2 * linux/drivers/char/vt.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * Hopefully this will be a rather complete VT102 implementation.
10 * Beeping thanks to John T Kohl.
12 * Virtual Consoles, Screen Blanking, Screen Dumping, Color, Graphics
13 * Chars, and VT100 enhancements by Peter MacDonald.
15 * Copy and paste function by Andrew Haylett,
16 * some enhancements by Alessandro Rubini.
18 * Code to check for different video-cards mostly by Galen Hunt,
19 * <g-hunt@ee.utah.edu>
21 * Rudimentary ISO 10646/Unicode/UTF-8 character set support by
22 * Markus Kuhn, <mskuhn@immd4.informatik.uni-erlangen.de>.
24 * Dynamic allocation of consoles, aeb@cwi.nl, May 1994
25 * Resizing of consoles, aeb, 940926
27 * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94
30 * User-defined bell sound, new setterm control sequences and printk
31 * redirection by Martin Mares <mj@k332.feld.cvut.cz> 19-Nov-95
33 * APM screenblank bug fixed Takashi Manabe <manabe@roy.dsl.tutics.tut.jp>
35 * Merge with the abstract console driver by Geert Uytterhoeven
36 * <geert@linux-m68k.org>, Jan 1997.
38 * Original m68k console driver modifications by
40 * - Arno Griffioen <arno@usn.nl>
41 * - David Carter <carter@cs.bris.ac.uk>
43 * The abstract console driver provides a generic interface for a text
44 * console. It supports VGA text mode, frame buffer based graphical consoles
45 * and special graphics processors that are only accessible through some
46 * registers (e.g. a TMS340x0 GSP).
48 * The interface to the hardware is specified using a special structure
49 * (struct consw) which contains function pointers to console operations
50 * (see <linux/console.h> for more information).
52 * Support for changeable cursor shape
53 * by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>, August 1997
55 * Ported to i386 and con_scrolldelta fixed
56 * by Emmanuel Marty <core@ggi-project.org>, April 1998
58 * Resurrected character buffers in videoram plus lots of other trickery
59 * by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998
61 * Removed old-style timers, introduced console_timer, made timer
62 * deletion SMP-safe. 17Jun00, Andrew Morton <andrewm@uow.edu.au>
64 * Removed console_lock, enabled interrupts across all console operations
65 * 13 March 2001, Andrew Morton
68 #include <linux/module.h>
69 #include <linux/types.h>
70 #include <linux/sched.h>
71 #include <linux/tty.h>
72 #include <linux/tty_flip.h>
73 #include <linux/kernel.h>
74 #include <linux/string.h>
75 #include <linux/errno.h>
77 #include <linux/slab.h>
78 #include <linux/major.h>
80 #include <linux/console.h>
81 #include <linux/init.h>
82 #include <linux/devfs_fs_kernel.h>
83 #include <linux/vt_kern.h>
84 #include <linux/selection.h>
85 #include <linux/tiocl.h>
86 #include <linux/kbd_kern.h>
87 #include <linux/consolemap.h>
88 #include <linux/timer.h>
89 #include <linux/interrupt.h>
90 #include <linux/config.h>
91 #include <linux/workqueue.h>
92 #include <linux/bootmem.h>
94 #include <linux/font.h>
95 #include <linux/bitops.h>
98 #include <asm/system.h>
99 #include <asm/uaccess.h>
101 #include "console_macros.h"
104 const struct consw *conswitchp;
106 /* A bitmap for codes <32. A bit of 1 indicates that the code
107 * corresponding to that bit number invokes some special action
108 * (such as cursor movement) and should not be displayed as a
109 * glyph unless the disp_ctrl mode is explicitly enabled.
111 #define CTRL_ACTION 0x0d00ff81
112 #define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */
115 * Here is the default bell parameters: 750HZ, 1/8th of a second
117 #define DEFAULT_BELL_PITCH 750
118 #define DEFAULT_BELL_DURATION (HZ/8)
120 extern void vcs_make_devfs(struct tty_struct *tty);
121 extern void vcs_remove_devfs(struct tty_struct *tty);
123 extern void console_map_init(void);
124 #ifdef CONFIG_PROM_CONSOLE
125 extern void prom_con_init(void);
127 #ifdef CONFIG_MDA_CONSOLE
128 extern int mda_console_init(void);
131 struct vc vc_cons [MAX_NR_CONSOLES];
133 #ifndef VT_SINGLE_DRIVER
134 static const struct consw *con_driver_map[MAX_NR_CONSOLES];
137 static int con_open(struct tty_struct *, struct file *);
138 static void vc_init(unsigned int console, unsigned int rows,
139 unsigned int cols, int do_clear);
140 static void gotoxy(struct vc_data *vc, int new_x, int new_y);
141 static void save_cur(int currcons);
142 static void reset_terminal(int currcons, int do_clear);
143 static void con_flush_chars(struct tty_struct *tty);
144 static void set_vesa_blanking(char __user *p);
145 static void set_cursor(struct vc_data *vc);
146 static void hide_cursor(struct vc_data *vc);
147 static void console_callback(void *ignored);
148 static void blank_screen_t(unsigned long dummy);
150 static int printable; /* Is console ready for printing? */
153 * ignore_poke: don't unblank the screen when things are typed. This is
154 * mainly for the privacy of braille terminal users.
156 static int ignore_poke;
158 int do_poke_blanked_console;
161 static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
162 static int blankinterval = 10*60*HZ;
163 static int vesa_off_interval;
165 static DECLARE_WORK(console_work, console_callback, NULL);
168 * fg_console is the current virtual console,
169 * last_console is the last used one,
170 * want_console is the console we want to switch to,
171 * kmsg_redirect is the console for kernel messages,
175 int want_console = -1;
179 * For each existing display, we have a pointer to console currently visible
180 * on that display, allowing consoles other than fg_console to be refreshed
181 * appropriately. Unless the low-level driver supplies its own display_fg
182 * variable, we use this one for the "master display".
184 static struct vc_data *master_display_fg;
187 * Unfortunately, we need to delay tty echo when we're currently writing to the
188 * console since the code is (and always was) not re-entrant, so we schedule
189 * all flip requests to process context with schedule-task() and run it from
190 * console_callback().
194 * For the same reason, we defer scrollback to the console callback.
196 static int scrollback_delta;
199 * Hook so that the power management routines can (un)blank
200 * the console on our behalf.
202 int (*console_blank_hook)(int);
204 static struct timer_list console_timer;
205 static int blank_state;
206 static int blank_timer_expired;
214 * Low-Level Functions
217 #define IS_FG (currcons == fg_console)
218 #define IS_FG_VC(vc) (vc == vc_cons[fg_console].d)
220 #define IS_VISIBLE CON_IS_VISIBLE(vc_cons[currcons].d)
222 #ifdef VT_BUF_VRAM_ONLY
224 #define DO_UPDATE_VC(vc) 0
226 #define DO_UPDATE IS_VISIBLE
227 #define DO_UPDATE_VC(vc) CON_IS_VISIBLE(vc)
230 static int pm_con_request(struct pm_dev *dev, pm_request_t rqst, void *data);
231 static struct pm_dev *pm_con;
233 static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed)
238 p = (unsigned short *)(vc->vc_origin + offset);
239 else if (!vc->vc_sw->con_screen_pos)
240 p = (unsigned short *)(vc->vc_visible_origin + offset);
242 p = vc->vc_sw->con_screen_pos(vc, offset);
246 static inline void scrolldelta(int lines)
248 scrollback_delta += lines;
249 schedule_console_callback();
252 void schedule_console_callback(void)
254 schedule_work(&console_work);
257 static void scrup(int currcons, unsigned int t, unsigned int b, int nr)
259 unsigned short *d, *s;
263 if (b > vc_cons[currcons].d->vc_rows || t >= b || nr < 1)
265 if (IS_VISIBLE && sw->con_scroll(vc_cons[currcons].d, t, b, SM_UP, nr))
267 d = (unsigned short *) (origin+vc_cons[currcons].d->vc_size_row*t);
268 s = (unsigned short *) (origin+vc_cons[currcons].d->vc_size_row*(t+nr));
269 scr_memmovew(d, s, (b-t-nr) * vc_cons[currcons].d->vc_size_row);
270 scr_memsetw(d + (b-t-nr) * vc_cons[currcons].d->vc_cols, video_erase_char,
271 vc_cons[currcons].d->vc_size_row * nr);
275 scrdown(int currcons, unsigned int t, unsigned int b, int nr)
282 if (b > vc_cons[currcons].d->vc_rows || t >= b || nr < 1)
284 if (IS_VISIBLE && sw->con_scroll(vc_cons[currcons].d, t, b, SM_DOWN, nr))
286 s = (unsigned short *) (origin+vc_cons[currcons].d->vc_size_row*t);
287 step = vc_cons[currcons].d->vc_cols * nr;
288 scr_memmovew(s + step, s, (b-t-nr)*vc_cons[currcons].d->vc_size_row);
289 scr_memsetw(s, video_erase_char, 2*step);
292 static void do_update_region(struct vc_data *vc, unsigned long start, int count)
294 #ifndef VT_BUF_VRAM_ONLY
295 unsigned int xx, yy, offset;
299 if (!vc->vc_sw->con_getxy) {
300 offset = (start - vc->vc_origin) / 2;
301 xx = offset % vc->vc_cols;
302 yy = offset / vc->vc_cols;
305 start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy);
309 u16 attrib = scr_readw(p) & 0xff00;
312 while (xx < vc->vc_cols && count) {
313 if (attrib != (scr_readw(p) & 0xff00)) {
315 vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
318 attrib = scr_readw(p) & 0xff00;
325 vc->vc_sw->con_putcs(vc, q, p-q, yy, startx);
330 if (vc->vc_sw->con_getxy) {
332 start = vc->vc_sw->con_getxy(vc, start, NULL, NULL);
338 void update_region(int currcons, unsigned long start, int count)
340 WARN_CONSOLE_UNLOCKED();
343 hide_cursor(vc_cons[currcons].d);
344 do_update_region(vc_cons[currcons].d, start, count);
345 set_cursor(vc_cons[currcons].d);
349 /* Structure of attributes is hardware-dependent */
351 static u8 build_attr(int currcons, u8 _color, u8 _intensity, u8 _blink, u8 _underline, u8 _reverse)
353 if (sw->con_build_attr)
354 return sw->con_build_attr(vc_cons[currcons].d, _color, _intensity, _blink, _underline, _reverse);
356 #ifndef VT_BUF_VRAM_ONLY
358 * ++roman: I completely changed the attribute format for monochrome
359 * mode (!can_do_color). The formerly used MDA (monochrome display
360 * adapter) format didn't allow the combination of certain effects.
361 * Now the attribute is just a bit vector:
362 * Bit 0..1: intensity (0..2)
369 if (!vc_cons[currcons].d->vc_can_do_color)
371 (_underline ? 4 : 0) |
375 a = (a & 0xf0) | ulcolor;
376 else if (_intensity == 0)
377 a = (a & 0xf0) | halfcolor;
379 a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77);
384 if (hi_font_mask == 0x100)
393 static void update_attr(int currcons)
395 attr = build_attr(currcons, color, intensity, blink, underline, reverse ^ decscnm);
396 video_erase_char = (build_attr(currcons, color, 1, blink, 0, decscnm) << 8) | ' ';
399 /* Note: inverting the screen twice should revert to the original state */
400 void invert_screen(struct vc_data *vc, int offset, int count, int viewed)
404 WARN_CONSOLE_UNLOCKED();
407 p = screenpos(vc, offset, viewed);
408 if (vc->vc_sw->con_invert_region)
409 vc->vc_sw->con_invert_region(vc, p, count);
410 #ifndef VT_BUF_VRAM_ONLY
416 if (!vc->vc_can_do_color) {
423 } else if (vc->vc_hi_font_mask == 0x100) {
426 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4);
433 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4);
440 if (DO_UPDATE_VC(vc))
441 do_update_region(vc, (unsigned long) p, count);
444 /* used by selection: complement pointer position */
445 void complement_pos(struct vc_data *vc, int offset)
447 static unsigned short *p;
448 static unsigned short old;
449 static unsigned short oldx, oldy;
451 WARN_CONSOLE_UNLOCKED();
455 if (DO_UPDATE_VC(vc))
456 vc->vc_sw->con_putc(vc, old, oldy, oldx);
462 p = screenpos(vc, offset, 1);
464 new = old ^ vc->vc_complement_mask;
466 if (DO_UPDATE_VC(vc)) {
467 oldx = (offset >> 1) % vc->vc_cols;
468 oldy = (offset >> 1) / vc->vc_cols;
469 vc->vc_sw->con_putc(vc, new, oldy, oldx);
474 static void insert_char(int currcons, unsigned int nr)
476 unsigned short *p, *q = (unsigned short *) pos;
478 p = q + vc_cons[currcons].d->vc_cols - nr - x;
480 scr_writew(scr_readw(p), p + nr);
481 scr_memsetw(q, video_erase_char, nr*2);
484 unsigned short oldattr = attr;
485 sw->con_bmove(vc_cons[currcons].d,y,x,y,x+nr,1,
486 vc_cons[currcons].d->vc_cols-x-nr);
487 attr = video_erase_char >> 8;
489 sw->con_putc(vc_cons[currcons].d,
490 video_erase_char,y,x+nr);
495 static void delete_char(int currcons, unsigned int nr)
498 unsigned short *p = (unsigned short *) pos;
500 while (++i <= vc_cons[currcons].d->vc_cols - nr) {
501 scr_writew(scr_readw(p+nr), p);
504 scr_memsetw(p, video_erase_char, nr*2);
507 unsigned short oldattr = attr;
508 sw->con_bmove(vc_cons[currcons].d, y, x+nr, y, x, 1,
509 vc_cons[currcons].d->vc_cols-x-nr);
510 attr = video_erase_char >> 8;
512 sw->con_putc(vc_cons[currcons].d,
514 vc_cons[currcons].d->vc_cols-1-nr);
519 static int softcursor_original;
521 static void add_softcursor(struct vc_data *vc)
523 int i = scr_readw((u16 *) vc->vc_pos);
524 u32 type = vc->vc_cursor_type;
526 if (! (type & 0x10)) return;
527 if (softcursor_original != -1) return;
528 softcursor_original = i;
529 i |= ((type >> 8) & 0xff00 );
530 i ^= ((type) & 0xff00 );
531 if ((type & 0x20) && ((softcursor_original & 0x7000) == (i & 0x7000))) i ^= 0x7000;
532 if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700;
533 scr_writew(i, (u16 *) vc->vc_pos);
534 if (DO_UPDATE_VC(vc))
535 vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x);
538 static void hide_softcursor(struct vc_data *vc)
540 if (softcursor_original != -1) {
541 scr_writew(softcursor_original, (u16 *)vc->vc_pos);
542 if (DO_UPDATE_VC(vc))
543 vc->vc_sw->con_putc(vc, softcursor_original,
545 softcursor_original = -1;
549 static void hide_cursor(struct vc_data *vc)
553 vc->vc_sw->con_cursor(vc, CM_ERASE);
557 static void set_cursor(struct vc_data *vc)
559 if (!IS_FG_VC(vc) || console_blanked ||
560 vc->vc_vt->vc_mode == KD_GRAPHICS)
566 if ((vc->vc_cursor_type & 0x0f) != 1)
567 vc->vc_sw->con_cursor(vc, CM_DRAW);
572 static void set_origin(int currcons)
574 WARN_CONSOLE_UNLOCKED();
577 !sw->con_set_origin ||
578 !sw->con_set_origin(vc_cons[currcons].d))
579 origin = (unsigned long) screenbuf;
580 visible_origin = origin;
581 scr_end = origin + screenbuf_size;
582 pos = origin + vc_cons[currcons].d->vc_size_row*y + 2*x;
585 static inline void save_screen(int currcons)
587 WARN_CONSOLE_UNLOCKED();
589 if (sw->con_save_screen)
590 sw->con_save_screen(vc_cons[currcons].d);
594 * Redrawing of screen
597 static void clear_buffer_attributes(int currcons)
599 unsigned short *p = (unsigned short *) origin;
600 int count = screenbuf_size/2;
601 int mask = hi_font_mask | 0xff;
603 for (; count > 0; count--, p++) {
604 scr_writew((scr_readw(p)&mask) | (video_erase_char&~mask), p);
608 void redraw_screen(int new_console, int is_switch)
611 int currcons, old_console;
613 WARN_CONSOLE_UNLOCKED();
615 if (!vc_cons_allocated(new_console)) {
617 /* printk("redraw_screen: tty %d not allocated ??\n", new_console+1); */
622 currcons = fg_console;
623 hide_cursor(vc_cons[currcons].d);
624 if (fg_console != new_console) {
625 struct vc_data **display = vc_cons[new_console].d->vc_display_fg;
626 old_console = (*display) ? (*display)->vc_num : fg_console;
627 *display = vc_cons[new_console].d;
628 fg_console = new_console;
629 currcons = old_console;
631 save_screen(currcons);
632 set_origin(currcons);
634 currcons = new_console;
635 if (old_console == new_console)
639 currcons = new_console;
640 hide_cursor(vc_cons[currcons].d);
645 int old_was_color = vc_cons[currcons].d->vc_can_do_color;
647 set_origin(currcons);
648 update = sw->con_switch(vc_cons[currcons].d);
649 set_palette(currcons);
651 * If console changed from mono<->color, the best we can do
652 * is to clear the buffer attributes. As it currently stands,
653 * rebuilding new attributes from the old buffer is not doable
654 * without overly complex code.
656 if (old_was_color != vc_cons[currcons].d->vc_can_do_color) {
657 update_attr(currcons);
658 clear_buffer_attributes(currcons);
660 if (update && vcmode != KD_GRAPHICS)
661 do_update_region(vc_cons[currcons].d, origin, screenbuf_size/2);
663 set_cursor(vc_cons[currcons].d);
666 compute_shiftstate();
671 * Allocation, freeing and resizing of VTs.
674 int vc_cons_allocated(unsigned int i)
676 return (i < MAX_NR_CONSOLES && vc_cons[i].d);
679 static void visual_init(int currcons, int init)
681 /* ++Geert: sw->con_init determines console size */
683 module_put(sw->owner);
685 #ifndef VT_SINGLE_DRIVER
686 if (con_driver_map[currcons])
687 sw = con_driver_map[currcons];
689 __module_get(sw->owner);
691 display_fg = &master_display_fg;
692 vc_cons[currcons].d->vc_uni_pagedir_loc = &vc_cons[currcons].d->vc_uni_pagedir;
693 vc_cons[currcons].d->vc_uni_pagedir = 0;
696 vc_cons[currcons].d->vc_can_do_color = 0;
697 sw->con_init(vc_cons[currcons].d, init);
698 if (!complement_mask)
700 vc_cons[currcons].d->vc_can_do_color ? 0x7700 : 0x0800;
701 s_complement_mask = complement_mask;
702 vc_cons[currcons].d->vc_size_row = vc_cons[currcons].d->vc_cols<<1;
703 screenbuf_size = vc_cons[currcons].d->vc_rows * vc_cons[currcons].d->vc_size_row;
706 int vc_allocate(unsigned int currcons) /* return 0 on success */
708 WARN_CONSOLE_UNLOCKED();
710 if (currcons >= MAX_NR_CONSOLES)
712 if (!vc_cons[currcons].d) {
715 /* prevent users from taking too much memory */
716 if (currcons >= MAX_NR_USER_CONSOLES && !capable(CAP_SYS_RESOURCE))
719 /* due to the granularity of kmalloc, we waste some memory here */
720 /* the alloc is done in two steps, to optimize the common situation
721 of a 25x80 console (structsize=216, screenbuf_size=4000) */
722 /* although the numbers above are not valid since long ago, the
723 point is still up-to-date and the comment still has its value
724 even if only as a historical artifact. --mj, July 1998 */
725 p = (long) kmalloc(structsize, GFP_KERNEL);
728 memset((void *)p, 0, structsize);
729 vc_cons[currcons].d = (struct vc_data *)p;
730 vt_cons[currcons] = (struct vt_struct *)(p+sizeof(struct vc_data));
731 vc_cons[currcons].d->vc_vt = vt_cons[currcons];
732 visual_init(currcons, 1);
733 if (!*vc_cons[currcons].d->vc_uni_pagedir_loc)
734 con_set_default_unimap(currcons);
735 q = (long)kmalloc(screenbuf_size, GFP_KERNEL);
738 vc_cons[currcons].d = NULL;
739 vt_cons[currcons] = NULL;
742 screenbuf = (unsigned short *) q;
744 vc_init(currcons, vc_cons[currcons].d->vc_rows, vc_cons[currcons].d->vc_cols, 1);
747 pm_con = pm_register(PM_SYS_DEV,
755 inline int resize_screen(int currcons, int width, int height)
757 /* Resizes the resolution of the display adapater */
760 if (vcmode != KD_GRAPHICS && sw->con_resize)
761 err = sw->con_resize(vc_cons[currcons].d, width, height);
766 * Change # of rows and columns (0 means unchanged/the size of fg_console)
767 * [this is to be used together with some user program
768 * like resize that changes the hardware videomode]
770 #define VC_RESIZE_MAXCOL (32767)
771 #define VC_RESIZE_MAXROW (32767)
772 int vc_resize(int currcons, unsigned int cols, unsigned int lines)
774 unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0;
775 unsigned int old_cols, old_rows, old_row_size, old_screen_size;
776 unsigned int new_cols, new_rows, new_row_size, new_screen_size;
777 unsigned short *newscreen;
779 WARN_CONSOLE_UNLOCKED();
781 if (!vc_cons_allocated(currcons))
784 if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW)
787 new_cols = (cols ? cols : vc_cons[currcons].d->vc_cols);
788 new_rows = (lines ? lines : vc_cons[currcons].d->vc_rows);
789 new_row_size = new_cols << 1;
790 new_screen_size = new_row_size * new_rows;
792 if (new_cols == vc_cons[currcons].d->vc_cols && new_rows == vc_cons[currcons].d->vc_rows)
795 newscreen = (unsigned short *) kmalloc(new_screen_size, GFP_USER);
799 old_rows = vc_cons[currcons].d->vc_rows;
800 old_cols = vc_cons[currcons].d->vc_cols;
801 old_row_size = vc_cons[currcons].d->vc_size_row;
802 old_screen_size = screenbuf_size;
804 err = resize_screen(currcons, new_cols, new_rows);
810 vc_cons[currcons].d->vc_rows = new_rows;
811 vc_cons[currcons].d->vc_cols = new_cols;
812 vc_cons[currcons].d->vc_size_row = new_row_size;
813 screenbuf_size = new_screen_size;
815 rlth = min(old_row_size, new_row_size);
816 rrem = new_row_size - rlth;
818 new_origin = (long) newscreen;
819 new_scr_end = new_origin + new_screen_size;
820 if (new_rows < old_rows)
821 old_origin += (old_rows - new_rows) * old_row_size;
823 update_attr(currcons);
825 while (old_origin < scr_end) {
826 scr_memcpyw((unsigned short *) new_origin, (unsigned short *) old_origin, rlth);
828 scr_memsetw((void *)(new_origin + rlth), video_erase_char, rrem);
829 old_origin += old_row_size;
830 new_origin += new_row_size;
832 if (new_scr_end > new_origin)
833 scr_memsetw((void *) new_origin, video_erase_char, new_scr_end - new_origin);
836 screenbuf = newscreen;
838 screenbuf_size = new_screen_size;
839 set_origin(currcons);
841 /* do part of a reset_terminal() */
843 bottom = vc_cons[currcons].d->vc_rows;
844 gotoxy(vc_cons[currcons].d, x, y);
847 if (vc_cons[currcons].d->vc_tty) {
848 struct winsize ws, *cws = &vc_cons[currcons].d->vc_tty->winsize;
850 memset(&ws, 0, sizeof(ws));
851 ws.ws_row = vc_cons[currcons].d->vc_rows;
852 ws.ws_col = vc_cons[currcons].d->vc_cols;
853 ws.ws_ypixel = video_scan_lines;
854 if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
855 vc_cons[currcons].d->vc_tty->pgrp > 0)
856 kill_pg(vc_cons[currcons].d->vc_tty->pgrp, SIGWINCH, 1);
861 update_screen(currcons);
866 void vc_disallocate(unsigned int currcons)
868 WARN_CONSOLE_UNLOCKED();
870 if (vc_cons_allocated(currcons)) {
871 sw->con_deinit(vc_cons[currcons].d);
874 if (currcons >= MIN_NR_CONSOLES)
875 kfree(vc_cons[currcons].d);
876 vc_cons[currcons].d = NULL;
884 #define set_kbd(x) set_vc_kbd_mode(kbd_table+currcons,x)
885 #define clr_kbd(x) clr_vc_kbd_mode(kbd_table+currcons,x)
886 #define is_kbd(x) vc_kbd_mode(kbd_table+currcons,x)
888 #define decarm VC_REPEAT
889 #define decckm VC_CKMODE
890 #define kbdapplic VC_APPLIC
894 * this is what the terminal answers to a ESC-Z or csi0c query.
896 #define VT100ID "\033[?1;2c"
897 #define VT102ID "\033[?6c"
899 unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7,
900 8,12,10,14, 9,13,11,15 };
902 /* the default colour table, for VGA+ colour systems */
903 int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa,
904 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff};
905 int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
906 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff};
907 int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
908 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
911 * gotoxy() must verify all boundaries, because the arguments
912 * might also be negative. If the given position is out of
913 * bounds, the cursor is placed at the nearest margin.
915 static void gotoxy(struct vc_data *vc, int new_x, int new_y)
922 if (new_x >= vc->vc_cols)
923 vc->vc_x = vc->vc_cols - 1;
930 max_y = vc->vc_bottom;
937 else if (new_y >= max_y)
938 vc->vc_y = max_y - 1;
941 vc->vc_pos = vc->vc_origin + vc->vc_y * vc->vc_size_row + (vc->vc_x<<1);
942 vc->vc_need_wrap = 0;
945 /* for absolute user moves, when decom is set */
946 static void gotoxay(int currcons, int new_x, int new_y)
948 gotoxy(vc_cons[currcons].d, new_x, decom ? (top+new_y) : new_y);
951 void scrollback(int lines)
953 int currcons = fg_console;
956 lines = vc_cons[currcons].d->vc_rows/2;
960 void scrollfront(int lines)
962 int currcons = fg_console;
965 lines = vc_cons[currcons].d->vc_rows/2;
969 static void lf(int currcons)
971 /* don't scroll if above bottom of scrolling region, or
972 * if below scrolling region
975 scrup(currcons,top,bottom,1);
976 else if (y < vc_cons[currcons].d->vc_rows-1) {
978 pos += vc_cons[currcons].d->vc_size_row;
983 static void ri(int currcons)
985 /* don't scroll if below top of scrolling region, or
986 * if above scrolling region
989 scrdown(currcons,top,bottom,1);
992 pos -= vc_cons[currcons].d->vc_size_row;
997 static inline void cr(int currcons)
1003 static inline void bs(int currcons)
1012 static inline void del(int currcons)
1017 static void csi_J(int currcons, int vpar)
1020 unsigned short * start;
1023 case 0: /* erase from cursor to end of display */
1024 count = (scr_end-pos)>>1;
1025 start = (unsigned short *) pos;
1027 /* do in two stages */
1028 sw->con_clear(vc_cons[currcons].d, y, x, 1,
1029 vc_cons[currcons].d->vc_cols-x);
1030 sw->con_clear(vc_cons[currcons].d, y+1, 0,
1031 vc_cons[currcons].d->vc_rows-y-1,
1032 vc_cons[currcons].d->vc_cols);
1035 case 1: /* erase from start to cursor */
1036 count = ((pos-origin)>>1)+1;
1037 start = (unsigned short *) origin;
1039 /* do in two stages */
1040 sw->con_clear(vc_cons[currcons].d, 0, 0, y,
1041 vc_cons[currcons].d->vc_cols);
1042 sw->con_clear(vc_cons[currcons].d, y, 0, 1,
1046 case 2: /* erase whole display */
1047 count = vc_cons[currcons].d->vc_cols * vc_cons[currcons].d->vc_rows;
1048 start = (unsigned short *) origin;
1050 sw->con_clear(vc_cons[currcons].d, 0, 0,
1051 vc_cons[currcons].d->vc_rows,
1052 vc_cons[currcons].d->vc_cols);
1057 scr_memsetw(start, video_erase_char, 2*count);
1061 static void csi_K(int currcons, int vpar)
1064 unsigned short * start;
1067 case 0: /* erase from cursor to end of line */
1068 count = vc_cons[currcons].d->vc_cols-x;
1069 start = (unsigned short *) pos;
1071 sw->con_clear(vc_cons[currcons].d, y, x, 1,
1072 vc_cons[currcons].d->vc_cols-x);
1074 case 1: /* erase from start of line to cursor */
1075 start = (unsigned short *) (pos - (x<<1));
1078 sw->con_clear(vc_cons[currcons].d, y, 0, 1,
1081 case 2: /* erase whole line */
1082 start = (unsigned short *) (pos - (x<<1));
1083 count = vc_cons[currcons].d->vc_cols;
1085 sw->con_clear(vc_cons[currcons].d, y, 0, 1,
1086 vc_cons[currcons].d->vc_cols);
1091 scr_memsetw(start, video_erase_char, 2 * count);
1095 static void csi_X(int currcons, int vpar) /* erase the following vpar positions */
1101 count = (vpar > vc_cons[currcons].d->vc_cols-x) ? (vc_cons[currcons].d->vc_cols-x) : vpar;
1103 scr_memsetw((unsigned short *) pos, video_erase_char, 2 * count);
1105 sw->con_clear(vc_cons[currcons].d, y, x, 1, count);
1109 static void default_attr(int currcons)
1118 /* console_sem is held */
1119 static void csi_m(int currcons)
1123 for (i=0;i<=npar;i++)
1125 case 0: /* all attributes off */
1126 default_attr(currcons);
1143 case 10: /* ANSI X3.64-1979 (SCO-ish?)
1144 * Select primary font, don't display
1145 * control chars if defined, don't set
1148 translate = set_translate(charset == 0
1150 : G1_charset,currcons);
1154 case 11: /* ANSI X3.64-1979 (SCO-ish?)
1155 * Select first alternate font, lets
1156 * chars < 32 be displayed as ROM chars.
1158 translate = set_translate(IBMPC_MAP,currcons);
1162 case 12: /* ANSI X3.64-1979 (SCO-ish?)
1163 * Select second alternate font, toggle
1164 * high bit before displaying as ROM char.
1166 translate = set_translate(IBMPC_MAP,currcons);
1183 case 38: /* ANSI X3.64-1979 (SCO-ish?)
1184 * Enables underscore, white foreground
1185 * with white underscore (Linux - use
1186 * default foreground).
1188 color = (def_color & 0x0f) | background;
1191 case 39: /* ANSI X3.64-1979 (SCO-ish?)
1192 * Disable underline option.
1193 * Reset colour to default? It did this
1196 color = (def_color & 0x0f) | background;
1200 color = (def_color & 0xf0) | foreground;
1203 if (par[i] >= 30 && par[i] <= 37)
1204 color = color_table[par[i]-30]
1206 else if (par[i] >= 40 && par[i] <= 47)
1207 color = (color_table[par[i]-40]<<4)
1211 update_attr(currcons);
1214 static void respond_string(const char *p, struct tty_struct *tty)
1217 tty_insert_flip_char(tty, *p, 0);
1220 con_schedule_flip(tty);
1223 static void cursor_report(int currcons, struct tty_struct *tty)
1227 sprintf(buf, "\033[%d;%dR", y + (decom ? top+1 : 1), x+1);
1228 respond_string(buf, tty);
1231 static inline void status_report(struct tty_struct *tty)
1233 respond_string("\033[0n", tty); /* Terminal ok */
1236 static inline void respond_ID(struct tty_struct * tty)
1238 respond_string(VT102ID, tty);
1241 void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry)
1245 sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx),
1247 respond_string(buf, tty);
1250 /* invoked via ioctl(TIOCLINUX) and through set_selection */
1251 int mouse_reporting(void)
1253 int currcons = fg_console;
1255 return report_mouse;
1258 /* console_sem is held */
1259 static void set_mode(int currcons, int on_off)
1263 for (i=0; i<=npar; i++)
1264 if (ques) switch(par[i]) { /* DEC private modes set/reset */
1265 case 1: /* Cursor keys send ^[Ox/^[[x */
1271 case 3: /* 80/132 mode switch unimplemented */
1274 (void) vc_resize(deccolm ? 132 : 80, vc_cons[currcons].d->vc_rows);
1275 /* this alone does not suffice; some user mode
1276 utility has to change the hardware regs */
1279 case 5: /* Inverted screen on/off */
1280 if (decscnm != on_off) {
1282 invert_screen(vc_cons[currcons].d, 0, screenbuf_size, 0);
1283 update_attr(currcons);
1286 case 6: /* Origin relative/absolute */
1288 gotoxay(currcons,0,0);
1290 case 7: /* Autowrap on/off */
1293 case 8: /* Autorepeat on/off */
1300 report_mouse = on_off ? 1 : 0;
1302 case 25: /* Cursor on/off */
1306 report_mouse = on_off ? 2 : 0;
1308 } else switch(par[i]) { /* ANSI modes set/reset */
1309 case 3: /* Monitor (display ctrls) */
1312 case 4: /* Insert Mode on/off */
1315 case 20: /* Lf, Enter == CrLf/Lf */
1324 /* console_sem is held */
1325 static void setterm_command(int currcons)
1328 case 1: /* set color for underline mode */
1329 if (vc_cons[currcons].d->vc_can_do_color &&
1331 ulcolor = color_table[par[1]];
1333 update_attr(currcons);
1336 case 2: /* set color for half intensity mode */
1337 if (vc_cons[currcons].d->vc_can_do_color &&
1339 halfcolor = color_table[par[1]];
1341 update_attr(currcons);
1344 case 8: /* store colors as defaults */
1346 if (hi_font_mask == 0x100)
1348 default_attr(currcons);
1349 update_attr(currcons);
1351 case 9: /* set blanking interval */
1352 blankinterval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;
1353 poke_blanked_console();
1355 case 10: /* set bell frequency in Hz */
1357 bell_pitch = par[1];
1359 bell_pitch = DEFAULT_BELL_PITCH;
1361 case 11: /* set bell duration in msec */
1363 bell_duration = (par[1] < 2000) ?
1366 bell_duration = DEFAULT_BELL_DURATION;
1368 case 12: /* bring specified console to the front */
1369 if (par[1] >= 1 && vc_cons_allocated(par[1]-1))
1370 set_console(par[1] - 1);
1372 case 13: /* unblank the screen */
1373 poke_blanked_console();
1375 case 14: /* set vesa powerdown interval */
1376 vesa_off_interval = ((par[1] < 60) ? par[1] : 60) * 60 * HZ;
1378 case 15: /* activate the previous console */
1379 set_console(last_console);
1384 /* console_sem is held */
1385 static void csi_at(int currcons, unsigned int nr)
1387 if (nr > vc_cons[currcons].d->vc_cols - x)
1388 nr = vc_cons[currcons].d->vc_cols - x;
1391 insert_char(currcons, nr);
1394 /* console_sem is held */
1395 static void csi_L(int currcons, unsigned int nr)
1397 if (nr > vc_cons[currcons].d->vc_rows - y)
1398 nr = vc_cons[currcons].d->vc_rows - y;
1401 scrdown(currcons,y,bottom,nr);
1405 /* console_sem is held */
1406 static void csi_P(int currcons, unsigned int nr)
1408 if (nr > vc_cons[currcons].d->vc_cols - x)
1409 nr = vc_cons[currcons].d->vc_cols - x;
1412 delete_char(currcons, nr);
1415 /* console_sem is held */
1416 static void csi_M(int currcons, unsigned int nr)
1418 if (nr > vc_cons[currcons].d->vc_rows - y)
1419 nr = vc_cons[currcons].d->vc_rows - y;
1422 scrup(currcons,y,bottom,nr);
1426 /* console_sem is held (except via vc_init->reset_terminal */
1427 static void save_cur(int currcons)
1431 s_intensity = intensity;
1432 s_underline = underline;
1434 s_reverse = reverse;
1435 s_charset = charset;
1437 saved_G0 = G0_charset;
1438 saved_G1 = G1_charset;
1441 /* console_sem is held */
1442 static void restore_cur(int currcons)
1444 gotoxy(vc_cons[currcons].d,saved_x,saved_y);
1445 intensity = s_intensity;
1446 underline = s_underline;
1448 reverse = s_reverse;
1449 charset = s_charset;
1451 G0_charset = saved_G0;
1452 G1_charset = saved_G1;
1453 translate = set_translate(charset ? G1_charset : G0_charset,currcons);
1454 update_attr(currcons);
1458 enum { ESnormal, ESesc, ESsquare, ESgetpars, ESgotpars, ESfunckey,
1459 EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd,
1462 /* console_sem is held (except via vc_init()) */
1463 static void reset_terminal(int currcons, int do_clear)
1466 bottom = vc_cons[currcons].d->vc_rows;
1467 vc_state = ESnormal;
1469 translate = set_translate(LAT1_MAP,currcons);
1470 G0_charset = LAT1_MAP;
1471 G1_charset = GRAF_MAP;
1491 kbd_table[currcons].lockstate = 0;
1492 kbd_table[currcons].slockstate = 0;
1493 kbd_table[currcons].ledmode = LED_SHOW_FLAGS;
1494 kbd_table[currcons].ledflagstate = kbd_table[currcons].default_ledflagstate;
1495 /* do not do set_leds here because this causes an endless tasklet loop
1496 when the keyboard hasn't been initialized yet */
1498 cursor_type = CUR_DEFAULT;
1499 complement_mask = s_complement_mask;
1501 default_attr(currcons);
1502 update_attr(currcons);
1504 tab_stop[0] = 0x01010100;
1508 tab_stop[4] = 0x01010101;
1510 bell_pitch = DEFAULT_BELL_PITCH;
1511 bell_duration = DEFAULT_BELL_DURATION;
1513 gotoxy(vc_cons[currcons].d, 0, 0);
1519 /* console_sem is held */
1520 static void do_con_trol(struct tty_struct *tty, unsigned int currcons, int c)
1523 * Control characters can be used in the _middle_
1524 * of an escape sequence.
1531 kd_mksound(bell_pitch, bell_duration);
1538 while (x < vc_cons[currcons].d->vc_cols - 1) {
1540 if (tab_stop[x >> 5] & (1 << (x & 31)))
1545 case 10: case 11: case 12:
1554 translate = set_translate(G1_charset,currcons);
1559 translate = set_translate(G0_charset,currcons);
1563 vc_state = ESnormal;
1572 vc_state = ESsquare;
1577 vc_state = ESnormal;
1580 vc_state = ESsquare;
1583 vc_state = ESnonstd;
1586 vc_state = ESpercent;
1599 tab_stop[x >> 5] |= (1 << (x & 31));
1608 restore_cur(currcons);
1620 reset_terminal(currcons,1);
1622 case '>': /* Numeric keypad */
1625 case '=': /* Appl. keypad */
1631 if (c=='P') { /* palette escape sequence */
1632 for (npar=0; npar<NPAR; npar++)
1635 vc_state = ESpalette;
1637 } else if (c=='R') { /* reset palette */
1638 reset_palette(currcons);
1639 vc_state = ESnormal;
1641 vc_state = ESnormal;
1644 if ( (c>='0'&&c<='9') || (c>='A'&&c<='F') || (c>='a'&&c<='f') ) {
1645 par[npar++] = (c>'9' ? (c&0xDF)-'A'+10 : c-'0') ;
1647 int i = par[0]*3, j = 1;
1648 palette[i] = 16*par[j++];
1649 palette[i++] += par[j++];
1650 palette[i] = 16*par[j++];
1651 palette[i++] += par[j++];
1652 palette[i] = 16*par[j++];
1653 palette[i] += par[j];
1654 set_palette(currcons);
1655 vc_state = ESnormal;
1658 vc_state = ESnormal;
1661 for(npar = 0 ; npar < NPAR ; npar++)
1664 vc_state = ESgetpars;
1665 if (c == '[') { /* Function key */
1673 if (c==';' && npar<NPAR-1) {
1676 } else if (c>='0' && c<='9') {
1680 } else vc_state=ESgotpars;
1682 vc_state = ESnormal;
1685 set_mode(currcons,1);
1688 set_mode(currcons,0);
1693 cursor_type = par[0] | (par[1]<<8) | (par[2]<<16);
1695 cursor_type = CUR_DEFAULT;
1703 complement_mask = par[0]<<8 | par[1];
1705 complement_mask = s_complement_mask;
1713 else if (par[0] == 6)
1714 cursor_report(currcons,tty);
1724 if (par[0]) par[0]--;
1725 gotoxy(vc_cons[currcons].d, par[0], y);
1728 if (!par[0]) par[0]++;
1729 gotoxy(vc_cons[currcons].d, x, y-par[0]);
1732 if (!par[0]) par[0]++;
1733 gotoxy(vc_cons[currcons].d, x, y+par[0]);
1736 if (!par[0]) par[0]++;
1737 gotoxy(vc_cons[currcons].d, x+par[0], y);
1740 if (!par[0]) par[0]++;
1741 gotoxy(vc_cons[currcons].d, x-par[0], y);
1744 if (!par[0]) par[0]++;
1745 gotoxy(vc_cons[currcons].d, 0, y+par[0]);
1748 if (!par[0]) par[0]++;
1749 gotoxy(vc_cons[currcons].d, 0, y-par[0]);
1752 if (par[0]) par[0]--;
1753 gotoxay(currcons,x,par[0]);
1756 if (par[0]) par[0]--;
1757 if (par[1]) par[1]--;
1758 gotoxay(currcons,par[1],par[0]);
1761 csi_J(currcons,par[0]);
1764 csi_K(currcons,par[0]);
1767 csi_L(currcons,par[0]);
1770 csi_M(currcons,par[0]);
1773 csi_P(currcons,par[0]);
1781 tab_stop[x >> 5] &= ~(1 << (x & 31));
1782 else if (par[0] == 3) {
1793 case 'q': /* DECLL - but only 3 leds */
1794 /* map 0,1,2,3 to 0,1,2,4 */
1796 setledstate(kbd_table + currcons,
1797 (par[0] < 3) ? par[0] : 4);
1803 par[1] = vc_cons[currcons].d->vc_rows;
1804 /* Minimum allowed region is 2 lines */
1805 if (par[0] < par[1] &&
1806 par[1] <= vc_cons[currcons].d->vc_rows) {
1809 gotoxay(currcons,0,0);
1816 restore_cur(currcons);
1819 csi_X(currcons, par[0]);
1822 csi_at(currcons,par[0]);
1824 case ']': /* setterm functions */
1825 setterm_command(currcons);
1830 vc_state = ESnormal;
1832 case '@': /* defined in ISO 2022 */
1835 case 'G': /* prelim official escape code */
1836 case '8': /* retained for compatibility */
1842 vc_state = ESnormal;
1845 vc_state = ESnormal;
1847 /* DEC screen alignment test. kludge :-) */
1849 (video_erase_char & 0xff00) | 'E';
1852 (video_erase_char & 0xff00) | ' ';
1853 do_update_region(vc_cons[currcons].d, origin, screenbuf_size/2);
1858 G0_charset = GRAF_MAP;
1860 G0_charset = LAT1_MAP;
1862 G0_charset = IBMPC_MAP;
1864 G0_charset = USER_MAP;
1866 translate = set_translate(G0_charset,currcons);
1867 vc_state = ESnormal;
1871 G1_charset = GRAF_MAP;
1873 G1_charset = LAT1_MAP;
1875 G1_charset = IBMPC_MAP;
1877 G1_charset = USER_MAP;
1879 translate = set_translate(G1_charset,currcons);
1880 vc_state = ESnormal;
1883 vc_state = ESnormal;
1887 /* This is a temporary buffer used to prepare a tty console write
1888 * so that we can easily avoid touching user space while holding the
1889 * console spinlock. It is allocated in con_init and is shared by
1890 * this code and the vc_screen read/write tty calls.
1892 * We have to allocate this statically in the kernel data section
1893 * since console_init (and thus con_init) are called before any
1894 * kernel memory allocation is available.
1896 char con_buf[CON_BUF_SIZE];
1897 DECLARE_MUTEX(con_buf_sem);
1899 /* acquires console_sem */
1900 static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count)
1902 #ifdef VT_BUF_VRAM_ONLY
1903 #define FLUSH do { } while(0);
1905 #define FLUSH if (draw_x >= 0) { \
1906 sw->con_putcs(vc_cons[currcons].d, (u16 *)draw_from, (u16 *)draw_to-(u16 *)draw_from, y, draw_x); \
1911 int c, tc, ok, n = 0, draw_x = -1;
1912 unsigned int currcons;
1913 unsigned long draw_from = 0, draw_to = 0;
1914 struct vt_struct *vt;
1915 u16 himask, charmask;
1916 const unsigned char *orig_buf = NULL;
1924 acquire_console_sem();
1925 vt = tty->driver_data;
1927 printk(KERN_ERR "vt: argh, driver_data is NULL !\n");
1928 release_console_sem();
1932 currcons = vt->vc_num;
1933 if (!vc_cons_allocated(currcons)) {
1934 /* could this happen? */
1935 static int error = 0;
1938 printk("con_write: tty %d not allocated\n", currcons+1);
1940 release_console_sem();
1943 release_console_sem();
1948 /* At this point 'buf' is guaranteed to be a kernel buffer
1949 * and therefore no access to userspace (and therefore sleeping)
1950 * will be needed. The con_buf_sem serializes all tty based
1951 * console rendering and vcs write/read operations. We hold
1952 * the console spinlock during the entire write.
1955 acquire_console_sem();
1957 vt = tty->driver_data;
1959 printk(KERN_ERR "vt: argh, driver_data _became_ NULL !\n");
1960 release_console_sem();
1964 himask = hi_font_mask;
1965 charmask = himask ? 0x1ff : 0xff;
1967 /* undraw cursor first */
1969 hide_cursor(vc_cons[currcons].d);
1971 while (!tty->stopped && count) {
1978 /* Do no translation at all in control states */
1979 if (vc_state != ESnormal) {
1982 /* Combine UTF-8 into Unicode */
1983 /* Incomplete characters silently ignored */
1985 if (utf_count > 0 && (c & 0xc0) == 0x80) {
1986 utf_char = (utf_char << 6) | (c & 0x3f);
1992 if ((c & 0xe0) == 0xc0) {
1994 utf_char = (c & 0x1f);
1995 } else if ((c & 0xf0) == 0xe0) {
1997 utf_char = (c & 0x0f);
1998 } else if ((c & 0xf8) == 0xf0) {
2000 utf_char = (c & 0x07);
2001 } else if ((c & 0xfc) == 0xf8) {
2003 utf_char = (c & 0x03);
2004 } else if ((c & 0xfe) == 0xfc) {
2006 utf_char = (c & 0x01);
2015 } else { /* no utf */
2016 tc = translate[toggle_meta ? (c|0x80) : c];
2019 /* If the original code was a control character we
2020 * only allow a glyph to be displayed if the code is
2021 * not normally used (such as for cursor movement) or
2022 * if the disp_ctrl mode has been explicitly enabled.
2023 * Certain characters (as given by the CTRL_ALWAYS
2024 * bitmap) are always displayed as control characters,
2025 * as the console would be pretty useless without
2026 * them; to display an arbitrary font position use the
2027 * direct-to-font zone in UTF-8 mode.
2029 ok = tc && (c >= 32 ||
2030 (!utf && !(((disp_ctrl ? CTRL_ALWAYS
2031 : CTRL_ACTION) >> c) & 1)))
2032 && (c != 127 || disp_ctrl)
2035 if (vc_state == ESnormal && ok) {
2036 /* Now try to find out how to display it */
2037 tc = conv_uni_to_pc(vc_cons[currcons].d, tc);
2039 /* If we got -4 (not found) then see if we have
2040 defined a replacement character (U+FFFD) */
2041 tc = conv_uni_to_pc(vc_cons[currcons].d, 0xfffd);
2043 /* One reason for the -4 can be that we just
2044 did a clear_unimap();
2045 try at least to show something. */
2048 } else if ( tc == -3 ) {
2049 /* Bad hash table -- hope for the best */
2053 continue; /* Conversion failed */
2055 if (need_wrap || decim)
2062 insert_char(currcons, 1);
2064 ((attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
2067 if (DO_UPDATE && draw_x < 0) {
2071 if (x == vc_cons[currcons].d->vc_cols - 1) {
2081 do_con_trol(tty, currcons, orig);
2084 console_conditional_schedule();
2085 release_console_sem();
2093 * This is the console switching callback.
2095 * Doing console switching in a process context allows
2096 * us to do the switches asynchronously (needed when we want
2097 * to switch due to a keyboard interrupt). Synchronization
2098 * with other console code and prevention of re-entrancy is
2099 * ensured with console_sem.
2101 static void console_callback(void *ignored)
2103 acquire_console_sem();
2105 if (want_console >= 0) {
2106 if (want_console != fg_console &&
2107 vc_cons_allocated(want_console)) {
2108 hide_cursor(vc_cons[fg_console].d);
2109 change_console(want_console);
2110 /* we only changed when the console had already
2111 been allocated - a new console is not created
2112 in an interrupt routine */
2116 if (do_poke_blanked_console) { /* do not unblank for a LED change */
2117 do_poke_blanked_console = 0;
2118 poke_blanked_console();
2120 if (scrollback_delta) {
2121 int currcons = fg_console;
2123 if (vcmode == KD_TEXT)
2124 sw->con_scrolldelta(vc_cons[currcons].d, scrollback_delta);
2125 scrollback_delta = 0;
2127 if (blank_timer_expired) {
2129 blank_timer_expired = 0;
2132 release_console_sem();
2135 void set_console(int nr)
2138 schedule_console_callback();
2141 struct tty_driver *console_driver;
2143 #ifdef CONFIG_VT_CONSOLE
2146 * Console on virtual terminal
2148 * The console must be locked when we get here.
2151 void vt_console_print(struct console *co, const char *b, unsigned count)
2153 int currcons = fg_console;
2155 static unsigned long printing;
2156 const ushort *start;
2160 /* console busy or not yet initialized */
2161 if (!printable || test_and_set_bit(0, &printing))
2164 if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1))
2165 currcons = kmsg_redirect - 1;
2167 /* read `x' only after setting currcons properly (otherwise
2168 the `x' macro will read the x of the foreground console). */
2171 if (!vc_cons_allocated(currcons)) {
2173 /* printk("vt_console_print: tty %d not allocated ??\n", currcons+1); */
2177 if (vcmode != KD_TEXT)
2180 /* undraw cursor first */
2182 hide_cursor(vc_cons[currcons].d);
2184 start = (ushort *)pos;
2186 /* Contrived structure to try to emulate original need_wrap behaviour
2187 * Problems caused when we have need_wrap set on '\n' character */
2190 if (c == 10 || c == 13 || c == 8 || need_wrap) {
2193 sw->con_putcs(vc_cons[currcons].d, start, cnt, y, x);
2199 if (c == 8) { /* backspace */
2201 start = (ushort *)pos;
2208 start = (ushort *)pos;
2210 if (c == 10 || c == 13)
2213 scr_writew((attr << 8) + c, (unsigned short *) pos);
2215 if (myx == vc_cons[currcons].d->vc_cols - 1) {
2224 sw->con_putcs(vc_cons[currcons].d, start, cnt, y, x);
2226 if (x == vc_cons[currcons].d->vc_cols) {
2231 set_cursor(vc_cons[currcons].d);
2233 if (!oops_in_progress)
2234 poke_blanked_console();
2237 clear_bit(0, &printing);
2240 static struct tty_driver *vt_console_device(struct console *c, int *index)
2242 *index = c->index ? c->index-1 : fg_console;
2243 return console_driver;
2246 struct console vt_console_driver = {
2248 .write = vt_console_print,
2249 .device = vt_console_device,
2250 .unblank = unblank_screen,
2251 .flags = CON_PRINTBUFFER,
2257 * Handling of Linux-specific VC ioctls
2261 * Generally a bit racy with respect to console_sem().
2263 * There are some functions which don't need it.
2265 * There are some functions which can sleep for arbitrary periods
2266 * (paste_selection) but we don't need the lock there anyway.
2268 * set_selection has locking, and definitely needs it
2271 int tioclinux(struct tty_struct *tty, unsigned long arg)
2274 char __user *p = (char __user *)arg;
2278 if (tty->driver->type != TTY_DRIVER_TYPE_CONSOLE)
2280 if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN))
2282 if (get_user(type, p))
2288 acquire_console_sem();
2289 ret = set_selection((struct tiocl_selection __user *)(p+1), tty);
2290 release_console_sem();
2292 case TIOCL_PASTESEL:
2293 ret = paste_selection(tty);
2295 case TIOCL_UNBLANKSCREEN:
2298 case TIOCL_SELLOADLUT:
2299 ret = sel_loadlut(p);
2301 case TIOCL_GETSHIFTSTATE:
2304 * Make it possible to react to Shift+Mousebutton.
2305 * Note that 'shift_state' is an undocumented
2306 * kernel-internal variable; programs not closely
2307 * related to the kernel should not use this.
2310 ret = __put_user(data, p);
2312 case TIOCL_GETMOUSEREPORTING:
2313 data = mouse_reporting();
2314 ret = __put_user(data, p);
2316 case TIOCL_SETVESABLANK:
2317 set_vesa_blanking(p);
2319 case TIOCL_SETKMSGREDIRECT:
2320 if (!capable(CAP_SYS_ADMIN)) {
2323 if (get_user(data, p+1))
2326 kmsg_redirect = data;
2329 case TIOCL_GETFGCONSOLE:
2332 case TIOCL_SCROLLCONSOLE:
2333 if (get_user(lines, (s32 __user *)(p+4))) {
2340 case TIOCL_BLANKSCREEN: /* until explicitly unblanked, not only poked */
2344 case TIOCL_BLANKEDSCREEN:
2345 ret = console_blanked;
2355 * /dev/ttyN handling
2358 static int con_write(struct tty_struct *tty, const unsigned char *buf, int count)
2362 retval = do_con_write(tty, buf, count);
2363 con_flush_chars(tty);
2368 static void con_put_char(struct tty_struct *tty, unsigned char ch)
2371 return; /* n_r3964 calls put_char() from interrupt context */
2372 do_con_write(tty, &ch, 1);
2375 static int con_write_room(struct tty_struct *tty)
2379 return 4096; /* No limit, really; we're not buffering */
2382 static int con_chars_in_buffer(struct tty_struct *tty)
2384 return 0; /* we're not buffering */
2388 * con_throttle and con_unthrottle are only used for
2389 * paste_selection(), which has to stuff in a large number of
2392 static void con_throttle(struct tty_struct *tty)
2396 static void con_unthrottle(struct tty_struct *tty)
2398 struct vt_struct *vt = tty->driver_data;
2400 wake_up_interruptible(&vt->paste_wait);
2404 * Turn the Scroll-Lock LED on when the tty is stopped
2406 static void con_stop(struct tty_struct *tty)
2411 console_num = tty->index;
2412 if (!vc_cons_allocated(console_num))
2414 set_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
2419 * Turn the Scroll-Lock LED off when the console is started
2421 static void con_start(struct tty_struct *tty)
2426 console_num = tty->index;
2427 if (!vc_cons_allocated(console_num))
2429 clr_vc_kbd_led(kbd_table + console_num, VC_SCROLLOCK);
2433 static void con_flush_chars(struct tty_struct *tty)
2435 struct vt_struct *vt;
2437 if (in_interrupt()) /* from flush_to_ldisc */
2440 /* if we race with con_close(), vt may be null */
2441 acquire_console_sem();
2442 vt = tty->driver_data;
2444 set_cursor(vc_cons[vt->vc_num].d);
2445 release_console_sem();
2449 * Allocate the console screen memory.
2451 static int con_open(struct tty_struct *tty, struct file *filp)
2453 unsigned int currcons = tty->index;
2456 acquire_console_sem();
2457 if (tty->count == 1) {
2458 ret = vc_allocate(currcons);
2460 vt_cons[currcons]->vc_num = currcons;
2461 tty->driver_data = vt_cons[currcons];
2462 vc_cons[currcons].d->vc_tty = tty;
2464 if (!tty->winsize.ws_row && !tty->winsize.ws_col) {
2465 tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
2466 tty->winsize.ws_col = vc_cons[currcons].d->vc_cols;
2468 release_console_sem();
2469 vcs_make_devfs(tty);
2473 release_console_sem();
2478 * We take tty_sem in here to prevent another thread from coming in via init_dev
2479 * and taking a ref against the tty while we're in the process of forgetting
2480 * about it and cleaning things up.
2482 * This is because vcs_remove_devfs() can sleep and will drop the BKL.
2484 static void con_close(struct tty_struct *tty, struct file *filp)
2487 acquire_console_sem();
2488 if (tty && tty->count == 1) {
2489 struct vt_struct *vt;
2491 vt = tty->driver_data;
2493 vc_cons[vt->vc_num].d->vc_tty = NULL;
2494 tty->driver_data = NULL;
2495 release_console_sem();
2496 vcs_remove_devfs(tty);
2499 * tty_sem is released, but we still hold BKL, so there is
2500 * still exclusion against init_dev()
2504 release_console_sem();
2508 static void vc_init(unsigned int currcons, unsigned int rows,
2509 unsigned int cols, int do_clear)
2513 vc_cons[currcons].d->vc_cols = cols;
2514 vc_cons[currcons].d->vc_rows = rows;
2515 vc_cons[currcons].d->vc_size_row = cols<<1;
2516 screenbuf_size = vc_cons[currcons].d->vc_rows * vc_cons[currcons].d->vc_size_row;
2518 set_origin(currcons);
2521 for (j=k=0; j<16; j++) {
2522 vc_cons[currcons].d->vc_palette[k++] = default_red[j] ;
2523 vc_cons[currcons].d->vc_palette[k++] = default_grn[j] ;
2524 vc_cons[currcons].d->vc_palette[k++] = default_blu[j] ;
2526 def_color = 0x07; /* white */
2527 ulcolor = 0x0f; /* bold white */
2528 halfcolor = 0x08; /* grey */
2529 init_waitqueue_head(&vt_cons[currcons]->paste_wait);
2530 reset_terminal(currcons, do_clear);
2534 * This routine initializes console interrupts, and does nothing
2535 * else. If you want the screen to clear, call tty_write with
2536 * the appropriate escape-sequence.
2539 static int __init con_init(void)
2541 const char *display_desc = NULL;
2542 unsigned int currcons = 0;
2544 acquire_console_sem();
2547 display_desc = conswitchp->con_startup();
2548 if (!display_desc) {
2550 release_console_sem();
2554 init_timer(&console_timer);
2555 console_timer.function = blank_screen_t;
2556 if (blankinterval) {
2557 blank_state = blank_normal_wait;
2558 mod_timer(&console_timer, jiffies + blankinterval);
2562 * kmalloc is not running yet - we use the bootmem allocator.
2564 for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
2565 vc_cons[currcons].d = (struct vc_data *)
2566 alloc_bootmem(sizeof(struct vc_data));
2567 vt_cons[currcons] = (struct vt_struct *)
2568 alloc_bootmem(sizeof(struct vt_struct));
2569 vc_cons[currcons].d->vc_vt = vt_cons[currcons];
2570 visual_init(currcons, 1);
2571 screenbuf = (unsigned short *) alloc_bootmem(screenbuf_size);
2573 vc_init(currcons, vc_cons[currcons].d->vc_rows, vc_cons[currcons].d->vc_cols,
2574 currcons || !sw->con_save_screen);
2576 currcons = fg_console = 0;
2577 master_display_fg = vc_cons[currcons].d;
2578 set_origin(currcons);
2579 save_screen(currcons);
2580 gotoxy(vc_cons[currcons].d, x, y);
2582 update_screen(fg_console);
2583 printk("Console: %s %s %dx%d",
2584 vc_cons[currcons].d->vc_can_do_color ? "colour" : "mono",
2585 display_desc, vc_cons[currcons].d->vc_cols, vc_cons[currcons].d->vc_rows);
2589 release_console_sem();
2591 #ifdef CONFIG_VT_CONSOLE
2592 register_console(&vt_console_driver);
2596 console_initcall(con_init);
2598 static struct tty_operations con_ops = {
2602 .write_room = con_write_room,
2603 .put_char = con_put_char,
2604 .flush_chars = con_flush_chars,
2605 .chars_in_buffer = con_chars_in_buffer,
2609 .throttle = con_throttle,
2610 .unthrottle = con_unthrottle,
2613 int __init vty_init(void)
2617 console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
2618 if (!console_driver)
2619 panic("Couldn't allocate console driver\n");
2620 console_driver->owner = THIS_MODULE;
2621 console_driver->devfs_name = "vc/";
2622 console_driver->name = "tty";
2623 console_driver->name_base = 1;
2624 console_driver->major = TTY_MAJOR;
2625 console_driver->minor_start = 1;
2626 console_driver->type = TTY_DRIVER_TYPE_CONSOLE;
2627 console_driver->init_termios = tty_std_termios;
2628 console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS;
2629 tty_set_operations(console_driver, &con_ops);
2630 if (tty_register_driver(console_driver))
2631 panic("Couldn't register console driver\n");
2635 #ifdef CONFIG_PROM_CONSOLE
2638 #ifdef CONFIG_MDA_CONSOLE
2644 #ifndef VT_SINGLE_DRIVER
2647 * If we support more console drivers, this function is used
2648 * when a driver wants to take over some existing consoles
2649 * and become default driver for newly opened ones.
2652 int take_over_console(const struct consw *csw, int first, int last, int deflt)
2656 struct module *owner;
2659 if (!try_module_get(owner))
2662 acquire_console_sem();
2664 desc = csw->con_startup();
2666 release_console_sem();
2672 module_put(conswitchp->owner);
2673 __module_get(owner);
2677 for (i = first; i <= last; i++) {
2681 if (con_driver_map[i])
2682 module_put(con_driver_map[i]->owner);
2683 __module_get(owner);
2684 con_driver_map[i] = csw;
2686 if (!vc_cons[i].d || !vc_cons[i].d->vc_sw)
2692 old_was_color = vc_cons[i].d->vc_can_do_color;
2693 vc_cons[i].d->vc_sw->con_deinit(vc_cons[i].d);
2694 origin = (unsigned long) screenbuf;
2695 visible_origin = origin;
2696 scr_end = origin + screenbuf_size;
2697 pos = origin + vc_cons[currcons].d->vc_size_row*y + 2*x;
2701 /* If the console changed between mono <-> color, then
2702 * the attributes in the screenbuf will be wrong. The
2703 * following resets all attributes to something sane.
2705 if (old_was_color != vc_cons[i].d->vc_can_do_color)
2706 clear_buffer_attributes(i);
2711 printk("Console: switching ");
2713 printk("consoles %d-%d ", first+1, last+1);
2715 printk("to %s %s %dx%d\n",
2716 vc_cons[j].d->vc_can_do_color ? "colour" : "mono",
2717 desc, vc_cons[j].d->vc_cols, vc_cons[j].d->vc_rows);
2719 printk("to %s\n", desc);
2721 release_console_sem();
2727 void give_up_console(const struct consw *csw)
2731 for(i = 0; i < MAX_NR_CONSOLES; i++)
2732 if (con_driver_map[i] == csw) {
2733 module_put(csw->owner);
2734 con_driver_map[i] = NULL;
2744 static void set_vesa_blanking(char __user *p)
2747 get_user(mode, p + 1);
2748 vesa_blank_mode = (mode < 4) ? mode : 0;
2752 * This is called by a timer handler
2754 static void vesa_powerdown(void)
2756 struct vc_data *c = vc_cons[fg_console].d;
2758 * Power down if currently suspended (1 or 2),
2759 * suspend if currently blanked (0),
2760 * else do nothing (i.e. already powered down (3)).
2761 * Called only if powerdown features are allowed.
2763 switch (vesa_blank_mode) {
2764 case VESA_NO_BLANKING:
2765 c->vc_sw->con_blank(c, VESA_VSYNC_SUSPEND+1, 0);
2767 case VESA_VSYNC_SUSPEND:
2768 case VESA_HSYNC_SUSPEND:
2769 c->vc_sw->con_blank(c, VESA_POWERDOWN+1, 0);
2774 void do_blank_screen(int entering_gfx)
2776 int currcons = fg_console;
2779 WARN_CONSOLE_UNLOCKED();
2781 if (console_blanked) {
2782 if (blank_state == blank_vesa_wait) {
2783 blank_state = blank_off;
2789 if (blank_state != blank_normal_wait)
2791 blank_state = blank_off;
2793 /* entering graphics mode? */
2795 hide_cursor(vc_cons[currcons].d);
2796 save_screen(currcons);
2797 sw->con_blank(vc_cons[currcons].d, -1, 1);
2798 console_blanked = fg_console + 1;
2799 set_origin(currcons);
2803 /* don't blank graphics */
2804 if (vcmode != KD_TEXT) {
2805 console_blanked = fg_console + 1;
2809 hide_cursor(vc_cons[currcons].d);
2810 del_timer_sync(&console_timer);
2811 blank_timer_expired = 0;
2813 save_screen(currcons);
2814 /* In case we need to reset origin, blanking hook returns 1 */
2815 i = sw->con_blank(vc_cons[currcons].d, 1, 0);
2816 console_blanked = fg_console + 1;
2818 set_origin(currcons);
2820 if (console_blank_hook && console_blank_hook(1))
2823 if (vesa_off_interval) {
2824 blank_state = blank_vesa_wait,
2825 mod_timer(&console_timer, jiffies + vesa_off_interval);
2828 if (vesa_blank_mode)
2829 sw->con_blank(vc_cons[currcons].d, vesa_blank_mode + 1, 0);
2831 EXPORT_SYMBOL(do_blank_screen);
2834 * Called by timer as well as from vt_console_driver
2836 void do_unblank_screen(int leaving_gfx)
2840 WARN_CONSOLE_UNLOCKED();
2843 if (!console_blanked)
2845 if (!vc_cons_allocated(fg_console)) {
2847 printk("unblank_screen: tty %d not allocated ??\n", fg_console+1);
2850 currcons = fg_console;
2851 if (vcmode != KD_TEXT)
2852 return; /* but leave console_blanked != 0 */
2854 if (blankinterval) {
2855 mod_timer(&console_timer, jiffies + blankinterval);
2856 blank_state = blank_normal_wait;
2859 console_blanked = 0;
2860 if (sw->con_blank(vc_cons[currcons].d, 0, leaving_gfx))
2861 /* Low-level driver cannot restore -> do it ourselves */
2862 update_screen(fg_console);
2863 if (console_blank_hook)
2864 console_blank_hook(0);
2865 set_palette(currcons);
2866 set_cursor(vc_cons[fg_console].d);
2868 EXPORT_SYMBOL(do_unblank_screen);
2871 * This is called by the outside world to cause a forced unblank, mostly for
2872 * oopses. Currently, I just call do_unblank_screen(0), but we could eventually
2873 * call it with 1 as an argument and so force a mode restore... that may kill
2874 * X or at least garbage the screen but would also make the Oops visible...
2876 void unblank_screen(void)
2878 do_unblank_screen(0);
2882 * We defer the timer blanking to work queue so it can take the console semaphore
2883 * (console operations can still happen at irq time, but only from printk which
2884 * has the console semaphore. Not perfect yet, but better than no locking
2886 static void blank_screen_t(unsigned long dummy)
2888 blank_timer_expired = 1;
2889 schedule_work(&console_work);
2892 void poke_blanked_console(void)
2894 WARN_CONSOLE_UNLOCKED();
2896 /* This isn't perfectly race free, but a race here would be mostly harmless,
2897 * at worse, we'll do a spurrious blank and it's unlikely
2899 del_timer(&console_timer);
2900 blank_timer_expired = 0;
2902 if (ignore_poke || !vt_cons[fg_console] || vt_cons[fg_console]->vc_mode == KD_GRAPHICS)
2904 if (console_blanked)
2906 else if (blankinterval) {
2907 mod_timer(&console_timer, jiffies + blankinterval);
2908 blank_state = blank_normal_wait;
2916 void set_palette(int currcons)
2918 WARN_CONSOLE_UNLOCKED();
2920 if (vcmode != KD_GRAPHICS)
2921 sw->con_set_palette(vc_cons[currcons].d, color_table);
2924 static int set_get_cmap(unsigned char __user *arg, int set)
2928 WARN_CONSOLE_UNLOCKED();
2930 for (i = 0; i < 16; i++)
2932 get_user(default_red[i], arg++);
2933 get_user(default_grn[i], arg++);
2934 get_user(default_blu[i], arg++);
2936 put_user(default_red[i], arg++);
2937 put_user(default_grn[i], arg++);
2938 put_user(default_blu[i], arg++);
2941 for (i = 0; i < MAX_NR_CONSOLES; i++)
2942 if (vc_cons_allocated(i)) {
2943 for (j = k = 0; j < 16; j++) {
2944 vc_cons[i].d->vc_palette[k++] = default_red[j];
2945 vc_cons[i].d->vc_palette[k++] = default_grn[j];
2946 vc_cons[i].d->vc_palette[k++] = default_blu[j];
2955 * Load palette into the DAC registers. arg points to a colour
2956 * map, 3 bytes per colour, 16 colours, range from 0 to 255.
2959 int con_set_cmap(unsigned char __user *arg)
2963 acquire_console_sem();
2964 rc = set_get_cmap (arg,1);
2965 release_console_sem();
2970 int con_get_cmap(unsigned char __user *arg)
2974 acquire_console_sem();
2975 rc = set_get_cmap (arg,0);
2976 release_console_sem();
2981 void reset_palette(int currcons)
2984 for (j=k=0; j<16; j++) {
2985 palette[k++] = default_red[j];
2986 palette[k++] = default_grn[j];
2987 palette[k++] = default_blu[j];
2989 set_palette(currcons);
2995 * Currently we only support fonts up to 32 pixels wide, at a maximum height
2996 * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints,
2997 * depending on width) reserved for each character which is kinda wasty, but
2998 * this is done in order to maintain compatibility with the EGA/VGA fonts. It
2999 * is upto the actual low-level console-driver convert data into its favorite
3000 * format (maybe we should add a `fontoffset' field to the `display'
3001 * structure so we won't have to convert the fontdata all the time.
3005 #define max_font_size 65536
3007 int con_font_get(int currcons, struct console_font_op *op)
3009 struct console_font font;
3013 if (vt_cons[currcons]->vc_mode != KD_TEXT)
3017 font.data = kmalloc(max_font_size, GFP_KERNEL);
3023 acquire_console_sem();
3024 if (sw->con_font_get)
3025 rc = sw->con_font_get(vc_cons[currcons].d, &font);
3028 release_console_sem();
3033 c = (font.width+7)/8 * 32 * font.charcount;
3035 if (op->data && font.charcount > op->charcount)
3037 if (!(op->flags & KD_FONT_FLAG_OLD)) {
3038 if (font.width > op->width || font.height > op->height)
3041 if (font.width != 8)
3043 else if ((op->height && font.height > op->height) ||
3050 op->height = font.height;
3051 op->width = font.width;
3052 op->charcount = font.charcount;
3054 if (op->data && copy_to_user(op->data, font.data, c))
3062 int con_font_set(int currcons, struct console_font_op *op)
3064 struct console_font font;
3068 if (vt_cons[currcons]->vc_mode != KD_TEXT)
3072 if (op->charcount > 512)
3074 if (!op->height) { /* Need to guess font height [compat] */
3076 u8 __user *charmap = op->data;
3079 /* If from KDFONTOP ioctl, don't allow things which can be done in userland,
3080 so that we can get rid of this soon */
3081 if (!(op->flags & KD_FONT_FLAG_OLD))
3083 for (h = 32; h > 0; h--)
3084 for (i = 0; i < op->charcount; i++) {
3085 if (get_user(tmp, &charmap[32*i+h-1]))
3094 if (op->width <= 0 || op->width > 32 || op->height > 32)
3096 size = (op->width+7)/8 * 32 * op->charcount;
3097 if (size > max_font_size)
3099 font.charcount = op->charcount;
3100 font.height = op->height;
3101 font.width = op->width;
3102 font.data = kmalloc(size, GFP_KERNEL);
3105 if (copy_from_user(font.data, op->data, size)) {
3109 acquire_console_sem();
3110 if (sw->con_font_set)
3111 rc = sw->con_font_set(vc_cons[currcons].d, &font, op->flags);
3114 release_console_sem();
3119 int con_font_default(int currcons, struct console_font_op *op)
3121 struct console_font font = {.width = op->width, .height = op->height};
3122 char name[MAX_FONT_NAME];
3126 if (vt_cons[currcons]->vc_mode != KD_TEXT)
3131 else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0)
3134 name[MAX_FONT_NAME - 1] = 0;
3136 acquire_console_sem();
3137 if (sw->con_font_default)
3138 rc = sw->con_font_default(vc_cons[currcons].d, &font, s);
3141 release_console_sem();
3143 op->width = font.width;
3144 op->height = font.height;
3149 int con_font_copy(int currcons, struct console_font_op *op)
3151 int con = op->height;
3155 if (vt_cons[currcons]->vc_mode != KD_TEXT)
3158 acquire_console_sem();
3159 vc = vc_cons[currcons].d;
3160 if (!sw->con_font_copy)
3162 else if (con < 0 || !vc_cons_allocated(con))
3164 else if (con == vc->vc_num) /* nothing to do */
3167 rc = sw->con_font_copy(vc, con);
3168 release_console_sem();
3172 int con_font_op(int currcons, struct console_font_op *op)
3175 case KD_FONT_OP_SET:
3176 return con_font_set(currcons, op);
3177 case KD_FONT_OP_GET:
3178 return con_font_get(currcons, op);
3179 case KD_FONT_OP_SET_DEFAULT:
3180 return con_font_default(currcons, op);
3181 case KD_FONT_OP_COPY:
3182 return con_font_copy(currcons, op);
3188 * Interface exported to selection and vcs.
3191 /* used by selection */
3192 u16 screen_glyph(struct vc_data *vc, int offset)
3194 u16 w = scr_readw(screenpos(vc, offset, 1));
3197 if (w & vc->vc_hi_font_mask)
3202 /* used by vcs - note the word offset */
3203 unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed)
3205 return screenpos(vc, 2 * w_offset, viewed);
3208 void getconsxy(struct vc_data *vc, unsigned char *p)
3214 void putconsxy(struct vc_data *vc, unsigned char *p)
3216 gotoxy(vc, p[0], p[1]);
3220 u16 vcs_scr_readw(struct vc_data *vc, const u16 *org)
3222 if ((unsigned long)org == vc->vc_pos && softcursor_original != -1)
3223 return softcursor_original;
3224 return scr_readw(org);
3227 void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org)
3229 scr_writew(val, org);
3230 if ((unsigned long)org == vc->vc_pos) {
3231 softcursor_original = -1;
3236 static int pm_con_request(struct pm_dev *dev, pm_request_t rqst, void *data)
3241 acquire_console_sem();
3243 release_console_sem();
3246 acquire_console_sem();
3248 release_console_sem();
3255 * Visible symbols for modules
3258 EXPORT_SYMBOL(color_table);
3259 EXPORT_SYMBOL(default_red);
3260 EXPORT_SYMBOL(default_grn);
3261 EXPORT_SYMBOL(default_blu);
3262 EXPORT_SYMBOL(update_region);
3263 EXPORT_SYMBOL(redraw_screen);
3264 EXPORT_SYMBOL(vc_resize);
3265 EXPORT_SYMBOL(fg_console);
3266 EXPORT_SYMBOL(console_blank_hook);
3267 EXPORT_SYMBOL(console_blanked);
3268 EXPORT_SYMBOL(vt_cons);
3269 EXPORT_SYMBOL(vc_cons);
3270 #ifndef VT_SINGLE_DRIVER
3271 EXPORT_SYMBOL(take_over_console);
3272 EXPORT_SYMBOL(give_up_console);