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> |
Rafael J. Wysocki | 1bfcf13 | 2008-10-15 22:01:21 -0700 | [diff] [blame] | 17 | #include <linux/kmod.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/delay.h> |
| 19 | #include <linux/fs.h> |
Andrew Morton | d53d9f1 | 2005-07-12 13:58:07 -0700 | [diff] [blame] | 20 | #include <linux/mount.h> |
Eric W. Biederman | 88d10bb | 2005-09-22 21:43:46 -0700 | [diff] [blame] | 21 | #include <linux/pm.h> |
Rafael J. Wysocki | 97c7801 | 2006-10-11 01:20:45 -0700 | [diff] [blame] | 22 | #include <linux/console.h> |
Rafael J. Wysocki | e3920fb | 2006-09-25 23:32:48 -0700 | [diff] [blame] | 23 | #include <linux/cpu.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 24 | #include <linux/freezer.h> |
Andrew Morton | d53d9f1 | 2005-07-12 13:58:07 -0700 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "power.h" |
| 27 | |
| 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static int noresume = 0; |
Adrian Bunk | 47a460d | 2008-02-04 22:30:06 -0800 | [diff] [blame] | 30 | static char resume_file[256] = CONFIG_PM_STD_PARTITION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | dev_t swsusp_resume_device; |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 32 | sector_t swsusp_resume_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 34 | enum { |
| 35 | HIBERNATION_INVALID, |
| 36 | HIBERNATION_PLATFORM, |
| 37 | HIBERNATION_TEST, |
| 38 | HIBERNATION_TESTPROC, |
| 39 | HIBERNATION_SHUTDOWN, |
| 40 | HIBERNATION_REBOOT, |
| 41 | /* keep last */ |
| 42 | __HIBERNATION_AFTER_LAST |
| 43 | }; |
| 44 | #define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1) |
| 45 | #define HIBERNATION_FIRST (HIBERNATION_INVALID + 1) |
| 46 | |
| 47 | static int hibernation_mode = HIBERNATION_SHUTDOWN; |
| 48 | |
Rafael J. Wysocki | b3dac3b | 2007-10-18 03:04:43 -0700 | [diff] [blame] | 49 | static struct platform_hibernation_ops *hibernation_ops; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * hibernation_set_ops - set the global hibernate operations |
| 53 | * @ops: the hibernation operations to use in subsequent hibernation transitions |
| 54 | */ |
| 55 | |
Rafael J. Wysocki | b3dac3b | 2007-10-18 03:04:43 -0700 | [diff] [blame] | 56 | void hibernation_set_ops(struct platform_hibernation_ops *ops) |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 57 | { |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 58 | if (ops && !(ops->begin && ops->end && ops->pre_snapshot |
| 59 | && ops->prepare && ops->finish && ops->enter && ops->pre_restore |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 60 | && ops->restore_cleanup)) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 61 | WARN_ON(1); |
| 62 | return; |
| 63 | } |
| 64 | mutex_lock(&pm_mutex); |
| 65 | hibernation_ops = ops; |
| 66 | if (ops) |
| 67 | hibernation_mode = HIBERNATION_PLATFORM; |
| 68 | else if (hibernation_mode == HIBERNATION_PLATFORM) |
| 69 | hibernation_mode = HIBERNATION_SHUTDOWN; |
| 70 | |
| 71 | mutex_unlock(&pm_mutex); |
| 72 | } |
| 73 | |
Rafael J. Wysocki | abfe2d7 | 2009-01-19 20:54:54 +0100 | [diff] [blame] | 74 | static bool entering_platform_hibernation; |
| 75 | |
| 76 | bool system_entering_hibernation(void) |
| 77 | { |
| 78 | return entering_platform_hibernation; |
| 79 | } |
| 80 | EXPORT_SYMBOL(system_entering_hibernation); |
| 81 | |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_PM_DEBUG |
| 83 | static void hibernation_debug_sleep(void) |
| 84 | { |
| 85 | printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n"); |
| 86 | mdelay(5000); |
| 87 | } |
| 88 | |
| 89 | static int hibernation_testmode(int mode) |
| 90 | { |
| 91 | if (hibernation_mode == mode) { |
| 92 | hibernation_debug_sleep(); |
| 93 | return 1; |
| 94 | } |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static int hibernation_test(int level) |
| 99 | { |
| 100 | if (pm_test_level == level) { |
| 101 | hibernation_debug_sleep(); |
| 102 | return 1; |
| 103 | } |
| 104 | return 0; |
| 105 | } |
| 106 | #else /* !CONFIG_PM_DEBUG */ |
| 107 | static int hibernation_testmode(int mode) { return 0; } |
| 108 | static int hibernation_test(int level) { return 0; } |
| 109 | #endif /* !CONFIG_PM_DEBUG */ |
| 110 | |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 111 | /** |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 112 | * platform_begin - tell the platform driver that we're starting |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 113 | * hibernation |
| 114 | */ |
| 115 | |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 116 | static int platform_begin(int platform_mode) |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 117 | { |
| 118 | return (platform_mode && hibernation_ops) ? |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 119 | hibernation_ops->begin() : 0; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * platform_end - tell the platform driver that we've entered the |
| 124 | * working state |
| 125 | */ |
| 126 | |
| 127 | static void platform_end(int platform_mode) |
| 128 | { |
| 129 | if (platform_mode && hibernation_ops) |
| 130 | hibernation_ops->end(); |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 131 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /** |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 134 | * platform_pre_snapshot - prepare the machine for hibernation using the |
Stefan Seyfried | 8a05aac | 2006-12-06 20:34:21 -0800 | [diff] [blame] | 135 | * platform driver if so configured and return an error code if it fails |
| 136 | */ |
| 137 | |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 138 | static int platform_pre_snapshot(int platform_mode) |
Stefan Seyfried | 8a05aac | 2006-12-06 20:34:21 -0800 | [diff] [blame] | 139 | { |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 140 | return (platform_mode && hibernation_ops) ? |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 141 | hibernation_ops->pre_snapshot() : 0; |
Stefan Seyfried | 8a05aac | 2006-12-06 20:34:21 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | /** |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 145 | * platform_leave - prepare the machine for switching to the normal mode |
| 146 | * of operation using the platform driver (called with interrupts disabled) |
| 147 | */ |
| 148 | |
| 149 | static void platform_leave(int platform_mode) |
| 150 | { |
| 151 | if (platform_mode && hibernation_ops) |
| 152 | hibernation_ops->leave(); |
| 153 | } |
| 154 | |
| 155 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 156 | * platform_finish - switch the machine to the normal mode of operation |
| 157 | * using the platform driver (must be called after platform_prepare()) |
| 158 | */ |
| 159 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 160 | static void platform_finish(int platform_mode) |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 161 | { |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 162 | if (platform_mode && hibernation_ops) |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 163 | hibernation_ops->finish(); |
| 164 | } |
| 165 | |
| 166 | /** |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 167 | * platform_pre_restore - prepare the platform for the restoration from a |
| 168 | * hibernation image. If the restore fails after this function has been |
| 169 | * called, platform_restore_cleanup() must be called. |
| 170 | */ |
| 171 | |
| 172 | static int platform_pre_restore(int platform_mode) |
| 173 | { |
| 174 | return (platform_mode && hibernation_ops) ? |
| 175 | hibernation_ops->pre_restore() : 0; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * platform_restore_cleanup - switch the platform to the normal mode of |
| 180 | * operation after a failing restore. If platform_pre_restore() has been |
| 181 | * called before the failing restore, this function must be called too, |
| 182 | * regardless of the result of platform_pre_restore(). |
| 183 | */ |
| 184 | |
| 185 | static void platform_restore_cleanup(int platform_mode) |
| 186 | { |
| 187 | if (platform_mode && hibernation_ops) |
| 188 | hibernation_ops->restore_cleanup(); |
| 189 | } |
| 190 | |
| 191 | /** |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 192 | * platform_recover - recover the platform from a failure to suspend |
| 193 | * devices. |
| 194 | */ |
| 195 | |
| 196 | static void platform_recover(int platform_mode) |
| 197 | { |
| 198 | if (platform_mode && hibernation_ops && hibernation_ops->recover) |
| 199 | hibernation_ops->recover(); |
| 200 | } |
| 201 | |
| 202 | /** |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 203 | * create_image - freeze devices that need to be frozen with interrupts |
| 204 | * off, create the hibernation image and thaw those devices. Control |
| 205 | * reappears in this routine after a restore. |
| 206 | */ |
| 207 | |
Adrian Bunk | 47a460d | 2008-02-04 22:30:06 -0800 | [diff] [blame] | 208 | static int create_image(int platform_mode) |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 209 | { |
| 210 | int error; |
| 211 | |
| 212 | error = arch_prepare_suspend(); |
| 213 | if (error) |
| 214 | return error; |
| 215 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 216 | device_pm_lock(); |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 217 | local_irq_disable(); |
| 218 | /* At this point, device_suspend() has been called, but *not* |
| 219 | * device_power_down(). We *must* call device_power_down() now. |
| 220 | * Otherwise, drivers for some devices (e.g. interrupt controllers) |
| 221 | * become desynchronized with the actual state of the hardware |
| 222 | * at resume time, and evil weirdness ensues. |
| 223 | */ |
| 224 | error = device_power_down(PMSG_FREEZE); |
| 225 | if (error) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 226 | printk(KERN_ERR "PM: Some devices failed to power down, " |
| 227 | "aborting hibernation\n"); |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 228 | goto Enable_irqs; |
| 229 | } |
| 230 | |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 231 | if (hibernation_test(TEST_CORE)) |
| 232 | goto Power_up; |
| 233 | |
| 234 | in_suspend = 1; |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 235 | save_processor_state(); |
| 236 | error = swsusp_arch_suspend(); |
| 237 | if (error) |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 238 | printk(KERN_ERR "PM: Error %d creating hibernation image\n", |
| 239 | error); |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 240 | /* Restore control flow magically appears here */ |
| 241 | restore_processor_state(); |
| 242 | if (!in_suspend) |
| 243 | platform_leave(platform_mode); |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 244 | Power_up: |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 245 | /* NOTE: device_power_up() is just a resume() for devices |
| 246 | * that suspended with irqs off ... no overall powerup. |
| 247 | */ |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 248 | device_power_up(in_suspend ? |
| 249 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 250 | Enable_irqs: |
| 251 | local_irq_enable(); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 252 | device_pm_unlock(); |
Rafael J. Wysocki | c7e0831 | 2007-10-18 03:04:55 -0700 | [diff] [blame] | 253 | return error; |
| 254 | } |
| 255 | |
| 256 | /** |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 257 | * hibernation_snapshot - quiesce devices and create the hibernation |
| 258 | * snapshot image. |
| 259 | * @platform_mode - if set, use the platform driver, if available, to |
| 260 | * prepare the platform frimware for the power transition. |
| 261 | * |
| 262 | * Must be called with pm_mutex held |
| 263 | */ |
| 264 | |
| 265 | int hibernation_snapshot(int platform_mode) |
| 266 | { |
Ingo Molnar | cbe2f5a | 2008-11-23 10:37:12 +0100 | [diff] [blame] | 267 | int error; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 268 | |
Zhang Rui | 3fe0313 | 2008-10-26 20:50:26 +0100 | [diff] [blame] | 269 | error = platform_begin(platform_mode); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 270 | if (error) |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 271 | return error; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 272 | |
Zhang Rui | 3fe0313 | 2008-10-26 20:50:26 +0100 | [diff] [blame] | 273 | /* Free memory before shutting down devices. */ |
| 274 | error = swsusp_shrink_memory(); |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 275 | if (error) |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 276 | goto Close; |
Rafael J. Wysocki | 74f270a | 2007-10-18 03:04:42 -0700 | [diff] [blame] | 277 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 278 | suspend_console(); |
| 279 | error = device_suspend(PMSG_FREEZE); |
| 280 | if (error) |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 281 | goto Recover_platform; |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 282 | |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 283 | if (hibernation_test(TEST_DEVICES)) |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 284 | goto Recover_platform; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 285 | |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 286 | error = platform_pre_snapshot(platform_mode); |
| 287 | if (error || hibernation_test(TEST_PLATFORM)) |
| 288 | goto Finish; |
| 289 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 290 | error = disable_nonboot_cpus(); |
| 291 | if (!error) { |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 292 | if (hibernation_test(TEST_CPUS)) |
| 293 | goto Enable_cpus; |
| 294 | |
| 295 | if (hibernation_testmode(HIBERNATION_TEST)) |
| 296 | goto Enable_cpus; |
| 297 | |
| 298 | error = create_image(platform_mode); |
| 299 | /* Control returns here after successful restore */ |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 300 | } |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 301 | Enable_cpus: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 302 | enable_nonboot_cpus(); |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 303 | Finish: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 304 | platform_finish(platform_mode); |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 305 | Resume_devices: |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 306 | device_resume(in_suspend ? |
| 307 | (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 308 | resume_console(); |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 309 | Close: |
| 310 | platform_end(platform_mode); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 311 | return error; |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 312 | |
| 313 | Recover_platform: |
| 314 | platform_recover(platform_mode); |
| 315 | goto Resume_devices; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /** |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 319 | * resume_target_kernel - prepare devices that need to be suspended with |
| 320 | * interrupts off, restore the contents of highmem that have not been |
| 321 | * restored yet from the image and run the low level code that will restore |
| 322 | * the remaining contents of memory and switch to the just restored target |
| 323 | * kernel. |
| 324 | */ |
| 325 | |
| 326 | static int resume_target_kernel(void) |
| 327 | { |
| 328 | int error; |
| 329 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 330 | device_pm_lock(); |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 331 | local_irq_disable(); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 332 | error = device_power_down(PMSG_QUIESCE); |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 333 | if (error) { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 334 | printk(KERN_ERR "PM: Some devices failed to power down, " |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 335 | "aborting resume\n"); |
| 336 | goto Enable_irqs; |
| 337 | } |
| 338 | /* We'll ignore saved state, but this gets preempt count (etc) right */ |
| 339 | save_processor_state(); |
| 340 | error = restore_highmem(); |
| 341 | if (!error) { |
| 342 | error = swsusp_arch_resume(); |
| 343 | /* |
| 344 | * The code below is only ever reached in case of a failure. |
| 345 | * Otherwise execution continues at place where |
| 346 | * swsusp_arch_suspend() was called |
| 347 | */ |
| 348 | BUG_ON(!error); |
| 349 | /* This call to restore_highmem() undos the previous one */ |
| 350 | restore_highmem(); |
| 351 | } |
| 352 | /* |
| 353 | * The only reason why swsusp_arch_resume() can fail is memory being |
| 354 | * very tight, so we have to free it as soon as we can to avoid |
| 355 | * subsequent failures |
| 356 | */ |
| 357 | swsusp_free(); |
| 358 | restore_processor_state(); |
| 359 | touch_softlockup_watchdog(); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 360 | device_power_up(PMSG_RECOVER); |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 361 | Enable_irqs: |
| 362 | local_irq_enable(); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 363 | device_pm_unlock(); |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 364 | return error; |
| 365 | } |
| 366 | |
| 367 | /** |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 368 | * hibernation_restore - quiesce devices and restore the hibernation |
| 369 | * snapshot image. If successful, control returns in hibernation_snaphot() |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 370 | * @platform_mode - if set, use the platform driver, if available, to |
| 371 | * prepare the platform frimware for the transition. |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 372 | * |
| 373 | * Must be called with pm_mutex held |
| 374 | */ |
| 375 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 376 | int hibernation_restore(int platform_mode) |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 377 | { |
Ingo Molnar | cbe2f5a | 2008-11-23 10:37:12 +0100 | [diff] [blame] | 378 | int error; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 379 | |
| 380 | pm_prepare_console(); |
| 381 | suspend_console(); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 382 | error = device_suspend(PMSG_QUIESCE); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 383 | if (error) |
| 384 | goto Finish; |
| 385 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 386 | error = platform_pre_restore(platform_mode); |
| 387 | if (!error) { |
| 388 | error = disable_nonboot_cpus(); |
| 389 | if (!error) |
Rafael J. Wysocki | 72df68c | 2007-12-08 02:04:21 +0100 | [diff] [blame] | 390 | error = resume_target_kernel(); |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 391 | enable_nonboot_cpus(); |
| 392 | } |
| 393 | platform_restore_cleanup(platform_mode); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 394 | device_resume(PMSG_RECOVER); |
Rafael J. Wysocki | 10a1803 | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 395 | Finish: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 396 | resume_console(); |
| 397 | pm_restore_console(); |
| 398 | return error; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * hibernation_platform_enter - enter the hibernation state using the |
| 403 | * platform driver (if available) |
| 404 | */ |
| 405 | |
| 406 | int hibernation_platform_enter(void) |
| 407 | { |
Ingo Molnar | cbe2f5a | 2008-11-23 10:37:12 +0100 | [diff] [blame] | 408 | int error; |
Rafael J. Wysocki | b1457bc | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 409 | |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 410 | if (!hibernation_ops) |
| 411 | return -ENOSYS; |
| 412 | |
| 413 | /* |
| 414 | * We have cancelled the power transition by running |
| 415 | * hibernation_ops->finish() before saving the image, so we should let |
| 416 | * the firmware know that we're going to enter the sleep state after all |
| 417 | */ |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 418 | error = hibernation_ops->begin(); |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 419 | if (error) |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 420 | goto Close; |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 421 | |
Rafael J. Wysocki | abfe2d7 | 2009-01-19 20:54:54 +0100 | [diff] [blame] | 422 | entering_platform_hibernation = true; |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 423 | suspend_console(); |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 424 | error = device_suspend(PMSG_HIBERNATE); |
Rafael J. Wysocki | d8f3de0 | 2008-06-12 23:24:06 +0200 | [diff] [blame] | 425 | if (error) { |
| 426 | if (hibernation_ops->recover) |
| 427 | hibernation_ops->recover(); |
| 428 | goto Resume_devices; |
| 429 | } |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 430 | |
| 431 | error = hibernation_ops->prepare(); |
| 432 | if (error) |
| 433 | goto Resume_devices; |
| 434 | |
| 435 | error = disable_nonboot_cpus(); |
| 436 | if (error) |
| 437 | goto Finish; |
| 438 | |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 439 | device_pm_lock(); |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 440 | local_irq_disable(); |
Rafael J. Wysocki | 3a2d5b7 | 2008-02-23 19:13:25 +0100 | [diff] [blame] | 441 | error = device_power_down(PMSG_HIBERNATE); |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 442 | if (!error) { |
| 443 | hibernation_ops->enter(); |
| 444 | /* We should never get here */ |
| 445 | while (1); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 446 | } |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 447 | local_irq_enable(); |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 448 | device_pm_unlock(); |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 449 | |
| 450 | /* |
| 451 | * We don't need to reenable the nonboot CPUs or resume consoles, since |
| 452 | * the system is going to be halted anyway. |
| 453 | */ |
| 454 | Finish: |
| 455 | hibernation_ops->finish(); |
| 456 | Resume_devices: |
Rafael J. Wysocki | abfe2d7 | 2009-01-19 20:54:54 +0100 | [diff] [blame] | 457 | entering_platform_hibernation = false; |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 458 | device_resume(PMSG_RESTORE); |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 459 | resume_console(); |
Rafael J. Wysocki | caea99e | 2008-01-08 00:08:44 +0100 | [diff] [blame] | 460 | Close: |
| 461 | hibernation_ops->end(); |
Rafael J. Wysocki | b1457bc | 2007-07-19 01:47:31 -0700 | [diff] [blame] | 462 | return error; |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 466 | * power_down - Shut the machine down for hibernation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | * |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 468 | * Use the platform driver, if configured so; otherwise try |
| 469 | * to power off or reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | */ |
| 471 | |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 472 | static void power_down(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 474 | switch (hibernation_mode) { |
| 475 | case HIBERNATION_TEST: |
| 476 | case HIBERNATION_TESTPROC: |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 477 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 478 | case HIBERNATION_REBOOT: |
Eric W. Biederman | fdde86a | 2005-07-26 12:01:17 -0600 | [diff] [blame] | 479 | kernel_restart(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 481 | case HIBERNATION_PLATFORM: |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 482 | hibernation_platform_enter(); |
Rafael J. Wysocki | 9cd9a00 | 2007-10-18 03:04:56 -0700 | [diff] [blame] | 483 | case HIBERNATION_SHUTDOWN: |
| 484 | kernel_power_off(); |
| 485 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | } |
Eric W. Biederman | fdde86a | 2005-07-26 12:01:17 -0600 | [diff] [blame] | 487 | kernel_halt(); |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 488 | /* |
| 489 | * Valid image is on the disk, if we continue we risk serious data |
| 490 | * corruption after resume. |
| 491 | */ |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 492 | printk(KERN_CRIT "PM: Please power down manually\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | while(1); |
| 494 | } |
| 495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | static int prepare_processes(void) |
| 497 | { |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 498 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | if (freeze_processes()) { |
| 501 | error = -EBUSY; |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 502 | thaw_processes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
Li Shaohua | 5a72e04 | 2005-06-25 14:55:06 -0700 | [diff] [blame] | 504 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 508 | * hibernate - The granpappy of the built-in hibernation management |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | */ |
| 510 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 511 | int hibernate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
| 513 | int error; |
| 514 | |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 515 | mutex_lock(&pm_mutex); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 516 | /* The snapshot device should not be opened while we're running */ |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 517 | if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { |
| 518 | error = -EBUSY; |
| 519 | goto Unlock; |
| 520 | } |
| 521 | |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 522 | pm_prepare_console(); |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 523 | error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); |
| 524 | if (error) |
| 525 | goto Exit; |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 526 | |
Rafael J. Wysocki | 1bfcf13 | 2008-10-15 22:01:21 -0700 | [diff] [blame] | 527 | error = usermodehelper_disable(); |
| 528 | if (error) |
| 529 | goto Exit; |
| 530 | |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 531 | /* Allocate memory management structures */ |
| 532 | error = create_basic_memory_bitmaps(); |
| 533 | if (error) |
| 534 | goto Exit; |
| 535 | |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 536 | printk(KERN_INFO "PM: Syncing filesystems ... "); |
Rafael J. Wysocki | 232b143 | 2007-10-18 03:04:44 -0700 | [diff] [blame] | 537 | sys_sync(); |
| 538 | printk("done.\n"); |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | error = prepare_processes(); |
Li Shaohua | 5a72e04 | 2005-06-25 14:55:06 -0700 | [diff] [blame] | 541 | if (error) |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 542 | goto Finish; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 544 | if (hibernation_test(TEST_FREEZER)) |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 545 | goto Thaw; |
Rafael J. Wysocki | 4cc7977 | 2007-11-19 23:42:31 +0100 | [diff] [blame] | 546 | |
| 547 | if (hibernation_testmode(HIBERNATION_TESTPROC)) |
| 548 | goto Thaw; |
| 549 | |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 550 | error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM); |
| 551 | if (in_suspend && !error) { |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 552 | unsigned int flags = 0; |
| 553 | |
| 554 | if (hibernation_mode == HIBERNATION_PLATFORM) |
| 555 | flags |= SF_PLATFORM_MODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | pr_debug("PM: writing image.\n"); |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 557 | error = swsusp_write(flags); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 558 | swsusp_free(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if (!error) |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 560 | power_down(); |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 561 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | pr_debug("PM: Image restored successfully.\n"); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 563 | swsusp_free(); |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 564 | } |
Rafael J. Wysocki | b918f6e | 2006-11-02 22:07:19 -0800 | [diff] [blame] | 565 | Thaw: |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 566 | thaw_processes(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 567 | Finish: |
| 568 | free_basic_memory_bitmaps(); |
Rafael J. Wysocki | 1bfcf13 | 2008-10-15 22:01:21 -0700 | [diff] [blame] | 569 | usermodehelper_enable(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 570 | Exit: |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 571 | pm_notifier_call_chain(PM_POST_HIBERNATION); |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 572 | pm_restore_console(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 573 | atomic_inc(&snapshot_device_available); |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 574 | Unlock: |
| 575 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | return error; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | /** |
| 581 | * software_resume - Resume from a saved image. |
| 582 | * |
| 583 | * Called as a late_initcall (so all devices are discovered and |
| 584 | * initialized), we call swsusp to see if we have a saved image or not. |
| 585 | * 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] | 586 | * return above (in hibernate() ) if everything goes well. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | * Otherwise, we fail gracefully and return to the normally |
| 588 | * scheduled program. |
| 589 | * |
| 590 | */ |
| 591 | |
| 592 | static int software_resume(void) |
| 593 | { |
| 594 | int error; |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 595 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Johannes Berg | 60a0d23 | 2007-11-14 17:00:16 -0800 | [diff] [blame] | 597 | /* |
| 598 | * name_to_dev_t() below takes a sysfs buffer mutex when sysfs |
| 599 | * is configured into the kernel. Since the regular hibernate |
| 600 | * trigger path is via sysfs which takes a buffer mutex before |
| 601 | * calling hibernate functions (which take pm_mutex) this can |
| 602 | * cause lockdep to complain about a possible ABBA deadlock |
| 603 | * which cannot happen since we're in the boot code here and |
| 604 | * sysfs can't be invoked yet. Therefore, we use a subclass |
| 605 | * here to avoid lockdep complaining. |
| 606 | */ |
| 607 | mutex_lock_nested(&pm_mutex, SINGLE_DEPTH_NESTING); |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 608 | if (!swsusp_resume_device) { |
Shaohua Li | dd5d666 | 2005-09-03 15:57:04 -0700 | [diff] [blame] | 609 | if (!strlen(resume_file)) { |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 610 | mutex_unlock(&pm_mutex); |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 611 | return -ENOENT; |
Shaohua Li | dd5d666 | 2005-09-03 15:57:04 -0700 | [diff] [blame] | 612 | } |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 613 | swsusp_resume_device = name_to_dev_t(resume_file); |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 614 | pr_debug("PM: Resume from partition %s\n", resume_file); |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 615 | } else { |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 616 | pr_debug("PM: Resume from partition %d:%d\n", |
| 617 | MAJOR(swsusp_resume_device), |
| 618 | MINOR(swsusp_resume_device)); |
Pavel Machek | 3efa147 | 2005-07-07 17:56:43 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | if (noresume) { |
| 622 | /** |
Rafael J. Wysocki | 9575809 | 2007-12-08 02:06:57 +0100 | [diff] [blame] | 623 | * FIXME: If noresume is specified, we need to find the |
| 624 | * partition and reset it back to normal swap space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | */ |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 626 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | return 0; |
| 628 | } |
| 629 | |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 630 | pr_debug("PM: Checking hibernation image.\n"); |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 631 | error = swsusp_check(); |
| 632 | if (error) |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 633 | goto Unlock; |
| 634 | |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 635 | /* The snapshot device should not be opened while we're running */ |
| 636 | if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { |
| 637 | error = -EBUSY; |
| 638 | goto Unlock; |
| 639 | } |
| 640 | |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 641 | pm_prepare_console(); |
Alan Stern | c3e94d8 | 2007-11-19 23:38:25 +0100 | [diff] [blame] | 642 | error = pm_notifier_call_chain(PM_RESTORE_PREPARE); |
| 643 | if (error) |
| 644 | goto Finish; |
| 645 | |
Rafael J. Wysocki | 1bfcf13 | 2008-10-15 22:01:21 -0700 | [diff] [blame] | 646 | error = usermodehelper_disable(); |
| 647 | if (error) |
| 648 | goto Finish; |
| 649 | |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 650 | error = create_basic_memory_bitmaps(); |
| 651 | if (error) |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 652 | goto Finish; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | pr_debug("PM: Preparing processes for restore.\n"); |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 655 | error = prepare_processes(); |
| 656 | if (error) { |
Al Viro | c2dd0da | 2007-10-08 13:21:10 -0400 | [diff] [blame] | 657 | swsusp_close(FMODE_READ); |
Li Shaohua | 5a72e04 | 2005-06-25 14:55:06 -0700 | [diff] [blame] | 658 | goto Done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 661 | pr_debug("PM: Reading hibernation image.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 663 | error = swsusp_read(&flags); |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 664 | if (!error) |
Rafael J. Wysocki | a634cc1 | 2007-07-19 01:47:30 -0700 | [diff] [blame] | 665 | hibernation_restore(flags & SF_PLATFORM_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Rafael J. Wysocki | ed746e3 | 2007-02-10 01:43:32 -0800 | [diff] [blame] | 667 | printk(KERN_ERR "PM: Restore failed, recovering.\n"); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 668 | swsusp_free(); |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 669 | thaw_processes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | Done: |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 671 | free_basic_memory_bitmaps(); |
Rafael J. Wysocki | 1bfcf13 | 2008-10-15 22:01:21 -0700 | [diff] [blame] | 672 | usermodehelper_enable(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 673 | Finish: |
Alan Stern | c3e94d8 | 2007-11-19 23:38:25 +0100 | [diff] [blame] | 674 | pm_notifier_call_chain(PM_POST_RESTORE); |
Rafael J. Wysocki | 5a0a2f3 | 2008-01-11 01:25:21 +0100 | [diff] [blame] | 675 | pm_restore_console(); |
Rafael J. Wysocki | 0709db6 | 2007-05-06 14:50:45 -0700 | [diff] [blame] | 676 | atomic_inc(&snapshot_device_available); |
Shaohua Li | dd5d666 | 2005-09-03 15:57:04 -0700 | [diff] [blame] | 677 | /* For success case, the suspend path will release the lock */ |
Rafael J. Wysocki | 74dfd66 | 2007-05-06 14:50:43 -0700 | [diff] [blame] | 678 | Unlock: |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 679 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | pr_debug("PM: Resume from disk failed.\n"); |
Rafael J. Wysocki | 7777fab | 2007-07-19 01:47:29 -0700 | [diff] [blame] | 681 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | late_initcall(software_resume); |
| 685 | |
| 686 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 687 | static const char * const hibernation_modes[] = { |
| 688 | [HIBERNATION_PLATFORM] = "platform", |
| 689 | [HIBERNATION_SHUTDOWN] = "shutdown", |
| 690 | [HIBERNATION_REBOOT] = "reboot", |
| 691 | [HIBERNATION_TEST] = "test", |
| 692 | [HIBERNATION_TESTPROC] = "testproc", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | }; |
| 694 | |
| 695 | /** |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 696 | * disk - Control hibernation mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | * |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 698 | * Suspend-to-disk can be handled in several ways. We have a few options |
| 699 | * 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] | 700 | * or other hibernation_ops), powering off the system or rebooting the |
| 701 | * system (for testing) as well as the two test modes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | * |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 703 | * 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] | 704 | * encoded by the presence of hibernation_ops). However, the user may |
| 705 | * choose 'shutdown' or 'reboot' as alternatives, as well as one fo the |
| 706 | * test modes, 'test' or 'testproc'. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | * |
| 708 | * show() will display what the mode is currently set to. |
| 709 | * store() will accept one of |
| 710 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | * 'platform' |
| 712 | * 'shutdown' |
| 713 | * 'reboot' |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 714 | * 'test' |
| 715 | * 'testproc' |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | * |
Johannes Berg | 11d77d0 | 2007-04-30 15:09:53 -0700 | [diff] [blame] | 717 | * It will only change to 'platform' if the system |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 718 | * supports it (as determined by having hibernation_ops). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | */ |
| 720 | |
Kay Sievers | 386f275 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 721 | static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 722 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 724 | int i; |
| 725 | char *start = buf; |
| 726 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 727 | for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { |
| 728 | if (!hibernation_modes[i]) |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 729 | continue; |
| 730 | switch (i) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 731 | case HIBERNATION_SHUTDOWN: |
| 732 | case HIBERNATION_REBOOT: |
| 733 | case HIBERNATION_TEST: |
| 734 | case HIBERNATION_TESTPROC: |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 735 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 736 | case HIBERNATION_PLATFORM: |
| 737 | if (hibernation_ops) |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 738 | break; |
| 739 | /* not a valid mode, continue with loop */ |
| 740 | continue; |
| 741 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 742 | if (i == hibernation_mode) |
| 743 | buf += sprintf(buf, "[%s] ", hibernation_modes[i]); |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 744 | else |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 745 | buf += sprintf(buf, "%s ", hibernation_modes[i]); |
Johannes Berg | f0ced9b | 2007-05-06 14:50:50 -0700 | [diff] [blame] | 746 | } |
| 747 | buf += sprintf(buf, "\n"); |
| 748 | return buf-start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
Kay Sievers | 386f275 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 752 | static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 753 | const char *buf, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
| 755 | int error = 0; |
| 756 | int i; |
| 757 | int len; |
| 758 | char *p; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 759 | int mode = HIBERNATION_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
| 761 | p = memchr(buf, '\n', n); |
| 762 | len = p ? p - buf : n; |
| 763 | |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 764 | mutex_lock(&pm_mutex); |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 765 | for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) { |
Rafael J. Wysocki | 8d98a69 | 2007-05-16 22:11:19 -0700 | [diff] [blame] | 766 | if (len == strlen(hibernation_modes[i]) |
| 767 | && !strncmp(buf, hibernation_modes[i], len)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | mode = i; |
| 769 | break; |
| 770 | } |
| 771 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 772 | if (mode != HIBERNATION_INVALID) { |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 773 | switch (mode) { |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 774 | case HIBERNATION_SHUTDOWN: |
| 775 | case HIBERNATION_REBOOT: |
| 776 | case HIBERNATION_TEST: |
| 777 | case HIBERNATION_TESTPROC: |
| 778 | hibernation_mode = mode; |
Johannes Berg | fe0c935 | 2007-04-30 15:09:51 -0700 | [diff] [blame] | 779 | break; |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 780 | case HIBERNATION_PLATFORM: |
| 781 | if (hibernation_ops) |
| 782 | hibernation_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | else |
| 784 | error = -EINVAL; |
| 785 | } |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 786 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | error = -EINVAL; |
| 788 | |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 789 | if (!error) |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 790 | pr_debug("PM: Hibernation mode set to '%s'\n", |
Rafael J. Wysocki | a3d25c2 | 2007-05-09 02:33:18 -0700 | [diff] [blame] | 791 | hibernation_modes[mode]); |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 792 | mutex_unlock(&pm_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | return error ? error : n; |
| 794 | } |
| 795 | |
| 796 | power_attr(disk); |
| 797 | |
Kay Sievers | 386f275 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 798 | static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 799 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
| 801 | return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device), |
| 802 | MINOR(swsusp_resume_device)); |
| 803 | } |
| 804 | |
Kay Sievers | 386f275 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 805 | static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 806 | const char *buf, size_t n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | unsigned int maj, min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | dev_t res; |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 810 | int ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 812 | if (sscanf(buf, "%u:%u", &maj, &min) != 2) |
| 813 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 815 | res = MKDEV(maj,min); |
| 816 | if (maj != MAJOR(res) || min != MINOR(res)) |
| 817 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 819 | mutex_lock(&pm_mutex); |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 820 | swsusp_resume_device = res; |
Stephen Hemminger | a6d7098 | 2006-12-06 20:34:35 -0800 | [diff] [blame] | 821 | mutex_unlock(&pm_mutex); |
Rafael J. Wysocki | 2397672 | 2007-12-08 02:09:43 +0100 | [diff] [blame] | 822 | printk(KERN_INFO "PM: Starting manual resume from disk\n"); |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 823 | noresume = 0; |
| 824 | software_resume(); |
| 825 | ret = n; |
Rafael J. Wysocki | 59a4933 | 2006-12-06 20:34:44 -0800 | [diff] [blame] | 826 | out: |
Andrew Morton | a576219 | 2006-01-06 00:09:50 -0800 | [diff] [blame] | 827 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | power_attr(resume); |
| 831 | |
Kay Sievers | 386f275 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 832 | static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr, |
| 833 | char *buf) |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 834 | { |
Rafael J. Wysocki | 853609b | 2006-02-01 03:05:07 -0800 | [diff] [blame] | 835 | return sprintf(buf, "%lu\n", image_size); |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 836 | } |
| 837 | |
Kay Sievers | 386f275 | 2007-11-02 13:47:53 +0100 | [diff] [blame] | 838 | static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr, |
| 839 | const char *buf, size_t n) |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 840 | { |
Rafael J. Wysocki | 853609b | 2006-02-01 03:05:07 -0800 | [diff] [blame] | 841 | unsigned long size; |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 842 | |
Rafael J. Wysocki | 853609b | 2006-02-01 03:05:07 -0800 | [diff] [blame] | 843 | if (sscanf(buf, "%lu", &size) == 1) { |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 844 | image_size = size; |
| 845 | return n; |
| 846 | } |
| 847 | |
| 848 | return -EINVAL; |
| 849 | } |
| 850 | |
| 851 | power_attr(image_size); |
| 852 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | static struct attribute * g[] = { |
| 854 | &disk_attr.attr, |
| 855 | &resume_attr.attr, |
Rafael J. Wysocki | ca0aec0 | 2006-01-06 00:15:56 -0800 | [diff] [blame] | 856 | &image_size_attr.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | NULL, |
| 858 | }; |
| 859 | |
| 860 | |
| 861 | static struct attribute_group attr_group = { |
| 862 | .attrs = g, |
| 863 | }; |
| 864 | |
| 865 | |
| 866 | static int __init pm_disk_init(void) |
| 867 | { |
Greg Kroah-Hartman | d76e15f | 2007-11-27 11:28:26 -0800 | [diff] [blame] | 868 | return sysfs_create_group(power_kobj, &attr_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | core_initcall(pm_disk_init); |
| 872 | |
| 873 | |
| 874 | static int __init resume_setup(char *str) |
| 875 | { |
| 876 | if (noresume) |
| 877 | return 1; |
| 878 | |
| 879 | strncpy( resume_file, str, 255 ); |
| 880 | return 1; |
| 881 | } |
| 882 | |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 883 | static int __init resume_offset_setup(char *str) |
| 884 | { |
| 885 | unsigned long long offset; |
| 886 | |
| 887 | if (noresume) |
| 888 | return 1; |
| 889 | |
| 890 | if (sscanf(str, "%llu", &offset) == 1) |
| 891 | swsusp_resume_block = offset; |
| 892 | |
| 893 | return 1; |
| 894 | } |
| 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | static int __init noresume_setup(char *str) |
| 897 | { |
| 898 | noresume = 1; |
| 899 | return 1; |
| 900 | } |
| 901 | |
| 902 | __setup("noresume", noresume_setup); |
Rafael J. Wysocki | 9a154d9 | 2006-12-06 20:34:12 -0800 | [diff] [blame] | 903 | __setup("resume_offset=", resume_offset_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | __setup("resume=", resume_setup); |