1 /******************************************************************************
3 * Module Name: evgpe - General Purpose Event handling and dispatch
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2019, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
49 #define _COMPONENT ACPI_EVENTS
50 ACPI_MODULE_NAME ("evgpe")
52 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
54 /* Local prototypes */
56 static void ACPI_SYSTEM_XFACE
57 AcpiEvAsynchExecuteGpeMethod (
60 static void ACPI_SYSTEM_XFACE
61 AcpiEvAsynchEnableGpe (
65 /*******************************************************************************
67 * FUNCTION: AcpiEvUpdateGpeEnableMask
69 * PARAMETERS: GpeEventInfo - GPE to update
73 * DESCRIPTION: Updates GPE register enable mask based upon whether there are
74 * runtime references to this GPE
76 ******************************************************************************/
79 AcpiEvUpdateGpeEnableMask (
80 ACPI_GPE_EVENT_INFO
*GpeEventInfo
)
82 ACPI_GPE_REGISTER_INFO
*GpeRegisterInfo
;
86 ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMask
);
89 GpeRegisterInfo
= GpeEventInfo
->RegisterInfo
;
92 return_ACPI_STATUS (AE_NOT_EXIST
);
95 RegisterBit
= AcpiHwGetGpeRegisterBit (GpeEventInfo
);
97 /* Clear the run bit up front */
99 ACPI_CLEAR_BIT (GpeRegisterInfo
->EnableForRun
, RegisterBit
);
101 /* Set the mask bit only if there are references to this GPE */
103 if (GpeEventInfo
->RuntimeCount
)
105 ACPI_SET_BIT (GpeRegisterInfo
->EnableForRun
, (UINT8
) RegisterBit
);
108 GpeRegisterInfo
->EnableMask
= GpeRegisterInfo
->EnableForRun
;
109 return_ACPI_STATUS (AE_OK
);
113 /*******************************************************************************
115 * FUNCTION: AcpiEvEnableGpe
117 * PARAMETERS: GpeEventInfo - GPE to enable
121 * DESCRIPTION: Enable a GPE.
123 ******************************************************************************/
127 ACPI_GPE_EVENT_INFO
*GpeEventInfo
)
132 ACPI_FUNCTION_TRACE (EvEnableGpe
);
135 /* Enable the requested GPE */
137 Status
= AcpiHwLowSetGpe (GpeEventInfo
, ACPI_GPE_ENABLE
);
138 return_ACPI_STATUS (Status
);
142 /*******************************************************************************
144 * FUNCTION: AcpiEvMaskGpe
146 * PARAMETERS: GpeEventInfo - GPE to be blocked/unblocked
147 * IsMasked - Whether the GPE is masked or not
151 * DESCRIPTION: Unconditionally mask/unmask a GPE during runtime.
153 ******************************************************************************/
157 ACPI_GPE_EVENT_INFO
*GpeEventInfo
,
160 ACPI_GPE_REGISTER_INFO
*GpeRegisterInfo
;
164 ACPI_FUNCTION_TRACE (EvMaskGpe
);
167 GpeRegisterInfo
= GpeEventInfo
->RegisterInfo
;
168 if (!GpeRegisterInfo
)
170 return_ACPI_STATUS (AE_NOT_EXIST
);
173 RegisterBit
= AcpiHwGetGpeRegisterBit (GpeEventInfo
);
175 /* Perform the action */
179 if (RegisterBit
& GpeRegisterInfo
->MaskForRun
)
181 return_ACPI_STATUS (AE_BAD_PARAMETER
);
184 (void) AcpiHwLowSetGpe (GpeEventInfo
, ACPI_GPE_DISABLE
);
185 ACPI_SET_BIT (GpeRegisterInfo
->MaskForRun
, (UINT8
) RegisterBit
);
189 if (!(RegisterBit
& GpeRegisterInfo
->MaskForRun
))
191 return_ACPI_STATUS (AE_BAD_PARAMETER
);
194 ACPI_CLEAR_BIT (GpeRegisterInfo
->MaskForRun
, (UINT8
) RegisterBit
);
195 if (GpeEventInfo
->RuntimeCount
&&
196 !GpeEventInfo
->DisableForDispatch
)
198 (void) AcpiHwLowSetGpe (GpeEventInfo
, ACPI_GPE_ENABLE
);
202 return_ACPI_STATUS (AE_OK
);
206 /*******************************************************************************
208 * FUNCTION: AcpiEvAddGpeReference
210 * PARAMETERS: GpeEventInfo - Add a reference to this GPE
211 * ClearOnEnable - Clear GPE status before enabling it
215 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
218 ******************************************************************************/
221 AcpiEvAddGpeReference (
222 ACPI_GPE_EVENT_INFO
*GpeEventInfo
,
223 BOOLEAN ClearOnEnable
)
225 ACPI_STATUS Status
= AE_OK
;
228 ACPI_FUNCTION_TRACE (EvAddGpeReference
);
231 if (GpeEventInfo
->RuntimeCount
== ACPI_UINT8_MAX
)
233 return_ACPI_STATUS (AE_LIMIT
);
236 GpeEventInfo
->RuntimeCount
++;
237 if (GpeEventInfo
->RuntimeCount
== 1)
239 /* Enable on first reference */
243 (void) AcpiHwClearGpe (GpeEventInfo
);
246 Status
= AcpiEvUpdateGpeEnableMask (GpeEventInfo
);
247 if (ACPI_SUCCESS (Status
))
249 Status
= AcpiEvEnableGpe (GpeEventInfo
);
252 if (ACPI_FAILURE (Status
))
254 GpeEventInfo
->RuntimeCount
--;
258 return_ACPI_STATUS (Status
);
262 /*******************************************************************************
264 * FUNCTION: AcpiEvRemoveGpeReference
266 * PARAMETERS: GpeEventInfo - Remove a reference to this GPE
270 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
271 * removed, the GPE is hardware-disabled.
273 ******************************************************************************/
276 AcpiEvRemoveGpeReference (
277 ACPI_GPE_EVENT_INFO
*GpeEventInfo
)
279 ACPI_STATUS Status
= AE_OK
;
282 ACPI_FUNCTION_TRACE (EvRemoveGpeReference
);
285 if (!GpeEventInfo
->RuntimeCount
)
287 return_ACPI_STATUS (AE_LIMIT
);
290 GpeEventInfo
->RuntimeCount
--;
291 if (!GpeEventInfo
->RuntimeCount
)
293 /* Disable on last reference */
295 Status
= AcpiEvUpdateGpeEnableMask (GpeEventInfo
);
296 if (ACPI_SUCCESS (Status
))
298 Status
= AcpiHwLowSetGpe (GpeEventInfo
, ACPI_GPE_DISABLE
);
301 if (ACPI_FAILURE (Status
))
303 GpeEventInfo
->RuntimeCount
++;
307 return_ACPI_STATUS (Status
);
311 /*******************************************************************************
313 * FUNCTION: AcpiEvLowGetGpeInfo
315 * PARAMETERS: GpeNumber - Raw GPE number
316 * GpeBlock - A GPE info block
318 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE (The GpeNumber
319 * is not within the specified GPE block)
321 * DESCRIPTION: Returns the EventInfo struct associated with this GPE. This is
322 * the low-level implementation of EvGetGpeEventInfo.
324 ******************************************************************************/
326 ACPI_GPE_EVENT_INFO
*
327 AcpiEvLowGetGpeInfo (
329 ACPI_GPE_BLOCK_INFO
*GpeBlock
)
335 * Validate that the GpeNumber is within the specified GpeBlock.
339 (GpeNumber
< GpeBlock
->BlockBaseNumber
))
344 GpeIndex
= GpeNumber
- GpeBlock
->BlockBaseNumber
;
345 if (GpeIndex
>= GpeBlock
->GpeCount
)
350 return (&GpeBlock
->EventInfo
[GpeIndex
]);
354 /*******************************************************************************
356 * FUNCTION: AcpiEvGetGpeEventInfo
358 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
359 * GpeNumber - Raw GPE number
361 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE
363 * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
364 * Validates the GpeBlock and the GpeNumber
366 * Should be called only when the GPE lists are semaphore locked
367 * and not subject to change.
369 ******************************************************************************/
371 ACPI_GPE_EVENT_INFO
*
372 AcpiEvGetGpeEventInfo (
373 ACPI_HANDLE GpeDevice
,
376 ACPI_OPERAND_OBJECT
*ObjDesc
;
377 ACPI_GPE_EVENT_INFO
*GpeInfo
;
381 ACPI_FUNCTION_ENTRY ();
384 /* A NULL GpeDevice means use the FADT-defined GPE block(s) */
388 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
390 for (i
= 0; i
< ACPI_MAX_GPE_BLOCKS
; i
++)
392 GpeInfo
= AcpiEvLowGetGpeInfo (GpeNumber
,
393 AcpiGbl_GpeFadtBlocks
[i
]);
400 /* The GpeNumber was not in the range of either FADT GPE block */
405 /* A Non-NULL GpeDevice means this is a GPE Block Device */
407 ObjDesc
= AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE
*) GpeDevice
);
409 !ObjDesc
->Device
.GpeBlock
)
414 return (AcpiEvLowGetGpeInfo (GpeNumber
, ObjDesc
->Device
.GpeBlock
));
418 /*******************************************************************************
420 * FUNCTION: AcpiEvGpeDetect
422 * PARAMETERS: GpeXruptList - Interrupt block for this interrupt.
423 * Can have multiple GPE blocks attached.
425 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
427 * DESCRIPTION: Detect if any GP events have occurred. This function is
428 * executed at interrupt level.
430 ******************************************************************************/
434 ACPI_GPE_XRUPT_INFO
*GpeXruptList
)
436 ACPI_GPE_BLOCK_INFO
*GpeBlock
;
437 ACPI_NAMESPACE_NODE
*GpeDevice
;
438 ACPI_GPE_REGISTER_INFO
*GpeRegisterInfo
;
439 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
441 UINT32 IntStatus
= ACPI_INTERRUPT_NOT_HANDLED
;
442 ACPI_CPU_FLAGS Flags
;
447 ACPI_FUNCTION_NAME (EvGpeDetect
);
449 /* Check for the case where there are no GPEs */
457 * We need to obtain the GPE lock for both the data structs and registers
458 * Note: Not necessary to obtain the hardware lock, since the GPE
459 * registers are owned by the GpeLock.
461 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
463 /* Examine all GPE blocks attached to this interrupt level */
465 GpeBlock
= GpeXruptList
->GpeBlockListHead
;
468 GpeDevice
= GpeBlock
->Node
;
471 * Read all of the 8-bit GPE status and enable registers in this GPE
472 * block, saving all of them. Find all currently active GP events.
474 for (i
= 0; i
< GpeBlock
->RegisterCount
; i
++)
476 /* Get the next status/enable pair */
478 GpeRegisterInfo
= &GpeBlock
->RegisterInfo
[i
];
481 * Optimization: If there are no GPEs enabled within this
482 * register, we can safely ignore the entire register.
484 if (!(GpeRegisterInfo
->EnableForRun
|
485 GpeRegisterInfo
->EnableForWake
))
487 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS
,
488 "Ignore disabled registers for GPE %02X-%02X: "
489 "RunEnable=%02X, WakeEnable=%02X\n",
490 GpeRegisterInfo
->BaseGpeNumber
,
491 GpeRegisterInfo
->BaseGpeNumber
+ (ACPI_GPE_REGISTER_WIDTH
- 1),
492 GpeRegisterInfo
->EnableForRun
,
493 GpeRegisterInfo
->EnableForWake
));
497 /* Now look at the individual GPEs in this byte register */
499 for (j
= 0; j
< ACPI_GPE_REGISTER_WIDTH
; j
++)
501 /* Detect and dispatch one GPE bit */
503 GpeEventInfo
= &GpeBlock
->EventInfo
[((ACPI_SIZE
) i
*
504 ACPI_GPE_REGISTER_WIDTH
) + j
];
505 GpeNumber
= j
+ GpeRegisterInfo
->BaseGpeNumber
;
506 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
507 IntStatus
|= AcpiEvDetectGpe (
508 GpeDevice
, GpeEventInfo
, GpeNumber
);
509 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
513 GpeBlock
= GpeBlock
->Next
;
516 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
521 /*******************************************************************************
523 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
525 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
529 * DESCRIPTION: Perform the actual execution of a GPE control method. This
530 * function is called from an invocation of AcpiOsExecute and
531 * therefore does NOT execute at interrupt level - so that
532 * the control method itself is not executed in the context of
533 * an interrupt handler.
535 ******************************************************************************/
537 static void ACPI_SYSTEM_XFACE
538 AcpiEvAsynchExecuteGpeMethod (
541 ACPI_GPE_EVENT_INFO
*GpeEventInfo
= Context
;
542 ACPI_STATUS Status
= AE_OK
;
543 ACPI_EVALUATE_INFO
*Info
;
544 ACPI_GPE_NOTIFY_INFO
*Notify
;
547 ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod
);
550 /* Do the correct dispatch - normal method or implicit notify */
552 switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
))
554 case ACPI_GPE_DISPATCH_NOTIFY
:
557 * Dispatch a DEVICE_WAKE notify to the appropriate handler.
558 * NOTE: the request is queued for execution after this method
559 * completes. The notify handlers are NOT invoked synchronously
560 * from this thread -- because handlers may in turn run other
563 * June 2012: Expand implicit notify mechanism to support
564 * notifies on multiple device objects.
566 Notify
= GpeEventInfo
->Dispatch
.NotifyList
;
567 while (ACPI_SUCCESS (Status
) && Notify
)
569 Status
= AcpiEvQueueNotifyRequest (
570 Notify
->DeviceNode
, ACPI_NOTIFY_DEVICE_WAKE
);
572 Notify
= Notify
->Next
;
576 case ACPI_GPE_DISPATCH_METHOD
:
578 /* Allocate the evaluation information block */
580 Info
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO
));
583 Status
= AE_NO_MEMORY
;
588 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
589 * _Lxx/_Exx control method that corresponds to this GPE
591 Info
->PrefixNode
= GpeEventInfo
->Dispatch
.MethodNode
;
592 Info
->Flags
= ACPI_IGNORE_RETURN_VALUE
;
594 Status
= AcpiNsEvaluate (Info
);
598 if (ACPI_FAILURE (Status
))
600 ACPI_EXCEPTION ((AE_INFO
, Status
,
601 "while evaluating GPE method [%4.4s]",
602 AcpiUtGetNodeName (GpeEventInfo
->Dispatch
.MethodNode
)));
608 goto ErrorExit
; /* Should never happen */
611 /* Defer enabling of GPE until all notify handlers are done */
613 Status
= AcpiOsExecute (OSL_NOTIFY_HANDLER
,
614 AcpiEvAsynchEnableGpe
, GpeEventInfo
);
615 if (ACPI_SUCCESS (Status
))
621 AcpiEvAsynchEnableGpe (GpeEventInfo
);
626 /*******************************************************************************
628 * FUNCTION: AcpiEvAsynchEnableGpe
630 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
631 * Callback from AcpiOsExecute
635 * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
636 * complete (i.e., finish execution of Notify)
638 ******************************************************************************/
640 static void ACPI_SYSTEM_XFACE
641 AcpiEvAsynchEnableGpe (
644 ACPI_GPE_EVENT_INFO
*GpeEventInfo
= Context
;
645 ACPI_CPU_FLAGS Flags
;
648 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
649 (void) AcpiEvFinishGpe (GpeEventInfo
);
650 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
656 /*******************************************************************************
658 * FUNCTION: AcpiEvFinishGpe
660 * PARAMETERS: GpeEventInfo - Info for this GPE
664 * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
665 * of a GPE method or a synchronous or asynchronous GPE handler.
667 ******************************************************************************/
671 ACPI_GPE_EVENT_INFO
*GpeEventInfo
)
676 if ((GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
) ==
677 ACPI_GPE_LEVEL_TRIGGERED
)
680 * GPE is level-triggered, we clear the GPE status bit after
681 * handling the event.
683 Status
= AcpiHwClearGpe (GpeEventInfo
);
684 if (ACPI_FAILURE (Status
))
691 * Enable this GPE, conditionally. This means that the GPE will
692 * only be physically enabled if the EnableMask bit is set
695 (void) AcpiHwLowSetGpe (GpeEventInfo
, ACPI_GPE_CONDITIONAL_ENABLE
);
696 GpeEventInfo
->DisableForDispatch
= FALSE
;
701 /*******************************************************************************
703 * FUNCTION: AcpiEvDetectGpe
705 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
706 * GpeEventInfo - Info for this GPE
707 * GpeNumber - Number relative to the parent GPE block
709 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
711 * DESCRIPTION: Detect and dispatch a General Purpose Event to either a function
712 * (e.g. EC) or method (e.g. _Lxx/_Exx) handler.
713 * NOTE: GPE is W1C, so it is possible to handle a single GPE from both
714 * task and irq context in parallel as long as the process to
715 * detect and mask the GPE is atomic.
716 * However the atomicity of ACPI_GPE_DISPATCH_RAW_HANDLER is
717 * dependent on the raw handler itself.
719 ******************************************************************************/
723 ACPI_NAMESPACE_NODE
*GpeDevice
,
724 ACPI_GPE_EVENT_INFO
*GpeEventInfo
,
727 UINT32 IntStatus
= ACPI_INTERRUPT_NOT_HANDLED
;
728 UINT8 EnabledStatusByte
;
732 ACPI_GPE_REGISTER_INFO
*GpeRegisterInfo
;
733 ACPI_GPE_HANDLER_INFO
*GpeHandlerInfo
;
734 ACPI_CPU_FLAGS Flags
;
738 ACPI_FUNCTION_TRACE (EvGpeDetect
);
741 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
745 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
752 /* Get the info block for the entire GPE register */
754 GpeRegisterInfo
= GpeEventInfo
->RegisterInfo
;
756 /* Get the register bitmask for this GPE */
758 RegisterBit
= AcpiHwGetGpeRegisterBit (GpeEventInfo
);
760 /* GPE currently enabled (enable bit == 1)? */
762 Status
= AcpiHwRead (&EnableReg
, &GpeRegisterInfo
->EnableAddress
);
763 if (ACPI_FAILURE (Status
))
768 /* GPE currently active (status bit == 1)? */
770 Status
= AcpiHwRead (&StatusReg
, &GpeRegisterInfo
->StatusAddress
);
771 if (ACPI_FAILURE (Status
))
776 /* Check if there is anything active at all in this GPE */
778 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS
,
779 "Read registers for GPE %02X: Status=%02X, Enable=%02X, "
780 "RunEnable=%02X, WakeEnable=%02X\n",
782 (UINT32
) (StatusReg
& RegisterBit
),
783 (UINT32
) (EnableReg
& RegisterBit
),
784 GpeRegisterInfo
->EnableForRun
,
785 GpeRegisterInfo
->EnableForWake
));
787 EnabledStatusByte
= (UINT8
) (StatusReg
& EnableReg
);
788 if (!(EnabledStatusByte
& RegisterBit
))
793 /* Invoke global event handler if present */
796 if (AcpiGbl_GlobalEventHandler
)
798 AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_GPE
,
799 GpeDevice
, GpeNumber
,
800 AcpiGbl_GlobalEventHandlerContext
);
803 /* Found an active GPE */
805 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
) ==
806 ACPI_GPE_DISPATCH_RAW_HANDLER
)
808 /* Dispatch the event to a raw handler */
810 GpeHandlerInfo
= GpeEventInfo
->Dispatch
.Handler
;
813 * There is no protection around the namespace node
814 * and the GPE handler to ensure a safe destruction
816 * 1. The namespace node is expected to always
817 * exist after loading a table.
818 * 2. The GPE handler is expected to be flushed by
819 * AcpiOsWaitEventsComplete() before the
822 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
823 IntStatus
|= GpeHandlerInfo
->Address (
824 GpeDevice
, GpeNumber
, GpeHandlerInfo
->Context
);
825 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
829 /* Dispatch the event to a standard handler or method. */
831 IntStatus
|= AcpiEvGpeDispatch (GpeDevice
,
832 GpeEventInfo
, GpeNumber
);
836 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
841 /*******************************************************************************
843 * FUNCTION: AcpiEvGpeDispatch
845 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
846 * GpeEventInfo - Info for this GPE
847 * GpeNumber - Number relative to the parent GPE block
849 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
851 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
852 * or method (e.g. _Lxx/_Exx) handler.
854 ******************************************************************************/
858 ACPI_NAMESPACE_NODE
*GpeDevice
,
859 ACPI_GPE_EVENT_INFO
*GpeEventInfo
,
866 ACPI_FUNCTION_TRACE (EvGpeDispatch
);
870 * Always disable the GPE so that it does not keep firing before
871 * any asynchronous activity completes (either from the execution
872 * of a GPE method or an asynchronous GPE handler.)
874 * If there is no handler or method to run, just disable the
875 * GPE and leave it disabled permanently to prevent further such
876 * pointless events from firing.
878 Status
= AcpiHwLowSetGpe (GpeEventInfo
, ACPI_GPE_DISABLE
);
879 if (ACPI_FAILURE (Status
))
881 ACPI_EXCEPTION ((AE_INFO
, Status
,
882 "Unable to disable GPE %02X", GpeNumber
));
883 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED
);
887 * If edge-triggered, clear the GPE status bit now. Note that
888 * level-triggered events are cleared after the GPE is serviced.
890 if ((GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
) ==
891 ACPI_GPE_EDGE_TRIGGERED
)
893 Status
= AcpiHwClearGpe (GpeEventInfo
);
894 if (ACPI_FAILURE (Status
))
896 ACPI_EXCEPTION ((AE_INFO
, Status
,
897 "Unable to clear GPE %02X", GpeNumber
));
898 (void) AcpiHwLowSetGpe (
899 GpeEventInfo
, ACPI_GPE_CONDITIONAL_ENABLE
);
900 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED
);
904 GpeEventInfo
->DisableForDispatch
= TRUE
;
907 * Dispatch the GPE to either an installed handler or the control
908 * method associated with this GPE (_Lxx or _Exx). If a handler
909 * exists, we invoke it and do not attempt to run the method.
910 * If there is neither a handler nor a method, leave the GPE
913 switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
))
915 case ACPI_GPE_DISPATCH_HANDLER
:
917 /* Invoke the installed handler (at interrupt level) */
919 ReturnValue
= GpeEventInfo
->Dispatch
.Handler
->Address (
920 GpeDevice
, GpeNumber
,
921 GpeEventInfo
->Dispatch
.Handler
->Context
);
923 /* If requested, clear (if level-triggered) and re-enable the GPE */
925 if (ReturnValue
& ACPI_REENABLE_GPE
)
927 (void) AcpiEvFinishGpe (GpeEventInfo
);
931 case ACPI_GPE_DISPATCH_METHOD
:
932 case ACPI_GPE_DISPATCH_NOTIFY
:
934 * Execute the method associated with the GPE
935 * NOTE: Level-triggered GPEs are cleared after the method completes.
937 Status
= AcpiOsExecute (OSL_GPE_HANDLER
,
938 AcpiEvAsynchExecuteGpeMethod
, GpeEventInfo
);
939 if (ACPI_FAILURE (Status
))
941 ACPI_EXCEPTION ((AE_INFO
, Status
,
942 "Unable to queue handler for GPE %02X - event disabled",
949 * No handler or method to run!
950 * 03/2010: This case should no longer be possible. We will not allow
951 * a GPE to be enabled if it has no handler or method.
953 ACPI_ERROR ((AE_INFO
,
954 "No handler or method for GPE %02X, disabling event",
959 return_UINT32 (ACPI_INTERRUPT_HANDLED
);
962 #endif /* !ACPI_REDUCED_HARDWARE */