The reason that PCI bus drivers are being discussed is that PCI interface is now vastly popular and most peripheral devices are supporting the PCI bus. Though it would be nice to somehow spoof a PCI peripheral device, i am not aware of a method to do it or probably it cannot be done.
Hence, an overview and brief of how a PCI BUS based peripheral is enumerated by the Linux kernel and how the kernel invokes a driver for the peripheral needs to be understood. To look at all the PCI bus and associated peripherals, run the “lspci -v ” command.
Before we look at how the kernel would enumerate the PCI device, we need to have a brief idea on PCI configuration address space
In the above configuration space, it is seen that the PCI peripheral is mapped with an unique Device ID and Vendor ID combination which specifies the device make and the company that developed the PCI peripheral. The Configuration space is read by the Linux kernel to determine which device driver has registered support for the PCI peripheral and invokes that device driver’s “probe” function.
The below picture provides details on how the PCI peripheral is brought up in Linux
The steps are outlined below
- PCI driver is loaded in kernel and it registers a PCI driver with the kernel. It provides details of Device ID + Vendor ID to the kernel stating that the driver supports specific Device ID + Vendor ID combination.
- PCI card is detected at PCI slot
- Kernel enumerates the list of drivers registered for the specific PCI peripheral by mapping the device ID + Vendor ID in the peripheral and that provided by the driver
- Kernel invokes the PCI device driver “probe” function and the driver proceeds with PCI peripheral initialization and to setup PCI device operation for the peripheral
Some of the basic PCI driver APIs that are important are listed below. for more details – refer /linux/pci.h in the Linux kernel.
API | Description |
pci_register_driver() | Register a new PCI driver |
pci_unregister_driver() | UnRegister a PCI driver |
pci_enable_device() | Initialize device before being used by driver |
pci_disable_device() | Disable PCI device after use |
Refer the link for details on PCI driver operation — https://docs.kernel.org/PCI/pci.html
The PCI driver has to perform the following after device detection and during release of PCI device
Pingback: Understanding network device drivers in the Linux Kernel | Hitch Hiker's Guide to Learning