Skip to contentSkip to conversation

save/restore screen support for ACPI S3 sleep

PM Pavel Machek 2 participants 4 messages Jul 26, 2003 – Aug 5, 2003

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi!

This way console should be correctly restored after S3...

[Prototype should be added to include/linux/suspend.h].

kernel/suspend.c part only moves code out of "SWSUSP_ONLY" section.

drivers/acpi/sleep/main.c +2 -0
Index: linux/drivers/acpi/sleep/main.c
===================================================================
@@ -226,6 +234,7 @@
 	if (state == ACPI_STATE_S4 && !acpi_gbl_FACS->S4bios_f)
 		return AE_ERROR;
 
+	prepare_suspend_console();
 	/*
 	 * TBD: S1 can be done without device_suspend.  Make a CONFIG_XX
 	 * to handle however when S1 failed without device_suspend.
@@ -270,6 +279,7 @@
 	/* reset firmware waking vector */
 	acpi_set_firmware_waking_vector((acpi_physical_address) 0);
 	thaw_processes();
+	restore_console();
 
 	return status;
 }
kernel/suspend.c +1 -1
Index: linux/kernel/suspend.c
===================================================================
@@ -5,7 +5,7 @@
  * machine suspend feature using pretty near only high-level routines
  *
  * Copyright (C) 1998-2001 Gabor Kuti <[email protected]>
- * Copyright (C) 1998,2001,2002 Pavel Machek <[email protected]>
+ * Copyright (C) 1998,2001-2003 Pavel Machek <[email protected]>
  *
  * I'd like to thank the following people for their work:
  * 
@@ 1,-1 1,-1 @@
 
+int prepare_suspend_console(void)
+{
+	orig_loglevel = console_loglevel;
+	console_loglevel = new_loglevel;
+
+#ifdef CONFIG_VT
+	orig_fgconsole = fg_console;
+#ifdef SUSPEND_CONSOLE
+	if(vc_allocate(SUSPEND_CONSOLE))
+	  /* we can't have a free VC for now. Too bad,
+	   * we don't want to mess the screen for now. */
+		return 1;
+
+	set_console (SUSPEND_CONSOLE);
+	if (vt_waitactive(SUSPEND_CONSOLE)) {
+		printk(KERN_ERR "Bummer. Can't switch VCs.\n");
+		return 1;
+	}
+	orig_kmsg = kmsg_redirect;
+	kmsg_redirect = SUSPEND_CONSOLE;
+#endif
+#endif
+	return 0;
+}
+
+void restore_console(void)
+{
+	console_loglevel = orig_loglevel;
+#ifdef SUSPEND_CONSOLE
+	set_console (orig_fgconsole);
+#endif
+	return;
+}
+
+#ifdef CONFIG_SOFTWARE_SUSPEND
 /*
  * Saving part...
  */

@@ -569,39 +603,6 @@
return pagedir;
}

-static int prepare_suspend_console(void)
-{
- orig_loglevel = console_loglevel;
- console_loglevel = new_loglevel;
-
-#ifdef CONFIG_VT
- orig_fgconsole = fg_console;
-#ifdef SUSPEND_CONSOLE
- if(vc_allocate(SUSPEND_CONSOLE))
- /* we can't have a free VC for now. Too bad,
- * we don't want to mess the screen for now. */
- return 1;
-
- set_console (SUSPEND_CONSOLE);
- if(vt_waitactive(SUSPEND_CONSOLE)) {
- PRINTK("Bummer. Can't switch VCs.");
- return 1;
- }
- orig_kmsg = kmsg_redirect;
- kmsg_redirect = SUSPEND_CONSOLE;
-#endif
-#endif
- return 0;
-}
-
-static void restore_console(void)
-{
- console_loglevel = orig_loglevel;
-#ifdef SUSPEND_CONSOLE
- set_console (orig_fgconsole);
-#endif
- return;
-}

static int prepare_suspend_processes(void)
{

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#1 lore raw
Quoted 7 lines

This way console should be correctly restored after S3...

[Prototype should be added to include/linux/suspend.h].

kernel/suspend.c part only moves code out of "SWSUSP_ONLY" section.

I moved this code to kernel/power/console.c and made it dependent on CONFIG_PM only. I also fixed up the breakage Andrew reported earlier and added prototypes to include/linux/suspend.h. Patch below for review (not directly applicable, as it's relative to the series).

-pat

ChangeSet 1.1518, 2003/08/04 17:35:30-07:00, [email protected]

[power] Divorce suspend console code from swsusp.

- Create kernel/power/console.c
- Rename prepare_suspend_console() to pm_prepare_console() and restore_console() to pm_restore_console().
- Add prototypes to include/linux/suspend.h.
- Make kernel/power/console.o dependent only on CONFIG_PM
- Simplify logic for SUSPEND_CONSOLE define
- Make software_resume() prepare console much earlier, so we can localize the loglevel variables in console.c.
- Remove #ifdef CONFIG_VT from console.c, and just check for SUSPEND_CONSOLE. (Perhaps we should make entire file dependent on CONFIG_VT_CONSOLE?)
- Add kernel/power/power.h to share things across local files.

 include/linux/suspend.h |    4 +++
 kernel/power/Makefile   |    2 -
 kernel/power/console.c  |   40 ++++++++++++++++++++++++++++++
 kernel/power/power.h    |    9 ++++++
 kernel/power/swsusp.c   |   62 ++++++------------------------------------------
 5 files changed, 62 insertions(+), 55 deletions(-)
include/linux/suspend.h +4 -0
diff -Nru a/include/linux/suspend.h b/include/linux/suspend.h
@@ -85,6 +85,10 @@
 extern void refrigerator(unsigned long);
 extern int freeze_processes(void);
 extern void thaw_processes(void);
+
+extern int pm_prepare_console(void);
+extern void pm_restore_console(void);
+
 #else
 static inline void refrigerator(unsigned long)
 {
kernel/power/Makefile +1 -1
diff -Nru a/kernel/power/Makefile b/kernel/power/Makefile
@@ -1,2 +1,2 @@
-obj-y				:= process.o
+obj-y				:= process.o console.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= swsusp.o
kernel/power/console.c new file +40 -0
diff -Nru a/kernel/power/console.c b/kernel/power/console.c
@@ -0,0 +1,40 @@
+#include <linux/vt_kern.h>
+#include <linux/kbd_kern.h>
+#include "power.h"
+
+static int new_loglevel = 7;
+static int orig_loglevel;
+static int orig_fgconsole, orig_kmsg;
+
+int pm_prepare_console(void)
+{
+	orig_loglevel = console_loglevel;
+	console_loglevel = new_loglevel;
+
+#ifdef SUSPEND_CONSOLE
+	orig_fgconsole = fg_console;
+
+	if(vc_allocate(SUSPEND_CONSOLE))
+	  /* we can't have a free VC for now. Too bad,
+	   * we don't want to mess the screen for now. */
+		return 1;
+
+	set_console (SUSPEND_CONSOLE);
+	if(vt_waitactive(SUSPEND_CONSOLE)) {
+		pr_debug("Suspend: Can't switch VCs.");
+		return 1;
+	}
+	orig_kmsg = kmsg_redirect;
+	kmsg_redirect = SUSPEND_CONSOLE;
+#endif
+	return 0;
+}
+
+void pm_restore_console(void)
+{
+	console_loglevel = orig_loglevel;
+#ifdef SUSPEND_CONSOLE
+	set_console (orig_fgconsole);
+#endif
+	return;
+}
kernel/power/power.h new file +9 -0
diff -Nru a/kernel/power/power.h b/kernel/power/power.h
@@ -0,0 +1,9 @@
+
+
+/* With SUSPEND_CONSOLE defined, it suspend looks *really* cool, but
+   we probably do not take enough locks for switching consoles, etc,
+   so bad things might happen.
+*/
+#if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
+#define SUSPEND_CONSOLE	(MAX_NR_CONSOLES-1)
+#endif
kernel/power/swsusp.c +8 -54

121 lines not on this page · raw message

#2 lore raw

Hi!

Quoted 11 lines
Quoted 6 lines

This way console should be correctly restored after S3...

[Prototype should be added to include/linux/suspend.h].

kernel/suspend.c part only moves code out of "SWSUSP_ONLY" section.

I moved this code to kernel/power/console.c and made it dependent on CONFIG_PM only. I also fixed up the breakage Andrew reported earlier and added prototypes to include/linux/suspend.h. Patch below for review (not directly applicable, as it's relative to the series).

Patch looks good, except that you should put some comment at begining of console.c. (GPL+copyrights+one line what this file is about). I guess that's trivial to fix up incrementally.
Pavel

Signature · 2 lines
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]
#3 lore raw
Quoted 9 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 6 lines

This way console should be correctly restored after S3...

[Prototype should be added to include/linux/suspend.h].

kernel/suspend.c part only moves code out of "SWSUSP_ONLY" section.

Quoted 8 lines
Quoted 4 lines

I moved this code to kernel/power/console.c and made it dependent on CONFIG_PM only. I also fixed up the breakage Andrew reported earlier and added prototypes to include/linux/suspend.h. Patch below for review (not directly applicable, as it's relative to the series).

Patch looks good, except that you should put some comment at begining of console.c. (GPL+copyrights+one line what this file is about). I guess that's trivial to fix up incrementally.

Sorry, missed that part. Will fix up.

-pat