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