xref: /openbmc/linux/Documentation/driver-api/acpi/scan_handlers.rst (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
1*97a63dd4SChangbin Du.. SPDX-License-Identifier: GPL-2.0
2*97a63dd4SChangbin Du.. include:: <isonum.txt>
3*97a63dd4SChangbin Du
4*97a63dd4SChangbin Du==================
5*97a63dd4SChangbin DuACPI Scan Handlers
6*97a63dd4SChangbin Du==================
7*97a63dd4SChangbin Du
8*97a63dd4SChangbin Du:Copyright: |copy| 2012, Intel Corporation
9*97a63dd4SChangbin Du
10*97a63dd4SChangbin Du:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11*97a63dd4SChangbin Du
12*97a63dd4SChangbin DuDuring system initialization and ACPI-based device hot-add, the ACPI namespace
13*97a63dd4SChangbin Duis scanned in search of device objects that generally represent various pieces
14*97a63dd4SChangbin Duof hardware.  This causes a struct acpi_device object to be created and
15*97a63dd4SChangbin Duregistered with the driver core for every device object in the ACPI namespace
16*97a63dd4SChangbin Duand the hierarchy of those struct acpi_device objects reflects the namespace
17*97a63dd4SChangbin Dulayout (i.e. parent device objects in the namespace are represented by parent
18*97a63dd4SChangbin Dustruct acpi_device objects and analogously for their children).  Those struct
19*97a63dd4SChangbin Duacpi_device objects are referred to as "device nodes" in what follows, but they
20*97a63dd4SChangbin Dushould not be confused with struct device_node objects used by the Device Trees
21*97a63dd4SChangbin Duparsing code (although their role is analogous to the role of those objects).
22*97a63dd4SChangbin Du
23*97a63dd4SChangbin DuDuring ACPI-based device hot-remove device nodes representing pieces of hardware
24*97a63dd4SChangbin Dubeing removed are unregistered and deleted.
25*97a63dd4SChangbin Du
26*97a63dd4SChangbin DuThe core ACPI namespace scanning code in drivers/acpi/scan.c carries out basic
27*97a63dd4SChangbin Duinitialization of device nodes, such as retrieving common configuration
28*97a63dd4SChangbin Duinformation from the device objects represented by them and populating them with
29*97a63dd4SChangbin Duappropriate data, but some of them require additional handling after they have
30*97a63dd4SChangbin Dubeen registered.  For example, if the given device node represents a PCI host
31*97a63dd4SChangbin Dubridge, its registration should cause the PCI bus under that bridge to be
32*97a63dd4SChangbin Duenumerated and PCI devices on that bus to be registered with the driver core.
33*97a63dd4SChangbin DuSimilarly, if the device node represents a PCI interrupt link, it is necessary
34*97a63dd4SChangbin Duto configure that link so that the kernel can use it.
35*97a63dd4SChangbin Du
36*97a63dd4SChangbin DuThose additional configuration tasks usually depend on the type of the hardware
37*97a63dd4SChangbin Ducomponent represented by the given device node which can be determined on the
38*97a63dd4SChangbin Dubasis of the device node's hardware ID (HID).  They are performed by objects
39*97a63dd4SChangbin Ducalled ACPI scan handlers represented by the following structure::
40*97a63dd4SChangbin Du
41*97a63dd4SChangbin Du	struct acpi_scan_handler {
42*97a63dd4SChangbin Du		const struct acpi_device_id *ids;
43*97a63dd4SChangbin Du		struct list_head list_node;
44*97a63dd4SChangbin Du		int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
45*97a63dd4SChangbin Du		void (*detach)(struct acpi_device *dev);
46*97a63dd4SChangbin Du	};
47*97a63dd4SChangbin Du
48*97a63dd4SChangbin Duwhere ids is the list of IDs of device nodes the given handler is supposed to
49*97a63dd4SChangbin Dutake care of, list_node is the hook to the global list of ACPI scan handlers
50*97a63dd4SChangbin Dumaintained by the ACPI core and the .attach() and .detach() callbacks are
51*97a63dd4SChangbin Duexecuted, respectively, after registration of new device nodes and before
52*97a63dd4SChangbin Duunregistration of device nodes the handler attached to previously.
53*97a63dd4SChangbin Du
54*97a63dd4SChangbin DuThe namespace scanning function, acpi_bus_scan(), first registers all of the
55*97a63dd4SChangbin Dudevice nodes in the given namespace scope with the driver core.  Then, it tries
56*97a63dd4SChangbin Duto match a scan handler against each of them using the ids arrays of the
57*97a63dd4SChangbin Duavailable scan handlers.  If a matching scan handler is found, its .attach()
58*97a63dd4SChangbin Ducallback is executed for the given device node.  If that callback returns 1,
59*97a63dd4SChangbin Duthat means that the handler has claimed the device node and is now responsible
60*97a63dd4SChangbin Dufor carrying out any additional configuration tasks related to it.  It also will
61*97a63dd4SChangbin Dube responsible for preparing the device node for unregistration in that case.
62*97a63dd4SChangbin DuThe device node's handler field is then populated with the address of the scan
63*97a63dd4SChangbin Duhandler that has claimed it.
64*97a63dd4SChangbin Du
65*97a63dd4SChangbin DuIf the .attach() callback returns 0, it means that the device node is not
66*97a63dd4SChangbin Duinteresting to the given scan handler and may be matched against the next scan
67*97a63dd4SChangbin Duhandler in the list.  If it returns a (negative) error code, that means that
68*97a63dd4SChangbin Duthe namespace scan should be terminated due to a serious error.  The error code
69*97a63dd4SChangbin Dureturned should then reflect the type of the error.
70*97a63dd4SChangbin Du
71*97a63dd4SChangbin DuThe namespace trimming function, acpi_bus_trim(), first executes .detach()
72*97a63dd4SChangbin Ducallbacks from the scan handlers of all device nodes in the given namespace
73*97a63dd4SChangbin Duscope (if they have scan handlers).  Next, it unregisters all of the device
74*97a63dd4SChangbin Dunodes in that scope.
75*97a63dd4SChangbin Du
76*97a63dd4SChangbin DuACPI scan handlers can be added to the list maintained by the ACPI core with the
77*97a63dd4SChangbin Duhelp of the acpi_scan_add_handler() function taking a pointer to the new scan
78*97a63dd4SChangbin Duhandler as an argument.  The order in which scan handlers are added to the list
79*97a63dd4SChangbin Duis the order in which they are matched against device nodes during namespace
80*97a63dd4SChangbin Duscans.
81*97a63dd4SChangbin Du
82*97a63dd4SChangbin DuAll scan handles must be added to the list before acpi_bus_scan() is run for the
83*97a63dd4SChangbin Dufirst time and they cannot be removed from it.
84