ReactOS 0.4.15-dev-7897-g78dc504
hwsleep.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Support functions for the
4 * original/legacy sleep/PM registers.
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2022, Intel Corp.
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
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.
26 *
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.
30 *
31 * NO WARRANTY
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 MERCHANTABILITY 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.
43 */
44
45#include "acpi.h"
46#include "accommon.h"
47
48#define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwsleep")
50
51
52#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53/*******************************************************************************
54 *
55 * FUNCTION: AcpiHwLegacySleep
56 *
57 * PARAMETERS: SleepState - Which sleep state to enter
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Enter a system sleep state via the legacy FADT PM registers
62 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
63 *
64 ******************************************************************************/
65
68 UINT8 SleepState)
69{
70 ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo;
71 ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo;
72 UINT32 Pm1aControl;
73 UINT32 Pm1bControl;
74 UINT32 InValue;
76
77
78 ACPI_FUNCTION_TRACE (HwLegacySleep);
79
80
83
84 /* Clear wake status */
85
88 if (ACPI_FAILURE (Status))
89 {
91 }
92
93 /* Disable all GPEs */
94
96 if (ACPI_FAILURE (Status))
97 {
99 }
101 if (ACPI_FAILURE(Status))
102 {
104 }
105 AcpiGbl_SystemAwakeAndRunning = FALSE;
106
107 /* Enable all wakeup GPEs */
108
110 if (ACPI_FAILURE (Status))
111 {
113 }
114
115 /* Get current value of PM1A control */
116
118 &Pm1aControl);
119 if (ACPI_FAILURE (Status))
120 {
122 }
124 "Entering sleep state [S%u]\n", SleepState));
125
126 /* Clear the SLP_EN and SLP_TYP fields */
127
128 Pm1aControl &= ~(SleepTypeRegInfo->AccessBitMask |
129 SleepEnableRegInfo->AccessBitMask);
130 Pm1bControl = Pm1aControl;
131
132 /* Insert the SLP_TYP bits */
133
134 Pm1aControl |= (AcpiGbl_SleepTypeA << SleepTypeRegInfo->BitPosition);
135 Pm1bControl |= (AcpiGbl_SleepTypeB << SleepTypeRegInfo->BitPosition);
136
137 /*
138 * We split the writes of SLP_TYP and SLP_EN to workaround
139 * poorly implemented hardware.
140 */
141
142 /* Write #1: write the SLP_TYP data to the PM1 Control registers */
143
144 Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
145 if (ACPI_FAILURE (Status))
146 {
148 }
149
150 /* Insert the sleep enable (SLP_EN) bit */
151
152 Pm1aControl |= SleepEnableRegInfo->AccessBitMask;
153 Pm1bControl |= SleepEnableRegInfo->AccessBitMask;
154
155 /* Flush caches, as per ACPI specification */
156
157 if (SleepState < ACPI_STATE_S4)
158 {
160 }
161
162 Status = AcpiOsEnterSleep (SleepState, Pm1aControl, Pm1bControl);
164 {
166 }
167 if (ACPI_FAILURE (Status))
168 {
170 }
171
172 /* Write #2: Write both SLP_TYP + SLP_EN */
173
174 Status = AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
175 if (ACPI_FAILURE (Status))
176 {
178 }
179
180 if (SleepState > ACPI_STATE_S3)
181 {
182 /*
183 * We wanted to sleep > S3, but it didn't happen (by virtue of the
184 * fact that we are still executing!)
185 *
186 * Wait ten seconds, then try again. This is to get S4/S5 to work on
187 * all machines.
188 *
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
191 * away entirely.
192 */
194
196 SleepEnableRegInfo->AccessBitMask);
197 if (ACPI_FAILURE (Status))
198 {
200 }
201 }
202
203 /* Wait for transition back to Working State */
204
205 do
206 {
208 if (ACPI_FAILURE (Status))
209 {
211 }
212
213 } while (!InValue);
214
216}
217
218
219/*******************************************************************************
220 *
221 * FUNCTION: AcpiHwLegacyWakePrep
222 *
223 * PARAMETERS: SleepState - Which sleep state we just exited
224 *
225 * RETURN: Status
226 *
227 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
228 * sleep.
229 * Called with interrupts ENABLED.
230 *
231 ******************************************************************************/
232
235 UINT8 SleepState)
236{
238 ACPI_BIT_REGISTER_INFO *SleepTypeRegInfo;
239 ACPI_BIT_REGISTER_INFO *SleepEnableRegInfo;
240 UINT32 Pm1aControl;
241 UINT32 Pm1bControl;
242
243
244 ACPI_FUNCTION_TRACE (HwLegacyWakePrep);
245
246 /*
247 * Set SLP_TYPE and SLP_EN to state S0.
248 * This is unclear from the ACPI Spec, but it is required
249 * by some machines.
250 */
251 if (AcpiGbl_SleepTypeAS0 != ACPI_SLEEP_TYPE_INVALID)
252 {
253 SleepTypeRegInfo =
255 SleepEnableRegInfo =
257
258 /* Get current value of PM1A control */
259
261 &Pm1aControl);
262 if (ACPI_SUCCESS (Status))
263 {
264 /* Clear the SLP_EN and SLP_TYP fields */
265
266 Pm1aControl &= ~(SleepTypeRegInfo->AccessBitMask |
267 SleepEnableRegInfo->AccessBitMask);
268 Pm1bControl = Pm1aControl;
269
270 /* Insert the SLP_TYP bits */
271
272 Pm1aControl |= (AcpiGbl_SleepTypeAS0 <<
273 SleepTypeRegInfo->BitPosition);
274 Pm1bControl |= (AcpiGbl_SleepTypeBS0 <<
275 SleepTypeRegInfo->BitPosition);
276
277 /* Write the control registers and ignore any errors */
278
279 (void) AcpiHwWritePm1Control (Pm1aControl, Pm1bControl);
280 }
281 }
282
284}
285
286
287/*******************************************************************************
288 *
289 * FUNCTION: AcpiHwLegacyWake
290 *
291 * PARAMETERS: SleepState - Which sleep state we just exited
292 *
293 * RETURN: Status
294 *
295 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
296 * Called with interrupts ENABLED.
297 *
298 ******************************************************************************/
299
302 UINT8 SleepState)
303{
305
306
307 ACPI_FUNCTION_TRACE (HwLegacyWake);
308
309
310 /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
311
312 AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID;
314
315 /*
316 * GPEs must be enabled before _WAK is called as GPEs
317 * might get fired there
318 *
319 * Restore the GPEs:
320 * 1) Disable all GPEs
321 * 2) Enable all runtime GPEs
322 */
324 if (ACPI_FAILURE (Status))
325 {
327 }
328
330 if (ACPI_FAILURE (Status))
331 {
333 }
334
335 /*
336 * Now we can execute _WAK, etc. Some machines require that the GPEs
337 * are enabled before the wake methods are executed.
338 */
340
341 /*
342 * Some BIOS code assumes that WAK_STS will be cleared on resume
343 * and use it to determine whether the system is rebooting or
344 * resuming. Clear WAK_STS for compatibility.
345 */
348 AcpiGbl_SystemAwakeAndRunning = TRUE;
349
350 /* Enable power button */
351
355
359
360 /* Enable sleep button */
361
365
369
370 /* Enable pcie wake event if support */
371 if ((AcpiGbl_FADT.Flags & ACPI_FADT_PCI_EXPRESS_WAKE)) {
378 }
379
382}
383
384#endif /* !ACPI_REDUCED_HARDWARE */
unsigned char UINT8
unsigned int UINT32
#define ACPI_FLUSH_CPU_CACHE()
Definition: accygwin.h:53
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
#define AE_CTRL_TERMINATE
Definition: acexcep.h:226
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
#define AE_OK
Definition: acexcep.h:97
ACPI_FIXED_EVENT_INFO AcpiGbl_FixedEventInfo[ACPI_NUM_FIXED_EVENTS]
Definition: utglobal.c:175
#define ACPI_SST_WORKING
Definition: achware.h:51
#define ACPI_SST_WAKING
Definition: achware.h:52
#define ACPI_REGISTER_PM1_CONTROL
Definition: aclocal.h:1186
#define METHOD_PATHNAME__SST
Definition: acnames.h:81
#define METHOD_PATHNAME__WAK
Definition: acnames.h:82
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
#define ACPI_DB_INIT
Definition: acoutput.h:151
ACPI_STATUS AcpiOsEnterSleep(UINT8 SleepState, UINT32 RegaValue, UINT32 RegbValue)
Definition: osl.c:932
void AcpiOsStall(UINT32 Microseconds)
Definition: osl.c:264
#define ACPI_FADT_PCI_EXPRESS_WAKE
Definition: actbl.h:350
#define ACPI_EVENT_POWER_BUTTON
Definition: actypes.h:765
#define ACPI_DISABLE_EVENT
Definition: actypes.h:944
#define ACPI_CLEAR_STATUS
Definition: actypes.h:939
#define ACPI_EVENT_PCIE_WAKE
Definition: actypes.h:768
#define ACPI_USEC_PER_SEC
Definition: actypes.h:471
#define ACPI_BITREG_SLEEP_ENABLE
Definition: actypes.h:927
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_ENABLE_EVENT
Definition: actypes.h:943
#define ACPI_STATE_S4
Definition: actypes.h:628
#define ACPI_SLEEP_TYPE_INVALID
Definition: actypes.h:651
#define ACPI_BITREG_SLEEP_TYPE
Definition: actypes.h:926
#define ACPI_EVENT_SLEEP_BUTTON
Definition: actypes.h:766
#define ACPI_BITREG_WAKE_STATUS
Definition: actypes.h:909
#define ACPI_STATE_S3
Definition: actypes.h:627
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:25
void AcpiHwExecuteSleepMethod(char *MethodPathname, UINT32 IntegerArgument)
Definition: hwesleep.c:67
ACPI_STATUS AcpiHwEnableAllWakeupGpes(void)
Definition: hwgpe.c:649
ACPI_STATUS AcpiHwDisableAllGpes(void)
Definition: hwgpe.c:595
ACPI_STATUS AcpiHwEnableAllRuntimeGpes(void)
Definition: hwgpe.c:622
ACPI_STATUS AcpiHwWritePm1Control(UINT32 Pm1aControl, UINT32 Pm1bControl)
Definition: hwregs.c:536
ACPI_STATUS AcpiHwClearAcpiStatus(void)
Definition: hwregs.c:452
ACPI_STATUS AcpiHwRegisterRead(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwregs.c:574
ACPI_STATUS AcpiHwRegisterWrite(UINT32 RegisterId, UINT32 Value)
Definition: hwregs.c:684
ACPI_BIT_REGISTER_INFO * AcpiHwGetBitRegisterInfo(UINT32 RegisterId)
Definition: hwregs.c:502
ACPI_STATUS AcpiHwLegacySleep(UINT8 SleepState)
Definition: hwsleep.c:67
ACPI_STATUS AcpiHwLegacyWake(UINT8 SleepState)
Definition: hwsleep.c:301
ACPI_STATUS AcpiHwLegacyWakePrep(UINT8 SleepState)
Definition: hwsleep.c:234
ACPI_STATUS AcpiWriteBitRegister(UINT32 RegisterId, UINT32 Value)
Definition: hwxface.c:282
ACPI_STATUS AcpiReadBitRegister(UINT32 RegisterId, UINT32 *ReturnValue)
Definition: hwxface.c:213