blob: f011e0870b52b316032295bc9b6ffcc45a4358ea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * kernel/power/disk.c - Suspend-to-disk support.
3 *
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 * Copyright (c) 2004 Pavel Machek <pavel@suse.cz>
7 *
8 * This file is released under the GPLv2.
9 *
10 */
11
12#include <linux/suspend.h>
13#include <linux/syscalls.h>
14#include <linux/reboot.h>
15#include <linux/string.h>
16#include <linux/device.h>
17#include <linux/delay.h>
18#include <linux/fs.h>
Andrew Mortond53d9f12005-07-12 13:58:07 -070019#include <linux/mount.h>
Eric W. Biederman88d10bb2005-09-22 21:43:46 -070020#include <linux/pm.h>
Rafael J. Wysocki97c78012006-10-11 01:20:45 -070021#include <linux/console.h>
Rafael J. Wysockie3920fb2006-09-25 23:32:48 -070022#include <linux/cpu.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080023#include <linux/freezer.h>
Andrew Mortond53d9f12005-07-12 13:58:07 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include "power.h"
26
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int noresume = 0;
Adrian Bunk47a460d2008-02-04 22:30:06 -080029static char resume_file[256] = CONFIG_PM_STD_PARTITION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030dev_t swsusp_resume_device;
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -080031sector_t swsusp_resume_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -070033enum {
34 HIBERNATION_INVALID,
35 HIBERNATION_PLATFORM,
36 HIBERNATION_TEST,
37 HIBERNATION_TESTPROC,
38 HIBERNATION_SHUTDOWN,
39 HIBERNATION_REBOOT,
40 /* keep last */
41 __HIBERNATION_AFTER_LAST
42};
43#define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
44#define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
45
46static int hibernation_mode = HIBERNATION_SHUTDOWN;
47
Rafael J. Wysockib3dac3b2007-10-18 03:04:43 -070048static struct platform_hibernation_ops *hibernation_ops;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -070049
50/**
51 * hibernation_set_ops - set the global hibernate operations
52 * @ops: the hibernation operations to use in subsequent hibernation transitions
53 */
54
Rafael J. Wysockib3dac3b2007-10-18 03:04:43 -070055void hibernation_set_ops(struct platform_hibernation_ops *ops)
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -070056{
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +010057 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
58 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -070059 && ops->restore_cleanup)) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -070060 WARN_ON(1);
61 return;
62 }
63 mutex_lock(&pm_mutex);
64 hibernation_ops = ops;
65 if (ops)
66 hibernation_mode = HIBERNATION_PLATFORM;
67 else if (hibernation_mode == HIBERNATION_PLATFORM)
68 hibernation_mode = HIBERNATION_SHUTDOWN;
69
70 mutex_unlock(&pm_mutex);
71}
72
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +010073#ifdef CONFIG_PM_DEBUG
74static void hibernation_debug_sleep(void)
75{
76 printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
77 mdelay(5000);
78}
79
80static int hibernation_testmode(int mode)
81{
82 if (hibernation_mode == mode) {
83 hibernation_debug_sleep();
84 return 1;
85 }
86 return 0;
87}
88
89static int hibernation_test(int level)
90{
91 if (pm_test_level == level) {
92 hibernation_debug_sleep();
93 return 1;
94 }
95 return 0;
96}
97#else /* !CONFIG_PM_DEBUG */
98static int hibernation_testmode(int mode) { return 0; }
99static int hibernation_test(int level) { return 0; }
100#endif /* !CONFIG_PM_DEBUG */
101
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700102/**
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100103 * platform_begin - tell the platform driver that we're starting
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700104 * hibernation
105 */
106
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100107static int platform_begin(int platform_mode)
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700108{
109 return (platform_mode && hibernation_ops) ?
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100110 hibernation_ops->begin() : 0;
111}
112
113/**
114 * platform_end - tell the platform driver that we've entered the
115 * working state
116 */
117
118static void platform_end(int platform_mode)
119{
120 if (platform_mode && hibernation_ops)
121 hibernation_ops->end();
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700122}
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/**
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700125 * platform_pre_snapshot - prepare the machine for hibernation using the
Stefan Seyfried8a05aac2006-12-06 20:34:21 -0800126 * platform driver if so configured and return an error code if it fails
127 */
128
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700129static int platform_pre_snapshot(int platform_mode)
Stefan Seyfried8a05aac2006-12-06 20:34:21 -0800130{
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700131 return (platform_mode && hibernation_ops) ?
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700132 hibernation_ops->pre_snapshot() : 0;
Stefan Seyfried8a05aac2006-12-06 20:34:21 -0800133}
134
135/**
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700136 * platform_leave - prepare the machine for switching to the normal mode
137 * of operation using the platform driver (called with interrupts disabled)
138 */
139
140static void platform_leave(int platform_mode)
141{
142 if (platform_mode && hibernation_ops)
143 hibernation_ops->leave();
144}
145
146/**
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700147 * platform_finish - switch the machine to the normal mode of operation
148 * using the platform driver (must be called after platform_prepare())
149 */
150
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700151static void platform_finish(int platform_mode)
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700152{
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700153 if (platform_mode && hibernation_ops)
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700154 hibernation_ops->finish();
155}
156
157/**
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700158 * platform_pre_restore - prepare the platform for the restoration from a
159 * hibernation image. If the restore fails after this function has been
160 * called, platform_restore_cleanup() must be called.
161 */
162
163static int platform_pre_restore(int platform_mode)
164{
165 return (platform_mode && hibernation_ops) ?
166 hibernation_ops->pre_restore() : 0;
167}
168
169/**
170 * platform_restore_cleanup - switch the platform to the normal mode of
171 * operation after a failing restore. If platform_pre_restore() has been
172 * called before the failing restore, this function must be called too,
173 * regardless of the result of platform_pre_restore().
174 */
175
176static void platform_restore_cleanup(int platform_mode)
177{
178 if (platform_mode && hibernation_ops)
179 hibernation_ops->restore_cleanup();
180}
181
182/**
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200183 * platform_recover - recover the platform from a failure to suspend
184 * devices.
185 */
186
187static void platform_recover(int platform_mode)
188{
189 if (platform_mode && hibernation_ops && hibernation_ops->recover)
190 hibernation_ops->recover();
191}
192
193/**
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700194 * create_image - freeze devices that need to be frozen with interrupts
195 * off, create the hibernation image and thaw those devices. Control
196 * reappears in this routine after a restore.
197 */
198
Adrian Bunk47a460d2008-02-04 22:30:06 -0800199static int create_image(int platform_mode)
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700200{
201 int error;
202
203 error = arch_prepare_suspend();
204 if (error)
205 return error;
206
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200207 device_pm_lock();
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700208 local_irq_disable();
209 /* At this point, device_suspend() has been called, but *not*
210 * device_power_down(). We *must* call device_power_down() now.
211 * Otherwise, drivers for some devices (e.g. interrupt controllers)
212 * become desynchronized with the actual state of the hardware
213 * at resume time, and evil weirdness ensues.
214 */
215 error = device_power_down(PMSG_FREEZE);
216 if (error) {
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100217 printk(KERN_ERR "PM: Some devices failed to power down, "
218 "aborting hibernation\n");
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700219 goto Enable_irqs;
220 }
221
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100222 if (hibernation_test(TEST_CORE))
223 goto Power_up;
224
225 in_suspend = 1;
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700226 save_processor_state();
227 error = swsusp_arch_suspend();
228 if (error)
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100229 printk(KERN_ERR "PM: Error %d creating hibernation image\n",
230 error);
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700231 /* Restore control flow magically appears here */
232 restore_processor_state();
233 if (!in_suspend)
234 platform_leave(platform_mode);
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100235 Power_up:
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700236 /* NOTE: device_power_up() is just a resume() for devices
237 * that suspended with irqs off ... no overall powerup.
238 */
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200239 device_power_up(in_suspend ?
240 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700241 Enable_irqs:
242 local_irq_enable();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200243 device_pm_unlock();
Rafael J. Wysockic7e08312007-10-18 03:04:55 -0700244 return error;
245}
246
247/**
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700248 * hibernation_snapshot - quiesce devices and create the hibernation
249 * snapshot image.
250 * @platform_mode - if set, use the platform driver, if available, to
251 * prepare the platform frimware for the power transition.
252 *
253 * Must be called with pm_mutex held
254 */
255
256int hibernation_snapshot(int platform_mode)
257{
258 int error;
259
260 /* Free memory before shutting down devices. */
261 error = swsusp_shrink_memory();
262 if (error)
Rafael J. Wysocki10a18032007-07-19 01:47:31 -0700263 return error;
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700264
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100265 error = platform_begin(platform_mode);
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700266 if (error)
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100267 goto Close;
Rafael J. Wysocki74f270a2007-10-18 03:04:42 -0700268
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700269 suspend_console();
270 error = device_suspend(PMSG_FREEZE);
271 if (error)
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200272 goto Recover_platform;
Rafael J. Wysocki10a18032007-07-19 01:47:31 -0700273
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100274 if (hibernation_test(TEST_DEVICES))
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200275 goto Recover_platform;
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700276
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100277 error = platform_pre_snapshot(platform_mode);
278 if (error || hibernation_test(TEST_PLATFORM))
279 goto Finish;
280
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700281 error = disable_nonboot_cpus();
282 if (!error) {
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100283 if (hibernation_test(TEST_CPUS))
284 goto Enable_cpus;
285
286 if (hibernation_testmode(HIBERNATION_TEST))
287 goto Enable_cpus;
288
289 error = create_image(platform_mode);
290 /* Control returns here after successful restore */
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700291 }
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100292 Enable_cpus:
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700293 enable_nonboot_cpus();
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100294 Finish:
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700295 platform_finish(platform_mode);
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100296 Resume_devices:
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200297 device_resume(in_suspend ?
298 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700299 resume_console();
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100300 Close:
301 platform_end(platform_mode);
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700302 return error;
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200303
304 Recover_platform:
305 platform_recover(platform_mode);
306 goto Resume_devices;
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700307}
308
309/**
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100310 * resume_target_kernel - prepare devices that need to be suspended with
311 * interrupts off, restore the contents of highmem that have not been
312 * restored yet from the image and run the low level code that will restore
313 * the remaining contents of memory and switch to the just restored target
314 * kernel.
315 */
316
317static int resume_target_kernel(void)
318{
319 int error;
320
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200321 device_pm_lock();
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100322 local_irq_disable();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200323 error = device_power_down(PMSG_QUIESCE);
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100324 if (error) {
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100325 printk(KERN_ERR "PM: Some devices failed to power down, "
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100326 "aborting resume\n");
327 goto Enable_irqs;
328 }
329 /* We'll ignore saved state, but this gets preempt count (etc) right */
330 save_processor_state();
331 error = restore_highmem();
332 if (!error) {
333 error = swsusp_arch_resume();
334 /*
335 * The code below is only ever reached in case of a failure.
336 * Otherwise execution continues at place where
337 * swsusp_arch_suspend() was called
338 */
339 BUG_ON(!error);
340 /* This call to restore_highmem() undos the previous one */
341 restore_highmem();
342 }
343 /*
344 * The only reason why swsusp_arch_resume() can fail is memory being
345 * very tight, so we have to free it as soon as we can to avoid
346 * subsequent failures
347 */
348 swsusp_free();
349 restore_processor_state();
350 touch_softlockup_watchdog();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200351 device_power_up(PMSG_RECOVER);
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100352 Enable_irqs:
353 local_irq_enable();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200354 device_pm_unlock();
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100355 return error;
356}
357
358/**
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700359 * hibernation_restore - quiesce devices and restore the hibernation
360 * snapshot image. If successful, control returns in hibernation_snaphot()
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700361 * @platform_mode - if set, use the platform driver, if available, to
362 * prepare the platform frimware for the transition.
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700363 *
364 * Must be called with pm_mutex held
365 */
366
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700367int hibernation_restore(int platform_mode)
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700368{
369 int error;
370
371 pm_prepare_console();
372 suspend_console();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200373 error = device_suspend(PMSG_QUIESCE);
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700374 if (error)
375 goto Finish;
376
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700377 error = platform_pre_restore(platform_mode);
378 if (!error) {
379 error = disable_nonboot_cpus();
380 if (!error)
Rafael J. Wysocki72df68c2007-12-08 02:04:21 +0100381 error = resume_target_kernel();
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700382 enable_nonboot_cpus();
383 }
384 platform_restore_cleanup(platform_mode);
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200385 device_resume(PMSG_RECOVER);
Rafael J. Wysocki10a18032007-07-19 01:47:31 -0700386 Finish:
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700387 resume_console();
388 pm_restore_console();
389 return error;
390}
391
392/**
393 * hibernation_platform_enter - enter the hibernation state using the
394 * platform driver (if available)
395 */
396
397int hibernation_platform_enter(void)
398{
Rafael J. Wysockib1457bc2007-07-19 01:47:31 -0700399 int error;
400
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700401 if (!hibernation_ops)
402 return -ENOSYS;
403
404 /*
405 * We have cancelled the power transition by running
406 * hibernation_ops->finish() before saving the image, so we should let
407 * the firmware know that we're going to enter the sleep state after all
408 */
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100409 error = hibernation_ops->begin();
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700410 if (error)
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100411 goto Close;
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700412
413 suspend_console();
Rafael J. Wysocki3a2d5b72008-02-23 19:13:25 +0100414 error = device_suspend(PMSG_HIBERNATE);
Rafael J. Wysockid8f3de02008-06-12 23:24:06 +0200415 if (error) {
416 if (hibernation_ops->recover)
417 hibernation_ops->recover();
418 goto Resume_devices;
419 }
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700420
421 error = hibernation_ops->prepare();
422 if (error)
423 goto Resume_devices;
424
425 error = disable_nonboot_cpus();
426 if (error)
427 goto Finish;
428
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200429 device_pm_lock();
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700430 local_irq_disable();
Rafael J. Wysocki3a2d5b72008-02-23 19:13:25 +0100431 error = device_power_down(PMSG_HIBERNATE);
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700432 if (!error) {
433 hibernation_ops->enter();
434 /* We should never get here */
435 while (1);
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700436 }
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700437 local_irq_enable();
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200438 device_pm_unlock();
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700439
440 /*
441 * We don't need to reenable the nonboot CPUs or resume consoles, since
442 * the system is going to be halted anyway.
443 */
444 Finish:
445 hibernation_ops->finish();
446 Resume_devices:
Rafael J. Wysocki1eede072008-05-20 23:00:01 +0200447 device_resume(PMSG_RESTORE);
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700448 resume_console();
Rafael J. Wysockicaea99e2008-01-08 00:08:44 +0100449 Close:
450 hibernation_ops->end();
Rafael J. Wysockib1457bc2007-07-19 01:47:31 -0700451 return error;
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700452}
453
454/**
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700455 * power_down - Shut the machine down for hibernation.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 *
Johannes Bergfe0c9352007-04-30 15:09:51 -0700457 * Use the platform driver, if configured so; otherwise try
458 * to power off or reboot.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 */
460
Johannes Bergfe0c9352007-04-30 15:09:51 -0700461static void power_down(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700463 switch (hibernation_mode) {
464 case HIBERNATION_TEST:
465 case HIBERNATION_TESTPROC:
Johannes Bergfe0c9352007-04-30 15:09:51 -0700466 break;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700467 case HIBERNATION_REBOOT:
Eric W. Biedermanfdde86a2005-07-26 12:01:17 -0600468 kernel_restart(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 break;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700470 case HIBERNATION_PLATFORM:
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700471 hibernation_platform_enter();
Rafael J. Wysocki9cd9a002007-10-18 03:04:56 -0700472 case HIBERNATION_SHUTDOWN:
473 kernel_power_off();
474 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
Eric W. Biedermanfdde86a2005-07-26 12:01:17 -0600476 kernel_halt();
Johannes Bergfe0c9352007-04-30 15:09:51 -0700477 /*
478 * Valid image is on the disk, if we continue we risk serious data
479 * corruption after resume.
480 */
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100481 printk(KERN_CRIT "PM: Please power down manually\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 while(1);
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485static int prepare_processes(void)
486{
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800487 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (freeze_processes()) {
490 error = -EBUSY;
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100491 thaw_processes();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
Li Shaohua5a72e042005-06-25 14:55:06 -0700493 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496/**
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700497 * hibernate - The granpappy of the built-in hibernation management
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 */
499
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700500int hibernate(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501{
502 int error;
503
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700504 mutex_lock(&pm_mutex);
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700505 /* The snapshot device should not be opened while we're running */
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700506 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
507 error = -EBUSY;
508 goto Unlock;
509 }
510
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100511 pm_prepare_console();
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700512 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
513 if (error)
514 goto Exit;
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700515
516 /* Allocate memory management structures */
517 error = create_basic_memory_bitmaps();
518 if (error)
519 goto Exit;
520
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100521 printk(KERN_INFO "PM: Syncing filesystems ... ");
Rafael J. Wysocki232b1432007-10-18 03:04:44 -0700522 sys_sync();
523 printk("done.\n");
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 error = prepare_processes();
Li Shaohua5a72e042005-06-25 14:55:06 -0700526 if (error)
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700527 goto Finish;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100529 if (hibernation_test(TEST_FREEZER))
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800530 goto Thaw;
Rafael J. Wysocki4cc79772007-11-19 23:42:31 +0100531
532 if (hibernation_testmode(HIBERNATION_TESTPROC))
533 goto Thaw;
534
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700535 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
536 if (in_suspend && !error) {
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700537 unsigned int flags = 0;
538
539 if (hibernation_mode == HIBERNATION_PLATFORM)
540 flags |= SF_PLATFORM_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 pr_debug("PM: writing image.\n");
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700542 error = swsusp_write(flags);
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700543 swsusp_free();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (!error)
Johannes Bergfe0c9352007-04-30 15:09:51 -0700545 power_down();
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800546 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 pr_debug("PM: Image restored successfully.\n");
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700548 swsusp_free();
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800549 }
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800550 Thaw:
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100551 thaw_processes();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700552 Finish:
553 free_basic_memory_bitmaps();
554 Exit:
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700555 pm_notifier_call_chain(PM_POST_HIBERNATION);
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100556 pm_restore_console();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700557 atomic_inc(&snapshot_device_available);
Rafael J. Wysockib10d9112007-07-19 01:47:36 -0700558 Unlock:
559 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return error;
561}
562
563
564/**
565 * software_resume - Resume from a saved image.
566 *
567 * Called as a late_initcall (so all devices are discovered and
568 * initialized), we call swsusp to see if we have a saved image or not.
569 * If so, we quiesce devices, the restore the saved image. We will
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700570 * return above (in hibernate() ) if everything goes well.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * Otherwise, we fail gracefully and return to the normally
572 * scheduled program.
573 *
574 */
575
576static int software_resume(void)
577{
578 int error;
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700579 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Johannes Berg60a0d232007-11-14 17:00:16 -0800581 /*
582 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
583 * is configured into the kernel. Since the regular hibernate
584 * trigger path is via sysfs which takes a buffer mutex before
585 * calling hibernate functions (which take pm_mutex) this can
586 * cause lockdep to complain about a possible ABBA deadlock
587 * which cannot happen since we're in the boot code here and
588 * sysfs can't be invoked yet. Therefore, we use a subclass
589 * here to avoid lockdep complaining.
590 */
591 mutex_lock_nested(&pm_mutex, SINGLE_DEPTH_NESTING);
Pavel Machek3efa1472005-07-07 17:56:43 -0700592 if (!swsusp_resume_device) {
Shaohua Lidd5d6662005-09-03 15:57:04 -0700593 if (!strlen(resume_file)) {
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800594 mutex_unlock(&pm_mutex);
Pavel Machek3efa1472005-07-07 17:56:43 -0700595 return -ENOENT;
Shaohua Lidd5d6662005-09-03 15:57:04 -0700596 }
Pavel Machek3efa1472005-07-07 17:56:43 -0700597 swsusp_resume_device = name_to_dev_t(resume_file);
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100598 pr_debug("PM: Resume from partition %s\n", resume_file);
Pavel Machek3efa1472005-07-07 17:56:43 -0700599 } else {
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100600 pr_debug("PM: Resume from partition %d:%d\n",
601 MAJOR(swsusp_resume_device),
602 MINOR(swsusp_resume_device));
Pavel Machek3efa1472005-07-07 17:56:43 -0700603 }
604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 if (noresume) {
606 /**
Rafael J. Wysocki95758092007-12-08 02:06:57 +0100607 * FIXME: If noresume is specified, we need to find the
608 * partition and reset it back to normal swap space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 */
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800610 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 return 0;
612 }
613
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100614 pr_debug("PM: Checking hibernation image.\n");
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800615 error = swsusp_check();
616 if (error)
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700617 goto Unlock;
618
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700619 /* The snapshot device should not be opened while we're running */
620 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
621 error = -EBUSY;
622 goto Unlock;
623 }
624
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100625 pm_prepare_console();
Alan Sternc3e94d82007-11-19 23:38:25 +0100626 error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
627 if (error)
628 goto Finish;
629
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700630 error = create_basic_memory_bitmaps();
631 if (error)
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700632 goto Finish;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 pr_debug("PM: Preparing processes for restore.\n");
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800635 error = prepare_processes();
636 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 swsusp_close();
Li Shaohua5a72e042005-06-25 14:55:06 -0700638 goto Done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100641 pr_debug("PM: Reading hibernation image.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700643 error = swsusp_read(&flags);
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800644 if (!error)
Rafael J. Wysockia634cc12007-07-19 01:47:30 -0700645 hibernation_restore(flags & SF_PLATFORM_MODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800647 printk(KERN_ERR "PM: Restore failed, recovering.\n");
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700648 swsusp_free();
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100649 thaw_processes();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 Done:
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700651 free_basic_memory_bitmaps();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700652 Finish:
Alan Sternc3e94d82007-11-19 23:38:25 +0100653 pm_notifier_call_chain(PM_POST_RESTORE);
Rafael J. Wysocki5a0a2f32008-01-11 01:25:21 +0100654 pm_restore_console();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700655 atomic_inc(&snapshot_device_available);
Shaohua Lidd5d6662005-09-03 15:57:04 -0700656 /* For success case, the suspend path will release the lock */
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700657 Unlock:
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800658 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 pr_debug("PM: Resume from disk failed.\n");
Rafael J. Wysocki7777fab2007-07-19 01:47:29 -0700660 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
663late_initcall(software_resume);
664
665
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700666static const char * const hibernation_modes[] = {
667 [HIBERNATION_PLATFORM] = "platform",
668 [HIBERNATION_SHUTDOWN] = "shutdown",
669 [HIBERNATION_REBOOT] = "reboot",
670 [HIBERNATION_TEST] = "test",
671 [HIBERNATION_TESTPROC] = "testproc",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672};
673
674/**
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700675 * disk - Control hibernation mode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700677 * Suspend-to-disk can be handled in several ways. We have a few options
678 * for putting the system to sleep - using the platform driver (e.g. ACPI
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700679 * or other hibernation_ops), powering off the system or rebooting the
680 * system (for testing) as well as the two test modes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700682 * The system can support 'platform', and that is known a priori (and
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700683 * encoded by the presence of hibernation_ops). However, the user may
684 * choose 'shutdown' or 'reboot' as alternatives, as well as one fo the
685 * test modes, 'test' or 'testproc'.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 *
687 * show() will display what the mode is currently set to.
688 * store() will accept one of
689 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 * 'platform'
691 * 'shutdown'
692 * 'reboot'
Johannes Berg11d77d02007-04-30 15:09:53 -0700693 * 'test'
694 * 'testproc'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700696 * It will only change to 'platform' if the system
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700697 * supports it (as determined by having hibernation_ops).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 */
699
Kay Sievers386f2752007-11-02 13:47:53 +0100700static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
701 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Johannes Bergf0ced9b2007-05-06 14:50:50 -0700703 int i;
704 char *start = buf;
705
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700706 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
707 if (!hibernation_modes[i])
Johannes Bergf0ced9b2007-05-06 14:50:50 -0700708 continue;
709 switch (i) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700710 case HIBERNATION_SHUTDOWN:
711 case HIBERNATION_REBOOT:
712 case HIBERNATION_TEST:
713 case HIBERNATION_TESTPROC:
Johannes Bergf0ced9b2007-05-06 14:50:50 -0700714 break;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700715 case HIBERNATION_PLATFORM:
716 if (hibernation_ops)
Johannes Bergf0ced9b2007-05-06 14:50:50 -0700717 break;
718 /* not a valid mode, continue with loop */
719 continue;
720 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700721 if (i == hibernation_mode)
722 buf += sprintf(buf, "[%s] ", hibernation_modes[i]);
Johannes Bergf0ced9b2007-05-06 14:50:50 -0700723 else
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700724 buf += sprintf(buf, "%s ", hibernation_modes[i]);
Johannes Bergf0ced9b2007-05-06 14:50:50 -0700725 }
726 buf += sprintf(buf, "\n");
727 return buf-start;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728}
729
730
Kay Sievers386f2752007-11-02 13:47:53 +0100731static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
732 const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 int error = 0;
735 int i;
736 int len;
737 char *p;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700738 int mode = HIBERNATION_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 p = memchr(buf, '\n', n);
741 len = p ? p - buf : n;
742
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800743 mutex_lock(&pm_mutex);
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700744 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
Rafael J. Wysocki8d98a692007-05-16 22:11:19 -0700745 if (len == strlen(hibernation_modes[i])
746 && !strncmp(buf, hibernation_modes[i], len)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 mode = i;
748 break;
749 }
750 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700751 if (mode != HIBERNATION_INVALID) {
Johannes Bergfe0c9352007-04-30 15:09:51 -0700752 switch (mode) {
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700753 case HIBERNATION_SHUTDOWN:
754 case HIBERNATION_REBOOT:
755 case HIBERNATION_TEST:
756 case HIBERNATION_TESTPROC:
757 hibernation_mode = mode;
Johannes Bergfe0c9352007-04-30 15:09:51 -0700758 break;
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700759 case HIBERNATION_PLATFORM:
760 if (hibernation_ops)
761 hibernation_mode = mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 else
763 error = -EINVAL;
764 }
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700765 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 error = -EINVAL;
767
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700768 if (!error)
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100769 pr_debug("PM: Hibernation mode set to '%s'\n",
Rafael J. Wysockia3d25c22007-05-09 02:33:18 -0700770 hibernation_modes[mode]);
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800771 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 return error ? error : n;
773}
774
775power_attr(disk);
776
Kay Sievers386f2752007-11-02 13:47:53 +0100777static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
778 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
781 MINOR(swsusp_resume_device));
782}
783
Kay Sievers386f2752007-11-02 13:47:53 +0100784static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
785 const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 unsigned int maj, min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 dev_t res;
Andrew Mortona5762192006-01-06 00:09:50 -0800789 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Andrew Mortona5762192006-01-06 00:09:50 -0800791 if (sscanf(buf, "%u:%u", &maj, &min) != 2)
792 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Andrew Mortona5762192006-01-06 00:09:50 -0800794 res = MKDEV(maj,min);
795 if (maj != MAJOR(res) || min != MINOR(res))
796 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800798 mutex_lock(&pm_mutex);
Andrew Mortona5762192006-01-06 00:09:50 -0800799 swsusp_resume_device = res;
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800800 mutex_unlock(&pm_mutex);
Rafael J. Wysocki23976722007-12-08 02:09:43 +0100801 printk(KERN_INFO "PM: Starting manual resume from disk\n");
Andrew Mortona5762192006-01-06 00:09:50 -0800802 noresume = 0;
803 software_resume();
804 ret = n;
Rafael J. Wysocki59a49332006-12-06 20:34:44 -0800805 out:
Andrew Mortona5762192006-01-06 00:09:50 -0800806 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807}
808
809power_attr(resume);
810
Kay Sievers386f2752007-11-02 13:47:53 +0100811static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
812 char *buf)
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800813{
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800814 return sprintf(buf, "%lu\n", image_size);
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800815}
816
Kay Sievers386f2752007-11-02 13:47:53 +0100817static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
818 const char *buf, size_t n)
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800819{
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800820 unsigned long size;
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800821
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800822 if (sscanf(buf, "%lu", &size) == 1) {
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800823 image_size = size;
824 return n;
825 }
826
827 return -EINVAL;
828}
829
830power_attr(image_size);
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832static struct attribute * g[] = {
833 &disk_attr.attr,
834 &resume_attr.attr,
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800835 &image_size_attr.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 NULL,
837};
838
839
840static struct attribute_group attr_group = {
841 .attrs = g,
842};
843
844
845static int __init pm_disk_init(void)
846{
Greg Kroah-Hartmand76e15f2007-11-27 11:28:26 -0800847 return sysfs_create_group(power_kobj, &attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
850core_initcall(pm_disk_init);
851
852
853static int __init resume_setup(char *str)
854{
855 if (noresume)
856 return 1;
857
858 strncpy( resume_file, str, 255 );
859 return 1;
860}
861
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -0800862static int __init resume_offset_setup(char *str)
863{
864 unsigned long long offset;
865
866 if (noresume)
867 return 1;
868
869 if (sscanf(str, "%llu", &offset) == 1)
870 swsusp_resume_block = offset;
871
872 return 1;
873}
874
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875static int __init noresume_setup(char *str)
876{
877 noresume = 1;
878 return 1;
879}
880
881__setup("noresume", noresume_setup);
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -0800882__setup("resume_offset=", resume_offset_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883__setup("resume=", resume_setup);