aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/sleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/sleep.c')
-rw-r--r--drivers/acpi/sleep.c95
1 files changed, 38 insertions, 57 deletions
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index aaa1af55e280..cf82989ae756 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -70,10 +70,10 @@ static int acpi_sleep_prepare(u32 acpi_state)
70 70
71 } 71 }
72 ACPI_FLUSH_CPU_CACHE(); 72 ACPI_FLUSH_CPU_CACHE();
73 acpi_enable_wakeup_device_prep(acpi_state);
74#endif 73#endif
75 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n", 74 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
76 acpi_state); 75 acpi_state);
76 acpi_enable_wakeup_devices(acpi_state);
77 acpi_enter_sleep_state_prep(acpi_state); 77 acpi_enter_sleep_state_prep(acpi_state);
78 return 0; 78 return 0;
79} 79}
@@ -82,6 +82,20 @@ static int acpi_sleep_prepare(u32 acpi_state)
82static u32 acpi_target_sleep_state = ACPI_STATE_S0; 82static u32 acpi_target_sleep_state = ACPI_STATE_S0;
83 83
84/* 84/*
85 * The ACPI specification wants us to save NVS memory regions during hibernation
86 * and to restore them during the subsequent resume. Windows does that also for
87 * suspend to RAM. However, it is known that this mechanism does not work on
88 * all machines, so we allow the user to disable it with the help of the
89 * 'acpi_sleep=nonvs' kernel command line option.
90 */
91static bool nvs_nosave;
92
93void __init acpi_nvs_nosave(void)
94{
95 nvs_nosave = true;
96}
97
98/*
85 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the 99 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
86 * user to request that behavior by using the 'acpi_old_suspend_ordering' 100 * user to request that behavior by using the 'acpi_old_suspend_ordering'
87 * kernel command line option that causes the following variable to be set. 101 * kernel command line option that causes the following variable to be set.
@@ -105,6 +119,16 @@ static int acpi_pm_freeze(void)
105} 119}
106 120
107/** 121/**
122 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
123 */
124static int acpi_pm_pre_suspend(void)
125{
126 acpi_pm_freeze();
127 suspend_nvs_save();
128 return 0;
129}
130
131/**
108 * __acpi_pm_prepare - Prepare the platform to enter the target state. 132 * __acpi_pm_prepare - Prepare the platform to enter the target state.
109 * 133 *
110 * If necessary, set the firmware waking vector and do arch-specific 134 * If necessary, set the firmware waking vector and do arch-specific
@@ -113,11 +137,9 @@ static int acpi_pm_freeze(void)
113static int __acpi_pm_prepare(void) 137static int __acpi_pm_prepare(void)
114{ 138{
115 int error = acpi_sleep_prepare(acpi_target_sleep_state); 139 int error = acpi_sleep_prepare(acpi_target_sleep_state);
116
117 suspend_nvs_save();
118
119 if (error) 140 if (error)
120 acpi_target_sleep_state = ACPI_STATE_S0; 141 acpi_target_sleep_state = ACPI_STATE_S0;
142
121 return error; 143 return error;
122} 144}
123 145
@@ -128,9 +150,8 @@ static int __acpi_pm_prepare(void)
128static int acpi_pm_prepare(void) 150static int acpi_pm_prepare(void)
129{ 151{
130 int error = __acpi_pm_prepare(); 152 int error = __acpi_pm_prepare();
131
132 if (!error) 153 if (!error)
133 acpi_pm_freeze(); 154 acpi_pm_pre_suspend();
134 155
135 return error; 156 return error;
136} 157}
@@ -145,7 +166,6 @@ static void acpi_pm_finish(void)
145{ 166{
146 u32 acpi_state = acpi_target_sleep_state; 167 u32 acpi_state = acpi_target_sleep_state;
147 168
148 suspend_nvs_free();
149 acpi_ec_unblock_transactions(); 169 acpi_ec_unblock_transactions();
150 170
151 if (acpi_state == ACPI_STATE_S0) 171 if (acpi_state == ACPI_STATE_S0)
@@ -153,7 +173,7 @@ static void acpi_pm_finish(void)
153 173
154 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", 174 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
155 acpi_state); 175 acpi_state);
156 acpi_disable_wakeup_device(acpi_state); 176 acpi_disable_wakeup_devices(acpi_state);
157 acpi_leave_sleep_state(acpi_state); 177 acpi_leave_sleep_state(acpi_state);
158 178
159 /* reset firmware waking vector */ 179 /* reset firmware waking vector */
@@ -167,6 +187,7 @@ static void acpi_pm_finish(void)
167 */ 187 */
168static void acpi_pm_end(void) 188static void acpi_pm_end(void)
169{ 189{
190 suspend_nvs_free();
170 /* 191 /*
171 * This is necessary in case acpi_pm_finish() is not called during a 192 * This is necessary in case acpi_pm_finish() is not called during a
172 * failing transition to a sleep state. 193 * failing transition to a sleep state.
@@ -197,8 +218,7 @@ static int acpi_suspend_begin(suspend_state_t pm_state)
197 u32 acpi_state = acpi_suspend_states[pm_state]; 218 u32 acpi_state = acpi_suspend_states[pm_state];
198 int error = 0; 219 int error = 0;
199 220
200 error = suspend_nvs_alloc(); 221 error = nvs_nosave ? 0 : suspend_nvs_alloc();
201
202 if (error) 222 if (error)
203 return error; 223 return error;
204 224
@@ -238,7 +258,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
238 } 258 }
239 259
240 local_irq_save(flags); 260 local_irq_save(flags);
241 acpi_enable_wakeup_device(acpi_state);
242 switch (acpi_state) { 261 switch (acpi_state) {
243 case ACPI_STATE_S1: 262 case ACPI_STATE_S1:
244 barrier(); 263 barrier();
@@ -284,11 +303,6 @@ static int acpi_suspend_enter(suspend_state_t pm_state)
284 return ACPI_SUCCESS(status) ? 0 : -EFAULT; 303 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
285} 304}
286 305
287static void acpi_suspend_finish(void)
288{
289 acpi_pm_finish();
290}
291
292static int acpi_suspend_state_valid(suspend_state_t pm_state) 306static int acpi_suspend_state_valid(suspend_state_t pm_state)
293{ 307{
294 u32 acpi_state; 308 u32 acpi_state;
@@ -310,7 +324,7 @@ static struct platform_suspend_ops acpi_suspend_ops = {
310 .begin = acpi_suspend_begin, 324 .begin = acpi_suspend_begin,
311 .prepare_late = acpi_pm_prepare, 325 .prepare_late = acpi_pm_prepare,
312 .enter = acpi_suspend_enter, 326 .enter = acpi_suspend_enter,
313 .wake = acpi_suspend_finish, 327 .wake = acpi_pm_finish,
314 .end = acpi_pm_end, 328 .end = acpi_pm_end,
315}; 329};
316 330
@@ -323,9 +337,9 @@ static struct platform_suspend_ops acpi_suspend_ops = {
323static int acpi_suspend_begin_old(suspend_state_t pm_state) 337static int acpi_suspend_begin_old(suspend_state_t pm_state)
324{ 338{
325 int error = acpi_suspend_begin(pm_state); 339 int error = acpi_suspend_begin(pm_state);
326
327 if (!error) 340 if (!error)
328 error = __acpi_pm_prepare(); 341 error = __acpi_pm_prepare();
342
329 return error; 343 return error;
330} 344}
331 345
@@ -336,9 +350,9 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state)
336static struct platform_suspend_ops acpi_suspend_ops_old = { 350static struct platform_suspend_ops acpi_suspend_ops_old = {
337 .valid = acpi_suspend_state_valid, 351 .valid = acpi_suspend_state_valid,
338 .begin = acpi_suspend_begin_old, 352 .begin = acpi_suspend_begin_old,
339 .prepare_late = acpi_pm_freeze, 353 .prepare_late = acpi_pm_pre_suspend,
340 .enter = acpi_suspend_enter, 354 .enter = acpi_suspend_enter,
341 .wake = acpi_suspend_finish, 355 .wake = acpi_pm_finish,
342 .end = acpi_pm_end, 356 .end = acpi_pm_end,
343 .recover = acpi_pm_finish, 357 .recover = acpi_pm_finish,
344}; 358};
@@ -388,20 +402,6 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
388#endif /* CONFIG_SUSPEND */ 402#endif /* CONFIG_SUSPEND */
389 403
390#ifdef CONFIG_HIBERNATION 404#ifdef CONFIG_HIBERNATION
391/*
392 * The ACPI specification wants us to save NVS memory regions during hibernation
393 * and to restore them during the subsequent resume. However, it is not certain
394 * if this mechanism is going to work on all machines, so we allow the user to
395 * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
396 * option.
397 */
398static bool s4_no_nvs;
399
400void __init acpi_s4_no_nvs(void)
401{
402 s4_no_nvs = true;
403}
404
405static unsigned long s4_hardware_signature; 405static unsigned long s4_hardware_signature;
406static struct acpi_table_facs *facs; 406static struct acpi_table_facs *facs;
407static bool nosigcheck; 407static bool nosigcheck;
@@ -415,7 +415,7 @@ static int acpi_hibernation_begin(void)
415{ 415{
416 int error; 416 int error;
417 417
418 error = s4_no_nvs ? 0 : suspend_nvs_alloc(); 418 error = nvs_nosave ? 0 : suspend_nvs_alloc();
419 if (!error) { 419 if (!error) {
420 acpi_target_sleep_state = ACPI_STATE_S4; 420 acpi_target_sleep_state = ACPI_STATE_S4;
421 acpi_sleep_tts_switch(acpi_target_sleep_state); 421 acpi_sleep_tts_switch(acpi_target_sleep_state);
@@ -424,16 +424,6 @@ static int acpi_hibernation_begin(void)
424 return error; 424 return error;
425} 425}
426 426
427static int acpi_hibernation_pre_snapshot(void)
428{
429 int error = acpi_pm_prepare();
430
431 if (!error)
432 suspend_nvs_save();
433
434 return error;
435}
436
437static int acpi_hibernation_enter(void) 427static int acpi_hibernation_enter(void)
438{ 428{
439 acpi_status status = AE_OK; 429 acpi_status status = AE_OK;
@@ -442,7 +432,6 @@ static int acpi_hibernation_enter(void)
442 ACPI_FLUSH_CPU_CACHE(); 432 ACPI_FLUSH_CPU_CACHE();
443 433
444 local_irq_save(flags); 434 local_irq_save(flags);
445 acpi_enable_wakeup_device(ACPI_STATE_S4);
446 /* This shouldn't return. If it returns, we have a problem */ 435 /* This shouldn't return. If it returns, we have a problem */
447 status = acpi_enter_sleep_state(ACPI_STATE_S4); 436 status = acpi_enter_sleep_state(ACPI_STATE_S4);
448 /* Reprogram control registers and execute _BFS */ 437 /* Reprogram control registers and execute _BFS */
@@ -482,7 +471,7 @@ static void acpi_pm_thaw(void)
482static struct platform_hibernation_ops acpi_hibernation_ops = { 471static struct platform_hibernation_ops acpi_hibernation_ops = {
483 .begin = acpi_hibernation_begin, 472 .begin = acpi_hibernation_begin,
484 .end = acpi_pm_end, 473 .end = acpi_pm_end,
485 .pre_snapshot = acpi_hibernation_pre_snapshot, 474 .pre_snapshot = acpi_pm_prepare,
486 .finish = acpi_pm_finish, 475 .finish = acpi_pm_finish,
487 .prepare = acpi_pm_prepare, 476 .prepare = acpi_pm_prepare,
488 .enter = acpi_hibernation_enter, 477 .enter = acpi_hibernation_enter,
@@ -510,7 +499,7 @@ static int acpi_hibernation_begin_old(void)
510 error = acpi_sleep_prepare(ACPI_STATE_S4); 499 error = acpi_sleep_prepare(ACPI_STATE_S4);
511 500
512 if (!error) { 501 if (!error) {
513 if (!s4_no_nvs) 502 if (!nvs_nosave)
514 error = suspend_nvs_alloc(); 503 error = suspend_nvs_alloc();
515 if (!error) 504 if (!error)
516 acpi_target_sleep_state = ACPI_STATE_S4; 505 acpi_target_sleep_state = ACPI_STATE_S4;
@@ -518,13 +507,6 @@ static int acpi_hibernation_begin_old(void)
518 return error; 507 return error;
519} 508}
520 509
521static int acpi_hibernation_pre_snapshot_old(void)
522{
523 acpi_pm_freeze();
524 suspend_nvs_save();
525 return 0;
526}
527
528/* 510/*
529 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has 511 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
530 * been requested. 512 * been requested.
@@ -532,7 +514,7 @@ static int acpi_hibernation_pre_snapshot_old(void)
532static struct platform_hibernation_ops acpi_hibernation_ops_old = { 514static struct platform_hibernation_ops acpi_hibernation_ops_old = {
533 .begin = acpi_hibernation_begin_old, 515 .begin = acpi_hibernation_begin_old,
534 .end = acpi_pm_end, 516 .end = acpi_pm_end,
535 .pre_snapshot = acpi_hibernation_pre_snapshot_old, 517 .pre_snapshot = acpi_pm_pre_suspend,
536 .prepare = acpi_pm_freeze, 518 .prepare = acpi_pm_freeze,
537 .finish = acpi_pm_finish, 519 .finish = acpi_pm_finish,
538 .enter = acpi_hibernation_enter, 520 .enter = acpi_hibernation_enter,
@@ -687,7 +669,6 @@ static void acpi_power_off(void)
687 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ 669 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
688 printk(KERN_DEBUG "%s called\n", __func__); 670 printk(KERN_DEBUG "%s called\n", __func__);
689 local_irq_disable(); 671 local_irq_disable();
690 acpi_enable_wakeup_device(ACPI_STATE_S5);
691 acpi_enter_sleep_state(ACPI_STATE_S5); 672 acpi_enter_sleep_state(ACPI_STATE_S5);
692} 673}
693 674