Home | History | Annotate | Line # | Download | only in hardware
hwesleep.c revision 1.5
      1  1.1  christos /******************************************************************************
      2  1.1  christos  *
      3  1.1  christos  * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the
      4  1.1  christos  *                    extended FADT-V5 sleep registers.
      5  1.1  christos  *
      6  1.1  christos  *****************************************************************************/
      7  1.1  christos 
      8  1.1  christos /*
      9  1.5  christos  * Copyright (C) 2000 - 2016, Intel Corp.
     10  1.1  christos  * All rights reserved.
     11  1.1  christos  *
     12  1.1  christos  * Redistribution and use in source and binary forms, with or without
     13  1.1  christos  * modification, are permitted provided that the following conditions
     14  1.1  christos  * are met:
     15  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     16  1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     17  1.1  christos  *    without modification.
     18  1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.1  christos  *    including a substantially similar Disclaimer requirement for further
     22  1.1  christos  *    binary redistribution.
     23  1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.1  christos  *    of any contributors may be used to endorse or promote products derived
     25  1.1  christos  *    from this software without specific prior written permission.
     26  1.1  christos  *
     27  1.1  christos  * Alternatively, this software may be distributed under the terms of the
     28  1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.1  christos  * Software Foundation.
     30  1.1  christos  *
     31  1.1  christos  * NO WARRANTY
     32  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     43  1.1  christos  */
     44  1.1  christos 
     45  1.1  christos #include "acpi.h"
     46  1.1  christos #include "accommon.h"
     47  1.1  christos 
     48  1.1  christos #define _COMPONENT          ACPI_HARDWARE
     49  1.1  christos         ACPI_MODULE_NAME    ("hwesleep")
     50  1.1  christos 
     51  1.1  christos 
     52  1.1  christos /*******************************************************************************
     53  1.1  christos  *
     54  1.1  christos  * FUNCTION:    AcpiHwExecuteSleepMethod
     55  1.1  christos  *
     56  1.1  christos  * PARAMETERS:  MethodPathname      - Pathname of method to execute
     57  1.1  christos  *              IntegerArgument     - Argument to pass to the method
     58  1.1  christos  *
     59  1.1  christos  * RETURN:      None
     60  1.1  christos  *
     61  1.1  christos  * DESCRIPTION: Execute a sleep/wake related method with one integer argument
     62  1.1  christos  *              and no return value.
     63  1.1  christos  *
     64  1.1  christos  ******************************************************************************/
     65  1.1  christos 
     66  1.1  christos void
     67  1.1  christos AcpiHwExecuteSleepMethod (
     68  1.1  christos     char                    *MethodPathname,
     69  1.1  christos     UINT32                  IntegerArgument)
     70  1.1  christos {
     71  1.1  christos     ACPI_OBJECT_LIST        ArgList;
     72  1.1  christos     ACPI_OBJECT             Arg;
     73  1.1  christos     ACPI_STATUS             Status;
     74  1.1  christos 
     75  1.1  christos 
     76  1.1  christos     ACPI_FUNCTION_TRACE (HwExecuteSleepMethod);
     77  1.1  christos 
     78  1.1  christos 
     79  1.1  christos     /* One argument, IntegerArgument; No return value expected */
     80  1.1  christos 
     81  1.1  christos     ArgList.Count = 1;
     82  1.1  christos     ArgList.Pointer = &Arg;
     83  1.1  christos     Arg.Type = ACPI_TYPE_INTEGER;
     84  1.1  christos     Arg.Integer.Value = (UINT64) IntegerArgument;
     85  1.1  christos 
     86  1.1  christos     Status = AcpiEvaluateObject (NULL, MethodPathname, &ArgList, NULL);
     87  1.1  christos     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
     88  1.1  christos     {
     89  1.1  christos         ACPI_EXCEPTION ((AE_INFO, Status, "While executing method %s",
     90  1.1  christos             MethodPathname));
     91  1.1  christos     }
     92  1.1  christos 
     93  1.1  christos     return_VOID;
     94  1.1  christos }
     95  1.1  christos 
     96  1.1  christos 
     97  1.1  christos /*******************************************************************************
     98  1.1  christos  *
     99  1.1  christos  * FUNCTION:    AcpiHwExtendedSleep
    100  1.1  christos  *
    101  1.1  christos  * PARAMETERS:  SleepState          - Which sleep state to enter
    102  1.1  christos  *
    103  1.1  christos  * RETURN:      Status
    104  1.1  christos  *
    105  1.1  christos  * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
    106  1.1  christos  *              registers (V5 FADT).
    107  1.1  christos  *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
    108  1.1  christos  *
    109  1.1  christos  ******************************************************************************/
    110  1.1  christos 
    111  1.1  christos ACPI_STATUS
    112  1.1  christos AcpiHwExtendedSleep (
    113  1.1  christos     UINT8                   SleepState)
    114  1.1  christos {
    115  1.1  christos     ACPI_STATUS             Status;
    116  1.1  christos     UINT8                   SleepTypeValue;
    117  1.1  christos     UINT64                  SleepStatus;
    118  1.1  christos 
    119  1.1  christos 
    120  1.1  christos     ACPI_FUNCTION_TRACE (HwExtendedSleep);
    121  1.1  christos 
    122  1.1  christos 
    123  1.1  christos     /* Extended sleep registers must be valid */
    124  1.1  christos 
    125  1.1  christos     if (!AcpiGbl_FADT.SleepControl.Address ||
    126  1.1  christos         !AcpiGbl_FADT.SleepStatus.Address)
    127  1.1  christos     {
    128  1.1  christos         return_ACPI_STATUS (AE_NOT_EXIST);
    129  1.1  christos     }
    130  1.1  christos 
    131  1.1  christos     /* Clear wake status (WAK_STS) */
    132  1.1  christos 
    133  1.5  christos     Status = AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS,
    134  1.5  christos         &AcpiGbl_FADT.SleepStatus);
    135  1.1  christos     if (ACPI_FAILURE (Status))
    136  1.1  christos     {
    137  1.1  christos         return_ACPI_STATUS (Status);
    138  1.1  christos     }
    139  1.1  christos 
    140  1.1  christos     AcpiGbl_SystemAwakeAndRunning = FALSE;
    141  1.1  christos 
    142  1.1  christos     /* Flush caches, as per ACPI specification */
    143  1.1  christos 
    144  1.1  christos     ACPI_FLUSH_CPU_CACHE ();
    145  1.1  christos 
    146  1.1  christos     /*
    147  1.1  christos      * Set the SLP_TYP and SLP_EN bits.
    148  1.1  christos      *
    149  1.1  christos      * Note: We only use the first value returned by the \_Sx method
    150  1.1  christos      * (AcpiGbl_SleepTypeA) - As per ACPI specification.
    151  1.1  christos      */
    152  1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
    153  1.1  christos         "Entering sleep state [S%u]\n", SleepState));
    154  1.1  christos 
    155  1.1  christos     SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
    156  1.1  christos         ACPI_X_SLEEP_TYPE_MASK);
    157  1.1  christos 
    158  1.1  christos     Status = AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE),
    159  1.1  christos         &AcpiGbl_FADT.SleepControl);
    160  1.1  christos     if (ACPI_FAILURE (Status))
    161  1.1  christos     {
    162  1.1  christos         return_ACPI_STATUS (Status);
    163  1.1  christos     }
    164  1.1  christos 
    165  1.1  christos     /* Wait for transition back to Working State */
    166  1.1  christos 
    167  1.1  christos     do
    168  1.1  christos     {
    169  1.1  christos         Status = AcpiRead (&SleepStatus, &AcpiGbl_FADT.SleepStatus);
    170  1.1  christos         if (ACPI_FAILURE (Status))
    171  1.1  christos         {
    172  1.1  christos             return_ACPI_STATUS (Status);
    173  1.1  christos         }
    174  1.1  christos 
    175  1.1  christos     } while (!(((UINT8) SleepStatus) & ACPI_X_WAKE_STATUS));
    176  1.1  christos 
    177  1.1  christos     return_ACPI_STATUS (AE_OK);
    178  1.1  christos }
    179  1.1  christos 
    180  1.1  christos 
    181  1.1  christos /*******************************************************************************
    182  1.1  christos  *
    183  1.1  christos  * FUNCTION:    AcpiHwExtendedWakePrep
    184  1.1  christos  *
    185  1.1  christos  * PARAMETERS:  SleepState          - Which sleep state we just exited
    186  1.1  christos  *
    187  1.1  christos  * RETURN:      Status
    188  1.1  christos  *
    189  1.1  christos  * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
    190  1.1  christos  *              a sleep. Called with interrupts ENABLED.
    191  1.1  christos  *
    192  1.1  christos  ******************************************************************************/
    193  1.1  christos 
    194  1.1  christos ACPI_STATUS
    195  1.1  christos AcpiHwExtendedWakePrep (
    196  1.1  christos     UINT8                   SleepState)
    197  1.1  christos {
    198  1.1  christos     ACPI_STATUS             Status;
    199  1.1  christos     UINT8                   SleepTypeValue;
    200  1.1  christos 
    201  1.1  christos 
    202  1.1  christos     ACPI_FUNCTION_TRACE (HwExtendedWakePrep);
    203  1.1  christos 
    204  1.1  christos 
    205  1.1  christos     Status = AcpiGetSleepTypeData (ACPI_STATE_S0,
    206  1.5  christos         &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
    207  1.1  christos     if (ACPI_SUCCESS (Status))
    208  1.1  christos     {
    209  1.1  christos         SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
    210  1.1  christos             ACPI_X_SLEEP_TYPE_MASK);
    211  1.1  christos 
    212  1.1  christos         (void) AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE),
    213  1.1  christos             &AcpiGbl_FADT.SleepControl);
    214  1.1  christos     }
    215  1.1  christos 
    216  1.1  christos     return_ACPI_STATUS (AE_OK);
    217  1.1  christos }
    218  1.1  christos 
    219  1.1  christos 
    220  1.1  christos /*******************************************************************************
    221  1.1  christos  *
    222  1.1  christos  * FUNCTION:    AcpiHwExtendedWake
    223  1.1  christos  *
    224  1.1  christos  * PARAMETERS:  SleepState          - Which sleep state we just exited
    225  1.1  christos  *
    226  1.1  christos  * RETURN:      Status
    227  1.1  christos  *
    228  1.1  christos  * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
    229  1.1  christos  *              Called with interrupts ENABLED.
    230  1.1  christos  *
    231  1.1  christos  ******************************************************************************/
    232  1.1  christos 
    233  1.1  christos ACPI_STATUS
    234  1.1  christos AcpiHwExtendedWake (
    235  1.1  christos     UINT8                   SleepState)
    236  1.1  christos {
    237  1.1  christos     ACPI_FUNCTION_TRACE (HwExtendedWake);
    238  1.1  christos 
    239  1.1  christos 
    240  1.1  christos     /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
    241  1.1  christos 
    242  1.1  christos     AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID;
    243  1.1  christos 
    244  1.1  christos     /* Execute the wake methods */
    245  1.1  christos 
    246  1.2  christos     AcpiHwExecuteSleepMethod (__UNCONST(METHOD_PATHNAME__SST), ACPI_SST_WAKING);
    247  1.2  christos     AcpiHwExecuteSleepMethod (__UNCONST(METHOD_PATHNAME__WAK), SleepState);
    248  1.1  christos 
    249  1.1  christos     /*
    250  1.1  christos      * Some BIOS code assumes that WAK_STS will be cleared on resume
    251  1.1  christos      * and use it to determine whether the system is rebooting or
    252  1.1  christos      * resuming. Clear WAK_STS for compatibility.
    253  1.1  christos      */
    254  1.1  christos     (void) AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS, &AcpiGbl_FADT.SleepStatus);
    255  1.1  christos     AcpiGbl_SystemAwakeAndRunning = TRUE;
    256  1.1  christos 
    257  1.2  christos     AcpiHwExecuteSleepMethod (__UNCONST(METHOD_PATHNAME__SST), ACPI_SST_WORKING);
    258  1.1  christos     return_ACPI_STATUS (AE_OK);
    259  1.1  christos }
    260