xref: /freebsd/share/man/man9/pci.9 (revision 2ab0398d94b7907f03a2c762720df57bd57eaa2e)
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*2ab0398dSJohn Baldwin.Dd June 24, 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 ,
47*2ab0398dSJohn 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 ,
537d971e36SRyan Stone.Nm pci_iov_detach ,
54855ed4c5SJohn Baldwin.Nm pci_msi_count ,
55855ed4c5SJohn Baldwin.Nm pci_msix_count ,
56ce204e1bSJohn Baldwin.Nm pci_msix_pba_bar ,
57ce204e1bSJohn Baldwin.Nm pci_msix_table_bar ,
58855ed4c5SJohn Baldwin.Nm pci_pending_msix ,
590a9c80e5SJohn Baldwin.Nm pci_read_config ,
60855ed4c5SJohn Baldwin.Nm pci_release_msi ,
61855ed4c5SJohn Baldwin.Nm pci_remap_msix ,
620a9c80e5SJohn Baldwin.Nm pci_restore_state ,
630a9c80e5SJohn Baldwin.Nm pci_save_state ,
64855ed4c5SJohn Baldwin.Nm pci_set_max_read_req ,
650a9c80e5SJohn Baldwin.Nm pci_set_powerstate ,
66ec603c72SJohn Baldwin.Nm pci_write_config ,
67ec603c72SJohn Baldwin.Nm pcie_adjust_config ,
68ec603c72SJohn Baldwin.Nm pcie_read_config ,
69ec603c72SJohn Baldwin.Nm pcie_write_config
70aac0aafaSHiten Pandya.Nd PCI bus interface
71aac0aafaSHiten Pandya.Sh SYNOPSIS
72aac0aafaSHiten Pandya.In sys/bus.h
73aac0aafaSHiten Pandya.In dev/pci/pcireg.h
74855ed4c5SJohn Baldwin.In dev/pci/pcivar.h
75855ed4c5SJohn Baldwin.Ft int
76855ed4c5SJohn Baldwin.Fn pci_alloc_msi "device_t dev" "int *count"
77855ed4c5SJohn Baldwin.Ft int
78855ed4c5SJohn Baldwin.Fn pci_alloc_msix "device_t dev" "int *count"
79aac0aafaSHiten Pandya.Ft int
80aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev"
81aac0aafaSHiten Pandya.Ft int
82aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space"
83aac0aafaSHiten Pandya.Ft int
840a9c80e5SJohn Baldwin.Fn pci_enable_busmaster "device_t dev"
85aac0aafaSHiten Pandya.Ft int
860a9c80e5SJohn Baldwin.Fn pci_enable_io "device_t dev" "int space"
87aac0aafaSHiten Pandya.Ft device_t
8865bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
89855ed4c5SJohn Baldwin.Ft int
90855ed4c5SJohn Baldwin.Fn pci_find_cap "device_t dev" "int capability" "int *capreg"
91aac0aafaSHiten Pandya.Ft device_t
9255aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
9355aaf894SMarius Strobl.Ft device_t
9465bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device"
950a9c80e5SJohn Baldwin.Ft int
9668bf9717SJohn Baldwin.Fn pci_find_extcap "device_t dev" "int capability" "int *capreg"
9768bf9717SJohn Baldwin.Ft int
9868bf9717SJohn Baldwin.Fn pci_find_htcap "device_t dev" "int capability" "int *capreg"
9987dd2f95SJohn Baldwin.Ft device_t
10087dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port "device_t dev"
10168bf9717SJohn Baldwin.Ft int
102d7be980dSAndrew Turner.Fn pci_get_id "device_t dev" "enum pci_id_type type" "uintptr_t *id"
103d7be980dSAndrew Turner.Ft int
104*2ab0398dSJohn Baldwin.Fn pci_get_max_payload "device_t dev"
105*2ab0398dSJohn Baldwin.Ft int
106855ed4c5SJohn Baldwin.Fn pci_get_max_read_req "device_t dev"
107855ed4c5SJohn Baldwin.Ft int
1080a9c80e5SJohn Baldwin.Fn pci_get_powerstate "device_t dev"
109855ed4c5SJohn Baldwin.Ft int
110855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
111855ed4c5SJohn Baldwin.Ft int
112855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
113855ed4c5SJohn Baldwin.Ft int
114855ed4c5SJohn Baldwin.Fn pci_msi_count "device_t dev"
115855ed4c5SJohn Baldwin.Ft int
116855ed4c5SJohn Baldwin.Fn pci_msix_count "device_t dev"
117855ed4c5SJohn Baldwin.Ft int
118ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar "device_t dev"
119ce204e1bSJohn Baldwin.Ft int
120ce204e1bSJohn Baldwin.Fn pci_msix_table_bar "device_t dev"
121ce204e1bSJohn Baldwin.Ft int
122855ed4c5SJohn Baldwin.Fn pci_pending_msix "device_t dev" "u_int index"
1230a9c80e5SJohn Baldwin.Ft uint32_t
1240a9c80e5SJohn Baldwin.Fn pci_read_config "device_t dev" "int reg" "int width"
125855ed4c5SJohn Baldwin.Ft int
126855ed4c5SJohn Baldwin.Fn pci_release_msi "device_t dev"
127855ed4c5SJohn Baldwin.Ft int
128855ed4c5SJohn Baldwin.Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors"
1290a9c80e5SJohn Baldwin.Ft void
1300a9c80e5SJohn Baldwin.Fn pci_restore_state "device_t dev"
1310a9c80e5SJohn Baldwin.Ft void
1320a9c80e5SJohn Baldwin.Fn pci_save_state "device_t dev"
1330a9c80e5SJohn Baldwin.Ft int
134855ed4c5SJohn Baldwin.Fn pci_set_max_read_req "device_t dev" "int size"
135855ed4c5SJohn Baldwin.Ft int
1360a9c80e5SJohn Baldwin.Fn pci_set_powerstate "device_t dev" "int state"
1370a9c80e5SJohn Baldwin.Ft void
1380a9c80e5SJohn Baldwin.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
139ec603c72SJohn Baldwin.Ft uint32_t
140ec603c72SJohn Baldwin.Fo pcie_adjust_config
141ec603c72SJohn Baldwin.Fa "device_t dev"
142ec603c72SJohn Baldwin.Fa "int reg"
143ec603c72SJohn Baldwin.Fa "uint32_t mask"
144ec603c72SJohn Baldwin.Fa "uint32_t val"
145ec603c72SJohn Baldwin.Fa "int width"
146ec603c72SJohn Baldwin.Fc
147ec603c72SJohn Baldwin.Ft uint32_t
148ec603c72SJohn Baldwin.Fn pcie_read_config "device_t dev" "int reg" "int width"
149ec603c72SJohn Baldwin.Ft void
150ec603c72SJohn Baldwin.Fn pcie_write_config "device_t dev" "int reg" "uint32_t val" "int width"
151f3bb9251SJohn Baldwin.In dev/pci/pci_iov.h
152f3bb9251SJohn Baldwin.Ft int
153f3bb9251SJohn Baldwin.Fn pci_iov_attach "device_t dev" "nvlist_t *pf_schema" "nvlist_t *vf_schema"
154f3bb9251SJohn Baldwin.Ft int
155f3bb9251SJohn Baldwin.Fn pci_iov_detach "device_t dev"
156aac0aafaSHiten Pandya.Sh DESCRIPTION
157aac0aafaSHiten PandyaThe
158aac0aafaSHiten Pandya.Nm
159aac0aafaSHiten Pandyaset of functions are used for managing PCI devices.
160855ed4c5SJohn BaldwinThe functions are split into several groups:
161855ed4c5SJohn Baldwinraw configuration access,
162855ed4c5SJohn Baldwinlocating devices,
163855ed4c5SJohn Baldwindevice information,
164855ed4c5SJohn Baldwindevice configuration,
165855ed4c5SJohn Baldwinand
166855ed4c5SJohn Baldwinmessage signaled interrupts.
167855ed4c5SJohn Baldwin.Ss Raw Configuration Access
168aac0aafaSHiten PandyaThe
169aac0aafaSHiten Pandya.Fn pci_read_config
170aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration
171aac0aafaSHiten Pandyaspace of the device
172aac0aafaSHiten Pandya.Fa dev ,
173aac0aafaSHiten Pandyaat offset
174aac0aafaSHiten Pandya.Fa reg ,
175aac0aafaSHiten Pandyawith
176aac0aafaSHiten Pandya.Fa width
177aac0aafaSHiten Pandyaspecifying the size of the access.
178aac0aafaSHiten Pandya.Pp
179aac0aafaSHiten PandyaThe
180aac0aafaSHiten Pandya.Fn pci_write_config
181aac0aafaSHiten Pandyafunction is used to write the value
182aac0aafaSHiten Pandya.Fa val
183aac0aafaSHiten Pandyato 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
192ec603c72SJohn BaldwinThe
193ec603c72SJohn Baldwin.Fn pcie_adjust_config
194ec603c72SJohn Baldwinfunction is used to modify the value of a register in the PCI-express
195ec603c72SJohn Baldwincapability register set of device
196ec603c72SJohn Baldwin.Fa dev .
197ec603c72SJohn BaldwinThe offset
198ec603c72SJohn Baldwin.Fa reg
199ec603c72SJohn Baldwinspecifies a relative offset in the register set with
200ec603c72SJohn Baldwin.Fa width
201ec603c72SJohn Baldwinspecifying the size of the access.
202ec603c72SJohn BaldwinThe new value of the register is computed by modifying bits set in
203ec603c72SJohn Baldwin.Fa mask
204ec603c72SJohn Baldwinto the value in
205ec603c72SJohn Baldwin.Fa val .
206ec603c72SJohn BaldwinAny bits not specified in
207ec603c72SJohn Baldwin.Fa mask
208ec603c72SJohn Baldwinare preserved.
209ec603c72SJohn BaldwinThe previous value of the register is returned.
210ec603c72SJohn Baldwin.Pp
211ec603c72SJohn BaldwinThe
212ec603c72SJohn Baldwin.Fn pcie_read_config
213ec603c72SJohn Baldwinfunction is used to read the value of a register in the PCI-express
214ec603c72SJohn Baldwincapability register set of device
215ec603c72SJohn Baldwin.Fa dev .
216ec603c72SJohn BaldwinThe offset
217ec603c72SJohn Baldwin.Fa reg
218ec603c72SJohn Baldwinspecifies a relative offset in the register set with
219ec603c72SJohn Baldwin.Fa width
220ec603c72SJohn Baldwinspecifying the size of the access.
221ec603c72SJohn Baldwin.Pp
222ec603c72SJohn BaldwinThe
223ec603c72SJohn Baldwin.Fn pcie_write_config
224ec603c72SJohn Baldwinfunction is used to write the value
225ec603c72SJohn Baldwin.Fa val
226ec603c72SJohn Baldwinto a register in the PCI-express capability register set of device
227ec603c72SJohn Baldwin.Fa dev .
228ec603c72SJohn BaldwinThe offset
229ec603c72SJohn Baldwin.Fa reg
230ec603c72SJohn Baldwinspecifies a relative offset in the register set with
231ec603c72SJohn Baldwin.Fa width
232ec603c72SJohn Baldwinspecifying the size of the access.
233ec603c72SJohn Baldwin.Pp
234855ed4c5SJohn Baldwin.Em NOTE :
235855ed4c5SJohn BaldwinDevice drivers should only use these functions for functionality that
236855ed4c5SJohn Baldwinis not available via another
237855ed4c5SJohn Baldwin.Fn pci
238855ed4c5SJohn Baldwinfunction.
239855ed4c5SJohn Baldwin.Ss Locating Devices
240855ed4c5SJohn BaldwinThe
241855ed4c5SJohn Baldwin.Fn pci_find_bsf
242855ed4c5SJohn Baldwinfunction looks up the
243855ed4c5SJohn Baldwin.Vt device_t
244855ed4c5SJohn Baldwinof a PCI device, given its
245855ed4c5SJohn Baldwin.Fa bus ,
246855ed4c5SJohn Baldwin.Fa slot ,
247855ed4c5SJohn Baldwinand
248855ed4c5SJohn Baldwin.Fa func .
249855ed4c5SJohn BaldwinThe
250855ed4c5SJohn Baldwin.Fa slot
251855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
252855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
253855ed4c5SJohn Baldwinin terms of a physical slot.
254855ed4c5SJohn BaldwinNote that in case the system has multiple PCI domains,
255855ed4c5SJohn Baldwinthe
256855ed4c5SJohn Baldwin.Fn pci_find_bsf
257855ed4c5SJohn Baldwinfunction only searches the first one.
258855ed4c5SJohn BaldwinActually, it is equivalent to:
259855ed4c5SJohn Baldwin.Bd -literal -offset indent
260855ed4c5SJohn Baldwinpci_find_dbsf(0, bus, slot, func);
261855ed4c5SJohn Baldwin.Ed
262855ed4c5SJohn Baldwin.Pp
263855ed4c5SJohn BaldwinThe
264855ed4c5SJohn Baldwin.Fn pci_find_dbsf
265855ed4c5SJohn Baldwinfunction looks up the
266855ed4c5SJohn Baldwin.Vt device_t
267855ed4c5SJohn Baldwinof a PCI device, given its
268855ed4c5SJohn Baldwin.Fa domain ,
269855ed4c5SJohn Baldwin.Fa bus ,
270855ed4c5SJohn Baldwin.Fa slot ,
271855ed4c5SJohn Baldwinand
272855ed4c5SJohn Baldwin.Fa func .
273855ed4c5SJohn BaldwinThe
274855ed4c5SJohn Baldwin.Fa slot
275855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus,
276855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location
277855ed4c5SJohn Baldwinin terms of a physical slot.
278855ed4c5SJohn Baldwin.Pp
279855ed4c5SJohn BaldwinThe
280855ed4c5SJohn Baldwin.Fn pci_find_device
281855ed4c5SJohn Baldwinfunction looks up the
282855ed4c5SJohn Baldwin.Vt device_t
283855ed4c5SJohn Baldwinof a PCI device, given its
284855ed4c5SJohn Baldwin.Fa vendor
285855ed4c5SJohn Baldwinand
286855ed4c5SJohn Baldwin.Fa device
287855ed4c5SJohn BaldwinIDs.
288855ed4c5SJohn BaldwinNote that there can be multiple matches for this search; this function
289855ed4c5SJohn Baldwinonly returns the first matching device.
290855ed4c5SJohn Baldwin.Ss Device Information
291855ed4c5SJohn BaldwinThe
292855ed4c5SJohn Baldwin.Fn pci_find_cap
293855ed4c5SJohn Baldwinfunction is used to locate the first instance of a PCI capability
294855ed4c5SJohn Baldwinregister set for the device
295855ed4c5SJohn Baldwin.Fa dev .
296855ed4c5SJohn BaldwinThe capability to locate is specified by ID via
297855ed4c5SJohn Baldwin.Fa capability .
298855ed4c5SJohn BaldwinConstant macros of the form
299855ed4c5SJohn Baldwin.Dv PCIY_xxx
300855ed4c5SJohn Baldwinfor standard capability IDs are defined in
301855ed4c5SJohn Baldwin.In dev/pci/pcireg.h .
302855ed4c5SJohn BaldwinIf the capability is found, then
303855ed4c5SJohn Baldwin.Fa *capreg
304281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
305855ed4c5SJohn Baldwinand
306855ed4c5SJohn Baldwin.Fn pci_find_cap
307855ed4c5SJohn Baldwinreturns zero.
308855ed4c5SJohn BaldwinIf the capability is not found or the device does not support capabilities,
309855ed4c5SJohn Baldwin.Fn pci_find_cap
310855ed4c5SJohn Baldwinreturns an error.
311855ed4c5SJohn Baldwin.Pp
312855ed4c5SJohn BaldwinThe
31368bf9717SJohn Baldwin.Fn pci_find_extcap
31468bf9717SJohn Baldwinfunction is used to locate the first instance of a PCI-express
31568bf9717SJohn Baldwinextended capability register set for the device
31668bf9717SJohn Baldwin.Fa dev .
31768bf9717SJohn BaldwinThe extended capability to locate is specified by ID via
31868bf9717SJohn Baldwin.Fa capability .
31968bf9717SJohn BaldwinConstant macros of the form
32068bf9717SJohn Baldwin.Dv PCIZ_xxx
32168bf9717SJohn Baldwinfor standard extended capability IDs are defined in
32268bf9717SJohn Baldwin.In dev/pci/pcireg.h .
32368bf9717SJohn BaldwinIf the extended capability is found, then
32468bf9717SJohn Baldwin.Fa *capreg
325281a359eSJohn Baldwinis set to the offset in configuration space of the extended capability
32668bf9717SJohn Baldwinregister set, and
32768bf9717SJohn Baldwin.Fn pci_find_extcap
32868bf9717SJohn Baldwinreturns zero.
32968bf9717SJohn BaldwinIf the extended capability is not found or the device is not a
33068bf9717SJohn BaldwinPCI-express device,
33168bf9717SJohn Baldwin.Fn pci_find_extcap
33268bf9717SJohn Baldwinreturns an error.
33368bf9717SJohn Baldwin.Pp
33468bf9717SJohn BaldwinThe
33568bf9717SJohn Baldwin.Fn pci_find_htcap
33668bf9717SJohn Baldwinfunction is used to locate the first instance of a HyperTransport capability
33768bf9717SJohn Baldwinregister set for the device
33868bf9717SJohn Baldwin.Fa dev .
33968bf9717SJohn BaldwinThe capability to locate is specified by type via
34068bf9717SJohn Baldwin.Fa capability .
34168bf9717SJohn BaldwinConstant macros of the form
34268bf9717SJohn Baldwin.Dv PCIM_HTCAP_xxx
34368bf9717SJohn Baldwinfor standard HyperTransport capability types are defined in
34468bf9717SJohn Baldwin.In dev/pci/pcireg.h .
34568bf9717SJohn BaldwinIf the capability is found, then
34668bf9717SJohn Baldwin.Fa *capreg
347281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set,
34868bf9717SJohn Baldwinand
34968bf9717SJohn Baldwin.Fn pci_find_htcap
35068bf9717SJohn Baldwinreturns zero.
35168bf9717SJohn BaldwinIf the capability is not found or the device is not a HyperTransport device,
35268bf9717SJohn Baldwin.Fn pci_find_htcap
35368bf9717SJohn Baldwinreturns an error.
35468bf9717SJohn Baldwin.Pp
35568bf9717SJohn BaldwinThe
35687dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
35787dd2f95SJohn Baldwinfunction walks up the PCI device hierarchy to locate the PCI-express root
35887dd2f95SJohn Baldwinport upstream of
35987dd2f95SJohn Baldwin.Fa dev .
36087dd2f95SJohn BaldwinIf a root port is not found,
36187dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port
36287dd2f95SJohn Baldwinreturns
36387dd2f95SJohn Baldwin.Dv NULL .
36487dd2f95SJohn Baldwin.Pp
36587dd2f95SJohn BaldwinThe
366d7be980dSAndrew Turner.Fn pci_get_id
367d7be980dSAndrew Turnerfunction is used to read an identifier from a device.
368d7be980dSAndrew TurnerThe
369d7be980dSAndrew Turner.Fa type
370d7be980dSAndrew Turnerflag is used to specify which identifier to read.
371d7be980dSAndrew TurnerThe following flags are supported:
372d7be980dSAndrew Turner.Bl -hang -width ".Dv PCI_ID_RID"
373d7be980dSAndrew Turner.It Dv PCI_ID_RID
374d7be980dSAndrew TurnerRead the routing identifier for the device.
3751e43b18cSAndrew Turner.It Dv PCI_ID_MSI
3761e43b18cSAndrew TurnerRead the MSI routing ID.
3771e43b18cSAndrew TurnerThis is needed by some interrupt controllers to route MSI and MSI-X interrupts.
378d7be980dSAndrew Turner.El
379d7be980dSAndrew Turner.Pp
380d7be980dSAndrew TurnerThe
381855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
382855ed4c5SJohn Baldwinfunction is used to fetch a device's Vital Product Data
383855ed4c5SJohn Baldwin.Pq VPD
384855ed4c5SJohn Baldwinidentifier string.
385855ed4c5SJohn BaldwinIf the device
386855ed4c5SJohn Baldwin.Fa dev
387855ed4c5SJohn Baldwinsupports VPD and provides an identifier string,
388855ed4c5SJohn Baldwinthen
389855ed4c5SJohn Baldwin.Fa *identptr
390855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the identifier
391855ed4c5SJohn Baldwinstring,
392855ed4c5SJohn Baldwinand
393855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
394855ed4c5SJohn Baldwinreturns zero.
395855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide an identifier
396855ed4c5SJohn Baldwinstring,
397855ed4c5SJohn Baldwinthen
398855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident
399855ed4c5SJohn Baldwinreturns an error.
400855ed4c5SJohn Baldwin.Pp
401855ed4c5SJohn BaldwinThe
402855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
403855ed4c5SJohn Baldwinfunction is used to fetch the value of a single VPD read-only keyword
404855ed4c5SJohn Baldwinfor the device
405855ed4c5SJohn Baldwin.Fa dev .
406855ed4c5SJohn BaldwinThe keyword to fetch is identified by the two character string
407855ed4c5SJohn Baldwin.Fa kw .
408855ed4c5SJohn BaldwinIf the device supports VPD and provides a read-only value for the
409855ed4c5SJohn Baldwinrequested keyword,
410855ed4c5SJohn Baldwinthen
411855ed4c5SJohn Baldwin.Fa *vptr
412855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the value,
413855ed4c5SJohn Baldwinand
414855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
415855ed4c5SJohn Baldwinreturns zero.
416855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide the requested
417855ed4c5SJohn Baldwinkeyword,
418855ed4c5SJohn Baldwinthen
419855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly
420855ed4c5SJohn Baldwinreturns an error.
421855ed4c5SJohn Baldwin.Ss Device Configuration
422aac0aafaSHiten PandyaThe
423aac0aafaSHiten Pandya.Fn pci_enable_busmaster
424aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device
425aac0aafaSHiten Pandya.Fa dev ,
426aac0aafaSHiten Pandyaby setting the
427aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN
428aac0aafaSHiten Pandyabit in the
429aac0aafaSHiten Pandya.Dv PCIR_COMMAND
430aac0aafaSHiten Pandyaregister.
431aac0aafaSHiten PandyaThe
432aac0aafaSHiten Pandya.Fn pci_disable_busmaster
433aac0aafaSHiten Pandyafunction clears this bit.
434aac0aafaSHiten Pandya.Pp
435aac0aafaSHiten PandyaThe
436aac0aafaSHiten Pandya.Fn pci_enable_io
437aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device
438aac0aafaSHiten Pandya.Fa dev ,
439aac0aafaSHiten Pandyaby setting the
440aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN
441aac0aafaSHiten Pandyaor
442aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN
443aac0aafaSHiten Pandyabit in the
444aac0aafaSHiten Pandya.Dv PCIR_COMMAND
4455203edcdSRuslan Ermilovregister appropriately.
4465203edcdSRuslan ErmilovThe
447aac0aafaSHiten Pandya.Fn pci_disable_io
448aac0aafaSHiten Pandyafunction clears the appropriate bit.
449aac0aafaSHiten PandyaThe
45065bb31b8SRuslan Ermilov.Fa space
451aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either
452aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY
453aac0aafaSHiten Pandyaor
454aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT
455aac0aafaSHiten Pandyaas appropriate.
456855ed4c5SJohn BaldwinDevice drivers should generally not use these routines directly.
457855ed4c5SJohn BaldwinThe PCI bus will enable decoding automatically when a
458855ed4c5SJohn Baldwin.Dv SYS_RES_MEMORY
459855ed4c5SJohn Baldwinor
460855ed4c5SJohn Baldwin.Dv SYS_RES_IOPORT
461855ed4c5SJohn Baldwinresource is activated via
462855ed4c5SJohn Baldwin.Xr bus_alloc_resource 9
463855ed4c5SJohn Baldwinor
464855ed4c5SJohn Baldwin.Xr bus_activate_resource 9 .
465aac0aafaSHiten Pandya.Pp
466855ed4c5SJohn BaldwinThe
467*2ab0398dSJohn Baldwin.Fn pci_get_max_payload
468*2ab0398dSJohn Baldwinfunction returns the current maximum TLP payload size in bytes for a
469*2ab0398dSJohn BaldwinPCI-express device.
470*2ab0398dSJohn BaldwinIf the
471*2ab0398dSJohn Baldwin.Fa dev
472*2ab0398dSJohn Baldwindevice is not a PCI-express device,
473*2ab0398dSJohn Baldwin.Fn pci_get_max_payload
474*2ab0398dSJohn Baldwinreturns zero.
475*2ab0398dSJohn Baldwin.Pp
476*2ab0398dSJohn BaldwinThe
477855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
478855ed4c5SJohn Baldwinfunction returns the current maximum read request size in bytes for a
479855ed4c5SJohn BaldwinPCI-express device.
480855ed4c5SJohn BaldwinIf the
481855ed4c5SJohn Baldwin.Fa dev
482855ed4c5SJohn Baldwindevice is not a PCI-express device,
483855ed4c5SJohn Baldwin.Fn pci_get_max_read_req
484855ed4c5SJohn Baldwinreturns zero.
485855ed4c5SJohn Baldwin.Pp
486855ed4c5SJohn BaldwinThe
487855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
488855ed4c5SJohn Baldwinsets the PCI-express maximum read request size for
489855ed4c5SJohn Baldwin.Fa dev .
490855ed4c5SJohn BaldwinThe requested
491855ed4c5SJohn Baldwin.Fa size
492855ed4c5SJohn Baldwinmay be adjusted,
493855ed4c5SJohn Baldwinand
494855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
495855ed4c5SJohn Baldwinreturns the actual size set in bytes.
496855ed4c5SJohn BaldwinIf the
497855ed4c5SJohn Baldwin.Fa dev
498855ed4c5SJohn Baldwindevice is not a PCI-express device,
499855ed4c5SJohn Baldwin.Fn pci_set_max_read_req
500855ed4c5SJohn Baldwinreturns zero.
501aac0aafaSHiten Pandya.Pp
502aac0aafaSHiten PandyaThe
503aac0aafaSHiten Pandya.Fn pci_get_powerstate
504adb63907SJohn Baldwinfunction returns the current power state of the device
505aac0aafaSHiten Pandya.Fa dev .
506aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default
507aac0aafaSHiten Pandyastate of
508aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0
509aac0aafaSHiten Pandyais returned.
510adb63907SJohn BaldwinThe following power states are defined by PCI:
51165bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
512aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0
513aac0aafaSHiten PandyaState in which device is on and running.
514aac0aafaSHiten PandyaIt is receiving full power from the system and delivering
515aac0aafaSHiten Pandyafull functionality to the user.
516aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1
517aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
5185a2e3b61SDaniel Gerzomay not be lost.
51965bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to
5209817b894SBruce M Simpsonforce devices to lose context.
521aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2
522aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
523aac0aafaSHiten Pandyamay not be lost.
524aac0aafaSHiten PandyaAttains greater power savings than
525aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 .
52665bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context.
527aac0aafaSHiten PandyaDevices
528aac0aafaSHiten Pandya.Em must
529aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher.
530aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3
531aac0aafaSHiten PandyaState in which the device is off and not running.
532aac0aafaSHiten PandyaDevice context is lost, and power from the device can
533aac0aafaSHiten Pandyabe removed.
534aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN
535aac0aafaSHiten PandyaState of the device is unknown.
536aac0aafaSHiten Pandya.El
537aac0aafaSHiten Pandya.Pp
538aac0aafaSHiten PandyaThe
539aac0aafaSHiten Pandya.Fn pci_set_powerstate
540aac0aafaSHiten Pandyafunction is used to transition the device
541aac0aafaSHiten Pandya.Fa dev
542adb63907SJohn Baldwinto the PCI power state
543aac0aafaSHiten Pandya.Fa state .
544adb63907SJohn BaldwinIf the device does not support power management capabilities or
545adb63907SJohn Baldwinit does not support the specific power state
546adb63907SJohn Baldwin.Fa state ,
547adb63907SJohn Baldwinthen the function will fail with
548adb63907SJohn Baldwin.Er EOPNOTSUPP .
549aac0aafaSHiten Pandya.Pp
550aac0aafaSHiten PandyaThe
5517d971e36SRyan Stone.Fn pci_iov_attach
5527d971e36SRyan Stonefunction is used to advertise that the given device
5537d971e36SRyan Stone.Pq and associated device driver
5547d971e36SRyan Stonesupports PCI Single-Root I/O Virtualization
555fe3ff217SPatrick Kelsey.Pq SR-IOV .
5567d971e36SRyan StoneA driver that supports SR-IOV must implement the
557f3bb9251SJohn Baldwin.Xr PCI_IOV_INIT 9 ,
558f3bb9251SJohn Baldwin.Xr PCI_IOV_ADD_VF 9
5597d971e36SRyan Stoneand
560f3bb9251SJohn Baldwin.Xr PCI_IOV_UNINIT 9
5617d971e36SRyan Stonemethods.
5627d971e36SRyan StoneThis function should be called during the
5637d971e36SRyan Stone.Xr DEVICE_ATTACH 9
5647d971e36SRyan Stonemethod.
5657d971e36SRyan StoneIf this function returns an error, it is recommended that the device driver
5667d971e36SRyan Stonestill successfully attaches, but runs with SR-IOV disabled.
5677d971e36SRyan StoneThe
5687d971e36SRyan Stone.Fa pf_schema
5697d971e36SRyan Stoneand
5707d971e36SRyan Stone.Fa vf_schema
5717d971e36SRyan Stoneparameters are used to define what device-specific configuration parameters the
5727d971e36SRyan Stonedevice driver accepts when SR-IOV is enabled for the Physical Function
5737d971e36SRyan Stone.Pq PF
5747d971e36SRyan Stoneand for individual Virtual Functions
5757d971e36SRyan Stone.Pq VFs
5767d971e36SRyan Stonerespectively.
5777d971e36SRyan StoneSee
5787d971e36SRyan Stone.Xr pci_iov_schema 9
5797d971e36SRyan Stonefor details on how to construct the schema.
5807d971e36SRyan StoneIf either the
5817d971e36SRyan Stone.Pa pf_schema
5827d971e36SRyan Stoneor
5837d971e36SRyan Stone.Pa vf_schema
5847d971e36SRyan Stoneis invalid or specifies parameter names that conflict with parameter names that
5857d971e36SRyan Stoneare already in use,
5867d971e36SRyan Stone.Fn pci_iov_attach
5877d971e36SRyan Stonewill return an error and SR-IOV will not be available on the PF device.
5887d971e36SRyan StoneIf a driver does not accept configuration parameters for either the PF device
5897d971e36SRyan Stoneor the VF devices, the driver must pass an empty schema for that device.
5907d971e36SRyan StoneThe SR-IOV infrastructure takes ownership of the
5917d971e36SRyan Stone.Fa pf_schema
5927d971e36SRyan Stoneand
5937d971e36SRyan Stone.Fa vf_schema
5947d971e36SRyan Stoneand is responsible for freeing them.
5957d971e36SRyan StoneThe driver must never free the schemas itself.
5967d971e36SRyan Stone.Pp
5977d971e36SRyan StoneThe
5987d971e36SRyan Stone.Fn pci_iov_detach
5997d971e36SRyan Stonefunction is used to advise the SR-IOV infrastructure that the driver for the
6007d971e36SRyan Stonegiven device is attempting to detach and that all SR-IOV resources for the
6017d971e36SRyan Stonedevice must be released.
6027d971e36SRyan StoneThis function must be called during the
6037d971e36SRyan Stone.Xr DEVICE_DETACH 9
6047d971e36SRyan Stonemethod if
6057d971e36SRyan Stone.Fn pci_iov_attach
6067d971e36SRyan Stonewas successfully called on the device and
6077d971e36SRyan Stone.Fn pci_iov_detach
6087d971e36SRyan Stonehas not subsequently been called on the device and returned no error.
6097d971e36SRyan StoneIf this function returns an error, the
6107d971e36SRyan Stone.Xr DEVICE_DETACH 9
6117d971e36SRyan Stonemethod must fail and return an error, as detaching the PF driver while VF
6127d971e36SRyan Stonedevices are active would cause system instability.
6137d971e36SRyan StoneThis function is safe to call and will always succeed if
6147d971e36SRyan Stone.Fn pci_iov_attach
6157d971e36SRyan Stonepreviously failed with an error on the given device, or if
6167d971e36SRyan Stone.Fn pci_iov_attach
6177d971e36SRyan Stonewas never called on the device.
6187d971e36SRyan Stone.Pp
6197d971e36SRyan StoneThe
6209415d1e0SJohn Baldwin.Fn pci_save_state
6219415d1e0SJohn Baldwinand
6229415d1e0SJohn Baldwin.Fn pci_restore_state
6239415d1e0SJohn Baldwinfunctions can be used by a device driver to save and restore standard PCI
6249415d1e0SJohn Baldwinconfig registers.
6259415d1e0SJohn BaldwinThe
6269415d1e0SJohn Baldwin.Fn pci_save_state
6279415d1e0SJohn Baldwinfunction must be invoked while the device has valid state before
6289415d1e0SJohn Baldwin.Fn pci_restore_state
6299415d1e0SJohn Baldwincan be used.
6309415d1e0SJohn BaldwinIf the device is not in the fully-powered state
6319415d1e0SJohn Baldwin.Pq Dv PCI_POWERSTATE_D0
6329415d1e0SJohn Baldwinwhen
6339415d1e0SJohn Baldwin.Fn pci_restore_state
6349415d1e0SJohn Baldwinis invoked,
6359415d1e0SJohn Baldwinthen the device will be transitioned to
6369415d1e0SJohn Baldwin.Dv PCI_POWERSTATE_D0
6379415d1e0SJohn Baldwinbefore any config registers are restored.
638855ed4c5SJohn Baldwin.Ss Message Signaled Interrupts
639855ed4c5SJohn BaldwinMessage Signaled Interrupts
640855ed4c5SJohn Baldwin.Pq MSI
641855ed4c5SJohn Baldwinand
642855ed4c5SJohn BaldwinEnhanced Message Signaled Interrupts
643855ed4c5SJohn Baldwin.Pq MSI-X
644855ed4c5SJohn Baldwinare PCI capabilities that provide an alternate method for PCI
645855ed4c5SJohn Baldwindevices to signal interrupts.
646855ed4c5SJohn BaldwinThe legacy INTx interrupt is available to PCI devices as a
647855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
648855ed4c5SJohn Baldwinresource with a resource ID of zero.
649855ed4c5SJohn BaldwinMSI and MSI-X interrupts are available to PCI devices as one or more
650855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
651855ed4c5SJohn Baldwinresources with resource IDs greater than zero.
652855ed4c5SJohn BaldwinA driver must ask the PCI bus to allocate MSI or MSI-X interrupts
653855ed4c5SJohn Baldwinusing
654855ed4c5SJohn Baldwin.Fn pci_alloc_msi
655855ed4c5SJohn Baldwinor
656855ed4c5SJohn Baldwin.Fn pci_alloc_msix
657855ed4c5SJohn Baldwinbefore it can use MSI or MSI-X
658855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
659855ed4c5SJohn Baldwinresources.
660855ed4c5SJohn BaldwinA driver is not allowed to use the legacy INTx
661855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
662855ed4c5SJohn Baldwinresource if MSI or MSI-X interrupts have been allocated,
663855ed4c5SJohn Baldwinand attempts to allocate MSI or MSI-X interrupts will fail if the
664855ed4c5SJohn Baldwindriver is currently using the legacy INTx
665855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
666855ed4c5SJohn Baldwinresource.
667855ed4c5SJohn BaldwinA driver is only allowed to use either MSI or MSI-X,
668855ed4c5SJohn Baldwinbut not both.
6699415d1e0SJohn Baldwin.Pp
6709415d1e0SJohn BaldwinThe
671563d4639SMark Johnston.Fn pci_msi_count
672855ed4c5SJohn Baldwinfunction returns the maximum number of MSI messages supported by the
673855ed4c5SJohn Baldwindevice
674855ed4c5SJohn Baldwin.Fa dev .
675855ed4c5SJohn BaldwinIf the device does not support MSI,
676855ed4c5SJohn Baldwinthen
677563d4639SMark Johnston.Fn pci_msi_count
678855ed4c5SJohn Baldwinreturns zero.
67955aaf894SMarius Strobl.Pp
68055aaf894SMarius StroblThe
681855ed4c5SJohn Baldwin.Fn pci_alloc_msi
682855ed4c5SJohn Baldwinfunction attempts to allocate
683855ed4c5SJohn Baldwin.Fa *count
684855ed4c5SJohn BaldwinMSI messages for the device
685855ed4c5SJohn Baldwin.Fa dev .
68655aaf894SMarius StroblThe
687855ed4c5SJohn Baldwin.Fn pci_alloc_msi
688855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
689855ed4c5SJohn Baldwinreasons including requests for more messages than the device
690855ed4c5SJohn Baldwin.Fa dev
691855ed4c5SJohn Baldwinsupports,
692855ed4c5SJohn Baldwinor if the system has a shortage of available MSI messages.
693855ed4c5SJohn BaldwinOn success,
694855ed4c5SJohn Baldwin.Fa *count
695855ed4c5SJohn Baldwinis set to the number of messages allocated and
696855ed4c5SJohn Baldwin.Fn pci_alloc_msi
697855ed4c5SJohn Baldwinreturns zero.
698855ed4c5SJohn BaldwinThe
699855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
700855ed4c5SJohn Baldwinresources for the allocated messages will be available at consecutive
701855ed4c5SJohn Baldwinresource IDs beginning with one.
702855ed4c5SJohn BaldwinIf
703855ed4c5SJohn Baldwin.Fn pci_alloc_msi
704855ed4c5SJohn Baldwinis not able to allocate any messages,
705855ed4c5SJohn Baldwinit returns an error.
706855ed4c5SJohn BaldwinNote that MSI only supports message counts that are powers of two;
707855ed4c5SJohn Baldwinrequests to allocate a non-power of two count of messages will fail.
708aac0aafaSHiten Pandya.Pp
709aac0aafaSHiten PandyaThe
710855ed4c5SJohn Baldwin.Fn pci_release_msi
711855ed4c5SJohn Baldwinfunction is used to release any allocated MSI or MSI-X messages back
712855ed4c5SJohn Baldwinto the system.
713855ed4c5SJohn BaldwinIf any MSI or MSI-X
714855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
715855ed4c5SJohn Baldwinresources are allocated by the driver or have a configured interrupt
716855ed4c5SJohn Baldwinhandler,
717855ed4c5SJohn Baldwinthis function will fail with
718855ed4c5SJohn Baldwin.Er EBUSY .
719855ed4c5SJohn BaldwinThe
720855ed4c5SJohn Baldwin.Fn pci_release_msi
721855ed4c5SJohn Baldwinfunction returns zero on success and an error on failure.
722855ed4c5SJohn Baldwin.Pp
723642c4993SSergey KandaurovThe
724563d4639SMark Johnston.Fn pci_msix_count
725855ed4c5SJohn Baldwinfunction returns the maximum number of MSI-X messages supported by the
726855ed4c5SJohn Baldwindevice
727855ed4c5SJohn Baldwin.Fa dev .
728855ed4c5SJohn BaldwinIf the device does not support MSI-X,
729855ed4c5SJohn Baldwinthen
730563d4639SMark Johnston.Fn pci_msix_count
731855ed4c5SJohn Baldwinreturns zero.
732855ed4c5SJohn Baldwin.Pp
733855ed4c5SJohn BaldwinThe
734ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
735ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the Base Address Register
736ce204e1bSJohn Baldwin.Pq BAR
737ce204e1bSJohn Baldwincontaining the MSI-X Pending Bit Array (PBA) for device
738ce204e1bSJohn Baldwin.Fa dev .
739ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
740ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
741ce204e1bSJohn Baldwinand
742ce204e1bSJohn Baldwin.Xr bus_release_resource 9
743ce204e1bSJohn Baldwinto allocate the BAR.
744ce204e1bSJohn BaldwinIf the device does not support MSI-X,
745ce204e1bSJohn Baldwinthen
746ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar
747ce204e1bSJohn Baldwinreturns -1.
748ce204e1bSJohn Baldwin.Pp
749ce204e1bSJohn BaldwinThe
750ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
751ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the BAR
752ce204e1bSJohn Baldwincontaining the MSI-X vector table for device
753ce204e1bSJohn Baldwin.Fa dev .
754ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with
755ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
756ce204e1bSJohn Baldwinand
757ce204e1bSJohn Baldwin.Xr bus_release_resource 9
758ce204e1bSJohn Baldwinto allocate the BAR.
759ce204e1bSJohn BaldwinIf the device does not support MSI-X,
760ce204e1bSJohn Baldwinthen
761ce204e1bSJohn Baldwin.Fn pci_msix_table_bar
762ce204e1bSJohn Baldwinreturns -1.
763ce204e1bSJohn Baldwin.Pp
764ce204e1bSJohn BaldwinThe
765855ed4c5SJohn Baldwin.Fn pci_alloc_msix
766855ed4c5SJohn Baldwinfunction attempts to allocate
767855ed4c5SJohn Baldwin.Fa *count
768855ed4c5SJohn BaldwinMSI-X messages for the device
769855ed4c5SJohn Baldwin.Fa dev .
770855ed4c5SJohn BaldwinThe
771855ed4c5SJohn Baldwin.Fn pci_alloc_msix
772855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various
773855ed4c5SJohn Baldwinreasons including requests for more messages than the device
774855ed4c5SJohn Baldwin.Fa dev
775855ed4c5SJohn Baldwinsupports,
776855ed4c5SJohn Baldwinor if the system has a shortage of available MSI-X messages.
777855ed4c5SJohn BaldwinOn success,
778855ed4c5SJohn Baldwin.Fa *count
779855ed4c5SJohn Baldwinis set to the number of messages allocated and
780855ed4c5SJohn Baldwin.Fn pci_alloc_msix
781855ed4c5SJohn Baldwinreturns zero.
782855ed4c5SJohn BaldwinFor MSI-X messages,
783855ed4c5SJohn Baldwinthe resource ID for each
78473bbeaa5SGlen Barber.Dv SYS_RES_IRQ
78573bbeaa5SGlen Barberresource identifies the index in the MSI-X table of the
786855ed4c5SJohn Baldwincorresponding message.
787855ed4c5SJohn BaldwinA resource ID of one maps to the first index of the MSI-X table;
788855ed4c5SJohn Baldwina resource ID two identifies the second index in the table, etc.
789855ed4c5SJohn BaldwinThe
790855ed4c5SJohn Baldwin.Fn pci_alloc_msix
791855ed4c5SJohn Baldwinfunction assigns the
792855ed4c5SJohn Baldwin.Fa *count
793855ed4c5SJohn Baldwinmessages allocated to the first
794855ed4c5SJohn Baldwin.Fa *count
7957c64ddd5SWarren Blocktable indices.
796855ed4c5SJohn BaldwinIf
797855ed4c5SJohn Baldwin.Fn pci_alloc_msix
798855ed4c5SJohn Baldwinis not able to allocate any messages,
799855ed4c5SJohn Baldwinit returns an error.
800855ed4c5SJohn BaldwinUnlike MSI,
801855ed4c5SJohn BaldwinMSI-X does not require message counts that are powers of two.
802855ed4c5SJohn Baldwin.Pp
803ce204e1bSJohn BaldwinThe BARs containing the MSI-X vector table and PBA must be
804ce204e1bSJohn Baldwinallocated via
805ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9
806ce204e1bSJohn Baldwinbefore calling
807ce204e1bSJohn Baldwin.Fn pci_alloc_msix
808ce204e1bSJohn Baldwinand must not be released until after calling
809ce204e1bSJohn Baldwin.Fn pci_release_msi .
810ce204e1bSJohn BaldwinNote that the vector table and PBA may be stored in the same BAR or in
811ce204e1bSJohn Baldwindifferent BARs.
812ce204e1bSJohn Baldwin.Pp
813855ed4c5SJohn BaldwinThe
814855ed4c5SJohn Baldwin.Fn pci_pending_msix
815855ed4c5SJohn Baldwinfunction examines the
816855ed4c5SJohn Baldwin.Fa dev
817ce204e1bSJohn Baldwindevice's PBA
818855ed4c5SJohn Baldwinto determine the pending status of the MSI-X message at table index
819855ed4c5SJohn Baldwin.Fa index .
820855ed4c5SJohn BaldwinIf the indicated message is pending,
821855ed4c5SJohn Baldwinthis function returns a non-zero value;
822855ed4c5SJohn Baldwinotherwise,
823855ed4c5SJohn Baldwinit returns zero.
824855ed4c5SJohn BaldwinPassing an invalid
825855ed4c5SJohn Baldwin.Fa index
826855ed4c5SJohn Baldwinto this function will result in undefined behavior.
827855ed4c5SJohn Baldwin.Pp
828855ed4c5SJohn BaldwinAs mentioned in the description of
829855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
830855ed4c5SJohn BaldwinMSI-X messages are initially assigned to the first N table entries.
831855ed4c5SJohn BaldwinA driver may use a different distribution of available messages to
832855ed4c5SJohn Baldwintable entries via the
833855ed4c5SJohn Baldwin.Fn pci_remap_msix
834855ed4c5SJohn Baldwinfunction.
83573bbeaa5SGlen BarberNote that this function must be called after a successful call to
836855ed4c5SJohn Baldwin.Fn pci_alloc_msix
837855ed4c5SJohn Baldwinbut before any of the
838855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
839855ed4c5SJohn Baldwinresources are allocated.
840855ed4c5SJohn BaldwinThe
841855ed4c5SJohn Baldwin.Fn pci_remap_msix
842855ed4c5SJohn Baldwinfunction returns zero on success,
843855ed4c5SJohn Baldwinor an error on failure.
844855ed4c5SJohn Baldwin.Pp
845855ed4c5SJohn BaldwinThe
846855ed4c5SJohn Baldwin.Fa vectors
847855ed4c5SJohn Baldwinarray should contain
848855ed4c5SJohn Baldwin.Fa count
849855ed4c5SJohn Baldwinmessage vectors.
850855ed4c5SJohn BaldwinThe array maps directly to the MSI-X table in that the first entry in
851855ed4c5SJohn Baldwinthe array specifies the message used for the first entry in the MSI-X
852855ed4c5SJohn Baldwintable,
853855ed4c5SJohn Baldwinthe second entry in the array corresponds to the second entry in the
854855ed4c5SJohn BaldwinMSI-X table,
855855ed4c5SJohn Baldwinetc.
856855ed4c5SJohn BaldwinThe vector value in each array index can either be zero to indicate
857855ed4c5SJohn Baldwinthat no message should be assigned to the corresponding MSI-X table entry,
858855ed4c5SJohn Baldwinor it can be a number from one to N
859855ed4c5SJohn Baldwin.Po
860855ed4c5SJohn Baldwinwhere N is the count returned from the previous call to
861855ed4c5SJohn Baldwin.Fn pci_alloc_msix
862855ed4c5SJohn Baldwin.Pc
863855ed4c5SJohn Baldwinto indicate which of the allocated messages should be assigned to the
864855ed4c5SJohn Baldwincorresponding MSI-X table entry.
865855ed4c5SJohn Baldwin.Pp
866855ed4c5SJohn BaldwinIf
867855ed4c5SJohn Baldwin.Fn pci_remap_msix
868855ed4c5SJohn Baldwinsucceeds,
869855ed4c5SJohn Baldwineach MSI-X table entry with a non-zero vector will have an associated
870855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ
871855ed4c5SJohn Baldwinresource whose resource ID corresponds to the table index as described
872855ed4c5SJohn Baldwinabove for
873855ed4c5SJohn Baldwin.Fn pci_alloc_msix .
874855ed4c5SJohn BaldwinMSI-X table entries that with a vector of zero will not have an
875855ed4c5SJohn Baldwinassociated
87673bbeaa5SGlen Barber.Dv SYS_RES_IRQ
87773bbeaa5SGlen Barberresource.
878855ed4c5SJohn BaldwinAdditionally,
879855ed4c5SJohn Baldwinif any of the original messages allocated by
880855ed4c5SJohn Baldwin.Fn pci_alloc_msix
881855ed4c5SJohn Baldwinare not used in the new distribution of messages in the MSI-X table,
882855ed4c5SJohn Baldwinthey will be released automatically.
883855ed4c5SJohn BaldwinNote that if a driver wishes to use fewer messages than were allocated by
884855ed4c5SJohn Baldwin.Fn pci_alloc_msix ,
885855ed4c5SJohn Baldwinthe driver must use a single, contiguous range of messages beginning
886855ed4c5SJohn Baldwinwith one in the new distribution.
887855ed4c5SJohn BaldwinThe
888855ed4c5SJohn Baldwin.Fn pci_remap_msix
889855ed4c5SJohn Baldwinfunction will fail if this condition is not met.
890aac0aafaSHiten Pandya.Sh IMPLEMENTATION NOTES
891aac0aafaSHiten PandyaThe
892aac0aafaSHiten Pandya.Vt pci_addr_t
89365bb31b8SRuslan Ermilovtype varies according to the size of the PCI bus address
894aac0aafaSHiten Pandyaspace on the target architecture.
895aac0aafaSHiten Pandya.Sh SEE ALSO
8967c2c06f2SSheldon Hearn.Xr pci 4 ,
8977c2c06f2SSheldon Hearn.Xr pciconf 8 ,
898aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 ,
899aac0aafaSHiten Pandya.Xr bus_dma 9 ,
900aac0aafaSHiten Pandya.Xr bus_release_resource 9 ,
901aac0aafaSHiten Pandya.Xr bus_setup_intr 9 ,
902aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 ,
903aac0aafaSHiten Pandya.Xr devclass 9 ,
904aac0aafaSHiten Pandya.Xr device 9 ,
905aac0aafaSHiten Pandya.Xr driver 9 ,
906aac0aafaSHiten Pandya.Xr rman 9
907aac0aafaSHiten Pandya.Rs
908aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook
909aac0aafaSHiten Pandya.%T NewBus
910aa4a335bSRuslan Ermilov.%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
911aac0aafaSHiten Pandya.Re
912aac0aafaSHiten Pandya.Rs
913aac0aafaSHiten Pandya.%A Shanley
914aac0aafaSHiten Pandya.%A Anderson
915aac0aafaSHiten Pandya.%B PCI System Architecture
916aac0aafaSHiten Pandya.%N 2nd Edition
917aac0aafaSHiten Pandya.%I Addison-Wesley
918aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2
919aac0aafaSHiten Pandya.Re
920aac0aafaSHiten Pandya.Sh AUTHORS
9218a7314fcSBaptiste Daroussin.An -nosplit
922571dba6eSHiten PandyaThis manual page was written by
9238a7314fcSBaptiste Daroussin.An Bruce M Simpson Aq Mt bms@FreeBSD.org
924855ed4c5SJohn Baldwinand
9258a7314fcSBaptiste Daroussin.An John Baldwin Aq Mt jhb@FreeBSD.org .
926aac0aafaSHiten Pandya.Sh BUGS
9274d80f750SBruce M SimpsonThe kernel PCI code has a number of references to
9284d80f750SBruce M Simpson.Dq "slot numbers" .
929bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices,
930bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL
931bf1639eeSBruce M Simpsonmechanism and the platform firmware.
932bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code.
933ce204e1bSJohn Baldwin.Pp
934ce204e1bSJohn BaldwinThe PCI bus driver should allocate the MSI-X vector table and PBA internally
935ce204e1bSJohn Baldwinas necessary rather than requiring the caller to do so.
936