r8169: Fix receive buffer length when MTU is between 1515 and 1536
[safe/jmp/linux-2.6] / drivers / acpi / power.c
index c926e7d..22b2979 100644 (file)
@@ -43,6 +43,9 @@
 #include <linux/seq_file.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/acpi_drivers.h>
+#include "sleep.h"
+
+#define PREFIX "ACPI: "
 
 #define _COMPONENT                     ACPI_POWER_COMPONENT
 ACPI_MODULE_NAME("power");
@@ -54,10 +57,6 @@ ACPI_MODULE_NAME("power");
 #define ACPI_POWER_RESOURCE_STATE_ON   0x01
 #define ACPI_POWER_RESOURCE_STATE_UNKNOWN 0xFF
 
-#ifdef MODULE_PARAM_PREFIX
-#undef MODULE_PARAM_PREFIX
-#endif
-#define MODULE_PARAM_PREFIX "acpi."
 int acpi_power_nocheck;
 module_param_named(power_nocheck, acpi_power_nocheck, bool, 000);
 
@@ -198,7 +197,7 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
 
 static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
 {
-       int result = 0, state;
+       int result = 0;
        int found = 0;
        acpi_status status = AE_OK;
        struct acpi_power_resource *resource = NULL;
@@ -240,18 +239,6 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
        if (ACPI_FAILURE(status))
                return -ENODEV;
 
-       if (!acpi_power_nocheck) {
-               /*
-                * If acpi_power_nocheck is set, it is unnecessary to check
-                * the power state after power transition.
-                */
-               result = acpi_power_get_state(resource->device->handle,
-                               &state);
-               if (result)
-                       return result;
-               if (state != ACPI_POWER_RESOURCE_STATE_ON)
-                       return -ENOEXEC;
-       }
        /* Update the power resource's _device_ power state */
        resource->device->power.state = ACPI_STATE_D0;
 
@@ -262,7 +249,7 @@ static int acpi_power_on(acpi_handle handle, struct acpi_device *dev)
 
 static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
 {
-       int result = 0, state;
+       int result = 0;
        acpi_status status = AE_OK;
        struct acpi_power_resource *resource = NULL;
        struct list_head *node, *next;
@@ -297,18 +284,6 @@ static int acpi_power_off_device(acpi_handle handle, struct acpi_device *dev)
        if (ACPI_FAILURE(status))
                return -ENODEV;
 
-       if (!acpi_power_nocheck) {
-               /*
-                * If acpi_power_nocheck is set, it is unnecessary to check
-                * the power state after power transition.
-                */
-               result = acpi_power_get_state(handle, &state);
-               if (result)
-                       return result;
-               if (state != ACPI_POWER_RESOURCE_STATE_OFF)
-                       return -ENOEXEC;
-       }
-
        /* Update the power resource's _device_ power state */
        resource->device->power.state = ACPI_STATE_D3;
 
@@ -389,17 +364,15 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
  */
 int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
 {
-       int i, err;
+       int i, err = 0;
 
        if (!dev || !dev->wakeup.flags.valid)
                return -EINVAL;
 
-       /*
-        * Do not execute the code below twice in a row without calling
-        * acpi_disable_wakeup_device_power() in between for the same device
-        */
-       if (dev->wakeup.flags.prepared)
-               return 0;
+       mutex_lock(&acpi_device_lock);
+
+       if (dev->wakeup.prepare_count++)
+               goto out;
 
        /* Open power resource */
        for (i = 0; i < dev->wakeup.resources.count; i++) {
@@ -407,7 +380,8 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
                if (ret) {
                        printk(KERN_ERR PREFIX "Transition power state\n");
                        dev->wakeup.flags.valid = 0;
-                       return -ENODEV;
+                       err = -ENODEV;
+                       goto err_out;
                }
        }
 
@@ -416,9 +390,13 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
         * in arbitrary power state afterwards.
         */
        err = acpi_device_sleep_wake(dev, 1, sleep_state, 3);
-       if (!err)
-               dev->wakeup.flags.prepared = 1;
 
+ err_out:
+       if (err)
+               dev->wakeup.prepare_count = 0;
+
+ out:
+       mutex_unlock(&acpi_device_lock);
        return err;
 }
 
@@ -430,35 +408,42 @@ int acpi_enable_wakeup_device_power(struct acpi_device *dev, int sleep_state)
  */
 int acpi_disable_wakeup_device_power(struct acpi_device *dev)
 {
-       int i, ret;
+       int i, err = 0;
 
        if (!dev || !dev->wakeup.flags.valid)
                return -EINVAL;
 
+       mutex_lock(&acpi_device_lock);
+
+       if (--dev->wakeup.prepare_count > 0)
+               goto out;
+
        /*
-        * Do not execute the code below twice in a row without calling
-        * acpi_enable_wakeup_device_power() in between for the same device
+        * Executing the code below even if prepare_count is already zero when
+        * the function is called may be useful, for example for initialisation.
         */
-       if (!dev->wakeup.flags.prepared)
-               return 0;
-
-       dev->wakeup.flags.prepared = 0;
+       if (dev->wakeup.prepare_count < 0)
+               dev->wakeup.prepare_count = 0;
 
-       ret = acpi_device_sleep_wake(dev, 0, 0, 0);
-       if (ret)
-               return ret;
+       err = acpi_device_sleep_wake(dev, 0, 0, 0);
+       if (err)
+               goto out;
 
        /* Close power resource */
        for (i = 0; i < dev->wakeup.resources.count; i++) {
-               ret = acpi_power_off_device(dev->wakeup.resources.handles[i], dev);
+               int ret = acpi_power_off_device(
+                               dev->wakeup.resources.handles[i], dev);
                if (ret) {
                        printk(KERN_ERR PREFIX "Transition power state\n");
                        dev->wakeup.flags.valid = 0;
-                       return -ENODEV;
+                       err = -ENODEV;
+                       goto out;
                }
        }
 
-       return ret;
+ out:
+       mutex_unlock(&acpi_device_lock);
+       return err;
 }
 
 /* --------------------------------------------------------------------------
@@ -773,14 +758,10 @@ static int acpi_power_resume(struct acpi_device *device)
        return 0;
 }
 
-static int __init acpi_power_init(void)
+int __init acpi_power_init(void)
 {
        int result = 0;
 
-
-       if (acpi_disabled)
-               return 0;
-
        INIT_LIST_HEAD(&acpi_power_resource_list);
 
        acpi_power_dir = proc_mkdir(ACPI_POWER_CLASS, acpi_root_dir);
@@ -795,5 +776,3 @@ static int __init acpi_power_init(void)
 
        return 0;
 }
-
-subsys_initcall(acpi_power_init);