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 ,
43 .Nm pci_get_max_read_req ,
44 .Nm pci_get_powerstate ,
45 .Nm pci_get_vpd_ident ,
46 .Nm pci_get_vpd_readonly ,
49 .Nm pci_pending_msix ,
53 .Nm pci_restore_state ,
55 .Nm pci_set_max_read_req ,
56 .Nm pci_set_powerstate ,
64 .Fn pci_alloc_msi "device_t dev" "int *count"
66 .Fn pci_alloc_msix "device_t dev" "int *count"
68 .Fn pci_disable_busmaster "device_t dev"
70 .Fn pci_disable_io "device_t dev" "int space"
72 .Fn pci_enable_busmaster "device_t dev"
74 .Fn pci_enable_io "device_t dev" "int space"
76 .Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
78 .Fn pci_find_cap "device_t dev" "int capability" "int *capreg"
80 .Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
82 .Fn pci_find_device "uint16_t vendor" "uint16_t device"
84 .Fn pci_get_max_read_req "device_t dev"
86 .Fn pci_get_powerstate "device_t dev"
88 .Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
90 .Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
92 .Fn pci_msi_count "device_t dev"
94 .Fn pci_msix_count "device_t dev"
96 .Fn pci_pending_msix "device_t dev" "u_int index"
98 .Fn pci_read_config "device_t dev" "int reg" "int width"
100 .Fn pci_release_msi "device_t dev"
102 .Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors"
104 .Fn pci_restore_state "device_t dev"
106 .Fn pci_save_state "device_t dev"
108 .Fn pci_set_max_read_req "device_t dev" "int size"
110 .Fn pci_set_powerstate "device_t dev" "int state"
112 .Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
116 set of functions are used for managing PCI devices.
117 The functions are split into several groups:
118 raw configuration access,
121 device configuration,
123 message signaled interrupts.
124 .Ss Raw Configuration Access
127 function is used to read data from the PCI configuration
134 specifying the size of the access.
138 function is used to write the value
140 to the PCI configuration
147 specifying the size of the access.
150 Device drivers should only use these functions for functionality that
151 is not available via another
157 function looks up the
159 of a PCI device, given its
166 number actually refers to the number of the device on the bus,
167 which does not necessarily indicate its geographic location
168 in terms of a physical slot.
169 Note that in case the system has multiple PCI domains,
172 function only searches the first one.
173 Actually, it is equivalent to:
174 .Bd -literal -offset indent
175 pci_find_dbsf(0, bus, slot, func);
180 function looks up the
182 of a PCI device, given its
190 number actually refers to the number of the device on the bus,
191 which does not necessarily indicate its geographic location
192 in terms of a physical slot.
196 function looks up the
198 of a PCI device, given its
203 Note that there can be multiple matches for this search; this function
204 only returns the first matching device.
205 .Ss Device Information
208 function is used to locate the first instance of a PCI capability
209 register set for the device
211 The capability to locate is specified by ID via
213 Constant macros of the form
215 for standard capability IDs are defined in
216 .In dev/pci/pcireg.h .
217 If the capability is found, then
219 is set to the offset in configuration space of the capability register set,
223 If the capability is not found or the device does not support capabilities,
228 .Fn pci_get_vpd_ident
229 function is used to fetch a device's Vital Product Data
234 supports VPD and provides an identifier string,
237 is set to point at a read-only, null-terminated copy of the identifier
240 .Fn pci_get_vpd_ident
242 If the device does not support VPD or does not provide an identifier
245 .Fn pci_get_vpd_ident
249 .Fn pci_get_vpd_readonly
250 function is used to fetch the value of a single VPD read-only keyword
253 The keyword to fetch is identified by the two character string
255 If the device supports VPD and provides a read-only value for the
259 is set to point at a read-only, null-terminated copy of the value,
261 .Fn pci_get_vpd_readonly
263 If the device does not support VPD or does not provide the requested
266 .Fn pci_get_vpd_readonly
268 .Ss Device Configuration
270 .Fn pci_enable_busmaster
271 function enables PCI bus mastering for the device
274 .Dv PCIM_CMD_BUSMASTEREN
279 .Fn pci_disable_busmaster
280 function clears this bit.
284 function enables memory or I/O port address decoding for the device
292 register appropriately.
295 function clears the appropriate bit.
298 argument specifies which resource is affected; this can be either
303 Device drivers should generally not use these routines directly.
304 The PCI bus will enable decoding automatically when a
308 resource is activated via
309 .Xr bus_alloc_resource 9
311 .Xr bus_activate_resource 9 .
314 .Fn pci_get_max_read_req
315 function returns the current maximum read request size in bytes for a
319 device is not a PCI-express device,
320 .Fn pci_get_max_read_req
324 .Fn pci_set_max_read_req
325 sets the PCI-express maximum read request size for
331 .Fn pci_set_max_read_req
332 returns the actual size set in bytes.
335 device is not a PCI-express device,
336 .Fn pci_set_max_read_req
340 .Fn pci_get_powerstate
341 function returns the current power state of the device
343 If the device does not support power management capabilities, then the default
345 .Dv PCI_POWERSTATE_D0
347 The following power states are defined by PCI:
348 .Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
349 .It Dv PCI_POWERSTATE_D0
350 State in which device is on and running.
351 It is receiving full power from the system and delivering
352 full functionality to the user.
353 .It Dv PCI_POWERSTATE_D1
354 Class-specific low-power state in which device context may or
356 Busses in this state cannot do anything to the bus, to
357 force devices to lose context.
358 .It Dv PCI_POWERSTATE_D2
359 Class-specific low-power state in which device context may or
361 Attains greater power savings than
362 .Dv PCI_POWERSTATE_D1 .
363 Busses in this state can cause devices to lose some context.
366 be prepared for the bus to be in this state or higher.
367 .It Dv PCI_POWERSTATE_D3
368 State in which the device is off and not running.
369 Device context is lost, and power from the device can
371 .It Dv PCI_POWERSTATE_UNKNOWN
372 State of the device is unknown.
376 .Fn pci_set_powerstate
377 function is used to transition the device
379 to the PCI power state
381 If the device does not support power management capabilities or
382 it does not support the specific power state
384 then the function will fail with
390 .Fn pci_restore_state
391 functions can be used by a device driver to save and restore standard PCI
395 function must be invoked while the device has valid state before
396 .Fn pci_restore_state
398 If the device is not in the fully-powered state
399 .Pq Dv PCI_POWERSTATE_D0
401 .Fn pci_restore_state
403 then the device will be transitioned to
404 .Dv PCI_POWERSTATE_D0
405 before any config registers are restored.
406 .Ss Message Signaled Interrupts
407 Message Signaled Interrupts
410 Enhanced Message Signaled Interrupts
412 are PCI capabilities that provide an alternate method for PCI
413 devices to signal interrupts.
414 The legacy INTx interrupt is available to PCI devices as a
416 resource with a resource ID of zero.
417 MSI and MSI-X interrupts are available to PCI devices as one or more
419 resources with resource IDs greater than zero.
420 A driver must ask the PCI bus to allocate MSI or MSI-X interrupts
425 before it can use MSI or MSI-X
428 A driver is not allowed to use the legacy INTx
430 resource if MSI or MSI-X interrupts have been allocated,
431 and attempts to allocate MSI or MSI-X interrupts will fail if the
432 driver is currently using the legacy INTx
435 A driver is only allowed to use either MSI or MSI-X,
440 function returns the maximum number of MSI messages supported by the
443 If the device does not support MSI,
450 function attempts to allocate
452 MSI messages for the device
456 function may allocate fewer messages than requested for various
457 reasons including requests for more messages than the device
460 or if the system has a shortage of available MSI messages.
463 is set to the number of messages allocated and
468 resources for the allocated messages will be available at consecutive
469 resource IDs beginning with one.
472 is not able to allocate any messages,
474 Note that MSI only supports message counts that are powers of two;
475 requests to allocate a non-power of two count of messages will fail.
479 function is used to release any allocated MSI or MSI-X messages back
483 resources are allocated by the driver or have a configured interrupt
485 this function will fail with
489 function returns zero on success and an error on failure.
493 function returns the maximum number of MSI-X messages supported by the
496 If the device does not support MSI-X,
503 function attempts to allocate
505 MSI-X messages for the device
509 function may allocate fewer messages than requested for various
510 reasons including requests for more messages than the device
513 or if the system has a shortage of available MSI-X messages.
516 is set to the number of messages allocated and
520 the resource ID for each
522 resource identifies the index in the MSI-X table of the
523 corresponding message.
524 A resource ID of one maps to the first index of the MSI-X table;
525 a resource ID two identifies the second index in the table, etc.
530 messages allocated to the first
535 is not able to allocate any messages,
538 MSI-X does not require message counts that are powers of two.
542 function examines the
544 device's Pending Bit Array
546 to determine the pending status of the MSI-X message at table index
548 If the indicated message is pending,
549 this function returns a non-zero value;
554 to this function will result in undefined behavior.
556 As mentioned in the description of
558 MSI-X messages are initially assigned to the first N table entries.
559 A driver may use a different distribution of available messages to
560 table entries via the
563 Note that this function must be called after a successful call to
565 but before any of the
567 resources are allocated.
570 function returns zero on success,
571 or an error on failure.
578 The array maps directly to the MSI-X table in that the first entry in
579 the array specifies the message used for the first entry in the MSI-X
581 the second entry in the array corresponds to the second entry in the
584 The vector value in each array index can either be zero to indicate
585 that no message should be assigned to the corresponding MSI-X table entry,
586 or it can be a number from one to N
588 where N is the count returned from the previous call to
591 to indicate which of the allocated messages should be assigned to the
592 corresponding MSI-X table entry.
597 each MSI-X table entry with a non-zero vector will have an associated
599 resource whose resource ID corresponds to the table index as described
602 MSI-X table entries that with a vector of zero will not have an
607 if any of the original messages allocated by
609 are not used in the new distribution of messages in the MSI-X table,
610 they will be released automatically.
611 Note that if a driver wishes to use fewer messages than were allocated by
613 the driver must use a single, contiguous range of messages beginning
614 with one in the new distribution.
617 function will fail if this condition is not met.
618 .Sh IMPLEMENTATION NOTES
621 type varies according to the size of the PCI bus address
622 space on the target architecture.
626 .Xr bus_alloc_resource 9 ,
628 .Xr bus_release_resource 9 ,
629 .Xr bus_setup_intr 9 ,
630 .Xr bus_teardown_intr 9 ,
636 .%B FreeBSD Developers' Handbook
638 .%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
643 .%B PCI System Architecture
646 .%O ISBN 0-201-30974-2
649 This manual page was written by
650 .An Bruce M Simpson Aq bms@FreeBSD.org
652 .An John Baldwin Aq jhb@FreeBSD.org .
654 The kernel PCI code has a number of references to
656 These do not refer to the geographic location of PCI devices,
657 but to the device number assigned by the combination of the PCI IDSEL
658 mechanism and the platform firmware.
659 This should be taken note of when working with the kernel PCI code.