xref: /linux/drivers/acpi/sleep.c (revision 0baed8da1ed91b664759f6c7f955b3a804457389)
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 
28d08ca2caSLen Brown 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 	acpi_enable_wakeup_device_prep(acpi_state);
74d08ca2caSLen Brown #endif
75d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
76d08ca2caSLen Brown 		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
82d08ca2caSLen Brown static u32 acpi_target_sleep_state = ACPI_STATE_S0;
83d08ca2caSLen Brown /*
84d08ca2caSLen Brown  * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
85d08ca2caSLen Brown  * user to request that behavior by using the 'acpi_old_suspend_ordering'
86d08ca2caSLen Brown  * kernel command line option that causes the following variable to be set.
87d08ca2caSLen Brown  */
88d08ca2caSLen Brown static bool old_suspend_ordering;
89d08ca2caSLen Brown 
90d08ca2caSLen Brown void __init acpi_old_suspend_ordering(void)
91d08ca2caSLen Brown {
92d08ca2caSLen Brown 	old_suspend_ordering = true;
93d08ca2caSLen Brown }
94d08ca2caSLen Brown 
95d08ca2caSLen Brown /**
96d08ca2caSLen Brown  *	acpi_pm_disable_gpes - Disable the GPEs.
97d08ca2caSLen Brown  */
98d08ca2caSLen Brown static int acpi_pm_disable_gpes(void)
99d08ca2caSLen Brown {
100d08ca2caSLen Brown 	acpi_disable_all_gpes();
101d08ca2caSLen Brown 	return 0;
102d08ca2caSLen Brown }
103d08ca2caSLen Brown 
104d08ca2caSLen Brown /**
105d08ca2caSLen Brown  *	__acpi_pm_prepare - Prepare the platform to enter the target state.
106d08ca2caSLen Brown  *
107d08ca2caSLen Brown  *	If necessary, set the firmware waking vector and do arch-specific
108d08ca2caSLen Brown  *	nastiness to get the wakeup code to the waking vector.
109d08ca2caSLen Brown  */
110d08ca2caSLen Brown static int __acpi_pm_prepare(void)
111d08ca2caSLen Brown {
112d08ca2caSLen Brown 	int error = acpi_sleep_prepare(acpi_target_sleep_state);
113d08ca2caSLen Brown 
114d08ca2caSLen Brown 	if (error)
115d08ca2caSLen Brown 		acpi_target_sleep_state = ACPI_STATE_S0;
116d08ca2caSLen Brown 	return error;
117d08ca2caSLen Brown }
118d08ca2caSLen Brown 
119d08ca2caSLen Brown /**
120d08ca2caSLen Brown  *	acpi_pm_prepare - Prepare the platform to enter the target sleep
121d08ca2caSLen Brown  *		state and disable the GPEs.
122d08ca2caSLen Brown  */
123d08ca2caSLen Brown static int acpi_pm_prepare(void)
124d08ca2caSLen Brown {
125d08ca2caSLen Brown 	int error = __acpi_pm_prepare();
126d08ca2caSLen Brown 
127d08ca2caSLen Brown 	if (!error)
128d08ca2caSLen Brown 		acpi_disable_all_gpes();
129d08ca2caSLen Brown 	return error;
130d08ca2caSLen Brown }
131d08ca2caSLen Brown 
132d08ca2caSLen Brown /**
133d08ca2caSLen Brown  *	acpi_pm_finish - Instruct the platform to leave a sleep state.
134d08ca2caSLen Brown  *
135d08ca2caSLen Brown  *	This is called after we wake back up (or if entering the sleep state
136d08ca2caSLen Brown  *	failed).
137d08ca2caSLen Brown  */
138d08ca2caSLen Brown static void acpi_pm_finish(void)
139d08ca2caSLen Brown {
140d08ca2caSLen Brown 	u32 acpi_state = acpi_target_sleep_state;
141d08ca2caSLen Brown 
142d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S0)
143d08ca2caSLen Brown 		return;
144d08ca2caSLen Brown 
145d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
146d08ca2caSLen Brown 		acpi_state);
147d08ca2caSLen Brown 	acpi_disable_wakeup_device(acpi_state);
148d08ca2caSLen Brown 	acpi_leave_sleep_state(acpi_state);
149d08ca2caSLen Brown 
150d08ca2caSLen Brown 	/* reset firmware waking vector */
151d08ca2caSLen Brown 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
152d08ca2caSLen Brown 
153d08ca2caSLen Brown 	acpi_target_sleep_state = ACPI_STATE_S0;
154d08ca2caSLen Brown }
155d08ca2caSLen Brown 
156d08ca2caSLen Brown /**
157d08ca2caSLen Brown  *	acpi_pm_end - Finish up suspend sequence.
158d08ca2caSLen Brown  */
159d08ca2caSLen Brown static void acpi_pm_end(void)
160d08ca2caSLen Brown {
161d08ca2caSLen Brown 	/*
162d08ca2caSLen Brown 	 * This is necessary in case acpi_pm_finish() is not called during a
163d08ca2caSLen Brown 	 * failing transition to a sleep state.
164d08ca2caSLen Brown 	 */
165d08ca2caSLen Brown 	acpi_target_sleep_state = ACPI_STATE_S0;
166d08ca2caSLen Brown 	acpi_sleep_tts_switch(acpi_target_sleep_state);
167d08ca2caSLen Brown }
168d08ca2caSLen Brown #else /* !CONFIG_ACPI_SLEEP */
169d08ca2caSLen Brown #define acpi_target_sleep_state	ACPI_STATE_S0
170d08ca2caSLen Brown #endif /* CONFIG_ACPI_SLEEP */
171d08ca2caSLen Brown 
172d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
1735d8b532aSRafael J. Wysocki /*
1745d8b532aSRafael J. Wysocki  * According to the ACPI specification the BIOS should make sure that ACPI is
1755d8b532aSRafael J. Wysocki  * enabled and SCI_EN bit is set on wake-up from S1 - S3 sleep states.  Still,
1765d8b532aSRafael J. Wysocki  * some BIOSes don't do that and therefore we use acpi_enable() to enable ACPI
1775d8b532aSRafael J. Wysocki  * on such systems during resume.  Unfortunately that doesn't help in
1785d8b532aSRafael J. Wysocki  * particularly pathological cases in which SCI_EN has to be set directly on
1795d8b532aSRafael J. Wysocki  * resume, although the specification states very clearly that this flag is
1805d8b532aSRafael J. Wysocki  * owned by the hardware.  The set_sci_en_on_resume variable will be set in such
1815d8b532aSRafael J. Wysocki  * cases.
1825d8b532aSRafael J. Wysocki  */
1835d8b532aSRafael J. Wysocki static bool set_sci_en_on_resume;
1845d8b532aSRafael J. Wysocki 
185d08ca2caSLen Brown extern void do_suspend_lowlevel(void);
186d08ca2caSLen Brown 
187d08ca2caSLen Brown static u32 acpi_suspend_states[] = {
188d08ca2caSLen Brown 	[PM_SUSPEND_ON] = ACPI_STATE_S0,
189d08ca2caSLen Brown 	[PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
190d08ca2caSLen Brown 	[PM_SUSPEND_MEM] = ACPI_STATE_S3,
191d08ca2caSLen Brown 	[PM_SUSPEND_MAX] = ACPI_STATE_S5
192d08ca2caSLen Brown };
193d08ca2caSLen Brown 
194d08ca2caSLen Brown /**
195d08ca2caSLen Brown  *	acpi_suspend_begin - Set the target system sleep state to the state
196d08ca2caSLen Brown  *		associated with given @pm_state, if supported.
197d08ca2caSLen Brown  */
198d08ca2caSLen Brown static int acpi_suspend_begin(suspend_state_t pm_state)
199d08ca2caSLen Brown {
200d08ca2caSLen Brown 	u32 acpi_state = acpi_suspend_states[pm_state];
201d08ca2caSLen Brown 	int error = 0;
202d08ca2caSLen Brown 
203d08ca2caSLen Brown 	if (sleep_states[acpi_state]) {
204d08ca2caSLen Brown 		acpi_target_sleep_state = acpi_state;
205d08ca2caSLen Brown 		acpi_sleep_tts_switch(acpi_target_sleep_state);
206d08ca2caSLen Brown 	} else {
207d08ca2caSLen Brown 		printk(KERN_ERR "ACPI does not support this state: %d\n",
208d08ca2caSLen Brown 			pm_state);
209d08ca2caSLen Brown 		error = -ENOSYS;
210d08ca2caSLen Brown 	}
211d08ca2caSLen Brown 	return error;
212d08ca2caSLen Brown }
213d08ca2caSLen Brown 
214d08ca2caSLen Brown /**
215d08ca2caSLen Brown  *	acpi_suspend_enter - Actually enter a sleep state.
216d08ca2caSLen Brown  *	@pm_state: ignored
217d08ca2caSLen Brown  *
218d08ca2caSLen Brown  *	Flush caches and go to sleep. For STR we have to call arch-specific
219d08ca2caSLen Brown  *	assembly, which in turn call acpi_enter_sleep_state().
220d08ca2caSLen Brown  *	It's unfortunate, but it works. Please fix if you're feeling frisky.
221d08ca2caSLen Brown  */
222d08ca2caSLen Brown static int acpi_suspend_enter(suspend_state_t pm_state)
223d08ca2caSLen Brown {
224d08ca2caSLen Brown 	acpi_status status = AE_OK;
225d08ca2caSLen Brown 	unsigned long flags = 0;
226d08ca2caSLen Brown 	u32 acpi_state = acpi_target_sleep_state;
227d08ca2caSLen Brown 
228d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
229d08ca2caSLen Brown 
230d08ca2caSLen Brown 	/* Do arch specific saving of state. */
231d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S3) {
232d08ca2caSLen Brown 		int error = acpi_save_state_mem();
233d08ca2caSLen Brown 
234d08ca2caSLen Brown 		if (error)
235d08ca2caSLen Brown 			return error;
236d08ca2caSLen Brown 	}
237d08ca2caSLen Brown 
238d08ca2caSLen Brown 	local_irq_save(flags);
239d08ca2caSLen Brown 	acpi_enable_wakeup_device(acpi_state);
240d08ca2caSLen Brown 	switch (acpi_state) {
241d08ca2caSLen Brown 	case ACPI_STATE_S1:
242d08ca2caSLen Brown 		barrier();
243d08ca2caSLen Brown 		status = acpi_enter_sleep_state(acpi_state);
244d08ca2caSLen Brown 		break;
245d08ca2caSLen Brown 
246d08ca2caSLen Brown 	case ACPI_STATE_S3:
247d08ca2caSLen Brown 		do_suspend_lowlevel();
248d08ca2caSLen Brown 		break;
249d08ca2caSLen Brown 	}
250d08ca2caSLen Brown 
251d08ca2caSLen Brown 	/* If ACPI is not enabled by the BIOS, we need to enable it here. */
252d08ca2caSLen Brown 	if (set_sci_en_on_resume)
25350ffba1bSBob Moore 		acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
254d08ca2caSLen Brown 	else
255d08ca2caSLen Brown 		acpi_enable();
256d08ca2caSLen Brown 
257d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
258d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(acpi_state);
259d08ca2caSLen Brown 
260d08ca2caSLen Brown 	/* ACPI 3.0 specs (P62) says that it's the responsibility
261d08ca2caSLen Brown 	 * of the OSPM to clear the status bit [ implying that the
262d08ca2caSLen Brown 	 * POWER_BUTTON event should not reach userspace ]
263d08ca2caSLen Brown 	 */
264d08ca2caSLen Brown 	if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
265d08ca2caSLen Brown 		acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
266d08ca2caSLen Brown 
267d08ca2caSLen Brown 	/*
268d08ca2caSLen Brown 	 * Disable and clear GPE status before interrupt is enabled. Some GPEs
269d08ca2caSLen Brown 	 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
270d08ca2caSLen Brown 	 * acpi_leave_sleep_state will reenable specific GPEs later
271d08ca2caSLen Brown 	 */
272d08ca2caSLen Brown 	acpi_disable_all_gpes();
273d08ca2caSLen Brown 
274d08ca2caSLen Brown 	local_irq_restore(flags);
275d08ca2caSLen Brown 	printk(KERN_DEBUG "Back to C!\n");
276d08ca2caSLen Brown 
277d08ca2caSLen Brown 	/* restore processor state */
278d08ca2caSLen Brown 	if (acpi_state == ACPI_STATE_S3)
279d08ca2caSLen Brown 		acpi_restore_state_mem();
280d08ca2caSLen Brown 
281d08ca2caSLen Brown 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
282d08ca2caSLen Brown }
283d08ca2caSLen Brown 
284d08ca2caSLen Brown static int acpi_suspend_state_valid(suspend_state_t pm_state)
285d08ca2caSLen Brown {
286d08ca2caSLen Brown 	u32 acpi_state;
287d08ca2caSLen Brown 
288d08ca2caSLen Brown 	switch (pm_state) {
289d08ca2caSLen Brown 	case PM_SUSPEND_ON:
290d08ca2caSLen Brown 	case PM_SUSPEND_STANDBY:
291d08ca2caSLen Brown 	case PM_SUSPEND_MEM:
292d08ca2caSLen Brown 		acpi_state = acpi_suspend_states[pm_state];
293d08ca2caSLen Brown 
294d08ca2caSLen Brown 		return sleep_states[acpi_state];
295d08ca2caSLen Brown 	default:
296d08ca2caSLen Brown 		return 0;
297d08ca2caSLen Brown 	}
298d08ca2caSLen Brown }
299d08ca2caSLen Brown 
300d08ca2caSLen Brown static struct platform_suspend_ops acpi_suspend_ops = {
301d08ca2caSLen Brown 	.valid = acpi_suspend_state_valid,
302d08ca2caSLen Brown 	.begin = acpi_suspend_begin,
3036a7c7eafSRafael J. Wysocki 	.prepare_late = acpi_pm_prepare,
304d08ca2caSLen Brown 	.enter = acpi_suspend_enter,
3056a7c7eafSRafael J. Wysocki 	.wake = acpi_pm_finish,
306d08ca2caSLen Brown 	.end = acpi_pm_end,
307d08ca2caSLen Brown };
308d08ca2caSLen Brown 
309d08ca2caSLen Brown /**
310d08ca2caSLen Brown  *	acpi_suspend_begin_old - Set the target system sleep state to the
311d08ca2caSLen Brown  *		state associated with given @pm_state, if supported, and
312d08ca2caSLen Brown  *		execute the _PTS control method.  This function is used if the
313d08ca2caSLen Brown  *		pre-ACPI 2.0 suspend ordering has been requested.
314d08ca2caSLen Brown  */
315d08ca2caSLen Brown static int acpi_suspend_begin_old(suspend_state_t pm_state)
316d08ca2caSLen Brown {
317d08ca2caSLen Brown 	int error = acpi_suspend_begin(pm_state);
318d08ca2caSLen Brown 
319d08ca2caSLen Brown 	if (!error)
320d08ca2caSLen Brown 		error = __acpi_pm_prepare();
321d08ca2caSLen Brown 	return error;
322d08ca2caSLen Brown }
323d08ca2caSLen Brown 
324d08ca2caSLen Brown /*
325d08ca2caSLen Brown  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
326d08ca2caSLen Brown  * been requested.
327d08ca2caSLen Brown  */
328d08ca2caSLen Brown static struct platform_suspend_ops acpi_suspend_ops_old = {
329d08ca2caSLen Brown 	.valid = acpi_suspend_state_valid,
330d08ca2caSLen Brown 	.begin = acpi_suspend_begin_old,
3316a7c7eafSRafael J. Wysocki 	.prepare_late = acpi_pm_disable_gpes,
332d08ca2caSLen Brown 	.enter = acpi_suspend_enter,
3336a7c7eafSRafael J. Wysocki 	.wake = acpi_pm_finish,
334d08ca2caSLen Brown 	.end = acpi_pm_end,
335d08ca2caSLen Brown 	.recover = acpi_pm_finish,
336d08ca2caSLen Brown };
337d08ca2caSLen Brown 
338d08ca2caSLen Brown static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
339d08ca2caSLen Brown {
340d08ca2caSLen Brown 	old_suspend_ordering = true;
341d08ca2caSLen Brown 	return 0;
342d08ca2caSLen Brown }
343d08ca2caSLen Brown 
344d08ca2caSLen Brown static int __init init_set_sci_en_on_resume(const struct dmi_system_id *d)
345d08ca2caSLen Brown {
346d08ca2caSLen Brown 	set_sci_en_on_resume = true;
347d08ca2caSLen Brown 	return 0;
348d08ca2caSLen Brown }
349d08ca2caSLen Brown 
350d08ca2caSLen Brown static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
351d08ca2caSLen Brown 	{
352d08ca2caSLen Brown 	.callback = init_old_suspend_ordering,
353d08ca2caSLen Brown 	.ident = "Abit KN9 (nForce4 variant)",
354d08ca2caSLen Brown 	.matches = {
355d08ca2caSLen Brown 		DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
356d08ca2caSLen Brown 		DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
357d08ca2caSLen Brown 		},
358d08ca2caSLen Brown 	},
359d08ca2caSLen Brown 	{
360d08ca2caSLen Brown 	.callback = init_old_suspend_ordering,
361d08ca2caSLen Brown 	.ident = "HP xw4600 Workstation",
362d08ca2caSLen Brown 	.matches = {
363d08ca2caSLen Brown 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
364d08ca2caSLen Brown 		DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
365d08ca2caSLen Brown 		},
366d08ca2caSLen Brown 	},
367d08ca2caSLen Brown 	{
368d08ca2caSLen Brown 	.callback = init_set_sci_en_on_resume,
369d08ca2caSLen Brown 	.ident = "Apple MacBook 1,1",
370d08ca2caSLen Brown 	.matches = {
371d08ca2caSLen Brown 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
372d08ca2caSLen Brown 		DMI_MATCH(DMI_PRODUCT_NAME, "MacBook1,1"),
373d08ca2caSLen Brown 		},
374d08ca2caSLen Brown 	},
375d08ca2caSLen Brown 	{
376d08ca2caSLen Brown 	.callback = init_set_sci_en_on_resume,
377d08ca2caSLen Brown 	.ident = "Apple MacMini 1,1",
378d08ca2caSLen Brown 	.matches = {
379d08ca2caSLen Brown 		DMI_MATCH(DMI_SYS_VENDOR, "Apple Computer, Inc."),
380d08ca2caSLen Brown 		DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
381d08ca2caSLen Brown 		},
382d08ca2caSLen Brown 	},
383a1404495SAndy Whitcroft 	{
384a1404495SAndy Whitcroft 	.callback = init_old_suspend_ordering,
385a1404495SAndy Whitcroft 	.ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
386a1404495SAndy Whitcroft 	.matches = {
387a1404495SAndy Whitcroft 		DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
388a1404495SAndy Whitcroft 		DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
389a1404495SAndy Whitcroft 		},
390a1404495SAndy Whitcroft 	},
39145e77988SZhang Rui 	{
39245e77988SZhang Rui 	.callback = init_set_sci_en_on_resume,
39345e77988SZhang Rui 	.ident = "Toshiba Satellite L300",
39445e77988SZhang Rui 	.matches = {
39545e77988SZhang Rui 		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
39645e77988SZhang Rui 		DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L300"),
39745e77988SZhang Rui 		},
39845e77988SZhang Rui 	},
3992a9ef8e1SZhao Yakui 	{
400ec79be26SBartlomiej Zolnierkiewicz 	.callback = init_set_sci_en_on_resume,
401ec79be26SBartlomiej Zolnierkiewicz 	.ident = "Hewlett-Packard HP G7000 Notebook PC",
402ec79be26SBartlomiej Zolnierkiewicz 	.matches = {
403ec79be26SBartlomiej Zolnierkiewicz 		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
404ec79be26SBartlomiej Zolnierkiewicz 		DMI_MATCH(DMI_PRODUCT_NAME, "HP G7000 Notebook PC"),
405ec79be26SBartlomiej Zolnierkiewicz 		},
406ec79be26SBartlomiej Zolnierkiewicz 	},
407ec79be26SBartlomiej Zolnierkiewicz 	{
4082a9ef8e1SZhao Yakui 	.callback = init_old_suspend_ordering,
4092a9ef8e1SZhao Yakui 	.ident = "Panasonic CF51-2L",
4102a9ef8e1SZhao Yakui 	.matches = {
4112a9ef8e1SZhao Yakui 		DMI_MATCH(DMI_BOARD_VENDOR,
4122a9ef8e1SZhao Yakui 				"Matsushita Electric Industrial Co.,Ltd."),
4132a9ef8e1SZhao Yakui 		DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
4142a9ef8e1SZhao Yakui 		},
4152a9ef8e1SZhao Yakui 	},
416d08ca2caSLen Brown 	{},
417d08ca2caSLen Brown };
418d08ca2caSLen Brown #endif /* CONFIG_SUSPEND */
419d08ca2caSLen Brown 
420d08ca2caSLen Brown #ifdef CONFIG_HIBERNATION
4215d8b532aSRafael J. Wysocki /*
4225d8b532aSRafael J. Wysocki  * The ACPI specification wants us to save NVS memory regions during hibernation
4235d8b532aSRafael J. Wysocki  * and to restore them during the subsequent resume.  However, it is not certain
4245d8b532aSRafael J. Wysocki  * if this mechanism is going to work on all machines, so we allow the user to
4255d8b532aSRafael J. Wysocki  * disable this mechanism using the 'acpi_sleep=s4_nonvs' kernel command line
4265d8b532aSRafael J. Wysocki  * option.
4275d8b532aSRafael J. Wysocki  */
4285d8b532aSRafael J. Wysocki static bool s4_no_nvs;
4295d8b532aSRafael J. Wysocki 
4305d8b532aSRafael J. Wysocki void __init acpi_s4_no_nvs(void)
4315d8b532aSRafael J. Wysocki {
4325d8b532aSRafael J. Wysocki 	s4_no_nvs = true;
4335d8b532aSRafael J. Wysocki }
4345d8b532aSRafael J. Wysocki 
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 
448d08ca2caSLen Brown 	error = s4_no_nvs ? 0 : hibernate_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_pre_snapshot(void)
458d08ca2caSLen Brown {
459d08ca2caSLen Brown 	int error = acpi_pm_prepare();
460d08ca2caSLen Brown 
461d08ca2caSLen Brown 	if (!error)
462d08ca2caSLen Brown 		hibernate_nvs_save();
463d08ca2caSLen Brown 
464d08ca2caSLen Brown 	return error;
465d08ca2caSLen Brown }
466d08ca2caSLen Brown 
467d08ca2caSLen Brown static int acpi_hibernation_enter(void)
468d08ca2caSLen Brown {
469d08ca2caSLen Brown 	acpi_status status = AE_OK;
470d08ca2caSLen Brown 	unsigned long flags = 0;
471d08ca2caSLen Brown 
472d08ca2caSLen Brown 	ACPI_FLUSH_CPU_CACHE();
473d08ca2caSLen Brown 
474d08ca2caSLen Brown 	local_irq_save(flags);
475d08ca2caSLen Brown 	acpi_enable_wakeup_device(ACPI_STATE_S4);
476d08ca2caSLen Brown 	/* This shouldn't return.  If it returns, we have a problem */
477d08ca2caSLen Brown 	status = acpi_enter_sleep_state(ACPI_STATE_S4);
478d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
479d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(ACPI_STATE_S4);
480d08ca2caSLen Brown 	local_irq_restore(flags);
481d08ca2caSLen Brown 
482d08ca2caSLen Brown 	return ACPI_SUCCESS(status) ? 0 : -EFAULT;
483d08ca2caSLen Brown }
484d08ca2caSLen Brown 
485d08ca2caSLen Brown static void acpi_hibernation_finish(void)
486d08ca2caSLen Brown {
487d08ca2caSLen Brown 	hibernate_nvs_free();
488d08ca2caSLen Brown 	acpi_pm_finish();
489d08ca2caSLen Brown }
490d08ca2caSLen Brown 
491d08ca2caSLen Brown static void acpi_hibernation_leave(void)
492d08ca2caSLen Brown {
493d08ca2caSLen Brown 	/*
494d08ca2caSLen Brown 	 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
495d08ca2caSLen Brown 	 * enable it here.
496d08ca2caSLen Brown 	 */
497d08ca2caSLen Brown 	acpi_enable();
498d08ca2caSLen Brown 	/* Reprogram control registers and execute _BFS */
499d08ca2caSLen Brown 	acpi_leave_sleep_state_prep(ACPI_STATE_S4);
500d08ca2caSLen Brown 	/* Check the hardware signature */
501d08ca2caSLen Brown 	if (facs && s4_hardware_signature != facs->hardware_signature) {
502d08ca2caSLen Brown 		printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
503d08ca2caSLen Brown 			"cannot resume!\n");
504d08ca2caSLen Brown 		panic("ACPI S4 hardware signature mismatch");
505d08ca2caSLen Brown 	}
506d08ca2caSLen Brown 	/* Restore the NVS memory area */
507d08ca2caSLen Brown 	hibernate_nvs_restore();
508d08ca2caSLen Brown }
509d08ca2caSLen Brown 
510d08ca2caSLen Brown static void acpi_pm_enable_gpes(void)
511d08ca2caSLen Brown {
512d08ca2caSLen Brown 	acpi_enable_all_runtime_gpes();
513d08ca2caSLen Brown }
514d08ca2caSLen Brown 
515d08ca2caSLen Brown static struct platform_hibernation_ops acpi_hibernation_ops = {
516d08ca2caSLen Brown 	.begin = acpi_hibernation_begin,
517d08ca2caSLen Brown 	.end = acpi_pm_end,
518d08ca2caSLen Brown 	.pre_snapshot = acpi_hibernation_pre_snapshot,
519d08ca2caSLen Brown 	.finish = acpi_hibernation_finish,
520d08ca2caSLen Brown 	.prepare = acpi_pm_prepare,
521d08ca2caSLen Brown 	.enter = acpi_hibernation_enter,
522d08ca2caSLen Brown 	.leave = acpi_hibernation_leave,
523d08ca2caSLen Brown 	.pre_restore = acpi_pm_disable_gpes,
524d08ca2caSLen Brown 	.restore_cleanup = acpi_pm_enable_gpes,
525d08ca2caSLen Brown };
526d08ca2caSLen Brown 
527d08ca2caSLen Brown /**
528d08ca2caSLen Brown  *	acpi_hibernation_begin_old - Set the target system sleep state to
529d08ca2caSLen Brown  *		ACPI_STATE_S4 and execute the _PTS control method.  This
530d08ca2caSLen Brown  *		function is used if the pre-ACPI 2.0 suspend ordering has been
531d08ca2caSLen Brown  *		requested.
532d08ca2caSLen Brown  */
533d08ca2caSLen Brown static int acpi_hibernation_begin_old(void)
534d08ca2caSLen Brown {
535d08ca2caSLen Brown 	int error;
536d08ca2caSLen Brown 	/*
537d08ca2caSLen Brown 	 * The _TTS object should always be evaluated before the _PTS object.
538d08ca2caSLen Brown 	 * When the old_suspended_ordering is true, the _PTS object is
539d08ca2caSLen Brown 	 * evaluated in the acpi_sleep_prepare.
540d08ca2caSLen Brown 	 */
541d08ca2caSLen Brown 	acpi_sleep_tts_switch(ACPI_STATE_S4);
542d08ca2caSLen Brown 
543d08ca2caSLen Brown 	error = acpi_sleep_prepare(ACPI_STATE_S4);
544d08ca2caSLen Brown 
545d08ca2caSLen Brown 	if (!error) {
546d08ca2caSLen Brown 		if (!s4_no_nvs)
547d08ca2caSLen Brown 			error = hibernate_nvs_alloc();
548d08ca2caSLen Brown 		if (!error)
549d08ca2caSLen Brown 			acpi_target_sleep_state = ACPI_STATE_S4;
550d08ca2caSLen Brown 	}
551d08ca2caSLen Brown 	return error;
552d08ca2caSLen Brown }
553d08ca2caSLen Brown 
554d08ca2caSLen Brown static int acpi_hibernation_pre_snapshot_old(void)
555d08ca2caSLen Brown {
556d08ca2caSLen Brown 	int error = acpi_pm_disable_gpes();
557d08ca2caSLen Brown 
558d08ca2caSLen Brown 	if (!error)
559d08ca2caSLen Brown 		hibernate_nvs_save();
560d08ca2caSLen Brown 
561d08ca2caSLen Brown 	return error;
562d08ca2caSLen Brown }
563d08ca2caSLen Brown 
564d08ca2caSLen Brown /*
565d08ca2caSLen Brown  * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
566d08ca2caSLen Brown  * been requested.
567d08ca2caSLen Brown  */
568d08ca2caSLen Brown static struct platform_hibernation_ops acpi_hibernation_ops_old = {
569d08ca2caSLen Brown 	.begin = acpi_hibernation_begin_old,
570d08ca2caSLen Brown 	.end = acpi_pm_end,
571d08ca2caSLen Brown 	.pre_snapshot = acpi_hibernation_pre_snapshot_old,
572d08ca2caSLen Brown 	.finish = acpi_hibernation_finish,
573d08ca2caSLen Brown 	.prepare = acpi_pm_disable_gpes,
574d08ca2caSLen Brown 	.enter = acpi_hibernation_enter,
575d08ca2caSLen Brown 	.leave = acpi_hibernation_leave,
576d08ca2caSLen Brown 	.pre_restore = acpi_pm_disable_gpes,
577d08ca2caSLen Brown 	.restore_cleanup = acpi_pm_enable_gpes,
578d08ca2caSLen Brown 	.recover = acpi_pm_finish,
579d08ca2caSLen Brown };
580d08ca2caSLen Brown #endif /* CONFIG_HIBERNATION */
581d08ca2caSLen Brown 
582d08ca2caSLen Brown int acpi_suspend(u32 acpi_state)
583d08ca2caSLen Brown {
584d08ca2caSLen Brown 	suspend_state_t states[] = {
585d08ca2caSLen Brown 		[1] = PM_SUSPEND_STANDBY,
586d08ca2caSLen Brown 		[3] = PM_SUSPEND_MEM,
587d08ca2caSLen Brown 		[5] = PM_SUSPEND_MAX
588d08ca2caSLen Brown 	};
589d08ca2caSLen Brown 
590d08ca2caSLen Brown 	if (acpi_state < 6 && states[acpi_state])
591d08ca2caSLen Brown 		return pm_suspend(states[acpi_state]);
592d08ca2caSLen Brown 	if (acpi_state == 4)
593d08ca2caSLen Brown 		return hibernate();
594d08ca2caSLen Brown 	return -EINVAL;
595d08ca2caSLen Brown }
596d08ca2caSLen Brown 
597d08ca2caSLen Brown #ifdef CONFIG_PM_SLEEP
598d08ca2caSLen Brown /**
599d08ca2caSLen Brown  *	acpi_pm_device_sleep_state - return preferred power state of ACPI device
600d08ca2caSLen Brown  *		in the system sleep state given by %acpi_target_sleep_state
601d08ca2caSLen Brown  *	@dev: device to examine; its driver model wakeup flags control
602d08ca2caSLen Brown  *		whether it should be able to wake up the system
603d08ca2caSLen Brown  *	@d_min_p: used to store the upper limit of allowed states range
604d08ca2caSLen Brown  *	Return value: preferred power state of the device on success, -ENODEV on
605d08ca2caSLen Brown  *		failure (ie. if there's no 'struct acpi_device' for @dev)
606d08ca2caSLen Brown  *
607d08ca2caSLen Brown  *	Find the lowest power (highest number) ACPI device power state that
608d08ca2caSLen Brown  *	device @dev can be in while the system is in the sleep state represented
609d08ca2caSLen Brown  *	by %acpi_target_sleep_state.  If @wake is nonzero, the device should be
610d08ca2caSLen Brown  *	able to wake up the system from this sleep state.  If @d_min_p is set,
611d08ca2caSLen Brown  *	the highest power (lowest number) device power state of @dev allowed
612d08ca2caSLen Brown  *	in this system sleep state is stored at the location pointed to by it.
613d08ca2caSLen Brown  *
614d08ca2caSLen Brown  *	The caller must ensure that @dev is valid before using this function.
615d08ca2caSLen Brown  *	The caller is also responsible for figuring out if the device is
616d08ca2caSLen Brown  *	supposed to be able to wake up the system and passing this information
617d08ca2caSLen Brown  *	via @wake.
618d08ca2caSLen Brown  */
619d08ca2caSLen Brown 
620d08ca2caSLen Brown int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
621d08ca2caSLen Brown {
622d08ca2caSLen Brown 	acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
623d08ca2caSLen Brown 	struct acpi_device *adev;
624d08ca2caSLen Brown 	char acpi_method[] = "_SxD";
625d08ca2caSLen Brown 	unsigned long long d_min, d_max;
626d08ca2caSLen Brown 
627d08ca2caSLen Brown 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
628d08ca2caSLen Brown 		printk(KERN_DEBUG "ACPI handle has no context!\n");
629d08ca2caSLen Brown 		return -ENODEV;
630d08ca2caSLen Brown 	}
631d08ca2caSLen Brown 
632d08ca2caSLen Brown 	acpi_method[2] = '0' + acpi_target_sleep_state;
633d08ca2caSLen Brown 	/*
634d08ca2caSLen Brown 	 * If the sleep state is S0, we will return D3, but if the device has
635d08ca2caSLen Brown 	 * _S0W, we will use the value from _S0W
636d08ca2caSLen Brown 	 */
637d08ca2caSLen Brown 	d_min = ACPI_STATE_D0;
638d08ca2caSLen Brown 	d_max = ACPI_STATE_D3;
639d08ca2caSLen Brown 
640d08ca2caSLen Brown 	/*
641d08ca2caSLen Brown 	 * If present, _SxD methods return the minimum D-state (highest power
642d08ca2caSLen Brown 	 * state) we can use for the corresponding S-states.  Otherwise, the
643d08ca2caSLen Brown 	 * minimum D-state is D0 (ACPI 3.x).
644d08ca2caSLen Brown 	 *
645d08ca2caSLen Brown 	 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
646d08ca2caSLen Brown 	 * provided -- that's our fault recovery, we ignore retval.
647d08ca2caSLen Brown 	 */
648d08ca2caSLen Brown 	if (acpi_target_sleep_state > ACPI_STATE_S0)
649d08ca2caSLen Brown 		acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
650d08ca2caSLen Brown 
651d08ca2caSLen Brown 	/*
652d08ca2caSLen Brown 	 * If _PRW says we can wake up the system from the target sleep state,
653d08ca2caSLen Brown 	 * the D-state returned by _SxD is sufficient for that (we assume a
654d08ca2caSLen Brown 	 * wakeup-aware driver if wake is set).  Still, if _SxW exists
655d08ca2caSLen Brown 	 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
656d08ca2caSLen Brown 	 * can wake the system.  _S0W may be valid, too.
657d08ca2caSLen Brown 	 */
658d08ca2caSLen Brown 	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
659d08ca2caSLen Brown 	    (device_may_wakeup(dev) && adev->wakeup.state.enabled &&
660d08ca2caSLen Brown 	     adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
661d08ca2caSLen Brown 		acpi_status status;
662d08ca2caSLen Brown 
663d08ca2caSLen Brown 		acpi_method[3] = 'W';
664d08ca2caSLen Brown 		status = acpi_evaluate_integer(handle, acpi_method, NULL,
665d08ca2caSLen Brown 						&d_max);
666d08ca2caSLen Brown 		if (ACPI_FAILURE(status)) {
667d08ca2caSLen Brown 			d_max = d_min;
668d08ca2caSLen Brown 		} else if (d_max < d_min) {
669d08ca2caSLen Brown 			/* Warn the user of the broken DSDT */
670d08ca2caSLen Brown 			printk(KERN_WARNING "ACPI: Wrong value from %s\n",
671d08ca2caSLen Brown 				acpi_method);
672d08ca2caSLen Brown 			/* Sanitize it */
673d08ca2caSLen Brown 			d_min = d_max;
674d08ca2caSLen Brown 		}
675d08ca2caSLen Brown 	}
676d08ca2caSLen Brown 
677d08ca2caSLen Brown 	if (d_min_p)
678d08ca2caSLen Brown 		*d_min_p = d_min;
679d08ca2caSLen Brown 	return d_max;
680d08ca2caSLen Brown }
681d08ca2caSLen Brown 
682d08ca2caSLen Brown /**
683d08ca2caSLen Brown  *	acpi_pm_device_sleep_wake - enable or disable the system wake-up
684d08ca2caSLen Brown  *                                  capability of given device
685d08ca2caSLen Brown  *	@dev: device to handle
686d08ca2caSLen Brown  *	@enable: 'true' - enable, 'false' - disable the wake-up capability
687d08ca2caSLen Brown  */
688d08ca2caSLen Brown int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
689d08ca2caSLen Brown {
690d08ca2caSLen Brown 	acpi_handle handle;
691d08ca2caSLen Brown 	struct acpi_device *adev;
692df8db91fSRafael J. Wysocki 	int error;
693d08ca2caSLen Brown 
694*0baed8daSRafael J. Wysocki 	if (!device_can_wakeup(dev))
695d08ca2caSLen Brown 		return -EINVAL;
696d08ca2caSLen Brown 
697d08ca2caSLen Brown 	handle = DEVICE_ACPI_HANDLE(dev);
698d08ca2caSLen Brown 	if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
699df8db91fSRafael J. Wysocki 		dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
700d08ca2caSLen Brown 		return -ENODEV;
701d08ca2caSLen Brown 	}
702d08ca2caSLen Brown 
703df8db91fSRafael J. Wysocki 	error = enable ?
704d08ca2caSLen Brown 		acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
705d08ca2caSLen Brown 		acpi_disable_wakeup_device_power(adev);
706df8db91fSRafael J. Wysocki 	if (!error)
707df8db91fSRafael J. Wysocki 		dev_info(dev, "wake-up capability %s by ACPI\n",
708df8db91fSRafael J. Wysocki 				enable ? "enabled" : "disabled");
709df8db91fSRafael J. Wysocki 
710df8db91fSRafael J. Wysocki 	return error;
711d08ca2caSLen Brown }
712d08ca2caSLen Brown #endif
713d08ca2caSLen Brown 
714d08ca2caSLen Brown static void acpi_power_off_prepare(void)
715d08ca2caSLen Brown {
716d08ca2caSLen Brown 	/* Prepare to power off the system */
717d08ca2caSLen Brown 	acpi_sleep_prepare(ACPI_STATE_S5);
718d08ca2caSLen Brown 	acpi_disable_all_gpes();
719d08ca2caSLen Brown }
720d08ca2caSLen Brown 
721d08ca2caSLen Brown static void acpi_power_off(void)
722d08ca2caSLen Brown {
723d08ca2caSLen Brown 	/* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
7244d939155SFrank Seidel 	printk(KERN_DEBUG "%s called\n", __func__);
725d08ca2caSLen Brown 	local_irq_disable();
726d08ca2caSLen Brown 	acpi_enable_wakeup_device(ACPI_STATE_S5);
727d08ca2caSLen Brown 	acpi_enter_sleep_state(ACPI_STATE_S5);
728d08ca2caSLen Brown }
729d08ca2caSLen Brown 
73096f15efcSLen Brown /*
73196f15efcSLen Brown  * ACPI 2.0 created the optional _GTS and _BFS,
73296f15efcSLen Brown  * but industry adoption has been neither rapid nor broad.
73396f15efcSLen Brown  *
73496f15efcSLen Brown  * Linux gets into trouble when it executes poorly validated
73596f15efcSLen Brown  * paths through the BIOS, so disable _GTS and _BFS by default,
73696f15efcSLen Brown  * but do speak up and offer the option to enable them.
73796f15efcSLen Brown  */
73896f15efcSLen Brown void __init acpi_gts_bfs_check(void)
73996f15efcSLen Brown {
74096f15efcSLen Brown 	acpi_handle dummy;
74196f15efcSLen Brown 
74296f15efcSLen Brown 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__GTS, &dummy)))
74396f15efcSLen Brown 	{
74496f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
74596f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
74696f15efcSLen Brown 			"please notify linux-acpi@vger.kernel.org\n");
74796f15efcSLen Brown 	}
74896f15efcSLen Brown 	if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_NAME__BFS, &dummy)))
74996f15efcSLen Brown 	{
75096f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
75196f15efcSLen Brown 		printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
75296f15efcSLen Brown 			"please notify linux-acpi@vger.kernel.org\n");
75396f15efcSLen Brown 	}
75496f15efcSLen Brown }
75596f15efcSLen Brown 
756d08ca2caSLen Brown int __init acpi_sleep_init(void)
757d08ca2caSLen Brown {
758d08ca2caSLen Brown 	acpi_status status;
759d08ca2caSLen Brown 	u8 type_a, type_b;
760d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
761d08ca2caSLen Brown 	int i = 0;
762d08ca2caSLen Brown 
763d08ca2caSLen Brown 	dmi_check_system(acpisleep_dmi_table);
764d08ca2caSLen Brown #endif
765d08ca2caSLen Brown 
766d08ca2caSLen Brown 	if (acpi_disabled)
767d08ca2caSLen Brown 		return 0;
768d08ca2caSLen Brown 
769d08ca2caSLen Brown 	sleep_states[ACPI_STATE_S0] = 1;
770d08ca2caSLen Brown 	printk(KERN_INFO PREFIX "(supports S0");
771d08ca2caSLen Brown 
772d08ca2caSLen Brown #ifdef CONFIG_SUSPEND
773d08ca2caSLen Brown 	for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
774d08ca2caSLen Brown 		status = acpi_get_sleep_type_data(i, &type_a, &type_b);
775d08ca2caSLen Brown 		if (ACPI_SUCCESS(status)) {
776d08ca2caSLen Brown 			sleep_states[i] = 1;
777d08ca2caSLen Brown 			printk(" S%d", i);
778d08ca2caSLen Brown 		}
779d08ca2caSLen Brown 	}
780d08ca2caSLen Brown 
781d08ca2caSLen Brown 	suspend_set_ops(old_suspend_ordering ?
782d08ca2caSLen Brown 		&acpi_suspend_ops_old : &acpi_suspend_ops);
783d08ca2caSLen Brown #endif
784d08ca2caSLen Brown 
785d08ca2caSLen Brown #ifdef CONFIG_HIBERNATION
786d08ca2caSLen Brown 	status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
787d08ca2caSLen Brown 	if (ACPI_SUCCESS(status)) {
788d08ca2caSLen Brown 		hibernation_set_ops(old_suspend_ordering ?
789d08ca2caSLen Brown 			&acpi_hibernation_ops_old : &acpi_hibernation_ops);
790d08ca2caSLen Brown 		sleep_states[ACPI_STATE_S4] = 1;
791d08ca2caSLen Brown 		printk(" S4");
792d08ca2caSLen Brown 		if (!nosigcheck) {
793d08ca2caSLen Brown 			acpi_get_table(ACPI_SIG_FACS, 1,
794d08ca2caSLen Brown 				(struct acpi_table_header **)&facs);
795d08ca2caSLen Brown 			if (facs)
796d08ca2caSLen Brown 				s4_hardware_signature =
797d08ca2caSLen Brown 					facs->hardware_signature;
798d08ca2caSLen Brown 		}
799d08ca2caSLen Brown 	}
800d08ca2caSLen Brown #endif
801d08ca2caSLen Brown 	status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
802d08ca2caSLen Brown 	if (ACPI_SUCCESS(status)) {
803d08ca2caSLen Brown 		sleep_states[ACPI_STATE_S5] = 1;
804d08ca2caSLen Brown 		printk(" S5");
805d08ca2caSLen Brown 		pm_power_off_prepare = acpi_power_off_prepare;
806d08ca2caSLen Brown 		pm_power_off = acpi_power_off;
807d08ca2caSLen Brown 	}
808d08ca2caSLen Brown 	printk(")\n");
809d08ca2caSLen Brown 	/*
810d08ca2caSLen Brown 	 * Register the tts_notifier to reboot notifier list so that the _TTS
811d08ca2caSLen Brown 	 * object can also be evaluated when the system enters S5.
812d08ca2caSLen Brown 	 */
813d08ca2caSLen Brown 	register_reboot_notifier(&tts_notifier);
81496f15efcSLen Brown 	acpi_gts_bfs_check();
815d08ca2caSLen Brown 	return 0;
816d08ca2caSLen Brown }
817