Linux Kernel Architecture

(Jacob Rumans) #1

Chapter7:Modules


Instead, we focus on a specific example illustrating the basic mechanism. Consider that a USB memory
stick is attached to the system, but the module that provides USB mass storage support has not yet been
loaded into the kernel. Additionally, the distribution wants to automatically mount the device so that the
user can immediately access it without further ado. The following steps are necessary to achieve this:


❑ The USB host controller detects a new device on the bus and reports this to the device driver.
The host controller allocates a new device and callsusb_new_deviceto register it.
❑ usb_new_devicetriggerskobject_ueventto be called.^22 This function calls the subsystem-
specific event notification procedure registered in thekobjectinstance for the object in
question.
❑ For USB device objects,usb_ueventis used as the notification function. The function prepares a
message that contains all necessary information forudevdto react properly to the insertion of the
new USB mass storage device.

Theudevddaemon allows inspection of all messages received from the kernel. Observe the following log
of the communication that takes place when a new USB stick is plugged into the system.


root@meitner #udevmonitor --environment
...
UEVENT[1201129806.368892] add /devices/pci0000:00/0000:00:1a.7/usb7/7-4/7-4:1.0
(usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1a.7/usb7/7-4/7-4:1.0
SUBSYSTEM=usb
DEVTYPE=usb_interface
DEVICE=/proc/bus/usb/007/005
PRODUCT=951/1600/100
TYPE=0/0/0
INTERFACE=8/6/80
MODALIAS=usb:v0951p1600d0100dc00dsc00dp00ic08isc06ip50
SEQNUM=1830

The first message is generated by the abovementioned functionusb_uevent. Every message consists of
identifier/value pairs that determine what is going on inside the kernel. Since a new device is added to
the system, the value forACTIONisadd.DEVICEdenotes where the information about the device can be
found in the USB filesystem, andPRODUCToffers some information about vendor and device. The most
important field in this case isINTERFACEbecause this determines the interface class to which the new
device belongs. The USB standard reserves 8 for mass storage devices:


<usb_ch9.h>
#define USB_CLASS_MASS_STORAGE 8

The fieldMODALIAScontains all generic pieces of information that are available about the device. It is
encoded in a string that is obviously not designed for the human eye, but can easily be parsed by a com-
puter. It is generated as follows (add_uevent_varis a helper function that adds a new identifier/value
pair to a hotplug message).


drivers/usb/core/usb.c
add_uevent_var(env,
"MODALIAS=usb:v%04Xp%04Xd%04Xdc%02Xdsc%02Xdp%02Xic%02Xisc%02Xip%02X",

(^22) The precise call path isusb_new_device→device_add→kobject_uevent.

Free download pdf