Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


Even though up to now I have always spoken of justoneUSB device tree, there may
be several such trees in kernel memory (that do not share the same root element).
This happens when a computer has several USB host controllers. The root elements
of all buses are kept in a separate list namedusb_bus_listthat is defined in
drivers/usb/core/hcd.c.

The elements in the bus list are represented by the following data structure:
<usb.h>
struct usb_bus {
struct device *controller;
int busnum; /* Bus number (in order of reg) */
char *bus_name; /* stable id (PCI slot_name etc) */
...
struct usb_devmap devmap; /* device address allocation map */
struct usb_device *root_hub; /* Root hub */
struct list_head bus_list; /* list of busses */
...
struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */
...
};

The data structure has two elements that uniquely identify the bus:busnumis an integer number assigned
sequentially when buses are registered, andbus_nameis a pointer to a short string holding a unique
name.controllerstores a pointer to thedeviceinstance of the hardware device that implements the
bus.

Not only devices but also the buses themselves appear in the USB filesystem mentioned above.usb_bus
must therefore also include a pointer to thedentryinstance to create the requisite link to the virtual
filesystem.

The middle elements of the data structure contain the most interesting data which link the available
buses with each other and also the attached devices. They also provide a standardized connection to the
underlying host controllers, thus abstracting the controllers as seen by the remaining USB layer.

❑ bus_listis a list element used to manage allusb_businstances on a linked list.
❑ root_hubis a pointer to the data structure of the (virtual) root hub that represents the root ele-
ment of the bus’s device tree.
❑ devmapis a bitmap list with a (minimum) length of 128 bits. It is used to keep track of which USB
numbers have already been allocated and which are still free.

Reminder: Each USB device on a number is assigned a unique integer number when it is
inserted. The standard specifies a maximum of 128 devices on a bus.
Theusb_devnumstructure type used is simply an array ofunsigned longelements that serves no
other purpose than to ensure that at least 128 consecutive bits are available.

To communicate with underlying controller hardware, aUSB request blockis used. Such blocks are used
to exchange data with USB devices in all possible forms of transfer (isochronous transfer, etc.).

drivers/usb/core/hcd.h
int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags) ;
Free download pdf