Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/include/linux/console.h | |
3 | * | |
4 | * Copyright (C) 1993 Hamish Macdonald | |
5 | * | |
6 | * This file is subject to the terms and conditions of the GNU General Public | |
7 | * License. See the file COPYING in the main directory of this archive | |
8 | * for more details. | |
9 | * | |
10 | * Changed: | |
11 | * 10-Mar-94: Arno Griffioen: Conversion for vt100 emulator port from PC LINUX | |
12 | */ | |
13 | ||
14 | #ifndef _LINUX_CONSOLE_H_ | |
15 | #define _LINUX_CONSOLE_H_ 1 | |
16 | ||
56e6c104 | 17 | #include <linux/atomic.h> |
717a5651 | 18 | #include <linux/bits.h> |
6c4afa79 | 19 | #include <linux/rculist.h> |
1da177e4 | 20 | #include <linux/types.h> |
1da177e4 LT |
21 | |
22 | struct vc_data; | |
23 | struct console_font_op; | |
24 | struct console_font; | |
25 | struct module; | |
1b135431 | 26 | struct tty_struct; |
83d83beb | 27 | struct notifier_block; |
1da177e4 | 28 | |
d705ff38 JS |
29 | enum con_scroll { |
30 | SM_UP, | |
31 | SM_DOWN, | |
32 | }; | |
33 | ||
b84ae3dc JS |
34 | enum vc_intensity; |
35 | ||
97293de9 JS |
36 | /** |
37 | * struct consw - callbacks for consoles | |
38 | * | |
d705ff38 JS |
39 | * @con_scroll: move lines from @top to @bottom in direction @dir by @lines. |
40 | * Return true if no generic handling should be done. | |
41 | * Invoked by csi_M and printing to the console. | |
709280da | 42 | * @con_set_palette: sets the palette of the console to @table (optional) |
97293de9 JS |
43 | * @con_scrolldelta: the contents of the console should be scrolled by @lines. |
44 | * Invoked by user. (optional) | |
45 | */ | |
1da177e4 LT |
46 | struct consw { |
47 | struct module *owner; | |
48 | const char *(*con_startup)(void); | |
209f668c KC |
49 | void (*con_init)(struct vc_data *vc, int init); |
50 | void (*con_deinit)(struct vc_data *vc); | |
51 | void (*con_clear)(struct vc_data *vc, int sy, int sx, int height, | |
52 | int width); | |
53 | void (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos); | |
54 | void (*con_putcs)(struct vc_data *vc, const unsigned short *s, | |
55 | int count, int ypos, int xpos); | |
56 | void (*con_cursor)(struct vc_data *vc, int mode); | |
57 | bool (*con_scroll)(struct vc_data *vc, unsigned int top, | |
d705ff38 JS |
58 | unsigned int bottom, enum con_scroll dir, |
59 | unsigned int lines); | |
209f668c KC |
60 | int (*con_switch)(struct vc_data *vc); |
61 | int (*con_blank)(struct vc_data *vc, int blank, int mode_switch); | |
62 | int (*con_font_set)(struct vc_data *vc, struct console_font *font, | |
ffc1e089 ST |
63 | unsigned int vpitch, unsigned int flags); |
64 | int (*con_font_get)(struct vc_data *vc, struct console_font *font, | |
65 | unsigned int vpitch); | |
209f668c KC |
66 | int (*con_font_default)(struct vc_data *vc, |
67 | struct console_font *font, char *name); | |
209f668c KC |
68 | int (*con_resize)(struct vc_data *vc, unsigned int width, |
69 | unsigned int height, unsigned int user); | |
70 | void (*con_set_palette)(struct vc_data *vc, | |
709280da | 71 | const unsigned char *table); |
209f668c KC |
72 | void (*con_scrolldelta)(struct vc_data *vc, int lines); |
73 | int (*con_set_origin)(struct vc_data *vc); | |
74 | void (*con_save_screen)(struct vc_data *vc); | |
b84ae3dc JS |
75 | u8 (*con_build_attr)(struct vc_data *vc, u8 color, |
76 | enum vc_intensity intensity, | |
77bc14f2 | 77 | bool blink, bool underline, bool reverse, bool italic); |
209f668c | 78 | void (*con_invert_region)(struct vc_data *vc, u16 *p, int count); |
d73568c4 | 79 | u16 *(*con_screen_pos)(const struct vc_data *vc, int offset); |
209f668c KC |
80 | unsigned long (*con_getxy)(struct vc_data *vc, unsigned long position, |
81 | int *px, int *py); | |
bcd375f7 MS |
82 | /* |
83 | * Flush the video console driver's scrollback buffer | |
84 | */ | |
209f668c | 85 | void (*con_flush_scrollback)(struct vc_data *vc); |
b45cfba4 JB |
86 | /* |
87 | * Prepare the console for the debugger. This includes, but is not | |
88 | * limited to, unblanking the console, loading an appropriate | |
89 | * palette, and allowing debugger generated output. | |
90 | */ | |
209f668c | 91 | int (*con_debug_enter)(struct vc_data *vc); |
b45cfba4 JB |
92 | /* |
93 | * Restore the console to its pre-debug state as closely as possible. | |
94 | */ | |
209f668c | 95 | int (*con_debug_leave)(struct vc_data *vc); |
1da177e4 LT |
96 | }; |
97 | ||
98 | extern const struct consw *conswitchp; | |
99 | ||
100 | extern const struct consw dummy_con; /* dummy console buffer */ | |
101 | extern const struct consw vga_con; /* VGA text console */ | |
102 | extern const struct consw newport_con; /* SGI Newport console */ | |
1da177e4 | 103 | |
3e795de7 | 104 | int con_is_bound(const struct consw *csw); |
e93a9a86 | 105 | int do_unregister_con_driver(const struct consw *csw); |
50e244cc | 106 | int do_take_over_console(const struct consw *sw, int first, int last, int deflt); |
1da177e4 | 107 | void give_up_console(const struct consw *sw); |
9261ec1a | 108 | #ifdef CONFIG_HW_CONSOLE |
b45cfba4 JB |
109 | int con_debug_enter(struct vc_data *vc); |
110 | int con_debug_leave(void); | |
9261ec1a | 111 | #else |
f2f0945e AB |
112 | static inline int con_debug_enter(struct vc_data *vc) |
113 | { | |
114 | return 0; | |
115 | } | |
116 | static inline int con_debug_leave(void) | |
117 | { | |
118 | return 0; | |
119 | } | |
9261ec1a | 120 | #endif |
b45cfba4 | 121 | |
1da177e4 LT |
122 | /* cursor */ |
123 | #define CM_DRAW (1) | |
124 | #define CM_ERASE (2) | |
125 | #define CM_MOVE (3) | |
126 | ||
127 | /* | |
128 | * The interface for a console, or any other device that wants to capture | |
129 | * console messages (printer driver?) | |
1da177e4 LT |
130 | */ |
131 | ||
717a5651 TG |
132 | /** |
133 | * cons_flags - General console flags | |
134 | * @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate | |
135 | * output of messages that were already shown by boot | |
136 | * consoles or read by userspace via syslog() syscall. | |
137 | * @CON_CONSDEV: Indicates that the console driver is backing | |
138 | * /dev/console. | |
139 | * @CON_ENABLED: Indicates if a console is allowed to print records. If | |
140 | * false, the console also will not advance to later | |
141 | * records. | |
142 | * @CON_BOOT: Marks the console driver as early console driver which | |
143 | * is used during boot before the real driver becomes | |
144 | * available. It will be automatically unregistered | |
145 | * when the real console driver is registered unless | |
146 | * "keep_bootcon" parameter is used. | |
147 | * @CON_ANYTIME: A misnomed historical flag which tells the core code | |
148 | * that the legacy @console::write callback can be invoked | |
149 | * on a CPU which is marked OFFLINE. That is misleading as | |
150 | * it suggests that there is no contextual limit for | |
151 | * invoking the callback. The original motivation was | |
152 | * readiness of the per-CPU areas. | |
153 | * @CON_BRL: Indicates a braille device which is exempt from | |
154 | * receiving the printk spam for obvious reasons. | |
155 | * @CON_EXTENDED: The console supports the extended output format of | |
156 | * /dev/kmesg which requires a larger output buffer. | |
157 | */ | |
158 | enum cons_flags { | |
159 | CON_PRINTBUFFER = BIT(0), | |
160 | CON_CONSDEV = BIT(1), | |
161 | CON_ENABLED = BIT(2), | |
162 | CON_BOOT = BIT(3), | |
163 | CON_ANYTIME = BIT(4), | |
164 | CON_BRL = BIT(5), | |
165 | CON_EXTENDED = BIT(6), | |
166 | }; | |
1da177e4 | 167 | |
02b2396d TG |
168 | /** |
169 | * struct console - The console descriptor structure | |
170 | * @name: The name of the console driver | |
171 | * @write: Write callback to output messages (Optional) | |
172 | * @read: Read callback for console input (Optional) | |
173 | * @device: The underlying TTY device driver (Optional) | |
174 | * @unblank: Callback to unblank the console (Optional) | |
175 | * @setup: Callback for initializing the console (Optional) | |
176 | * @exit: Callback for teardown of the console (Optional) | |
177 | * @match: Callback for matching a console (Optional) | |
178 | * @flags: Console flags. See enum cons_flags | |
179 | * @index: Console index, e.g. port number | |
180 | * @cflag: TTY control mode flags | |
181 | * @ispeed: TTY input speed | |
182 | * @ospeed: TTY output speed | |
183 | * @seq: Sequence number of the next ringbuffer record to print | |
184 | * @dropped: Number of unreported dropped ringbuffer records | |
185 | * @data: Driver private data | |
186 | * @node: hlist node for the console list | |
187 | */ | |
6ae9200f | 188 | struct console { |
02b2396d TG |
189 | char name[16]; |
190 | void (*write)(struct console *co, const char *s, unsigned int count); | |
191 | int (*read)(struct console *co, char *s, unsigned int count); | |
192 | struct tty_driver *(*device)(struct console *co, int *index); | |
193 | void (*unblank)(void); | |
194 | int (*setup)(struct console *co, char *options); | |
195 | int (*exit)(struct console *co); | |
196 | int (*match)(struct console *co, char *name, int idx, char *options); | |
197 | short flags; | |
198 | short index; | |
199 | int cflag; | |
200 | uint ispeed; | |
201 | uint ospeed; | |
202 | u64 seq; | |
203 | unsigned long dropped; | |
204 | void *data; | |
205 | struct hlist_node node; | |
1da177e4 LT |
206 | }; |
207 | ||
4dc64682 JO |
208 | #ifdef CONFIG_LOCKDEP |
209 | extern void lockdep_assert_console_list_lock_held(void); | |
210 | #else | |
211 | static inline void lockdep_assert_console_list_lock_held(void) | |
212 | { | |
213 | } | |
214 | #endif | |
215 | ||
6c4afa79 JO |
216 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
217 | extern bool console_srcu_read_lock_is_held(void); | |
218 | #else | |
219 | static inline bool console_srcu_read_lock_is_held(void) | |
220 | { | |
221 | return 1; | |
222 | } | |
223 | #endif | |
224 | ||
225 | extern int console_srcu_read_lock(void); | |
226 | extern void console_srcu_read_unlock(int cookie); | |
227 | ||
4dc64682 JO |
228 | extern void console_list_lock(void) __acquires(console_mutex); |
229 | extern void console_list_unlock(void) __releases(console_mutex); | |
230 | ||
d9a4af56 TG |
231 | extern struct hlist_head console_list; |
232 | ||
100bdef2 JO |
233 | /** |
234 | * console_srcu_read_flags - Locklessly read the console flags | |
235 | * @con: struct console pointer of console to read flags from | |
236 | * | |
237 | * This function provides the necessary READ_ONCE() and data_race() | |
238 | * notation for locklessly reading the console flags. The READ_ONCE() | |
239 | * in this function matches the WRITE_ONCE() when @flags are modified | |
240 | * for registered consoles with console_srcu_write_flags(). | |
241 | * | |
242 | * Only use this function to read console flags when locklessly | |
243 | * iterating the console list via srcu. | |
244 | * | |
245 | * Context: Any context. | |
246 | */ | |
247 | static inline short console_srcu_read_flags(const struct console *con) | |
248 | { | |
249 | WARN_ON_ONCE(!console_srcu_read_lock_is_held()); | |
250 | ||
251 | /* | |
252 | * Locklessly reading console->flags provides a consistent | |
253 | * read value because there is at most one CPU modifying | |
254 | * console->flags and that CPU is using only read-modify-write | |
255 | * operations to do so. | |
256 | */ | |
257 | return data_race(READ_ONCE(con->flags)); | |
258 | } | |
259 | ||
260 | /** | |
261 | * console_srcu_write_flags - Write flags for a registered console | |
262 | * @con: struct console pointer of console to write flags to | |
263 | * @flags: new flags value to write | |
264 | * | |
265 | * Only use this function to write flags for registered consoles. It | |
266 | * requires holding the console_list_lock. | |
267 | * | |
268 | * Context: Any context. | |
269 | */ | |
270 | static inline void console_srcu_write_flags(struct console *con, short flags) | |
271 | { | |
272 | lockdep_assert_console_list_lock_held(); | |
273 | ||
274 | /* This matches the READ_ONCE() in console_srcu_read_flags(). */ | |
275 | WRITE_ONCE(con->flags, flags); | |
276 | } | |
277 | ||
1fd4224a JO |
278 | /* Variant of console_is_registered() when the console_list_lock is held. */ |
279 | static inline bool console_is_registered_locked(const struct console *con) | |
280 | { | |
281 | lockdep_assert_console_list_lock_held(); | |
282 | return !hlist_unhashed(&con->node); | |
283 | } | |
284 | ||
285 | /* | |
286 | * console_is_registered - Check if the console is registered | |
287 | * @con: struct console pointer of console to check | |
288 | * | |
289 | * Context: Process context. May sleep while acquiring console list lock. | |
290 | * Return: true if the console is in the console list, otherwise false. | |
291 | * | |
292 | * If false is returned for a console that was previously registered, it | |
293 | * can be assumed that the console's unregistration is fully completed, | |
294 | * including the exit() callback after console list removal. | |
295 | */ | |
296 | static inline bool console_is_registered(const struct console *con) | |
297 | { | |
298 | bool ret; | |
299 | ||
300 | console_list_lock(); | |
301 | ret = console_is_registered_locked(con); | |
302 | console_list_unlock(); | |
303 | return ret; | |
304 | } | |
305 | ||
6c4afa79 JO |
306 | /** |
307 | * for_each_console_srcu() - Iterator over registered consoles | |
308 | * @con: struct console pointer used as loop cursor | |
309 | * | |
310 | * Although SRCU guarantees the console list will be consistent, the | |
311 | * struct console fields may be updated by other CPUs while iterating. | |
312 | * | |
313 | * Requires console_srcu_read_lock to be held. Can be invoked from | |
314 | * any context. | |
315 | */ | |
316 | #define for_each_console_srcu(con) \ | |
317 | hlist_for_each_entry_srcu(con, &console_list, node, \ | |
318 | console_srcu_read_lock_is_held()) | |
319 | ||
4dc64682 JO |
320 | /** |
321 | * for_each_console() - Iterator over registered consoles | |
322 | * @con: struct console pointer used as loop cursor | |
323 | * | |
324 | * The console list and the console->flags are immutable while iterating. | |
325 | * | |
326 | * Requires console_list_lock to be held. | |
a75d946f | 327 | */ |
4dc64682 JO |
328 | #define for_each_console(con) \ |
329 | lockdep_assert_console_list_lock_held(); \ | |
d9a4af56 | 330 | hlist_for_each_entry(con, &console_list, node) |
a75d946f | 331 | |
9e124fe1 | 332 | extern int console_set_on_cmdline; |
d0380e6c | 333 | extern struct console *early_console; |
9e124fe1 | 334 | |
de6da1e8 FT |
335 | enum con_flush_mode { |
336 | CONSOLE_FLUSH_PENDING, | |
337 | CONSOLE_REPLAY_ALL, | |
338 | }; | |
339 | ||
1da177e4 | 340 | extern int add_preferred_console(char *name, int idx, char *options); |
6f883675 | 341 | extern void console_force_preferred_locked(struct console *con); |
1da177e4 LT |
342 | extern void register_console(struct console *); |
343 | extern int unregister_console(struct console *); | |
ac751efa TH |
344 | extern void console_lock(void); |
345 | extern int console_trylock(void); | |
346 | extern void console_unlock(void); | |
1da177e4 LT |
347 | extern void console_conditional_schedule(void); |
348 | extern void console_unblank(void); | |
de6da1e8 | 349 | extern void console_flush_on_panic(enum con_flush_mode mode); |
1da177e4 LT |
350 | extern struct tty_driver *console_device(int *); |
351 | extern void console_stop(struct console *); | |
352 | extern void console_start(struct console *); | |
353 | extern int is_console_locked(void); | |
f7511d5f ST |
354 | extern int braille_register_console(struct console *, int index, |
355 | char *console_options, char *braille_options); | |
356 | extern int braille_unregister_console(struct console *); | |
4f73bc4d | 357 | #ifdef CONFIG_TTY |
fbc92a34 | 358 | extern void console_sysfs_notify(void); |
4f73bc4d JM |
359 | #else |
360 | static inline void console_sysfs_notify(void) | |
361 | { } | |
362 | #endif | |
90ab5ee9 | 363 | extern bool console_suspend_enabled; |
8f4ce8c3 | 364 | |
557240b4 LT |
365 | /* Suspend and resume console messages over PM events */ |
366 | extern void suspend_console(void); | |
367 | extern void resume_console(void); | |
368 | ||
3cb340ec | 369 | int mda_console_init(void); |
3cb340ec | 370 | |
4995f8ef KS |
371 | void vcs_make_sysfs(int index); |
372 | void vcs_remove_sysfs(int index); | |
1b135431 | 373 | |
1da177e4 | 374 | /* Some debug stub to catch some of the obvious races in the VT code */ |
56e6c104 TZ |
375 | #define WARN_CONSOLE_UNLOCKED() \ |
376 | WARN_ON(!atomic_read(&ignore_console_lock_warning) && \ | |
377 | !is_console_locked() && !oops_in_progress) | |
378 | /* | |
379 | * Increment ignore_console_lock_warning if you need to quiet | |
380 | * WARN_CONSOLE_UNLOCKED() for debugging purposes. | |
381 | */ | |
382 | extern atomic_t ignore_console_lock_warning; | |
1da177e4 LT |
383 | |
384 | /* VESA Blanking Levels */ | |
385 | #define VESA_NO_BLANKING 0 | |
386 | #define VESA_VSYNC_SUSPEND 1 | |
387 | #define VESA_HSYNC_SUSPEND 2 | |
388 | #define VESA_POWERDOWN 3 | |
389 | ||
0c688614 NP |
390 | extern void console_init(void); |
391 | ||
83d83beb HG |
392 | /* For deferred console takeover */ |
393 | void dummycon_register_output_notifier(struct notifier_block *nb); | |
394 | void dummycon_unregister_output_notifier(struct notifier_block *nb); | |
395 | ||
1da177e4 | 396 | #endif /* _LINUX_CONSOLE_H */ |