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