2 .\" Copyright (c) 2005 Bruce M Simpson <bms@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .Nm pci_disable_busmaster ,
37 .Nm pci_enable_busmaster ,
45 .Nm pci_find_pcie_root_port ,
46 .Nm pci_get_max_read_req ,
47 .Nm pci_get_powerstate ,
48 .Nm pci_get_vpd_ident ,
49 .Nm pci_get_vpd_readonly ,
54 .Nm pci_pending_msix ,
58 .Nm pci_restore_state ,
60 .Nm pci_set_max_read_req ,
61 .Nm pci_set_powerstate ,
62 .Nm pci_write_config ,
63 .Nm pcie_adjust_config ,
64 .Nm pcie_read_config ,
72 .Fn pci_alloc_msi "device_t dev" "int *count"
74 .Fn pci_alloc_msix "device_t dev" "int *count"
76 .Fn pci_disable_busmaster "device_t dev"
78 .Fn pci_disable_io "device_t dev" "int space"
80 .Fn pci_enable_busmaster "device_t dev"
82 .Fn pci_enable_io "device_t dev" "int space"
84 .Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
86 .Fn pci_find_cap "device_t dev" "int capability" "int *capreg"
88 .Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
90 .Fn pci_find_device "uint16_t vendor" "uint16_t device"
92 .Fn pci_find_extcap "device_t dev" "int capability" "int *capreg"
94 .Fn pci_find_htcap "device_t dev" "int capability" "int *capreg"
96 .Fn pci_find_pcie_root_port "device_t dev"
98 .Fn pci_get_max_read_req "device_t dev"
100 .Fn pci_get_powerstate "device_t dev"
102 .Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
104 .Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
106 .Fn pci_msi_count "device_t dev"
108 .Fn pci_msix_count "device_t dev"
110 .Fn pci_pending_msix "device_t dev" "u_int index"
112 .Fn pci_read_config "device_t dev" "int reg" "int width"
114 .Fn pci_release_msi "device_t dev"
116 .Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors"
118 .Fn pci_restore_state "device_t dev"
120 .Fn pci_save_state "device_t dev"
122 .Fn pci_set_max_read_req "device_t dev" "int size"
124 .Fn pci_set_powerstate "device_t dev" "int state"
126 .Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
128 .Fo pcie_adjust_config
136 .Fn pcie_read_config "device_t dev" "int reg" "int width"
138 .Fn pcie_write_config "device_t dev" "int reg" "uint32_t val" "int width"
139 .In dev/pci/pci_iov.h
141 .Fn pci_iov_attach "device_t dev" "nvlist_t *pf_schema" "nvlist_t *vf_schema"
143 .Fn pci_iov_detach "device_t dev"
147 set of functions are used for managing PCI devices.
148 The functions are split into several groups:
149 raw configuration access,
152 device configuration,
154 message signaled interrupts.
155 .Ss Raw Configuration Access
158 function is used to read data from the PCI configuration
165 specifying the size of the access.
169 function is used to write the value
171 to the PCI configuration
178 specifying the size of the access.
181 .Fn pcie_adjust_config
182 function is used to modify the value of a register in the PCI-express
183 capability register set of device
187 specifies a relative offset in the register set with
189 specifying the size of the access.
190 The new value of the register is computed by modifying bits set in
194 Any bits not specified in
197 The previous value of the register is returned.
201 function is used to read the value of a register in the PCI-express
202 capability register set of device
206 specifies a relative offset in the register set with
208 specifying the size of the access.
211 .Fn pcie_write_config
212 function is used to write the value
214 to a register in the PCI-express capability register set of device
218 specifies a relative offset in the register set with
220 specifying the size of the access.
223 Device drivers should only use these functions for functionality that
224 is not available via another
230 function looks up the
232 of a PCI device, given its
239 number actually refers to the number of the device on the bus,
240 which does not necessarily indicate its geographic location
241 in terms of a physical slot.
242 Note that in case the system has multiple PCI domains,
245 function only searches the first one.
246 Actually, it is equivalent to:
247 .Bd -literal -offset indent
248 pci_find_dbsf(0, bus, slot, func);
253 function looks up the
255 of a PCI device, given its
263 number actually refers to the number of the device on the bus,
264 which does not necessarily indicate its geographic location
265 in terms of a physical slot.
269 function looks up the
271 of a PCI device, given its
276 Note that there can be multiple matches for this search; this function
277 only returns the first matching device.
278 .Ss Device Information
281 function is used to locate the first instance of a PCI capability
282 register set for the device
284 The capability to locate is specified by ID via
286 Constant macros of the form
288 for standard capability IDs are defined in
289 .In dev/pci/pcireg.h .
290 If the capability is found, then
292 is set to the offset in configuration space of the capability register set,
296 If the capability is not found or the device does not support capabilities,
302 function is used to locate the first instance of a PCI-express
303 extended capability register set for the device
305 The extended capability to locate is specified by ID via
307 Constant macros of the form
309 for standard extended capability IDs are defined in
310 .In dev/pci/pcireg.h .
311 If the extended capability is found, then
313 is set to the offset in configuration space of the extended capability
317 If the extended capability is not found or the device is not a
324 function is used to locate the first instance of a HyperTransport capability
325 register set for the device
327 The capability to locate is specified by type via
329 Constant macros of the form
331 for standard HyperTransport capability types are defined in
332 .In dev/pci/pcireg.h .
333 If the capability is found, then
335 is set to the offset in configuration space of the capability register set,
339 If the capability is not found or the device is not a HyperTransport device,
344 .Fn pci_find_pcie_root_port
345 function walks up the PCI device hierarchy to locate the PCI-express root
348 If a root port is not found,
349 .Fn pci_find_pcie_root_port
354 .Fn pci_get_vpd_ident
355 function is used to fetch a device's Vital Product Data
360 supports VPD and provides an identifier string,
363 is set to point at a read-only, null-terminated copy of the identifier
366 .Fn pci_get_vpd_ident
368 If the device does not support VPD or does not provide an identifier
371 .Fn pci_get_vpd_ident
375 .Fn pci_get_vpd_readonly
376 function is used to fetch the value of a single VPD read-only keyword
379 The keyword to fetch is identified by the two character string
381 If the device supports VPD and provides a read-only value for the
385 is set to point at a read-only, null-terminated copy of the value,
387 .Fn pci_get_vpd_readonly
389 If the device does not support VPD or does not provide the requested
392 .Fn pci_get_vpd_readonly
394 .Ss Device Configuration
396 .Fn pci_enable_busmaster
397 function enables PCI bus mastering for the device
400 .Dv PCIM_CMD_BUSMASTEREN
405 .Fn pci_disable_busmaster
406 function clears this bit.
410 function enables memory or I/O port address decoding for the device
418 register appropriately.
421 function clears the appropriate bit.
424 argument specifies which resource is affected; this can be either
429 Device drivers should generally not use these routines directly.
430 The PCI bus will enable decoding automatically when a
434 resource is activated via
435 .Xr bus_alloc_resource 9
437 .Xr bus_activate_resource 9 .
440 .Fn pci_get_max_read_req
441 function returns the current maximum read request size in bytes for a
445 device is not a PCI-express device,
446 .Fn pci_get_max_read_req
450 .Fn pci_set_max_read_req
451 sets the PCI-express maximum read request size for
457 .Fn pci_set_max_read_req
458 returns the actual size set in bytes.
461 device is not a PCI-express device,
462 .Fn pci_set_max_read_req
466 .Fn pci_get_powerstate
467 function returns the current power state of the device
469 If the device does not support power management capabilities, then the default
471 .Dv PCI_POWERSTATE_D0
473 The following power states are defined by PCI:
474 .Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
475 .It Dv PCI_POWERSTATE_D0
476 State in which device is on and running.
477 It is receiving full power from the system and delivering
478 full functionality to the user.
479 .It Dv PCI_POWERSTATE_D1
480 Class-specific low-power state in which device context may or
482 Busses in this state cannot do anything to the bus, to
483 force devices to lose context.
484 .It Dv PCI_POWERSTATE_D2
485 Class-specific low-power state in which device context may or
487 Attains greater power savings than
488 .Dv PCI_POWERSTATE_D1 .
489 Busses in this state can cause devices to lose some context.
492 be prepared for the bus to be in this state or higher.
493 .It Dv PCI_POWERSTATE_D3
494 State in which the device is off and not running.
495 Device context is lost, and power from the device can
497 .It Dv PCI_POWERSTATE_UNKNOWN
498 State of the device is unknown.
502 .Fn pci_set_powerstate
503 function is used to transition the device
505 to the PCI power state
507 If the device does not support power management capabilities or
508 it does not support the specific power state
510 then the function will fail with
515 function is used to advertise that the given device
516 .Pq and associated device driver
517 supports PCI Single-Root I/O Virtualization
519 A driver that supports SR-IOV must implement the
525 This function should be called during the
528 If this function returns an error, it is recommended that the device driver
529 still successfully attaches, but runs with SR-IOV disabled.
534 parameters are used to define what device-specific configuration parameters the
535 device driver accepts when SR-IOV is enabled for the Physical Function
537 and for individual Virtual Functions
542 for details on how to construct the schema.
547 is invalid or specifies parameter names that conflict with parameter names that
550 will return an error and SR-IOV will not be available on the PF device.
551 If a driver does not accept configuration parameters for either the PF device
552 or the VF devices, the driver must pass an empty schema for that device.
553 The SR-IOV infrastructure takes ownership of the
557 and is responsible for freeing them.
558 The driver must never free the schemas itself.
562 function is used to advise the SR-IOV infrastructure that the driver for the
563 given device is attempting to detach and that all SR-IOV resources for the
564 device must be released.
565 This function must be called during the
569 was successfully called on the device and
571 has not subsequently been called on the device and returned no error.
572 If this function returns an error, the
574 method must fail and return an error, as detaching the PF driver while VF
575 devices are active would cause system instability.
576 This function is safe to call and will always succeed if
578 previously failed with an error on the given device, or if
580 was never called on the device.
585 .Fn pci_restore_state
586 functions can be used by a device driver to save and restore standard PCI
590 function must be invoked while the device has valid state before
591 .Fn pci_restore_state
593 If the device is not in the fully-powered state
594 .Pq Dv PCI_POWERSTATE_D0
596 .Fn pci_restore_state
598 then the device will be transitioned to
599 .Dv PCI_POWERSTATE_D0
600 before any config registers are restored.
601 .Ss Message Signaled Interrupts
602 Message Signaled Interrupts
605 Enhanced Message Signaled Interrupts
607 are PCI capabilities that provide an alternate method for PCI
608 devices to signal interrupts.
609 The legacy INTx interrupt is available to PCI devices as a
611 resource with a resource ID of zero.
612 MSI and MSI-X interrupts are available to PCI devices as one or more
614 resources with resource IDs greater than zero.
615 A driver must ask the PCI bus to allocate MSI or MSI-X interrupts
620 before it can use MSI or MSI-X
623 A driver is not allowed to use the legacy INTx
625 resource if MSI or MSI-X interrupts have been allocated,
626 and attempts to allocate MSI or MSI-X interrupts will fail if the
627 driver is currently using the legacy INTx
630 A driver is only allowed to use either MSI or MSI-X,
635 function returns the maximum number of MSI messages supported by the
638 If the device does not support MSI,
645 function attempts to allocate
647 MSI messages for the device
651 function may allocate fewer messages than requested for various
652 reasons including requests for more messages than the device
655 or if the system has a shortage of available MSI messages.
658 is set to the number of messages allocated and
663 resources for the allocated messages will be available at consecutive
664 resource IDs beginning with one.
667 is not able to allocate any messages,
669 Note that MSI only supports message counts that are powers of two;
670 requests to allocate a non-power of two count of messages will fail.
674 function is used to release any allocated MSI or MSI-X messages back
678 resources are allocated by the driver or have a configured interrupt
680 this function will fail with
684 function returns zero on success and an error on failure.
688 function returns the maximum number of MSI-X messages supported by the
691 If the device does not support MSI-X,
698 function attempts to allocate
700 MSI-X messages for the device
704 function may allocate fewer messages than requested for various
705 reasons including requests for more messages than the device
708 or if the system has a shortage of available MSI-X messages.
711 is set to the number of messages allocated and
715 the resource ID for each
717 resource identifies the index in the MSI-X table of the
718 corresponding message.
719 A resource ID of one maps to the first index of the MSI-X table;
720 a resource ID two identifies the second index in the table, etc.
725 messages allocated to the first
730 is not able to allocate any messages,
733 MSI-X does not require message counts that are powers of two.
737 function examines the
739 device's Pending Bit Array
741 to determine the pending status of the MSI-X message at table index
743 If the indicated message is pending,
744 this function returns a non-zero value;
749 to this function will result in undefined behavior.
751 As mentioned in the description of
753 MSI-X messages are initially assigned to the first N table entries.
754 A driver may use a different distribution of available messages to
755 table entries via the
758 Note that this function must be called after a successful call to
760 but before any of the
762 resources are allocated.
765 function returns zero on success,
766 or an error on failure.
773 The array maps directly to the MSI-X table in that the first entry in
774 the array specifies the message used for the first entry in the MSI-X
776 the second entry in the array corresponds to the second entry in the
779 The vector value in each array index can either be zero to indicate
780 that no message should be assigned to the corresponding MSI-X table entry,
781 or it can be a number from one to N
783 where N is the count returned from the previous call to
786 to indicate which of the allocated messages should be assigned to the
787 corresponding MSI-X table entry.
792 each MSI-X table entry with a non-zero vector will have an associated
794 resource whose resource ID corresponds to the table index as described
797 MSI-X table entries that with a vector of zero will not have an
802 if any of the original messages allocated by
804 are not used in the new distribution of messages in the MSI-X table,
805 they will be released automatically.
806 Note that if a driver wishes to use fewer messages than were allocated by
808 the driver must use a single, contiguous range of messages beginning
809 with one in the new distribution.
812 function will fail if this condition is not met.
813 .Sh IMPLEMENTATION NOTES
816 type varies according to the size of the PCI bus address
817 space on the target architecture.
821 .Xr bus_alloc_resource 9 ,
823 .Xr bus_release_resource 9 ,
824 .Xr bus_setup_intr 9 ,
825 .Xr bus_teardown_intr 9 ,
831 .%B FreeBSD Developers' Handbook
833 .%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
838 .%B PCI System Architecture
841 .%O ISBN 0-201-30974-2
845 This manual page was written by
846 .An Bruce M Simpson Aq Mt bms@FreeBSD.org
848 .An John Baldwin Aq Mt jhb@FreeBSD.org .
850 The kernel PCI code has a number of references to
852 These do not refer to the geographic location of PCI devices,
853 but to the device number assigned by the combination of the PCI IDSEL
854 mechanism and the platform firmware.
855 This should be taken note of when working with the kernel PCI code.