xref: /freebsd/share/man/man4/pci.4 (revision 7bd6fde3)
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 October 24, 1999
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.Sh KERNEL CONFIGURATION
58It is only necessary to specify one
59.Nm
60controller in the kernel.
61Additional
62.Tn PCI
63busses are handled automatically as they are encountered.
64.Sh IOCTLS
65The following
66.Xr ioctl 2
67calls are supported by the
68.Nm
69driver.
70They are defined in the header file
71.In sys/pciio.h .
72.Bl -tag -width 012345678901234
73.Pp
74.It PCIOCGETCONF
75This
76.Xr ioctl 2
77takes a
78.Va pci_conf_io
79structure.
80It allows the user to retrieve information on all
81.Tn PCI
82devices in the system, or on
83.Tn PCI
84devices matching patterns supplied by the user.
85The call may set
86.Va errno
87to any value specified in either
88.Xr copyin 9
89or
90.Xr copyout 9 .
91The
92.Va pci_conf_io
93structure consists of a number of fields:
94.Bl -tag -width match_buf_len
95.It pat_buf_len
96The length, in bytes, of the buffer filled with user-supplied patterns.
97.It num_patterns
98The number of user-supplied patterns.
99.It patterns
100Pointer to a buffer filled with user-supplied patterns.
101.Va patterns
102is a pointer to
103.Va num_patterns
104.Va pci_match_conf
105structures.
106The
107.Va pci_match_conf
108structure consists of the following elements:
109.Bl -tag -width pd_vendor
110.It pc_sel
111.Tn PCI
112bus, slot and function.
113.It pd_name
114.Tn PCI
115device driver name.
116.It pd_unit
117.Tn PCI
118device driver unit number.
119.It pc_vendor
120.Tn PCI
121vendor ID.
122.It pc_device
123.Tn PCI
124device ID.
125.It pc_class
126.Tn PCI
127device class.
128.It flags
129The flags describe which of the fields the kernel should match against.
130A device must match all specified fields in order to be returned.
131The match flags are enumerated in the
132.Va pci_getconf_flags
133structure.
134Hopefully the flag values are obvious enough that they do not need to
135described in detail.
136.El
137.It match_buf_len
138Length of the
139.Va matches
140buffer allocated by the user to hold the results of the
141.Dv PCIOCGETCONF
142query.
143.It num_matches
144Number of matches returned by the kernel.
145.It matches
146Buffer containing matching devices returned by the kernel.
147The items in this buffer are of type
148.Va pci_conf ,
149which consists of the following items:
150.Bl -tag -width pc_subvendor
151.It pc_sel
152.Tn PCI
153bus, slot and function.
154.It pc_hdr
155.Tn PCI
156header type.
157.It pc_subvendor
158.Tn PCI
159subvendor ID.
160.It pc_subdevice
161.Tn PCI
162subdevice ID.
163.It pc_vendor
164.Tn PCI
165vendor ID.
166.It pc_device
167.Tn PCI
168device ID.
169.It pc_class
170.Tn PCI
171device class.
172.It pc_subclass
173.Tn PCI
174device subclass.
175.It pc_progif
176.Tn PCI
177device programming interface.
178.It pc_revid
179.Tn PCI
180revision ID.
181.It pd_name
182Driver name.
183.It pd_unit
184Driver unit number.
185.El
186.It offset
187The offset is passed in by the user to tell the kernel where it should
188start traversing the device list.
189The value passed out by the kernel
190points to the record immediately after the last one returned.
191The user may
192pass the value returned by the kernel in subsequent calls to the
193.Dv PCIOCGETCONF
194ioctl.
195If the user does not intend to use the offset, it must be set to zero.
196.It generation
197.Tn PCI
198configuration generation.
199This value only needs to be set if the offset is set.
200The kernel will compare the current generation number of its internal
201device list to the generation passed in by the user to determine whether
202its device list has changed since the user last called the
203.Dv PCIOCGETCONF
204ioctl.
205If the device list has changed, a status of
206.Va PCI_GETCONF_LIST_CHANGED
207will be passed back.
208.It status
209The status tells the user the disposition of his request for a device list.
210The possible status values are:
211.Bl -ohang
212.It PCI_GETCONF_LAST_DEVICE
213This means that there are no more devices in the PCI device list after the
214ones returned in the
215.Va matches
216buffer.
217.It PCI_GETCONF_LIST_CHANGED
218This status tells the user that the
219.Tn PCI
220device list has changed since his last call to the
221.Dv PCIOCGETCONF
222ioctl and he must reset the
223.Va offset
224and
225.Va generation
226to zero to start over at the beginning of the list.
227.It PCI_GETCONF_MORE_DEVS
228This tells the user that his buffer was not large enough to hold all of the
229remaining devices in the device list that possibly match his criteria.
230It is possible for this status to be returned, even when none of the remaining
231devices in the list would match the user's criteria.
232.It PCI_GETCONF_ERROR
233This indicates a general error while servicing the user's request.
234If the
235.Va pat_buf_len
236is not equal to
237.Va num_patterns
238times
239.Fn sizeof "struct pci_match_conf" ,
240.Va errno
241will be set to
242.Er EINVAL .
243.El
244.El
245.It PCIOCREAD
246This
247.Xr ioctl 2
248reads the
249.Tn PCI
250configuration registers specified by the passed-in
251.Va pci_io
252structure.
253The
254.Va pci_io
255structure consists of the following fields:
256.Bl -tag -width pi_width
257.It pi_sel
258A
259.Va pcisel
260structure which specifies the bus, slot and function the user would like to
261query.
262If the specific bus is not found, errno will be set to ENODEV and -1 returned from the ioctl.
263.It pi_reg
264The
265.Tn PCI
266configuration register the user would like to access.
267.It pi_width
268The width, in bytes, of the data the user would like to read.
269This value
270may be either 1, 2, or 4.
2713-byte reads and reads larger than 4 bytes are
272not supported.
273If an invalid width is passed, errno will be set to EINVAL.
274.It pi_data
275The data returned by the kernel.
276.El
277.It PCIOCWRITE
278This
279.Xr ioctl 2
280allows users to write to the
281.Tn PCI
282specified in the passed-in
283.Va pci_io
284structure.
285The
286.Va pci_io
287structure is described above.
288The limitations on data width described for
289reading registers, above, also apply to writing
290.Tn PCI
291configuration registers.
292.El
293.Sh FILES
294.Bl -tag -width /dev/pci -compact
295.It Pa /dev/pci
296Character device for the
297.Nm
298driver.
299.El
300.Sh DIAGNOSTICS
301None.
302.Sh SEE ALSO
303.Xr pciconf 8
304.Sh HISTORY
305The
306.Nm
307driver (not the kernel's
308.Tn PCI
309support code) first appeared in
310.Fx 2.2 ,
311and was written by Stefan Esser and Garrett Wollman.
312Support for device listing and matching was re-implemented by
313Kenneth Merry, and first appeared in
314.Fx 3.0 .
315.Sh AUTHORS
316.An Kenneth Merry Aq ken@FreeBSD.org
317.Sh BUGS
318It is not possible for users to specify an accurate offset into the device
319list without calling the
320.Dv PCIOCGETCONF
321at least once, since they have no way of knowing the current generation
322number otherwise.
323This probably is not a serious problem, though, since
324users can easily narrow their search by specifying a pattern or patterns
325for the kernel to match against.
326