---
name: "pci"
section: "4"
platform: "linux"
package: "freebsd-manpages"
version: "6.0-5"
release: "Debian 4.0 (Etch)"
platforms: ["linux", "freebsd", "openbsd"]
url: "https://new.carta.tech/pci"
---

# pci(4)

generic PCI driver

## NAME

**pci** – generic PCI driver

## SYNOPSIS

**device** **pci**

## DESCRIPTION

The **pci** driver provides a way for userland programs to read and write PCI configuration registers. It also provides a way for userland programs to get a list of all PCI devices, or all PCI devices that match various patterns.

Since the **pci** driver provides a write interface for PCI configuration registers, system administrators should exercise caution when granting access to the **pci** device. If used improperly, this driver can allow userland applications to crash a machine or cause data loss.

## KERNEL CONFIGURATION

It is only necessary to specify one **pci** controller in the kernel. Additional PCI busses are handled automatically as they are encountered.

## IOCTLS

The following [ioctl(2)](/ioctl/2.md) calls are supported by the **pci** driver. They are defined in the header file ⟨sys/pciio.h⟩.

- PCIOCGETCONF

  This [ioctl(2)](/ioctl/2.md) takes a *pci\_conf\_io* structure. It allows the user to retrieve information on all PCI devices in the system, or on PCI devices matching patterns supplied by the user. The call may set *errno* to any value specified in either [copyin(9)](/copyin/9.md) or [copyout(9)](/copyout/9.md). The *pci\_conf\_io* structure consists of a number of fields:

  - pat\_buf\_len

    The length, in bytes, of the buffer filled with user-supplied patterns.

  - num\_patterns

    The number of user-supplied patterns.

  - patterns

    Pointer to a buffer filled with user-supplied patterns. *patterns* is a pointer to *num\_patterns* *pci\_match\_conf* structures. The *pci\_match\_conf* structure consists of the following elements:

    - pc\_sel

      PCI bus, slot and function.

    - pd\_name

      PCI device driver name.

    - pd\_unit

      PCI device driver unit number.

    - pc\_vendor

      PCI vendor ID.

    - pc\_device

      PCI device ID.

    - pc\_class

      PCI device class.

    - flags

      The flags describe which of the fields the kernel should match against. A device must match all specified fields in order to be returned. The match flags are enumerated in the *pci\_getconf\_flags* structure. Hopefully the flag values are obvious enough that they do not need to described in detail.

  - match\_buf\_len

    Length of the *matches* buffer allocated by the user to hold the results of the PCIOCGETCONF query.

  - num\_matches

    Number of matches returned by the kernel.

  - matches

    Buffer containing matching devices returned by the kernel. The items in this buffer are of type *pci\_conf*, which consists of the following items:

    - pc\_sel

      PCI bus, slot and function.

    - pc\_hdr

      PCI header type.

    - pc\_subvendor

      PCI subvendor ID.

    - pc\_subdevice

      PCI subdevice ID.

    - pc\_vendor

      PCI vendor ID.

    - pc\_device

      PCI device ID.

    - pc\_class

      PCI device class.

    - pc\_subclass

      PCI device subclass.

    - pc\_progif

      PCI device programming interface.

    - pc\_revid

      PCI revision ID.

    - pd\_name

      Driver name.

    - pd\_unit

      Driver unit number.

  - offset

    The offset is passed in by the user to tell the kernel where it should start traversing the device list. The value passed out by the kernel points to the record immediately after the last one returned. The user may pass the value returned by the kernel in subsequent calls to the PCIOCGETCONF ioctl. If the user does not intend to use the offset, it must be set to zero.

  - generation

    PCI configuration generation. This value only needs to be set if the offset is set. The kernel will compare the current generation number of its internal device list to the generation passed in by the user to determine whether its device list has changed since the user last called the PCIOCGETCONF ioctl. If the device list has changed, a status of *PCI\_GETCONF\_LIST\_CHANGED* will be passed back.

  - status

    The status tells the user the disposition of his request for a device list. The possible status values are:

    - PCI\_GETCONF\_LAST\_DEVICE

      This means that there are no more devices in the PCI device list after the ones returned in the *matches* buffer.

    - PCI\_GETCONF\_LIST\_CHANGED

      This status tells the user that the PCI device list has changed since his last call to the PCIOCGETCONF ioctl and he must reset the *offset* and *generation* to zero to start over at the beginning of the list.

    - PCI\_GETCONF\_MORE\_DEVS

      This tells the user that his buffer was not large enough to hold all of the remaining devices in the device list that possibly match his criteria. It is possible for this status to be returned, even when none of the remaining devices in the list would match the user's criteria.

    - PCI\_GETCONF\_ERROR

      This indicates a general error while servicing the user's request. If the *pat\_buf\_len* is not equal to *num\_patterns* times **sizeof**(*struct pci\_match\_conf*), *errno* will be set to EINVAL.

- PCIOCREAD

  This [ioctl(2)](/ioctl/2.md) reads the PCI configuration registers specified by the passed-in *pci\_io* structure. The *pci\_io* structure consists of the following fields:

  - pi\_sel

    A *pcisel* structure which specifies the bus, slot and function the user would like to query. If the specific bus is not found, errno will be set to ENODEV and -1 returned from the ioctl.

  - pi\_reg

    The PCI configuration register the user would like to access.

  - pi\_width

    The width, in bytes, of the data the user would like to read. This value may be either 1, 2, or 4. 3-byte reads and reads larger than 4 bytes are not supported. If an invalid width is passed, errno will be set to EINVAL.

  - pi\_data

    The data returned by the kernel.

- PCIOCWRITE

  This [ioctl(2)](/ioctl/2.md) allows users to write to the PCI specified in the passed-in *pci\_io* structure. The *pci\_io* structure is described above. The limitations on data width described for reading registers, above, also apply to writing PCI configuration registers.

## FILES

- */dev/pci*

  Character device for the **pci** driver.

## DIAGNOSTICS

None.

## SEE ALSO

[pciconf(8)](/pciconf/8.md)

## HISTORY

The **pci** driver (not the kernel's PCI support code) first appeared in FreeBSD 2.2, and was written by Stefan Esser and Garrett Wollman. Support for device listing and matching was re-implemented by Kenneth Merry, and first appeared in FreeBSD 3.0.

## AUTHORS

Kenneth Merry ⟨ken@FreeBSD.org⟩

## BUGS

It is not possible for users to specify an accurate offset into the device list without calling the PCIOCGETCONF at least once, since they have no way of knowing the current generation number otherwise. This probably is not a serious problem, though, since users can easily narrow their search by specifying a pattern or patterns for the kernel to match against.
