On Mon, Sep 25, 2006 at 06:50:17PM +0200, Stefan Seyfried wrote:
> Note that we could get rid of that platform_mode variable if we had the
> possibility to specify defaults in the struct config_par (without resorting
> to platform_mode i would have had multiple incarnations of
>
> if (strcmp(shutdown_method, "reboot") || strcmp(shutdown_method,
> "shutdown"))
> foo;
>
> which i wanted to avoid). Would a patch for this be something of interest?
Forget about that, i should have inspected the code closer before writing :-)
Updated patch follows.
Implement the userspace part of "use platform mode to suspend machines".
Index: suspend.c
===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.57
diff -u -p -r1.57 suspend.c
--- suspend.c 24 Sep 2006 08:09:59 -0000 1.57
+++ suspend.c 25 Sep 2006 17:37:53 -0000
@@ -67,7 +67,7 @@ static char s2ram;
static char early_writeout;
static char splash_param;
#define SHUTDOWN_LEN 16
-static char shutdown_method[SHUTDOWN_LEN];
+static char shutdown_method[SHUTDOWN_LEN] = "platform";
static int suspend_swappiness = SUSPEND_SWAPPINESS;
static struct splash splash;
@@ -659,13 +659,18 @@ static int reset_signature(int fd)
}
#endif
-static void suspend_shutdown(void)
+static void suspend_shutdown(int dev)
{
- /* todo: platform, S3 */
+ /* todo: S3 */
if (!strcmp(shutdown_method, "reboot"))
reboot();
- else
- power_off();
+ else if (!strcmp(shutdown_method, "platform")) {
+ int ret = platform_enter(dev);
+ if (ret < 0)
+ fprintf(stderr, "suspend: pm_ops->enter returned"
+ " error %d, calling power_off\n", ret);
+ }
+ power_off();
/* Signature is on disk, it is very dangerous to continue now.
* We'd do resume with stale caches on next boot. */
fprintf(stderr,"Powerdown failed. That's impossible.\n");
@@ -699,6 +704,13 @@ int suspend_system(int snapshot_fd, int
if (error)
goto Unfreeze;
+ if (!strcmp(shutdown_method, "platform")) {
+ int ret = platform_prepare(snapshot_fd);
+ if (ret < 0)
+ fprintf(stderr, "suspend: pm_ops->prepare returned "
+ "error %d\n", ret);
+ }
+
printf("suspend: Snapshotting system\n");
attempts = 2;
do {
@@ -709,6 +721,12 @@ int suspend_system(int snapshot_fd, int
if (!atomic_snapshot(snapshot_fd, &in_suspend)) {
if (!in_suspend) {
free_snapshot(snapshot_fd);
+ if (!strcmp(shutdown_method, "platform")) {
+ int ret = platform_finish(snapshot_fd);
+ if (ret < 0)
+ fprintf(stderr, "suspend:
pm_ops->finish "
+ "returned error %d\n",
ret);
+ }
break;
}
error = write_image(snapshot_fd, resume_fd);
@@ -716,14 +734,14 @@ int suspend_system(int snapshot_fd, int
splash.progress(100);
#ifdef CONFIG_BOTH
if (!s2ram) {
- suspend_shutdown();
+ suspend_shutdown(snapshot_fd);
} else {
/* If we die (and allow system to
continue) between
* now and reset_signature(), very bad
things will
* happen. */
error = suspend_to_ram(snapshot_fd);
if (error)
- suspend_shutdown();
+ suspend_shutdown(snapshot_fd);
reset_signature(resume_fd);
free_swap_pages(snapshot_fd);
free_snapshot(snapshot_fd);
@@ -731,7 +749,7 @@ int suspend_system(int snapshot_fd, int
goto Unfreeze;
}
#else
- suspend_shutdown();
+ suspend_shutdown(snapshot_fd);
#endif
} else {
free_swap_pages(snapshot_fd);
Index: swsusp.h
===================================================================
RCS file: /cvsroot/suspend/suspend/swsusp.h,v
retrieving revision 1.27
diff -u -p -r1.27 swsusp.h
--- swsusp.h 24 Sep 2006 08:09:59 -0000 1.27
+++ swsusp.h 25 Sep 2006 17:37:53 -0000
@@ -26,7 +26,12 @@
#define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9)
#define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned
int)
#define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11)
-#define SNAPSHOT_IOC_MAXNR 11
+#define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned
int)
+#define SNAPSHOT_IOC_MAXNR 12
+
+#define PMOPS_PREPARE 1
+#define PMOPS_ENTER 2
+#define PMOPS_FINISH 3
#define LINUX_REBOOT_MAGIC1 0xfee1dead
#define LINUX_REBOOT_MAGIC2 672274793
@@ -99,6 +104,21 @@ static inline int atomic_restore(int dev
return ioctl(dev, SNAPSHOT_ATOMIC_RESTORE, 0);
}
+static inline int platform_prepare(int dev)
+{
+ return ioctl (dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
+}
+
+static inline int platform_enter(int dev)
+{
+ return ioctl (dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
+}
+
+static inline int platform_finish(int dev)
+{
+ return ioctl (dev, SNAPSHOT_PMOPS, PMOPS_FINISH);
+}
+
static inline int free_snapshot(int dev)
{
return ioctl(dev, SNAPSHOT_FREE, 0);
--
Stefan Seyfried
QA / R&D Team Mobile Devices | "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg | "Well, surrounding them's out."
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Suspend-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/suspend-devel