blob: 9e44c6c767e65c821032a8851055278362182434 [file] [log] [blame]
Bob Moore70958572012-02-14 18:47:42 +08001/******************************************************************************
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 - 2012, 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 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.
43 */
44
45#include <acpi/acpi.h>
46#include "accommon.h"
47#include <linux/module.h>
48
49#define _COMPONENT ACPI_HARDWARE
50ACPI_MODULE_NAME("hwesleep")
51
52static unsigned int gts, bfs;
53module_param(gts, uint, 0644);
54module_param(bfs, uint, 0644);
55MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
56MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
57
58/*******************************************************************************
59 *
60 * FUNCTION: acpi_hw_execute_sleep_method
61 *
62 * PARAMETERS: method_name - Pathname of method to execute
63 * integer_argument - Argument to pass to the method
64 *
65 * RETURN: None
66 *
67 * DESCRIPTION: Execute a sleep/wake related method with one integer argument
68 * and no return value.
69 *
70 ******************************************************************************/
71void acpi_hw_execute_sleep_method(char *method_name, u32 integer_argument)
72{
73 struct acpi_object_list arg_list;
74 union acpi_object arg;
75 acpi_status status;
76
77 ACPI_FUNCTION_TRACE(hw_execute_sleep_method);
78
79 if (!ACPI_STRCMP(METHOD_NAME__GTS, method_name) && !gts)
80 return_VOID;
81
82 if (!ACPI_STRCMP(METHOD_NAME__BFS, method_name) && !bfs)
83 return_VOID;
84
85 /* One argument, integer_argument; No return value expected */
86
87 arg_list.count = 1;
88 arg_list.pointer = &arg;
89 arg.type = ACPI_TYPE_INTEGER;
90 arg.integer.value = (u64)integer_argument;
91
92 status = acpi_evaluate_object(NULL, method_name, &arg_list, NULL);
93 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
94 ACPI_EXCEPTION((AE_INFO, status, "While executing method %s",
95 method_name));
96 }
97
98 return_VOID;
99}
100
101/*******************************************************************************
102 *
103 * FUNCTION: acpi_hw_extended_sleep
104 *
105 * PARAMETERS: sleep_state - Which sleep state to enter
106 *
107 * RETURN: Status
108 *
109 * DESCRIPTION: Enter a system sleep state via the extended FADT sleep
110 * registers (V5 FADT).
111 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
112 *
113 ******************************************************************************/
114
115acpi_status acpi_hw_extended_sleep(u8 sleep_state)
116{
117 acpi_status status;
118 u8 sleep_type_value;
119 u64 sleep_status;
120
121 ACPI_FUNCTION_TRACE(hw_extended_sleep);
122
123 /* Extended sleep registers must be valid */
124
125 if (!acpi_gbl_FADT.sleep_control.address ||
126 !acpi_gbl_FADT.sleep_status.address) {
127 return_ACPI_STATUS(AE_NOT_EXIST);
128 }
129
130 /* Clear wake status (WAK_STS) */
131
132 status = acpi_write(ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
133 if (ACPI_FAILURE(status)) {
134 return_ACPI_STATUS(status);
135 }
136
137 acpi_gbl_system_awake_and_running = FALSE;
138
139 /* Execute the _GTS method (Going To Sleep) */
140
141 acpi_hw_execute_sleep_method(METHOD_NAME__GTS, sleep_state);
142
143 /* Flush caches, as per ACPI specification */
144
145 ACPI_FLUSH_CPU_CACHE();
146
147 /*
148 * Set the SLP_TYP and SLP_EN bits.
149 *
150 * Note: We only use the first value returned by the \_Sx method
151 * (acpi_gbl_sleep_type_a) - As per ACPI specification.
152 */
153 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
154 "Entering sleep state [S%u]\n", sleep_state));
155
156 sleep_type_value =
157 ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
158 ACPI_X_SLEEP_TYPE_MASK);
159
160 status = acpi_write((sleep_type_value | ACPI_X_SLEEP_ENABLE),
161 &acpi_gbl_FADT.sleep_control);
162 if (ACPI_FAILURE(status)) {
163 return_ACPI_STATUS(status);
164 }
165
166 /* Wait for transition back to Working State */
167
168 do {
169 status = acpi_read(&sleep_status, &acpi_gbl_FADT.sleep_status);
170 if (ACPI_FAILURE(status)) {
171 return_ACPI_STATUS(status);
172 }
173
174 } while (!(((u8)sleep_status) & ACPI_X_WAKE_STATUS));
175
176 return_ACPI_STATUS(AE_OK);
177}
178
179/*******************************************************************************
180 *
181 * FUNCTION: acpi_hw_extended_wake_prep
182 *
183 * PARAMETERS: sleep_state - Which sleep state we just exited
184 *
185 * RETURN: Status
186 *
187 * DESCRIPTION: Perform first part of OS-independent ACPI cleanup after
188 * a sleep. Called with interrupts ENABLED.
189 *
190 ******************************************************************************/
191
192acpi_status acpi_hw_extended_wake_prep(u8 sleep_state)
193{
194 acpi_status status;
195 u8 sleep_type_value;
196
197 ACPI_FUNCTION_TRACE(hw_extended_wake_prep);
198
199 status = acpi_get_sleep_type_data(ACPI_STATE_S0,
200 &acpi_gbl_sleep_type_a,
201 &acpi_gbl_sleep_type_b);
202 if (ACPI_SUCCESS(status)) {
203 sleep_type_value =
204 ((acpi_gbl_sleep_type_a << ACPI_X_SLEEP_TYPE_POSITION) &
205 ACPI_X_SLEEP_TYPE_MASK);
206
207 (void)acpi_write((sleep_type_value | ACPI_X_SLEEP_ENABLE),
208 &acpi_gbl_FADT.sleep_control);
209 }
210
211 acpi_hw_execute_sleep_method(METHOD_NAME__BFS, sleep_state);
212 return_ACPI_STATUS(AE_OK);
213}
214
215/*******************************************************************************
216 *
217 * FUNCTION: acpi_hw_extended_wake
218 *
219 * PARAMETERS: sleep_state - Which sleep state we just exited
220 *
221 * RETURN: Status
222 *
223 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
224 * Called with interrupts ENABLED.
225 *
226 ******************************************************************************/
227
228acpi_status acpi_hw_extended_wake(u8 sleep_state)
229{
230 ACPI_FUNCTION_TRACE(hw_extended_wake);
231
232 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
233
234 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
235
236 /* Execute the wake methods */
237
238 acpi_hw_execute_sleep_method(METHOD_NAME__SST, ACPI_SST_WAKING);
239 acpi_hw_execute_sleep_method(METHOD_NAME__WAK, sleep_state);
240
241 /*
242 * Some BIOS code assumes that WAK_STS will be cleared on resume
243 * and use it to determine whether the system is rebooting or
244 * resuming. Clear WAK_STS for compatibility.
245 */
246 (void)acpi_write(ACPI_X_WAKE_STATUS, &acpi_gbl_FADT.sleep_status);
247 acpi_gbl_system_awake_and_running = TRUE;
248
249 acpi_hw_execute_sleep_method(METHOD_NAME__SST, ACPI_SST_WORKING);
250 return_ACPI_STATUS(AE_OK);
251}