ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / kernel / power / console.c
1 /*
2  * drivers/power/process.c - Functions for saving/restoring console.
3  *
4  * Originally from swsusp.
5  */
6
7 #include <linux/vt_kern.h>
8 #include <linux/kbd_kern.h>
9 #include <linux/console.h>
10 #include "power.h"
11
12 static int new_loglevel = 10;
13 static int orig_loglevel;
14 static int orig_fgconsole, orig_kmsg;
15
16 int pm_prepare_console(void)
17 {
18         orig_loglevel = console_loglevel;
19         console_loglevel = new_loglevel;
20
21 #ifdef SUSPEND_CONSOLE
22         acquire_console_sem();
23
24         orig_fgconsole = fg_console;
25
26         if (vc_allocate(SUSPEND_CONSOLE)) {
27           /* we can't have a free VC for now. Too bad,
28            * we don't want to mess the screen for now. */
29                 release_console_sem();
30                 return 1;
31         }
32
33         set_console(SUSPEND_CONSOLE);
34         release_console_sem();
35
36         if (vt_waitactive(SUSPEND_CONSOLE)) {
37                 pr_debug("Suspend: Can't switch VCs.");
38                 return 1;
39         }
40         orig_kmsg = kmsg_redirect;
41         kmsg_redirect = SUSPEND_CONSOLE;
42 #endif
43         return 0;
44 }
45
46 void pm_restore_console(void)
47 {
48         console_loglevel = orig_loglevel;
49 #ifdef SUSPEND_CONSOLE
50         acquire_console_sem();
51         set_console(orig_fgconsole);
52         release_console_sem();
53 #endif
54         return;
55 }