summaryrefslogtreecommitdiff
path: root/drivers/acpi/scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r--drivers/acpi/scan.c224
1 files changed, 151 insertions, 73 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 416d87f9bd10..565a84a7d7bc 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -5,6 +5,7 @@
#define pr_fmt(fmt) "ACPI: " fmt
+#include <linux/async.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
@@ -42,6 +43,7 @@ static LIST_HEAD(acpi_scan_handlers_list);
DEFINE_MUTEX(acpi_device_lock);
LIST_HEAD(acpi_wakeup_device_list);
static DEFINE_MUTEX(acpi_hp_context_lock);
+static LIST_HEAD(acpi_scan_system_dev_list);
/*
* The UART device described by the SPCR table is the only object which needs
@@ -998,15 +1000,11 @@ static int acpi_bus_extract_wakeup_device_power_package(struct acpi_device *dev)
return err;
}
-/* Do not use a button for S5 wakeup */
-#define ACPI_AVOID_WAKE_FROM_S5 BIT(0)
-
static bool acpi_wakeup_gpe_init(struct acpi_device *device)
{
static const struct acpi_device_id button_device_ids[] = {
- {"PNP0C0C", 0}, /* Power button */
- {"PNP0C0D", ACPI_AVOID_WAKE_FROM_S5}, /* Lid */
- {"PNP0C0E", ACPI_AVOID_WAKE_FROM_S5}, /* Sleep button */
+ {"PNP0C0D", 0}, /* Lid */
+ {"PNP0C0E", 0}, /* Sleep button */
{"", 0},
};
struct acpi_device_wakeup *wakeup = &device->wakeup;
@@ -1015,16 +1013,9 @@ static bool acpi_wakeup_gpe_init(struct acpi_device *device)
wakeup->flags.notifier_present = 0;
- /* Power button, Lid switch always enable wakeup */
match = acpi_match_acpi_device(button_device_ids, device);
- if (match) {
- if ((match->driver_data & ACPI_AVOID_WAKE_FROM_S5) &&
- wakeup->sleep_state == ACPI_STATE_S5)
- wakeup->sleep_state = ACPI_STATE_S4;
- acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number);
- device_set_wakeup_capable(&device->dev, true);
- return true;
- }
+ if (match && wakeup->sleep_state == ACPI_STATE_S5)
+ wakeup->sleep_state = ACPI_STATE_S4;
status = acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device,
wakeup->gpe_number);
@@ -1294,8 +1285,6 @@ acpi_backlight_cap_match(acpi_handle handle, u32 level, void *context,
* The device will get a Linux specific CID added in scan.c to
* identify the device as an ACPI graphics device
* Be aware that the graphics device may not be physically present
- * Use acpi_video_get_capabilities() to detect general ACPI video
- * capabilities of present cards
*/
long acpi_is_video_device(acpi_handle handle)
{
@@ -1469,6 +1458,7 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
break;
case ACPI_BUS_TYPE_THERMAL:
acpi_add_id(pnp, ACPI_THERMAL_HID);
+ pnp->type.platform_id = 1;
break;
case ACPI_BUS_TYPE_POWER_BUTTON:
acpi_add_id(pnp, ACPI_BUTTON_HID_POWERF);
@@ -2203,19 +2193,48 @@ static acpi_status acpi_bus_check_add_2(acpi_handle handle, u32 lvl_not_used,
return acpi_bus_check_add(handle, false, (struct acpi_device **)ret_p);
}
+struct acpi_scan_system_dev {
+ struct list_head node;
+ struct acpi_device *adev;
+};
+
+static const char * const acpi_system_dev_ids[] = {
+ "PNP0C01", /* Memory controller */
+ "PNP0C02", /* Motherboard resource */
+ NULL
+};
+
static void acpi_default_enumeration(struct acpi_device *device)
{
/*
* Do not enumerate devices with enumeration_by_parent flag set as
* they will be enumerated by their respective parents.
*/
- if (!device->flags.enumeration_by_parent) {
- acpi_create_platform_device(device, NULL);
- acpi_device_set_enumerated(device);
- } else {
+ if (device->flags.enumeration_by_parent) {
blocking_notifier_call_chain(&acpi_reconfig_chain,
ACPI_RECONFIG_DEVICE_ADD, device);
+ return;
+ }
+ if (match_string(acpi_system_dev_ids, -1, acpi_device_hid(device)) >= 0) {
+ struct acpi_scan_system_dev *sd;
+
+ /*
+ * This is a generic system device, so there is no need to
+ * create a platform device for it, but its resources need to be
+ * reserved. However, that needs to be done after all of the
+ * other device objects have been processed and PCI has claimed
+ * BARs in case there are resource conflicts.
+ */
+ sd = kmalloc(sizeof(*sd), GFP_KERNEL);
+ if (sd) {
+ sd->adev = device;
+ list_add_tail(&sd->node, &acpi_scan_system_dev_list);
+ }
+ } else {
+ /* For a regular device object, create a platform device. */
+ acpi_create_platform_device(device, NULL);
}
+ acpi_device_set_enumerated(device);
}
static const struct acpi_device_id generic_device_ids[] = {
@@ -2320,7 +2339,8 @@ static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
if (ret < 0)
return 0;
- if (device->pnp.type.platform_id || device->flags.enumeration_by_parent)
+ if (device->pnp.type.platform_id || device->pnp.type.backlight ||
+ device->flags.enumeration_by_parent)
acpi_default_enumeration(device);
else
acpi_device_set_enumerated(device);
@@ -2360,46 +2380,34 @@ static int acpi_dev_get_next_consumer_dev_cb(struct acpi_dep_data *dep, void *da
return 0;
}
-struct acpi_scan_clear_dep_work {
- struct work_struct work;
- struct acpi_device *adev;
-};
-
-static void acpi_scan_clear_dep_fn(struct work_struct *work)
+static void acpi_scan_clear_dep_fn(void *dev, async_cookie_t cookie)
{
- struct acpi_scan_clear_dep_work *cdw;
-
- cdw = container_of(work, struct acpi_scan_clear_dep_work, work);
+ struct acpi_device *adev = to_acpi_device(dev);
acpi_scan_lock_acquire();
- acpi_bus_attach(cdw->adev, (void *)true);
+ acpi_bus_attach(adev, (void *)true);
acpi_scan_lock_release();
- acpi_dev_put(cdw->adev);
- kfree(cdw);
+ acpi_dev_put(adev);
}
static bool acpi_scan_clear_dep_queue(struct acpi_device *adev)
{
- struct acpi_scan_clear_dep_work *cdw;
-
if (adev->dep_unmet)
return false;
- cdw = kmalloc(sizeof(*cdw), GFP_KERNEL);
- if (!cdw)
- return false;
-
- cdw->adev = adev;
- INIT_WORK(&cdw->work, acpi_scan_clear_dep_fn);
/*
- * Since the work function may block on the lock until the entire
- * initial enumeration of devices is complete, put it into the unbound
- * workqueue.
+ * Async schedule the deferred acpi_scan_clear_dep_fn() since:
+ * - acpi_bus_attach() needs to hold acpi_scan_lock which cannot
+ * be acquired under acpi_dep_list_lock (held here)
+ * - the deferred work at boot stage is ensured to be finished
+ * before userspace init task by the async_synchronize_full()
+ * barrier
+ *
+ * Use _nocall variant since it'll return on failure instead of
+ * run the function synchronously.
*/
- queue_work(system_dfl_wq, &cdw->work);
-
- return true;
+ return async_schedule_dev_nocall(acpi_scan_clear_dep_fn, &adev->dev);
}
static void acpi_scan_delete_dep_data(struct acpi_dep_data *dep)
@@ -2571,6 +2579,87 @@ static void acpi_scan_postponed(void)
mutex_unlock(&acpi_dep_list_lock);
}
+static void acpi_scan_claim_resources(struct acpi_device *adev)
+{
+ struct resource_entry *rentry;
+ LIST_HEAD(resource_list);
+ unsigned int count = 0;
+ const char *regionid;
+
+ if (acpi_dev_get_resources(adev, &resource_list, NULL, NULL) <= 0)
+ return;
+
+ regionid = kstrdup(dev_name(&adev->dev), GFP_KERNEL);
+ if (!regionid)
+ goto exit;
+
+ list_for_each_entry(rentry, &resource_list, node) {
+ struct resource *res = rentry->res;
+ struct resource *r;
+
+ /* Skip disabled and invalid resources. */
+ if ((res->flags & IORESOURCE_DISABLED) || res->end < res->start)
+ continue;
+
+ if (resource_type(res) == IORESOURCE_IO) {
+ /*
+ * Follow the PNP system driver and on x86 skip I/O
+ * resources that start below 0x100 (the "standard PC
+ * hardware" boundary).
+ */
+ if (IS_ENABLED(CONFIG_X86) && res->start < 0x100) {
+ dev_info(&adev->dev, "Skipped %pR\n", res);
+ continue;
+ }
+ r = request_region(res->start, resource_size(res), regionid);
+ } else if (resource_type(res) == IORESOURCE_MEM) {
+ r = request_mem_region(res->start, resource_size(res), regionid);
+ } else {
+ continue;
+ }
+
+ if (r) {
+ r->flags &= ~IORESOURCE_BUSY;
+ dev_info(&adev->dev, "Reserved %pR\n", r);
+ count++;
+ } else {
+ /*
+ * Failures at this point are usually harmless. PCI
+ * quirks, for example, reserve resources they know
+ * about too, so there may well be double reservations.
+ */
+ dev_info(&adev->dev, "Could not reserve %pR\n", res);
+ }
+ }
+
+ if (!count)
+ kfree(regionid);
+
+exit:
+ acpi_dev_free_resource_list(&resource_list);
+}
+
+static int __init acpi_reserve_motherboard_resources(void)
+{
+ struct acpi_scan_system_dev *sd, *tmp;
+
+ guard(mutex)(&acpi_scan_lock);
+
+ list_for_each_entry_safe(sd, tmp, &acpi_scan_system_dev_list, node) {
+ acpi_scan_claim_resources(sd->adev);
+ list_del(&sd->node);
+ kfree(sd);
+ }
+
+ return 0;
+}
+
+/*
+ * Reserve motherboard resources after PCI claims BARs, but before PCI assigns
+ * resources for uninitialized PCI devices.
+ */
+fs_initcall(acpi_reserve_motherboard_resources);
+
/**
* acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
* @handle: Root of the namespace scope to scan.
@@ -2642,38 +2731,27 @@ int acpi_bus_register_early_device(int type)
if (result)
return result;
- device->flags.match_driver = true;
- return device_attach(&device->dev);
+ acpi_default_enumeration(device);
+ return 0;
}
EXPORT_SYMBOL_GPL(acpi_bus_register_early_device);
-static void acpi_bus_scan_fixed(void)
+static void acpi_bus_add_fixed_device_object(enum acpi_bus_device_type type)
{
- if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON)) {
- struct acpi_device *adev = NULL;
+ struct acpi_device *adev = NULL;
- acpi_add_single_object(&adev, NULL, ACPI_BUS_TYPE_POWER_BUTTON,
- false);
- if (adev) {
- adev->flags.match_driver = true;
- if (device_attach(&adev->dev) >= 0)
- device_init_wakeup(&adev->dev, true);
- else
- dev_dbg(&adev->dev, "No driver\n");
- }
- }
+ acpi_add_single_object(&adev, NULL, type, false);
+ if (adev)
+ acpi_default_enumeration(adev);
+}
- if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON)) {
- struct acpi_device *adev = NULL;
+static void acpi_bus_scan_fixed(void)
+{
+ if (!(acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON))
+ acpi_bus_add_fixed_device_object(ACPI_BUS_TYPE_POWER_BUTTON);
- acpi_add_single_object(&adev, NULL, ACPI_BUS_TYPE_SLEEP_BUTTON,
- false);
- if (adev) {
- adev->flags.match_driver = true;
- if (device_attach(&adev->dev) < 0)
- dev_dbg(&adev->dev, "No driver\n");
- }
- }
+ if (!(acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON))
+ acpi_bus_add_fixed_device_object(ACPI_BUS_TYPE_SLEEP_BUTTON);
}
static void __init acpi_get_spcr_uart_addr(void)