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