From c56980744ed99994799850903627c4bbb5fed006 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 3 Mar 2013 23:05:14 +0100 Subject: ACPI / scan: Introduce acpi_scan_match_handler() Introduce helper routine acpi_scan_match_handler() that will find the ACPI scan handler matching a given device ID, if there is one, and rework acpi_scan_attach_handler() to use the new routine (that routine will also be useful for other purposes going forward). Signed-off-by: Rafael J. Wysocki Acked-by: Yasuaki Ishimatsu Acked-by: Toshi Kani Tested-by: Toshi Kani --- drivers/acpi/scan.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5e7e991717d7..cc1b0020478b 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1536,6 +1536,25 @@ static int acpi_bus_type_and_status(acpi_handle handle, int *type, return 0; } +static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, + const struct acpi_device_id **matchid) +{ + struct acpi_scan_handler *handler; + + list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) { + const struct acpi_device_id *devid; + + for (devid = handler->ids; devid->id[0]; devid++) + if (!strcmp((char *)devid->id, idstr)) { + if (matchid) + *matchid = devid; + + return handler; + } + } + return NULL; +} + static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, void *not_used, void **return_value) { @@ -1583,42 +1602,26 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, return AE_OK; } -static int acpi_scan_do_attach_handler(struct acpi_device *device, char *id) +static int acpi_scan_attach_handler(struct acpi_device *device) { - struct acpi_scan_handler *handler; + struct acpi_hardware_id *hwid; + int ret = 0; - list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) { + list_for_each_entry(hwid, &device->pnp.ids, list) { const struct acpi_device_id *devid; + struct acpi_scan_handler *handler; - for (devid = handler->ids; devid->id[0]; devid++) { - int ret; - - if (strcmp((char *)devid->id, id)) - continue; - + handler = acpi_scan_match_handler(hwid->id, &devid); + if (handler) { ret = handler->attach(device, devid); if (ret > 0) { device->handler = handler; - return ret; + break; } else if (ret < 0) { - return ret; + break; } } } - return 0; -} - -static int acpi_scan_attach_handler(struct acpi_device *device) -{ - struct acpi_hardware_id *hwid; - int ret = 0; - - list_for_each_entry(hwid, &device->pnp.ids, list) { - ret = acpi_scan_do_attach_handler(device, hwid->id); - if (ret) - break; - - } return ret; } -- cgit v1.2.3 From a33ec399e9fc266ba20f9b71d693aa63658bf2aa Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 3 Mar 2013 23:05:29 +0100 Subject: ACPI / scan: Introduce common code for ACPI-based device hotplug Multiple drivers handling hotplug-capable ACPI device nodes install notify handlers covering the same types of events in a very similar way. Moreover, those handlers are installed in separate namespace walks, although that really should be done during namespace scans carried out by acpi_bus_scan(). This leads to substantial code duplication, unnecessary overhead and behavior that is hard to follow. For this reason, introduce common code in drivers/acpi/scan.c for handling hotplug-related notification and carrying out device insertion and eject operations in a generic fashion, such that it may be used by all of the relevant drivers in the future. To cover the existing differences between those drivers introduce struct acpi_hotplug_profile for representing collections of hotplug settings associated with different ACPI scan handlers that can be used by the drivers to make the common code reflect their current behavior. Signed-off-by: Rafael J. Wysocki Acked-by: Toshi Kani Tested-by: Toshi Kani --- drivers/acpi/scan.c | 269 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 216 insertions(+), 53 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index cc1b0020478b..de73fdf89598 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -107,32 +107,19 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha } static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL); -/** - * acpi_bus_hot_remove_device: hot-remove a device and its children - * @context: struct acpi_eject_event pointer (freed in this func) - * - * Hot-remove a device and its children. This function frees up the - * memory space passed by arg context, so that the caller may call - * this function asynchronously through acpi_os_hotplug_execute(). - */ -void acpi_bus_hot_remove_device(void *context) +static int acpi_scan_hot_remove(struct acpi_device *device) { - struct acpi_eject_event *ej_event = context; - struct acpi_device *device = ej_event->device; acpi_handle handle = device->handle; - acpi_handle temp; + acpi_handle not_used; struct acpi_object_list arg_list; union acpi_object arg; - acpi_status status = AE_OK; - u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */ - - mutex_lock(&acpi_scan_lock); + acpi_status status; /* If there is no handle, the device node has been unregistered. */ - if (!device->handle) { + if (!handle) { dev_dbg(&device->dev, "ACPI handle missing\n"); put_device(&device->dev); - goto out; + return -EINVAL; } ACPI_DEBUG_PRINT((ACPI_DB_INFO, @@ -143,7 +130,7 @@ void acpi_bus_hot_remove_device(void *context) put_device(&device->dev); device = NULL; - if (ACPI_SUCCESS(acpi_get_handle(handle, "_LCK", &temp))) { + if (ACPI_SUCCESS(acpi_get_handle(handle, "_LCK", ¬_used))) { arg_list.count = 1; arg_list.pointer = &arg; arg.type = ACPI_TYPE_INTEGER; @@ -161,18 +148,158 @@ void acpi_bus_hot_remove_device(void *context) */ status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL); if (ACPI_FAILURE(status)) { - if (status != AE_NOT_FOUND) + if (status == AE_NOT_FOUND) { + return -ENODEV; + } else { acpi_handle_warn(handle, "Eject failed\n"); + return -EIO; + } + } + return 0; +} - /* Tell the firmware the hot-remove operation has failed. */ - acpi_evaluate_hotplug_ost(handle, ej_event->event, - ost_code, NULL); +static void acpi_bus_device_eject(void *context) +{ + acpi_handle handle = context; + struct acpi_device *device = NULL; + struct acpi_scan_handler *handler; + u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; + + mutex_lock(&acpi_scan_lock); + + acpi_bus_get_device(handle, &device); + if (!device) + goto err_out; + + handler = device->handler; + if (!handler || !handler->hotplug.enabled) { + ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED; + goto err_out; + } + acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, + ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); + if (handler->hotplug.mode == AHM_CONTAINER) { + device->flags.eject_pending = true; + kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); + } else { + int error; + + get_device(&device->dev); + error = acpi_scan_hot_remove(device); + if (error) + goto err_out; } out: mutex_unlock(&acpi_scan_lock); - kfree(context); return; + + err_out: + acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, ost_code, + NULL); + goto out; +} + +static void acpi_scan_bus_device_check(acpi_handle handle, u32 ost_source) +{ + struct acpi_device *device = NULL; + u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; + int error; + + mutex_lock(&acpi_scan_lock); + + acpi_bus_get_device(handle, &device); + if (device) { + dev_warn(&device->dev, "Attempt to re-insert\n"); + goto out; + } + acpi_evaluate_hotplug_ost(handle, ost_source, + ACPI_OST_SC_INSERT_IN_PROGRESS, NULL); + error = acpi_bus_scan(handle); + if (error) { + acpi_handle_warn(handle, "Namespace scan failure\n"); + goto out; + } + error = acpi_bus_get_device(handle, &device); + if (error) { + acpi_handle_warn(handle, "Missing device node object\n"); + goto out; + } + ost_code = ACPI_OST_SC_SUCCESS; + if (device->handler && device->handler->hotplug.mode == AHM_CONTAINER) + kobject_uevent(&device->dev.kobj, KOBJ_ONLINE); + + out: + acpi_evaluate_hotplug_ost(handle, ost_source, ost_code, NULL); + mutex_unlock(&acpi_scan_lock); +} + +static void acpi_scan_bus_check(void *context) +{ + acpi_scan_bus_device_check((acpi_handle)context, + ACPI_NOTIFY_BUS_CHECK); +} + +static void acpi_scan_device_check(void *context) +{ + acpi_scan_bus_device_check((acpi_handle)context, + ACPI_NOTIFY_DEVICE_CHECK); +} + +static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *not_used) +{ + acpi_osd_exec_callback callback; + acpi_status status; + + switch (type) { + case ACPI_NOTIFY_BUS_CHECK: + acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); + callback = acpi_scan_bus_check; + break; + case ACPI_NOTIFY_DEVICE_CHECK: + acpi_handle_debug(handle, "ACPI_NOTIFY_DEVICE_CHECK event\n"); + callback = acpi_scan_device_check; + break; + case ACPI_NOTIFY_EJECT_REQUEST: + acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); + callback = acpi_bus_device_eject; + break; + default: + /* non-hotplug event; possibly handled by other handler */ + return; + } + status = acpi_os_hotplug_execute(callback, handle); + if (ACPI_FAILURE(status)) + acpi_evaluate_hotplug_ost(handle, type, + ACPI_OST_SC_NON_SPECIFIC_FAILURE, + NULL); +} + +/** + * acpi_bus_hot_remove_device: hot-remove a device and its children + * @context: struct acpi_eject_event pointer (freed in this func) + * + * Hot-remove a device and its children. This function frees up the + * memory space passed by arg context, so that the caller may call + * this function asynchronously through acpi_os_hotplug_execute(). + */ +void acpi_bus_hot_remove_device(void *context) +{ + struct acpi_eject_event *ej_event = context; + struct acpi_device *device = ej_event->device; + acpi_handle handle = device->handle; + int error; + + mutex_lock(&acpi_scan_lock); + + error = acpi_scan_hot_remove(device); + if (error && handle) + acpi_evaluate_hotplug_ost(handle, ej_event->event, + ACPI_OST_SC_NON_SPECIFIC_FAILURE, + NULL); + + mutex_unlock(&acpi_scan_lock); + kfree(context); } EXPORT_SYMBOL(acpi_bus_hot_remove_device); @@ -206,51 +333,61 @@ static ssize_t acpi_eject_store(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { - int ret = count; - acpi_status status; - acpi_object_type type = 0; struct acpi_device *acpi_device = to_acpi_device(d); struct acpi_eject_event *ej_event; + acpi_object_type not_used; + acpi_status status; + u32 ost_source; + int ret; - if ((!count) || (buf[0] != '1')) { + if (!count || buf[0] != '1') return -EINVAL; - } - if (!acpi_device->driver && !acpi_device->handler) { - ret = -ENODEV; - goto err; - } - status = acpi_get_type(acpi_device->handle, &type); - if (ACPI_FAILURE(status) || (!acpi_device->flags.ejectable)) { - ret = -ENODEV; - goto err; - } - ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); - if (!ej_event) { - ret = -ENOMEM; - goto err; - } + if ((!acpi_device->handler || !acpi_device->handler->hotplug.enabled) + && !acpi_device->driver) + return -ENODEV; + + status = acpi_get_type(acpi_device->handle, ¬_used); + if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable) + return -ENODEV; + + mutex_lock(&acpi_scan_lock); - get_device(&acpi_device->dev); - ej_event->device = acpi_device; if (acpi_device->flags.eject_pending) { - /* event originated from ACPI eject notification */ - ej_event->event = ACPI_NOTIFY_EJECT_REQUEST; + /* ACPI eject notification event. */ + ost_source = ACPI_NOTIFY_EJECT_REQUEST; acpi_device->flags.eject_pending = 0; } else { - /* event originated from user */ - ej_event->event = ACPI_OST_EC_OSPM_EJECT; - (void) acpi_evaluate_hotplug_ost(acpi_device->handle, - ej_event->event, ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); + /* Eject initiated by user space. */ + ost_source = ACPI_OST_EC_OSPM_EJECT; } - + ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); + if (!ej_event) { + ret = -ENOMEM; + goto err_out; + } + acpi_evaluate_hotplug_ost(acpi_device->handle, ost_source, + ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); + ej_event->device = acpi_device; + ej_event->event = ost_source; + get_device(&acpi_device->dev); status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event); if (ACPI_FAILURE(status)) { put_device(&acpi_device->dev); kfree(ej_event); + ret = status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN; + goto err_out; } -err: + ret = count; + + out: + mutex_unlock(&acpi_scan_lock); return ret; + + err_out: + acpi_evaluate_hotplug_ost(acpi_device->handle, ost_source, + ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); + goto out; } static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); @@ -1555,6 +1692,30 @@ static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, return NULL; } +static void acpi_scan_init_hotplug(acpi_handle handle) +{ + struct acpi_device_info *info; + struct acpi_scan_handler *handler; + + if (ACPI_FAILURE(acpi_get_object_info(handle, &info))) + return; + + if (!(info->valid & ACPI_VALID_HID)) { + kfree(info); + return; + } + + /* + * This relies on the fact that acpi_install_notify_handler() will not + * install the same notify handler routine twice for the same handle. + */ + handler = acpi_scan_match_handler(info->hardware_id.string, NULL); + kfree(info); + if (handler && handler->hotplug.enabled) + acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb, NULL); +} + static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, void *not_used, void **return_value) { @@ -1577,6 +1738,8 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, return AE_OK; } + acpi_scan_init_hotplug(handle); + if (!(sta & ACPI_STA_DEVICE_PRESENT) && !(sta & ACPI_STA_DEVICE_FUNCTIONING)) { struct acpi_device_wakeup wakeup; -- cgit v1.2.3 From 4b59cc1fd6fd1dac1d4468b4f327ae9f59d1c0aa Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 3 Mar 2013 23:06:21 +0100 Subject: ACPI / scan: Introduce acpi_scan_handler_matching() Introduce new helper routine acpi_scan_handler_matching() for checking if the given ACPI scan handler matches a given device ID and rework acpi_scan_match_handler() to use the new routine (that routine will also be useful for other purposes in the future). Signed-off-by: Rafael J. Wysocki Acked-by: Yasuaki Ishimatsu Acked-by: Toshi Kani Tested-by: Toshi Kani --- drivers/acpi/scan.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index de73fdf89598..45fbe95ba1f3 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1673,22 +1673,32 @@ static int acpi_bus_type_and_status(acpi_handle handle, int *type, return 0; } +static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler, + char *idstr, + const struct acpi_device_id **matchid) +{ + const struct acpi_device_id *devid; + + for (devid = handler->ids; devid->id[0]; devid++) + if (!strcmp((char *)devid->id, idstr)) { + if (matchid) + *matchid = devid; + + return true; + } + + return false; +} + static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, const struct acpi_device_id **matchid) { struct acpi_scan_handler *handler; - list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) { - const struct acpi_device_id *devid; - - for (devid = handler->ids; devid->id[0]; devid++) - if (!strcmp((char *)devid->id, idstr)) { - if (matchid) - *matchid = devid; + list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) + if (acpi_scan_handler_matching(handler, idstr, matchid)) + return handler; - return handler; - } - } return NULL; } -- cgit v1.2.3 From 3f8055c3583640ed3e4c81864dd76e06a7faa505 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 3 Mar 2013 23:08:16 +0100 Subject: ACPI / hotplug: Introduce user space interface for hotplug profiles Introduce user space interface for manipulating hotplug profiles associated with ACPI scan handlers. The interface consists of sysfs directories under /sys/firmware/acpi/hotplug/, one for each hotplug profile, containing an attribute allowing user space to manipulate the enabled field of the corresponding profile. Namely, switching the enabled attribute from '0' to '1' will cause the common hotplug notify handler to be installed for all ACPI namespace objects representing devices matching the scan handler associated with the given hotplug profile (and analogously for the converse switch). Drivers willing to use the new user space interface should add their ACPI scan handlers with the help of new funtion acpi_scan_add_handler_with_hotplug(). Signed-off-by: Rafael J. Wysocki Acked-by: Toshi Kani Tested-by: Toshi Kani --- drivers/acpi/scan.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 45fbe95ba1f3..5458403c8249 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -63,6 +63,19 @@ int acpi_scan_add_handler(struct acpi_scan_handler *handler) return 0; } +int acpi_scan_add_handler_with_hotplug(struct acpi_scan_handler *handler, + const char *hotplug_profile_name) +{ + int error; + + error = acpi_scan_add_handler(handler); + if (error) + return error; + + acpi_sysfs_add_hotplug_profile(&handler->hotplug, hotplug_profile_name); + return 0; +} + /* * Creates hid/cid(s) string needed for modalias and uevent * e.g. on a device with hid:IBM0001 and cid:ACPI0001 you get: @@ -1690,6 +1703,52 @@ static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler, return false; } +static acpi_status acpi_scan_hotplug_modify(acpi_handle handle, + u32 lvl_not_used, void *data, + void **ret_not_used) +{ + struct acpi_scan_handler *handler = data; + struct acpi_device_info *info; + bool match = false; + + if (ACPI_FAILURE(acpi_get_object_info(handle, &info))) + return AE_OK; + + if (info->valid & ACPI_VALID_HID) { + char *idstr = info->hardware_id.string; + match = acpi_scan_handler_matching(handler, idstr, NULL); + } + kfree(info); + if (!match) + return AE_OK; + + if (handler->hotplug.enabled) + acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb, NULL); + else + acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb); + + return AE_OK; +} + +void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val) +{ + struct acpi_scan_handler *handler; + + if (!!hotplug->enabled == !!val) + return; + + mutex_lock(&acpi_scan_lock); + + hotplug->enabled = val; + handler = container_of(hotplug, struct acpi_scan_handler, hotplug); + acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, + acpi_scan_hotplug_modify, NULL, handler, NULL); + + mutex_unlock(&acpi_scan_lock); +} + static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, const struct acpi_device_id **matchid) { -- cgit v1.2.3 From 0a34764411aaab0114aa3f3656fda33a69a46d10 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Sun, 3 Mar 2013 23:18:03 +0100 Subject: ACPI / scan: Make memory hotplug driver use struct acpi_scan_handler Make the ACPI memory hotplug driver use struct acpi_scan_handler for representing the object used to set up ACPI memory hotplug functionality and to remove hotplug memory ranges and data structures used by the driver before unregistering ACPI device nodes representing memory. Register the new struct acpi_scan_handler object with the help of acpi_scan_add_handler_with_hotplug() to allow user space to manipulate the attributes of the memory hotplug profile. This results in a significant reduction of the drvier's code size and removes some ACPI hotplug code duplication. Signed-off-by: Rafael J. Wysocki Acked-by: Toshi Kani Tested-by: Toshi Kani --- drivers/acpi/scan.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5458403c8249..d69d77ab9c7e 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -2026,6 +2026,7 @@ int __init acpi_scan_init(void) acpi_csrt_init(); acpi_container_init(); acpi_pci_slot_init(); + acpi_memory_hotplug_init(); mutex_lock(&acpi_scan_lock); /* -- cgit v1.2.3 From f58b082aed43400c03e53beacc50a9f9eb23ac91 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 6 Mar 2013 23:46:20 +0100 Subject: ACPI / scan: Add special handler for Intel Lynxpoint LPSS devices Devices on the Intel Lynxpoint Low Power Subsystem (LPSS) have some common features that aren't shared with any other platform devices, including the clock and LTR (Latency Tolerance Reporting) registers. It is better to handle those features in common code than to bother device drivers with doing that (I/O functionality-wise the LPSS devices are generally compatible with other devices that don't have those special registers and may be handled by the same drivers). The clock registers of the LPSS devices are now taken care of by the special clk-x86-lpss driver, but the MMIO mappings used for accessing those registers can also be used for accessing the LTR registers on those devices (LTR support for the Lynxpoint LPSS is going to be added by a subsequent patch). Thus it is convenient to add a special ACPI scan handler for the Lynxpoint LPSS devices that will create the MMIO mappings for accessing the clock (and LTR in the future) registers and will register the LPSS devices' clocks, so the clk-x86-lpss driver will only need to take care of the main Lynxpoint LPSS clock. Introduce a special ACPI scan handler for Intel Lynxpoint LPSS devices as described above. This also reduces overhead related to browsing the ACPI namespace in search of the LPSS devices before the registration of their clocks, removes some LPSS-specific (and somewhat ugly) code from acpi_platform.c and shrinks the overall code size slightly. Signed-off-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki Acked-by: Mike Turquette --- drivers/acpi/scan.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 5e7e991717d7..433a4e15019c 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1788,6 +1788,7 @@ int __init acpi_scan_init(void) acpi_pci_root_init(); acpi_pci_link_init(); acpi_platform_init(); + acpi_lpss_init(); acpi_csrt_init(); acpi_container_init(); acpi_pci_slot_init(); -- cgit v1.2.3 From d4e1a692e9e85f9cbee090ea8d6158b133d32157 Mon Sep 17 00:00:00 2001 From: Toshi Kani Date: Mon, 4 Mar 2013 21:30:41 +0000 Subject: ACPI: Remove acpi_device dependency in acpi_device_set_id() This patch updates the internal operations of acpi_device_set_id() to setup acpi_device_pnp without using acpi_device. There is no functional change to acpi_device_set_id() in this patch. acpi_pnp_type is added to acpi_device_pnp, so that PNPID type is self-contained within acpi_device_pnp. acpi_add_id(), acpi_bay_match(), acpi_dock_match(), acpi_ibm_smbus_match() and acpi_is_video_device() are changed to take acpi_handle as an argument, instead of acpi_device. Signed-off-by: Toshi Kani Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 69 ++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index d69d77ab9c7e..f9c698d766f1 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -526,7 +526,7 @@ static int acpi_device_setup_files(struct acpi_device *dev) goto end; } - if (dev->flags.bus_address) + if (dev->pnp.type.bus_address) result = device_create_file(&dev->dev, &dev_attr_adr); if (dev->pnp.unique_id) result = device_create_file(&dev->dev, &dev_attr_uid); @@ -599,7 +599,7 @@ static void acpi_device_remove_files(struct acpi_device *dev) if (dev->pnp.unique_id) device_remove_file(&dev->dev, &dev_attr_uid); - if (dev->flags.bus_address) + if (dev->pnp.type.bus_address) device_remove_file(&dev->dev, &dev_attr_adr); device_remove_file(&dev->dev, &dev_attr_modalias); device_remove_file(&dev->dev, &dev_attr_hid); @@ -1406,19 +1406,17 @@ static void acpi_device_get_busid(struct acpi_device *device) } /* - * acpi_bay_match - see if a device is an ejectable driver bay + * acpi_bay_match - see if an acpi object is an ejectable driver bay * * If an acpi object is ejectable and has one of the ACPI ATA methods defined, * then we can safely call it an ejectable drive bay */ -static int acpi_bay_match(struct acpi_device *device){ +static int acpi_bay_match(acpi_handle handle) +{ acpi_status status; - acpi_handle handle; acpi_handle tmp; acpi_handle phandle; - handle = device->handle; - status = acpi_get_handle(handle, "_EJ0", &tmp); if (ACPI_FAILURE(status)) return -ENODEV; @@ -1442,12 +1440,12 @@ static int acpi_bay_match(struct acpi_device *device){ } /* - * acpi_dock_match - see if a device has a _DCK method + * acpi_dock_match - see if an acpi object has a _DCK method */ -static int acpi_dock_match(struct acpi_device *device) +static int acpi_dock_match(acpi_handle handle) { acpi_handle tmp; - return acpi_get_handle(device->handle, "_DCK", &tmp); + return acpi_get_handle(handle, "_DCK", &tmp); } const char *acpi_device_hid(struct acpi_device *device) @@ -1462,7 +1460,7 @@ const char *acpi_device_hid(struct acpi_device *device) } EXPORT_SYMBOL(acpi_device_hid); -static void acpi_add_id(struct acpi_device *device, const char *dev_id) +static void acpi_add_id(struct acpi_device_pnp *pnp, const char *dev_id) { struct acpi_hardware_id *id; @@ -1476,7 +1474,8 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id) return; } - list_add_tail(&id->list, &device->pnp.ids); + list_add_tail(&id->list, &pnp->ids); + pnp->type.hardware_id = 1; } /* @@ -1484,7 +1483,7 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id) * lacks the SMBUS01 HID and the methods do not have the necessary "_" * prefix. Work around this. */ -static int acpi_ibm_smbus_match(struct acpi_device *device) +static int acpi_ibm_smbus_match(acpi_handle handle) { acpi_handle h_dummy; struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL}; @@ -1494,7 +1493,7 @@ static int acpi_ibm_smbus_match(struct acpi_device *device) return -ENODEV; /* Look for SMBS object */ - result = acpi_get_name(device->handle, ACPI_SINGLE_NAME, &path); + result = acpi_get_name(handle, ACPI_SINGLE_NAME, &path); if (result) return result; @@ -1505,9 +1504,9 @@ static int acpi_ibm_smbus_match(struct acpi_device *device) /* Does it have the necessary (but misnamed) methods? */ result = -ENODEV; - if (ACPI_SUCCESS(acpi_get_handle(device->handle, "SBI", &h_dummy)) && - ACPI_SUCCESS(acpi_get_handle(device->handle, "SBR", &h_dummy)) && - ACPI_SUCCESS(acpi_get_handle(device->handle, "SBW", &h_dummy))) + if (ACPI_SUCCESS(acpi_get_handle(handle, "SBI", &h_dummy)) && + ACPI_SUCCESS(acpi_get_handle(handle, "SBR", &h_dummy)) && + ACPI_SUCCESS(acpi_get_handle(handle, "SBW", &h_dummy))) result = 0; out: kfree(path.pointer); @@ -1524,7 +1523,7 @@ static void acpi_device_set_id(struct acpi_device *device) switch (device->device_type) { case ACPI_BUS_TYPE_DEVICE: if (ACPI_IS_ROOT_DEVICE(device)) { - acpi_add_id(device, ACPI_SYSTEM_HID); + acpi_add_id(&device->pnp, ACPI_SYSTEM_HID); break; } @@ -1535,15 +1534,15 @@ static void acpi_device_set_id(struct acpi_device *device) } if (info->valid & ACPI_VALID_HID) - acpi_add_id(device, info->hardware_id.string); + acpi_add_id(&device->pnp, info->hardware_id.string); if (info->valid & ACPI_VALID_CID) { cid_list = &info->compatible_id_list; for (i = 0; i < cid_list->count; i++) - acpi_add_id(device, cid_list->ids[i].string); + acpi_add_id(&device->pnp, cid_list->ids[i].string); } if (info->valid & ACPI_VALID_ADR) { device->pnp.bus_address = info->address; - device->flags.bus_address = 1; + device->pnp.type.bus_address = 1; } if (info->valid & ACPI_VALID_UID) device->pnp.unique_id = kstrdup(info->unique_id.string, @@ -1555,36 +1554,36 @@ static void acpi_device_set_id(struct acpi_device *device) * Some devices don't reliably have _HIDs & _CIDs, so add * synthetic HIDs to make sure drivers can find them. */ - if (acpi_is_video_device(device)) - acpi_add_id(device, ACPI_VIDEO_HID); - else if (ACPI_SUCCESS(acpi_bay_match(device))) - acpi_add_id(device, ACPI_BAY_HID); - else if (ACPI_SUCCESS(acpi_dock_match(device))) - acpi_add_id(device, ACPI_DOCK_HID); - else if (!acpi_ibm_smbus_match(device)) - acpi_add_id(device, ACPI_SMBUS_IBM_HID); + if (acpi_is_video_device(device->handle)) + acpi_add_id(&device->pnp, ACPI_VIDEO_HID); + else if (ACPI_SUCCESS(acpi_bay_match(device->handle))) + acpi_add_id(&device->pnp, ACPI_BAY_HID); + else if (ACPI_SUCCESS(acpi_dock_match(device->handle))) + acpi_add_id(&device->pnp, ACPI_DOCK_HID); + else if (!acpi_ibm_smbus_match(device->handle)) + acpi_add_id(&device->pnp, ACPI_SMBUS_IBM_HID); else if (list_empty(&device->pnp.ids) && ACPI_IS_ROOT_DEVICE(device->parent)) { - acpi_add_id(device, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ + acpi_add_id(&device->pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME); strcpy(device->pnp.device_class, ACPI_BUS_CLASS); } break; case ACPI_BUS_TYPE_POWER: - acpi_add_id(device, ACPI_POWER_HID); + acpi_add_id(&device->pnp, ACPI_POWER_HID); break; case ACPI_BUS_TYPE_PROCESSOR: - acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID); + acpi_add_id(&device->pnp, ACPI_PROCESSOR_OBJECT_HID); break; case ACPI_BUS_TYPE_THERMAL: - acpi_add_id(device, ACPI_THERMAL_HID); + acpi_add_id(&device->pnp, ACPI_THERMAL_HID); break; case ACPI_BUS_TYPE_POWER_BUTTON: - acpi_add_id(device, ACPI_BUTTON_HID_POWERF); + acpi_add_id(&device->pnp, ACPI_BUTTON_HID_POWERF); break; case ACPI_BUS_TYPE_SLEEP_BUTTON: - acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF); + acpi_add_id(&device->pnp, ACPI_BUTTON_HID_SLEEPF); break; } } -- cgit v1.2.3 From c0af41757f406651cdd32de3e915753746c2948a Mon Sep 17 00:00:00 2001 From: Toshi Kani Date: Mon, 4 Mar 2013 21:30:42 +0000 Subject: ACPI: Update PNPID set/free interfaces This patch introduces acpi_set_pnp_ids() and acpi_free_pnp_ids(), which are updated from acpi_device_set_id() and acpi_free_ids(), to setup and free acpi_device_pnp for a given acpi_handle. They can be called without acpi_device. Signed-off-by: Toshi Kani Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 85 +++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index f9c698d766f1..e9a71ed9954a 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -662,17 +662,6 @@ int acpi_match_device_ids(struct acpi_device *device, } EXPORT_SYMBOL(acpi_match_device_ids); -void acpi_free_ids(struct acpi_device *device) -{ - struct acpi_hardware_id *id, *tmp; - - list_for_each_entry_safe(id, tmp, &device->pnp.ids, list) { - kfree(id->id); - kfree(id); - } - kfree(device->pnp.unique_id); -} - static void acpi_free_power_resources_lists(struct acpi_device *device) { int i; @@ -693,7 +682,7 @@ static void acpi_device_release(struct device *dev) { struct acpi_device *acpi_dev = to_acpi_device(dev); - acpi_free_ids(acpi_dev); + acpi_free_pnp_ids(&acpi_dev->pnp); acpi_free_power_resources_lists(acpi_dev); kfree(acpi_dev); } @@ -1513,39 +1502,41 @@ out: return result; } -static void acpi_device_set_id(struct acpi_device *device) +static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp, + int device_type) { acpi_status status; struct acpi_device_info *info; struct acpi_pnp_device_id_list *cid_list; int i; - switch (device->device_type) { + switch (device_type) { case ACPI_BUS_TYPE_DEVICE: - if (ACPI_IS_ROOT_DEVICE(device)) { - acpi_add_id(&device->pnp, ACPI_SYSTEM_HID); + if (handle == ACPI_ROOT_OBJECT) { + acpi_add_id(pnp, ACPI_SYSTEM_HID); break; } - status = acpi_get_object_info(device->handle, &info); + status = acpi_get_object_info(handle, &info); if (ACPI_FAILURE(status)) { - printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__); + pr_err(PREFIX "%s: Error reading device info\n", + __func__); return; } if (info->valid & ACPI_VALID_HID) - acpi_add_id(&device->pnp, info->hardware_id.string); + acpi_add_id(pnp, info->hardware_id.string); if (info->valid & ACPI_VALID_CID) { cid_list = &info->compatible_id_list; for (i = 0; i < cid_list->count; i++) - acpi_add_id(&device->pnp, cid_list->ids[i].string); + acpi_add_id(pnp, cid_list->ids[i].string); } if (info->valid & ACPI_VALID_ADR) { - device->pnp.bus_address = info->address; - device->pnp.type.bus_address = 1; + pnp->bus_address = info->address; + pnp->type.bus_address = 1; } if (info->valid & ACPI_VALID_UID) - device->pnp.unique_id = kstrdup(info->unique_id.string, + pnp->unique_id = kstrdup(info->unique_id.string, GFP_KERNEL); kfree(info); @@ -1554,40 +1545,50 @@ static void acpi_device_set_id(struct acpi_device *device) * Some devices don't reliably have _HIDs & _CIDs, so add * synthetic HIDs to make sure drivers can find them. */ - if (acpi_is_video_device(device->handle)) - acpi_add_id(&device->pnp, ACPI_VIDEO_HID); - else if (ACPI_SUCCESS(acpi_bay_match(device->handle))) - acpi_add_id(&device->pnp, ACPI_BAY_HID); - else if (ACPI_SUCCESS(acpi_dock_match(device->handle))) - acpi_add_id(&device->pnp, ACPI_DOCK_HID); - else if (!acpi_ibm_smbus_match(device->handle)) - acpi_add_id(&device->pnp, ACPI_SMBUS_IBM_HID); - else if (list_empty(&device->pnp.ids) && - ACPI_IS_ROOT_DEVICE(device->parent)) { - acpi_add_id(&device->pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ - strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME); - strcpy(device->pnp.device_class, ACPI_BUS_CLASS); + if (acpi_is_video_device(handle)) + acpi_add_id(pnp, ACPI_VIDEO_HID); + else if (ACPI_SUCCESS(acpi_bay_match(handle))) + acpi_add_id(pnp, ACPI_BAY_HID); + else if (ACPI_SUCCESS(acpi_dock_match(handle))) + acpi_add_id(pnp, ACPI_DOCK_HID); + else if (!acpi_ibm_smbus_match(handle)) + acpi_add_id(pnp, ACPI_SMBUS_IBM_HID); + else if (list_empty(&pnp->ids) && handle == ACPI_ROOT_OBJECT) { + acpi_add_id(pnp, ACPI_BUS_HID); /* \_SB, LNXSYBUS */ + strcpy(pnp->device_name, ACPI_BUS_DEVICE_NAME); + strcpy(pnp->device_class, ACPI_BUS_CLASS); } break; case ACPI_BUS_TYPE_POWER: - acpi_add_id(&device->pnp, ACPI_POWER_HID); + acpi_add_id(pnp, ACPI_POWER_HID); break; case ACPI_BUS_TYPE_PROCESSOR: - acpi_add_id(&device->pnp, ACPI_PROCESSOR_OBJECT_HID); + acpi_add_id(pnp, ACPI_PROCESSOR_OBJECT_HID); break; case ACPI_BUS_TYPE_THERMAL: - acpi_add_id(&device->pnp, ACPI_THERMAL_HID); + acpi_add_id(pnp, ACPI_THERMAL_HID); break; case ACPI_BUS_TYPE_POWER_BUTTON: - acpi_add_id(&device->pnp, ACPI_BUTTON_HID_POWERF); + acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF); break; case ACPI_BUS_TYPE_SLEEP_BUTTON: - acpi_add_id(&device->pnp, ACPI_BUTTON_HID_SLEEPF); + acpi_add_id(pnp, ACPI_BUTTON_HID_SLEEPF); break; } } +void acpi_free_pnp_ids(struct acpi_device_pnp *pnp) +{ + struct acpi_hardware_id *id, *tmp; + + list_for_each_entry_safe(id, tmp, &pnp->ids, list) { + kfree(id->id); + kfree(id); + } + kfree(pnp->unique_id); +} + void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, int type, unsigned long long sta) { @@ -1597,7 +1598,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle, device->parent = acpi_bus_get_parent(handle); STRUCT_TO_INT(device->status) = sta; acpi_device_get_busid(device); - acpi_device_set_id(device); + acpi_set_pnp_ids(handle, &device->pnp, type); acpi_bus_get_flags(device); device->flags.match_driver = false; device_initialize(&device->dev); -- cgit v1.2.3 From 6b772e8f9e9deb3528402ac14fd0aa186d84ae75 Mon Sep 17 00:00:00 2001 From: Toshi Kani Date: Mon, 4 Mar 2013 21:30:43 +0000 Subject: ACPI: Update PNPID match handling for notify When installing/removing a notify handler to/from an ACPI device object, ACPI core tries to match its associated scan handler to see if it supports hotplug. However, the matching logic of the notify handler is different from the matching logic of attaching a scan handler to an ACPI device object. This patch updates the matching logic of the notify handlers to be consistent with the attach handling. Signed-off-by: Toshi Kani Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 85 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 33 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index e9a71ed9954a..3f6ec0dd4fb6 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1703,24 +1703,47 @@ static bool acpi_scan_handler_matching(struct acpi_scan_handler *handler, return false; } +static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, + const struct acpi_device_id **matchid) +{ + struct acpi_scan_handler *handler; + + list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) + if (acpi_scan_handler_matching(handler, idstr, matchid)) + return handler; + + return NULL; +} + static acpi_status acpi_scan_hotplug_modify(acpi_handle handle, u32 lvl_not_used, void *data, void **ret_not_used) { - struct acpi_scan_handler *handler = data; - struct acpi_device_info *info; + struct acpi_device_pnp pnp = {}; + struct acpi_scan_handler *tgt_handler = data, *handler; + struct acpi_hardware_id *hwid; + unsigned long long sta_not_used; + int type; bool match = false; - if (ACPI_FAILURE(acpi_get_object_info(handle, &info))) + if (acpi_bus_type_and_status(handle, &type, &sta_not_used)) + return AE_OK; + + INIT_LIST_HEAD(&pnp.ids); + acpi_set_pnp_ids(handle, &pnp, type); + + if (!pnp.type.hardware_id) return AE_OK; - if (info->valid & ACPI_VALID_HID) { - char *idstr = info->hardware_id.string; - match = acpi_scan_handler_matching(handler, idstr, NULL); + list_for_each_entry(hwid, &pnp.ids, list) { + handler = acpi_scan_match_handler(hwid->id, NULL); + if (handler && handler == tgt_handler) { + match = true; + break; + } } - kfree(info); if (!match) - return AE_OK; + goto out; if (handler->hotplug.enabled) acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, @@ -1729,6 +1752,8 @@ static acpi_status acpi_scan_hotplug_modify(acpi_handle handle, acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, acpi_hotplug_notify_cb); +out: + acpi_free_pnp_ids(&pnp); return AE_OK; } @@ -1749,40 +1774,34 @@ void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val) mutex_unlock(&acpi_scan_lock); } -static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, - const struct acpi_device_id **matchid) -{ - struct acpi_scan_handler *handler; - - list_for_each_entry(handler, &acpi_scan_handlers_list, list_node) - if (acpi_scan_handler_matching(handler, idstr, matchid)) - return handler; - - return NULL; -} - -static void acpi_scan_init_hotplug(acpi_handle handle) +static void acpi_scan_init_hotplug(acpi_handle handle, int type) { - struct acpi_device_info *info; + struct acpi_device_pnp pnp = {}; + struct acpi_hardware_id *hwid; struct acpi_scan_handler *handler; - if (ACPI_FAILURE(acpi_get_object_info(handle, &info))) - return; + INIT_LIST_HEAD(&pnp.ids); + acpi_set_pnp_ids(handle, &pnp, type); - if (!(info->valid & ACPI_VALID_HID)) { - kfree(info); + if (!pnp.type.hardware_id) return; - } /* * This relies on the fact that acpi_install_notify_handler() will not * install the same notify handler routine twice for the same handle. */ - handler = acpi_scan_match_handler(info->hardware_id.string, NULL); - kfree(info); - if (handler && handler->hotplug.enabled) - acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb, NULL); + list_for_each_entry(hwid, &pnp.ids, list) { + handler = acpi_scan_match_handler(hwid->id, NULL); + if (handler) { + if (handler->hotplug.enabled) + acpi_install_notify_handler(handle, + ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb, NULL); + break; + } + } + + acpi_free_pnp_ids(&pnp); } static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, @@ -1807,7 +1826,7 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used, return AE_OK; } - acpi_scan_init_hotplug(handle); + acpi_scan_init_hotplug(handle, type); if (!(sta & ACPI_STA_DEVICE_PRESENT) && !(sta & ACPI_STA_DEVICE_FUNCTIONING)) { -- cgit v1.2.3 From 2cbb14fb7065b0cc08ef03ee69dce93d65197c29 Mon Sep 17 00:00:00 2001 From: Toshi Kani Date: Tue, 5 Mar 2013 22:33:31 +0000 Subject: ACPI: Update _OST handling for notify When the kernel calls _OSC with OSC_SB_HOTPLUG_OST_SUPPORT bit set at boot-time, the OS is responsible for calling _OST for ACPI hotplug events. However, when hotplug.enabled attribute is unset for ACPI scan drivers, their notify handlers are removed and _OST is not called for ACPI hotplug events as a result. This patch keeps the notify handler of ACPI scan drivers, acpi_hotplug_notify_cb(), installed regardless of the state of hotplug.enabled. The notify handler then checks if hotplug.enabled is set for the associated scan handler. If unset, the notify handler calls _OST with a proper error code. The patch also eliminates ACPI namespace walk when hotplug.enabled is changed via sysfs. Signed-off-by: Toshi Kani Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 87 +++++++++++++++++++++-------------------------------- 1 file changed, 35 insertions(+), 52 deletions(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 3f6ec0dd4fb6..dfdbcfdd9def 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -259,11 +259,43 @@ static void acpi_scan_device_check(void *context) ACPI_NOTIFY_DEVICE_CHECK); } -static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *not_used) +static void acpi_hotplug_unsupported(acpi_handle handle, u32 type) +{ + u32 ost_status; + + switch (type) { + case ACPI_NOTIFY_BUS_CHECK: + acpi_handle_debug(handle, + "ACPI_NOTIFY_BUS_CHECK event: unsupported\n"); + ost_status = ACPI_OST_SC_INSERT_NOT_SUPPORTED; + break; + case ACPI_NOTIFY_DEVICE_CHECK: + acpi_handle_debug(handle, + "ACPI_NOTIFY_DEVICE_CHECK event: unsupported\n"); + ost_status = ACPI_OST_SC_INSERT_NOT_SUPPORTED; + break; + case ACPI_NOTIFY_EJECT_REQUEST: + acpi_handle_debug(handle, + "ACPI_NOTIFY_EJECT_REQUEST event: unsupported\n"); + ost_status = ACPI_OST_SC_EJECT_NOT_SUPPORTED; + break; + default: + /* non-hotplug event; possibly handled by other handler */ + return; + } + + acpi_evaluate_hotplug_ost(handle, type, ost_status, NULL); +} + +static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) { acpi_osd_exec_callback callback; + struct acpi_scan_handler *handler = data; acpi_status status; + if (!handler->hotplug.enabled) + return acpi_hotplug_unsupported(handle, type); + switch (type) { case ACPI_NOTIFY_BUS_CHECK: acpi_handle_debug(handle, "ACPI_NOTIFY_BUS_CHECK event\n"); @@ -1715,61 +1747,14 @@ static struct acpi_scan_handler *acpi_scan_match_handler(char *idstr, return NULL; } -static acpi_status acpi_scan_hotplug_modify(acpi_handle handle, - u32 lvl_not_used, void *data, - void **ret_not_used) -{ - struct acpi_device_pnp pnp = {}; - struct acpi_scan_handler *tgt_handler = data, *handler; - struct acpi_hardware_id *hwid; - unsigned long long sta_not_used; - int type; - bool match = false; - - if (acpi_bus_type_and_status(handle, &type, &sta_not_used)) - return AE_OK; - - INIT_LIST_HEAD(&pnp.ids); - acpi_set_pnp_ids(handle, &pnp, type); - - if (!pnp.type.hardware_id) - return AE_OK; - - list_for_each_entry(hwid, &pnp.ids, list) { - handler = acpi_scan_match_handler(hwid->id, NULL); - if (handler && handler == tgt_handler) { - match = true; - break; - } - } - if (!match) - goto out; - - if (handler->hotplug.enabled) - acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb, NULL); - else - acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb); - -out: - acpi_free_pnp_ids(&pnp); - return AE_OK; -} - void acpi_scan_hotplug_enabled(struct acpi_hotplug_profile *hotplug, bool val) { - struct acpi_scan_handler *handler; - if (!!hotplug->enabled == !!val) return; mutex_lock(&acpi_scan_lock); hotplug->enabled = val; - handler = container_of(hotplug, struct acpi_scan_handler, hotplug); - acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, - acpi_scan_hotplug_modify, NULL, handler, NULL); mutex_unlock(&acpi_scan_lock); } @@ -1793,10 +1778,8 @@ static void acpi_scan_init_hotplug(acpi_handle handle, int type) list_for_each_entry(hwid, &pnp.ids, list) { handler = acpi_scan_match_handler(hwid->id, NULL); if (handler) { - if (handler->hotplug.enabled) - acpi_install_notify_handler(handle, - ACPI_SYSTEM_NOTIFY, - acpi_hotplug_notify_cb, NULL); + acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY, + acpi_hotplug_notify_cb, handler); break; } } -- cgit v1.2.3 From 882fd12e641b612bcf31620f9b1b7bb03f8e9ab5 Mon Sep 17 00:00:00 2001 From: Toshi Kani Date: Wed, 13 Mar 2013 19:29:26 +0000 Subject: ACPI: Verify device status after eject ACPI spec states that the OS evaluates _STA after calling _EJ0 in order to verify if eject was successful. Added a check to verify if the enabled bit of the status value is cleared after _EJ0. Note, the present bit is not checked since some FW implementations do not clear the present bit until the hardware is physically removed. Signed-off-by: Toshi Kani Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'drivers/acpi/scan.c') diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index dfdbcfdd9def..8cacc16af6e7 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -127,6 +127,7 @@ static int acpi_scan_hot_remove(struct acpi_device *device) struct acpi_object_list arg_list; union acpi_object arg; acpi_status status; + unsigned long long sta; /* If there is no handle, the device node has been unregistered. */ if (!handle) { @@ -164,10 +165,25 @@ static int acpi_scan_hot_remove(struct acpi_device *device) if (status == AE_NOT_FOUND) { return -ENODEV; } else { - acpi_handle_warn(handle, "Eject failed\n"); + acpi_handle_warn(handle, "Eject failed (0x%x)\n", + status); return -EIO; } } + + /* + * Verify if eject was indeed successful. If not, log an error + * message. No need to call _OST since _EJ0 call was made OK. + */ + status = acpi_evaluate_integer(handle, "_STA", NULL, &sta); + if (ACPI_FAILURE(status)) { + acpi_handle_warn(handle, + "Status check after eject failed (0x%x)\n", status); + } else if (sta & ACPI_STA_DEVICE_ENABLED) { + acpi_handle_warn(handle, + "Eject incomplete - status 0x%llx\n", sta); + } + return 0; } -- cgit v1.2.3