1 /******************************************************************************
3 * Name: hwesleep.c - ACPI Hardware Sleep/Wake Support functions for the
4 * extended FADT-V5 sleep registers.
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, 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.
45 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME("hwesleep")
51 /*******************************************************************************
53 * FUNCTION: acpi_hw_execute_sleep_method
55 * PARAMETERS: method_pathname - Pathname of method to execute
56 * integer_argument - Argument to pass to the method
60 * DESCRIPTION: Execute a sleep/wake related method with one integer argument
61 * and no return value.
63 ******************************************************************************/
64 void acpi_hw_execute_sleep_method(char *method_pathname, u32 integer_argument)
66 struct acpi_object_list arg_list;
67 union acpi_object arg;
70 ACPI_FUNCTION_TRACE(hw_execute_sleep_method);
72 /* One argument, integer_argument; No return value expected */
75 arg_list.pointer = &arg;
76 arg.type = ACPI_TYPE_INTEGER;
77 arg.integer.value = (u64)integer_argument;
79 status = acpi_evaluate_object(NULL, method_pathname, &arg_list, NULL);
80 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
81 ACPI_EXCEPTION((AE_INFO, status, "While executing method %s",
88 /*******************************************************************************
90 * FUNCTION: acpi_hw_extended_sleep
92 * PARAMETERS: sleep_state - Which sleep state to enter
93 * flags - ACPI_EXECUTE_GTS to run optional method
97 * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
98 * registers (V5 FADT).
99 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
101 ******************************************************************************/
103 acpi_status acpi_hw_extended_sleep(u8 sleep_state, u8 flags)
109 ACPI_FUNCTION_TRACE(hw_extended_sleep);
111 /* Extended sleep registers must be valid */
113 if (!acpi_gbl_FADT.sleep_control.address ||
114 !acpi_gbl_FADT.sleep_status.address) {
115 return_ACPI_STATUS(AE_NOT_EXIST);
118 /* Clear wake status (WAK_STS) */
121 acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
122 if (ACPI_FAILURE(status)) {
123 return_ACPI_STATUS(status);
126 acpi_gbl_system_awake_and_running = FALSE;
128 /* Optionally execute _GTS (Going To Sleep) */
130 if (flags & ACPI_EXECUTE_GTS) {
131 acpi_hw_execute_sleep_method(METHOD_PATHNAME__GTS, sleep_state);
134 /* Flush caches, as per ACPI specification */
136 ACPI_FLUSH_CPU_CACHE();
139 * Set the SLP_TYP and SLP_EN bits.
141 * Note: We only use the first value returned by the \_Sx method
142 * (acpi_gbl_sleep_type_a) - As per ACPI specification.
144 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
145 "Entering sleep state [S%u]\n", sleep_state));
148 ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
149 ACPI_X_SLEEP_TYPE_MASK);
151 status = acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
152 &acpi_gbl_FADT.sleep_control);
153 if (ACPI_FAILURE(status)) {
154 return_ACPI_STATUS(status);
157 /* Wait for transition back to Working State */
160 status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
161 if (ACPI_FAILURE(status)) {
162 return_ACPI_STATUS(status);
165 } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
167 return_ACPI_STATUS(AE_OK);
170 /*******************************************************************************
172 * FUNCTION: acpi_hw_extended_wake_prep
174 * PARAMETERS: sleep_state - Which sleep state we just exited
175 * flags - ACPI_EXECUTE_BFS to run optional method
179 * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
180 * a sleep. Called with interrupts ENABLED.
182 ******************************************************************************/
184 acpi_status acpi_hw_extended_wake_prep(u8 sleep_state, u8 flags)
189 ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
191 status = acpi_get_sleep_type_data(ACPI_STATE_S0,
192 &acpi_gbl_sleep_type_a,
193 &acpi_gbl_sleep_type_b);
194 if (ACPI_SUCCESS(status)) {
196 ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
197 ACPI_X_SLEEP_TYPE_MASK);
199 (void)acpi_write((u64)(sleep_type_value | ACPI_X_SLEEP_ENABLE),
200 &acpi_gbl_FADT.sleep_control);
203 /* Optionally execute _BFS (Back From Sleep) */
205 if (flags & ACPI_EXECUTE_BFS) {
206 acpi_hw_execute_sleep_method(METHOD_PATHNAME__BFS, sleep_state);
208 return_ACPI_STATUS(AE_OK);
211 /*******************************************************************************
213 * FUNCTION: acpi_hw_extended_wake
215 * PARAMETERS: sleep_state - Which sleep state we just exited
216 * flags - Reserved, set to zero
220 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
221 * Called with interrupts ENABLED.
223 ******************************************************************************/
225 acpi_status acpi_hw_extended_wake(u8 sleep_state, u8 flags)
227 ACPI_FUNCTION_TRACE(hw_extended_wake);
229 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
231 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
233 /* Execute the wake methods */
235 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WAKING);
236 acpi_hw_execute_sleep_method(METHOD_PATHNAME__WAK, sleep_state);
239 * Some BIOS code assumes that WAK_STS will be cleared on resume
240 * and use it to determine whether the system is rebooting or
241 * resuming. Clear WAK_STS for compatibility.
243 (void)acpi_write((u64)ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
244 acpi_gbl_system_awake_and_running = TRUE;
246 acpi_hw_execute_sleep_method(METHOD_PATHNAME__SST, ACPI_SST_WORKING);
247 return_ACPI_STATUS(AE_OK);