Commit 2b5b09b3 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Linus Torvalds

[PATCH] swsusp: Change pm_ops handling by userland interface

Make the userland interface of swsusp call pm_ops->finish() after
enable_nonboot_cpus() and before resume_device(), as indicated by the recent
discussion on Linux-PM (cf.
http://lists.osdl.org/pipermail/linux-pm/2006-November/004164.html).

This patch changes the SNAPSHOT_PMOPS ioctl so that its first function,
PMOPS_PREPARE, only sets a switch turning the platform suspend mode on, and
its last function, PMOPS_FINISH, only checks if the platform mode is enabled.
This should allow the older userland tools to work with new kernels without
any modifications.

The changes here only affect the userland interface of swsusp.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Cc: Greg KH <greg@kroah.com>
Cc: Nigel Cunningham <nigel@suspend2.net>
Cc: Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d12c610e
...@@ -37,6 +37,7 @@ static struct snapshot_data { ...@@ -37,6 +37,7 @@ static struct snapshot_data {
int mode; int mode;
char frozen; char frozen;
char ready; char ready;
char platform_suspend;
} snapshot_state; } snapshot_state;
static atomic_t device_available = ATOMIC_INIT(1); static atomic_t device_available = ATOMIC_INIT(1);
...@@ -66,6 +67,7 @@ static int snapshot_open(struct inode *inode, struct file *filp) ...@@ -66,6 +67,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
data->bitmap = NULL; data->bitmap = NULL;
data->frozen = 0; data->frozen = 0;
data->ready = 0; data->ready = 0;
data->platform_suspend = 0;
return 0; return 0;
} }
...@@ -122,7 +124,23 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf, ...@@ -122,7 +124,23 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
return res; return res;
} }
static int snapshot_suspend(void) static inline int platform_prepare(void)
{
int error = 0;
if (pm_ops && pm_ops->prepare)
error = pm_ops->prepare(PM_SUSPEND_DISK);
return error;
}
static inline void platform_finish(void)
{
if (pm_ops && pm_ops->finish)
pm_ops->finish(PM_SUSPEND_DISK);
}
static inline int snapshot_suspend(int platform_suspend)
{ {
int error; int error;
...@@ -132,6 +150,11 @@ static int snapshot_suspend(void) ...@@ -132,6 +150,11 @@ static int snapshot_suspend(void)
if (error) if (error)
goto Finish; goto Finish;
if (platform_suspend) {
error = platform_prepare();
if (error)
goto Finish;
}
suspend_console(); suspend_console();
error = device_suspend(PMSG_FREEZE); error = device_suspend(PMSG_FREEZE);
if (error) if (error)
...@@ -144,6 +167,9 @@ static int snapshot_suspend(void) ...@@ -144,6 +167,9 @@ static int snapshot_suspend(void)
} }
enable_nonboot_cpus(); enable_nonboot_cpus();
Resume_devices: Resume_devices:
if (platform_suspend)
platform_finish();
device_resume(); device_resume();
resume_console(); resume_console();
Finish: Finish:
...@@ -151,12 +177,17 @@ static int snapshot_suspend(void) ...@@ -151,12 +177,17 @@ static int snapshot_suspend(void)
return error; return error;
} }
static int snapshot_restore(void) static inline int snapshot_restore(int platform_suspend)
{ {
int error; int error;
mutex_lock(&pm_mutex); mutex_lock(&pm_mutex);
pm_prepare_console(); pm_prepare_console();
if (platform_suspend) {
error = platform_prepare();
if (error)
goto Finish;
}
suspend_console(); suspend_console();
error = device_suspend(PMSG_PRETHAW); error = device_suspend(PMSG_PRETHAW);
if (error) if (error)
...@@ -168,8 +199,12 @@ static int snapshot_restore(void) ...@@ -168,8 +199,12 @@ static int snapshot_restore(void)
enable_nonboot_cpus(); enable_nonboot_cpus();
Resume_devices: Resume_devices:
if (platform_suspend)
platform_finish();
device_resume(); device_resume();
resume_console(); resume_console();
Finish:
pm_restore_console(); pm_restore_console();
mutex_unlock(&pm_mutex); mutex_unlock(&pm_mutex);
return error; return error;
...@@ -221,7 +256,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -221,7 +256,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EPERM; error = -EPERM;
break; break;
} }
error = snapshot_suspend(); error = snapshot_suspend(data->platform_suspend);
if (!error) if (!error)
error = put_user(in_suspend, (unsigned int __user *)arg); error = put_user(in_suspend, (unsigned int __user *)arg);
if (!error) if (!error)
...@@ -235,7 +270,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -235,7 +270,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EPERM; error = -EPERM;
break; break;
} }
error = snapshot_restore(); error = snapshot_restore(data->platform_suspend);
break; break;
case SNAPSHOT_FREE: case SNAPSHOT_FREE:
...@@ -306,6 +341,11 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -306,6 +341,11 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
break; break;
case SNAPSHOT_S2RAM: case SNAPSHOT_S2RAM:
if (!pm_ops) {
error = -ENOSYS;
break;
}
if (!data->frozen) { if (!data->frozen) {
error = -EPERM; error = -EPERM;
break; break;
...@@ -343,28 +383,35 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -343,28 +383,35 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
break; break;
case SNAPSHOT_PMOPS: case SNAPSHOT_PMOPS:
error = -EINVAL;
switch (arg) { switch (arg) {
case PMOPS_PREPARE: case PMOPS_PREPARE:
if (pm_ops->prepare) { if (pm_ops && pm_ops->enter) {
error = pm_ops->prepare(PM_SUSPEND_DISK); data->platform_suspend = 1;
error = 0;
} else {
error = -ENOSYS;
} }
break; break;
case PMOPS_ENTER: case PMOPS_ENTER:
kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK); if (data->platform_suspend) {
error = pm_ops->enter(PM_SUSPEND_DISK); kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK);
error = pm_ops->enter(PM_SUSPEND_DISK);
error = 0;
}
break; break;
case PMOPS_FINISH: case PMOPS_FINISH:
if (pm_ops && pm_ops->finish) { if (data->platform_suspend)
pm_ops->finish(PM_SUSPEND_DISK); error = 0;
}
break; break;
default: default:
printk(KERN_ERR "SNAPSHOT_PMOPS: invalid argument %ld\n", arg); printk(KERN_ERR "SNAPSHOT_PMOPS: invalid argument %ld\n", arg);
error = -EINVAL;
} }
break; break;
......
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