Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


More interesting are the elements ofstruct device, which have the following meanings:

❑ The embeddedkobjectcontrols generic object properties as discussed above.
❑ Various elements are used to build hierarchical relationships between devices.klist_children
is the head of a linked list with all lower-level devices of the specified device.knode_parentis
used as a list element if the device itself is included on such a list.parentpoints to thedevice
instance of the parent element.
❑ Since a device driver is able to serve more than one device (when, for example, two identical
cards are installed in the system),knode_driveris used as a list element to list thedevice
instances of all managed devices.driverpoints to the data structure of the device driver that
controls the device (more on this below).
❑ bus_iduniquely specifies the position of the device on the hosting bus (the format used varies
between bus types). For example, the positionof devices on a PCI bus is uniquely defined by a
string with the following format:<bus number>:<slot number>.<function number>.
❑ busis a pointer to the data structure instance of the bus (more below) on which the device is
located.
❑ driver_datais a private element of the driver that is not modified by generic code. It can be
used to point to specific data that do not fit into the general scheme but are needed to work with
the device.platform_dataandfirmware_dataare also private elements that can be used to
associate architecture-specific data and firmware information with a device; they are also left
untouched by the generic driver model.
❑ releaseis a destructor function to free the allocated resources to the kernel when the device (or
deviceinstance) is no longer in use.

The kernel provides thedevice_registerstandard function to add a new device to the kernel data
structures. This function is examined below. Thedevice_getanddevice_putfunction pair counts the
references.

The generic driver model also makes a separate data structure available for device drivers.

<driver.h>
struct device_driver {
const char * name;
struct bus_type * bus;

struct kobject kobj;
struct klist klist_devices;
struct klist_node knode_bus;
...
int (*probe) (struct device * dev);
int (*remove) (struct device * dev);
void (*shutdown) (struct device * dev);
int (*suspend) (struct device * dev, pm_message_t state);
int (*resume) (struct device * dev);
};
Free download pdf