1 /******************************************************************************
3 * Module Name: evmisc - Miscellaneous event manager support functions
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #include <contrib/dev/acpica/acpi.h>
118 #include <contrib/dev/acpica/acevents.h>
119 #include <contrib/dev/acpica/acnamesp.h>
120 #include <contrib/dev/acpica/acinterp.h>
122 #define _COMPONENT ACPI_EVENTS
123 ACPI_MODULE_NAME ("evmisc")
126 /* Names for Notify() values, used for debug output */
128 #ifdef ACPI_DEBUG_OUTPUT
129 static const char *AcpiNotifyValueNames[] =
135 "Device Check Light",
136 "Frequency Mismatch",
142 /* Pointer to FACS needed for the Global Lock */
144 static ACPI_TABLE_FACS *Facs = NULL;
146 /* Local prototypes */
148 static void ACPI_SYSTEM_XFACE
149 AcpiEvNotifyDispatch (
153 AcpiEvGlobalLockHandler (
157 AcpiEvRemoveGlobalLockHandler (
161 /*******************************************************************************
163 * FUNCTION: AcpiEvIsNotifyObject
165 * PARAMETERS: Node - Node to check
167 * RETURN: TRUE if notifies allowed on this object
169 * DESCRIPTION: Check type of node for a object that supports notifies.
171 * TBD: This could be replaced by a flag bit in the node.
173 ******************************************************************************/
176 AcpiEvIsNotifyObject (
177 ACPI_NAMESPACE_NODE *Node)
181 case ACPI_TYPE_DEVICE:
182 case ACPI_TYPE_PROCESSOR:
183 case ACPI_TYPE_POWER:
184 case ACPI_TYPE_THERMAL:
186 * These are the ONLY objects that can receive ACPI notifications
196 /*******************************************************************************
198 * FUNCTION: AcpiEvQueueNotifyRequest
200 * PARAMETERS: Node - NS node for the notified object
201 * NotifyValue - Value from the Notify() request
205 * DESCRIPTION: Dispatch a device notification event to a previously
208 ******************************************************************************/
211 AcpiEvQueueNotifyRequest (
212 ACPI_NAMESPACE_NODE *Node,
215 ACPI_OPERAND_OBJECT *ObjDesc;
216 ACPI_OPERAND_OBJECT *HandlerObj = NULL;
217 ACPI_GENERIC_STATE *NotifyInfo;
218 ACPI_STATUS Status = AE_OK;
221 ACPI_FUNCTION_NAME (EvQueueNotifyRequest);
225 * For value 3 (Ejection Request), some device method may need to be run.
226 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need
228 * For value 0x80 (Status Change) on the power button or sleep button,
229 * initiate soft-off or sleep operation?
231 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
232 "Dispatching Notify(%X) on node %p\n", NotifyValue, Node));
234 if (NotifyValue <= 7)
236 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: %s\n",
237 AcpiNotifyValueNames[NotifyValue]));
241 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
242 "Notify value: 0x%2.2X **Device Specific**\n",
246 /* Get the notify object attached to the NS Node */
248 ObjDesc = AcpiNsGetAttachedObject (Node);
251 /* We have the notify object, Get the right handler */
255 case ACPI_TYPE_DEVICE:
256 case ACPI_TYPE_THERMAL:
257 case ACPI_TYPE_PROCESSOR:
258 case ACPI_TYPE_POWER:
260 if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
262 HandlerObj = ObjDesc->CommonNotify.SystemNotify;
266 HandlerObj = ObjDesc->CommonNotify.DeviceNotify;
271 /* All other types are not supported */
276 /* If there is any handler to run, schedule the dispatcher */
278 if ((AcpiGbl_SystemNotify.Handler && (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) ||
279 (AcpiGbl_DeviceNotify.Handler && (NotifyValue > ACPI_MAX_SYS_NOTIFY)) ||
282 NotifyInfo = AcpiUtCreateGenericState ();
285 return (AE_NO_MEMORY);
288 NotifyInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_NOTIFY;
289 NotifyInfo->Notify.Node = Node;
290 NotifyInfo->Notify.Value = (UINT16) NotifyValue;
291 NotifyInfo->Notify.HandlerObj = HandlerObj;
293 Status = AcpiOsExecute (
294 OSL_NOTIFY_HANDLER, AcpiEvNotifyDispatch, NotifyInfo);
295 if (ACPI_FAILURE (Status))
297 AcpiUtDeleteGenericState (NotifyInfo);
304 * There is no per-device notify handler for this device.
305 * This may or may not be a problem.
307 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
308 "No notify handler for Notify(%4.4s, %X) node %p\n",
309 AcpiUtGetNodeName (Node), NotifyValue, Node));
316 /*******************************************************************************
318 * FUNCTION: AcpiEvNotifyDispatch
320 * PARAMETERS: Context - To be passed to the notify handler
324 * DESCRIPTION: Dispatch a device notification event to a previously
327 ******************************************************************************/
329 static void ACPI_SYSTEM_XFACE
330 AcpiEvNotifyDispatch (
333 ACPI_GENERIC_STATE *NotifyInfo = (ACPI_GENERIC_STATE *) Context;
334 ACPI_NOTIFY_HANDLER GlobalHandler = NULL;
335 void *GlobalContext = NULL;
336 ACPI_OPERAND_OBJECT *HandlerObj;
339 ACPI_FUNCTION_ENTRY ();
343 * We will invoke a global notify handler if installed.
344 * This is done _before_ we invoke the per-device handler attached
347 if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY)
349 /* Global system notification handler */
351 if (AcpiGbl_SystemNotify.Handler)
353 GlobalHandler = AcpiGbl_SystemNotify.Handler;
354 GlobalContext = AcpiGbl_SystemNotify.Context;
359 /* Global driver notification handler */
361 if (AcpiGbl_DeviceNotify.Handler)
363 GlobalHandler = AcpiGbl_DeviceNotify.Handler;
364 GlobalContext = AcpiGbl_DeviceNotify.Context;
368 /* Invoke the system handler first, if present */
372 GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value,
376 /* Now invoke the per-device handler, if present */
378 HandlerObj = NotifyInfo->Notify.HandlerObj;
381 HandlerObj->Notify.Handler (NotifyInfo->Notify.Node,
382 NotifyInfo->Notify.Value,
383 HandlerObj->Notify.Context);
386 /* All done with the info object */
388 AcpiUtDeleteGenericState (NotifyInfo);
392 /*******************************************************************************
394 * FUNCTION: AcpiEvGlobalLockHandler
396 * PARAMETERS: Context - From thread interface, not used
398 * RETURN: ACPI_INTERRUPT_HANDLED
400 * DESCRIPTION: Invoked directly from the SCI handler when a global lock
401 * release interrupt occurs. Attempt to acquire the global lock,
402 * if successful, signal the thread waiting for the lock.
404 * NOTE: Assumes that the semaphore can be signaled from interrupt level. If
405 * this is not possible for some reason, a separate thread will have to be
406 * scheduled to do this.
408 ******************************************************************************/
411 AcpiEvGlobalLockHandler (
414 BOOLEAN Acquired = FALSE;
419 * Attempt to get the lock.
421 * If we don't get it now, it will be marked pending and we will
422 * take another interrupt when it becomes free.
424 ACPI_ACQUIRE_GLOBAL_LOCK (Facs, Acquired);
427 /* Got the lock, now wake the thread waiting for it */
429 AcpiGbl_GlobalLockAcquired = TRUE;
431 /* Send a unit to the semaphore */
433 Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore, 1);
434 if (ACPI_FAILURE (Status))
436 ACPI_ERROR ((AE_INFO, "Could not signal Global Lock semaphore"));
440 return (ACPI_INTERRUPT_HANDLED);
444 /*******************************************************************************
446 * FUNCTION: AcpiEvInitGlobalLockHandler
452 * DESCRIPTION: Install a handler for the global lock release event
454 ******************************************************************************/
457 AcpiEvInitGlobalLockHandler (
463 ACPI_FUNCTION_TRACE (EvInitGlobalLockHandler);
466 Status = AcpiGetTableByIndex (ACPI_TABLE_INDEX_FACS,
467 ACPI_CAST_INDIRECT_PTR (ACPI_TABLE_HEADER, &Facs));
468 if (ACPI_FAILURE (Status))
470 return_ACPI_STATUS (Status);
473 AcpiGbl_GlobalLockPresent = TRUE;
474 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
475 AcpiEvGlobalLockHandler, NULL);
478 * If the global lock does not exist on this platform, the attempt
479 * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick)
480 * Map to AE_OK, but mark global lock as not present.
481 * Any attempt to actually use the global lock will be flagged
484 if (Status == AE_NO_HARDWARE_RESPONSE)
486 ACPI_ERROR ((AE_INFO,
487 "No response from Global Lock hardware, disabling lock"));
489 AcpiGbl_GlobalLockPresent = FALSE;
493 return_ACPI_STATUS (Status);
497 /*******************************************************************************
499 * FUNCTION: AcpiEvRemoveGlobalLockHandler
505 * DESCRIPTION: Remove the handler for the Global Lock
507 ******************************************************************************/
510 AcpiEvRemoveGlobalLockHandler (
516 ACPI_FUNCTION_TRACE (EvRemoveGlobalLockHandler);
518 AcpiGbl_GlobalLockPresent = FALSE;
519 Status = AcpiRemoveFixedEventHandler (ACPI_EVENT_GLOBAL,
520 AcpiEvGlobalLockHandler);
522 return_ACPI_STATUS (Status);
526 /******************************************************************************
528 * FUNCTION: AcpiEvAcquireGlobalLock
530 * PARAMETERS: Timeout - Max time to wait for the lock, in millisec.
534 * DESCRIPTION: Attempt to gain ownership of the Global Lock.
536 * MUTEX: Interpreter must be locked
538 * Note: The original implementation allowed multiple threads to "acquire" the
539 * Global Lock, and the OS would hold the lock until the last thread had
540 * released it. However, this could potentially starve the BIOS out of the
541 * lock, especially in the case where there is a tight handshake between the
542 * Embedded Controller driver and the BIOS. Therefore, this implementation
543 * allows only one thread to acquire the HW Global Lock at a time, and makes
544 * the global lock appear as a standard mutex on the OS side.
546 *****************************************************************************/
549 AcpiEvAcquireGlobalLock (
552 ACPI_STATUS Status = AE_OK;
553 BOOLEAN Acquired = FALSE;
556 ACPI_FUNCTION_TRACE (EvAcquireGlobalLock);
560 * Only one thread can acquire the GL at a time, the GlobalLockMutex
561 * enforces this. This interface releases the interpreter if we must wait.
563 Status = AcpiExSystemWaitMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex,
565 if (ACPI_FAILURE (Status))
567 return_ACPI_STATUS (Status);
571 * Update the global lock handle and check for wraparound. The handle is
572 * only used for the external global lock interfaces, but it is updated
573 * here to properly handle the case where a single thread may acquire the
574 * lock via both the AML and the AcpiAcquireGlobalLock interfaces. The
575 * handle is therefore updated on the first acquire from a given thread
576 * regardless of where the acquisition request originated.
578 AcpiGbl_GlobalLockHandle++;
579 if (AcpiGbl_GlobalLockHandle == 0)
581 AcpiGbl_GlobalLockHandle = 1;
585 * Make sure that a global lock actually exists. If not, just treat
586 * the lock as a standard mutex.
588 if (!AcpiGbl_GlobalLockPresent)
590 AcpiGbl_GlobalLockAcquired = TRUE;
591 return_ACPI_STATUS (AE_OK);
594 /* Attempt to acquire the actual hardware lock */
596 ACPI_ACQUIRE_GLOBAL_LOCK (Facs, Acquired);
599 /* We got the lock */
601 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired hardware Global Lock\n"));
603 AcpiGbl_GlobalLockAcquired = TRUE;
604 return_ACPI_STATUS (AE_OK);
608 * Did not get the lock. The pending bit was set above, and we must now
609 * wait until we get the global lock released interrupt.
611 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for hardware Global Lock\n"));
614 * Wait for handshake with the global lock interrupt handler.
615 * This interface releases the interpreter if we must wait.
617 Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
620 return_ACPI_STATUS (Status);
624 /*******************************************************************************
626 * FUNCTION: AcpiEvReleaseGlobalLock
632 * DESCRIPTION: Releases ownership of the Global Lock.
634 ******************************************************************************/
637 AcpiEvReleaseGlobalLock (
640 BOOLEAN Pending = FALSE;
641 ACPI_STATUS Status = AE_OK;
644 ACPI_FUNCTION_TRACE (EvReleaseGlobalLock);
647 /* Lock must be already acquired */
649 if (!AcpiGbl_GlobalLockAcquired)
651 ACPI_WARNING ((AE_INFO,
652 "Cannot release the ACPI Global Lock, it has not been acquired"));
653 return_ACPI_STATUS (AE_NOT_ACQUIRED);
656 if (AcpiGbl_GlobalLockPresent)
658 /* Allow any thread to release the lock */
660 ACPI_RELEASE_GLOBAL_LOCK (Facs, Pending);
663 * If the pending bit was set, we must write GBL_RLS to the control
668 Status = AcpiSetRegister (
669 ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1);
672 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Released hardware Global Lock\n"));
675 AcpiGbl_GlobalLockAcquired = FALSE;
677 /* Release the local GL mutex */
679 AcpiOsReleaseMutex (AcpiGbl_GlobalLockMutex->Mutex.OsMutex);
680 return_ACPI_STATUS (Status);
684 /******************************************************************************
686 * FUNCTION: AcpiEvTerminate
692 * DESCRIPTION: Disable events and free memory allocated for table storage.
694 ******************************************************************************/
704 ACPI_FUNCTION_TRACE (EvTerminate);
707 if (AcpiGbl_EventsInitialized)
710 * Disable all event-related functionality.
711 * In all cases, on error, print a message but obviously we don't abort.
714 /* Disable all fixed events */
716 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
718 Status = AcpiDisableEvent ((UINT32) i, 0);
719 if (ACPI_FAILURE (Status))
721 ACPI_ERROR ((AE_INFO,
722 "Could not disable fixed event %d", (UINT32) i));
726 /* Disable all GPEs in all GPE blocks */
728 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock);
730 /* Remove SCI handler */
732 Status = AcpiEvRemoveSciHandler ();
733 if (ACPI_FAILURE(Status))
735 ACPI_ERROR ((AE_INFO,
736 "Could not remove SCI handler"));
739 Status = AcpiEvRemoveGlobalLockHandler ();
740 if (ACPI_FAILURE(Status))
742 ACPI_ERROR ((AE_INFO,
743 "Could not remove Global Lock handler"));
747 /* Deallocate all handler objects installed within GPE info structs */
749 Status = AcpiEvWalkGpeList (AcpiEvDeleteGpeHandlers);
751 /* Return to original mode if necessary */
753 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
755 Status = AcpiDisable ();
756 if (ACPI_FAILURE (Status))
758 ACPI_WARNING ((AE_INFO, "AcpiDisable failed"));