Subversion Repositories Kolibri OS

Rev

Rev 1498 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. /******************************************************************************
  3.  *
  4.  * Module Name: hwgpe - Low level GPE enable/disable/clear functions
  5.  *
  6.  *****************************************************************************/
  7.  
  8. /******************************************************************************
  9.  *
  10.  * 1. Copyright Notice
  11.  *
  12.  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
  13.  * All rights reserved.
  14.  *
  15.  * 2. License
  16.  *
  17.  * 2.1. This is your license from Intel Corp. under its intellectual property
  18.  * rights.  You may have additional license terms from the party that provided
  19.  * you this software, covering your right to use that party's intellectual
  20.  * property rights.
  21.  *
  22.  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
  23.  * copy of the source code appearing in this file ("Covered Code") an
  24.  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
  25.  * base code distributed originally by Intel ("Original Intel Code") to copy,
  26.  * make derivatives, distribute, use and display any portion of the Covered
  27.  * Code in any form, with the right to sublicense such rights; and
  28.  *
  29.  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
  30.  * license (with the right to sublicense), under only those claims of Intel
  31.  * patents that are infringed by the Original Intel Code, to make, use, sell,
  32.  * offer to sell, and import the Covered Code and derivative works thereof
  33.  * solely to the minimum extent necessary to exercise the above copyright
  34.  * license, and in no event shall the patent license extend to any additions
  35.  * to or modifications of the Original Intel Code.  No other license or right
  36.  * is granted directly or by implication, estoppel or otherwise;
  37.  *
  38.  * The above copyright and patent license is granted only if the following
  39.  * conditions are met:
  40.  *
  41.  * 3. Conditions
  42.  *
  43.  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
  44.  * Redistribution of source code of any substantial portion of the Covered
  45.  * Code or modification with rights to further distribute source must include
  46.  * the above Copyright Notice, the above License, this list of Conditions,
  47.  * and the following Disclaimer and Export Compliance provision.  In addition,
  48.  * Licensee must cause all Covered Code to which Licensee contributes to
  49.  * contain a file documenting the changes Licensee made to create that Covered
  50.  * Code and the date of any change.  Licensee must include in that file the
  51.  * documentation of any changes made by any predecessor Licensee.  Licensee
  52.  * must include a prominent statement that the modification is derived,
  53.  * directly or indirectly, from Original Intel Code.
  54.  *
  55.  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
  56.  * Redistribution of source code of any substantial portion of the Covered
  57.  * Code or modification without rights to further distribute source must
  58.  * include the following Disclaimer and Export Compliance provision in the
  59.  * documentation and/or other materials provided with distribution.  In
  60.  * addition, Licensee may not authorize further sublicense of source of any
  61.  * portion of the Covered Code, and must include terms to the effect that the
  62.  * license from Licensee to its licensee is limited to the intellectual
  63.  * property embodied in the software Licensee provides to its licensee, and
  64.  * not to intellectual property embodied in modifications its licensee may
  65.  * make.
  66.  *
  67.  * 3.3. Redistribution of Executable. Redistribution in executable form of any
  68.  * substantial portion of the Covered Code or modification must reproduce the
  69.  * above Copyright Notice, and the following Disclaimer and Export Compliance
  70.  * provision in the documentation and/or other materials provided with the
  71.  * distribution.
  72.  *
  73.  * 3.4. Intel retains all right, title, and interest in and to the Original
  74.  * Intel Code.
  75.  *
  76.  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
  77.  * Intel shall be used in advertising or otherwise to promote the sale, use or
  78.  * other dealings in products derived from or relating to the Covered Code
  79.  * without prior written authorization from Intel.
  80.  *
  81.  * 4. Disclaimer and Export Compliance
  82.  *
  83.  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
  84.  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
  85.  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
  86.  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
  87.  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
  88.  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
  89.  * PARTICULAR PURPOSE.
  90.  *
  91.  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
  92.  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
  93.  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
  94.  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
  95.  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
  96.  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
  97.  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
  98.  * LIMITED REMEDY.
  99.  *
  100.  * 4.3. Licensee shall not export, either directly or indirectly, any of this
  101.  * software or system incorporating such software without first obtaining any
  102.  * required license or other approval from the U. S. Department of Commerce or
  103.  * any other agency or department of the United States Government.  In the
  104.  * event Licensee exports any such software from the United States or
  105.  * re-exports any such software from a foreign destination, Licensee shall
  106.  * ensure that the distribution and export/re-export of the software is in
  107.  * compliance with all laws, regulations, orders, or other restrictions of the
  108.  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
  109.  * any of its subsidiaries will export/re-export any technical data, process,
  110.  * software, or service, directly or indirectly, to any country for which the
  111.  * United States government or any agency thereof requires an export license,
  112.  * other governmental approval, or letter of assurance, without first obtaining
  113.  * such license, approval or letter.
  114.  *
  115.  *****************************************************************************/
  116.  
  117. #include "acpi.h"
  118. #include "accommon.h"
  119. #include "acevents.h"
  120.  
  121. #define _COMPONENT          ACPI_HARDWARE
  122.         ACPI_MODULE_NAME    ("hwgpe")
  123.  
  124. /* Local prototypes */
  125.  
  126. static ACPI_STATUS
  127. AcpiHwEnableWakeupGpeBlock (
  128.     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
  129.     ACPI_GPE_BLOCK_INFO     *GpeBlock,
  130.     void                    *Context);
  131.  
  132.  
  133. /******************************************************************************
  134.  *
  135.  * FUNCTION:    AcpiHwGetGpeRegisterBit
  136.  *
  137.  * PARAMETERS:  GpeEventInfo        - Info block for the GPE
  138.  *              GpeRegisterInfo     - Info block for the GPE register
  139.  *
  140.  * RETURN:      Register mask with a one in the GPE bit position
  141.  *
  142.  * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
  143.  *              correct position for the input GPE.
  144.  *
  145.  ******************************************************************************/
  146.  
  147. UINT32
  148. AcpiHwGetGpeRegisterBit (
  149.     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
  150.     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo)
  151. {
  152.  
  153.     return ((UINT32) 1 <<
  154.         (GpeEventInfo->GpeNumber - GpeRegisterInfo->BaseGpeNumber));
  155. }
  156.  
  157.  
  158. /******************************************************************************
  159.  *
  160.  * FUNCTION:    AcpiHwLowSetGpe
  161.  *
  162.  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to be disabled
  163.  *              Action              - Enable or disable
  164.  *
  165.  * RETURN:      Status
  166.  *
  167.  * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
  168.  *
  169.  ******************************************************************************/
  170.  
  171. ACPI_STATUS
  172. AcpiHwLowSetGpe (
  173.     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
  174.     UINT32                  Action)
  175. {
  176.     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
  177.     ACPI_STATUS             Status;
  178.     UINT32                  EnableMask;
  179.     UINT32                  RegisterBit;
  180.  
  181.  
  182.     ACPI_FUNCTION_ENTRY ();
  183.  
  184.  
  185.     /* Get the info block for the entire GPE register */
  186.  
  187.     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
  188.     if (!GpeRegisterInfo)
  189.     {
  190.         return (AE_NOT_EXIST);
  191.     }
  192.  
  193.     /* Get current value of the enable register that contains this GPE */
  194.  
  195.     Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
  196.     if (ACPI_FAILURE (Status))
  197.     {
  198.         return (Status);
  199.     }
  200.  
  201.     /* Set or clear just the bit that corresponds to this GPE */
  202.  
  203.     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
  204.     switch (Action)
  205.     {
  206.     case ACPI_GPE_CONDITIONAL_ENABLE:
  207.  
  208.         /* Only enable if the EnableForRun bit is set */
  209.  
  210.         if (!(RegisterBit & GpeRegisterInfo->EnableForRun))
  211.         {
  212.             return (AE_BAD_PARAMETER);
  213.         }
  214.  
  215.         /*lint -fallthrough */
  216.  
  217.     case ACPI_GPE_ENABLE:
  218.         ACPI_SET_BIT (EnableMask, RegisterBit);
  219.         break;
  220.  
  221.     case ACPI_GPE_DISABLE:
  222.         ACPI_CLEAR_BIT (EnableMask, RegisterBit);
  223.         break;
  224.  
  225.     default:
  226.         ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u\n", Action));
  227.         return (AE_BAD_PARAMETER);
  228.     }
  229.  
  230.     /* Write the updated enable mask */
  231.  
  232.     Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
  233.     return (Status);
  234. }
  235.  
  236.  
  237. /******************************************************************************
  238.  *
  239.  * FUNCTION:    AcpiHwClearGpe
  240.  *
  241.  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to be cleared
  242.  *
  243.  * RETURN:      Status
  244.  *
  245.  * DESCRIPTION: Clear the status bit for a single GPE.
  246.  *
  247.  ******************************************************************************/
  248.  
  249. ACPI_STATUS
  250. AcpiHwClearGpe (
  251.     ACPI_GPE_EVENT_INFO     *GpeEventInfo)
  252. {
  253.     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
  254.     ACPI_STATUS             Status;
  255.     UINT32                  RegisterBit;
  256.  
  257.  
  258.     ACPI_FUNCTION_ENTRY ();
  259.  
  260.     /* Get the info block for the entire GPE register */
  261.  
  262.     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
  263.     if (!GpeRegisterInfo)
  264.     {
  265.         return (AE_NOT_EXIST);
  266.     }
  267.  
  268.     /*
  269.      * Write a one to the appropriate bit in the status register to
  270.      * clear this GPE.
  271.      */
  272.     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
  273.  
  274.     Status = AcpiHwWrite (RegisterBit,
  275.                     &GpeRegisterInfo->StatusAddress);
  276.  
  277.     return (Status);
  278. }
  279.  
  280.  
  281. /******************************************************************************
  282.  *
  283.  * FUNCTION:    AcpiHwGetGpeStatus
  284.  *
  285.  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to queried
  286.  *              EventStatus         - Where the GPE status is returned
  287.  *
  288.  * RETURN:      Status
  289.  *
  290.  * DESCRIPTION: Return the status of a single GPE.
  291.  *
  292.  ******************************************************************************/
  293.  
  294. ACPI_STATUS
  295. AcpiHwGetGpeStatus (
  296.     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
  297.     ACPI_EVENT_STATUS       *EventStatus)
  298. {
  299.     UINT32                  InByte;
  300.     UINT32                  RegisterBit;
  301.     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
  302.     ACPI_EVENT_STATUS       LocalEventStatus = 0;
  303.     ACPI_STATUS             Status;
  304.  
  305.  
  306.     ACPI_FUNCTION_ENTRY ();
  307.  
  308.  
  309.     if (!EventStatus)
  310.     {
  311.         return (AE_BAD_PARAMETER);
  312.     }
  313.  
  314.     /* Get the info block for the entire GPE register */
  315.  
  316.     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
  317.  
  318.     /* Get the register bitmask for this GPE */
  319.  
  320.     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
  321.  
  322.     /* GPE currently enabled? (enabled for runtime?) */
  323.  
  324.     if (RegisterBit & GpeRegisterInfo->EnableForRun)
  325.     {
  326.         LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
  327.     }
  328.  
  329.     /* GPE enabled for wake? */
  330.  
  331.     if (RegisterBit & GpeRegisterInfo->EnableForWake)
  332.     {
  333.         LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
  334.     }
  335.  
  336.     /* GPE currently active (status bit == 1)? */
  337.  
  338.     Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
  339.     if (ACPI_FAILURE (Status))
  340.     {
  341.         return (Status);
  342.     }
  343.  
  344.     if (RegisterBit & InByte)
  345.     {
  346.         LocalEventStatus |= ACPI_EVENT_FLAG_SET;
  347.     }
  348.  
  349.     /* Set return value */
  350.  
  351.     (*EventStatus) = LocalEventStatus;
  352.     return (AE_OK);
  353. }
  354.  
  355.  
  356. /******************************************************************************
  357.  *
  358.  * FUNCTION:    AcpiHwDisableGpeBlock
  359.  *
  360.  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
  361.  *              GpeBlock            - Gpe Block info
  362.  *
  363.  * RETURN:      Status
  364.  *
  365.  * DESCRIPTION: Disable all GPEs within a single GPE block
  366.  *
  367.  ******************************************************************************/
  368.  
  369. ACPI_STATUS
  370. AcpiHwDisableGpeBlock (
  371.     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
  372.     ACPI_GPE_BLOCK_INFO     *GpeBlock,
  373.     void                    *Context)
  374. {
  375.     UINT32                  i;
  376.     ACPI_STATUS             Status;
  377.  
  378.  
  379.     /* Examine each GPE Register within the block */
  380.  
  381.     for (i = 0; i < GpeBlock->RegisterCount; i++)
  382.     {
  383.         /* Disable all GPEs in this register */
  384.  
  385.         Status = AcpiHwWrite (0x00, &GpeBlock->RegisterInfo[i].EnableAddress);
  386.         if (ACPI_FAILURE (Status))
  387.         {
  388.             return (Status);
  389.         }
  390.     }
  391.  
  392.     return (AE_OK);
  393. }
  394.  
  395.  
  396. /******************************************************************************
  397.  *
  398.  * FUNCTION:    AcpiHwClearGpeBlock
  399.  *
  400.  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
  401.  *              GpeBlock            - Gpe Block info
  402.  *
  403.  * RETURN:      Status
  404.  *
  405.  * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
  406.  *
  407.  ******************************************************************************/
  408.  
  409. ACPI_STATUS
  410. AcpiHwClearGpeBlock (
  411.     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
  412.     ACPI_GPE_BLOCK_INFO     *GpeBlock,
  413.     void                    *Context)
  414. {
  415.     UINT32                  i;
  416.     ACPI_STATUS             Status;
  417.  
  418.  
  419.     /* Examine each GPE Register within the block */
  420.  
  421.     for (i = 0; i < GpeBlock->RegisterCount; i++)
  422.     {
  423.         /* Clear status on all GPEs in this register */
  424.  
  425.         Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
  426.         if (ACPI_FAILURE (Status))
  427.         {
  428.             return (Status);
  429.         }
  430.     }
  431.  
  432.     return (AE_OK);
  433. }
  434.  
  435.  
  436. /******************************************************************************
  437.  *
  438.  * FUNCTION:    AcpiHwEnableRuntimeGpeBlock
  439.  *
  440.  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
  441.  *              GpeBlock            - Gpe Block info
  442.  *
  443.  * RETURN:      Status
  444.  *
  445.  * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
  446.  *              combination wake/run GPEs.
  447.  *
  448.  ******************************************************************************/
  449.  
  450. ACPI_STATUS
  451. AcpiHwEnableRuntimeGpeBlock (
  452.     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
  453.     ACPI_GPE_BLOCK_INFO     *GpeBlock,
  454.     void                    *Context)
  455. {
  456.     UINT32                  i;
  457.     ACPI_STATUS             Status;
  458.  
  459.  
  460.     /* NOTE: assumes that all GPEs are currently disabled */
  461.  
  462.     /* Examine each GPE Register within the block */
  463.  
  464.     for (i = 0; i < GpeBlock->RegisterCount; i++)
  465.     {
  466.         if (!GpeBlock->RegisterInfo[i].EnableForRun)
  467.         {
  468.             continue;
  469.         }
  470.  
  471.         /* Enable all "runtime" GPEs in this register */
  472.  
  473.         Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForRun,
  474.                     &GpeBlock->RegisterInfo[i].EnableAddress);
  475.         if (ACPI_FAILURE (Status))
  476.         {
  477.             return (Status);
  478.         }
  479.     }
  480.  
  481.     return (AE_OK);
  482. }
  483.  
  484.  
  485. /******************************************************************************
  486.  *
  487.  * FUNCTION:    AcpiHwEnableWakeupGpeBlock
  488.  *
  489.  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
  490.  *              GpeBlock            - Gpe Block info
  491.  *
  492.  * RETURN:      Status
  493.  *
  494.  * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
  495.  *              combination wake/run GPEs.
  496.  *
  497.  ******************************************************************************/
  498.  
  499. static ACPI_STATUS
  500. AcpiHwEnableWakeupGpeBlock (
  501.     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
  502.     ACPI_GPE_BLOCK_INFO     *GpeBlock,
  503.     void                    *Context)
  504. {
  505.     UINT32                  i;
  506.     ACPI_STATUS             Status;
  507.  
  508.  
  509.     /* Examine each GPE Register within the block */
  510.  
  511.     for (i = 0; i < GpeBlock->RegisterCount; i++)
  512.     {
  513.         if (!GpeBlock->RegisterInfo[i].EnableForWake)
  514.         {
  515.             continue;
  516.         }
  517.  
  518.         /* Enable all "wake" GPEs in this register */
  519.  
  520.         Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForWake,
  521.                     &GpeBlock->RegisterInfo[i].EnableAddress);
  522.         if (ACPI_FAILURE (Status))
  523.         {
  524.             return (Status);
  525.         }
  526.     }
  527.  
  528.     return (AE_OK);
  529. }
  530.  
  531.  
  532. /******************************************************************************
  533.  *
  534.  * FUNCTION:    AcpiHwDisableAllGpes
  535.  *
  536.  * PARAMETERS:  None
  537.  *
  538.  * RETURN:      Status
  539.  *
  540.  * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  541.  *
  542.  ******************************************************************************/
  543.  
  544. ACPI_STATUS
  545. AcpiHwDisableAllGpes (
  546.     void)
  547. {
  548.     ACPI_STATUS             Status;
  549.  
  550.  
  551.     ACPI_FUNCTION_TRACE (HwDisableAllGpes);
  552.  
  553.  
  554.     Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
  555.     Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
  556.     return_ACPI_STATUS (Status);
  557. }
  558.  
  559.  
  560. /******************************************************************************
  561.  *
  562.  * FUNCTION:    AcpiHwEnableAllRuntimeGpes
  563.  *
  564.  * PARAMETERS:  None
  565.  *
  566.  * RETURN:      Status
  567.  *
  568.  * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  569.  *
  570.  ******************************************************************************/
  571.  
  572. ACPI_STATUS
  573. AcpiHwEnableAllRuntimeGpes (
  574.     void)
  575. {
  576.     ACPI_STATUS             Status;
  577.  
  578.  
  579.     ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
  580.  
  581.  
  582.     Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
  583.     return_ACPI_STATUS (Status);
  584. }
  585.  
  586.  
  587. /******************************************************************************
  588.  *
  589.  * FUNCTION:    AcpiHwEnableAllWakeupGpes
  590.  *
  591.  * PARAMETERS:  None
  592.  *
  593.  * RETURN:      Status
  594.  *
  595.  * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
  596.  *
  597.  ******************************************************************************/
  598.  
  599. ACPI_STATUS
  600. AcpiHwEnableAllWakeupGpes (
  601.     void)
  602. {
  603.     ACPI_STATUS             Status;
  604.  
  605.  
  606.     ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
  607.  
  608.  
  609.     Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
  610.     return_ACPI_STATUS (Status);
  611. }
  612.  
  613.