Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


The following data structures are associated with the items in this list.


Theusb_driverstructure is the starting point of the collaboration between the USB device driver and
the rest of the kernel (above all the USB layer).


<usb.h>
struct usb_driver {
const char *name;

int (*probe) (struct usb_interface *intf,
const struct usb_device_id *id);
void (*disconnect) (struct usb_interface *intf);
int (*ioctl) (struct usb_interface *intf, unsigned int code,
void *buf);
...
const struct usb_device_id *id_table;
...
struct usbdrv_wrap drvwrap;
...
};

Thenameandownerfields fulfill the usual management purposes. The former holds the name of the
driver, which must be unique within the kernel (the filename of the module is normally used). The latter
creates an association betweenusb_driverand themodulestructure if the driver has been added to the
kernel as a module. The usual embeddeddriverobject is hidden in another structure this time.


<usb.h>
struct usbdrv_wrap {
struct device_driver driver;
int for_devices;
};

The extra data structure allows distinguishing between interface drivers (for_devicesis zero in this
case) and proper device drivers.


Of special interest are the function pointersprobeanddisconnect.Togetherwithid_table,theyform
the backbone of the hotplugging capabilities of the USB subsystem. When the host adapter detects that a
new device has been inserted, aprobingprocess is started to find a suitable device driver.


The kernel then traverses all elements of the devicetree to ascertain whether any driver is interested.
This presupposes, of course, that a driver has not already been assigned to the device. If a driver has
been allocated, the device is skipped.


The kernel first scans the list of all devices that are supported by the driver and are included in its
id_tablelist. This approach is familiar because USB devices (like PCI devices) can be uniquely iden-
tified by a number. Once a match has been found between device and table, the driver-specificprobe
function is invoked to perform further checks and initialization work.


If no match is found between the device ID and the list of drivers, the kernel skips to the next driver and
need not invoke the function stored inprobe.

Free download pdf