| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Rafael J. Wysocki | 46cd2f3 | 2006-02-07 12:58:50 -0800 | [diff] [blame] | 12 | #if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE) | 
 | 13 | #define SUSPEND_CONSOLE	(MAX_NR_CONSOLES-1) | 
 | 14 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | static int orig_fgconsole, orig_kmsg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 |  | 
 | 17 | int pm_prepare_console(void) | 
 | 18 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | 	acquire_console_sem(); | 
 | 20 |  | 
 | 21 | 	orig_fgconsole = fg_console; | 
 | 22 |  | 
 | 23 | 	if (vc_allocate(SUSPEND_CONSOLE)) { | 
 | 24 | 	  /* we can't have a free VC for now. Too bad, | 
 | 25 | 	   * we don't want to mess the screen for now. */ | 
 | 26 | 		release_console_sem(); | 
 | 27 | 		return 1; | 
 | 28 | 	} | 
 | 29 |  | 
| Andrew Johnson | b257bc0 | 2007-03-16 13:38:24 -0800 | [diff] [blame] | 30 | 	if (set_console(SUSPEND_CONSOLE)) { | 
 | 31 | 		/* | 
 | 32 | 		 * We're unable to switch to the SUSPEND_CONSOLE. | 
 | 33 | 		 * Let the calling function know so it can decide | 
 | 34 | 		 * what to do. | 
 | 35 | 		 */ | 
 | 36 | 		release_console_sem(); | 
 | 37 | 		return 1; | 
 | 38 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | 	release_console_sem(); | 
 | 40 |  | 
 | 41 | 	if (vt_waitactive(SUSPEND_CONSOLE)) { | 
 | 42 | 		pr_debug("Suspend: Can't switch VCs."); | 
 | 43 | 		return 1; | 
 | 44 | 	} | 
 | 45 | 	orig_kmsg = kmsg_redirect; | 
 | 46 | 	kmsg_redirect = SUSPEND_CONSOLE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | 	return 0; | 
 | 48 | } | 
 | 49 |  | 
 | 50 | void pm_restore_console(void) | 
 | 51 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | 	acquire_console_sem(); | 
 | 53 | 	set_console(orig_fgconsole); | 
 | 54 | 	release_console_sem(); | 
 | 55 | 	kmsg_redirect = orig_kmsg; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | 	return; | 
 | 57 | } | 
| Rafael J. Wysocki | f7b8988 | 2006-02-01 03:05:21 -0800 | [diff] [blame] | 58 | #endif |