1 /******************************************************************************
3 * Module Name: evgpeblk - GPE block creation and initialization.
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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 *****************************************************************************/
118 #include "acevents.h"
119 #include "acnamesp.h"
121 #define _COMPONENT ACPI_EVENTS
122 ACPI_MODULE_NAME ("evgpeblk")
125 /*******************************************************************************
127 * FUNCTION: AcpiEvValidGpeEvent
129 * PARAMETERS: GpeEventInfo - Info for this GPE
131 * RETURN: TRUE if the GpeEvent is valid
133 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
134 * Should be called only when the GPE lists are semaphore locked
135 * and not subject to change.
137 ******************************************************************************/
140 AcpiEvValidGpeEvent (
141 ACPI_GPE_EVENT_INFO *GpeEventInfo)
143 ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
144 ACPI_GPE_BLOCK_INFO *GpeBlock;
147 ACPI_FUNCTION_ENTRY ();
150 /* No need for spin lock since we are not changing any list elements */
152 /* Walk the GPE interrupt levels */
154 GpeXruptBlock = AcpiGbl_GpeXruptListHead;
155 while (GpeXruptBlock)
157 GpeBlock = GpeXruptBlock->GpeBlockListHead;
159 /* Walk the GPE blocks on this interrupt level */
163 if ((&GpeBlock->EventInfo[0] <= GpeEventInfo) &&
164 (&GpeBlock->EventInfo[((ACPI_SIZE) GpeBlock->RegisterCount) * 8] > GpeEventInfo))
169 GpeBlock = GpeBlock->Next;
172 GpeXruptBlock = GpeXruptBlock->Next;
179 /*******************************************************************************
181 * FUNCTION: AcpiEvWalkGpeList
183 * PARAMETERS: GpeWalkCallback - Routine called for each GPE block
187 * DESCRIPTION: Walk the GPE lists.
188 * FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
190 ******************************************************************************/
194 ACPI_GPE_CALLBACK GpeWalkCallback)
196 ACPI_GPE_BLOCK_INFO *GpeBlock;
197 ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
198 ACPI_STATUS Status = AE_OK;
201 ACPI_FUNCTION_TRACE ("EvWalkGpeList");
204 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_ISR);
206 /* Walk the interrupt level descriptor list */
208 GpeXruptInfo = AcpiGbl_GpeXruptListHead;
211 /* Walk all Gpe Blocks attached to this interrupt level */
213 GpeBlock = GpeXruptInfo->GpeBlockListHead;
216 /* One callback per GPE block */
218 Status = GpeWalkCallback (GpeXruptInfo, GpeBlock);
219 if (ACPI_FAILURE (Status))
224 GpeBlock = GpeBlock->Next;
227 GpeXruptInfo = GpeXruptInfo->Next;
231 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_ISR);
232 return_ACPI_STATUS (Status);
236 /*******************************************************************************
238 * FUNCTION: AcpiEvSaveMethodInfo
240 * PARAMETERS: Callback from WalkNamespace
244 * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
245 * control method under the _GPE portion of the namespace.
246 * Extract the name and GPE type from the object, saving this
247 * information for quick lookup during GPE dispatch
249 * The name of each GPE control method is of the form:
252 * L - means that the GPE is level triggered
253 * E - means that the GPE is edge triggered
254 * nn - is the GPE number [in HEX]
256 ******************************************************************************/
259 AcpiEvSaveMethodInfo (
260 ACPI_HANDLE ObjHandle,
265 ACPI_GPE_BLOCK_INFO *GpeBlock = (void *) ObjDesc;
266 ACPI_GPE_EVENT_INFO *GpeEventInfo;
268 char Name[ACPI_NAME_SIZE + 1];
273 ACPI_FUNCTION_TRACE ("EvSaveMethodInfo");
276 /* Extract the name from the object and convert to a string */
278 ACPI_MOVE_32_TO_32 (Name,
279 &((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Integer);
280 Name[ACPI_NAME_SIZE] = 0;
283 * Edge/Level determination is based on the 2nd character
289 Type = ACPI_EVENT_LEVEL_TRIGGERED;
293 Type = ACPI_EVENT_EDGE_TRIGGERED;
297 /* Unknown method type, just ignore it! */
299 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
300 "Unknown GPE method type: %s (name not of form _Lnn or _Enn)\n",
302 return_ACPI_STATUS (AE_OK);
305 /* Convert the last two characters of the name to the GPE Number */
307 GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
308 if (GpeNumber == ACPI_UINT32_MAX)
310 /* Conversion failed; invalid method, just ignore it */
312 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
313 "Could not extract GPE number from name: %s (name is not of form _Lnn or _Enn)\n",
315 return_ACPI_STATUS (AE_OK);
318 /* Ensure that we have a valid GPE number for this GPE block */
320 if ((GpeNumber < GpeBlock->BlockBaseNumber) ||
321 (GpeNumber >= (GpeBlock->BlockBaseNumber + (GpeBlock->RegisterCount * 8))))
324 * Not valid for this GPE block, just ignore it
325 * However, it may be valid for a different GPE block, since GPE0 and GPE1
326 * methods both appear under \_GPE.
328 return_ACPI_STATUS (AE_OK);
332 * Now we can add this information to the GpeEventInfo block
333 * for use during dispatch of this GPE.
335 GpeEventInfo = &GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber];
337 GpeEventInfo->Flags = Type;
338 GpeEventInfo->MethodNode = (ACPI_NAMESPACE_NODE *) ObjHandle;
340 /* Enable the GPE (SCIs should be disabled at this point) */
342 Status = AcpiHwEnableGpe (GpeEventInfo);
343 if (ACPI_FAILURE (Status))
345 return_ACPI_STATUS (Status);
348 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
349 "Registered GPE method %s as GPE number 0x%.2X\n",
351 return_ACPI_STATUS (AE_OK);
355 /*******************************************************************************
357 * FUNCTION: AcpiEvGetGpeXruptBlock
359 * PARAMETERS: InterruptLevel - Interrupt for a GPE block
361 * RETURN: A GPE interrupt block
363 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
364 * block per unique interrupt level used for GPEs.
365 * Should be called only when the GPE lists are semaphore locked
366 * and not subject to change.
368 ******************************************************************************/
370 static ACPI_GPE_XRUPT_INFO *
371 AcpiEvGetGpeXruptBlock (
372 UINT32 InterruptLevel)
374 ACPI_GPE_XRUPT_INFO *NextGpeXrupt;
375 ACPI_GPE_XRUPT_INFO *GpeXrupt;
379 ACPI_FUNCTION_TRACE ("EvGetGpeXruptBlock");
382 /* No need for spin lock since we are not changing any list elements here */
384 NextGpeXrupt = AcpiGbl_GpeXruptListHead;
387 if (NextGpeXrupt->InterruptLevel == InterruptLevel)
389 return_PTR (NextGpeXrupt);
392 NextGpeXrupt = NextGpeXrupt->Next;
395 /* Not found, must allocate a new xrupt descriptor */
397 GpeXrupt = ACPI_MEM_CALLOCATE (sizeof (ACPI_GPE_XRUPT_INFO));
403 GpeXrupt->InterruptLevel = InterruptLevel;
405 /* Install new interrupt descriptor with spin lock */
407 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
408 if (AcpiGbl_GpeXruptListHead)
410 NextGpeXrupt = AcpiGbl_GpeXruptListHead;
411 while (NextGpeXrupt->Next)
413 NextGpeXrupt = NextGpeXrupt->Next;
416 NextGpeXrupt->Next = GpeXrupt;
417 GpeXrupt->Previous = NextGpeXrupt;
421 AcpiGbl_GpeXruptListHead = GpeXrupt;
423 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
425 /* Install new interrupt handler if not SCI_INT */
427 if (InterruptLevel != AcpiGbl_FADT->SciInt)
429 Status = AcpiOsInstallInterruptHandler (InterruptLevel,
430 AcpiEvGpeXruptHandler, GpeXrupt);
431 if (ACPI_FAILURE (Status))
433 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
434 "Could not install GPE interrupt handler at level 0x%X\n",
440 return_PTR (GpeXrupt);
444 /*******************************************************************************
446 * FUNCTION: AcpiEvDeleteGpeXrupt
448 * PARAMETERS: GpeXrupt - A GPE interrupt info block
452 * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated
453 * interrupt handler if not the SCI interrupt.
455 ******************************************************************************/
458 AcpiEvDeleteGpeXrupt (
459 ACPI_GPE_XRUPT_INFO *GpeXrupt)
464 ACPI_FUNCTION_TRACE ("EvDeleteGpeXrupt");
467 /* We never want to remove the SCI interrupt handler */
469 if (GpeXrupt->InterruptLevel == AcpiGbl_FADT->SciInt)
471 GpeXrupt->GpeBlockListHead = NULL;
472 return_ACPI_STATUS (AE_OK);
475 /* Disable this interrupt */
477 Status = AcpiOsRemoveInterruptHandler (GpeXrupt->InterruptLevel,
478 AcpiEvGpeXruptHandler);
479 if (ACPI_FAILURE (Status))
481 return_ACPI_STATUS (Status);
484 /* Unlink the interrupt block with lock */
486 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
487 if (GpeXrupt->Previous)
489 GpeXrupt->Previous->Next = GpeXrupt->Next;
494 GpeXrupt->Next->Previous = GpeXrupt->Previous;
496 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
500 ACPI_MEM_FREE (GpeXrupt);
501 return_ACPI_STATUS (AE_OK);
505 /*******************************************************************************
507 * FUNCTION: AcpiEvInstallGpeBlock
509 * PARAMETERS: GpeBlock - New GPE block
510 * InterruptLevel - Level to be associated with this GPE block
514 * DESCRIPTION: Install new GPE block with mutex support
516 ******************************************************************************/
519 AcpiEvInstallGpeBlock (
520 ACPI_GPE_BLOCK_INFO *GpeBlock,
521 UINT32 InterruptLevel)
523 ACPI_GPE_BLOCK_INFO *NextGpeBlock;
524 ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
528 ACPI_FUNCTION_TRACE ("EvInstallGpeBlock");
531 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
532 if (ACPI_FAILURE (Status))
534 return_ACPI_STATUS (Status);
537 GpeXruptBlock = AcpiEvGetGpeXruptBlock (InterruptLevel);
540 Status = AE_NO_MEMORY;
544 /* Install the new block at the end of the list for this interrupt with lock */
546 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
547 if (GpeXruptBlock->GpeBlockListHead)
549 NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
550 while (NextGpeBlock->Next)
552 NextGpeBlock = NextGpeBlock->Next;
555 NextGpeBlock->Next = GpeBlock;
556 GpeBlock->Previous = NextGpeBlock;
560 GpeXruptBlock->GpeBlockListHead = GpeBlock;
563 GpeBlock->XruptBlock = GpeXruptBlock;
564 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
567 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
568 return_ACPI_STATUS (Status);
572 /*******************************************************************************
574 * FUNCTION: AcpiEvDeleteGpeBlock
576 * PARAMETERS: GpeBlock - Existing GPE block
580 * DESCRIPTION: Remove a GPE block
582 ******************************************************************************/
585 AcpiEvDeleteGpeBlock (
586 ACPI_GPE_BLOCK_INFO *GpeBlock)
591 ACPI_FUNCTION_TRACE ("EvInstallGpeBlock");
594 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
595 if (ACPI_FAILURE (Status))
597 return_ACPI_STATUS (Status);
600 /* Disable all GPEs in this block */
602 Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock);
604 if (!GpeBlock->Previous && !GpeBlock->Next)
606 /* This is the last GpeBlock on this interrupt */
608 Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
609 if (ACPI_FAILURE (Status))
616 /* Remove the block on this interrupt with lock */
618 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
619 if (GpeBlock->Previous)
621 GpeBlock->Previous->Next = GpeBlock->Next;
625 GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
630 GpeBlock->Next->Previous = GpeBlock->Previous;
632 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
635 /* Free the GpeBlock */
637 ACPI_MEM_FREE (GpeBlock->RegisterInfo);
638 ACPI_MEM_FREE (GpeBlock->EventInfo);
639 ACPI_MEM_FREE (GpeBlock);
642 Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
643 return_ACPI_STATUS (Status);
647 /*******************************************************************************
649 * FUNCTION: AcpiEvCreateGpeInfoBlocks
651 * PARAMETERS: GpeBlock - New GPE block
655 * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
657 ******************************************************************************/
660 AcpiEvCreateGpeInfoBlocks (
661 ACPI_GPE_BLOCK_INFO *GpeBlock)
663 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo = NULL;
664 ACPI_GPE_EVENT_INFO *GpeEventInfo = NULL;
665 ACPI_GPE_EVENT_INFO *ThisEvent;
666 ACPI_GPE_REGISTER_INFO *ThisRegister;
672 ACPI_FUNCTION_TRACE ("EvCreateGpeInfoBlocks");
675 /* Allocate the GPE register information block */
677 GpeRegisterInfo = ACPI_MEM_CALLOCATE (
678 (ACPI_SIZE) GpeBlock->RegisterCount *
679 sizeof (ACPI_GPE_REGISTER_INFO));
680 if (!GpeRegisterInfo)
682 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
683 "Could not allocate the GpeRegisterInfo table\n"));
684 return_ACPI_STATUS (AE_NO_MEMORY);
688 * Allocate the GPE EventInfo block. There are eight distinct GPEs
689 * per register. Initialization to zeros is sufficient.
691 GpeEventInfo = ACPI_MEM_CALLOCATE (
692 ((ACPI_SIZE) GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH) *
693 sizeof (ACPI_GPE_EVENT_INFO));
696 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the GpeEventInfo table\n"));
697 Status = AE_NO_MEMORY;
701 /* Save the new Info arrays in the GPE block */
703 GpeBlock->RegisterInfo = GpeRegisterInfo;
704 GpeBlock->EventInfo = GpeEventInfo;
707 * Initialize the GPE Register and Event structures. A goal of these
708 * tables is to hide the fact that there are two separate GPE register sets
709 * in a given gpe hardware block, the status registers occupy the first half,
710 * and the enable registers occupy the second half.
712 ThisRegister = GpeRegisterInfo;
713 ThisEvent = GpeEventInfo;
715 for (i = 0; i < GpeBlock->RegisterCount; i++)
717 /* Init the RegisterInfo for this GPE register (8 GPEs) */
719 ThisRegister->BaseGpeNumber = (UINT8) (GpeBlock->BlockBaseNumber +
720 (i * ACPI_GPE_REGISTER_WIDTH));
722 ACPI_STORE_ADDRESS (ThisRegister->StatusAddress.Address,
723 (ACPI_GET_ADDRESS (GpeBlock->BlockAddress.Address)
726 ACPI_STORE_ADDRESS (ThisRegister->EnableAddress.Address,
727 (ACPI_GET_ADDRESS (GpeBlock->BlockAddress.Address)
729 + GpeBlock->RegisterCount));
731 ThisRegister->StatusAddress.AddressSpaceId = GpeBlock->BlockAddress.AddressSpaceId;
732 ThisRegister->EnableAddress.AddressSpaceId = GpeBlock->BlockAddress.AddressSpaceId;
733 ThisRegister->StatusAddress.RegisterBitWidth = ACPI_GPE_REGISTER_WIDTH;
734 ThisRegister->EnableAddress.RegisterBitWidth = ACPI_GPE_REGISTER_WIDTH;
735 ThisRegister->StatusAddress.RegisterBitOffset = ACPI_GPE_REGISTER_WIDTH;
736 ThisRegister->EnableAddress.RegisterBitOffset = ACPI_GPE_REGISTER_WIDTH;
738 /* Init the EventInfo for each GPE within this register */
740 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
742 ThisEvent->BitMask = AcpiGbl_DecodeTo8bit[j];
743 ThisEvent->RegisterInfo = ThisRegister;
748 * Clear the status/enable registers. Note that status registers
749 * are cleared by writing a '1', while enable registers are cleared
752 Status = AcpiHwLowLevelWrite (ACPI_GPE_REGISTER_WIDTH, 0x00,
753 &ThisRegister->EnableAddress);
754 if (ACPI_FAILURE (Status))
759 Status = AcpiHwLowLevelWrite (ACPI_GPE_REGISTER_WIDTH, 0xFF,
760 &ThisRegister->StatusAddress);
761 if (ACPI_FAILURE (Status))
769 return_ACPI_STATUS (AE_OK);
775 ACPI_MEM_FREE (GpeRegisterInfo);
779 ACPI_MEM_FREE (GpeEventInfo);
782 return_ACPI_STATUS (Status);
786 /*******************************************************************************
788 * FUNCTION: AcpiEvCreateGpeBlock
790 * PARAMETERS: GpeDevice - Handle to the parent GPE block
791 * GpeBlockAddress - Address and SpaceID
792 * RegisterCount - Number of GPE register pairs in the block
793 * GpeBlockBaseNumber - Starting GPE number for the block
794 * InterruptLevel - H/W interrupt for the block
795 * ReturnGpeBlock - Where the new block descriptor is returned
799 * DESCRIPTION: Create and Install a block of GPE registers
801 ******************************************************************************/
804 AcpiEvCreateGpeBlock (
805 ACPI_NAMESPACE_NODE *GpeDevice,
806 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
807 UINT32 RegisterCount,
808 UINT8 GpeBlockBaseNumber,
809 UINT32 InterruptLevel,
810 ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
812 ACPI_GPE_BLOCK_INFO *GpeBlock;
816 ACPI_FUNCTION_TRACE ("EvCreateGpeBlock");
821 return_ACPI_STATUS (AE_OK);
824 /* Allocate a new GPE block */
826 GpeBlock = ACPI_MEM_CALLOCATE (sizeof (ACPI_GPE_BLOCK_INFO));
829 return_ACPI_STATUS (AE_NO_MEMORY);
832 /* Initialize the new GPE block */
834 GpeBlock->RegisterCount = RegisterCount;
835 GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
837 ACPI_MEMCPY (&GpeBlock->BlockAddress, GpeBlockAddress, sizeof (ACPI_GENERIC_ADDRESS));
839 /* Create the RegisterInfo and EventInfo sub-structures */
841 Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
842 if (ACPI_FAILURE (Status))
844 ACPI_MEM_FREE (GpeBlock);
845 return_ACPI_STATUS (Status);
848 /* Install the new block in the global list(s) */
850 Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptLevel);
851 if (ACPI_FAILURE (Status))
853 ACPI_MEM_FREE (GpeBlock);
854 return_ACPI_STATUS (Status);
857 /* Dump info about this GPE block */
859 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "GPE %02d to %02d [%4.4s] %d regs at %8.8X%8.8X on int %d\n",
860 GpeBlock->BlockBaseNumber,
861 (UINT32) (GpeBlock->BlockBaseNumber +
862 ((GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH) -1)),
863 GpeDevice->Name.Ascii,
864 GpeBlock->RegisterCount,
865 ACPI_FORMAT_UINT64 (ACPI_GET_ADDRESS (GpeBlock->BlockAddress.Address)),
868 /* Find all GPE methods (_Lxx, _Exx) for this block */
870 Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
871 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK, AcpiEvSaveMethodInfo,
874 /* Return the new block */
878 (*ReturnGpeBlock) = GpeBlock;
881 return_ACPI_STATUS (AE_OK);
885 /*******************************************************************************
887 * FUNCTION: AcpiEvGpeInitialize
893 * DESCRIPTION: Initialize the GPE data structures
895 ******************************************************************************/
898 AcpiEvGpeInitialize (void)
900 UINT32 RegisterCount0 = 0;
901 UINT32 RegisterCount1 = 0;
902 UINT32 GpeNumberMax = 0;
903 ACPI_HANDLE GpeDevice;
907 ACPI_FUNCTION_TRACE ("EvGpeInitialize");
910 /* Get a handle to the predefined _GPE object */
912 Status = AcpiGetHandle (NULL, "\\_GPE", &GpeDevice);
913 if (ACPI_FAILURE (Status))
915 return_ACPI_STATUS (Status);
919 * Initialize the GPE Blocks defined in the FADT
921 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
922 * section "General-Purpose Event Registers", we have:
924 * "Each register block contains two registers of equal length
925 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
926 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
927 * The length of the GPE1_STS and GPE1_EN registers is equal to
928 * half the GPE1_LEN. If a generic register block is not supported
929 * then its respective block pointer and block length values in the
930 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
931 * to be the same size."
935 * Determine the maximum GPE number for this machine.
937 * Note: both GPE0 and GPE1 are optional, and either can exist without
940 * If EITHER the register length OR the block address are zero, then that
941 * particular block is not supported.
943 if (AcpiGbl_FADT->Gpe0BlkLen &&
944 ACPI_GET_ADDRESS (AcpiGbl_FADT->XGpe0Blk.Address))
946 /* GPE block 0 exists (has both length and address > 0) */
948 RegisterCount0 = (UINT16) (AcpiGbl_FADT->Gpe0BlkLen / 2);
950 GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
952 /* Install GPE Block 0 */
954 Status = AcpiEvCreateGpeBlock (GpeDevice, &AcpiGbl_FADT->XGpe0Blk,
955 RegisterCount0, 0, AcpiGbl_FADT->SciInt, &AcpiGbl_GpeFadtBlocks[0]);
956 if (ACPI_FAILURE (Status))
959 "Could not create GPE Block 0, %s\n",
960 AcpiFormatException (Status)));
964 if (AcpiGbl_FADT->Gpe1BlkLen &&
965 ACPI_GET_ADDRESS (AcpiGbl_FADT->XGpe1Blk.Address))
967 /* GPE block 1 exists (has both length and address > 0) */
969 RegisterCount1 = (UINT16) (AcpiGbl_FADT->Gpe1BlkLen / 2);
971 /* Check for GPE0/GPE1 overlap (if both banks exist) */
973 if ((RegisterCount0) &&
974 (GpeNumberMax >= AcpiGbl_FADT->Gpe1Base))
977 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1\n",
978 GpeNumberMax, AcpiGbl_FADT->Gpe1Base,
979 AcpiGbl_FADT->Gpe1Base +
980 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
982 /* Ignore GPE1 block by setting the register count to zero */
988 /* Install GPE Block 1 */
990 Status = AcpiEvCreateGpeBlock (GpeDevice, &AcpiGbl_FADT->XGpe1Blk,
991 RegisterCount1, AcpiGbl_FADT->Gpe1Base,
992 AcpiGbl_FADT->SciInt, &AcpiGbl_GpeFadtBlocks[1]);
993 if (ACPI_FAILURE (Status))
996 "Could not create GPE Block 1, %s\n",
997 AcpiFormatException (Status)));
1001 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1002 * space. However, GPE0 always starts at GPE number zero.
1004 GpeNumberMax = AcpiGbl_FADT->Gpe1Base +
1005 ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1009 /* Exit if there are no GPE registers */
1011 if ((RegisterCount0 + RegisterCount1) == 0)
1013 /* GPEs are not required by ACPI, this is OK */
1015 ACPI_REPORT_INFO (("There are no GPE blocks defined in the FADT\n"));
1016 return_ACPI_STATUS (AE_OK);
1019 /* Check for Max GPE number out-of-range */
1021 if (GpeNumberMax > ACPI_GPE_MAX)
1023 ACPI_REPORT_ERROR (("Maximum GPE number from FADT is too large: 0x%X\n",
1025 return_ACPI_STATUS (AE_BAD_VALUE);
1028 return_ACPI_STATUS (AE_OK);