xref: /linux-6.15/include/linux/console_struct.h (revision dbee4cff)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * console_struct.h
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Data structure describing single virtual console except for data
61da177e4SLinus Torvalds  * used by vt.c.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Fields marked with [#] must be set by the low-level driver.
91da177e4SLinus Torvalds  * Fields marked with [!] can be changed by the low-level driver
101da177e4SLinus Torvalds  * to achieve effects such as fast scrolling by changing the origin.
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds 
13217397d7SRobert P. J. Day #ifndef _LINUX_CONSOLE_STRUCT_H
14217397d7SRobert P. J. Day #define _LINUX_CONSOLE_STRUCT_H
15217397d7SRobert P. J. Day 
16a8f340e3SJon Smirl #include <linux/wait.h>
17e07dea98SAntonino A. Daplas #include <linux/vt.h>
188b6312f4SEric W. Biederman #include <linux/workqueue.h>
19e07dea98SAntonino A. Daplas 
20e4bdab70STakashi Iwai struct uni_pagedir;
21d8ae7242SNicolas Pitre struct uni_screen;
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #define NPAR 16
24*dbee4cffSJiri Slaby #define VC_TABSTOPS_COUNT	256U
251da177e4SLinus Torvalds 
26b84ae3dcSJiri Slaby enum vc_intensity {
27b84ae3dcSJiri Slaby 	VCI_HALF_BRIGHT,
28b84ae3dcSJiri Slaby 	VCI_NORMAL,
29b84ae3dcSJiri Slaby 	VCI_BOLD,
30b84ae3dcSJiri Slaby 	VCI_MASK = 0x3,
31b84ae3dcSJiri Slaby };
32b84ae3dcSJiri Slaby 
3328bc24fcSJiri Slaby /**
3428bc24fcSJiri Slaby  * struct vc_state -- state of a VC
3528bc24fcSJiri Slaby  * @x: cursor's x-position
3628bc24fcSJiri Slaby  * @y: cursor's y-position
3728bc24fcSJiri Slaby  * @color: foreground & background colors
38b70ec4d9SJiri Slaby  * @Gx_charset: what's G0/G1 slot set to (like GRAF_MAP, LAT1_MAP)
3928bc24fcSJiri Slaby  * @charset: what character set to use (0=G0 or 1=G1)
40b84ae3dcSJiri Slaby  * @intensity: see enum vc_intensity for values
4128bc24fcSJiri Slaby  * @reverse: reversed foreground/background colors
4228bc24fcSJiri Slaby  *
4328bc24fcSJiri Slaby  * These members are defined separately from struct vc_data as we save &
4428bc24fcSJiri Slaby  * restore them at times.
4528bc24fcSJiri Slaby  */
4628bc24fcSJiri Slaby struct vc_state {
4728bc24fcSJiri Slaby 	unsigned int	x, y;
4828bc24fcSJiri Slaby 
4928bc24fcSJiri Slaby 	unsigned char	color;
5028bc24fcSJiri Slaby 
51b70ec4d9SJiri Slaby 	unsigned char	Gx_charset[2];
5228bc24fcSJiri Slaby 	unsigned int	charset		: 1;
5328bc24fcSJiri Slaby 
5428bc24fcSJiri Slaby 	/* attribute flags */
55b84ae3dcSJiri Slaby 	enum vc_intensity intensity;
5677bc14f2SJiri Slaby 	bool		italic;
5777bc14f2SJiri Slaby 	bool		underline;
5877bc14f2SJiri Slaby 	bool		blink;
5977bc14f2SJiri Slaby 	bool		reverse;
6028bc24fcSJiri Slaby };
6128bc24fcSJiri Slaby 
62a4bedd01SJiri Slaby /*
63a4bedd01SJiri Slaby  * Example: vc_data of a console that was scrolled 3 lines down.
64a4bedd01SJiri Slaby  *
65a4bedd01SJiri Slaby  *                              Console buffer
66a4bedd01SJiri Slaby  * vc_screenbuf ---------> +----------------------+-.
67a4bedd01SJiri Slaby  *                         | initializing W       |  \
68a4bedd01SJiri Slaby  *                         | initializing X       |   |
69a4bedd01SJiri Slaby  *                         | initializing Y       |    > scroll-back area
70a4bedd01SJiri Slaby  *                         | initializing Z       |   |
71a4bedd01SJiri Slaby  *                         |                      |  /
72a4bedd01SJiri Slaby  * vc_visible_origin ---> ^+----------------------+-:
73a4bedd01SJiri Slaby  * (changes by scroll)    || Welcome to linux     |  \
74a4bedd01SJiri Slaby  *                        ||                      |   |
75a4bedd01SJiri Slaby  *           vc_rows --->< | login: root          |   |  visible on console
76a4bedd01SJiri Slaby  *                        || password:            |    > (vc_screenbuf_size is
77a4bedd01SJiri Slaby  * vc_origin -----------> ||                      |   |   vc_size_row * vc_rows)
78a4bedd01SJiri Slaby  * (start when no scroll) || Last login: 12:28    |  /
79a4bedd01SJiri Slaby  *                        v+----------------------+-:
80a4bedd01SJiri Slaby  *                         | Have a lot of fun... |  \
81a4bedd01SJiri Slaby  * vc_pos -----------------|--------v             |   > scroll-front area
82a4bedd01SJiri Slaby  *                         | ~ # cat_             |  /
83a4bedd01SJiri Slaby  * vc_scr_end -----------> +----------------------+-:
84a4bedd01SJiri Slaby  * (vc_origin +            |                      |  \ EMPTY, to be filled by
85a4bedd01SJiri Slaby  *  vc_screenbuf_size)     |                      |  / vc_video_erase_char
86a4bedd01SJiri Slaby  *                         +----------------------+-'
87a4bedd01SJiri Slaby  *                         <---- 2 * vc_cols ----->
88a4bedd01SJiri Slaby  *                         <---- vc_size_row ----->
89a4bedd01SJiri Slaby  *
90a4bedd01SJiri Slaby  * Note that every character in the console buffer is accompanied with an
91a4bedd01SJiri Slaby  * attribute in the buffer right after the character. This is not depicted
92a4bedd01SJiri Slaby  * in the figure.
93a4bedd01SJiri Slaby  */
941da177e4SLinus Torvalds struct vc_data {
95ff917ba4SAlan Cox 	struct tty_port port;			/* Upper level data */
96ff917ba4SAlan Cox 
9728bc24fcSJiri Slaby 	struct vc_state state, saved_state;
9828bc24fcSJiri Slaby 
991da177e4SLinus Torvalds 	unsigned short	vc_num;			/* Console number */
1001da177e4SLinus Torvalds 	unsigned int	vc_cols;		/* [#] Console size */
1011da177e4SLinus Torvalds 	unsigned int	vc_rows;
1021da177e4SLinus Torvalds 	unsigned int	vc_size_row;		/* Bytes per row */
1031da177e4SLinus Torvalds 	unsigned int	vc_scan_lines;		/* # of scan lines */
1041da177e4SLinus Torvalds 	unsigned long	vc_origin;		/* [!] Start of real screen */
1051da177e4SLinus Torvalds 	unsigned long	vc_scr_end;		/* [!] End of real screen */
1061da177e4SLinus Torvalds 	unsigned long	vc_visible_origin;	/* [!] Top of visible window */
1071da177e4SLinus Torvalds 	unsigned int	vc_top, vc_bottom;	/* Scrolling region */
1081da177e4SLinus Torvalds 	const struct consw *vc_sw;
1091da177e4SLinus Torvalds 	unsigned short	*vc_screenbuf;		/* In-memory character/attribute buffer */
1101da177e4SLinus Torvalds 	unsigned int	vc_screenbuf_size;
1111da177e4SLinus Torvalds 	unsigned char	vc_mode;		/* KD_TEXT, ... */
1121da177e4SLinus Torvalds 	/* attributes for all characters on screen */
1131da177e4SLinus Torvalds 	unsigned char	vc_attr;		/* Current attributes */
1141da177e4SLinus Torvalds 	unsigned char	vc_def_color;		/* Default colors */
1151da177e4SLinus Torvalds 	unsigned char	vc_ulcolor;		/* Color for underline mode */
116fa6ce9abSJan Engelhardt 	unsigned char   vc_itcolor;
1171da177e4SLinus Torvalds 	unsigned char	vc_halfcolor;		/* Color for half intensity mode */
1181da177e4SLinus Torvalds 	/* cursor */
1191da177e4SLinus Torvalds 	unsigned int	vc_cursor_type;
1201da177e4SLinus Torvalds 	unsigned short	vc_complement_mask;	/* [#] Xor mask for mouse pointer */
1211da177e4SLinus Torvalds 	unsigned short	vc_s_complement_mask;	/* Saved mouse pointer mask */
1221da177e4SLinus Torvalds 	unsigned long	vc_pos;			/* Cursor address */
1231da177e4SLinus Torvalds 	/* fonts */
1241da177e4SLinus Torvalds 	unsigned short	vc_hi_font_mask;	/* [#] Attribute set for upper 256 chars of font or 0 if not supported */
1251da177e4SLinus Torvalds 	struct console_font vc_font;		/* Current VC font set */
1261da177e4SLinus Torvalds 	unsigned short	vc_video_erase_char;	/* Background erase character */
1271da177e4SLinus Torvalds 	/* VT terminal data */
1281da177e4SLinus Torvalds 	unsigned int	vc_state;		/* Escape sequence parser state */
1291da177e4SLinus Torvalds 	unsigned int	vc_npar,vc_par[NPAR];	/* Parameters of current escape sequence */
1301da177e4SLinus Torvalds 	/* data for manual vt switching */
1311da177e4SLinus Torvalds 	struct vt_mode	vt_mode;
132bde0d2c9SEric W. Biederman 	struct pid 	*vt_pid;
1331da177e4SLinus Torvalds 	int		vt_newvt;
1341da177e4SLinus Torvalds 	wait_queue_head_t paste_wait;
1351da177e4SLinus Torvalds 	/* mode flags */
1361da177e4SLinus Torvalds 	unsigned int	vc_disp_ctrl	: 1;	/* Display chars < 32? */
1371da177e4SLinus Torvalds 	unsigned int	vc_toggle_meta	: 1;	/* Toggle high bit? */
1381da177e4SLinus Torvalds 	unsigned int	vc_decscnm	: 1;	/* Screen Mode */
1391da177e4SLinus Torvalds 	unsigned int	vc_decom	: 1;	/* Origin Mode */
1401da177e4SLinus Torvalds 	unsigned int	vc_decawm	: 1;	/* Autowrap Mode */
1411da177e4SLinus Torvalds 	unsigned int	vc_deccm	: 1;	/* Cursor Visible */
1421da177e4SLinus Torvalds 	unsigned int	vc_decim	: 1;	/* Insert Mode */
1431da177e4SLinus Torvalds 	/* misc */
1442ff5c5a1SMartin Hostettler 	unsigned int	vc_priv		: 3;
1451da177e4SLinus Torvalds 	unsigned int	vc_need_wrap	: 1;
1461da177e4SLinus Torvalds 	unsigned int	vc_can_do_color	: 1;
1471da177e4SLinus Torvalds 	unsigned int	vc_report_mouse : 2;
1481da177e4SLinus Torvalds 	unsigned char	vc_utf		: 1;	/* Unicode UTF-8 encoding */
1491da177e4SLinus Torvalds 	unsigned char	vc_utf_count;
1501da177e4SLinus Torvalds 		 int	vc_utf_char;
151*dbee4cffSJiri Slaby 	DECLARE_BITMAP(vc_tab_stop, VC_TABSTOPS_COUNT);	/* Tab stops. 256 columns. */
1521da177e4SLinus Torvalds 	unsigned char   vc_palette[16*3];       /* Colour palette for VGA+ */
1531da177e4SLinus Torvalds 	unsigned short * vc_translate;
154e400b6ecSAntonino A. Daplas 	unsigned int    vc_resize_user;         /* resize request from user */
1551da177e4SLinus Torvalds 	unsigned int	vc_bell_pitch;		/* Console bell pitch */
1561da177e4SLinus Torvalds 	unsigned int	vc_bell_duration;	/* Console bell duration */
157bd63364cSScot Doyle 	unsigned short	vc_cur_blink_ms;	/* Cursor blink duration */
1581da177e4SLinus Torvalds 	struct vc_data **vc_display_fg;		/* [!] Ptr to var holding fg console for this display */
159e4bdab70STakashi Iwai 	struct uni_pagedir *vc_uni_pagedir;
160e4bdab70STakashi Iwai 	struct uni_pagedir **vc_uni_pagedir_loc; /* [!] Location of uni_pagedir variable for this console */
161d8ae7242SNicolas Pitre 	struct uni_screen *vc_uni_screen;	/* unicode screen content */
1621da177e4SLinus Torvalds 	/* additional information is in vt_kern.h */
1631da177e4SLinus Torvalds };
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds struct vc {
1661da177e4SLinus Torvalds 	struct vc_data *d;
1678b6312f4SEric W. Biederman 	struct work_struct SAK_work;
1681da177e4SLinus Torvalds 
169f4c6fbc9SAdam Borowski 	/* might add  scrmem, kbd  at some time,
1701da177e4SLinus Torvalds 	   to have everything in one place - the disadvantage
1711da177e4SLinus Torvalds 	   would be that vc_cons etc can no longer be static */
1721da177e4SLinus Torvalds };
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds extern struct vc vc_cons [MAX_NR_CONSOLES];
1758b6312f4SEric W. Biederman extern void vc_SAK(struct work_struct *work);
1761da177e4SLinus Torvalds 
1771da177e4SLinus Torvalds #define CUR_DEF		0
1781da177e4SLinus Torvalds #define CUR_NONE	1
1791da177e4SLinus Torvalds #define CUR_UNDERLINE	2
1801da177e4SLinus Torvalds #define CUR_LOWER_THIRD	3
1811da177e4SLinus Torvalds #define CUR_LOWER_HALF	4
1821da177e4SLinus Torvalds #define CUR_TWO_THIRDS	5
1831da177e4SLinus Torvalds #define CUR_BLOCK	6
1841da177e4SLinus Torvalds #define CUR_HWMASK	0x0f
1851da177e4SLinus Torvalds #define CUR_SWMASK	0xfff0
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds #define CUR_DEFAULT CUR_UNDERLINE
1881da177e4SLinus Torvalds 
189ddde3c18SDaniel Vetter bool con_is_visible(const struct vc_data *vc);
190217397d7SRobert P. J. Day 
191217397d7SRobert P. J. Day #endif /* _LINUX_CONSOLE_STRUCT_H */
192