[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / events / evgpe.c
1 /******************************************************************************
2 *
3 * Module Name: evgpe - General Purpose Event handling and dispatch
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
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.
20 *
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
27 *
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;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
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.
53 *
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.
65 *
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.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
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.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
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.
89 *
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.
98 *
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.
113 *
114 *****************************************************************************/
115
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "acevents.h"
119 #include "acnamesp.h"
120
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpe")
123
124 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
125
126 /* Local prototypes */
127
128 static void ACPI_SYSTEM_XFACE
129 AcpiEvAsynchExecuteGpeMethod (
130 void *Context);
131
132 static void ACPI_SYSTEM_XFACE
133 AcpiEvAsynchEnableGpe (
134 void *Context);
135
136
137 /*******************************************************************************
138 *
139 * FUNCTION: AcpiEvUpdateGpeEnableMask
140 *
141 * PARAMETERS: GpeEventInfo - GPE to update
142 *
143 * RETURN: Status
144 *
145 * DESCRIPTION: Updates GPE register enable mask based upon whether there are
146 * runtime references to this GPE
147 *
148 ******************************************************************************/
149
150 ACPI_STATUS
151 AcpiEvUpdateGpeEnableMask (
152 ACPI_GPE_EVENT_INFO *GpeEventInfo)
153 {
154 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
155 UINT32 RegisterBit;
156
157
158 ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMask);
159
160
161 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
162 if (!GpeRegisterInfo)
163 {
164 return_ACPI_STATUS (AE_NOT_EXIST);
165 }
166
167 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
168
169 /* Clear the run bit up front */
170
171 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);
172
173 /* Set the mask bit only if there are references to this GPE */
174
175 if (GpeEventInfo->RuntimeCount)
176 {
177 ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, (UINT8) RegisterBit);
178 }
179
180 return_ACPI_STATUS (AE_OK);
181 }
182
183
184 /*******************************************************************************
185 *
186 * FUNCTION: AcpiEvEnableGpe
187 *
188 * PARAMETERS: GpeEventInfo - GPE to enable
189 *
190 * RETURN: Status
191 *
192 * DESCRIPTION: Clear a GPE of stale events and enable it.
193 *
194 ******************************************************************************/
195
196 ACPI_STATUS
197 AcpiEvEnableGpe (
198 ACPI_GPE_EVENT_INFO *GpeEventInfo)
199 {
200 ACPI_STATUS Status;
201
202
203 ACPI_FUNCTION_TRACE (EvEnableGpe);
204
205
206 /* Clear the GPE (of stale events) */
207
208 Status = AcpiHwClearGpe (GpeEventInfo);
209 if (ACPI_FAILURE (Status))
210 {
211 return_ACPI_STATUS (Status);
212 }
213
214 /* Enable the requested GPE */
215
216 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE_SAVE);
217 return_ACPI_STATUS (Status);
218 }
219
220
221 /*******************************************************************************
222 *
223 * FUNCTION: AcpiEvAddGpeReference
224 *
225 * PARAMETERS: GpeEventInfo - Add a reference to this GPE
226 *
227 * RETURN: Status
228 *
229 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
230 * hardware-enabled.
231 *
232 ******************************************************************************/
233
234 ACPI_STATUS
235 AcpiEvAddGpeReference (
236 ACPI_GPE_EVENT_INFO *GpeEventInfo)
237 {
238 ACPI_STATUS Status = AE_OK;
239
240
241 ACPI_FUNCTION_TRACE (EvAddGpeReference);
242
243
244 if (GpeEventInfo->RuntimeCount == ACPI_UINT8_MAX)
245 {
246 return_ACPI_STATUS (AE_LIMIT);
247 }
248
249 GpeEventInfo->RuntimeCount++;
250 if (GpeEventInfo->RuntimeCount == 1)
251 {
252 /* Enable on first reference */
253
254 Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
255 if (ACPI_SUCCESS (Status))
256 {
257 Status = AcpiEvEnableGpe (GpeEventInfo);
258 }
259
260 if (ACPI_FAILURE (Status))
261 {
262 GpeEventInfo->RuntimeCount--;
263 }
264 }
265
266 return_ACPI_STATUS (Status);
267 }
268
269
270 /*******************************************************************************
271 *
272 * FUNCTION: AcpiEvRemoveGpeReference
273 *
274 * PARAMETERS: GpeEventInfo - Remove a reference to this GPE
275 *
276 * RETURN: Status
277 *
278 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
279 * removed, the GPE is hardware-disabled.
280 *
281 ******************************************************************************/
282
283 ACPI_STATUS
284 AcpiEvRemoveGpeReference (
285 ACPI_GPE_EVENT_INFO *GpeEventInfo)
286 {
287 ACPI_STATUS Status = AE_OK;
288
289
290 ACPI_FUNCTION_TRACE (EvRemoveGpeReference);
291
292
293 if (!GpeEventInfo->RuntimeCount)
294 {
295 return_ACPI_STATUS (AE_LIMIT);
296 }
297
298 GpeEventInfo->RuntimeCount--;
299 if (!GpeEventInfo->RuntimeCount)
300 {
301 /* Disable on last reference */
302
303 Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);
304 if (ACPI_SUCCESS (Status))
305 {
306 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE_SAVE);
307 }
308
309 if (ACPI_FAILURE (Status))
310 {
311 GpeEventInfo->RuntimeCount++;
312 }
313 }
314
315 return_ACPI_STATUS (Status);
316 }
317
318
319 /*******************************************************************************
320 *
321 * FUNCTION: AcpiEvLowGetGpeInfo
322 *
323 * PARAMETERS: GpeNumber - Raw GPE number
324 * GpeBlock - A GPE info block
325 *
326 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE (The GpeNumber
327 * is not within the specified GPE block)
328 *
329 * DESCRIPTION: Returns the EventInfo struct associated with this GPE. This is
330 * the low-level implementation of EvGetGpeEventInfo.
331 *
332 ******************************************************************************/
333
334 ACPI_GPE_EVENT_INFO *
335 AcpiEvLowGetGpeInfo (
336 UINT32 GpeNumber,
337 ACPI_GPE_BLOCK_INFO *GpeBlock)
338 {
339 UINT32 GpeIndex;
340
341
342 /*
343 * Validate that the GpeNumber is within the specified GpeBlock.
344 * (Two steps)
345 */
346 if (!GpeBlock ||
347 (GpeNumber < GpeBlock->BlockBaseNumber))
348 {
349 return (NULL);
350 }
351
352 GpeIndex = GpeNumber - GpeBlock->BlockBaseNumber;
353 if (GpeIndex >= GpeBlock->GpeCount)
354 {
355 return (NULL);
356 }
357
358 return (&GpeBlock->EventInfo[GpeIndex]);
359 }
360
361
362 /*******************************************************************************
363 *
364 * FUNCTION: AcpiEvGetGpeEventInfo
365 *
366 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
367 * GpeNumber - Raw GPE number
368 *
369 * RETURN: A GPE EventInfo struct. NULL if not a valid GPE
370 *
371 * DESCRIPTION: Returns the EventInfo struct associated with this GPE.
372 * Validates the GpeBlock and the GpeNumber
373 *
374 * Should be called only when the GPE lists are semaphore locked
375 * and not subject to change.
376 *
377 ******************************************************************************/
378
379 ACPI_GPE_EVENT_INFO *
380 AcpiEvGetGpeEventInfo (
381 ACPI_HANDLE GpeDevice,
382 UINT32 GpeNumber)
383 {
384 ACPI_OPERAND_OBJECT *ObjDesc;
385 ACPI_GPE_EVENT_INFO *GpeInfo;
386 UINT32 i;
387
388
389 ACPI_FUNCTION_ENTRY ();
390
391
392 /* A NULL GpeDevice means use the FADT-defined GPE block(s) */
393
394 if (!GpeDevice)
395 {
396 /* Examine GPE Block 0 and 1 (These blocks are permanent) */
397
398 for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)
399 {
400 GpeInfo = AcpiEvLowGetGpeInfo (GpeNumber,
401 AcpiGbl_GpeFadtBlocks[i]);
402 if (GpeInfo)
403 {
404 return (GpeInfo);
405 }
406 }
407
408 /* The GpeNumber was not in the range of either FADT GPE block */
409
410 return (NULL);
411 }
412
413 /* A Non-NULL GpeDevice means this is a GPE Block Device */
414
415 ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);
416 if (!ObjDesc ||
417 !ObjDesc->Device.GpeBlock)
418 {
419 return (NULL);
420 }
421
422 return (AcpiEvLowGetGpeInfo (GpeNumber, ObjDesc->Device.GpeBlock));
423 }
424
425
426 /*******************************************************************************
427 *
428 * FUNCTION: AcpiEvGpeDetect
429 *
430 * PARAMETERS: GpeXruptList - Interrupt block for this interrupt.
431 * Can have multiple GPE blocks attached.
432 *
433 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
434 *
435 * DESCRIPTION: Detect if any GP events have occurred. This function is
436 * executed at interrupt level.
437 *
438 ******************************************************************************/
439
440 UINT32
441 AcpiEvGpeDetect (
442 ACPI_GPE_XRUPT_INFO *GpeXruptList)
443 {
444 ACPI_STATUS Status;
445 ACPI_GPE_BLOCK_INFO *GpeBlock;
446 ACPI_NAMESPACE_NODE *GpeDevice;
447 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
448 ACPI_GPE_EVENT_INFO *GpeEventInfo;
449 UINT32 GpeNumber;
450 ACPI_GPE_HANDLER_INFO *GpeHandlerInfo;
451 UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;
452 UINT8 EnabledStatusByte;
453 UINT32 StatusReg;
454 UINT32 EnableReg;
455 ACPI_CPU_FLAGS Flags;
456 UINT32 i;
457 UINT32 j;
458
459
460 ACPI_FUNCTION_NAME (EvGpeDetect);
461
462 /* Check for the case where there are no GPEs */
463
464 if (!GpeXruptList)
465 {
466 return (IntStatus);
467 }
468
469 /*
470 * We need to obtain the GPE lock for both the data structs and registers
471 * Note: Not necessary to obtain the hardware lock, since the GPE
472 * registers are owned by the GpeLock.
473 */
474 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
475
476 /* Examine all GPE blocks attached to this interrupt level */
477
478 GpeBlock = GpeXruptList->GpeBlockListHead;
479 while (GpeBlock)
480 {
481 GpeDevice = GpeBlock->Node;
482
483 /*
484 * Read all of the 8-bit GPE status and enable registers in this GPE
485 * block, saving all of them. Find all currently active GP events.
486 */
487 for (i = 0; i < GpeBlock->RegisterCount; i++)
488 {
489 /* Get the next status/enable pair */
490
491 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
492
493 /*
494 * Optimization: If there are no GPEs enabled within this
495 * register, we can safely ignore the entire register.
496 */
497 if (!(GpeRegisterInfo->EnableForRun |
498 GpeRegisterInfo->EnableForWake))
499 {
500 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
501 "Ignore disabled registers for GPE %02X-%02X: "
502 "RunEnable=%02X, WakeEnable=%02X\n",
503 GpeRegisterInfo->BaseGpeNumber,
504 GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),
505 GpeRegisterInfo->EnableForRun,
506 GpeRegisterInfo->EnableForWake));
507 continue;
508 }
509
510 /* Read the Status Register */
511
512 Status = AcpiHwRead (&StatusReg, &GpeRegisterInfo->StatusAddress);
513 if (ACPI_FAILURE (Status))
514 {
515 goto UnlockAndExit;
516 }
517
518 /* Read the Enable Register */
519
520 Status = AcpiHwRead (&EnableReg, &GpeRegisterInfo->EnableAddress);
521 if (ACPI_FAILURE (Status))
522 {
523 goto UnlockAndExit;
524 }
525
526 ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,
527 "Read registers for GPE %02X-%02X: Status=%02X, Enable=%02X, "
528 "RunEnable=%02X, WakeEnable=%02X\n",
529 GpeRegisterInfo->BaseGpeNumber,
530 GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),
531 StatusReg, EnableReg,
532 GpeRegisterInfo->EnableForRun,
533 GpeRegisterInfo->EnableForWake));
534
535 /* Check if there is anything active at all in this register */
536
537 EnabledStatusByte = (UINT8) (StatusReg & EnableReg);
538 if (!EnabledStatusByte)
539 {
540 /* No active GPEs in this register, move on */
541
542 continue;
543 }
544
545 /* Now look at the individual GPEs in this byte register */
546
547 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
548 {
549 /* Examine one GPE bit */
550
551 GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
552 ACPI_GPE_REGISTER_WIDTH) + j];
553 GpeNumber = j + GpeRegisterInfo->BaseGpeNumber;
554
555 if (EnabledStatusByte & (1 << j))
556 {
557 /* Invoke global event handler if present */
558
559 AcpiGpeCount++;
560 if (AcpiGbl_GlobalEventHandler)
561 {
562 AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_GPE,
563 GpeDevice, GpeNumber,
564 AcpiGbl_GlobalEventHandlerContext);
565 }
566
567 /* Found an active GPE */
568
569 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
570 ACPI_GPE_DISPATCH_RAW_HANDLER)
571 {
572 /* Dispatch the event to a raw handler */
573
574 GpeHandlerInfo = GpeEventInfo->Dispatch.Handler;
575
576 /*
577 * There is no protection around the namespace node
578 * and the GPE handler to ensure a safe destruction
579 * because:
580 * 1. The namespace node is expected to always
581 * exist after loading a table.
582 * 2. The GPE handler is expected to be flushed by
583 * AcpiOsWaitEventsComplete() before the
584 * destruction.
585 */
586 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
587 IntStatus |= GpeHandlerInfo->Address (
588 GpeDevice, GpeNumber, GpeHandlerInfo->Context);
589 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
590 }
591 else
592 {
593 /*
594 * Dispatch the event to a standard handler or
595 * method.
596 */
597 IntStatus |= AcpiEvGpeDispatch (GpeDevice,
598 GpeEventInfo, GpeNumber);
599 }
600 }
601 }
602 }
603
604 GpeBlock = GpeBlock->Next;
605 }
606
607 UnlockAndExit:
608
609 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
610 return (IntStatus);
611 }
612
613
614 /*******************************************************************************
615 *
616 * FUNCTION: AcpiEvAsynchExecuteGpeMethod
617 *
618 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
619 *
620 * RETURN: None
621 *
622 * DESCRIPTION: Perform the actual execution of a GPE control method. This
623 * function is called from an invocation of AcpiOsExecute and
624 * therefore does NOT execute at interrupt level - so that
625 * the control method itself is not executed in the context of
626 * an interrupt handler.
627 *
628 ******************************************************************************/
629
630 static void ACPI_SYSTEM_XFACE
631 AcpiEvAsynchExecuteGpeMethod (
632 void *Context)
633 {
634 ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;
635 ACPI_STATUS Status = AE_OK;
636 ACPI_EVALUATE_INFO *Info;
637 ACPI_GPE_NOTIFY_INFO *Notify;
638
639
640 ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod);
641
642
643 /* Do the correct dispatch - normal method or implicit notify */
644
645 switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
646 {
647 case ACPI_GPE_DISPATCH_NOTIFY:
648 /*
649 * Implicit notify.
650 * Dispatch a DEVICE_WAKE notify to the appropriate handler.
651 * NOTE: the request is queued for execution after this method
652 * completes. The notify handlers are NOT invoked synchronously
653 * from this thread -- because handlers may in turn run other
654 * control methods.
655 *
656 * June 2012: Expand implicit notify mechanism to support
657 * notifies on multiple device objects.
658 */
659 Notify = GpeEventInfo->Dispatch.NotifyList;
660 while (ACPI_SUCCESS (Status) && Notify)
661 {
662 Status = AcpiEvQueueNotifyRequest (Notify->DeviceNode,
663 ACPI_NOTIFY_DEVICE_WAKE);
664
665 Notify = Notify->Next;
666 }
667 break;
668
669 case ACPI_GPE_DISPATCH_METHOD:
670
671 /* Allocate the evaluation information block */
672
673 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
674 if (!Info)
675 {
676 Status = AE_NO_MEMORY;
677 }
678 else
679 {
680 /*
681 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the
682 * _Lxx/_Exx control method that corresponds to this GPE
683 */
684 Info->PrefixNode = GpeEventInfo->Dispatch.MethodNode;
685 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
686
687 Status = AcpiNsEvaluate (Info);
688 ACPI_FREE (Info);
689 }
690
691 if (ACPI_FAILURE (Status))
692 {
693 ACPI_EXCEPTION ((AE_INFO, Status,
694 "while evaluating GPE method [%4.4s]",
695 AcpiUtGetNodeName (GpeEventInfo->Dispatch.MethodNode)));
696 }
697 break;
698
699 default:
700
701 goto ErrorExit; /* Should never happen */
702 }
703
704 /* Defer enabling of GPE until all notify handlers are done */
705
706 Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,
707 AcpiEvAsynchEnableGpe, GpeEventInfo);
708 if (ACPI_SUCCESS (Status))
709 {
710 return_VOID;
711 }
712
713 ErrorExit:
714 AcpiEvAsynchEnableGpe (GpeEventInfo);
715 return_VOID;
716 }
717
718
719 /*******************************************************************************
720 *
721 * FUNCTION: AcpiEvAsynchEnableGpe
722 *
723 * PARAMETERS: Context (GpeEventInfo) - Info for this GPE
724 * Callback from AcpiOsExecute
725 *
726 * RETURN: None
727 *
728 * DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to
729 * complete (i.e., finish execution of Notify)
730 *
731 ******************************************************************************/
732
733 static void ACPI_SYSTEM_XFACE
734 AcpiEvAsynchEnableGpe (
735 void *Context)
736 {
737 ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;
738 ACPI_CPU_FLAGS Flags;
739
740
741 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
742 (void) AcpiEvFinishGpe (GpeEventInfo);
743 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
744
745 return;
746 }
747
748
749 /*******************************************************************************
750 *
751 * FUNCTION: AcpiEvFinishGpe
752 *
753 * PARAMETERS: GpeEventInfo - Info for this GPE
754 *
755 * RETURN: Status
756 *
757 * DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution
758 * of a GPE method or a synchronous or asynchronous GPE handler.
759 *
760 ******************************************************************************/
761
762 ACPI_STATUS
763 AcpiEvFinishGpe (
764 ACPI_GPE_EVENT_INFO *GpeEventInfo)
765 {
766 ACPI_STATUS Status;
767
768
769 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
770 ACPI_GPE_LEVEL_TRIGGERED)
771 {
772 /*
773 * GPE is level-triggered, we clear the GPE status bit after
774 * handling the event.
775 */
776 Status = AcpiHwClearGpe (GpeEventInfo);
777 if (ACPI_FAILURE (Status))
778 {
779 return (Status);
780 }
781 }
782
783 /*
784 * Enable this GPE, conditionally. This means that the GPE will
785 * only be physically enabled if the EnableMask bit is set
786 * in the EventInfo.
787 */
788 (void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);
789 return (AE_OK);
790 }
791
792
793 /*******************************************************************************
794 *
795 * FUNCTION: AcpiEvGpeDispatch
796 *
797 * PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1
798 * GpeEventInfo - Info for this GPE
799 * GpeNumber - Number relative to the parent GPE block
800 *
801 * RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
802 *
803 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
804 * or method (e.g. _Lxx/_Exx) handler.
805 *
806 * This function executes at interrupt level.
807 *
808 ******************************************************************************/
809
810 UINT32
811 AcpiEvGpeDispatch (
812 ACPI_NAMESPACE_NODE *GpeDevice,
813 ACPI_GPE_EVENT_INFO *GpeEventInfo,
814 UINT32 GpeNumber)
815 {
816 ACPI_STATUS Status;
817 UINT32 ReturnValue;
818
819
820 ACPI_FUNCTION_TRACE (EvGpeDispatch);
821
822
823 /*
824 * Always disable the GPE so that it does not keep firing before
825 * any asynchronous activity completes (either from the execution
826 * of a GPE method or an asynchronous GPE handler.)
827 *
828 * If there is no handler or method to run, just disable the
829 * GPE and leave it disabled permanently to prevent further such
830 * pointless events from firing.
831 */
832 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
833 if (ACPI_FAILURE (Status))
834 {
835 ACPI_EXCEPTION ((AE_INFO, Status,
836 "Unable to disable GPE %02X", GpeNumber));
837 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
838 }
839
840 /*
841 * If edge-triggered, clear the GPE status bit now. Note that
842 * level-triggered events are cleared after the GPE is serviced.
843 */
844 if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
845 ACPI_GPE_EDGE_TRIGGERED)
846 {
847 Status = AcpiHwClearGpe (GpeEventInfo);
848 if (ACPI_FAILURE (Status))
849 {
850 ACPI_EXCEPTION ((AE_INFO, Status,
851 "Unable to clear GPE %02X", GpeNumber));
852 (void) AcpiHwLowSetGpe (GpeEventInfo,
853 ACPI_GPE_CONDITIONAL_ENABLE);
854 return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);
855 }
856 }
857
858 /*
859 * Dispatch the GPE to either an installed handler or the control
860 * method associated with this GPE (_Lxx or _Exx). If a handler
861 * exists, we invoke it and do not attempt to run the method.
862 * If there is neither a handler nor a method, leave the GPE
863 * disabled.
864 */
865 switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))
866 {
867 case ACPI_GPE_DISPATCH_HANDLER:
868
869 /* Invoke the installed handler (at interrupt level) */
870
871 ReturnValue = GpeEventInfo->Dispatch.Handler->Address (
872 GpeDevice, GpeNumber,
873 GpeEventInfo->Dispatch.Handler->Context);
874
875 /* If requested, clear (if level-triggered) and reenable the GPE */
876
877 if (ReturnValue & ACPI_REENABLE_GPE)
878 {
879 (void) AcpiEvFinishGpe (GpeEventInfo);
880 }
881 break;
882
883 case ACPI_GPE_DISPATCH_METHOD:
884 case ACPI_GPE_DISPATCH_NOTIFY:
885 /*
886 * Execute the method associated with the GPE
887 * NOTE: Level-triggered GPEs are cleared after the method completes.
888 */
889 Status = AcpiOsExecute (OSL_GPE_HANDLER,
890 AcpiEvAsynchExecuteGpeMethod, GpeEventInfo);
891 if (ACPI_FAILURE (Status))
892 {
893 ACPI_EXCEPTION ((AE_INFO, Status,
894 "Unable to queue handler for GPE %02X - event disabled",
895 GpeNumber));
896 }
897 break;
898
899 default:
900 /*
901 * No handler or method to run!
902 * 03/2010: This case should no longer be possible. We will not allow
903 * a GPE to be enabled if it has no handler or method.
904 */
905 ACPI_ERROR ((AE_INFO,
906 "No handler or method for GPE %02X, disabling event",
907 GpeNumber));
908 break;
909 }
910
911 return_UINT32 (ACPI_INTERRUPT_HANDLED);
912 }
913
914 #endif /* !ACPI_REDUCED_HARDWARE */