2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
79 #include <linux/uaccess.h>
86 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
88 # define DPRINTK(fmt, args...)
94 * - fbcon state itself is protected by the console_lock, and the code does a
95 * pretty good job at making sure that lock is held everywhere it's needed.
97 * - access to the registered_fb array is entirely unprotected. This should use
98 * proper object lifetime handling, i.e. get/put_fb_info. This also means
99 * switching from indices to proper pointers for fb_info everywhere.
101 * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since it
102 * means concurrent access to the same fbdev from both fbcon and userspace
103 * will blow up. To fix this all fbcon calls from fbmem.c need to be moved out
104 * of fb_lock/unlock protected sections, since otherwise we'll recurse and
105 * deadlock eventually. Aside: Due to these deadlock issues the fbdev code in
106 * fbmem.c cannot use locking asserts, and there's lots of callers which get
107 * the rules wrong, e.g. fbsysfs.c entirely missed fb_lock/unlock calls too.
111 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
112 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
113 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
116 static struct fbcon_display fb_display[MAX_NR_CONSOLES];
118 static signed char con2fb_map[MAX_NR_CONSOLES];
119 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
121 static int logo_lines;
122 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
124 static int logo_shown = FBCON_LOGO_CANSHOW;
125 /* console mappings */
126 static int first_fb_vc;
127 static int last_fb_vc = MAX_NR_CONSOLES - 1;
128 static int fbcon_is_default = 1;
129 static int primary_device = -1;
130 static int fbcon_has_console_bind;
132 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
133 static int map_override;
135 static inline void fbcon_map_override(void)
140 static inline void fbcon_map_override(void)
143 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
145 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
146 static bool deferred_takeover = true;
148 #define deferred_takeover false
152 static char fontname[40];
154 /* current fb_info */
155 static int info_idx = -1;
157 /* console rotation */
158 static int initial_rotation = -1;
159 static int fbcon_has_sysfs;
160 static int margin_color;
162 static const struct consw fb_con;
164 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
166 static int fbcon_cursor_noblink;
168 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
171 * Interface used by the world
174 static const char *fbcon_startup(void);
175 static void fbcon_init(struct vc_data *vc, int init);
176 static void fbcon_deinit(struct vc_data *vc);
177 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
179 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
180 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
181 int count, int ypos, int xpos);
182 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
183 static void fbcon_cursor(struct vc_data *vc, int mode);
184 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
185 int height, int width);
186 static int fbcon_switch(struct vc_data *vc);
187 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
188 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
193 static __inline__ void ywrap_up(struct vc_data *vc, int count);
194 static __inline__ void ywrap_down(struct vc_data *vc, int count);
195 static __inline__ void ypan_up(struct vc_data *vc, int count);
196 static __inline__ void ypan_down(struct vc_data *vc, int count);
197 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
198 int dy, int dx, int height, int width, u_int y_break);
199 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
201 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
202 int line, int count, int dy);
203 static void fbcon_modechanged(struct fb_info *info);
204 static void fbcon_set_all_vcs(struct fb_info *info);
205 static void fbcon_start(void);
206 static void fbcon_exit(void);
207 static struct device *fbcon_device;
209 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
210 static inline void fbcon_set_rotation(struct fb_info *info)
212 struct fbcon_ops *ops = info->fbcon_par;
214 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
215 ops->p->con_rotate < 4)
216 ops->rotate = ops->p->con_rotate;
221 static void fbcon_rotate(struct fb_info *info, u32 rotate)
223 struct fbcon_ops *ops= info->fbcon_par;
224 struct fb_info *fb_info;
226 if (!ops || ops->currcon == -1)
229 fb_info = registered_fb[con2fb_map[ops->currcon]];
231 if (info == fb_info) {
232 struct fbcon_display *p = &fb_display[ops->currcon];
235 p->con_rotate = rotate;
239 fbcon_modechanged(info);
243 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
245 struct fbcon_ops *ops = info->fbcon_par;
247 struct fbcon_display *p;
250 if (!ops || ops->currcon < 0 || rotate > 3)
253 for (i = first_fb_vc; i <= last_fb_vc; i++) {
255 if (!vc || vc->vc_mode != KD_TEXT ||
256 registered_fb[con2fb_map[i]] != info)
259 p = &fb_display[vc->vc_num];
260 p->con_rotate = rotate;
263 fbcon_set_all_vcs(info);
266 static inline void fbcon_set_rotation(struct fb_info *info)
268 struct fbcon_ops *ops = info->fbcon_par;
270 ops->rotate = FB_ROTATE_UR;
273 static void fbcon_rotate(struct fb_info *info, u32 rotate)
278 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
282 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
284 static int fbcon_get_rotate(struct fb_info *info)
286 struct fbcon_ops *ops = info->fbcon_par;
288 return (ops) ? ops->rotate : 0;
291 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
293 struct fbcon_ops *ops = info->fbcon_par;
295 return (info->state != FBINFO_STATE_RUNNING ||
296 vc->vc_mode != KD_TEXT || ops->graphics);
299 static int get_color(struct vc_data *vc, struct fb_info *info,
302 int depth = fb_get_color_depth(&info->var, &info->fix);
305 if (console_blanked) {
306 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
308 c = vc->vc_video_erase_char & charmask;
312 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
313 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
318 int col = mono_col(info);
320 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
321 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
326 color = (is_fg) ? fg : bg;
331 * Scale down 16-colors to 4 colors. Default 4-color palette
332 * is grayscale. However, simply dividing the values by 4
333 * will not work, as colors 1, 2 and 3 will be scaled-down
334 * to zero rendering them invisible. So empirically convert
335 * colors to a sane 4-level grayscale.
339 color = 0; /* black */
342 color = 2; /* white */
345 color = 1; /* gray */
348 color = 3; /* intense white */
354 * Last 8 entries of default 16-color palette is a more intense
355 * version of the first 8 (i.e., same chrominance, different
366 static void fb_flashcursor(struct work_struct *work)
368 struct fb_info *info = container_of(work, struct fb_info, queue);
369 struct fbcon_ops *ops = info->fbcon_par;
370 struct vc_data *vc = NULL;
375 /* FIXME: we should sort out the unbind locking instead */
376 /* instead we just fail to flash the cursor if we can't get
377 * the lock instead of blocking fbcon deinit */
378 ret = console_trylock();
382 if (ops && ops->currcon != -1)
383 vc = vc_cons[ops->currcon].d;
385 if (!vc || !con_is_visible(vc) ||
386 registered_fb[con2fb_map[vc->vc_num]] != info ||
392 c = scr_readw((u16 *) vc->vc_pos);
393 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
395 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
396 get_color(vc, info, c, 0));
400 static void cursor_timer_handler(struct timer_list *t)
402 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
403 struct fb_info *info = ops->info;
405 queue_work(system_power_efficient_wq, &info->queue);
406 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
409 static void fbcon_add_cursor_timer(struct fb_info *info)
411 struct fbcon_ops *ops = info->fbcon_par;
413 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
414 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
415 !fbcon_cursor_noblink) {
416 if (!info->queue.func)
417 INIT_WORK(&info->queue, fb_flashcursor);
419 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
420 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
421 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
425 static void fbcon_del_cursor_timer(struct fb_info *info)
427 struct fbcon_ops *ops = info->fbcon_par;
429 if (info->queue.func == fb_flashcursor &&
430 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
431 del_timer_sync(&ops->cursor_timer);
432 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
437 static int __init fb_console_setup(char *this_opt)
442 if (!this_opt || !*this_opt)
445 while ((options = strsep(&this_opt, ",")) != NULL) {
446 if (!strncmp(options, "font:", 5)) {
447 strlcpy(fontname, options + 5, sizeof(fontname));
451 if (!strncmp(options, "scrollback:", 11)) {
452 pr_warn("Ignoring scrollback size option\n");
456 if (!strncmp(options, "map:", 4)) {
459 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
463 (options[j++]-'0') % FB_MAX;
466 fbcon_map_override();
471 if (!strncmp(options, "vc:", 3)) {
474 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
477 if (*options++ == '-')
478 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
479 fbcon_is_default = 0;
483 if (!strncmp(options, "rotate:", 7)) {
486 initial_rotation = simple_strtoul(options, &options, 0);
487 if (initial_rotation > 3)
488 initial_rotation = 0;
492 if (!strncmp(options, "margin:", 7)) {
495 margin_color = simple_strtoul(options, &options, 0);
498 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
499 if (!strcmp(options, "nodefer")) {
500 deferred_takeover = false;
505 if (!strncmp(options, "logo-pos:", 9)) {
507 if (!strcmp(options, "center"))
508 fb_center_logo = true;
512 if (!strncmp(options, "logo-count:", 11)) {
515 fb_logo_count = simple_strtol(options, &options, 0);
522 __setup("fbcon=", fb_console_setup);
525 static int search_fb_in_map(int idx)
529 for (i = first_fb_vc; i <= last_fb_vc; i++) {
530 if (con2fb_map[i] == idx)
536 static int search_for_mapped_con(void)
540 for (i = first_fb_vc; i <= last_fb_vc; i++) {
541 if (con2fb_map[i] != -1)
547 static int do_fbcon_takeover(int show_logo)
551 if (!num_registered_fb)
555 logo_shown = FBCON_LOGO_DONTSHOW;
557 for (i = first_fb_vc; i <= last_fb_vc; i++)
558 con2fb_map[i] = info_idx;
560 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
564 for (i = first_fb_vc; i <= last_fb_vc; i++)
568 fbcon_has_console_bind = 1;
575 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
576 int cols, int rows, int new_cols, int new_rows)
578 logo_shown = FBCON_LOGO_DONTSHOW;
581 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
582 int cols, int rows, int new_cols, int new_rows)
584 /* Need to make room for the logo */
585 struct fbcon_ops *ops = info->fbcon_par;
586 int cnt, erase = vc->vc_video_erase_char, step;
587 unsigned short *save = NULL, *r, *q;
590 if (info->fbops->owner) {
591 logo_shown = FBCON_LOGO_DONTSHOW;
596 * remove underline attribute from erase character
597 * if black and white framebuffer.
599 if (fb_get_color_depth(&info->var, &info->fix) == 1)
601 logo_height = fb_prepare_logo(info, ops->rotate);
602 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
603 q = (unsigned short *) (vc->vc_origin +
604 vc->vc_size_row * rows);
605 step = logo_lines * cols;
606 for (r = q - logo_lines * cols; r < q; r++)
607 if (scr_readw(r) != vc->vc_video_erase_char)
609 if (r != q && new_rows >= rows + logo_lines) {
610 save = kmalloc(array3_size(logo_lines, new_cols, 2),
613 int i = cols < new_cols ? cols : new_cols;
614 scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
616 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
617 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
622 /* We can scroll screen down */
624 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
625 scr_memcpyw(r + step, r, vc->vc_size_row);
630 if (vc->state.y + logo_lines >= rows)
631 lines = rows - vc->state.y - 1;
634 vc->state.y += lines;
635 vc->vc_pos += lines * vc->vc_size_row;
638 scr_memsetw((unsigned short *) vc->vc_origin,
640 vc->vc_size_row * logo_lines);
642 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
643 fbcon_clear_margins(vc, 0);
648 q = (unsigned short *) (vc->vc_origin +
651 scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
652 vc->state.y += logo_lines;
653 vc->vc_pos += logo_lines * vc->vc_size_row;
657 if (logo_shown == FBCON_LOGO_DONTSHOW)
660 if (logo_lines > vc->vc_bottom) {
661 logo_shown = FBCON_LOGO_CANSHOW;
663 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
665 logo_shown = FBCON_LOGO_DRAW;
666 vc->vc_top = logo_lines;
671 #ifdef CONFIG_FB_TILEBLITTING
672 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
674 struct fbcon_ops *ops = info->fbcon_par;
676 ops->p = &fb_display[vc->vc_num];
678 if ((info->flags & FBINFO_MISC_TILEBLITTING))
679 fbcon_set_tileops(vc, info);
681 fbcon_set_rotation(info);
682 fbcon_set_bitops(ops);
686 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
690 if (info->flags & FBINFO_MISC_TILEBLITTING &&
691 info->tileops->fb_get_tilemax(info) < charcount)
697 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
699 struct fbcon_ops *ops = info->fbcon_par;
701 info->flags &= ~FBINFO_MISC_TILEBLITTING;
702 ops->p = &fb_display[vc->vc_num];
703 fbcon_set_rotation(info);
704 fbcon_set_bitops(ops);
707 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
712 #endif /* CONFIG_MISC_TILEBLITTING */
715 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
716 int unit, int oldidx)
718 struct fbcon_ops *ops = NULL;
721 if (!try_module_get(info->fbops->owner))
724 if (!err && info->fbops->fb_open &&
725 info->fbops->fb_open(info, 0))
729 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
735 ops->cur_blink_jiffies = HZ / 5;
737 info->fbcon_par = ops;
740 set_blitting_type(vc, info);
744 con2fb_map[unit] = oldidx;
745 module_put(info->fbops->owner);
751 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
752 struct fb_info *newinfo, int unit,
753 int oldidx, int found)
755 struct fbcon_ops *ops = oldinfo->fbcon_par;
758 if (oldinfo->fbops->fb_release &&
759 oldinfo->fbops->fb_release(oldinfo, 0)) {
760 con2fb_map[unit] = oldidx;
761 if (!found && newinfo->fbops->fb_release)
762 newinfo->fbops->fb_release(newinfo, 0);
764 module_put(newinfo->fbops->owner);
769 fbcon_del_cursor_timer(oldinfo);
770 kfree(ops->cursor_state.mask);
771 kfree(ops->cursor_data);
772 kfree(ops->cursor_src);
773 kfree(ops->fontbuffer);
774 kfree(oldinfo->fbcon_par);
775 oldinfo->fbcon_par = NULL;
776 module_put(oldinfo->fbops->owner);
778 If oldinfo and newinfo are driving the same hardware,
779 the fb_release() method of oldinfo may attempt to
780 restore the hardware state. This will leave the
781 newinfo in an undefined state. Thus, a call to
782 fb_set_par() may be needed for the newinfo.
784 if (newinfo && newinfo->fbops->fb_set_par) {
785 ret = newinfo->fbops->fb_set_par(newinfo);
788 printk(KERN_ERR "con2fb_release_oldinfo: "
789 "detected unhandled fb_set_par error, "
790 "error code %d\n", ret);
797 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
798 int unit, int show_logo)
800 struct fbcon_ops *ops = info->fbcon_par;
803 ops->currcon = fg_console;
805 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
806 ret = info->fbops->fb_set_par(info);
809 printk(KERN_ERR "con2fb_init_display: detected "
810 "unhandled fb_set_par error, "
811 "error code %d\n", ret);
814 ops->flags |= FBCON_FLAGS_INIT;
816 fbcon_set_disp(info, &info->var, unit);
819 struct vc_data *fg_vc = vc_cons[fg_console].d;
820 struct fb_info *fg_info =
821 registered_fb[con2fb_map[fg_console]];
823 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
824 fg_vc->vc_rows, fg_vc->vc_cols,
828 update_screen(vc_cons[fg_console].d);
832 * set_con2fb_map - map console to frame buffer device
833 * @unit: virtual console number to map
834 * @newidx: frame buffer index to map virtual console to
835 * @user: user request
837 * Maps a virtual console @unit to a frame buffer device
840 * This should be called with the console lock held.
842 static int set_con2fb_map(int unit, int newidx, int user)
844 struct vc_data *vc = vc_cons[unit].d;
845 int oldidx = con2fb_map[unit];
846 struct fb_info *info = registered_fb[newidx];
847 struct fb_info *oldinfo = NULL;
850 WARN_CONSOLE_UNLOCKED();
852 if (oldidx == newidx)
858 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
860 return do_fbcon_takeover(0);
864 oldinfo = registered_fb[oldidx];
866 found = search_fb_in_map(newidx);
868 con2fb_map[unit] = newidx;
870 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
873 * If old fb is not mapped to any of the consoles,
874 * fbcon should release it.
876 if (!err && oldinfo && !search_fb_in_map(oldidx))
877 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
881 int show_logo = (fg_console == 0 && !user &&
882 logo_shown != FBCON_LOGO_DONTSHOW);
885 fbcon_add_cursor_timer(info);
886 con2fb_map_boot[unit] = newidx;
887 con2fb_init_display(vc, info, unit, show_logo);
890 if (!search_fb_in_map(info_idx))
897 * Low Level Operations
899 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
900 static int var_to_display(struct fbcon_display *disp,
901 struct fb_var_screeninfo *var,
902 struct fb_info *info)
904 disp->xres_virtual = var->xres_virtual;
905 disp->yres_virtual = var->yres_virtual;
906 disp->bits_per_pixel = var->bits_per_pixel;
907 disp->grayscale = var->grayscale;
908 disp->nonstd = var->nonstd;
909 disp->accel_flags = var->accel_flags;
910 disp->height = var->height;
911 disp->width = var->width;
912 disp->red = var->red;
913 disp->green = var->green;
914 disp->blue = var->blue;
915 disp->transp = var->transp;
916 disp->rotate = var->rotate;
917 disp->mode = fb_match_mode(var, &info->modelist);
918 if (disp->mode == NULL)
919 /* This should not happen */
924 static void display_to_var(struct fb_var_screeninfo *var,
925 struct fbcon_display *disp)
927 fb_videomode_to_var(var, disp->mode);
928 var->xres_virtual = disp->xres_virtual;
929 var->yres_virtual = disp->yres_virtual;
930 var->bits_per_pixel = disp->bits_per_pixel;
931 var->grayscale = disp->grayscale;
932 var->nonstd = disp->nonstd;
933 var->accel_flags = disp->accel_flags;
934 var->height = disp->height;
935 var->width = disp->width;
936 var->red = disp->red;
937 var->green = disp->green;
938 var->blue = disp->blue;
939 var->transp = disp->transp;
940 var->rotate = disp->rotate;
943 static const char *fbcon_startup(void)
945 const char *display_desc = "frame buffer device";
946 struct fbcon_display *p = &fb_display[fg_console];
947 struct vc_data *vc = vc_cons[fg_console].d;
948 const struct font_desc *font = NULL;
949 struct module *owner;
950 struct fb_info *info = NULL;
951 struct fbcon_ops *ops;
955 * If num_registered_fb is zero, this is a call for the dummy part.
956 * The frame buffer devices weren't initialized yet.
958 if (!num_registered_fb || info_idx == -1)
961 * Instead of blindly using registered_fb[0], we use info_idx, set by
964 info = registered_fb[info_idx];
968 owner = info->fbops->owner;
969 if (!try_module_get(owner))
971 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
976 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
984 ops->cur_rotate = -1;
985 ops->cur_blink_jiffies = HZ / 5;
987 info->fbcon_par = ops;
989 p->con_rotate = initial_rotation;
990 if (p->con_rotate == -1)
991 p->con_rotate = info->fbcon_rotate_hint;
992 if (p->con_rotate == -1)
993 p->con_rotate = FB_ROTATE_UR;
995 set_blitting_type(vc, info);
997 /* Setup default font */
998 if (!p->fontdata && !vc->vc_font.data) {
999 if (!fontname[0] || !(font = find_font(fontname)))
1000 font = get_default_font(info->var.xres,
1002 info->pixmap.blit_x,
1003 info->pixmap.blit_y);
1004 vc->vc_font.width = font->width;
1005 vc->vc_font.height = font->height;
1006 vc->vc_font.data = (void *)(p->fontdata = font->data);
1007 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1009 p->fontdata = vc->vc_font.data;
1012 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1013 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1014 cols /= vc->vc_font.width;
1015 rows /= vc->vc_font.height;
1016 vc_resize(vc, cols, rows);
1018 DPRINTK("mode: %s\n", info->fix.id);
1019 DPRINTK("visual: %d\n", info->fix.visual);
1020 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1022 info->var.bits_per_pixel);
1024 fbcon_add_cursor_timer(info);
1025 return display_desc;
1028 static void fbcon_init(struct vc_data *vc, int init)
1030 struct fb_info *info;
1031 struct fbcon_ops *ops;
1032 struct vc_data **default_mode = vc->vc_display_fg;
1033 struct vc_data *svc = *default_mode;
1034 struct fbcon_display *t, *p = &fb_display[vc->vc_num];
1035 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1038 if (WARN_ON(info_idx == -1))
1041 if (con2fb_map[vc->vc_num] == -1)
1042 con2fb_map[vc->vc_num] = info_idx;
1044 info = registered_fb[con2fb_map[vc->vc_num]];
1046 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1047 logo_shown = FBCON_LOGO_DONTSHOW;
1049 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1050 (info->fix.type == FB_TYPE_TEXT))
1053 if (var_to_display(p, &info->var, info))
1056 if (!info->fbcon_par)
1057 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1059 /* If we are not the first console on this
1060 fb, copy the font from that console */
1061 t = &fb_display[fg_console];
1064 struct vc_data *fvc = vc_cons[fg_console].d;
1066 vc->vc_font.data = (void *)(p->fontdata =
1068 vc->vc_font.width = fvc->vc_font.width;
1069 vc->vc_font.height = fvc->vc_font.height;
1070 p->userfont = t->userfont;
1073 REFCOUNT(p->fontdata)++;
1075 const struct font_desc *font = NULL;
1077 if (!fontname[0] || !(font = find_font(fontname)))
1078 font = get_default_font(info->var.xres,
1080 info->pixmap.blit_x,
1081 info->pixmap.blit_y);
1082 vc->vc_font.width = font->width;
1083 vc->vc_font.height = font->height;
1084 vc->vc_font.data = (void *)(p->fontdata = font->data);
1085 vc->vc_font.charcount = 256; /* FIXME Need to
1086 support more fonts */
1091 charcnt = FNTCHARCNT(p->fontdata);
1093 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1094 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1095 if (charcnt == 256) {
1096 vc->vc_hi_font_mask = 0;
1098 vc->vc_hi_font_mask = 0x100;
1099 if (vc->vc_can_do_color)
1100 vc->vc_complement_mask <<= 1;
1103 if (!*svc->vc_uni_pagedir_loc)
1104 con_set_default_unimap(svc);
1105 if (!*vc->vc_uni_pagedir_loc)
1106 con_copy_unimap(vc, svc);
1108 ops = info->fbcon_par;
1109 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1111 p->con_rotate = initial_rotation;
1112 if (p->con_rotate == -1)
1113 p->con_rotate = info->fbcon_rotate_hint;
1114 if (p->con_rotate == -1)
1115 p->con_rotate = FB_ROTATE_UR;
1117 set_blitting_type(vc, info);
1121 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1122 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1123 new_cols /= vc->vc_font.width;
1124 new_rows /= vc->vc_font.height;
1127 * We must always set the mode. The mode of the previous console
1128 * driver could be in the same resolution but we are using different
1129 * hardware so we have to initialize the hardware.
1131 * We need to do it in fbcon_init() to prevent screen corruption.
1133 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1134 if (info->fbops->fb_set_par &&
1135 !(ops->flags & FBCON_FLAGS_INIT)) {
1136 ret = info->fbops->fb_set_par(info);
1139 printk(KERN_ERR "fbcon_init: detected "
1140 "unhandled fb_set_par error, "
1141 "error code %d\n", ret);
1144 ops->flags |= FBCON_FLAGS_INIT;
1150 * No more hw acceleration for fbcon.
1152 * FIXME: Garbage collect all the now dead code after sufficient time
1155 p->scrollmode = SCROLL_REDRAW;
1158 * ++guenther: console.c:vc_allocate() relies on initializing
1159 * vc_{cols,rows}, but we must not set those if we are only
1160 * resizing the console.
1163 vc->vc_cols = new_cols;
1164 vc->vc_rows = new_rows;
1166 vc_resize(vc, new_cols, new_rows);
1169 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1171 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1172 ops->rotate = FB_ROTATE_UR;
1173 set_blitting_type(vc, info);
1176 ops->p = &fb_display[fg_console];
1179 static void fbcon_free_font(struct fbcon_display *p, bool freefont)
1181 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1182 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1187 static void set_vc_hi_font(struct vc_data *vc, bool set);
1189 static void fbcon_deinit(struct vc_data *vc)
1191 struct fbcon_display *p = &fb_display[vc->vc_num];
1192 struct fb_info *info;
1193 struct fbcon_ops *ops;
1195 bool free_font = true;
1197 idx = con2fb_map[vc->vc_num];
1202 info = registered_fb[idx];
1207 if (info->flags & FBINFO_MISC_FIRMWARE)
1209 ops = info->fbcon_par;
1214 if (con_is_visible(vc))
1215 fbcon_del_cursor_timer(info);
1217 ops->flags &= ~FBCON_FLAGS_INIT;
1220 fbcon_free_font(p, free_font);
1222 vc->vc_font.data = NULL;
1224 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1225 set_vc_hi_font(vc, false);
1227 if (!con_is_bound(&fb_con))
1230 if (vc->vc_num == logo_shown)
1231 logo_shown = FBCON_LOGO_CANSHOW;
1236 /* ====================================================================== */
1238 /* fbcon_XXX routines - interface used by the world
1240 * This system is now divided into two levels because of complications
1241 * caused by hardware scrolling. Top level functions:
1243 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1245 * handles y values in range [0, scr_height-1] that correspond to real
1246 * screen positions. y_wrap shift means that first line of bitmap may be
1247 * anywhere on this display. These functions convert lineoffsets to
1248 * bitmap offsets and deal with the wrap-around case by splitting blits.
1250 * fbcon_bmove_physical_8() -- These functions fast implementations
1251 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1252 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1256 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1257 * Implies should only really hardware scroll in rows. Only reason for
1258 * restriction is simplicity & efficiency at the moment.
1261 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1264 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1265 struct fbcon_ops *ops = info->fbcon_par;
1267 struct fbcon_display *p = &fb_display[vc->vc_num];
1270 if (fbcon_is_inactive(vc, info))
1273 if (!height || !width)
1276 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1279 * If the font dimensions are not an integral of the display
1280 * dimensions then the ops->clear below won't end up clearing
1281 * the margins. Call clear_margins here in case the logo
1282 * bitmap stretched into the margin area.
1284 fbcon_clear_margins(vc, 0);
1287 /* Split blits that cross physical y_wrap boundary */
1289 y_break = p->vrows - p->yscroll;
1290 if (sy < y_break && sy + height - 1 >= y_break) {
1291 u_int b = y_break - sy;
1292 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1293 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1296 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1299 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1300 int count, int ypos, int xpos)
1302 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1303 struct fbcon_display *p = &fb_display[vc->vc_num];
1304 struct fbcon_ops *ops = info->fbcon_par;
1306 if (!fbcon_is_inactive(vc, info))
1307 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1308 get_color(vc, info, scr_readw(s), 1),
1309 get_color(vc, info, scr_readw(s), 0));
1312 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1316 scr_writew(c, &chr);
1317 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1320 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1322 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1323 struct fbcon_ops *ops = info->fbcon_par;
1325 if (!fbcon_is_inactive(vc, info))
1326 ops->clear_margins(vc, info, margin_color, bottom_only);
1329 static void fbcon_cursor(struct vc_data *vc, int mode)
1331 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1332 struct fbcon_ops *ops = info->fbcon_par;
1333 int c = scr_readw((u16 *) vc->vc_pos);
1335 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1337 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1340 if (vc->vc_cursor_type & CUR_SW)
1341 fbcon_del_cursor_timer(info);
1343 fbcon_add_cursor_timer(info);
1345 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1347 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1348 get_color(vc, info, c, 0));
1351 static int scrollback_phys_max = 0;
1352 static int scrollback_max = 0;
1353 static int scrollback_current = 0;
1355 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1358 struct fbcon_display *p, *t;
1359 struct vc_data **default_mode, *vc;
1360 struct vc_data *svc;
1361 struct fbcon_ops *ops = info->fbcon_par;
1362 int rows, cols, charcnt = 256;
1364 p = &fb_display[unit];
1366 if (var_to_display(p, var, info))
1369 vc = vc_cons[unit].d;
1374 default_mode = vc->vc_display_fg;
1375 svc = *default_mode;
1376 t = &fb_display[svc->vc_num];
1378 if (!vc->vc_font.data) {
1379 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1380 vc->vc_font.width = (*default_mode)->vc_font.width;
1381 vc->vc_font.height = (*default_mode)->vc_font.height;
1382 p->userfont = t->userfont;
1384 REFCOUNT(p->fontdata)++;
1387 charcnt = FNTCHARCNT(p->fontdata);
1389 var->activate = FB_ACTIVATE_NOW;
1390 info->var.activate = var->activate;
1391 var->yoffset = info->var.yoffset;
1392 var->xoffset = info->var.xoffset;
1393 fb_set_var(info, var);
1394 ops->var = info->var;
1395 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1396 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1397 if (charcnt == 256) {
1398 vc->vc_hi_font_mask = 0;
1400 vc->vc_hi_font_mask = 0x100;
1401 if (vc->vc_can_do_color)
1402 vc->vc_complement_mask <<= 1;
1405 if (!*svc->vc_uni_pagedir_loc)
1406 con_set_default_unimap(svc);
1407 if (!*vc->vc_uni_pagedir_loc)
1408 con_copy_unimap(vc, svc);
1410 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1411 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1412 cols /= vc->vc_font.width;
1413 rows /= vc->vc_font.height;
1414 vc_resize(vc, cols, rows);
1416 if (con_is_visible(vc)) {
1421 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1423 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1424 struct fbcon_ops *ops = info->fbcon_par;
1425 struct fbcon_display *p = &fb_display[vc->vc_num];
1427 p->yscroll += count;
1428 if (p->yscroll >= p->vrows) /* Deal with wrap */
1429 p->yscroll -= p->vrows;
1430 ops->var.xoffset = 0;
1431 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1432 ops->var.vmode |= FB_VMODE_YWRAP;
1433 ops->update_start(info);
1434 scrollback_max += count;
1435 if (scrollback_max > scrollback_phys_max)
1436 scrollback_max = scrollback_phys_max;
1437 scrollback_current = 0;
1440 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1442 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1443 struct fbcon_ops *ops = info->fbcon_par;
1444 struct fbcon_display *p = &fb_display[vc->vc_num];
1446 p->yscroll -= count;
1447 if (p->yscroll < 0) /* Deal with wrap */
1448 p->yscroll += p->vrows;
1449 ops->var.xoffset = 0;
1450 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1451 ops->var.vmode |= FB_VMODE_YWRAP;
1452 ops->update_start(info);
1453 scrollback_max -= count;
1454 if (scrollback_max < 0)
1456 scrollback_current = 0;
1459 static __inline__ void ypan_up(struct vc_data *vc, int count)
1461 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1462 struct fbcon_display *p = &fb_display[vc->vc_num];
1463 struct fbcon_ops *ops = info->fbcon_par;
1465 p->yscroll += count;
1466 if (p->yscroll > p->vrows - vc->vc_rows) {
1467 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1468 0, 0, 0, vc->vc_rows, vc->vc_cols);
1469 p->yscroll -= p->vrows - vc->vc_rows;
1472 ops->var.xoffset = 0;
1473 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1474 ops->var.vmode &= ~FB_VMODE_YWRAP;
1475 ops->update_start(info);
1476 fbcon_clear_margins(vc, 1);
1477 scrollback_max += count;
1478 if (scrollback_max > scrollback_phys_max)
1479 scrollback_max = scrollback_phys_max;
1480 scrollback_current = 0;
1483 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1485 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1486 struct fbcon_ops *ops = info->fbcon_par;
1487 struct fbcon_display *p = &fb_display[vc->vc_num];
1489 p->yscroll += count;
1491 if (p->yscroll > p->vrows - vc->vc_rows) {
1492 p->yscroll -= p->vrows - vc->vc_rows;
1493 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1496 ops->var.xoffset = 0;
1497 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1498 ops->var.vmode &= ~FB_VMODE_YWRAP;
1499 ops->update_start(info);
1500 fbcon_clear_margins(vc, 1);
1501 scrollback_max += count;
1502 if (scrollback_max > scrollback_phys_max)
1503 scrollback_max = scrollback_phys_max;
1504 scrollback_current = 0;
1507 static __inline__ void ypan_down(struct vc_data *vc, int count)
1509 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1510 struct fbcon_display *p = &fb_display[vc->vc_num];
1511 struct fbcon_ops *ops = info->fbcon_par;
1513 p->yscroll -= count;
1514 if (p->yscroll < 0) {
1515 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1516 0, vc->vc_rows, vc->vc_cols);
1517 p->yscroll += p->vrows - vc->vc_rows;
1520 ops->var.xoffset = 0;
1521 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1522 ops->var.vmode &= ~FB_VMODE_YWRAP;
1523 ops->update_start(info);
1524 fbcon_clear_margins(vc, 1);
1525 scrollback_max -= count;
1526 if (scrollback_max < 0)
1528 scrollback_current = 0;
1531 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1533 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1534 struct fbcon_ops *ops = info->fbcon_par;
1535 struct fbcon_display *p = &fb_display[vc->vc_num];
1537 p->yscroll -= count;
1539 if (p->yscroll < 0) {
1540 p->yscroll += p->vrows - vc->vc_rows;
1541 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1544 ops->var.xoffset = 0;
1545 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1546 ops->var.vmode &= ~FB_VMODE_YWRAP;
1547 ops->update_start(info);
1548 fbcon_clear_margins(vc, 1);
1549 scrollback_max -= count;
1550 if (scrollback_max < 0)
1552 scrollback_current = 0;
1555 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
1556 int line, int count, int dy)
1558 unsigned short *s = (unsigned short *)
1559 (vc->vc_origin + vc->vc_size_row * line);
1562 unsigned short *start = s;
1563 unsigned short *le = advance_row(s, 1);
1566 unsigned short attr = 1;
1570 if (attr != (c & 0xff00)) {
1573 fbcon_putcs(vc, start, s - start,
1579 console_conditional_schedule();
1583 fbcon_putcs(vc, start, s - start, dy, x);
1584 console_conditional_schedule();
1589 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1590 struct fbcon_display *p, int line, int count, int ycount)
1592 int offset = ycount * vc->vc_cols;
1593 unsigned short *d = (unsigned short *)
1594 (vc->vc_origin + vc->vc_size_row * line);
1595 unsigned short *s = d + offset;
1596 struct fbcon_ops *ops = info->fbcon_par;
1599 unsigned short *start = s;
1600 unsigned short *le = advance_row(s, 1);
1607 if (c == scr_readw(d)) {
1609 ops->bmove(vc, info, line + ycount, x,
1610 line, x, 1, s-start);
1620 console_conditional_schedule();
1625 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1627 console_conditional_schedule();
1632 /* NOTE: We subtract two lines from these pointers */
1633 s -= vc->vc_size_row;
1634 d -= vc->vc_size_row;
1639 static void fbcon_redraw(struct vc_data *vc, struct fbcon_display *p,
1640 int line, int count, int offset)
1642 unsigned short *d = (unsigned short *)
1643 (vc->vc_origin + vc->vc_size_row * line);
1644 unsigned short *s = d + offset;
1647 unsigned short *start = s;
1648 unsigned short *le = advance_row(s, 1);
1651 unsigned short attr = 1;
1655 if (attr != (c & 0xff00)) {
1658 fbcon_putcs(vc, start, s - start,
1664 if (c == scr_readw(d)) {
1666 fbcon_putcs(vc, start, s - start,
1676 console_conditional_schedule();
1681 fbcon_putcs(vc, start, s - start, line, x);
1682 console_conditional_schedule();
1687 /* NOTE: We subtract two lines from these pointers */
1688 s -= vc->vc_size_row;
1689 d -= vc->vc_size_row;
1694 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1695 enum con_scroll dir, unsigned int count)
1697 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1698 struct fbcon_display *p = &fb_display[vc->vc_num];
1699 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1701 if (fbcon_is_inactive(vc, info))
1704 fbcon_cursor(vc, CM_ERASE);
1707 * ++Geert: Only use ywrap/ypan if the console is in text mode
1708 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1709 * whole screen (prevents flicker).
1714 if (count > vc->vc_rows) /* Maximum realistic size */
1715 count = vc->vc_rows;
1716 if (logo_shown >= 0)
1718 switch (p->scrollmode) {
1720 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1722 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1723 scr_memsetw((unsigned short *) (vc->vc_origin +
1726 vc->vc_video_erase_char,
1727 vc->vc_size_row * count);
1730 case SCROLL_WRAP_MOVE:
1731 if (b - t - count > 3 * vc->vc_rows >> 2) {
1733 fbcon_bmove(vc, 0, 0, count, 0, t,
1735 ywrap_up(vc, count);
1736 if (vc->vc_rows - b > 0)
1737 fbcon_bmove(vc, b - count, 0, b, 0,
1740 } else if (info->flags & FBINFO_READS_FAST)
1741 fbcon_bmove(vc, t + count, 0, t, 0,
1742 b - t - count, vc->vc_cols);
1745 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1748 case SCROLL_PAN_REDRAW:
1749 if ((p->yscroll + count <=
1750 2 * (p->vrows - vc->vc_rows))
1751 && ((!scroll_partial && (b - t == vc->vc_rows))
1754 3 * vc->vc_rows >> 2)))) {
1756 fbcon_redraw_move(vc, p, 0, t, count);
1757 ypan_up_redraw(vc, t, count);
1758 if (vc->vc_rows - b > 0)
1759 fbcon_redraw_move(vc, p, b,
1760 vc->vc_rows - b, b);
1762 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1763 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1766 case SCROLL_PAN_MOVE:
1767 if ((p->yscroll + count <=
1768 2 * (p->vrows - vc->vc_rows))
1769 && ((!scroll_partial && (b - t == vc->vc_rows))
1772 3 * vc->vc_rows >> 2)))) {
1774 fbcon_bmove(vc, 0, 0, count, 0, t,
1777 if (vc->vc_rows - b > 0)
1778 fbcon_bmove(vc, b - count, 0, b, 0,
1781 } else if (info->flags & FBINFO_READS_FAST)
1782 fbcon_bmove(vc, t + count, 0, t, 0,
1783 b - t - count, vc->vc_cols);
1786 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1791 fbcon_redraw(vc, p, t, b - t - count,
1792 count * vc->vc_cols);
1793 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1794 scr_memsetw((unsigned short *) (vc->vc_origin +
1797 vc->vc_video_erase_char,
1798 vc->vc_size_row * count);
1804 if (count > vc->vc_rows) /* Maximum realistic size */
1805 count = vc->vc_rows;
1806 if (logo_shown >= 0)
1808 switch (p->scrollmode) {
1810 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1812 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1813 scr_memsetw((unsigned short *) (vc->vc_origin +
1816 vc->vc_video_erase_char,
1817 vc->vc_size_row * count);
1820 case SCROLL_WRAP_MOVE:
1821 if (b - t - count > 3 * vc->vc_rows >> 2) {
1822 if (vc->vc_rows - b > 0)
1823 fbcon_bmove(vc, b, 0, b - count, 0,
1826 ywrap_down(vc, count);
1828 fbcon_bmove(vc, count, 0, 0, 0, t,
1830 } else if (info->flags & FBINFO_READS_FAST)
1831 fbcon_bmove(vc, t, 0, t + count, 0,
1832 b - t - count, vc->vc_cols);
1835 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1838 case SCROLL_PAN_MOVE:
1839 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1840 && ((!scroll_partial && (b - t == vc->vc_rows))
1843 3 * vc->vc_rows >> 2)))) {
1844 if (vc->vc_rows - b > 0)
1845 fbcon_bmove(vc, b, 0, b - count, 0,
1848 ypan_down(vc, count);
1850 fbcon_bmove(vc, count, 0, 0, 0, t,
1852 } else if (info->flags & FBINFO_READS_FAST)
1853 fbcon_bmove(vc, t, 0, t + count, 0,
1854 b - t - count, vc->vc_cols);
1857 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1860 case SCROLL_PAN_REDRAW:
1861 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1862 && ((!scroll_partial && (b - t == vc->vc_rows))
1865 3 * vc->vc_rows >> 2)))) {
1866 if (vc->vc_rows - b > 0)
1867 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1869 ypan_down_redraw(vc, t, count);
1871 fbcon_redraw_move(vc, p, count, t, 0);
1873 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1874 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1879 fbcon_redraw(vc, p, b - 1, b - t - count,
1880 -count * vc->vc_cols);
1881 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1882 scr_memsetw((unsigned short *) (vc->vc_origin +
1885 vc->vc_video_erase_char,
1886 vc->vc_size_row * count);
1894 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1895 int height, int width)
1897 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1898 struct fbcon_display *p = &fb_display[vc->vc_num];
1900 if (fbcon_is_inactive(vc, info))
1903 if (!width || !height)
1906 /* Split blits that cross physical y_wrap case.
1907 * Pathological case involves 4 blits, better to use recursive
1908 * code rather than unrolled case
1910 * Recursive invocations don't need to erase the cursor over and
1911 * over again, so we use fbcon_bmove_rec()
1913 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1914 p->vrows - p->yscroll);
1917 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
1918 int dy, int dx, int height, int width, u_int y_break)
1920 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1921 struct fbcon_ops *ops = info->fbcon_par;
1924 if (sy < y_break && sy + height > y_break) {
1926 if (dy < sy) { /* Avoid trashing self */
1927 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1929 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1930 height - b, width, y_break);
1932 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1933 height - b, width, y_break);
1934 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1940 if (dy < y_break && dy + height > y_break) {
1942 if (dy < sy) { /* Avoid trashing self */
1943 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1945 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1946 height - b, width, y_break);
1948 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1949 height - b, width, y_break);
1950 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1955 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1959 static void updatescrollmode(struct fbcon_display *p,
1960 struct fb_info *info,
1963 struct fbcon_ops *ops = info->fbcon_par;
1964 int fh = vc->vc_font.height;
1965 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1966 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1967 info->var.xres_virtual);
1969 p->vrows = vyres/fh;
1970 if (yres > (fh * (vc->vc_rows + 1)))
1971 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1972 if ((yres % fh) && (vyres % fh < yres % fh))
1976 #define PITCH(w) (((w) + 7) >> 3)
1977 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
1979 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1980 unsigned int height, unsigned int user)
1982 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1983 struct fbcon_ops *ops = info->fbcon_par;
1984 struct fbcon_display *p = &fb_display[vc->vc_num];
1985 struct fb_var_screeninfo var = info->var;
1986 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
1988 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
1990 int pitch = PITCH(vc->vc_font.width);
1993 * If user font, ensure that a possible change to user font
1994 * height or width will not allow a font data out-of-bounds access.
1995 * NOTE: must use original charcount in calculation as font
1996 * charcount can change and cannot be used to determine the
1997 * font data allocated size.
2001 size = CALC_FONTSZ(vc->vc_font.height, pitch, FNTCHARCNT(vc->vc_font.data));
2002 if (size > FNTSIZE(vc->vc_font.data))
2006 virt_w = FBCON_SWAP(ops->rotate, width, height);
2007 virt_h = FBCON_SWAP(ops->rotate, height, width);
2008 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2009 vc->vc_font.height);
2010 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2012 var.xres = virt_w * virt_fw;
2013 var.yres = virt_h * virt_fh;
2014 x_diff = info->var.xres - var.xres;
2015 y_diff = info->var.yres - var.yres;
2016 if (x_diff < 0 || x_diff > virt_fw ||
2017 y_diff < 0 || y_diff > virt_fh) {
2018 const struct fb_videomode *mode;
2020 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2021 mode = fb_find_best_mode(&var, &info->modelist);
2024 display_to_var(&var, p);
2025 fb_videomode_to_var(&var, mode);
2027 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2030 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2031 if (con_is_visible(vc)) {
2032 var.activate = FB_ACTIVATE_NOW |
2034 fb_set_var(info, &var);
2036 var_to_display(p, &info->var, info);
2037 ops->var = info->var;
2039 updatescrollmode(p, info, vc);
2043 static int fbcon_switch(struct vc_data *vc)
2045 struct fb_info *info, *old_info = NULL;
2046 struct fbcon_ops *ops;
2047 struct fbcon_display *p = &fb_display[vc->vc_num];
2048 struct fb_var_screeninfo var;
2049 int i, ret, prev_console, charcnt = 256;
2051 info = registered_fb[con2fb_map[vc->vc_num]];
2052 ops = info->fbcon_par;
2054 if (logo_shown >= 0) {
2055 struct vc_data *conp2 = vc_cons[logo_shown].d;
2057 if (conp2->vc_top == logo_lines
2058 && conp2->vc_bottom == conp2->vc_rows)
2060 logo_shown = FBCON_LOGO_CANSHOW;
2063 prev_console = ops->currcon;
2064 if (prev_console != -1)
2065 old_info = registered_fb[con2fb_map[prev_console]];
2067 * FIXME: If we have multiple fbdev's loaded, we need to
2068 * update all info->currcon. Perhaps, we can place this
2069 * in a centralized structure, but this might break some
2072 * info->currcon = vc->vc_num;
2074 for_each_registered_fb(i) {
2075 if (registered_fb[i]->fbcon_par) {
2076 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2078 o->currcon = vc->vc_num;
2081 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2082 display_to_var(&var, p);
2083 var.activate = FB_ACTIVATE_NOW;
2086 * make sure we don't unnecessarily trip the memcmp()
2089 info->var.activate = var.activate;
2090 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2091 fb_set_var(info, &var);
2092 ops->var = info->var;
2094 if (old_info != NULL && (old_info != info ||
2095 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2096 if (info->fbops->fb_set_par) {
2097 ret = info->fbops->fb_set_par(info);
2100 printk(KERN_ERR "fbcon_switch: detected "
2101 "unhandled fb_set_par error, "
2102 "error code %d\n", ret);
2105 if (old_info != info)
2106 fbcon_del_cursor_timer(old_info);
2109 if (fbcon_is_inactive(vc, info) ||
2110 ops->blank_state != FB_BLANK_UNBLANK)
2111 fbcon_del_cursor_timer(info);
2113 fbcon_add_cursor_timer(info);
2115 set_blitting_type(vc, info);
2116 ops->cursor_reset = 1;
2118 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2119 ops->rotate = FB_ROTATE_UR;
2120 set_blitting_type(vc, info);
2123 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2124 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2127 charcnt = FNTCHARCNT(vc->vc_font.data);
2130 vc->vc_complement_mask <<= 1;
2132 updatescrollmode(p, info, vc);
2134 switch (p->scrollmode) {
2135 case SCROLL_WRAP_MOVE:
2136 scrollback_phys_max = p->vrows - vc->vc_rows;
2138 case SCROLL_PAN_MOVE:
2139 case SCROLL_PAN_REDRAW:
2140 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2141 if (scrollback_phys_max < 0)
2142 scrollback_phys_max = 0;
2145 scrollback_phys_max = 0;
2150 scrollback_current = 0;
2152 if (!fbcon_is_inactive(vc, info)) {
2153 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2154 ops->update_start(info);
2157 fbcon_set_palette(vc, color_table);
2158 fbcon_clear_margins(vc, 0);
2160 if (logo_shown == FBCON_LOGO_DRAW) {
2162 logo_shown = fg_console;
2163 /* This is protected above by initmem_freed */
2164 fb_show_logo(info, ops->rotate);
2166 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2167 vc->vc_size_row * (vc->vc_bottom -
2174 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2178 unsigned short charmask = vc->vc_hi_font_mask ?
2180 unsigned short oldc;
2182 oldc = vc->vc_video_erase_char;
2183 vc->vc_video_erase_char &= charmask;
2184 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2185 vc->vc_video_erase_char = oldc;
2189 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2191 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2192 struct fbcon_ops *ops = info->fbcon_par;
2195 struct fb_var_screeninfo var = info->var;
2200 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE |
2201 FB_ACTIVATE_KD_TEXT;
2202 fb_set_var(info, &var);
2204 ops->var = info->var;
2208 if (!fbcon_is_inactive(vc, info)) {
2209 if (ops->blank_state != blank) {
2210 ops->blank_state = blank;
2211 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2212 ops->cursor_flash = (!blank);
2214 if (fb_blank(info, blank))
2215 fbcon_generic_blank(vc, info, blank);
2222 if (mode_switch || fbcon_is_inactive(vc, info) ||
2223 ops->blank_state != FB_BLANK_UNBLANK)
2224 fbcon_del_cursor_timer(info);
2226 fbcon_add_cursor_timer(info);
2231 static int fbcon_debug_enter(struct vc_data *vc)
2233 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2234 struct fbcon_ops *ops = info->fbcon_par;
2236 ops->save_graphics = ops->graphics;
2238 if (info->fbops->fb_debug_enter)
2239 info->fbops->fb_debug_enter(info);
2240 fbcon_set_palette(vc, color_table);
2244 static int fbcon_debug_leave(struct vc_data *vc)
2246 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2247 struct fbcon_ops *ops = info->fbcon_par;
2249 ops->graphics = ops->save_graphics;
2250 if (info->fbops->fb_debug_leave)
2251 info->fbops->fb_debug_leave(info);
2255 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2257 u8 *fontdata = vc->vc_font.data;
2258 u8 *data = font->data;
2261 font->width = vc->vc_font.width;
2262 font->height = vc->vc_font.height;
2263 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2267 if (font->width <= 8) {
2268 j = vc->vc_font.height;
2269 if (font->charcount * j > FNTSIZE(fontdata))
2272 for (i = 0; i < font->charcount; i++) {
2273 memcpy(data, fontdata, j);
2274 memset(data + j, 0, 32 - j);
2278 } else if (font->width <= 16) {
2279 j = vc->vc_font.height * 2;
2280 if (font->charcount * j > FNTSIZE(fontdata))
2283 for (i = 0; i < font->charcount; i++) {
2284 memcpy(data, fontdata, j);
2285 memset(data + j, 0, 64 - j);
2289 } else if (font->width <= 24) {
2290 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
2293 for (i = 0; i < font->charcount; i++) {
2294 for (j = 0; j < vc->vc_font.height; j++) {
2295 *data++ = fontdata[0];
2296 *data++ = fontdata[1];
2297 *data++ = fontdata[2];
2298 fontdata += sizeof(u32);
2300 memset(data, 0, 3 * (32 - j));
2301 data += 3 * (32 - j);
2304 j = vc->vc_font.height * 4;
2305 if (font->charcount * j > FNTSIZE(fontdata))
2308 for (i = 0; i < font->charcount; i++) {
2309 memcpy(data, fontdata, j);
2310 memset(data + j, 0, 128 - j);
2318 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2319 static void set_vc_hi_font(struct vc_data *vc, bool set)
2322 vc->vc_hi_font_mask = 0;
2323 if (vc->vc_can_do_color) {
2324 vc->vc_complement_mask >>= 1;
2325 vc->vc_s_complement_mask >>= 1;
2328 /* ++Edmund: reorder the attribute bits */
2329 if (vc->vc_can_do_color) {
2330 unsigned short *cp =
2331 (unsigned short *) vc->vc_origin;
2332 int count = vc->vc_screenbuf_size / 2;
2334 for (; count > 0; count--, cp++) {
2336 scr_writew(((c & 0xfe00) >> 1) |
2339 c = vc->vc_video_erase_char;
2340 vc->vc_video_erase_char =
2341 ((c & 0xfe00) >> 1) | (c & 0xff);
2345 vc->vc_hi_font_mask = 0x100;
2346 if (vc->vc_can_do_color) {
2347 vc->vc_complement_mask <<= 1;
2348 vc->vc_s_complement_mask <<= 1;
2351 /* ++Edmund: reorder the attribute bits */
2353 unsigned short *cp =
2354 (unsigned short *) vc->vc_origin;
2355 int count = vc->vc_screenbuf_size / 2;
2357 for (; count > 0; count--, cp++) {
2358 unsigned short newc;
2360 if (vc->vc_can_do_color)
2362 ((c & 0xff00) << 1) | (c &
2366 scr_writew(newc, cp);
2368 c = vc->vc_video_erase_char;
2369 if (vc->vc_can_do_color) {
2370 vc->vc_video_erase_char =
2371 ((c & 0xff00) << 1) | (c & 0xff);
2374 vc->vc_video_erase_char = c & ~0x100;
2379 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2380 const u8 * data, int userfont)
2382 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2383 struct fbcon_ops *ops = info->fbcon_par;
2384 struct fbcon_display *p = &fb_display[vc->vc_num];
2387 char *old_data = NULL;
2389 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2391 old_data = vc->vc_font.data;
2393 cnt = FNTCHARCNT(data);
2396 vc->vc_font.data = (void *)(p->fontdata = data);
2397 if ((p->userfont = userfont))
2399 vc->vc_font.width = w;
2400 vc->vc_font.height = h;
2401 if (vc->vc_hi_font_mask && cnt == 256)
2402 set_vc_hi_font(vc, false);
2403 else if (!vc->vc_hi_font_mask && cnt == 512)
2404 set_vc_hi_font(vc, true);
2409 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2410 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2413 vc_resize(vc, cols, rows);
2414 } else if (con_is_visible(vc)
2415 && vc->vc_mode == KD_TEXT) {
2416 fbcon_clear_margins(vc, 0);
2420 if (old_data && (--REFCOUNT(old_data) == 0))
2421 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2425 static int fbcon_copy_font(struct vc_data *vc, int con)
2427 struct fbcon_display *od = &fb_display[con];
2428 struct console_font *f = &vc->vc_font;
2430 if (od->fontdata == f->data)
2431 return 0; /* already the same font... */
2432 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2436 * User asked to set font; we are guaranteed that
2437 * a) width and height are in range 1..32
2438 * b) charcount does not exceed 512
2439 * but lets not assume that, since someone might someday want to use larger
2440 * fonts. And charcount of 512 is small for unicode support.
2442 * However, user space gives the font in 32 rows , regardless of
2443 * actual font height. So a new API is needed if support for larger fonts
2444 * is ever implemented.
2447 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2450 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2451 unsigned charcount = font->charcount;
2452 int w = font->width;
2453 int h = font->height;
2456 u8 *new_data, *data = font->data;
2457 int pitch = PITCH(font->width);
2459 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2460 * If not this check should be changed to charcount < 256 */
2461 if (charcount != 256 && charcount != 512)
2464 /* Make sure drawing engine can handle the font */
2465 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2466 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2469 /* Make sure driver can handle the font length */
2470 if (fbcon_invalid_charcount(info, charcount))
2473 size = CALC_FONTSZ(h, pitch, charcount);
2475 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2480 new_data += FONT_EXTRA_WORDS * sizeof(int);
2481 FNTSIZE(new_data) = size;
2482 FNTCHARCNT(new_data) = charcount;
2483 REFCOUNT(new_data) = 0; /* usage counter */
2484 for (i=0; i< charcount; i++) {
2485 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2488 /* Since linux has a nice crc32 function use it for counting font
2490 csum = crc32(0, new_data, size);
2492 FNTSUM(new_data) = csum;
2493 /* Check if the same font is on some other console already */
2494 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2495 struct vc_data *tmp = vc_cons[i].d;
2497 if (fb_display[i].userfont &&
2498 fb_display[i].fontdata &&
2499 FNTSUM(fb_display[i].fontdata) == csum &&
2500 FNTSIZE(fb_display[i].fontdata) == size &&
2501 tmp->vc_font.width == w &&
2502 !memcmp(fb_display[i].fontdata, new_data, size)) {
2503 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2504 new_data = (u8 *)fb_display[i].fontdata;
2508 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2511 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2513 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2514 const struct font_desc *f;
2517 f = get_default_font(info->var.xres, info->var.yres,
2518 info->pixmap.blit_x, info->pixmap.blit_y);
2519 else if (!(f = find_font(name)))
2522 font->width = f->width;
2523 font->height = f->height;
2524 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2527 static u16 palette_red[16];
2528 static u16 palette_green[16];
2529 static u16 palette_blue[16];
2531 static struct fb_cmap palette_cmap = {
2532 0, 16, palette_red, palette_green, palette_blue, NULL
2535 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2537 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2541 if (fbcon_is_inactive(vc, info))
2544 if (!con_is_visible(vc))
2547 depth = fb_get_color_depth(&info->var, &info->fix);
2549 for (i = j = 0; i < 16; i++) {
2551 val = vc->vc_palette[j++];
2552 palette_red[k] = (val << 8) | val;
2553 val = vc->vc_palette[j++];
2554 palette_green[k] = (val << 8) | val;
2555 val = vc->vc_palette[j++];
2556 palette_blue[k] = (val << 8) | val;
2558 palette_cmap.len = 16;
2559 palette_cmap.start = 0;
2561 * If framebuffer is capable of less than 16 colors,
2562 * use default palette of fbcon.
2565 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2567 fb_set_cmap(&palette_cmap, info);
2570 static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset)
2572 return (u16 *) (vc->vc_origin + offset);
2575 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2581 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2582 unsigned long offset = (pos - vc->vc_origin) / 2;
2584 x = offset % vc->vc_cols;
2585 y = offset / vc->vc_cols;
2586 ret = pos + (vc->vc_cols - x) * 2;
2588 /* Should not happen */
2590 ret = vc->vc_origin;
2599 /* As we might be inside of softback, we may work with non-contiguous buffer,
2600 that's why we have to use a separate routine. */
2601 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2604 u16 a = scr_readw(p);
2605 if (!vc->vc_can_do_color)
2607 else if (vc->vc_hi_font_mask == 0x100)
2608 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2609 (((a) & 0x0e00) << 4);
2611 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2612 (((a) & 0x0700) << 4);
2617 void fbcon_suspended(struct fb_info *info)
2619 struct vc_data *vc = NULL;
2620 struct fbcon_ops *ops = info->fbcon_par;
2622 if (!ops || ops->currcon < 0)
2624 vc = vc_cons[ops->currcon].d;
2626 /* Clear cursor, restore saved data */
2627 fbcon_cursor(vc, CM_ERASE);
2630 void fbcon_resumed(struct fb_info *info)
2633 struct fbcon_ops *ops = info->fbcon_par;
2635 if (!ops || ops->currcon < 0)
2637 vc = vc_cons[ops->currcon].d;
2642 static void fbcon_modechanged(struct fb_info *info)
2644 struct fbcon_ops *ops = info->fbcon_par;
2646 struct fbcon_display *p;
2649 if (!ops || ops->currcon < 0)
2651 vc = vc_cons[ops->currcon].d;
2652 if (vc->vc_mode != KD_TEXT ||
2653 registered_fb[con2fb_map[ops->currcon]] != info)
2656 p = &fb_display[vc->vc_num];
2657 set_blitting_type(vc, info);
2659 if (con_is_visible(vc)) {
2660 var_to_display(p, &info->var, info);
2661 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2662 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2663 cols /= vc->vc_font.width;
2664 rows /= vc->vc_font.height;
2665 vc_resize(vc, cols, rows);
2666 updatescrollmode(p, info, vc);
2668 scrollback_current = 0;
2670 if (!fbcon_is_inactive(vc, info)) {
2671 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2672 ops->update_start(info);
2675 fbcon_set_palette(vc, color_table);
2680 static void fbcon_set_all_vcs(struct fb_info *info)
2682 struct fbcon_ops *ops = info->fbcon_par;
2684 struct fbcon_display *p;
2685 int i, rows, cols, fg = -1;
2687 if (!ops || ops->currcon < 0)
2690 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2692 if (!vc || vc->vc_mode != KD_TEXT ||
2693 registered_fb[con2fb_map[i]] != info)
2696 if (con_is_visible(vc)) {
2701 p = &fb_display[vc->vc_num];
2702 set_blitting_type(vc, info);
2703 var_to_display(p, &info->var, info);
2704 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2705 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2706 cols /= vc->vc_font.width;
2707 rows /= vc->vc_font.height;
2708 vc_resize(vc, cols, rows);
2712 fbcon_modechanged(info);
2716 void fbcon_update_vcs(struct fb_info *info, bool all)
2719 fbcon_set_all_vcs(info);
2721 fbcon_modechanged(info);
2723 EXPORT_SYMBOL(fbcon_update_vcs);
2725 int fbcon_mode_deleted(struct fb_info *info,
2726 struct fb_videomode *mode)
2728 struct fb_info *fb_info;
2729 struct fbcon_display *p;
2730 int i, j, found = 0;
2732 /* before deletion, ensure that mode is not in use */
2733 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2737 fb_info = registered_fb[j];
2738 if (fb_info != info)
2743 if (fb_mode_is_equal(p->mode, mode)) {
2751 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2752 static void fbcon_unbind(void)
2756 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2760 fbcon_has_console_bind = 0;
2763 static inline void fbcon_unbind(void) {}
2764 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2766 /* called with console_lock held */
2767 void fbcon_fb_unbind(struct fb_info *info)
2769 int i, new_idx = -1, ret = 0;
2770 int idx = info->node;
2772 WARN_CONSOLE_UNLOCKED();
2774 if (!fbcon_has_console_bind)
2777 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2778 if (con2fb_map[i] != idx &&
2779 con2fb_map[i] != -1) {
2780 new_idx = con2fb_map[i];
2785 if (new_idx != -1) {
2786 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2787 if (con2fb_map[i] == idx)
2788 set_con2fb_map(i, new_idx, 0);
2791 struct fb_info *info = registered_fb[idx];
2793 /* This is sort of like set_con2fb_map, except it maps
2794 * the consoles to no device and then releases the
2795 * oldinfo to free memory and cancel the cursor blink
2796 * timer. I can imagine this just becoming part of
2797 * set_con2fb_map where new_idx is -1
2799 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2800 if (con2fb_map[i] == idx) {
2802 if (!search_fb_in_map(idx)) {
2803 ret = con2fb_release_oldinfo(vc_cons[i].d,
2807 con2fb_map[i] = idx;
2817 /* called with console_lock held */
2818 void fbcon_fb_unregistered(struct fb_info *info)
2822 WARN_CONSOLE_UNLOCKED();
2824 if (deferred_takeover)
2828 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2829 if (con2fb_map[i] == idx)
2833 if (idx == info_idx) {
2836 for_each_registered_fb(i) {
2842 if (info_idx != -1) {
2843 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2844 if (con2fb_map[i] == -1)
2845 con2fb_map[i] = info_idx;
2849 if (primary_device == idx)
2850 primary_device = -1;
2852 if (!num_registered_fb)
2853 do_unregister_con_driver(&fb_con);
2856 void fbcon_remap_all(struct fb_info *info)
2858 int i, idx = info->node;
2861 if (deferred_takeover) {
2862 for (i = first_fb_vc; i <= last_fb_vc; i++)
2863 con2fb_map_boot[i] = idx;
2864 fbcon_map_override();
2869 for (i = first_fb_vc; i <= last_fb_vc; i++)
2870 set_con2fb_map(i, idx, 0);
2872 if (con_is_bound(&fb_con)) {
2873 printk(KERN_INFO "fbcon: Remapping primary device, "
2874 "fb%i, to tty %i-%i\n", idx,
2875 first_fb_vc + 1, last_fb_vc + 1);
2881 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2882 static void fbcon_select_primary(struct fb_info *info)
2884 if (!map_override && primary_device == -1 &&
2885 fb_is_primary_device(info)) {
2888 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2889 info->fix.id, info->node);
2890 primary_device = info->node;
2892 for (i = first_fb_vc; i <= last_fb_vc; i++)
2893 con2fb_map_boot[i] = primary_device;
2895 if (con_is_bound(&fb_con)) {
2896 printk(KERN_INFO "fbcon: Remapping primary device, "
2897 "fb%i, to tty %i-%i\n", info->node,
2898 first_fb_vc + 1, last_fb_vc + 1);
2899 info_idx = primary_device;
2905 static inline void fbcon_select_primary(struct fb_info *info)
2909 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2911 /* called with console_lock held */
2912 int fbcon_fb_registered(struct fb_info *info)
2914 int ret = 0, i, idx;
2916 WARN_CONSOLE_UNLOCKED();
2919 fbcon_select_primary(info);
2921 if (deferred_takeover) {
2922 pr_info("fbcon: Deferring console take-over\n");
2926 if (info_idx == -1) {
2927 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2928 if (con2fb_map_boot[i] == idx) {
2935 ret = do_fbcon_takeover(1);
2937 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2938 if (con2fb_map_boot[i] == idx)
2939 set_con2fb_map(i, idx, 0);
2946 void fbcon_fb_blanked(struct fb_info *info, int blank)
2948 struct fbcon_ops *ops = info->fbcon_par;
2951 if (!ops || ops->currcon < 0)
2954 vc = vc_cons[ops->currcon].d;
2955 if (vc->vc_mode != KD_TEXT ||
2956 registered_fb[con2fb_map[ops->currcon]] != info)
2959 if (con_is_visible(vc)) {
2963 do_unblank_screen(0);
2965 ops->blank_state = blank;
2968 void fbcon_new_modelist(struct fb_info *info)
2972 struct fb_var_screeninfo var;
2973 const struct fb_videomode *mode;
2975 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2976 if (registered_fb[con2fb_map[i]] != info)
2978 if (!fb_display[i].mode)
2981 display_to_var(&var, &fb_display[i]);
2982 mode = fb_find_nearest_mode(fb_display[i].mode,
2984 fb_videomode_to_var(&var, mode);
2985 fbcon_set_disp(info, &var, vc->vc_num);
2989 void fbcon_get_requirement(struct fb_info *info,
2990 struct fb_blit_caps *caps)
2993 struct fbcon_display *p;
2998 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3000 if (vc && vc->vc_mode == KD_TEXT &&
3001 info->node == con2fb_map[i]) {
3003 caps->x |= 1 << (vc->vc_font.width - 1);
3004 caps->y |= 1 << (vc->vc_font.height - 1);
3005 charcnt = (p->userfont) ?
3006 FNTCHARCNT(p->fontdata) : 256;
3007 if (caps->len < charcnt)
3008 caps->len = charcnt;
3012 vc = vc_cons[fg_console].d;
3014 if (vc && vc->vc_mode == KD_TEXT &&
3015 info->node == con2fb_map[fg_console]) {
3016 p = &fb_display[fg_console];
3017 caps->x = 1 << (vc->vc_font.width - 1);
3018 caps->y = 1 << (vc->vc_font.height - 1);
3019 caps->len = (p->userfont) ?
3020 FNTCHARCNT(p->fontdata) : 256;
3025 int fbcon_set_con2fb_map_ioctl(void __user *argp)
3027 struct fb_con2fbmap con2fb;
3030 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3032 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3034 if (con2fb.framebuffer >= FB_MAX)
3036 if (!registered_fb[con2fb.framebuffer])
3037 request_module("fb%d", con2fb.framebuffer);
3038 if (!registered_fb[con2fb.framebuffer]) {
3043 ret = set_con2fb_map(con2fb.console - 1,
3044 con2fb.framebuffer, 1);
3050 int fbcon_get_con2fb_map_ioctl(void __user *argp)
3052 struct fb_con2fbmap con2fb;
3054 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3056 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3060 con2fb.framebuffer = con2fb_map[con2fb.console - 1];
3063 return copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
3067 * The console `switch' structure for the frame buffer based console
3070 static const struct consw fb_con = {
3071 .owner = THIS_MODULE,
3072 .con_startup = fbcon_startup,
3073 .con_init = fbcon_init,
3074 .con_deinit = fbcon_deinit,
3075 .con_clear = fbcon_clear,
3076 .con_putc = fbcon_putc,
3077 .con_putcs = fbcon_putcs,
3078 .con_cursor = fbcon_cursor,
3079 .con_scroll = fbcon_scroll,
3080 .con_switch = fbcon_switch,
3081 .con_blank = fbcon_blank,
3082 .con_font_set = fbcon_set_font,
3083 .con_font_get = fbcon_get_font,
3084 .con_font_default = fbcon_set_def_font,
3085 .con_font_copy = fbcon_copy_font,
3086 .con_set_palette = fbcon_set_palette,
3087 .con_invert_region = fbcon_invert_region,
3088 .con_screen_pos = fbcon_screen_pos,
3089 .con_getxy = fbcon_getxy,
3090 .con_resize = fbcon_resize,
3091 .con_debug_enter = fbcon_debug_enter,
3092 .con_debug_leave = fbcon_debug_leave,
3095 static ssize_t store_rotate(struct device *device,
3096 struct device_attribute *attr, const char *buf,
3099 struct fb_info *info;
3104 idx = con2fb_map[fg_console];
3106 if (idx == -1 || registered_fb[idx] == NULL)
3109 info = registered_fb[idx];
3110 rotate = simple_strtoul(buf, last, 0);
3111 fbcon_rotate(info, rotate);
3117 static ssize_t store_rotate_all(struct device *device,
3118 struct device_attribute *attr,const char *buf,
3121 struct fb_info *info;
3126 idx = con2fb_map[fg_console];
3128 if (idx == -1 || registered_fb[idx] == NULL)
3131 info = registered_fb[idx];
3132 rotate = simple_strtoul(buf, last, 0);
3133 fbcon_rotate_all(info, rotate);
3139 static ssize_t show_rotate(struct device *device,
3140 struct device_attribute *attr,char *buf)
3142 struct fb_info *info;
3143 int rotate = 0, idx;
3146 idx = con2fb_map[fg_console];
3148 if (idx == -1 || registered_fb[idx] == NULL)
3151 info = registered_fb[idx];
3152 rotate = fbcon_get_rotate(info);
3155 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3158 static ssize_t show_cursor_blink(struct device *device,
3159 struct device_attribute *attr, char *buf)
3161 struct fb_info *info;
3162 struct fbcon_ops *ops;
3163 int idx, blink = -1;
3166 idx = con2fb_map[fg_console];
3168 if (idx == -1 || registered_fb[idx] == NULL)
3171 info = registered_fb[idx];
3172 ops = info->fbcon_par;
3177 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3180 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3183 static ssize_t store_cursor_blink(struct device *device,
3184 struct device_attribute *attr,
3185 const char *buf, size_t count)
3187 struct fb_info *info;
3192 idx = con2fb_map[fg_console];
3194 if (idx == -1 || registered_fb[idx] == NULL)
3197 info = registered_fb[idx];
3199 if (!info->fbcon_par)
3202 blink = simple_strtoul(buf, last, 0);
3205 fbcon_cursor_noblink = 0;
3206 fbcon_add_cursor_timer(info);
3208 fbcon_cursor_noblink = 1;
3209 fbcon_del_cursor_timer(info);
3217 static struct device_attribute device_attrs[] = {
3218 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3219 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3220 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3221 store_cursor_blink),
3224 static int fbcon_init_device(void)
3228 fbcon_has_sysfs = 1;
3230 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3231 error = device_create_file(fbcon_device, &device_attrs[i]);
3239 device_remove_file(fbcon_device, &device_attrs[i]);
3241 fbcon_has_sysfs = 0;
3247 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3248 static void fbcon_register_existing_fbs(struct work_struct *work)
3254 for_each_registered_fb(i)
3255 fbcon_fb_registered(registered_fb[i]);
3260 static struct notifier_block fbcon_output_nb;
3261 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3263 static int fbcon_output_notifier(struct notifier_block *nb,
3264 unsigned long action, void *data)
3266 WARN_CONSOLE_UNLOCKED();
3268 pr_info("fbcon: Taking over console\n");
3270 dummycon_unregister_output_notifier(&fbcon_output_nb);
3271 deferred_takeover = false;
3272 logo_shown = FBCON_LOGO_DONTSHOW;
3274 /* We may get called in atomic context */
3275 schedule_work(&fbcon_deferred_takeover_work);
3281 static void fbcon_start(void)
3283 WARN_CONSOLE_UNLOCKED();
3285 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3286 if (conswitchp != &dummy_con)
3287 deferred_takeover = false;
3289 if (deferred_takeover) {
3290 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3291 dummycon_register_output_notifier(&fbcon_output_nb);
3296 if (num_registered_fb) {
3299 for_each_registered_fb(i) {
3304 do_fbcon_takeover(0);
3308 static void fbcon_exit(void)
3310 struct fb_info *info;
3313 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3314 if (deferred_takeover) {
3315 dummycon_unregister_output_notifier(&fbcon_output_nb);
3316 deferred_takeover = false;
3320 for_each_registered_fb(i) {
3324 info = registered_fb[i];
3326 if (info->queue.func)
3327 pending = cancel_work_sync(&info->queue);
3328 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3331 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3332 if (con2fb_map[j] == i) {
3339 if (info->fbops->fb_release)
3340 info->fbops->fb_release(info, 0);
3341 module_put(info->fbops->owner);
3343 if (info->fbcon_par) {
3344 struct fbcon_ops *ops = info->fbcon_par;
3346 fbcon_del_cursor_timer(info);
3347 kfree(ops->cursor_src);
3348 kfree(ops->cursor_state.mask);
3349 kfree(info->fbcon_par);
3350 info->fbcon_par = NULL;
3353 if (info->queue.func == fb_flashcursor)
3354 info->queue.func = NULL;
3359 void __init fb_console_init(void)
3364 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3367 if (IS_ERR(fbcon_device)) {
3368 printk(KERN_WARNING "Unable to create device "
3369 "for fbcon; errno = %ld\n",
3370 PTR_ERR(fbcon_device));
3371 fbcon_device = NULL;
3373 fbcon_init_device();
3375 for (i = 0; i < MAX_NR_CONSOLES; i++)
3384 static void __exit fbcon_deinit_device(void)
3388 if (fbcon_has_sysfs) {
3389 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3390 device_remove_file(fbcon_device, &device_attrs[i]);
3392 fbcon_has_sysfs = 0;
3396 void __exit fb_console_exit(void)
3399 fbcon_deinit_device();
3400 device_destroy(fb_class, MKDEV(0, 0));
3402 do_unregister_con_driver(&fb_con);