Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /******************************************************************************
  2.  *
  3.  * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
  4.  *
  5.  *****************************************************************************/
  6.  
  7. /******************************************************************************
  8.  *
  9.  * 1. Copyright Notice
  10.  *
  11.  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
  12.  * All rights reserved.
  13.  *
  14.  * 2. License
  15.  *
  16.  * 2.1. This is your license from Intel Corp. under its intellectual property
  17.  * rights.  You may have additional license terms from the party that provided
  18.  * you this software, covering your right to use that party's intellectual
  19.  * property rights.
  20.  *
  21.  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  22.  * copy of the source code appearing in this file ("Covered Code") an
  23.  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  24.  * base code distributed originally by Intel ("Original Intel Code") to copy,
  25.  * make derivatives, distribute, use and display any portion of the Covered
  26.  * Code in any form, with the right to sublicense such rights; and
  27.  *
  28.  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  29.  * license (with the right to sublicense), under only those claims of Intel
  30.  * patents that are infringed by the Original Intel Code, to make, use, sell,
  31.  * offer to sell, and import the Covered Code and derivative works thereof
  32.  * solely to the minimum extent necessary to exercise the above copyright
  33.  * license, and in no event shall the patent license extend to any additions
  34.  * to or modifications of the Original Intel Code.  No other license or right
  35.  * is granted directly or by implication, estoppel or otherwise;
  36.  *
  37.  * The above copyright and patent license is granted only if the following
  38.  * conditions are met:
  39.  *
  40.  * 3. Conditions
  41.  *
  42.  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  43.  * Redistribution of source code of any substantial portion of the Covered
  44.  * Code or modification with rights to further distribute source must include
  45.  * the above Copyright Notice, the above License, this list of Conditions,
  46.  * and the following Disclaimer and Export Compliance provision.  In addition,
  47.  * Licensee must cause all Covered Code to which Licensee contributes to
  48.  * contain a file documenting the changes Licensee made to create that Covered
  49.  * Code and the date of any change.  Licensee must include in that file the
  50.  * documentation of any changes made by any predecessor Licensee.  Licensee
  51.  * must include a prominent statement that the modification is derived,
  52.  * directly or indirectly, from Original Intel Code.
  53.  *
  54.  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  55.  * Redistribution of source code of any substantial portion of the Covered
  56.  * Code or modification without rights to further distribute source must
  57.  * include the following Disclaimer and Export Compliance provision in the
  58.  * documentation and/or other materials provided with distribution.  In
  59.  * addition, Licensee may not authorize further sublicense of source of any
  60.  * portion of the Covered Code, and must include terms to the effect that the
  61.  * license from Licensee to its licensee is limited to the intellectual
  62.  * property embodied in the software Licensee provides to its licensee, and
  63.  * not to intellectual property embodied in modifications its licensee may
  64.  * make.
  65.  *
  66.  * 3.3. Redistribution of Executable. Redistribution in executable form of any
  67.  * substantial portion of the Covered Code or modification must reproduce the
  68.  * above Copyright Notice, and the following Disclaimer and Export Compliance
  69.  * provision in the documentation and/or other materials provided with the
  70.  * distribution.
  71.  *
  72.  * 3.4. Intel retains all right, title, and interest in and to the Original
  73.  * Intel Code.
  74.  *
  75.  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  76.  * Intel shall be used in advertising or otherwise to promote the sale, use or
  77.  * other dealings in products derived from or relating to the Covered Code
  78.  * without prior written authorization from Intel.
  79.  *
  80.  * 4. Disclaimer and Export Compliance
  81.  *
  82.  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  83.  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  84.  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
  85.  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
  86.  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
  87.  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  88.  * PARTICULAR PURPOSE.
  89.  *
  90.  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  91.  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  92.  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  93.  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  94.  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  95.  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
  96.  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  97.  * LIMITED REMEDY.
  98.  *
  99.  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  100.  * software or system incorporating such software without first obtaining any
  101.  * required license or other approval from the U. S. Department of Commerce or
  102.  * any other agency or department of the United States Government.  In the
  103.  * event Licensee exports any such software from the United States or
  104.  * re-exports any such software from a foreign destination, Licensee shall
  105.  * ensure that the distribution and export/re-export of the software is in
  106.  * compliance with all laws, regulations, orders, or other restrictions of the
  107.  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  108.  * any of its subsidiaries will export/re-export any technical data, process,
  109.  * software, or service, directly or indirectly, to any country for which the
  110.  * United States government or any agency thereof requires an export license,
  111.  * other governmental approval, or letter of assurance, without first obtaining
  112.  * such license, approval or letter.
  113.  *
  114.  *****************************************************************************/
  115.  
  116.  
  117. #define __EVXFGPE_C__
  118.  
  119. #include "acpi.h"
  120. #include "accommon.h"
  121. #include "acevents.h"
  122. #include "acnamesp.h"
  123.  
  124. #define _COMPONENT          ACPI_EVENTS
  125.         ACPI_MODULE_NAME    ("evxfgpe")
  126.  
  127.  
  128. /*******************************************************************************
  129.  *
  130.  * FUNCTION:    AcpiUpdateAllGpes
  131.  *
  132.  * PARAMETERS:  None
  133.  *
  134.  * RETURN:      Status
  135.  *
  136.  * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
  137.  *              associated _Lxx or _Exx methods and are not pointed to by any
  138.  *              device _PRW methods (this indicates that these GPEs are
  139.  *              generally intended for system or device wakeup. Such GPEs
  140.  *              have to be enabled directly when the devices whose _PRW
  141.  *              methods point to them are set up for wakeup signaling.)
  142.  *
  143.  * NOTE: Should be called after any GPEs are added to the system. Primarily,
  144.  * after the system _PRW methods have been run, but also after a GPE Block
  145.  * Device has been added or if any new GPE methods have been added via a
  146.  * dynamic table load.
  147.  *
  148.  ******************************************************************************/
  149.  
  150. ACPI_STATUS
  151. AcpiUpdateAllGpes (
  152.     void)
  153. {
  154.     ACPI_STATUS             Status;
  155.  
  156.  
  157.     ACPI_FUNCTION_TRACE (AcpiUpdateGpes);
  158.  
  159.  
  160.     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
  161.     if (ACPI_FAILURE (Status))
  162.     {
  163.         return_ACPI_STATUS (Status);
  164.     }
  165.  
  166.     if (AcpiGbl_AllGpesInitialized)
  167.     {
  168.         goto UnlockAndExit;
  169.     }
  170.  
  171.     Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
  172.     if (ACPI_SUCCESS (Status))
  173.     {
  174.         AcpiGbl_AllGpesInitialized = TRUE;
  175.     }
  176.  
  177. UnlockAndExit:
  178.     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
  179.     return_ACPI_STATUS (Status);
  180. }
  181.  
  182. ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
  183.  
  184.  
  185. /*******************************************************************************
  186.  *
  187.  * FUNCTION:    AcpiEnableGpe
  188.  *
  189.  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  190.  *              GpeNumber           - GPE level within the GPE block
  191.  *
  192.  * RETURN:      Status
  193.  *
  194.  * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
  195.  *              hardware-enabled.
  196.  *
  197.  ******************************************************************************/
  198.  
  199. ACPI_STATUS
  200. AcpiEnableGpe (
  201.     ACPI_HANDLE             GpeDevice,
  202.     UINT32                  GpeNumber)
  203. {
  204.     ACPI_STATUS             Status = AE_BAD_PARAMETER;
  205.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  206.     ACPI_CPU_FLAGS          Flags;
  207.  
  208.  
  209.     ACPI_FUNCTION_TRACE (AcpiEnableGpe);
  210.  
  211.  
  212.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  213.  
  214.     /* Ensure that we have a valid GPE number */
  215.  
  216.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  217.     if (GpeEventInfo)
  218.     {
  219.         Status = AcpiEvAddGpeReference (GpeEventInfo);
  220.     }
  221.  
  222.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  223.     return_ACPI_STATUS (Status);
  224. }
  225.  
  226. ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
  227.  
  228.  
  229. /*******************************************************************************
  230.  *
  231.  * FUNCTION:    AcpiDisableGpe
  232.  *
  233.  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  234.  *              GpeNumber           - GPE level within the GPE block
  235.  *
  236.  * RETURN:      Status
  237.  *
  238.  * DESCRIPTION: Remove a reference to a GPE. When the last reference is
  239.  *              removed, only then is the GPE disabled (for runtime GPEs), or
  240.  *              the GPE mask bit disabled (for wake GPEs)
  241.  *
  242.  ******************************************************************************/
  243.  
  244. ACPI_STATUS
  245. AcpiDisableGpe (
  246.     ACPI_HANDLE             GpeDevice,
  247.     UINT32                  GpeNumber)
  248. {
  249.     ACPI_STATUS             Status = AE_BAD_PARAMETER;
  250.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  251.     ACPI_CPU_FLAGS          Flags;
  252.  
  253.  
  254.     ACPI_FUNCTION_TRACE (AcpiDisableGpe);
  255.  
  256.  
  257.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  258.  
  259.     /* Ensure that we have a valid GPE number */
  260.  
  261.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  262.     if (GpeEventInfo)
  263.     {
  264.         Status = AcpiEvRemoveGpeReference (GpeEventInfo);
  265.     }
  266.  
  267.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  268.     return_ACPI_STATUS (Status);
  269. }
  270.  
  271. ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
  272.  
  273.  
  274. /*******************************************************************************
  275.  *
  276.  * FUNCTION:    AcpiSetGpe
  277.  *
  278.  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  279.  *              GpeNumber           - GPE level within the GPE block
  280.  *              Action              - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
  281.  *
  282.  * RETURN:      Status
  283.  *
  284.  * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
  285.  *              the reference count mechanism used in the AcpiEnableGpe and
  286.  *              AcpiDisableGpe interfaces -- and should be used with care.
  287.  *
  288.  * Note: Typically used to disable a runtime GPE for short period of time,
  289.  * then re-enable it, without disturbing the existing reference counts. This
  290.  * is useful, for example, in the Embedded Controller (EC) driver.
  291.  *
  292.  ******************************************************************************/
  293.  
  294. ACPI_STATUS
  295. AcpiSetGpe (
  296.     ACPI_HANDLE             GpeDevice,
  297.     UINT32                  GpeNumber,
  298.     UINT8                   Action)
  299. {
  300.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  301.     ACPI_STATUS             Status;
  302.     ACPI_CPU_FLAGS          Flags;
  303.  
  304.  
  305.     ACPI_FUNCTION_TRACE (AcpiSetGpe);
  306.  
  307.  
  308.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  309.  
  310.     /* Ensure that we have a valid GPE number */
  311.  
  312.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  313.     if (!GpeEventInfo)
  314.     {
  315.         Status = AE_BAD_PARAMETER;
  316.         goto UnlockAndExit;
  317.     }
  318.  
  319.     /* Perform the action */
  320.  
  321.     switch (Action)
  322.     {
  323.     case ACPI_GPE_ENABLE:
  324.         Status = AcpiEvEnableGpe (GpeEventInfo);
  325.         break;
  326.  
  327.     case ACPI_GPE_DISABLE:
  328.         Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
  329.         break;
  330.  
  331.     default:
  332.         Status = AE_BAD_PARAMETER;
  333.         break;
  334.     }
  335.  
  336. UnlockAndExit:
  337.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  338.     return_ACPI_STATUS (Status);
  339. }
  340.  
  341. ACPI_EXPORT_SYMBOL (AcpiSetGpe)
  342.  
  343.  
  344. /*******************************************************************************
  345.  *
  346.  * FUNCTION:    AcpiSetupGpeForWake
  347.  *
  348.  * PARAMETERS:  WakeDevice          - Device associated with the GPE (via _PRW)
  349.  *              GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  350.  *              GpeNumber           - GPE level within the GPE block
  351.  *
  352.  * RETURN:      Status
  353.  *
  354.  * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
  355.  *              interface is intended to be used as the host executes the
  356.  *              _PRW methods (Power Resources for Wake) in the system tables.
  357.  *              Each _PRW appears under a Device Object (The WakeDevice), and
  358.  *              contains the info for the wake GPE associated with the
  359.  *              WakeDevice.
  360.  *
  361.  ******************************************************************************/
  362.  
  363. ACPI_STATUS
  364. AcpiSetupGpeForWake (
  365.     ACPI_HANDLE             WakeDevice,
  366.     ACPI_HANDLE             GpeDevice,
  367.     UINT32                  GpeNumber)
  368. {
  369.     ACPI_STATUS             Status = AE_BAD_PARAMETER;
  370.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  371.     ACPI_NAMESPACE_NODE     *DeviceNode;
  372.     ACPI_CPU_FLAGS          Flags;
  373.  
  374.  
  375.     ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
  376.  
  377.  
  378.     /* Parameter Validation */
  379.  
  380.     if (!WakeDevice)
  381.     {
  382.         /*
  383.          * By forcing WakeDevice to be valid, we automatically enable the
  384.          * implicit notify feature on all hosts.
  385.          */
  386.         return_ACPI_STATUS (AE_BAD_PARAMETER);
  387.     }
  388.  
  389.     /* Handle root object case */
  390.  
  391.     if (WakeDevice == ACPI_ROOT_OBJECT)
  392.     {
  393.         DeviceNode = AcpiGbl_RootNode;
  394.     }
  395.     else
  396.     {
  397.         DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
  398.     }
  399.  
  400.     /* Validate WakeDevice is of type Device */
  401.  
  402.     if (DeviceNode->Type != ACPI_TYPE_DEVICE)
  403.     {
  404.         return_ACPI_STATUS (AE_BAD_PARAMETER);
  405.     }
  406.  
  407.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  408.  
  409.     /* Ensure that we have a valid GPE number */
  410.  
  411.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  412.     if (GpeEventInfo)
  413.     {
  414.         /*
  415.          * If there is no method or handler for this GPE, then the
  416.          * WakeDevice will be notified whenever this GPE fires (aka
  417.          * "implicit notify") Note: The GPE is assumed to be
  418.          * level-triggered (for windows compatibility).
  419.          */
  420.         if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
  421.                 ACPI_GPE_DISPATCH_NONE)
  422.         {
  423.             GpeEventInfo->Flags =
  424.                 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
  425.             GpeEventInfo->Dispatch.DeviceNode = DeviceNode;
  426.         }
  427.  
  428.         GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
  429.         Status = AE_OK;
  430.     }
  431.  
  432.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  433.     return_ACPI_STATUS (Status);
  434. }
  435.  
  436. ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
  437.  
  438.  
  439. /*******************************************************************************
  440.  *
  441.  * FUNCTION:    AcpiSetGpeWakeMask
  442.  *
  443.  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  444.  *              GpeNumber           - GPE level within the GPE block
  445.  *              Action              - Enable or Disable
  446.  *
  447.  * RETURN:      Status
  448.  *
  449.  * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
  450.  *              already be marked as a WAKE GPE.
  451.  *
  452.  ******************************************************************************/
  453.  
  454. ACPI_STATUS
  455. AcpiSetGpeWakeMask (
  456.     ACPI_HANDLE             GpeDevice,
  457.     UINT32                  GpeNumber,
  458.     UINT8                   Action)
  459. {
  460.     ACPI_STATUS             Status = AE_OK;
  461.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  462.     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
  463.     ACPI_CPU_FLAGS          Flags;
  464.     UINT32                  RegisterBit;
  465.  
  466.  
  467.     ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
  468.  
  469.  
  470.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  471.  
  472.     /*
  473.      * Ensure that we have a valid GPE number and that this GPE is in
  474.      * fact a wake GPE
  475.      */
  476.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  477.     if (!GpeEventInfo)
  478.     {
  479.         Status = AE_BAD_PARAMETER;
  480.         goto UnlockAndExit;
  481.     }
  482.  
  483.     if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
  484.     {
  485.         Status = AE_TYPE;
  486.         goto UnlockAndExit;
  487.     }
  488.  
  489.     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
  490.     if (!GpeRegisterInfo)
  491.     {
  492.         Status = AE_NOT_EXIST;
  493.         goto UnlockAndExit;
  494.     }
  495.  
  496.     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
  497.  
  498.     /* Perform the action */
  499.  
  500.     switch (Action)
  501.     {
  502.     case ACPI_GPE_ENABLE:
  503.         ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
  504.         break;
  505.  
  506.     case ACPI_GPE_DISABLE:
  507.         ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
  508.         break;
  509.  
  510.     default:
  511.         ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
  512.         Status = AE_BAD_PARAMETER;
  513.         break;
  514.     }
  515.  
  516. UnlockAndExit:
  517.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  518.     return_ACPI_STATUS (Status);
  519. }
  520.  
  521. ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
  522.  
  523.  
  524. /*******************************************************************************
  525.  *
  526.  * FUNCTION:    AcpiClearGpe
  527.  *
  528.  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  529.  *              GpeNumber           - GPE level within the GPE block
  530.  *
  531.  * RETURN:      Status
  532.  *
  533.  * DESCRIPTION: Clear an ACPI event (general purpose)
  534.  *
  535.  ******************************************************************************/
  536.  
  537. ACPI_STATUS
  538. AcpiClearGpe (
  539.     ACPI_HANDLE             GpeDevice,
  540.     UINT32                  GpeNumber)
  541. {
  542.     ACPI_STATUS             Status = AE_OK;
  543.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  544.     ACPI_CPU_FLAGS          Flags;
  545.  
  546.  
  547.     ACPI_FUNCTION_TRACE (AcpiClearGpe);
  548.  
  549.  
  550.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  551.  
  552.     /* Ensure that we have a valid GPE number */
  553.  
  554.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  555.     if (!GpeEventInfo)
  556.     {
  557.         Status = AE_BAD_PARAMETER;
  558.         goto UnlockAndExit;
  559.     }
  560.  
  561.     Status = AcpiHwClearGpe (GpeEventInfo);
  562.  
  563. UnlockAndExit:
  564.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  565.     return_ACPI_STATUS (Status);
  566. }
  567.  
  568. ACPI_EXPORT_SYMBOL (AcpiClearGpe)
  569.  
  570.  
  571. /*******************************************************************************
  572.  *
  573.  * FUNCTION:    AcpiGetGpeStatus
  574.  *
  575.  * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
  576.  *              GpeNumber           - GPE level within the GPE block
  577.  *              EventStatus         - Where the current status of the event
  578.  *                                    will be returned
  579.  *
  580.  * RETURN:      Status
  581.  *
  582.  * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
  583.  *
  584.  ******************************************************************************/
  585.  
  586. ACPI_STATUS
  587. AcpiGetGpeStatus (
  588.     ACPI_HANDLE             GpeDevice,
  589.     UINT32                  GpeNumber,
  590.     ACPI_EVENT_STATUS       *EventStatus)
  591. {
  592.     ACPI_STATUS             Status = AE_OK;
  593.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  594.     ACPI_CPU_FLAGS          Flags;
  595.  
  596.  
  597.     ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
  598.  
  599.  
  600.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  601.  
  602.     /* Ensure that we have a valid GPE number */
  603.  
  604.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  605.     if (!GpeEventInfo)
  606.     {
  607.         Status = AE_BAD_PARAMETER;
  608.         goto UnlockAndExit;
  609.     }
  610.  
  611.     /* Obtain status on the requested GPE number */
  612.  
  613.     Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
  614.  
  615. UnlockAndExit:
  616.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  617.     return_ACPI_STATUS (Status);
  618. }
  619.  
  620. ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
  621.  
  622.  
  623. /*******************************************************************************
  624.  *
  625.  * FUNCTION:    AcpiFinishGpe
  626.  *
  627.  * PARAMETERS:  GpeDevice           - Namespace node for the GPE Block
  628.  *                                    (NULL for FADT defined GPEs)
  629.  *              GpeNumber           - GPE level within the GPE block
  630.  *
  631.  * RETURN:      Status
  632.  *
  633.  * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
  634.  *              processing. Intended for use by asynchronous host-installed
  635.  *              GPE handlers. The GPE is only reenabled if the EnableForRun bit
  636.  *              is set in the GPE info.
  637.  *
  638.  ******************************************************************************/
  639.  
  640. ACPI_STATUS
  641. AcpiFinishGpe (
  642.     ACPI_HANDLE             GpeDevice,
  643.     UINT32                  GpeNumber)
  644. {
  645.     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
  646.     ACPI_STATUS             Status;
  647.     ACPI_CPU_FLAGS          Flags;
  648.  
  649.  
  650.     ACPI_FUNCTION_TRACE (AcpiFinishGpe);
  651.  
  652.  
  653.     Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
  654.  
  655.     /* Ensure that we have a valid GPE number */
  656.  
  657.     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
  658.     if (!GpeEventInfo)
  659.     {
  660.         Status = AE_BAD_PARAMETER;
  661.         goto UnlockAndExit;
  662.     }
  663.  
  664.     Status = AcpiEvFinishGpe (GpeEventInfo);
  665.  
  666. UnlockAndExit:
  667.     AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
  668.     return_ACPI_STATUS (Status);
  669. }
  670.  
  671. ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
  672.  
  673.  
  674. /******************************************************************************
  675.  *
  676.  * FUNCTION:    AcpiDisableAllGpes
  677.  *
  678.  * PARAMETERS:  None
  679.  *
  680.  * RETURN:      Status
  681.  *
  682.  * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  683.  *
  684.  ******************************************************************************/
  685.  
  686. ACPI_STATUS
  687. AcpiDisableAllGpes (
  688.     void)
  689. {
  690.     ACPI_STATUS             Status;
  691.  
  692.  
  693.     ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
  694.  
  695.  
  696.     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
  697.     if (ACPI_FAILURE (Status))
  698.     {
  699.         return_ACPI_STATUS (Status);
  700.     }
  701.  
  702.     Status = AcpiHwDisableAllGpes ();
  703.     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
  704.  
  705.     return_ACPI_STATUS (Status);
  706. }
  707.  
  708. ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
  709.  
  710.  
  711. /******************************************************************************
  712.  *
  713.  * FUNCTION:    AcpiEnableAllRuntimeGpes
  714.  *
  715.  * PARAMETERS:  None
  716.  *
  717.  * RETURN:      Status
  718.  *
  719.  * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  720.  *
  721.  ******************************************************************************/
  722.  
  723. ACPI_STATUS
  724. AcpiEnableAllRuntimeGpes (
  725.     void)
  726. {
  727.     ACPI_STATUS             Status;
  728.  
  729.  
  730.     ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
  731.  
  732.  
  733.     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
  734.     if (ACPI_FAILURE (Status))
  735.     {
  736.         return_ACPI_STATUS (Status);
  737.     }
  738.  
  739.     Status = AcpiHwEnableAllRuntimeGpes ();
  740.     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
  741.  
  742.     return_ACPI_STATUS (Status);
  743. }
  744.  
  745. ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
  746.  
  747.  
  748. /*******************************************************************************
  749.  *
  750.  * FUNCTION:    AcpiInstallGpeBlock
  751.  *
  752.  * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
  753.  *              GpeBlockAddress     - Address and SpaceID
  754.  *              RegisterCount       - Number of GPE register pairs in the block
  755.  *              InterruptNumber     - H/W interrupt for the block
  756.  *
  757.  * RETURN:      Status
  758.  *
  759.  * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
  760.  *              enabled here.
  761.  *
  762.  ******************************************************************************/
  763.  
  764. ACPI_STATUS
  765. AcpiInstallGpeBlock (
  766.     ACPI_HANDLE             GpeDevice,
  767.     ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
  768.     UINT32                  RegisterCount,
  769.     UINT32                  InterruptNumber)
  770. {
  771.     ACPI_STATUS             Status;
  772.     ACPI_OPERAND_OBJECT     *ObjDesc;
  773.     ACPI_NAMESPACE_NODE     *Node;
  774.     ACPI_GPE_BLOCK_INFO     *GpeBlock;
  775.  
  776.  
  777.     ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
  778.  
  779.  
  780.     if ((!GpeDevice)       ||
  781.         (!GpeBlockAddress) ||
  782.         (!RegisterCount))
  783.     {
  784.         return_ACPI_STATUS (AE_BAD_PARAMETER);
  785.     }
  786.  
  787.     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
  788.     if (ACPI_FAILURE (Status))
  789.     {
  790.         return (Status);
  791.     }
  792.  
  793.     Node = AcpiNsValidateHandle (GpeDevice);
  794.     if (!Node)
  795.     {
  796.         Status = AE_BAD_PARAMETER;
  797.         goto UnlockAndExit;
  798.     }
  799.  
  800.     /*
  801.      * For user-installed GPE Block Devices, the GpeBlockBaseNumber
  802.      * is always zero
  803.      */
  804.     Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
  805.                 0, InterruptNumber, &GpeBlock);
  806.     if (ACPI_FAILURE (Status))
  807.     {
  808.         goto UnlockAndExit;
  809.     }
  810.  
  811.     /* Install block in the DeviceObject attached to the node */
  812.  
  813.     ObjDesc = AcpiNsGetAttachedObject (Node);
  814.     if (!ObjDesc)
  815.     {
  816.         /*
  817.          * No object, create a new one (Device nodes do not always have
  818.          * an attached object)
  819.          */
  820.         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
  821.         if (!ObjDesc)
  822.         {
  823.             Status = AE_NO_MEMORY;
  824.             goto UnlockAndExit;
  825.         }
  826.  
  827.         Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
  828.  
  829.         /* Remove local reference to the object */
  830.  
  831.         AcpiUtRemoveReference (ObjDesc);
  832.         if (ACPI_FAILURE (Status))
  833.         {
  834.             goto UnlockAndExit;
  835.         }
  836.     }
  837.  
  838.     /* Now install the GPE block in the DeviceObject */
  839.  
  840.     ObjDesc->Device.GpeBlock = GpeBlock;
  841.  
  842.  
  843. UnlockAndExit:
  844.     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
  845.     return_ACPI_STATUS (Status);
  846. }
  847.  
  848. ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
  849.  
  850.  
  851. /*******************************************************************************
  852.  *
  853.  * FUNCTION:    AcpiRemoveGpeBlock
  854.  *
  855.  * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
  856.  *
  857.  * RETURN:      Status
  858.  *
  859.  * DESCRIPTION: Remove a previously installed block of GPE registers
  860.  *
  861.  ******************************************************************************/
  862.  
  863. ACPI_STATUS
  864. AcpiRemoveGpeBlock (
  865.     ACPI_HANDLE             GpeDevice)
  866. {
  867.     ACPI_OPERAND_OBJECT     *ObjDesc;
  868.     ACPI_STATUS             Status;
  869.     ACPI_NAMESPACE_NODE     *Node;
  870.  
  871.  
  872.     ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
  873.  
  874.  
  875.     if (!GpeDevice)
  876.     {
  877.         return_ACPI_STATUS (AE_BAD_PARAMETER);
  878.     }
  879.  
  880.     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
  881.     if (ACPI_FAILURE (Status))
  882.     {
  883.         return (Status);
  884.     }
  885.  
  886.     Node = AcpiNsValidateHandle (GpeDevice);
  887.     if (!Node)
  888.     {
  889.         Status = AE_BAD_PARAMETER;
  890.         goto UnlockAndExit;
  891.     }
  892.  
  893.     /* Get the DeviceObject attached to the node */
  894.  
  895.     ObjDesc = AcpiNsGetAttachedObject (Node);
  896.     if (!ObjDesc ||
  897.         !ObjDesc->Device.GpeBlock)
  898.     {
  899.         return_ACPI_STATUS (AE_NULL_OBJECT);
  900.     }
  901.  
  902.     /* Delete the GPE block (but not the DeviceObject) */
  903.  
  904.     Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
  905.     if (ACPI_SUCCESS (Status))
  906.     {
  907.         ObjDesc->Device.GpeBlock = NULL;
  908.     }
  909.  
  910. UnlockAndExit:
  911.     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
  912.     return_ACPI_STATUS (Status);
  913. }
  914.  
  915. ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
  916.  
  917.  
  918. /*******************************************************************************
  919.  *
  920.  * FUNCTION:    AcpiGetGpeDevice
  921.  *
  922.  * PARAMETERS:  Index               - System GPE index (0-CurrentGpeCount)
  923.  *              GpeDevice           - Where the parent GPE Device is returned
  924.  *
  925.  * RETURN:      Status
  926.  *
  927.  * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
  928.  *              gpe device indicates that the gpe number is contained in one of
  929.  *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
  930.  *
  931.  ******************************************************************************/
  932.  
  933. ACPI_STATUS
  934. AcpiGetGpeDevice (
  935.     UINT32                  Index,
  936.     ACPI_HANDLE             *GpeDevice)
  937. {
  938.     ACPI_GPE_DEVICE_INFO    Info;
  939.     ACPI_STATUS             Status;
  940.  
  941.  
  942.     ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
  943.  
  944.  
  945.     if (!GpeDevice)
  946.     {
  947.         return_ACPI_STATUS (AE_BAD_PARAMETER);
  948.     }
  949.  
  950.     if (Index >= AcpiCurrentGpeCount)
  951.     {
  952.         return_ACPI_STATUS (AE_NOT_EXIST);
  953.     }
  954.  
  955.     /* Setup and walk the GPE list */
  956.  
  957.     Info.Index = Index;
  958.     Info.Status = AE_NOT_EXIST;
  959.     Info.GpeDevice = NULL;
  960.     Info.NextBlockBaseIndex = 0;
  961.  
  962.     Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
  963.     if (ACPI_FAILURE (Status))
  964.     {
  965.         return_ACPI_STATUS (Status);
  966.     }
  967.  
  968.     *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
  969.     return_ACPI_STATUS (Info.Status);
  970. }
  971.  
  972. ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
  973.