Driver Functions

The third and final basic data structure that forms the PCI layer is called pci_driver. It is used to implement 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; int (*probe) (struct pci_dev *dev inserted */

struct device_driver driver;

/* must be non-NULL for probe to be called */ const struct pci_device_id *id); /* New device

/* Device removed (NULL if not a hot-plug capable

The meaning of the first two elements is self-evident. name is a text identifier for the device (typically, the name of the module in which the driver is implemented), and driver establishes the link to the generic device model.

The most important aspect of the PCI driver structure is 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 as probing and explains the name of the pointer); and remove, 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 named pci_device_id is 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.

Continue reading here: Registering Drivers

Was this article helpful?

0 0