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