TEXT   12


Guest on 10th August 2021 01:17:37 AM

  1. The Linux Kernel Device Model
  3. Patrick Mochel  <mochel@osdl.org>
  6. Overview
  7. ~~~~~~~~
  9. This driver model is a unification of all the current, disparate driver models
  10. that are currently in the kernel. It is intended is to augment the
  11. bus-specific drivers for bridges and devices by consolidating a set of data
  12. and operations into globally accessible data structures.
  14. Current driver models implement some sort of tree-like structure (sometimes
  15. just a list) for the devices they control. But, there is no linkage between
  16. the different bus types.
  18. A common data structure can provide this linkage with little overhead: when a
  19. bus driver discovers a particular device, it can insert it into the global
  20. tree as well as its local tree. In fact, the local tree becomes just a subset
  21. of the global tree.
  23. Common data fields can also be moved out of the local bus models into the
  24. global model. Some of the manipulation of these fields can also be
  25. consolidated. Most likely, manipulation functions will become a set
  26. of helper functions, which the bus drivers wrap around to include any
  27. bus-specific items.
  29. The common device and bridge interface currently reflects the goals of the
  30. modern PC: namely the ability to do seamless Plug and Play, power management,
  31. and hot plug. (The model dictated by Intel and Microsoft (read: ACPI) ensures
  32. us that any device in the system may fit any of these criteria.)
  34. In reality, not every bus will be able to support such operations. But, most
  35. buses will support a majority of those operations, and all future buses will.
  36. In other words, a bus that doesn't support an operation is the exception,
  37. instead of the other way around.
  41. Downstream Access
  42. ~~~~~~~~~~~~~~~~~
  44. Common data fields have been moved out of individual bus layers into a common
  45. data structure. But, these fields must still be accessed by the bus layers,
  46. and sometimes by the device-specific drivers.
  48. Other bus layers are encouraged to do what has been done for the PCI layer.
  49. struct pci_dev now looks like this:
  51. struct pci_dev {
  52.         ...
  54.         struct device device;
  55. };
  57. Note first that it is statically allocated. This means only one allocation on
  58. device discovery. Note also that it is at the _end_ of struct pci_dev. This is
  59. to make people think about what they're doing when switching between the bus
  60. driver and the global driver; and to prevent against mindless casts between
  61. the two.
  63. The PCI bus layer freely accesses the fields of struct device. It knows about
  64. the structure of struct pci_dev, and it should know the structure of struct
  65. device. PCI devices that have been converted generally do not touch the fields
  66. of struct device. More precisely, device-specific drivers should not touch
  67. fields of struct device unless there is a strong compelling reason to do so.
  69. This abstraction is prevention of unnecessary pain during transitional phases.
  70. If the name of the field changes or is removed, then every downstream driver
  71. will break. On the other hand, if only the bus layer (and not the device
  72. layer) accesses struct device, it is only those that need to change.
  75. User Interface
  76. ~~~~~~~~~~~~~~
  78. By virtue of having a complete hierarchical view of all the devices in the
  79. system, exporting a complete hierarchical view to userspace becomes relatively
  80. easy. This has been accomplished by implementing a special purpose virtual
  81. file system named driverfs. It is hence possible for the user to mount the
  82. whole driverfs filesystem anywhere in userspace.
  84. This can be done permanently by providing the following entry into the
  85. /etc/fstab (under the provision that the mount point does exist, of course):
  87. none            /devices        driverfs    defaults            0       0
  89. Or by hand on the command line:
  91. ~: mount -t driverfs none /devices
  93. Whenever a device is inserted into the tree, a directory is created for it.
  94. This directory may be populated at each layer of discovery - the global layer,
  95. the bus layer, or the device layer.
  97. The global layer currently creates two files - name and 'power'. The
  98. former only reports the name of the device. The latter reports the
  99. current power state of the device. It also be used to set the current
  100. power state.
  102. The bus layer may also create files for the devices it finds while probing the
  103. bus. For example, the PCI layer currently creates 'irq' and 'resource' files
  104. for each PCI device.
  106. A device-specific driver may also export files in its directory to expose
  107. device-specific data or tunable interfaces.
  109. More information about the driverfs directory layout can be found in
  110. the other documents in this directory and in the file
  111. Documentation/filesystems/driverfs.txt.

Raw Paste

Login or Register to edit or fork this paste. It's free.