acpi-drivers.rst 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. include:: <isonum.txt>
  3. =========================================
  4. Why using ACPI drivers is not a good idea
  5. =========================================
  6. :Copyright: |copy| 2026, Intel Corporation
  7. :Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  8. Even though binding drivers directly to struct acpi_device objects, also
  9. referred to as "ACPI device nodes", allows basic functionality to be provided
  10. at least in some cases, there are problems with it, related to general
  11. consistency, sysfs layout, power management operation ordering, and code
  12. cleanliness.
  13. First of all, ACPI device nodes represent firmware entities rather than
  14. hardware and in many cases they provide auxiliary information on devices
  15. enumerated independently (like PCI devices or CPUs). It is therefore generally
  16. questionable to assign resources to them because the entities represented by
  17. them do not decode addresses in the memory or I/O address spaces and do not
  18. generate interrupts or similar (all of that is done by hardware).
  19. Second, as a general rule, a struct acpi_device can only be a parent of another
  20. struct acpi_device. If that is not the case, the location of the child device
  21. in the device hierarchy is at least confusing and it may not be straightforward
  22. to identify the piece of hardware providing functionality represented by it.
  23. However, binding a driver directly to an ACPI device node may cause that to
  24. happen if the given driver registers input devices or wakeup sources under it,
  25. for example.
  26. Next, using system suspend and resume callbacks directly on ACPI device nodes
  27. is also questionable because it may cause ordering problems to appear. Namely,
  28. ACPI device nodes are registered before enumerating hardware corresponding to
  29. them and they land on the PM list in front of the majority of other device
  30. objects. Consequently, the execution ordering of their PM callbacks may be
  31. different from what is generally expected. Also, in general, dependencies
  32. returned by _DEP objects do not affect ACPI device nodes themselves, but the
  33. "physical" devices associated with them, which potentially is one more source
  34. of inconsistency related to treating ACPI device nodes as "real" device
  35. representation.
  36. All of the above means that binding drivers to ACPI device nodes should
  37. generally be avoided and so struct acpi_driver objects should not be used.
  38. Moreover, a device ID is necessary to bind a driver directly to an ACPI device
  39. node, but device IDs are not generally associated with all of them. Some of
  40. them contain alternative information allowing the corresponding pieces of
  41. hardware to be identified, for example represeted by an _ADR object return
  42. value, and device IDs are not used in those cases. In consequence, confusingly
  43. enough, binding an ACPI driver to an ACPI device node may even be impossible.
  44. When that happens, the piece of hardware corresponding to the given ACPI device
  45. node is represented by another device object, like a struct pci_dev, and the
  46. ACPI device node is the "ACPI companion" of that device, accessible through its
  47. fwnode pointer used by the ACPI_COMPANION() macro. The ACPI companion holds
  48. additional information on the device configuration and possibly some "recipes"
  49. on device manipulation in the form of AML (ACPI Machine Language) bytecode
  50. provided by the platform firmware. Thus the role of the ACPI device node is
  51. similar to the role of a struct device_node on a system where Device Tree is
  52. used for platform description.
  53. For consistency, this approach has been extended to the cases in which ACPI
  54. device IDs are used. Namely, in those cases, an additional device object is
  55. created to represent the piece of hardware corresponding to a given ACPI device
  56. node. By default, it is a platform device, but it may also be a PNP device, a
  57. CPU device, or another type of device, depending on what the given piece of
  58. hardware actually is. There are even cases in which multiple devices are
  59. "backed" or "accompanied" by one ACPI device node (e.g. ACPI device nodes
  60. corresponding to GPUs that may provide firmware interfaces for backlight
  61. brightness control in addition to GPU configuration information).
  62. This means that it really should never be necessary to bind a driver directly to
  63. an ACPI device node because there is a "proper" device object representing the
  64. corresponding piece of hardware that can be bound to by a "proper" driver using
  65. the given ACPI device node as the device's ACPI companion. Thus, in principle,
  66. there is no reason to use ACPI drivers and if they all were replaced with other
  67. driver types (for example, platform drivers), some code could be dropped and
  68. some complexity would go away.