Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / acpi / scan.c
index 2951a27..6ad4656 100644 (file)
@@ -175,6 +175,16 @@ acpi_device_hid_show(struct device *dev, struct device_attribute *attr, char *bu
 }
 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
 
+#ifdef CONFIG_PCI_GUESTDEV
+static ssize_t
+acpi_device_uid_show(struct device *dev, struct device_attribute *attr, char *buf) {
+       struct acpi_device *acpi_dev = to_acpi_device(dev);
+
+       return sprintf(buf, "%s\n", acpi_dev->pnp.unique_id);
+}
+static DEVICE_ATTR(uid, 0444, acpi_device_uid_show, NULL);
+#endif
+
 static ssize_t
 acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *buf) {
        struct acpi_device *acpi_dev = to_acpi_device(dev);
@@ -217,6 +227,13 @@ static int acpi_device_setup_files(struct acpi_device *dev)
                        goto end;
        }
 
+#ifdef CONFIG_PCI_GUESTDEV
+       if(dev->pnp.unique_id) {
+               result = device_create_file(&dev->dev, &dev_attr_uid);
+               if(result)
+                       goto end;
+       }
+#endif
         /*
          * If device has _EJ0, 'eject' file is created that is used to trigger
          * hot-removal function from userland.
@@ -280,6 +297,9 @@ static void acpi_free_ids(struct acpi_device *device)
                kfree(id->id);
                kfree(id);
        }
+#ifdef CONFIG_PCI_GUESTDEV
+       kfree(device->pnp.unique_id);
+#endif
 }
 
 static void acpi_device_release(struct device *dev)
@@ -778,7 +798,7 @@ acpi_bus_extract_wakeup_device_power_package(acpi_handle handle,
                wakeup->resources.handles[i] = element->reference.handle;
        }
 
-       acpi_gpe_can_wake(wakeup->gpe_device, wakeup->gpe_number);
+       acpi_setup_gpe_for_wake(handle, wakeup->gpe_device, wakeup->gpe_number);
 
  out:
        kfree(buffer.pointer);
@@ -797,13 +817,12 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
        acpi_status status;
        acpi_event_status event_status;
 
-       device->wakeup.run_wake_count = 0;
        device->wakeup.flags.notifier_present = 0;
 
        /* Power button, Lid switch always enable wakeup */
        if (!acpi_match_device_ids(device, button_device_ids)) {
                device->wakeup.flags.run_wake = 1;
-               device->wakeup.flags.always_enabled = 1;
+               device_set_wakeup_capable(&device->dev, true);
                return;
        }
 
@@ -815,16 +834,22 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
                                !!(event_status & ACPI_EVENT_FLAG_HANDLE);
 }
 
-static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
+static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
 {
+       acpi_handle temp;
        acpi_status status = 0;
        int psw_error;
 
+       /* Presence of _PRW indicates wake capable */
+       status = acpi_get_handle(device->handle, "_PRW", &temp);
+       if (ACPI_FAILURE(status))
+               return;
+
        status = acpi_bus_extract_wakeup_device_power_package(device->handle,
                                                              &device->wakeup);
        if (ACPI_FAILURE(status)) {
                ACPI_EXCEPTION((AE_INFO, status, "Extracting _PRW package"));
-               goto end;
+               return;
        }
 
        device->wakeup.flags.valid = 1;
@@ -840,13 +865,10 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
        if (psw_error)
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                "error in _DSW or _PSW evaluation\n"));
-
-end:
-       if (ACPI_FAILURE(status))
-               device->flags.wake_capable = 0;
-       return 0;
 }
 
+static void acpi_bus_add_power_resource(acpi_handle handle);
+
 static int acpi_bus_get_power_flags(struct acpi_device *device)
 {
        acpi_status status = 0;
@@ -867,7 +889,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
        /*
         * Enumerate supported power management states
         */
-       for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3; i++) {
+       for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
                struct acpi_device_power_state *ps = &device->power.states[i];
                char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
 
@@ -875,20 +897,25 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
                acpi_evaluate_reference(device->handle, object_name, NULL,
                                        &ps->resources);
                if (ps->resources.count) {
+                       int j;
+
                        device->power.flags.power_resources = 1;
-                       ps->flags.valid = 1;
+                       for (j = 0; j < ps->resources.count; j++)
+                               acpi_bus_add_power_resource(ps->resources.handles[j]);
                }
 
                /* Evaluate "_PSx" to see if we can do explicit sets */
                object_name[2] = 'S';
                status = acpi_get_handle(device->handle, object_name, &handle);
-               if (ACPI_SUCCESS(status)) {
+               if (ACPI_SUCCESS(status))
                        ps->flags.explicit_set = 1;
-                       ps->flags.valid = 1;
-               }
 
-               /* State is valid if we have some power control */
-               if (ps->resources.count || ps->flags.explicit_set)
+               /*
+                * State is valid if there are means to put the device into it.
+                * D3hot is only valid if _PR3 present.
+                */
+               if (ps->resources.count ||
+                   (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT))
                        ps->flags.valid = 1;
 
                ps->power = -1; /* Unknown - driver assigned */
@@ -901,6 +928,10 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
        device->power.states[ACPI_STATE_D3].flags.valid = 1;
        device->power.states[ACPI_STATE_D3].power = 0;
 
+       /* Set D3cold's explicit_set flag if _PS3 exists. */
+       if (device->power.states[ACPI_STATE_D3_HOT].flags.explicit_set)
+               device->power.states[ACPI_STATE_D3_COLD].flags.explicit_set = 1;
+
        acpi_bus_init_power(device);
 
        return 0;
@@ -937,6 +968,10 @@ static int acpi_bus_get_flags(struct acpi_device *device)
        if (ACPI_SUCCESS(status))
                device->flags.lockable = 1;
 
+       /* Power resources cannot be power manageable. */
+       if (device->device_type == ACPI_BUS_TYPE_POWER)
+               return 0;
+
        /* Presence of _PS0|_PR0 indicates 'power manageable' */
        status = acpi_get_handle(device->handle, "_PS0", &temp);
        if (ACPI_FAILURE(status))
@@ -944,11 +979,6 @@ static int acpi_bus_get_flags(struct acpi_device *device)
        if (ACPI_SUCCESS(status))
                device->flags.power_manageable = 1;
 
-       /* Presence of _PRW indicates wake capable */
-       status = acpi_get_handle(device->handle, "_PRW", &temp);
-       if (ACPI_SUCCESS(status))
-               device->flags.wake_capable = 1;
-
        /* TBD: Performance management */
 
        return 0;
@@ -1057,13 +1087,12 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id)
        if (!id)
                return;
 
-       id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL);
+       id->id = kstrdup(dev_id, GFP_KERNEL);
        if (!id->id) {
                kfree(id);
                return;
        }
 
-       strcpy(id->id, dev_id);
        list_add_tail(&id->list, &device->pnp.ids);
 }
 
@@ -1129,6 +1158,11 @@ static void acpi_device_set_id(struct acpi_device *device)
                        for (i = 0; i < cid_list->count; i++)
                                acpi_add_id(device, cid_list->ids[i].string);
                }
+#ifdef CONFIG_PCI_GUESTDEV
+               if (info->valid & ACPI_VALID_UID)
+                       device->pnp.unique_id = kstrdup(info->unique_id.string,
+                                                       GFP_KERNEL);
+#endif
                if (info->valid & ACPI_VALID_ADR) {
                        device->pnp.bus_address = info->address;
                        device->flags.bus_address = 1;
@@ -1275,11 +1309,7 @@ static int acpi_add_single_object(struct acpi_device **child,
         * Wakeup device management
         *-----------------------
         */
-       if (device->flags.wake_capable) {
-               result = acpi_bus_get_wakeup_device_flags(device);
-               if (result)
-                       goto end;
-       }
+       acpi_bus_get_wakeup_device_flags(device);
 
        /*
         * Performance Management
@@ -1323,6 +1353,20 @@ end:
 #define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
                          ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING)
 
+static void acpi_bus_add_power_resource(acpi_handle handle)
+{
+       struct acpi_bus_ops ops = {
+               .acpi_op_add = 1,
+               .acpi_op_start = 1,
+       };
+       struct acpi_device *device = NULL;
+
+       acpi_bus_get_device(handle, &device);
+       if (!device)
+               acpi_add_single_object(&device, handle, ACPI_BUS_TYPE_POWER,
+                                       ACPI_STA_DEFAULT, &ops);
+}
+
 static int acpi_bus_type_and_status(acpi_handle handle, int *type,
                                    unsigned long long *sta)
 {
@@ -1368,7 +1412,6 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,
        struct acpi_bus_ops *ops = context;
        int type;
        unsigned long long sta;
-       struct acpi_device_wakeup wakeup;
        struct acpi_device *device;
        acpi_status status;
        int result;
@@ -1379,7 +1422,13 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,
 
        if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
            !(sta & ACPI_STA_DEVICE_FUNCTIONING)) {
-               acpi_bus_extract_wakeup_device_power_package(handle, &wakeup);
+               struct acpi_device_wakeup wakeup;
+               acpi_handle temp;
+
+               status = acpi_get_handle(handle, "_PRW", &temp);
+               if (ACPI_SUCCESS(status))
+                       acpi_bus_extract_wakeup_device_power_package(handle,
+                                                                    &wakeup);
                return AE_CTRL_DEPTH;
        }
 
@@ -1464,7 +1513,7 @@ int acpi_bus_start(struct acpi_device *device)
 
        result = acpi_bus_scan(device->handle, &ops, NULL);
 
-       acpi_update_gpes();
+       acpi_update_all_gpes();
 
        return result;
 }
@@ -1583,7 +1632,7 @@ int __init acpi_scan_init(void)
        if (result)
                acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
        else
-               acpi_update_gpes();
+               acpi_update_all_gpes();
 
        return result;
 }