console.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <linux/module.h>
  10. #include "power.h"
  11. #if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
  12. #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
  13. static int orig_fgconsole, orig_kmsg;
  14. static int disable_vt_switch;
  15. /*
  16. * Normally during a suspend, we allocate a new console and switch to it.
  17. * When we resume, we switch back to the original console. This switch
  18. * can be slow, so on systems where the framebuffer can handle restoration
  19. * of video registers anyways, there's little point in doing the console
  20. * switch. This function allows you to disable it by passing it '0'.
  21. */
  22. void pm_set_vt_switch(int do_switch)
  23. {
  24. acquire_console_sem();
  25. disable_vt_switch = !do_switch;
  26. release_console_sem();
  27. }
  28. EXPORT_SYMBOL(pm_set_vt_switch);
  29. int pm_prepare_console(void)
  30. {
  31. acquire_console_sem();
  32. if (disable_vt_switch) {
  33. release_console_sem();
  34. return 0;
  35. }
  36. orig_fgconsole = fg_console;
  37. if (vc_allocate(SUSPEND_CONSOLE)) {
  38. /* we can't have a free VC for now. Too bad,
  39. * we don't want to mess the screen for now. */
  40. release_console_sem();
  41. return 1;
  42. }
  43. if (set_console(SUSPEND_CONSOLE)) {
  44. /*
  45. * We're unable to switch to the SUSPEND_CONSOLE.
  46. * Let the calling function know so it can decide
  47. * what to do.
  48. */
  49. release_console_sem();
  50. return 1;
  51. }
  52. release_console_sem();
  53. if (vt_waitactive(SUSPEND_CONSOLE)) {
  54. pr_debug("Suspend: Can't switch VCs.");
  55. return 1;
  56. }
  57. orig_kmsg = kmsg_redirect;
  58. kmsg_redirect = SUSPEND_CONSOLE;
  59. return 0;
  60. }
  61. void pm_restore_console(void)
  62. {
  63. acquire_console_sem();
  64. if (disable_vt_switch) {
  65. release_console_sem();
  66. return;
  67. }
  68. set_console(orig_fgconsole);
  69. release_console_sem();
  70. if (vt_waitactive(orig_fgconsole)) {
  71. pr_debug("Resume: Can't switch VCs.");
  72. return;
  73. }
  74. kmsg_redirect = orig_kmsg;
  75. }
  76. #endif