173d4e80bSchristos /******************************************************************************
273d4e80bSchristos  *
373d4e80bSchristos  * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
473d4e80bSchristos  *
573d4e80bSchristos  *****************************************************************************/
673d4e80bSchristos 
773d4e80bSchristos /*
8*ec12a2faSchristos  * Copyright (C) 2000 - 2022, Intel Corp.
973d4e80bSchristos  * All rights reserved.
1073d4e80bSchristos  *
1173d4e80bSchristos  * Redistribution and use in source and binary forms, with or without
1273d4e80bSchristos  * modification, are permitted provided that the following conditions
1373d4e80bSchristos  * are met:
1473d4e80bSchristos  * 1. Redistributions of source code must retain the above copyright
1573d4e80bSchristos  *    notice, this list of conditions, and the following disclaimer,
1673d4e80bSchristos  *    without modification.
1773d4e80bSchristos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1873d4e80bSchristos  *    substantially similar to the "NO WARRANTY" disclaimer below
1973d4e80bSchristos  *    ("Disclaimer") and any redistribution must be conditioned upon
2073d4e80bSchristos  *    including a substantially similar Disclaimer requirement for further
2173d4e80bSchristos  *    binary redistribution.
2273d4e80bSchristos  * 3. Neither the names of the above-listed copyright holders nor the names
2373d4e80bSchristos  *    of any contributors may be used to endorse or promote products derived
2473d4e80bSchristos  *    from this software without specific prior written permission.
2573d4e80bSchristos  *
2673d4e80bSchristos  * Alternatively, this software may be distributed under the terms of the
2773d4e80bSchristos  * GNU General Public License ("GPL") version 2 as published by the Free
2873d4e80bSchristos  * Software Foundation.
2973d4e80bSchristos  *
3073d4e80bSchristos  * NO WARRANTY
3173d4e80bSchristos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3273d4e80bSchristos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33adee7055Schristos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3473d4e80bSchristos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3573d4e80bSchristos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3673d4e80bSchristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3773d4e80bSchristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3873d4e80bSchristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3973d4e80bSchristos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4073d4e80bSchristos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4173d4e80bSchristos  * POSSIBILITY OF SUCH DAMAGES.
4273d4e80bSchristos  */
4373d4e80bSchristos 
4473d4e80bSchristos #define EXPORT_ACPI_INTERFACES
4573d4e80bSchristos 
4673d4e80bSchristos #include "acpi.h"
4773d4e80bSchristos #include "accommon.h"
4873d4e80bSchristos 
4973d4e80bSchristos #define _COMPONENT          ACPI_HARDWARE
5073d4e80bSchristos         ACPI_MODULE_NAME    ("hwxfsleep")
5173d4e80bSchristos 
5273d4e80bSchristos /* Local prototypes */
5373d4e80bSchristos 
54e34402d4Schristos #if (!ACPI_REDUCED_HARDWARE)
55e34402d4Schristos static ACPI_STATUS
56e34402d4Schristos AcpiHwSetFirmwareWakingVector (
57e34402d4Schristos     ACPI_TABLE_FACS         *Facs,
58e34402d4Schristos     ACPI_PHYSICAL_ADDRESS   PhysicalAddress,
59e34402d4Schristos     ACPI_PHYSICAL_ADDRESS   PhysicalAddress64);
60e34402d4Schristos #endif
61e34402d4Schristos 
6273d4e80bSchristos static ACPI_STATUS
6373d4e80bSchristos AcpiHwSleepDispatch (
6473d4e80bSchristos     UINT8                   SleepState,
6573d4e80bSchristos     UINT32                  FunctionId);
6673d4e80bSchristos 
6773d4e80bSchristos /*
6873d4e80bSchristos  * Dispatch table used to efficiently branch to the various sleep
6973d4e80bSchristos  * functions.
7073d4e80bSchristos  */
7173d4e80bSchristos #define ACPI_SLEEP_FUNCTION_ID          0
7273d4e80bSchristos #define ACPI_WAKE_PREP_FUNCTION_ID      1
7373d4e80bSchristos #define ACPI_WAKE_FUNCTION_ID           2
7473d4e80bSchristos 
7573d4e80bSchristos /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
7673d4e80bSchristos 
7773d4e80bSchristos static ACPI_SLEEP_FUNCTIONS         AcpiSleepDispatch[] =
7873d4e80bSchristos {
79dab10b95Schristos     {ACPI_STRUCT_INIT (LegacyFunction,
8035a687ffSchristos                        ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacySleep)),
81dab10b95Schristos      ACPI_STRUCT_INIT (ExtendedFunction,
8235a687ffSchristos                        AcpiHwExtendedSleep) },
83dab10b95Schristos     {ACPI_STRUCT_INIT (LegacyFunction,
8435a687ffSchristos                        ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWakePrep)),
85dab10b95Schristos      ACPI_STRUCT_INIT (ExtendedFunction,
8635a687ffSchristos                        AcpiHwExtendedWakePrep) },
875fc006f0Schristos     {ACPI_STRUCT_INIT (LegacyFunction,
8835a687ffSchristos                        ACPI_HW_OPTIONAL_FUNCTION (AcpiHwLegacyWake)),
89dab10b95Schristos      ACPI_STRUCT_INIT (ExtendedFunction,
9035a687ffSchristos                        AcpiHwExtendedWake) }
9173d4e80bSchristos };
9273d4e80bSchristos 
9373d4e80bSchristos 
9473d4e80bSchristos /*
9573d4e80bSchristos  * These functions are removed for the ACPI_REDUCED_HARDWARE case:
9673d4e80bSchristos  *      AcpiSetFirmwareWakingVector
9773d4e80bSchristos  *      AcpiEnterSleepStateS4bios
9873d4e80bSchristos  */
9973d4e80bSchristos 
10073d4e80bSchristos #if (!ACPI_REDUCED_HARDWARE)
10173d4e80bSchristos /*******************************************************************************
10273d4e80bSchristos  *
103e34402d4Schristos  * FUNCTION:    AcpiHwSetFirmwareWakingVector
10473d4e80bSchristos  *
105e34402d4Schristos  * PARAMETERS:  Facs                - Pointer to FACS table
106e34402d4Schristos  *              PhysicalAddress     - 32-bit physical address of ACPI real mode
107e34402d4Schristos  *                                    entry point
108e34402d4Schristos  *              PhysicalAddress64   - 64-bit physical address of ACPI protected
109dc79220aSchristos  *                                    mode entry point
11073d4e80bSchristos  *
11173d4e80bSchristos  * RETURN:      Status
11273d4e80bSchristos  *
113e34402d4Schristos  * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
11473d4e80bSchristos  *
11573d4e80bSchristos  ******************************************************************************/
11673d4e80bSchristos 
117e34402d4Schristos static ACPI_STATUS
AcpiHwSetFirmwareWakingVector(ACPI_TABLE_FACS * Facs,ACPI_PHYSICAL_ADDRESS PhysicalAddress,ACPI_PHYSICAL_ADDRESS PhysicalAddress64)118e34402d4Schristos AcpiHwSetFirmwareWakingVector (
119e34402d4Schristos     ACPI_TABLE_FACS         *Facs,
120e34402d4Schristos     ACPI_PHYSICAL_ADDRESS   PhysicalAddress,
121e34402d4Schristos     ACPI_PHYSICAL_ADDRESS   PhysicalAddress64)
12273d4e80bSchristos {
123e34402d4Schristos     ACPI_FUNCTION_TRACE (AcpiHwSetFirmwareWakingVector);
12473d4e80bSchristos 
12573d4e80bSchristos 
12673d4e80bSchristos     /*
12773d4e80bSchristos      * According to the ACPI specification 2.0c and later, the 64-bit
12873d4e80bSchristos      * waking vector should be cleared and the 32-bit waking vector should
12973d4e80bSchristos      * be used, unless we want the wake-up code to be called by the BIOS in
13073d4e80bSchristos      * Protected Mode. Some systems (for example HP dv5-1004nr) are known
13173d4e80bSchristos      * to fail to resume if the 64-bit vector is used.
13273d4e80bSchristos      */
13373d4e80bSchristos 
13473d4e80bSchristos     /* Set the 32-bit vector */
13573d4e80bSchristos 
136e34402d4Schristos     Facs->FirmwareWakingVector = (UINT32) PhysicalAddress;
13773d4e80bSchristos 
138e34402d4Schristos     if (Facs->Length > 32)
139e34402d4Schristos     {
140e34402d4Schristos         if (Facs->Version >= 1)
141e34402d4Schristos         {
142e34402d4Schristos             /* Set the 64-bit vector */
143e34402d4Schristos 
144e34402d4Schristos             Facs->XFirmwareWakingVector = PhysicalAddress64;
145e34402d4Schristos         }
146e34402d4Schristos         else
147e34402d4Schristos         {
14873d4e80bSchristos             /* Clear the 64-bit vector if it exists */
14973d4e80bSchristos 
150e34402d4Schristos             Facs->XFirmwareWakingVector = 0;
151e34402d4Schristos         }
152e34402d4Schristos     }
153e34402d4Schristos 
154e34402d4Schristos     return_ACPI_STATUS (AE_OK);
155e34402d4Schristos }
156e34402d4Schristos 
157e34402d4Schristos 
158e34402d4Schristos /*******************************************************************************
159e34402d4Schristos  *
160e34402d4Schristos  * FUNCTION:    AcpiSetFirmwareWakingVector
161e34402d4Schristos  *
162e34402d4Schristos  * PARAMETERS:  PhysicalAddress     - 32-bit physical address of ACPI real mode
163e34402d4Schristos  *                                    entry point
164e34402d4Schristos  *              PhysicalAddress64   - 64-bit physical address of ACPI protected
165dc79220aSchristos  *                                    mode entry point
166e34402d4Schristos  *
167e34402d4Schristos  * RETURN:      Status
168e34402d4Schristos  *
169e34402d4Schristos  * DESCRIPTION: Sets the FirmwareWakingVector fields of the FACS
170e34402d4Schristos  *
171e34402d4Schristos  ******************************************************************************/
172e34402d4Schristos 
173e34402d4Schristos ACPI_STATUS
AcpiSetFirmwareWakingVector(ACPI_PHYSICAL_ADDRESS PhysicalAddress,ACPI_PHYSICAL_ADDRESS PhysicalAddress64)174e34402d4Schristos AcpiSetFirmwareWakingVector (
175e34402d4Schristos     ACPI_PHYSICAL_ADDRESS   PhysicalAddress,
176e34402d4Schristos     ACPI_PHYSICAL_ADDRESS   PhysicalAddress64)
17773d4e80bSchristos {
178e34402d4Schristos 
179e34402d4Schristos     ACPI_FUNCTION_TRACE (AcpiSetFirmwareWakingVector);
180e34402d4Schristos 
18194e0d463Schristos     if (AcpiGbl_FACS)
182e34402d4Schristos     {
18394e0d463Schristos         (void) AcpiHwSetFirmwareWakingVector (AcpiGbl_FACS,
184e34402d4Schristos             PhysicalAddress, PhysicalAddress64);
18573d4e80bSchristos     }
18673d4e80bSchristos 
18773d4e80bSchristos     return_ACPI_STATUS (AE_OK);
18873d4e80bSchristos }
18973d4e80bSchristos 
ACPI_EXPORT_SYMBOL(AcpiSetFirmwareWakingVector)19073d4e80bSchristos ACPI_EXPORT_SYMBOL (AcpiSetFirmwareWakingVector)
19173d4e80bSchristos 
19273d4e80bSchristos 
19373d4e80bSchristos /*******************************************************************************
19473d4e80bSchristos  *
19573d4e80bSchristos  * FUNCTION:    AcpiEnterSleepStateS4bios
19673d4e80bSchristos  *
19773d4e80bSchristos  * PARAMETERS:  None
19873d4e80bSchristos  *
19973d4e80bSchristos  * RETURN:      Status
20073d4e80bSchristos  *
20173d4e80bSchristos  * DESCRIPTION: Perform a S4 bios request.
20273d4e80bSchristos  *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
20373d4e80bSchristos  *
20473d4e80bSchristos  ******************************************************************************/
20573d4e80bSchristos 
20673d4e80bSchristos ACPI_STATUS
20773d4e80bSchristos AcpiEnterSleepStateS4bios (
20873d4e80bSchristos     void)
20973d4e80bSchristos {
21073d4e80bSchristos     UINT32                  InValue;
21173d4e80bSchristos     ACPI_STATUS             Status;
21273d4e80bSchristos 
21373d4e80bSchristos 
21473d4e80bSchristos     ACPI_FUNCTION_TRACE (AcpiEnterSleepStateS4bios);
21573d4e80bSchristos 
21673d4e80bSchristos 
21773d4e80bSchristos     /* Clear the wake status bit (PM1) */
21873d4e80bSchristos 
21973d4e80bSchristos     Status = AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS);
22073d4e80bSchristos     if (ACPI_FAILURE (Status))
22173d4e80bSchristos     {
22273d4e80bSchristos         return_ACPI_STATUS (Status);
22373d4e80bSchristos     }
22473d4e80bSchristos 
22573d4e80bSchristos     Status = AcpiHwClearAcpiStatus ();
22673d4e80bSchristos     if (ACPI_FAILURE (Status))
22773d4e80bSchristos     {
22873d4e80bSchristos         return_ACPI_STATUS (Status);
22973d4e80bSchristos     }
23073d4e80bSchristos 
23173d4e80bSchristos     /*
232116aa910Schristos      * 1) Disable all GPEs
23373d4e80bSchristos      * 2) Enable all wakeup GPEs
23473d4e80bSchristos      */
23573d4e80bSchristos     Status = AcpiHwDisableAllGpes ();
23673d4e80bSchristos     if (ACPI_FAILURE (Status))
23773d4e80bSchristos     {
23873d4e80bSchristos         return_ACPI_STATUS (Status);
23973d4e80bSchristos     }
24073d4e80bSchristos     AcpiGbl_SystemAwakeAndRunning = FALSE;
24173d4e80bSchristos 
24273d4e80bSchristos     Status = AcpiHwEnableAllWakeupGpes ();
24373d4e80bSchristos     if (ACPI_FAILURE (Status))
24473d4e80bSchristos     {
24573d4e80bSchristos         return_ACPI_STATUS (Status);
24673d4e80bSchristos     }
24773d4e80bSchristos 
24873d4e80bSchristos     ACPI_FLUSH_CPU_CACHE ();
24973d4e80bSchristos 
25073d4e80bSchristos     Status = AcpiHwWritePort (AcpiGbl_FADT.SmiCommand,
25173d4e80bSchristos         (UINT32) AcpiGbl_FADT.S4BiosRequest, 8);
2525fc006f0Schristos     if (ACPI_FAILURE (Status))
2535fc006f0Schristos     {
2545fc006f0Schristos         return_ACPI_STATUS (Status);
2555fc006f0Schristos     }
25673d4e80bSchristos 
25773d4e80bSchristos     do {
25873d4e80bSchristos         AcpiOsStall (ACPI_USEC_PER_MSEC);
25973d4e80bSchristos         Status = AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS, &InValue);
26073d4e80bSchristos         if (ACPI_FAILURE (Status))
26173d4e80bSchristos         {
26273d4e80bSchristos             return_ACPI_STATUS (Status);
26373d4e80bSchristos         }
26494e0d463Schristos 
26573d4e80bSchristos     } while (!InValue);
26673d4e80bSchristos 
26773d4e80bSchristos     return_ACPI_STATUS (AE_OK);
26873d4e80bSchristos }
26973d4e80bSchristos 
ACPI_EXPORT_SYMBOL(AcpiEnterSleepStateS4bios)27073d4e80bSchristos ACPI_EXPORT_SYMBOL (AcpiEnterSleepStateS4bios)
27173d4e80bSchristos 
27273d4e80bSchristos #endif /* !ACPI_REDUCED_HARDWARE */
27373d4e80bSchristos 
27473d4e80bSchristos 
27573d4e80bSchristos /*******************************************************************************
27673d4e80bSchristos  *
27773d4e80bSchristos  * FUNCTION:    AcpiHwSleepDispatch
27873d4e80bSchristos  *
27973d4e80bSchristos  * PARAMETERS:  SleepState          - Which sleep state to enter/exit
28073d4e80bSchristos  *              FunctionId          - Sleep, WakePrep, or Wake
28173d4e80bSchristos  *
28273d4e80bSchristos  * RETURN:      Status from the invoked sleep handling function.
28373d4e80bSchristos  *
28473d4e80bSchristos  * DESCRIPTION: Dispatch a sleep/wake request to the appropriate handling
28573d4e80bSchristos  *              function.
28673d4e80bSchristos  *
28773d4e80bSchristos  ******************************************************************************/
28873d4e80bSchristos 
28973d4e80bSchristos static ACPI_STATUS
29073d4e80bSchristos AcpiHwSleepDispatch (
29173d4e80bSchristos     UINT8                   SleepState,
29273d4e80bSchristos     UINT32                  FunctionId)
29373d4e80bSchristos {
29473d4e80bSchristos     ACPI_STATUS             Status;
29573d4e80bSchristos     ACPI_SLEEP_FUNCTIONS    *SleepFunctions = &AcpiSleepDispatch[FunctionId];
29673d4e80bSchristos 
29773d4e80bSchristos 
29873d4e80bSchristos #if (!ACPI_REDUCED_HARDWARE)
29973d4e80bSchristos     /*
30073d4e80bSchristos      * If the Hardware Reduced flag is set (from the FADT), we must
30173d4e80bSchristos      * use the extended sleep registers (FADT). Note: As per the ACPI
30273d4e80bSchristos      * specification, these extended registers are to be used for HW-reduced
30373d4e80bSchristos      * platforms only. They are not general-purpose replacements for the
30473d4e80bSchristos      * legacy PM register sleep support.
30573d4e80bSchristos      */
30673d4e80bSchristos     if (AcpiGbl_ReducedHardware)
30773d4e80bSchristos     {
30873d4e80bSchristos         Status = SleepFunctions->ExtendedFunction (SleepState);
30973d4e80bSchristos     }
31073d4e80bSchristos     else
31173d4e80bSchristos     {
31273d4e80bSchristos         /* Legacy sleep */
31373d4e80bSchristos 
31473d4e80bSchristos         Status = SleepFunctions->LegacyFunction (SleepState);
31573d4e80bSchristos     }
31673d4e80bSchristos 
31773d4e80bSchristos     return (Status);
31873d4e80bSchristos 
31973d4e80bSchristos #else
32073d4e80bSchristos     /*
32173d4e80bSchristos      * For the case where reduced-hardware-only code is being generated,
32273d4e80bSchristos      * we know that only the extended sleep registers are available
32373d4e80bSchristos      */
32473d4e80bSchristos     Status = SleepFunctions->ExtendedFunction (SleepState);
32573d4e80bSchristos     return (Status);
32673d4e80bSchristos 
32773d4e80bSchristos #endif /* !ACPI_REDUCED_HARDWARE */
32873d4e80bSchristos }
32973d4e80bSchristos 
33073d4e80bSchristos 
33173d4e80bSchristos /*******************************************************************************
33273d4e80bSchristos  *
33373d4e80bSchristos  * FUNCTION:    AcpiEnterSleepStatePrep
33473d4e80bSchristos  *
33573d4e80bSchristos  * PARAMETERS:  SleepState          - Which sleep state to enter
33673d4e80bSchristos  *
33773d4e80bSchristos  * RETURN:      Status
33873d4e80bSchristos  *
33973d4e80bSchristos  * DESCRIPTION: Prepare to enter a system sleep state.
34073d4e80bSchristos  *              This function must execute with interrupts enabled.
34173d4e80bSchristos  *              We break sleeping into 2 stages so that OSPM can handle
34273d4e80bSchristos  *              various OS-specific tasks between the two steps.
34373d4e80bSchristos  *
34473d4e80bSchristos  ******************************************************************************/
34573d4e80bSchristos 
34673d4e80bSchristos ACPI_STATUS
AcpiEnterSleepStatePrep(UINT8 SleepState)34773d4e80bSchristos AcpiEnterSleepStatePrep (
34873d4e80bSchristos     UINT8                   SleepState)
34973d4e80bSchristos {
35073d4e80bSchristos     ACPI_STATUS             Status;
35173d4e80bSchristos     ACPI_OBJECT_LIST        ArgList;
35273d4e80bSchristos     ACPI_OBJECT             Arg;
35373d4e80bSchristos     UINT32                  SstValue;
35473d4e80bSchristos 
35573d4e80bSchristos 
35673d4e80bSchristos     ACPI_FUNCTION_TRACE (AcpiEnterSleepStatePrep);
35773d4e80bSchristos 
35873d4e80bSchristos 
35973d4e80bSchristos     Status = AcpiGetSleepTypeData (SleepState,
36073d4e80bSchristos         &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
36173d4e80bSchristos     if (ACPI_FAILURE (Status))
36273d4e80bSchristos     {
36373d4e80bSchristos         return_ACPI_STATUS (Status);
36473d4e80bSchristos     }
36573d4e80bSchristos 
36640fe8e0eSchristos     Status = AcpiGetSleepTypeData (ACPI_STATE_S0,
36740fe8e0eSchristos         &AcpiGbl_SleepTypeAS0, &AcpiGbl_SleepTypeBS0);
36840fe8e0eSchristos     if (ACPI_FAILURE (Status)) {
36940fe8e0eSchristos         AcpiGbl_SleepTypeAS0 = ACPI_SLEEP_TYPE_INVALID;
37040fe8e0eSchristos     }
37140fe8e0eSchristos 
37273d4e80bSchristos     /* Execute the _PTS method (Prepare To Sleep) */
37373d4e80bSchristos 
37473d4e80bSchristos     ArgList.Count = 1;
37573d4e80bSchristos     ArgList.Pointer = &Arg;
37673d4e80bSchristos     Arg.Type = ACPI_TYPE_INTEGER;
37773d4e80bSchristos     Arg.Integer.Value = SleepState;
37873d4e80bSchristos 
37973d4e80bSchristos     Status = AcpiEvaluateObject (NULL, METHOD_PATHNAME__PTS, &ArgList, NULL);
38073d4e80bSchristos     if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
38173d4e80bSchristos     {
38273d4e80bSchristos         return_ACPI_STATUS (Status);
38373d4e80bSchristos     }
38473d4e80bSchristos 
38573d4e80bSchristos     /* Setup the argument to the _SST method (System STatus) */
38673d4e80bSchristos 
38773d4e80bSchristos     switch (SleepState)
38873d4e80bSchristos     {
38973d4e80bSchristos     case ACPI_STATE_S0:
39073d4e80bSchristos 
39173d4e80bSchristos         SstValue = ACPI_SST_WORKING;
39273d4e80bSchristos         break;
39373d4e80bSchristos 
39473d4e80bSchristos     case ACPI_STATE_S1:
39573d4e80bSchristos     case ACPI_STATE_S2:
39673d4e80bSchristos     case ACPI_STATE_S3:
39773d4e80bSchristos 
39873d4e80bSchristos         SstValue = ACPI_SST_SLEEPING;
39973d4e80bSchristos         break;
40073d4e80bSchristos 
40173d4e80bSchristos     case ACPI_STATE_S4:
40273d4e80bSchristos 
40373d4e80bSchristos         SstValue = ACPI_SST_SLEEP_CONTEXT;
40473d4e80bSchristos         break;
40573d4e80bSchristos 
40673d4e80bSchristos     default:
40773d4e80bSchristos 
40873d4e80bSchristos         SstValue = ACPI_SST_INDICATOR_OFF; /* Default is off */
40973d4e80bSchristos         break;
41073d4e80bSchristos     }
41173d4e80bSchristos 
41273d4e80bSchristos     /*
41373d4e80bSchristos      * Set the system indicators to show the desired sleep state.
41473d4e80bSchristos      * _SST is an optional method (return no error if not found)
41573d4e80bSchristos      */
41633841f6dSchristos     AcpiHwExecuteSleepMethod (__UNCONST(METHOD_PATHNAME__SST), SstValue);
41773d4e80bSchristos     return_ACPI_STATUS (AE_OK);
41873d4e80bSchristos }
41973d4e80bSchristos 
ACPI_EXPORT_SYMBOL(AcpiEnterSleepStatePrep)42073d4e80bSchristos ACPI_EXPORT_SYMBOL (AcpiEnterSleepStatePrep)
42173d4e80bSchristos 
42273d4e80bSchristos 
42373d4e80bSchristos /*******************************************************************************
42473d4e80bSchristos  *
42573d4e80bSchristos  * FUNCTION:    AcpiEnterSleepState
42673d4e80bSchristos  *
42773d4e80bSchristos  * PARAMETERS:  SleepState          - Which sleep state to enter
42873d4e80bSchristos  *
42973d4e80bSchristos  * RETURN:      Status
43073d4e80bSchristos  *
43173d4e80bSchristos  * DESCRIPTION: Enter a system sleep state
43273d4e80bSchristos  *              THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
43373d4e80bSchristos  *
43473d4e80bSchristos  ******************************************************************************/
43573d4e80bSchristos 
43673d4e80bSchristos ACPI_STATUS
43773d4e80bSchristos AcpiEnterSleepState (
43873d4e80bSchristos     UINT8                   SleepState)
43973d4e80bSchristos {
44073d4e80bSchristos     ACPI_STATUS             Status;
44173d4e80bSchristos 
44273d4e80bSchristos 
44373d4e80bSchristos     ACPI_FUNCTION_TRACE (AcpiEnterSleepState);
44473d4e80bSchristos 
44573d4e80bSchristos 
44673d4e80bSchristos     if ((AcpiGbl_SleepTypeA > ACPI_SLEEP_TYPE_MAX) ||
44773d4e80bSchristos         (AcpiGbl_SleepTypeB > ACPI_SLEEP_TYPE_MAX))
44873d4e80bSchristos     {
44973d4e80bSchristos         ACPI_ERROR ((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X",
45073d4e80bSchristos             AcpiGbl_SleepTypeA, AcpiGbl_SleepTypeB));
45173d4e80bSchristos         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
45273d4e80bSchristos     }
45373d4e80bSchristos 
45473d4e80bSchristos     Status = AcpiHwSleepDispatch (SleepState, ACPI_SLEEP_FUNCTION_ID);
45573d4e80bSchristos     return_ACPI_STATUS (Status);
45673d4e80bSchristos }
45773d4e80bSchristos 
ACPI_EXPORT_SYMBOL(AcpiEnterSleepState)45873d4e80bSchristos ACPI_EXPORT_SYMBOL (AcpiEnterSleepState)
45973d4e80bSchristos 
46073d4e80bSchristos 
46173d4e80bSchristos /*******************************************************************************
46273d4e80bSchristos  *
46373d4e80bSchristos  * FUNCTION:    AcpiLeaveSleepStatePrep
46473d4e80bSchristos  *
46573d4e80bSchristos  * PARAMETERS:  SleepState          - Which sleep state we are exiting
46673d4e80bSchristos  *
46773d4e80bSchristos  * RETURN:      Status
46873d4e80bSchristos  *
46973d4e80bSchristos  * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
47073d4e80bSchristos  *              sleep. Called with interrupts DISABLED.
47173d4e80bSchristos  *              We break wake/resume into 2 stages so that OSPM can handle
47273d4e80bSchristos  *              various OS-specific tasks between the two steps.
47373d4e80bSchristos  *
47473d4e80bSchristos  ******************************************************************************/
47573d4e80bSchristos 
47673d4e80bSchristos ACPI_STATUS
47773d4e80bSchristos AcpiLeaveSleepStatePrep (
47873d4e80bSchristos     UINT8                   SleepState)
47973d4e80bSchristos {
48073d4e80bSchristos     ACPI_STATUS             Status;
48173d4e80bSchristos 
48273d4e80bSchristos 
48373d4e80bSchristos     ACPI_FUNCTION_TRACE (AcpiLeaveSleepStatePrep);
48473d4e80bSchristos 
48573d4e80bSchristos 
48673d4e80bSchristos     Status = AcpiHwSleepDispatch (SleepState, ACPI_WAKE_PREP_FUNCTION_ID);
48773d4e80bSchristos     return_ACPI_STATUS (Status);
48873d4e80bSchristos }
48973d4e80bSchristos 
ACPI_EXPORT_SYMBOL(AcpiLeaveSleepStatePrep)49073d4e80bSchristos ACPI_EXPORT_SYMBOL (AcpiLeaveSleepStatePrep)
49173d4e80bSchristos 
49273d4e80bSchristos 
49373d4e80bSchristos /*******************************************************************************
49473d4e80bSchristos  *
49573d4e80bSchristos  * FUNCTION:    AcpiLeaveSleepState
49673d4e80bSchristos  *
49773d4e80bSchristos  * PARAMETERS:  SleepState          - Which sleep state we are exiting
49873d4e80bSchristos  *
49973d4e80bSchristos  * RETURN:      Status
50073d4e80bSchristos  *
50173d4e80bSchristos  * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
50273d4e80bSchristos  *              Called with interrupts ENABLED.
50373d4e80bSchristos  *
50473d4e80bSchristos  ******************************************************************************/
50573d4e80bSchristos 
50673d4e80bSchristos ACPI_STATUS
50773d4e80bSchristos AcpiLeaveSleepState (
50873d4e80bSchristos     UINT8                   SleepState)
50973d4e80bSchristos {
51073d4e80bSchristos     ACPI_STATUS             Status;
51173d4e80bSchristos 
51273d4e80bSchristos 
51373d4e80bSchristos     ACPI_FUNCTION_TRACE (AcpiLeaveSleepState);
51473d4e80bSchristos 
51573d4e80bSchristos 
51673d4e80bSchristos     Status = AcpiHwSleepDispatch (SleepState, ACPI_WAKE_FUNCTION_ID);
51773d4e80bSchristos     return_ACPI_STATUS (Status);
51873d4e80bSchristos }
51973d4e80bSchristos 
52073d4e80bSchristos ACPI_EXPORT_SYMBOL (AcpiLeaveSleepState)
521