xref: /freebsd/share/man/man9/pci.9 (revision 64414cc00fb76d5ae12d483c3d4ae46d3009c46f)
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.\"
28*64414cc0SJohn 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 ,
69ec603c72SJohn Baldwin.Nm pcie_read_config ,
70ec603c72SJohn Baldwin.Nm pcie_write_config
71aac0aafaSHiten Pandya.Nd PCI bus interface
72aac0aafaSHiten Pandya.Sh SYNOPSIS
73aac0aafaSHiten Pandya.In sys/bus.h
74aac0aafaSHiten Pandya.In dev/pci/pcireg.h
75855ed4c5SJohn Baldwin.In dev/pci/pcivar.h
76855ed4c5SJohn Baldwin.Ft int
77855ed4c5SJohn Baldwin.Fn pci_alloc_msi "device_t dev" "int *count"
78855ed4c5SJohn Baldwin.Ft int
79855ed4c5SJohn Baldwin.Fn pci_alloc_msix "device_t dev" "int *count"
80aac0aafaSHiten Pandya.Ft int
81aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev"
82aac0aafaSHiten Pandya.Ft int
83aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space"
84aac0aafaSHiten Pandya.Ft int
850a9c80e5SJohn Baldwin.Fn pci_enable_busmaster "device_t dev"
86aac0aafaSHiten Pandya.Ft int
870a9c80e5SJohn Baldwin.Fn pci_enable_io "device_t dev" "int space"
88aac0aafaSHiten Pandya.Ft device_t
8965bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
90855ed4c5SJohn Baldwin.Ft int
91855ed4c5SJohn Baldwin.Fn pci_find_cap "device_t dev" "int capability" "int *capreg"
92aac0aafaSHiten Pandya.Ft device_t
9355aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
9455aaf894SMarius Strobl.Ft device_t
9565bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device"
960a9c80e5SJohn Baldwin.Ft int
9768bf9717SJohn Baldwin.Fn pci_find_extcap "device_t dev" "int capability" "int *capreg"
9868bf9717SJohn Baldwin.Ft int
9968bf9717SJohn Baldwin.Fn pci_find_htcap "device_t dev" "int capability" "int *capreg"
10087dd2f95SJohn Baldwin.Ft device_t
10187dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port "device_t dev"
10268bf9717SJohn Baldwin.Ft int
103d7be980dSAndrew Turner.Fn pci_get_id "device_t dev" "enum pci_id_type type" "uintptr_t *id"
104d7be980dSAndrew Turner.Ft int
1052ab0398dSJohn Baldwin.Fn pci_get_max_payload "device_t dev"
1062ab0398dSJohn Baldwin.Ft int
107855ed4c5SJohn Baldwin.Fn pci_get_max_read_req "device_t dev"
108855ed4c5SJohn Baldwin.Ft int
1090a9c80e5SJohn Baldwin.Fn pci_get_powerstate "device_t dev"
110855ed4c5SJohn Baldwin.Ft int
111855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
112855ed4c5SJohn Baldwin.Ft int
113855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
114855ed4c5SJohn Baldwin.Ft int
115855ed4c5SJohn Baldwin.Fn pci_msi_count "device_t dev"
116855ed4c5SJohn Baldwin.Ft int
117855ed4c5SJohn Baldwin.Fn pci_msix_count "device_t dev"
118855ed4c5SJohn Baldwin.Ft int
119ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar "device_t dev"
120ce204e1bSJohn Baldwin.Ft int
121ce204e1bSJohn Baldwin.Fn pci_msix_table_bar "device_t dev"
122ce204e1bSJohn Baldwin.Ft int
123855ed4c5SJohn Baldwin.Fn pci_pending_msix "device_t dev" "u_int index"
1240a9c80e5SJohn Baldwin.Ft uint32_t
1250a9c80e5SJohn Baldwin.Fn pci_read_config "device_t dev" "int reg" "int width"
126855ed4c5SJohn Baldwin.Ft int
127855ed4c5SJohn Baldwin.Fn pci_release_msi "device_t dev"
128855ed4c5SJohn Baldwin.Ft int
129855ed4c5SJohn Baldwin.Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors"
1300a9c80e5SJohn Baldwin.Ft void
1310a9c80e5SJohn Baldwin.Fn pci_restore_state "device_t dev"
1320a9c80e5SJohn Baldwin.Ft void
1330a9c80e5SJohn Baldwin.Fn pci_save_state "device_t dev"
1340a9c80e5SJohn Baldwin.Ft int
135855ed4c5SJohn Baldwin.Fn pci_set_max_read_req "device_t dev" "int size"
136855ed4c5SJohn Baldwin.Ft int
1370a9c80e5SJohn Baldwin.Fn pci_set_powerstate "device_t dev" "int state"
1380a9c80e5SJohn Baldwin.Ft void
1390a9c80e5SJohn Baldwin.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
140ec603c72SJohn Baldwin.Ft uint32_t
141ec603c72SJohn Baldwin.Fo pcie_adjust_config
142ec603c72SJohn Baldwin.Fa "device_t dev"
143ec603c72SJohn Baldwin.Fa "int reg"
144ec603c72SJohn Baldwin.Fa "uint32_t mask"
145ec603c72SJohn Baldwin.Fa "uint32_t val"
146ec603c72SJohn Baldwin.Fa "int width"
147ec603c72SJohn Baldwin.Fc
148ec603c72SJohn Baldwin.Ft uint32_t
149ec603c72SJohn Baldwin.Fn pcie_read_config "device_t dev" "int reg" "int width"
150ec603c72SJohn Baldwin.Ft void
151ec603c72SJohn Baldwin.Fn pcie_write_config "device_t dev" "int reg" "uint32_t val" "int width"
152*64414cc0SJohn Baldwin.Ft void
153*64414cc0SJohn Baldwin.Fn pci_event_fn "void *arg" "device_t dev"
154*64414cc0SJohn Baldwin.Fn EVENTHANDLER_REGISTER "pci_add_device" "pci_event_fn"
155*64414cc0SJohn Baldwin.Fn EVENTHANDLER_DEREGISTER "pci_delete_resource" "pci_event_fn"
156f3bb9251SJohn Baldwin.In dev/pci/pci_iov.h
157f3bb9251SJohn Baldwin.Ft int
158f3bb9251SJohn Baldwin.Fn pci_iov_attach "device_t dev" "nvlist_t *pf_schema" "nvlist_t *vf_schema"
159f3bb9251SJohn Baldwin.Ft int
1600aee83ccSJohn Baldwin.Fo pci_iov_attach_name
1610aee83ccSJohn Baldwin.Fa "device_t dev"
1620aee83ccSJohn Baldwin.Fa "nvlist_t *pf_schema"
1630aee83ccSJohn Baldwin.Fa "nvlist_t *vf_schema"
1640aee83ccSJohn Baldwin.Fa "const char *fmt"
1650aee83ccSJohn Baldwin.Fa "..."
1660aee83ccSJohn Baldwin.Fc
1670aee83ccSJohn Baldwin.Ft int
168f3bb9251SJohn Baldwin.Fn pci_iov_detach "device_t dev"
169aac0aafaSHiten Pandya.Sh DESCRIPTION
170aac0aafaSHiten PandyaThe
171aac0aafaSHiten Pandya.Nm
172aac0aafaSHiten Pandyaset of functions are used for managing PCI devices.
173855ed4c5SJohn BaldwinThe functions are split into several groups:
174855ed4c5SJohn Baldwinraw configuration access,
175855ed4c5SJohn Baldwinlocating devices,
176855ed4c5SJohn Baldwindevice information,
177855ed4c5SJohn Baldwindevice configuration,
178855ed4c5SJohn Baldwinand
179855ed4c5SJohn Baldwinmessage signaled interrupts.
180855ed4c5SJohn Baldwin.Ss Raw Configuration Access
181aac0aafaSHiten PandyaThe
182aac0aafaSHiten Pandya.Fn pci_read_config
183aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration
184aac0aafaSHiten Pandyaspace of the device
185aac0aafaSHiten Pandya.Fa dev ,
186aac0aafaSHiten Pandyaat offset
187aac0aafaSHiten Pandya.Fa reg ,
188aac0aafaSHiten Pandyawith
189aac0aafaSHiten Pandya.Fa width
190aac0aafaSHiten Pandyaspecifying the size of the access.
191aac0aafaSHiten Pandya.Pp
192aac0aafaSHiten PandyaThe
193aac0aafaSHiten Pandya.Fn pci_write_config
194aac0aafaSHiten Pandyafunction is used to write the value
195aac0aafaSHiten Pandya.Fa val
196aac0aafaSHiten Pandyato the PCI configuration
197aac0aafaSHiten Pandyaspace of the device
198aac0aafaSHiten Pandya.Fa dev ,
199aac0aafaSHiten Pandyaat offset
200aac0aafaSHiten Pandya.Fa reg ,
201aac0aafaSHiten Pandyawith
202aac0aafaSHiten Pandya.Fa width
203aac0aafaSHiten Pandyaspecifying the size of the access.
204aac0aafaSHiten Pandya.Pp
205ec603c72SJohn BaldwinThe
206ec603c72SJohn Baldwin.Fn pcie_adjust_config
207ec603c72SJohn Baldwinfunction is used to modify the value of a register in the PCI-express
208ec603c72SJohn Baldwincapability register set of device
209ec603c72SJohn Baldwin.Fa dev .
210ec603c72SJohn BaldwinThe offset
211ec603c72SJohn Baldwin.Fa reg
212ec603c72SJohn Baldwinspecifies a relative offset in the register set with
213ec603c72SJohn Baldwin.Fa width
214ec603c72SJohn Baldwinspecifying the size of the access.
215ec603c72SJohn BaldwinThe new value of the register is computed by modifying bits set in
216ec603c72SJohn Baldwin.Fa mask
217ec603c72SJohn Baldwinto the value in
218ec603c72SJohn Baldwin.Fa val .
219ec603c72SJohn BaldwinAny bits not specified in
220ec603c72SJohn Baldwin.Fa mask
221ec603c72SJohn Baldwinare preserved.
222ec603c72SJohn BaldwinThe previous value of the register is returned.
223ec603c72SJohn Baldwin.Pp
224ec603c72SJohn BaldwinThe
225ec603c72SJohn Baldwin.Fn pcie_read_config
226ec603c72SJohn Baldwinfunction is used to read the value of a register in the PCI-express
227ec603c72SJohn Baldwincapability register set of device
228ec603c72SJohn Baldwin.Fa dev .
229ec603c72SJohn BaldwinThe offset
230ec603c72SJohn Baldwin.Fa reg
231ec603c72SJohn Baldwinspecifies a relative offset in the register set with
232ec603c72SJohn Baldwin.Fa width
233ec603c72SJohn Baldwinspecifying the size of the access.
234ec603c72SJohn Baldwin.Pp
235ec603c72SJohn BaldwinThe
236ec603c72SJohn Baldwin.Fn pcie_write_config
237ec603c72SJohn Baldwinfunction is used to write the value
238ec603c72SJohn Baldwin.Fa val
239ec603c72SJohn Baldwinto a register in the PCI-express capability register set of device
240ec603c72SJohn Baldwin.Fa dev .
241ec603c72SJohn BaldwinThe offset
242ec603c72SJohn Baldwin.Fa reg
243ec603c72SJohn Baldwinspecifies a relative offset in the register set with
244ec603c72SJohn Baldwin.Fa width
245ec603c72SJohn Baldwinspecifying the size of the access.
246ec603c72SJohn Baldwin.Pp
247855ed4c5SJohn Baldwin.Em NOTE :
248855ed4c5SJohn BaldwinDevice drivers should only use these functions for functionality that
249855ed4c5SJohn Baldwinis not available via another
250855ed4c5SJohn Baldwin.Fn pci
251855ed4c5SJohn Baldwinfunction.
252855ed4c5SJohn Baldwin.Ss Locating Devices
253855ed4c5SJohn BaldwinThe
254855ed4c5SJohn Baldwin.Fn pci_find_bsf
255855ed4c5SJohn Baldwinfunction looks up the
256855ed4c5SJohn Baldwin.Vt device_t
257855ed4c5SJohn Baldwinof a PCI device, given its
258855ed4c5SJohn Baldwin.Fa bus ,
259855ed4c5SJohn Baldwin.Fa slot ,
260855ed4c5SJohn Baldwinand
261855ed4c5SJohn Baldwin.Fa func .
262855ed4c5SJohn BaldwinThe
263855ed4c5SJohn Baldwin.Fa slot
264855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
265855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
266855ed4c5SJohn Baldwinin terms of a physical slot.
267855ed4c5SJohn BaldwinNote that in case the system has multiple PCI domains,
268855ed4c5SJohn Baldwinthe
269855ed4c5SJohn Baldwin.Fn pci_find_bsf
270855ed4c5SJohn Baldwinfunction only searches the first one.
271855ed4c5SJohn BaldwinActually, it is equivalent to:
272855ed4c5SJohn Baldwin.Bd -literal -offset indent
273855ed4c5SJohn Baldwinpci_find_dbsf(0, bus, slot, func);
274855ed4c5SJohn Baldwin.Ed
275855ed4c5SJohn Baldwin.Pp
276855ed4c5SJohn BaldwinThe
277855ed4c5SJohn Baldwin.Fn pci_find_dbsf
278855ed4c5SJohn Baldwinfunction looks up the
279855ed4c5SJohn Baldwin.Vt device_t
280855ed4c5SJohn Baldwinof a PCI device, given its
281855ed4c5SJohn Baldwin.Fa domain ,
282855ed4c5SJohn Baldwin.Fa bus ,
283855ed4c5SJohn Baldwin.Fa slot ,
284855ed4c5SJohn Baldwinand
285855ed4c5SJohn Baldwin.Fa func .
286855ed4c5SJohn BaldwinThe
287855ed4c5SJohn Baldwin.Fa slot
288855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
289855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
290855ed4c5SJohn Baldwinin terms of a physical slot.
291855ed4c5SJohn Baldwin.Pp
292855ed4c5SJohn BaldwinThe
293855ed4c5SJohn Baldwin.Fn pci_find_device
294855ed4c5SJohn Baldwinfunction looks up the
295855ed4c5SJohn Baldwin.Vt device_t
296855ed4c5SJohn Baldwinof a PCI device, given its
297855ed4c5SJohn Baldwin.Fa vendor
298855ed4c5SJohn Baldwinand
299855ed4c5SJohn Baldwin.Fa device
300855ed4c5SJohn BaldwinIDs.
301855ed4c5SJohn BaldwinNote that there can be multiple matches for this search; this function
302855ed4c5SJohn Baldwinonly returns the first matching device.
303855ed4c5SJohn Baldwin.Ss Device Information
304855ed4c5SJohn BaldwinThe
305855ed4c5SJohn Baldwin.Fn pci_find_cap
306855ed4c5SJohn Baldwinfunction is used to locate the first instance of a PCI capability
307855ed4c5SJohn Baldwinregister set for the device
308855ed4c5SJohn Baldwin.Fa dev .
309855ed4c5SJohn BaldwinThe capability to locate is specified by ID via
310855ed4c5SJohn Baldwin.Fa capability .
311855ed4c5SJohn BaldwinConstant macros of the form
312855ed4c5SJohn Baldwin.Dv PCIY_xxx
313855ed4c5SJohn Baldwinfor standard capability IDs are defined in
314855ed4c5SJohn Baldwin.In dev/pci/pcireg.h .
315855ed4c5SJohn BaldwinIf the capability is found, then
316855ed4c5SJohn Baldwin.Fa *capreg
317281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
318855ed4c5SJohn Baldwinand
319855ed4c5SJohn Baldwin.Fn pci_find_cap
320855ed4c5SJohn Baldwinreturns zero.
321855ed4c5SJohn BaldwinIf the capability is not found or the device does not support capabilities,
322855ed4c5SJohn Baldwin.Fn pci_find_cap
323855ed4c5SJohn Baldwinreturns an error.
324855ed4c5SJohn Baldwin.Pp
325855ed4c5SJohn BaldwinThe
32668bf9717SJohn Baldwin.Fn pci_find_extcap
32768bf9717SJohn Baldwinfunction is used to locate the first instance of a PCI-express
32868bf9717SJohn Baldwinextended capability register set for the device
32968bf9717SJohn Baldwin.Fa dev .
33068bf9717SJohn BaldwinThe extended capability to locate is specified by ID via
33168bf9717SJohn Baldwin.Fa capability .
33268bf9717SJohn BaldwinConstant macros of the form
33368bf9717SJohn Baldwin.Dv PCIZ_xxx
33468bf9717SJohn Baldwinfor standard extended capability IDs are defined in
33568bf9717SJohn Baldwin.In dev/pci/pcireg.h .
33668bf9717SJohn BaldwinIf the extended capability is found, then
33768bf9717SJohn Baldwin.Fa *capreg
338281a359eSJohn Baldwinis set to the offset in configuration space of the extended capability
33968bf9717SJohn Baldwinregister set, and
34068bf9717SJohn Baldwin.Fn pci_find_extcap
34168bf9717SJohn Baldwinreturns zero.
34268bf9717SJohn BaldwinIf the extended capability is not found or the device is not a
34368bf9717SJohn BaldwinPCI-express device,
34468bf9717SJohn Baldwin.Fn pci_find_extcap
34568bf9717SJohn Baldwinreturns an error.
34668bf9717SJohn Baldwin.Pp
34768bf9717SJohn BaldwinThe
34868bf9717SJohn Baldwin.Fn pci_find_htcap
34968bf9717SJohn Baldwinfunction is used to locate the first instance of a HyperTransport capability
35068bf9717SJohn Baldwinregister set for the device
35168bf9717SJohn Baldwin.Fa dev .
35268bf9717SJohn BaldwinThe capability to locate is specified by type via
35368bf9717SJohn Baldwin.Fa capability .
35468bf9717SJohn BaldwinConstant macros of the form
35568bf9717SJohn Baldwin.Dv PCIM_HTCAP_xxx
35668bf9717SJohn Baldwinfor standard HyperTransport capability types are defined in
35768bf9717SJohn Baldwin.In dev/pci/pcireg.h .
35868bf9717SJohn BaldwinIf the capability is found, then
35968bf9717SJohn Baldwin.Fa *capreg
360281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
36168bf9717SJohn Baldwinand
36268bf9717SJohn Baldwin.Fn pci_find_htcap
36368bf9717SJohn Baldwinreturns zero.
36468bf9717SJohn BaldwinIf the capability is not found or the device is not a HyperTransport device,
36568bf9717SJohn Baldwin.Fn pci_find_htcap
36668bf9717SJohn Baldwinreturns an error.
36768bf9717SJohn Baldwin.Pp
36868bf9717SJohn BaldwinThe
36987dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
37087dd2f95SJohn Baldwinfunction walks up the PCI device hierarchy to locate the PCI-express root
37187dd2f95SJohn Baldwinport upstream of
37287dd2f95SJohn Baldwin.Fa dev .
37387dd2f95SJohn BaldwinIf a root port is not found,
37487dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
37587dd2f95SJohn Baldwinreturns
37687dd2f95SJohn Baldwin.Dv NULL .
37787dd2f95SJohn Baldwin.Pp
37887dd2f95SJohn BaldwinThe
379d7be980dSAndrew Turner.Fn pci_get_id
380d7be980dSAndrew Turnerfunction is used to read an identifier from a device.
381d7be980dSAndrew TurnerThe
382d7be980dSAndrew Turner.Fa type
383d7be980dSAndrew Turnerflag is used to specify which identifier to read.
384d7be980dSAndrew TurnerThe following flags are supported:
385d7be980dSAndrew Turner.Bl -hang -width ".Dv PCI_ID_RID"
386d7be980dSAndrew Turner.It Dv PCI_ID_RID
387d7be980dSAndrew TurnerRead the routing identifier for the device.
3881e43b18cSAndrew Turner.It Dv PCI_ID_MSI
3891e43b18cSAndrew TurnerRead the MSI routing ID.
3901e43b18cSAndrew TurnerThis is needed by some interrupt controllers to route MSI and MSI-X interrupts.
391d7be980dSAndrew Turner.El
392d7be980dSAndrew Turner.Pp
393d7be980dSAndrew TurnerThe
394855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
395855ed4c5SJohn Baldwinfunction is used to fetch a device's Vital Product Data
396855ed4c5SJohn Baldwin.Pq VPD
397855ed4c5SJohn Baldwinidentifier string.
398855ed4c5SJohn BaldwinIf the device
399855ed4c5SJohn Baldwin.Fa dev
400855ed4c5SJohn Baldwinsupports VPD and provides an identifier string,
401855ed4c5SJohn Baldwinthen
402855ed4c5SJohn Baldwin.Fa *identptr
403855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the identifier
404855ed4c5SJohn Baldwinstring,
405855ed4c5SJohn Baldwinand
406855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
407855ed4c5SJohn Baldwinreturns zero.
408855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide an identifier
409855ed4c5SJohn Baldwinstring,
410855ed4c5SJohn Baldwinthen
411855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
412855ed4c5SJohn Baldwinreturns an error.
413855ed4c5SJohn Baldwin.Pp
414855ed4c5SJohn BaldwinThe
415855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
416855ed4c5SJohn Baldwinfunction is used to fetch the value of a single VPD read-only keyword
417855ed4c5SJohn Baldwinfor the device
418855ed4c5SJohn Baldwin.Fa dev .
419855ed4c5SJohn BaldwinThe keyword to fetch is identified by the two character string
420855ed4c5SJohn Baldwin.Fa kw .
421855ed4c5SJohn BaldwinIf the device supports VPD and provides a read-only value for the
422855ed4c5SJohn Baldwinrequested keyword,
423855ed4c5SJohn Baldwinthen
424855ed4c5SJohn Baldwin.Fa *vptr
425855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the value,
426855ed4c5SJohn Baldwinand
427855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
428855ed4c5SJohn Baldwinreturns zero.
429855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide the requested
430855ed4c5SJohn Baldwinkeyword,
431855ed4c5SJohn Baldwinthen
432855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
433855ed4c5SJohn Baldwinreturns an error.
434855ed4c5SJohn Baldwin.Ss Device Configuration
435aac0aafaSHiten PandyaThe
436aac0aafaSHiten Pandya.Fn pci_enable_busmaster
437aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device
438aac0aafaSHiten Pandya.Fa dev ,
439aac0aafaSHiten Pandyaby setting the
440aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN
441aac0aafaSHiten Pandyabit in the
442aac0aafaSHiten Pandya.Dv PCIR_COMMAND
443aac0aafaSHiten Pandyaregister.
444aac0aafaSHiten PandyaThe
445aac0aafaSHiten Pandya.Fn pci_disable_busmaster
446aac0aafaSHiten Pandyafunction clears this bit.
447aac0aafaSHiten Pandya.Pp
448aac0aafaSHiten PandyaThe
449aac0aafaSHiten Pandya.Fn pci_enable_io
450aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device
451aac0aafaSHiten Pandya.Fa dev ,
452aac0aafaSHiten Pandyaby setting the
453aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN
454aac0aafaSHiten Pandyaor
455aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN
456aac0aafaSHiten Pandyabit in the
457aac0aafaSHiten Pandya.Dv PCIR_COMMAND
4585203edcdSRuslan Ermilovregister appropriately.
4595203edcdSRuslan ErmilovThe
460aac0aafaSHiten Pandya.Fn pci_disable_io
461aac0aafaSHiten Pandyafunction clears the appropriate bit.
462aac0aafaSHiten PandyaThe
46365bb31b8SRuslan Ermilov.Fa space
464aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either
465aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY
466aac0aafaSHiten Pandyaor
467aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT
468aac0aafaSHiten Pandyaas appropriate.
469855ed4c5SJohn BaldwinDevice drivers should generally not use these routines directly.
470855ed4c5SJohn BaldwinThe PCI bus will enable decoding automatically when a
471855ed4c5SJohn Baldwin.Dv SYS_RES_MEMORY
472855ed4c5SJohn Baldwinor
473855ed4c5SJohn Baldwin.Dv SYS_RES_IOPORT
474855ed4c5SJohn Baldwinresource is activated via
475855ed4c5SJohn Baldwin.Xr bus_alloc_resource 9
476855ed4c5SJohn Baldwinor
477855ed4c5SJohn Baldwin.Xr bus_activate_resource 9 .
478aac0aafaSHiten Pandya.Pp
479855ed4c5SJohn BaldwinThe
4802ab0398dSJohn Baldwin.Fn pci_get_max_payload
4812ab0398dSJohn Baldwinfunction returns the current maximum TLP payload size in bytes for a
4822ab0398dSJohn BaldwinPCI-express device.
4832ab0398dSJohn BaldwinIf the
4842ab0398dSJohn Baldwin.Fa dev
4852ab0398dSJohn Baldwindevice is not a PCI-express device,
4862ab0398dSJohn Baldwin.Fn pci_get_max_payload
4872ab0398dSJohn Baldwinreturns zero.
4882ab0398dSJohn Baldwin.Pp
4892ab0398dSJohn BaldwinThe
490855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
491855ed4c5SJohn Baldwinfunction returns the current maximum read request size in bytes for a
492855ed4c5SJohn BaldwinPCI-express device.
493855ed4c5SJohn BaldwinIf the
494855ed4c5SJohn Baldwin.Fa dev
495855ed4c5SJohn Baldwindevice is not a PCI-express device,
496855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
497855ed4c5SJohn Baldwinreturns zero.
498855ed4c5SJohn Baldwin.Pp
499855ed4c5SJohn BaldwinThe
500855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
501855ed4c5SJohn Baldwinsets the PCI-express maximum read request size for
502855ed4c5SJohn Baldwin.Fa dev .
503855ed4c5SJohn BaldwinThe requested
504855ed4c5SJohn Baldwin.Fa size
505855ed4c5SJohn Baldwinmay be adjusted,
506855ed4c5SJohn Baldwinand
507855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
508855ed4c5SJohn Baldwinreturns the actual size set in bytes.
509855ed4c5SJohn BaldwinIf the
510855ed4c5SJohn Baldwin.Fa dev
511855ed4c5SJohn Baldwindevice is not a PCI-express device,
512855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
513855ed4c5SJohn Baldwinreturns zero.
514aac0aafaSHiten Pandya.Pp
515aac0aafaSHiten PandyaThe
516aac0aafaSHiten Pandya.Fn pci_get_powerstate
517adb63907SJohn Baldwinfunction returns the current power state of the device
518aac0aafaSHiten Pandya.Fa dev .
519aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default
520aac0aafaSHiten Pandyastate of
521aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0
522aac0aafaSHiten Pandyais returned.
523adb63907SJohn BaldwinThe following power states are defined by PCI:
52465bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
525aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0
526aac0aafaSHiten PandyaState in which device is on and running.
527aac0aafaSHiten PandyaIt is receiving full power from the system and delivering
528aac0aafaSHiten Pandyafull functionality to the user.
529aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1
530aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
5315a2e3b61SDaniel Gerzomay not be lost.
53265bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to
5339817b894SBruce M Simpsonforce devices to lose context.
534aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2
535aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
536aac0aafaSHiten Pandyamay not be lost.
537aac0aafaSHiten PandyaAttains greater power savings than
538aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 .
53965bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context.
540aac0aafaSHiten PandyaDevices
541aac0aafaSHiten Pandya.Em must
542aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher.
543aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3
544aac0aafaSHiten PandyaState in which the device is off and not running.
545aac0aafaSHiten PandyaDevice context is lost, and power from the device can
546aac0aafaSHiten Pandyabe removed.
547aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN
548aac0aafaSHiten PandyaState of the device is unknown.
549aac0aafaSHiten Pandya.El
550aac0aafaSHiten Pandya.Pp
551aac0aafaSHiten PandyaThe
552aac0aafaSHiten Pandya.Fn pci_set_powerstate
553aac0aafaSHiten Pandyafunction is used to transition the device
554aac0aafaSHiten Pandya.Fa dev
555adb63907SJohn Baldwinto the PCI power state
556aac0aafaSHiten Pandya.Fa state .
557adb63907SJohn BaldwinIf the device does not support power management capabilities or
558adb63907SJohn Baldwinit does not support the specific power state
559adb63907SJohn Baldwin.Fa state ,
560adb63907SJohn Baldwinthen the function will fail with
561adb63907SJohn Baldwin.Er EOPNOTSUPP .
562aac0aafaSHiten Pandya.Pp
563aac0aafaSHiten PandyaThe
5647d971e36SRyan Stone.Fn pci_iov_attach
5657d971e36SRyan Stonefunction is used to advertise that the given device
5667d971e36SRyan Stone.Pq and associated device driver
5677d971e36SRyan Stonesupports PCI Single-Root I/O Virtualization
568fe3ff217SPatrick Kelsey.Pq SR-IOV .
5697d971e36SRyan StoneA driver that supports SR-IOV must implement the
570f3bb9251SJohn Baldwin.Xr PCI_IOV_INIT 9 ,
571f3bb9251SJohn Baldwin.Xr PCI_IOV_ADD_VF 9
5727d971e36SRyan Stoneand
573f3bb9251SJohn Baldwin.Xr PCI_IOV_UNINIT 9
5747d971e36SRyan Stonemethods.
5757d971e36SRyan StoneThis function should be called during the
5767d971e36SRyan Stone.Xr DEVICE_ATTACH 9
5777d971e36SRyan Stonemethod.
5787d971e36SRyan StoneIf this function returns an error, it is recommended that the device driver
5797d971e36SRyan Stonestill successfully attaches, but runs with SR-IOV disabled.
5807d971e36SRyan StoneThe
5817d971e36SRyan Stone.Fa pf_schema
5827d971e36SRyan Stoneand
5837d971e36SRyan Stone.Fa vf_schema
5847d971e36SRyan Stoneparameters are used to define what device-specific configuration parameters the
5857d971e36SRyan Stonedevice driver accepts when SR-IOV is enabled for the Physical Function
5867d971e36SRyan Stone.Pq PF
5877d971e36SRyan Stoneand for individual Virtual Functions
5887d971e36SRyan Stone.Pq VFs
5897d971e36SRyan Stonerespectively.
5907d971e36SRyan StoneSee
5917d971e36SRyan Stone.Xr pci_iov_schema 9
5927d971e36SRyan Stonefor details on how to construct the schema.
5937d971e36SRyan StoneIf either the
5947d971e36SRyan Stone.Pa pf_schema
5957d971e36SRyan Stoneor
5967d971e36SRyan Stone.Pa vf_schema
5977d971e36SRyan Stoneis invalid or specifies parameter names that conflict with parameter names that
5987d971e36SRyan Stoneare already in use,
5997d971e36SRyan Stone.Fn pci_iov_attach
6007d971e36SRyan Stonewill return an error and SR-IOV will not be available on the PF device.
6017d971e36SRyan StoneIf a driver does not accept configuration parameters for either the PF device
6027d971e36SRyan Stoneor the VF devices, the driver must pass an empty schema for that device.
6037d971e36SRyan StoneThe SR-IOV infrastructure takes ownership of the
6047d971e36SRyan Stone.Fa pf_schema
6057d971e36SRyan Stoneand
6067d971e36SRyan Stone.Fa vf_schema
6077d971e36SRyan Stoneand is responsible for freeing them.
6087d971e36SRyan StoneThe driver must never free the schemas itself.
6097d971e36SRyan Stone.Pp
6107d971e36SRyan StoneThe
6110aee83ccSJohn Baldwin.Fn pci_iov_attach_name
6120aee83ccSJohn Baldwinfunction is a variant of
6130aee83ccSJohn Baldwin.Fn pci_iov_attach
6140aee83ccSJohn Baldwinthat allows the name of the associated character device in
6150aee83ccSJohn Baldwin.Pa /dev/iov
6160aee83ccSJohn Baldwinto be specified by
6170aee83ccSJohn Baldwin.Fa fmt .
6180aee83ccSJohn BaldwinThe
6190aee83ccSJohn Baldwin.Fn pci_iov_attach
6200aee83ccSJohn Baldwinfunction uses the name of
6210aee83ccSJohn Baldwin.Fa dev
6220aee83ccSJohn Baldwinas the device name.
6230aee83ccSJohn Baldwin.Pp
6240aee83ccSJohn BaldwinThe
6257d971e36SRyan Stone.Fn pci_iov_detach
6267d971e36SRyan Stonefunction is used to advise the SR-IOV infrastructure that the driver for the
6277d971e36SRyan Stonegiven device is attempting to detach and that all SR-IOV resources for the
6287d971e36SRyan Stonedevice must be released.
6297d971e36SRyan StoneThis function must be called during the
6307d971e36SRyan Stone.Xr DEVICE_DETACH 9
6317d971e36SRyan Stonemethod if
6327d971e36SRyan Stone.Fn pci_iov_attach
6337d971e36SRyan Stonewas successfully called on the device and
6347d971e36SRyan Stone.Fn pci_iov_detach
6357d971e36SRyan Stonehas not subsequently been called on the device and returned no error.
6367d971e36SRyan StoneIf this function returns an error, the
6377d971e36SRyan Stone.Xr DEVICE_DETACH 9
6387d971e36SRyan Stonemethod must fail and return an error, as detaching the PF driver while VF
6397d971e36SRyan Stonedevices are active would cause system instability.
6407d971e36SRyan StoneThis function is safe to call and will always succeed if
6417d971e36SRyan Stone.Fn pci_iov_attach
6427d971e36SRyan Stonepreviously failed with an error on the given device, or if
6437d971e36SRyan Stone.Fn pci_iov_attach
6447d971e36SRyan Stonewas never called on the device.
6457d971e36SRyan Stone.Pp
6467d971e36SRyan StoneThe
6479415d1e0SJohn Baldwin.Fn pci_save_state
6489415d1e0SJohn Baldwinand
6499415d1e0SJohn Baldwin.Fn pci_restore_state
6509415d1e0SJohn Baldwinfunctions can be used by a device driver to save and restore standard PCI
6519415d1e0SJohn Baldwinconfig registers.
6529415d1e0SJohn BaldwinThe
6539415d1e0SJohn Baldwin.Fn pci_save_state
6549415d1e0SJohn Baldwinfunction must be invoked while the device has valid state before
6559415d1e0SJohn Baldwin.Fn pci_restore_state
6569415d1e0SJohn Baldwincan be used.
6579415d1e0SJohn BaldwinIf the device is not in the fully-powered state
6589415d1e0SJohn Baldwin.Pq Dv PCI_POWERSTATE_D0
6599415d1e0SJohn Baldwinwhen
6609415d1e0SJohn Baldwin.Fn pci_restore_state
6619415d1e0SJohn Baldwinis invoked,
6629415d1e0SJohn Baldwinthen the device will be transitioned to
6639415d1e0SJohn Baldwin.Dv PCI_POWERSTATE_D0
6649415d1e0SJohn Baldwinbefore any config registers are restored.
665855ed4c5SJohn Baldwin.Ss Message Signaled Interrupts
666855ed4c5SJohn BaldwinMessage Signaled Interrupts
667855ed4c5SJohn Baldwin.Pq MSI
668855ed4c5SJohn Baldwinand
669855ed4c5SJohn BaldwinEnhanced Message Signaled Interrupts
670855ed4c5SJohn Baldwin.Pq MSI-X
671855ed4c5SJohn Baldwinare PCI capabilities that provide an alternate method for PCI
672855ed4c5SJohn Baldwindevices to signal interrupts.
673855ed4c5SJohn BaldwinThe legacy INTx interrupt is available to PCI devices as a
674855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
675855ed4c5SJohn Baldwinresource with a resource ID of zero.
676855ed4c5SJohn BaldwinMSI and MSI-X interrupts are available to PCI devices as one or more
677855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
678855ed4c5SJohn Baldwinresources with resource IDs greater than zero.
679855ed4c5SJohn BaldwinA driver must ask the PCI bus to allocate MSI or MSI-X interrupts
680855ed4c5SJohn Baldwinusing
681855ed4c5SJohn Baldwin.Fn pci_alloc_msi
682855ed4c5SJohn Baldwinor
683855ed4c5SJohn Baldwin.Fn pci_alloc_msix
684855ed4c5SJohn Baldwinbefore it can use MSI or MSI-X
685855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
686855ed4c5SJohn Baldwinresources.
687855ed4c5SJohn BaldwinA driver is not allowed to use the legacy INTx
688855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
689855ed4c5SJohn Baldwinresource if MSI or MSI-X interrupts have been allocated,
690855ed4c5SJohn Baldwinand attempts to allocate MSI or MSI-X interrupts will fail if the
691855ed4c5SJohn Baldwindriver is currently using the legacy INTx
692855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
693855ed4c5SJohn Baldwinresource.
694855ed4c5SJohn BaldwinA driver is only allowed to use either MSI or MSI-X,
695855ed4c5SJohn Baldwinbut not both.
6969415d1e0SJohn Baldwin.Pp
6979415d1e0SJohn BaldwinThe
698563d4639SMark Johnston.Fn pci_msi_count
699855ed4c5SJohn Baldwinfunction returns the maximum number of MSI messages supported by the
700855ed4c5SJohn Baldwindevice
701855ed4c5SJohn Baldwin.Fa dev .
702855ed4c5SJohn BaldwinIf the device does not support MSI,
703855ed4c5SJohn Baldwinthen
704563d4639SMark Johnston.Fn pci_msi_count
705855ed4c5SJohn Baldwinreturns zero.
70655aaf894SMarius Strobl.Pp
70755aaf894SMarius StroblThe
708855ed4c5SJohn Baldwin.Fn pci_alloc_msi
709855ed4c5SJohn Baldwinfunction attempts to allocate
710855ed4c5SJohn Baldwin.Fa *count
711855ed4c5SJohn BaldwinMSI messages for the device
712855ed4c5SJohn Baldwin.Fa dev .
71355aaf894SMarius StroblThe
714855ed4c5SJohn Baldwin.Fn pci_alloc_msi
715855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
716855ed4c5SJohn Baldwinreasons including requests for more messages than the device
717855ed4c5SJohn Baldwin.Fa dev
718855ed4c5SJohn Baldwinsupports,
719855ed4c5SJohn Baldwinor if the system has a shortage of available MSI messages.
720855ed4c5SJohn BaldwinOn success,
721855ed4c5SJohn Baldwin.Fa *count
722855ed4c5SJohn Baldwinis set to the number of messages allocated and
723855ed4c5SJohn Baldwin.Fn pci_alloc_msi
724855ed4c5SJohn Baldwinreturns zero.
725855ed4c5SJohn BaldwinThe
726855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
727855ed4c5SJohn Baldwinresources for the allocated messages will be available at consecutive
728855ed4c5SJohn Baldwinresource IDs beginning with one.
729855ed4c5SJohn BaldwinIf
730855ed4c5SJohn Baldwin.Fn pci_alloc_msi
731855ed4c5SJohn Baldwinis not able to allocate any messages,
732855ed4c5SJohn Baldwinit returns an error.
733855ed4c5SJohn BaldwinNote that MSI only supports message counts that are powers of two;
734855ed4c5SJohn Baldwinrequests to allocate a non-power of two count of messages will fail.
735aac0aafaSHiten Pandya.Pp
736aac0aafaSHiten PandyaThe
737855ed4c5SJohn Baldwin.Fn pci_release_msi
738855ed4c5SJohn Baldwinfunction is used to release any allocated MSI or MSI-X messages back
739855ed4c5SJohn Baldwinto the system.
740855ed4c5SJohn BaldwinIf any MSI or MSI-X
741855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
742855ed4c5SJohn Baldwinresources are allocated by the driver or have a configured interrupt
743855ed4c5SJohn Baldwinhandler,
744855ed4c5SJohn Baldwinthis function will fail with
745855ed4c5SJohn Baldwin.Er EBUSY .
746855ed4c5SJohn BaldwinThe
747855ed4c5SJohn Baldwin.Fn pci_release_msi
748855ed4c5SJohn Baldwinfunction returns zero on success and an error on failure.
749855ed4c5SJohn Baldwin.Pp
750642c4993SSergey KandaurovThe
751563d4639SMark Johnston.Fn pci_msix_count
752855ed4c5SJohn Baldwinfunction returns the maximum number of MSI-X messages supported by the
753855ed4c5SJohn Baldwindevice
754855ed4c5SJohn Baldwin.Fa dev .
755855ed4c5SJohn BaldwinIf the device does not support MSI-X,
756855ed4c5SJohn Baldwinthen
757563d4639SMark Johnston.Fn pci_msix_count
758855ed4c5SJohn Baldwinreturns zero.
759855ed4c5SJohn Baldwin.Pp
760855ed4c5SJohn BaldwinThe
761ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
762ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the Base Address Register
763ce204e1bSJohn Baldwin.Pq BAR
764ce204e1bSJohn Baldwincontaining the MSI-X Pending Bit Array (PBA) for device
765ce204e1bSJohn Baldwin.Fa dev .
766ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
767ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
768ce204e1bSJohn Baldwinand
769ce204e1bSJohn Baldwin.Xr bus_release_resource 9
770ce204e1bSJohn Baldwinto allocate the BAR.
771ce204e1bSJohn BaldwinIf the device does not support MSI-X,
772ce204e1bSJohn Baldwinthen
773ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
774ce204e1bSJohn Baldwinreturns -1.
775ce204e1bSJohn Baldwin.Pp
776ce204e1bSJohn BaldwinThe
777ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
778ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the BAR
779ce204e1bSJohn Baldwincontaining the MSI-X vector table for device
780ce204e1bSJohn Baldwin.Fa dev .
781ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
782ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
783ce204e1bSJohn Baldwinand
784ce204e1bSJohn Baldwin.Xr bus_release_resource 9
785ce204e1bSJohn Baldwinto allocate the BAR.
786ce204e1bSJohn BaldwinIf the device does not support MSI-X,
787ce204e1bSJohn Baldwinthen
788ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
789ce204e1bSJohn Baldwinreturns -1.
790ce204e1bSJohn Baldwin.Pp
791ce204e1bSJohn BaldwinThe
792855ed4c5SJohn Baldwin.Fn pci_alloc_msix
793855ed4c5SJohn Baldwinfunction attempts to allocate
794855ed4c5SJohn Baldwin.Fa *count
795855ed4c5SJohn BaldwinMSI-X messages for the device
796855ed4c5SJohn Baldwin.Fa dev .
797855ed4c5SJohn BaldwinThe
798855ed4c5SJohn Baldwin.Fn pci_alloc_msix
799855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
800855ed4c5SJohn Baldwinreasons including requests for more messages than the device
801855ed4c5SJohn Baldwin.Fa dev
802855ed4c5SJohn Baldwinsupports,
803855ed4c5SJohn Baldwinor if the system has a shortage of available MSI-X messages.
804855ed4c5SJohn BaldwinOn success,
805855ed4c5SJohn Baldwin.Fa *count
806855ed4c5SJohn Baldwinis set to the number of messages allocated and
807855ed4c5SJohn Baldwin.Fn pci_alloc_msix
808855ed4c5SJohn Baldwinreturns zero.
809855ed4c5SJohn BaldwinFor MSI-X messages,
810855ed4c5SJohn Baldwinthe resource ID for each
81173bbeaa5SGlen Barber.Dv SYS_RES_IRQ
81273bbeaa5SGlen Barberresource identifies the index in the MSI-X table of the
813855ed4c5SJohn Baldwincorresponding message.
814855ed4c5SJohn BaldwinA resource ID of one maps to the first index of the MSI-X table;
815855ed4c5SJohn Baldwina resource ID two identifies the second index in the table, etc.
816855ed4c5SJohn BaldwinThe
817855ed4c5SJohn Baldwin.Fn pci_alloc_msix
818855ed4c5SJohn Baldwinfunction assigns the
819855ed4c5SJohn Baldwin.Fa *count
820855ed4c5SJohn Baldwinmessages allocated to the first
821855ed4c5SJohn Baldwin.Fa *count
8227c64ddd5SWarren Blocktable indices.
823855ed4c5SJohn BaldwinIf
824855ed4c5SJohn Baldwin.Fn pci_alloc_msix
825855ed4c5SJohn Baldwinis not able to allocate any messages,
826855ed4c5SJohn Baldwinit returns an error.
827855ed4c5SJohn BaldwinUnlike MSI,
828855ed4c5SJohn BaldwinMSI-X does not require message counts that are powers of two.
829855ed4c5SJohn Baldwin.Pp
830ce204e1bSJohn BaldwinThe BARs containing the MSI-X vector table and PBA must be
831ce204e1bSJohn Baldwinallocated via
832ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
833ce204e1bSJohn Baldwinbefore calling
834ce204e1bSJohn Baldwin.Fn pci_alloc_msix
835ce204e1bSJohn Baldwinand must not be released until after calling
836ce204e1bSJohn Baldwin.Fn pci_release_msi .
837ce204e1bSJohn BaldwinNote that the vector table and PBA may be stored in the same BAR or in
838ce204e1bSJohn Baldwindifferent BARs.
839ce204e1bSJohn Baldwin.Pp
840855ed4c5SJohn BaldwinThe
841855ed4c5SJohn Baldwin.Fn pci_pending_msix
842855ed4c5SJohn Baldwinfunction examines the
843855ed4c5SJohn Baldwin.Fa dev
844ce204e1bSJohn Baldwindevice's PBA
845855ed4c5SJohn Baldwinto determine the pending status of the MSI-X message at table index
846855ed4c5SJohn Baldwin.Fa index .
847855ed4c5SJohn BaldwinIf the indicated message is pending,
848855ed4c5SJohn Baldwinthis function returns a non-zero value;
849855ed4c5SJohn Baldwinotherwise,
850855ed4c5SJohn Baldwinit returns zero.
851855ed4c5SJohn BaldwinPassing an invalid
852855ed4c5SJohn Baldwin.Fa index
853855ed4c5SJohn Baldwinto this function will result in undefined behavior.
854855ed4c5SJohn Baldwin.Pp
855855ed4c5SJohn BaldwinAs mentioned in the description of
856855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
857855ed4c5SJohn BaldwinMSI-X messages are initially assigned to the first N table entries.
858855ed4c5SJohn BaldwinA driver may use a different distribution of available messages to
859855ed4c5SJohn Baldwintable entries via the
860855ed4c5SJohn Baldwin.Fn pci_remap_msix
861855ed4c5SJohn Baldwinfunction.
86273bbeaa5SGlen BarberNote that this function must be called after a successful call to
863855ed4c5SJohn Baldwin.Fn pci_alloc_msix
864855ed4c5SJohn Baldwinbut before any of the
865855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
866855ed4c5SJohn Baldwinresources are allocated.
867855ed4c5SJohn BaldwinThe
868855ed4c5SJohn Baldwin.Fn pci_remap_msix
869855ed4c5SJohn Baldwinfunction returns zero on success,
870855ed4c5SJohn Baldwinor an error on failure.
871855ed4c5SJohn Baldwin.Pp
872855ed4c5SJohn BaldwinThe
873855ed4c5SJohn Baldwin.Fa vectors
874855ed4c5SJohn Baldwinarray should contain
875855ed4c5SJohn Baldwin.Fa count
876855ed4c5SJohn Baldwinmessage vectors.
877855ed4c5SJohn BaldwinThe array maps directly to the MSI-X table in that the first entry in
878855ed4c5SJohn Baldwinthe array specifies the message used for the first entry in the MSI-X
879855ed4c5SJohn Baldwintable,
880855ed4c5SJohn Baldwinthe second entry in the array corresponds to the second entry in the
881855ed4c5SJohn BaldwinMSI-X table,
882855ed4c5SJohn Baldwinetc.
883855ed4c5SJohn BaldwinThe vector value in each array index can either be zero to indicate
884855ed4c5SJohn Baldwinthat no message should be assigned to the corresponding MSI-X table entry,
885855ed4c5SJohn Baldwinor it can be a number from one to N
886855ed4c5SJohn Baldwin.Po
887855ed4c5SJohn Baldwinwhere N is the count returned from the previous call to
888855ed4c5SJohn Baldwin.Fn pci_alloc_msix
889855ed4c5SJohn Baldwin.Pc
890855ed4c5SJohn Baldwinto indicate which of the allocated messages should be assigned to the
891855ed4c5SJohn Baldwincorresponding MSI-X table entry.
892855ed4c5SJohn Baldwin.Pp
893855ed4c5SJohn BaldwinIf
894855ed4c5SJohn Baldwin.Fn pci_remap_msix
895855ed4c5SJohn Baldwinsucceeds,
896855ed4c5SJohn Baldwineach MSI-X table entry with a non-zero vector will have an associated
897855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
898855ed4c5SJohn Baldwinresource whose resource ID corresponds to the table index as described
899855ed4c5SJohn Baldwinabove for
900855ed4c5SJohn Baldwin.Fn pci_alloc_msix .
901855ed4c5SJohn BaldwinMSI-X table entries that with a vector of zero will not have an
902855ed4c5SJohn Baldwinassociated
90373bbeaa5SGlen Barber.Dv SYS_RES_IRQ
90473bbeaa5SGlen Barberresource.
905855ed4c5SJohn BaldwinAdditionally,
906855ed4c5SJohn Baldwinif any of the original messages allocated by
907855ed4c5SJohn Baldwin.Fn pci_alloc_msix
908855ed4c5SJohn Baldwinare not used in the new distribution of messages in the MSI-X table,
909855ed4c5SJohn Baldwinthey will be released automatically.
910855ed4c5SJohn BaldwinNote that if a driver wishes to use fewer messages than were allocated by
911855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
912855ed4c5SJohn Baldwinthe driver must use a single, contiguous range of messages beginning
913855ed4c5SJohn Baldwinwith one in the new distribution.
914855ed4c5SJohn BaldwinThe
915855ed4c5SJohn Baldwin.Fn pci_remap_msix
916855ed4c5SJohn Baldwinfunction will fail if this condition is not met.
917*64414cc0SJohn Baldwin.Ss Device Events
918*64414cc0SJohn BaldwinThe
919*64414cc0SJohn Baldwin.Va pci_add_device
920*64414cc0SJohn Baldwinevent handler is invoked every time a new PCI device is added to the system.
921*64414cc0SJohn BaldwinThis includes the creation of Virtual Functions via SR-IOV.
922*64414cc0SJohn Baldwin.Pp
923*64414cc0SJohn BaldwinThe
924*64414cc0SJohn Baldwin.Va pci_delete_device
925*64414cc0SJohn Baldwinevent handler is invoked every time a PCI device is removed from the system.
926*64414cc0SJohn Baldwin.Pp
927*64414cc0SJohn BaldwinBoth event handlers pass the
928*64414cc0SJohn Baldwin.Vt device_t
929*64414cc0SJohn Baldwinobject of the relevant PCI device as
930*64414cc0SJohn Baldwin.Fa dev
931*64414cc0SJohn Baldwinto each callback function.
932*64414cc0SJohn BaldwinBoth event handlers are invoked while
933*64414cc0SJohn Baldwin.Fa dev
934*64414cc0SJohn Baldwinis unattached but with valid instance variables.
935aac0aafaSHiten Pandya.Sh SEE ALSO
9367c2c06f2SSheldon Hearn.Xr pci 4 ,
9377c2c06f2SSheldon Hearn.Xr pciconf 8 ,
938aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 ,
939aac0aafaSHiten Pandya.Xr bus_dma 9 ,
940aac0aafaSHiten Pandya.Xr bus_release_resource 9 ,
941aac0aafaSHiten Pandya.Xr bus_setup_intr 9 ,
942aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 ,
943aac0aafaSHiten Pandya.Xr devclass 9 ,
944aac0aafaSHiten Pandya.Xr device 9 ,
945aac0aafaSHiten Pandya.Xr driver 9 ,
946*64414cc0SJohn Baldwin.Xr eventhandler 9 ,
947aac0aafaSHiten Pandya.Xr rman 9
948aac0aafaSHiten Pandya.Rs
949aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook
950aac0aafaSHiten Pandya.%T NewBus
951aa4a335bSRuslan Ermilov.%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
952aac0aafaSHiten Pandya.Re
953aac0aafaSHiten Pandya.Rs
954aac0aafaSHiten Pandya.%A Shanley
955aac0aafaSHiten Pandya.%A Anderson
956aac0aafaSHiten Pandya.%B PCI System Architecture
957aac0aafaSHiten Pandya.%N 2nd Edition
958aac0aafaSHiten Pandya.%I Addison-Wesley
959aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2
960aac0aafaSHiten Pandya.Re
961aac0aafaSHiten Pandya.Sh AUTHORS
9628a7314fcSBaptiste Daroussin.An -nosplit
963571dba6eSHiten PandyaThis manual page was written by
9648a7314fcSBaptiste Daroussin.An Bruce M Simpson Aq Mt bms@FreeBSD.org
965855ed4c5SJohn Baldwinand
9668a7314fcSBaptiste Daroussin.An John Baldwin Aq Mt jhb@FreeBSD.org .
967aac0aafaSHiten Pandya.Sh BUGS
9684d80f750SBruce M SimpsonThe kernel PCI code has a number of references to
9694d80f750SBruce M Simpson.Dq "slot numbers" .
970bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices,
971bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL
972bf1639eeSBruce M Simpsonmechanism and the platform firmware.
973bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code.
974ce204e1bSJohn Baldwin.Pp
975ce204e1bSJohn BaldwinThe PCI bus driver should allocate the MSI-X vector table and PBA internally
976ce204e1bSJohn Baldwinas necessary rather than requiring the caller to do so.
977