1 /******************************************************************************
3 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Support functions for the
4 * original/legacy sleep/PM registers.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2017, 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 ("hwsleep")
52 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53 /*******************************************************************************
55 * FUNCTION: AcpiHwLegacySleep
57 * PARAMETERS: SleepState - Which sleep state to enter
61 * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
64 ******************************************************************************/
70 ACPI_BIT_REGISTER_INFO
*SleepTypeRegInfo
;
71 ACPI_BIT_REGISTER_INFO
*SleepEnableRegInfo
;
78 ACPI_FUNCTION_TRACE (HwLegacySleep
);
81 SleepTypeRegInfo
= AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE
);
82 SleepEnableRegInfo
= AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE
);
84 /* Clear wake status */
86 Status
= AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS
,
88 if (ACPI_FAILURE (Status
))
90 return_ACPI_STATUS (Status
);
93 /* Clear all fixed and general purpose status bits */
95 Status
= AcpiHwClearAcpiStatus ();
96 if (ACPI_FAILURE (Status
))
98 return_ACPI_STATUS (Status
);
102 * 1) Disable/Clear all GPEs
103 * 2) Enable all wakeup GPEs
105 Status
= AcpiHwDisableAllGpes ();
106 if (ACPI_FAILURE (Status
))
108 return_ACPI_STATUS (Status
);
110 AcpiGbl_SystemAwakeAndRunning
= FALSE
;
112 Status
= AcpiHwEnableAllWakeupGpes ();
113 if (ACPI_FAILURE (Status
))
115 return_ACPI_STATUS (Status
);
118 /* Get current value of PM1A control */
120 Status
= AcpiHwRegisterRead (ACPI_REGISTER_PM1_CONTROL
,
122 if (ACPI_FAILURE (Status
))
124 return_ACPI_STATUS (Status
);
126 ACPI_DEBUG_PRINT ((ACPI_DB_INIT
,
127 "Entering sleep state [S%u]\n", SleepState
));
129 /* Clear the SLP_EN and SLP_TYP fields */
131 Pm1aControl
&= ~(SleepTypeRegInfo
->AccessBitMask
|
132 SleepEnableRegInfo
->AccessBitMask
);
133 Pm1bControl
= Pm1aControl
;
135 /* Insert the SLP_TYP bits */
137 Pm1aControl
|= (AcpiGbl_SleepTypeA
<< SleepTypeRegInfo
->BitPosition
);
138 Pm1bControl
|= (AcpiGbl_SleepTypeB
<< SleepTypeRegInfo
->BitPosition
);
141 * We split the writes of SLP_TYP and SLP_EN to workaround
142 * poorly implemented hardware.
145 /* Write #1: write the SLP_TYP data to the PM1 Control registers */
147 Status
= AcpiHwWritePm1Control (Pm1aControl
, Pm1bControl
);
148 if (ACPI_FAILURE (Status
))
150 return_ACPI_STATUS (Status
);
153 /* Insert the sleep enable (SLP_EN) bit */
155 Pm1aControl
|= SleepEnableRegInfo
->AccessBitMask
;
156 Pm1bControl
|= SleepEnableRegInfo
->AccessBitMask
;
158 /* Flush caches, as per ACPI specification */
160 ACPI_FLUSH_CPU_CACHE ();
162 Status
= AcpiOsEnterSleep (SleepState
, Pm1aControl
, Pm1bControl
);
163 if (Status
== AE_CTRL_TERMINATE
)
165 return_ACPI_STATUS (AE_OK
);
167 if (ACPI_FAILURE (Status
))
169 return_ACPI_STATUS (Status
);
172 /* Write #2: Write both SLP_TYP + SLP_EN */
174 Status
= AcpiHwWritePm1Control (Pm1aControl
, Pm1bControl
);
175 if (ACPI_FAILURE (Status
))
177 return_ACPI_STATUS (Status
);
180 if (SleepState
> ACPI_STATE_S3
)
183 * We wanted to sleep > S3, but it didn't happen (by virtue of the
184 * fact that we are still executing!)
186 * Wait ten seconds, then try again. This is to get S4/S5 to work on
189 * We wait so long to allow chipsets that poll this reg very slowly
190 * to still read the right value. Ideally, this block would go
193 AcpiOsStall (10 * ACPI_USEC_PER_SEC
);
195 Status
= AcpiHwRegisterWrite (ACPI_REGISTER_PM1_CONTROL
,
196 SleepEnableRegInfo
->AccessBitMask
);
197 if (ACPI_FAILURE (Status
))
199 return_ACPI_STATUS (Status
);
203 /* Wait for transition back to Working State */
207 Status
= AcpiReadBitRegister (ACPI_BITREG_WAKE_STATUS
, &InValue
);
208 if (ACPI_FAILURE (Status
))
210 return_ACPI_STATUS (Status
);
215 return_ACPI_STATUS (AE_OK
);
219 /*******************************************************************************
221 * FUNCTION: AcpiHwLegacyWakePrep
223 * PARAMETERS: SleepState - Which sleep state we just exited
227 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
229 * Called with interrupts ENABLED.
231 ******************************************************************************/
234 AcpiHwLegacyWakePrep (
238 ACPI_BIT_REGISTER_INFO
*SleepTypeRegInfo
;
239 ACPI_BIT_REGISTER_INFO
*SleepEnableRegInfo
;
244 ACPI_FUNCTION_TRACE (HwLegacyWakePrep
);
247 * Set SLP_TYPE and SLP_EN to state S0.
248 * This is unclear from the ACPI Spec, but it is required
251 Status
= AcpiGetSleepTypeData (ACPI_STATE_S0
,
252 &AcpiGbl_SleepTypeA
, &AcpiGbl_SleepTypeB
);
253 if (ACPI_SUCCESS (Status
))
256 AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_TYPE
);
258 AcpiHwGetBitRegisterInfo (ACPI_BITREG_SLEEP_ENABLE
);
260 /* Get current value of PM1A control */
262 Status
= AcpiHwRegisterRead (ACPI_REGISTER_PM1_CONTROL
,
264 if (ACPI_SUCCESS (Status
))
266 /* Clear the SLP_EN and SLP_TYP fields */
268 Pm1aControl
&= ~(SleepTypeRegInfo
->AccessBitMask
|
269 SleepEnableRegInfo
->AccessBitMask
);
270 Pm1bControl
= Pm1aControl
;
272 /* Insert the SLP_TYP bits */
274 Pm1aControl
|= (AcpiGbl_SleepTypeA
<<
275 SleepTypeRegInfo
->BitPosition
);
276 Pm1bControl
|= (AcpiGbl_SleepTypeB
<<
277 SleepTypeRegInfo
->BitPosition
);
279 /* Write the control registers and ignore any errors */
281 (void) AcpiHwWritePm1Control (Pm1aControl
, Pm1bControl
);
285 return_ACPI_STATUS (Status
);
289 /*******************************************************************************
291 * FUNCTION: AcpiHwLegacyWake
293 * PARAMETERS: SleepState - Which sleep state we just exited
297 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
298 * Called with interrupts ENABLED.
300 ******************************************************************************/
309 ACPI_FUNCTION_TRACE (HwLegacyWake
);
312 /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
314 AcpiGbl_SleepTypeA
= ACPI_SLEEP_TYPE_INVALID
;
315 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST
, ACPI_SST_WAKING
);
318 * GPEs must be enabled before _WAK is called as GPEs
319 * might get fired there
322 * 1) Disable/Clear all GPEs
323 * 2) Enable all runtime GPEs
325 Status
= AcpiHwDisableAllGpes ();
326 if (ACPI_FAILURE (Status
))
328 return_ACPI_STATUS (Status
);
331 Status
= AcpiHwEnableAllRuntimeGpes ();
332 if (ACPI_FAILURE (Status
))
334 return_ACPI_STATUS (Status
);
338 * Now we can execute _WAK, etc. Some machines require that the GPEs
339 * are enabled before the wake methods are executed.
341 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__WAK
, SleepState
);
344 * Some BIOS code assumes that WAK_STS will be cleared on resume
345 * and use it to determine whether the system is rebooting or
346 * resuming. Clear WAK_STS for compatibility.
348 (void) AcpiWriteBitRegister (ACPI_BITREG_WAKE_STATUS
,
350 AcpiGbl_SystemAwakeAndRunning
= TRUE
;
352 /* Enable power button */
354 (void) AcpiWriteBitRegister(
355 AcpiGbl_FixedEventInfo
[ACPI_EVENT_POWER_BUTTON
].EnableRegisterId
,
358 (void) AcpiWriteBitRegister(
359 AcpiGbl_FixedEventInfo
[ACPI_EVENT_POWER_BUTTON
].StatusRegisterId
,
362 AcpiHwExecuteSleepMethod (METHOD_PATHNAME__SST
, ACPI_SST_WORKING
);
363 return_ACPI_STATUS (Status
);
366 #endif /* !ACPI_REDUCED_HARDWARE */