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/suspend.h>
18 #include <linux/reboot.h>
19 #include <linux/acpi.h>
20 #include <linux/module.h>
21 #include <linux/pm_runtime.h>
25 #include <acpi/acpi_bus.h>
26 #include <acpi/acpi_drivers.h>
28 #include <asm/realmode.h>
33 u8 wake_sleep_flags = ACPI_NO_OPTIONAL_METHODS;
34 static unsigned int gts, bfs;
35 static int set_param_wake_flag(const char *val, struct kernel_param *kp)
37 int ret = param_set_int(val, kp);
42 if (kp->arg == (const char *)>s) {
44 wake_sleep_flags |= ACPI_EXECUTE_GTS;
46 wake_sleep_flags &= ~ACPI_EXECUTE_GTS;
48 if (kp->arg == (const char *)&bfs) {
50 wake_sleep_flags |= ACPI_EXECUTE_BFS;
52 wake_sleep_flags &= ~ACPI_EXECUTE_BFS;
56 module_param_call(gts, set_param_wake_flag, param_get_int, >s, 0644);
57 module_param_call(bfs, set_param_wake_flag, param_get_int, &bfs, 0644);
58 MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
59 MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
61 static u8 sleep_states[ACPI_S_STATE_COUNT];
63 static void acpi_sleep_tts_switch(u32 acpi_state)
65 union acpi_object in_arg = { ACPI_TYPE_INTEGER };
66 struct acpi_object_list arg_list = { 1, &in_arg };
67 acpi_status status = AE_OK;
69 in_arg.integer.value = acpi_state;
70 status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
71 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
73 * OS can't evaluate the _TTS object correctly. Some warning
74 * message will be printed. But it won't break anything.
76 printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
80 static int tts_notify_reboot(struct notifier_block *this,
81 unsigned long code, void *x)
83 acpi_sleep_tts_switch(ACPI_STATE_S5);
87 static struct notifier_block tts_notifier = {
88 .notifier_call = tts_notify_reboot,
93 static int acpi_sleep_prepare(u32 acpi_state)
95 #ifdef CONFIG_ACPI_SLEEP
96 unsigned long wakeup_pa = real_mode_header->wakeup_start;
97 /* do we have a wakeup address for S2 and S3? */
98 if (acpi_state == ACPI_STATE_S3) {
101 acpi_set_firmware_waking_vector(
102 (acpi_physical_address)wakeup_pa);
105 ACPI_FLUSH_CPU_CACHE();
107 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
109 acpi_enable_wakeup_devices(acpi_state);
110 acpi_enter_sleep_state_prep(acpi_state);
114 #ifdef CONFIG_ACPI_SLEEP
115 static u32 acpi_target_sleep_state = ACPI_STATE_S0;
118 * The ACPI specification wants us to save NVS memory regions during hibernation
119 * and to restore them during the subsequent resume. Windows does that also for
120 * suspend to RAM. However, it is known that this mechanism does not work on
121 * all machines, so we allow the user to disable it with the help of the
122 * 'acpi_sleep=nonvs' kernel command line option.
124 static bool nvs_nosave;
126 void __init acpi_nvs_nosave(void)
132 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
133 * user to request that behavior by using the 'acpi_old_suspend_ordering'
134 * kernel command line option that causes the following variable to be set.
136 static bool old_suspend_ordering;
138 void __init acpi_old_suspend_ordering(void)
140 old_suspend_ordering = true;
144 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
146 static int acpi_pm_freeze(void)
148 acpi_disable_all_gpes();
149 acpi_os_wait_events_complete(NULL);
150 acpi_ec_block_transactions();
155 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
157 static int acpi_pm_pre_suspend(void)
160 return suspend_nvs_save();
164 * __acpi_pm_prepare - Prepare the platform to enter the target state.
166 * If necessary, set the firmware waking vector and do arch-specific
167 * nastiness to get the wakeup code to the waking vector.
169 static int __acpi_pm_prepare(void)
171 int error = acpi_sleep_prepare(acpi_target_sleep_state);
173 acpi_target_sleep_state = ACPI_STATE_S0;
179 * acpi_pm_prepare - Prepare the platform to enter the target sleep
180 * state and disable the GPEs.
182 static int acpi_pm_prepare(void)
184 int error = __acpi_pm_prepare();
186 error = acpi_pm_pre_suspend();
192 * acpi_pm_finish - Instruct the platform to leave a sleep state.
194 * This is called after we wake back up (or if entering the sleep state
197 static void acpi_pm_finish(void)
199 u32 acpi_state = acpi_target_sleep_state;
201 acpi_ec_unblock_transactions();
204 if (acpi_state == ACPI_STATE_S0)
207 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
209 acpi_disable_wakeup_devices(acpi_state);
210 acpi_leave_sleep_state(acpi_state);
212 /* reset firmware waking vector */
213 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
215 acpi_target_sleep_state = ACPI_STATE_S0;
219 * acpi_pm_end - Finish up suspend sequence.
221 static void acpi_pm_end(void)
224 * This is necessary in case acpi_pm_finish() is not called during a
225 * failing transition to a sleep state.
227 acpi_target_sleep_state = ACPI_STATE_S0;
228 acpi_sleep_tts_switch(acpi_target_sleep_state);
230 #else /* !CONFIG_ACPI_SLEEP */
231 #define acpi_target_sleep_state ACPI_STATE_S0
232 #endif /* CONFIG_ACPI_SLEEP */
234 #ifdef CONFIG_SUSPEND
235 static u32 acpi_suspend_states[] = {
236 [PM_SUSPEND_ON] = ACPI_STATE_S0,
237 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
238 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
239 [PM_SUSPEND_MAX] = ACPI_STATE_S5
243 * acpi_suspend_begin - Set the target system sleep state to the state
244 * associated with given @pm_state, if supported.
246 static int acpi_suspend_begin(suspend_state_t pm_state)
248 u32 acpi_state = acpi_suspend_states[pm_state];
251 error = nvs_nosave ? 0 : suspend_nvs_alloc();
255 if (sleep_states[acpi_state]) {
256 acpi_target_sleep_state = acpi_state;
257 acpi_sleep_tts_switch(acpi_target_sleep_state);
259 printk(KERN_ERR "ACPI does not support this state: %d\n",
267 * acpi_suspend_enter - Actually enter a sleep state.
270 * Flush caches and go to sleep. For STR we have to call arch-specific
271 * assembly, which in turn call acpi_enter_sleep_state().
272 * It's unfortunate, but it works. Please fix if you're feeling frisky.
274 static int acpi_suspend_enter(suspend_state_t pm_state)
276 acpi_status status = AE_OK;
277 u32 acpi_state = acpi_target_sleep_state;
280 ACPI_FLUSH_CPU_CACHE();
282 switch (acpi_state) {
285 status = acpi_enter_sleep_state(acpi_state, wake_sleep_flags);
289 error = acpi_suspend_lowlevel();
292 pr_info(PREFIX "Low-level resume complete\n");
296 /* This violates the spec but is required for bug compatibility. */
297 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
299 /* Reprogram control registers and execute _BFS */
300 acpi_leave_sleep_state_prep(acpi_state, wake_sleep_flags);
302 /* ACPI 3.0 specs (P62) says that it's the responsibility
303 * of the OSPM to clear the status bit [ implying that the
304 * POWER_BUTTON event should not reach userspace ]
306 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
307 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
310 * Disable and clear GPE status before interrupt is enabled. Some GPEs
311 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
312 * acpi_leave_sleep_state will reenable specific GPEs later
314 acpi_disable_all_gpes();
315 /* Allow EC transactions to happen. */
316 acpi_ec_unblock_transactions_early();
318 suspend_nvs_restore();
320 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
323 static int acpi_suspend_state_valid(suspend_state_t pm_state)
329 case PM_SUSPEND_STANDBY:
331 acpi_state = acpi_suspend_states[pm_state];
333 return sleep_states[acpi_state];
339 static const struct platform_suspend_ops acpi_suspend_ops = {
340 .valid = acpi_suspend_state_valid,
341 .begin = acpi_suspend_begin,
342 .prepare_late = acpi_pm_prepare,
343 .enter = acpi_suspend_enter,
344 .wake = acpi_pm_finish,
349 * acpi_suspend_begin_old - Set the target system sleep state to the
350 * state associated with given @pm_state, if supported, and
351 * execute the _PTS control method. This function is used if the
352 * pre-ACPI 2.0 suspend ordering has been requested.
354 static int acpi_suspend_begin_old(suspend_state_t pm_state)
356 int error = acpi_suspend_begin(pm_state);
358 error = __acpi_pm_prepare();
364 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
367 static const struct platform_suspend_ops acpi_suspend_ops_old = {
368 .valid = acpi_suspend_state_valid,
369 .begin = acpi_suspend_begin_old,
370 .prepare_late = acpi_pm_pre_suspend,
371 .enter = acpi_suspend_enter,
372 .wake = acpi_pm_finish,
374 .recover = acpi_pm_finish,
377 static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
379 old_suspend_ordering = true;
383 static int __init init_nvs_nosave(const struct dmi_system_id *d)
389 static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
391 .callback = init_old_suspend_ordering,
392 .ident = "Abit KN9 (nForce4 variant)",
394 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
395 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
399 .callback = init_old_suspend_ordering,
400 .ident = "HP xw4600 Workstation",
402 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
403 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
407 .callback = init_old_suspend_ordering,
408 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
410 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
411 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
415 .callback = init_old_suspend_ordering,
416 .ident = "Panasonic CF51-2L",
418 DMI_MATCH(DMI_BOARD_VENDOR,
419 "Matsushita Electric Industrial Co.,Ltd."),
420 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
424 .callback = init_nvs_nosave,
425 .ident = "Sony Vaio VGN-FW21E",
427 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
428 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
432 .callback = init_nvs_nosave,
433 .ident = "Sony Vaio VPCEB17FX",
435 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
436 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
440 .callback = init_nvs_nosave,
441 .ident = "Sony Vaio VGN-SR11M",
443 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
444 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
448 .callback = init_nvs_nosave,
449 .ident = "Everex StepNote Series",
451 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
452 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
456 .callback = init_nvs_nosave,
457 .ident = "Sony Vaio VPCEB1Z1E",
459 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
460 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
464 .callback = init_nvs_nosave,
465 .ident = "Sony Vaio VGN-NW130D",
467 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
468 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
472 .callback = init_nvs_nosave,
473 .ident = "Sony Vaio VPCCW29FX",
475 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
476 DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
480 .callback = init_nvs_nosave,
481 .ident = "Averatec AV1020-ED2",
483 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
484 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
488 .callback = init_old_suspend_ordering,
489 .ident = "Asus A8N-SLI DELUXE",
491 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
492 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
496 .callback = init_old_suspend_ordering,
497 .ident = "Asus A8N-SLI Premium",
499 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
500 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
504 .callback = init_nvs_nosave,
505 .ident = "Sony Vaio VGN-SR26GN_P",
507 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
508 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
512 .callback = init_nvs_nosave,
513 .ident = "Sony Vaio VGN-FW520F",
515 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
516 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
520 .callback = init_nvs_nosave,
521 .ident = "Asus K54C",
523 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
524 DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
528 .callback = init_nvs_nosave,
529 .ident = "Asus K54HR",
531 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
532 DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
537 #endif /* CONFIG_SUSPEND */
539 #ifdef CONFIG_HIBERNATION
540 static unsigned long s4_hardware_signature;
541 static struct acpi_table_facs *facs;
542 static bool nosigcheck;
544 void __init acpi_no_s4_hw_signature(void)
549 static int acpi_hibernation_begin(void)
553 error = nvs_nosave ? 0 : suspend_nvs_alloc();
555 acpi_target_sleep_state = ACPI_STATE_S4;
556 acpi_sleep_tts_switch(acpi_target_sleep_state);
562 static int acpi_hibernation_enter(void)
564 acpi_status status = AE_OK;
566 ACPI_FLUSH_CPU_CACHE();
568 /* This shouldn't return. If it returns, we have a problem */
569 status = acpi_enter_sleep_state(ACPI_STATE_S4, wake_sleep_flags);
570 /* Reprogram control registers and execute _BFS */
571 acpi_leave_sleep_state_prep(ACPI_STATE_S4, wake_sleep_flags);
573 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
576 static void acpi_hibernation_leave(void)
579 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
583 /* Reprogram control registers and execute _BFS */
584 acpi_leave_sleep_state_prep(ACPI_STATE_S4, wake_sleep_flags);
585 /* Check the hardware signature */
586 if (facs && s4_hardware_signature != facs->hardware_signature) {
587 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
589 panic("ACPI S4 hardware signature mismatch");
591 /* Restore the NVS memory area */
592 suspend_nvs_restore();
593 /* Allow EC transactions to happen. */
594 acpi_ec_unblock_transactions_early();
597 static void acpi_pm_thaw(void)
599 acpi_ec_unblock_transactions();
600 acpi_enable_all_runtime_gpes();
603 static const struct platform_hibernation_ops acpi_hibernation_ops = {
604 .begin = acpi_hibernation_begin,
606 .pre_snapshot = acpi_pm_prepare,
607 .finish = acpi_pm_finish,
608 .prepare = acpi_pm_prepare,
609 .enter = acpi_hibernation_enter,
610 .leave = acpi_hibernation_leave,
611 .pre_restore = acpi_pm_freeze,
612 .restore_cleanup = acpi_pm_thaw,
616 * acpi_hibernation_begin_old - Set the target system sleep state to
617 * ACPI_STATE_S4 and execute the _PTS control method. This
618 * function is used if the pre-ACPI 2.0 suspend ordering has been
621 static int acpi_hibernation_begin_old(void)
625 * The _TTS object should always be evaluated before the _PTS object.
626 * When the old_suspended_ordering is true, the _PTS object is
627 * evaluated in the acpi_sleep_prepare.
629 acpi_sleep_tts_switch(ACPI_STATE_S4);
631 error = acpi_sleep_prepare(ACPI_STATE_S4);
635 error = suspend_nvs_alloc();
637 acpi_target_sleep_state = ACPI_STATE_S4;
643 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
646 static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
647 .begin = acpi_hibernation_begin_old,
649 .pre_snapshot = acpi_pm_pre_suspend,
650 .prepare = acpi_pm_freeze,
651 .finish = acpi_pm_finish,
652 .enter = acpi_hibernation_enter,
653 .leave = acpi_hibernation_leave,
654 .pre_restore = acpi_pm_freeze,
655 .restore_cleanup = acpi_pm_thaw,
656 .recover = acpi_pm_finish,
658 #endif /* CONFIG_HIBERNATION */
660 int acpi_suspend(u32 acpi_state)
662 suspend_state_t states[] = {
663 [1] = PM_SUSPEND_STANDBY,
664 [3] = PM_SUSPEND_MEM,
668 if (acpi_state < 6 && states[acpi_state])
669 return pm_suspend(states[acpi_state]);
677 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
678 * in the system sleep state given by %acpi_target_sleep_state
679 * @dev: device to examine; its driver model wakeup flags control
680 * whether it should be able to wake up the system
681 * @d_min_p: used to store the upper limit of allowed states range
682 * Return value: preferred power state of the device on success, -ENODEV on
683 * failure (ie. if there's no 'struct acpi_device' for @dev)
685 * Find the lowest power (highest number) ACPI device power state that
686 * device @dev can be in while the system is in the sleep state represented
687 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
688 * able to wake up the system from this sleep state. If @d_min_p is set,
689 * the highest power (lowest number) device power state of @dev allowed
690 * in this system sleep state is stored at the location pointed to by it.
692 * The caller must ensure that @dev is valid before using this function.
693 * The caller is also responsible for figuring out if the device is
694 * supposed to be able to wake up the system and passing this information
698 int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
700 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
701 struct acpi_device *adev;
702 char acpi_method[] = "_SxD";
703 unsigned long long d_min, d_max;
705 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
706 printk(KERN_DEBUG "ACPI handle has no context!\n");
710 acpi_method[2] = '0' + acpi_target_sleep_state;
712 * If the sleep state is S0, we will return D3, but if the device has
713 * _S0W, we will use the value from _S0W
715 d_min = ACPI_STATE_D0;
716 d_max = ACPI_STATE_D3;
719 * If present, _SxD methods return the minimum D-state (highest power
720 * state) we can use for the corresponding S-states. Otherwise, the
721 * minimum D-state is D0 (ACPI 3.x).
723 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
724 * provided -- that's our fault recovery, we ignore retval.
726 if (acpi_target_sleep_state > ACPI_STATE_S0)
727 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
730 * If _PRW says we can wake up the system from the target sleep state,
731 * the D-state returned by _SxD is sufficient for that (we assume a
732 * wakeup-aware driver if wake is set). Still, if _SxW exists
733 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
734 * can wake the system. _S0W may be valid, too.
736 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
737 (device_may_wakeup(dev) &&
738 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
741 acpi_method[3] = 'W';
742 status = acpi_evaluate_integer(handle, acpi_method, NULL,
744 if (ACPI_FAILURE(status)) {
745 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
746 status != AE_NOT_FOUND)
748 } else if (d_max < d_min) {
749 /* Warn the user of the broken DSDT */
750 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
761 #endif /* CONFIG_PM */
763 #ifdef CONFIG_PM_SLEEP
765 * acpi_pm_device_run_wake - Enable/disable wake-up for given device.
766 * @phys_dev: Device to enable/disable the platform to wake-up the system for.
767 * @enable: Whether enable or disable the wake-up functionality.
769 * Find the ACPI device object corresponding to @pci_dev and try to
770 * enable/disable the GPE associated with it.
772 int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
774 struct acpi_device *dev;
777 if (!device_run_wake(phys_dev))
780 handle = DEVICE_ACPI_HANDLE(phys_dev);
781 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) {
782 dev_dbg(phys_dev, "ACPI handle has no context in %s!\n",
788 acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0);
789 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
791 acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
792 acpi_disable_wakeup_device_power(dev);
799 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
800 * capability of given device
801 * @dev: device to handle
802 * @enable: 'true' - enable, 'false' - disable the wake-up capability
804 int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
807 struct acpi_device *adev;
810 if (!device_can_wakeup(dev))
813 handle = DEVICE_ACPI_HANDLE(dev);
814 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
815 dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
820 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
821 acpi_disable_wakeup_device_power(adev);
823 dev_info(dev, "wake-up capability %s by ACPI\n",
824 enable ? "enabled" : "disabled");
828 #endif /* CONFIG_PM_SLEEP */
830 static void acpi_power_off_prepare(void)
832 /* Prepare to power off the system */
833 acpi_sleep_prepare(ACPI_STATE_S5);
834 acpi_disable_all_gpes();
837 static void acpi_power_off(void)
839 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
840 printk(KERN_DEBUG "%s called\n", __func__);
842 acpi_enter_sleep_state(ACPI_STATE_S5, wake_sleep_flags);
846 * ACPI 2.0 created the optional _GTS and _BFS,
847 * but industry adoption has been neither rapid nor broad.
849 * Linux gets into trouble when it executes poorly validated
850 * paths through the BIOS, so disable _GTS and _BFS by default,
851 * but do speak up and offer the option to enable them.
853 static void __init acpi_gts_bfs_check(void)
857 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__GTS, &dummy)))
859 printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
860 printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
861 "please notify linux-acpi@vger.kernel.org\n");
863 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__BFS, &dummy)))
865 printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
866 printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
867 "please notify linux-acpi@vger.kernel.org\n");
871 int __init acpi_sleep_init(void)
875 #ifdef CONFIG_SUSPEND
878 dmi_check_system(acpisleep_dmi_table);
884 sleep_states[ACPI_STATE_S0] = 1;
885 printk(KERN_INFO PREFIX "(supports S0");
887 #ifdef CONFIG_SUSPEND
888 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
889 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
890 if (ACPI_SUCCESS(status)) {
892 printk(KERN_CONT " S%d", i);
896 suspend_set_ops(old_suspend_ordering ?
897 &acpi_suspend_ops_old : &acpi_suspend_ops);
900 #ifdef CONFIG_HIBERNATION
901 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
902 if (ACPI_SUCCESS(status)) {
903 hibernation_set_ops(old_suspend_ordering ?
904 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
905 sleep_states[ACPI_STATE_S4] = 1;
906 printk(KERN_CONT " S4");
908 acpi_get_table(ACPI_SIG_FACS, 1,
909 (struct acpi_table_header **)&facs);
911 s4_hardware_signature =
912 facs->hardware_signature;
916 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
917 if (ACPI_SUCCESS(status)) {
918 sleep_states[ACPI_STATE_S5] = 1;
919 printk(KERN_CONT " S5");
920 pm_power_off_prepare = acpi_power_off_prepare;
921 pm_power_off = acpi_power_off;
923 printk(KERN_CONT ")\n");
925 * Register the tts_notifier to reboot notifier list so that the _TTS
926 * object can also be evaluated when the system enters S5.
928 register_reboot_notifier(&tts_notifier);
929 acpi_gts_bfs_check();