diff options
Diffstat (limited to 'kernel/power/disk.c')
-rw-r--r-- | kernel/power/disk.c | 92 |
1 files changed, 43 insertions, 49 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index 027322a564f4..e24446f8d8cd 100644 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c | |||
@@ -24,10 +24,11 @@ | |||
24 | 24 | ||
25 | extern suspend_disk_method_t pm_disk_mode; | 25 | extern suspend_disk_method_t pm_disk_mode; |
26 | 26 | ||
27 | extern int swsusp_shrink_memory(void); | ||
27 | extern int swsusp_suspend(void); | 28 | extern int swsusp_suspend(void); |
28 | extern int swsusp_write(void); | 29 | extern int swsusp_write(struct pbe *pblist, unsigned int nr_pages); |
29 | extern int swsusp_check(void); | 30 | extern int swsusp_check(void); |
30 | extern int swsusp_read(void); | 31 | extern int swsusp_read(struct pbe **pblist_ptr); |
31 | extern void swsusp_close(void); | 32 | extern void swsusp_close(void); |
32 | extern int swsusp_resume(void); | 33 | extern int swsusp_resume(void); |
33 | 34 | ||
@@ -73,31 +74,6 @@ static void power_down(suspend_disk_method_t mode) | |||
73 | static int in_suspend __nosavedata = 0; | 74 | static int in_suspend __nosavedata = 0; |
74 | 75 | ||
75 | 76 | ||
76 | /** | ||
77 | * free_some_memory - Try to free as much memory as possible | ||
78 | * | ||
79 | * ... but do not OOM-kill anyone | ||
80 | * | ||
81 | * Notice: all userland should be stopped at this point, or | ||
82 | * livelock is possible. | ||
83 | */ | ||
84 | |||
85 | static void free_some_memory(void) | ||
86 | { | ||
87 | unsigned int i = 0; | ||
88 | unsigned int tmp; | ||
89 | unsigned long pages = 0; | ||
90 | char *p = "-\\|/"; | ||
91 | |||
92 | printk("Freeing memory... "); | ||
93 | while ((tmp = shrink_all_memory(10000))) { | ||
94 | pages += tmp; | ||
95 | printk("\b%c", p[i++ % 4]); | ||
96 | } | ||
97 | printk("\bdone (%li pages freed)\n", pages); | ||
98 | } | ||
99 | |||
100 | |||
101 | static inline void platform_finish(void) | 77 | static inline void platform_finish(void) |
102 | { | 78 | { |
103 | if (pm_disk_mode == PM_DISK_PLATFORM) { | 79 | if (pm_disk_mode == PM_DISK_PLATFORM) { |
@@ -127,8 +103,8 @@ static int prepare_processes(void) | |||
127 | } | 103 | } |
128 | 104 | ||
129 | /* Free memory before shutting down devices. */ | 105 | /* Free memory before shutting down devices. */ |
130 | free_some_memory(); | 106 | if (!(error = swsusp_shrink_memory())) |
131 | return 0; | 107 | return 0; |
132 | thaw: | 108 | thaw: |
133 | thaw_processes(); | 109 | thaw_processes(); |
134 | enable_nonboot_cpus(); | 110 | enable_nonboot_cpus(); |
@@ -176,7 +152,7 @@ int pm_suspend_disk(void) | |||
176 | if (in_suspend) { | 152 | if (in_suspend) { |
177 | device_resume(); | 153 | device_resume(); |
178 | pr_debug("PM: writing image.\n"); | 154 | pr_debug("PM: writing image.\n"); |
179 | error = swsusp_write(); | 155 | error = swsusp_write(pagedir_nosave, nr_copy_pages); |
180 | if (!error) | 156 | if (!error) |
181 | power_down(pm_disk_mode); | 157 | power_down(pm_disk_mode); |
182 | else { | 158 | else { |
@@ -247,7 +223,7 @@ static int software_resume(void) | |||
247 | 223 | ||
248 | pr_debug("PM: Reading swsusp image.\n"); | 224 | pr_debug("PM: Reading swsusp image.\n"); |
249 | 225 | ||
250 | if ((error = swsusp_read())) { | 226 | if ((error = swsusp_read(&pagedir_nosave))) { |
251 | swsusp_free(); | 227 | swsusp_free(); |
252 | goto Thaw; | 228 | goto Thaw; |
253 | } | 229 | } |
@@ -363,37 +339,55 @@ static ssize_t resume_show(struct subsystem * subsys, char *buf) | |||
363 | MINOR(swsusp_resume_device)); | 339 | MINOR(swsusp_resume_device)); |
364 | } | 340 | } |
365 | 341 | ||
366 | static ssize_t resume_store(struct subsystem * subsys, const char * buf, size_t n) | 342 | static ssize_t resume_store(struct subsystem *subsys, const char *buf, size_t n) |
367 | { | 343 | { |
368 | int len; | ||
369 | char *p; | ||
370 | unsigned int maj, min; | 344 | unsigned int maj, min; |
371 | int error = -EINVAL; | ||
372 | dev_t res; | 345 | dev_t res; |
346 | int ret = -EINVAL; | ||
373 | 347 | ||
374 | p = memchr(buf, '\n', n); | 348 | if (sscanf(buf, "%u:%u", &maj, &min) != 2) |
375 | len = p ? p - buf : n; | 349 | goto out; |
376 | 350 | ||
377 | if (sscanf(buf, "%u:%u", &maj, &min) == 2) { | 351 | res = MKDEV(maj,min); |
378 | res = MKDEV(maj,min); | 352 | if (maj != MAJOR(res) || min != MINOR(res)) |
379 | if (maj == MAJOR(res) && min == MINOR(res)) { | 353 | goto out; |
380 | down(&pm_sem); | ||
381 | swsusp_resume_device = res; | ||
382 | up(&pm_sem); | ||
383 | printk("Attempting manual resume\n"); | ||
384 | noresume = 0; | ||
385 | software_resume(); | ||
386 | } | ||
387 | } | ||
388 | 354 | ||
389 | return error >= 0 ? n : error; | 355 | down(&pm_sem); |
356 | swsusp_resume_device = res; | ||
357 | up(&pm_sem); | ||
358 | printk("Attempting manual resume\n"); | ||
359 | noresume = 0; | ||
360 | software_resume(); | ||
361 | ret = n; | ||
362 | out: | ||
363 | return ret; | ||
390 | } | 364 | } |
391 | 365 | ||
392 | power_attr(resume); | 366 | power_attr(resume); |
393 | 367 | ||
368 | static ssize_t image_size_show(struct subsystem * subsys, char *buf) | ||
369 | { | ||
370 | return sprintf(buf, "%u\n", image_size); | ||
371 | } | ||
372 | |||
373 | static ssize_t image_size_store(struct subsystem * subsys, const char * buf, size_t n) | ||
374 | { | ||
375 | unsigned int size; | ||
376 | |||
377 | if (sscanf(buf, "%u", &size) == 1) { | ||
378 | image_size = size; | ||
379 | return n; | ||
380 | } | ||
381 | |||
382 | return -EINVAL; | ||
383 | } | ||
384 | |||
385 | power_attr(image_size); | ||
386 | |||
394 | static struct attribute * g[] = { | 387 | static struct attribute * g[] = { |
395 | &disk_attr.attr, | 388 | &disk_attr.attr, |
396 | &resume_attr.attr, | 389 | &resume_attr.attr, |
390 | &image_size_attr.attr, | ||
397 | NULL, | 391 | NULL, |
398 | }; | 392 | }; |
399 | 393 | ||