diff -urNp linux-3.15.orig/drivers/tty/vt/consolemap.c linux-3.15/drivers/tty/vt/consolemap.c --- linux-3.15.orig/drivers/tty/vt/consolemap.c 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/tty/vt/consolemap.c 2014-06-09 09:00:22.000000000 +0900 @@ -23,7 +23,11 @@ #include #include +#ifdef CONFIG_UNICON +unsigned short translations[][256] = { +#else static unsigned short translations[][256] = { +#endif /* 8-bit Latin-1 mapped to Unicode -- trivial mapping */ { 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, diff -urNp linux-3.15.orig/drivers/tty/vt/selection.c linux-3.15/drivers/tty/vt/selection.c --- linux-3.15.orig/drivers/tty/vt/selection.c 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/tty/vt/selection.c 2014-06-09 09:00:22.000000000 +0900 @@ -216,6 +216,31 @@ int set_selection(const struct tiocl_sel switch (sel_mode) { case TIOCL_SELCHAR: /* character-by-character selection */ +#ifdef CONFIG_UNICON + { + unsigned char c; + int num = 0; + int ps1 = ps; + + while(1) + { + c = sel_pos(ps1); + if(!(c & 0x80)) + break; + + num++; + if (!(ps1 % vc->vc_size_row)) + break; + ps1 -= 2; + } + if(num != 0) + { + if(num%2) + pe += 2; + else ps -= 2; + } + } +#endif new_sel_start = ps; new_sel_end = pe; break; @@ -224,7 +249,11 @@ int set_selection(const struct tiocl_sel for (new_sel_start = ps; ; ps -= 2) { if ((spc && !isspace(sel_pos(ps))) || +#ifdef CONFIG_UNICON + (!spc && !inword(sel_pos(ps))&& !(sel_pos(ps)&0x80))) +#else (!spc && !inword(sel_pos(ps)))) +#endif break; new_sel_start = ps; if (!(ps % vc->vc_size_row)) @@ -234,7 +263,12 @@ int set_selection(const struct tiocl_sel for (new_sel_end = pe; ; pe += 2) { if ((spc && !isspace(sel_pos(pe))) || +#ifdef CONFIG_UNICON + (!spc && !inword(sel_pos(pe))&& !(sel_pos(pe) & 0x80))) +#else + (!spc && !inword(sel_pos(pe)))) +#endif break; new_sel_end = pe; if (!((pe + 2) % vc->vc_size_row)) diff -urNp linux-3.15.orig/drivers/tty/vt/vt.c linux-3.15/drivers/tty/vt/vt.c --- linux-3.15.orig/drivers/tty/vt/vt.c 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/tty/vt/vt.c 2014-06-09 09:00:22.000000000 +0900 @@ -100,6 +100,11 @@ #include #include #include +#include +#ifdef CONFIG_UNICON +#include +extern unsigned short translations[][256]; +#endif #include #include @@ -292,6 +297,21 @@ static inline unsigned short *screenpos( return p; } +#ifdef CONFIG_UNICON +static inline unsigned short *screenpos_ext(struct vc_data *vc, int offset, int viewed) +{ + unsigned short *p; + + if (!viewed) + p = (unsigned short *)(vc->vc_origin + offset + vc->vc_screenbuf_size); + else if (!vc->vc_sw->con_screen_pos) + p = (unsigned short *)(vc->vc_visible_origin + offset + vc->vc_screenbuf_size); + else + p = vc->vc_sw->con_screen_pos(vc, -offset-1); + return p; +} +#endif + /* Called from the keyboard irq path.. */ static inline void scrolldelta(int lines) { @@ -322,6 +342,13 @@ static void scrup(struct vc_data *vc, un scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row); scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char, vc->vc_size_row * nr); +#ifdef CONFIG_UNICON + d += (vc->vc_screenbuf_size>>1); + s += (vc->vc_screenbuf_size>>1); + scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row); + scr_memsetw(d + (b - t - nr) * vc->vc_cols, (vc->vc_video_erase_char & 0xff), + vc->vc_size_row * nr); +#endif } static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr) @@ -339,6 +366,11 @@ static void scrdown(struct vc_data *vc, step = vc->vc_cols * nr; scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row); scr_memsetw(s, vc->vc_video_erase_char, 2 * step); +#ifdef CONFIG_UNICON + s += (vc->vc_screenbuf_size>>1); + scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row); + scr_memsetw(s, (vc->vc_video_erase_char & 0xff), 2 * step); +#endif } static void do_update_region(struct vc_data *vc, unsigned long start, int count) @@ -362,6 +394,10 @@ static void do_update_region(struct vc_d int startx = xx; u16 *q = p; while (xx < vc->vc_cols && count) { +#ifdef CONFIG_UNICON + //line by line, so the following putcs will be assured to + //handle only in-line string. +#endif if (attrib != (scr_readw(p) & 0xff00)) { if (p > q) vc->vc_sw->con_putcs(vc, q, p-q, yy, startx); @@ -504,16 +540,30 @@ void invert_screen(struct vc_data *vc, i void complement_pos(struct vc_data *vc, int offset) { static int old_offset = -1; +#ifdef CONFIG_UNICON + static unsigned short old = 0; + static unsigned short oldx = 0, oldy = 0; + static unsigned short *p_ext = NULL; + static unsigned short old_ext = 0; +#else static unsigned short old; static unsigned short oldx, oldy; +#endif WARN_CONSOLE_UNLOCKED(); if (old_offset != -1 && old_offset >= 0 && old_offset < vc->vc_screenbuf_size) { scr_writew(old, screenpos(vc, old_offset, 1)); +#ifdef CONFIG_UNICON + //scr_writew(old_ext, screenpos_ext(vc, old_offset, 1)); +#endif if (DO_UPDATE(vc)) +#ifdef CONFIG_UNICON + vc->vc_sw->con_putc(vc, (old_ext<<16) | old, oldy, oldx); +#else vc->vc_sw->con_putc(vc, old, oldy, oldx); +#endif } old_offset = offset; @@ -523,13 +573,23 @@ void complement_pos(struct vc_data *vc, unsigned short new; unsigned short *p; p = screenpos(vc, offset, 1); +#ifdef CONFIG_UNICON + p_ext = screenpos_ext(vc, offset, 1); +#endif old = scr_readw(p); +#ifdef CONFIG_UNICON + old_ext = scr_readw(p_ext); +#endif new = old ^ vc->vc_complement_mask; scr_writew(new, p); if (DO_UPDATE(vc)) { oldx = (offset >> 1) % vc->vc_cols; oldy = (offset >> 1) / vc->vc_cols; +#ifdef CONFIG_UNICON + vc->vc_sw->con_putc(vc, (old_ext<<16) | new, oldy, oldx); +#else vc->vc_sw->con_putc(vc, new, oldy, oldx); +#endif } } @@ -541,6 +601,11 @@ static void insert_char(struct vc_data * scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2); scr_memsetw(p, vc->vc_video_erase_char, nr * 2); +#ifdef CONFIG_UNICON + scr_memmovew(p + nr + (vc->vc_screenbuf_size>>1), p + (vc->vc_screenbuf_size>>1), + (vc->vc_cols - vc->vc_x - nr) * 2); + scr_memsetw(p + (vc->vc_screenbuf_size>>1), (vc->vc_video_erase_char & 0xff), nr * 2); +#endif vc->vc_need_wrap = 0; if (DO_UPDATE(vc)) do_update_region(vc, (unsigned long) p, @@ -552,8 +617,16 @@ static void delete_char(struct vc_data * unsigned short *p = (unsigned short *) vc->vc_pos; scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2); +#ifdef CONFIG_UNICON + scr_memcpyw(p + (vc->vc_screenbuf_size>>1), p + nr + (vc->vc_screenbuf_size>>1), + (vc->vc_cols - vc->vc_x - nr) * 2); +#endif scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char, nr * 2); +#ifdef CONFIG_UNICON + scr_memsetw(p + vc->vc_cols - vc->vc_x - nr + (vc->vc_screenbuf_size>>1), + (vc->vc_video_erase_char & 0xff), nr * 2); +#endif vc->vc_need_wrap = 0; if (DO_UPDATE(vc)) do_update_region(vc, (unsigned long) p, @@ -576,7 +649,11 @@ static void add_softcursor(struct vc_dat if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700; scr_writew(i, (u16 *) vc->vc_pos); if (DO_UPDATE(vc)) +#ifdef CONFIG_UNICON + vc->vc_sw->con_putc(vc, scr_readw((u16 *) vc->vc_pos+ (vc->vc_screenbuf_size>>1))<<16 | (i & 0xffff), vc->vc_y, vc->vc_x); +#else vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x); +#endif } static void hide_softcursor(struct vc_data *vc) @@ -584,8 +661,13 @@ static void hide_softcursor(struct vc_da if (softcursor_original != -1) { scr_writew(softcursor_original, (u16 *)vc->vc_pos); if (DO_UPDATE(vc)) +#ifdef CONFIG_UNICON + vc->vc_sw->con_putc(vc, scr_readw((u16 *) vc->vc_pos+ (vc->vc_screenbuf_size>>1))<<16 | softcursor_original, + vc->vc_y, vc->vc_x); +#else vc->vc_sw->con_putc(vc, softcursor_original, vc->vc_y, vc->vc_x); +#endif softcursor_original = -1; } } @@ -777,7 +859,11 @@ int vc_allocate(unsigned int currcons) / visual_init(vc, currcons, 1); if (!*vc->vc_uni_pagedir_loc) con_set_default_unimap(vc); +#ifdef CONFIG_UNICON + vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size * 2, GFP_KERNEL); +#else vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); +#endif if (!vc->vc_screenbuf) { kfree(vc); vc_cons[currcons].d = NULL; @@ -837,7 +923,7 @@ static int vc_do_resize(struct tty_struc { unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; unsigned long end; - unsigned int old_rows, old_row_size; + unsigned int old_rows, old_row_size, old_screen_size; unsigned int new_cols, new_rows, new_row_size, new_screen_size; unsigned int user; unsigned short *newscreen; @@ -861,12 +947,19 @@ static int vc_do_resize(struct tty_struc if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) return 0; +#ifdef CONFIG_UNICON + newscreen = kmalloc(new_screen_size*2, GFP_USER); +#else newscreen = kmalloc(new_screen_size, GFP_USER); +#endif if (!newscreen) return -ENOMEM; old_rows = vc->vc_rows; old_row_size = vc->vc_size_row; +#ifdef CONFIG_UNICON + old_screen_size = vc->vc_screenbuf_size; +#endif err = resize_screen(vc, new_cols, new_rows, user); if (err) { @@ -908,15 +1001,30 @@ static int vc_do_resize(struct tty_struc while (old_origin < end) { scr_memcpyw((unsigned short *) new_origin, (unsigned short *) old_origin, rlth); - if (rrem) +#ifdef CONFIG_UNICON + scr_memcpyw((unsigned short *) (new_origin + new_screen_size), + (unsigned short *) (old_origin + old_screen_size), + rlth); +#endif + if (rrem) { scr_memsetw((void *)(new_origin + rlth), vc->vc_video_erase_char, rrem); +#ifdef CONFIG_UNICON + scr_memsetw((void *)(new_origin + rlth + new_screen_size), + (vc->vc_video_erase_char & 0xff), rrem); +#endif + } old_origin += old_row_size; new_origin += new_row_size; } - if (new_scr_end > new_origin) + if (new_scr_end > new_origin) { scr_memsetw((void *)new_origin, vc->vc_video_erase_char, new_scr_end - new_origin); +#ifdef CONFIG_UNICON + scr_memsetw((void *)(new_origin + new_screen_size), (vc->vc_video_erase_char & 0xff), + new_scr_end - new_origin); +#endif + } kfree(vc->vc_screenbuf); vc->vc_screenbuf = newscreen; vc->vc_screenbuf_size = new_screen_size; @@ -1175,6 +1283,9 @@ static void csi_J(struct vc_data *vc, in return; } scr_memsetw(start, vc->vc_video_erase_char, 2 * count); +#ifdef CONFIG_UNICON + scr_memsetw(start + (vc->vc_screenbuf_size>>1), (vc->vc_video_erase_char & 0xff), 2 * count); +#endif if (DO_UPDATE(vc)) do_update_region(vc, (unsigned long) start, count); vc->vc_need_wrap = 0; @@ -1202,6 +1313,9 @@ static void csi_K(struct vc_data *vc, in return; } scr_memsetw(start, vc->vc_video_erase_char, 2 * count); +#ifdef CONFIG_UNICON + scr_memsetw(start + (vc->vc_screenbuf_size>>1), (vc->vc_video_erase_char & 0xff), 2 * count); +#endif vc->vc_need_wrap = 0; if (DO_UPDATE(vc)) do_update_region(vc, (unsigned long) start, count); @@ -1216,6 +1330,9 @@ static void csi_X(struct vc_data *vc, in count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar; scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); +#ifdef CONFIG_UNICON + scr_memsetw((unsigned short *)vc->vc_pos + (vc->vc_screenbuf_size>>1), (vc->vc_video_erase_char & 0xff), 2 * count); +#endif if (DO_UPDATE(vc)) vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count); vc->vc_need_wrap = 0; @@ -1835,7 +1952,13 @@ static void do_con_trol(struct tty_struc if (vc->vc_ques) { clear_selection(); if (vc->vc_par[0]) +#ifdef CONFIG_UNICON + // force the low byte to be zero + + vc->vc_complement_mask = vc->vc_par[0] << 8; +#else vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1]; +#endif else vc->vc_complement_mask = vc->vc_s_complement_mask; return; @@ -2095,6 +2218,12 @@ static int do_con_write(struct tty_struc uint8_t inverse; uint8_t width; u16 himask, charmask; +#ifdef CONFIG_UNICON + /* added by Arthur Ma, for multiple font support */ + struct double_byte * doublebyte_default = NULL; +#define GB_LEFT 0x8000 +#define GB_RIGHT 0xc000 +#endif if (in_interrupt()) return count; @@ -2109,6 +2238,12 @@ static int do_con_write(struct tty_struc return 0; } +#ifdef CONFIG_UNICON + /* added by Arthur Ma, for multiple font support */ + if (UniconFontManager != NULL) + doublebyte_default = UniconFontManager->getfont (vc->vc_num); +#endif + currcons = vc->vc_num; if (!vc_cons_allocated(currcons)) { /* could this happen? */ @@ -2292,6 +2427,58 @@ rescan_last_byte: ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) : (vc_attr << 8) + tc, (u16 *) vc->vc_pos); +#ifdef CONFIG_UNICON +#define HIGH_WORD ((u16 *) ((long)vc->vc_pos + vc->vc_screenbuf_size)) +#define HIGH_WORD_PREV ((u16 *) ((long)vc->vc_pos - 2 + vc->vc_screenbuf_size)) +#define HIGH_WORD_NEXT ((u16 *) ((long)vc->vc_pos + 2 + vc->vc_screenbuf_size)) + /* + * following condiction we do not tread the char + * as double byte. + * 1. default encoding is NULL. The encode module + * not install yet. + * 2. Current char set is not the default one. + * We are possible drawing a table lines right + * now. + * -Chris + */ + if (doublebyte_default && vc->vc_translate == translations[0] + && (vc->vc_pos==vc->vc_origin||!(scr_readw(HIGH_WORD_PREV)&DB_HALF_MASK)) + && doublebyte_default->is_left(tc)){ + /* + * possible the left char of the Double + * Byte, but we don't know yet, because + * the right char is unknow right now. + * So mark it as Half char, the possible + * candidate + * -Chris + */ + scr_writew(DB_HALF_MASK,HIGH_WORD); + + } else if(doublebyte_default&& vc->vc_translate == translations[0] + && scr_readw(HIGH_WORD_PREV)==DB_HALF_MASK + && doublebyte_default->is_right(tc)) { + scr_writew(DB_LEFT|(tc & 0xff),HIGH_WORD_PREV); + scr_writew(DB_RIGHT|(scr_readw((u16*)(vc->vc_pos-2))&0xff),HIGH_WORD); + if (DO_UPDATE(vc) && draw_x < 0) { + draw_from = vc->vc_pos-2; + if (vc->vc_x>0) { + draw_x = vc->vc_x-1; + } else { + draw_to = vc->vc_pos; + draw_x = vc->vc_cols -1; + vc->vc_y--; + FLUSH + vc->vc_y++; + draw_x = 0; + draw_from = vc->vc_pos; + } + } + } else if(doublebyte_default) { + /* normal ASCII or table lines, + clean hight byte */ + scr_writew(0,HIGH_WORD); + } +#endif if (DO_UPDATE(vc) && draw_x < 0) { draw_x = vc->vc_x; draw_from = vc->vc_pos; @@ -2351,6 +2538,11 @@ static void console_callback(struct work if (want_console >= 0) { if (want_console != fg_console && vc_cons_allocated(want_console)) { +#ifdef CONFIG_UNICON + extern void (*Unicon_TtyChangeUpdate) (int nTty); + if (Unicon_TtyChangeUpdate != NULL) + (*Unicon_TtyChangeUpdate) (want_console); +#endif hide_cursor(vc_cons[fg_console].d); change_console(vc_cons[want_console].d); /* we only changed when the console had already @@ -2511,6 +2703,9 @@ static void vt_console_print(struct cons continue; } scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos); +#ifdef CONFIG_UNICON + scr_writew(0, (unsigned short *)vc->vc_pos + (vc->vc_screenbuf_size>>1)); +#endif notify_write(vc, c); cnt++; if (myx == vc->vc_cols - 1) { @@ -2907,7 +3102,11 @@ static int __init con_init(void) INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); tty_port_init(&vc->port); visual_init(vc, currcons, 1); +#ifdef CONFIG_UNICON + vc->vc_screenbuf = kzalloc(2 * vc->vc_screenbuf_size, GFP_NOWAIT); +#else vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); +#endif vc_init(vc, vc->vc_rows, vc->vc_cols, currcons || !vc->vc_sw->con_save_screen); } @@ -4157,6 +4356,12 @@ void putconsxy(struct vc_data *vc, unsig set_cursor(vc); } +#ifdef CONFIG_UNICON +/* + Now, the unicon doesn't support vcs! + To support it, first change the vc_screen.c! +*/ +#endif u16 vcs_scr_readw(struct vc_data *vc, const u16 *org) { if ((unsigned long)org == vc->vc_pos && softcursor_original != -1) @@ -4182,6 +4387,18 @@ void vcs_scr_updated(struct vc_data *vc) * Visible symbols for modules */ +#ifdef CONFIG_UNICON +int (*Unicon_fnKeyHook) + (struct tty_struct *tty, unsigned char ch, char flag) = NULL; +int (*Unicon_fnLowerKeyHook) (unsigned char ch) = NULL; +void (*Unicon_TtyChangeUpdate) (int nTty) = NULL; +EXPORT_SYMBOL(Unicon_fnLowerKeyHook); +EXPORT_SYMBOL(Unicon_fnKeyHook); +EXPORT_SYMBOL(Unicon_TtyChangeUpdate); +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) +EXPORT_SYMBOL(vc_cons); +#endif +#endif EXPORT_SYMBOL(color_table); EXPORT_SYMBOL(default_red); EXPORT_SYMBOL(default_grn); diff -urNp linux-3.15.orig/drivers/tty/vt/vt.c.orig linux-3.15/drivers/tty/vt/vt.c.orig --- linux-3.15.orig/drivers/tty/vt/vt.c.orig 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/tty/vt/vt.c.orig 2014-06-09 03:19:54.000000000 +0900 @@ -0,0 +1,4199 @@ +/* + * Copyright (C) 1991, 1992 Linus Torvalds + */ + +/* + * Hopefully this will be a rather complete VT102 implementation. + * + * Beeping thanks to John T Kohl. + * + * Virtual Consoles, Screen Blanking, Screen Dumping, Color, Graphics + * Chars, and VT100 enhancements by Peter MacDonald. + * + * Copy and paste function by Andrew Haylett, + * some enhancements by Alessandro Rubini. + * + * Code to check for different video-cards mostly by Galen Hunt, + * + * + * Rudimentary ISO 10646/Unicode/UTF-8 character set support by + * Markus Kuhn, . + * + * Dynamic allocation of consoles, aeb@cwi.nl, May 1994 + * Resizing of consoles, aeb, 940926 + * + * Code for xterm like mouse click reporting by Peter Orbaek 20-Jul-94 + * + * + * User-defined bell sound, new setterm control sequences and printk + * redirection by Martin Mares 19-Nov-95 + * + * APM screenblank bug fixed Takashi Manabe + * + * Merge with the abstract console driver by Geert Uytterhoeven + * , Jan 1997. + * + * Original m68k console driver modifications by + * + * - Arno Griffioen + * - David Carter + * + * The abstract console driver provides a generic interface for a text + * console. It supports VGA text mode, frame buffer based graphical consoles + * and special graphics processors that are only accessible through some + * registers (e.g. a TMS340x0 GSP). + * + * The interface to the hardware is specified using a special structure + * (struct consw) which contains function pointers to console operations + * (see for more information). + * + * Support for changeable cursor shape + * by Pavel Machek , August 1997 + * + * Ported to i386 and con_scrolldelta fixed + * by Emmanuel Marty , April 1998 + * + * Resurrected character buffers in videoram plus lots of other trickery + * by Martin Mares , July 1998 + * + * Removed old-style timers, introduced console_timer, made timer + * deletion SMP-safe. 17Jun00, Andrew Morton + * + * Removed console_lock, enabled interrupts across all console operations + * 13 March 2001, Andrew Morton + * + * Fixed UTF-8 mode so alternate charset modes always work according + * to control sequences interpreted in do_con_trol function + * preserving backward VT100 semigraphics compatibility, + * malformed UTF sequences represented as sequences of replacement glyphs, + * original codes or '?' as a last resort if replacement glyph is undefined + * by Adam Tla/lka , Aug 2006 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX_NR_CON_DRIVER 16 + +#define CON_DRIVER_FLAG_MODULE 1 +#define CON_DRIVER_FLAG_INIT 2 +#define CON_DRIVER_FLAG_ATTR 4 + +struct con_driver { + const struct consw *con; + const char *desc; + struct device *dev; + int node; + int first; + int last; + int flag; +}; + +static struct con_driver registered_con_driver[MAX_NR_CON_DRIVER]; +const struct consw *conswitchp; + +/* A bitmap for codes <32. A bit of 1 indicates that the code + * corresponding to that bit number invokes some special action + * (such as cursor movement) and should not be displayed as a + * glyph unless the disp_ctrl mode is explicitly enabled. + */ +#define CTRL_ACTION 0x0d00ff81 +#define CTRL_ALWAYS 0x0800f501 /* Cannot be overridden by disp_ctrl */ + +/* + * Here is the default bell parameters: 750HZ, 1/8th of a second + */ +#define DEFAULT_BELL_PITCH 750 +#define DEFAULT_BELL_DURATION (HZ/8) + +struct vc vc_cons [MAX_NR_CONSOLES]; + +#ifndef VT_SINGLE_DRIVER +static const struct consw *con_driver_map[MAX_NR_CONSOLES]; +#endif + +static int con_open(struct tty_struct *, struct file *); +static void vc_init(struct vc_data *vc, unsigned int rows, + unsigned int cols, int do_clear); +static void gotoxy(struct vc_data *vc, int new_x, int new_y); +static void save_cur(struct vc_data *vc); +static void reset_terminal(struct vc_data *vc, int do_clear); +static void con_flush_chars(struct tty_struct *tty); +static int set_vesa_blanking(char __user *p); +static void set_cursor(struct vc_data *vc); +static void hide_cursor(struct vc_data *vc); +static void console_callback(struct work_struct *ignored); +static void blank_screen_t(unsigned long dummy); +static void set_palette(struct vc_data *vc); + +static int printable; /* Is console ready for printing? */ +int default_utf8 = true; +module_param(default_utf8, int, S_IRUGO | S_IWUSR); +int global_cursor_default = -1; +module_param(global_cursor_default, int, S_IRUGO | S_IWUSR); + +static int cur_default = CUR_DEFAULT; +module_param(cur_default, int, S_IRUGO | S_IWUSR); + +/* + * ignore_poke: don't unblank the screen when things are typed. This is + * mainly for the privacy of braille terminal users. + */ +static int ignore_poke; + +int do_poke_blanked_console; +int console_blanked; + +static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */ +static int vesa_off_interval; +static int blankinterval = 10*60; +core_param(consoleblank, blankinterval, int, 0444); + +static DECLARE_WORK(console_work, console_callback); + +/* + * fg_console is the current virtual console, + * last_console is the last used one, + * want_console is the console we want to switch to, + * saved_* variants are for save/restore around kernel debugger enter/leave + */ +int fg_console; +int last_console; +int want_console = -1; +static int saved_fg_console; +static int saved_last_console; +static int saved_want_console; +static int saved_vc_mode; +static int saved_console_blanked; + +/* + * For each existing display, we have a pointer to console currently visible + * on that display, allowing consoles other than fg_console to be refreshed + * appropriately. Unless the low-level driver supplies its own display_fg + * variable, we use this one for the "master display". + */ +static struct vc_data *master_display_fg; + +/* + * Unfortunately, we need to delay tty echo when we're currently writing to the + * console since the code is (and always was) not re-entrant, so we schedule + * all flip requests to process context with schedule-task() and run it from + * console_callback(). + */ + +/* + * For the same reason, we defer scrollback to the console callback. + */ +static int scrollback_delta; + +/* + * Hook so that the power management routines can (un)blank + * the console on our behalf. + */ +int (*console_blank_hook)(int); + +static DEFINE_TIMER(console_timer, blank_screen_t, 0, 0); +static int blank_state; +static int blank_timer_expired; +enum { + blank_off = 0, + blank_normal_wait, + blank_vesa_wait, +}; + +/* + * /sys/class/tty/tty0/ + * + * the attribute 'active' contains the name of the current vc + * console and it supports poll() to detect vc switches + */ +static struct device *tty0dev; + +/* + * Notifier list for console events. + */ +static ATOMIC_NOTIFIER_HEAD(vt_notifier_list); + +int register_vt_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&vt_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(register_vt_notifier); + +int unregister_vt_notifier(struct notifier_block *nb) +{ + return atomic_notifier_chain_unregister(&vt_notifier_list, nb); +} +EXPORT_SYMBOL_GPL(unregister_vt_notifier); + +static void notify_write(struct vc_data *vc, unsigned int unicode) +{ + struct vt_notifier_param param = { .vc = vc, .c = unicode }; + atomic_notifier_call_chain(&vt_notifier_list, VT_WRITE, ¶m); +} + +static void notify_update(struct vc_data *vc) +{ + struct vt_notifier_param param = { .vc = vc }; + atomic_notifier_call_chain(&vt_notifier_list, VT_UPDATE, ¶m); +} +/* + * Low-Level Functions + */ + +#define IS_FG(vc) ((vc)->vc_num == fg_console) + +#ifdef VT_BUF_VRAM_ONLY +#define DO_UPDATE(vc) 0 +#else +#define DO_UPDATE(vc) (CON_IS_VISIBLE(vc) && !console_blanked) +#endif + +static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewed) +{ + unsigned short *p; + + if (!viewed) + p = (unsigned short *)(vc->vc_origin + offset); + else if (!vc->vc_sw->con_screen_pos) + p = (unsigned short *)(vc->vc_visible_origin + offset); + else + p = vc->vc_sw->con_screen_pos(vc, offset); + return p; +} + +/* Called from the keyboard irq path.. */ +static inline void scrolldelta(int lines) +{ + /* FIXME */ + /* scrolldelta needs some kind of consistency lock, but the BKL was + and still is not protecting versus the scheduled back end */ + scrollback_delta += lines; + schedule_console_callback(); +} + +void schedule_console_callback(void) +{ + schedule_work(&console_work); +} + +static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr) +{ + unsigned short *d, *s; + + if (t+nr >= b) + nr = b - t - 1; + if (b > vc->vc_rows || t >= b || nr < 1) + return; + if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_UP, nr)) + return; + d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); + s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr)); + scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row); + scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char, + vc->vc_size_row * nr); +} + +static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr) +{ + unsigned short *s; + unsigned int step; + + if (t+nr >= b) + nr = b - t - 1; + if (b > vc->vc_rows || t >= b || nr < 1) + return; + if (CON_IS_VISIBLE(vc) && vc->vc_sw->con_scroll(vc, t, b, SM_DOWN, nr)) + return; + s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); + step = vc->vc_cols * nr; + scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row); + scr_memsetw(s, vc->vc_video_erase_char, 2 * step); +} + +static void do_update_region(struct vc_data *vc, unsigned long start, int count) +{ +#ifndef VT_BUF_VRAM_ONLY + unsigned int xx, yy, offset; + u16 *p; + + p = (u16 *) start; + if (!vc->vc_sw->con_getxy) { + offset = (start - vc->vc_origin) / 2; + xx = offset % vc->vc_cols; + yy = offset / vc->vc_cols; + } else { + int nxx, nyy; + start = vc->vc_sw->con_getxy(vc, start, &nxx, &nyy); + xx = nxx; yy = nyy; + } + for(;;) { + u16 attrib = scr_readw(p) & 0xff00; + int startx = xx; + u16 *q = p; + while (xx < vc->vc_cols && count) { + if (attrib != (scr_readw(p) & 0xff00)) { + if (p > q) + vc->vc_sw->con_putcs(vc, q, p-q, yy, startx); + startx = xx; + q = p; + attrib = scr_readw(p) & 0xff00; + } + p++; + xx++; + count--; + } + if (p > q) + vc->vc_sw->con_putcs(vc, q, p-q, yy, startx); + if (!count) + break; + xx = 0; + yy++; + if (vc->vc_sw->con_getxy) { + p = (u16 *)start; + start = vc->vc_sw->con_getxy(vc, start, NULL, NULL); + } + } +#endif +} + +void update_region(struct vc_data *vc, unsigned long start, int count) +{ + WARN_CONSOLE_UNLOCKED(); + + if (DO_UPDATE(vc)) { + hide_cursor(vc); + do_update_region(vc, start, count); + set_cursor(vc); + } +} + +/* Structure of attributes is hardware-dependent */ + +static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, + u8 _underline, u8 _reverse, u8 _italic) +{ + if (vc->vc_sw->con_build_attr) + return vc->vc_sw->con_build_attr(vc, _color, _intensity, + _blink, _underline, _reverse, _italic); + +#ifndef VT_BUF_VRAM_ONLY +/* + * ++roman: I completely changed the attribute format for monochrome + * mode (!can_do_color). The formerly used MDA (monochrome display + * adapter) format didn't allow the combination of certain effects. + * Now the attribute is just a bit vector: + * Bit 0..1: intensity (0..2) + * Bit 2 : underline + * Bit 3 : reverse + * Bit 7 : blink + */ + { + u8 a = _color; + if (!vc->vc_can_do_color) + return _intensity | + (_italic ? 2 : 0) | + (_underline ? 4 : 0) | + (_reverse ? 8 : 0) | + (_blink ? 0x80 : 0); + if (_italic) + a = (a & 0xF0) | vc->vc_itcolor; + else if (_underline) + a = (a & 0xf0) | vc->vc_ulcolor; + else if (_intensity == 0) + a = (a & 0xf0) | vc->vc_ulcolor; + if (_reverse) + a = ((a) & 0x88) | ((((a) >> 4) | ((a) << 4)) & 0x77); + if (_blink) + a ^= 0x80; + if (_intensity == 2) + a ^= 0x08; + if (vc->vc_hi_font_mask == 0x100) + a <<= 1; + return a; + } +#else + return 0; +#endif +} + +static void update_attr(struct vc_data *vc) +{ + vc->vc_attr = build_attr(vc, vc->vc_color, vc->vc_intensity, + vc->vc_blink, vc->vc_underline, + vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic); + vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' '; +} + +/* Note: inverting the screen twice should revert to the original state */ +void invert_screen(struct vc_data *vc, int offset, int count, int viewed) +{ + unsigned short *p; + + WARN_CONSOLE_UNLOCKED(); + + count /= 2; + p = screenpos(vc, offset, viewed); + if (vc->vc_sw->con_invert_region) + vc->vc_sw->con_invert_region(vc, p, count); +#ifndef VT_BUF_VRAM_ONLY + else { + u16 *q = p; + int cnt = count; + u16 a; + + if (!vc->vc_can_do_color) { + while (cnt--) { + a = scr_readw(q); + a ^= 0x0800; + scr_writew(a, q); + q++; + } + } else if (vc->vc_hi_font_mask == 0x100) { + while (cnt--) { + a = scr_readw(q); + a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | (((a) & 0x0e00) << 4); + scr_writew(a, q); + q++; + } + } else { + while (cnt--) { + a = scr_readw(q); + a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | (((a) & 0x0700) << 4); + scr_writew(a, q); + q++; + } + } + } +#endif + if (DO_UPDATE(vc)) + do_update_region(vc, (unsigned long) p, count); +} + +/* used by selection: complement pointer position */ +void complement_pos(struct vc_data *vc, int offset) +{ + static int old_offset = -1; + static unsigned short old; + static unsigned short oldx, oldy; + + WARN_CONSOLE_UNLOCKED(); + + if (old_offset != -1 && old_offset >= 0 && + old_offset < vc->vc_screenbuf_size) { + scr_writew(old, screenpos(vc, old_offset, 1)); + if (DO_UPDATE(vc)) + vc->vc_sw->con_putc(vc, old, oldy, oldx); + } + + old_offset = offset; + + if (offset != -1 && offset >= 0 && + offset < vc->vc_screenbuf_size) { + unsigned short new; + unsigned short *p; + p = screenpos(vc, offset, 1); + old = scr_readw(p); + new = old ^ vc->vc_complement_mask; + scr_writew(new, p); + if (DO_UPDATE(vc)) { + oldx = (offset >> 1) % vc->vc_cols; + oldy = (offset >> 1) / vc->vc_cols; + vc->vc_sw->con_putc(vc, new, oldy, oldx); + } + } + +} + +static void insert_char(struct vc_data *vc, unsigned int nr) +{ + unsigned short *p = (unsigned short *) vc->vc_pos; + + scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2); + scr_memsetw(p, vc->vc_video_erase_char, nr * 2); + vc->vc_need_wrap = 0; + if (DO_UPDATE(vc)) + do_update_region(vc, (unsigned long) p, + vc->vc_cols - vc->vc_x); +} + +static void delete_char(struct vc_data *vc, unsigned int nr) +{ + unsigned short *p = (unsigned short *) vc->vc_pos; + + scr_memcpyw(p, p + nr, (vc->vc_cols - vc->vc_x - nr) * 2); + scr_memsetw(p + vc->vc_cols - vc->vc_x - nr, vc->vc_video_erase_char, + nr * 2); + vc->vc_need_wrap = 0; + if (DO_UPDATE(vc)) + do_update_region(vc, (unsigned long) p, + vc->vc_cols - vc->vc_x); +} + +static int softcursor_original; + +static void add_softcursor(struct vc_data *vc) +{ + int i = scr_readw((u16 *) vc->vc_pos); + u32 type = vc->vc_cursor_type; + + if (! (type & 0x10)) return; + if (softcursor_original != -1) return; + softcursor_original = i; + i |= ((type >> 8) & 0xff00 ); + i ^= ((type) & 0xff00 ); + if ((type & 0x20) && ((softcursor_original & 0x7000) == (i & 0x7000))) i ^= 0x7000; + if ((type & 0x40) && ((i & 0x700) == ((i & 0x7000) >> 4))) i ^= 0x0700; + scr_writew(i, (u16 *) vc->vc_pos); + if (DO_UPDATE(vc)) + vc->vc_sw->con_putc(vc, i, vc->vc_y, vc->vc_x); +} + +static void hide_softcursor(struct vc_data *vc) +{ + if (softcursor_original != -1) { + scr_writew(softcursor_original, (u16 *)vc->vc_pos); + if (DO_UPDATE(vc)) + vc->vc_sw->con_putc(vc, softcursor_original, + vc->vc_y, vc->vc_x); + softcursor_original = -1; + } +} + +static void hide_cursor(struct vc_data *vc) +{ + if (vc == sel_cons) + clear_selection(); + vc->vc_sw->con_cursor(vc, CM_ERASE); + hide_softcursor(vc); +} + +static void set_cursor(struct vc_data *vc) +{ + if (!IS_FG(vc) || console_blanked || + vc->vc_mode == KD_GRAPHICS) + return; + if (vc->vc_deccm) { + if (vc == sel_cons) + clear_selection(); + add_softcursor(vc); + if ((vc->vc_cursor_type & 0x0f) != 1) + vc->vc_sw->con_cursor(vc, CM_DRAW); + } else + hide_cursor(vc); +} + +static void set_origin(struct vc_data *vc) +{ + WARN_CONSOLE_UNLOCKED(); + + if (!CON_IS_VISIBLE(vc) || + !vc->vc_sw->con_set_origin || + !vc->vc_sw->con_set_origin(vc)) + vc->vc_origin = (unsigned long)vc->vc_screenbuf; + vc->vc_visible_origin = vc->vc_origin; + vc->vc_scr_end = vc->vc_origin + vc->vc_screenbuf_size; + vc->vc_pos = vc->vc_origin + vc->vc_size_row * vc->vc_y + 2 * vc->vc_x; +} + +static inline void save_screen(struct vc_data *vc) +{ + WARN_CONSOLE_UNLOCKED(); + + if (vc->vc_sw->con_save_screen) + vc->vc_sw->con_save_screen(vc); +} + +/* + * Redrawing of screen + */ + +void clear_buffer_attributes(struct vc_data *vc) +{ + unsigned short *p = (unsigned short *)vc->vc_origin; + int count = vc->vc_screenbuf_size / 2; + int mask = vc->vc_hi_font_mask | 0xff; + + for (; count > 0; count--, p++) { + scr_writew((scr_readw(p)&mask) | (vc->vc_video_erase_char & ~mask), p); + } +} + +void redraw_screen(struct vc_data *vc, int is_switch) +{ + int redraw = 0; + + WARN_CONSOLE_UNLOCKED(); + + if (!vc) { + /* strange ... */ + /* printk("redraw_screen: tty %d not allocated ??\n", new_console+1); */ + return; + } + + if (is_switch) { + struct vc_data *old_vc = vc_cons[fg_console].d; + if (old_vc == vc) + return; + if (!CON_IS_VISIBLE(vc)) + redraw = 1; + *vc->vc_display_fg = vc; + fg_console = vc->vc_num; + hide_cursor(old_vc); + if (!CON_IS_VISIBLE(old_vc)) { + save_screen(old_vc); + set_origin(old_vc); + } + if (tty0dev) + sysfs_notify(&tty0dev->kobj, NULL, "active"); + } else { + hide_cursor(vc); + redraw = 1; + } + + if (redraw) { + int update; + int old_was_color = vc->vc_can_do_color; + + set_origin(vc); + update = vc->vc_sw->con_switch(vc); + set_palette(vc); + /* + * If console changed from mono<->color, the best we can do + * is to clear the buffer attributes. As it currently stands, + * rebuilding new attributes from the old buffer is not doable + * without overly complex code. + */ + if (old_was_color != vc->vc_can_do_color) { + update_attr(vc); + clear_buffer_attributes(vc); + } + + /* Forcibly update if we're panicing */ + if ((update && vc->vc_mode != KD_GRAPHICS) || + vt_force_oops_output(vc)) + do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2); + } + set_cursor(vc); + if (is_switch) { + set_leds(); + compute_shiftstate(); + notify_update(vc); + } +} + +/* + * Allocation, freeing and resizing of VTs. + */ + +int vc_cons_allocated(unsigned int i) +{ + return (i < MAX_NR_CONSOLES && vc_cons[i].d); +} + +static void visual_init(struct vc_data *vc, int num, int init) +{ + /* ++Geert: vc->vc_sw->con_init determines console size */ + if (vc->vc_sw) + module_put(vc->vc_sw->owner); + vc->vc_sw = conswitchp; +#ifndef VT_SINGLE_DRIVER + if (con_driver_map[num]) + vc->vc_sw = con_driver_map[num]; +#endif + __module_get(vc->vc_sw->owner); + vc->vc_num = num; + vc->vc_display_fg = &master_display_fg; + vc->vc_uni_pagedir_loc = &vc->vc_uni_pagedir; + vc->vc_uni_pagedir = 0; + vc->vc_hi_font_mask = 0; + vc->vc_complement_mask = 0; + vc->vc_can_do_color = 0; + vc->vc_panic_force_write = false; + vc->vc_sw->con_init(vc, init); + if (!vc->vc_complement_mask) + vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; + vc->vc_s_complement_mask = vc->vc_complement_mask; + vc->vc_size_row = vc->vc_cols << 1; + vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row; +} + +int vc_allocate(unsigned int currcons) /* return 0 on success */ +{ + WARN_CONSOLE_UNLOCKED(); + + if (currcons >= MAX_NR_CONSOLES) + return -ENXIO; + if (!vc_cons[currcons].d) { + struct vc_data *vc; + struct vt_notifier_param param; + + /* prevent users from taking too much memory */ + if (currcons >= MAX_NR_USER_CONSOLES && !capable(CAP_SYS_RESOURCE)) + return -EPERM; + + /* due to the granularity of kmalloc, we waste some memory here */ + /* the alloc is done in two steps, to optimize the common situation + of a 25x80 console (structsize=216, screenbuf_size=4000) */ + /* although the numbers above are not valid since long ago, the + point is still up-to-date and the comment still has its value + even if only as a historical artifact. --mj, July 1998 */ + param.vc = vc = kzalloc(sizeof(struct vc_data), GFP_KERNEL); + if (!vc) + return -ENOMEM; + vc_cons[currcons].d = vc; + tty_port_init(&vc->port); + INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); + visual_init(vc, currcons, 1); + if (!*vc->vc_uni_pagedir_loc) + con_set_default_unimap(vc); + vc->vc_screenbuf = kmalloc(vc->vc_screenbuf_size, GFP_KERNEL); + if (!vc->vc_screenbuf) { + kfree(vc); + vc_cons[currcons].d = NULL; + return -ENOMEM; + } + + /* If no drivers have overridden us and the user didn't pass a + boot option, default to displaying the cursor */ + if (global_cursor_default == -1) + global_cursor_default = 1; + + vc_init(vc, vc->vc_rows, vc->vc_cols, 1); + vcs_make_sysfs(currcons); + atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, ¶m); + } + return 0; +} + +static inline int resize_screen(struct vc_data *vc, int width, int height, + int user) +{ + /* Resizes the resolution of the display adapater */ + int err = 0; + + if (vc->vc_mode != KD_GRAPHICS && vc->vc_sw->con_resize) + err = vc->vc_sw->con_resize(vc, width, height, user); + + return err; +} + +/* + * Change # of rows and columns (0 means unchanged/the size of fg_console) + * [this is to be used together with some user program + * like resize that changes the hardware videomode] + */ +#define VC_RESIZE_MAXCOL (32767) +#define VC_RESIZE_MAXROW (32767) + +/** + * vc_do_resize - resizing method for the tty + * @tty: tty being resized + * @real_tty: real tty (different to tty if a pty/tty pair) + * @vc: virtual console private data + * @cols: columns + * @lines: lines + * + * Resize a virtual console, clipping according to the actual constraints. + * If the caller passes a tty structure then update the termios winsize + * information and perform any necessary signal handling. + * + * Caller must hold the console semaphore. Takes the termios rwsem and + * ctrl_lock of the tty IFF a tty is passed. + */ + +static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, + unsigned int cols, unsigned int lines) +{ + unsigned long old_origin, new_origin, new_scr_end, rlth, rrem, err = 0; + unsigned long end; + unsigned int old_rows, old_row_size; + unsigned int new_cols, new_rows, new_row_size, new_screen_size; + unsigned int user; + unsigned short *newscreen; + + WARN_CONSOLE_UNLOCKED(); + + if (!vc) + return -ENXIO; + + user = vc->vc_resize_user; + vc->vc_resize_user = 0; + + if (cols > VC_RESIZE_MAXCOL || lines > VC_RESIZE_MAXROW) + return -EINVAL; + + new_cols = (cols ? cols : vc->vc_cols); + new_rows = (lines ? lines : vc->vc_rows); + new_row_size = new_cols << 1; + new_screen_size = new_row_size * new_rows; + + if (new_cols == vc->vc_cols && new_rows == vc->vc_rows) + return 0; + + newscreen = kmalloc(new_screen_size, GFP_USER); + if (!newscreen) + return -ENOMEM; + + old_rows = vc->vc_rows; + old_row_size = vc->vc_size_row; + + err = resize_screen(vc, new_cols, new_rows, user); + if (err) { + kfree(newscreen); + return err; + } + + vc->vc_rows = new_rows; + vc->vc_cols = new_cols; + vc->vc_size_row = new_row_size; + vc->vc_screenbuf_size = new_screen_size; + + rlth = min(old_row_size, new_row_size); + rrem = new_row_size - rlth; + old_origin = vc->vc_origin; + new_origin = (long) newscreen; + new_scr_end = new_origin + new_screen_size; + + if (vc->vc_y > new_rows) { + if (old_rows - vc->vc_y < new_rows) { + /* + * Cursor near the bottom, copy contents from the + * bottom of buffer + */ + old_origin += (old_rows - new_rows) * old_row_size; + } else { + /* + * Cursor is in no man's land, copy 1/2 screenful + * from the top and bottom of cursor position + */ + old_origin += (vc->vc_y - new_rows/2) * old_row_size; + } + } + + end = old_origin + old_row_size * min(old_rows, new_rows); + + update_attr(vc); + + while (old_origin < end) { + scr_memcpyw((unsigned short *) new_origin, + (unsigned short *) old_origin, rlth); + if (rrem) + scr_memsetw((void *)(new_origin + rlth), + vc->vc_video_erase_char, rrem); + old_origin += old_row_size; + new_origin += new_row_size; + } + if (new_scr_end > new_origin) + scr_memsetw((void *)new_origin, vc->vc_video_erase_char, + new_scr_end - new_origin); + kfree(vc->vc_screenbuf); + vc->vc_screenbuf = newscreen; + vc->vc_screenbuf_size = new_screen_size; + set_origin(vc); + + /* do part of a reset_terminal() */ + vc->vc_top = 0; + vc->vc_bottom = vc->vc_rows; + gotoxy(vc, vc->vc_x, vc->vc_y); + save_cur(vc); + + if (tty) { + /* Rewrite the requested winsize data with the actual + resulting sizes */ + struct winsize ws; + memset(&ws, 0, sizeof(ws)); + ws.ws_row = vc->vc_rows; + ws.ws_col = vc->vc_cols; + ws.ws_ypixel = vc->vc_scan_lines; + tty_do_resize(tty, &ws); + } + + if (CON_IS_VISIBLE(vc)) + update_screen(vc); + vt_event_post(VT_EVENT_RESIZE, vc->vc_num, vc->vc_num); + return err; +} + +/** + * vc_resize - resize a VT + * @vc: virtual console + * @cols: columns + * @rows: rows + * + * Resize a virtual console as seen from the console end of things. We + * use the common vc_do_resize methods to update the structures. The + * caller must hold the console sem to protect console internals and + * vc->port.tty + */ + +int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows) +{ + return vc_do_resize(vc->port.tty, vc, cols, rows); +} + +/** + * vt_resize - resize a VT + * @tty: tty to resize + * @ws: winsize attributes + * + * Resize a virtual terminal. This is called by the tty layer as we + * register our own handler for resizing. The mutual helper does all + * the actual work. + * + * Takes the console sem and the called methods then take the tty + * termios_rwsem and the tty ctrl_lock in that order. + */ +static int vt_resize(struct tty_struct *tty, struct winsize *ws) +{ + struct vc_data *vc = tty->driver_data; + int ret; + + console_lock(); + ret = vc_do_resize(tty, vc, ws->ws_col, ws->ws_row); + console_unlock(); + return ret; +} + +struct vc_data *vc_deallocate(unsigned int currcons) +{ + struct vc_data *vc = NULL; + + WARN_CONSOLE_UNLOCKED(); + + if (vc_cons_allocated(currcons)) { + struct vt_notifier_param param; + + param.vc = vc = vc_cons[currcons].d; + atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, ¶m); + vcs_remove_sysfs(currcons); + vc->vc_sw->con_deinit(vc); + put_pid(vc->vt_pid); + module_put(vc->vc_sw->owner); + kfree(vc->vc_screenbuf); + vc_cons[currcons].d = NULL; + } + return vc; +} + +/* + * VT102 emulator + */ + +#define set_kbd(vc, x) vt_set_kbd_mode_bit((vc)->vc_num, (x)) +#define clr_kbd(vc, x) vt_clr_kbd_mode_bit((vc)->vc_num, (x)) +#define is_kbd(vc, x) vt_get_kbd_mode_bit((vc)->vc_num, (x)) + +#define decarm VC_REPEAT +#define decckm VC_CKMODE +#define kbdapplic VC_APPLIC +#define lnm VC_CRLF + +/* + * this is what the terminal answers to a ESC-Z or csi0c query. + */ +#define VT100ID "\033[?1;2c" +#define VT102ID "\033[?6c" + +unsigned char color_table[] = { 0, 4, 2, 6, 1, 5, 3, 7, + 8,12,10,14, 9,13,11,15 }; + +/* the default colour table, for VGA+ colour systems */ +int default_red[] = {0x00,0xaa,0x00,0xaa,0x00,0xaa,0x00,0xaa, + 0x55,0xff,0x55,0xff,0x55,0xff,0x55,0xff}; +int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa, + 0x55,0x55,0xff,0xff,0x55,0x55,0xff,0xff}; +int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa, + 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff}; + +module_param_array(default_red, int, NULL, S_IRUGO | S_IWUSR); +module_param_array(default_grn, int, NULL, S_IRUGO | S_IWUSR); +module_param_array(default_blu, int, NULL, S_IRUGO | S_IWUSR); + +/* + * gotoxy() must verify all boundaries, because the arguments + * might also be negative. If the given position is out of + * bounds, the cursor is placed at the nearest margin. + */ +static void gotoxy(struct vc_data *vc, int new_x, int new_y) +{ + int min_y, max_y; + + if (new_x < 0) + vc->vc_x = 0; + else { + if (new_x >= vc->vc_cols) + vc->vc_x = vc->vc_cols - 1; + else + vc->vc_x = new_x; + } + + if (vc->vc_decom) { + min_y = vc->vc_top; + max_y = vc->vc_bottom; + } else { + min_y = 0; + max_y = vc->vc_rows; + } + if (new_y < min_y) + vc->vc_y = min_y; + else if (new_y >= max_y) + vc->vc_y = max_y - 1; + else + vc->vc_y = new_y; + vc->vc_pos = vc->vc_origin + vc->vc_y * vc->vc_size_row + (vc->vc_x<<1); + vc->vc_need_wrap = 0; +} + +/* for absolute user moves, when decom is set */ +static void gotoxay(struct vc_data *vc, int new_x, int new_y) +{ + gotoxy(vc, new_x, vc->vc_decom ? (vc->vc_top + new_y) : new_y); +} + +void scrollback(struct vc_data *vc, int lines) +{ + if (!lines) + lines = vc->vc_rows / 2; + scrolldelta(-lines); +} + +void scrollfront(struct vc_data *vc, int lines) +{ + if (!lines) + lines = vc->vc_rows / 2; + scrolldelta(lines); +} + +static void lf(struct vc_data *vc) +{ + /* don't scroll if above bottom of scrolling region, or + * if below scrolling region + */ + if (vc->vc_y + 1 == vc->vc_bottom) + scrup(vc, vc->vc_top, vc->vc_bottom, 1); + else if (vc->vc_y < vc->vc_rows - 1) { + vc->vc_y++; + vc->vc_pos += vc->vc_size_row; + } + vc->vc_need_wrap = 0; + notify_write(vc, '\n'); +} + +static void ri(struct vc_data *vc) +{ + /* don't scroll if below top of scrolling region, or + * if above scrolling region + */ + if (vc->vc_y == vc->vc_top) + scrdown(vc, vc->vc_top, vc->vc_bottom, 1); + else if (vc->vc_y > 0) { + vc->vc_y--; + vc->vc_pos -= vc->vc_size_row; + } + vc->vc_need_wrap = 0; +} + +static inline void cr(struct vc_data *vc) +{ + vc->vc_pos -= vc->vc_x << 1; + vc->vc_need_wrap = vc->vc_x = 0; + notify_write(vc, '\r'); +} + +static inline void bs(struct vc_data *vc) +{ + if (vc->vc_x) { + vc->vc_pos -= 2; + vc->vc_x--; + vc->vc_need_wrap = 0; + notify_write(vc, '\b'); + } +} + +static inline void del(struct vc_data *vc) +{ + /* ignored */ +} + +static void csi_J(struct vc_data *vc, int vpar) +{ + unsigned int count; + unsigned short * start; + + switch (vpar) { + case 0: /* erase from cursor to end of display */ + count = (vc->vc_scr_end - vc->vc_pos) >> 1; + start = (unsigned short *)vc->vc_pos; + break; + case 1: /* erase from start to cursor */ + count = ((vc->vc_pos - vc->vc_origin) >> 1) + 1; + start = (unsigned short *)vc->vc_origin; + break; + case 3: /* erase scroll-back buffer (and whole display) */ + scr_memsetw(vc->vc_screenbuf, vc->vc_video_erase_char, + vc->vc_screenbuf_size >> 1); + set_origin(vc); + if (CON_IS_VISIBLE(vc)) + update_screen(vc); + /* fall through */ + case 2: /* erase whole display */ + count = vc->vc_cols * vc->vc_rows; + start = (unsigned short *)vc->vc_origin; + break; + default: + return; + } + scr_memsetw(start, vc->vc_video_erase_char, 2 * count); + if (DO_UPDATE(vc)) + do_update_region(vc, (unsigned long) start, count); + vc->vc_need_wrap = 0; +} + +static void csi_K(struct vc_data *vc, int vpar) +{ + unsigned int count; + unsigned short * start; + + switch (vpar) { + case 0: /* erase from cursor to end of line */ + count = vc->vc_cols - vc->vc_x; + start = (unsigned short *)vc->vc_pos; + break; + case 1: /* erase from start of line to cursor */ + start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1)); + count = vc->vc_x + 1; + break; + case 2: /* erase whole line */ + start = (unsigned short *)(vc->vc_pos - (vc->vc_x << 1)); + count = vc->vc_cols; + break; + default: + return; + } + scr_memsetw(start, vc->vc_video_erase_char, 2 * count); + vc->vc_need_wrap = 0; + if (DO_UPDATE(vc)) + do_update_region(vc, (unsigned long) start, count); +} + +static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar positions */ +{ /* not vt100? */ + int count; + + if (!vpar) + vpar++; + count = (vpar > vc->vc_cols - vc->vc_x) ? (vc->vc_cols - vc->vc_x) : vpar; + + scr_memsetw((unsigned short *)vc->vc_pos, vc->vc_video_erase_char, 2 * count); + if (DO_UPDATE(vc)) + vc->vc_sw->con_clear(vc, vc->vc_y, vc->vc_x, 1, count); + vc->vc_need_wrap = 0; +} + +static void default_attr(struct vc_data *vc) +{ + vc->vc_intensity = 1; + vc->vc_italic = 0; + vc->vc_underline = 0; + vc->vc_reverse = 0; + vc->vc_blink = 0; + vc->vc_color = vc->vc_def_color; +} + +/* console_lock is held */ +static void csi_m(struct vc_data *vc) +{ + int i; + + for (i = 0; i <= vc->vc_npar; i++) + switch (vc->vc_par[i]) { + case 0: /* all attributes off */ + default_attr(vc); + break; + case 1: + vc->vc_intensity = 2; + break; + case 2: + vc->vc_intensity = 0; + break; + case 3: + vc->vc_italic = 1; + break; + case 4: + vc->vc_underline = 1; + break; + case 5: + vc->vc_blink = 1; + break; + case 7: + vc->vc_reverse = 1; + break; + case 10: /* ANSI X3.64-1979 (SCO-ish?) + * Select primary font, don't display + * control chars if defined, don't set + * bit 8 on output. + */ + vc->vc_translate = set_translate(vc->vc_charset == 0 + ? vc->vc_G0_charset + : vc->vc_G1_charset, vc); + vc->vc_disp_ctrl = 0; + vc->vc_toggle_meta = 0; + break; + case 11: /* ANSI X3.64-1979 (SCO-ish?) + * Select first alternate font, lets + * chars < 32 be displayed as ROM chars. + */ + vc->vc_translate = set_translate(IBMPC_MAP, vc); + vc->vc_disp_ctrl = 1; + vc->vc_toggle_meta = 0; + break; + case 12: /* ANSI X3.64-1979 (SCO-ish?) + * Select second alternate font, toggle + * high bit before displaying as ROM char. + */ + vc->vc_translate = set_translate(IBMPC_MAP, vc); + vc->vc_disp_ctrl = 1; + vc->vc_toggle_meta = 1; + break; + case 21: + case 22: + vc->vc_intensity = 1; + break; + case 23: + vc->vc_italic = 0; + break; + case 24: + vc->vc_underline = 0; + break; + case 25: + vc->vc_blink = 0; + break; + case 27: + vc->vc_reverse = 0; + break; + case 38: + case 48: /* ITU T.416 + * Higher colour modes. + * They break the usual properties of SGR codes + * and thus need to be detected and ignored by + * hand. Strictly speaking, that standard also + * wants : rather than ; as separators, contrary + * to ECMA-48, but no one produces such codes + * and almost no one accepts them. + */ + i++; + if (i > vc->vc_npar) + break; + if (vc->vc_par[i] == 5) /* 256 colours */ + i++; /* ubiquitous */ + else if (vc->vc_par[i] == 2) /* 24 bit colours */ + i += 3; /* extremely rare */ + /* Subcommands 3 (CMY) and 4 (CMYK) are so insane + * that detecting them is not worth the few extra + * bytes of kernel's size. + */ + break; + case 39: + vc->vc_color = (vc->vc_def_color & 0x0f) | (vc->vc_color & 0xf0); + break; + case 49: + vc->vc_color = (vc->vc_def_color & 0xf0) | (vc->vc_color & 0x0f); + break; + default: + if (vc->vc_par[i] >= 30 && vc->vc_par[i] <= 37) + vc->vc_color = color_table[vc->vc_par[i] - 30] + | (vc->vc_color & 0xf0); + else if (vc->vc_par[i] >= 40 && vc->vc_par[i] <= 47) + vc->vc_color = (color_table[vc->vc_par[i] - 40] << 4) + | (vc->vc_color & 0x0f); + break; + } + update_attr(vc); +} + +static void respond_string(const char *p, struct tty_port *port) +{ + while (*p) { + tty_insert_flip_char(port, *p, 0); + p++; + } + tty_schedule_flip(port); +} + +static void cursor_report(struct vc_data *vc, struct tty_struct *tty) +{ + char buf[40]; + + sprintf(buf, "\033[%d;%dR", vc->vc_y + (vc->vc_decom ? vc->vc_top + 1 : 1), vc->vc_x + 1); + respond_string(buf, tty->port); +} + +static inline void status_report(struct tty_struct *tty) +{ + respond_string("\033[0n", tty->port); /* Terminal ok */ +} + +static inline void respond_ID(struct tty_struct *tty) +{ + respond_string(VT102ID, tty->port); +} + +void mouse_report(struct tty_struct *tty, int butt, int mrx, int mry) +{ + char buf[8]; + + sprintf(buf, "\033[M%c%c%c", (char)(' ' + butt), (char)('!' + mrx), + (char)('!' + mry)); + respond_string(buf, tty->port); +} + +/* invoked via ioctl(TIOCLINUX) and through set_selection */ +int mouse_reporting(void) +{ + return vc_cons[fg_console].d->vc_report_mouse; +} + +/* console_lock is held */ +static void set_mode(struct vc_data *vc, int on_off) +{ + int i; + + for (i = 0; i <= vc->vc_npar; i++) + if (vc->vc_ques) { + switch(vc->vc_par[i]) { /* DEC private modes set/reset */ + case 1: /* Cursor keys send ^[Ox/^[[x */ + if (on_off) + set_kbd(vc, decckm); + else + clr_kbd(vc, decckm); + break; + case 3: /* 80/132 mode switch unimplemented */ + vc->vc_deccolm = on_off; +#if 0 + vc_resize(deccolm ? 132 : 80, vc->vc_rows); + /* this alone does not suffice; some user mode + utility has to change the hardware regs */ +#endif + break; + case 5: /* Inverted screen on/off */ + if (vc->vc_decscnm != on_off) { + vc->vc_decscnm = on_off; + invert_screen(vc, 0, vc->vc_screenbuf_size, 0); + update_attr(vc); + } + break; + case 6: /* Origin relative/absolute */ + vc->vc_decom = on_off; + gotoxay(vc, 0, 0); + break; + case 7: /* Autowrap on/off */ + vc->vc_decawm = on_off; + break; + case 8: /* Autorepeat on/off */ + if (on_off) + set_kbd(vc, decarm); + else + clr_kbd(vc, decarm); + break; + case 9: + vc->vc_report_mouse = on_off ? 1 : 0; + break; + case 25: /* Cursor on/off */ + vc->vc_deccm = on_off; + break; + case 1000: + vc->vc_report_mouse = on_off ? 2 : 0; + break; + } + } else { + switch(vc->vc_par[i]) { /* ANSI modes set/reset */ + case 3: /* Monitor (display ctrls) */ + vc->vc_disp_ctrl = on_off; + break; + case 4: /* Insert Mode on/off */ + vc->vc_decim = on_off; + break; + case 20: /* Lf, Enter == CrLf/Lf */ + if (on_off) + set_kbd(vc, lnm); + else + clr_kbd(vc, lnm); + break; + } + } +} + +/* console_lock is held */ +static void setterm_command(struct vc_data *vc) +{ + switch(vc->vc_par[0]) { + case 1: /* set color for underline mode */ + if (vc->vc_can_do_color && + vc->vc_par[1] < 16) { + vc->vc_ulcolor = color_table[vc->vc_par[1]]; + if (vc->vc_underline) + update_attr(vc); + } + break; + case 2: /* set color for half intensity mode */ + if (vc->vc_can_do_color && + vc->vc_par[1] < 16) { + vc->vc_halfcolor = color_table[vc->vc_par[1]]; + if (vc->vc_intensity == 0) + update_attr(vc); + } + break; + case 8: /* store colors as defaults */ + vc->vc_def_color = vc->vc_attr; + if (vc->vc_hi_font_mask == 0x100) + vc->vc_def_color >>= 1; + default_attr(vc); + update_attr(vc); + break; + case 9: /* set blanking interval */ + blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60; + poke_blanked_console(); + break; + case 10: /* set bell frequency in Hz */ + if (vc->vc_npar >= 1) + vc->vc_bell_pitch = vc->vc_par[1]; + else + vc->vc_bell_pitch = DEFAULT_BELL_PITCH; + break; + case 11: /* set bell duration in msec */ + if (vc->vc_npar >= 1) + vc->vc_bell_duration = (vc->vc_par[1] < 2000) ? + vc->vc_par[1] * HZ / 1000 : 0; + else + vc->vc_bell_duration = DEFAULT_BELL_DURATION; + break; + case 12: /* bring specified console to the front */ + if (vc->vc_par[1] >= 1 && vc_cons_allocated(vc->vc_par[1] - 1)) + set_console(vc->vc_par[1] - 1); + break; + case 13: /* unblank the screen */ + poke_blanked_console(); + break; + case 14: /* set vesa powerdown interval */ + vesa_off_interval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ; + break; + case 15: /* activate the previous console */ + set_console(last_console); + break; + } +} + +/* console_lock is held */ +static void csi_at(struct vc_data *vc, unsigned int nr) +{ + if (nr > vc->vc_cols - vc->vc_x) + nr = vc->vc_cols - vc->vc_x; + else if (!nr) + nr = 1; + insert_char(vc, nr); +} + +/* console_lock is held */ +static void csi_L(struct vc_data *vc, unsigned int nr) +{ + if (nr > vc->vc_rows - vc->vc_y) + nr = vc->vc_rows - vc->vc_y; + else if (!nr) + nr = 1; + scrdown(vc, vc->vc_y, vc->vc_bottom, nr); + vc->vc_need_wrap = 0; +} + +/* console_lock is held */ +static void csi_P(struct vc_data *vc, unsigned int nr) +{ + if (nr > vc->vc_cols - vc->vc_x) + nr = vc->vc_cols - vc->vc_x; + else if (!nr) + nr = 1; + delete_char(vc, nr); +} + +/* console_lock is held */ +static void csi_M(struct vc_data *vc, unsigned int nr) +{ + if (nr > vc->vc_rows - vc->vc_y) + nr = vc->vc_rows - vc->vc_y; + else if (!nr) + nr=1; + scrup(vc, vc->vc_y, vc->vc_bottom, nr); + vc->vc_need_wrap = 0; +} + +/* console_lock is held (except via vc_init->reset_terminal */ +static void save_cur(struct vc_data *vc) +{ + vc->vc_saved_x = vc->vc_x; + vc->vc_saved_y = vc->vc_y; + vc->vc_s_intensity = vc->vc_intensity; + vc->vc_s_italic = vc->vc_italic; + vc->vc_s_underline = vc->vc_underline; + vc->vc_s_blink = vc->vc_blink; + vc->vc_s_reverse = vc->vc_reverse; + vc->vc_s_charset = vc->vc_charset; + vc->vc_s_color = vc->vc_color; + vc->vc_saved_G0 = vc->vc_G0_charset; + vc->vc_saved_G1 = vc->vc_G1_charset; +} + +/* console_lock is held */ +static void restore_cur(struct vc_data *vc) +{ + gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y); + vc->vc_intensity = vc->vc_s_intensity; + vc->vc_italic = vc->vc_s_italic; + vc->vc_underline = vc->vc_s_underline; + vc->vc_blink = vc->vc_s_blink; + vc->vc_reverse = vc->vc_s_reverse; + vc->vc_charset = vc->vc_s_charset; + vc->vc_color = vc->vc_s_color; + vc->vc_G0_charset = vc->vc_saved_G0; + vc->vc_G1_charset = vc->vc_saved_G1; + vc->vc_translate = set_translate(vc->vc_charset ? vc->vc_G1_charset : vc->vc_G0_charset, vc); + update_attr(vc); + vc->vc_need_wrap = 0; +} + +enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey, + EShash, ESsetG0, ESsetG1, ESpercent, ESignore, ESnonstd, + ESpalette, ESosc }; + +/* console_lock is held (except via vc_init()) */ +static void reset_terminal(struct vc_data *vc, int do_clear) +{ + vc->vc_top = 0; + vc->vc_bottom = vc->vc_rows; + vc->vc_state = ESnormal; + vc->vc_ques = 0; + vc->vc_translate = set_translate(LAT1_MAP, vc); + vc->vc_G0_charset = LAT1_MAP; + vc->vc_G1_charset = GRAF_MAP; + vc->vc_charset = 0; + vc->vc_need_wrap = 0; + vc->vc_report_mouse = 0; + vc->vc_utf = default_utf8; + vc->vc_utf_count = 0; + + vc->vc_disp_ctrl = 0; + vc->vc_toggle_meta = 0; + + vc->vc_decscnm = 0; + vc->vc_decom = 0; + vc->vc_decawm = 1; + vc->vc_deccm = global_cursor_default; + vc->vc_decim = 0; + + vt_reset_keyboard(vc->vc_num); + + vc->vc_cursor_type = cur_default; + vc->vc_complement_mask = vc->vc_s_complement_mask; + + default_attr(vc); + update_attr(vc); + + vc->vc_tab_stop[0] = 0x01010100; + vc->vc_tab_stop[1] = + vc->vc_tab_stop[2] = + vc->vc_tab_stop[3] = + vc->vc_tab_stop[4] = + vc->vc_tab_stop[5] = + vc->vc_tab_stop[6] = + vc->vc_tab_stop[7] = 0x01010101; + + vc->vc_bell_pitch = DEFAULT_BELL_PITCH; + vc->vc_bell_duration = DEFAULT_BELL_DURATION; + + gotoxy(vc, 0, 0); + save_cur(vc); + if (do_clear) + csi_J(vc, 2); +} + +/* console_lock is held */ +static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c) +{ + /* + * Control characters can be used in the _middle_ + * of an escape sequence. + */ + if (vc->vc_state == ESosc && c>=8 && c<=13) /* ... except for OSC */ + return; + switch (c) { + case 0: + return; + case 7: + if (vc->vc_state == ESosc) + vc->vc_state = ESnormal; + else if (vc->vc_bell_duration) + kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration); + return; + case 8: + bs(vc); + return; + case 9: + vc->vc_pos -= (vc->vc_x << 1); + while (vc->vc_x < vc->vc_cols - 1) { + vc->vc_x++; + if (vc->vc_tab_stop[vc->vc_x >> 5] & (1 << (vc->vc_x & 31))) + break; + } + vc->vc_pos += (vc->vc_x << 1); + notify_write(vc, '\t'); + return; + case 10: case 11: case 12: + lf(vc); + if (!is_kbd(vc, lnm)) + return; + case 13: + cr(vc); + return; + case 14: + vc->vc_charset = 1; + vc->vc_translate = set_translate(vc->vc_G1_charset, vc); + vc->vc_disp_ctrl = 1; + return; + case 15: + vc->vc_charset = 0; + vc->vc_translate = set_translate(vc->vc_G0_charset, vc); + vc->vc_disp_ctrl = 0; + return; + case 24: case 26: + vc->vc_state = ESnormal; + return; + case 27: + vc->vc_state = ESesc; + return; + case 127: + del(vc); + return; + case 128+27: + vc->vc_state = ESsquare; + return; + } + switch(vc->vc_state) { + case ESesc: + vc->vc_state = ESnormal; + switch (c) { + case '[': + vc->vc_state = ESsquare; + return; + case ']': + vc->vc_state = ESnonstd; + return; + case '%': + vc->vc_state = ESpercent; + return; + case 'E': + cr(vc); + lf(vc); + return; + case 'M': + ri(vc); + return; + case 'D': + lf(vc); + return; + case 'H': + vc->vc_tab_stop[vc->vc_x >> 5] |= (1 << (vc->vc_x & 31)); + return; + case 'Z': + respond_ID(tty); + return; + case '7': + save_cur(vc); + return; + case '8': + restore_cur(vc); + return; + case '(': + vc->vc_state = ESsetG0; + return; + case ')': + vc->vc_state = ESsetG1; + return; + case '#': + vc->vc_state = EShash; + return; + case 'c': + reset_terminal(vc, 1); + return; + case '>': /* Numeric keypad */ + clr_kbd(vc, kbdapplic); + return; + case '=': /* Appl. keypad */ + set_kbd(vc, kbdapplic); + return; + } + return; + case ESnonstd: + if (c=='P') { /* palette escape sequence */ + for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++) + vc->vc_par[vc->vc_npar] = 0; + vc->vc_npar = 0; + vc->vc_state = ESpalette; + return; + } else if (c=='R') { /* reset palette */ + reset_palette(vc); + vc->vc_state = ESnormal; + } else if (c>='0' && c<='9') + vc->vc_state = ESosc; + else + vc->vc_state = ESnormal; + return; + case ESpalette: + if (isxdigit(c)) { + vc->vc_par[vc->vc_npar++] = hex_to_bin(c); + if (vc->vc_npar == 7) { + int i = vc->vc_par[0] * 3, j = 1; + vc->vc_palette[i] = 16 * vc->vc_par[j++]; + vc->vc_palette[i++] += vc->vc_par[j++]; + vc->vc_palette[i] = 16 * vc->vc_par[j++]; + vc->vc_palette[i++] += vc->vc_par[j++]; + vc->vc_palette[i] = 16 * vc->vc_par[j++]; + vc->vc_palette[i] += vc->vc_par[j]; + set_palette(vc); + vc->vc_state = ESnormal; + } + } else + vc->vc_state = ESnormal; + return; + case ESsquare: + for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++) + vc->vc_par[vc->vc_npar] = 0; + vc->vc_npar = 0; + vc->vc_state = ESgetpars; + if (c == '[') { /* Function key */ + vc->vc_state=ESfunckey; + return; + } + vc->vc_ques = (c == '?'); + if (vc->vc_ques) + return; + case ESgetpars: + if (c == ';' && vc->vc_npar < NPAR - 1) { + vc->vc_npar++; + return; + } else if (c>='0' && c<='9') { + vc->vc_par[vc->vc_npar] *= 10; + vc->vc_par[vc->vc_npar] += c - '0'; + return; + } + vc->vc_state = ESnormal; + switch(c) { + case 'h': + set_mode(vc, 1); + return; + case 'l': + set_mode(vc, 0); + return; + case 'c': + if (vc->vc_ques) { + if (vc->vc_par[0]) + vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16); + else + vc->vc_cursor_type = cur_default; + return; + } + break; + case 'm': + if (vc->vc_ques) { + clear_selection(); + if (vc->vc_par[0]) + vc->vc_complement_mask = vc->vc_par[0] << 8 | vc->vc_par[1]; + else + vc->vc_complement_mask = vc->vc_s_complement_mask; + return; + } + break; + case 'n': + if (!vc->vc_ques) { + if (vc->vc_par[0] == 5) + status_report(tty); + else if (vc->vc_par[0] == 6) + cursor_report(vc, tty); + } + return; + } + if (vc->vc_ques) { + vc->vc_ques = 0; + return; + } + switch(c) { + case 'G': case '`': + if (vc->vc_par[0]) + vc->vc_par[0]--; + gotoxy(vc, vc->vc_par[0], vc->vc_y); + return; + case 'A': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->vc_x, vc->vc_y - vc->vc_par[0]); + return; + case 'B': case 'e': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->vc_x, vc->vc_y + vc->vc_par[0]); + return; + case 'C': case 'a': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->vc_x + vc->vc_par[0], vc->vc_y); + return; + case 'D': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, vc->vc_x - vc->vc_par[0], vc->vc_y); + return; + case 'E': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, 0, vc->vc_y + vc->vc_par[0]); + return; + case 'F': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + gotoxy(vc, 0, vc->vc_y - vc->vc_par[0]); + return; + case 'd': + if (vc->vc_par[0]) + vc->vc_par[0]--; + gotoxay(vc, vc->vc_x ,vc->vc_par[0]); + return; + case 'H': case 'f': + if (vc->vc_par[0]) + vc->vc_par[0]--; + if (vc->vc_par[1]) + vc->vc_par[1]--; + gotoxay(vc, vc->vc_par[1], vc->vc_par[0]); + return; + case 'J': + csi_J(vc, vc->vc_par[0]); + return; + case 'K': + csi_K(vc, vc->vc_par[0]); + return; + case 'L': + csi_L(vc, vc->vc_par[0]); + return; + case 'M': + csi_M(vc, vc->vc_par[0]); + return; + case 'P': + csi_P(vc, vc->vc_par[0]); + return; + case 'c': + if (!vc->vc_par[0]) + respond_ID(tty); + return; + case 'g': + if (!vc->vc_par[0]) + vc->vc_tab_stop[vc->vc_x >> 5] &= ~(1 << (vc->vc_x & 31)); + else if (vc->vc_par[0] == 3) { + vc->vc_tab_stop[0] = + vc->vc_tab_stop[1] = + vc->vc_tab_stop[2] = + vc->vc_tab_stop[3] = + vc->vc_tab_stop[4] = + vc->vc_tab_stop[5] = + vc->vc_tab_stop[6] = + vc->vc_tab_stop[7] = 0; + } + return; + case 'm': + csi_m(vc); + return; + case 'q': /* DECLL - but only 3 leds */ + /* map 0,1,2,3 to 0,1,2,4 */ + if (vc->vc_par[0] < 4) + vt_set_led_state(vc->vc_num, + (vc->vc_par[0] < 3) ? vc->vc_par[0] : 4); + return; + case 'r': + if (!vc->vc_par[0]) + vc->vc_par[0]++; + if (!vc->vc_par[1]) + vc->vc_par[1] = vc->vc_rows; + /* Minimum allowed region is 2 lines */ + if (vc->vc_par[0] < vc->vc_par[1] && + vc->vc_par[1] <= vc->vc_rows) { + vc->vc_top = vc->vc_par[0] - 1; + vc->vc_bottom = vc->vc_par[1]; + gotoxay(vc, 0, 0); + } + return; + case 's': + save_cur(vc); + return; + case 'u': + restore_cur(vc); + return; + case 'X': + csi_X(vc, vc->vc_par[0]); + return; + case '@': + csi_at(vc, vc->vc_par[0]); + return; + case ']': /* setterm functions */ + setterm_command(vc); + return; + } + return; + case ESpercent: + vc->vc_state = ESnormal; + switch (c) { + case '@': /* defined in ISO 2022 */ + vc->vc_utf = 0; + return; + case 'G': /* prelim official escape code */ + case '8': /* retained for compatibility */ + vc->vc_utf = 1; + return; + } + return; + case ESfunckey: + vc->vc_state = ESnormal; + return; + case EShash: + vc->vc_state = ESnormal; + if (c == '8') { + /* DEC screen alignment test. kludge :-) */ + vc->vc_video_erase_char = + (vc->vc_video_erase_char & 0xff00) | 'E'; + csi_J(vc, 2); + vc->vc_video_erase_char = + (vc->vc_video_erase_char & 0xff00) | ' '; + do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2); + } + return; + case ESsetG0: + if (c == '0') + vc->vc_G0_charset = GRAF_MAP; + else if (c == 'B') + vc->vc_G0_charset = LAT1_MAP; + else if (c == 'U') + vc->vc_G0_charset = IBMPC_MAP; + else if (c == 'K') + vc->vc_G0_charset = USER_MAP; + if (vc->vc_charset == 0) + vc->vc_translate = set_translate(vc->vc_G0_charset, vc); + vc->vc_state = ESnormal; + return; + case ESsetG1: + if (c == '0') + vc->vc_G1_charset = GRAF_MAP; + else if (c == 'B') + vc->vc_G1_charset = LAT1_MAP; + else if (c == 'U') + vc->vc_G1_charset = IBMPC_MAP; + else if (c == 'K') + vc->vc_G1_charset = USER_MAP; + if (vc->vc_charset == 1) + vc->vc_translate = set_translate(vc->vc_G1_charset, vc); + vc->vc_state = ESnormal; + return; + case ESosc: + return; + default: + vc->vc_state = ESnormal; + } +} + +/* is_double_width() is based on the wcwidth() implementation by + * Markus Kuhn -- 2007-05-26 (Unicode 5.0) + * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c + */ +struct interval { + uint32_t first; + uint32_t last; +}; + +static int bisearch(uint32_t ucs, const struct interval *table, int max) +{ + int min = 0; + int mid; + + if (ucs < table[0].first || ucs > table[max].last) + return 0; + while (max >= min) { + mid = (min + max) / 2; + if (ucs > table[mid].last) + min = mid + 1; + else if (ucs < table[mid].first) + max = mid - 1; + else + return 1; + } + return 0; +} + +static int is_double_width(uint32_t ucs) +{ + static const struct interval double_width[] = { + { 0x1100, 0x115F }, { 0x2329, 0x232A }, { 0x2E80, 0x303E }, + { 0x3040, 0xA4CF }, { 0xAC00, 0xD7A3 }, { 0xF900, 0xFAFF }, + { 0xFE10, 0xFE19 }, { 0xFE30, 0xFE6F }, { 0xFF00, 0xFF60 }, + { 0xFFE0, 0xFFE6 }, { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD } + }; + return bisearch(ucs, double_width, ARRAY_SIZE(double_width) - 1); +} + +/* acquires console_lock */ +static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count) +{ +#ifdef VT_BUF_VRAM_ONLY +#define FLUSH do { } while(0); +#else +#define FLUSH if (draw_x >= 0) { \ + vc->vc_sw->con_putcs(vc, (u16 *)draw_from, (u16 *)draw_to - (u16 *)draw_from, vc->vc_y, draw_x); \ + draw_x = -1; \ + } +#endif + + int c, tc, ok, n = 0, draw_x = -1; + unsigned int currcons; + unsigned long draw_from = 0, draw_to = 0; + struct vc_data *vc; + unsigned char vc_attr; + struct vt_notifier_param param; + uint8_t rescan; + uint8_t inverse; + uint8_t width; + u16 himask, charmask; + + if (in_interrupt()) + return count; + + might_sleep(); + + console_lock(); + vc = tty->driver_data; + if (vc == NULL) { + printk(KERN_ERR "vt: argh, driver_data is NULL !\n"); + console_unlock(); + return 0; + } + + currcons = vc->vc_num; + if (!vc_cons_allocated(currcons)) { + /* could this happen? */ + pr_warn_once("con_write: tty %d not allocated\n", currcons+1); + console_unlock(); + return 0; + } + + himask = vc->vc_hi_font_mask; + charmask = himask ? 0x1ff : 0xff; + + /* undraw cursor first */ + if (IS_FG(vc)) + hide_cursor(vc); + + param.vc = vc; + + while (!tty->stopped && count) { + int orig = *buf; + c = orig; + buf++; + n++; + count--; + rescan = 0; + inverse = 0; + width = 1; + + /* Do no translation at all in control states */ + if (vc->vc_state != ESnormal) { + tc = c; + } else if (vc->vc_utf && !vc->vc_disp_ctrl) { + /* Combine UTF-8 into Unicode in vc_utf_char. + * vc_utf_count is the number of continuation bytes still + * expected to arrive. + * vc_npar is the number of continuation bytes arrived so + * far + */ +rescan_last_byte: + if ((c & 0xc0) == 0x80) { + /* Continuation byte received */ + static const uint32_t utf8_length_changes[] = { 0x0000007f, 0x000007ff, 0x0000ffff, 0x001fffff, 0x03ffffff, 0x7fffffff }; + if (vc->vc_utf_count) { + vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f); + vc->vc_npar++; + if (--vc->vc_utf_count) { + /* Still need some bytes */ + continue; + } + /* Got a whole character */ + c = vc->vc_utf_char; + /* Reject overlong sequences */ + if (c <= utf8_length_changes[vc->vc_npar - 1] || + c > utf8_length_changes[vc->vc_npar]) + c = 0xfffd; + } else { + /* Unexpected continuation byte */ + vc->vc_utf_count = 0; + c = 0xfffd; + } + } else { + /* Single ASCII byte or first byte of a sequence received */ + if (vc->vc_utf_count) { + /* Continuation byte expected */ + rescan = 1; + vc->vc_utf_count = 0; + c = 0xfffd; + } else if (c > 0x7f) { + /* First byte of a multibyte sequence received */ + vc->vc_npar = 0; + if ((c & 0xe0) == 0xc0) { + vc->vc_utf_count = 1; + vc->vc_utf_char = (c & 0x1f); + } else if ((c & 0xf0) == 0xe0) { + vc->vc_utf_count = 2; + vc->vc_utf_char = (c & 0x0f); + } else if ((c & 0xf8) == 0xf0) { + vc->vc_utf_count = 3; + vc->vc_utf_char = (c & 0x07); + } else if ((c & 0xfc) == 0xf8) { + vc->vc_utf_count = 4; + vc->vc_utf_char = (c & 0x03); + } else if ((c & 0xfe) == 0xfc) { + vc->vc_utf_count = 5; + vc->vc_utf_char = (c & 0x01); + } else { + /* 254 and 255 are invalid */ + c = 0xfffd; + } + if (vc->vc_utf_count) { + /* Still need some bytes */ + continue; + } + } + /* Nothing to do if an ASCII byte was received */ + } + /* End of UTF-8 decoding. */ + /* c is the received character, or U+FFFD for invalid sequences. */ + /* Replace invalid Unicode code points with U+FFFD too */ + if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) + c = 0xfffd; + tc = c; + } else { /* no utf or alternate charset mode */ + tc = vc_translate(vc, c); + } + + param.c = tc; + if (atomic_notifier_call_chain(&vt_notifier_list, VT_PREWRITE, + ¶m) == NOTIFY_STOP) + continue; + + /* If the original code was a control character we + * only allow a glyph to be displayed if the code is + * not normally used (such as for cursor movement) or + * if the disp_ctrl mode has been explicitly enabled. + * Certain characters (as given by the CTRL_ALWAYS + * bitmap) are always displayed as control characters, + * as the console would be pretty useless without + * them; to display an arbitrary font position use the + * direct-to-font zone in UTF-8 mode. + */ + ok = tc && (c >= 32 || + !(vc->vc_disp_ctrl ? (CTRL_ALWAYS >> c) & 1 : + vc->vc_utf || ((CTRL_ACTION >> c) & 1))) + && (c != 127 || vc->vc_disp_ctrl) + && (c != 128+27); + + if (vc->vc_state == ESnormal && ok) { + if (vc->vc_utf && !vc->vc_disp_ctrl) { + if (is_double_width(c)) + width = 2; + } + /* Now try to find out how to display it */ + tc = conv_uni_to_pc(vc, tc); + if (tc & ~charmask) { + if (tc == -1 || tc == -2) { + continue; /* nothing to display */ + } + /* Glyph not found */ + if ((!(vc->vc_utf && !vc->vc_disp_ctrl) || c < 128) && !(c & ~charmask)) { + /* In legacy mode use the glyph we get by a 1:1 mapping. + This would make absolutely no sense with Unicode in mind, + but do this for ASCII characters since a font may lack + Unicode mapping info and we don't want to end up with + having question marks only. */ + tc = c; + } else { + /* Display U+FFFD. If it's not found, display an inverse question mark. */ + tc = conv_uni_to_pc(vc, 0xfffd); + if (tc < 0) { + inverse = 1; + tc = conv_uni_to_pc(vc, '?'); + if (tc < 0) tc = '?'; + } + } + } + + if (!inverse) { + vc_attr = vc->vc_attr; + } else { + /* invert vc_attr */ + if (!vc->vc_can_do_color) { + vc_attr = (vc->vc_attr) ^ 0x08; + } else if (vc->vc_hi_font_mask == 0x100) { + vc_attr = ((vc->vc_attr) & 0x11) | (((vc->vc_attr) & 0xe0) >> 4) | (((vc->vc_attr) & 0x0e) << 4); + } else { + vc_attr = ((vc->vc_attr) & 0x88) | (((vc->vc_attr) & 0x70) >> 4) | (((vc->vc_attr) & 0x07) << 4); + } + FLUSH + } + + while (1) { + if (vc->vc_need_wrap || vc->vc_decim) + FLUSH + if (vc->vc_need_wrap) { + cr(vc); + lf(vc); + } + if (vc->vc_decim) + insert_char(vc, 1); + scr_writew(himask ? + ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) : + (vc_attr << 8) + tc, + (u16 *) vc->vc_pos); + if (DO_UPDATE(vc) && draw_x < 0) { + draw_x = vc->vc_x; + draw_from = vc->vc_pos; + } + if (vc->vc_x == vc->vc_cols - 1) { + vc->vc_need_wrap = vc->vc_decawm; + draw_to = vc->vc_pos + 2; + } else { + vc->vc_x++; + draw_to = (vc->vc_pos += 2); + } + + if (!--width) break; + + tc = conv_uni_to_pc(vc, ' '); /* A space is printed in the second column */ + if (tc < 0) tc = ' '; + } + notify_write(vc, c); + + if (inverse) { + FLUSH + } + + if (rescan) { + rescan = 0; + inverse = 0; + width = 1; + c = orig; + goto rescan_last_byte; + } + continue; + } + FLUSH + do_con_trol(tty, vc, orig); + } + FLUSH + console_conditional_schedule(); + console_unlock(); + notify_update(vc); + return n; +#undef FLUSH +} + +/* + * This is the console switching callback. + * + * Doing console switching in a process context allows + * us to do the switches asynchronously (needed when we want + * to switch due to a keyboard interrupt). Synchronization + * with other console code and prevention of re-entrancy is + * ensured with console_lock. + */ +static void console_callback(struct work_struct *ignored) +{ + console_lock(); + + if (want_console >= 0) { + if (want_console != fg_console && + vc_cons_allocated(want_console)) { + hide_cursor(vc_cons[fg_console].d); + change_console(vc_cons[want_console].d); + /* we only changed when the console had already + been allocated - a new console is not created + in an interrupt routine */ + } + want_console = -1; + } + if (do_poke_blanked_console) { /* do not unblank for a LED change */ + do_poke_blanked_console = 0; + poke_blanked_console(); + } + if (scrollback_delta) { + struct vc_data *vc = vc_cons[fg_console].d; + clear_selection(); + if (vc->vc_mode == KD_TEXT) + vc->vc_sw->con_scrolldelta(vc, scrollback_delta); + scrollback_delta = 0; + } + if (blank_timer_expired) { + do_blank_screen(0); + blank_timer_expired = 0; + } + notify_update(vc_cons[fg_console].d); + + console_unlock(); +} + +int set_console(int nr) +{ + struct vc_data *vc = vc_cons[fg_console].d; + + if (!vc_cons_allocated(nr) || vt_dont_switch || + (vc->vt_mode.mode == VT_AUTO && vc->vc_mode == KD_GRAPHICS)) { + + /* + * Console switch will fail in console_callback() or + * change_console() so there is no point scheduling + * the callback + * + * Existing set_console() users don't check the return + * value so this shouldn't break anything + */ + return -EINVAL; + } + + want_console = nr; + schedule_console_callback(); + + return 0; +} + +struct tty_driver *console_driver; + +#ifdef CONFIG_VT_CONSOLE + +/** + * vt_kmsg_redirect() - Sets/gets the kernel message console + * @new: The new virtual terminal number or -1 if the console should stay + * unchanged + * + * By default, the kernel messages are always printed on the current virtual + * console. However, the user may modify that default with the + * TIOCL_SETKMSGREDIRECT ioctl call. + * + * This function sets the kernel message console to be @new. It returns the old + * virtual console number. The virtual terminal number 0 (both as parameter and + * return value) means no redirection (i.e. always printed on the currently + * active console). + * + * The parameter -1 means that only the current console is returned, but the + * value is not modified. You may use the macro vt_get_kmsg_redirect() in that + * case to make the code more understandable. + * + * When the kernel is compiled without CONFIG_VT_CONSOLE, this function ignores + * the parameter and always returns 0. + */ +int vt_kmsg_redirect(int new) +{ + static int kmsg_con; + + if (new != -1) + return xchg(&kmsg_con, new); + else + return kmsg_con; +} + +/* + * Console on virtual terminal + * + * The console must be locked when we get here. + */ + +static void vt_console_print(struct console *co, const char *b, unsigned count) +{ + struct vc_data *vc = vc_cons[fg_console].d; + unsigned char c; + static DEFINE_SPINLOCK(printing_lock); + const ushort *start; + ushort cnt = 0; + ushort myx; + int kmsg_console; + + /* console busy or not yet initialized */ + if (!printable) + return; + if (!spin_trylock(&printing_lock)) + return; + + kmsg_console = vt_get_kmsg_redirect(); + if (kmsg_console && vc_cons_allocated(kmsg_console - 1)) + vc = vc_cons[kmsg_console - 1].d; + + /* read `x' only after setting currcons properly (otherwise + the `x' macro will read the x of the foreground console). */ + myx = vc->vc_x; + + if (!vc_cons_allocated(fg_console)) { + /* impossible */ + /* printk("vt_console_print: tty %d not allocated ??\n", currcons+1); */ + goto quit; + } + + if (vc->vc_mode != KD_TEXT && !vt_force_oops_output(vc)) + goto quit; + + /* undraw cursor first */ + if (IS_FG(vc)) + hide_cursor(vc); + + start = (ushort *)vc->vc_pos; + + /* Contrived structure to try to emulate original need_wrap behaviour + * Problems caused when we have need_wrap set on '\n' character */ + while (count--) { + c = *b++; + if (c == 10 || c == 13 || c == 8 || vc->vc_need_wrap) { + if (cnt > 0) { + if (CON_IS_VISIBLE(vc)) + vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x); + vc->vc_x += cnt; + if (vc->vc_need_wrap) + vc->vc_x--; + cnt = 0; + } + if (c == 8) { /* backspace */ + bs(vc); + start = (ushort *)vc->vc_pos; + myx = vc->vc_x; + continue; + } + if (c != 13) + lf(vc); + cr(vc); + start = (ushort *)vc->vc_pos; + myx = vc->vc_x; + if (c == 10 || c == 13) + continue; + } + scr_writew((vc->vc_attr << 8) + c, (unsigned short *)vc->vc_pos); + notify_write(vc, c); + cnt++; + if (myx == vc->vc_cols - 1) { + vc->vc_need_wrap = 1; + continue; + } + vc->vc_pos += 2; + myx++; + } + if (cnt > 0) { + if (CON_IS_VISIBLE(vc)) + vc->vc_sw->con_putcs(vc, start, cnt, vc->vc_y, vc->vc_x); + vc->vc_x += cnt; + if (vc->vc_x == vc->vc_cols) { + vc->vc_x--; + vc->vc_need_wrap = 1; + } + } + set_cursor(vc); + notify_update(vc); + +quit: + spin_unlock(&printing_lock); +} + +static struct tty_driver *vt_console_device(struct console *c, int *index) +{ + *index = c->index ? c->index-1 : fg_console; + return console_driver; +} + +static struct console vt_console_driver = { + .name = "tty", + .write = vt_console_print, + .device = vt_console_device, + .unblank = unblank_screen, + .flags = CON_PRINTBUFFER, + .index = -1, +}; +#endif + +/* + * Handling of Linux-specific VC ioctls + */ + +/* + * Generally a bit racy with respect to console_lock();. + * + * There are some functions which don't need it. + * + * There are some functions which can sleep for arbitrary periods + * (paste_selection) but we don't need the lock there anyway. + * + * set_selection has locking, and definitely needs it + */ + +int tioclinux(struct tty_struct *tty, unsigned long arg) +{ + char type, data; + char __user *p = (char __user *)arg; + int lines; + int ret; + + if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN)) + return -EPERM; + if (get_user(type, p)) + return -EFAULT; + ret = 0; + + switch (type) + { + case TIOCL_SETSEL: + console_lock(); + ret = set_selection((struct tiocl_selection __user *)(p+1), tty); + console_unlock(); + break; + case TIOCL_PASTESEL: + ret = paste_selection(tty); + break; + case TIOCL_UNBLANKSCREEN: + console_lock(); + unblank_screen(); + console_unlock(); + break; + case TIOCL_SELLOADLUT: + console_lock(); + ret = sel_loadlut(p); + console_unlock(); + break; + case TIOCL_GETSHIFTSTATE: + + /* + * Make it possible to react to Shift+Mousebutton. + * Note that 'shift_state' is an undocumented + * kernel-internal variable; programs not closely + * related to the kernel should not use this. + */ + data = vt_get_shift_state(); + ret = __put_user(data, p); + break; + case TIOCL_GETMOUSEREPORTING: + console_lock(); /* May be overkill */ + data = mouse_reporting(); + console_unlock(); + ret = __put_user(data, p); + break; + case TIOCL_SETVESABLANK: + console_lock(); + ret = set_vesa_blanking(p); + console_unlock(); + break; + case TIOCL_GETKMSGREDIRECT: + data = vt_get_kmsg_redirect(); + ret = __put_user(data, p); + break; + case TIOCL_SETKMSGREDIRECT: + if (!capable(CAP_SYS_ADMIN)) { + ret = -EPERM; + } else { + if (get_user(data, p+1)) + ret = -EFAULT; + else + vt_kmsg_redirect(data); + } + break; + case TIOCL_GETFGCONSOLE: + /* No locking needed as this is a transiently + correct return anyway if the caller hasn't + disabled switching */ + ret = fg_console; + break; + case TIOCL_SCROLLCONSOLE: + if (get_user(lines, (s32 __user *)(p+4))) { + ret = -EFAULT; + } else { + /* Need the console lock here. Note that lots + of other calls need fixing before the lock + is actually useful ! */ + console_lock(); + scrollfront(vc_cons[fg_console].d, lines); + console_unlock(); + ret = 0; + } + break; + case TIOCL_BLANKSCREEN: /* until explicitly unblanked, not only poked */ + console_lock(); + ignore_poke = 1; + do_blank_screen(0); + console_unlock(); + break; + case TIOCL_BLANKEDSCREEN: + ret = console_blanked; + break; + default: + ret = -EINVAL; + break; + } + return ret; +} + +/* + * /dev/ttyN handling + */ + +static int con_write(struct tty_struct *tty, const unsigned char *buf, int count) +{ + int retval; + + retval = do_con_write(tty, buf, count); + con_flush_chars(tty); + + return retval; +} + +static int con_put_char(struct tty_struct *tty, unsigned char ch) +{ + if (in_interrupt()) + return 0; /* n_r3964 calls put_char() from interrupt context */ + return do_con_write(tty, &ch, 1); +} + +static int con_write_room(struct tty_struct *tty) +{ + if (tty->stopped) + return 0; + return 32768; /* No limit, really; we're not buffering */ +} + +static int con_chars_in_buffer(struct tty_struct *tty) +{ + return 0; /* we're not buffering */ +} + +/* + * con_throttle and con_unthrottle are only used for + * paste_selection(), which has to stuff in a large number of + * characters... + */ +static void con_throttle(struct tty_struct *tty) +{ +} + +static void con_unthrottle(struct tty_struct *tty) +{ + struct vc_data *vc = tty->driver_data; + + wake_up_interruptible(&vc->paste_wait); +} + +/* + * Turn the Scroll-Lock LED on when the tty is stopped + */ +static void con_stop(struct tty_struct *tty) +{ + int console_num; + if (!tty) + return; + console_num = tty->index; + if (!vc_cons_allocated(console_num)) + return; + vt_kbd_con_stop(console_num); +} + +/* + * Turn the Scroll-Lock LED off when the console is started + */ +static void con_start(struct tty_struct *tty) +{ + int console_num; + if (!tty) + return; + console_num = tty->index; + if (!vc_cons_allocated(console_num)) + return; + vt_kbd_con_start(console_num); +} + +static void con_flush_chars(struct tty_struct *tty) +{ + struct vc_data *vc; + + if (in_interrupt()) /* from flush_to_ldisc */ + return; + + /* if we race with con_close(), vt may be null */ + console_lock(); + vc = tty->driver_data; + if (vc) + set_cursor(vc); + console_unlock(); +} + +/* + * Allocate the console screen memory. + */ +static int con_install(struct tty_driver *driver, struct tty_struct *tty) +{ + unsigned int currcons = tty->index; + struct vc_data *vc; + int ret; + + console_lock(); + ret = vc_allocate(currcons); + if (ret) + goto unlock; + + vc = vc_cons[currcons].d; + + /* Still being freed */ + if (vc->port.tty) { + ret = -ERESTARTSYS; + goto unlock; + } + + ret = tty_port_install(&vc->port, driver, tty); + if (ret) + goto unlock; + + tty->driver_data = vc; + vc->port.tty = tty; + + if (!tty->winsize.ws_row && !tty->winsize.ws_col) { + tty->winsize.ws_row = vc_cons[currcons].d->vc_rows; + tty->winsize.ws_col = vc_cons[currcons].d->vc_cols; + } + if (vc->vc_utf) + tty->termios.c_iflag |= IUTF8; + else + tty->termios.c_iflag &= ~IUTF8; +unlock: + console_unlock(); + return ret; +} + +static int con_open(struct tty_struct *tty, struct file *filp) +{ + /* everything done in install */ + return 0; +} + + +static void con_close(struct tty_struct *tty, struct file *filp) +{ + /* Nothing to do - we defer to shutdown */ +} + +static void con_shutdown(struct tty_struct *tty) +{ + struct vc_data *vc = tty->driver_data; + BUG_ON(vc == NULL); + console_lock(); + vc->port.tty = NULL; + console_unlock(); +} + +static int default_color = 7; /* white */ +static int default_italic_color = 2; // green (ASCII) +static int default_underline_color = 3; // cyan (ASCII) +module_param_named(color, default_color, int, S_IRUGO | S_IWUSR); +module_param_named(italic, default_italic_color, int, S_IRUGO | S_IWUSR); +module_param_named(underline, default_underline_color, int, S_IRUGO | S_IWUSR); + +static void vc_init(struct vc_data *vc, unsigned int rows, + unsigned int cols, int do_clear) +{ + int j, k ; + + vc->vc_cols = cols; + vc->vc_rows = rows; + vc->vc_size_row = cols << 1; + vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row; + + set_origin(vc); + vc->vc_pos = vc->vc_origin; + reset_vc(vc); + for (j=k=0; j<16; j++) { + vc->vc_palette[k++] = default_red[j] ; + vc->vc_palette[k++] = default_grn[j] ; + vc->vc_palette[k++] = default_blu[j] ; + } + vc->vc_def_color = default_color; + vc->vc_ulcolor = default_underline_color; + vc->vc_itcolor = default_italic_color; + vc->vc_halfcolor = 0x08; /* grey */ + init_waitqueue_head(&vc->paste_wait); + reset_terminal(vc, do_clear); +} + +/* + * This routine initializes console interrupts, and does nothing + * else. If you want the screen to clear, call tty_write with + * the appropriate escape-sequence. + */ + +static int __init con_init(void) +{ + const char *display_desc = NULL; + struct vc_data *vc; + unsigned int currcons = 0, i; + + console_lock(); + + if (conswitchp) + display_desc = conswitchp->con_startup(); + if (!display_desc) { + fg_console = 0; + console_unlock(); + return 0; + } + + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + struct con_driver *con_driver = ®istered_con_driver[i]; + + if (con_driver->con == NULL) { + con_driver->con = conswitchp; + con_driver->desc = display_desc; + con_driver->flag = CON_DRIVER_FLAG_INIT; + con_driver->first = 0; + con_driver->last = MAX_NR_CONSOLES - 1; + break; + } + } + + for (i = 0; i < MAX_NR_CONSOLES; i++) + con_driver_map[i] = conswitchp; + + if (blankinterval) { + blank_state = blank_normal_wait; + mod_timer(&console_timer, jiffies + (blankinterval * HZ)); + } + + for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { + vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); + INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); + tty_port_init(&vc->port); + visual_init(vc, currcons, 1); + vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); + vc_init(vc, vc->vc_rows, vc->vc_cols, + currcons || !vc->vc_sw->con_save_screen); + } + currcons = fg_console = 0; + master_display_fg = vc = vc_cons[currcons].d; + set_origin(vc); + save_screen(vc); + gotoxy(vc, vc->vc_x, vc->vc_y); + csi_J(vc, 0); + update_screen(vc); + pr_info("Console: %s %s %dx%d\n", + vc->vc_can_do_color ? "colour" : "mono", + display_desc, vc->vc_cols, vc->vc_rows); + printable = 1; + + console_unlock(); + +#ifdef CONFIG_VT_CONSOLE + register_console(&vt_console_driver); +#endif + return 0; +} +console_initcall(con_init); + +static const struct tty_operations con_ops = { + .install = con_install, + .open = con_open, + .close = con_close, + .write = con_write, + .write_room = con_write_room, + .put_char = con_put_char, + .flush_chars = con_flush_chars, + .chars_in_buffer = con_chars_in_buffer, + .ioctl = vt_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = vt_compat_ioctl, +#endif + .stop = con_stop, + .start = con_start, + .throttle = con_throttle, + .unthrottle = con_unthrottle, + .resize = vt_resize, + .shutdown = con_shutdown +}; + +static struct cdev vc0_cdev; + +static ssize_t show_tty_active(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "tty%d\n", fg_console + 1); +} +static DEVICE_ATTR(active, S_IRUGO, show_tty_active, NULL); + +int __init vty_init(const struct file_operations *console_fops) +{ + cdev_init(&vc0_cdev, console_fops); + if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || + register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) + panic("Couldn't register /dev/tty0 driver\n"); + tty0dev = device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0"); + if (IS_ERR(tty0dev)) + tty0dev = NULL; + else + WARN_ON(device_create_file(tty0dev, &dev_attr_active) < 0); + + vcs_init(); + + console_driver = alloc_tty_driver(MAX_NR_CONSOLES); + if (!console_driver) + panic("Couldn't allocate console driver\n"); + + console_driver->name = "tty"; + console_driver->name_base = 1; + console_driver->major = TTY_MAJOR; + console_driver->minor_start = 1; + console_driver->type = TTY_DRIVER_TYPE_CONSOLE; + console_driver->init_termios = tty_std_termios; + if (default_utf8) + console_driver->init_termios.c_iflag |= IUTF8; + console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS; + tty_set_operations(console_driver, &con_ops); + if (tty_register_driver(console_driver)) + panic("Couldn't register console driver\n"); + kbd_init(); + console_map_init(); +#ifdef CONFIG_MDA_CONSOLE + mda_console_init(); +#endif + return 0; +} + +#ifndef VT_SINGLE_DRIVER + +static struct class *vtconsole_class; + +static int do_bind_con_driver(const struct consw *csw, int first, int last, + int deflt) +{ + struct module *owner = csw->owner; + const char *desc = NULL; + struct con_driver *con_driver; + int i, j = -1, k = -1, retval = -ENODEV; + + if (!try_module_get(owner)) + return -ENODEV; + + WARN_CONSOLE_UNLOCKED(); + + /* check if driver is registered */ + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + con_driver = ®istered_con_driver[i]; + + if (con_driver->con == csw) { + desc = con_driver->desc; + retval = 0; + break; + } + } + + if (retval) + goto err; + + if (!(con_driver->flag & CON_DRIVER_FLAG_INIT)) { + csw->con_startup(); + con_driver->flag |= CON_DRIVER_FLAG_INIT; + } + + if (deflt) { + if (conswitchp) + module_put(conswitchp->owner); + + __module_get(owner); + conswitchp = csw; + } + + first = max(first, con_driver->first); + last = min(last, con_driver->last); + + for (i = first; i <= last; i++) { + int old_was_color; + struct vc_data *vc = vc_cons[i].d; + + if (con_driver_map[i]) + module_put(con_driver_map[i]->owner); + __module_get(owner); + con_driver_map[i] = csw; + + if (!vc || !vc->vc_sw) + continue; + + j = i; + + if (CON_IS_VISIBLE(vc)) { + k = i; + save_screen(vc); + } + + old_was_color = vc->vc_can_do_color; + vc->vc_sw->con_deinit(vc); + vc->vc_origin = (unsigned long)vc->vc_screenbuf; + visual_init(vc, i, 0); + set_origin(vc); + update_attr(vc); + + /* If the console changed between mono <-> color, then + * the attributes in the screenbuf will be wrong. The + * following resets all attributes to something sane. + */ + if (old_was_color != vc->vc_can_do_color) + clear_buffer_attributes(vc); + } + + pr_info("Console: switching "); + if (!deflt) + printk("consoles %d-%d ", first+1, last+1); + if (j >= 0) { + struct vc_data *vc = vc_cons[j].d; + + printk("to %s %s %dx%d\n", + vc->vc_can_do_color ? "colour" : "mono", + desc, vc->vc_cols, vc->vc_rows); + + if (k >= 0) { + vc = vc_cons[k].d; + update_screen(vc); + } + } else + printk("to %s\n", desc); + + retval = 0; +err: + module_put(owner); + return retval; +}; + + +#ifdef CONFIG_VT_HW_CONSOLE_BINDING +static int con_is_graphics(const struct consw *csw, int first, int last) +{ + int i, retval = 0; + + for (i = first; i <= last; i++) { + struct vc_data *vc = vc_cons[i].d; + + if (vc && vc->vc_mode == KD_GRAPHICS) { + retval = 1; + break; + } + } + + return retval; +} + +/* unlocked version of unbind_con_driver() */ +int do_unbind_con_driver(const struct consw *csw, int first, int last, int deflt) +{ + struct module *owner = csw->owner; + const struct consw *defcsw = NULL; + struct con_driver *con_driver = NULL, *con_back = NULL; + int i, retval = -ENODEV; + + if (!try_module_get(owner)) + return -ENODEV; + + WARN_CONSOLE_UNLOCKED(); + + /* check if driver is registered and if it is unbindable */ + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + con_driver = ®istered_con_driver[i]; + + if (con_driver->con == csw && + con_driver->flag & CON_DRIVER_FLAG_MODULE) { + retval = 0; + break; + } + } + + if (retval) + goto err; + + retval = -ENODEV; + + /* check if backup driver exists */ + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + con_back = ®istered_con_driver[i]; + + if (con_back->con && + !(con_back->flag & CON_DRIVER_FLAG_MODULE)) { + defcsw = con_back->con; + retval = 0; + break; + } + } + + if (retval) + goto err; + + if (!con_is_bound(csw)) + goto err; + + first = max(first, con_driver->first); + last = min(last, con_driver->last); + + for (i = first; i <= last; i++) { + if (con_driver_map[i] == csw) { + module_put(csw->owner); + con_driver_map[i] = NULL; + } + } + + if (!con_is_bound(defcsw)) { + const struct consw *defconsw = conswitchp; + + defcsw->con_startup(); + con_back->flag |= CON_DRIVER_FLAG_INIT; + /* + * vgacon may change the default driver to point + * to dummycon, we restore it here... + */ + conswitchp = defconsw; + } + + if (!con_is_bound(csw)) + con_driver->flag &= ~CON_DRIVER_FLAG_INIT; + + /* ignore return value, binding should not fail */ + do_bind_con_driver(defcsw, first, last, deflt); +err: + module_put(owner); + return retval; + +} +EXPORT_SYMBOL_GPL(do_unbind_con_driver); + +static int vt_bind(struct con_driver *con) +{ + const struct consw *defcsw = NULL, *csw = NULL; + int i, more = 1, first = -1, last = -1, deflt = 0; + + if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE) || + con_is_graphics(con->con, con->first, con->last)) + goto err; + + csw = con->con; + + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + struct con_driver *con = ®istered_con_driver[i]; + + if (con->con && !(con->flag & CON_DRIVER_FLAG_MODULE)) { + defcsw = con->con; + break; + } + } + + if (!defcsw) + goto err; + + while (more) { + more = 0; + + for (i = con->first; i <= con->last; i++) { + if (con_driver_map[i] == defcsw) { + if (first == -1) + first = i; + last = i; + more = 1; + } else if (first != -1) + break; + } + + if (first == 0 && last == MAX_NR_CONSOLES -1) + deflt = 1; + + if (first != -1) { + console_lock(); + do_bind_con_driver(csw, first, last, deflt); + console_unlock(); + } + + first = -1; + last = -1; + deflt = 0; + } + +err: + return 0; +} + +static int vt_unbind(struct con_driver *con) +{ + const struct consw *csw = NULL; + int i, more = 1, first = -1, last = -1, deflt = 0; + + if (!con->con || !(con->flag & CON_DRIVER_FLAG_MODULE) || + con_is_graphics(con->con, con->first, con->last)) + goto err; + + csw = con->con; + + while (more) { + more = 0; + + for (i = con->first; i <= con->last; i++) { + if (con_driver_map[i] == csw) { + if (first == -1) + first = i; + last = i; + more = 1; + } else if (first != -1) + break; + } + + if (first == 0 && last == MAX_NR_CONSOLES -1) + deflt = 1; + + if (first != -1) { + console_lock(); + do_unbind_con_driver(csw, first, last, deflt); + console_unlock(); + } + + first = -1; + last = -1; + deflt = 0; + } + +err: + return 0; +} +#else +static inline int vt_bind(struct con_driver *con) +{ + return 0; +} +static inline int vt_unbind(struct con_driver *con) +{ + return 0; +} +#endif /* CONFIG_VT_HW_CONSOLE_BINDING */ + +static ssize_t store_bind(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct con_driver *con = dev_get_drvdata(dev); + int bind = simple_strtoul(buf, NULL, 0); + + if (bind) + vt_bind(con); + else + vt_unbind(con); + + return count; +} + +static ssize_t show_bind(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct con_driver *con = dev_get_drvdata(dev); + int bind = con_is_bound(con->con); + + return snprintf(buf, PAGE_SIZE, "%i\n", bind); +} + +static ssize_t show_name(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct con_driver *con = dev_get_drvdata(dev); + + return snprintf(buf, PAGE_SIZE, "%s %s\n", + (con->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)", + con->desc); + +} + +static struct device_attribute device_attrs[] = { + __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind), + __ATTR(name, S_IRUGO, show_name, NULL), +}; + +static int vtconsole_init_device(struct con_driver *con) +{ + int i; + int error = 0; + + con->flag |= CON_DRIVER_FLAG_ATTR; + dev_set_drvdata(con->dev, con); + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { + error = device_create_file(con->dev, &device_attrs[i]); + if (error) + break; + } + + if (error) { + while (--i >= 0) + device_remove_file(con->dev, &device_attrs[i]); + con->flag &= ~CON_DRIVER_FLAG_ATTR; + } + + return error; +} + +static void vtconsole_deinit_device(struct con_driver *con) +{ + int i; + + if (con->flag & CON_DRIVER_FLAG_ATTR) { + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) + device_remove_file(con->dev, &device_attrs[i]); + con->flag &= ~CON_DRIVER_FLAG_ATTR; + } +} + +/** + * con_is_bound - checks if driver is bound to the console + * @csw: console driver + * + * RETURNS: zero if unbound, nonzero if bound + * + * Drivers can call this and if zero, they should release + * all resources allocated on con_startup() + */ +int con_is_bound(const struct consw *csw) +{ + int i, bound = 0; + + for (i = 0; i < MAX_NR_CONSOLES; i++) { + if (con_driver_map[i] == csw) { + bound = 1; + break; + } + } + + return bound; +} +EXPORT_SYMBOL(con_is_bound); + +/** + * con_debug_enter - prepare the console for the kernel debugger + * @sw: console driver + * + * Called when the console is taken over by the kernel debugger, this + * function needs to save the current console state, then put the console + * into a state suitable for the kernel debugger. + * + * RETURNS: + * Zero on success, nonzero if a failure occurred when trying to prepare + * the console for the debugger. + */ +int con_debug_enter(struct vc_data *vc) +{ + int ret = 0; + + saved_fg_console = fg_console; + saved_last_console = last_console; + saved_want_console = want_console; + saved_vc_mode = vc->vc_mode; + saved_console_blanked = console_blanked; + vc->vc_mode = KD_TEXT; + console_blanked = 0; + if (vc->vc_sw->con_debug_enter) + ret = vc->vc_sw->con_debug_enter(vc); +#ifdef CONFIG_KGDB_KDB + /* Set the initial LINES variable if it is not already set */ + if (vc->vc_rows < 999) { + int linecount; + char lns[4]; + const char *setargs[3] = { + "set", + "LINES", + lns, + }; + if (kdbgetintenv(setargs[0], &linecount)) { + snprintf(lns, 4, "%i", vc->vc_rows); + kdb_set(2, setargs); + } + } + if (vc->vc_cols < 999) { + int colcount; + char cols[4]; + const char *setargs[3] = { + "set", + "COLUMNS", + cols, + }; + if (kdbgetintenv(setargs[0], &colcount)) { + snprintf(cols, 4, "%i", vc->vc_cols); + kdb_set(2, setargs); + } + } +#endif /* CONFIG_KGDB_KDB */ + return ret; +} +EXPORT_SYMBOL_GPL(con_debug_enter); + +/** + * con_debug_leave - restore console state + * @sw: console driver + * + * Restore the console state to what it was before the kernel debugger + * was invoked. + * + * RETURNS: + * Zero on success, nonzero if a failure occurred when trying to restore + * the console. + */ +int con_debug_leave(void) +{ + struct vc_data *vc; + int ret = 0; + + fg_console = saved_fg_console; + last_console = saved_last_console; + want_console = saved_want_console; + console_blanked = saved_console_blanked; + vc_cons[fg_console].d->vc_mode = saved_vc_mode; + + vc = vc_cons[fg_console].d; + if (vc->vc_sw->con_debug_leave) + ret = vc->vc_sw->con_debug_leave(vc); + return ret; +} +EXPORT_SYMBOL_GPL(con_debug_leave); + +static int do_register_con_driver(const struct consw *csw, int first, int last) +{ + struct module *owner = csw->owner; + struct con_driver *con_driver; + const char *desc; + int i, retval = 0; + + WARN_CONSOLE_UNLOCKED(); + + if (!try_module_get(owner)) + return -ENODEV; + + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + con_driver = ®istered_con_driver[i]; + + /* already registered */ + if (con_driver->con == csw) + retval = -EBUSY; + } + + if (retval) + goto err; + + desc = csw->con_startup(); + + if (!desc) + goto err; + + retval = -EINVAL; + + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + con_driver = ®istered_con_driver[i]; + + if (con_driver->con == NULL) { + con_driver->con = csw; + con_driver->desc = desc; + con_driver->node = i; + con_driver->flag = CON_DRIVER_FLAG_MODULE | + CON_DRIVER_FLAG_INIT; + con_driver->first = first; + con_driver->last = last; + retval = 0; + break; + } + } + + if (retval) + goto err; + + con_driver->dev = device_create(vtconsole_class, NULL, + MKDEV(0, con_driver->node), + NULL, "vtcon%i", + con_driver->node); + + if (IS_ERR(con_driver->dev)) { + printk(KERN_WARNING "Unable to create device for %s; " + "errno = %ld\n", con_driver->desc, + PTR_ERR(con_driver->dev)); + con_driver->dev = NULL; + } else { + vtconsole_init_device(con_driver); + } + +err: + module_put(owner); + return retval; +} + + +/** + * do_unregister_con_driver - unregister console driver from console layer + * @csw: console driver + * + * DESCRIPTION: All drivers that registers to the console layer must + * call this function upon exit, or if the console driver is in a state + * where it won't be able to handle console services, such as the + * framebuffer console without loaded framebuffer drivers. + * + * The driver must unbind first prior to unregistration. + */ +int do_unregister_con_driver(const struct consw *csw) +{ + int i, retval = -ENODEV; + + /* cannot unregister a bound driver */ + if (con_is_bound(csw)) + goto err; + + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + struct con_driver *con_driver = ®istered_con_driver[i]; + + if (con_driver->con == csw && + con_driver->flag & CON_DRIVER_FLAG_MODULE) { + vtconsole_deinit_device(con_driver); + device_destroy(vtconsole_class, + MKDEV(0, con_driver->node)); + con_driver->con = NULL; + con_driver->desc = NULL; + con_driver->dev = NULL; + con_driver->node = 0; + con_driver->flag = 0; + con_driver->first = 0; + con_driver->last = 0; + retval = 0; + break; + } + } +err: + return retval; +} +EXPORT_SYMBOL_GPL(do_unregister_con_driver); + +/* + * If we support more console drivers, this function is used + * when a driver wants to take over some existing consoles + * and become default driver for newly opened ones. + * + * do_take_over_console is basically a register followed by unbind + */ +int do_take_over_console(const struct consw *csw, int first, int last, int deflt) +{ + int err; + + err = do_register_con_driver(csw, first, last); + /* + * If we get an busy error we still want to bind the console driver + * and return success, as we may have unbound the console driver + * but not unregistered it. + */ + if (err == -EBUSY) + err = 0; + if (!err) + do_bind_con_driver(csw, first, last, deflt); + + return err; +} +EXPORT_SYMBOL_GPL(do_take_over_console); + + +/* + * give_up_console is a wrapper to unregister_con_driver. It will only + * work if driver is fully unbound. + */ +void give_up_console(const struct consw *csw) +{ + console_lock(); + do_unregister_con_driver(csw); + console_unlock(); +} + +static int __init vtconsole_class_init(void) +{ + int i; + + vtconsole_class = class_create(THIS_MODULE, "vtconsole"); + if (IS_ERR(vtconsole_class)) { + printk(KERN_WARNING "Unable to create vt console class; " + "errno = %ld\n", PTR_ERR(vtconsole_class)); + vtconsole_class = NULL; + } + + /* Add system drivers to sysfs */ + for (i = 0; i < MAX_NR_CON_DRIVER; i++) { + struct con_driver *con = ®istered_con_driver[i]; + + if (con->con && !con->dev) { + con->dev = device_create(vtconsole_class, NULL, + MKDEV(0, con->node), + NULL, "vtcon%i", + con->node); + + if (IS_ERR(con->dev)) { + printk(KERN_WARNING "Unable to create " + "device for %s; errno = %ld\n", + con->desc, PTR_ERR(con->dev)); + con->dev = NULL; + } else { + vtconsole_init_device(con); + } + } + } + + return 0; +} +postcore_initcall(vtconsole_class_init); + +#endif + +/* + * Screen blanking + */ + +static int set_vesa_blanking(char __user *p) +{ + unsigned int mode; + + if (get_user(mode, p + 1)) + return -EFAULT; + + vesa_blank_mode = (mode < 4) ? mode : 0; + return 0; +} + +void do_blank_screen(int entering_gfx) +{ + struct vc_data *vc = vc_cons[fg_console].d; + int i; + + WARN_CONSOLE_UNLOCKED(); + + if (console_blanked) { + if (blank_state == blank_vesa_wait) { + blank_state = blank_off; + vc->vc_sw->con_blank(vc, vesa_blank_mode + 1, 0); + } + return; + } + + /* entering graphics mode? */ + if (entering_gfx) { + hide_cursor(vc); + save_screen(vc); + vc->vc_sw->con_blank(vc, -1, 1); + console_blanked = fg_console + 1; + blank_state = blank_off; + set_origin(vc); + return; + } + + if (blank_state != blank_normal_wait) + return; + blank_state = blank_off; + + /* don't blank graphics */ + if (vc->vc_mode != KD_TEXT) { + console_blanked = fg_console + 1; + return; + } + + hide_cursor(vc); + del_timer_sync(&console_timer); + blank_timer_expired = 0; + + save_screen(vc); + /* In case we need to reset origin, blanking hook returns 1 */ + i = vc->vc_sw->con_blank(vc, vesa_off_interval ? 1 : (vesa_blank_mode + 1), 0); + console_blanked = fg_console + 1; + if (i) + set_origin(vc); + + if (console_blank_hook && console_blank_hook(1)) + return; + + if (vesa_off_interval && vesa_blank_mode) { + blank_state = blank_vesa_wait; + mod_timer(&console_timer, jiffies + vesa_off_interval); + } + vt_event_post(VT_EVENT_BLANK, vc->vc_num, vc->vc_num); +} +EXPORT_SYMBOL(do_blank_screen); + +/* + * Called by timer as well as from vt_console_driver + */ +void do_unblank_screen(int leaving_gfx) +{ + struct vc_data *vc; + + /* This should now always be called from a "sane" (read: can schedule) + * context for the sake of the low level drivers, except in the special + * case of oops_in_progress + */ + if (!oops_in_progress) + might_sleep(); + + WARN_CONSOLE_UNLOCKED(); + + ignore_poke = 0; + if (!console_blanked) + return; + if (!vc_cons_allocated(fg_console)) { + /* impossible */ + pr_warning("unblank_screen: tty %d not allocated ??\n", + fg_console+1); + return; + } + vc = vc_cons[fg_console].d; + /* Try to unblank in oops case too */ + if (vc->vc_mode != KD_TEXT && !vt_force_oops_output(vc)) + return; /* but leave console_blanked != 0 */ + + if (blankinterval) { + mod_timer(&console_timer, jiffies + (blankinterval * HZ)); + blank_state = blank_normal_wait; + } + + console_blanked = 0; + if (vc->vc_sw->con_blank(vc, 0, leaving_gfx) || vt_force_oops_output(vc)) + /* Low-level driver cannot restore -> do it ourselves */ + update_screen(vc); + if (console_blank_hook) + console_blank_hook(0); + set_palette(vc); + set_cursor(vc); + vt_event_post(VT_EVENT_UNBLANK, vc->vc_num, vc->vc_num); +} +EXPORT_SYMBOL(do_unblank_screen); + +/* + * This is called by the outside world to cause a forced unblank, mostly for + * oopses. Currently, I just call do_unblank_screen(0), but we could eventually + * call it with 1 as an argument and so force a mode restore... that may kill + * X or at least garbage the screen but would also make the Oops visible... + */ +void unblank_screen(void) +{ + do_unblank_screen(0); +} + +/* + * We defer the timer blanking to work queue so it can take the console mutex + * (console operations can still happen at irq time, but only from printk which + * has the console mutex. Not perfect yet, but better than no locking + */ +static void blank_screen_t(unsigned long dummy) +{ + if (unlikely(!keventd_up())) { + mod_timer(&console_timer, jiffies + (blankinterval * HZ)); + return; + } + blank_timer_expired = 1; + schedule_work(&console_work); +} + +void poke_blanked_console(void) +{ + WARN_CONSOLE_UNLOCKED(); + + /* Add this so we quickly catch whoever might call us in a non + * safe context. Nowadays, unblank_screen() isn't to be called in + * atomic contexts and is allowed to schedule (with the special case + * of oops_in_progress, but that isn't of any concern for this + * function. --BenH. + */ + might_sleep(); + + /* This isn't perfectly race free, but a race here would be mostly harmless, + * at worse, we'll do a spurrious blank and it's unlikely + */ + del_timer(&console_timer); + blank_timer_expired = 0; + + if (ignore_poke || !vc_cons[fg_console].d || vc_cons[fg_console].d->vc_mode == KD_GRAPHICS) + return; + if (console_blanked) + unblank_screen(); + else if (blankinterval) { + mod_timer(&console_timer, jiffies + (blankinterval * HZ)); + blank_state = blank_normal_wait; + } +} + +/* + * Palettes + */ + +static void set_palette(struct vc_data *vc) +{ + WARN_CONSOLE_UNLOCKED(); + + if (vc->vc_mode != KD_GRAPHICS) + vc->vc_sw->con_set_palette(vc, color_table); +} + +/* + * Load palette into the DAC registers. arg points to a colour + * map, 3 bytes per colour, 16 colours, range from 0 to 255. + */ + +int con_set_cmap(unsigned char __user *arg) +{ + int i, j, k; + unsigned char colormap[3*16]; + + if (copy_from_user(colormap, arg, sizeof(colormap))) + return -EFAULT; + + console_lock(); + for (i = k = 0; i < 16; i++) { + default_red[i] = colormap[k++]; + default_grn[i] = colormap[k++]; + default_blu[i] = colormap[k++]; + } + for (i = 0; i < MAX_NR_CONSOLES; i++) { + if (!vc_cons_allocated(i)) + continue; + for (j = k = 0; j < 16; j++) { + vc_cons[i].d->vc_palette[k++] = default_red[j]; + vc_cons[i].d->vc_palette[k++] = default_grn[j]; + vc_cons[i].d->vc_palette[k++] = default_blu[j]; + } + set_palette(vc_cons[i].d); + } + console_unlock(); + + return 0; +} + +int con_get_cmap(unsigned char __user *arg) +{ + int i, k; + unsigned char colormap[3*16]; + + console_lock(); + for (i = k = 0; i < 16; i++) { + colormap[k++] = default_red[i]; + colormap[k++] = default_grn[i]; + colormap[k++] = default_blu[i]; + } + console_unlock(); + + if (copy_to_user(arg, colormap, sizeof(colormap))) + return -EFAULT; + + return 0; +} + +void reset_palette(struct vc_data *vc) +{ + int j, k; + for (j=k=0; j<16; j++) { + vc->vc_palette[k++] = default_red[j]; + vc->vc_palette[k++] = default_grn[j]; + vc->vc_palette[k++] = default_blu[j]; + } + set_palette(vc); +} + +/* + * Font switching + * + * Currently we only support fonts up to 32 pixels wide, at a maximum height + * of 32 pixels. Userspace fontdata is stored with 32 bytes (shorts/ints, + * depending on width) reserved for each character which is kinda wasty, but + * this is done in order to maintain compatibility with the EGA/VGA fonts. It + * is up to the actual low-level console-driver convert data into its favorite + * format (maybe we should add a `fontoffset' field to the `display' + * structure so we won't have to convert the fontdata all the time. + * /Jes + */ + +#define max_font_size 65536 + +static int con_font_get(struct vc_data *vc, struct console_font_op *op) +{ + struct console_font font; + int rc = -EINVAL; + int c; + + if (op->data) { + font.data = kmalloc(max_font_size, GFP_KERNEL); + if (!font.data) + return -ENOMEM; + } else + font.data = NULL; + + console_lock(); + if (vc->vc_mode != KD_TEXT) + rc = -EINVAL; + else if (vc->vc_sw->con_font_get) + rc = vc->vc_sw->con_font_get(vc, &font); + else + rc = -ENOSYS; + console_unlock(); + + if (rc) + goto out; + + c = (font.width+7)/8 * 32 * font.charcount; + + if (op->data && font.charcount > op->charcount) + rc = -ENOSPC; + if (!(op->flags & KD_FONT_FLAG_OLD)) { + if (font.width > op->width || font.height > op->height) + rc = -ENOSPC; + } else { + if (font.width != 8) + rc = -EIO; + else if ((op->height && font.height > op->height) || + font.height > 32) + rc = -ENOSPC; + } + if (rc) + goto out; + + op->height = font.height; + op->width = font.width; + op->charcount = font.charcount; + + if (op->data && copy_to_user(op->data, font.data, c)) + rc = -EFAULT; + +out: + kfree(font.data); + return rc; +} + +static int con_font_set(struct vc_data *vc, struct console_font_op *op) +{ + struct console_font font; + int rc = -EINVAL; + int size; + + if (vc->vc_mode != KD_TEXT) + return -EINVAL; + if (!op->data) + return -EINVAL; + if (op->charcount > 512) + return -EINVAL; + if (!op->height) { /* Need to guess font height [compat] */ + int h, i; + u8 __user *charmap = op->data; + u8 tmp; + + /* If from KDFONTOP ioctl, don't allow things which can be done in userland, + so that we can get rid of this soon */ + if (!(op->flags & KD_FONT_FLAG_OLD)) + return -EINVAL; + for (h = 32; h > 0; h--) + for (i = 0; i < op->charcount; i++) { + if (get_user(tmp, &charmap[32*i+h-1])) + return -EFAULT; + if (tmp) + goto nonzero; + } + return -EINVAL; + nonzero: + op->height = h; + } + if (op->width <= 0 || op->width > 32 || op->height > 32) + return -EINVAL; + size = (op->width+7)/8 * 32 * op->charcount; + if (size > max_font_size) + return -ENOSPC; + font.charcount = op->charcount; + font.height = op->height; + font.width = op->width; + font.data = memdup_user(op->data, size); + if (IS_ERR(font.data)) + return PTR_ERR(font.data); + console_lock(); + if (vc->vc_mode != KD_TEXT) + rc = -EINVAL; + else if (vc->vc_sw->con_font_set) + rc = vc->vc_sw->con_font_set(vc, &font, op->flags); + else + rc = -ENOSYS; + console_unlock(); + kfree(font.data); + return rc; +} + +static int con_font_default(struct vc_data *vc, struct console_font_op *op) +{ + struct console_font font = {.width = op->width, .height = op->height}; + char name[MAX_FONT_NAME]; + char *s = name; + int rc; + + + if (!op->data) + s = NULL; + else if (strncpy_from_user(name, op->data, MAX_FONT_NAME - 1) < 0) + return -EFAULT; + else + name[MAX_FONT_NAME - 1] = 0; + + console_lock(); + if (vc->vc_mode != KD_TEXT) { + console_unlock(); + return -EINVAL; + } + if (vc->vc_sw->con_font_default) + rc = vc->vc_sw->con_font_default(vc, &font, s); + else + rc = -ENOSYS; + console_unlock(); + if (!rc) { + op->width = font.width; + op->height = font.height; + } + return rc; +} + +static int con_font_copy(struct vc_data *vc, struct console_font_op *op) +{ + int con = op->height; + int rc; + + + console_lock(); + if (vc->vc_mode != KD_TEXT) + rc = -EINVAL; + else if (!vc->vc_sw->con_font_copy) + rc = -ENOSYS; + else if (con < 0 || !vc_cons_allocated(con)) + rc = -ENOTTY; + else if (con == vc->vc_num) /* nothing to do */ + rc = 0; + else + rc = vc->vc_sw->con_font_copy(vc, con); + console_unlock(); + return rc; +} + +int con_font_op(struct vc_data *vc, struct console_font_op *op) +{ + switch (op->op) { + case KD_FONT_OP_SET: + return con_font_set(vc, op); + case KD_FONT_OP_GET: + return con_font_get(vc, op); + case KD_FONT_OP_SET_DEFAULT: + return con_font_default(vc, op); + case KD_FONT_OP_COPY: + return con_font_copy(vc, op); + } + return -ENOSYS; +} + +/* + * Interface exported to selection and vcs. + */ + +/* used by selection */ +u16 screen_glyph(struct vc_data *vc, int offset) +{ + u16 w = scr_readw(screenpos(vc, offset, 1)); + u16 c = w & 0xff; + + if (w & vc->vc_hi_font_mask) + c |= 0x100; + return c; +} +EXPORT_SYMBOL_GPL(screen_glyph); + +/* used by vcs - note the word offset */ +unsigned short *screen_pos(struct vc_data *vc, int w_offset, int viewed) +{ + return screenpos(vc, 2 * w_offset, viewed); +} + +void getconsxy(struct vc_data *vc, unsigned char *p) +{ + p[0] = vc->vc_x; + p[1] = vc->vc_y; +} + +void putconsxy(struct vc_data *vc, unsigned char *p) +{ + hide_cursor(vc); + gotoxy(vc, p[0], p[1]); + set_cursor(vc); +} + +u16 vcs_scr_readw(struct vc_data *vc, const u16 *org) +{ + if ((unsigned long)org == vc->vc_pos && softcursor_original != -1) + return softcursor_original; + return scr_readw(org); +} + +void vcs_scr_writew(struct vc_data *vc, u16 val, u16 *org) +{ + scr_writew(val, org); + if ((unsigned long)org == vc->vc_pos) { + softcursor_original = -1; + add_softcursor(vc); + } +} + +void vcs_scr_updated(struct vc_data *vc) +{ + notify_update(vc); +} + +/* + * Visible symbols for modules + */ + +EXPORT_SYMBOL(color_table); +EXPORT_SYMBOL(default_red); +EXPORT_SYMBOL(default_grn); +EXPORT_SYMBOL(default_blu); +EXPORT_SYMBOL(update_region); +EXPORT_SYMBOL(redraw_screen); +EXPORT_SYMBOL(vc_resize); +EXPORT_SYMBOL(fg_console); +EXPORT_SYMBOL(console_blank_hook); +EXPORT_SYMBOL(console_blanked); +EXPORT_SYMBOL(vc_cons); +EXPORT_SYMBOL(global_cursor_default); +#ifndef VT_SINGLE_DRIVER +EXPORT_SYMBOL(give_up_console); +#endif diff -urNp linux-3.15.orig/drivers/video/Kconfig linux-3.15/drivers/video/Kconfig --- linux-3.15.orig/drivers/video/Kconfig 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/video/Kconfig 2014-06-09 09:26:58.000000000 +0900 @@ -5,6 +5,17 @@ menu "Graphics support" depends on HAS_IOMEM +config UNICON + bool "UNICON console support" + depends on FB + select FRAMEBUFFER_CONSOLE + help + This is UNICON CJK display system lower level driver and API. + Unikey and CJK font modules are included in the UNICON package. + If you want to use UNICON, say Y here. If unsure, say N. + + source "drivers/video/unicon/Kconfig" + config HAVE_FB_ATMEL bool diff -urNp linux-3.15.orig/drivers/video/Makefile linux-3.15/drivers/video/Makefile --- linux-3.15.orig/drivers/video/Makefile 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/video/Makefile 2014-06-09 09:28:17.000000000 +0900 @@ -7,6 +7,10 @@ obj-y += backlight/ obj-y += fbdev/ +ifeq ($(CONFIG_UNICON),y) +subdir-m += unicon +endif + obj-$(CONFIG_VIDEOMODE_HELPERS) += display_timing.o videomode.o ifeq ($(CONFIG_OF),y) obj-$(CONFIG_VIDEOMODE_HELPERS) += of_display_timing.o of_videomode.o diff -urNp linux-3.15.orig/drivers/video/console/bitblit.c linux-3.15/drivers/video/console/bitblit.c --- linux-3.15.orig/drivers/video/console/bitblit.c 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/video/console/bitblit.c 2014-06-09 09:00:22.000000000 +0900 @@ -19,6 +19,10 @@ #include #include "fbcon.h" +#ifdef CONFIG_UNICON +#include "unicon.c" +extern struct display fb_display[MAX_NR_CONSOLES]; +#endif /* * Accelerated handlers. */ @@ -201,7 +205,211 @@ static void bit_putcs(struct vc_data *vc kfree(buf); } +#ifdef CONFIG_UNICON +static void bit_putcs_tl(struct vc_data *vc, struct fb_info *info, + const unsigned short *s, int count, int yy, int xx, + int fg, int bg, struct double_byte * doublebyte_default) +{ +/* void (*move_unaligned)(struct fb_info *info, struct fb_pixmap *buf, + u8 *dst, u32 d_pitch, u8 *src, u32 idx, + u32 height, u32 shift_high, u32 shift_low, + u32 mod); + void (*move_aligned)(struct fb_info *info, struct fb_pixmap *buf, + u8 *dst, u32 d_pitch, u8 *src, u32 s_pitch, + u32 height);*/ + unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; + unsigned int width = (vc->vc_font.width + 7) >> 3; + unsigned int cellsize = vc->vc_font.height * width; + unsigned int maxcnt = info->pixmap.size/cellsize; + unsigned int scan_align = info->pixmap.scan_align - 1; + unsigned int buf_align = info->pixmap.buf_align - 1; + unsigned int shift_low = 0, mod = vc->vc_font.width % 8; + unsigned int shift_high = 8, pitch, cnt, size, k; + unsigned int idx = vc->vc_font.width >> 3; + unsigned int attribute = get_attribute(info, scr_readw(s)); + struct fb_image image; + u8 *src, *dst, *buf = NULL; + u_char * fontdata_save; + int index, c,i; + int extendedchar; + fontdata_save = vc->vc_font.data; + + if (attribute) { + buf = kmalloc(cellsize, GFP_KERNEL); + if (!buf) + return; + } + + image.fg_color = fg; + image.bg_color = bg; + + image.dx = xx * vc->vc_font.width; + image.dy = yy * vc->vc_font.height; + image.height = vc->vc_font.height; + image.depth = 1; + + /*if (info->pixmap.outbuf && info->pixmap.inbuf) { + move_aligned = fb_iomove_buf_aligned; + move_unaligned = fb_iomove_buf_unaligned; + } else { + move_aligned = fb_sysmove_buf_aligned; + move_unaligned = fb_sysmove_buf_unaligned; + }*/ + while (count) { + if (count > maxcnt) + cnt = k = maxcnt; + else + cnt = k = count; + + image.width = vc->vc_font.width * cnt; + pitch = ((image.width + 7) >> 3) + scan_align; + pitch &= ~scan_align; + size = pitch * image.height + buf_align; + size &= ~buf_align; + dst = fb_get_buffer_offset(info, &info->pixmap, size); + image.data = dst; + if (mod) { + for(i = 0; i < k; s++, i++){ + c = (scr_readw (hibyte_pos (vc, s)) << 16) | scr_readw (s); + extendedchar = c & (DB_VALIDATE<<16); + if (extendedchar){ + if ( c & (DB_RIGHT_MASK << 16) ) // right half + index = doublebyte_default->font_index((c>>16)&0xff, (c&0xff)) + 16; + else + index = doublebyte_default->font_index((c&0xff),(c>>16)&0xff); + } + if (extendedchar && index >=0 && index < doublebyte_default->charcount){ + vc->vc_font.data = doublebyte_default->font_data +index; + c = (c & 0xff00); + }else{ + c = c & 0xffff; + vc->vc_font.data = fontdata_save; + } + src = vc->vc_font.data + (c&charmask)*cellsize; + + if (attribute) { + update_attr(buf, src, attribute, vc); + src = buf; + } + + fb_pad_unaligned_buffer(dst, pitch, src, idx, + image.height, shift_high, + shift_low, mod); + shift_low += mod; + dst += (shift_low >= 8) ? width : width - 1; + shift_low &= 7; + shift_high = 8 - shift_low; + } + } else { + for(i = 0; i < k; s++, i++){ + c = (scr_readw (hibyte_pos (vc, s)) << 16) | scr_readw (s); + extendedchar = c & (DB_VALIDATE<<16); + if (extendedchar){ + if ( c & (DB_RIGHT_MASK << 16) ) // right half + index = doublebyte_default->font_index((c>>16)&0xff, (c&0xff)) + 16; + else + index = doublebyte_default->font_index((c&0xff),(c>>16)&0xff); + } + if (extendedchar && index >=0 && index < doublebyte_default->charcount){ + vc->vc_font.data = doublebyte_default->font_data +index; + c = (c & 0xff00); + }else{ + c = c & 0xffff; + vc->vc_font.data = fontdata_save; + } + src = vc->vc_font.data + (c&charmask)*cellsize; + + if (attribute) { + update_attr(buf, src, attribute, vc); + src = buf; + } + + fb_pad_aligned_buffer(dst, pitch, src, idx, image.height); + dst += width; + } + } + info->fbops->fb_imageblit(info, &image); + image.dx += cnt * vc->vc_font.width; + count -= cnt; + } + + if (buf) + kfree(buf); + vc->vc_font.data = fontdata_save; +} +static void bit_putcs_wrap(struct vc_data *vc, struct fb_info *info, + const unsigned short *s, int count, int ypos, int xpos, + int fg, int bg) +{ + int n,yy; + struct display *p = &fb_display[vc->vc_num]; + const unsigned short * str = s; + struct double_byte * doublebyte_default = NULL; + + yy = real_y(p, ypos); + + if (UniconFontManager != NULL) + doublebyte_default = UniconFontManager->getfont (vc->vc_num); + + if (!doublebyte_default) + { + bit_putcs(vc, info, s, count, yy, xpos, fg, bg); + return; + } + + /* + * 2009/01/23 + * modified by Toshi for gpm + */ + if(count == 1) + { + u32 extendedchar, index, c; + u8* fontdata_save; + u16 chr[2] = {0, 0}; + + fontdata_save = vc->vc_font.data; + c = (s >= (u16*)vc->vc_origin) && (s < (u16*)vc->vc_scr_end); + c = c ? (scr_readw (hibyte_pos (vc, s)) << 16) | scr_readw (s) : (s[1] << 16) | s[0]; + + extendedchar = c & (DB_VALIDATE<<16); + if (extendedchar) { + if ( c & (DB_RIGHT_MASK << 16)) {// right half + index = doublebyte_default->font_index((c>>16)&0xff, (c&0xff)) + 16; + } else { + index = doublebyte_default->font_index((c&0xff),(c>>16)&0xff); + } + + if (index >=0 && index < doublebyte_default->charcount) { + vc->vc_font.data = doublebyte_default->font_data +index; + c &= 0xff00; + } + } + + chr[0] = (u16)c; + bit_putcs(vc, info, &chr[0], 1, yy, xpos, fg, bg); + + vc->vc_font.data = fontdata_save; + return; + } + + while (count > 0) { + n = fbcon_get_dchar_len (vc, p, str, count); + if (n != 0) + bit_putcs_tl(vc, info, str, n, yy, xpos, + fg, bg, doublebyte_default); + str += n; + xpos += n; + count -= n; + n = fbcon_get_schar_len (vc, p, str, count); + if (n != 0) + bit_putcs(vc, info, str, n, yy, xpos ,fg ,bg); + str += n; + xpos += n; + count -= n; + } +} +#endif static void bit_clear_margins(struct vc_data *vc, struct fb_info *info, int bottom_only) { @@ -245,6 +453,11 @@ static void bit_cursor(struct vc_data *v int attribute, use_sw = (vc->vc_cursor_type & 0x10); int err = 1; char *src; +#ifdef CONFIG_UNICON + int extendedchar = 0; + u_char * fontdata_save; + struct double_byte * doublebyte_default = NULL; +#endif cursor.set = 0; @@ -257,7 +470,33 @@ static void bit_cursor(struct vc_data *v y += softback_lines; } +#ifdef CONFIG_UNICON + if (UniconFontManager != NULL) + doublebyte_default = UniconFontManager->getfont (vc->vc_num); + + fontdata_save = vc->vc_font.data; + if(doublebyte_default != NULL){ + c = (scr_readw (hibyte_pos (vc, (u16 *) vc->vc_pos)) << 16) | + scr_readw((u16 *) vc->vc_pos); + extendedchar = c & (DB_VALIDATE<<16); + if (extendedchar) { + int index; + if ( c & (DB_RIGHT_MASK << 16)) {// right half + index = doublebyte_default->font_index((c>>16)&0xff, (c&0xff)) + 16; + } else { + index = doublebyte_default->font_index((c&0xff),(c>>16)&0xff); + } + if (index >=0 && index < doublebyte_default->charcount) { + vc->vc_font.data = doublebyte_default->font_data +index; + c = (c & 0xff00); + }else c = c & 0xffff; + } else { + c = c & 0xffff; + } + }else c = scr_readw((u16 *) vc->vc_pos); +#else c = scr_readw((u16 *) vc->vc_pos); +#endif attribute = get_attribute(info, c); src = vc->vc_font.data + ((c & charmask) * (w * vc->vc_font.height)); @@ -387,6 +626,10 @@ static void bit_cursor(struct vc_data *v soft_cursor(info, &cursor); ops->cursor_reset = 0; +#ifdef CONFIG_UNICON + if (doublebyte_default != NULL && extendedchar) + vc->vc_font.data = fontdata_save; +#endif } static int bit_update_start(struct fb_info *info) @@ -405,7 +648,11 @@ void fbcon_set_bitops(struct fbcon_ops * { ops->bmove = bit_bmove; ops->clear = bit_clear; +#ifdef CONFIG_UNICON + ops->putcs = bit_putcs_wrap; +#else ops->putcs = bit_putcs; +#endif ops->clear_margins = bit_clear_margins; ops->cursor = bit_cursor; ops->update_start = bit_update_start; diff -urNp linux-3.15.orig/drivers/video/console/fbcon.c linux-3.15/drivers/video/console/fbcon.c --- linux-3.15.orig/drivers/video/console/fbcon.c 2014-06-09 03:19:54.000000000 +0900 +++ linux-3.15/drivers/video/console/fbcon.c 2014-06-09 09:00:22.000000000 +0900 @@ -92,7 +92,11 @@ enum { FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */ }; +#ifdef CONFIG_UNICON +struct display fb_display[MAX_NR_CONSOLES]; +#else static struct display fb_display[MAX_NR_CONSOLES]; +#endif static signed char con2fb_map[MAX_NR_CONSOLES]; static signed char con2fb_map_boot[MAX_NR_CONSOLES]; @@ -102,7 +106,11 @@ static int logo_lines; enums. */ static int logo_shown = FBCON_LOGO_CANSHOW; /* Software scrollback */ +#ifdef CONFIG_UNICON +int fbcon_softback_size = 32768; +#else static int fbcon_softback_size = 32768; +#endif static unsigned long softback_buf, softback_curr; static unsigned long softback_in; static unsigned long softback_top, softback_end; @@ -195,6 +203,11 @@ static void fbcon_start(void); static void fbcon_exit(void); static struct device *fbcon_device; +#ifdef CONFIG_UNICON +#include +const unsigned short * hibyte_pos(struct vc_data *vc, const unsigned short *p); +#endif + #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION static inline void fbcon_set_rotation(struct fb_info *info) { @@ -968,7 +981,11 @@ static const char *fbcon_startup(void) if (!softback_buf) { softback_buf = (unsigned long) +#ifdef CONFIG_UNICON + kmalloc(fbcon_softback_size * 2, +#else kmalloc(fbcon_softback_size, +#endif GFP_KERNEL); if (!softback_buf) { fbcon_softback_size = 0; @@ -1276,11 +1293,17 @@ static void fbcon_putcs(struct vc_data * int count, int ypos, int xpos) { struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; +#ifndef CONFIG_UNICON struct display *p = &fb_display[vc->vc_num]; +#endif struct fbcon_ops *ops = info->fbcon_par; if (!fbcon_is_inactive(vc, info)) +#ifdef CONFIG_UNICON + ops->putcs(vc, info, s, count, ypos, xpos, +#else ops->putcs(vc, info, s, count, real_y(p, ypos), xpos, +#endif get_color(vc, info, scr_readw(s), 1), get_color(vc, info, scr_readw(s), 0)); } @@ -1290,7 +1313,11 @@ static void fbcon_putc(struct vc_data *v unsigned short chr; scr_writew(c, &chr); +#ifdef CONFIG_UNICON + fbcon_putcs(vc, (unsigned short *)&c, 1, ypos, xpos); +#else fbcon_putcs(vc, &chr, 1, ypos, xpos); +#endif } static void fbcon_clear_margins(struct vc_data *vc, int bottom_only) @@ -1589,11 +1616,17 @@ static void fbcon_redraw_softback(struct unsigned short c; int x = 0; unsigned short attr = 1; +#ifdef CONFIG_UNICON + unsigned short c_ext; +#endif start = s; le = advance_row(s, 1); do { c = scr_readw(s); +#ifdef CONFIG_UNICON + c_ext = scr_readw(hibyte_pos(vc,s)); +#endif if (attr != (c & 0xff00)) { attr = c & 0xff00; if (s > start) { @@ -1603,7 +1636,11 @@ static void fbcon_redraw_softback(struct start = s; } } +#ifdef CONFIG_UNICON + if (c == scr_readw(d) && c_ext == scr_readw(hibyte_pos(vc,d))) { +#else if (c == scr_readw(d)) { +#endif if (s > start) { fbcon_putcs(vc, start, s - start, line, x); @@ -1728,9 +1765,15 @@ static void fbcon_redraw(struct vc_data unsigned short c; int x = 0; unsigned short attr = 1; +#ifdef CONFIG_UNICON + unsigned short c_ext; +#endif do { c = scr_readw(s); +#ifdef CONFIG_UNICON + c_ext = scr_readw(hibyte_pos(vc,s)); +#endif if (attr != (c & 0xff00)) { attr = c & 0xff00; if (s > start) { @@ -1740,7 +1783,11 @@ static void fbcon_redraw(struct vc_data start = s; } } +#ifdef CONFIG_UNICON + if (c == scr_readw(d) && c_ext == scr_readw(hibyte_pos(vc,d))) { +#else if (c == scr_readw(d)) { +#endif if (s > start) { fbcon_putcs(vc, start, s - start, line, x); @@ -1752,6 +1799,9 @@ static void fbcon_redraw(struct vc_data } } scr_writew(c, d); +#ifdef CONFIG_UNICON + scr_writew(scr_readw(s+(vc->vc_screenbuf_size>>1)),d+(vc->vc_screenbuf_size>>1)); +#endif console_conditional_schedule(); s++; d++; @@ -1781,6 +1831,9 @@ static inline void fbcon_softback_note(s while (count) { scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row); +#ifdef CONFIG_UNICON + scr_memcpyw((u16 *)softback_in+(fbcon_softback_size>>1),p+(vc->vc_screenbuf_size>>1),vc->vc_size_row); +#endif count--; p = advance_row(p, 1); softback_in += vc->vc_size_row; @@ -1903,6 +1956,15 @@ static int fbcon_scroll(struct vc_data * (b - count)), vc->vc_video_erase_char, vc->vc_size_row * count); +#ifdef CONFIG_UNICON + /* SCROLL_REDRAW */ + scr_memsetw((unsigned short *) (vc->vc_origin + + vc->vc_size_row * + (b - count) + + vc->vc_screenbuf_size), + vc->vc_video_erase_char & 0xff, + vc->vc_size_row * count); +#endif return 1; } break; @@ -1992,6 +2054,15 @@ static int fbcon_scroll(struct vc_data * t), vc->vc_video_erase_char, vc->vc_size_row * count); +#ifdef CONFIG_UNICON + /* SCROLL_REDRAW */ + scr_memsetw((unsigned short *) (vc->vc_origin + + vc->vc_size_row * + t + + vc->vc_screenbuf_size), + vc->vc_video_erase_char & 0xff, + vc->vc_size_row * count); +#endif return 1; } } @@ -2691,6 +2762,20 @@ static u16 *fbcon_screen_pos(struct vc_d unsigned long p; int line; +#ifdef CONFIG_UNICON + if (offset < 0) { + offset = -offset - 1; + if (vc->vc_num != fg_console || !softback_lines) + return (u16 *)(vc->vc_origin + offset + vc->vc_screenbuf_size); + line = offset / vc->vc_size_row; + if (line >= softback_lines) + return (u16 *)(vc->vc_origin + offset - softback_lines * vc->vc_size_row + vc->vc_screenbuf_size); + p = softback_curr + offset; + if (p >= softback_end) + p += softback_buf - softback_end; + return (u16 *)(p+fbcon_softback_size); + } +#endif if (vc->vc_num != fg_console || !softback_lines) return (u16 *) (vc->vc_origin + offset); line = offset / vc->vc_size_row; @@ -2798,6 +2883,11 @@ static int fbcon_scrolldelta(struct vc_d q -= vc->vc_size_row; scr_memcpyw((u16 *) q, (u16 *) p, vc->vc_size_row); +#ifdef CONFIG_UNICON + scr_memcpyw((u16* )(q+vc->vc_screenbuf_size), + (u16* )(p+fbcon_softback_size), + vc->vc_size_row); +#endif } softback_in = softback_curr = p; update_region(vc, vc->vc_origin, @@ -3655,4 +3745,9 @@ module_exit(fb_console_exit); #endif +#ifdef CONFIG_UNICON +EXPORT_SYMBOL(con2fb_map); +EXPORT_SYMBOL(fbcon_putc); +#endif + MODULE_LICENSE("GPL"); diff -urNp linux-3.15.orig/drivers/video/console/fbcon.c.orig linux-3.15/drivers/video/console/fbcon.c.orig --- linux-3.15.orig/drivers/video/console/fbcon.c.orig 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/console/fbcon.c.orig 2014-06-09 03:19:54.000000000 +0900 @@ -0,0 +1,3658 @@ +/* + * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver + * + * Copyright (C) 1995 Geert Uytterhoeven + * + * + * This file is based on the original Amiga console driver (amicon.c): + * + * Copyright (C) 1993 Hamish Macdonald + * Greg Harp + * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk] + * + * with work by William Rucklidge (wjr@cs.cornell.edu) + * Geert Uytterhoeven + * Jes Sorensen (jds@kom.auc.dk) + * Martin Apel + * + * and on the original Atari console driver (atacon.c): + * + * Copyright (C) 1993 Bjoern Brauel + * Roman Hodek + * + * with work by Guenther Kelleter + * Martin Schaller + * Andreas Schwab + * + * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org) + * Smart redraw scrolling, arbitrary font width support, 512char font support + * and software scrollback added by + * Jakub Jelinek (jj@ultra.linux.cz) + * + * Random hacking by Martin Mares + * + * 2001 - Documented with DocBook + * - Brad Douglas + * + * The low level operations for the various display memory organizations are + * now in separate source files. + * + * Currently the following organizations are supported: + * + * o afb Amiga bitplanes + * o cfb{2,4,8,16,24,32} Packed pixels + * o ilbm Amiga interleaved bitplanes + * o iplan2p[248] Atari interleaved bitplanes + * o mfb Monochrome + * o vga VGA characters/attributes + * + * To do: + * + * - Implement 16 plane mode (iplan2p16) + * + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file COPYING in the main directory of this archive for + * more details. + */ + +#undef FBCONDEBUG + +#include +#include +#include +#include +#include /* MSch: for IRQ probe */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* For counting font checksums */ +#include +#include + +#include "fbcon.h" + +#ifdef FBCONDEBUG +# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args) +#else +# define DPRINTK(fmt, args...) +#endif + +enum { + FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */ + FBCON_LOGO_DRAW = -2, /* draw the logo to a console */ + FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */ +}; + +static struct display fb_display[MAX_NR_CONSOLES]; + +static signed char con2fb_map[MAX_NR_CONSOLES]; +static signed char con2fb_map_boot[MAX_NR_CONSOLES]; + +static int logo_lines; +/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO + enums. */ +static int logo_shown = FBCON_LOGO_CANSHOW; +/* Software scrollback */ +static int fbcon_softback_size = 32768; +static unsigned long softback_buf, softback_curr; +static unsigned long softback_in; +static unsigned long softback_top, softback_end; +static int softback_lines; +/* console mappings */ +static int first_fb_vc; +static int last_fb_vc = MAX_NR_CONSOLES - 1; +static int fbcon_is_default = 1; +static int fbcon_has_exited; +static int primary_device = -1; +static int fbcon_has_console_bind; + +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY +static int map_override; + +static inline void fbcon_map_override(void) +{ + map_override = 1; +} +#else +static inline void fbcon_map_override(void) +{ +} +#endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */ + +/* font data */ +static char fontname[40]; + +/* current fb_info */ +static int info_idx = -1; + +/* console rotation */ +static int initial_rotation; +static int fbcon_has_sysfs; + +static const struct consw fb_con; + +#define CM_SOFTBACK (8) + +#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row) + +static int fbcon_set_origin(struct vc_data *); + +#define CURSOR_DRAW_DELAY (1) + +static int vbl_cursor_cnt; +static int fbcon_cursor_noblink; + +#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1) + +/* + * Interface used by the world + */ + +static const char *fbcon_startup(void); +static void fbcon_init(struct vc_data *vc, int init); +static void fbcon_deinit(struct vc_data *vc); +static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, + int width); +static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos); +static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, + int count, int ypos, int xpos); +static void fbcon_clear_margins(struct vc_data *vc, int bottom_only); +static void fbcon_cursor(struct vc_data *vc, int mode); +static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, + int count); +static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, + int height, int width); +static int fbcon_switch(struct vc_data *vc); +static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch); +static int fbcon_set_palette(struct vc_data *vc, unsigned char *table); +static int fbcon_scrolldelta(struct vc_data *vc, int lines); + +/* + * Internal routines + */ +static __inline__ void ywrap_up(struct vc_data *vc, int count); +static __inline__ void ywrap_down(struct vc_data *vc, int count); +static __inline__ void ypan_up(struct vc_data *vc, int count); +static __inline__ void ypan_down(struct vc_data *vc, int count); +static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx, + int dy, int dx, int height, int width, u_int y_break); +static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var, + int unit); +static void fbcon_redraw_move(struct vc_data *vc, struct display *p, + int line, int count, int dy); +static void fbcon_modechanged(struct fb_info *info); +static void fbcon_set_all_vcs(struct fb_info *info); +static void fbcon_start(void); +static void fbcon_exit(void); +static struct device *fbcon_device; + +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION +static inline void fbcon_set_rotation(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + if (!(info->flags & FBINFO_MISC_TILEBLITTING) && + ops->p->con_rotate < 4) + ops->rotate = ops->p->con_rotate; + else + ops->rotate = 0; +} + +static void fbcon_rotate(struct fb_info *info, u32 rotate) +{ + struct fbcon_ops *ops= info->fbcon_par; + struct fb_info *fb_info; + + if (!ops || ops->currcon == -1) + return; + + fb_info = registered_fb[con2fb_map[ops->currcon]]; + + if (info == fb_info) { + struct display *p = &fb_display[ops->currcon]; + + if (rotate < 4) + p->con_rotate = rotate; + else + p->con_rotate = 0; + + fbcon_modechanged(info); + } +} + +static void fbcon_rotate_all(struct fb_info *info, u32 rotate) +{ + struct fbcon_ops *ops = info->fbcon_par; + struct vc_data *vc; + struct display *p; + int i; + + if (!ops || ops->currcon < 0 || rotate > 3) + return; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + vc = vc_cons[i].d; + if (!vc || vc->vc_mode != KD_TEXT || + registered_fb[con2fb_map[i]] != info) + continue; + + p = &fb_display[vc->vc_num]; + p->con_rotate = rotate; + } + + fbcon_set_all_vcs(info); +} +#else +static inline void fbcon_set_rotation(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + ops->rotate = FB_ROTATE_UR; +} + +static void fbcon_rotate(struct fb_info *info, u32 rotate) +{ + return; +} + +static void fbcon_rotate_all(struct fb_info *info, u32 rotate) +{ + return; +} +#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */ + +static int fbcon_get_rotate(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + return (ops) ? ops->rotate : 0; +} + +static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + return (info->state != FBINFO_STATE_RUNNING || + vc->vc_mode != KD_TEXT || ops->graphics) && + !vt_force_oops_output(vc); +} + +static int get_color(struct vc_data *vc, struct fb_info *info, + u16 c, int is_fg) +{ + int depth = fb_get_color_depth(&info->var, &info->fix); + int color = 0; + + if (console_blanked) { + unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; + + c = vc->vc_video_erase_char & charmask; + } + + if (depth != 1) + color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c) + : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c); + + switch (depth) { + case 1: + { + int col = mono_col(info); + /* 0 or 1 */ + int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0; + int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col; + + if (console_blanked) + fg = bg; + + color = (is_fg) ? fg : bg; + break; + } + case 2: + /* + * Scale down 16-colors to 4 colors. Default 4-color palette + * is grayscale. However, simply dividing the values by 4 + * will not work, as colors 1, 2 and 3 will be scaled-down + * to zero rendering them invisible. So empirically convert + * colors to a sane 4-level grayscale. + */ + switch (color) { + case 0: + color = 0; /* black */ + break; + case 1 ... 6: + color = 2; /* white */ + break; + case 7 ... 8: + color = 1; /* gray */ + break; + default: + color = 3; /* intense white */ + break; + } + break; + case 3: + /* + * Last 8 entries of default 16-color palette is a more intense + * version of the first 8 (i.e., same chrominance, different + * luminance). + */ + color &= 7; + break; + } + + + return color; +} + +static void fbcon_update_softback(struct vc_data *vc) +{ + int l = fbcon_softback_size / vc->vc_size_row; + + if (l > 5) + softback_end = softback_buf + l * vc->vc_size_row; + else + /* Smaller scrollback makes no sense, and 0 would screw + the operation totally */ + softback_top = 0; +} + +static void fb_flashcursor(struct work_struct *work) +{ + struct fb_info *info = container_of(work, struct fb_info, queue); + struct fbcon_ops *ops = info->fbcon_par; + struct vc_data *vc = NULL; + int c; + int mode; + int ret; + + /* FIXME: we should sort out the unbind locking instead */ + /* instead we just fail to flash the cursor if we can't get + * the lock instead of blocking fbcon deinit */ + ret = console_trylock(); + if (ret == 0) + return; + + if (ops && ops->currcon != -1) + vc = vc_cons[ops->currcon].d; + + if (!vc || !CON_IS_VISIBLE(vc) || + registered_fb[con2fb_map[vc->vc_num]] != info || + vc->vc_deccm != 1) { + console_unlock(); + return; + } + + c = scr_readw((u16 *) vc->vc_pos); + mode = (!ops->cursor_flash || ops->cursor_state.enable) ? + CM_ERASE : CM_DRAW; + ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1), + get_color(vc, info, c, 0)); + console_unlock(); +} + +static void cursor_timer_handler(unsigned long dev_addr) +{ + struct fb_info *info = (struct fb_info *) dev_addr; + struct fbcon_ops *ops = info->fbcon_par; + + queue_work(system_power_efficient_wq, &info->queue); + mod_timer(&ops->cursor_timer, jiffies + HZ/5); +} + +static void fbcon_add_cursor_timer(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + if ((!info->queue.func || info->queue.func == fb_flashcursor) && + !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) && + !fbcon_cursor_noblink) { + if (!info->queue.func) + INIT_WORK(&info->queue, fb_flashcursor); + + init_timer(&ops->cursor_timer); + ops->cursor_timer.function = cursor_timer_handler; + ops->cursor_timer.expires = jiffies + HZ / 5; + ops->cursor_timer.data = (unsigned long ) info; + add_timer(&ops->cursor_timer); + ops->flags |= FBCON_FLAGS_CURSOR_TIMER; + } +} + +static void fbcon_del_cursor_timer(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + if (info->queue.func == fb_flashcursor && + ops->flags & FBCON_FLAGS_CURSOR_TIMER) { + del_timer_sync(&ops->cursor_timer); + ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER; + } +} + +#ifndef MODULE +static int __init fb_console_setup(char *this_opt) +{ + char *options; + int i, j; + + if (!this_opt || !*this_opt) + return 1; + + while ((options = strsep(&this_opt, ",")) != NULL) { + if (!strncmp(options, "font:", 5)) + strlcpy(fontname, options + 5, sizeof(fontname)); + + if (!strncmp(options, "scrollback:", 11)) { + options += 11; + if (*options) { + fbcon_softback_size = simple_strtoul(options, &options, 0); + if (*options == 'k' || *options == 'K') { + fbcon_softback_size *= 1024; + options++; + } + if (*options != ',') + return 1; + options++; + } else + return 1; + } + + if (!strncmp(options, "map:", 4)) { + options += 4; + if (*options) { + for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) { + if (!options[j]) + j = 0; + con2fb_map_boot[i] = + (options[j++]-'0') % FB_MAX; + } + + fbcon_map_override(); + } + + return 1; + } + + if (!strncmp(options, "vc:", 3)) { + options += 3; + if (*options) + first_fb_vc = simple_strtoul(options, &options, 10) - 1; + if (first_fb_vc < 0) + first_fb_vc = 0; + if (*options++ == '-') + last_fb_vc = simple_strtoul(options, &options, 10) - 1; + fbcon_is_default = 0; + } + + if (!strncmp(options, "rotate:", 7)) { + options += 7; + if (*options) + initial_rotation = simple_strtoul(options, &options, 0); + if (initial_rotation > 3) + initial_rotation = 0; + } + } + return 1; +} + +__setup("fbcon=", fb_console_setup); +#endif + +static int search_fb_in_map(int idx) +{ + int i, retval = 0; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] == idx) + retval = 1; + } + return retval; +} + +static int search_for_mapped_con(void) +{ + int i, retval = 0; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] != -1) + retval = 1; + } + return retval; +} + +static int do_fbcon_takeover(int show_logo) +{ + int err, i; + + if (!num_registered_fb) + return -ENODEV; + + if (!show_logo) + logo_shown = FBCON_LOGO_DONTSHOW; + + for (i = first_fb_vc; i <= last_fb_vc; i++) + con2fb_map[i] = info_idx; + + err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc, + fbcon_is_default); + + if (err) { + for (i = first_fb_vc; i <= last_fb_vc; i++) + con2fb_map[i] = -1; + info_idx = -1; + } else { + fbcon_has_console_bind = 1; + } + + return err; +} + +#ifdef MODULE +static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, + int cols, int rows, int new_cols, int new_rows) +{ + logo_shown = FBCON_LOGO_DONTSHOW; +} +#else +static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, + int cols, int rows, int new_cols, int new_rows) +{ + /* Need to make room for the logo */ + struct fbcon_ops *ops = info->fbcon_par; + int cnt, erase = vc->vc_video_erase_char, step; + unsigned short *save = NULL, *r, *q; + int logo_height; + + if (info->flags & FBINFO_MODULE) { + logo_shown = FBCON_LOGO_DONTSHOW; + return; + } + + /* + * remove underline attribute from erase character + * if black and white framebuffer. + */ + if (fb_get_color_depth(&info->var, &info->fix) == 1) + erase &= ~0x400; + logo_height = fb_prepare_logo(info, ops->rotate); + logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height); + q = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * rows); + step = logo_lines * cols; + for (r = q - logo_lines * cols; r < q; r++) + if (scr_readw(r) != vc->vc_video_erase_char) + break; + if (r != q && new_rows >= rows + logo_lines) { + save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL); + if (save) { + int i = cols < new_cols ? cols : new_cols; + scr_memsetw(save, erase, logo_lines * new_cols * 2); + r = q - step; + for (cnt = 0; cnt < logo_lines; cnt++, r += i) + scr_memcpyw(save + cnt * new_cols, r, 2 * i); + r = q; + } + } + if (r == q) { + /* We can scroll screen down */ + r = q - step - cols; + for (cnt = rows - logo_lines; cnt > 0; cnt--) { + scr_memcpyw(r + step, r, vc->vc_size_row); + r -= cols; + } + if (!save) { + int lines; + if (vc->vc_y + logo_lines >= rows) + lines = rows - vc->vc_y - 1; + else + lines = logo_lines; + vc->vc_y += lines; + vc->vc_pos += lines * vc->vc_size_row; + } + } + scr_memsetw((unsigned short *) vc->vc_origin, + erase, + vc->vc_size_row * logo_lines); + + if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) { + fbcon_clear_margins(vc, 0); + update_screen(vc); + } + + if (save) { + q = (unsigned short *) (vc->vc_origin + + vc->vc_size_row * + rows); + scr_memcpyw(q, save, logo_lines * new_cols * 2); + vc->vc_y += logo_lines; + vc->vc_pos += logo_lines * vc->vc_size_row; + kfree(save); + } + + if (logo_lines > vc->vc_bottom) { + logo_shown = FBCON_LOGO_CANSHOW; + printk(KERN_INFO + "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n"); + } else if (logo_shown != FBCON_LOGO_DONTSHOW) { + logo_shown = FBCON_LOGO_DRAW; + vc->vc_top = logo_lines; + } +} +#endif /* MODULE */ + +#ifdef CONFIG_FB_TILEBLITTING +static void set_blitting_type(struct vc_data *vc, struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + ops->p = &fb_display[vc->vc_num]; + + if ((info->flags & FBINFO_MISC_TILEBLITTING)) + fbcon_set_tileops(vc, info); + else { + fbcon_set_rotation(info); + fbcon_set_bitops(ops); + } +} + +static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount) +{ + int err = 0; + + if (info->flags & FBINFO_MISC_TILEBLITTING && + info->tileops->fb_get_tilemax(info) < charcount) + err = 1; + + return err; +} +#else +static void set_blitting_type(struct vc_data *vc, struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + + info->flags &= ~FBINFO_MISC_TILEBLITTING; + ops->p = &fb_display[vc->vc_num]; + fbcon_set_rotation(info); + fbcon_set_bitops(ops); +} + +static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount) +{ + return 0; +} + +#endif /* CONFIG_MISC_TILEBLITTING */ + + +static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info, + int unit, int oldidx) +{ + struct fbcon_ops *ops = NULL; + int err = 0; + + if (!try_module_get(info->fbops->owner)) + err = -ENODEV; + + if (!err && info->fbops->fb_open && + info->fbops->fb_open(info, 0)) + err = -ENODEV; + + if (!err) { + ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); + if (!ops) + err = -ENOMEM; + } + + if (!err) { + info->fbcon_par = ops; + + if (vc) + set_blitting_type(vc, info); + } + + if (err) { + con2fb_map[unit] = oldidx; + module_put(info->fbops->owner); + } + + return err; +} + +static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo, + struct fb_info *newinfo, int unit, + int oldidx, int found) +{ + struct fbcon_ops *ops = oldinfo->fbcon_par; + int err = 0, ret; + + if (oldinfo->fbops->fb_release && + oldinfo->fbops->fb_release(oldinfo, 0)) { + con2fb_map[unit] = oldidx; + if (!found && newinfo->fbops->fb_release) + newinfo->fbops->fb_release(newinfo, 0); + if (!found) + module_put(newinfo->fbops->owner); + err = -ENODEV; + } + + if (!err) { + fbcon_del_cursor_timer(oldinfo); + kfree(ops->cursor_state.mask); + kfree(ops->cursor_data); + kfree(ops->fontbuffer); + kfree(oldinfo->fbcon_par); + oldinfo->fbcon_par = NULL; + module_put(oldinfo->fbops->owner); + /* + If oldinfo and newinfo are driving the same hardware, + the fb_release() method of oldinfo may attempt to + restore the hardware state. This will leave the + newinfo in an undefined state. Thus, a call to + fb_set_par() may be needed for the newinfo. + */ + if (newinfo && newinfo->fbops->fb_set_par) { + ret = newinfo->fbops->fb_set_par(newinfo); + + if (ret) + printk(KERN_ERR "con2fb_release_oldinfo: " + "detected unhandled fb_set_par error, " + "error code %d\n", ret); + } + } + + return err; +} + +static void con2fb_init_display(struct vc_data *vc, struct fb_info *info, + int unit, int show_logo) +{ + struct fbcon_ops *ops = info->fbcon_par; + int ret; + + ops->currcon = fg_console; + + if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) { + ret = info->fbops->fb_set_par(info); + + if (ret) + printk(KERN_ERR "con2fb_init_display: detected " + "unhandled fb_set_par error, " + "error code %d\n", ret); + } + + ops->flags |= FBCON_FLAGS_INIT; + ops->graphics = 0; + fbcon_set_disp(info, &info->var, unit); + + if (show_logo) { + struct vc_data *fg_vc = vc_cons[fg_console].d; + struct fb_info *fg_info = + registered_fb[con2fb_map[fg_console]]; + + fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols, + fg_vc->vc_rows, fg_vc->vc_cols, + fg_vc->vc_rows); + } + + update_screen(vc_cons[fg_console].d); +} + +/** + * set_con2fb_map - map console to frame buffer device + * @unit: virtual console number to map + * @newidx: frame buffer index to map virtual console to + * @user: user request + * + * Maps a virtual console @unit to a frame buffer device + * @newidx. + * + * This should be called with the console lock held. + */ +static int set_con2fb_map(int unit, int newidx, int user) +{ + struct vc_data *vc = vc_cons[unit].d; + int oldidx = con2fb_map[unit]; + struct fb_info *info = registered_fb[newidx]; + struct fb_info *oldinfo = NULL; + int found, err = 0; + + if (oldidx == newidx) + return 0; + + if (!info) + return -EINVAL; + + if (!search_for_mapped_con() || !con_is_bound(&fb_con)) { + info_idx = newidx; + return do_fbcon_takeover(0); + } + + if (oldidx != -1) + oldinfo = registered_fb[oldidx]; + + found = search_fb_in_map(newidx); + + con2fb_map[unit] = newidx; + if (!err && !found) + err = con2fb_acquire_newinfo(vc, info, unit, oldidx); + + + /* + * If old fb is not mapped to any of the consoles, + * fbcon should release it. + */ + if (!err && oldinfo && !search_fb_in_map(oldidx)) + err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx, + found); + + if (!err) { + int show_logo = (fg_console == 0 && !user && + logo_shown != FBCON_LOGO_DONTSHOW); + + if (!found) + fbcon_add_cursor_timer(info); + con2fb_map_boot[unit] = newidx; + con2fb_init_display(vc, info, unit, show_logo); + } + + if (!search_fb_in_map(info_idx)) + info_idx = newidx; + + return err; +} + +/* + * Low Level Operations + */ +/* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */ +static int var_to_display(struct display *disp, + struct fb_var_screeninfo *var, + struct fb_info *info) +{ + disp->xres_virtual = var->xres_virtual; + disp->yres_virtual = var->yres_virtual; + disp->bits_per_pixel = var->bits_per_pixel; + disp->grayscale = var->grayscale; + disp->nonstd = var->nonstd; + disp->accel_flags = var->accel_flags; + disp->height = var->height; + disp->width = var->width; + disp->red = var->red; + disp->green = var->green; + disp->blue = var->blue; + disp->transp = var->transp; + disp->rotate = var->rotate; + disp->mode = fb_match_mode(var, &info->modelist); + if (disp->mode == NULL) + /* This should not happen */ + return -EINVAL; + return 0; +} + +static void display_to_var(struct fb_var_screeninfo *var, + struct display *disp) +{ + fb_videomode_to_var(var, disp->mode); + var->xres_virtual = disp->xres_virtual; + var->yres_virtual = disp->yres_virtual; + var->bits_per_pixel = disp->bits_per_pixel; + var->grayscale = disp->grayscale; + var->nonstd = disp->nonstd; + var->accel_flags = disp->accel_flags; + var->height = disp->height; + var->width = disp->width; + var->red = disp->red; + var->green = disp->green; + var->blue = disp->blue; + var->transp = disp->transp; + var->rotate = disp->rotate; +} + +static const char *fbcon_startup(void) +{ + const char *display_desc = "frame buffer device"; + struct display *p = &fb_display[fg_console]; + struct vc_data *vc = vc_cons[fg_console].d; + const struct font_desc *font = NULL; + struct module *owner; + struct fb_info *info = NULL; + struct fbcon_ops *ops; + int rows, cols; + + /* + * If num_registered_fb is zero, this is a call for the dummy part. + * The frame buffer devices weren't initialized yet. + */ + if (!num_registered_fb || info_idx == -1) + return display_desc; + /* + * Instead of blindly using registered_fb[0], we use info_idx, set by + * fb_console_init(); + */ + info = registered_fb[info_idx]; + if (!info) + return NULL; + + owner = info->fbops->owner; + if (!try_module_get(owner)) + return NULL; + if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) { + module_put(owner); + return NULL; + } + + ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); + if (!ops) { + module_put(owner); + return NULL; + } + + ops->currcon = -1; + ops->graphics = 1; + ops->cur_rotate = -1; + info->fbcon_par = ops; + p->con_rotate = initial_rotation; + set_blitting_type(vc, info); + + if (info->fix.type != FB_TYPE_TEXT) { + if (fbcon_softback_size) { + if (!softback_buf) { + softback_buf = + (unsigned long) + kmalloc(fbcon_softback_size, + GFP_KERNEL); + if (!softback_buf) { + fbcon_softback_size = 0; + softback_top = 0; + } + } + } else { + if (softback_buf) { + kfree((void *) softback_buf); + softback_buf = 0; + softback_top = 0; + } + } + if (softback_buf) + softback_in = softback_top = softback_curr = + softback_buf; + softback_lines = 0; + } + + /* Setup default font */ + if (!p->fontdata && !vc->vc_font.data) { + if (!fontname[0] || !(font = find_font(fontname))) + font = get_default_font(info->var.xres, + info->var.yres, + info->pixmap.blit_x, + info->pixmap.blit_y); + vc->vc_font.width = font->width; + vc->vc_font.height = font->height; + vc->vc_font.data = (void *)(p->fontdata = font->data); + vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */ + } else { + p->fontdata = vc->vc_font.data; + } + + cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); + rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + cols /= vc->vc_font.width; + rows /= vc->vc_font.height; + vc_resize(vc, cols, rows); + + DPRINTK("mode: %s\n", info->fix.id); + DPRINTK("visual: %d\n", info->fix.visual); + DPRINTK("res: %dx%d-%d\n", info->var.xres, + info->var.yres, + info->var.bits_per_pixel); + + fbcon_add_cursor_timer(info); + fbcon_has_exited = 0; + return display_desc; +} + +static void fbcon_init(struct vc_data *vc, int init) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops; + struct vc_data **default_mode = vc->vc_display_fg; + struct vc_data *svc = *default_mode; + struct display *t, *p = &fb_display[vc->vc_num]; + int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256; + int cap, ret; + + if (info_idx == -1 || info == NULL) + return; + + cap = info->flags; + + if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW || + (info->fix.type == FB_TYPE_TEXT)) + logo = 0; + + if (var_to_display(p, &info->var, info)) + return; + + if (!info->fbcon_par) + con2fb_acquire_newinfo(vc, info, vc->vc_num, -1); + + /* If we are not the first console on this + fb, copy the font from that console */ + t = &fb_display[fg_console]; + if (!p->fontdata) { + if (t->fontdata) { + struct vc_data *fvc = vc_cons[fg_console].d; + + vc->vc_font.data = (void *)(p->fontdata = + fvc->vc_font.data); + vc->vc_font.width = fvc->vc_font.width; + vc->vc_font.height = fvc->vc_font.height; + p->userfont = t->userfont; + + if (p->userfont) + REFCOUNT(p->fontdata)++; + } else { + const struct font_desc *font = NULL; + + if (!fontname[0] || !(font = find_font(fontname))) + font = get_default_font(info->var.xres, + info->var.yres, + info->pixmap.blit_x, + info->pixmap.blit_y); + vc->vc_font.width = font->width; + vc->vc_font.height = font->height; + vc->vc_font.data = (void *)(p->fontdata = font->data); + vc->vc_font.charcount = 256; /* FIXME Need to + support more fonts */ + } + } + + if (p->userfont) + charcnt = FNTCHARCNT(p->fontdata); + + vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT); + vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); + vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; + if (charcnt == 256) { + vc->vc_hi_font_mask = 0; + } else { + vc->vc_hi_font_mask = 0x100; + if (vc->vc_can_do_color) + vc->vc_complement_mask <<= 1; + } + + if (!*svc->vc_uni_pagedir_loc) + con_set_default_unimap(svc); + if (!*vc->vc_uni_pagedir_loc) + con_copy_unimap(vc, svc); + + ops = info->fbcon_par; + p->con_rotate = initial_rotation; + set_blitting_type(vc, info); + + cols = vc->vc_cols; + rows = vc->vc_rows; + new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); + new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + new_cols /= vc->vc_font.width; + new_rows /= vc->vc_font.height; + + /* + * We must always set the mode. The mode of the previous console + * driver could be in the same resolution but we are using different + * hardware so we have to initialize the hardware. + * + * We need to do it in fbcon_init() to prevent screen corruption. + */ + if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) { + if (info->fbops->fb_set_par && + !(ops->flags & FBCON_FLAGS_INIT)) { + ret = info->fbops->fb_set_par(info); + + if (ret) + printk(KERN_ERR "fbcon_init: detected " + "unhandled fb_set_par error, " + "error code %d\n", ret); + } + + ops->flags |= FBCON_FLAGS_INIT; + } + + ops->graphics = 0; + + if ((cap & FBINFO_HWACCEL_COPYAREA) && + !(cap & FBINFO_HWACCEL_DISABLED)) + p->scrollmode = SCROLL_MOVE; + else /* default to something safe */ + p->scrollmode = SCROLL_REDRAW; + + /* + * ++guenther: console.c:vc_allocate() relies on initializing + * vc_{cols,rows}, but we must not set those if we are only + * resizing the console. + */ + if (init) { + vc->vc_cols = new_cols; + vc->vc_rows = new_rows; + } else + vc_resize(vc, new_cols, new_rows); + + if (logo) + fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows); + + if (vc == svc && softback_buf) + fbcon_update_softback(vc); + + if (ops->rotate_font && ops->rotate_font(info, vc)) { + ops->rotate = FB_ROTATE_UR; + set_blitting_type(vc, info); + } + + ops->p = &fb_display[fg_console]; +} + +static void fbcon_free_font(struct display *p, bool freefont) +{ + if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0)) + kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int)); + p->fontdata = NULL; + p->userfont = 0; +} + +static void fbcon_deinit(struct vc_data *vc) +{ + struct display *p = &fb_display[vc->vc_num]; + struct fb_info *info; + struct fbcon_ops *ops; + int idx; + bool free_font = true; + + idx = con2fb_map[vc->vc_num]; + + if (idx == -1) + goto finished; + + info = registered_fb[idx]; + + if (!info) + goto finished; + + if (info->flags & FBINFO_MISC_FIRMWARE) + free_font = false; + ops = info->fbcon_par; + + if (!ops) + goto finished; + + if (CON_IS_VISIBLE(vc)) + fbcon_del_cursor_timer(info); + + ops->flags &= ~FBCON_FLAGS_INIT; +finished: + + fbcon_free_font(p, free_font); + if (free_font) + vc->vc_font.data = NULL; + + if (!con_is_bound(&fb_con)) + fbcon_exit(); + + return; +} + +/* ====================================================================== */ + +/* fbcon_XXX routines - interface used by the world + * + * This system is now divided into two levels because of complications + * caused by hardware scrolling. Top level functions: + * + * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins() + * + * handles y values in range [0, scr_height-1] that correspond to real + * screen positions. y_wrap shift means that first line of bitmap may be + * anywhere on this display. These functions convert lineoffsets to + * bitmap offsets and deal with the wrap-around case by splitting blits. + * + * fbcon_bmove_physical_8() -- These functions fast implementations + * fbcon_clear_physical_8() -- of original fbcon_XXX fns. + * fbcon_putc_physical_8() -- (font width != 8) may be added later + * + * WARNING: + * + * At the moment fbcon_putc() cannot blit across vertical wrap boundary + * Implies should only really hardware scroll in rows. Only reason for + * restriction is simplicity & efficiency at the moment. + */ + +static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, + int width) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + + struct display *p = &fb_display[vc->vc_num]; + u_int y_break; + + if (fbcon_is_inactive(vc, info)) + return; + + if (!height || !width) + return; + + if (sy < vc->vc_top && vc->vc_top == logo_lines) { + vc->vc_top = 0; + /* + * If the font dimensions are not an integral of the display + * dimensions then the ops->clear below won't end up clearing + * the margins. Call clear_margins here in case the logo + * bitmap stretched into the margin area. + */ + fbcon_clear_margins(vc, 0); + } + + /* Split blits that cross physical y_wrap boundary */ + + y_break = p->vrows - p->yscroll; + if (sy < y_break && sy + height - 1 >= y_break) { + u_int b = y_break - sy; + ops->clear(vc, info, real_y(p, sy), sx, b, width); + ops->clear(vc, info, real_y(p, sy + b), sx, height - b, + width); + } else + ops->clear(vc, info, real_y(p, sy), sx, height, width); +} + +static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, + int count, int ypos, int xpos) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct display *p = &fb_display[vc->vc_num]; + struct fbcon_ops *ops = info->fbcon_par; + + if (!fbcon_is_inactive(vc, info)) + ops->putcs(vc, info, s, count, real_y(p, ypos), xpos, + get_color(vc, info, scr_readw(s), 1), + get_color(vc, info, scr_readw(s), 0)); +} + +static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos) +{ + unsigned short chr; + + scr_writew(c, &chr); + fbcon_putcs(vc, &chr, 1, ypos, xpos); +} + +static void fbcon_clear_margins(struct vc_data *vc, int bottom_only) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + + if (!fbcon_is_inactive(vc, info)) + ops->clear_margins(vc, info, bottom_only); +} + +static void fbcon_cursor(struct vc_data *vc, int mode) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + int y; + int c = scr_readw((u16 *) vc->vc_pos); + + if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1) + return; + + if (vc->vc_cursor_type & 0x10) + fbcon_del_cursor_timer(info); + else + fbcon_add_cursor_timer(info); + + ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1; + if (mode & CM_SOFTBACK) { + mode &= ~CM_SOFTBACK; + y = softback_lines; + } else { + if (softback_lines) + fbcon_set_origin(vc); + y = 0; + } + + ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1), + get_color(vc, info, c, 0)); + vbl_cursor_cnt = CURSOR_DRAW_DELAY; +} + +static int scrollback_phys_max = 0; +static int scrollback_max = 0; +static int scrollback_current = 0; + +static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var, + int unit) +{ + struct display *p, *t; + struct vc_data **default_mode, *vc; + struct vc_data *svc; + struct fbcon_ops *ops = info->fbcon_par; + int rows, cols, charcnt = 256; + + p = &fb_display[unit]; + + if (var_to_display(p, var, info)) + return; + + vc = vc_cons[unit].d; + + if (!vc) + return; + + default_mode = vc->vc_display_fg; + svc = *default_mode; + t = &fb_display[svc->vc_num]; + + if (!vc->vc_font.data) { + vc->vc_font.data = (void *)(p->fontdata = t->fontdata); + vc->vc_font.width = (*default_mode)->vc_font.width; + vc->vc_font.height = (*default_mode)->vc_font.height; + p->userfont = t->userfont; + if (p->userfont) + REFCOUNT(p->fontdata)++; + } + if (p->userfont) + charcnt = FNTCHARCNT(p->fontdata); + + var->activate = FB_ACTIVATE_NOW; + info->var.activate = var->activate; + var->yoffset = info->var.yoffset; + var->xoffset = info->var.xoffset; + fb_set_var(info, var); + ops->var = info->var; + vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); + vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; + if (charcnt == 256) { + vc->vc_hi_font_mask = 0; + } else { + vc->vc_hi_font_mask = 0x100; + if (vc->vc_can_do_color) + vc->vc_complement_mask <<= 1; + } + + if (!*svc->vc_uni_pagedir_loc) + con_set_default_unimap(svc); + if (!*vc->vc_uni_pagedir_loc) + con_copy_unimap(vc, svc); + + cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); + rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + cols /= vc->vc_font.width; + rows /= vc->vc_font.height; + vc_resize(vc, cols, rows); + + if (CON_IS_VISIBLE(vc)) { + update_screen(vc); + if (softback_buf) + fbcon_update_softback(vc); + } +} + +static __inline__ void ywrap_up(struct vc_data *vc, int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *p = &fb_display[vc->vc_num]; + + p->yscroll += count; + if (p->yscroll >= p->vrows) /* Deal with wrap */ + p->yscroll -= p->vrows; + ops->var.xoffset = 0; + ops->var.yoffset = p->yscroll * vc->vc_font.height; + ops->var.vmode |= FB_VMODE_YWRAP; + ops->update_start(info); + scrollback_max += count; + if (scrollback_max > scrollback_phys_max) + scrollback_max = scrollback_phys_max; + scrollback_current = 0; +} + +static __inline__ void ywrap_down(struct vc_data *vc, int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *p = &fb_display[vc->vc_num]; + + p->yscroll -= count; + if (p->yscroll < 0) /* Deal with wrap */ + p->yscroll += p->vrows; + ops->var.xoffset = 0; + ops->var.yoffset = p->yscroll * vc->vc_font.height; + ops->var.vmode |= FB_VMODE_YWRAP; + ops->update_start(info); + scrollback_max -= count; + if (scrollback_max < 0) + scrollback_max = 0; + scrollback_current = 0; +} + +static __inline__ void ypan_up(struct vc_data *vc, int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct display *p = &fb_display[vc->vc_num]; + struct fbcon_ops *ops = info->fbcon_par; + + p->yscroll += count; + if (p->yscroll > p->vrows - vc->vc_rows) { + ops->bmove(vc, info, p->vrows - vc->vc_rows, + 0, 0, 0, vc->vc_rows, vc->vc_cols); + p->yscroll -= p->vrows - vc->vc_rows; + } + + ops->var.xoffset = 0; + ops->var.yoffset = p->yscroll * vc->vc_font.height; + ops->var.vmode &= ~FB_VMODE_YWRAP; + ops->update_start(info); + fbcon_clear_margins(vc, 1); + scrollback_max += count; + if (scrollback_max > scrollback_phys_max) + scrollback_max = scrollback_phys_max; + scrollback_current = 0; +} + +static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *p = &fb_display[vc->vc_num]; + + p->yscroll += count; + + if (p->yscroll > p->vrows - vc->vc_rows) { + p->yscroll -= p->vrows - vc->vc_rows; + fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t); + } + + ops->var.xoffset = 0; + ops->var.yoffset = p->yscroll * vc->vc_font.height; + ops->var.vmode &= ~FB_VMODE_YWRAP; + ops->update_start(info); + fbcon_clear_margins(vc, 1); + scrollback_max += count; + if (scrollback_max > scrollback_phys_max) + scrollback_max = scrollback_phys_max; + scrollback_current = 0; +} + +static __inline__ void ypan_down(struct vc_data *vc, int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct display *p = &fb_display[vc->vc_num]; + struct fbcon_ops *ops = info->fbcon_par; + + p->yscroll -= count; + if (p->yscroll < 0) { + ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows, + 0, vc->vc_rows, vc->vc_cols); + p->yscroll += p->vrows - vc->vc_rows; + } + + ops->var.xoffset = 0; + ops->var.yoffset = p->yscroll * vc->vc_font.height; + ops->var.vmode &= ~FB_VMODE_YWRAP; + ops->update_start(info); + fbcon_clear_margins(vc, 1); + scrollback_max -= count; + if (scrollback_max < 0) + scrollback_max = 0; + scrollback_current = 0; +} + +static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *p = &fb_display[vc->vc_num]; + + p->yscroll -= count; + + if (p->yscroll < 0) { + p->yscroll += p->vrows - vc->vc_rows; + fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count); + } + + ops->var.xoffset = 0; + ops->var.yoffset = p->yscroll * vc->vc_font.height; + ops->var.vmode &= ~FB_VMODE_YWRAP; + ops->update_start(info); + fbcon_clear_margins(vc, 1); + scrollback_max -= count; + if (scrollback_max < 0) + scrollback_max = 0; + scrollback_current = 0; +} + +static void fbcon_redraw_softback(struct vc_data *vc, struct display *p, + long delta) +{ + int count = vc->vc_rows; + unsigned short *d, *s; + unsigned long n; + int line = 0; + + d = (u16 *) softback_curr; + if (d == (u16 *) softback_in) + d = (u16 *) vc->vc_origin; + n = softback_curr + delta * vc->vc_size_row; + softback_lines -= delta; + if (delta < 0) { + if (softback_curr < softback_top && n < softback_buf) { + n += softback_end - softback_buf; + if (n < softback_top) { + softback_lines -= + (softback_top - n) / vc->vc_size_row; + n = softback_top; + } + } else if (softback_curr >= softback_top + && n < softback_top) { + softback_lines -= + (softback_top - n) / vc->vc_size_row; + n = softback_top; + } + } else { + if (softback_curr > softback_in && n >= softback_end) { + n += softback_buf - softback_end; + if (n > softback_in) { + n = softback_in; + softback_lines = 0; + } + } else if (softback_curr <= softback_in && n > softback_in) { + n = softback_in; + softback_lines = 0; + } + } + if (n == softback_curr) + return; + softback_curr = n; + s = (u16 *) softback_curr; + if (s == (u16 *) softback_in) + s = (u16 *) vc->vc_origin; + while (count--) { + unsigned short *start; + unsigned short *le; + unsigned short c; + int x = 0; + unsigned short attr = 1; + + start = s; + le = advance_row(s, 1); + do { + c = scr_readw(s); + if (attr != (c & 0xff00)) { + attr = c & 0xff00; + if (s > start) { + fbcon_putcs(vc, start, s - start, + line, x); + x += s - start; + start = s; + } + } + if (c == scr_readw(d)) { + if (s > start) { + fbcon_putcs(vc, start, s - start, + line, x); + x += s - start + 1; + start = s + 1; + } else { + x++; + start++; + } + } + s++; + d++; + } while (s < le); + if (s > start) + fbcon_putcs(vc, start, s - start, line, x); + line++; + if (d == (u16 *) softback_end) + d = (u16 *) softback_buf; + if (d == (u16 *) softback_in) + d = (u16 *) vc->vc_origin; + if (s == (u16 *) softback_end) + s = (u16 *) softback_buf; + if (s == (u16 *) softback_in) + s = (u16 *) vc->vc_origin; + } +} + +static void fbcon_redraw_move(struct vc_data *vc, struct display *p, + int line, int count, int dy) +{ + unsigned short *s = (unsigned short *) + (vc->vc_origin + vc->vc_size_row * line); + + while (count--) { + unsigned short *start = s; + unsigned short *le = advance_row(s, 1); + unsigned short c; + int x = 0; + unsigned short attr = 1; + + do { + c = scr_readw(s); + if (attr != (c & 0xff00)) { + attr = c & 0xff00; + if (s > start) { + fbcon_putcs(vc, start, s - start, + dy, x); + x += s - start; + start = s; + } + } + console_conditional_schedule(); + s++; + } while (s < le); + if (s > start) + fbcon_putcs(vc, start, s - start, dy, x); + console_conditional_schedule(); + dy++; + } +} + +static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info, + struct display *p, int line, int count, int ycount) +{ + int offset = ycount * vc->vc_cols; + unsigned short *d = (unsigned short *) + (vc->vc_origin + vc->vc_size_row * line); + unsigned short *s = d + offset; + struct fbcon_ops *ops = info->fbcon_par; + + while (count--) { + unsigned short *start = s; + unsigned short *le = advance_row(s, 1); + unsigned short c; + int x = 0; + + do { + c = scr_readw(s); + + if (c == scr_readw(d)) { + if (s > start) { + ops->bmove(vc, info, line + ycount, x, + line, x, 1, s-start); + x += s - start + 1; + start = s + 1; + } else { + x++; + start++; + } + } + + scr_writew(c, d); + console_conditional_schedule(); + s++; + d++; + } while (s < le); + if (s > start) + ops->bmove(vc, info, line + ycount, x, line, x, 1, + s-start); + console_conditional_schedule(); + if (ycount > 0) + line++; + else { + line--; + /* NOTE: We subtract two lines from these pointers */ + s -= vc->vc_size_row; + d -= vc->vc_size_row; + } + } +} + +static void fbcon_redraw(struct vc_data *vc, struct display *p, + int line, int count, int offset) +{ + unsigned short *d = (unsigned short *) + (vc->vc_origin + vc->vc_size_row * line); + unsigned short *s = d + offset; + + while (count--) { + unsigned short *start = s; + unsigned short *le = advance_row(s, 1); + unsigned short c; + int x = 0; + unsigned short attr = 1; + + do { + c = scr_readw(s); + if (attr != (c & 0xff00)) { + attr = c & 0xff00; + if (s > start) { + fbcon_putcs(vc, start, s - start, + line, x); + x += s - start; + start = s; + } + } + if (c == scr_readw(d)) { + if (s > start) { + fbcon_putcs(vc, start, s - start, + line, x); + x += s - start + 1; + start = s + 1; + } else { + x++; + start++; + } + } + scr_writew(c, d); + console_conditional_schedule(); + s++; + d++; + } while (s < le); + if (s > start) + fbcon_putcs(vc, start, s - start, line, x); + console_conditional_schedule(); + if (offset > 0) + line++; + else { + line--; + /* NOTE: We subtract two lines from these pointers */ + s -= vc->vc_size_row; + d -= vc->vc_size_row; + } + } +} + +static inline void fbcon_softback_note(struct vc_data *vc, int t, + int count) +{ + unsigned short *p; + + if (vc->vc_num != fg_console) + return; + p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row); + + while (count) { + scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row); + count--; + p = advance_row(p, 1); + softback_in += vc->vc_size_row; + if (softback_in == softback_end) + softback_in = softback_buf; + if (softback_in == softback_top) { + softback_top += vc->vc_size_row; + if (softback_top == softback_end) + softback_top = softback_buf; + } + } + softback_curr = softback_in; +} + +static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, + int count) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct display *p = &fb_display[vc->vc_num]; + int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK; + + if (fbcon_is_inactive(vc, info)) + return -EINVAL; + + fbcon_cursor(vc, CM_ERASE); + + /* + * ++Geert: Only use ywrap/ypan if the console is in text mode + * ++Andrew: Only use ypan on hardware text mode when scrolling the + * whole screen (prevents flicker). + */ + + switch (dir) { + case SM_UP: + if (count > vc->vc_rows) /* Maximum realistic size */ + count = vc->vc_rows; + if (softback_top) + fbcon_softback_note(vc, t, count); + if (logo_shown >= 0) + goto redraw_up; + switch (p->scrollmode) { + case SCROLL_MOVE: + fbcon_redraw_blit(vc, info, p, t, b - t - count, + count); + fbcon_clear(vc, b - count, 0, count, vc->vc_cols); + scr_memsetw((unsigned short *) (vc->vc_origin + + vc->vc_size_row * + (b - count)), + vc->vc_video_erase_char, + vc->vc_size_row * count); + return 1; + break; + + case SCROLL_WRAP_MOVE: + if (b - t - count > 3 * vc->vc_rows >> 2) { + if (t > 0) + fbcon_bmove(vc, 0, 0, count, 0, t, + vc->vc_cols); + ywrap_up(vc, count); + if (vc->vc_rows - b > 0) + fbcon_bmove(vc, b - count, 0, b, 0, + vc->vc_rows - b, + vc->vc_cols); + } else if (info->flags & FBINFO_READS_FAST) + fbcon_bmove(vc, t + count, 0, t, 0, + b - t - count, vc->vc_cols); + else + goto redraw_up; + fbcon_clear(vc, b - count, 0, count, vc->vc_cols); + break; + + case SCROLL_PAN_REDRAW: + if ((p->yscroll + count <= + 2 * (p->vrows - vc->vc_rows)) + && ((!scroll_partial && (b - t == vc->vc_rows)) + || (scroll_partial + && (b - t - count > + 3 * vc->vc_rows >> 2)))) { + if (t > 0) + fbcon_redraw_move(vc, p, 0, t, count); + ypan_up_redraw(vc, t, count); + if (vc->vc_rows - b > 0) + fbcon_redraw_move(vc, p, b, + vc->vc_rows - b, b); + } else + fbcon_redraw_move(vc, p, t + count, b - t - count, t); + fbcon_clear(vc, b - count, 0, count, vc->vc_cols); + break; + + case SCROLL_PAN_MOVE: + if ((p->yscroll + count <= + 2 * (p->vrows - vc->vc_rows)) + && ((!scroll_partial && (b - t == vc->vc_rows)) + || (scroll_partial + && (b - t - count > + 3 * vc->vc_rows >> 2)))) { + if (t > 0) + fbcon_bmove(vc, 0, 0, count, 0, t, + vc->vc_cols); + ypan_up(vc, count); + if (vc->vc_rows - b > 0) + fbcon_bmove(vc, b - count, 0, b, 0, + vc->vc_rows - b, + vc->vc_cols); + } else if (info->flags & FBINFO_READS_FAST) + fbcon_bmove(vc, t + count, 0, t, 0, + b - t - count, vc->vc_cols); + else + goto redraw_up; + fbcon_clear(vc, b - count, 0, count, vc->vc_cols); + break; + + case SCROLL_REDRAW: + redraw_up: + fbcon_redraw(vc, p, t, b - t - count, + count * vc->vc_cols); + fbcon_clear(vc, b - count, 0, count, vc->vc_cols); + scr_memsetw((unsigned short *) (vc->vc_origin + + vc->vc_size_row * + (b - count)), + vc->vc_video_erase_char, + vc->vc_size_row * count); + return 1; + } + break; + + case SM_DOWN: + if (count > vc->vc_rows) /* Maximum realistic size */ + count = vc->vc_rows; + if (logo_shown >= 0) + goto redraw_down; + switch (p->scrollmode) { + case SCROLL_MOVE: + fbcon_redraw_blit(vc, info, p, b - 1, b - t - count, + -count); + fbcon_clear(vc, t, 0, count, vc->vc_cols); + scr_memsetw((unsigned short *) (vc->vc_origin + + vc->vc_size_row * + t), + vc->vc_video_erase_char, + vc->vc_size_row * count); + return 1; + break; + + case SCROLL_WRAP_MOVE: + if (b - t - count > 3 * vc->vc_rows >> 2) { + if (vc->vc_rows - b > 0) + fbcon_bmove(vc, b, 0, b - count, 0, + vc->vc_rows - b, + vc->vc_cols); + ywrap_down(vc, count); + if (t > 0) + fbcon_bmove(vc, count, 0, 0, 0, t, + vc->vc_cols); + } else if (info->flags & FBINFO_READS_FAST) + fbcon_bmove(vc, t, 0, t + count, 0, + b - t - count, vc->vc_cols); + else + goto redraw_down; + fbcon_clear(vc, t, 0, count, vc->vc_cols); + break; + + case SCROLL_PAN_MOVE: + if ((count - p->yscroll <= p->vrows - vc->vc_rows) + && ((!scroll_partial && (b - t == vc->vc_rows)) + || (scroll_partial + && (b - t - count > + 3 * vc->vc_rows >> 2)))) { + if (vc->vc_rows - b > 0) + fbcon_bmove(vc, b, 0, b - count, 0, + vc->vc_rows - b, + vc->vc_cols); + ypan_down(vc, count); + if (t > 0) + fbcon_bmove(vc, count, 0, 0, 0, t, + vc->vc_cols); + } else if (info->flags & FBINFO_READS_FAST) + fbcon_bmove(vc, t, 0, t + count, 0, + b - t - count, vc->vc_cols); + else + goto redraw_down; + fbcon_clear(vc, t, 0, count, vc->vc_cols); + break; + + case SCROLL_PAN_REDRAW: + if ((count - p->yscroll <= p->vrows - vc->vc_rows) + && ((!scroll_partial && (b - t == vc->vc_rows)) + || (scroll_partial + && (b - t - count > + 3 * vc->vc_rows >> 2)))) { + if (vc->vc_rows - b > 0) + fbcon_redraw_move(vc, p, b, vc->vc_rows - b, + b - count); + ypan_down_redraw(vc, t, count); + if (t > 0) + fbcon_redraw_move(vc, p, count, t, 0); + } else + fbcon_redraw_move(vc, p, t, b - t - count, t + count); + fbcon_clear(vc, t, 0, count, vc->vc_cols); + break; + + case SCROLL_REDRAW: + redraw_down: + fbcon_redraw(vc, p, b - 1, b - t - count, + -count * vc->vc_cols); + fbcon_clear(vc, t, 0, count, vc->vc_cols); + scr_memsetw((unsigned short *) (vc->vc_origin + + vc->vc_size_row * + t), + vc->vc_video_erase_char, + vc->vc_size_row * count); + return 1; + } + } + return 0; +} + + +static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, + int height, int width) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct display *p = &fb_display[vc->vc_num]; + + if (fbcon_is_inactive(vc, info)) + return; + + if (!width || !height) + return; + + /* Split blits that cross physical y_wrap case. + * Pathological case involves 4 blits, better to use recursive + * code rather than unrolled case + * + * Recursive invocations don't need to erase the cursor over and + * over again, so we use fbcon_bmove_rec() + */ + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width, + p->vrows - p->yscroll); +} + +static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx, + int dy, int dx, int height, int width, u_int y_break) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + u_int b; + + if (sy < y_break && sy + height > y_break) { + b = y_break - sy; + if (dy < sy) { /* Avoid trashing self */ + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + } else { + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + } + return; + } + + if (dy < y_break && dy + height > y_break) { + b = y_break - dy; + if (dy < sy) { /* Avoid trashing self */ + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + } else { + fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, + height - b, width, y_break); + fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, + y_break); + } + return; + } + ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx, + height, width); +} + +static void updatescrollmode(struct display *p, + struct fb_info *info, + struct vc_data *vc) +{ + struct fbcon_ops *ops = info->fbcon_par; + int fh = vc->vc_font.height; + int cap = info->flags; + u16 t = 0; + int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep, + info->fix.xpanstep); + int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t); + int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual, + info->var.xres_virtual); + int good_pan = (cap & FBINFO_HWACCEL_YPAN) && + divides(ypan, vc->vc_font.height) && vyres > yres; + int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) && + divides(ywrap, vc->vc_font.height) && + divides(vc->vc_font.height, vyres) && + divides(vc->vc_font.height, yres); + int reading_fast = cap & FBINFO_READS_FAST; + int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) && + !(cap & FBINFO_HWACCEL_DISABLED); + int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) && + !(cap & FBINFO_HWACCEL_DISABLED); + + p->vrows = vyres/fh; + if (yres > (fh * (vc->vc_rows + 1))) + p->vrows -= (yres - (fh * vc->vc_rows)) / fh; + if ((yres % fh) && (vyres % fh < yres % fh)) + p->vrows--; + + if (good_wrap || good_pan) { + if (reading_fast || fast_copyarea) + p->scrollmode = good_wrap ? + SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE; + else + p->scrollmode = good_wrap ? SCROLL_REDRAW : + SCROLL_PAN_REDRAW; + } else { + if (reading_fast || (fast_copyarea && !fast_imageblit)) + p->scrollmode = SCROLL_MOVE; + else + p->scrollmode = SCROLL_REDRAW; + } +} + +static int fbcon_resize(struct vc_data *vc, unsigned int width, + unsigned int height, unsigned int user) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *p = &fb_display[vc->vc_num]; + struct fb_var_screeninfo var = info->var; + int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh; + + virt_w = FBCON_SWAP(ops->rotate, width, height); + virt_h = FBCON_SWAP(ops->rotate, height, width); + virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width, + vc->vc_font.height); + virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height, + vc->vc_font.width); + var.xres = virt_w * virt_fw; + var.yres = virt_h * virt_fh; + x_diff = info->var.xres - var.xres; + y_diff = info->var.yres - var.yres; + if (x_diff < 0 || x_diff > virt_fw || + y_diff < 0 || y_diff > virt_fh) { + const struct fb_videomode *mode; + + DPRINTK("attempting resize %ix%i\n", var.xres, var.yres); + mode = fb_find_best_mode(&var, &info->modelist); + if (mode == NULL) + return -EINVAL; + display_to_var(&var, p); + fb_videomode_to_var(&var, mode); + + if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh) + return -EINVAL; + + DPRINTK("resize now %ix%i\n", var.xres, var.yres); + if (CON_IS_VISIBLE(vc)) { + var.activate = FB_ACTIVATE_NOW | + FB_ACTIVATE_FORCE; + fb_set_var(info, &var); + } + var_to_display(p, &info->var, info); + ops->var = info->var; + } + updatescrollmode(p, info, vc); + return 0; +} + +static int fbcon_switch(struct vc_data *vc) +{ + struct fb_info *info, *old_info = NULL; + struct fbcon_ops *ops; + struct display *p = &fb_display[vc->vc_num]; + struct fb_var_screeninfo var; + int i, ret, prev_console, charcnt = 256; + + info = registered_fb[con2fb_map[vc->vc_num]]; + ops = info->fbcon_par; + + if (softback_top) { + if (softback_lines) + fbcon_set_origin(vc); + softback_top = softback_curr = softback_in = softback_buf; + softback_lines = 0; + fbcon_update_softback(vc); + } + + if (logo_shown >= 0) { + struct vc_data *conp2 = vc_cons[logo_shown].d; + + if (conp2->vc_top == logo_lines + && conp2->vc_bottom == conp2->vc_rows) + conp2->vc_top = 0; + logo_shown = FBCON_LOGO_CANSHOW; + } + + prev_console = ops->currcon; + if (prev_console != -1) + old_info = registered_fb[con2fb_map[prev_console]]; + /* + * FIXME: If we have multiple fbdev's loaded, we need to + * update all info->currcon. Perhaps, we can place this + * in a centralized structure, but this might break some + * drivers. + * + * info->currcon = vc->vc_num; + */ + for (i = 0; i < FB_MAX; i++) { + if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) { + struct fbcon_ops *o = registered_fb[i]->fbcon_par; + + o->currcon = vc->vc_num; + } + } + memset(&var, 0, sizeof(struct fb_var_screeninfo)); + display_to_var(&var, p); + var.activate = FB_ACTIVATE_NOW; + + /* + * make sure we don't unnecessarily trip the memcmp() + * in fb_set_var() + */ + info->var.activate = var.activate; + var.vmode |= info->var.vmode & ~FB_VMODE_MASK; + fb_set_var(info, &var); + ops->var = info->var; + + if (old_info != NULL && (old_info != info || + info->flags & FBINFO_MISC_ALWAYS_SETPAR)) { + if (info->fbops->fb_set_par) { + ret = info->fbops->fb_set_par(info); + + if (ret) + printk(KERN_ERR "fbcon_switch: detected " + "unhandled fb_set_par error, " + "error code %d\n", ret); + } + + if (old_info != info) + fbcon_del_cursor_timer(old_info); + } + + if (fbcon_is_inactive(vc, info) || + ops->blank_state != FB_BLANK_UNBLANK) + fbcon_del_cursor_timer(info); + else + fbcon_add_cursor_timer(info); + + set_blitting_type(vc, info); + ops->cursor_reset = 1; + + if (ops->rotate_font && ops->rotate_font(info, vc)) { + ops->rotate = FB_ROTATE_UR; + set_blitting_type(vc, info); + } + + vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); + vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; + + if (p->userfont) + charcnt = FNTCHARCNT(vc->vc_font.data); + + if (charcnt > 256) + vc->vc_complement_mask <<= 1; + + updatescrollmode(p, info, vc); + + switch (p->scrollmode) { + case SCROLL_WRAP_MOVE: + scrollback_phys_max = p->vrows - vc->vc_rows; + break; + case SCROLL_PAN_MOVE: + case SCROLL_PAN_REDRAW: + scrollback_phys_max = p->vrows - 2 * vc->vc_rows; + if (scrollback_phys_max < 0) + scrollback_phys_max = 0; + break; + default: + scrollback_phys_max = 0; + break; + } + + scrollback_max = 0; + scrollback_current = 0; + + if (!fbcon_is_inactive(vc, info)) { + ops->var.xoffset = ops->var.yoffset = p->yscroll = 0; + ops->update_start(info); + } + + fbcon_set_palette(vc, color_table); + fbcon_clear_margins(vc, 0); + + if (logo_shown == FBCON_LOGO_DRAW) { + + logo_shown = fg_console; + /* This is protected above by initmem_freed */ + fb_show_logo(info, ops->rotate); + update_region(vc, + vc->vc_origin + vc->vc_size_row * vc->vc_top, + vc->vc_size_row * (vc->vc_bottom - + vc->vc_top) / 2); + return 0; + } + return 1; +} + +static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info, + int blank) +{ + struct fb_event event; + + if (blank) { + unsigned short charmask = vc->vc_hi_font_mask ? + 0x1ff : 0xff; + unsigned short oldc; + + oldc = vc->vc_video_erase_char; + vc->vc_video_erase_char &= charmask; + fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols); + vc->vc_video_erase_char = oldc; + } + + + if (!lock_fb_info(info)) + return; + event.info = info; + event.data = ␣ + fb_notifier_call_chain(FB_EVENT_CONBLANK, &event); + unlock_fb_info(info); +} + +static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + + if (mode_switch) { + struct fb_var_screeninfo var = info->var; + + ops->graphics = 1; + + if (!blank) { + var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE; + fb_set_var(info, &var); + ops->graphics = 0; + ops->var = info->var; + } + } + + if (!fbcon_is_inactive(vc, info)) { + if (ops->blank_state != blank) { + ops->blank_state = blank; + fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW); + ops->cursor_flash = (!blank); + + if (!(info->flags & FBINFO_MISC_USEREVENT)) + if (fb_blank(info, blank)) + fbcon_generic_blank(vc, info, blank); + } + + if (!blank) + update_screen(vc); + } + + if (mode_switch || fbcon_is_inactive(vc, info) || + ops->blank_state != FB_BLANK_UNBLANK) + fbcon_del_cursor_timer(info); + else + fbcon_add_cursor_timer(info); + + return 0; +} + +static int fbcon_debug_enter(struct vc_data *vc) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + + ops->save_graphics = ops->graphics; + ops->graphics = 0; + if (info->fbops->fb_debug_enter) + info->fbops->fb_debug_enter(info); + fbcon_set_palette(vc, color_table); + return 0; +} + +static int fbcon_debug_leave(struct vc_data *vc) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + + ops->graphics = ops->save_graphics; + if (info->fbops->fb_debug_leave) + info->fbops->fb_debug_leave(info); + return 0; +} + +static int fbcon_get_font(struct vc_data *vc, struct console_font *font) +{ + u8 *fontdata = vc->vc_font.data; + u8 *data = font->data; + int i, j; + + font->width = vc->vc_font.width; + font->height = vc->vc_font.height; + font->charcount = vc->vc_hi_font_mask ? 512 : 256; + if (!font->data) + return 0; + + if (font->width <= 8) { + j = vc->vc_font.height; + for (i = 0; i < font->charcount; i++) { + memcpy(data, fontdata, j); + memset(data + j, 0, 32 - j); + data += 32; + fontdata += j; + } + } else if (font->width <= 16) { + j = vc->vc_font.height * 2; + for (i = 0; i < font->charcount; i++) { + memcpy(data, fontdata, j); + memset(data + j, 0, 64 - j); + data += 64; + fontdata += j; + } + } else if (font->width <= 24) { + for (i = 0; i < font->charcount; i++) { + for (j = 0; j < vc->vc_font.height; j++) { + *data++ = fontdata[0]; + *data++ = fontdata[1]; + *data++ = fontdata[2]; + fontdata += sizeof(u32); + } + memset(data, 0, 3 * (32 - j)); + data += 3 * (32 - j); + } + } else { + j = vc->vc_font.height * 4; + for (i = 0; i < font->charcount; i++) { + memcpy(data, fontdata, j); + memset(data + j, 0, 128 - j); + data += 128; + fontdata += j; + } + } + return 0; +} + +static int fbcon_do_set_font(struct vc_data *vc, int w, int h, + const u8 * data, int userfont) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *p = &fb_display[vc->vc_num]; + int resize; + int cnt; + char *old_data = NULL; + + if (CON_IS_VISIBLE(vc) && softback_lines) + fbcon_set_origin(vc); + + resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); + if (p->userfont) + old_data = vc->vc_font.data; + if (userfont) + cnt = FNTCHARCNT(data); + else + cnt = 256; + vc->vc_font.data = (void *)(p->fontdata = data); + if ((p->userfont = userfont)) + REFCOUNT(data)++; + vc->vc_font.width = w; + vc->vc_font.height = h; + if (vc->vc_hi_font_mask && cnt == 256) { + vc->vc_hi_font_mask = 0; + if (vc->vc_can_do_color) { + vc->vc_complement_mask >>= 1; + vc->vc_s_complement_mask >>= 1; + } + + /* ++Edmund: reorder the attribute bits */ + if (vc->vc_can_do_color) { + unsigned short *cp = + (unsigned short *) vc->vc_origin; + int count = vc->vc_screenbuf_size / 2; + unsigned short c; + for (; count > 0; count--, cp++) { + c = scr_readw(cp); + scr_writew(((c & 0xfe00) >> 1) | + (c & 0xff), cp); + } + c = vc->vc_video_erase_char; + vc->vc_video_erase_char = + ((c & 0xfe00) >> 1) | (c & 0xff); + vc->vc_attr >>= 1; + } + } else if (!vc->vc_hi_font_mask && cnt == 512) { + vc->vc_hi_font_mask = 0x100; + if (vc->vc_can_do_color) { + vc->vc_complement_mask <<= 1; + vc->vc_s_complement_mask <<= 1; + } + + /* ++Edmund: reorder the attribute bits */ + { + unsigned short *cp = + (unsigned short *) vc->vc_origin; + int count = vc->vc_screenbuf_size / 2; + unsigned short c; + for (; count > 0; count--, cp++) { + unsigned short newc; + c = scr_readw(cp); + if (vc->vc_can_do_color) + newc = + ((c & 0xff00) << 1) | (c & + 0xff); + else + newc = c & ~0x100; + scr_writew(newc, cp); + } + c = vc->vc_video_erase_char; + if (vc->vc_can_do_color) { + vc->vc_video_erase_char = + ((c & 0xff00) << 1) | (c & 0xff); + vc->vc_attr <<= 1; + } else + vc->vc_video_erase_char = c & ~0x100; + } + + } + + if (resize) { + int cols, rows; + + cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); + rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + cols /= w; + rows /= h; + vc_resize(vc, cols, rows); + if (CON_IS_VISIBLE(vc) && softback_buf) + fbcon_update_softback(vc); + } else if (CON_IS_VISIBLE(vc) + && vc->vc_mode == KD_TEXT) { + fbcon_clear_margins(vc, 0); + update_screen(vc); + } + + if (old_data && (--REFCOUNT(old_data) == 0)) + kfree(old_data - FONT_EXTRA_WORDS * sizeof(int)); + return 0; +} + +static int fbcon_copy_font(struct vc_data *vc, int con) +{ + struct display *od = &fb_display[con]; + struct console_font *f = &vc->vc_font; + + if (od->fontdata == f->data) + return 0; /* already the same font... */ + return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont); +} + +/* + * User asked to set font; we are guaranteed that + * a) width and height are in range 1..32 + * b) charcount does not exceed 512 + * but lets not assume that, since someone might someday want to use larger + * fonts. And charcount of 512 is small for unicode support. + * + * However, user space gives the font in 32 rows , regardless of + * actual font height. So a new API is needed if support for larger fonts + * is ever implemented. + */ + +static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + unsigned charcount = font->charcount; + int w = font->width; + int h = font->height; + int size; + int i, csum; + u8 *new_data, *data = font->data; + int pitch = (font->width+7) >> 3; + + /* Is there a reason why fbconsole couldn't handle any charcount >256? + * If not this check should be changed to charcount < 256 */ + if (charcount != 256 && charcount != 512) + return -EINVAL; + + /* Make sure drawing engine can handle the font */ + if (!(info->pixmap.blit_x & (1 << (font->width - 1))) || + !(info->pixmap.blit_y & (1 << (font->height - 1)))) + return -EINVAL; + + /* Make sure driver can handle the font length */ + if (fbcon_invalid_charcount(info, charcount)) + return -EINVAL; + + size = h * pitch * charcount; + + new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER); + + if (!new_data) + return -ENOMEM; + + new_data += FONT_EXTRA_WORDS * sizeof(int); + FNTSIZE(new_data) = size; + FNTCHARCNT(new_data) = charcount; + REFCOUNT(new_data) = 0; /* usage counter */ + for (i=0; i< charcount; i++) { + memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch); + } + + /* Since linux has a nice crc32 function use it for counting font + * checksums. */ + csum = crc32(0, new_data, size); + + FNTSUM(new_data) = csum; + /* Check if the same font is on some other console already */ + for (i = first_fb_vc; i <= last_fb_vc; i++) { + struct vc_data *tmp = vc_cons[i].d; + + if (fb_display[i].userfont && + fb_display[i].fontdata && + FNTSUM(fb_display[i].fontdata) == csum && + FNTSIZE(fb_display[i].fontdata) == size && + tmp->vc_font.width == w && + !memcmp(fb_display[i].fontdata, new_data, size)) { + kfree(new_data - FONT_EXTRA_WORDS * sizeof(int)); + new_data = (u8 *)fb_display[i].fontdata; + break; + } + } + return fbcon_do_set_font(vc, font->width, font->height, new_data, 1); +} + +static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + const struct font_desc *f; + + if (!name) + f = get_default_font(info->var.xres, info->var.yres, + info->pixmap.blit_x, info->pixmap.blit_y); + else if (!(f = find_font(name))) + return -ENOENT; + + font->width = f->width; + font->height = f->height; + return fbcon_do_set_font(vc, f->width, f->height, f->data, 0); +} + +static u16 palette_red[16]; +static u16 palette_green[16]; +static u16 palette_blue[16]; + +static struct fb_cmap palette_cmap = { + 0, 16, palette_red, palette_green, palette_blue, NULL +}; + +static int fbcon_set_palette(struct vc_data *vc, unsigned char *table) +{ + struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; + int i, j, k, depth; + u8 val; + + if (fbcon_is_inactive(vc, info)) + return -EINVAL; + + if (!CON_IS_VISIBLE(vc)) + return 0; + + depth = fb_get_color_depth(&info->var, &info->fix); + if (depth > 3) { + for (i = j = 0; i < 16; i++) { + k = table[i]; + val = vc->vc_palette[j++]; + palette_red[k] = (val << 8) | val; + val = vc->vc_palette[j++]; + palette_green[k] = (val << 8) | val; + val = vc->vc_palette[j++]; + palette_blue[k] = (val << 8) | val; + } + palette_cmap.len = 16; + palette_cmap.start = 0; + /* + * If framebuffer is capable of less than 16 colors, + * use default palette of fbcon. + */ + } else + fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap); + + return fb_set_cmap(&palette_cmap, info); +} + +static u16 *fbcon_screen_pos(struct vc_data *vc, int offset) +{ + unsigned long p; + int line; + + if (vc->vc_num != fg_console || !softback_lines) + return (u16 *) (vc->vc_origin + offset); + line = offset / vc->vc_size_row; + if (line >= softback_lines) + return (u16 *) (vc->vc_origin + offset - + softback_lines * vc->vc_size_row); + p = softback_curr + offset; + if (p >= softback_end) + p += softback_buf - softback_end; + return (u16 *) p; +} + +static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos, + int *px, int *py) +{ + unsigned long ret; + int x, y; + + if (pos >= vc->vc_origin && pos < vc->vc_scr_end) { + unsigned long offset = (pos - vc->vc_origin) / 2; + + x = offset % vc->vc_cols; + y = offset / vc->vc_cols; + if (vc->vc_num == fg_console) + y += softback_lines; + ret = pos + (vc->vc_cols - x) * 2; + } else if (vc->vc_num == fg_console && softback_lines) { + unsigned long offset = pos - softback_curr; + + if (pos < softback_curr) + offset += softback_end - softback_buf; + offset /= 2; + x = offset % vc->vc_cols; + y = offset / vc->vc_cols; + ret = pos + (vc->vc_cols - x) * 2; + if (ret == softback_end) + ret = softback_buf; + if (ret == softback_in) + ret = vc->vc_origin; + } else { + /* Should not happen */ + x = y = 0; + ret = vc->vc_origin; + } + if (px) + *px = x; + if (py) + *py = y; + return ret; +} + +/* As we might be inside of softback, we may work with non-contiguous buffer, + that's why we have to use a separate routine. */ +static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt) +{ + while (cnt--) { + u16 a = scr_readw(p); + if (!vc->vc_can_do_color) + a ^= 0x0800; + else if (vc->vc_hi_font_mask == 0x100) + a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | + (((a) & 0x0e00) << 4); + else + a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | + (((a) & 0x0700) << 4); + scr_writew(a, p++); + if (p == (u16 *) softback_end) + p = (u16 *) softback_buf; + if (p == (u16 *) softback_in) + p = (u16 *) vc->vc_origin; + } +} + +static int fbcon_scrolldelta(struct vc_data *vc, int lines) +{ + struct fb_info *info = registered_fb[con2fb_map[fg_console]]; + struct fbcon_ops *ops = info->fbcon_par; + struct display *disp = &fb_display[fg_console]; + int offset, limit, scrollback_old; + + if (softback_top) { + if (vc->vc_num != fg_console) + return 0; + if (vc->vc_mode != KD_TEXT || !lines) + return 0; + if (logo_shown >= 0) { + struct vc_data *conp2 = vc_cons[logo_shown].d; + + if (conp2->vc_top == logo_lines + && conp2->vc_bottom == conp2->vc_rows) + conp2->vc_top = 0; + if (logo_shown == vc->vc_num) { + unsigned long p, q; + int i; + + p = softback_in; + q = vc->vc_origin + + logo_lines * vc->vc_size_row; + for (i = 0; i < logo_lines; i++) { + if (p == softback_top) + break; + if (p == softback_buf) + p = softback_end; + p -= vc->vc_size_row; + q -= vc->vc_size_row; + scr_memcpyw((u16 *) q, (u16 *) p, + vc->vc_size_row); + } + softback_in = softback_curr = p; + update_region(vc, vc->vc_origin, + logo_lines * vc->vc_cols); + } + logo_shown = FBCON_LOGO_CANSHOW; + } + fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK); + fbcon_redraw_softback(vc, disp, lines); + fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK); + return 0; + } + + if (!scrollback_phys_max) + return -ENOSYS; + + scrollback_old = scrollback_current; + scrollback_current -= lines; + if (scrollback_current < 0) + scrollback_current = 0; + else if (scrollback_current > scrollback_max) + scrollback_current = scrollback_max; + if (scrollback_current == scrollback_old) + return 0; + + if (fbcon_is_inactive(vc, info)) + return 0; + + fbcon_cursor(vc, CM_ERASE); + + offset = disp->yscroll - scrollback_current; + limit = disp->vrows; + switch (disp->scrollmode) { + case SCROLL_WRAP_MOVE: + info->var.vmode |= FB_VMODE_YWRAP; + break; + case SCROLL_PAN_MOVE: + case SCROLL_PAN_REDRAW: + limit -= vc->vc_rows; + info->var.vmode &= ~FB_VMODE_YWRAP; + break; + } + if (offset < 0) + offset += limit; + else if (offset >= limit) + offset -= limit; + + ops->var.xoffset = 0; + ops->var.yoffset = offset * vc->vc_font.height; + ops->update_start(info); + + if (!scrollback_current) + fbcon_cursor(vc, CM_DRAW); + return 0; +} + +static int fbcon_set_origin(struct vc_data *vc) +{ + if (softback_lines) + fbcon_scrolldelta(vc, softback_lines); + return 0; +} + +static void fbcon_suspended(struct fb_info *info) +{ + struct vc_data *vc = NULL; + struct fbcon_ops *ops = info->fbcon_par; + + if (!ops || ops->currcon < 0) + return; + vc = vc_cons[ops->currcon].d; + + /* Clear cursor, restore saved data */ + fbcon_cursor(vc, CM_ERASE); +} + +static void fbcon_resumed(struct fb_info *info) +{ + struct vc_data *vc; + struct fbcon_ops *ops = info->fbcon_par; + + if (!ops || ops->currcon < 0) + return; + vc = vc_cons[ops->currcon].d; + + update_screen(vc); +} + +static void fbcon_modechanged(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + struct vc_data *vc; + struct display *p; + int rows, cols; + + if (!ops || ops->currcon < 0) + return; + vc = vc_cons[ops->currcon].d; + if (vc->vc_mode != KD_TEXT || + registered_fb[con2fb_map[ops->currcon]] != info) + return; + + p = &fb_display[vc->vc_num]; + set_blitting_type(vc, info); + + if (CON_IS_VISIBLE(vc)) { + var_to_display(p, &info->var, info); + cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); + rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + cols /= vc->vc_font.width; + rows /= vc->vc_font.height; + vc_resize(vc, cols, rows); + updatescrollmode(p, info, vc); + scrollback_max = 0; + scrollback_current = 0; + + if (!fbcon_is_inactive(vc, info)) { + ops->var.xoffset = ops->var.yoffset = p->yscroll = 0; + ops->update_start(info); + } + + fbcon_set_palette(vc, color_table); + update_screen(vc); + if (softback_buf) + fbcon_update_softback(vc); + } +} + +static void fbcon_set_all_vcs(struct fb_info *info) +{ + struct fbcon_ops *ops = info->fbcon_par; + struct vc_data *vc; + struct display *p; + int i, rows, cols, fg = -1; + + if (!ops || ops->currcon < 0) + return; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + vc = vc_cons[i].d; + if (!vc || vc->vc_mode != KD_TEXT || + registered_fb[con2fb_map[i]] != info) + continue; + + if (CON_IS_VISIBLE(vc)) { + fg = i; + continue; + } + + p = &fb_display[vc->vc_num]; + set_blitting_type(vc, info); + var_to_display(p, &info->var, info); + cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); + rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); + cols /= vc->vc_font.width; + rows /= vc->vc_font.height; + vc_resize(vc, cols, rows); + } + + if (fg != -1) + fbcon_modechanged(info); +} + +static int fbcon_mode_deleted(struct fb_info *info, + struct fb_videomode *mode) +{ + struct fb_info *fb_info; + struct display *p; + int i, j, found = 0; + + /* before deletion, ensure that mode is not in use */ + for (i = first_fb_vc; i <= last_fb_vc; i++) { + j = con2fb_map[i]; + if (j == -1) + continue; + fb_info = registered_fb[j]; + if (fb_info != info) + continue; + p = &fb_display[i]; + if (!p || !p->mode) + continue; + if (fb_mode_is_equal(p->mode, mode)) { + found = 1; + break; + } + } + return found; +} + +#ifdef CONFIG_VT_HW_CONSOLE_BINDING +static int fbcon_unbind(void) +{ + int ret; + + ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc, + fbcon_is_default); + + if (!ret) + fbcon_has_console_bind = 0; + + return ret; +} +#else +static inline int fbcon_unbind(void) +{ + return -EINVAL; +} +#endif /* CONFIG_VT_HW_CONSOLE_BINDING */ + +/* called with console_lock held */ +static int fbcon_fb_unbind(int idx) +{ + int i, new_idx = -1, ret = 0; + + if (!fbcon_has_console_bind) + return 0; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] != idx && + con2fb_map[i] != -1) { + new_idx = i; + break; + } + } + + if (new_idx != -1) { + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] == idx) + set_con2fb_map(i, new_idx, 0); + } + } else { + struct fb_info *info = registered_fb[idx]; + + /* This is sort of like set_con2fb_map, except it maps + * the consoles to no device and then releases the + * oldinfo to free memory and cancel the cursor blink + * timer. I can imagine this just becoming part of + * set_con2fb_map where new_idx is -1 + */ + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] == idx) { + con2fb_map[i] = -1; + if (!search_fb_in_map(idx)) { + ret = con2fb_release_oldinfo(vc_cons[i].d, + info, NULL, i, + idx, 0); + if (ret) { + con2fb_map[i] = idx; + return ret; + } + } + } + } + ret = fbcon_unbind(); + } + + return ret; +} + +/* called with console_lock held */ +static int fbcon_fb_unregistered(struct fb_info *info) +{ + int i, idx; + + idx = info->node; + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] == idx) + con2fb_map[i] = -1; + } + + if (idx == info_idx) { + info_idx = -1; + + for (i = 0; i < FB_MAX; i++) { + if (registered_fb[i] != NULL) { + info_idx = i; + break; + } + } + } + + if (info_idx != -1) { + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map[i] == -1) + con2fb_map[i] = info_idx; + } + } + + if (primary_device == idx) + primary_device = -1; + + if (!num_registered_fb) + do_unregister_con_driver(&fb_con); + + return 0; +} + +/* called with console_lock held */ +static void fbcon_remap_all(int idx) +{ + int i; + for (i = first_fb_vc; i <= last_fb_vc; i++) + set_con2fb_map(i, idx, 0); + + if (con_is_bound(&fb_con)) { + printk(KERN_INFO "fbcon: Remapping primary device, " + "fb%i, to tty %i-%i\n", idx, + first_fb_vc + 1, last_fb_vc + 1); + info_idx = idx; + } +} + +#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY +static void fbcon_select_primary(struct fb_info *info) +{ + if (!map_override && primary_device == -1 && + fb_is_primary_device(info)) { + int i; + + printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n", + info->fix.id, info->node); + primary_device = info->node; + + for (i = first_fb_vc; i <= last_fb_vc; i++) + con2fb_map_boot[i] = primary_device; + + if (con_is_bound(&fb_con)) { + printk(KERN_INFO "fbcon: Remapping primary device, " + "fb%i, to tty %i-%i\n", info->node, + first_fb_vc + 1, last_fb_vc + 1); + info_idx = primary_device; + } + } + +} +#else +static inline void fbcon_select_primary(struct fb_info *info) +{ + return; +} +#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */ + +/* called with console_lock held */ +static int fbcon_fb_registered(struct fb_info *info) +{ + int ret = 0, i, idx; + + idx = info->node; + fbcon_select_primary(info); + + if (info_idx == -1) { + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map_boot[i] == idx) { + info_idx = idx; + break; + } + } + + if (info_idx != -1) + ret = do_fbcon_takeover(1); + } else { + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (con2fb_map_boot[i] == idx) + set_con2fb_map(i, idx, 0); + } + } + + return ret; +} + +static void fbcon_fb_blanked(struct fb_info *info, int blank) +{ + struct fbcon_ops *ops = info->fbcon_par; + struct vc_data *vc; + + if (!ops || ops->currcon < 0) + return; + + vc = vc_cons[ops->currcon].d; + if (vc->vc_mode != KD_TEXT || + registered_fb[con2fb_map[ops->currcon]] != info) + return; + + if (CON_IS_VISIBLE(vc)) { + if (blank) + do_blank_screen(0); + else + do_unblank_screen(0); + } + ops->blank_state = blank; +} + +static void fbcon_new_modelist(struct fb_info *info) +{ + int i; + struct vc_data *vc; + struct fb_var_screeninfo var; + const struct fb_videomode *mode; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + if (registered_fb[con2fb_map[i]] != info) + continue; + if (!fb_display[i].mode) + continue; + vc = vc_cons[i].d; + display_to_var(&var, &fb_display[i]); + mode = fb_find_nearest_mode(fb_display[i].mode, + &info->modelist); + fb_videomode_to_var(&var, mode); + fbcon_set_disp(info, &var, vc->vc_num); + } +} + +static void fbcon_get_requirement(struct fb_info *info, + struct fb_blit_caps *caps) +{ + struct vc_data *vc; + struct display *p; + + if (caps->flags) { + int i, charcnt; + + for (i = first_fb_vc; i <= last_fb_vc; i++) { + vc = vc_cons[i].d; + if (vc && vc->vc_mode == KD_TEXT && + info->node == con2fb_map[i]) { + p = &fb_display[i]; + caps->x |= 1 << (vc->vc_font.width - 1); + caps->y |= 1 << (vc->vc_font.height - 1); + charcnt = (p->userfont) ? + FNTCHARCNT(p->fontdata) : 256; + if (caps->len < charcnt) + caps->len = charcnt; + } + } + } else { + vc = vc_cons[fg_console].d; + + if (vc && vc->vc_mode == KD_TEXT && + info->node == con2fb_map[fg_console]) { + p = &fb_display[fg_console]; + caps->x = 1 << (vc->vc_font.width - 1); + caps->y = 1 << (vc->vc_font.height - 1); + caps->len = (p->userfont) ? + FNTCHARCNT(p->fontdata) : 256; + } + } +} + +static int fbcon_event_notify(struct notifier_block *self, + unsigned long action, void *data) +{ + struct fb_event *event = data; + struct fb_info *info = event->info; + struct fb_videomode *mode; + struct fb_con2fbmap *con2fb; + struct fb_blit_caps *caps; + int idx, ret = 0; + + /* + * ignore all events except driver registration and deregistration + * if fbcon is not active + */ + if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED || + action == FB_EVENT_FB_UNREGISTERED)) + goto done; + + switch(action) { + case FB_EVENT_SUSPEND: + fbcon_suspended(info); + break; + case FB_EVENT_RESUME: + fbcon_resumed(info); + break; + case FB_EVENT_MODE_CHANGE: + fbcon_modechanged(info); + break; + case FB_EVENT_MODE_CHANGE_ALL: + fbcon_set_all_vcs(info); + break; + case FB_EVENT_MODE_DELETE: + mode = event->data; + ret = fbcon_mode_deleted(info, mode); + break; + case FB_EVENT_FB_UNBIND: + idx = info->node; + ret = fbcon_fb_unbind(idx); + break; + case FB_EVENT_FB_REGISTERED: + ret = fbcon_fb_registered(info); + break; + case FB_EVENT_FB_UNREGISTERED: + ret = fbcon_fb_unregistered(info); + break; + case FB_EVENT_SET_CONSOLE_MAP: + /* called with console lock held */ + con2fb = event->data; + ret = set_con2fb_map(con2fb->console - 1, + con2fb->framebuffer, 1); + break; + case FB_EVENT_GET_CONSOLE_MAP: + con2fb = event->data; + con2fb->framebuffer = con2fb_map[con2fb->console - 1]; + break; + case FB_EVENT_BLANK: + fbcon_fb_blanked(info, *(int *)event->data); + break; + case FB_EVENT_NEW_MODELIST: + fbcon_new_modelist(info); + break; + case FB_EVENT_GET_REQ: + caps = event->data; + fbcon_get_requirement(info, caps); + break; + case FB_EVENT_REMAP_ALL_CONSOLE: + idx = info->node; + fbcon_remap_all(idx); + break; + } +done: + return ret; +} + +/* + * The console `switch' structure for the frame buffer based console + */ + +static const struct consw fb_con = { + .owner = THIS_MODULE, + .con_startup = fbcon_startup, + .con_init = fbcon_init, + .con_deinit = fbcon_deinit, + .con_clear = fbcon_clear, + .con_putc = fbcon_putc, + .con_putcs = fbcon_putcs, + .con_cursor = fbcon_cursor, + .con_scroll = fbcon_scroll, + .con_bmove = fbcon_bmove, + .con_switch = fbcon_switch, + .con_blank = fbcon_blank, + .con_font_set = fbcon_set_font, + .con_font_get = fbcon_get_font, + .con_font_default = fbcon_set_def_font, + .con_font_copy = fbcon_copy_font, + .con_set_palette = fbcon_set_palette, + .con_scrolldelta = fbcon_scrolldelta, + .con_set_origin = fbcon_set_origin, + .con_invert_region = fbcon_invert_region, + .con_screen_pos = fbcon_screen_pos, + .con_getxy = fbcon_getxy, + .con_resize = fbcon_resize, + .con_debug_enter = fbcon_debug_enter, + .con_debug_leave = fbcon_debug_leave, +}; + +static struct notifier_block fbcon_event_notifier = { + .notifier_call = fbcon_event_notify, +}; + +static ssize_t store_rotate(struct device *device, + struct device_attribute *attr, const char *buf, + size_t count) +{ + struct fb_info *info; + int rotate, idx; + char **last = NULL; + + if (fbcon_has_exited) + return count; + + console_lock(); + idx = con2fb_map[fg_console]; + + if (idx == -1 || registered_fb[idx] == NULL) + goto err; + + info = registered_fb[idx]; + rotate = simple_strtoul(buf, last, 0); + fbcon_rotate(info, rotate); +err: + console_unlock(); + return count; +} + +static ssize_t store_rotate_all(struct device *device, + struct device_attribute *attr,const char *buf, + size_t count) +{ + struct fb_info *info; + int rotate, idx; + char **last = NULL; + + if (fbcon_has_exited) + return count; + + console_lock(); + idx = con2fb_map[fg_console]; + + if (idx == -1 || registered_fb[idx] == NULL) + goto err; + + info = registered_fb[idx]; + rotate = simple_strtoul(buf, last, 0); + fbcon_rotate_all(info, rotate); +err: + console_unlock(); + return count; +} + +static ssize_t show_rotate(struct device *device, + struct device_attribute *attr,char *buf) +{ + struct fb_info *info; + int rotate = 0, idx; + + if (fbcon_has_exited) + return 0; + + console_lock(); + idx = con2fb_map[fg_console]; + + if (idx == -1 || registered_fb[idx] == NULL) + goto err; + + info = registered_fb[idx]; + rotate = fbcon_get_rotate(info); +err: + console_unlock(); + return snprintf(buf, PAGE_SIZE, "%d\n", rotate); +} + +static ssize_t show_cursor_blink(struct device *device, + struct device_attribute *attr, char *buf) +{ + struct fb_info *info; + struct fbcon_ops *ops; + int idx, blink = -1; + + if (fbcon_has_exited) + return 0; + + console_lock(); + idx = con2fb_map[fg_console]; + + if (idx == -1 || registered_fb[idx] == NULL) + goto err; + + info = registered_fb[idx]; + ops = info->fbcon_par; + + if (!ops) + goto err; + + blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0; +err: + console_unlock(); + return snprintf(buf, PAGE_SIZE, "%d\n", blink); +} + +static ssize_t store_cursor_blink(struct device *device, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fb_info *info; + int blink, idx; + char **last = NULL; + + if (fbcon_has_exited) + return count; + + console_lock(); + idx = con2fb_map[fg_console]; + + if (idx == -1 || registered_fb[idx] == NULL) + goto err; + + info = registered_fb[idx]; + + if (!info->fbcon_par) + goto err; + + blink = simple_strtoul(buf, last, 0); + + if (blink) { + fbcon_cursor_noblink = 0; + fbcon_add_cursor_timer(info); + } else { + fbcon_cursor_noblink = 1; + fbcon_del_cursor_timer(info); + } + +err: + console_unlock(); + return count; +} + +static struct device_attribute device_attrs[] = { + __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate), + __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all), + __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink, + store_cursor_blink), +}; + +static int fbcon_init_device(void) +{ + int i, error = 0; + + fbcon_has_sysfs = 1; + + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) { + error = device_create_file(fbcon_device, &device_attrs[i]); + + if (error) + break; + } + + if (error) { + while (--i >= 0) + device_remove_file(fbcon_device, &device_attrs[i]); + + fbcon_has_sysfs = 0; + } + + return 0; +} + +static void fbcon_start(void) +{ + if (num_registered_fb) { + int i; + + console_lock(); + + for (i = 0; i < FB_MAX; i++) { + if (registered_fb[i] != NULL) { + info_idx = i; + break; + } + } + + do_fbcon_takeover(0); + console_unlock(); + + } +} + +static void fbcon_exit(void) +{ + struct fb_info *info; + int i, j, mapped; + + if (fbcon_has_exited) + return; + + kfree((void *)softback_buf); + softback_buf = 0UL; + + for (i = 0; i < FB_MAX; i++) { + int pending = 0; + + mapped = 0; + info = registered_fb[i]; + + if (info == NULL) + continue; + + if (info->queue.func) + pending = cancel_work_sync(&info->queue); + DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" : + "no")); + + for (j = first_fb_vc; j <= last_fb_vc; j++) { + if (con2fb_map[j] == i) { + mapped = 1; + break; + } + } + + if (mapped) { + if (info->fbops->fb_release) + info->fbops->fb_release(info, 0); + module_put(info->fbops->owner); + + if (info->fbcon_par) { + struct fbcon_ops *ops = info->fbcon_par; + + fbcon_del_cursor_timer(info); + kfree(ops->cursor_src); + kfree(ops->cursor_state.mask); + kfree(info->fbcon_par); + info->fbcon_par = NULL; + } + + if (info->queue.func == fb_flashcursor) + info->queue.func = NULL; + } + } + + fbcon_has_exited = 1; +} + +static int __init fb_console_init(void) +{ + int i; + + console_lock(); + fb_register_client(&fbcon_event_notifier); + fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL, + "fbcon"); + + if (IS_ERR(fbcon_device)) { + printk(KERN_WARNING "Unable to create device " + "for fbcon; errno = %ld\n", + PTR_ERR(fbcon_device)); + fbcon_device = NULL; + } else + fbcon_init_device(); + + for (i = 0; i < MAX_NR_CONSOLES; i++) + con2fb_map[i] = -1; + + console_unlock(); + fbcon_start(); + return 0; +} + +module_init(fb_console_init); + +#ifdef MODULE + +static void __exit fbcon_deinit_device(void) +{ + int i; + + if (fbcon_has_sysfs) { + for (i = 0; i < ARRAY_SIZE(device_attrs); i++) + device_remove_file(fbcon_device, &device_attrs[i]); + + fbcon_has_sysfs = 0; + } +} + +static void __exit fb_console_exit(void) +{ + console_lock(); + fb_unregister_client(&fbcon_event_notifier); + fbcon_deinit_device(); + device_destroy(fb_class, MKDEV(0, 0)); + fbcon_exit(); + do_unregister_con_driver(&fb_con); + console_unlock(); +} + +module_exit(fb_console_exit); + +#endif + +MODULE_LICENSE("GPL"); diff -urNp linux-3.15.orig/drivers/video/console/unicon.c linux-3.15/drivers/video/console/unicon.c --- linux-3.15.orig/drivers/video/console/unicon.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/console/unicon.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,70 @@ + +#include + +extern int fbcon_softback_size; +DBFontManager *UniconFontManager = NULL; +EXPORT_SYMBOL (UniconFontManager); + +const unsigned short * hibyte_pos(struct vc_data *vc, const unsigned short *p) +{ + unsigned long pos=(long)p; + if (pos >= vc->vc_origin && pos < vc->vc_scr_end) { + /* pos in the vc buffer - Chrisl 99.11.12*/ + return (unsigned short*)(pos+vc->vc_screenbuf_size); + } else if (vc->vc_num == fg_console){ + /*&& softback_lines,because the scroll will first change + softback_lines, then call this function, so it is ignored here + -JimChen 99.11.12*/ + return (unsigned short*)(pos+fbcon_softback_size); + } else { + /* Should not happen */ + printk("Warnning, changing not active console\n"); + return p; + } +} + +static int fbcon_get_dchar_len (struct vc_data *vc, + struct display *p, + const unsigned short *s, int count) +{ + int n, i; + struct double_byte * doublebyte_default = NULL; + unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; + + if (UniconFontManager != NULL) + doublebyte_default = UniconFontManager->getfont (vc->vc_num); + if (!doublebyte_default) + return 0; + + for (n = 0, i = 0; i < count; i++, s++){ + if (doublebyte_default->is_left (*s & charmask) == 1 || + doublebyte_default->is_right (*s & charmask) == 1) + n++; + else + break; + } + return n; +} + +static int fbcon_get_schar_len (struct vc_data *vc, + struct display *p, + const unsigned short *s, int count) +{ + int n, i; + struct double_byte * doublebyte_default = NULL; + unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; + + if (UniconFontManager != NULL) + doublebyte_default = UniconFontManager->getfont (vc->vc_num); + if (!doublebyte_default) + return count; + + for (n = 0, i = 0; i < count; i++, s++){ + if (doublebyte_default->is_left (*s & charmask) == 0 && + doublebyte_default->is_right (*s & charmask) == 0) + n++; + else + break; + } + return n; +} diff -urNp linux-3.15.orig/drivers/video/unicon/COPYING linux-3.15/drivers/video/unicon/COPYING --- linux-3.15.orig/drivers/video/unicon/COPYING 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/COPYING 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,341 @@ + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + Appendix: How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. + diff -urNp linux-3.15.orig/drivers/video/unicon/CREDITS linux-3.15/drivers/video/unicon/CREDITS --- linux-3.15.orig/drivers/video/unicon/CREDITS 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/CREDITS 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,38 @@ +This is at least a partial credits-file of people that have +contributed to the Linux UNICON subsystems, including tools and +drivers. + +The format of this file was shamelessly stolen from the CREDITS file +in the Linux kernel distribution. + +It is sorted by name and formatted to allow easy grepping and +beautification by scripts. The fields are: name (N), email (E), +web-address (W), PGP key ID and fingerprint (P), description (D), and +snail-mail address (S). + +---------- +N: ChenJun +E: jimc@turbolinux.com.cn +D: Original author of unicon display support in the console driver. + Table character etc. + +N: Li Qi Cheng +E: chrisl at gnuchina dot org +D: Original author of unicon display support in the console driver. + +N: Ma Jun +E: arthur.ma@turbolinux.com.cn +D: Original author of input C/S method and international of the + Unicon project + Imm C/S struct architecture + Font Manager & Unikey + Font modules + SmallFont Utility + Unicon Tools + +N: Yu Min Jian +E: yumingjian@china.com +D: Original author of unicon grasp server + +---------- +End of the Linux UNICON CREDITS file. diff -urNp linux-3.15.orig/drivers/video/unicon/ChangeLog.TL linux-3.15/drivers/video/unicon/ChangeLog.TL --- linux-3.15.orig/drivers/video/unicon/ChangeLog.TL 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/ChangeLog.TL 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,59 @@ +2001-05-30 Ma Lin + * Unicon-3.0.3 released + Kernel patches for 2.4.5 and 2.2.19 + 2.4 Kernel patch cleanup, some bugfix. +2001-05-23 Ma Lin + More documents updated. + Unicon startup scripts updated. + Fixed some install problem. +2001-02-27 Ma Lin + unicon-3.0.2pl2 + Documents updated. + Fixed compile problem under gcc2.96. + kernel patches for 2.4.2 and 2.2.19pre15 +2001-02-26 Ma Lin + * unicon-3.0.2 released + fix a few Makefile and spell problems. + add unicon start scripts. +2001-02-19 Ma Lin + rearrange IMM directory structure + update pinyin.map and sysphrase.txt + kernel patch for 2.4.1 + some other bug-fixes and document-updates. +2001-02-15 Ma Lin + add cxterm IMM module and cit files. +2000-11-22 Arthur ma + * unicon-3.0.1 released + fix a bug on GB==>GBK input switch + remove CFLAG "-V2.7.2.3" in Makefile.in + add kernel 2.4-test11 patch + add kernel 2.2.18-pre22 patch + clean up Makefile and configure script. +2000-09-20 Arthur Ma + release 2.4-test8 patch + add usb patch +2000-08-11 Arthur Ma + kernel font manager bugs +2000-06-8 Arthur Ma + fix memeory leak +2000-05-11 Arthur Ma + delete multiple display of the same phrase. +2000-05-08 Arthur Ma + * release unicon1.1 +2000-05-01 Arthur Ma + port to kernel 2.2.15 +2000-04-21 Arthur Ma + fix the unikey to fit Muti-processor +2000-03-21 Arthur Ma + input method C/S +2000-02-21 Arthur Ma + disable the OS forward key (fix bugs about Ctrl-F1) +2000-02-10 Arthur Ma + Keyboard States monitor +1999-09-21 Justin Yu + * First Public Released 0.1 +1999-09-17 + * Add Help +1999-09-07 + * Change the share memory in xl_pinyin.c to + conventional memory diff -urNp linux-3.15.orig/drivers/video/unicon/Kconfig linux-3.15/drivers/video/unicon/Kconfig --- linux-3.15.orig/drivers/video/unicon/Kconfig 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/Kconfig 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,34 @@ +config UNICON_GB + tristate "UNICON GB Font support" + depends on UNICON + default m + +config UNICON_GBK + tristate "UNICON GBK Font support" + depends on UNICON + default m + +config UNICON_BIG5 + tristate "UNICON Big5 Font support" + depends on UNICON + default m + +config UNICON_EUCJP + tristate "UNICON EUC-JP Font support" + depends on UNICON + default m + +config UNICON_JIS + tristate "UNICON JIS Font support" + depends on UNICON + default m + +config UNICON_SJIS + tristate "UNICON Shift-JIS Font support" + depends on UNICON + default m + +config UNICON_KSCM + tristate "UNICON KSCM Font support" + depends on UNICON + default m diff -urNp linux-3.15.orig/drivers/video/unicon/Makefile linux-3.15/drivers/video/unicon/Makefile --- linux-3.15.orig/drivers/video/unicon/Makefile 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/Makefile 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,21 @@ +# Makefile for the UNICON + +unikey-objs := xl_fm.o xl_hzfb.o xl_keyhooks.o xl_keymasks.o xl_unikey.o + +obj-m := unikey.o +obj-$(CONFIG_UNICON_GB) += encode-gb.o +obj-$(CONFIG_UNICON_GBK) += encode-gbk.o +obj-$(CONFIG_UNICON_BIG5) += encode-big5.o +obj-$(CONFIG_UNICON_EUCJP) += encode-eucjp.o +obj-$(CONFIG_UNICON_JIS) += encode-jis.o +obj-$(CONFIG_UNICON_SJIS) += encode-sjis.o +obj-$(CONFIG_UNICON_KSCM) += encode-kscm.o + +unikey.o: $(unikey-objs) + $(LD) -r -o $@ $(unikey-objs) + +ifeq ($(VERSION),2) +ifneq ($(PATCHLEVEL),6) +include $(TOPDIR)/Rules.make +endif +endif diff -urNp linux-3.15.orig/drivers/video/unicon/encode-big5.c linux-3.15/drivers/video/unicon/encode-big5.c --- linux-3.15.orig/drivers/video/unicon/encode-big5.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-big5.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,85 @@ + +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#include +#include +#include "font_big5_16.h" + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int index_big5(int left, int right) +{ + int rec; + rec = (left - 0xa1) * (0xff - 0x40) + right - 0x40; + return rec << 5; +} + +static int is_hz_left(int c) +{ + return (c >= 0xa1 && c <= 0xfa); +} + +static int is_hz_right(int c) +{ + return (c >= 40 && c <= 0xff); +} + +#ifdef MODULE +static struct double_byte db_big5 = +#else +struct double_byte db_big5 = +#endif +{ + 0, + "BIG5", + is_hz_left, + is_hz_right, + index_big5, + 16,16, + max_big5_16, + font_big5_16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == 0) + return 1; + if (UniconFontManager->registerfont (XL_DB_BIG5, &db_big5) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == 0) + return; + UniconFontManager->unregisterfont (XL_DB_BIG5); +} +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/encode-eucjp.c linux-3.15/drivers/video/unicon/encode-eucjp.c --- linux-3.15.orig/drivers/video/unicon/encode-eucjp.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-eucjp.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,93 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#include +#include +#include "font_eucjp16.h" +#define min1 0xa1 +#define max1 0xfe +// 0x2121 -- 0x7424 + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int index_euc(int left, int right) +{ + if ( left == 0x8E ) + left = 0; + else + left &= 0x7F; + right &= 0x7F; + + if (left > 0x29) + return ((right - 0x40 + (left - 0x25) * 96) << 5); + else + return ((right - 0x20 + (left - 0x20) * 96) << 5); +} + +static int is_hz_left(int c) +{ + return ( c >= min1 && c<=max1); +} + +static int is_hz_right(int c) +{ + return ( c >= min1 && c<=max1); +} + +#ifdef MODULE +static struct double_byte db_eucjp = +#else +struct double_byte db_eucjp = +#endif +{ + 0, + "EUCJP", + is_hz_left, + is_hz_right, + index_euc, + 16,16, + max_jis16, + font_jis16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == (DBFontManager *) 0) + return 1; + if (UniconFontManager->registerfont (XL_DB_EUCJP, &db_eucjp) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == (DBFontManager *) 0) + return; + UniconFontManager->unregisterfont (XL_DB_EUCJP); +} +#endif diff -urNp linux-3.15.orig/drivers/video/unicon/encode-gb.c linux-3.15/drivers/video/unicon/encode-gb.c --- linux-3.15.orig/drivers/video/unicon/encode-gb.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-gb.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,79 @@ + +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#include +#include +#include "font_gb16.h" +#define min1 0xa1 +#define max1 0xfe + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int index_gb(int left, int right) +{ + return ((left-min1)*94+right-min1) << 5; +} +static int is_hz(int c) +{ + return ( c >= min1 && c<=max1); +} +#ifdef MODULE +static struct double_byte db_gb = +#else +struct double_byte db_gb = +#endif + +{ + 0, + "GB", + is_hz, + is_hz, + index_gb, + 16,16, + max_gb16, + font_gb16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == 0) + return 1; + if (UniconFontManager->registerfont (XL_DB_GB, &db_gb) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == 0) + return; + UniconFontManager->unregisterfont (XL_DB_GB); +} +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/encode-gbk.c linux-3.15/drivers/video/unicon/encode-gbk.c --- linux-3.15.orig/drivers/video/unicon/encode-gbk.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-gbk.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,96 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + + /************************************************************************** + the GBK standard internal code is + start at 33088 ===> 0x8140 + end at 65279 ===> 0xfeff + Arthur Ma arthur.ma@turbolinux.com.cn + */ + +#include +#include +#include "font_gbk16.h" +#define min1 0x81 +#define max1 0xfe +#define min2 0x40 +#define max2 0xff + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int index_gbk (int left, int right) +{ + int n; + n = (left - 0x81) * 192; + if (right <= 0xff && right >= 0x40) + n += (right - 0x40); + return n << 5; +} + +static int is_hz_left(int c) +{ + return (c >= min1 && c <= max1); +} + +static int is_hz_right(int c) +{ + return (c >= min2 && c <= max2); +} + +#ifdef MODULE +static struct double_byte db_gbk = +#else +struct double_byte db_gbk = +#endif +{ + 0, + "GBK", + is_hz_left, + is_hz_right, + index_gbk, + 16,16, + max_gbk16, + font_gbk16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == NULL) + return 1; + if (UniconFontManager->registerfont (XL_DB_GBK, &db_gbk) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == NULL) + return; + UniconFontManager->unregisterfont (XL_DB_GBK); +} +#endif diff -urNp linux-3.15.orig/drivers/video/unicon/encode-jis.c linux-3.15/drivers/video/unicon/encode-jis.c --- linux-3.15.orig/drivers/video/unicon/encode-jis.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-jis.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,99 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +/* + * changelog + * Sat Jan 25 2003 Go Taniguchi + * support jisx0213-1 + */ + +#include +#include +#include "font_jis16.h" +// 0x2121 -- 0x7e79 + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int index_jis(int left, int right) +{ + int rec; + left = left & 0x7f; + right = right & 0x7f; + rec = (left - 0x21) * (0x7e - 0x21 + 1) + right - 0x21; + return rec << 5; +} + +static int is_hz_left(int c) +{ + if (c < 0x80) + return 0; + c = c & 0x7f; + return (c >= 0x21 && c <= 0x7e); +} + +static int is_hz_right(int c) +{ + if (c < 0x80) + return 0; + c = c & 0x7f; + return (c >= 21 && c <= 0x7e); +} + +#ifdef MODULE +static struct double_byte db_jis = +#else +struct double_byte db_jis = +#endif +{ + 0, + "JIS", + is_hz_left, + is_hz_right, + index_jis, + 16,16, + max_jis16, + font_jis16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == (DBFontManager *) 0) + return 1; + if (UniconFontManager->registerfont (XL_DB_JIS, &db_jis) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == (DBFontManager *) 0) + return; + UniconFontManager->unregisterfont (XL_DB_JIS); +} +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/encode-kscm.c linux-3.15/drivers/video/unicon/encode-kscm.c --- linux-3.15.orig/drivers/video/unicon/encode-kscm.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-kscm.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,99 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#include +#include +#include "font_kscm16.h" +// 0x2121 -- 0x7d7e + +/* + the KSC5601 standard internal code is + start at 8481 ===> 0x2121 + end at 32126 ===> 0x7d7e +*/ + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int index_kscm(int left, int right) +{ + int rec; + left = left & 0x7f; + right = right & 0x7f; + rec = (left - 0x21) * (0x7e - 0x21 + 1) + right - 0x21; + return rec << 5; +} + +static int is_hz_left(int c) +{ + if (c < 0x80) + return 0; + c = c & 0x7f; + return (c >= 0x21 && c <= 0x7d); +} + +static int is_hz_right(int c) +{ + if (c < 0x80) + return 0; + c = c & 0x7f; + return (c >= 21 && c <= 0x7e); +} + +#ifdef MODULE +static struct double_byte db_kscm = +#else +struct double_byte db_kscm = +#endif +{ + 0, + "kscm", + is_hz_left, + is_hz_right, + index_kscm, + 16,16, + max_kscm16, + font_kscm16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == 0) + return 1; + if (UniconFontManager->registerfont (XL_DB_KSCM, &db_kscm) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == 0) + return; + UniconFontManager->unregisterfont (XL_DB_KSCM); +} +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/encode-sjis.c linux-3.15/drivers/video/unicon/encode-sjis.c --- linux-3.15.orig/drivers/video/unicon/encode-sjis.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/encode-sjis.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,111 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#include +#include +#include "font_eucjp16.h" +#define min1 0x81 +#define max1 0xfc +// 0x2121 -- 0x7424 + +#ifdef MODULE_LICENSE +MODULE_LICENSE("GPL"); +#endif + +static int is_hz_left(int c) +{ + return ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)); +} + +static int is_hz_right(int c) +{ + return ((c >= 0x40 && c <= 0x7e) || (c >= 0x80 && c <= 0xfc)); +} + +static int index_sjis(int left, int right) +{ + int ch1, ch2; + + if ( !is_hz_left(left) || !is_hz_right(right) ) return -512; + + ch1 = left; + ch2 = right; + + if ( ch1 <= 0x9f ) + ch1 -= 0x71; + else + ch1 -= 0xb1; + ch1 *= 2; + ++ch1; + + if ( ch2 >= 0x7f ) + --ch2; + if ( ch2 >= 0x9e ) { + ch2 -= 0x7d; + ++ch1; + } else { + ch2 -= 0x1f; + } + + if (ch1 > 0x29) + return ((ch2 - 0x40 + (ch1 - 0x25) * 96) << 5); + else + return ((ch2 - 0x20 + (ch1 - 0x20) * 96) << 5); +} + +#ifdef MODULE +static struct double_byte db_sjis = +#else +struct double_byte db_sjis = +#endif +{ + 0, + "SJIS", + is_hz_left, + is_hz_right, + index_sjis, + 16,16, + max_jis16, + font_jis16 +}; + +#ifdef MODULE +int init_module(void) +{ + if (UniconFontManager == (DBFontManager *) 0) + return 1; + if (UniconFontManager->registerfont (XL_DB_SJIS, &db_sjis) == 0) + return 1; + return 0; +} + +void cleanup_module(void) +{ + if (UniconFontManager == (DBFontManager *) 0) + return; + UniconFontManager->unregisterfont (XL_DB_SJIS); +} +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/unikey.h linux-3.15/drivers/video/unicon/unikey.h --- linux-3.15.orig/drivers/video/unicon/unikey.h 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/unikey.h 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,104 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#ifndef UNIDEV_H +#define UNIDEV_H + +#include +#include +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) +#include "../console/fbcon.h" +#endif + +typedef struct __ChinesePut_T__ +{ + int x, y; + unsigned char c1, c2; + long cl; +} +ChinesePut_T; + +typedef struct __AsciiPut_T__ +{ + int x, y; + unsigned char ch; + long cl; +} +AsciiPut_T; + +typedef struct __VtInfo_T__ +{ + int vt_has_resized; + int width, height; +} +VtInfo_T; + +typedef struct __VtFont_T__ +{ + int tty; + int font_type; + int input_method_notify; +} VtFont_T; + +#define DEVICE_FILE_NAME "/dev/unikey" +#define MAJOR_NUM 10 +#define MINOR_NUM 202 +#define UNIKEY_IOCTL 100 +#define UNI_INPUT_GET_INFO _IOR(UNIKEY_IOCTL, 0, char *) +#define UNI_INPUT_SET_INFO _IOR(UNIKEY_IOCTL, 1, char *) +#define UNI_INPUT_REGISTER _IOR(UNIKEY_IOCTL, 2, char *) +#define UNI_INPUT_UNREGISTER _IOR(UNIKEY_IOCTL, 3, char *) + +#define UNI_INPUT_PUT_ASCII _IOR(UNIKEY_IOCTL, 4, AsciiPut_T *) +#define UNI_INPUT_PUT_CHINESE _IOR(UNIKEY_IOCTL, 5, ChinesePut_T *) +#define UNI_INPUT_CLS_BOTTOM _IOR(UNIKEY_IOCTL, 6, char *) +#define UNI_INPUT_GET_VT_INFO _IOR(UNIKEY_IOCTL, 7, VtInfo_T *) + +#define UNI_INPUT_SET_CUR_TTY _IOR(UNIKEY_IOCTL, 8, VtInfo_T *) +#define UNI_INPUT_SET_RESIZE_FLAG _IOR(UNIKEY_IOCTL, 9, char *) +#define UNI_INPUT_SET_UNRESIZE_FLAG _IOR(UNIKEY_IOCTL, 10, char *) +#define UNI_SET_CURRENT_FONT _IOR(UNIKEY_IOCTL, 11, VtFont_T *) + +#define MAXTTYS 6 +#define SUCCESS 0 +#define DEVICE_NAME "unikey" +#define BUF_LEN 80 +#define MAX_CHAR 8 + +/* op */ +#define FLUSH_BOTTOM 1 +#define FLUSH_INPUTMETHOD 2 + +typedef struct __TTY_KEY_T__ +{ + u_char nTty; + u_char op; //bFlushInput; + u_char buf[MAX_CHAR]; + u_char nTotal; +} +TTY_KEY_T; +extern int nCurTty; +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/xl_fm.c linux-3.15/drivers/video/unicon/xl_fm.c --- linux-3.15.orig/drivers/video/unicon/xl_fm.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/xl_fm.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,186 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +/* This is the main entry of font manager of UNICON */ + +#include +#include +#include +#include +#include +#include +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) +#include +#endif +#include + + +// #define __XL_DEBUG__ +typedef struct DBFontRegister_T +{ + int font_type; + struct double_byte *p; +} DBFont; + +static DBFont TtyDbFont[MAX_TTY]; +static DBFont aDbFont[MAX_FONT]; + +static void XL_InitDBFont (void); +static int XL_RegisterDBFont (int font_type, struct double_byte *p); +static int XL_UnregisterDBFont (int font_type); +static int XL_IsAvailable (int font_type); +static struct double_byte *XL_GetTtyDBFont (int tty); +static int XL_SetTtyDbFont (int tty, int font_type); +static void ReleaseAllTtyFont (int font_type); + +static void XL_InitDBFont () +{ +#ifdef __XL_DEBUG__ + printk ("XL_InitDBFont () \n"); +#endif + memset (aDbFont, 0, sizeof (aDbFont) * MAX_FONT); + memset (TtyDbFont, 0, sizeof (TtyDbFont) * MAX_TTY); +} + +static int XL_RegisterDBFont (int font_type, struct double_byte *p) +{ +#ifdef __XL_DEBUG__ + printk ("XL_RegisterDBFont (font_type=%d, double_byte=0x%x)\n", font_type, (long) p); +#endif + if (font_type < 0 || font_type >= MAX_FONT) + return 0; + if (aDbFont[font_type].p != NULL) + return 0; + aDbFont[font_type].font_type = font_type; + aDbFont[font_type].p = p; + return 1; +} + +static int XL_UnregisterDBFont (int font_type) +{ +#ifdef __XL_DEBUG__ + printk ("XL_UnregisterDBFont (font_type=%d)\n", font_type); +#endif + if (font_type < 0 || font_type >= MAX_FONT) + return 0; + ReleaseAllTtyFont (font_type); + memset (&aDbFont[font_type], 0, sizeof (DBFont)); + return 1; +} + +static int XL_IsAvailable (int font_type) +{ +#ifdef __XL_DEBUG__ + printk ("XL_IsAvailable (font_type=%d)\n", font_type); +#endif + if (font_type < 0 || font_type >= MAX_FONT) + return 0; + if (aDbFont[font_type].p != NULL) + return 1; + return 0; +} + +static struct double_byte *XL_GetTtyDBFont (int tty) +{ +#ifdef __XL_DEBUG__ + printk ("XL_GetTtyDBFont (tty=%d)\n", tty); +#endif + if (tty < 0 || tty >= MAX_TTY) + return NULL; + if (TtyDbFont[tty].p != NULL) + return TtyDbFont[tty].p; + else + return NULL; +} + +static int XL_SetTtyDbFont (int tty, int font_type) +{ +#ifdef __XL_DEBUG__ + printk ("XL_SetTtyDBFont (tty=%d, font_type=%d)\n", tty, font_type); +#endif + if (font_type < 0 || font_type >= MAX_FONT) + return 0; + if (tty < 0 || tty >= MAX_TTY) + return 0; + if (XL_IsAvailable (font_type) == 0) + return 0; + TtyDbFont[tty].font_type = font_type; + TtyDbFont[tty].p = aDbFont[font_type].p; + return 1; +} + +static void ReleaseAllTtyFont (int font_type) +{ + int i; +#ifdef __XL_DEBUG__ + printk ("ReleaseAllTtyFont (font_type=%d)\n", font_type); +#endif + if (font_type < 0 || font_type >= MAX_FONT) + return; + for (i = 0; i < MAX_TTY; i++) + { + if (TtyDbFont[i].font_type == font_type) + memset (&TtyDbFont[i], 0, sizeof (DBFont)); + } +} + +static DBFontManager UniconFontManagerAbc = +{ + /* init */ + XL_InitDBFont, /* init */ + + /* font manager */ + XL_RegisterDBFont, /* register */ + XL_UnregisterDBFont, /* unregister */ + XL_IsAvailable, /* test available */ + + /* tty font manager */ + XL_GetTtyDBFont, + XL_SetTtyDbFont, +}; + +void UniconFontManagerOpen (void) +{ +#ifdef __XL_DEBUG__ + printk ("void UniconFontManagerOpen ()\n"); +#endif + UniconFontManager = &UniconFontManagerAbc; +} + +void UniconFontManagerClose (void) +{ +#ifdef __XL_DEBUG__ + printk ("void UniconFontManagerClose ()\n"); +#endif +/* + ReleaseAllTtyFont (XL_DB_GB); + ReleaseAllTtyFont (XL_DB_GBK); + ReleaseAllTtyFont (XL_DB_BIG5); + ReleaseAllTtyFont (XL_DB_JIS); + ReleaseAllTtyFont (XL_DB_KSCM); + */ + UniconFontManager = 0; +} + diff -urNp linux-3.15.orig/drivers/video/unicon/xl_funckeys.h linux-3.15/drivers/video/unicon/xl_funckeys.h --- linux-3.15.orig/drivers/video/unicon/xl_funckeys.h 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/xl_funckeys.h 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,54 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#ifndef __XL_FUNCKEY_H__ +#define __XL_FUNCKEY_H__ +/* + printscreen 0xe0, 0xe0, 0x37, 0xe0, 0xb7, 0xe0 + pause break 0xe1 0x45, 0xe1, 0xc5 + insert 0xe0 0x52 0xe0 0xd2 + home 0xe0 0x47 0xe0 0xc7 + pageup 0xe0 0x49 0xe0 0x79 + delete 0xe0 0x53 0xe0 0xd3 + end 0xe0 0x4f 0xe0 0xcf + pagedown 0xe0 0x51 0xe0 0xd1 + up 0xe0 0x48 0xe0 0xc8 + down 0xe0 0x50 0xe0 0xd0 + left 0xe0 0x4b 0xe0 0xcb + right 0xe0 0x4d 0xe0 0xcd + wakeup 0xe0 0x63 0xe0 0xe3 + sleep 0xe0 0x5f 0xe0 0xdf + power 0xe0 0x5e 0xe0 0xde + / 0xe0 0x35 0xe0 0xb5 + right enter 0xe0 0x1c 0xe0 0x9c + windows special keys support + left1 0xe0 0x5b 0xe0 0xdb + right1 0xe0 0x5c 0xe0 0xdc + right2 0xe0 0x5d 0xe0 0xdd +*/ + scrolllock 0x46, 0xc6 + numlock 0x45 0xc5 +#endif + diff -urNp linux-3.15.orig/drivers/video/unicon/xl_hzfb.c linux-3.15/drivers/video/unicon/xl_hzfb.c --- linux-3.15.orig/drivers/video/unicon/xl_hzfb.c 1970-01-01 09:00:00.000000000 +0900 +++ linux-3.15/drivers/video/unicon/xl_hzfb.c 2014-06-09 09:00:22.000000000 +0900 @@ -0,0 +1,154 @@ +/* + * + * UNICON - The Console Chinese & I18N + * Copyright (c) 1999-2000 + * + * This file is part of UNICON, a console Chinese & I18N + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * See the file COPYING directory of this archive + * Author: see CREDITS + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) +#include +#endif +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) +#include "../console/fbcon.h" +#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)) +#include