1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * console_struct.h
4  *
5  * Data structure describing single virtual console except for data
6  * used by vt.c.
7  *
8  * Fields marked with [#] must be set by the low-level driver.
9  * Fields marked with [!] can be changed by the low-level driver
10  * to achieve effects such as fast scrolling by changing the origin.
11  */
12 
13 #ifndef _LINUX_CONSOLE_STRUCT_H
14 #define _LINUX_CONSOLE_STRUCT_H
15 
16 #include <linux/wait.h>
17 #include <linux/vt.h>
18 #include <linux/workqueue.h>
19 
20 struct uni_pagedir;
21 struct uni_screen;
22 
23 #define NPAR 16
24 
25 /*
26  * Example: vc_data of a console that was scrolled 3 lines down.
27  *
28  *                              Console buffer
29  * vc_screenbuf ---------> +----------------------+-.
30  *                         | initializing W       |  \
31  *                         | initializing X       |   |
32  *                         | initializing Y       |    > scroll-back area
33  *                         | initializing Z       |   |
34  *                         |                      |  /
35  * vc_visible_origin ---> ^+----------------------+-:
36  * (changes by scroll)    || Welcome to linux     |  \
37  *                        ||                      |   |
38  *           vc_rows --->< | login: root          |   |  visible on console
39  *                        || password:            |    > (vc_screenbuf_size is
40  * vc_origin -----------> ||                      |   |   vc_size_row * vc_rows)
41  * (start when no scroll) || Last login: 12:28    |  /
42  *                        v+----------------------+-:
43  *                         | Have a lot of fun... |  \
44  * vc_pos -----------------|--------v             |   > scroll-front area
45  *                         | ~ # cat_             |  /
46  * vc_scr_end -----------> +----------------------+-:
47  * (vc_origin +            |                      |  \ EMPTY, to be filled by
48  *  vc_screenbuf_size)     |                      |  / vc_video_erase_char
49  *                         +----------------------+-'
50  *                         <---- 2 * vc_cols ----->
51  *                         <---- vc_size_row ----->
52  *
53  * Note that every character in the console buffer is accompanied with an
54  * attribute in the buffer right after the character. This is not depicted
55  * in the figure.
56  */
57 struct vc_data {
58 	struct tty_port port;			/* Upper level data */
59 
60 	unsigned short	vc_num;			/* Console number */
61 	unsigned int	vc_cols;		/* [#] Console size */
62 	unsigned int	vc_rows;
63 	unsigned int	vc_size_row;		/* Bytes per row */
64 	unsigned int	vc_scan_lines;		/* # of scan lines */
65 	unsigned int	vc_cell_height;		/* CRTC character cell height */
66 	unsigned long	vc_origin;		/* [!] Start of real screen */
67 	unsigned long	vc_scr_end;		/* [!] End of real screen */
68 	unsigned long	vc_visible_origin;	/* [!] Top of visible window */
69 	unsigned int	vc_top, vc_bottom;	/* Scrolling region */
70 	const struct consw *vc_sw;
71 	unsigned short	*vc_screenbuf;		/* In-memory character/attribute buffer */
72 	unsigned int	vc_screenbuf_size;
73 	unsigned char	vc_mode;		/* KD_TEXT, ... */
74 	/* attributes for all characters on screen */
75 	unsigned char	vc_attr;		/* Current attributes */
76 	unsigned char	vc_def_color;		/* Default colors */
77 	unsigned char	vc_color;		/* Foreground & background */
78 	unsigned char	vc_s_color;		/* Saved foreground & background */
79 	unsigned char	vc_ulcolor;		/* Color for underline mode */
80 	unsigned char   vc_itcolor;
81 	unsigned char	vc_halfcolor;		/* Color for half intensity mode */
82 	/* cursor */
83 	unsigned int	vc_cursor_type;
84 	unsigned short	vc_complement_mask;	/* [#] Xor mask for mouse pointer */
85 	unsigned short	vc_s_complement_mask;	/* Saved mouse pointer mask */
86 	unsigned int	vc_x, vc_y;		/* Cursor position */
87 	unsigned int	vc_saved_x, vc_saved_y;
88 	unsigned long	vc_pos;			/* Cursor address */
89 	/* fonts */
90 	unsigned short	vc_hi_font_mask;	/* [#] Attribute set for upper 256 chars of font or 0 if not supported */
91 	struct console_font vc_font;		/* Current VC font set */
92 	unsigned short	vc_video_erase_char;	/* Background erase character */
93 	/* VT terminal data */
94 	unsigned int	vc_state;		/* Escape sequence parser state */
95 	unsigned int	vc_npar,vc_par[NPAR];	/* Parameters of current escape sequence */
96 	/* data for manual vt switching */
97 	struct vt_mode	vt_mode;
98 	struct pid 	*vt_pid;
99 	int		vt_newvt;
100 	wait_queue_head_t paste_wait;
101 	/* mode flags */
102 	unsigned int	vc_charset	: 1;	/* Character set G0 / G1 */
103 	unsigned int	vc_s_charset	: 1;	/* Saved character set */
104 	unsigned int	vc_disp_ctrl	: 1;	/* Display chars < 32? */
105 	unsigned int	vc_toggle_meta	: 1;	/* Toggle high bit? */
106 	unsigned int	vc_decscnm	: 1;	/* Screen Mode */
107 	unsigned int	vc_decom	: 1;	/* Origin Mode */
108 	unsigned int	vc_decawm	: 1;	/* Autowrap Mode */
109 	unsigned int	vc_deccm	: 1;	/* Cursor Visible */
110 	unsigned int	vc_decim	: 1;	/* Insert Mode */
111 	/* attribute flags */
112 	unsigned int	vc_intensity	: 2;	/* 0=half-bright, 1=normal, 2=bold */
113 	unsigned int    vc_italic:1;
114 	unsigned int	vc_underline	: 1;
115 	unsigned int	vc_blink	: 1;
116 	unsigned int	vc_reverse	: 1;
117 	unsigned int	vc_s_intensity	: 2;	/* saved rendition */
118 	unsigned int    vc_s_italic:1;
119 	unsigned int	vc_s_underline	: 1;
120 	unsigned int	vc_s_blink	: 1;
121 	unsigned int	vc_s_reverse	: 1;
122 	/* misc */
123 	unsigned int	vc_ques		: 1;
124 	unsigned int	vc_need_wrap	: 1;
125 	unsigned int	vc_can_do_color	: 1;
126 	unsigned int	vc_report_mouse : 2;
127 	unsigned char	vc_utf		: 1;	/* Unicode UTF-8 encoding */
128 	unsigned char	vc_utf_count;
129 		 int	vc_utf_char;
130 	unsigned int	vc_tab_stop[8];		/* Tab stops. 256 columns. */
131 	unsigned char   vc_palette[16*3];       /* Colour palette for VGA+ */
132 	unsigned short * vc_translate;
133 	unsigned char 	vc_G0_charset;
134 	unsigned char 	vc_G1_charset;
135 	unsigned char 	vc_saved_G0;
136 	unsigned char 	vc_saved_G1;
137 	unsigned int    vc_resize_user;         /* resize request from user */
138 	unsigned int	vc_bell_pitch;		/* Console bell pitch */
139 	unsigned int	vc_bell_duration;	/* Console bell duration */
140 	unsigned short	vc_cur_blink_ms;	/* Cursor blink duration */
141 	struct vc_data **vc_display_fg;		/* [!] Ptr to var holding fg console for this display */
142 	struct uni_pagedir *vc_uni_pagedir;
143 	struct uni_pagedir **vc_uni_pagedir_loc; /* [!] Location of uni_pagedir variable for this console */
144 	struct uni_screen *vc_uni_screen;	/* unicode screen content */
145 	bool vc_panic_force_write; /* when oops/panic this VC can accept forced output/blanking */
146 	/* additional information is in vt_kern.h */
147 };
148 
149 struct vc {
150 	struct vc_data *d;
151 	struct work_struct SAK_work;
152 
153 	/* might add  scrmem, kbd  at some time,
154 	   to have everything in one place - the disadvantage
155 	   would be that vc_cons etc can no longer be static */
156 };
157 
158 extern struct vc vc_cons [MAX_NR_CONSOLES];
159 extern void vc_SAK(struct work_struct *work);
160 
161 #define CUR_DEF		0
162 #define CUR_NONE	1
163 #define CUR_UNDERLINE	2
164 #define CUR_LOWER_THIRD	3
165 #define CUR_LOWER_HALF	4
166 #define CUR_TWO_THIRDS	5
167 #define CUR_BLOCK	6
168 #define CUR_HWMASK	0x0f
169 #define CUR_SWMASK	0xfff0
170 
171 #define CUR_DEFAULT CUR_UNDERLINE
172 
con_is_visible(const struct vc_data * vc)173 static inline bool con_is_visible(const struct vc_data *vc)
174 {
175 	return *vc->vc_display_fg == vc;
176 }
177 
178 #endif /* _LINUX_CONSOLE_STRUCT_H */
179