1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #include <contrib/dev/acpica/acpi.h>
118 #include <contrib/dev/acpica/acevents.h>
119 #include <contrib/dev/acpica/acnamesp.h>
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpeblk")
124 /* Local prototypes */
127 AcpiEvSaveMethodInfo (
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[((ACPI_SIZE) GpeBlock->RegisterCount) * 8] > GpeEventInfo))
202 GpeBlock = GpeBlock->Next;
205 GpeXruptBlock = GpeXruptBlock->Next;
212 /*******************************************************************************
214 * FUNCTION: AcpiEvWalkGpeList
216 * PARAMETERS: GpeWalkCallback - Routine called for each GPE block
220 * DESCRIPTION: Walk the GPE lists.
222 ******************************************************************************/
226 ACPI_GPE_CALLBACK GpeWalkCallback)
228 ACPI_GPE_BLOCK_INFO *GpeBlock;
229 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
230 ACPI_STATUS Status = AE_OK;
231 ACPI_NATIVE_UINT Flags;
234 ACPI_FUNCTION_TRACE ("EvWalkGpeList");
237 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
239 /* Walk the interrupt level descriptor list */
241 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
244 /* Walk all Gpe Blocks attached to this interrupt level */
246 GpeBlock = GpeXruptInfo->GpeBlockListHead;
249 /* One callback per GPE block */
251 Status = GpeWalkCallback (GpeXruptInfo, GpeBlock);
252 if (ACPI_FAILURE (Status))
257 GpeBlock = GpeBlock->Next;
260 GpeXruptInfo = GpeXruptInfo->Next;
264 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
265 return_ACPI_STATUS (Status);
269 /*******************************************************************************
271 * FUNCTION: AcpiEvDeleteGpeHandlers
273 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
274 * GpeBlock - Gpe Block info
278 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
279 * Used only prior to termination.
281 ******************************************************************************/
284 AcpiEvDeleteGpeHandlers (
285 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
286 ACPI_GPE_BLOCK_INFO *GpeBlock)
288 ACPI_GPE_EVENT_INFO *GpeEventInfo;
293 ACPI_FUNCTION_TRACE ("EvDeleteGpeHandlers");
296 /* Examine each GPE Register within the block */
298 for (i = 0; i < GpeBlock->RegisterCount; i++)
300 /* Now look at the individual GPEs in this byte register */
302 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
304 GpeEventInfo = &GpeBlock->EventInfo[(i * ACPI_GPE_REGISTER_WIDTH) + j];
306 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
307 ACPI_GPE_DISPATCH_HANDLER)
309 ACPI_MEM_FREE (GpeEventInfo->Dispatch.Handler);
310 GpeEventInfo->Dispatch.Handler = NULL;
311 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
316 return_ACPI_STATUS (AE_OK);
320 /*******************************************************************************
322 * FUNCTION: AcpiEvSaveMethodInfo
324 * PARAMETERS: Callback from WalkNamespace
328 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
329 * control method under the _GPE portion of the namespace.
330 * Extract the name and GPE type from the object, saving this
331 * information for quick lookup during GPE dispatch
333 * The name of each GPE control method is of the form:
336 * L - means that the GPE is level triggered
337 * E - means that the GPE is edge triggered
338 * xx - is the GPE number [in HEX]
340 ******************************************************************************/
343 AcpiEvSaveMethodInfo (
344 ACPI_HANDLE ObjHandle,
349 ACPI_GPE_BLOCK_INFO *GpeBlock = (void *) ObjDesc;
350 ACPI_GPE_EVENT_INFO *GpeEventInfo;
352 char Name[ACPI_NAME_SIZE + 1];
357 ACPI_FUNCTION_TRACE ("EvSaveMethodInfo");
361 * _Lxx and _Exx GPE method support
363 * 1) Extract the name from the object and convert to a string
365 ACPI_MOVE_32_TO_32 (Name,
366 &((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Integer);
367 Name[ACPI_NAME_SIZE] = 0;
370 * 2) Edge/Level determination is based on the 2nd character
373 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
374 * if a _PRW object is found that points to this GPE.
379 Type = ACPI_GPE_LEVEL_TRIGGERED;
383 Type = ACPI_GPE_EDGE_TRIGGERED;
387 /* Unknown method type, just ignore it! */
389 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
390 "Unknown GPE method type: %s (name not of form _Lxx or _Exx)\n",
392 return_ACPI_STATUS (AE_OK);
395 /* Convert the last two characters of the name to the GPE Number */
397 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
398 if (GpeNumber == ACPI_UINT32_MAX)
400 /* Conversion failed; invalid method, just ignore it */
402 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
403 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)\n",
405 return_ACPI_STATUS (AE_OK);
408 /* Ensure that we have a valid GPE number for this GPE block */
410 if ((GpeNumber < GpeBlock->BlockBaseNumber) ||
411 (GpeNumber >= (GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8))))
414 * Not valid for this GPE block, just ignore it
415 * However, it may be valid for a different GPE block, since GPE0 and GPE1
416 * methods both appear under \_GPE.
418 return_ACPI_STATUS (AE_OK);
422 * Now we can add this information to the GpeEventInfo block
423 * for use during dispatch of this GPE. Default type is RUNTIME, although
424 * this may change when the _PRW methods are executed later.
426 GpeEventInfo = &GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber];
428 GpeEventInfo->Flags = (UINT8) (Type | ACPI_GPE_DISPATCH_METHOD |
429 ACPI_GPE_TYPE_RUNTIME);
431 GpeEventInfo->Dispatch.MethodNode = (ACPI_NAMESPACE_NODE *) ObjHandle;
433 /* Update enable mask, but don't enable the HW GPE as of yet */
435 Status = AcpiEvEnableGpe (GpeEventInfo, FALSE);
437 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
438 "Registered GPE method %s as GPE number 0x%.2X\n",
440 return_ACPI_STATUS (Status);
444 /*******************************************************************************
446 * FUNCTION: AcpiEvMatchPrwAndGpe
448 * PARAMETERS: Callback from WalkNamespace
450 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
451 * not aborted on a single _PRW failure.
453 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
454 * Device. Run the _PRW method. If present, extract the GPE
455 * number and mark the GPE as a WAKE GPE.
457 ******************************************************************************/
460 AcpiEvMatchPrwAndGpe (
461 ACPI_HANDLE ObjHandle,
466 ACPI_GPE_WALK_INFO *GpeInfo = (void *) Info;
467 ACPI_NAMESPACE_NODE *GpeDevice;
468 ACPI_GPE_BLOCK_INFO *GpeBlock;
469 ACPI_NAMESPACE_NODE *TargetGpeDevice;
470 ACPI_GPE_EVENT_INFO *GpeEventInfo;
471 ACPI_OPERAND_OBJECT *PkgDesc;
472 ACPI_OPERAND_OBJECT *ObjDesc;
477 ACPI_FUNCTION_TRACE ("EvMatchPrwAndGpe");
480 /* Check for a _PRW method under this device */
482 Status = AcpiUtEvaluateObject (ObjHandle, METHOD_NAME__PRW,
483 ACPI_BTYPE_PACKAGE, &PkgDesc);
484 if (ACPI_FAILURE (Status))
486 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
488 return_ACPI_STATUS (AE_OK);
491 /* The returned _PRW package must have at least two elements */
493 if (PkgDesc->Package.Count < 2)
498 /* Extract pointers from the input context */
500 GpeDevice = GpeInfo->GpeDevice;
501 GpeBlock = GpeInfo->GpeBlock;
504 * The _PRW object must return a package, we are only interested
505 * in the first element
507 ObjDesc = PkgDesc->Package.Elements[0];
509 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
511 /* Use FADT-defined GPE device (from definition of _PRW) */
513 TargetGpeDevice = AcpiGbl_FadtGpeDevice;
515 /* Integer is the GPE number in the FADT described GPE blocks */
517 GpeNumber = (UINT32) ObjDesc->Integer.Value;
519 else if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
521 /* Package contains a GPE reference and GPE number within a GPE block */
523 if ((ObjDesc->Package.Count < 2) ||
524 (ACPI_GET_OBJECT_TYPE (ObjDesc->Package.Elements[0]) != ACPI_TYPE_LOCAL_REFERENCE) ||
525 (ACPI_GET_OBJECT_TYPE (ObjDesc->Package.Elements[1]) != ACPI_TYPE_INTEGER))
530 /* Get GPE block reference and decode */
532 TargetGpeDevice = ObjDesc->Package.Elements[0]->Reference.Node;
533 GpeNumber = (UINT32) ObjDesc->Package.Elements[1]->Integer.Value;
537 /* Unknown type, just ignore it */
543 * Is this GPE within this block?
545 * TRUE iff these conditions are true:
546 * 1) The GPE devices match.
547 * 2) The GPE index(number) is within the range of the Gpe Block
548 * associated with the GPE device.
550 if ((GpeDevice == TargetGpeDevice) &&
551 (GpeNumber >= GpeBlock->BlockBaseNumber) &&
552 (GpeNumber < GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8)))
554 GpeEventInfo = &GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber];
556 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
558 GpeEventInfo->Flags &= ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
559 Status = AcpiEvSetGpeType (GpeEventInfo, ACPI_GPE_TYPE_WAKE);
560 if (ACPI_FAILURE (Status))
564 Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_DISABLE);
568 AcpiUtRemoveReference (PkgDesc);
569 return_ACPI_STATUS (AE_OK);
573 /*******************************************************************************
575 * FUNCTION: AcpiEvGetGpeXruptBlock
577 * PARAMETERS: InterruptNumber - Interrupt for a GPE block
579 * RETURN: A GPE interrupt block
581 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
582 * block per unique interrupt level used for GPEs.
583 * Should be called only when the GPE lists are semaphore locked
584 * and not subject to change.
586 ******************************************************************************/
588 static ACPI_GPE_XRUPT_INFO *
589 AcpiEvGetGpeXruptBlock (
590 UINT32 InterruptNumber)
592 ACPI_GPE_XRUPT_INFO *NextGpeXrupt;
593 ACPI_GPE_XRUPT_INFO *GpeXrupt;
595 ACPI_NATIVE_UINT Flags;
598 ACPI_FUNCTION_TRACE ("EvGetGpeXruptBlock");
601 /* No need for lock since we are not changing any list elements here */
603 NextGpeXrupt = AcpiGbl_GpeXruptListHead;
606 if (NextGpeXrupt->InterruptNumber == InterruptNumber)
608 return_PTR (NextGpeXrupt);
611 NextGpeXrupt = NextGpeXrupt->Next;
614 /* Not found, must allocate a new xrupt descriptor */
616 GpeXrupt = ACPI_MEM_CALLOCATE (sizeof (ACPI_GPE_XRUPT_INFO));
622 GpeXrupt->InterruptNumber = InterruptNumber;
624 /* Install new interrupt descriptor with spin lock */
626 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
627 if (AcpiGbl_GpeXruptListHead)
629 NextGpeXrupt = AcpiGbl_GpeXruptListHead;
630 while (NextGpeXrupt->Next)
632 NextGpeXrupt = NextGpeXrupt->Next;
635 NextGpeXrupt->Next = GpeXrupt;
636 GpeXrupt->Previous = NextGpeXrupt;
640 AcpiGbl_GpeXruptListHead = GpeXrupt;
642 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
644 /* Install new interrupt handler if not SCI_INT */
646 if (InterruptNumber != AcpiGbl_FADT->SciInt)
648 Status = AcpiOsInstallInterruptHandler (InterruptNumber,
649 AcpiEvGpeXruptHandler, GpeXrupt);
650 if (ACPI_FAILURE (Status))
652 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
653 "Could not install GPE interrupt handler at level 0x%X\n",
659 return_PTR (GpeXrupt);
663 /*******************************************************************************
665 * FUNCTION: AcpiEvDeleteGpeXrupt
667 * PARAMETERS: GpeXrupt - A GPE interrupt info block
671 * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated
672 * interrupt handler if not the SCI interrupt.
674 ******************************************************************************/
677 AcpiEvDeleteGpeXrupt (
678 ACPI_GPE_XRUPT_INFO *GpeXrupt)
681 ACPI_NATIVE_UINT Flags;
684 ACPI_FUNCTION_TRACE ("EvDeleteGpeXrupt");
687 /* We never want to remove the SCI interrupt handler */
689 if (GpeXrupt->InterruptNumber == AcpiGbl_FADT->SciInt)
691 GpeXrupt->GpeBlockListHead = NULL;
692 return_ACPI_STATUS (AE_OK);
695 /* Disable this interrupt */
697 Status = AcpiOsRemoveInterruptHandler (GpeXrupt->InterruptNumber,
698 AcpiEvGpeXruptHandler);
699 if (ACPI_FAILURE (Status))
701 return_ACPI_STATUS (Status);
704 /* Unlink the interrupt block with lock */
706 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
707 if (GpeXrupt->Previous)
709 GpeXrupt->Previous->Next = GpeXrupt->Next;
714 GpeXrupt->Next->Previous = GpeXrupt->Previous;
716 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
720 ACPI_MEM_FREE (GpeXrupt);
721 return_ACPI_STATUS (AE_OK);
725 /*******************************************************************************
727 * FUNCTION: AcpiEvInstallGpeBlock
729 * PARAMETERS: GpeBlock - New GPE block
730 * InterruptNumber - Xrupt to be associated with this GPE block
734 * DESCRIPTION: Install new GPE block with mutex support
736 ******************************************************************************/
739 AcpiEvInstallGpeBlock (
740 ACPI_GPE_BLOCK_INFO *GpeBlock,
741 UINT32 InterruptNumber)
743 ACPI_GPE_BLOCK_INFO *NextGpeBlock;
744 ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
746 ACPI_NATIVE_UINT Flags;
749 ACPI_FUNCTION_TRACE ("EvInstallGpeBlock");
752 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
753 if (ACPI_FAILURE (Status))
755 return_ACPI_STATUS (Status);
758 GpeXruptBlock = AcpiEvGetGpeXruptBlock (InterruptNumber);
761 Status = AE_NO_MEMORY;
765 /* Install the new block at the end of the list with lock */
767 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
768 if (GpeXruptBlock->GpeBlockListHead)
770 NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
771 while (NextGpeBlock->Next)
773 NextGpeBlock = NextGpeBlock->Next;
776 NextGpeBlock->Next = GpeBlock;
777 GpeBlock->Previous = NextGpeBlock;
781 GpeXruptBlock->GpeBlockListHead = GpeBlock;
784 GpeBlock->XruptBlock = GpeXruptBlock;
785 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
788 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
789 return_ACPI_STATUS (Status);
793 /*******************************************************************************
795 * FUNCTION: AcpiEvDeleteGpeBlock
797 * PARAMETERS: GpeBlock - Existing GPE block
801 * DESCRIPTION: Remove a GPE block
803 ******************************************************************************/
806 AcpiEvDeleteGpeBlock (
807 ACPI_GPE_BLOCK_INFO *GpeBlock)
810 ACPI_NATIVE_UINT Flags;
813 ACPI_FUNCTION_TRACE ("EvInstallGpeBlock");
816 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
817 if (ACPI_FAILURE (Status))
819 return_ACPI_STATUS (Status);
822 /* Disable all GPEs in this block */
824 Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock);
826 if (!GpeBlock->Previous && !GpeBlock->Next)
828 /* This is the last GpeBlock on this interrupt */
830 Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
831 if (ACPI_FAILURE (Status))
838 /* Remove the block on this interrupt with lock */
840 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
841 if (GpeBlock->Previous)
843 GpeBlock->Previous->Next = GpeBlock->Next;
847 GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
852 GpeBlock->Next->Previous = GpeBlock->Previous;
854 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
857 /* Free the GpeBlock */
859 ACPI_MEM_FREE (GpeBlock->RegisterInfo);
860 ACPI_MEM_FREE (GpeBlock->EventInfo);
861 ACPI_MEM_FREE (GpeBlock);
864 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
865 return_ACPI_STATUS (Status);
869 /*******************************************************************************
871 * FUNCTION: AcpiEvCreateGpeInfoBlocks
873 * PARAMETERS: GpeBlock - New GPE block
877 * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
879 ******************************************************************************/
882 AcpiEvCreateGpeInfoBlocks (
883 ACPI_GPE_BLOCK_INFO *GpeBlock)
885 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo = NULL;
886 ACPI_GPE_EVENT_INFO *GpeEventInfo = NULL;
887 ACPI_GPE_EVENT_INFO *ThisEvent;
888 ACPI_GPE_REGISTER_INFO *ThisRegister;
894 ACPI_FUNCTION_TRACE ("EvCreateGpeInfoBlocks");
897 /* Allocate the GPE register information block */
899 GpeRegisterInfo = ACPI_MEM_CALLOCATE (
900 (ACPI_SIZE) GpeBlock->RegisterCount *
901 sizeof (ACPI_GPE_REGISTER_INFO));
902 if (!GpeRegisterInfo)
904 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
905 "Could not allocate the GpeRegisterInfo table\n"));
906 return_ACPI_STATUS (AE_NO_MEMORY);
910 * Allocate the GPE EventInfo block. There are eight distinct GPEs
911 * per register. Initialization to zeros is sufficient.
913 GpeEventInfo = ACPI_MEM_CALLOCATE (
914 ((ACPI_SIZE) GpeBlock->RegisterCount *
915 ACPI_GPE_REGISTER_WIDTH) *
916 sizeof (ACPI_GPE_EVENT_INFO));
919 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
920 "Could not allocate the GpeEventInfo table\n"));
921 Status = AE_NO_MEMORY;
925 /* Save the new Info arrays in the GPE block */
927 GpeBlock->RegisterInfo = GpeRegisterInfo;
928 GpeBlock->EventInfo = GpeEventInfo;
931 * Initialize the GPE Register and Event structures. A goal of these
932 * tables is to hide the fact that there are two separate GPE register sets
933 * in a given gpe hardware block, the status registers occupy the first half,
934 * and the enable registers occupy the second half.
936 ThisRegister = GpeRegisterInfo;
937 ThisEvent = GpeEventInfo;
939 for (i = 0; i < GpeBlock->RegisterCount; i++)
941 /* Init the RegisterInfo for this GPE register (8 GPEs) */
943 ThisRegister->BaseGpeNumber = (UINT8) (GpeBlock->BlockBaseNumber +
944 (i * ACPI_GPE_REGISTER_WIDTH));
946 ACPI_STORE_ADDRESS (ThisRegister->StatusAddress.Address,
947 (ACPI_GET_ADDRESS (GpeBlock->BlockAddress.Address)
950 ACPI_STORE_ADDRESS (ThisRegister->EnableAddress.Address,
951 (ACPI_GET_ADDRESS (GpeBlock->BlockAddress.Address)
953 + GpeBlock->RegisterCount));
955 ThisRegister->StatusAddress.AddressSpaceId = GpeBlock->BlockAddress.AddressSpaceId;
956 ThisRegister->EnableAddress.AddressSpaceId = GpeBlock->BlockAddress.AddressSpaceId;
957 ThisRegister->StatusAddress.RegisterBitWidth = ACPI_GPE_REGISTER_WIDTH;
958 ThisRegister->EnableAddress.RegisterBitWidth = ACPI_GPE_REGISTER_WIDTH;
959 ThisRegister->StatusAddress.RegisterBitOffset = ACPI_GPE_REGISTER_WIDTH;
960 ThisRegister->EnableAddress.RegisterBitOffset = ACPI_GPE_REGISTER_WIDTH;
962 /* Init the EventInfo for each GPE within this register */
964 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
966 ThisEvent->RegisterBit = AcpiGbl_DecodeTo8bit[j];
967 ThisEvent->RegisterInfo = ThisRegister;
972 * Clear the status/enable registers. Note that status registers
973 * are cleared by writing a '1', while enable registers are cleared
976 Status = AcpiHwLowLevelWrite (ACPI_GPE_REGISTER_WIDTH, 0x00,
977 &ThisRegister->EnableAddress);
978 if (ACPI_FAILURE (Status))
983 Status = AcpiHwLowLevelWrite (ACPI_GPE_REGISTER_WIDTH, 0xFF,
984 &ThisRegister->StatusAddress);
985 if (ACPI_FAILURE (Status))
993 return_ACPI_STATUS (AE_OK);
999 ACPI_MEM_FREE (GpeRegisterInfo);
1003 ACPI_MEM_FREE (GpeEventInfo);
1006 return_ACPI_STATUS (Status);
1010 /*******************************************************************************
1012 * FUNCTION: AcpiEvCreateGpeBlock
1014 * PARAMETERS: GpeDevice - Handle to the parent GPE block
1015 * GpeBlockAddress - Address and SpaceID
1016 * RegisterCount - Number of GPE register pairs in the block
1017 * GpeBlockBaseNumber - Starting GPE number for the block
1018 * InterruptNumber - H/W interrupt for the block
1019 * ReturnGpeBlock - Where the new block descriptor is returned
1023 * DESCRIPTION: Create and Install a block of GPE registers
1025 ******************************************************************************/
1028 AcpiEvCreateGpeBlock (
1029 ACPI_NAMESPACE_NODE *GpeDevice,
1030 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
1031 UINT32 RegisterCount,
1032 UINT8 GpeBlockBaseNumber,
1033 UINT32 InterruptNumber,
1034 ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
1036 ACPI_GPE_BLOCK_INFO *GpeBlock;
1037 ACPI_GPE_EVENT_INFO *GpeEventInfo;
1040 UINT32 WakeGpeCount;
1041 UINT32 GpeEnabledCount;
1043 ACPI_GPE_WALK_INFO GpeInfo;
1046 ACPI_FUNCTION_TRACE ("EvCreateGpeBlock");
1051 return_ACPI_STATUS (AE_OK);
1054 /* Allocate a new GPE block */
1056 GpeBlock = ACPI_MEM_CALLOCATE (sizeof (ACPI_GPE_BLOCK_INFO));
1059 return_ACPI_STATUS (AE_NO_MEMORY);
1062 /* Initialize the new GPE block */
1064 GpeBlock->RegisterCount = RegisterCount;
1065 GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
1066 GpeBlock->Node = GpeDevice;
1068 ACPI_MEMCPY (&GpeBlock->BlockAddress, GpeBlockAddress,
1069 sizeof (ACPI_GENERIC_ADDRESS));
1071 /* Create the RegisterInfo and EventInfo sub-structures */
1073 Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
1074 if (ACPI_FAILURE (Status))
1076 ACPI_MEM_FREE (GpeBlock);
1077 return_ACPI_STATUS (Status);
1080 /* Install the new block in the global list(s) */
1082 Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
1083 if (ACPI_FAILURE (Status))
1085 ACPI_MEM_FREE (GpeBlock);
1086 return_ACPI_STATUS (Status);
1089 /* Find all GPE methods (_Lxx, _Exx) for this block */
1091 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
1092 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, AcpiEvSaveMethodInfo,
1096 * Runtime option: Should Wake GPEs be enabled at runtime? The default
1097 * is No,they should only be enabled just as the machine goes to sleep.
1099 if (AcpiGbl_LeaveWakeGpesDisabled)
1102 * Differentiate RUNTIME vs WAKE GPEs, via the _PRW control methods.
1103 * (Each GPE that has one or more _PRWs that reference it is by
1104 * definition a WAKE GPE and will not be enabled while the machine
1107 GpeInfo.GpeBlock = GpeBlock;
1108 GpeInfo.GpeDevice = GpeDevice;
1110 Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1111 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, AcpiEvMatchPrwAndGpe,
1116 * Enable all GPEs in this block that are 1) "runtime" or "run/wake" GPEs,
1117 * and 2) have a corresponding _Lxx or _Exx method. All other GPEs must
1118 * be enabled via the AcpiEnableGpe() external interface.
1121 GpeEnabledCount = 0;
1123 for (i = 0; i < GpeBlock->RegisterCount; i++)
1125 for (j = 0; j < 8; j++)
1127 /* Get the info block for this particular GPE */
1129 GpeEventInfo = &GpeBlock->EventInfo[(i * ACPI_GPE_REGISTER_WIDTH) + j];
1131 if (((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_METHOD) &&
1132 (GpeEventInfo->Flags & ACPI_GPE_TYPE_RUNTIME))
1137 if (GpeEventInfo->Flags & ACPI_GPE_TYPE_WAKE)
1144 /* Dump info about this GPE block */
1146 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1147 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
1148 (UINT32) GpeBlock->BlockBaseNumber,
1149 (UINT32) (GpeBlock->BlockBaseNumber +
1150 ((GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH) -1)),
1151 GpeDevice->Name.Ascii,
1152 GpeBlock->RegisterCount,
1155 /* Enable all valid GPEs found above */
1157 Status = AcpiHwEnableRuntimeGpeBlock (NULL, GpeBlock);
1159 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1160 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1161 WakeGpeCount, GpeEnabledCount));
1163 /* Return the new block */
1167 (*ReturnGpeBlock) = GpeBlock;
1170 return_ACPI_STATUS (AE_OK);
1174 /*******************************************************************************
1176 * FUNCTION: AcpiEvGpeInitialize
1182 * DESCRIPTION: Initialize the GPE data structures
1184 ******************************************************************************/
1187 AcpiEvGpeInitialize (
1190 UINT32 RegisterCount0 = 0;
1191 UINT32 RegisterCount1 = 0;
1192 UINT32 GpeNumberMax = 0;
1196 ACPI_FUNCTION_TRACE ("EvGpeInitialize");
1199 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1200 if (ACPI_FAILURE (Status))
1202 return_ACPI_STATUS (Status);
1206 * Initialize the GPE Block(s) defined in the FADT
1208 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1209 * section "General-Purpose Event Registers", we have:
1211 * "Each register block contains two registers of equal length
1212 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1213 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1214 * The length of the GPE1_STS and GPE1_EN registers is equal to
1215 * half the GPE1_LEN. If a generic register block is not supported
1216 * then its respective block pointer and block length values in the
1217 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1218 * to be the same size."
1222 * Determine the maximum GPE number for this machine.
1224 * Note: both GPE0 and GPE1 are optional, and either can exist without
1227 * If EITHER the register length OR the block address are zero, then that
1228 * particular block is not supported.
1230 if (AcpiGbl_FADT->Gpe0BlkLen &&
1231 ACPI_GET_ADDRESS (AcpiGbl_FADT->XGpe0Blk.Address))
1233 /* GPE block 0 exists (has both length and address > 0) */
1235 RegisterCount0 = (UINT16) (AcpiGbl_FADT->Gpe0BlkLen / 2);
1237 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1239 /* Install GPE Block 0 */
1241 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
1242 &AcpiGbl_FADT->XGpe0Blk, RegisterCount0, 0,
1243 AcpiGbl_FADT->SciInt, &AcpiGbl_GpeFadtBlocks[0]);
1245 if (ACPI_FAILURE (Status))
1247 ACPI_REPORT_ERROR ((
1248 "Could not create GPE Block 0, %s\n",
1249 AcpiFormatException (Status)));
1253 if (AcpiGbl_FADT->Gpe1BlkLen &&
1254 ACPI_GET_ADDRESS (AcpiGbl_FADT->XGpe1Blk.Address))
1256 /* GPE block 1 exists (has both length and address > 0) */
1258 RegisterCount1 = (UINT16) (AcpiGbl_FADT->Gpe1BlkLen / 2);
1260 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1262 if ((RegisterCount0) &&
1263 (GpeNumberMax >= AcpiGbl_FADT->Gpe1Base))
1265 ACPI_REPORT_ERROR ((
1266 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n",
1267 GpeNumberMax, AcpiGbl_FADT->Gpe1Base,
1268 AcpiGbl_FADT->Gpe1Base +
1269 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
1271 /* Ignore GPE1 block by setting the register count to zero */
1277 /* Install GPE Block 1 */
1279 Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
1280 &AcpiGbl_FADT->XGpe1Blk, RegisterCount1,
1281 AcpiGbl_FADT->Gpe1Base,
1282 AcpiGbl_FADT->SciInt, &AcpiGbl_GpeFadtBlocks[1]);
1284 if (ACPI_FAILURE (Status))
1286 ACPI_REPORT_ERROR ((
1287 "Could not create GPE Block 1, %s\n",
1288 AcpiFormatException (Status)));
1292 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1293 * space. However, GPE0 always starts at GPE number zero.
1295 GpeNumberMax = AcpiGbl_FADT->Gpe1Base +
1296 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1300 /* Exit if there are no GPE registers */
1302 if ((RegisterCount0 + RegisterCount1) == 0)
1304 /* GPEs are not required by ACPI, this is OK */
1306 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
1307 "There are no GPE blocks defined in the FADT\n"));
1312 /* Check for Max GPE number out-of-range */
1314 if (GpeNumberMax > ACPI_GPE_MAX)
1316 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
1318 Status = AE_BAD_VALUE;
1323 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1324 return_ACPI_STATUS (AE_OK);