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