--- zzzz-none-000/linux-3.10.107/drivers/pnp/pnpacpi/core.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/pnp/pnpacpi/core.c 2021-02-04 17:41:59.000000000 +0000 @@ -24,33 +24,12 @@ #include #include #include -#include #include "../base.h" #include "pnpacpi.h" static int num; -/* We need only to blacklist devices that have already an acpi driver that - * can't use pnp layer. We don't need to blacklist device that are directly - * used by the kernel (PCI root, ...), as it is harmless and there were - * already present in pnpbios. But there is an exception for devices that - * have irqs (PIC, Timer) because we call acpi_register_gsi. - * Finally, only devices that have a CRS method need to be in this list. - */ -static struct acpi_device_id excluded_id_list[] __initdata = { - {"PNP0C09", 0}, /* EC */ - {"PNP0C0F", 0}, /* Link device */ - {"PNP0000", 0}, /* PIC */ - {"PNP0100", 0}, /* Timer */ - {"", 0}, -}; - -static inline int __init is_exclusive_device(struct acpi_device *dev) -{ - return (!acpi_match_device_ids(dev, excluded_id_list)); -} - /* * Compatible Device IDs */ @@ -84,13 +63,12 @@ { struct acpi_device *acpi_dev; acpi_handle handle; - struct acpi_buffer buffer; - int ret; + int ret = 0; pnp_dbg(&dev->dev, "set resources\n"); - handle = DEVICE_ACPI_HANDLE(&dev->dev); - if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { + acpi_dev = ACPI_COMPANION(&dev->dev); + if (!acpi_dev) { dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); return -ENODEV; } @@ -98,69 +76,74 @@ if (WARN_ON_ONCE(acpi_dev != dev->data)) dev->data = acpi_dev; - ret = pnpacpi_build_resource_template(dev, &buffer); - if (ret) - return ret; - ret = pnpacpi_encode_resources(dev, &buffer); - if (ret) { + handle = acpi_dev->handle; + if (acpi_has_method(handle, METHOD_NAME__SRS)) { + struct acpi_buffer buffer; + + ret = pnpacpi_build_resource_template(dev, &buffer); + if (ret) + return ret; + + ret = pnpacpi_encode_resources(dev, &buffer); + if (!ret) { + acpi_status status; + + status = acpi_set_current_resources(handle, &buffer); + if (ACPI_FAILURE(status)) + ret = -EIO; + } kfree(buffer.pointer); - return ret; } - if (ACPI_FAILURE(acpi_set_current_resources(handle, &buffer))) - ret = -EINVAL; - else if (acpi_bus_power_manageable(handle)) - ret = acpi_bus_set_power(handle, ACPI_STATE_D0); - kfree(buffer.pointer); + if (!ret && acpi_device_power_manageable(acpi_dev)) + ret = acpi_device_set_power(acpi_dev, ACPI_STATE_D0); + return ret; } static int pnpacpi_disable_resources(struct pnp_dev *dev) { struct acpi_device *acpi_dev; - acpi_handle handle; - int ret; + acpi_status status; dev_dbg(&dev->dev, "disable resources\n"); - handle = DEVICE_ACPI_HANDLE(&dev->dev); - if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { + acpi_dev = ACPI_COMPANION(&dev->dev); + if (!acpi_dev) { dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); return 0; } /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ - ret = 0; - if (acpi_bus_power_manageable(handle)) - acpi_bus_set_power(handle, ACPI_STATE_D3); - /* continue even if acpi_bus_set_power() fails */ - if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DIS", NULL, NULL))) - ret = -ENODEV; - return ret; + if (acpi_device_power_manageable(acpi_dev)) + acpi_device_set_power(acpi_dev, ACPI_STATE_D3_COLD); + + /* continue even if acpi_device_set_power() fails */ + status = acpi_evaluate_object(acpi_dev->handle, "_DIS", NULL, NULL); + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) + return -ENODEV; + + return 0; } #ifdef CONFIG_ACPI_SLEEP static bool pnpacpi_can_wakeup(struct pnp_dev *dev) { - struct acpi_device *acpi_dev; - acpi_handle handle; + struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); - handle = DEVICE_ACPI_HANDLE(&dev->dev); - if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { + if (!acpi_dev) { dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); return false; } - return acpi_bus_can_wakeup(handle); + return acpi_bus_can_wakeup(acpi_dev->handle); } static int pnpacpi_suspend(struct pnp_dev *dev, pm_message_t state) { - struct acpi_device *acpi_dev; - acpi_handle handle; + struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); int error = 0; - handle = DEVICE_ACPI_HANDLE(&dev->dev); - if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { + if (!acpi_dev) { dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); return 0; } @@ -172,20 +155,20 @@ return error; } - if (acpi_bus_power_manageable(handle)) { + if (acpi_device_power_manageable(acpi_dev)) { int power_state = acpi_pm_device_sleep_state(&dev->dev, NULL, - ACPI_STATE_D3); + ACPI_STATE_D3_COLD); if (power_state < 0) power_state = (state.event == PM_EVENT_ON) ? - ACPI_STATE_D0 : ACPI_STATE_D3; + ACPI_STATE_D0 : ACPI_STATE_D3_COLD; /* - * acpi_bus_set_power() often fails (keyboard port can't be + * acpi_device_set_power() can fail (keyboard port can't be * powered-down?), and in any case, our return value is ignored * by pnp_bus_suspend(). Hence we don't revert the wakeup * setting if the set_power fails. */ - error = acpi_bus_set_power(handle, power_state); + error = acpi_device_set_power(acpi_dev, power_state); } return error; @@ -193,11 +176,10 @@ static int pnpacpi_resume(struct pnp_dev *dev) { - struct acpi_device *acpi_dev; - acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev); + struct acpi_device *acpi_dev = ACPI_COMPANION(&dev->dev); int error = 0; - if (!handle || acpi_bus_get_device(handle, &acpi_dev)) { + if (!acpi_dev) { dev_dbg(&dev->dev, "ACPI device not found in %s!\n", __func__); return -ENODEV; } @@ -205,8 +187,8 @@ if (device_may_wakeup(&dev->dev)) acpi_pm_device_sleep_wake(&dev->dev, false); - if (acpi_bus_power_manageable(handle)) - error = acpi_bus_set_power(handle, ACPI_STATE_D0); + if (acpi_device_power_manageable(acpi_dev)) + error = acpi_device_set_power(acpi_dev, ACPI_STATE_D0); return error; } @@ -225,7 +207,7 @@ }; EXPORT_SYMBOL(pnpacpi_protocol); -static char *__init pnpacpi_get_id(struct acpi_device *device) +static const char *__init pnpacpi_get_id(struct acpi_device *device) { struct acpi_hardware_id *id; @@ -239,11 +221,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device) { - acpi_handle temp = NULL; - acpi_status status; struct pnp_dev *dev; - char *pnpid; + const char *pnpid; struct acpi_hardware_id *id; + int error; /* Skip devices that are already bound */ if (device->physical_node_count) @@ -253,34 +234,32 @@ * If a PnPacpi device is not present , the device * driver should not be loaded. */ - status = acpi_get_handle(device->handle, "_CRS", &temp); - if (ACPI_FAILURE(status)) + if (!acpi_has_method(device->handle, "_CRS")) return 0; pnpid = pnpacpi_get_id(device); if (!pnpid) return 0; - if (is_exclusive_device(device) || !device->status.present) + if (!device->status.present) return 0; dev = pnp_alloc_dev(&pnpacpi_protocol, num, pnpid); if (!dev) return -ENOMEM; + ACPI_COMPANION_SET(&dev->dev, device); dev->data = device; /* .enabled means the device can decode the resources */ dev->active = device->status.enabled; - status = acpi_get_handle(device->handle, "_SRS", &temp); - if (ACPI_SUCCESS(status)) + if (acpi_has_method(device->handle, "_SRS")) dev->capabilities |= PNP_CONFIGURABLE; dev->capabilities |= PNP_READ; if (device->flags.dynamic_status && (dev->capabilities & PNP_CONFIGURABLE)) dev->capabilities |= PNP_WRITE; if (device->flags.removable) dev->capabilities |= PNP_REMOVABLE; - status = acpi_get_handle(device->handle, "_DIS", &temp); - if (ACPI_SUCCESS(status)) + if (acpi_has_method(device->handle, "_DIS")) dev->capabilities |= PNP_DISABLE; if (strlen(acpi_device_name(device))) @@ -305,10 +284,16 @@ /* clear out the damaged flags */ if (!dev->active) pnp_init_resources(dev); - pnp_add_device(dev); + + error = pnp_add_device(dev); + if (error) { + put_device(&dev->dev); + return error; + } + num++; - return AE_OK; + return 0; } static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, @@ -317,53 +302,13 @@ { struct acpi_device *device; - if (!acpi_bus_get_device(handle, &device)) - pnpacpi_add_device(device); - else + if (acpi_bus_get_device(handle, &device)) return AE_CTRL_DEPTH; + if (acpi_is_pnp_device(device)) + pnpacpi_add_device(device); return AE_OK; } -static int __init acpi_pnp_match(struct device *dev, void *_pnp) -{ - struct acpi_device *acpi = to_acpi_device(dev); - struct pnp_dev *pnp = _pnp; - - /* true means it matched */ - return !acpi->physical_node_count - && compare_pnp_id(pnp->id, acpi_device_hid(acpi)); -} - -static int __init acpi_pnp_find_device(struct device *dev, acpi_handle * handle) -{ - struct device *adev; - struct acpi_device *acpi; - - adev = bus_find_device(&acpi_bus_type, NULL, - to_pnp_dev(dev), acpi_pnp_match); - if (!adev) - return -ENODEV; - - acpi = to_acpi_device(adev); - *handle = acpi->handle; - put_device(adev); - return 0; -} - -/* complete initialization of a PNPACPI device includes having - * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling. - */ -static bool acpi_pnp_bus_match(struct device *dev) -{ - return dev->bus == &pnp_bus_type; -} - -static struct acpi_bus_type __initdata acpi_pnp_bus = { - .name = "PNP", - .match = acpi_pnp_bus_match, - .find_device = acpi_pnp_find_device, -}; - int pnpacpi_disabled __initdata; static int __init pnpacpi_init(void) { @@ -373,10 +318,8 @@ } printk(KERN_INFO "pnp: PnP ACPI init\n"); pnp_register_protocol(&pnpacpi_protocol); - register_acpi_bus_type(&acpi_pnp_bus); acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL); printk(KERN_INFO "pnp: PnP ACPI: found %d devices\n", num); - unregister_acpi_bus_type(&acpi_pnp_bus); pnp_platform_devices = 1; return 0; }