xref: /linux/drivers/acpi/sleep.c (revision f1a2003e22f6b50ea21f7f4b38b38c5ebc9c8017)
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();
12726fcaf60SJiri 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)
15326fcaf60SJiri 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();
169d551d81dSRafael J. Wysocki 	suspend_nvs_free();
1702a6b6976SMatthew Garrett 
171d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S0)
172d08ca2caSLen Brown 		return;
173d08ca2caSLen Brown 
174d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
175d08ca2caSLen Brown 		acpi_state);
17678f5f023SRafael J. Wysocki 	acpi_disable_wakeup_devices(acpi_state);
177d08ca2caSLen Brown 	acpi_leave_sleep_state(acpi_state);
178d08ca2caSLen Brown 
179d08ca2caSLen Brown 	/* reset firmware waking vector */
180d08ca2caSLen Brown 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
181d08ca2caSLen Brown 
182d08ca2caSLen Brown 	acpi_target_sleep_state = ACPI_STATE_S0;
183d08ca2caSLen Brown }
184d08ca2caSLen Brown 
185d08ca2caSLen Brown /**
186d08ca2caSLen Brown  *	acpi_pm_end - Finish up suspend sequence.
187d08ca2caSLen Brown  */
188d08ca2caSLen Brown static void acpi_pm_end(void)
189d08ca2caSLen Brown {
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 static u32 acpi_suspend_states[] = {
203d08ca2caSLen Brown 	[PM_SUSPEND_ON] = ACPI_STATE_S0,
204d08ca2caSLen Brown 	[PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
205d08ca2caSLen Brown 	[PM_SUSPEND_MEM] = ACPI_STATE_S3,
206d08ca2caSLen Brown 	[PM_SUSPEND_MAX] = ACPI_STATE_S5
207d08ca2caSLen Brown };
208d08ca2caSLen Brown 
209d08ca2caSLen Brown /**
210d08ca2caSLen Brown  *	acpi_suspend_begin - Set the target system sleep state to the state
211d08ca2caSLen Brown  *		associated with given @pm_state, if supported.
212d08ca2caSLen Brown  */
213d08ca2caSLen Brown static int acpi_suspend_begin(suspend_state_t pm_state)
214d08ca2caSLen Brown {
215d08ca2caSLen Brown 	u32 acpi_state = acpi_suspend_states[pm_state];
216d08ca2caSLen Brown 	int error = 0;
217d08ca2caSLen Brown 
21872ad5d77SRafael J. Wysocki 	error = nvs_nosave ? 0 : suspend_nvs_alloc();
2192a6b6976SMatthew Garrett 	if (error)
2202a6b6976SMatthew Garrett 		return error;
2212a6b6976SMatthew Garrett 
222d08ca2caSLen Brown 	if (sleep_states[acpi_state]) {
223d08ca2caSLen Brown 		acpi_target_sleep_state = acpi_state;
224d08ca2caSLen Brown 		acpi_sleep_tts_switch(acpi_target_sleep_state);
225d08ca2caSLen Brown 	} else {
226d08ca2caSLen Brown 		printk(KERN_ERR "ACPI does not support this state: %d\n",
227d08ca2caSLen Brown 			pm_state);
228d08ca2caSLen Brown 		error = -ENOSYS;
229d08ca2caSLen Brown 	}
230d08ca2caSLen Brown 	return error;
231d08ca2caSLen Brown }
232d08ca2caSLen Brown 
233d08ca2caSLen Brown /**
234d08ca2caSLen Brown  *	acpi_suspend_enter - Actually enter a sleep state.
235d08ca2caSLen Brown  *	@pm_state: ignored
236d08ca2caSLen Brown  *
237d08ca2caSLen Brown  *	Flush caches and go to sleep. For STR we have to call arch-specific
238d08ca2caSLen Brown  *	assembly, which in turn call acpi_enter_sleep_state().
239d08ca2caSLen Brown  *	It's unfortunate, but it works. Please fix if you're feeling frisky.
240d08ca2caSLen Brown  */
241d08ca2caSLen Brown static int acpi_suspend_enter(suspend_state_t pm_state)
242d08ca2caSLen Brown {
243d08ca2caSLen Brown 	acpi_status status = AE_OK;
244d08ca2caSLen Brown 	u32 acpi_state = acpi_target_sleep_state;
245979f11b0SRafael J. Wysocki 	int error;
246d08ca2caSLen Brown 
247d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
248d08ca2caSLen Brown 
249d08ca2caSLen Brown 	switch (acpi_state) {
250d08ca2caSLen Brown 	case ACPI_STATE_S1:
251d08ca2caSLen Brown 		barrier();
252d08ca2caSLen Brown 		status = acpi_enter_sleep_state(acpi_state);
253d08ca2caSLen Brown 		break;
254d08ca2caSLen Brown 
255d08ca2caSLen Brown 	case ACPI_STATE_S3:
256*f1a2003eSRafael J. Wysocki 		error = acpi_suspend_lowlevel();
257979f11b0SRafael J. Wysocki 		if (error)
258979f11b0SRafael J. Wysocki 			return error;
2597a63f08bSRafael J. Wysocki 		pr_info(PREFIX "Low-level resume complete\n");
260d08ca2caSLen Brown 		break;
261d08ca2caSLen Brown 	}
262d08ca2caSLen Brown 
263b6dacf63SMatthew Garrett 	/* This violates the spec but is required for bug compatibility. */
26450ffba1bSBob Moore 	acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
265d08ca2caSLen Brown 
266d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
267d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(acpi_state);
268d08ca2caSLen Brown 
269d08ca2caSLen Brown 	/* ACPI 3.0 specs (P62) says that it's the responsibility
270d08ca2caSLen Brown 	 * of the OSPM to clear the status bit [ implying that the
271d08ca2caSLen Brown 	 * POWER_BUTTON event should not reach userspace ]
272d08ca2caSLen Brown 	 */
273d08ca2caSLen Brown 	if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
274d08ca2caSLen Brown 		acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
275d08ca2caSLen Brown 
276d08ca2caSLen Brown 	/*
277d08ca2caSLen Brown 	 * Disable and clear GPE status before interrupt is enabled. Some GPEs
278d08ca2caSLen Brown 	 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
279d08ca2caSLen Brown 	 * acpi_leave_sleep_state will reenable specific GPEs later
280d08ca2caSLen Brown 	 */
281d08ca2caSLen Brown 	acpi_disable_all_gpes();
282d5a64513SRafael J. Wysocki 	/* Allow EC transactions to happen. */
283fe955682SRafael J. Wysocki 	acpi_ec_unblock_transactions_early();
284d08ca2caSLen Brown 
2852a6b6976SMatthew Garrett 	suspend_nvs_restore();
2862a6b6976SMatthew Garrett 
287d08ca2caSLen Brown 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
288d08ca2caSLen Brown }
289d08ca2caSLen Brown 
290d08ca2caSLen Brown static int acpi_suspend_state_valid(suspend_state_t pm_state)
291d08ca2caSLen Brown {
292d08ca2caSLen Brown 	u32 acpi_state;
293d08ca2caSLen Brown 
294d08ca2caSLen Brown 	switch (pm_state) {
295d08ca2caSLen Brown 	case PM_SUSPEND_ON:
296d08ca2caSLen Brown 	case PM_SUSPEND_STANDBY:
297d08ca2caSLen Brown 	case PM_SUSPEND_MEM:
298d08ca2caSLen Brown 		acpi_state = acpi_suspend_states[pm_state];
299d08ca2caSLen Brown 
300d08ca2caSLen Brown 		return sleep_states[acpi_state];
301d08ca2caSLen Brown 	default:
302d08ca2caSLen Brown 		return 0;
303d08ca2caSLen Brown 	}
304d08ca2caSLen Brown }
305d08ca2caSLen Brown 
3062f55ac07SLionel Debroux static const struct platform_suspend_ops acpi_suspend_ops = {
307d08ca2caSLen Brown 	.valid = acpi_suspend_state_valid,
308d08ca2caSLen Brown 	.begin = acpi_suspend_begin,
3096a7c7eafSRafael J. Wysocki 	.prepare_late = acpi_pm_prepare,
310d08ca2caSLen Brown 	.enter = acpi_suspend_enter,
311618d7fd0SRafael J. Wysocki 	.wake = acpi_pm_finish,
312d08ca2caSLen Brown 	.end = acpi_pm_end,
313d08ca2caSLen Brown };
314d08ca2caSLen Brown 
315d08ca2caSLen Brown /**
316d08ca2caSLen Brown  *	acpi_suspend_begin_old - Set the target system sleep state to the
317d08ca2caSLen Brown  *		state associated with given @pm_state, if supported, and
318d08ca2caSLen Brown  *		execute the _PTS control method.  This function is used if the
319d08ca2caSLen Brown  *		pre-ACPI 2.0 suspend ordering has been requested.
320d08ca2caSLen Brown  */
321d08ca2caSLen Brown static int acpi_suspend_begin_old(suspend_state_t pm_state)
322d08ca2caSLen Brown {
323d08ca2caSLen Brown 	int error = acpi_suspend_begin(pm_state);
324d08ca2caSLen Brown 	if (!error)
325d08ca2caSLen Brown 		error = __acpi_pm_prepare();
326c5f7a1bbSRafael J. Wysocki 
327d08ca2caSLen Brown 	return error;
328d08ca2caSLen Brown }
329d08ca2caSLen Brown 
330d08ca2caSLen Brown /*
331d08ca2caSLen Brown  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
332d08ca2caSLen Brown  * been requested.
333d08ca2caSLen Brown  */
3342f55ac07SLionel Debroux static const struct platform_suspend_ops acpi_suspend_ops_old = {
335d08ca2caSLen Brown 	.valid = acpi_suspend_state_valid,
336d08ca2caSLen Brown 	.begin = acpi_suspend_begin_old,
337c5f7a1bbSRafael J. Wysocki 	.prepare_late = acpi_pm_pre_suspend,
338d08ca2caSLen Brown 	.enter = acpi_suspend_enter,
339618d7fd0SRafael J. Wysocki 	.wake = acpi_pm_finish,
340d08ca2caSLen Brown 	.end = acpi_pm_end,
341d08ca2caSLen Brown 	.recover = acpi_pm_finish,
342d08ca2caSLen Brown };
343d08ca2caSLen Brown 
344d08ca2caSLen Brown static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
345d08ca2caSLen Brown {
346d08ca2caSLen Brown 	old_suspend_ordering = true;
347d08ca2caSLen Brown 	return 0;
348d08ca2caSLen Brown }
349d08ca2caSLen Brown 
35053998648SRafael J. Wysocki static int __init init_nvs_nosave(const struct dmi_system_id *d)
35153998648SRafael J. Wysocki {
35253998648SRafael J. Wysocki 	acpi_nvs_nosave();
35353998648SRafael J. Wysocki 	return 0;
35453998648SRafael J. Wysocki }
35553998648SRafael J. Wysocki 
356d08ca2caSLen Brown static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
357d08ca2caSLen Brown 	{
358d08ca2caSLen Brown 	.callback = init_old_suspend_ordering,
359d08ca2caSLen Brown 	.ident = "Abit KN9 (nForce4 variant)",
360d08ca2caSLen Brown 	.matches = {
361d08ca2caSLen Brown 		DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
362d08ca2caSLen Brown 		DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
363d08ca2caSLen Brown 		},
364d08ca2caSLen Brown 	},
365d08ca2caSLen Brown 	{
366d08ca2caSLen Brown 	.callback = init_old_suspend_ordering,
367d08ca2caSLen Brown 	.ident = "HP xw4600 Workstation",
368d08ca2caSLen Brown 	.matches = {
369d08ca2caSLen Brown 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
370d08ca2caSLen Brown 		DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
371d08ca2caSLen Brown 		},
372d08ca2caSLen Brown 	},
373d08ca2caSLen Brown 	{
374a1404495SAndy Whitcroft 	.callback = init_old_suspend_ordering,
375a1404495SAndy Whitcroft 	.ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
376a1404495SAndy Whitcroft 	.matches = {
377a1404495SAndy Whitcroft 		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
378a1404495SAndy Whitcroft 		DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
379a1404495SAndy Whitcroft 		},
380a1404495SAndy Whitcroft 	},
38145e77988SZhang Rui 	{
3822a9ef8e1SZhao Yakui 	.callback = init_old_suspend_ordering,
3832a9ef8e1SZhao Yakui 	.ident = "Panasonic CF51-2L",
3842a9ef8e1SZhao Yakui 	.matches = {
3852a9ef8e1SZhao Yakui 		DMI_MATCH(DMI_BOARD_VENDOR,
3862a9ef8e1SZhao Yakui 				"Matsushita Electric Industrial Co.,Ltd."),
3872a9ef8e1SZhao Yakui 		DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
3882a9ef8e1SZhao Yakui 		},
3892a9ef8e1SZhao Yakui 	},
39053998648SRafael J. Wysocki 	{
39153998648SRafael J. Wysocki 	.callback = init_nvs_nosave,
39253998648SRafael J. Wysocki 	.ident = "Sony Vaio VGN-SR11M",
39353998648SRafael J. Wysocki 	.matches = {
39453998648SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
39553998648SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
39653998648SRafael J. Wysocki 		},
39753998648SRafael J. Wysocki 	},
39853998648SRafael J. Wysocki 	{
39953998648SRafael J. Wysocki 	.callback = init_nvs_nosave,
40053998648SRafael J. Wysocki 	.ident = "Everex StepNote Series",
40153998648SRafael J. Wysocki 	.matches = {
40253998648SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
40353998648SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
40453998648SRafael J. Wysocki 		},
40553998648SRafael J. Wysocki 	},
406af48931cSRafael J. Wysocki 	{
407af48931cSRafael J. Wysocki 	.callback = init_nvs_nosave,
408af48931cSRafael J. Wysocki 	.ident = "Sony Vaio VPCEB1Z1E",
409af48931cSRafael J. Wysocki 	.matches = {
410af48931cSRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
411af48931cSRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
412af48931cSRafael J. Wysocki 		},
413af48931cSRafael J. Wysocki 	},
414291a73c9SRafael J. Wysocki 	{
415291a73c9SRafael J. Wysocki 	.callback = init_nvs_nosave,
416291a73c9SRafael J. Wysocki 	.ident = "Sony Vaio VGN-NW130D",
417291a73c9SRafael J. Wysocki 	.matches = {
418291a73c9SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
419291a73c9SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
420291a73c9SRafael J. Wysocki 		},
421291a73c9SRafael J. Wysocki 	},
4227b330707SRafael J. Wysocki 	{
4237b330707SRafael J. Wysocki 	.callback = init_nvs_nosave,
4247b330707SRafael J. Wysocki 	.ident = "Averatec AV1020-ED2",
4257b330707SRafael J. Wysocki 	.matches = {
4267b330707SRafael J. Wysocki 		DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
4277b330707SRafael J. Wysocki 		DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
4287b330707SRafael J. Wysocki 		},
4297b330707SRafael J. Wysocki 	},
430d08ca2caSLen Brown 	{},
431d08ca2caSLen Brown };
432d08ca2caSLen Brown #endif /* CONFIG_SUSPEND */
433d08ca2caSLen Brown 
434d08ca2caSLen Brown #ifdef CONFIG_HIBERNATION
435d08ca2caSLen Brown static unsigned long s4_hardware_signature;
436d08ca2caSLen Brown static struct acpi_table_facs *facs;
437d08ca2caSLen Brown static bool nosigcheck;
438d08ca2caSLen Brown 
439d08ca2caSLen Brown void __init acpi_no_s4_hw_signature(void)
440d08ca2caSLen Brown {
441d08ca2caSLen Brown 	nosigcheck = true;
442d08ca2caSLen Brown }
443d08ca2caSLen Brown 
444d08ca2caSLen Brown static int acpi_hibernation_begin(void)
445d08ca2caSLen Brown {
446d08ca2caSLen Brown 	int error;
447d08ca2caSLen Brown 
44872ad5d77SRafael J. Wysocki 	error = nvs_nosave ? 0 : suspend_nvs_alloc();
449d08ca2caSLen Brown 	if (!error) {
450d08ca2caSLen Brown 		acpi_target_sleep_state = ACPI_STATE_S4;
451d08ca2caSLen Brown 		acpi_sleep_tts_switch(acpi_target_sleep_state);
452d08ca2caSLen Brown 	}
453d08ca2caSLen Brown 
454d08ca2caSLen Brown 	return error;
455d08ca2caSLen Brown }
456d08ca2caSLen Brown 
457d08ca2caSLen Brown static int acpi_hibernation_enter(void)
458d08ca2caSLen Brown {
459d08ca2caSLen Brown 	acpi_status status = AE_OK;
460d08ca2caSLen Brown 	unsigned long flags = 0;
461d08ca2caSLen Brown 
462d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
463d08ca2caSLen Brown 
464d08ca2caSLen Brown 	local_irq_save(flags);
465d08ca2caSLen Brown 	/* This shouldn't return.  If it returns, we have a problem */
466d08ca2caSLen Brown 	status = acpi_enter_sleep_state(ACPI_STATE_S4);
467d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
468d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(ACPI_STATE_S4);
469d08ca2caSLen Brown 	local_irq_restore(flags);
470d08ca2caSLen Brown 
471d08ca2caSLen Brown 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
472d08ca2caSLen Brown }
473d08ca2caSLen Brown 
474d08ca2caSLen Brown static void acpi_hibernation_leave(void)
475d08ca2caSLen Brown {
476d08ca2caSLen Brown 	/*
477d08ca2caSLen Brown 	 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
478d08ca2caSLen Brown 	 * enable it here.
479d08ca2caSLen Brown 	 */
480d08ca2caSLen Brown 	acpi_enable();
481d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
482d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(ACPI_STATE_S4);
483d08ca2caSLen Brown 	/* Check the hardware signature */
484d08ca2caSLen Brown 	if (facs && s4_hardware_signature != facs->hardware_signature) {
485d08ca2caSLen Brown 		printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
486d08ca2caSLen Brown 			"cannot resume!\n");
487d08ca2caSLen Brown 		panic("ACPI S4 hardware signature mismatch");
488d08ca2caSLen Brown 	}
489d08ca2caSLen Brown 	/* Restore the NVS memory area */
490dd4c4f17SMatthew Garrett 	suspend_nvs_restore();
491d5a64513SRafael J. Wysocki 	/* Allow EC transactions to happen. */
492fe955682SRafael J. Wysocki 	acpi_ec_unblock_transactions_early();
493d08ca2caSLen Brown }
494d08ca2caSLen Brown 
495d5a64513SRafael J. Wysocki static void acpi_pm_thaw(void)
496f6bb13aaSRafael J. Wysocki {
497fe955682SRafael J. Wysocki 	acpi_ec_unblock_transactions();
498d08ca2caSLen Brown 	acpi_enable_all_runtime_gpes();
499d08ca2caSLen Brown }
500d08ca2caSLen Brown 
501073ef1f6SLionel Debroux static const struct platform_hibernation_ops acpi_hibernation_ops = {
502d08ca2caSLen Brown 	.begin = acpi_hibernation_begin,
503d08ca2caSLen Brown 	.end = acpi_pm_end,
504c5f7a1bbSRafael J. Wysocki 	.pre_snapshot = acpi_pm_prepare,
5052a6b6976SMatthew Garrett 	.finish = acpi_pm_finish,
506d08ca2caSLen Brown 	.prepare = acpi_pm_prepare,
507d08ca2caSLen Brown 	.enter = acpi_hibernation_enter,
508d08ca2caSLen Brown 	.leave = acpi_hibernation_leave,
509d5a64513SRafael J. Wysocki 	.pre_restore = acpi_pm_freeze,
510d5a64513SRafael J. Wysocki 	.restore_cleanup = acpi_pm_thaw,
511d08ca2caSLen Brown };
512d08ca2caSLen Brown 
513d08ca2caSLen Brown /**
514d08ca2caSLen Brown  *	acpi_hibernation_begin_old - Set the target system sleep state to
515d08ca2caSLen Brown  *		ACPI_STATE_S4 and execute the _PTS control method.  This
516d08ca2caSLen Brown  *		function is used if the pre-ACPI 2.0 suspend ordering has been
517d08ca2caSLen Brown  *		requested.
518d08ca2caSLen Brown  */
519d08ca2caSLen Brown static int acpi_hibernation_begin_old(void)
520d08ca2caSLen Brown {
521d08ca2caSLen Brown 	int error;
522d08ca2caSLen Brown 	/*
523d08ca2caSLen Brown 	 * The _TTS object should always be evaluated before the _PTS object.
524d08ca2caSLen Brown 	 * When the old_suspended_ordering is true, the _PTS object is
525d08ca2caSLen Brown 	 * evaluated in the acpi_sleep_prepare.
526d08ca2caSLen Brown 	 */
527d08ca2caSLen Brown 	acpi_sleep_tts_switch(ACPI_STATE_S4);
528d08ca2caSLen Brown 
529d08ca2caSLen Brown 	error = acpi_sleep_prepare(ACPI_STATE_S4);
530d08ca2caSLen Brown 
531d08ca2caSLen Brown 	if (!error) {
53272ad5d77SRafael J. Wysocki 		if (!nvs_nosave)
533dd4c4f17SMatthew Garrett 			error = suspend_nvs_alloc();
534d08ca2caSLen Brown 		if (!error)
535d08ca2caSLen Brown 			acpi_target_sleep_state = ACPI_STATE_S4;
536d08ca2caSLen Brown 	}
537d08ca2caSLen Brown 	return error;
538d08ca2caSLen Brown }
539d08ca2caSLen Brown 
540d08ca2caSLen Brown /*
541d08ca2caSLen Brown  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
542d08ca2caSLen Brown  * been requested.
543d08ca2caSLen Brown  */
544073ef1f6SLionel Debroux static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
545d08ca2caSLen Brown 	.begin = acpi_hibernation_begin_old,
546d08ca2caSLen Brown 	.end = acpi_pm_end,
547c5f7a1bbSRafael J. Wysocki 	.pre_snapshot = acpi_pm_pre_suspend,
548d5a64513SRafael J. Wysocki 	.prepare = acpi_pm_freeze,
5492a6b6976SMatthew Garrett 	.finish = acpi_pm_finish,
550d08ca2caSLen Brown 	.enter = acpi_hibernation_enter,
551d08ca2caSLen Brown 	.leave = acpi_hibernation_leave,
552d5a64513SRafael J. Wysocki 	.pre_restore = acpi_pm_freeze,
553d5a64513SRafael J. Wysocki 	.restore_cleanup = acpi_pm_thaw,
554d08ca2caSLen Brown 	.recover = acpi_pm_finish,
555d08ca2caSLen Brown };
556d08ca2caSLen Brown #endif /* CONFIG_HIBERNATION */
557d08ca2caSLen Brown 
558d08ca2caSLen Brown int acpi_suspend(u32 acpi_state)
559d08ca2caSLen Brown {
560d08ca2caSLen Brown 	suspend_state_t states[] = {
561d08ca2caSLen Brown 		[1] = PM_SUSPEND_STANDBY,
562d08ca2caSLen Brown 		[3] = PM_SUSPEND_MEM,
563d08ca2caSLen Brown 		[5] = PM_SUSPEND_MAX
564d08ca2caSLen Brown 	};
565d08ca2caSLen Brown 
566d08ca2caSLen Brown 	if (acpi_state < 6 && states[acpi_state])
567d08ca2caSLen Brown 		return pm_suspend(states[acpi_state]);
568d08ca2caSLen Brown 	if (acpi_state == 4)
569d08ca2caSLen Brown 		return hibernate();
570d08ca2caSLen Brown 	return -EINVAL;
571d08ca2caSLen Brown }
572d08ca2caSLen Brown 
573761afb86SRafael J. Wysocki #ifdef CONFIG_PM_OPS
574d08ca2caSLen Brown /**
575d08ca2caSLen Brown  *	acpi_pm_device_sleep_state - return preferred power state of ACPI device
576d08ca2caSLen Brown  *		in the system sleep state given by %acpi_target_sleep_state
577d08ca2caSLen Brown  *	@dev: device to examine; its driver model wakeup flags control
578d08ca2caSLen Brown  *		whether it should be able to wake up the system
579d08ca2caSLen Brown  *	@d_min_p: used to store the upper limit of allowed states range
580d08ca2caSLen Brown  *	Return value: preferred power state of the device on success, -ENODEV on
581d08ca2caSLen Brown  *		failure (ie. if there's no 'struct acpi_device' for @dev)
582d08ca2caSLen Brown  *
583d08ca2caSLen Brown  *	Find the lowest power (highest number) ACPI device power state that
584d08ca2caSLen Brown  *	device @dev can be in while the system is in the sleep state represented
585d08ca2caSLen Brown  *	by %acpi_target_sleep_state.  If @wake is nonzero, the device should be
586d08ca2caSLen Brown  *	able to wake up the system from this sleep state.  If @d_min_p is set,
587d08ca2caSLen Brown  *	the highest power (lowest number) device power state of @dev allowed
588d08ca2caSLen Brown  *	in this system sleep state is stored at the location pointed to by it.
589d08ca2caSLen Brown  *
590d08ca2caSLen Brown  *	The caller must ensure that @dev is valid before using this function.
591d08ca2caSLen Brown  *	The caller is also responsible for figuring out if the device is
592d08ca2caSLen Brown  *	supposed to be able to wake up the system and passing this information
593d08ca2caSLen Brown  *	via @wake.
594d08ca2caSLen Brown  */
595d08ca2caSLen Brown 
596d08ca2caSLen Brown int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
597d08ca2caSLen Brown {
598d08ca2caSLen Brown 	acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
599d08ca2caSLen Brown 	struct acpi_device *adev;
600d08ca2caSLen Brown 	char acpi_method[] = "_SxD";
601d08ca2caSLen Brown 	unsigned long long d_min, d_max;
602d08ca2caSLen Brown 
603d08ca2caSLen Brown 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
604d08ca2caSLen Brown 		printk(KERN_DEBUG "ACPI handle has no context!\n");
605d08ca2caSLen Brown 		return -ENODEV;
606d08ca2caSLen Brown 	}
607d08ca2caSLen Brown 
608d08ca2caSLen Brown 	acpi_method[2] = '0' + acpi_target_sleep_state;
609d08ca2caSLen Brown 	/*
610d08ca2caSLen Brown 	 * If the sleep state is S0, we will return D3, but if the device has
611d08ca2caSLen Brown 	 * _S0W, we will use the value from _S0W
612d08ca2caSLen Brown 	 */
613d08ca2caSLen Brown 	d_min = ACPI_STATE_D0;
614d08ca2caSLen Brown 	d_max = ACPI_STATE_D3;
615d08ca2caSLen Brown 
616d08ca2caSLen Brown 	/*
617d08ca2caSLen Brown 	 * If present, _SxD methods return the minimum D-state (highest power
618d08ca2caSLen Brown 	 * state) we can use for the corresponding S-states.  Otherwise, the
619d08ca2caSLen Brown 	 * minimum D-state is D0 (ACPI 3.x).
620d08ca2caSLen Brown 	 *
621d08ca2caSLen Brown 	 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
622d08ca2caSLen Brown 	 * provided -- that's our fault recovery, we ignore retval.
623d08ca2caSLen Brown 	 */
624d08ca2caSLen Brown 	if (acpi_target_sleep_state > ACPI_STATE_S0)
625d08ca2caSLen Brown 		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
626d08ca2caSLen Brown 
627d08ca2caSLen Brown 	/*
628d08ca2caSLen Brown 	 * If _PRW says we can wake up the system from the target sleep state,
629d08ca2caSLen Brown 	 * the D-state returned by _SxD is sufficient for that (we assume a
630d08ca2caSLen Brown 	 * wakeup-aware driver if wake is set).  Still, if _SxW exists
631d08ca2caSLen Brown 	 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
632d08ca2caSLen Brown 	 * can wake the system.  _S0W may be valid, too.
633d08ca2caSLen Brown 	 */
634d08ca2caSLen Brown 	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
635761afb86SRafael J. Wysocki 	    (device_may_wakeup(dev) &&
636d08ca2caSLen Brown 	     adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
637d08ca2caSLen Brown 		acpi_status status;
638d08ca2caSLen Brown 
639d08ca2caSLen Brown 		acpi_method[3] = 'W';
640d08ca2caSLen Brown 		status = acpi_evaluate_integer(handle, acpi_method, NULL,
641d08ca2caSLen Brown 						&d_max);
642d08ca2caSLen Brown 		if (ACPI_FAILURE(status)) {
643761afb86SRafael J. Wysocki 			if (acpi_target_sleep_state != ACPI_STATE_S0 ||
644761afb86SRafael J. Wysocki 			    status != AE_NOT_FOUND)
645d08ca2caSLen Brown 				d_max = d_min;
646d08ca2caSLen Brown 		} else if (d_max < d_min) {
647d08ca2caSLen Brown 			/* Warn the user of the broken DSDT */
648d08ca2caSLen Brown 			printk(KERN_WARNING "ACPI: Wrong value from %s\n",
649d08ca2caSLen Brown 				acpi_method);
650d08ca2caSLen Brown 			/* Sanitize it */
651d08ca2caSLen Brown 			d_min = d_max;
652d08ca2caSLen Brown 		}
653d08ca2caSLen Brown 	}
654d08ca2caSLen Brown 
655d08ca2caSLen Brown 	if (d_min_p)
656d08ca2caSLen Brown 		*d_min_p = d_min;
657d08ca2caSLen Brown 	return d_max;
658d08ca2caSLen Brown }
659761afb86SRafael J. Wysocki #endif /* CONFIG_PM_OPS */
660d08ca2caSLen Brown 
661761afb86SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
662d08ca2caSLen Brown /**
663d08ca2caSLen Brown  *	acpi_pm_device_sleep_wake - enable or disable the system wake-up
664d08ca2caSLen Brown  *                                  capability of given device
665d08ca2caSLen Brown  *	@dev: device to handle
666d08ca2caSLen Brown  *	@enable: 'true' - enable, 'false' - disable the wake-up capability
667d08ca2caSLen Brown  */
668d08ca2caSLen Brown int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
669d08ca2caSLen Brown {
670d08ca2caSLen Brown 	acpi_handle handle;
671d08ca2caSLen Brown 	struct acpi_device *adev;
672df8db91fSRafael J. Wysocki 	int error;
673d08ca2caSLen Brown 
6740baed8daSRafael J. Wysocki 	if (!device_can_wakeup(dev))
675d08ca2caSLen Brown 		return -EINVAL;
676d08ca2caSLen Brown 
677d08ca2caSLen Brown 	handle = DEVICE_ACPI_HANDLE(dev);
678d08ca2caSLen Brown 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
679df8db91fSRafael J. Wysocki 		dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
680d08ca2caSLen Brown 		return -ENODEV;
681d08ca2caSLen Brown 	}
682d08ca2caSLen Brown 
683e8b6f970SRafael J. Wysocki 	error = enable ?
684e8b6f970SRafael J. Wysocki 		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
685e8b6f970SRafael J. Wysocki 		acpi_disable_wakeup_device_power(adev);
686df8db91fSRafael J. Wysocki 	if (!error)
687df8db91fSRafael J. Wysocki 		dev_info(dev, "wake-up capability %s by ACPI\n",
688df8db91fSRafael J. Wysocki 				enable ? "enabled" : "disabled");
689df8db91fSRafael J. Wysocki 
690df8db91fSRafael J. Wysocki 	return error;
691d08ca2caSLen Brown }
692761afb86SRafael J. Wysocki #endif  /* CONFIG_PM_SLEEP */
693d08ca2caSLen Brown 
694d08ca2caSLen Brown static void acpi_power_off_prepare(void)
695d08ca2caSLen Brown {
696d08ca2caSLen Brown 	/* Prepare to power off the system */
697d08ca2caSLen Brown 	acpi_sleep_prepare(ACPI_STATE_S5);
698d08ca2caSLen Brown 	acpi_disable_all_gpes();
699d08ca2caSLen Brown }
700d08ca2caSLen Brown 
701d08ca2caSLen Brown static void acpi_power_off(void)
702d08ca2caSLen Brown {
703d08ca2caSLen Brown 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
7044d939155SFrank Seidel 	printk(KERN_DEBUG "%s called\n", __func__);
705d08ca2caSLen Brown 	local_irq_disable();
706d08ca2caSLen Brown 	acpi_enter_sleep_state(ACPI_STATE_S5);
707d08ca2caSLen Brown }
708d08ca2caSLen Brown 
70996f15efcSLen Brown /*
71096f15efcSLen Brown  * ACPI 2.0 created the optional _GTS and _BFS,
71196f15efcSLen Brown  * but industry adoption has been neither rapid nor broad.
71296f15efcSLen Brown  *
71396f15efcSLen Brown  * Linux gets into trouble when it executes poorly validated
71496f15efcSLen Brown  * paths through the BIOS, so disable _GTS and _BFS by default,
71596f15efcSLen Brown  * but do speak up and offer the option to enable them.
71696f15efcSLen Brown  */
71701eac60bSStephen Hemminger static void __init acpi_gts_bfs_check(void)
71896f15efcSLen Brown {
71996f15efcSLen Brown 	acpi_handle dummy;
72096f15efcSLen Brown 
72196f15efcSLen Brown 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
72296f15efcSLen Brown 	{
72396f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
72496f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
72596f15efcSLen Brown 			"please notify linux-acpi@vger.kernel.org\n");
72696f15efcSLen Brown 	}
72796f15efcSLen Brown 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
72896f15efcSLen Brown 	{
72996f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
73096f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
73196f15efcSLen Brown 			"please notify linux-acpi@vger.kernel.org\n");
73296f15efcSLen Brown 	}
73396f15efcSLen Brown }
73496f15efcSLen Brown 
735d08ca2caSLen Brown int __init acpi_sleep_init(void)
736d08ca2caSLen Brown {
737d08ca2caSLen Brown 	acpi_status status;
738d08ca2caSLen Brown 	u8 type_a, type_b;
739d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
740d08ca2caSLen Brown 	int i = 0;
741d08ca2caSLen Brown 
742d08ca2caSLen Brown 	dmi_check_system(acpisleep_dmi_table);
743d08ca2caSLen Brown #endif
744d08ca2caSLen Brown 
745d08ca2caSLen Brown 	if (acpi_disabled)
746d08ca2caSLen Brown 		return 0;
747d08ca2caSLen Brown 
748d08ca2caSLen Brown 	sleep_states[ACPI_STATE_S0] = 1;
749d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "(supports S0");
750d08ca2caSLen Brown 
751d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
752d08ca2caSLen Brown 	for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
753d08ca2caSLen Brown 		status = acpi_get_sleep_type_data(i, &type_a, &type_b);
754d08ca2caSLen Brown 		if (ACPI_SUCCESS(status)) {
755d08ca2caSLen Brown 			sleep_states[i] = 1;
756d08ca2caSLen Brown 			printk(" S%d", i);
757d08ca2caSLen Brown 		}
758d08ca2caSLen Brown 	}
759d08ca2caSLen Brown 
760d08ca2caSLen Brown 	suspend_set_ops(old_suspend_ordering ?
761d08ca2caSLen Brown 		&acpi_suspend_ops_old : &acpi_suspend_ops);
762d08ca2caSLen Brown #endif
763d08ca2caSLen Brown 
764d08ca2caSLen Brown #ifdef CONFIG_HIBERNATION
765d08ca2caSLen Brown 	status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
766d08ca2caSLen Brown 	if (ACPI_SUCCESS(status)) {
767d08ca2caSLen Brown 		hibernation_set_ops(old_suspend_ordering ?
768d08ca2caSLen Brown 			&acpi_hibernation_ops_old : &acpi_hibernation_ops);
769d08ca2caSLen Brown 		sleep_states[ACPI_STATE_S4] = 1;
770d08ca2caSLen Brown 		printk(" S4");
771d08ca2caSLen Brown 		if (!nosigcheck) {
772d08ca2caSLen Brown 			acpi_get_table(ACPI_SIG_FACS, 1,
773d08ca2caSLen Brown 				(struct acpi_table_header **)&facs);
774d08ca2caSLen Brown 			if (facs)
775d08ca2caSLen Brown 				s4_hardware_signature =
776d08ca2caSLen Brown 					facs->hardware_signature;
777d08ca2caSLen Brown 		}
778d08ca2caSLen Brown 	}
779d08ca2caSLen Brown #endif
780d08ca2caSLen Brown 	status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
781d08ca2caSLen Brown 	if (ACPI_SUCCESS(status)) {
782d08ca2caSLen Brown 		sleep_states[ACPI_STATE_S5] = 1;
783d08ca2caSLen Brown 		printk(" S5");
784d08ca2caSLen Brown 		pm_power_off_prepare = acpi_power_off_prepare;
785d08ca2caSLen Brown 		pm_power_off = acpi_power_off;
786d08ca2caSLen Brown 	}
787d08ca2caSLen Brown 	printk(")\n");
788d08ca2caSLen Brown 	/*
789d08ca2caSLen Brown 	 * Register the tts_notifier to reboot notifier list so that the _TTS
790d08ca2caSLen Brown 	 * object can also be evaluated when the system enters S5.
791d08ca2caSLen Brown 	 */
792d08ca2caSLen Brown 	register_reboot_notifier(&tts_notifier);
79396f15efcSLen Brown 	acpi_gts_bfs_check();
794d08ca2caSLen Brown 	return 0;
795d08ca2caSLen Brown }
796