Lines Matching +full:display +full:- +full:rows

1 // SPDX-License-Identifier: GPL-2.0
17 * Code to check for different video-cards mostly by Galen Hunt,
18 * <g-hunt@ee.utah.edu>
20 * Rudimentary ISO 10646/Unicode/UTF-8 character set support by
21 * Markus Kuhn, <mskuhn@immd4.informatik.uni-erlangen.de>.
26 * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94
29 * User-defined bell sound, new setterm control sequences and printk
30 * redirection by Martin Mares <mj@k332.feld.cvut.cz> 19-Nov-95
35 * <geert@linux-m68k.org>, Jan 1997.
39 * - Arno Griffioen <arno@usn.nl>
40 * - David Carter <carter@cs.bris.ac.uk>
55 * by Emmanuel Marty <core@ggi-project.org>, April 1998
60 * Removed old-style timers, introduced console_timer, made timer
61 * deletion SMP-safe. 17Jun00, Andrew Morton
66 * Fixed UTF-8 mode so alternate charset modes always work according
157 #define vt_get_kmsg_redirect() vt_kmsg_redirect(-1)
161 int global_cursor_default = -1;
195 int want_console = -1;
204 * For each existing display, we have a pointer to console currently visible
205 * on that display, allowing consoles other than fg_console to be refreshed
206 * appropriately. Unless the low-level driver supplies its own display_fg
207 * variable, we use this one for the "master display".
213 * console since the code is (and always was) not re-entrant, so we schedule
214 * all flip requests to process context with schedule-task() and run it from
276 * Low-Level Functions
281 return vc->vc_num == fg_console;
292 unsigned long origin = viewed ? vc->vc_visible_origin : vc->vc_origin;
299 if (vc->vc_sw->con_putc)
300 vc->vc_sw->con_putc(vc, ca, y, x);
302 vc->vc_sw->con_putcs(vc, &ca, 1, y, x);
321 * Code to manage unicode-based screen buffers
329 static u32 **vc_uniscr_alloc(unsigned int cols, unsigned int rows)
336 memsize = col_size * rows;
337 memsize += rows * sizeof(*uni_lines);
343 p = uni_lines + rows;
344 for (i = 0; i < rows; i++) {
359 vc_uniscr_free(vc->vc_uni_lines);
360 vc->vc_uni_lines = new_uni_lines;
365 if (vc->vc_uni_lines)
366 vc->vc_uni_lines[vc->state.y][vc->state.x] = uc;
371 if (vc->vc_uni_lines) {
372 u32 *ln = vc->vc_uni_lines[vc->state.y];
373 unsigned int x = vc->state.x, cols = vc->vc_cols;
375 memmove(&ln[x + nr], &ln[x], (cols - x - nr) * sizeof(*ln));
382 if (vc->vc_uni_lines) {
383 u32 *ln = vc->vc_uni_lines[vc->state.y];
384 unsigned int x = vc->state.x, cols = vc->vc_cols;
386 memmove(&ln[x], &ln[x + nr], (cols - x - nr) * sizeof(*ln));
387 memset32(&ln[cols - nr], ' ', nr);
394 if (vc->vc_uni_lines)
395 memset32(&vc->vc_uni_lines[vc->state.y][x], ' ', nr);
401 if (vc->vc_uni_lines)
402 while (nr--)
403 memset32(vc->vc_uni_lines[y++], ' ', vc->vc_cols);
432 u32 **uni_lines = vc->vc_uni_lines;
433 unsigned int size = bottom - top;
439 juggle_array(&uni_lines[top], size, size - nr);
443 vc_uniscr_clear_lines(vc, bottom - nr, nr);
465 if (dst_cols - src_cols)
466 memset32(dst_line + src_cols, ' ', dst_cols - src_cols);
482 * In particular, -ENODATA is returned if the console is not in UTF-8 mode.
492 if (!vc->vc_utf)
493 return -ENODATA;
495 if (vc->vc_uni_lines)
498 uni_lines = vc_uniscr_alloc(vc->vc_cols, vc->vc_rows);
500 return -ENOMEM;
508 p = (unsigned short *)vc->vc_origin;
509 mask = vc->vc_hi_font_mask | 0xff;
510 for (y = 0; y < vc->vc_rows; y++) {
512 for (x = 0; x < vc->vc_cols; x++) {
518 vc->vc_uni_lines = uni_lines;
531 u32 **uni_lines = vc->vc_uni_lines;
532 int offset = row * vc->vc_size_row + col * 2;
539 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
545 row = (pos - vc->vc_origin) / vc->vc_size_row;
546 col = ((pos - vc->vc_origin) % vc->vc_size_row) / 2;
552 * synchronize with console display drivers for a scrollback
556 int mask = vc->vc_hi_font_mask | 0xff;
558 while (nr--) {
569 unsigned int rows = bottom - top;
573 nr = rows - 1;
574 if (bottom > vc->vc_rows || top >= bottom || nr < 1)
579 vc->vc_sw->con_scroll(vc, top, bottom, dir, nr))
582 src = clear = (u16 *)(vc->vc_origin + vc->vc_size_row * top);
583 dst = (u16 *)(vc->vc_origin + vc->vc_size_row * (top + nr));
586 clear = src + (rows - nr) * vc->vc_cols;
589 scr_memmovew(dst, src, (rows - nr) * vc->vc_size_row);
590 scr_memsetw(clear, vc->vc_video_erase_char, vc->vc_size_row * nr);
598 offset = (start - vc->vc_origin) / 2;
599 xx = offset % vc->vc_cols;
600 yy = offset / vc->vc_cols;
606 while (xx < vc->vc_cols && count) {
609 vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
616 count--;
619 vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
639 /* Structure of attributes is hardware-dependent */
645 if (vc->vc_sw->con_build_attr)
646 return vc->vc_sw->con_build_attr(vc, _color, _intensity,
651 * mode (!can_do_color). The formerly used MDA (monochrome display
661 if (!vc->vc_can_do_color)
668 a = (a & 0xF0) | vc->vc_itcolor;
670 a = (a & 0xf0) | vc->vc_ulcolor;
672 a = (a & 0xf0) | vc->vc_halfcolor;
679 if (vc->vc_hi_font_mask == 0x100)
687 vc->vc_attr = build_attr(vc, vc->state.color, vc->state.intensity,
688 vc->state.blink, vc->state.underline,
689 vc->state.reverse ^ vc->vc_decscnm, vc->state.italic);
690 vc->vc_video_erase_char = ' ' | (build_attr(vc, vc->state.color,
691 VCI_NORMAL, vc->state.blink, false,
692 vc->vc_decscnm, false) << 8);
704 if (vc->vc_sw->con_invert_region) {
705 vc->vc_sw->con_invert_region(vc, p, count);
711 if (!vc->vc_can_do_color) {
712 while (cnt--) {
718 } else if (vc->vc_hi_font_mask == 0x100) {
719 while (cnt--) {
728 while (cnt--) {
747 static int old_offset = -1;
753 if (old_offset != -1 && old_offset >= 0 &&
754 old_offset < vc->vc_screenbuf_size) {
763 if (offset != -1 && offset >= 0 &&
764 offset < vc->vc_screenbuf_size) {
768 new = old ^ vc->vc_complement_mask;
771 oldx = (offset >> 1) % vc->vc_cols;
772 oldy = (offset >> 1) / vc->vc_cols;
781 unsigned short *p = (unsigned short *) vc->vc_pos;
784 scr_memmovew(p + nr, p, (vc->vc_cols - vc->state.x - nr) * 2);
785 scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
786 vc->vc_need_wrap = 0;
789 vc->vc_cols - vc->state.x);
794 unsigned short *p = (unsigned short *) vc->vc_pos;
797 scr_memmovew(p, p + nr, (vc->vc_cols - vc->state.x - nr) * 2);
798 scr_memsetw(p + vc->vc_cols - vc->state.x - nr, vc->vc_video_erase_char,
800 vc->vc_need_wrap = 0;
803 vc->vc_cols - vc->state.x);
806 static int softcursor_original = -1;
810 int i = scr_readw((u16 *) vc->vc_pos);
811 u32 type = vc->vc_cursor_type;
815 if (softcursor_original != -1)
825 scr_writew(i, (u16 *)vc->vc_pos);
827 con_putc(vc, i, vc->state.y, vc->state.x);
832 if (softcursor_original != -1) {
833 scr_writew(softcursor_original, (u16 *)vc->vc_pos);
835 con_putc(vc, softcursor_original, vc->state.y,
836 vc->state.x);
837 softcursor_original = -1;
846 vc->vc_sw->con_cursor(vc, false);
852 if (!con_is_fg(vc) || console_blanked || vc->vc_mode == KD_GRAPHICS)
854 if (vc->vc_deccm) {
858 if (CUR_SIZE(vc->vc_cursor_type) != CUR_NONE)
859 vc->vc_sw->con_cursor(vc, true);
869 !vc->vc_sw->con_set_origin ||
870 !vc->vc_sw->con_set_origin(vc))
871 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
872 vc->vc_visible_origin = vc->vc_origin;
873 vc->vc_scr_end = vc->vc_origin + vc->vc_screenbuf_size;
874 vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->state.y +
875 2 * vc->state.x;
882 if (vc->vc_sw->con_save_screen)
883 vc->vc_sw->con_save_screen(vc);
901 vc->vc_sw->con_switch(vc);
911 unsigned short *p = (unsigned short *)vc->vc_origin;
912 int count = vc->vc_screenbuf_size / 2;
913 int mask = vc->vc_hi_font_mask | 0xff;
915 for (; count > 0; count--, p++) {
916 scr_writew((scr_readw(p)&mask) | (vc->vc_video_erase_char & ~mask), p);
938 *vc->vc_display_fg = vc;
939 fg_console = vc->vc_num;
946 sysfs_notify(&tty0dev->kobj, NULL, "active");
954 int old_was_color = vc->vc_can_do_color;
957 update = vc->vc_sw->con_switch(vc);
960 * If console changed from mono<->color, the best we can do
965 if (old_was_color != vc->vc_can_do_color) {
970 if (update && vc->vc_mode != KD_GRAPHICS)
971 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
992 /* ++Geert: vc->vc_sw->con_init determines console size */
993 if (vc->vc_sw)
994 module_put(vc->vc_sw->owner);
995 vc->vc_sw = conswitchp;
998 vc->vc_sw = con_driver_map[num];
1000 __module_get(vc->vc_sw->owner);
1001 vc->vc_num = num;
1002 vc->vc_display_fg = &master_display_fg;
1003 if (vc->uni_pagedict_loc)
1005 vc->uni_pagedict_loc = &vc->uni_pagedict;
1006 vc->uni_pagedict = NULL;
1007 vc->vc_hi_font_mask = 0;
1008 vc->vc_complement_mask = 0;
1009 vc->vc_can_do_color = 0;
1010 vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;
1011 vc->vc_sw->con_init(vc, init);
1012 if (!vc->vc_complement_mask)
1013 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1014 vc->vc_s_complement_mask = vc->vc_complement_mask;
1015 vc->vc_size_row = vc->vc_cols << 1;
1016 vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;
1022 vc->vc_sw->con_deinit(vc);
1023 module_put(vc->vc_sw->owner);
1038 * Change # of rows and columns (0 means unchanged/the size of fg_console)
1054 return -ENXIO;
1063 point is still up-to-date and the comment still has its value
1064 even if only as a historical artifact. --mj, July 1998 */
1067 return -ENOMEM;
1070 tty_port_init(&vc->port);
1071 vc->port.ops = &vc_port_ops;
1076 if (!*vc->uni_pagedict_loc)
1079 err = -EINVAL;
1080 if (vc->vc_cols > VC_MAXCOL || vc->vc_rows > VC_MAXROW ||
1081 vc->vc_screenbuf_size > KMALLOC_MAX_SIZE || !vc->vc_screenbuf_size)
1083 err = -ENOMEM;
1084 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_KERNEL);
1085 if (!vc->vc_screenbuf)
1090 if (global_cursor_default == -1)
1108 /* Resizes the resolution of the display adapater */
1111 if (vc->vc_sw->con_resize)
1112 err = vc->vc_sw->con_resize(vc, width, height, from_user);
1118 * vc_do_resize - resizing method for the tty
1145 return -EINVAL;
1147 new_cols = (cols ? cols : vc->vc_cols);
1148 new_rows = (lines ? lines : vc->vc_rows);
1152 if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) {
1157 * yres/xres equal to a number non-multiple of vc_font.height
1162 * if above, and this causes the fbcon_display->vrows to become
1163 * negative and it eventually leads to out-of-bound
1173 return -EINVAL;
1176 return -ENOMEM;
1178 if (vc->vc_uni_lines) {
1182 return -ENOMEM;
1189 old_rows = vc->vc_rows;
1190 old_row_size = vc->vc_size_row;
1199 vc->vc_rows = new_rows;
1200 vc->vc_cols = new_cols;
1201 vc->vc_size_row = new_row_size;
1202 vc->vc_screenbuf_size = new_screen_size;
1205 rrem = new_row_size - rlth;
1206 old_origin = vc->vc_origin;
1210 if (vc->state.y > new_rows) {
1211 if (old_rows - vc->state.y < new_rows) {
1216 first_copied_row = (old_rows - new_rows);
1222 first_copied_row = (vc->state.y - new_rows/2);
1230 vc->vc_uni_lines, rlth/2, first_copied_row,
1241 vc->vc_video_erase_char, rrem);
1246 scr_memsetw((void *)new_origin, vc->vc_video_erase_char,
1247 new_scr_end - new_origin);
1248 oldscreen = vc->vc_screenbuf;
1249 vc->vc_screenbuf = newscreen;
1250 vc->vc_screenbuf_size = new_screen_size;
1255 vc->vc_top = 0;
1256 vc->vc_bottom = vc->vc_rows;
1257 gotoxy(vc, vc->state.x, vc->state.y);
1265 ws.ws_row = vc->vc_rows;
1266 ws.ws_col = vc->vc_cols;
1267 ws.ws_ypixel = vc->vc_scan_lines;
1273 vt_event_post(VT_EVENT_RESIZE, vc->vc_num, vc->vc_num);
1279 * __vc_resize - resize a VT
1282 * @rows: rows
1289 * and @vc->port.tty.
1291 int __vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows,
1294 return vc_do_resize(vc->port.tty, vc, cols, rows, from_user);
1299 * vt_resize - resize a VT
1311 struct vc_data *vc = tty->driver_data;
1315 ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row, false);
1334 put_pid(vc->vt_pid);
1336 kfree(vc->vc_screenbuf);
1348 #define set_kbd(vc, x) vt_set_kbd_mode_bit((vc)->vc_num, (x))
1349 #define clr_kbd(vc, x) vt_clr_kbd_mode_bit((vc)->vc_num, (x))
1350 #define is_kbd(vc, x) vt_get_kbd_mode_bit((vc)->vc_num, (x))
1393 vc->state.x = 0;
1395 if (new_x >= vc->vc_cols)
1396 vc->state.x = vc->vc_cols - 1;
1398 vc->state.x = new_x;
1401 if (vc->vc_decom) {
1402 min_y = vc->vc_top;
1403 max_y = vc->vc_bottom;
1406 max_y = vc->vc_rows;
1409 vc->state.y = min_y;
1411 vc->state.y = max_y - 1;
1413 vc->state.y = new_y;
1414 vc->vc_pos = vc->vc_origin + vc->state.y * vc->vc_size_row +
1415 (vc->state.x << 1);
1416 vc->vc_need_wrap = 0;
1422 gotoxy(vc, new_x, vc->vc_decom ? (vc->vc_top + new_y) : new_y);
1427 scrolldelta(-(vc->vc_rows / 2));
1433 lines = vc->vc_rows / 2;
1442 if (vc->state.y + 1 == vc->vc_bottom)
1443 con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_UP, 1);
1444 else if (vc->state.y < vc->vc_rows - 1) {
1445 vc->state.y++;
1446 vc->vc_pos += vc->vc_size_row;
1448 vc->vc_need_wrap = 0;
1457 if (vc->state.y == vc->vc_top)
1458 con_scroll(vc, vc->vc_top, vc->vc_bottom, SM_DOWN, 1);
1459 else if (vc->state.y > 0) {
1460 vc->state.y--;
1461 vc->vc_pos -= vc->vc_size_row;
1463 vc->vc_need_wrap = 0;
1468 vc->vc_pos -= vc->state.x << 1;
1469 vc->vc_need_wrap = vc->state.x = 0;
1475 if (vc->state.x) {
1476 vc->vc_pos -= 2;
1477 vc->state.x--;
1478 vc->vc_need_wrap = 0;
1502 vc_uniscr_clear_line(vc, vc->state.x,
1503 vc->vc_cols - vc->state.x);
1504 vc_uniscr_clear_lines(vc, vc->state.y + 1,
1505 vc->vc_rows - vc->state.y - 1);
1506 count = (vc->vc_scr_end - vc->vc_pos) >> 1;
1507 start = (unsigned short *)vc->vc_pos;
1510 vc_uniscr_clear_line(vc, 0, vc->state.x + 1);
1511 vc_uniscr_clear_lines(vc, 0, vc->state.y);
1512 count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1;
1513 start = (unsigned short *)vc->vc_origin;
1519 vc_uniscr_clear_lines(vc, 0, vc->vc_rows);
1520 count = vc->vc_cols * vc->vc_rows;
1521 start = (unsigned short *)vc->vc_origin;
1526 scr_memsetw(start, vc->vc_video_erase_char, 2 * count);
1529 vc->vc_need_wrap = 0;
1541 unsigned short *start = (unsigned short *)vc->vc_pos;
1544 switch (vc->vc_par[0]) {
1547 count = vc->vc_cols - vc->state.x;
1550 offset = -vc->state.x;
1551 count = vc->state.x + 1;
1554 offset = -vc->state.x;
1555 count = vc->vc_cols;
1560 vc_uniscr_clear_line(vc, vc->state.x + offset, count);
1561 scr_memsetw(start + offset, vc->vc_video_erase_char, 2 * count);
1562 vc->vc_need_wrap = 0;
1570 unsigned int count = clamp(vc->vc_par[0], 1, vc->vc_cols - vc->state.x);
1572 vc_uniscr_clear_line(vc, vc->state.x, count);
1573 scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count);
1575 vc->vc_sw->con_clear(vc, vc->state.y, vc->state.x, count);
1576 vc->vc_need_wrap = 0;
1581 vc->state.intensity = VCI_NORMAL;
1582 vc->state.italic = false;
1583 vc->state.underline = false;
1584 vc->state.reverse = false;
1585 vc->state.blink = false;
1586 vc->state.color = vc->vc_def_color;
1594 c->r = i&1 ? 0xaa : 0x00;
1595 c->g = i&2 ? 0xaa : 0x00;
1596 c->b = i&4 ? 0xaa : 0x00;
1598 c->r = i&1 ? 0xff : 0x55;
1599 c->g = i&2 ? 0xff : 0x55;
1600 c->b = i&4 ? 0xff : 0x55;
1602 i -= 16;
1603 c->b = i % 6 * 255 / 6;
1605 c->g = i % 6 * 255 / 6;
1607 c->r = i * 255 / 6;
1609 c->r = c->g = c->b = i * 10 - 2312;
1614 u8 hue = 0, max = max3(c->r, c->g, c->b);
1616 if (c->r > max / 2)
1618 if (c->g > max / 2)
1620 if (c->b > max / 2)
1625 vc->state.intensity = VCI_BOLD;
1627 vc->state.intensity = VCI_BOLD;
1629 vc->state.intensity = VCI_NORMAL;
1631 vc->state.color = (vc->state.color & 0xf0) | hue;
1637 vc->state.color = (vc->state.color & 0x0f)
1638 | (c->r&0x80) >> 1 | (c->g&0x80) >> 2 | (c->b&0x80) >> 3;
1656 if (i > vc->vc_npar)
1659 if (vc->vc_par[i] == 5 && i + 1 <= vc->vc_npar) {
1662 rgb_from_256(vc->vc_par[i], &c);
1663 } else if (vc->vc_par[i] == 2 && i + 3 <= vc->vc_npar) {
1665 c.r = vc->vc_par[i + 1];
1666 c.g = vc->vc_par[i + 2];
1667 c.b = vc->vc_par[i + 3];
1704 CSI_m_BRIGHT_FG_COLOR_OFF = CSI_m_BRIGHT_FG_COLOR_BEG - CSI_m_FG_COLOR_BEG,
1707 CSI_m_BRIGHT_BG_COLOR_OFF = CSI_m_BRIGHT_BG_COLOR_BEG - CSI_m_BG_COLOR_BEG,
1715 for (i = 0; i <= vc->vc_npar; i++)
1716 switch (vc->vc_par[i]) {
1721 vc->state.intensity = VCI_BOLD;
1724 vc->state.intensity = VCI_HALF_BRIGHT;
1727 vc->state.italic = true;
1735 vc->state.underline = true;
1738 vc->state.blink = true;
1741 vc->state.reverse = true;
1743 case CSI_m_PRI_FONT: /* ANSI X3.64-1979 (SCO-ish?)
1744 * Select primary font, don't display control chars if
1747 vc->vc_translate = set_translate(vc->state.Gx_charset[vc->state.charset], vc);
1748 vc->vc_disp_ctrl = 0;
1749 vc->vc_toggle_meta = 0;
1751 case CSI_m_ALT_FONT1: /* ANSI X3.64-1979 (SCO-ish?)
1755 vc->vc_translate = set_translate(IBMPC_MAP, vc);
1756 vc->vc_disp_ctrl = 1;
1757 vc->vc_toggle_meta = 0;
1759 case CSI_m_ALT_FONT2: /* ANSI X3.64-1979 (SCO-ish?)
1763 vc->vc_translate = set_translate(IBMPC_MAP, vc);
1764 vc->vc_disp_ctrl = 1;
1765 vc->vc_toggle_meta = 1;
1768 vc->state.intensity = VCI_NORMAL;
1771 vc->state.italic = false;
1774 vc->state.underline = false;
1777 vc->state.blink = false;
1780 vc->state.reverse = false;
1789 vc->state.color = (vc->vc_def_color & 0x0f) |
1790 (vc->state.color & 0xf0);
1793 vc->state.color = (vc->vc_def_color & 0xf0) |
1794 (vc->state.color & 0x0f);
1797 vc->state.intensity = VCI_BOLD;
1798 vc->vc_par[i] -= CSI_m_BRIGHT_FG_COLOR_OFF;
1801 vc->vc_par[i] -= CSI_m_FG_COLOR_BEG;
1802 vc->state.color = color_table[vc->vc_par[i]] |
1803 (vc->state.color & 0xf0);
1806 vc->vc_par[i] -= CSI_m_BRIGHT_BG_COLOR_OFF;
1809 vc->vc_par[i] -= CSI_m_BG_COLOR_BEG;
1810 vc->state.color = (color_table[vc->vc_par[i]] << 4) |
1811 (vc->state.color & 0x0f);
1828 len = sprintf(buf, "\033[%d;%dR", vc->state.y +
1829 (vc->vc_decom ? vc->vc_top + 1 : 1),
1830 vc->state.x + 1);
1831 respond_string(buf, len, tty->port);
1838 respond_string(teminal_ok, strlen(teminal_ok), tty->port);
1843 /* terminal answer to an ESC-Z or csi0c query. */
1846 respond_string(vt102_id, strlen(vt102_id), tty->port);
1856 respond_string(buf, len, tty->port);
1862 return vc_cons[fg_console].d->vc_report_mouse;
1882 for (i = 0; i <= vc->vc_npar; i++)
1883 switch (vc->vc_par[i]) {
1892 vc_resize(deccolm ? 132 : 80, vc->vc_rows);
1898 if (vc->vc_decscnm != on_off) {
1899 vc->vc_decscnm = on_off;
1900 invert_screen(vc, 0, vc->vc_screenbuf_size,
1906 vc->vc_decom = on_off;
1910 vc->vc_decawm = on_off;
1919 vc->vc_report_mouse = on_off ? 1 : 0;
1922 vc->vc_deccm = on_off;
1925 vc->vc_report_mouse = on_off ? 2 : 0;
1941 for (i = 0; i <= vc->vc_npar; i++)
1942 switch (vc->vc_par[i]) { /* ANSI modes set/reset */
1944 vc->vc_disp_ctrl = on_off;
1947 vc->vc_decim = on_off;
1973 * csi_RSB - csi+] (Right Square Bracket) handler
1981 switch (vc->vc_par[0]) {
1983 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
1984 vc->vc_ulcolor = color_table[vc->vc_par[1]];
1985 if (vc->state.underline)
1990 if (vc->vc_can_do_color && vc->vc_par[1] < 16) {
1991 vc->vc_halfcolor = color_table[vc->vc_par[1]];
1992 if (vc->state.intensity == VCI_HALF_BRIGHT)
1997 vc->vc_def_color = vc->vc_attr;
1998 if (vc->vc_hi_font_mask == 0x100)
1999 vc->vc_def_color >>= 1;
2004 blankinterval = min(vc->vc_par[1], 60U) * 60;
2008 if (vc->vc_npar >= 1)
2009 vc->vc_bell_pitch = vc->vc_par[1];
2011 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
2014 if (vc->vc_npar >= 1)
2015 vc->vc_bell_duration = (vc->vc_par[1] < 2000) ?
2016 msecs_to_jiffies(vc->vc_par[1]) : 0;
2018 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
2021 if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1))
2022 set_console(vc->vc_par[1] - 1);
2028 vesa_off_interval = min(vc->vc_par[1], 60U) * 60 * HZ;
2034 if (vc->vc_npar >= 1 && vc->vc_par[1] >= 50 &&
2035 vc->vc_par[1] <= USHRT_MAX)
2036 vc->vc_cur_blink_ms = vc->vc_par[1];
2038 vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;
2046 nr = clamp(nr, 1, vc->vc_cols - vc->state.x);
2053 unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_rows - vc->state.y);
2055 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_DOWN, nr);
2056 vc->vc_need_wrap = 0;
2062 unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_cols - vc->state.x);
2070 unsigned int nr = clamp(vc->vc_par[0], 1, vc->vc_rows - vc->state.y);
2072 con_scroll(vc, vc->state.y, vc->vc_bottom, SM_UP, nr);
2073 vc->vc_need_wrap = 0;
2076 /* console_lock is held (except via vc_init->reset_terminal */
2079 memcpy(&vc->saved_state, &vc->state, sizeof(vc->state));
2085 memcpy(&vc->state, &vc->saved_state, sizeof(vc->state));
2087 gotoxy(vc, vc->state.x, vc->state.y);
2088 vc->vc_translate = set_translate(vc->state.Gx_charset[vc->state.charset],
2091 vc->vc_need_wrap = 0;
2095 * enum vc_ctl_state - control characters state of a vt
2099 * @ESsquare: CSI parsed -- modifiers/parameters/ctrl chars expected
2100 * @ESgetpars: CSI parsed -- parameters/ctrl chars expected
2106 * @EScsiignore: CSI [0x20-0x3f] parsed
2109 * @ESosc: OSC [0-9] parsed
2142 vc->vc_top = 0;
2143 vc->vc_bottom = vc->vc_rows;
2144 vc->vc_state = ESnormal;
2145 vc->vc_priv = EPecma;
2146 vc->vc_translate = set_translate(LAT1_MAP, vc);
2147 vc->state.Gx_charset[0] = LAT1_MAP;
2148 vc->state.Gx_charset[1] = GRAF_MAP;
2149 vc->state.charset = 0;
2150 vc->vc_need_wrap = 0;
2151 vc->vc_report_mouse = 0;
2152 vc->vc_utf = default_utf8;
2153 vc->vc_utf_count = 0;
2155 vc->vc_disp_ctrl = 0;
2156 vc->vc_toggle_meta = 0;
2158 vc->vc_decscnm = 0;
2159 vc->vc_decom = 0;
2160 vc->vc_decawm = 1;
2161 vc->vc_deccm = global_cursor_default;
2162 vc->vc_decim = 0;
2164 vt_reset_keyboard(vc->vc_num);
2166 vc->vc_cursor_type = cur_default;
2167 vc->vc_complement_mask = vc->vc_s_complement_mask;
2172 bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2174 set_bit(i, vc->vc_tab_stop);
2176 vc->vc_bell_pitch = DEFAULT_BELL_PITCH;
2177 vc->vc_bell_duration = DEFAULT_BELL_DURATION;
2178 vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;
2188 unsigned char *charset = &vc->state.Gx_charset[which];
2205 if (vc->state.charset == which)
2206 vc->vc_translate = set_translate(*charset, vc);
2230 ASCII_CSI_IGNORE_FIRST = ' ', /* 0x2x, 0x3a and 0x3c - 0x3f */
2248 if (ansi_control_string(vc->vc_state))
2249 vc->vc_state = ESnormal;
2250 else if (vc->vc_bell_duration)
2251 kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration);
2257 vc->vc_pos -= (vc->state.x << 1);
2259 vc->state.x = find_next_bit(vc->vc_tab_stop,
2260 min(vc->vc_cols - 1, VC_TABSTOPS_COUNT),
2261 vc->state.x + 1);
2262 if (vc->state.x >= VC_TABSTOPS_COUNT)
2263 vc->state.x = vc->vc_cols - 1;
2265 vc->vc_pos += (vc->state.x << 1);
2279 vc->state.charset = 1;
2280 vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc);
2281 vc->vc_disp_ctrl = 1;
2284 vc->state.charset = 0;
2285 vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc);
2286 vc->vc_disp_ctrl = 0;
2290 vc->vc_state = ESnormal;
2293 vc->vc_state = ESesc;
2299 vc->vc_state = ESsquare;
2313 vc->vc_state = ESnormal;
2316 vc->vc_state = ESsquare;
2319 vc->vc_state = ESnonstd;
2322 vc->vc_state = ESapc;
2325 vc->vc_state = ESpm;
2328 vc->vc_state = ESpercent;
2341 if (vc->state.x < VC_TABSTOPS_COUNT)
2342 set_bit(vc->state.x, vc->vc_tab_stop);
2345 vc->vc_state = ESdcs;
2357 vc->vc_state = ESsetG0;
2360 vc->vc_state = ESsetG1;
2363 vc->vc_state = EShash;
2379 * are in @vc->vc_par and the char is in @c here.
2391 if (vc->vc_par[0])
2392 vc->vc_cursor_type = CUR_MAKE(vc->vc_par[0],
2393 vc->vc_par[1],
2394 vc->vc_par[2]);
2396 vc->vc_cursor_type = cur_default;
2400 if (vc->vc_par[0])
2401 vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1];
2403 vc->vc_complement_mask = vc->vc_s_complement_mask;
2406 if (vc->vc_par[0] == 5)
2408 else if (vc->vc_par[0] == 6)
2416 * "ESC [ parameters char". Parameters are in @vc->vc_par and the char is in
2424 if (vc->vc_par[0])
2425 vc->vc_par[0]--;
2426 gotoxy(vc, vc->vc_par[0], vc->state.y);
2429 if (!vc->vc_par[0])
2430 vc->vc_par[0]++;
2431 gotoxy(vc, vc->state.x, vc->state.y - vc->vc_par[0]);
2435 if (!vc->vc_par[0])
2436 vc->vc_par[0]++;
2437 gotoxy(vc, vc->state.x, vc->state.y + vc->vc_par[0]);
2441 if (!vc->vc_par[0])
2442 vc->vc_par[0]++;
2443 gotoxy(vc, vc->state.x + vc->vc_par[0], vc->state.y);
2446 if (!vc->vc_par[0])
2447 vc->vc_par[0]++;
2448 gotoxy(vc, vc->state.x - vc->vc_par[0], vc->state.y);
2451 if (!vc->vc_par[0])
2452 vc->vc_par[0]++;
2453 gotoxy(vc, 0, vc->state.y + vc->vc_par[0]);
2456 if (!vc->vc_par[0])
2457 vc->vc_par[0]++;
2458 gotoxy(vc, 0, vc->state.y - vc->vc_par[0]);
2461 if (vc->vc_par[0])
2462 vc->vc_par[0]--;
2463 gotoxay(vc, vc->state.x ,vc->vc_par[0]);
2467 if (vc->vc_par[0])
2468 vc->vc_par[0]--;
2469 if (vc->vc_par[1])
2470 vc->vc_par[1]--;
2471 gotoxay(vc, vc->vc_par[1], vc->vc_par[0]);
2474 csi_J(vc, vc->vc_par[0]);
2489 if (!vc->vc_par[0])
2493 if (!vc->vc_par[0] && vc->state.x < VC_TABSTOPS_COUNT)
2494 set_bit(vc->state.x, vc->vc_tab_stop);
2495 else if (vc->vc_par[0] == 3)
2496 bitmap_zero(vc->vc_tab_stop, VC_TABSTOPS_COUNT);
2508 if (vc->vc_par[0] == 5)
2510 else if (vc->vc_par[0] == 6)
2513 case 'q': /* DECLL - but only 3 leds */
2515 if (vc->vc_par[0] < 4)
2516 vt_set_led_state(vc->vc_num,
2517 (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4);
2520 if (!vc->vc_par[0])
2521 vc->vc_par[0]++;
2522 if (!vc->vc_par[1])
2523 vc->vc_par[1] = vc->vc_rows;
2525 if (vc->vc_par[0] < vc->vc_par[1] &&
2526 vc->vc_par[1] <= vc->vc_rows) {
2527 vc->vc_top = vc->vc_par[0] - 1;
2528 vc->vc_bottom = vc->vc_par[1];
2542 csi_at(vc, vc->vc_par[0]);
2553 memset(vc->vc_par, 0, sizeof(vc->vc_par));
2554 vc->vc_npar = 0;
2564 if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST &&
2571 switch(vc->vc_state) {
2579 vc->vc_state = ESpalette;
2585 vc->vc_state = ESosc;
2588 vc->vc_state = ESnormal;
2592 vc->vc_par[vc->vc_npar++] = hex_to_bin(c);
2593 if (vc->vc_npar == 7) {
2594 int i = vc->vc_par[0] * 3, j = 1;
2595 vc->vc_palette[i] = 16 * vc->vc_par[j++];
2596 vc->vc_palette[i++] += vc->vc_par[j++];
2597 vc->vc_palette[i] = 16 * vc->vc_par[j++];
2598 vc->vc_palette[i++] += vc->vc_par[j++];
2599 vc->vc_palette[i] = 16 * vc->vc_par[j++];
2600 vc->vc_palette[i] += vc->vc_par[j];
2602 vc->vc_state = ESnormal;
2605 vc->vc_state = ESnormal;
2610 vc->vc_state = ESgetpars;
2613 vc->vc_state = ESfunckey;
2616 vc->vc_priv = EPdec;
2619 vc->vc_priv = EPgt;
2622 vc->vc_priv = EPeq;
2625 vc->vc_priv = EPlt;
2628 vc->vc_priv = EPecma;
2633 if (vc->vc_npar < NPAR - 1) {
2634 vc->vc_npar++;
2639 vc->vc_par[vc->vc_npar] *= 10;
2640 vc->vc_par[vc->vc_npar] += c - '0';
2644 vc->vc_state = EScsiignore;
2650 vc->vc_state = ESnormal;
2652 switch (vc->vc_priv) {
2665 vc->vc_state = ESnormal;
2668 vc->vc_state = ESnormal;
2671 vc->vc_utf = 0;
2675 vc->vc_utf = 1;
2680 vc->vc_state = ESnormal;
2683 vc->vc_state = ESnormal;
2685 /* DEC screen alignment test. kludge :-) */
2686 vc->vc_video_erase_char =
2687 (vc->vc_video_erase_char & 0xff00) | 'E';
2689 vc->vc_video_erase_char =
2690 (vc->vc_video_erase_char & 0xff00) | ' ';
2691 do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
2696 vc->vc_state = ESnormal;
2700 vc->vc_state = ESnormal;
2704 case ESosc: /* ESC ] [0-9] aka OSC [0-9] */
2711 vc->vc_state = ESnormal;
2716 * Markus Kuhn -- 2007-05-26 (Unicode 5.0)
2732 return -1;
2745 ucs > double_width[ARRAY_SIZE(double_width) - 1].last)
2759 if (draw->x < 0)
2762 vc->vc_sw->con_putcs(vc, (u16 *)draw->from,
2763 (u16 *)draw->to - (u16 *)draw->from, vc->state.y,
2764 draw->x);
2765 draw->x = -1;
2771 if (vc->vc_toggle_meta)
2774 return vc->vc_translate[c];
2782 * vc_sanitize_unicode - Replace invalid Unicode code points with ``U+FFFD``
2794 * vc_translate_unicode - Combine UTF-8 into Unicode in &vc_data.vc_utf_char
2796 * @c: UTF-8 byte to translate
2797 * @rescan: set to true iff @c wasn't consumed here and needs to be re-processed
2799 * * &vc_data.vc_utf_char is the being-constructed Unicode code point.
2805 * * %-1 - Input OK so far, @c consumed, further bytes expected.
2806 * * %0xFFFD - Possibility 1: input invalid, @c may have been consumed (see
2810 * * otherwise - Input OK, @c consumed, resulting code point returned.
2819 if (!vc->vc_utf_count)
2822 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
2823 vc->vc_npar++;
2824 if (--vc->vc_utf_count)
2828 c = vc->vc_utf_char;
2830 if (c <= utf8_length_changes[vc->vc_npar - 1] ||
2831 c > utf8_length_changes[vc->vc_npar])
2838 if (vc->vc_utf_count) {
2841 vc->vc_utf_count = 0;
2850 vc->vc_npar = 0;
2852 vc->vc_utf_count = 1;
2853 vc->vc_utf_char = (c & 0x1f);
2855 vc->vc_utf_count = 2;
2856 vc->vc_utf_char = (c & 0x0f);
2858 vc->vc_utf_count = 3;
2859 vc->vc_utf_char = (c & 0x07);
2865 return -1;
2871 if (vc->vc_state != ESnormal)
2874 if (vc->vc_utf && !vc->vc_disp_ctrl)
2883 if (!vc->vc_can_do_color)
2884 return vc->vc_attr ^ 0x08;
2886 if (vc->vc_hi_font_mask == 0x100)
2887 return (vc->vc_attr & 0x11) |
2888 ((vc->vc_attr & 0xe0) >> 4) |
2889 ((vc->vc_attr & 0x0e) << 4);
2891 return (vc->vc_attr & 0x88) |
2892 ((vc->vc_attr & 0x70) >> 4) |
2893 ((vc->vc_attr & 0x07) << 4);
2912 if (vc->vc_state != ESnormal)
2924 * useless without them; to display an arbitrary font position use the
2925 * direct-to-font zone in UTF-8 mode.
2928 if (vc->vc_disp_ctrl)
2931 return vc->vc_utf || (CTRL_ACTION & BIT(c));
2934 if (c == ASCII_DEL && !vc->vc_disp_ctrl)
2947 unsigned char vc_attr = vc->vc_attr;
2948 u16 himask = vc->vc_hi_font_mask, charmask = himask ? 0x1ff : 0xff;
2952 if (vc->vc_utf && !vc->vc_disp_ctrl) {
2957 /* Now try to find out how to display it */
2960 if (tc == -1 || tc == -2)
2961 return -1; /* nothing to display */
2964 if ((!vc->vc_utf || vc->vc_disp_ctrl || c < 128) &&
2977 * Display U+FFFD. If it's not found, display an inverse
2995 if (vc->vc_need_wrap || vc->vc_decim)
2997 if (vc->vc_need_wrap) {
3001 if (vc->vc_decim)
3010 scr_writew(tc, (u16 *)vc->vc_pos);
3012 if (con_should_update(vc) && draw->x < 0) {
3013 draw->x = vc->state.x;
3014 draw->from = vc->vc_pos;
3016 if (vc->state.x == vc->vc_cols - 1) {
3017 vc->vc_need_wrap = vc->vc_decawm;
3018 draw->to = vc->vc_pos + 2;
3020 vc->state.x++;
3021 draw->to = (vc->vc_pos += 2);
3024 if (!--width)
3045 .x = -1,
3049 struct vc_data *vc = tty->driver_data;
3057 currcons = vc->vc_num;
3072 while (!tty->flow.stopped && count) {
3076 count--;
3082 if (tc == -1)
3115 * with other console code and prevention of re-entrancy is
3128 been allocated - a new console is not created
3131 want_console = -1;
3140 if (vc->vc_mode == KD_TEXT && vc->vc_sw->con_scrolldelta)
3141 vc->vc_sw->con_scrolldelta(vc, scrollback_delta);
3158 (vc->vt_mode.mode == VT_AUTO && vc->vc_mode == KD_GRAPHICS)) {
3168 return -EINVAL;
3182 * vt_kmsg_redirect() - sets/gets the kernel message console
3183 * @new: the new virtual terminal number or -1 if the console should stay
3195 * The parameter -1 means that only the current console is returned, but the
3206 if (new != -1)
3234 if (kmsg_console && vc_cons_allocated(kmsg_console - 1))
3235 vc = vc_cons[kmsg_console - 1].d;
3243 if (vc->vc_mode != KD_TEXT)
3250 start = (ushort *)vc->vc_pos;
3251 start_x = vc->state.x;
3253 while (count--) {
3256 c == ASCII_BACKSPACE || vc->vc_need_wrap) {
3258 vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x);
3262 start = (ushort *)vc->vc_pos;
3263 start_x = vc->state.x;
3269 start = (ushort *)vc->vc_pos;
3270 start_x = vc->state.x;
3275 scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos);
3278 if (vc->state.x == vc->vc_cols - 1) {
3279 vc->vc_need_wrap = 1;
3281 vc->vc_pos += 2;
3282 vc->state.x++;
3286 vc->vc_sw->con_putcs(vc, start, cnt, vc->state.y, start_x);
3296 *index = c->index ? c->index-1 : fg_console;
3302 return co->index >= MAX_NR_CONSOLES ? -EINVAL : 0;
3312 .index = -1,
3317 * Handling of Linux-specific VC ioctls
3340 if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN))
3341 return -EPERM;
3343 return -EFAULT;
3351 return -EPERM;
3360 return -EPERM;
3365 * 'shift_state' is an undocumented kernel-internal variable;
3383 return -EPERM;
3386 return -EFAULT;
3399 return -EFAULT;
3418 return -EINVAL;
3445 if (tty->flow.stopped)
3461 struct vc_data *vc = tty->driver_data;
3463 wake_up_interruptible(&vc->paste_wait);
3467 * Turn the Scroll-Lock LED on when the tty is stopped
3474 console_num = tty->index;
3481 * Turn the Scroll-Lock LED off when the console is started
3488 console_num = tty->index;
3496 struct vc_data *vc = tty->driver_data;
3511 unsigned int currcons = tty->index;
3523 if (vc->port.tty) {
3524 ret = -ERESTARTSYS;
3528 ret = tty_port_install(&vc->port, driver, tty);
3532 tty->driver_data = vc;
3533 vc->port.tty = tty;
3534 tty_port_get(&vc->port);
3536 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
3537 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
3538 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
3540 if (vc->vc_utf)
3541 tty->termios.c_iflag |= IUTF8;
3543 tty->termios.c_iflag &= ~IUTF8;
3558 /* Nothing to do - we defer to shutdown */
3563 struct vc_data *vc = tty->driver_data;
3566 vc->port.tty = NULL;
3572 struct vc_data *vc = tty->driver_data;
3574 tty_port_put(&vc->port);
3583 return ldisc == N_TTY ? 0 : -EINVAL;
3598 vc->vc_pos = vc->vc_origin;
3601 vc->vc_palette[k++] = default_red[j] ;
3602 vc->vc_palette[k++] = default_grn[j] ;
3603 vc->vc_palette[k++] = default_blu[j] ;
3605 vc->vc_def_color = default_color;
3606 vc->vc_ulcolor = default_underline_color;
3607 vc->vc_itcolor = default_italic_color;
3608 vc->vc_halfcolor = 0x08; /* grey */
3609 init_waitqueue_head(&vc->paste_wait);
3616 * the appropriate escape-sequence.
3629 display_desc = conswitchp->con_startup();
3639 if (con_driver->con == NULL) {
3640 con_driver->con = conswitchp;
3641 con_driver->desc = display_desc;
3642 con_driver->flag = CON_DRIVER_FLAG_INIT;
3643 con_driver->first = 0;
3644 con_driver->last = MAX_NR_CONSOLES - 1;
3660 tty_port_init(&vc->port);
3662 /* Assuming vc->vc_{cols,rows,screenbuf_size} are sane here. */
3663 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT);
3664 vc_init(vc, currcons || !vc->vc_sw->con_save_screen);
3670 gotoxy(vc, vc->state.x, vc->state.y);
3674 vc->vc_can_do_color ? "colour" : "mono",
3675 display_desc, vc->vc_cols, vc->vc_rows);
3743 console_driver->name = "tty";
3744 console_driver->name_base = 1;
3745 console_driver->major = TTY_MAJOR;
3746 console_driver->minor_start = 1;
3747 console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
3748 console_driver->init_termios = tty_std_termios;
3750 console_driver->init_termios.c_iflag |= IUTF8;
3769 struct module *owner = csw->owner;
3772 int i, j = -1, k = -1, retval = -ENODEV;
3775 return -ENODEV;
3783 if (con_driver->con == csw) {
3784 desc = con_driver->desc;
3793 if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) {
3794 csw->con_startup();
3795 con_driver->flag |= CON_DRIVER_FLAG_INIT;
3800 module_put(conswitchp->owner);
3806 first = max(first, con_driver->first);
3807 last = min(last, con_driver->last);
3814 module_put(con_driver_map[i]->owner);
3818 if (!vc || !vc->vc_sw)
3828 old_was_color = vc->vc_can_do_color;
3829 vc->vc_sw->con_deinit(vc);
3830 vc->vc_origin = (unsigned long)vc->vc_screenbuf;
3835 /* If the console changed between mono <-> color, then
3839 if (old_was_color != vc->vc_can_do_color)
3845 pr_cont("consoles %d-%d ", first + 1, last + 1);
3850 vc->vc_can_do_color ? "colour" : "mono",
3851 desc, vc->vc_cols, vc->vc_rows);
3871 struct module *owner = csw->owner;
3874 int i, retval = -ENODEV;
3877 return -ENODEV;
3885 if (con_driver->con == csw &&
3886 con_driver->flag & CON_DRIVER_FLAG_MODULE) {
3895 retval = -ENODEV;
3901 if (con_back->con && con_back->con != csw) {
3902 defcsw = con_back->con;
3914 first = max(first, con_driver->first);
3915 last = min(last, con_driver->last);
3919 module_put(csw->owner);
3927 defcsw->con_startup();
3928 con_back->flag |= CON_DRIVER_FLAG_INIT;
3937 con_driver->flag &= ~CON_DRIVER_FLAG_INIT;
3951 int i, more = 1, first = -1, last = -1, deflt = 0;
3953 if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE))
3956 csw = con->con;
3961 if (con->con && !(con->flag & CON_DRIVER_FLAG_MODULE)) {
3962 defcsw = con->con;
3973 for (i = con->first; i <= con->last; i++) {
3975 if (first == -1)
3979 } else if (first != -1)
3983 if (first == 0 && last == MAX_NR_CONSOLES -1)
3986 if (first != -1)
3989 first = -1;
3990 last = -1;
4001 int i, more = 1, first = -1, last = -1, deflt = 0;
4004 if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE))
4007 csw = con->con;
4012 for (i = con->first; i <= con->last; i++) {
4014 if (first == -1)
4018 } else if (first != -1)
4022 if (first == 0 && last == MAX_NR_CONSOLES -1)
4025 if (first != -1) {
4031 first = -1;
4032 last = -1;
4075 bind = con_is_bound(con->con);
4087 (con->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)",
4088 con->desc);
4105 con->flag |= CON_DRIVER_FLAG_ATTR;
4111 con->flag &= ~CON_DRIVER_FLAG_ATTR;
4115 * con_is_bound - checks if driver is bound to the console
4141 * con_is_visible - checks whether the current console is visible
4150 return *vc->vc_display_fg == vc;
4155 * con_debug_enter - prepare the console for the kernel debugger
4167 saved_vc_mode = vc->vc_mode;
4169 vc->vc_mode = KD_TEXT;
4171 if (vc->vc_sw->con_debug_enter)
4172 vc->vc_sw->con_debug_enter(vc);
4175 if (vc->vc_rows < 999) {
4184 snprintf(lns, 4, "%i", vc->vc_rows);
4188 if (vc->vc_cols < 999) {
4197 snprintf(cols, 4, "%i", vc->vc_cols);
4206 * con_debug_leave - restore console state
4219 vc_cons[fg_console].d->vc_mode = saved_vc_mode;
4222 if (vc->vc_sw->con_debug_leave)
4223 vc->vc_sw->con_debug_leave(vc);
4229 struct module *owner = csw->owner;
4237 return -ENODEV;
4243 if (con_driver->con == csw) {
4244 retval = -EBUSY;
4249 desc = csw->con_startup();
4251 retval = -ENODEV;
4255 retval = -EINVAL;
4260 if (con_driver->con == NULL &&
4261 !(con_driver->flag & CON_DRIVER_FLAG_ZOMBIE)) {
4262 con_driver->con = csw;
4263 con_driver->desc = desc;
4264 con_driver->node = i;
4265 con_driver->flag = CON_DRIVER_FLAG_MODULE |
4267 con_driver->first = first;
4268 con_driver->last = last;
4277 con_driver->dev =
4279 MKDEV(0, con_driver->node),
4281 "vtcon%i", con_driver->node);
4282 if (IS_ERR(con_driver->dev)) {
4284 con_driver->desc, PTR_ERR(con_driver->dev));
4285 con_driver->dev = NULL;
4297 * do_unregister_con_driver - unregister console driver from console layer
4313 return -EBUSY;
4316 return -EINVAL;
4321 if (con_driver->con == csw) {
4332 con_driver->con = NULL;
4333 con_driver->flag = CON_DRIVER_FLAG_ZOMBIE;
4340 return -ENODEV;
4353 if (!(con_driver->flag & CON_DRIVER_FLAG_ZOMBIE))
4359 device_destroy(&vtconsole_class, MKDEV(0, con_driver->node));
4363 if (WARN_ON_ONCE(con_driver->con))
4364 con_driver->con = NULL;
4365 con_driver->desc = NULL;
4366 con_driver->dev = NULL;
4367 con_driver->node = 0;
4368 WARN_ON_ONCE(con_driver->flag != CON_DRIVER_FLAG_ZOMBIE);
4369 con_driver->flag = 0;
4370 con_driver->first = 0;
4371 con_driver->last = 0;
4394 if (err == -EBUSY)
4428 if (con->con && !con->dev) {
4429 con->dev =
4431 MKDEV(0, con->node),
4433 "vtcon%i", con->node);
4435 if (IS_ERR(con->dev)) {
4437 con->desc, PTR_ERR(con->dev));
4438 con->dev = NULL;
4458 return -EFAULT;
4479 vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0);
4488 vc->vc_sw->con_blank(vc, VESA_VSYNC_SUSPEND, 1);
4498 if (vc->vc_mode != KD_TEXT) {
4509 i = vc->vc_sw->con_blank(vc, vesa_off_interval ? VESA_VSYNC_SUSPEND :
4522 vt_event_post(VT_EVENT_BLANK, vc->vc_num, vc->vc_num);
4552 if (vc->vc_mode != KD_TEXT)
4561 if (vc->vc_sw->con_blank(vc, VESA_NO_BLANKING, leaving_gfx))
4562 /* Low-level driver cannot restore -> do it ourselves */
4568 vt_event_post(VT_EVENT_UNBLANK, vc->vc_num, vc->vc_num);
4602 * function. --BenH.
4612 if (ignore_poke || !vc_cons[fg_console].d || vc_cons[fg_console].d->vc_mode == KD_GRAPHICS)
4630 if (vc->vc_mode != KD_GRAPHICS && vc->vc_sw->con_set_palette)
4631 vc->vc_sw->con_set_palette(vc, color_table);
4645 return -EFAULT;
4657 vc_cons[i].d->vc_palette[k++] = default_red[j];
4658 vc_cons[i].d->vc_palette[k++] = default_grn[j];
4659 vc_cons[i].d->vc_palette[k++] = default_blu[j];
4682 return -EFAULT;
4691 vc->vc_palette[k++] = default_red[j];
4692 vc->vc_palette[k++] = default_grn[j];
4693 vc->vc_palette[k++] = default_blu[j];
4705 * EGA/VGA fonts. It is up to the actual low-level console-driver convert data
4707 * `display' structure so we won't have to convert the fontdata all the time.
4719 int rc = -EINVAL;
4721 unsigned int vpitch = op->op == KD_FONT_OP_GET_TALL ? op->height : 32;
4724 return -EINVAL;
4726 if (op->data) {
4729 return -ENOMEM;
4734 if (vc->vc_mode != KD_TEXT)
4735 rc = -EINVAL;
4736 else if (vc->vc_sw->con_font_get)
4737 rc = vc->vc_sw->con_font_get(vc, &font, vpitch);
4739 rc = -ENOSYS;
4747 if (op->data && font.charcount > op->charcount)
4748 rc = -ENOSPC;
4749 if (font.width > op->width || font.height > op->height)
4750 rc = -ENOSPC;
4754 op->height = font.height;
4755 op->width = font.width;
4756 op->charcount = font.charcount;
4758 if (op->data && copy_to_user(op->data, font.data, c))
4759 rc = -EFAULT;
4769 int rc = -EINVAL;
4771 unsigned int vpitch = op->op == KD_FONT_OP_SET_TALL ? op->height : 32;
4773 if (vc->vc_mode != KD_TEXT)
4774 return -EINVAL;
4775 if (!op->data)
4776 return -EINVAL;
4777 if (op->charcount > max_font_glyphs)
4778 return -EINVAL;
4779 if (op->width <= 0 || op->width > max_font_width || !op->height ||
4780 op->height > max_font_height)
4781 return -EINVAL;
4782 if (vpitch < op->height)
4783 return -EINVAL;
4784 size = (op->width+7)/8 * vpitch * op->charcount;
4786 return -ENOSPC;
4788 font.data = memdup_user(op->data, size);
4792 font.charcount = op->charcount;
4793 font.width = op->width;
4794 font.height = op->height;
4797 if (vc->vc_mode != KD_TEXT)
4798 rc = -EINVAL;
4799 else if (vc->vc_sw->con_font_set) {
4802 rc = vc->vc_sw->con_font_set(vc, &font, vpitch, op->flags);
4804 rc = -ENOSYS;
4812 struct console_font font = {.width = op->width, .height = op->height};
4818 if (!op->data)
4820 else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0)
4821 return -EFAULT;
4823 name[MAX_FONT_NAME - 1] = 0;
4826 if (vc->vc_mode != KD_TEXT) {
4828 return -EINVAL;
4830 if (vc->vc_sw->con_font_default) {
4833 rc = vc->vc_sw->con_font_default(vc, &font, s);
4835 rc = -ENOSYS;
4838 op->width = font.width;
4839 op->height = font.height;
4846 switch (op->op) {
4857 return -EINVAL;
4859 return -ENOSYS;
4872 if (w & vc->vc_hi_font_mask)
4880 u32 **uni_lines = vc->vc_uni_lines;
4883 return uni_lines[n / vc->vc_cols][n % vc->vc_cols];
4889 /* used by vcs - note the word offset */
4899 xy[0] = min(vc->state.x, 0xFFu);
4900 xy[1] = min(vc->state.y, 0xFFu);
4912 if ((unsigned long)org == vc->vc_pos && softcursor_original != -1)
4920 if ((unsigned long)org == vc->vc_pos) {
4921 softcursor_original = -1;