提交 eb57c1cf 编写于 作者: R Rafael J. Wysocki 提交者: Len Brown

Hibernation: Rework platform support ioctls (rev. 2)

Modify the hibernation userland interface by adding two new ioctls to it,
SNAPSHOT_PLATFORM_SUPPORT and SNAPSHOT_POWER_OFF, that can be used,
respectively, to switch the hibernation platform support on/off and to make the
kernel transition the system to the hibernation state (eg. ACPI S4) using the
platform (eg. ACPI) driver.

These ioctls are intended to replace the misdesigned SNAPSHOT_PMOPS ioctl,
which from now is regarded as obsolete and will be removed in the future.
Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
Acked-by: NPavel Machek <pavel@ucw.cz>
Signed-off-by: NLen Brown <len.brown@intel.com>
上级 af508b34
...@@ -85,6 +85,12 @@ SNAPSHOT_SET_SWAP_AREA - set the resume partition and the offset (in <PAGE_SIZE> ...@@ -85,6 +85,12 @@ SNAPSHOT_SET_SWAP_AREA - set the resume partition and the offset (in <PAGE_SIZE>
recommended to always use this call, because the code to set the resume recommended to always use this call, because the code to set the resume
partition may be removed from future kernels partition may be removed from future kernels
SNAPSHOT_PLATFORM_SUPPORT - enable/disable the hibernation platform support,
depending on the argument value (enable, if the argument is nonzero)
SNAPSHOT_POWER_OFF - make the kernel transition the system to the hibernation
state (eg. ACPI S4) using the platform (eg. ACPI) driver
SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to
immediately enter the suspend-to-RAM state, so this call must always immediately enter the suspend-to-RAM state, so this call must always
be preceded by the SNAPSHOT_FREEZE call and it is also necessary be preceded by the SNAPSHOT_FREEZE call and it is also necessary
...@@ -95,24 +101,6 @@ SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to ...@@ -95,24 +101,6 @@ SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to
to resume the system from RAM if there's enough battery power or restore to resume the system from RAM if there's enough battery power or restore
its state on the basis of the saved suspend image otherwise) its state on the basis of the saved suspend image otherwise)
SNAPSHOT_PMOPS - enable the usage of the hibernation_ops->prepare,
hibernate_ops->enter and hibernation_ops->finish methods (the in-kernel
swsusp knows these as the "platform method") which are needed on many
machines to (among others) speed up the resume by letting the BIOS skip
some steps or to let the system recognise the correct state of the
hardware after the resume (in particular on many machines this ensures
that unplugged AC adapters get correctly detected and that kacpid does
not run wild after the resume). The last ioctl() argument can take one
of the three values, defined in kernel/power/power.h:
PMOPS_PREPARE - make the kernel carry out the
hibernation_ops->prepare() operation
PMOPS_ENTER - make the kernel power off the system by calling
hibernation_ops->enter()
PMOPS_FINISH - make the kernel carry out the
hibernation_ops->finish() operation
Note that the actual constants are misnamed because they surface
internal kernel implementation details that have changed.
The device's read() operation can be used to transfer the snapshot image from The device's read() operation can be used to transfer the snapshot image from
the kernel. It has the following limitations: the kernel. It has the following limitations:
- you cannot read() more than one virtual memory page at a time - you cannot read() more than one virtual memory page at a time
......
...@@ -156,15 +156,12 @@ struct resume_swap_area { ...@@ -156,15 +156,12 @@ struct resume_swap_area {
#define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9) #define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9)
#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int) #define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
#define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11) #define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11)
#define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
#define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \ #define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \
struct resume_swap_area) struct resume_swap_area)
#define SNAPSHOT_GET_IMAGE_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t) #define SNAPSHOT_GET_IMAGE_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t)
#define SNAPSHOT_IOC_MAXNR 14 #define SNAPSHOT_PLATFORM_SUPPORT _IO(SNAPSHOT_IOC_MAGIC, 15)
#define SNAPSHOT_POWER_OFF _IO(SNAPSHOT_IOC_MAGIC, 16)
#define PMOPS_PREPARE 1 #define SNAPSHOT_IOC_MAXNR 16
#define PMOPS_ENTER 2
#define PMOPS_FINISH 3
/* If unset, the snapshot device cannot be open. */ /* If unset, the snapshot device cannot be open. */
extern atomic_t snapshot_device_available; extern atomic_t snapshot_device_available;
......
...@@ -28,6 +28,18 @@ ...@@ -28,6 +28,18 @@
#include "power.h" #include "power.h"
/*
* NOTE: The SNAPSHOT_PMOPS ioctl is obsolete and will be removed in the
* future. It is only preserved here for compatibility with existing userland
* utilities.
*/
#define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
#define PMOPS_PREPARE 1
#define PMOPS_ENTER 2
#define PMOPS_FINISH 3
#define SNAPSHOT_MINOR 231 #define SNAPSHOT_MINOR 231
static struct snapshot_data { static struct snapshot_data {
...@@ -36,7 +48,7 @@ static struct snapshot_data { ...@@ -36,7 +48,7 @@ static struct snapshot_data {
int mode; int mode;
char frozen; char frozen;
char ready; char ready;
char platform_suspend; char platform_support;
} snapshot_state; } snapshot_state;
atomic_t snapshot_device_available = ATOMIC_INIT(1); atomic_t snapshot_device_available = ATOMIC_INIT(1);
...@@ -70,7 +82,7 @@ static int snapshot_open(struct inode *inode, struct file *filp) ...@@ -70,7 +82,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
} }
data->frozen = 0; data->frozen = 0;
data->ready = 0; data->ready = 0;
data->platform_suspend = 0; data->platform_support = 0;
return 0; return 0;
} }
...@@ -183,7 +195,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -183,7 +195,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EPERM; error = -EPERM;
break; break;
} }
error = hibernation_snapshot(data->platform_suspend); error = hibernation_snapshot(data->platform_support);
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)
...@@ -197,7 +209,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -197,7 +209,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
error = -EPERM; error = -EPERM;
break; break;
} }
error = hibernation_restore(data->platform_suspend); error = hibernation_restore(data->platform_support);
break; break;
case SNAPSHOT_FREE: case SNAPSHOT_FREE:
...@@ -285,26 +297,33 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, ...@@ -285,26 +297,33 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
mutex_unlock(&pm_mutex); mutex_unlock(&pm_mutex);
break; break;
case SNAPSHOT_PMOPS: case SNAPSHOT_PLATFORM_SUPPORT:
data->platform_support = !!arg;
break;
case SNAPSHOT_POWER_OFF:
if (data->platform_support)
error = hibernation_platform_enter();
break;
case SNAPSHOT_PMOPS: /* This ioctl is deprecated */
error = -EINVAL; error = -EINVAL;
switch (arg) { switch (arg) {
case PMOPS_PREPARE: case PMOPS_PREPARE:
data->platform_suspend = 1; data->platform_support = 1;
error = 0; error = 0;
break; break;
case PMOPS_ENTER: case PMOPS_ENTER:
if (data->platform_suspend) if (data->platform_support)
error = hibernation_platform_enter(); error = hibernation_platform_enter();
break; break;
case PMOPS_FINISH: case PMOPS_FINISH:
if (data->platform_suspend) if (data->platform_support)
error = 0; error = 0;
break; break;
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册