Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


The ID table is made up of several instances of the following structure, which describes a USB device by
means of several identifiers:

<mod_devicetable.h>
struct usb_device_id {
/* which fields to match against? */
__u16 match_flags;

/* Used for product specific matches; range is inclusive */
__u16 idVendor;
__u16 idProduct;
__u16 bcdDevice_lo;
__u16 bcdDevice_hi;

/* Used for device class matches */
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;

/* Used for interface class matches */
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
...
};

match_flagsis used to specify which fields of the structure are to be compared with the device data; var-
ious pre-processor constants are defined for this purpose. For example,USB_DEVICE_ID_MATCH_VENDOR
indicates that theidVendorfield is to be checked, andUSB_DEVICE_ID_MATCH_DEV_PROTOCOLinstructs the
kernel to check the protocol field. The meaning of the other fields ofusb_device_idis self-explanatory.

The association between driver and device is established not only when a new device is added to the
system but also when a new driver is loaded. The same approach is adopted as described above. The
starting point is theusb_registerroutine, which must be invoked to register a new USB driver.

Theprobeandremovefunctions work with interfaces that are described by a separate data structure
(usb_interface). Besides interface characteristics, these include pointers to the associated device, the
driver, and the USB class to which the interface belongs. It is not therefore necessary to go into the details
of the data structure definition.

Representationof the DeviceTree


A further data structure is needed to represent the USB device tree and the various device characteristics
in the kernel.

<usb.h>
struct usb_device {
int devnum; /* Address on USB bus */
char devpath [16]; /* Use in messages: /port/port/... */
enum usb_device_state state; /* configured, not attached, etc */
enum usb_device_speed speed; /* high/full/low (or error) */
...
Free download pdf