Lines Matching refs:vc
137 struct vc vc_cons [MAX_NR_CONSOLES];
144 static void vc_init(struct vc_data *vc, unsigned int rows,
146 static void gotoxy(struct vc_data *vc, int new_x, int new_y);
147 static void save_cur(struct vc_data *vc);
148 static void reset_terminal(struct vc_data *vc, int do_clear);
151 static void set_cursor(struct vc_data *vc);
152 static void hide_cursor(struct vc_data *vc);
156 static void set_palette(struct vc_data *vc);
239 * the attribute 'active' contains the name of the current vc
240 * console and it supports poll() to detect vc switches
261 static void notify_write(struct vc_data *vc, unsigned int unicode)
263 struct vt_notifier_param param = { .vc = vc, .c = unicode };
267 static void notify_update(struct vc_data *vc)
269 struct vt_notifier_param param = { .vc = vc };
276 static inline bool con_is_fg(const struct vc_data *vc)
278 return vc->vc_num == fg_console;
281 static inline bool con_should_update(const struct vc_data *vc)
283 return con_is_visible(vc) && !console_blanked;
286 static inline unsigned short *screenpos(const struct vc_data *vc, int offset,
292 p = (unsigned short *)(vc->vc_origin + offset);
293 else if (!vc->vc_sw->con_screen_pos)
294 p = (unsigned short *)(vc->vc_visible_origin + offset);
296 p = vc->vc_sw->con_screen_pos(vc, offset);
321 #define get_vc_uniscr(vc) NULL
323 #define get_vc_uniscr(vc) vc->vc_uni_screen
366 static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
368 vc_uniscr_free(vc->vc_uni_screen);
369 vc->vc_uni_screen = new_uniscr;
372 static void vc_uniscr_putc(struct vc_data *vc, char32_t uc)
374 struct uni_screen *uniscr = get_vc_uniscr(vc);
377 uniscr->lines[vc->state.y][vc->state.x] = uc;
380 static void vc_uniscr_insert(struct vc_data *vc, unsigned int nr)
382 struct uni_screen *uniscr = get_vc_uniscr(vc);
385 char32_t *ln = uniscr->lines[vc->state.y];
386 unsigned int x = vc->state.x, cols = vc->vc_cols;
393 static void vc_uniscr_delete(struct vc_data *vc, unsigned int nr)
395 struct uni_screen *uniscr = get_vc_uniscr(vc);
398 char32_t *ln = uniscr->lines[vc->state.y];
399 unsigned int x = vc->state.x, cols = vc->vc_cols;
406 static void vc_uniscr_clear_line(struct vc_data *vc, unsigned int x,
409 struct uni_screen *uniscr = get_vc_uniscr(vc);
412 char32_t *ln = uniscr->lines[vc->state.y];
418 static void vc_uniscr_clear_lines(struct vc_data *vc, unsigned int y,
421 struct uni_screen *uniscr = get_vc_uniscr(vc);
424 unsigned int cols = vc->vc_cols;
431 static void vc_uniscr_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
434 struct uni_screen *uniscr = get_vc_uniscr(vc);
460 vc_uniscr_clear_lines(vc, clear, nr);
501 int vc_uniscr_check(struct vc_data *vc)
512 if (!vc->vc_utf)
515 if (vc->vc_uni_screen)
518 uniscr = vc_uniscr_alloc(vc->vc_cols, vc->vc_rows);
528 p = (unsigned short *)vc->vc_origin;
529 mask = vc->vc_hi_font_mask | 0xff;
530 for (y = 0; y < vc->vc_rows; y++) {
532 for (x = 0; x < vc->vc_cols; x++) {
534 line[x] = inverse_translate(vc, glyph, true);
538 vc->vc_uni_screen = uniscr;
547 void vc_uniscr_copy_line(const struct vc_data *vc, void *dest, bool viewed,
550 struct uni_screen *uniscr = get_vc_uniscr(vc);
551 int offset = row * vc->vc_size_row + col * 2;
556 pos = (unsigned long)screenpos(vc, offset, viewed);
557 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
563 row = (pos - vc->vc_origin) / vc->vc_size_row;
564 col = ((pos - vc->vc_origin) % vc->vc_size_row) / 2;
574 int mask = vc->vc_hi_font_mask | 0xff;
578 *uni_buf++ = inverse_translate(vc, glyph, true);
584 static void vc_uniscr_debug_check(struct vc_data *vc)
586 struct uni_screen *uniscr = get_vc_uniscr(vc);
599 p = (unsigned short *)vc->vc_origin;
600 mask = vc->vc_hi_font_mask | 0xff;
601 for (y = 0; y < vc->vc_rows; y++) {
603 for (x = 0; x < vc->vc_cols; x++) {
606 int tc = conv_uni_to_pc(vc, uc);
608 tc = conv_uni_to_pc(vc, 0xfffd);
610 tc = conv_uni_to_pc(vc, '?');
620 static void con_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
627 if (b > vc->vc_rows || t >= b || nr < 1)
629 vc_uniscr_scroll(vc, t, b, dir, nr);
630 if (con_is_visible(vc) && vc->vc_sw->con_scroll(vc, t, b, dir, nr))
633 s = clear = (u16 *)(vc->vc_origin + vc->vc_size_row * t);
634 d = (u16 *)(vc->vc_origin + vc->vc_size_row * (t + nr));
637 clear = s + (b - t - nr) * vc->vc_cols;
640 scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
641 scr_memsetw(clear, vc->vc_video_erase_char, vc->vc_size_row * nr);
644 static void do_update_region(struct vc_data *vc, unsigned long start, int count)
650 if (!vc->vc_sw->con_getxy) {
651 offset = (start - vc->vc_origin) / 2;
652 xx = offset % vc->vc_cols;
653 yy = offset / vc->vc_cols;
656 start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy);
663 while (xx < vc->vc_cols && count) {
666 vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
676 vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
681 if (vc->vc_sw->con_getxy) {
683 start = vc->vc_sw->con_getxy(vc, start, NULL, NULL);
688 void update_region(struct vc_data *vc, unsigned long start, int count)
692 if (con_should_update(vc)) {
693 hide_cursor(vc);
694 do_update_region(vc, start, count);
695 set_cursor(vc);
701 static u8 build_attr(struct vc_data *vc, u8 _color,
705 if (vc->vc_sw->con_build_attr)
706 return vc->vc_sw->con_build_attr(vc, _color, _intensity,
721 if (!vc->vc_can_do_color)
728 a = (a & 0xF0) | vc->vc_itcolor;
730 a = (a & 0xf0) | vc->vc_ulcolor;
732 a = (a & 0xf0) | vc->vc_halfcolor;
739 if (vc->vc_hi_font_mask == 0x100)
745 static void update_attr(struct vc_data *vc)
747 vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity,
748 vc->state.blink, vc->state.underline,
749 vc->state.reverse ^ vc->vc_decscnm, vc->state.italic);
750 vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color,
751 VCI_NORMAL, vc->state.blink, false,
752 vc->vc_decscnm, false) << 8);
756 void invert_screen(struct vc_data *vc, int offset, int count, bool viewed)
763 p = screenpos(vc, offset, viewed);
764 if (vc->vc_sw->con_invert_region) {
765 vc->vc_sw->con_invert_region(vc, p, count);
771 if (!vc->vc_can_do_color) {
778 } else if (vc->vc_hi_font_mask == 0x100) {
799 if (con_should_update(vc))
800 do_update_region(vc, (unsigned long) p, count);
801 notify_update(vc);
805 void complement_pos(struct vc_data *vc, int offset)
814 old_offset < vc->vc_screenbuf_size) {
815 scr_writew(old, screenpos(vc, old_offset, true));
816 if (con_should_update(vc))
817 vc->vc_sw->con_putc(vc, old, oldy, oldx);
818 notify_update(vc);
824 offset < vc->vc_screenbuf_size) {
827 p = screenpos(vc, offset, true);
829 new = old ^ vc->vc_complement_mask;
831 if (con_should_update(vc)) {
832 oldx = (offset >> 1) % vc->vc_cols;
833 oldy = (offset >> 1) / vc->vc_cols;
834 vc->vc_sw->con_putc(vc, new, oldy, oldx);
836 notify_update(vc);
840 static void insert_char(struct vc_data *vc, unsigned int nr)
842 unsigned short *p = (unsigned short *) vc->vc_pos;
844 vc_uniscr_insert(vc, nr);
845 scr_memmovew(p + nr, p, (vc->vc_cols - vc->state.x - nr) * 2);
846 scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
847 vc->vc_need_wrap = 0;
848 if (con_should_update(vc))
849 do_update_region(vc, (unsigned long) p,
850 vc->vc_cols - vc->state.x);
853 static void delete_char(struct vc_data *vc, unsigned int nr)
855 unsigned short *p = (unsigned short *) vc->vc_pos;
857 vc_uniscr_delete(vc, nr);
858 scr_memmovew(p, p + nr, (vc->vc_cols - vc->state.x - nr) * 2);
859 scr_memsetw(p + vc->vc_cols - vc->state.x - nr, vc->vc_video_erase_char,
861 vc->vc_need_wrap = 0;
862 if (con_should_update(vc))
863 do_update_region(vc, (unsigned long) p,
864 vc->vc_cols - vc->state.x);
869 static void add_softcursor(struct vc_data *vc)
871 int i = scr_readw((u16 *) vc->vc_pos);
872 u32 type = vc->vc_cursor_type;
886 scr_writew(i, (u16 *)vc->vc_pos);
887 if (con_should_update(vc))
888 vc->vc_sw->con_putc(vc, i, vc->state.y, vc->state.x);
891 static void hide_softcursor(struct vc_data *vc)
894 scr_writew(softcursor_original, (u16 *)vc->vc_pos);
895 if (con_should_update(vc))
896 vc->vc_sw->con_putc(vc, softcursor_original,
897 vc->state.y, vc->state.x);
902 static void hide_cursor(struct vc_data *vc)
904 if (vc_is_sel(vc))
907 vc->vc_sw->con_cursor(vc, CM_ERASE);
908 hide_softcursor(vc);
911 static void set_cursor(struct vc_data *vc)
913 if (!con_is_fg(vc) || console_blanked || vc->vc_mode == KD_GRAPHICS)
915 if (vc->vc_deccm) {
916 if (vc_is_sel(vc))
918 add_softcursor(vc);
919 if (CUR_SIZE(vc->vc_cursor_type) != CUR_NONE)
920 vc->vc_sw->con_cursor(vc, CM_DRAW);
922 hide_cursor(vc);
925 static void set_origin(struct vc_data *vc)
929 if (!con_is_visible(vc) ||
930 !vc->vc_sw->con_set_origin ||
931 !vc->vc_sw->con_set_origin(vc))
932 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
933 vc->vc_visible_origin = vc->vc_origin;
934 vc->vc_scr_end = vc->vc_origin + vc->vc_screenbuf_size;
935 vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->state.y +
936 2 * vc->state.x;
939 static void save_screen(struct vc_data *vc)
943 if (vc->vc_sw->con_save_screen)
944 vc->vc_sw->con_save_screen(vc);
947 static void flush_scrollback(struct vc_data *vc)
951 set_origin(vc);
952 if (vc->vc_sw->con_flush_scrollback) {
953 vc->vc_sw->con_flush_scrollback(vc);
954 } else if (con_is_visible(vc)) {
963 hide_cursor(vc);
964 vc->vc_sw->con_switch(vc);
965 set_cursor(vc);
973 void clear_buffer_attributes(struct vc_data *vc)
975 unsigned short *p = (unsigned short *)vc->vc_origin;
976 int count = vc->vc_screenbuf_size / 2;
977 int mask = vc->vc_hi_font_mask | 0xff;
980 scr_writew((scr_readw(p)&mask) | (vc->vc_video_erase_char & ~mask), p);
984 void redraw_screen(struct vc_data *vc, int is_switch)
990 if (!vc) {
998 if (old_vc == vc)
1000 if (!con_is_visible(vc))
1002 *vc->vc_display_fg = vc;
1003 fg_console = vc->vc_num;
1012 hide_cursor(vc);
1018 int old_was_color = vc->vc_can_do_color;
1020 set_origin(vc);
1021 update = vc->vc_sw->con_switch(vc);
1022 set_palette(vc);
1029 if (old_was_color != vc->vc_can_do_color) {
1030 update_attr(vc);
1031 clear_buffer_attributes(vc);
1034 if (update && vc->vc_mode != KD_GRAPHICS)
1035 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
1037 set_cursor(vc);
1041 notify_update(vc);
1054 static void visual_init(struct vc_data *vc, int num, int init)
1056 /* ++Geert: vc->vc_sw->con_init determines console size */
1057 if (vc->vc_sw)
1058 module_put(vc->vc_sw->owner);
1059 vc->vc_sw = conswitchp;
1062 vc->vc_sw = con_driver_map[num];
1064 __module_get(vc->vc_sw->owner);
1065 vc->vc_num = num;
1066 vc->vc_display_fg = &master_display_fg;
1067 if (vc->vc_uni_pagedir_loc)
1068 con_free_unimap(vc);
1069 vc->vc_uni_pagedir_loc = &vc->vc_uni_pagedir;
1070 vc->vc_uni_pagedir = NULL;
1071 vc->vc_hi_font_mask = 0;
1072 vc->vc_complement_mask = 0;
1073 vc->vc_can_do_color = 0;
1074 vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;
1075 vc->vc_sw->con_init(vc, init);
1076 if (!vc->vc_complement_mask)
1077 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1078 vc->vc_s_complement_mask = vc->vc_complement_mask;
1079 vc->vc_size_row = vc->vc_cols << 1;
1080 vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
1084 static void visual_deinit(struct vc_data *vc)
1086 vc->vc_sw->con_deinit(vc);
1087 module_put(vc->vc_sw->owner);
1092 struct vc_data *vc = container_of(port, struct vc_data, port);
1094 kfree(vc);
1112 struct vc_data *vc;
1129 param.vc = vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL);
1130 if (!vc)
1133 vc_cons[currcons].d = vc;
1134 tty_port_init(&vc->port);
1135 vc->port.ops = &vc_port_ops;
1138 visual_init(vc, currcons, 1);
1140 if (!*vc->vc_uni_pagedir_loc)
1141 con_set_default_unimap(vc);
1144 if (vc->vc_cols > VC_MAXCOL || vc->vc_rows > VC_MAXROW ||
1145 vc->vc_screenbuf_size > KMALLOC_MAX_SIZE || !vc->vc_screenbuf_size)
1148 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL);
1149 if (!vc->vc_screenbuf)
1157 vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
1163 visual_deinit(vc);
1164 kfree(vc);
1169 static inline int resize_screen(struct vc_data *vc, int width, int height,
1175 if (vc->vc_sw->con_resize)
1176 err = vc->vc_sw->con_resize(vc, width, height, user);
1184 * @vc: virtual console private data
1196 static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
1209 if (!vc)
1212 user = vc->vc_resize_user;
1213 vc->vc_resize_user = 0;
1218 new_cols = (cols ? cols : vc->vc_cols);
1219 new_rows = (lines ? lines : vc->vc_rows);
1223 if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) {
1240 return resize_screen(vc, new_cols, new_rows, user);
1249 if (get_vc_uniscr(vc)) {
1257 if (vc_is_sel(vc))
1260 old_rows = vc->vc_rows;
1261 old_row_size = vc->vc_size_row;
1263 err = resize_screen(vc, new_cols, new_rows, user);
1270 vc->vc_rows = new_rows;
1271 vc->vc_cols = new_cols;
1272 vc->vc_size_row = new_row_size;
1273 vc->vc_screenbuf_size = new_screen_size;
1277 old_origin = vc->vc_origin;
1281 if (vc->state.y > new_rows) {
1282 if (old_rows - vc->state.y < new_rows) {
1293 first_copied_row = (vc->state.y - new_rows/2);
1301 get_vc_uniscr(vc), rlth/2, first_copied_row,
1303 vc_uniscr_set(vc, new_uniscr);
1305 update_attr(vc);
1312 vc->vc_video_erase_char, rrem);
1317 scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
1319 oldscreen = vc->vc_screenbuf;
1320 vc->vc_screenbuf = newscreen;
1321 vc->vc_screenbuf_size = new_screen_size;
1322 set_origin(vc);
1326 vc->vc_top = 0;
1327 vc->vc_bottom = vc->vc_rows;
1328 gotoxy(vc, vc->state.x, vc->state.y);
1329 save_cur(vc);
1336 ws.ws_row = vc->vc_rows;
1337 ws.ws_col = vc->vc_cols;
1338 ws.ws_ypixel = vc->vc_scan_lines;
1342 if (con_is_visible(vc))
1343 update_screen(vc);
1344 vt_event_post(VT_EVENT_RESIZE, vc->vc_num, vc->vc_num);
1345 notify_update(vc);
1351 * @vc: virtual console
1358 * vc->port.tty
1361 int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
1363 return vc_do_resize(vc->port.tty, vc, cols, rows);
1380 struct vc_data *vc = tty->driver_data;
1384 ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row);
1391 struct vc_data *vc = NULL;
1398 param.vc = vc = vc_cons[currcons].d;
1401 visual_deinit(vc);
1402 con_free_unimap(vc);
1403 put_pid(vc->vt_pid);
1404 vc_uniscr_set(vc, NULL);
1405 kfree(vc->vc_screenbuf);
1408 return vc;
1417 #define set_kbd(vc, x) vt_set_kbd_mode_bit((vc)->vc_num, (x))
1418 #define clr_kbd(vc, x) vt_clr_kbd_mode_bit((vc)->vc_num, (x))
1419 #define is_kbd(vc, x) vt_get_kbd_mode_bit((vc)->vc_num, (x))
1453 static void gotoxy(struct vc_data *vc, int new_x, int new_y)
1458 vc->state.x = 0;
1460 if (new_x >= vc->vc_cols)
1461 vc->state.x = vc->vc_cols - 1;
1463 vc->state.x = new_x;
1466 if (vc->vc_decom) {
1467 min_y = vc->vc_top;
1468 max_y = vc->vc_bottom;
1471 max_y = vc->vc_rows;
1474 vc->state.y = min_y;
1476 vc->state.y = max_y - 1;
1478 vc->state.y = new_y;
1479 vc->vc_pos = vc->vc_origin + vc->state.y * vc->vc_size_row +
1480 (vc->state.x << 1);
1481 vc->vc_need_wrap = 0;
1485 static void gotoxay(struct vc_data *vc, int new_x, int new_y)
1487 gotoxy(vc, new_x, vc->vc_decom ? (vc->vc_top + new_y) : new_y);
1490 void scrollback(struct vc_data *vc)
1492 scrolldelta(-(vc->vc_rows / 2));
1495 void scrollfront(struct vc_data *vc, int lines)
1498 lines = vc->vc_rows / 2;
1502 static void lf(struct vc_data *vc)
1507 if (vc->state.y + 1 == vc->vc_bottom)
1508 con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_UP, 1);
1509 else if (vc->state.y < vc->vc_rows - 1) {
1510 vc->state.y++;
1511 vc->vc_pos += vc->vc_size_row;
1513 vc->vc_need_wrap = 0;
1514 notify_write(vc, '\n');
1517 static void ri(struct vc_data *vc)
1522 if (vc->state.y == vc->vc_top)
1523 con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_DOWN, 1);
1524 else if (vc->state.y > 0) {
1525 vc->state.y--;
1526 vc->vc_pos -= vc->vc_size_row;
1528 vc->vc_need_wrap = 0;
1531 static inline void cr(struct vc_data *vc)
1533 vc->vc_pos -= vc->state.x << 1;
1534 vc->vc_need_wrap = vc->state.x = 0;
1535 notify_write(vc, '\r');
1538 static inline void bs(struct vc_data *vc)
1540 if (vc->state.x) {
1541 vc->vc_pos -= 2;
1542 vc->state.x--;
1543 vc->vc_need_wrap = 0;
1544 notify_write(vc, '\b');
1548 static inline void del(struct vc_data *vc)
1553 static void csi_J(struct vc_data *vc, int vpar)
1560 vc_uniscr_clear_line(vc, vc->state.x,
1561 vc->vc_cols - vc->state.x);
1562 vc_uniscr_clear_lines(vc, vc->state.y + 1,
1563 vc->vc_rows - vc->state.y - 1);
1564 count = (vc->vc_scr_end - vc->vc_pos) >> 1;
1565 start = (unsigned short *)vc->vc_pos;
1568 vc_uniscr_clear_line(vc, 0, vc->state.x + 1);
1569 vc_uniscr_clear_lines(vc, 0, vc->state.y);
1570 count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
1571 start = (unsigned short *)vc->vc_origin;
1574 flush_scrollback(vc);
1577 vc_uniscr_clear_lines(vc, 0, vc->vc_rows);
1578 count = vc->vc_cols * vc->vc_rows;
1579 start = (unsigned short *)vc->vc_origin;
1584 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
1585 if (con_should_update(vc))
1586 do_update_region(vc, (unsigned long) start, count);
1587 vc->vc_need_wrap = 0;
1590 static void csi_K(struct vc_data *vc, int vpar)
1593 unsigned short *start = (unsigned short *)vc->vc_pos;
1599 count = vc->vc_cols - vc->state.x;
1602 offset = -vc->state.x;
1603 count = vc->state.x + 1;
1606 offset = -vc->state.x;
1607 count = vc->vc_cols;
1612 vc_uniscr_clear_line(vc, vc->state.x + offset, count);
1613 scr_memsetw(start + offset, vc->vc_video_erase_char, 2 * count);
1614 vc->vc_need_wrap = 0;
1615 if (con_should_update(vc))
1616 do_update_region(vc, (unsigned long)(start + offset), count);
1620 static void csi_X(struct vc_data *vc, unsigned int vpar)
1627 count = min(vpar, vc->vc_cols - vc->state.x);
1629 vc_uniscr_clear_line(vc, vc->state.x, count);
1630 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
1631 if (con_should_update(vc))
1632 vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, 1, count);
1633 vc->vc_need_wrap = 0;
1636 static void default_attr(struct vc_data *vc)
1638 vc->state.intensity = VCI_NORMAL;
1639 vc->state.italic = false;
1640 vc->state.underline = false;
1641 vc->state.reverse = false;
1642 vc->state.blink = false;
1643 vc->state.color = vc->vc_def_color;
1666 static void rgb_foreground(struct vc_data *vc, const struct rgb *c)
1679 vc->state.intensity = VCI_BOLD;
1681 vc->state.intensity = VCI_BOLD;
1683 vc->state.intensity = VCI_NORMAL;
1685 vc->state.color = (vc->state.color & 0xf0) | hue;
1688 static void rgb_background(struct vc_data *vc, const struct rgb *c)
1691 vc->state.color = (vc->state.color & 0x0f)
1704 static int vc_t416_color(struct vc_data *vc, int i,
1705 void(*set_color)(struct vc_data *vc, const struct rgb *c))
1710 if (i > vc->vc_npar)
1713 if (vc->vc_par[i] == 5 && i + 1 <= vc->vc_npar) {
1716 rgb_from_256(vc->vc_par[i], &c);
1717 } else if (vc->vc_par[i] == 2 && i + 3 <= vc->vc_npar) {
1719 c.r = vc->vc_par[i + 1];
1720 c.g = vc->vc_par[i + 2];
1721 c.b = vc->vc_par[i + 3];
1726 set_color(vc, &c);
1732 static void csi_m(struct vc_data *vc)
1736 for (i = 0; i <= vc->vc_npar; i++)
1737 switch (vc->vc_par[i]) {
1739 default_attr(vc);
1742 vc->state.intensity = VCI_BOLD;
1745 vc->state.intensity = VCI_HALF_BRIGHT;
1748 vc->state.italic = true;
1756 vc->state.underline = true;
1759 vc->state.blink = true;
1762 vc->state.reverse = true;
1768 vc->vc_translate = set_translate(vc->state.Gx_charset[vc->state.charset], vc);
1769 vc->vc_disp_ctrl = 0;
1770 vc->vc_toggle_meta = 0;
1776 vc->vc_translate = set_translate(IBMPC_MAP, vc);
1777 vc->vc_disp_ctrl = 1;
1778 vc->vc_toggle_meta = 0;
1784 vc->vc_translate = set_translate(IBMPC_MAP, vc);
1785 vc->vc_disp_ctrl = 1;
1786 vc->vc_toggle_meta = 1;
1789 vc->state.intensity = VCI_NORMAL;
1792 vc->state.italic = false;
1795 vc->state.underline = false;
1798 vc->state.blink = false;
1801 vc->state.reverse = false;
1804 i = vc_t416_color(vc, i, rgb_foreground);
1807 i = vc_t416_color(vc, i, rgb_background);
1810 vc->state.color = (vc->vc_def_color & 0x0f) |
1811 (vc->state.color & 0xf0);
1814 vc->state.color = (vc->vc_def_color & 0xf0) |
1815 (vc->state.color & 0x0f);
1818 if (vc->vc_par[i] >= 90 && vc->vc_par[i] <= 107) {
1819 if (vc->vc_par[i] < 100)
1820 vc->state.intensity = VCI_BOLD;
1821 vc->vc_par[i] -= 60;
1823 if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37)
1824 vc->state.color = color_table[vc->vc_par[i] - 30]
1825 | (vc->state.color & 0xf0);
1826 else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47)
1827 vc->state.color = (color_table[vc->vc_par[i] - 40] << 4)
1828 | (vc->state.color & 0x0f);
1831 update_attr(vc);
1840 static void cursor_report(struct vc_data *vc, struct tty_struct *tty)
1845 len = sprintf(buf, "\033[%d;%dR", vc->state.y +
1846 (vc->vc_decom ? vc->vc_top + 1 : 1),
1847 vc->state.x + 1);
1883 static void set_mode(struct vc_data *vc, int on_off)
1887 for (i = 0; i <= vc->vc_npar; i++)
1888 if (vc->vc_priv == EPdec) {
1889 switch(vc->vc_par[i]) { /* DEC private modes set/reset */
1892 set_kbd(vc, decckm);
1894 clr_kbd(vc, decckm);
1898 vc_resize(deccolm ? 132 : 80, vc->vc_rows);
1904 if (vc->vc_decscnm != on_off) {
1905 vc->vc_decscnm = on_off;
1906 invert_screen(vc, 0,
1907 vc->vc_screenbuf_size,
1909 update_attr(vc);
1913 vc->vc_decom = on_off;
1914 gotoxay(vc, 0, 0);
1917 vc->vc_decawm = on_off;
1921 set_kbd(vc, decarm);
1923 clr_kbd(vc, decarm);
1926 vc->vc_report_mouse = on_off ? 1 : 0;
1929 vc->vc_deccm = on_off;
1932 vc->vc_report_mouse = on_off ? 2 : 0;
1936 switch(vc->vc_par[i]) { /* ANSI modes set/reset */
1938 vc->vc_disp_ctrl = on_off;
1941 vc->vc_decim = on_off;
1945 set_kbd(vc, lnm);
1947 clr_kbd(vc, lnm);
1954 static void setterm_command(struct vc_data *vc)
1956 switch (vc->vc_par[0]) {
1958 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
1959 vc->vc_ulcolor = color_table[vc->vc_par[1]];
1960 if (vc->state.underline)
1961 update_attr(vc);
1965 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
1966 vc->vc_halfcolor = color_table[vc->vc_par[1]];
1967 if (vc->state.intensity == VCI_HALF_BRIGHT)
1968 update_attr(vc);
1972 vc->vc_def_color = vc->vc_attr;
1973 if (vc->vc_hi_font_mask == 0x100)
1974 vc->vc_def_color >>= 1;
1975 default_attr(vc);
1976 update_attr(vc);
1979 blankinterval = min(vc->vc_par[1], 60U) * 60;
1983 if (vc->vc_npar >= 1)
1984 vc->vc_bell_pitch = vc->vc_par[1];
1986 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
1989 if (vc->vc_npar >= 1)
1990 vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?
1991 msecs_to_jiffies(vc->vc_par[1]) : 0;
1993 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
1996 if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1))
1997 set_console(vc->vc_par[1] - 1);
2003 vesa_off_interval = min(vc->vc_par[1], 60U) * 60 * HZ;
2009 if (vc->vc_npar >= 1 && vc->vc_par[1] >= 50 &&
2010 vc->vc_par[1] <= USHRT_MAX)
2011 vc->vc_cur_blink_ms = vc->vc_par[1];
2013 vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;
2019 static void csi_at(struct vc_data *vc, unsigned int nr)
2021 if (nr > vc->vc_cols - vc->state.x)
2022 nr = vc->vc_cols - vc->state.x;
2025 insert_char(vc, nr);
2029 static void csi_L(struct vc_data *vc, unsigned int nr)
2031 if (nr > vc->vc_rows - vc->state.y)
2032 nr = vc->vc_rows - vc->state.y;
2035 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_DOWN, nr);
2036 vc->vc_need_wrap = 0;
2040 static void csi_P(struct vc_data *vc, unsigned int nr)
2042 if (nr > vc->vc_cols - vc->state.x)
2043 nr = vc->vc_cols - vc->state.x;
2046 delete_char(vc, nr);
2050 static void csi_M(struct vc_data *vc, unsigned int nr)
2052 if (nr > vc->vc_rows - vc->state.y)
2053 nr = vc->vc_rows - vc->state.y;
2056 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_UP, nr);
2057 vc->vc_need_wrap = 0;
2061 static void save_cur(struct vc_data *vc)
2063 memcpy(&vc->saved_state, &vc->state, sizeof(vc->state));
2067 static void restore_cur(struct vc_data *vc)
2069 memcpy(&vc->state, &vc->saved_state, sizeof(vc->state));
2071 gotoxy(vc, vc->state.x, vc->state.y);
2072 vc->vc_translate = set_translate(vc->state.Gx_charset[vc->state.charset],
2073 vc);
2074 update_attr(vc);
2075 vc->vc_need_wrap = 0;
2083 static void reset_terminal(struct vc_data *vc, int do_clear)
2087 vc->vc_top = 0;
2088 vc->vc_bottom = vc->vc_rows;
2089 vc->vc_state = ESnormal;
2090 vc->vc_priv = EPecma;
2091 vc->vc_translate = set_translate(LAT1_MAP, vc);
2092 vc->state.Gx_charset[0] = LAT1_MAP;
2093 vc->state.Gx_charset[1] = GRAF_MAP;
2094 vc->state.charset = 0;
2095 vc->vc_need_wrap = 0;
2096 vc->vc_report_mouse = 0;
2097 vc->vc_utf = default_utf8;
2098 vc->vc_utf_count = 0;
2100 vc->vc_disp_ctrl = 0;
2101 vc->vc_toggle_meta = 0;
2103 vc->vc_decscnm = 0;
2104 vc->vc_decom = 0;
2105 vc->vc_decawm = 1;
2106 vc->vc_deccm = global_cursor_default;
2107 vc->vc_decim = 0;
2109 vt_reset_keyboard(vc->vc_num);
2111 vc->vc_cursor_type = cur_default;
2112 vc->vc_complement_mask = vc->vc_s_complement_mask;
2114 default_attr(vc);
2115 update_attr(vc);
2117 bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2119 set_bit(i, vc->vc_tab_stop);
2121 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
2122 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
2123 vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;
2125 gotoxy(vc, 0, 0);
2126 save_cur(vc);
2128 csi_J(vc, 2);
2131 static void vc_setGx(struct vc_data *vc, unsigned int which, int c)
2133 unsigned char *charset = &vc->state.Gx_charset[which];
2150 if (vc->state.charset == which)
2151 vc->vc_translate = set_translate(*charset, vc);
2163 static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
2169 if (ansi_control_string(vc->vc_state) && c >= 8 && c <= 13)
2175 if (ansi_control_string(vc->vc_state))
2176 vc->vc_state = ESnormal;
2177 else if (vc->vc_bell_duration)
2178 kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration);
2181 bs(vc);
2184 vc->vc_pos -= (vc->state.x << 1);
2186 vc->state.x = find_next_bit(vc->vc_tab_stop,
2187 min(vc->vc_cols - 1, VC_TABSTOPS_COUNT),
2188 vc->state.x + 1);
2189 if (vc->state.x >= VC_TABSTOPS_COUNT)
2190 vc->state.x = vc->vc_cols - 1;
2192 vc->vc_pos += (vc->state.x << 1);
2193 notify_write(vc, '\t');
2196 lf(vc);
2197 if (!is_kbd(vc, lnm))
2201 cr(vc);
2204 vc->state.charset = 1;
2205 vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc);
2206 vc->vc_disp_ctrl = 1;
2209 vc->state.charset = 0;
2210 vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc);
2211 vc->vc_disp_ctrl = 0;
2214 vc->vc_state = ESnormal;
2217 vc->vc_state = ESesc;
2220 del(vc);
2223 vc->vc_state = ESsquare;
2226 switch(vc->vc_state) {
2228 vc->vc_state = ESnormal;
2231 vc->vc_state = ESsquare;
2234 vc->vc_state = ESnonstd;
2237 vc->vc_state = ESapc;
2240 vc->vc_state = ESpm;
2243 vc->vc_state = ESpercent;
2246 cr(vc);
2247 lf(vc);
2250 ri(vc);
2253 lf(vc);
2256 if (vc->state.x < VC_TABSTOPS_COUNT)
2257 set_bit(vc->state.x, vc->vc_tab_stop);
2260 vc->vc_state = ESdcs;
2266 save_cur(vc);
2269 restore_cur(vc);
2272 vc->vc_state = ESsetG0;
2275 vc->vc_state = ESsetG1;
2278 vc->vc_state = EShash;
2281 reset_terminal(vc, 1);
2284 clr_kbd(vc, kbdapplic);
2287 set_kbd(vc, kbdapplic);
2293 for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
2294 vc->vc_par[vc->vc_npar] = 0;
2295 vc->vc_npar = 0;
2296 vc->vc_state = ESpalette;
2299 reset_palette(vc);
2300 vc->vc_state = ESnormal;
2302 vc->vc_state = ESosc;
2304 vc->vc_state = ESnormal;
2308 vc->vc_par[vc->vc_npar++] = hex_to_bin(c);
2309 if (vc->vc_npar == 7) {
2310 int i = vc->vc_par[0] * 3, j = 1;
2311 vc->vc_palette[i] = 16 * vc->vc_par[j++];
2312 vc->vc_palette[i++] += vc->vc_par[j++];
2313 vc->vc_palette[i] = 16 * vc->vc_par[j++];
2314 vc->vc_palette[i++] += vc->vc_par[j++];
2315 vc->vc_palette[i] = 16 * vc->vc_par[j++];
2316 vc->vc_palette[i] += vc->vc_par[j];
2317 set_palette(vc);
2318 vc->vc_state = ESnormal;
2321 vc->vc_state = ESnormal;
2324 for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
2325 vc->vc_par[vc->vc_npar] = 0;
2326 vc->vc_npar = 0;
2327 vc->vc_state = ESgetpars;
2329 vc->vc_state=ESfunckey;
2334 vc->vc_priv = EPdec;
2337 vc->vc_priv = EPgt;
2340 vc->vc_priv = EPeq;
2343 vc->vc_priv = EPlt;
2346 vc->vc_priv = EPecma;
2349 if (c == ';' && vc->vc_npar < NPAR - 1) {
2350 vc->vc_npar++;
2353 vc->vc_par[vc->vc_npar] *= 10;
2354 vc->vc_par[vc->vc_npar] += c - '0';
2358 vc->vc_state = EScsiignore;
2361 vc->vc_state = ESnormal;
2364 if (vc->vc_priv <= EPdec)
2365 set_mode(vc, 1);
2368 if (vc->vc_priv <= EPdec)
2369 set_mode(vc, 0);
2372 if (vc->vc_priv == EPdec) {
2373 if (vc->vc_par[0])
2374 vc->vc_cursor_type =
2375 CUR_MAKE(vc->vc_par[0],
2376 vc->vc_par[1],
2377 vc->vc_par[2]);
2379 vc->vc_cursor_type = cur_default;
2384 if (vc->vc_priv == EPdec) {
2386 if (vc->vc_par[0])
2387 vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1];
2389 vc->vc_complement_mask = vc->vc_s_complement_mask;
2394 if (vc->vc_priv == EPecma) {
2395 if (vc->vc_par[0] == 5)
2397 else if (vc->vc_par[0] == 6)
2398 cursor_report(vc, tty);
2402 if (vc->vc_priv != EPecma) {
2403 vc->vc_priv = EPecma;
2408 if (vc->vc_par[0])
2409 vc->vc_par[0]--;
2410 gotoxy(vc, vc->vc_par[0], vc->state.y);
2413 if (!vc->vc_par[0])
2414 vc->vc_par[0]++;
2415 gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]);
2418 if (!vc->vc_par[0])
2419 vc->vc_par[0]++;
2420 gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]);
2423 if (!vc->vc_par[0])
2424 vc->vc_par[0]++;
2425 gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y);
2428 if (!vc->vc_par[0])
2429 vc->vc_par[0]++;
2430 gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y);
2433 if (!vc->vc_par[0])
2434 vc->vc_par[0]++;
2435 gotoxy(vc, 0, vc->state.y + vc->vc_par[0]);
2438 if (!vc->vc_par[0])
2439 vc->vc_par[0]++;
2440 gotoxy(vc, 0, vc->state.y - vc->vc_par[0]);
2443 if (vc->vc_par[0])
2444 vc->vc_par[0]--;
2445 gotoxay(vc, vc->state.x ,vc->vc_par[0]);
2448 if (vc->vc_par[0])
2449 vc->vc_par[0]--;
2450 if (vc->vc_par[1])
2451 vc->vc_par[1]--;
2452 gotoxay(vc, vc->vc_par[1], vc->vc_par[0]);
2455 csi_J(vc, vc->vc_par[0]);
2458 csi_K(vc, vc->vc_par[0]);
2461 csi_L(vc, vc->vc_par[0]);
2464 csi_M(vc, vc->vc_par[0]);
2467 csi_P(vc, vc->vc_par[0]);
2470 if (!vc->vc_par[0])
2474 if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT)
2475 set_bit(vc->state.x, vc->vc_tab_stop);
2476 else if (vc->vc_par[0] == 3)
2477 bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2480 csi_m(vc);
2484 if (vc->vc_par[0] < 4)
2485 vt_set_led_state(vc->vc_num,
2486 (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
2489 if (!vc->vc_par[0])
2490 vc->vc_par[0]++;
2491 if (!vc->vc_par[1])
2492 vc->vc_par[1] = vc->vc_rows;
2494 if (vc->vc_par[0] < vc->vc_par[1] &&
2495 vc->vc_par[1] <= vc->vc_rows) {
2496 vc->vc_top = vc->vc_par[0] - 1;
2497 vc->vc_bottom = vc->vc_par[1];
2498 gotoxay(vc, 0, 0);
2502 save_cur(vc);
2505 restore_cur(vc);
2508 csi_X(vc, vc->vc_par[0]);
2511 csi_at(vc, vc->vc_par[0]);
2514 setterm_command(vc);
2521 vc->vc_state = ESnormal;
2524 vc->vc_state = ESnormal;
2527 vc->vc_utf = 0;
2531 vc->vc_utf = 1;
2536 vc->vc_state = ESnormal;
2539 vc->vc_state = ESnormal;
2542 vc->vc_video_erase_char =
2543 (vc->vc_video_erase_char & 0xff00) | 'E';
2544 csi_J(vc, 2);
2545 vc->vc_video_erase_char =
2546 (vc->vc_video_erase_char & 0xff00) | ' ';
2547 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
2551 vc_setGx(vc, 0, c);
2552 vc->vc_state = ESnormal;
2555 vc_setGx(vc, 1, c);
2556 vc->vc_state = ESnormal;
2567 vc->vc_state = ESnormal;
2613 static void con_flush(struct vc_data *vc, struct vc_draw_region *draw)
2618 vc->vc_sw->con_putcs(vc, (u16 *)draw->from,
2619 (u16 *)draw->to - (u16 *)draw->from, vc->state.y,
2624 static inline int vc_translate_ascii(const struct vc_data *vc, int c)
2627 if (vc->vc_toggle_meta)
2630 return vc->vc_translate[c];
2651 * @vc: virtual console
2659 static int vc_translate_unicode(struct vc_data *vc, int c, bool *rescan)
2669 if (!vc->vc_utf_count)
2672 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
2673 vc->vc_npar++;
2674 if (--vc->vc_utf_count)
2678 c = vc->vc_utf_char;
2680 if (c <= utf8_length_changes[vc->vc_npar - 1] ||
2681 c > utf8_length_changes[vc->vc_npar])
2688 if (vc->vc_utf_count) {
2691 vc->vc_utf_count = 0;
2700 vc->vc_npar = 0;
2702 vc->vc_utf_count = 1;
2703 vc->vc_utf_char = (c & 0x1f);
2705 vc->vc_utf_count = 2;
2706 vc->vc_utf_char = (c & 0x0f);
2708 vc->vc_utf_count = 3;
2709 vc->vc_utf_char = (c & 0x07);
2711 vc->vc_utf_count = 4;
2712 vc->vc_utf_char = (c & 0x03);
2714 vc->vc_utf_count = 5;
2715 vc->vc_utf_char = (c & 0x01);
2725 static int vc_translate(struct vc_data *vc, int *c, bool *rescan)
2728 if (vc->vc_state != ESnormal)
2731 if (vc->vc_utf && !vc->vc_disp_ctrl)
2732 return *c = vc_translate_unicode(vc, *c, rescan);
2735 return vc_translate_ascii(vc, *c);
2738 static inline unsigned char vc_invert_attr(const struct vc_data *vc)
2740 if (!vc->vc_can_do_color)
2741 return vc->vc_attr ^ 0x08;
2743 if (vc->vc_hi_font_mask == 0x100)
2744 return (vc->vc_attr & 0x11) |
2745 ((vc->vc_attr & 0xe0) >> 4) |
2746 ((vc->vc_attr & 0x0e) << 4);
2748 return (vc->vc_attr & 0x88) |
2749 ((vc->vc_attr & 0x70) >> 4) |
2750 ((vc->vc_attr & 0x07) << 4);
2753 static bool vc_is_control(struct vc_data *vc, int tc, int c)
2765 if (vc->vc_state != ESnormal)
2781 if (vc->vc_disp_ctrl)
2784 return vc->vc_utf || (CTRL_ACTION & BIT(c));
2787 if (c == 127 && !vc->vc_disp_ctrl)
2796 static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
2800 unsigned char vc_attr = vc->vc_attr;
2801 u16 himask = vc->vc_hi_font_mask, charmask = himask ? 0x1ff : 0xff;
2805 if (vc->vc_utf && !vc->vc_disp_ctrl) {
2811 tc = conv_uni_to_pc(vc, tc);
2817 if ((!vc->vc_utf || vc->vc_disp_ctrl || c < 128) &&
2833 tc = conv_uni_to_pc(vc, 0xfffd);
2836 tc = conv_uni_to_pc(vc, '?');
2840 vc_attr = vc_invert_attr(vc);
2841 con_flush(vc, draw);
2848 if (vc->vc_need_wrap || vc->vc_decim)
2849 con_flush(vc, draw);
2850 if (vc->vc_need_wrap) {
2851 cr(vc);
2852 lf(vc);
2854 if (vc->vc_decim)
2855 insert_char(vc, 1);
2856 vc_uniscr_putc(vc, next_c);
2863 scr_writew(tc, (u16 *)vc->vc_pos);
2865 if (con_should_update(vc) && draw->x < 0) {
2866 draw->x = vc->state.x;
2867 draw->from = vc->vc_pos;
2869 if (vc->state.x == vc->vc_cols - 1) {
2870 vc->vc_need_wrap = vc->vc_decawm;
2871 draw->to = vc->vc_pos + 2;
2873 vc->state.x++;
2874 draw->to = (vc->vc_pos += 2);
2881 tc = conv_uni_to_pc(vc, ' ');
2886 notify_write(vc, c);
2889 con_flush(vc, draw);
2902 struct vc_data *vc;
2910 vc = tty->driver_data;
2911 if (vc == NULL) {
2917 currcons = vc->vc_num;
2927 if (con_is_fg(vc))
2928 hide_cursor(vc);
2930 param.vc = vc;
2941 tc = vc_translate(vc, &c, &rescan);
2950 if (vc_is_control(vc, tc, c)) {
2951 con_flush(vc, &draw);
2952 do_con_trol(tty, vc, orig);
2956 if (vc_con_write_normal(vc, tc, c, &draw) < 0)
2962 con_flush(vc, &draw);
2963 vc_uniscr_debug_check(vc);
2965 notify_update(vc);
2999 struct vc_data *vc = vc_cons[fg_console].d;
3001 if (vc->vc_mode == KD_TEXT && vc->vc_sw->con_scrolldelta)
3002 vc->vc_sw->con_scrolldelta(vc, scrollback_delta);
3016 struct vc_data *vc = vc_cons[fg_console].d;
3019 (vc->vt_mode.mode == VT_AUTO && vc->vc_mode == KD_GRAPHICS)) {
3081 struct vc_data *vc = vc_cons[fg_console].d;
3096 vc = vc_cons[kmsg_console - 1].d;
3104 if (vc->vc_mode != KD_TEXT)
3108 if (con_is_fg(vc))
3109 hide_cursor(vc);
3111 start = (ushort *)vc->vc_pos;
3112 start_x = vc->state.x;
3116 if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) {
3117 if (cnt && con_is_visible(vc))
3118 vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x);
3121 bs(vc);
3122 start = (ushort *)vc->vc_pos;
3123 start_x = vc->state.x;
3127 lf(vc);
3128 cr(vc);
3129 start = (ushort *)vc->vc_pos;
3130 start_x = vc->state.x;
3134 vc_uniscr_putc(vc, c);
3135 scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos);
3136 notify_write(vc, c);
3138 if (vc->state.x == vc->vc_cols - 1) {
3139 vc->vc_need_wrap = 1;
3141 vc->vc_pos += 2;
3142 vc->state.x++;
3145 if (cnt && con_is_visible(vc))
3146 vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x);
3147 set_cursor(vc);
3148 notify_update(vc);
3332 struct vc_data *vc = tty->driver_data;
3334 wake_up_interruptible(&vc->paste_wait);
3367 struct vc_data *vc;
3374 vc = tty->driver_data;
3375 if (vc)
3376 set_cursor(vc);
3386 struct vc_data *vc;
3394 vc = vc_cons[currcons].d;
3397 if (vc->port.tty) {
3402 ret = tty_port_install(&vc->port, driver, tty);
3406 tty->driver_data = vc;
3407 vc->port.tty = tty;
3408 tty_port_get(&vc->port);
3414 if (vc->vc_utf)
3437 struct vc_data *vc = tty->driver_data;
3438 BUG_ON(vc == NULL);
3440 vc->port.tty = NULL;
3446 struct vc_data *vc = tty->driver_data;
3448 tty_port_put(&vc->port);
3458 static void vc_init(struct vc_data *vc, unsigned int rows,
3463 vc->vc_cols = cols;
3464 vc->vc_rows = rows;
3465 vc->vc_size_row = cols << 1;
3466 vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
3468 set_origin(vc);
3469 vc->vc_pos = vc->vc_origin;
3470 reset_vc(vc);
3472 vc->vc_palette[k++] = default_red[j] ;
3473 vc->vc_palette[k++] = default_grn[j] ;
3474 vc->vc_palette[k++] = default_blu[j] ;
3476 vc->vc_def_color = default_color;
3477 vc->vc_ulcolor = default_underline_color;
3478 vc->vc_itcolor = default_italic_color;
3479 vc->vc_halfcolor = 0x08; /* grey */
3480 init_waitqueue_head(&vc->paste_wait);
3481 reset_terminal(vc, do_clear);
3493 struct vc_data *vc;
3529 vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
3531 tty_port_init(&vc->port);
3532 visual_init(vc, currcons, 1);
3533 /* Assuming vc->vc_{cols,rows,screenbuf_size} are sane here. */
3534 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT);
3535 vc_init(vc, vc->vc_rows, vc->vc_cols,
3536 currcons || !vc->vc_sw->con_save_screen);
3539 master_display_fg = vc = vc_cons[currcons].d;
3540 set_origin(vc);
3541 save_screen(vc);
3542 gotoxy(vc, vc->state.x, vc->state.y);
3543 csi_J(vc, 0);
3544 update_screen(vc);
3546 vc->vc_can_do_color ? "colour" : "mono",
3547 display_desc, vc->vc_cols, vc->vc_rows);
3601 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
3684 struct vc_data *vc = vc_cons[i].d;
3691 if (!vc || !vc->vc_sw)
3696 if (con_is_visible(vc)) {
3698 save_screen(vc);
3701 old_was_color = vc->vc_can_do_color;
3702 vc->vc_sw->con_deinit(vc);
3703 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
3704 visual_init(vc, i, 0);
3705 set_origin(vc);
3706 update_attr(vc);
3712 if (old_was_color != vc->vc_can_do_color)
3713 clear_buffer_attributes(vc);
3720 struct vc_data *vc = vc_cons[j].d;
3723 vc->vc_can_do_color ? "colour" : "mono",
3724 desc, vc->vc_cols, vc->vc_rows);
3727 vc = vc_cons[k].d;
3728 update_screen(vc);
4015 * @vc: virtual console
4019 bool con_is_visible(const struct vc_data *vc)
4023 return *vc->vc_display_fg == vc;
4029 * @vc: virtual console
4039 int con_debug_enter(struct vc_data *vc)
4046 saved_vc_mode = vc->vc_mode;
4048 vc->vc_mode = KD_TEXT;
4050 if (vc->vc_sw->con_debug_enter)
4051 ret = vc->vc_sw->con_debug_enter(vc);
4054 if (vc->vc_rows < 999) {
4063 snprintf(lns, 4, "%i", vc->vc_rows);
4067 if (vc->vc_cols < 999) {
4076 snprintf(cols, 4, "%i", vc->vc_cols);
4097 struct vc_data *vc;
4106 vc = vc_cons[fg_console].d;
4107 if (vc->vc_sw->con_debug_leave)
4108 ret = vc->vc_sw->con_debug_leave(vc);
4356 struct vc_data *vc = vc_cons[fg_console].d;
4366 vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0);
4373 hide_cursor(vc);
4374 save_screen(vc);
4375 vc->vc_sw->con_blank(vc, -1, 1);
4378 set_origin(vc);
4385 if (vc->vc_mode != KD_TEXT) {
4390 hide_cursor(vc);
4394 save_screen(vc);
4396 i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0);
4399 set_origin(vc);
4408 vt_event_post(VT_EVENT_BLANK, vc->vc_num, vc->vc_num);
4417 struct vc_data *vc;
4437 vc = vc_cons[fg_console].d;
4438 if (vc->vc_mode != KD_TEXT)
4447 if (vc->vc_sw->con_blank(vc, 0, leaving_gfx))
4449 update_screen(vc);
4452 set_palette(vc);
4453 set_cursor(vc);
4454 vt_event_post(VT_EVENT_UNBLANK, vc->vc_num, vc->vc_num);
4512 static void set_palette(struct vc_data *vc)
4516 if (vc->vc_mode != KD_GRAPHICS && vc->vc_sw->con_set_palette)
4517 vc->vc_sw->con_set_palette(vc, color_table);
4573 void reset_palette(struct vc_data *vc)
4577 vc->vc_palette[k++] = default_red[j];
4578 vc->vc_palette[k++] = default_grn[j];
4579 vc->vc_palette[k++] = default_blu[j];
4581 set_palette(vc);
4599 static int con_font_get(struct vc_data *vc, struct console_font_op *op)
4613 if (vc->vc_mode != KD_TEXT)
4615 else if (vc->vc_sw->con_font_get)
4616 rc = vc->vc_sw->con_font_get(vc, &font);
4645 static int con_font_set(struct vc_data *vc, struct console_font_op *op)
4651 if (vc->vc_mode != KD_TEXT)
4672 if (vc->vc_mode != KD_TEXT)
4674 else if (vc->vc_sw->con_font_set) {
4675 if (vc_is_sel(vc))
4677 rc = vc->vc_sw->con_font_set(vc, &font, op->flags);
4685 static int con_font_default(struct vc_data *vc, struct console_font_op *op)
4701 if (vc->vc_mode != KD_TEXT) {
4705 if (vc->vc_sw->con_font_default) {
4706 if (vc_is_sel(vc))
4708 rc = vc->vc_sw->con_font_default(vc, &font, s);
4719 int con_font_op(struct vc_data *vc, struct console_font_op *op)
4723 return con_font_set(vc, op);
4725 return con_font_get(vc, op);
4727 return con_font_default(vc, op);
4740 u16 screen_glyph(const struct vc_data *vc, int offset)
4742 u16 w = scr_readw(screenpos(vc, offset, true));
4745 if (w & vc->vc_hi_font_mask)
4751 u32 screen_glyph_unicode(const struct vc_data *vc, int n)
4753 struct uni_screen *uniscr = get_vc_uniscr(vc);
4756 return uniscr->lines[n / vc->vc_cols][n % vc->vc_cols];
4757 return inverse_translate(vc, screen_glyph(vc, n * 2), 1);
4762 unsigned short *screen_pos(const struct vc_data *vc, int w_offset, bool viewed)
4764 return screenpos(vc, 2 * w_offset, viewed);
4768 void getconsxy(const struct vc_data *vc, unsigned char xy[static 2])
4771 xy[0] = min(vc->state.x, 0xFFu);
4772 xy[1] = min(vc->state.y, 0xFFu);
4775 void putconsxy(struct vc_data *vc, unsigned char xy[static const 2])
4777 hide_cursor(vc);
4778 gotoxy(vc, xy[0], xy[1]);
4779 set_cursor(vc);
4782 u16 vcs_scr_readw(const struct vc_data *vc, const u16 *org)
4784 if ((unsigned long)org == vc->vc_pos && softcursor_original != -1)
4789 void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
4792 if ((unsigned long)org == vc->vc_pos) {
4794 add_softcursor(vc);
4798 void vcs_scr_updated(struct vc_data *vc)
4800 notify_update(vc);