xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/acpi/scan_handlers.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun.. include:: <isonum.txt>
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun==================
5*4882a593SmuzhiyunACPI Scan Handlers
6*4882a593Smuzhiyun==================
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun:Copyright: |copy| 2012, Intel Corporation
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11*4882a593Smuzhiyun
12*4882a593SmuzhiyunDuring system initialization and ACPI-based device hot-add, the ACPI namespace
13*4882a593Smuzhiyunis scanned in search of device objects that generally represent various pieces
14*4882a593Smuzhiyunof hardware.  This causes a struct acpi_device object to be created and
15*4882a593Smuzhiyunregistered with the driver core for every device object in the ACPI namespace
16*4882a593Smuzhiyunand the hierarchy of those struct acpi_device objects reflects the namespace
17*4882a593Smuzhiyunlayout (i.e. parent device objects in the namespace are represented by parent
18*4882a593Smuzhiyunstruct acpi_device objects and analogously for their children).  Those struct
19*4882a593Smuzhiyunacpi_device objects are referred to as "device nodes" in what follows, but they
20*4882a593Smuzhiyunshould not be confused with struct device_node objects used by the Device Trees
21*4882a593Smuzhiyunparsing code (although their role is analogous to the role of those objects).
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunDuring ACPI-based device hot-remove device nodes representing pieces of hardware
24*4882a593Smuzhiyunbeing removed are unregistered and deleted.
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunThe core ACPI namespace scanning code in drivers/acpi/scan.c carries out basic
27*4882a593Smuzhiyuninitialization of device nodes, such as retrieving common configuration
28*4882a593Smuzhiyuninformation from the device objects represented by them and populating them with
29*4882a593Smuzhiyunappropriate data, but some of them require additional handling after they have
30*4882a593Smuzhiyunbeen registered.  For example, if the given device node represents a PCI host
31*4882a593Smuzhiyunbridge, its registration should cause the PCI bus under that bridge to be
32*4882a593Smuzhiyunenumerated and PCI devices on that bus to be registered with the driver core.
33*4882a593SmuzhiyunSimilarly, if the device node represents a PCI interrupt link, it is necessary
34*4882a593Smuzhiyunto configure that link so that the kernel can use it.
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunThose additional configuration tasks usually depend on the type of the hardware
37*4882a593Smuzhiyuncomponent represented by the given device node which can be determined on the
38*4882a593Smuzhiyunbasis of the device node's hardware ID (HID).  They are performed by objects
39*4882a593Smuzhiyuncalled ACPI scan handlers represented by the following structure::
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun	struct acpi_scan_handler {
42*4882a593Smuzhiyun		const struct acpi_device_id *ids;
43*4882a593Smuzhiyun		struct list_head list_node;
44*4882a593Smuzhiyun		int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
45*4882a593Smuzhiyun		void (*detach)(struct acpi_device *dev);
46*4882a593Smuzhiyun	};
47*4882a593Smuzhiyun
48*4882a593Smuzhiyunwhere ids is the list of IDs of device nodes the given handler is supposed to
49*4882a593Smuzhiyuntake care of, list_node is the hook to the global list of ACPI scan handlers
50*4882a593Smuzhiyunmaintained by the ACPI core and the .attach() and .detach() callbacks are
51*4882a593Smuzhiyunexecuted, respectively, after registration of new device nodes and before
52*4882a593Smuzhiyununregistration of device nodes the handler attached to previously.
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunThe namespace scanning function, acpi_bus_scan(), first registers all of the
55*4882a593Smuzhiyundevice nodes in the given namespace scope with the driver core.  Then, it tries
56*4882a593Smuzhiyunto match a scan handler against each of them using the ids arrays of the
57*4882a593Smuzhiyunavailable scan handlers.  If a matching scan handler is found, its .attach()
58*4882a593Smuzhiyuncallback is executed for the given device node.  If that callback returns 1,
59*4882a593Smuzhiyunthat means that the handler has claimed the device node and is now responsible
60*4882a593Smuzhiyunfor carrying out any additional configuration tasks related to it.  It also will
61*4882a593Smuzhiyunbe responsible for preparing the device node for unregistration in that case.
62*4882a593SmuzhiyunThe device node's handler field is then populated with the address of the scan
63*4882a593Smuzhiyunhandler that has claimed it.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunIf the .attach() callback returns 0, it means that the device node is not
66*4882a593Smuzhiyuninteresting to the given scan handler and may be matched against the next scan
67*4882a593Smuzhiyunhandler in the list.  If it returns a (negative) error code, that means that
68*4882a593Smuzhiyunthe namespace scan should be terminated due to a serious error.  The error code
69*4882a593Smuzhiyunreturned should then reflect the type of the error.
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunThe namespace trimming function, acpi_bus_trim(), first executes .detach()
72*4882a593Smuzhiyuncallbacks from the scan handlers of all device nodes in the given namespace
73*4882a593Smuzhiyunscope (if they have scan handlers).  Next, it unregisters all of the device
74*4882a593Smuzhiyunnodes in that scope.
75*4882a593Smuzhiyun
76*4882a593SmuzhiyunACPI scan handlers can be added to the list maintained by the ACPI core with the
77*4882a593Smuzhiyunhelp of the acpi_scan_add_handler() function taking a pointer to the new scan
78*4882a593Smuzhiyunhandler as an argument.  The order in which scan handlers are added to the list
79*4882a593Smuzhiyunis the order in which they are matched against device nodes during namespace
80*4882a593Smuzhiyunscans.
81*4882a593Smuzhiyun
82*4882a593SmuzhiyunAll scan handles must be added to the list before acpi_bus_scan() is run for the
83*4882a593Smuzhiyunfirst time and they cannot be removed from it.
84