1 /******************************************************************************
3 * Module Name: evgpe - General Purpose Event handling and dispatch
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2021, Intel Corp.
12 * All rights reserved.
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
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
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
153 #include "accommon.h"
154 #include "acevents.h"
155 #include "acnamesp.h"
157 #define _COMPONENT ACPI_EVENTS
158 ACPI_MODULE_NAME ("evgpe")
160 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
162 /* Local prototypes */
164 static void ACPI_SYSTEM_XFACE
165 AcpiEvAsynchExecuteGpeMethod (
168 static void ACPI_SYSTEM_XFACE
169 AcpiEvAsynchEnableGpe (
173 /*******************************************************************************
175 * FUNCTION: AcpiEvUpdateGpeEnableMask
177 * PARAMETERS: GpeEventInfo - GPE to update
181 * DESCRIPTION: Updates GPE register enable mask based upon whether there are
182 * runtime references to this GPE
184 ******************************************************************************/
187 AcpiEvUpdateGpeEnableMask (
188 ACPI_GPE_EVENT_INFO *GpeEventInfo)
190 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
194 ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMask);
197 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
198 if (!GpeRegisterInfo)
200 return_ACPI_STATUS (AE_NOT_EXIST);
203 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
205 /* Clear the run bit up front */
207 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
209 /* Set the mask bit only if there are references to this GPE */
211 if (GpeEventInfo->RuntimeCount)
213 ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, (UINT8) RegisterBit);
216 GpeRegisterInfo->EnableMask = GpeRegisterInfo->EnableForRun;
217 return_ACPI_STATUS (AE_OK);
221 /*******************************************************************************
223 * FUNCTION: AcpiEvEnableGpe
225 * PARAMETERS: GpeEventInfo - GPE to enable
229 * DESCRIPTION: Enable a GPE.
231 ******************************************************************************/
235 ACPI_GPE_EVENT_INFO *GpeEventInfo)
240 ACPI_FUNCTION_TRACE (EvEnableGpe);
243 /* Enable the requested GPE */
245 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
246 return_ACPI_STATUS (Status);
250 /*******************************************************************************
252 * FUNCTION: AcpiEvMaskGpe
254 * PARAMETERS: GpeEventInfo - GPE to be blocked/unblocked
255 * IsMasked - Whether the GPE is masked or not
259 * DESCRIPTION: Unconditionally mask/unmask a GPE during runtime.
261 ******************************************************************************/
265 ACPI_GPE_EVENT_INFO *GpeEventInfo,
268 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
272 ACPI_FUNCTION_TRACE (EvMaskGpe);
275 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
276 if (!GpeRegisterInfo)
278 return_ACPI_STATUS (AE_NOT_EXIST);
281 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
283 /* Perform the action */
287 if (RegisterBit & GpeRegisterInfo->MaskForRun)
289 return_ACPI_STATUS (AE_BAD_PARAMETER);
292 (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
293 ACPI_SET_BIT (GpeRegisterInfo->MaskForRun, (UINT8) RegisterBit);
297 if (!(RegisterBit & GpeRegisterInfo->MaskForRun))
299 return_ACPI_STATUS (AE_BAD_PARAMETER);
302 ACPI_CLEAR_BIT (GpeRegisterInfo->MaskForRun, (UINT8) RegisterBit);
303 if (GpeEventInfo->RuntimeCount &&
304 !GpeEventInfo->DisableForDispatch)
306 (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
310 return_ACPI_STATUS (AE_OK);
314 /*******************************************************************************
316 * FUNCTION: AcpiEvAddGpeReference
318 * PARAMETERS: GpeEventInfo - Add a reference to this GPE
319 * ClearOnEnable - Clear GPE status before enabling it
323 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
326 ******************************************************************************/
329 AcpiEvAddGpeReference (
330 ACPI_GPE_EVENT_INFO *GpeEventInfo,
331 BOOLEAN ClearOnEnable)
333 ACPI_STATUS Status = AE_OK;
336 ACPI_FUNCTION_TRACE (EvAddGpeReference);
339 if (GpeEventInfo->RuntimeCount == ACPI_UINT8_MAX)
341 return_ACPI_STATUS (AE_LIMIT);
344 GpeEventInfo->RuntimeCount++;
345 if (GpeEventInfo->RuntimeCount == 1)
347 /* Enable on first reference */
351 (void) AcpiHwClearGpe (GpeEventInfo);
354 Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
355 if (ACPI_SUCCESS (Status))
357 Status = AcpiEvEnableGpe (GpeEventInfo);
360 if (ACPI_FAILURE (Status))
362 GpeEventInfo->RuntimeCount--;
366 return_ACPI_STATUS (Status);
370 /*******************************************************************************
372 * FUNCTION: AcpiEvRemoveGpeReference
374 * PARAMETERS: GpeEventInfo - Remove a reference to this GPE
378 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
379 * removed, the GPE is hardware-disabled.
381 ******************************************************************************/
384 AcpiEvRemoveGpeReference (
385 ACPI_GPE_EVENT_INFO *GpeEventInfo)
387 ACPI_STATUS Status = AE_OK;
390 ACPI_FUNCTION_TRACE (EvRemoveGpeReference);
393 if (!GpeEventInfo->RuntimeCount)
395 return_ACPI_STATUS (AE_LIMIT);
398 GpeEventInfo->RuntimeCount--;
399 if (!GpeEventInfo->RuntimeCount)
401 /* Disable on last reference */
403 Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
404 if (ACPI_SUCCESS (Status))
406 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
409 if (ACPI_FAILURE (Status))
411 GpeEventInfo->RuntimeCount++;
415 return_ACPI_STATUS (Status);
419 /*******************************************************************************
421 * FUNCTION: AcpiEvLowGetGpeInfo
423 * PARAMETERS: GpeNumber - Raw GPE number
424 * GpeBlock - A GPE info block
426 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE (The GpeNumber
427 * is not within the specified GPE block)
429 * DESCRIPTION: Returns the EventInfo struct associated with this GPE. This is
430 * the low-level implementation of EvGetGpeEventInfo.
432 ******************************************************************************/
434 ACPI_GPE_EVENT_INFO *
435 AcpiEvLowGetGpeInfo (
437 ACPI_GPE_BLOCK_INFO *GpeBlock)
443 * Validate that the GpeNumber is within the specified GpeBlock.
447 (GpeNumber < GpeBlock->BlockBaseNumber))
452 GpeIndex = GpeNumber - GpeBlock->BlockBaseNumber;
453 if (GpeIndex >= GpeBlock->GpeCount)
458 return (&GpeBlock->EventInfo[GpeIndex]);
462 /*******************************************************************************
464 * FUNCTION: AcpiEvGetGpeEventInfo
466 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
467 * GpeNumber - Raw GPE number
469 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE
471 * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
472 * Validates the GpeBlock and the GpeNumber
474 * Should be called only when the GPE lists are semaphore locked
475 * and not subject to change.
477 ******************************************************************************/
479 ACPI_GPE_EVENT_INFO *
480 AcpiEvGetGpeEventInfo (
481 ACPI_HANDLE GpeDevice,
484 ACPI_OPERAND_OBJECT *ObjDesc;
485 ACPI_GPE_EVENT_INFO *GpeInfo;
489 ACPI_FUNCTION_ENTRY ();
492 /* A NULL GpeDevice means use the FADT-defined GPE block(s) */
496 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
498 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
500 GpeInfo = AcpiEvLowGetGpeInfo (GpeNumber,
501 AcpiGbl_GpeFadtBlocks[i]);
508 /* The GpeNumber was not in the range of either FADT GPE block */
513 /* A Non-NULL GpeDevice means this is a GPE Block Device */
515 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
517 !ObjDesc->Device.GpeBlock)
522 return (AcpiEvLowGetGpeInfo (GpeNumber, ObjDesc->Device.GpeBlock));
526 /*******************************************************************************
528 * FUNCTION: AcpiEvGpeDetect
530 * PARAMETERS: GpeXruptList - Interrupt block for this interrupt.
531 * Can have multiple GPE blocks attached.
533 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
535 * DESCRIPTION: Detect if any GP events have occurred. This function is
536 * executed at interrupt level.
538 ******************************************************************************/
542 ACPI_GPE_XRUPT_INFO *GpeXruptList)
544 ACPI_GPE_BLOCK_INFO *GpeBlock;
545 ACPI_NAMESPACE_NODE *GpeDevice;
546 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
547 ACPI_GPE_EVENT_INFO *GpeEventInfo;
549 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
550 ACPI_CPU_FLAGS Flags;
555 ACPI_FUNCTION_NAME (EvGpeDetect);
557 /* Check for the case where there are no GPEs */
565 * We need to obtain the GPE lock for both the data structs and registers
566 * Note: Not necessary to obtain the hardware lock, since the GPE
567 * registers are owned by the GpeLock.
569 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
571 /* Examine all GPE blocks attached to this interrupt level */
573 GpeBlock = GpeXruptList->GpeBlockListHead;
576 GpeDevice = GpeBlock->Node;
579 * Read all of the 8-bit GPE status and enable registers in this GPE
580 * block, saving all of them. Find all currently active GP events.
582 for (i = 0; i < GpeBlock->RegisterCount; i++)
584 /* Get the next status/enable pair */
586 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
589 * Optimization: If there are no GPEs enabled within this
590 * register, we can safely ignore the entire register.
592 if (!(GpeRegisterInfo->EnableForRun |
593 GpeRegisterInfo->EnableForWake))
595 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
596 "Ignore disabled registers for GPE %02X-%02X: "
597 "RunEnable=%02X, WakeEnable=%02X\n",
598 GpeRegisterInfo->BaseGpeNumber,
599 GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),
600 GpeRegisterInfo->EnableForRun,
601 GpeRegisterInfo->EnableForWake));
605 /* Now look at the individual GPEs in this byte register */
607 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
609 /* Detect and dispatch one GPE bit */
611 GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
612 ACPI_GPE_REGISTER_WIDTH) + j];
613 GpeNumber = j + GpeRegisterInfo->BaseGpeNumber;
614 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
615 IntStatus |= AcpiEvDetectGpe (
616 GpeDevice, GpeEventInfo, GpeNumber);
617 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
621 GpeBlock = GpeBlock->Next;
624 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
629 /*******************************************************************************
631 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
633 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
637 * DESCRIPTION: Perform the actual execution of a GPE control method. This
638 * function is called from an invocation of AcpiOsExecute and
639 * therefore does NOT execute at interrupt level - so that
640 * the control method itself is not executed in the context of
641 * an interrupt handler.
643 ******************************************************************************/
645 static void ACPI_SYSTEM_XFACE
646 AcpiEvAsynchExecuteGpeMethod (
649 ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;
650 ACPI_STATUS Status = AE_OK;
651 ACPI_EVALUATE_INFO *Info;
652 ACPI_GPE_NOTIFY_INFO *Notify;
655 ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod);
658 /* Do the correct dispatch - normal method or implicit notify */
660 switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
662 case ACPI_GPE_DISPATCH_NOTIFY:
665 * Dispatch a DEVICE_WAKE notify to the appropriate handler.
666 * NOTE: the request is queued for execution after this method
667 * completes. The notify handlers are NOT invoked synchronously
668 * from this thread -- because handlers may in turn run other
671 * June 2012: Expand implicit notify mechanism to support
672 * notifies on multiple device objects.
674 Notify = GpeEventInfo->Dispatch.NotifyList;
675 while (ACPI_SUCCESS (Status) && Notify)
677 Status = AcpiEvQueueNotifyRequest (
678 Notify->DeviceNode, ACPI_NOTIFY_DEVICE_WAKE);
680 Notify = Notify->Next;
684 case ACPI_GPE_DISPATCH_METHOD:
686 /* Allocate the evaluation information block */
688 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
691 Status = AE_NO_MEMORY;
696 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
697 * _Lxx/_Exx control method that corresponds to this GPE
699 Info->PrefixNode = GpeEventInfo->Dispatch.MethodNode;
700 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
702 Status = AcpiNsEvaluate (Info);
706 if (ACPI_FAILURE (Status))
708 ACPI_EXCEPTION ((AE_INFO, Status,
709 "while evaluating GPE method [%4.4s]",
710 AcpiUtGetNodeName (GpeEventInfo->Dispatch.MethodNode)));
716 goto ErrorExit; /* Should never happen */
719 /* Defer enabling of GPE until all notify handlers are done */
721 Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
722 AcpiEvAsynchEnableGpe, GpeEventInfo);
723 if (ACPI_SUCCESS (Status))
729 AcpiEvAsynchEnableGpe (GpeEventInfo);
734 /*******************************************************************************
736 * FUNCTION: AcpiEvAsynchEnableGpe
738 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
739 * Callback from AcpiOsExecute
743 * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
744 * complete (i.e., finish execution of Notify)
746 ******************************************************************************/
748 static void ACPI_SYSTEM_XFACE
749 AcpiEvAsynchEnableGpe (
752 ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;
753 ACPI_CPU_FLAGS Flags;
756 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
757 (void) AcpiEvFinishGpe (GpeEventInfo);
758 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
764 /*******************************************************************************
766 * FUNCTION: AcpiEvFinishGpe
768 * PARAMETERS: GpeEventInfo - Info for this GPE
772 * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
773 * of a GPE method or a synchronous or asynchronous GPE handler.
775 ******************************************************************************/
779 ACPI_GPE_EVENT_INFO *GpeEventInfo)
784 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
785 ACPI_GPE_LEVEL_TRIGGERED)
788 * GPE is level-triggered, we clear the GPE status bit after
789 * handling the event.
791 Status = AcpiHwClearGpe (GpeEventInfo);
792 if (ACPI_FAILURE (Status))
799 * Enable this GPE, conditionally. This means that the GPE will
800 * only be physically enabled if the EnableMask bit is set
803 (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
804 GpeEventInfo->DisableForDispatch = FALSE;
809 /*******************************************************************************
811 * FUNCTION: AcpiEvDetectGpe
813 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
814 * GpeEventInfo - Info for this GPE
815 * GpeNumber - Number relative to the parent GPE block
817 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
819 * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
820 * (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
821 * NOTE: GPE is W1C, so it is possible to handle a single GPE from both
822 * task and irq context in parallel as long as the process to
823 * detect and mask the GPE is atomic.
824 * However the atomicity of ACPI_GPE_DISPATCH_RAW_HANDLER is
825 * dependent on the raw handler itself.
827 ******************************************************************************/
831 ACPI_NAMESPACE_NODE *GpeDevice,
832 ACPI_GPE_EVENT_INFO *GpeEventInfo,
835 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
836 UINT8 EnabledStatusByte;
840 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
841 ACPI_GPE_HANDLER_INFO *GpeHandlerInfo;
842 ACPI_CPU_FLAGS Flags;
846 ACPI_FUNCTION_TRACE (EvGpeDetect);
849 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
853 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
860 /* Get the info block for the entire GPE register */
862 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
864 /* Get the register bitmask for this GPE */
866 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
868 /* GPE currently enabled (enable bit == 1)? */
870 Status = AcpiHwRead (&EnableReg, &GpeRegisterInfo->EnableAddress);
871 if (ACPI_FAILURE (Status))
876 /* GPE currently active (status bit == 1)? */
878 Status = AcpiHwRead (&StatusReg, &GpeRegisterInfo->StatusAddress);
879 if (ACPI_FAILURE (Status))
884 /* Check if there is anything active at all in this GPE */
886 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
887 "Read registers for GPE %02X: Status=%02X, Enable=%02X, "
888 "RunEnable=%02X, WakeEnable=%02X\n",
890 (UINT32) (StatusReg & RegisterBit),
891 (UINT32) (EnableReg & RegisterBit),
892 GpeRegisterInfo->EnableForRun,
893 GpeRegisterInfo->EnableForWake));
895 EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
896 if (!(EnabledStatusByte & RegisterBit))
901 /* Invoke global event handler if present */
904 if (AcpiGbl_GlobalEventHandler)
906 AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_GPE,
907 GpeDevice, GpeNumber,
908 AcpiGbl_GlobalEventHandlerContext);
911 /* Found an active GPE */
913 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
914 ACPI_GPE_DISPATCH_RAW_HANDLER)
916 /* Dispatch the event to a raw handler */
918 GpeHandlerInfo = GpeEventInfo->Dispatch.Handler;
921 * There is no protection around the namespace node
922 * and the GPE handler to ensure a safe destruction
924 * 1. The namespace node is expected to always
925 * exist after loading a table.
926 * 2. The GPE handler is expected to be flushed by
927 * AcpiOsWaitEventsComplete() before the
930 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
931 IntStatus |= GpeHandlerInfo->Address (
932 GpeDevice, GpeNumber, GpeHandlerInfo->Context);
933 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
937 /* Dispatch the event to a standard handler or method. */
939 IntStatus |= AcpiEvGpeDispatch (GpeDevice,
940 GpeEventInfo, GpeNumber);
944 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
949 /*******************************************************************************
951 * FUNCTION: AcpiEvGpeDispatch
953 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
954 * GpeEventInfo - Info for this GPE
955 * GpeNumber - Number relative to the parent GPE block
957 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
959 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
960 * or method (e.g. _Lxx/_Exx) handler.
962 ******************************************************************************/
966 ACPI_NAMESPACE_NODE *GpeDevice,
967 ACPI_GPE_EVENT_INFO *GpeEventInfo,
974 ACPI_FUNCTION_TRACE (EvGpeDispatch);
978 * Always disable the GPE so that it does not keep firing before
979 * any asynchronous activity completes (either from the execution
980 * of a GPE method or an asynchronous GPE handler.)
982 * If there is no handler or method to run, just disable the
983 * GPE and leave it disabled permanently to prevent further such
984 * pointless events from firing.
986 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
987 if (ACPI_FAILURE (Status))
989 ACPI_EXCEPTION ((AE_INFO, Status,
990 "Unable to disable GPE %02X", GpeNumber));
991 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
995 * If edge-triggered, clear the GPE status bit now. Note that
996 * level-triggered events are cleared after the GPE is serviced.
998 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
999 ACPI_GPE_EDGE_TRIGGERED)
1001 Status = AcpiHwClearGpe (GpeEventInfo);
1002 if (ACPI_FAILURE (Status))
1004 ACPI_EXCEPTION ((AE_INFO, Status,
1005 "Unable to clear GPE %02X", GpeNumber));
1006 (void) AcpiHwLowSetGpe (
1007 GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
1008 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
1012 GpeEventInfo->DisableForDispatch = TRUE;
1015 * Dispatch the GPE to either an installed handler or the control
1016 * method associated with this GPE (_Lxx or _Exx). If a handler
1017 * exists, we invoke it and do not attempt to run the method.
1018 * If there is neither a handler nor a method, leave the GPE
1021 switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
1023 case ACPI_GPE_DISPATCH_HANDLER:
1025 /* Invoke the installed handler (at interrupt level) */
1027 ReturnValue = GpeEventInfo->Dispatch.Handler->Address (
1028 GpeDevice, GpeNumber,
1029 GpeEventInfo->Dispatch.Handler->Context);
1031 /* If requested, clear (if level-triggered) and re-enable the GPE */
1033 if (ReturnValue & ACPI_REENABLE_GPE)
1035 (void) AcpiEvFinishGpe (GpeEventInfo);
1039 case ACPI_GPE_DISPATCH_METHOD:
1040 case ACPI_GPE_DISPATCH_NOTIFY:
1042 * Execute the method associated with the GPE
1043 * NOTE: Level-triggered GPEs are cleared after the method completes.
1045 Status = AcpiOsExecute (OSL_GPE_HANDLER,
1046 AcpiEvAsynchExecuteGpeMethod, GpeEventInfo);
1047 if (ACPI_FAILURE (Status))
1049 ACPI_EXCEPTION ((AE_INFO, Status,
1050 "Unable to queue handler for GPE %02X - event disabled",
1057 * No handler or method to run!
1058 * 03/2010: This case should no longer be possible. We will not allow
1059 * a GPE to be enabled if it has no handler or method.
1061 ACPI_ERROR ((AE_INFO,
1062 "No handler or method for GPE %02X, disabling event",
1067 return_UINT32 (ACPI_INTERRUPT_HANDLED);
1070 #endif /* !ACPI_REDUCED_HARDWARE */