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
59 #include <linux/module.h>
60 #include <linux/types.h>
62 #include <linux/kernel.h>
63 #include <linux/delay.h> /* MSch: for IRQ probe */
64 #include <linux/console.h>
65 #include <linux/string.h>
67 #include <linux/slab.h>
69 #include <linux/fbcon.h>
70 #include <linux/vt_kern.h>
71 #include <linux/selection.h>
72 #include <linux/font.h>
73 #include <linux/smp.h>
74 #include <linux/init.h>
75 #include <linux/interrupt.h>
76 #include <linux/crc32.h> /* For counting font checksums */
77 #include <linux/uaccess.h>
86 * - fbcon state itself is protected by the console_lock, and the code does a
87 * pretty good job at making sure that lock is held everywhere it's needed.
89 * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since it
90 * means concurrent access to the same fbdev from both fbcon and userspace
91 * will blow up. To fix this all fbcon calls from fbmem.c need to be moved out
92 * of fb_lock/unlock protected sections, since otherwise we'll recurse and
93 * deadlock eventually. Aside: Due to these deadlock issues the fbdev code in
94 * fbmem.c cannot use locking asserts, and there's lots of callers which get
95 * the rules wrong, e.g. fbsysfs.c entirely missed fb_lock/unlock calls too.
99 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
100 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
101 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
104 static struct fbcon_display fb_display[MAX_NR_CONSOLES];
106 struct fb_info *fbcon_registered_fb[FB_MAX];
107 int fbcon_num_registered_fb;
109 #define fbcon_for_each_registered_fb(i) \
110 for (i = 0; WARN_CONSOLE_UNLOCKED(), i < FB_MAX; i++) \
111 if (!fbcon_registered_fb[i]) {} else
113 static signed char con2fb_map[MAX_NR_CONSOLES];
114 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
116 static struct fb_info *fbcon_info_from_console(int console)
118 WARN_CONSOLE_UNLOCKED();
120 return fbcon_registered_fb[con2fb_map[console]];
123 static int logo_lines;
124 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
126 static int logo_shown = FBCON_LOGO_CANSHOW;
127 /* console mappings */
128 static unsigned int first_fb_vc;
129 static unsigned int last_fb_vc = MAX_NR_CONSOLES - 1;
130 static int fbcon_is_default = 1;
131 static int primary_device = -1;
132 static int fbcon_has_console_bind;
134 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
135 static int map_override;
137 static inline void fbcon_map_override(void)
142 static inline void fbcon_map_override(void)
145 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
147 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
148 static bool deferred_takeover = true;
150 #define deferred_takeover false
154 static char fontname[40];
156 /* current fb_info */
157 static int info_idx = -1;
159 /* console rotation */
160 static int initial_rotation = -1;
161 static int fbcon_has_sysfs;
162 static int margin_color;
164 static const struct consw fb_con;
166 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
168 static int fbcon_cursor_noblink;
170 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
173 * Interface used by the world
176 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
177 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
182 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
184 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
185 int line, int count, int dy);
186 static void fbcon_modechanged(struct fb_info *info);
187 static void fbcon_set_all_vcs(struct fb_info *info);
189 static struct device *fbcon_device;
191 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
192 static inline void fbcon_set_rotation(struct fb_info *info)
194 struct fbcon_ops *ops = info->fbcon_par;
196 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
197 ops->p->con_rotate < 4)
198 ops->rotate = ops->p->con_rotate;
203 static void fbcon_rotate(struct fb_info *info, u32 rotate)
205 struct fbcon_ops *ops= info->fbcon_par;
206 struct fb_info *fb_info;
208 if (!ops || ops->currcon == -1)
211 fb_info = fbcon_info_from_console(ops->currcon);
213 if (info == fb_info) {
214 struct fbcon_display *p = &fb_display[ops->currcon];
217 p->con_rotate = rotate;
221 fbcon_modechanged(info);
225 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
227 struct fbcon_ops *ops = info->fbcon_par;
229 struct fbcon_display *p;
232 if (!ops || ops->currcon < 0 || rotate > 3)
235 for (i = first_fb_vc; i <= last_fb_vc; i++) {
237 if (!vc || vc->vc_mode != KD_TEXT ||
238 fbcon_info_from_console(i) != info)
241 p = &fb_display[vc->vc_num];
242 p->con_rotate = rotate;
245 fbcon_set_all_vcs(info);
248 static inline void fbcon_set_rotation(struct fb_info *info)
250 struct fbcon_ops *ops = info->fbcon_par;
252 ops->rotate = FB_ROTATE_UR;
255 static void fbcon_rotate(struct fb_info *info, u32 rotate)
260 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
264 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
266 static int fbcon_get_rotate(struct fb_info *info)
268 struct fbcon_ops *ops = info->fbcon_par;
270 return (ops) ? ops->rotate : 0;
273 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
275 struct fbcon_ops *ops = info->fbcon_par;
277 return (info->state != FBINFO_STATE_RUNNING ||
278 vc->vc_mode != KD_TEXT || ops->graphics);
281 static int get_color(struct vc_data *vc, struct fb_info *info,
284 int depth = fb_get_color_depth(&info->var, &info->fix);
287 if (console_blanked) {
288 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
290 c = vc->vc_video_erase_char & charmask;
294 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
295 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
300 int col = mono_col(info);
302 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
303 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
308 color = (is_fg) ? fg : bg;
313 * Scale down 16-colors to 4 colors. Default 4-color palette
314 * is grayscale. However, simply dividing the values by 4
315 * will not work, as colors 1, 2 and 3 will be scaled-down
316 * to zero rendering them invisible. So empirically convert
317 * colors to a sane 4-level grayscale.
321 color = 0; /* black */
324 color = 2; /* white */
327 color = 1; /* gray */
330 color = 3; /* intense white */
336 * Last 8 entries of default 16-color palette is a more intense
337 * version of the first 8 (i.e., same chrominance, different
348 static void fb_flashcursor(struct work_struct *work)
350 struct fbcon_ops *ops = container_of(work, struct fbcon_ops, cursor_work.work);
351 struct fb_info *info;
352 struct vc_data *vc = NULL;
357 /* FIXME: we should sort out the unbind locking instead */
358 /* instead we just fail to flash the cursor if we can't get
359 * the lock instead of blocking fbcon deinit */
360 ret = console_trylock();
364 /* protected by console_lock */
367 if (ops->currcon != -1)
368 vc = vc_cons[ops->currcon].d;
370 if (!vc || !con_is_visible(vc) ||
371 fbcon_info_from_console(vc->vc_num) != info ||
377 c = scr_readw((u16 *) vc->vc_pos);
378 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
380 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
381 get_color(vc, info, c, 0));
384 queue_delayed_work(system_power_efficient_wq, &ops->cursor_work,
385 ops->cur_blink_jiffies);
388 static void fbcon_add_cursor_work(struct fb_info *info)
390 struct fbcon_ops *ops = info->fbcon_par;
392 if (!fbcon_cursor_noblink)
393 queue_delayed_work(system_power_efficient_wq, &ops->cursor_work,
394 ops->cur_blink_jiffies);
397 static void fbcon_del_cursor_work(struct fb_info *info)
399 struct fbcon_ops *ops = info->fbcon_par;
401 cancel_delayed_work_sync(&ops->cursor_work);
405 static int __init fb_console_setup(char *this_opt)
410 if (!this_opt || !*this_opt)
413 while ((options = strsep(&this_opt, ",")) != NULL) {
414 if (!strncmp(options, "font:", 5)) {
415 strlcpy(fontname, options + 5, sizeof(fontname));
419 if (!strncmp(options, "scrollback:", 11)) {
420 pr_warn("Ignoring scrollback size option\n");
424 if (!strncmp(options, "map:", 4)) {
427 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
431 (options[j++]-'0') % FB_MAX;
434 fbcon_map_override();
439 if (!strncmp(options, "vc:", 3)) {
442 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
443 if (first_fb_vc >= MAX_NR_CONSOLES)
445 if (*options++ == '-')
446 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
447 if (last_fb_vc < first_fb_vc || last_fb_vc >= MAX_NR_CONSOLES)
448 last_fb_vc = MAX_NR_CONSOLES - 1;
449 fbcon_is_default = 0;
453 if (!strncmp(options, "rotate:", 7)) {
456 initial_rotation = simple_strtoul(options, &options, 0);
457 if (initial_rotation > 3)
458 initial_rotation = 0;
462 if (!strncmp(options, "margin:", 7)) {
465 margin_color = simple_strtoul(options, &options, 0);
468 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
469 if (!strcmp(options, "nodefer")) {
470 deferred_takeover = false;
475 if (!strncmp(options, "logo-pos:", 9)) {
477 if (!strcmp(options, "center"))
478 fb_center_logo = true;
482 if (!strncmp(options, "logo-count:", 11)) {
485 fb_logo_count = simple_strtol(options, &options, 0);
492 __setup("fbcon=", fb_console_setup);
495 static int search_fb_in_map(int idx)
499 for (i = first_fb_vc; i <= last_fb_vc; i++) {
500 if (con2fb_map[i] == idx)
506 static int search_for_mapped_con(void)
510 for (i = first_fb_vc; i <= last_fb_vc; i++) {
511 if (con2fb_map[i] != -1)
517 static int do_fbcon_takeover(int show_logo)
521 if (!fbcon_num_registered_fb)
525 logo_shown = FBCON_LOGO_DONTSHOW;
527 for (i = first_fb_vc; i <= last_fb_vc; i++)
528 con2fb_map[i] = info_idx;
530 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
534 for (i = first_fb_vc; i <= last_fb_vc; i++)
538 fbcon_has_console_bind = 1;
545 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
546 int cols, int rows, int new_cols, int new_rows)
548 logo_shown = FBCON_LOGO_DONTSHOW;
551 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
552 int cols, int rows, int new_cols, int new_rows)
554 /* Need to make room for the logo */
555 struct fbcon_ops *ops = info->fbcon_par;
556 int cnt, erase = vc->vc_video_erase_char, step;
557 unsigned short *save = NULL, *r, *q;
560 if (info->fbops->owner) {
561 logo_shown = FBCON_LOGO_DONTSHOW;
566 * remove underline attribute from erase character
567 * if black and white framebuffer.
569 if (fb_get_color_depth(&info->var, &info->fix) == 1)
571 logo_height = fb_prepare_logo(info, ops->rotate);
572 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
573 q = (unsigned short *) (vc->vc_origin +
574 vc->vc_size_row * rows);
575 step = logo_lines * cols;
576 for (r = q - logo_lines * cols; r < q; r++)
577 if (scr_readw(r) != vc->vc_video_erase_char)
579 if (r != q && new_rows >= rows + logo_lines) {
580 save = kmalloc(array3_size(logo_lines, new_cols, 2),
583 int i = min(cols, new_cols);
584 scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
586 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
587 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
592 /* We can scroll screen down */
594 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
595 scr_memcpyw(r + step, r, vc->vc_size_row);
600 if (vc->state.y + logo_lines >= rows)
601 lines = rows - vc->state.y - 1;
604 vc->state.y += lines;
605 vc->vc_pos += lines * vc->vc_size_row;
608 scr_memsetw((unsigned short *) vc->vc_origin,
610 vc->vc_size_row * logo_lines);
612 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
613 fbcon_clear_margins(vc, 0);
618 q = (unsigned short *) (vc->vc_origin +
621 scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
622 vc->state.y += logo_lines;
623 vc->vc_pos += logo_lines * vc->vc_size_row;
627 if (logo_shown == FBCON_LOGO_DONTSHOW)
630 if (logo_lines > vc->vc_bottom) {
631 logo_shown = FBCON_LOGO_CANSHOW;
633 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
635 logo_shown = FBCON_LOGO_DRAW;
636 vc->vc_top = logo_lines;
641 #ifdef CONFIG_FB_TILEBLITTING
642 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
644 struct fbcon_ops *ops = info->fbcon_par;
646 ops->p = &fb_display[vc->vc_num];
648 if ((info->flags & FBINFO_MISC_TILEBLITTING))
649 fbcon_set_tileops(vc, info);
651 fbcon_set_rotation(info);
652 fbcon_set_bitops(ops);
656 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
660 if (info->flags & FBINFO_MISC_TILEBLITTING &&
661 info->tileops->fb_get_tilemax(info) < charcount)
667 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
669 struct fbcon_ops *ops = info->fbcon_par;
671 info->flags &= ~FBINFO_MISC_TILEBLITTING;
672 ops->p = &fb_display[vc->vc_num];
673 fbcon_set_rotation(info);
674 fbcon_set_bitops(ops);
677 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
682 #endif /* CONFIG_MISC_TILEBLITTING */
684 static void fbcon_release(struct fb_info *info)
687 if (info->fbops->fb_release)
688 info->fbops->fb_release(info, 0);
689 unlock_fb_info(info);
691 module_put(info->fbops->owner);
693 if (info->fbcon_par) {
694 struct fbcon_ops *ops = info->fbcon_par;
696 fbcon_del_cursor_work(info);
697 kfree(ops->cursor_state.mask);
698 kfree(ops->cursor_data);
699 kfree(ops->cursor_src);
700 kfree(ops->fontbuffer);
701 kfree(info->fbcon_par);
702 info->fbcon_par = NULL;
706 static int fbcon_open(struct fb_info *info)
708 struct fbcon_ops *ops;
710 if (!try_module_get(info->fbops->owner))
714 if (info->fbops->fb_open &&
715 info->fbops->fb_open(info, 0)) {
716 unlock_fb_info(info);
717 module_put(info->fbops->owner);
720 unlock_fb_info(info);
722 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
728 INIT_DELAYED_WORK(&ops->cursor_work, fb_flashcursor);
730 info->fbcon_par = ops;
731 ops->cur_blink_jiffies = HZ / 5;
736 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
741 err = fbcon_open(info);
746 set_blitting_type(vc, info);
751 static void con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
752 struct fb_info *newinfo)
756 fbcon_release(oldinfo);
759 If oldinfo and newinfo are driving the same hardware,
760 the fb_release() method of oldinfo may attempt to
761 restore the hardware state. This will leave the
762 newinfo in an undefined state. Thus, a call to
763 fb_set_par() may be needed for the newinfo.
765 if (newinfo && newinfo->fbops->fb_set_par) {
766 ret = newinfo->fbops->fb_set_par(newinfo);
769 printk(KERN_ERR "con2fb_release_oldinfo: "
770 "detected unhandled fb_set_par error, "
771 "error code %d\n", ret);
775 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
776 int unit, int show_logo)
778 struct fbcon_ops *ops = info->fbcon_par;
781 ops->currcon = fg_console;
783 if (info->fbops->fb_set_par && !ops->initialized) {
784 ret = info->fbops->fb_set_par(info);
787 printk(KERN_ERR "con2fb_init_display: detected "
788 "unhandled fb_set_par error, "
789 "error code %d\n", ret);
792 ops->initialized = true;
794 fbcon_set_disp(info, &info->var, unit);
797 struct vc_data *fg_vc = vc_cons[fg_console].d;
798 struct fb_info *fg_info =
799 fbcon_info_from_console(fg_console);
801 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
802 fg_vc->vc_rows, fg_vc->vc_cols,
806 update_screen(vc_cons[fg_console].d);
810 * set_con2fb_map - map console to frame buffer device
811 * @unit: virtual console number to map
812 * @newidx: frame buffer index to map virtual console to
813 * @user: user request
815 * Maps a virtual console @unit to a frame buffer device
818 * This should be called with the console lock held.
820 static int set_con2fb_map(int unit, int newidx, int user)
822 struct vc_data *vc = vc_cons[unit].d;
823 int oldidx = con2fb_map[unit];
824 struct fb_info *info = fbcon_registered_fb[newidx];
825 struct fb_info *oldinfo = NULL;
826 int found, err = 0, show_logo;
828 WARN_CONSOLE_UNLOCKED();
830 if (oldidx == newidx)
836 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
838 return do_fbcon_takeover(0);
842 oldinfo = fbcon_registered_fb[oldidx];
844 found = search_fb_in_map(newidx);
846 if (!err && !found) {
847 err = con2fb_acquire_newinfo(vc, info, unit);
849 con2fb_map[unit] = newidx;
853 * If old fb is not mapped to any of the consoles,
854 * fbcon should release it.
856 if (!err && oldinfo && !search_fb_in_map(oldidx))
857 con2fb_release_oldinfo(vc, oldinfo, info);
859 show_logo = (fg_console == 0 && !user &&
860 logo_shown != FBCON_LOGO_DONTSHOW);
863 fbcon_add_cursor_work(info);
864 con2fb_map_boot[unit] = newidx;
865 con2fb_init_display(vc, info, unit, show_logo);
867 if (!search_fb_in_map(info_idx))
874 * Low Level Operations
876 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
877 static int var_to_display(struct fbcon_display *disp,
878 struct fb_var_screeninfo *var,
879 struct fb_info *info)
881 disp->xres_virtual = var->xres_virtual;
882 disp->yres_virtual = var->yres_virtual;
883 disp->bits_per_pixel = var->bits_per_pixel;
884 disp->grayscale = var->grayscale;
885 disp->nonstd = var->nonstd;
886 disp->accel_flags = var->accel_flags;
887 disp->height = var->height;
888 disp->width = var->width;
889 disp->red = var->red;
890 disp->green = var->green;
891 disp->blue = var->blue;
892 disp->transp = var->transp;
893 disp->rotate = var->rotate;
894 disp->mode = fb_match_mode(var, &info->modelist);
895 if (disp->mode == NULL)
896 /* This should not happen */
901 static void display_to_var(struct fb_var_screeninfo *var,
902 struct fbcon_display *disp)
904 fb_videomode_to_var(var, disp->mode);
905 var->xres_virtual = disp->xres_virtual;
906 var->yres_virtual = disp->yres_virtual;
907 var->bits_per_pixel = disp->bits_per_pixel;
908 var->grayscale = disp->grayscale;
909 var->nonstd = disp->nonstd;
910 var->accel_flags = disp->accel_flags;
911 var->height = disp->height;
912 var->width = disp->width;
913 var->red = disp->red;
914 var->green = disp->green;
915 var->blue = disp->blue;
916 var->transp = disp->transp;
917 var->rotate = disp->rotate;
920 static const char *fbcon_startup(void)
922 const char *display_desc = "frame buffer device";
923 struct fbcon_display *p = &fb_display[fg_console];
924 struct vc_data *vc = vc_cons[fg_console].d;
925 const struct font_desc *font = NULL;
926 struct fb_info *info = NULL;
927 struct fbcon_ops *ops;
931 * If num_registered_fb is zero, this is a call for the dummy part.
932 * The frame buffer devices weren't initialized yet.
934 if (!fbcon_num_registered_fb || info_idx == -1)
937 * Instead of blindly using registered_fb[0], we use info_idx, set by
938 * fbcon_fb_registered();
940 info = fbcon_registered_fb[info_idx];
944 if (fbcon_open(info))
947 ops = info->fbcon_par;
950 ops->cur_rotate = -1;
952 p->con_rotate = initial_rotation;
953 if (p->con_rotate == -1)
954 p->con_rotate = info->fbcon_rotate_hint;
955 if (p->con_rotate == -1)
956 p->con_rotate = FB_ROTATE_UR;
958 set_blitting_type(vc, info);
960 /* Setup default font */
961 if (!p->fontdata && !vc->vc_font.data) {
962 if (!fontname[0] || !(font = find_font(fontname)))
963 font = get_default_font(info->var.xres,
966 info->pixmap.blit_y);
967 vc->vc_font.width = font->width;
968 vc->vc_font.height = font->height;
969 vc->vc_font.data = (void *)(p->fontdata = font->data);
970 vc->vc_font.charcount = font->charcount;
972 p->fontdata = vc->vc_font.data;
975 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
976 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
977 cols /= vc->vc_font.width;
978 rows /= vc->vc_font.height;
979 vc_resize(vc, cols, rows);
981 pr_debug("mode: %s\n", info->fix.id);
982 pr_debug("visual: %d\n", info->fix.visual);
983 pr_debug("res: %dx%d-%d\n", info->var.xres,
985 info->var.bits_per_pixel);
987 fbcon_add_cursor_work(info);
991 static void fbcon_init(struct vc_data *vc, int init)
993 struct fb_info *info;
994 struct fbcon_ops *ops;
995 struct vc_data **default_mode = vc->vc_display_fg;
996 struct vc_data *svc = *default_mode;
997 struct fbcon_display *t, *p = &fb_display[vc->vc_num];
998 int logo = 1, new_rows, new_cols, rows, cols;
1001 if (WARN_ON(info_idx == -1))
1004 if (con2fb_map[vc->vc_num] == -1)
1005 con2fb_map[vc->vc_num] = info_idx;
1007 info = fbcon_info_from_console(vc->vc_num);
1009 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1010 logo_shown = FBCON_LOGO_DONTSHOW;
1012 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1013 (info->fix.type == FB_TYPE_TEXT))
1016 if (var_to_display(p, &info->var, info))
1019 if (!info->fbcon_par)
1020 con2fb_acquire_newinfo(vc, info, vc->vc_num);
1022 /* If we are not the first console on this
1023 fb, copy the font from that console */
1024 t = &fb_display[fg_console];
1027 struct vc_data *fvc = vc_cons[fg_console].d;
1029 vc->vc_font.data = (void *)(p->fontdata =
1031 vc->vc_font.width = fvc->vc_font.width;
1032 vc->vc_font.height = fvc->vc_font.height;
1033 vc->vc_font.charcount = fvc->vc_font.charcount;
1034 p->userfont = t->userfont;
1037 REFCOUNT(p->fontdata)++;
1039 const struct font_desc *font = NULL;
1041 if (!fontname[0] || !(font = find_font(fontname)))
1042 font = get_default_font(info->var.xres,
1044 info->pixmap.blit_x,
1045 info->pixmap.blit_y);
1046 vc->vc_font.width = font->width;
1047 vc->vc_font.height = font->height;
1048 vc->vc_font.data = (void *)(p->fontdata = font->data);
1049 vc->vc_font.charcount = font->charcount;
1053 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1054 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1055 if (vc->vc_font.charcount == 256) {
1056 vc->vc_hi_font_mask = 0;
1058 vc->vc_hi_font_mask = 0x100;
1059 if (vc->vc_can_do_color)
1060 vc->vc_complement_mask <<= 1;
1063 if (!*svc->vc_uni_pagedir_loc)
1064 con_set_default_unimap(svc);
1065 if (!*vc->vc_uni_pagedir_loc)
1066 con_copy_unimap(vc, svc);
1068 ops = info->fbcon_par;
1069 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1071 p->con_rotate = initial_rotation;
1072 if (p->con_rotate == -1)
1073 p->con_rotate = info->fbcon_rotate_hint;
1074 if (p->con_rotate == -1)
1075 p->con_rotate = FB_ROTATE_UR;
1077 set_blitting_type(vc, info);
1081 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1082 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1083 new_cols /= vc->vc_font.width;
1084 new_rows /= vc->vc_font.height;
1087 * We must always set the mode. The mode of the previous console
1088 * driver could be in the same resolution but we are using different
1089 * hardware so we have to initialize the hardware.
1091 * We need to do it in fbcon_init() to prevent screen corruption.
1093 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1094 if (info->fbops->fb_set_par && !ops->initialized) {
1095 ret = info->fbops->fb_set_par(info);
1098 printk(KERN_ERR "fbcon_init: detected "
1099 "unhandled fb_set_par error, "
1100 "error code %d\n", ret);
1103 ops->initialized = true;
1108 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1109 if ((info->flags & FBINFO_HWACCEL_COPYAREA) &&
1110 !(info->flags & FBINFO_HWACCEL_DISABLED))
1111 p->scrollmode = SCROLL_MOVE;
1112 else /* default to something safe */
1113 p->scrollmode = SCROLL_REDRAW;
1117 * ++guenther: console.c:vc_allocate() relies on initializing
1118 * vc_{cols,rows}, but we must not set those if we are only
1119 * resizing the console.
1122 vc->vc_cols = new_cols;
1123 vc->vc_rows = new_rows;
1125 vc_resize(vc, new_cols, new_rows);
1128 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1130 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1131 ops->rotate = FB_ROTATE_UR;
1132 set_blitting_type(vc, info);
1135 ops->p = &fb_display[fg_console];
1138 static void fbcon_free_font(struct fbcon_display *p, bool freefont)
1140 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1141 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1146 static void set_vc_hi_font(struct vc_data *vc, bool set);
1148 static void fbcon_release_all(void)
1150 struct fb_info *info;
1153 fbcon_for_each_registered_fb(i) {
1155 info = fbcon_registered_fb[i];
1157 for (j = first_fb_vc; j <= last_fb_vc; j++) {
1158 if (con2fb_map[j] == i) {
1165 fbcon_release(info);
1169 static void fbcon_deinit(struct vc_data *vc)
1171 struct fbcon_display *p = &fb_display[vc->vc_num];
1172 struct fb_info *info;
1173 struct fbcon_ops *ops;
1175 bool free_font = true;
1177 idx = con2fb_map[vc->vc_num];
1182 info = fbcon_registered_fb[idx];
1187 if (info->flags & FBINFO_MISC_FIRMWARE)
1189 ops = info->fbcon_par;
1194 if (con_is_visible(vc))
1195 fbcon_del_cursor_work(info);
1197 ops->initialized = false;
1200 fbcon_free_font(p, free_font);
1202 vc->vc_font.data = NULL;
1204 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1205 set_vc_hi_font(vc, false);
1207 if (!con_is_bound(&fb_con))
1208 fbcon_release_all();
1210 if (vc->vc_num == logo_shown)
1211 logo_shown = FBCON_LOGO_CANSHOW;
1216 /* ====================================================================== */
1218 /* fbcon_XXX routines - interface used by the world
1220 * This system is now divided into two levels because of complications
1221 * caused by hardware scrolling. Top level functions:
1223 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1225 * handles y values in range [0, scr_height-1] that correspond to real
1226 * screen positions. y_wrap shift means that first line of bitmap may be
1227 * anywhere on this display. These functions convert lineoffsets to
1228 * bitmap offsets and deal with the wrap-around case by splitting blits.
1230 * fbcon_bmove_physical_8() -- These functions fast implementations
1231 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1232 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1236 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1237 * Implies should only really hardware scroll in rows. Only reason for
1238 * restriction is simplicity & efficiency at the moment.
1241 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1244 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1245 struct fbcon_ops *ops = info->fbcon_par;
1247 struct fbcon_display *p = &fb_display[vc->vc_num];
1250 if (fbcon_is_inactive(vc, info))
1253 if (!height || !width)
1256 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1259 * If the font dimensions are not an integral of the display
1260 * dimensions then the ops->clear below won't end up clearing
1261 * the margins. Call clear_margins here in case the logo
1262 * bitmap stretched into the margin area.
1264 fbcon_clear_margins(vc, 0);
1267 /* Split blits that cross physical y_wrap boundary */
1269 y_break = p->vrows - p->yscroll;
1270 if (sy < y_break && sy + height - 1 >= y_break) {
1271 u_int b = y_break - sy;
1272 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1273 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1276 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1279 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1280 int count, int ypos, int xpos)
1282 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1283 struct fbcon_display *p = &fb_display[vc->vc_num];
1284 struct fbcon_ops *ops = info->fbcon_par;
1286 if (!fbcon_is_inactive(vc, info))
1287 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1288 get_color(vc, info, scr_readw(s), 1),
1289 get_color(vc, info, scr_readw(s), 0));
1292 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1296 scr_writew(c, &chr);
1297 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1300 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1302 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1303 struct fbcon_ops *ops = info->fbcon_par;
1305 if (!fbcon_is_inactive(vc, info))
1306 ops->clear_margins(vc, info, margin_color, bottom_only);
1309 static void fbcon_cursor(struct vc_data *vc, int mode)
1311 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1312 struct fbcon_ops *ops = info->fbcon_par;
1313 int c = scr_readw((u16 *) vc->vc_pos);
1315 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1317 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1320 if (vc->vc_cursor_type & CUR_SW)
1321 fbcon_del_cursor_work(info);
1323 fbcon_add_cursor_work(info);
1325 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1330 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1331 get_color(vc, info, c, 0));
1334 static int scrollback_phys_max = 0;
1335 static int scrollback_max = 0;
1336 static int scrollback_current = 0;
1338 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1341 struct fbcon_display *p, *t;
1342 struct vc_data **default_mode, *vc;
1343 struct vc_data *svc;
1344 struct fbcon_ops *ops = info->fbcon_par;
1347 p = &fb_display[unit];
1349 if (var_to_display(p, var, info))
1352 vc = vc_cons[unit].d;
1357 default_mode = vc->vc_display_fg;
1358 svc = *default_mode;
1359 t = &fb_display[svc->vc_num];
1361 if (!vc->vc_font.data) {
1362 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1363 vc->vc_font.width = (*default_mode)->vc_font.width;
1364 vc->vc_font.height = (*default_mode)->vc_font.height;
1365 vc->vc_font.charcount = (*default_mode)->vc_font.charcount;
1366 p->userfont = t->userfont;
1368 REFCOUNT(p->fontdata)++;
1371 var->activate = FB_ACTIVATE_NOW;
1372 info->var.activate = var->activate;
1373 var->yoffset = info->var.yoffset;
1374 var->xoffset = info->var.xoffset;
1375 fb_set_var(info, var);
1376 ops->var = info->var;
1377 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1378 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1379 if (vc->vc_font.charcount == 256) {
1380 vc->vc_hi_font_mask = 0;
1382 vc->vc_hi_font_mask = 0x100;
1383 if (vc->vc_can_do_color)
1384 vc->vc_complement_mask <<= 1;
1387 if (!*svc->vc_uni_pagedir_loc)
1388 con_set_default_unimap(svc);
1389 if (!*vc->vc_uni_pagedir_loc)
1390 con_copy_unimap(vc, svc);
1392 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1393 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1394 cols /= vc->vc_font.width;
1395 rows /= vc->vc_font.height;
1396 vc_resize(vc, cols, rows);
1398 if (con_is_visible(vc)) {
1403 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1405 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1406 struct fbcon_ops *ops = info->fbcon_par;
1407 struct fbcon_display *p = &fb_display[vc->vc_num];
1409 p->yscroll += count;
1410 if (p->yscroll >= p->vrows) /* Deal with wrap */
1411 p->yscroll -= p->vrows;
1412 ops->var.xoffset = 0;
1413 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1414 ops->var.vmode |= FB_VMODE_YWRAP;
1415 ops->update_start(info);
1416 scrollback_max += count;
1417 if (scrollback_max > scrollback_phys_max)
1418 scrollback_max = scrollback_phys_max;
1419 scrollback_current = 0;
1422 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1424 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1425 struct fbcon_ops *ops = info->fbcon_par;
1426 struct fbcon_display *p = &fb_display[vc->vc_num];
1428 p->yscroll -= count;
1429 if (p->yscroll < 0) /* Deal with wrap */
1430 p->yscroll += p->vrows;
1431 ops->var.xoffset = 0;
1432 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1433 ops->var.vmode |= FB_VMODE_YWRAP;
1434 ops->update_start(info);
1435 scrollback_max -= count;
1436 if (scrollback_max < 0)
1438 scrollback_current = 0;
1441 static __inline__ void ypan_up(struct vc_data *vc, int count)
1443 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1444 struct fbcon_display *p = &fb_display[vc->vc_num];
1445 struct fbcon_ops *ops = info->fbcon_par;
1447 p->yscroll += count;
1448 if (p->yscroll > p->vrows - vc->vc_rows) {
1449 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1450 0, 0, 0, vc->vc_rows, vc->vc_cols);
1451 p->yscroll -= p->vrows - vc->vc_rows;
1454 ops->var.xoffset = 0;
1455 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1456 ops->var.vmode &= ~FB_VMODE_YWRAP;
1457 ops->update_start(info);
1458 fbcon_clear_margins(vc, 1);
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 ypan_up_redraw(struct vc_data *vc, int t, int count)
1467 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1468 struct fbcon_ops *ops = info->fbcon_par;
1469 struct fbcon_display *p = &fb_display[vc->vc_num];
1471 p->yscroll += count;
1473 if (p->yscroll > p->vrows - vc->vc_rows) {
1474 p->yscroll -= p->vrows - vc->vc_rows;
1475 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1478 ops->var.xoffset = 0;
1479 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1480 ops->var.vmode &= ~FB_VMODE_YWRAP;
1481 ops->update_start(info);
1482 fbcon_clear_margins(vc, 1);
1483 scrollback_max += count;
1484 if (scrollback_max > scrollback_phys_max)
1485 scrollback_max = scrollback_phys_max;
1486 scrollback_current = 0;
1489 static __inline__ void ypan_down(struct vc_data *vc, int count)
1491 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1492 struct fbcon_display *p = &fb_display[vc->vc_num];
1493 struct fbcon_ops *ops = info->fbcon_par;
1495 p->yscroll -= count;
1496 if (p->yscroll < 0) {
1497 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1498 0, vc->vc_rows, vc->vc_cols);
1499 p->yscroll += p->vrows - vc->vc_rows;
1502 ops->var.xoffset = 0;
1503 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1504 ops->var.vmode &= ~FB_VMODE_YWRAP;
1505 ops->update_start(info);
1506 fbcon_clear_margins(vc, 1);
1507 scrollback_max -= count;
1508 if (scrollback_max < 0)
1510 scrollback_current = 0;
1513 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1515 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1516 struct fbcon_ops *ops = info->fbcon_par;
1517 struct fbcon_display *p = &fb_display[vc->vc_num];
1519 p->yscroll -= count;
1521 if (p->yscroll < 0) {
1522 p->yscroll += p->vrows - vc->vc_rows;
1523 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1526 ops->var.xoffset = 0;
1527 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1528 ops->var.vmode &= ~FB_VMODE_YWRAP;
1529 ops->update_start(info);
1530 fbcon_clear_margins(vc, 1);
1531 scrollback_max -= count;
1532 if (scrollback_max < 0)
1534 scrollback_current = 0;
1537 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
1538 int line, int count, int dy)
1540 unsigned short *s = (unsigned short *)
1541 (vc->vc_origin + vc->vc_size_row * line);
1544 unsigned short *start = s;
1545 unsigned short *le = advance_row(s, 1);
1548 unsigned short attr = 1;
1552 if (attr != (c & 0xff00)) {
1555 fbcon_putcs(vc, start, s - start,
1561 console_conditional_schedule();
1565 fbcon_putcs(vc, start, s - start, dy, x);
1566 console_conditional_schedule();
1571 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1572 struct fbcon_display *p, int line, int count, int ycount)
1574 int offset = ycount * vc->vc_cols;
1575 unsigned short *d = (unsigned short *)
1576 (vc->vc_origin + vc->vc_size_row * line);
1577 unsigned short *s = d + offset;
1578 struct fbcon_ops *ops = info->fbcon_par;
1581 unsigned short *start = s;
1582 unsigned short *le = advance_row(s, 1);
1589 if (c == scr_readw(d)) {
1591 ops->bmove(vc, info, line + ycount, x,
1592 line, x, 1, s-start);
1602 console_conditional_schedule();
1607 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1609 console_conditional_schedule();
1614 /* NOTE: We subtract two lines from these pointers */
1615 s -= vc->vc_size_row;
1616 d -= vc->vc_size_row;
1621 static void fbcon_redraw(struct vc_data *vc, struct fbcon_display *p,
1622 int line, int count, int offset)
1624 unsigned short *d = (unsigned short *)
1625 (vc->vc_origin + vc->vc_size_row * line);
1626 unsigned short *s = d + offset;
1629 unsigned short *start = s;
1630 unsigned short *le = advance_row(s, 1);
1633 unsigned short attr = 1;
1637 if (attr != (c & 0xff00)) {
1640 fbcon_putcs(vc, start, s - start,
1646 if (c == scr_readw(d)) {
1648 fbcon_putcs(vc, start, s - start,
1658 console_conditional_schedule();
1663 fbcon_putcs(vc, start, s - start, line, x);
1664 console_conditional_schedule();
1669 /* NOTE: We subtract two lines from these pointers */
1670 s -= vc->vc_size_row;
1671 d -= vc->vc_size_row;
1676 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
1677 int dy, int dx, int height, int width, u_int y_break)
1679 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1680 struct fbcon_ops *ops = info->fbcon_par;
1683 if (sy < y_break && sy + height > y_break) {
1685 if (dy < sy) { /* Avoid trashing self */
1686 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1688 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1689 height - b, width, y_break);
1691 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1692 height - b, width, y_break);
1693 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1699 if (dy < y_break && dy + height > y_break) {
1701 if (dy < sy) { /* Avoid trashing self */
1702 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1704 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1705 height - b, width, y_break);
1707 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1708 height - b, width, y_break);
1709 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1714 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1718 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1719 int height, int width)
1721 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1722 struct fbcon_display *p = &fb_display[vc->vc_num];
1724 if (fbcon_is_inactive(vc, info))
1727 if (!width || !height)
1730 /* Split blits that cross physical y_wrap case.
1731 * Pathological case involves 4 blits, better to use recursive
1732 * code rather than unrolled case
1734 * Recursive invocations don't need to erase the cursor over and
1735 * over again, so we use fbcon_bmove_rec()
1737 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1738 p->vrows - p->yscroll);
1741 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1742 enum con_scroll dir, unsigned int count)
1744 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
1745 struct fbcon_display *p = &fb_display[vc->vc_num];
1746 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1748 if (fbcon_is_inactive(vc, info))
1751 fbcon_cursor(vc, CM_ERASE);
1754 * ++Geert: Only use ywrap/ypan if the console is in text mode
1755 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1756 * whole screen (prevents flicker).
1761 if (count > vc->vc_rows) /* Maximum realistic size */
1762 count = vc->vc_rows;
1763 switch (fb_scrollmode(p)) {
1765 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1767 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1768 scr_memsetw((unsigned short *) (vc->vc_origin +
1771 vc->vc_video_erase_char,
1772 vc->vc_size_row * count);
1775 case SCROLL_WRAP_MOVE:
1776 if (b - t - count > 3 * vc->vc_rows >> 2) {
1778 fbcon_bmove(vc, 0, 0, count, 0, t,
1780 ywrap_up(vc, count);
1781 if (vc->vc_rows - b > 0)
1782 fbcon_bmove(vc, b - count, 0, b, 0,
1785 } else if (info->flags & FBINFO_READS_FAST)
1786 fbcon_bmove(vc, t + count, 0, t, 0,
1787 b - t - count, vc->vc_cols);
1790 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1793 case SCROLL_PAN_REDRAW:
1794 if ((p->yscroll + count <=
1795 2 * (p->vrows - vc->vc_rows))
1796 && ((!scroll_partial && (b - t == vc->vc_rows))
1799 3 * vc->vc_rows >> 2)))) {
1801 fbcon_redraw_move(vc, p, 0, t, count);
1802 ypan_up_redraw(vc, t, count);
1803 if (vc->vc_rows - b > 0)
1804 fbcon_redraw_move(vc, p, b,
1805 vc->vc_rows - b, b);
1807 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1808 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1811 case SCROLL_PAN_MOVE:
1812 if ((p->yscroll + count <=
1813 2 * (p->vrows - vc->vc_rows))
1814 && ((!scroll_partial && (b - t == vc->vc_rows))
1817 3 * vc->vc_rows >> 2)))) {
1819 fbcon_bmove(vc, 0, 0, count, 0, t,
1822 if (vc->vc_rows - b > 0)
1823 fbcon_bmove(vc, b - count, 0, b, 0,
1826 } else if (info->flags & FBINFO_READS_FAST)
1827 fbcon_bmove(vc, t + count, 0, t, 0,
1828 b - t - count, vc->vc_cols);
1831 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1836 fbcon_redraw(vc, p, t, b - t - count,
1837 count * vc->vc_cols);
1838 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1839 scr_memsetw((unsigned short *) (vc->vc_origin +
1842 vc->vc_video_erase_char,
1843 vc->vc_size_row * count);
1849 if (count > vc->vc_rows) /* Maximum realistic size */
1850 count = vc->vc_rows;
1851 switch (fb_scrollmode(p)) {
1853 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1855 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1856 scr_memsetw((unsigned short *) (vc->vc_origin +
1859 vc->vc_video_erase_char,
1860 vc->vc_size_row * count);
1863 case SCROLL_WRAP_MOVE:
1864 if (b - t - count > 3 * vc->vc_rows >> 2) {
1865 if (vc->vc_rows - b > 0)
1866 fbcon_bmove(vc, b, 0, b - count, 0,
1869 ywrap_down(vc, count);
1871 fbcon_bmove(vc, count, 0, 0, 0, t,
1873 } else if (info->flags & FBINFO_READS_FAST)
1874 fbcon_bmove(vc, t, 0, t + count, 0,
1875 b - t - count, vc->vc_cols);
1878 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1881 case SCROLL_PAN_MOVE:
1882 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1883 && ((!scroll_partial && (b - t == vc->vc_rows))
1886 3 * vc->vc_rows >> 2)))) {
1887 if (vc->vc_rows - b > 0)
1888 fbcon_bmove(vc, b, 0, b - count, 0,
1891 ypan_down(vc, count);
1893 fbcon_bmove(vc, count, 0, 0, 0, t,
1895 } else if (info->flags & FBINFO_READS_FAST)
1896 fbcon_bmove(vc, t, 0, t + count, 0,
1897 b - t - count, vc->vc_cols);
1900 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1903 case SCROLL_PAN_REDRAW:
1904 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1905 && ((!scroll_partial && (b - t == vc->vc_rows))
1908 3 * vc->vc_rows >> 2)))) {
1909 if (vc->vc_rows - b > 0)
1910 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1912 ypan_down_redraw(vc, t, count);
1914 fbcon_redraw_move(vc, p, count, t, 0);
1916 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1917 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1922 fbcon_redraw(vc, p, b - 1, b - t - count,
1923 -count * vc->vc_cols);
1924 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1925 scr_memsetw((unsigned short *) (vc->vc_origin +
1928 vc->vc_video_erase_char,
1929 vc->vc_size_row * count);
1937 static void updatescrollmode_accel(struct fbcon_display *p,
1938 struct fb_info *info,
1941 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1942 struct fbcon_ops *ops = info->fbcon_par;
1943 int cap = info->flags;
1945 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1946 info->fix.xpanstep);
1947 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1948 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1949 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1950 info->var.xres_virtual);
1951 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1952 divides(ypan, vc->vc_font.height) && vyres > yres;
1953 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1954 divides(ywrap, vc->vc_font.height) &&
1955 divides(vc->vc_font.height, vyres) &&
1956 divides(vc->vc_font.height, yres);
1957 int reading_fast = cap & FBINFO_READS_FAST;
1958 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1959 !(cap & FBINFO_HWACCEL_DISABLED);
1960 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1961 !(cap & FBINFO_HWACCEL_DISABLED);
1963 if (good_wrap || good_pan) {
1964 if (reading_fast || fast_copyarea)
1965 p->scrollmode = good_wrap ?
1966 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1968 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1971 if (reading_fast || (fast_copyarea && !fast_imageblit))
1972 p->scrollmode = SCROLL_MOVE;
1974 p->scrollmode = SCROLL_REDRAW;
1979 static void updatescrollmode(struct fbcon_display *p,
1980 struct fb_info *info,
1983 struct fbcon_ops *ops = info->fbcon_par;
1984 int fh = vc->vc_font.height;
1985 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1986 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1987 info->var.xres_virtual);
1989 p->vrows = vyres/fh;
1990 if (yres > (fh * (vc->vc_rows + 1)))
1991 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1992 if ((yres % fh) && (vyres % fh < yres % fh))
1995 /* update scrollmode in case hardware acceleration is used */
1996 updatescrollmode_accel(p, info, vc);
1999 #define PITCH(w) (((w) + 7) >> 3)
2000 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
2002 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2003 unsigned int height, unsigned int user)
2005 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2006 struct fbcon_ops *ops = info->fbcon_par;
2007 struct fbcon_display *p = &fb_display[vc->vc_num];
2008 struct fb_var_screeninfo var = info->var;
2009 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2011 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
2013 int pitch = PITCH(vc->vc_font.width);
2016 * If user font, ensure that a possible change to user font
2017 * height or width will not allow a font data out-of-bounds access.
2018 * NOTE: must use original charcount in calculation as font
2019 * charcount can change and cannot be used to determine the
2020 * font data allocated size.
2024 size = CALC_FONTSZ(vc->vc_font.height, pitch, vc->vc_font.charcount);
2025 if (size > FNTSIZE(vc->vc_font.data))
2029 virt_w = FBCON_SWAP(ops->rotate, width, height);
2030 virt_h = FBCON_SWAP(ops->rotate, height, width);
2031 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2032 vc->vc_font.height);
2033 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2035 var.xres = virt_w * virt_fw;
2036 var.yres = virt_h * virt_fh;
2037 x_diff = info->var.xres - var.xres;
2038 y_diff = info->var.yres - var.yres;
2039 if (x_diff < 0 || x_diff > virt_fw ||
2040 y_diff < 0 || y_diff > virt_fh) {
2041 const struct fb_videomode *mode;
2043 pr_debug("attempting resize %ix%i\n", var.xres, var.yres);
2044 mode = fb_find_best_mode(&var, &info->modelist);
2047 display_to_var(&var, p);
2048 fb_videomode_to_var(&var, mode);
2050 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2053 pr_debug("resize now %ix%i\n", var.xres, var.yres);
2054 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
2055 var.activate = FB_ACTIVATE_NOW |
2057 fb_set_var(info, &var);
2059 var_to_display(p, &info->var, info);
2060 ops->var = info->var;
2062 updatescrollmode(p, info, vc);
2066 static int fbcon_switch(struct vc_data *vc)
2068 struct fb_info *info, *old_info = NULL;
2069 struct fbcon_ops *ops;
2070 struct fbcon_display *p = &fb_display[vc->vc_num];
2071 struct fb_var_screeninfo var;
2072 int i, ret, prev_console;
2074 info = fbcon_info_from_console(vc->vc_num);
2075 ops = info->fbcon_par;
2077 if (logo_shown >= 0) {
2078 struct vc_data *conp2 = vc_cons[logo_shown].d;
2080 if (conp2->vc_top == logo_lines
2081 && conp2->vc_bottom == conp2->vc_rows)
2083 logo_shown = FBCON_LOGO_CANSHOW;
2086 prev_console = ops->currcon;
2087 if (prev_console != -1)
2088 old_info = fbcon_info_from_console(prev_console);
2090 * FIXME: If we have multiple fbdev's loaded, we need to
2091 * update all info->currcon. Perhaps, we can place this
2092 * in a centralized structure, but this might break some
2095 * info->currcon = vc->vc_num;
2097 fbcon_for_each_registered_fb(i) {
2098 if (fbcon_registered_fb[i]->fbcon_par) {
2099 struct fbcon_ops *o = fbcon_registered_fb[i]->fbcon_par;
2101 o->currcon = vc->vc_num;
2104 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2105 display_to_var(&var, p);
2106 var.activate = FB_ACTIVATE_NOW;
2109 * make sure we don't unnecessarily trip the memcmp()
2112 info->var.activate = var.activate;
2113 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2114 fb_set_var(info, &var);
2115 ops->var = info->var;
2117 if (old_info != NULL && (old_info != info ||
2118 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2119 if (info->fbops->fb_set_par) {
2120 ret = info->fbops->fb_set_par(info);
2123 printk(KERN_ERR "fbcon_switch: detected "
2124 "unhandled fb_set_par error, "
2125 "error code %d\n", ret);
2128 if (old_info != info)
2129 fbcon_del_cursor_work(old_info);
2132 if (fbcon_is_inactive(vc, info) ||
2133 ops->blank_state != FB_BLANK_UNBLANK)
2134 fbcon_del_cursor_work(info);
2136 fbcon_add_cursor_work(info);
2138 set_blitting_type(vc, info);
2139 ops->cursor_reset = 1;
2141 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2142 ops->rotate = FB_ROTATE_UR;
2143 set_blitting_type(vc, info);
2146 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2147 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2149 if (vc->vc_font.charcount > 256)
2150 vc->vc_complement_mask <<= 1;
2152 updatescrollmode(p, info, vc);
2154 switch (fb_scrollmode(p)) {
2155 case SCROLL_WRAP_MOVE:
2156 scrollback_phys_max = p->vrows - vc->vc_rows;
2158 case SCROLL_PAN_MOVE:
2159 case SCROLL_PAN_REDRAW:
2160 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2161 if (scrollback_phys_max < 0)
2162 scrollback_phys_max = 0;
2165 scrollback_phys_max = 0;
2170 scrollback_current = 0;
2172 if (!fbcon_is_inactive(vc, info)) {
2173 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2174 ops->update_start(info);
2177 fbcon_set_palette(vc, color_table);
2178 fbcon_clear_margins(vc, 0);
2180 if (logo_shown == FBCON_LOGO_DRAW) {
2182 logo_shown = fg_console;
2183 fb_show_logo(info, ops->rotate);
2185 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2186 vc->vc_size_row * (vc->vc_bottom -
2193 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2197 unsigned short charmask = vc->vc_hi_font_mask ?
2199 unsigned short oldc;
2201 oldc = vc->vc_video_erase_char;
2202 vc->vc_video_erase_char &= charmask;
2203 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2204 vc->vc_video_erase_char = oldc;
2208 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2210 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2211 struct fbcon_ops *ops = info->fbcon_par;
2214 struct fb_var_screeninfo var = info->var;
2219 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE |
2220 FB_ACTIVATE_KD_TEXT;
2221 fb_set_var(info, &var);
2223 ops->var = info->var;
2227 if (!fbcon_is_inactive(vc, info)) {
2228 if (ops->blank_state != blank) {
2229 ops->blank_state = blank;
2230 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2231 ops->cursor_flash = (!blank);
2233 if (fb_blank(info, blank))
2234 fbcon_generic_blank(vc, info, blank);
2241 if (mode_switch || fbcon_is_inactive(vc, info) ||
2242 ops->blank_state != FB_BLANK_UNBLANK)
2243 fbcon_del_cursor_work(info);
2245 fbcon_add_cursor_work(info);
2250 static int fbcon_debug_enter(struct vc_data *vc)
2252 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2253 struct fbcon_ops *ops = info->fbcon_par;
2255 ops->save_graphics = ops->graphics;
2257 if (info->fbops->fb_debug_enter)
2258 info->fbops->fb_debug_enter(info);
2259 fbcon_set_palette(vc, color_table);
2263 static int fbcon_debug_leave(struct vc_data *vc)
2265 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2266 struct fbcon_ops *ops = info->fbcon_par;
2268 ops->graphics = ops->save_graphics;
2269 if (info->fbops->fb_debug_leave)
2270 info->fbops->fb_debug_leave(info);
2274 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2276 u8 *fontdata = vc->vc_font.data;
2277 u8 *data = font->data;
2280 font->width = vc->vc_font.width;
2281 font->height = vc->vc_font.height;
2282 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2286 if (font->width <= 8) {
2287 j = vc->vc_font.height;
2288 if (font->charcount * j > FNTSIZE(fontdata))
2291 for (i = 0; i < font->charcount; i++) {
2292 memcpy(data, fontdata, j);
2293 memset(data + j, 0, 32 - j);
2297 } else if (font->width <= 16) {
2298 j = vc->vc_font.height * 2;
2299 if (font->charcount * j > FNTSIZE(fontdata))
2302 for (i = 0; i < font->charcount; i++) {
2303 memcpy(data, fontdata, j);
2304 memset(data + j, 0, 64 - j);
2308 } else if (font->width <= 24) {
2309 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
2312 for (i = 0; i < font->charcount; i++) {
2313 for (j = 0; j < vc->vc_font.height; j++) {
2314 *data++ = fontdata[0];
2315 *data++ = fontdata[1];
2316 *data++ = fontdata[2];
2317 fontdata += sizeof(u32);
2319 memset(data, 0, 3 * (32 - j));
2320 data += 3 * (32 - j);
2323 j = vc->vc_font.height * 4;
2324 if (font->charcount * j > FNTSIZE(fontdata))
2327 for (i = 0; i < font->charcount; i++) {
2328 memcpy(data, fontdata, j);
2329 memset(data + j, 0, 128 - j);
2337 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2338 static void set_vc_hi_font(struct vc_data *vc, bool set)
2341 vc->vc_hi_font_mask = 0;
2342 if (vc->vc_can_do_color) {
2343 vc->vc_complement_mask >>= 1;
2344 vc->vc_s_complement_mask >>= 1;
2347 /* ++Edmund: reorder the attribute bits */
2348 if (vc->vc_can_do_color) {
2349 unsigned short *cp =
2350 (unsigned short *) vc->vc_origin;
2351 int count = vc->vc_screenbuf_size / 2;
2353 for (; count > 0; count--, cp++) {
2355 scr_writew(((c & 0xfe00) >> 1) |
2358 c = vc->vc_video_erase_char;
2359 vc->vc_video_erase_char =
2360 ((c & 0xfe00) >> 1) | (c & 0xff);
2364 vc->vc_hi_font_mask = 0x100;
2365 if (vc->vc_can_do_color) {
2366 vc->vc_complement_mask <<= 1;
2367 vc->vc_s_complement_mask <<= 1;
2370 /* ++Edmund: reorder the attribute bits */
2372 unsigned short *cp =
2373 (unsigned short *) vc->vc_origin;
2374 int count = vc->vc_screenbuf_size / 2;
2376 for (; count > 0; count--, cp++) {
2377 unsigned short newc;
2379 if (vc->vc_can_do_color)
2381 ((c & 0xff00) << 1) | (c &
2385 scr_writew(newc, cp);
2387 c = vc->vc_video_erase_char;
2388 if (vc->vc_can_do_color) {
2389 vc->vc_video_erase_char =
2390 ((c & 0xff00) << 1) | (c & 0xff);
2393 vc->vc_video_erase_char = c & ~0x100;
2398 static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
2399 const u8 * data, int userfont)
2401 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2402 struct fbcon_ops *ops = info->fbcon_par;
2403 struct fbcon_display *p = &fb_display[vc->vc_num];
2405 char *old_data = NULL;
2407 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2409 old_data = vc->vc_font.data;
2410 vc->vc_font.data = (void *)(p->fontdata = data);
2411 if ((p->userfont = userfont))
2413 vc->vc_font.width = w;
2414 vc->vc_font.height = h;
2415 vc->vc_font.charcount = charcount;
2416 if (vc->vc_hi_font_mask && charcount == 256)
2417 set_vc_hi_font(vc, false);
2418 else if (!vc->vc_hi_font_mask && charcount == 512)
2419 set_vc_hi_font(vc, true);
2424 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2425 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2428 vc_resize(vc, cols, rows);
2429 } else if (con_is_visible(vc)
2430 && vc->vc_mode == KD_TEXT) {
2431 fbcon_clear_margins(vc, 0);
2435 if (old_data && (--REFCOUNT(old_data) == 0))
2436 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2441 * User asked to set font; we are guaranteed that
2442 * a) width and height are in range 1..32
2443 * b) charcount does not exceed 512
2444 * but lets not assume that, since someone might someday want to use larger
2445 * fonts. And charcount of 512 is small for unicode support.
2447 * However, user space gives the font in 32 rows , regardless of
2448 * actual font height. So a new API is needed if support for larger fonts
2449 * is ever implemented.
2452 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2455 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2456 unsigned charcount = font->charcount;
2457 int w = font->width;
2458 int h = font->height;
2461 u8 *new_data, *data = font->data;
2462 int pitch = PITCH(font->width);
2464 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2465 * If not this check should be changed to charcount < 256 */
2466 if (charcount != 256 && charcount != 512)
2469 /* font bigger than screen resolution ? */
2470 if (w > FBCON_SWAP(info->var.rotate, info->var.xres, info->var.yres) ||
2471 h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres))
2474 /* Make sure drawing engine can handle the font */
2475 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2476 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2479 /* Make sure driver can handle the font length */
2480 if (fbcon_invalid_charcount(info, charcount))
2483 size = CALC_FONTSZ(h, pitch, charcount);
2485 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2490 memset(new_data, 0, FONT_EXTRA_WORDS * sizeof(int));
2492 new_data += FONT_EXTRA_WORDS * sizeof(int);
2493 FNTSIZE(new_data) = size;
2494 REFCOUNT(new_data) = 0; /* usage counter */
2495 for (i=0; i< charcount; i++) {
2496 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2499 /* Since linux has a nice crc32 function use it for counting font
2501 csum = crc32(0, new_data, size);
2503 FNTSUM(new_data) = csum;
2504 /* Check if the same font is on some other console already */
2505 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2506 struct vc_data *tmp = vc_cons[i].d;
2508 if (fb_display[i].userfont &&
2509 fb_display[i].fontdata &&
2510 FNTSUM(fb_display[i].fontdata) == csum &&
2511 FNTSIZE(fb_display[i].fontdata) == size &&
2512 tmp->vc_font.width == w &&
2513 !memcmp(fb_display[i].fontdata, new_data, size)) {
2514 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2515 new_data = (u8 *)fb_display[i].fontdata;
2519 return fbcon_do_set_font(vc, font->width, font->height, charcount, new_data, 1);
2522 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2524 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2525 const struct font_desc *f;
2528 f = get_default_font(info->var.xres, info->var.yres,
2529 info->pixmap.blit_x, info->pixmap.blit_y);
2530 else if (!(f = find_font(name)))
2533 font->width = f->width;
2534 font->height = f->height;
2535 return fbcon_do_set_font(vc, f->width, f->height, f->charcount, f->data, 0);
2538 static u16 palette_red[16];
2539 static u16 palette_green[16];
2540 static u16 palette_blue[16];
2542 static struct fb_cmap palette_cmap = {
2543 0, 16, palette_red, palette_green, palette_blue, NULL
2546 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2548 struct fb_info *info = fbcon_info_from_console(vc->vc_num);
2552 if (fbcon_is_inactive(vc, info))
2555 if (!con_is_visible(vc))
2558 depth = fb_get_color_depth(&info->var, &info->fix);
2560 for (i = j = 0; i < 16; i++) {
2562 val = vc->vc_palette[j++];
2563 palette_red[k] = (val << 8) | val;
2564 val = vc->vc_palette[j++];
2565 palette_green[k] = (val << 8) | val;
2566 val = vc->vc_palette[j++];
2567 palette_blue[k] = (val << 8) | val;
2569 palette_cmap.len = 16;
2570 palette_cmap.start = 0;
2572 * If framebuffer is capable of less than 16 colors,
2573 * use default palette of fbcon.
2576 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2578 fb_set_cmap(&palette_cmap, info);
2581 static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset)
2583 return (u16 *) (vc->vc_origin + offset);
2586 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2592 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2593 unsigned long offset = (pos - vc->vc_origin) / 2;
2595 x = offset % vc->vc_cols;
2596 y = offset / vc->vc_cols;
2597 ret = pos + (vc->vc_cols - x) * 2;
2599 /* Should not happen */
2601 ret = vc->vc_origin;
2610 /* As we might be inside of softback, we may work with non-contiguous buffer,
2611 that's why we have to use a separate routine. */
2612 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2615 u16 a = scr_readw(p);
2616 if (!vc->vc_can_do_color)
2618 else if (vc->vc_hi_font_mask == 0x100)
2619 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2620 (((a) & 0x0e00) << 4);
2622 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2623 (((a) & 0x0700) << 4);
2628 void fbcon_suspended(struct fb_info *info)
2630 struct vc_data *vc = NULL;
2631 struct fbcon_ops *ops = info->fbcon_par;
2633 if (!ops || ops->currcon < 0)
2635 vc = vc_cons[ops->currcon].d;
2637 /* Clear cursor, restore saved data */
2638 fbcon_cursor(vc, CM_ERASE);
2641 void fbcon_resumed(struct fb_info *info)
2644 struct fbcon_ops *ops = info->fbcon_par;
2646 if (!ops || ops->currcon < 0)
2648 vc = vc_cons[ops->currcon].d;
2653 static void fbcon_modechanged(struct fb_info *info)
2655 struct fbcon_ops *ops = info->fbcon_par;
2657 struct fbcon_display *p;
2660 if (!ops || ops->currcon < 0)
2662 vc = vc_cons[ops->currcon].d;
2663 if (vc->vc_mode != KD_TEXT ||
2664 fbcon_info_from_console(ops->currcon) != info)
2667 p = &fb_display[vc->vc_num];
2668 set_blitting_type(vc, info);
2670 if (con_is_visible(vc)) {
2671 var_to_display(p, &info->var, info);
2672 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2673 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2674 cols /= vc->vc_font.width;
2675 rows /= vc->vc_font.height;
2676 vc_resize(vc, cols, rows);
2677 updatescrollmode(p, info, vc);
2679 scrollback_current = 0;
2681 if (!fbcon_is_inactive(vc, info)) {
2682 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2683 ops->update_start(info);
2686 fbcon_set_palette(vc, color_table);
2691 static void fbcon_set_all_vcs(struct fb_info *info)
2693 struct fbcon_ops *ops = info->fbcon_par;
2695 struct fbcon_display *p;
2696 int i, rows, cols, fg = -1;
2698 if (!ops || ops->currcon < 0)
2701 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2703 if (!vc || vc->vc_mode != KD_TEXT ||
2704 fbcon_info_from_console(i) != info)
2707 if (con_is_visible(vc)) {
2712 p = &fb_display[vc->vc_num];
2713 set_blitting_type(vc, info);
2714 var_to_display(p, &info->var, info);
2715 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2716 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2717 cols /= vc->vc_font.width;
2718 rows /= vc->vc_font.height;
2719 vc_resize(vc, cols, rows);
2723 fbcon_modechanged(info);
2727 void fbcon_update_vcs(struct fb_info *info, bool all)
2730 fbcon_set_all_vcs(info);
2732 fbcon_modechanged(info);
2734 EXPORT_SYMBOL(fbcon_update_vcs);
2736 /* let fbcon check if it supports a new screen resolution */
2737 int fbcon_modechange_possible(struct fb_info *info, struct fb_var_screeninfo *var)
2739 struct fbcon_ops *ops = info->fbcon_par;
2743 WARN_CONSOLE_UNLOCKED();
2748 /* prevent setting a screen size which is smaller than font size */
2749 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2751 if (!vc || vc->vc_mode != KD_TEXT ||
2752 fbcon_info_from_console(i) != info)
2755 if (vc->vc_font.width > FBCON_SWAP(var->rotate, var->xres, var->yres) ||
2756 vc->vc_font.height > FBCON_SWAP(var->rotate, var->yres, var->xres))
2762 EXPORT_SYMBOL_GPL(fbcon_modechange_possible);
2764 int fbcon_mode_deleted(struct fb_info *info,
2765 struct fb_videomode *mode)
2767 struct fb_info *fb_info;
2768 struct fbcon_display *p;
2769 int i, j, found = 0;
2771 /* before deletion, ensure that mode is not in use */
2772 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2776 fb_info = fbcon_registered_fb[j];
2777 if (fb_info != info)
2782 if (fb_mode_is_equal(p->mode, mode)) {
2790 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2791 static void fbcon_unbind(void)
2795 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2799 fbcon_has_console_bind = 0;
2802 static inline void fbcon_unbind(void) {}
2803 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2805 void fbcon_fb_unbind(struct fb_info *info)
2807 int i, new_idx = -1;
2808 int idx = info->node;
2812 if (!fbcon_has_console_bind) {
2817 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2818 if (con2fb_map[i] != idx &&
2819 con2fb_map[i] != -1) {
2820 new_idx = con2fb_map[i];
2825 if (new_idx != -1) {
2826 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2827 if (con2fb_map[i] == idx)
2828 set_con2fb_map(i, new_idx, 0);
2831 struct fb_info *info = fbcon_registered_fb[idx];
2833 /* This is sort of like set_con2fb_map, except it maps
2834 * the consoles to no device and then releases the
2835 * oldinfo to free memory and cancel the cursor blink
2836 * timer. I can imagine this just becoming part of
2837 * set_con2fb_map where new_idx is -1
2839 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2840 if (con2fb_map[i] == idx) {
2842 if (!search_fb_in_map(idx)) {
2843 con2fb_release_oldinfo(vc_cons[i].d,
2854 void fbcon_fb_unregistered(struct fb_info *info)
2860 fbcon_registered_fb[info->node] = NULL;
2861 fbcon_num_registered_fb--;
2863 if (deferred_takeover) {
2869 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2870 if (con2fb_map[i] == idx)
2874 if (idx == info_idx) {
2877 fbcon_for_each_registered_fb(i) {
2883 if (info_idx != -1) {
2884 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2885 if (con2fb_map[i] == -1)
2886 con2fb_map[i] = info_idx;
2890 if (primary_device == idx)
2891 primary_device = -1;
2893 if (!fbcon_num_registered_fb)
2894 do_unregister_con_driver(&fb_con);
2898 void fbcon_remap_all(struct fb_info *info)
2900 int i, idx = info->node;
2903 if (deferred_takeover) {
2904 for (i = first_fb_vc; i <= last_fb_vc; i++)
2905 con2fb_map_boot[i] = idx;
2906 fbcon_map_override();
2911 for (i = first_fb_vc; i <= last_fb_vc; i++)
2912 set_con2fb_map(i, idx, 0);
2914 if (con_is_bound(&fb_con)) {
2915 printk(KERN_INFO "fbcon: Remapping primary device, "
2916 "fb%i, to tty %i-%i\n", idx,
2917 first_fb_vc + 1, last_fb_vc + 1);
2923 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2924 static void fbcon_select_primary(struct fb_info *info)
2926 if (!map_override && primary_device == -1 &&
2927 fb_is_primary_device(info)) {
2930 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2931 info->fix.id, info->node);
2932 primary_device = info->node;
2934 for (i = first_fb_vc; i <= last_fb_vc; i++)
2935 con2fb_map_boot[i] = primary_device;
2937 if (con_is_bound(&fb_con)) {
2938 printk(KERN_INFO "fbcon: Remapping primary device, "
2939 "fb%i, to tty %i-%i\n", info->node,
2940 first_fb_vc + 1, last_fb_vc + 1);
2941 info_idx = primary_device;
2947 static inline void fbcon_select_primary(struct fb_info *info)
2951 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2953 static bool lockless_register_fb;
2954 module_param_named_unsafe(lockless_register_fb, lockless_register_fb, bool, 0400);
2955 MODULE_PARM_DESC(lockless_register_fb,
2956 "Lockless framebuffer registration for debugging [default=off]");
2958 /* called with console_lock held */
2959 static int do_fb_registered(struct fb_info *info)
2961 int ret = 0, i, idx;
2963 WARN_CONSOLE_UNLOCKED();
2965 fbcon_registered_fb[info->node] = info;
2966 fbcon_num_registered_fb++;
2969 fbcon_select_primary(info);
2971 if (deferred_takeover) {
2972 pr_info("fbcon: Deferring console take-over\n");
2976 if (info_idx == -1) {
2977 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2978 if (con2fb_map_boot[i] == idx) {
2985 ret = do_fbcon_takeover(1);
2987 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2988 if (con2fb_map_boot[i] == idx)
2989 set_con2fb_map(i, idx, 0);
2996 int fbcon_fb_registered(struct fb_info *info)
3000 if (!lockless_register_fb)
3003 atomic_inc(&ignore_console_lock_warning);
3005 ret = do_fb_registered(info);
3007 if (!lockless_register_fb)
3010 atomic_dec(&ignore_console_lock_warning);
3015 void fbcon_fb_blanked(struct fb_info *info, int blank)
3017 struct fbcon_ops *ops = info->fbcon_par;
3020 if (!ops || ops->currcon < 0)
3023 vc = vc_cons[ops->currcon].d;
3024 if (vc->vc_mode != KD_TEXT ||
3025 fbcon_info_from_console(ops->currcon) != info)
3028 if (con_is_visible(vc)) {
3032 do_unblank_screen(0);
3034 ops->blank_state = blank;
3037 void fbcon_new_modelist(struct fb_info *info)
3041 struct fb_var_screeninfo var;
3042 const struct fb_videomode *mode;
3044 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3045 if (fbcon_info_from_console(i) != info)
3047 if (!fb_display[i].mode)
3050 display_to_var(&var, &fb_display[i]);
3051 mode = fb_find_nearest_mode(fb_display[i].mode,
3053 fb_videomode_to_var(&var, mode);
3054 fbcon_set_disp(info, &var, vc->vc_num);
3058 void fbcon_get_requirement(struct fb_info *info,
3059 struct fb_blit_caps *caps)
3066 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3068 if (vc && vc->vc_mode == KD_TEXT &&
3069 info->node == con2fb_map[i]) {
3070 caps->x |= 1 << (vc->vc_font.width - 1);
3071 caps->y |= 1 << (vc->vc_font.height - 1);
3072 charcnt = vc->vc_font.charcount;
3073 if (caps->len < charcnt)
3074 caps->len = charcnt;
3078 vc = vc_cons[fg_console].d;
3080 if (vc && vc->vc_mode == KD_TEXT &&
3081 info->node == con2fb_map[fg_console]) {
3082 caps->x = 1 << (vc->vc_font.width - 1);
3083 caps->y = 1 << (vc->vc_font.height - 1);
3084 caps->len = vc->vc_font.charcount;
3089 int fbcon_set_con2fb_map_ioctl(void __user *argp)
3091 struct fb_con2fbmap con2fb;
3094 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3096 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3098 if (con2fb.framebuffer >= FB_MAX)
3100 if (!fbcon_registered_fb[con2fb.framebuffer])
3101 request_module("fb%d", con2fb.framebuffer);
3102 if (!fbcon_registered_fb[con2fb.framebuffer]) {
3107 ret = set_con2fb_map(con2fb.console - 1,
3108 con2fb.framebuffer, 1);
3114 int fbcon_get_con2fb_map_ioctl(void __user *argp)
3116 struct fb_con2fbmap con2fb;
3118 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3120 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3124 con2fb.framebuffer = con2fb_map[con2fb.console - 1];
3127 return copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
3131 * The console `switch' structure for the frame buffer based console
3134 static const struct consw fb_con = {
3135 .owner = THIS_MODULE,
3136 .con_startup = fbcon_startup,
3137 .con_init = fbcon_init,
3138 .con_deinit = fbcon_deinit,
3139 .con_clear = fbcon_clear,
3140 .con_putc = fbcon_putc,
3141 .con_putcs = fbcon_putcs,
3142 .con_cursor = fbcon_cursor,
3143 .con_scroll = fbcon_scroll,
3144 .con_switch = fbcon_switch,
3145 .con_blank = fbcon_blank,
3146 .con_font_set = fbcon_set_font,
3147 .con_font_get = fbcon_get_font,
3148 .con_font_default = fbcon_set_def_font,
3149 .con_set_palette = fbcon_set_palette,
3150 .con_invert_region = fbcon_invert_region,
3151 .con_screen_pos = fbcon_screen_pos,
3152 .con_getxy = fbcon_getxy,
3153 .con_resize = fbcon_resize,
3154 .con_debug_enter = fbcon_debug_enter,
3155 .con_debug_leave = fbcon_debug_leave,
3158 static ssize_t store_rotate(struct device *device,
3159 struct device_attribute *attr, const char *buf,
3162 struct fb_info *info;
3167 idx = con2fb_map[fg_console];
3169 if (idx == -1 || fbcon_registered_fb[idx] == NULL)
3172 info = fbcon_registered_fb[idx];
3173 rotate = simple_strtoul(buf, last, 0);
3174 fbcon_rotate(info, rotate);
3180 static ssize_t store_rotate_all(struct device *device,
3181 struct device_attribute *attr,const char *buf,
3184 struct fb_info *info;
3189 idx = con2fb_map[fg_console];
3191 if (idx == -1 || fbcon_registered_fb[idx] == NULL)
3194 info = fbcon_registered_fb[idx];
3195 rotate = simple_strtoul(buf, last, 0);
3196 fbcon_rotate_all(info, rotate);
3202 static ssize_t show_rotate(struct device *device,
3203 struct device_attribute *attr,char *buf)
3205 struct fb_info *info;
3206 int rotate = 0, idx;
3209 idx = con2fb_map[fg_console];
3211 if (idx == -1 || fbcon_registered_fb[idx] == NULL)
3214 info = fbcon_registered_fb[idx];
3215 rotate = fbcon_get_rotate(info);
3218 return sysfs_emit(buf, "%d\n", rotate);
3221 static ssize_t show_cursor_blink(struct device *device,
3222 struct device_attribute *attr, char *buf)
3224 struct fb_info *info;
3225 struct fbcon_ops *ops;
3226 int idx, blink = -1;
3229 idx = con2fb_map[fg_console];
3231 if (idx == -1 || fbcon_registered_fb[idx] == NULL)
3234 info = fbcon_registered_fb[idx];
3235 ops = info->fbcon_par;
3240 blink = delayed_work_pending(&ops->cursor_work);
3243 return sysfs_emit(buf, "%d\n", blink);
3246 static ssize_t store_cursor_blink(struct device *device,
3247 struct device_attribute *attr,
3248 const char *buf, size_t count)
3250 struct fb_info *info;
3255 idx = con2fb_map[fg_console];
3257 if (idx == -1 || fbcon_registered_fb[idx] == NULL)
3260 info = fbcon_registered_fb[idx];
3262 if (!info->fbcon_par)
3265 blink = simple_strtoul(buf, last, 0);
3268 fbcon_cursor_noblink = 0;
3269 fbcon_add_cursor_work(info);
3271 fbcon_cursor_noblink = 1;
3272 fbcon_del_cursor_work(info);
3280 static struct device_attribute device_attrs[] = {
3281 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3282 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3283 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3284 store_cursor_blink),
3287 static int fbcon_init_device(void)
3291 fbcon_has_sysfs = 1;
3293 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3294 error = device_create_file(fbcon_device, &device_attrs[i]);
3302 device_remove_file(fbcon_device, &device_attrs[i]);
3304 fbcon_has_sysfs = 0;
3310 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3311 static void fbcon_register_existing_fbs(struct work_struct *work)
3317 deferred_takeover = false;
3318 logo_shown = FBCON_LOGO_DONTSHOW;
3320 fbcon_for_each_registered_fb(i)
3321 do_fb_registered(fbcon_registered_fb[i]);
3326 static struct notifier_block fbcon_output_nb;
3327 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3329 static int fbcon_output_notifier(struct notifier_block *nb,
3330 unsigned long action, void *data)
3332 WARN_CONSOLE_UNLOCKED();
3334 pr_info("fbcon: Taking over console\n");
3336 dummycon_unregister_output_notifier(&fbcon_output_nb);
3338 /* We may get called in atomic context */
3339 schedule_work(&fbcon_deferred_takeover_work);
3345 static void fbcon_start(void)
3347 WARN_CONSOLE_UNLOCKED();
3349 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3350 if (conswitchp != &dummy_con)
3351 deferred_takeover = false;
3353 if (deferred_takeover) {
3354 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3355 dummycon_register_output_notifier(&fbcon_output_nb);
3361 void __init fb_console_init(void)
3366 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3369 if (IS_ERR(fbcon_device)) {
3370 printk(KERN_WARNING "Unable to create device "
3371 "for fbcon; errno = %ld\n",
3372 PTR_ERR(fbcon_device));
3373 fbcon_device = NULL;
3375 fbcon_init_device();
3377 for (i = 0; i < MAX_NR_CONSOLES; i++)
3386 static void __exit fbcon_deinit_device(void)
3390 if (fbcon_has_sysfs) {
3391 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3392 device_remove_file(fbcon_device, &device_attrs[i]);
3394 fbcon_has_sysfs = 0;
3398 void __exit fb_console_exit(void)
3400 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3402 if (deferred_takeover)
3403 dummycon_unregister_output_notifier(&fbcon_output_nb);
3406 cancel_work_sync(&fbcon_deferred_takeover_work);
3410 fbcon_deinit_device();
3411 device_destroy(fb_class, MKDEV(0, 0));
3413 do_unregister_con_driver(&fb_con);