xref: /freebsd/share/man/man4/pci.4 (revision 9005607c8fa7317a759f1fc16cae4738f9a2fbb3)
1.\"
2.\" Copyright (c) 1999 Kenneth D. Merry.
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. The name of the author may not be used to endorse or promote products
11.\"    derived from this software without specific prior written permission.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd January 3, 2008
28.Dt PCI 4
29.Os
30.Sh NAME
31.Nm pci
32.Nd generic PCI driver
33.Sh SYNOPSIS
34.Cd device pci
35.Sh DESCRIPTION
36The
37.Nm
38driver provides a way for userland programs to read and write
39.Tn PCI
40configuration registers.
41It also provides a way for userland programs to get a list of all
42.Tn PCI
43devices, or all
44.Tn PCI
45devices that match various patterns.
46.Pp
47Since the
48.Nm
49driver provides a write interface for
50.Tn PCI
51configuration registers, system administrators should exercise caution when
52granting access to the
53.Nm
54device.
55If used improperly, this driver can allow userland applications to
56crash a machine or cause data loss.
57.Pp
58The
59.Nm
60driver implements the
61.Tn PCI
62bus in the kernel.
63It enumerates any devices on the
64.Tn PCI
65bus and gives
66.Tn PCI
67client drivers the chance to attach to them.
68It assigns resources to children, when the BIOS does not.
69It takes care of routing interrupts when necessary.
70It reprobes the unattached
71.Tn PCI
72children when
73.Tn PCI
74client drivers are dynamically
75loaded at runtime.
76.Sh KERNEL CONFIGURATION
77The
78.Nm
79device is included in the kernel as described in the SYNOPSIS section.
80The
81.Nm
82driver cannot be built as a
83.Xr kld 4 .
84.Sh IOCTLS
85The following
86.Xr ioctl 2
87calls are supported by the
88.Nm
89driver.
90They are defined in the header file
91.In sys/pciio.h .
92.Bl -tag -width 012345678901234
93.It PCIOCGETCONF
94This
95.Xr ioctl 2
96takes a
97.Va pci_conf_io
98structure.
99It allows the user to retrieve information on all
100.Tn PCI
101devices in the system, or on
102.Tn PCI
103devices matching patterns supplied by the user.
104The call may set
105.Va errno
106to any value specified in either
107.Xr copyin 9
108or
109.Xr copyout 9 .
110The
111.Va pci_conf_io
112structure consists of a number of fields:
113.Bl -tag -width match_buf_len
114.It pat_buf_len
115The length, in bytes, of the buffer filled with user-supplied patterns.
116.It num_patterns
117The number of user-supplied patterns.
118.It patterns
119Pointer to a buffer filled with user-supplied patterns.
120.Va patterns
121is a pointer to
122.Va num_patterns
123.Va pci_match_conf
124structures.
125The
126.Va pci_match_conf
127structure consists of the following elements:
128.Bl -tag -width pd_vendor
129.It pc_sel
130.Tn PCI
131domain, bus, slot and function.
132.It pd_name
133.Tn PCI
134device driver name.
135.It pd_unit
136.Tn PCI
137device driver unit number.
138.It pc_vendor
139.Tn PCI
140vendor ID.
141.It pc_device
142.Tn PCI
143device ID.
144.It pc_class
145.Tn PCI
146device class.
147.It flags
148The flags describe which of the fields the kernel should match against.
149A device must match all specified fields in order to be returned.
150The match flags are enumerated in the
151.Va pci_getconf_flags
152structure.
153Hopefully the flag values are obvious enough that they do not need to
154described in detail.
155.El
156.It match_buf_len
157Length of the
158.Va matches
159buffer allocated by the user to hold the results of the
160.Dv PCIOCGETCONF
161query.
162.It num_matches
163Number of matches returned by the kernel.
164.It matches
165Buffer containing matching devices returned by the kernel.
166The items in this buffer are of type
167.Va pci_conf ,
168which consists of the following items:
169.Bl -tag -width pc_subvendor
170.It pc_sel
171.Tn PCI
172domain, bus, slot and function.
173.It pc_hdr
174.Tn PCI
175header type.
176.It pc_subvendor
177.Tn PCI
178subvendor ID.
179.It pc_subdevice
180.Tn PCI
181subdevice ID.
182.It pc_vendor
183.Tn PCI
184vendor ID.
185.It pc_device
186.Tn PCI
187device ID.
188.It pc_class
189.Tn PCI
190device class.
191.It pc_subclass
192.Tn PCI
193device subclass.
194.It pc_progif
195.Tn PCI
196device programming interface.
197.It pc_revid
198.Tn PCI
199revision ID.
200.It pd_name
201Driver name.
202.It pd_unit
203Driver unit number.
204.El
205.It offset
206The offset is passed in by the user to tell the kernel where it should
207start traversing the device list.
208The value passed out by the kernel
209points to the record immediately after the last one returned.
210The user may
211pass the value returned by the kernel in subsequent calls to the
212.Dv PCIOCGETCONF
213ioctl.
214If the user does not intend to use the offset, it must be set to zero.
215.It generation
216.Tn PCI
217configuration generation.
218This value only needs to be set if the offset is set.
219The kernel will compare the current generation number of its internal
220device list to the generation passed in by the user to determine whether
221its device list has changed since the user last called the
222.Dv PCIOCGETCONF
223ioctl.
224If the device list has changed, a status of
225.Va PCI_GETCONF_LIST_CHANGED
226will be passed back.
227.It status
228The status tells the user the disposition of his request for a device list.
229The possible status values are:
230.Bl -ohang
231.It PCI_GETCONF_LAST_DEVICE
232This means that there are no more devices in the PCI device list after the
233ones returned in the
234.Va matches
235buffer.
236.It PCI_GETCONF_LIST_CHANGED
237This status tells the user that the
238.Tn PCI
239device list has changed since his last call to the
240.Dv PCIOCGETCONF
241ioctl and he must reset the
242.Va offset
243and
244.Va generation
245to zero to start over at the beginning of the list.
246.It PCI_GETCONF_MORE_DEVS
247This tells the user that his buffer was not large enough to hold all of the
248remaining devices in the device list that possibly match his criteria.
249It is possible for this status to be returned, even when none of the remaining
250devices in the list would match the user's criteria.
251.It PCI_GETCONF_ERROR
252This indicates a general error while servicing the user's request.
253If the
254.Va pat_buf_len
255is not equal to
256.Va num_patterns
257times
258.Fn sizeof "struct pci_match_conf" ,
259.Va errno
260will be set to
261.Er EINVAL .
262.El
263.El
264.It PCIOCREAD
265This
266.Xr ioctl 2
267reads the
268.Tn PCI
269configuration registers specified by the passed-in
270.Va pci_io
271structure.
272The
273.Va pci_io
274structure consists of the following fields:
275.Bl -tag -width pi_width
276.It pi_sel
277A
278.Va pcisel
279structure which specifies the domain, bus, slot and function the user would
280like to query.
281If the specific bus is not found, errno will be set to ENODEV and -1 returned
282from the ioctl.
283.It pi_reg
284The
285.Tn PCI
286configuration register the user would like to access.
287.It pi_width
288The width, in bytes, of the data the user would like to read.
289This value
290may be either 1, 2, or 4.
2913-byte reads and reads larger than 4 bytes are
292not supported.
293If an invalid width is passed, errno will be set to EINVAL.
294.It pi_data
295The data returned by the kernel.
296.El
297.It PCIOCWRITE
298This
299.Xr ioctl 2
300allows users to write to the
301.Tn PCI
302specified in the passed-in
303.Va pci_io
304structure.
305The
306.Va pci_io
307structure is described above.
308The limitations on data width described for
309reading registers, above, also apply to writing
310.Tn PCI
311configuration registers.
312.El
313.Sh FILES
314.Bl -tag -width /dev/pci -compact
315.It Pa /dev/pci
316Character device for the
317.Nm
318driver.
319.El
320.Sh SEE ALSO
321.Xr pciconf 8
322.Sh HISTORY
323The
324.Nm
325driver (not the kernel's
326.Tn PCI
327support code) first appeared in
328.Fx 2.2 ,
329and was written by Stefan Esser and Garrett Wollman.
330Support for device listing and matching was re-implemented by
331Kenneth Merry, and first appeared in
332.Fx 3.0 .
333.Sh AUTHORS
334.An Kenneth Merry Aq ken@FreeBSD.org
335.Sh BUGS
336It is not possible for users to specify an accurate offset into the device
337list without calling the
338.Dv PCIOCGETCONF
339at least once, since they have no way of knowing the current generation
340number otherwise.
341This probably is not a serious problem, though, since
342users can easily narrow their search by specifying a pattern or patterns
343for the kernel to match against.
344