| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * sleep.c - ACPI sleep support. | 
 | 3 |  * | 
| Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 4 |  * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
 | 8 |  * | 
 | 9 |  * This file is released under the GPLv2. | 
 | 10 |  * | 
 | 11 |  */ | 
 | 12 |  | 
 | 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> | 
| Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 18 | #include <linux/reboot.h> | 
| H. Peter Anvin | d1ee433 | 2011-02-14 15:42:46 -0800 | [diff] [blame] | 19 | #include <linux/acpi.h> | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 20 | #include <linux/module.h> | 
| Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 22 |  | 
 | 23 | #include <asm/io.h> | 
 | 24 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <acpi/acpi_bus.h> | 
 | 26 | #include <acpi/acpi_drivers.h> | 
| Bjorn Helgaas | e60cc7a | 2009-03-13 12:08:26 -0600 | [diff] [blame] | 27 |  | 
 | 28 | #include "internal.h" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "sleep.h" | 
 | 30 |  | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 31 | static unsigned int gts, bfs; | 
 | 32 | module_param(gts, uint, 0644); | 
 | 33 | module_param(bfs, uint, 0644); | 
 | 34 | MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend."); | 
 | 35 | MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".); | 
 | 36 |  | 
 | 37 | static u8 wake_sleep_flags(void) | 
 | 38 | { | 
 | 39 | 	u8 flags = ACPI_NO_OPTIONAL_METHODS; | 
 | 40 |  | 
 | 41 | 	if (gts) | 
 | 42 | 		flags |= ACPI_EXECUTE_GTS; | 
 | 43 | 	if (bfs) | 
 | 44 | 		flags |= ACPI_EXECUTE_BFS; | 
 | 45 |  | 
 | 46 | 	return flags; | 
 | 47 | } | 
 | 48 |  | 
| Stephen Hemminger | 01eac60 | 2010-10-18 18:47:25 -0700 | [diff] [blame] | 49 | static u8 sleep_states[ACPI_S_STATE_COUNT]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 |  | 
| Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 51 | static void acpi_sleep_tts_switch(u32 acpi_state) | 
 | 52 | { | 
 | 53 | 	union acpi_object in_arg = { ACPI_TYPE_INTEGER }; | 
 | 54 | 	struct acpi_object_list arg_list = { 1, &in_arg }; | 
 | 55 | 	acpi_status status = AE_OK; | 
 | 56 |  | 
 | 57 | 	in_arg.integer.value = acpi_state; | 
 | 58 | 	status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL); | 
 | 59 | 	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | 
 | 60 | 		/* | 
 | 61 | 		 * OS can't evaluate the _TTS object correctly. Some warning | 
 | 62 | 		 * message will be printed. But it won't break anything. | 
 | 63 | 		 */ | 
 | 64 | 		printk(KERN_NOTICE "Failure in evaluating _TTS object\n"); | 
 | 65 | 	} | 
 | 66 | } | 
 | 67 |  | 
 | 68 | static int tts_notify_reboot(struct notifier_block *this, | 
 | 69 | 			unsigned long code, void *x) | 
 | 70 | { | 
 | 71 | 	acpi_sleep_tts_switch(ACPI_STATE_S5); | 
 | 72 | 	return NOTIFY_DONE; | 
 | 73 | } | 
 | 74 |  | 
 | 75 | static struct notifier_block tts_notifier = { | 
 | 76 | 	.notifier_call	= tts_notify_reboot, | 
 | 77 | 	.next		= NULL, | 
 | 78 | 	.priority	= 0, | 
 | 79 | }; | 
 | 80 |  | 
| Rafael J. Wysocki | c9b6c8f | 2008-01-08 00:10:57 +0100 | [diff] [blame] | 81 | static int acpi_sleep_prepare(u32 acpi_state) | 
| Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 82 | { | 
 | 83 | #ifdef CONFIG_ACPI_SLEEP | 
 | 84 | 	/* do we have a wakeup address for S2 and S3? */ | 
 | 85 | 	if (acpi_state == ACPI_STATE_S3) { | 
 | 86 | 		if (!acpi_wakeup_address) { | 
 | 87 | 			return -EFAULT; | 
 | 88 | 		} | 
| H. Peter Anvin | 4b4f728 | 2008-06-24 23:03:48 +0200 | [diff] [blame] | 89 | 		acpi_set_firmware_waking_vector( | 
 | 90 | 				(acpi_physical_address)acpi_wakeup_address); | 
| Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 91 |  | 
 | 92 | 	} | 
 | 93 | 	ACPI_FLUSH_CPU_CACHE(); | 
| Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 94 | #endif | 
| Rafael J. Wysocki | c9b6c8f | 2008-01-08 00:10:57 +0100 | [diff] [blame] | 95 | 	printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n", | 
 | 96 | 		acpi_state); | 
| Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 97 | 	acpi_enable_wakeup_devices(acpi_state); | 
| Alexey Starikovskiy | 2f3f2226 | 2007-09-24 14:33:21 +0200 | [diff] [blame] | 98 | 	acpi_enter_sleep_state_prep(acpi_state); | 
 | 99 | 	return 0; | 
 | 100 | } | 
 | 101 |  | 
| Rafael J. Wysocki | 5d1e072 | 2008-10-22 14:58:43 -0400 | [diff] [blame] | 102 | #ifdef CONFIG_ACPI_SLEEP | 
| Jan Beulich | 091aad6 | 2010-12-07 14:52:25 +0000 | [diff] [blame] | 103 | static u32 acpi_target_sleep_state = ACPI_STATE_S0; | 
 | 104 |  | 
| Zhang Rui | d7f0eea | 2009-12-30 15:36:42 +0800 | [diff] [blame] | 105 | /* | 
| Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 106 |  * The ACPI specification wants us to save NVS memory regions during hibernation | 
 | 107 |  * and to restore them during the subsequent resume.  Windows does that also for | 
 | 108 |  * suspend to RAM.  However, it is known that this mechanism does not work on | 
 | 109 |  * all machines, so we allow the user to disable it with the help of the | 
 | 110 |  * 'acpi_sleep=nonvs' kernel command line option. | 
 | 111 |  */ | 
 | 112 | static bool nvs_nosave; | 
 | 113 |  | 
 | 114 | void __init acpi_nvs_nosave(void) | 
 | 115 | { | 
 | 116 | 	nvs_nosave = true; | 
 | 117 | } | 
 | 118 |  | 
 | 119 | /* | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 120 |  * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the | 
 | 121 |  * user to request that behavior by using the 'acpi_old_suspend_ordering' | 
 | 122 |  * kernel command line option that causes the following variable to be set. | 
 | 123 |  */ | 
 | 124 | static bool old_suspend_ordering; | 
 | 125 |  | 
 | 126 | void __init acpi_old_suspend_ordering(void) | 
 | 127 | { | 
 | 128 | 	old_suspend_ordering = true; | 
 | 129 | } | 
 | 130 |  | 
 | 131 | /** | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 132 |  * acpi_pm_freeze - Disable the GPEs and suspend EC transactions. | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 133 |  */ | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 134 | static int acpi_pm_freeze(void) | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 135 | { | 
| Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 136 | 	acpi_disable_all_gpes(); | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 137 | 	acpi_os_wait_events_complete(NULL); | 
| Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 138 | 	acpi_ec_block_transactions(); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 139 | 	return 0; | 
 | 140 | } | 
 | 141 |  | 
 | 142 | /** | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 143 |  * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS. | 
 | 144 |  */ | 
 | 145 | static int acpi_pm_pre_suspend(void) | 
 | 146 | { | 
 | 147 | 	acpi_pm_freeze(); | 
| Jiri Slaby | 26fcaf6 | 2011-01-07 01:42:31 +0100 | [diff] [blame] | 148 | 	return suspend_nvs_save(); | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 149 | } | 
 | 150 |  | 
 | 151 | /** | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 152 |  *	__acpi_pm_prepare - Prepare the platform to enter the target state. | 
 | 153 |  * | 
 | 154 |  *	If necessary, set the firmware waking vector and do arch-specific | 
 | 155 |  *	nastiness to get the wakeup code to the waking vector. | 
 | 156 |  */ | 
 | 157 | static int __acpi_pm_prepare(void) | 
 | 158 | { | 
 | 159 | 	int error = acpi_sleep_prepare(acpi_target_sleep_state); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 160 | 	if (error) | 
 | 161 | 		acpi_target_sleep_state = ACPI_STATE_S0; | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 162 |  | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 163 | 	return error; | 
 | 164 | } | 
 | 165 |  | 
 | 166 | /** | 
 | 167 |  *	acpi_pm_prepare - Prepare the platform to enter the target sleep | 
 | 168 |  *		state and disable the GPEs. | 
 | 169 |  */ | 
 | 170 | static int acpi_pm_prepare(void) | 
 | 171 | { | 
 | 172 | 	int error = __acpi_pm_prepare(); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 173 | 	if (!error) | 
| Jiri Slaby | 26fcaf6 | 2011-01-07 01:42:31 +0100 | [diff] [blame] | 174 | 		error = acpi_pm_pre_suspend(); | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 175 |  | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 176 | 	return error; | 
 | 177 | } | 
 | 178 |  | 
 | 179 | /** | 
 | 180 |  *	acpi_pm_finish - Instruct the platform to leave a sleep state. | 
 | 181 |  * | 
 | 182 |  *	This is called after we wake back up (or if entering the sleep state | 
 | 183 |  *	failed). | 
 | 184 |  */ | 
 | 185 | static void acpi_pm_finish(void) | 
 | 186 | { | 
 | 187 | 	u32 acpi_state = acpi_target_sleep_state; | 
 | 188 |  | 
| Len Brown | 42de553 | 2010-06-12 01:15:40 -0400 | [diff] [blame] | 189 | 	acpi_ec_unblock_transactions(); | 
| Rafael J. Wysocki | d551d81 | 2011-01-19 22:27:55 +0100 | [diff] [blame] | 190 | 	suspend_nvs_free(); | 
| Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 191 |  | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 192 | 	if (acpi_state == ACPI_STATE_S0) | 
 | 193 | 		return; | 
 | 194 |  | 
 | 195 | 	printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n", | 
 | 196 | 		acpi_state); | 
| Rafael J. Wysocki | 78f5f02 | 2010-07-06 22:09:38 -0400 | [diff] [blame] | 197 | 	acpi_disable_wakeup_devices(acpi_state); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 198 | 	acpi_leave_sleep_state(acpi_state); | 
 | 199 |  | 
 | 200 | 	/* reset firmware waking vector */ | 
 | 201 | 	acpi_set_firmware_waking_vector((acpi_physical_address) 0); | 
 | 202 |  | 
 | 203 | 	acpi_target_sleep_state = ACPI_STATE_S0; | 
 | 204 | } | 
 | 205 |  | 
 | 206 | /** | 
 | 207 |  *	acpi_pm_end - Finish up suspend sequence. | 
 | 208 |  */ | 
 | 209 | static void acpi_pm_end(void) | 
 | 210 | { | 
 | 211 | 	/* | 
 | 212 | 	 * This is necessary in case acpi_pm_finish() is not called during a | 
 | 213 | 	 * failing transition to a sleep state. | 
 | 214 | 	 */ | 
 | 215 | 	acpi_target_sleep_state = ACPI_STATE_S0; | 
| Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 216 | 	acpi_sleep_tts_switch(acpi_target_sleep_state); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 217 | } | 
| Rafael J. Wysocki | 92daa7b | 2008-10-23 21:46:43 +0200 | [diff] [blame] | 218 | #else /* !CONFIG_ACPI_SLEEP */ | 
 | 219 | #define acpi_target_sleep_state	ACPI_STATE_S0 | 
| Rafael J. Wysocki | 5d1e072 | 2008-10-22 14:58:43 -0400 | [diff] [blame] | 220 | #endif /* CONFIG_ACPI_SLEEP */ | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 221 |  | 
 | 222 | #ifdef CONFIG_SUSPEND | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | static u32 acpi_suspend_states[] = { | 
| Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 224 | 	[PM_SUSPEND_ON] = ACPI_STATE_S0, | 
 | 225 | 	[PM_SUSPEND_STANDBY] = ACPI_STATE_S1, | 
 | 226 | 	[PM_SUSPEND_MEM] = ACPI_STATE_S3, | 
| Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 227 | 	[PM_SUSPEND_MAX] = ACPI_STATE_S5 | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | }; | 
 | 229 |  | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 230 | /** | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 231 |  *	acpi_suspend_begin - Set the target system sleep state to the state | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 232 |  *		associated with given @pm_state, if supported. | 
 | 233 |  */ | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 234 | static int acpi_suspend_begin(suspend_state_t pm_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { | 
 | 236 | 	u32 acpi_state = acpi_suspend_states[pm_state]; | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 237 | 	int error = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 |  | 
| Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 239 | 	error = nvs_nosave ? 0 : suspend_nvs_alloc(); | 
| Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 240 | 	if (error) | 
 | 241 | 		return error; | 
 | 242 |  | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 243 | 	if (sleep_states[acpi_state]) { | 
 | 244 | 		acpi_target_sleep_state = acpi_state; | 
| Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 245 | 		acpi_sleep_tts_switch(acpi_target_sleep_state); | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 246 | 	} else { | 
 | 247 | 		printk(KERN_ERR "ACPI does not support this state: %d\n", | 
 | 248 | 			pm_state); | 
 | 249 | 		error = -ENOSYS; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | 	} | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 251 | 	return error; | 
 | 252 | } | 
 | 253 |  | 
 | 254 | /** | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 255 |  *	acpi_suspend_enter - Actually enter a sleep state. | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 256 |  *	@pm_state: ignored | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  * | 
| Rafael J. Wysocki | 50ad147 | 2007-07-24 11:58:39 +0200 | [diff] [blame] | 258 |  *	Flush caches and go to sleep. For STR we have to call arch-specific | 
 | 259 |  *	assembly, which in turn call acpi_enter_sleep_state(). | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 |  *	It's unfortunate, but it works. Please fix if you're feeling frisky. | 
 | 261 |  */ | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 262 | static int acpi_suspend_enter(suspend_state_t pm_state) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { | 
 | 264 | 	acpi_status status = AE_OK; | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 265 | 	u32 acpi_state = acpi_target_sleep_state; | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 266 | 	u8 flags = wake_sleep_flags(); | 
| Rafael J. Wysocki | 979f11b | 2011-02-08 23:42:09 +0100 | [diff] [blame] | 267 | 	int error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 |  | 
 | 269 | 	ACPI_FLUSH_CPU_CACHE(); | 
 | 270 |  | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 271 | 	switch (acpi_state) { | 
 | 272 | 	case ACPI_STATE_S1: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | 		barrier(); | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 274 | 		status = acpi_enter_sleep_state(acpi_state, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | 		break; | 
 | 276 |  | 
| Rafael J. Wysocki | e9b3aba | 2007-07-17 22:40:06 +0200 | [diff] [blame] | 277 | 	case ACPI_STATE_S3: | 
| Rafael J. Wysocki | f1a2003 | 2011-02-08 23:42:22 +0100 | [diff] [blame] | 278 | 		error = acpi_suspend_lowlevel(); | 
| Rafael J. Wysocki | 979f11b | 2011-02-08 23:42:09 +0100 | [diff] [blame] | 279 | 		if (error) | 
 | 280 | 			return error; | 
| Rafael J. Wysocki | 7a63f08 | 2011-02-08 23:41:57 +0100 | [diff] [blame] | 281 | 		pr_info(PREFIX "Low-level resume complete\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | 	} | 
| Arnaud Patard | 872d83d | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 284 |  | 
| Matthew Garrett | b6dacf6 | 2010-05-11 13:49:25 -0400 | [diff] [blame] | 285 | 	/* This violates the spec but is required for bug compatibility. */ | 
 | 286 | 	acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1); | 
| Rafael J. Wysocki | 65df784 | 2008-11-26 17:53:13 -0500 | [diff] [blame] | 287 |  | 
| Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 288 | 	/* Reprogram control registers and execute _BFS */ | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 289 | 	acpi_leave_sleep_state_prep(acpi_state, flags); | 
| Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 290 |  | 
| Pavel Machek | 23b168d | 2008-02-05 19:27:12 +0100 | [diff] [blame] | 291 | 	/* ACPI 3.0 specs (P62) says that it's the responsibility | 
| Arnaud Patard | 872d83d | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 292 | 	 * of the OSPM to clear the status bit [ implying that the | 
 | 293 | 	 * POWER_BUTTON event should not reach userspace ] | 
 | 294 | 	 */ | 
 | 295 | 	if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3)) | 
 | 296 | 		acpi_clear_event(ACPI_EVENT_POWER_BUTTON); | 
 | 297 |  | 
| Shaohua Li | a3627f6 | 2007-06-20 09:17:58 +0800 | [diff] [blame] | 298 | 	/* | 
 | 299 | 	 * Disable and clear GPE status before interrupt is enabled. Some GPEs | 
 | 300 | 	 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire. | 
 | 301 | 	 * acpi_leave_sleep_state will reenable specific GPEs later | 
 | 302 | 	 */ | 
| Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 303 | 	acpi_disable_all_gpes(); | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 304 | 	/* Allow EC transactions to happen. */ | 
| Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 305 | 	acpi_ec_unblock_transactions_early(); | 
| Shaohua Li | a3627f6 | 2007-06-20 09:17:58 +0800 | [diff] [blame] | 306 |  | 
| Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 307 | 	suspend_nvs_restore(); | 
 | 308 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | 	return ACPI_SUCCESS(status) ? 0 : -EFAULT; | 
 | 310 | } | 
 | 311 |  | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 312 | static int acpi_suspend_state_valid(suspend_state_t pm_state) | 
| Shaohua Li | eb9289e | 2005-10-30 15:00:01 -0800 | [diff] [blame] | 313 | { | 
| Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 314 | 	u32 acpi_state; | 
| Shaohua Li | eb9289e | 2005-10-30 15:00:01 -0800 | [diff] [blame] | 315 |  | 
| Johannes Berg | e8c9c50 | 2007-04-30 15:09:54 -0700 | [diff] [blame] | 316 | 	switch (pm_state) { | 
 | 317 | 	case PM_SUSPEND_ON: | 
 | 318 | 	case PM_SUSPEND_STANDBY: | 
 | 319 | 	case PM_SUSPEND_MEM: | 
 | 320 | 		acpi_state = acpi_suspend_states[pm_state]; | 
 | 321 |  | 
 | 322 | 		return sleep_states[acpi_state]; | 
 | 323 | 	default: | 
 | 324 | 		return 0; | 
 | 325 | 	} | 
| Shaohua Li | eb9289e | 2005-10-30 15:00:01 -0800 | [diff] [blame] | 326 | } | 
 | 327 |  | 
| Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 328 | static const struct platform_suspend_ops acpi_suspend_ops = { | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 329 | 	.valid = acpi_suspend_state_valid, | 
 | 330 | 	.begin = acpi_suspend_begin, | 
| Rafael J. Wysocki | 6a7c7ea | 2009-04-19 20:08:42 +0200 | [diff] [blame] | 331 | 	.prepare_late = acpi_pm_prepare, | 
| Len Brown | 2c6e33c | 2008-04-23 18:02:52 -0400 | [diff] [blame] | 332 | 	.enter = acpi_suspend_enter, | 
| Rafael J. Wysocki | 618d7fd | 2010-07-02 00:14:57 +0200 | [diff] [blame] | 333 | 	.wake = acpi_pm_finish, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 334 | 	.end = acpi_pm_end, | 
 | 335 | }; | 
 | 336 |  | 
 | 337 | /** | 
 | 338 |  *	acpi_suspend_begin_old - Set the target system sleep state to the | 
 | 339 |  *		state associated with given @pm_state, if supported, and | 
 | 340 |  *		execute the _PTS control method.  This function is used if the | 
 | 341 |  *		pre-ACPI 2.0 suspend ordering has been requested. | 
 | 342 |  */ | 
 | 343 | static int acpi_suspend_begin_old(suspend_state_t pm_state) | 
 | 344 | { | 
 | 345 | 	int error = acpi_suspend_begin(pm_state); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 346 | 	if (!error) | 
 | 347 | 		error = __acpi_pm_prepare(); | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 348 |  | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 349 | 	return error; | 
 | 350 | } | 
 | 351 |  | 
 | 352 | /* | 
 | 353 |  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has | 
 | 354 |  * been requested. | 
 | 355 |  */ | 
| Lionel Debroux | 2f55ac0 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 356 | static const struct platform_suspend_ops acpi_suspend_ops_old = { | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 357 | 	.valid = acpi_suspend_state_valid, | 
 | 358 | 	.begin = acpi_suspend_begin_old, | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 359 | 	.prepare_late = acpi_pm_pre_suspend, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 360 | 	.enter = acpi_suspend_enter, | 
| Rafael J. Wysocki | 618d7fd | 2010-07-02 00:14:57 +0200 | [diff] [blame] | 361 | 	.wake = acpi_pm_finish, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 362 | 	.end = acpi_pm_end, | 
 | 363 | 	.recover = acpi_pm_finish, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | }; | 
| Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 365 |  | 
 | 366 | static int __init init_old_suspend_ordering(const struct dmi_system_id *d) | 
 | 367 | { | 
 | 368 | 	old_suspend_ordering = true; | 
 | 369 | 	return 0; | 
 | 370 | } | 
 | 371 |  | 
| Rafael J. Wysocki | 5399864 | 2010-09-24 16:46:14 -0400 | [diff] [blame] | 372 | static int __init init_nvs_nosave(const struct dmi_system_id *d) | 
 | 373 | { | 
 | 374 | 	acpi_nvs_nosave(); | 
 | 375 | 	return 0; | 
 | 376 | } | 
 | 377 |  | 
| Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 378 | static struct dmi_system_id __initdata acpisleep_dmi_table[] = { | 
 | 379 | 	{ | 
 | 380 | 	.callback = init_old_suspend_ordering, | 
 | 381 | 	.ident = "Abit KN9 (nForce4 variant)", | 
 | 382 | 	.matches = { | 
 | 383 | 		DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"), | 
 | 384 | 		DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"), | 
 | 385 | 		}, | 
 | 386 | 	}, | 
| Rafael J. Wysocki | 4fb507b | 2008-10-14 22:54:06 +0200 | [diff] [blame] | 387 | 	{ | 
 | 388 | 	.callback = init_old_suspend_ordering, | 
 | 389 | 	.ident = "HP xw4600 Workstation", | 
 | 390 | 	.matches = { | 
 | 391 | 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), | 
 | 392 | 		DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"), | 
 | 393 | 		}, | 
 | 394 | 	}, | 
| Rafael J. Wysocki | 65df784 | 2008-11-26 17:53:13 -0500 | [diff] [blame] | 395 | 	{ | 
| Andy Whitcroft | a140449 | 2009-02-11 18:11:22 +0000 | [diff] [blame] | 396 | 	.callback = init_old_suspend_ordering, | 
 | 397 | 	.ident = "Asus Pundit P1-AH2 (M2N8L motherboard)", | 
 | 398 | 	.matches = { | 
 | 399 | 		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."), | 
 | 400 | 		DMI_MATCH(DMI_BOARD_NAME, "M2N8L"), | 
 | 401 | 		}, | 
 | 402 | 	}, | 
| Zhang Rui | 45e7798 | 2009-03-15 22:13:44 -0400 | [diff] [blame] | 403 | 	{ | 
| Zhao Yakui | 2a9ef8e | 2009-03-18 16:36:25 +0800 | [diff] [blame] | 404 | 	.callback = init_old_suspend_ordering, | 
 | 405 | 	.ident = "Panasonic CF51-2L", | 
 | 406 | 	.matches = { | 
 | 407 | 		DMI_MATCH(DMI_BOARD_VENDOR, | 
 | 408 | 				"Matsushita Electric Industrial Co.,Ltd."), | 
 | 409 | 		DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"), | 
 | 410 | 		}, | 
 | 411 | 	}, | 
| Rafael J. Wysocki | 5399864 | 2010-09-24 16:46:14 -0400 | [diff] [blame] | 412 | 	{ | 
 | 413 | 	.callback = init_nvs_nosave, | 
| Dave Jones | d11c78e | 2011-10-19 23:15:11 +0200 | [diff] [blame] | 414 | 	.ident = "Sony Vaio VGN-FW21E", | 
 | 415 | 	.matches = { | 
 | 416 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 417 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"), | 
 | 418 | 		}, | 
 | 419 | 	}, | 
 | 420 | 	{ | 
 | 421 | 	.callback = init_nvs_nosave, | 
| Dave Jones | ddf6ce4 | 2011-11-03 00:58:59 +0100 | [diff] [blame] | 422 | 	.ident = "Sony Vaio VPCEB17FX", | 
 | 423 | 	.matches = { | 
 | 424 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 425 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"), | 
 | 426 | 		}, | 
 | 427 | 	}, | 
 | 428 | 	{ | 
 | 429 | 	.callback = init_nvs_nosave, | 
| Rafael J. Wysocki | 5399864 | 2010-09-24 16:46:14 -0400 | [diff] [blame] | 430 | 	.ident = "Sony Vaio VGN-SR11M", | 
 | 431 | 	.matches = { | 
 | 432 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 433 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"), | 
 | 434 | 		}, | 
 | 435 | 	}, | 
 | 436 | 	{ | 
 | 437 | 	.callback = init_nvs_nosave, | 
 | 438 | 	.ident = "Everex StepNote Series", | 
 | 439 | 	.matches = { | 
 | 440 | 		DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."), | 
 | 441 | 		DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"), | 
 | 442 | 		}, | 
 | 443 | 	}, | 
| Rafael J. Wysocki | af48931 | 2010-10-17 21:01:21 +0200 | [diff] [blame] | 444 | 	{ | 
 | 445 | 	.callback = init_nvs_nosave, | 
 | 446 | 	.ident = "Sony Vaio VPCEB1Z1E", | 
 | 447 | 	.matches = { | 
 | 448 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 449 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"), | 
 | 450 | 		}, | 
 | 451 | 	}, | 
| Rafael J. Wysocki | 291a73c | 2010-12-12 21:10:42 +0100 | [diff] [blame] | 452 | 	{ | 
 | 453 | 	.callback = init_nvs_nosave, | 
 | 454 | 	.ident = "Sony Vaio VGN-NW130D", | 
 | 455 | 	.matches = { | 
 | 456 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 457 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"), | 
 | 458 | 		}, | 
 | 459 | 	}, | 
| Rafael J. Wysocki | 7b33070 | 2011-01-06 23:37:01 +0100 | [diff] [blame] | 460 | 	{ | 
 | 461 | 	.callback = init_nvs_nosave, | 
| Lan Tianyu | 93f7708 | 2012-01-21 09:23:56 +0800 | [diff] [blame] | 462 | 	.ident = "Sony Vaio VPCCW29FX", | 
 | 463 | 	.matches = { | 
 | 464 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 465 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"), | 
 | 466 | 		}, | 
 | 467 | 	}, | 
 | 468 | 	{ | 
 | 469 | 	.callback = init_nvs_nosave, | 
| Rafael J. Wysocki | 7b33070 | 2011-01-06 23:37:01 +0100 | [diff] [blame] | 470 | 	.ident = "Averatec AV1020-ED2", | 
 | 471 | 	.matches = { | 
 | 472 | 		DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"), | 
 | 473 | 		DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"), | 
 | 474 | 		}, | 
 | 475 | 	}, | 
| Zhang Rui | bb0c5ed | 2011-07-30 01:40:48 -0400 | [diff] [blame] | 476 | 	{ | 
 | 477 | 	.callback = init_old_suspend_ordering, | 
 | 478 | 	.ident = "Asus A8N-SLI DELUXE", | 
 | 479 | 	.matches = { | 
 | 480 | 		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), | 
 | 481 | 		DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"), | 
 | 482 | 		}, | 
 | 483 | 	}, | 
 | 484 | 	{ | 
 | 485 | 	.callback = init_old_suspend_ordering, | 
 | 486 | 	.ident = "Asus A8N-SLI Premium", | 
 | 487 | 	.matches = { | 
 | 488 | 		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."), | 
 | 489 | 		DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"), | 
 | 490 | 		}, | 
 | 491 | 	}, | 
| Rafael J. Wysocki | 89e8ea1 | 2011-10-06 20:35:03 +0200 | [diff] [blame] | 492 | 	{ | 
 | 493 | 	.callback = init_nvs_nosave, | 
 | 494 | 	.ident = "Sony Vaio VGN-SR26GN_P", | 
 | 495 | 	.matches = { | 
 | 496 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 497 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"), | 
 | 498 | 		}, | 
 | 499 | 	}, | 
| Bogdan Radulescu | 731b25a | 2011-10-06 20:35:12 +0200 | [diff] [blame] | 500 | 	{ | 
 | 501 | 	.callback = init_nvs_nosave, | 
 | 502 | 	.ident = "Sony Vaio VGN-FW520F", | 
 | 503 | 	.matches = { | 
 | 504 | 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), | 
 | 505 | 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"), | 
 | 506 | 		}, | 
 | 507 | 	}, | 
| Keng-Yu Lin | 5a50a7c | 2011-12-02 00:04:23 +0100 | [diff] [blame] | 508 | 	{ | 
 | 509 | 	.callback = init_nvs_nosave, | 
 | 510 | 	.ident = "Asus K54C", | 
 | 511 | 	.matches = { | 
 | 512 | 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), | 
 | 513 | 		DMI_MATCH(DMI_PRODUCT_NAME, "K54C"), | 
 | 514 | 		}, | 
 | 515 | 	}, | 
 | 516 | 	{ | 
 | 517 | 	.callback = init_nvs_nosave, | 
 | 518 | 	.ident = "Asus K54HR", | 
 | 519 | 	.matches = { | 
 | 520 | 		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."), | 
 | 521 | 		DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"), | 
 | 522 | 		}, | 
 | 523 | 	}, | 
| Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 524 | 	{}, | 
 | 525 | }; | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 526 | #endif /* CONFIG_SUSPEND */ | 
 | 527 |  | 
| Rafael J. Wysocki | b0cb1a1 | 2007-07-29 23:24:36 +0200 | [diff] [blame] | 528 | #ifdef CONFIG_HIBERNATION | 
| Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 529 | static unsigned long s4_hardware_signature; | 
 | 530 | static struct acpi_table_facs *facs; | 
 | 531 | static bool nosigcheck; | 
 | 532 |  | 
 | 533 | void __init acpi_no_s4_hw_signature(void) | 
 | 534 | { | 
 | 535 | 	nosigcheck = true; | 
 | 536 | } | 
 | 537 |  | 
| Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 538 | static int acpi_hibernation_begin(void) | 
| Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 539 | { | 
| Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 540 | 	int error; | 
 | 541 |  | 
| Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 542 | 	error = nvs_nosave ? 0 : suspend_nvs_alloc(); | 
| Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 543 | 	if (!error) { | 
 | 544 | 		acpi_target_sleep_state = ACPI_STATE_S4; | 
 | 545 | 		acpi_sleep_tts_switch(acpi_target_sleep_state); | 
 | 546 | 	} | 
 | 547 |  | 
 | 548 | 	return error; | 
 | 549 | } | 
 | 550 |  | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 551 | static int acpi_hibernation_enter(void) | 
 | 552 | { | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 553 | 	u8 flags = wake_sleep_flags(); | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 554 | 	acpi_status status = AE_OK; | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 555 |  | 
 | 556 | 	ACPI_FLUSH_CPU_CACHE(); | 
 | 557 |  | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 558 | 	/* This shouldn't return.  If it returns, we have a problem */ | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 559 | 	status = acpi_enter_sleep_state(ACPI_STATE_S4, flags); | 
| Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 560 | 	/* Reprogram control registers and execute _BFS */ | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 561 | 	acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags); | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 562 |  | 
 | 563 | 	return ACPI_SUCCESS(status) ? 0 : -EFAULT; | 
 | 564 | } | 
 | 565 |  | 
| Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 566 | static void acpi_hibernation_leave(void) | 
 | 567 | { | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 568 | 	u8 flags = wake_sleep_flags(); | 
 | 569 |  | 
| Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 570 | 	/* | 
 | 571 | 	 * If ACPI is not enabled by the BIOS and the boot kernel, we need to | 
 | 572 | 	 * enable it here. | 
 | 573 | 	 */ | 
 | 574 | 	acpi_enable(); | 
| Rafael J. Wysocki | c95d47a | 2008-01-08 00:05:21 +0100 | [diff] [blame] | 575 | 	/* Reprogram control registers and execute _BFS */ | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 576 | 	acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags); | 
| Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 577 | 	/* Check the hardware signature */ | 
 | 578 | 	if (facs && s4_hardware_signature != facs->hardware_signature) { | 
 | 579 | 		printk(KERN_EMERG "ACPI: Hardware changed while hibernated, " | 
 | 580 | 			"cannot resume!\n"); | 
 | 581 | 		panic("ACPI S4 hardware signature mismatch"); | 
 | 582 | 	} | 
| Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 583 | 	/* Restore the NVS memory area */ | 
| Matthew Garrett | dd4c4f1 | 2010-05-28 16:32:14 -0400 | [diff] [blame] | 584 | 	suspend_nvs_restore(); | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 585 | 	/* Allow EC transactions to happen. */ | 
| Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 586 | 	acpi_ec_unblock_transactions_early(); | 
| Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 587 | } | 
 | 588 |  | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 589 | static void acpi_pm_thaw(void) | 
| Rafael J. Wysocki | f6bb13a | 2010-03-04 01:52:58 +0100 | [diff] [blame] | 590 | { | 
| Rafael J. Wysocki | fe95568 | 2010-04-09 01:40:38 +0200 | [diff] [blame] | 591 | 	acpi_ec_unblock_transactions(); | 
| Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 592 | 	acpi_enable_all_runtime_gpes(); | 
| Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 593 | } | 
 | 594 |  | 
| Lionel Debroux | 073ef1f | 2010-11-09 21:48:49 +0100 | [diff] [blame] | 595 | static const struct platform_hibernation_ops acpi_hibernation_ops = { | 
| Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 596 | 	.begin = acpi_hibernation_begin, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 597 | 	.end = acpi_pm_end, | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 598 | 	.pre_snapshot = acpi_pm_prepare, | 
| Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 599 | 	.finish = acpi_pm_finish, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 600 | 	.prepare = acpi_pm_prepare, | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 601 | 	.enter = acpi_hibernation_enter, | 
| Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 602 | 	.leave = acpi_hibernation_leave, | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 603 | 	.pre_restore = acpi_pm_freeze, | 
 | 604 | 	.restore_cleanup = acpi_pm_thaw, | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 605 | }; | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 606 |  | 
 | 607 | /** | 
 | 608 |  *	acpi_hibernation_begin_old - Set the target system sleep state to | 
 | 609 |  *		ACPI_STATE_S4 and execute the _PTS control method.  This | 
 | 610 |  *		function is used if the pre-ACPI 2.0 suspend ordering has been | 
 | 611 |  *		requested. | 
 | 612 |  */ | 
 | 613 | static int acpi_hibernation_begin_old(void) | 
 | 614 | { | 
| Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 615 | 	int error; | 
 | 616 | 	/* | 
 | 617 | 	 * The _TTS object should always be evaluated before the _PTS object. | 
 | 618 | 	 * When the old_suspended_ordering is true, the _PTS object is | 
 | 619 | 	 * evaluated in the acpi_sleep_prepare. | 
 | 620 | 	 */ | 
 | 621 | 	acpi_sleep_tts_switch(ACPI_STATE_S4); | 
 | 622 |  | 
 | 623 | 	error = acpi_sleep_prepare(ACPI_STATE_S4); | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 624 |  | 
| Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 625 | 	if (!error) { | 
| Rafael J. Wysocki | 72ad5d7 | 2010-07-23 22:59:09 +0200 | [diff] [blame] | 626 | 		if (!nvs_nosave) | 
| Matthew Garrett | dd4c4f1 | 2010-05-28 16:32:14 -0400 | [diff] [blame] | 627 | 			error = suspend_nvs_alloc(); | 
| Rafael J. Wysocki | 3f4b0ef | 2008-10-26 20:52:15 +0100 | [diff] [blame] | 628 | 		if (!error) | 
 | 629 | 			acpi_target_sleep_state = ACPI_STATE_S4; | 
 | 630 | 	} | 
 | 631 | 	return error; | 
 | 632 | } | 
 | 633 |  | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 634 | /* | 
 | 635 |  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has | 
 | 636 |  * been requested. | 
 | 637 |  */ | 
| Lionel Debroux | 073ef1f | 2010-11-09 21:48:49 +0100 | [diff] [blame] | 638 | static const struct platform_hibernation_ops acpi_hibernation_ops_old = { | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 639 | 	.begin = acpi_hibernation_begin_old, | 
 | 640 | 	.end = acpi_pm_end, | 
| Rafael J. Wysocki | c5f7a1b | 2010-07-02 00:14:09 +0200 | [diff] [blame] | 641 | 	.pre_snapshot = acpi_pm_pre_suspend, | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 642 | 	.prepare = acpi_pm_freeze, | 
| Matthew Garrett | 2a6b697 | 2010-05-28 16:32:15 -0400 | [diff] [blame] | 643 | 	.finish = acpi_pm_finish, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 644 | 	.enter = acpi_hibernation_enter, | 
 | 645 | 	.leave = acpi_hibernation_leave, | 
| Rafael J. Wysocki | d5a6451 | 2010-04-09 01:39:40 +0200 | [diff] [blame] | 646 | 	.pre_restore = acpi_pm_freeze, | 
 | 647 | 	.restore_cleanup = acpi_pm_thaw, | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 648 | 	.recover = acpi_pm_finish, | 
 | 649 | }; | 
 | 650 | #endif /* CONFIG_HIBERNATION */ | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 651 |  | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 652 | int acpi_suspend(u32 acpi_state) | 
 | 653 | { | 
 | 654 | 	suspend_state_t states[] = { | 
 | 655 | 		[1] = PM_SUSPEND_STANDBY, | 
 | 656 | 		[3] = PM_SUSPEND_MEM, | 
 | 657 | 		[5] = PM_SUSPEND_MAX | 
 | 658 | 	}; | 
 | 659 |  | 
 | 660 | 	if (acpi_state < 6 && states[acpi_state]) | 
 | 661 | 		return pm_suspend(states[acpi_state]); | 
 | 662 | 	if (acpi_state == 4) | 
 | 663 | 		return hibernate(); | 
 | 664 | 	return -EINVAL; | 
 | 665 | } | 
 | 666 |  | 
| Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 667 | #ifdef CONFIG_PM | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 668 | /** | 
 | 669 |  *	acpi_pm_device_sleep_state - return preferred power state of ACPI device | 
 | 670 |  *		in the system sleep state given by %acpi_target_sleep_state | 
| David Brownell | 2fe2de5 | 2008-06-05 01:15:40 +0200 | [diff] [blame] | 671 |  *	@dev: device to examine; its driver model wakeup flags control | 
 | 672 |  *		whether it should be able to wake up the system | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 673 |  *	@d_min_p: used to store the upper limit of allowed states range | 
 | 674 |  *	Return value: preferred power state of the device on success, -ENODEV on | 
 | 675 |  *		failure (ie. if there's no 'struct acpi_device' for @dev) | 
 | 676 |  * | 
 | 677 |  *	Find the lowest power (highest number) ACPI device power state that | 
 | 678 |  *	device @dev can be in while the system is in the sleep state represented | 
 | 679 |  *	by %acpi_target_sleep_state.  If @wake is nonzero, the device should be | 
 | 680 |  *	able to wake up the system from this sleep state.  If @d_min_p is set, | 
 | 681 |  *	the highest power (lowest number) device power state of @dev allowed | 
 | 682 |  *	in this system sleep state is stored at the location pointed to by it. | 
 | 683 |  * | 
 | 684 |  *	The caller must ensure that @dev is valid before using this function. | 
 | 685 |  *	The caller is also responsible for figuring out if the device is | 
 | 686 |  *	supposed to be able to wake up the system and passing this information | 
 | 687 |  *	via @wake. | 
 | 688 |  */ | 
 | 689 |  | 
| David Brownell | 2fe2de5 | 2008-06-05 01:15:40 +0200 | [diff] [blame] | 690 | int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 691 | { | 
 | 692 | 	acpi_handle handle = DEVICE_ACPI_HANDLE(dev); | 
 | 693 | 	struct acpi_device *adev; | 
 | 694 | 	char acpi_method[] = "_SxD"; | 
| Matthew Wilcox | 27663c5 | 2008-10-10 02:22:59 -0400 | [diff] [blame] | 695 | 	unsigned long long d_min, d_max; | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 696 |  | 
 | 697 | 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | 
| Shaohua Li | ead7759 | 2007-08-23 15:01:13 +0800 | [diff] [blame] | 698 | 		printk(KERN_DEBUG "ACPI handle has no context!\n"); | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 699 | 		return -ENODEV; | 
 | 700 | 	} | 
 | 701 |  | 
 | 702 | 	acpi_method[2] = '0' + acpi_target_sleep_state; | 
 | 703 | 	/* | 
 | 704 | 	 * If the sleep state is S0, we will return D3, but if the device has | 
 | 705 | 	 * _S0W, we will use the value from _S0W | 
 | 706 | 	 */ | 
 | 707 | 	d_min = ACPI_STATE_D0; | 
 | 708 | 	d_max = ACPI_STATE_D3; | 
 | 709 |  | 
 | 710 | 	/* | 
 | 711 | 	 * If present, _SxD methods return the minimum D-state (highest power | 
 | 712 | 	 * state) we can use for the corresponding S-states.  Otherwise, the | 
 | 713 | 	 * minimum D-state is D0 (ACPI 3.x). | 
 | 714 | 	 * | 
 | 715 | 	 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer | 
 | 716 | 	 * provided -- that's our fault recovery, we ignore retval. | 
 | 717 | 	 */ | 
 | 718 | 	if (acpi_target_sleep_state > ACPI_STATE_S0) | 
 | 719 | 		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min); | 
 | 720 |  | 
 | 721 | 	/* | 
 | 722 | 	 * If _PRW says we can wake up the system from the target sleep state, | 
 | 723 | 	 * the D-state returned by _SxD is sufficient for that (we assume a | 
 | 724 | 	 * wakeup-aware driver if wake is set).  Still, if _SxW exists | 
 | 725 | 	 * (ACPI 3.x), it should return the maximum (lowest power) D-state that | 
 | 726 | 	 * can wake the system.  _S0W may be valid, too. | 
 | 727 | 	 */ | 
 | 728 | 	if (acpi_target_sleep_state == ACPI_STATE_S0 || | 
| Rafael J. Wysocki | 761afb8 | 2010-10-14 23:24:13 +0200 | [diff] [blame] | 729 | 	    (device_may_wakeup(dev) && | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 730 | 	     adev->wakeup.sleep_state <= acpi_target_sleep_state)) { | 
| Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 731 | 		acpi_status status; | 
 | 732 |  | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 733 | 		acpi_method[3] = 'W'; | 
| Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 734 | 		status = acpi_evaluate_integer(handle, acpi_method, NULL, | 
 | 735 | 						&d_max); | 
 | 736 | 		if (ACPI_FAILURE(status)) { | 
| Rafael J. Wysocki | 761afb8 | 2010-10-14 23:24:13 +0200 | [diff] [blame] | 737 | 			if (acpi_target_sleep_state != ACPI_STATE_S0 || | 
 | 738 | 			    status != AE_NOT_FOUND) | 
 | 739 | 				d_max = d_min; | 
| Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 740 | 		} else if (d_max < d_min) { | 
 | 741 | 			/* Warn the user of the broken DSDT */ | 
 | 742 | 			printk(KERN_WARNING "ACPI: Wrong value from %s\n", | 
 | 743 | 				acpi_method); | 
 | 744 | 			/* Sanitize it */ | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 745 | 			d_min = d_max; | 
| Rafael J. Wysocki | ad3399c | 2008-01-11 00:10:38 +0100 | [diff] [blame] | 746 | 		} | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 747 | 	} | 
 | 748 |  | 
 | 749 | 	if (d_min_p) | 
 | 750 | 		*d_min_p = d_min; | 
 | 751 | 	return d_max; | 
 | 752 | } | 
| Rafael J. Wysocki | aa33860 | 2011-02-11 00:06:54 +0100 | [diff] [blame] | 753 | #endif /* CONFIG_PM */ | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 754 |  | 
| Rafael J. Wysocki | 761afb8 | 2010-10-14 23:24:13 +0200 | [diff] [blame] | 755 | #ifdef CONFIG_PM_SLEEP | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 756 | /** | 
| Lin Ming | b24e509 | 2012-03-27 15:43:25 +0800 | [diff] [blame] | 757 |  * acpi_pm_device_run_wake - Enable/disable wake-up for given device. | 
 | 758 |  * @phys_dev: Device to enable/disable the platform to wake-up the system for. | 
 | 759 |  * @enable: Whether enable or disable the wake-up functionality. | 
 | 760 |  * | 
 | 761 |  * Find the ACPI device object corresponding to @pci_dev and try to | 
 | 762 |  * enable/disable the GPE associated with it. | 
 | 763 |  */ | 
 | 764 | int acpi_pm_device_run_wake(struct device *phys_dev, bool enable) | 
 | 765 | { | 
 | 766 | 	struct acpi_device *dev; | 
 | 767 | 	acpi_handle handle; | 
 | 768 |  | 
 | 769 | 	if (!device_run_wake(phys_dev)) | 
 | 770 | 		return -EINVAL; | 
 | 771 |  | 
 | 772 | 	handle = DEVICE_ACPI_HANDLE(phys_dev); | 
 | 773 | 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) { | 
 | 774 | 		dev_dbg(phys_dev, "ACPI handle has no context in %s!\n", | 
 | 775 | 			__func__); | 
 | 776 | 		return -ENODEV; | 
 | 777 | 	} | 
 | 778 |  | 
 | 779 | 	if (enable) { | 
 | 780 | 		acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0); | 
 | 781 | 		acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number); | 
 | 782 | 	} else { | 
 | 783 | 		acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number); | 
 | 784 | 		acpi_disable_wakeup_device_power(dev); | 
 | 785 | 	} | 
 | 786 |  | 
 | 787 | 	return 0; | 
 | 788 | } | 
 | 789 |  | 
 | 790 | /** | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 791 |  *	acpi_pm_device_sleep_wake - enable or disable the system wake-up | 
 | 792 |  *                                  capability of given device | 
 | 793 |  *	@dev: device to handle | 
 | 794 |  *	@enable: 'true' - enable, 'false' - disable the wake-up capability | 
 | 795 |  */ | 
 | 796 | int acpi_pm_device_sleep_wake(struct device *dev, bool enable) | 
 | 797 | { | 
 | 798 | 	acpi_handle handle; | 
 | 799 | 	struct acpi_device *adev; | 
| Rafael J. Wysocki | df8db91 | 2009-09-08 23:13:49 +0200 | [diff] [blame] | 800 | 	int error; | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 801 |  | 
| Rafael J. Wysocki | 0baed8d | 2009-09-08 23:16:24 +0200 | [diff] [blame] | 802 | 	if (!device_can_wakeup(dev)) | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 803 | 		return -EINVAL; | 
 | 804 |  | 
 | 805 | 	handle = DEVICE_ACPI_HANDLE(dev); | 
 | 806 | 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { | 
| Rafael J. Wysocki | df8db91 | 2009-09-08 23:13:49 +0200 | [diff] [blame] | 807 | 		dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__); | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 808 | 		return -ENODEV; | 
 | 809 | 	} | 
 | 810 |  | 
| Rafael J. Wysocki | e8b6f97 | 2010-06-25 01:18:39 +0200 | [diff] [blame] | 811 | 	error = enable ? | 
 | 812 | 		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) : | 
 | 813 | 		acpi_disable_wakeup_device_power(adev); | 
| Rafael J. Wysocki | df8db91 | 2009-09-08 23:13:49 +0200 | [diff] [blame] | 814 | 	if (!error) | 
 | 815 | 		dev_info(dev, "wake-up capability %s by ACPI\n", | 
 | 816 | 				enable ? "enabled" : "disabled"); | 
 | 817 |  | 
 | 818 | 	return error; | 
| Rafael J. Wysocki | eb9d0fe | 2008-07-07 03:34:48 +0200 | [diff] [blame] | 819 | } | 
| Rafael J. Wysocki | 761afb8 | 2010-10-14 23:24:13 +0200 | [diff] [blame] | 820 | #endif  /* CONFIG_PM_SLEEP */ | 
| Shaohua Li | fd4aff1 | 2007-07-17 22:40:25 +0200 | [diff] [blame] | 821 |  | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 822 | static void acpi_power_off_prepare(void) | 
 | 823 | { | 
 | 824 | 	/* Prepare to power off the system */ | 
 | 825 | 	acpi_sleep_prepare(ACPI_STATE_S5); | 
| Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 826 | 	acpi_disable_all_gpes(); | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 827 | } | 
 | 828 |  | 
 | 829 | static void acpi_power_off(void) | 
 | 830 | { | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 831 | 	u8 flags = wake_sleep_flags(); | 
 | 832 |  | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 833 | 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */ | 
| Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 834 | 	printk(KERN_DEBUG "%s called\n", __func__); | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 835 | 	local_irq_disable(); | 
| Lin Ming | a2ef5c4 | 2012-03-21 10:58:46 +0800 | [diff] [blame] | 836 | 	acpi_enter_sleep_state(ACPI_STATE_S5, flags); | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 837 | } | 
 | 838 |  | 
| Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 839 | /* | 
 | 840 |  * ACPI 2.0 created the optional _GTS and _BFS, | 
 | 841 |  * but industry adoption has been neither rapid nor broad. | 
 | 842 |  * | 
 | 843 |  * Linux gets into trouble when it executes poorly validated | 
 | 844 |  * paths through the BIOS, so disable _GTS and _BFS by default, | 
 | 845 |  * but do speak up and offer the option to enable them. | 
 | 846 |  */ | 
| Stephen Hemminger | 01eac60 | 2010-10-18 18:47:25 -0700 | [diff] [blame] | 847 | static void __init acpi_gts_bfs_check(void) | 
| Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 848 | { | 
 | 849 | 	acpi_handle dummy; | 
 | 850 |  | 
| Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 851 | 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__GTS, &dummy))) | 
| Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 852 | 	{ | 
 | 853 | 		printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n"); | 
 | 854 | 		printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, " | 
 | 855 | 			"please notify linux-acpi@vger.kernel.org\n"); | 
 | 856 | 	} | 
| Bob Moore | 4efeeec | 2012-03-21 09:42:45 +0800 | [diff] [blame] | 857 | 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__BFS, &dummy))) | 
| Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 858 | 	{ | 
 | 859 | 		printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n"); | 
 | 860 | 		printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, " | 
 | 861 | 			"please notify linux-acpi@vger.kernel.org\n"); | 
 | 862 | 	} | 
 | 863 | } | 
 | 864 |  | 
| Alexey Starikovskiy | aafbcd1 | 2007-02-10 01:32:16 -0500 | [diff] [blame] | 865 | int __init acpi_sleep_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 867 | 	acpi_status status; | 
 | 868 | 	u8 type_a, type_b; | 
 | 869 | #ifdef CONFIG_SUSPEND | 
| Alexey Starikovskiy | e2a5b42 | 2005-03-18 16:20:46 -0500 | [diff] [blame] | 870 | 	int i = 0; | 
| Carlos Corbacho | e41fb7c | 2008-07-23 21:28:43 -0700 | [diff] [blame] | 871 |  | 
 | 872 | 	dmi_check_system(acpisleep_dmi_table); | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 873 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 |  | 
 | 875 | 	if (acpi_disabled) | 
 | 876 | 		return 0; | 
 | 877 |  | 
| Frans Pop | 5a50fe7 | 2007-09-20 22:27:44 +0200 | [diff] [blame] | 878 | 	sleep_states[ACPI_STATE_S0] = 1; | 
 | 879 | 	printk(KERN_INFO PREFIX "(supports S0"); | 
 | 880 |  | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 881 | #ifdef CONFIG_SUSPEND | 
| Frans Pop | 5a50fe7 | 2007-09-20 22:27:44 +0200 | [diff] [blame] | 882 | 	for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | 		status = acpi_get_sleep_type_data(i, &type_a, &type_b); | 
 | 884 | 		if (ACPI_SUCCESS(status)) { | 
 | 885 | 			sleep_states[i] = 1; | 
 | 886 | 			printk(" S%d", i); | 
 | 887 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 |  | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 890 | 	suspend_set_ops(old_suspend_ordering ? | 
 | 891 | 		&acpi_suspend_ops_old : &acpi_suspend_ops); | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 892 | #endif | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 893 |  | 
| Rafael J. Wysocki | b0cb1a1 | 2007-07-29 23:24:36 +0200 | [diff] [blame] | 894 | #ifdef CONFIG_HIBERNATION | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 895 | 	status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b); | 
 | 896 | 	if (ACPI_SUCCESS(status)) { | 
| Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 897 | 		hibernation_set_ops(old_suspend_ordering ? | 
 | 898 | 			&acpi_hibernation_ops_old : &acpi_hibernation_ops); | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 899 | 		sleep_states[ACPI_STATE_S4] = 1; | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 900 | 		printk(" S4"); | 
| Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 901 | 		if (!nosigcheck) { | 
| Lin Ming | 3d97e42 | 2008-12-16 16:57:46 +0800 | [diff] [blame] | 902 | 			acpi_get_table(ACPI_SIG_FACS, 1, | 
| Shaohua Li | bdfe6b7 | 2008-07-23 21:28:41 -0700 | [diff] [blame] | 903 | 				(struct acpi_table_header **)&facs); | 
 | 904 | 			if (facs) | 
 | 905 | 				s4_hardware_signature = | 
 | 906 | 					facs->hardware_signature; | 
 | 907 | 		} | 
| Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 908 | 	} | 
| Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 909 | #endif | 
| Alexey Starikovskiy | f216cc3 | 2007-09-20 21:32:35 +0400 | [diff] [blame] | 910 | 	status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b); | 
 | 911 | 	if (ACPI_SUCCESS(status)) { | 
 | 912 | 		sleep_states[ACPI_STATE_S5] = 1; | 
 | 913 | 		printk(" S5"); | 
 | 914 | 		pm_power_off_prepare = acpi_power_off_prepare; | 
 | 915 | 		pm_power_off = acpi_power_off; | 
 | 916 | 	} | 
 | 917 | 	printk(")\n"); | 
| Zhao Yakui | e49f711 | 2008-08-12 10:20:22 +0800 | [diff] [blame] | 918 | 	/* | 
 | 919 | 	 * Register the tts_notifier to reboot notifier list so that the _TTS | 
 | 920 | 	 * object can also be evaluated when the system enters S5. | 
 | 921 | 	 */ | 
 | 922 | 	register_reboot_notifier(&tts_notifier); | 
| Len Brown | 96f15ef | 2009-04-17 23:32:20 -0400 | [diff] [blame] | 923 | 	acpi_gts_bfs_check(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | 	return 0; | 
 | 925 | } |