aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2007-10-25 19:01:10 -0400
committerLen Brown <len.brown@intel.com>2008-02-01 18:30:53 -0500
commiteb57c1cf059630454b40fb8bb124e3f318d241f8 (patch)
treedf8abba4265647f15b3b30053a4d843099bb6b9e
parentaf508b34d27e3341287d89e0eae6752fdb1b873f (diff)
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: Rafael J. Wysocki <rjw@sisk.pl> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Len Brown <len.brown@intel.com>
-rw-r--r--Documentation/power/userland-swsusp.txt24
-rw-r--r--kernel/power/power.h9
-rw-r--r--kernel/power/user.c39
3 files changed, 38 insertions, 34 deletions
diff --git a/Documentation/power/userland-swsusp.txt b/Documentation/power/userland-swsusp.txt
index 32f187479697..381e9c0fb9d6 100644
--- a/Documentation/power/userland-swsusp.txt
+++ b/Documentation/power/userland-swsusp.txt
@@ -85,6 +85,12 @@ SNAPSHOT_SET_SWAP_AREA - set the resume partition and the offset (in <PAGE_SIZE>
85 recommended to always use this call, because the code to set the resume 85 recommended to always use this call, because the code to set the resume
86 partition may be removed from future kernels 86 partition may be removed from future kernels
87 87
88SNAPSHOT_PLATFORM_SUPPORT - enable/disable the hibernation platform support,
89 depending on the argument value (enable, if the argument is nonzero)
90
91SNAPSHOT_POWER_OFF - make the kernel transition the system to the hibernation
92 state (eg. ACPI S4) using the platform (eg. ACPI) driver
93
88SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to 94SNAPSHOT_S2RAM - suspend to RAM; using this call causes the kernel to
89 immediately enter the suspend-to-RAM state, so this call must always 95 immediately enter the suspend-to-RAM state, so this call must always
90 be preceded by the SNAPSHOT_FREEZE call and it is also necessary 96 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 to resume the system from RAM if there's enough battery power or restore 101 to resume the system from RAM if there's enough battery power or restore
96 its state on the basis of the saved suspend image otherwise) 102 its state on the basis of the saved suspend image otherwise)
97 103
98SNAPSHOT_PMOPS - enable the usage of the hibernation_ops->prepare,
99 hibernate_ops->enter and hibernation_ops->finish methods (the in-kernel
100 swsusp knows these as the "platform method") which are needed on many
101 machines to (among others) speed up the resume by letting the BIOS skip
102 some steps or to let the system recognise the correct state of the
103 hardware after the resume (in particular on many machines this ensures
104 that unplugged AC adapters get correctly detected and that kacpid does
105 not run wild after the resume). The last ioctl() argument can take one
106 of the three values, defined in kernel/power/power.h:
107 PMOPS_PREPARE - make the kernel carry out the
108 hibernation_ops->prepare() operation
109 PMOPS_ENTER - make the kernel power off the system by calling
110 hibernation_ops->enter()
111 PMOPS_FINISH - make the kernel carry out the
112 hibernation_ops->finish() operation
113 Note that the actual constants are misnamed because they surface
114 internal kernel implementation details that have changed.
115
116The device's read() operation can be used to transfer the snapshot image from 104The device's read() operation can be used to transfer the snapshot image from
117the kernel. It has the following limitations: 105the kernel. It has the following limitations:
118- you cannot read() more than one virtual memory page at a time 106- you cannot read() more than one virtual memory page at a time
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 23c17031ed21..6ca85fd4975f 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -156,15 +156,12 @@ struct resume_swap_area {
156#define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9) 156#define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9)
157#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int) 157#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
158#define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11) 158#define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11)
159#define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
160#define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \ 159#define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \
161 struct resume_swap_area) 160 struct resume_swap_area)
162#define SNAPSHOT_GET_IMAGE_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t) 161#define SNAPSHOT_GET_IMAGE_SIZE _IOR(SNAPSHOT_IOC_MAGIC, 14, loff_t)
163#define SNAPSHOT_IOC_MAXNR 14 162#define SNAPSHOT_PLATFORM_SUPPORT _IO(SNAPSHOT_IOC_MAGIC, 15)
164 163#define SNAPSHOT_POWER_OFF _IO(SNAPSHOT_IOC_MAGIC, 16)
165#define PMOPS_PREPARE 1 164#define SNAPSHOT_IOC_MAXNR 16
166#define PMOPS_ENTER 2
167#define PMOPS_FINISH 3
168 165
169/* If unset, the snapshot device cannot be open. */ 166/* If unset, the snapshot device cannot be open. */
170extern atomic_t snapshot_device_available; 167extern atomic_t snapshot_device_available;
diff --git a/kernel/power/user.c b/kernel/power/user.c
index 88aac26e598a..de3fb433ae39 100644
--- a/kernel/power/user.c
+++ b/kernel/power/user.c
@@ -28,6 +28,18 @@
28 28
29#include "power.h" 29#include "power.h"
30 30
31/*
32 * NOTE: The SNAPSHOT_PMOPS ioctl is obsolete and will be removed in the
33 * future. It is only preserved here for compatibility with existing userland
34 * utilities.
35 */
36#define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
37
38#define PMOPS_PREPARE 1
39#define PMOPS_ENTER 2
40#define PMOPS_FINISH 3
41
42
31#define SNAPSHOT_MINOR 231 43#define SNAPSHOT_MINOR 231
32 44
33static struct snapshot_data { 45static struct snapshot_data {
@@ -36,7 +48,7 @@ static struct snapshot_data {
36 int mode; 48 int mode;
37 char frozen; 49 char frozen;
38 char ready; 50 char ready;
39 char platform_suspend; 51 char platform_support;
40} snapshot_state; 52} snapshot_state;
41 53
42atomic_t snapshot_device_available = ATOMIC_INIT(1); 54atomic_t snapshot_device_available = ATOMIC_INIT(1);
@@ -70,7 +82,7 @@ static int snapshot_open(struct inode *inode, struct file *filp)
70 } 82 }
71 data->frozen = 0; 83 data->frozen = 0;
72 data->ready = 0; 84 data->ready = 0;
73 data->platform_suspend = 0; 85 data->platform_support = 0;
74 86
75 return 0; 87 return 0;
76} 88}
@@ -183,7 +195,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
183 error = -EPERM; 195 error = -EPERM;
184 break; 196 break;
185 } 197 }
186 error = hibernation_snapshot(data->platform_suspend); 198 error = hibernation_snapshot(data->platform_support);
187 if (!error) 199 if (!error)
188 error = put_user(in_suspend, (unsigned int __user *)arg); 200 error = put_user(in_suspend, (unsigned int __user *)arg);
189 if (!error) 201 if (!error)
@@ -197,7 +209,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
197 error = -EPERM; 209 error = -EPERM;
198 break; 210 break;
199 } 211 }
200 error = hibernation_restore(data->platform_suspend); 212 error = hibernation_restore(data->platform_support);
201 break; 213 break;
202 214
203 case SNAPSHOT_FREE: 215 case SNAPSHOT_FREE:
@@ -285,26 +297,33 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
285 mutex_unlock(&pm_mutex); 297 mutex_unlock(&pm_mutex);
286 break; 298 break;
287 299
288 case SNAPSHOT_PMOPS: 300 case SNAPSHOT_PLATFORM_SUPPORT:
301 data->platform_support = !!arg;
302 break;
303
304 case SNAPSHOT_POWER_OFF:
305 if (data->platform_support)
306 error = hibernation_platform_enter();
307 break;
308
309 case SNAPSHOT_PMOPS: /* This ioctl is deprecated */
289 error = -EINVAL; 310 error = -EINVAL;
290 311
291 switch (arg) { 312 switch (arg) {
292 313
293 case PMOPS_PREPARE: 314 case PMOPS_PREPARE:
294 data->platform_suspend = 1; 315 data->platform_support = 1;
295 error = 0; 316 error = 0;
296 break; 317 break;
297 318
298 case PMOPS_ENTER: 319 case PMOPS_ENTER:
299 if (data->platform_suspend) 320 if (data->platform_support)
300 error = hibernation_platform_enter(); 321 error = hibernation_platform_enter();
301
302 break; 322 break;
303 323
304 case PMOPS_FINISH: 324 case PMOPS_FINISH:
305 if (data->platform_suspend) 325 if (data->platform_support)
306 error = 0; 326 error = 0;
307
308 break; 327 break;
309 328
310 default: 329 default: