13446Smrj /******************************************************************************
23446Smrj *
33446Smrj * Module Name: evgpeblk - GPE block creation and initialization.
43446Smrj *
53446Smrj *****************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
119980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj #include "acpi.h"
1179980SDana.Myers@Sun.COM #include "accommon.h"
1183446Smrj #include "acevents.h"
1193446Smrj #include "acnamesp.h"
1203446Smrj
1213446Smrj #define _COMPONENT ACPI_EVENTS
1223446Smrj ACPI_MODULE_NAME ("evgpeblk")
1233446Smrj
1243446Smrj /* Local prototypes */
1253446Smrj
1263446Smrj static ACPI_STATUS
1273446Smrj AcpiEvSaveMethodInfo (
1283446Smrj ACPI_HANDLE ObjHandle,
1293446Smrj UINT32 Level,
1303446Smrj void *ObjDesc,
1313446Smrj void **ReturnValue);
1323446Smrj
1333446Smrj static ACPI_STATUS
1343446Smrj AcpiEvMatchPrwAndGpe (
1353446Smrj ACPI_HANDLE ObjHandle,
1363446Smrj UINT32 Level,
1373446Smrj void *Info,
1383446Smrj void **ReturnValue);
1393446Smrj
1403446Smrj static ACPI_GPE_XRUPT_INFO *
1413446Smrj AcpiEvGetGpeXruptBlock (
1423446Smrj UINT32 InterruptNumber);
1433446Smrj
1443446Smrj static ACPI_STATUS
1453446Smrj AcpiEvDeleteGpeXrupt (
1463446Smrj ACPI_GPE_XRUPT_INFO *GpeXrupt);
1473446Smrj
1483446Smrj static ACPI_STATUS
1493446Smrj AcpiEvInstallGpeBlock (
1503446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock,
1513446Smrj UINT32 InterruptNumber);
1523446Smrj
1533446Smrj static ACPI_STATUS
1543446Smrj AcpiEvCreateGpeInfoBlocks (
1553446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock);
1563446Smrj
1573446Smrj
1583446Smrj /*******************************************************************************
1593446Smrj *
1603446Smrj * FUNCTION: AcpiEvValidGpeEvent
1613446Smrj *
1623446Smrj * PARAMETERS: GpeEventInfo - Info for this GPE
1633446Smrj *
1643446Smrj * RETURN: TRUE if the GpeEvent is valid
1653446Smrj *
1663446Smrj * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
1673446Smrj * Should be called only when the GPE lists are semaphore locked
1683446Smrj * and not subject to change.
1693446Smrj *
1703446Smrj ******************************************************************************/
1713446Smrj
1723446Smrj BOOLEAN
AcpiEvValidGpeEvent(ACPI_GPE_EVENT_INFO * GpeEventInfo)1733446Smrj AcpiEvValidGpeEvent (
1743446Smrj ACPI_GPE_EVENT_INFO *GpeEventInfo)
1753446Smrj {
1763446Smrj ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
1773446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock;
1783446Smrj
1793446Smrj
1803446Smrj ACPI_FUNCTION_ENTRY ();
1813446Smrj
1823446Smrj
1833446Smrj /* No need for spin lock since we are not changing any list elements */
1843446Smrj
1853446Smrj /* Walk the GPE interrupt levels */
1863446Smrj
1873446Smrj GpeXruptBlock = AcpiGbl_GpeXruptListHead;
1883446Smrj while (GpeXruptBlock)
1893446Smrj {
1903446Smrj GpeBlock = GpeXruptBlock->GpeBlockListHead;
1913446Smrj
1923446Smrj /* Walk the GPE blocks on this interrupt level */
1933446Smrj
1943446Smrj while (GpeBlock)
1953446Smrj {
1963446Smrj if ((&GpeBlock->EventInfo[0] <= GpeEventInfo) &&
1979980SDana.Myers@Sun.COM (&GpeBlock->EventInfo[((ACPI_SIZE)
1989980SDana.Myers@Sun.COM GpeBlock->RegisterCount) * 8] > GpeEventInfo))
1993446Smrj {
2003446Smrj return (TRUE);
2013446Smrj }
2023446Smrj
2033446Smrj GpeBlock = GpeBlock->Next;
2043446Smrj }
2053446Smrj
2063446Smrj GpeXruptBlock = GpeXruptBlock->Next;
2073446Smrj }
2083446Smrj
2093446Smrj return (FALSE);
2103446Smrj }
2113446Smrj
2123446Smrj
2133446Smrj /*******************************************************************************
2143446Smrj *
2153446Smrj * FUNCTION: AcpiEvWalkGpeList
2163446Smrj *
2173446Smrj * PARAMETERS: GpeWalkCallback - Routine called for each GPE block
2189980SDana.Myers@Sun.COM * Context - Value passed to callback
2193446Smrj *
2203446Smrj * RETURN: Status
2213446Smrj *
2223446Smrj * DESCRIPTION: Walk the GPE lists.
2233446Smrj *
2243446Smrj ******************************************************************************/
2253446Smrj
2263446Smrj ACPI_STATUS
AcpiEvWalkGpeList(ACPI_GPE_CALLBACK GpeWalkCallback,void * Context)2273446Smrj AcpiEvWalkGpeList (
2289980SDana.Myers@Sun.COM ACPI_GPE_CALLBACK GpeWalkCallback,
2299980SDana.Myers@Sun.COM void *Context)
2303446Smrj {
2313446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock;
2323446Smrj ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
2333446Smrj ACPI_STATUS Status = AE_OK;
2343446Smrj ACPI_CPU_FLAGS Flags;
2353446Smrj
2363446Smrj
2373446Smrj ACPI_FUNCTION_TRACE (EvWalkGpeList);
2383446Smrj
2393446Smrj
2403446Smrj Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
2413446Smrj
2423446Smrj /* Walk the interrupt level descriptor list */
2433446Smrj
2443446Smrj GpeXruptInfo = AcpiGbl_GpeXruptListHead;
2453446Smrj while (GpeXruptInfo)
2463446Smrj {
2473446Smrj /* Walk all Gpe Blocks attached to this interrupt level */
2483446Smrj
2493446Smrj GpeBlock = GpeXruptInfo->GpeBlockListHead;
2503446Smrj while (GpeBlock)
2513446Smrj {
2523446Smrj /* One callback per GPE block */
2533446Smrj
2549980SDana.Myers@Sun.COM Status = GpeWalkCallback (GpeXruptInfo, GpeBlock, Context);
2553446Smrj if (ACPI_FAILURE (Status))
2563446Smrj {
2579980SDana.Myers@Sun.COM if (Status == AE_CTRL_END) /* Callback abort */
2589980SDana.Myers@Sun.COM {
2599980SDana.Myers@Sun.COM Status = AE_OK;
2609980SDana.Myers@Sun.COM }
2613446Smrj goto UnlockAndExit;
2623446Smrj }
2633446Smrj
2643446Smrj GpeBlock = GpeBlock->Next;
2653446Smrj }
2663446Smrj
2673446Smrj GpeXruptInfo = GpeXruptInfo->Next;
2683446Smrj }
2693446Smrj
2703446Smrj UnlockAndExit:
2713446Smrj AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
2723446Smrj return_ACPI_STATUS (Status);
2733446Smrj }
2743446Smrj
2753446Smrj
2763446Smrj /*******************************************************************************
2773446Smrj *
2783446Smrj * FUNCTION: AcpiEvDeleteGpeHandlers
2793446Smrj *
2803446Smrj * PARAMETERS: GpeXruptInfo - GPE Interrupt info
2813446Smrj * GpeBlock - Gpe Block info
2823446Smrj *
2833446Smrj * RETURN: Status
2843446Smrj *
2853446Smrj * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
2863446Smrj * Used only prior to termination.
2873446Smrj *
2883446Smrj ******************************************************************************/
2893446Smrj
2903446Smrj ACPI_STATUS
AcpiEvDeleteGpeHandlers(ACPI_GPE_XRUPT_INFO * GpeXruptInfo,ACPI_GPE_BLOCK_INFO * GpeBlock,void * Context)2913446Smrj AcpiEvDeleteGpeHandlers (
2923446Smrj ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
2939980SDana.Myers@Sun.COM ACPI_GPE_BLOCK_INFO *GpeBlock,
2949980SDana.Myers@Sun.COM void *Context)
2953446Smrj {
2963446Smrj ACPI_GPE_EVENT_INFO *GpeEventInfo;
2977851SDana.Myers@Sun.COM UINT32 i;
2987851SDana.Myers@Sun.COM UINT32 j;
2993446Smrj
3003446Smrj
3013446Smrj ACPI_FUNCTION_TRACE (EvDeleteGpeHandlers);
3023446Smrj
3033446Smrj
3043446Smrj /* Examine each GPE Register within the block */
3053446Smrj
3063446Smrj for (i = 0; i < GpeBlock->RegisterCount; i++)
3073446Smrj {
3083446Smrj /* Now look at the individual GPEs in this byte register */
3093446Smrj
3103446Smrj for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
3113446Smrj {
3129980SDana.Myers@Sun.COM GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
3139980SDana.Myers@Sun.COM ACPI_GPE_REGISTER_WIDTH) + j];
3143446Smrj
3153446Smrj if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
3163446Smrj ACPI_GPE_DISPATCH_HANDLER)
3173446Smrj {
3183446Smrj ACPI_FREE (GpeEventInfo->Dispatch.Handler);
3193446Smrj GpeEventInfo->Dispatch.Handler = NULL;
3203446Smrj GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK;
3213446Smrj }
3223446Smrj }
3233446Smrj }
3243446Smrj
3253446Smrj return_ACPI_STATUS (AE_OK);
3263446Smrj }
3273446Smrj
3283446Smrj
3293446Smrj /*******************************************************************************
3303446Smrj *
3313446Smrj * FUNCTION: AcpiEvSaveMethodInfo
3323446Smrj *
3333446Smrj * PARAMETERS: Callback from WalkNamespace
3343446Smrj *
3353446Smrj * RETURN: Status
3363446Smrj *
3373446Smrj * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
3383446Smrj * control method under the _GPE portion of the namespace.
3393446Smrj * Extract the name and GPE type from the object, saving this
3403446Smrj * information for quick lookup during GPE dispatch
3413446Smrj *
3423446Smrj * The name of each GPE control method is of the form:
3433446Smrj * "_Lxx" or "_Exx"
3443446Smrj * Where:
3453446Smrj * L - means that the GPE is level triggered
3463446Smrj * E - means that the GPE is edge triggered
3473446Smrj * xx - is the GPE number [in HEX]
3483446Smrj *
3493446Smrj ******************************************************************************/
3503446Smrj
3513446Smrj static ACPI_STATUS
AcpiEvSaveMethodInfo(ACPI_HANDLE ObjHandle,UINT32 Level,void * ObjDesc,void ** ReturnValue)3523446Smrj AcpiEvSaveMethodInfo (
3533446Smrj ACPI_HANDLE ObjHandle,
3543446Smrj UINT32 Level,
3553446Smrj void *ObjDesc,
3563446Smrj void **ReturnValue)
3573446Smrj {
3583446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock = (void *) ObjDesc;
3593446Smrj ACPI_GPE_EVENT_INFO *GpeEventInfo;
3603446Smrj UINT32 GpeNumber;
3613446Smrj char Name[ACPI_NAME_SIZE + 1];
3623446Smrj UINT8 Type;
3633446Smrj ACPI_STATUS Status;
3643446Smrj
3653446Smrj
3663446Smrj ACPI_FUNCTION_TRACE (EvSaveMethodInfo);
3673446Smrj
3683446Smrj
3693446Smrj /*
3703446Smrj * _Lxx and _Exx GPE method support
3713446Smrj *
3723446Smrj * 1) Extract the name from the object and convert to a string
3733446Smrj */
3743446Smrj ACPI_MOVE_32_TO_32 (
3753446Smrj Name, &((ACPI_NAMESPACE_NODE *) ObjHandle)->Name.Integer);
3763446Smrj Name[ACPI_NAME_SIZE] = 0;
3773446Smrj
3783446Smrj /*
3793446Smrj * 2) Edge/Level determination is based on the 2nd character
3803446Smrj * of the method name
3813446Smrj *
3823446Smrj * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
3833446Smrj * if a _PRW object is found that points to this GPE.
3843446Smrj */
3853446Smrj switch (Name[1])
3863446Smrj {
3873446Smrj case 'L':
3883446Smrj Type = ACPI_GPE_LEVEL_TRIGGERED;
3893446Smrj break;
3903446Smrj
3913446Smrj case 'E':
3923446Smrj Type = ACPI_GPE_EDGE_TRIGGERED;
3933446Smrj break;
3943446Smrj
3953446Smrj default:
3963446Smrj /* Unknown method type, just ignore it! */
3973446Smrj
3983446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
3999980SDana.Myers@Sun.COM "Ignoring unknown GPE method type: %s "
4009980SDana.Myers@Sun.COM "(name not of form _Lxx or _Exx)",
4013446Smrj Name));
4023446Smrj return_ACPI_STATUS (AE_OK);
4033446Smrj }
4043446Smrj
4053446Smrj /* Convert the last two characters of the name to the GPE Number */
4063446Smrj
4073446Smrj GpeNumber = ACPI_STRTOUL (&Name[2], NULL, 16);
4083446Smrj if (GpeNumber == ACPI_UINT32_MAX)
4093446Smrj {
4103446Smrj /* Conversion failed; invalid method, just ignore it */
4113446Smrj
4123446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
4139980SDana.Myers@Sun.COM "Could not extract GPE number from name: %s "
4149980SDana.Myers@Sun.COM "(name is not of form _Lxx or _Exx)",
4153446Smrj Name));
4163446Smrj return_ACPI_STATUS (AE_OK);
4173446Smrj }
4183446Smrj
4193446Smrj /* Ensure that we have a valid GPE number for this GPE block */
4203446Smrj
4213446Smrj if ((GpeNumber < GpeBlock->BlockBaseNumber) ||
4229980SDana.Myers@Sun.COM (GpeNumber >= (GpeBlock->BlockBaseNumber +
4239980SDana.Myers@Sun.COM (GpeBlock->RegisterCount * 8))))
4243446Smrj {
4253446Smrj /*
4269980SDana.Myers@Sun.COM * Not valid for this GPE block, just ignore it. However, it may be
4279980SDana.Myers@Sun.COM * valid for a different GPE block, since GPE0 and GPE1 methods both
4289980SDana.Myers@Sun.COM * appear under \_GPE.
4293446Smrj */
4303446Smrj return_ACPI_STATUS (AE_OK);
4313446Smrj }
4323446Smrj
4333446Smrj /*
4349980SDana.Myers@Sun.COM * Now we can add this information to the GpeEventInfo block for use
4359980SDana.Myers@Sun.COM * during dispatch of this GPE. Default type is RUNTIME, although this may
4369980SDana.Myers@Sun.COM * change when the _PRW methods are executed later.
4373446Smrj */
4383446Smrj GpeEventInfo = &GpeBlock->EventInfo[GpeNumber - GpeBlock->BlockBaseNumber];
4393446Smrj
4403446Smrj GpeEventInfo->Flags = (UINT8)
4413446Smrj (Type | ACPI_GPE_DISPATCH_METHOD | ACPI_GPE_TYPE_RUNTIME);
4423446Smrj
4433446Smrj GpeEventInfo->Dispatch.MethodNode = (ACPI_NAMESPACE_NODE *) ObjHandle;
4443446Smrj
4453446Smrj /* Update enable mask, but don't enable the HW GPE as of yet */
4463446Smrj
4473446Smrj Status = AcpiEvEnableGpe (GpeEventInfo, FALSE);
4483446Smrj
4493446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_LOAD,
4503446Smrj "Registered GPE method %s as GPE number 0x%.2X\n",
4513446Smrj Name, GpeNumber));
4523446Smrj return_ACPI_STATUS (Status);
4533446Smrj }
4543446Smrj
4553446Smrj
4563446Smrj /*******************************************************************************
4573446Smrj *
4583446Smrj * FUNCTION: AcpiEvMatchPrwAndGpe
4593446Smrj *
4603446Smrj * PARAMETERS: Callback from WalkNamespace
4613446Smrj *
4623446Smrj * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
4633446Smrj * not aborted on a single _PRW failure.
4643446Smrj *
4653446Smrj * DESCRIPTION: Called from AcpiWalkNamespace. Expects each object to be a
4663446Smrj * Device. Run the _PRW method. If present, extract the GPE
4673446Smrj * number and mark the GPE as a WAKE GPE.
4683446Smrj *
4693446Smrj ******************************************************************************/
4703446Smrj
4713446Smrj static ACPI_STATUS
AcpiEvMatchPrwAndGpe(ACPI_HANDLE ObjHandle,UINT32 Level,void * Info,void ** ReturnValue)4723446Smrj AcpiEvMatchPrwAndGpe (
4733446Smrj ACPI_HANDLE ObjHandle,
4743446Smrj UINT32 Level,
4753446Smrj void *Info,
4763446Smrj void **ReturnValue)
4773446Smrj {
4783446Smrj ACPI_GPE_WALK_INFO *GpeInfo = (void *) Info;
4793446Smrj ACPI_NAMESPACE_NODE *GpeDevice;
4803446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock;
4813446Smrj ACPI_NAMESPACE_NODE *TargetGpeDevice;
4823446Smrj ACPI_GPE_EVENT_INFO *GpeEventInfo;
4833446Smrj ACPI_OPERAND_OBJECT *PkgDesc;
4843446Smrj ACPI_OPERAND_OBJECT *ObjDesc;
4853446Smrj UINT32 GpeNumber;
4863446Smrj ACPI_STATUS Status;
4873446Smrj
4883446Smrj
4893446Smrj ACPI_FUNCTION_TRACE (EvMatchPrwAndGpe);
4903446Smrj
4913446Smrj
4923446Smrj /* Check for a _PRW method under this device */
4933446Smrj
4943446Smrj Status = AcpiUtEvaluateObject (ObjHandle, METHOD_NAME__PRW,
4953446Smrj ACPI_BTYPE_PACKAGE, &PkgDesc);
4963446Smrj if (ACPI_FAILURE (Status))
4973446Smrj {
4983446Smrj /* Ignore all errors from _PRW, we don't want to abort the subsystem */
4993446Smrj
5003446Smrj return_ACPI_STATUS (AE_OK);
5013446Smrj }
5023446Smrj
5033446Smrj /* The returned _PRW package must have at least two elements */
5043446Smrj
5053446Smrj if (PkgDesc->Package.Count < 2)
5063446Smrj {
5073446Smrj goto Cleanup;
5083446Smrj }
5093446Smrj
5103446Smrj /* Extract pointers from the input context */
5113446Smrj
5123446Smrj GpeDevice = GpeInfo->GpeDevice;
5133446Smrj GpeBlock = GpeInfo->GpeBlock;
5143446Smrj
5153446Smrj /*
5169980SDana.Myers@Sun.COM * The _PRW object must return a package, we are only interested in the
5179980SDana.Myers@Sun.COM * first element
5183446Smrj */
5193446Smrj ObjDesc = PkgDesc->Package.Elements[0];
5203446Smrj
5219980SDana.Myers@Sun.COM if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
5223446Smrj {
5233446Smrj /* Use FADT-defined GPE device (from definition of _PRW) */
5243446Smrj
5253446Smrj TargetGpeDevice = AcpiGbl_FadtGpeDevice;
5263446Smrj
5273446Smrj /* Integer is the GPE number in the FADT described GPE blocks */
5283446Smrj
5293446Smrj GpeNumber = (UINT32) ObjDesc->Integer.Value;
5303446Smrj }
5319980SDana.Myers@Sun.COM else if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
5323446Smrj {
5333446Smrj /* Package contains a GPE reference and GPE number within a GPE block */
5343446Smrj
5353446Smrj if ((ObjDesc->Package.Count < 2) ||
5369980SDana.Myers@Sun.COM ((ObjDesc->Package.Elements[0])->Common.Type !=
5379980SDana.Myers@Sun.COM ACPI_TYPE_LOCAL_REFERENCE) ||
5389980SDana.Myers@Sun.COM ((ObjDesc->Package.Elements[1])->Common.Type !=
5399980SDana.Myers@Sun.COM ACPI_TYPE_INTEGER))
5403446Smrj {
5413446Smrj goto Cleanup;
5423446Smrj }
5433446Smrj
5443446Smrj /* Get GPE block reference and decode */
5453446Smrj
5463446Smrj TargetGpeDevice = ObjDesc->Package.Elements[0]->Reference.Node;
5473446Smrj GpeNumber = (UINT32) ObjDesc->Package.Elements[1]->Integer.Value;
5483446Smrj }
5493446Smrj else
5503446Smrj {
5513446Smrj /* Unknown type, just ignore it */
5523446Smrj
5533446Smrj goto Cleanup;
5543446Smrj }
5553446Smrj
5563446Smrj /*
5573446Smrj * Is this GPE within this block?
5583446Smrj *
5599980SDana.Myers@Sun.COM * TRUE if and only if these conditions are true:
5603446Smrj * 1) The GPE devices match.
5613446Smrj * 2) The GPE index(number) is within the range of the Gpe Block
5623446Smrj * associated with the GPE device.
5633446Smrj */
5643446Smrj if ((GpeDevice == TargetGpeDevice) &&
5653446Smrj (GpeNumber >= GpeBlock->BlockBaseNumber) &&
5669980SDana.Myers@Sun.COM (GpeNumber < GpeBlock->BlockBaseNumber +
5679980SDana.Myers@Sun.COM (GpeBlock->RegisterCount * 8)))
5683446Smrj {
5699980SDana.Myers@Sun.COM GpeEventInfo = &GpeBlock->EventInfo[GpeNumber -
5709980SDana.Myers@Sun.COM GpeBlock->BlockBaseNumber];
5713446Smrj
5723446Smrj /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
5733446Smrj
5743446Smrj GpeEventInfo->Flags &= ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
5753446Smrj
5763446Smrj Status = AcpiEvSetGpeType (GpeEventInfo, ACPI_GPE_TYPE_WAKE);
5773446Smrj if (ACPI_FAILURE (Status))
5783446Smrj {
5793446Smrj goto Cleanup;
5803446Smrj }
5819980SDana.Myers@Sun.COM
5823446Smrj Status = AcpiEvUpdateGpeEnableMasks (GpeEventInfo, ACPI_GPE_DISABLE);
5833446Smrj }
5843446Smrj
5853446Smrj Cleanup:
5863446Smrj AcpiUtRemoveReference (PkgDesc);
5873446Smrj return_ACPI_STATUS (AE_OK);
5883446Smrj }
5893446Smrj
5903446Smrj
5913446Smrj /*******************************************************************************
5923446Smrj *
5933446Smrj * FUNCTION: AcpiEvGetGpeXruptBlock
5943446Smrj *
5953446Smrj * PARAMETERS: InterruptNumber - Interrupt for a GPE block
5963446Smrj *
5973446Smrj * RETURN: A GPE interrupt block
5983446Smrj *
5993446Smrj * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
6009980SDana.Myers@Sun.COM * block per unique interrupt level used for GPEs. Should be
6019980SDana.Myers@Sun.COM * called only when the GPE lists are semaphore locked and not
6029980SDana.Myers@Sun.COM * subject to change.
6033446Smrj *
6043446Smrj ******************************************************************************/
6053446Smrj
6063446Smrj static ACPI_GPE_XRUPT_INFO *
AcpiEvGetGpeXruptBlock(UINT32 InterruptNumber)6073446Smrj AcpiEvGetGpeXruptBlock (
6083446Smrj UINT32 InterruptNumber)
6093446Smrj {
6103446Smrj ACPI_GPE_XRUPT_INFO *NextGpeXrupt;
6113446Smrj ACPI_GPE_XRUPT_INFO *GpeXrupt;
6123446Smrj ACPI_STATUS Status;
6133446Smrj ACPI_CPU_FLAGS Flags;
6143446Smrj
6153446Smrj
6163446Smrj ACPI_FUNCTION_TRACE (EvGetGpeXruptBlock);
6173446Smrj
6183446Smrj
6193446Smrj /* No need for lock since we are not changing any list elements here */
6203446Smrj
6213446Smrj NextGpeXrupt = AcpiGbl_GpeXruptListHead;
6223446Smrj while (NextGpeXrupt)
6233446Smrj {
6243446Smrj if (NextGpeXrupt->InterruptNumber == InterruptNumber)
6253446Smrj {
6263446Smrj return_PTR (NextGpeXrupt);
6273446Smrj }
6283446Smrj
6293446Smrj NextGpeXrupt = NextGpeXrupt->Next;
6303446Smrj }
6313446Smrj
6323446Smrj /* Not found, must allocate a new xrupt descriptor */
6333446Smrj
6343446Smrj GpeXrupt = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_XRUPT_INFO));
6353446Smrj if (!GpeXrupt)
6363446Smrj {
6373446Smrj return_PTR (NULL);
6383446Smrj }
6393446Smrj
6403446Smrj GpeXrupt->InterruptNumber = InterruptNumber;
6413446Smrj
6423446Smrj /* Install new interrupt descriptor with spin lock */
6433446Smrj
6443446Smrj Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
6453446Smrj if (AcpiGbl_GpeXruptListHead)
6463446Smrj {
6473446Smrj NextGpeXrupt = AcpiGbl_GpeXruptListHead;
6483446Smrj while (NextGpeXrupt->Next)
6493446Smrj {
6503446Smrj NextGpeXrupt = NextGpeXrupt->Next;
6513446Smrj }
6523446Smrj
6533446Smrj NextGpeXrupt->Next = GpeXrupt;
6543446Smrj GpeXrupt->Previous = NextGpeXrupt;
6553446Smrj }
6563446Smrj else
6573446Smrj {
6583446Smrj AcpiGbl_GpeXruptListHead = GpeXrupt;
6593446Smrj }
6603446Smrj AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
6613446Smrj
6623446Smrj /* Install new interrupt handler if not SCI_INT */
6633446Smrj
6647851SDana.Myers@Sun.COM if (InterruptNumber != AcpiGbl_FADT.SciInterrupt)
6653446Smrj {
6663446Smrj Status = AcpiOsInstallInterruptHandler (InterruptNumber,
6673446Smrj AcpiEvGpeXruptHandler, GpeXrupt);
6683446Smrj if (ACPI_FAILURE (Status))
6693446Smrj {
6703446Smrj ACPI_ERROR ((AE_INFO,
6713446Smrj "Could not install GPE interrupt handler at level 0x%X",
6723446Smrj InterruptNumber));
6733446Smrj return_PTR (NULL);
6743446Smrj }
6753446Smrj }
6763446Smrj
6773446Smrj return_PTR (GpeXrupt);
6783446Smrj }
6793446Smrj
6803446Smrj
6813446Smrj /*******************************************************************************
6823446Smrj *
6833446Smrj * FUNCTION: AcpiEvDeleteGpeXrupt
6843446Smrj *
6853446Smrj * PARAMETERS: GpeXrupt - A GPE interrupt info block
6863446Smrj *
6873446Smrj * RETURN: Status
6883446Smrj *
6893446Smrj * DESCRIPTION: Remove and free a GpeXrupt block. Remove an associated
6903446Smrj * interrupt handler if not the SCI interrupt.
6913446Smrj *
6923446Smrj ******************************************************************************/
6933446Smrj
6943446Smrj static ACPI_STATUS
AcpiEvDeleteGpeXrupt(ACPI_GPE_XRUPT_INFO * GpeXrupt)6953446Smrj AcpiEvDeleteGpeXrupt (
6963446Smrj ACPI_GPE_XRUPT_INFO *GpeXrupt)
6973446Smrj {
6983446Smrj ACPI_STATUS Status;
6993446Smrj ACPI_CPU_FLAGS Flags;
7003446Smrj
7013446Smrj
7023446Smrj ACPI_FUNCTION_TRACE (EvDeleteGpeXrupt);
7033446Smrj
7043446Smrj
7053446Smrj /* We never want to remove the SCI interrupt handler */
7063446Smrj
7077851SDana.Myers@Sun.COM if (GpeXrupt->InterruptNumber == AcpiGbl_FADT.SciInterrupt)
7083446Smrj {
7093446Smrj GpeXrupt->GpeBlockListHead = NULL;
7103446Smrj return_ACPI_STATUS (AE_OK);
7113446Smrj }
7123446Smrj
7133446Smrj /* Disable this interrupt */
7143446Smrj
7153446Smrj Status = AcpiOsRemoveInterruptHandler (
7163446Smrj GpeXrupt->InterruptNumber, AcpiEvGpeXruptHandler);
7173446Smrj if (ACPI_FAILURE (Status))
7183446Smrj {
7193446Smrj return_ACPI_STATUS (Status);
7203446Smrj }
7213446Smrj
7223446Smrj /* Unlink the interrupt block with lock */
7233446Smrj
7243446Smrj Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
7253446Smrj if (GpeXrupt->Previous)
7263446Smrj {
7273446Smrj GpeXrupt->Previous->Next = GpeXrupt->Next;
7283446Smrj }
7297851SDana.Myers@Sun.COM else
7307851SDana.Myers@Sun.COM {
7317851SDana.Myers@Sun.COM /* No previous, update list head */
7327851SDana.Myers@Sun.COM
7337851SDana.Myers@Sun.COM AcpiGbl_GpeXruptListHead = GpeXrupt->Next;
7347851SDana.Myers@Sun.COM }
7353446Smrj
7363446Smrj if (GpeXrupt->Next)
7373446Smrj {
7383446Smrj GpeXrupt->Next->Previous = GpeXrupt->Previous;
7393446Smrj }
7403446Smrj AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
7413446Smrj
7423446Smrj /* Free the block */
7433446Smrj
7443446Smrj ACPI_FREE (GpeXrupt);
7453446Smrj return_ACPI_STATUS (AE_OK);
7463446Smrj }
7473446Smrj
7483446Smrj
7493446Smrj /*******************************************************************************
7503446Smrj *
7513446Smrj * FUNCTION: AcpiEvInstallGpeBlock
7523446Smrj *
7539980SDana.Myers@Sun.COM * PARAMETERS: GpeBlock - New GPE block
7549980SDana.Myers@Sun.COM * InterruptNumber - Xrupt to be associated with this
7559980SDana.Myers@Sun.COM * GPE block
7563446Smrj *
7573446Smrj * RETURN: Status
7583446Smrj *
7593446Smrj * DESCRIPTION: Install new GPE block with mutex support
7603446Smrj *
7613446Smrj ******************************************************************************/
7623446Smrj
7633446Smrj static ACPI_STATUS
AcpiEvInstallGpeBlock(ACPI_GPE_BLOCK_INFO * GpeBlock,UINT32 InterruptNumber)7643446Smrj AcpiEvInstallGpeBlock (
7653446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock,
7663446Smrj UINT32 InterruptNumber)
7673446Smrj {
7683446Smrj ACPI_GPE_BLOCK_INFO *NextGpeBlock;
7693446Smrj ACPI_GPE_XRUPT_INFO *GpeXruptBlock;
7703446Smrj ACPI_STATUS Status;
7713446Smrj ACPI_CPU_FLAGS Flags;
7723446Smrj
7733446Smrj
7743446Smrj ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
7753446Smrj
7763446Smrj
7773446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
7783446Smrj if (ACPI_FAILURE (Status))
7793446Smrj {
7803446Smrj return_ACPI_STATUS (Status);
7813446Smrj }
7823446Smrj
7833446Smrj GpeXruptBlock = AcpiEvGetGpeXruptBlock (InterruptNumber);
7843446Smrj if (!GpeXruptBlock)
7853446Smrj {
7863446Smrj Status = AE_NO_MEMORY;
7873446Smrj goto UnlockAndExit;
7883446Smrj }
7893446Smrj
7903446Smrj /* Install the new block at the end of the list with lock */
7913446Smrj
7923446Smrj Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
7933446Smrj if (GpeXruptBlock->GpeBlockListHead)
7943446Smrj {
7953446Smrj NextGpeBlock = GpeXruptBlock->GpeBlockListHead;
7963446Smrj while (NextGpeBlock->Next)
7973446Smrj {
7983446Smrj NextGpeBlock = NextGpeBlock->Next;
7993446Smrj }
8003446Smrj
8013446Smrj NextGpeBlock->Next = GpeBlock;
8023446Smrj GpeBlock->Previous = NextGpeBlock;
8033446Smrj }
8043446Smrj else
8053446Smrj {
8063446Smrj GpeXruptBlock->GpeBlockListHead = GpeBlock;
8073446Smrj }
8083446Smrj
8093446Smrj GpeBlock->XruptBlock = GpeXruptBlock;
8103446Smrj AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
8113446Smrj
8123446Smrj
8133446Smrj UnlockAndExit:
8143446Smrj Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
8153446Smrj return_ACPI_STATUS (Status);
8163446Smrj }
8173446Smrj
8183446Smrj
8193446Smrj /*******************************************************************************
8203446Smrj *
8213446Smrj * FUNCTION: AcpiEvDeleteGpeBlock
8223446Smrj *
8239980SDana.Myers@Sun.COM * PARAMETERS: GpeBlock - Existing GPE block
8243446Smrj *
8253446Smrj * RETURN: Status
8263446Smrj *
8273446Smrj * DESCRIPTION: Remove a GPE block
8283446Smrj *
8293446Smrj ******************************************************************************/
8303446Smrj
8313446Smrj ACPI_STATUS
AcpiEvDeleteGpeBlock(ACPI_GPE_BLOCK_INFO * GpeBlock)8323446Smrj AcpiEvDeleteGpeBlock (
8333446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock)
8343446Smrj {
8353446Smrj ACPI_STATUS Status;
8363446Smrj ACPI_CPU_FLAGS Flags;
8373446Smrj
8383446Smrj
8393446Smrj ACPI_FUNCTION_TRACE (EvInstallGpeBlock);
8403446Smrj
8413446Smrj
8423446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
8433446Smrj if (ACPI_FAILURE (Status))
8443446Smrj {
8453446Smrj return_ACPI_STATUS (Status);
8463446Smrj }
8473446Smrj
8483446Smrj /* Disable all GPEs in this block */
8493446Smrj
8509980SDana.Myers@Sun.COM Status = AcpiHwDisableGpeBlock (GpeBlock->XruptBlock, GpeBlock, NULL);
8513446Smrj
8523446Smrj if (!GpeBlock->Previous && !GpeBlock->Next)
8533446Smrj {
8543446Smrj /* This is the last GpeBlock on this interrupt */
8553446Smrj
8563446Smrj Status = AcpiEvDeleteGpeXrupt (GpeBlock->XruptBlock);
8573446Smrj if (ACPI_FAILURE (Status))
8583446Smrj {
8593446Smrj goto UnlockAndExit;
8603446Smrj }
8613446Smrj }
8623446Smrj else
8633446Smrj {
8643446Smrj /* Remove the block on this interrupt with lock */
8653446Smrj
8663446Smrj Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
8673446Smrj if (GpeBlock->Previous)
8683446Smrj {
8693446Smrj GpeBlock->Previous->Next = GpeBlock->Next;
8703446Smrj }
8713446Smrj else
8723446Smrj {
8733446Smrj GpeBlock->XruptBlock->GpeBlockListHead = GpeBlock->Next;
8743446Smrj }
8753446Smrj
8763446Smrj if (GpeBlock->Next)
8773446Smrj {
8783446Smrj GpeBlock->Next->Previous = GpeBlock->Previous;
8793446Smrj }
8803446Smrj AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
8813446Smrj }
8823446Smrj
8839980SDana.Myers@Sun.COM AcpiCurrentGpeCount -= GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH;
8849980SDana.Myers@Sun.COM
8853446Smrj /* Free the GpeBlock */
8863446Smrj
8873446Smrj ACPI_FREE (GpeBlock->RegisterInfo);
8883446Smrj ACPI_FREE (GpeBlock->EventInfo);
8893446Smrj ACPI_FREE (GpeBlock);
8903446Smrj
8913446Smrj UnlockAndExit:
8923446Smrj Status = AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
8933446Smrj return_ACPI_STATUS (Status);
8943446Smrj }
8953446Smrj
8963446Smrj
8973446Smrj /*******************************************************************************
8983446Smrj *
8993446Smrj * FUNCTION: AcpiEvCreateGpeInfoBlocks
9003446Smrj *
9013446Smrj * PARAMETERS: GpeBlock - New GPE block
9023446Smrj *
9033446Smrj * RETURN: Status
9043446Smrj *
9053446Smrj * DESCRIPTION: Create the RegisterInfo and EventInfo blocks for this GPE block
9063446Smrj *
9073446Smrj ******************************************************************************/
9083446Smrj
9093446Smrj static ACPI_STATUS
AcpiEvCreateGpeInfoBlocks(ACPI_GPE_BLOCK_INFO * GpeBlock)9103446Smrj AcpiEvCreateGpeInfoBlocks (
9113446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock)
9123446Smrj {
9133446Smrj ACPI_GPE_REGISTER_INFO *GpeRegisterInfo = NULL;
9143446Smrj ACPI_GPE_EVENT_INFO *GpeEventInfo = NULL;
9153446Smrj ACPI_GPE_EVENT_INFO *ThisEvent;
9163446Smrj ACPI_GPE_REGISTER_INFO *ThisRegister;
9177851SDana.Myers@Sun.COM UINT32 i;
9187851SDana.Myers@Sun.COM UINT32 j;
9193446Smrj ACPI_STATUS Status;
9203446Smrj
9213446Smrj
9223446Smrj ACPI_FUNCTION_TRACE (EvCreateGpeInfoBlocks);
9233446Smrj
9243446Smrj
9253446Smrj /* Allocate the GPE register information block */
9263446Smrj
9273446Smrj GpeRegisterInfo = ACPI_ALLOCATE_ZEROED (
9283446Smrj (ACPI_SIZE) GpeBlock->RegisterCount *
9293446Smrj sizeof (ACPI_GPE_REGISTER_INFO));
9303446Smrj if (!GpeRegisterInfo)
9313446Smrj {
9323446Smrj ACPI_ERROR ((AE_INFO,
9333446Smrj "Could not allocate the GpeRegisterInfo table"));
9343446Smrj return_ACPI_STATUS (AE_NO_MEMORY);
9353446Smrj }
9363446Smrj
9373446Smrj /*
9383446Smrj * Allocate the GPE EventInfo block. There are eight distinct GPEs
9393446Smrj * per register. Initialization to zeros is sufficient.
9403446Smrj */
9413446Smrj GpeEventInfo = ACPI_ALLOCATE_ZEROED (
9423446Smrj ((ACPI_SIZE) GpeBlock->RegisterCount *
9433446Smrj ACPI_GPE_REGISTER_WIDTH) *
9443446Smrj sizeof (ACPI_GPE_EVENT_INFO));
9453446Smrj if (!GpeEventInfo)
9463446Smrj {
9473446Smrj ACPI_ERROR ((AE_INFO,
9483446Smrj "Could not allocate the GpeEventInfo table"));
9493446Smrj Status = AE_NO_MEMORY;
9503446Smrj goto ErrorExit;
9513446Smrj }
9523446Smrj
9533446Smrj /* Save the new Info arrays in the GPE block */
9543446Smrj
9553446Smrj GpeBlock->RegisterInfo = GpeRegisterInfo;
9563446Smrj GpeBlock->EventInfo = GpeEventInfo;
9573446Smrj
9583446Smrj /*
9593446Smrj * Initialize the GPE Register and Event structures. A goal of these
9609980SDana.Myers@Sun.COM * tables is to hide the fact that there are two separate GPE register
9619980SDana.Myers@Sun.COM * sets in a given GPE hardware block, the status registers occupy the
9629980SDana.Myers@Sun.COM * first half, and the enable registers occupy the second half.
9633446Smrj */
9643446Smrj ThisRegister = GpeRegisterInfo;
9653446Smrj ThisEvent = GpeEventInfo;
9663446Smrj
9673446Smrj for (i = 0; i < GpeBlock->RegisterCount; i++)
9683446Smrj {
9693446Smrj /* Init the RegisterInfo for this GPE register (8 GPEs) */
9703446Smrj
9713446Smrj ThisRegister->BaseGpeNumber = (UINT8) (GpeBlock->BlockBaseNumber +
9723446Smrj (i * ACPI_GPE_REGISTER_WIDTH));
9733446Smrj
9747851SDana.Myers@Sun.COM ThisRegister->StatusAddress.Address =
9757851SDana.Myers@Sun.COM GpeBlock->BlockAddress.Address + i;
9767851SDana.Myers@Sun.COM
9777851SDana.Myers@Sun.COM ThisRegister->EnableAddress.Address =
9787851SDana.Myers@Sun.COM GpeBlock->BlockAddress.Address + i + GpeBlock->RegisterCount;
9793446Smrj
9807851SDana.Myers@Sun.COM ThisRegister->StatusAddress.SpaceId = GpeBlock->BlockAddress.SpaceId;
9817851SDana.Myers@Sun.COM ThisRegister->EnableAddress.SpaceId = GpeBlock->BlockAddress.SpaceId;
9827851SDana.Myers@Sun.COM ThisRegister->StatusAddress.BitWidth = ACPI_GPE_REGISTER_WIDTH;
9837851SDana.Myers@Sun.COM ThisRegister->EnableAddress.BitWidth = ACPI_GPE_REGISTER_WIDTH;
9849980SDana.Myers@Sun.COM ThisRegister->StatusAddress.BitOffset = 0;
9859980SDana.Myers@Sun.COM ThisRegister->EnableAddress.BitOffset = 0;
9863446Smrj
9873446Smrj /* Init the EventInfo for each GPE within this register */
9883446Smrj
9893446Smrj for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)
9903446Smrj {
9917851SDana.Myers@Sun.COM ThisEvent->GpeNumber = (UINT8) (ThisRegister->BaseGpeNumber + j);
9923446Smrj ThisEvent->RegisterInfo = ThisRegister;
9933446Smrj ThisEvent++;
9943446Smrj }
9953446Smrj
9963446Smrj /* Disable all GPEs within this register */
9973446Smrj
998*11225SDana.Myers@Sun.COM Status = AcpiHwWrite (0x00, &ThisRegister->EnableAddress);
9993446Smrj if (ACPI_FAILURE (Status))
10003446Smrj {
10013446Smrj goto ErrorExit;
10023446Smrj }
10033446Smrj
10043446Smrj /* Clear any pending GPE events within this register */
10053446Smrj
1006*11225SDana.Myers@Sun.COM Status = AcpiHwWrite (0xFF, &ThisRegister->StatusAddress);
10073446Smrj if (ACPI_FAILURE (Status))
10083446Smrj {
10093446Smrj goto ErrorExit;
10103446Smrj }
10113446Smrj
10123446Smrj ThisRegister++;
10133446Smrj }
10143446Smrj
10153446Smrj return_ACPI_STATUS (AE_OK);
10163446Smrj
10173446Smrj
10183446Smrj ErrorExit:
10193446Smrj if (GpeRegisterInfo)
10203446Smrj {
10213446Smrj ACPI_FREE (GpeRegisterInfo);
10223446Smrj }
10233446Smrj if (GpeEventInfo)
10243446Smrj {
10253446Smrj ACPI_FREE (GpeEventInfo);
10263446Smrj }
10273446Smrj
10283446Smrj return_ACPI_STATUS (Status);
10293446Smrj }
10303446Smrj
10313446Smrj
10323446Smrj /*******************************************************************************
10333446Smrj *
10343446Smrj * FUNCTION: AcpiEvCreateGpeBlock
10353446Smrj *
10363446Smrj * PARAMETERS: GpeDevice - Handle to the parent GPE block
10373446Smrj * GpeBlockAddress - Address and SpaceID
10383446Smrj * RegisterCount - Number of GPE register pairs in the block
10393446Smrj * GpeBlockBaseNumber - Starting GPE number for the block
10403446Smrj * InterruptNumber - H/W interrupt for the block
10413446Smrj * ReturnGpeBlock - Where the new block descriptor is returned
10423446Smrj *
10433446Smrj * RETURN: Status
10443446Smrj *
10453446Smrj * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
10463446Smrj * the block are disabled at exit.
10473446Smrj * Note: Assumes namespace is locked.
10483446Smrj *
10493446Smrj ******************************************************************************/
10503446Smrj
10513446Smrj ACPI_STATUS
AcpiEvCreateGpeBlock(ACPI_NAMESPACE_NODE * GpeDevice,ACPI_GENERIC_ADDRESS * GpeBlockAddress,UINT32 RegisterCount,UINT8 GpeBlockBaseNumber,UINT32 InterruptNumber,ACPI_GPE_BLOCK_INFO ** ReturnGpeBlock)10523446Smrj AcpiEvCreateGpeBlock (
10533446Smrj ACPI_NAMESPACE_NODE *GpeDevice,
10543446Smrj ACPI_GENERIC_ADDRESS *GpeBlockAddress,
10553446Smrj UINT32 RegisterCount,
10563446Smrj UINT8 GpeBlockBaseNumber,
10573446Smrj UINT32 InterruptNumber,
10583446Smrj ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
10593446Smrj {
10603446Smrj ACPI_STATUS Status;
10613446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock;
10623446Smrj
10633446Smrj
10643446Smrj ACPI_FUNCTION_TRACE (EvCreateGpeBlock);
10653446Smrj
10663446Smrj
10673446Smrj if (!RegisterCount)
10683446Smrj {
10693446Smrj return_ACPI_STATUS (AE_OK);
10703446Smrj }
10713446Smrj
10723446Smrj /* Allocate a new GPE block */
10733446Smrj
10743446Smrj GpeBlock = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_BLOCK_INFO));
10753446Smrj if (!GpeBlock)
10763446Smrj {
10773446Smrj return_ACPI_STATUS (AE_NO_MEMORY);
10783446Smrj }
10793446Smrj
10803446Smrj /* Initialize the new GPE block */
10813446Smrj
10823446Smrj GpeBlock->Node = GpeDevice;
10833446Smrj GpeBlock->RegisterCount = RegisterCount;
10843446Smrj GpeBlock->BlockBaseNumber = GpeBlockBaseNumber;
10853446Smrj
10863446Smrj ACPI_MEMCPY (&GpeBlock->BlockAddress, GpeBlockAddress,
10873446Smrj sizeof (ACPI_GENERIC_ADDRESS));
10883446Smrj
10893446Smrj /*
10903446Smrj * Create the RegisterInfo and EventInfo sub-structures
10913446Smrj * Note: disables and clears all GPEs in the block
10923446Smrj */
10933446Smrj Status = AcpiEvCreateGpeInfoBlocks (GpeBlock);
10943446Smrj if (ACPI_FAILURE (Status))
10953446Smrj {
10963446Smrj ACPI_FREE (GpeBlock);
10973446Smrj return_ACPI_STATUS (Status);
10983446Smrj }
10993446Smrj
11003446Smrj /* Install the new block in the global lists */
11013446Smrj
11023446Smrj Status = AcpiEvInstallGpeBlock (GpeBlock, InterruptNumber);
11033446Smrj if (ACPI_FAILURE (Status))
11043446Smrj {
11053446Smrj ACPI_FREE (GpeBlock);
11063446Smrj return_ACPI_STATUS (Status);
11073446Smrj }
11083446Smrj
11093446Smrj /* Find all GPE methods (_Lxx, _Exx) for this block */
11103446Smrj
11113446Smrj Status = AcpiNsWalkNamespace (ACPI_TYPE_METHOD, GpeDevice,
11123446Smrj ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
1113*11225SDana.Myers@Sun.COM AcpiEvSaveMethodInfo, NULL, GpeBlock, NULL);
11143446Smrj
11153446Smrj /* Return the new block */
11163446Smrj
11173446Smrj if (ReturnGpeBlock)
11183446Smrj {
11193446Smrj (*ReturnGpeBlock) = GpeBlock;
11203446Smrj }
11213446Smrj
11223446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
11233446Smrj "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
11243446Smrj (UINT32) GpeBlock->BlockBaseNumber,
11253446Smrj (UINT32) (GpeBlock->BlockBaseNumber +
11263446Smrj ((GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH) -1)),
11273446Smrj GpeDevice->Name.Ascii,
11283446Smrj GpeBlock->RegisterCount,
11293446Smrj InterruptNumber));
11303446Smrj
11319980SDana.Myers@Sun.COM /* Update global count of currently available GPEs */
11329980SDana.Myers@Sun.COM
11339980SDana.Myers@Sun.COM AcpiCurrentGpeCount += RegisterCount * ACPI_GPE_REGISTER_WIDTH;
11343446Smrj return_ACPI_STATUS (AE_OK);
11353446Smrj }
11363446Smrj
11373446Smrj
11383446Smrj /*******************************************************************************
11393446Smrj *
11403446Smrj * FUNCTION: AcpiEvInitializeGpeBlock
11413446Smrj *
11423446Smrj * PARAMETERS: GpeDevice - Handle to the parent GPE block
11433446Smrj * GpeBlock - Gpe Block info
11443446Smrj *
11453446Smrj * RETURN: Status
11463446Smrj *
11473446Smrj * DESCRIPTION: Initialize and enable a GPE block. First find and run any
11483446Smrj * _PRT methods associated with the block, then enable the
11493446Smrj * appropriate GPEs.
11503446Smrj * Note: Assumes namespace is locked.
11513446Smrj *
11523446Smrj ******************************************************************************/
11533446Smrj
11543446Smrj ACPI_STATUS
AcpiEvInitializeGpeBlock(ACPI_NAMESPACE_NODE * GpeDevice,ACPI_GPE_BLOCK_INFO * GpeBlock)11553446Smrj AcpiEvInitializeGpeBlock (
11563446Smrj ACPI_NAMESPACE_NODE *GpeDevice,
11573446Smrj ACPI_GPE_BLOCK_INFO *GpeBlock)
11583446Smrj {
11593446Smrj ACPI_STATUS Status;
11603446Smrj ACPI_GPE_EVENT_INFO *GpeEventInfo;
11613446Smrj ACPI_GPE_WALK_INFO GpeInfo;
11623446Smrj UINT32 WakeGpeCount;
11633446Smrj UINT32 GpeEnabledCount;
11647851SDana.Myers@Sun.COM UINT32 i;
11657851SDana.Myers@Sun.COM UINT32 j;
11663446Smrj
11673446Smrj
11683446Smrj ACPI_FUNCTION_TRACE (EvInitializeGpeBlock);
11693446Smrj
11703446Smrj
11713446Smrj /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
11723446Smrj
11733446Smrj if (!GpeBlock)
11743446Smrj {
11753446Smrj return_ACPI_STATUS (AE_OK);
11763446Smrj }
11773446Smrj
11783446Smrj /*
11793446Smrj * Runtime option: Should wake GPEs be enabled at runtime? The default
11803446Smrj * is no, they should only be enabled just as the machine goes to sleep.
11813446Smrj */
11823446Smrj if (AcpiGbl_LeaveWakeGpesDisabled)
11833446Smrj {
11843446Smrj /*
11853446Smrj * Differentiate runtime vs wake GPEs, via the _PRW control methods.
11863446Smrj * Each GPE that has one or more _PRWs that reference it is by
11873446Smrj * definition a wake GPE and will not be enabled while the machine
11883446Smrj * is running.
11893446Smrj */
11903446Smrj GpeInfo.GpeBlock = GpeBlock;
11913446Smrj GpeInfo.GpeDevice = GpeDevice;
11923446Smrj
11933446Smrj Status = AcpiNsWalkNamespace (ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
11943446Smrj ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
1195*11225SDana.Myers@Sun.COM AcpiEvMatchPrwAndGpe, NULL, &GpeInfo, NULL);
11963446Smrj }
11973446Smrj
11983446Smrj /*
11993446Smrj * Enable all GPEs in this block that have these attributes:
12003446Smrj * 1) are "runtime" or "run/wake" GPEs, and
12013446Smrj * 2) have a corresponding _Lxx or _Exx method
12023446Smrj *
12039980SDana.Myers@Sun.COM * Any other GPEs within this block must be enabled via the
12049980SDana.Myers@Sun.COM * AcpiEnableGpe() external interface.
12053446Smrj */
12063446Smrj WakeGpeCount = 0;
12073446Smrj GpeEnabledCount = 0;
12083446Smrj
12093446Smrj for (i = 0; i < GpeBlock->RegisterCount; i++)
12103446Smrj {
12113446Smrj for (j = 0; j < 8; j++)
12123446Smrj {
12133446Smrj /* Get the info block for this particular GPE */
12143446Smrj
12159980SDana.Myers@Sun.COM GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *
12169980SDana.Myers@Sun.COM ACPI_GPE_REGISTER_WIDTH) + j];
12173446Smrj
12189980SDana.Myers@Sun.COM if (((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
12199980SDana.Myers@Sun.COM ACPI_GPE_DISPATCH_METHOD) &&
12203446Smrj (GpeEventInfo->Flags & ACPI_GPE_TYPE_RUNTIME))
12213446Smrj {
12223446Smrj GpeEnabledCount++;
12233446Smrj }
12243446Smrj
12253446Smrj if (GpeEventInfo->Flags & ACPI_GPE_TYPE_WAKE)
12263446Smrj {
12273446Smrj WakeGpeCount++;
12283446Smrj }
12293446Smrj }
12303446Smrj }
12313446Smrj
12323446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
12333446Smrj "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
12343446Smrj WakeGpeCount, GpeEnabledCount));
12353446Smrj
12363446Smrj /* Enable all valid runtime GPEs found above */
12373446Smrj
12389980SDana.Myers@Sun.COM Status = AcpiHwEnableRuntimeGpeBlock (NULL, GpeBlock, NULL);
12393446Smrj if (ACPI_FAILURE (Status))
12403446Smrj {
12413446Smrj ACPI_ERROR ((AE_INFO, "Could not enable GPEs in GpeBlock %p",
12423446Smrj GpeBlock));
12433446Smrj }
12443446Smrj
12453446Smrj return_ACPI_STATUS (Status);
12463446Smrj }
12473446Smrj
12483446Smrj
12493446Smrj /*******************************************************************************
12503446Smrj *
12513446Smrj * FUNCTION: AcpiEvGpeInitialize
12523446Smrj *
12533446Smrj * PARAMETERS: None
12543446Smrj *
12553446Smrj * RETURN: Status
12563446Smrj *
12573446Smrj * DESCRIPTION: Initialize the GPE data structures
12583446Smrj *
12593446Smrj ******************************************************************************/
12603446Smrj
12613446Smrj ACPI_STATUS
AcpiEvGpeInitialize(void)12623446Smrj AcpiEvGpeInitialize (
12633446Smrj void)
12643446Smrj {
12653446Smrj UINT32 RegisterCount0 = 0;
12663446Smrj UINT32 RegisterCount1 = 0;
12673446Smrj UINT32 GpeNumberMax = 0;
12683446Smrj ACPI_STATUS Status;
12693446Smrj
12703446Smrj
12713446Smrj ACPI_FUNCTION_TRACE (EvGpeInitialize);
12723446Smrj
12733446Smrj
12743446Smrj Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
12753446Smrj if (ACPI_FAILURE (Status))
12763446Smrj {
12773446Smrj return_ACPI_STATUS (Status);
12783446Smrj }
12793446Smrj
12803446Smrj /*
12813446Smrj * Initialize the GPE Block(s) defined in the FADT
12823446Smrj *
12839980SDana.Myers@Sun.COM * Why the GPE register block lengths are divided by 2: From the ACPI
12849980SDana.Myers@Sun.COM * Spec, section "General-Purpose Event Registers", we have:
12853446Smrj *
12863446Smrj * "Each register block contains two registers of equal length
12873446Smrj * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
12883446Smrj * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
12893446Smrj * The length of the GPE1_STS and GPE1_EN registers is equal to
12903446Smrj * half the GPE1_LEN. If a generic register block is not supported
12913446Smrj * then its respective block pointer and block length values in the
12923446Smrj * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
12933446Smrj * to be the same size."
12943446Smrj */
12953446Smrj
12963446Smrj /*
12973446Smrj * Determine the maximum GPE number for this machine.
12983446Smrj *
12993446Smrj * Note: both GPE0 and GPE1 are optional, and either can exist without
13003446Smrj * the other.
13013446Smrj *
13023446Smrj * If EITHER the register length OR the block address are zero, then that
13033446Smrj * particular block is not supported.
13043446Smrj */
13057851SDana.Myers@Sun.COM if (AcpiGbl_FADT.Gpe0BlockLength &&
13067851SDana.Myers@Sun.COM AcpiGbl_FADT.XGpe0Block.Address)
13073446Smrj {
13083446Smrj /* GPE block 0 exists (has both length and address > 0) */
13093446Smrj
13107851SDana.Myers@Sun.COM RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
13113446Smrj
13123446Smrj GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
13133446Smrj
13143446Smrj /* Install GPE Block 0 */
13153446Smrj
13163446Smrj Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
13177851SDana.Myers@Sun.COM &AcpiGbl_FADT.XGpe0Block, RegisterCount0, 0,
13187851SDana.Myers@Sun.COM AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
13193446Smrj
13203446Smrj if (ACPI_FAILURE (Status))
13213446Smrj {
13223446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
13233446Smrj "Could not create GPE Block 0"));
13243446Smrj }
13253446Smrj }
13263446Smrj
13277851SDana.Myers@Sun.COM if (AcpiGbl_FADT.Gpe1BlockLength &&
13287851SDana.Myers@Sun.COM AcpiGbl_FADT.XGpe1Block.Address)
13293446Smrj {
13303446Smrj /* GPE block 1 exists (has both length and address > 0) */
13313446Smrj
13327851SDana.Myers@Sun.COM RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
13333446Smrj
13343446Smrj /* Check for GPE0/GPE1 overlap (if both banks exist) */
13353446Smrj
13363446Smrj if ((RegisterCount0) &&
13377851SDana.Myers@Sun.COM (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
13383446Smrj {
13393446Smrj ACPI_ERROR ((AE_INFO,
13409980SDana.Myers@Sun.COM "GPE0 block (GPE 0 to %d) overlaps the GPE1 block "
13419980SDana.Myers@Sun.COM "(GPE %d to %d) - Ignoring GPE1",
13427851SDana.Myers@Sun.COM GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
13437851SDana.Myers@Sun.COM AcpiGbl_FADT.Gpe1Base +
13443446Smrj ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
13453446Smrj
13463446Smrj /* Ignore GPE1 block by setting the register count to zero */
13473446Smrj
13483446Smrj RegisterCount1 = 0;
13493446Smrj }
13503446Smrj else
13513446Smrj {
13523446Smrj /* Install GPE Block 1 */
13533446Smrj
13543446Smrj Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
13557851SDana.Myers@Sun.COM &AcpiGbl_FADT.XGpe1Block, RegisterCount1,
13567851SDana.Myers@Sun.COM AcpiGbl_FADT.Gpe1Base,
13577851SDana.Myers@Sun.COM AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
13583446Smrj
13593446Smrj if (ACPI_FAILURE (Status))
13603446Smrj {
13613446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
13623446Smrj "Could not create GPE Block 1"));
13633446Smrj }
13643446Smrj
13653446Smrj /*
13663446Smrj * GPE0 and GPE1 do not have to be contiguous in the GPE number
13673446Smrj * space. However, GPE0 always starts at GPE number zero.
13683446Smrj */
13697851SDana.Myers@Sun.COM GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
13703446Smrj ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
13713446Smrj }
13723446Smrj }
13733446Smrj
13743446Smrj /* Exit if there are no GPE registers */
13753446Smrj
13763446Smrj if ((RegisterCount0 + RegisterCount1) == 0)
13773446Smrj {
13783446Smrj /* GPEs are not required by ACPI, this is OK */
13793446Smrj
13803446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
13813446Smrj "There are no GPE blocks defined in the FADT\n"));
13823446Smrj Status = AE_OK;
13833446Smrj goto Cleanup;
13843446Smrj }
13853446Smrj
13863446Smrj /* Check for Max GPE number out-of-range */
13873446Smrj
13883446Smrj if (GpeNumberMax > ACPI_GPE_MAX)
13893446Smrj {
13903446Smrj ACPI_ERROR ((AE_INFO,
13913446Smrj "Maximum GPE number from FADT is too large: 0x%X",
13923446Smrj GpeNumberMax));
13933446Smrj Status = AE_BAD_VALUE;
13943446Smrj goto Cleanup;
13953446Smrj }
13963446Smrj
13973446Smrj Cleanup:
13983446Smrj (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
13993446Smrj return_ACPI_STATUS (AE_OK);
14003446Smrj }
14013446Smrj
14023446Smrj
1403