1 /******************************************************************************
3 * Module Name: evmisc - Miscellaneous event manager support functions
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/evmisc.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $ */
119 #include "acevents.h"
120 #include "acnamesp.h"
121 #include "acinterp.h"
123 #define _COMPONENT ACPI_EVENTS
124 ACPI_MODULE_NAME ("evmisc")
127 /*******************************************************************************
129 * FUNCTION: AcpiEvIsNotifyObject
131 * PARAMETERS: Node - Node to check
133 * RETURN: TRUE if notifies allowed on this object
135 * DESCRIPTION: Check type of node for a object that supports notifies.
137 * TBD: This could be replaced by a flag bit in the node.
139 ******************************************************************************/
142 AcpiEvIsNotifyObject (
143 ACPI_NAMESPACE_NODE *Node)
147 case ACPI_TYPE_DEVICE:
148 case ACPI_TYPE_PROCESSOR:
149 case ACPI_TYPE_POWER:
150 case ACPI_TYPE_THERMAL:
152 * These are the ONLY objects that can receive ACPI notifications
162 /*******************************************************************************
164 * FUNCTION: AcpiEvQueueNotifyRequest
170 * DESCRIPTION: Dispatch a device notification event to a previously
173 ******************************************************************************/
176 AcpiEvQueueNotifyRequest (
177 ACPI_NAMESPACE_NODE *Node,
180 ACPI_OPERAND_OBJECT *ObjDesc;
181 ACPI_OPERAND_OBJECT *HandlerObj = NULL;
182 ACPI_GENERIC_STATE *NotifyInfo;
183 ACPI_STATUS Status = AE_OK;
186 ACPI_FUNCTION_NAME ("EvQueueNotifyRequest");
190 * For value 1 (Ejection Request), some device method may need to be run.
191 * For value 2 (Device Wake) if _PRW exists, the _PS0 method may need to be run.
192 * For value 0x80 (Status Change) on the power button or sleep button,
193 * initiate soft-off or sleep operation?
195 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
196 "Dispatching Notify(%X) on node %p\n", NotifyValue, Node));
201 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Re-enumerate Devices\n"));
205 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Ejection Request\n"));
209 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Device Wake\n"));
213 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Notify value: Status Change\n"));
217 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Unknown Notify Value: %X \n", NotifyValue));
222 * Get the notify object attached to the NS Node
224 ObjDesc = AcpiNsGetAttachedObject (Node);
227 /* We have the notify object, Get the right handler */
231 case ACPI_TYPE_DEVICE:
232 case ACPI_TYPE_THERMAL:
233 case ACPI_TYPE_PROCESSOR:
234 case ACPI_TYPE_POWER:
236 if (NotifyValue <= ACPI_MAX_SYS_NOTIFY)
238 HandlerObj = ObjDesc->CommonNotify.SysHandler;
242 HandlerObj = ObjDesc->CommonNotify.DrvHandler;
247 /* All other types are not supported */
252 /* If there is any handler to run, schedule the dispatcher */
254 if ((AcpiGbl_SysNotify.Handler && (NotifyValue <= ACPI_MAX_SYS_NOTIFY)) ||
255 (AcpiGbl_DrvNotify.Handler && (NotifyValue > ACPI_MAX_SYS_NOTIFY)) ||
258 NotifyInfo = AcpiUtCreateGenericState ();
261 return (AE_NO_MEMORY);
264 NotifyInfo->Common.DataType = ACPI_DESC_TYPE_STATE_NOTIFY;
265 NotifyInfo->Notify.Node = Node;
266 NotifyInfo->Notify.Value = (UINT16) NotifyValue;
267 NotifyInfo->Notify.HandlerObj = HandlerObj;
269 Status = AcpiOsQueueForExecution (OSD_PRIORITY_HIGH,
270 AcpiEvNotifyDispatch, NotifyInfo);
271 if (ACPI_FAILURE (Status))
273 AcpiUtDeleteGenericState (NotifyInfo);
279 /* There is no per-device notify handler for this device */
281 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
282 "No notify handler for [%4.4s] node %p\n", Node->Name.Ascii, Node));
289 /*******************************************************************************
291 * FUNCTION: AcpiEvNotifyDispatch
297 * DESCRIPTION: Dispatch a device notification event to a previously
300 ******************************************************************************/
302 void ACPI_SYSTEM_XFACE
303 AcpiEvNotifyDispatch (
306 ACPI_GENERIC_STATE *NotifyInfo = (ACPI_GENERIC_STATE *) Context;
307 ACPI_NOTIFY_HANDLER GlobalHandler = NULL;
308 void *GlobalContext = NULL;
309 ACPI_OPERAND_OBJECT *HandlerObj;
312 ACPI_FUNCTION_ENTRY ();
316 * We will invoke a global notify handler if installed.
317 * This is done _before_ we invoke the per-device handler attached to the device.
319 if (NotifyInfo->Notify.Value <= ACPI_MAX_SYS_NOTIFY)
321 /* Global system notification handler */
323 if (AcpiGbl_SysNotify.Handler)
325 GlobalHandler = AcpiGbl_SysNotify.Handler;
326 GlobalContext = AcpiGbl_SysNotify.Context;
331 /* Global driver notification handler */
333 if (AcpiGbl_DrvNotify.Handler)
335 GlobalHandler = AcpiGbl_DrvNotify.Handler;
336 GlobalContext = AcpiGbl_DrvNotify.Context;
340 /* Invoke the system handler first, if present */
344 GlobalHandler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value, GlobalContext);
347 /* Now invoke the per-device handler, if present */
349 HandlerObj = NotifyInfo->Notify.HandlerObj;
352 HandlerObj->NotifyHandler.Handler (NotifyInfo->Notify.Node, NotifyInfo->Notify.Value,
353 HandlerObj->NotifyHandler.Context);
356 /* All done with the info object */
358 AcpiUtDeleteGenericState (NotifyInfo);
362 /*******************************************************************************
364 * FUNCTION: AcpiEvGlobalLockThread
368 * DESCRIPTION: Invoked by SCI interrupt handler upon acquisition of the
369 * Global Lock. Simply signal all threads that are waiting
372 ******************************************************************************/
374 static void ACPI_SYSTEM_XFACE
375 AcpiEvGlobalLockThread (
381 /* Signal threads that are waiting for the lock */
383 if (AcpiGbl_GlobalLockThreadCount)
385 /* Send sufficient units to the semaphore */
387 Status = AcpiOsSignalSemaphore (AcpiGbl_GlobalLockSemaphore,
388 AcpiGbl_GlobalLockThreadCount);
389 if (ACPI_FAILURE (Status))
391 ACPI_REPORT_ERROR (("Could not signal Global Lock semaphore\n"));
397 /*******************************************************************************
399 * FUNCTION: AcpiEvGlobalLockHandler
403 * DESCRIPTION: Invoked directly from the SCI handler when a global lock
404 * release interrupt occurs. Grab the global lock and queue
405 * the global lock thread for execution
407 ******************************************************************************/
410 AcpiEvGlobalLockHandler (
413 BOOLEAN Acquired = FALSE;
418 * Attempt to get the lock
419 * If we don't get it now, it will be marked pending and we will
420 * take another interrupt when it becomes free.
422 ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Acquired);
425 /* Got the lock, now wake all threads waiting for it */
427 AcpiGbl_GlobalLockAcquired = TRUE;
429 /* Run the Global Lock thread which will signal all waiting threads */
431 Status = AcpiOsQueueForExecution (OSD_PRIORITY_HIGH,
432 AcpiEvGlobalLockThread, Context);
433 if (ACPI_FAILURE (Status))
435 ACPI_REPORT_ERROR (("Could not queue Global Lock thread, %s\n",
436 AcpiFormatException (Status)));
438 return (ACPI_INTERRUPT_NOT_HANDLED);
442 return (ACPI_INTERRUPT_HANDLED);
446 /*******************************************************************************
448 * FUNCTION: AcpiEvInitGlobalLockHandler
452 * DESCRIPTION: Install a handler for the global lock release event
454 ******************************************************************************/
457 AcpiEvInitGlobalLockHandler (void)
462 ACPI_FUNCTION_TRACE ("EvInitGlobalLockHandler");
465 AcpiGbl_GlobalLockPresent = TRUE;
466 Status = AcpiInstallFixedEventHandler (ACPI_EVENT_GLOBAL,
467 AcpiEvGlobalLockHandler, NULL);
470 * If the global lock does not exist on this platform, the attempt
471 * to enable GBL_STATUS will fail (the GBL_ENABLE bit will not stick)
472 * Map to AE_OK, but mark global lock as not present.
473 * Any attempt to actually use the global lock will be flagged
476 if (Status == AE_NO_HARDWARE_RESPONSE)
478 AcpiGbl_GlobalLockPresent = FALSE;
482 return_ACPI_STATUS (Status);
486 /******************************************************************************
488 * FUNCTION: AcpiEvAcquireGlobalLock
492 * DESCRIPTION: Attempt to gain ownership of the Global Lock.
494 *****************************************************************************/
497 AcpiEvAcquireGlobalLock (
500 ACPI_STATUS Status = AE_OK;
501 BOOLEAN Acquired = FALSE;
504 ACPI_FUNCTION_TRACE ("EvAcquireGlobalLock");
507 #ifndef ACPI_APPLICATION
508 /* Make sure that we actually have a global lock */
510 if (!AcpiGbl_GlobalLockPresent)
512 return_ACPI_STATUS (AE_NO_GLOBAL_LOCK);
516 /* One more thread wants the global lock */
518 AcpiGbl_GlobalLockThreadCount++;
520 /* If we (OS side vs. BIOS side) have the hardware lock already, we are done */
522 if (AcpiGbl_GlobalLockAcquired)
524 return_ACPI_STATUS (AE_OK);
527 /* We must acquire the actual hardware lock */
529 ACPI_ACQUIRE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Acquired);
532 /* We got the lock */
534 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Acquired the HW Global Lock\n"));
536 AcpiGbl_GlobalLockAcquired = TRUE;
537 return_ACPI_STATUS (AE_OK);
541 * Did not get the lock. The pending bit was set above, and we must now
542 * wait until we get the global lock released interrupt.
544 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Waiting for the HW Global Lock\n"));
547 * Acquire the global lock semaphore first.
548 * Since this wait will block, we must release the interpreter
550 Status = AcpiExSystemWaitSemaphore (AcpiGbl_GlobalLockSemaphore,
552 return_ACPI_STATUS (Status);
556 /*******************************************************************************
558 * FUNCTION: AcpiEvReleaseGlobalLock
560 * DESCRIPTION: Releases ownership of the Global Lock.
562 ******************************************************************************/
565 AcpiEvReleaseGlobalLock (void)
567 BOOLEAN Pending = FALSE;
568 ACPI_STATUS Status = AE_OK;
571 ACPI_FUNCTION_TRACE ("EvReleaseGlobalLock");
574 if (!AcpiGbl_GlobalLockThreadCount)
576 ACPI_REPORT_WARNING(("Cannot release HW Global Lock, it has not been acquired\n"));
577 return_ACPI_STATUS (AE_NOT_ACQUIRED);
580 /* One fewer thread has the global lock */
582 AcpiGbl_GlobalLockThreadCount--;
583 if (AcpiGbl_GlobalLockThreadCount)
585 /* There are still some threads holding the lock, cannot release */
587 return_ACPI_STATUS (AE_OK);
591 * No more threads holding lock, we can do the actual hardware
594 ACPI_RELEASE_GLOBAL_LOCK (AcpiGbl_CommonFACS.GlobalLock, Pending);
595 AcpiGbl_GlobalLockAcquired = FALSE;
598 * If the pending bit was set, we must write GBL_RLS to the control
603 Status = AcpiSetRegister (ACPI_BITREG_GLOBAL_LOCK_RELEASE, 1, ACPI_MTX_LOCK);
606 return_ACPI_STATUS (Status);
610 /******************************************************************************
612 * FUNCTION: AcpiEvTerminate
618 * DESCRIPTION: Disable events and free memory allocated for table storage.
620 ******************************************************************************/
623 AcpiEvTerminate (void)
627 ACPI_GPE_BLOCK_INFO *GpeBlock;
628 ACPI_GPE_BLOCK_INFO *NextGpeBlock;
629 ACPI_GPE_EVENT_INFO *GpeEventInfo;
632 ACPI_FUNCTION_TRACE ("EvTerminate");
635 if (AcpiGbl_EventsInitialized)
638 * Disable all event-related functionality.
639 * In all cases, on error, print a message but obviously we don't abort.
643 * Disable all fixed events
645 for (i = 0; i < ACPI_NUM_FIXED_EVENTS; i++)
647 Status = AcpiDisableEvent ((UINT32) i, ACPI_EVENT_FIXED, 0);
648 if (ACPI_FAILURE (Status))
650 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable fixed event %d\n", (UINT32) i));
657 GpeBlock = AcpiGbl_GpeBlockListHead;
660 GpeEventInfo = GpeBlock->EventInfo;
661 for (i = 0; i < (GpeBlock->RegisterCount * 8); i++)
663 Status = AcpiHwDisableGpe (GpeEventInfo);
664 if (ACPI_FAILURE (Status))
666 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not disable GPE %d\n", (UINT32) i));
672 GpeBlock = GpeBlock->Next;
678 Status = AcpiEvRemoveSciHandler ();
679 if (ACPI_FAILURE(Status))
681 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not remove SCI handler\n"));
686 * Return to original mode if necessary
688 if (AcpiGbl_OriginalMode == ACPI_SYS_MODE_LEGACY)
690 Status = AcpiDisable ();
691 if (ACPI_FAILURE (Status))
693 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "AcpiDisable failed\n"));
698 * Free global GPE blocks and related info structures
700 GpeBlock = AcpiGbl_GpeBlockListHead;
703 NextGpeBlock = GpeBlock->Next;
704 ACPI_MEM_FREE (GpeBlock->EventInfo);
705 ACPI_MEM_FREE (GpeBlock->RegisterInfo);
706 ACPI_MEM_FREE (GpeBlock);
708 GpeBlock = NextGpeBlock;