162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci.. include:: <isonum.txt>
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci==================
562306a36Sopenharmony_ciACPI Scan Handlers
662306a36Sopenharmony_ci==================
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci:Copyright: |copy| 2012, Intel Corporation
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciDuring system initialization and ACPI-based device hot-add, the ACPI namespace
1362306a36Sopenharmony_ciis scanned in search of device objects that generally represent various pieces
1462306a36Sopenharmony_ciof hardware.  This causes a struct acpi_device object to be created and
1562306a36Sopenharmony_ciregistered with the driver core for every device object in the ACPI namespace
1662306a36Sopenharmony_ciand the hierarchy of those struct acpi_device objects reflects the namespace
1762306a36Sopenharmony_cilayout (i.e. parent device objects in the namespace are represented by parent
1862306a36Sopenharmony_cistruct acpi_device objects and analogously for their children).  Those struct
1962306a36Sopenharmony_ciacpi_device objects are referred to as "device nodes" in what follows, but they
2062306a36Sopenharmony_cishould not be confused with struct device_node objects used by the Device Trees
2162306a36Sopenharmony_ciparsing code (although their role is analogous to the role of those objects).
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciDuring ACPI-based device hot-remove device nodes representing pieces of hardware
2462306a36Sopenharmony_cibeing removed are unregistered and deleted.
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciThe core ACPI namespace scanning code in drivers/acpi/scan.c carries out basic
2762306a36Sopenharmony_ciinitialization of device nodes, such as retrieving common configuration
2862306a36Sopenharmony_ciinformation from the device objects represented by them and populating them with
2962306a36Sopenharmony_ciappropriate data, but some of them require additional handling after they have
3062306a36Sopenharmony_cibeen registered.  For example, if the given device node represents a PCI host
3162306a36Sopenharmony_cibridge, its registration should cause the PCI bus under that bridge to be
3262306a36Sopenharmony_cienumerated and PCI devices on that bus to be registered with the driver core.
3362306a36Sopenharmony_ciSimilarly, if the device node represents a PCI interrupt link, it is necessary
3462306a36Sopenharmony_cito configure that link so that the kernel can use it.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciThose additional configuration tasks usually depend on the type of the hardware
3762306a36Sopenharmony_cicomponent represented by the given device node which can be determined on the
3862306a36Sopenharmony_cibasis of the device node's hardware ID (HID).  They are performed by objects
3962306a36Sopenharmony_cicalled ACPI scan handlers represented by the following structure::
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	struct acpi_scan_handler {
4262306a36Sopenharmony_ci		const struct acpi_device_id *ids;
4362306a36Sopenharmony_ci		struct list_head list_node;
4462306a36Sopenharmony_ci		int (*attach)(struct acpi_device *dev, const struct acpi_device_id *id);
4562306a36Sopenharmony_ci		void (*detach)(struct acpi_device *dev);
4662306a36Sopenharmony_ci	};
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ciwhere ids is the list of IDs of device nodes the given handler is supposed to
4962306a36Sopenharmony_citake care of, list_node is the hook to the global list of ACPI scan handlers
5062306a36Sopenharmony_cimaintained by the ACPI core and the .attach() and .detach() callbacks are
5162306a36Sopenharmony_ciexecuted, respectively, after registration of new device nodes and before
5262306a36Sopenharmony_ciunregistration of device nodes the handler attached to previously.
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciThe namespace scanning function, acpi_bus_scan(), first registers all of the
5562306a36Sopenharmony_cidevice nodes in the given namespace scope with the driver core.  Then, it tries
5662306a36Sopenharmony_cito match a scan handler against each of them using the ids arrays of the
5762306a36Sopenharmony_ciavailable scan handlers.  If a matching scan handler is found, its .attach()
5862306a36Sopenharmony_cicallback is executed for the given device node.  If that callback returns 1,
5962306a36Sopenharmony_cithat means that the handler has claimed the device node and is now responsible
6062306a36Sopenharmony_cifor carrying out any additional configuration tasks related to it.  It also will
6162306a36Sopenharmony_cibe responsible for preparing the device node for unregistration in that case.
6262306a36Sopenharmony_ciThe device node's handler field is then populated with the address of the scan
6362306a36Sopenharmony_cihandler that has claimed it.
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciIf the .attach() callback returns 0, it means that the device node is not
6662306a36Sopenharmony_ciinteresting to the given scan handler and may be matched against the next scan
6762306a36Sopenharmony_cihandler in the list.  If it returns a (negative) error code, that means that
6862306a36Sopenharmony_cithe namespace scan should be terminated due to a serious error.  The error code
6962306a36Sopenharmony_cireturned should then reflect the type of the error.
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ciThe namespace trimming function, acpi_bus_trim(), first executes .detach()
7262306a36Sopenharmony_cicallbacks from the scan handlers of all device nodes in the given namespace
7362306a36Sopenharmony_ciscope (if they have scan handlers).  Next, it unregisters all of the device
7462306a36Sopenharmony_cinodes in that scope.
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ciACPI scan handlers can be added to the list maintained by the ACPI core with the
7762306a36Sopenharmony_cihelp of the acpi_scan_add_handler() function taking a pointer to the new scan
7862306a36Sopenharmony_cihandler as an argument.  The order in which scan handlers are added to the list
7962306a36Sopenharmony_ciis the order in which they are matched against device nodes during namespace
8062306a36Sopenharmony_ciscans.
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciAll scan handles must be added to the list before acpi_bus_scan() is run for the
8362306a36Sopenharmony_cifirst time and they cannot be removed from it.
84