On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / kernel / power / hibernate.c
blob5d0d1500d526502aea6b611756bbddb7509eca1f
1 /*
2 * kernel/power/hibernate.c - Hibernation (a.k.a suspend-to-disk) support.
4 * Copyright (c) 2003 Patrick Mochel
5 * Copyright (c) 2003 Open Source Development Lab
6 * Copyright (c) 2004 Pavel Machek <pavel@suse.cz>
7 * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc.
9 * This file is released under the GPLv2.
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 #include <scsi/scsi_scan.h>
26 #include <asm/suspend.h>
28 #include "power.h"
31 static int noresume = 0;
32 static char resume_file[256] = CONFIG_PM_STD_PARTITION;
33 dev_t swsusp_resume_device;
34 sector_t swsusp_resume_block;
35 int in_suspend __nosavedata = 0;
37 enum {
38 HIBERNATION_INVALID,
39 HIBERNATION_PLATFORM,
40 HIBERNATION_TEST,
41 HIBERNATION_TESTPROC,
42 HIBERNATION_SHUTDOWN,
43 HIBERNATION_REBOOT,
44 /* keep last */
45 __HIBERNATION_AFTER_LAST
47 #define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
48 #define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
50 static int hibernation_mode = HIBERNATION_SHUTDOWN;
52 static struct platform_hibernation_ops *hibernation_ops;
54 /**
55 * hibernation_set_ops - set the global hibernate operations
56 * @ops: the hibernation operations to use in subsequent hibernation transitions
59 void hibernation_set_ops(struct platform_hibernation_ops *ops)
61 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
62 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
63 && ops->restore_cleanup)) {
64 WARN_ON(1);
65 return;
67 mutex_lock(&pm_mutex);
68 hibernation_ops = ops;
69 if (ops)
70 hibernation_mode = HIBERNATION_PLATFORM;
71 else if (hibernation_mode == HIBERNATION_PLATFORM)
72 hibernation_mode = HIBERNATION_SHUTDOWN;
74 mutex_unlock(&pm_mutex);
77 static bool entering_platform_hibernation;
79 bool system_entering_hibernation(void)
81 return entering_platform_hibernation;
83 EXPORT_SYMBOL(system_entering_hibernation);
85 #ifdef CONFIG_PM_DEBUG
86 static void hibernation_debug_sleep(void)
88 printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
89 mdelay(5000);
92 static int hibernation_testmode(int mode)
94 if (hibernation_mode == mode) {
95 hibernation_debug_sleep();
96 return 1;
98 return 0;
101 static int hibernation_test(int level)
103 if (pm_test_level == level) {
104 hibernation_debug_sleep();
105 return 1;
107 return 0;
109 #else /* !CONFIG_PM_DEBUG */
110 static int hibernation_testmode(int mode) { return 0; }
111 static int hibernation_test(int level) { return 0; }
112 #endif /* !CONFIG_PM_DEBUG */
115 * platform_begin - tell the platform driver that we're starting
116 * hibernation
119 static int platform_begin(int platform_mode)
121 return (platform_mode && hibernation_ops) ?
122 hibernation_ops->begin() : 0;
126 * platform_end - tell the platform driver that we've entered the
127 * working state
130 static void platform_end(int platform_mode)
132 if (platform_mode && hibernation_ops)
133 hibernation_ops->end();
137 * platform_pre_snapshot - prepare the machine for hibernation using the
138 * platform driver if so configured and return an error code if it fails
141 static int platform_pre_snapshot(int platform_mode)
143 return (platform_mode && hibernation_ops) ?
144 hibernation_ops->pre_snapshot() : 0;
148 * platform_leave - prepare the machine for switching to the normal mode
149 * of operation using the platform driver (called with interrupts disabled)
152 static void platform_leave(int platform_mode)
154 if (platform_mode && hibernation_ops)
155 hibernation_ops->leave();
159 * platform_finish - switch the machine to the normal mode of operation
160 * using the platform driver (must be called after platform_prepare())
163 static void platform_finish(int platform_mode)
165 if (platform_mode && hibernation_ops)
166 hibernation_ops->finish();
170 * platform_pre_restore - prepare the platform for the restoration from a
171 * hibernation image. If the restore fails after this function has been
172 * called, platform_restore_cleanup() must be called.
175 static int platform_pre_restore(int platform_mode)
177 return (platform_mode && hibernation_ops) ?
178 hibernation_ops->pre_restore() : 0;
182 * platform_restore_cleanup - switch the platform to the normal mode of
183 * operation after a failing restore. If platform_pre_restore() has been
184 * called before the failing restore, this function must be called too,
185 * regardless of the result of platform_pre_restore().
188 static void platform_restore_cleanup(int platform_mode)
190 if (platform_mode && hibernation_ops)
191 hibernation_ops->restore_cleanup();
195 * platform_recover - recover the platform from a failure to suspend
196 * devices.
199 static void platform_recover(int platform_mode)
201 if (platform_mode && hibernation_ops && hibernation_ops->recover)
202 hibernation_ops->recover();
206 * swsusp_show_speed - print the time elapsed between two events represented by
207 * @start and @stop
209 * @nr_pages - number of pages processed between @start and @stop
210 * @msg - introductory message to print
213 void swsusp_show_speed(struct timeval *start, struct timeval *stop,
214 unsigned nr_pages, char *msg)
216 int centisecs = pm_time_elapsed(start, stop) / 10;
217 int k;
218 int kps;
220 if (centisecs == 0)
221 centisecs = 1; /* avoid div-by-zero */
222 k = nr_pages * (PAGE_SIZE / 1024);
223 kps = (k * 100) / centisecs;
224 printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
225 msg, k,
226 centisecs / 100, centisecs % 100,
227 kps / 1000, (kps % 1000) / 10);
231 * create_image - freeze devices that need to be frozen with interrupts
232 * off, create the hibernation image and thaw those devices. Control
233 * reappears in this routine after a restore.
236 static int create_image(int platform_mode)
238 int error;
240 error = arch_prepare_suspend();
241 if (error)
242 return error;
244 /* At this point, dpm_suspend_start() has been called, but *not*
245 * dpm_suspend_noirq(). We *must* call dpm_suspend_noirq() now.
246 * Otherwise, drivers for some devices (e.g. interrupt controllers)
247 * become desynchronized with the actual state of the hardware
248 * at resume time, and evil weirdness ensues.
250 error = dpm_suspend_noirq(PMSG_FREEZE);
251 if (error) {
252 printk(KERN_ERR "PM: Some devices failed to power down, "
253 "aborting hibernation\n");
254 return error;
257 error = platform_pre_snapshot(platform_mode);
258 if (error || hibernation_test(TEST_PLATFORM))
259 goto Platform_finish;
261 error = disable_nonboot_cpus();
262 if (error || hibernation_test(TEST_CPUS)
263 || hibernation_testmode(HIBERNATION_TEST))
264 goto Enable_cpus;
266 local_irq_disable();
268 error = sysdev_suspend(PMSG_FREEZE);
269 if (error) {
270 printk(KERN_ERR "PM: Some system devices failed to power down, "
271 "aborting hibernation\n");
272 goto Enable_irqs;
275 if (hibernation_test(TEST_CORE))
276 goto Power_up;
278 in_suspend = 1;
279 save_processor_state();
280 error = swsusp_arch_suspend();
281 if (error)
282 printk(KERN_ERR "PM: Error %d creating hibernation image\n",
283 error);
284 /* Restore control flow magically appears here */
285 restore_processor_state();
286 if (!in_suspend)
287 platform_leave(platform_mode);
289 Power_up:
290 sysdev_resume();
291 /* NOTE: dpm_resume_noirq() is just a resume() for devices
292 * that suspended with irqs off ... no overall powerup.
295 Enable_irqs:
296 local_irq_enable();
298 Enable_cpus:
299 enable_nonboot_cpus();
301 Platform_finish:
302 platform_finish(platform_mode);
304 dpm_resume_noirq(in_suspend ?
305 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
307 return error;
311 * hibernation_snapshot - quiesce devices and create the hibernation
312 * snapshot image.
313 * @platform_mode - if set, use the platform driver, if available, to
314 * prepare the platform firmware for the power transition.
316 * Must be called with pm_mutex held
319 int hibernation_snapshot(int platform_mode)
321 int error;
323 error = platform_begin(platform_mode);
324 if (error)
325 return error;
327 /* Preallocate image memory before shutting down devices. */
328 error = hibernate_preallocate_memory();
329 if (error)
330 goto Close;
332 suspend_console();
333 error = dpm_suspend_start(PMSG_FREEZE);
334 if (error)
335 goto Recover_platform;
337 if (hibernation_test(TEST_DEVICES))
338 goto Recover_platform;
340 error = create_image(platform_mode);
341 /* Control returns here after successful restore */
343 Resume_devices:
344 /* We may need to release the preallocated image pages here. */
345 if (error || !in_suspend)
346 swsusp_free();
348 dpm_resume_end(in_suspend ?
349 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
350 resume_console();
351 Close:
352 platform_end(platform_mode);
353 return error;
355 Recover_platform:
356 platform_recover(platform_mode);
357 goto Resume_devices;
361 * resume_target_kernel - prepare devices that need to be suspended with
362 * interrupts off, restore the contents of highmem that have not been
363 * restored yet from the image and run the low level code that will restore
364 * the remaining contents of memory and switch to the just restored target
365 * kernel.
368 static int resume_target_kernel(bool platform_mode)
370 int error;
372 error = dpm_suspend_noirq(PMSG_QUIESCE);
373 if (error) {
374 printk(KERN_ERR "PM: Some devices failed to power down, "
375 "aborting resume\n");
376 return error;
379 error = platform_pre_restore(platform_mode);
380 if (error)
381 goto Cleanup;
383 error = disable_nonboot_cpus();
384 if (error)
385 goto Enable_cpus;
387 local_irq_disable();
389 error = sysdev_suspend(PMSG_QUIESCE);
390 if (error)
391 goto Enable_irqs;
393 /* We'll ignore saved state, but this gets preempt count (etc) right */
394 save_processor_state();
395 error = restore_highmem();
396 if (!error) {
397 error = swsusp_arch_resume();
399 * The code below is only ever reached in case of a failure.
400 * Otherwise execution continues at place where
401 * swsusp_arch_suspend() was called
403 BUG_ON(!error);
404 /* This call to restore_highmem() undos the previous one */
405 restore_highmem();
408 * The only reason why swsusp_arch_resume() can fail is memory being
409 * very tight, so we have to free it as soon as we can to avoid
410 * subsequent failures
412 swsusp_free();
413 restore_processor_state();
414 touch_softlockup_watchdog();
416 sysdev_resume();
418 Enable_irqs:
419 local_irq_enable();
421 Enable_cpus:
422 enable_nonboot_cpus();
424 Cleanup:
425 platform_restore_cleanup(platform_mode);
427 dpm_resume_noirq(PMSG_RECOVER);
429 return error;
433 * hibernation_restore - quiesce devices and restore the hibernation
434 * snapshot image. If successful, control returns in hibernation_snaphot()
435 * @platform_mode - if set, use the platform driver, if available, to
436 * prepare the platform firmware for the transition.
438 * Must be called with pm_mutex held
441 int hibernation_restore(int platform_mode)
443 int error;
445 pm_prepare_console();
446 suspend_console();
447 error = dpm_suspend_start(PMSG_QUIESCE);
448 if (!error) {
449 error = resume_target_kernel(platform_mode);
450 dpm_resume_end(PMSG_RECOVER);
452 resume_console();
453 pm_restore_console();
454 return error;
458 * hibernation_platform_enter - enter the hibernation state using the
459 * platform driver (if available)
462 int hibernation_platform_enter(void)
464 int error;
466 if (!hibernation_ops)
467 return -ENOSYS;
470 * We have cancelled the power transition by running
471 * hibernation_ops->finish() before saving the image, so we should let
472 * the firmware know that we're going to enter the sleep state after all
474 error = hibernation_ops->begin();
475 if (error)
476 goto Close;
478 entering_platform_hibernation = true;
479 suspend_console();
480 error = dpm_suspend_start(PMSG_HIBERNATE);
481 if (error) {
482 if (hibernation_ops->recover)
483 hibernation_ops->recover();
484 goto Resume_devices;
487 error = dpm_suspend_noirq(PMSG_HIBERNATE);
488 if (error)
489 goto Resume_devices;
491 error = hibernation_ops->prepare();
492 if (error)
493 goto Platform_finish;
495 error = disable_nonboot_cpus();
496 if (error)
497 goto Platform_finish;
499 local_irq_disable();
500 sysdev_suspend(PMSG_HIBERNATE);
501 hibernation_ops->enter();
502 /* We should never get here */
503 while (1);
506 * We don't need to reenable the nonboot CPUs or resume consoles, since
507 * the system is going to be halted anyway.
509 Platform_finish:
510 hibernation_ops->finish();
512 dpm_suspend_noirq(PMSG_RESTORE);
514 Resume_devices:
515 entering_platform_hibernation = false;
516 dpm_resume_end(PMSG_RESTORE);
517 resume_console();
519 Close:
520 hibernation_ops->end();
522 return error;
526 * power_down - Shut the machine down for hibernation.
528 * Use the platform driver, if configured so; otherwise try
529 * to power off or reboot.
532 static void power_down(void)
534 switch (hibernation_mode) {
535 case HIBERNATION_TEST:
536 case HIBERNATION_TESTPROC:
537 break;
538 case HIBERNATION_REBOOT:
539 kernel_restart(NULL);
540 break;
541 case HIBERNATION_PLATFORM:
542 hibernation_platform_enter();
543 case HIBERNATION_SHUTDOWN:
544 kernel_power_off();
545 break;
547 kernel_halt();
549 * Valid image is on the disk, if we continue we risk serious data
550 * corruption after resume.
552 printk(KERN_CRIT "PM: Please power down manually\n");
553 while(1);
556 static int prepare_processes(void)
558 int error = 0;
560 if (freeze_processes()) {
561 error = -EBUSY;
562 thaw_processes();
564 return error;
568 * hibernate - The granpappy of the built-in hibernation management
571 int hibernate(void)
573 int error;
575 mutex_lock(&pm_mutex);
576 /* The snapshot device should not be opened while we're running */
577 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
578 error = -EBUSY;
579 goto Unlock;
582 pm_prepare_console();
583 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
584 if (error)
585 goto Exit;
587 error = usermodehelper_disable();
588 if (error)
589 goto Exit;
591 /* Allocate memory management structures */
592 error = create_basic_memory_bitmaps();
593 if (error)
594 goto Exit;
596 printk(KERN_INFO "PM: Syncing filesystems ... ");
597 sys_sync();
598 printk("done.\n");
600 error = prepare_processes();
601 if (error)
602 goto Finish;
604 if (hibernation_test(TEST_FREEZER))
605 goto Thaw;
607 if (hibernation_testmode(HIBERNATION_TESTPROC))
608 goto Thaw;
610 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
611 if (error)
612 goto Thaw;
614 if (in_suspend) {
615 unsigned int flags = 0;
617 if (hibernation_mode == HIBERNATION_PLATFORM)
618 flags |= SF_PLATFORM_MODE;
619 pr_debug("PM: writing image.\n");
620 error = swsusp_write(flags);
621 swsusp_free();
622 if (!error)
623 power_down();
624 } else {
625 pr_debug("PM: Image restored successfully.\n");
628 Thaw:
629 thaw_processes();
630 Finish:
631 free_basic_memory_bitmaps();
632 usermodehelper_enable();
633 Exit:
634 pm_notifier_call_chain(PM_POST_HIBERNATION);
635 pm_restore_console();
636 atomic_inc(&snapshot_device_available);
637 Unlock:
638 mutex_unlock(&pm_mutex);
639 return error;
644 * software_resume - Resume from a saved image.
646 * Called as a late_initcall (so all devices are discovered and
647 * initialized), we call swsusp to see if we have a saved image or not.
648 * If so, we quiesce devices, the restore the saved image. We will
649 * return above (in hibernate() ) if everything goes well.
650 * Otherwise, we fail gracefully and return to the normally
651 * scheduled program.
655 static int software_resume(void)
657 int error;
658 unsigned int flags;
661 * If the user said "noresume".. bail out early.
663 if (noresume)
664 return 0;
667 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
668 * is configured into the kernel. Since the regular hibernate
669 * trigger path is via sysfs which takes a buffer mutex before
670 * calling hibernate functions (which take pm_mutex) this can
671 * cause lockdep to complain about a possible ABBA deadlock
672 * which cannot happen since we're in the boot code here and
673 * sysfs can't be invoked yet. Therefore, we use a subclass
674 * here to avoid lockdep complaining.
676 mutex_lock_nested(&pm_mutex, SINGLE_DEPTH_NESTING);
678 if (swsusp_resume_device)
679 goto Check_image;
681 if (!strlen(resume_file)) {
682 error = -ENOENT;
683 goto Unlock;
686 pr_debug("PM: Checking image partition %s\n", resume_file);
688 /* Check if the device is there */
689 swsusp_resume_device = name_to_dev_t(resume_file);
690 if (!swsusp_resume_device) {
692 * Some device discovery might still be in progress; we need
693 * to wait for this to finish.
695 wait_for_device_probe();
697 * We can't depend on SCSI devices being available after loading
698 * one of their modules until scsi_complete_async_scans() is
699 * called and the resume device usually is a SCSI one.
701 scsi_complete_async_scans();
703 swsusp_resume_device = name_to_dev_t(resume_file);
704 if (!swsusp_resume_device) {
705 error = -ENODEV;
706 goto Unlock;
710 Check_image:
711 pr_debug("PM: Resume from partition %d:%d\n",
712 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
714 pr_debug("PM: Checking hibernation image.\n");
715 error = swsusp_check();
716 if (error)
717 goto Unlock;
719 /* The snapshot device should not be opened while we're running */
720 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
721 error = -EBUSY;
722 swsusp_close(FMODE_READ);
723 goto Unlock;
726 pm_prepare_console();
727 error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
728 if (error)
729 goto close_finish;
731 error = usermodehelper_disable();
732 if (error)
733 goto close_finish;
735 error = create_basic_memory_bitmaps();
736 if (error)
737 goto close_finish;
739 pr_debug("PM: Preparing processes for restore.\n");
740 error = prepare_processes();
741 if (error) {
742 swsusp_close(FMODE_READ);
743 goto Done;
746 pr_debug("PM: Reading hibernation image.\n");
748 error = swsusp_read(&flags);
749 swsusp_close(FMODE_READ);
750 if (!error)
751 hibernation_restore(flags & SF_PLATFORM_MODE);
753 printk(KERN_ERR "PM: Restore failed, recovering.\n");
754 swsusp_free();
755 thaw_processes();
756 Done:
757 free_basic_memory_bitmaps();
758 usermodehelper_enable();
759 Finish:
760 pm_notifier_call_chain(PM_POST_RESTORE);
761 pm_restore_console();
762 atomic_inc(&snapshot_device_available);
763 /* For success case, the suspend path will release the lock */
764 Unlock:
765 mutex_unlock(&pm_mutex);
766 pr_debug("PM: Resume from disk failed.\n");
767 return error;
768 close_finish:
769 swsusp_close(FMODE_READ);
770 goto Finish;
773 late_initcall(software_resume);
776 static const char * const hibernation_modes[] = {
777 [HIBERNATION_PLATFORM] = "platform",
778 [HIBERNATION_SHUTDOWN] = "shutdown",
779 [HIBERNATION_REBOOT] = "reboot",
780 [HIBERNATION_TEST] = "test",
781 [HIBERNATION_TESTPROC] = "testproc",
785 * disk - Control hibernation mode
787 * Suspend-to-disk can be handled in several ways. We have a few options
788 * for putting the system to sleep - using the platform driver (e.g. ACPI
789 * or other hibernation_ops), powering off the system or rebooting the
790 * system (for testing) as well as the two test modes.
792 * The system can support 'platform', and that is known a priori (and
793 * encoded by the presence of hibernation_ops). However, the user may
794 * choose 'shutdown' or 'reboot' as alternatives, as well as one fo the
795 * test modes, 'test' or 'testproc'.
797 * show() will display what the mode is currently set to.
798 * store() will accept one of
800 * 'platform'
801 * 'shutdown'
802 * 'reboot'
803 * 'test'
804 * 'testproc'
806 * It will only change to 'platform' if the system
807 * supports it (as determined by having hibernation_ops).
810 static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
811 char *buf)
813 int i;
814 char *start = buf;
816 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
817 if (!hibernation_modes[i])
818 continue;
819 switch (i) {
820 case HIBERNATION_SHUTDOWN:
821 case HIBERNATION_REBOOT:
822 case HIBERNATION_TEST:
823 case HIBERNATION_TESTPROC:
824 break;
825 case HIBERNATION_PLATFORM:
826 if (hibernation_ops)
827 break;
828 /* not a valid mode, continue with loop */
829 continue;
831 if (i == hibernation_mode)
832 buf += sprintf(buf, "[%s] ", hibernation_modes[i]);
833 else
834 buf += sprintf(buf, "%s ", hibernation_modes[i]);
836 buf += sprintf(buf, "\n");
837 return buf-start;
841 static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
842 const char *buf, size_t n)
844 int error = 0;
845 int i;
846 int len;
847 char *p;
848 int mode = HIBERNATION_INVALID;
850 p = memchr(buf, '\n', n);
851 len = p ? p - buf : n;
853 mutex_lock(&pm_mutex);
854 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
855 if (len == strlen(hibernation_modes[i])
856 && !strncmp(buf, hibernation_modes[i], len)) {
857 mode = i;
858 break;
861 if (mode != HIBERNATION_INVALID) {
862 switch (mode) {
863 case HIBERNATION_SHUTDOWN:
864 case HIBERNATION_REBOOT:
865 case HIBERNATION_TEST:
866 case HIBERNATION_TESTPROC:
867 hibernation_mode = mode;
868 break;
869 case HIBERNATION_PLATFORM:
870 if (hibernation_ops)
871 hibernation_mode = mode;
872 else
873 error = -EINVAL;
875 } else
876 error = -EINVAL;
878 if (!error)
879 pr_debug("PM: Hibernation mode set to '%s'\n",
880 hibernation_modes[mode]);
881 mutex_unlock(&pm_mutex);
882 return error ? error : n;
885 power_attr(disk);
887 static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
888 char *buf)
890 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
891 MINOR(swsusp_resume_device));
894 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
895 const char *buf, size_t n)
897 unsigned int maj, min;
898 dev_t res;
899 int ret = -EINVAL;
901 if (sscanf(buf, "%u:%u", &maj, &min) != 2)
902 goto out;
904 res = MKDEV(maj,min);
905 if (maj != MAJOR(res) || min != MINOR(res))
906 goto out;
908 mutex_lock(&pm_mutex);
909 swsusp_resume_device = res;
910 mutex_unlock(&pm_mutex);
911 printk(KERN_INFO "PM: Starting manual resume from disk\n");
912 noresume = 0;
913 software_resume();
914 ret = n;
915 out:
916 return ret;
919 power_attr(resume);
921 static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
922 char *buf)
924 return sprintf(buf, "%lu\n", image_size);
927 static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
928 const char *buf, size_t n)
930 unsigned long size;
932 if (sscanf(buf, "%lu", &size) == 1) {
933 image_size = size;
934 return n;
937 return -EINVAL;
940 power_attr(image_size);
942 static struct attribute * g[] = {
943 &disk_attr.attr,
944 &resume_attr.attr,
945 &image_size_attr.attr,
946 NULL,
950 static struct attribute_group attr_group = {
951 .attrs = g,
955 static int __init pm_disk_init(void)
957 return sysfs_create_group(power_kobj, &attr_group);
960 core_initcall(pm_disk_init);
963 static int __init resume_setup(char *str)
965 if (noresume)
966 return 1;
968 strncpy( resume_file, str, 255 );
969 return 1;
972 static int __init resume_offset_setup(char *str)
974 unsigned long long offset;
976 if (noresume)
977 return 1;
979 if (sscanf(str, "%llu", &offset) == 1)
980 swsusp_resume_block = offset;
982 return 1;
985 static int __init noresume_setup(char *str)
987 noresume = 1;
988 return 1;
991 __setup("noresume", noresume_setup);
992 __setup("resume_offset=", resume_offset_setup);
993 __setup("resume=", resume_setup);