PM: Change hibernation code ordering
[deliverable/linux.git] / kernel / power / disk.c
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/kmod.h>
18 #include <linux/delay.h>
19 #include <linux/fs.h>
20 #include <linux/mount.h>
21 #include <linux/pm.h>
22 #include <linux/console.h>
23 #include <linux/cpu.h>
24 #include <linux/freezer.h>
25
26 #include "power.h"
27
28
29 static int noresume = 0;
30 static char resume_file[256] = CONFIG_PM_STD_PARTITION;
31 dev_t swsusp_resume_device;
32 sector_t swsusp_resume_block;
33
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
49 static struct platform_hibernation_ops *hibernation_ops;
50
51 /**
52 * hibernation_set_ops - set the global hibernate operations
53 * @ops: the hibernation operations to use in subsequent hibernation transitions
54 */
55
56 void hibernation_set_ops(struct platform_hibernation_ops *ops)
57 {
58 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
59 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
60 && ops->restore_cleanup)) {
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
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
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
111 /**
112 * platform_begin - tell the platform driver that we're starting
113 * hibernation
114 */
115
116 static int platform_begin(int platform_mode)
117 {
118 return (platform_mode && hibernation_ops) ?
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();
131 }
132
133 /**
134 * platform_pre_snapshot - prepare the machine for hibernation using the
135 * platform driver if so configured and return an error code if it fails
136 */
137
138 static int platform_pre_snapshot(int platform_mode)
139 {
140 return (platform_mode && hibernation_ops) ?
141 hibernation_ops->pre_snapshot() : 0;
142 }
143
144 /**
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 /**
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
160 static void platform_finish(int platform_mode)
161 {
162 if (platform_mode && hibernation_ops)
163 hibernation_ops->finish();
164 }
165
166 /**
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 /**
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 /**
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
208 static int create_image(int platform_mode)
209 {
210 int error;
211
212 error = arch_prepare_suspend();
213 if (error)
214 return error;
215
216 device_pm_lock();
217
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) {
226 printk(KERN_ERR "PM: Some devices failed to power down, "
227 "aborting hibernation\n");
228 goto Unlock;
229 }
230
231 error = platform_pre_snapshot(platform_mode);
232 if (error || hibernation_test(TEST_PLATFORM))
233 goto Platform_finish;
234
235 error = disable_nonboot_cpus();
236 if (error || hibernation_test(TEST_CPUS)
237 || hibernation_testmode(HIBERNATION_TEST))
238 goto Enable_cpus;
239
240 local_irq_disable();
241
242 sysdev_suspend(PMSG_FREEZE);
243 if (error) {
244 printk(KERN_ERR "PM: Some devices failed to power down, "
245 "aborting hibernation\n");
246 goto Enable_irqs;
247 }
248
249 if (hibernation_test(TEST_CORE))
250 goto Power_up;
251
252 in_suspend = 1;
253 save_processor_state();
254 error = swsusp_arch_suspend();
255 if (error)
256 printk(KERN_ERR "PM: Error %d creating hibernation image\n",
257 error);
258 /* Restore control flow magically appears here */
259 restore_processor_state();
260 if (!in_suspend)
261 platform_leave(platform_mode);
262
263 Power_up:
264 sysdev_resume();
265 /* NOTE: device_power_up() is just a resume() for devices
266 * that suspended with irqs off ... no overall powerup.
267 */
268
269 Enable_irqs:
270 local_irq_enable();
271
272 Enable_cpus:
273 enable_nonboot_cpus();
274
275 Platform_finish:
276 platform_finish(platform_mode);
277
278 device_power_up(in_suspend ?
279 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
280
281 Unlock:
282 device_pm_unlock();
283
284 return error;
285 }
286
287 /**
288 * hibernation_snapshot - quiesce devices and create the hibernation
289 * snapshot image.
290 * @platform_mode - if set, use the platform driver, if available, to
291 * prepare the platform frimware for the power transition.
292 *
293 * Must be called with pm_mutex held
294 */
295
296 int hibernation_snapshot(int platform_mode)
297 {
298 int error;
299
300 error = platform_begin(platform_mode);
301 if (error)
302 return error;
303
304 /* Free memory before shutting down devices. */
305 error = swsusp_shrink_memory();
306 if (error)
307 goto Close;
308
309 suspend_console();
310 error = device_suspend(PMSG_FREEZE);
311 if (error)
312 goto Recover_platform;
313
314 if (hibernation_test(TEST_DEVICES))
315 goto Recover_platform;
316
317 error = create_image(platform_mode);
318 /* Control returns here after successful restore */
319
320 Resume_devices:
321 device_resume(in_suspend ?
322 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
323 resume_console();
324 Close:
325 platform_end(platform_mode);
326 return error;
327
328 Recover_platform:
329 platform_recover(platform_mode);
330 goto Resume_devices;
331 }
332
333 /**
334 * resume_target_kernel - prepare devices that need to be suspended with
335 * interrupts off, restore the contents of highmem that have not been
336 * restored yet from the image and run the low level code that will restore
337 * the remaining contents of memory and switch to the just restored target
338 * kernel.
339 */
340
341 static int resume_target_kernel(bool platform_mode)
342 {
343 int error;
344
345 device_pm_lock();
346
347 error = device_power_down(PMSG_QUIESCE);
348 if (error) {
349 printk(KERN_ERR "PM: Some devices failed to power down, "
350 "aborting resume\n");
351 goto Unlock;
352 }
353
354 error = platform_pre_restore(platform_mode);
355 if (error)
356 goto Cleanup;
357
358 error = disable_nonboot_cpus();
359 if (error)
360 goto Enable_cpus;
361
362 local_irq_disable();
363
364 error = sysdev_suspend(PMSG_QUIESCE);
365 if (error)
366 goto Enable_irqs;
367
368 /* We'll ignore saved state, but this gets preempt count (etc) right */
369 save_processor_state();
370 error = restore_highmem();
371 if (!error) {
372 error = swsusp_arch_resume();
373 /*
374 * The code below is only ever reached in case of a failure.
375 * Otherwise execution continues at place where
376 * swsusp_arch_suspend() was called
377 */
378 BUG_ON(!error);
379 /* This call to restore_highmem() undos the previous one */
380 restore_highmem();
381 }
382 /*
383 * The only reason why swsusp_arch_resume() can fail is memory being
384 * very tight, so we have to free it as soon as we can to avoid
385 * subsequent failures
386 */
387 swsusp_free();
388 restore_processor_state();
389 touch_softlockup_watchdog();
390
391 sysdev_resume();
392
393 Enable_irqs:
394 local_irq_enable();
395
396 Enable_cpus:
397 enable_nonboot_cpus();
398
399 Cleanup:
400 platform_restore_cleanup(platform_mode);
401
402 device_power_up(PMSG_RECOVER);
403
404 Unlock:
405 device_pm_unlock();
406
407 return error;
408 }
409
410 /**
411 * hibernation_restore - quiesce devices and restore the hibernation
412 * snapshot image. If successful, control returns in hibernation_snaphot()
413 * @platform_mode - if set, use the platform driver, if available, to
414 * prepare the platform frimware for the transition.
415 *
416 * Must be called with pm_mutex held
417 */
418
419 int hibernation_restore(int platform_mode)
420 {
421 int error;
422
423 pm_prepare_console();
424 suspend_console();
425 error = device_suspend(PMSG_QUIESCE);
426 if (!error) {
427 error = resume_target_kernel(platform_mode);
428 device_resume(PMSG_RECOVER);
429 }
430 resume_console();
431 pm_restore_console();
432 return error;
433 }
434
435 /**
436 * hibernation_platform_enter - enter the hibernation state using the
437 * platform driver (if available)
438 */
439
440 int hibernation_platform_enter(void)
441 {
442 int error;
443
444 if (!hibernation_ops)
445 return -ENOSYS;
446
447 /*
448 * We have cancelled the power transition by running
449 * hibernation_ops->finish() before saving the image, so we should let
450 * the firmware know that we're going to enter the sleep state after all
451 */
452 error = hibernation_ops->begin();
453 if (error)
454 goto Close;
455
456 entering_platform_hibernation = true;
457 suspend_console();
458 error = device_suspend(PMSG_HIBERNATE);
459 if (error) {
460 if (hibernation_ops->recover)
461 hibernation_ops->recover();
462 goto Resume_devices;
463 }
464
465 device_pm_lock();
466
467 error = device_power_down(PMSG_HIBERNATE);
468 if (error)
469 goto Unlock;
470
471 error = hibernation_ops->prepare();
472 if (error)
473 goto Platofrm_finish;
474
475 error = disable_nonboot_cpus();
476 if (error)
477 goto Platofrm_finish;
478
479 local_irq_disable();
480 sysdev_suspend(PMSG_HIBERNATE);
481 hibernation_ops->enter();
482 /* We should never get here */
483 while (1);
484
485 /*
486 * We don't need to reenable the nonboot CPUs or resume consoles, since
487 * the system is going to be halted anyway.
488 */
489 Platofrm_finish:
490 hibernation_ops->finish();
491
492 device_power_up(PMSG_RESTORE);
493
494 Unlock:
495 device_pm_unlock();
496
497 Resume_devices:
498 entering_platform_hibernation = false;
499 device_resume(PMSG_RESTORE);
500 resume_console();
501
502 Close:
503 hibernation_ops->end();
504
505 return error;
506 }
507
508 /**
509 * power_down - Shut the machine down for hibernation.
510 *
511 * Use the platform driver, if configured so; otherwise try
512 * to power off or reboot.
513 */
514
515 static void power_down(void)
516 {
517 switch (hibernation_mode) {
518 case HIBERNATION_TEST:
519 case HIBERNATION_TESTPROC:
520 break;
521 case HIBERNATION_REBOOT:
522 kernel_restart(NULL);
523 break;
524 case HIBERNATION_PLATFORM:
525 hibernation_platform_enter();
526 case HIBERNATION_SHUTDOWN:
527 kernel_power_off();
528 break;
529 }
530 kernel_halt();
531 /*
532 * Valid image is on the disk, if we continue we risk serious data
533 * corruption after resume.
534 */
535 printk(KERN_CRIT "PM: Please power down manually\n");
536 while(1);
537 }
538
539 static int prepare_processes(void)
540 {
541 int error = 0;
542
543 if (freeze_processes()) {
544 error = -EBUSY;
545 thaw_processes();
546 }
547 return error;
548 }
549
550 /**
551 * hibernate - The granpappy of the built-in hibernation management
552 */
553
554 int hibernate(void)
555 {
556 int error;
557
558 mutex_lock(&pm_mutex);
559 /* The snapshot device should not be opened while we're running */
560 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
561 error = -EBUSY;
562 goto Unlock;
563 }
564
565 pm_prepare_console();
566 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
567 if (error)
568 goto Exit;
569
570 error = usermodehelper_disable();
571 if (error)
572 goto Exit;
573
574 /* Allocate memory management structures */
575 error = create_basic_memory_bitmaps();
576 if (error)
577 goto Exit;
578
579 printk(KERN_INFO "PM: Syncing filesystems ... ");
580 sys_sync();
581 printk("done.\n");
582
583 error = prepare_processes();
584 if (error)
585 goto Finish;
586
587 if (hibernation_test(TEST_FREEZER))
588 goto Thaw;
589
590 if (hibernation_testmode(HIBERNATION_TESTPROC))
591 goto Thaw;
592
593 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
594 if (in_suspend && !error) {
595 unsigned int flags = 0;
596
597 if (hibernation_mode == HIBERNATION_PLATFORM)
598 flags |= SF_PLATFORM_MODE;
599 pr_debug("PM: writing image.\n");
600 error = swsusp_write(flags);
601 swsusp_free();
602 if (!error)
603 power_down();
604 } else {
605 pr_debug("PM: Image restored successfully.\n");
606 swsusp_free();
607 }
608 Thaw:
609 thaw_processes();
610 Finish:
611 free_basic_memory_bitmaps();
612 usermodehelper_enable();
613 Exit:
614 pm_notifier_call_chain(PM_POST_HIBERNATION);
615 pm_restore_console();
616 atomic_inc(&snapshot_device_available);
617 Unlock:
618 mutex_unlock(&pm_mutex);
619 return error;
620 }
621
622
623 /**
624 * software_resume - Resume from a saved image.
625 *
626 * Called as a late_initcall (so all devices are discovered and
627 * initialized), we call swsusp to see if we have a saved image or not.
628 * If so, we quiesce devices, the restore the saved image. We will
629 * return above (in hibernate() ) if everything goes well.
630 * Otherwise, we fail gracefully and return to the normally
631 * scheduled program.
632 *
633 */
634
635 static int software_resume(void)
636 {
637 int error;
638 unsigned int flags;
639
640 /*
641 * If the user said "noresume".. bail out early.
642 */
643 if (noresume)
644 return 0;
645
646 /*
647 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
648 * is configured into the kernel. Since the regular hibernate
649 * trigger path is via sysfs which takes a buffer mutex before
650 * calling hibernate functions (which take pm_mutex) this can
651 * cause lockdep to complain about a possible ABBA deadlock
652 * which cannot happen since we're in the boot code here and
653 * sysfs can't be invoked yet. Therefore, we use a subclass
654 * here to avoid lockdep complaining.
655 */
656 mutex_lock_nested(&pm_mutex, SINGLE_DEPTH_NESTING);
657 if (!swsusp_resume_device) {
658 if (!strlen(resume_file)) {
659 mutex_unlock(&pm_mutex);
660 return -ENOENT;
661 }
662 /*
663 * Some device discovery might still be in progress; we need
664 * to wait for this to finish.
665 */
666 wait_for_device_probe();
667 swsusp_resume_device = name_to_dev_t(resume_file);
668 pr_debug("PM: Resume from partition %s\n", resume_file);
669 } else {
670 pr_debug("PM: Resume from partition %d:%d\n",
671 MAJOR(swsusp_resume_device),
672 MINOR(swsusp_resume_device));
673 }
674
675 if (noresume) {
676 /**
677 * FIXME: If noresume is specified, we need to find the
678 * partition and reset it back to normal swap space.
679 */
680 mutex_unlock(&pm_mutex);
681 return 0;
682 }
683
684 pr_debug("PM: Checking hibernation image.\n");
685 error = swsusp_check();
686 if (error)
687 goto Unlock;
688
689 /* The snapshot device should not be opened while we're running */
690 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
691 error = -EBUSY;
692 goto Unlock;
693 }
694
695 pm_prepare_console();
696 error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
697 if (error)
698 goto Finish;
699
700 error = usermodehelper_disable();
701 if (error)
702 goto Finish;
703
704 error = create_basic_memory_bitmaps();
705 if (error)
706 goto Finish;
707
708 pr_debug("PM: Preparing processes for restore.\n");
709 error = prepare_processes();
710 if (error) {
711 swsusp_close(FMODE_READ);
712 goto Done;
713 }
714
715 pr_debug("PM: Reading hibernation image.\n");
716
717 error = swsusp_read(&flags);
718 if (!error)
719 hibernation_restore(flags & SF_PLATFORM_MODE);
720
721 printk(KERN_ERR "PM: Restore failed, recovering.\n");
722 swsusp_free();
723 thaw_processes();
724 Done:
725 free_basic_memory_bitmaps();
726 usermodehelper_enable();
727 Finish:
728 pm_notifier_call_chain(PM_POST_RESTORE);
729 pm_restore_console();
730 atomic_inc(&snapshot_device_available);
731 /* For success case, the suspend path will release the lock */
732 Unlock:
733 mutex_unlock(&pm_mutex);
734 pr_debug("PM: Resume from disk failed.\n");
735 return error;
736 }
737
738 late_initcall(software_resume);
739
740
741 static const char * const hibernation_modes[] = {
742 [HIBERNATION_PLATFORM] = "platform",
743 [HIBERNATION_SHUTDOWN] = "shutdown",
744 [HIBERNATION_REBOOT] = "reboot",
745 [HIBERNATION_TEST] = "test",
746 [HIBERNATION_TESTPROC] = "testproc",
747 };
748
749 /**
750 * disk - Control hibernation mode
751 *
752 * Suspend-to-disk can be handled in several ways. We have a few options
753 * for putting the system to sleep - using the platform driver (e.g. ACPI
754 * or other hibernation_ops), powering off the system or rebooting the
755 * system (for testing) as well as the two test modes.
756 *
757 * The system can support 'platform', and that is known a priori (and
758 * encoded by the presence of hibernation_ops). However, the user may
759 * choose 'shutdown' or 'reboot' as alternatives, as well as one fo the
760 * test modes, 'test' or 'testproc'.
761 *
762 * show() will display what the mode is currently set to.
763 * store() will accept one of
764 *
765 * 'platform'
766 * 'shutdown'
767 * 'reboot'
768 * 'test'
769 * 'testproc'
770 *
771 * It will only change to 'platform' if the system
772 * supports it (as determined by having hibernation_ops).
773 */
774
775 static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
776 char *buf)
777 {
778 int i;
779 char *start = buf;
780
781 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
782 if (!hibernation_modes[i])
783 continue;
784 switch (i) {
785 case HIBERNATION_SHUTDOWN:
786 case HIBERNATION_REBOOT:
787 case HIBERNATION_TEST:
788 case HIBERNATION_TESTPROC:
789 break;
790 case HIBERNATION_PLATFORM:
791 if (hibernation_ops)
792 break;
793 /* not a valid mode, continue with loop */
794 continue;
795 }
796 if (i == hibernation_mode)
797 buf += sprintf(buf, "[%s] ", hibernation_modes[i]);
798 else
799 buf += sprintf(buf, "%s ", hibernation_modes[i]);
800 }
801 buf += sprintf(buf, "\n");
802 return buf-start;
803 }
804
805
806 static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
807 const char *buf, size_t n)
808 {
809 int error = 0;
810 int i;
811 int len;
812 char *p;
813 int mode = HIBERNATION_INVALID;
814
815 p = memchr(buf, '\n', n);
816 len = p ? p - buf : n;
817
818 mutex_lock(&pm_mutex);
819 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
820 if (len == strlen(hibernation_modes[i])
821 && !strncmp(buf, hibernation_modes[i], len)) {
822 mode = i;
823 break;
824 }
825 }
826 if (mode != HIBERNATION_INVALID) {
827 switch (mode) {
828 case HIBERNATION_SHUTDOWN:
829 case HIBERNATION_REBOOT:
830 case HIBERNATION_TEST:
831 case HIBERNATION_TESTPROC:
832 hibernation_mode = mode;
833 break;
834 case HIBERNATION_PLATFORM:
835 if (hibernation_ops)
836 hibernation_mode = mode;
837 else
838 error = -EINVAL;
839 }
840 } else
841 error = -EINVAL;
842
843 if (!error)
844 pr_debug("PM: Hibernation mode set to '%s'\n",
845 hibernation_modes[mode]);
846 mutex_unlock(&pm_mutex);
847 return error ? error : n;
848 }
849
850 power_attr(disk);
851
852 static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
853 char *buf)
854 {
855 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
856 MINOR(swsusp_resume_device));
857 }
858
859 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
860 const char *buf, size_t n)
861 {
862 unsigned int maj, min;
863 dev_t res;
864 int ret = -EINVAL;
865
866 if (sscanf(buf, "%u:%u", &maj, &min) != 2)
867 goto out;
868
869 res = MKDEV(maj,min);
870 if (maj != MAJOR(res) || min != MINOR(res))
871 goto out;
872
873 mutex_lock(&pm_mutex);
874 swsusp_resume_device = res;
875 mutex_unlock(&pm_mutex);
876 printk(KERN_INFO "PM: Starting manual resume from disk\n");
877 noresume = 0;
878 software_resume();
879 ret = n;
880 out:
881 return ret;
882 }
883
884 power_attr(resume);
885
886 static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
887 char *buf)
888 {
889 return sprintf(buf, "%lu\n", image_size);
890 }
891
892 static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
893 const char *buf, size_t n)
894 {
895 unsigned long size;
896
897 if (sscanf(buf, "%lu", &size) == 1) {
898 image_size = size;
899 return n;
900 }
901
902 return -EINVAL;
903 }
904
905 power_attr(image_size);
906
907 static struct attribute * g[] = {
908 &disk_attr.attr,
909 &resume_attr.attr,
910 &image_size_attr.attr,
911 NULL,
912 };
913
914
915 static struct attribute_group attr_group = {
916 .attrs = g,
917 };
918
919
920 static int __init pm_disk_init(void)
921 {
922 return sysfs_create_group(power_kobj, &attr_group);
923 }
924
925 core_initcall(pm_disk_init);
926
927
928 static int __init resume_setup(char *str)
929 {
930 if (noresume)
931 return 1;
932
933 strncpy( resume_file, str, 255 );
934 return 1;
935 }
936
937 static int __init resume_offset_setup(char *str)
938 {
939 unsigned long long offset;
940
941 if (noresume)
942 return 1;
943
944 if (sscanf(str, "%llu", &offset) == 1)
945 swsusp_resume_block = offset;
946
947 return 1;
948 }
949
950 static int __init noresume_setup(char *str)
951 {
952 noresume = 1;
953 return 1;
954 }
955
956 __setup("noresume", noresume_setup);
957 __setup("resume_offset=", resume_offset_setup);
958 __setup("resume=", resume_setup);
This page took 0.05154 seconds and 5 git commands to generate.