diff options
Diffstat (limited to 'kernel/power/disk.c')
-rw-r--r-- | kernel/power/disk.c | 94 |
1 files changed, 50 insertions, 44 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index 406b20adb27a..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,40 +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 | switch(mode) { | 64 | switch (pm_disk_mode) { |
62 | case PM_DISK_PLATFORM: | 65 | case PM_DISK_TEST: |
63 | if (pm_ops && pm_ops->enter) { | 66 | case PM_DISK_TESTPROC: |
64 | kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK); | 67 | break; |
65 | pm_ops->enter(PM_SUSPEND_DISK); | ||
66 | break; | ||
67 | } | ||
68 | case PM_DISK_SHUTDOWN: | 68 | case PM_DISK_SHUTDOWN: |
69 | kernel_power_off(); | 69 | kernel_power_off(); |
70 | break; | 70 | break; |
71 | case PM_DISK_REBOOT: | 71 | case PM_DISK_REBOOT: |
72 | kernel_restart(NULL); | 72 | kernel_restart(NULL); |
73 | 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 | } | ||
74 | } | 80 | } |
75 | kernel_halt(); | 81 | kernel_halt(); |
76 | /* Valid image is on the disk, if we continue we risk serious data corruption | 82 | /* |
77 | after resume. */ | 83 | * Valid image is on the disk, if we continue we risk serious data |
84 | * corruption after resume. | ||
85 | */ | ||
78 | printk(KERN_CRIT "Please power me down manually\n"); | 86 | printk(KERN_CRIT "Please power me down manually\n"); |
79 | while(1); | 87 | while(1); |
80 | } | 88 | } |
81 | 89 | ||
82 | static inline void platform_finish(void) | 90 | static inline void platform_finish(void) |
83 | { | 91 | { |
84 | 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: | ||
85 | if (pm_ops && pm_ops->finish) | 99 | if (pm_ops && pm_ops->finish) |
86 | pm_ops->finish(PM_SUSPEND_DISK); | 100 | pm_ops->finish(PM_SUSPEND_DISK); |
87 | } | 101 | } |
@@ -108,8 +122,6 @@ static int prepare_processes(void) | |||
108 | /** | 122 | /** |
109 | * pm_suspend_disk - The granpappy of hibernation power management. | 123 | * pm_suspend_disk - The granpappy of hibernation power management. |
110 | * | 124 | * |
111 | * If we're going through the firmware, then get it over with quickly. | ||
112 | * | ||
113 | * 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 |
114 | * to power down the system. | 126 | * to power down the system. |
115 | */ | 127 | */ |
@@ -166,7 +178,7 @@ int pm_suspend_disk(void) | |||
166 | pr_debug("PM: writing image.\n"); | 178 | pr_debug("PM: writing image.\n"); |
167 | error = swsusp_write(); | 179 | error = swsusp_write(); |
168 | if (!error) | 180 | if (!error) |
169 | power_down(pm_disk_mode); | 181 | power_down(); |
170 | else { | 182 | else { |
171 | swsusp_free(); | 183 | swsusp_free(); |
172 | goto Thaw; | 184 | goto Thaw; |
@@ -240,12 +252,6 @@ static int software_resume(void) | |||
240 | goto Done; | 252 | goto Done; |
241 | } | 253 | } |
242 | 254 | ||
243 | error = platform_prepare(); | ||
244 | if (error) { | ||
245 | swsusp_free(); | ||
246 | goto Thaw; | ||
247 | } | ||
248 | |||
249 | pr_debug("PM: Reading swsusp image.\n"); | 255 | pr_debug("PM: Reading swsusp image.\n"); |
250 | 256 | ||
251 | error = swsusp_read(); | 257 | error = swsusp_read(); |
@@ -268,7 +274,6 @@ static int software_resume(void) | |||
268 | enable_nonboot_cpus(); | 274 | enable_nonboot_cpus(); |
269 | Free: | 275 | Free: |
270 | swsusp_free(); | 276 | swsusp_free(); |
271 | platform_finish(); | ||
272 | device_resume(); | 277 | device_resume(); |
273 | resume_console(); | 278 | resume_console(); |
274 | Thaw: | 279 | Thaw: |
@@ -285,7 +290,6 @@ late_initcall(software_resume); | |||
285 | 290 | ||
286 | 291 | ||
287 | static const char * const pm_disk_modes[] = { | 292 | static const char * const pm_disk_modes[] = { |
288 | [PM_DISK_FIRMWARE] = "firmware", | ||
289 | [PM_DISK_PLATFORM] = "platform", | 293 | [PM_DISK_PLATFORM] = "platform", |
290 | [PM_DISK_SHUTDOWN] = "shutdown", | 294 | [PM_DISK_SHUTDOWN] = "shutdown", |
291 | [PM_DISK_REBOOT] = "reboot", | 295 | [PM_DISK_REBOOT] = "reboot", |
@@ -296,27 +300,25 @@ static const char * const pm_disk_modes[] = { | |||
296 | /** | 300 | /** |
297 | * disk - Control suspend-to-disk mode | 301 | * disk - Control suspend-to-disk mode |
298 | * | 302 | * |
299 | * 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 |
300 | * 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 |
301 | * 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 |
302 | * the system. | 306 | * (for testing) as well as the two test modes. |
303 | * If the OS does it, then we have three options for putting the system | ||
304 | * to sleep - using the platform driver (e.g. ACPI or other PM registers), | ||
305 | * powering off the system or rebooting the system (for testing). | ||
306 | * | 307 | * |
307 | * The system will support either 'firmware' or 'platform', and that is | 308 | * The system can support 'platform', and that is known a priori (and |
308 | * 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' |
309 | * 'shutdown' or 'reboot' as alternatives. | 310 | * as alternatives, as well as the test modes 'test' and 'testproc'. |
310 | * | 311 | * |
311 | * show() will display what the mode is currently set to. | 312 | * show() will display what the mode is currently set to. |
312 | * store() will accept one of | 313 | * store() will accept one of |
313 | * | 314 | * |
314 | * 'firmware' | ||
315 | * 'platform' | 315 | * 'platform' |
316 | * 'shutdown' | 316 | * 'shutdown' |
317 | * 'reboot' | 317 | * 'reboot' |
318 | * 'test' | ||
319 | * 'testproc' | ||
318 | * | 320 | * |
319 | * It will only change to 'firmware' or 'platform' if the system | 321 | * It will only change to 'platform' if the system |
320 | * supports it (as determined from pm_ops->pm_disk_mode). | 322 | * supports it (as determined from pm_ops->pm_disk_mode). |
321 | */ | 323 | */ |
322 | 324 | ||
@@ -338,17 +340,21 @@ static ssize_t disk_store(struct subsystem * s, const char * buf, size_t n) | |||
338 | len = p ? p - buf : n; | 340 | len = p ? p - buf : n; |
339 | 341 | ||
340 | mutex_lock(&pm_mutex); | 342 | mutex_lock(&pm_mutex); |
341 | for (i = PM_DISK_FIRMWARE; i < PM_DISK_MAX; i++) { | 343 | for (i = PM_DISK_PLATFORM; i < PM_DISK_MAX; i++) { |
342 | if (!strncmp(buf, pm_disk_modes[i], len)) { | 344 | if (!strncmp(buf, pm_disk_modes[i], len)) { |
343 | mode = i; | 345 | mode = i; |
344 | break; | 346 | break; |
345 | } | 347 | } |
346 | } | 348 | } |
347 | if (mode) { | 349 | if (mode) { |
348 | if (mode == PM_DISK_SHUTDOWN || mode == PM_DISK_REBOOT || | 350 | switch (mode) { |
349 | 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: | ||
350 | pm_disk_mode = mode; | 355 | pm_disk_mode = mode; |
351 | } else { | 356 | break; |
357 | default: | ||
352 | if (pm_ops && pm_ops->enter && | 358 | if (pm_ops && pm_ops->enter && |
353 | (mode == pm_ops->pm_disk_mode)) | 359 | (mode == pm_ops->pm_disk_mode)) |
354 | pm_disk_mode = mode; | 360 | pm_disk_mode = mode; |