ACPI: call init_acpi_device_notify() explicitly rather than as initcall
[safe/jmp/linux-2.6] / drivers / acpi / bus.c
index 2d1955c..db9eca8 100644 (file)
 #ifdef CONFIG_X86
 #include <asm/mpspec.h>
 #endif
+#include <linux/pci.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
 
+#include "internal.h"
+
 #define _COMPONENT             ACPI_BUS_COMPONENT
 ACPI_MODULE_NAME("bus");
 
@@ -47,6 +50,23 @@ EXPORT_SYMBOL(acpi_root_dir);
 
 #define STRUCT_TO_INT(s)       (*((int*)&s))
 
+static int set_power_nocheck(const struct dmi_system_id *id)
+{
+       printk(KERN_NOTICE PREFIX "%s detected - "
+               "disable power check in power transistion\n", id->ident);
+       acpi_power_nocheck = 1;
+       return 0;
+}
+static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
+       {
+       set_power_nocheck, "HP Pavilion 05", {
+       DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
+       DMI_MATCH(DMI_SYS_VENDOR, "HP Pavilion 05"),
+       DMI_MATCH(DMI_PRODUCT_VERSION, "2001211RE101GLEND") }, NULL},
+       {},
+};
+
+
 /* --------------------------------------------------------------------------
                                 Device Management
    -------------------------------------------------------------------------- */
@@ -76,7 +96,7 @@ EXPORT_SYMBOL(acpi_bus_get_device);
 int acpi_bus_get_status(struct acpi_device *device)
 {
        acpi_status status = AE_OK;
-       unsigned long sta = 0;
+       unsigned long long sta = 0;
 
 
        if (!device)
@@ -94,21 +114,21 @@ int acpi_bus_get_status(struct acpi_device *device)
        }
 
        /*
-        * Otherwise we assume the status of our parent (unless we don't
-        * have one, in which case status is implied).
+        * According to ACPI spec some device can be present and functional
+        * even if the parent is not present but functional.
+        * In such conditions the child device should not inherit the status
+        * from the parent.
         */
-       else if (device->parent)
-               device->status = device->parent->status;
        else
                STRUCT_TO_INT(device->status) =
                    ACPI_STA_DEVICE_PRESENT | ACPI_STA_DEVICE_ENABLED |
                    ACPI_STA_DEVICE_UI      | ACPI_STA_DEVICE_FUNCTIONING;
 
        if (device->status.functional && !device->status.present) {
-               printk(KERN_WARNING PREFIX "Device [%s] status [%08x]: "
-                      "functional but not present; setting present\n",
-                      device->pnp.bus_id, (u32) STRUCT_TO_INT(device->status));
-               device->status.present = 1;
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]: "
+                      "functional but not present;\n",
+                       device->pnp.bus_id,
+                       (u32) STRUCT_TO_INT(device->status)));
        }
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] status [%08x]\n",
@@ -154,7 +174,7 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
        int result = 0;
        acpi_status status = 0;
        struct acpi_device *device = NULL;
-       unsigned long psc = 0;
+       unsigned long long psc = 0;
 
 
        result = acpi_bus_get_device(handle, &device);
@@ -222,7 +242,19 @@ int acpi_bus_set_power(acpi_handle handle, int state)
        /*
         * Get device's current power state
         */
-       acpi_bus_get_power(device->handle, &device->power.state);
+       if (!acpi_power_nocheck) {
+               /*
+                * Maybe the incorrect power state is returned on the bogus
+                * bios, which is different with the real power state.
+                * For example: the bios returns D0 state and the real power
+                * state is D3. OS expects to set the device to D0 state. In
+                * such case if OS uses the power state returned by the BIOS,
+                * the device can't be transisted to the correct power state.
+                * So if the acpi_power_nocheck is set, it is unnecessary to
+                * get the power state by calling acpi_bus_get_power.
+                */
+               acpi_bus_get_power(device->handle, &device->power.state);
+       }
        if ((state == device->power.state) && !device->flags.force_power_state) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
                                  state));
@@ -294,6 +326,28 @@ int acpi_bus_set_power(acpi_handle handle, int state)
 
 EXPORT_SYMBOL(acpi_bus_set_power);
 
+bool acpi_bus_power_manageable(acpi_handle handle)
+{
+       struct acpi_device *device;
+       int result;
+
+       result = acpi_bus_get_device(handle, &device);
+       return result ? false : device->flags.power_manageable;
+}
+
+EXPORT_SYMBOL(acpi_bus_power_manageable);
+
+bool acpi_bus_can_wakeup(acpi_handle handle)
+{
+       struct acpi_device *device;
+       int result;
+
+       result = acpi_bus_get_device(handle, &device);
+       return result ? false : device->wakeup.flags.valid;
+}
+
+EXPORT_SYMBOL(acpi_bus_can_wakeup);
+
 /* --------------------------------------------------------------------------
                                 Event Management
    -------------------------------------------------------------------------- */
@@ -473,6 +527,19 @@ static int acpi_bus_check_scope(struct acpi_device *device)
        return 0;
 }
 
+static BLOCKING_NOTIFIER_HEAD(acpi_bus_notify_list);
+int register_acpi_bus_notifier(struct notifier_block *nb)
+{
+       return blocking_notifier_chain_register(&acpi_bus_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(register_acpi_bus_notifier);
+
+void unregister_acpi_bus_notifier(struct notifier_block *nb)
+{
+       blocking_notifier_chain_unregister(&acpi_bus_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_acpi_bus_notifier);
+
 /**
  * acpi_bus_notify
  * ---------------
@@ -483,6 +550,8 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
        int result = 0;
        struct acpi_device *device = NULL;
 
+       blocking_notifier_call_chain(&acpi_bus_notify_list,
+               type, (void *)handle);
 
        if (acpi_bus_get_device(handle, &device))
                return;
@@ -611,7 +680,7 @@ static int __init acpi_bus_init_irq(void)
        return 0;
 }
 
-acpi_native_uint acpi_gbl_permanent_mmap;
+u8 acpi_gbl_permanent_mmap;
 
 
 void __init acpi_early_init(void)
@@ -707,7 +776,7 @@ static int __init acpi_bus_init(void)
                       "Unable to initialize ACPI OS objects\n");
                goto error1;
        }
-#ifdef CONFIG_ACPI_EC
+
        /*
         * ACPI 2.0 requires the EC driver to be loaded and work before
         * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
@@ -718,7 +787,6 @@ static int __init acpi_bus_init(void)
         */
        status = acpi_ec_ecdt_probe();
        /* Ignore result. Not having an ECDT is not fatal. */
-#endif
 
        status = acpi_initialize_objects(ACPI_FULL_INITIALIZATION);
        if (ACPI_FAILURE(status)) {
@@ -726,6 +794,12 @@ static int __init acpi_bus_init(void)
                goto error1;
        }
 
+       /*
+        * Maybe EC region is required at bus_scan/acpi_get_devices. So it
+        * is necessary to enable it as early as possible.
+        */
+       acpi_boot_ec_enable();
+
        printk(KERN_INFO PREFIX "Interpreter enabled\n");
 
        /* Initialize sleep structures */
@@ -781,9 +855,11 @@ static int __init acpi_init(void)
                acpi_kobj = NULL;
        }
 
+       init_acpi_device_notify();
        result = acpi_bus_init();
 
        if (!result) {
+               pci_mmcfg_late_init();
                if (!(pm_flags & PM_APM))
                        pm_flags |= PM_ACPI;
                else {
@@ -795,6 +871,20 @@ static int __init acpi_init(void)
        } else
                disable_acpi();
 
+       if (acpi_disabled)
+               return result;
+
+       /*
+        * If the laptop falls into the DMI check table, the power state check
+        * will be disabled in the course of device power transistion.
+        */
+       dmi_check_system(power_nocheck_dmi_table);
+
+       acpi_scan_init();
+       acpi_ec_init();
+       acpi_power_init();
+       acpi_system_init();
+       acpi_debug_init();
        return result;
 }