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