blob: e518379b667a77a6df39321c3bed94dcafbb1f2d [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
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700133 /* The snapshot device should not be opened while we're running */
134 if (!atomic_add_unless(&snapshot_device_available, -1, 0))
135 return -EBUSY;
136
137 /* Allocate memory management structures */
138 error = create_basic_memory_bitmaps();
139 if (error)
140 goto Exit;
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 error = prepare_processes();
Li Shaohua5a72e042005-06-25 14:55:06 -0700143 if (error)
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700144 goto Finish;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800146 if (pm_disk_mode == PM_DISK_TESTPROC) {
147 printk("swsusp debug: Waiting for 5 seconds.\n");
148 mdelay(5000);
149 goto Thaw;
150 }
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800151
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700152 /* Free memory before shutting down devices. */
153 error = swsusp_shrink_memory();
154 if (error)
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700155 goto Thaw;
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700156
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800157 error = platform_prepare();
158 if (error)
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700159 goto Thaw;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800160
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700161 suspend_console();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700162 error = device_suspend(PMSG_FREEZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (error) {
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800164 printk(KERN_ERR "PM: Some devices failed to suspend\n");
165 goto Resume_devices;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800166 }
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800167 error = disable_nonboot_cpus();
168 if (error)
169 goto Enable_cpus;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800170
171 if (pm_disk_mode == PM_DISK_TEST) {
172 printk("swsusp debug: Waiting for 5 seconds.\n");
173 mdelay(5000);
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800174 goto Enable_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 pr_debug("PM: snapshotting memory.\n");
178 in_suspend = 1;
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800179 error = swsusp_suspend();
180 if (error)
181 goto Enable_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 if (in_suspend) {
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800184 enable_nonboot_cpus();
185 platform_finish();
Rafael J. Wysocki0245b3e2005-10-30 15:00:01 -0800186 device_resume();
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700187 resume_console();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 pr_debug("PM: writing image.\n");
Rafael J. Wysockif577eb32006-03-23 02:59:59 -0800189 error = swsusp_write();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (!error)
Johannes Bergfe0c935a2007-04-30 15:09:51 -0700191 power_down();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700192 else {
Pavel Machek99dc7d62005-09-03 15:57:05 -0700193 swsusp_free();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700194 goto Thaw;
Pavel Machek99dc7d62005-09-03 15:57:05 -0700195 }
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800196 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 pr_debug("PM: Image restored successfully.\n");
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800198 }
Pavel Machek99dc7d62005-09-03 15:57:05 -0700199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 swsusp_free();
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800201 Enable_cpus:
202 enable_nonboot_cpus();
203 Resume_devices:
204 platform_finish();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700205 device_resume();
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700206 resume_console();
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800207 Thaw:
Pavel Machek99dc7d62005-09-03 15:57:05 -0700208 unprepare_processes();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700209 Finish:
210 free_basic_memory_bitmaps();
211 Exit:
212 atomic_inc(&snapshot_device_available);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return error;
214}
215
216
217/**
218 * software_resume - Resume from a saved image.
219 *
220 * Called as a late_initcall (so all devices are discovered and
221 * initialized), we call swsusp to see if we have a saved image or not.
222 * If so, we quiesce devices, the restore the saved image. We will
223 * return above (in pm_suspend_disk() ) if everything goes well.
224 * Otherwise, we fail gracefully and return to the normally
225 * scheduled program.
226 *
227 */
228
229static int software_resume(void)
230{
231 int error;
232
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800233 mutex_lock(&pm_mutex);
Pavel Machek3efa1472005-07-07 17:56:43 -0700234 if (!swsusp_resume_device) {
Shaohua Lidd5d6662005-09-03 15:57:04 -0700235 if (!strlen(resume_file)) {
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800236 mutex_unlock(&pm_mutex);
Pavel Machek3efa1472005-07-07 17:56:43 -0700237 return -ENOENT;
Shaohua Lidd5d6662005-09-03 15:57:04 -0700238 }
Pavel Machek3efa1472005-07-07 17:56:43 -0700239 swsusp_resume_device = name_to_dev_t(resume_file);
240 pr_debug("swsusp: Resume From Partition %s\n", resume_file);
241 } else {
242 pr_debug("swsusp: Resume From Partition %d:%d\n",
243 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
244 }
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (noresume) {
247 /**
248 * FIXME: If noresume is specified, we need to find the partition
249 * and reset it back to normal swap space.
250 */
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800251 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 return 0;
253 }
254
255 pr_debug("PM: Checking swsusp image.\n");
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800256 error = swsusp_check();
257 if (error)
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700258 goto Unlock;
259
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700260 /* The snapshot device should not be opened while we're running */
261 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
262 error = -EBUSY;
263 goto Unlock;
264 }
265
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700266 error = create_basic_memory_bitmaps();
267 if (error)
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700268 goto Finish;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 pr_debug("PM: Preparing processes for restore.\n");
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800271 error = prepare_processes();
272 if (error) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 swsusp_close();
Li Shaohua5a72e042005-06-25 14:55:06 -0700274 goto Done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
277 pr_debug("PM: Reading swsusp image.\n");
278
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800279 error = swsusp_read();
280 if (error) {
Rafael J. Wysocki2c1b4a52005-10-30 14:59:58 -0800281 swsusp_free();
282 goto Thaw;
283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 pr_debug("PM: Preparing devices for restore.\n");
286
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700287 suspend_console();
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800288 error = device_suspend(PMSG_PRETHAW);
289 if (error)
290 goto Free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800292 error = disable_nonboot_cpus();
293 if (!error)
294 swsusp_resume();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800296 enable_nonboot_cpus();
297 Free:
298 swsusp_free();
Pavel Machek99dc7d62005-09-03 15:57:05 -0700299 device_resume();
Rafael J. Wysocki97c78012006-10-11 01:20:45 -0700300 resume_console();
Rafael J. Wysocki2c1b4a52005-10-30 14:59:58 -0800301 Thaw:
Rafael J. Wysockied746e32007-02-10 01:43:32 -0800302 printk(KERN_ERR "PM: Restore failed, recovering.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 unprepare_processes();
304 Done:
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700305 free_basic_memory_bitmaps();
Rafael J. Wysocki0709db62007-05-06 14:50:45 -0700306 Finish:
307 atomic_inc(&snapshot_device_available);
Shaohua Lidd5d6662005-09-03 15:57:04 -0700308 /* For success case, the suspend path will release the lock */
Rafael J. Wysocki74dfd662007-05-06 14:50:43 -0700309 Unlock:
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800310 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 pr_debug("PM: Resume from disk failed.\n");
312 return 0;
313}
314
315late_initcall(software_resume);
316
317
Andreas Mohr3b364b82006-06-25 05:47:56 -0700318static const char * const pm_disk_modes[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 [PM_DISK_PLATFORM] = "platform",
320 [PM_DISK_SHUTDOWN] = "shutdown",
321 [PM_DISK_REBOOT] = "reboot",
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800322 [PM_DISK_TEST] = "test",
323 [PM_DISK_TESTPROC] = "testproc",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324};
325
326/**
327 * disk - Control suspend-to-disk mode
328 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700329 * Suspend-to-disk can be handled in several ways. We have a few options
330 * for putting the system to sleep - using the platform driver (e.g. ACPI
331 * or other pm_ops), powering off the system or rebooting the system
332 * (for testing) as well as the two test modes.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700334 * The system can support 'platform', and that is known a priori (and
335 * encoded in pm_ops). However, the user may choose 'shutdown' or 'reboot'
336 * as alternatives, as well as the test modes 'test' and 'testproc'.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 *
338 * show() will display what the mode is currently set to.
339 * store() will accept one of
340 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 * 'platform'
342 * 'shutdown'
343 * 'reboot'
Johannes Berg11d77d02007-04-30 15:09:53 -0700344 * 'test'
345 * 'testproc'
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 *
Johannes Berg11d77d02007-04-30 15:09:53 -0700347 * It will only change to 'platform' if the system
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 * supports it (as determined from pm_ops->pm_disk_mode).
349 */
350
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700351static ssize_t disk_show(struct kset *kset, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
353 return sprintf(buf, "%s\n", pm_disk_modes[pm_disk_mode]);
354}
355
356
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700357static ssize_t disk_store(struct kset *kset, const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
359 int error = 0;
360 int i;
361 int len;
362 char *p;
363 suspend_disk_method_t mode = 0;
364
365 p = memchr(buf, '\n', n);
366 len = p ? p - buf : n;
367
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800368 mutex_lock(&pm_mutex);
Johannes Berg11d77d02007-04-30 15:09:53 -0700369 for (i = PM_DISK_PLATFORM; i < PM_DISK_MAX; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 if (!strncmp(buf, pm_disk_modes[i], len)) {
371 mode = i;
372 break;
373 }
374 }
375 if (mode) {
Johannes Bergfe0c935a2007-04-30 15:09:51 -0700376 switch (mode) {
377 case PM_DISK_SHUTDOWN:
378 case PM_DISK_REBOOT:
379 case PM_DISK_TEST:
380 case PM_DISK_TESTPROC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 pm_disk_mode = mode;
Johannes Bergfe0c935a2007-04-30 15:09:51 -0700382 break;
383 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 if (pm_ops && pm_ops->enter &&
385 (mode == pm_ops->pm_disk_mode))
386 pm_disk_mode = mode;
387 else
388 error = -EINVAL;
389 }
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800390 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 error = -EINVAL;
Rafael J. Wysockib918f6e2006-11-02 22:07:19 -0800392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 pr_debug("PM: suspend-to-disk mode set to '%s'\n",
395 pm_disk_modes[mode]);
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800396 mutex_unlock(&pm_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 return error ? error : n;
398}
399
400power_attr(disk);
401
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700402static ssize_t resume_show(struct kset *kset, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
404 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
405 MINOR(swsusp_resume_device));
406}
407
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700408static ssize_t resume_store(struct kset *kset, const char *buf, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 unsigned int maj, min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 dev_t res;
Andrew Mortona5762192006-01-06 00:09:50 -0800412 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Andrew Mortona5762192006-01-06 00:09:50 -0800414 if (sscanf(buf, "%u:%u", &maj, &min) != 2)
415 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Andrew Mortona5762192006-01-06 00:09:50 -0800417 res = MKDEV(maj,min);
418 if (maj != MAJOR(res) || min != MINOR(res))
419 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800421 mutex_lock(&pm_mutex);
Andrew Mortona5762192006-01-06 00:09:50 -0800422 swsusp_resume_device = res;
Stephen Hemmingera6d70982006-12-06 20:34:35 -0800423 mutex_unlock(&pm_mutex);
Andrew Mortona5762192006-01-06 00:09:50 -0800424 printk("Attempting manual resume\n");
425 noresume = 0;
426 software_resume();
427 ret = n;
Rafael J. Wysocki59a493352006-12-06 20:34:44 -0800428 out:
Andrew Mortona5762192006-01-06 00:09:50 -0800429 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432power_attr(resume);
433
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700434static ssize_t image_size_show(struct kset *kset, char *buf)
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800435{
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800436 return sprintf(buf, "%lu\n", image_size);
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800437}
438
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700439static ssize_t image_size_store(struct kset *kset, const char *buf, size_t n)
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800440{
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800441 unsigned long size;
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800442
Rafael J. Wysocki853609b2006-02-01 03:05:07 -0800443 if (sscanf(buf, "%lu", &size) == 1) {
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800444 image_size = size;
445 return n;
446 }
447
448 return -EINVAL;
449}
450
451power_attr(image_size);
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453static struct attribute * g[] = {
454 &disk_attr.attr,
455 &resume_attr.attr,
Rafael J. Wysockica0aec02006-01-06 00:15:56 -0800456 &image_size_attr.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 NULL,
458};
459
460
461static struct attribute_group attr_group = {
462 .attrs = g,
463};
464
465
466static int __init pm_disk_init(void)
467{
Greg Kroah-Hartman823bccf2007-04-13 13:15:19 -0700468 return sysfs_create_group(&power_subsys.kobj, &attr_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469}
470
471core_initcall(pm_disk_init);
472
473
474static int __init resume_setup(char *str)
475{
476 if (noresume)
477 return 1;
478
479 strncpy( resume_file, str, 255 );
480 return 1;
481}
482
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -0800483static int __init resume_offset_setup(char *str)
484{
485 unsigned long long offset;
486
487 if (noresume)
488 return 1;
489
490 if (sscanf(str, "%llu", &offset) == 1)
491 swsusp_resume_block = offset;
492
493 return 1;
494}
495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496static int __init noresume_setup(char *str)
497{
498 noresume = 1;
499 return 1;
500}
501
502__setup("noresume", noresume_setup);
Rafael J. Wysocki9a154d92006-12-06 20:34:12 -0800503__setup("resume_offset=", resume_offset_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504__setup("resume=", resume_setup);