xref: /freebsd/share/man/man9/pci.9 (revision d7be980dbe6961abce6b3e12de0391cbad295f95)
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*d7be980dSAndrew Turner.Dd May 16, 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 ,
46*d7be980dSAndrew Turner.Nm pci_get_id ,
47855ed4c5SJohn Baldwin.Nm pci_get_max_read_req ,
480a9c80e5SJohn Baldwin.Nm pci_get_powerstate ,
49855ed4c5SJohn Baldwin.Nm pci_get_vpd_ident ,
50855ed4c5SJohn Baldwin.Nm pci_get_vpd_readonly ,
517d971e36SRyan Stone.Nm pci_iov_attach ,
527d971e36SRyan Stone.Nm pci_iov_detach ,
53855ed4c5SJohn Baldwin.Nm pci_msi_count ,
54855ed4c5SJohn Baldwin.Nm pci_msix_count ,
55ce204e1bSJohn Baldwin.Nm pci_msix_pba_bar ,
56ce204e1bSJohn Baldwin.Nm pci_msix_table_bar ,
57855ed4c5SJohn Baldwin.Nm pci_pending_msix ,
580a9c80e5SJohn Baldwin.Nm pci_read_config ,
59855ed4c5SJohn Baldwin.Nm pci_release_msi ,
60855ed4c5SJohn Baldwin.Nm pci_remap_msix ,
610a9c80e5SJohn Baldwin.Nm pci_restore_state ,
620a9c80e5SJohn Baldwin.Nm pci_save_state ,
63855ed4c5SJohn Baldwin.Nm pci_set_max_read_req ,
640a9c80e5SJohn Baldwin.Nm pci_set_powerstate ,
65ec603c72SJohn Baldwin.Nm pci_write_config ,
66ec603c72SJohn Baldwin.Nm pcie_adjust_config ,
67ec603c72SJohn Baldwin.Nm pcie_read_config ,
68ec603c72SJohn Baldwin.Nm pcie_write_config
69aac0aafaSHiten Pandya.Nd PCI bus interface
70aac0aafaSHiten Pandya.Sh SYNOPSIS
71aac0aafaSHiten Pandya.In sys/bus.h
72aac0aafaSHiten Pandya.In dev/pci/pcireg.h
73855ed4c5SJohn Baldwin.In dev/pci/pcivar.h
74855ed4c5SJohn Baldwin.Ft int
75855ed4c5SJohn Baldwin.Fn pci_alloc_msi "device_t dev" "int *count"
76855ed4c5SJohn Baldwin.Ft int
77855ed4c5SJohn Baldwin.Fn pci_alloc_msix "device_t dev" "int *count"
78aac0aafaSHiten Pandya.Ft int
79aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev"
80aac0aafaSHiten Pandya.Ft int
81aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space"
82aac0aafaSHiten Pandya.Ft int
830a9c80e5SJohn Baldwin.Fn pci_enable_busmaster "device_t dev"
84aac0aafaSHiten Pandya.Ft int
850a9c80e5SJohn Baldwin.Fn pci_enable_io "device_t dev" "int space"
86aac0aafaSHiten Pandya.Ft device_t
8765bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
88855ed4c5SJohn Baldwin.Ft int
89855ed4c5SJohn Baldwin.Fn pci_find_cap "device_t dev" "int capability" "int *capreg"
90aac0aafaSHiten Pandya.Ft device_t
9155aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
9255aaf894SMarius Strobl.Ft device_t
9365bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device"
940a9c80e5SJohn Baldwin.Ft int
9568bf9717SJohn Baldwin.Fn pci_find_extcap "device_t dev" "int capability" "int *capreg"
9668bf9717SJohn Baldwin.Ft int
9768bf9717SJohn Baldwin.Fn pci_find_htcap "device_t dev" "int capability" "int *capreg"
9887dd2f95SJohn Baldwin.Ft device_t
9987dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port "device_t dev"
10068bf9717SJohn Baldwin.Ft int
101*d7be980dSAndrew Turner.Fn pci_get_id "device_t dev" "enum pci_id_type type" "uintptr_t *id"
102*d7be980dSAndrew Turner.Ft int
103855ed4c5SJohn Baldwin.Fn pci_get_max_read_req "device_t dev"
104855ed4c5SJohn Baldwin.Ft int
1050a9c80e5SJohn Baldwin.Fn pci_get_powerstate "device_t dev"
106855ed4c5SJohn Baldwin.Ft int
107855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
108855ed4c5SJohn Baldwin.Ft int
109855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
110855ed4c5SJohn Baldwin.Ft int
111855ed4c5SJohn Baldwin.Fn pci_msi_count "device_t dev"
112855ed4c5SJohn Baldwin.Ft int
113855ed4c5SJohn Baldwin.Fn pci_msix_count "device_t dev"
114855ed4c5SJohn Baldwin.Ft int
115ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar "device_t dev"
116ce204e1bSJohn Baldwin.Ft int
117ce204e1bSJohn Baldwin.Fn pci_msix_table_bar "device_t dev"
118ce204e1bSJohn Baldwin.Ft int
119855ed4c5SJohn Baldwin.Fn pci_pending_msix "device_t dev" "u_int index"
1200a9c80e5SJohn Baldwin.Ft uint32_t
1210a9c80e5SJohn Baldwin.Fn pci_read_config "device_t dev" "int reg" "int width"
122855ed4c5SJohn Baldwin.Ft int
123855ed4c5SJohn Baldwin.Fn pci_release_msi "device_t dev"
124855ed4c5SJohn Baldwin.Ft int
125855ed4c5SJohn Baldwin.Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors"
1260a9c80e5SJohn Baldwin.Ft void
1270a9c80e5SJohn Baldwin.Fn pci_restore_state "device_t dev"
1280a9c80e5SJohn Baldwin.Ft void
1290a9c80e5SJohn Baldwin.Fn pci_save_state "device_t dev"
1300a9c80e5SJohn Baldwin.Ft int
131855ed4c5SJohn Baldwin.Fn pci_set_max_read_req "device_t dev" "int size"
132855ed4c5SJohn Baldwin.Ft int
1330a9c80e5SJohn Baldwin.Fn pci_set_powerstate "device_t dev" "int state"
1340a9c80e5SJohn Baldwin.Ft void
1350a9c80e5SJohn Baldwin.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
136ec603c72SJohn Baldwin.Ft uint32_t
137ec603c72SJohn Baldwin.Fo pcie_adjust_config
138ec603c72SJohn Baldwin.Fa "device_t dev"
139ec603c72SJohn Baldwin.Fa "int reg"
140ec603c72SJohn Baldwin.Fa "uint32_t mask"
141ec603c72SJohn Baldwin.Fa "uint32_t val"
142ec603c72SJohn Baldwin.Fa "int width"
143ec603c72SJohn Baldwin.Fc
144ec603c72SJohn Baldwin.Ft uint32_t
145ec603c72SJohn Baldwin.Fn pcie_read_config "device_t dev" "int reg" "int width"
146ec603c72SJohn Baldwin.Ft void
147ec603c72SJohn Baldwin.Fn pcie_write_config "device_t dev" "int reg" "uint32_t val" "int width"
148f3bb9251SJohn Baldwin.In dev/pci/pci_iov.h
149f3bb9251SJohn Baldwin.Ft int
150f3bb9251SJohn Baldwin.Fn pci_iov_attach "device_t dev" "nvlist_t *pf_schema" "nvlist_t *vf_schema"
151f3bb9251SJohn Baldwin.Ft int
152f3bb9251SJohn Baldwin.Fn pci_iov_detach "device_t dev"
153aac0aafaSHiten Pandya.Sh DESCRIPTION
154aac0aafaSHiten PandyaThe
155aac0aafaSHiten Pandya.Nm
156aac0aafaSHiten Pandyaset of functions are used for managing PCI devices.
157855ed4c5SJohn BaldwinThe functions are split into several groups:
158855ed4c5SJohn Baldwinraw configuration access,
159855ed4c5SJohn Baldwinlocating devices,
160855ed4c5SJohn Baldwindevice information,
161855ed4c5SJohn Baldwindevice configuration,
162855ed4c5SJohn Baldwinand
163855ed4c5SJohn Baldwinmessage signaled interrupts.
164855ed4c5SJohn Baldwin.Ss Raw Configuration Access
165aac0aafaSHiten PandyaThe
166aac0aafaSHiten Pandya.Fn pci_read_config
167aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration
168aac0aafaSHiten Pandyaspace of the device
169aac0aafaSHiten Pandya.Fa dev ,
170aac0aafaSHiten Pandyaat offset
171aac0aafaSHiten Pandya.Fa reg ,
172aac0aafaSHiten Pandyawith
173aac0aafaSHiten Pandya.Fa width
174aac0aafaSHiten Pandyaspecifying the size of the access.
175aac0aafaSHiten Pandya.Pp
176aac0aafaSHiten PandyaThe
177aac0aafaSHiten Pandya.Fn pci_write_config
178aac0aafaSHiten Pandyafunction is used to write the value
179aac0aafaSHiten Pandya.Fa val
180aac0aafaSHiten Pandyato the PCI configuration
181aac0aafaSHiten Pandyaspace of the device
182aac0aafaSHiten Pandya.Fa dev ,
183aac0aafaSHiten Pandyaat offset
184aac0aafaSHiten Pandya.Fa reg ,
185aac0aafaSHiten Pandyawith
186aac0aafaSHiten Pandya.Fa width
187aac0aafaSHiten Pandyaspecifying the size of the access.
188aac0aafaSHiten Pandya.Pp
189ec603c72SJohn BaldwinThe
190ec603c72SJohn Baldwin.Fn pcie_adjust_config
191ec603c72SJohn Baldwinfunction is used to modify the value of a register in the PCI-express
192ec603c72SJohn Baldwincapability register set of device
193ec603c72SJohn Baldwin.Fa dev .
194ec603c72SJohn BaldwinThe offset
195ec603c72SJohn Baldwin.Fa reg
196ec603c72SJohn Baldwinspecifies a relative offset in the register set with
197ec603c72SJohn Baldwin.Fa width
198ec603c72SJohn Baldwinspecifying the size of the access.
199ec603c72SJohn BaldwinThe new value of the register is computed by modifying bits set in
200ec603c72SJohn Baldwin.Fa mask
201ec603c72SJohn Baldwinto the value in
202ec603c72SJohn Baldwin.Fa val .
203ec603c72SJohn BaldwinAny bits not specified in
204ec603c72SJohn Baldwin.Fa mask
205ec603c72SJohn Baldwinare preserved.
206ec603c72SJohn BaldwinThe previous value of the register is returned.
207ec603c72SJohn Baldwin.Pp
208ec603c72SJohn BaldwinThe
209ec603c72SJohn Baldwin.Fn pcie_read_config
210ec603c72SJohn Baldwinfunction is used to read the value of a register in the PCI-express
211ec603c72SJohn Baldwincapability register set of device
212ec603c72SJohn Baldwin.Fa dev .
213ec603c72SJohn BaldwinThe offset
214ec603c72SJohn Baldwin.Fa reg
215ec603c72SJohn Baldwinspecifies a relative offset in the register set with
216ec603c72SJohn Baldwin.Fa width
217ec603c72SJohn Baldwinspecifying the size of the access.
218ec603c72SJohn Baldwin.Pp
219ec603c72SJohn BaldwinThe
220ec603c72SJohn Baldwin.Fn pcie_write_config
221ec603c72SJohn Baldwinfunction is used to write the value
222ec603c72SJohn Baldwin.Fa val
223ec603c72SJohn Baldwinto a register in the PCI-express capability register set of device
224ec603c72SJohn Baldwin.Fa dev .
225ec603c72SJohn BaldwinThe offset
226ec603c72SJohn Baldwin.Fa reg
227ec603c72SJohn Baldwinspecifies a relative offset in the register set with
228ec603c72SJohn Baldwin.Fa width
229ec603c72SJohn Baldwinspecifying the size of the access.
230ec603c72SJohn Baldwin.Pp
231855ed4c5SJohn Baldwin.Em NOTE :
232855ed4c5SJohn BaldwinDevice drivers should only use these functions for functionality that
233855ed4c5SJohn Baldwinis not available via another
234855ed4c5SJohn Baldwin.Fn pci
235855ed4c5SJohn Baldwinfunction.
236855ed4c5SJohn Baldwin.Ss Locating Devices
237855ed4c5SJohn BaldwinThe
238855ed4c5SJohn Baldwin.Fn pci_find_bsf
239855ed4c5SJohn Baldwinfunction looks up the
240855ed4c5SJohn Baldwin.Vt device_t
241855ed4c5SJohn Baldwinof a PCI device, given its
242855ed4c5SJohn Baldwin.Fa bus ,
243855ed4c5SJohn Baldwin.Fa slot ,
244855ed4c5SJohn Baldwinand
245855ed4c5SJohn Baldwin.Fa func .
246855ed4c5SJohn BaldwinThe
247855ed4c5SJohn Baldwin.Fa slot
248855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
249855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
250855ed4c5SJohn Baldwinin terms of a physical slot.
251855ed4c5SJohn BaldwinNote that in case the system has multiple PCI domains,
252855ed4c5SJohn Baldwinthe
253855ed4c5SJohn Baldwin.Fn pci_find_bsf
254855ed4c5SJohn Baldwinfunction only searches the first one.
255855ed4c5SJohn BaldwinActually, it is equivalent to:
256855ed4c5SJohn Baldwin.Bd -literal -offset indent
257855ed4c5SJohn Baldwinpci_find_dbsf(0, bus, slot, func);
258855ed4c5SJohn Baldwin.Ed
259855ed4c5SJohn Baldwin.Pp
260855ed4c5SJohn BaldwinThe
261855ed4c5SJohn Baldwin.Fn pci_find_dbsf
262855ed4c5SJohn Baldwinfunction looks up the
263855ed4c5SJohn Baldwin.Vt device_t
264855ed4c5SJohn Baldwinof a PCI device, given its
265855ed4c5SJohn Baldwin.Fa domain ,
266855ed4c5SJohn Baldwin.Fa bus ,
267855ed4c5SJohn Baldwin.Fa slot ,
268855ed4c5SJohn Baldwinand
269855ed4c5SJohn Baldwin.Fa func .
270855ed4c5SJohn BaldwinThe
271855ed4c5SJohn Baldwin.Fa slot
272855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
273855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
274855ed4c5SJohn Baldwinin terms of a physical slot.
275855ed4c5SJohn Baldwin.Pp
276855ed4c5SJohn BaldwinThe
277855ed4c5SJohn Baldwin.Fn pci_find_device
278855ed4c5SJohn Baldwinfunction looks up the
279855ed4c5SJohn Baldwin.Vt device_t
280855ed4c5SJohn Baldwinof a PCI device, given its
281855ed4c5SJohn Baldwin.Fa vendor
282855ed4c5SJohn Baldwinand
283855ed4c5SJohn Baldwin.Fa device
284855ed4c5SJohn BaldwinIDs.
285855ed4c5SJohn BaldwinNote that there can be multiple matches for this search; this function
286855ed4c5SJohn Baldwinonly returns the first matching device.
287855ed4c5SJohn Baldwin.Ss Device Information
288855ed4c5SJohn BaldwinThe
289855ed4c5SJohn Baldwin.Fn pci_find_cap
290855ed4c5SJohn Baldwinfunction is used to locate the first instance of a PCI capability
291855ed4c5SJohn Baldwinregister set for the device
292855ed4c5SJohn Baldwin.Fa dev .
293855ed4c5SJohn BaldwinThe capability to locate is specified by ID via
294855ed4c5SJohn Baldwin.Fa capability .
295855ed4c5SJohn BaldwinConstant macros of the form
296855ed4c5SJohn Baldwin.Dv PCIY_xxx
297855ed4c5SJohn Baldwinfor standard capability IDs are defined in
298855ed4c5SJohn Baldwin.In dev/pci/pcireg.h .
299855ed4c5SJohn BaldwinIf the capability is found, then
300855ed4c5SJohn Baldwin.Fa *capreg
301281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
302855ed4c5SJohn Baldwinand
303855ed4c5SJohn Baldwin.Fn pci_find_cap
304855ed4c5SJohn Baldwinreturns zero.
305855ed4c5SJohn BaldwinIf the capability is not found or the device does not support capabilities,
306855ed4c5SJohn Baldwin.Fn pci_find_cap
307855ed4c5SJohn Baldwinreturns an error.
308855ed4c5SJohn Baldwin.Pp
309855ed4c5SJohn BaldwinThe
31068bf9717SJohn Baldwin.Fn pci_find_extcap
31168bf9717SJohn Baldwinfunction is used to locate the first instance of a PCI-express
31268bf9717SJohn Baldwinextended capability register set for the device
31368bf9717SJohn Baldwin.Fa dev .
31468bf9717SJohn BaldwinThe extended capability to locate is specified by ID via
31568bf9717SJohn Baldwin.Fa capability .
31668bf9717SJohn BaldwinConstant macros of the form
31768bf9717SJohn Baldwin.Dv PCIZ_xxx
31868bf9717SJohn Baldwinfor standard extended capability IDs are defined in
31968bf9717SJohn Baldwin.In dev/pci/pcireg.h .
32068bf9717SJohn BaldwinIf the extended capability is found, then
32168bf9717SJohn Baldwin.Fa *capreg
322281a359eSJohn Baldwinis set to the offset in configuration space of the extended capability
32368bf9717SJohn Baldwinregister set, and
32468bf9717SJohn Baldwin.Fn pci_find_extcap
32568bf9717SJohn Baldwinreturns zero.
32668bf9717SJohn BaldwinIf the extended capability is not found or the device is not a
32768bf9717SJohn BaldwinPCI-express device,
32868bf9717SJohn Baldwin.Fn pci_find_extcap
32968bf9717SJohn Baldwinreturns an error.
33068bf9717SJohn Baldwin.Pp
33168bf9717SJohn BaldwinThe
33268bf9717SJohn Baldwin.Fn pci_find_htcap
33368bf9717SJohn Baldwinfunction is used to locate the first instance of a HyperTransport capability
33468bf9717SJohn Baldwinregister set for the device
33568bf9717SJohn Baldwin.Fa dev .
33668bf9717SJohn BaldwinThe capability to locate is specified by type via
33768bf9717SJohn Baldwin.Fa capability .
33868bf9717SJohn BaldwinConstant macros of the form
33968bf9717SJohn Baldwin.Dv PCIM_HTCAP_xxx
34068bf9717SJohn Baldwinfor standard HyperTransport capability types are defined in
34168bf9717SJohn Baldwin.In dev/pci/pcireg.h .
34268bf9717SJohn BaldwinIf the capability is found, then
34368bf9717SJohn Baldwin.Fa *capreg
344281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
34568bf9717SJohn Baldwinand
34668bf9717SJohn Baldwin.Fn pci_find_htcap
34768bf9717SJohn Baldwinreturns zero.
34868bf9717SJohn BaldwinIf the capability is not found or the device is not a HyperTransport device,
34968bf9717SJohn Baldwin.Fn pci_find_htcap
35068bf9717SJohn Baldwinreturns an error.
35168bf9717SJohn Baldwin.Pp
35268bf9717SJohn BaldwinThe
35387dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
35487dd2f95SJohn Baldwinfunction walks up the PCI device hierarchy to locate the PCI-express root
35587dd2f95SJohn Baldwinport upstream of
35687dd2f95SJohn Baldwin.Fa dev .
35787dd2f95SJohn BaldwinIf a root port is not found,
35887dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
35987dd2f95SJohn Baldwinreturns
36087dd2f95SJohn Baldwin.Dv NULL .
36187dd2f95SJohn Baldwin.Pp
36287dd2f95SJohn BaldwinThe
363*d7be980dSAndrew Turner.Fn pci_get_id
364*d7be980dSAndrew Turnerfunction is used to read an identifier from a device.
365*d7be980dSAndrew TurnerThe
366*d7be980dSAndrew Turner.Fa type
367*d7be980dSAndrew Turnerflag is used to specify which identifier to read.
368*d7be980dSAndrew TurnerThe following flags are supported:
369*d7be980dSAndrew Turner.Bl -hang -width ".Dv PCI_ID_RID"
370*d7be980dSAndrew Turner.It Dv PCI_ID_RID
371*d7be980dSAndrew TurnerRead the routing identifier for the device.
372*d7be980dSAndrew Turner.El
373*d7be980dSAndrew Turner.Pp
374*d7be980dSAndrew TurnerThe
375855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
376855ed4c5SJohn Baldwinfunction is used to fetch a device's Vital Product Data
377855ed4c5SJohn Baldwin.Pq VPD
378855ed4c5SJohn Baldwinidentifier string.
379855ed4c5SJohn BaldwinIf the device
380855ed4c5SJohn Baldwin.Fa dev
381855ed4c5SJohn Baldwinsupports VPD and provides an identifier string,
382855ed4c5SJohn Baldwinthen
383855ed4c5SJohn Baldwin.Fa *identptr
384855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the identifier
385855ed4c5SJohn Baldwinstring,
386855ed4c5SJohn Baldwinand
387855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
388855ed4c5SJohn Baldwinreturns zero.
389855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide an identifier
390855ed4c5SJohn Baldwinstring,
391855ed4c5SJohn Baldwinthen
392855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
393855ed4c5SJohn Baldwinreturns an error.
394855ed4c5SJohn Baldwin.Pp
395855ed4c5SJohn BaldwinThe
396855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
397855ed4c5SJohn Baldwinfunction is used to fetch the value of a single VPD read-only keyword
398855ed4c5SJohn Baldwinfor the device
399855ed4c5SJohn Baldwin.Fa dev .
400855ed4c5SJohn BaldwinThe keyword to fetch is identified by the two character string
401855ed4c5SJohn Baldwin.Fa kw .
402855ed4c5SJohn BaldwinIf the device supports VPD and provides a read-only value for the
403855ed4c5SJohn Baldwinrequested keyword,
404855ed4c5SJohn Baldwinthen
405855ed4c5SJohn Baldwin.Fa *vptr
406855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the value,
407855ed4c5SJohn Baldwinand
408855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
409855ed4c5SJohn Baldwinreturns zero.
410855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide the requested
411855ed4c5SJohn Baldwinkeyword,
412855ed4c5SJohn Baldwinthen
413855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
414855ed4c5SJohn Baldwinreturns an error.
415855ed4c5SJohn Baldwin.Ss Device Configuration
416aac0aafaSHiten PandyaThe
417aac0aafaSHiten Pandya.Fn pci_enable_busmaster
418aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device
419aac0aafaSHiten Pandya.Fa dev ,
420aac0aafaSHiten Pandyaby setting the
421aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN
422aac0aafaSHiten Pandyabit in the
423aac0aafaSHiten Pandya.Dv PCIR_COMMAND
424aac0aafaSHiten Pandyaregister.
425aac0aafaSHiten PandyaThe
426aac0aafaSHiten Pandya.Fn pci_disable_busmaster
427aac0aafaSHiten Pandyafunction clears this bit.
428aac0aafaSHiten Pandya.Pp
429aac0aafaSHiten PandyaThe
430aac0aafaSHiten Pandya.Fn pci_enable_io
431aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device
432aac0aafaSHiten Pandya.Fa dev ,
433aac0aafaSHiten Pandyaby setting the
434aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN
435aac0aafaSHiten Pandyaor
436aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN
437aac0aafaSHiten Pandyabit in the
438aac0aafaSHiten Pandya.Dv PCIR_COMMAND
4395203edcdSRuslan Ermilovregister appropriately.
4405203edcdSRuslan ErmilovThe
441aac0aafaSHiten Pandya.Fn pci_disable_io
442aac0aafaSHiten Pandyafunction clears the appropriate bit.
443aac0aafaSHiten PandyaThe
44465bb31b8SRuslan Ermilov.Fa space
445aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either
446aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY
447aac0aafaSHiten Pandyaor
448aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT
449aac0aafaSHiten Pandyaas appropriate.
450855ed4c5SJohn BaldwinDevice drivers should generally not use these routines directly.
451855ed4c5SJohn BaldwinThe PCI bus will enable decoding automatically when a
452855ed4c5SJohn Baldwin.Dv SYS_RES_MEMORY
453855ed4c5SJohn Baldwinor
454855ed4c5SJohn Baldwin.Dv SYS_RES_IOPORT
455855ed4c5SJohn Baldwinresource is activated via
456855ed4c5SJohn Baldwin.Xr bus_alloc_resource 9
457855ed4c5SJohn Baldwinor
458855ed4c5SJohn Baldwin.Xr bus_activate_resource 9 .
459aac0aafaSHiten Pandya.Pp
460855ed4c5SJohn BaldwinThe
461855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
462855ed4c5SJohn Baldwinfunction returns the current maximum read request size in bytes for a
463855ed4c5SJohn BaldwinPCI-express device.
464855ed4c5SJohn BaldwinIf the
465855ed4c5SJohn Baldwin.Fa dev
466855ed4c5SJohn Baldwindevice is not a PCI-express device,
467855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
468855ed4c5SJohn Baldwinreturns zero.
469855ed4c5SJohn Baldwin.Pp
470855ed4c5SJohn BaldwinThe
471855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
472855ed4c5SJohn Baldwinsets the PCI-express maximum read request size for
473855ed4c5SJohn Baldwin.Fa dev .
474855ed4c5SJohn BaldwinThe requested
475855ed4c5SJohn Baldwin.Fa size
476855ed4c5SJohn Baldwinmay be adjusted,
477855ed4c5SJohn Baldwinand
478855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
479855ed4c5SJohn Baldwinreturns the actual size set in bytes.
480855ed4c5SJohn BaldwinIf the
481855ed4c5SJohn Baldwin.Fa dev
482855ed4c5SJohn Baldwindevice is not a PCI-express device,
483855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
484855ed4c5SJohn Baldwinreturns zero.
485aac0aafaSHiten Pandya.Pp
486aac0aafaSHiten PandyaThe
487aac0aafaSHiten Pandya.Fn pci_get_powerstate
488adb63907SJohn Baldwinfunction returns the current power state of the device
489aac0aafaSHiten Pandya.Fa dev .
490aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default
491aac0aafaSHiten Pandyastate of
492aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0
493aac0aafaSHiten Pandyais returned.
494adb63907SJohn BaldwinThe following power states are defined by PCI:
49565bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
496aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0
497aac0aafaSHiten PandyaState in which device is on and running.
498aac0aafaSHiten PandyaIt is receiving full power from the system and delivering
499aac0aafaSHiten Pandyafull functionality to the user.
500aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1
501aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
5025a2e3b61SDaniel Gerzomay not be lost.
50365bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to
5049817b894SBruce M Simpsonforce devices to lose context.
505aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2
506aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
507aac0aafaSHiten Pandyamay not be lost.
508aac0aafaSHiten PandyaAttains greater power savings than
509aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 .
51065bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context.
511aac0aafaSHiten PandyaDevices
512aac0aafaSHiten Pandya.Em must
513aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher.
514aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3
515aac0aafaSHiten PandyaState in which the device is off and not running.
516aac0aafaSHiten PandyaDevice context is lost, and power from the device can
517aac0aafaSHiten Pandyabe removed.
518aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN
519aac0aafaSHiten PandyaState of the device is unknown.
520aac0aafaSHiten Pandya.El
521aac0aafaSHiten Pandya.Pp
522aac0aafaSHiten PandyaThe
523aac0aafaSHiten Pandya.Fn pci_set_powerstate
524aac0aafaSHiten Pandyafunction is used to transition the device
525aac0aafaSHiten Pandya.Fa dev
526adb63907SJohn Baldwinto the PCI power state
527aac0aafaSHiten Pandya.Fa state .
528adb63907SJohn BaldwinIf the device does not support power management capabilities or
529adb63907SJohn Baldwinit does not support the specific power state
530adb63907SJohn Baldwin.Fa state ,
531adb63907SJohn Baldwinthen the function will fail with
532adb63907SJohn Baldwin.Er EOPNOTSUPP .
533aac0aafaSHiten Pandya.Pp
534aac0aafaSHiten PandyaThe
5357d971e36SRyan Stone.Fn pci_iov_attach
5367d971e36SRyan Stonefunction is used to advertise that the given device
5377d971e36SRyan Stone.Pq and associated device driver
5387d971e36SRyan Stonesupports PCI Single-Root I/O Virtualization
539fe3ff217SPatrick Kelsey.Pq SR-IOV .
5407d971e36SRyan StoneA driver that supports SR-IOV must implement the
541f3bb9251SJohn Baldwin.Xr PCI_IOV_INIT 9 ,
542f3bb9251SJohn Baldwin.Xr PCI_IOV_ADD_VF 9
5437d971e36SRyan Stoneand
544f3bb9251SJohn Baldwin.Xr PCI_IOV_UNINIT 9
5457d971e36SRyan Stonemethods.
5467d971e36SRyan StoneThis function should be called during the
5477d971e36SRyan Stone.Xr DEVICE_ATTACH 9
5487d971e36SRyan Stonemethod.
5497d971e36SRyan StoneIf this function returns an error, it is recommended that the device driver
5507d971e36SRyan Stonestill successfully attaches, but runs with SR-IOV disabled.
5517d971e36SRyan StoneThe
5527d971e36SRyan Stone.Fa pf_schema
5537d971e36SRyan Stoneand
5547d971e36SRyan Stone.Fa vf_schema
5557d971e36SRyan Stoneparameters are used to define what device-specific configuration parameters the
5567d971e36SRyan Stonedevice driver accepts when SR-IOV is enabled for the Physical Function
5577d971e36SRyan Stone.Pq PF
5587d971e36SRyan Stoneand for individual Virtual Functions
5597d971e36SRyan Stone.Pq VFs
5607d971e36SRyan Stonerespectively.
5617d971e36SRyan StoneSee
5627d971e36SRyan Stone.Xr pci_iov_schema 9
5637d971e36SRyan Stonefor details on how to construct the schema.
5647d971e36SRyan StoneIf either the
5657d971e36SRyan Stone.Pa pf_schema
5667d971e36SRyan Stoneor
5677d971e36SRyan Stone.Pa vf_schema
5687d971e36SRyan Stoneis invalid or specifies parameter names that conflict with parameter names that
5697d971e36SRyan Stoneare already in use,
5707d971e36SRyan Stone.Fn pci_iov_attach
5717d971e36SRyan Stonewill return an error and SR-IOV will not be available on the PF device.
5727d971e36SRyan StoneIf a driver does not accept configuration parameters for either the PF device
5737d971e36SRyan Stoneor the VF devices, the driver must pass an empty schema for that device.
5747d971e36SRyan StoneThe SR-IOV infrastructure takes ownership of the
5757d971e36SRyan Stone.Fa pf_schema
5767d971e36SRyan Stoneand
5777d971e36SRyan Stone.Fa vf_schema
5787d971e36SRyan Stoneand is responsible for freeing them.
5797d971e36SRyan StoneThe driver must never free the schemas itself.
5807d971e36SRyan Stone.Pp
5817d971e36SRyan StoneThe
5827d971e36SRyan Stone.Fn pci_iov_detach
5837d971e36SRyan Stonefunction is used to advise the SR-IOV infrastructure that the driver for the
5847d971e36SRyan Stonegiven device is attempting to detach and that all SR-IOV resources for the
5857d971e36SRyan Stonedevice must be released.
5867d971e36SRyan StoneThis function must be called during the
5877d971e36SRyan Stone.Xr DEVICE_DETACH 9
5887d971e36SRyan Stonemethod if
5897d971e36SRyan Stone.Fn pci_iov_attach
5907d971e36SRyan Stonewas successfully called on the device and
5917d971e36SRyan Stone.Fn pci_iov_detach
5927d971e36SRyan Stonehas not subsequently been called on the device and returned no error.
5937d971e36SRyan StoneIf this function returns an error, the
5947d971e36SRyan Stone.Xr DEVICE_DETACH 9
5957d971e36SRyan Stonemethod must fail and return an error, as detaching the PF driver while VF
5967d971e36SRyan Stonedevices are active would cause system instability.
5977d971e36SRyan StoneThis function is safe to call and will always succeed if
5987d971e36SRyan Stone.Fn pci_iov_attach
5997d971e36SRyan Stonepreviously failed with an error on the given device, or if
6007d971e36SRyan Stone.Fn pci_iov_attach
6017d971e36SRyan Stonewas never called on the device.
6027d971e36SRyan Stone.Pp
6037d971e36SRyan StoneThe
6049415d1e0SJohn Baldwin.Fn pci_save_state
6059415d1e0SJohn Baldwinand
6069415d1e0SJohn Baldwin.Fn pci_restore_state
6079415d1e0SJohn Baldwinfunctions can be used by a device driver to save and restore standard PCI
6089415d1e0SJohn Baldwinconfig registers.
6099415d1e0SJohn BaldwinThe
6109415d1e0SJohn Baldwin.Fn pci_save_state
6119415d1e0SJohn Baldwinfunction must be invoked while the device has valid state before
6129415d1e0SJohn Baldwin.Fn pci_restore_state
6139415d1e0SJohn Baldwincan be used.
6149415d1e0SJohn BaldwinIf the device is not in the fully-powered state
6159415d1e0SJohn Baldwin.Pq Dv PCI_POWERSTATE_D0
6169415d1e0SJohn Baldwinwhen
6179415d1e0SJohn Baldwin.Fn pci_restore_state
6189415d1e0SJohn Baldwinis invoked,
6199415d1e0SJohn Baldwinthen the device will be transitioned to
6209415d1e0SJohn Baldwin.Dv PCI_POWERSTATE_D0
6219415d1e0SJohn Baldwinbefore any config registers are restored.
622855ed4c5SJohn Baldwin.Ss Message Signaled Interrupts
623855ed4c5SJohn BaldwinMessage Signaled Interrupts
624855ed4c5SJohn Baldwin.Pq MSI
625855ed4c5SJohn Baldwinand
626855ed4c5SJohn BaldwinEnhanced Message Signaled Interrupts
627855ed4c5SJohn Baldwin.Pq MSI-X
628855ed4c5SJohn Baldwinare PCI capabilities that provide an alternate method for PCI
629855ed4c5SJohn Baldwindevices to signal interrupts.
630855ed4c5SJohn BaldwinThe legacy INTx interrupt is available to PCI devices as a
631855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
632855ed4c5SJohn Baldwinresource with a resource ID of zero.
633855ed4c5SJohn BaldwinMSI and MSI-X interrupts are available to PCI devices as one or more
634855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
635855ed4c5SJohn Baldwinresources with resource IDs greater than zero.
636855ed4c5SJohn BaldwinA driver must ask the PCI bus to allocate MSI or MSI-X interrupts
637855ed4c5SJohn Baldwinusing
638855ed4c5SJohn Baldwin.Fn pci_alloc_msi
639855ed4c5SJohn Baldwinor
640855ed4c5SJohn Baldwin.Fn pci_alloc_msix
641855ed4c5SJohn Baldwinbefore it can use MSI or MSI-X
642855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
643855ed4c5SJohn Baldwinresources.
644855ed4c5SJohn BaldwinA driver is not allowed to use the legacy INTx
645855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
646855ed4c5SJohn Baldwinresource if MSI or MSI-X interrupts have been allocated,
647855ed4c5SJohn Baldwinand attempts to allocate MSI or MSI-X interrupts will fail if the
648855ed4c5SJohn Baldwindriver is currently using the legacy INTx
649855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
650855ed4c5SJohn Baldwinresource.
651855ed4c5SJohn BaldwinA driver is only allowed to use either MSI or MSI-X,
652855ed4c5SJohn Baldwinbut not both.
6539415d1e0SJohn Baldwin.Pp
6549415d1e0SJohn BaldwinThe
655563d4639SMark Johnston.Fn pci_msi_count
656855ed4c5SJohn Baldwinfunction returns the maximum number of MSI messages supported by the
657855ed4c5SJohn Baldwindevice
658855ed4c5SJohn Baldwin.Fa dev .
659855ed4c5SJohn BaldwinIf the device does not support MSI,
660855ed4c5SJohn Baldwinthen
661563d4639SMark Johnston.Fn pci_msi_count
662855ed4c5SJohn Baldwinreturns zero.
66355aaf894SMarius Strobl.Pp
66455aaf894SMarius StroblThe
665855ed4c5SJohn Baldwin.Fn pci_alloc_msi
666855ed4c5SJohn Baldwinfunction attempts to allocate
667855ed4c5SJohn Baldwin.Fa *count
668855ed4c5SJohn BaldwinMSI messages for the device
669855ed4c5SJohn Baldwin.Fa dev .
67055aaf894SMarius StroblThe
671855ed4c5SJohn Baldwin.Fn pci_alloc_msi
672855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
673855ed4c5SJohn Baldwinreasons including requests for more messages than the device
674855ed4c5SJohn Baldwin.Fa dev
675855ed4c5SJohn Baldwinsupports,
676855ed4c5SJohn Baldwinor if the system has a shortage of available MSI messages.
677855ed4c5SJohn BaldwinOn success,
678855ed4c5SJohn Baldwin.Fa *count
679855ed4c5SJohn Baldwinis set to the number of messages allocated and
680855ed4c5SJohn Baldwin.Fn pci_alloc_msi
681855ed4c5SJohn Baldwinreturns zero.
682855ed4c5SJohn BaldwinThe
683855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
684855ed4c5SJohn Baldwinresources for the allocated messages will be available at consecutive
685855ed4c5SJohn Baldwinresource IDs beginning with one.
686855ed4c5SJohn BaldwinIf
687855ed4c5SJohn Baldwin.Fn pci_alloc_msi
688855ed4c5SJohn Baldwinis not able to allocate any messages,
689855ed4c5SJohn Baldwinit returns an error.
690855ed4c5SJohn BaldwinNote that MSI only supports message counts that are powers of two;
691855ed4c5SJohn Baldwinrequests to allocate a non-power of two count of messages will fail.
692aac0aafaSHiten Pandya.Pp
693aac0aafaSHiten PandyaThe
694855ed4c5SJohn Baldwin.Fn pci_release_msi
695855ed4c5SJohn Baldwinfunction is used to release any allocated MSI or MSI-X messages back
696855ed4c5SJohn Baldwinto the system.
697855ed4c5SJohn BaldwinIf any MSI or MSI-X
698855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
699855ed4c5SJohn Baldwinresources are allocated by the driver or have a configured interrupt
700855ed4c5SJohn Baldwinhandler,
701855ed4c5SJohn Baldwinthis function will fail with
702855ed4c5SJohn Baldwin.Er EBUSY .
703855ed4c5SJohn BaldwinThe
704855ed4c5SJohn Baldwin.Fn pci_release_msi
705855ed4c5SJohn Baldwinfunction returns zero on success and an error on failure.
706855ed4c5SJohn Baldwin.Pp
707642c4993SSergey KandaurovThe
708563d4639SMark Johnston.Fn pci_msix_count
709855ed4c5SJohn Baldwinfunction returns the maximum number of MSI-X messages supported by the
710855ed4c5SJohn Baldwindevice
711855ed4c5SJohn Baldwin.Fa dev .
712855ed4c5SJohn BaldwinIf the device does not support MSI-X,
713855ed4c5SJohn Baldwinthen
714563d4639SMark Johnston.Fn pci_msix_count
715855ed4c5SJohn Baldwinreturns zero.
716855ed4c5SJohn Baldwin.Pp
717855ed4c5SJohn BaldwinThe
718ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
719ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the Base Address Register
720ce204e1bSJohn Baldwin.Pq BAR
721ce204e1bSJohn Baldwincontaining the MSI-X Pending Bit Array (PBA) for device
722ce204e1bSJohn Baldwin.Fa dev .
723ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
724ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
725ce204e1bSJohn Baldwinand
726ce204e1bSJohn Baldwin.Xr bus_release_resource 9
727ce204e1bSJohn Baldwinto allocate the BAR.
728ce204e1bSJohn BaldwinIf the device does not support MSI-X,
729ce204e1bSJohn Baldwinthen
730ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
731ce204e1bSJohn Baldwinreturns -1.
732ce204e1bSJohn Baldwin.Pp
733ce204e1bSJohn BaldwinThe
734ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
735ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the BAR
736ce204e1bSJohn Baldwincontaining the MSI-X vector table for device
737ce204e1bSJohn Baldwin.Fa dev .
738ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
739ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
740ce204e1bSJohn Baldwinand
741ce204e1bSJohn Baldwin.Xr bus_release_resource 9
742ce204e1bSJohn Baldwinto allocate the BAR.
743ce204e1bSJohn BaldwinIf the device does not support MSI-X,
744ce204e1bSJohn Baldwinthen
745ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
746ce204e1bSJohn Baldwinreturns -1.
747ce204e1bSJohn Baldwin.Pp
748ce204e1bSJohn BaldwinThe
749855ed4c5SJohn Baldwin.Fn pci_alloc_msix
750855ed4c5SJohn Baldwinfunction attempts to allocate
751855ed4c5SJohn Baldwin.Fa *count
752855ed4c5SJohn BaldwinMSI-X messages for the device
753855ed4c5SJohn Baldwin.Fa dev .
754855ed4c5SJohn BaldwinThe
755855ed4c5SJohn Baldwin.Fn pci_alloc_msix
756855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
757855ed4c5SJohn Baldwinreasons including requests for more messages than the device
758855ed4c5SJohn Baldwin.Fa dev
759855ed4c5SJohn Baldwinsupports,
760855ed4c5SJohn Baldwinor if the system has a shortage of available MSI-X messages.
761855ed4c5SJohn BaldwinOn success,
762855ed4c5SJohn Baldwin.Fa *count
763855ed4c5SJohn Baldwinis set to the number of messages allocated and
764855ed4c5SJohn Baldwin.Fn pci_alloc_msix
765855ed4c5SJohn Baldwinreturns zero.
766855ed4c5SJohn BaldwinFor MSI-X messages,
767855ed4c5SJohn Baldwinthe resource ID for each
76873bbeaa5SGlen Barber.Dv SYS_RES_IRQ
76973bbeaa5SGlen Barberresource identifies the index in the MSI-X table of the
770855ed4c5SJohn Baldwincorresponding message.
771855ed4c5SJohn BaldwinA resource ID of one maps to the first index of the MSI-X table;
772855ed4c5SJohn Baldwina resource ID two identifies the second index in the table, etc.
773855ed4c5SJohn BaldwinThe
774855ed4c5SJohn Baldwin.Fn pci_alloc_msix
775855ed4c5SJohn Baldwinfunction assigns the
776855ed4c5SJohn Baldwin.Fa *count
777855ed4c5SJohn Baldwinmessages allocated to the first
778855ed4c5SJohn Baldwin.Fa *count
7797c64ddd5SWarren Blocktable indices.
780855ed4c5SJohn BaldwinIf
781855ed4c5SJohn Baldwin.Fn pci_alloc_msix
782855ed4c5SJohn Baldwinis not able to allocate any messages,
783855ed4c5SJohn Baldwinit returns an error.
784855ed4c5SJohn BaldwinUnlike MSI,
785855ed4c5SJohn BaldwinMSI-X does not require message counts that are powers of two.
786855ed4c5SJohn Baldwin.Pp
787ce204e1bSJohn BaldwinThe BARs containing the MSI-X vector table and PBA must be
788ce204e1bSJohn Baldwinallocated via
789ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
790ce204e1bSJohn Baldwinbefore calling
791ce204e1bSJohn Baldwin.Fn pci_alloc_msix
792ce204e1bSJohn Baldwinand must not be released until after calling
793ce204e1bSJohn Baldwin.Fn pci_release_msi .
794ce204e1bSJohn BaldwinNote that the vector table and PBA may be stored in the same BAR or in
795ce204e1bSJohn Baldwindifferent BARs.
796ce204e1bSJohn Baldwin.Pp
797855ed4c5SJohn BaldwinThe
798855ed4c5SJohn Baldwin.Fn pci_pending_msix
799855ed4c5SJohn Baldwinfunction examines the
800855ed4c5SJohn Baldwin.Fa dev
801ce204e1bSJohn Baldwindevice's PBA
802855ed4c5SJohn Baldwinto determine the pending status of the MSI-X message at table index
803855ed4c5SJohn Baldwin.Fa index .
804855ed4c5SJohn BaldwinIf the indicated message is pending,
805855ed4c5SJohn Baldwinthis function returns a non-zero value;
806855ed4c5SJohn Baldwinotherwise,
807855ed4c5SJohn Baldwinit returns zero.
808855ed4c5SJohn BaldwinPassing an invalid
809855ed4c5SJohn Baldwin.Fa index
810855ed4c5SJohn Baldwinto this function will result in undefined behavior.
811855ed4c5SJohn Baldwin.Pp
812855ed4c5SJohn BaldwinAs mentioned in the description of
813855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
814855ed4c5SJohn BaldwinMSI-X messages are initially assigned to the first N table entries.
815855ed4c5SJohn BaldwinA driver may use a different distribution of available messages to
816855ed4c5SJohn Baldwintable entries via the
817855ed4c5SJohn Baldwin.Fn pci_remap_msix
818855ed4c5SJohn Baldwinfunction.
81973bbeaa5SGlen BarberNote that this function must be called after a successful call to
820855ed4c5SJohn Baldwin.Fn pci_alloc_msix
821855ed4c5SJohn Baldwinbut before any of the
822855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
823855ed4c5SJohn Baldwinresources are allocated.
824855ed4c5SJohn BaldwinThe
825855ed4c5SJohn Baldwin.Fn pci_remap_msix
826855ed4c5SJohn Baldwinfunction returns zero on success,
827855ed4c5SJohn Baldwinor an error on failure.
828855ed4c5SJohn Baldwin.Pp
829855ed4c5SJohn BaldwinThe
830855ed4c5SJohn Baldwin.Fa vectors
831855ed4c5SJohn Baldwinarray should contain
832855ed4c5SJohn Baldwin.Fa count
833855ed4c5SJohn Baldwinmessage vectors.
834855ed4c5SJohn BaldwinThe array maps directly to the MSI-X table in that the first entry in
835855ed4c5SJohn Baldwinthe array specifies the message used for the first entry in the MSI-X
836855ed4c5SJohn Baldwintable,
837855ed4c5SJohn Baldwinthe second entry in the array corresponds to the second entry in the
838855ed4c5SJohn BaldwinMSI-X table,
839855ed4c5SJohn Baldwinetc.
840855ed4c5SJohn BaldwinThe vector value in each array index can either be zero to indicate
841855ed4c5SJohn Baldwinthat no message should be assigned to the corresponding MSI-X table entry,
842855ed4c5SJohn Baldwinor it can be a number from one to N
843855ed4c5SJohn Baldwin.Po
844855ed4c5SJohn Baldwinwhere N is the count returned from the previous call to
845855ed4c5SJohn Baldwin.Fn pci_alloc_msix
846855ed4c5SJohn Baldwin.Pc
847855ed4c5SJohn Baldwinto indicate which of the allocated messages should be assigned to the
848855ed4c5SJohn Baldwincorresponding MSI-X table entry.
849855ed4c5SJohn Baldwin.Pp
850855ed4c5SJohn BaldwinIf
851855ed4c5SJohn Baldwin.Fn pci_remap_msix
852855ed4c5SJohn Baldwinsucceeds,
853855ed4c5SJohn Baldwineach MSI-X table entry with a non-zero vector will have an associated
854855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
855855ed4c5SJohn Baldwinresource whose resource ID corresponds to the table index as described
856855ed4c5SJohn Baldwinabove for
857855ed4c5SJohn Baldwin.Fn pci_alloc_msix .
858855ed4c5SJohn BaldwinMSI-X table entries that with a vector of zero will not have an
859855ed4c5SJohn Baldwinassociated
86073bbeaa5SGlen Barber.Dv SYS_RES_IRQ
86173bbeaa5SGlen Barberresource.
862855ed4c5SJohn BaldwinAdditionally,
863855ed4c5SJohn Baldwinif any of the original messages allocated by
864855ed4c5SJohn Baldwin.Fn pci_alloc_msix
865855ed4c5SJohn Baldwinare not used in the new distribution of messages in the MSI-X table,
866855ed4c5SJohn Baldwinthey will be released automatically.
867855ed4c5SJohn BaldwinNote that if a driver wishes to use fewer messages than were allocated by
868855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
869855ed4c5SJohn Baldwinthe driver must use a single, contiguous range of messages beginning
870855ed4c5SJohn Baldwinwith one in the new distribution.
871855ed4c5SJohn BaldwinThe
872855ed4c5SJohn Baldwin.Fn pci_remap_msix
873855ed4c5SJohn Baldwinfunction will fail if this condition is not met.
874aac0aafaSHiten Pandya.Sh IMPLEMENTATION NOTES
875aac0aafaSHiten PandyaThe
876aac0aafaSHiten Pandya.Vt pci_addr_t
87765bb31b8SRuslan Ermilovtype varies according to the size of the PCI bus address
878aac0aafaSHiten Pandyaspace on the target architecture.
879aac0aafaSHiten Pandya.Sh SEE ALSO
8807c2c06f2SSheldon Hearn.Xr pci 4 ,
8817c2c06f2SSheldon Hearn.Xr pciconf 8 ,
882aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 ,
883aac0aafaSHiten Pandya.Xr bus_dma 9 ,
884aac0aafaSHiten Pandya.Xr bus_release_resource 9 ,
885aac0aafaSHiten Pandya.Xr bus_setup_intr 9 ,
886aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 ,
887aac0aafaSHiten Pandya.Xr devclass 9 ,
888aac0aafaSHiten Pandya.Xr device 9 ,
889aac0aafaSHiten Pandya.Xr driver 9 ,
890aac0aafaSHiten Pandya.Xr rman 9
891aac0aafaSHiten Pandya.Rs
892aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook
893aac0aafaSHiten Pandya.%T NewBus
894aa4a335bSRuslan Ermilov.%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
895aac0aafaSHiten Pandya.Re
896aac0aafaSHiten Pandya.Rs
897aac0aafaSHiten Pandya.%A Shanley
898aac0aafaSHiten Pandya.%A Anderson
899aac0aafaSHiten Pandya.%B PCI System Architecture
900aac0aafaSHiten Pandya.%N 2nd Edition
901aac0aafaSHiten Pandya.%I Addison-Wesley
902aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2
903aac0aafaSHiten Pandya.Re
904aac0aafaSHiten Pandya.Sh AUTHORS
9058a7314fcSBaptiste Daroussin.An -nosplit
906571dba6eSHiten PandyaThis manual page was written by
9078a7314fcSBaptiste Daroussin.An Bruce M Simpson Aq Mt bms@FreeBSD.org
908855ed4c5SJohn Baldwinand
9098a7314fcSBaptiste Daroussin.An John Baldwin Aq Mt jhb@FreeBSD.org .
910aac0aafaSHiten Pandya.Sh BUGS
9114d80f750SBruce M SimpsonThe kernel PCI code has a number of references to
9124d80f750SBruce M Simpson.Dq "slot numbers" .
913bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices,
914bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL
915bf1639eeSBruce M Simpsonmechanism and the platform firmware.
916bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code.
917ce204e1bSJohn Baldwin.Pp
918ce204e1bSJohn BaldwinThe PCI bus driver should allocate the MSI-X vector table and PBA internally
919ce204e1bSJohn Baldwinas necessary rather than requiring the caller to do so.
920