Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


the same data. The lists enable all resources (devices and drivers) to be scanned quickly, and the
ksets ensure automatic integration into thesysfsfilesystem.subsysprovides a connection with
the bus subsystem. Accordingly buses appear in/sys/bus/busname.
❑ matchpoints to a function that attempts to find a matching driver for a given device.
❑ addis used to inform a bus that a new device has been added to the system.
❑ probeis invoked when it is necessary to link a driver with a device. This function checks whether
the device is actually present in the system.
❑ removeremoves the link between a driver and a device. This happens, for example, when a hot-
pluggable device is removed from the system.
❑ shutdown,suspend,andresumeare power management functions.

Registration Procedures


To clarify how the data structures for buses, devices, and device drivers are connected with each other, it
is useful to examine the registration procedures for each type. Some technical details like error handling
are omitted in the following to highlight the essential points. Naturally, the functions make extensive use
of methods provided by the generic device model.

Registering Buses


Before devices and their drivers can be registered, a bus is required. Thus we start withbus_register,
which adds a new bus to the system. First of all, the new bus is added to the bus subsystem via the
embeddedsubsyskset:

drivers/base/bus.c
int bus_register(struct bus_type * bus)
{
int retval;

retval = kobject_set_name(&bus->subsys.kobj, "%s", bus->name);
bus->subsys.kobj.kset = &bus_subsys;
retval = subsystem_register(&bus->subsys);
...

The bus wants to know all about both its devices and their drivers, so the bus registers kernel sets for
them. Both have the bus as parent anddriversksets:

drivers/base/bus.c
kobject_set_name(&bus->devices.kobj, "devices");
bus->devices.kobj.parent = &bus->subsys.kobj;
retval = kset_register(&bus->devices);

kobject_set_name(&bus->drivers.kobj, "drivers");
bus->drivers.kobj.parent = &bus->subsys.kobj;
bus->drivers.ktype = &driver_ktype;
retval = kset_register(&bus->drivers);
...
}
Free download pdf