console.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * drivers/power/process.c - Functions for saving/restoring console.
  3. *
  4. * Originally from swsusp.
  5. */
  6. #include <linux/vt_kern.h>
  7. #include <linux/kbd_kern.h>
  8. #include <linux/console.h>
  9. #include "power.h"
  10. #if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
  11. #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
  12. static int orig_fgconsole, orig_kmsg;
  13. int pm_prepare_console(void)
  14. {
  15. acquire_console_sem();
  16. orig_fgconsole = fg_console;
  17. if (vc_allocate(SUSPEND_CONSOLE)) {
  18. /* we can't have a free VC for now. Too bad,
  19. * we don't want to mess the screen for now. */
  20. release_console_sem();
  21. return 1;
  22. }
  23. if (set_console(SUSPEND_CONSOLE)) {
  24. /*
  25. * We're unable to switch to the SUSPEND_CONSOLE.
  26. * Let the calling function know so it can decide
  27. * what to do.
  28. */
  29. release_console_sem();
  30. return 1;
  31. }
  32. release_console_sem();
  33. if (vt_waitactive(SUSPEND_CONSOLE)) {
  34. pr_debug("Suspend: Can't switch VCs.");
  35. return 1;
  36. }
  37. orig_kmsg = kmsg_redirect;
  38. kmsg_redirect = SUSPEND_CONSOLE;
  39. return 0;
  40. }
  41. void pm_restore_console(void)
  42. {
  43. acquire_console_sem();
  44. set_console(orig_fgconsole);
  45. release_console_sem();
  46. kmsg_redirect = orig_kmsg;
  47. return;
  48. }
  49. #endif