1 /******************************************************************************
3 * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the
4 * extended FADT-V5 sleep registers.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2015, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwesleep")
52 /*******************************************************************************
54 * FUNCTION: AcpiHwExecuteSleepMethod
56 * PARAMETERS: MethodPathname - Pathname of method to execute
57 * IntegerArgument - Argument to pass to the method
61 * DESCRIPTION: Execute a sleep/wake related method with one integer argument
62 * and no return value.
64 ******************************************************************************/
67 AcpiHwExecuteSleepMethod (
69 UINT32 IntegerArgument)
71 ACPI_OBJECT_LIST ArgList;
76 ACPI_FUNCTION_TRACE (HwExecuteSleepMethod);
79 /* One argument, IntegerArgument; No return value expected */
82 ArgList.Pointer = &Arg;
83 Arg.Type = ACPI_TYPE_INTEGER;
84 Arg.Integer.Value = (UINT64) IntegerArgument;
86 Status = AcpiEvaluateObject (NULL, MethodPathname, &ArgList, NULL);
87 if (ACPI_FAILURE (Status) && Status != AE_NOT_FOUND)
89 ACPI_EXCEPTION ((AE_INFO, Status, "While executing method %s",
97 /*******************************************************************************
99 * FUNCTION: AcpiHwExtendedSleep
101 * PARAMETERS: SleepState - Which sleep state to enter
105 * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
106 * registers (V5 FADT).
107 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
109 ******************************************************************************/
112 AcpiHwExtendedSleep (
116 UINT8 SleepTypeValue;
120 ACPI_FUNCTION_TRACE (HwExtendedSleep);
123 /* Extended sleep registers must be valid */
125 if (!AcpiGbl_FADT.SleepControl.Address ||
126 !AcpiGbl_FADT.SleepStatus.Address)
128 return_ACPI_STATUS (AE_NOT_EXIST);
131 /* Clear wake status (WAK_STS) */
133 Status = AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS,
134 &AcpiGbl_FADT.SleepStatus);
135 if (ACPI_FAILURE (Status))
137 return_ACPI_STATUS (Status);
140 AcpiGbl_SystemAwakeAndRunning = FALSE;
142 /* Flush caches, as per ACPI specification */
144 ACPI_FLUSH_CPU_CACHE ();
147 * Set the SLP_TYP and SLP_EN bits.
149 * Note: We only use the first value returned by the \_Sx method
150 * (AcpiGbl_SleepTypeA) - As per ACPI specification.
152 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
153 "Entering sleep state [S%u]\n", SleepState));
155 SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
156 ACPI_X_SLEEP_TYPE_MASK);
158 Status = AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE),
159 &AcpiGbl_FADT.SleepControl);
160 if (ACPI_FAILURE (Status))
162 return_ACPI_STATUS (Status);
165 /* Wait for transition back to Working State */
169 Status = AcpiRead (&SleepStatus, &AcpiGbl_FADT.SleepStatus);
170 if (ACPI_FAILURE (Status))
172 return_ACPI_STATUS (Status);
175 } while (!(((UINT8) SleepStatus) & ACPI_X_WAKE_STATUS));
177 return_ACPI_STATUS (AE_OK);
181 /*******************************************************************************
183 * FUNCTION: AcpiHwExtendedWakePrep
185 * PARAMETERS: SleepState - Which sleep state we just exited
189 * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
190 * a sleep. Called with interrupts ENABLED.
192 ******************************************************************************/
195 AcpiHwExtendedWakePrep (
199 UINT8 SleepTypeValue;
202 ACPI_FUNCTION_TRACE (HwExtendedWakePrep);
205 Status = AcpiGetSleepTypeData (ACPI_STATE_S0,
206 &AcpiGbl_SleepTypeA, &AcpiGbl_SleepTypeB);
207 if (ACPI_SUCCESS (Status))
209 SleepTypeValue = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
210 ACPI_X_SLEEP_TYPE_MASK);
212 (void) AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE),
213 &AcpiGbl_FADT.SleepControl);
216 return_ACPI_STATUS (AE_OK);
220 /*******************************************************************************
222 * FUNCTION: AcpiHwExtendedWake
224 * PARAMETERS: SleepState - Which sleep state we just exited
228 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
229 * Called with interrupts ENABLED.
231 ******************************************************************************/
237 ACPI_FUNCTION_TRACE (HwExtendedWake);
240 /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
242 AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID;
244 /* Execute the wake methods */
246 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST, ACPI_SST_WAKING);
247 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__WAK, SleepState);
250 * Some BIOS code assumes that WAK_STS will be cleared on resume
251 * and use it to determine whether the system is rebooting or
252 * resuming. Clear WAK_STS for compatibility.
254 (void) AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS, &AcpiGbl_FADT.SleepStatus);
255 AcpiGbl_SystemAwakeAndRunning = TRUE;
257 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST, ACPI_SST_WORKING);
258 return_ACPI_STATUS (AE_OK);