[PATCH] swsusp: add s2ram ioctl to userland interface
authorLuca Tettamanti <kronos.it@gmail.com>
Thu, 23 Mar 2006 11:00:09 +0000 (03:00 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Thu, 23 Mar 2006 15:38:08 +0000 (07:38 -0800)
Add the SNAPSHOT_S2RAM ioctl to the snapshot device.

This ioctl allows a userland application to make the system (previously frozen
with the SNAPSHOT_FREE ioctl) enter the S3 state without freezing processes
and disabling nonboot CPUs for the second time.

This will allow us to implement the suspend-to-disk-and-RAM (STDR)
functionality in the userland suspend tools.

Signed-off-by: Luca Tettamanti <kronos.it@gmail.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
kernel/power/main.c
kernel/power/power.h
kernel/power/user.c

index 9cb235cba4a9c8136670a74b034fd1738bb615dc..ee371f50ccaae6fc183f988ff92215df87a03064 100644 (file)
@@ -103,7 +103,7 @@ static int suspend_prepare(suspend_state_t state)
 }
 
 
-static int suspend_enter(suspend_state_t state)
+int suspend_enter(suspend_state_t state)
 {
        int error = 0;
        unsigned long flags;
index 42c431c8bdde178974a087ab22df85d815a2cf77..f06f12f2176733c6f87528c3a16f8c0a881e543c 100644 (file)
@@ -77,7 +77,8 @@ int snapshot_image_loaded(struct snapshot_handle *handle);
 #define SNAPSHOT_GET_SWAP_PAGE         _IOR(SNAPSHOT_IOC_MAGIC, 8, void *)
 #define SNAPSHOT_FREE_SWAP_PAGES       _IO(SNAPSHOT_IOC_MAGIC, 9)
 #define SNAPSHOT_SET_SWAP_FILE         _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
-#define SNAPSHOT_IOC_MAXNR     10
+#define SNAPSHOT_S2RAM                 _IO(SNAPSHOT_IOC_MAGIC, 11)
+#define SNAPSHOT_IOC_MAXNR     11
 
 /**
  *     The bitmap is used for tracing allocated swap pages
@@ -112,3 +113,4 @@ extern int swsusp_resume(void);
 extern int swsusp_read(void);
 extern int swsusp_write(void);
 extern void swsusp_close(void);
+extern int suspend_enter(suspend_state_t state);
index bbd4842104aa012786ff875aa37f58dc90d4a05b..3f1539fbe48a8be9c9f5ecf86f13042b3fed523d 100644 (file)
@@ -266,6 +266,42 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp,
                }
                break;
 
+       case SNAPSHOT_S2RAM:
+               if (!data->frozen) {
+                       error = -EPERM;
+                       break;
+               }
+
+               if (down_trylock(&pm_sem)) {
+                       error = -EBUSY;
+                       break;
+               }
+
+               if (pm_ops->prepare) {
+                       error = pm_ops->prepare(PM_SUSPEND_MEM);
+                       if (error)
+                               goto OutS3;
+               }
+
+               /* Put devices to sleep */
+               error = device_suspend(PMSG_SUSPEND);
+               if (error) {
+                       printk(KERN_ERR "Failed to suspend some devices.\n");
+               } else {
+                       /* Enter S3, system is already frozen */
+                       suspend_enter(PM_SUSPEND_MEM);
+
+                       /* Wake up devices */
+                       device_resume();
+               }
+
+               if (pm_ops->finish)
+                       pm_ops->finish(PM_SUSPEND_MEM);
+
+OutS3:
+               up(&pm_sem);
+               break;
+
        default:
                error = -ENOTTY;