blob: 803402aefaeb65d1bd9c81affd8d9bc853be65a8 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Bob Moore70958572012-02-14 18:47:42 +08002/******************************************************************************
3 *
4 * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the
5 * extended FADT-V5 sleep registers.
6 *
Bob Moore4441e552021-01-15 10:48:25 -08007 * Copyright (C) 2000 - 2021, Intel Corp.
Bob Moore70958572012-02-14 18:47:42 +08008 *
Erik Schmauss95857632018-03-14 16:13:07 -07009 *****************************************************************************/
Bob Moore70958572012-02-14 18:47:42 +080010
11#include <acpi/acpi.h>
12#include "accommon.h"
Bob Moore70958572012-02-14 18:47:42 +080013
14#define _COMPONENT ACPI_HARDWARE
15ACPI_MODULE_NAME("hwesleep")
16
Bob Moore70958572012-02-14 18:47:42 +080017/*******************************************************************************
18 *
19 * FUNCTION: acpi_hw_execute_sleep_method
20 *
Bob Moore4efeeec2012-03-21 09:42:45 +080021 * PARAMETERS: method_pathname - Pathname of method to execute
Bob Moore70958572012-02-14 18:47:42 +080022 * integer_argument - Argument to pass to the method
23 *
24 * RETURN: None
25 *
26 * DESCRIPTION: Execute a sleep/wake related method with one integer argument
27 * and no return value.
28 *
29 ******************************************************************************/
Bob Moore4efeeec2012-03-21 09:42:45 +080030void acpi_hw_execute_sleep_method(char *method_pathname, u32 integer_argument)
Bob Moore70958572012-02-14 18:47:42 +080031{
32 struct acpi_object_list arg_list;
33 union acpi_object arg;
34 acpi_status status;
35
36 ACPI_FUNCTION_TRACE(hw_execute_sleep_method);
37
Bob Moore70958572012-02-14 18:47:42 +080038 /* One argument, integer_argument; No return value expected */
39
40 arg_list.count = 1;
41 arg_list.pointer = &arg;
42 arg.type = ACPI_TYPE_INTEGER;
43 arg.integer.value = (u64)integer_argument;
44
Bob Moore4efeeec2012-03-21 09:42:45 +080045 status = acpi_evaluate_object(NULL, method_pathname, &arg_list, NULL);
Bob Moore70958572012-02-14 18:47:42 +080046 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
47 ACPI_EXCEPTION((AE_INFO, status, "While executing method %s",
Bob Moore4efeeec2012-03-21 09:42:45 +080048 method_pathname));
Bob Moore70958572012-02-14 18:47:42 +080049 }
50
51 return_VOID;
52}
53
54/*******************************************************************************
55 *
56 * FUNCTION: acpi_hw_extended_sleep
57 *
58 * PARAMETERS: sleep_state - Which sleep state to enter
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
63 * registers (V5 FADT).
64 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
65 *
66 ******************************************************************************/
67
Len Brown3f6f49c2012-07-26 20:08:54 -040068acpi_status acpi_hw_extended_sleep(u8 sleep_state)
Bob Moore70958572012-02-14 18:47:42 +080069{
70 acpi_status status;
Lv Zheng0fc5e8f2016-12-28 15:28:49 +080071 u8 sleep_control;
Bob Moore70958572012-02-14 18:47:42 +080072 u64 sleep_status;
73
74 ACPI_FUNCTION_TRACE(hw_extended_sleep);
75
76 /* Extended sleep registers must be valid */
77
78 if (!acpi_gbl_FADT.sleep_control.address ||
79 !acpi_gbl_FADT.sleep_status.address) {
80 return_ACPI_STATUS(AE_NOT_EXIST);
81 }
82
83 /* Clear wake status (WAK_STS) */
84
Bob Moore1fad8732015-12-29 13:54:36 +080085 status = acpi_write((u64)ACPI_X_WAKE_STATUS,
86 &acpi_gbl_FADT.sleep_status);
Bob Moore70958572012-02-14 18:47:42 +080087 if (ACPI_FAILURE(status)) {
88 return_ACPI_STATUS(status);
89 }
90
91 acpi_gbl_system_awake_and_running = FALSE;
92
Bob Moore70958572012-02-14 18:47:42 +080093 /*
94 * Set the SLP_TYP and SLP_EN bits.
95 *
96 * Note: We only use the first value returned by the \_Sx method
97 * (acpi_gbl_sleep_type_a) - As per ACPI specification.
98 */
99 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
100 "Entering sleep state [S%u]\n", sleep_state));
101
Lv Zheng0fc5e8f2016-12-28 15:28:49 +0800102 sleep_control = ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
103 ACPI_X_SLEEP_TYPE_MASK) | ACPI_X_SLEEP_ENABLE;
Bob Moore70958572012-02-14 18:47:42 +0800104
Lv Zheng0fc5e8f2016-12-28 15:28:49 +0800105 /* Flush caches, as per ACPI specification */
106
107 ACPI_FLUSH_CPU_CACHE();
108
109 status = acpi_os_enter_sleep(sleep_state, sleep_control, 0);
110 if (status == AE_CTRL_TERMINATE) {
111 return_ACPI_STATUS(AE_OK);
112 }
113 if (ACPI_FAILURE(status)) {
114 return_ACPI_STATUS(status);
115 }
116
117 status = acpi_write((u64)sleep_control, &acpi_gbl_FADT.sleep_control);
Bob Moore70958572012-02-14 18:47:42 +0800118 if (ACPI_FAILURE(status)) {
119 return_ACPI_STATUS(status);
120 }
121
122 /* Wait for transition back to Working State */
123
124 do {
125 status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
126 if (ACPI_FAILURE(status)) {
127 return_ACPI_STATUS(status);
128 }
129
130 } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
131
132 return_ACPI_STATUS(AE_OK);
133}
134
135/*******************************************************************************
136 *
137 * FUNCTION: acpi_hw_extended_wake_prep
138 *
139 * PARAMETERS: sleep_state - Which sleep state we just exited
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
144 * a sleep. Called with interrupts ENABLED.
145 *
146 ******************************************************************************/
147
Len Brown3f6f49c2012-07-26 20:08:54 -0400148acpi_status acpi_hw_extended_wake_prep(u8 sleep_state)
Bob Moore70958572012-02-14 18:47:42 +0800149{
150 acpi_status status;
151 u8 sleep_type_value;
152
153 ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
154
155 status = acpi_get_sleep_type_data(ACPI_STATE_S0,
156 &acpi_gbl_sleep_type_a,
157 &acpi_gbl_sleep_type_b);
158 if (ACPI_SUCCESS(status)) {
159 sleep_type_value =
160 ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
161 ACPI_X_SLEEP_TYPE_MASK);
162
Bob Moore5134abf2012-05-03 09:43:21 +0800163 (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
Bob Moore70958572012-02-14 18:47:42 +0800164 &acpi_gbl_FADT.sleep_control);
165 }
166
Bob Moore70958572012-02-14 18:47:42 +0800167 return_ACPI_STATUS(AE_OK);
168}
169
170/*******************************************************************************
171 *
172 * FUNCTION: acpi_hw_extended_wake
173 *
174 * PARAMETERS: sleep_state - Which sleep state we just exited
175 *
176 * RETURN: Status
177 *
178 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
179 * Called with interrupts ENABLED.
180 *
181 ******************************************************************************/
182
Len Brown3f6f49c2012-07-26 20:08:54 -0400183acpi_status acpi_hw_extended_wake(u8 sleep_state)
Bob Moore70958572012-02-14 18:47:42 +0800184{
185 ACPI_FUNCTION_TRACE(hw_extended_wake);
186
187 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
188
189 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
190
191 /* Execute the wake methods */
192
Bob Moore4efeeec2012-03-21 09:42:45 +0800193 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
194 acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
Bob Moore70958572012-02-14 18:47:42 +0800195
196 /*
197 * Some BIOS code assumes that WAK_STS will be cleared on resume
198 * and use it to determine whether the system is rebooting or
199 * resuming. Clear WAK_STS for compatibility.
200 */
Bob Moore5134abf2012-05-03 09:43:21 +0800201 (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
Bob Moore70958572012-02-14 18:47:42 +0800202 acpi_gbl_system_awake_and_running = TRUE;
203
Bob Moore4efeeec2012-03-21 09:42:45 +0800204 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
Bob Moore70958572012-02-14 18:47:42 +0800205 return_ACPI_STATUS(AE_OK);
206}