blob: 403bc3722fee914f13d82a912739c83b1f508895 [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;
29char resume_file[256] = CONFIG_PM_STD_PARTITION;
30dev_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
33/**
Stefan Seyfried8a05aac2006-12-06 20:34:21 -080034 * platform_prepare - prepare the machine for hibernation using the
35 * platform driver if so configured and return an error code if it fails
36 */
37
38static inline int platform_prepare(void)
39{
40 int error = 0;
41
Johannes Bergfe0c935a2007-04-30 15:09:51 -070042 switch (pm_disk_mode) {
43 case PM_DISK_TEST:
44 case PM_DISK_TESTPROC:
45 case PM_DISK_SHUTDOWN:
46 case PM_DISK_REBOOT:
47 break;
48 default:
Stefan Seyfried8a05aac2006-12-06 20:34:21 -080049 if (pm_ops && pm_ops->prepare)
50 error = pm_ops->prepare(PM_SUSPEND_DISK);
51 }
52 return error;
53}
54
55/**
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 * power_down - Shut machine down for hibernate.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
Johannes Bergfe0c935a2007-04-30 15:09:51 -070058 * Use the platform driver, if configured so; otherwise try
59 * to power off or reboot.
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 */
61
Johannes Bergfe0c935a2007-04-30 15:09:51 -070062static void power_down(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Johannes Bergfe0c935a2007-04-30 15:09:51 -070064 switch (pm_disk_mode) {
65 case PM_DISK_TEST:
66 case PM_DISK_TESTPROC:
67 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 case PM_DISK_SHUTDOWN:
Eric W. Biedermanfdde86a2005-07-26 12:01:17 -060069 kernel_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 break;
71 case PM_DISK_REBOOT:
Eric W. Biedermanfdde86a2005-07-26 12:01:17 -060072 kernel_restart(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 break;
Johannes Bergfe0c935a2007-04-30 15:09:51 -070074 default:
75 if (pm_ops && pm_ops->enter) {
76 kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK);
77 pm_ops->enter(PM_SUSPEND_DISK);
78 break;
79 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
Eric W. Biedermanfdde86a2005-07-26 12:01:17 -060081 kernel_halt();
Johannes Bergfe0c935a2007-04-30 15:09:51 -070082 /*
83 * Valid image is on the disk, if we continue we risk serious data
84 * corruption after resume.
85 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 printk(KERN_CRIT "Please power me down manually\n");
87 while(1);
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090static inline void platform_finish(void)
91{
Johannes Bergfe0c935a2007-04-30 15:09:51 -070092 switch (pm_disk_mode) {
93 case PM_DISK_TEST:
94 case PM_DISK_TESTPROC:
95 case PM_DISK_SHUTDOWN:
96 case PM_DISK_REBOOT:
97 break;
98 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (pm_ops && pm_ops->finish)
100 pm_ops->finish(PM_SUSPEND_DISK);
101 }
102}
103
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800104static void unprepare_processes(void)
105{
106 thaw_processes();
107 pm_restore_console();
108}
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static int prepare_processes(void)
111{
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800112 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 pm_prepare_console();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 if (freeze_processes()) {
116 error = -EBUSY;
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800117 unprepare_processes();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
Li Shaohua5a72e042005-06-25 14:55:06 -0700119 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/**
David Brownellf1cc0a82006-08-14 23:11:08 -0700123 * pm_suspend_disk - The granpappy of hibernation power management.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * If not, then call swsusp to do its thing, then figure out how
126 * to power down the system.
127 */
128
129int pm_suspend_disk(void)
130{
131 int error;
132
133 error = prepare_processes();
Li Shaohua5a72e042005-06-25 14:55:06 -0700134 if (error)
135 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800137 if (pm_disk_mode == PM_DISK_TESTPROC) {
138 printk("swsusp debug: Waiting for 5 seconds.\n");
139 mdelay(5000);
140 goto Thaw;
141 }
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700142 /* Allocate memory management structures */
143 error = create_basic_memory_bitmaps();
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800144 if (error)
145 goto Thaw;
146
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700147 /* Free memory before shutting down devices. */
148 error = swsusp_shrink_memory();
149 if (error)
150 goto Finish;
151
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800152 error = platform_prepare();
153 if (error)
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700154 goto Finish;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800155
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700156 suspend_console();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700157 error = device_suspend(PMSG_FREEZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 if (error) {
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800159 printk(KERN_ERR "PM: Some devices failed to suspend\n");
160 goto Resume_devices;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800161 }
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800162 error = disable_nonboot_cpus();
163 if (error)
164 goto Enable_cpus;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800165
166 if (pm_disk_mode == PM_DISK_TEST) {
167 printk("swsusp debug: Waiting for 5 seconds.\n");
168 mdelay(5000);
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800169 goto Enable_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 pr_debug("PM: snapshotting memory.\n");
173 in_suspend = 1;
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800174 error = swsusp_suspend();
175 if (error)
176 goto Enable_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 if (in_suspend) {
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800179 enable_nonboot_cpus();
180 platform_finish();
Rafael J. Wysocki0245b3e2005-10-30 15:00:01 -0800181 device_resume();
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700182 resume_console();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 pr_debug("PM: writing image.\n");
Rafael J. Wysockif577eb32006-03-23 02:59:59 -0800184 error = swsusp_write();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 if (!error)
Johannes Bergfe0c935a2007-04-30 15:09:51 -0700186 power_down();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700187 else {
Pavel Machek99dc7d62005-09-03 15:57:05 -0700188 swsusp_free();
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700189 goto Finish;
Pavel Machek99dc7d62005-09-03 15:57:05 -0700190 }
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800191 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 pr_debug("PM: Image restored successfully.\n");
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800193 }
Pavel Machek99dc7d62005-09-03 15:57:05 -0700194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 swsusp_free();
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800196 Enable_cpus:
197 enable_nonboot_cpus();
198 Resume_devices:
199 platform_finish();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700200 device_resume();
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700201 resume_console();
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700202 Finish:
203 free_basic_memory_bitmaps();
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800204 Thaw:
Pavel Machek99dc7d62005-09-03 15:57:05 -0700205 unprepare_processes();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return error;
207}
208
209
210/**
211 * software_resume - Resume from a saved image.
212 *
213 * Called as a late_initcall (so all devices are discovered and
214 * initialized), we call swsusp to see if we have a saved image or not.
215 * If so, we quiesce devices, the restore the saved image. We will
216 * return above (in pm_suspend_disk() ) if everything goes well.
217 * Otherwise, we fail gracefully and return to the normally
218 * scheduled program.
219 *
220 */
221
222static int software_resume(void)
223{
224 int error;
225
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800226 mutex_lock(&pm_mutex);
Pavel Machek3efa1472005-07-07 17:56:43 -0700227 if (!swsusp_resume_device) {
Shaohua Lidd5d6662005-09-03 15:57:04 -0700228 if (!strlen(resume_file)) {
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800229 mutex_unlock(&pm_mutex);
Pavel Machek3efa1472005-07-07 17:56:43 -0700230 return -ENOENT;
Shaohua Lidd5d6662005-09-03 15:57:04 -0700231 }
Pavel Machek3efa1472005-07-07 17:56:43 -0700232 swsusp_resume_device = name_to_dev_t(resume_file);
233 pr_debug("swsusp: Resume From Partition %s\n", resume_file);
234 } else {
235 pr_debug("swsusp: Resume From Partition %d:%d\n",
236 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
237 }
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (noresume) {
240 /**
241 * FIXME: If noresume is specified, we need to find the partition
242 * and reset it back to normal swap space.
243 */
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800244 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return 0;
246 }
247
248 pr_debug("PM: Checking swsusp image.\n");
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800249 error = swsusp_check();
250 if (error)
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700251 goto Unlock;
252
253 error = create_basic_memory_bitmaps();
254 if (error)
255 goto Unlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 pr_debug("PM: Preparing processes for restore.\n");
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800258 error = prepare_processes();
259 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 swsusp_close();
Li Shaohua5a72e042005-06-25 14:55:06 -0700261 goto Done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263
264 pr_debug("PM: Reading swsusp image.\n");
265
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800266 error = swsusp_read();
267 if (error) {
Rafael J. Wysocki2c1b4a52005-10-30 14:59:58 -0800268 swsusp_free();
269 goto Thaw;
270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 pr_debug("PM: Preparing devices for restore.\n");
273
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700274 suspend_console();
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800275 error = device_suspend(PMSG_PRETHAW);
276 if (error)
277 goto Free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800279 error = disable_nonboot_cpus();
280 if (!error)
281 swsusp_resume();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800283 enable_nonboot_cpus();
284 Free:
285 swsusp_free();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700286 device_resume();
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700287 resume_console();
Rafael J. Wysocki2c1b4a52005-10-30 14:59:58 -0800288 Thaw:
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800289 printk(KERN_ERR "PM: Restore failed, recovering.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 unprepare_processes();
291 Done:
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700292 free_basic_memory_bitmaps();
Shaohua Lidd5d6662005-09-03 15:57:04 -0700293 /* For success case, the suspend path will release the lock */
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700294 Unlock:
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800295 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 pr_debug("PM: Resume from disk failed.\n");
297 return 0;
298}
299
300late_initcall(software_resume);
301
302
Andreas Mohr3b364b82006-06-25 05:47:56 -0700303static const char * const pm_disk_modes[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 [PM_DISK_PLATFORM] = "platform",
305 [PM_DISK_SHUTDOWN] = "shutdown",
306 [PM_DISK_REBOOT] = "reboot",
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800307 [PM_DISK_TEST] = "test",
308 [PM_DISK_TESTPROC] = "testproc",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309};
310
311/**
312 * disk - Control suspend-to-disk mode
313 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700314 * Suspend-to-disk can be handled in several ways. We have a few options
315 * for putting the system to sleep - using the platform driver (e.g. ACPI
316 * or other pm_ops), powering off the system or rebooting the system
317 * (for testing) as well as the two test modes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700319 * The system can support 'platform', and that is known a priori (and
320 * encoded in pm_ops). However, the user may choose 'shutdown' or 'reboot'
321 * as alternatives, as well as the test modes 'test' and 'testproc'.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 *
323 * show() will display what the mode is currently set to.
324 * store() will accept one of
325 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 * 'platform'
327 * 'shutdown'
328 * 'reboot'
Johannes Berg11d77d02007-04-30 15:09:53 -0700329 * 'test'
330 * 'testproc'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700332 * It will only change to 'platform' if the system
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 * supports it (as determined from pm_ops->pm_disk_mode).
334 */
335
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700336static ssize_t disk_show(struct kset *kset, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 return sprintf(buf, "%s\n", pm_disk_modes[pm_disk_mode]);
339}
340
341
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700342static ssize_t disk_store(struct kset *kset, const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
344 int error = 0;
345 int i;
346 int len;
347 char *p;
348 suspend_disk_method_t mode = 0;
349
350 p = memchr(buf, '\n', n);
351 len = p ? p - buf : n;
352
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800353 mutex_lock(&pm_mutex);
Johannes Berg11d77d02007-04-30 15:09:53 -0700354 for (i = PM_DISK_PLATFORM; i < PM_DISK_MAX; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 if (!strncmp(buf, pm_disk_modes[i], len)) {
356 mode = i;
357 break;
358 }
359 }
360 if (mode) {
Johannes Bergfe0c935a2007-04-30 15:09:51 -0700361 switch (mode) {
362 case PM_DISK_SHUTDOWN:
363 case PM_DISK_REBOOT:
364 case PM_DISK_TEST:
365 case PM_DISK_TESTPROC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 pm_disk_mode = mode;
Johannes Bergfe0c935a2007-04-30 15:09:51 -0700367 break;
368 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (pm_ops && pm_ops->enter &&
370 (mode == pm_ops->pm_disk_mode))
371 pm_disk_mode = mode;
372 else
373 error = -EINVAL;
374 }
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800375 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 error = -EINVAL;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 pr_debug("PM: suspend-to-disk mode set to '%s'\n",
380 pm_disk_modes[mode]);
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800381 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return error ? error : n;
383}
384
385power_attr(disk);
386
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700387static ssize_t resume_show(struct kset *kset, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
389 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
390 MINOR(swsusp_resume_device));
391}
392
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700393static ssize_t resume_store(struct kset *kset, const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 unsigned int maj, min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 dev_t res;
Andrew Mortona5762192006-01-06 00:09:50 -0800397 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Andrew Mortona5762192006-01-06 00:09:50 -0800399 if (sscanf(buf, "%u:%u", &maj, &min) != 2)
400 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Andrew Mortona5762192006-01-06 00:09:50 -0800402 res = MKDEV(maj,min);
403 if (maj != MAJOR(res) || min != MINOR(res))
404 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800406 mutex_lock(&pm_mutex);
Andrew Mortona5762192006-01-06 00:09:50 -0800407 swsusp_resume_device = res;
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800408 mutex_unlock(&pm_mutex);
Andrew Mortona5762192006-01-06 00:09:50 -0800409 printk("Attempting manual resume\n");
410 noresume = 0;
411 software_resume();
412 ret = n;
Rafael J. Wysocki59a493352006-12-06 20:34:44 -0800413 out:
Andrew Mortona5762192006-01-06 00:09:50 -0800414 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
417power_attr(resume);
418
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700419static ssize_t image_size_show(struct kset *kset, char *buf)
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800420{
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800421 return sprintf(buf, "%lu\n", image_size);
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800422}
423
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700424static ssize_t image_size_store(struct kset *kset, const char *buf, size_t n)
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800425{
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800426 unsigned long size;
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800427
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800428 if (sscanf(buf, "%lu", &size) == 1) {
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800429 image_size = size;
430 return n;
431 }
432
433 return -EINVAL;
434}
435
436power_attr(image_size);
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438static struct attribute * g[] = {
439 &disk_attr.attr,
440 &resume_attr.attr,
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800441 &image_size_attr.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 NULL,
443};
444
445
446static struct attribute_group attr_group = {
447 .attrs = g,
448};
449
450
451static int __init pm_disk_init(void)
452{
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700453 return sysfs_create_group(&power_subsys.kobj, &attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
455
456core_initcall(pm_disk_init);
457
458
459static int __init resume_setup(char *str)
460{
461 if (noresume)
462 return 1;
463
464 strncpy( resume_file, str, 255 );
465 return 1;
466}
467
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -0800468static int __init resume_offset_setup(char *str)
469{
470 unsigned long long offset;
471
472 if (noresume)
473 return 1;
474
475 if (sscanf(str, "%llu", &offset) == 1)
476 swsusp_resume_block = offset;
477
478 return 1;
479}
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481static int __init noresume_setup(char *str)
482{
483 noresume = 1;
484 return 1;
485}
486
487__setup("noresume", noresume_setup);
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -0800488__setup("resume_offset=", resume_offset_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489__setup("resume=", resume_setup);