Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / acpi / scan.c
index da11b53..7f2e051 100644 (file)
@@ -4,10 +4,12 @@
 
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/acpi.h>
 #include <linux/signal.h>
 #include <linux/kthread.h>
+#include <linux/dmi.h>
 
 #include <acpi/acpi_drivers.h>
 
@@ -741,19 +743,40 @@ acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
        return AE_OK;
 }
 
-static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
+static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
 {
-       acpi_status status = 0;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-       union acpi_object *package = NULL;
-       int psw_error;
-
        struct acpi_device_id button_device_ids[] = {
                {"PNP0C0D", 0},
                {"PNP0C0C", 0},
                {"PNP0C0E", 0},
                {"", 0},
        };
+       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;
+               return;
+       }
+
+       status = acpi_get_gpe_status(NULL, device->wakeup.gpe_number,
+                                       &event_status);
+       if (status == AE_OK)
+               device->wakeup.flags.run_wake =
+                               !!(event_status & ACPI_EVENT_FLAG_HANDLE);
+}
+
+static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
+{
+       acpi_status status = 0;
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       union acpi_object *package = NULL;
+       int psw_error;
 
        /* _PRW */
        status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
@@ -773,6 +796,7 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
 
        device->wakeup.flags.valid = 1;
        device->wakeup.prepare_count = 0;
+       acpi_bus_set_run_wake_flags(device);
        /* Call _PSW/_DSW object to disable its ability to wake the sleeping
         * system for the ACPI device with the _PRW object.
         * The _PSW object is depreciated in ACPI 3.0 and is replaced by _DSW.
@@ -784,10 +808,6 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                "error in _DSW or _PSW evaluation\n"));
 
-       /* Power button, Lid switch always enable wakeup */
-       if (!acpi_match_device_ids(device, button_device_ids))
-               device->wakeup.flags.run_wake = 1;
-
 end:
        if (ACPI_FAILURE(status))
                device->flags.wake_capable = 0;
@@ -1014,25 +1034,52 @@ static void acpi_add_id(struct acpi_device *device, const char *dev_id)
        list_add_tail(&id->list, &device->pnp.ids);
 }
 
+/*
+ * Old IBM workstations have a DSDT bug wherein the SMBus object
+ * 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)
+{
+       acpi_handle h_dummy;
+       struct acpi_buffer path = {ACPI_ALLOCATE_BUFFER, NULL};
+       int result;
+
+       if (!dmi_name_in_vendors("IBM"))
+               return -ENODEV;
+
+       /* Look for SMBS object */
+       result = acpi_get_name(device->handle, ACPI_SINGLE_NAME, &path);
+       if (result)
+               return result;
+
+       if (strcmp("SMBS", path.pointer)) {
+               result = -ENODEV;
+               goto out;
+       }
+
+       /* 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)))
+               result = 0;
+out:
+       kfree(path.pointer);
+       return result;
+}
+
 static void acpi_device_set_id(struct acpi_device *device)
 {
-       struct acpi_device_info *info = NULL;
-       char *hid = NULL;
-       struct acpica_device_id_list *cid_list = NULL;
-       char *cid_add = NULL;
        acpi_status status;
+       struct acpi_device_info *info;
+       struct acpica_device_id_list *cid_list;
        int i;
 
        switch (device->device_type) {
        case ACPI_BUS_TYPE_DEVICE:
                if (ACPI_IS_ROOT_DEVICE(device)) {
-                       hid = ACPI_SYSTEM_HID;
-                       break;
-               } else if (ACPI_IS_ROOT_DEVICE(device->parent)) {
-                       /* \_SB_, the only root-level namespace device */
-                       hid = ACPI_BUS_HID;
-                       strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
-                       strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
+                       acpi_add_id(device, ACPI_SYSTEM_HID);
                        break;
                }
 
@@ -1043,41 +1090,53 @@ static void acpi_device_set_id(struct acpi_device *device)
                }
 
                if (info->valid & ACPI_VALID_HID)
-                       hid = info->hardware_id.string;
-               if (info->valid & ACPI_VALID_CID)
+                       acpi_add_id(device, 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);
+               }
                if (info->valid & ACPI_VALID_ADR) {
                        device->pnp.bus_address = info->address;
                        device->flags.bus_address = 1;
                }
 
-               /* If we have a video/bay/dock device, add our selfdefined
-                  HID to the CID list. Like that the video/bay/dock drivers
-                  will get autoloaded and the device might still match
-                  against another driver.
-               */
+               kfree(info);
+
+               /*
+                * 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))
-                       cid_add = ACPI_VIDEO_HID;
+                       acpi_add_id(device, ACPI_VIDEO_HID);
                else if (ACPI_SUCCESS(acpi_bay_match(device)))
-                       cid_add = ACPI_BAY_HID;
+                       acpi_add_id(device, ACPI_BAY_HID);
                else if (ACPI_SUCCESS(acpi_dock_match(device)))
-                       cid_add = ACPI_DOCK_HID;
+                       acpi_add_id(device, ACPI_DOCK_HID);
+               else if (!acpi_ibm_smbus_match(device))
+                       acpi_add_id(device, ACPI_SMBUS_IBM_HID);
+               else if (!acpi_device_hid(device) &&
+                        ACPI_IS_ROOT_DEVICE(device->parent)) {
+                       acpi_add_id(device, 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:
-               hid = ACPI_POWER_HID;
+               acpi_add_id(device, ACPI_POWER_HID);
                break;
        case ACPI_BUS_TYPE_PROCESSOR:
-               hid = ACPI_PROCESSOR_OBJECT_HID;
+               acpi_add_id(device, ACPI_PROCESSOR_OBJECT_HID);
                break;
        case ACPI_BUS_TYPE_THERMAL:
-               hid = ACPI_THERMAL_HID;
+               acpi_add_id(device, ACPI_THERMAL_HID);
                break;
        case ACPI_BUS_TYPE_POWER_BUTTON:
-               hid = ACPI_BUTTON_HID_POWERF;
+               acpi_add_id(device, ACPI_BUTTON_HID_POWERF);
                break;
        case ACPI_BUS_TYPE_SLEEP_BUTTON:
-               hid = ACPI_BUTTON_HID_SLEEPF;
+               acpi_add_id(device, ACPI_BUTTON_HID_SLEEPF);
                break;
        }
 
@@ -1088,18 +1147,8 @@ static void acpi_device_set_id(struct acpi_device *device)
         * This generic ID isn't useful for driver binding, but it provides
         * the useful property that "every acpi_device has an ID."
         */
-       if (!hid && !cid_list && !cid_add)
-               hid = "device";
-
-       if (hid)
-               acpi_add_id(device, hid);
-       if (cid_list)
-               for (i = 0; i < cid_list->count; i++)
-                       acpi_add_id(device, cid_list->ids[i].string);
-       if (cid_add)
-               acpi_add_id(device, cid_add);
-
-       kfree(info);
+       if (list_empty(&device->pnp.ids))
+               acpi_add_id(device, "device");
 }
 
 static int acpi_device_set_context(struct acpi_device *device)
@@ -1335,23 +1384,34 @@ static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops,
                         struct acpi_device **child)
 {
        acpi_status status;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
        void *device = NULL;
 
-       acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
-       printk(KERN_INFO PREFIX "Enumerating devices from [%s]\n",
-              (char *) buffer.pointer);
-
        status = acpi_bus_check_add(handle, 0, ops, &device);
        if (ACPI_SUCCESS(status))
                acpi_walk_namespace(ACPI_TYPE_ANY, handle, ACPI_UINT32_MAX,
-                                   acpi_bus_check_add, ops, &device);
+                                   acpi_bus_check_add, NULL, ops, &device);
 
        if (child)
                *child = device;
-       return 0;
+
+       if (device)
+               return 0;
+       else
+               return -ENODEV;
 }
 
+/*
+ * acpi_bus_add and acpi_bus_start
+ *
+ * scan a given ACPI tree and (probably recently hot-plugged)
+ * create and add or starts found devices.
+ *
+ * If no devices were found -ENODEV is returned which does not
+ * mean that this is a real error, there just have been no suitable
+ * ACPI objects in the table trunk from which the kernel could create
+ * a device and add/start an appropriate driver.
+ */
+
 int
 acpi_bus_add(struct acpi_device **child,
             struct acpi_device *parent, acpi_handle handle, int type)
@@ -1361,8 +1421,7 @@ acpi_bus_add(struct acpi_device **child,
        memset(&ops, 0, sizeof(ops));
        ops.acpi_op_add = 1;
 
-       acpi_bus_scan(handle, &ops, child);
-       return 0;
+       return acpi_bus_scan(handle, &ops, child);
 }
 EXPORT_SYMBOL(acpi_bus_add);
 
@@ -1370,11 +1429,13 @@ int acpi_bus_start(struct acpi_device *device)
 {
        struct acpi_bus_ops ops;
 
+       if (!device)
+               return -EINVAL;
+
        memset(&ops, 0, sizeof(ops));
        ops.acpi_op_start = 1;
 
-       acpi_bus_scan(device->handle, &ops, NULL);
-       return 0;
+       return acpi_bus_scan(device->handle, &ops, NULL);
 }
 EXPORT_SYMBOL(acpi_bus_start);