1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, 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 #include <contrib/dev/acpica/include/acpi.h>
117 #include <contrib/dev/acpica/include/accommon.h>
118 #include <contrib/dev/acpica/include/acevents.h>
119 #include <contrib/dev/acpica/include/acnamesp.h>
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpeblk")
124 /* Local prototypes */
127 AcpiEvMatchGpeMethod (
128 ACPI_HANDLE ObjHandle,
134 AcpiEvMatchPrwAndGpe (
135 ACPI_HANDLE ObjHandle,
140 static ACPI_GPE_XRUPT_INFO *
141 AcpiEvGetGpeXruptBlock (
142 UINT32 InterruptNumber);
145 AcpiEvDeleteGpeXrupt (
146 ACPI_GPE_XRUPT_INFO *GpeXrupt);
149 AcpiEvInstallGpeBlock (
150 ACPI_GPE_BLOCK_INFO *GpeBlock,
151 UINT32 InterruptNumber);
154 AcpiEvCreateGpeInfoBlocks (
155 ACPI_GPE_BLOCK_INFO *GpeBlock);
158 /*******************************************************************************
160 * FUNCTION: AcpiEvValidGpeEvent
162 * PARAMETERS: GpeEventInfo - Info for this GPE
164 * RETURN: TRUE if the GpeEvent is valid
166 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
167 * Should be called only when the GPE lists are semaphore locked
168 * and not subject to change.
170 ******************************************************************************/
173 AcpiEvValidGpeEvent (
174 ACPI_GPE_EVENT_INFO *GpeEventInfo)
176 ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
177 ACPI_GPE_BLOCK_INFO *GpeBlock;
180 ACPI_FUNCTION_ENTRY ();
183 /* No need for spin lock since we are not changing any list elements */
185 /* Walk the GPE interrupt levels */
187 GpeXruptBlock = AcpiGbl_GpeXruptListHead;
188 while (GpeXruptBlock)
190 GpeBlock = GpeXruptBlock->GpeBlockListHead;
192 /* Walk the GPE blocks on this interrupt level */
196 if ((&GpeBlock->EventInfo[0] <= GpeEventInfo) &&
197 (&GpeBlock->EventInfo[GpeBlock->GpeCount] > GpeEventInfo))
202 GpeBlock = GpeBlock->Next;
205 GpeXruptBlock = GpeXruptBlock->Next;
212 /*******************************************************************************
214 * FUNCTION: AcpiEvWalkGpeList
216 * PARAMETERS: GpeWalkCallback - Routine called for each GPE block
217 * Context - Value passed to callback
221 * DESCRIPTION: Walk the GPE lists.
223 ******************************************************************************/
227 ACPI_GPE_CALLBACK GpeWalkCallback,
230 ACPI_GPE_BLOCK_INFO *GpeBlock;
231 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
232 ACPI_STATUS Status = AE_OK;
233 ACPI_CPU_FLAGS Flags;
236 ACPI_FUNCTION_TRACE (EvWalkGpeList);
239 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
241 /* Walk the interrupt level descriptor list */
243 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
246 /* Walk all Gpe Blocks attached to this interrupt level */
248 GpeBlock = GpeXruptInfo->GpeBlockListHead;
251 /* One callback per GPE block */
253 Status = GpeWalkCallback (GpeXruptInfo, GpeBlock, Context);
254 if (ACPI_FAILURE (Status))
256 if (Status == AE_CTRL_END) /* Callback abort */
263 GpeBlock = GpeBlock->Next;
266 GpeXruptInfo = GpeXruptInfo->Next;
270 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
271 return_ACPI_STATUS (Status);
275 /*******************************************************************************
277 * FUNCTION: AcpiEvDeleteGpeHandlers
279 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
280 * GpeBlock - Gpe Block info
284 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
285 * Used only prior to termination.
287 ******************************************************************************/
290 AcpiEvDeleteGpeHandlers (
291 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
292 ACPI_GPE_BLOCK_INFO *GpeBlock,
295 ACPI_GPE_EVENT_INFO *GpeEventInfo;
300 ACPI_FUNCTION_TRACE (EvDeleteGpeHandlers);
303 /* Examine each GPE Register within the block */
305 for (i = 0; i < GpeBlock->RegisterCount; i++)
307 /* Now look at the individual GPEs in this byte register */
309 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
311 GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
312 ACPI_GPE_REGISTER_WIDTH) + j];
314 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
315 ACPI_GPE_DISPATCH_HANDLER)
317 ACPI_FREE (GpeEventInfo->Dispatch.Handler);
318 GpeEventInfo->Dispatch.Handler = NULL;
319 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
324 return_ACPI_STATUS (AE_OK);
328 /*******************************************************************************
330 * FUNCTION: AcpiEvMatchGpeMethod
332 * PARAMETERS: Callback from WalkNamespace
336 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
337 * control method under the _GPE portion of the namespace.
338 * Extract the name and GPE type from the object, saving this
339 * information for quick lookup during GPE dispatch
341 * The name of each GPE control method is of the form:
342 * "_Lxx" or "_Exx", where:
343 * L - means that the GPE is level triggered
344 * E - means that the GPE is edge triggered
345 * xx - is the GPE number [in HEX]
347 ******************************************************************************/
350 AcpiEvMatchGpeMethod (
351 ACPI_HANDLE ObjHandle,
356 ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
357 ACPI_GPE_BLOCK_INFO *GpeBlock = (void *) ObjDesc;
358 ACPI_GPE_EVENT_INFO *GpeEventInfo;
360 char Name[ACPI_NAME_SIZE + 1];
364 ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
368 * Match and decode the _Lxx and _Exx GPE method names
370 * 1) Extract the method name and null terminate it
372 ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
373 Name[ACPI_NAME_SIZE] = 0;
375 /* 2) Name must begin with an underscore */
379 return_ACPI_STATUS (AE_OK); /* Ignore this method */
383 * 3) Edge/Level determination is based on the 2nd character
386 * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
387 * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
392 Type = ACPI_GPE_LEVEL_TRIGGERED;
396 Type = ACPI_GPE_EDGE_TRIGGERED;
400 /* Unknown method type, just ignore it */
402 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
403 "Ignoring unknown GPE method type: %s "
404 "(name not of form _Lxx or _Exx)", Name));
405 return_ACPI_STATUS (AE_OK);
408 /* 4) The last two characters of the name are the hex GPE Number */
410 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
411 if (GpeNumber == ACPI_UINT32_MAX)
413 /* Conversion failed; invalid method, just ignore it */
415 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
416 "Could not extract GPE number from name: %s "
417 "(name is not of form _Lxx or _Exx)", Name));
418 return_ACPI_STATUS (AE_OK);
421 /* Ensure that we have a valid GPE number for this GPE block */
423 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, GpeBlock);
427 * This GpeNumber is not valid for this GPE block, just ignore it.
428 * However, it may be valid for a different GPE block, since GPE0
429 * and GPE1 methods both appear under \_GPE.
431 return_ACPI_STATUS (AE_OK);
435 * Add the GPE information from above to the GpeEventInfo block for
436 * use during dispatch of this GPE.
438 GpeEventInfo->Flags = (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD);
439 GpeEventInfo->Dispatch.MethodNode = MethodNode;
441 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
442 "Registered GPE method %s as GPE number 0x%.2X\n",
444 return_ACPI_STATUS (AE_OK);
448 /*******************************************************************************
450 * FUNCTION: AcpiEvMatchPrwAndGpe
452 * PARAMETERS: Callback from WalkNamespace
454 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
455 * not aborted on a single _PRW failure.
457 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
458 * Device. Run the _PRW method. If present, extract the GPE
459 * number and mark the GPE as a CAN_WAKE GPE.
461 ******************************************************************************/
464 AcpiEvMatchPrwAndGpe (
465 ACPI_HANDLE ObjHandle,
470 ACPI_GPE_WALK_INFO *GpeInfo = (void *) Info;
471 ACPI_NAMESPACE_NODE *GpeDevice;
472 ACPI_GPE_BLOCK_INFO *GpeBlock;
473 ACPI_NAMESPACE_NODE *TargetGpeDevice;
474 ACPI_GPE_EVENT_INFO *GpeEventInfo;
475 ACPI_OPERAND_OBJECT *PkgDesc;
476 ACPI_OPERAND_OBJECT *ObjDesc;
481 ACPI_FUNCTION_TRACE (EvMatchPrwAndGpe);
484 /* Check for a _PRW method under this device */
486 Status = AcpiUtEvaluateObject (ObjHandle, METHOD_NAME__PRW,
487 ACPI_BTYPE_PACKAGE, &PkgDesc);
488 if (ACPI_FAILURE (Status))
490 /* Ignore all errors from _PRW, we don't want to abort the walk */
492 return_ACPI_STATUS (AE_OK);
495 /* The returned _PRW package must have at least two elements */
497 if (PkgDesc->Package.Count < 2)
502 /* Extract pointers from the input context */
504 GpeDevice = GpeInfo->GpeDevice;
505 GpeBlock = GpeInfo->GpeBlock;
508 * The _PRW object must return a package, we are only interested in the
511 ObjDesc = PkgDesc->Package.Elements[0];
513 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
515 /* Use FADT-defined GPE device (from definition of _PRW) */
517 TargetGpeDevice = AcpiGbl_FadtGpeDevice;
519 /* Integer is the GPE number in the FADT described GPE blocks */
521 GpeNumber = (UINT32) ObjDesc->Integer.Value;
523 else if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
525 /* Package contains a GPE reference and GPE number within a GPE block */
527 if ((ObjDesc->Package.Count < 2) ||
528 ((ObjDesc->Package.Elements[0])->Common.Type !=
529 ACPI_TYPE_LOCAL_REFERENCE) ||
530 ((ObjDesc->Package.Elements[1])->Common.Type !=
536 /* Get GPE block reference and decode */
538 TargetGpeDevice = ObjDesc->Package.Elements[0]->Reference.Node;
539 GpeNumber = (UINT32) ObjDesc->Package.Elements[1]->Integer.Value;
543 /* Unknown type, just ignore it */
549 * Is this GPE within this block?
551 * TRUE if and only if these conditions are true:
552 * 1) The GPE devices match.
553 * 2) The GPE index(number) is within the range of the Gpe Block
554 * associated with the GPE device.
556 if (GpeDevice != TargetGpeDevice)
561 GpeEventInfo = AcpiEvLowGetGpeInfo (GpeNumber, GpeBlock);
564 /* This GPE can wake the system */
566 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
570 AcpiUtRemoveReference (PkgDesc);
571 return_ACPI_STATUS (AE_OK);
575 /*******************************************************************************
577 * FUNCTION: AcpiEvGetGpeXruptBlock
579 * PARAMETERS: InterruptNumber - Interrupt for a GPE block
581 * RETURN: A GPE interrupt block
583 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
584 * block per unique interrupt level used for GPEs. Should be
585 * called only when the GPE lists are semaphore locked and not
588 ******************************************************************************/
590 static ACPI_GPE_XRUPT_INFO *
591 AcpiEvGetGpeXruptBlock (
592 UINT32 InterruptNumber)
594 ACPI_GPE_XRUPT_INFO *NextGpeXrupt;
595 ACPI_GPE_XRUPT_INFO *GpeXrupt;
597 ACPI_CPU_FLAGS Flags;
600 ACPI_FUNCTION_TRACE (EvGetGpeXruptBlock);
603 /* No need for lock since we are not changing any list elements here */
605 NextGpeXrupt = AcpiGbl_GpeXruptListHead;
608 if (NextGpeXrupt->InterruptNumber == InterruptNumber)
610 return_PTR (NextGpeXrupt);
613 NextGpeXrupt = NextGpeXrupt->Next;
616 /* Not found, must allocate a new xrupt descriptor */
618 GpeXrupt = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_XRUPT_INFO));
624 GpeXrupt->InterruptNumber = InterruptNumber;
626 /* Install new interrupt descriptor with spin lock */
628 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
629 if (AcpiGbl_GpeXruptListHead)
631 NextGpeXrupt = AcpiGbl_GpeXruptListHead;
632 while (NextGpeXrupt->Next)
634 NextGpeXrupt = NextGpeXrupt->Next;
637 NextGpeXrupt->Next = GpeXrupt;
638 GpeXrupt->Previous = NextGpeXrupt;
642 AcpiGbl_GpeXruptListHead = GpeXrupt;
644 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
646 /* Install new interrupt handler if not SCI_INT */
648 if (InterruptNumber != AcpiGbl_FADT.SciInterrupt)
650 Status = AcpiOsInstallInterruptHandler (InterruptNumber,
651 AcpiEvGpeXruptHandler, GpeXrupt);
652 if (ACPI_FAILURE (Status))
654 ACPI_ERROR ((AE_INFO,
655 "Could not install GPE interrupt handler at level 0x%X",
661 return_PTR (GpeXrupt);
665 /*******************************************************************************
667 * FUNCTION: AcpiEvDeleteGpeXrupt
669 * PARAMETERS: GpeXrupt - A GPE interrupt info block
673 * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated
674 * interrupt handler if not the SCI interrupt.
676 ******************************************************************************/
679 AcpiEvDeleteGpeXrupt (
680 ACPI_GPE_XRUPT_INFO *GpeXrupt)
683 ACPI_CPU_FLAGS Flags;
686 ACPI_FUNCTION_TRACE (EvDeleteGpeXrupt);
689 /* We never want to remove the SCI interrupt handler */
691 if (GpeXrupt->InterruptNumber == AcpiGbl_FADT.SciInterrupt)
693 GpeXrupt->GpeBlockListHead = NULL;
694 return_ACPI_STATUS (AE_OK);
697 /* Disable this interrupt */
699 Status = AcpiOsRemoveInterruptHandler (
700 GpeXrupt->InterruptNumber, AcpiEvGpeXruptHandler);
701 if (ACPI_FAILURE (Status))
703 return_ACPI_STATUS (Status);
706 /* Unlink the interrupt block with lock */
708 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
709 if (GpeXrupt->Previous)
711 GpeXrupt->Previous->Next = GpeXrupt->Next;
715 /* No previous, update list head */
717 AcpiGbl_GpeXruptListHead = GpeXrupt->Next;
722 GpeXrupt->Next->Previous = GpeXrupt->Previous;
724 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
728 ACPI_FREE (GpeXrupt);
729 return_ACPI_STATUS (AE_OK);
733 /*******************************************************************************
735 * FUNCTION: AcpiEvInstallGpeBlock
737 * PARAMETERS: GpeBlock - New GPE block
738 * InterruptNumber - Xrupt to be associated with this
743 * DESCRIPTION: Install new GPE block with mutex support
745 ******************************************************************************/
748 AcpiEvInstallGpeBlock (
749 ACPI_GPE_BLOCK_INFO *GpeBlock,
750 UINT32 InterruptNumber)
752 ACPI_GPE_BLOCK_INFO *NextGpeBlock;
753 ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
755 ACPI_CPU_FLAGS Flags;
758 ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
761 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
762 if (ACPI_FAILURE (Status))
764 return_ACPI_STATUS (Status);
767 GpeXruptBlock = AcpiEvGetGpeXruptBlock (InterruptNumber);
770 Status = AE_NO_MEMORY;
774 /* Install the new block at the end of the list with lock */
776 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
777 if (GpeXruptBlock->GpeBlockListHead)
779 NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
780 while (NextGpeBlock->Next)
782 NextGpeBlock = NextGpeBlock->Next;
785 NextGpeBlock->Next = GpeBlock;
786 GpeBlock->Previous = NextGpeBlock;
790 GpeXruptBlock->GpeBlockListHead = GpeBlock;
793 GpeBlock->XruptBlock = GpeXruptBlock;
794 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
798 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
799 return_ACPI_STATUS (Status);
803 /*******************************************************************************
805 * FUNCTION: AcpiEvDeleteGpeBlock
807 * PARAMETERS: GpeBlock - Existing GPE block
811 * DESCRIPTION: Remove a GPE block
813 ******************************************************************************/
816 AcpiEvDeleteGpeBlock (
817 ACPI_GPE_BLOCK_INFO *GpeBlock)
820 ACPI_CPU_FLAGS Flags;
823 ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
826 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
827 if (ACPI_FAILURE (Status))
829 return_ACPI_STATUS (Status);
832 /* Disable all GPEs in this block */
834 Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
836 if (!GpeBlock->Previous && !GpeBlock->Next)
838 /* This is the last GpeBlock on this interrupt */
840 Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
841 if (ACPI_FAILURE (Status))
848 /* Remove the block on this interrupt with lock */
850 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
851 if (GpeBlock->Previous)
853 GpeBlock->Previous->Next = GpeBlock->Next;
857 GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
862 GpeBlock->Next->Previous = GpeBlock->Previous;
864 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
867 AcpiCurrentGpeCount -= GpeBlock->GpeCount;
869 /* Free the GpeBlock */
871 ACPI_FREE (GpeBlock->RegisterInfo);
872 ACPI_FREE (GpeBlock->EventInfo);
873 ACPI_FREE (GpeBlock);
876 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
877 return_ACPI_STATUS (Status);
881 /*******************************************************************************
883 * FUNCTION: AcpiEvCreateGpeInfoBlocks
885 * PARAMETERS: GpeBlock - New GPE block
889 * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
891 ******************************************************************************/
894 AcpiEvCreateGpeInfoBlocks (
895 ACPI_GPE_BLOCK_INFO *GpeBlock)
897 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo = NULL;
898 ACPI_GPE_EVENT_INFO *GpeEventInfo = NULL;
899 ACPI_GPE_EVENT_INFO *ThisEvent;
900 ACPI_GPE_REGISTER_INFO *ThisRegister;
906 ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
909 /* Allocate the GPE register information block */
911 GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
912 (ACPI_SIZE) GpeBlock->RegisterCount *
913 sizeof (ACPI_GPE_REGISTER_INFO));
914 if (!GpeRegisterInfo)
916 ACPI_ERROR ((AE_INFO,
917 "Could not allocate the GpeRegisterInfo table"));
918 return_ACPI_STATUS (AE_NO_MEMORY);
922 * Allocate the GPE EventInfo block. There are eight distinct GPEs
923 * per register. Initialization to zeros is sufficient.
925 GpeEventInfo = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) GpeBlock->GpeCount *
926 sizeof (ACPI_GPE_EVENT_INFO));
929 ACPI_ERROR ((AE_INFO,
930 "Could not allocate the GpeEventInfo table"));
931 Status = AE_NO_MEMORY;
935 /* Save the new Info arrays in the GPE block */
937 GpeBlock->RegisterInfo = GpeRegisterInfo;
938 GpeBlock->EventInfo = GpeEventInfo;
941 * Initialize the GPE Register and Event structures. A goal of these
942 * tables is to hide the fact that there are two separate GPE register
943 * sets in a given GPE hardware block, the status registers occupy the
944 * first half, and the enable registers occupy the second half.
946 ThisRegister = GpeRegisterInfo;
947 ThisEvent = GpeEventInfo;
949 for (i = 0; i < GpeBlock->RegisterCount; i++)
951 /* Init the RegisterInfo for this GPE register (8 GPEs) */
953 ThisRegister->BaseGpeNumber = (UINT8) (GpeBlock->BlockBaseNumber +
954 (i * ACPI_GPE_REGISTER_WIDTH));
956 ThisRegister->StatusAddress.Address =
957 GpeBlock->BlockAddress.Address + i;
959 ThisRegister->EnableAddress.Address =
960 GpeBlock->BlockAddress.Address + i + GpeBlock->RegisterCount;
962 ThisRegister->StatusAddress.SpaceId = GpeBlock->BlockAddress.SpaceId;
963 ThisRegister->EnableAddress.SpaceId = GpeBlock->BlockAddress.SpaceId;
964 ThisRegister->StatusAddress.BitWidth = ACPI_GPE_REGISTER_WIDTH;
965 ThisRegister->EnableAddress.BitWidth = ACPI_GPE_REGISTER_WIDTH;
966 ThisRegister->StatusAddress.BitOffset = 0;
967 ThisRegister->EnableAddress.BitOffset = 0;
969 /* Init the EventInfo for each GPE within this register */
971 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
973 ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
974 ThisEvent->RegisterInfo = ThisRegister;
978 /* Disable all GPEs within this register */
980 Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
981 if (ACPI_FAILURE (Status))
986 /* Clear any pending GPE events within this register */
988 Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
989 if (ACPI_FAILURE (Status))
997 return_ACPI_STATUS (AE_OK);
1001 if (GpeRegisterInfo)
1003 ACPI_FREE (GpeRegisterInfo);
1007 ACPI_FREE (GpeEventInfo);
1010 return_ACPI_STATUS (Status);
1014 /*******************************************************************************
1016 * FUNCTION: AcpiEvCreateGpeBlock
1018 * PARAMETERS: GpeDevice - Handle to the parent GPE block
1019 * GpeBlockAddress - Address and SpaceID
1020 * RegisterCount - Number of GPE register pairs in the block
1021 * GpeBlockBaseNumber - Starting GPE number for the block
1022 * InterruptNumber - H/W interrupt for the block
1023 * ReturnGpeBlock - Where the new block descriptor is returned
1027 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
1028 * the block are disabled at exit.
1029 * Note: Assumes namespace is locked.
1031 ******************************************************************************/
1034 AcpiEvCreateGpeBlock (
1035 ACPI_NAMESPACE_NODE *GpeDevice,
1036 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
1037 UINT32 RegisterCount,
1038 UINT8 GpeBlockBaseNumber,
1039 UINT32 InterruptNumber,
1040 ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
1043 ACPI_GPE_BLOCK_INFO *GpeBlock;
1046 ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
1051 return_ACPI_STATUS (AE_OK);
1054 /* Allocate a new GPE block */
1056 GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
1059 return_ACPI_STATUS (AE_NO_MEMORY);
1062 /* Initialize the new GPE block */
1064 GpeBlock->Node = GpeDevice;
1065 GpeBlock->GpeCount = (UINT16) (RegisterCount * ACPI_GPE_REGISTER_WIDTH);
1066 GpeBlock->RegisterCount = RegisterCount;
1067 GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
1069 ACPI_MEMCPY (&GpeBlock->BlockAddress, GpeBlockAddress,
1070 sizeof (ACPI_GENERIC_ADDRESS));
1073 * Create the RegisterInfo and EventInfo sub-structures
1074 * Note: disables and clears all GPEs in the block
1076 Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
1077 if (ACPI_FAILURE (Status))
1079 ACPI_FREE (GpeBlock);
1080 return_ACPI_STATUS (Status);
1083 /* Install the new block in the global lists */
1085 Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
1086 if (ACPI_FAILURE (Status))
1088 ACPI_FREE (GpeBlock);
1089 return_ACPI_STATUS (Status);
1092 /* Find all GPE methods (_Lxx, _Exx) for this block */
1094 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
1095 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
1096 AcpiEvMatchGpeMethod, NULL, GpeBlock, NULL);
1098 /* Return the new block */
1102 (*ReturnGpeBlock) = GpeBlock;
1105 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1106 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
1107 (UINT32) GpeBlock->BlockBaseNumber,
1108 (UINT32) (GpeBlock->BlockBaseNumber + (GpeBlock->GpeCount - 1)),
1109 GpeDevice->Name.Ascii, GpeBlock->RegisterCount,
1112 /* Update global count of currently available GPEs */
1114 AcpiCurrentGpeCount += GpeBlock->GpeCount;
1115 return_ACPI_STATUS (AE_OK);
1119 /*******************************************************************************
1121 * FUNCTION: AcpiEvInitializeGpeBlock
1123 * PARAMETERS: GpeDevice - Handle to the parent GPE block
1124 * GpeBlock - Gpe Block info
1128 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
1129 * _PRT methods associated with the block, then enable the
1131 * Note: Assumes namespace is locked.
1133 ******************************************************************************/
1136 AcpiEvInitializeGpeBlock (
1137 ACPI_NAMESPACE_NODE *GpeDevice,
1138 ACPI_GPE_BLOCK_INFO *GpeBlock)
1141 ACPI_GPE_EVENT_INFO *GpeEventInfo;
1142 ACPI_GPE_WALK_INFO GpeInfo;
1143 UINT32 WakeGpeCount;
1144 UINT32 GpeEnabledCount;
1151 ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
1154 /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
1158 return_ACPI_STATUS (AE_OK);
1162 * Runtime option: Should wake GPEs be enabled at runtime? The default
1163 * is no, they should only be enabled just as the machine goes to sleep.
1165 if (AcpiGbl_LeaveWakeGpesDisabled)
1168 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
1169 * Each GPE that has one or more _PRWs that reference it is by
1170 * definition a wake GPE and will not be enabled while the machine
1173 GpeInfo.GpeBlock = GpeBlock;
1174 GpeInfo.GpeDevice = GpeDevice;
1176 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1177 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
1178 AcpiEvMatchPrwAndGpe, NULL, &GpeInfo, NULL);
1179 if (ACPI_FAILURE (Status))
1181 ACPI_EXCEPTION ((AE_INFO, Status, "While executing _PRW methods"));
1186 * Enable all GPEs that have a corresponding method and are not
1187 * capable of generating wakeups. Any other GPEs within this block
1188 * must be enabled via the AcpiEnableGpe interface.
1191 GpeEnabledCount = 0;
1193 if (GpeDevice == AcpiGbl_FadtGpeDevice)
1198 for (i = 0; i < GpeBlock->RegisterCount; i++)
1200 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
1202 /* Get the info block for this particular GPE */
1204 GpeIndex = (i * ACPI_GPE_REGISTER_WIDTH) + j;
1205 GpeEventInfo = &GpeBlock->EventInfo[GpeIndex];
1207 /* Ignore GPEs that can wake the system */
1209 if (GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE)
1212 if (AcpiGbl_LeaveWakeGpesDisabled)
1218 /* Ignore GPEs that have no corresponding _Lxx/_Exx method */
1220 if (!(GpeEventInfo->Flags & ACPI_GPE_DISPATCH_METHOD))
1225 /* Enable this GPE */
1227 GpeNumber = GpeIndex + GpeBlock->BlockBaseNumber;
1228 Status = AcpiEnableGpe (GpeDevice, GpeNumber,
1229 ACPI_GPE_TYPE_RUNTIME);
1230 if (ACPI_FAILURE (Status))
1232 ACPI_EXCEPTION ((AE_INFO, Status,
1233 "Could not enable GPE 0x%02X", GpeNumber));
1241 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1242 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1243 WakeGpeCount, GpeEnabledCount));
1245 return_ACPI_STATUS (AE_OK);
1249 /*******************************************************************************
1251 * FUNCTION: AcpiEvGpeInitialize
1257 * DESCRIPTION: Initialize the GPE data structures
1259 ******************************************************************************/
1262 AcpiEvGpeInitialize (
1265 UINT32 RegisterCount0 = 0;
1266 UINT32 RegisterCount1 = 0;
1267 UINT32 GpeNumberMax = 0;
1271 ACPI_FUNCTION_TRACE (EvGpeInitialize);
1274 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1275 if (ACPI_FAILURE (Status))
1277 return_ACPI_STATUS (Status);
1281 * Initialize the GPE Block(s) defined in the FADT
1283 * Why the GPE register block lengths are divided by 2: From the ACPI
1284 * Spec, section "General-Purpose Event Registers", we have:
1286 * "Each register block contains two registers of equal length
1287 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1288 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1289 * The length of the GPE1_STS and GPE1_EN registers is equal to
1290 * half the GPE1_LEN. If a generic register block is not supported
1291 * then its respective block pointer and block length values in the
1292 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1293 * to be the same size."
1297 * Determine the maximum GPE number for this machine.
1299 * Note: both GPE0 and GPE1 are optional, and either can exist without
1302 * If EITHER the register length OR the block address are zero, then that
1303 * particular block is not supported.
1305 if (AcpiGbl_FADT.Gpe0BlockLength &&
1306 AcpiGbl_FADT.XGpe0Block.Address)
1308 /* GPE block 0 exists (has both length and address > 0) */
1310 RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
1312 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1314 /* Install GPE Block 0 */
1316 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
1317 &AcpiGbl_FADT.XGpe0Block, RegisterCount0, 0,
1318 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
1320 if (ACPI_FAILURE (Status))
1322 ACPI_EXCEPTION ((AE_INFO, Status,
1323 "Could not create GPE Block 0"));
1327 if (AcpiGbl_FADT.Gpe1BlockLength &&
1328 AcpiGbl_FADT.XGpe1Block.Address)
1330 /* GPE block 1 exists (has both length and address > 0) */
1332 RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
1334 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1336 if ((RegisterCount0) &&
1337 (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
1339 ACPI_ERROR ((AE_INFO,
1340 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
1341 "(GPE %u to %u) - Ignoring GPE1",
1342 GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
1343 AcpiGbl_FADT.Gpe1Base +
1344 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
1346 /* Ignore GPE1 block by setting the register count to zero */
1352 /* Install GPE Block 1 */
1354 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
1355 &AcpiGbl_FADT.XGpe1Block, RegisterCount1,
1356 AcpiGbl_FADT.Gpe1Base,
1357 AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
1359 if (ACPI_FAILURE (Status))
1361 ACPI_EXCEPTION ((AE_INFO, Status,
1362 "Could not create GPE Block 1"));
1366 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1367 * space. However, GPE0 always starts at GPE number zero.
1369 GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
1370 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1374 /* Exit if there are no GPE registers */
1376 if ((RegisterCount0 + RegisterCount1) == 0)
1378 /* GPEs are not required by ACPI, this is OK */
1380 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1381 "There are no GPE blocks defined in the FADT\n"));
1386 /* Check for Max GPE number out-of-range */
1388 if (GpeNumberMax > ACPI_GPE_MAX)
1390 ACPI_ERROR ((AE_INFO,
1391 "Maximum GPE number from FADT is too large: 0x%X",
1393 Status = AE_BAD_VALUE;
1398 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1399 return_ACPI_STATUS (AE_OK);