Commit 62c552cc authored by Bojan Smojver's avatar Bojan Smojver Committed by Rafael J. Wysocki

PM / Hibernate: Enable suspend to both for in-kernel hibernation.

It is often useful to suspend to memory after hibernation image has been
written to disk. If the battery runs out or power is otherwise lost, the
computer will resume from the hibernated image. If not, it will resume
from memory and hibernation image will be discarded.
Signed-off-by: default avatarBojan Smojver <bojan@rexursive.com>
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
parent 6887a413
...@@ -33,6 +33,11 @@ echo shutdown > /sys/power/disk; echo disk > /sys/power/state ...@@ -33,6 +33,11 @@ echo shutdown > /sys/power/disk; echo disk > /sys/power/state
echo platform > /sys/power/disk; echo disk > /sys/power/state echo platform > /sys/power/disk; echo disk > /sys/power/state
. If you would like to write hibernation image to swap and then suspend
to RAM (provided your platform supports it), you can try
echo suspend > /sys/power/disk; echo disk > /sys/power/state
. If you have SATA disks, you'll need recent kernels with SATA suspend . If you have SATA disks, you'll need recent kernels with SATA suspend
support. For suspend and resume to work, make sure your disk drivers support. For suspend and resume to work, make sure your disk drivers
are built into kernel -- not modules. [There's way to make are built into kernel -- not modules. [There's way to make
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Copyright (c) 2003 Open Source Development Lab * Copyright (c) 2003 Open Source Development Lab
* Copyright (c) 2004 Pavel Machek <pavel@ucw.cz> * Copyright (c) 2004 Pavel Machek <pavel@ucw.cz>
* Copyright (c) 2009 Rafael J. Wysocki, Novell Inc. * Copyright (c) 2009 Rafael J. Wysocki, Novell Inc.
* Copyright (C) 2012 Bojan Smojver <bojan@rexursive.com>
* *
* This file is released under the GPLv2. * This file is released under the GPLv2.
*/ */
...@@ -46,6 +47,9 @@ enum { ...@@ -46,6 +47,9 @@ enum {
HIBERNATION_PLATFORM, HIBERNATION_PLATFORM,
HIBERNATION_SHUTDOWN, HIBERNATION_SHUTDOWN,
HIBERNATION_REBOOT, HIBERNATION_REBOOT,
#ifdef CONFIG_SUSPEND
HIBERNATION_SUSPEND,
#endif
/* keep last */ /* keep last */
__HIBERNATION_AFTER_LAST __HIBERNATION_AFTER_LAST
}; };
...@@ -574,6 +578,10 @@ int hibernation_platform_enter(void) ...@@ -574,6 +578,10 @@ int hibernation_platform_enter(void)
*/ */
static void power_down(void) static void power_down(void)
{ {
#ifdef CONFIG_SUSPEND
int error;
#endif
switch (hibernation_mode) { switch (hibernation_mode) {
case HIBERNATION_REBOOT: case HIBERNATION_REBOOT:
kernel_restart(NULL); kernel_restart(NULL);
...@@ -583,6 +591,25 @@ static void power_down(void) ...@@ -583,6 +591,25 @@ static void power_down(void)
case HIBERNATION_SHUTDOWN: case HIBERNATION_SHUTDOWN:
kernel_power_off(); kernel_power_off();
break; break;
#ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:
error = suspend_devices_and_enter(PM_SUSPEND_MEM);
if (error) {
if (hibernation_ops)
hibernation_mode = HIBERNATION_PLATFORM;
else
hibernation_mode = HIBERNATION_SHUTDOWN;
power_down();
}
/*
* Restore swap signature.
*/
error = swsusp_unmark();
if (error)
printk(KERN_ERR "PM: Swap will be unusable! "
"Try swapon -a.\n");
return;
#endif
} }
kernel_halt(); kernel_halt();
/* /*
...@@ -827,6 +854,9 @@ static const char * const hibernation_modes[] = { ...@@ -827,6 +854,9 @@ static const char * const hibernation_modes[] = {
[HIBERNATION_PLATFORM] = "platform", [HIBERNATION_PLATFORM] = "platform",
[HIBERNATION_SHUTDOWN] = "shutdown", [HIBERNATION_SHUTDOWN] = "shutdown",
[HIBERNATION_REBOOT] = "reboot", [HIBERNATION_REBOOT] = "reboot",
#ifdef CONFIG_SUSPEND
[HIBERNATION_SUSPEND] = "suspend",
#endif
}; };
/* /*
...@@ -867,6 +897,9 @@ static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -867,6 +897,9 @@ static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
switch (i) { switch (i) {
case HIBERNATION_SHUTDOWN: case HIBERNATION_SHUTDOWN:
case HIBERNATION_REBOOT: case HIBERNATION_REBOOT:
#ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:
#endif
break; break;
case HIBERNATION_PLATFORM: case HIBERNATION_PLATFORM:
if (hibernation_ops) if (hibernation_ops)
...@@ -907,6 +940,9 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr, ...@@ -907,6 +940,9 @@ static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
switch (mode) { switch (mode) {
case HIBERNATION_SHUTDOWN: case HIBERNATION_SHUTDOWN:
case HIBERNATION_REBOOT: case HIBERNATION_REBOOT:
#ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:
#endif
hibernation_mode = mode; hibernation_mode = mode;
break; break;
case HIBERNATION_PLATFORM: case HIBERNATION_PLATFORM:
......
...@@ -156,6 +156,9 @@ extern void swsusp_free(void); ...@@ -156,6 +156,9 @@ extern void swsusp_free(void);
extern int swsusp_read(unsigned int *flags_p); extern int swsusp_read(unsigned int *flags_p);
extern int swsusp_write(unsigned int flags); extern int swsusp_write(unsigned int flags);
extern void swsusp_close(fmode_t); extern void swsusp_close(fmode_t);
#ifdef CONFIG_SUSPEND
extern int swsusp_unmark(void);
#endif
/* kernel/power/block_io.c */ /* kernel/power/block_io.c */
extern struct block_device *hib_resume_bdev; extern struct block_device *hib_resume_bdev;
......
...@@ -1472,6 +1472,34 @@ void swsusp_close(fmode_t mode) ...@@ -1472,6 +1472,34 @@ void swsusp_close(fmode_t mode)
blkdev_put(hib_resume_bdev, mode); blkdev_put(hib_resume_bdev, mode);
} }
/**
* swsusp_unmark - Unmark swsusp signature in the resume device
*/
#ifdef CONFIG_SUSPEND
int swsusp_unmark(void)
{
int error;
hib_bio_read_page(swsusp_resume_block, swsusp_header, NULL);
if (!memcmp(HIBERNATE_SIG,swsusp_header->sig, 10)) {
memcpy(swsusp_header->sig,swsusp_header->orig_sig, 10);
error = hib_bio_write_page(swsusp_resume_block,
swsusp_header, NULL);
} else {
printk(KERN_ERR "PM: Cannot find swsusp signature!\n");
error = -ENODEV;
}
/*
* We just returned from suspend, we don't need the image any more.
*/
free_all_swap_pages(root_swap);
return error;
}
#endif
static int swsusp_header_init(void) static int swsusp_header_init(void)
{ {
swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL); swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment