Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/evmisc.c need to be fixed.

0001 /******************************************************************************
0002  *
0003  * Module Name: evmisc - Miscellaneous event manager support functions
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #include "acpi.h"
0117 #include "accommon.h"
0118 #include "acevents.h"
0119 #include "acnamesp.h"
0120 #include "acinterp.h"
0121 
0122 #define _COMPONENT          ACPI_EVENTS
0123         ACPI_MODULE_NAME    ("evmisc")
0124 
0125 
0126 /* Local prototypes */
0127 
0128 static void ACPI_SYSTEM_XFACE
0129 AcpiEvNotifyDispatch (
0130     void                    *Context);
0131 
0132 static UINT32
0133 AcpiEvGlobalLockHandler (
0134     void                    *Context);
0135 
0136 static ACPI_STATUS
0137 AcpiEvRemoveGlobalLockHandler (
0138     void);
0139 
0140 
0141 /*******************************************************************************
0142  *
0143  * FUNCTION:    AcpiEvIsNotifyObject
0144  *
0145  * PARAMETERS:  Node            - Node to check
0146  *
0147  * RETURN:      TRUE if notifies allowed on this object
0148  *
0149  * DESCRIPTION: Check type of node for a object that supports notifies.
0150  *
0151  *              TBD: This could be replaced by a flag bit in the node.
0152  *
0153  ******************************************************************************/
0154 
0155 BOOLEAN
0156 AcpiEvIsNotifyObject (
0157     ACPI_NAMESPACE_NODE     *Node)
0158 {
0159     switch (Node->Type)
0160     {
0161     case ACPI_TYPE_DEVICE:
0162     case ACPI_TYPE_PROCESSOR:
0163     case ACPI_TYPE_THERMAL:
0164         /*
0165          * These are the ONLY objects that can receive ACPI notifications
0166          */
0167         return (TRUE);
0168 
0169     default:
0170         return (FALSE);
0171     }
0172 }
0173 
0174 
0175 /*******************************************************************************
0176  *
0177  * FUNCTION:    AcpiEvQueueNotifyRequest
0178  *
0179  * PARAMETERS:  Node            - NS node for the notified object
0180  *              NotifyValue     - Value from the Notify() request
0181  *
0182  * RETURN:      Status
0183  *
0184  * DESCRIPTION: Dispatch a device notification event to a previously
0185  *              installed handler.
0186  *
0187  ******************************************************************************/
0188 
0189 ACPI_STATUS
0190 AcpiEvQueueNotifyRequest (
0191     ACPI_NAMESPACE_NODE     *Node,
0192     UINT32                  NotifyValue)
0193 {
0194     ACPI_OPERAND_OBJECT     *ObjDesc;
0195     ACPI_OPERAND_OBJECT     *HandlerObj = NULL;
0196     ACPI_GENERIC_STATE      *NotifyInfo;
0197     ACPI_STATUS             Status = AE_OK;
0198 
0199 
0200     ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
0201 
0202 
0203     /*
0204      * For value 3 (Ejection Request), some device method may need to be run.
0205      * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
0206      *   to be run.
0207      * For value 0x80 (Status Change) on the power button or sleep button,
0208      *   initiate soft-off or sleep operation?
0209      */
0210     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0211         "Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",
0212         AcpiUtGetNodeName (Node), Node, NotifyValue,
0213         AcpiUtGetNotifyName (NotifyValue)));
0214 
0215     /* Get the notify object attached to the NS Node */
0216 
0217     ObjDesc = AcpiNsGetAttachedObject (Node);
0218     if (ObjDesc)
0219     {
0220         /* We have the notify object, Get the right handler */
0221 
0222         switch (Node->Type)
0223         {
0224         /* Notify allowed only on these types */
0225 
0226         case ACPI_TYPE_DEVICE:
0227         case ACPI_TYPE_THERMAL:
0228         case ACPI_TYPE_PROCESSOR:
0229 
0230             if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
0231             {
0232                 HandlerObj = ObjDesc->CommonNotify.SystemNotify;
0233             }
0234             else
0235             {
0236                 HandlerObj = ObjDesc->CommonNotify.DeviceNotify;
0237             }
0238             break;
0239 
0240         default:
0241 
0242             /* All other types are not supported */
0243 
0244             return (AE_TYPE);
0245         }
0246     }
0247 
0248     /*
0249      * If there is any handler to run, schedule the dispatcher.
0250      * Check for:
0251      * 1) Global system notify handler
0252      * 2) Global device notify handler
0253      * 3) Per-device notify handler
0254      */
0255     if ((AcpiGbl_SystemNotify.Handler &&
0256             (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) ||
0257         (AcpiGbl_DeviceNotify.Handler &&
0258             (NotifyValue > ACPI_MAX_SYS_NOTIFY))  ||
0259         HandlerObj)
0260     {
0261         NotifyInfo = AcpiUtCreateGenericState ();
0262         if (!NotifyInfo)
0263         {
0264             return (AE_NO_MEMORY);
0265         }
0266 
0267         if (!HandlerObj)
0268         {
0269             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0270                 "Executing system notify handler for Notify (%4.4s, %X) "
0271                 "node %p\n",
0272                 AcpiUtGetNodeName (Node), NotifyValue, Node));
0273         }
0274 
0275         NotifyInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
0276         NotifyInfo->Notify.Node = Node;
0277         NotifyInfo->Notify.Value = (UINT16) NotifyValue;
0278         NotifyInfo->Notify.HandlerObj = HandlerObj;
0279 
0280         Status = AcpiOsExecute (
0281                     OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, NotifyInfo);
0282         if (ACPI_FAILURE (Status))
0283         {
0284             AcpiUtDeleteGenericState (NotifyInfo);
0285         }
0286     }
0287     else
0288     {
0289         /* There is no notify handler (per-device or system) for this device */
0290 
0291         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
0292             "No notify handler for Notify (%4.4s, %X) node %p\n",
0293             AcpiUtGetNodeName (Node), NotifyValue, Node));
0294     }
0295 
0296     return (Status);
0297 }
0298 
0299 
0300 /*******************************************************************************
0301  *
0302  * FUNCTION:    AcpiEvNotifyDispatch
0303  *
0304  * PARAMETERS:  Context         - To be passed to the notify handler
0305  *
0306  * RETURN:      None.
0307  *
0308  * DESCRIPTION: Dispatch a device notification event to a previously
0309  *              installed handler.
0310  *
0311  ******************************************************************************/
0312 
0313 static void ACPI_SYSTEM_XFACE
0314 AcpiEvNotifyDispatch (
0315     void                    *Context)
0316 {
0317     ACPI_GENERIC_STATE      *NotifyInfo = (ACPI_GENERIC_STATE *) Context;
0318     ACPI_NOTIFY_HANDLER     GlobalHandler = NULL;
0319     void                    *GlobalContext = NULL;
0320     ACPI_OPERAND_OBJECT     *HandlerObj;
0321 
0322 
0323     ACPI_FUNCTION_ENTRY ();
0324 
0325 
0326     /*
0327      * We will invoke a global notify handler if installed. This is done
0328      * _before_ we invoke the per-device handler attached to the device.
0329      */
0330     if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY)
0331     {
0332         /* Global system notification handler */
0333 
0334         if (AcpiGbl_SystemNotify.Handler)
0335         {
0336             GlobalHandler = AcpiGbl_SystemNotify.Handler;
0337             GlobalContext = AcpiGbl_SystemNotify.Context;
0338         }
0339     }
0340     else
0341     {
0342         /* Global driver notification handler */
0343 
0344         if (AcpiGbl_DeviceNotify.Handler)
0345         {
0346             GlobalHandler = AcpiGbl_DeviceNotify.Handler;
0347             GlobalContext = AcpiGbl_DeviceNotify.Context;
0348         }
0349     }
0350 
0351     /* Invoke the system handler first, if present */
0352 
0353     if (GlobalHandler)
0354     {
0355         GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value,
0356             GlobalContext);
0357     }
0358 
0359     /* Now invoke the per-device handler, if present */
0360 
0361     HandlerObj = NotifyInfo->Notify.HandlerObj;
0362     if (HandlerObj)
0363     {
0364         HandlerObj->Notify.Handler (NotifyInfo->Notify.Node,
0365             NotifyInfo->Notify.Value,
0366             HandlerObj->Notify.Context);
0367     }
0368 
0369     /* All done with the info object */
0370 
0371     AcpiUtDeleteGenericState (NotifyInfo);
0372 }
0373 
0374 
0375 /*******************************************************************************
0376  *
0377  * FUNCTION:    AcpiEvGlobalLockHandler
0378  *
0379  * PARAMETERS:  Context         - From thread interface, not used
0380  *
0381  * RETURN:      ACPI_INTERRUPT_HANDLED
0382  *
0383  * DESCRIPTION: Invoked directly from the SCI handler when a global lock
0384  *              release interrupt occurs. Attempt to acquire the global lock,
0385  *              if successful, signal the thread waiting for the lock.
0386  *
0387  * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
0388  * this is not possible for some reason, a separate thread will have to be
0389  * scheduled to do this.
0390  *
0391  ******************************************************************************/
0392 
0393 static UINT32
0394 AcpiEvGlobalLockHandler (
0395     void                    *Context)
0396 {
0397     BOOLEAN                 Acquired = FALSE;
0398     ACPI_STATUS             Status;
0399 
0400 
0401     /*
0402      * Attempt to get the lock.
0403      *
0404      * If we don't get it now, it will be marked pending and we will
0405      * take another interrupt when it becomes free.
0406      */
0407     ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
0408     if (Acquired)
0409     {
0410         /* Got the lock, now wake the thread waiting for it */
0411 
0412         AcpiGbl_GlobalLockAcquired = TRUE;
0413 
0414         /* Send a unit to the semaphore */
0415 
0416         Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
0417         if (ACPI_FAILURE (Status))
0418         {
0419             ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
0420         }
0421     }
0422 
0423     return (ACPI_INTERRUPT_HANDLED);
0424 }
0425 
0426 
0427 /*******************************************************************************
0428  *
0429  * FUNCTION:    AcpiEvInitGlobalLockHandler
0430  *
0431  * PARAMETERS:  None
0432  *
0433  * RETURN:      Status
0434  *
0435  * DESCRIPTION: Install a handler for the global lock release event
0436  *
0437  ******************************************************************************/
0438 
0439 ACPI_STATUS
0440 AcpiEvInitGlobalLockHandler (
0441     void)
0442 {
0443     ACPI_STATUS             Status;
0444 
0445 
0446     ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
0447 
0448 
0449     /* Attempt installation of the global lock handler */
0450 
0451     Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
0452                 AcpiEvGlobalLockHandler, NULL);
0453 
0454     /*
0455      * If the global lock does not exist on this platform, the attempt to
0456      * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
0457      * Map to AE_OK, but mark global lock as not present. Any attempt to
0458      * actually use the global lock will be flagged with an error.
0459      */
0460     if (Status == AE_NO_HARDWARE_RESPONSE)
0461     {
0462         ACPI_ERROR ((AE_INFO,
0463             "No response from Global Lock hardware, disabling lock"));
0464 
0465         AcpiGbl_GlobalLockPresent = FALSE;
0466         return_ACPI_STATUS (AE_OK);
0467     }
0468 
0469     AcpiGbl_GlobalLockPresent = TRUE;
0470     return_ACPI_STATUS (Status);
0471 }
0472 
0473 
0474 /*******************************************************************************
0475  *
0476  * FUNCTION:    AcpiEvRemoveGlobalLockHandler
0477  *
0478  * PARAMETERS:  None
0479  *
0480  * RETURN:      Status
0481  *
0482  * DESCRIPTION: Remove the handler for the Global Lock
0483  *
0484  ******************************************************************************/
0485 
0486 static ACPI_STATUS
0487 AcpiEvRemoveGlobalLockHandler (
0488     void)
0489 {
0490     ACPI_STATUS             Status;
0491 
0492 
0493     ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
0494 
0495     AcpiGbl_GlobalLockPresent = FALSE;
0496     Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
0497                 AcpiEvGlobalLockHandler);
0498 
0499     return_ACPI_STATUS (Status);
0500 }
0501 
0502 
0503 /******************************************************************************
0504  *
0505  * FUNCTION:    AcpiEvAcquireGlobalLock
0506  *
0507  * PARAMETERS:  Timeout         - Max time to wait for the lock, in millisec.
0508  *
0509  * RETURN:      Status
0510  *
0511  * DESCRIPTION: Attempt to gain ownership of the Global Lock.
0512  *
0513  * MUTEX:       Interpreter must be locked
0514  *
0515  * Note: The original implementation allowed multiple threads to "acquire" the
0516  * Global Lock, and the OS would hold the lock until the last thread had
0517  * released it. However, this could potentially starve the BIOS out of the
0518  * lock, especially in the case where there is a tight handshake between the
0519  * Embedded Controller driver and the BIOS. Therefore, this implementation
0520  * allows only one thread to acquire the HW Global Lock at a time, and makes
0521  * the global lock appear as a standard mutex on the OS side.
0522  *
0523  *****************************************************************************/
0524 
0525 ACPI_STATUS
0526 AcpiEvAcquireGlobalLock (
0527     UINT16                  Timeout)
0528 {
0529     ACPI_STATUS             Status = AE_OK;
0530     BOOLEAN                 Acquired = FALSE;
0531 
0532 
0533     ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
0534 
0535 
0536     /*
0537      * Only one thread can acquire the GL at a time, the GlobalLockMutex
0538      * enforces this. This interface releases the interpreter if we must wait.
0539      */
0540     Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
0541                 Timeout);
0542     if (ACPI_FAILURE (Status))
0543     {
0544         return_ACPI_STATUS (Status);
0545     }
0546 
0547     /*
0548      * Update the global lock handle and check for wraparound. The handle is
0549      * only used for the external global lock interfaces, but it is updated
0550      * here to properly handle the case where a single thread may acquire the
0551      * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
0552      * handle is therefore updated on the first acquire from a given thread
0553      * regardless of where the acquisition request originated.
0554      */
0555     AcpiGbl_GlobalLockHandle++;
0556     if (AcpiGbl_GlobalLockHandle == 0)
0557     {
0558         AcpiGbl_GlobalLockHandle = 1;
0559     }
0560 
0561     /*
0562      * Make sure that a global lock actually exists. If not, just treat the
0563      * lock as a standard mutex.
0564      */
0565     if (!AcpiGbl_GlobalLockPresent)
0566     {
0567         AcpiGbl_GlobalLockAcquired = TRUE;
0568         return_ACPI_STATUS (AE_OK);
0569     }
0570 
0571     /* Attempt to acquire the actual hardware lock */
0572 
0573     ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
0574     if (Acquired)
0575     {
0576        /* We got the lock */
0577 
0578         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired hardware Global Lock\n"));
0579 
0580         AcpiGbl_GlobalLockAcquired = TRUE;
0581         return_ACPI_STATUS (AE_OK);
0582     }
0583 
0584     /*
0585      * Did not get the lock. The pending bit was set above, and we must now
0586      * wait until we get the global lock released interrupt.
0587      */
0588     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n"));
0589 
0590     /*
0591      * Wait for handshake with the global lock interrupt handler.
0592      * This interface releases the interpreter if we must wait.
0593      */
0594     Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
0595                 ACPI_WAIT_FOREVER);
0596 
0597     return_ACPI_STATUS (Status);
0598 }
0599 
0600 
0601 /*******************************************************************************
0602  *
0603  * FUNCTION:    AcpiEvReleaseGlobalLock
0604  *
0605  * PARAMETERS:  None
0606  *
0607  * RETURN:      Status
0608  *
0609  * DESCRIPTION: Releases ownership of the Global Lock.
0610  *
0611  ******************************************************************************/
0612 
0613 ACPI_STATUS
0614 AcpiEvReleaseGlobalLock (
0615     void)
0616 {
0617     BOOLEAN                 Pending = FALSE;
0618     ACPI_STATUS             Status = AE_OK;
0619 
0620 
0621     ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
0622 
0623 
0624     /* Lock must be already acquired */
0625 
0626     if (!AcpiGbl_GlobalLockAcquired)
0627     {
0628         ACPI_WARNING ((AE_INFO,
0629             "Cannot release the ACPI Global Lock, it has not been acquired"));
0630         return_ACPI_STATUS (AE_NOT_ACQUIRED);
0631     }
0632 
0633     if (AcpiGbl_GlobalLockPresent)
0634     {
0635         /* Allow any thread to release the lock */
0636 
0637         ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
0638 
0639         /*
0640          * If the pending bit was set, we must write GBL_RLS to the control
0641          * register
0642          */
0643         if (Pending)
0644         {
0645             Status = AcpiWriteBitRegister (
0646                         ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT);
0647         }
0648 
0649         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
0650     }
0651 
0652     AcpiGbl_GlobalLockAcquired = FALSE;
0653 
0654     /* Release the local GL mutex */
0655 
0656     AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
0657     return_ACPI_STATUS (Status);
0658 }
0659 
0660 
0661 /******************************************************************************
0662  *
0663  * FUNCTION:    AcpiEvTerminate
0664  *
0665  * PARAMETERS:  none
0666  *
0667  * RETURN:      none
0668  *
0669  * DESCRIPTION: Disable events and free memory allocated for table storage.
0670  *
0671  ******************************************************************************/
0672 
0673 void
0674 AcpiEvTerminate (
0675     void)
0676 {
0677     UINT32                  i;
0678     ACPI_STATUS             Status;
0679 
0680 
0681     ACPI_FUNCTION_TRACE (EvTerminate);
0682 
0683 
0684     if (AcpiGbl_EventsInitialized)
0685     {
0686         /*
0687          * Disable all event-related functionality. In all cases, on error,
0688          * print a message but obviously we don't abort.
0689          */
0690 
0691         /* Disable all fixed events */
0692 
0693         for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
0694         {
0695             Status = AcpiDisableEvent (i, 0);
0696             if (ACPI_FAILURE (Status))
0697             {
0698                 ACPI_ERROR ((AE_INFO,
0699                     "Could not disable fixed event %d", (UINT32) i));
0700             }
0701         }
0702 
0703         /* Disable all GPEs in all GPE blocks */
0704 
0705         Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
0706 
0707         /* Remove SCI handler */
0708 
0709         Status = AcpiEvRemoveSciHandler ();
0710         if (ACPI_FAILURE(Status))
0711         {
0712             ACPI_ERROR ((AE_INFO,
0713                 "Could not remove SCI handler"));
0714         }
0715 
0716         Status = AcpiEvRemoveGlobalLockHandler ();
0717         if (ACPI_FAILURE(Status))
0718         {
0719             ACPI_ERROR ((AE_INFO,
0720                 "Could not remove Global Lock handler"));
0721         }
0722     }
0723 
0724     /* Deallocate all handler objects installed within GPE info structs */
0725 
0726     Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL);
0727 
0728     /* Return to original mode if necessary */
0729 
0730     if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
0731     {
0732         Status = AcpiDisable ();
0733         if (ACPI_FAILURE (Status))
0734         {
0735             ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));
0736         }
0737     }
0738     return_VOID;
0739 }
0740