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>
96 #ifdef CONFIG_BOOTSPLASH
97 #include "../bootsplash/bootsplash.h"
101 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
103 # define DPRINTK(fmt, args...)
107 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
108 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
109 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
112 static struct display fb_display[MAX_NR_CONSOLES];
114 #ifdef CONFIG_BOOTSPLASH
115 signed char con2fb_map[MAX_NR_CONSOLES];
117 static signed char con2fb_map[MAX_NR_CONSOLES];
119 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
120 static int logo_height;
121 static int logo_lines;
122 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
124 static int logo_shown = FBCON_LOGO_CANSHOW;
125 /* Software scrollback */
126 static int fbcon_softback_size = 32768;
127 static unsigned long softback_buf, softback_curr;
128 static unsigned long softback_in;
129 static unsigned long softback_top, softback_end;
130 static int softback_lines;
131 /* console mappings */
132 static int first_fb_vc;
133 static int last_fb_vc = MAX_NR_CONSOLES - 1;
134 static int fbcon_is_default = 1;
136 static char fontname[40];
138 /* current fb_info */
139 static int info_idx = -1;
141 /* console rotation */
144 static const struct consw fb_con;
146 #define CM_SOFTBACK (8)
148 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
150 static void fbcon_free_font(struct display *);
151 static int fbcon_set_origin(struct vc_data *);
153 #define CURSOR_DRAW_DELAY (1)
155 /* # VBL ints between cursor state changes */
156 #define ATARI_CURSOR_BLINK_RATE (42)
157 #define MAC_CURSOR_BLINK_RATE (32)
158 #define DEFAULT_CURSOR_BLINK_RATE (20)
160 static int vbl_cursor_cnt;
162 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
165 * Interface used by the world
168 static const char *fbcon_startup(void);
169 static void fbcon_init(struct vc_data *vc, int init);
170 static void fbcon_deinit(struct vc_data *vc);
171 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
173 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
174 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
175 int count, int ypos, int xpos);
176 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
177 static void fbcon_cursor(struct vc_data *vc, int mode);
178 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
180 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
181 int height, int width);
182 static int fbcon_switch(struct vc_data *vc);
183 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
184 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
185 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
190 static __inline__ void ywrap_up(struct vc_data *vc, int count);
191 static __inline__ void ywrap_down(struct vc_data *vc, int count);
192 static __inline__ void ypan_up(struct vc_data *vc, int count);
193 static __inline__ void ypan_down(struct vc_data *vc, int count);
194 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
195 int dy, int dx, int height, int width, u_int y_break);
196 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
198 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
200 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
201 int line, int count, int dy);
202 static void fbcon_modechanged(struct fb_info *info);
203 static void fbcon_set_all_vcs(struct fb_info *info);
207 * On the Macintoy, there may or may not be a working VBL int. We need to probe
209 static int vbl_detected;
211 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
218 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
219 static inline void fbcon_set_rotation(struct fb_info *info)
221 struct fbcon_ops *ops = info->fbcon_par;
223 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
224 ops->p->con_rotate < 4)
225 ops->rotate = ops->p->con_rotate;
230 static void fbcon_rotate(struct fb_info *info, u32 rotate)
232 struct fbcon_ops *ops= info->fbcon_par;
233 struct fb_info *fb_info;
235 if (!ops || ops->currcon == -1)
238 fb_info = registered_fb[con2fb_map[ops->currcon]];
240 if (info == fb_info) {
241 struct display *p = &fb_display[ops->currcon];
244 p->con_rotate = rotate;
248 fbcon_modechanged(info);
252 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
254 struct fbcon_ops *ops = info->fbcon_par;
259 if (!ops || ops->currcon < 0 || rotate > 3)
262 for (i = 0; i < MAX_NR_CONSOLES; i++) {
264 if (!vc || vc->vc_mode != KD_TEXT ||
265 registered_fb[con2fb_map[i]] != info)
268 p = &fb_display[vc->vc_num];
269 p->con_rotate = rotate;
272 fbcon_set_all_vcs(info);
275 static inline void fbcon_set_rotation(struct fb_info *info)
277 struct fbcon_ops *ops = info->fbcon_par;
279 ops->rotate = FB_ROTATE_UR;
282 static void fbcon_rotate(struct fb_info *info, u32 rotate)
287 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
291 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
293 static int fbcon_get_rotate(struct fb_info *info)
295 struct fbcon_ops *ops = info->fbcon_par;
297 return (ops) ? ops->rotate : 0;
300 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
302 struct fbcon_ops *ops = info->fbcon_par;
304 return (info->state != FBINFO_STATE_RUNNING ||
305 vc->vc_mode != KD_TEXT || ops->graphics);
308 static inline int get_color(struct vc_data *vc, struct fb_info *info,
311 int depth = fb_get_color_depth(&info->var, &info->fix);
314 if (console_blanked) {
315 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
317 c = vc->vc_video_erase_char & charmask;
321 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
322 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
327 int col = ~(0xfff << (max(info->var.green.length,
328 max(info->var.red.length,
329 info->var.blue.length)))) & 0xff;
332 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
333 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
338 color = (is_fg) ? fg : bg;
343 * Scale down 16-colors to 4 colors. Default 4-color palette
344 * is grayscale. However, simply dividing the values by 4
345 * will not work, as colors 1, 2 and 3 will be scaled-down
346 * to zero rendering them invisible. So empirically convert
347 * colors to a sane 4-level grayscale.
351 color = 0; /* black */
354 color = 2; /* white */
357 color = 1; /* gray */
360 color = 3; /* intense white */
366 * Last 8 entries of default 16-color palette is a more intense
367 * version of the first 8 (i.e., same chrominance, different
378 static void fbcon_update_softback(struct vc_data *vc)
380 int l = fbcon_softback_size / vc->vc_size_row;
383 softback_end = softback_buf + l * vc->vc_size_row;
385 /* Smaller scrollback makes no sense, and 0 would screw
386 the operation totally */
390 static void fb_flashcursor(void *private)
392 struct fb_info *info = private;
393 struct fbcon_ops *ops = info->fbcon_par;
395 struct vc_data *vc = NULL;
399 if (ops->currcon != -1)
400 vc = vc_cons[ops->currcon].d;
402 if (!vc || !CON_IS_VISIBLE(vc) ||
403 fbcon_is_inactive(vc, info) ||
404 registered_fb[con2fb_map[vc->vc_num]] != info ||
405 vc_cons[ops->currcon].d->vc_deccm != 1)
407 acquire_console_sem();
408 p = &fb_display[vc->vc_num];
409 c = scr_readw((u16 *) vc->vc_pos);
410 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
412 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
413 get_color(vc, info, c, 0));
414 release_console_sem();
417 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
418 static int cursor_blink_rate;
419 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
421 struct fb_info *info = dev_id;
423 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
424 schedule_work(&info->queue);
425 vbl_cursor_cnt = cursor_blink_rate;
431 static void cursor_timer_handler(unsigned long dev_addr)
433 struct fb_info *info = (struct fb_info *) dev_addr;
434 struct fbcon_ops *ops = info->fbcon_par;
436 schedule_work(&info->queue);
437 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
440 static void fbcon_add_cursor_timer(struct fb_info *info)
442 struct fbcon_ops *ops = info->fbcon_par;
444 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
445 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
446 if (!info->queue.func)
447 INIT_WORK(&info->queue, fb_flashcursor, info);
449 init_timer(&ops->cursor_timer);
450 ops->cursor_timer.function = cursor_timer_handler;
451 ops->cursor_timer.expires = jiffies + HZ / 5;
452 ops->cursor_timer.data = (unsigned long ) info;
453 add_timer(&ops->cursor_timer);
454 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
458 static void fbcon_del_cursor_timer(struct fb_info *info)
460 struct fbcon_ops *ops = info->fbcon_par;
462 if (info->queue.func == fb_flashcursor &&
463 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
464 del_timer_sync(&ops->cursor_timer);
465 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
470 static int __init fb_console_setup(char *this_opt)
475 if (!this_opt || !*this_opt)
478 while ((options = strsep(&this_opt, ",")) != NULL) {
479 if (!strncmp(options, "font:", 5))
480 strcpy(fontname, options + 5);
482 if (!strncmp(options, "scrollback:", 11)) {
485 fbcon_softback_size = simple_strtoul(options, &options, 0);
486 if (*options == 'k' || *options == 'K') {
487 fbcon_softback_size *= 1024;
497 if (!strncmp(options, "map:", 4)) {
500 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
504 (options[j++]-'0') % FB_MAX;
509 if (!strncmp(options, "vc:", 3)) {
512 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
515 if (*options++ == '-')
516 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
517 fbcon_is_default = 0;
520 if (!strncmp(options, "rotate:", 7)) {
523 rotate = simple_strtoul(options, &options, 0);
531 __setup("fbcon=", fb_console_setup);
534 static int search_fb_in_map(int idx)
538 for (i = 0; i < MAX_NR_CONSOLES; i++) {
539 if (con2fb_map[i] == idx)
545 static int search_for_mapped_con(void)
549 for (i = 0; i < MAX_NR_CONSOLES; i++) {
550 if (con2fb_map[i] != -1)
556 static int fbcon_takeover(int show_logo)
560 if (!num_registered_fb)
564 logo_shown = FBCON_LOGO_DONTSHOW;
566 for (i = first_fb_vc; i <= last_fb_vc; i++)
567 con2fb_map[i] = info_idx;
569 #ifdef CONFIG_BOOTSPLASH
573 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
576 for (i = first_fb_vc; i <= last_fb_vc; i++) {
585 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
586 int cols, int rows, int new_cols, int new_rows)
588 /* Need to make room for the logo */
589 struct fbcon_ops *ops = info->fbcon_par;
590 int cnt, erase = vc->vc_video_erase_char, step;
591 unsigned short *save = NULL, *r, *q;
594 * remove underline attribute from erase character
595 * if black and white framebuffer.
597 if (fb_get_color_depth(&info->var, &info->fix) == 1)
599 logo_height = fb_prepare_logo(info, ops->rotate);
600 logo_lines = (logo_height + vc->vc_font.height - 1) /
602 q = (unsigned short *) (vc->vc_origin +
603 vc->vc_size_row * rows);
604 step = logo_lines * cols;
605 for (r = q - logo_lines * cols; r < q; r++)
606 if (scr_readw(r) != vc->vc_video_erase_char)
608 if (r != q && new_rows >= rows + logo_lines) {
609 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
611 int i = cols < new_cols ? cols : new_cols;
612 scr_memsetw(save, erase, logo_lines * new_cols * 2);
614 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
615 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
620 /* We can scroll screen down */
622 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
623 scr_memcpyw(r + step, r, vc->vc_size_row);
627 vc->vc_y += logo_lines;
628 vc->vc_pos += logo_lines * vc->vc_size_row;
631 scr_memsetw((unsigned short *) vc->vc_origin,
633 vc->vc_size_row * logo_lines);
635 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
636 fbcon_clear_margins(vc, 0);
641 q = (unsigned short *) (vc->vc_origin +
644 scr_memcpyw(q, save, logo_lines * new_cols * 2);
645 vc->vc_y += logo_lines;
646 vc->vc_pos += logo_lines * vc->vc_size_row;
650 if (logo_lines > vc->vc_bottom) {
651 logo_shown = FBCON_LOGO_CANSHOW;
653 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
654 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
655 logo_shown = FBCON_LOGO_DRAW;
656 vc->vc_top = logo_lines;
660 #ifdef CONFIG_FB_TILEBLITTING
661 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
663 struct fbcon_ops *ops = info->fbcon_par;
665 ops->p = &fb_display[vc->vc_num];
667 if ((info->flags & FBINFO_MISC_TILEBLITTING))
668 fbcon_set_tileops(vc, info);
670 fbcon_set_rotation(info);
671 fbcon_set_bitops(ops);
675 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
677 struct fbcon_ops *ops = info->fbcon_par;
679 info->flags &= ~FBINFO_MISC_TILEBLITTING;
680 ops->p = &fb_display[vc->vc_num];
681 fbcon_set_rotation(info);
682 fbcon_set_bitops(ops);
684 #endif /* CONFIG_MISC_TILEBLITTING */
687 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
688 int unit, int oldidx)
690 struct fbcon_ops *ops = NULL;
693 if (!try_module_get(info->fbops->owner))
696 if (!err && info->fbops->fb_open &&
697 info->fbops->fb_open(info, 0))
701 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
707 info->fbcon_par = ops;
708 set_blitting_type(vc, info);
712 con2fb_map[unit] = oldidx;
713 module_put(info->fbops->owner);
719 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
720 struct fb_info *newinfo, int unit,
721 int oldidx, int found)
723 struct fbcon_ops *ops = oldinfo->fbcon_par;
726 if (oldinfo->fbops->fb_release &&
727 oldinfo->fbops->fb_release(oldinfo, 0)) {
728 con2fb_map[unit] = oldidx;
729 if (!found && newinfo->fbops->fb_release)
730 newinfo->fbops->fb_release(newinfo, 0);
732 module_put(newinfo->fbops->owner);
737 fbcon_del_cursor_timer(oldinfo);
738 kfree(ops->cursor_state.mask);
739 kfree(ops->cursor_data);
740 kfree(ops->fontbuffer);
741 kfree(oldinfo->fbcon_par);
742 oldinfo->fbcon_par = NULL;
743 module_put(oldinfo->fbops->owner);
745 If oldinfo and newinfo are driving the same hardware,
746 the fb_release() method of oldinfo may attempt to
747 restore the hardware state. This will leave the
748 newinfo in an undefined state. Thus, a call to
749 fb_set_par() may be needed for the newinfo.
751 if (newinfo->fbops->fb_set_par)
752 newinfo->fbops->fb_set_par(newinfo);
758 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
759 int unit, int show_logo)
761 struct fbcon_ops *ops = info->fbcon_par;
763 ops->currcon = fg_console;
765 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
766 info->fbops->fb_set_par(info);
768 ops->flags |= FBCON_FLAGS_INIT;
772 fbcon_set_disp(info, &info->var, vc);
774 fbcon_preset_disp(info, &info->var, unit);
777 struct vc_data *fg_vc = vc_cons[fg_console].d;
778 struct fb_info *fg_info =
779 registered_fb[con2fb_map[fg_console]];
781 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
782 fg_vc->vc_rows, fg_vc->vc_cols,
786 update_screen(vc_cons[fg_console].d);
790 * set_con2fb_map - map console to frame buffer device
791 * @unit: virtual console number to map
792 * @newidx: frame buffer index to map virtual console to
793 * @user: user request
795 * Maps a virtual console @unit to a frame buffer device
798 static int set_con2fb_map(int unit, int newidx, int user)
800 struct vc_data *vc = vc_cons[unit].d;
801 int oldidx = con2fb_map[unit];
802 struct fb_info *info = registered_fb[newidx];
803 struct fb_info *oldinfo = NULL;
806 if (oldidx == newidx)
812 if (!err && !search_for_mapped_con()) {
814 return fbcon_takeover(0);
818 oldinfo = registered_fb[oldidx];
820 found = search_fb_in_map(newidx);
822 acquire_console_sem();
823 con2fb_map[unit] = newidx;
825 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
829 * If old fb is not mapped to any of the consoles,
830 * fbcon should release it.
832 if (!err && oldinfo && !search_fb_in_map(oldidx))
833 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
837 int show_logo = (fg_console == 0 && !user &&
838 logo_shown != FBCON_LOGO_DONTSHOW);
841 fbcon_add_cursor_timer(info);
842 con2fb_map_boot[unit] = newidx;
843 con2fb_init_display(vc, info, unit, show_logo);
846 release_console_sem();
851 * Low Level Operations
853 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
854 static int var_to_display(struct display *disp,
855 struct fb_var_screeninfo *var,
856 struct fb_info *info)
858 disp->xres_virtual = var->xres_virtual;
859 disp->yres_virtual = var->yres_virtual;
860 disp->bits_per_pixel = var->bits_per_pixel;
861 disp->grayscale = var->grayscale;
862 disp->nonstd = var->nonstd;
863 disp->accel_flags = var->accel_flags;
864 disp->height = var->height;
865 disp->width = var->width;
866 disp->red = var->red;
867 disp->green = var->green;
868 disp->blue = var->blue;
869 disp->transp = var->transp;
870 disp->rotate = var->rotate;
871 disp->mode = fb_match_mode(var, &info->modelist);
872 if (disp->mode == NULL)
873 /* This should not happen */
878 static void display_to_var(struct fb_var_screeninfo *var,
879 struct display *disp)
881 fb_videomode_to_var(var, disp->mode);
882 var->xres_virtual = disp->xres_virtual;
883 var->yres_virtual = disp->yres_virtual;
884 var->bits_per_pixel = disp->bits_per_pixel;
885 var->grayscale = disp->grayscale;
886 var->nonstd = disp->nonstd;
887 var->accel_flags = disp->accel_flags;
888 var->height = disp->height;
889 var->width = disp->width;
890 var->red = disp->red;
891 var->green = disp->green;
892 var->blue = disp->blue;
893 var->transp = disp->transp;
894 var->rotate = disp->rotate;
897 static const char *fbcon_startup(void)
899 const char *display_desc = "frame buffer device";
900 struct display *p = &fb_display[fg_console];
901 struct vc_data *vc = vc_cons[fg_console].d;
902 const struct font_desc *font = NULL;
903 struct module *owner;
904 struct fb_info *info = NULL;
905 struct fbcon_ops *ops;
911 * If num_registered_fb is zero, this is a call for the dummy part.
912 * The frame buffer devices weren't initialized yet.
914 if (!num_registered_fb || info_idx == -1)
917 * Instead of blindly using registered_fb[0], we use info_idx, set by
920 info = registered_fb[info_idx];
924 owner = info->fbops->owner;
925 if (!try_module_get(owner))
927 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
932 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
940 ops->cur_rotate = -1;
941 info->fbcon_par = ops;
942 p->con_rotate = rotate;
943 set_blitting_type(vc, info);
945 if (info->fix.type != FB_TYPE_TEXT) {
946 if (fbcon_softback_size) {
950 kmalloc(fbcon_softback_size,
953 fbcon_softback_size = 0;
959 kfree((void *) softback_buf);
965 softback_in = softback_top = softback_curr =
970 /* Setup default font */
972 if (!fontname[0] || !(font = find_font(fontname)))
973 font = get_default_font(info->var.xres,
975 vc->vc_font.width = font->width;
976 vc->vc_font.height = font->height;
977 vc->vc_font.data = (void *)(p->fontdata = font->data);
978 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
981 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
982 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
983 cols /= vc->vc_font.width;
984 rows /= vc->vc_font.height;
985 vc_resize(vc, cols, rows);
987 DPRINTK("mode: %s\n", info->fix.id);
988 DPRINTK("visual: %d\n", info->fix.visual);
989 DPRINTK("res: %dx%d-%d\n", info->var.xres,
991 info->var.bits_per_pixel);
995 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
997 request_irq(IRQ_AUTO_4, fb_vbl_handler,
998 IRQ_TYPE_PRIO, "framebuffer vbl",
1001 #endif /* CONFIG_ATARI */
1005 * On a Macintoy, the VBL interrupt may or may not be active.
1006 * As interrupt based cursor is more reliable and race free, we
1007 * probe for VBL interrupts.
1012 * Probe for VBL: set temp. handler ...
1014 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1015 "framebuffer vbl", info);
1019 * ... and spin for 20 ms ...
1021 while (!vbl_detected && ++ct < 1000)
1026 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1028 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1032 * interrupt based cursor ok
1034 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1036 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1037 "framebuffer vbl", info);
1040 * VBL not detected: fall through, use timer based cursor
1045 #endif /* CONFIG_MAC */
1047 fbcon_add_cursor_timer(info);
1048 return display_desc;
1051 static void fbcon_init(struct vc_data *vc, int init)
1053 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1054 struct fbcon_ops *ops;
1055 struct vc_data **default_mode = vc->vc_display_fg;
1056 struct vc_data *svc = *default_mode;
1057 struct display *t, *p = &fb_display[vc->vc_num];
1058 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1061 if (info_idx == -1 || info == NULL)
1066 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1067 (info->fix.type == FB_TYPE_TEXT))
1070 if (var_to_display(p, &info->var, info))
1073 /* If we are not the first console on this
1074 fb, copy the font from that console */
1075 t = &fb_display[svc->vc_num];
1076 if (!vc->vc_font.data) {
1077 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1078 vc->vc_font.width = (*default_mode)->vc_font.width;
1079 vc->vc_font.height = (*default_mode)->vc_font.height;
1080 p->userfont = t->userfont;
1082 REFCOUNT(p->fontdata)++;
1085 charcnt = FNTCHARCNT(p->fontdata);
1086 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1087 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1088 if (charcnt == 256) {
1089 vc->vc_hi_font_mask = 0;
1091 vc->vc_hi_font_mask = 0x100;
1092 if (vc->vc_can_do_color)
1093 vc->vc_complement_mask <<= 1;
1096 if (!*svc->vc_uni_pagedir_loc)
1097 con_set_default_unimap(svc);
1098 if (!*vc->vc_uni_pagedir_loc)
1099 con_copy_unimap(vc, svc);
1101 ops = info->fbcon_par;
1102 p->con_rotate = rotate;
1103 set_blitting_type(vc, info);
1107 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1108 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1109 new_cols /= vc->vc_font.width;
1110 new_rows /= vc->vc_font.height;
1112 #ifdef CONFIG_BOOTSPLASH
1113 if (vc->vc_splash_data && vc->vc_splash_data->splash_state) {
1114 new_cols = vc->vc_splash_data->splash_text_wi / vc->vc_font.width;
1115 new_rows = vc->vc_splash_data->splash_text_he / vc->vc_font.height;
1117 con_remap_def_color(vc, vc->vc_splash_data->splash_color << 4 | vc->vc_splash_data->splash_fg_color);
1121 vc_resize(vc, new_cols, new_rows);
1124 * We must always set the mode. The mode of the previous console
1125 * driver could be in the same resolution but we are using different
1126 * hardware so we have to initialize the hardware.
1128 * We need to do it in fbcon_init() to prevent screen corruption.
1130 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1131 if (info->fbops->fb_set_par &&
1132 !(ops->flags & FBCON_FLAGS_INIT))
1133 info->fbops->fb_set_par(info);
1134 ops->flags |= FBCON_FLAGS_INIT;
1139 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1140 !(cap & FBINFO_HWACCEL_DISABLED))
1141 p->scrollmode = SCROLL_MOVE;
1142 else /* default to something safe */
1143 p->scrollmode = SCROLL_REDRAW;
1146 * ++guenther: console.c:vc_allocate() relies on initializing
1147 * vc_{cols,rows}, but we must not set those if we are only
1148 * resizing the console.
1151 vc->vc_cols = new_cols;
1152 vc->vc_rows = new_rows;
1156 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1158 if (vc == svc && softback_buf)
1159 fbcon_update_softback(vc);
1161 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1162 ops->rotate = FB_ROTATE_UR;
1163 set_blitting_type(vc, info);
1166 ops->p = &fb_display[fg_console];
1169 static void fbcon_deinit(struct vc_data *vc)
1171 struct display *p = &fb_display[vc->vc_num];
1178 /* ====================================================================== */
1180 /* fbcon_XXX routines - interface used by the world
1182 * This system is now divided into two levels because of complications
1183 * caused by hardware scrolling. Top level functions:
1185 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1187 * handles y values in range [0, scr_height-1] that correspond to real
1188 * screen positions. y_wrap shift means that first line of bitmap may be
1189 * anywhere on this display. These functions convert lineoffsets to
1190 * bitmap offsets and deal with the wrap-around case by splitting blits.
1192 * fbcon_bmove_physical_8() -- These functions fast implementations
1193 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1194 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1198 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1199 * Implies should only really hardware scroll in rows. Only reason for
1200 * restriction is simplicity & efficiency at the moment.
1203 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1206 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1207 struct fbcon_ops *ops = info->fbcon_par;
1209 struct display *p = &fb_display[vc->vc_num];
1212 if (fbcon_is_inactive(vc, info))
1215 if (!height || !width)
1218 /* Split blits that cross physical y_wrap boundary */
1220 y_break = p->vrows - p->yscroll;
1221 if (sy < y_break && sy + height - 1 >= y_break) {
1222 u_int b = y_break - sy;
1223 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1224 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1227 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1230 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1231 int count, int ypos, int xpos)
1233 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1234 struct display *p = &fb_display[vc->vc_num];
1235 struct fbcon_ops *ops = info->fbcon_par;
1237 if (!fbcon_is_inactive(vc, info))
1238 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1239 get_color(vc, info, scr_readw(s), 1),
1240 get_color(vc, info, scr_readw(s), 0));
1243 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1247 scr_writew(c, &chr);
1248 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1251 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1253 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1254 struct fbcon_ops *ops = info->fbcon_par;
1256 if (!fbcon_is_inactive(vc, info))
1257 ops->clear_margins(vc, info, bottom_only);
1260 static void fbcon_cursor(struct vc_data *vc, int mode)
1262 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1263 struct fbcon_ops *ops = info->fbcon_par;
1265 int c = scr_readw((u16 *) vc->vc_pos);
1267 if (fbcon_is_inactive(vc, info))
1270 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1271 if (mode & CM_SOFTBACK) {
1272 mode &= ~CM_SOFTBACK;
1276 fbcon_set_origin(vc);
1280 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1281 get_color(vc, info, c, 0));
1282 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1285 static int scrollback_phys_max = 0;
1286 static int scrollback_max = 0;
1287 static int scrollback_current = 0;
1290 * If no vc is existent yet, just set struct display
1292 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1295 struct display *p = &fb_display[unit];
1296 struct display *t = &fb_display[fg_console];
1298 if (var_to_display(p, var, info))
1301 p->fontdata = t->fontdata;
1302 p->userfont = t->userfont;
1304 REFCOUNT(p->fontdata)++;
1307 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1310 struct display *p = &fb_display[vc->vc_num], *t;
1311 struct vc_data **default_mode = vc->vc_display_fg;
1312 struct vc_data *svc = *default_mode;
1313 struct fbcon_ops *ops = info->fbcon_par;
1314 int rows, cols, charcnt = 256;
1316 if (var_to_display(p, var, info))
1318 t = &fb_display[svc->vc_num];
1319 if (!vc->vc_font.data) {
1320 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1321 vc->vc_font.width = (*default_mode)->vc_font.width;
1322 vc->vc_font.height = (*default_mode)->vc_font.height;
1323 p->userfont = t->userfont;
1325 REFCOUNT(p->fontdata)++;
1328 charcnt = FNTCHARCNT(p->fontdata);
1330 var->activate = FB_ACTIVATE_NOW;
1331 info->var.activate = var->activate;
1332 var->yoffset = info->var.yoffset;
1333 var->xoffset = info->var.xoffset;
1334 fb_set_var(info, var);
1335 ops->var = info->var;
1336 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1337 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1338 if (charcnt == 256) {
1339 vc->vc_hi_font_mask = 0;
1341 vc->vc_hi_font_mask = 0x100;
1342 if (vc->vc_can_do_color)
1343 vc->vc_complement_mask <<= 1;
1346 if (!*svc->vc_uni_pagedir_loc)
1347 con_set_default_unimap(svc);
1348 if (!*vc->vc_uni_pagedir_loc)
1349 con_copy_unimap(vc, svc);
1351 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1352 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1353 cols /= vc->vc_font.width;
1354 rows /= vc->vc_font.height;
1355 vc_resize(vc, cols, rows);
1357 if (CON_IS_VISIBLE(vc)) {
1360 fbcon_update_softback(vc);
1364 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1366 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1367 struct fbcon_ops *ops = info->fbcon_par;
1368 struct display *p = &fb_display[vc->vc_num];
1370 p->yscroll += count;
1371 if (p->yscroll >= p->vrows) /* Deal with wrap */
1372 p->yscroll -= p->vrows;
1373 ops->var.xoffset = 0;
1374 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1375 ops->var.vmode |= FB_VMODE_YWRAP;
1376 ops->update_start(info);
1377 scrollback_max += count;
1378 if (scrollback_max > scrollback_phys_max)
1379 scrollback_max = scrollback_phys_max;
1380 scrollback_current = 0;
1383 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1385 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1386 struct fbcon_ops *ops = info->fbcon_par;
1387 struct display *p = &fb_display[vc->vc_num];
1389 p->yscroll -= count;
1390 if (p->yscroll < 0) /* Deal with wrap */
1391 p->yscroll += p->vrows;
1392 ops->var.xoffset = 0;
1393 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1394 ops->var.vmode |= FB_VMODE_YWRAP;
1395 ops->update_start(info);
1396 scrollback_max -= count;
1397 if (scrollback_max < 0)
1399 scrollback_current = 0;
1402 static __inline__ void ypan_up(struct vc_data *vc, int count)
1404 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1405 struct display *p = &fb_display[vc->vc_num];
1406 struct fbcon_ops *ops = info->fbcon_par;
1408 p->yscroll += count;
1409 if (p->yscroll > p->vrows - vc->vc_rows) {
1410 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1411 0, 0, 0, vc->vc_rows, vc->vc_cols);
1412 p->yscroll -= p->vrows - vc->vc_rows;
1415 ops->var.xoffset = 0;
1416 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1417 ops->var.vmode &= ~FB_VMODE_YWRAP;
1418 ops->update_start(info);
1419 fbcon_clear_margins(vc, 1);
1420 scrollback_max += count;
1421 if (scrollback_max > scrollback_phys_max)
1422 scrollback_max = scrollback_phys_max;
1423 scrollback_current = 0;
1426 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1428 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1429 struct fbcon_ops *ops = info->fbcon_par;
1430 struct display *p = &fb_display[vc->vc_num];
1432 p->yscroll += count;
1434 if (p->yscroll > p->vrows - vc->vc_rows) {
1435 p->yscroll -= p->vrows - vc->vc_rows;
1436 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1439 ops->var.xoffset = 0;
1440 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1441 ops->var.vmode &= ~FB_VMODE_YWRAP;
1442 ops->update_start(info);
1443 fbcon_clear_margins(vc, 1);
1444 scrollback_max += count;
1445 if (scrollback_max > scrollback_phys_max)
1446 scrollback_max = scrollback_phys_max;
1447 scrollback_current = 0;
1450 static __inline__ void ypan_down(struct vc_data *vc, int count)
1452 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1453 struct display *p = &fb_display[vc->vc_num];
1454 struct fbcon_ops *ops = info->fbcon_par;
1456 p->yscroll -= count;
1457 if (p->yscroll < 0) {
1458 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1459 0, vc->vc_rows, vc->vc_cols);
1460 p->yscroll += p->vrows - vc->vc_rows;
1463 ops->var.xoffset = 0;
1464 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1465 ops->var.vmode &= ~FB_VMODE_YWRAP;
1466 ops->update_start(info);
1467 fbcon_clear_margins(vc, 1);
1468 scrollback_max -= count;
1469 if (scrollback_max < 0)
1471 scrollback_current = 0;
1474 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1476 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1477 struct fbcon_ops *ops = info->fbcon_par;
1478 struct display *p = &fb_display[vc->vc_num];
1480 p->yscroll -= count;
1482 if (p->yscroll < 0) {
1483 p->yscroll += p->vrows - vc->vc_rows;
1484 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1487 ops->var.xoffset = 0;
1488 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1489 ops->var.vmode &= ~FB_VMODE_YWRAP;
1490 ops->update_start(info);
1491 fbcon_clear_margins(vc, 1);
1492 scrollback_max -= count;
1493 if (scrollback_max < 0)
1495 scrollback_current = 0;
1498 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1501 int count = vc->vc_rows;
1502 unsigned short *d, *s;
1506 d = (u16 *) softback_curr;
1507 if (d == (u16 *) softback_in)
1508 d = (u16 *) vc->vc_origin;
1509 n = softback_curr + delta * vc->vc_size_row;
1510 softback_lines -= delta;
1512 if (softback_curr < softback_top && n < softback_buf) {
1513 n += softback_end - softback_buf;
1514 if (n < softback_top) {
1516 (softback_top - n) / vc->vc_size_row;
1519 } else if (softback_curr >= softback_top
1520 && n < softback_top) {
1522 (softback_top - n) / vc->vc_size_row;
1526 if (softback_curr > softback_in && n >= softback_end) {
1527 n += softback_buf - softback_end;
1528 if (n > softback_in) {
1532 } else if (softback_curr <= softback_in && n > softback_in) {
1537 if (n == softback_curr)
1540 s = (u16 *) softback_curr;
1541 if (s == (u16 *) softback_in)
1542 s = (u16 *) vc->vc_origin;
1544 unsigned short *start;
1548 unsigned short attr = 1;
1551 le = advance_row(s, 1);
1554 if (attr != (c & 0xff00)) {
1557 fbcon_putcs(vc, start, s - start,
1563 if (c == scr_readw(d)) {
1565 fbcon_putcs(vc, start, s - start,
1578 fbcon_putcs(vc, start, s - start, line, x);
1580 if (d == (u16 *) softback_end)
1581 d = (u16 *) softback_buf;
1582 if (d == (u16 *) softback_in)
1583 d = (u16 *) vc->vc_origin;
1584 if (s == (u16 *) softback_end)
1585 s = (u16 *) softback_buf;
1586 if (s == (u16 *) softback_in)
1587 s = (u16 *) vc->vc_origin;
1591 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1592 int line, int count, int dy)
1594 unsigned short *s = (unsigned short *)
1595 (vc->vc_origin + vc->vc_size_row * line);
1598 unsigned short *start = s;
1599 unsigned short *le = advance_row(s, 1);
1602 unsigned short attr = 1;
1606 if (attr != (c & 0xff00)) {
1609 fbcon_putcs(vc, start, s - start,
1615 console_conditional_schedule();
1619 fbcon_putcs(vc, start, s - start, dy, x);
1620 console_conditional_schedule();
1625 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1626 int line, int count, int offset)
1628 unsigned short *d = (unsigned short *)
1629 (vc->vc_origin + vc->vc_size_row * line);
1630 unsigned short *s = d + offset;
1633 unsigned short *start = s;
1634 unsigned short *le = advance_row(s, 1);
1637 unsigned short attr = 1;
1641 if (attr != (c & 0xff00)) {
1644 fbcon_putcs(vc, start, s - start,
1650 if (c == scr_readw(d)) {
1652 fbcon_putcs(vc, start, s - start,
1662 console_conditional_schedule();
1667 fbcon_putcs(vc, start, s - start, line, x);
1668 console_conditional_schedule();
1673 /* NOTE: We subtract two lines from these pointers */
1674 s -= vc->vc_size_row;
1675 d -= vc->vc_size_row;
1680 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1685 if (vc->vc_num != fg_console)
1687 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1690 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1692 p = advance_row(p, 1);
1693 softback_in += vc->vc_size_row;
1694 if (softback_in == softback_end)
1695 softback_in = softback_buf;
1696 if (softback_in == softback_top) {
1697 softback_top += vc->vc_size_row;
1698 if (softback_top == softback_end)
1699 softback_top = softback_buf;
1702 softback_curr = softback_in;
1705 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1708 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1709 struct display *p = &fb_display[vc->vc_num];
1710 struct fbcon_ops *ops = info->fbcon_par;
1711 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1713 if (fbcon_is_inactive(vc, info))
1716 fbcon_cursor(vc, CM_ERASE);
1719 * ++Geert: Only use ywrap/ypan if the console is in text mode
1720 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1721 * whole screen (prevents flicker).
1726 if (count > vc->vc_rows) /* Maximum realistic size */
1727 count = vc->vc_rows;
1729 fbcon_softback_note(vc, t, count);
1730 if (logo_shown >= 0)
1732 #ifdef CONFIG_BOOTSPLASH
1733 if (info->splash_data)
1736 switch (p->scrollmode) {
1738 ops->bmove(vc, info, t + count, 0, t, 0,
1739 b - t - count, vc->vc_cols);
1740 ops->clear(vc, info, b - count, 0, count,
1744 case SCROLL_WRAP_MOVE:
1745 if (b - t - count > 3 * vc->vc_rows >> 2) {
1747 fbcon_bmove(vc, 0, 0, count, 0, t,
1749 ywrap_up(vc, count);
1750 if (vc->vc_rows - b > 0)
1751 fbcon_bmove(vc, b - count, 0, b, 0,
1754 } else if (info->flags & FBINFO_READS_FAST)
1755 fbcon_bmove(vc, t + count, 0, t, 0,
1756 b - t - count, vc->vc_cols);
1759 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1762 case SCROLL_PAN_REDRAW:
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_redraw_move(vc, p, 0, t, count);
1771 ypan_up_redraw(vc, t, count);
1772 if (vc->vc_rows - b > 0)
1773 fbcon_redraw_move(vc, p, b,
1774 vc->vc_rows - b, b);
1776 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1777 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1780 case SCROLL_PAN_MOVE:
1781 if ((p->yscroll + count <=
1782 2 * (p->vrows - vc->vc_rows))
1783 && ((!scroll_partial && (b - t == vc->vc_rows))
1786 3 * vc->vc_rows >> 2)))) {
1788 fbcon_bmove(vc, 0, 0, count, 0, t,
1791 if (vc->vc_rows - b > 0)
1792 fbcon_bmove(vc, b - count, 0, b, 0,
1795 } else if (info->flags & FBINFO_READS_FAST)
1796 fbcon_bmove(vc, t + count, 0, t, 0,
1797 b - t - count, vc->vc_cols);
1800 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1805 fbcon_redraw(vc, p, t, b - t - count,
1806 count * vc->vc_cols);
1807 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1808 scr_memsetw((unsigned short *) (vc->vc_origin +
1811 vc->vc_video_erase_char,
1812 vc->vc_size_row * count);
1818 if (count > vc->vc_rows) /* Maximum realistic size */
1819 count = vc->vc_rows;
1820 if (logo_shown >= 0)
1822 #ifdef CONFIG_BOOTSPLASH
1823 if (info->splash_data)
1826 switch (p->scrollmode) {
1828 ops->bmove(vc, info, t, 0, t + count, 0,
1829 b - t - count, vc->vc_cols);
1830 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1833 case SCROLL_WRAP_MOVE:
1834 if (b - t - count > 3 * vc->vc_rows >> 2) {
1835 if (vc->vc_rows - b > 0)
1836 fbcon_bmove(vc, b, 0, b - count, 0,
1839 ywrap_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_MOVE:
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_bmove(vc, b, 0, b - count, 0,
1861 ypan_down(vc, count);
1863 fbcon_bmove(vc, count, 0, 0, 0, t,
1865 } else if (info->flags & FBINFO_READS_FAST)
1866 fbcon_bmove(vc, t, 0, t + count, 0,
1867 b - t - count, vc->vc_cols);
1870 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1873 case SCROLL_PAN_REDRAW:
1874 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1875 && ((!scroll_partial && (b - t == vc->vc_rows))
1878 3 * vc->vc_rows >> 2)))) {
1879 if (vc->vc_rows - b > 0)
1880 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1882 ypan_down_redraw(vc, t, count);
1884 fbcon_redraw_move(vc, p, count, t, 0);
1886 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1887 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1892 fbcon_redraw(vc, p, b - 1, b - t - count,
1893 -count * vc->vc_cols);
1894 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1895 scr_memsetw((unsigned short *) (vc->vc_origin +
1898 vc->vc_video_erase_char,
1899 vc->vc_size_row * count);
1907 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1908 int height, int width)
1910 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1911 struct display *p = &fb_display[vc->vc_num];
1913 if (fbcon_is_inactive(vc, info))
1916 if (!width || !height)
1919 /* Split blits that cross physical y_wrap case.
1920 * Pathological case involves 4 blits, better to use recursive
1921 * code rather than unrolled case
1923 * Recursive invocations don't need to erase the cursor over and
1924 * over again, so we use fbcon_bmove_rec()
1926 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1927 p->vrows - p->yscroll);
1930 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1931 int dy, int dx, int height, int width, u_int y_break)
1933 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1934 struct fbcon_ops *ops = info->fbcon_par;
1937 if (sy < y_break && sy + height > y_break) {
1939 if (dy < sy) { /* Avoid trashing self */
1940 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1942 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1943 height - b, width, y_break);
1945 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1946 height - b, width, y_break);
1947 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1953 if (dy < y_break && dy + height > y_break) {
1955 if (dy < sy) { /* Avoid trashing self */
1956 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1958 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1959 height - b, width, y_break);
1961 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1962 height - b, width, y_break);
1963 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1969 #ifdef CONFIG_BOOTSPLASH
1970 if (info->splash_data && sy == dy && height == 1) {
1971 /* must use slower redraw bmove to keep background pic intact */
1972 splash_bmove_redraw(info->splash_data, vc, info, sy, sx, dx, width);
1976 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1980 static __inline__ void updatescrollmode(struct display *p,
1981 struct fb_info *info,
1984 struct fbcon_ops *ops = info->fbcon_par;
1985 int fh = vc->vc_font.height;
1986 int cap = info->flags;
1988 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1989 info->fix.xpanstep);
1990 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1991 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1992 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1993 info->var.xres_virtual);
1994 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1995 divides(ypan, vc->vc_font.height) && vyres > yres;
1996 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1997 divides(ywrap, vc->vc_font.height) &&
1998 divides(vc->vc_font.height, vyres) &&
1999 divides(vc->vc_font.height, yres);
2000 int reading_fast = cap & FBINFO_READS_FAST;
2001 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2002 !(cap & FBINFO_HWACCEL_DISABLED);
2003 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2004 !(cap & FBINFO_HWACCEL_DISABLED);
2006 p->vrows = vyres/fh;
2007 if (yres > (fh * (vc->vc_rows + 1)))
2008 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2009 if ((yres % fh) && (vyres % fh < yres % fh))
2012 if (good_wrap || good_pan) {
2013 if (reading_fast || fast_copyarea)
2014 p->scrollmode = good_wrap ?
2015 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2017 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2020 if (reading_fast || (fast_copyarea && !fast_imageblit))
2021 p->scrollmode = SCROLL_MOVE;
2023 p->scrollmode = SCROLL_REDRAW;
2027 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2028 unsigned int height)
2030 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2031 struct fbcon_ops *ops = info->fbcon_par;
2032 struct display *p = &fb_display[vc->vc_num];
2033 struct fb_var_screeninfo var = info->var;
2034 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2036 virt_w = FBCON_SWAP(ops->rotate, width, height);
2037 virt_h = FBCON_SWAP(ops->rotate, height, width);
2038 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2039 vc->vc_font.height);
2040 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2042 var.xres = virt_w * virt_fw;
2043 var.yres = virt_h * virt_fh;
2044 x_diff = info->var.xres - var.xres;
2045 y_diff = info->var.yres - var.yres;
2046 if (x_diff < 0 || x_diff > virt_fw ||
2047 y_diff < 0 || y_diff > virt_fh) {
2048 struct fb_videomode *mode;
2050 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2051 mode = fb_find_best_mode(&var, &info->modelist);
2054 display_to_var(&var, p);
2055 fb_videomode_to_var(&var, mode);
2057 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2060 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2061 if (CON_IS_VISIBLE(vc)) {
2062 var.activate = FB_ACTIVATE_NOW |
2064 fb_set_var(info, &var);
2066 var_to_display(p, &info->var, info);
2067 ops->var = info->var;
2069 updatescrollmode(p, info, vc);
2073 static int fbcon_switch(struct vc_data *vc)
2075 struct fb_info *info, *old_info = NULL;
2076 struct fbcon_ops *ops;
2077 struct display *p = &fb_display[vc->vc_num];
2078 struct fb_var_screeninfo var;
2079 int i, prev_console, charcnt = 256;
2081 info = registered_fb[con2fb_map[vc->vc_num]];
2082 ops = info->fbcon_par;
2084 #ifdef CONFIG_BOOTSPLASH
2085 splash_prepare(vc, info);
2090 fbcon_set_origin(vc);
2091 softback_top = softback_curr = softback_in = softback_buf;
2093 fbcon_update_softback(vc);
2096 if (logo_shown >= 0) {
2097 struct vc_data *conp2 = vc_cons[logo_shown].d;
2099 if (conp2->vc_top == logo_lines
2100 && conp2->vc_bottom == conp2->vc_rows)
2102 logo_shown = FBCON_LOGO_CANSHOW;
2105 prev_console = ops->currcon;
2106 if (prev_console != -1)
2107 old_info = registered_fb[con2fb_map[prev_console]];
2109 * FIXME: If we have multiple fbdev's loaded, we need to
2110 * update all info->currcon. Perhaps, we can place this
2111 * in a centralized structure, but this might break some
2114 * info->currcon = vc->vc_num;
2116 for (i = 0; i < FB_MAX; i++) {
2117 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2118 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2120 o->currcon = vc->vc_num;
2123 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2124 display_to_var(&var, p);
2125 var.activate = FB_ACTIVATE_NOW;
2128 * make sure we don't unnecessarily trip the memcmp()
2131 info->var.activate = var.activate;
2132 var.yoffset = info->var.yoffset;
2133 var.xoffset = info->var.xoffset;
2134 var.vmode = info->var.vmode;
2135 fb_set_var(info, &var);
2136 ops->var = info->var;
2138 if (old_info != NULL && (old_info != info ||
2139 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2140 if (info->fbops->fb_set_par)
2141 info->fbops->fb_set_par(info);
2143 if (old_info != info) {
2144 fbcon_del_cursor_timer(old_info);
2145 fbcon_add_cursor_timer(info);
2149 set_blitting_type(vc, info);
2150 ops->cursor_reset = 1;
2152 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2153 ops->rotate = FB_ROTATE_UR;
2154 set_blitting_type(vc, info);
2157 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2158 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2161 charcnt = FNTCHARCNT(vc->vc_font.data);
2164 vc->vc_complement_mask <<= 1;
2166 updatescrollmode(p, info, vc);
2168 switch (p->scrollmode) {
2169 case SCROLL_WRAP_MOVE:
2170 scrollback_phys_max = p->vrows - vc->vc_rows;
2172 case SCROLL_PAN_MOVE:
2173 case SCROLL_PAN_REDRAW:
2174 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2175 if (scrollback_phys_max < 0)
2176 scrollback_phys_max = 0;
2179 scrollback_phys_max = 0;
2184 scrollback_current = 0;
2186 if (!fbcon_is_inactive(vc, info)) {
2187 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2188 ops->update_start(info);
2191 fbcon_set_palette(vc, color_table);
2192 fbcon_clear_margins(vc, 0);
2194 if (logo_shown == FBCON_LOGO_DRAW) {
2196 logo_shown = fg_console;
2197 /* This is protected above by initmem_freed */
2198 fb_show_logo(info, ops->rotate);
2200 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2201 vc->vc_size_row * (vc->vc_bottom -
2208 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2211 #ifdef CONFIG_BOOTSPLASH
2212 if (info->splash_data) {
2213 splash_blank(info->splash_data, vc, info, blank);
2218 unsigned short charmask = vc->vc_hi_font_mask ?
2220 unsigned short oldc;
2222 oldc = vc->vc_video_erase_char;
2223 vc->vc_video_erase_char &= charmask;
2224 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2225 vc->vc_video_erase_char = oldc;
2229 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2231 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2232 struct fbcon_ops *ops = info->fbcon_par;
2235 struct fb_var_screeninfo var = info->var;
2240 if (info->fbops->fb_save_state)
2241 info->fbops->fb_save_state(info);
2242 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2243 fb_set_var(info, &var);
2245 ops->var = info->var;
2246 } else if (info->fbops->fb_restore_state)
2247 info->fbops->fb_restore_state(info);
2250 if (!fbcon_is_inactive(vc, info)) {
2251 if (ops->blank_state != blank) {
2252 ops->blank_state = blank;
2253 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2254 ops->cursor_flash = (!blank);
2256 if (fb_blank(info, blank))
2257 fbcon_generic_blank(vc, info, blank);
2265 fbcon_add_cursor_timer(info);
2267 fbcon_del_cursor_timer(info);
2272 static void fbcon_free_font(struct display *p)
2274 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2275 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2280 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2282 u8 *fontdata = vc->vc_font.data;
2283 u8 *data = font->data;
2286 font->width = vc->vc_font.width;
2287 font->height = vc->vc_font.height;
2288 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2292 if (font->width <= 8) {
2293 j = vc->vc_font.height;
2294 for (i = 0; i < font->charcount; i++) {
2295 memcpy(data, fontdata, j);
2296 memset(data + j, 0, 32 - j);
2300 } else if (font->width <= 16) {
2301 j = vc->vc_font.height * 2;
2302 for (i = 0; i < font->charcount; i++) {
2303 memcpy(data, fontdata, j);
2304 memset(data + j, 0, 64 - j);
2308 } else if (font->width <= 24) {
2309 for (i = 0; i < font->charcount; i++) {
2310 for (j = 0; j < vc->vc_font.height; j++) {
2311 *data++ = fontdata[0];
2312 *data++ = fontdata[1];
2313 *data++ = fontdata[2];
2314 fontdata += sizeof(u32);
2316 memset(data, 0, 3 * (32 - j));
2317 data += 3 * (32 - j);
2320 j = vc->vc_font.height * 4;
2321 for (i = 0; i < font->charcount; i++) {
2322 memcpy(data, fontdata, j);
2323 memset(data + j, 0, 128 - j);
2331 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2332 const u8 * data, int userfont)
2334 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2335 struct fbcon_ops *ops = info->fbcon_par;
2336 struct display *p = &fb_display[vc->vc_num];
2339 char *old_data = NULL;
2341 if (CON_IS_VISIBLE(vc) && softback_lines)
2342 fbcon_set_origin(vc);
2344 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2346 old_data = vc->vc_font.data;
2348 cnt = FNTCHARCNT(data);
2351 vc->vc_font.data = (void *)(p->fontdata = data);
2352 if ((p->userfont = userfont))
2354 vc->vc_font.width = w;
2355 vc->vc_font.height = h;
2356 if (vc->vc_hi_font_mask && cnt == 256) {
2357 vc->vc_hi_font_mask = 0;
2358 if (vc->vc_can_do_color) {
2359 vc->vc_complement_mask >>= 1;
2360 vc->vc_s_complement_mask >>= 1;
2363 /* ++Edmund: reorder the attribute bits */
2364 if (vc->vc_can_do_color) {
2365 unsigned short *cp =
2366 (unsigned short *) vc->vc_origin;
2367 int count = vc->vc_screenbuf_size / 2;
2369 for (; count > 0; count--, cp++) {
2371 scr_writew(((c & 0xfe00) >> 1) |
2374 c = vc->vc_video_erase_char;
2375 vc->vc_video_erase_char =
2376 ((c & 0xfe00) >> 1) | (c & 0xff);
2379 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2380 vc->vc_hi_font_mask = 0x100;
2381 if (vc->vc_can_do_color) {
2382 vc->vc_complement_mask <<= 1;
2383 vc->vc_s_complement_mask <<= 1;
2386 /* ++Edmund: reorder the attribute bits */
2388 unsigned short *cp =
2389 (unsigned short *) vc->vc_origin;
2390 int count = vc->vc_screenbuf_size / 2;
2392 for (; count > 0; count--, cp++) {
2393 unsigned short newc;
2395 if (vc->vc_can_do_color)
2397 ((c & 0xff00) << 1) | (c &
2401 scr_writew(newc, cp);
2403 c = vc->vc_video_erase_char;
2404 if (vc->vc_can_do_color) {
2405 vc->vc_video_erase_char =
2406 ((c & 0xff00) << 1) | (c & 0xff);
2409 vc->vc_video_erase_char = c & ~0x100;
2417 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2418 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2419 #ifdef CONFIG_BOOTSPLASH
2420 if (info->splash_data) {
2421 cols = info->splash_data->splash_text_wi;
2422 rows = info->splash_data->splash_text_he;
2427 vc_resize(vc, cols, rows);
2428 if (CON_IS_VISIBLE(vc) && softback_buf)
2429 fbcon_update_softback(vc);
2430 } else if (CON_IS_VISIBLE(vc)
2431 && vc->vc_mode == KD_TEXT) {
2432 fbcon_clear_margins(vc, 0);
2436 if (old_data && (--REFCOUNT(old_data) == 0))
2437 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2441 static int fbcon_copy_font(struct vc_data *vc, int con)
2443 struct display *od = &fb_display[con];
2444 struct console_font *f = &vc->vc_font;
2446 if (od->fontdata == f->data)
2447 return 0; /* already the same font... */
2448 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2452 * User asked to set font; we are guaranteed that
2453 * a) width and height are in range 1..32
2454 * b) charcount does not exceed 512
2455 * but lets not assume that, since someone might someday want to use larger
2456 * fonts. And charcount of 512 is small for unicode support.
2458 * However, user space gives the font in 32 rows , regardless of
2459 * actual font height. So a new API is needed if support for larger fonts
2460 * is ever implemented.
2463 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2465 unsigned charcount = font->charcount;
2466 int w = font->width;
2467 int h = font->height;
2470 u8 *new_data, *data = font->data;
2471 int pitch = (font->width+7) >> 3;
2473 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2474 * If not this check should be changed to charcount < 256 */
2475 if (charcount != 256 && charcount != 512)
2478 size = h * pitch * charcount;
2480 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2485 new_data += FONT_EXTRA_WORDS * sizeof(int);
2486 FNTSIZE(new_data) = size;
2487 FNTCHARCNT(new_data) = charcount;
2488 REFCOUNT(new_data) = 0; /* usage counter */
2489 for (i=0; i< charcount; i++) {
2490 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2493 /* Since linux has a nice crc32 function use it for counting font
2495 csum = crc32(0, new_data, size);
2497 FNTSUM(new_data) = csum;
2498 /* Check if the same font is on some other console already */
2499 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2500 struct vc_data *tmp = vc_cons[i].d;
2502 if (fb_display[i].userfont &&
2503 fb_display[i].fontdata &&
2504 FNTSUM(fb_display[i].fontdata) == csum &&
2505 FNTSIZE(fb_display[i].fontdata) == size &&
2506 tmp->vc_font.width == w &&
2507 !memcmp(fb_display[i].fontdata, new_data, size)) {
2508 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2509 new_data = (u8 *)fb_display[i].fontdata;
2513 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2516 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2518 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2519 const struct font_desc *f;
2522 f = get_default_font(info->var.xres, info->var.yres);
2523 else if (!(f = find_font(name)))
2526 font->width = f->width;
2527 font->height = f->height;
2528 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2531 static u16 palette_red[16];
2532 static u16 palette_green[16];
2533 static u16 palette_blue[16];
2535 static struct fb_cmap palette_cmap = {
2536 0, 16, palette_red, palette_green, palette_blue, NULL
2539 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2541 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2545 if (fbcon_is_inactive(vc, info))
2548 if (!CON_IS_VISIBLE(vc))
2551 depth = fb_get_color_depth(&info->var, &info->fix);
2553 for (i = j = 0; i < 16; i++) {
2555 val = vc->vc_palette[j++];
2556 palette_red[k] = (val << 8) | val;
2557 val = vc->vc_palette[j++];
2558 palette_green[k] = (val << 8) | val;
2559 val = vc->vc_palette[j++];
2560 palette_blue[k] = (val << 8) | val;
2562 palette_cmap.len = 16;
2563 palette_cmap.start = 0;
2565 * If framebuffer is capable of less than 16 colors,
2566 * use default palette of fbcon.
2569 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2571 return fb_set_cmap(&palette_cmap, info);
2574 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2579 if (vc->vc_num != fg_console || !softback_lines)
2580 return (u16 *) (vc->vc_origin + offset);
2581 line = offset / vc->vc_size_row;
2582 if (line >= softback_lines)
2583 return (u16 *) (vc->vc_origin + offset -
2584 softback_lines * vc->vc_size_row);
2585 p = softback_curr + offset;
2586 if (p >= softback_end)
2587 p += softback_buf - softback_end;
2591 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2597 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2598 unsigned long offset = (pos - vc->vc_origin) / 2;
2600 x = offset % vc->vc_cols;
2601 y = offset / vc->vc_cols;
2602 if (vc->vc_num == fg_console)
2603 y += softback_lines;
2604 ret = pos + (vc->vc_cols - x) * 2;
2605 } else if (vc->vc_num == fg_console && softback_lines) {
2606 unsigned long offset = pos - softback_curr;
2608 if (pos < softback_curr)
2609 offset += softback_end - softback_buf;
2611 x = offset % vc->vc_cols;
2612 y = offset / vc->vc_cols;
2613 ret = pos + (vc->vc_cols - x) * 2;
2614 if (ret == softback_end)
2616 if (ret == softback_in)
2617 ret = vc->vc_origin;
2619 /* Should not happen */
2621 ret = vc->vc_origin;
2630 /* As we might be inside of softback, we may work with non-contiguous buffer,
2631 that's why we have to use a separate routine. */
2632 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2635 u16 a = scr_readw(p);
2636 if (!vc->vc_can_do_color)
2638 else if (vc->vc_hi_font_mask == 0x100)
2639 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2640 (((a) & 0x0e00) << 4);
2642 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2643 (((a) & 0x0700) << 4);
2645 if (p == (u16 *) softback_end)
2646 p = (u16 *) softback_buf;
2647 if (p == (u16 *) softback_in)
2648 p = (u16 *) vc->vc_origin;
2652 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2654 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2655 struct fbcon_ops *ops = info->fbcon_par;
2656 struct display *p = &fb_display[fg_console];
2657 int offset, limit, scrollback_old;
2660 if (vc->vc_num != fg_console)
2662 if (vc->vc_mode != KD_TEXT || !lines)
2664 if (logo_shown >= 0) {
2665 struct vc_data *conp2 = vc_cons[logo_shown].d;
2667 if (conp2->vc_top == logo_lines
2668 && conp2->vc_bottom == conp2->vc_rows)
2670 if (logo_shown == vc->vc_num) {
2676 logo_lines * vc->vc_size_row;
2677 for (i = 0; i < logo_lines; i++) {
2678 if (p == softback_top)
2680 if (p == softback_buf)
2682 p -= vc->vc_size_row;
2683 q -= vc->vc_size_row;
2684 scr_memcpyw((u16 *) q, (u16 *) p,
2687 softback_in = softback_curr = p;
2688 update_region(vc, vc->vc_origin,
2689 logo_lines * vc->vc_cols);
2691 logo_shown = FBCON_LOGO_CANSHOW;
2693 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2694 fbcon_redraw_softback(vc, p, lines);
2695 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2699 if (!scrollback_phys_max)
2702 scrollback_old = scrollback_current;
2703 scrollback_current -= lines;
2704 if (scrollback_current < 0)
2705 scrollback_current = 0;
2706 else if (scrollback_current > scrollback_max)
2707 scrollback_current = scrollback_max;
2708 if (scrollback_current == scrollback_old)
2711 if (fbcon_is_inactive(vc, info))
2714 fbcon_cursor(vc, CM_ERASE);
2716 offset = p->yscroll - scrollback_current;
2718 switch (p->scrollmode) {
2719 case SCROLL_WRAP_MOVE:
2720 info->var.vmode |= FB_VMODE_YWRAP;
2722 case SCROLL_PAN_MOVE:
2723 case SCROLL_PAN_REDRAW:
2724 limit -= vc->vc_rows;
2725 info->var.vmode &= ~FB_VMODE_YWRAP;
2730 else if (offset >= limit)
2733 ops->var.xoffset = 0;
2734 ops->var.yoffset = offset * vc->vc_font.height;
2735 ops->update_start(info);
2737 if (!scrollback_current)
2738 fbcon_cursor(vc, CM_DRAW);
2742 static int fbcon_set_origin(struct vc_data *vc)
2745 fbcon_scrolldelta(vc, softback_lines);
2749 static void fbcon_suspended(struct fb_info *info)
2751 struct vc_data *vc = NULL;
2752 struct fbcon_ops *ops = info->fbcon_par;
2754 if (!ops || ops->currcon < 0)
2756 vc = vc_cons[ops->currcon].d;
2758 /* Clear cursor, restore saved data */
2759 fbcon_cursor(vc, CM_ERASE);
2762 static void fbcon_resumed(struct fb_info *info)
2765 struct fbcon_ops *ops = info->fbcon_par;
2767 if (!ops || ops->currcon < 0)
2769 vc = vc_cons[ops->currcon].d;
2774 static void fbcon_modechanged(struct fb_info *info)
2776 struct fbcon_ops *ops = info->fbcon_par;
2781 if (!ops || ops->currcon < 0)
2783 vc = vc_cons[ops->currcon].d;
2784 if (vc->vc_mode != KD_TEXT ||
2785 registered_fb[con2fb_map[ops->currcon]] != info)
2788 p = &fb_display[vc->vc_num];
2789 set_blitting_type(vc, info);
2791 if (CON_IS_VISIBLE(vc)) {
2792 var_to_display(p, &info->var, info);
2793 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2794 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2795 cols /= vc->vc_font.width;
2796 rows /= vc->vc_font.height;
2797 vc_resize(vc, cols, rows);
2798 updatescrollmode(p, info, vc);
2800 scrollback_current = 0;
2802 if (!fbcon_is_inactive(vc, info)) {
2803 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2804 ops->update_start(info);
2807 fbcon_set_palette(vc, color_table);
2810 fbcon_update_softback(vc);
2814 static void fbcon_set_all_vcs(struct fb_info *info)
2816 struct fbcon_ops *ops = info->fbcon_par;
2821 if (!ops || ops->currcon < 0)
2824 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2826 if (!vc || vc->vc_mode != KD_TEXT ||
2827 registered_fb[con2fb_map[i]] != info)
2830 p = &fb_display[vc->vc_num];
2831 set_blitting_type(vc, info);
2832 var_to_display(p, &info->var, info);
2833 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2834 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2835 cols /= vc->vc_font.width;
2836 rows /= vc->vc_font.height;
2837 vc_resize(vc, cols, rows);
2839 if (CON_IS_VISIBLE(vc)) {
2840 updatescrollmode(p, info, vc);
2842 scrollback_current = 0;
2844 if (!fbcon_is_inactive(vc, info)) {
2845 ops->var.xoffset = ops->var.yoffset =
2847 ops->update_start(info);
2850 fbcon_set_palette(vc, color_table);
2853 fbcon_update_softback(vc);
2857 ops->p = &fb_display[ops->currcon];
2860 static int fbcon_mode_deleted(struct fb_info *info,
2861 struct fb_videomode *mode)
2863 struct fb_info *fb_info;
2865 int i, j, found = 0;
2867 /* before deletion, ensure that mode is not in use */
2868 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2872 fb_info = registered_fb[j];
2873 if (fb_info != info)
2878 if (fb_mode_is_equal(p->mode, mode)) {
2886 static int fbcon_fb_registered(int idx)
2890 if (info_idx == -1) {
2891 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2892 if (con2fb_map_boot[i] == idx) {
2898 ret = fbcon_takeover(1);
2900 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2901 if (con2fb_map_boot[i] == idx)
2902 set_con2fb_map(i, idx, 0);
2909 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2911 struct fbcon_ops *ops = info->fbcon_par;
2914 if (!ops || ops->currcon < 0)
2917 vc = vc_cons[ops->currcon].d;
2918 if (vc->vc_mode != KD_TEXT ||
2919 registered_fb[con2fb_map[ops->currcon]] != info)
2922 if (CON_IS_VISIBLE(vc)) {
2926 do_unblank_screen(0);
2928 ops->blank_state = blank;
2931 static void fbcon_new_modelist(struct fb_info *info)
2935 struct fb_var_screeninfo var;
2936 struct fb_videomode *mode;
2938 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2939 if (registered_fb[con2fb_map[i]] != info)
2941 if (!fb_display[i].mode)
2944 display_to_var(&var, &fb_display[i]);
2945 mode = fb_find_nearest_mode(fb_display[i].mode,
2947 fb_videomode_to_var(&var, mode);
2950 fbcon_set_disp(info, &var, vc);
2952 fbcon_preset_disp(info, &var, i);
2957 static int fbcon_event_notify(struct notifier_block *self,
2958 unsigned long action, void *data)
2960 struct fb_event *event = data;
2961 struct fb_info *info = event->info;
2962 struct fb_videomode *mode;
2963 struct fb_con2fbmap *con2fb;
2967 case FB_EVENT_SUSPEND:
2968 fbcon_suspended(info);
2970 case FB_EVENT_RESUME:
2971 fbcon_resumed(info);
2973 case FB_EVENT_MODE_CHANGE:
2974 fbcon_modechanged(info);
2976 case FB_EVENT_MODE_CHANGE_ALL:
2977 fbcon_set_all_vcs(info);
2979 case FB_EVENT_MODE_DELETE:
2981 ret = fbcon_mode_deleted(info, mode);
2983 case FB_EVENT_FB_REGISTERED:
2984 ret = fbcon_fb_registered(info->node);
2986 case FB_EVENT_SET_CONSOLE_MAP:
2987 con2fb = event->data;
2988 ret = set_con2fb_map(con2fb->console - 1,
2989 con2fb->framebuffer, 1);
2991 case FB_EVENT_GET_CONSOLE_MAP:
2992 con2fb = event->data;
2993 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2995 case FB_EVENT_BLANK:
2996 fbcon_fb_blanked(info, *(int *)event->data);
2998 case FB_EVENT_NEW_MODELIST:
2999 fbcon_new_modelist(info);
3001 case FB_EVENT_SET_CON_ROTATE:
3002 fbcon_rotate(info, *(int *)event->data);
3004 case FB_EVENT_GET_CON_ROTATE:
3005 ret = fbcon_get_rotate(info);
3007 case FB_EVENT_SET_CON_ROTATE_ALL:
3008 fbcon_rotate_all(info, *(int *)event->data);
3015 * The console `switch' structure for the frame buffer based console
3018 static const struct consw fb_con = {
3019 .owner = THIS_MODULE,
3020 .con_startup = fbcon_startup,
3021 .con_init = fbcon_init,
3022 .con_deinit = fbcon_deinit,
3023 .con_clear = fbcon_clear,
3024 .con_putc = fbcon_putc,
3025 .con_putcs = fbcon_putcs,
3026 .con_cursor = fbcon_cursor,
3027 .con_scroll = fbcon_scroll,
3028 .con_bmove = fbcon_bmove,
3029 .con_switch = fbcon_switch,
3030 .con_blank = fbcon_blank,
3031 .con_font_set = fbcon_set_font,
3032 .con_font_get = fbcon_get_font,
3033 .con_font_default = fbcon_set_def_font,
3034 .con_font_copy = fbcon_copy_font,
3035 .con_set_palette = fbcon_set_palette,
3036 .con_scrolldelta = fbcon_scrolldelta,
3037 .con_set_origin = fbcon_set_origin,
3038 .con_invert_region = fbcon_invert_region,
3039 .con_screen_pos = fbcon_screen_pos,
3040 .con_getxy = fbcon_getxy,
3041 .con_resize = fbcon_resize,
3044 static struct notifier_block fbcon_event_notifier = {
3045 .notifier_call = fbcon_event_notify,
3048 static int __init fb_console_init(void)
3052 acquire_console_sem();
3053 fb_register_client(&fbcon_event_notifier);
3054 release_console_sem();
3056 for (i = 0; i < MAX_NR_CONSOLES; i++)
3059 if (num_registered_fb) {
3060 for (i = 0; i < FB_MAX; i++) {
3061 if (registered_fb[i] != NULL) {
3072 module_init(fb_console_init);
3076 static void __exit fb_console_exit(void)
3078 acquire_console_sem();
3079 fb_unregister_client(&fbcon_event_notifier);
3080 release_console_sem();
3081 give_up_console(&fb_con);
3084 module_exit(fb_console_exit);
3088 MODULE_LICENSE("GPL");