Pull sony into release branch
[pandora-kernel.git] / drivers / acpi / events / evmisc.c
index f82b81c..1b784ff 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2006, R. Byron Moore
+ * Copyright (C) 2000 - 2007, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -63,14 +63,18 @@ static const char *acpi_notify_value_names[] = {
 };
 #endif
 
+/* Pointer to FACS needed for the Global Lock */
+
+static struct acpi_table_facs *facs = NULL;
+
 /* Local prototypes */
 
 static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context);
 
-static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context);
-
 static u32 acpi_ev_global_lock_handler(void *context);
 
+static acpi_status acpi_ev_remove_global_lock_handler(void);
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_is_notify_object
@@ -280,45 +284,21 @@ static void ACPI_SYSTEM_XFACE acpi_ev_notify_dispatch(void *context)
        acpi_ut_delete_generic_state(notify_info);
 }
 
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_global_lock_thread
- *
- * PARAMETERS:  Context         - From thread interface, not used
- *
- * RETURN:      None
- *
- * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the
- *              Global Lock.  Simply signal all threads that are waiting
- *              for the lock.
- *
- ******************************************************************************/
-
-static void ACPI_SYSTEM_XFACE acpi_ev_global_lock_thread(void *context)
-{
-       acpi_status status;
-
-       /* Signal the thread that is waiting for the lock */
-
-       /* Send a unit to the semaphore */
-
-       status = acpi_os_signal_semaphore(acpi_gbl_global_lock_semaphore, 1);
-       if (ACPI_FAILURE(status)) {
-               ACPI_ERROR((AE_INFO, "Could not signal Global Lock semaphore"));
-       }
-}
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_global_lock_handler
  *
  * PARAMETERS:  Context         - From thread interface, not used
  *
- * RETURN:      ACPI_INTERRUPT_HANDLED or ACPI_INTERRUPT_NOT_HANDLED
+ * RETURN:      ACPI_INTERRUPT_HANDLED
  *
  * DESCRIPTION: Invoked directly from the SCI handler when a global lock
- *              release interrupt occurs.  Grab the global lock and queue
- *              the global lock thread for execution
+ *              release interrupt occurs. Attempt to acquire the global lock,
+ *              if successful, signal the thread waiting for the lock.
+ *
+ * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
+ * this is not possible for some reason, a separate thread will have to be
+ * scheduled to do this.
  *
  ******************************************************************************/
 
@@ -332,13 +312,19 @@ static u32 acpi_ev_global_lock_handler(void *context)
         * If we don't get it now, it will be marked pending and we will
         * take another interrupt when it becomes free.
         */
-       ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, acquired);
+       ACPI_ACQUIRE_GLOBAL_LOCK(facs, acquired);
        if (acquired) {
 
                /* Got the lock, now wake all threads waiting for it */
 
                acpi_gbl_global_lock_acquired = TRUE;
-               acpi_ev_global_lock_thread(context);
+               /* Send a unit to the semaphore */
+
+               if (ACPI_FAILURE(acpi_os_signal_semaphore(
+                       acpi_gbl_global_lock_semaphore, 1))) {
+                       ACPI_ERROR((AE_INFO,
+                                   "Could not signal Global Lock semaphore"));
+               }
        }
 
        return (ACPI_INTERRUPT_HANDLED);
@@ -362,6 +348,13 @@ acpi_status acpi_ev_init_global_lock_handler(void)
 
        ACPI_FUNCTION_TRACE(ev_init_global_lock_handler);
 
+       status =
+           acpi_get_table_by_index(ACPI_TABLE_INDEX_FACS,
+                                   (struct acpi_table_header **)&facs);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
        acpi_gbl_global_lock_present = TRUE;
        status = acpi_install_fixed_event_handler(ACPI_EVENT_GLOBAL,
                                                  acpi_ev_global_lock_handler,
@@ -385,6 +378,31 @@ acpi_status acpi_ev_init_global_lock_handler(void)
        return_ACPI_STATUS(status);
 }
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_remove_global_lock_handler
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Remove the handler for the Global Lock
+ *
+ ******************************************************************************/
+
+static acpi_status acpi_ev_remove_global_lock_handler(void)
+{
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(ev_remove_global_lock_handler);
+
+       acpi_gbl_global_lock_present = FALSE;
+       status = acpi_remove_fixed_event_handler(ACPI_EVENT_GLOBAL,
+                                                acpi_ev_global_lock_handler);
+
+       return_ACPI_STATUS(status);
+}
+
 /******************************************************************************
  *
  * FUNCTION:    acpi_ev_acquire_global_lock
@@ -434,7 +452,7 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
 
        /* Attempt to acquire the actual hardware lock */
 
-       ACPI_ACQUIRE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock, acquired);
+       ACPI_ACQUIRE_GLOBAL_LOCK(facs, acquired);
        if (acquired) {
 
                /* We got the lock */
@@ -458,6 +476,7 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
         */
        status = acpi_ex_system_wait_semaphore(acpi_gbl_global_lock_semaphore,
                                               ACPI_WAIT_FOREVER);
+
        return_ACPI_STATUS(status);
 }
 
@@ -480,7 +499,7 @@ acpi_status acpi_ev_release_global_lock(void)
 
        ACPI_FUNCTION_TRACE(ev_release_global_lock);
 
-       /* Lock must be acquired */
+       /* Lock must be already acquired */
 
        if (!acpi_gbl_global_lock_acquired) {
                ACPI_WARNING((AE_INFO,
@@ -492,8 +511,7 @@ acpi_status acpi_ev_release_global_lock(void)
 
                /* Allow any thread to release the lock */
 
-               ACPI_RELEASE_GLOBAL_LOCK(acpi_gbl_common_fACS.global_lock,
-                                        pending);
+               ACPI_RELEASE_GLOBAL_LOCK(facs, pending);
 
                /*
                 * If the pending bit was set, we must write GBL_RLS to the control
@@ -502,7 +520,7 @@ acpi_status acpi_ev_release_global_lock(void)
                if (pending) {
                        status =
                            acpi_set_register(ACPI_BITREG_GLOBAL_LOCK_RELEASE,
-                                             1, ACPI_MTX_LOCK);
+                                             1);
                }
 
                ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
@@ -563,6 +581,12 @@ void acpi_ev_terminate(void)
                if (ACPI_FAILURE(status)) {
                        ACPI_ERROR((AE_INFO, "Could not remove SCI handler"));
                }
+
+               status = acpi_ev_remove_global_lock_handler();
+               if (ACPI_FAILURE(status)) {
+                       ACPI_ERROR((AE_INFO,
+                                   "Could not remove Global Lock handler"));
+               }
        }
 
        /* Deallocate all handler objects installed within GPE info structs */