No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / events / evgpe.c
blob17738b384040aa920cdff015516b053831463854
1 /******************************************************************************
3 * Module Name: evgpe - General Purpose Event handling and dispatch
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "acevents.h"
119 #include "acnamesp.h"
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpe")
124 /* Local prototypes */
126 static void ACPI_SYSTEM_XFACE
127 AcpiEvAsynchExecuteGpeMethod (
128 void *Context);
130 static void ACPI_SYSTEM_XFACE
131 AcpiEvAsynchEnableGpe (
132 void *Context);
135 /*******************************************************************************
137 * FUNCTION: AcpiEvSetGpeType
139 * PARAMETERS: GpeEventInfo - GPE to set
140 * Type - New type
142 * RETURN: Status
144 * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
146 ******************************************************************************/
148 ACPI_STATUS
149 AcpiEvSetGpeType (
150 ACPI_GPE_EVENT_INFO *GpeEventInfo,
151 UINT8 Type)
153 ACPI_STATUS Status;
156 ACPI_FUNCTION_TRACE (EvSetGpeType);
159 /* Validate type and update register enable masks */
161 switch (Type)
163 case ACPI_GPE_TYPE_WAKE:
164 case ACPI_GPE_TYPE_RUNTIME:
165 case ACPI_GPE_TYPE_WAKE_RUN:
166 break;
168 default:
169 return_ACPI_STATUS (AE_BAD_PARAMETER);
172 /* Disable the GPE if currently enabled */
174 Status = AcpiEvDisableGpe (GpeEventInfo);
176 /* Clear the type bits and insert the new Type */
178 GpeEventInfo->Flags &= ~ACPI_GPE_TYPE_MASK;
179 GpeEventInfo->Flags |= Type;
180 return_ACPI_STATUS (Status);
184 /*******************************************************************************
186 * FUNCTION: AcpiEvUpdateGpeEnableMasks
188 * PARAMETERS: GpeEventInfo - GPE to update
189 * Type - What to do: ACPI_GPE_DISABLE or
190 * ACPI_GPE_ENABLE
192 * RETURN: Status
194 * DESCRIPTION: Updates GPE register enable masks based on the GPE type
196 ******************************************************************************/
198 ACPI_STATUS
199 AcpiEvUpdateGpeEnableMasks (
200 ACPI_GPE_EVENT_INFO *GpeEventInfo,
201 UINT8 Type)
203 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
204 UINT8 RegisterBit;
207 ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMasks);
210 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
211 if (!GpeRegisterInfo)
213 return_ACPI_STATUS (AE_NOT_EXIST);
216 RegisterBit = (UINT8)
217 (1 << (GpeEventInfo->GpeNumber - GpeRegisterInfo->BaseGpeNumber));
219 /* 1) Disable case. Simply clear all enable bits */
221 if (Type == ACPI_GPE_DISABLE)
223 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
224 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
225 return_ACPI_STATUS (AE_OK);
228 /* 2) Enable case. Set/Clear the appropriate enable bits */
230 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
232 case ACPI_GPE_TYPE_WAKE:
233 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
234 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
235 break;
237 case ACPI_GPE_TYPE_RUNTIME:
238 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
239 ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
240 break;
242 case ACPI_GPE_TYPE_WAKE_RUN:
243 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, RegisterBit);
244 ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
245 break;
247 default:
248 return_ACPI_STATUS (AE_BAD_PARAMETER);
251 return_ACPI_STATUS (AE_OK);
255 /*******************************************************************************
257 * FUNCTION: AcpiEvEnableGpe
259 * PARAMETERS: GpeEventInfo - GPE to enable
260 * WriteToHardware - Enable now, or just mark data structs
261 * (WAKE GPEs should be deferred)
263 * RETURN: Status
265 * DESCRIPTION: Enable a GPE based on the GPE type
267 ******************************************************************************/
269 ACPI_STATUS
270 AcpiEvEnableGpe (
271 ACPI_GPE_EVENT_INFO *GpeEventInfo,
272 BOOLEAN WriteToHardware)
274 ACPI_STATUS Status;
277 ACPI_FUNCTION_TRACE (EvEnableGpe);
280 /* Make sure HW enable masks are updated */
282 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_ENABLE);
283 if (ACPI_FAILURE (Status))
285 return_ACPI_STATUS (Status);
288 /* Mark wake-enabled or HW enable, or both */
290 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
292 case ACPI_GPE_TYPE_WAKE:
294 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
295 break;
297 case ACPI_GPE_TYPE_WAKE_RUN:
299 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
301 /*lint -fallthrough */
303 case ACPI_GPE_TYPE_RUNTIME:
305 ACPI_SET_BIT (GpeEventInfo->Flags, ACPI_GPE_RUN_ENABLED);
307 if (WriteToHardware)
309 /* Clear the GPE (of stale events), then enable it */
311 Status = AcpiHwClearGpe (GpeEventInfo);
312 if (ACPI_FAILURE (Status))
314 return_ACPI_STATUS (Status);
317 /* Enable the requested runtime GPE */
319 Status = AcpiHwWriteGpeEnableReg (GpeEventInfo);
321 break;
323 default:
324 return_ACPI_STATUS (AE_BAD_PARAMETER);
327 return_ACPI_STATUS (AE_OK);
331 /*******************************************************************************
333 * FUNCTION: AcpiEvDisableGpe
335 * PARAMETERS: GpeEventInfo - GPE to disable
337 * RETURN: Status
339 * DESCRIPTION: Disable a GPE based on the GPE type
341 ******************************************************************************/
343 ACPI_STATUS
344 AcpiEvDisableGpe (
345 ACPI_GPE_EVENT_INFO *GpeEventInfo)
347 ACPI_STATUS Status;
350 ACPI_FUNCTION_TRACE (EvDisableGpe);
354 * Note: Always disable the GPE, even if we think that that it is already
355 * disabled. It is possible that the AML or some other code has enabled
356 * the GPE behind our back.
359 /* Make sure HW enable masks are updated */
361 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_DISABLE);
362 if (ACPI_FAILURE (Status))
364 return_ACPI_STATUS (Status);
367 /* Clear the appropriate enabled flags for this GPE */
369 switch (GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK)
371 case ACPI_GPE_TYPE_WAKE:
373 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
374 break;
376 case ACPI_GPE_TYPE_WAKE_RUN:
378 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_WAKE_ENABLED);
380 /*lint -fallthrough */
382 case ACPI_GPE_TYPE_RUNTIME:
384 /* Disable the requested runtime GPE */
386 ACPI_CLEAR_BIT (GpeEventInfo->Flags, ACPI_GPE_RUN_ENABLED);
387 break;
389 default:
390 break;
394 * Always H/W disable this GPE, even if we don't know the GPE type.
395 * Simply clear the enable bit for this particular GPE, but do not
396 * write out the current GPE enable mask since this may inadvertently
397 * enable GPEs too early. An example is a rogue GPE that has arrived
398 * during ACPICA initialization - possibly because AML or other code
399 * has enabled the GPE.
401 Status = AcpiHwLowDisableGpe (GpeEventInfo);
402 return_ACPI_STATUS (Status);
406 /*******************************************************************************
408 * FUNCTION: AcpiEvGetGpeEventInfo
410 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
411 * GpeNumber - Raw GPE number
413 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE
415 * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
416 * Validates the GpeBlock and the GpeNumber
418 * Should be called only when the GPE lists are semaphore locked
419 * and not subject to change.
421 ******************************************************************************/
423 ACPI_GPE_EVENT_INFO *
424 AcpiEvGetGpeEventInfo (
425 ACPI_HANDLE GpeDevice,
426 UINT32 GpeNumber)
428 ACPI_OPERAND_OBJECT *ObjDesc;
429 ACPI_GPE_BLOCK_INFO *GpeBlock;
430 UINT32 i;
433 ACPI_FUNCTION_ENTRY ();
436 /* A NULL GpeBlock means use the FADT-defined GPE block(s) */
438 if (!GpeDevice)
440 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
442 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
444 GpeBlock = AcpiGbl_GpeFadtBlocks[i];
445 if (GpeBlock)
447 if ((GpeNumber >= GpeBlock->BlockBaseNumber) &&
448 (GpeNumber < GpeBlock->BlockBaseNumber +
449 (GpeBlock->RegisterCount * 8)))
451 return (&GpeBlock->EventInfo[GpeNumber -
452 GpeBlock->BlockBaseNumber]);
457 /* The GpeNumber was not in the range of either FADT GPE block */
459 return (NULL);
462 /* A Non-NULL GpeDevice means this is a GPE Block Device */
464 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
465 if (!ObjDesc ||
466 !ObjDesc->Device.GpeBlock)
468 return (NULL);
471 GpeBlock = ObjDesc->Device.GpeBlock;
473 if ((GpeNumber >= GpeBlock->BlockBaseNumber) &&
474 (GpeNumber < GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8)))
476 return (&GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber]);
479 return (NULL);
483 /*******************************************************************************
485 * FUNCTION: AcpiEvGpeDetect
487 * PARAMETERS: GpeXruptList - Interrupt block for this interrupt.
488 * Can have multiple GPE blocks attached.
490 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
492 * DESCRIPTION: Detect if any GP events have occurred. This function is
493 * executed at interrupt level.
495 ******************************************************************************/
497 UINT32
498 AcpiEvGpeDetect (
499 ACPI_GPE_XRUPT_INFO *GpeXruptList)
501 ACPI_STATUS Status;
502 ACPI_GPE_BLOCK_INFO *GpeBlock;
503 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
504 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
505 UINT8 EnabledStatusByte;
506 UINT32 StatusReg;
507 UINT32 EnableReg;
508 ACPI_CPU_FLAGS Flags;
509 UINT32 i;
510 UINT32 j;
513 ACPI_FUNCTION_NAME (EvGpeDetect);
515 /* Check for the case where there are no GPEs */
517 if (!GpeXruptList)
519 return (IntStatus);
523 * We need to obtain the GPE lock for both the data structs and registers
524 * Note: Not necessary to obtain the hardware lock, since the GPE
525 * registers are owned by the GpeLock.
527 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
529 /* Examine all GPE blocks attached to this interrupt level */
531 GpeBlock = GpeXruptList->GpeBlockListHead;
532 while (GpeBlock)
535 * Read all of the 8-bit GPE status and enable registers in this GPE
536 * block, saving all of them. Find all currently active GP events.
538 for (i = 0; i < GpeBlock->RegisterCount; i++)
540 /* Get the next status/enable pair */
542 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
544 /* Read the Status Register */
546 Status = AcpiHwRead (&StatusReg, &GpeRegisterInfo->StatusAddress);
547 if (ACPI_FAILURE (Status))
549 goto UnlockAndExit;
552 /* Read the Enable Register */
554 Status = AcpiHwRead (&EnableReg, &GpeRegisterInfo->EnableAddress);
555 if (ACPI_FAILURE (Status))
557 goto UnlockAndExit;
560 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
561 "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
562 GpeRegisterInfo->BaseGpeNumber, StatusReg, EnableReg));
564 /* Check if there is anything active at all in this register */
566 EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
567 if (!EnabledStatusByte)
569 /* No active GPEs in this register, move on */
571 continue;
574 /* Now look at the individual GPEs in this byte register */
576 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
578 /* Examine one GPE bit */
580 if (EnabledStatusByte & (1 << j))
583 * Found an active GPE. Dispatch the event to a handler
584 * or method.
586 IntStatus |= AcpiEvGpeDispatch (
587 &GpeBlock->EventInfo[((ACPI_SIZE) i *
588 ACPI_GPE_REGISTER_WIDTH) + j],
589 j + GpeRegisterInfo->BaseGpeNumber);
594 GpeBlock = GpeBlock->Next;
597 UnlockAndExit:
599 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
600 return (IntStatus);
604 /*******************************************************************************
606 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
608 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
610 * RETURN: None
612 * DESCRIPTION: Perform the actual execution of a GPE control method. This
613 * function is called from an invocation of AcpiOsExecute and
614 * therefore does NOT execute at interrupt level - so that
615 * the control method itself is not executed in the context of
616 * an interrupt handler.
618 ******************************************************************************/
620 static void ACPI_SYSTEM_XFACE
621 AcpiEvAsynchExecuteGpeMethod (
622 void *Context)
624 ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;
625 ACPI_STATUS Status;
626 ACPI_GPE_EVENT_INFO *LocalGpeEventInfo;
627 ACPI_EVALUATE_INFO *Info;
630 ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod);
633 /* Allocate a local GPE block */
635 LocalGpeEventInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_EVENT_INFO));
636 if (!LocalGpeEventInfo)
638 ACPI_EXCEPTION ((AE_INFO, AE_NO_MEMORY,
639 "while handling a GPE"));
640 return_VOID;
643 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
644 if (ACPI_FAILURE (Status))
646 return_VOID;
649 /* Must revalidate the GpeNumber/GpeBlock */
651 if (!AcpiEvValidGpeEvent (GpeEventInfo))
653 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
654 return_VOID;
657 /* Set the GPE flags for return to enabled state */
659 (void) AcpiEvEnableGpe (GpeEventInfo, FALSE);
662 * Take a snapshot of the GPE info for this level - we copy the info to
663 * prevent a race condition with RemoveHandler/RemoveBlock.
665 ACPI_MEMCPY (LocalGpeEventInfo, GpeEventInfo,
666 sizeof (ACPI_GPE_EVENT_INFO));
668 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
669 if (ACPI_FAILURE (Status))
671 return_VOID;
675 * Must check for control method type dispatch one more time to avoid a
676 * race with EvGpeInstallHandler
678 if ((LocalGpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
679 ACPI_GPE_DISPATCH_METHOD)
681 /* Allocate the evaluation information block */
683 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
684 if (!Info)
686 Status = AE_NO_MEMORY;
688 else
691 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
692 * control method that corresponds to this GPE
694 Info->PrefixNode = LocalGpeEventInfo->Dispatch.MethodNode;
695 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
697 Status = AcpiNsEvaluate (Info);
698 ACPI_FREE (Info);
701 if (ACPI_FAILURE (Status))
703 ACPI_EXCEPTION ((AE_INFO, Status,
704 "while evaluating GPE method [%4.4s]",
705 AcpiUtGetNodeName (LocalGpeEventInfo->Dispatch.MethodNode)));
709 /* Defer enabling of GPE until all notify handlers are done */
711 Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
712 AcpiEvAsynchEnableGpe, LocalGpeEventInfo);
713 if (ACPI_FAILURE (Status))
715 ACPI_FREE (LocalGpeEventInfo);
717 return_VOID;
721 /*******************************************************************************
723 * FUNCTION: AcpiEvAsynchEnableGpe
725 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
727 * RETURN: None
729 * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
730 * complete (i.e., finish execution of Notify)
732 ******************************************************************************/
734 static void ACPI_SYSTEM_XFACE
735 AcpiEvAsynchEnableGpe (
736 void *Context)
738 ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;
739 ACPI_STATUS Status;
742 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
743 ACPI_GPE_LEVEL_TRIGGERED)
746 * GPE is level-triggered, we clear the GPE status bit after handling
747 * the event.
749 Status = AcpiHwClearGpe (GpeEventInfo);
750 if (ACPI_FAILURE (Status))
752 goto Exit;
756 /* Enable this GPE */
758 (void) AcpiHwWriteGpeEnableReg (GpeEventInfo);
760 Exit:
761 ACPI_FREE (GpeEventInfo);
762 return;
766 /*******************************************************************************
768 * FUNCTION: AcpiEvGpeDispatch
770 * PARAMETERS: GpeEventInfo - Info for this GPE
771 * GpeNumber - Number relative to the parent GPE block
773 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
775 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
776 * or method (e.g. _Lxx/_Exx) handler.
778 * This function executes at interrupt level.
780 ******************************************************************************/
782 UINT32
783 AcpiEvGpeDispatch (
784 ACPI_GPE_EVENT_INFO *GpeEventInfo,
785 UINT32 GpeNumber)
787 ACPI_STATUS Status;
790 ACPI_FUNCTION_TRACE (EvGpeDispatch);
793 AcpiGpeCount++;
796 * If edge-triggered, clear the GPE status bit now. Note that
797 * level-triggered events are cleared after the GPE is serviced.
799 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
800 ACPI_GPE_EDGE_TRIGGERED)
802 Status = AcpiHwClearGpe (GpeEventInfo);
803 if (ACPI_FAILURE (Status))
805 ACPI_EXCEPTION ((AE_INFO, Status,
806 "Unable to clear GPE[%2X]", GpeNumber));
807 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
812 * Dispatch the GPE to either an installed handler, or the control method
813 * associated with this GPE (_Lxx or _Exx). If a handler exists, we invoke
814 * it and do not attempt to run the method. If there is neither a handler
815 * nor a method, we disable this GPE to prevent further such pointless
816 * events from firing.
818 switch (GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK)
820 case ACPI_GPE_DISPATCH_HANDLER:
823 * Invoke the installed handler (at interrupt level)
824 * Ignore return status for now.
825 * TBD: leave GPE disabled on error?
827 (void) GpeEventInfo->Dispatch.Handler->Address (
828 GpeEventInfo->Dispatch.Handler->Context);
830 /* It is now safe to clear level-triggered events. */
832 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
833 ACPI_GPE_LEVEL_TRIGGERED)
835 Status = AcpiHwClearGpe (GpeEventInfo);
836 if (ACPI_FAILURE (Status))
838 ACPI_EXCEPTION ((AE_INFO, Status,
839 "Unable to clear GPE[%2X]", GpeNumber));
840 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
843 break;
845 case ACPI_GPE_DISPATCH_METHOD:
848 * Disable the GPE, so it doesn't keep firing before the method has a
849 * chance to run (it runs asynchronously with interrupts enabled).
851 Status = AcpiEvDisableGpe (GpeEventInfo);
852 if (ACPI_FAILURE (Status))
854 ACPI_EXCEPTION ((AE_INFO, Status,
855 "Unable to disable GPE[%2X]", GpeNumber));
856 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
860 * Execute the method associated with the GPE
861 * NOTE: Level-triggered GPEs are cleared after the method completes.
863 Status = AcpiOsExecute (OSL_GPE_HANDLER,
864 AcpiEvAsynchExecuteGpeMethod, GpeEventInfo);
865 if (ACPI_FAILURE (Status))
867 ACPI_EXCEPTION ((AE_INFO, Status,
868 "Unable to queue handler for GPE[%2X] - event disabled",
869 GpeNumber));
871 break;
873 default:
875 /* No handler or method to run! */
877 ACPI_ERROR ((AE_INFO,
878 "No handler or method for GPE[%2X], disabling event",
879 GpeNumber));
882 * Disable the GPE. The GPE will remain disabled until the ACPICA
883 * Core Subsystem is restarted, or a handler is installed.
885 Status = AcpiEvDisableGpe (GpeEventInfo);
886 if (ACPI_FAILURE (Status))
888 ACPI_EXCEPTION ((AE_INFO, Status,
889 "Unable to disable GPE[%2X]", GpeNumber));
890 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
892 break;
895 return_UINT32 (ACPI_INTERRUPT_HANDLED);