dummycon.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/drivers/video/dummycon.c -- A dummy console driver
  4. *
  5. * To be used if there's no other console driver (e.g. for plain VGA text)
  6. * available, usually until fbcon takes console over.
  7. */
  8. #include <linux/types.h>
  9. #include <linux/kdev_t.h>
  10. #include <linux/console.h>
  11. #include <linux/vt_kern.h>
  12. #include <linux/screen_info.h>
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. /*
  16. * Dummy console driver
  17. */
  18. #if defined(__arm__)
  19. #define DUMMY_COLUMNS screen_info.orig_video_cols
  20. #define DUMMY_ROWS screen_info.orig_video_lines
  21. #else
  22. /* set by Kconfig. Use 80x25 for 640x480 and 160x64 for 1280x1024 */
  23. #define DUMMY_COLUMNS CONFIG_DUMMY_CONSOLE_COLUMNS
  24. #define DUMMY_ROWS CONFIG_DUMMY_CONSOLE_ROWS
  25. #endif
  26. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  27. /* These are both protected by the console_lock */
  28. static RAW_NOTIFIER_HEAD(dummycon_output_nh);
  29. static bool dummycon_putc_called;
  30. void dummycon_register_output_notifier(struct notifier_block *nb)
  31. {
  32. WARN_CONSOLE_UNLOCKED();
  33. raw_notifier_chain_register(&dummycon_output_nh, nb);
  34. if (dummycon_putc_called)
  35. nb->notifier_call(nb, 0, NULL);
  36. }
  37. void dummycon_unregister_output_notifier(struct notifier_block *nb)
  38. {
  39. WARN_CONSOLE_UNLOCKED();
  40. raw_notifier_chain_unregister(&dummycon_output_nh, nb);
  41. }
  42. static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos)
  43. {
  44. WARN_CONSOLE_UNLOCKED();
  45. dummycon_putc_called = true;
  46. raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
  47. }
  48. static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
  49. int count, int ypos, int xpos)
  50. {
  51. int i;
  52. if (!dummycon_putc_called) {
  53. /* Ignore erases */
  54. for (i = 0 ; i < count; i++) {
  55. if (s[i] != vc->vc_video_erase_char)
  56. break;
  57. }
  58. if (i == count)
  59. return;
  60. dummycon_putc_called = true;
  61. }
  62. raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
  63. }
  64. static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
  65. {
  66. /* Redraw, so that we get putc(s) for output done while blanked */
  67. return 1;
  68. }
  69. #else
  70. static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
  71. static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
  72. int count, int ypos, int xpos) { }
  73. static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
  74. {
  75. return 0;
  76. }
  77. #endif
  78. static const char *dummycon_startup(void)
  79. {
  80. return "dummy device";
  81. }
  82. static void dummycon_init(struct vc_data *vc, int init)
  83. {
  84. vc->vc_can_do_color = 1;
  85. if (init) {
  86. vc->vc_cols = DUMMY_COLUMNS;
  87. vc->vc_rows = DUMMY_ROWS;
  88. } else
  89. vc_resize(vc, DUMMY_COLUMNS, DUMMY_ROWS);
  90. }
  91. static void dummycon_deinit(struct vc_data *vc) { }
  92. static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height,
  93. int width) { }
  94. static void dummycon_cursor(struct vc_data *vc, int mode) { }
  95. static bool dummycon_scroll(struct vc_data *vc, unsigned int top,
  96. unsigned int bottom, enum con_scroll dir,
  97. unsigned int lines)
  98. {
  99. return false;
  100. }
  101. static int dummycon_switch(struct vc_data *vc)
  102. {
  103. return 0;
  104. }
  105. static int dummycon_font_set(struct vc_data *vc, struct console_font *font,
  106. unsigned int flags)
  107. {
  108. return 0;
  109. }
  110. static int dummycon_font_default(struct vc_data *vc,
  111. struct console_font *font, char *name)
  112. {
  113. return 0;
  114. }
  115. static int dummycon_font_copy(struct vc_data *vc, int con)
  116. {
  117. return 0;
  118. }
  119. /*
  120. * The console `switch' structure for the dummy console
  121. *
  122. * Most of the operations are dummies.
  123. */
  124. const struct consw dummy_con = {
  125. .owner = THIS_MODULE,
  126. .con_startup = dummycon_startup,
  127. .con_init = dummycon_init,
  128. .con_deinit = dummycon_deinit,
  129. .con_clear = dummycon_clear,
  130. .con_putc = dummycon_putc,
  131. .con_putcs = dummycon_putcs,
  132. .con_cursor = dummycon_cursor,
  133. .con_scroll = dummycon_scroll,
  134. .con_switch = dummycon_switch,
  135. .con_blank = dummycon_blank,
  136. .con_font_set = dummycon_font_set,
  137. .con_font_default = dummycon_font_default,
  138. .con_font_copy = dummycon_font_copy,
  139. };
  140. EXPORT_SYMBOL_GPL(dummy_con);