xref: /linux/drivers/acpi/sleep.c (revision 26fcaf60fe3861409eb4c455c5c0d0f00f599b08)
1d08ca2caSLen Brown /*
2d08ca2caSLen Brown  * sleep.c - ACPI sleep support.
3d08ca2caSLen Brown  *
4d08ca2caSLen Brown  * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
5d08ca2caSLen Brown  * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
6d08ca2caSLen Brown  * Copyright (c) 2000-2003 Patrick Mochel
7d08ca2caSLen Brown  * Copyright (c) 2003 Open Source Development Lab
8d08ca2caSLen Brown  *
9d08ca2caSLen Brown  * This file is released under the GPLv2.
10d08ca2caSLen Brown  *
11d08ca2caSLen Brown  */
12d08ca2caSLen Brown 
13d08ca2caSLen Brown #include <linux/delay.h>
14d08ca2caSLen Brown #include <linux/irq.h>
15d08ca2caSLen Brown #include <linux/dmi.h>
16d08ca2caSLen Brown #include <linux/device.h>
17d08ca2caSLen Brown #include <linux/suspend.h>
18d08ca2caSLen Brown #include <linux/reboot.h>
19d08ca2caSLen Brown 
20d08ca2caSLen Brown #include <asm/io.h>
21d08ca2caSLen Brown 
22d08ca2caSLen Brown #include <acpi/acpi_bus.h>
23d08ca2caSLen Brown #include <acpi/acpi_drivers.h>
24e60cc7a6SBjorn Helgaas 
25e60cc7a6SBjorn Helgaas #include "internal.h"
26d08ca2caSLen Brown #include "sleep.h"
27d08ca2caSLen Brown 
2801eac60bSStephen Hemminger static u8 sleep_states[ACPI_S_STATE_COUNT];
29d08ca2caSLen Brown 
30d08ca2caSLen Brown static void acpi_sleep_tts_switch(u32 acpi_state)
31d08ca2caSLen Brown {
32d08ca2caSLen Brown 	union acpi_object in_arg = { ACPI_TYPE_INTEGER };
33d08ca2caSLen Brown 	struct acpi_object_list arg_list = { 1, &in_arg };
34d08ca2caSLen Brown 	acpi_status status = AE_OK;
35d08ca2caSLen Brown 
36d08ca2caSLen Brown 	in_arg.integer.value = acpi_state;
37d08ca2caSLen Brown 	status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
38d08ca2caSLen Brown 	if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
39d08ca2caSLen Brown 		/*
40d08ca2caSLen Brown 		 * OS can't evaluate the _TTS object correctly. Some warning
41d08ca2caSLen Brown 		 * message will be printed. But it won't break anything.
42d08ca2caSLen Brown 		 */
43d08ca2caSLen Brown 		printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
44d08ca2caSLen Brown 	}
45d08ca2caSLen Brown }
46d08ca2caSLen Brown 
47d08ca2caSLen Brown static int tts_notify_reboot(struct notifier_block *this,
48d08ca2caSLen Brown 			unsigned long code, void *x)
49d08ca2caSLen Brown {
50d08ca2caSLen Brown 	acpi_sleep_tts_switch(ACPI_STATE_S5);
51d08ca2caSLen Brown 	return NOTIFY_DONE;
52d08ca2caSLen Brown }
53d08ca2caSLen Brown 
54d08ca2caSLen Brown static struct notifier_block tts_notifier = {
55d08ca2caSLen Brown 	.notifier_call	= tts_notify_reboot,
56d08ca2caSLen Brown 	.next		= NULL,
57d08ca2caSLen Brown 	.priority	= 0,
58d08ca2caSLen Brown };
59d08ca2caSLen Brown 
60d08ca2caSLen Brown static int acpi_sleep_prepare(u32 acpi_state)
61d08ca2caSLen Brown {
62d08ca2caSLen Brown #ifdef CONFIG_ACPI_SLEEP
63d08ca2caSLen Brown 	/* do we have a wakeup address for S2 and S3? */
64d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S3) {
65d08ca2caSLen Brown 		if (!acpi_wakeup_address) {
66d08ca2caSLen Brown 			return -EFAULT;
67d08ca2caSLen Brown 		}
68d08ca2caSLen Brown 		acpi_set_firmware_waking_vector(
69d08ca2caSLen Brown 				(acpi_physical_address)acpi_wakeup_address);
70d08ca2caSLen Brown 
71d08ca2caSLen Brown 	}
72d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
73d08ca2caSLen Brown #endif
74d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
75d08ca2caSLen Brown 		acpi_state);
7678f5f023SRafael J. Wysocki 	acpi_enable_wakeup_devices(acpi_state);
77d08ca2caSLen Brown 	acpi_enter_sleep_state_prep(acpi_state);
78d08ca2caSLen Brown 	return 0;
79d08ca2caSLen Brown }
80d08ca2caSLen Brown 
81d08ca2caSLen Brown #ifdef CONFIG_ACPI_SLEEP
82091aad6aSJan Beulich static u32 acpi_target_sleep_state = ACPI_STATE_S0;
83091aad6aSJan Beulich 
84d7f0eea9SZhang Rui /*
8572ad5d77SRafael J. Wysocki  * The ACPI specification wants us to save NVS memory regions during hibernation
8672ad5d77SRafael J. Wysocki  * and to restore them during the subsequent resume.  Windows does that also for
8772ad5d77SRafael J. Wysocki  * suspend to RAM.  However, it is known that this mechanism does not work on
8872ad5d77SRafael J. Wysocki  * all machines, so we allow the user to disable it with the help of the
8972ad5d77SRafael J. Wysocki  * 'acpi_sleep=nonvs' kernel command line option.
9072ad5d77SRafael J. Wysocki  */
9172ad5d77SRafael J. Wysocki static bool nvs_nosave;
9272ad5d77SRafael J. Wysocki 
9372ad5d77SRafael J. Wysocki void __init acpi_nvs_nosave(void)
9472ad5d77SRafael J. Wysocki {
9572ad5d77SRafael J. Wysocki 	nvs_nosave = true;
9672ad5d77SRafael J. Wysocki }
9772ad5d77SRafael J. Wysocki 
9872ad5d77SRafael J. Wysocki /*
99d08ca2caSLen Brown  * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
100d08ca2caSLen Brown  * user to request that behavior by using the 'acpi_old_suspend_ordering'
101d08ca2caSLen Brown  * kernel command line option that causes the following variable to be set.
102d08ca2caSLen Brown  */
103d08ca2caSLen Brown static bool old_suspend_ordering;
104d08ca2caSLen Brown 
105d08ca2caSLen Brown void __init acpi_old_suspend_ordering(void)
106d08ca2caSLen Brown {
107d08ca2caSLen Brown 	old_suspend_ordering = true;
108d08ca2caSLen Brown }
109d08ca2caSLen Brown 
110d08ca2caSLen Brown /**
111d5a64513SRafael J. Wysocki  * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
112d08ca2caSLen Brown  */
113d5a64513SRafael J. Wysocki static int acpi_pm_freeze(void)
114d08ca2caSLen Brown {
115d08ca2caSLen Brown 	acpi_disable_all_gpes();
116d5a64513SRafael J. Wysocki 	acpi_os_wait_events_complete(NULL);
117fe955682SRafael J. Wysocki 	acpi_ec_block_transactions();
118d08ca2caSLen Brown 	return 0;
119d08ca2caSLen Brown }
120d08ca2caSLen Brown 
121d08ca2caSLen Brown /**
122c5f7a1bbSRafael J. Wysocki  * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
123c5f7a1bbSRafael J. Wysocki  */
124c5f7a1bbSRafael J. Wysocki static int acpi_pm_pre_suspend(void)
125c5f7a1bbSRafael J. Wysocki {
126c5f7a1bbSRafael J. Wysocki 	acpi_pm_freeze();
127*26fcaf60SJiri Slaby 	return suspend_nvs_save();
128c5f7a1bbSRafael J. Wysocki }
129c5f7a1bbSRafael J. Wysocki 
130c5f7a1bbSRafael J. Wysocki /**
131d08ca2caSLen Brown  *	__acpi_pm_prepare - Prepare the platform to enter the target state.
132d08ca2caSLen Brown  *
133d08ca2caSLen Brown  *	If necessary, set the firmware waking vector and do arch-specific
134d08ca2caSLen Brown  *	nastiness to get the wakeup code to the waking vector.
135d08ca2caSLen Brown  */
136d08ca2caSLen Brown static int __acpi_pm_prepare(void)
137d08ca2caSLen Brown {
138d08ca2caSLen Brown 	int error = acpi_sleep_prepare(acpi_target_sleep_state);
139d08ca2caSLen Brown 	if (error)
140d08ca2caSLen Brown 		acpi_target_sleep_state = ACPI_STATE_S0;
141c5f7a1bbSRafael J. Wysocki 
142d08ca2caSLen Brown 	return error;
143d08ca2caSLen Brown }
144d08ca2caSLen Brown 
145d08ca2caSLen Brown /**
146d08ca2caSLen Brown  *	acpi_pm_prepare - Prepare the platform to enter the target sleep
147d08ca2caSLen Brown  *		state and disable the GPEs.
148d08ca2caSLen Brown  */
149d08ca2caSLen Brown static int acpi_pm_prepare(void)
150d08ca2caSLen Brown {
151d08ca2caSLen Brown 	int error = __acpi_pm_prepare();
152d08ca2caSLen Brown 	if (!error)
153*26fcaf60SJiri Slaby 		error = acpi_pm_pre_suspend();
154d5a64513SRafael J. Wysocki 
155d08ca2caSLen Brown 	return error;
156d08ca2caSLen Brown }
157d08ca2caSLen Brown 
158d08ca2caSLen Brown /**
159d08ca2caSLen Brown  *	acpi_pm_finish - Instruct the platform to leave a sleep state.
160d08ca2caSLen Brown  *
161d08ca2caSLen Brown  *	This is called after we wake back up (or if entering the sleep state
162d08ca2caSLen Brown  *	failed).
163d08ca2caSLen Brown  */
164d08ca2caSLen Brown static void acpi_pm_finish(void)
165d08ca2caSLen Brown {
166d08ca2caSLen Brown 	u32 acpi_state = acpi_target_sleep_state;
167d08ca2caSLen Brown 
16842de5532SLen Brown 	acpi_ec_unblock_transactions();
1692a6b6976SMatthew Garrett 
170d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S0)
171d08ca2caSLen Brown 		return;
172d08ca2caSLen Brown 
173d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
174d08ca2caSLen Brown 		acpi_state);
17578f5f023SRafael J. Wysocki 	acpi_disable_wakeup_devices(acpi_state);
176d08ca2caSLen Brown 	acpi_leave_sleep_state(acpi_state);
177d08ca2caSLen Brown 
178d08ca2caSLen Brown 	/* reset firmware waking vector */
179d08ca2caSLen Brown 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
180d08ca2caSLen Brown 
181d08ca2caSLen Brown 	acpi_target_sleep_state = ACPI_STATE_S0;
182d08ca2caSLen Brown }
183d08ca2caSLen Brown 
184d08ca2caSLen Brown /**
185d08ca2caSLen Brown  *	acpi_pm_end - Finish up suspend sequence.
186d08ca2caSLen Brown  */
187d08ca2caSLen Brown static void acpi_pm_end(void)
188d08ca2caSLen Brown {
189e96c4b08SRafael J. Wysocki 	suspend_nvs_free();
190d08ca2caSLen Brown 	/*
191d08ca2caSLen Brown 	 * This is necessary in case acpi_pm_finish() is not called during a
192d08ca2caSLen Brown 	 * failing transition to a sleep state.
193d08ca2caSLen Brown 	 */
194d08ca2caSLen Brown 	acpi_target_sleep_state = ACPI_STATE_S0;
195d08ca2caSLen Brown 	acpi_sleep_tts_switch(acpi_target_sleep_state);
196d08ca2caSLen Brown }
197d08ca2caSLen Brown #else /* !CONFIG_ACPI_SLEEP */
198d08ca2caSLen Brown #define acpi_target_sleep_state	ACPI_STATE_S0
199d08ca2caSLen Brown #endif /* CONFIG_ACPI_SLEEP */
200d08ca2caSLen Brown 
201d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
202d08ca2caSLen Brown extern void do_suspend_lowlevel(void);
203d08ca2caSLen Brown 
204d08ca2caSLen Brown static u32 acpi_suspend_states[] = {
205d08ca2caSLen Brown 	[PM_SUSPEND_ON] = ACPI_STATE_S0,
206d08ca2caSLen Brown 	[PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
207d08ca2caSLen Brown 	[PM_SUSPEND_MEM] = ACPI_STATE_S3,
208d08ca2caSLen Brown 	[PM_SUSPEND_MAX] = ACPI_STATE_S5
209d08ca2caSLen Brown };
210d08ca2caSLen Brown 
211d08ca2caSLen Brown /**
212d08ca2caSLen Brown  *	acpi_suspend_begin - Set the target system sleep state to the state
213d08ca2caSLen Brown  *		associated with given @pm_state, if supported.
214d08ca2caSLen Brown  */
215d08ca2caSLen Brown static int acpi_suspend_begin(suspend_state_t pm_state)
216d08ca2caSLen Brown {
217d08ca2caSLen Brown 	u32 acpi_state = acpi_suspend_states[pm_state];
218d08ca2caSLen Brown 	int error = 0;
219d08ca2caSLen Brown 
22072ad5d77SRafael J. Wysocki 	error = nvs_nosave ? 0 : suspend_nvs_alloc();
2212a6b6976SMatthew Garrett 	if (error)
2222a6b6976SMatthew Garrett 		return error;
2232a6b6976SMatthew Garrett 
224d08ca2caSLen Brown 	if (sleep_states[acpi_state]) {
225d08ca2caSLen Brown 		acpi_target_sleep_state = acpi_state;
226d08ca2caSLen Brown 		acpi_sleep_tts_switch(acpi_target_sleep_state);
227d08ca2caSLen Brown 	} else {
228d08ca2caSLen Brown 		printk(KERN_ERR "ACPI does not support this state: %d\n",
229d08ca2caSLen Brown 			pm_state);
230d08ca2caSLen Brown 		error = -ENOSYS;
231d08ca2caSLen Brown 	}
232d08ca2caSLen Brown 	return error;
233d08ca2caSLen Brown }
234d08ca2caSLen Brown 
235d08ca2caSLen Brown /**
236d08ca2caSLen Brown  *	acpi_suspend_enter - Actually enter a sleep state.
237d08ca2caSLen Brown  *	@pm_state: ignored
238d08ca2caSLen Brown  *
239d08ca2caSLen Brown  *	Flush caches and go to sleep. For STR we have to call arch-specific
240d08ca2caSLen Brown  *	assembly, which in turn call acpi_enter_sleep_state().
241d08ca2caSLen Brown  *	It's unfortunate, but it works. Please fix if you're feeling frisky.
242d08ca2caSLen Brown  */
243d08ca2caSLen Brown static int acpi_suspend_enter(suspend_state_t pm_state)
244d08ca2caSLen Brown {
245d08ca2caSLen Brown 	acpi_status status = AE_OK;
246d08ca2caSLen Brown 	unsigned long flags = 0;
247d08ca2caSLen Brown 	u32 acpi_state = acpi_target_sleep_state;
248d08ca2caSLen Brown 
249d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
250d08ca2caSLen Brown 
251d08ca2caSLen Brown 	/* Do arch specific saving of state. */
252d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S3) {
253d08ca2caSLen Brown 		int error = acpi_save_state_mem();
254d08ca2caSLen Brown 
255d08ca2caSLen Brown 		if (error)
256d08ca2caSLen Brown 			return error;
257d08ca2caSLen Brown 	}
258d08ca2caSLen Brown 
259d08ca2caSLen Brown 	local_irq_save(flags);
260d08ca2caSLen Brown 	switch (acpi_state) {
261d08ca2caSLen Brown 	case ACPI_STATE_S1:
262d08ca2caSLen Brown 		barrier();
263d08ca2caSLen Brown 		status = acpi_enter_sleep_state(acpi_state);
264d08ca2caSLen Brown 		break;
265d08ca2caSLen Brown 
266d08ca2caSLen Brown 	case ACPI_STATE_S3:
267d08ca2caSLen Brown 		do_suspend_lowlevel();
268d08ca2caSLen Brown 		break;
269d08ca2caSLen Brown 	}
270d08ca2caSLen Brown 
271b6dacf63SMatthew Garrett 	/* This violates the spec but is required for bug compatibility. */
27250ffba1bSBob Moore 	acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
273d08ca2caSLen Brown 
274d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
275d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(acpi_state);
276d08ca2caSLen Brown 
277d08ca2caSLen Brown 	/* ACPI 3.0 specs (P62) says that it's the responsibility
278d08ca2caSLen Brown 	 * of the OSPM to clear the status bit [ implying that the
279d08ca2caSLen Brown 	 * POWER_BUTTON event should not reach userspace ]
280d08ca2caSLen Brown 	 */
281d08ca2caSLen Brown 	if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
282d08ca2caSLen Brown 		acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
283d08ca2caSLen Brown 
284d08ca2caSLen Brown 	/*
285d08ca2caSLen Brown 	 * Disable and clear GPE status before interrupt is enabled. Some GPEs
286d08ca2caSLen Brown 	 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
287d08ca2caSLen Brown 	 * acpi_leave_sleep_state will reenable specific GPEs later
288d08ca2caSLen Brown 	 */
289d08ca2caSLen Brown 	acpi_disable_all_gpes();
290d5a64513SRafael J. Wysocki 	/* Allow EC transactions to happen. */
291fe955682SRafael J. Wysocki 	acpi_ec_unblock_transactions_early();
292d08ca2caSLen Brown 
293d08ca2caSLen Brown 	local_irq_restore(flags);
294d08ca2caSLen Brown 	printk(KERN_DEBUG "Back to C!\n");
295d08ca2caSLen Brown 
296d08ca2caSLen Brown 	/* restore processor state */
297d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S3)
298d08ca2caSLen Brown 		acpi_restore_state_mem();
299d08ca2caSLen Brown 
3002a6b6976SMatthew Garrett 	suspend_nvs_restore();
3012a6b6976SMatthew Garrett 
302d08ca2caSLen Brown 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
303d08ca2caSLen Brown }
304d08ca2caSLen Brown 
305d08ca2caSLen Brown static int acpi_suspend_state_valid(suspend_state_t pm_state)
306d08ca2caSLen Brown {
307d08ca2caSLen Brown 	u32 acpi_state;
308d08ca2caSLen Brown 
309d08ca2caSLen Brown 	switch (pm_state) {
310d08ca2caSLen Brown 	case PM_SUSPEND_ON:
311d08ca2caSLen Brown 	case PM_SUSPEND_STANDBY:
312d08ca2caSLen Brown 	case PM_SUSPEND_MEM:
313d08ca2caSLen Brown 		acpi_state = acpi_suspend_states[pm_state];
314d08ca2caSLen Brown 
315d08ca2caSLen Brown 		return sleep_states[acpi_state];
316d08ca2caSLen Brown 	default:
317d08ca2caSLen Brown 		return 0;
318d08ca2caSLen Brown 	}
319d08ca2caSLen Brown }
320d08ca2caSLen Brown 
321d08ca2caSLen Brown static struct platform_suspend_ops acpi_suspend_ops = {
322d08ca2caSLen Brown 	.valid = acpi_suspend_state_valid,
323d08ca2caSLen Brown 	.begin = acpi_suspend_begin,
3246a7c7eafSRafael J. Wysocki 	.prepare_late = acpi_pm_prepare,
325d08ca2caSLen Brown 	.enter = acpi_suspend_enter,
326618d7fd0SRafael J. Wysocki 	.wake = acpi_pm_finish,
327d08ca2caSLen Brown 	.end = acpi_pm_end,
328d08ca2caSLen Brown };
329d08ca2caSLen Brown 
330d08ca2caSLen Brown /**
331d08ca2caSLen Brown  *	acpi_suspend_begin_old - Set the target system sleep state to the
332d08ca2caSLen Brown  *		state associated with given @pm_state, if supported, and
333d08ca2caSLen Brown  *		execute the _PTS control method.  This function is used if the
334d08ca2caSLen Brown  *		pre-ACPI 2.0 suspend ordering has been requested.
335d08ca2caSLen Brown  */
336d08ca2caSLen Brown static int acpi_suspend_begin_old(suspend_state_t pm_state)
337d08ca2caSLen Brown {
338d08ca2caSLen Brown 	int error = acpi_suspend_begin(pm_state);
339d08ca2caSLen Brown 	if (!error)
340d08ca2caSLen Brown 		error = __acpi_pm_prepare();
341c5f7a1bbSRafael J. Wysocki 
342d08ca2caSLen Brown 	return error;
343d08ca2caSLen Brown }
344d08ca2caSLen Brown 
345d08ca2caSLen Brown /*
346d08ca2caSLen Brown  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
347d08ca2caSLen Brown  * been requested.
348d08ca2caSLen Brown  */
349d08ca2caSLen Brown static struct platform_suspend_ops acpi_suspend_ops_old = {
350d08ca2caSLen Brown 	.valid = acpi_suspend_state_valid,
351d08ca2caSLen Brown 	.begin = acpi_suspend_begin_old,
352c5f7a1bbSRafael J. Wysocki 	.prepare_late = acpi_pm_pre_suspend,
353d08ca2caSLen Brown 	.enter = acpi_suspend_enter,
354618d7fd0SRafael J. Wysocki 	.wake = acpi_pm_finish,
355d08ca2caSLen Brown 	.end = acpi_pm_end,
356d08ca2caSLen Brown 	.recover = acpi_pm_finish,
357d08ca2caSLen Brown };
358d08ca2caSLen Brown 
359d08ca2caSLen Brown static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
360d08ca2caSLen Brown {
361d08ca2caSLen Brown 	old_suspend_ordering = true;
362d08ca2caSLen Brown 	return 0;
363d08ca2caSLen Brown }
364d08ca2caSLen Brown 
36553998648SRafael J. Wysocki static int __init init_nvs_nosave(const struct dmi_system_id *d)
36653998648SRafael J. Wysocki {
36753998648SRafael J. Wysocki 	acpi_nvs_nosave();
36853998648SRafael J. Wysocki 	return 0;
36953998648SRafael J. Wysocki }
37053998648SRafael J. Wysocki 
371d08ca2caSLen Brown static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
372d08ca2caSLen Brown 	{
373d08ca2caSLen Brown 	.callback = init_old_suspend_ordering,
374d08ca2caSLen Brown 	.ident = "Abit KN9 (nForce4 variant)",
375d08ca2caSLen Brown 	.matches = {
376d08ca2caSLen Brown 		DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
377d08ca2caSLen Brown 		DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
378d08ca2caSLen Brown 		},
379d08ca2caSLen Brown 	},
380d08ca2caSLen Brown 	{
381d08ca2caSLen Brown 	.callback = init_old_suspend_ordering,
382d08ca2caSLen Brown 	.ident = "HP xw4600 Workstation",
383d08ca2caSLen Brown 	.matches = {
384d08ca2caSLen Brown 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
385d08ca2caSLen Brown 		DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
386d08ca2caSLen Brown 		},
387d08ca2caSLen Brown 	},
388d08ca2caSLen Brown 	{
389a1404495SAndy Whitcroft 	.callback = init_old_suspend_ordering,
390a1404495SAndy Whitcroft 	.ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
391a1404495SAndy Whitcroft 	.matches = {
392a1404495SAndy Whitcroft 		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
393a1404495SAndy Whitcroft 		DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
394a1404495SAndy Whitcroft 		},
395a1404495SAndy Whitcroft 	},
39645e77988SZhang Rui 	{
3972a9ef8e1SZhao Yakui 	.callback = init_old_suspend_ordering,
3982a9ef8e1SZhao Yakui 	.ident = "Panasonic CF51-2L",
3992a9ef8e1SZhao Yakui 	.matches = {
4002a9ef8e1SZhao Yakui 		DMI_MATCH(DMI_BOARD_VENDOR,
4012a9ef8e1SZhao Yakui 				"Matsushita Electric Industrial Co.,Ltd."),
4022a9ef8e1SZhao Yakui 		DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
4032a9ef8e1SZhao Yakui 		},
4042a9ef8e1SZhao Yakui 	},
40553998648SRafael J. Wysocki 	{
40653998648SRafael J. Wysocki 	.callback = init_nvs_nosave,
40753998648SRafael J. Wysocki 	.ident = "Sony Vaio VGN-SR11M",
40853998648SRafael J. Wysocki 	.matches = {
40953998648SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
41053998648SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
41153998648SRafael J. Wysocki 		},
41253998648SRafael J. Wysocki 	},
41353998648SRafael J. Wysocki 	{
41453998648SRafael J. Wysocki 	.callback = init_nvs_nosave,
41553998648SRafael J. Wysocki 	.ident = "Everex StepNote Series",
41653998648SRafael J. Wysocki 	.matches = {
41753998648SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
41853998648SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
41953998648SRafael J. Wysocki 		},
42053998648SRafael J. Wysocki 	},
421af48931cSRafael J. Wysocki 	{
422af48931cSRafael J. Wysocki 	.callback = init_nvs_nosave,
423af48931cSRafael J. Wysocki 	.ident = "Sony Vaio VPCEB1Z1E",
424af48931cSRafael J. Wysocki 	.matches = {
425af48931cSRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
426af48931cSRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
427af48931cSRafael J. Wysocki 		},
428af48931cSRafael J. Wysocki 	},
429291a73c9SRafael J. Wysocki 	{
430291a73c9SRafael J. Wysocki 	.callback = init_nvs_nosave,
431291a73c9SRafael J. Wysocki 	.ident = "Sony Vaio VGN-NW130D",
432291a73c9SRafael J. Wysocki 	.matches = {
433291a73c9SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
434291a73c9SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
435291a73c9SRafael J. Wysocki 		},
436291a73c9SRafael J. Wysocki 	},
437d08ca2caSLen Brown 	{},
438d08ca2caSLen Brown };
439d08ca2caSLen Brown #endif /* CONFIG_SUSPEND */
440d08ca2caSLen Brown 
441d08ca2caSLen Brown #ifdef CONFIG_HIBERNATION
442d08ca2caSLen Brown static unsigned long s4_hardware_signature;
443d08ca2caSLen Brown static struct acpi_table_facs *facs;
444d08ca2caSLen Brown static bool nosigcheck;
445d08ca2caSLen Brown 
446d08ca2caSLen Brown void __init acpi_no_s4_hw_signature(void)
447d08ca2caSLen Brown {
448d08ca2caSLen Brown 	nosigcheck = true;
449d08ca2caSLen Brown }
450d08ca2caSLen Brown 
451d08ca2caSLen Brown static int acpi_hibernation_begin(void)
452d08ca2caSLen Brown {
453d08ca2caSLen Brown 	int error;
454d08ca2caSLen Brown 
45572ad5d77SRafael J. Wysocki 	error = nvs_nosave ? 0 : suspend_nvs_alloc();
456d08ca2caSLen Brown 	if (!error) {
457d08ca2caSLen Brown 		acpi_target_sleep_state = ACPI_STATE_S4;
458d08ca2caSLen Brown 		acpi_sleep_tts_switch(acpi_target_sleep_state);
459d08ca2caSLen Brown 	}
460d08ca2caSLen Brown 
461d08ca2caSLen Brown 	return error;
462d08ca2caSLen Brown }
463d08ca2caSLen Brown 
464d08ca2caSLen Brown static int acpi_hibernation_enter(void)
465d08ca2caSLen Brown {
466d08ca2caSLen Brown 	acpi_status status = AE_OK;
467d08ca2caSLen Brown 	unsigned long flags = 0;
468d08ca2caSLen Brown 
469d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
470d08ca2caSLen Brown 
471d08ca2caSLen Brown 	local_irq_save(flags);
472d08ca2caSLen Brown 	/* This shouldn't return.  If it returns, we have a problem */
473d08ca2caSLen Brown 	status = acpi_enter_sleep_state(ACPI_STATE_S4);
474d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
475d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(ACPI_STATE_S4);
476d08ca2caSLen Brown 	local_irq_restore(flags);
477d08ca2caSLen Brown 
478d08ca2caSLen Brown 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
479d08ca2caSLen Brown }
480d08ca2caSLen Brown 
481d08ca2caSLen Brown static void acpi_hibernation_leave(void)
482d08ca2caSLen Brown {
483d08ca2caSLen Brown 	/*
484d08ca2caSLen Brown 	 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
485d08ca2caSLen Brown 	 * enable it here.
486d08ca2caSLen Brown 	 */
487d08ca2caSLen Brown 	acpi_enable();
488d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
489d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(ACPI_STATE_S4);
490d08ca2caSLen Brown 	/* Check the hardware signature */
491d08ca2caSLen Brown 	if (facs && s4_hardware_signature != facs->hardware_signature) {
492d08ca2caSLen Brown 		printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
493d08ca2caSLen Brown 			"cannot resume!\n");
494d08ca2caSLen Brown 		panic("ACPI S4 hardware signature mismatch");
495d08ca2caSLen Brown 	}
496d08ca2caSLen Brown 	/* Restore the NVS memory area */
497dd4c4f17SMatthew Garrett 	suspend_nvs_restore();
498d5a64513SRafael J. Wysocki 	/* Allow EC transactions to happen. */
499fe955682SRafael J. Wysocki 	acpi_ec_unblock_transactions_early();
500d08ca2caSLen Brown }
501d08ca2caSLen Brown 
502d5a64513SRafael J. Wysocki static void acpi_pm_thaw(void)
503f6bb13aaSRafael J. Wysocki {
504fe955682SRafael J. Wysocki 	acpi_ec_unblock_transactions();
505d08ca2caSLen Brown 	acpi_enable_all_runtime_gpes();
506d08ca2caSLen Brown }
507d08ca2caSLen Brown 
508d08ca2caSLen Brown static struct platform_hibernation_ops acpi_hibernation_ops = {
509d08ca2caSLen Brown 	.begin = acpi_hibernation_begin,
510d08ca2caSLen Brown 	.end = acpi_pm_end,
511c5f7a1bbSRafael J. Wysocki 	.pre_snapshot = acpi_pm_prepare,
5122a6b6976SMatthew Garrett 	.finish = acpi_pm_finish,
513d08ca2caSLen Brown 	.prepare = acpi_pm_prepare,
514d08ca2caSLen Brown 	.enter = acpi_hibernation_enter,
515d08ca2caSLen Brown 	.leave = acpi_hibernation_leave,
516d5a64513SRafael J. Wysocki 	.pre_restore = acpi_pm_freeze,
517d5a64513SRafael J. Wysocki 	.restore_cleanup = acpi_pm_thaw,
518d08ca2caSLen Brown };
519d08ca2caSLen Brown 
520d08ca2caSLen Brown /**
521d08ca2caSLen Brown  *	acpi_hibernation_begin_old - Set the target system sleep state to
522d08ca2caSLen Brown  *		ACPI_STATE_S4 and execute the _PTS control method.  This
523d08ca2caSLen Brown  *		function is used if the pre-ACPI 2.0 suspend ordering has been
524d08ca2caSLen Brown  *		requested.
525d08ca2caSLen Brown  */
526d08ca2caSLen Brown static int acpi_hibernation_begin_old(void)
527d08ca2caSLen Brown {
528d08ca2caSLen Brown 	int error;
529d08ca2caSLen Brown 	/*
530d08ca2caSLen Brown 	 * The _TTS object should always be evaluated before the _PTS object.
531d08ca2caSLen Brown 	 * When the old_suspended_ordering is true, the _PTS object is
532d08ca2caSLen Brown 	 * evaluated in the acpi_sleep_prepare.
533d08ca2caSLen Brown 	 */
534d08ca2caSLen Brown 	acpi_sleep_tts_switch(ACPI_STATE_S4);
535d08ca2caSLen Brown 
536d08ca2caSLen Brown 	error = acpi_sleep_prepare(ACPI_STATE_S4);
537d08ca2caSLen Brown 
538d08ca2caSLen Brown 	if (!error) {
53972ad5d77SRafael J. Wysocki 		if (!nvs_nosave)
540dd4c4f17SMatthew Garrett 			error = suspend_nvs_alloc();
541d08ca2caSLen Brown 		if (!error)
542d08ca2caSLen Brown 			acpi_target_sleep_state = ACPI_STATE_S4;
543d08ca2caSLen Brown 	}
544d08ca2caSLen Brown 	return error;
545d08ca2caSLen Brown }
546d08ca2caSLen Brown 
547d08ca2caSLen Brown /*
548d08ca2caSLen Brown  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
549d08ca2caSLen Brown  * been requested.
550d08ca2caSLen Brown  */
551d08ca2caSLen Brown static struct platform_hibernation_ops acpi_hibernation_ops_old = {
552d08ca2caSLen Brown 	.begin = acpi_hibernation_begin_old,
553d08ca2caSLen Brown 	.end = acpi_pm_end,
554c5f7a1bbSRafael J. Wysocki 	.pre_snapshot = acpi_pm_pre_suspend,
555d5a64513SRafael J. Wysocki 	.prepare = acpi_pm_freeze,
5562a6b6976SMatthew Garrett 	.finish = acpi_pm_finish,
557d08ca2caSLen Brown 	.enter = acpi_hibernation_enter,
558d08ca2caSLen Brown 	.leave = acpi_hibernation_leave,
559d5a64513SRafael J. Wysocki 	.pre_restore = acpi_pm_freeze,
560d5a64513SRafael J. Wysocki 	.restore_cleanup = acpi_pm_thaw,
561d08ca2caSLen Brown 	.recover = acpi_pm_finish,
562d08ca2caSLen Brown };
563d08ca2caSLen Brown #endif /* CONFIG_HIBERNATION */
564d08ca2caSLen Brown 
565d08ca2caSLen Brown int acpi_suspend(u32 acpi_state)
566d08ca2caSLen Brown {
567d08ca2caSLen Brown 	suspend_state_t states[] = {
568d08ca2caSLen Brown 		[1] = PM_SUSPEND_STANDBY,
569d08ca2caSLen Brown 		[3] = PM_SUSPEND_MEM,
570d08ca2caSLen Brown 		[5] = PM_SUSPEND_MAX
571d08ca2caSLen Brown 	};
572d08ca2caSLen Brown 
573d08ca2caSLen Brown 	if (acpi_state < 6 && states[acpi_state])
574d08ca2caSLen Brown 		return pm_suspend(states[acpi_state]);
575d08ca2caSLen Brown 	if (acpi_state == 4)
576d08ca2caSLen Brown 		return hibernate();
577d08ca2caSLen Brown 	return -EINVAL;
578d08ca2caSLen Brown }
579d08ca2caSLen Brown 
580761afb86SRafael J. Wysocki #ifdef CONFIG_PM_OPS
581d08ca2caSLen Brown /**
582d08ca2caSLen Brown  *	acpi_pm_device_sleep_state - return preferred power state of ACPI device
583d08ca2caSLen Brown  *		in the system sleep state given by %acpi_target_sleep_state
584d08ca2caSLen Brown  *	@dev: device to examine; its driver model wakeup flags control
585d08ca2caSLen Brown  *		whether it should be able to wake up the system
586d08ca2caSLen Brown  *	@d_min_p: used to store the upper limit of allowed states range
587d08ca2caSLen Brown  *	Return value: preferred power state of the device on success, -ENODEV on
588d08ca2caSLen Brown  *		failure (ie. if there's no 'struct acpi_device' for @dev)
589d08ca2caSLen Brown  *
590d08ca2caSLen Brown  *	Find the lowest power (highest number) ACPI device power state that
591d08ca2caSLen Brown  *	device @dev can be in while the system is in the sleep state represented
592d08ca2caSLen Brown  *	by %acpi_target_sleep_state.  If @wake is nonzero, the device should be
593d08ca2caSLen Brown  *	able to wake up the system from this sleep state.  If @d_min_p is set,
594d08ca2caSLen Brown  *	the highest power (lowest number) device power state of @dev allowed
595d08ca2caSLen Brown  *	in this system sleep state is stored at the location pointed to by it.
596d08ca2caSLen Brown  *
597d08ca2caSLen Brown  *	The caller must ensure that @dev is valid before using this function.
598d08ca2caSLen Brown  *	The caller is also responsible for figuring out if the device is
599d08ca2caSLen Brown  *	supposed to be able to wake up the system and passing this information
600d08ca2caSLen Brown  *	via @wake.
601d08ca2caSLen Brown  */
602d08ca2caSLen Brown 
603d08ca2caSLen Brown int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
604d08ca2caSLen Brown {
605d08ca2caSLen Brown 	acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
606d08ca2caSLen Brown 	struct acpi_device *adev;
607d08ca2caSLen Brown 	char acpi_method[] = "_SxD";
608d08ca2caSLen Brown 	unsigned long long d_min, d_max;
609d08ca2caSLen Brown 
610d08ca2caSLen Brown 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
611d08ca2caSLen Brown 		printk(KERN_DEBUG "ACPI handle has no context!\n");
612d08ca2caSLen Brown 		return -ENODEV;
613d08ca2caSLen Brown 	}
614d08ca2caSLen Brown 
615d08ca2caSLen Brown 	acpi_method[2] = '0' + acpi_target_sleep_state;
616d08ca2caSLen Brown 	/*
617d08ca2caSLen Brown 	 * If the sleep state is S0, we will return D3, but if the device has
618d08ca2caSLen Brown 	 * _S0W, we will use the value from _S0W
619d08ca2caSLen Brown 	 */
620d08ca2caSLen Brown 	d_min = ACPI_STATE_D0;
621d08ca2caSLen Brown 	d_max = ACPI_STATE_D3;
622d08ca2caSLen Brown 
623d08ca2caSLen Brown 	/*
624d08ca2caSLen Brown 	 * If present, _SxD methods return the minimum D-state (highest power
625d08ca2caSLen Brown 	 * state) we can use for the corresponding S-states.  Otherwise, the
626d08ca2caSLen Brown 	 * minimum D-state is D0 (ACPI 3.x).
627d08ca2caSLen Brown 	 *
628d08ca2caSLen Brown 	 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
629d08ca2caSLen Brown 	 * provided -- that's our fault recovery, we ignore retval.
630d08ca2caSLen Brown 	 */
631d08ca2caSLen Brown 	if (acpi_target_sleep_state > ACPI_STATE_S0)
632d08ca2caSLen Brown 		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
633d08ca2caSLen Brown 
634d08ca2caSLen Brown 	/*
635d08ca2caSLen Brown 	 * If _PRW says we can wake up the system from the target sleep state,
636d08ca2caSLen Brown 	 * the D-state returned by _SxD is sufficient for that (we assume a
637d08ca2caSLen Brown 	 * wakeup-aware driver if wake is set).  Still, if _SxW exists
638d08ca2caSLen Brown 	 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
639d08ca2caSLen Brown 	 * can wake the system.  _S0W may be valid, too.
640d08ca2caSLen Brown 	 */
641d08ca2caSLen Brown 	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
642761afb86SRafael J. Wysocki 	    (device_may_wakeup(dev) &&
643d08ca2caSLen Brown 	     adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
644d08ca2caSLen Brown 		acpi_status status;
645d08ca2caSLen Brown 
646d08ca2caSLen Brown 		acpi_method[3] = 'W';
647d08ca2caSLen Brown 		status = acpi_evaluate_integer(handle, acpi_method, NULL,
648d08ca2caSLen Brown 						&d_max);
649d08ca2caSLen Brown 		if (ACPI_FAILURE(status)) {
650761afb86SRafael J. Wysocki 			if (acpi_target_sleep_state != ACPI_STATE_S0 ||
651761afb86SRafael J. Wysocki 			    status != AE_NOT_FOUND)
652d08ca2caSLen Brown 				d_max = d_min;
653d08ca2caSLen Brown 		} else if (d_max < d_min) {
654d08ca2caSLen Brown 			/* Warn the user of the broken DSDT */
655d08ca2caSLen Brown 			printk(KERN_WARNING "ACPI: Wrong value from %s\n",
656d08ca2caSLen Brown 				acpi_method);
657d08ca2caSLen Brown 			/* Sanitize it */
658d08ca2caSLen Brown 			d_min = d_max;
659d08ca2caSLen Brown 		}
660d08ca2caSLen Brown 	}
661d08ca2caSLen Brown 
662d08ca2caSLen Brown 	if (d_min_p)
663d08ca2caSLen Brown 		*d_min_p = d_min;
664d08ca2caSLen Brown 	return d_max;
665d08ca2caSLen Brown }
666761afb86SRafael J. Wysocki #endif /* CONFIG_PM_OPS */
667d08ca2caSLen Brown 
668761afb86SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
669d08ca2caSLen Brown /**
670d08ca2caSLen Brown  *	acpi_pm_device_sleep_wake - enable or disable the system wake-up
671d08ca2caSLen Brown  *                                  capability of given device
672d08ca2caSLen Brown  *	@dev: device to handle
673d08ca2caSLen Brown  *	@enable: 'true' - enable, 'false' - disable the wake-up capability
674d08ca2caSLen Brown  */
675d08ca2caSLen Brown int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
676d08ca2caSLen Brown {
677d08ca2caSLen Brown 	acpi_handle handle;
678d08ca2caSLen Brown 	struct acpi_device *adev;
679df8db91fSRafael J. Wysocki 	int error;
680d08ca2caSLen Brown 
6810baed8daSRafael J. Wysocki 	if (!device_can_wakeup(dev))
682d08ca2caSLen Brown 		return -EINVAL;
683d08ca2caSLen Brown 
684d08ca2caSLen Brown 	handle = DEVICE_ACPI_HANDLE(dev);
685d08ca2caSLen Brown 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
686df8db91fSRafael J. Wysocki 		dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
687d08ca2caSLen Brown 		return -ENODEV;
688d08ca2caSLen Brown 	}
689d08ca2caSLen Brown 
690e8b6f970SRafael J. Wysocki 	error = enable ?
691e8b6f970SRafael J. Wysocki 		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
692e8b6f970SRafael J. Wysocki 		acpi_disable_wakeup_device_power(adev);
693df8db91fSRafael J. Wysocki 	if (!error)
694df8db91fSRafael J. Wysocki 		dev_info(dev, "wake-up capability %s by ACPI\n",
695df8db91fSRafael J. Wysocki 				enable ? "enabled" : "disabled");
696df8db91fSRafael J. Wysocki 
697df8db91fSRafael J. Wysocki 	return error;
698d08ca2caSLen Brown }
699761afb86SRafael J. Wysocki #endif  /* CONFIG_PM_SLEEP */
700d08ca2caSLen Brown 
701d08ca2caSLen Brown static void acpi_power_off_prepare(void)
702d08ca2caSLen Brown {
703d08ca2caSLen Brown 	/* Prepare to power off the system */
704d08ca2caSLen Brown 	acpi_sleep_prepare(ACPI_STATE_S5);
705d08ca2caSLen Brown 	acpi_disable_all_gpes();
706d08ca2caSLen Brown }
707d08ca2caSLen Brown 
708d08ca2caSLen Brown static void acpi_power_off(void)
709d08ca2caSLen Brown {
710d08ca2caSLen Brown 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
7114d939155SFrank Seidel 	printk(KERN_DEBUG "%s called\n", __func__);
712d08ca2caSLen Brown 	local_irq_disable();
713d08ca2caSLen Brown 	acpi_enter_sleep_state(ACPI_STATE_S5);
714d08ca2caSLen Brown }
715d08ca2caSLen Brown 
71696f15efcSLen Brown /*
71796f15efcSLen Brown  * ACPI 2.0 created the optional _GTS and _BFS,
71896f15efcSLen Brown  * but industry adoption has been neither rapid nor broad.
71996f15efcSLen Brown  *
72096f15efcSLen Brown  * Linux gets into trouble when it executes poorly validated
72196f15efcSLen Brown  * paths through the BIOS, so disable _GTS and _BFS by default,
72296f15efcSLen Brown  * but do speak up and offer the option to enable them.
72396f15efcSLen Brown  */
72401eac60bSStephen Hemminger static void __init acpi_gts_bfs_check(void)
72596f15efcSLen Brown {
72696f15efcSLen Brown 	acpi_handle dummy;
72796f15efcSLen Brown 
72896f15efcSLen Brown 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
72996f15efcSLen Brown 	{
73096f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
73196f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
73296f15efcSLen Brown 			"please notify linux-acpi@vger.kernel.org\n");
73396f15efcSLen Brown 	}
73496f15efcSLen Brown 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
73596f15efcSLen Brown 	{
73696f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
73796f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
73896f15efcSLen Brown 			"please notify linux-acpi@vger.kernel.org\n");
73996f15efcSLen Brown 	}
74096f15efcSLen Brown }
74196f15efcSLen Brown 
742d08ca2caSLen Brown int __init acpi_sleep_init(void)
743d08ca2caSLen Brown {
744d08ca2caSLen Brown 	acpi_status status;
745d08ca2caSLen Brown 	u8 type_a, type_b;
746d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
747d08ca2caSLen Brown 	int i = 0;
748d08ca2caSLen Brown 
749d08ca2caSLen Brown 	dmi_check_system(acpisleep_dmi_table);
750d08ca2caSLen Brown #endif
751d08ca2caSLen Brown 
752d08ca2caSLen Brown 	if (acpi_disabled)
753d08ca2caSLen Brown 		return 0;
754d08ca2caSLen Brown 
755d08ca2caSLen Brown 	sleep_states[ACPI_STATE_S0] = 1;
756d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "(supports S0");
757d08ca2caSLen Brown 
758d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
759d08ca2caSLen Brown 	for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
760d08ca2caSLen Brown 		status = acpi_get_sleep_type_data(i, &type_a, &type_b);
761d08ca2caSLen Brown 		if (ACPI_SUCCESS(status)) {
762d08ca2caSLen Brown 			sleep_states[i] = 1;
763d08ca2caSLen Brown 			printk(" S%d", i);
764d08ca2caSLen Brown 		}
765d08ca2caSLen Brown 	}
766d08ca2caSLen Brown 
767d08ca2caSLen Brown 	suspend_set_ops(old_suspend_ordering ?
768d08ca2caSLen Brown 		&acpi_suspend_ops_old : &acpi_suspend_ops);
769d08ca2caSLen Brown #endif
770d08ca2caSLen Brown 
771d08ca2caSLen Brown #ifdef CONFIG_HIBERNATION
772d08ca2caSLen Brown 	status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
773d08ca2caSLen Brown 	if (ACPI_SUCCESS(status)) {
774d08ca2caSLen Brown 		hibernation_set_ops(old_suspend_ordering ?
775d08ca2caSLen Brown 			&acpi_hibernation_ops_old : &acpi_hibernation_ops);
776d08ca2caSLen Brown 		sleep_states[ACPI_STATE_S4] = 1;
777d08ca2caSLen Brown 		printk(" S4");
778d08ca2caSLen Brown 		if (!nosigcheck) {
779d08ca2caSLen Brown 			acpi_get_table(ACPI_SIG_FACS, 1,
780d08ca2caSLen Brown 				(struct acpi_table_header **)&facs);
781d08ca2caSLen Brown 			if (facs)
782d08ca2caSLen Brown 				s4_hardware_signature =
783d08ca2caSLen Brown 					facs->hardware_signature;
784d08ca2caSLen Brown 		}
785d08ca2caSLen Brown 	}
786d08ca2caSLen Brown #endif
787d08ca2caSLen Brown 	status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
788d08ca2caSLen Brown 	if (ACPI_SUCCESS(status)) {
789d08ca2caSLen Brown 		sleep_states[ACPI_STATE_S5] = 1;
790d08ca2caSLen Brown 		printk(" S5");
791d08ca2caSLen Brown 		pm_power_off_prepare = acpi_power_off_prepare;
792d08ca2caSLen Brown 		pm_power_off = acpi_power_off;
793d08ca2caSLen Brown 	}
794d08ca2caSLen Brown 	printk(")\n");
795d08ca2caSLen Brown 	/*
796d08ca2caSLen Brown 	 * Register the tts_notifier to reboot notifier list so that the _TTS
797d08ca2caSLen Brown 	 * object can also be evaluated when the system enters S5.
798d08ca2caSLen Brown 	 */
799d08ca2caSLen Brown 	register_reboot_notifier(&tts_notifier);
80096f15efcSLen Brown 	acpi_gts_bfs_check();
801d08ca2caSLen Brown 	return 0;
802d08ca2caSLen Brown }
803