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/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
96 static struct display fb_display[MAX_NR_CONSOLES];
98 static signed char con2fb_map[MAX_NR_CONSOLES];
99 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
101 static int logo_lines;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown = FBCON_LOGO_CANSHOW;
105 /* console mappings */
106 static int first_fb_vc;
107 static int last_fb_vc = MAX_NR_CONSOLES - 1;
108 static int fbcon_is_default = 1;
109 static int fbcon_has_exited;
110 static int primary_device = -1;
111 static int fbcon_has_console_bind;
113 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
114 static int map_override;
116 static inline void fbcon_map_override(void)
121 static inline void fbcon_map_override(void)
124 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
127 static char fontname[40];
129 /* current fb_info */
130 static int info_idx = -1;
132 /* console rotation */
133 static int initial_rotation = -1;
134 static int fbcon_has_sysfs;
135 static int margin_color;
137 static const struct consw fb_con;
139 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
141 static int fbcon_set_origin(struct vc_data *);
143 static int fbcon_cursor_noblink;
145 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
148 * Interface used by the world
151 static const char *fbcon_startup(void);
152 static void fbcon_init(struct vc_data *vc, int init);
153 static void fbcon_deinit(struct vc_data *vc);
154 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
156 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
157 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
158 int count, int ypos, int xpos);
159 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
160 static void fbcon_cursor(struct vc_data *vc, int mode);
161 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
162 int height, int width);
163 static int fbcon_switch(struct vc_data *vc);
164 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
165 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
170 static __inline__ void ywrap_up(struct vc_data *vc, int count);
171 static __inline__ void ywrap_down(struct vc_data *vc, int count);
172 static __inline__ void ypan_up(struct vc_data *vc, int count);
173 static __inline__ void ypan_down(struct vc_data *vc, int count);
174 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
175 int dy, int dx, int height, int width, u_int y_break);
176 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
178 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
179 int line, int count, int dy);
180 static void fbcon_modechanged(struct fb_info *info);
181 static void fbcon_set_all_vcs(struct fb_info *info);
182 static void fbcon_start(void);
183 static void fbcon_exit(void);
184 static struct device *fbcon_device;
186 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
187 static inline void fbcon_set_rotation(struct fb_info *info)
189 struct fbcon_ops *ops = info->fbcon_par;
191 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
192 ops->p->con_rotate < 4)
193 ops->rotate = ops->p->con_rotate;
198 static void fbcon_rotate(struct fb_info *info, u32 rotate)
200 struct fbcon_ops *ops= info->fbcon_par;
201 struct fb_info *fb_info;
203 if (!ops || ops->currcon == -1)
206 fb_info = registered_fb[con2fb_map[ops->currcon]];
208 if (info == fb_info) {
209 struct display *p = &fb_display[ops->currcon];
212 p->con_rotate = rotate;
216 fbcon_modechanged(info);
220 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
222 struct fbcon_ops *ops = info->fbcon_par;
227 if (!ops || ops->currcon < 0 || rotate > 3)
230 for (i = first_fb_vc; i <= last_fb_vc; i++) {
232 if (!vc || vc->vc_mode != KD_TEXT ||
233 registered_fb[con2fb_map[i]] != info)
236 p = &fb_display[vc->vc_num];
237 p->con_rotate = rotate;
240 fbcon_set_all_vcs(info);
243 static inline void fbcon_set_rotation(struct fb_info *info)
245 struct fbcon_ops *ops = info->fbcon_par;
247 ops->rotate = FB_ROTATE_UR;
250 static void fbcon_rotate(struct fb_info *info, u32 rotate)
255 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
259 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
261 static int fbcon_get_rotate(struct fb_info *info)
263 struct fbcon_ops *ops = info->fbcon_par;
265 return (ops) ? ops->rotate : 0;
268 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
270 struct fbcon_ops *ops = info->fbcon_par;
272 return (info->state != FBINFO_STATE_RUNNING ||
273 vc->vc_mode != KD_TEXT || ops->graphics) &&
274 !vt_force_oops_output(vc);
277 static int get_color(struct vc_data *vc, struct fb_info *info,
280 int depth = fb_get_color_depth(&info->var, &info->fix);
283 if (console_blanked) {
284 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
286 c = vc->vc_video_erase_char & charmask;
290 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
291 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
296 int col = mono_col(info);
298 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
299 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
304 color = (is_fg) ? fg : bg;
309 * Scale down 16-colors to 4 colors. Default 4-color palette
310 * is grayscale. However, simply dividing the values by 4
311 * will not work, as colors 1, 2 and 3 will be scaled-down
312 * to zero rendering them invisible. So empirically convert
313 * colors to a sane 4-level grayscale.
317 color = 0; /* black */
320 color = 2; /* white */
323 color = 1; /* gray */
326 color = 3; /* intense white */
332 * Last 8 entries of default 16-color palette is a more intense
333 * version of the first 8 (i.e., same chrominance, different
344 static void fb_flashcursor(struct work_struct *work)
346 struct fb_info *info = container_of(work, struct fb_info, queue);
347 struct fbcon_ops *ops = info->fbcon_par;
348 struct vc_data *vc = NULL;
353 /* FIXME: we should sort out the unbind locking instead */
354 /* instead we just fail to flash the cursor if we can't get
355 * the lock instead of blocking fbcon deinit */
356 ret = console_trylock();
360 if (ops && ops->currcon != -1)
361 vc = vc_cons[ops->currcon].d;
363 if (!vc || !con_is_visible(vc) ||
364 registered_fb[con2fb_map[vc->vc_num]] != info ||
370 c = scr_readw((u16 *) vc->vc_pos);
371 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
373 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
374 get_color(vc, info, c, 0));
378 static void cursor_timer_handler(unsigned long dev_addr)
380 struct fb_info *info = (struct fb_info *) dev_addr;
381 struct fbcon_ops *ops = info->fbcon_par;
383 queue_work(system_power_efficient_wq, &info->queue);
384 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
387 static void fbcon_add_cursor_timer(struct fb_info *info)
389 struct fbcon_ops *ops = info->fbcon_par;
391 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
392 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
393 !fbcon_cursor_noblink) {
394 if (!info->queue.func)
395 INIT_WORK(&info->queue, fb_flashcursor);
397 setup_timer(&ops->cursor_timer, cursor_timer_handler,
398 (unsigned long) info);
399 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
400 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
404 static void fbcon_del_cursor_timer(struct fb_info *info)
406 struct fbcon_ops *ops = info->fbcon_par;
408 if (info->queue.func == fb_flashcursor &&
409 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
410 del_timer_sync(&ops->cursor_timer);
411 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
416 static int __init fb_console_setup(char *this_opt)
421 if (!this_opt || !*this_opt)
424 while ((options = strsep(&this_opt, ",")) != NULL) {
425 if (!strncmp(options, "font:", 5)) {
426 strlcpy(fontname, options + 5, sizeof(fontname));
430 if (!strncmp(options, "scrollback:", 11)) {
431 pr_warn("Ignoring scrollback size option\n");
435 if (!strncmp(options, "map:", 4)) {
438 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
442 (options[j++]-'0') % FB_MAX;
445 fbcon_map_override();
450 if (!strncmp(options, "vc:", 3)) {
453 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
456 if (*options++ == '-')
457 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
458 fbcon_is_default = 0;
462 if (!strncmp(options, "rotate:", 7)) {
465 initial_rotation = simple_strtoul(options, &options, 0);
466 if (initial_rotation > 3)
467 initial_rotation = 0;
471 if (!strncmp(options, "margin:", 7)) {
474 margin_color = simple_strtoul(options, &options, 0);
481 __setup("fbcon=", fb_console_setup);
484 static int search_fb_in_map(int idx)
488 for (i = first_fb_vc; i <= last_fb_vc; i++) {
489 if (con2fb_map[i] == idx)
495 static int search_for_mapped_con(void)
499 for (i = first_fb_vc; i <= last_fb_vc; i++) {
500 if (con2fb_map[i] != -1)
506 static int do_fbcon_takeover(int show_logo)
510 if (!num_registered_fb)
514 logo_shown = FBCON_LOGO_DONTSHOW;
516 for (i = first_fb_vc; i <= last_fb_vc; i++)
517 con2fb_map[i] = info_idx;
519 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
523 for (i = first_fb_vc; i <= last_fb_vc; i++)
527 fbcon_has_console_bind = 1;
534 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
535 int cols, int rows, int new_cols, int new_rows)
537 logo_shown = FBCON_LOGO_DONTSHOW;
540 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
541 int cols, int rows, int new_cols, int new_rows)
543 /* Need to make room for the logo */
544 struct fbcon_ops *ops = info->fbcon_par;
545 int cnt, erase = vc->vc_video_erase_char, step;
546 unsigned short *save = NULL, *r, *q;
549 if (info->fbops->owner) {
550 logo_shown = FBCON_LOGO_DONTSHOW;
555 * remove underline attribute from erase character
556 * if black and white framebuffer.
558 if (fb_get_color_depth(&info->var, &info->fix) == 1)
560 logo_height = fb_prepare_logo(info, ops->rotate);
561 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
562 q = (unsigned short *) (vc->vc_origin +
563 vc->vc_size_row * rows);
564 step = logo_lines * cols;
565 for (r = q - logo_lines * cols; r < q; r++)
566 if (scr_readw(r) != vc->vc_video_erase_char)
568 if (r != q && new_rows >= rows + logo_lines) {
569 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
571 int i = cols < new_cols ? cols : new_cols;
572 scr_memsetw(save, erase, logo_lines * new_cols * 2);
574 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
575 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
580 /* We can scroll screen down */
582 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
583 scr_memcpyw(r + step, r, vc->vc_size_row);
588 if (vc->vc_y + logo_lines >= rows)
589 lines = rows - vc->vc_y - 1;
593 vc->vc_pos += lines * vc->vc_size_row;
596 scr_memsetw((unsigned short *) vc->vc_origin,
598 vc->vc_size_row * logo_lines);
600 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
601 fbcon_clear_margins(vc, 0);
606 q = (unsigned short *) (vc->vc_origin +
609 scr_memcpyw(q, save, logo_lines * new_cols * 2);
610 vc->vc_y += logo_lines;
611 vc->vc_pos += logo_lines * vc->vc_size_row;
615 if (logo_lines > vc->vc_bottom) {
616 logo_shown = FBCON_LOGO_CANSHOW;
618 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
619 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
620 logo_shown = FBCON_LOGO_DRAW;
621 vc->vc_top = logo_lines;
626 #ifdef CONFIG_FB_TILEBLITTING
627 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
629 struct fbcon_ops *ops = info->fbcon_par;
631 ops->p = &fb_display[vc->vc_num];
633 if ((info->flags & FBINFO_MISC_TILEBLITTING))
634 fbcon_set_tileops(vc, info);
636 fbcon_set_rotation(info);
637 fbcon_set_bitops(ops);
641 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
645 if (info->flags & FBINFO_MISC_TILEBLITTING &&
646 info->tileops->fb_get_tilemax(info) < charcount)
652 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
654 struct fbcon_ops *ops = info->fbcon_par;
656 info->flags &= ~FBINFO_MISC_TILEBLITTING;
657 ops->p = &fb_display[vc->vc_num];
658 fbcon_set_rotation(info);
659 fbcon_set_bitops(ops);
662 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
667 #endif /* CONFIG_MISC_TILEBLITTING */
670 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
671 int unit, int oldidx)
673 struct fbcon_ops *ops = NULL;
676 if (!try_module_get(info->fbops->owner))
679 if (!err && info->fbops->fb_open &&
680 info->fbops->fb_open(info, 0))
684 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
690 ops->cur_blink_jiffies = HZ / 5;
691 info->fbcon_par = ops;
694 set_blitting_type(vc, info);
698 con2fb_map[unit] = oldidx;
699 module_put(info->fbops->owner);
705 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
706 struct fb_info *newinfo, int unit,
707 int oldidx, int found)
709 struct fbcon_ops *ops = oldinfo->fbcon_par;
712 if (oldinfo->fbops->fb_release &&
713 oldinfo->fbops->fb_release(oldinfo, 0)) {
714 con2fb_map[unit] = oldidx;
715 if (!found && newinfo->fbops->fb_release)
716 newinfo->fbops->fb_release(newinfo, 0);
718 module_put(newinfo->fbops->owner);
723 fbcon_del_cursor_timer(oldinfo);
724 kfree(ops->cursor_state.mask);
725 kfree(ops->cursor_data);
726 kfree(ops->cursor_src);
727 kfree(ops->fontbuffer);
728 kfree(oldinfo->fbcon_par);
729 oldinfo->fbcon_par = NULL;
730 module_put(oldinfo->fbops->owner);
732 If oldinfo and newinfo are driving the same hardware,
733 the fb_release() method of oldinfo may attempt to
734 restore the hardware state. This will leave the
735 newinfo in an undefined state. Thus, a call to
736 fb_set_par() may be needed for the newinfo.
738 if (newinfo && newinfo->fbops->fb_set_par) {
739 ret = newinfo->fbops->fb_set_par(newinfo);
742 printk(KERN_ERR "con2fb_release_oldinfo: "
743 "detected unhandled fb_set_par error, "
744 "error code %d\n", ret);
751 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
752 int unit, int show_logo)
754 struct fbcon_ops *ops = info->fbcon_par;
757 ops->currcon = fg_console;
759 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
760 ret = info->fbops->fb_set_par(info);
763 printk(KERN_ERR "con2fb_init_display: detected "
764 "unhandled fb_set_par error, "
765 "error code %d\n", ret);
768 ops->flags |= FBCON_FLAGS_INIT;
770 fbcon_set_disp(info, &info->var, unit);
773 struct vc_data *fg_vc = vc_cons[fg_console].d;
774 struct fb_info *fg_info =
775 registered_fb[con2fb_map[fg_console]];
777 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
778 fg_vc->vc_rows, fg_vc->vc_cols,
782 update_screen(vc_cons[fg_console].d);
786 * set_con2fb_map - map console to frame buffer device
787 * @unit: virtual console number to map
788 * @newidx: frame buffer index to map virtual console to
789 * @user: user request
791 * Maps a virtual console @unit to a frame buffer device
794 * This should be called with the console lock held.
796 static int set_con2fb_map(int unit, int newidx, int user)
798 struct vc_data *vc = vc_cons[unit].d;
799 int oldidx = con2fb_map[unit];
800 struct fb_info *info = registered_fb[newidx];
801 struct fb_info *oldinfo = NULL;
804 if (oldidx == newidx)
810 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
812 return do_fbcon_takeover(0);
816 oldinfo = registered_fb[oldidx];
818 found = search_fb_in_map(newidx);
820 con2fb_map[unit] = newidx;
822 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
826 * If old fb is not mapped to any of the consoles,
827 * fbcon should release it.
829 if (!err && oldinfo && !search_fb_in_map(oldidx))
830 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
834 int show_logo = (fg_console == 0 && !user &&
835 logo_shown != FBCON_LOGO_DONTSHOW);
838 fbcon_add_cursor_timer(info);
839 con2fb_map_boot[unit] = newidx;
840 con2fb_init_display(vc, info, unit, show_logo);
843 if (!search_fb_in_map(info_idx))
850 * Low Level Operations
852 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
853 static int var_to_display(struct display *disp,
854 struct fb_var_screeninfo *var,
855 struct fb_info *info)
857 disp->xres_virtual = var->xres_virtual;
858 disp->yres_virtual = var->yres_virtual;
859 disp->bits_per_pixel = var->bits_per_pixel;
860 disp->grayscale = var->grayscale;
861 disp->nonstd = var->nonstd;
862 disp->accel_flags = var->accel_flags;
863 disp->height = var->height;
864 disp->width = var->width;
865 disp->red = var->red;
866 disp->green = var->green;
867 disp->blue = var->blue;
868 disp->transp = var->transp;
869 disp->rotate = var->rotate;
870 disp->mode = fb_match_mode(var, &info->modelist);
871 if (disp->mode == NULL)
872 /* This should not happen */
877 static void display_to_var(struct fb_var_screeninfo *var,
878 struct display *disp)
880 fb_videomode_to_var(var, disp->mode);
881 var->xres_virtual = disp->xres_virtual;
882 var->yres_virtual = disp->yres_virtual;
883 var->bits_per_pixel = disp->bits_per_pixel;
884 var->grayscale = disp->grayscale;
885 var->nonstd = disp->nonstd;
886 var->accel_flags = disp->accel_flags;
887 var->height = disp->height;
888 var->width = disp->width;
889 var->red = disp->red;
890 var->green = disp->green;
891 var->blue = disp->blue;
892 var->transp = disp->transp;
893 var->rotate = disp->rotate;
896 static const char *fbcon_startup(void)
898 const char *display_desc = "frame buffer device";
899 struct display *p = &fb_display[fg_console];
900 struct vc_data *vc = vc_cons[fg_console].d;
901 const struct font_desc *font = NULL;
902 struct module *owner;
903 struct fb_info *info = NULL;
904 struct fbcon_ops *ops;
908 * If num_registered_fb is zero, this is a call for the dummy part.
909 * The frame buffer devices weren't initialized yet.
911 if (!num_registered_fb || info_idx == -1)
914 * Instead of blindly using registered_fb[0], we use info_idx, set by
917 info = registered_fb[info_idx];
921 owner = info->fbops->owner;
922 if (!try_module_get(owner))
924 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
929 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
937 ops->cur_rotate = -1;
938 ops->cur_blink_jiffies = HZ / 5;
939 info->fbcon_par = ops;
940 if (initial_rotation != -1)
941 p->con_rotate = initial_rotation;
943 p->con_rotate = fbcon_platform_get_rotate(info);
944 set_blitting_type(vc, info);
946 /* Setup default font */
947 if (!p->fontdata && !vc->vc_font.data) {
948 if (!fontname[0] || !(font = find_font(fontname)))
949 font = get_default_font(info->var.xres,
952 info->pixmap.blit_y);
953 vc->vc_font.width = font->width;
954 vc->vc_font.height = font->height;
955 vc->vc_font.data = (void *)(p->fontdata = font->data);
956 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
958 p->fontdata = vc->vc_font.data;
961 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
962 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
963 cols /= vc->vc_font.width;
964 rows /= vc->vc_font.height;
965 vc_resize(vc, cols, rows);
967 DPRINTK("mode: %s\n", info->fix.id);
968 DPRINTK("visual: %d\n", info->fix.visual);
969 DPRINTK("res: %dx%d-%d\n", info->var.xres,
971 info->var.bits_per_pixel);
973 fbcon_add_cursor_timer(info);
974 fbcon_has_exited = 0;
978 static void fbcon_init(struct vc_data *vc, int init)
980 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
981 struct fbcon_ops *ops;
982 struct vc_data **default_mode = vc->vc_display_fg;
983 struct vc_data *svc = *default_mode;
984 struct display *t, *p = &fb_display[vc->vc_num];
985 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
988 if (info_idx == -1 || info == NULL)
993 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
994 (info->fix.type == FB_TYPE_TEXT))
997 if (var_to_display(p, &info->var, info))
1000 if (!info->fbcon_par)
1001 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1003 /* If we are not the first console on this
1004 fb, copy the font from that console */
1005 t = &fb_display[fg_console];
1008 struct vc_data *fvc = vc_cons[fg_console].d;
1010 vc->vc_font.data = (void *)(p->fontdata =
1012 vc->vc_font.width = fvc->vc_font.width;
1013 vc->vc_font.height = fvc->vc_font.height;
1014 p->userfont = t->userfont;
1017 REFCOUNT(p->fontdata)++;
1019 const struct font_desc *font = NULL;
1021 if (!fontname[0] || !(font = find_font(fontname)))
1022 font = get_default_font(info->var.xres,
1024 info->pixmap.blit_x,
1025 info->pixmap.blit_y);
1026 vc->vc_font.width = font->width;
1027 vc->vc_font.height = font->height;
1028 vc->vc_font.data = (void *)(p->fontdata = font->data);
1029 vc->vc_font.charcount = 256; /* FIXME Need to
1030 support more fonts */
1035 charcnt = FNTCHARCNT(p->fontdata);
1037 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1038 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1039 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1040 if (charcnt == 256) {
1041 vc->vc_hi_font_mask = 0;
1043 vc->vc_hi_font_mask = 0x100;
1044 if (vc->vc_can_do_color)
1045 vc->vc_complement_mask <<= 1;
1048 if (!*svc->vc_uni_pagedir_loc)
1049 con_set_default_unimap(svc);
1050 if (!*vc->vc_uni_pagedir_loc)
1051 con_copy_unimap(vc, svc);
1053 ops = info->fbcon_par;
1054 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1055 if (initial_rotation != -1)
1056 p->con_rotate = initial_rotation;
1058 p->con_rotate = fbcon_platform_get_rotate(info);
1059 set_blitting_type(vc, info);
1063 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1064 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1065 new_cols /= vc->vc_font.width;
1066 new_rows /= vc->vc_font.height;
1069 * We must always set the mode. The mode of the previous console
1070 * driver could be in the same resolution but we are using different
1071 * hardware so we have to initialize the hardware.
1073 * We need to do it in fbcon_init() to prevent screen corruption.
1075 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1076 if (info->fbops->fb_set_par &&
1077 !(ops->flags & FBCON_FLAGS_INIT)) {
1078 ret = info->fbops->fb_set_par(info);
1081 printk(KERN_ERR "fbcon_init: detected "
1082 "unhandled fb_set_par error, "
1083 "error code %d\n", ret);
1086 ops->flags |= FBCON_FLAGS_INIT;
1091 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1092 !(cap & FBINFO_HWACCEL_DISABLED))
1093 p->scrollmode = SCROLL_MOVE;
1094 else /* default to something safe */
1095 p->scrollmode = SCROLL_REDRAW;
1098 * ++guenther: console.c:vc_allocate() relies on initializing
1099 * vc_{cols,rows}, but we must not set those if we are only
1100 * resizing the console.
1103 vc->vc_cols = new_cols;
1104 vc->vc_rows = new_rows;
1106 vc_resize(vc, new_cols, new_rows);
1109 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1111 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1112 ops->rotate = FB_ROTATE_UR;
1113 set_blitting_type(vc, info);
1116 ops->p = &fb_display[fg_console];
1119 static void fbcon_free_font(struct display *p, bool freefont)
1121 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1122 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1127 static void set_vc_hi_font(struct vc_data *vc, bool set);
1129 static void fbcon_deinit(struct vc_data *vc)
1131 struct display *p = &fb_display[vc->vc_num];
1132 struct fb_info *info;
1133 struct fbcon_ops *ops;
1135 bool free_font = true;
1137 idx = con2fb_map[vc->vc_num];
1142 info = registered_fb[idx];
1147 if (info->flags & FBINFO_MISC_FIRMWARE)
1149 ops = info->fbcon_par;
1154 if (con_is_visible(vc))
1155 fbcon_del_cursor_timer(info);
1157 ops->flags &= ~FBCON_FLAGS_INIT;
1160 fbcon_free_font(p, free_font);
1162 vc->vc_font.data = NULL;
1164 if (vc->vc_hi_font_mask)
1165 set_vc_hi_font(vc, false);
1167 if (!con_is_bound(&fb_con))
1170 if (vc->vc_num == logo_shown)
1171 logo_shown = FBCON_LOGO_CANSHOW;
1176 /* ====================================================================== */
1178 /* fbcon_XXX routines - interface used by the world
1180 * This system is now divided into two levels because of complications
1181 * caused by hardware scrolling. Top level functions:
1183 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1185 * handles y values in range [0, scr_height-1] that correspond to real
1186 * screen positions. y_wrap shift means that first line of bitmap may be
1187 * anywhere on this display. These functions convert lineoffsets to
1188 * bitmap offsets and deal with the wrap-around case by splitting blits.
1190 * fbcon_bmove_physical_8() -- These functions fast implementations
1191 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1192 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1196 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1197 * Implies should only really hardware scroll in rows. Only reason for
1198 * restriction is simplicity & efficiency at the moment.
1201 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1204 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1205 struct fbcon_ops *ops = info->fbcon_par;
1207 struct display *p = &fb_display[vc->vc_num];
1210 if (fbcon_is_inactive(vc, info))
1213 if (!height || !width)
1216 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1219 * If the font dimensions are not an integral of the display
1220 * dimensions then the ops->clear below won't end up clearing
1221 * the margins. Call clear_margins here in case the logo
1222 * bitmap stretched into the margin area.
1224 fbcon_clear_margins(vc, 0);
1227 /* Split blits that cross physical y_wrap boundary */
1229 y_break = p->vrows - p->yscroll;
1230 if (sy < y_break && sy + height - 1 >= y_break) {
1231 u_int b = y_break - sy;
1232 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1233 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1236 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1239 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1240 int count, int ypos, int xpos)
1242 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1243 struct display *p = &fb_display[vc->vc_num];
1244 struct fbcon_ops *ops = info->fbcon_par;
1246 if (!fbcon_is_inactive(vc, info))
1247 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1248 get_color(vc, info, scr_readw(s), 1),
1249 get_color(vc, info, scr_readw(s), 0));
1252 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1256 scr_writew(c, &chr);
1257 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1260 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1262 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1263 struct fbcon_ops *ops = info->fbcon_par;
1265 if (!fbcon_is_inactive(vc, info))
1266 ops->clear_margins(vc, info, margin_color, bottom_only);
1269 static void fbcon_cursor(struct vc_data *vc, int mode)
1271 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1272 struct fbcon_ops *ops = info->fbcon_par;
1273 int c = scr_readw((u16 *) vc->vc_pos);
1275 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1277 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1280 if (vc->vc_cursor_type & 0x10)
1281 fbcon_del_cursor_timer(info);
1283 fbcon_add_cursor_timer(info);
1285 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1290 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1291 get_color(vc, info, c, 0));
1294 static int scrollback_phys_max = 0;
1295 static int scrollback_max = 0;
1296 static int scrollback_current = 0;
1298 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1301 struct display *p, *t;
1302 struct vc_data **default_mode, *vc;
1303 struct vc_data *svc;
1304 struct fbcon_ops *ops = info->fbcon_par;
1305 int rows, cols, charcnt = 256;
1307 p = &fb_display[unit];
1309 if (var_to_display(p, var, info))
1312 vc = vc_cons[unit].d;
1317 default_mode = vc->vc_display_fg;
1318 svc = *default_mode;
1319 t = &fb_display[svc->vc_num];
1321 if (!vc->vc_font.data) {
1322 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1323 vc->vc_font.width = (*default_mode)->vc_font.width;
1324 vc->vc_font.height = (*default_mode)->vc_font.height;
1325 p->userfont = t->userfont;
1327 REFCOUNT(p->fontdata)++;
1330 charcnt = FNTCHARCNT(p->fontdata);
1332 var->activate = FB_ACTIVATE_NOW;
1333 info->var.activate = var->activate;
1334 var->yoffset = info->var.yoffset;
1335 var->xoffset = info->var.xoffset;
1336 fb_set_var(info, var);
1337 ops->var = info->var;
1338 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1339 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1340 if (charcnt == 256) {
1341 vc->vc_hi_font_mask = 0;
1343 vc->vc_hi_font_mask = 0x100;
1344 if (vc->vc_can_do_color)
1345 vc->vc_complement_mask <<= 1;
1348 if (!*svc->vc_uni_pagedir_loc)
1349 con_set_default_unimap(svc);
1350 if (!*vc->vc_uni_pagedir_loc)
1351 con_copy_unimap(vc, svc);
1353 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1354 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1355 cols /= vc->vc_font.width;
1356 rows /= vc->vc_font.height;
1357 vc_resize(vc, cols, rows);
1359 if (con_is_visible(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_move(struct vc_data *vc, struct display *p,
1499 int line, int count, int dy)
1501 unsigned short *s = (unsigned short *)
1502 (vc->vc_origin + vc->vc_size_row * line);
1505 unsigned short *start = s;
1506 unsigned short *le = advance_row(s, 1);
1509 unsigned short attr = 1;
1513 if (attr != (c & 0xff00)) {
1516 fbcon_putcs(vc, start, s - start,
1522 console_conditional_schedule();
1526 fbcon_putcs(vc, start, s - start, dy, x);
1527 console_conditional_schedule();
1532 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1533 struct display *p, int line, int count, int ycount)
1535 int offset = ycount * vc->vc_cols;
1536 unsigned short *d = (unsigned short *)
1537 (vc->vc_origin + vc->vc_size_row * line);
1538 unsigned short *s = d + offset;
1539 struct fbcon_ops *ops = info->fbcon_par;
1542 unsigned short *start = s;
1543 unsigned short *le = advance_row(s, 1);
1550 if (c == scr_readw(d)) {
1552 ops->bmove(vc, info, line + ycount, x,
1553 line, x, 1, s-start);
1563 console_conditional_schedule();
1568 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1570 console_conditional_schedule();
1575 /* NOTE: We subtract two lines from these pointers */
1576 s -= vc->vc_size_row;
1577 d -= vc->vc_size_row;
1582 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1583 int line, int count, int offset)
1585 unsigned short *d = (unsigned short *)
1586 (vc->vc_origin + vc->vc_size_row * line);
1587 unsigned short *s = d + offset;
1590 unsigned short *start = s;
1591 unsigned short *le = advance_row(s, 1);
1594 unsigned short attr = 1;
1598 if (attr != (c & 0xff00)) {
1601 fbcon_putcs(vc, start, s - start,
1607 if (c == scr_readw(d)) {
1609 fbcon_putcs(vc, start, s - start,
1619 console_conditional_schedule();
1624 fbcon_putcs(vc, start, s - start, line, x);
1625 console_conditional_schedule();
1630 /* NOTE: We subtract two lines from these pointers */
1631 s -= vc->vc_size_row;
1632 d -= vc->vc_size_row;
1637 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1638 enum con_scroll dir, unsigned int count)
1640 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1641 struct display *p = &fb_display[vc->vc_num];
1642 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1644 if (fbcon_is_inactive(vc, info))
1647 fbcon_cursor(vc, CM_ERASE);
1650 * ++Geert: Only use ywrap/ypan if the console is in text mode
1651 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1652 * whole screen (prevents flicker).
1657 if (count > vc->vc_rows) /* Maximum realistic size */
1658 count = vc->vc_rows;
1659 if (logo_shown >= 0)
1661 switch (p->scrollmode) {
1663 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1665 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1666 scr_memsetw((unsigned short *) (vc->vc_origin +
1669 vc->vc_video_erase_char,
1670 vc->vc_size_row * count);
1674 case SCROLL_WRAP_MOVE:
1675 if (b - t - count > 3 * vc->vc_rows >> 2) {
1677 fbcon_bmove(vc, 0, 0, count, 0, t,
1679 ywrap_up(vc, count);
1680 if (vc->vc_rows - b > 0)
1681 fbcon_bmove(vc, b - count, 0, b, 0,
1684 } else if (info->flags & FBINFO_READS_FAST)
1685 fbcon_bmove(vc, t + count, 0, t, 0,
1686 b - t - count, vc->vc_cols);
1689 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1692 case SCROLL_PAN_REDRAW:
1693 if ((p->yscroll + count <=
1694 2 * (p->vrows - vc->vc_rows))
1695 && ((!scroll_partial && (b - t == vc->vc_rows))
1698 3 * vc->vc_rows >> 2)))) {
1700 fbcon_redraw_move(vc, p, 0, t, count);
1701 ypan_up_redraw(vc, t, count);
1702 if (vc->vc_rows - b > 0)
1703 fbcon_redraw_move(vc, p, b,
1704 vc->vc_rows - b, b);
1706 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1707 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1710 case SCROLL_PAN_MOVE:
1711 if ((p->yscroll + count <=
1712 2 * (p->vrows - vc->vc_rows))
1713 && ((!scroll_partial && (b - t == vc->vc_rows))
1716 3 * vc->vc_rows >> 2)))) {
1718 fbcon_bmove(vc, 0, 0, count, 0, t,
1721 if (vc->vc_rows - b > 0)
1722 fbcon_bmove(vc, b - count, 0, b, 0,
1725 } else if (info->flags & FBINFO_READS_FAST)
1726 fbcon_bmove(vc, t + count, 0, t, 0,
1727 b - t - count, vc->vc_cols);
1730 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1735 fbcon_redraw(vc, p, t, b - t - count,
1736 count * vc->vc_cols);
1737 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1738 scr_memsetw((unsigned short *) (vc->vc_origin +
1741 vc->vc_video_erase_char,
1742 vc->vc_size_row * count);
1748 if (count > vc->vc_rows) /* Maximum realistic size */
1749 count = vc->vc_rows;
1750 if (logo_shown >= 0)
1752 switch (p->scrollmode) {
1754 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1756 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1757 scr_memsetw((unsigned short *) (vc->vc_origin +
1760 vc->vc_video_erase_char,
1761 vc->vc_size_row * count);
1765 case SCROLL_WRAP_MOVE:
1766 if (b - t - count > 3 * vc->vc_rows >> 2) {
1767 if (vc->vc_rows - b > 0)
1768 fbcon_bmove(vc, b, 0, b - count, 0,
1771 ywrap_down(vc, count);
1773 fbcon_bmove(vc, count, 0, 0, 0, t,
1775 } else if (info->flags & FBINFO_READS_FAST)
1776 fbcon_bmove(vc, t, 0, t + count, 0,
1777 b - t - count, vc->vc_cols);
1780 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1783 case SCROLL_PAN_MOVE:
1784 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1785 && ((!scroll_partial && (b - t == vc->vc_rows))
1788 3 * vc->vc_rows >> 2)))) {
1789 if (vc->vc_rows - b > 0)
1790 fbcon_bmove(vc, b, 0, b - count, 0,
1793 ypan_down(vc, count);
1795 fbcon_bmove(vc, count, 0, 0, 0, t,
1797 } else if (info->flags & FBINFO_READS_FAST)
1798 fbcon_bmove(vc, t, 0, t + count, 0,
1799 b - t - count, vc->vc_cols);
1802 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1805 case SCROLL_PAN_REDRAW:
1806 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1807 && ((!scroll_partial && (b - t == vc->vc_rows))
1810 3 * vc->vc_rows >> 2)))) {
1811 if (vc->vc_rows - b > 0)
1812 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1814 ypan_down_redraw(vc, t, count);
1816 fbcon_redraw_move(vc, p, count, t, 0);
1818 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1819 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1824 fbcon_redraw(vc, p, b - 1, b - t - count,
1825 -count * vc->vc_cols);
1826 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1827 scr_memsetw((unsigned short *) (vc->vc_origin +
1830 vc->vc_video_erase_char,
1831 vc->vc_size_row * count);
1839 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1840 int height, int width)
1842 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1843 struct display *p = &fb_display[vc->vc_num];
1845 if (fbcon_is_inactive(vc, info))
1848 if (!width || !height)
1851 /* Split blits that cross physical y_wrap case.
1852 * Pathological case involves 4 blits, better to use recursive
1853 * code rather than unrolled case
1855 * Recursive invocations don't need to erase the cursor over and
1856 * over again, so we use fbcon_bmove_rec()
1858 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1859 p->vrows - p->yscroll);
1862 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1863 int dy, int dx, int height, int width, u_int y_break)
1865 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1866 struct fbcon_ops *ops = info->fbcon_par;
1869 if (sy < y_break && sy + height > y_break) {
1871 if (dy < sy) { /* Avoid trashing self */
1872 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1874 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1875 height - b, width, y_break);
1877 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1878 height - b, width, y_break);
1879 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1885 if (dy < y_break && dy + height > y_break) {
1887 if (dy < sy) { /* Avoid trashing self */
1888 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1890 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1891 height - b, width, y_break);
1893 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1894 height - b, width, y_break);
1895 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1900 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1904 static void updatescrollmode(struct display *p,
1905 struct fb_info *info,
1908 struct fbcon_ops *ops = info->fbcon_par;
1909 int fh = vc->vc_font.height;
1910 int cap = info->flags;
1912 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1913 info->fix.xpanstep);
1914 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1915 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1916 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1917 info->var.xres_virtual);
1918 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1919 divides(ypan, vc->vc_font.height) && vyres > yres;
1920 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1921 divides(ywrap, vc->vc_font.height) &&
1922 divides(vc->vc_font.height, vyres) &&
1923 divides(vc->vc_font.height, yres);
1924 int reading_fast = cap & FBINFO_READS_FAST;
1925 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1926 !(cap & FBINFO_HWACCEL_DISABLED);
1927 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1928 !(cap & FBINFO_HWACCEL_DISABLED);
1930 p->vrows = vyres/fh;
1931 if (yres > (fh * (vc->vc_rows + 1)))
1932 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1933 if ((yres % fh) && (vyres % fh < yres % fh))
1936 if (good_wrap || good_pan) {
1937 if (reading_fast || fast_copyarea)
1938 p->scrollmode = good_wrap ?
1939 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1941 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1944 if (reading_fast || (fast_copyarea && !fast_imageblit))
1945 p->scrollmode = SCROLL_MOVE;
1947 p->scrollmode = SCROLL_REDRAW;
1951 #define PITCH(w) (((w) + 7) >> 3)
1952 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
1954 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1955 unsigned int height, unsigned int user)
1957 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1958 struct fbcon_ops *ops = info->fbcon_par;
1959 struct display *p = &fb_display[vc->vc_num];
1960 struct fb_var_screeninfo var = info->var;
1961 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
1963 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
1965 int pitch = PITCH(vc->vc_font.width);
1968 * If user font, ensure that a possible change to user font
1969 * height or width will not allow a font data out-of-bounds access.
1970 * NOTE: must use original charcount in calculation as font
1971 * charcount can change and cannot be used to determine the
1972 * font data allocated size.
1976 size = CALC_FONTSZ(vc->vc_font.height, pitch, FNTCHARCNT(vc->vc_font.data));
1977 if (size > FNTSIZE(vc->vc_font.data))
1981 virt_w = FBCON_SWAP(ops->rotate, width, height);
1982 virt_h = FBCON_SWAP(ops->rotate, height, width);
1983 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
1984 vc->vc_font.height);
1985 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
1987 var.xres = virt_w * virt_fw;
1988 var.yres = virt_h * virt_fh;
1989 x_diff = info->var.xres - var.xres;
1990 y_diff = info->var.yres - var.yres;
1991 if (x_diff < 0 || x_diff > virt_fw ||
1992 y_diff < 0 || y_diff > virt_fh) {
1993 const struct fb_videomode *mode;
1995 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
1996 mode = fb_find_best_mode(&var, &info->modelist);
1999 display_to_var(&var, p);
2000 fb_videomode_to_var(&var, mode);
2002 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2005 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2006 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
2007 var.activate = FB_ACTIVATE_NOW |
2009 fb_set_var(info, &var);
2011 var_to_display(p, &info->var, info);
2012 ops->var = info->var;
2014 updatescrollmode(p, info, vc);
2018 static int fbcon_switch(struct vc_data *vc)
2020 struct fb_info *info, *old_info = NULL;
2021 struct fbcon_ops *ops;
2022 struct display *p = &fb_display[vc->vc_num];
2023 struct fb_var_screeninfo var;
2024 int i, ret, prev_console, charcnt = 256;
2026 info = registered_fb[con2fb_map[vc->vc_num]];
2027 ops = info->fbcon_par;
2029 if (logo_shown >= 0) {
2030 struct vc_data *conp2 = vc_cons[logo_shown].d;
2032 if (conp2->vc_top == logo_lines
2033 && conp2->vc_bottom == conp2->vc_rows)
2035 logo_shown = FBCON_LOGO_CANSHOW;
2038 prev_console = ops->currcon;
2039 if (prev_console != -1)
2040 old_info = registered_fb[con2fb_map[prev_console]];
2042 * FIXME: If we have multiple fbdev's loaded, we need to
2043 * update all info->currcon. Perhaps, we can place this
2044 * in a centralized structure, but this might break some
2047 * info->currcon = vc->vc_num;
2049 for (i = 0; i < FB_MAX; i++) {
2050 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2051 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2053 o->currcon = vc->vc_num;
2056 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2057 display_to_var(&var, p);
2058 var.activate = FB_ACTIVATE_NOW;
2061 * make sure we don't unnecessarily trip the memcmp()
2064 info->var.activate = var.activate;
2065 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2066 fb_set_var(info, &var);
2067 ops->var = info->var;
2069 if (old_info != NULL && (old_info != info ||
2070 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2071 if (info->fbops->fb_set_par) {
2072 ret = info->fbops->fb_set_par(info);
2075 printk(KERN_ERR "fbcon_switch: detected "
2076 "unhandled fb_set_par error, "
2077 "error code %d\n", ret);
2080 if (old_info != info)
2081 fbcon_del_cursor_timer(old_info);
2084 if (fbcon_is_inactive(vc, info) ||
2085 ops->blank_state != FB_BLANK_UNBLANK)
2086 fbcon_del_cursor_timer(info);
2088 fbcon_add_cursor_timer(info);
2090 set_blitting_type(vc, info);
2091 ops->cursor_reset = 1;
2093 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2094 ops->rotate = FB_ROTATE_UR;
2095 set_blitting_type(vc, info);
2098 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2099 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2102 charcnt = FNTCHARCNT(vc->vc_font.data);
2105 vc->vc_complement_mask <<= 1;
2107 updatescrollmode(p, info, vc);
2109 switch (p->scrollmode) {
2110 case SCROLL_WRAP_MOVE:
2111 scrollback_phys_max = p->vrows - vc->vc_rows;
2113 case SCROLL_PAN_MOVE:
2114 case SCROLL_PAN_REDRAW:
2115 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2116 if (scrollback_phys_max < 0)
2117 scrollback_phys_max = 0;
2120 scrollback_phys_max = 0;
2125 scrollback_current = 0;
2127 if (!fbcon_is_inactive(vc, info)) {
2128 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2129 ops->update_start(info);
2132 fbcon_set_palette(vc, color_table);
2133 fbcon_clear_margins(vc, 0);
2135 if (logo_shown == FBCON_LOGO_DRAW) {
2137 logo_shown = fg_console;
2138 /* This is protected above by initmem_freed */
2139 fb_show_logo(info, ops->rotate);
2141 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2142 vc->vc_size_row * (vc->vc_bottom -
2149 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2152 struct fb_event event;
2155 unsigned short charmask = vc->vc_hi_font_mask ?
2157 unsigned short oldc;
2159 oldc = vc->vc_video_erase_char;
2160 vc->vc_video_erase_char &= charmask;
2161 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2162 vc->vc_video_erase_char = oldc;
2166 if (!lock_fb_info(info))
2169 event.data = ␣
2170 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2171 unlock_fb_info(info);
2174 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2176 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2177 struct fbcon_ops *ops = info->fbcon_par;
2180 struct fb_var_screeninfo var = info->var;
2185 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2186 fb_set_var(info, &var);
2188 ops->var = info->var;
2192 if (!fbcon_is_inactive(vc, info)) {
2193 if (ops->blank_state != blank) {
2194 ops->blank_state = blank;
2195 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2196 ops->cursor_flash = (!blank);
2198 if (!(info->flags & FBINFO_MISC_USEREVENT))
2199 if (fb_blank(info, blank))
2200 fbcon_generic_blank(vc, info, blank);
2207 if (mode_switch || fbcon_is_inactive(vc, info) ||
2208 ops->blank_state != FB_BLANK_UNBLANK)
2209 fbcon_del_cursor_timer(info);
2211 fbcon_add_cursor_timer(info);
2216 static int fbcon_debug_enter(struct vc_data *vc)
2218 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2219 struct fbcon_ops *ops = info->fbcon_par;
2221 ops->save_graphics = ops->graphics;
2223 if (info->fbops->fb_debug_enter)
2224 info->fbops->fb_debug_enter(info);
2225 fbcon_set_palette(vc, color_table);
2229 static int fbcon_debug_leave(struct vc_data *vc)
2231 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2232 struct fbcon_ops *ops = info->fbcon_par;
2234 ops->graphics = ops->save_graphics;
2235 if (info->fbops->fb_debug_leave)
2236 info->fbops->fb_debug_leave(info);
2240 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2242 u8 *fontdata = vc->vc_font.data;
2243 u8 *data = font->data;
2246 font->width = vc->vc_font.width;
2247 font->height = vc->vc_font.height;
2248 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2252 if (font->width <= 8) {
2253 j = vc->vc_font.height;
2254 if (font->charcount * j > FNTSIZE(fontdata))
2257 for (i = 0; i < font->charcount; i++) {
2258 memcpy(data, fontdata, j);
2259 memset(data + j, 0, 32 - j);
2263 } else if (font->width <= 16) {
2264 j = vc->vc_font.height * 2;
2265 if (font->charcount * j > FNTSIZE(fontdata))
2268 for (i = 0; i < font->charcount; i++) {
2269 memcpy(data, fontdata, j);
2270 memset(data + j, 0, 64 - j);
2274 } else if (font->width <= 24) {
2275 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
2278 for (i = 0; i < font->charcount; i++) {
2279 for (j = 0; j < vc->vc_font.height; j++) {
2280 *data++ = fontdata[0];
2281 *data++ = fontdata[1];
2282 *data++ = fontdata[2];
2283 fontdata += sizeof(u32);
2285 memset(data, 0, 3 * (32 - j));
2286 data += 3 * (32 - j);
2289 j = vc->vc_font.height * 4;
2290 if (font->charcount * j > FNTSIZE(fontdata))
2293 for (i = 0; i < font->charcount; i++) {
2294 memcpy(data, fontdata, j);
2295 memset(data + j, 0, 128 - j);
2303 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2304 static void set_vc_hi_font(struct vc_data *vc, bool set)
2307 vc->vc_hi_font_mask = 0;
2308 if (vc->vc_can_do_color) {
2309 vc->vc_complement_mask >>= 1;
2310 vc->vc_s_complement_mask >>= 1;
2313 /* ++Edmund: reorder the attribute bits */
2314 if (vc->vc_can_do_color) {
2315 unsigned short *cp =
2316 (unsigned short *) vc->vc_origin;
2317 int count = vc->vc_screenbuf_size / 2;
2319 for (; count > 0; count--, cp++) {
2321 scr_writew(((c & 0xfe00) >> 1) |
2324 c = vc->vc_video_erase_char;
2325 vc->vc_video_erase_char =
2326 ((c & 0xfe00) >> 1) | (c & 0xff);
2330 vc->vc_hi_font_mask = 0x100;
2331 if (vc->vc_can_do_color) {
2332 vc->vc_complement_mask <<= 1;
2333 vc->vc_s_complement_mask <<= 1;
2336 /* ++Edmund: reorder the attribute bits */
2338 unsigned short *cp =
2339 (unsigned short *) vc->vc_origin;
2340 int count = vc->vc_screenbuf_size / 2;
2342 for (; count > 0; count--, cp++) {
2343 unsigned short newc;
2345 if (vc->vc_can_do_color)
2347 ((c & 0xff00) << 1) | (c &
2351 scr_writew(newc, cp);
2353 c = vc->vc_video_erase_char;
2354 if (vc->vc_can_do_color) {
2355 vc->vc_video_erase_char =
2356 ((c & 0xff00) << 1) | (c & 0xff);
2359 vc->vc_video_erase_char = c & ~0x100;
2364 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2365 const u8 * data, int userfont)
2367 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2368 struct fbcon_ops *ops = info->fbcon_par;
2369 struct display *p = &fb_display[vc->vc_num];
2372 char *old_data = NULL;
2374 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2376 old_data = vc->vc_font.data;
2378 cnt = FNTCHARCNT(data);
2381 vc->vc_font.data = (void *)(p->fontdata = data);
2382 if ((p->userfont = userfont))
2384 vc->vc_font.width = w;
2385 vc->vc_font.height = h;
2386 if (vc->vc_hi_font_mask && cnt == 256)
2387 set_vc_hi_font(vc, false);
2388 else if (!vc->vc_hi_font_mask && cnt == 512)
2389 set_vc_hi_font(vc, true);
2394 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2395 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2398 vc_resize(vc, cols, rows);
2399 } else if (con_is_visible(vc)
2400 && vc->vc_mode == KD_TEXT) {
2401 fbcon_clear_margins(vc, 0);
2405 if (old_data && (--REFCOUNT(old_data) == 0))
2406 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2410 static int fbcon_copy_font(struct vc_data *vc, int con)
2412 struct display *od = &fb_display[con];
2413 struct console_font *f = &vc->vc_font;
2415 if (od->fontdata == f->data)
2416 return 0; /* already the same font... */
2417 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2421 * User asked to set font; we are guaranteed that
2422 * a) width and height are in range 1..32
2423 * b) charcount does not exceed 512
2424 * but lets not assume that, since someone might someday want to use larger
2425 * fonts. And charcount of 512 is small for unicode support.
2427 * However, user space gives the font in 32 rows , regardless of
2428 * actual font height. So a new API is needed if support for larger fonts
2429 * is ever implemented.
2432 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2434 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2435 unsigned charcount = font->charcount;
2436 int w = font->width;
2437 int h = font->height;
2440 u8 *new_data, *data = font->data;
2441 int pitch = PITCH(font->width);
2443 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2444 * If not this check should be changed to charcount < 256 */
2445 if (charcount != 256 && charcount != 512)
2448 /* font bigger than screen resolution ? */
2449 if (w > FBCON_SWAP(info->var.rotate, info->var.xres, info->var.yres) ||
2450 h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres))
2453 /* Make sure drawing engine can handle the font */
2454 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2455 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2458 /* Make sure driver can handle the font length */
2459 if (fbcon_invalid_charcount(info, charcount))
2462 size = CALC_FONTSZ(h, pitch, charcount);
2464 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2469 new_data += FONT_EXTRA_WORDS * sizeof(int);
2470 FNTSIZE(new_data) = size;
2471 FNTCHARCNT(new_data) = charcount;
2472 REFCOUNT(new_data) = 0; /* usage counter */
2473 for (i=0; i< charcount; i++) {
2474 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2477 /* Since linux has a nice crc32 function use it for counting font
2479 csum = crc32(0, new_data, size);
2481 FNTSUM(new_data) = csum;
2482 /* Check if the same font is on some other console already */
2483 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2484 struct vc_data *tmp = vc_cons[i].d;
2486 if (fb_display[i].userfont &&
2487 fb_display[i].fontdata &&
2488 FNTSUM(fb_display[i].fontdata) == csum &&
2489 FNTSIZE(fb_display[i].fontdata) == size &&
2490 tmp->vc_font.width == w &&
2491 !memcmp(fb_display[i].fontdata, new_data, size)) {
2492 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2493 new_data = (u8 *)fb_display[i].fontdata;
2497 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2500 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2502 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2503 const struct font_desc *f;
2506 f = get_default_font(info->var.xres, info->var.yres,
2507 info->pixmap.blit_x, info->pixmap.blit_y);
2508 else if (!(f = find_font(name)))
2511 font->width = f->width;
2512 font->height = f->height;
2513 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2516 static u16 palette_red[16];
2517 static u16 palette_green[16];
2518 static u16 palette_blue[16];
2520 static struct fb_cmap palette_cmap = {
2521 0, 16, palette_red, palette_green, palette_blue, NULL
2524 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2526 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2530 if (fbcon_is_inactive(vc, info))
2533 if (!con_is_visible(vc))
2536 depth = fb_get_color_depth(&info->var, &info->fix);
2538 for (i = j = 0; i < 16; i++) {
2540 val = vc->vc_palette[j++];
2541 palette_red[k] = (val << 8) | val;
2542 val = vc->vc_palette[j++];
2543 palette_green[k] = (val << 8) | val;
2544 val = vc->vc_palette[j++];
2545 palette_blue[k] = (val << 8) | val;
2547 palette_cmap.len = 16;
2548 palette_cmap.start = 0;
2550 * If framebuffer is capable of less than 16 colors,
2551 * use default palette of fbcon.
2554 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2556 fb_set_cmap(&palette_cmap, info);
2559 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2561 return (u16 *) (vc->vc_origin + offset);
2564 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2570 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2571 unsigned long offset = (pos - vc->vc_origin) / 2;
2573 x = offset % vc->vc_cols;
2574 y = offset / vc->vc_cols;
2575 ret = pos + (vc->vc_cols - x) * 2;
2577 /* Should not happen */
2579 ret = vc->vc_origin;
2588 /* As we might be inside of softback, we may work with non-contiguous buffer,
2589 that's why we have to use a separate routine. */
2590 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2593 u16 a = scr_readw(p);
2594 if (!vc->vc_can_do_color)
2596 else if (vc->vc_hi_font_mask == 0x100)
2597 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2598 (((a) & 0x0e00) << 4);
2600 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2601 (((a) & 0x0700) << 4);
2606 static int fbcon_set_origin(struct vc_data *vc)
2611 static void fbcon_suspended(struct fb_info *info)
2613 struct vc_data *vc = NULL;
2614 struct fbcon_ops *ops = info->fbcon_par;
2616 if (!ops || ops->currcon < 0)
2618 vc = vc_cons[ops->currcon].d;
2620 /* Clear cursor, restore saved data */
2621 fbcon_cursor(vc, CM_ERASE);
2624 static void fbcon_resumed(struct fb_info *info)
2627 struct fbcon_ops *ops = info->fbcon_par;
2629 if (!ops || ops->currcon < 0)
2631 vc = vc_cons[ops->currcon].d;
2636 static void fbcon_modechanged(struct fb_info *info)
2638 struct fbcon_ops *ops = info->fbcon_par;
2643 if (!ops || ops->currcon < 0)
2645 vc = vc_cons[ops->currcon].d;
2646 if (vc->vc_mode != KD_TEXT ||
2647 registered_fb[con2fb_map[ops->currcon]] != info)
2650 p = &fb_display[vc->vc_num];
2651 set_blitting_type(vc, info);
2653 if (con_is_visible(vc)) {
2654 var_to_display(p, &info->var, info);
2655 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2656 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2657 cols /= vc->vc_font.width;
2658 rows /= vc->vc_font.height;
2659 vc_resize(vc, cols, rows);
2660 updatescrollmode(p, info, vc);
2662 scrollback_current = 0;
2664 if (!fbcon_is_inactive(vc, info)) {
2665 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2666 ops->update_start(info);
2669 fbcon_set_palette(vc, color_table);
2674 static void fbcon_set_all_vcs(struct fb_info *info)
2676 struct fbcon_ops *ops = info->fbcon_par;
2679 int i, rows, cols, fg = -1;
2681 if (!ops || ops->currcon < 0)
2684 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2686 if (!vc || vc->vc_mode != KD_TEXT ||
2687 registered_fb[con2fb_map[i]] != info)
2690 if (con_is_visible(vc)) {
2695 p = &fb_display[vc->vc_num];
2696 set_blitting_type(vc, info);
2697 var_to_display(p, &info->var, info);
2698 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2699 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2700 cols /= vc->vc_font.width;
2701 rows /= vc->vc_font.height;
2702 vc_resize(vc, cols, rows);
2706 fbcon_modechanged(info);
2709 static int fbcon_mode_deleted(struct fb_info *info,
2710 struct fb_videomode *mode)
2712 struct fb_info *fb_info;
2714 int i, j, found = 0;
2716 /* before deletion, ensure that mode is not in use */
2717 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2721 fb_info = registered_fb[j];
2722 if (fb_info != info)
2727 if (fb_mode_is_equal(p->mode, mode)) {
2735 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2736 static int fbcon_unbind(void)
2740 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2744 fbcon_has_console_bind = 0;
2749 static inline int fbcon_unbind(void)
2753 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2755 /* called with console_lock held */
2756 static int fbcon_fb_unbind(int idx)
2758 int i, new_idx = -1, ret = 0;
2760 if (!fbcon_has_console_bind)
2763 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2764 if (con2fb_map[i] != idx &&
2765 con2fb_map[i] != -1) {
2766 new_idx = con2fb_map[i];
2771 if (new_idx != -1) {
2772 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2773 if (con2fb_map[i] == idx)
2774 set_con2fb_map(i, new_idx, 0);
2777 struct fb_info *info = registered_fb[idx];
2779 /* This is sort of like set_con2fb_map, except it maps
2780 * the consoles to no device and then releases the
2781 * oldinfo to free memory and cancel the cursor blink
2782 * timer. I can imagine this just becoming part of
2783 * set_con2fb_map where new_idx is -1
2785 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2786 if (con2fb_map[i] == idx) {
2788 if (!search_fb_in_map(idx)) {
2789 ret = con2fb_release_oldinfo(vc_cons[i].d,
2793 con2fb_map[i] = idx;
2799 ret = fbcon_unbind();
2805 /* called with console_lock held */
2806 static int fbcon_fb_unregistered(struct fb_info *info)
2811 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2812 if (con2fb_map[i] == idx)
2816 if (idx == info_idx) {
2819 for (i = 0; i < FB_MAX; i++) {
2820 if (registered_fb[i] != NULL) {
2827 if (info_idx != -1) {
2828 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2829 if (con2fb_map[i] == -1)
2830 con2fb_map[i] = info_idx;
2834 if (primary_device == idx)
2835 primary_device = -1;
2837 if (!num_registered_fb)
2838 do_unregister_con_driver(&fb_con);
2843 /* called with console_lock held */
2844 static void fbcon_remap_all(int idx)
2847 for (i = first_fb_vc; i <= last_fb_vc; i++)
2848 set_con2fb_map(i, idx, 0);
2850 if (con_is_bound(&fb_con)) {
2851 printk(KERN_INFO "fbcon: Remapping primary device, "
2852 "fb%i, to tty %i-%i\n", idx,
2853 first_fb_vc + 1, last_fb_vc + 1);
2858 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2859 static void fbcon_select_primary(struct fb_info *info)
2861 if (!map_override && primary_device == -1 &&
2862 fb_is_primary_device(info)) {
2865 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2866 info->fix.id, info->node);
2867 primary_device = info->node;
2869 for (i = first_fb_vc; i <= last_fb_vc; i++)
2870 con2fb_map_boot[i] = primary_device;
2872 if (con_is_bound(&fb_con)) {
2873 printk(KERN_INFO "fbcon: Remapping primary device, "
2874 "fb%i, to tty %i-%i\n", info->node,
2875 first_fb_vc + 1, last_fb_vc + 1);
2876 info_idx = primary_device;
2882 static inline void fbcon_select_primary(struct fb_info *info)
2886 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2888 /* called with console_lock held */
2889 static int fbcon_fb_registered(struct fb_info *info)
2891 int ret = 0, i, idx;
2894 fbcon_select_primary(info);
2896 if (info_idx == -1) {
2897 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2898 if (con2fb_map_boot[i] == idx) {
2905 ret = do_fbcon_takeover(1);
2907 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2908 if (con2fb_map_boot[i] == idx)
2909 set_con2fb_map(i, idx, 0);
2916 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2918 struct fbcon_ops *ops = info->fbcon_par;
2921 if (!ops || ops->currcon < 0)
2924 vc = vc_cons[ops->currcon].d;
2925 if (vc->vc_mode != KD_TEXT ||
2926 registered_fb[con2fb_map[ops->currcon]] != info)
2929 if (con_is_visible(vc)) {
2933 do_unblank_screen(0);
2935 ops->blank_state = blank;
2938 static void fbcon_new_modelist(struct fb_info *info)
2942 struct fb_var_screeninfo var;
2943 const struct fb_videomode *mode;
2945 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2946 if (registered_fb[con2fb_map[i]] != info)
2948 if (!fb_display[i].mode)
2951 display_to_var(&var, &fb_display[i]);
2952 mode = fb_find_nearest_mode(fb_display[i].mode,
2954 fb_videomode_to_var(&var, mode);
2955 fbcon_set_disp(info, &var, vc->vc_num);
2959 static void fbcon_get_requirement(struct fb_info *info,
2960 struct fb_blit_caps *caps)
2968 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2970 if (vc && vc->vc_mode == KD_TEXT &&
2971 info->node == con2fb_map[i]) {
2973 caps->x |= 1 << (vc->vc_font.width - 1);
2974 caps->y |= 1 << (vc->vc_font.height - 1);
2975 charcnt = (p->userfont) ?
2976 FNTCHARCNT(p->fontdata) : 256;
2977 if (caps->len < charcnt)
2978 caps->len = charcnt;
2982 vc = vc_cons[fg_console].d;
2984 if (vc && vc->vc_mode == KD_TEXT &&
2985 info->node == con2fb_map[fg_console]) {
2986 p = &fb_display[fg_console];
2987 caps->x = 1 << (vc->vc_font.width - 1);
2988 caps->y = 1 << (vc->vc_font.height - 1);
2989 caps->len = (p->userfont) ?
2990 FNTCHARCNT(p->fontdata) : 256;
2995 static int fbcon_event_notify(struct notifier_block *self,
2996 unsigned long action, void *data)
2998 struct fb_event *event = data;
2999 struct fb_info *info = event->info;
3000 struct fb_videomode *mode;
3001 struct fb_con2fbmap *con2fb;
3002 struct fb_blit_caps *caps;
3006 * ignore all events except driver registration and deregistration
3007 * if fbcon is not active
3009 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3010 action == FB_EVENT_FB_UNREGISTERED))
3014 case FB_EVENT_SUSPEND:
3015 fbcon_suspended(info);
3017 case FB_EVENT_RESUME:
3018 fbcon_resumed(info);
3020 case FB_EVENT_MODE_CHANGE:
3021 fbcon_modechanged(info);
3023 case FB_EVENT_MODE_CHANGE_ALL:
3024 fbcon_set_all_vcs(info);
3026 case FB_EVENT_MODE_DELETE:
3028 ret = fbcon_mode_deleted(info, mode);
3030 case FB_EVENT_FB_UNBIND:
3032 ret = fbcon_fb_unbind(idx);
3034 case FB_EVENT_FB_REGISTERED:
3035 ret = fbcon_fb_registered(info);
3037 case FB_EVENT_FB_UNREGISTERED:
3038 ret = fbcon_fb_unregistered(info);
3040 case FB_EVENT_SET_CONSOLE_MAP:
3041 /* called with console lock held */
3042 con2fb = event->data;
3043 ret = set_con2fb_map(con2fb->console - 1,
3044 con2fb->framebuffer, 1);
3046 case FB_EVENT_GET_CONSOLE_MAP:
3047 con2fb = event->data;
3048 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3050 case FB_EVENT_BLANK:
3051 fbcon_fb_blanked(info, *(int *)event->data);
3053 case FB_EVENT_NEW_MODELIST:
3054 fbcon_new_modelist(info);
3056 case FB_EVENT_GET_REQ:
3058 fbcon_get_requirement(info, caps);
3060 case FB_EVENT_REMAP_ALL_CONSOLE:
3062 fbcon_remap_all(idx);
3070 * The console `switch' structure for the frame buffer based console
3073 static const struct consw fb_con = {
3074 .owner = THIS_MODULE,
3075 .con_startup = fbcon_startup,
3076 .con_init = fbcon_init,
3077 .con_deinit = fbcon_deinit,
3078 .con_clear = fbcon_clear,
3079 .con_putc = fbcon_putc,
3080 .con_putcs = fbcon_putcs,
3081 .con_cursor = fbcon_cursor,
3082 .con_scroll = fbcon_scroll,
3083 .con_switch = fbcon_switch,
3084 .con_blank = fbcon_blank,
3085 .con_font_set = fbcon_set_font,
3086 .con_font_get = fbcon_get_font,
3087 .con_font_default = fbcon_set_def_font,
3088 .con_font_copy = fbcon_copy_font,
3089 .con_set_palette = fbcon_set_palette,
3090 .con_set_origin = fbcon_set_origin,
3091 .con_invert_region = fbcon_invert_region,
3092 .con_screen_pos = fbcon_screen_pos,
3093 .con_getxy = fbcon_getxy,
3094 .con_resize = fbcon_resize,
3095 .con_debug_enter = fbcon_debug_enter,
3096 .con_debug_leave = fbcon_debug_leave,
3099 static struct notifier_block fbcon_event_notifier = {
3100 .notifier_call = fbcon_event_notify,
3103 static ssize_t store_rotate(struct device *device,
3104 struct device_attribute *attr, const char *buf,
3107 struct fb_info *info;
3111 if (fbcon_has_exited)
3115 idx = con2fb_map[fg_console];
3117 if (idx == -1 || registered_fb[idx] == NULL)
3120 info = registered_fb[idx];
3121 rotate = simple_strtoul(buf, last, 0);
3122 fbcon_rotate(info, rotate);
3128 static ssize_t store_rotate_all(struct device *device,
3129 struct device_attribute *attr,const char *buf,
3132 struct fb_info *info;
3136 if (fbcon_has_exited)
3140 idx = con2fb_map[fg_console];
3142 if (idx == -1 || registered_fb[idx] == NULL)
3145 info = registered_fb[idx];
3146 rotate = simple_strtoul(buf, last, 0);
3147 fbcon_rotate_all(info, rotate);
3153 static ssize_t show_rotate(struct device *device,
3154 struct device_attribute *attr,char *buf)
3156 struct fb_info *info;
3157 int rotate = 0, idx;
3159 if (fbcon_has_exited)
3163 idx = con2fb_map[fg_console];
3165 if (idx == -1 || registered_fb[idx] == NULL)
3168 info = registered_fb[idx];
3169 rotate = fbcon_get_rotate(info);
3172 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3175 static ssize_t show_cursor_blink(struct device *device,
3176 struct device_attribute *attr, char *buf)
3178 struct fb_info *info;
3179 struct fbcon_ops *ops;
3180 int idx, blink = -1;
3182 if (fbcon_has_exited)
3186 idx = con2fb_map[fg_console];
3188 if (idx == -1 || registered_fb[idx] == NULL)
3191 info = registered_fb[idx];
3192 ops = info->fbcon_par;
3197 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3200 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3203 static ssize_t store_cursor_blink(struct device *device,
3204 struct device_attribute *attr,
3205 const char *buf, size_t count)
3207 struct fb_info *info;
3211 if (fbcon_has_exited)
3215 idx = con2fb_map[fg_console];
3217 if (idx == -1 || registered_fb[idx] == NULL)
3220 info = registered_fb[idx];
3222 if (!info->fbcon_par)
3225 blink = simple_strtoul(buf, last, 0);
3228 fbcon_cursor_noblink = 0;
3229 fbcon_add_cursor_timer(info);
3231 fbcon_cursor_noblink = 1;
3232 fbcon_del_cursor_timer(info);
3240 static struct device_attribute device_attrs[] = {
3241 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3242 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3243 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3244 store_cursor_blink),
3247 static int fbcon_init_device(void)
3251 fbcon_has_sysfs = 1;
3253 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3254 error = device_create_file(fbcon_device, &device_attrs[i]);
3262 device_remove_file(fbcon_device, &device_attrs[i]);
3264 fbcon_has_sysfs = 0;
3270 static void fbcon_start(void)
3272 if (num_registered_fb) {
3277 for (i = 0; i < FB_MAX; i++) {
3278 if (registered_fb[i] != NULL) {
3284 do_fbcon_takeover(0);
3290 static void fbcon_exit(void)
3292 struct fb_info *info;
3295 if (fbcon_has_exited)
3298 for (i = 0; i < FB_MAX; i++) {
3302 info = registered_fb[i];
3307 if (info->queue.func)
3308 pending = cancel_work_sync(&info->queue);
3309 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3312 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3313 if (con2fb_map[j] == i) {
3320 if (info->fbops->fb_release)
3321 info->fbops->fb_release(info, 0);
3322 module_put(info->fbops->owner);
3324 if (info->fbcon_par) {
3325 struct fbcon_ops *ops = info->fbcon_par;
3327 fbcon_del_cursor_timer(info);
3328 kfree(ops->cursor_src);
3329 kfree(ops->cursor_state.mask);
3330 kfree(info->fbcon_par);
3331 info->fbcon_par = NULL;
3334 if (info->queue.func == fb_flashcursor)
3335 info->queue.func = NULL;
3339 fbcon_has_exited = 1;
3342 void __init fb_console_init(void)
3347 fb_register_client(&fbcon_event_notifier);
3348 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3351 if (IS_ERR(fbcon_device)) {
3352 printk(KERN_WARNING "Unable to create device "
3353 "for fbcon; errno = %ld\n",
3354 PTR_ERR(fbcon_device));
3355 fbcon_device = NULL;
3357 fbcon_init_device();
3359 for (i = 0; i < MAX_NR_CONSOLES; i++)
3368 static void __exit fbcon_deinit_device(void)
3372 if (fbcon_has_sysfs) {
3373 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3374 device_remove_file(fbcon_device, &device_attrs[i]);
3376 fbcon_has_sysfs = 0;
3380 void __exit fb_console_exit(void)
3383 fb_unregister_client(&fbcon_event_notifier);
3384 fbcon_deinit_device();
3385 device_destroy(fb_class, MKDEV(0, 0));
3387 do_unregister_con_driver(&fb_con);