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