ReactOS 0.4.15-dev-8039-g69ebfd6
hwesleep.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the
4 * extended FADT-V5 sleep 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 ("hwesleep")
50
51
52/*******************************************************************************
53 *
54 * FUNCTION: AcpiHwExecuteSleepMethod
55 *
56 * PARAMETERS: MethodPathname - Pathname of method to execute
57 * IntegerArgument - Argument to pass to the method
58 *
59 * RETURN: None
60 *
61 * DESCRIPTION: Execute a sleep/wake related method with one integer argument
62 * and no return value.
63 *
64 ******************************************************************************/
65
66void
68 char *MethodPathname,
69 UINT32 IntegerArgument)
70{
71 ACPI_OBJECT_LIST ArgList;
72 ACPI_OBJECT Arg;
74
75
76 ACPI_FUNCTION_TRACE (HwExecuteSleepMethod);
77
78
79 /* One argument, IntegerArgument; No return value expected */
80
81 ArgList.Count = 1;
82 ArgList.Pointer = &Arg;
84 Arg.Integer.Value = (UINT64) IntegerArgument;
85
86 Status = AcpiEvaluateObject (NULL, MethodPathname, &ArgList, NULL);
88 {
89 ACPI_EXCEPTION ((AE_INFO, Status, "While executing method %s",
90 MethodPathname));
91 }
92
94}
95
96
97/*******************************************************************************
98 *
99 * FUNCTION: AcpiHwExtendedSleep
100 *
101 * PARAMETERS: SleepState - Which sleep state to enter
102 *
103 * RETURN: Status
104 *
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
108 *
109 ******************************************************************************/
110
113 UINT8 SleepState)
114{
116 UINT8 SleepControl;
117 UINT64 SleepStatus;
118
119
120 ACPI_FUNCTION_TRACE (HwExtendedSleep);
121
122
123 /* Extended sleep registers must be valid */
124
125 if (!AcpiGbl_FADT.SleepControl.Address ||
126 !AcpiGbl_FADT.SleepStatus.Address)
127 {
129 }
130
131 /* Clear wake status (WAK_STS) */
132
134 &AcpiGbl_FADT.SleepStatus);
135 if (ACPI_FAILURE (Status))
136 {
138 }
139
140 AcpiGbl_SystemAwakeAndRunning = FALSE;
141
142 /*
143 * Set the SLP_TYP and SLP_EN bits.
144 *
145 * Note: We only use the first value returned by the \_Sx method
146 * (AcpiGbl_SleepTypeA) - As per ACPI specification.
147 */
149 "Entering sleep state [S%u]\n", SleepState));
150
151 SleepControl = ((AcpiGbl_SleepTypeA << ACPI_X_SLEEP_TYPE_POSITION) &
153
154 /* Flush caches, as per ACPI specification */
155
156 if (SleepState < ACPI_STATE_S4)
157 {
159 }
160
161 Status = AcpiOsEnterSleep (SleepState, SleepControl, 0);
163 {
165 }
166 if (ACPI_FAILURE (Status))
167 {
169 }
170
171 Status = AcpiWrite ((UINT64) SleepControl, &AcpiGbl_FADT.SleepControl);
172 if (ACPI_FAILURE (Status))
173 {
175 }
176
177 /* Wait for transition back to Working State */
178
179 do
180 {
181 Status = AcpiRead (&SleepStatus, &AcpiGbl_FADT.SleepStatus);
182 if (ACPI_FAILURE (Status))
183 {
185 }
186
187 } while (!(((UINT8) SleepStatus) & ACPI_X_WAKE_STATUS));
188
190}
191
192
193/*******************************************************************************
194 *
195 * FUNCTION: AcpiHwExtendedWakePrep
196 *
197 * PARAMETERS: SleepState - Which sleep state we just exited
198 *
199 * RETURN: Status
200 *
201 * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
202 * a sleep. Called with interrupts ENABLED.
203 *
204 ******************************************************************************/
205
208 UINT8 SleepState)
209{
210 UINT8 SleepTypeValue;
211
212
213 ACPI_FUNCTION_TRACE (HwExtendedWakePrep);
214
215
216 if (AcpiGbl_SleepTypeAS0 != ACPI_SLEEP_TYPE_INVALID)
217 {
218 SleepTypeValue = ((AcpiGbl_SleepTypeAS0 << ACPI_X_SLEEP_TYPE_POSITION) &
220
221 (void) AcpiWrite ((UINT64) (SleepTypeValue | ACPI_X_SLEEP_ENABLE),
222 &AcpiGbl_FADT.SleepControl);
223 }
224
226}
227
228
229/*******************************************************************************
230 *
231 * FUNCTION: AcpiHwExtendedWake
232 *
233 * PARAMETERS: SleepState - Which sleep state we just exited
234 *
235 * RETURN: Status
236 *
237 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
238 * Called with interrupts ENABLED.
239 *
240 ******************************************************************************/
241
244 UINT8 SleepState)
245{
246 ACPI_FUNCTION_TRACE (HwExtendedWake);
247
248
249 /* Ensure EnterSleepStatePrep -> EnterSleepState ordering */
250
251 AcpiGbl_SleepTypeA = ACPI_SLEEP_TYPE_INVALID;
252
253 /* Execute the wake methods */
254
257
258 /*
259 * Some BIOS code assumes that WAK_STS will be cleared on resume
260 * and use it to determine whether the system is rebooting or
261 * resuming. Clear WAK_STS for compatibility.
262 */
263 (void) AcpiWrite ((UINT64) ACPI_X_WAKE_STATUS, &AcpiGbl_FADT.SleepStatus);
264 AcpiGbl_SystemAwakeAndRunning = TRUE;
265
268}
unsigned long long UINT64
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_NOT_FOUND
Definition: acexcep.h:113
#define AE_CTRL_TERMINATE
Definition: acexcep.h:226
#define AE_NOT_EXIST
Definition: acexcep.h:114
#define AE_OK
Definition: acexcep.h:97
#define ACPI_SST_WORKING
Definition: achware.h:51
#define ACPI_SST_WAKING
Definition: achware.h:52
#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_EXCEPTION(plist)
Definition: acoutput.h:239
#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 AE_INFO
Definition: acoutput.h:230
#define return_VOID
Definition: acoutput.h:495
#define ACPI_DB_INIT
Definition: acoutput.h:151
ACPI_STATUS AcpiOsEnterSleep(UINT8 SleepState, UINT32 RegaValue, UINT32 RegbValue)
Definition: osl.c:932
#define ACPI_X_SLEEP_TYPE_MASK
Definition: actbl.h:378
#define ACPI_X_SLEEP_TYPE_POSITION
Definition: actbl.h:379
#define ACPI_X_WAKE_STATUS
Definition: actbl.h:377
#define ACPI_X_SLEEP_ENABLE
Definition: actbl.h:380
#define ACPI_TYPE_INTEGER
Definition: actypes.h:688
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_STATE_S4
Definition: actypes.h:628
#define ACPI_SLEEP_TYPE_INVALID
Definition: actypes.h:651
#define NULL
Definition: types.h:112
#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 AcpiHwExtendedWakePrep(UINT8 SleepState)
Definition: hwesleep.c:207
ACPI_STATUS AcpiHwExtendedSleep(UINT8 SleepState)
Definition: hwesleep.c:112
ACPI_STATUS AcpiHwExtendedWake(UINT8 SleepState)
Definition: hwesleep.c:243
ACPI_STATUS AcpiRead(UINT64 *ReturnValue, ACPI_GENERIC_ADDRESS *Reg)
Definition: hwxface.c:138
ACPI_STATUS AcpiWrite(UINT64 Value, ACPI_GENERIC_ADDRESS *Reg)
Definition: hwxface.c:169
ACPI_STATUS AcpiEvaluateObject(ACPI_HANDLE Handle, ACPI_STRING Pathname, ACPI_OBJECT_LIST *ExternalParams, ACPI_BUFFER *ReturnBuffer)
Definition: nsxfeval.c:217
ACPI_OBJECT * Pointer
Definition: actypes.h:1029
struct acpi_object::@615 Integer
ACPI_OBJECT_TYPE Type
Definition: actypes.h:970