scan_handlers.rst 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. .. SPDX-License-Identifier: GPL-2.0
  2. .. include:: <isonum.txt>
  3. ==================
  4. ACPI Scan Handlers
  5. ==================
  6. :Copyright: |copy| 2012, Intel Corporation
  7. :Author: Rafael J. Wysocki <[email protected]>
  8. During system initialization and ACPI-based device hot-add, the ACPI namespace
  9. is scanned in search of device objects that generally represent various pieces
  10. of hardware. This causes a struct acpi_device object to be created and
  11. registered with the driver core for every device object in the ACPI namespace
  12. and the hierarchy of those struct acpi_device objects reflects the namespace
  13. layout (i.e. parent device objects in the namespace are represented by parent
  14. struct acpi_device objects and analogously for their children). Those struct
  15. acpi_device objects are referred to as "device nodes" in what follows, but they
  16. should not be confused with struct device_node objects used by the Device Trees
  17. parsing code (although their role is analogous to the role of those objects).
  18. During ACPI-based device hot-remove device nodes representing pieces of hardware
  19. being removed are unregistered and deleted.
  20. The core ACPI namespace scanning code in drivers/acpi/scan.c carries out basic
  21. initialization of device nodes, such as retrieving common configuration
  22. information from the device objects represented by them and populating them with
  23. appropriate data, but some of them require additional handling after they have
  24. been registered. For example, if the given device node represents a PCI host
  25. bridge, its registration should cause the PCI bus under that bridge to be
  26. enumerated and PCI devices on that bus to be registered with the driver core.
  27. Similarly, if the device node represents a PCI interrupt link, it is necessary
  28. to configure that link so that the kernel can use it.
  29. Those additional configuration tasks usually depend on the type of the hardware
  30. component represented by the given device node which can be determined on the
  31. basis of the device node's hardware ID (HID). They are performed by objects
  32. called ACPI scan handlers represented by the following structure::
  33. struct acpi_scan_handler {
  34. const struct acpi_device_id *ids;
  35. struct list_head list_node;
  36. int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
  37. void (*detach)(struct acpi_device *dev);
  38. };
  39. where ids is the list of IDs of device nodes the given handler is supposed to
  40. take care of, list_node is the hook to the global list of ACPI scan handlers
  41. maintained by the ACPI core and the .attach() and .detach() callbacks are
  42. executed, respectively, after registration of new device nodes and before
  43. unregistration of device nodes the handler attached to previously.
  44. The namespace scanning function, acpi_bus_scan(), first registers all of the
  45. device nodes in the given namespace scope with the driver core. Then, it tries
  46. to match a scan handler against each of them using the ids arrays of the
  47. available scan handlers. If a matching scan handler is found, its .attach()
  48. callback is executed for the given device node. If that callback returns 1,
  49. that means that the handler has claimed the device node and is now responsible
  50. for carrying out any additional configuration tasks related to it. It also will
  51. be responsible for preparing the device node for unregistration in that case.
  52. The device node's handler field is then populated with the address of the scan
  53. handler that has claimed it.
  54. If the .attach() callback returns 0, it means that the device node is not
  55. interesting to the given scan handler and may be matched against the next scan
  56. handler in the list. If it returns a (negative) error code, that means that
  57. the namespace scan should be terminated due to a serious error. The error code
  58. returned should then reflect the type of the error.
  59. The namespace trimming function, acpi_bus_trim(), first executes .detach()
  60. callbacks from the scan handlers of all device nodes in the given namespace
  61. scope (if they have scan handlers). Next, it unregisters all of the device
  62. nodes in that scope.
  63. ACPI scan handlers can be added to the list maintained by the ACPI core with the
  64. help of the acpi_scan_add_handler() function taking a pointer to the new scan
  65. handler as an argument. The order in which scan handlers are added to the list
  66. is the order in which they are matched against device nodes during namespace
  67. scans.
  68. All scan handles must be added to the list before acpi_bus_scan() is run for the
  69. first time and they cannot be removed from it.