dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / drivers / acpi / sleep.c
blob4f07029de20960fce6183bc4a6e1d3d21eeefbe8
1 /*
2 * sleep.c - ACPI sleep support.
4 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
5 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (c) 2000-2003 Patrick Mochel
7 * Copyright (c) 2003 Open Source Development Lab
9 * This file is released under the GPLv2.
13 #include <linux/delay.h>
14 #include <linux/irq.h>
15 #include <linux/dmi.h>
16 #include <linux/device.h>
17 #include <linux/interrupt.h>
18 #include <linux/suspend.h>
19 #include <linux/reboot.h>
20 #include <linux/acpi.h>
21 #include <linux/module.h>
22 #include <asm/io.h>
23 #include <trace/events/power.h>
25 #include "internal.h"
26 #include "sleep.h"
28 static u8 sleep_states[ACPI_S_STATE_COUNT];
30 static void acpi_sleep_tts_switch(u32 acpi_state)
32 acpi_status status;
34 status = acpi_execute_simple_method(NULL, "\\_TTS", acpi_state);
35 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
37 * OS can't evaluate the _TTS object correctly. Some warning
38 * message will be printed. But it won't break anything.
40 printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
44 static int tts_notify_reboot(struct notifier_block *this,
45 unsigned long code, void *x)
47 acpi_sleep_tts_switch(ACPI_STATE_S5);
48 return NOTIFY_DONE;
51 static struct notifier_block tts_notifier = {
52 .notifier_call = tts_notify_reboot,
53 .next = NULL,
54 .priority = 0,
57 static int acpi_sleep_prepare(u32 acpi_state)
59 #ifdef CONFIG_ACPI_SLEEP
60 /* do we have a wakeup address for S2 and S3? */
61 if (acpi_state == ACPI_STATE_S3) {
62 if (!acpi_wakeup_address)
63 return -EFAULT;
64 acpi_set_firmware_waking_vector(acpi_wakeup_address);
67 ACPI_FLUSH_CPU_CACHE();
68 #endif
69 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
70 acpi_state);
71 acpi_enable_wakeup_devices(acpi_state);
72 acpi_enter_sleep_state_prep(acpi_state);
73 return 0;
76 static bool acpi_sleep_state_supported(u8 sleep_state)
78 acpi_status status;
79 u8 type_a, type_b;
81 status = acpi_get_sleep_type_data(sleep_state, &type_a, &type_b);
82 return ACPI_SUCCESS(status) && (!acpi_gbl_reduced_hardware
83 || (acpi_gbl_FADT.sleep_control.address
84 && acpi_gbl_FADT.sleep_status.address));
87 #ifdef CONFIG_ACPI_SLEEP
88 static u32 acpi_target_sleep_state = ACPI_STATE_S0;
90 u32 acpi_target_system_state(void)
92 return acpi_target_sleep_state;
94 EXPORT_SYMBOL_GPL(acpi_target_system_state);
96 static bool pwr_btn_event_pending;
99 * The ACPI specification wants us to save NVS memory regions during hibernation
100 * and to restore them during the subsequent resume. Windows does that also for
101 * suspend to RAM. However, it is known that this mechanism does not work on
102 * all machines, so we allow the user to disable it with the help of the
103 * 'acpi_sleep=nonvs' kernel command line option.
105 static bool nvs_nosave;
107 void __init acpi_nvs_nosave(void)
109 nvs_nosave = true;
113 * The ACPI specification wants us to save NVS memory regions during hibernation
114 * but says nothing about saving NVS during S3. Not all versions of Windows
115 * save NVS on S3 suspend either, and it is clear that not all systems need
116 * NVS to be saved at S3 time. To improve suspend/resume time, allow the
117 * user to disable saving NVS on S3 if their system does not require it, but
118 * continue to save/restore NVS for S4 as specified.
120 static bool nvs_nosave_s3;
122 void __init acpi_nvs_nosave_s3(void)
124 nvs_nosave_s3 = true;
127 static int __init init_nvs_save_s3(const struct dmi_system_id *d)
129 nvs_nosave_s3 = false;
130 return 0;
134 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
135 * user to request that behavior by using the 'acpi_old_suspend_ordering'
136 * kernel command line option that causes the following variable to be set.
138 static bool old_suspend_ordering;
140 void __init acpi_old_suspend_ordering(void)
142 old_suspend_ordering = true;
145 static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
147 acpi_old_suspend_ordering();
148 return 0;
151 static int __init init_nvs_nosave(const struct dmi_system_id *d)
153 acpi_nvs_nosave();
154 return 0;
157 static struct dmi_system_id acpisleep_dmi_table[] __initdata = {
159 .callback = init_old_suspend_ordering,
160 .ident = "Abit KN9 (nForce4 variant)",
161 .matches = {
162 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
163 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
167 .callback = init_old_suspend_ordering,
168 .ident = "HP xw4600 Workstation",
169 .matches = {
170 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
171 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
175 .callback = init_old_suspend_ordering,
176 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
177 .matches = {
178 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
179 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
183 .callback = init_old_suspend_ordering,
184 .ident = "Panasonic CF51-2L",
185 .matches = {
186 DMI_MATCH(DMI_BOARD_VENDOR,
187 "Matsushita Electric Industrial Co.,Ltd."),
188 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
192 .callback = init_nvs_nosave,
193 .ident = "Sony Vaio VGN-FW41E_H",
194 .matches = {
195 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
196 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW41E_H"),
200 .callback = init_nvs_nosave,
201 .ident = "Sony Vaio VGN-FW21E",
202 .matches = {
203 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
204 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
208 .callback = init_nvs_nosave,
209 .ident = "Sony Vaio VGN-FW21M",
210 .matches = {
211 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
212 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21M"),
216 .callback = init_nvs_nosave,
217 .ident = "Sony Vaio VPCEB17FX",
218 .matches = {
219 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
220 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
224 .callback = init_nvs_nosave,
225 .ident = "Sony Vaio VGN-SR11M",
226 .matches = {
227 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
228 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
232 .callback = init_nvs_nosave,
233 .ident = "Everex StepNote Series",
234 .matches = {
235 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
236 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
240 .callback = init_nvs_nosave,
241 .ident = "Sony Vaio VPCEB1Z1E",
242 .matches = {
243 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
244 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
248 .callback = init_nvs_nosave,
249 .ident = "Sony Vaio VGN-NW130D",
250 .matches = {
251 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
252 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
256 .callback = init_nvs_nosave,
257 .ident = "Sony Vaio VPCCW29FX",
258 .matches = {
259 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
260 DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
264 .callback = init_nvs_nosave,
265 .ident = "Averatec AV1020-ED2",
266 .matches = {
267 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
268 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
272 .callback = init_old_suspend_ordering,
273 .ident = "Asus A8N-SLI DELUXE",
274 .matches = {
275 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
276 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
280 .callback = init_old_suspend_ordering,
281 .ident = "Asus A8N-SLI Premium",
282 .matches = {
283 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
284 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
288 .callback = init_nvs_nosave,
289 .ident = "Sony Vaio VGN-SR26GN_P",
290 .matches = {
291 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
292 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
296 .callback = init_nvs_nosave,
297 .ident = "Sony Vaio VPCEB1S1E",
298 .matches = {
299 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
300 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1S1E"),
304 .callback = init_nvs_nosave,
305 .ident = "Sony Vaio VGN-FW520F",
306 .matches = {
307 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
308 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
312 .callback = init_nvs_nosave,
313 .ident = "Asus K54C",
314 .matches = {
315 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
316 DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
320 .callback = init_nvs_nosave,
321 .ident = "Asus K54HR",
322 .matches = {
323 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
324 DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
328 .callback = init_nvs_save_s3,
329 .ident = "Asus 1025C",
330 .matches = {
331 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
332 DMI_MATCH(DMI_PRODUCT_NAME, "1025C"),
336 * https://bugzilla.kernel.org/show_bug.cgi?id=189431
337 * Lenovo G50-45 is a platform later than 2012, but needs nvs memory
338 * saving during S3.
341 .callback = init_nvs_save_s3,
342 .ident = "Lenovo G50-45",
343 .matches = {
344 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
345 DMI_MATCH(DMI_PRODUCT_NAME, "80E3"),
351 static void __init acpi_sleep_dmi_check(void)
353 int year;
355 if (dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL) && year >= 2012)
356 acpi_nvs_nosave_s3();
358 dmi_check_system(acpisleep_dmi_table);
362 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
364 static int acpi_pm_freeze(void)
366 acpi_disable_all_gpes();
367 acpi_os_wait_events_complete();
368 acpi_ec_block_transactions();
369 return 0;
373 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
375 static int acpi_pm_pre_suspend(void)
377 acpi_pm_freeze();
378 return suspend_nvs_save();
382 * __acpi_pm_prepare - Prepare the platform to enter the target state.
384 * If necessary, set the firmware waking vector and do arch-specific
385 * nastiness to get the wakeup code to the waking vector.
387 static int __acpi_pm_prepare(void)
389 int error = acpi_sleep_prepare(acpi_target_sleep_state);
390 if (error)
391 acpi_target_sleep_state = ACPI_STATE_S0;
393 return error;
397 * acpi_pm_prepare - Prepare the platform to enter the target sleep
398 * state and disable the GPEs.
400 static int acpi_pm_prepare(void)
402 int error = __acpi_pm_prepare();
403 if (!error)
404 error = acpi_pm_pre_suspend();
406 return error;
409 static int find_powerf_dev(struct device *dev, void *data)
411 struct acpi_device *device = to_acpi_device(dev);
412 const char *hid = acpi_device_hid(device);
414 return !strcmp(hid, ACPI_BUTTON_HID_POWERF);
418 * acpi_pm_finish - Instruct the platform to leave a sleep state.
420 * This is called after we wake back up (or if entering the sleep state
421 * failed).
423 static void acpi_pm_finish(void)
425 struct device *pwr_btn_dev;
426 u32 acpi_state = acpi_target_sleep_state;
428 acpi_ec_unblock_transactions();
429 suspend_nvs_free();
431 if (acpi_state == ACPI_STATE_S0)
432 return;
434 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
435 acpi_state);
436 acpi_disable_wakeup_devices(acpi_state);
437 acpi_leave_sleep_state(acpi_state);
439 /* reset firmware waking vector */
440 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
442 acpi_target_sleep_state = ACPI_STATE_S0;
444 acpi_resume_power_resources();
446 /* If we were woken with the fixed power button, provide a small
447 * hint to userspace in the form of a wakeup event on the fixed power
448 * button device (if it can be found).
450 * We delay the event generation til now, as the PM layer requires
451 * timekeeping to be running before we generate events. */
452 if (!pwr_btn_event_pending)
453 return;
455 pwr_btn_event_pending = false;
456 pwr_btn_dev = bus_find_device(&acpi_bus_type, NULL, NULL,
457 find_powerf_dev);
458 if (pwr_btn_dev) {
459 pm_wakeup_event(pwr_btn_dev, 0);
460 put_device(pwr_btn_dev);
465 * acpi_pm_start - Start system PM transition.
467 static void acpi_pm_start(u32 acpi_state)
469 acpi_target_sleep_state = acpi_state;
470 acpi_sleep_tts_switch(acpi_target_sleep_state);
471 acpi_scan_lock_acquire();
475 * acpi_pm_end - Finish up system PM transition.
477 static void acpi_pm_end(void)
479 acpi_scan_lock_release();
481 * This is necessary in case acpi_pm_finish() is not called during a
482 * failing transition to a sleep state.
484 acpi_target_sleep_state = ACPI_STATE_S0;
485 acpi_sleep_tts_switch(acpi_target_sleep_state);
487 #else /* !CONFIG_ACPI_SLEEP */
488 #define acpi_target_sleep_state ACPI_STATE_S0
489 static inline void acpi_sleep_dmi_check(void) {}
490 #endif /* CONFIG_ACPI_SLEEP */
492 #ifdef CONFIG_SUSPEND
493 static u32 acpi_suspend_states[] = {
494 [PM_SUSPEND_ON] = ACPI_STATE_S0,
495 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
496 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
497 [PM_SUSPEND_MAX] = ACPI_STATE_S5
501 * acpi_suspend_begin - Set the target system sleep state to the state
502 * associated with given @pm_state, if supported.
504 static int acpi_suspend_begin(suspend_state_t pm_state)
506 u32 acpi_state = acpi_suspend_states[pm_state];
507 int error;
509 error = (nvs_nosave || nvs_nosave_s3) ? 0 : suspend_nvs_alloc();
510 if (error)
511 return error;
513 if (!sleep_states[acpi_state]) {
514 pr_err("ACPI does not support sleep state S%u\n", acpi_state);
515 return -ENOSYS;
517 if (acpi_state > ACPI_STATE_S1)
518 pm_set_suspend_via_firmware();
520 acpi_pm_start(acpi_state);
521 return 0;
525 * acpi_suspend_enter - Actually enter a sleep state.
526 * @pm_state: ignored
528 * Flush caches and go to sleep. For STR we have to call arch-specific
529 * assembly, which in turn call acpi_enter_sleep_state().
530 * It's unfortunate, but it works. Please fix if you're feeling frisky.
532 static int acpi_suspend_enter(suspend_state_t pm_state)
534 acpi_status status = AE_OK;
535 u32 acpi_state = acpi_target_sleep_state;
536 int error;
538 ACPI_FLUSH_CPU_CACHE();
540 trace_suspend_resume(TPS("acpi_suspend"), acpi_state, true);
541 switch (acpi_state) {
542 case ACPI_STATE_S1:
543 barrier();
544 status = acpi_enter_sleep_state(acpi_state);
545 break;
547 case ACPI_STATE_S3:
548 if (!acpi_suspend_lowlevel)
549 return -ENOSYS;
550 error = acpi_suspend_lowlevel();
551 if (error)
552 return error;
553 pr_info(PREFIX "Low-level resume complete\n");
554 pm_set_resume_via_firmware();
555 break;
557 trace_suspend_resume(TPS("acpi_suspend"), acpi_state, false);
559 /* This violates the spec but is required for bug compatibility. */
560 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
562 /* Reprogram control registers */
563 acpi_leave_sleep_state_prep(acpi_state);
565 /* ACPI 3.0 specs (P62) says that it's the responsibility
566 * of the OSPM to clear the status bit [ implying that the
567 * POWER_BUTTON event should not reach userspace ]
569 * However, we do generate a small hint for userspace in the form of
570 * a wakeup event. We flag this condition for now and generate the
571 * event later, as we're currently too early in resume to be able to
572 * generate wakeup events.
574 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) {
575 acpi_event_status pwr_btn_status = ACPI_EVENT_FLAG_DISABLED;
577 acpi_get_event_status(ACPI_EVENT_POWER_BUTTON, &pwr_btn_status);
579 if (pwr_btn_status & ACPI_EVENT_FLAG_SET) {
580 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
581 /* Flag for later */
582 pwr_btn_event_pending = true;
587 * Disable and clear GPE status before interrupt is enabled. Some GPEs
588 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
589 * acpi_leave_sleep_state will reenable specific GPEs later
591 acpi_disable_all_gpes();
592 /* Allow EC transactions to happen. */
593 acpi_ec_unblock_transactions_early();
595 suspend_nvs_restore();
597 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
600 static int acpi_suspend_state_valid(suspend_state_t pm_state)
602 u32 acpi_state;
604 switch (pm_state) {
605 case PM_SUSPEND_ON:
606 case PM_SUSPEND_STANDBY:
607 case PM_SUSPEND_MEM:
608 acpi_state = acpi_suspend_states[pm_state];
610 return sleep_states[acpi_state];
611 default:
612 return 0;
616 static const struct platform_suspend_ops acpi_suspend_ops = {
617 .valid = acpi_suspend_state_valid,
618 .begin = acpi_suspend_begin,
619 .prepare_late = acpi_pm_prepare,
620 .enter = acpi_suspend_enter,
621 .wake = acpi_pm_finish,
622 .end = acpi_pm_end,
626 * acpi_suspend_begin_old - Set the target system sleep state to the
627 * state associated with given @pm_state, if supported, and
628 * execute the _PTS control method. This function is used if the
629 * pre-ACPI 2.0 suspend ordering has been requested.
631 static int acpi_suspend_begin_old(suspend_state_t pm_state)
633 int error = acpi_suspend_begin(pm_state);
634 if (!error)
635 error = __acpi_pm_prepare();
637 return error;
641 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
642 * been requested.
644 static const struct platform_suspend_ops acpi_suspend_ops_old = {
645 .valid = acpi_suspend_state_valid,
646 .begin = acpi_suspend_begin_old,
647 .prepare_late = acpi_pm_pre_suspend,
648 .enter = acpi_suspend_enter,
649 .wake = acpi_pm_finish,
650 .end = acpi_pm_end,
651 .recover = acpi_pm_finish,
654 static int acpi_freeze_begin(void)
656 acpi_scan_lock_acquire();
657 return 0;
660 static int acpi_freeze_prepare(void)
662 acpi_enable_wakeup_devices(ACPI_STATE_S0);
663 acpi_enable_all_wakeup_gpes();
664 acpi_os_wait_events_complete();
665 if (acpi_sci_irq_valid())
666 enable_irq_wake(acpi_sci_irq);
667 return 0;
670 static void acpi_freeze_restore(void)
672 acpi_disable_wakeup_devices(ACPI_STATE_S0);
673 if (acpi_sci_irq_valid())
674 disable_irq_wake(acpi_sci_irq);
675 acpi_enable_all_runtime_gpes();
678 static void acpi_freeze_end(void)
680 acpi_scan_lock_release();
683 static const struct platform_freeze_ops acpi_freeze_ops = {
684 .begin = acpi_freeze_begin,
685 .prepare = acpi_freeze_prepare,
686 .restore = acpi_freeze_restore,
687 .end = acpi_freeze_end,
690 static void acpi_sleep_suspend_setup(void)
692 int i;
694 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++)
695 if (acpi_sleep_state_supported(i))
696 sleep_states[i] = 1;
698 suspend_set_ops(old_suspend_ordering ?
699 &acpi_suspend_ops_old : &acpi_suspend_ops);
700 freeze_set_ops(&acpi_freeze_ops);
703 #else /* !CONFIG_SUSPEND */
704 static inline void acpi_sleep_suspend_setup(void) {}
705 #endif /* !CONFIG_SUSPEND */
707 #ifdef CONFIG_HIBERNATION
708 static unsigned long s4_hardware_signature;
709 static struct acpi_table_facs *facs;
710 static bool nosigcheck;
712 void __init acpi_no_s4_hw_signature(void)
714 nosigcheck = true;
717 static int acpi_hibernation_begin(void)
719 int error;
721 error = nvs_nosave ? 0 : suspend_nvs_alloc();
722 if (!error)
723 acpi_pm_start(ACPI_STATE_S4);
725 return error;
728 static int acpi_hibernation_enter(void)
730 acpi_status status = AE_OK;
732 ACPI_FLUSH_CPU_CACHE();
734 /* This shouldn't return. If it returns, we have a problem */
735 status = acpi_enter_sleep_state(ACPI_STATE_S4);
736 /* Reprogram control registers */
737 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
739 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
742 static void acpi_hibernation_leave(void)
744 pm_set_resume_via_firmware();
746 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
747 * enable it here.
749 acpi_enable();
750 /* Reprogram control registers */
751 acpi_leave_sleep_state_prep(ACPI_STATE_S4);
752 /* Check the hardware signature */
753 if (facs && s4_hardware_signature != facs->hardware_signature)
754 pr_crit("ACPI: Hardware changed while hibernated, success doubtful!\n");
755 /* Restore the NVS memory area */
756 suspend_nvs_restore();
757 /* Allow EC transactions to happen. */
758 acpi_ec_unblock_transactions_early();
761 static void acpi_pm_thaw(void)
763 acpi_ec_unblock_transactions();
764 acpi_enable_all_runtime_gpes();
767 static const struct platform_hibernation_ops acpi_hibernation_ops = {
768 .begin = acpi_hibernation_begin,
769 .end = acpi_pm_end,
770 .pre_snapshot = acpi_pm_prepare,
771 .finish = acpi_pm_finish,
772 .prepare = acpi_pm_prepare,
773 .enter = acpi_hibernation_enter,
774 .leave = acpi_hibernation_leave,
775 .pre_restore = acpi_pm_freeze,
776 .restore_cleanup = acpi_pm_thaw,
780 * acpi_hibernation_begin_old - Set the target system sleep state to
781 * ACPI_STATE_S4 and execute the _PTS control method. This
782 * function is used if the pre-ACPI 2.0 suspend ordering has been
783 * requested.
785 static int acpi_hibernation_begin_old(void)
787 int error;
789 * The _TTS object should always be evaluated before the _PTS object.
790 * When the old_suspended_ordering is true, the _PTS object is
791 * evaluated in the acpi_sleep_prepare.
793 acpi_sleep_tts_switch(ACPI_STATE_S4);
795 error = acpi_sleep_prepare(ACPI_STATE_S4);
797 if (!error) {
798 if (!nvs_nosave)
799 error = suspend_nvs_alloc();
800 if (!error) {
801 acpi_target_sleep_state = ACPI_STATE_S4;
802 acpi_scan_lock_acquire();
805 return error;
809 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
810 * been requested.
812 static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
813 .begin = acpi_hibernation_begin_old,
814 .end = acpi_pm_end,
815 .pre_snapshot = acpi_pm_pre_suspend,
816 .prepare = acpi_pm_freeze,
817 .finish = acpi_pm_finish,
818 .enter = acpi_hibernation_enter,
819 .leave = acpi_hibernation_leave,
820 .pre_restore = acpi_pm_freeze,
821 .restore_cleanup = acpi_pm_thaw,
822 .recover = acpi_pm_finish,
825 static void acpi_sleep_hibernate_setup(void)
827 if (!acpi_sleep_state_supported(ACPI_STATE_S4))
828 return;
830 hibernation_set_ops(old_suspend_ordering ?
831 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
832 sleep_states[ACPI_STATE_S4] = 1;
833 if (nosigcheck)
834 return;
836 acpi_get_table(ACPI_SIG_FACS, 1, (struct acpi_table_header **)&facs);
837 if (facs)
838 s4_hardware_signature = facs->hardware_signature;
840 #else /* !CONFIG_HIBERNATION */
841 static inline void acpi_sleep_hibernate_setup(void) {}
842 #endif /* !CONFIG_HIBERNATION */
844 static void acpi_power_off_prepare(void)
846 /* Prepare to power off the system */
847 acpi_sleep_prepare(ACPI_STATE_S5);
848 acpi_disable_all_gpes();
849 acpi_os_wait_events_complete();
852 static void acpi_power_off(void)
854 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
855 printk(KERN_DEBUG "%s called\n", __func__);
856 local_irq_disable();
857 acpi_enter_sleep_state(ACPI_STATE_S5);
860 int __init acpi_sleep_init(void)
862 char supported[ACPI_S_STATE_COUNT * 3 + 1];
863 char *pos = supported;
864 int i;
866 acpi_sleep_dmi_check();
868 sleep_states[ACPI_STATE_S0] = 1;
870 acpi_sleep_suspend_setup();
871 acpi_sleep_hibernate_setup();
873 if (acpi_sleep_state_supported(ACPI_STATE_S5)) {
874 sleep_states[ACPI_STATE_S5] = 1;
875 pm_power_off_prepare = acpi_power_off_prepare;
876 pm_power_off = acpi_power_off;
879 supported[0] = 0;
880 for (i = 0; i < ACPI_S_STATE_COUNT; i++) {
881 if (sleep_states[i])
882 pos += sprintf(pos, " S%d", i);
884 pr_info(PREFIX "(supports%s)\n", supported);
887 * Register the tts_notifier to reboot notifier list so that the _TTS
888 * object can also be evaluated when the system enters S5.
890 register_reboot_notifier(&tts_notifier);
891 return 0;