Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


necessary to fetch these data from the configuration space for subsequent operations since they can be
obtained quickly and easily from the data structure.

driverpoints to the driver used to control the device; I discuss thestruct pci_driverdata structure
used to do this shortly. Each PCI driver is uniquely identified by an instance of this structure. A link to
the genericdevice modelis also a must for PCI devices and is established by means of thedevelement.

irqspecifies the number of the interrupt used by the device, andresourceis an array that holds the
instances of theresources reserved by the driver for I/O memory.

Driver Functions


The third and final basic data structure that forms the PCI layer is calledpci_driver.Itisusedtoimple-
ment PCI drivers and represents the interface between generic kernel code and the low-level hardware
driver for a device. Each PCI driver must pack its functions into this interface so that the kernel is able to
control the available drivers consistently.

The structure is defined as follows (for the sake of simplicitiy I have omitted the entries required to
implement power management):


struct pci_driver {
...
char *name;
const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device
inserted */
void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable
driver) */
...
struct device_driver driver;
...
};
The meaning of the first two elements is self-evident.nameis a text identifier for the device (typically, the
nameofthemoduleinwhichthedriverisimplemented),anddriverestablishes the link to the generic
device model.

The most important aspect of the PCI driver structureis support for detection, installation, and removal
of devices. Two function pointers are available for this purpose:probe, which checks whether a PCI
device is supported by the driver (this procedure is known asprobingand explains the name of the
pointer); andremove, which helps remove a device. Removal of PCI devices only makes sense if the
system supports hotplugging (which is not usually the case).

A driver must know for which devices it is responsible. The (sub)device and (sub)vendor IDs discussed
above are used to uniquely identify the devices supported in a list to which the kernel refers to ascertain
which devices are supported by the driver. A further data structure namedpci_device_idis used to
implement the list. This structure is of great importance in the PCI subsystem and is discussed below.
Since a driver can support various (more or less compatible) devices, the kernel supports a whole search
list of device IDs.
Free download pdf