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/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
79 #include <asm/system.h>
80 #include <asm/uaccess.h>
82 #include <asm/atariints.h>
85 #include <asm/macints.h>
87 #if defined(__mc68000__) || defined(CONFIG_APUS)
88 #include <asm/machdep.h>
89 #include <asm/setup.h>
95 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
97 # define DPRINTK(fmt, args...)
101 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
106 static struct display fb_display[MAX_NR_CONSOLES];
108 static signed char con2fb_map[MAX_NR_CONSOLES];
109 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
111 static int logo_height;
113 static int logo_lines;
114 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
116 static int logo_shown = FBCON_LOGO_CANSHOW;
117 /* Software scrollback */
118 static int fbcon_softback_size = 32768;
119 static unsigned long softback_buf, softback_curr;
120 static unsigned long softback_in;
121 static unsigned long softback_top, softback_end;
122 static int softback_lines;
123 /* console mappings */
124 static int first_fb_vc;
125 static int last_fb_vc = MAX_NR_CONSOLES - 1;
126 static int fbcon_is_default = 1;
127 static int fbcon_has_exited;
130 static char fontname[40];
132 /* current fb_info */
133 static int info_idx = -1;
135 /* console rotation */
137 static int fbcon_has_sysfs;
139 static const struct consw fb_con;
141 #define CM_SOFTBACK (8)
143 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
145 static int fbcon_set_origin(struct vc_data *);
147 #define CURSOR_DRAW_DELAY (1)
149 /* # VBL ints between cursor state changes */
150 #define ATARI_CURSOR_BLINK_RATE (42)
151 #define MAC_CURSOR_BLINK_RATE (32)
152 #define DEFAULT_CURSOR_BLINK_RATE (20)
154 static int vbl_cursor_cnt;
156 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
159 * Interface used by the world
162 static const char *fbcon_startup(void);
163 static void fbcon_init(struct vc_data *vc, int init);
164 static void fbcon_deinit(struct vc_data *vc);
165 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
167 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
168 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
169 int count, int ypos, int xpos);
170 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
171 static void fbcon_cursor(struct vc_data *vc, int mode);
172 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
174 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
175 int height, int width);
176 static int fbcon_switch(struct vc_data *vc);
177 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
178 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
179 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
184 static __inline__ void ywrap_up(struct vc_data *vc, int count);
185 static __inline__ void ywrap_down(struct vc_data *vc, int count);
186 static __inline__ void ypan_up(struct vc_data *vc, int count);
187 static __inline__ void ypan_down(struct vc_data *vc, int count);
188 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
192 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
194 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
195 int line, int count, int dy);
196 static void fbcon_modechanged(struct fb_info *info);
197 static void fbcon_set_all_vcs(struct fb_info *info);
198 static void fbcon_start(void);
199 static void fbcon_exit(void);
200 static struct class_device *fbcon_class_device;
204 * On the Macintoy, there may or may not be a working VBL int. We need to probe
206 static int vbl_detected;
208 static irqreturn_t fb_vbl_detect(int irq, void *dummy)
215 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
216 static inline void fbcon_set_rotation(struct fb_info *info)
218 struct fbcon_ops *ops = info->fbcon_par;
220 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
221 ops->p->con_rotate < 4)
222 ops->rotate = ops->p->con_rotate;
227 static void fbcon_rotate(struct fb_info *info, u32 rotate)
229 struct fbcon_ops *ops= info->fbcon_par;
230 struct fb_info *fb_info;
232 if (!ops || ops->currcon == -1)
235 fb_info = registered_fb[con2fb_map[ops->currcon]];
237 if (info == fb_info) {
238 struct display *p = &fb_display[ops->currcon];
241 p->con_rotate = rotate;
245 fbcon_modechanged(info);
249 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
251 struct fbcon_ops *ops = info->fbcon_par;
256 if (!ops || ops->currcon < 0 || rotate > 3)
259 for (i = first_fb_vc; i <= last_fb_vc; i++) {
261 if (!vc || vc->vc_mode != KD_TEXT ||
262 registered_fb[con2fb_map[i]] != info)
265 p = &fb_display[vc->vc_num];
266 p->con_rotate = rotate;
269 fbcon_set_all_vcs(info);
272 static inline void fbcon_set_rotation(struct fb_info *info)
274 struct fbcon_ops *ops = info->fbcon_par;
276 ops->rotate = FB_ROTATE_UR;
279 static void fbcon_rotate(struct fb_info *info, u32 rotate)
284 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
288 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
290 static int fbcon_get_rotate(struct fb_info *info)
292 struct fbcon_ops *ops = info->fbcon_par;
294 return (ops) ? ops->rotate : 0;
297 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
299 struct fbcon_ops *ops = info->fbcon_par;
301 return (info->state != FBINFO_STATE_RUNNING ||
302 vc->vc_mode != KD_TEXT || ops->graphics);
305 static inline int get_color(struct vc_data *vc, struct fb_info *info,
308 int depth = fb_get_color_depth(&info->var, &info->fix);
311 if (console_blanked) {
312 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
314 c = vc->vc_video_erase_char & charmask;
318 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
319 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
324 int col = ~(0xfff << (max(info->var.green.length,
325 max(info->var.red.length,
326 info->var.blue.length)))) & 0xff;
329 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
330 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
335 color = (is_fg) ? fg : bg;
340 * Scale down 16-colors to 4 colors. Default 4-color palette
341 * is grayscale. However, simply dividing the values by 4
342 * will not work, as colors 1, 2 and 3 will be scaled-down
343 * to zero rendering them invisible. So empirically convert
344 * colors to a sane 4-level grayscale.
348 color = 0; /* black */
351 color = 2; /* white */
354 color = 1; /* gray */
357 color = 3; /* intense white */
363 * Last 8 entries of default 16-color palette is a more intense
364 * version of the first 8 (i.e., same chrominance, different
375 static void fbcon_update_softback(struct vc_data *vc)
377 int l = fbcon_softback_size / vc->vc_size_row;
380 softback_end = softback_buf + l * vc->vc_size_row;
382 /* Smaller scrollback makes no sense, and 0 would screw
383 the operation totally */
387 static void fb_flashcursor(struct work_struct *work)
389 struct fb_info *info = container_of(work, struct fb_info, queue);
390 struct fbcon_ops *ops = info->fbcon_par;
392 struct vc_data *vc = NULL;
396 acquire_console_sem();
397 if (ops && ops->currcon != -1)
398 vc = vc_cons[ops->currcon].d;
400 if (!vc || !CON_IS_VISIBLE(vc) ||
401 registered_fb[con2fb_map[vc->vc_num]] != info ||
403 release_console_sem();
407 p = &fb_display[vc->vc_num];
408 c = scr_readw((u16 *) vc->vc_pos);
409 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
411 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
412 get_color(vc, info, c, 0));
413 release_console_sem();
416 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
417 static int cursor_blink_rate;
418 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
420 struct fb_info *info = dev_id;
422 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
423 schedule_work(&info->queue);
424 vbl_cursor_cnt = cursor_blink_rate;
430 static void cursor_timer_handler(unsigned long dev_addr)
432 struct fb_info *info = (struct fb_info *) dev_addr;
433 struct fbcon_ops *ops = info->fbcon_par;
435 schedule_work(&info->queue);
436 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
439 static void fbcon_add_cursor_timer(struct fb_info *info)
441 struct fbcon_ops *ops = info->fbcon_par;
443 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
444 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
445 if (!info->queue.func)
446 INIT_WORK(&info->queue, fb_flashcursor);
448 init_timer(&ops->cursor_timer);
449 ops->cursor_timer.function = cursor_timer_handler;
450 ops->cursor_timer.expires = jiffies + HZ / 5;
451 ops->cursor_timer.data = (unsigned long ) info;
452 add_timer(&ops->cursor_timer);
453 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
457 static void fbcon_del_cursor_timer(struct fb_info *info)
459 struct fbcon_ops *ops = info->fbcon_par;
461 if (info->queue.func == fb_flashcursor &&
462 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
463 del_timer_sync(&ops->cursor_timer);
464 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
469 static int __init fb_console_setup(char *this_opt)
474 if (!this_opt || !*this_opt)
477 while ((options = strsep(&this_opt, ",")) != NULL) {
478 if (!strncmp(options, "font:", 5))
479 strcpy(fontname, options + 5);
481 if (!strncmp(options, "scrollback:", 11)) {
484 fbcon_softback_size = simple_strtoul(options, &options, 0);
485 if (*options == 'k' || *options == 'K') {
486 fbcon_softback_size *= 1024;
496 if (!strncmp(options, "map:", 4)) {
499 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
503 (options[j++]-'0') % FB_MAX;
508 if (!strncmp(options, "vc:", 3)) {
511 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
514 if (*options++ == '-')
515 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
516 fbcon_is_default = 0;
519 if (!strncmp(options, "rotate:", 7)) {
522 rotate = simple_strtoul(options, &options, 0);
530 __setup("fbcon=", fb_console_setup);
533 static int search_fb_in_map(int idx)
537 for (i = first_fb_vc; i <= last_fb_vc; i++) {
538 if (con2fb_map[i] == idx)
544 static int search_for_mapped_con(void)
548 for (i = first_fb_vc; i <= last_fb_vc; i++) {
549 if (con2fb_map[i] != -1)
555 static int fbcon_takeover(int show_logo)
559 if (!num_registered_fb)
563 logo_shown = FBCON_LOGO_DONTSHOW;
565 for (i = first_fb_vc; i <= last_fb_vc; i++)
566 con2fb_map[i] = info_idx;
568 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
572 for (i = first_fb_vc; i <= last_fb_vc; i++) {
582 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
583 int cols, int rows, int new_cols, int new_rows)
585 logo_shown = FBCON_LOGO_DONTSHOW;
588 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
589 int cols, int rows, int new_cols, int new_rows)
591 /* Need to make room for the logo */
592 struct fbcon_ops *ops = info->fbcon_par;
593 int cnt, erase = vc->vc_video_erase_char, step;
594 unsigned short *save = NULL, *r, *q;
596 if (info->flags & FBINFO_MODULE) {
597 logo_shown = FBCON_LOGO_DONTSHOW;
602 * remove underline attribute from erase character
603 * if black and white framebuffer.
605 if (fb_get_color_depth(&info->var, &info->fix) == 1)
607 logo_height = fb_prepare_logo(info, ops->rotate);
608 logo_lines = (logo_height + vc->vc_font.height - 1) /
610 q = (unsigned short *) (vc->vc_origin +
611 vc->vc_size_row * rows);
612 step = logo_lines * cols;
613 for (r = q - logo_lines * cols; r < q; r++)
614 if (scr_readw(r) != vc->vc_video_erase_char)
616 if (r != q && new_rows >= rows + logo_lines) {
617 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
619 int i = cols < new_cols ? cols : new_cols;
620 scr_memsetw(save, erase, logo_lines * new_cols * 2);
622 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
623 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
628 /* We can scroll screen down */
630 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
631 scr_memcpyw(r + step, r, vc->vc_size_row);
636 if (vc->vc_y + logo_lines >= rows)
637 lines = rows - vc->vc_y - 1;
641 vc->vc_pos += lines * vc->vc_size_row;
644 scr_memsetw((unsigned short *) vc->vc_origin,
646 vc->vc_size_row * logo_lines);
648 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
649 fbcon_clear_margins(vc, 0);
654 q = (unsigned short *) (vc->vc_origin +
657 scr_memcpyw(q, save, logo_lines * new_cols * 2);
658 vc->vc_y += logo_lines;
659 vc->vc_pos += logo_lines * vc->vc_size_row;
663 if (logo_lines > vc->vc_bottom) {
664 logo_shown = FBCON_LOGO_CANSHOW;
666 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
667 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
668 logo_shown = FBCON_LOGO_DRAW;
669 vc->vc_top = logo_lines;
674 #ifdef CONFIG_FB_TILEBLITTING
675 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
677 struct fbcon_ops *ops = info->fbcon_par;
679 ops->p = &fb_display[vc->vc_num];
681 if ((info->flags & FBINFO_MISC_TILEBLITTING))
682 fbcon_set_tileops(vc, info);
684 fbcon_set_rotation(info);
685 fbcon_set_bitops(ops);
689 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
693 if (info->flags & FBINFO_MISC_TILEBLITTING &&
694 info->tileops->fb_get_tilemax(info) < charcount)
700 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
702 struct fbcon_ops *ops = info->fbcon_par;
704 info->flags &= ~FBINFO_MISC_TILEBLITTING;
705 ops->p = &fb_display[vc->vc_num];
706 fbcon_set_rotation(info);
707 fbcon_set_bitops(ops);
710 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
715 #endif /* CONFIG_MISC_TILEBLITTING */
718 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
719 int unit, int oldidx)
721 struct fbcon_ops *ops = NULL;
724 if (!try_module_get(info->fbops->owner))
727 if (!err && info->fbops->fb_open &&
728 info->fbops->fb_open(info, 0))
732 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
738 info->fbcon_par = ops;
739 set_blitting_type(vc, info);
743 con2fb_map[unit] = oldidx;
744 module_put(info->fbops->owner);
750 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
751 struct fb_info *newinfo, int unit,
752 int oldidx, int found)
754 struct fbcon_ops *ops = oldinfo->fbcon_par;
757 if (oldinfo->fbops->fb_release &&
758 oldinfo->fbops->fb_release(oldinfo, 0)) {
759 con2fb_map[unit] = oldidx;
760 if (!found && newinfo->fbops->fb_release)
761 newinfo->fbops->fb_release(newinfo, 0);
763 module_put(newinfo->fbops->owner);
768 fbcon_del_cursor_timer(oldinfo);
769 kfree(ops->cursor_state.mask);
770 kfree(ops->cursor_data);
771 kfree(ops->fontbuffer);
772 kfree(oldinfo->fbcon_par);
773 oldinfo->fbcon_par = NULL;
774 module_put(oldinfo->fbops->owner);
776 If oldinfo and newinfo are driving the same hardware,
777 the fb_release() method of oldinfo may attempt to
778 restore the hardware state. This will leave the
779 newinfo in an undefined state. Thus, a call to
780 fb_set_par() may be needed for the newinfo.
782 if (newinfo->fbops->fb_set_par)
783 newinfo->fbops->fb_set_par(newinfo);
789 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
790 int unit, int show_logo)
792 struct fbcon_ops *ops = info->fbcon_par;
794 ops->currcon = fg_console;
796 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
797 info->fbops->fb_set_par(info);
799 ops->flags |= FBCON_FLAGS_INIT;
803 fbcon_set_disp(info, &info->var, vc);
805 fbcon_preset_disp(info, &info->var, unit);
808 struct vc_data *fg_vc = vc_cons[fg_console].d;
809 struct fb_info *fg_info =
810 registered_fb[con2fb_map[fg_console]];
812 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
813 fg_vc->vc_rows, fg_vc->vc_cols,
817 update_screen(vc_cons[fg_console].d);
821 * set_con2fb_map - map console to frame buffer device
822 * @unit: virtual console number to map
823 * @newidx: frame buffer index to map virtual console to
824 * @user: user request
826 * Maps a virtual console @unit to a frame buffer device
829 static int set_con2fb_map(int unit, int newidx, int user)
831 struct vc_data *vc = vc_cons[unit].d;
832 int oldidx = con2fb_map[unit];
833 struct fb_info *info = registered_fb[newidx];
834 struct fb_info *oldinfo = NULL;
837 if (oldidx == newidx)
840 if (!info || fbcon_has_exited)
843 if (!err && !search_for_mapped_con()) {
845 return fbcon_takeover(0);
849 oldinfo = registered_fb[oldidx];
851 found = search_fb_in_map(newidx);
853 acquire_console_sem();
854 con2fb_map[unit] = newidx;
856 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
860 * If old fb is not mapped to any of the consoles,
861 * fbcon should release it.
863 if (!err && oldinfo && !search_fb_in_map(oldidx))
864 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
868 int show_logo = (fg_console == 0 && !user &&
869 logo_shown != FBCON_LOGO_DONTSHOW);
872 fbcon_add_cursor_timer(info);
873 con2fb_map_boot[unit] = newidx;
874 con2fb_init_display(vc, info, unit, show_logo);
877 if (!search_fb_in_map(info_idx))
880 release_console_sem();
885 * Low Level Operations
887 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
888 static int var_to_display(struct display *disp,
889 struct fb_var_screeninfo *var,
890 struct fb_info *info)
892 disp->xres_virtual = var->xres_virtual;
893 disp->yres_virtual = var->yres_virtual;
894 disp->bits_per_pixel = var->bits_per_pixel;
895 disp->grayscale = var->grayscale;
896 disp->nonstd = var->nonstd;
897 disp->accel_flags = var->accel_flags;
898 disp->height = var->height;
899 disp->width = var->width;
900 disp->red = var->red;
901 disp->green = var->green;
902 disp->blue = var->blue;
903 disp->transp = var->transp;
904 disp->rotate = var->rotate;
905 disp->mode = fb_match_mode(var, &info->modelist);
906 if (disp->mode == NULL)
907 /* This should not happen */
912 static void display_to_var(struct fb_var_screeninfo *var,
913 struct display *disp)
915 fb_videomode_to_var(var, disp->mode);
916 var->xres_virtual = disp->xres_virtual;
917 var->yres_virtual = disp->yres_virtual;
918 var->bits_per_pixel = disp->bits_per_pixel;
919 var->grayscale = disp->grayscale;
920 var->nonstd = disp->nonstd;
921 var->accel_flags = disp->accel_flags;
922 var->height = disp->height;
923 var->width = disp->width;
924 var->red = disp->red;
925 var->green = disp->green;
926 var->blue = disp->blue;
927 var->transp = disp->transp;
928 var->rotate = disp->rotate;
931 static const char *fbcon_startup(void)
933 const char *display_desc = "frame buffer device";
934 struct display *p = &fb_display[fg_console];
935 struct vc_data *vc = vc_cons[fg_console].d;
936 const struct font_desc *font = NULL;
937 struct module *owner;
938 struct fb_info *info = NULL;
939 struct fbcon_ops *ops;
945 * If num_registered_fb is zero, this is a call for the dummy part.
946 * The frame buffer devices weren't initialized yet.
948 if (!num_registered_fb || info_idx == -1)
951 * Instead of blindly using registered_fb[0], we use info_idx, set by
954 info = registered_fb[info_idx];
958 owner = info->fbops->owner;
959 if (!try_module_get(owner))
961 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
966 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
974 ops->cur_rotate = -1;
975 info->fbcon_par = ops;
976 p->con_rotate = rotate;
977 set_blitting_type(vc, info);
979 if (info->fix.type != FB_TYPE_TEXT) {
980 if (fbcon_softback_size) {
984 kmalloc(fbcon_softback_size,
987 fbcon_softback_size = 0;
993 kfree((void *) softback_buf);
999 softback_in = softback_top = softback_curr =
1004 /* Setup default font */
1006 if (!fontname[0] || !(font = find_font(fontname)))
1007 font = get_default_font(info->var.xres,
1009 info->pixmap.blit_x,
1010 info->pixmap.blit_y);
1011 vc->vc_font.width = font->width;
1012 vc->vc_font.height = font->height;
1013 vc->vc_font.data = (void *)(p->fontdata = font->data);
1014 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1017 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1018 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1019 cols /= vc->vc_font.width;
1020 rows /= vc->vc_font.height;
1021 vc_resize(vc, cols, rows);
1023 DPRINTK("mode: %s\n", info->fix.id);
1024 DPRINTK("visual: %d\n", info->fix.visual);
1025 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1027 info->var.bits_per_pixel);
1030 if (MACH_IS_ATARI) {
1031 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1033 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1034 IRQ_TYPE_PRIO, "framebuffer vbl",
1037 #endif /* CONFIG_ATARI */
1041 * On a Macintoy, the VBL interrupt may or may not be active.
1042 * As interrupt based cursor is more reliable and race free, we
1043 * probe for VBL interrupts.
1048 * Probe for VBL: set temp. handler ...
1050 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1051 "framebuffer vbl", info);
1055 * ... and spin for 20 ms ...
1057 while (!vbl_detected && ++ct < 1000)
1062 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1064 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1068 * interrupt based cursor ok
1070 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1072 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1073 "framebuffer vbl", info);
1076 * VBL not detected: fall through, use timer based cursor
1081 #endif /* CONFIG_MAC */
1083 fbcon_add_cursor_timer(info);
1084 fbcon_has_exited = 0;
1085 return display_desc;
1088 static void fbcon_init(struct vc_data *vc, int init)
1090 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1091 struct fbcon_ops *ops;
1092 struct vc_data **default_mode = vc->vc_display_fg;
1093 struct vc_data *svc = *default_mode;
1094 struct display *t, *p = &fb_display[vc->vc_num];
1095 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1098 if (info_idx == -1 || info == NULL)
1103 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1104 (info->fix.type == FB_TYPE_TEXT))
1107 if (var_to_display(p, &info->var, info))
1110 /* If we are not the first console on this
1111 fb, copy the font from that console */
1112 t = &fb_display[fg_console];
1115 struct vc_data *fvc = vc_cons[fg_console].d;
1117 vc->vc_font.data = (void *)(p->fontdata =
1119 vc->vc_font.width = fvc->vc_font.width;
1120 vc->vc_font.height = fvc->vc_font.height;
1121 p->userfont = t->userfont;
1124 REFCOUNT(p->fontdata)++;
1126 const struct font_desc *font = NULL;
1128 if (!fontname[0] || !(font = find_font(fontname)))
1129 font = get_default_font(info->var.xres,
1131 info->pixmap.blit_x,
1132 info->pixmap.blit_y);
1133 vc->vc_font.width = font->width;
1134 vc->vc_font.height = font->height;
1135 vc->vc_font.data = (void *)(p->fontdata = font->data);
1136 vc->vc_font.charcount = 256; /* FIXME Need to
1137 support more fonts */
1142 charcnt = FNTCHARCNT(p->fontdata);
1144 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1145 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1146 if (charcnt == 256) {
1147 vc->vc_hi_font_mask = 0;
1149 vc->vc_hi_font_mask = 0x100;
1150 if (vc->vc_can_do_color)
1151 vc->vc_complement_mask <<= 1;
1154 if (!*svc->vc_uni_pagedir_loc)
1155 con_set_default_unimap(svc);
1156 if (!*vc->vc_uni_pagedir_loc)
1157 con_copy_unimap(vc, svc);
1159 ops = info->fbcon_par;
1160 p->con_rotate = rotate;
1161 set_blitting_type(vc, info);
1165 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1166 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1167 new_cols /= vc->vc_font.width;
1168 new_rows /= vc->vc_font.height;
1169 vc_resize(vc, new_cols, new_rows);
1172 * We must always set the mode. The mode of the previous console
1173 * driver could be in the same resolution but we are using different
1174 * hardware so we have to initialize the hardware.
1176 * We need to do it in fbcon_init() to prevent screen corruption.
1178 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1179 if (info->fbops->fb_set_par &&
1180 !(ops->flags & FBCON_FLAGS_INIT))
1181 info->fbops->fb_set_par(info);
1182 ops->flags |= FBCON_FLAGS_INIT;
1187 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1188 !(cap & FBINFO_HWACCEL_DISABLED))
1189 p->scrollmode = SCROLL_MOVE;
1190 else /* default to something safe */
1191 p->scrollmode = SCROLL_REDRAW;
1194 * ++guenther: console.c:vc_allocate() relies on initializing
1195 * vc_{cols,rows}, but we must not set those if we are only
1196 * resizing the console.
1199 vc->vc_cols = new_cols;
1200 vc->vc_rows = new_rows;
1204 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1206 if (vc == svc && softback_buf)
1207 fbcon_update_softback(vc);
1209 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1210 ops->rotate = FB_ROTATE_UR;
1211 set_blitting_type(vc, info);
1214 ops->p = &fb_display[fg_console];
1217 static void fbcon_free_font(struct display *p)
1219 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1220 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1225 static void fbcon_deinit(struct vc_data *vc)
1227 struct display *p = &fb_display[vc->vc_num];
1228 struct fb_info *info;
1229 struct fbcon_ops *ops;
1233 idx = con2fb_map[vc->vc_num];
1238 info = registered_fb[idx];
1243 ops = info->fbcon_par;
1248 if (CON_IS_VISIBLE(vc))
1249 fbcon_del_cursor_timer(info);
1251 ops->flags &= ~FBCON_FLAGS_INIT;
1254 if (!con_is_bound(&fb_con))
1260 /* ====================================================================== */
1262 /* fbcon_XXX routines - interface used by the world
1264 * This system is now divided into two levels because of complications
1265 * caused by hardware scrolling. Top level functions:
1267 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1269 * handles y values in range [0, scr_height-1] that correspond to real
1270 * screen positions. y_wrap shift means that first line of bitmap may be
1271 * anywhere on this display. These functions convert lineoffsets to
1272 * bitmap offsets and deal with the wrap-around case by splitting blits.
1274 * fbcon_bmove_physical_8() -- These functions fast implementations
1275 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1276 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1280 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1281 * Implies should only really hardware scroll in rows. Only reason for
1282 * restriction is simplicity & efficiency at the moment.
1285 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1288 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1289 struct fbcon_ops *ops = info->fbcon_par;
1291 struct display *p = &fb_display[vc->vc_num];
1294 if (fbcon_is_inactive(vc, info))
1297 if (!height || !width)
1300 /* Split blits that cross physical y_wrap boundary */
1302 y_break = p->vrows - p->yscroll;
1303 if (sy < y_break && sy + height - 1 >= y_break) {
1304 u_int b = y_break - sy;
1305 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1306 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1309 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1312 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1313 int count, int ypos, int xpos)
1315 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1316 struct display *p = &fb_display[vc->vc_num];
1317 struct fbcon_ops *ops = info->fbcon_par;
1319 if (!fbcon_is_inactive(vc, info))
1320 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1321 get_color(vc, info, scr_readw(s), 1),
1322 get_color(vc, info, scr_readw(s), 0));
1325 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1329 scr_writew(c, &chr);
1330 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1333 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1335 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1336 struct fbcon_ops *ops = info->fbcon_par;
1338 if (!fbcon_is_inactive(vc, info))
1339 ops->clear_margins(vc, info, bottom_only);
1342 static void fbcon_cursor(struct vc_data *vc, int mode)
1344 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1345 struct fbcon_ops *ops = info->fbcon_par;
1347 int c = scr_readw((u16 *) vc->vc_pos);
1349 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1352 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1353 if (mode & CM_SOFTBACK) {
1354 mode &= ~CM_SOFTBACK;
1358 fbcon_set_origin(vc);
1362 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1363 get_color(vc, info, c, 0));
1364 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1367 static int scrollback_phys_max = 0;
1368 static int scrollback_max = 0;
1369 static int scrollback_current = 0;
1372 * If no vc is existent yet, just set struct display
1374 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1377 struct display *p = &fb_display[unit];
1378 struct display *t = &fb_display[fg_console];
1380 if (var_to_display(p, var, info))
1383 p->fontdata = t->fontdata;
1384 p->userfont = t->userfont;
1386 REFCOUNT(p->fontdata)++;
1389 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1392 struct display *p = &fb_display[vc->vc_num], *t;
1393 struct vc_data **default_mode = vc->vc_display_fg;
1394 struct vc_data *svc = *default_mode;
1395 struct fbcon_ops *ops = info->fbcon_par;
1396 int rows, cols, charcnt = 256;
1398 if (var_to_display(p, var, info))
1400 t = &fb_display[svc->vc_num];
1401 if (!vc->vc_font.data) {
1402 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1403 vc->vc_font.width = (*default_mode)->vc_font.width;
1404 vc->vc_font.height = (*default_mode)->vc_font.height;
1405 p->userfont = t->userfont;
1407 REFCOUNT(p->fontdata)++;
1410 charcnt = FNTCHARCNT(p->fontdata);
1412 var->activate = FB_ACTIVATE_NOW;
1413 info->var.activate = var->activate;
1414 var->yoffset = info->var.yoffset;
1415 var->xoffset = info->var.xoffset;
1416 fb_set_var(info, var);
1417 ops->var = info->var;
1418 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1419 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1420 if (charcnt == 256) {
1421 vc->vc_hi_font_mask = 0;
1423 vc->vc_hi_font_mask = 0x100;
1424 if (vc->vc_can_do_color)
1425 vc->vc_complement_mask <<= 1;
1428 if (!*svc->vc_uni_pagedir_loc)
1429 con_set_default_unimap(svc);
1430 if (!*vc->vc_uni_pagedir_loc)
1431 con_copy_unimap(vc, svc);
1433 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1434 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1435 cols /= vc->vc_font.width;
1436 rows /= vc->vc_font.height;
1437 vc_resize(vc, cols, rows);
1439 if (CON_IS_VISIBLE(vc)) {
1442 fbcon_update_softback(vc);
1446 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1448 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1449 struct fbcon_ops *ops = info->fbcon_par;
1450 struct display *p = &fb_display[vc->vc_num];
1452 p->yscroll += count;
1453 if (p->yscroll >= p->vrows) /* Deal with wrap */
1454 p->yscroll -= p->vrows;
1455 ops->var.xoffset = 0;
1456 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1457 ops->var.vmode |= FB_VMODE_YWRAP;
1458 ops->update_start(info);
1459 scrollback_max += count;
1460 if (scrollback_max > scrollback_phys_max)
1461 scrollback_max = scrollback_phys_max;
1462 scrollback_current = 0;
1465 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1467 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1468 struct fbcon_ops *ops = info->fbcon_par;
1469 struct display *p = &fb_display[vc->vc_num];
1471 p->yscroll -= count;
1472 if (p->yscroll < 0) /* Deal with wrap */
1473 p->yscroll += p->vrows;
1474 ops->var.xoffset = 0;
1475 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1476 ops->var.vmode |= FB_VMODE_YWRAP;
1477 ops->update_start(info);
1478 scrollback_max -= count;
1479 if (scrollback_max < 0)
1481 scrollback_current = 0;
1484 static __inline__ void ypan_up(struct vc_data *vc, int count)
1486 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1487 struct display *p = &fb_display[vc->vc_num];
1488 struct fbcon_ops *ops = info->fbcon_par;
1490 p->yscroll += count;
1491 if (p->yscroll > p->vrows - vc->vc_rows) {
1492 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1493 0, 0, 0, vc->vc_rows, vc->vc_cols);
1494 p->yscroll -= p->vrows - vc->vc_rows;
1497 ops->var.xoffset = 0;
1498 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1499 ops->var.vmode &= ~FB_VMODE_YWRAP;
1500 ops->update_start(info);
1501 fbcon_clear_margins(vc, 1);
1502 scrollback_max += count;
1503 if (scrollback_max > scrollback_phys_max)
1504 scrollback_max = scrollback_phys_max;
1505 scrollback_current = 0;
1508 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1510 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1511 struct fbcon_ops *ops = info->fbcon_par;
1512 struct display *p = &fb_display[vc->vc_num];
1514 p->yscroll += count;
1516 if (p->yscroll > p->vrows - vc->vc_rows) {
1517 p->yscroll -= p->vrows - vc->vc_rows;
1518 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1521 ops->var.xoffset = 0;
1522 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1523 ops->var.vmode &= ~FB_VMODE_YWRAP;
1524 ops->update_start(info);
1525 fbcon_clear_margins(vc, 1);
1526 scrollback_max += count;
1527 if (scrollback_max > scrollback_phys_max)
1528 scrollback_max = scrollback_phys_max;
1529 scrollback_current = 0;
1532 static __inline__ void ypan_down(struct vc_data *vc, int count)
1534 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1535 struct display *p = &fb_display[vc->vc_num];
1536 struct fbcon_ops *ops = info->fbcon_par;
1538 p->yscroll -= count;
1539 if (p->yscroll < 0) {
1540 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1541 0, vc->vc_rows, vc->vc_cols);
1542 p->yscroll += p->vrows - vc->vc_rows;
1545 ops->var.xoffset = 0;
1546 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1547 ops->var.vmode &= ~FB_VMODE_YWRAP;
1548 ops->update_start(info);
1549 fbcon_clear_margins(vc, 1);
1550 scrollback_max -= count;
1551 if (scrollback_max < 0)
1553 scrollback_current = 0;
1556 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1558 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1559 struct fbcon_ops *ops = info->fbcon_par;
1560 struct display *p = &fb_display[vc->vc_num];
1562 p->yscroll -= count;
1564 if (p->yscroll < 0) {
1565 p->yscroll += p->vrows - vc->vc_rows;
1566 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1569 ops->var.xoffset = 0;
1570 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1571 ops->var.vmode &= ~FB_VMODE_YWRAP;
1572 ops->update_start(info);
1573 fbcon_clear_margins(vc, 1);
1574 scrollback_max -= count;
1575 if (scrollback_max < 0)
1577 scrollback_current = 0;
1580 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1583 int count = vc->vc_rows;
1584 unsigned short *d, *s;
1588 d = (u16 *) softback_curr;
1589 if (d == (u16 *) softback_in)
1590 d = (u16 *) vc->vc_origin;
1591 n = softback_curr + delta * vc->vc_size_row;
1592 softback_lines -= delta;
1594 if (softback_curr < softback_top && n < softback_buf) {
1595 n += softback_end - softback_buf;
1596 if (n < softback_top) {
1598 (softback_top - n) / vc->vc_size_row;
1601 } else if (softback_curr >= softback_top
1602 && n < softback_top) {
1604 (softback_top - n) / vc->vc_size_row;
1608 if (softback_curr > softback_in && n >= softback_end) {
1609 n += softback_buf - softback_end;
1610 if (n > softback_in) {
1614 } else if (softback_curr <= softback_in && n > softback_in) {
1619 if (n == softback_curr)
1622 s = (u16 *) softback_curr;
1623 if (s == (u16 *) softback_in)
1624 s = (u16 *) vc->vc_origin;
1626 unsigned short *start;
1630 unsigned short attr = 1;
1633 le = advance_row(s, 1);
1636 if (attr != (c & 0xff00)) {
1639 fbcon_putcs(vc, start, s - start,
1645 if (c == scr_readw(d)) {
1647 fbcon_putcs(vc, start, s - start,
1660 fbcon_putcs(vc, start, s - start, line, x);
1662 if (d == (u16 *) softback_end)
1663 d = (u16 *) softback_buf;
1664 if (d == (u16 *) softback_in)
1665 d = (u16 *) vc->vc_origin;
1666 if (s == (u16 *) softback_end)
1667 s = (u16 *) softback_buf;
1668 if (s == (u16 *) softback_in)
1669 s = (u16 *) vc->vc_origin;
1673 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1674 int line, int count, int dy)
1676 unsigned short *s = (unsigned short *)
1677 (vc->vc_origin + vc->vc_size_row * line);
1680 unsigned short *start = s;
1681 unsigned short *le = advance_row(s, 1);
1684 unsigned short attr = 1;
1688 if (attr != (c & 0xff00)) {
1691 fbcon_putcs(vc, start, s - start,
1697 console_conditional_schedule();
1701 fbcon_putcs(vc, start, s - start, dy, x);
1702 console_conditional_schedule();
1707 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1708 int line, int count, int offset)
1710 unsigned short *d = (unsigned short *)
1711 (vc->vc_origin + vc->vc_size_row * line);
1712 unsigned short *s = d + offset;
1715 unsigned short *start = s;
1716 unsigned short *le = advance_row(s, 1);
1719 unsigned short attr = 1;
1723 if (attr != (c & 0xff00)) {
1726 fbcon_putcs(vc, start, s - start,
1732 if (c == scr_readw(d)) {
1734 fbcon_putcs(vc, start, s - start,
1744 console_conditional_schedule();
1749 fbcon_putcs(vc, start, s - start, line, x);
1750 console_conditional_schedule();
1755 /* NOTE: We subtract two lines from these pointers */
1756 s -= vc->vc_size_row;
1757 d -= vc->vc_size_row;
1762 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1767 if (vc->vc_num != fg_console)
1769 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1772 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1774 p = advance_row(p, 1);
1775 softback_in += vc->vc_size_row;
1776 if (softback_in == softback_end)
1777 softback_in = softback_buf;
1778 if (softback_in == softback_top) {
1779 softback_top += vc->vc_size_row;
1780 if (softback_top == softback_end)
1781 softback_top = softback_buf;
1784 softback_curr = softback_in;
1787 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1790 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1791 struct display *p = &fb_display[vc->vc_num];
1792 struct fbcon_ops *ops = info->fbcon_par;
1793 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1795 if (fbcon_is_inactive(vc, info))
1798 fbcon_cursor(vc, CM_ERASE);
1801 * ++Geert: Only use ywrap/ypan if the console is in text mode
1802 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1803 * whole screen (prevents flicker).
1808 if (count > vc->vc_rows) /* Maximum realistic size */
1809 count = vc->vc_rows;
1811 fbcon_softback_note(vc, t, count);
1812 if (logo_shown >= 0)
1814 switch (p->scrollmode) {
1816 ops->bmove(vc, info, t + count, 0, t, 0,
1817 b - t - count, vc->vc_cols);
1818 ops->clear(vc, info, b - count, 0, count,
1822 case SCROLL_WRAP_MOVE:
1823 if (b - t - count > 3 * vc->vc_rows >> 2) {
1825 fbcon_bmove(vc, 0, 0, count, 0, t,
1827 ywrap_up(vc, count);
1828 if (vc->vc_rows - b > 0)
1829 fbcon_bmove(vc, b - count, 0, b, 0,
1832 } else if (info->flags & FBINFO_READS_FAST)
1833 fbcon_bmove(vc, t + count, 0, t, 0,
1834 b - t - count, vc->vc_cols);
1837 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1840 case SCROLL_PAN_REDRAW:
1841 if ((p->yscroll + count <=
1842 2 * (p->vrows - vc->vc_rows))
1843 && ((!scroll_partial && (b - t == vc->vc_rows))
1846 3 * vc->vc_rows >> 2)))) {
1848 fbcon_redraw_move(vc, p, 0, t, count);
1849 ypan_up_redraw(vc, t, count);
1850 if (vc->vc_rows - b > 0)
1851 fbcon_redraw_move(vc, p, b,
1852 vc->vc_rows - b, b);
1854 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1855 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1858 case SCROLL_PAN_MOVE:
1859 if ((p->yscroll + count <=
1860 2 * (p->vrows - vc->vc_rows))
1861 && ((!scroll_partial && (b - t == vc->vc_rows))
1864 3 * vc->vc_rows >> 2)))) {
1866 fbcon_bmove(vc, 0, 0, count, 0, t,
1869 if (vc->vc_rows - b > 0)
1870 fbcon_bmove(vc, b - count, 0, b, 0,
1873 } else if (info->flags & FBINFO_READS_FAST)
1874 fbcon_bmove(vc, t + count, 0, t, 0,
1875 b - t - count, vc->vc_cols);
1878 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1883 fbcon_redraw(vc, p, t, b - t - count,
1884 count * vc->vc_cols);
1885 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1886 scr_memsetw((unsigned short *) (vc->vc_origin +
1889 vc->vc_video_erase_char,
1890 vc->vc_size_row * count);
1896 if (count > vc->vc_rows) /* Maximum realistic size */
1897 count = vc->vc_rows;
1898 if (logo_shown >= 0)
1900 switch (p->scrollmode) {
1902 ops->bmove(vc, info, t, 0, t + count, 0,
1903 b - t - count, vc->vc_cols);
1904 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1907 case SCROLL_WRAP_MOVE:
1908 if (b - t - count > 3 * vc->vc_rows >> 2) {
1909 if (vc->vc_rows - b > 0)
1910 fbcon_bmove(vc, b, 0, b - count, 0,
1913 ywrap_down(vc, count);
1915 fbcon_bmove(vc, count, 0, 0, 0, t,
1917 } else if (info->flags & FBINFO_READS_FAST)
1918 fbcon_bmove(vc, t, 0, t + count, 0,
1919 b - t - count, vc->vc_cols);
1922 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1925 case SCROLL_PAN_MOVE:
1926 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1927 && ((!scroll_partial && (b - t == vc->vc_rows))
1930 3 * vc->vc_rows >> 2)))) {
1931 if (vc->vc_rows - b > 0)
1932 fbcon_bmove(vc, b, 0, b - count, 0,
1935 ypan_down(vc, count);
1937 fbcon_bmove(vc, count, 0, 0, 0, t,
1939 } else if (info->flags & FBINFO_READS_FAST)
1940 fbcon_bmove(vc, t, 0, t + count, 0,
1941 b - t - count, vc->vc_cols);
1944 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1947 case SCROLL_PAN_REDRAW:
1948 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1949 && ((!scroll_partial && (b - t == vc->vc_rows))
1952 3 * vc->vc_rows >> 2)))) {
1953 if (vc->vc_rows - b > 0)
1954 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1956 ypan_down_redraw(vc, t, count);
1958 fbcon_redraw_move(vc, p, count, t, 0);
1960 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1961 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1966 fbcon_redraw(vc, p, b - 1, b - t - count,
1967 -count * vc->vc_cols);
1968 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1969 scr_memsetw((unsigned short *) (vc->vc_origin +
1972 vc->vc_video_erase_char,
1973 vc->vc_size_row * count);
1981 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1982 int height, int width)
1984 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1985 struct display *p = &fb_display[vc->vc_num];
1987 if (fbcon_is_inactive(vc, info))
1990 if (!width || !height)
1993 /* Split blits that cross physical y_wrap case.
1994 * Pathological case involves 4 blits, better to use recursive
1995 * code rather than unrolled case
1997 * Recursive invocations don't need to erase the cursor over and
1998 * over again, so we use fbcon_bmove_rec()
2000 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2001 p->vrows - p->yscroll);
2004 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2005 int dy, int dx, int height, int width, u_int y_break)
2007 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2008 struct fbcon_ops *ops = info->fbcon_par;
2011 if (sy < y_break && sy + height > y_break) {
2013 if (dy < sy) { /* Avoid trashing self */
2014 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2016 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2017 height - b, width, y_break);
2019 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2020 height - b, width, y_break);
2021 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2027 if (dy < y_break && dy + height > y_break) {
2029 if (dy < sy) { /* Avoid trashing self */
2030 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2032 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2033 height - b, width, y_break);
2035 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2036 height - b, width, y_break);
2037 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2042 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2046 static __inline__ void updatescrollmode(struct display *p,
2047 struct fb_info *info,
2050 struct fbcon_ops *ops = info->fbcon_par;
2051 int fh = vc->vc_font.height;
2052 int cap = info->flags;
2054 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2055 info->fix.xpanstep);
2056 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2057 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2058 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2059 info->var.xres_virtual);
2060 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2061 divides(ypan, vc->vc_font.height) && vyres > yres;
2062 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2063 divides(ywrap, vc->vc_font.height) &&
2064 divides(vc->vc_font.height, vyres) &&
2065 divides(vc->vc_font.height, yres);
2066 int reading_fast = cap & FBINFO_READS_FAST;
2067 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2068 !(cap & FBINFO_HWACCEL_DISABLED);
2069 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2070 !(cap & FBINFO_HWACCEL_DISABLED);
2072 p->vrows = vyres/fh;
2073 if (yres > (fh * (vc->vc_rows + 1)))
2074 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2075 if ((yres % fh) && (vyres % fh < yres % fh))
2078 if (good_wrap || good_pan) {
2079 if (reading_fast || fast_copyarea)
2080 p->scrollmode = good_wrap ?
2081 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2083 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2086 if (reading_fast || (fast_copyarea && !fast_imageblit))
2087 p->scrollmode = SCROLL_MOVE;
2089 p->scrollmode = SCROLL_REDRAW;
2093 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2094 unsigned int height)
2096 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2097 struct fbcon_ops *ops = info->fbcon_par;
2098 struct display *p = &fb_display[vc->vc_num];
2099 struct fb_var_screeninfo var = info->var;
2100 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2102 virt_w = FBCON_SWAP(ops->rotate, width, height);
2103 virt_h = FBCON_SWAP(ops->rotate, height, width);
2104 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2105 vc->vc_font.height);
2106 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2108 var.xres = virt_w * virt_fw;
2109 var.yres = virt_h * virt_fh;
2110 x_diff = info->var.xres - var.xres;
2111 y_diff = info->var.yres - var.yres;
2112 if (x_diff < 0 || x_diff > virt_fw ||
2113 y_diff < 0 || y_diff > virt_fh) {
2114 const struct fb_videomode *mode;
2116 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2117 mode = fb_find_best_mode(&var, &info->modelist);
2120 display_to_var(&var, p);
2121 fb_videomode_to_var(&var, mode);
2123 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2126 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2127 if (CON_IS_VISIBLE(vc)) {
2128 var.activate = FB_ACTIVATE_NOW |
2130 fb_set_var(info, &var);
2132 var_to_display(p, &info->var, info);
2133 ops->var = info->var;
2135 updatescrollmode(p, info, vc);
2139 static int fbcon_switch(struct vc_data *vc)
2141 struct fb_info *info, *old_info = NULL;
2142 struct fbcon_ops *ops;
2143 struct display *p = &fb_display[vc->vc_num];
2144 struct fb_var_screeninfo var;
2145 int i, prev_console, charcnt = 256;
2147 info = registered_fb[con2fb_map[vc->vc_num]];
2148 ops = info->fbcon_par;
2152 fbcon_set_origin(vc);
2153 softback_top = softback_curr = softback_in = softback_buf;
2155 fbcon_update_softback(vc);
2158 if (logo_shown >= 0) {
2159 struct vc_data *conp2 = vc_cons[logo_shown].d;
2161 if (conp2->vc_top == logo_lines
2162 && conp2->vc_bottom == conp2->vc_rows)
2164 logo_shown = FBCON_LOGO_CANSHOW;
2167 prev_console = ops->currcon;
2168 if (prev_console != -1)
2169 old_info = registered_fb[con2fb_map[prev_console]];
2171 * FIXME: If we have multiple fbdev's loaded, we need to
2172 * update all info->currcon. Perhaps, we can place this
2173 * in a centralized structure, but this might break some
2176 * info->currcon = vc->vc_num;
2178 for (i = 0; i < FB_MAX; i++) {
2179 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2180 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2182 o->currcon = vc->vc_num;
2185 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2186 display_to_var(&var, p);
2187 var.activate = FB_ACTIVATE_NOW;
2190 * make sure we don't unnecessarily trip the memcmp()
2193 info->var.activate = var.activate;
2194 var.yoffset = info->var.yoffset;
2195 var.xoffset = info->var.xoffset;
2196 var.vmode = info->var.vmode;
2197 fb_set_var(info, &var);
2198 ops->var = info->var;
2200 if (old_info != NULL && (old_info != info ||
2201 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2202 if (info->fbops->fb_set_par)
2203 info->fbops->fb_set_par(info);
2205 if (old_info != info)
2206 fbcon_del_cursor_timer(old_info);
2209 if (fbcon_is_inactive(vc, info) ||
2210 ops->blank_state != FB_BLANK_UNBLANK)
2211 fbcon_del_cursor_timer(info);
2213 fbcon_add_cursor_timer(info);
2215 set_blitting_type(vc, info);
2216 ops->cursor_reset = 1;
2218 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2219 ops->rotate = FB_ROTATE_UR;
2220 set_blitting_type(vc, info);
2223 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2224 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2227 charcnt = FNTCHARCNT(vc->vc_font.data);
2230 vc->vc_complement_mask <<= 1;
2232 updatescrollmode(p, info, vc);
2234 switch (p->scrollmode) {
2235 case SCROLL_WRAP_MOVE:
2236 scrollback_phys_max = p->vrows - vc->vc_rows;
2238 case SCROLL_PAN_MOVE:
2239 case SCROLL_PAN_REDRAW:
2240 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2241 if (scrollback_phys_max < 0)
2242 scrollback_phys_max = 0;
2245 scrollback_phys_max = 0;
2250 scrollback_current = 0;
2252 if (!fbcon_is_inactive(vc, info)) {
2253 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2254 ops->update_start(info);
2257 fbcon_set_palette(vc, color_table);
2258 fbcon_clear_margins(vc, 0);
2260 if (logo_shown == FBCON_LOGO_DRAW) {
2262 logo_shown = fg_console;
2263 /* This is protected above by initmem_freed */
2264 fb_show_logo(info, ops->rotate);
2266 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2267 vc->vc_size_row * (vc->vc_bottom -
2274 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2277 struct fb_event event;
2280 unsigned short charmask = vc->vc_hi_font_mask ?
2282 unsigned short oldc;
2284 oldc = vc->vc_video_erase_char;
2285 vc->vc_video_erase_char &= charmask;
2286 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2287 vc->vc_video_erase_char = oldc;
2292 event.data = ␣
2293 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2296 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2299 struct fbcon_ops *ops = info->fbcon_par;
2302 struct fb_var_screeninfo var = info->var;
2307 if (info->fbops->fb_save_state)
2308 info->fbops->fb_save_state(info);
2309 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2310 fb_set_var(info, &var);
2312 ops->var = info->var;
2313 } else if (info->fbops->fb_restore_state)
2314 info->fbops->fb_restore_state(info);
2317 if (!fbcon_is_inactive(vc, info)) {
2318 if (ops->blank_state != blank) {
2319 ops->blank_state = blank;
2320 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2321 ops->cursor_flash = (!blank);
2323 if (fb_blank(info, blank))
2324 fbcon_generic_blank(vc, info, blank);
2331 if (fbcon_is_inactive(vc, info) ||
2332 ops->blank_state != FB_BLANK_UNBLANK)
2333 fbcon_del_cursor_timer(info);
2335 fbcon_add_cursor_timer(info);
2340 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2342 u8 *fontdata = vc->vc_font.data;
2343 u8 *data = font->data;
2346 font->width = vc->vc_font.width;
2347 font->height = vc->vc_font.height;
2348 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2352 if (font->width <= 8) {
2353 j = vc->vc_font.height;
2354 for (i = 0; i < font->charcount; i++) {
2355 memcpy(data, fontdata, j);
2356 memset(data + j, 0, 32 - j);
2360 } else if (font->width <= 16) {
2361 j = vc->vc_font.height * 2;
2362 for (i = 0; i < font->charcount; i++) {
2363 memcpy(data, fontdata, j);
2364 memset(data + j, 0, 64 - j);
2368 } else if (font->width <= 24) {
2369 for (i = 0; i < font->charcount; i++) {
2370 for (j = 0; j < vc->vc_font.height; j++) {
2371 *data++ = fontdata[0];
2372 *data++ = fontdata[1];
2373 *data++ = fontdata[2];
2374 fontdata += sizeof(u32);
2376 memset(data, 0, 3 * (32 - j));
2377 data += 3 * (32 - j);
2380 j = vc->vc_font.height * 4;
2381 for (i = 0; i < font->charcount; i++) {
2382 memcpy(data, fontdata, j);
2383 memset(data + j, 0, 128 - j);
2391 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2392 const u8 * data, int userfont)
2394 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2395 struct fbcon_ops *ops = info->fbcon_par;
2396 struct display *p = &fb_display[vc->vc_num];
2399 char *old_data = NULL;
2401 if (CON_IS_VISIBLE(vc) && softback_lines)
2402 fbcon_set_origin(vc);
2404 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2406 old_data = vc->vc_font.data;
2408 cnt = FNTCHARCNT(data);
2411 vc->vc_font.data = (void *)(p->fontdata = data);
2412 if ((p->userfont = userfont))
2414 vc->vc_font.width = w;
2415 vc->vc_font.height = h;
2416 if (vc->vc_hi_font_mask && cnt == 256) {
2417 vc->vc_hi_font_mask = 0;
2418 if (vc->vc_can_do_color) {
2419 vc->vc_complement_mask >>= 1;
2420 vc->vc_s_complement_mask >>= 1;
2423 /* ++Edmund: reorder the attribute bits */
2424 if (vc->vc_can_do_color) {
2425 unsigned short *cp =
2426 (unsigned short *) vc->vc_origin;
2427 int count = vc->vc_screenbuf_size / 2;
2429 for (; count > 0; count--, cp++) {
2431 scr_writew(((c & 0xfe00) >> 1) |
2434 c = vc->vc_video_erase_char;
2435 vc->vc_video_erase_char =
2436 ((c & 0xfe00) >> 1) | (c & 0xff);
2439 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2440 vc->vc_hi_font_mask = 0x100;
2441 if (vc->vc_can_do_color) {
2442 vc->vc_complement_mask <<= 1;
2443 vc->vc_s_complement_mask <<= 1;
2446 /* ++Edmund: reorder the attribute bits */
2448 unsigned short *cp =
2449 (unsigned short *) vc->vc_origin;
2450 int count = vc->vc_screenbuf_size / 2;
2452 for (; count > 0; count--, cp++) {
2453 unsigned short newc;
2455 if (vc->vc_can_do_color)
2457 ((c & 0xff00) << 1) | (c &
2461 scr_writew(newc, cp);
2463 c = vc->vc_video_erase_char;
2464 if (vc->vc_can_do_color) {
2465 vc->vc_video_erase_char =
2466 ((c & 0xff00) << 1) | (c & 0xff);
2469 vc->vc_video_erase_char = c & ~0x100;
2477 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2478 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2481 vc_resize(vc, cols, rows);
2482 if (CON_IS_VISIBLE(vc) && softback_buf)
2483 fbcon_update_softback(vc);
2484 } else if (CON_IS_VISIBLE(vc)
2485 && vc->vc_mode == KD_TEXT) {
2486 fbcon_clear_margins(vc, 0);
2490 if (old_data && (--REFCOUNT(old_data) == 0))
2491 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2495 static int fbcon_copy_font(struct vc_data *vc, int con)
2497 struct display *od = &fb_display[con];
2498 struct console_font *f = &vc->vc_font;
2500 if (od->fontdata == f->data)
2501 return 0; /* already the same font... */
2502 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2506 * User asked to set font; we are guaranteed that
2507 * a) width and height are in range 1..32
2508 * b) charcount does not exceed 512
2509 * but lets not assume that, since someone might someday want to use larger
2510 * fonts. And charcount of 512 is small for unicode support.
2512 * However, user space gives the font in 32 rows , regardless of
2513 * actual font height. So a new API is needed if support for larger fonts
2514 * is ever implemented.
2517 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2519 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2520 unsigned charcount = font->charcount;
2521 int w = font->width;
2522 int h = font->height;
2525 u8 *new_data, *data = font->data;
2526 int pitch = (font->width+7) >> 3;
2528 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2529 * If not this check should be changed to charcount < 256 */
2530 if (charcount != 256 && charcount != 512)
2533 /* Make sure drawing engine can handle the font */
2534 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2535 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2538 /* Make sure driver can handle the font length */
2539 if (fbcon_invalid_charcount(info, charcount))
2542 size = h * pitch * charcount;
2544 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2549 new_data += FONT_EXTRA_WORDS * sizeof(int);
2550 FNTSIZE(new_data) = size;
2551 FNTCHARCNT(new_data) = charcount;
2552 REFCOUNT(new_data) = 0; /* usage counter */
2553 for (i=0; i< charcount; i++) {
2554 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2557 /* Since linux has a nice crc32 function use it for counting font
2559 csum = crc32(0, new_data, size);
2561 FNTSUM(new_data) = csum;
2562 /* Check if the same font is on some other console already */
2563 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2564 struct vc_data *tmp = vc_cons[i].d;
2566 if (fb_display[i].userfont &&
2567 fb_display[i].fontdata &&
2568 FNTSUM(fb_display[i].fontdata) == csum &&
2569 FNTSIZE(fb_display[i].fontdata) == size &&
2570 tmp->vc_font.width == w &&
2571 !memcmp(fb_display[i].fontdata, new_data, size)) {
2572 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2573 new_data = (u8 *)fb_display[i].fontdata;
2577 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2580 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2582 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2583 const struct font_desc *f;
2586 f = get_default_font(info->var.xres, info->var.yres,
2587 info->pixmap.blit_x, info->pixmap.blit_y);
2588 else if (!(f = find_font(name)))
2591 font->width = f->width;
2592 font->height = f->height;
2593 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2596 static u16 palette_red[16];
2597 static u16 palette_green[16];
2598 static u16 palette_blue[16];
2600 static struct fb_cmap palette_cmap = {
2601 0, 16, palette_red, palette_green, palette_blue, NULL
2604 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2606 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2610 if (fbcon_is_inactive(vc, info))
2613 if (!CON_IS_VISIBLE(vc))
2616 depth = fb_get_color_depth(&info->var, &info->fix);
2618 for (i = j = 0; i < 16; i++) {
2620 val = vc->vc_palette[j++];
2621 palette_red[k] = (val << 8) | val;
2622 val = vc->vc_palette[j++];
2623 palette_green[k] = (val << 8) | val;
2624 val = vc->vc_palette[j++];
2625 palette_blue[k] = (val << 8) | val;
2627 palette_cmap.len = 16;
2628 palette_cmap.start = 0;
2630 * If framebuffer is capable of less than 16 colors,
2631 * use default palette of fbcon.
2634 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2636 return fb_set_cmap(&palette_cmap, info);
2639 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2644 if (vc->vc_num != fg_console || !softback_lines)
2645 return (u16 *) (vc->vc_origin + offset);
2646 line = offset / vc->vc_size_row;
2647 if (line >= softback_lines)
2648 return (u16 *) (vc->vc_origin + offset -
2649 softback_lines * vc->vc_size_row);
2650 p = softback_curr + offset;
2651 if (p >= softback_end)
2652 p += softback_buf - softback_end;
2656 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2662 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2663 unsigned long offset = (pos - vc->vc_origin) / 2;
2665 x = offset % vc->vc_cols;
2666 y = offset / vc->vc_cols;
2667 if (vc->vc_num == fg_console)
2668 y += softback_lines;
2669 ret = pos + (vc->vc_cols - x) * 2;
2670 } else if (vc->vc_num == fg_console && softback_lines) {
2671 unsigned long offset = pos - softback_curr;
2673 if (pos < softback_curr)
2674 offset += softback_end - softback_buf;
2676 x = offset % vc->vc_cols;
2677 y = offset / vc->vc_cols;
2678 ret = pos + (vc->vc_cols - x) * 2;
2679 if (ret == softback_end)
2681 if (ret == softback_in)
2682 ret = vc->vc_origin;
2684 /* Should not happen */
2686 ret = vc->vc_origin;
2695 /* As we might be inside of softback, we may work with non-contiguous buffer,
2696 that's why we have to use a separate routine. */
2697 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2700 u16 a = scr_readw(p);
2701 if (!vc->vc_can_do_color)
2703 else if (vc->vc_hi_font_mask == 0x100)
2704 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2705 (((a) & 0x0e00) << 4);
2707 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2708 (((a) & 0x0700) << 4);
2710 if (p == (u16 *) softback_end)
2711 p = (u16 *) softback_buf;
2712 if (p == (u16 *) softback_in)
2713 p = (u16 *) vc->vc_origin;
2717 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2719 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2720 struct fbcon_ops *ops = info->fbcon_par;
2721 struct display *p = &fb_display[fg_console];
2722 int offset, limit, scrollback_old;
2725 if (vc->vc_num != fg_console)
2727 if (vc->vc_mode != KD_TEXT || !lines)
2729 if (logo_shown >= 0) {
2730 struct vc_data *conp2 = vc_cons[logo_shown].d;
2732 if (conp2->vc_top == logo_lines
2733 && conp2->vc_bottom == conp2->vc_rows)
2735 if (logo_shown == vc->vc_num) {
2741 logo_lines * vc->vc_size_row;
2742 for (i = 0; i < logo_lines; i++) {
2743 if (p == softback_top)
2745 if (p == softback_buf)
2747 p -= vc->vc_size_row;
2748 q -= vc->vc_size_row;
2749 scr_memcpyw((u16 *) q, (u16 *) p,
2752 softback_in = softback_curr = p;
2753 update_region(vc, vc->vc_origin,
2754 logo_lines * vc->vc_cols);
2756 logo_shown = FBCON_LOGO_CANSHOW;
2758 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2759 fbcon_redraw_softback(vc, p, lines);
2760 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2764 if (!scrollback_phys_max)
2767 scrollback_old = scrollback_current;
2768 scrollback_current -= lines;
2769 if (scrollback_current < 0)
2770 scrollback_current = 0;
2771 else if (scrollback_current > scrollback_max)
2772 scrollback_current = scrollback_max;
2773 if (scrollback_current == scrollback_old)
2776 if (fbcon_is_inactive(vc, info))
2779 fbcon_cursor(vc, CM_ERASE);
2781 offset = p->yscroll - scrollback_current;
2783 switch (p->scrollmode) {
2784 case SCROLL_WRAP_MOVE:
2785 info->var.vmode |= FB_VMODE_YWRAP;
2787 case SCROLL_PAN_MOVE:
2788 case SCROLL_PAN_REDRAW:
2789 limit -= vc->vc_rows;
2790 info->var.vmode &= ~FB_VMODE_YWRAP;
2795 else if (offset >= limit)
2798 ops->var.xoffset = 0;
2799 ops->var.yoffset = offset * vc->vc_font.height;
2800 ops->update_start(info);
2802 if (!scrollback_current)
2803 fbcon_cursor(vc, CM_DRAW);
2807 static int fbcon_set_origin(struct vc_data *vc)
2810 fbcon_scrolldelta(vc, softback_lines);
2814 static void fbcon_suspended(struct fb_info *info)
2816 struct vc_data *vc = NULL;
2817 struct fbcon_ops *ops = info->fbcon_par;
2819 if (!ops || ops->currcon < 0)
2821 vc = vc_cons[ops->currcon].d;
2823 /* Clear cursor, restore saved data */
2824 fbcon_cursor(vc, CM_ERASE);
2827 static void fbcon_resumed(struct fb_info *info)
2830 struct fbcon_ops *ops = info->fbcon_par;
2832 if (!ops || ops->currcon < 0)
2834 vc = vc_cons[ops->currcon].d;
2839 static void fbcon_modechanged(struct fb_info *info)
2841 struct fbcon_ops *ops = info->fbcon_par;
2846 if (!ops || ops->currcon < 0)
2848 vc = vc_cons[ops->currcon].d;
2849 if (vc->vc_mode != KD_TEXT ||
2850 registered_fb[con2fb_map[ops->currcon]] != info)
2853 p = &fb_display[vc->vc_num];
2854 set_blitting_type(vc, info);
2856 if (CON_IS_VISIBLE(vc)) {
2857 var_to_display(p, &info->var, info);
2858 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2859 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2860 cols /= vc->vc_font.width;
2861 rows /= vc->vc_font.height;
2862 vc_resize(vc, cols, rows);
2863 updatescrollmode(p, info, vc);
2865 scrollback_current = 0;
2867 if (!fbcon_is_inactive(vc, info)) {
2868 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2869 ops->update_start(info);
2872 fbcon_set_palette(vc, color_table);
2875 fbcon_update_softback(vc);
2879 static void fbcon_set_all_vcs(struct fb_info *info)
2881 struct fbcon_ops *ops = info->fbcon_par;
2884 int i, rows, cols, fg = -1;
2886 if (!ops || ops->currcon < 0)
2889 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2891 if (!vc || vc->vc_mode != KD_TEXT ||
2892 registered_fb[con2fb_map[i]] != info)
2895 if (CON_IS_VISIBLE(vc)) {
2900 p = &fb_display[vc->vc_num];
2901 set_blitting_type(vc, info);
2902 var_to_display(p, &info->var, info);
2903 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2904 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
2905 cols /= vc->vc_font.width;
2906 rows /= vc->vc_font.height;
2907 vc_resize(vc, cols, rows);
2911 fbcon_modechanged(info);
2914 static int fbcon_mode_deleted(struct fb_info *info,
2915 struct fb_videomode *mode)
2917 struct fb_info *fb_info;
2919 int i, j, found = 0;
2921 /* before deletion, ensure that mode is not in use */
2922 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2926 fb_info = registered_fb[j];
2927 if (fb_info != info)
2932 if (fb_mode_is_equal(p->mode, mode)) {
2940 static int fbcon_fb_unregistered(int idx)
2944 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2945 if (con2fb_map[i] == idx)
2949 if (idx == info_idx) {
2952 for (i = 0; i < FB_MAX; i++) {
2953 if (registered_fb[i] != NULL) {
2960 if (info_idx != -1) {
2961 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2962 if (con2fb_map[i] == -1)
2963 con2fb_map[i] = info_idx;
2967 if (!num_registered_fb)
2968 unregister_con_driver(&fb_con);
2973 static int fbcon_fb_registered(int idx)
2977 if (info_idx == -1) {
2978 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2979 if (con2fb_map_boot[i] == idx) {
2986 ret = fbcon_takeover(1);
2988 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2989 if (con2fb_map_boot[i] == idx &&
2990 con2fb_map[i] == -1)
2991 set_con2fb_map(i, idx, 0);
2998 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3000 struct fbcon_ops *ops = info->fbcon_par;
3003 if (!ops || ops->currcon < 0)
3006 vc = vc_cons[ops->currcon].d;
3007 if (vc->vc_mode != KD_TEXT ||
3008 registered_fb[con2fb_map[ops->currcon]] != info)
3011 if (CON_IS_VISIBLE(vc)) {
3015 do_unblank_screen(0);
3017 ops->blank_state = blank;
3020 static void fbcon_new_modelist(struct fb_info *info)
3024 struct fb_var_screeninfo var;
3025 const struct fb_videomode *mode;
3027 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3028 if (registered_fb[con2fb_map[i]] != info)
3030 if (!fb_display[i].mode)
3033 display_to_var(&var, &fb_display[i]);
3034 mode = fb_find_nearest_mode(fb_display[i].mode,
3036 fb_videomode_to_var(&var, mode);
3039 fbcon_set_disp(info, &var, vc);
3041 fbcon_preset_disp(info, &var, i);
3046 static void fbcon_get_requirement(struct fb_info *info,
3047 struct fb_blit_caps *caps)
3055 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3057 if (vc && vc->vc_mode == KD_TEXT &&
3058 info->node == con2fb_map[i]) {
3060 caps->x |= 1 << (vc->vc_font.width - 1);
3061 caps->y |= 1 << (vc->vc_font.height - 1);
3062 charcnt = (p->userfont) ?
3063 FNTCHARCNT(p->fontdata) : 256;
3064 if (caps->len < charcnt)
3065 caps->len = charcnt;
3069 vc = vc_cons[fg_console].d;
3071 if (vc && vc->vc_mode == KD_TEXT &&
3072 info->node == con2fb_map[fg_console]) {
3073 p = &fb_display[fg_console];
3074 caps->x = 1 << (vc->vc_font.width - 1);
3075 caps->y = 1 << (vc->vc_font.height - 1);
3076 caps->len = (p->userfont) ?
3077 FNTCHARCNT(p->fontdata) : 256;
3082 static int fbcon_event_notify(struct notifier_block *self,
3083 unsigned long action, void *data)
3085 struct fb_event *event = data;
3086 struct fb_info *info = event->info;
3087 struct fb_videomode *mode;
3088 struct fb_con2fbmap *con2fb;
3089 struct fb_blit_caps *caps;
3093 * ignore all events except driver registration and deregistration
3094 * if fbcon is not active
3096 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3097 action == FB_EVENT_FB_UNREGISTERED))
3101 case FB_EVENT_SUSPEND:
3102 fbcon_suspended(info);
3104 case FB_EVENT_RESUME:
3105 fbcon_resumed(info);
3107 case FB_EVENT_MODE_CHANGE:
3108 fbcon_modechanged(info);
3110 case FB_EVENT_MODE_CHANGE_ALL:
3111 fbcon_set_all_vcs(info);
3113 case FB_EVENT_MODE_DELETE:
3115 ret = fbcon_mode_deleted(info, mode);
3117 case FB_EVENT_FB_REGISTERED:
3118 ret = fbcon_fb_registered(info->node);
3120 case FB_EVENT_FB_UNREGISTERED:
3121 ret = fbcon_fb_unregistered(info->node);
3123 case FB_EVENT_SET_CONSOLE_MAP:
3124 con2fb = event->data;
3125 ret = set_con2fb_map(con2fb->console - 1,
3126 con2fb->framebuffer, 1);
3128 case FB_EVENT_GET_CONSOLE_MAP:
3129 con2fb = event->data;
3130 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3132 case FB_EVENT_BLANK:
3133 fbcon_fb_blanked(info, *(int *)event->data);
3135 case FB_EVENT_NEW_MODELIST:
3136 fbcon_new_modelist(info);
3138 case FB_EVENT_GET_REQ:
3140 fbcon_get_requirement(info, caps);
3149 * The console `switch' structure for the frame buffer based console
3152 static const struct consw fb_con = {
3153 .owner = THIS_MODULE,
3154 .con_startup = fbcon_startup,
3155 .con_init = fbcon_init,
3156 .con_deinit = fbcon_deinit,
3157 .con_clear = fbcon_clear,
3158 .con_putc = fbcon_putc,
3159 .con_putcs = fbcon_putcs,
3160 .con_cursor = fbcon_cursor,
3161 .con_scroll = fbcon_scroll,
3162 .con_bmove = fbcon_bmove,
3163 .con_switch = fbcon_switch,
3164 .con_blank = fbcon_blank,
3165 .con_font_set = fbcon_set_font,
3166 .con_font_get = fbcon_get_font,
3167 .con_font_default = fbcon_set_def_font,
3168 .con_font_copy = fbcon_copy_font,
3169 .con_set_palette = fbcon_set_palette,
3170 .con_scrolldelta = fbcon_scrolldelta,
3171 .con_set_origin = fbcon_set_origin,
3172 .con_invert_region = fbcon_invert_region,
3173 .con_screen_pos = fbcon_screen_pos,
3174 .con_getxy = fbcon_getxy,
3175 .con_resize = fbcon_resize,
3178 static struct notifier_block fbcon_event_notifier = {
3179 .notifier_call = fbcon_event_notify,
3182 static ssize_t store_rotate(struct class_device *class_device,
3183 const char *buf, size_t count)
3185 struct fb_info *info;
3189 if (fbcon_has_exited)
3192 acquire_console_sem();
3193 idx = con2fb_map[fg_console];
3195 if (idx == -1 || registered_fb[idx] == NULL)
3198 info = registered_fb[idx];
3199 rotate = simple_strtoul(buf, last, 0);
3200 fbcon_rotate(info, rotate);
3202 release_console_sem();
3206 static ssize_t store_rotate_all(struct class_device *class_device,
3207 const char *buf, size_t count)
3209 struct fb_info *info;
3213 if (fbcon_has_exited)
3216 acquire_console_sem();
3217 idx = con2fb_map[fg_console];
3219 if (idx == -1 || registered_fb[idx] == NULL)
3222 info = registered_fb[idx];
3223 rotate = simple_strtoul(buf, last, 0);
3224 fbcon_rotate_all(info, rotate);
3226 release_console_sem();
3230 static ssize_t show_rotate(struct class_device *class_device, char *buf)
3232 struct fb_info *info;
3233 int rotate = 0, idx;
3235 if (fbcon_has_exited)
3238 acquire_console_sem();
3239 idx = con2fb_map[fg_console];
3241 if (idx == -1 || registered_fb[idx] == NULL)
3244 info = registered_fb[idx];
3245 rotate = fbcon_get_rotate(info);
3247 release_console_sem();
3248 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3251 static struct class_device_attribute class_device_attrs[] = {
3252 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3253 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3256 static int fbcon_init_class_device(void)
3260 fbcon_has_sysfs = 1;
3262 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3263 error = class_device_create_file(fbcon_class_device,
3264 &class_device_attrs[i]);
3272 class_device_remove_file(fbcon_class_device,
3273 &class_device_attrs[i]);
3275 fbcon_has_sysfs = 0;
3281 static void fbcon_start(void)
3283 if (num_registered_fb) {
3286 acquire_console_sem();
3288 for (i = 0; i < FB_MAX; i++) {
3289 if (registered_fb[i] != NULL) {
3295 release_console_sem();
3300 static void fbcon_exit(void)
3302 struct fb_info *info;
3305 if (fbcon_has_exited)
3309 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3312 if (MACH_IS_MAC && vbl_detected)
3313 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
3316 kfree((void *)softback_buf);
3319 for (i = 0; i < FB_MAX; i++) {
3321 info = registered_fb[i];
3326 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3327 if (con2fb_map[j] == i)
3332 if (info->fbops->fb_release)
3333 info->fbops->fb_release(info, 0);
3334 module_put(info->fbops->owner);
3336 if (info->fbcon_par) {
3337 struct fbcon_ops *ops = info->fbcon_par;
3339 fbcon_del_cursor_timer(info);
3340 kfree(ops->cursor_src);
3341 kfree(info->fbcon_par);
3342 info->fbcon_par = NULL;
3345 if (info->queue.func == fb_flashcursor)
3346 info->queue.func = NULL;
3350 fbcon_has_exited = 1;
3353 static int __init fb_console_init(void)
3357 acquire_console_sem();
3358 fb_register_client(&fbcon_event_notifier);
3359 fbcon_class_device =
3360 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
3362 if (IS_ERR(fbcon_class_device)) {
3363 printk(KERN_WARNING "Unable to create class_device "
3364 "for fbcon; errno = %ld\n",
3365 PTR_ERR(fbcon_class_device));
3366 fbcon_class_device = NULL;
3368 fbcon_init_class_device();
3370 for (i = 0; i < MAX_NR_CONSOLES; i++)
3373 release_console_sem();
3378 module_init(fb_console_init);
3382 static void __exit fbcon_deinit_class_device(void)
3386 if (fbcon_has_sysfs) {
3387 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3388 class_device_remove_file(fbcon_class_device,
3389 &class_device_attrs[i]);
3391 fbcon_has_sysfs = 0;
3395 static void __exit fb_console_exit(void)
3397 acquire_console_sem();
3398 fb_unregister_client(&fbcon_event_notifier);
3399 fbcon_deinit_class_device();
3400 class_device_destroy(fb_class, MKDEV(0, 0));
3402 release_console_sem();
3403 unregister_con_driver(&fb_con);
3406 module_exit(fb_console_exit);
3410 MODULE_LICENSE("GPL");