Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


6.7.1 The Generic Driver Model


Modern bus systems may differ in the details of their layout and structure, but they have much in com-
mon, a fact that is reflected in the data structures in the kernel. Many elements are used in all buses (and
in the associated device data structures). Duringthe development of 2.6, a generic driver model (device
model) was incorporated into the kernel to prevent unnecessary duplication. Properties common to all
buses are packed into special data structures that are associated with the bus-specific elements and can
be processed by generic methods.

The generic driver model is heavily based on the generic object model as discussed in Chapter 1, and has
thus also strong connections with the sysfs filesystem as examined in Section 10.3.

Representationof Devices


The driver model features a special data structure to represent the generic device properties of practically
all bus types.^19 This structure is embedded directly in the bus-specific data structures and not by means of
a reference — as is the case with thekobjects introduced above. Its (simplified) definition is as follows:

<device.h>
struct device {
struct klist klist_children;
struct klist_node knode_parent; /* node in sibling list */
struct klist_node knode_driver;
struct klist_node knode_bus;
struct device * parent;

struct kobject kobj;
char bus_id[BUS_ID_SIZE]; /* position on parent bus */
...

struct bus_type * bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this
device */
void *driver_data; /* data private to the driver */
void *platform_data; /* Platform specific data, device
core doesn’t touch it */
...
void (*release)(struct device * dev);
};

Theklistandklist_nodedata structures used are enhanced versions of the familiarlist_headdata
structures to which locking and reference management elements have been added.klistis a list head
andklist_nodea list element. Various list manipulation operations implemented by means of this
mechanism are located in<klist.h>. The associated code is rather technical, but does not offer any
deep insight into the kernel, so I won’t discuss it here, particularly as lists of this kind are used only for
the generic device model but not by the remainder of the kernel.

(^19) Devices of all relatively modern buses include such properties, and this will not change in new bus designs. Older buses that do
not comply with the model areregarded as exceptions.

Free download pdf