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