xref: /freebsd/share/man/man9/pci.9 (revision da0fc9250c31dfb380b868492644e0f1bf64275d)
1aac0aafaSHiten Pandya.\"
2bf1639eeSBruce M Simpson.\" Copyright (c) 2005 Bruce M Simpson <bms@FreeBSD.org>
3aac0aafaSHiten Pandya.\" All rights reserved.
4aac0aafaSHiten Pandya.\"
5aac0aafaSHiten Pandya.\" Redistribution and use in source and binary forms, with or without
6aac0aafaSHiten Pandya.\" modification, are permitted provided that the following conditions
7aac0aafaSHiten Pandya.\" are met:
8aac0aafaSHiten Pandya.\" 1. Redistributions of source code must retain the above copyright
9aac0aafaSHiten Pandya.\"    notice, this list of conditions and the following disclaimer.
10aac0aafaSHiten Pandya.\" 2. Redistributions in binary form must reproduce the above copyright
11aac0aafaSHiten Pandya.\"    notice, this list of conditions and the following disclaimer in the
12aac0aafaSHiten Pandya.\"    documentation and/or other materials provided with the distribution.
13aac0aafaSHiten Pandya.\"
14aac0aafaSHiten Pandya.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15aac0aafaSHiten Pandya.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16aac0aafaSHiten Pandya.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17aac0aafaSHiten Pandya.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18aac0aafaSHiten Pandya.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19aac0aafaSHiten Pandya.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20aac0aafaSHiten Pandya.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21aac0aafaSHiten Pandya.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22aac0aafaSHiten Pandya.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23aac0aafaSHiten Pandya.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24aac0aafaSHiten Pandya.\" SUCH DAMAGE.
25aac0aafaSHiten Pandya.\"
26aac0aafaSHiten Pandya.\" $FreeBSD$
27aac0aafaSHiten Pandya.\"
2864414cc0SJohn Baldwin.Dd September 6, 2016
29aac0aafaSHiten Pandya.Dt PCI 9
30aac0aafaSHiten Pandya.Os
31aac0aafaSHiten Pandya.Sh NAME
32aac0aafaSHiten Pandya.Nm pci ,
33855ed4c5SJohn Baldwin.Nm pci_alloc_msi ,
34855ed4c5SJohn Baldwin.Nm pci_alloc_msix ,
35aac0aafaSHiten Pandya.Nm pci_disable_busmaster ,
36aac0aafaSHiten Pandya.Nm pci_disable_io ,
370a9c80e5SJohn Baldwin.Nm pci_enable_busmaster ,
380a9c80e5SJohn Baldwin.Nm pci_enable_io ,
39aac0aafaSHiten Pandya.Nm pci_find_bsf ,
40855ed4c5SJohn Baldwin.Nm pci_find_cap ,
4155aaf894SMarius Strobl.Nm pci_find_dbsf ,
420a9c80e5SJohn Baldwin.Nm pci_find_device ,
4368bf9717SJohn Baldwin.Nm pci_find_extcap ,
4468bf9717SJohn Baldwin.Nm pci_find_htcap ,
4587dd2f95SJohn Baldwin.Nm pci_find_pcie_root_port ,
46d7be980dSAndrew Turner.Nm pci_get_id ,
472ab0398dSJohn Baldwin.Nm pci_get_max_payload ,
48855ed4c5SJohn Baldwin.Nm pci_get_max_read_req ,
490a9c80e5SJohn Baldwin.Nm pci_get_powerstate ,
50855ed4c5SJohn Baldwin.Nm pci_get_vpd_ident ,
51855ed4c5SJohn Baldwin.Nm pci_get_vpd_readonly ,
527d971e36SRyan Stone.Nm pci_iov_attach ,
530aee83ccSJohn Baldwin.Nm pci_iov_attach_name ,
547d971e36SRyan Stone.Nm pci_iov_detach ,
55855ed4c5SJohn Baldwin.Nm pci_msi_count ,
56855ed4c5SJohn Baldwin.Nm pci_msix_count ,
57ce204e1bSJohn Baldwin.Nm pci_msix_pba_bar ,
58ce204e1bSJohn Baldwin.Nm pci_msix_table_bar ,
59855ed4c5SJohn Baldwin.Nm pci_pending_msix ,
600a9c80e5SJohn Baldwin.Nm pci_read_config ,
61855ed4c5SJohn Baldwin.Nm pci_release_msi ,
62855ed4c5SJohn Baldwin.Nm pci_remap_msix ,
630a9c80e5SJohn Baldwin.Nm pci_restore_state ,
640a9c80e5SJohn Baldwin.Nm pci_save_state ,
65855ed4c5SJohn Baldwin.Nm pci_set_max_read_req ,
660a9c80e5SJohn Baldwin.Nm pci_set_powerstate ,
67ec603c72SJohn Baldwin.Nm pci_write_config ,
68ec603c72SJohn Baldwin.Nm pcie_adjust_config ,
69*da0fc925SJohn Baldwin.Nm pcie_flr ,
70*da0fc925SJohn Baldwin.Nm pcie_get_max_completion_timeout ,
71ec603c72SJohn Baldwin.Nm pcie_read_config ,
72*da0fc925SJohn Baldwin.Nm pcie_wait_for_pending_transactions ,
73ec603c72SJohn Baldwin.Nm pcie_write_config
74aac0aafaSHiten Pandya.Nd PCI bus interface
75aac0aafaSHiten Pandya.Sh SYNOPSIS
76aac0aafaSHiten Pandya.In sys/bus.h
77aac0aafaSHiten Pandya.In dev/pci/pcireg.h
78855ed4c5SJohn Baldwin.In dev/pci/pcivar.h
79855ed4c5SJohn Baldwin.Ft int
80855ed4c5SJohn Baldwin.Fn pci_alloc_msi "device_t dev" "int *count"
81855ed4c5SJohn Baldwin.Ft int
82855ed4c5SJohn Baldwin.Fn pci_alloc_msix "device_t dev" "int *count"
83aac0aafaSHiten Pandya.Ft int
84aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev"
85aac0aafaSHiten Pandya.Ft int
86aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space"
87aac0aafaSHiten Pandya.Ft int
880a9c80e5SJohn Baldwin.Fn pci_enable_busmaster "device_t dev"
89aac0aafaSHiten Pandya.Ft int
900a9c80e5SJohn Baldwin.Fn pci_enable_io "device_t dev" "int space"
91aac0aafaSHiten Pandya.Ft device_t
9265bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
93855ed4c5SJohn Baldwin.Ft int
94855ed4c5SJohn Baldwin.Fn pci_find_cap "device_t dev" "int capability" "int *capreg"
95aac0aafaSHiten Pandya.Ft device_t
9655aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
9755aaf894SMarius Strobl.Ft device_t
9865bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device"
990a9c80e5SJohn Baldwin.Ft int
10068bf9717SJohn Baldwin.Fn pci_find_extcap "device_t dev" "int capability" "int *capreg"
10168bf9717SJohn Baldwin.Ft int
10268bf9717SJohn Baldwin.Fn pci_find_htcap "device_t dev" "int capability" "int *capreg"
10387dd2f95SJohn Baldwin.Ft device_t
10487dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port "device_t dev"
10568bf9717SJohn Baldwin.Ft int
106d7be980dSAndrew Turner.Fn pci_get_id "device_t dev" "enum pci_id_type type" "uintptr_t *id"
107d7be980dSAndrew Turner.Ft int
1082ab0398dSJohn Baldwin.Fn pci_get_max_payload "device_t dev"
1092ab0398dSJohn Baldwin.Ft int
110855ed4c5SJohn Baldwin.Fn pci_get_max_read_req "device_t dev"
111855ed4c5SJohn Baldwin.Ft int
1120a9c80e5SJohn Baldwin.Fn pci_get_powerstate "device_t dev"
113855ed4c5SJohn Baldwin.Ft int
114855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
115855ed4c5SJohn Baldwin.Ft int
116855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
117855ed4c5SJohn Baldwin.Ft int
118855ed4c5SJohn Baldwin.Fn pci_msi_count "device_t dev"
119855ed4c5SJohn Baldwin.Ft int
120855ed4c5SJohn Baldwin.Fn pci_msix_count "device_t dev"
121855ed4c5SJohn Baldwin.Ft int
122ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar "device_t dev"
123ce204e1bSJohn Baldwin.Ft int
124ce204e1bSJohn Baldwin.Fn pci_msix_table_bar "device_t dev"
125ce204e1bSJohn Baldwin.Ft int
126855ed4c5SJohn Baldwin.Fn pci_pending_msix "device_t dev" "u_int index"
1270a9c80e5SJohn Baldwin.Ft uint32_t
1280a9c80e5SJohn Baldwin.Fn pci_read_config "device_t dev" "int reg" "int width"
129855ed4c5SJohn Baldwin.Ft int
130855ed4c5SJohn Baldwin.Fn pci_release_msi "device_t dev"
131855ed4c5SJohn Baldwin.Ft int
132855ed4c5SJohn Baldwin.Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors"
1330a9c80e5SJohn Baldwin.Ft void
1340a9c80e5SJohn Baldwin.Fn pci_restore_state "device_t dev"
1350a9c80e5SJohn Baldwin.Ft void
1360a9c80e5SJohn Baldwin.Fn pci_save_state "device_t dev"
1370a9c80e5SJohn Baldwin.Ft int
138855ed4c5SJohn Baldwin.Fn pci_set_max_read_req "device_t dev" "int size"
139855ed4c5SJohn Baldwin.Ft int
1400a9c80e5SJohn Baldwin.Fn pci_set_powerstate "device_t dev" "int state"
1410a9c80e5SJohn Baldwin.Ft void
1420a9c80e5SJohn Baldwin.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
143ec603c72SJohn Baldwin.Ft uint32_t
144ec603c72SJohn Baldwin.Fo pcie_adjust_config
145ec603c72SJohn Baldwin.Fa "device_t dev"
146ec603c72SJohn Baldwin.Fa "int reg"
147ec603c72SJohn Baldwin.Fa "uint32_t mask"
148ec603c72SJohn Baldwin.Fa "uint32_t val"
149ec603c72SJohn Baldwin.Fa "int width"
150ec603c72SJohn Baldwin.Fc
151*da0fc925SJohn Baldwin.Ft bool
152*da0fc925SJohn Baldwin.Fn pcie_flr "device_t dev" "u_int max_delay" "bool force"
153*da0fc925SJohn Baldwin.Ft int
154*da0fc925SJohn Baldwin.Fn pcie_get_max_completion_timeout "device_t dev"
155ec603c72SJohn Baldwin.Ft uint32_t
156ec603c72SJohn Baldwin.Fn pcie_read_config "device_t dev" "int reg" "int width"
157*da0fc925SJohn Baldwin.Ft bool
158*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions "device_t dev" "u_int max_delay"
159ec603c72SJohn Baldwin.Ft void
160ec603c72SJohn Baldwin.Fn pcie_write_config "device_t dev" "int reg" "uint32_t val" "int width"
16164414cc0SJohn Baldwin.Ft void
16264414cc0SJohn Baldwin.Fn pci_event_fn "void *arg" "device_t dev"
16364414cc0SJohn Baldwin.Fn EVENTHANDLER_REGISTER "pci_add_device" "pci_event_fn"
16464414cc0SJohn Baldwin.Fn EVENTHANDLER_DEREGISTER "pci_delete_resource" "pci_event_fn"
165f3bb9251SJohn Baldwin.In dev/pci/pci_iov.h
166f3bb9251SJohn Baldwin.Ft int
167f3bb9251SJohn Baldwin.Fn pci_iov_attach "device_t dev" "nvlist_t *pf_schema" "nvlist_t *vf_schema"
168f3bb9251SJohn Baldwin.Ft int
1690aee83ccSJohn Baldwin.Fo pci_iov_attach_name
1700aee83ccSJohn Baldwin.Fa "device_t dev"
1710aee83ccSJohn Baldwin.Fa "nvlist_t *pf_schema"
1720aee83ccSJohn Baldwin.Fa "nvlist_t *vf_schema"
1730aee83ccSJohn Baldwin.Fa "const char *fmt"
1740aee83ccSJohn Baldwin.Fa "..."
1750aee83ccSJohn Baldwin.Fc
1760aee83ccSJohn Baldwin.Ft int
177f3bb9251SJohn Baldwin.Fn pci_iov_detach "device_t dev"
178aac0aafaSHiten Pandya.Sh DESCRIPTION
179aac0aafaSHiten PandyaThe
180aac0aafaSHiten Pandya.Nm
181aac0aafaSHiten Pandyaset of functions are used for managing PCI devices.
182855ed4c5SJohn BaldwinThe functions are split into several groups:
183855ed4c5SJohn Baldwinraw configuration access,
184855ed4c5SJohn Baldwinlocating devices,
185855ed4c5SJohn Baldwindevice information,
186855ed4c5SJohn Baldwindevice configuration,
187855ed4c5SJohn Baldwinand
188855ed4c5SJohn Baldwinmessage signaled interrupts.
189855ed4c5SJohn Baldwin.Ss Raw Configuration Access
190aac0aafaSHiten PandyaThe
191aac0aafaSHiten Pandya.Fn pci_read_config
192aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration
193aac0aafaSHiten Pandyaspace of the device
194aac0aafaSHiten Pandya.Fa dev ,
195aac0aafaSHiten Pandyaat offset
196aac0aafaSHiten Pandya.Fa reg ,
197aac0aafaSHiten Pandyawith
198aac0aafaSHiten Pandya.Fa width
199aac0aafaSHiten Pandyaspecifying the size of the access.
200aac0aafaSHiten Pandya.Pp
201aac0aafaSHiten PandyaThe
202aac0aafaSHiten Pandya.Fn pci_write_config
203aac0aafaSHiten Pandyafunction is used to write the value
204aac0aafaSHiten Pandya.Fa val
205aac0aafaSHiten Pandyato the PCI configuration
206aac0aafaSHiten Pandyaspace of the device
207aac0aafaSHiten Pandya.Fa dev ,
208aac0aafaSHiten Pandyaat offset
209aac0aafaSHiten Pandya.Fa reg ,
210aac0aafaSHiten Pandyawith
211aac0aafaSHiten Pandya.Fa width
212aac0aafaSHiten Pandyaspecifying the size of the access.
213aac0aafaSHiten Pandya.Pp
214ec603c72SJohn BaldwinThe
215ec603c72SJohn Baldwin.Fn pcie_adjust_config
216ec603c72SJohn Baldwinfunction is used to modify the value of a register in the PCI-express
217ec603c72SJohn Baldwincapability register set of device
218ec603c72SJohn Baldwin.Fa dev .
219ec603c72SJohn BaldwinThe offset
220ec603c72SJohn Baldwin.Fa reg
221ec603c72SJohn Baldwinspecifies a relative offset in the register set with
222ec603c72SJohn Baldwin.Fa width
223ec603c72SJohn Baldwinspecifying the size of the access.
224ec603c72SJohn BaldwinThe new value of the register is computed by modifying bits set in
225ec603c72SJohn Baldwin.Fa mask
226ec603c72SJohn Baldwinto the value in
227ec603c72SJohn Baldwin.Fa val .
228ec603c72SJohn BaldwinAny bits not specified in
229ec603c72SJohn Baldwin.Fa mask
230ec603c72SJohn Baldwinare preserved.
231ec603c72SJohn BaldwinThe previous value of the register is returned.
232ec603c72SJohn Baldwin.Pp
233ec603c72SJohn BaldwinThe
234ec603c72SJohn Baldwin.Fn pcie_read_config
235ec603c72SJohn Baldwinfunction is used to read the value of a register in the PCI-express
236ec603c72SJohn Baldwincapability register set of device
237ec603c72SJohn Baldwin.Fa dev .
238ec603c72SJohn BaldwinThe offset
239ec603c72SJohn Baldwin.Fa reg
240ec603c72SJohn Baldwinspecifies a relative offset in the register set with
241ec603c72SJohn Baldwin.Fa width
242ec603c72SJohn Baldwinspecifying the size of the access.
243ec603c72SJohn Baldwin.Pp
244ec603c72SJohn BaldwinThe
245ec603c72SJohn Baldwin.Fn pcie_write_config
246ec603c72SJohn Baldwinfunction is used to write the value
247ec603c72SJohn Baldwin.Fa val
248ec603c72SJohn Baldwinto a register in the PCI-express capability register set of device
249ec603c72SJohn Baldwin.Fa dev .
250ec603c72SJohn BaldwinThe offset
251ec603c72SJohn Baldwin.Fa reg
252ec603c72SJohn Baldwinspecifies a relative offset in the register set with
253ec603c72SJohn Baldwin.Fa width
254ec603c72SJohn Baldwinspecifying the size of the access.
255ec603c72SJohn Baldwin.Pp
256855ed4c5SJohn Baldwin.Em NOTE :
257855ed4c5SJohn BaldwinDevice drivers should only use these functions for functionality that
258855ed4c5SJohn Baldwinis not available via another
259855ed4c5SJohn Baldwin.Fn pci
260855ed4c5SJohn Baldwinfunction.
261855ed4c5SJohn Baldwin.Ss Locating Devices
262855ed4c5SJohn BaldwinThe
263855ed4c5SJohn Baldwin.Fn pci_find_bsf
264855ed4c5SJohn Baldwinfunction looks up the
265855ed4c5SJohn Baldwin.Vt device_t
266855ed4c5SJohn Baldwinof a PCI device, given its
267855ed4c5SJohn Baldwin.Fa bus ,
268855ed4c5SJohn Baldwin.Fa slot ,
269855ed4c5SJohn Baldwinand
270855ed4c5SJohn Baldwin.Fa func .
271855ed4c5SJohn BaldwinThe
272855ed4c5SJohn Baldwin.Fa slot
273855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
274855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
275855ed4c5SJohn Baldwinin terms of a physical slot.
276855ed4c5SJohn BaldwinNote that in case the system has multiple PCI domains,
277855ed4c5SJohn Baldwinthe
278855ed4c5SJohn Baldwin.Fn pci_find_bsf
279855ed4c5SJohn Baldwinfunction only searches the first one.
280855ed4c5SJohn BaldwinActually, it is equivalent to:
281855ed4c5SJohn Baldwin.Bd -literal -offset indent
282855ed4c5SJohn Baldwinpci_find_dbsf(0, bus, slot, func);
283855ed4c5SJohn Baldwin.Ed
284855ed4c5SJohn Baldwin.Pp
285855ed4c5SJohn BaldwinThe
286855ed4c5SJohn Baldwin.Fn pci_find_dbsf
287855ed4c5SJohn Baldwinfunction looks up the
288855ed4c5SJohn Baldwin.Vt device_t
289855ed4c5SJohn Baldwinof a PCI device, given its
290855ed4c5SJohn Baldwin.Fa domain ,
291855ed4c5SJohn Baldwin.Fa bus ,
292855ed4c5SJohn Baldwin.Fa slot ,
293855ed4c5SJohn Baldwinand
294855ed4c5SJohn Baldwin.Fa func .
295855ed4c5SJohn BaldwinThe
296855ed4c5SJohn Baldwin.Fa slot
297855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
298855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
299855ed4c5SJohn Baldwinin terms of a physical slot.
300855ed4c5SJohn Baldwin.Pp
301855ed4c5SJohn BaldwinThe
302855ed4c5SJohn Baldwin.Fn pci_find_device
303855ed4c5SJohn Baldwinfunction looks up the
304855ed4c5SJohn Baldwin.Vt device_t
305855ed4c5SJohn Baldwinof a PCI device, given its
306855ed4c5SJohn Baldwin.Fa vendor
307855ed4c5SJohn Baldwinand
308855ed4c5SJohn Baldwin.Fa device
309855ed4c5SJohn BaldwinIDs.
310855ed4c5SJohn BaldwinNote that there can be multiple matches for this search; this function
311855ed4c5SJohn Baldwinonly returns the first matching device.
312855ed4c5SJohn Baldwin.Ss Device Information
313855ed4c5SJohn BaldwinThe
314855ed4c5SJohn Baldwin.Fn pci_find_cap
315855ed4c5SJohn Baldwinfunction is used to locate the first instance of a PCI capability
316855ed4c5SJohn Baldwinregister set for the device
317855ed4c5SJohn Baldwin.Fa dev .
318855ed4c5SJohn BaldwinThe capability to locate is specified by ID via
319855ed4c5SJohn Baldwin.Fa capability .
320855ed4c5SJohn BaldwinConstant macros of the form
321855ed4c5SJohn Baldwin.Dv PCIY_xxx
322855ed4c5SJohn Baldwinfor standard capability IDs are defined in
323855ed4c5SJohn Baldwin.In dev/pci/pcireg.h .
324855ed4c5SJohn BaldwinIf the capability is found, then
325855ed4c5SJohn Baldwin.Fa *capreg
326281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
327855ed4c5SJohn Baldwinand
328855ed4c5SJohn Baldwin.Fn pci_find_cap
329855ed4c5SJohn Baldwinreturns zero.
330855ed4c5SJohn BaldwinIf the capability is not found or the device does not support capabilities,
331855ed4c5SJohn Baldwin.Fn pci_find_cap
332855ed4c5SJohn Baldwinreturns an error.
333855ed4c5SJohn Baldwin.Pp
334855ed4c5SJohn BaldwinThe
33568bf9717SJohn Baldwin.Fn pci_find_extcap
33668bf9717SJohn Baldwinfunction is used to locate the first instance of a PCI-express
33768bf9717SJohn Baldwinextended capability register set for the device
33868bf9717SJohn Baldwin.Fa dev .
33968bf9717SJohn BaldwinThe extended capability to locate is specified by ID via
34068bf9717SJohn Baldwin.Fa capability .
34168bf9717SJohn BaldwinConstant macros of the form
34268bf9717SJohn Baldwin.Dv PCIZ_xxx
34368bf9717SJohn Baldwinfor standard extended capability IDs are defined in
34468bf9717SJohn Baldwin.In dev/pci/pcireg.h .
34568bf9717SJohn BaldwinIf the extended capability is found, then
34668bf9717SJohn Baldwin.Fa *capreg
347281a359eSJohn Baldwinis set to the offset in configuration space of the extended capability
34868bf9717SJohn Baldwinregister set, and
34968bf9717SJohn Baldwin.Fn pci_find_extcap
35068bf9717SJohn Baldwinreturns zero.
35168bf9717SJohn BaldwinIf the extended capability is not found or the device is not a
35268bf9717SJohn BaldwinPCI-express device,
35368bf9717SJohn Baldwin.Fn pci_find_extcap
35468bf9717SJohn Baldwinreturns an error.
35568bf9717SJohn Baldwin.Pp
35668bf9717SJohn BaldwinThe
35768bf9717SJohn Baldwin.Fn pci_find_htcap
35868bf9717SJohn Baldwinfunction is used to locate the first instance of a HyperTransport capability
35968bf9717SJohn Baldwinregister set for the device
36068bf9717SJohn Baldwin.Fa dev .
36168bf9717SJohn BaldwinThe capability to locate is specified by type via
36268bf9717SJohn Baldwin.Fa capability .
36368bf9717SJohn BaldwinConstant macros of the form
36468bf9717SJohn Baldwin.Dv PCIM_HTCAP_xxx
36568bf9717SJohn Baldwinfor standard HyperTransport capability types are defined in
36668bf9717SJohn Baldwin.In dev/pci/pcireg.h .
36768bf9717SJohn BaldwinIf the capability is found, then
36868bf9717SJohn Baldwin.Fa *capreg
369281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
37068bf9717SJohn Baldwinand
37168bf9717SJohn Baldwin.Fn pci_find_htcap
37268bf9717SJohn Baldwinreturns zero.
37368bf9717SJohn BaldwinIf the capability is not found or the device is not a HyperTransport device,
37468bf9717SJohn Baldwin.Fn pci_find_htcap
37568bf9717SJohn Baldwinreturns an error.
37668bf9717SJohn Baldwin.Pp
37768bf9717SJohn BaldwinThe
37887dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
37987dd2f95SJohn Baldwinfunction walks up the PCI device hierarchy to locate the PCI-express root
38087dd2f95SJohn Baldwinport upstream of
38187dd2f95SJohn Baldwin.Fa dev .
38287dd2f95SJohn BaldwinIf a root port is not found,
38387dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
38487dd2f95SJohn Baldwinreturns
38587dd2f95SJohn Baldwin.Dv NULL .
38687dd2f95SJohn Baldwin.Pp
38787dd2f95SJohn BaldwinThe
388d7be980dSAndrew Turner.Fn pci_get_id
389d7be980dSAndrew Turnerfunction is used to read an identifier from a device.
390d7be980dSAndrew TurnerThe
391d7be980dSAndrew Turner.Fa type
392d7be980dSAndrew Turnerflag is used to specify which identifier to read.
393d7be980dSAndrew TurnerThe following flags are supported:
394d7be980dSAndrew Turner.Bl -hang -width ".Dv PCI_ID_RID"
395d7be980dSAndrew Turner.It Dv PCI_ID_RID
396d7be980dSAndrew TurnerRead the routing identifier for the device.
3971e43b18cSAndrew Turner.It Dv PCI_ID_MSI
3981e43b18cSAndrew TurnerRead the MSI routing ID.
3991e43b18cSAndrew TurnerThis is needed by some interrupt controllers to route MSI and MSI-X interrupts.
400d7be980dSAndrew Turner.El
401d7be980dSAndrew Turner.Pp
402d7be980dSAndrew TurnerThe
403855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
404855ed4c5SJohn Baldwinfunction is used to fetch a device's Vital Product Data
405855ed4c5SJohn Baldwin.Pq VPD
406855ed4c5SJohn Baldwinidentifier string.
407855ed4c5SJohn BaldwinIf the device
408855ed4c5SJohn Baldwin.Fa dev
409855ed4c5SJohn Baldwinsupports VPD and provides an identifier string,
410855ed4c5SJohn Baldwinthen
411855ed4c5SJohn Baldwin.Fa *identptr
412855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the identifier
413855ed4c5SJohn Baldwinstring,
414855ed4c5SJohn Baldwinand
415855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
416855ed4c5SJohn Baldwinreturns zero.
417855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide an identifier
418855ed4c5SJohn Baldwinstring,
419855ed4c5SJohn Baldwinthen
420855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
421855ed4c5SJohn Baldwinreturns an error.
422855ed4c5SJohn Baldwin.Pp
423855ed4c5SJohn BaldwinThe
424855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
425855ed4c5SJohn Baldwinfunction is used to fetch the value of a single VPD read-only keyword
426855ed4c5SJohn Baldwinfor the device
427855ed4c5SJohn Baldwin.Fa dev .
428855ed4c5SJohn BaldwinThe keyword to fetch is identified by the two character string
429855ed4c5SJohn Baldwin.Fa kw .
430855ed4c5SJohn BaldwinIf the device supports VPD and provides a read-only value for the
431855ed4c5SJohn Baldwinrequested keyword,
432855ed4c5SJohn Baldwinthen
433855ed4c5SJohn Baldwin.Fa *vptr
434855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the value,
435855ed4c5SJohn Baldwinand
436855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
437855ed4c5SJohn Baldwinreturns zero.
438855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide the requested
439855ed4c5SJohn Baldwinkeyword,
440855ed4c5SJohn Baldwinthen
441855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
442855ed4c5SJohn Baldwinreturns an error.
443*da0fc925SJohn Baldwin.Pp
444*da0fc925SJohn BaldwinThe
445*da0fc925SJohn Baldwin.Fn pcie_get_max_completion_timeout
446*da0fc925SJohn Baldwinfunction returns the maximum completion timeout configured for the device
447*da0fc925SJohn Baldwin.Fa dev
448*da0fc925SJohn Baldwinin microseconds.
449*da0fc925SJohn BaldwinIf the
450*da0fc925SJohn Baldwin.Fa dev
451*da0fc925SJohn Baldwindevice is not a PCI-express device,
452*da0fc925SJohn Baldwin.Fn pcie_get_max_completion_timeout
453*da0fc925SJohn Baldwinreturns zero.
454*da0fc925SJohn BaldwinWhen completion timeouts are disabled for
455*da0fc925SJohn Baldwin.Fa dev ,
456*da0fc925SJohn Baldwinthis function returns the maxmimum timeout that would be used if timeouts
457*da0fc925SJohn Baldwinwere enabled.
458*da0fc925SJohn Baldwin.Pp
459*da0fc925SJohn BaldwinThe
460*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions
461*da0fc925SJohn Baldwinfunction waits for any pending transactions initiated by the
462*da0fc925SJohn Baldwin.Fa dev
463*da0fc925SJohn Baldwindevice to complete.
464*da0fc925SJohn BaldwinThe function checks for pending transactions by polling the transactions
465*da0fc925SJohn Baldwinpending flag in the PCI-express device status register.
466*da0fc925SJohn BaldwinIt returns
467*da0fc925SJohn Baldwin.Dv true
468*da0fc925SJohn Baldwinonce the transaction pending flag is clear.
469*da0fc925SJohn BaldwinIf transactions are still pending after
470*da0fc925SJohn Baldwin.Fa max_delay
471*da0fc925SJohn Baldwinmilliseconds,
472*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions
473*da0fc925SJohn Baldwinreturns
474*da0fc925SJohn Baldwin.Dv false .
475*da0fc925SJohn BaldwinIf
476*da0fc925SJohn Baldwin.Fa max_delay
477*da0fc925SJohn Baldwinis set to zero,
478*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions
479*da0fc925SJohn Baldwinperforms a single check;
480*da0fc925SJohn Baldwinotherwise,
481*da0fc925SJohn Baldwinthis function may sleep while polling the transactions pending flag.
482*da0fc925SJohn Baldwin.Nm pcie_wait_for_pending_transactions
483*da0fc925SJohn Baldwinreturns
484*da0fc925SJohn Baldwin.Dv true
485*da0fc925SJohn Baldwinif
486*da0fc925SJohn Baldwin.Fa dev
487*da0fc925SJohn Baldwinis not a PCI-express device.
488855ed4c5SJohn Baldwin.Ss Device Configuration
489aac0aafaSHiten PandyaThe
490aac0aafaSHiten Pandya.Fn pci_enable_busmaster
491aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device
492aac0aafaSHiten Pandya.Fa dev ,
493aac0aafaSHiten Pandyaby setting the
494aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN
495aac0aafaSHiten Pandyabit in the
496aac0aafaSHiten Pandya.Dv PCIR_COMMAND
497aac0aafaSHiten Pandyaregister.
498aac0aafaSHiten PandyaThe
499aac0aafaSHiten Pandya.Fn pci_disable_busmaster
500aac0aafaSHiten Pandyafunction clears this bit.
501aac0aafaSHiten Pandya.Pp
502aac0aafaSHiten PandyaThe
503aac0aafaSHiten Pandya.Fn pci_enable_io
504aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device
505aac0aafaSHiten Pandya.Fa dev ,
506aac0aafaSHiten Pandyaby setting the
507aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN
508aac0aafaSHiten Pandyaor
509aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN
510aac0aafaSHiten Pandyabit in the
511aac0aafaSHiten Pandya.Dv PCIR_COMMAND
5125203edcdSRuslan Ermilovregister appropriately.
5135203edcdSRuslan ErmilovThe
514aac0aafaSHiten Pandya.Fn pci_disable_io
515aac0aafaSHiten Pandyafunction clears the appropriate bit.
516aac0aafaSHiten PandyaThe
51765bb31b8SRuslan Ermilov.Fa space
518aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either
519aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY
520aac0aafaSHiten Pandyaor
521aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT
522aac0aafaSHiten Pandyaas appropriate.
523855ed4c5SJohn BaldwinDevice drivers should generally not use these routines directly.
524855ed4c5SJohn BaldwinThe PCI bus will enable decoding automatically when a
525855ed4c5SJohn Baldwin.Dv SYS_RES_MEMORY
526855ed4c5SJohn Baldwinor
527855ed4c5SJohn Baldwin.Dv SYS_RES_IOPORT
528855ed4c5SJohn Baldwinresource is activated via
529855ed4c5SJohn Baldwin.Xr bus_alloc_resource 9
530855ed4c5SJohn Baldwinor
531855ed4c5SJohn Baldwin.Xr bus_activate_resource 9 .
532aac0aafaSHiten Pandya.Pp
533855ed4c5SJohn BaldwinThe
5342ab0398dSJohn Baldwin.Fn pci_get_max_payload
5352ab0398dSJohn Baldwinfunction returns the current maximum TLP payload size in bytes for a
5362ab0398dSJohn BaldwinPCI-express device.
5372ab0398dSJohn BaldwinIf the
5382ab0398dSJohn Baldwin.Fa dev
5392ab0398dSJohn Baldwindevice is not a PCI-express device,
5402ab0398dSJohn Baldwin.Fn pci_get_max_payload
5412ab0398dSJohn Baldwinreturns zero.
5422ab0398dSJohn Baldwin.Pp
5432ab0398dSJohn BaldwinThe
544855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
545855ed4c5SJohn Baldwinfunction returns the current maximum read request size in bytes for a
546855ed4c5SJohn BaldwinPCI-express device.
547855ed4c5SJohn BaldwinIf the
548855ed4c5SJohn Baldwin.Fa dev
549855ed4c5SJohn Baldwindevice is not a PCI-express device,
550855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
551855ed4c5SJohn Baldwinreturns zero.
552855ed4c5SJohn Baldwin.Pp
553855ed4c5SJohn BaldwinThe
554855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
555855ed4c5SJohn Baldwinsets the PCI-express maximum read request size for
556855ed4c5SJohn Baldwin.Fa dev .
557855ed4c5SJohn BaldwinThe requested
558855ed4c5SJohn Baldwin.Fa size
559855ed4c5SJohn Baldwinmay be adjusted,
560855ed4c5SJohn Baldwinand
561855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
562855ed4c5SJohn Baldwinreturns the actual size set in bytes.
563855ed4c5SJohn BaldwinIf the
564855ed4c5SJohn Baldwin.Fa dev
565855ed4c5SJohn Baldwindevice is not a PCI-express device,
566855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
567855ed4c5SJohn Baldwinreturns zero.
568aac0aafaSHiten Pandya.Pp
569aac0aafaSHiten PandyaThe
570aac0aafaSHiten Pandya.Fn pci_get_powerstate
571adb63907SJohn Baldwinfunction returns the current power state of the device
572aac0aafaSHiten Pandya.Fa dev .
573aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default
574aac0aafaSHiten Pandyastate of
575aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0
576aac0aafaSHiten Pandyais returned.
577adb63907SJohn BaldwinThe following power states are defined by PCI:
57865bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
579aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0
580aac0aafaSHiten PandyaState in which device is on and running.
581aac0aafaSHiten PandyaIt is receiving full power from the system and delivering
582aac0aafaSHiten Pandyafull functionality to the user.
583aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1
584aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
5855a2e3b61SDaniel Gerzomay not be lost.
58665bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to
5879817b894SBruce M Simpsonforce devices to lose context.
588aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2
589aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
590aac0aafaSHiten Pandyamay not be lost.
591aac0aafaSHiten PandyaAttains greater power savings than
592aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 .
59365bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context.
594aac0aafaSHiten PandyaDevices
595aac0aafaSHiten Pandya.Em must
596aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher.
597aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3
598aac0aafaSHiten PandyaState in which the device is off and not running.
599aac0aafaSHiten PandyaDevice context is lost, and power from the device can
600aac0aafaSHiten Pandyabe removed.
601aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN
602aac0aafaSHiten PandyaState of the device is unknown.
603aac0aafaSHiten Pandya.El
604aac0aafaSHiten Pandya.Pp
605aac0aafaSHiten PandyaThe
606aac0aafaSHiten Pandya.Fn pci_set_powerstate
607aac0aafaSHiten Pandyafunction is used to transition the device
608aac0aafaSHiten Pandya.Fa dev
609adb63907SJohn Baldwinto the PCI power state
610aac0aafaSHiten Pandya.Fa state .
611adb63907SJohn BaldwinIf the device does not support power management capabilities or
612adb63907SJohn Baldwinit does not support the specific power state
613adb63907SJohn Baldwin.Fa state ,
614adb63907SJohn Baldwinthen the function will fail with
615adb63907SJohn Baldwin.Er EOPNOTSUPP .
616aac0aafaSHiten Pandya.Pp
617aac0aafaSHiten PandyaThe
6187d971e36SRyan Stone.Fn pci_iov_attach
6197d971e36SRyan Stonefunction is used to advertise that the given device
6207d971e36SRyan Stone.Pq and associated device driver
6217d971e36SRyan Stonesupports PCI Single-Root I/O Virtualization
622fe3ff217SPatrick Kelsey.Pq SR-IOV .
6237d971e36SRyan StoneA driver that supports SR-IOV must implement the
624f3bb9251SJohn Baldwin.Xr PCI_IOV_INIT 9 ,
625f3bb9251SJohn Baldwin.Xr PCI_IOV_ADD_VF 9
6267d971e36SRyan Stoneand
627f3bb9251SJohn Baldwin.Xr PCI_IOV_UNINIT 9
6287d971e36SRyan Stonemethods.
6297d971e36SRyan StoneThis function should be called during the
6307d971e36SRyan Stone.Xr DEVICE_ATTACH 9
6317d971e36SRyan Stonemethod.
6327d971e36SRyan StoneIf this function returns an error, it is recommended that the device driver
6337d971e36SRyan Stonestill successfully attaches, but runs with SR-IOV disabled.
6347d971e36SRyan StoneThe
6357d971e36SRyan Stone.Fa pf_schema
6367d971e36SRyan Stoneand
6377d971e36SRyan Stone.Fa vf_schema
6387d971e36SRyan Stoneparameters are used to define what device-specific configuration parameters the
6397d971e36SRyan Stonedevice driver accepts when SR-IOV is enabled for the Physical Function
6407d971e36SRyan Stone.Pq PF
6417d971e36SRyan Stoneand for individual Virtual Functions
6427d971e36SRyan Stone.Pq VFs
6437d971e36SRyan Stonerespectively.
6447d971e36SRyan StoneSee
6457d971e36SRyan Stone.Xr pci_iov_schema 9
6467d971e36SRyan Stonefor details on how to construct the schema.
6477d971e36SRyan StoneIf either the
6487d971e36SRyan Stone.Pa pf_schema
6497d971e36SRyan Stoneor
6507d971e36SRyan Stone.Pa vf_schema
6517d971e36SRyan Stoneis invalid or specifies parameter names that conflict with parameter names that
6527d971e36SRyan Stoneare already in use,
6537d971e36SRyan Stone.Fn pci_iov_attach
6547d971e36SRyan Stonewill return an error and SR-IOV will not be available on the PF device.
6557d971e36SRyan StoneIf a driver does not accept configuration parameters for either the PF device
6567d971e36SRyan Stoneor the VF devices, the driver must pass an empty schema for that device.
6577d971e36SRyan StoneThe SR-IOV infrastructure takes ownership of the
6587d971e36SRyan Stone.Fa pf_schema
6597d971e36SRyan Stoneand
6607d971e36SRyan Stone.Fa vf_schema
6617d971e36SRyan Stoneand is responsible for freeing them.
6627d971e36SRyan StoneThe driver must never free the schemas itself.
6637d971e36SRyan Stone.Pp
6647d971e36SRyan StoneThe
6650aee83ccSJohn Baldwin.Fn pci_iov_attach_name
6660aee83ccSJohn Baldwinfunction is a variant of
6670aee83ccSJohn Baldwin.Fn pci_iov_attach
6680aee83ccSJohn Baldwinthat allows the name of the associated character device in
6690aee83ccSJohn Baldwin.Pa /dev/iov
6700aee83ccSJohn Baldwinto be specified by
6710aee83ccSJohn Baldwin.Fa fmt .
6720aee83ccSJohn BaldwinThe
6730aee83ccSJohn Baldwin.Fn pci_iov_attach
6740aee83ccSJohn Baldwinfunction uses the name of
6750aee83ccSJohn Baldwin.Fa dev
6760aee83ccSJohn Baldwinas the device name.
6770aee83ccSJohn Baldwin.Pp
6780aee83ccSJohn BaldwinThe
6797d971e36SRyan Stone.Fn pci_iov_detach
6807d971e36SRyan Stonefunction is used to advise the SR-IOV infrastructure that the driver for the
6817d971e36SRyan Stonegiven device is attempting to detach and that all SR-IOV resources for the
6827d971e36SRyan Stonedevice must be released.
6837d971e36SRyan StoneThis function must be called during the
6847d971e36SRyan Stone.Xr DEVICE_DETACH 9
6857d971e36SRyan Stonemethod if
6867d971e36SRyan Stone.Fn pci_iov_attach
6877d971e36SRyan Stonewas successfully called on the device and
6887d971e36SRyan Stone.Fn pci_iov_detach
6897d971e36SRyan Stonehas not subsequently been called on the device and returned no error.
6907d971e36SRyan StoneIf this function returns an error, the
6917d971e36SRyan Stone.Xr DEVICE_DETACH 9
6927d971e36SRyan Stonemethod must fail and return an error, as detaching the PF driver while VF
6937d971e36SRyan Stonedevices are active would cause system instability.
6947d971e36SRyan StoneThis function is safe to call and will always succeed if
6957d971e36SRyan Stone.Fn pci_iov_attach
6967d971e36SRyan Stonepreviously failed with an error on the given device, or if
6977d971e36SRyan Stone.Fn pci_iov_attach
6987d971e36SRyan Stonewas never called on the device.
6997d971e36SRyan Stone.Pp
7007d971e36SRyan StoneThe
7019415d1e0SJohn Baldwin.Fn pci_save_state
7029415d1e0SJohn Baldwinand
7039415d1e0SJohn Baldwin.Fn pci_restore_state
7049415d1e0SJohn Baldwinfunctions can be used by a device driver to save and restore standard PCI
7059415d1e0SJohn Baldwinconfig registers.
7069415d1e0SJohn BaldwinThe
7079415d1e0SJohn Baldwin.Fn pci_save_state
7089415d1e0SJohn Baldwinfunction must be invoked while the device has valid state before
7099415d1e0SJohn Baldwin.Fn pci_restore_state
7109415d1e0SJohn Baldwincan be used.
7119415d1e0SJohn BaldwinIf the device is not in the fully-powered state
7129415d1e0SJohn Baldwin.Pq Dv PCI_POWERSTATE_D0
7139415d1e0SJohn Baldwinwhen
7149415d1e0SJohn Baldwin.Fn pci_restore_state
7159415d1e0SJohn Baldwinis invoked,
7169415d1e0SJohn Baldwinthen the device will be transitioned to
7179415d1e0SJohn Baldwin.Dv PCI_POWERSTATE_D0
7189415d1e0SJohn Baldwinbefore any config registers are restored.
719*da0fc925SJohn Baldwin.Pp
720*da0fc925SJohn BaldwinThe
721*da0fc925SJohn Baldwin.Fn pcie_flr
722*da0fc925SJohn Baldwinfunction requests a Function Level Reset
723*da0fc925SJohn Baldwin.Pq FLR
724*da0fc925SJohn Baldwinof
725*da0fc925SJohn Baldwin.Fa dev .
726*da0fc925SJohn BaldwinIf
727*da0fc925SJohn Baldwin.Fa dev
728*da0fc925SJohn Baldwinis not a PCI-express device or does not support Function Level Resets via
729*da0fc925SJohn Baldwinthe PCI-express device control register,
730*da0fc925SJohn Baldwin.Dv false
731*da0fc925SJohn Baldwinis returned.
732*da0fc925SJohn BaldwinPending transactions are drained by disabling busmastering and calling
733*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions
734*da0fc925SJohn Baldwinbefore resetting the device.
735*da0fc925SJohn BaldwinThe
736*da0fc925SJohn Baldwin.Fa max_delay
737*da0fc925SJohn Baldwinargument specifies the maximum timeout to wait for pending transactions as
738*da0fc925SJohn Baldwindescribed for
739*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions .
740*da0fc925SJohn BaldwinIf
741*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions
742*da0fc925SJohn Baldwinfails with a timeout and
743*da0fc925SJohn Baldwin.Fa force
744*da0fc925SJohn Baldwinis
745*da0fc925SJohn Baldwin.Dv false ,
746*da0fc925SJohn Baldwinbusmastering is re-enabled and
747*da0fc925SJohn Baldwin.Dv false
748*da0fc925SJohn Baldwinis returned.
749*da0fc925SJohn BaldwinIf
750*da0fc925SJohn Baldwin.Fn pcie_wait_for_pending_transactions
751*da0fc925SJohn Baldwinfails with a timeout and
752*da0fc925SJohn Baldwin.Fa force
753*da0fc925SJohn Baldwinis
754*da0fc925SJohn Baldwin.Dv true ,
755*da0fc925SJohn Baldwinthe device is reset despite the timeout.
756*da0fc925SJohn BaldwinAfter the reset has been requested,
757*da0fc925SJohn Baldwin.Nm pcie_flr
758*da0fc925SJohn Baldwinsleeps for at least 100 milliseconds before returning
759*da0fc925SJohn Baldwin.Dv true .
760*da0fc925SJohn BaldwinNote that
761*da0fc925SJohn Baldwin.Nm pcie_flr
762*da0fc925SJohn Baldwindoes not save and restore any state around the reset.
763*da0fc925SJohn BaldwinThe caller should save and restore state as needed.
764855ed4c5SJohn Baldwin.Ss Message Signaled Interrupts
765855ed4c5SJohn BaldwinMessage Signaled Interrupts
766855ed4c5SJohn Baldwin.Pq MSI
767855ed4c5SJohn Baldwinand
768855ed4c5SJohn BaldwinEnhanced Message Signaled Interrupts
769855ed4c5SJohn Baldwin.Pq MSI-X
770855ed4c5SJohn Baldwinare PCI capabilities that provide an alternate method for PCI
771855ed4c5SJohn Baldwindevices to signal interrupts.
772855ed4c5SJohn BaldwinThe legacy INTx interrupt is available to PCI devices as a
773855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
774855ed4c5SJohn Baldwinresource with a resource ID of zero.
775855ed4c5SJohn BaldwinMSI and MSI-X interrupts are available to PCI devices as one or more
776855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
777855ed4c5SJohn Baldwinresources with resource IDs greater than zero.
778855ed4c5SJohn BaldwinA driver must ask the PCI bus to allocate MSI or MSI-X interrupts
779855ed4c5SJohn Baldwinusing
780855ed4c5SJohn Baldwin.Fn pci_alloc_msi
781855ed4c5SJohn Baldwinor
782855ed4c5SJohn Baldwin.Fn pci_alloc_msix
783855ed4c5SJohn Baldwinbefore it can use MSI or MSI-X
784855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
785855ed4c5SJohn Baldwinresources.
786855ed4c5SJohn BaldwinA driver is not allowed to use the legacy INTx
787855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
788855ed4c5SJohn Baldwinresource if MSI or MSI-X interrupts have been allocated,
789855ed4c5SJohn Baldwinand attempts to allocate MSI or MSI-X interrupts will fail if the
790855ed4c5SJohn Baldwindriver is currently using the legacy INTx
791855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
792855ed4c5SJohn Baldwinresource.
793855ed4c5SJohn BaldwinA driver is only allowed to use either MSI or MSI-X,
794855ed4c5SJohn Baldwinbut not both.
7959415d1e0SJohn Baldwin.Pp
7969415d1e0SJohn BaldwinThe
797563d4639SMark Johnston.Fn pci_msi_count
798855ed4c5SJohn Baldwinfunction returns the maximum number of MSI messages supported by the
799855ed4c5SJohn Baldwindevice
800855ed4c5SJohn Baldwin.Fa dev .
801855ed4c5SJohn BaldwinIf the device does not support MSI,
802855ed4c5SJohn Baldwinthen
803563d4639SMark Johnston.Fn pci_msi_count
804855ed4c5SJohn Baldwinreturns zero.
80555aaf894SMarius Strobl.Pp
80655aaf894SMarius StroblThe
807855ed4c5SJohn Baldwin.Fn pci_alloc_msi
808855ed4c5SJohn Baldwinfunction attempts to allocate
809855ed4c5SJohn Baldwin.Fa *count
810855ed4c5SJohn BaldwinMSI messages for the device
811855ed4c5SJohn Baldwin.Fa dev .
81255aaf894SMarius StroblThe
813855ed4c5SJohn Baldwin.Fn pci_alloc_msi
814855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
815855ed4c5SJohn Baldwinreasons including requests for more messages than the device
816855ed4c5SJohn Baldwin.Fa dev
817855ed4c5SJohn Baldwinsupports,
818855ed4c5SJohn Baldwinor if the system has a shortage of available MSI messages.
819855ed4c5SJohn BaldwinOn success,
820855ed4c5SJohn Baldwin.Fa *count
821855ed4c5SJohn Baldwinis set to the number of messages allocated and
822855ed4c5SJohn Baldwin.Fn pci_alloc_msi
823855ed4c5SJohn Baldwinreturns zero.
824855ed4c5SJohn BaldwinThe
825855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
826855ed4c5SJohn Baldwinresources for the allocated messages will be available at consecutive
827855ed4c5SJohn Baldwinresource IDs beginning with one.
828855ed4c5SJohn BaldwinIf
829855ed4c5SJohn Baldwin.Fn pci_alloc_msi
830855ed4c5SJohn Baldwinis not able to allocate any messages,
831855ed4c5SJohn Baldwinit returns an error.
832855ed4c5SJohn BaldwinNote that MSI only supports message counts that are powers of two;
833855ed4c5SJohn Baldwinrequests to allocate a non-power of two count of messages will fail.
834aac0aafaSHiten Pandya.Pp
835aac0aafaSHiten PandyaThe
836855ed4c5SJohn Baldwin.Fn pci_release_msi
837855ed4c5SJohn Baldwinfunction is used to release any allocated MSI or MSI-X messages back
838855ed4c5SJohn Baldwinto the system.
839855ed4c5SJohn BaldwinIf any MSI or MSI-X
840855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
841855ed4c5SJohn Baldwinresources are allocated by the driver or have a configured interrupt
842855ed4c5SJohn Baldwinhandler,
843855ed4c5SJohn Baldwinthis function will fail with
844855ed4c5SJohn Baldwin.Er EBUSY .
845855ed4c5SJohn BaldwinThe
846855ed4c5SJohn Baldwin.Fn pci_release_msi
847855ed4c5SJohn Baldwinfunction returns zero on success and an error on failure.
848855ed4c5SJohn Baldwin.Pp
849642c4993SSergey KandaurovThe
850563d4639SMark Johnston.Fn pci_msix_count
851855ed4c5SJohn Baldwinfunction returns the maximum number of MSI-X messages supported by the
852855ed4c5SJohn Baldwindevice
853855ed4c5SJohn Baldwin.Fa dev .
854855ed4c5SJohn BaldwinIf the device does not support MSI-X,
855855ed4c5SJohn Baldwinthen
856563d4639SMark Johnston.Fn pci_msix_count
857855ed4c5SJohn Baldwinreturns zero.
858855ed4c5SJohn Baldwin.Pp
859855ed4c5SJohn BaldwinThe
860ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
861ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the Base Address Register
862ce204e1bSJohn Baldwin.Pq BAR
863ce204e1bSJohn Baldwincontaining the MSI-X Pending Bit Array (PBA) for device
864ce204e1bSJohn Baldwin.Fa dev .
865ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
866ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
867ce204e1bSJohn Baldwinand
868ce204e1bSJohn Baldwin.Xr bus_release_resource 9
869ce204e1bSJohn Baldwinto allocate the BAR.
870ce204e1bSJohn BaldwinIf the device does not support MSI-X,
871ce204e1bSJohn Baldwinthen
872ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
873ce204e1bSJohn Baldwinreturns -1.
874ce204e1bSJohn Baldwin.Pp
875ce204e1bSJohn BaldwinThe
876ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
877ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the BAR
878ce204e1bSJohn Baldwincontaining the MSI-X vector table for device
879ce204e1bSJohn Baldwin.Fa dev .
880ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
881ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
882ce204e1bSJohn Baldwinand
883ce204e1bSJohn Baldwin.Xr bus_release_resource 9
884ce204e1bSJohn Baldwinto allocate the BAR.
885ce204e1bSJohn BaldwinIf the device does not support MSI-X,
886ce204e1bSJohn Baldwinthen
887ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
888ce204e1bSJohn Baldwinreturns -1.
889ce204e1bSJohn Baldwin.Pp
890ce204e1bSJohn BaldwinThe
891855ed4c5SJohn Baldwin.Fn pci_alloc_msix
892855ed4c5SJohn Baldwinfunction attempts to allocate
893855ed4c5SJohn Baldwin.Fa *count
894855ed4c5SJohn BaldwinMSI-X messages for the device
895855ed4c5SJohn Baldwin.Fa dev .
896855ed4c5SJohn BaldwinThe
897855ed4c5SJohn Baldwin.Fn pci_alloc_msix
898855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
899855ed4c5SJohn Baldwinreasons including requests for more messages than the device
900855ed4c5SJohn Baldwin.Fa dev
901855ed4c5SJohn Baldwinsupports,
902855ed4c5SJohn Baldwinor if the system has a shortage of available MSI-X messages.
903855ed4c5SJohn BaldwinOn success,
904855ed4c5SJohn Baldwin.Fa *count
905855ed4c5SJohn Baldwinis set to the number of messages allocated and
906855ed4c5SJohn Baldwin.Fn pci_alloc_msix
907855ed4c5SJohn Baldwinreturns zero.
908855ed4c5SJohn BaldwinFor MSI-X messages,
909855ed4c5SJohn Baldwinthe resource ID for each
91073bbeaa5SGlen Barber.Dv SYS_RES_IRQ
91173bbeaa5SGlen Barberresource identifies the index in the MSI-X table of the
912855ed4c5SJohn Baldwincorresponding message.
913855ed4c5SJohn BaldwinA resource ID of one maps to the first index of the MSI-X table;
914855ed4c5SJohn Baldwina resource ID two identifies the second index in the table, etc.
915855ed4c5SJohn BaldwinThe
916855ed4c5SJohn Baldwin.Fn pci_alloc_msix
917855ed4c5SJohn Baldwinfunction assigns the
918855ed4c5SJohn Baldwin.Fa *count
919855ed4c5SJohn Baldwinmessages allocated to the first
920855ed4c5SJohn Baldwin.Fa *count
9217c64ddd5SWarren Blocktable indices.
922855ed4c5SJohn BaldwinIf
923855ed4c5SJohn Baldwin.Fn pci_alloc_msix
924855ed4c5SJohn Baldwinis not able to allocate any messages,
925855ed4c5SJohn Baldwinit returns an error.
926855ed4c5SJohn BaldwinUnlike MSI,
927855ed4c5SJohn BaldwinMSI-X does not require message counts that are powers of two.
928855ed4c5SJohn Baldwin.Pp
929ce204e1bSJohn BaldwinThe BARs containing the MSI-X vector table and PBA must be
930ce204e1bSJohn Baldwinallocated via
931ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
932ce204e1bSJohn Baldwinbefore calling
933ce204e1bSJohn Baldwin.Fn pci_alloc_msix
934ce204e1bSJohn Baldwinand must not be released until after calling
935ce204e1bSJohn Baldwin.Fn pci_release_msi .
936ce204e1bSJohn BaldwinNote that the vector table and PBA may be stored in the same BAR or in
937ce204e1bSJohn Baldwindifferent BARs.
938ce204e1bSJohn Baldwin.Pp
939855ed4c5SJohn BaldwinThe
940855ed4c5SJohn Baldwin.Fn pci_pending_msix
941855ed4c5SJohn Baldwinfunction examines the
942855ed4c5SJohn Baldwin.Fa dev
943ce204e1bSJohn Baldwindevice's PBA
944855ed4c5SJohn Baldwinto determine the pending status of the MSI-X message at table index
945855ed4c5SJohn Baldwin.Fa index .
946855ed4c5SJohn BaldwinIf the indicated message is pending,
947855ed4c5SJohn Baldwinthis function returns a non-zero value;
948855ed4c5SJohn Baldwinotherwise,
949855ed4c5SJohn Baldwinit returns zero.
950855ed4c5SJohn BaldwinPassing an invalid
951855ed4c5SJohn Baldwin.Fa index
952855ed4c5SJohn Baldwinto this function will result in undefined behavior.
953855ed4c5SJohn Baldwin.Pp
954855ed4c5SJohn BaldwinAs mentioned in the description of
955855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
956855ed4c5SJohn BaldwinMSI-X messages are initially assigned to the first N table entries.
957855ed4c5SJohn BaldwinA driver may use a different distribution of available messages to
958855ed4c5SJohn Baldwintable entries via the
959855ed4c5SJohn Baldwin.Fn pci_remap_msix
960855ed4c5SJohn Baldwinfunction.
96173bbeaa5SGlen BarberNote that this function must be called after a successful call to
962855ed4c5SJohn Baldwin.Fn pci_alloc_msix
963855ed4c5SJohn Baldwinbut before any of the
964855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
965855ed4c5SJohn Baldwinresources are allocated.
966855ed4c5SJohn BaldwinThe
967855ed4c5SJohn Baldwin.Fn pci_remap_msix
968855ed4c5SJohn Baldwinfunction returns zero on success,
969855ed4c5SJohn Baldwinor an error on failure.
970855ed4c5SJohn Baldwin.Pp
971855ed4c5SJohn BaldwinThe
972855ed4c5SJohn Baldwin.Fa vectors
973855ed4c5SJohn Baldwinarray should contain
974855ed4c5SJohn Baldwin.Fa count
975855ed4c5SJohn Baldwinmessage vectors.
976855ed4c5SJohn BaldwinThe array maps directly to the MSI-X table in that the first entry in
977855ed4c5SJohn Baldwinthe array specifies the message used for the first entry in the MSI-X
978855ed4c5SJohn Baldwintable,
979855ed4c5SJohn Baldwinthe second entry in the array corresponds to the second entry in the
980855ed4c5SJohn BaldwinMSI-X table,
981855ed4c5SJohn Baldwinetc.
982855ed4c5SJohn BaldwinThe vector value in each array index can either be zero to indicate
983855ed4c5SJohn Baldwinthat no message should be assigned to the corresponding MSI-X table entry,
984855ed4c5SJohn Baldwinor it can be a number from one to N
985855ed4c5SJohn Baldwin.Po
986855ed4c5SJohn Baldwinwhere N is the count returned from the previous call to
987855ed4c5SJohn Baldwin.Fn pci_alloc_msix
988855ed4c5SJohn Baldwin.Pc
989855ed4c5SJohn Baldwinto indicate which of the allocated messages should be assigned to the
990855ed4c5SJohn Baldwincorresponding MSI-X table entry.
991855ed4c5SJohn Baldwin.Pp
992855ed4c5SJohn BaldwinIf
993855ed4c5SJohn Baldwin.Fn pci_remap_msix
994855ed4c5SJohn Baldwinsucceeds,
995855ed4c5SJohn Baldwineach MSI-X table entry with a non-zero vector will have an associated
996855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
997855ed4c5SJohn Baldwinresource whose resource ID corresponds to the table index as described
998855ed4c5SJohn Baldwinabove for
999855ed4c5SJohn Baldwin.Fn pci_alloc_msix .
1000855ed4c5SJohn BaldwinMSI-X table entries that with a vector of zero will not have an
1001855ed4c5SJohn Baldwinassociated
100273bbeaa5SGlen Barber.Dv SYS_RES_IRQ
100373bbeaa5SGlen Barberresource.
1004855ed4c5SJohn BaldwinAdditionally,
1005855ed4c5SJohn Baldwinif any of the original messages allocated by
1006855ed4c5SJohn Baldwin.Fn pci_alloc_msix
1007855ed4c5SJohn Baldwinare not used in the new distribution of messages in the MSI-X table,
1008855ed4c5SJohn Baldwinthey will be released automatically.
1009855ed4c5SJohn BaldwinNote that if a driver wishes to use fewer messages than were allocated by
1010855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
1011855ed4c5SJohn Baldwinthe driver must use a single, contiguous range of messages beginning
1012855ed4c5SJohn Baldwinwith one in the new distribution.
1013855ed4c5SJohn BaldwinThe
1014855ed4c5SJohn Baldwin.Fn pci_remap_msix
1015855ed4c5SJohn Baldwinfunction will fail if this condition is not met.
101664414cc0SJohn Baldwin.Ss Device Events
101764414cc0SJohn BaldwinThe
101864414cc0SJohn Baldwin.Va pci_add_device
101964414cc0SJohn Baldwinevent handler is invoked every time a new PCI device is added to the system.
102064414cc0SJohn BaldwinThis includes the creation of Virtual Functions via SR-IOV.
102164414cc0SJohn Baldwin.Pp
102264414cc0SJohn BaldwinThe
102364414cc0SJohn Baldwin.Va pci_delete_device
102464414cc0SJohn Baldwinevent handler is invoked every time a PCI device is removed from the system.
102564414cc0SJohn Baldwin.Pp
102664414cc0SJohn BaldwinBoth event handlers pass the
102764414cc0SJohn Baldwin.Vt device_t
102864414cc0SJohn Baldwinobject of the relevant PCI device as
102964414cc0SJohn Baldwin.Fa dev
103064414cc0SJohn Baldwinto each callback function.
103164414cc0SJohn BaldwinBoth event handlers are invoked while
103264414cc0SJohn Baldwin.Fa dev
103364414cc0SJohn Baldwinis unattached but with valid instance variables.
1034aac0aafaSHiten Pandya.Sh SEE ALSO
10357c2c06f2SSheldon Hearn.Xr pci 4 ,
10367c2c06f2SSheldon Hearn.Xr pciconf 8 ,
1037aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 ,
1038aac0aafaSHiten Pandya.Xr bus_dma 9 ,
1039aac0aafaSHiten Pandya.Xr bus_release_resource 9 ,
1040aac0aafaSHiten Pandya.Xr bus_setup_intr 9 ,
1041aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 ,
1042aac0aafaSHiten Pandya.Xr devclass 9 ,
1043aac0aafaSHiten Pandya.Xr device 9 ,
1044aac0aafaSHiten Pandya.Xr driver 9 ,
104564414cc0SJohn Baldwin.Xr eventhandler 9 ,
1046aac0aafaSHiten Pandya.Xr rman 9
1047aac0aafaSHiten Pandya.Rs
1048aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook
1049aac0aafaSHiten Pandya.%T NewBus
1050aa4a335bSRuslan Ermilov.%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
1051aac0aafaSHiten Pandya.Re
1052aac0aafaSHiten Pandya.Rs
1053aac0aafaSHiten Pandya.%A Shanley
1054aac0aafaSHiten Pandya.%A Anderson
1055aac0aafaSHiten Pandya.%B PCI System Architecture
1056aac0aafaSHiten Pandya.%N 2nd Edition
1057aac0aafaSHiten Pandya.%I Addison-Wesley
1058aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2
1059aac0aafaSHiten Pandya.Re
1060aac0aafaSHiten Pandya.Sh AUTHORS
10618a7314fcSBaptiste Daroussin.An -nosplit
1062571dba6eSHiten PandyaThis manual page was written by
10638a7314fcSBaptiste Daroussin.An Bruce M Simpson Aq Mt bms@FreeBSD.org
1064855ed4c5SJohn Baldwinand
10658a7314fcSBaptiste Daroussin.An John Baldwin Aq Mt jhb@FreeBSD.org .
1066aac0aafaSHiten Pandya.Sh BUGS
10674d80f750SBruce M SimpsonThe kernel PCI code has a number of references to
10684d80f750SBruce M Simpson.Dq "slot numbers" .
1069bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices,
1070bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL
1071bf1639eeSBruce M Simpsonmechanism and the platform firmware.
1072bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code.
1073ce204e1bSJohn Baldwin.Pp
1074ce204e1bSJohn BaldwinThe PCI bus driver should allocate the MSI-X vector table and PBA internally
1075ce204e1bSJohn Baldwinas necessary rather than requiring the caller to do so.
1076