2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/config.h>
62 #include <linux/module.h>
63 #include <linux/types.h>
64 #include <linux/sched.h>
66 #include <linux/kernel.h>
67 #include <linux/delay.h> /* MSch: for IRQ probe */
68 #include <linux/tty.h>
69 #include <linux/console.h>
70 #include <linux/string.h>
72 #include <linux/slab.h>
74 #include <linux/vt_kern.h>
75 #include <linux/selection.h>
76 #include <linux/font.h>
77 #include <linux/smp.h>
78 #include <linux/init.h>
79 #include <linux/interrupt.h>
80 #include <linux/crc32.h> /* For counting font checksums */
82 #include <asm/system.h>
83 #include <asm/uaccess.h>
85 #include <asm/atariints.h>
88 #include <asm/macints.h>
90 #if defined(__mc68000__) || defined(CONFIG_APUS)
91 #include <asm/machdep.h>
92 #include <asm/setup.h>
98 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
100 # define DPRINTK(fmt, args...)
104 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
105 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
106 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
109 static struct display fb_display[MAX_NR_CONSOLES];
111 static signed char con2fb_map[MAX_NR_CONSOLES];
112 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
113 static int logo_height;
114 static int logo_lines;
115 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
117 static int logo_shown = FBCON_LOGO_CANSHOW;
118 /* Software scrollback */
119 static int fbcon_softback_size = 32768;
120 static unsigned long softback_buf, softback_curr;
121 static unsigned long softback_in;
122 static unsigned long softback_top, softback_end;
123 static int softback_lines;
124 /* console mappings */
125 static int first_fb_vc;
126 static int last_fb_vc = MAX_NR_CONSOLES - 1;
127 static int fbcon_is_default = 1;
129 static char fontname[40];
131 /* current fb_info */
132 static int info_idx = -1;
134 /* console rotation */
137 static const struct consw fb_con;
139 #define CM_SOFTBACK (8)
141 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
143 static void fbcon_free_font(struct display *);
144 static int fbcon_set_origin(struct vc_data *);
146 #define CURSOR_DRAW_DELAY (1)
148 /* # VBL ints between cursor state changes */
149 #define ATARI_CURSOR_BLINK_RATE (42)
150 #define MAC_CURSOR_BLINK_RATE (32)
151 #define DEFAULT_CURSOR_BLINK_RATE (20)
153 static int vbl_cursor_cnt;
155 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
158 * Interface used by the world
161 static const char *fbcon_startup(void);
162 static void fbcon_init(struct vc_data *vc, int init);
163 static void fbcon_deinit(struct vc_data *vc);
164 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
166 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
167 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
168 int count, int ypos, int xpos);
169 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
170 static void fbcon_cursor(struct vc_data *vc, int mode);
171 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
173 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
174 int height, int width);
175 static int fbcon_switch(struct vc_data *vc);
176 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
177 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
178 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
183 static __inline__ void ywrap_up(struct vc_data *vc, int count);
184 static __inline__ void ywrap_down(struct vc_data *vc, int count);
185 static __inline__ void ypan_up(struct vc_data *vc, int count);
186 static __inline__ void ypan_down(struct vc_data *vc, int count);
187 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
188 int dy, int dx, int height, int width, u_int y_break);
189 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
193 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
194 int line, int count, int dy);
195 static void fbcon_modechanged(struct fb_info *info);
196 static void fbcon_set_all_vcs(struct fb_info *info);
200 * On the Macintoy, there may or may not be a working VBL int. We need to probe
202 static int vbl_detected;
204 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
211 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
212 static inline void fbcon_set_rotation(struct fb_info *info)
214 struct fbcon_ops *ops = info->fbcon_par;
216 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
217 ops->p->con_rotate < 4)
218 ops->rotate = ops->p->con_rotate;
223 static void fbcon_rotate(struct fb_info *info, u32 rotate)
225 struct fbcon_ops *ops= info->fbcon_par;
226 struct fb_info *fb_info;
228 if (!ops || ops->currcon == -1)
231 fb_info = registered_fb[con2fb_map[ops->currcon]];
233 if (info == fb_info) {
234 struct display *p = &fb_display[ops->currcon];
237 p->con_rotate = rotate;
241 fbcon_modechanged(info);
245 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
247 struct fbcon_ops *ops = info->fbcon_par;
252 if (!ops || ops->currcon < 0 || rotate > 3)
255 for (i = 0; i < MAX_NR_CONSOLES; i++) {
257 if (!vc || vc->vc_mode != KD_TEXT ||
258 registered_fb[con2fb_map[i]] != info)
261 p = &fb_display[vc->vc_num];
262 p->con_rotate = rotate;
265 fbcon_set_all_vcs(info);
268 static inline void fbcon_set_rotation(struct fb_info *info)
270 struct fbcon_ops *ops = info->fbcon_par;
272 ops->rotate = FB_ROTATE_UR;
275 static void fbcon_rotate(struct fb_info *info, u32 rotate)
280 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
284 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
286 static int fbcon_get_rotate(struct fb_info *info)
288 struct fbcon_ops *ops = info->fbcon_par;
290 return (ops) ? ops->rotate : 0;
293 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
295 struct fbcon_ops *ops = info->fbcon_par;
297 return (info->state != FBINFO_STATE_RUNNING ||
298 vc->vc_mode != KD_TEXT || ops->graphics);
301 static inline int get_color(struct vc_data *vc, struct fb_info *info,
304 int depth = fb_get_color_depth(&info->var, &info->fix);
307 if (console_blanked) {
308 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
310 c = vc->vc_video_erase_char & charmask;
314 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
315 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
320 int col = ~(0xfff << (max(info->var.green.length,
321 max(info->var.red.length,
322 info->var.blue.length)))) & 0xff;
325 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
326 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
331 color = (is_fg) ? fg : bg;
336 * Scale down 16-colors to 4 colors. Default 4-color palette
337 * is grayscale. However, simply dividing the values by 4
338 * will not work, as colors 1, 2 and 3 will be scaled-down
339 * to zero rendering them invisible. So empirically convert
340 * colors to a sane 4-level grayscale.
344 color = 0; /* black */
347 color = 2; /* white */
350 color = 1; /* gray */
353 color = 3; /* intense white */
359 * Last 8 entries of default 16-color palette is a more intense
360 * version of the first 8 (i.e., same chrominance, different
371 static void fbcon_update_softback(struct vc_data *vc)
373 int l = fbcon_softback_size / vc->vc_size_row;
376 softback_end = softback_buf + l * vc->vc_size_row;
378 /* Smaller scrollback makes no sense, and 0 would screw
379 the operation totally */
383 static void fb_flashcursor(void *private)
385 struct fb_info *info = private;
386 struct fbcon_ops *ops = info->fbcon_par;
388 struct vc_data *vc = NULL;
392 if (ops->currcon != -1)
393 vc = vc_cons[ops->currcon].d;
395 if (!vc || !CON_IS_VISIBLE(vc) ||
396 fbcon_is_inactive(vc, info) ||
397 registered_fb[con2fb_map[vc->vc_num]] != info ||
398 vc_cons[ops->currcon].d->vc_deccm != 1)
400 acquire_console_sem();
401 p = &fb_display[vc->vc_num];
402 c = scr_readw((u16 *) vc->vc_pos);
403 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
405 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
406 get_color(vc, info, c, 0));
407 release_console_sem();
410 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
411 static int cursor_blink_rate;
412 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
414 struct fb_info *info = dev_id;
416 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
417 schedule_work(&info->queue);
418 vbl_cursor_cnt = cursor_blink_rate;
424 static void cursor_timer_handler(unsigned long dev_addr)
426 struct fb_info *info = (struct fb_info *) dev_addr;
427 struct fbcon_ops *ops = info->fbcon_par;
429 schedule_work(&info->queue);
430 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
433 static void fbcon_add_cursor_timer(struct fb_info *info)
435 struct fbcon_ops *ops = info->fbcon_par;
437 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
438 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
439 if (!info->queue.func)
440 INIT_WORK(&info->queue, fb_flashcursor, info);
442 init_timer(&ops->cursor_timer);
443 ops->cursor_timer.function = cursor_timer_handler;
444 ops->cursor_timer.expires = jiffies + HZ / 5;
445 ops->cursor_timer.data = (unsigned long ) info;
446 add_timer(&ops->cursor_timer);
447 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
451 static void fbcon_del_cursor_timer(struct fb_info *info)
453 struct fbcon_ops *ops = info->fbcon_par;
455 if (info->queue.func == fb_flashcursor &&
456 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
457 del_timer_sync(&ops->cursor_timer);
458 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
463 static int __init fb_console_setup(char *this_opt)
468 if (!this_opt || !*this_opt)
471 while ((options = strsep(&this_opt, ",")) != NULL) {
472 if (!strncmp(options, "font:", 5))
473 strcpy(fontname, options + 5);
475 if (!strncmp(options, "scrollback:", 11)) {
478 fbcon_softback_size = simple_strtoul(options, &options, 0);
479 if (*options == 'k' || *options == 'K') {
480 fbcon_softback_size *= 1024;
490 if (!strncmp(options, "map:", 4)) {
493 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
497 (options[j++]-'0') % FB_MAX;
502 if (!strncmp(options, "vc:", 3)) {
505 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
508 if (*options++ == '-')
509 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
510 fbcon_is_default = 0;
513 if (!strncmp(options, "rotate:", 7)) {
516 rotate = simple_strtoul(options, &options, 0);
524 __setup("fbcon=", fb_console_setup);
527 static int search_fb_in_map(int idx)
531 for (i = 0; i < MAX_NR_CONSOLES; i++) {
532 if (con2fb_map[i] == idx)
538 static int search_for_mapped_con(void)
542 for (i = 0; i < MAX_NR_CONSOLES; i++) {
543 if (con2fb_map[i] != -1)
549 static int fbcon_takeover(int show_logo)
553 if (!num_registered_fb)
557 logo_shown = FBCON_LOGO_DONTSHOW;
559 for (i = first_fb_vc; i <= last_fb_vc; i++)
560 con2fb_map[i] = info_idx;
562 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
565 for (i = first_fb_vc; i <= last_fb_vc; i++) {
574 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
575 int cols, int rows, int new_cols, int new_rows)
577 /* Need to make room for the logo */
578 struct fbcon_ops *ops = info->fbcon_par;
579 int cnt, erase = vc->vc_video_erase_char, step;
580 unsigned short *save = NULL, *r, *q;
583 * remove underline attribute from erase character
584 * if black and white framebuffer.
586 if (fb_get_color_depth(&info->var, &info->fix) == 1)
588 logo_height = fb_prepare_logo(info, ops->rotate);
589 logo_lines = (logo_height + vc->vc_font.height - 1) /
591 q = (unsigned short *) (vc->vc_origin +
592 vc->vc_size_row * rows);
593 step = logo_lines * cols;
594 for (r = q - logo_lines * cols; r < q; r++)
595 if (scr_readw(r) != vc->vc_video_erase_char)
597 if (r != q && new_rows >= rows + logo_lines) {
598 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
600 int i = cols < new_cols ? cols : new_cols;
601 scr_memsetw(save, erase, logo_lines * new_cols * 2);
603 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
604 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
609 /* We can scroll screen down */
611 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
612 scr_memcpyw(r + step, r, vc->vc_size_row);
616 vc->vc_y += logo_lines;
617 vc->vc_pos += logo_lines * vc->vc_size_row;
620 scr_memsetw((unsigned short *) vc->vc_origin,
622 vc->vc_size_row * logo_lines);
624 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
625 fbcon_clear_margins(vc, 0);
630 q = (unsigned short *) (vc->vc_origin +
633 scr_memcpyw(q, save, logo_lines * new_cols * 2);
634 vc->vc_y += logo_lines;
635 vc->vc_pos += logo_lines * vc->vc_size_row;
639 if (logo_lines > vc->vc_bottom) {
640 logo_shown = FBCON_LOGO_CANSHOW;
642 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
643 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
644 logo_shown = FBCON_LOGO_DRAW;
645 vc->vc_top = logo_lines;
649 #ifdef CONFIG_FB_TILEBLITTING
650 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
652 struct fbcon_ops *ops = info->fbcon_par;
654 ops->p = &fb_display[vc->vc_num];
656 if ((info->flags & FBINFO_MISC_TILEBLITTING))
657 fbcon_set_tileops(vc, info);
659 fbcon_set_rotation(info);
660 fbcon_set_bitops(ops);
664 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
666 struct fbcon_ops *ops = info->fbcon_par;
668 info->flags &= ~FBINFO_MISC_TILEBLITTING;
669 ops->p = &fb_display[vc->vc_num];
670 fbcon_set_rotation(info);
671 fbcon_set_bitops(ops);
673 #endif /* CONFIG_MISC_TILEBLITTING */
676 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
677 int unit, int oldidx)
679 struct fbcon_ops *ops = NULL;
682 if (!try_module_get(info->fbops->owner))
685 if (!err && info->fbops->fb_open &&
686 info->fbops->fb_open(info, 0))
690 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
696 memset(ops, 0, sizeof(struct fbcon_ops));
697 info->fbcon_par = ops;
698 set_blitting_type(vc, info);
702 con2fb_map[unit] = oldidx;
703 module_put(info->fbops->owner);
709 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
710 struct fb_info *newinfo, int unit,
711 int oldidx, int found)
713 struct fbcon_ops *ops = oldinfo->fbcon_par;
716 if (oldinfo->fbops->fb_release &&
717 oldinfo->fbops->fb_release(oldinfo, 0)) {
718 con2fb_map[unit] = oldidx;
719 if (!found && newinfo->fbops->fb_release)
720 newinfo->fbops->fb_release(newinfo, 0);
722 module_put(newinfo->fbops->owner);
727 fbcon_del_cursor_timer(oldinfo);
728 kfree(ops->cursor_state.mask);
729 kfree(ops->cursor_data);
730 kfree(ops->fontbuffer);
731 kfree(oldinfo->fbcon_par);
732 oldinfo->fbcon_par = NULL;
733 module_put(oldinfo->fbops->owner);
735 If oldinfo and newinfo are driving the same hardware,
736 the fb_release() method of oldinfo may attempt to
737 restore the hardware state. This will leave the
738 newinfo in an undefined state. Thus, a call to
739 fb_set_par() may be needed for the newinfo.
741 if (newinfo->fbops->fb_set_par)
742 newinfo->fbops->fb_set_par(newinfo);
748 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
749 int unit, int show_logo)
751 struct fbcon_ops *ops = info->fbcon_par;
753 ops->currcon = fg_console;
755 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
756 info->fbops->fb_set_par(info);
758 ops->flags |= FBCON_FLAGS_INIT;
762 fbcon_set_disp(info, &info->var, vc);
764 fbcon_preset_disp(info, &info->var, unit);
767 struct vc_data *fg_vc = vc_cons[fg_console].d;
768 struct fb_info *fg_info =
769 registered_fb[con2fb_map[fg_console]];
771 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
772 fg_vc->vc_rows, fg_vc->vc_cols,
776 update_screen(vc_cons[fg_console].d);
780 * set_con2fb_map - map console to frame buffer device
781 * @unit: virtual console number to map
782 * @newidx: frame buffer index to map virtual console to
783 * @user: user request
785 * Maps a virtual console @unit to a frame buffer device
788 static int set_con2fb_map(int unit, int newidx, int user)
790 struct vc_data *vc = vc_cons[unit].d;
791 int oldidx = con2fb_map[unit];
792 struct fb_info *info = registered_fb[newidx];
793 struct fb_info *oldinfo = NULL;
796 if (oldidx == newidx)
802 if (!err && !search_for_mapped_con()) {
804 return fbcon_takeover(0);
808 oldinfo = registered_fb[oldidx];
810 found = search_fb_in_map(newidx);
812 acquire_console_sem();
813 con2fb_map[unit] = newidx;
815 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
819 * If old fb is not mapped to any of the consoles,
820 * fbcon should release it.
822 if (!err && oldinfo && !search_fb_in_map(oldidx))
823 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
827 int show_logo = (fg_console == 0 && !user &&
828 logo_shown != FBCON_LOGO_DONTSHOW);
831 fbcon_add_cursor_timer(info);
832 con2fb_map_boot[unit] = newidx;
833 con2fb_init_display(vc, info, unit, show_logo);
836 release_console_sem();
841 * Low Level Operations
843 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
844 static int var_to_display(struct display *disp,
845 struct fb_var_screeninfo *var,
846 struct fb_info *info)
848 disp->xres_virtual = var->xres_virtual;
849 disp->yres_virtual = var->yres_virtual;
850 disp->bits_per_pixel = var->bits_per_pixel;
851 disp->grayscale = var->grayscale;
852 disp->nonstd = var->nonstd;
853 disp->accel_flags = var->accel_flags;
854 disp->height = var->height;
855 disp->width = var->width;
856 disp->red = var->red;
857 disp->green = var->green;
858 disp->blue = var->blue;
859 disp->transp = var->transp;
860 disp->rotate = var->rotate;
861 disp->mode = fb_match_mode(var, &info->modelist);
862 if (disp->mode == NULL)
863 /* This should not happen */
868 static void display_to_var(struct fb_var_screeninfo *var,
869 struct display *disp)
871 fb_videomode_to_var(var, disp->mode);
872 var->xres_virtual = disp->xres_virtual;
873 var->yres_virtual = disp->yres_virtual;
874 var->bits_per_pixel = disp->bits_per_pixel;
875 var->grayscale = disp->grayscale;
876 var->nonstd = disp->nonstd;
877 var->accel_flags = disp->accel_flags;
878 var->height = disp->height;
879 var->width = disp->width;
880 var->red = disp->red;
881 var->green = disp->green;
882 var->blue = disp->blue;
883 var->transp = disp->transp;
884 var->rotate = disp->rotate;
887 static const char *fbcon_startup(void)
889 const char *display_desc = "frame buffer device";
890 struct display *p = &fb_display[fg_console];
891 struct vc_data *vc = vc_cons[fg_console].d;
892 const struct font_desc *font = NULL;
893 struct module *owner;
894 struct fb_info *info = NULL;
895 struct fbcon_ops *ops;
901 * If num_registered_fb is zero, this is a call for the dummy part.
902 * The frame buffer devices weren't initialized yet.
904 if (!num_registered_fb || info_idx == -1)
907 * Instead of blindly using registered_fb[0], we use info_idx, set by
910 info = registered_fb[info_idx];
914 owner = info->fbops->owner;
915 if (!try_module_get(owner))
917 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
922 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
928 memset(ops, 0, sizeof(struct fbcon_ops));
931 ops->cur_rotate = -1;
932 info->fbcon_par = ops;
933 p->con_rotate = rotate;
934 set_blitting_type(vc, info);
936 if (info->fix.type != FB_TYPE_TEXT) {
937 if (fbcon_softback_size) {
941 kmalloc(fbcon_softback_size,
944 fbcon_softback_size = 0;
950 kfree((void *) softback_buf);
956 softback_in = softback_top = softback_curr =
961 /* Setup default font */
963 if (!fontname[0] || !(font = find_font(fontname)))
964 font = get_default_font(info->var.xres,
966 vc->vc_font.width = font->width;
967 vc->vc_font.height = font->height;
968 vc->vc_font.data = (void *)(p->fontdata = font->data);
969 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
972 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
973 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
974 cols /= vc->vc_font.width;
975 rows /= vc->vc_font.height;
976 vc_resize(vc, cols, rows);
978 DPRINTK("mode: %s\n", info->fix.id);
979 DPRINTK("visual: %d\n", info->fix.visual);
980 DPRINTK("res: %dx%d-%d\n", info->var.xres,
982 info->var.bits_per_pixel);
986 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
988 request_irq(IRQ_AUTO_4, fb_vbl_handler,
989 IRQ_TYPE_PRIO, "framebuffer vbl",
992 #endif /* CONFIG_ATARI */
996 * On a Macintoy, the VBL interrupt may or may not be active.
997 * As interrupt based cursor is more reliable and race free, we
998 * probe for VBL interrupts.
1003 * Probe for VBL: set temp. handler ...
1005 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1006 "framebuffer vbl", info);
1010 * ... and spin for 20 ms ...
1012 while (!vbl_detected && ++ct < 1000)
1017 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1019 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1023 * interrupt based cursor ok
1025 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1027 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1028 "framebuffer vbl", info);
1031 * VBL not detected: fall through, use timer based cursor
1036 #endif /* CONFIG_MAC */
1038 fbcon_add_cursor_timer(info);
1039 return display_desc;
1042 static void fbcon_init(struct vc_data *vc, int init)
1044 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1045 struct fbcon_ops *ops;
1046 struct vc_data **default_mode = vc->vc_display_fg;
1047 struct vc_data *svc = *default_mode;
1048 struct display *t, *p = &fb_display[vc->vc_num];
1049 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1052 if (info_idx == -1 || info == NULL)
1057 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1058 (info->fix.type == FB_TYPE_TEXT))
1061 if (var_to_display(p, &info->var, info))
1064 /* If we are not the first console on this
1065 fb, copy the font from that console */
1066 t = &fb_display[svc->vc_num];
1067 if (!vc->vc_font.data) {
1068 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1069 vc->vc_font.width = (*default_mode)->vc_font.width;
1070 vc->vc_font.height = (*default_mode)->vc_font.height;
1071 p->userfont = t->userfont;
1073 REFCOUNT(p->fontdata)++;
1076 charcnt = FNTCHARCNT(p->fontdata);
1077 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1078 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1079 if (charcnt == 256) {
1080 vc->vc_hi_font_mask = 0;
1082 vc->vc_hi_font_mask = 0x100;
1083 if (vc->vc_can_do_color)
1084 vc->vc_complement_mask <<= 1;
1087 if (!*svc->vc_uni_pagedir_loc)
1088 con_set_default_unimap(svc);
1089 if (!*vc->vc_uni_pagedir_loc)
1090 con_copy_unimap(vc, svc);
1092 ops = info->fbcon_par;
1093 p->con_rotate = rotate;
1094 set_blitting_type(vc, info);
1098 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1099 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1100 new_cols /= vc->vc_font.width;
1101 new_rows /= vc->vc_font.height;
1102 vc_resize(vc, new_cols, new_rows);
1105 * We must always set the mode. The mode of the previous console
1106 * driver could be in the same resolution but we are using different
1107 * hardware so we have to initialize the hardware.
1109 * We need to do it in fbcon_init() to prevent screen corruption.
1111 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1112 if (info->fbops->fb_set_par &&
1113 !(ops->flags & FBCON_FLAGS_INIT))
1114 info->fbops->fb_set_par(info);
1115 ops->flags |= FBCON_FLAGS_INIT;
1120 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1121 !(cap & FBINFO_HWACCEL_DISABLED))
1122 p->scrollmode = SCROLL_MOVE;
1123 else /* default to something safe */
1124 p->scrollmode = SCROLL_REDRAW;
1127 * ++guenther: console.c:vc_allocate() relies on initializing
1128 * vc_{cols,rows}, but we must not set those if we are only
1129 * resizing the console.
1132 vc->vc_cols = new_cols;
1133 vc->vc_rows = new_rows;
1137 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1139 if (vc == svc && softback_buf)
1140 fbcon_update_softback(vc);
1142 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1143 ops->rotate = FB_ROTATE_UR;
1144 set_blitting_type(vc, info);
1149 static void fbcon_deinit(struct vc_data *vc)
1151 struct display *p = &fb_display[vc->vc_num];
1158 /* ====================================================================== */
1160 /* fbcon_XXX routines - interface used by the world
1162 * This system is now divided into two levels because of complications
1163 * caused by hardware scrolling. Top level functions:
1165 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1167 * handles y values in range [0, scr_height-1] that correspond to real
1168 * screen positions. y_wrap shift means that first line of bitmap may be
1169 * anywhere on this display. These functions convert lineoffsets to
1170 * bitmap offsets and deal with the wrap-around case by splitting blits.
1172 * fbcon_bmove_physical_8() -- These functions fast implementations
1173 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1174 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1178 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1179 * Implies should only really hardware scroll in rows. Only reason for
1180 * restriction is simplicity & efficiency at the moment.
1183 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1186 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1187 struct fbcon_ops *ops = info->fbcon_par;
1189 struct display *p = &fb_display[vc->vc_num];
1192 if (fbcon_is_inactive(vc, info))
1195 if (!height || !width)
1198 /* Split blits that cross physical y_wrap boundary */
1200 y_break = p->vrows - p->yscroll;
1201 if (sy < y_break && sy + height - 1 >= y_break) {
1202 u_int b = y_break - sy;
1203 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1204 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1207 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1210 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1211 int count, int ypos, int xpos)
1213 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1214 struct display *p = &fb_display[vc->vc_num];
1215 struct fbcon_ops *ops = info->fbcon_par;
1217 if (!fbcon_is_inactive(vc, info))
1218 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1219 get_color(vc, info, scr_readw(s), 1),
1220 get_color(vc, info, scr_readw(s), 0));
1223 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1227 scr_writew(c, &chr);
1228 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1231 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1233 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1234 struct fbcon_ops *ops = info->fbcon_par;
1236 if (!fbcon_is_inactive(vc, info))
1237 ops->clear_margins(vc, info, bottom_only);
1240 static void fbcon_cursor(struct vc_data *vc, int mode)
1242 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1243 struct fbcon_ops *ops = info->fbcon_par;
1245 int c = scr_readw((u16 *) vc->vc_pos);
1247 if (fbcon_is_inactive(vc, info))
1250 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1251 if (mode & CM_SOFTBACK) {
1252 mode &= ~CM_SOFTBACK;
1256 fbcon_set_origin(vc);
1260 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1261 get_color(vc, info, c, 0));
1262 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1265 static int scrollback_phys_max = 0;
1266 static int scrollback_max = 0;
1267 static int scrollback_current = 0;
1270 * If no vc is existent yet, just set struct display
1272 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1275 struct display *p = &fb_display[unit];
1276 struct display *t = &fb_display[fg_console];
1278 if (var_to_display(p, var, info))
1281 p->fontdata = t->fontdata;
1282 p->userfont = t->userfont;
1284 REFCOUNT(p->fontdata)++;
1287 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1290 struct display *p = &fb_display[vc->vc_num], *t;
1291 struct vc_data **default_mode = vc->vc_display_fg;
1292 struct vc_data *svc = *default_mode;
1293 struct fbcon_ops *ops = info->fbcon_par;
1294 int rows, cols, charcnt = 256;
1296 if (var_to_display(p, var, info))
1298 t = &fb_display[svc->vc_num];
1299 if (!vc->vc_font.data) {
1300 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1301 vc->vc_font.width = (*default_mode)->vc_font.width;
1302 vc->vc_font.height = (*default_mode)->vc_font.height;
1303 p->userfont = t->userfont;
1305 REFCOUNT(p->fontdata)++;
1308 charcnt = FNTCHARCNT(p->fontdata);
1310 var->activate = FB_ACTIVATE_NOW;
1311 info->var.activate = var->activate;
1312 var->yoffset = info->var.yoffset;
1313 var->xoffset = info->var.xoffset;
1314 fb_set_var(info, var);
1315 ops->var = info->var;
1316 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1317 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1318 if (charcnt == 256) {
1319 vc->vc_hi_font_mask = 0;
1321 vc->vc_hi_font_mask = 0x100;
1322 if (vc->vc_can_do_color)
1323 vc->vc_complement_mask <<= 1;
1326 if (!*svc->vc_uni_pagedir_loc)
1327 con_set_default_unimap(svc);
1328 if (!*vc->vc_uni_pagedir_loc)
1329 con_copy_unimap(vc, svc);
1331 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1332 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1333 cols /= vc->vc_font.width;
1334 rows /= vc->vc_font.height;
1335 vc_resize(vc, cols, rows);
1337 if (CON_IS_VISIBLE(vc)) {
1340 fbcon_update_softback(vc);
1344 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1346 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1347 struct fbcon_ops *ops = info->fbcon_par;
1348 struct display *p = &fb_display[vc->vc_num];
1350 p->yscroll += count;
1351 if (p->yscroll >= p->vrows) /* Deal with wrap */
1352 p->yscroll -= p->vrows;
1353 ops->var.xoffset = 0;
1354 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1355 ops->var.vmode |= FB_VMODE_YWRAP;
1356 ops->update_start(info);
1357 scrollback_max += count;
1358 if (scrollback_max > scrollback_phys_max)
1359 scrollback_max = scrollback_phys_max;
1360 scrollback_current = 0;
1363 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1365 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1366 struct fbcon_ops *ops = info->fbcon_par;
1367 struct display *p = &fb_display[vc->vc_num];
1369 p->yscroll -= count;
1370 if (p->yscroll < 0) /* Deal with wrap */
1371 p->yscroll += p->vrows;
1372 ops->var.xoffset = 0;
1373 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1374 ops->var.vmode |= FB_VMODE_YWRAP;
1375 ops->update_start(info);
1376 scrollback_max -= count;
1377 if (scrollback_max < 0)
1379 scrollback_current = 0;
1382 static __inline__ void ypan_up(struct vc_data *vc, int count)
1384 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1385 struct display *p = &fb_display[vc->vc_num];
1386 struct fbcon_ops *ops = info->fbcon_par;
1388 p->yscroll += count;
1389 if (p->yscroll > p->vrows - vc->vc_rows) {
1390 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1391 0, 0, 0, vc->vc_rows, vc->vc_cols);
1392 p->yscroll -= p->vrows - vc->vc_rows;
1395 ops->var.xoffset = 0;
1396 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1397 ops->var.vmode &= ~FB_VMODE_YWRAP;
1398 ops->update_start(info);
1399 fbcon_clear_margins(vc, 1);
1400 scrollback_max += count;
1401 if (scrollback_max > scrollback_phys_max)
1402 scrollback_max = scrollback_phys_max;
1403 scrollback_current = 0;
1406 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1408 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1409 struct fbcon_ops *ops = info->fbcon_par;
1410 struct display *p = &fb_display[vc->vc_num];
1413 p->yscroll += count;
1414 if (p->yscroll > p->vrows - vc->vc_rows) {
1415 p->yscroll -= p->vrows - vc->vc_rows;
1420 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1422 ops->var.xoffset = 0;
1423 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1424 ops->var.vmode &= ~FB_VMODE_YWRAP;
1425 ops->update_start(info);
1426 fbcon_clear_margins(vc, 1);
1427 scrollback_max += count;
1428 if (scrollback_max > scrollback_phys_max)
1429 scrollback_max = scrollback_phys_max;
1430 scrollback_current = 0;
1433 static __inline__ void ypan_down(struct vc_data *vc, int count)
1435 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1436 struct display *p = &fb_display[vc->vc_num];
1437 struct fbcon_ops *ops = info->fbcon_par;
1439 p->yscroll -= count;
1440 if (p->yscroll < 0) {
1441 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1442 0, vc->vc_rows, vc->vc_cols);
1443 p->yscroll += p->vrows - vc->vc_rows;
1446 ops->var.xoffset = 0;
1447 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1448 ops->var.vmode &= ~FB_VMODE_YWRAP;
1449 ops->update_start(info);
1450 fbcon_clear_margins(vc, 1);
1451 scrollback_max -= count;
1452 if (scrollback_max < 0)
1454 scrollback_current = 0;
1457 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1459 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1460 struct fbcon_ops *ops = info->fbcon_par;
1461 struct display *p = &fb_display[vc->vc_num];
1464 p->yscroll -= count;
1465 if (p->yscroll < 0) {
1466 p->yscroll += p->vrows - vc->vc_rows;
1471 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1473 ops->var.xoffset = 0;
1474 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1475 ops->var.vmode &= ~FB_VMODE_YWRAP;
1476 ops->update_start(info);
1477 fbcon_clear_margins(vc, 1);
1478 scrollback_max -= count;
1479 if (scrollback_max < 0)
1481 scrollback_current = 0;
1484 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1487 int count = vc->vc_rows;
1488 unsigned short *d, *s;
1492 d = (u16 *) softback_curr;
1493 if (d == (u16 *) softback_in)
1494 d = (u16 *) vc->vc_origin;
1495 n = softback_curr + delta * vc->vc_size_row;
1496 softback_lines -= delta;
1498 if (softback_curr < softback_top && n < softback_buf) {
1499 n += softback_end - softback_buf;
1500 if (n < softback_top) {
1502 (softback_top - n) / vc->vc_size_row;
1505 } else if (softback_curr >= softback_top
1506 && n < softback_top) {
1508 (softback_top - n) / vc->vc_size_row;
1512 if (softback_curr > softback_in && n >= softback_end) {
1513 n += softback_buf - softback_end;
1514 if (n > softback_in) {
1518 } else if (softback_curr <= softback_in && n > softback_in) {
1523 if (n == softback_curr)
1526 s = (u16 *) softback_curr;
1527 if (s == (u16 *) softback_in)
1528 s = (u16 *) vc->vc_origin;
1530 unsigned short *start;
1534 unsigned short attr = 1;
1537 le = advance_row(s, 1);
1540 if (attr != (c & 0xff00)) {
1543 fbcon_putcs(vc, start, s - start,
1549 if (c == scr_readw(d)) {
1551 fbcon_putcs(vc, start, s - start,
1564 fbcon_putcs(vc, start, s - start, line, x);
1566 if (d == (u16 *) softback_end)
1567 d = (u16 *) softback_buf;
1568 if (d == (u16 *) softback_in)
1569 d = (u16 *) vc->vc_origin;
1570 if (s == (u16 *) softback_end)
1571 s = (u16 *) softback_buf;
1572 if (s == (u16 *) softback_in)
1573 s = (u16 *) vc->vc_origin;
1577 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1578 int line, int count, int dy)
1580 unsigned short *s = (unsigned short *)
1581 (vc->vc_origin + vc->vc_size_row * line);
1584 unsigned short *start = s;
1585 unsigned short *le = advance_row(s, 1);
1588 unsigned short attr = 1;
1592 if (attr != (c & 0xff00)) {
1595 fbcon_putcs(vc, start, s - start,
1601 console_conditional_schedule();
1605 fbcon_putcs(vc, start, s - start, dy, x);
1606 console_conditional_schedule();
1611 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1612 int line, int count, int offset)
1614 unsigned short *d = (unsigned short *)
1615 (vc->vc_origin + vc->vc_size_row * line);
1616 unsigned short *s = d + offset;
1619 unsigned short *start = s;
1620 unsigned short *le = advance_row(s, 1);
1623 unsigned short attr = 1;
1627 if (attr != (c & 0xff00)) {
1630 fbcon_putcs(vc, start, s - start,
1636 if (c == scr_readw(d)) {
1638 fbcon_putcs(vc, start, s - start,
1648 console_conditional_schedule();
1653 fbcon_putcs(vc, start, s - start, line, x);
1654 console_conditional_schedule();
1659 /* NOTE: We subtract two lines from these pointers */
1660 s -= vc->vc_size_row;
1661 d -= vc->vc_size_row;
1666 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1671 if (vc->vc_num != fg_console)
1673 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1676 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1678 p = advance_row(p, 1);
1679 softback_in += vc->vc_size_row;
1680 if (softback_in == softback_end)
1681 softback_in = softback_buf;
1682 if (softback_in == softback_top) {
1683 softback_top += vc->vc_size_row;
1684 if (softback_top == softback_end)
1685 softback_top = softback_buf;
1688 softback_curr = softback_in;
1691 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1694 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1695 struct display *p = &fb_display[vc->vc_num];
1696 struct fbcon_ops *ops = info->fbcon_par;
1697 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1699 if (fbcon_is_inactive(vc, info))
1702 fbcon_cursor(vc, CM_ERASE);
1705 * ++Geert: Only use ywrap/ypan if the console is in text mode
1706 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1707 * whole screen (prevents flicker).
1712 if (count > vc->vc_rows) /* Maximum realistic size */
1713 count = vc->vc_rows;
1715 fbcon_softback_note(vc, t, count);
1716 if (logo_shown >= 0)
1718 switch (p->scrollmode) {
1720 ops->bmove(vc, info, t + count, 0, t, 0,
1721 b - t - count, vc->vc_cols);
1722 ops->clear(vc, info, b - count, 0, count,
1726 case SCROLL_WRAP_MOVE:
1727 if (b - t - count > 3 * vc->vc_rows >> 2) {
1729 fbcon_bmove(vc, 0, 0, count, 0, t,
1731 ywrap_up(vc, count);
1732 if (vc->vc_rows - b > 0)
1733 fbcon_bmove(vc, b - count, 0, b, 0,
1736 } else if (info->flags & FBINFO_READS_FAST)
1737 fbcon_bmove(vc, t + count, 0, t, 0,
1738 b - t - count, vc->vc_cols);
1741 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1744 case SCROLL_PAN_REDRAW:
1745 if ((p->yscroll + count <=
1746 2 * (p->vrows - vc->vc_rows))
1747 && ((!scroll_partial && (b - t == vc->vc_rows))
1750 3 * vc->vc_rows >> 2)))) {
1752 fbcon_redraw_move(vc, p, 0, t, count);
1753 ypan_up_redraw(vc, t, count);
1754 if (vc->vc_rows - b > 0)
1755 fbcon_redraw_move(vc, p, b - count,
1756 vc->vc_rows - b, b);
1758 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1759 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1762 case SCROLL_PAN_MOVE:
1763 if ((p->yscroll + count <=
1764 2 * (p->vrows - vc->vc_rows))
1765 && ((!scroll_partial && (b - t == vc->vc_rows))
1768 3 * vc->vc_rows >> 2)))) {
1770 fbcon_bmove(vc, 0, 0, count, 0, t,
1773 if (vc->vc_rows - b > 0)
1774 fbcon_bmove(vc, b - count, 0, b, 0,
1777 } else if (info->flags & FBINFO_READS_FAST)
1778 fbcon_bmove(vc, t + count, 0, t, 0,
1779 b - t - count, vc->vc_cols);
1782 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1787 fbcon_redraw(vc, p, t, b - t - count,
1788 count * vc->vc_cols);
1789 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1790 scr_memsetw((unsigned short *) (vc->vc_origin +
1793 vc->vc_video_erase_char,
1794 vc->vc_size_row * count);
1800 if (count > vc->vc_rows) /* Maximum realistic size */
1801 count = vc->vc_rows;
1802 if (logo_shown >= 0)
1804 switch (p->scrollmode) {
1806 ops->bmove(vc, info, t, 0, t + count, 0,
1807 b - t - count, vc->vc_cols);
1808 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1811 case SCROLL_WRAP_MOVE:
1812 if (b - t - count > 3 * vc->vc_rows >> 2) {
1813 if (vc->vc_rows - b > 0)
1814 fbcon_bmove(vc, b, 0, b - count, 0,
1817 ywrap_down(vc, count);
1819 fbcon_bmove(vc, count, 0, 0, 0, t,
1821 } else if (info->flags & FBINFO_READS_FAST)
1822 fbcon_bmove(vc, t, 0, t + count, 0,
1823 b - t - count, vc->vc_cols);
1826 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1829 case SCROLL_PAN_MOVE:
1830 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1831 && ((!scroll_partial && (b - t == vc->vc_rows))
1834 3 * vc->vc_rows >> 2)))) {
1835 if (vc->vc_rows - b > 0)
1836 fbcon_bmove(vc, b, 0, b - count, 0,
1839 ypan_down(vc, count);
1841 fbcon_bmove(vc, count, 0, 0, 0, t,
1843 } else if (info->flags & FBINFO_READS_FAST)
1844 fbcon_bmove(vc, t, 0, t + count, 0,
1845 b - t - count, vc->vc_cols);
1848 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1851 case SCROLL_PAN_REDRAW:
1852 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1853 && ((!scroll_partial && (b - t == vc->vc_rows))
1856 3 * vc->vc_rows >> 2)))) {
1857 if (vc->vc_rows - b > 0)
1858 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1860 ypan_down_redraw(vc, t, count);
1862 fbcon_redraw_move(vc, p, count, t, 0);
1864 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1865 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1870 fbcon_redraw(vc, p, b - 1, b - t - count,
1871 -count * vc->vc_cols);
1872 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1873 scr_memsetw((unsigned short *) (vc->vc_origin +
1876 vc->vc_video_erase_char,
1877 vc->vc_size_row * count);
1885 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1886 int height, int width)
1888 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1889 struct display *p = &fb_display[vc->vc_num];
1891 if (fbcon_is_inactive(vc, info))
1894 if (!width || !height)
1897 /* Split blits that cross physical y_wrap case.
1898 * Pathological case involves 4 blits, better to use recursive
1899 * code rather than unrolled case
1901 * Recursive invocations don't need to erase the cursor over and
1902 * over again, so we use fbcon_bmove_rec()
1904 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1905 p->vrows - p->yscroll);
1908 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1909 int dy, int dx, int height, int width, u_int y_break)
1911 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1912 struct fbcon_ops *ops = info->fbcon_par;
1915 if (sy < y_break && sy + height > y_break) {
1917 if (dy < sy) { /* Avoid trashing self */
1918 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1920 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1921 height - b, width, y_break);
1923 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1924 height - b, width, y_break);
1925 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1931 if (dy < y_break && dy + height > y_break) {
1933 if (dy < sy) { /* Avoid trashing self */
1934 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1936 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1937 height - b, width, y_break);
1939 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1940 height - b, width, y_break);
1941 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1946 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1950 static __inline__ void updatescrollmode(struct display *p,
1951 struct fb_info *info,
1954 struct fbcon_ops *ops = info->fbcon_par;
1955 int fh = vc->vc_font.height;
1956 int cap = info->flags;
1958 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1959 info->fix.xpanstep);
1960 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1961 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1962 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1963 info->var.xres_virtual);
1964 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1965 divides(ypan, vc->vc_font.height) && vyres > yres;
1966 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1967 divides(ywrap, vc->vc_font.height) &&
1968 divides(vc->vc_font.height, vyres);
1969 int reading_fast = cap & FBINFO_READS_FAST;
1970 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1971 !(cap & FBINFO_HWACCEL_DISABLED);
1972 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1973 !(cap & FBINFO_HWACCEL_DISABLED);
1975 p->vrows = vyres/fh;
1976 if (yres > (fh * (vc->vc_rows + 1)))
1977 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1978 if ((yres % fh) && (vyres % fh < yres % fh))
1981 if (good_wrap || good_pan) {
1982 if (reading_fast || fast_copyarea)
1983 p->scrollmode = good_wrap ?
1984 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1986 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1989 if (reading_fast || (fast_copyarea && !fast_imageblit))
1990 p->scrollmode = SCROLL_MOVE;
1992 p->scrollmode = SCROLL_REDRAW;
1996 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1997 unsigned int height)
1999 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2000 struct fbcon_ops *ops = info->fbcon_par;
2001 struct display *p = &fb_display[vc->vc_num];
2002 struct fb_var_screeninfo var = info->var;
2003 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2005 virt_w = FBCON_SWAP(ops->rotate, width, height);
2006 virt_h = FBCON_SWAP(ops->rotate, height, width);
2007 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2008 vc->vc_font.height);
2009 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2011 var.xres = virt_w * virt_fw;
2012 var.yres = virt_h * virt_fh;
2013 x_diff = info->var.xres - var.xres;
2014 y_diff = info->var.yres - var.yres;
2015 if (x_diff < 0 || x_diff > virt_fw ||
2016 y_diff < 0 || y_diff > virt_fh) {
2017 struct fb_videomode *mode;
2019 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2020 mode = fb_find_best_mode(&var, &info->modelist);
2023 display_to_var(&var, p);
2024 fb_videomode_to_var(&var, mode);
2026 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2029 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2030 if (CON_IS_VISIBLE(vc)) {
2031 var.activate = FB_ACTIVATE_NOW |
2033 fb_set_var(info, &var);
2035 var_to_display(p, &info->var, info);
2036 ops->var = info->var;
2038 updatescrollmode(p, info, vc);
2042 static int fbcon_switch(struct vc_data *vc)
2044 struct fb_info *info, *old_info = NULL;
2045 struct fbcon_ops *ops;
2046 struct display *p = &fb_display[vc->vc_num];
2047 struct fb_var_screeninfo var;
2048 int i, prev_console, charcnt = 256;
2050 info = registered_fb[con2fb_map[vc->vc_num]];
2051 ops = info->fbcon_par;
2055 fbcon_set_origin(vc);
2056 softback_top = softback_curr = softback_in = softback_buf;
2058 fbcon_update_softback(vc);
2061 if (logo_shown >= 0) {
2062 struct vc_data *conp2 = vc_cons[logo_shown].d;
2064 if (conp2->vc_top == logo_lines
2065 && conp2->vc_bottom == conp2->vc_rows)
2067 logo_shown = FBCON_LOGO_CANSHOW;
2070 prev_console = ops->currcon;
2071 if (prev_console != -1)
2072 old_info = registered_fb[con2fb_map[prev_console]];
2074 * FIXME: If we have multiple fbdev's loaded, we need to
2075 * update all info->currcon. Perhaps, we can place this
2076 * in a centralized structure, but this might break some
2079 * info->currcon = vc->vc_num;
2081 for (i = 0; i < FB_MAX; i++) {
2082 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2083 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2085 o->currcon = vc->vc_num;
2088 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2089 display_to_var(&var, p);
2090 var.activate = FB_ACTIVATE_NOW;
2093 * make sure we don't unnecessarily trip the memcmp()
2096 info->var.activate = var.activate;
2097 var.yoffset = info->var.yoffset;
2098 var.xoffset = info->var.xoffset;
2099 var.vmode = info->var.vmode;
2100 fb_set_var(info, &var);
2101 ops->var = info->var;
2103 if (old_info != NULL && (old_info != info ||
2104 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2105 if (info->fbops->fb_set_par)
2106 info->fbops->fb_set_par(info);
2107 fbcon_del_cursor_timer(old_info);
2108 fbcon_add_cursor_timer(info);
2111 set_blitting_type(vc, info);
2112 ops->cursor_reset = 1;
2114 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2115 ops->rotate = FB_ROTATE_UR;
2116 set_blitting_type(vc, info);
2119 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2120 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2123 charcnt = FNTCHARCNT(vc->vc_font.data);
2126 vc->vc_complement_mask <<= 1;
2128 updatescrollmode(p, info, vc);
2130 switch (p->scrollmode) {
2131 case SCROLL_WRAP_MOVE:
2132 scrollback_phys_max = p->vrows - vc->vc_rows;
2134 case SCROLL_PAN_MOVE:
2135 case SCROLL_PAN_REDRAW:
2136 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2137 if (scrollback_phys_max < 0)
2138 scrollback_phys_max = 0;
2141 scrollback_phys_max = 0;
2146 scrollback_current = 0;
2148 if (!fbcon_is_inactive(vc, info)) {
2149 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2150 ops->update_start(info);
2153 fbcon_set_palette(vc, color_table);
2154 fbcon_clear_margins(vc, 0);
2156 if (logo_shown == FBCON_LOGO_DRAW) {
2158 logo_shown = fg_console;
2159 /* This is protected above by initmem_freed */
2160 fb_show_logo(info, ops->rotate);
2162 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2163 vc->vc_size_row * (vc->vc_bottom -
2170 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2174 unsigned short charmask = vc->vc_hi_font_mask ?
2176 unsigned short oldc;
2178 oldc = vc->vc_video_erase_char;
2179 vc->vc_video_erase_char &= charmask;
2180 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2181 vc->vc_video_erase_char = oldc;
2185 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2187 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2188 struct fbcon_ops *ops = info->fbcon_par;
2191 struct fb_var_screeninfo var = info->var;
2196 if (info->fbops->fb_save_state)
2197 info->fbops->fb_save_state(info);
2198 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2199 fb_set_var(info, &var);
2201 ops->var = info->var;
2202 } else if (info->fbops->fb_restore_state)
2203 info->fbops->fb_restore_state(info);
2206 if (!fbcon_is_inactive(vc, info)) {
2207 if (ops->blank_state != blank) {
2208 ops->blank_state = blank;
2209 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2210 ops->cursor_flash = (!blank);
2212 if (fb_blank(info, blank))
2213 fbcon_generic_blank(vc, info, blank);
2221 fbcon_add_cursor_timer(info);
2223 fbcon_del_cursor_timer(info);
2228 static void fbcon_free_font(struct display *p)
2230 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2231 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2236 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2238 u8 *fontdata = vc->vc_font.data;
2239 u8 *data = font->data;
2242 font->width = vc->vc_font.width;
2243 font->height = vc->vc_font.height;
2244 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2248 if (font->width <= 8) {
2249 j = vc->vc_font.height;
2250 for (i = 0; i < font->charcount; i++) {
2251 memcpy(data, fontdata, j);
2252 memset(data + j, 0, 32 - j);
2256 } else if (font->width <= 16) {
2257 j = vc->vc_font.height * 2;
2258 for (i = 0; i < font->charcount; i++) {
2259 memcpy(data, fontdata, j);
2260 memset(data + j, 0, 64 - j);
2264 } else if (font->width <= 24) {
2265 for (i = 0; i < font->charcount; i++) {
2266 for (j = 0; j < vc->vc_font.height; j++) {
2267 *data++ = fontdata[0];
2268 *data++ = fontdata[1];
2269 *data++ = fontdata[2];
2270 fontdata += sizeof(u32);
2272 memset(data, 0, 3 * (32 - j));
2273 data += 3 * (32 - j);
2276 j = vc->vc_font.height * 4;
2277 for (i = 0; i < font->charcount; i++) {
2278 memcpy(data, fontdata, j);
2279 memset(data + j, 0, 128 - j);
2287 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2288 const u8 * data, int userfont)
2290 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2291 struct fbcon_ops *ops = info->fbcon_par;
2292 struct display *p = &fb_display[vc->vc_num];
2295 char *old_data = NULL;
2297 if (CON_IS_VISIBLE(vc) && softback_lines)
2298 fbcon_set_origin(vc);
2300 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2302 old_data = vc->vc_font.data;
2304 cnt = FNTCHARCNT(data);
2307 vc->vc_font.data = (void *)(p->fontdata = data);
2308 if ((p->userfont = userfont))
2310 vc->vc_font.width = w;
2311 vc->vc_font.height = h;
2312 if (vc->vc_hi_font_mask && cnt == 256) {
2313 vc->vc_hi_font_mask = 0;
2314 if (vc->vc_can_do_color) {
2315 vc->vc_complement_mask >>= 1;
2316 vc->vc_s_complement_mask >>= 1;
2319 /* ++Edmund: reorder the attribute bits */
2320 if (vc->vc_can_do_color) {
2321 unsigned short *cp =
2322 (unsigned short *) vc->vc_origin;
2323 int count = vc->vc_screenbuf_size / 2;
2325 for (; count > 0; count--, cp++) {
2327 scr_writew(((c & 0xfe00) >> 1) |
2330 c = vc->vc_video_erase_char;
2331 vc->vc_video_erase_char =
2332 ((c & 0xfe00) >> 1) | (c & 0xff);
2335 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2336 vc->vc_hi_font_mask = 0x100;
2337 if (vc->vc_can_do_color) {
2338 vc->vc_complement_mask <<= 1;
2339 vc->vc_s_complement_mask <<= 1;
2342 /* ++Edmund: reorder the attribute bits */
2344 unsigned short *cp =
2345 (unsigned short *) vc->vc_origin;
2346 int count = vc->vc_screenbuf_size / 2;
2348 for (; count > 0; count--, cp++) {
2349 unsigned short newc;
2351 if (vc->vc_can_do_color)
2353 ((c & 0xff00) << 1) | (c &
2357 scr_writew(newc, cp);
2359 c = vc->vc_video_erase_char;
2360 if (vc->vc_can_do_color) {
2361 vc->vc_video_erase_char =
2362 ((c & 0xff00) << 1) | (c & 0xff);
2365 vc->vc_video_erase_char = c & ~0x100;
2373 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2374 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2377 vc_resize(vc, cols, rows);
2378 if (CON_IS_VISIBLE(vc) && softback_buf)
2379 fbcon_update_softback(vc);
2380 } else if (CON_IS_VISIBLE(vc)
2381 && vc->vc_mode == KD_TEXT) {
2382 fbcon_clear_margins(vc, 0);
2386 if (old_data && (--REFCOUNT(old_data) == 0))
2387 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2391 static int fbcon_copy_font(struct vc_data *vc, int con)
2393 struct display *od = &fb_display[con];
2394 struct console_font *f = &vc->vc_font;
2396 if (od->fontdata == f->data)
2397 return 0; /* already the same font... */
2398 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2402 * User asked to set font; we are guaranteed that
2403 * a) width and height are in range 1..32
2404 * b) charcount does not exceed 512
2405 * but lets not assume that, since someone might someday want to use larger
2406 * fonts. And charcount of 512 is small for unicode support.
2408 * However, user space gives the font in 32 rows , regardless of
2409 * actual font height. So a new API is needed if support for larger fonts
2410 * is ever implemented.
2413 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2415 unsigned charcount = font->charcount;
2416 int w = font->width;
2417 int h = font->height;
2420 u8 *new_data, *data = font->data;
2421 int pitch = (font->width+7) >> 3;
2423 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2424 * If not this check should be changed to charcount < 256 */
2425 if (charcount != 256 && charcount != 512)
2428 size = h * pitch * charcount;
2430 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2435 new_data += FONT_EXTRA_WORDS * sizeof(int);
2436 FNTSIZE(new_data) = size;
2437 FNTCHARCNT(new_data) = charcount;
2438 REFCOUNT(new_data) = 0; /* usage counter */
2439 for (i=0; i< charcount; i++) {
2440 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2443 /* Since linux has a nice crc32 function use it for counting font
2445 csum = crc32(0, new_data, size);
2447 FNTSUM(new_data) = csum;
2448 /* Check if the same font is on some other console already */
2449 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2450 struct vc_data *tmp = vc_cons[i].d;
2452 if (fb_display[i].userfont &&
2453 fb_display[i].fontdata &&
2454 FNTSUM(fb_display[i].fontdata) == csum &&
2455 FNTSIZE(fb_display[i].fontdata) == size &&
2456 tmp->vc_font.width == w &&
2457 !memcmp(fb_display[i].fontdata, new_data, size)) {
2458 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2459 new_data = (u8 *)fb_display[i].fontdata;
2463 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2466 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2468 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2469 const struct font_desc *f;
2472 f = get_default_font(info->var.xres, info->var.yres);
2473 else if (!(f = find_font(name)))
2476 font->width = f->width;
2477 font->height = f->height;
2478 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2481 static u16 palette_red[16];
2482 static u16 palette_green[16];
2483 static u16 palette_blue[16];
2485 static struct fb_cmap palette_cmap = {
2486 0, 16, palette_red, palette_green, palette_blue, NULL
2489 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2491 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2495 if (fbcon_is_inactive(vc, info))
2498 if (!CON_IS_VISIBLE(vc))
2501 depth = fb_get_color_depth(&info->var, &info->fix);
2503 for (i = j = 0; i < 16; i++) {
2505 val = vc->vc_palette[j++];
2506 palette_red[k] = (val << 8) | val;
2507 val = vc->vc_palette[j++];
2508 palette_green[k] = (val << 8) | val;
2509 val = vc->vc_palette[j++];
2510 palette_blue[k] = (val << 8) | val;
2512 palette_cmap.len = 16;
2513 palette_cmap.start = 0;
2515 * If framebuffer is capable of less than 16 colors,
2516 * use default palette of fbcon.
2519 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2521 return fb_set_cmap(&palette_cmap, info);
2524 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2529 if (vc->vc_num != fg_console || !softback_lines)
2530 return (u16 *) (vc->vc_origin + offset);
2531 line = offset / vc->vc_size_row;
2532 if (line >= softback_lines)
2533 return (u16 *) (vc->vc_origin + offset -
2534 softback_lines * vc->vc_size_row);
2535 p = softback_curr + offset;
2536 if (p >= softback_end)
2537 p += softback_buf - softback_end;
2541 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2547 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2548 unsigned long offset = (pos - vc->vc_origin) / 2;
2550 x = offset % vc->vc_cols;
2551 y = offset / vc->vc_cols;
2552 if (vc->vc_num == fg_console)
2553 y += softback_lines;
2554 ret = pos + (vc->vc_cols - x) * 2;
2555 } else if (vc->vc_num == fg_console && softback_lines) {
2556 unsigned long offset = pos - softback_curr;
2558 if (pos < softback_curr)
2559 offset += softback_end - softback_buf;
2561 x = offset % vc->vc_cols;
2562 y = offset / vc->vc_cols;
2563 ret = pos + (vc->vc_cols - x) * 2;
2564 if (ret == softback_end)
2566 if (ret == softback_in)
2567 ret = vc->vc_origin;
2569 /* Should not happen */
2571 ret = vc->vc_origin;
2580 /* As we might be inside of softback, we may work with non-contiguous buffer,
2581 that's why we have to use a separate routine. */
2582 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2585 u16 a = scr_readw(p);
2586 if (!vc->vc_can_do_color)
2588 else if (vc->vc_hi_font_mask == 0x100)
2589 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2590 (((a) & 0x0e00) << 4);
2592 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2593 (((a) & 0x0700) << 4);
2595 if (p == (u16 *) softback_end)
2596 p = (u16 *) softback_buf;
2597 if (p == (u16 *) softback_in)
2598 p = (u16 *) vc->vc_origin;
2602 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2604 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2605 struct fbcon_ops *ops = info->fbcon_par;
2606 struct display *p = &fb_display[fg_console];
2607 int offset, limit, scrollback_old;
2610 if (vc->vc_num != fg_console)
2612 if (vc->vc_mode != KD_TEXT || !lines)
2614 if (logo_shown >= 0) {
2615 struct vc_data *conp2 = vc_cons[logo_shown].d;
2617 if (conp2->vc_top == logo_lines
2618 && conp2->vc_bottom == conp2->vc_rows)
2620 if (logo_shown == vc->vc_num) {
2626 logo_lines * vc->vc_size_row;
2627 for (i = 0; i < logo_lines; i++) {
2628 if (p == softback_top)
2630 if (p == softback_buf)
2632 p -= vc->vc_size_row;
2633 q -= vc->vc_size_row;
2634 scr_memcpyw((u16 *) q, (u16 *) p,
2638 update_region(vc, vc->vc_origin,
2639 logo_lines * vc->vc_cols);
2641 logo_shown = FBCON_LOGO_CANSHOW;
2643 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2644 fbcon_redraw_softback(vc, p, lines);
2645 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2649 if (!scrollback_phys_max)
2652 scrollback_old = scrollback_current;
2653 scrollback_current -= lines;
2654 if (scrollback_current < 0)
2655 scrollback_current = 0;
2656 else if (scrollback_current > scrollback_max)
2657 scrollback_current = scrollback_max;
2658 if (scrollback_current == scrollback_old)
2661 if (fbcon_is_inactive(vc, info))
2664 fbcon_cursor(vc, CM_ERASE);
2666 offset = p->yscroll - scrollback_current;
2668 switch (p->scrollmode) {
2669 case SCROLL_WRAP_MOVE:
2670 info->var.vmode |= FB_VMODE_YWRAP;
2672 case SCROLL_PAN_MOVE:
2673 case SCROLL_PAN_REDRAW:
2674 limit -= vc->vc_rows;
2675 info->var.vmode &= ~FB_VMODE_YWRAP;
2680 else if (offset >= limit)
2683 ops->var.xoffset = 0;
2684 ops->var.yoffset = offset * vc->vc_font.height;
2685 ops->update_start(info);
2687 if (!scrollback_current)
2688 fbcon_cursor(vc, CM_DRAW);
2692 static int fbcon_set_origin(struct vc_data *vc)
2695 fbcon_scrolldelta(vc, softback_lines);
2699 static void fbcon_suspended(struct fb_info *info)
2701 struct vc_data *vc = NULL;
2702 struct fbcon_ops *ops = info->fbcon_par;
2704 if (!ops || ops->currcon < 0)
2706 vc = vc_cons[ops->currcon].d;
2708 /* Clear cursor, restore saved data */
2709 fbcon_cursor(vc, CM_ERASE);
2712 static void fbcon_resumed(struct fb_info *info)
2715 struct fbcon_ops *ops = info->fbcon_par;
2717 if (!ops || ops->currcon < 0)
2719 vc = vc_cons[ops->currcon].d;
2724 static void fbcon_modechanged(struct fb_info *info)
2726 struct fbcon_ops *ops = info->fbcon_par;
2731 if (!ops || ops->currcon < 0)
2733 vc = vc_cons[ops->currcon].d;
2734 if (vc->vc_mode != KD_TEXT ||
2735 registered_fb[con2fb_map[ops->currcon]] != info)
2738 p = &fb_display[vc->vc_num];
2739 set_blitting_type(vc, info);
2741 if (CON_IS_VISIBLE(vc)) {
2742 var_to_display(p, &info->var, info);
2743 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2744 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2745 cols /= vc->vc_font.width;
2746 rows /= vc->vc_font.height;
2747 vc_resize(vc, cols, rows);
2748 updatescrollmode(p, info, vc);
2750 scrollback_current = 0;
2752 if (!fbcon_is_inactive(vc, info)) {
2753 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2754 ops->update_start(info);
2757 fbcon_set_palette(vc, color_table);
2760 fbcon_update_softback(vc);
2764 static void fbcon_set_all_vcs(struct fb_info *info)
2766 struct fbcon_ops *ops = info->fbcon_par;
2771 if (!ops || ops->currcon < 0)
2774 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2776 if (!vc || vc->vc_mode != KD_TEXT ||
2777 registered_fb[con2fb_map[i]] != info)
2780 p = &fb_display[vc->vc_num];
2781 set_blitting_type(vc, info);
2782 var_to_display(p, &info->var, info);
2783 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2784 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2785 cols /= vc->vc_font.width;
2786 rows /= vc->vc_font.height;
2787 vc_resize(vc, cols, rows);
2789 if (CON_IS_VISIBLE(vc)) {
2790 updatescrollmode(p, info, vc);
2792 scrollback_current = 0;
2794 if (!fbcon_is_inactive(vc, info)) {
2795 ops->var.xoffset = ops->var.yoffset =
2797 ops->update_start(info);
2800 fbcon_set_palette(vc, color_table);
2803 fbcon_update_softback(vc);
2808 static int fbcon_mode_deleted(struct fb_info *info,
2809 struct fb_videomode *mode)
2811 struct fb_info *fb_info;
2813 int i, j, found = 0;
2815 /* before deletion, ensure that mode is not in use */
2816 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2820 fb_info = registered_fb[j];
2821 if (fb_info != info)
2826 if (fb_mode_is_equal(p->mode, mode)) {
2834 static int fbcon_fb_registered(int idx)
2838 if (info_idx == -1) {
2839 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2840 if (con2fb_map_boot[i] == idx) {
2846 ret = fbcon_takeover(1);
2848 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2849 if (con2fb_map_boot[i] == idx)
2850 set_con2fb_map(i, idx, 0);
2857 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2859 struct fbcon_ops *ops = info->fbcon_par;
2862 if (!ops || ops->currcon < 0)
2865 vc = vc_cons[ops->currcon].d;
2866 if (vc->vc_mode != KD_TEXT ||
2867 registered_fb[con2fb_map[ops->currcon]] != info)
2870 if (CON_IS_VISIBLE(vc)) {
2874 do_unblank_screen(0);
2876 ops->blank_state = blank;
2879 static void fbcon_new_modelist(struct fb_info *info)
2883 struct fb_var_screeninfo var;
2884 struct fb_videomode *mode;
2886 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2887 if (registered_fb[con2fb_map[i]] != info)
2889 if (!fb_display[i].mode)
2892 display_to_var(&var, &fb_display[i]);
2893 mode = fb_find_nearest_mode(fb_display[i].mode,
2895 fb_videomode_to_var(&var, mode);
2898 fbcon_set_disp(info, &var, vc);
2900 fbcon_preset_disp(info, &var, i);
2905 static int fbcon_event_notify(struct notifier_block *self,
2906 unsigned long action, void *data)
2908 struct fb_event *event = data;
2909 struct fb_info *info = event->info;
2910 struct fb_videomode *mode;
2911 struct fb_con2fbmap *con2fb;
2915 case FB_EVENT_SUSPEND:
2916 fbcon_suspended(info);
2918 case FB_EVENT_RESUME:
2919 fbcon_resumed(info);
2921 case FB_EVENT_MODE_CHANGE:
2922 fbcon_modechanged(info);
2924 case FB_EVENT_MODE_CHANGE_ALL:
2925 fbcon_set_all_vcs(info);
2927 case FB_EVENT_MODE_DELETE:
2929 ret = fbcon_mode_deleted(info, mode);
2931 case FB_EVENT_FB_REGISTERED:
2932 ret = fbcon_fb_registered(info->node);
2934 case FB_EVENT_SET_CONSOLE_MAP:
2935 con2fb = event->data;
2936 ret = set_con2fb_map(con2fb->console - 1,
2937 con2fb->framebuffer, 1);
2939 case FB_EVENT_GET_CONSOLE_MAP:
2940 con2fb = event->data;
2941 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2943 case FB_EVENT_BLANK:
2944 fbcon_fb_blanked(info, *(int *)event->data);
2946 case FB_EVENT_NEW_MODELIST:
2947 fbcon_new_modelist(info);
2949 case FB_EVENT_SET_CON_ROTATE:
2950 fbcon_rotate(info, *(int *)event->data);
2952 case FB_EVENT_GET_CON_ROTATE:
2953 ret = fbcon_get_rotate(info);
2955 case FB_EVENT_SET_CON_ROTATE_ALL:
2956 fbcon_rotate_all(info, *(int *)event->data);
2963 * The console `switch' structure for the frame buffer based console
2966 static const struct consw fb_con = {
2967 .owner = THIS_MODULE,
2968 .con_startup = fbcon_startup,
2969 .con_init = fbcon_init,
2970 .con_deinit = fbcon_deinit,
2971 .con_clear = fbcon_clear,
2972 .con_putc = fbcon_putc,
2973 .con_putcs = fbcon_putcs,
2974 .con_cursor = fbcon_cursor,
2975 .con_scroll = fbcon_scroll,
2976 .con_bmove = fbcon_bmove,
2977 .con_switch = fbcon_switch,
2978 .con_blank = fbcon_blank,
2979 .con_font_set = fbcon_set_font,
2980 .con_font_get = fbcon_get_font,
2981 .con_font_default = fbcon_set_def_font,
2982 .con_font_copy = fbcon_copy_font,
2983 .con_set_palette = fbcon_set_palette,
2984 .con_scrolldelta = fbcon_scrolldelta,
2985 .con_set_origin = fbcon_set_origin,
2986 .con_invert_region = fbcon_invert_region,
2987 .con_screen_pos = fbcon_screen_pos,
2988 .con_getxy = fbcon_getxy,
2989 .con_resize = fbcon_resize,
2992 static struct notifier_block fbcon_event_notifier = {
2993 .notifier_call = fbcon_event_notify,
2996 static int __init fb_console_init(void)
3000 acquire_console_sem();
3001 fb_register_client(&fbcon_event_notifier);
3002 release_console_sem();
3004 for (i = 0; i < MAX_NR_CONSOLES; i++)
3007 if (num_registered_fb) {
3008 for (i = 0; i < FB_MAX; i++) {
3009 if (registered_fb[i] != NULL) {
3020 module_init(fb_console_init);
3024 static void __exit fb_console_exit(void)
3026 acquire_console_sem();
3027 fb_unregister_client(&fbcon_event_notifier);
3028 release_console_sem();
3029 give_up_console(&fb_con);
3032 module_exit(fb_console_exit);
3036 MODULE_LICENSE("GPL");