include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / acpi / scan.c
index 6d85289..0261b11 100644 (file)
@@ -4,11 +4,16 @@
 
 #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>
-#include <acpi/acinterp.h>     /* for acpi_ex_eisa_id_to_string() */
+
+#include "internal.h"
 
 #define _COMPONENT             ACPI_BUS_COMPONENT
 ACPI_MODULE_NAME("scan");
@@ -19,9 +24,11 @@ extern struct acpi_device *acpi_root;
 #define ACPI_BUS_HID                   "LNXSYBUS"
 #define ACPI_BUS_DEVICE_NAME           "System Bus"
 
+#define ACPI_IS_ROOT_DEVICE(device)    (!(device)->parent)
+
 static LIST_HEAD(acpi_device_list);
 static LIST_HEAD(acpi_bus_id_list);
-DEFINE_SPINLOCK(acpi_device_lock);
+DEFINE_MUTEX(acpi_device_lock);
 LIST_HEAD(acpi_wakeup_device_list);
 
 struct acpi_device_bus_id{
@@ -40,40 +47,19 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
 {
        int len;
        int count;
-
-       if (!acpi_dev->flags.hardware_id && !acpi_dev->flags.compatible_ids)
-               return -ENODEV;
+       struct acpi_hardware_id *id;
 
        len = snprintf(modalias, size, "acpi:");
        size -= len;
 
-       if (acpi_dev->flags.hardware_id) {
-               count = snprintf(&modalias[len], size, "%s:",
-                                acpi_dev->pnp.hardware_id);
+       list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
+               count = snprintf(&modalias[len], size, "%s:", id->id);
                if (count < 0 || count >= size)
                        return -EINVAL;
                len += count;
                size -= count;
        }
 
-       if (acpi_dev->flags.compatible_ids) {
-               struct acpi_compatible_id_list *cid_list;
-               int i;
-
-               cid_list = acpi_dev->pnp.cid_list;
-               for (i = 0; i < cid_list->count; i++) {
-                       count = snprintf(&modalias[len], size, "%s:",
-                                        cid_list->id[i].value);
-                       if (count < 0 || count >= size) {
-                               printk(KERN_ERR PREFIX "%s cid[%i] exceeds event buffer size",
-                                      acpi_dev->pnp.device_name, i);
-                               break;
-                       }
-                       len += count;
-                       size -= count;
-               }
-       }
-
        modalias[len] = '\0';
        return len;
 }
@@ -92,17 +78,36 @@ acpi_device_modalias_show(struct device *dev, struct device_attribute *attr, cha
 }
 static DEVICE_ATTR(modalias, 0444, acpi_device_modalias_show, NULL);
 
-static int acpi_eject_operation(acpi_handle handle, int lockable)
+static void acpi_bus_hot_remove_device(void *context)
 {
+       struct acpi_device *device;
+       acpi_handle handle = context;
        struct acpi_object_list arg_list;
        union acpi_object arg;
        acpi_status status = AE_OK;
 
-       /*
-        * TBD: evaluate _PS3?
-        */
+       if (acpi_bus_get_device(handle, &device))
+               return;
+
+       if (!device)
+               return;
+
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+               "Hot-removing device %s...\n", dev_name(&device->dev)));
+
+       if (acpi_bus_trim(device, 1)) {
+               printk(KERN_ERR PREFIX
+                               "Removing device failed\n");
+               return;
+       }
+
+       /* power off device */
+       status = acpi_evaluate_object(handle, "_PS3", NULL, NULL);
+       if (ACPI_FAILURE(status) && status != AE_NOT_FOUND)
+               printk(KERN_WARNING PREFIX
+                               "Power-off device failed\n");
 
-       if (lockable) {
+       if (device->flags.lockable) {
                arg_list.count = 1;
                arg_list.pointer = &arg;
                arg.type = ACPI_TYPE_INTEGER;
@@ -118,24 +123,20 @@ static int acpi_eject_operation(acpi_handle handle, int lockable)
        /*
         * TBD: _EJD support.
         */
-
        status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
-       if (ACPI_FAILURE(status)) {
-               return (-ENODEV);
-       }
+       if (ACPI_FAILURE(status))
+               printk(KERN_WARNING PREFIX
+                               "Eject device failed\n");
 
-       return (0);
+       return;
 }
 
 static ssize_t
 acpi_eject_store(struct device *d, struct device_attribute *attr,
                const char *buf, size_t count)
 {
-       int result;
        int ret = count;
-       int islockable;
        acpi_status status;
-       acpi_handle handle;
        acpi_object_type type = 0;
        struct acpi_device *acpi_device = to_acpi_device(d);
 
@@ -154,18 +155,8 @@ acpi_eject_store(struct device *d, struct device_attribute *attr,
                goto err;
        }
 
-       islockable = acpi_device->flags.lockable;
-       handle = acpi_device->handle;
-
-       result = acpi_bus_trim(acpi_device, 1);
-
-       if (!result)
-               result = acpi_eject_operation(handle, islockable);
-
-       if (result) {
-               ret = -EBUSY;
-       }
-      err:
+       acpi_os_hotplug_execute(acpi_bus_hot_remove_device, acpi_device->handle);
+err:
        return ret;
 }
 
@@ -175,7 +166,7 @@ static ssize_t
 acpi_device_hid_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.hardware_id);
+       return sprintf(buf, "%s\n", acpi_device_hid(acpi_dev));
 }
 static DEVICE_ATTR(hid, 0444, acpi_device_hid_show, NULL);
 
@@ -186,12 +177,12 @@ acpi_device_path_show(struct device *dev, struct device_attribute *attr, char *b
        int result;
 
        result = acpi_get_name(acpi_dev->handle, ACPI_FULL_PATHNAME, &path);
-       if(result)
+       if (result)
                goto end;
 
        result = sprintf(buf, "%s\n", (char*)path.pointer);
        kfree(path.pointer);
-  end:
+end:
        return result;
 }
 static DEVICE_ATTR(path, 0444, acpi_device_path_show, NULL);
@@ -205,23 +196,19 @@ static int acpi_device_setup_files(struct acpi_device *dev)
        /*
         * Devices gotten from FADT don't have a "path" attribute
         */
-       if(dev->handle) {
+       if (dev->handle) {
                result = device_create_file(&dev->dev, &dev_attr_path);
-               if(result)
+               if (result)
                        goto end;
        }
 
-       if(dev->flags.hardware_id) {
-               result = device_create_file(&dev->dev, &dev_attr_hid);
-               if(result)
-                       goto end;
-       }
+       result = device_create_file(&dev->dev, &dev_attr_hid);
+       if (result)
+               goto end;
 
-       if (dev->flags.hardware_id || dev->flags.compatible_ids){
-               result = device_create_file(&dev->dev, &dev_attr_modalias);
-               if(result)
-                       goto end;
-       }
+       result = device_create_file(&dev->dev, &dev_attr_modalias);
+       if (result)
+               goto end;
 
         /*
          * If device has _EJ0, 'eject' file is created that is used to trigger
@@ -230,7 +217,7 @@ static int acpi_device_setup_files(struct acpi_device *dev)
        status = acpi_get_handle(dev->handle, "_EJ0", &temp);
        if (ACPI_SUCCESS(status))
                result = device_create_file(&dev->dev, &dev_attr_eject);
-  end:
+end:
        return result;
 }
 
@@ -247,12 +234,9 @@ static void acpi_device_remove_files(struct acpi_device *dev)
        if (ACPI_SUCCESS(status))
                device_remove_file(&dev->dev, &dev_attr_eject);
 
-       if (dev->flags.hardware_id || dev->flags.compatible_ids)
-               device_remove_file(&dev->dev, &dev_attr_modalias);
-
-       if(dev->flags.hardware_id)
-               device_remove_file(&dev->dev, &dev_attr_hid);
-       if(dev->handle)
+       device_remove_file(&dev->dev, &dev_attr_modalias);
+       device_remove_file(&dev->dev, &dev_attr_hid);
+       if (dev->handle)
                device_remove_file(&dev->dev, &dev_attr_path);
 }
 /* --------------------------------------------------------------------------
@@ -263,37 +247,39 @@ int acpi_match_device_ids(struct acpi_device *device,
                          const struct acpi_device_id *ids)
 {
        const struct acpi_device_id *id;
+       struct acpi_hardware_id *hwid;
 
-       if (device->flags.hardware_id) {
-               for (id = ids; id->id[0]; id++) {
-                       if (!strcmp((char*)id->id, device->pnp.hardware_id))
-                               return 0;
-               }
-       }
-
-       if (device->flags.compatible_ids) {
-               struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
-               int i;
+       /*
+        * If the device is not present, it is unnecessary to load device
+        * driver for it.
+        */
+       if (!device->status.present)
+               return -ENODEV;
 
-               for (id = ids; id->id[0]; id++) {
-                       /* compare multiple _CID entries against driver ids */
-                       for (i = 0; i < cid_list->count; i++) {
-                               if (!strcmp((char*)id->id,
-                                           cid_list->id[i].value))
-                                       return 0;
-                       }
-               }
-       }
+       for (id = ids; id->id[0]; id++)
+               list_for_each_entry(hwid, &device->pnp.ids, list)
+                       if (!strcmp((char *) id->id, hwid->id))
+                               return 0;
 
        return -ENOENT;
 }
 EXPORT_SYMBOL(acpi_match_device_ids);
 
+static 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);
+       }
+}
+
 static void acpi_device_release(struct device *dev)
 {
        struct acpi_device *acpi_dev = to_acpi_device(dev);
 
-       kfree(acpi_dev->pnp.cid_list);
+       acpi_free_ids(acpi_dev);
        kfree(acpi_dev);
 }
 
@@ -340,6 +326,60 @@ static int acpi_device_uevent(struct device *dev, struct kobj_uevent_env *env)
        return 0;
 }
 
+static void acpi_device_notify(acpi_handle handle, u32 event, void *data)
+{
+       struct acpi_device *device = data;
+
+       device->driver->ops.notify(device, event);
+}
+
+static acpi_status acpi_device_notify_fixed(void *data)
+{
+       struct acpi_device *device = data;
+
+       /* Fixed hardware devices have no handles */
+       acpi_device_notify(NULL, ACPI_FIXED_HARDWARE_EVENT, device);
+       return AE_OK;
+}
+
+static int acpi_device_install_notify_handler(struct acpi_device *device)
+{
+       acpi_status status;
+
+       if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
+               status =
+                   acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
+                                                    acpi_device_notify_fixed,
+                                                    device);
+       else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
+               status =
+                   acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
+                                                    acpi_device_notify_fixed,
+                                                    device);
+       else
+               status = acpi_install_notify_handler(device->handle,
+                                                    ACPI_DEVICE_NOTIFY,
+                                                    acpi_device_notify,
+                                                    device);
+
+       if (ACPI_FAILURE(status))
+               return -EINVAL;
+       return 0;
+}
+
+static void acpi_device_remove_notify_handler(struct acpi_device *device)
+{
+       if (device->device_type == ACPI_BUS_TYPE_POWER_BUTTON)
+               acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON,
+                                               acpi_device_notify_fixed);
+       else if (device->device_type == ACPI_BUS_TYPE_SLEEP_BUTTON)
+               acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON,
+                                               acpi_device_notify_fixed);
+       else
+               acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
+                                          acpi_device_notify);
+}
+
 static int acpi_bus_driver_init(struct acpi_device *, struct acpi_driver *);
 static int acpi_start_single_object(struct acpi_device *);
 static int acpi_device_probe(struct device * dev)
@@ -352,6 +392,17 @@ static int acpi_device_probe(struct device * dev)
        if (!ret) {
                if (acpi_dev->bus_ops.acpi_op_start)
                        acpi_start_single_object(acpi_dev);
+
+               if (acpi_drv->ops.notify) {
+                       ret = acpi_device_install_notify_handler(acpi_dev);
+                       if (ret) {
+                               if (acpi_drv->ops.remove)
+                                       acpi_drv->ops.remove(acpi_dev,
+                                                    acpi_dev->removal_type);
+                               return ret;
+                       }
+               }
+
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                        "Found driver [%s] for device [%s]\n",
                        acpi_drv->name, acpi_dev->pnp.bus_id));
@@ -366,46 +417,34 @@ static int acpi_device_remove(struct device * dev)
        struct acpi_driver *acpi_drv = acpi_dev->driver;
 
        if (acpi_drv) {
-               if (acpi_drv->ops.stop)
-                       acpi_drv->ops.stop(acpi_dev, acpi_dev->removal_type);
+               if (acpi_drv->ops.notify)
+                       acpi_device_remove_notify_handler(acpi_dev);
                if (acpi_drv->ops.remove)
                        acpi_drv->ops.remove(acpi_dev, acpi_dev->removal_type);
        }
        acpi_dev->driver = NULL;
-       acpi_driver_data(dev) = NULL;
+       acpi_dev->driver_data = NULL;
 
        put_device(dev);
        return 0;
 }
 
-static void acpi_device_shutdown(struct device *dev)
-{
-       struct acpi_device *acpi_dev = to_acpi_device(dev);
-       struct acpi_driver *acpi_drv = acpi_dev->driver;
-
-       if (acpi_drv && acpi_drv->ops.shutdown)
-               acpi_drv->ops.shutdown(acpi_dev);
-
-       return ;
-}
-
 struct bus_type acpi_bus_type = {
        .name           = "acpi",
        .suspend        = acpi_device_suspend,
        .resume         = acpi_device_resume,
-       .shutdown       = acpi_device_shutdown,
        .match          = acpi_bus_match,
        .probe          = acpi_device_probe,
        .remove         = acpi_device_remove,
        .uevent         = acpi_device_uevent,
 };
 
-static int acpi_device_register(struct acpi_device *device,
-                                struct acpi_device *parent)
+static int acpi_device_register(struct acpi_device *device)
 {
        int result;
        struct acpi_device_bus_id *acpi_device_bus_id, *new_bus_id;
        int found = 0;
+
        /*
         * Linkage
         * -------
@@ -413,7 +452,6 @@ static int acpi_device_register(struct acpi_device *device,
         */
        INIT_LIST_HEAD(&device->children);
        INIT_LIST_HEAD(&device->node);
-       INIT_LIST_HEAD(&device->g_list);
        INIT_LIST_HEAD(&device->wakeup_list);
 
        new_bus_id = kzalloc(sizeof(struct acpi_device_bus_id), GFP_KERNEL);
@@ -422,76 +460,69 @@ static int acpi_device_register(struct acpi_device *device,
                return -ENOMEM;
        }
 
-       spin_lock(&acpi_device_lock);
+       mutex_lock(&acpi_device_lock);
        /*
         * Find suitable bus_id and instance number in acpi_bus_id_list
         * If failed, create one and link it into acpi_bus_id_list
         */
        list_for_each_entry(acpi_device_bus_id, &acpi_bus_id_list, node) {
-               if(!strcmp(acpi_device_bus_id->bus_id, device->flags.hardware_id? device->pnp.hardware_id : "device")) {
-                       acpi_device_bus_id->instance_no ++;
+               if (!strcmp(acpi_device_bus_id->bus_id,
+                           acpi_device_hid(device))) {
+                       acpi_device_bus_id->instance_no++;
                        found = 1;
                        kfree(new_bus_id);
                        break;
                }
        }
-       if(!found) {
+       if (!found) {
                acpi_device_bus_id = new_bus_id;
-               strcpy(acpi_device_bus_id->bus_id, device->flags.hardware_id ? device->pnp.hardware_id : "device");
+               strcpy(acpi_device_bus_id->bus_id, acpi_device_hid(device));
                acpi_device_bus_id->instance_no = 0;
                list_add_tail(&acpi_device_bus_id->node, &acpi_bus_id_list);
        }
-       sprintf(device->dev.bus_id, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
+       dev_set_name(&device->dev, "%s:%02x", acpi_device_bus_id->bus_id, acpi_device_bus_id->instance_no);
 
-       if (device->parent) {
+       if (device->parent)
                list_add_tail(&device->node, &device->parent->children);
-               list_add_tail(&device->g_list, &device->parent->g_list);
-       } else
-               list_add_tail(&device->g_list, &acpi_device_list);
+
        if (device->wakeup.flags.valid)
                list_add_tail(&device->wakeup_list, &acpi_wakeup_device_list);
-       spin_unlock(&acpi_device_lock);
+       mutex_unlock(&acpi_device_lock);
 
        if (device->parent)
-               device->dev.parent = &parent->dev;
+               device->dev.parent = &device->parent->dev;
        device->dev.bus = &acpi_bus_type;
-       device_initialize(&device->dev);
        device->dev.release = &acpi_device_release;
-       result = device_add(&device->dev);
-       if(result) {
-               printk(KERN_ERR PREFIX "Error adding device %s", device->dev.bus_id);
+       result = device_register(&device->dev);
+       if (result) {
+               dev_err(&device->dev, "Error registering device\n");
                goto end;
        }
 
        result = acpi_device_setup_files(device);
-       if(result)
-               ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Error creating sysfs interface for device %s\n", device->dev.bus_id));
+       if (result)
+               printk(KERN_ERR PREFIX "Error creating sysfs interface for device %s\n",
+                      dev_name(&device->dev));
 
        device->removal_type = ACPI_BUS_REMOVAL_NORMAL;
        return 0;
-  end:
-       spin_lock(&acpi_device_lock);
-       if (device->parent) {
+end:
+       mutex_lock(&acpi_device_lock);
+       if (device->parent)
                list_del(&device->node);
-               list_del(&device->g_list);
-       } else
-               list_del(&device->g_list);
        list_del(&device->wakeup_list);
-       spin_unlock(&acpi_device_lock);
+       mutex_unlock(&acpi_device_lock);
        return result;
 }
 
 static void acpi_device_unregister(struct acpi_device *device, int type)
 {
-       spin_lock(&acpi_device_lock);
-       if (device->parent) {
+       mutex_lock(&acpi_device_lock);
+       if (device->parent)
                list_del(&device->node);
-               list_del(&device->g_list);
-       } else
-               list_del(&device->g_list);
 
        list_del(&device->wakeup_list);
-       spin_unlock(&acpi_device_lock);
+       mutex_unlock(&acpi_device_lock);
 
        acpi_detach_data(device->handle, acpi_bus_data_handler);
 
@@ -507,7 +538,7 @@ static void acpi_device_unregister(struct acpi_device *device, int type)
  * @device: the device to add and initialize
  * @driver: driver for the device
  *
- * Used to initialize a device via its device driver.  Called whenever a 
+ * Used to initialize a device via its device driver.  Called whenever a
  * driver is bound to a device.  Invokes the driver's add() ops.
  */
 static int
@@ -515,7 +546,6 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
 {
        int result = 0;
 
-
        if (!device || !driver)
                return -EINVAL;
 
@@ -525,7 +555,7 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
        result = driver->ops.add(device);
        if (result) {
                device->driver = NULL;
-               acpi_driver_data(device) = NULL;
+               device->driver_data = NULL;
                return result;
        }
 
@@ -600,6 +630,33 @@ EXPORT_SYMBOL(acpi_bus_unregister_driver);
 /* --------------------------------------------------------------------------
                                  Device Enumeration
    -------------------------------------------------------------------------- */
+static struct acpi_device *acpi_bus_get_parent(acpi_handle handle)
+{
+       acpi_status status;
+       int ret;
+       struct acpi_device *device;
+
+       /*
+        * Fixed hardware devices do not appear in the namespace and do not
+        * have handles, but we fabricate acpi_devices for them, so we have
+        * to deal with them specially.
+        */
+       if (handle == NULL)
+               return acpi_root;
+
+       do {
+               status = acpi_get_parent(handle, &handle);
+               if (status == AE_NULL_ENTRY)
+                       return NULL;
+               if (ACPI_FAILURE(status))
+                       return acpi_root;
+
+               ret = acpi_bus_get_device(handle, &device);
+               if (ret == 0)
+                       return device;
+       } while (1);
+}
+
 acpi_status
 acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
 {
@@ -623,7 +680,7 @@ acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
 }
 EXPORT_SYMBOL_GPL(acpi_bus_get_ejd);
 
-void acpi_bus_data_handler(acpi_handle handle, u32 function, void *context)
+void acpi_bus_data_handler(acpi_handle handle, void *context)
 {
 
        /* TBD */
@@ -686,21 +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;
-       union acpi_object in_arg[3];
-       struct acpi_object_list arg_list = { 3, in_arg };
-       acpi_status psw_status = AE_OK;
-
        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,
+                                       ACPI_NOT_ISR, &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);
@@ -719,50 +795,20 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
        kfree(buffer.pointer);
 
        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.
         * So it is necessary to call _DSW object first. Only when it is not
         * present will the _PSW object used.
         */
-       /*
-        * Three agruments are needed for the _DSW object.
-        * Argument 0: enable/disable the wake capabilities
-        * When _DSW object is called to disable the wake capabilities, maybe
-        * the first argument is filled. The value of the other two agruments
-        * is meaningless.
-        */
-       in_arg[0].type = ACPI_TYPE_INTEGER;
-       in_arg[0].integer.value = 0;
-       in_arg[1].type = ACPI_TYPE_INTEGER;
-       in_arg[1].integer.value = 0;
-       in_arg[2].type = ACPI_TYPE_INTEGER;
-       in_arg[2].integer.value = 0;
-       psw_status = acpi_evaluate_object(device->handle, "_DSW",
-                                               &arg_list, NULL);
-       if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND))
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in evaluate _DSW\n"));
-       /*
-        * When the _DSW object is not present, OSPM will call _PSW object.
-        */
-       if (psw_status == AE_NOT_FOUND) {
-               /*
-                * Only one agruments is required for the _PSW object.
-                * agrument 0: enable/disable the wake capabilities
-                */
-               arg_list.count = 1;
-               in_arg[0].integer.value = 0;
-               psw_status = acpi_evaluate_object(device->handle, "_PSW",
-                                               &arg_list, NULL);
-               if (ACPI_FAILURE(psw_status) && (psw_status != AE_NOT_FOUND))
-                       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "error in "
-                                               "evaluate _PSW\n"));
-       }
-       /* Power button, Lid switch always enable wakeup */
-       if (!acpi_match_device_ids(device, button_device_ids))
-               device->wakeup.flags.run_wake = 1;
+       psw_error = acpi_device_sleep_wake(device, 0, 0, 0);
+       if (psw_error)
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                               "error in _DSW or _PSW evaluation\n"));
 
-      end:
+end:
        if (ACPI_FAILURE(status))
                device->flags.wake_capable = 0;
        return 0;
@@ -825,6 +871,7 @@ static int acpi_bus_get_power_flags(struct acpi_device *device)
        /* TBD: System wake support and resource requirements. */
 
        device->power.state = ACPI_STATE_UNKNOWN;
+       acpi_bus_get_power(device->handle, &(device->power.state));
 
        return 0;
 }
@@ -840,11 +887,6 @@ static int acpi_bus_get_flags(struct acpi_device *device)
        if (ACPI_SUCCESS(status))
                device->flags.dynamic_status = 1;
 
-       /* Presence of _CID indicates 'compatible_ids' */
-       status = acpi_get_handle(device->handle, "_CID", &temp);
-       if (ACPI_SUCCESS(status))
-               device->flags.compatible_ids = 1;
-
        /* Presence of _RMV indicates 'removable' */
        status = acpi_get_handle(device->handle, "_RMV", &temp);
        if (ACPI_SUCCESS(status))
@@ -882,8 +924,7 @@ static int acpi_bus_get_flags(struct acpi_device *device)
        return 0;
 }
 
-static void acpi_device_get_busid(struct acpi_device *device,
-                                 acpi_handle handle, int type)
+static void acpi_device_get_busid(struct acpi_device *device)
 {
        char bus_id[5] = { '?', 0 };
        struct acpi_buffer buffer = { sizeof(bus_id), bus_id };
@@ -895,10 +936,12 @@ static void acpi_device_get_busid(struct acpi_device *device,
         * The device's Bus ID is simply the object name.
         * TBD: Shouldn't this value be unique (within the ACPI namespace)?
         */
-       switch (type) {
-       case ACPI_BUS_TYPE_SYSTEM:
+       if (ACPI_IS_ROOT_DEVICE(device)) {
                strcpy(device->pnp.bus_id, "ACPI");
-               break;
+               return;
+       }
+
+       switch (device->device_type) {
        case ACPI_BUS_TYPE_POWER_BUTTON:
                strcpy(device->pnp.bus_id, "PWRF");
                break;
@@ -906,7 +949,7 @@ static void acpi_device_get_busid(struct acpi_device *device,
                strcpy(device->pnp.bus_id, "SLPF");
                break;
        default:
-               acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);
+               acpi_get_name(device->handle, ACPI_SINGLE_NAME, &buffer);
                /* Clean up trailing underscores (if any) */
                for (i = 3; i > 1; i--) {
                        if (bus_id[i] == '_')
@@ -919,36 +962,6 @@ static void acpi_device_get_busid(struct acpi_device *device,
        }
 }
 
-static int
-acpi_video_bus_match(struct acpi_device *device)
-{
-       acpi_handle h_dummy;
-
-       if (!device)
-               return -EINVAL;
-
-       /* Since there is no HID, CID for ACPI Video drivers, we have
-        * to check well known required nodes for each feature we support.
-        */
-
-       /* Does this device able to support video switching ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOD", &h_dummy)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy)))
-               return 0;
-
-       /* Does this device able to retrieve a video ROM ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy)))
-               return 0;
-
-       /* Does this device able to configure which video head to be POSTed ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy)))
-               return 0;
-
-       return -ENODEV;
-}
-
 /*
  * acpi_bay_match - see if a device is an ejectable driver bay
  *
@@ -994,157 +1007,171 @@ static int acpi_dock_match(struct acpi_device *device)
        return acpi_get_handle(device->handle, "_DCK", &tmp);
 }
 
-static void acpi_device_set_id(struct acpi_device *device,
-                              struct acpi_device *parent, acpi_handle handle,
-                              int type)
+char *acpi_device_hid(struct acpi_device *device)
+{
+       struct acpi_hardware_id *hid;
+
+       hid = list_first_entry(&device->pnp.ids, struct acpi_hardware_id, list);
+       return hid->id;
+}
+EXPORT_SYMBOL(acpi_device_hid);
+
+static void acpi_add_id(struct acpi_device *device, const char *dev_id)
+{
+       struct acpi_hardware_id *id;
+
+       id = kmalloc(sizeof(*id), GFP_KERNEL);
+       if (!id)
+               return;
+
+       id->id = kmalloc(strlen(dev_id) + 1, GFP_KERNEL);
+       if (!id->id) {
+               kfree(id);
+               return;
+       }
+
+       strcpy(id->id, 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;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
-       char *hid = NULL;
-       char *uid = NULL;
-       struct acpi_compatible_id_list *cid_list = NULL;
-       const char *cid_add = NULL;
        acpi_status status;
+       struct acpi_device_info *info;
+       struct acpica_device_id_list *cid_list;
+       int i;
 
-       switch (type) {
+       switch (device->device_type) {
        case ACPI_BUS_TYPE_DEVICE:
-               status = acpi_get_object_info(handle, &buffer);
+               if (ACPI_IS_ROOT_DEVICE(device)) {
+                       acpi_add_id(device, ACPI_SYSTEM_HID);
+                       break;
+               } else if (ACPI_IS_ROOT_DEVICE(device->parent)) {
+                       /* \_SB_, the only root-level namespace device */
+                       acpi_add_id(device, ACPI_BUS_HID);
+                       strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
+                       strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
+                       break;
+               }
+
+               status = acpi_get_object_info(device->handle, &info);
                if (ACPI_FAILURE(status)) {
                        printk(KERN_ERR PREFIX "%s: Error reading device info\n", __func__);
                        return;
                }
 
-               info = buffer.pointer;
                if (info->valid & ACPI_VALID_HID)
-                       hid = info->hardware_id.value;
-               if (info->valid & ACPI_VALID_UID)
-                       uid = info->unique_id.value;
-               if (info->valid & ACPI_VALID_CID)
-                       cid_list = &info->compatibility_id;
+                       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.
-               */
-               if (ACPI_SUCCESS(acpi_video_bus_match(device)))
-                       cid_add = ACPI_VIDEO_HID;
+               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))
+                       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);
 
                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_HID;
-               break;
-       case ACPI_BUS_TYPE_SYSTEM:
-               hid = ACPI_SYSTEM_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;
        }
 
-       /* 
-        * \_SB
-        * ----
-        * Fix for the system root bus device -- the only root-level device.
+       /*
+        * We build acpi_devices for some objects that don't have _HID or _CID,
+        * e.g., PCI bridges and slots.  Drivers can't bind to these objects,
+        * but we do use them indirectly by traversing the acpi_device tree.
+        * This generic ID isn't useful for driver binding, but it provides
+        * the useful property that "every acpi_device has an ID."
         */
-       if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
-               hid = ACPI_BUS_HID;
-               strcpy(device->pnp.device_name, ACPI_BUS_DEVICE_NAME);
-               strcpy(device->pnp.device_class, ACPI_BUS_CLASS);
-       }
-
-       if (hid) {
-               strcpy(device->pnp.hardware_id, hid);
-               device->flags.hardware_id = 1;
-       }
-       if (uid) {
-               strcpy(device->pnp.unique_id, uid);
-               device->flags.unique_id = 1;
-       }
-       if (cid_list || cid_add) {
-               struct  acpi_compatible_id_list *list;
-               int size = 0;
-               int count = 0;
-
-               if (cid_list) {
-                       size = cid_list->size;
-               } else if (cid_add) {
-                       size = sizeof(struct acpi_compatible_id_list);
-                       cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
-                       if (!cid_list) {
-                               printk(KERN_ERR "Memory allocation error\n");
-                               kfree(buffer.pointer);
-                               return;
-                       } else {
-                               cid_list->count = 0;
-                               cid_list->size = size;
-                       }
-               }
-               if (cid_add)
-                       size += sizeof(struct acpi_compatible_id);
-               list = kmalloc(size, GFP_KERNEL);
-
-               if (list) {
-                       if (cid_list) {
-                               memcpy(list, cid_list, cid_list->size);
-                               count = cid_list->count;
-                       }
-                       if (cid_add) {
-                               strncpy(list->id[count].value, cid_add,
-                                       ACPI_MAX_CID_LENGTH);
-                               count++;
-                               device->flags.compatible_ids = 1;
-                       }
-                       list->size = size;
-                       list->count = count;
-                       device->pnp.cid_list = list;
-               } else
-                       printk(KERN_ERR PREFIX "Memory allocation error\n");
-       }
-
-       kfree(buffer.pointer);
+       if (list_empty(&device->pnp.ids))
+               acpi_add_id(device, "device");
 }
 
-static int acpi_device_set_context(struct acpi_device *device, int type)
+static int acpi_device_set_context(struct acpi_device *device)
 {
-       acpi_status status = AE_OK;
-       int result = 0;
+       acpi_status status;
+
        /*
         * Context
         * -------
         * Attach this 'struct acpi_device' to the ACPI object.  This makes
-        * resolutions from handle->device very efficient.  Note that we need
-        * to be careful with fixed-feature devices as they all attach to the
-        * root object.
+        * resolutions from handle->device very efficient.  Fixed hardware
+        * devices have no handles, so we skip them.
         */
-       if (type != ACPI_BUS_TYPE_POWER_BUTTON &&
-           type != ACPI_BUS_TYPE_SLEEP_BUTTON) {
-               status = acpi_attach_data(device->handle,
-                                         acpi_bus_data_handler, device);
+       if (!device->handle)
+               return 0;
 
-               if (ACPI_FAILURE(status)) {
-                       printk(KERN_ERR PREFIX "Error attaching device data\n");
-                       result = -ENODEV;
-               }
-       }
-       return result;
+       status = acpi_attach_data(device->handle,
+                                 acpi_bus_data_handler, device);
+       if (ACPI_SUCCESS(status))
+               return 0;
+
+       printk(KERN_ERR PREFIX "Error attaching device data\n");
+       return -ENODEV;
 }
 
 static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
@@ -1170,31 +1197,14 @@ static int acpi_bus_remove(struct acpi_device *dev, int rmdevice)
        return 0;
 }
 
-static int
-acpi_is_child_device(struct acpi_device *device,
-                       int (*matcher)(struct acpi_device *))
-{
-       int result = -ENODEV;
-
-       do {
-               if (ACPI_SUCCESS(matcher(device)))
-                       return AE_OK;
-       } while ((device = device->parent));
-
-       return result;
-}
-
-static int
-acpi_add_single_object(struct acpi_device **child,
-                      struct acpi_device *parent, acpi_handle handle, int type,
-                       struct acpi_bus_ops *ops)
+static int acpi_add_single_object(struct acpi_device **child,
+                                 acpi_handle handle, int type,
+                                 unsigned long long sta,
+                                 struct acpi_bus_ops *ops)
 {
-       int result = 0;
-       struct acpi_device *device = NULL;
-
-
-       if (!child)
-               return -EINVAL;
+       int result;
+       struct acpi_device *device;
+       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
 
        device = kzalloc(sizeof(struct acpi_device), GFP_KERNEL);
        if (!device) {
@@ -1202,72 +1212,31 @@ acpi_add_single_object(struct acpi_device **child,
                return -ENOMEM;
        }
 
+       INIT_LIST_HEAD(&device->pnp.ids);
+       device->device_type = type;
        device->handle = handle;
-       device->parent = parent;
+       device->parent = acpi_bus_get_parent(handle);
        device->bus_ops = *ops; /* workround for not call .start */
+       STRUCT_TO_INT(device->status) = sta;
 
-
-       acpi_device_get_busid(device, handle, type);
+       acpi_device_get_busid(device);
 
        /*
         * Flags
         * -----
-        * Get prior to calling acpi_bus_get_status() so we know whether
-        * or not _STA is present.  Note that we only look for object
-        * handles -- cannot evaluate objects until we know the device is
-        * present and properly initialized.
+        * Note that we only look for object handles -- cannot evaluate objects
+        * until we know the device is present and properly initialized.
         */
        result = acpi_bus_get_flags(device);
        if (result)
                goto end;
 
        /*
-        * Status
-        * ------
-        * See if the device is present.  We always assume that non-Device
-        * and non-Processor objects (e.g. thermal zones, power resources,
-        * etc.) are present, functioning, etc. (at least when parent object
-        * is present).  Note that _STA has a different meaning for some
-        * objects (e.g. power resources) so we need to be careful how we use
-        * it.
-        */
-       switch (type) {
-       case ACPI_BUS_TYPE_PROCESSOR:
-       case ACPI_BUS_TYPE_DEVICE:
-               result = acpi_bus_get_status(device);
-               if (ACPI_FAILURE(result)) {
-                       result = -ENODEV;
-                       goto end;
-               }
-               if (!device->status.present) {
-                       /* Bay and dock should be handled even if absent */
-                       if (!ACPI_SUCCESS(
-                            acpi_is_child_device(device, acpi_bay_match)) &&
-                           !ACPI_SUCCESS(
-                            acpi_is_child_device(device, acpi_dock_match))) {
-                                       result = -ENODEV;
-                                       goto end;
-                       }
-               }
-               break;
-       default:
-               STRUCT_TO_INT(device->status) =
-                   ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
-                   ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
-               break;
-       }
-
-       /*
         * Initialize Device
         * -----------------
         * TBD: Synch with Core's enumeration/initialization process.
         */
-
-       /*
-        * Hardware ID, Unique ID, & Bus Address
-        * -------------------------------------
-        */
-       acpi_device_set_id(device, parent, handle, type);
+       acpi_device_set_id(device);
 
        /*
         * Power Management
@@ -1299,10 +1268,10 @@ acpi_add_single_object(struct acpi_device **child,
                        goto end;
        }
 
-       if ((result = acpi_device_set_context(device, type)))
+       if ((result = acpi_device_set_context(device)))
                goto end;
 
-       result = acpi_device_register(device, parent);
+       result = acpi_device_register(device);
 
        /*
         * Bind _ADR-Based Devices when hot add
@@ -1312,166 +1281,162 @@ acpi_add_single_object(struct acpi_device **child,
                        device->parent->ops.bind(device);
        }
 
-      end:
-       if (!result)
+end:
+       if (!result) {
+               acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                       "Adding %s [%s] parent %s\n", dev_name(&device->dev),
+                        (char *) buffer.pointer,
+                        device->parent ? dev_name(&device->parent->dev) :
+                                         "(null)"));
+               kfree(buffer.pointer);
                *child = device;
-       else {
-               kfree(device->pnp.cid_list);
-               kfree(device);
-       }
+       } else
+               acpi_device_release(&device->dev);
 
        return result;
 }
 
-static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
+#define ACPI_STA_DEFAULT (ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED | \
+                         ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING)
+
+static int acpi_bus_type_and_status(acpi_handle handle, int *type,
+                                   unsigned long long *sta)
 {
-       acpi_status status = AE_OK;
-       struct acpi_device *parent = NULL;
-       struct acpi_device *child = NULL;
-       acpi_handle phandle = NULL;
-       acpi_handle chandle = NULL;
-       acpi_object_type type = 0;
-       u32 level = 1;
+       acpi_status status;
+       acpi_object_type acpi_type;
 
+       status = acpi_get_type(handle, &acpi_type);
+       if (ACPI_FAILURE(status))
+               return -ENODEV;
 
-       if (!start)
-               return -EINVAL;
+       switch (acpi_type) {
+       case ACPI_TYPE_ANY:             /* for ACPI_ROOT_OBJECT */
+       case ACPI_TYPE_DEVICE:
+               *type = ACPI_BUS_TYPE_DEVICE;
+               status = acpi_bus_get_status_handle(handle, sta);
+               if (ACPI_FAILURE(status))
+                       return -ENODEV;
+               break;
+       case ACPI_TYPE_PROCESSOR:
+               *type = ACPI_BUS_TYPE_PROCESSOR;
+               status = acpi_bus_get_status_handle(handle, sta);
+               if (ACPI_FAILURE(status))
+                       return -ENODEV;
+               break;
+       case ACPI_TYPE_THERMAL:
+               *type = ACPI_BUS_TYPE_THERMAL;
+               *sta = ACPI_STA_DEFAULT;
+               break;
+       case ACPI_TYPE_POWER:
+               *type = ACPI_BUS_TYPE_POWER;
+               *sta = ACPI_STA_DEFAULT;
+               break;
+       default:
+               return -ENODEV;
+       }
 
-       parent = start;
-       phandle = start->handle;
+       return 0;
+}
 
-       /*
-        * Parse through the ACPI namespace, identify all 'devices', and
-        * create a new 'struct acpi_device' for each.
-        */
-       while ((level > 0) && parent) {
+static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl,
+                                     void *context, void **return_value)
+{
+       struct acpi_bus_ops *ops = context;
+       int type;
+       unsigned long long sta;
+       struct acpi_device *device;
+       acpi_status status;
+       int result;
 
-               status = acpi_get_next_object(ACPI_TYPE_ANY, phandle,
-                                             chandle, &chandle);
+       result = acpi_bus_type_and_status(handle, &type, &sta);
+       if (result)
+               return AE_OK;
 
-               /*
-                * If this scope is exhausted then move our way back up.
-                */
-               if (ACPI_FAILURE(status)) {
-                       level--;
-                       chandle = phandle;
-                       acpi_get_parent(phandle, &phandle);
-                       if (parent->parent)
-                               parent = parent->parent;
-                       continue;
-               }
+       if (!(sta & ACPI_STA_DEVICE_PRESENT) &&
+           !(sta & ACPI_STA_DEVICE_FUNCTIONING))
+               return AE_CTRL_DEPTH;
 
-               status = acpi_get_type(chandle, &type);
-               if (ACPI_FAILURE(status))
-                       continue;
+       /*
+        * We may already have an acpi_device from a previous enumeration.  If
+        * so, we needn't add it again, but we may still have to start it.
+        */
+       device = NULL;
+       acpi_bus_get_device(handle, &device);
+       if (ops->acpi_op_add && !device)
+               acpi_add_single_object(&device, handle, type, sta, ops);
 
-               /*
-                * If this is a scope object then parse it (depth-first).
-                */
-               if (type == ACPI_TYPE_LOCAL_SCOPE) {
-                       level++;
-                       phandle = chandle;
-                       chandle = NULL;
-                       continue;
-               }
+       if (!device)
+               return AE_CTRL_DEPTH;
 
-               /*
-                * We're only interested in objects that we consider 'devices'.
-                */
-               switch (type) {
-               case ACPI_TYPE_DEVICE:
-                       type = ACPI_BUS_TYPE_DEVICE;
-                       break;
-               case ACPI_TYPE_PROCESSOR:
-                       type = ACPI_BUS_TYPE_PROCESSOR;
-                       break;
-               case ACPI_TYPE_THERMAL:
-                       type = ACPI_BUS_TYPE_THERMAL;
-                       break;
-               case ACPI_TYPE_POWER:
-                       type = ACPI_BUS_TYPE_POWER;
-                       break;
-               default:
-                       continue;
-               }
+       if (ops->acpi_op_start && !(ops->acpi_op_add)) {
+               status = acpi_start_single_object(device);
+               if (ACPI_FAILURE(status))
+                       return AE_CTRL_DEPTH;
+       }
 
-               if (ops->acpi_op_add)
-                       status = acpi_add_single_object(&child, parent,
-                               chandle, type, ops);
-               else
-                       status = acpi_bus_get_device(chandle, &child);
+       if (!*return_value)
+               *return_value = device;
+       return AE_OK;
+}
 
-               if (ACPI_FAILURE(status))
-                       continue;
+static int acpi_bus_scan(acpi_handle handle, struct acpi_bus_ops *ops,
+                        struct acpi_device **child)
+{
+       acpi_status status;
+       void *device = NULL;
 
-               if (ops->acpi_op_start && !(ops->acpi_op_add)) {
-                       status = acpi_start_single_object(child);
-                       if (ACPI_FAILURE(status))
-                               continue;
-               }
+       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, NULL, ops, &device);
 
-               /*
-                * If the device is present, enabled, and functioning then
-                * parse its scope (depth-first).  Note that we need to
-                * represent absent devices to facilitate PnP notifications
-                * -- but only the subtree head (not all of its children,
-                * which will be enumerated when the parent is inserted).
-                *
-                * TBD: Need notifications and other detection mechanisms
-                *      in place before we can fully implement this.
-                */
-               if (child->status.present) {
-                       status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
-                                                     NULL, NULL);
-                       if (ACPI_SUCCESS(status)) {
-                               level++;
-                               phandle = chandle;
-                               chandle = NULL;
-                               parent = child;
-                       }
-               }
-       }
+       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)
 {
-       int result;
        struct acpi_bus_ops ops;
 
        memset(&ops, 0, sizeof(ops));
        ops.acpi_op_add = 1;
 
-       result = acpi_add_single_object(child, parent, handle, type, &ops);
-       if (!result)
-               result = acpi_bus_scan(*child, &ops);
-
-       return result;
+       return acpi_bus_scan(handle, &ops, child);
 }
-
 EXPORT_SYMBOL(acpi_bus_add);
 
 int acpi_bus_start(struct acpi_device *device)
 {
-       int result;
        struct acpi_bus_ops ops;
 
-
        if (!device)
                return -EINVAL;
 
-       result = acpi_start_single_object(device);
-       if (!result) {
-               memset(&ops, 0, sizeof(ops));
-               ops.acpi_op_start = 1;
-               result = acpi_bus_scan(device, &ops);
-       }
-       return result;
-}
+       memset(&ops, 0, sizeof(ops));
+       ops.acpi_op_start = 1;
 
+       return acpi_bus_scan(device->handle, &ops, NULL);
+}
 EXPORT_SYMBOL(acpi_bus_start);
 
 int acpi_bus_trim(struct acpi_device *start, int rmdevice)
@@ -1529,16 +1494,12 @@ int acpi_bus_trim(struct acpi_device *start, int rmdevice)
 }
 EXPORT_SYMBOL_GPL(acpi_bus_trim);
 
-
-static int acpi_bus_scan_fixed(struct acpi_device *root)
+static int acpi_bus_scan_fixed(void)
 {
        int result = 0;
        struct acpi_device *device = NULL;
        struct acpi_bus_ops ops;
 
-       if (!root)
-               return -ENODEV;
-
        memset(&ops, 0, sizeof(ops));
        ops.acpi_op_add = 1;
        ops.acpi_op_start = 1;
@@ -1547,33 +1508,27 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
         * Enumerate all fixed-feature devices.
         */
        if ((acpi_gbl_FADT.flags & ACPI_FADT_POWER_BUTTON) == 0) {
-               result = acpi_add_single_object(&device, acpi_root,
-                                               NULL,
+               result = acpi_add_single_object(&device, NULL,
                                                ACPI_BUS_TYPE_POWER_BUTTON,
+                                               ACPI_STA_DEFAULT,
                                                &ops);
        }
 
        if ((acpi_gbl_FADT.flags & ACPI_FADT_SLEEP_BUTTON) == 0) {
-               result = acpi_add_single_object(&device, acpi_root,
-                                               NULL,
+               result = acpi_add_single_object(&device, NULL,
                                                ACPI_BUS_TYPE_SLEEP_BUTTON,
+                                               ACPI_STA_DEFAULT,
                                                &ops);
        }
 
        return result;
 }
 
-int __init acpi_boot_ec_enable(void);
-
-static int __init acpi_scan_init(void)
+int __init acpi_scan_init(void)
 {
        int result;
        struct acpi_bus_ops ops;
 
-
-       if (acpi_disabled)
-               return 0;
-
        memset(&ops, 0, sizeof(ops));
        ops.acpi_op_add = 1;
        ops.acpi_op_start = 1;
@@ -1585,29 +1540,15 @@ static int __init acpi_scan_init(void)
        }
 
        /*
-        * Create the root device in the bus's device tree
-        */
-       result = acpi_add_single_object(&acpi_root, NULL, ACPI_ROOT_OBJECT,
-                                       ACPI_BUS_TYPE_SYSTEM, &ops);
-       if (result)
-               goto Done;
-
-       /*
         * Enumerate devices in the ACPI namespace.
         */
-       result = acpi_bus_scan_fixed(acpi_root);
-
-       /* EC region might be needed at bus_scan, so enable it now */
-       acpi_boot_ec_enable();
+       result = acpi_bus_scan(ACPI_ROOT_OBJECT, &ops, &acpi_root);
 
        if (!result)
-               result = acpi_bus_scan(acpi_root, &ops);
+               result = acpi_bus_scan_fixed();
 
        if (result)
                acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
 
-      Done:
        return result;
 }
-
-subsys_initcall(acpi_scan_init);