Path: blob/main/sys/contrib/dev/acpica/components/events/evgpe.c
48526 views
/******************************************************************************1*2* Module Name: evgpe - General Purpose Event handling and dispatch3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acevents.h>154#include <contrib/dev/acpica/include/acnamesp.h>155156#define _COMPONENT ACPI_EVENTS157ACPI_MODULE_NAME ("evgpe")158159#if (!ACPI_REDUCED_HARDWARE) /* Entire module */160161/* Local prototypes */162163static void ACPI_SYSTEM_XFACE164AcpiEvAsynchExecuteGpeMethod (165void *Context);166167static void ACPI_SYSTEM_XFACE168AcpiEvAsynchEnableGpe (169void *Context);170171172/*******************************************************************************173*174* FUNCTION: AcpiEvUpdateGpeEnableMask175*176* PARAMETERS: GpeEventInfo - GPE to update177*178* RETURN: Status179*180* DESCRIPTION: Updates GPE register enable mask based upon whether there are181* runtime references to this GPE182*183******************************************************************************/184185ACPI_STATUS186AcpiEvUpdateGpeEnableMask (187ACPI_GPE_EVENT_INFO *GpeEventInfo)188{189ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;190UINT32 RegisterBit;191192193ACPI_FUNCTION_TRACE (EvUpdateGpeEnableMask);194195196GpeRegisterInfo = GpeEventInfo->RegisterInfo;197if (!GpeRegisterInfo)198{199return_ACPI_STATUS (AE_NOT_EXIST);200}201202RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);203204/* Clear the run bit up front */205206ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForRun, RegisterBit);207208/* Set the mask bit only if there are references to this GPE */209210if (GpeEventInfo->RuntimeCount)211{212ACPI_SET_BIT (GpeRegisterInfo->EnableForRun, (UINT8) RegisterBit);213}214215GpeRegisterInfo->EnableMask = GpeRegisterInfo->EnableForRun;216return_ACPI_STATUS (AE_OK);217}218219220/*******************************************************************************221*222* FUNCTION: AcpiEvEnableGpe223*224* PARAMETERS: GpeEventInfo - GPE to enable225*226* RETURN: Status227*228* DESCRIPTION: Enable a GPE.229*230******************************************************************************/231232ACPI_STATUS233AcpiEvEnableGpe (234ACPI_GPE_EVENT_INFO *GpeEventInfo)235{236ACPI_STATUS Status;237238239ACPI_FUNCTION_TRACE (EvEnableGpe);240241242/* Enable the requested GPE */243244Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);245return_ACPI_STATUS (Status);246}247248249/*******************************************************************************250*251* FUNCTION: AcpiEvMaskGpe252*253* PARAMETERS: GpeEventInfo - GPE to be blocked/unblocked254* IsMasked - Whether the GPE is masked or not255*256* RETURN: Status257*258* DESCRIPTION: Unconditionally mask/unmask a GPE during runtime.259*260******************************************************************************/261262ACPI_STATUS263AcpiEvMaskGpe (264ACPI_GPE_EVENT_INFO *GpeEventInfo,265BOOLEAN IsMasked)266{267ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;268UINT32 RegisterBit;269270271ACPI_FUNCTION_TRACE (EvMaskGpe);272273274GpeRegisterInfo = GpeEventInfo->RegisterInfo;275if (!GpeRegisterInfo)276{277return_ACPI_STATUS (AE_NOT_EXIST);278}279280RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);281282/* Perform the action */283284if (IsMasked)285{286if (RegisterBit & GpeRegisterInfo->MaskForRun)287{288return_ACPI_STATUS (AE_BAD_PARAMETER);289}290291(void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);292ACPI_SET_BIT (GpeRegisterInfo->MaskForRun, (UINT8) RegisterBit);293}294else295{296if (!(RegisterBit & GpeRegisterInfo->MaskForRun))297{298return_ACPI_STATUS (AE_BAD_PARAMETER);299}300301ACPI_CLEAR_BIT (GpeRegisterInfo->MaskForRun, (UINT8) RegisterBit);302if (GpeEventInfo->RuntimeCount &&303!GpeEventInfo->DisableForDispatch)304{305(void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);306}307}308309return_ACPI_STATUS (AE_OK);310}311312313/*******************************************************************************314*315* FUNCTION: AcpiEvAddGpeReference316*317* PARAMETERS: GpeEventInfo - Add a reference to this GPE318* ClearOnEnable - Clear GPE status before enabling it319*320* RETURN: Status321*322* DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is323* hardware-enabled.324*325******************************************************************************/326327ACPI_STATUS328AcpiEvAddGpeReference (329ACPI_GPE_EVENT_INFO *GpeEventInfo,330BOOLEAN ClearOnEnable)331{332ACPI_STATUS Status = AE_OK;333334335ACPI_FUNCTION_TRACE (EvAddGpeReference);336337338if (GpeEventInfo->RuntimeCount == ACPI_UINT8_MAX)339{340return_ACPI_STATUS (AE_LIMIT);341}342343GpeEventInfo->RuntimeCount++;344if (GpeEventInfo->RuntimeCount == 1)345{346/* Enable on first reference */347348if (ClearOnEnable)349{350(void) AcpiHwClearGpe (GpeEventInfo);351}352353Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);354if (ACPI_SUCCESS (Status))355{356Status = AcpiEvEnableGpe (GpeEventInfo);357}358359if (ACPI_FAILURE (Status))360{361GpeEventInfo->RuntimeCount--;362}363}364365return_ACPI_STATUS (Status);366}367368369/*******************************************************************************370*371* FUNCTION: AcpiEvRemoveGpeReference372*373* PARAMETERS: GpeEventInfo - Remove a reference to this GPE374*375* RETURN: Status376*377* DESCRIPTION: Remove a reference to a GPE. When the last reference is378* removed, the GPE is hardware-disabled.379*380******************************************************************************/381382ACPI_STATUS383AcpiEvRemoveGpeReference (384ACPI_GPE_EVENT_INFO *GpeEventInfo)385{386ACPI_STATUS Status = AE_OK;387388389ACPI_FUNCTION_TRACE (EvRemoveGpeReference);390391392if (!GpeEventInfo->RuntimeCount)393{394return_ACPI_STATUS (AE_LIMIT);395}396397GpeEventInfo->RuntimeCount--;398if (!GpeEventInfo->RuntimeCount)399{400/* Disable on last reference */401402Status = AcpiEvUpdateGpeEnableMask (GpeEventInfo);403if (ACPI_SUCCESS (Status))404{405Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);406}407408if (ACPI_FAILURE (Status))409{410GpeEventInfo->RuntimeCount++;411}412}413414return_ACPI_STATUS (Status);415}416417418/*******************************************************************************419*420* FUNCTION: AcpiEvLowGetGpeInfo421*422* PARAMETERS: GpeNumber - Raw GPE number423* GpeBlock - A GPE info block424*425* RETURN: A GPE EventInfo struct. NULL if not a valid GPE (The GpeNumber426* is not within the specified GPE block)427*428* DESCRIPTION: Returns the EventInfo struct associated with this GPE. This is429* the low-level implementation of EvGetGpeEventInfo.430*431******************************************************************************/432433ACPI_GPE_EVENT_INFO *434AcpiEvLowGetGpeInfo (435UINT32 GpeNumber,436ACPI_GPE_BLOCK_INFO *GpeBlock)437{438UINT32 GpeIndex;439440441/*442* Validate that the GpeNumber is within the specified GpeBlock.443* (Two steps)444*/445if (!GpeBlock ||446(GpeNumber < GpeBlock->BlockBaseNumber))447{448return (NULL);449}450451GpeIndex = GpeNumber - GpeBlock->BlockBaseNumber;452if (GpeIndex >= GpeBlock->GpeCount)453{454return (NULL);455}456457return (&GpeBlock->EventInfo[GpeIndex]);458}459460461/*******************************************************************************462*463* FUNCTION: AcpiEvGetGpeEventInfo464*465* PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1466* GpeNumber - Raw GPE number467*468* RETURN: A GPE EventInfo struct. NULL if not a valid GPE469*470* DESCRIPTION: Returns the EventInfo struct associated with this GPE.471* Validates the GpeBlock and the GpeNumber472*473* Should be called only when the GPE lists are semaphore locked474* and not subject to change.475*476******************************************************************************/477478ACPI_GPE_EVENT_INFO *479AcpiEvGetGpeEventInfo (480ACPI_HANDLE GpeDevice,481UINT32 GpeNumber)482{483ACPI_OPERAND_OBJECT *ObjDesc;484ACPI_GPE_EVENT_INFO *GpeInfo;485UINT32 i;486487488ACPI_FUNCTION_ENTRY ();489490491/* A NULL GpeDevice means use the FADT-defined GPE block(s) */492493if (!GpeDevice)494{495/* Examine GPE Block 0 and 1 (These blocks are permanent) */496497for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++)498{499GpeInfo = AcpiEvLowGetGpeInfo (GpeNumber,500AcpiGbl_GpeFadtBlocks[i]);501if (GpeInfo)502{503return (GpeInfo);504}505}506507/* The GpeNumber was not in the range of either FADT GPE block */508509return (NULL);510}511512/* A Non-NULL GpeDevice means this is a GPE Block Device */513514ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) GpeDevice);515if (!ObjDesc ||516!ObjDesc->Device.GpeBlock)517{518return (NULL);519}520521return (AcpiEvLowGetGpeInfo (GpeNumber, ObjDesc->Device.GpeBlock));522}523524525/*******************************************************************************526*527* FUNCTION: AcpiEvGpeDetect528*529* PARAMETERS: GpeXruptList - Interrupt block for this interrupt.530* Can have multiple GPE blocks attached.531*532* RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED533*534* DESCRIPTION: Detect if any GP events have occurred. This function is535* executed at interrupt level.536*537******************************************************************************/538539UINT32540AcpiEvGpeDetect (541ACPI_GPE_XRUPT_INFO *GpeXruptList)542{543ACPI_GPE_BLOCK_INFO *GpeBlock;544ACPI_NAMESPACE_NODE *GpeDevice;545ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;546ACPI_GPE_EVENT_INFO *GpeEventInfo;547UINT32 GpeNumber;548UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;549ACPI_CPU_FLAGS Flags;550UINT32 i;551UINT32 j;552553554ACPI_FUNCTION_NAME (EvGpeDetect);555556/* Check for the case where there are no GPEs */557558if (!GpeXruptList)559{560return (IntStatus);561}562563/*564* We need to obtain the GPE lock for both the data structs and registers565* Note: Not necessary to obtain the hardware lock, since the GPE566* registers are owned by the GpeLock.567*/568Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);569570/* Examine all GPE blocks attached to this interrupt level */571572GpeBlock = GpeXruptList->GpeBlockListHead;573while (GpeBlock)574{575GpeDevice = GpeBlock->Node;576577/*578* Read all of the 8-bit GPE status and enable registers in this GPE579* block, saving all of them. Find all currently active GP events.580*/581for (i = 0; i < GpeBlock->RegisterCount; i++)582{583/* Get the next status/enable pair */584585GpeRegisterInfo = &GpeBlock->RegisterInfo[i];586587/*588* Optimization: If there are no GPEs enabled within this589* register, we can safely ignore the entire register.590*/591if (!(GpeRegisterInfo->EnableForRun |592GpeRegisterInfo->EnableForWake))593{594ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,595"Ignore disabled registers for GPE %02X-%02X: "596"RunEnable=%02X, WakeEnable=%02X\n",597GpeRegisterInfo->BaseGpeNumber,598GpeRegisterInfo->BaseGpeNumber + (ACPI_GPE_REGISTER_WIDTH - 1),599GpeRegisterInfo->EnableForRun,600GpeRegisterInfo->EnableForWake));601continue;602}603604/* Now look at the individual GPEs in this byte register */605606for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++)607{608/* Detect and dispatch one GPE bit */609610GpeEventInfo = &GpeBlock->EventInfo[((ACPI_SIZE) i *611ACPI_GPE_REGISTER_WIDTH) + j];612GpeNumber = j + GpeRegisterInfo->BaseGpeNumber;613AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);614IntStatus |= AcpiEvDetectGpe (615GpeDevice, GpeEventInfo, GpeNumber);616Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);617}618}619620GpeBlock = GpeBlock->Next;621}622623AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);624return (IntStatus);625}626627628/*******************************************************************************629*630* FUNCTION: AcpiEvAsynchExecuteGpeMethod631*632* PARAMETERS: Context (GpeEventInfo) - Info for this GPE633*634* RETURN: None635*636* DESCRIPTION: Perform the actual execution of a GPE control method. This637* function is called from an invocation of AcpiOsExecute and638* therefore does NOT execute at interrupt level - so that639* the control method itself is not executed in the context of640* an interrupt handler.641*642******************************************************************************/643644static void ACPI_SYSTEM_XFACE645AcpiEvAsynchExecuteGpeMethod (646void *Context)647{648ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;649ACPI_STATUS Status = AE_OK;650ACPI_EVALUATE_INFO *Info;651ACPI_GPE_NOTIFY_INFO *Notify;652653654ACPI_FUNCTION_TRACE (EvAsynchExecuteGpeMethod);655656657/* Do the correct dispatch - normal method or implicit notify */658659switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))660{661case ACPI_GPE_DISPATCH_NOTIFY:662/*663* Implicit notify.664* Dispatch a DEVICE_WAKE notify to the appropriate handler.665* NOTE: the request is queued for execution after this method666* completes. The notify handlers are NOT invoked synchronously667* from this thread -- because handlers may in turn run other668* control methods.669*670* June 2012: Expand implicit notify mechanism to support671* notifies on multiple device objects.672*/673Notify = GpeEventInfo->Dispatch.NotifyList;674while (ACPI_SUCCESS (Status) && Notify)675{676Status = AcpiEvQueueNotifyRequest (677Notify->DeviceNode, ACPI_NOTIFY_DEVICE_WAKE);678679Notify = Notify->Next;680}681break;682683case ACPI_GPE_DISPATCH_METHOD:684685/* Allocate the evaluation information block */686687Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));688if (!Info)689{690Status = AE_NO_MEMORY;691}692else693{694/*695* Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the696* _Lxx/_Exx control method that corresponds to this GPE697*/698Info->PrefixNode = GpeEventInfo->Dispatch.MethodNode;699Info->Flags = ACPI_IGNORE_RETURN_VALUE;700701Status = AcpiNsEvaluate (Info);702ACPI_FREE (Info);703}704705if (ACPI_FAILURE (Status))706{707ACPI_EXCEPTION ((AE_INFO, Status,708"while evaluating GPE method [%4.4s]",709AcpiUtGetNodeName (GpeEventInfo->Dispatch.MethodNode)));710}711break;712713default:714715goto ErrorExit; /* Should never happen */716}717718/* Defer enabling of GPE until all notify handlers are done */719720Status = AcpiOsExecute (OSL_NOTIFY_HANDLER,721AcpiEvAsynchEnableGpe, GpeEventInfo);722if (ACPI_SUCCESS (Status))723{724return_VOID;725}726727ErrorExit:728AcpiEvAsynchEnableGpe (GpeEventInfo);729return_VOID;730}731732733/*******************************************************************************734*735* FUNCTION: AcpiEvAsynchEnableGpe736*737* PARAMETERS: Context (GpeEventInfo) - Info for this GPE738* Callback from AcpiOsExecute739*740* RETURN: None741*742* DESCRIPTION: Asynchronous clear/enable for GPE. This allows the GPE to743* complete (i.e., finish execution of Notify)744*745******************************************************************************/746747static void ACPI_SYSTEM_XFACE748AcpiEvAsynchEnableGpe (749void *Context)750{751ACPI_GPE_EVENT_INFO *GpeEventInfo = Context;752ACPI_CPU_FLAGS Flags;753754755Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);756(void) AcpiEvFinishGpe (GpeEventInfo);757AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);758759return;760}761762763/*******************************************************************************764*765* FUNCTION: AcpiEvFinishGpe766*767* PARAMETERS: GpeEventInfo - Info for this GPE768*769* RETURN: Status770*771* DESCRIPTION: Clear/Enable a GPE. Common code that is used after execution772* of a GPE method or a synchronous or asynchronous GPE handler.773*774******************************************************************************/775776ACPI_STATUS777AcpiEvFinishGpe (778ACPI_GPE_EVENT_INFO *GpeEventInfo)779{780ACPI_STATUS Status;781782783if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==784ACPI_GPE_LEVEL_TRIGGERED)785{786/*787* GPE is level-triggered, we clear the GPE status bit after788* handling the event.789*/790Status = AcpiHwClearGpe (GpeEventInfo);791if (ACPI_FAILURE (Status))792{793return (Status);794}795}796797/*798* Enable this GPE, conditionally. This means that the GPE will799* only be physically enabled if the EnableMask bit is set800* in the EventInfo.801*/802(void) AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);803GpeEventInfo->DisableForDispatch = FALSE;804return (AE_OK);805}806807808/*******************************************************************************809*810* FUNCTION: AcpiEvDetectGpe811*812* PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1813* GpeEventInfo - Info for this GPE814* GpeNumber - Number relative to the parent GPE block815*816* RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED817*818* DESCRIPTION: Detect and dispatch a General Purpose Event to either a function819* (e.g. EC) or method (e.g. _Lxx/_Exx) handler.820* NOTE: GPE is W1C, so it is possible to handle a single GPE from both821* task and irq context in parallel as long as the process to822* detect and mask the GPE is atomic.823* However the atomicity of ACPI_GPE_DISPATCH_RAW_HANDLER is824* dependent on the raw handler itself.825*826******************************************************************************/827828UINT32829AcpiEvDetectGpe (830ACPI_NAMESPACE_NODE *GpeDevice,831ACPI_GPE_EVENT_INFO *GpeEventInfo,832UINT32 GpeNumber)833{834UINT32 IntStatus = ACPI_INTERRUPT_NOT_HANDLED;835UINT8 EnabledStatusByte;836UINT64 StatusReg;837UINT64 EnableReg;838UINT32 RegisterBit;839ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;840ACPI_GPE_HANDLER_INFO *GpeHandlerInfo;841ACPI_CPU_FLAGS Flags;842ACPI_STATUS Status;843844845ACPI_FUNCTION_TRACE (EvGpeDetect);846847848Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);849850if (!GpeEventInfo)851{852GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);853if (!GpeEventInfo)854{855goto ErrorExit;856}857}858859/* Get the info block for the entire GPE register */860861GpeRegisterInfo = GpeEventInfo->RegisterInfo;862863/* Get the register bitmask for this GPE */864865RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);866867/* GPE currently enabled (enable bit == 1)? */868869Status = AcpiHwRead (&EnableReg, &GpeRegisterInfo->EnableAddress);870if (ACPI_FAILURE (Status))871{872goto ErrorExit;873}874875/* GPE currently active (status bit == 1)? */876877Status = AcpiHwRead (&StatusReg, &GpeRegisterInfo->StatusAddress);878if (ACPI_FAILURE (Status))879{880goto ErrorExit;881}882883/* Check if there is anything active at all in this GPE */884885ACPI_DEBUG_PRINT ((ACPI_DB_INTERRUPTS,886"Read registers for GPE %02X: Status=%02X, Enable=%02X, "887"RunEnable=%02X, WakeEnable=%02X\n",888GpeNumber,889(UINT32) (StatusReg & RegisterBit),890(UINT32) (EnableReg & RegisterBit),891GpeRegisterInfo->EnableForRun,892GpeRegisterInfo->EnableForWake));893894EnabledStatusByte = (UINT8) (StatusReg & EnableReg);895if (!(EnabledStatusByte & RegisterBit))896{897goto ErrorExit;898}899900/* Invoke global event handler if present */901902AcpiGpeCount++;903if (AcpiGbl_GlobalEventHandler)904{905AcpiGbl_GlobalEventHandler (ACPI_EVENT_TYPE_GPE,906GpeDevice, GpeNumber,907AcpiGbl_GlobalEventHandlerContext);908}909910/* Found an active GPE */911912if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==913ACPI_GPE_DISPATCH_RAW_HANDLER)914{915/* Dispatch the event to a raw handler */916917GpeHandlerInfo = GpeEventInfo->Dispatch.Handler;918919/*920* There is no protection around the namespace node921* and the GPE handler to ensure a safe destruction922* because:923* 1. The namespace node is expected to always924* exist after loading a table.925* 2. The GPE handler is expected to be flushed by926* AcpiOsWaitEventsComplete() before the927* destruction.928*/929AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);930IntStatus |= GpeHandlerInfo->Address (931GpeDevice, GpeNumber, GpeHandlerInfo->Context);932Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);933}934else935{936/* Dispatch the event to a standard handler or method. */937938IntStatus |= AcpiEvGpeDispatch (GpeDevice,939GpeEventInfo, GpeNumber);940}941942ErrorExit:943AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);944return (IntStatus);945}946947948/*******************************************************************************949*950* FUNCTION: AcpiEvGpeDispatch951*952* PARAMETERS: GpeDevice - Device node. NULL for GPE0/GPE1953* GpeEventInfo - Info for this GPE954* GpeNumber - Number relative to the parent GPE block955*956* RETURN: INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED957*958* DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)959* or method (e.g. _Lxx/_Exx) handler.960*961******************************************************************************/962963UINT32964AcpiEvGpeDispatch (965ACPI_NAMESPACE_NODE *GpeDevice,966ACPI_GPE_EVENT_INFO *GpeEventInfo,967UINT32 GpeNumber)968{969ACPI_STATUS Status;970UINT32 ReturnValue;971972973ACPI_FUNCTION_TRACE (EvGpeDispatch);974975976/*977* Always disable the GPE so that it does not keep firing before978* any asynchronous activity completes (either from the execution979* of a GPE method or an asynchronous GPE handler.)980*981* If there is no handler or method to run, just disable the982* GPE and leave it disabled permanently to prevent further such983* pointless events from firing.984*/985Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);986if (ACPI_FAILURE (Status))987{988ACPI_EXCEPTION ((AE_INFO, Status,989"Unable to disable GPE %02X", GpeNumber));990return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);991}992993/*994* If edge-triggered, clear the GPE status bit now. Note that995* level-triggered events are cleared after the GPE is serviced.996*/997if ((GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK) ==998ACPI_GPE_EDGE_TRIGGERED)999{1000Status = AcpiHwClearGpe (GpeEventInfo);1001if (ACPI_FAILURE (Status))1002{1003ACPI_EXCEPTION ((AE_INFO, Status,1004"Unable to clear GPE %02X", GpeNumber));1005(void) AcpiHwLowSetGpe (1006GpeEventInfo, ACPI_GPE_CONDITIONAL_ENABLE);1007return_UINT32 (ACPI_INTERRUPT_NOT_HANDLED);1008}1009}10101011GpeEventInfo->DisableForDispatch = TRUE;10121013/*1014* Dispatch the GPE to either an installed handler or the control1015* method associated with this GPE (_Lxx or _Exx). If a handler1016* exists, we invoke it and do not attempt to run the method.1017* If there is neither a handler nor a method, leave the GPE1018* disabled.1019*/1020switch (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags))1021{1022case ACPI_GPE_DISPATCH_HANDLER:10231024/* Invoke the installed handler (at interrupt level) */10251026ReturnValue = GpeEventInfo->Dispatch.Handler->Address (1027GpeDevice, GpeNumber,1028GpeEventInfo->Dispatch.Handler->Context);10291030/* If requested, clear (if level-triggered) and re-enable the GPE */10311032if (ReturnValue & ACPI_REENABLE_GPE)1033{1034(void) AcpiEvFinishGpe (GpeEventInfo);1035}1036break;10371038case ACPI_GPE_DISPATCH_METHOD:1039case ACPI_GPE_DISPATCH_NOTIFY:1040/*1041* Execute the method associated with the GPE1042* NOTE: Level-triggered GPEs are cleared after the method completes.1043*/1044Status = AcpiOsExecute (OSL_GPE_HANDLER,1045AcpiEvAsynchExecuteGpeMethod, GpeEventInfo);1046if (ACPI_FAILURE (Status))1047{1048ACPI_EXCEPTION ((AE_INFO, Status,1049"Unable to queue handler for GPE %02X - event disabled",1050GpeNumber));1051}1052break;10531054default:1055/*1056* No handler or method to run!1057* 03/2010: This case should no longer be possible. We will not allow1058* a GPE to be enabled if it has no handler or method.1059*/1060ACPI_ERROR ((AE_INFO,1061"No handler or method for GPE %02X, disabling event",1062GpeNumber));1063break;1064}10651066return_UINT32 (ACPI_INTERRUPT_HANDLED);1067}10681069#endif /* !ACPI_REDUCED_HARDWARE */107010711072