Merge tag 'soc-fixes-6.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-block.git] / include / linux / console.h
CommitLineData
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>
6c4afa79 18#include <linux/rculist.h>
1da177e4 19#include <linux/types.h>
1da177e4
LT
20
21struct vc_data;
22struct console_font_op;
23struct console_font;
24struct module;
1b135431 25struct tty_struct;
83d83beb 26struct notifier_block;
1da177e4 27
d705ff38
JS
28enum con_scroll {
29 SM_UP,
30 SM_DOWN,
31};
32
b84ae3dc
JS
33enum vc_intensity;
34
97293de9
JS
35/**
36 * struct consw - callbacks for consoles
37 *
d705ff38
JS
38 * @con_scroll: move lines from @top to @bottom in direction @dir by @lines.
39 * Return true if no generic handling should be done.
40 * Invoked by csi_M and printing to the console.
709280da 41 * @con_set_palette: sets the palette of the console to @table (optional)
97293de9
JS
42 * @con_scrolldelta: the contents of the console should be scrolled by @lines.
43 * Invoked by user. (optional)
44 */
1da177e4
LT
45struct consw {
46 struct module *owner;
47 const char *(*con_startup)(void);
209f668c
KC
48 void (*con_init)(struct vc_data *vc, int init);
49 void (*con_deinit)(struct vc_data *vc);
50 void (*con_clear)(struct vc_data *vc, int sy, int sx, int height,
51 int width);
52 void (*con_putc)(struct vc_data *vc, int c, int ypos, int xpos);
53 void (*con_putcs)(struct vc_data *vc, const unsigned short *s,
54 int count, int ypos, int xpos);
55 void (*con_cursor)(struct vc_data *vc, int mode);
56 bool (*con_scroll)(struct vc_data *vc, unsigned int top,
d705ff38
JS
57 unsigned int bottom, enum con_scroll dir,
58 unsigned int lines);
209f668c
KC
59 int (*con_switch)(struct vc_data *vc);
60 int (*con_blank)(struct vc_data *vc, int blank, int mode_switch);
61 int (*con_font_set)(struct vc_data *vc, struct console_font *font,
62 unsigned int flags);
63 int (*con_font_get)(struct vc_data *vc, struct console_font *font);
64 int (*con_font_default)(struct vc_data *vc,
65 struct console_font *font, char *name);
209f668c
KC
66 int (*con_resize)(struct vc_data *vc, unsigned int width,
67 unsigned int height, unsigned int user);
68 void (*con_set_palette)(struct vc_data *vc,
709280da 69 const unsigned char *table);
209f668c
KC
70 void (*con_scrolldelta)(struct vc_data *vc, int lines);
71 int (*con_set_origin)(struct vc_data *vc);
72 void (*con_save_screen)(struct vc_data *vc);
b84ae3dc
JS
73 u8 (*con_build_attr)(struct vc_data *vc, u8 color,
74 enum vc_intensity intensity,
77bc14f2 75 bool blink, bool underline, bool reverse, bool italic);
209f668c 76 void (*con_invert_region)(struct vc_data *vc, u16 *p, int count);
d73568c4 77 u16 *(*con_screen_pos)(const struct vc_data *vc, int offset);
209f668c
KC
78 unsigned long (*con_getxy)(struct vc_data *vc, unsigned long position,
79 int *px, int *py);
bcd375f7
MS
80 /*
81 * Flush the video console driver's scrollback buffer
82 */
209f668c 83 void (*con_flush_scrollback)(struct vc_data *vc);
b45cfba4
JB
84 /*
85 * Prepare the console for the debugger. This includes, but is not
86 * limited to, unblanking the console, loading an appropriate
87 * palette, and allowing debugger generated output.
88 */
209f668c 89 int (*con_debug_enter)(struct vc_data *vc);
b45cfba4
JB
90 /*
91 * Restore the console to its pre-debug state as closely as possible.
92 */
209f668c 93 int (*con_debug_leave)(struct vc_data *vc);
1da177e4
LT
94};
95
96extern const struct consw *conswitchp;
97
98extern const struct consw dummy_con; /* dummy console buffer */
99extern const struct consw vga_con; /* VGA text console */
100extern const struct consw newport_con; /* SGI Newport console */
1da177e4 101
3e795de7 102int con_is_bound(const struct consw *csw);
e93a9a86 103int do_unregister_con_driver(const struct consw *csw);
50e244cc 104int do_take_over_console(const struct consw *sw, int first, int last, int deflt);
1da177e4 105void give_up_console(const struct consw *sw);
9261ec1a 106#ifdef CONFIG_HW_CONSOLE
b45cfba4
JB
107int con_debug_enter(struct vc_data *vc);
108int con_debug_leave(void);
9261ec1a 109#else
f2f0945e
AB
110static inline int con_debug_enter(struct vc_data *vc)
111{
112 return 0;
113}
114static inline int con_debug_leave(void)
115{
116 return 0;
117}
9261ec1a 118#endif
b45cfba4 119
1da177e4
LT
120/* cursor */
121#define CM_DRAW (1)
122#define CM_ERASE (2)
123#define CM_MOVE (3)
124
125/*
126 * The interface for a console, or any other device that wants to capture
127 * console messages (printer driver?)
128 *
129 * If a console driver is marked CON_BOOT then it will be auto-unregistered
130 * when the first real console is registered. This is for early-printk drivers.
131 */
132
133#define CON_PRINTBUFFER (1)
33225d7b 134#define CON_CONSDEV (2) /* Preferred console, /dev/console */
1da177e4
LT
135#define CON_ENABLED (4)
136#define CON_BOOT (8)
76a8ad29 137#define CON_ANYTIME (16) /* Safe to call when cpu is offline */
f7511d5f 138#define CON_BRL (32) /* Used for a braille device */
6fe29354 139#define CON_EXTENDED (64) /* Use the extended output format a la /dev/kmsg */
1da177e4 140
6ae9200f
AM
141struct console {
142 char name[16];
1da177e4
LT
143 void (*write)(struct console *, const char *, unsigned);
144 int (*read)(struct console *, char *, unsigned);
145 struct tty_driver *(*device)(struct console *, int *);
146 void (*unblank)(void);
147 int (*setup)(struct console *, char *);
ed31685c 148 int (*exit)(struct console *);
c7cef0a8 149 int (*match)(struct console *, char *name, int idx, char *options);
1da177e4
LT
150 short flags;
151 short index;
152 int cflag;
027b5717
PR
153 uint ispeed;
154 uint ospeed;
a699449b
JO
155 u64 seq;
156 unsigned long dropped;
1da177e4 157 void *data;
d9a4af56 158 struct hlist_node node;
1da177e4
LT
159};
160
4dc64682
JO
161#ifdef CONFIG_LOCKDEP
162extern void lockdep_assert_console_list_lock_held(void);
163#else
164static inline void lockdep_assert_console_list_lock_held(void)
165{
166}
167#endif
168
6c4afa79
JO
169#ifdef CONFIG_DEBUG_LOCK_ALLOC
170extern bool console_srcu_read_lock_is_held(void);
171#else
172static inline bool console_srcu_read_lock_is_held(void)
173{
174 return 1;
175}
176#endif
177
178extern int console_srcu_read_lock(void);
179extern void console_srcu_read_unlock(int cookie);
180
4dc64682
JO
181extern void console_list_lock(void) __acquires(console_mutex);
182extern void console_list_unlock(void) __releases(console_mutex);
183
d9a4af56
TG
184extern struct hlist_head console_list;
185
100bdef2
JO
186/**
187 * console_srcu_read_flags - Locklessly read the console flags
188 * @con: struct console pointer of console to read flags from
189 *
190 * This function provides the necessary READ_ONCE() and data_race()
191 * notation for locklessly reading the console flags. The READ_ONCE()
192 * in this function matches the WRITE_ONCE() when @flags are modified
193 * for registered consoles with console_srcu_write_flags().
194 *
195 * Only use this function to read console flags when locklessly
196 * iterating the console list via srcu.
197 *
198 * Context: Any context.
199 */
200static inline short console_srcu_read_flags(const struct console *con)
201{
202 WARN_ON_ONCE(!console_srcu_read_lock_is_held());
203
204 /*
205 * Locklessly reading console->flags provides a consistent
206 * read value because there is at most one CPU modifying
207 * console->flags and that CPU is using only read-modify-write
208 * operations to do so.
209 */
210 return data_race(READ_ONCE(con->flags));
211}
212
213/**
214 * console_srcu_write_flags - Write flags for a registered console
215 * @con: struct console pointer of console to write flags to
216 * @flags: new flags value to write
217 *
218 * Only use this function to write flags for registered consoles. It
219 * requires holding the console_list_lock.
220 *
221 * Context: Any context.
222 */
223static inline void console_srcu_write_flags(struct console *con, short flags)
224{
225 lockdep_assert_console_list_lock_held();
226
227 /* This matches the READ_ONCE() in console_srcu_read_flags(). */
228 WRITE_ONCE(con->flags, flags);
229}
230
1fd4224a
JO
231/* Variant of console_is_registered() when the console_list_lock is held. */
232static inline bool console_is_registered_locked(const struct console *con)
233{
234 lockdep_assert_console_list_lock_held();
235 return !hlist_unhashed(&con->node);
236}
237
238/*
239 * console_is_registered - Check if the console is registered
240 * @con: struct console pointer of console to check
241 *
242 * Context: Process context. May sleep while acquiring console list lock.
243 * Return: true if the console is in the console list, otherwise false.
244 *
245 * If false is returned for a console that was previously registered, it
246 * can be assumed that the console's unregistration is fully completed,
247 * including the exit() callback after console list removal.
248 */
249static inline bool console_is_registered(const struct console *con)
250{
251 bool ret;
252
253 console_list_lock();
254 ret = console_is_registered_locked(con);
255 console_list_unlock();
256 return ret;
257}
258
6c4afa79
JO
259/**
260 * for_each_console_srcu() - Iterator over registered consoles
261 * @con: struct console pointer used as loop cursor
262 *
263 * Although SRCU guarantees the console list will be consistent, the
264 * struct console fields may be updated by other CPUs while iterating.
265 *
266 * Requires console_srcu_read_lock to be held. Can be invoked from
267 * any context.
268 */
269#define for_each_console_srcu(con) \
270 hlist_for_each_entry_srcu(con, &console_list, node, \
271 console_srcu_read_lock_is_held())
272
4dc64682
JO
273/**
274 * for_each_console() - Iterator over registered consoles
275 * @con: struct console pointer used as loop cursor
276 *
277 * The console list and the console->flags are immutable while iterating.
278 *
279 * Requires console_list_lock to be held.
a75d946f 280 */
4dc64682
JO
281#define for_each_console(con) \
282 lockdep_assert_console_list_lock_held(); \
d9a4af56 283 hlist_for_each_entry(con, &console_list, node)
a75d946f 284
9e124fe1 285extern int console_set_on_cmdline;
d0380e6c 286extern struct console *early_console;
9e124fe1 287
de6da1e8
FT
288enum con_flush_mode {
289 CONSOLE_FLUSH_PENDING,
290 CONSOLE_REPLAY_ALL,
291};
292
1da177e4 293extern int add_preferred_console(char *name, int idx, char *options);
6f883675 294extern void console_force_preferred_locked(struct console *con);
1da177e4
LT
295extern void register_console(struct console *);
296extern int unregister_console(struct console *);
ac751efa
TH
297extern void console_lock(void);
298extern int console_trylock(void);
299extern void console_unlock(void);
1da177e4
LT
300extern void console_conditional_schedule(void);
301extern void console_unblank(void);
de6da1e8 302extern void console_flush_on_panic(enum con_flush_mode mode);
1da177e4
LT
303extern struct tty_driver *console_device(int *);
304extern void console_stop(struct console *);
305extern void console_start(struct console *);
306extern int is_console_locked(void);
f7511d5f
ST
307extern int braille_register_console(struct console *, int index,
308 char *console_options, char *braille_options);
309extern int braille_unregister_console(struct console *);
4f73bc4d 310#ifdef CONFIG_TTY
fbc92a34 311extern void console_sysfs_notify(void);
4f73bc4d
JM
312#else
313static inline void console_sysfs_notify(void)
314{ }
315#endif
90ab5ee9 316extern bool console_suspend_enabled;
8f4ce8c3 317
557240b4
LT
318/* Suspend and resume console messages over PM events */
319extern void suspend_console(void);
320extern void resume_console(void);
321
3cb340ec 322int mda_console_init(void);
3cb340ec 323
4995f8ef
KS
324void vcs_make_sysfs(int index);
325void vcs_remove_sysfs(int index);
1b135431 326
1da177e4 327/* Some debug stub to catch some of the obvious races in the VT code */
56e6c104
TZ
328#define WARN_CONSOLE_UNLOCKED() \
329 WARN_ON(!atomic_read(&ignore_console_lock_warning) && \
330 !is_console_locked() && !oops_in_progress)
331/*
332 * Increment ignore_console_lock_warning if you need to quiet
333 * WARN_CONSOLE_UNLOCKED() for debugging purposes.
334 */
335extern atomic_t ignore_console_lock_warning;
1da177e4
LT
336
337/* VESA Blanking Levels */
338#define VESA_NO_BLANKING 0
339#define VESA_VSYNC_SUSPEND 1
340#define VESA_HSYNC_SUSPEND 2
341#define VESA_POWERDOWN 3
342
0c688614
NP
343extern void console_init(void);
344
83d83beb
HG
345/* For deferred console takeover */
346void dummycon_register_output_notifier(struct notifier_block *nb);
347void dummycon_unregister_output_notifier(struct notifier_block *nb);
348
1da177e4 349#endif /* _LINUX_CONSOLE_H */