📄 overview.txt
字号:
The Linux Kernel Device ModelPatrick Mochel <mochel@digitalimplant.org>Drafted 26 August 2002Updated 31 January 2006Overview~~~~~~~~The Linux Kernel Driver Model is a unification of all the disparate drivermodels that were previously used in the kernel. It is intended to augment thebus-specific drivers for bridges and devices by consolidating a set of dataand operations into globally accessible data structures.Traditional driver models implemented some sort of tree-like structure(sometimes just a list) for the devices they control. There wasn't anyuniformity across the different bus types.The current driver model provides a common, uniform data model for describinga bus and the devices that can appear under the bus. The unified busmodel includes a set of common attributes which all busses carry, and a setof common callbacks, such as device discovery during bus probing, busshutdown, bus power management, etc.The common device and bridge interface reflects the goals of the moderncomputer: namely the ability to do seamless device "plug and play", powermanagement, and hot plug. In particular, the model dictated by Intel andMicrosoft (namely ACPI) ensures that almost every device on almost any buson an x86-compatible system can work within this paradigm. Of course,not every bus is able to support all such operations, although mostbuses support a most of those operations.Downstream Access~~~~~~~~~~~~~~~~~Common data fields have been moved out of individual bus layers into a commondata structure. These fields must still be accessed by the bus layers,and sometimes by the device-specific drivers.Other bus layers are encouraged to do what has been done for the PCI layer.struct pci_dev now looks like this:struct pci_dev { ... struct device dev;};Note first that it is statically allocated. This means only one allocation ondevice discovery. Note also that it is at the _end_ of struct pci_dev. This isto make people think about what they're doing when switching between the busdriver and the global driver; and to prevent against mindless casts betweenthe two.The PCI bus layer freely accesses the fields of struct device. It knows aboutthe structure of struct pci_dev, and it should know the structure of structdevice. Individual PCI device drivers that have been converted to the currentdriver model generally do not and should not touch the fields of struct device,unless there is a strong compelling reason to do so.This abstraction is prevention of unnecessary pain during transitional phases.If the name of the field changes or is removed, then every downstream driverwill break. On the other hand, if only the bus layer (and not the devicelayer) accesses struct device, it is only that layer that needs to change.User Interface~~~~~~~~~~~~~~By virtue of having a complete hierarchical view of all the devices in thesystem, exporting a complete hierarchical view to userspace becomes relativelyeasy. This has been accomplished by implementing a special purpose virtualfile system named sysfs. It is hence possible for the user to mount thewhole sysfs filesystem anywhere in userspace.This can be done permanently by providing the following entry into the/etc/fstab (under the provision that the mount point does exist, of course):none /sys sysfs defaults 0 0Or by hand on the command line:# mount -t sysfs sysfs /sysWhenever a device is inserted into the tree, a directory is created for it.This directory may be populated at each layer of discovery - the global layer,the bus layer, or the device layer.The global layer currently creates two files - 'name' and 'power'. Theformer only reports the name of the device. The latter reports thecurrent power state of the device. It will also be used to set the currentpower state. The bus layer may also create files for the devices it finds while probing thebus. For example, the PCI layer currently creates 'irq' and 'resource' filesfor each PCI device.A device-specific driver may also export files in its directory to exposedevice-specific data or tunable interfaces.More information about the sysfs directory layout can be found inthe other documents in this directory and in the file Documentation/filesystems/sysfs.txt.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -