blob: ff2055804809f6807d202ab9a77df9e902297734 [file] [log] [blame]
Bob Moore2feec472012-02-14 15:00:53 +08001/******************************************************************************
2 *
3 * Name: hwxfsleep.c - ACPI Hardware Sleep/Wake External Interfaces
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2012, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include <linux/module.h>
47
48#define _COMPONENT ACPI_HARDWARE
49ACPI_MODULE_NAME("hwxfsleep")
50
Bob Moore33620c52012-02-14 18:14:27 +080051#if (!ACPI_REDUCED_HARDWARE)
Bob Moore2feec472012-02-14 15:00:53 +080052/*******************************************************************************
53 *
54 * FUNCTION: acpi_set_firmware_waking_vector
55 *
56 * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode
57 * entry point.
58 *
59 * RETURN: Status
60 *
61 * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS
62 *
63 ******************************************************************************/
64acpi_status acpi_set_firmware_waking_vector(u32 physical_address)
65{
66 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
67
68
69 /*
70 * According to the ACPI specification 2.0c and later, the 64-bit
71 * waking vector should be cleared and the 32-bit waking vector should
72 * be used, unless we want the wake-up code to be called by the BIOS in
73 * Protected Mode. Some systems (for example HP dv5-1004nr) are known
74 * to fail to resume if the 64-bit vector is used.
75 */
76
77 /* Set the 32-bit vector */
78
79 acpi_gbl_FACS->firmware_waking_vector = physical_address;
80
81 /* Clear the 64-bit vector if it exists */
82
83 if ((acpi_gbl_FACS->length > 32) && (acpi_gbl_FACS->version >= 1)) {
84 acpi_gbl_FACS->xfirmware_waking_vector = 0;
85 }
86
87 return_ACPI_STATUS(AE_OK);
88}
89
90ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
91
92#if ACPI_MACHINE_WIDTH == 64
93/*******************************************************************************
94 *
95 * FUNCTION: acpi_set_firmware_waking_vector64
96 *
97 * PARAMETERS: physical_address - 64-bit physical address of ACPI protected
98 * mode entry point.
99 *
100 * RETURN: Status
101 *
102 * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if
103 * it exists in the table. This function is intended for use with
104 * 64-bit host operating systems.
105 *
106 ******************************************************************************/
107acpi_status acpi_set_firmware_waking_vector64(u64 physical_address)
108{
109 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64);
110
111
112 /* Determine if the 64-bit vector actually exists */
113
114 if ((acpi_gbl_FACS->length <= 32) || (acpi_gbl_FACS->version < 1)) {
115 return_ACPI_STATUS(AE_NOT_EXIST);
116 }
117
118 /* Clear 32-bit vector, set the 64-bit X_ vector */
119
120 acpi_gbl_FACS->firmware_waking_vector = 0;
121 acpi_gbl_FACS->xfirmware_waking_vector = physical_address;
122 return_ACPI_STATUS(AE_OK);
123}
124
125ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64)
126#endif
127
128/*******************************************************************************
129 *
130 * FUNCTION: acpi_enter_sleep_state_s4bios
131 *
132 * PARAMETERS: None
133 *
134 * RETURN: Status
135 *
136 * DESCRIPTION: Perform a S4 bios request.
137 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
138 *
139 ******************************************************************************/
140acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
141{
142 u32 in_value;
143 acpi_status status;
144
145 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios);
146
147 /* Clear the wake status bit (PM1) */
148
149 status =
150 acpi_write_bit_register(ACPI_BITREG_WAKE_STATUS, ACPI_CLEAR_STATUS);
151 if (ACPI_FAILURE(status)) {
152 return_ACPI_STATUS(status);
153 }
154
155 status = acpi_hw_clear_acpi_status();
156 if (ACPI_FAILURE(status)) {
157 return_ACPI_STATUS(status);
158 }
159
160 /*
161 * 1) Disable/Clear all GPEs
162 * 2) Enable all wakeup GPEs
163 */
164 status = acpi_hw_disable_all_gpes();
165 if (ACPI_FAILURE(status)) {
166 return_ACPI_STATUS(status);
167 }
168 acpi_gbl_system_awake_and_running = FALSE;
169
170 status = acpi_hw_enable_all_wakeup_gpes();
171 if (ACPI_FAILURE(status)) {
172 return_ACPI_STATUS(status);
173 }
174
175 ACPI_FLUSH_CPU_CACHE();
176
177 status = acpi_hw_write_port(acpi_gbl_FADT.smi_command,
178 (u32)acpi_gbl_FADT.S4bios_request, 8);
179
180 do {
181 acpi_os_stall(1000);
182 status =
183 acpi_read_bit_register(ACPI_BITREG_WAKE_STATUS, &in_value);
184 if (ACPI_FAILURE(status)) {
185 return_ACPI_STATUS(status);
186 }
187 } while (!in_value);
188
189 return_ACPI_STATUS(AE_OK);
190}
191
192ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
Bob Moore33620c52012-02-14 18:14:27 +0800193#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore2feec472012-02-14 15:00:53 +0800194/*******************************************************************************
195 *
196 * FUNCTION: acpi_enter_sleep_state_prep
197 *
198 * PARAMETERS: sleep_state - Which sleep state to enter
199 *
200 * RETURN: Status
201 *
202 * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231)
203 * This function must execute with interrupts enabled.
204 * We break sleeping into 2 stages so that OSPM can handle
205 * various OS-specific tasks between the two steps.
206 *
207 ******************************************************************************/
208acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
209{
210 acpi_status status;
211 struct acpi_object_list arg_list;
212 union acpi_object arg;
213 u32 sst_value;
214
215 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep);
216
217 /* _PSW methods could be run here to enable wake-on keyboard, LAN, etc. */
218
219 status = acpi_get_sleep_type_data(sleep_state,
220 &acpi_gbl_sleep_type_a,
221 &acpi_gbl_sleep_type_b);
222 if (ACPI_FAILURE(status)) {
223 return_ACPI_STATUS(status);
224 }
225
226 /* Execute the _PTS method (Prepare To Sleep) */
227
228 arg_list.count = 1;
229 arg_list.pointer = &arg;
230 arg.type = ACPI_TYPE_INTEGER;
231 arg.integer.value = sleep_state;
232
233 status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL);
234 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
235 return_ACPI_STATUS(status);
236 }
237
238 /* Setup the argument to the _SST method (System STatus) */
239
240 switch (sleep_state) {
241 case ACPI_STATE_S0:
242 sst_value = ACPI_SST_WORKING;
243 break;
244
245 case ACPI_STATE_S1:
246 case ACPI_STATE_S2:
247 case ACPI_STATE_S3:
248 sst_value = ACPI_SST_SLEEPING;
249 break;
250
251 case ACPI_STATE_S4:
252 sst_value = ACPI_SST_SLEEP_CONTEXT;
253 break;
254
255 default:
256 sst_value = ACPI_SST_INDICATOR_OFF; /* Default is off */
257 break;
258 }
259
260 /*
261 * Set the system indicators to show the desired sleep state.
262 * _SST is an optional method (return no error if not found)
263 */
Bob Mooref99648b2012-02-14 18:43:03 +0800264 acpi_hw_execute_sleep_method(METHOD_NAME__SST, sst_value);
Bob Moore2feec472012-02-14 15:00:53 +0800265 return_ACPI_STATUS(AE_OK);
266}
267
268ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep)
269
270/*******************************************************************************
271 *
272 * FUNCTION: acpi_enter_sleep_state
273 *
274 * PARAMETERS: sleep_state - Which sleep state to enter
275 *
276 * RETURN: Status
277 *
278 * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
279 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
280 *
281 ******************************************************************************/
282acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
283{
284 acpi_status status;
285
286 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state);
287
288 if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
289 (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
290 ACPI_ERROR((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X",
291 acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
292 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
293 }
Bob Moore33620c52012-02-14 18:14:27 +0800294#if (!ACPI_REDUCED_HARDWARE)
Bob Moore2feec472012-02-14 15:00:53 +0800295
296 /* If Hardware Reduced flag is set, must use the extended sleep registers */
297
298 if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
299 status = acpi_hw_extended_sleep(sleep_state);
300 } else {
301 /* Legacy sleep */
302
303 status = acpi_hw_legacy_sleep(sleep_state);
304 }
305
Bob Moore33620c52012-02-14 18:14:27 +0800306#else
307 status = acpi_hw_extended_sleep(sleep_state);
308
309#endif /* !ACPI_REDUCED_HARDWARE */
310
Bob Moore2feec472012-02-14 15:00:53 +0800311 return_ACPI_STATUS(status);
312}
313
314ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state)
315
316/*******************************************************************************
317 *
318 * FUNCTION: acpi_leave_sleep_state_prep
319 *
320 * PARAMETERS: sleep_state - Which sleep state we are exiting
321 *
322 * RETURN: Status
323 *
324 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
325 * sleep.
326 * Called with interrupts DISABLED.
327 *
328 ******************************************************************************/
329acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
330{
331 acpi_status status;
332
333 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
334
335
Bob Moore33620c52012-02-14 18:14:27 +0800336#if (!ACPI_REDUCED_HARDWARE)
337
Bob Moore2feec472012-02-14 15:00:53 +0800338 /* If Hardware Reduced flag is set, must use the extended sleep registers */
339
340 if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
341 status = acpi_hw_extended_wake_prep(sleep_state);
342 } else {
343 /* Legacy sleep */
344
345 status = acpi_hw_legacy_wake_prep(sleep_state);
346 }
Bob Moore33620c52012-02-14 18:14:27 +0800347#else
348 status = acpi_hw_extended_wake_prep(sleep_state);
349
350#endif /* !ACPI_REDUCED_HARDWARE */
Bob Moore2feec472012-02-14 15:00:53 +0800351
352
353 return_ACPI_STATUS(status);
354}
355
356ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state_prep)
357
358/*******************************************************************************
359 *
360 * FUNCTION: acpi_leave_sleep_state
361 *
362 * PARAMETERS: sleep_state - Which sleep state we just exited
363 *
364 * RETURN: Status
365 *
366 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
367 * Called with interrupts ENABLED.
368 *
369 ******************************************************************************/
370acpi_status acpi_leave_sleep_state(u8 sleep_state)
371{
372 acpi_status status;
373
374 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
375
376
Bob Moore33620c52012-02-14 18:14:27 +0800377#if (!ACPI_REDUCED_HARDWARE)
378
Bob Moore2feec472012-02-14 15:00:53 +0800379 /* If Hardware Reduced flag is set, must use the extended sleep registers */
380
381 if (acpi_gbl_reduced_hardware || acpi_gbl_FADT.sleep_control.address) {
382 status = acpi_hw_extended_wake(sleep_state);
383 } else {
384 /* Legacy sleep */
385
386 status = acpi_hw_legacy_wake(sleep_state);
387 }
388
Bob Moore33620c52012-02-14 18:14:27 +0800389#else
390 status = acpi_hw_extended_wake(sleep_state);
391
392#endif /* !ACPI_REDUCED_HARDWARE */
393
Bob Moore2feec472012-02-14 15:00:53 +0800394 return_ACPI_STATUS(status);
395}
396
397ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state)