blob: 1d661b5c3287fb4b5083a6636d13e48643da8d51 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sleep.c - ACPI sleep support.
3 *
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -05004 * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
6 * Copyright (c) 2000-2003 Patrick Mochel
7 * Copyright (c) 2003 Open Source Development Lab
8 *
9 * This file is released under the GPLv2.
10 *
11 */
12
13#include <linux/delay.h>
14#include <linux/irq.h>
15#include <linux/dmi.h>
16#include <linux/device.h>
17#include <linux/suspend.h>
Zhao Yakuie49f7112008-08-12 10:20:22 +080018#include <linux/reboot.h>
H. Peter Anvind1ee4332011-02-14 15:42:46 -080019#include <linux/acpi.h>
Lin Minga2ef5c42012-03-21 10:58:46 +080020#include <linux/module.h>
Lin Mingb24e5092012-03-27 15:43:25 +080021#include <linux/pm_runtime.h>
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +040022
23#include <asm/io.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <acpi/acpi_bus.h>
26#include <acpi/acpi_drivers.h>
Bjorn Helgaase60cc7a2009-03-13 12:08:26 -060027
28#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "sleep.h"
30
Lin Minga2ef5c42012-03-21 10:58:46 +080031static unsigned int gts, bfs;
32module_param(gts, uint, 0644);
33module_param(bfs, uint, 0644);
34MODULE_PARM_DESC(gts, "Enable evaluation of _GTS on suspend.");
35MODULE_PARM_DESC(bfs, "Enable evaluation of _BFS on resume".);
36
37static u8 wake_sleep_flags(void)
38{
39 u8 flags = ACPI_NO_OPTIONAL_METHODS;
40
41 if (gts)
42 flags |= ACPI_EXECUTE_GTS;
43 if (bfs)
44 flags |= ACPI_EXECUTE_BFS;
45
46 return flags;
47}
48
Stephen Hemminger01eac602010-10-18 18:47:25 -070049static u8 sleep_states[ACPI_S_STATE_COUNT];
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Zhao Yakuie49f7112008-08-12 10:20:22 +080051static void acpi_sleep_tts_switch(u32 acpi_state)
52{
53 union acpi_object in_arg = { ACPI_TYPE_INTEGER };
54 struct acpi_object_list arg_list = { 1, &in_arg };
55 acpi_status status = AE_OK;
56
57 in_arg.integer.value = acpi_state;
58 status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
59 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
60 /*
61 * OS can't evaluate the _TTS object correctly. Some warning
62 * message will be printed. But it won't break anything.
63 */
64 printk(KERN_NOTICE "Failure in evaluating _TTS object\n");
65 }
66}
67
68static int tts_notify_reboot(struct notifier_block *this,
69 unsigned long code, void *x)
70{
71 acpi_sleep_tts_switch(ACPI_STATE_S5);
72 return NOTIFY_DONE;
73}
74
75static struct notifier_block tts_notifier = {
76 .notifier_call = tts_notify_reboot,
77 .next = NULL,
78 .priority = 0,
79};
80
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010081static int acpi_sleep_prepare(u32 acpi_state)
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020082{
83#ifdef CONFIG_ACPI_SLEEP
84 /* do we have a wakeup address for S2 and S3? */
85 if (acpi_state == ACPI_STATE_S3) {
86 if (!acpi_wakeup_address) {
87 return -EFAULT;
88 }
H. Peter Anvin4b4f7282008-06-24 23:03:48 +020089 acpi_set_firmware_waking_vector(
90 (acpi_physical_address)acpi_wakeup_address);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020091
92 }
93 ACPI_FLUSH_CPU_CACHE();
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020094#endif
Rafael J. Wysockic9b6c8f2008-01-08 00:10:57 +010095 printk(KERN_INFO PREFIX "Preparing to enter system sleep state S%d\n",
96 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -040097 acpi_enable_wakeup_devices(acpi_state);
Alexey Starikovskiy2f3f22262007-09-24 14:33:21 +020098 acpi_enter_sleep_state_prep(acpi_state);
99 return 0;
100}
101
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -0400102#ifdef CONFIG_ACPI_SLEEP
Jan Beulich091aad62010-12-07 14:52:25 +0000103static u32 acpi_target_sleep_state = ACPI_STATE_S0;
104
Zhang Ruid7f0eea2009-12-30 15:36:42 +0800105/*
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200106 * The ACPI specification wants us to save NVS memory regions during hibernation
107 * and to restore them during the subsequent resume. Windows does that also for
108 * suspend to RAM. However, it is known that this mechanism does not work on
109 * all machines, so we allow the user to disable it with the help of the
110 * 'acpi_sleep=nonvs' kernel command line option.
111 */
112static bool nvs_nosave;
113
114void __init acpi_nvs_nosave(void)
115{
116 nvs_nosave = true;
117}
118
119/*
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200120 * ACPI 1.0 wants us to execute _PTS before suspending devices, so we allow the
121 * user to request that behavior by using the 'acpi_old_suspend_ordering'
122 * kernel command line option that causes the following variable to be set.
123 */
124static bool old_suspend_ordering;
125
126void __init acpi_old_suspend_ordering(void)
127{
128 old_suspend_ordering = true;
129}
130
131/**
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200132 * acpi_pm_freeze - Disable the GPEs and suspend EC transactions.
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200133 */
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200134static int acpi_pm_freeze(void)
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200135{
Lin Ming3d97e422008-12-16 16:57:46 +0800136 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200137 acpi_os_wait_events_complete(NULL);
Rafael J. Wysockife955682010-04-09 01:40:38 +0200138 acpi_ec_block_transactions();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200139 return 0;
140}
141
142/**
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200143 * acpi_pre_suspend - Enable wakeup devices, "freeze" EC and save NVS.
144 */
145static int acpi_pm_pre_suspend(void)
146{
147 acpi_pm_freeze();
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100148 return suspend_nvs_save();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200149}
150
151/**
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200152 * __acpi_pm_prepare - Prepare the platform to enter the target state.
153 *
154 * If necessary, set the firmware waking vector and do arch-specific
155 * nastiness to get the wakeup code to the waking vector.
156 */
157static int __acpi_pm_prepare(void)
158{
159 int error = acpi_sleep_prepare(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200160 if (error)
161 acpi_target_sleep_state = ACPI_STATE_S0;
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200162
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200163 return error;
164}
165
166/**
167 * acpi_pm_prepare - Prepare the platform to enter the target sleep
168 * state and disable the GPEs.
169 */
170static int acpi_pm_prepare(void)
171{
172 int error = __acpi_pm_prepare();
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200173 if (!error)
Jiri Slaby26fcaf62011-01-07 01:42:31 +0100174 error = acpi_pm_pre_suspend();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200175
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200176 return error;
177}
178
179/**
180 * acpi_pm_finish - Instruct the platform to leave a sleep state.
181 *
182 * This is called after we wake back up (or if entering the sleep state
183 * failed).
184 */
185static void acpi_pm_finish(void)
186{
187 u32 acpi_state = acpi_target_sleep_state;
188
Len Brown42de5532010-06-12 01:15:40 -0400189 acpi_ec_unblock_transactions();
Rafael J. Wysockid551d812011-01-19 22:27:55 +0100190 suspend_nvs_free();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400191
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200192 if (acpi_state == ACPI_STATE_S0)
193 return;
194
195 printk(KERN_INFO PREFIX "Waking up from system sleep state S%d\n",
196 acpi_state);
Rafael J. Wysocki78f5f022010-07-06 22:09:38 -0400197 acpi_disable_wakeup_devices(acpi_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200198 acpi_leave_sleep_state(acpi_state);
199
200 /* reset firmware waking vector */
201 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
202
203 acpi_target_sleep_state = ACPI_STATE_S0;
204}
205
206/**
207 * acpi_pm_end - Finish up suspend sequence.
208 */
209static void acpi_pm_end(void)
210{
211 /*
212 * This is necessary in case acpi_pm_finish() is not called during a
213 * failing transition to a sleep state.
214 */
215 acpi_target_sleep_state = ACPI_STATE_S0;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800216 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200217}
Rafael J. Wysocki92daa7b2008-10-23 21:46:43 +0200218#else /* !CONFIG_ACPI_SLEEP */
219#define acpi_target_sleep_state ACPI_STATE_S0
Rafael J. Wysocki5d1e0722008-10-22 14:58:43 -0400220#endif /* CONFIG_ACPI_SLEEP */
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200221
222#ifdef CONFIG_SUSPEND
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static u32 acpi_suspend_states[] = {
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500224 [PM_SUSPEND_ON] = ACPI_STATE_S0,
225 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
226 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500227 [PM_SUSPEND_MAX] = ACPI_STATE_S5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228};
229
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200230/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400231 * acpi_suspend_begin - Set the target system sleep state to the state
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200232 * associated with given @pm_state, if supported.
233 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400234static int acpi_suspend_begin(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 u32 acpi_state = acpi_suspend_states[pm_state];
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200237 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200239 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400240 if (error)
241 return error;
242
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200243 if (sleep_states[acpi_state]) {
244 acpi_target_sleep_state = acpi_state;
Zhao Yakuie49f7112008-08-12 10:20:22 +0800245 acpi_sleep_tts_switch(acpi_target_sleep_state);
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200246 } else {
247 printk(KERN_ERR "ACPI does not support this state: %d\n",
248 pm_state);
249 error = -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200251 return error;
252}
253
254/**
Len Brown2c6e33c2008-04-23 18:02:52 -0400255 * acpi_suspend_enter - Actually enter a sleep state.
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200256 * @pm_state: ignored
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 *
Rafael J. Wysocki50ad1472007-07-24 11:58:39 +0200258 * Flush caches and go to sleep. For STR we have to call arch-specific
259 * assembly, which in turn call acpi_enter_sleep_state().
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 * It's unfortunate, but it works. Please fix if you're feeling frisky.
261 */
Len Brown2c6e33c2008-04-23 18:02:52 -0400262static int acpi_suspend_enter(suspend_state_t pm_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
264 acpi_status status = AE_OK;
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200265 u32 acpi_state = acpi_target_sleep_state;
Lin Minga2ef5c42012-03-21 10:58:46 +0800266 u8 flags = wake_sleep_flags();
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100267 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 ACPI_FLUSH_CPU_CACHE();
270
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200271 switch (acpi_state) {
272 case ACPI_STATE_S1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 barrier();
Lin Minga2ef5c42012-03-21 10:58:46 +0800274 status = acpi_enter_sleep_state(acpi_state, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 break;
276
Rafael J. Wysockie9b3aba2007-07-17 22:40:06 +0200277 case ACPI_STATE_S3:
Rafael J. Wysockif1a20032011-02-08 23:42:22 +0100278 error = acpi_suspend_lowlevel();
Rafael J. Wysocki979f11b2011-02-08 23:42:09 +0100279 if (error)
280 return error;
Rafael J. Wysocki7a63f082011-02-08 23:41:57 +0100281 pr_info(PREFIX "Low-level resume complete\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
Arnaud Patard872d83d2006-04-27 05:25:00 -0400284
Matthew Garrettb6dacf62010-05-11 13:49:25 -0400285 /* This violates the spec but is required for bug compatibility. */
286 acpi_write_bit_register(ACPI_BITREG_SCI_ENABLE, 1);
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500287
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100288 /* Reprogram control registers and execute _BFS */
Lin Minga2ef5c42012-03-21 10:58:46 +0800289 acpi_leave_sleep_state_prep(acpi_state, flags);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100290
Pavel Machek23b168d2008-02-05 19:27:12 +0100291 /* ACPI 3.0 specs (P62) says that it's the responsibility
Arnaud Patard872d83d2006-04-27 05:25:00 -0400292 * of the OSPM to clear the status bit [ implying that the
293 * POWER_BUTTON event should not reach userspace ]
294 */
295 if (ACPI_SUCCESS(status) && (acpi_state == ACPI_STATE_S3))
296 acpi_clear_event(ACPI_EVENT_POWER_BUTTON);
297
Shaohua Lia3627f62007-06-20 09:17:58 +0800298 /*
299 * Disable and clear GPE status before interrupt is enabled. Some GPEs
300 * (like wakeup GPE) haven't handler, this can avoid such GPE misfire.
301 * acpi_leave_sleep_state will reenable specific GPEs later
302 */
Lin Ming3d97e422008-12-16 16:57:46 +0800303 acpi_disable_all_gpes();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200304 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200305 acpi_ec_unblock_transactions_early();
Shaohua Lia3627f62007-06-20 09:17:58 +0800306
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400307 suspend_nvs_restore();
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
310}
311
Len Brown2c6e33c2008-04-23 18:02:52 -0400312static int acpi_suspend_state_valid(suspend_state_t pm_state)
Shaohua Lieb9289e2005-10-30 15:00:01 -0800313{
Johannes Berge8c9c502007-04-30 15:09:54 -0700314 u32 acpi_state;
Shaohua Lieb9289e2005-10-30 15:00:01 -0800315
Johannes Berge8c9c502007-04-30 15:09:54 -0700316 switch (pm_state) {
317 case PM_SUSPEND_ON:
318 case PM_SUSPEND_STANDBY:
319 case PM_SUSPEND_MEM:
320 acpi_state = acpi_suspend_states[pm_state];
321
322 return sleep_states[acpi_state];
323 default:
324 return 0;
325 }
Shaohua Lieb9289e2005-10-30 15:00:01 -0800326}
327
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100328static const struct platform_suspend_ops acpi_suspend_ops = {
Len Brown2c6e33c2008-04-23 18:02:52 -0400329 .valid = acpi_suspend_state_valid,
330 .begin = acpi_suspend_begin,
Rafael J. Wysocki6a7c7ea2009-04-19 20:08:42 +0200331 .prepare_late = acpi_pm_prepare,
Len Brown2c6e33c2008-04-23 18:02:52 -0400332 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200333 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200334 .end = acpi_pm_end,
335};
336
337/**
338 * acpi_suspend_begin_old - Set the target system sleep state to the
339 * state associated with given @pm_state, if supported, and
340 * execute the _PTS control method. This function is used if the
341 * pre-ACPI 2.0 suspend ordering has been requested.
342 */
343static int acpi_suspend_begin_old(suspend_state_t pm_state)
344{
345 int error = acpi_suspend_begin(pm_state);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200346 if (!error)
347 error = __acpi_pm_prepare();
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200348
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200349 return error;
350}
351
352/*
353 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
354 * been requested.
355 */
Lionel Debroux2f55ac02010-11-16 14:14:02 +0100356static const struct platform_suspend_ops acpi_suspend_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200357 .valid = acpi_suspend_state_valid,
358 .begin = acpi_suspend_begin_old,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200359 .prepare_late = acpi_pm_pre_suspend,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200360 .enter = acpi_suspend_enter,
Rafael J. Wysocki618d7fd2010-07-02 00:14:57 +0200361 .wake = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200362 .end = acpi_pm_end,
363 .recover = acpi_pm_finish,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364};
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700365
366static int __init init_old_suspend_ordering(const struct dmi_system_id *d)
367{
368 old_suspend_ordering = true;
369 return 0;
370}
371
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400372static int __init init_nvs_nosave(const struct dmi_system_id *d)
373{
374 acpi_nvs_nosave();
375 return 0;
376}
377
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700378static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
379 {
380 .callback = init_old_suspend_ordering,
381 .ident = "Abit KN9 (nForce4 variant)",
382 .matches = {
383 DMI_MATCH(DMI_BOARD_VENDOR, "http://www.abit.com.tw/"),
384 DMI_MATCH(DMI_BOARD_NAME, "KN9 Series(NF-CK804)"),
385 },
386 },
Rafael J. Wysocki4fb507b2008-10-14 22:54:06 +0200387 {
388 .callback = init_old_suspend_ordering,
389 .ident = "HP xw4600 Workstation",
390 .matches = {
391 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
392 DMI_MATCH(DMI_PRODUCT_NAME, "HP xw4600 Workstation"),
393 },
394 },
Rafael J. Wysocki65df7842008-11-26 17:53:13 -0500395 {
Andy Whitcrofta1404492009-02-11 18:11:22 +0000396 .callback = init_old_suspend_ordering,
397 .ident = "Asus Pundit P1-AH2 (M2N8L motherboard)",
398 .matches = {
399 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTek Computer INC."),
400 DMI_MATCH(DMI_BOARD_NAME, "M2N8L"),
401 },
402 },
Zhang Rui45e77982009-03-15 22:13:44 -0400403 {
Zhao Yakui2a9ef8e2009-03-18 16:36:25 +0800404 .callback = init_old_suspend_ordering,
405 .ident = "Panasonic CF51-2L",
406 .matches = {
407 DMI_MATCH(DMI_BOARD_VENDOR,
408 "Matsushita Electric Industrial Co.,Ltd."),
409 DMI_MATCH(DMI_BOARD_NAME, "CF51-2L"),
410 },
411 },
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400412 {
413 .callback = init_nvs_nosave,
Dave Jonesd11c78e2011-10-19 23:15:11 +0200414 .ident = "Sony Vaio VGN-FW21E",
415 .matches = {
416 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
417 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW21E"),
418 },
419 },
420 {
421 .callback = init_nvs_nosave,
Dave Jonesddf6ce42011-11-03 00:58:59 +0100422 .ident = "Sony Vaio VPCEB17FX",
423 .matches = {
424 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
425 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
426 },
427 },
428 {
429 .callback = init_nvs_nosave,
Rafael J. Wysocki53998642010-09-24 16:46:14 -0400430 .ident = "Sony Vaio VGN-SR11M",
431 .matches = {
432 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
433 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR11M"),
434 },
435 },
436 {
437 .callback = init_nvs_nosave,
438 .ident = "Everex StepNote Series",
439 .matches = {
440 DMI_MATCH(DMI_SYS_VENDOR, "Everex Systems, Inc."),
441 DMI_MATCH(DMI_PRODUCT_NAME, "Everex StepNote Series"),
442 },
443 },
Rafael J. Wysockiaf489312010-10-17 21:01:21 +0200444 {
445 .callback = init_nvs_nosave,
446 .ident = "Sony Vaio VPCEB1Z1E",
447 .matches = {
448 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
449 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB1Z1E"),
450 },
451 },
Rafael J. Wysocki291a73c2010-12-12 21:10:42 +0100452 {
453 .callback = init_nvs_nosave,
454 .ident = "Sony Vaio VGN-NW130D",
455 .matches = {
456 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
457 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-NW130D"),
458 },
459 },
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100460 {
461 .callback = init_nvs_nosave,
Lan Tianyu93f77082012-01-21 09:23:56 +0800462 .ident = "Sony Vaio VPCCW29FX",
463 .matches = {
464 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
465 DMI_MATCH(DMI_PRODUCT_NAME, "VPCCW29FX"),
466 },
467 },
468 {
469 .callback = init_nvs_nosave,
Rafael J. Wysocki7b330702011-01-06 23:37:01 +0100470 .ident = "Averatec AV1020-ED2",
471 .matches = {
472 DMI_MATCH(DMI_SYS_VENDOR, "AVERATEC"),
473 DMI_MATCH(DMI_PRODUCT_NAME, "1000 Series"),
474 },
475 },
Zhang Ruibb0c5ed2011-07-30 01:40:48 -0400476 {
477 .callback = init_old_suspend_ordering,
478 .ident = "Asus A8N-SLI DELUXE",
479 .matches = {
480 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
481 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI DELUXE"),
482 },
483 },
484 {
485 .callback = init_old_suspend_ordering,
486 .ident = "Asus A8N-SLI Premium",
487 .matches = {
488 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
489 DMI_MATCH(DMI_BOARD_NAME, "A8N-SLI Premium"),
490 },
491 },
Rafael J. Wysocki89e8ea12011-10-06 20:35:03 +0200492 {
493 .callback = init_nvs_nosave,
494 .ident = "Sony Vaio VGN-SR26GN_P",
495 .matches = {
496 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
497 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-SR26GN_P"),
498 },
499 },
Bogdan Radulescu731b25a2011-10-06 20:35:12 +0200500 {
501 .callback = init_nvs_nosave,
502 .ident = "Sony Vaio VGN-FW520F",
503 .matches = {
504 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
505 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FW520F"),
506 },
507 },
Keng-Yu Lin5a50a7c2011-12-02 00:04:23 +0100508 {
509 .callback = init_nvs_nosave,
510 .ident = "Asus K54C",
511 .matches = {
512 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
513 DMI_MATCH(DMI_PRODUCT_NAME, "K54C"),
514 },
515 },
516 {
517 .callback = init_nvs_nosave,
518 .ident = "Asus K54HR",
519 .matches = {
520 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
521 DMI_MATCH(DMI_PRODUCT_NAME, "K54HR"),
522 },
523 },
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700524 {},
525};
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200526#endif /* CONFIG_SUSPEND */
527
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200528#ifdef CONFIG_HIBERNATION
Shaohua Libdfe6b72008-07-23 21:28:41 -0700529static unsigned long s4_hardware_signature;
530static struct acpi_table_facs *facs;
531static bool nosigcheck;
532
533void __init acpi_no_s4_hw_signature(void)
534{
535 nosigcheck = true;
536}
537
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100538static int acpi_hibernation_begin(void)
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700539{
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100540 int error;
541
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200542 error = nvs_nosave ? 0 : suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100543 if (!error) {
544 acpi_target_sleep_state = ACPI_STATE_S4;
545 acpi_sleep_tts_switch(acpi_target_sleep_state);
546 }
547
548 return error;
549}
550
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700551static int acpi_hibernation_enter(void)
552{
Lin Minga2ef5c42012-03-21 10:58:46 +0800553 u8 flags = wake_sleep_flags();
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700554 acpi_status status = AE_OK;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700555
556 ACPI_FLUSH_CPU_CACHE();
557
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700558 /* This shouldn't return. If it returns, we have a problem */
Lin Minga2ef5c42012-03-21 10:58:46 +0800559 status = acpi_enter_sleep_state(ACPI_STATE_S4, flags);
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100560 /* Reprogram control registers and execute _BFS */
Lin Minga2ef5c42012-03-21 10:58:46 +0800561 acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700562
563 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
564}
565
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700566static void acpi_hibernation_leave(void)
567{
Lin Minga2ef5c42012-03-21 10:58:46 +0800568 u8 flags = wake_sleep_flags();
569
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700570 /*
571 * If ACPI is not enabled by the BIOS and the boot kernel, we need to
572 * enable it here.
573 */
574 acpi_enable();
Rafael J. Wysockic95d47a2008-01-08 00:05:21 +0100575 /* Reprogram control registers and execute _BFS */
Lin Minga2ef5c42012-03-21 10:58:46 +0800576 acpi_leave_sleep_state_prep(ACPI_STATE_S4, flags);
Shaohua Libdfe6b72008-07-23 21:28:41 -0700577 /* Check the hardware signature */
578 if (facs && s4_hardware_signature != facs->hardware_signature) {
579 printk(KERN_EMERG "ACPI: Hardware changed while hibernated, "
580 "cannot resume!\n");
581 panic("ACPI S4 hardware signature mismatch");
582 }
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100583 /* Restore the NVS memory area */
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400584 suspend_nvs_restore();
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200585 /* Allow EC transactions to happen. */
Rafael J. Wysockife955682010-04-09 01:40:38 +0200586 acpi_ec_unblock_transactions_early();
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700587}
588
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200589static void acpi_pm_thaw(void)
Rafael J. Wysockif6bb13a2010-03-04 01:52:58 +0100590{
Rafael J. Wysockife955682010-04-09 01:40:38 +0200591 acpi_ec_unblock_transactions();
Lin Ming3d97e422008-12-16 16:57:46 +0800592 acpi_enable_all_runtime_gpes();
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700593}
594
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100595static const struct platform_hibernation_ops acpi_hibernation_ops = {
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100596 .begin = acpi_hibernation_begin,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200597 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200598 .pre_snapshot = acpi_pm_prepare,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400599 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200600 .prepare = acpi_pm_prepare,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700601 .enter = acpi_hibernation_enter,
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700602 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200603 .pre_restore = acpi_pm_freeze,
604 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700605};
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200606
607/**
608 * acpi_hibernation_begin_old - Set the target system sleep state to
609 * ACPI_STATE_S4 and execute the _PTS control method. This
610 * function is used if the pre-ACPI 2.0 suspend ordering has been
611 * requested.
612 */
613static int acpi_hibernation_begin_old(void)
614{
Zhao Yakuie49f7112008-08-12 10:20:22 +0800615 int error;
616 /*
617 * The _TTS object should always be evaluated before the _PTS object.
618 * When the old_suspended_ordering is true, the _PTS object is
619 * evaluated in the acpi_sleep_prepare.
620 */
621 acpi_sleep_tts_switch(ACPI_STATE_S4);
622
623 error = acpi_sleep_prepare(ACPI_STATE_S4);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200624
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100625 if (!error) {
Rafael J. Wysocki72ad5d72010-07-23 22:59:09 +0200626 if (!nvs_nosave)
Matthew Garrettdd4c4f12010-05-28 16:32:14 -0400627 error = suspend_nvs_alloc();
Rafael J. Wysocki3f4b0ef2008-10-26 20:52:15 +0100628 if (!error)
629 acpi_target_sleep_state = ACPI_STATE_S4;
630 }
631 return error;
632}
633
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200634/*
635 * The following callbacks are used if the pre-ACPI 2.0 suspend ordering has
636 * been requested.
637 */
Lionel Debroux073ef1f2010-11-09 21:48:49 +0100638static const struct platform_hibernation_ops acpi_hibernation_ops_old = {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200639 .begin = acpi_hibernation_begin_old,
640 .end = acpi_pm_end,
Rafael J. Wysockic5f7a1b2010-07-02 00:14:09 +0200641 .pre_snapshot = acpi_pm_pre_suspend,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200642 .prepare = acpi_pm_freeze,
Matthew Garrett2a6b6972010-05-28 16:32:15 -0400643 .finish = acpi_pm_finish,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200644 .enter = acpi_hibernation_enter,
645 .leave = acpi_hibernation_leave,
Rafael J. Wysockid5a64512010-04-09 01:39:40 +0200646 .pre_restore = acpi_pm_freeze,
647 .restore_cleanup = acpi_pm_thaw,
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200648 .recover = acpi_pm_finish,
649};
650#endif /* CONFIG_HIBERNATION */
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700651
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200652int acpi_suspend(u32 acpi_state)
653{
654 suspend_state_t states[] = {
655 [1] = PM_SUSPEND_STANDBY,
656 [3] = PM_SUSPEND_MEM,
657 [5] = PM_SUSPEND_MAX
658 };
659
660 if (acpi_state < 6 && states[acpi_state])
661 return pm_suspend(states[acpi_state]);
662 if (acpi_state == 4)
663 return hibernate();
664 return -EINVAL;
665}
666
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100667#ifdef CONFIG_PM
Shaohua Lifd4aff12007-07-17 22:40:25 +0200668/**
669 * acpi_pm_device_sleep_state - return preferred power state of ACPI device
670 * in the system sleep state given by %acpi_target_sleep_state
David Brownell2fe2de52008-06-05 01:15:40 +0200671 * @dev: device to examine; its driver model wakeup flags control
672 * whether it should be able to wake up the system
Shaohua Lifd4aff12007-07-17 22:40:25 +0200673 * @d_min_p: used to store the upper limit of allowed states range
674 * Return value: preferred power state of the device on success, -ENODEV on
675 * failure (ie. if there's no 'struct acpi_device' for @dev)
676 *
677 * Find the lowest power (highest number) ACPI device power state that
678 * device @dev can be in while the system is in the sleep state represented
679 * by %acpi_target_sleep_state. If @wake is nonzero, the device should be
680 * able to wake up the system from this sleep state. If @d_min_p is set,
681 * the highest power (lowest number) device power state of @dev allowed
682 * in this system sleep state is stored at the location pointed to by it.
683 *
684 * The caller must ensure that @dev is valid before using this function.
685 * The caller is also responsible for figuring out if the device is
686 * supposed to be able to wake up the system and passing this information
687 * via @wake.
688 */
689
David Brownell2fe2de52008-06-05 01:15:40 +0200690int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
Shaohua Lifd4aff12007-07-17 22:40:25 +0200691{
692 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
693 struct acpi_device *adev;
694 char acpi_method[] = "_SxD";
Matthew Wilcox27663c52008-10-10 02:22:59 -0400695 unsigned long long d_min, d_max;
Shaohua Lifd4aff12007-07-17 22:40:25 +0200696
697 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Shaohua Liead77592007-08-23 15:01:13 +0800698 printk(KERN_DEBUG "ACPI handle has no context!\n");
Shaohua Lifd4aff12007-07-17 22:40:25 +0200699 return -ENODEV;
700 }
701
702 acpi_method[2] = '0' + acpi_target_sleep_state;
703 /*
704 * If the sleep state is S0, we will return D3, but if the device has
705 * _S0W, we will use the value from _S0W
706 */
707 d_min = ACPI_STATE_D0;
708 d_max = ACPI_STATE_D3;
709
710 /*
711 * If present, _SxD methods return the minimum D-state (highest power
712 * state) we can use for the corresponding S-states. Otherwise, the
713 * minimum D-state is D0 (ACPI 3.x).
714 *
715 * NOTE: We rely on acpi_evaluate_integer() not clobbering the integer
716 * provided -- that's our fault recovery, we ignore retval.
717 */
718 if (acpi_target_sleep_state > ACPI_STATE_S0)
719 acpi_evaluate_integer(handle, acpi_method, NULL, &d_min);
720
721 /*
722 * If _PRW says we can wake up the system from the target sleep state,
723 * the D-state returned by _SxD is sufficient for that (we assume a
724 * wakeup-aware driver if wake is set). Still, if _SxW exists
725 * (ACPI 3.x), it should return the maximum (lowest power) D-state that
726 * can wake the system. _S0W may be valid, too.
727 */
728 if (acpi_target_sleep_state == ACPI_STATE_S0 ||
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200729 (device_may_wakeup(dev) &&
Shaohua Lifd4aff12007-07-17 22:40:25 +0200730 adev->wakeup.sleep_state <= acpi_target_sleep_state)) {
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100731 acpi_status status;
732
Shaohua Lifd4aff12007-07-17 22:40:25 +0200733 acpi_method[3] = 'W';
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100734 status = acpi_evaluate_integer(handle, acpi_method, NULL,
735 &d_max);
736 if (ACPI_FAILURE(status)) {
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200737 if (acpi_target_sleep_state != ACPI_STATE_S0 ||
738 status != AE_NOT_FOUND)
739 d_max = d_min;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100740 } else if (d_max < d_min) {
741 /* Warn the user of the broken DSDT */
742 printk(KERN_WARNING "ACPI: Wrong value from %s\n",
743 acpi_method);
744 /* Sanitize it */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200745 d_min = d_max;
Rafael J. Wysockiad3399c2008-01-11 00:10:38 +0100746 }
Shaohua Lifd4aff12007-07-17 22:40:25 +0200747 }
748
749 if (d_min_p)
750 *d_min_p = d_min;
751 return d_max;
752}
Rafael J. Wysockiaa338602011-02-11 00:06:54 +0100753#endif /* CONFIG_PM */
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200754
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200755#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200756/**
Lin Mingb24e5092012-03-27 15:43:25 +0800757 * acpi_pm_device_run_wake - Enable/disable wake-up for given device.
758 * @phys_dev: Device to enable/disable the platform to wake-up the system for.
759 * @enable: Whether enable or disable the wake-up functionality.
760 *
761 * Find the ACPI device object corresponding to @pci_dev and try to
762 * enable/disable the GPE associated with it.
763 */
764int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
765{
766 struct acpi_device *dev;
767 acpi_handle handle;
768
769 if (!device_run_wake(phys_dev))
770 return -EINVAL;
771
772 handle = DEVICE_ACPI_HANDLE(phys_dev);
773 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &dev))) {
774 dev_dbg(phys_dev, "ACPI handle has no context in %s!\n",
775 __func__);
776 return -ENODEV;
777 }
778
779 if (enable) {
780 acpi_enable_wakeup_device_power(dev, ACPI_STATE_S0);
781 acpi_enable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
782 } else {
783 acpi_disable_gpe(dev->wakeup.gpe_device, dev->wakeup.gpe_number);
784 acpi_disable_wakeup_device_power(dev);
785 }
786
787 return 0;
788}
789
790/**
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200791 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
792 * capability of given device
793 * @dev: device to handle
794 * @enable: 'true' - enable, 'false' - disable the wake-up capability
795 */
796int acpi_pm_device_sleep_wake(struct device *dev, bool enable)
797{
798 acpi_handle handle;
799 struct acpi_device *adev;
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200800 int error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200801
Rafael J. Wysocki0baed8d2009-09-08 23:16:24 +0200802 if (!device_can_wakeup(dev))
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200803 return -EINVAL;
804
805 handle = DEVICE_ACPI_HANDLE(dev);
806 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200807 dev_dbg(dev, "ACPI handle has no context in %s!\n", __func__);
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200808 return -ENODEV;
809 }
810
Rafael J. Wysockie8b6f972010-06-25 01:18:39 +0200811 error = enable ?
812 acpi_enable_wakeup_device_power(adev, acpi_target_sleep_state) :
813 acpi_disable_wakeup_device_power(adev);
Rafael J. Wysockidf8db912009-09-08 23:13:49 +0200814 if (!error)
815 dev_info(dev, "wake-up capability %s by ACPI\n",
816 enable ? "enabled" : "disabled");
817
818 return error;
Rafael J. Wysockieb9d0fe2008-07-07 03:34:48 +0200819}
Rafael J. Wysocki761afb82010-10-14 23:24:13 +0200820#endif /* CONFIG_PM_SLEEP */
Shaohua Lifd4aff12007-07-17 22:40:25 +0200821
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400822static void acpi_power_off_prepare(void)
823{
824 /* Prepare to power off the system */
825 acpi_sleep_prepare(ACPI_STATE_S5);
Lin Ming3d97e422008-12-16 16:57:46 +0800826 acpi_disable_all_gpes();
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400827}
828
829static void acpi_power_off(void)
830{
Lin Minga2ef5c42012-03-21 10:58:46 +0800831 u8 flags = wake_sleep_flags();
832
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400833 /* acpi_sleep_prepare(ACPI_STATE_S5) should have already been called */
Frank Seidel4d939152009-02-04 17:03:07 +0100834 printk(KERN_DEBUG "%s called\n", __func__);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400835 local_irq_disable();
Lin Minga2ef5c42012-03-21 10:58:46 +0800836 acpi_enter_sleep_state(ACPI_STATE_S5, flags);
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400837}
838
Len Brown96f15ef2009-04-17 23:32:20 -0400839/*
840 * ACPI 2.0 created the optional _GTS and _BFS,
841 * but industry adoption has been neither rapid nor broad.
842 *
843 * Linux gets into trouble when it executes poorly validated
844 * paths through the BIOS, so disable _GTS and _BFS by default,
845 * but do speak up and offer the option to enable them.
846 */
Stephen Hemminger01eac602010-10-18 18:47:25 -0700847static void __init acpi_gts_bfs_check(void)
Len Brown96f15ef2009-04-17 23:32:20 -0400848{
849 acpi_handle dummy;
850
Bob Moore4efeeec2012-03-21 09:42:45 +0800851 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__GTS, &dummy)))
Len Brown96f15ef2009-04-17 23:32:20 -0400852 {
853 printk(KERN_NOTICE PREFIX "BIOS offers _GTS\n");
854 printk(KERN_NOTICE PREFIX "If \"acpi.gts=1\" improves suspend, "
855 "please notify linux-acpi@vger.kernel.org\n");
856 }
Bob Moore4efeeec2012-03-21 09:42:45 +0800857 if (ACPI_SUCCESS(acpi_get_handle(ACPI_ROOT_OBJECT, METHOD_PATHNAME__BFS, &dummy)))
Len Brown96f15ef2009-04-17 23:32:20 -0400858 {
859 printk(KERN_NOTICE PREFIX "BIOS offers _BFS\n");
860 printk(KERN_NOTICE PREFIX "If \"acpi.bfs=1\" improves resume, "
861 "please notify linux-acpi@vger.kernel.org\n");
862 }
863}
864
Alexey Starikovskiyaafbcd12007-02-10 01:32:16 -0500865int __init acpi_sleep_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200867 acpi_status status;
868 u8 type_a, type_b;
869#ifdef CONFIG_SUSPEND
Alexey Starikovskiye2a5b422005-03-18 16:20:46 -0500870 int i = 0;
Carlos Corbachoe41fb7c2008-07-23 21:28:43 -0700871
872 dmi_check_system(acpisleep_dmi_table);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200873#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 if (acpi_disabled)
876 return 0;
877
Frans Pop5a50fe72007-09-20 22:27:44 +0200878 sleep_states[ACPI_STATE_S0] = 1;
879 printk(KERN_INFO PREFIX "(supports S0");
880
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200881#ifdef CONFIG_SUSPEND
Frans Pop5a50fe72007-09-20 22:27:44 +0200882 for (i = ACPI_STATE_S1; i < ACPI_STATE_S4; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 status = acpi_get_sleep_type_data(i, &type_a, &type_b);
884 if (ACPI_SUCCESS(status)) {
885 sleep_states[i] = 1;
886 printk(" S%d", i);
887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200890 suspend_set_ops(old_suspend_ordering ?
891 &acpi_suspend_ops_old : &acpi_suspend_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200892#endif
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700893
Rafael J. Wysockib0cb1a12007-07-29 23:24:36 +0200894#ifdef CONFIG_HIBERNATION
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200895 status = acpi_get_sleep_type_data(ACPI_STATE_S4, &type_a, &type_b);
896 if (ACPI_SUCCESS(status)) {
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200897 hibernation_set_ops(old_suspend_ordering ?
898 &acpi_hibernation_ops_old : &acpi_hibernation_ops);
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200899 sleep_states[ACPI_STATE_S4] = 1;
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400900 printk(" S4");
Shaohua Libdfe6b72008-07-23 21:28:41 -0700901 if (!nosigcheck) {
Lin Ming3d97e422008-12-16 16:57:46 +0800902 acpi_get_table(ACPI_SIG_FACS, 1,
Shaohua Libdfe6b72008-07-23 21:28:41 -0700903 (struct acpi_table_header **)&facs);
904 if (facs)
905 s4_hardware_signature =
906 facs->hardware_signature;
907 }
Rafael J. Wysocki296699d2007-07-29 23:27:18 +0200908 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700909#endif
Alexey Starikovskiyf216cc32007-09-20 21:32:35 +0400910 status = acpi_get_sleep_type_data(ACPI_STATE_S5, &type_a, &type_b);
911 if (ACPI_SUCCESS(status)) {
912 sleep_states[ACPI_STATE_S5] = 1;
913 printk(" S5");
914 pm_power_off_prepare = acpi_power_off_prepare;
915 pm_power_off = acpi_power_off;
916 }
917 printk(")\n");
Zhao Yakuie49f7112008-08-12 10:20:22 +0800918 /*
919 * Register the tts_notifier to reboot notifier list so that the _TTS
920 * object can also be evaluated when the system enters S5.
921 */
922 register_reboot_notifier(&tts_notifier);
Len Brown96f15ef2009-04-17 23:32:20 -0400923 acpi_gts_bfs_check();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 return 0;
925}