xref: /onnv-gate/usr/src/uts/intel/io/acpica/events/evmisc.c (revision 9980:13d7f3eec672)
13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: evmisc - Miscellaneous event manager support functions
43446Smrj  *
53446Smrj  *****************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
11*9980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj #include "acpi.h"
117*9980SDana.Myers@Sun.COM #include "accommon.h"
1183446Smrj #include "acevents.h"
1193446Smrj #include "acnamesp.h"
1203446Smrj #include "acinterp.h"
1213446Smrj 
1223446Smrj #define _COMPONENT          ACPI_EVENTS
1233446Smrj         ACPI_MODULE_NAME    ("evmisc")
1243446Smrj 
1253446Smrj 
1263446Smrj /* Local prototypes */
1273446Smrj 
1283446Smrj static void ACPI_SYSTEM_XFACE
1293446Smrj AcpiEvNotifyDispatch (
1303446Smrj     void                    *Context);
1313446Smrj 
1323446Smrj static UINT32
1333446Smrj AcpiEvGlobalLockHandler (
1343446Smrj     void                    *Context);
1353446Smrj 
1367851SDana.Myers@Sun.COM static ACPI_STATUS
1377851SDana.Myers@Sun.COM AcpiEvRemoveGlobalLockHandler (
1387851SDana.Myers@Sun.COM     void);
1397851SDana.Myers@Sun.COM 
1403446Smrj 
1413446Smrj /*******************************************************************************
1423446Smrj  *
1433446Smrj  * FUNCTION:    AcpiEvIsNotifyObject
1443446Smrj  *
1453446Smrj  * PARAMETERS:  Node            - Node to check
1463446Smrj  *
1473446Smrj  * RETURN:      TRUE if notifies allowed on this object
1483446Smrj  *
1493446Smrj  * DESCRIPTION: Check type of node for a object that supports notifies.
1503446Smrj  *
1513446Smrj  *              TBD: This could be replaced by a flag bit in the node.
1523446Smrj  *
1533446Smrj  ******************************************************************************/
1543446Smrj 
1553446Smrj BOOLEAN
AcpiEvIsNotifyObject(ACPI_NAMESPACE_NODE * Node)1563446Smrj AcpiEvIsNotifyObject (
1573446Smrj     ACPI_NAMESPACE_NODE     *Node)
1583446Smrj {
1593446Smrj     switch (Node->Type)
1603446Smrj     {
1613446Smrj     case ACPI_TYPE_DEVICE:
1623446Smrj     case ACPI_TYPE_PROCESSOR:
1633446Smrj     case ACPI_TYPE_THERMAL:
1643446Smrj         /*
1653446Smrj          * These are the ONLY objects that can receive ACPI notifications
1663446Smrj          */
1673446Smrj         return (TRUE);
1683446Smrj 
1693446Smrj     default:
1703446Smrj         return (FALSE);
1713446Smrj     }
1723446Smrj }
1733446Smrj 
1743446Smrj 
1753446Smrj /*******************************************************************************
1763446Smrj  *
1773446Smrj  * FUNCTION:    AcpiEvQueueNotifyRequest
1783446Smrj  *
1793446Smrj  * PARAMETERS:  Node            - NS node for the notified object
1803446Smrj  *              NotifyValue     - Value from the Notify() request
1813446Smrj  *
1823446Smrj  * RETURN:      Status
1833446Smrj  *
1843446Smrj  * DESCRIPTION: Dispatch a device notification event to a previously
1853446Smrj  *              installed handler.
1863446Smrj  *
1873446Smrj  ******************************************************************************/
1883446Smrj 
1893446Smrj ACPI_STATUS
AcpiEvQueueNotifyRequest(ACPI_NAMESPACE_NODE * Node,UINT32 NotifyValue)1903446Smrj AcpiEvQueueNotifyRequest (
1913446Smrj     ACPI_NAMESPACE_NODE     *Node,
1923446Smrj     UINT32                  NotifyValue)
1933446Smrj {
1943446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
1953446Smrj     ACPI_OPERAND_OBJECT     *HandlerObj = NULL;
1963446Smrj     ACPI_GENERIC_STATE      *NotifyInfo;
1973446Smrj     ACPI_STATUS             Status = AE_OK;
1983446Smrj 
1993446Smrj 
2003446Smrj     ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
2013446Smrj 
2023446Smrj 
2033446Smrj     /*
2043446Smrj      * For value 3 (Ejection Request), some device method may need to be run.
2053446Smrj      * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
2063446Smrj      *   to be run.
2073446Smrj      * For value 0x80 (Status Change) on the power button or sleep button,
2083446Smrj      *   initiate soft-off or sleep operation?
2093446Smrj      */
2103446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
2117851SDana.Myers@Sun.COM         "Dispatching Notify on [%4.4s] Node %p Value 0x%2.2X (%s)\n",
2127851SDana.Myers@Sun.COM         AcpiUtGetNodeName (Node), Node, NotifyValue,
2137851SDana.Myers@Sun.COM         AcpiUtGetNotifyName (NotifyValue)));
2143446Smrj 
2153446Smrj     /* Get the notify object attached to the NS Node */
2163446Smrj 
2173446Smrj     ObjDesc = AcpiNsGetAttachedObject (Node);
2183446Smrj     if (ObjDesc)
2193446Smrj     {
2203446Smrj         /* We have the notify object, Get the right handler */
2213446Smrj 
2223446Smrj         switch (Node->Type)
2233446Smrj         {
2247851SDana.Myers@Sun.COM         /* Notify allowed only on these types */
2257851SDana.Myers@Sun.COM 
2263446Smrj         case ACPI_TYPE_DEVICE:
2273446Smrj         case ACPI_TYPE_THERMAL:
2283446Smrj         case ACPI_TYPE_PROCESSOR:
2293446Smrj 
2303446Smrj             if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
2313446Smrj             {
2323446Smrj                 HandlerObj = ObjDesc->CommonNotify.SystemNotify;
2333446Smrj             }
2343446Smrj             else
2353446Smrj             {
2363446Smrj                 HandlerObj = ObjDesc->CommonNotify.DeviceNotify;
2373446Smrj             }
2383446Smrj             break;
2393446Smrj 
2403446Smrj         default:
241*9980SDana.Myers@Sun.COM 
2423446Smrj             /* All other types are not supported */
243*9980SDana.Myers@Sun.COM 
2443446Smrj             return (AE_TYPE);
2453446Smrj         }
2463446Smrj     }
2473446Smrj 
2487851SDana.Myers@Sun.COM     /*
2497851SDana.Myers@Sun.COM      * If there is any handler to run, schedule the dispatcher.
2507851SDana.Myers@Sun.COM      * Check for:
2517851SDana.Myers@Sun.COM      * 1) Global system notify handler
2527851SDana.Myers@Sun.COM      * 2) Global device notify handler
2537851SDana.Myers@Sun.COM      * 3) Per-device notify handler
2547851SDana.Myers@Sun.COM      */
255*9980SDana.Myers@Sun.COM     if ((AcpiGbl_SystemNotify.Handler &&
256*9980SDana.Myers@Sun.COM             (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) ||
257*9980SDana.Myers@Sun.COM         (AcpiGbl_DeviceNotify.Handler &&
258*9980SDana.Myers@Sun.COM             (NotifyValue > ACPI_MAX_SYS_NOTIFY))  ||
2593446Smrj         HandlerObj)
2603446Smrj     {
2613446Smrj         NotifyInfo = AcpiUtCreateGenericState ();
2623446Smrj         if (!NotifyInfo)
2633446Smrj         {
2643446Smrj             return (AE_NO_MEMORY);
2653446Smrj         }
2663446Smrj 
2677851SDana.Myers@Sun.COM         if (!HandlerObj)
2687851SDana.Myers@Sun.COM         {
2697851SDana.Myers@Sun.COM             ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
270*9980SDana.Myers@Sun.COM                 "Executing system notify handler for Notify (%4.4s, %X) "
271*9980SDana.Myers@Sun.COM                 "node %p\n",
2727851SDana.Myers@Sun.COM                 AcpiUtGetNodeName (Node), NotifyValue, Node));
2737851SDana.Myers@Sun.COM         }
2747851SDana.Myers@Sun.COM 
2753446Smrj         NotifyInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
2763446Smrj         NotifyInfo->Notify.Node = Node;
2773446Smrj         NotifyInfo->Notify.Value = (UINT16) NotifyValue;
2783446Smrj         NotifyInfo->Notify.HandlerObj = HandlerObj;
2793446Smrj 
2803446Smrj         Status = AcpiOsExecute (
2813446Smrj                     OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, NotifyInfo);
2823446Smrj         if (ACPI_FAILURE (Status))
2833446Smrj         {
2843446Smrj             AcpiUtDeleteGenericState (NotifyInfo);
2853446Smrj         }
2863446Smrj     }
2877851SDana.Myers@Sun.COM     else
2883446Smrj     {
289*9980SDana.Myers@Sun.COM         /* There is no notify handler (per-device or system) for this device */
290*9980SDana.Myers@Sun.COM 
2913446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
2927851SDana.Myers@Sun.COM             "No notify handler for Notify (%4.4s, %X) node %p\n",
2933446Smrj             AcpiUtGetNodeName (Node), NotifyValue, Node));
2943446Smrj     }
2953446Smrj 
2963446Smrj     return (Status);
2973446Smrj }
2983446Smrj 
2993446Smrj 
3003446Smrj /*******************************************************************************
3013446Smrj  *
3023446Smrj  * FUNCTION:    AcpiEvNotifyDispatch
3033446Smrj  *
3043446Smrj  * PARAMETERS:  Context         - To be passed to the notify handler
3053446Smrj  *
3063446Smrj  * RETURN:      None.
3073446Smrj  *
3083446Smrj  * DESCRIPTION: Dispatch a device notification event to a previously
3093446Smrj  *              installed handler.
3103446Smrj  *
3113446Smrj  ******************************************************************************/
3123446Smrj 
3133446Smrj static void ACPI_SYSTEM_XFACE
AcpiEvNotifyDispatch(void * Context)3143446Smrj AcpiEvNotifyDispatch (
3153446Smrj     void                    *Context)
3163446Smrj {
3173446Smrj     ACPI_GENERIC_STATE      *NotifyInfo = (ACPI_GENERIC_STATE *) Context;
3183446Smrj     ACPI_NOTIFY_HANDLER     GlobalHandler = NULL;
3193446Smrj     void                    *GlobalContext = NULL;
3203446Smrj     ACPI_OPERAND_OBJECT     *HandlerObj;
3213446Smrj 
3223446Smrj 
3233446Smrj     ACPI_FUNCTION_ENTRY ();
3243446Smrj 
3253446Smrj 
3263446Smrj     /*
327*9980SDana.Myers@Sun.COM      * We will invoke a global notify handler if installed. This is done
328*9980SDana.Myers@Sun.COM      * _before_ we invoke the per-device handler attached to the device.
3293446Smrj      */
3303446Smrj     if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY)
3313446Smrj     {
3323446Smrj         /* Global system notification handler */
3333446Smrj 
3343446Smrj         if (AcpiGbl_SystemNotify.Handler)
3353446Smrj         {
3363446Smrj             GlobalHandler = AcpiGbl_SystemNotify.Handler;
3373446Smrj             GlobalContext = AcpiGbl_SystemNotify.Context;
3383446Smrj         }
3393446Smrj     }
3403446Smrj     else
3413446Smrj     {
3423446Smrj         /* Global driver notification handler */
3433446Smrj 
3443446Smrj         if (AcpiGbl_DeviceNotify.Handler)
3453446Smrj         {
3463446Smrj             GlobalHandler = AcpiGbl_DeviceNotify.Handler;
3473446Smrj             GlobalContext = AcpiGbl_DeviceNotify.Context;
3483446Smrj         }
3493446Smrj     }
3503446Smrj 
3513446Smrj     /* Invoke the system handler first, if present */
3523446Smrj 
3533446Smrj     if (GlobalHandler)
3543446Smrj     {
3553446Smrj         GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value,
3563446Smrj             GlobalContext);
3573446Smrj     }
3583446Smrj 
3593446Smrj     /* Now invoke the per-device handler, if present */
3603446Smrj 
3613446Smrj     HandlerObj = NotifyInfo->Notify.HandlerObj;
3623446Smrj     if (HandlerObj)
3633446Smrj     {
3643446Smrj         HandlerObj->Notify.Handler (NotifyInfo->Notify.Node,
3653446Smrj             NotifyInfo->Notify.Value,
3663446Smrj             HandlerObj->Notify.Context);
3673446Smrj     }
3683446Smrj 
3693446Smrj     /* All done with the info object */
3703446Smrj 
3713446Smrj     AcpiUtDeleteGenericState (NotifyInfo);
3723446Smrj }
3733446Smrj 
3743446Smrj 
3753446Smrj /*******************************************************************************
3763446Smrj  *
3773446Smrj  * FUNCTION:    AcpiEvGlobalLockHandler
3783446Smrj  *
3793446Smrj  * PARAMETERS:  Context         - From thread interface, not used
3803446Smrj  *
3813446Smrj  * RETURN:      ACPI_INTERRUPT_HANDLED
3823446Smrj  *
3833446Smrj  * DESCRIPTION: Invoked directly from the SCI handler when a global lock
3843446Smrj  *              release interrupt occurs. Attempt to acquire the global lock,
3853446Smrj  *              if successful, signal the thread waiting for the lock.
3863446Smrj  *
3873446Smrj  * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
3883446Smrj  * this is not possible for some reason, a separate thread will have to be
3893446Smrj  * scheduled to do this.
3903446Smrj  *
3913446Smrj  ******************************************************************************/
3923446Smrj 
3933446Smrj static UINT32
AcpiEvGlobalLockHandler(void * Context)3943446Smrj AcpiEvGlobalLockHandler (
3953446Smrj     void                    *Context)
3963446Smrj {
3973446Smrj     BOOLEAN                 Acquired = FALSE;
3983446Smrj     ACPI_STATUS             Status;
3993446Smrj 
4003446Smrj 
4013446Smrj     /*
4023446Smrj      * Attempt to get the lock.
4033446Smrj      *
4043446Smrj      * If we don't get it now, it will be marked pending and we will
4053446Smrj      * take another interrupt when it becomes free.
4063446Smrj      */
407*9980SDana.Myers@Sun.COM     ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
4083446Smrj     if (Acquired)
4093446Smrj     {
4103446Smrj         /* Got the lock, now wake the thread waiting for it */
4113446Smrj 
4123446Smrj         AcpiGbl_GlobalLockAcquired = TRUE;
4133446Smrj 
4143446Smrj         /* Send a unit to the semaphore */
4153446Smrj 
4163446Smrj         Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
4173446Smrj         if (ACPI_FAILURE (Status))
4183446Smrj         {
4193446Smrj             ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
4203446Smrj         }
4213446Smrj     }
4223446Smrj 
4233446Smrj     return (ACPI_INTERRUPT_HANDLED);
4243446Smrj }
4253446Smrj 
4263446Smrj 
4273446Smrj /*******************************************************************************
4283446Smrj  *
4293446Smrj  * FUNCTION:    AcpiEvInitGlobalLockHandler
4303446Smrj  *
4313446Smrj  * PARAMETERS:  None
4323446Smrj  *
4333446Smrj  * RETURN:      Status
4343446Smrj  *
4353446Smrj  * DESCRIPTION: Install a handler for the global lock release event
4363446Smrj  *
4373446Smrj  ******************************************************************************/
4383446Smrj 
4393446Smrj ACPI_STATUS
AcpiEvInitGlobalLockHandler(void)4403446Smrj AcpiEvInitGlobalLockHandler (
4413446Smrj     void)
4423446Smrj {
4433446Smrj     ACPI_STATUS             Status;
4443446Smrj 
4453446Smrj 
4463446Smrj     ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
4473446Smrj 
4483446Smrj 
449*9980SDana.Myers@Sun.COM     /* Attempt installation of the global lock handler */
4507851SDana.Myers@Sun.COM 
4513446Smrj     Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
4523446Smrj                 AcpiEvGlobalLockHandler, NULL);
4533446Smrj 
4543446Smrj     /*
455*9980SDana.Myers@Sun.COM      * If the global lock does not exist on this platform, the attempt to
456*9980SDana.Myers@Sun.COM      * enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick).
457*9980SDana.Myers@Sun.COM      * Map to AE_OK, but mark global lock as not present. Any attempt to
458*9980SDana.Myers@Sun.COM      * actually use the global lock will be flagged with an error.
4593446Smrj      */
4603446Smrj     if (Status == AE_NO_HARDWARE_RESPONSE)
4613446Smrj     {
4623446Smrj         ACPI_ERROR ((AE_INFO,
4633446Smrj             "No response from Global Lock hardware, disabling lock"));
4643446Smrj 
4653446Smrj         AcpiGbl_GlobalLockPresent = FALSE;
466*9980SDana.Myers@Sun.COM         return_ACPI_STATUS (AE_OK);
4673446Smrj     }
4683446Smrj 
469*9980SDana.Myers@Sun.COM     AcpiGbl_GlobalLockPresent = TRUE;
4703446Smrj     return_ACPI_STATUS (Status);
4713446Smrj }
4723446Smrj 
4733446Smrj 
4747851SDana.Myers@Sun.COM /*******************************************************************************
4757851SDana.Myers@Sun.COM  *
4767851SDana.Myers@Sun.COM  * FUNCTION:    AcpiEvRemoveGlobalLockHandler
4777851SDana.Myers@Sun.COM  *
4787851SDana.Myers@Sun.COM  * PARAMETERS:  None
4797851SDana.Myers@Sun.COM  *
4807851SDana.Myers@Sun.COM  * RETURN:      Status
4817851SDana.Myers@Sun.COM  *
4827851SDana.Myers@Sun.COM  * DESCRIPTION: Remove the handler for the Global Lock
4837851SDana.Myers@Sun.COM  *
4847851SDana.Myers@Sun.COM  ******************************************************************************/
4857851SDana.Myers@Sun.COM 
4867851SDana.Myers@Sun.COM static ACPI_STATUS
AcpiEvRemoveGlobalLockHandler(void)4877851SDana.Myers@Sun.COM AcpiEvRemoveGlobalLockHandler (
4887851SDana.Myers@Sun.COM     void)
4897851SDana.Myers@Sun.COM {
4907851SDana.Myers@Sun.COM     ACPI_STATUS             Status;
4917851SDana.Myers@Sun.COM 
4927851SDana.Myers@Sun.COM 
4937851SDana.Myers@Sun.COM     ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
4947851SDana.Myers@Sun.COM 
4957851SDana.Myers@Sun.COM     AcpiGbl_GlobalLockPresent = FALSE;
4967851SDana.Myers@Sun.COM     Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
4977851SDana.Myers@Sun.COM                 AcpiEvGlobalLockHandler);
4987851SDana.Myers@Sun.COM 
4997851SDana.Myers@Sun.COM     return_ACPI_STATUS (Status);
5007851SDana.Myers@Sun.COM }
5017851SDana.Myers@Sun.COM 
5027851SDana.Myers@Sun.COM 
5033446Smrj /******************************************************************************
5043446Smrj  *
5053446Smrj  * FUNCTION:    AcpiEvAcquireGlobalLock
5063446Smrj  *
5073446Smrj  * PARAMETERS:  Timeout         - Max time to wait for the lock, in millisec.
5083446Smrj  *
5093446Smrj  * RETURN:      Status
5103446Smrj  *
5113446Smrj  * DESCRIPTION: Attempt to gain ownership of the Global Lock.
5123446Smrj  *
5133446Smrj  * MUTEX:       Interpreter must be locked
5143446Smrj  *
5153446Smrj  * Note: The original implementation allowed multiple threads to "acquire" the
5163446Smrj  * Global Lock, and the OS would hold the lock until the last thread had
5173446Smrj  * released it. However, this could potentially starve the BIOS out of the
5183446Smrj  * lock, especially in the case where there is a tight handshake between the
5193446Smrj  * Embedded Controller driver and the BIOS. Therefore, this implementation
5203446Smrj  * allows only one thread to acquire the HW Global Lock at a time, and makes
5213446Smrj  * the global lock appear as a standard mutex on the OS side.
5223446Smrj  *
5233446Smrj  *****************************************************************************/
5243446Smrj 
5253446Smrj ACPI_STATUS
AcpiEvAcquireGlobalLock(UINT16 Timeout)5263446Smrj AcpiEvAcquireGlobalLock (
5273446Smrj     UINT16                  Timeout)
5283446Smrj {
5293446Smrj     ACPI_STATUS             Status = AE_OK;
5303446Smrj     BOOLEAN                 Acquired = FALSE;
5313446Smrj 
5323446Smrj 
5333446Smrj     ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
5343446Smrj 
5353446Smrj 
5363446Smrj     /*
5373446Smrj      * Only one thread can acquire the GL at a time, the GlobalLockMutex
5383446Smrj      * enforces this. This interface releases the interpreter if we must wait.
5393446Smrj      */
5407851SDana.Myers@Sun.COM     Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
5417851SDana.Myers@Sun.COM                 Timeout);
5423446Smrj     if (ACPI_FAILURE (Status))
5433446Smrj     {
5443446Smrj         return_ACPI_STATUS (Status);
5453446Smrj     }
5463446Smrj 
5473446Smrj     /*
5487851SDana.Myers@Sun.COM      * Update the global lock handle and check for wraparound. The handle is
5497851SDana.Myers@Sun.COM      * only used for the external global lock interfaces, but it is updated
5507851SDana.Myers@Sun.COM      * here to properly handle the case where a single thread may acquire the
5517851SDana.Myers@Sun.COM      * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
5527851SDana.Myers@Sun.COM      * handle is therefore updated on the first acquire from a given thread
5537851SDana.Myers@Sun.COM      * regardless of where the acquisition request originated.
5547851SDana.Myers@Sun.COM      */
5557851SDana.Myers@Sun.COM     AcpiGbl_GlobalLockHandle++;
5567851SDana.Myers@Sun.COM     if (AcpiGbl_GlobalLockHandle == 0)
5577851SDana.Myers@Sun.COM     {
5587851SDana.Myers@Sun.COM         AcpiGbl_GlobalLockHandle = 1;
5597851SDana.Myers@Sun.COM     }
5607851SDana.Myers@Sun.COM 
5617851SDana.Myers@Sun.COM     /*
562*9980SDana.Myers@Sun.COM      * Make sure that a global lock actually exists. If not, just treat the
563*9980SDana.Myers@Sun.COM      * lock as a standard mutex.
5643446Smrj      */
5653446Smrj     if (!AcpiGbl_GlobalLockPresent)
5663446Smrj     {
5673446Smrj         AcpiGbl_GlobalLockAcquired = TRUE;
5683446Smrj         return_ACPI_STATUS (AE_OK);
5693446Smrj     }
5703446Smrj 
5713446Smrj     /* Attempt to acquire the actual hardware lock */
5723446Smrj 
573*9980SDana.Myers@Sun.COM     ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_FACS, Acquired);
5743446Smrj     if (Acquired)
5753446Smrj     {
5763446Smrj        /* We got the lock */
5773446Smrj 
5783446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired hardware Global Lock\n"));
5793446Smrj 
5803446Smrj         AcpiGbl_GlobalLockAcquired = TRUE;
5813446Smrj         return_ACPI_STATUS (AE_OK);
5823446Smrj     }
5833446Smrj 
5843446Smrj     /*
5853446Smrj      * Did not get the lock. The pending bit was set above, and we must now
5863446Smrj      * wait until we get the global lock released interrupt.
5873446Smrj      */
5883446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n"));
5893446Smrj 
5903446Smrj     /*
5913446Smrj      * Wait for handshake with the global lock interrupt handler.
5923446Smrj      * This interface releases the interpreter if we must wait.
5933446Smrj      */
5943446Smrj     Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
5953446Smrj                 ACPI_WAIT_FOREVER);
5967851SDana.Myers@Sun.COM 
5973446Smrj     return_ACPI_STATUS (Status);
5983446Smrj }
5993446Smrj 
6003446Smrj 
6013446Smrj /*******************************************************************************
6023446Smrj  *
6033446Smrj  * FUNCTION:    AcpiEvReleaseGlobalLock
6043446Smrj  *
6053446Smrj  * PARAMETERS:  None
6063446Smrj  *
6073446Smrj  * RETURN:      Status
6083446Smrj  *
6093446Smrj  * DESCRIPTION: Releases ownership of the Global Lock.
6103446Smrj  *
6113446Smrj  ******************************************************************************/
6123446Smrj 
6133446Smrj ACPI_STATUS
AcpiEvReleaseGlobalLock(void)6143446Smrj AcpiEvReleaseGlobalLock (
6153446Smrj     void)
6163446Smrj {
6173446Smrj     BOOLEAN                 Pending = FALSE;
6183446Smrj     ACPI_STATUS             Status = AE_OK;
6193446Smrj 
6203446Smrj 
6213446Smrj     ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
6223446Smrj 
6233446Smrj 
6243446Smrj     /* Lock must be already acquired */
6253446Smrj 
6263446Smrj     if (!AcpiGbl_GlobalLockAcquired)
6273446Smrj     {
6283446Smrj         ACPI_WARNING ((AE_INFO,
6293446Smrj             "Cannot release the ACPI Global Lock, it has not been acquired"));
6303446Smrj         return_ACPI_STATUS (AE_NOT_ACQUIRED);
6313446Smrj     }
6323446Smrj 
6333446Smrj     if (AcpiGbl_GlobalLockPresent)
6343446Smrj     {
6353446Smrj         /* Allow any thread to release the lock */
6363446Smrj 
637*9980SDana.Myers@Sun.COM         ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_FACS, Pending);
6383446Smrj 
6393446Smrj         /*
6403446Smrj          * If the pending bit was set, we must write GBL_RLS to the control
6413446Smrj          * register
6423446Smrj          */
6433446Smrj         if (Pending)
6443446Smrj         {
645*9980SDana.Myers@Sun.COM             Status = AcpiWriteBitRegister (
646*9980SDana.Myers@Sun.COM                         ACPI_BITREG_GLOBAL_LOCK_RELEASE, ACPI_ENABLE_EVENT);
6473446Smrj         }
6483446Smrj 
6493446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
6503446Smrj     }
6513446Smrj 
6523446Smrj     AcpiGbl_GlobalLockAcquired = FALSE;
6533446Smrj 
6543446Smrj     /* Release the local GL mutex */
6553446Smrj 
6567851SDana.Myers@Sun.COM     AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
6573446Smrj     return_ACPI_STATUS (Status);
6583446Smrj }
6593446Smrj 
6603446Smrj 
6613446Smrj /******************************************************************************
6623446Smrj  *
6633446Smrj  * FUNCTION:    AcpiEvTerminate
6643446Smrj  *
6653446Smrj  * PARAMETERS:  none
6663446Smrj  *
6673446Smrj  * RETURN:      none
6683446Smrj  *
6693446Smrj  * DESCRIPTION: Disable events and free memory allocated for table storage.
6703446Smrj  *
6713446Smrj  ******************************************************************************/
6723446Smrj 
6733446Smrj void
AcpiEvTerminate(void)6743446Smrj AcpiEvTerminate (
6753446Smrj     void)
6763446Smrj {
6777851SDana.Myers@Sun.COM     UINT32                  i;
6783446Smrj     ACPI_STATUS             Status;
6793446Smrj 
6803446Smrj 
6813446Smrj     ACPI_FUNCTION_TRACE (EvTerminate);
6823446Smrj 
6833446Smrj 
6843446Smrj     if (AcpiGbl_EventsInitialized)
6853446Smrj     {
6863446Smrj         /*
687*9980SDana.Myers@Sun.COM          * Disable all event-related functionality. In all cases, on error,
688*9980SDana.Myers@Sun.COM          * print a message but obviously we don't abort.
6893446Smrj          */
6903446Smrj 
6913446Smrj         /* Disable all fixed events */
6923446Smrj 
6933446Smrj         for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
6943446Smrj         {
6957851SDana.Myers@Sun.COM             Status = AcpiDisableEvent (i, 0);
6963446Smrj             if (ACPI_FAILURE (Status))
6973446Smrj             {
6983446Smrj                 ACPI_ERROR ((AE_INFO,
6993446Smrj                     "Could not disable fixed event %d", (UINT32) i));
7003446Smrj             }
7013446Smrj         }
7023446Smrj 
7033446Smrj         /* Disable all GPEs in all GPE blocks */
7043446Smrj 
705*9980SDana.Myers@Sun.COM         Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
7063446Smrj 
7073446Smrj         /* Remove SCI handler */
7083446Smrj 
7093446Smrj         Status = AcpiEvRemoveSciHandler ();
7103446Smrj         if (ACPI_FAILURE(Status))
7113446Smrj         {
7123446Smrj             ACPI_ERROR ((AE_INFO,
7133446Smrj                 "Could not remove SCI handler"));
7143446Smrj         }
7157851SDana.Myers@Sun.COM 
7167851SDana.Myers@Sun.COM         Status = AcpiEvRemoveGlobalLockHandler ();
7177851SDana.Myers@Sun.COM         if (ACPI_FAILURE(Status))
7187851SDana.Myers@Sun.COM         {
7197851SDana.Myers@Sun.COM             ACPI_ERROR ((AE_INFO,
7207851SDana.Myers@Sun.COM                 "Could not remove Global Lock handler"));
7217851SDana.Myers@Sun.COM         }
7223446Smrj     }
7233446Smrj 
7243446Smrj     /* Deallocate all handler objects installed within GPE info structs */
7253446Smrj 
726*9980SDana.Myers@Sun.COM     Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers, NULL);
7273446Smrj 
7283446Smrj     /* Return to original mode if necessary */
7293446Smrj 
7303446Smrj     if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
7313446Smrj     {
7323446Smrj         Status = AcpiDisable ();
7333446Smrj         if (ACPI_FAILURE (Status))
7343446Smrj         {
7353446Smrj             ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));
7363446Smrj         }
7373446Smrj     }
7383446Smrj     return_VOID;
7393446Smrj }
7403446Smrj 
741