xref: /linux/drivers/video/console/dummycon.c (revision 5fc6c6f258b34fd0d2ff2a63b8a407a4dcbca750)
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 
9 #include <linux/types.h>
10 #include <linux/kdev_t.h>
11 #include <linux/console.h>
12 #include <linux/vt_kern.h>
13 #include <linux/screen_info.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
16 
17 /*
18  *  Dummy console driver
19  */
20 
21 #if defined(CONFIG_ARCH_FOOTBRIDGE) && defined(CONFIG_VGA_CONSOLE)
22 #include <asm/vga.h>
23 #define DUMMY_COLUMNS	vgacon_screen_info.orig_video_cols
24 #define DUMMY_ROWS	vgacon_screen_info.orig_video_lines
25 #else
26 /* set by Kconfig. Use 80x25 for 640x480 and 160x64 for 1280x1024 */
27 #define DUMMY_COLUMNS	CONFIG_DUMMY_CONSOLE_COLUMNS
28 #define DUMMY_ROWS	CONFIG_DUMMY_CONSOLE_ROWS
29 #endif
30 
31 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
32 /* These are both protected by the console_lock */
33 static RAW_NOTIFIER_HEAD(dummycon_output_nh);
34 static bool dummycon_putc_called;
35 
dummycon_register_output_notifier(struct notifier_block * nb)36 void dummycon_register_output_notifier(struct notifier_block *nb)
37 {
38 	WARN_CONSOLE_UNLOCKED();
39 
40 	raw_notifier_chain_register(&dummycon_output_nh, nb);
41 
42 	if (dummycon_putc_called)
43 		nb->notifier_call(nb, 0, NULL);
44 }
45 
dummycon_unregister_output_notifier(struct notifier_block * nb)46 void dummycon_unregister_output_notifier(struct notifier_block *nb)
47 {
48 	WARN_CONSOLE_UNLOCKED();
49 
50 	raw_notifier_chain_unregister(&dummycon_output_nh, nb);
51 }
52 
dummycon_putc(struct vc_data * vc,u16 c,unsigned int y,unsigned int x)53 static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y,
54                           unsigned int x)
55 {
56 	WARN_CONSOLE_UNLOCKED();
57 
58 	dummycon_putc_called = true;
59 	raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
60 }
61 
dummycon_putcs(struct vc_data * vc,const u16 * s,unsigned int count,unsigned int ypos,unsigned int xpos)62 static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
63 			   unsigned int ypos, unsigned int xpos)
64 {
65 	unsigned int i;
66 
67 	if (!dummycon_putc_called) {
68 		/* Ignore erases */
69 		for (i = 0 ; i < count; i++) {
70 			if (s[i] != vc->vc_video_erase_char)
71 				break;
72 		}
73 		if (i == count)
74 			return;
75 
76 		dummycon_putc_called = true;
77 	}
78 
79 	raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
80 }
81 
dummycon_blank(struct vc_data * vc,enum vesa_blank_mode blank,bool mode_switch)82 static bool dummycon_blank(struct vc_data *vc, enum vesa_blank_mode blank,
83 			   bool mode_switch)
84 {
85 	/* Redraw, so that we get putc(s) for output done while blanked */
86 	return true;
87 }
88 
dummycon_switch(struct vc_data * vc)89 static bool dummycon_switch(struct vc_data *vc)
90 {
91 	/*
92 	 * Redraw, so that we get putc(s) for output done while switched
93 	 * away. Informs deferred consoles to take over the display.
94 	 */
95 	return true;
96 }
97 #else
dummycon_putc(struct vc_data * vc,u16 c,unsigned int y,unsigned int x)98 static void dummycon_putc(struct vc_data *vc, u16 c, unsigned int y,
99 			  unsigned int x) { }
dummycon_putcs(struct vc_data * vc,const u16 * s,unsigned int count,unsigned int ypos,unsigned int xpos)100 static void dummycon_putcs(struct vc_data *vc, const u16 *s, unsigned int count,
101 			   unsigned int ypos, unsigned int xpos) { }
dummycon_blank(struct vc_data * vc,enum vesa_blank_mode blank,bool mode_switch)102 static bool dummycon_blank(struct vc_data *vc, enum vesa_blank_mode blank,
103 			   bool mode_switch)
104 {
105 	return false;
106 }
dummycon_switch(struct vc_data * vc)107 static bool dummycon_switch(struct vc_data *vc)
108 {
109 	return false;
110 }
111 #endif
112 
dummycon_startup(void)113 static const char *dummycon_startup(void)
114 {
115     return "dummy device";
116 }
117 
dummycon_init(struct vc_data * vc,bool init)118 static void dummycon_init(struct vc_data *vc, bool init)
119 {
120     vc->vc_can_do_color = 1;
121     if (init) {
122 	vc->vc_cols = DUMMY_COLUMNS;
123 	vc->vc_rows = DUMMY_ROWS;
124     } else
125 	vc_resize(vc, DUMMY_COLUMNS, DUMMY_ROWS);
126 }
127 
dummycon_deinit(struct vc_data * vc)128 static void dummycon_deinit(struct vc_data *vc) { }
dummycon_clear(struct vc_data * vc,unsigned int sy,unsigned int sx,unsigned int width)129 static void dummycon_clear(struct vc_data *vc, unsigned int sy, unsigned int sx,
130 			   unsigned int width) { }
dummycon_cursor(struct vc_data * vc,bool enable)131 static void dummycon_cursor(struct vc_data *vc, bool enable) { }
132 
dummycon_scroll(struct vc_data * vc,unsigned int top,unsigned int bottom,enum con_scroll dir,unsigned int lines)133 static bool dummycon_scroll(struct vc_data *vc, unsigned int top,
134 			    unsigned int bottom, enum con_scroll dir,
135 			    unsigned int lines)
136 {
137 	return false;
138 }
139 
140 /*
141  *  The console `switch' structure for the dummy console
142  *
143  *  Most of the operations are dummies.
144  */
145 
146 const struct consw dummy_con = {
147 	.owner =		THIS_MODULE,
148 	.con_startup =	dummycon_startup,
149 	.con_init =		dummycon_init,
150 	.con_deinit =	dummycon_deinit,
151 	.con_clear =	dummycon_clear,
152 	.con_putc =		dummycon_putc,
153 	.con_putcs =	dummycon_putcs,
154 	.con_cursor =	dummycon_cursor,
155 	.con_scroll =	dummycon_scroll,
156 	.con_switch =	dummycon_switch,
157 	.con_blank =	dummycon_blank,
158 };
159 EXPORT_SYMBOL_GPL(dummy_con);
160