Commit 2c22e652 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

ACPI / scan: Use direct recurrence for device hierarchy walks

Rework acpi_bus_trim() and acpi_bus_device_attach(), which is
renamed as acpi_bus_attach(), to walk the list of each device
object's children directly and call themselves recursively for
each child instead of using acpi_walk_namespace().  This
simplifies the code quite a bit and avoids the overhead of
callbacks and the ACPICA's internal processing which are not
really necessary for these two routines.
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 25db115b
...@@ -1909,54 +1909,40 @@ static int acpi_scan_attach_handler(struct acpi_device *device) ...@@ -1909,54 +1909,40 @@ static int acpi_scan_attach_handler(struct acpi_device *device)
return ret; return ret;
} }
static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used, static void acpi_bus_attach(struct acpi_device *device)
void *not_used, void **ret_not_used)
{ {
struct acpi_device *device; struct acpi_device *child;
unsigned long long sta;
int ret; int ret;
/* acpi_bus_get_status(device);
* Ignore errors ignored by acpi_bus_check_add() to avoid terminating
* namespace walks prematurely.
*/
if (acpi_bus_type_and_status(handle, &ret, &sta))
return AE_OK;
if (acpi_bus_get_device(handle, &device))
return AE_CTRL_DEPTH;
acpi_set_device_status(device, sta);
/* Skip devices that are not present. */ /* Skip devices that are not present. */
if (!acpi_device_is_present(device)) if (!acpi_device_is_present(device)) {
goto err; device->flags.visited = false;
return;
}
if (device->handler) if (device->handler)
return AE_OK; goto ok;
if (!device->flags.initialized) { if (!device->flags.initialized) {
acpi_bus_update_power(device, NULL); acpi_bus_update_power(device, NULL);
device->flags.initialized = true; device->flags.initialized = true;
} }
device->flags.visited = false;
ret = acpi_scan_attach_handler(device); ret = acpi_scan_attach_handler(device);
if (ret < 0) if (ret < 0)
goto err; return;
device->flags.match_driver = true; device->flags.match_driver = true;
if (ret > 0) if (!ret) {
goto ok; ret = device_attach(&device->dev);
if (ret < 0)
ret = device_attach(&device->dev); return;
if (ret < 0) }
goto err;
ok:
device->flags.visited = true; device->flags.visited = true;
return AE_OK;
err: ok:
device->flags.visited = false; list_for_each_entry(child, &device->children, node)
return AE_CTRL_DEPTH; acpi_bus_attach(child);
} }
/** /**
...@@ -1976,64 +1962,48 @@ static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used, ...@@ -1976,64 +1962,48 @@ static acpi_status acpi_bus_device_attach(acpi_handle handle, u32 lvl_not_used,
int acpi_bus_scan(acpi_handle handle) int acpi_bus_scan(acpi_handle handle)
{ {
void *device = NULL; void *device = NULL;
int error = 0;
if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device))) if (ACPI_SUCCESS(acpi_bus_check_add(handle, 0, NULL, &device)))
acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX, acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
acpi_bus_check_add, NULL, NULL, &device); acpi_bus_check_add, NULL, NULL, &device);
if (!device) if (device) {
error = -ENODEV; acpi_bus_attach(device);
else if (ACPI_SUCCESS(acpi_bus_device_attach(handle, 0, NULL, NULL))) return 0;
acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
acpi_bus_device_attach, NULL, NULL, NULL);
return error;
}
EXPORT_SYMBOL(acpi_bus_scan);
static acpi_status acpi_bus_device_detach(acpi_handle handle, u32 lvl_not_used,
void *not_used, void **ret_not_used)
{
struct acpi_device *device = NULL;
if (!acpi_bus_get_device(handle, &device)) {
struct acpi_scan_handler *dev_handler = device->handler;
if (dev_handler) {
if (dev_handler->detach)
dev_handler->detach(device);
device->handler = NULL;
} else {
device_release_driver(&device->dev);
}
/*
* Most likely, the device is going away, so put it into D3cold
* before that.
*/
acpi_device_set_power(device, ACPI_STATE_D3_COLD);
device->flags.initialized = false;
device->flags.visited = false;
} }
return AE_OK; return -ENODEV;
} }
EXPORT_SYMBOL(acpi_bus_scan);
/** /**
* acpi_bus_trim - Remove ACPI device node and all of its descendants * acpi_bus_trim - Detach scan handlers and drivers from ACPI device objects.
* @start: Root of the ACPI device nodes subtree to remove. * @adev: Root of the ACPI namespace scope to walk.
* *
* Must be called under acpi_scan_lock. * Must be called under acpi_scan_lock.
*/ */
void acpi_bus_trim(struct acpi_device *start) void acpi_bus_trim(struct acpi_device *adev)
{ {
struct acpi_scan_handler *handler = adev->handler;
struct acpi_device *child;
list_for_each_entry_reverse(child, &adev->children, node)
acpi_bus_trim(child);
if (handler) {
if (handler->detach)
handler->detach(adev);
adev->handler = NULL;
} else {
device_release_driver(&adev->dev);
}
/* /*
* Execute acpi_bus_device_detach() as a post-order callback to detach * Most likely, the device is going away, so put it into D3cold before
* all ACPI drivers from the device nodes being removed. * that.
*/ */
acpi_walk_namespace(ACPI_TYPE_ANY, start->handle, ACPI_UINT32_MAX, NULL, acpi_device_set_power(adev, ACPI_STATE_D3_COLD);
acpi_bus_device_detach, NULL, NULL); adev->flags.initialized = false;
acpi_bus_device_detach(start->handle, 0, NULL, NULL); adev->flags.visited = false;
} }
EXPORT_SYMBOL_GPL(acpi_bus_trim); EXPORT_SYMBOL_GPL(acpi_bus_trim);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment