ACPI: Thermal: Drop concurrent thermal checks
[safe/jmp/linux-2.6] / drivers / acpi / bus.c
index f4a36d3..9ba778a 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
+#include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/sched.h>
 #include <linux/pm.h>
 #include <acpi/acpi_drivers.h>
 
 #define _COMPONENT             ACPI_BUS_COMPONENT
-ACPI_MODULE_NAME("acpi_bus")
+ACPI_MODULE_NAME("bus");
 #ifdef CONFIG_X86
 extern void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger);
 #endif
 
-struct fadt_descriptor acpi_fadt;
-EXPORT_SYMBOL(acpi_fadt);
-
 struct acpi_device *acpi_root;
 struct proc_dir_entry *acpi_root_dir;
 EXPORT_SYMBOL(acpi_root_dir);
@@ -60,20 +58,20 @@ int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
 {
        acpi_status status = AE_OK;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_get_device");
 
        if (!device)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        /* TBD: Support fixed-feature devices */
 
        status = acpi_get_data(handle, acpi_bus_data_handler, (void **)device);
        if (ACPI_FAILURE(status) || !*device) {
-               ACPI_EXCEPTION((AE_INFO, status, "No context for object [%p]", handle));
-               return_VALUE(-ENODEV);
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
+                                 handle));
+               return -ENODEV;
        }
 
-       return_VALUE(0);
+       return 0;
 }
 
 EXPORT_SYMBOL(acpi_bus_get_device);
@@ -83,10 +81,9 @@ int acpi_bus_get_status(struct acpi_device *device)
        acpi_status status = AE_OK;
        unsigned long sta = 0;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_get_status");
 
        if (!device)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        /*
         * Evaluate _STA if present.
@@ -95,7 +92,7 @@ int acpi_bus_get_status(struct acpi_device *device)
                status =
                    acpi_evaluate_integer(device->handle, "_STA", NULL, &sta);
                if (ACPI_FAILURE(status))
-                       return_VALUE(-ENODEV);
+                       return -ENODEV;
                STRUCT_TO_INT(device->status) = (int)sta;
        }
 
@@ -106,7 +103,9 @@ int acpi_bus_get_status(struct acpi_device *device)
        else if (device->parent)
                device->status = device->parent->status;
        else
-               STRUCT_TO_INT(device->status) = 0x0F;
+               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]: "
@@ -119,7 +118,7 @@ int acpi_bus_get_status(struct acpi_device *device)
                          device->pnp.bus_id,
                          (u32) STRUCT_TO_INT(device->status)));
 
-       return_VALUE(0);
+       return 0;
 }
 
 EXPORT_SYMBOL(acpi_bus_get_status);
@@ -135,11 +134,10 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
        struct acpi_device *device = NULL;
        unsigned long psc = 0;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_get_power");
 
        result = acpi_bus_get_device(handle, &device);
        if (result)
-               return_VALUE(result);
+               return result;
 
        *state = ACPI_STATE_UNKNOWN;
 
@@ -151,19 +149,19 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
                        *state = ACPI_STATE_D0;
        } else {
                /*
-                * Get the device's power state either directly (via _PSC) or 
+                * Get the device's power state either directly (via _PSC) or
                 * indirectly (via power resources).
                 */
                if (device->power.flags.explicit_get) {
                        status = acpi_evaluate_integer(device->handle, "_PSC",
                                                       NULL, &psc);
                        if (ACPI_FAILURE(status))
-                               return_VALUE(-ENODEV);
+                               return -ENODEV;
                        device->power.state = (int)psc;
                } else if (device->power.flags.power_resources) {
                        result = acpi_power_get_inferred_state(device);
                        if (result)
-                               return_VALUE(result);
+                               return result;
                }
 
                *state = device->power.state;
@@ -172,7 +170,7 @@ int acpi_bus_get_power(acpi_handle handle, int *state)
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device [%s] power state is D%d\n",
                          device->pnp.bus_id, device->power.state));
 
-       return_VALUE(0);
+       return 0;
 }
 
 EXPORT_SYMBOL(acpi_bus_get_power);
@@ -184,44 +182,42 @@ int acpi_bus_set_power(acpi_handle handle, int state)
        struct acpi_device *device = NULL;
        char object_name[5] = { '_', 'P', 'S', '0' + state, '\0' };
 
-       ACPI_FUNCTION_TRACE("acpi_bus_set_power");
 
        result = acpi_bus_get_device(handle, &device);
        if (result)
-               return_VALUE(result);
+               return result;
 
        if ((state < ACPI_STATE_D0) || (state > ACPI_STATE_D3))
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        /* Make sure this is a valid target state */
 
        if (!device->flags.power_manageable) {
-               printk(KERN_DEBUG "Device `[%s]is not power manageable",
-                               device->kobj.name);
-               return_VALUE(-ENODEV);
+               ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device `[%s]' is not power manageable\n",
+                               device->dev.kobj.name));
+               return -ENODEV;
        }
        /*
         * Get device's current power state if it's unknown
         * This means device power state isn't initialized or previous setting failed
         */
-       if (!device->flags.force_power_state) {
-               if (device->power.state == ACPI_STATE_UNKNOWN)
-                       acpi_bus_get_power(device->handle, &device->power.state);
-               if (state == device->power.state) {
-                       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Device is already at D%d\n",
-                                         state));
-                       return_VALUE(0);
-               }
+       if ((device->power.state == ACPI_STATE_UNKNOWN) || device->flags.force_power_state)
+               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));
+               return 0;
        }
+
        if (!device->power.states[state].flags.valid) {
-               ACPI_WARNING((AE_INFO, "Device does not support D%d", state));
-               return_VALUE(-ENODEV);
+               printk(KERN_WARNING PREFIX "Device does not support D%d\n", state);
+               return -ENODEV;
        }
        if (device->parent && (state < device->parent->power.state)) {
-               ACPI_WARNING((AE_INFO,
+               printk(KERN_WARNING PREFIX
                              "Cannot set device to a higher-powered"
-                             " state than parent"));
-               return_VALUE(-ENODEV);
+                             " state than parent\n");
+               return -ENODEV;
        }
 
        /*
@@ -263,15 +259,15 @@ int acpi_bus_set_power(acpi_handle handle, int state)
 
       end:
        if (result)
-               ACPI_WARNING((AE_INFO,
-                             "Transitioning device [%s] to D%d",
-                             device->pnp.bus_id, state));
+               printk(KERN_WARNING PREFIX
+                             "Transitioning device [%s] to D%d\n",
+                             device->pnp.bus_id, state);
        else
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                  "Device [%s] transitioned to D%d\n",
                                  device->pnp.bus_id, state));
 
-       return_VALUE(result);
+       return result;
 }
 
 EXPORT_SYMBOL(acpi_bus_set_power);
@@ -280,6 +276,7 @@ EXPORT_SYMBOL(acpi_bus_set_power);
                                 Event Management
    -------------------------------------------------------------------------- */
 
+#ifdef CONFIG_ACPI_PROC_EVENT
 static DEFINE_SPINLOCK(acpi_bus_event_lock);
 
 LIST_HEAD(acpi_bus_event_list);
@@ -287,23 +284,22 @@ DECLARE_WAIT_QUEUE_HEAD(acpi_bus_event_queue);
 
 extern int event_is_open;
 
-int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
+int acpi_bus_generate_proc_event(struct acpi_device *device, u8 type, int data)
 {
        struct acpi_bus_event *event = NULL;
        unsigned long flags = 0;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_generate_event");
 
        if (!device)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        /* drop event on the floor if no one's listening */
        if (!event_is_open)
-               return_VALUE(0);
+               return 0;
 
        event = kmalloc(sizeof(struct acpi_bus_event), GFP_ATOMIC);
        if (!event)
-               return_VALUE(-ENOMEM);
+               return -ENOMEM;
 
        strcpy(event->device_class, device->pnp.device_class);
        strcpy(event->bus_id, device->pnp.bus_id);
@@ -316,10 +312,10 @@ int acpi_bus_generate_event(struct acpi_device *device, u8 type, int data)
 
        wake_up_interruptible(&acpi_bus_event_queue);
 
-       return_VALUE(0);
+       return 0;
 }
 
-EXPORT_SYMBOL(acpi_bus_generate_event);
+EXPORT_SYMBOL(acpi_bus_generate_proc_event);
 
 int acpi_bus_receive_event(struct acpi_bus_event *event)
 {
@@ -328,10 +324,9 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
 
        DECLARE_WAITQUEUE(wait, current);
 
-       ACPI_FUNCTION_TRACE("acpi_bus_receive_event");
 
        if (!event)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        if (list_empty(&acpi_bus_event_list)) {
 
@@ -345,7 +340,7 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
                set_current_state(TASK_RUNNING);
 
                if (signal_pending(current))
-                       return_VALUE(-ERESTARTSYS);
+                       return -ERESTARTSYS;
        }
 
        spin_lock_irqsave(&acpi_bus_event_lock, flags);
@@ -356,16 +351,17 @@ int acpi_bus_receive_event(struct acpi_bus_event *event)
        spin_unlock_irqrestore(&acpi_bus_event_lock, flags);
 
        if (!entry)
-               return_VALUE(-ENODEV);
+               return -ENODEV;
 
        memcpy(event, entry, sizeof(struct acpi_bus_event));
 
        kfree(entry);
 
-       return_VALUE(0);
+       return 0;
 }
 
 EXPORT_SYMBOL(acpi_bus_receive_event);
+#endif /* CONFIG_ACPI_PROC_EVENT */
 
 /* --------------------------------------------------------------------------
                              Notification Handling
@@ -377,10 +373,9 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
        acpi_status status = 0;
        struct acpi_device_status old_status;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_check_device");
 
        if (!device)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        if (status_changed)
                *status_changed = 0;
@@ -397,15 +392,15 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
                        if (status_changed)
                                *status_changed = 1;
                }
-               return_VALUE(0);
+               return 0;
        }
 
        status = acpi_bus_get_status(device);
        if (ACPI_FAILURE(status))
-               return_VALUE(-ENODEV);
+               return -ENODEV;
 
        if (STRUCT_TO_INT(old_status) == STRUCT_TO_INT(device->status))
-               return_VALUE(0);
+               return 0;
 
        if (status_changed)
                *status_changed = 1;
@@ -421,7 +416,7 @@ acpi_bus_check_device(struct acpi_device *device, int *status_changed)
                /* TBD: Handle device removal */
        }
 
-       return_VALUE(0);
+       return 0;
 }
 
 static int acpi_bus_check_scope(struct acpi_device *device)
@@ -429,25 +424,24 @@ static int acpi_bus_check_scope(struct acpi_device *device)
        int result = 0;
        int status_changed = 0;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_check_scope");
 
        if (!device)
-               return_VALUE(-EINVAL);
+               return -EINVAL;
 
        /* Status Change? */
        result = acpi_bus_check_device(device, &status_changed);
        if (result)
-               return_VALUE(result);
+               return result;
 
        if (!status_changed)
-               return_VALUE(0);
+               return 0;
 
        /*
         * TBD: Enumerate child devices within this device's scope and
         *       run acpi_bus_check_device()'s on them.
         */
 
-       return_VALUE(0);
+       return 0;
 }
 
 /**
@@ -460,10 +454,9 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
        int result = 0;
        struct acpi_device *device = NULL;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_notify");
 
        if (acpi_bus_get_device(handle, &device))
-               return_VOID;
+               return;
 
        switch (type) {
 
@@ -472,7 +465,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
                                  "Received BUS CHECK notification for device [%s]\n",
                                  device->pnp.bus_id));
                result = acpi_bus_check_scope(device);
-               /* 
+               /*
                 * TBD: We'll need to outsource certain events to non-ACPI
                 *      drivers via the device manager (device.c).
                 */
@@ -483,7 +476,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
                                  "Received DEVICE CHECK notification for device [%s]\n",
                                  device->pnp.bus_id));
                result = acpi_bus_check_device(device, NULL);
-               /* 
+               /*
                 * TBD: We'll need to outsource certain events to non-ACPI
                 *      drivers via the device manager (device.c).
                 */
@@ -538,7 +531,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
                break;
        }
 
-       return_VOID;
+       return;
 }
 
 /* --------------------------------------------------------------------------
@@ -552,9 +545,8 @@ static int __init acpi_bus_init_irq(void)
        struct acpi_object_list arg_list = { 1, &arg };
        char *message = NULL;
 
-       ACPI_FUNCTION_TRACE("acpi_bus_init_irq");
 
-       /* 
+       /*
         * Let the system know what interrupt model we are using by
         * evaluating the \_PIC object, if exists.
         */
@@ -569,9 +561,12 @@ static int __init acpi_bus_init_irq(void)
        case ACPI_IRQ_MODEL_IOSAPIC:
                message = "IOSAPIC";
                break;
+       case ACPI_IRQ_MODEL_PLATFORM:
+               message = "platform specific model";
+               break;
        default:
                printk(KERN_WARNING PREFIX "Unknown interrupt routing model\n");
-               return_VALUE(-ENODEV);
+               return -ENODEV;
        }
 
        printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
@@ -581,21 +576,21 @@ static int __init acpi_bus_init_irq(void)
        status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
        if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
                ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
-               return_VALUE(-ENODEV);
+               return -ENODEV;
        }
 
-       return_VALUE(0);
+       return 0;
 }
 
+acpi_native_uint acpi_gbl_permanent_mmap;
+
+
 void __init acpi_early_init(void)
 {
        acpi_status status = AE_OK;
-       struct acpi_buffer buffer = { sizeof(acpi_fadt), &acpi_fadt };
-
-       ACPI_FUNCTION_TRACE("acpi_early_init");
 
        if (acpi_disabled)
-               return_VOID;
+               return;
 
        printk(KERN_INFO PREFIX "Core revision %08x\n", ACPI_CA_VERSION);
 
@@ -603,6 +598,15 @@ void __init acpi_early_init(void)
        if (!acpi_strict)
                acpi_gbl_enable_interpreter_slack = TRUE;
 
+       acpi_gbl_permanent_mmap = 1;
+
+       status = acpi_reallocate_root_table();
+       if (ACPI_FAILURE(status)) {
+               printk(KERN_ERR PREFIX
+                      "Unable to reallocate ACPI tables\n");
+               goto error0;
+       }
+
        status = acpi_initialize_subsystem();
        if (ACPI_FAILURE(status)) {
                printk(KERN_ERR PREFIX
@@ -617,32 +621,25 @@ void __init acpi_early_init(void)
                goto error0;
        }
 
-       /*
-        * Get a separate copy of the FADT for use by other drivers.
-        */
-       status = acpi_get_table(ACPI_TABLE_ID_FADT, 1, &buffer);
-       if (ACPI_FAILURE(status)) {
-               printk(KERN_ERR PREFIX "Unable to get the FADT\n");
-               goto error0;
-       }
 #ifdef CONFIG_X86
        if (!acpi_ioapic) {
-               extern acpi_interrupt_flags acpi_sci_flags;
+               extern u8 acpi_sci_flags;
 
                /* compatible (0) means level (3) */
-               if (acpi_sci_flags.trigger == 0)
-                       acpi_sci_flags.trigger = 3;
-
+               if (!(acpi_sci_flags & ACPI_MADT_TRIGGER_MASK)) {
+                       acpi_sci_flags &= ~ACPI_MADT_TRIGGER_MASK;
+                       acpi_sci_flags |= ACPI_MADT_TRIGGER_LEVEL;
+               }
                /* Set PIC-mode SCI trigger type */
-               acpi_pic_sci_set_trigger(acpi_fadt.sci_int,
-                                        acpi_sci_flags.trigger);
+               acpi_pic_sci_set_trigger(acpi_gbl_FADT.sci_interrupt,
+                                        (acpi_sci_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
        } else {
                extern int acpi_sci_override_gsi;
                /*
-                * now that acpi_fadt is initialized,
+                * now that acpi_gbl_FADT is initialized,
                 * update it with result from INT_SRC_OVR parsing
                 */
-               acpi_fadt.sci_int = acpi_sci_override_gsi;
+               acpi_gbl_FADT.sci_interrupt = acpi_sci_override_gsi;
        }
 #endif
 
@@ -655,11 +652,11 @@ void __init acpi_early_init(void)
                goto error0;
        }
 
-       return_VOID;
+       return;
 
       error0:
        disable_acpi();
-       return_VOID;
+       return;
 }
 
 static int __init acpi_bus_init(void)
@@ -668,7 +665,6 @@ static int __init acpi_bus_init(void)
        acpi_status status = AE_OK;
        extern acpi_status acpi_os_initialize1(void);
 
-       ACPI_FUNCTION_TRACE("acpi_bus_init");
 
        status = acpi_os_initialize1();
 
@@ -691,7 +687,7 @@ static int __init acpi_bus_init(void)
         * the EC device is found in the namespace (i.e. before acpi_initialize_objects()
         * is called).
         *
-        * This is accomplished by looking for the ECDT table, and getting 
+        * This is accomplished by looking for the ECDT table, and getting
         * the EC parameters out of that.
         */
        status = acpi_ec_ecdt_probe();
@@ -706,6 +702,9 @@ static int __init acpi_bus_init(void)
 
        printk(KERN_INFO PREFIX "Interpreter enabled\n");
 
+       /* Initialize sleep structures */
+       acpi_sleep_init();
+
        /*
         * Get the system interrupt model and evaluate \_PIC.
         */
@@ -730,12 +729,12 @@ static int __init acpi_bus_init(void)
         */
        acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
 
-       return_VALUE(0);
+       return 0;
 
        /* Mimic structured exception handling */
       error1:
        acpi_terminate();
-       return_VALUE(-ENODEV);
+       return -ENODEV;
 }
 
 decl_subsys(acpi, NULL, NULL);
@@ -744,14 +743,16 @@ static int __init acpi_init(void)
 {
        int result = 0;
 
-       ACPI_FUNCTION_TRACE("acpi_init");
 
        if (acpi_disabled) {
                printk(KERN_INFO PREFIX "Interpreter disabled.\n");
-               return_VALUE(-ENODEV);
+               return -ENODEV;
        }
 
-       firmware_register(&acpi_subsys);
+       result = firmware_register(&acpi_subsys);
+       if (result < 0)
+               printk(KERN_WARNING "%s: firmware_register error: %d\n",
+                       __FUNCTION__, result);
 
        result = acpi_bus_init();
 
@@ -769,7 +770,7 @@ static int __init acpi_init(void)
        } else
                disable_acpi();
 
-       return_VALUE(result);
+       return result;
 }
 
 subsys_initcall(acpi_init);