1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/export.h>
14#include <linux/suspend.h>
15#include <linux/syscalls.h>
16#include <linux/reboot.h>
17#include <linux/string.h>
18#include <linux/device.h>
19#include <linux/async.h>
20#include <linux/delay.h>
21#include <linux/fs.h>
22#include <linux/mount.h>
23#include <linux/pm.h>
24#include <linux/console.h>
25#include <linux/cpu.h>
26#include <linux/freezer.h>
27#include <linux/gfp.h>
28#include <linux/syscore_ops.h>
29#include <linux/ctype.h>
30#include <linux/genhd.h>
31#include <linux/security.h>
32
33#include "power.h"
34
35
36static int nocompress;
37static int noresume;
38static int nohibernate;
39static int resume_wait;
40static int resume_delay;
41static char resume_file[256] = CONFIG_PM_STD_PARTITION;
42dev_t swsusp_resume_device;
43sector_t swsusp_resume_block;
44int in_suspend __nosavedata;
45
46enum {
47 HIBERNATION_INVALID,
48 HIBERNATION_PLATFORM,
49 HIBERNATION_SHUTDOWN,
50 HIBERNATION_REBOOT,
51#ifdef CONFIG_SUSPEND
52 HIBERNATION_SUSPEND,
53#endif
54
55 __HIBERNATION_AFTER_LAST
56};
57#define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
58#define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
59
60static int hibernation_mode = HIBERNATION_SHUTDOWN;
61
62bool freezer_test_done;
63
64static const struct platform_hibernation_ops *hibernation_ops;
65
66bool hibernation_available(void)
67{
68 return (nohibernate == 0);
69}
70
71
72
73
74
75void hibernation_set_ops(const struct platform_hibernation_ops *ops)
76{
77 if (ops && !(ops->begin && ops->end && ops->pre_snapshot
78 && ops->prepare && ops->finish && ops->enter && ops->pre_restore
79 && ops->restore_cleanup && ops->leave)) {
80 WARN_ON(1);
81 return;
82 }
83 lock_system_sleep();
84 hibernation_ops = ops;
85 if (ops)
86 hibernation_mode = HIBERNATION_PLATFORM;
87 else if (hibernation_mode == HIBERNATION_PLATFORM)
88 hibernation_mode = HIBERNATION_SHUTDOWN;
89
90 unlock_system_sleep();
91}
92
93static bool entering_platform_hibernation;
94
95bool system_entering_hibernation(void)
96{
97 return entering_platform_hibernation;
98}
99EXPORT_SYMBOL(system_entering_hibernation);
100
101#ifdef CONFIG_PM_DEBUG
102static void hibernation_debug_sleep(void)
103{
104 printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
105 mdelay(5000);
106}
107
108static int hibernation_test(int level)
109{
110 if (pm_test_level == level) {
111 hibernation_debug_sleep();
112 return 1;
113 }
114 return 0;
115}
116#else
117static int hibernation_test(int level) { return 0; }
118#endif
119
120
121
122
123
124static int platform_begin(int platform_mode)
125{
126 return (platform_mode && hibernation_ops) ?
127 hibernation_ops->begin() : 0;
128}
129
130
131
132
133
134static void platform_end(int platform_mode)
135{
136 if (platform_mode && hibernation_ops)
137 hibernation_ops->end();
138}
139
140
141
142
143
144
145
146
147
148static int platform_pre_snapshot(int platform_mode)
149{
150 return (platform_mode && hibernation_ops) ?
151 hibernation_ops->pre_snapshot() : 0;
152}
153
154
155
156
157
158
159
160
161
162
163static void platform_leave(int platform_mode)
164{
165 if (platform_mode && hibernation_ops)
166 hibernation_ops->leave();
167}
168
169
170
171
172
173
174
175
176
177
178static void platform_finish(int platform_mode)
179{
180 if (platform_mode && hibernation_ops)
181 hibernation_ops->finish();
182}
183
184
185
186
187
188
189
190
191
192
193
194static int platform_pre_restore(int platform_mode)
195{
196 return (platform_mode && hibernation_ops) ?
197 hibernation_ops->pre_restore() : 0;
198}
199
200
201
202
203
204
205
206
207
208
209
210
211static void platform_restore_cleanup(int platform_mode)
212{
213 if (platform_mode && hibernation_ops)
214 hibernation_ops->restore_cleanup();
215}
216
217
218
219
220
221static void platform_recover(int platform_mode)
222{
223 if (platform_mode && hibernation_ops && hibernation_ops->recover)
224 hibernation_ops->recover();
225}
226
227
228
229
230
231
232
233
234void swsusp_show_speed(struct timeval *start, struct timeval *stop,
235 unsigned nr_pages, char *msg)
236{
237 s64 elapsed_centisecs64;
238 int centisecs;
239 int k;
240 int kps;
241
242 elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
243 do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
244 centisecs = elapsed_centisecs64;
245 if (centisecs == 0)
246 centisecs = 1;
247 k = nr_pages * (PAGE_SIZE / 1024);
248 kps = (k * 100) / centisecs;
249 printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
250 msg, k,
251 centisecs / 100, centisecs % 100,
252 kps / 1000, (kps % 1000) / 10);
253}
254
255
256
257
258
259
260
261
262
263
264static int create_image(int platform_mode)
265{
266 int error;
267
268 error = dpm_suspend_end(PMSG_FREEZE);
269 if (error) {
270 printk(KERN_ERR "PM: Some devices failed to power down, "
271 "aborting hibernation\n");
272 return error;
273 }
274
275 error = platform_pre_snapshot(platform_mode);
276 if (error || hibernation_test(TEST_PLATFORM))
277 goto Platform_finish;
278
279 error = disable_nonboot_cpus();
280 if (error || hibernation_test(TEST_CPUS))
281 goto Enable_cpus;
282
283 local_irq_disable();
284
285 error = syscore_suspend();
286 if (error) {
287 printk(KERN_ERR "PM: Some system devices failed to power down, "
288 "aborting hibernation\n");
289 goto Enable_irqs;
290 }
291
292 if (hibernation_test(TEST_CORE) || pm_wakeup_pending())
293 goto Power_up;
294
295 in_suspend = 1;
296 save_processor_state();
297 error = swsusp_arch_suspend();
298
299 restore_processor_state();
300 if (error)
301 printk(KERN_ERR "PM: Error %d creating hibernation image\n",
302 error);
303 if (!in_suspend) {
304 events_check_enabled = false;
305 platform_leave(platform_mode);
306 }
307
308 Power_up:
309 syscore_resume();
310
311 Enable_irqs:
312 local_irq_enable();
313
314 Enable_cpus:
315 enable_nonboot_cpus();
316
317 Platform_finish:
318 platform_finish(platform_mode);
319
320 dpm_resume_start(in_suspend ?
321 (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE);
322
323 return error;
324}
325
326
327
328
329
330
331
332int hibernation_snapshot(int platform_mode)
333{
334 pm_message_t msg;
335 int error;
336
337 error = platform_begin(platform_mode);
338 if (error)
339 goto Close;
340
341
342 error = hibernate_preallocate_memory();
343 if (error)
344 goto Close;
345
346 error = freeze_kernel_threads();
347 if (error)
348 goto Cleanup;
349
350 if (hibernation_test(TEST_FREEZER)) {
351
352
353
354
355
356 freezer_test_done = true;
357 goto Thaw;
358 }
359
360 error = dpm_prepare(PMSG_FREEZE);
361 if (error) {
362 dpm_complete(PMSG_RECOVER);
363 goto Thaw;
364 }
365
366 suspend_console();
367 pm_restrict_gfp_mask();
368
369 error = dpm_suspend(PMSG_FREEZE);
370
371 if (error || hibernation_test(TEST_DEVICES))
372 platform_recover(platform_mode);
373 else
374 error = create_image(platform_mode);
375
376
377
378
379
380
381
382
383 if (error || !in_suspend)
384 swsusp_free();
385
386 msg = in_suspend ? (error ? PMSG_RECOVER : PMSG_THAW) : PMSG_RESTORE;
387 dpm_resume(msg);
388
389 if (error || !in_suspend)
390 pm_restore_gfp_mask();
391
392 resume_console();
393 dpm_complete(msg);
394
395 Close:
396 platform_end(platform_mode);
397 return error;
398
399 Thaw:
400 thaw_kernel_threads();
401 Cleanup:
402 swsusp_free();
403 goto Close;
404}
405
406int __weak hibernate_resume_nonboot_cpu_disable(void)
407{
408 return disable_nonboot_cpus();
409}
410
411
412
413
414
415
416
417
418
419
420static int resume_target_kernel(bool platform_mode)
421{
422 int error;
423
424 error = dpm_suspend_end(PMSG_QUIESCE);
425 if (error) {
426 printk(KERN_ERR "PM: Some devices failed to power down, "
427 "aborting resume\n");
428 return error;
429 }
430
431 error = platform_pre_restore(platform_mode);
432 if (error)
433 goto Cleanup;
434
435 error = hibernate_resume_nonboot_cpu_disable();
436 if (error)
437 goto Enable_cpus;
438
439 local_irq_disable();
440
441 error = syscore_suspend();
442 if (error)
443 goto Enable_irqs;
444
445 save_processor_state();
446 error = restore_highmem();
447 if (!error) {
448 error = swsusp_arch_resume();
449
450
451
452
453
454 BUG_ON(!error);
455
456
457
458
459 restore_highmem();
460 }
461
462
463
464
465
466 swsusp_free();
467 restore_processor_state();
468 touch_softlockup_watchdog();
469
470 syscore_resume();
471
472 Enable_irqs:
473 local_irq_enable();
474
475 Enable_cpus:
476 enable_nonboot_cpus();
477
478 Cleanup:
479 platform_restore_cleanup(platform_mode);
480
481 dpm_resume_start(PMSG_RECOVER);
482
483 return error;
484}
485
486
487
488
489
490
491
492
493int hibernation_restore(int platform_mode)
494{
495 int error;
496
497 pm_prepare_console();
498 suspend_console();
499 pm_restrict_gfp_mask();
500 error = dpm_suspend_start(PMSG_QUIESCE);
501 if (!error) {
502 error = resume_target_kernel(platform_mode);
503 dpm_resume_end(PMSG_RECOVER);
504 }
505 pm_restore_gfp_mask();
506 resume_console();
507 pm_restore_console();
508 return error;
509}
510
511
512
513
514int hibernation_platform_enter(void)
515{
516 int error;
517
518 if (!hibernation_ops)
519 return -ENOSYS;
520
521
522
523
524
525
526 error = hibernation_ops->begin();
527 if (error)
528 goto Close;
529
530 entering_platform_hibernation = true;
531 suspend_console();
532 error = dpm_suspend_start(PMSG_HIBERNATE);
533 if (error) {
534 if (hibernation_ops->recover)
535 hibernation_ops->recover();
536 goto Resume_devices;
537 }
538
539 error = dpm_suspend_end(PMSG_HIBERNATE);
540 if (error)
541 goto Resume_devices;
542
543 error = hibernation_ops->prepare();
544 if (error)
545 goto Platform_finish;
546
547 error = disable_nonboot_cpus();
548 if (error)
549 goto Platform_finish;
550
551 local_irq_disable();
552 syscore_suspend();
553 if (pm_wakeup_pending()) {
554 error = -EAGAIN;
555 goto Power_up;
556 }
557
558 hibernation_ops->enter();
559
560 while (1);
561
562 Power_up:
563 syscore_resume();
564 local_irq_enable();
565 enable_nonboot_cpus();
566
567 Platform_finish:
568 hibernation_ops->finish();
569
570 dpm_resume_start(PMSG_RESTORE);
571
572 Resume_devices:
573 entering_platform_hibernation = false;
574 dpm_resume_end(PMSG_RESTORE);
575 resume_console();
576
577 Close:
578 hibernation_ops->end();
579
580 return error;
581}
582
583
584
585
586
587
588
589
590static void power_down(void)
591{
592#ifdef CONFIG_SUSPEND
593 int error;
594#endif
595
596 switch (hibernation_mode) {
597 case HIBERNATION_REBOOT:
598 kernel_restart(NULL);
599 break;
600 case HIBERNATION_PLATFORM:
601 hibernation_platform_enter();
602 case HIBERNATION_SHUTDOWN:
603 kernel_power_off();
604 break;
605#ifdef CONFIG_SUSPEND
606 case HIBERNATION_SUSPEND:
607 error = suspend_devices_and_enter(PM_SUSPEND_MEM);
608 if (error) {
609 if (hibernation_ops)
610 hibernation_mode = HIBERNATION_PLATFORM;
611 else
612 hibernation_mode = HIBERNATION_SHUTDOWN;
613 power_down();
614 }
615
616
617
618 error = swsusp_unmark();
619 if (error)
620 printk(KERN_ERR "PM: Swap will be unusable! "
621 "Try swapon -a.\n");
622 return;
623#endif
624 }
625 kernel_halt();
626
627
628
629
630 printk(KERN_CRIT "PM: Please power down manually\n");
631 while(1);
632}
633
634
635
636
637int hibernate(void)
638{
639 int error;
640
641 if (get_securelevel() > 0) {
642 return -EPERM;
643 }
644
645 if (!hibernation_available()) {
646 pr_debug("PM: Hibernation not available.\n");
647 return -EPERM;
648 }
649
650 lock_system_sleep();
651
652 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
653 error = -EBUSY;
654 goto Unlock;
655 }
656
657 pm_prepare_console();
658 error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE);
659 if (error)
660 goto Exit;
661
662 printk(KERN_INFO "PM: Syncing filesystems ... ");
663 sys_sync();
664 printk("done.\n");
665
666 error = freeze_processes();
667 if (error)
668 goto Exit;
669
670 lock_device_hotplug();
671
672 error = create_basic_memory_bitmaps();
673 if (error)
674 goto Thaw;
675
676 error = hibernation_snapshot(hibernation_mode == HIBERNATION_PLATFORM);
677 if (error || freezer_test_done)
678 goto Free_bitmaps;
679
680 if (in_suspend) {
681 unsigned int flags = 0;
682
683 if (hibernation_mode == HIBERNATION_PLATFORM)
684 flags |= SF_PLATFORM_MODE;
685 if (nocompress)
686 flags |= SF_NOCOMPRESS_MODE;
687 else
688 flags |= SF_CRC32_MODE;
689
690 pr_debug("PM: writing image.\n");
691 error = swsusp_write(flags);
692 swsusp_free();
693 if (!error)
694 power_down();
695 in_suspend = 0;
696 pm_restore_gfp_mask();
697 } else {
698 pr_debug("PM: Image restored successfully.\n");
699 }
700
701 Free_bitmaps:
702 free_basic_memory_bitmaps();
703 Thaw:
704 unlock_device_hotplug();
705 thaw_processes();
706
707
708 freezer_test_done = false;
709 Exit:
710 pm_notifier_call_chain(PM_POST_HIBERNATION);
711 pm_restore_console();
712 atomic_inc(&snapshot_device_available);
713 Unlock:
714 unlock_system_sleep();
715 return error;
716}
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734static int software_resume(void)
735{
736 int error;
737 unsigned int flags;
738
739
740
741
742 if (noresume || (get_securelevel() > 0) || !hibernation_available())
743 return 0;
744
745
746
747
748
749
750
751
752
753
754
755 mutex_lock_nested(&pm_mutex, SINGLE_DEPTH_NESTING);
756
757 if (swsusp_resume_device)
758 goto Check_image;
759
760 if (!strlen(resume_file)) {
761 error = -ENOENT;
762 goto Unlock;
763 }
764
765 pr_debug("PM: Checking hibernation image partition %s\n", resume_file);
766
767 if (resume_delay) {
768 printk(KERN_INFO "Waiting %dsec before reading resume device...\n",
769 resume_delay);
770 ssleep(resume_delay);
771 }
772
773
774 swsusp_resume_device = name_to_dev_t(resume_file);
775
776
777
778
779
780 if (isdigit(resume_file[0]) && resume_wait) {
781 int partno;
782 while (!get_gendisk(swsusp_resume_device, &partno))
783 msleep(10);
784 }
785
786 if (!swsusp_resume_device) {
787
788
789
790
791 wait_for_device_probe();
792
793 if (resume_wait) {
794 while ((swsusp_resume_device = name_to_dev_t(resume_file)) == 0)
795 msleep(10);
796 async_synchronize_full();
797 }
798
799 swsusp_resume_device = name_to_dev_t(resume_file);
800 if (!swsusp_resume_device) {
801 error = -ENODEV;
802 goto Unlock;
803 }
804 }
805
806 Check_image:
807 pr_debug("PM: Hibernation image partition %d:%d present\n",
808 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
809
810 pr_debug("PM: Looking for hibernation image.\n");
811 error = swsusp_check();
812 if (error)
813 goto Unlock;
814
815
816 if (!atomic_add_unless(&snapshot_device_available, -1, 0)) {
817 error = -EBUSY;
818 swsusp_close(FMODE_READ);
819 goto Unlock;
820 }
821
822 pm_prepare_console();
823 error = pm_notifier_call_chain(PM_RESTORE_PREPARE);
824 if (error)
825 goto Close_Finish;
826
827 pr_debug("PM: Preparing processes for restore.\n");
828 error = freeze_processes();
829 if (error)
830 goto Close_Finish;
831
832 pr_debug("PM: Loading hibernation image.\n");
833
834 lock_device_hotplug();
835 error = create_basic_memory_bitmaps();
836 if (error)
837 goto Thaw;
838
839 error = swsusp_read(&flags);
840 swsusp_close(FMODE_READ);
841 if (!error)
842 hibernation_restore(flags & SF_PLATFORM_MODE);
843
844 printk(KERN_ERR "PM: Failed to load hibernation image, recovering.\n");
845 swsusp_free();
846 free_basic_memory_bitmaps();
847 Thaw:
848 unlock_device_hotplug();
849 thaw_processes();
850 Finish:
851 pm_notifier_call_chain(PM_POST_RESTORE);
852 pm_restore_console();
853 atomic_inc(&snapshot_device_available);
854
855 Unlock:
856 mutex_unlock(&pm_mutex);
857 pr_debug("PM: Hibernation image not present or could not be loaded.\n");
858 return error;
859 Close_Finish:
860 swsusp_close(FMODE_READ);
861 goto Finish;
862}
863
864late_initcall(software_resume);
865
866
867static const char * const hibernation_modes[] = {
868 [HIBERNATION_PLATFORM] = "platform",
869 [HIBERNATION_SHUTDOWN] = "shutdown",
870 [HIBERNATION_REBOOT] = "reboot",
871#ifdef CONFIG_SUSPEND
872 [HIBERNATION_SUSPEND] = "suspend",
873#endif
874};
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
903 char *buf)
904{
905 int i;
906 char *start = buf;
907
908 if (get_securelevel() > 0) {
909 buf += sprintf(buf, "[%s]\n", "disabled");
910 return buf-start;
911 }
912
913 if (!hibernation_available())
914 return sprintf(buf, "[disabled]\n");
915
916 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
917 if (!hibernation_modes[i])
918 continue;
919 switch (i) {
920 case HIBERNATION_SHUTDOWN:
921 case HIBERNATION_REBOOT:
922#ifdef CONFIG_SUSPEND
923 case HIBERNATION_SUSPEND:
924#endif
925 break;
926 case HIBERNATION_PLATFORM:
927 if (hibernation_ops)
928 break;
929
930 continue;
931 }
932 if (i == hibernation_mode)
933 buf += sprintf(buf, "[%s] ", hibernation_modes[i]);
934 else
935 buf += sprintf(buf, "%s ", hibernation_modes[i]);
936 }
937 buf += sprintf(buf, "\n");
938 return buf-start;
939}
940
941static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
942 const char *buf, size_t n)
943{
944 int error = 0;
945 int i;
946 int len;
947 char *p;
948 int mode = HIBERNATION_INVALID;
949
950 if (get_securelevel() > 0)
951 return -EPERM;
952
953 if (!hibernation_available())
954 return -EPERM;
955
956 p = memchr(buf, '\n', n);
957 len = p ? p - buf : n;
958
959 lock_system_sleep();
960 for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
961 if (len == strlen(hibernation_modes[i])
962 && !strncmp(buf, hibernation_modes[i], len)) {
963 mode = i;
964 break;
965 }
966 }
967 if (mode != HIBERNATION_INVALID) {
968 switch (mode) {
969 case HIBERNATION_SHUTDOWN:
970 case HIBERNATION_REBOOT:
971#ifdef CONFIG_SUSPEND
972 case HIBERNATION_SUSPEND:
973#endif
974 hibernation_mode = mode;
975 break;
976 case HIBERNATION_PLATFORM:
977 if (hibernation_ops)
978 hibernation_mode = mode;
979 else
980 error = -EINVAL;
981 }
982 } else
983 error = -EINVAL;
984
985 if (!error)
986 pr_debug("PM: Hibernation mode set to '%s'\n",
987 hibernation_modes[mode]);
988 unlock_system_sleep();
989 return error ? error : n;
990}
991
992power_attr(disk);
993
994static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
995 char *buf)
996{
997 return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
998 MINOR(swsusp_resume_device));
999}
1000
1001static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
1002 const char *buf, size_t n)
1003{
1004 unsigned int maj, min;
1005 dev_t res;
1006 int ret = -EINVAL;
1007
1008 if (sscanf(buf, "%u:%u", &maj, &min) != 2)
1009 goto out;
1010
1011 res = MKDEV(maj,min);
1012 if (maj != MAJOR(res) || min != MINOR(res))
1013 goto out;
1014
1015 lock_system_sleep();
1016 swsusp_resume_device = res;
1017 unlock_system_sleep();
1018 printk(KERN_INFO "PM: Starting manual resume from disk\n");
1019 noresume = 0;
1020 software_resume();
1021 ret = n;
1022 out:
1023 return ret;
1024}
1025
1026power_attr(resume);
1027
1028static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
1029 char *buf)
1030{
1031 return sprintf(buf, "%lu\n", image_size);
1032}
1033
1034static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
1035 const char *buf, size_t n)
1036{
1037 unsigned long size;
1038
1039 if (sscanf(buf, "%lu", &size) == 1) {
1040 image_size = size;
1041 return n;
1042 }
1043
1044 return -EINVAL;
1045}
1046
1047power_attr(image_size);
1048
1049static ssize_t reserved_size_show(struct kobject *kobj,
1050 struct kobj_attribute *attr, char *buf)
1051{
1052 return sprintf(buf, "%lu\n", reserved_size);
1053}
1054
1055static ssize_t reserved_size_store(struct kobject *kobj,
1056 struct kobj_attribute *attr,
1057 const char *buf, size_t n)
1058{
1059 unsigned long size;
1060
1061 if (sscanf(buf, "%lu", &size) == 1) {
1062 reserved_size = size;
1063 return n;
1064 }
1065
1066 return -EINVAL;
1067}
1068
1069power_attr(reserved_size);
1070
1071static struct attribute * g[] = {
1072 &disk_attr.attr,
1073 &resume_attr.attr,
1074 &image_size_attr.attr,
1075 &reserved_size_attr.attr,
1076 NULL,
1077};
1078
1079
1080static struct attribute_group attr_group = {
1081 .attrs = g,
1082};
1083
1084
1085static int __init pm_disk_init(void)
1086{
1087 return sysfs_create_group(power_kobj, &attr_group);
1088}
1089
1090core_initcall(pm_disk_init);
1091
1092
1093static int __init resume_setup(char *str)
1094{
1095 if (noresume)
1096 return 1;
1097
1098 strncpy( resume_file, str, 255 );
1099 return 1;
1100}
1101
1102static int __init resume_offset_setup(char *str)
1103{
1104 unsigned long long offset;
1105
1106 if (noresume)
1107 return 1;
1108
1109 if (sscanf(str, "%llu", &offset) == 1)
1110 swsusp_resume_block = offset;
1111
1112 return 1;
1113}
1114
1115static int __init hibernate_setup(char *str)
1116{
1117 if (!strncmp(str, "noresume", 8))
1118 noresume = 1;
1119 else if (!strncmp(str, "nocompress", 10))
1120 nocompress = 1;
1121 else if (!strncmp(str, "no", 2)) {
1122 noresume = 1;
1123 nohibernate = 1;
1124 }
1125 return 1;
1126}
1127
1128static int __init noresume_setup(char *str)
1129{
1130 noresume = 1;
1131 return 1;
1132}
1133
1134static int __init resumewait_setup(char *str)
1135{
1136 resume_wait = 1;
1137 return 1;
1138}
1139
1140static int __init resumedelay_setup(char *str)
1141{
1142 resume_delay = simple_strtoul(str, NULL, 0);
1143 return 1;
1144}
1145
1146static int __init nohibernate_setup(char *str)
1147{
1148 noresume = 1;
1149 nohibernate = 1;
1150 return 1;
1151}
1152
1153
1154__setup("noresume", noresume_setup);
1155__setup("resume_offset=", resume_offset_setup);
1156__setup("resume=", resume_setup);
1157__setup("hibernate=", hibernate_setup);
1158__setup("resumewait", resumewait_setup);
1159__setup("resumedelay=", resumedelay_setup);
1160__setup("nohibernate", nohibernate_setup);
1161