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@ucw.cz>
7 * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc.
8 * Copyright (C) 2012 Bojan Smojver <bojan@rexursive.com>
10 * This file is released under the GPLv2.
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>
22 #include <linux/mount.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>
35 static int nocompress
;
37 static int resume_wait
;
38 static int resume_delay
;
39 char resume_file
[256] = CONFIG_PM_STD_PARTITION
;
40 EXPORT_SYMBOL_GPL(resume_file
);
41 dev_t swsusp_resume_device
;
42 sector_t swsusp_resume_block
;
43 int in_suspend __nosavedata
;
54 __HIBERNATION_AFTER_LAST
56 #define HIBERNATION_MAX (__HIBERNATION_AFTER_LAST-1)
57 #define HIBERNATION_FIRST (HIBERNATION_INVALID + 1)
59 static int hibernation_mode
= HIBERNATION_SHUTDOWN
;
61 bool freezer_test_done
;
63 static const struct platform_hibernation_ops
*hibernation_ops
;
66 * hibernation_set_ops - Set the global hibernate operations.
67 * @ops: Hibernation operations to use in subsequent hibernation transitions.
69 void hibernation_set_ops(const struct platform_hibernation_ops
*ops
)
71 if (ops
&& !(ops
->begin
&& ops
->end
&& ops
->pre_snapshot
72 && ops
->prepare
&& ops
->finish
&& ops
->enter
&& ops
->pre_restore
73 && ops
->restore_cleanup
&& ops
->leave
)) {
78 hibernation_ops
= ops
;
80 hibernation_mode
= HIBERNATION_PLATFORM
;
81 else if (hibernation_mode
== HIBERNATION_PLATFORM
)
82 hibernation_mode
= HIBERNATION_SHUTDOWN
;
84 unlock_system_sleep();
87 static bool entering_platform_hibernation
;
89 bool system_entering_hibernation(void)
91 return entering_platform_hibernation
;
93 EXPORT_SYMBOL(system_entering_hibernation
);
95 #ifdef CONFIG_PM_DEBUG
96 static void hibernation_debug_sleep(void)
98 printk(KERN_INFO
"hibernation debug: Waiting for 5 seconds.\n");
102 static int hibernation_test(int level
)
104 if (pm_test_level
== level
) {
105 hibernation_debug_sleep();
110 #else /* !CONFIG_PM_DEBUG */
111 static int hibernation_test(int level
) { return 0; }
112 #endif /* !CONFIG_PM_DEBUG */
115 * platform_begin - Call platform to start hibernation.
116 * @platform_mode: Whether or not to use the platform driver.
118 int platform_begin(int platform_mode
)
120 return (platform_mode
&& hibernation_ops
) ?
121 hibernation_ops
->begin() : 0;
123 EXPORT_SYMBOL_GPL(platform_begin
);
126 * platform_end - Call platform to finish transition to the working state.
127 * @platform_mode: Whether or not to use the platform driver.
129 void platform_end(int platform_mode
)
131 if (platform_mode
&& hibernation_ops
)
132 hibernation_ops
->end();
134 EXPORT_SYMBOL_GPL(platform_end
);
137 * platform_pre_snapshot - Call platform to prepare the machine for hibernation.
138 * @platform_mode: Whether or not to use the platform driver.
140 * Use the platform driver to prepare the system for creating a hibernate image,
141 * if so configured, and return an error code if that fails.
144 int platform_pre_snapshot(int platform_mode
)
146 return (platform_mode
&& hibernation_ops
) ?
147 hibernation_ops
->pre_snapshot() : 0;
149 EXPORT_SYMBOL_GPL(platform_pre_snapshot
);
152 * platform_leave - Call platform to prepare a transition to the working state.
153 * @platform_mode: Whether or not to use the platform driver.
155 * Use the platform driver prepare to prepare the machine for switching to the
156 * normal mode of operation.
158 * This routine is called on one CPU with interrupts disabled.
160 void platform_leave(int platform_mode
)
162 if (platform_mode
&& hibernation_ops
)
163 hibernation_ops
->leave();
165 EXPORT_SYMBOL_GPL(platform_leave
);
168 * platform_finish - Call platform to switch the system to the working state.
169 * @platform_mode: Whether or not to use the platform driver.
171 * Use the platform driver to switch the machine to the normal mode of
174 * This routine must be called after platform_prepare().
176 void platform_finish(int platform_mode
)
178 if (platform_mode
&& hibernation_ops
)
179 hibernation_ops
->finish();
181 EXPORT_SYMBOL_GPL(platform_finish
);
184 * platform_pre_restore - Prepare for hibernate image restoration.
185 * @platform_mode: Whether or not to use the platform driver.
187 * Use the platform driver to prepare the system for resume from a hibernation
190 * If the restore fails after this function has been called,
191 * platform_restore_cleanup() must be called.
193 int platform_pre_restore(int platform_mode
)
195 return (platform_mode
&& hibernation_ops
) ?
196 hibernation_ops
->pre_restore() : 0;
198 EXPORT_SYMBOL_GPL(platform_pre_restore
);
201 * platform_restore_cleanup - Switch to the working state after failing restore.
202 * @platform_mode: Whether or not to use the platform driver.
204 * Use the platform driver to switch the system to the normal mode of operation
205 * after a failing restore.
207 * If platform_pre_restore() has been called before the failing restore, this
208 * function must be called too, regardless of the result of
209 * platform_pre_restore().
211 void platform_restore_cleanup(int platform_mode
)
213 if (platform_mode
&& hibernation_ops
)
214 hibernation_ops
->restore_cleanup();
216 EXPORT_SYMBOL_GPL(platform_restore_cleanup
);
219 * platform_recover - Recover from a failure to suspend devices.
220 * @platform_mode: Whether or not to use the platform driver.
222 void platform_recover(int platform_mode
)
224 if (platform_mode
&& hibernation_ops
&& hibernation_ops
->recover
)
225 hibernation_ops
->recover();
227 EXPORT_SYMBOL_GPL(platform_recover
);
230 * swsusp_show_speed - Print time elapsed between two events during hibernation.
231 * @start: Starting event.
232 * @stop: Final event.
233 * @nr_pages: Number of memory pages processed between @start and @stop.
234 * @msg: Additional diagnostic message to print.
236 void swsusp_show_speed(struct timeval
*start
, struct timeval
*stop
,
237 unsigned nr_pages
, char *msg
)
239 s64 elapsed_centisecs64
;
244 elapsed_centisecs64
= timeval_to_ns(stop
) - timeval_to_ns(start
);
245 do_div(elapsed_centisecs64
, NSEC_PER_SEC
/ 100);
246 centisecs
= elapsed_centisecs64
;
248 centisecs
= 1; /* avoid div-by-zero */
249 k
= nr_pages
* (PAGE_SIZE
/ 1024);
250 kps
= (k
* 100) / centisecs
;
251 printk(KERN_INFO
"PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
253 centisecs
/ 100, centisecs
% 100,
254 kps
/ 1000, (kps
% 1000) / 10);
258 * create_image - Create a hibernation image.
259 * @platform_mode: Whether or not to use the platform driver.
261 * Execute device drivers' "late" and "noirq" freeze callbacks, create a
262 * hibernation image and run the drivers' "noirq" and "early" thaw callbacks.
264 * Control reappears in this routine after the subsequent restore.
266 static int create_image(int platform_mode
)
270 error
= dpm_suspend_end(PMSG_FREEZE
);
272 printk(KERN_ERR
"PM: Some devices failed to power down, "
273 "aborting hibernation\n");
277 error
= platform_pre_snapshot(platform_mode
);
278 if (error
|| hibernation_test(TEST_PLATFORM
))
279 goto Platform_finish
;
281 error
= disable_nonboot_cpus();
282 if (error
|| hibernation_test(TEST_CPUS
))
287 error
= syscore_suspend();
289 printk(KERN_ERR
"PM: Some system devices failed to power down, "
290 "aborting hibernation\n");
294 if (hibernation_test(TEST_CORE
) || pm_wakeup_pending())
298 save_processor_state();
299 error
= swsusp_arch_suspend();
301 printk(KERN_ERR
"PM: Error %d creating hibernation image\n",
303 /* Restore control flow magically appears here */
304 restore_processor_state();
306 events_check_enabled
= false;
307 platform_leave(platform_mode
);
317 enable_nonboot_cpus();
320 platform_finish(platform_mode
);
322 dpm_resume_start(in_suspend
?
323 (error
? PMSG_RECOVER
: PMSG_THAW
) : PMSG_RESTORE
);
329 * hibernation_snapshot - Quiesce devices and create a hibernation image.
330 * @platform_mode: If set, use platform driver to prepare for the transition.
332 * This routine must be called with pm_mutex held.
334 int hibernation_snapshot(int platform_mode
)
339 error
= platform_begin(platform_mode
);
343 /* Preallocate image memory before shutting down devices. */
344 error
= hibernate_preallocate_memory();
348 error
= freeze_kernel_threads();
352 if (hibernation_test(TEST_FREEZER
)) {
355 * Indicate to the caller that we are returning due to a
356 * successful freezer test.
358 freezer_test_done
= true;
362 error
= dpm_prepare(PMSG_FREEZE
);
364 dpm_complete(PMSG_RECOVER
);
370 pm_restrict_gfp_mask();
372 error
= dpm_suspend(PMSG_FREEZE
);
374 if (error
|| hibernation_test(TEST_DEVICES
))
375 platform_recover(platform_mode
);
377 error
= create_image(platform_mode
);
380 * In the case that we call create_image() above, the control
381 * returns here (1) after the image has been created or the
382 * image creation has failed and (2) after a successful restore.
385 /* We may need to release the preallocated image pages here. */
386 if (error
|| !in_suspend
)
389 msg
= in_suspend
? (error
? PMSG_RECOVER
: PMSG_THAW
) : PMSG_RESTORE
;
392 if (error
|| !in_suspend
)
393 pm_restore_gfp_mask();
400 platform_end(platform_mode
);
404 thaw_kernel_threads();
411 * resume_target_kernel - Restore system state from a hibernation image.
412 * @platform_mode: Whether or not to use the platform driver.
414 * Execute device drivers' "noirq" and "late" freeze callbacks, restore the
415 * contents of highmem that have not been restored yet from the image and run
416 * the low-level code that will restore the remaining contents of memory and
417 * switch to the just restored target kernel.
419 static int resume_target_kernel(bool platform_mode
)
423 error
= dpm_suspend_end(PMSG_QUIESCE
);
425 printk(KERN_ERR
"PM: Some devices failed to power down, "
426 "aborting resume\n");
430 error
= platform_pre_restore(platform_mode
);
434 error
= disable_nonboot_cpus();
440 error
= syscore_suspend();
444 save_processor_state();
445 error
= restore_highmem();
447 error
= swsusp_arch_resume();
449 * The code below is only ever reached in case of a failure.
450 * Otherwise, execution continues at the place where
451 * swsusp_arch_suspend() was called.
455 * This call to restore_highmem() reverts the changes made by
461 * The only reason why swsusp_arch_resume() can fail is memory being
462 * very tight, so we have to free it as soon as we can to avoid
463 * subsequent failures.
466 restore_processor_state();
467 touch_softlockup_watchdog();
475 enable_nonboot_cpus();
478 platform_restore_cleanup(platform_mode
);
480 dpm_resume_start(PMSG_RECOVER
);
486 * hibernation_restore - Quiesce devices and restore from a hibernation image.
487 * @platform_mode: If set, use platform driver to prepare for the transition.
489 * This routine must be called with pm_mutex held. If it is successful, control
490 * reappears in the restored target kernel in hibernation_snapshot().
492 int hibernation_restore(int platform_mode
)
496 pm_prepare_console();
499 pm_restrict_gfp_mask();
500 error
= dpm_suspend_start(PMSG_QUIESCE
);
502 error
= resume_target_kernel(platform_mode
);
504 * The above should either succeed and jump to the new kernel,
505 * or return with an error. Otherwise things are just
506 * undefined, so let's be paranoid.
510 dpm_resume_end(PMSG_RECOVER
);
511 pm_restore_gfp_mask();
514 pm_restore_console();
519 * hibernation_platform_enter - Power off the system using the platform driver.
521 int hibernation_platform_enter(void)
525 if (!hibernation_ops
)
529 * We have cancelled the power transition by running
530 * hibernation_ops->finish() before saving the image, so we should let
531 * the firmware know that we're going to enter the sleep state after all
533 error
= hibernation_ops
->begin();
537 entering_platform_hibernation
= true;
540 error
= dpm_suspend_start(PMSG_HIBERNATE
);
542 if (hibernation_ops
->recover
)
543 hibernation_ops
->recover();
547 error
= dpm_suspend_end(PMSG_HIBERNATE
);
551 error
= hibernation_ops
->prepare();
553 goto Platform_finish
;
555 error
= disable_nonboot_cpus();
557 goto Platform_finish
;
561 if (pm_wakeup_pending()) {
566 hibernation_ops
->enter();
567 /* We should never get here */
573 enable_nonboot_cpus();
576 hibernation_ops
->finish();
578 dpm_resume_start(PMSG_RESTORE
);
581 entering_platform_hibernation
= false;
582 dpm_resume_end(PMSG_RESTORE
);
587 hibernation_ops
->end();
591 EXPORT_SYMBOL_GPL(hibernation_platform_enter
);
594 * power_down - Shut the machine down for hibernation.
596 * Use the platform driver, if configured, to put the system into the sleep
597 * state corresponding to hibernation, or try to power it off or reboot,
598 * depending on the value of hibernation_mode.
600 static void power_down(void)
602 #ifdef CONFIG_SUSPEND
606 switch (hibernation_mode
) {
607 case HIBERNATION_REBOOT
:
608 kernel_restart(NULL
);
610 case HIBERNATION_PLATFORM
:
611 hibernation_platform_enter();
612 case HIBERNATION_SHUTDOWN
:
615 #ifdef CONFIG_SUSPEND
616 case HIBERNATION_SUSPEND
:
617 error
= suspend_devices_and_enter(PM_SUSPEND_MEM
);
620 hibernation_mode
= HIBERNATION_PLATFORM
;
622 hibernation_mode
= HIBERNATION_SHUTDOWN
;
626 * Restore swap signature.
628 error
= swsusp_unmark();
630 printk(KERN_ERR
"PM: Swap will be unusable! "
637 * Valid image is on the disk, if we continue we risk serious data
638 * corruption after resume.
640 printk(KERN_CRIT
"PM: Please power down manually\n");
645 * hibernate - Carry out system hibernation, including saving the image.
651 hib_log("entering hibernate()\n");
653 if (test_action_state(TOI_REPLACE_SWSUSP
))
654 return try_tuxonice_hibernate();
657 /* The snapshot device should not be opened while we're running */
658 if (!atomic_add_unless(&snapshot_device_available
, -1, 0)) {
663 pm_prepare_console();
664 error
= pm_notifier_call_chain(PM_HIBERNATION_PREPARE
);
668 /* Allocate memory management structures */
669 error
= create_basic_memory_bitmaps();
673 printk(KERN_INFO
"PM: Syncing filesystems ... ");
677 error
= freeze_processes();
681 error
= hibernation_snapshot(hibernation_mode
== HIBERNATION_PLATFORM
);
682 if (error
|| freezer_test_done
)
686 unsigned int flags
= 0;
688 if (hibernation_mode
== HIBERNATION_PLATFORM
)
689 flags
|= SF_PLATFORM_MODE
;
691 flags
|= SF_NOCOMPRESS_MODE
;
693 flags
|= SF_CRC32_MODE
;
695 pr_debug("PM: writing image.\n");
696 error
= swsusp_write(flags
);
701 pm_restore_gfp_mask();
703 pr_debug("PM: Image restored successfully.\n");
709 /* Don't bother checking whether freezer_test_done is true */
710 freezer_test_done
= false;
713 free_basic_memory_bitmaps();
715 pm_notifier_call_chain(PM_POST_HIBERNATION
);
716 pm_restore_console();
717 atomic_inc(&snapshot_device_available
);
719 unlock_system_sleep();
725 * software_resume - Resume from a saved hibernation image.
727 * This routine is called as a late initcall, when all devices have been
728 * discovered and initialized already.
730 * The image reading code is called to see if there is a hibernation image
731 * available for reading. If that is the case, devices are quiesced and the
732 * contents of memory is restored from the saved image.
734 * If this is successful, control reappears in the restored target kernel in
735 * hibernation_snaphot() which returns to hibernate(). Otherwise, the routine
736 * attempts to recover gracefully and make the kernel return to the normal mode
739 int software_resume(void)
744 resume_attempted
= 1;
747 * We can't know (until an image header - if any - is loaded), whether
748 * we did override swsusp. We therefore ensure that both are tried.
750 try_tuxonice_resume();
753 * If the user said "noresume".. bail out early.
759 * name_to_dev_t() below takes a sysfs buffer mutex when sysfs
760 * is configured into the kernel. Since the regular hibernate
761 * trigger path is via sysfs which takes a buffer mutex before
762 * calling hibernate functions (which take pm_mutex) this can
763 * cause lockdep to complain about a possible ABBA deadlock
764 * which cannot happen since we're in the boot code here and
765 * sysfs can't be invoked yet. Therefore, we use a subclass
766 * here to avoid lockdep complaining.
768 mutex_lock_nested(&pm_mutex
, SINGLE_DEPTH_NESTING
);
770 if (swsusp_resume_device
)
773 if (!strlen(resume_file
)) {
778 pr_debug("PM: Checking hibernation image partition %s\n", resume_file
);
781 printk(KERN_INFO
"Waiting %dsec before reading resume device...\n",
783 ssleep(resume_delay
);
786 /* Check if the device is there */
787 swsusp_resume_device
= name_to_dev_t(resume_file
);
790 * name_to_dev_t is ineffective to verify parition if resume_file is in
791 * integer format. (e.g. major:minor)
793 if (isdigit(resume_file
[0]) && resume_wait
) {
795 while (!get_gendisk(swsusp_resume_device
, &partno
))
799 if (!swsusp_resume_device
) {
801 * Some device discovery might still be in progress; we need
802 * to wait for this to finish.
804 wait_for_device_probe();
807 while ((swsusp_resume_device
= name_to_dev_t(resume_file
)) == 0)
809 async_synchronize_full();
812 swsusp_resume_device
= name_to_dev_t(resume_file
);
813 if (!swsusp_resume_device
) {
820 pr_debug("PM: Hibernation image partition %d:%d present\n",
821 MAJOR(swsusp_resume_device
), MINOR(swsusp_resume_device
));
823 pr_debug("PM: Looking for hibernation image.\n");
824 error
= swsusp_check();
828 /* The snapshot device should not be opened while we're running */
829 if (!atomic_add_unless(&snapshot_device_available
, -1, 0)) {
831 swsusp_close(FMODE_READ
);
835 pm_prepare_console();
836 error
= pm_notifier_call_chain(PM_RESTORE_PREPARE
);
840 error
= create_basic_memory_bitmaps();
844 pr_debug("PM: Preparing processes for restore.\n");
845 error
= freeze_processes();
847 swsusp_close(FMODE_READ
);
851 pr_debug("PM: Loading hibernation image.\n");
853 error
= swsusp_read(&flags
);
854 swsusp_close(FMODE_READ
);
856 hibernation_restore(flags
& SF_PLATFORM_MODE
);
858 printk(KERN_ERR
"PM: Failed to load hibernation image, recovering.\n");
862 free_basic_memory_bitmaps();
864 pm_notifier_call_chain(PM_POST_RESTORE
);
865 pm_restore_console();
866 atomic_inc(&snapshot_device_available
);
867 /* For success case, the suspend path will release the lock */
869 mutex_unlock(&pm_mutex
);
870 pr_debug("PM: Hibernation image not present or could not be loaded.\n");
873 swsusp_close(FMODE_READ
);
877 #if !defined(CONFIG_MTK_HIBERNATION)
878 // IPO-H, move to kernel_init() @ kernel/init/main.c
879 late_initcall(software_resume
);
883 static const char * const hibernation_modes
[] = {
884 [HIBERNATION_PLATFORM
] = "platform",
885 [HIBERNATION_SHUTDOWN
] = "shutdown",
886 [HIBERNATION_REBOOT
] = "reboot",
887 #ifdef CONFIG_SUSPEND
888 [HIBERNATION_SUSPEND
] = "suspend",
893 * /sys/power/disk - Control hibernation mode.
895 * Hibernation can be handled in several ways. There are a few different ways
896 * to put the system into the sleep state: using the platform driver (e.g. ACPI
897 * or other hibernation_ops), powering it off or rebooting it (for testing
900 * The sysfs file /sys/power/disk provides an interface for selecting the
901 * hibernation mode to use. Reading from this file causes the available modes
902 * to be printed. There are 3 modes that can be supported:
908 * If a platform hibernation driver is in use, 'platform' will be supported
909 * and will be used by default. Otherwise, 'shutdown' will be used by default.
910 * The selected option (i.e. the one corresponding to the current value of
911 * hibernation_mode) is enclosed by a square bracket.
913 * To select a given hibernation mode it is necessary to write the mode's
914 * string representation (as returned by reading from /sys/power/disk) back
915 * into /sys/power/disk.
918 static ssize_t
disk_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
924 for (i
= HIBERNATION_FIRST
; i
<= HIBERNATION_MAX
; i
++) {
925 if (!hibernation_modes
[i
])
928 case HIBERNATION_SHUTDOWN
:
929 case HIBERNATION_REBOOT
:
930 #ifdef CONFIG_SUSPEND
931 case HIBERNATION_SUSPEND
:
934 case HIBERNATION_PLATFORM
:
937 /* not a valid mode, continue with loop */
940 if (i
== hibernation_mode
)
941 buf
+= sprintf(buf
, "[%s] ", hibernation_modes
[i
]);
943 buf
+= sprintf(buf
, "%s ", hibernation_modes
[i
]);
945 buf
+= sprintf(buf
, "\n");
949 static ssize_t
disk_store(struct kobject
*kobj
, struct kobj_attribute
*attr
,
950 const char *buf
, size_t n
)
956 int mode
= HIBERNATION_INVALID
;
958 p
= memchr(buf
, '\n', n
);
959 len
= p
? p
- buf
: n
;
962 for (i
= HIBERNATION_FIRST
; i
<= HIBERNATION_MAX
; i
++) {
963 if (len
== strlen(hibernation_modes
[i
])
964 && !strncmp(buf
, hibernation_modes
[i
], len
)) {
969 if (mode
!= HIBERNATION_INVALID
) {
971 case HIBERNATION_SHUTDOWN
:
972 case HIBERNATION_REBOOT
:
973 #ifdef CONFIG_SUSPEND
974 case HIBERNATION_SUSPEND
:
976 hibernation_mode
= mode
;
978 case HIBERNATION_PLATFORM
:
980 hibernation_mode
= mode
;
988 pr_debug("PM: Hibernation mode set to '%s'\n",
989 hibernation_modes
[mode
]);
990 unlock_system_sleep();
991 return error
? error
: n
;
996 static ssize_t
resume_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
999 return sprintf(buf
,"%d:%d\n", MAJOR(swsusp_resume_device
),
1000 MINOR(swsusp_resume_device
));
1003 static ssize_t
resume_store(struct kobject
*kobj
, struct kobj_attribute
*attr
,
1004 const char *buf
, size_t n
)
1006 unsigned int maj
, min
;
1010 if (sscanf(buf
, "%u:%u", &maj
, &min
) != 2)
1013 res
= MKDEV(maj
,min
);
1014 if (maj
!= MAJOR(res
) || min
!= MINOR(res
))
1017 lock_system_sleep();
1018 swsusp_resume_device
= res
;
1019 unlock_system_sleep();
1020 printk(KERN_INFO
"PM: Starting manual resume from disk\n");
1030 static ssize_t
image_size_show(struct kobject
*kobj
, struct kobj_attribute
*attr
,
1033 return sprintf(buf
, "%lu\n", image_size
);
1036 static ssize_t
image_size_store(struct kobject
*kobj
, struct kobj_attribute
*attr
,
1037 const char *buf
, size_t n
)
1041 if (sscanf(buf
, "%lu", &size
) == 1) {
1049 power_attr(image_size
);
1051 static ssize_t
reserved_size_show(struct kobject
*kobj
,
1052 struct kobj_attribute
*attr
, char *buf
)
1054 return sprintf(buf
, "%lu\n", reserved_size
);
1057 static ssize_t
reserved_size_store(struct kobject
*kobj
,
1058 struct kobj_attribute
*attr
,
1059 const char *buf
, size_t n
)
1063 if (sscanf(buf
, "%lu", &size
) == 1) {
1064 reserved_size
= size
;
1071 power_attr(reserved_size
);
1073 static struct attribute
* g
[] = {
1076 &image_size_attr
.attr
,
1077 &reserved_size_attr
.attr
,
1082 static struct attribute_group attr_group
= {
1087 static int __init
pm_disk_init(void)
1089 return sysfs_create_group(power_kobj
, &attr_group
);
1092 core_initcall(pm_disk_init
);
1095 static int __init
resume_setup(char *str
)
1100 strncpy( resume_file
, str
, 255 );
1104 static int __init
resume_offset_setup(char *str
)
1106 unsigned long long offset
;
1111 if (sscanf(str
, "%llu", &offset
) == 1)
1112 swsusp_resume_block
= offset
;
1117 static int __init
hibernate_setup(char *str
)
1119 if (!strncmp(str
, "noresume", 8))
1121 else if (!strncmp(str
, "nocompress", 10))
1126 static int __init
noresume_setup(char *str
)
1129 set_toi_state(TOI_NORESUME_SPECIFIED
);
1133 static int __init
resumewait_setup(char *str
)
1139 static int __init
resumedelay_setup(char *str
)
1141 resume_delay
= simple_strtoul(str
, NULL
, 0);
1145 __setup("noresume", noresume_setup
);
1146 __setup("resume_offset=", resume_offset_setup
);
1147 __setup("resume=", resume_setup
);
1148 __setup("hibernate=", hibernate_setup
);
1149 __setup("resumewait", resumewait_setup
);
1150 __setup("resumedelay=", resumedelay_setup
);