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 * - access to the registered_fb array is entirely unprotected. This should use
90 * proper object lifetime handling, i.e. get/put_fb_info. This also means
91 * switching from indices to proper pointers for fb_info everywhere.
93 * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since it
94 * means concurrent access to the same fbdev from both fbcon and userspace
95 * will blow up. To fix this all fbcon calls from fbmem.c need to be moved out
96 * of fb_lock/unlock protected sections, since otherwise we'll recurse and
97 * deadlock eventually. Aside: Due to these deadlock issues the fbdev code in
98 * fbmem.c cannot use locking asserts, and there's lots of callers which get
99 * the rules wrong, e.g. fbsysfs.c entirely missed fb_lock/unlock calls too.
103 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
104 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
105 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
108 static struct fbcon_display fb_display[MAX_NR_CONSOLES];
110 static signed char con2fb_map[MAX_NR_CONSOLES];
111 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
113 static int logo_lines;
114 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
116 static int logo_shown = FBCON_LOGO_CANSHOW;
117 /* console mappings */
118 static int first_fb_vc;
119 static int last_fb_vc = MAX_NR_CONSOLES - 1;
120 static int fbcon_is_default = 1;
121 static int primary_device = -1;
122 static int fbcon_has_console_bind;
124 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
125 static int map_override;
127 static inline void fbcon_map_override(void)
132 static inline void fbcon_map_override(void)
135 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
137 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
138 static bool deferred_takeover = true;
140 #define deferred_takeover false
144 static char fontname[40];
146 /* current fb_info */
147 static int info_idx = -1;
149 /* console rotation */
150 static int initial_rotation = -1;
151 static int fbcon_has_sysfs;
152 static int margin_color;
154 static const struct consw fb_con;
156 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
158 static int fbcon_cursor_noblink;
160 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
163 * Interface used by the world
166 static const char *fbcon_startup(void);
167 static void fbcon_init(struct vc_data *vc, int init);
168 static void fbcon_deinit(struct vc_data *vc);
169 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
171 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
172 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
173 int count, int ypos, int xpos);
174 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
175 static void fbcon_cursor(struct vc_data *vc, int mode);
176 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
177 int height, int width);
178 static int fbcon_switch(struct vc_data *vc);
179 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
180 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
185 static __inline__ void ywrap_up(struct vc_data *vc, int count);
186 static __inline__ void ywrap_down(struct vc_data *vc, int count);
187 static __inline__ void ypan_up(struct vc_data *vc, int count);
188 static __inline__ void ypan_down(struct vc_data *vc, int count);
189 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
190 int dy, int dx, int height, int width, u_int y_break);
191 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
193 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
194 int line, int count, int dy);
195 static void fbcon_modechanged(struct fb_info *info);
196 static void fbcon_set_all_vcs(struct fb_info *info);
197 static void fbcon_start(void);
198 static void fbcon_exit(void);
199 static struct device *fbcon_device;
201 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
202 static inline void fbcon_set_rotation(struct fb_info *info)
204 struct fbcon_ops *ops = info->fbcon_par;
206 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
207 ops->p->con_rotate < 4)
208 ops->rotate = ops->p->con_rotate;
213 static void fbcon_rotate(struct fb_info *info, u32 rotate)
215 struct fbcon_ops *ops= info->fbcon_par;
216 struct fb_info *fb_info;
218 if (!ops || ops->currcon == -1)
221 fb_info = registered_fb[con2fb_map[ops->currcon]];
223 if (info == fb_info) {
224 struct fbcon_display *p = &fb_display[ops->currcon];
227 p->con_rotate = rotate;
231 fbcon_modechanged(info);
235 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
237 struct fbcon_ops *ops = info->fbcon_par;
239 struct fbcon_display *p;
242 if (!ops || ops->currcon < 0 || rotate > 3)
245 for (i = first_fb_vc; i <= last_fb_vc; i++) {
247 if (!vc || vc->vc_mode != KD_TEXT ||
248 registered_fb[con2fb_map[i]] != info)
251 p = &fb_display[vc->vc_num];
252 p->con_rotate = rotate;
255 fbcon_set_all_vcs(info);
258 static inline void fbcon_set_rotation(struct fb_info *info)
260 struct fbcon_ops *ops = info->fbcon_par;
262 ops->rotate = FB_ROTATE_UR;
265 static void fbcon_rotate(struct fb_info *info, u32 rotate)
270 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
274 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
276 static int fbcon_get_rotate(struct fb_info *info)
278 struct fbcon_ops *ops = info->fbcon_par;
280 return (ops) ? ops->rotate : 0;
283 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
285 struct fbcon_ops *ops = info->fbcon_par;
287 return (info->state != FBINFO_STATE_RUNNING ||
288 vc->vc_mode != KD_TEXT || ops->graphics);
291 static int get_color(struct vc_data *vc, struct fb_info *info,
294 int depth = fb_get_color_depth(&info->var, &info->fix);
297 if (console_blanked) {
298 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
300 c = vc->vc_video_erase_char & charmask;
304 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
305 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
310 int col = mono_col(info);
312 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
313 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
318 color = (is_fg) ? fg : bg;
323 * Scale down 16-colors to 4 colors. Default 4-color palette
324 * is grayscale. However, simply dividing the values by 4
325 * will not work, as colors 1, 2 and 3 will be scaled-down
326 * to zero rendering them invisible. So empirically convert
327 * colors to a sane 4-level grayscale.
331 color = 0; /* black */
334 color = 2; /* white */
337 color = 1; /* gray */
340 color = 3; /* intense white */
346 * Last 8 entries of default 16-color palette is a more intense
347 * version of the first 8 (i.e., same chrominance, different
358 static void fb_flashcursor(struct work_struct *work)
360 struct fb_info *info = container_of(work, struct fb_info, queue);
361 struct fbcon_ops *ops = info->fbcon_par;
362 struct vc_data *vc = NULL;
367 /* FIXME: we should sort out the unbind locking instead */
368 /* instead we just fail to flash the cursor if we can't get
369 * the lock instead of blocking fbcon deinit */
370 ret = console_trylock();
374 if (ops && ops->currcon != -1)
375 vc = vc_cons[ops->currcon].d;
377 if (!vc || !con_is_visible(vc) ||
378 registered_fb[con2fb_map[vc->vc_num]] != info ||
384 c = scr_readw((u16 *) vc->vc_pos);
385 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
387 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
388 get_color(vc, info, c, 0));
392 static void cursor_timer_handler(struct timer_list *t)
394 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
395 struct fb_info *info = ops->info;
397 queue_work(system_power_efficient_wq, &info->queue);
398 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
401 static void fbcon_add_cursor_timer(struct fb_info *info)
403 struct fbcon_ops *ops = info->fbcon_par;
405 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
406 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
407 !fbcon_cursor_noblink) {
408 if (!info->queue.func)
409 INIT_WORK(&info->queue, fb_flashcursor);
411 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
412 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
413 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
417 static void fbcon_del_cursor_timer(struct fb_info *info)
419 struct fbcon_ops *ops = info->fbcon_par;
421 if (info->queue.func == fb_flashcursor &&
422 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
423 del_timer_sync(&ops->cursor_timer);
424 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
429 static int __init fb_console_setup(char *this_opt)
434 if (!this_opt || !*this_opt)
437 while ((options = strsep(&this_opt, ",")) != NULL) {
438 if (!strncmp(options, "font:", 5)) {
439 strlcpy(fontname, options + 5, sizeof(fontname));
443 if (!strncmp(options, "scrollback:", 11)) {
444 pr_warn("Ignoring scrollback size option\n");
448 if (!strncmp(options, "map:", 4)) {
451 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
455 (options[j++]-'0') % FB_MAX;
458 fbcon_map_override();
463 if (!strncmp(options, "vc:", 3)) {
466 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
469 if (*options++ == '-')
470 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
471 fbcon_is_default = 0;
475 if (!strncmp(options, "rotate:", 7)) {
478 initial_rotation = simple_strtoul(options, &options, 0);
479 if (initial_rotation > 3)
480 initial_rotation = 0;
484 if (!strncmp(options, "margin:", 7)) {
487 margin_color = simple_strtoul(options, &options, 0);
490 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
491 if (!strcmp(options, "nodefer")) {
492 deferred_takeover = false;
497 if (!strncmp(options, "logo-pos:", 9)) {
499 if (!strcmp(options, "center"))
500 fb_center_logo = true;
504 if (!strncmp(options, "logo-count:", 11)) {
507 fb_logo_count = simple_strtol(options, &options, 0);
514 __setup("fbcon=", fb_console_setup);
517 static int search_fb_in_map(int idx)
521 for (i = first_fb_vc; i <= last_fb_vc; i++) {
522 if (con2fb_map[i] == idx)
528 static int search_for_mapped_con(void)
532 for (i = first_fb_vc; i <= last_fb_vc; i++) {
533 if (con2fb_map[i] != -1)
539 static int do_fbcon_takeover(int show_logo)
543 if (!num_registered_fb)
547 logo_shown = FBCON_LOGO_DONTSHOW;
549 for (i = first_fb_vc; i <= last_fb_vc; i++)
550 con2fb_map[i] = info_idx;
552 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
556 for (i = first_fb_vc; i <= last_fb_vc; i++)
560 fbcon_has_console_bind = 1;
567 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
568 int cols, int rows, int new_cols, int new_rows)
570 logo_shown = FBCON_LOGO_DONTSHOW;
573 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
574 int cols, int rows, int new_cols, int new_rows)
576 /* Need to make room for the logo */
577 struct fbcon_ops *ops = info->fbcon_par;
578 int cnt, erase = vc->vc_video_erase_char, step;
579 unsigned short *save = NULL, *r, *q;
582 if (info->fbops->owner) {
583 logo_shown = FBCON_LOGO_DONTSHOW;
588 * remove underline attribute from erase character
589 * if black and white framebuffer.
591 if (fb_get_color_depth(&info->var, &info->fix) == 1)
593 logo_height = fb_prepare_logo(info, ops->rotate);
594 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
595 q = (unsigned short *) (vc->vc_origin +
596 vc->vc_size_row * rows);
597 step = logo_lines * cols;
598 for (r = q - logo_lines * cols; r < q; r++)
599 if (scr_readw(r) != vc->vc_video_erase_char)
601 if (r != q && new_rows >= rows + logo_lines) {
602 save = kmalloc(array3_size(logo_lines, new_cols, 2),
605 int i = cols < new_cols ? cols : new_cols;
606 scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
608 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
609 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
614 /* We can scroll screen down */
616 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
617 scr_memcpyw(r + step, r, vc->vc_size_row);
622 if (vc->state.y + logo_lines >= rows)
623 lines = rows - vc->state.y - 1;
626 vc->state.y += lines;
627 vc->vc_pos += lines * vc->vc_size_row;
630 scr_memsetw((unsigned short *) vc->vc_origin,
632 vc->vc_size_row * logo_lines);
634 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
635 fbcon_clear_margins(vc, 0);
640 q = (unsigned short *) (vc->vc_origin +
643 scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
644 vc->state.y += logo_lines;
645 vc->vc_pos += logo_lines * vc->vc_size_row;
649 if (logo_shown == FBCON_LOGO_DONTSHOW)
652 if (logo_lines > vc->vc_bottom) {
653 logo_shown = FBCON_LOGO_CANSHOW;
655 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
657 logo_shown = FBCON_LOGO_DRAW;
658 vc->vc_top = logo_lines;
663 #ifdef CONFIG_FB_TILEBLITTING
664 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
666 struct fbcon_ops *ops = info->fbcon_par;
668 ops->p = &fb_display[vc->vc_num];
670 if ((info->flags & FBINFO_MISC_TILEBLITTING))
671 fbcon_set_tileops(vc, info);
673 fbcon_set_rotation(info);
674 fbcon_set_bitops(ops);
678 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
682 if (info->flags & FBINFO_MISC_TILEBLITTING &&
683 info->tileops->fb_get_tilemax(info) < charcount)
689 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
691 struct fbcon_ops *ops = info->fbcon_par;
693 info->flags &= ~FBINFO_MISC_TILEBLITTING;
694 ops->p = &fb_display[vc->vc_num];
695 fbcon_set_rotation(info);
696 fbcon_set_bitops(ops);
699 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
704 #endif /* CONFIG_MISC_TILEBLITTING */
707 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
708 int unit, int oldidx)
710 struct fbcon_ops *ops = NULL;
713 if (!try_module_get(info->fbops->owner))
716 if (!err && info->fbops->fb_open &&
717 info->fbops->fb_open(info, 0))
721 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
727 ops->cur_blink_jiffies = HZ / 5;
729 info->fbcon_par = ops;
732 set_blitting_type(vc, info);
736 con2fb_map[unit] = oldidx;
737 module_put(info->fbops->owner);
743 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
744 struct fb_info *newinfo, int unit,
745 int oldidx, int found)
747 struct fbcon_ops *ops = oldinfo->fbcon_par;
750 if (oldinfo->fbops->fb_release &&
751 oldinfo->fbops->fb_release(oldinfo, 0)) {
752 con2fb_map[unit] = oldidx;
753 if (!found && newinfo->fbops->fb_release)
754 newinfo->fbops->fb_release(newinfo, 0);
756 module_put(newinfo->fbops->owner);
761 fbcon_del_cursor_timer(oldinfo);
762 kfree(ops->cursor_state.mask);
763 kfree(ops->cursor_data);
764 kfree(ops->cursor_src);
765 kfree(ops->fontbuffer);
766 kfree(oldinfo->fbcon_par);
767 oldinfo->fbcon_par = NULL;
768 module_put(oldinfo->fbops->owner);
770 If oldinfo and newinfo are driving the same hardware,
771 the fb_release() method of oldinfo may attempt to
772 restore the hardware state. This will leave the
773 newinfo in an undefined state. Thus, a call to
774 fb_set_par() may be needed for the newinfo.
776 if (newinfo && newinfo->fbops->fb_set_par) {
777 ret = newinfo->fbops->fb_set_par(newinfo);
780 printk(KERN_ERR "con2fb_release_oldinfo: "
781 "detected unhandled fb_set_par error, "
782 "error code %d\n", ret);
789 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
790 int unit, int show_logo)
792 struct fbcon_ops *ops = info->fbcon_par;
795 ops->currcon = fg_console;
797 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
798 ret = info->fbops->fb_set_par(info);
801 printk(KERN_ERR "con2fb_init_display: detected "
802 "unhandled fb_set_par error, "
803 "error code %d\n", ret);
806 ops->flags |= FBCON_FLAGS_INIT;
808 fbcon_set_disp(info, &info->var, unit);
811 struct vc_data *fg_vc = vc_cons[fg_console].d;
812 struct fb_info *fg_info =
813 registered_fb[con2fb_map[fg_console]];
815 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
816 fg_vc->vc_rows, fg_vc->vc_cols,
820 update_screen(vc_cons[fg_console].d);
824 * set_con2fb_map - map console to frame buffer device
825 * @unit: virtual console number to map
826 * @newidx: frame buffer index to map virtual console to
827 * @user: user request
829 * Maps a virtual console @unit to a frame buffer device
832 * This should be called with the console lock held.
834 static int set_con2fb_map(int unit, int newidx, int user)
836 struct vc_data *vc = vc_cons[unit].d;
837 int oldidx = con2fb_map[unit];
838 struct fb_info *info = registered_fb[newidx];
839 struct fb_info *oldinfo = NULL;
842 WARN_CONSOLE_UNLOCKED();
844 if (oldidx == newidx)
850 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
852 return do_fbcon_takeover(0);
856 oldinfo = registered_fb[oldidx];
858 found = search_fb_in_map(newidx);
860 con2fb_map[unit] = newidx;
862 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
865 * If old fb is not mapped to any of the consoles,
866 * fbcon should release it.
868 if (!err && oldinfo && !search_fb_in_map(oldidx))
869 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
873 int show_logo = (fg_console == 0 && !user &&
874 logo_shown != FBCON_LOGO_DONTSHOW);
877 fbcon_add_cursor_timer(info);
878 con2fb_map_boot[unit] = newidx;
879 con2fb_init_display(vc, info, unit, show_logo);
882 if (!search_fb_in_map(info_idx))
889 * Low Level Operations
891 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
892 static int var_to_display(struct fbcon_display *disp,
893 struct fb_var_screeninfo *var,
894 struct fb_info *info)
896 disp->xres_virtual = var->xres_virtual;
897 disp->yres_virtual = var->yres_virtual;
898 disp->bits_per_pixel = var->bits_per_pixel;
899 disp->grayscale = var->grayscale;
900 disp->nonstd = var->nonstd;
901 disp->accel_flags = var->accel_flags;
902 disp->height = var->height;
903 disp->width = var->width;
904 disp->red = var->red;
905 disp->green = var->green;
906 disp->blue = var->blue;
907 disp->transp = var->transp;
908 disp->rotate = var->rotate;
909 disp->mode = fb_match_mode(var, &info->modelist);
910 if (disp->mode == NULL)
911 /* This should not happen */
916 static void display_to_var(struct fb_var_screeninfo *var,
917 struct fbcon_display *disp)
919 fb_videomode_to_var(var, disp->mode);
920 var->xres_virtual = disp->xres_virtual;
921 var->yres_virtual = disp->yres_virtual;
922 var->bits_per_pixel = disp->bits_per_pixel;
923 var->grayscale = disp->grayscale;
924 var->nonstd = disp->nonstd;
925 var->accel_flags = disp->accel_flags;
926 var->height = disp->height;
927 var->width = disp->width;
928 var->red = disp->red;
929 var->green = disp->green;
930 var->blue = disp->blue;
931 var->transp = disp->transp;
932 var->rotate = disp->rotate;
935 static const char *fbcon_startup(void)
937 const char *display_desc = "frame buffer device";
938 struct fbcon_display *p = &fb_display[fg_console];
939 struct vc_data *vc = vc_cons[fg_console].d;
940 const struct font_desc *font = NULL;
941 struct module *owner;
942 struct fb_info *info = NULL;
943 struct fbcon_ops *ops;
947 * If num_registered_fb is zero, this is a call for the dummy part.
948 * The frame buffer devices weren't initialized yet.
950 if (!num_registered_fb || info_idx == -1)
953 * Instead of blindly using registered_fb[0], we use info_idx, set by
956 info = registered_fb[info_idx];
960 owner = info->fbops->owner;
961 if (!try_module_get(owner))
963 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
968 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
976 ops->cur_rotate = -1;
977 ops->cur_blink_jiffies = HZ / 5;
979 info->fbcon_par = ops;
981 p->con_rotate = initial_rotation;
982 if (p->con_rotate == -1)
983 p->con_rotate = info->fbcon_rotate_hint;
984 if (p->con_rotate == -1)
985 p->con_rotate = FB_ROTATE_UR;
987 set_blitting_type(vc, info);
989 /* Setup default font */
990 if (!p->fontdata && !vc->vc_font.data) {
991 if (!fontname[0] || !(font = find_font(fontname)))
992 font = get_default_font(info->var.xres,
995 info->pixmap.blit_y);
996 vc->vc_font.width = font->width;
997 vc->vc_font.height = font->height;
998 vc->vc_font.data = (void *)(p->fontdata = font->data);
999 vc->vc_font.charcount = font->charcount;
1001 p->fontdata = vc->vc_font.data;
1004 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1005 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1006 cols /= vc->vc_font.width;
1007 rows /= vc->vc_font.height;
1008 vc_resize(vc, cols, rows);
1010 pr_debug("mode: %s\n", info->fix.id);
1011 pr_debug("visual: %d\n", info->fix.visual);
1012 pr_debug("res: %dx%d-%d\n", info->var.xres,
1014 info->var.bits_per_pixel);
1016 fbcon_add_cursor_timer(info);
1017 return display_desc;
1020 static void fbcon_init(struct vc_data *vc, int init)
1022 struct fb_info *info;
1023 struct fbcon_ops *ops;
1024 struct vc_data **default_mode = vc->vc_display_fg;
1025 struct vc_data *svc = *default_mode;
1026 struct fbcon_display *t, *p = &fb_display[vc->vc_num];
1027 int logo = 1, new_rows, new_cols, rows, cols;
1030 if (WARN_ON(info_idx == -1))
1033 if (con2fb_map[vc->vc_num] == -1)
1034 con2fb_map[vc->vc_num] = info_idx;
1036 info = registered_fb[con2fb_map[vc->vc_num]];
1038 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1039 logo_shown = FBCON_LOGO_DONTSHOW;
1041 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1042 (info->fix.type == FB_TYPE_TEXT))
1045 if (var_to_display(p, &info->var, info))
1048 if (!info->fbcon_par)
1049 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1051 /* If we are not the first console on this
1052 fb, copy the font from that console */
1053 t = &fb_display[fg_console];
1056 struct vc_data *fvc = vc_cons[fg_console].d;
1058 vc->vc_font.data = (void *)(p->fontdata =
1060 vc->vc_font.width = fvc->vc_font.width;
1061 vc->vc_font.height = fvc->vc_font.height;
1062 vc->vc_font.charcount = fvc->vc_font.charcount;
1063 p->userfont = t->userfont;
1066 REFCOUNT(p->fontdata)++;
1068 const struct font_desc *font = NULL;
1070 if (!fontname[0] || !(font = find_font(fontname)))
1071 font = get_default_font(info->var.xres,
1073 info->pixmap.blit_x,
1074 info->pixmap.blit_y);
1075 vc->vc_font.width = font->width;
1076 vc->vc_font.height = font->height;
1077 vc->vc_font.data = (void *)(p->fontdata = font->data);
1078 vc->vc_font.charcount = font->charcount;
1082 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1083 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1084 if (vc->vc_font.charcount == 256) {
1085 vc->vc_hi_font_mask = 0;
1087 vc->vc_hi_font_mask = 0x100;
1088 if (vc->vc_can_do_color)
1089 vc->vc_complement_mask <<= 1;
1092 if (!*svc->vc_uni_pagedir_loc)
1093 con_set_default_unimap(svc);
1094 if (!*vc->vc_uni_pagedir_loc)
1095 con_copy_unimap(vc, svc);
1097 ops = info->fbcon_par;
1098 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1100 p->con_rotate = initial_rotation;
1101 if (p->con_rotate == -1)
1102 p->con_rotate = info->fbcon_rotate_hint;
1103 if (p->con_rotate == -1)
1104 p->con_rotate = FB_ROTATE_UR;
1106 set_blitting_type(vc, info);
1110 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1111 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1112 new_cols /= vc->vc_font.width;
1113 new_rows /= vc->vc_font.height;
1116 * We must always set the mode. The mode of the previous console
1117 * driver could be in the same resolution but we are using different
1118 * hardware so we have to initialize the hardware.
1120 * We need to do it in fbcon_init() to prevent screen corruption.
1122 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1123 if (info->fbops->fb_set_par &&
1124 !(ops->flags & FBCON_FLAGS_INIT)) {
1125 ret = info->fbops->fb_set_par(info);
1128 printk(KERN_ERR "fbcon_init: detected "
1129 "unhandled fb_set_par error, "
1130 "error code %d\n", ret);
1133 ops->flags |= FBCON_FLAGS_INIT;
1138 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1139 if ((info->flags & FBINFO_HWACCEL_COPYAREA) &&
1140 !(info->flags & FBINFO_HWACCEL_DISABLED))
1141 p->scrollmode = SCROLL_MOVE;
1142 else /* default to something safe */
1143 p->scrollmode = SCROLL_REDRAW;
1147 * ++guenther: console.c:vc_allocate() relies on initializing
1148 * vc_{cols,rows}, but we must not set those if we are only
1149 * resizing the console.
1152 vc->vc_cols = new_cols;
1153 vc->vc_rows = new_rows;
1155 vc_resize(vc, new_cols, new_rows);
1158 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1160 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1161 ops->rotate = FB_ROTATE_UR;
1162 set_blitting_type(vc, info);
1165 ops->p = &fb_display[fg_console];
1168 static void fbcon_free_font(struct fbcon_display *p, bool freefont)
1170 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1171 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1176 static void set_vc_hi_font(struct vc_data *vc, bool set);
1178 static void fbcon_deinit(struct vc_data *vc)
1180 struct fbcon_display *p = &fb_display[vc->vc_num];
1181 struct fb_info *info;
1182 struct fbcon_ops *ops;
1184 bool free_font = true;
1186 idx = con2fb_map[vc->vc_num];
1191 info = registered_fb[idx];
1196 if (info->flags & FBINFO_MISC_FIRMWARE)
1198 ops = info->fbcon_par;
1203 if (con_is_visible(vc))
1204 fbcon_del_cursor_timer(info);
1206 ops->flags &= ~FBCON_FLAGS_INIT;
1209 fbcon_free_font(p, free_font);
1211 vc->vc_font.data = NULL;
1213 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1214 set_vc_hi_font(vc, false);
1216 if (!con_is_bound(&fb_con))
1219 if (vc->vc_num == logo_shown)
1220 logo_shown = FBCON_LOGO_CANSHOW;
1225 /* ====================================================================== */
1227 /* fbcon_XXX routines - interface used by the world
1229 * This system is now divided into two levels because of complications
1230 * caused by hardware scrolling. Top level functions:
1232 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1234 * handles y values in range [0, scr_height-1] that correspond to real
1235 * screen positions. y_wrap shift means that first line of bitmap may be
1236 * anywhere on this display. These functions convert lineoffsets to
1237 * bitmap offsets and deal with the wrap-around case by splitting blits.
1239 * fbcon_bmove_physical_8() -- These functions fast implementations
1240 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1241 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1245 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1246 * Implies should only really hardware scroll in rows. Only reason for
1247 * restriction is simplicity & efficiency at the moment.
1250 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1253 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1254 struct fbcon_ops *ops = info->fbcon_par;
1256 struct fbcon_display *p = &fb_display[vc->vc_num];
1259 if (fbcon_is_inactive(vc, info))
1262 if (!height || !width)
1265 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1268 * If the font dimensions are not an integral of the display
1269 * dimensions then the ops->clear below won't end up clearing
1270 * the margins. Call clear_margins here in case the logo
1271 * bitmap stretched into the margin area.
1273 fbcon_clear_margins(vc, 0);
1276 /* Split blits that cross physical y_wrap boundary */
1278 y_break = p->vrows - p->yscroll;
1279 if (sy < y_break && sy + height - 1 >= y_break) {
1280 u_int b = y_break - sy;
1281 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1282 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1285 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1288 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1289 int count, int ypos, int xpos)
1291 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1292 struct fbcon_display *p = &fb_display[vc->vc_num];
1293 struct fbcon_ops *ops = info->fbcon_par;
1295 if (!fbcon_is_inactive(vc, info))
1296 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1297 get_color(vc, info, scr_readw(s), 1),
1298 get_color(vc, info, scr_readw(s), 0));
1301 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1305 scr_writew(c, &chr);
1306 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1309 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1311 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1312 struct fbcon_ops *ops = info->fbcon_par;
1314 if (!fbcon_is_inactive(vc, info))
1315 ops->clear_margins(vc, info, margin_color, bottom_only);
1318 static void fbcon_cursor(struct vc_data *vc, int mode)
1320 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1321 struct fbcon_ops *ops = info->fbcon_par;
1322 int c = scr_readw((u16 *) vc->vc_pos);
1324 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1326 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1329 if (vc->vc_cursor_type & CUR_SW)
1330 fbcon_del_cursor_timer(info);
1332 fbcon_add_cursor_timer(info);
1334 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1339 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1340 get_color(vc, info, c, 0));
1343 static int scrollback_phys_max = 0;
1344 static int scrollback_max = 0;
1345 static int scrollback_current = 0;
1347 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1350 struct fbcon_display *p, *t;
1351 struct vc_data **default_mode, *vc;
1352 struct vc_data *svc;
1353 struct fbcon_ops *ops = info->fbcon_par;
1356 p = &fb_display[unit];
1358 if (var_to_display(p, var, info))
1361 vc = vc_cons[unit].d;
1366 default_mode = vc->vc_display_fg;
1367 svc = *default_mode;
1368 t = &fb_display[svc->vc_num];
1370 if (!vc->vc_font.data) {
1371 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1372 vc->vc_font.width = (*default_mode)->vc_font.width;
1373 vc->vc_font.height = (*default_mode)->vc_font.height;
1374 vc->vc_font.charcount = (*default_mode)->vc_font.charcount;
1375 p->userfont = t->userfont;
1377 REFCOUNT(p->fontdata)++;
1380 var->activate = FB_ACTIVATE_NOW;
1381 info->var.activate = var->activate;
1382 var->yoffset = info->var.yoffset;
1383 var->xoffset = info->var.xoffset;
1384 fb_set_var(info, var);
1385 ops->var = info->var;
1386 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1387 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1388 if (vc->vc_font.charcount == 256) {
1389 vc->vc_hi_font_mask = 0;
1391 vc->vc_hi_font_mask = 0x100;
1392 if (vc->vc_can_do_color)
1393 vc->vc_complement_mask <<= 1;
1396 if (!*svc->vc_uni_pagedir_loc)
1397 con_set_default_unimap(svc);
1398 if (!*vc->vc_uni_pagedir_loc)
1399 con_copy_unimap(vc, svc);
1401 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1402 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1403 cols /= vc->vc_font.width;
1404 rows /= vc->vc_font.height;
1405 vc_resize(vc, cols, rows);
1407 if (con_is_visible(vc)) {
1412 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1414 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1415 struct fbcon_ops *ops = info->fbcon_par;
1416 struct fbcon_display *p = &fb_display[vc->vc_num];
1418 p->yscroll += count;
1419 if (p->yscroll >= p->vrows) /* Deal with wrap */
1420 p->yscroll -= p->vrows;
1421 ops->var.xoffset = 0;
1422 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1423 ops->var.vmode |= FB_VMODE_YWRAP;
1424 ops->update_start(info);
1425 scrollback_max += count;
1426 if (scrollback_max > scrollback_phys_max)
1427 scrollback_max = scrollback_phys_max;
1428 scrollback_current = 0;
1431 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1433 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1434 struct fbcon_ops *ops = info->fbcon_par;
1435 struct fbcon_display *p = &fb_display[vc->vc_num];
1437 p->yscroll -= count;
1438 if (p->yscroll < 0) /* Deal with wrap */
1439 p->yscroll += p->vrows;
1440 ops->var.xoffset = 0;
1441 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1442 ops->var.vmode |= FB_VMODE_YWRAP;
1443 ops->update_start(info);
1444 scrollback_max -= count;
1445 if (scrollback_max < 0)
1447 scrollback_current = 0;
1450 static __inline__ void ypan_up(struct vc_data *vc, int count)
1452 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1453 struct fbcon_display *p = &fb_display[vc->vc_num];
1454 struct fbcon_ops *ops = info->fbcon_par;
1456 p->yscroll += count;
1457 if (p->yscroll > p->vrows - vc->vc_rows) {
1458 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1459 0, 0, 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 > scrollback_phys_max)
1470 scrollback_max = scrollback_phys_max;
1471 scrollback_current = 0;
1474 static __inline__ void ypan_up_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 fbcon_display *p = &fb_display[vc->vc_num];
1480 p->yscroll += count;
1482 if (p->yscroll > p->vrows - vc->vc_rows) {
1483 p->yscroll -= p->vrows - vc->vc_rows;
1484 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
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 > scrollback_phys_max)
1494 scrollback_max = scrollback_phys_max;
1495 scrollback_current = 0;
1498 static __inline__ void ypan_down(struct vc_data *vc, int count)
1500 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1501 struct fbcon_display *p = &fb_display[vc->vc_num];
1502 struct fbcon_ops *ops = info->fbcon_par;
1504 p->yscroll -= count;
1505 if (p->yscroll < 0) {
1506 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1507 0, vc->vc_rows, vc->vc_cols);
1508 p->yscroll += p->vrows - vc->vc_rows;
1511 ops->var.xoffset = 0;
1512 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1513 ops->var.vmode &= ~FB_VMODE_YWRAP;
1514 ops->update_start(info);
1515 fbcon_clear_margins(vc, 1);
1516 scrollback_max -= count;
1517 if (scrollback_max < 0)
1519 scrollback_current = 0;
1522 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1524 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1525 struct fbcon_ops *ops = info->fbcon_par;
1526 struct fbcon_display *p = &fb_display[vc->vc_num];
1528 p->yscroll -= count;
1530 if (p->yscroll < 0) {
1531 p->yscroll += p->vrows - vc->vc_rows;
1532 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1535 ops->var.xoffset = 0;
1536 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1537 ops->var.vmode &= ~FB_VMODE_YWRAP;
1538 ops->update_start(info);
1539 fbcon_clear_margins(vc, 1);
1540 scrollback_max -= count;
1541 if (scrollback_max < 0)
1543 scrollback_current = 0;
1546 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
1547 int line, int count, int dy)
1549 unsigned short *s = (unsigned short *)
1550 (vc->vc_origin + vc->vc_size_row * line);
1553 unsigned short *start = s;
1554 unsigned short *le = advance_row(s, 1);
1557 unsigned short attr = 1;
1561 if (attr != (c & 0xff00)) {
1564 fbcon_putcs(vc, start, s - start,
1570 console_conditional_schedule();
1574 fbcon_putcs(vc, start, s - start, dy, x);
1575 console_conditional_schedule();
1580 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1581 struct fbcon_display *p, int line, int count, int ycount)
1583 int offset = ycount * vc->vc_cols;
1584 unsigned short *d = (unsigned short *)
1585 (vc->vc_origin + vc->vc_size_row * line);
1586 unsigned short *s = d + offset;
1587 struct fbcon_ops *ops = info->fbcon_par;
1590 unsigned short *start = s;
1591 unsigned short *le = advance_row(s, 1);
1598 if (c == scr_readw(d)) {
1600 ops->bmove(vc, info, line + ycount, x,
1601 line, x, 1, s-start);
1611 console_conditional_schedule();
1616 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1618 console_conditional_schedule();
1623 /* NOTE: We subtract two lines from these pointers */
1624 s -= vc->vc_size_row;
1625 d -= vc->vc_size_row;
1630 static void fbcon_redraw(struct vc_data *vc, struct fbcon_display *p,
1631 int line, int count, int offset)
1633 unsigned short *d = (unsigned short *)
1634 (vc->vc_origin + vc->vc_size_row * line);
1635 unsigned short *s = d + offset;
1638 unsigned short *start = s;
1639 unsigned short *le = advance_row(s, 1);
1642 unsigned short attr = 1;
1646 if (attr != (c & 0xff00)) {
1649 fbcon_putcs(vc, start, s - start,
1655 if (c == scr_readw(d)) {
1657 fbcon_putcs(vc, start, s - start,
1667 console_conditional_schedule();
1672 fbcon_putcs(vc, start, s - start, line, x);
1673 console_conditional_schedule();
1678 /* NOTE: We subtract two lines from these pointers */
1679 s -= vc->vc_size_row;
1680 d -= vc->vc_size_row;
1685 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1686 enum con_scroll dir, unsigned int count)
1688 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1689 struct fbcon_display *p = &fb_display[vc->vc_num];
1690 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1692 if (fbcon_is_inactive(vc, info))
1695 fbcon_cursor(vc, CM_ERASE);
1698 * ++Geert: Only use ywrap/ypan if the console is in text mode
1699 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1700 * whole screen (prevents flicker).
1705 if (count > vc->vc_rows) /* Maximum realistic size */
1706 count = vc->vc_rows;
1707 if (logo_shown >= 0)
1709 switch (fb_scrollmode(p)) {
1711 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1713 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1714 scr_memsetw((unsigned short *) (vc->vc_origin +
1717 vc->vc_video_erase_char,
1718 vc->vc_size_row * count);
1721 case SCROLL_WRAP_MOVE:
1722 if (b - t - count > 3 * vc->vc_rows >> 2) {
1724 fbcon_bmove(vc, 0, 0, count, 0, t,
1726 ywrap_up(vc, count);
1727 if (vc->vc_rows - b > 0)
1728 fbcon_bmove(vc, b - count, 0, b, 0,
1731 } else if (info->flags & FBINFO_READS_FAST)
1732 fbcon_bmove(vc, t + count, 0, t, 0,
1733 b - t - count, vc->vc_cols);
1736 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1739 case SCROLL_PAN_REDRAW:
1740 if ((p->yscroll + count <=
1741 2 * (p->vrows - vc->vc_rows))
1742 && ((!scroll_partial && (b - t == vc->vc_rows))
1745 3 * vc->vc_rows >> 2)))) {
1747 fbcon_redraw_move(vc, p, 0, t, count);
1748 ypan_up_redraw(vc, t, count);
1749 if (vc->vc_rows - b > 0)
1750 fbcon_redraw_move(vc, p, b,
1751 vc->vc_rows - b, b);
1753 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1754 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1757 case SCROLL_PAN_MOVE:
1758 if ((p->yscroll + count <=
1759 2 * (p->vrows - vc->vc_rows))
1760 && ((!scroll_partial && (b - t == vc->vc_rows))
1763 3 * vc->vc_rows >> 2)))) {
1765 fbcon_bmove(vc, 0, 0, count, 0, t,
1768 if (vc->vc_rows - b > 0)
1769 fbcon_bmove(vc, b - count, 0, b, 0,
1772 } else if (info->flags & FBINFO_READS_FAST)
1773 fbcon_bmove(vc, t + count, 0, t, 0,
1774 b - t - count, vc->vc_cols);
1777 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1782 fbcon_redraw(vc, p, t, b - t - count,
1783 count * vc->vc_cols);
1784 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1785 scr_memsetw((unsigned short *) (vc->vc_origin +
1788 vc->vc_video_erase_char,
1789 vc->vc_size_row * count);
1795 if (count > vc->vc_rows) /* Maximum realistic size */
1796 count = vc->vc_rows;
1797 if (logo_shown >= 0)
1799 switch (fb_scrollmode(p)) {
1801 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1803 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1804 scr_memsetw((unsigned short *) (vc->vc_origin +
1807 vc->vc_video_erase_char,
1808 vc->vc_size_row * count);
1811 case SCROLL_WRAP_MOVE:
1812 if (b - t - count > 3 * vc->vc_rows >> 2) {
1813 if (vc->vc_rows - b > 0)
1814 fbcon_bmove(vc, b, 0, b - count, 0,
1817 ywrap_down(vc, count);
1819 fbcon_bmove(vc, count, 0, 0, 0, t,
1821 } else if (info->flags & FBINFO_READS_FAST)
1822 fbcon_bmove(vc, t, 0, t + count, 0,
1823 b - t - count, vc->vc_cols);
1826 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1829 case SCROLL_PAN_MOVE:
1830 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1831 && ((!scroll_partial && (b - t == vc->vc_rows))
1834 3 * vc->vc_rows >> 2)))) {
1835 if (vc->vc_rows - b > 0)
1836 fbcon_bmove(vc, b, 0, b - count, 0,
1839 ypan_down(vc, count);
1841 fbcon_bmove(vc, count, 0, 0, 0, t,
1843 } else if (info->flags & FBINFO_READS_FAST)
1844 fbcon_bmove(vc, t, 0, t + count, 0,
1845 b - t - count, vc->vc_cols);
1848 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1851 case SCROLL_PAN_REDRAW:
1852 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1853 && ((!scroll_partial && (b - t == vc->vc_rows))
1856 3 * vc->vc_rows >> 2)))) {
1857 if (vc->vc_rows - b > 0)
1858 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1860 ypan_down_redraw(vc, t, count);
1862 fbcon_redraw_move(vc, p, count, t, 0);
1864 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1865 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1870 fbcon_redraw(vc, p, b - 1, b - t - count,
1871 -count * vc->vc_cols);
1872 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1873 scr_memsetw((unsigned short *) (vc->vc_origin +
1876 vc->vc_video_erase_char,
1877 vc->vc_size_row * count);
1885 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1886 int height, int width)
1888 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1889 struct fbcon_display *p = &fb_display[vc->vc_num];
1891 if (fbcon_is_inactive(vc, info))
1894 if (!width || !height)
1897 /* Split blits that cross physical y_wrap case.
1898 * Pathological case involves 4 blits, better to use recursive
1899 * code rather than unrolled case
1901 * Recursive invocations don't need to erase the cursor over and
1902 * over again, so we use fbcon_bmove_rec()
1904 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1905 p->vrows - p->yscroll);
1908 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
1909 int dy, int dx, int height, int width, u_int y_break)
1911 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1912 struct fbcon_ops *ops = info->fbcon_par;
1915 if (sy < y_break && sy + height > y_break) {
1917 if (dy < sy) { /* Avoid trashing self */
1918 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1920 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1921 height - b, width, y_break);
1923 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1924 height - b, width, y_break);
1925 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1931 if (dy < y_break && dy + height > y_break) {
1933 if (dy < sy) { /* Avoid trashing self */
1934 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1936 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1937 height - b, width, y_break);
1939 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1940 height - b, width, y_break);
1941 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1946 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1950 static void updatescrollmode_accel(struct fbcon_display *p,
1951 struct fb_info *info,
1954 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1955 struct fbcon_ops *ops = info->fbcon_par;
1956 int cap = info->flags;
1958 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1959 info->fix.xpanstep);
1960 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1961 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1962 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1963 info->var.xres_virtual);
1964 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1965 divides(ypan, vc->vc_font.height) && vyres > yres;
1966 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1967 divides(ywrap, vc->vc_font.height) &&
1968 divides(vc->vc_font.height, vyres) &&
1969 divides(vc->vc_font.height, yres);
1970 int reading_fast = cap & FBINFO_READS_FAST;
1971 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1972 !(cap & FBINFO_HWACCEL_DISABLED);
1973 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1974 !(cap & FBINFO_HWACCEL_DISABLED);
1976 if (good_wrap || good_pan) {
1977 if (reading_fast || fast_copyarea)
1978 p->scrollmode = good_wrap ?
1979 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1981 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1984 if (reading_fast || (fast_copyarea && !fast_imageblit))
1985 p->scrollmode = SCROLL_MOVE;
1987 p->scrollmode = SCROLL_REDRAW;
1992 static void updatescrollmode(struct fbcon_display *p,
1993 struct fb_info *info,
1996 struct fbcon_ops *ops = info->fbcon_par;
1997 int fh = vc->vc_font.height;
1998 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1999 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2000 info->var.xres_virtual);
2002 p->vrows = vyres/fh;
2003 if (yres > (fh * (vc->vc_rows + 1)))
2004 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2005 if ((yres % fh) && (vyres % fh < yres % fh))
2008 /* update scrollmode in case hardware acceleration is used */
2009 updatescrollmode_accel(p, info, vc);
2012 #define PITCH(w) (((w) + 7) >> 3)
2013 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
2015 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2016 unsigned int height, unsigned int user)
2018 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2019 struct fbcon_ops *ops = info->fbcon_par;
2020 struct fbcon_display *p = &fb_display[vc->vc_num];
2021 struct fb_var_screeninfo var = info->var;
2022 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2024 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
2026 int pitch = PITCH(vc->vc_font.width);
2029 * If user font, ensure that a possible change to user font
2030 * height or width will not allow a font data out-of-bounds access.
2031 * NOTE: must use original charcount in calculation as font
2032 * charcount can change and cannot be used to determine the
2033 * font data allocated size.
2037 size = CALC_FONTSZ(vc->vc_font.height, pitch, vc->vc_font.charcount);
2038 if (size > FNTSIZE(vc->vc_font.data))
2042 virt_w = FBCON_SWAP(ops->rotate, width, height);
2043 virt_h = FBCON_SWAP(ops->rotate, height, width);
2044 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2045 vc->vc_font.height);
2046 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2048 var.xres = virt_w * virt_fw;
2049 var.yres = virt_h * virt_fh;
2050 x_diff = info->var.xres - var.xres;
2051 y_diff = info->var.yres - var.yres;
2052 if (x_diff < 0 || x_diff > virt_fw ||
2053 y_diff < 0 || y_diff > virt_fh) {
2054 const struct fb_videomode *mode;
2056 pr_debug("attempting resize %ix%i\n", var.xres, var.yres);
2057 mode = fb_find_best_mode(&var, &info->modelist);
2060 display_to_var(&var, p);
2061 fb_videomode_to_var(&var, mode);
2063 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2066 pr_debug("resize now %ix%i\n", var.xres, var.yres);
2067 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
2068 var.activate = FB_ACTIVATE_NOW |
2070 fb_set_var(info, &var);
2072 var_to_display(p, &info->var, info);
2073 ops->var = info->var;
2075 updatescrollmode(p, info, vc);
2079 static int fbcon_switch(struct vc_data *vc)
2081 struct fb_info *info, *old_info = NULL;
2082 struct fbcon_ops *ops;
2083 struct fbcon_display *p = &fb_display[vc->vc_num];
2084 struct fb_var_screeninfo var;
2085 int i, ret, prev_console;
2087 info = registered_fb[con2fb_map[vc->vc_num]];
2088 ops = info->fbcon_par;
2090 if (logo_shown >= 0) {
2091 struct vc_data *conp2 = vc_cons[logo_shown].d;
2093 if (conp2->vc_top == logo_lines
2094 && conp2->vc_bottom == conp2->vc_rows)
2096 logo_shown = FBCON_LOGO_CANSHOW;
2099 prev_console = ops->currcon;
2100 if (prev_console != -1)
2101 old_info = registered_fb[con2fb_map[prev_console]];
2103 * FIXME: If we have multiple fbdev's loaded, we need to
2104 * update all info->currcon. Perhaps, we can place this
2105 * in a centralized structure, but this might break some
2108 * info->currcon = vc->vc_num;
2110 for_each_registered_fb(i) {
2111 if (registered_fb[i]->fbcon_par) {
2112 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2114 o->currcon = vc->vc_num;
2117 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2118 display_to_var(&var, p);
2119 var.activate = FB_ACTIVATE_NOW;
2122 * make sure we don't unnecessarily trip the memcmp()
2125 info->var.activate = var.activate;
2126 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2127 fb_set_var(info, &var);
2128 ops->var = info->var;
2130 if (old_info != NULL && (old_info != info ||
2131 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2132 if (info->fbops->fb_set_par) {
2133 ret = info->fbops->fb_set_par(info);
2136 printk(KERN_ERR "fbcon_switch: detected "
2137 "unhandled fb_set_par error, "
2138 "error code %d\n", ret);
2141 if (old_info != info)
2142 fbcon_del_cursor_timer(old_info);
2145 if (fbcon_is_inactive(vc, info) ||
2146 ops->blank_state != FB_BLANK_UNBLANK)
2147 fbcon_del_cursor_timer(info);
2149 fbcon_add_cursor_timer(info);
2151 set_blitting_type(vc, info);
2152 ops->cursor_reset = 1;
2154 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2155 ops->rotate = FB_ROTATE_UR;
2156 set_blitting_type(vc, info);
2159 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2160 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2162 if (vc->vc_font.charcount > 256)
2163 vc->vc_complement_mask <<= 1;
2165 updatescrollmode(p, info, vc);
2167 switch (fb_scrollmode(p)) {
2168 case SCROLL_WRAP_MOVE:
2169 scrollback_phys_max = p->vrows - vc->vc_rows;
2171 case SCROLL_PAN_MOVE:
2172 case SCROLL_PAN_REDRAW:
2173 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2174 if (scrollback_phys_max < 0)
2175 scrollback_phys_max = 0;
2178 scrollback_phys_max = 0;
2183 scrollback_current = 0;
2185 if (!fbcon_is_inactive(vc, info)) {
2186 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2187 ops->update_start(info);
2190 fbcon_set_palette(vc, color_table);
2191 fbcon_clear_margins(vc, 0);
2193 if (logo_shown == FBCON_LOGO_DRAW) {
2195 logo_shown = fg_console;
2196 /* This is protected above by initmem_freed */
2197 fb_show_logo(info, ops->rotate);
2199 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2200 vc->vc_size_row * (vc->vc_bottom -
2207 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2211 unsigned short charmask = vc->vc_hi_font_mask ?
2213 unsigned short oldc;
2215 oldc = vc->vc_video_erase_char;
2216 vc->vc_video_erase_char &= charmask;
2217 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2218 vc->vc_video_erase_char = oldc;
2222 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2224 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2225 struct fbcon_ops *ops = info->fbcon_par;
2228 struct fb_var_screeninfo var = info->var;
2233 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE |
2234 FB_ACTIVATE_KD_TEXT;
2235 fb_set_var(info, &var);
2237 ops->var = info->var;
2241 if (!fbcon_is_inactive(vc, info)) {
2242 if (ops->blank_state != blank) {
2243 ops->blank_state = blank;
2244 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2245 ops->cursor_flash = (!blank);
2247 if (fb_blank(info, blank))
2248 fbcon_generic_blank(vc, info, blank);
2255 if (mode_switch || fbcon_is_inactive(vc, info) ||
2256 ops->blank_state != FB_BLANK_UNBLANK)
2257 fbcon_del_cursor_timer(info);
2259 fbcon_add_cursor_timer(info);
2264 static int fbcon_debug_enter(struct vc_data *vc)
2266 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2267 struct fbcon_ops *ops = info->fbcon_par;
2269 ops->save_graphics = ops->graphics;
2271 if (info->fbops->fb_debug_enter)
2272 info->fbops->fb_debug_enter(info);
2273 fbcon_set_palette(vc, color_table);
2277 static int fbcon_debug_leave(struct vc_data *vc)
2279 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2280 struct fbcon_ops *ops = info->fbcon_par;
2282 ops->graphics = ops->save_graphics;
2283 if (info->fbops->fb_debug_leave)
2284 info->fbops->fb_debug_leave(info);
2288 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2290 u8 *fontdata = vc->vc_font.data;
2291 u8 *data = font->data;
2294 font->width = vc->vc_font.width;
2295 font->height = vc->vc_font.height;
2296 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2300 if (font->width <= 8) {
2301 j = vc->vc_font.height;
2302 if (font->charcount * j > FNTSIZE(fontdata))
2305 for (i = 0; i < font->charcount; i++) {
2306 memcpy(data, fontdata, j);
2307 memset(data + j, 0, 32 - j);
2311 } else if (font->width <= 16) {
2312 j = vc->vc_font.height * 2;
2313 if (font->charcount * j > FNTSIZE(fontdata))
2316 for (i = 0; i < font->charcount; i++) {
2317 memcpy(data, fontdata, j);
2318 memset(data + j, 0, 64 - j);
2322 } else if (font->width <= 24) {
2323 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
2326 for (i = 0; i < font->charcount; i++) {
2327 for (j = 0; j < vc->vc_font.height; j++) {
2328 *data++ = fontdata[0];
2329 *data++ = fontdata[1];
2330 *data++ = fontdata[2];
2331 fontdata += sizeof(u32);
2333 memset(data, 0, 3 * (32 - j));
2334 data += 3 * (32 - j);
2337 j = vc->vc_font.height * 4;
2338 if (font->charcount * j > FNTSIZE(fontdata))
2341 for (i = 0; i < font->charcount; i++) {
2342 memcpy(data, fontdata, j);
2343 memset(data + j, 0, 128 - j);
2351 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2352 static void set_vc_hi_font(struct vc_data *vc, bool set)
2355 vc->vc_hi_font_mask = 0;
2356 if (vc->vc_can_do_color) {
2357 vc->vc_complement_mask >>= 1;
2358 vc->vc_s_complement_mask >>= 1;
2361 /* ++Edmund: reorder the attribute bits */
2362 if (vc->vc_can_do_color) {
2363 unsigned short *cp =
2364 (unsigned short *) vc->vc_origin;
2365 int count = vc->vc_screenbuf_size / 2;
2367 for (; count > 0; count--, cp++) {
2369 scr_writew(((c & 0xfe00) >> 1) |
2372 c = vc->vc_video_erase_char;
2373 vc->vc_video_erase_char =
2374 ((c & 0xfe00) >> 1) | (c & 0xff);
2378 vc->vc_hi_font_mask = 0x100;
2379 if (vc->vc_can_do_color) {
2380 vc->vc_complement_mask <<= 1;
2381 vc->vc_s_complement_mask <<= 1;
2384 /* ++Edmund: reorder the attribute bits */
2386 unsigned short *cp =
2387 (unsigned short *) vc->vc_origin;
2388 int count = vc->vc_screenbuf_size / 2;
2390 for (; count > 0; count--, cp++) {
2391 unsigned short newc;
2393 if (vc->vc_can_do_color)
2395 ((c & 0xff00) << 1) | (c &
2399 scr_writew(newc, cp);
2401 c = vc->vc_video_erase_char;
2402 if (vc->vc_can_do_color) {
2403 vc->vc_video_erase_char =
2404 ((c & 0xff00) << 1) | (c & 0xff);
2407 vc->vc_video_erase_char = c & ~0x100;
2412 static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
2413 const u8 * data, int userfont)
2415 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2416 struct fbcon_ops *ops = info->fbcon_par;
2417 struct fbcon_display *p = &fb_display[vc->vc_num];
2419 char *old_data = NULL;
2421 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2423 old_data = vc->vc_font.data;
2424 vc->vc_font.data = (void *)(p->fontdata = data);
2425 if ((p->userfont = userfont))
2427 vc->vc_font.width = w;
2428 vc->vc_font.height = h;
2429 vc->vc_font.charcount = charcount;
2430 if (vc->vc_hi_font_mask && charcount == 256)
2431 set_vc_hi_font(vc, false);
2432 else if (!vc->vc_hi_font_mask && charcount == 512)
2433 set_vc_hi_font(vc, true);
2438 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2439 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2442 vc_resize(vc, cols, rows);
2443 } else if (con_is_visible(vc)
2444 && vc->vc_mode == KD_TEXT) {
2445 fbcon_clear_margins(vc, 0);
2449 if (old_data && (--REFCOUNT(old_data) == 0))
2450 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2455 * User asked to set font; we are guaranteed that
2456 * a) width and height are in range 1..32
2457 * b) charcount does not exceed 512
2458 * but lets not assume that, since someone might someday want to use larger
2459 * fonts. And charcount of 512 is small for unicode support.
2461 * However, user space gives the font in 32 rows , regardless of
2462 * actual font height. So a new API is needed if support for larger fonts
2463 * is ever implemented.
2466 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2470 unsigned charcount = font->charcount;
2471 int w = font->width;
2472 int h = font->height;
2475 u8 *new_data, *data = font->data;
2476 int pitch = PITCH(font->width);
2478 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2479 * If not this check should be changed to charcount < 256 */
2480 if (charcount != 256 && charcount != 512)
2483 /* Make sure drawing engine can handle the font */
2484 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2485 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2488 /* Make sure driver can handle the font length */
2489 if (fbcon_invalid_charcount(info, charcount))
2492 size = CALC_FONTSZ(h, pitch, charcount);
2494 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2499 memset(new_data, 0, FONT_EXTRA_WORDS * sizeof(int));
2501 new_data += FONT_EXTRA_WORDS * sizeof(int);
2502 FNTSIZE(new_data) = size;
2503 REFCOUNT(new_data) = 0; /* usage counter */
2504 for (i=0; i< charcount; i++) {
2505 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2508 /* Since linux has a nice crc32 function use it for counting font
2510 csum = crc32(0, new_data, size);
2512 FNTSUM(new_data) = csum;
2513 /* Check if the same font is on some other console already */
2514 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2515 struct vc_data *tmp = vc_cons[i].d;
2517 if (fb_display[i].userfont &&
2518 fb_display[i].fontdata &&
2519 FNTSUM(fb_display[i].fontdata) == csum &&
2520 FNTSIZE(fb_display[i].fontdata) == size &&
2521 tmp->vc_font.width == w &&
2522 !memcmp(fb_display[i].fontdata, new_data, size)) {
2523 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2524 new_data = (u8 *)fb_display[i].fontdata;
2528 return fbcon_do_set_font(vc, font->width, font->height, charcount, new_data, 1);
2531 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2533 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2534 const struct font_desc *f;
2537 f = get_default_font(info->var.xres, info->var.yres,
2538 info->pixmap.blit_x, info->pixmap.blit_y);
2539 else if (!(f = find_font(name)))
2542 font->width = f->width;
2543 font->height = f->height;
2544 return fbcon_do_set_font(vc, f->width, f->height, f->charcount, f->data, 0);
2547 static u16 palette_red[16];
2548 static u16 palette_green[16];
2549 static u16 palette_blue[16];
2551 static struct fb_cmap palette_cmap = {
2552 0, 16, palette_red, palette_green, palette_blue, NULL
2555 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2557 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2561 if (fbcon_is_inactive(vc, info))
2564 if (!con_is_visible(vc))
2567 depth = fb_get_color_depth(&info->var, &info->fix);
2569 for (i = j = 0; i < 16; i++) {
2571 val = vc->vc_palette[j++];
2572 palette_red[k] = (val << 8) | val;
2573 val = vc->vc_palette[j++];
2574 palette_green[k] = (val << 8) | val;
2575 val = vc->vc_palette[j++];
2576 palette_blue[k] = (val << 8) | val;
2578 palette_cmap.len = 16;
2579 palette_cmap.start = 0;
2581 * If framebuffer is capable of less than 16 colors,
2582 * use default palette of fbcon.
2585 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2587 fb_set_cmap(&palette_cmap, info);
2590 static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset)
2592 return (u16 *) (vc->vc_origin + offset);
2595 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2601 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2602 unsigned long offset = (pos - vc->vc_origin) / 2;
2604 x = offset % vc->vc_cols;
2605 y = offset / vc->vc_cols;
2606 ret = pos + (vc->vc_cols - x) * 2;
2608 /* Should not happen */
2610 ret = vc->vc_origin;
2619 /* As we might be inside of softback, we may work with non-contiguous buffer,
2620 that's why we have to use a separate routine. */
2621 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2624 u16 a = scr_readw(p);
2625 if (!vc->vc_can_do_color)
2627 else if (vc->vc_hi_font_mask == 0x100)
2628 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2629 (((a) & 0x0e00) << 4);
2631 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2632 (((a) & 0x0700) << 4);
2637 void fbcon_suspended(struct fb_info *info)
2639 struct vc_data *vc = NULL;
2640 struct fbcon_ops *ops = info->fbcon_par;
2642 if (!ops || ops->currcon < 0)
2644 vc = vc_cons[ops->currcon].d;
2646 /* Clear cursor, restore saved data */
2647 fbcon_cursor(vc, CM_ERASE);
2650 void fbcon_resumed(struct fb_info *info)
2653 struct fbcon_ops *ops = info->fbcon_par;
2655 if (!ops || ops->currcon < 0)
2657 vc = vc_cons[ops->currcon].d;
2662 static void fbcon_modechanged(struct fb_info *info)
2664 struct fbcon_ops *ops = info->fbcon_par;
2666 struct fbcon_display *p;
2669 if (!ops || ops->currcon < 0)
2671 vc = vc_cons[ops->currcon].d;
2672 if (vc->vc_mode != KD_TEXT ||
2673 registered_fb[con2fb_map[ops->currcon]] != info)
2676 p = &fb_display[vc->vc_num];
2677 set_blitting_type(vc, info);
2679 if (con_is_visible(vc)) {
2680 var_to_display(p, &info->var, info);
2681 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2682 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2683 cols /= vc->vc_font.width;
2684 rows /= vc->vc_font.height;
2685 vc_resize(vc, cols, rows);
2686 updatescrollmode(p, info, vc);
2688 scrollback_current = 0;
2690 if (!fbcon_is_inactive(vc, info)) {
2691 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2692 ops->update_start(info);
2695 fbcon_set_palette(vc, color_table);
2700 static void fbcon_set_all_vcs(struct fb_info *info)
2702 struct fbcon_ops *ops = info->fbcon_par;
2704 struct fbcon_display *p;
2705 int i, rows, cols, fg = -1;
2707 if (!ops || ops->currcon < 0)
2710 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2712 if (!vc || vc->vc_mode != KD_TEXT ||
2713 registered_fb[con2fb_map[i]] != info)
2716 if (con_is_visible(vc)) {
2721 p = &fb_display[vc->vc_num];
2722 set_blitting_type(vc, info);
2723 var_to_display(p, &info->var, info);
2724 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2725 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2726 cols /= vc->vc_font.width;
2727 rows /= vc->vc_font.height;
2728 vc_resize(vc, cols, rows);
2732 fbcon_modechanged(info);
2736 void fbcon_update_vcs(struct fb_info *info, bool all)
2739 fbcon_set_all_vcs(info);
2741 fbcon_modechanged(info);
2743 EXPORT_SYMBOL(fbcon_update_vcs);
2745 int fbcon_mode_deleted(struct fb_info *info,
2746 struct fb_videomode *mode)
2748 struct fb_info *fb_info;
2749 struct fbcon_display *p;
2750 int i, j, found = 0;
2752 /* before deletion, ensure that mode is not in use */
2753 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2757 fb_info = registered_fb[j];
2758 if (fb_info != info)
2763 if (fb_mode_is_equal(p->mode, mode)) {
2771 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2772 static void fbcon_unbind(void)
2776 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2780 fbcon_has_console_bind = 0;
2783 static inline void fbcon_unbind(void) {}
2784 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2786 /* called with console_lock held */
2787 void fbcon_fb_unbind(struct fb_info *info)
2789 int i, new_idx = -1, ret = 0;
2790 int idx = info->node;
2792 WARN_CONSOLE_UNLOCKED();
2794 if (!fbcon_has_console_bind)
2797 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2798 if (con2fb_map[i] != idx &&
2799 con2fb_map[i] != -1) {
2800 new_idx = con2fb_map[i];
2805 if (new_idx != -1) {
2806 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2807 if (con2fb_map[i] == idx)
2808 set_con2fb_map(i, new_idx, 0);
2811 struct fb_info *info = registered_fb[idx];
2813 /* This is sort of like set_con2fb_map, except it maps
2814 * the consoles to no device and then releases the
2815 * oldinfo to free memory and cancel the cursor blink
2816 * timer. I can imagine this just becoming part of
2817 * set_con2fb_map where new_idx is -1
2819 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2820 if (con2fb_map[i] == idx) {
2822 if (!search_fb_in_map(idx)) {
2823 ret = con2fb_release_oldinfo(vc_cons[i].d,
2827 con2fb_map[i] = idx;
2837 /* called with console_lock held */
2838 void fbcon_fb_unregistered(struct fb_info *info)
2842 WARN_CONSOLE_UNLOCKED();
2844 if (deferred_takeover)
2848 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2849 if (con2fb_map[i] == idx)
2853 if (idx == info_idx) {
2856 for_each_registered_fb(i) {
2862 if (info_idx != -1) {
2863 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2864 if (con2fb_map[i] == -1)
2865 con2fb_map[i] = info_idx;
2869 if (primary_device == idx)
2870 primary_device = -1;
2872 if (!num_registered_fb)
2873 do_unregister_con_driver(&fb_con);
2876 void fbcon_remap_all(struct fb_info *info)
2878 int i, idx = info->node;
2881 if (deferred_takeover) {
2882 for (i = first_fb_vc; i <= last_fb_vc; i++)
2883 con2fb_map_boot[i] = idx;
2884 fbcon_map_override();
2889 for (i = first_fb_vc; i <= last_fb_vc; i++)
2890 set_con2fb_map(i, idx, 0);
2892 if (con_is_bound(&fb_con)) {
2893 printk(KERN_INFO "fbcon: Remapping primary device, "
2894 "fb%i, to tty %i-%i\n", idx,
2895 first_fb_vc + 1, last_fb_vc + 1);
2901 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2902 static void fbcon_select_primary(struct fb_info *info)
2904 if (!map_override && primary_device == -1 &&
2905 fb_is_primary_device(info)) {
2908 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2909 info->fix.id, info->node);
2910 primary_device = info->node;
2912 for (i = first_fb_vc; i <= last_fb_vc; i++)
2913 con2fb_map_boot[i] = primary_device;
2915 if (con_is_bound(&fb_con)) {
2916 printk(KERN_INFO "fbcon: Remapping primary device, "
2917 "fb%i, to tty %i-%i\n", info->node,
2918 first_fb_vc + 1, last_fb_vc + 1);
2919 info_idx = primary_device;
2925 static inline void fbcon_select_primary(struct fb_info *info)
2929 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2931 /* called with console_lock held */
2932 int fbcon_fb_registered(struct fb_info *info)
2934 int ret = 0, i, idx;
2936 WARN_CONSOLE_UNLOCKED();
2939 fbcon_select_primary(info);
2941 if (deferred_takeover) {
2942 pr_info("fbcon: Deferring console take-over\n");
2946 if (info_idx == -1) {
2947 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2948 if (con2fb_map_boot[i] == idx) {
2955 ret = do_fbcon_takeover(1);
2957 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2958 if (con2fb_map_boot[i] == idx)
2959 set_con2fb_map(i, idx, 0);
2966 void fbcon_fb_blanked(struct fb_info *info, int blank)
2968 struct fbcon_ops *ops = info->fbcon_par;
2971 if (!ops || ops->currcon < 0)
2974 vc = vc_cons[ops->currcon].d;
2975 if (vc->vc_mode != KD_TEXT ||
2976 registered_fb[con2fb_map[ops->currcon]] != info)
2979 if (con_is_visible(vc)) {
2983 do_unblank_screen(0);
2985 ops->blank_state = blank;
2988 void fbcon_new_modelist(struct fb_info *info)
2992 struct fb_var_screeninfo var;
2993 const struct fb_videomode *mode;
2995 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2996 if (registered_fb[con2fb_map[i]] != info)
2998 if (!fb_display[i].mode)
3001 display_to_var(&var, &fb_display[i]);
3002 mode = fb_find_nearest_mode(fb_display[i].mode,
3004 fb_videomode_to_var(&var, mode);
3005 fbcon_set_disp(info, &var, vc->vc_num);
3009 void fbcon_get_requirement(struct fb_info *info,
3010 struct fb_blit_caps *caps)
3017 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3019 if (vc && vc->vc_mode == KD_TEXT &&
3020 info->node == con2fb_map[i]) {
3021 caps->x |= 1 << (vc->vc_font.width - 1);
3022 caps->y |= 1 << (vc->vc_font.height - 1);
3023 charcnt = vc->vc_font.charcount;
3024 if (caps->len < charcnt)
3025 caps->len = charcnt;
3029 vc = vc_cons[fg_console].d;
3031 if (vc && vc->vc_mode == KD_TEXT &&
3032 info->node == con2fb_map[fg_console]) {
3033 caps->x = 1 << (vc->vc_font.width - 1);
3034 caps->y = 1 << (vc->vc_font.height - 1);
3035 caps->len = vc->vc_font.charcount;
3040 int fbcon_set_con2fb_map_ioctl(void __user *argp)
3042 struct fb_con2fbmap con2fb;
3045 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3047 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3049 if (con2fb.framebuffer >= FB_MAX)
3051 if (!registered_fb[con2fb.framebuffer])
3052 request_module("fb%d", con2fb.framebuffer);
3053 if (!registered_fb[con2fb.framebuffer]) {
3058 ret = set_con2fb_map(con2fb.console - 1,
3059 con2fb.framebuffer, 1);
3065 int fbcon_get_con2fb_map_ioctl(void __user *argp)
3067 struct fb_con2fbmap con2fb;
3069 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3071 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3075 con2fb.framebuffer = con2fb_map[con2fb.console - 1];
3078 return copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
3082 * The console `switch' structure for the frame buffer based console
3085 static const struct consw fb_con = {
3086 .owner = THIS_MODULE,
3087 .con_startup = fbcon_startup,
3088 .con_init = fbcon_init,
3089 .con_deinit = fbcon_deinit,
3090 .con_clear = fbcon_clear,
3091 .con_putc = fbcon_putc,
3092 .con_putcs = fbcon_putcs,
3093 .con_cursor = fbcon_cursor,
3094 .con_scroll = fbcon_scroll,
3095 .con_switch = fbcon_switch,
3096 .con_blank = fbcon_blank,
3097 .con_font_set = fbcon_set_font,
3098 .con_font_get = fbcon_get_font,
3099 .con_font_default = fbcon_set_def_font,
3100 .con_set_palette = fbcon_set_palette,
3101 .con_invert_region = fbcon_invert_region,
3102 .con_screen_pos = fbcon_screen_pos,
3103 .con_getxy = fbcon_getxy,
3104 .con_resize = fbcon_resize,
3105 .con_debug_enter = fbcon_debug_enter,
3106 .con_debug_leave = fbcon_debug_leave,
3109 static ssize_t store_rotate(struct device *device,
3110 struct device_attribute *attr, const char *buf,
3113 struct fb_info *info;
3118 idx = con2fb_map[fg_console];
3120 if (idx == -1 || registered_fb[idx] == NULL)
3123 info = registered_fb[idx];
3124 rotate = simple_strtoul(buf, last, 0);
3125 fbcon_rotate(info, rotate);
3131 static ssize_t store_rotate_all(struct device *device,
3132 struct device_attribute *attr,const char *buf,
3135 struct fb_info *info;
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;
3160 idx = con2fb_map[fg_console];
3162 if (idx == -1 || registered_fb[idx] == NULL)
3165 info = registered_fb[idx];
3166 rotate = fbcon_get_rotate(info);
3169 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3172 static ssize_t show_cursor_blink(struct device *device,
3173 struct device_attribute *attr, char *buf)
3175 struct fb_info *info;
3176 struct fbcon_ops *ops;
3177 int idx, blink = -1;
3180 idx = con2fb_map[fg_console];
3182 if (idx == -1 || registered_fb[idx] == NULL)
3185 info = registered_fb[idx];
3186 ops = info->fbcon_par;
3191 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3194 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3197 static ssize_t store_cursor_blink(struct device *device,
3198 struct device_attribute *attr,
3199 const char *buf, size_t count)
3201 struct fb_info *info;
3206 idx = con2fb_map[fg_console];
3208 if (idx == -1 || registered_fb[idx] == NULL)
3211 info = registered_fb[idx];
3213 if (!info->fbcon_par)
3216 blink = simple_strtoul(buf, last, 0);
3219 fbcon_cursor_noblink = 0;
3220 fbcon_add_cursor_timer(info);
3222 fbcon_cursor_noblink = 1;
3223 fbcon_del_cursor_timer(info);
3231 static struct device_attribute device_attrs[] = {
3232 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3233 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3234 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3235 store_cursor_blink),
3238 static int fbcon_init_device(void)
3242 fbcon_has_sysfs = 1;
3244 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3245 error = device_create_file(fbcon_device, &device_attrs[i]);
3253 device_remove_file(fbcon_device, &device_attrs[i]);
3255 fbcon_has_sysfs = 0;
3261 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3262 static void fbcon_register_existing_fbs(struct work_struct *work)
3268 for_each_registered_fb(i)
3269 fbcon_fb_registered(registered_fb[i]);
3274 static struct notifier_block fbcon_output_nb;
3275 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3277 static int fbcon_output_notifier(struct notifier_block *nb,
3278 unsigned long action, void *data)
3280 WARN_CONSOLE_UNLOCKED();
3282 pr_info("fbcon: Taking over console\n");
3284 dummycon_unregister_output_notifier(&fbcon_output_nb);
3285 deferred_takeover = false;
3286 logo_shown = FBCON_LOGO_DONTSHOW;
3288 /* We may get called in atomic context */
3289 schedule_work(&fbcon_deferred_takeover_work);
3295 static void fbcon_start(void)
3297 WARN_CONSOLE_UNLOCKED();
3299 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3300 if (conswitchp != &dummy_con)
3301 deferred_takeover = false;
3303 if (deferred_takeover) {
3304 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3305 dummycon_register_output_notifier(&fbcon_output_nb);
3310 if (num_registered_fb) {
3313 for_each_registered_fb(i) {
3318 do_fbcon_takeover(0);
3322 static void fbcon_exit(void)
3324 struct fb_info *info;
3327 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3328 if (deferred_takeover) {
3329 dummycon_unregister_output_notifier(&fbcon_output_nb);
3330 deferred_takeover = false;
3334 for_each_registered_fb(i) {
3338 info = registered_fb[i];
3340 if (info->queue.func)
3341 pending = cancel_work_sync(&info->queue);
3342 pr_debug("fbcon: %s pending work\n", (pending ? "canceled" : "no"));
3344 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3345 if (con2fb_map[j] == i) {
3352 if (info->fbops->fb_release)
3353 info->fbops->fb_release(info, 0);
3354 module_put(info->fbops->owner);
3356 if (info->fbcon_par) {
3357 struct fbcon_ops *ops = info->fbcon_par;
3359 fbcon_del_cursor_timer(info);
3360 kfree(ops->cursor_src);
3361 kfree(ops->cursor_state.mask);
3362 kfree(info->fbcon_par);
3363 info->fbcon_par = NULL;
3366 if (info->queue.func == fb_flashcursor)
3367 info->queue.func = NULL;
3372 void __init fb_console_init(void)
3377 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3380 if (IS_ERR(fbcon_device)) {
3381 printk(KERN_WARNING "Unable to create device "
3382 "for fbcon; errno = %ld\n",
3383 PTR_ERR(fbcon_device));
3384 fbcon_device = NULL;
3386 fbcon_init_device();
3388 for (i = 0; i < MAX_NR_CONSOLES; i++)
3397 static void __exit fbcon_deinit_device(void)
3401 if (fbcon_has_sysfs) {
3402 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3403 device_remove_file(fbcon_device, &device_attrs[i]);
3405 fbcon_has_sysfs = 0;
3409 void __exit fb_console_exit(void)
3412 fbcon_deinit_device();
3413 device_destroy(fb_class, MKDEV(0, 0));
3415 do_unregister_con_driver(&fb_con);