diff options
Diffstat (limited to 'kernel/power/disk.c')
| -rw-r--r-- | kernel/power/disk.c | 88 |
1 files changed, 50 insertions, 38 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index dee0ff40befd..02e4fb69111a 100644 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c | |||
| @@ -39,7 +39,13 @@ static inline int platform_prepare(void) | |||
| 39 | { | 39 | { |
| 40 | int error = 0; | 40 | int error = 0; |
| 41 | 41 | ||
| 42 | if (pm_disk_mode == PM_DISK_PLATFORM) { | 42 | 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: | ||
| 43 | if (pm_ops && pm_ops->prepare) | 49 | if (pm_ops && pm_ops->prepare) |
| 44 | error = pm_ops->prepare(PM_SUSPEND_DISK); | 50 | error = pm_ops->prepare(PM_SUSPEND_DISK); |
| 45 | } | 51 | } |
| @@ -48,41 +54,48 @@ static inline int platform_prepare(void) | |||
| 48 | 54 | ||
| 49 | /** | 55 | /** |
| 50 | * power_down - Shut machine down for hibernate. | 56 | * power_down - Shut machine down for hibernate. |
| 51 | * @mode: Suspend-to-disk mode | ||
| 52 | * | 57 | * |
| 53 | * Use the platform driver, if configured so, and return gracefully if it | 58 | * Use the platform driver, if configured so; otherwise try |
| 54 | * fails. | 59 | * to power off or reboot. |
| 55 | * Otherwise, try to power off and reboot. If they fail, halt the machine, | ||
| 56 | * there ain't no turning back. | ||
| 57 | */ | 60 | */ |
| 58 | 61 | ||
| 59 | static void power_down(suspend_disk_method_t mode) | 62 | static void power_down(void) |
| 60 | { | 63 | { |
| 61 | disable_nonboot_cpus(); | 64 | switch (pm_disk_mode) { |
| 62 | switch(mode) { | 65 | case PM_DISK_TEST: |
| 63 | case PM_DISK_PLATFORM: | 66 | case PM_DISK_TESTPROC: |
| 64 | if (pm_ops && pm_ops->enter) { | 67 | break; |
| 65 | kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK); | ||
| 66 | pm_ops->enter(PM_SUSPEND_DISK); | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | case PM_DISK_SHUTDOWN: | 68 | case PM_DISK_SHUTDOWN: |
| 70 | kernel_power_off(); | 69 | kernel_power_off(); |
| 71 | break; | 70 | break; |
| 72 | case PM_DISK_REBOOT: | 71 | case PM_DISK_REBOOT: |
| 73 | kernel_restart(NULL); | 72 | kernel_restart(NULL); |
| 74 | break; | 73 | break; |
| 74 | 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 | } | ||
| 75 | } | 80 | } |
| 76 | kernel_halt(); | 81 | kernel_halt(); |
| 77 | /* Valid image is on the disk, if we continue we risk serious data corruption | 82 | /* |
| 78 | after resume. */ | 83 | * Valid image is on the disk, if we continue we risk serious data |
| 84 | * corruption after resume. | ||
| 85 | */ | ||
| 79 | printk(KERN_CRIT "Please power me down manually\n"); | 86 | printk(KERN_CRIT "Please power me down manually\n"); |
| 80 | while(1); | 87 | while(1); |
| 81 | } | 88 | } |
| 82 | 89 | ||
| 83 | static inline void platform_finish(void) | 90 | static inline void platform_finish(void) |
| 84 | { | 91 | { |
| 85 | if (pm_disk_mode == PM_DISK_PLATFORM) { | 92 | 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: | ||
| 86 | if (pm_ops && pm_ops->finish) | 99 | if (pm_ops && pm_ops->finish) |
| 87 | pm_ops->finish(PM_SUSPEND_DISK); | 100 | pm_ops->finish(PM_SUSPEND_DISK); |
| 88 | } | 101 | } |
| @@ -109,8 +122,6 @@ static int prepare_processes(void) | |||
| 109 | /** | 122 | /** |
| 110 | * pm_suspend_disk - The granpappy of hibernation power management. | 123 | * pm_suspend_disk - The granpappy of hibernation power management. |
| 111 | * | 124 | * |
| 112 | * If we're going through the firmware, then get it over with quickly. | ||
| 113 | * | ||
| 114 | * If not, then call swsusp to do its thing, then figure out how | 125 | * If not, then call swsusp to do its thing, then figure out how |
| 115 | * to power down the system. | 126 | * to power down the system. |
| 116 | */ | 127 | */ |
| @@ -167,7 +178,7 @@ int pm_suspend_disk(void) | |||
| 167 | pr_debug("PM: writing image.\n"); | 178 | pr_debug("PM: writing image.\n"); |
| 168 | error = swsusp_write(); | 179 | error = swsusp_write(); |
| 169 | if (!error) | 180 | if (!error) |
| 170 | power_down(pm_disk_mode); | 181 | power_down(); |
| 171 | else { | 182 | else { |
| 172 | swsusp_free(); | 183 | swsusp_free(); |
| 173 | goto Thaw; | 184 | goto Thaw; |
| @@ -279,7 +290,6 @@ late_initcall(software_resume); | |||
| 279 | 290 | ||
| 280 | 291 | ||
| 281 | static const char * const pm_disk_modes[] = { | 292 | static const char * const pm_disk_modes[] = { |
| 282 | [PM_DISK_FIRMWARE] = "firmware", | ||
| 283 | [PM_DISK_PLATFORM] = "platform", | 293 | [PM_DISK_PLATFORM] = "platform", |
| 284 | [PM_DISK_SHUTDOWN] = "shutdown", | 294 | [PM_DISK_SHUTDOWN] = "shutdown", |
| 285 | [PM_DISK_REBOOT] = "reboot", | 295 | [PM_DISK_REBOOT] = "reboot", |
| @@ -290,27 +300,25 @@ static const char * const pm_disk_modes[] = { | |||
| 290 | /** | 300 | /** |
| 291 | * disk - Control suspend-to-disk mode | 301 | * disk - Control suspend-to-disk mode |
| 292 | * | 302 | * |
| 293 | * Suspend-to-disk can be handled in several ways. The greatest | 303 | * Suspend-to-disk can be handled in several ways. We have a few options |
| 294 | * distinction is who writes memory to disk - the firmware or the OS. | 304 | * for putting the system to sleep - using the platform driver (e.g. ACPI |
| 295 | * If the firmware does it, we assume that it also handles suspending | 305 | * or other pm_ops), powering off the system or rebooting the system |
| 296 | * the system. | 306 | * (for testing) as well as the two test modes. |
| 297 | * If the OS does it, then we have three options for putting the system | ||
| 298 | * to sleep - using the platform driver (e.g. ACPI or other PM registers), | ||
| 299 | * powering off the system or rebooting the system (for testing). | ||
| 300 | * | 307 | * |
| 301 | * The system will support either 'firmware' or 'platform', and that is | 308 | * The system can support 'platform', and that is known a priori (and |
| 302 | * known a priori (and encoded in pm_ops). But, the user may choose | 309 | * encoded in pm_ops). However, the user may choose 'shutdown' or 'reboot' |
| 303 | * 'shutdown' or 'reboot' as alternatives. | 310 | * as alternatives, as well as the test modes 'test' and 'testproc'. |
| 304 | * | 311 | * |
| 305 | * show() will display what the mode is currently set to. | 312 | * show() will display what the mode is currently set to. |
| 306 | * store() will accept one of | 313 | * store() will accept one of |
| 307 | * | 314 | * |
| 308 | * 'firmware' | ||
| 309 | * 'platform' | 315 | * 'platform' |
| 310 | * 'shutdown' | 316 | * 'shutdown' |
| 311 | * 'reboot' | 317 | * 'reboot' |
| 318 | * 'test' | ||
| 319 | * 'testproc' | ||
| 312 | * | 320 | * |
| 313 | * It will only change to 'firmware' or 'platform' if the system | 321 | * It will only change to 'platform' if the system |
| 314 | * supports it (as determined from pm_ops->pm_disk_mode). | 322 | * supports it (as determined from pm_ops->pm_disk_mode). |
| 315 | */ | 323 | */ |
| 316 | 324 | ||
| @@ -332,17 +340,21 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n) | |||
| 332 | len = p ? p - buf : n; | 340 | len = p ? p - buf : n; |
| 333 | 341 | ||
| 334 | mutex_lock(&pm_mutex); | 342 | mutex_lock(&pm_mutex); |
| 335 | for (i = PM_DISK_FIRMWARE; i < PM_DISK_MAX; i++) { | 343 | for (i = PM_DISK_PLATFORM; i < PM_DISK_MAX; i++) { |
| 336 | if (!strncmp(buf, pm_disk_modes[i], len)) { | 344 | if (!strncmp(buf, pm_disk_modes[i], len)) { |
| 337 | mode = i; | 345 | mode = i; |
| 338 | break; | 346 | break; |
| 339 | } | 347 | } |
| 340 | } | 348 | } |
| 341 | if (mode) { | 349 | if (mode) { |
| 342 | if (mode == PM_DISK_SHUTDOWN || mode == PM_DISK_REBOOT || | 350 | switch (mode) { |
| 343 | mode == PM_DISK_TEST || mode == PM_DISK_TESTPROC) { | 351 | case PM_DISK_SHUTDOWN: |
| 352 | case PM_DISK_REBOOT: | ||
| 353 | case PM_DISK_TEST: | ||
| 354 | case PM_DISK_TESTPROC: | ||
| 344 | pm_disk_mode = mode; | 355 | pm_disk_mode = mode; |
| 345 | } else { | 356 | break; |
| 357 | default: | ||
| 346 | if (pm_ops && pm_ops->enter && | 358 | if (pm_ops && pm_ops->enter && |
| 347 | (mode == pm_ops->pm_disk_mode)) | 359 | (mode == pm_ops->pm_disk_mode)) |
| 348 | pm_disk_mode = mode; | 360 | pm_disk_mode = mode; |
