1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */ 28 29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */ 30 /* All Rights Reserved */ 31 32 #ifndef _SYS_TEM_IMPL_H 33 #define _SYS_TEM_IMPL_H 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #include <sys/types.h> 40 #include <sys/font.h> 41 #include <sys/rgb.h> 42 #if !defined(_BOOT) 43 #include <sys/sunddi.h> 44 #include <sys/sunldi.h> 45 #include <sys/visual_io.h> 46 #include <sys/list.h> 47 #include <sys/tem.h> 48 #include <sys/note.h> 49 #endif 50 51 /* 52 * Definitions for ANSI x3.64 terminal control language parser. 53 * With UTF-8 support we use 32-bit value for Unicode codepoints. 54 * 55 * However, as we only need 21 bits for unicode char, we will use the 56 * rest of the bits for attributes, so we can save memory and 57 * have combined attribute+char in screen buffer. This will also allow us 58 * to keep better track about attributes and apply other optimizations. 59 * 60 * This setup will give us 11 bits for attributes (mask 0x7FF). 61 * Bits Meaning 62 * 0-20 char 63 * 21-31 attributes 64 * 65 * The current implementation is building the screen buffer in three parts, 66 * tvs_screen_buf is implementing the character array and the foreground 67 * and the background colors have tvs_fg_color and tvs_bg_color arrays. 68 * The character and color arrays are currently only used to restore the 69 * screen from tem switch (vt switch, or switch from Xorg session). 70 * To implement the console history, this buffering needs to be reviewed. 71 */ 72 73 #define TEM_ATTR_MASK 0x7FF 74 #define TEM_CHAR(c) ((c) & 0x1fffff) 75 #define TEM_CHAR_ATTR(c) (((c) >> 21) & TEM_ATTR_MASK) 76 #define TEM_ATTR(c) (((c) & TEM_ATTR_MASK) << 21) 77 #define TEM_ATTR_ISSET(c, a) ((TEM_CHAR_ATTR(c) & (a)) == (a)) 78 79 #define TEM_MAXPARAMS 5 /* maximum number of ANSI paramters */ 80 #define TEM_MAXFKEY 30 /* max length of function key with <ESC>Q */ 81 82 #define TEM_SCROLL_UP 0 83 #define TEM_SCROLL_DOWN 1 84 #define TEM_SHIFT_LEFT 0 85 #define TEM_SHIFT_RIGHT 1 86 87 /* Attributes 0-0x7ff */ 88 #define TEM_ATTR_NORMAL 0x0000 89 #define TEM_ATTR_REVERSE 0x0001 90 #define TEM_ATTR_BOLD 0x0002 91 #define TEM_ATTR_BLINK 0x0004 92 #define TEM_ATTR_UNDERLINE 0x0008 93 #define TEM_ATTR_SCREEN_REVERSE 0x0010 94 #define TEM_ATTR_BRIGHT_FG 0x0020 95 #define TEM_ATTR_BRIGHT_BG 0x0040 96 #define TEM_ATTR_TRANSPARENT 0x0080 97 #define TEM_ATTR_IMAGE 0x0100 98 #define TEM_ATTR_RGB_FG 0x0200 99 #define TEM_ATTR_RGB_BG 0x0400 100 101 #define ANSI_COLOR_BLACK 0 102 #define ANSI_COLOR_RED 1 103 #define ANSI_COLOR_GREEN 2 104 #define ANSI_COLOR_BROWN 3 105 #define ANSI_COLOR_BLUE 4 106 #define ANSI_COLOR_MAGENTA 5 107 #define ANSI_COLOR_CYAN 6 108 #define ANSI_COLOR_WHITE 7 109 110 #define TEM_TEXT_WHITE 0 111 #define TEM_TEXT_BLACK 1 112 #define TEM_TEXT_BLACK24_RED 0x00 113 #define TEM_TEXT_BLACK24_GREEN 0x00 114 #define TEM_TEXT_BLACK24_BLUE 0x00 115 #define TEM_TEXT_WHITE24_RED 0xff 116 #define TEM_TEXT_WHITE24_GREEN 0xff 117 #define TEM_TEXT_WHITE24_BLUE 0xff 118 119 #define A_STATE_START 0 120 #define A_STATE_ESC 1 121 #define A_STATE_CSI 2 122 #define A_STATE_CSI_QMARK 3 123 #define A_STATE_CSI_EQUAL 4 124 125 /* 126 * Default number of rows and columns 127 */ 128 #ifdef _HAVE_TEM_FIRMWARE 129 #define TEM_DEFAULT_ROWS 34 130 #define TEM_DEFAULT_COLS 80 131 #else 132 #define TEM_DEFAULT_ROWS 25 133 #define TEM_DEFAULT_COLS 80 134 #endif 135 136 /* 137 * Default foreground/background color 138 */ 139 140 #define DEFAULT_ANSI_FOREGROUND ANSI_COLOR_BLACK 141 #define DEFAULT_ANSI_BACKGROUND ANSI_COLOR_WHITE 142 143 typedef uint32_t tem_char_t; /* 32bit char to support UTF-8 */ 144 typedef union { 145 uint32_t n; 146 struct bgra { 147 uint8_t b; 148 uint8_t g; 149 uint8_t r; 150 uint8_t a; 151 } rgb; 152 } text_color_t; 153 typedef uint16_t text_attr_t; 154 155 #if !defined(_BOOT) 156 typedef struct tem_color { 157 text_color_t fg_color; 158 text_color_t bg_color; 159 text_attr_t a_flags; 160 } tem_color_t; 161 162 enum called_from { CALLED_FROM_NORMAL, CALLED_FROM_STANDALONE }; 163 164 struct tem_pix_pos { 165 screen_pos_t x; 166 screen_pos_t y; 167 }; 168 169 struct tem_char_pos { 170 screen_pos_t col; 171 screen_pos_t row; 172 }; 173 174 struct tem_size { 175 screen_size_t width; 176 screen_size_t height; 177 }; 178 179 /* Combined color and 32bit tem char */ 180 typedef struct term_char { 181 text_color_t tc_fg_color; 182 text_color_t tc_bg_color; 183 tem_char_t tc_char; 184 } term_char_t; 185 186 /* 187 * State structure for each virtual terminal emulator 188 */ 189 struct tem_vt_state { 190 kmutex_t tvs_lock; 191 uchar_t tvs_fbmode; /* framebuffer mode */ 192 uchar_t tvs_alpha; /* rgb alpha channel */ 193 text_attr_t tvs_flags; /* flags for this x3.64 terminal */ 194 int tvs_state; /* state in output esc seq processing */ 195 boolean_t tvs_gotparam; /* does output esc seq have a param */ 196 197 int tvs_curparam; /* current param # of output esc seq */ 198 int tvs_paramval; /* value of current param */ 199 int tvs_params[TEM_MAXPARAMS]; /* parameters of output esc seq */ 200 screen_pos_t *tvs_tabs; /* tab stops */ 201 size_t tvs_maxtab; /* maximum number of tab stops */ 202 size_t tvs_ntabs; /* number of tabs used */ 203 int tvs_nscroll; /* number of lines to scroll */ 204 205 struct tem_char_pos tvs_s_cursor; /* start cursor position */ 206 struct tem_char_pos tvs_c_cursor; /* current cursor position */ 207 struct tem_char_pos tvs_r_cursor; /* remembered cursor position */ 208 209 term_char_t *tvs_outbuf; /* place to keep incomplete lines */ 210 size_t tvs_outbuf_size; 211 size_t tvs_outindex; /* index into a_outbuf */ 212 void *tvs_pix_data; /* pointer to tmp bitmap area */ 213 size_t tvs_pix_data_size; 214 215 text_color_t tvs_fg_color; /* console foreground */ 216 text_color_t tvs_bg_color; /* console background */ 217 218 int tvs_first_line; /* kernel console output begins */ 219 220 term_char_t *tvs_screen_buf; /* whole screen buffer */ 221 term_char_t **tvs_screen_rows; /* screen buffer rows */ 222 size_t tvs_screen_buf_size; 223 size_t tvs_screen_history_size; 224 225 unsigned tvs_utf8_left; /* UTF-8 code points */ 226 tem_char_t tvs_utf8_partial; /* UTF-8 char being completed */ 227 228 boolean_t tvs_isactive; 229 boolean_t tvs_initialized; /* initialization flag */ 230 231 list_node_t tvs_list_node; 232 }; 233 _NOTE(MUTEX_PROTECTS_DATA(tem_vt_state::tvs_lock, tem_vt_state)) 234 235 typedef struct tem_safe_callbacks { 236 void (*tsc_display)(struct tem_vt_state *, term_char_t *, int, 237 screen_pos_t, screen_pos_t, cred_t *, enum called_from); 238 void (*tsc_copy)(struct tem_vt_state *, 239 screen_pos_t, screen_pos_t, screen_pos_t, screen_pos_t, 240 screen_pos_t, screen_pos_t, cred_t *, enum called_from); 241 void (*tsc_cursor)(struct tem_vt_state *, short, cred_t *, 242 enum called_from); 243 void (*tsc_bit2pix)(struct tem_vt_state *, term_char_t *); 244 void (*tsc_cls)(struct tem_vt_state *, int, 245 screen_pos_t, screen_pos_t, cred_t *, enum called_from); 246 } tem_safe_callbacks_t; 247 248 /* 249 * common term soft state structure shared by all virtual terminal emulators 250 */ 251 typedef struct tem_state { 252 ldi_handle_t ts_hdl; /* Framework handle for layered on dev */ 253 screen_size_t ts_linebytes; /* Layered on bytes per scan line */ 254 255 int ts_display_mode; /* What mode we are in */ 256 struct vis_polledio *ts_fb_polledio; 257 258 struct tem_size ts_c_dimension; /* window dimensions in characters */ 259 struct tem_size ts_p_dimension; /* screen dimensions in pixels */ 260 struct tem_pix_pos ts_p_offset; /* pix offset to center the display */ 261 262 int ts_pix_data_size; /* size of bitmap data areas */ 263 int ts_pdepth; /* pixel depth */ 264 struct font ts_font; /* font table */ 265 266 term_char_t *ts_blank_line; /* a blank line for scrolling */ 267 tem_safe_callbacks_t *ts_callbacks; /* internal output functions */ 268 269 int ts_initialized; /* initialization flag */ 270 271 tem_modechg_cb_t ts_modechg_cb; 272 tem_modechg_cb_arg_t ts_modechg_arg; 273 274 color_map_fn_t ts_color_map; 275 276 tem_color_t ts_init_color; /* initial color and attributes */ 277 278 struct tem_vt_state *ts_active; 279 kmutex_t ts_lock; 280 list_t ts_list; /* chain of all tems */ 281 } tem_state_t; 282 283 extern tem_state_t tems; 284 extern tem_safe_callbacks_t tem_safe_text_callbacks; 285 extern tem_safe_callbacks_t tem_safe_pix_callbacks; 286 287 288 /* 289 * tems_* fuctions mean that they just operate on the common soft state 290 * (tem_state_t), and tem_* functions mean that they operate on the 291 * per-tem structure (tem_vt_state). All "safe" interfaces are in tem_safe.c. 292 */ 293 int tems_cls_layered(struct vis_consclear *, cred_t *); 294 void tems_display_layered(struct vis_consdisplay *, cred_t *); 295 void tems_copy_layered(struct vis_conscopy *, cred_t *); 296 void tems_cursor_layered(struct vis_conscursor *, cred_t *); 297 void tems_safe_copy(struct vis_conscopy *, cred_t *, enum called_from); 298 299 void tem_align(struct tem_vt_state *, cred_t *, enum called_from); 300 void tem_safe_check_first_time(struct tem_vt_state *tem, cred_t *, 301 enum called_from); 302 void tem_safe_reset_display(struct tem_vt_state *, cred_t *, 303 enum called_from, boolean_t, boolean_t); 304 void tem_safe_terminal_emulate(struct tem_vt_state *, uchar_t *, int, 305 cred_t *, enum called_from); 306 void tem_safe_text_display(struct tem_vt_state *, term_char_t *, 307 int, screen_pos_t, screen_pos_t, cred_t *, enum called_from); 308 void tem_safe_text_copy(struct tem_vt_state *, 309 screen_pos_t, screen_pos_t, 310 screen_pos_t, screen_pos_t, 311 screen_pos_t, screen_pos_t, 312 cred_t *, enum called_from); 313 void tem_safe_text_cursor(struct tem_vt_state *, short, cred_t *, 314 enum called_from); 315 void tem_safe_text_cls(struct tem_vt_state *, 316 int count, screen_pos_t row, screen_pos_t col, 317 cred_t *credp, enum called_from called_from); 318 void tem_safe_pix_display(struct tem_vt_state *, term_char_t *, 319 int, screen_pos_t, screen_pos_t, cred_t *, enum called_from); 320 void tem_safe_pix_copy(struct tem_vt_state *, 321 screen_pos_t, screen_pos_t, 322 screen_pos_t, screen_pos_t, 323 screen_pos_t, screen_pos_t, 324 cred_t *, enum called_from); 325 void tem_safe_pix_cursor(struct tem_vt_state *, short, cred_t *, 326 enum called_from); 327 void tem_safe_pix_bit2pix(struct tem_vt_state *, term_char_t *); 328 void tem_safe_pix_cls(struct tem_vt_state *, int, screen_pos_t, screen_pos_t, 329 cred_t *, enum called_from); 330 void tem_safe_pix_cls_range(struct tem_vt_state *, 331 screen_pos_t, int, int, 332 screen_pos_t, int, int, 333 boolean_t, cred_t *, enum called_from); 334 335 void tem_safe_pix_clear_entire_screen(struct tem_vt_state *, 336 cred_t *, enum called_from); 337 338 void tem_safe_get_attr(struct tem_vt_state *, text_color_t *, 339 text_color_t *, text_attr_t *, uint8_t); 340 341 void tem_safe_blank_screen(struct tem_vt_state *, cred_t *, 342 enum called_from); 343 void tem_safe_unblank_screen(struct tem_vt_state *, cred_t *, 344 enum called_from); 345 #endif /* _BOOT */ 346 347 #ifdef __cplusplus 348 } 349 #endif 350 351 #endif /* _SYS_TEM_IMPL_H */ 352