ACPI: remove unnecessary argument checking
[safe/jmp/linux-2.6] / drivers / acpi / scan.c
index d9d531c..f2e2834 100644 (file)
@@ -6,9 +6,12 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/acpi.h>
+#include <linux/signal.h>
+#include <linux/kthread.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");
@@ -21,7 +24,7 @@ extern struct acpi_device *acpi_root;
 
 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{
@@ -39,27 +42,33 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
                           int size)
 {
        int len;
+       int count;
 
-       if (!acpi_dev->flags.hardware_id)
+       if (!acpi_dev->flags.hardware_id && !acpi_dev->flags.compatible_ids)
                return -ENODEV;
 
-       len = snprintf(modalias, size, "acpi:%s:",
-                      acpi_dev->pnp.hardware_id);
-       if (len < 0 || len >= size)
-               return -EINVAL;
+       len = snprintf(modalias, size, "acpi:");
        size -= len;
 
+       if (acpi_dev->flags.hardware_id) {
+               count = snprintf(&modalias[len], size, "%s:",
+                                acpi_dev->pnp.hardware_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;
+               struct acpica_device_id_list *cid_list;
                int i;
-               int count;
 
                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);
+                                        cid_list->ids[i].string);
                        if (count < 0 || count >= size) {
-                               printk(KERN_ERR "acpi: %s cid[%i] exceeds event buffer size",
+                               printk(KERN_ERR PREFIX "%s cid[%i] exceeds event buffer size",
                                       acpi_dev->pnp.device_name, i);
                                break;
                        }
@@ -86,17 +95,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;
+       }
 
-       if (lockable) {
+       /* 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 (device->flags.lockable) {
                arg_list.count = 1;
                arg_list.pointer = &arg;
                arg.type = ACPI_TYPE_INTEGER;
@@ -112,24 +140,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);
 
@@ -148,18 +172,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;
 }
 
@@ -180,12 +194,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);
@@ -199,21 +213,21 @@ 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) {
+       if (dev->flags.hardware_id) {
                result = device_create_file(&dev->dev, &dev_attr_hid);
-               if(result)
+               if (result)
                        goto end;
        }
 
-       if (dev->flags.hardware_id || dev->flags.compatible_ids){
+       if (dev->flags.hardware_id || dev->flags.compatible_ids) {
                result = device_create_file(&dev->dev, &dev_attr_modalias);
-               if(result)
+               if (result)
                        goto end;
        }
 
@@ -224,7 +238,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;
 }
 
@@ -244,9 +258,9 @@ static void acpi_device_remove_files(struct acpi_device *dev)
        if (dev->flags.hardware_id || dev->flags.compatible_ids)
                device_remove_file(&dev->dev, &dev_attr_modalias);
 
-       if(dev->flags.hardware_id)
+       if (dev->flags.hardware_id)
                device_remove_file(&dev->dev, &dev_attr_hid);
-       if(dev->handle)
+       if (dev->handle)
                device_remove_file(&dev->dev, &dev_attr_path);
 }
 /* --------------------------------------------------------------------------
@@ -258,6 +272,13 @@ int acpi_match_device_ids(struct acpi_device *device,
 {
        const struct acpi_device_id *id;
 
+       /*
+        * If the device is not present, it is unnecessary to load device
+        * driver for it.
+        */
+       if (!device->status.present)
+               return -ENODEV;
+
        if (device->flags.hardware_id) {
                for (id = ids; id->id[0]; id++) {
                        if (!strcmp((char*)id->id, device->pnp.hardware_id))
@@ -266,14 +287,14 @@ int acpi_match_device_ids(struct acpi_device *device,
        }
 
        if (device->flags.compatible_ids) {
-               struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
+               struct acpica_device_id_list *cid_list = device->pnp.cid_list;
                int i;
 
                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))
+                                           cid_list->ids[i].string))
                                        return 0;
                        }
                }
@@ -288,6 +309,10 @@ static void acpi_device_release(struct device *dev)
        struct acpi_device *acpi_dev = to_acpi_device(dev);
 
        kfree(acpi_dev->pnp.cid_list);
+       if (acpi_dev->flags.hardware_id)
+               kfree(acpi_dev->pnp.hardware_id);
+       if (acpi_dev->flags.unique_id)
+               kfree(acpi_dev->pnp.unique_id);
        kfree(acpi_dev);
 }
 
@@ -334,6 +359,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)
@@ -346,6 +425,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));
@@ -360,46 +450,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
         * -------
@@ -407,7 +485,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);
@@ -416,7 +493,7 @@ 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
@@ -429,63 +506,55 @@ static int acpi_device_register(struct acpi_device *device,
                        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");
                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("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);
 
@@ -501,7 +570,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
@@ -509,7 +578,6 @@ acpi_bus_driver_init(struct acpi_device *device, struct acpi_driver *driver)
 {
        int result = 0;
 
-
        if (!device || !driver)
                return -EINVAL;
 
@@ -519,7 +587,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;
        }
 
@@ -609,14 +677,15 @@ acpi_bus_get_ejd(acpi_handle handle, acpi_handle *ejd)
        status = acpi_evaluate_object(handle, "_EJD", NULL, &buffer);
        if (ACPI_SUCCESS(status)) {
                obj = buffer.pointer;
-               status = acpi_get_handle(NULL, obj->string.pointer, ejd);
+               status = acpi_get_handle(ACPI_ROOT_OBJECT, obj->string.pointer,
+                                        ejd);
                kfree(buffer.pointer);
        }
        return status;
 }
 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 */
@@ -670,9 +739,8 @@ acpi_bus_extract_wakeup_device_power_package(struct acpi_device *device,
        device->wakeup.resources.count = package->package.count - 2;
        for (i = 0; i < device->wakeup.resources.count; i++) {
                element = &(package->package.elements[i + 2]);
-               if (element->type != ACPI_TYPE_ANY) {
+               if (element->type != ACPI_TYPE_LOCAL_REFERENCE)
                        return AE_BAD_DATA;
-               }
 
                device->wakeup.resources.handles[i] = element->reference.handle;
        }
@@ -685,6 +753,7 @@ 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;
 
        struct acpi_device_id button_device_ids[] = {
                {"PNP0C0D", 0},
@@ -693,7 +762,6 @@ static int acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
                {"", 0},
        };
 
-
        /* _PRW */
        status = acpi_evaluate_object(device->handle, "_PRW", NULL, &buffer);
        if (ACPI_FAILURE(status)) {
@@ -711,11 +779,23 @@ 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;
+       /* 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.
+        */
+       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"));
+
        /* Power button, Lid switch always enable wakeup */
        if (!acpi_match_device_ids(device, button_device_ids))
                device->wakeup.flags.run_wake = 1;
 
-      end:
+end:
        if (ACPI_FAILURE(status))
                device->flags.wake_capable = 0;
        return 0;
@@ -778,6 +858,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;
 }
@@ -835,8 +916,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 };
@@ -848,7 +928,7 @@ 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) {
+       switch (device->device_type) {
        case ACPI_BUS_TYPE_SYSTEM:
                strcpy(device->pnp.bus_id, "ACPI");
                break;
@@ -859,7 +939,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] == '_')
@@ -872,39 +952,6 @@ static void acpi_device_get_busid(struct acpi_device *device,
        }
 }
 
-static int
-acpi_video_bus_match(struct acpi_device *device)
-{
-       acpi_handle h_dummy1;
-       acpi_handle h_dummy2;
-       acpi_handle h_dummy3;
-
-
-       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_dummy1)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_DOS", &h_dummy2)))
-               return 0;
-
-       /* Does this device able to retrieve a video ROM ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_ROM", &h_dummy1)))
-               return 0;
-
-       /* Does this device able to configure which video head to be POSTed ? */
-       if (ACPI_SUCCESS(acpi_get_handle(device->handle, "_VPO", &h_dummy1)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_GPD", &h_dummy2)) &&
-           ACPI_SUCCESS(acpi_get_handle(device->handle, "_SPD", &h_dummy3)))
-               return 0;
-
-       return -ENODEV;
-}
-
 /*
  * acpi_bay_match - see if a device is an ejectable driver bay
  *
@@ -941,52 +988,119 @@ static int acpi_bay_match(struct acpi_device *device){
        return -ENODEV;
 }
 
-static void acpi_device_set_id(struct acpi_device *device,
-                              struct acpi_device *parent, acpi_handle handle,
-                              int type)
+/*
+ * acpi_dock_match - see if a device has a _DCK method
+ */
+static int acpi_dock_match(struct acpi_device *device)
 {
-       struct acpi_device_info *info;
-       struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+       acpi_handle tmp;
+       return acpi_get_handle(device->handle, "_DCK", &tmp);
+}
+
+static struct acpica_device_id_list*
+acpi_add_cid(
+       struct acpi_device_info         *info,
+       struct acpica_device_id         *new_cid)
+{
+       struct acpica_device_id_list    *cid;
+       char                            *next_id_string;
+       acpi_size                       cid_length;
+       acpi_size                       new_cid_length;
+       u32                             i;
+
+
+       /* Allocate new CID list with room for the new CID */
+
+       if (!new_cid)
+               new_cid_length = info->compatible_id_list.list_size;
+       else if (info->compatible_id_list.list_size)
+               new_cid_length = info->compatible_id_list.list_size +
+                       new_cid->length + sizeof(struct acpica_device_id);
+       else
+               new_cid_length = sizeof(struct acpica_device_id_list) + new_cid->length;
+
+       cid = ACPI_ALLOCATE_ZEROED(new_cid_length);
+       if (!cid) {
+               return NULL;
+       }
+
+       cid->list_size = new_cid_length;
+       cid->count = info->compatible_id_list.count;
+       if (new_cid)
+               cid->count++;
+       next_id_string = (char *) cid->ids + (cid->count * sizeof(struct acpica_device_id));
+
+       /* Copy all existing CIDs */
+
+       for (i = 0; i < info->compatible_id_list.count; i++) {
+               cid_length = info->compatible_id_list.ids[i].length;
+               cid->ids[i].string = next_id_string;
+               cid->ids[i].length = cid_length;
+
+               ACPI_MEMCPY(next_id_string, info->compatible_id_list.ids[i].string,
+                       cid_length);
+
+               next_id_string += cid_length;
+       }
+
+       /* Append the new CID */
+
+       if (new_cid) {
+               cid->ids[i].string = next_id_string;
+               cid->ids[i].length = new_cid->length;
+
+               ACPI_MEMCPY(next_id_string, new_cid->string, new_cid->length);
+       }
+
+       return cid;
+}
+
+static void acpi_device_set_id(struct acpi_device *device)
+{
+       struct acpi_device_info *info = NULL;
        char *hid = NULL;
        char *uid = NULL;
-       struct acpi_compatible_id_list *cid_list = NULL;
+       struct acpica_device_id_list *cid_list = NULL;
+       char *cid_add = NULL;
        acpi_status status;
 
-       switch (type) {
+       switch (device->device_type) {
        case ACPI_BUS_TYPE_DEVICE:
-               status = acpi_get_object_info(handle, &buffer);
+               status = acpi_get_object_info(device->handle, &info);
                if (ACPI_FAILURE(status)) {
-                       printk("%s: Error reading device info\n", __FUNCTION__);
+                       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;
+                       hid = info->hardware_id.string;
                if (info->valid & ACPI_VALID_UID)
-                       uid = info->unique_id.value;
+                       uid = info->unique_id.string;
                if (info->valid & ACPI_VALID_CID)
-                       cid_list = &info->compatibility_id;
+                       cid_list = &info->compatible_id_list;
                if (info->valid & ACPI_VALID_ADR) {
                        device->pnp.bus_address = info->address;
                        device->flags.bus_address = 1;
                }
 
-               if(!(info->valid & (ACPI_VALID_HID | ACPI_VALID_CID))){
-                       status = acpi_video_bus_match(device);
-                       if(ACPI_SUCCESS(status))
-                               hid = ACPI_VIDEO_HID;
+               /* 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_is_video_device(device))
+                       cid_add = ACPI_VIDEO_HID;
+               else if (ACPI_SUCCESS(acpi_bay_match(device)))
+                       cid_add = ACPI_BAY_HID;
+               else if (ACPI_SUCCESS(acpi_dock_match(device)))
+                       cid_add = ACPI_DOCK_HID;
 
-                       status = acpi_bay_match(device);
-                       if (ACPI_SUCCESS(status))
-                               hid = ACPI_BAY_HID;
-               }
                break;
        case ACPI_BUS_TYPE_POWER:
                hid = ACPI_POWER_HID;
                break;
        case ACPI_BUS_TYPE_PROCESSOR:
-               hid = ACPI_PROCESSOR_HID;
+               hid = ACPI_PROCESSOR_OBJECT_HID;
                break;
        case ACPI_BUS_TYPE_SYSTEM:
                hid = ACPI_SYSTEM_HID;
@@ -1002,59 +1116,82 @@ static void acpi_device_set_id(struct acpi_device *device,
                break;
        }
 
-       /* 
+       /*
         * \_SB
         * ----
         * Fix for the system root bus device -- the only root-level device.
         */
-       if (((acpi_handle)parent == ACPI_ROOT_OBJECT) && (type == ACPI_BUS_TYPE_DEVICE)) {
+       if (((acpi_handle)device->parent == ACPI_ROOT_OBJECT) &&
+            (device->device_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;
+               device->pnp.hardware_id = ACPI_ALLOCATE_ZEROED(strlen (hid) + 1);
+               if (device->pnp.hardware_id) {
+                       strcpy(device->pnp.hardware_id, hid);
+                       device->flags.hardware_id = 1;
+               }
        }
+       if (!device->flags.hardware_id)
+               device->pnp.hardware_id = "";
+
        if (uid) {
-               strcpy(device->pnp.unique_id, uid);
-               device->flags.unique_id = 1;
+               device->pnp.unique_id = ACPI_ALLOCATE_ZEROED(strlen (uid) + 1);
+               if (device->pnp.unique_id) {
+                       strcpy(device->pnp.unique_id, uid);
+                       device->flags.unique_id = 1;
+               }
        }
-       if (cid_list) {
-               device->pnp.cid_list = kmalloc(cid_list->size, GFP_KERNEL);
-               if (device->pnp.cid_list)
-                       memcpy(device->pnp.cid_list, cid_list, cid_list->size);
-               else
-                       printk(KERN_ERR "Memory allocation error\n");
+       if (!device->flags.unique_id)
+               device->pnp.unique_id = "";
+
+       if (cid_list || cid_add) {
+               struct acpica_device_id_list *list;
+
+               if (cid_add) {
+                       struct acpica_device_id cid;
+                       cid.length = strlen (cid_add) + 1;
+                       cid.string = cid_add;
+
+                       list = acpi_add_cid(info, &cid);
+               } else {
+                       list = acpi_add_cid(info, NULL);
+               }
+
+               if (list) {
+                       device->pnp.cid_list = list;
+                       if (cid_add)
+                               device->flags.compatible_ids = 1;
+               }
        }
 
-       kfree(buffer.pointer);
+       kfree(info);
 }
 
-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("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)
@@ -1085,12 +1222,9 @@ acpi_add_single_object(struct acpi_device **child,
                       struct acpi_device *parent, acpi_handle handle, int type,
                        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) {
@@ -1098,12 +1232,12 @@ acpi_add_single_object(struct acpi_device **child,
                return -ENOMEM;
        }
 
+       device->device_type = type;
        device->handle = handle;
        device->parent = parent;
        device->bus_ops = *ops; /* workround for not call .start */
 
-
-       acpi_device_get_busid(device, handle, type);
+       acpi_device_get_busid(device);
 
        /*
         * Flags
@@ -1131,8 +1265,21 @@ acpi_add_single_object(struct acpi_device **child,
        case ACPI_BUS_TYPE_PROCESSOR:
        case ACPI_BUS_TYPE_DEVICE:
                result = acpi_bus_get_status(device);
-               if (ACPI_FAILURE(result) || !device->status.present) {
-                       result = -ENOENT;
+               if (ACPI_FAILURE(result)) {
+                       result = -ENODEV;
+                       goto end;
+               }
+               /*
+                * When the device is neither present nor functional, the
+                * device should not be added to Linux ACPI device tree.
+                * When the status of the device is not present but functinal,
+                * it should be added to Linux ACPI tree. For example : bay
+                * device , dock device.
+                * In such conditions it is unncessary to check whether it is
+                * bay device or dock device.
+                */
+               if (!device->status.present && !device->status.functional) {
+                       result = -ENODEV;
                        goto end;
                }
                break;
@@ -1153,7 +1300,7 @@ acpi_add_single_object(struct acpi_device **child,
         * Hardware ID, Unique ID, & Bus Address
         * -------------------------------------
         */
-       acpi_device_set_id(device, parent, handle, type);
+       acpi_device_set_id(device);
 
        /*
         * Power Management
@@ -1185,10 +1332,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
@@ -1198,13 +1345,18 @@ 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;
 }
@@ -1306,7 +1458,12 @@ static int acpi_bus_scan(struct acpi_device *start, struct acpi_bus_ops *ops)
                 * TBD: Need notifications and other detection mechanisms
                 *      in place before we can fully implement this.
                 */
-               if (child->status.present) {
+                /*
+                * When the device is not present but functional, it is also
+                * necessary to scan the children of this device.
+                */
+               if (child->status.present || (!child->status.present &&
+                                       child->status.functional)) {
                        status = acpi_get_next_object(ACPI_TYPE_ANY, chandle,
                                                      NULL, NULL);
                        if (ACPI_SUCCESS(status)) {
@@ -1337,7 +1494,6 @@ acpi_bus_add(struct acpi_device **child,
 
        return result;
 }
-
 EXPORT_SYMBOL(acpi_bus_add);
 
 int acpi_bus_start(struct acpi_device *device)
@@ -1357,7 +1513,6 @@ int acpi_bus_start(struct acpi_device *device)
        }
        return result;
 }
-
 EXPORT_SYMBOL(acpi_bus_start);
 
 int acpi_bus_trim(struct acpi_device *start, int rmdevice)
@@ -1415,16 +1570,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;
@@ -1449,17 +1600,11 @@ static int acpi_bus_scan_fixed(struct acpi_device *root)
        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;
@@ -1481,10 +1626,7 @@ static int __init acpi_scan_init(void)
        /*
         * 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_fixed();
 
        if (!result)
                result = acpi_bus_scan(acpi_root, &ops);
@@ -1492,8 +1634,6 @@ static int __init acpi_scan_init(void)
        if (result)
                acpi_device_unregister(acpi_root, ACPI_BUS_REMOVAL_NORMAL);
 
-      Done:
+Done:
        return result;
 }
-
-subsys_initcall(acpi_scan_init);