Merge branch 'cpus4096' into irq/threaded
[safe/jmp/linux-2.6] / drivers / acpi / osl.c
index c2c5853..eb8980d 100644 (file)
@@ -4,6 +4,8 @@
  *  Copyright (C) 2000       Andrew Henroid
  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
+ *  Copyright (c) 2008 Intel Corporation
+ *   Author: Matthew Wilcox <willy@linux.intel.com>
  *
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
 #include <linux/interrupt.h>
 #include <linux/kmod.h>
 #include <linux/delay.h>
-#include <linux/dmi.h>
 #include <linux/workqueue.h>
 #include <linux/nmi.h>
 #include <linux/acpi.h>
-#include <acpi/acpi.h>
-#include <asm/io.h>
-#include <acpi/acpi_bus.h>
-#include <acpi/processor.h>
-#include <asm/uaccess.h>
-
 #include <linux/efi.h>
 #include <linux/ioport.h>
 #include <linux/list.h>
+#include <linux/jiffies.h>
+#include <linux/semaphore.h>
+
+#include <asm/io.h>
+#include <asm/uaccess.h>
+
+#include <acpi/acpi.h>
+#include <acpi/acpi_bus.h>
+#include <acpi/processor.h>
 
 #define _COMPONENT             ACPI_OS_SERVICES
 ACPI_MODULE_NAME("osl");
@@ -92,54 +96,44 @@ static DEFINE_SPINLOCK(acpi_res_lock);
 static char osi_additional_string[OSI_STRING_LENGTH_MAX];
 
 /*
- * "Ode to _OSI(Linux)"
+ * The story of _OSI(Linux)
  *
- * osi_linux -- Control response to BIOS _OSI(Linux) query.
+ * From pre-history through Linux-2.6.22,
+ * Linux responded TRUE upon a BIOS OSI(Linux) query.
  *
- * As Linux evolves, the features that it supports change.
- * So an OSI string such as "Linux" is not specific enough
- * to be useful across multiple versions of Linux.  It
- * doesn't identify any particular feature, interface,
- * or even any particular version of Linux...
+ * Unfortunately, reference BIOS writers got wind of this
+ * and put OSI(Linux) in their example code, quickly exposing
+ * this string as ill-conceived and opening the door to
+ * an un-bounded number of BIOS incompatibilities.
  *
- * Unfortunately, Linux-2.6.22 and earlier responded "yes"
- * to a BIOS _OSI(Linux) query.  When
- * a reference mobile BIOS started using it, its use
- * started to spread to many vendor platforms.
- * As it is not supportable, we need to halt that spread.
+ * For example, OSI(Linux) was used on resume to re-POST a
+ * video card on one system, because Linux at that time
+ * could not do a speedy restore in its native driver.
+ * But then upon gaining quick native restore capability,
+ * Linux has no way to tell the BIOS to skip the time-consuming
+ * POST -- putting Linux at a permanent performance disadvantage.
+ * On another system, the BIOS writer used OSI(Linux)
+ * to infer native OS support for IPMI!  On other systems,
+ * OSI(Linux) simply got in the way of Linux claiming to
+ * be compatible with other operating systems, exposing
+ * BIOS issues such as skipped device initialization.
  *
- * Today, most BIOS references to _OSI(Linux) are noise --
- * they have no functional effect and are just dead code
- * carried over from the reference BIOS.
- *
- * The next most common case is that _OSI(Linux) harms Linux,
- * usually by causing the BIOS to follow paths that are
- * not tested during Windows validation.
- *
- * Finally, there is a short list of platforms
- * where OSI(Linux) benefits Linux.
- *
- * In Linux-2.6.23, OSI(Linux) is first disabled by default.
- * DMI is used to disable the dmesg warning about OSI(Linux)
- * on platforms where it is known to have no effect.
- * But a dmesg warning remains for systems where
- * we do not know if OSI(Linux) is good or bad for the system.
- * DMI is also used to enable OSI(Linux) for the machines
- * that are known to need it.
+ * So "Linux" turned out to be a really poor chose of
+ * OSI string, and from Linux-2.6.23 onward we respond FALSE.
  *
  * BIOS writers should NOT query _OSI(Linux) on future systems.
- * It will be ignored by default, and to get Linux to
- * not ignore it will require a kernel source update to
- * add a DMI entry, or a boot-time "acpi_osi=Linux" invocation.
+ * Linux will complain on the console when it sees it, and return FALSE.
+ * To get Linux to return TRUE for your system  will require
+ * a kernel source update to add a DMI entry,
+ * or boot with "acpi_osi=Linux"
  */
-#define OSI_LINUX_ENABLE 0
 
 static struct osi_linux {
        unsigned int    enable:1;
        unsigned int    dmi:1;
        unsigned int    cmdline:1;
        unsigned int    known:1;
-} osi_linux = { OSI_LINUX_ENABLE, 0, 0, 0};
+} osi_linux = { 0, 0, 0, 0};
 
 static void __init acpi_request_region (struct acpi_generic_address *addr,
        unsigned int length, char *desc)
@@ -196,15 +190,6 @@ acpi_status __init acpi_os_initialize(void)
 
 acpi_status acpi_os_initialize1(void)
 {
-       /*
-        * Initialize PCI configuration space access, as we'll need to access
-        * it while walking the namespace (bus 0 and root bridges w/ _BBNs).
-        */
-       if (!raw_pci_ops) {
-               printk(KERN_ERR PREFIX
-                      "Access to PCI configuration space unavailable\n");
-               return AE_NULL_ENTRY;
-       }
        kacpid_wq = create_singlethread_workqueue("kacpid");
        kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
        BUG_ON(!kacpid_wq);
@@ -243,10 +228,10 @@ void acpi_os_vprintf(const char *fmt, va_list args)
        if (acpi_in_debugger) {
                kdb_printf("%s", buffer);
        } else {
-               printk("%s", buffer);
+               printk(KERN_CONT "%s", buffer);
        }
 #else
-       printk("%s", buffer);
+       printk(KERN_CONT "%s", buffer);
 #endif
 }
 
@@ -287,14 +272,21 @@ acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
 }
 EXPORT_SYMBOL_GPL(acpi_os_map_memory);
 
-void acpi_os_unmap_memory(void __iomem * virt, acpi_size size)
+void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
 {
-       if (acpi_gbl_permanent_mmap) {
+       if (acpi_gbl_permanent_mmap)
                iounmap(virt);
-       }
+       else
+               __acpi_unmap_table(virt, size);
 }
 EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
 
+void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
+{
+       if (!acpi_gbl_permanent_mmap)
+               __acpi_unmap_table(virt, size);
+}
+
 #ifdef ACPI_FUTURE_USAGE
 acpi_status
 acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
@@ -336,14 +328,19 @@ acpi_os_table_override(struct acpi_table_header * existing_table,
        if (!existing_table || !new_table)
                return AE_BAD_PARAMETER;
 
+       *new_table = NULL;
+
 #ifdef CONFIG_ACPI_CUSTOM_DSDT
        if (strncmp(existing_table->signature, "DSDT", 4) == 0)
                *new_table = (struct acpi_table_header *)AmlCode;
-       else
-               *new_table = NULL;
-#else
-       *new_table = NULL;
 #endif
+       if (*new_table != NULL) {
+               printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
+                          "this is unsafe: tainting kernel\n",
+                      existing_table->signature,
+                      existing_table->oem_table_id);
+               add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
+       }
        return AE_OK;
 }
 
@@ -543,7 +540,7 @@ acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
 
 acpi_status
 acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
-                              void *value, u32 width)
+                              u32 *value, u32 width)
 {
        int result, size;
 
@@ -564,11 +561,9 @@ acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
                return AE_ERROR;
        }
 
-       BUG_ON(!raw_pci_ops);
-
-       result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
-                                  PCI_DEVFN(pci_id->device, pci_id->function),
-                                  reg, size, value);
+       result = raw_pci_read(pci_id->segment, pci_id->bus,
+                               PCI_DEVFN(pci_id->device, pci_id->function),
+                               reg, size, value);
 
        return (result ? AE_ERROR : AE_OK);
 }
@@ -593,11 +588,9 @@ acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
                return AE_ERROR;
        }
 
-       BUG_ON(!raw_pci_ops);
-
-       result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
-                                   PCI_DEVFN(pci_id->device, pci_id->function),
-                                   reg, size, value);
+       result = raw_pci_write(pci_id->segment, pci_id->bus,
+                               PCI_DEVFN(pci_id->device, pci_id->function),
+                               reg, size, value);
 
        return (result ? AE_ERROR : AE_OK);
 }
@@ -611,9 +604,8 @@ static void acpi_os_derive_pci_id_2(acpi_handle rhandle,    /* upper bound  */
        acpi_handle handle;
        struct acpi_pci_id *pci_id = *id;
        acpi_status status;
-       unsigned long temp;
+       unsigned long long temp;
        acpi_object_type type;
-       u8 tu8;
 
        acpi_get_parent(chandle, &handle);
        if (handle != rhandle) {
@@ -624,10 +616,10 @@ static void acpi_os_derive_pci_id_2(acpi_handle rhandle,  /* upper bound  */
                if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
                        return;
 
-               status =
-                   acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
+               status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
                                          &temp);
                if (ACPI_SUCCESS(status)) {
+                       u32 val;
                        pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
                        pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
 
@@ -636,24 +628,24 @@ static void acpi_os_derive_pci_id_2(acpi_handle rhandle,  /* upper bound  */
 
                        /* any nicer way to get bus number of bridge ? */
                        status =
-                           acpi_os_read_pci_configuration(pci_id, 0x0e, &tu8,
+                           acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
                                                           8);
                        if (ACPI_SUCCESS(status)
-                           && ((tu8 & 0x7f) == 1 || (tu8 & 0x7f) == 2)) {
+                           && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
                                status =
                                    acpi_os_read_pci_configuration(pci_id, 0x18,
-                                                                  &tu8, 8);
+                                                                  &val, 8);
                                if (!ACPI_SUCCESS(status)) {
                                        /* Certainly broken...  FIX ME */
                                        return;
                                }
                                *is_bridge = 1;
-                               pci_id->bus = tu8;
+                               pci_id->bus = val;
                                status =
                                    acpi_os_read_pci_configuration(pci_id, 0x19,
-                                                                  &tu8, 8);
+                                                                  &val, 8);
                                if (ACPI_SUCCESS(status)) {
-                                       *bus_number = tu8;
+                                       *bus_number = val;
                                }
                        } else
                                *is_bridge = 0;
@@ -685,6 +677,22 @@ static void acpi_os_execute_deferred(struct work_struct *work)
        return;
 }
 
+static void acpi_os_execute_hp_deferred(struct work_struct *work)
+{
+       struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
+       if (!dpc) {
+               printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
+               return;
+       }
+
+       acpi_os_wait_events_complete(NULL);
+
+       dpc->function(dpc->context);
+       kfree(dpc);
+
+       return;
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_os_execute
@@ -700,12 +708,13 @@ static void acpi_os_execute_deferred(struct work_struct *work)
  *
  ******************************************************************************/
 
-acpi_status acpi_os_execute(acpi_execute_type type,
-                           acpi_osd_exec_callback function, void *context)
+static acpi_status __acpi_os_execute(acpi_execute_type type,
+       acpi_osd_exec_callback function, void *context, int hp)
 {
        acpi_status status = AE_OK;
        struct acpi_os_dpc *dpc;
        struct workqueue_struct *queue;
+       int ret;
        ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
                          "Scheduling function [%p(%p)] for deferred execution.\n",
                          function, context));
@@ -724,27 +733,47 @@ acpi_status acpi_os_execute(acpi_execute_type type,
 
        dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
        if (!dpc)
-               return_ACPI_STATUS(AE_NO_MEMORY);
+               return AE_NO_MEMORY;
 
        dpc->function = function;
        dpc->context = context;
 
-       INIT_WORK(&dpc->work, acpi_os_execute_deferred);
-       queue = (type == OSL_NOTIFY_HANDLER) ? kacpi_notify_wq : kacpid_wq;
-       if (!queue_work(queue, &dpc->work)) {
-               ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
-                         "Call to queue_work() failed.\n"));
+       if (!hp) {
+               INIT_WORK(&dpc->work, acpi_os_execute_deferred);
+               queue = (type == OSL_NOTIFY_HANDLER) ?
+                       kacpi_notify_wq : kacpid_wq;
+               ret = queue_work(queue, &dpc->work);
+       } else {
+               INIT_WORK(&dpc->work, acpi_os_execute_hp_deferred);
+               ret = schedule_work(&dpc->work);
+       }
+
+       if (!ret) {
+               printk(KERN_ERR PREFIX
+                         "Call to queue_work() failed.\n");
                status = AE_ERROR;
                kfree(dpc);
        }
-       return_ACPI_STATUS(status);
+       return status;
 }
 
+acpi_status acpi_os_execute(acpi_execute_type type,
+                           acpi_osd_exec_callback function, void *context)
+{
+       return __acpi_os_execute(type, function, context, 0);
+}
 EXPORT_SYMBOL(acpi_os_execute);
 
+acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
+       void *context)
+{
+       return __acpi_os_execute(0, function, context, 1);
+}
+
 void acpi_os_wait_events_complete(void *context)
 {
        flush_workqueue(kacpid_wq);
+       flush_workqueue(kacpi_notify_wq);
 }
 
 EXPORT_SYMBOL(acpi_os_wait_events_complete);
@@ -772,7 +801,6 @@ acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
 {
        struct semaphore *sem = NULL;
 
-
        sem = acpi_os_allocate(sizeof(struct semaphore));
        if (!sem)
                return AE_NO_MEMORY;
@@ -799,12 +827,12 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle)
 {
        struct semaphore *sem = (struct semaphore *)handle;
 
-
        if (!sem)
                return AE_BAD_PARAMETER;
 
        ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
 
+       BUG_ON(!list_empty(&sem->wait_list));
        kfree(sem);
        sem = NULL;
 
@@ -812,21 +840,15 @@ acpi_status acpi_os_delete_semaphore(acpi_handle handle)
 }
 
 /*
- * TODO: The kernel doesn't have a 'down_timeout' function -- had to
- * improvise.  The process is to sleep for one scheduler quantum
- * until the semaphore becomes available.  Downside is that this
- * may result in starvation for timeout-based waits when there's
- * lots of semaphore activity.
- *
  * TODO: Support for units > 1?
  */
 acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
 {
        acpi_status status = AE_OK;
        struct semaphore *sem = (struct semaphore *)handle;
+       long jiffies;
        int ret = 0;
 
-
        if (!sem || (units < 1))
                return AE_BAD_PARAMETER;
 
@@ -836,58 +858,14 @@ acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
        ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
                          handle, units, timeout));
 
-       /*
-        * This can be called during resume with interrupts off.
-        * Like boot-time, we should be single threaded and will
-        * always get the lock if we try -- timeout or not.
-        * If this doesn't succeed, then we will oops courtesy of
-        * might_sleep() in down().
-        */
-       if (!down_trylock(sem))
-               return AE_OK;
-
-       switch (timeout) {
-               /*
-                * No Wait:
-                * --------
-                * A zero timeout value indicates that we shouldn't wait - just
-                * acquire the semaphore if available otherwise return AE_TIME
-                * (a.k.a. 'would block').
-                */
-       case 0:
-               if (down_trylock(sem))
-                       status = AE_TIME;
-               break;
-
-               /*
-                * Wait Indefinitely:
-                * ------------------
-                */
-       case ACPI_WAIT_FOREVER:
-               down(sem);
-               break;
-
-               /*
-                * Wait w/ Timeout:
-                * ----------------
-                */
-       default:
-               // TODO: A better timeout algorithm?
-               {
-                       int i = 0;
-                       static const int quantum_ms = 1000 / HZ;
-
-                       ret = down_trylock(sem);
-                       for (i = timeout; (i > 0 && ret != 0); i -= quantum_ms) {
-                               schedule_timeout_interruptible(1);
-                               ret = down_trylock(sem);
-                       }
-
-                       if (ret != 0)
-                               status = AE_TIME;
-               }
-               break;
-       }
+       if (timeout == ACPI_WAIT_FOREVER)
+               jiffies = MAX_SCHEDULE_TIMEOUT;
+       else
+               jiffies = msecs_to_jiffies(timeout);
+       
+       ret = down_timeout(sem, jiffies);
+       if (ret)
+               status = AE_TIME;
 
        if (ACPI_FAILURE(status)) {
                ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
@@ -910,7 +888,6 @@ acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
 {
        struct semaphore *sem = (struct semaphore *)handle;
 
-
        if (!sem || (units < 1))
                return AE_BAD_PARAMETER;
 
@@ -1033,7 +1010,7 @@ void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  * string starting with '!' disables that string
  * otherwise string is added to list, augmenting built-in strings
  */
-static int __init acpi_osi_setup(char *str)
+int __init acpi_osi_setup(char *str)
 {
        if (str == NULL || *str == '\0') {
                printk(KERN_INFO PREFIX "_OSI method disabled\n");
@@ -1161,7 +1138,7 @@ int acpi_check_resource_conflict(struct resource *res)
 
        if (clash) {
                if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
-                       printk(KERN_INFO "%sACPI: %s resource %s [0x%llx-0x%llx]"
+                       printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
                               " conflicts with ACPI region %s"
                               " [0x%llx-0x%llx]\n",
                               acpi_enforce_resources == ENFORCE_RESOURCES_LAX
@@ -1315,34 +1292,6 @@ acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
        return (AE_OK);
 }
 
-/**
- *     acpi_dmi_dump - dump DMI slots needed for blacklist entry
- *
- *     Returns 0 on success
- */
-static int acpi_dmi_dump(void)
-{
-
-       if (!dmi_available)
-               return -1;
-
-       printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
-               dmi_get_system_info(DMI_SYS_VENDOR));
-       printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
-               dmi_get_system_info(DMI_PRODUCT_NAME));
-       printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
-               dmi_get_system_info(DMI_PRODUCT_VERSION));
-       printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
-               dmi_get_system_info(DMI_BOARD_NAME));
-       printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
-               dmi_get_system_info(DMI_BIOS_VENDOR));
-       printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
-               dmi_get_system_info(DMI_BIOS_DATE));
-
-       return 0;
-}
-
-
 /******************************************************************************
  *
  * FUNCTION:    acpi_os_validate_interface
@@ -1369,21 +1318,6 @@ acpi_os_validate_interface (char *interface)
                        osi_linux.cmdline ? " via cmdline" :
                        osi_linux.dmi ? " via DMI" : "");
 
-               if (!osi_linux.dmi) {
-                       if (acpi_dmi_dump())
-                               printk(KERN_NOTICE PREFIX
-                                       "[please extract dmidecode output]\n");
-                       printk(KERN_NOTICE PREFIX
-                               "Please send DMI info above to "
-                               "linux-acpi@vger.kernel.org\n");
-               }
-               if (!osi_linux.known && !osi_linux.cmdline) {
-                       printk(KERN_NOTICE PREFIX
-                               "If \"acpi_osi=%sLinux\" works better, "
-                               "please notify linux-acpi@vger.kernel.org\n",
-                               osi_linux.enable ? "!" : "");
-               }
-
                if (osi_linux.enable)
                        return AE_OK;
        }