Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Morton | d53d9f1 | 2005-07-12 13:58:07 -0700 | [diff] [blame] | 19 | #include <linux/mount.h> |
Eric W. Biederman | 88d10bb | 2005-09-22 21:43:46 -0700 | [diff] [blame] | 20 | #include <linux/pm.h> |
Rafael J. Wysocki | 97c7801 | 2006-10-11 01:20:45 -0700 | [diff] [blame] | 21 | #include <linux/console.h> |
Rafael J. Wysocki | e3920fb | 2006-09-25 23:32:48 -0700 | [diff] [blame] | 22 | #include <linux/cpu.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 23 | #include <linux/freezer.h> |
Andrew Morton | d53d9f1 | 2005-07-12 13:58:07 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include "power.h" |
| 26 | |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int noresume = 0; |
| 29 | char resume_file[256] = CONFIG_PM_STD_PARTITION; |
| 30 | dev_t swsusp_resume_device; |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 31 | sector_t swsusp_resume_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 33 | enum { |
| 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 | |
| 46 | static int hibernation_mode = HIBERNATION_SHUTDOWN; |
| 47 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 48 | static struct hibernation_ops *hibernation_ops; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * hibernation_set_ops - set the global hibernate operations |
| 52 | * @ops: the hibernation operations to use in subsequent hibernation transitions |
| 53 | */ |
| 54 | |
| 55 | void hibernation_set_ops(struct hibernation_ops *ops) |
| 56 | { |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 57 | if (ops && !(ops->prepare && ops->enter && ops->finish |
| 58 | && ops->pre_restore && ops->restore_cleanup)) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 59 | WARN_ON(1); |
| 60 | return; |
| 61 | } |
| 62 | mutex_lock(&pm_mutex); |
| 63 | hibernation_ops = ops; |
| 64 | if (ops) |
| 65 | hibernation_mode = HIBERNATION_PLATFORM; |
| 66 | else if (hibernation_mode == HIBERNATION_PLATFORM) |
| 67 | hibernation_mode = HIBERNATION_SHUTDOWN; |
| 68 | |
| 69 | mutex_unlock(&pm_mutex); |
| 70 | } |
| 71 | |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /** |
Stefan Seyfried | 8a05aac | 2006-12-06 20:34:21 -0800 | [diff] [blame] | 74 | * platform_prepare - prepare the machine for hibernation using the |
| 75 | * platform driver if so configured and return an error code if it fails |
| 76 | */ |
| 77 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 78 | static int platform_prepare(int platform_mode) |
Stefan Seyfried | 8a05aac | 2006-12-06 20:34:21 -0800 | [diff] [blame] | 79 | { |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 80 | return (platform_mode && hibernation_ops) ? |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 81 | hibernation_ops->prepare() : 0; |
Stefan Seyfried | 8a05aac | 2006-12-06 20:34:21 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 85 | * platform_finish - switch the machine to the normal mode of operation |
| 86 | * using the platform driver (must be called after platform_prepare()) |
| 87 | */ |
| 88 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 89 | static void platform_finish(int platform_mode) |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 90 | { |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 91 | if (platform_mode && hibernation_ops) |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 92 | hibernation_ops->finish(); |
| 93 | } |
| 94 | |
| 95 | /** |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 96 | * platform_pre_restore - prepare the platform for the restoration from a |
| 97 | * hibernation image. If the restore fails after this function has been |
| 98 | * called, platform_restore_cleanup() must be called. |
| 99 | */ |
| 100 | |
| 101 | static int platform_pre_restore(int platform_mode) |
| 102 | { |
| 103 | return (platform_mode && hibernation_ops) ? |
| 104 | hibernation_ops->pre_restore() : 0; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * platform_restore_cleanup - switch the platform to the normal mode of |
| 109 | * operation after a failing restore. If platform_pre_restore() has been |
| 110 | * called before the failing restore, this function must be called too, |
| 111 | * regardless of the result of platform_pre_restore(). |
| 112 | */ |
| 113 | |
| 114 | static void platform_restore_cleanup(int platform_mode) |
| 115 | { |
| 116 | if (platform_mode && hibernation_ops) |
| 117 | hibernation_ops->restore_cleanup(); |
| 118 | } |
| 119 | |
| 120 | /** |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 121 | * hibernation_snapshot - quiesce devices and create the hibernation |
| 122 | * snapshot image. |
| 123 | * @platform_mode - if set, use the platform driver, if available, to |
| 124 | * prepare the platform frimware for the power transition. |
| 125 | * |
| 126 | * Must be called with pm_mutex held |
| 127 | */ |
| 128 | |
| 129 | int hibernation_snapshot(int platform_mode) |
| 130 | { |
| 131 | int error; |
| 132 | |
| 133 | /* Free memory before shutting down devices. */ |
| 134 | error = swsusp_shrink_memory(); |
| 135 | if (error) |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 136 | return error; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 137 | |
| 138 | suspend_console(); |
| 139 | error = device_suspend(PMSG_FREEZE); |
| 140 | if (error) |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 141 | goto Resume_console; |
| 142 | |
| 143 | error = platform_prepare(platform_mode); |
| 144 | if (error) |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 145 | goto Resume_devices; |
| 146 | |
| 147 | error = disable_nonboot_cpus(); |
| 148 | if (!error) { |
| 149 | if (hibernation_mode != HIBERNATION_TEST) { |
| 150 | in_suspend = 1; |
| 151 | error = swsusp_suspend(); |
| 152 | /* Control returns here after successful restore */ |
| 153 | } else { |
| 154 | printk("swsusp debug: Waiting for 5 seconds.\n"); |
| 155 | mdelay(5000); |
| 156 | } |
| 157 | } |
| 158 | enable_nonboot_cpus(); |
| 159 | Resume_devices: |
| 160 | platform_finish(platform_mode); |
| 161 | device_resume(); |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 162 | Resume_console: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 163 | resume_console(); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 164 | return error; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * hibernation_restore - quiesce devices and restore the hibernation |
| 169 | * snapshot image. If successful, control returns in hibernation_snaphot() |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 170 | * @platform_mode - if set, use the platform driver, if available, to |
| 171 | * prepare the platform frimware for the transition. |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 172 | * |
| 173 | * Must be called with pm_mutex held |
| 174 | */ |
| 175 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 176 | int hibernation_restore(int platform_mode) |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 177 | { |
| 178 | int error; |
| 179 | |
| 180 | pm_prepare_console(); |
| 181 | suspend_console(); |
| 182 | error = device_suspend(PMSG_PRETHAW); |
| 183 | if (error) |
| 184 | goto Finish; |
| 185 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 186 | error = platform_pre_restore(platform_mode); |
| 187 | if (!error) { |
| 188 | error = disable_nonboot_cpus(); |
| 189 | if (!error) |
| 190 | error = swsusp_resume(); |
| 191 | enable_nonboot_cpus(); |
| 192 | } |
| 193 | platform_restore_cleanup(platform_mode); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 194 | device_resume(); |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 195 | Finish: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 196 | resume_console(); |
| 197 | pm_restore_console(); |
| 198 | return error; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * hibernation_platform_enter - enter the hibernation state using the |
| 203 | * platform driver (if available) |
| 204 | */ |
| 205 | |
| 206 | int hibernation_platform_enter(void) |
| 207 | { |
Rafael J. Wysocki | b1457bc | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 208 | int error; |
| 209 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 210 | if (hibernation_ops) { |
| 211 | kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK); |
Rafael J. Wysocki | b1457bc | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 212 | /* |
| 213 | * We have cancelled the power transition by running |
| 214 | * hibernation_ops->finish() before saving the image, so we |
| 215 | * should let the firmware know that we're going to enter the |
| 216 | * sleep state after all |
| 217 | */ |
| 218 | error = hibernation_ops->prepare(); |
| 219 | if (!error) |
| 220 | error = hibernation_ops->enter(); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 221 | } else { |
Rafael J. Wysocki | b1457bc | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 222 | error = -ENOSYS; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 223 | } |
Rafael J. Wysocki | b1457bc | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 224 | return error; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 228 | * power_down - Shut the machine down for hibernation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | * |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 230 | * Use the platform driver, if configured so; otherwise try |
| 231 | * to power off or reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | */ |
| 233 | |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 234 | static void power_down(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 236 | switch (hibernation_mode) { |
| 237 | case HIBERNATION_TEST: |
| 238 | case HIBERNATION_TESTPROC: |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 239 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 240 | case HIBERNATION_SHUTDOWN: |
Eric W. Biederman | fdde86a | 2005-07-26 12:01:17 -0600 | [diff] [blame] | 241 | kernel_power_off(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 243 | case HIBERNATION_REBOOT: |
Eric W. Biederman | fdde86a | 2005-07-26 12:01:17 -0600 | [diff] [blame] | 244 | kernel_restart(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 246 | case HIBERNATION_PLATFORM: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 247 | hibernation_platform_enter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
Eric W. Biederman | fdde86a | 2005-07-26 12:01:17 -0600 | [diff] [blame] | 249 | kernel_halt(); |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 250 | /* |
| 251 | * Valid image is on the disk, if we continue we risk serious data |
| 252 | * corruption after resume. |
| 253 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | printk(KERN_CRIT "Please power me down manually\n"); |
| 255 | while(1); |
| 256 | } |
| 257 | |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 258 | static void unprepare_processes(void) |
| 259 | { |
| 260 | thaw_processes(); |
| 261 | pm_restore_console(); |
| 262 | } |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | static int prepare_processes(void) |
| 265 | { |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 266 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | pm_prepare_console(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | if (freeze_processes()) { |
| 270 | error = -EBUSY; |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 271 | unprepare_processes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
Li Shaohua | 5a72e04 | 2005-06-25 14:55:06 -0700 | [diff] [blame] | 273 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 277 | * hibernate - The granpappy of the built-in hibernation management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | */ |
| 279 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 280 | int hibernate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | int error; |
| 283 | |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame^] | 284 | mutex_lock(&pm_mutex); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 285 | /* The snapshot device should not be opened while we're running */ |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame^] | 286 | if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { |
| 287 | error = -EBUSY; |
| 288 | goto Unlock; |
| 289 | } |
| 290 | |
| 291 | error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); |
| 292 | if (error) |
| 293 | goto Exit; |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 294 | |
| 295 | /* Allocate memory management structures */ |
| 296 | error = create_basic_memory_bitmaps(); |
| 297 | if (error) |
| 298 | goto Exit; |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | error = prepare_processes(); |
Li Shaohua | 5a72e04 | 2005-06-25 14:55:06 -0700 | [diff] [blame] | 301 | if (error) |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 302 | goto Finish; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 304 | if (hibernation_mode == HIBERNATION_TESTPROC) { |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 305 | printk("swsusp debug: Waiting for 5 seconds.\n"); |
| 306 | mdelay(5000); |
| 307 | goto Thaw; |
| 308 | } |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 309 | error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); |
| 310 | if (in_suspend && !error) { |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 311 | unsigned int flags = 0; |
| 312 | |
| 313 | if (hibernation_mode == HIBERNATION_PLATFORM) |
| 314 | flags |= SF_PLATFORM_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | pr_debug("PM: writing image.\n"); |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 316 | error = swsusp_write(flags); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 317 | swsusp_free(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (!error) |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 319 | power_down(); |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 320 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | pr_debug("PM: Image restored successfully.\n"); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 322 | swsusp_free(); |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 323 | } |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 324 | Thaw: |
Pavel Machek | 99dc7d6 | 2005-09-03 15:57:05 -0700 | [diff] [blame] | 325 | unprepare_processes(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 326 | Finish: |
| 327 | free_basic_memory_bitmaps(); |
| 328 | Exit: |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame^] | 329 | pm_notifier_call_chain(PM_POST_HIBERNATION); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 330 | atomic_inc(&snapshot_device_available); |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame^] | 331 | Unlock: |
| 332 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return error; |
| 334 | } |
| 335 | |
| 336 | |
| 337 | /** |
| 338 | * software_resume - Resume from a saved image. |
| 339 | * |
| 340 | * Called as a late_initcall (so all devices are discovered and |
| 341 | * initialized), we call swsusp to see if we have a saved image or not. |
| 342 | * If so, we quiesce devices, the restore the saved image. We will |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 343 | * return above (in hibernate() ) if everything goes well. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | * Otherwise, we fail gracefully and return to the normally |
| 345 | * scheduled program. |
| 346 | * |
| 347 | */ |
| 348 | |
| 349 | static int software_resume(void) |
| 350 | { |
| 351 | int error; |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 352 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 354 | mutex_lock(&pm_mutex); |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 355 | if (!swsusp_resume_device) { |
Shaohua Li | dd5d666 | 2005-09-03 15:57:04 -0700 | [diff] [blame] | 356 | if (!strlen(resume_file)) { |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 357 | mutex_unlock(&pm_mutex); |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 358 | return -ENOENT; |
Shaohua Li | dd5d666 | 2005-09-03 15:57:04 -0700 | [diff] [blame] | 359 | } |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 360 | swsusp_resume_device = name_to_dev_t(resume_file); |
| 361 | pr_debug("swsusp: Resume From Partition %s\n", resume_file); |
| 362 | } else { |
| 363 | pr_debug("swsusp: Resume From Partition %d:%d\n", |
| 364 | MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device)); |
| 365 | } |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | if (noresume) { |
| 368 | /** |
| 369 | * FIXME: If noresume is specified, we need to find the partition |
| 370 | * and reset it back to normal swap space. |
| 371 | */ |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 372 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | pr_debug("PM: Checking swsusp image.\n"); |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 377 | error = swsusp_check(); |
| 378 | if (error) |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 379 | goto Unlock; |
| 380 | |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 381 | /* The snapshot device should not be opened while we're running */ |
| 382 | if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { |
| 383 | error = -EBUSY; |
| 384 | goto Unlock; |
| 385 | } |
| 386 | |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 387 | error = create_basic_memory_bitmaps(); |
| 388 | if (error) |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 389 | goto Finish; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | pr_debug("PM: Preparing processes for restore.\n"); |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 392 | error = prepare_processes(); |
| 393 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | swsusp_close(); |
Li Shaohua | 5a72e04 | 2005-06-25 14:55:06 -0700 | [diff] [blame] | 395 | goto Done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | pr_debug("PM: Reading swsusp image.\n"); |
| 399 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 400 | error = swsusp_read(&flags); |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 401 | if (!error) |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 402 | hibernation_restore(flags & SF_PLATFORM_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 404 | printk(KERN_ERR "PM: Restore failed, recovering.\n"); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 405 | swsusp_free(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | unprepare_processes(); |
| 407 | Done: |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 408 | free_basic_memory_bitmaps(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 409 | Finish: |
| 410 | atomic_inc(&snapshot_device_available); |
Shaohua Li | dd5d666 | 2005-09-03 15:57:04 -0700 | [diff] [blame] | 411 | /* For success case, the suspend path will release the lock */ |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 412 | Unlock: |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 413 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | pr_debug("PM: Resume from disk failed.\n"); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 415 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | late_initcall(software_resume); |
| 419 | |
| 420 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 421 | static const char * const hibernation_modes[] = { |
| 422 | [HIBERNATION_PLATFORM] = "platform", |
| 423 | [HIBERNATION_SHUTDOWN] = "shutdown", |
| 424 | [HIBERNATION_REBOOT] = "reboot", |
| 425 | [HIBERNATION_TEST] = "test", |
| 426 | [HIBERNATION_TESTPROC] = "testproc", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | }; |
| 428 | |
| 429 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 430 | * disk - Control hibernation mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | * |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 432 | * Suspend-to-disk can be handled in several ways. We have a few options |
| 433 | * for putting the system to sleep - using the platform driver (e.g. ACPI |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 434 | * or other hibernation_ops), powering off the system or rebooting the |
| 435 | * system (for testing) as well as the two test modes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | * |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 437 | * The system can support 'platform', and that is known a priori (and |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 438 | * encoded by the presence of hibernation_ops). However, the user may |
| 439 | * choose 'shutdown' or 'reboot' as alternatives, as well as one fo the |
| 440 | * test modes, 'test' or 'testproc'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | * |
| 442 | * show() will display what the mode is currently set to. |
| 443 | * store() will accept one of |
| 444 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | * 'platform' |
| 446 | * 'shutdown' |
| 447 | * 'reboot' |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 448 | * 'test' |
| 449 | * 'testproc' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | * |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 451 | * It will only change to 'platform' if the system |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 452 | * supports it (as determined by having hibernation_ops). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | */ |
| 454 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 455 | static ssize_t disk_show(struct kset *kset, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 457 | int i; |
| 458 | char *start = buf; |
| 459 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 460 | for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { |
| 461 | if (!hibernation_modes[i]) |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 462 | continue; |
| 463 | switch (i) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 464 | case HIBERNATION_SHUTDOWN: |
| 465 | case HIBERNATION_REBOOT: |
| 466 | case HIBERNATION_TEST: |
| 467 | case HIBERNATION_TESTPROC: |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 468 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 469 | case HIBERNATION_PLATFORM: |
| 470 | if (hibernation_ops) |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 471 | break; |
| 472 | /* not a valid mode, continue with loop */ |
| 473 | continue; |
| 474 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 475 | if (i == hibernation_mode) |
| 476 | buf += sprintf(buf, "[%s] ", hibernation_modes[i]); |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 477 | else |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 478 | buf += sprintf(buf, "%s ", hibernation_modes[i]); |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 479 | } |
| 480 | buf += sprintf(buf, "\n"); |
| 481 | return buf-start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 485 | static ssize_t disk_store(struct kset *kset, const char *buf, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
| 487 | int error = 0; |
| 488 | int i; |
| 489 | int len; |
| 490 | char *p; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 491 | int mode = HIBERNATION_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | p = memchr(buf, '\n', n); |
| 494 | len = p ? p - buf : n; |
| 495 | |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 496 | mutex_lock(&pm_mutex); |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 497 | for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { |
Rafael J. Wysocki | 8d98a69 | 2007-05-16 22:11:19 -0700 | [diff] [blame] | 498 | if (len == strlen(hibernation_modes[i]) |
| 499 | && !strncmp(buf, hibernation_modes[i], len)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | mode = i; |
| 501 | break; |
| 502 | } |
| 503 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 504 | if (mode != HIBERNATION_INVALID) { |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 505 | switch (mode) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 506 | case HIBERNATION_SHUTDOWN: |
| 507 | case HIBERNATION_REBOOT: |
| 508 | case HIBERNATION_TEST: |
| 509 | case HIBERNATION_TESTPROC: |
| 510 | hibernation_mode = mode; |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 511 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 512 | case HIBERNATION_PLATFORM: |
| 513 | if (hibernation_ops) |
| 514 | hibernation_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | else |
| 516 | error = -EINVAL; |
| 517 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 518 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | error = -EINVAL; |
| 520 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 521 | if (!error) |
| 522 | pr_debug("PM: suspend-to-disk mode set to '%s'\n", |
| 523 | hibernation_modes[mode]); |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 524 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return error ? error : n; |
| 526 | } |
| 527 | |
| 528 | power_attr(disk); |
| 529 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 530 | static ssize_t resume_show(struct kset *kset, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
| 532 | return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device), |
| 533 | MINOR(swsusp_resume_device)); |
| 534 | } |
| 535 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 536 | static ssize_t resume_store(struct kset *kset, const char *buf, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | unsigned int maj, min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | dev_t res; |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 540 | int ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 542 | if (sscanf(buf, "%u:%u", &maj, &min) != 2) |
| 543 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 545 | res = MKDEV(maj,min); |
| 546 | if (maj != MAJOR(res) || min != MINOR(res)) |
| 547 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 549 | mutex_lock(&pm_mutex); |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 550 | swsusp_resume_device = res; |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 551 | mutex_unlock(&pm_mutex); |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 552 | printk("Attempting manual resume\n"); |
| 553 | noresume = 0; |
| 554 | software_resume(); |
| 555 | ret = n; |
Rafael J. Wysocki | 59a4933 | 2006-12-06 20:34:44 -0800 | [diff] [blame] | 556 | out: |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 557 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | power_attr(resume); |
| 561 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 562 | static ssize_t image_size_show(struct kset *kset, char *buf) |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 563 | { |
Rafael J. Wysocki | 853609b | 2006-02-01 03:05:07 -0800 | [diff] [blame] | 564 | return sprintf(buf, "%lu\n", image_size); |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 565 | } |
| 566 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 567 | static ssize_t image_size_store(struct kset *kset, const char *buf, size_t n) |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 568 | { |
Rafael J. Wysocki | 853609b | 2006-02-01 03:05:07 -0800 | [diff] [blame] | 569 | unsigned long size; |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 570 | |
Rafael J. Wysocki | 853609b | 2006-02-01 03:05:07 -0800 | [diff] [blame] | 571 | if (sscanf(buf, "%lu", &size) == 1) { |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 572 | image_size = size; |
| 573 | return n; |
| 574 | } |
| 575 | |
| 576 | return -EINVAL; |
| 577 | } |
| 578 | |
| 579 | power_attr(image_size); |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | static struct attribute * g[] = { |
| 582 | &disk_attr.attr, |
| 583 | &resume_attr.attr, |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 584 | &image_size_attr.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | NULL, |
| 586 | }; |
| 587 | |
| 588 | |
| 589 | static struct attribute_group attr_group = { |
| 590 | .attrs = g, |
| 591 | }; |
| 592 | |
| 593 | |
| 594 | static int __init pm_disk_init(void) |
| 595 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 596 | return sysfs_create_group(&power_subsys.kobj, &attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | core_initcall(pm_disk_init); |
| 600 | |
| 601 | |
| 602 | static int __init resume_setup(char *str) |
| 603 | { |
| 604 | if (noresume) |
| 605 | return 1; |
| 606 | |
| 607 | strncpy( resume_file, str, 255 ); |
| 608 | return 1; |
| 609 | } |
| 610 | |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 611 | static int __init resume_offset_setup(char *str) |
| 612 | { |
| 613 | unsigned long long offset; |
| 614 | |
| 615 | if (noresume) |
| 616 | return 1; |
| 617 | |
| 618 | if (sscanf(str, "%llu", &offset) == 1) |
| 619 | swsusp_resume_block = offset; |
| 620 | |
| 621 | return 1; |
| 622 | } |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | static int __init noresume_setup(char *str) |
| 625 | { |
| 626 | noresume = 1; |
| 627 | return 1; |
| 628 | } |
| 629 | |
| 630 | __setup("noresume", noresume_setup); |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 631 | __setup("resume_offset=", resume_offset_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | __setup("resume=", resume_setup); |