]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/acpi/acpica/hwsleep.c
ACPICA: Remove ACPI_GET_OBJECT_TYPE macro
[mirror_ubuntu-hirsute-kernel.git] / drivers / acpi / acpica / hwsleep.c
CommitLineData
1da177e4
LT
1
2/******************************************************************************
3 *
4 * Name: hwsleep.c - ACPI Hardware Sleep/Wake Interface
5 *
6 *****************************************************************************/
7
8/*
75a44ce0 9 * Copyright (C) 2000 - 2008, Intel Corp.
1da177e4
LT
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
1da177e4 45#include <acpi/acpi.h>
e2f7a777
LB
46#include "accommon.h"
47#include "actables.h"
1da177e4
LT
48
49#define _COMPONENT ACPI_HARDWARE
4be44fcd 50ACPI_MODULE_NAME("hwsleep")
1da177e4 51
44f6c012 52/*******************************************************************************
1da177e4
LT
53 *
54 * FUNCTION: acpi_set_firmware_waking_vector
55 *
d85988fa 56 * PARAMETERS: physical_address - 32-bit physical address of ACPI real mode
1da177e4
LT
57 * entry point.
58 *
59 * RETURN: Status
60 *
d85988fa 61 * DESCRIPTION: Sets the 32-bit firmware_waking_vector field of the FACS
1da177e4
LT
62 *
63 ******************************************************************************/
1da177e4 64acpi_status
d85988fa 65acpi_set_firmware_waking_vector(u32 physical_address)
1da177e4 66{
b229cf92 67 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector);
1da177e4 68
f3d2e786 69
a6629105
RW
70 /*
71 * According to the ACPI specification 2.0c and later, the 64-bit
72 * waking vector should be cleared and the 32-bit waking vector should
73 * be used, unless we want the wake-up code to be called by the BIOS in
74 * Protected Mode. Some systems (for example HP dv5-1004nr) are known
75 * to fail to resume if the 64-bit vector is used.
76 */
a6629105 77
d85988fa
BM
78 /* Set the 32-bit vector */
79
009c4cbe 80 acpi_gbl_FACS->firmware_waking_vector = physical_address;
d85988fa
BM
81
82 /* Clear the 64-bit vector if it exists */
83
009c4cbe
BM
84 if ((acpi_gbl_FACS->length > 32) && (acpi_gbl_FACS->version >= 1)) {
85 acpi_gbl_FACS->xfirmware_waking_vector = 0;
d85988fa 86 }
1da177e4 87
4be44fcd 88 return_ACPI_STATUS(AE_OK);
1da177e4
LT
89}
90
8313524a
BM
91ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector)
92
44f6c012 93/*******************************************************************************
1da177e4 94 *
d85988fa 95 * FUNCTION: acpi_set_firmware_waking_vector64
1da177e4 96 *
d85988fa
BM
97 * PARAMETERS: physical_address - 64-bit physical address of ACPI protected
98 * mode entry point.
1da177e4 99 *
d85988fa 100 * RETURN: Status
1da177e4 101 *
d85988fa
BM
102 * DESCRIPTION: Sets the 64-bit X_firmware_waking_vector field of the FACS, if
103 * it exists in the table.
1da177e4
LT
104 *
105 ******************************************************************************/
1da177e4 106acpi_status
d85988fa 107acpi_set_firmware_waking_vector64(u64 physical_address)
1da177e4 108{
d85988fa 109 ACPI_FUNCTION_TRACE(acpi_set_firmware_waking_vector64);
1da177e4 110
1da177e4 111
d85988fa
BM
112 /* Determine if the 64-bit vector actually exists */
113
009c4cbe 114 if ((acpi_gbl_FACS->length <= 32) || (acpi_gbl_FACS->version < 1)) {
d85988fa
BM
115 return_ACPI_STATUS(AE_NOT_EXIST);
116 }
117
118 /* Clear 32-bit vector, set the 64-bit X_ vector */
119
009c4cbe
BM
120 acpi_gbl_FACS->firmware_waking_vector = 0;
121 acpi_gbl_FACS->xfirmware_waking_vector = physical_address;
1da177e4 122
4be44fcd 123 return_ACPI_STATUS(AE_OK);
1da177e4 124}
8313524a 125
d85988fa
BM
126ACPI_EXPORT_SYMBOL(acpi_set_firmware_waking_vector64)
127
44f6c012 128/*******************************************************************************
1da177e4
LT
129 *
130 * FUNCTION: acpi_enter_sleep_state_prep
131 *
132 * PARAMETERS: sleep_state - Which sleep state to enter
133 *
134 * RETURN: Status
135 *
136 * DESCRIPTION: Prepare to enter a system sleep state (see ACPI 2.0 spec p 231)
137 * This function must execute with interrupts enabled.
138 * We break sleeping into 2 stages so that OSPM can handle
139 * various OS-specific tasks between the two steps.
140 *
141 ******************************************************************************/
4be44fcd 142acpi_status acpi_enter_sleep_state_prep(u8 sleep_state)
1da177e4 143{
4be44fcd
LB
144 acpi_status status;
145 struct acpi_object_list arg_list;
146 union acpi_object arg;
1da177e4 147
b229cf92 148 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_prep);
1da177e4 149
32c9ef99
BM
150 /* _PSW methods could be run here to enable wake-on keyboard, LAN, etc. */
151
4be44fcd
LB
152 status = acpi_get_sleep_type_data(sleep_state,
153 &acpi_gbl_sleep_type_a,
154 &acpi_gbl_sleep_type_b);
155 if (ACPI_FAILURE(status)) {
156 return_ACPI_STATUS(status);
1da177e4
LT
157 }
158
159 /* Setup parameter object */
160
161 arg_list.count = 1;
162 arg_list.pointer = &arg;
163
164 arg.type = ACPI_TYPE_INTEGER;
165 arg.integer.value = sleep_state;
166
c95d47a8 167 /* Run the _PTS method */
1da177e4 168
4be44fcd
LB
169 status = acpi_evaluate_object(NULL, METHOD_NAME__PTS, &arg_list, NULL);
170 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
171 return_ACPI_STATUS(status);
1da177e4
LT
172 }
173
1da177e4
LT
174 /* Setup the argument to _SST */
175
176 switch (sleep_state) {
177 case ACPI_STATE_S0:
178 arg.integer.value = ACPI_SST_WORKING;
179 break;
180
181 case ACPI_STATE_S1:
182 case ACPI_STATE_S2:
183 case ACPI_STATE_S3:
184 arg.integer.value = ACPI_SST_SLEEPING;
185 break;
186
187 case ACPI_STATE_S4:
188 arg.integer.value = ACPI_SST_SLEEP_CONTEXT;
189 break;
190
191 default:
4be44fcd 192 arg.integer.value = ACPI_SST_INDICATOR_OFF; /* Default is off */
1da177e4
LT
193 break;
194 }
195
d52c79ac
BM
196 /*
197 * Set the system indicators to show the desired sleep state.
198 * _SST is an optional method (return no error if not found)
199 */
4be44fcd
LB
200 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
201 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
b8e4d893
BM
202 ACPI_EXCEPTION((AE_INFO, status,
203 "While executing method _SST"));
1da177e4
LT
204 }
205
d52c79ac 206 return_ACPI_STATUS(AE_OK);
1da177e4
LT
207}
208
8313524a
BM
209ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_prep)
210
44f6c012 211/*******************************************************************************
1da177e4
LT
212 *
213 * FUNCTION: acpi_enter_sleep_state
214 *
215 * PARAMETERS: sleep_state - Which sleep state to enter
216 *
217 * RETURN: Status
218 *
219 * DESCRIPTION: Enter a system sleep state (see ACPI 2.0 spec p 231)
220 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
221 *
222 ******************************************************************************/
4be44fcd 223acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
1da177e4 224{
32c9ef99
BM
225 u32 pm1a_control;
226 u32 pm1b_control;
4be44fcd
LB
227 struct acpi_bit_register_info *sleep_type_reg_info;
228 struct acpi_bit_register_info *sleep_enable_reg_info;
229 u32 in_value;
c95d47a8
RW
230 struct acpi_object_list arg_list;
231 union acpi_object arg;
4be44fcd 232 acpi_status status;
1da177e4 233
b229cf92 234 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state);
1da177e4
LT
235
236 if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
4be44fcd 237 (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
b8e4d893
BM
238 ACPI_ERROR((AE_INFO, "Sleep values out of range: A=%X B=%X",
239 acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
4be44fcd 240 return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
1da177e4
LT
241 }
242
4be44fcd 243 sleep_type_reg_info =
82d79b86 244 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE);
4be44fcd
LB
245 sleep_enable_reg_info =
246 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE);
1da177e4
LT
247
248 /* Clear wake status */
249
d8c71b6d 250 status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
4be44fcd
LB
251 if (ACPI_FAILURE(status)) {
252 return_ACPI_STATUS(status);
1da177e4
LT
253 }
254
255 /* Clear all fixed and general purpose status bits */
256
d8c71b6d 257 status = acpi_hw_clear_acpi_status();
4be44fcd
LB
258 if (ACPI_FAILURE(status)) {
259 return_ACPI_STATUS(status);
1da177e4
LT
260 }
261
262 /*
23b168d4 263 * 1) Disable/Clear all GPEs
1da177e4
LT
264 * 2) Enable all wakeup GPEs
265 */
1d99967b
AS
266 status = acpi_hw_disable_all_gpes();
267 if (ACPI_FAILURE(status)) {
268 return_ACPI_STATUS(status);
269 }
1da177e4
LT
270 acpi_gbl_system_awake_and_running = FALSE;
271
4be44fcd
LB
272 status = acpi_hw_enable_all_wakeup_gpes();
273 if (ACPI_FAILURE(status)) {
274 return_ACPI_STATUS(status);
1da177e4
LT
275 }
276
c95d47a8
RW
277 /* Execute the _GTS method */
278
279 arg_list.count = 1;
280 arg_list.pointer = &arg;
281 arg.type = ACPI_TYPE_INTEGER;
282 arg.integer.value = sleep_state;
283
284 status = acpi_evaluate_object(NULL, METHOD_NAME__GTS, &arg_list, NULL);
285 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
286 return_ACPI_STATUS(status);
287 }
288
1da177e4
LT
289 /* Get current value of PM1A control */
290
32c9ef99
BM
291 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
292 &pm1a_control);
4be44fcd
LB
293 if (ACPI_FAILURE(status)) {
294 return_ACPI_STATUS(status);
1da177e4 295 }
4be44fcd
LB
296 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
297 "Entering sleep state [S%d]\n", sleep_state));
1da177e4 298
32c9ef99 299 /* Clear the SLP_EN and SLP_TYP fields */
1da177e4 300
32c9ef99
BM
301 pm1a_control &= ~(sleep_type_reg_info->access_bit_mask |
302 sleep_enable_reg_info->access_bit_mask);
303 pm1b_control = pm1a_control;
1da177e4 304
32c9ef99 305 /* Insert the SLP_TYP bits */
1da177e4 306
32c9ef99 307 pm1a_control |=
4be44fcd 308 (acpi_gbl_sleep_type_a << sleep_type_reg_info->bit_position);
32c9ef99 309 pm1b_control |=
4be44fcd 310 (acpi_gbl_sleep_type_b << sleep_type_reg_info->bit_position);
1da177e4
LT
311
312 /*
313 * We split the writes of SLP_TYP and SLP_EN to workaround
314 * poorly implemented hardware.
315 */
316
32c9ef99 317 /* Write #1: write the SLP_TYP data to the PM1 Control registers */
1da177e4 318
32c9ef99 319 status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control);
4be44fcd
LB
320 if (ACPI_FAILURE(status)) {
321 return_ACPI_STATUS(status);
1da177e4
LT
322 }
323
32c9ef99 324 /* Insert the sleep enable (SLP_EN) bit */
1da177e4 325
32c9ef99
BM
326 pm1a_control |= sleep_enable_reg_info->access_bit_mask;
327 pm1b_control |= sleep_enable_reg_info->access_bit_mask;
1da177e4 328
32c9ef99 329 /* Flush caches, as per ACPI specification */
1da177e4 330
4be44fcd 331 ACPI_FLUSH_CPU_CACHE();
1da177e4 332
32c9ef99 333 /* Write #2: Write both SLP_TYP + SLP_EN */
1da177e4 334
32c9ef99 335 status = acpi_hw_write_pm1_control(pm1a_control, pm1b_control);
4be44fcd
LB
336 if (ACPI_FAILURE(status)) {
337 return_ACPI_STATUS(status);
1da177e4
LT
338 }
339
340 if (sleep_state > ACPI_STATE_S3) {
341 /*
44f6c012
RM
342 * We wanted to sleep > S3, but it didn't happen (by virtue of the
343 * fact that we are still executing!)
1da177e4 344 *
44f6c012
RM
345 * Wait ten seconds, then try again. This is to get S4/S5 to work on
346 * all machines.
1da177e4
LT
347 *
348 * We wait so long to allow chipsets that poll this reg very slowly to
349 * still read the right value. Ideally, this block would go
350 * away entirely.
351 */
4be44fcd
LB
352 acpi_os_stall(10000000);
353
d30dc9ab 354 status = acpi_hw_register_write(ACPI_REGISTER_PM1_CONTROL,
4be44fcd
LB
355 sleep_enable_reg_info->
356 access_bit_mask);
357 if (ACPI_FAILURE(status)) {
358 return_ACPI_STATUS(status);
1da177e4
LT
359 }
360 }
361
362 /* Wait until we enter sleep state */
363
364 do {
2d571b33
AS
365 status = acpi_get_register_unlocked(ACPI_BITREG_WAKE_STATUS,
366 &in_value);
4be44fcd
LB
367 if (ACPI_FAILURE(status)) {
368 return_ACPI_STATUS(status);
1da177e4
LT
369 }
370
371 /* Spin until we wake */
372
373 } while (!in_value);
374
4be44fcd 375 return_ACPI_STATUS(AE_OK);
1da177e4 376}
1da177e4 377
8313524a 378ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state)
1da177e4 379
44f6c012 380/*******************************************************************************
1da177e4
LT
381 *
382 * FUNCTION: acpi_enter_sleep_state_s4bios
383 *
384 * PARAMETERS: None
385 *
386 * RETURN: Status
387 *
388 * DESCRIPTION: Perform a S4 bios request.
389 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED
390 *
391 ******************************************************************************/
4be44fcd 392acpi_status asmlinkage acpi_enter_sleep_state_s4bios(void)
1da177e4 393{
4be44fcd
LB
394 u32 in_value;
395 acpi_status status;
1da177e4 396
b229cf92 397 ACPI_FUNCTION_TRACE(acpi_enter_sleep_state_s4bios);
1da177e4 398
d8c71b6d 399 status = acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
4be44fcd
LB
400 if (ACPI_FAILURE(status)) {
401 return_ACPI_STATUS(status);
1da177e4
LT
402 }
403
d8c71b6d 404 status = acpi_hw_clear_acpi_status();
4be44fcd
LB
405 if (ACPI_FAILURE(status)) {
406 return_ACPI_STATUS(status);
1da177e4
LT
407 }
408
409 /*
410 * 1) Disable/Clear all GPEs
411 * 2) Enable all wakeup GPEs
412 */
4be44fcd
LB
413 status = acpi_hw_disable_all_gpes();
414 if (ACPI_FAILURE(status)) {
415 return_ACPI_STATUS(status);
1da177e4
LT
416 }
417 acpi_gbl_system_awake_and_running = FALSE;
418
4be44fcd
LB
419 status = acpi_hw_enable_all_wakeup_gpes();
420 if (ACPI_FAILURE(status)) {
421 return_ACPI_STATUS(status);
1da177e4
LT
422 }
423
4be44fcd 424 ACPI_FLUSH_CPU_CACHE();
1da177e4 425
f3d2e786
BM
426 status = acpi_os_write_port(acpi_gbl_FADT.smi_command,
427 (u32) acpi_gbl_FADT.S4bios_request, 8);
1da177e4
LT
428
429 do {
430 acpi_os_stall(1000);
d8c71b6d 431 status = acpi_get_register(ACPI_BITREG_WAKE_STATUS, &in_value);
4be44fcd
LB
432 if (ACPI_FAILURE(status)) {
433 return_ACPI_STATUS(status);
1da177e4
LT
434 }
435 } while (!in_value);
436
4be44fcd 437 return_ACPI_STATUS(AE_OK);
1da177e4 438}
1da177e4 439
8313524a 440ACPI_EXPORT_SYMBOL(acpi_enter_sleep_state_s4bios)
1da177e4 441
44f6c012 442/*******************************************************************************
1da177e4 443 *
c95d47a8 444 * FUNCTION: acpi_leave_sleep_state_prep
1da177e4 445 *
c95d47a8 446 * PARAMETERS: sleep_state - Which sleep state we are exiting
1da177e4
LT
447 *
448 * RETURN: Status
449 *
c95d47a8
RW
450 * DESCRIPTION: Perform the first state of OS-independent ACPI cleanup after a
451 * sleep.
452 * Called with interrupts DISABLED.
1da177e4
LT
453 *
454 ******************************************************************************/
c95d47a8 455acpi_status acpi_leave_sleep_state_prep(u8 sleep_state)
1da177e4 456{
4be44fcd
LB
457 struct acpi_object_list arg_list;
458 union acpi_object arg;
459 acpi_status status;
460 struct acpi_bit_register_info *sleep_type_reg_info;
461 struct acpi_bit_register_info *sleep_enable_reg_info;
32c9ef99
BM
462 u32 pm1a_control;
463 u32 pm1b_control;
1da177e4 464
c95d47a8 465 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state_prep);
1da177e4
LT
466
467 /*
468 * Set SLP_TYPE and SLP_EN to state S0.
469 * This is unclear from the ACPI Spec, but it is required
470 * by some machines.
471 */
4be44fcd
LB
472 status = acpi_get_sleep_type_data(ACPI_STATE_S0,
473 &acpi_gbl_sleep_type_a,
474 &acpi_gbl_sleep_type_b);
475 if (ACPI_SUCCESS(status)) {
476 sleep_type_reg_info =
82d79b86 477 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_TYPE);
4be44fcd
LB
478 sleep_enable_reg_info =
479 acpi_hw_get_bit_register_info(ACPI_BITREG_SLEEP_ENABLE);
1da177e4
LT
480
481 /* Get current value of PM1A control */
482
d30dc9ab 483 status = acpi_hw_register_read(ACPI_REGISTER_PM1_CONTROL,
32c9ef99 484 &pm1a_control);
4be44fcd 485 if (ACPI_SUCCESS(status)) {
52fc0b02 486
32c9ef99 487 /* Clear the SLP_EN and SLP_TYP fields */
1da177e4 488
32c9ef99
BM
489 pm1a_control &= ~(sleep_type_reg_info->access_bit_mask |
490 sleep_enable_reg_info->
491 access_bit_mask);
492 pm1b_control = pm1a_control;
1da177e4 493
32c9ef99 494 /* Insert the SLP_TYP bits */
1da177e4 495
32c9ef99 496 pm1a_control |=
4be44fcd
LB
497 (acpi_gbl_sleep_type_a << sleep_type_reg_info->
498 bit_position);
32c9ef99 499 pm1b_control |=
4be44fcd
LB
500 (acpi_gbl_sleep_type_b << sleep_type_reg_info->
501 bit_position);
1da177e4 502
32c9ef99 503 /* Write the control registers and ignore any errors */
1da177e4 504
32c9ef99
BM
505 (void)acpi_hw_write_pm1_control(pm1a_control,
506 pm1b_control);
1da177e4
LT
507 }
508 }
509
c95d47a8
RW
510 /* Execute the _BFS method */
511
512 arg_list.count = 1;
513 arg_list.pointer = &arg;
514 arg.type = ACPI_TYPE_INTEGER;
515 arg.integer.value = sleep_state;
516
517 status = acpi_evaluate_object(NULL, METHOD_NAME__BFS, &arg_list, NULL);
518 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
519 ACPI_EXCEPTION((AE_INFO, status, "During Method _BFS"));
520 }
521
522 return_ACPI_STATUS(status);
523}
524
525/*******************************************************************************
526 *
527 * FUNCTION: acpi_leave_sleep_state
528 *
529 * PARAMETERS: sleep_state - Which sleep state we just exited
530 *
531 * RETURN: Status
532 *
533 * DESCRIPTION: Perform OS-independent ACPI cleanup after a sleep
534 * Called with interrupts ENABLED.
535 *
536 ******************************************************************************/
537acpi_status acpi_leave_sleep_state(u8 sleep_state)
538{
539 struct acpi_object_list arg_list;
540 union acpi_object arg;
541 acpi_status status;
542
543 ACPI_FUNCTION_TRACE(acpi_leave_sleep_state);
544
1da177e4
LT
545 /* Ensure enter_sleep_state_prep -> enter_sleep_state ordering */
546
547 acpi_gbl_sleep_type_a = ACPI_SLEEP_TYPE_INVALID;
548
549 /* Setup parameter object */
550
551 arg_list.count = 1;
552 arg_list.pointer = &arg;
553 arg.type = ACPI_TYPE_INTEGER;
554
555 /* Ignore any errors from these methods */
556
557 arg.integer.value = ACPI_SST_WAKING;
4be44fcd
LB
558 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
559 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
b8e4d893 560 ACPI_EXCEPTION((AE_INFO, status, "During Method _SST"));
1da177e4
LT
561 }
562
1da177e4 563 /*
79d2dfaa
TR
564 * GPEs must be enabled before _WAK is called as GPEs
565 * might get fired there
566 *
1da177e4
LT
567 * Restore the GPEs:
568 * 1) Disable/Clear all GPEs
569 * 2) Enable all runtime GPEs
570 */
4be44fcd
LB
571 status = acpi_hw_disable_all_gpes();
572 if (ACPI_FAILURE(status)) {
573 return_ACPI_STATUS(status);
1da177e4 574 }
4be44fcd
LB
575 status = acpi_hw_enable_all_runtime_gpes();
576 if (ACPI_FAILURE(status)) {
577 return_ACPI_STATUS(status);
1da177e4
LT
578 }
579
314ccd64 580 arg.integer.value = sleep_state;
79d2dfaa
TR
581 status = acpi_evaluate_object(NULL, METHOD_NAME__WAK, &arg_list, NULL);
582 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
583 ACPI_EXCEPTION((AE_INFO, status, "During Method _WAK"));
584 }
585 /* TBD: _WAK "sometimes" returns stuff - do we want to look at it? */
586
a68823ee
MG
587 /*
588 * Some BIOSes assume that WAK_STS will be cleared on resume and use
589 * it to determine whether the system is rebooting or resuming. Clear
590 * it for compatibility.
591 */
592 acpi_set_register(ACPI_BITREG_WAKE_STATUS, 1);
593
79d2dfaa
TR
594 acpi_gbl_system_awake_and_running = TRUE;
595
1da177e4
LT
596 /* Enable power button */
597
4be44fcd
LB
598 (void)
599 acpi_set_register(acpi_gbl_fixed_event_info
d8c71b6d 600 [ACPI_EVENT_POWER_BUTTON].enable_register_id, 1);
44f6c012 601
4be44fcd
LB
602 (void)
603 acpi_set_register(acpi_gbl_fixed_event_info
d8c71b6d 604 [ACPI_EVENT_POWER_BUTTON].status_register_id, 1);
1da177e4
LT
605
606 arg.integer.value = ACPI_SST_WORKING;
4be44fcd
LB
607 status = acpi_evaluate_object(NULL, METHOD_NAME__SST, &arg_list, NULL);
608 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
b8e4d893 609 ACPI_EXCEPTION((AE_INFO, status, "During Method _SST"));
1da177e4
LT
610 }
611
4be44fcd 612 return_ACPI_STATUS(status);
1da177e4 613}
8313524a
BM
614
615ACPI_EXPORT_SYMBOL(acpi_leave_sleep_state)