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 unsigned int first_fb_vc;
119 static unsigned 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;
467 if (first_fb_vc >= MAX_NR_CONSOLES)
469 if (*options++ == '-')
470 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
471 if (last_fb_vc < first_fb_vc || last_fb_vc >= MAX_NR_CONSOLES)
472 last_fb_vc = MAX_NR_CONSOLES - 1;
473 fbcon_is_default = 0;
477 if (!strncmp(options, "rotate:", 7)) {
480 initial_rotation = simple_strtoul(options, &options, 0);
481 if (initial_rotation > 3)
482 initial_rotation = 0;
486 if (!strncmp(options, "margin:", 7)) {
489 margin_color = simple_strtoul(options, &options, 0);
492 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
493 if (!strcmp(options, "nodefer")) {
494 deferred_takeover = false;
499 if (!strncmp(options, "logo-pos:", 9)) {
501 if (!strcmp(options, "center"))
502 fb_center_logo = true;
506 if (!strncmp(options, "logo-count:", 11)) {
509 fb_logo_count = simple_strtol(options, &options, 0);
516 __setup("fbcon=", fb_console_setup);
519 static int search_fb_in_map(int idx)
523 for (i = first_fb_vc; i <= last_fb_vc; i++) {
524 if (con2fb_map[i] == idx)
530 static int search_for_mapped_con(void)
534 for (i = first_fb_vc; i <= last_fb_vc; i++) {
535 if (con2fb_map[i] != -1)
541 static int do_fbcon_takeover(int show_logo)
545 if (!num_registered_fb)
549 logo_shown = FBCON_LOGO_DONTSHOW;
551 for (i = first_fb_vc; i <= last_fb_vc; i++)
552 con2fb_map[i] = info_idx;
554 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
558 for (i = first_fb_vc; i <= last_fb_vc; i++)
562 fbcon_has_console_bind = 1;
569 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
570 int cols, int rows, int new_cols, int new_rows)
572 logo_shown = FBCON_LOGO_DONTSHOW;
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 /* Need to make room for the logo */
579 struct fbcon_ops *ops = info->fbcon_par;
580 int cnt, erase = vc->vc_video_erase_char, step;
581 unsigned short *save = NULL, *r, *q;
584 if (info->fbops->owner) {
585 logo_shown = FBCON_LOGO_DONTSHOW;
590 * remove underline attribute from erase character
591 * if black and white framebuffer.
593 if (fb_get_color_depth(&info->var, &info->fix) == 1)
595 logo_height = fb_prepare_logo(info, ops->rotate);
596 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
597 q = (unsigned short *) (vc->vc_origin +
598 vc->vc_size_row * rows);
599 step = logo_lines * cols;
600 for (r = q - logo_lines * cols; r < q; r++)
601 if (scr_readw(r) != vc->vc_video_erase_char)
603 if (r != q && new_rows >= rows + logo_lines) {
604 save = kmalloc(array3_size(logo_lines, new_cols, 2),
607 int i = cols < new_cols ? cols : new_cols;
608 scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
610 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
611 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
616 /* We can scroll screen down */
618 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
619 scr_memcpyw(r + step, r, vc->vc_size_row);
624 if (vc->state.y + logo_lines >= rows)
625 lines = rows - vc->state.y - 1;
628 vc->state.y += lines;
629 vc->vc_pos += lines * vc->vc_size_row;
632 scr_memsetw((unsigned short *) vc->vc_origin,
634 vc->vc_size_row * logo_lines);
636 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
637 fbcon_clear_margins(vc, 0);
642 q = (unsigned short *) (vc->vc_origin +
645 scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
646 vc->state.y += logo_lines;
647 vc->vc_pos += logo_lines * vc->vc_size_row;
651 if (logo_shown == FBCON_LOGO_DONTSHOW)
654 if (logo_lines > vc->vc_bottom) {
655 logo_shown = FBCON_LOGO_CANSHOW;
657 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
659 logo_shown = FBCON_LOGO_DRAW;
660 vc->vc_top = logo_lines;
665 #ifdef CONFIG_FB_TILEBLITTING
666 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
668 struct fbcon_ops *ops = info->fbcon_par;
670 ops->p = &fb_display[vc->vc_num];
672 if ((info->flags & FBINFO_MISC_TILEBLITTING))
673 fbcon_set_tileops(vc, info);
675 fbcon_set_rotation(info);
676 fbcon_set_bitops(ops);
680 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
684 if (info->flags & FBINFO_MISC_TILEBLITTING &&
685 info->tileops->fb_get_tilemax(info) < charcount)
691 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
693 struct fbcon_ops *ops = info->fbcon_par;
695 info->flags &= ~FBINFO_MISC_TILEBLITTING;
696 ops->p = &fb_display[vc->vc_num];
697 fbcon_set_rotation(info);
698 fbcon_set_bitops(ops);
701 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
706 #endif /* CONFIG_MISC_TILEBLITTING */
709 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
710 int unit, int oldidx)
712 struct fbcon_ops *ops = NULL;
715 if (!try_module_get(info->fbops->owner))
718 if (!err && info->fbops->fb_open &&
719 info->fbops->fb_open(info, 0))
723 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
729 ops->cur_blink_jiffies = HZ / 5;
731 info->fbcon_par = ops;
734 set_blitting_type(vc, info);
738 con2fb_map[unit] = oldidx;
739 module_put(info->fbops->owner);
745 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
746 struct fb_info *newinfo, int unit,
747 int oldidx, int found)
749 struct fbcon_ops *ops = oldinfo->fbcon_par;
752 if (oldinfo->fbops->fb_release &&
753 oldinfo->fbops->fb_release(oldinfo, 0)) {
754 con2fb_map[unit] = oldidx;
755 if (!found && newinfo->fbops->fb_release)
756 newinfo->fbops->fb_release(newinfo, 0);
758 module_put(newinfo->fbops->owner);
763 fbcon_del_cursor_timer(oldinfo);
764 kfree(ops->cursor_state.mask);
765 kfree(ops->cursor_data);
766 kfree(ops->cursor_src);
767 kfree(ops->fontbuffer);
768 kfree(oldinfo->fbcon_par);
769 oldinfo->fbcon_par = NULL;
770 module_put(oldinfo->fbops->owner);
772 If oldinfo and newinfo are driving the same hardware,
773 the fb_release() method of oldinfo may attempt to
774 restore the hardware state. This will leave the
775 newinfo in an undefined state. Thus, a call to
776 fb_set_par() may be needed for the newinfo.
778 if (newinfo && newinfo->fbops->fb_set_par) {
779 ret = newinfo->fbops->fb_set_par(newinfo);
782 printk(KERN_ERR "con2fb_release_oldinfo: "
783 "detected unhandled fb_set_par error, "
784 "error code %d\n", ret);
791 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
792 int unit, int show_logo)
794 struct fbcon_ops *ops = info->fbcon_par;
797 ops->currcon = fg_console;
799 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
800 ret = info->fbops->fb_set_par(info);
803 printk(KERN_ERR "con2fb_init_display: detected "
804 "unhandled fb_set_par error, "
805 "error code %d\n", ret);
808 ops->flags |= FBCON_FLAGS_INIT;
810 fbcon_set_disp(info, &info->var, unit);
813 struct vc_data *fg_vc = vc_cons[fg_console].d;
814 struct fb_info *fg_info =
815 registered_fb[con2fb_map[fg_console]];
817 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
818 fg_vc->vc_rows, fg_vc->vc_cols,
822 update_screen(vc_cons[fg_console].d);
826 * set_con2fb_map - map console to frame buffer device
827 * @unit: virtual console number to map
828 * @newidx: frame buffer index to map virtual console to
829 * @user: user request
831 * Maps a virtual console @unit to a frame buffer device
834 * This should be called with the console lock held.
836 static int set_con2fb_map(int unit, int newidx, int user)
838 struct vc_data *vc = vc_cons[unit].d;
839 int oldidx = con2fb_map[unit];
840 struct fb_info *info = registered_fb[newidx];
841 struct fb_info *oldinfo = NULL;
844 WARN_CONSOLE_UNLOCKED();
846 if (oldidx == newidx)
852 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
854 return do_fbcon_takeover(0);
858 oldinfo = registered_fb[oldidx];
860 found = search_fb_in_map(newidx);
862 con2fb_map[unit] = newidx;
864 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
867 * If old fb is not mapped to any of the consoles,
868 * fbcon should release it.
870 if (!err && oldinfo && !search_fb_in_map(oldidx))
871 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
875 int show_logo = (fg_console == 0 && !user &&
876 logo_shown != FBCON_LOGO_DONTSHOW);
879 fbcon_add_cursor_timer(info);
880 con2fb_map_boot[unit] = newidx;
881 con2fb_init_display(vc, info, unit, show_logo);
884 if (!search_fb_in_map(info_idx))
891 * Low Level Operations
893 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
894 static int var_to_display(struct fbcon_display *disp,
895 struct fb_var_screeninfo *var,
896 struct fb_info *info)
898 disp->xres_virtual = var->xres_virtual;
899 disp->yres_virtual = var->yres_virtual;
900 disp->bits_per_pixel = var->bits_per_pixel;
901 disp->grayscale = var->grayscale;
902 disp->nonstd = var->nonstd;
903 disp->accel_flags = var->accel_flags;
904 disp->height = var->height;
905 disp->width = var->width;
906 disp->red = var->red;
907 disp->green = var->green;
908 disp->blue = var->blue;
909 disp->transp = var->transp;
910 disp->rotate = var->rotate;
911 disp->mode = fb_match_mode(var, &info->modelist);
912 if (disp->mode == NULL)
913 /* This should not happen */
918 static void display_to_var(struct fb_var_screeninfo *var,
919 struct fbcon_display *disp)
921 fb_videomode_to_var(var, disp->mode);
922 var->xres_virtual = disp->xres_virtual;
923 var->yres_virtual = disp->yres_virtual;
924 var->bits_per_pixel = disp->bits_per_pixel;
925 var->grayscale = disp->grayscale;
926 var->nonstd = disp->nonstd;
927 var->accel_flags = disp->accel_flags;
928 var->height = disp->height;
929 var->width = disp->width;
930 var->red = disp->red;
931 var->green = disp->green;
932 var->blue = disp->blue;
933 var->transp = disp->transp;
934 var->rotate = disp->rotate;
937 static const char *fbcon_startup(void)
939 const char *display_desc = "frame buffer device";
940 struct fbcon_display *p = &fb_display[fg_console];
941 struct vc_data *vc = vc_cons[fg_console].d;
942 const struct font_desc *font = NULL;
943 struct module *owner;
944 struct fb_info *info = NULL;
945 struct fbcon_ops *ops;
949 * If num_registered_fb is zero, this is a call for the dummy part.
950 * The frame buffer devices weren't initialized yet.
952 if (!num_registered_fb || info_idx == -1)
955 * Instead of blindly using registered_fb[0], we use info_idx, set by
958 info = registered_fb[info_idx];
962 owner = info->fbops->owner;
963 if (!try_module_get(owner))
965 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
970 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
978 ops->cur_rotate = -1;
979 ops->cur_blink_jiffies = HZ / 5;
981 info->fbcon_par = ops;
983 p->con_rotate = initial_rotation;
984 if (p->con_rotate == -1)
985 p->con_rotate = info->fbcon_rotate_hint;
986 if (p->con_rotate == -1)
987 p->con_rotate = FB_ROTATE_UR;
989 set_blitting_type(vc, info);
991 /* Setup default font */
992 if (!p->fontdata && !vc->vc_font.data) {
993 if (!fontname[0] || !(font = find_font(fontname)))
994 font = get_default_font(info->var.xres,
997 info->pixmap.blit_y);
998 vc->vc_font.width = font->width;
999 vc->vc_font.height = font->height;
1000 vc->vc_font.data = (void *)(p->fontdata = font->data);
1001 vc->vc_font.charcount = font->charcount;
1003 p->fontdata = vc->vc_font.data;
1006 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1007 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1008 cols /= vc->vc_font.width;
1009 rows /= vc->vc_font.height;
1010 vc_resize(vc, cols, rows);
1012 pr_debug("mode: %s\n", info->fix.id);
1013 pr_debug("visual: %d\n", info->fix.visual);
1014 pr_debug("res: %dx%d-%d\n", info->var.xres,
1016 info->var.bits_per_pixel);
1018 fbcon_add_cursor_timer(info);
1019 return display_desc;
1022 static void fbcon_init(struct vc_data *vc, int init)
1024 struct fb_info *info;
1025 struct fbcon_ops *ops;
1026 struct vc_data **default_mode = vc->vc_display_fg;
1027 struct vc_data *svc = *default_mode;
1028 struct fbcon_display *t, *p = &fb_display[vc->vc_num];
1029 int logo = 1, new_rows, new_cols, rows, cols;
1032 if (WARN_ON(info_idx == -1))
1035 if (con2fb_map[vc->vc_num] == -1)
1036 con2fb_map[vc->vc_num] = info_idx;
1038 info = registered_fb[con2fb_map[vc->vc_num]];
1040 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1041 logo_shown = FBCON_LOGO_DONTSHOW;
1043 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1044 (info->fix.type == FB_TYPE_TEXT))
1047 if (var_to_display(p, &info->var, info))
1050 if (!info->fbcon_par)
1051 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1053 /* If we are not the first console on this
1054 fb, copy the font from that console */
1055 t = &fb_display[fg_console];
1058 struct vc_data *fvc = vc_cons[fg_console].d;
1060 vc->vc_font.data = (void *)(p->fontdata =
1062 vc->vc_font.width = fvc->vc_font.width;
1063 vc->vc_font.height = fvc->vc_font.height;
1064 vc->vc_font.charcount = fvc->vc_font.charcount;
1065 p->userfont = t->userfont;
1068 REFCOUNT(p->fontdata)++;
1070 const struct font_desc *font = NULL;
1072 if (!fontname[0] || !(font = find_font(fontname)))
1073 font = get_default_font(info->var.xres,
1075 info->pixmap.blit_x,
1076 info->pixmap.blit_y);
1077 vc->vc_font.width = font->width;
1078 vc->vc_font.height = font->height;
1079 vc->vc_font.data = (void *)(p->fontdata = font->data);
1080 vc->vc_font.charcount = font->charcount;
1084 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1085 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1086 if (vc->vc_font.charcount == 256) {
1087 vc->vc_hi_font_mask = 0;
1089 vc->vc_hi_font_mask = 0x100;
1090 if (vc->vc_can_do_color)
1091 vc->vc_complement_mask <<= 1;
1094 if (!*svc->vc_uni_pagedir_loc)
1095 con_set_default_unimap(svc);
1096 if (!*vc->vc_uni_pagedir_loc)
1097 con_copy_unimap(vc, svc);
1099 ops = info->fbcon_par;
1100 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1102 p->con_rotate = initial_rotation;
1103 if (p->con_rotate == -1)
1104 p->con_rotate = info->fbcon_rotate_hint;
1105 if (p->con_rotate == -1)
1106 p->con_rotate = FB_ROTATE_UR;
1108 set_blitting_type(vc, info);
1112 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1113 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1114 new_cols /= vc->vc_font.width;
1115 new_rows /= vc->vc_font.height;
1118 * We must always set the mode. The mode of the previous console
1119 * driver could be in the same resolution but we are using different
1120 * hardware so we have to initialize the hardware.
1122 * We need to do it in fbcon_init() to prevent screen corruption.
1124 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1125 if (info->fbops->fb_set_par &&
1126 !(ops->flags & FBCON_FLAGS_INIT)) {
1127 ret = info->fbops->fb_set_par(info);
1130 printk(KERN_ERR "fbcon_init: detected "
1131 "unhandled fb_set_par error, "
1132 "error code %d\n", ret);
1135 ops->flags |= FBCON_FLAGS_INIT;
1140 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1141 if ((info->flags & FBINFO_HWACCEL_COPYAREA) &&
1142 !(info->flags & FBINFO_HWACCEL_DISABLED))
1143 p->scrollmode = SCROLL_MOVE;
1144 else /* default to something safe */
1145 p->scrollmode = SCROLL_REDRAW;
1149 * ++guenther: console.c:vc_allocate() relies on initializing
1150 * vc_{cols,rows}, but we must not set those if we are only
1151 * resizing the console.
1154 vc->vc_cols = new_cols;
1155 vc->vc_rows = new_rows;
1157 vc_resize(vc, new_cols, new_rows);
1160 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1162 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1163 ops->rotate = FB_ROTATE_UR;
1164 set_blitting_type(vc, info);
1167 ops->p = &fb_display[fg_console];
1170 static void fbcon_free_font(struct fbcon_display *p, bool freefont)
1172 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1173 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1178 static void set_vc_hi_font(struct vc_data *vc, bool set);
1180 static void fbcon_deinit(struct vc_data *vc)
1182 struct fbcon_display *p = &fb_display[vc->vc_num];
1183 struct fb_info *info;
1184 struct fbcon_ops *ops;
1186 bool free_font = true;
1188 idx = con2fb_map[vc->vc_num];
1193 info = registered_fb[idx];
1198 if (info->flags & FBINFO_MISC_FIRMWARE)
1200 ops = info->fbcon_par;
1205 if (con_is_visible(vc))
1206 fbcon_del_cursor_timer(info);
1208 ops->flags &= ~FBCON_FLAGS_INIT;
1211 fbcon_free_font(p, free_font);
1213 vc->vc_font.data = NULL;
1215 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1216 set_vc_hi_font(vc, false);
1218 if (!con_is_bound(&fb_con))
1221 if (vc->vc_num == logo_shown)
1222 logo_shown = FBCON_LOGO_CANSHOW;
1227 /* ====================================================================== */
1229 /* fbcon_XXX routines - interface used by the world
1231 * This system is now divided into two levels because of complications
1232 * caused by hardware scrolling. Top level functions:
1234 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1236 * handles y values in range [0, scr_height-1] that correspond to real
1237 * screen positions. y_wrap shift means that first line of bitmap may be
1238 * anywhere on this display. These functions convert lineoffsets to
1239 * bitmap offsets and deal with the wrap-around case by splitting blits.
1241 * fbcon_bmove_physical_8() -- These functions fast implementations
1242 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1243 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1247 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1248 * Implies should only really hardware scroll in rows. Only reason for
1249 * restriction is simplicity & efficiency at the moment.
1252 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1255 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1256 struct fbcon_ops *ops = info->fbcon_par;
1258 struct fbcon_display *p = &fb_display[vc->vc_num];
1261 if (fbcon_is_inactive(vc, info))
1264 if (!height || !width)
1267 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1270 * If the font dimensions are not an integral of the display
1271 * dimensions then the ops->clear below won't end up clearing
1272 * the margins. Call clear_margins here in case the logo
1273 * bitmap stretched into the margin area.
1275 fbcon_clear_margins(vc, 0);
1278 /* Split blits that cross physical y_wrap boundary */
1280 y_break = p->vrows - p->yscroll;
1281 if (sy < y_break && sy + height - 1 >= y_break) {
1282 u_int b = y_break - sy;
1283 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1284 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1287 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1290 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1291 int count, int ypos, int xpos)
1293 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1294 struct fbcon_display *p = &fb_display[vc->vc_num];
1295 struct fbcon_ops *ops = info->fbcon_par;
1297 if (!fbcon_is_inactive(vc, info))
1298 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1299 get_color(vc, info, scr_readw(s), 1),
1300 get_color(vc, info, scr_readw(s), 0));
1303 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1307 scr_writew(c, &chr);
1308 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1311 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1313 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1314 struct fbcon_ops *ops = info->fbcon_par;
1316 if (!fbcon_is_inactive(vc, info))
1317 ops->clear_margins(vc, info, margin_color, bottom_only);
1320 static void fbcon_cursor(struct vc_data *vc, int mode)
1322 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1323 struct fbcon_ops *ops = info->fbcon_par;
1324 int c = scr_readw((u16 *) vc->vc_pos);
1326 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1328 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1331 if (vc->vc_cursor_type & CUR_SW)
1332 fbcon_del_cursor_timer(info);
1334 fbcon_add_cursor_timer(info);
1336 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1341 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1342 get_color(vc, info, c, 0));
1345 static int scrollback_phys_max = 0;
1346 static int scrollback_max = 0;
1347 static int scrollback_current = 0;
1349 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1352 struct fbcon_display *p, *t;
1353 struct vc_data **default_mode, *vc;
1354 struct vc_data *svc;
1355 struct fbcon_ops *ops = info->fbcon_par;
1358 p = &fb_display[unit];
1360 if (var_to_display(p, var, info))
1363 vc = vc_cons[unit].d;
1368 default_mode = vc->vc_display_fg;
1369 svc = *default_mode;
1370 t = &fb_display[svc->vc_num];
1372 if (!vc->vc_font.data) {
1373 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1374 vc->vc_font.width = (*default_mode)->vc_font.width;
1375 vc->vc_font.height = (*default_mode)->vc_font.height;
1376 vc->vc_font.charcount = (*default_mode)->vc_font.charcount;
1377 p->userfont = t->userfont;
1379 REFCOUNT(p->fontdata)++;
1382 var->activate = FB_ACTIVATE_NOW;
1383 info->var.activate = var->activate;
1384 var->yoffset = info->var.yoffset;
1385 var->xoffset = info->var.xoffset;
1386 fb_set_var(info, var);
1387 ops->var = info->var;
1388 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1389 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1390 if (vc->vc_font.charcount == 256) {
1391 vc->vc_hi_font_mask = 0;
1393 vc->vc_hi_font_mask = 0x100;
1394 if (vc->vc_can_do_color)
1395 vc->vc_complement_mask <<= 1;
1398 if (!*svc->vc_uni_pagedir_loc)
1399 con_set_default_unimap(svc);
1400 if (!*vc->vc_uni_pagedir_loc)
1401 con_copy_unimap(vc, svc);
1403 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1404 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1405 cols /= vc->vc_font.width;
1406 rows /= vc->vc_font.height;
1407 vc_resize(vc, cols, rows);
1409 if (con_is_visible(vc)) {
1414 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1416 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1417 struct fbcon_ops *ops = info->fbcon_par;
1418 struct fbcon_display *p = &fb_display[vc->vc_num];
1420 p->yscroll += count;
1421 if (p->yscroll >= p->vrows) /* Deal with wrap */
1422 p->yscroll -= p->vrows;
1423 ops->var.xoffset = 0;
1424 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1425 ops->var.vmode |= FB_VMODE_YWRAP;
1426 ops->update_start(info);
1427 scrollback_max += count;
1428 if (scrollback_max > scrollback_phys_max)
1429 scrollback_max = scrollback_phys_max;
1430 scrollback_current = 0;
1433 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1435 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1436 struct fbcon_ops *ops = info->fbcon_par;
1437 struct fbcon_display *p = &fb_display[vc->vc_num];
1439 p->yscroll -= count;
1440 if (p->yscroll < 0) /* Deal with wrap */
1441 p->yscroll += p->vrows;
1442 ops->var.xoffset = 0;
1443 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1444 ops->var.vmode |= FB_VMODE_YWRAP;
1445 ops->update_start(info);
1446 scrollback_max -= count;
1447 if (scrollback_max < 0)
1449 scrollback_current = 0;
1452 static __inline__ void ypan_up(struct vc_data *vc, int count)
1454 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1455 struct fbcon_display *p = &fb_display[vc->vc_num];
1456 struct fbcon_ops *ops = info->fbcon_par;
1458 p->yscroll += count;
1459 if (p->yscroll > p->vrows - vc->vc_rows) {
1460 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1461 0, 0, 0, vc->vc_rows, vc->vc_cols);
1462 p->yscroll -= p->vrows - vc->vc_rows;
1465 ops->var.xoffset = 0;
1466 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1467 ops->var.vmode &= ~FB_VMODE_YWRAP;
1468 ops->update_start(info);
1469 fbcon_clear_margins(vc, 1);
1470 scrollback_max += count;
1471 if (scrollback_max > scrollback_phys_max)
1472 scrollback_max = scrollback_phys_max;
1473 scrollback_current = 0;
1476 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1478 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1479 struct fbcon_ops *ops = info->fbcon_par;
1480 struct fbcon_display *p = &fb_display[vc->vc_num];
1482 p->yscroll += count;
1484 if (p->yscroll > p->vrows - vc->vc_rows) {
1485 p->yscroll -= p->vrows - vc->vc_rows;
1486 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1489 ops->var.xoffset = 0;
1490 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1491 ops->var.vmode &= ~FB_VMODE_YWRAP;
1492 ops->update_start(info);
1493 fbcon_clear_margins(vc, 1);
1494 scrollback_max += count;
1495 if (scrollback_max > scrollback_phys_max)
1496 scrollback_max = scrollback_phys_max;
1497 scrollback_current = 0;
1500 static __inline__ void ypan_down(struct vc_data *vc, int count)
1502 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1503 struct fbcon_display *p = &fb_display[vc->vc_num];
1504 struct fbcon_ops *ops = info->fbcon_par;
1506 p->yscroll -= count;
1507 if (p->yscroll < 0) {
1508 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1509 0, vc->vc_rows, vc->vc_cols);
1510 p->yscroll += p->vrows - vc->vc_rows;
1513 ops->var.xoffset = 0;
1514 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1515 ops->var.vmode &= ~FB_VMODE_YWRAP;
1516 ops->update_start(info);
1517 fbcon_clear_margins(vc, 1);
1518 scrollback_max -= count;
1519 if (scrollback_max < 0)
1521 scrollback_current = 0;
1524 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1526 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1527 struct fbcon_ops *ops = info->fbcon_par;
1528 struct fbcon_display *p = &fb_display[vc->vc_num];
1530 p->yscroll -= count;
1532 if (p->yscroll < 0) {
1533 p->yscroll += p->vrows - vc->vc_rows;
1534 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1537 ops->var.xoffset = 0;
1538 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1539 ops->var.vmode &= ~FB_VMODE_YWRAP;
1540 ops->update_start(info);
1541 fbcon_clear_margins(vc, 1);
1542 scrollback_max -= count;
1543 if (scrollback_max < 0)
1545 scrollback_current = 0;
1548 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
1549 int line, int count, int dy)
1551 unsigned short *s = (unsigned short *)
1552 (vc->vc_origin + vc->vc_size_row * line);
1555 unsigned short *start = s;
1556 unsigned short *le = advance_row(s, 1);
1559 unsigned short attr = 1;
1563 if (attr != (c & 0xff00)) {
1566 fbcon_putcs(vc, start, s - start,
1572 console_conditional_schedule();
1576 fbcon_putcs(vc, start, s - start, dy, x);
1577 console_conditional_schedule();
1582 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1583 struct fbcon_display *p, int line, int count, int ycount)
1585 int offset = ycount * vc->vc_cols;
1586 unsigned short *d = (unsigned short *)
1587 (vc->vc_origin + vc->vc_size_row * line);
1588 unsigned short *s = d + offset;
1589 struct fbcon_ops *ops = info->fbcon_par;
1592 unsigned short *start = s;
1593 unsigned short *le = advance_row(s, 1);
1600 if (c == scr_readw(d)) {
1602 ops->bmove(vc, info, line + ycount, x,
1603 line, x, 1, s-start);
1613 console_conditional_schedule();
1618 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1620 console_conditional_schedule();
1625 /* NOTE: We subtract two lines from these pointers */
1626 s -= vc->vc_size_row;
1627 d -= vc->vc_size_row;
1632 static void fbcon_redraw(struct vc_data *vc, struct fbcon_display *p,
1633 int line, int count, int offset)
1635 unsigned short *d = (unsigned short *)
1636 (vc->vc_origin + vc->vc_size_row * line);
1637 unsigned short *s = d + offset;
1640 unsigned short *start = s;
1641 unsigned short *le = advance_row(s, 1);
1644 unsigned short attr = 1;
1648 if (attr != (c & 0xff00)) {
1651 fbcon_putcs(vc, start, s - start,
1657 if (c == scr_readw(d)) {
1659 fbcon_putcs(vc, start, s - start,
1669 console_conditional_schedule();
1674 fbcon_putcs(vc, start, s - start, line, x);
1675 console_conditional_schedule();
1680 /* NOTE: We subtract two lines from these pointers */
1681 s -= vc->vc_size_row;
1682 d -= vc->vc_size_row;
1687 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1688 enum con_scroll dir, unsigned int count)
1690 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1691 struct fbcon_display *p = &fb_display[vc->vc_num];
1692 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1694 if (fbcon_is_inactive(vc, info))
1697 fbcon_cursor(vc, CM_ERASE);
1700 * ++Geert: Only use ywrap/ypan if the console is in text mode
1701 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1702 * whole screen (prevents flicker).
1707 if (count > vc->vc_rows) /* Maximum realistic size */
1708 count = vc->vc_rows;
1709 if (logo_shown >= 0)
1711 switch (fb_scrollmode(p)) {
1713 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1715 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1716 scr_memsetw((unsigned short *) (vc->vc_origin +
1719 vc->vc_video_erase_char,
1720 vc->vc_size_row * count);
1723 case SCROLL_WRAP_MOVE:
1724 if (b - t - count > 3 * vc->vc_rows >> 2) {
1726 fbcon_bmove(vc, 0, 0, count, 0, t,
1728 ywrap_up(vc, count);
1729 if (vc->vc_rows - b > 0)
1730 fbcon_bmove(vc, b - count, 0, b, 0,
1733 } else if (info->flags & FBINFO_READS_FAST)
1734 fbcon_bmove(vc, t + count, 0, t, 0,
1735 b - t - count, vc->vc_cols);
1738 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1741 case SCROLL_PAN_REDRAW:
1742 if ((p->yscroll + count <=
1743 2 * (p->vrows - vc->vc_rows))
1744 && ((!scroll_partial && (b - t == vc->vc_rows))
1747 3 * vc->vc_rows >> 2)))) {
1749 fbcon_redraw_move(vc, p, 0, t, count);
1750 ypan_up_redraw(vc, t, count);
1751 if (vc->vc_rows - b > 0)
1752 fbcon_redraw_move(vc, p, b,
1753 vc->vc_rows - b, b);
1755 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1756 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1759 case SCROLL_PAN_MOVE:
1760 if ((p->yscroll + count <=
1761 2 * (p->vrows - vc->vc_rows))
1762 && ((!scroll_partial && (b - t == vc->vc_rows))
1765 3 * vc->vc_rows >> 2)))) {
1767 fbcon_bmove(vc, 0, 0, count, 0, t,
1770 if (vc->vc_rows - b > 0)
1771 fbcon_bmove(vc, b - count, 0, b, 0,
1774 } else if (info->flags & FBINFO_READS_FAST)
1775 fbcon_bmove(vc, t + count, 0, t, 0,
1776 b - t - count, vc->vc_cols);
1779 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1784 fbcon_redraw(vc, p, t, b - t - count,
1785 count * vc->vc_cols);
1786 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1787 scr_memsetw((unsigned short *) (vc->vc_origin +
1790 vc->vc_video_erase_char,
1791 vc->vc_size_row * count);
1797 if (count > vc->vc_rows) /* Maximum realistic size */
1798 count = vc->vc_rows;
1799 if (logo_shown >= 0)
1801 switch (fb_scrollmode(p)) {
1803 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1805 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1806 scr_memsetw((unsigned short *) (vc->vc_origin +
1809 vc->vc_video_erase_char,
1810 vc->vc_size_row * count);
1813 case SCROLL_WRAP_MOVE:
1814 if (b - t - count > 3 * vc->vc_rows >> 2) {
1815 if (vc->vc_rows - b > 0)
1816 fbcon_bmove(vc, b, 0, b - count, 0,
1819 ywrap_down(vc, count);
1821 fbcon_bmove(vc, count, 0, 0, 0, t,
1823 } else if (info->flags & FBINFO_READS_FAST)
1824 fbcon_bmove(vc, t, 0, t + count, 0,
1825 b - t - count, vc->vc_cols);
1828 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1831 case SCROLL_PAN_MOVE:
1832 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1833 && ((!scroll_partial && (b - t == vc->vc_rows))
1836 3 * vc->vc_rows >> 2)))) {
1837 if (vc->vc_rows - b > 0)
1838 fbcon_bmove(vc, b, 0, b - count, 0,
1841 ypan_down(vc, count);
1843 fbcon_bmove(vc, count, 0, 0, 0, t,
1845 } else if (info->flags & FBINFO_READS_FAST)
1846 fbcon_bmove(vc, t, 0, t + count, 0,
1847 b - t - count, vc->vc_cols);
1850 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1853 case SCROLL_PAN_REDRAW:
1854 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1855 && ((!scroll_partial && (b - t == vc->vc_rows))
1858 3 * vc->vc_rows >> 2)))) {
1859 if (vc->vc_rows - b > 0)
1860 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1862 ypan_down_redraw(vc, t, count);
1864 fbcon_redraw_move(vc, p, count, t, 0);
1866 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1867 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1872 fbcon_redraw(vc, p, b - 1, b - t - count,
1873 -count * vc->vc_cols);
1874 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1875 scr_memsetw((unsigned short *) (vc->vc_origin +
1878 vc->vc_video_erase_char,
1879 vc->vc_size_row * count);
1887 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1888 int height, int width)
1890 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1891 struct fbcon_display *p = &fb_display[vc->vc_num];
1893 if (fbcon_is_inactive(vc, info))
1896 if (!width || !height)
1899 /* Split blits that cross physical y_wrap case.
1900 * Pathological case involves 4 blits, better to use recursive
1901 * code rather than unrolled case
1903 * Recursive invocations don't need to erase the cursor over and
1904 * over again, so we use fbcon_bmove_rec()
1906 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1907 p->vrows - p->yscroll);
1910 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
1911 int dy, int dx, int height, int width, u_int y_break)
1913 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1914 struct fbcon_ops *ops = info->fbcon_par;
1917 if (sy < y_break && sy + height > y_break) {
1919 if (dy < sy) { /* Avoid trashing self */
1920 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1922 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1923 height - b, width, y_break);
1925 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1926 height - b, width, y_break);
1927 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1933 if (dy < y_break && dy + height > y_break) {
1935 if (dy < sy) { /* Avoid trashing self */
1936 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1938 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1939 height - b, width, y_break);
1941 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1942 height - b, width, y_break);
1943 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1948 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1952 static void updatescrollmode_accel(struct fbcon_display *p,
1953 struct fb_info *info,
1956 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1957 struct fbcon_ops *ops = info->fbcon_par;
1958 int cap = info->flags;
1960 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1961 info->fix.xpanstep);
1962 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1963 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1964 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1965 info->var.xres_virtual);
1966 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1967 divides(ypan, vc->vc_font.height) && vyres > yres;
1968 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1969 divides(ywrap, vc->vc_font.height) &&
1970 divides(vc->vc_font.height, vyres) &&
1971 divides(vc->vc_font.height, yres);
1972 int reading_fast = cap & FBINFO_READS_FAST;
1973 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1974 !(cap & FBINFO_HWACCEL_DISABLED);
1975 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1976 !(cap & FBINFO_HWACCEL_DISABLED);
1978 if (good_wrap || good_pan) {
1979 if (reading_fast || fast_copyarea)
1980 p->scrollmode = good_wrap ?
1981 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1983 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1986 if (reading_fast || (fast_copyarea && !fast_imageblit))
1987 p->scrollmode = SCROLL_MOVE;
1989 p->scrollmode = SCROLL_REDRAW;
1994 static void updatescrollmode(struct fbcon_display *p,
1995 struct fb_info *info,
1998 struct fbcon_ops *ops = info->fbcon_par;
1999 int fh = vc->vc_font.height;
2000 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2001 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2002 info->var.xres_virtual);
2004 p->vrows = vyres/fh;
2005 if (yres > (fh * (vc->vc_rows + 1)))
2006 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2007 if ((yres % fh) && (vyres % fh < yres % fh))
2010 /* update scrollmode in case hardware acceleration is used */
2011 updatescrollmode_accel(p, info, vc);
2014 #define PITCH(w) (((w) + 7) >> 3)
2015 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
2017 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2018 unsigned int height, unsigned int user)
2020 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2021 struct fbcon_ops *ops = info->fbcon_par;
2022 struct fbcon_display *p = &fb_display[vc->vc_num];
2023 struct fb_var_screeninfo var = info->var;
2024 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2026 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
2028 int pitch = PITCH(vc->vc_font.width);
2031 * If user font, ensure that a possible change to user font
2032 * height or width will not allow a font data out-of-bounds access.
2033 * NOTE: must use original charcount in calculation as font
2034 * charcount can change and cannot be used to determine the
2035 * font data allocated size.
2039 size = CALC_FONTSZ(vc->vc_font.height, pitch, vc->vc_font.charcount);
2040 if (size > FNTSIZE(vc->vc_font.data))
2044 virt_w = FBCON_SWAP(ops->rotate, width, height);
2045 virt_h = FBCON_SWAP(ops->rotate, height, width);
2046 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2047 vc->vc_font.height);
2048 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2050 var.xres = virt_w * virt_fw;
2051 var.yres = virt_h * virt_fh;
2052 x_diff = info->var.xres - var.xres;
2053 y_diff = info->var.yres - var.yres;
2054 if (x_diff < 0 || x_diff > virt_fw ||
2055 y_diff < 0 || y_diff > virt_fh) {
2056 const struct fb_videomode *mode;
2058 pr_debug("attempting resize %ix%i\n", var.xres, var.yres);
2059 mode = fb_find_best_mode(&var, &info->modelist);
2062 display_to_var(&var, p);
2063 fb_videomode_to_var(&var, mode);
2065 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2068 pr_debug("resize now %ix%i\n", var.xres, var.yres);
2069 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
2070 var.activate = FB_ACTIVATE_NOW |
2072 fb_set_var(info, &var);
2074 var_to_display(p, &info->var, info);
2075 ops->var = info->var;
2077 updatescrollmode(p, info, vc);
2081 static int fbcon_switch(struct vc_data *vc)
2083 struct fb_info *info, *old_info = NULL;
2084 struct fbcon_ops *ops;
2085 struct fbcon_display *p = &fb_display[vc->vc_num];
2086 struct fb_var_screeninfo var;
2087 int i, ret, prev_console;
2089 info = registered_fb[con2fb_map[vc->vc_num]];
2090 ops = info->fbcon_par;
2092 if (logo_shown >= 0) {
2093 struct vc_data *conp2 = vc_cons[logo_shown].d;
2095 if (conp2->vc_top == logo_lines
2096 && conp2->vc_bottom == conp2->vc_rows)
2098 logo_shown = FBCON_LOGO_CANSHOW;
2101 prev_console = ops->currcon;
2102 if (prev_console != -1)
2103 old_info = registered_fb[con2fb_map[prev_console]];
2105 * FIXME: If we have multiple fbdev's loaded, we need to
2106 * update all info->currcon. Perhaps, we can place this
2107 * in a centralized structure, but this might break some
2110 * info->currcon = vc->vc_num;
2112 for_each_registered_fb(i) {
2113 if (registered_fb[i]->fbcon_par) {
2114 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2116 o->currcon = vc->vc_num;
2119 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2120 display_to_var(&var, p);
2121 var.activate = FB_ACTIVATE_NOW;
2124 * make sure we don't unnecessarily trip the memcmp()
2127 info->var.activate = var.activate;
2128 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2129 fb_set_var(info, &var);
2130 ops->var = info->var;
2132 if (old_info != NULL && (old_info != info ||
2133 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2134 if (info->fbops->fb_set_par) {
2135 ret = info->fbops->fb_set_par(info);
2138 printk(KERN_ERR "fbcon_switch: detected "
2139 "unhandled fb_set_par error, "
2140 "error code %d\n", ret);
2143 if (old_info != info)
2144 fbcon_del_cursor_timer(old_info);
2147 if (fbcon_is_inactive(vc, info) ||
2148 ops->blank_state != FB_BLANK_UNBLANK)
2149 fbcon_del_cursor_timer(info);
2151 fbcon_add_cursor_timer(info);
2153 set_blitting_type(vc, info);
2154 ops->cursor_reset = 1;
2156 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2157 ops->rotate = FB_ROTATE_UR;
2158 set_blitting_type(vc, info);
2161 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2162 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2164 if (vc->vc_font.charcount > 256)
2165 vc->vc_complement_mask <<= 1;
2167 updatescrollmode(p, info, vc);
2169 switch (fb_scrollmode(p)) {
2170 case SCROLL_WRAP_MOVE:
2171 scrollback_phys_max = p->vrows - vc->vc_rows;
2173 case SCROLL_PAN_MOVE:
2174 case SCROLL_PAN_REDRAW:
2175 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2176 if (scrollback_phys_max < 0)
2177 scrollback_phys_max = 0;
2180 scrollback_phys_max = 0;
2185 scrollback_current = 0;
2187 if (!fbcon_is_inactive(vc, info)) {
2188 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2189 ops->update_start(info);
2192 fbcon_set_palette(vc, color_table);
2193 fbcon_clear_margins(vc, 0);
2195 if (logo_shown == FBCON_LOGO_DRAW) {
2197 logo_shown = fg_console;
2198 /* This is protected above by initmem_freed */
2199 fb_show_logo(info, ops->rotate);
2201 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2202 vc->vc_size_row * (vc->vc_bottom -
2209 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2213 unsigned short charmask = vc->vc_hi_font_mask ?
2215 unsigned short oldc;
2217 oldc = vc->vc_video_erase_char;
2218 vc->vc_video_erase_char &= charmask;
2219 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2220 vc->vc_video_erase_char = oldc;
2224 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2226 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2227 struct fbcon_ops *ops = info->fbcon_par;
2230 struct fb_var_screeninfo var = info->var;
2235 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE |
2236 FB_ACTIVATE_KD_TEXT;
2237 fb_set_var(info, &var);
2239 ops->var = info->var;
2243 if (!fbcon_is_inactive(vc, info)) {
2244 if (ops->blank_state != blank) {
2245 ops->blank_state = blank;
2246 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2247 ops->cursor_flash = (!blank);
2249 if (fb_blank(info, blank))
2250 fbcon_generic_blank(vc, info, blank);
2257 if (mode_switch || fbcon_is_inactive(vc, info) ||
2258 ops->blank_state != FB_BLANK_UNBLANK)
2259 fbcon_del_cursor_timer(info);
2261 fbcon_add_cursor_timer(info);
2266 static int fbcon_debug_enter(struct vc_data *vc)
2268 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2269 struct fbcon_ops *ops = info->fbcon_par;
2271 ops->save_graphics = ops->graphics;
2273 if (info->fbops->fb_debug_enter)
2274 info->fbops->fb_debug_enter(info);
2275 fbcon_set_palette(vc, color_table);
2279 static int fbcon_debug_leave(struct vc_data *vc)
2281 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2282 struct fbcon_ops *ops = info->fbcon_par;
2284 ops->graphics = ops->save_graphics;
2285 if (info->fbops->fb_debug_leave)
2286 info->fbops->fb_debug_leave(info);
2290 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2292 u8 *fontdata = vc->vc_font.data;
2293 u8 *data = font->data;
2296 font->width = vc->vc_font.width;
2297 font->height = vc->vc_font.height;
2298 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2302 if (font->width <= 8) {
2303 j = vc->vc_font.height;
2304 if (font->charcount * j > FNTSIZE(fontdata))
2307 for (i = 0; i < font->charcount; i++) {
2308 memcpy(data, fontdata, j);
2309 memset(data + j, 0, 32 - j);
2313 } else if (font->width <= 16) {
2314 j = vc->vc_font.height * 2;
2315 if (font->charcount * j > FNTSIZE(fontdata))
2318 for (i = 0; i < font->charcount; i++) {
2319 memcpy(data, fontdata, j);
2320 memset(data + j, 0, 64 - j);
2324 } else if (font->width <= 24) {
2325 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
2328 for (i = 0; i < font->charcount; i++) {
2329 for (j = 0; j < vc->vc_font.height; j++) {
2330 *data++ = fontdata[0];
2331 *data++ = fontdata[1];
2332 *data++ = fontdata[2];
2333 fontdata += sizeof(u32);
2335 memset(data, 0, 3 * (32 - j));
2336 data += 3 * (32 - j);
2339 j = vc->vc_font.height * 4;
2340 if (font->charcount * j > FNTSIZE(fontdata))
2343 for (i = 0; i < font->charcount; i++) {
2344 memcpy(data, fontdata, j);
2345 memset(data + j, 0, 128 - j);
2353 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2354 static void set_vc_hi_font(struct vc_data *vc, bool set)
2357 vc->vc_hi_font_mask = 0;
2358 if (vc->vc_can_do_color) {
2359 vc->vc_complement_mask >>= 1;
2360 vc->vc_s_complement_mask >>= 1;
2363 /* ++Edmund: reorder the attribute bits */
2364 if (vc->vc_can_do_color) {
2365 unsigned short *cp =
2366 (unsigned short *) vc->vc_origin;
2367 int count = vc->vc_screenbuf_size / 2;
2369 for (; count > 0; count--, cp++) {
2371 scr_writew(((c & 0xfe00) >> 1) |
2374 c = vc->vc_video_erase_char;
2375 vc->vc_video_erase_char =
2376 ((c & 0xfe00) >> 1) | (c & 0xff);
2380 vc->vc_hi_font_mask = 0x100;
2381 if (vc->vc_can_do_color) {
2382 vc->vc_complement_mask <<= 1;
2383 vc->vc_s_complement_mask <<= 1;
2386 /* ++Edmund: reorder the attribute bits */
2388 unsigned short *cp =
2389 (unsigned short *) vc->vc_origin;
2390 int count = vc->vc_screenbuf_size / 2;
2392 for (; count > 0; count--, cp++) {
2393 unsigned short newc;
2395 if (vc->vc_can_do_color)
2397 ((c & 0xff00) << 1) | (c &
2401 scr_writew(newc, cp);
2403 c = vc->vc_video_erase_char;
2404 if (vc->vc_can_do_color) {
2405 vc->vc_video_erase_char =
2406 ((c & 0xff00) << 1) | (c & 0xff);
2409 vc->vc_video_erase_char = c & ~0x100;
2414 static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
2415 const u8 * data, int userfont)
2417 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2418 struct fbcon_ops *ops = info->fbcon_par;
2419 struct fbcon_display *p = &fb_display[vc->vc_num];
2421 char *old_data = NULL;
2423 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2425 old_data = vc->vc_font.data;
2426 vc->vc_font.data = (void *)(p->fontdata = data);
2427 if ((p->userfont = userfont))
2429 vc->vc_font.width = w;
2430 vc->vc_font.height = h;
2431 vc->vc_font.charcount = charcount;
2432 if (vc->vc_hi_font_mask && charcount == 256)
2433 set_vc_hi_font(vc, false);
2434 else if (!vc->vc_hi_font_mask && charcount == 512)
2435 set_vc_hi_font(vc, true);
2440 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2441 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2444 vc_resize(vc, cols, rows);
2445 } else if (con_is_visible(vc)
2446 && vc->vc_mode == KD_TEXT) {
2447 fbcon_clear_margins(vc, 0);
2451 if (old_data && (--REFCOUNT(old_data) == 0))
2452 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2457 * User asked to set font; we are guaranteed that
2458 * a) width and height are in range 1..32
2459 * b) charcount does not exceed 512
2460 * but lets not assume that, since someone might someday want to use larger
2461 * fonts. And charcount of 512 is small for unicode support.
2463 * However, user space gives the font in 32 rows , regardless of
2464 * actual font height. So a new API is needed if support for larger fonts
2465 * is ever implemented.
2468 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2471 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2472 unsigned charcount = font->charcount;
2473 int w = font->width;
2474 int h = font->height;
2477 u8 *new_data, *data = font->data;
2478 int pitch = PITCH(font->width);
2480 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2481 * If not this check should be changed to charcount < 256 */
2482 if (charcount != 256 && charcount != 512)
2485 /* font bigger than screen resolution ? */
2486 if (w > FBCON_SWAP(info->var.rotate, info->var.xres, info->var.yres) ||
2487 h > FBCON_SWAP(info->var.rotate, info->var.yres, info->var.xres))
2490 /* Make sure drawing engine can handle the font */
2491 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2492 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2495 /* Make sure driver can handle the font length */
2496 if (fbcon_invalid_charcount(info, charcount))
2499 size = CALC_FONTSZ(h, pitch, charcount);
2501 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2506 memset(new_data, 0, FONT_EXTRA_WORDS * sizeof(int));
2508 new_data += FONT_EXTRA_WORDS * sizeof(int);
2509 FNTSIZE(new_data) = size;
2510 REFCOUNT(new_data) = 0; /* usage counter */
2511 for (i=0; i< charcount; i++) {
2512 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2515 /* Since linux has a nice crc32 function use it for counting font
2517 csum = crc32(0, new_data, size);
2519 FNTSUM(new_data) = csum;
2520 /* Check if the same font is on some other console already */
2521 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2522 struct vc_data *tmp = vc_cons[i].d;
2524 if (fb_display[i].userfont &&
2525 fb_display[i].fontdata &&
2526 FNTSUM(fb_display[i].fontdata) == csum &&
2527 FNTSIZE(fb_display[i].fontdata) == size &&
2528 tmp->vc_font.width == w &&
2529 !memcmp(fb_display[i].fontdata, new_data, size)) {
2530 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2531 new_data = (u8 *)fb_display[i].fontdata;
2535 return fbcon_do_set_font(vc, font->width, font->height, charcount, new_data, 1);
2538 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2540 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2541 const struct font_desc *f;
2544 f = get_default_font(info->var.xres, info->var.yres,
2545 info->pixmap.blit_x, info->pixmap.blit_y);
2546 else if (!(f = find_font(name)))
2549 font->width = f->width;
2550 font->height = f->height;
2551 return fbcon_do_set_font(vc, f->width, f->height, f->charcount, f->data, 0);
2554 static u16 palette_red[16];
2555 static u16 palette_green[16];
2556 static u16 palette_blue[16];
2558 static struct fb_cmap palette_cmap = {
2559 0, 16, palette_red, palette_green, palette_blue, NULL
2562 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2564 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2568 if (fbcon_is_inactive(vc, info))
2571 if (!con_is_visible(vc))
2574 depth = fb_get_color_depth(&info->var, &info->fix);
2576 for (i = j = 0; i < 16; i++) {
2578 val = vc->vc_palette[j++];
2579 palette_red[k] = (val << 8) | val;
2580 val = vc->vc_palette[j++];
2581 palette_green[k] = (val << 8) | val;
2582 val = vc->vc_palette[j++];
2583 palette_blue[k] = (val << 8) | val;
2585 palette_cmap.len = 16;
2586 palette_cmap.start = 0;
2588 * If framebuffer is capable of less than 16 colors,
2589 * use default palette of fbcon.
2592 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2594 fb_set_cmap(&palette_cmap, info);
2597 static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset)
2599 return (u16 *) (vc->vc_origin + offset);
2602 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2608 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2609 unsigned long offset = (pos - vc->vc_origin) / 2;
2611 x = offset % vc->vc_cols;
2612 y = offset / vc->vc_cols;
2613 ret = pos + (vc->vc_cols - x) * 2;
2615 /* Should not happen */
2617 ret = vc->vc_origin;
2626 /* As we might be inside of softback, we may work with non-contiguous buffer,
2627 that's why we have to use a separate routine. */
2628 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2631 u16 a = scr_readw(p);
2632 if (!vc->vc_can_do_color)
2634 else if (vc->vc_hi_font_mask == 0x100)
2635 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2636 (((a) & 0x0e00) << 4);
2638 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2639 (((a) & 0x0700) << 4);
2644 void fbcon_suspended(struct fb_info *info)
2646 struct vc_data *vc = NULL;
2647 struct fbcon_ops *ops = info->fbcon_par;
2649 if (!ops || ops->currcon < 0)
2651 vc = vc_cons[ops->currcon].d;
2653 /* Clear cursor, restore saved data */
2654 fbcon_cursor(vc, CM_ERASE);
2657 void fbcon_resumed(struct fb_info *info)
2660 struct fbcon_ops *ops = info->fbcon_par;
2662 if (!ops || ops->currcon < 0)
2664 vc = vc_cons[ops->currcon].d;
2669 static void fbcon_modechanged(struct fb_info *info)
2671 struct fbcon_ops *ops = info->fbcon_par;
2673 struct fbcon_display *p;
2676 if (!ops || ops->currcon < 0)
2678 vc = vc_cons[ops->currcon].d;
2679 if (vc->vc_mode != KD_TEXT ||
2680 registered_fb[con2fb_map[ops->currcon]] != info)
2683 p = &fb_display[vc->vc_num];
2684 set_blitting_type(vc, info);
2686 if (con_is_visible(vc)) {
2687 var_to_display(p, &info->var, info);
2688 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2689 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2690 cols /= vc->vc_font.width;
2691 rows /= vc->vc_font.height;
2692 vc_resize(vc, cols, rows);
2693 updatescrollmode(p, info, vc);
2695 scrollback_current = 0;
2697 if (!fbcon_is_inactive(vc, info)) {
2698 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2699 ops->update_start(info);
2702 fbcon_set_palette(vc, color_table);
2707 static void fbcon_set_all_vcs(struct fb_info *info)
2709 struct fbcon_ops *ops = info->fbcon_par;
2711 struct fbcon_display *p;
2712 int i, rows, cols, fg = -1;
2714 if (!ops || ops->currcon < 0)
2717 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2719 if (!vc || vc->vc_mode != KD_TEXT ||
2720 registered_fb[con2fb_map[i]] != info)
2723 if (con_is_visible(vc)) {
2728 p = &fb_display[vc->vc_num];
2729 set_blitting_type(vc, info);
2730 var_to_display(p, &info->var, info);
2731 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2732 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2733 cols /= vc->vc_font.width;
2734 rows /= vc->vc_font.height;
2735 vc_resize(vc, cols, rows);
2739 fbcon_modechanged(info);
2743 void fbcon_update_vcs(struct fb_info *info, bool all)
2746 fbcon_set_all_vcs(info);
2748 fbcon_modechanged(info);
2750 EXPORT_SYMBOL(fbcon_update_vcs);
2752 /* let fbcon check if it supports a new screen resolution */
2753 int fbcon_modechange_possible(struct fb_info *info, struct fb_var_screeninfo *var)
2755 struct fbcon_ops *ops = info->fbcon_par;
2759 WARN_CONSOLE_UNLOCKED();
2764 /* prevent setting a screen size which is smaller than font size */
2765 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2767 if (!vc || vc->vc_mode != KD_TEXT ||
2768 registered_fb[con2fb_map[i]] != info)
2771 if (vc->vc_font.width > FBCON_SWAP(var->rotate, var->xres, var->yres) ||
2772 vc->vc_font.height > FBCON_SWAP(var->rotate, var->yres, var->xres))
2778 EXPORT_SYMBOL_GPL(fbcon_modechange_possible);
2780 int fbcon_mode_deleted(struct fb_info *info,
2781 struct fb_videomode *mode)
2783 struct fb_info *fb_info;
2784 struct fbcon_display *p;
2785 int i, j, found = 0;
2787 /* before deletion, ensure that mode is not in use */
2788 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2792 fb_info = registered_fb[j];
2793 if (fb_info != info)
2798 if (fb_mode_is_equal(p->mode, mode)) {
2806 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2807 static void fbcon_unbind(void)
2811 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2815 fbcon_has_console_bind = 0;
2818 static inline void fbcon_unbind(void) {}
2819 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2821 /* called with console_lock held */
2822 void fbcon_fb_unbind(struct fb_info *info)
2824 int i, new_idx = -1, ret = 0;
2825 int idx = info->node;
2827 WARN_CONSOLE_UNLOCKED();
2829 if (!fbcon_has_console_bind)
2832 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2833 if (con2fb_map[i] != idx &&
2834 con2fb_map[i] != -1) {
2835 new_idx = con2fb_map[i];
2840 if (new_idx != -1) {
2841 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2842 if (con2fb_map[i] == idx)
2843 set_con2fb_map(i, new_idx, 0);
2846 struct fb_info *info = registered_fb[idx];
2848 /* This is sort of like set_con2fb_map, except it maps
2849 * the consoles to no device and then releases the
2850 * oldinfo to free memory and cancel the cursor blink
2851 * timer. I can imagine this just becoming part of
2852 * set_con2fb_map where new_idx is -1
2854 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2855 if (con2fb_map[i] == idx) {
2857 if (!search_fb_in_map(idx)) {
2858 ret = con2fb_release_oldinfo(vc_cons[i].d,
2862 con2fb_map[i] = idx;
2872 /* called with console_lock held */
2873 void fbcon_fb_unregistered(struct fb_info *info)
2877 WARN_CONSOLE_UNLOCKED();
2879 if (deferred_takeover)
2883 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2884 if (con2fb_map[i] == idx)
2888 if (idx == info_idx) {
2891 for_each_registered_fb(i) {
2897 if (info_idx != -1) {
2898 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2899 if (con2fb_map[i] == -1)
2900 con2fb_map[i] = info_idx;
2904 if (primary_device == idx)
2905 primary_device = -1;
2907 if (!num_registered_fb)
2908 do_unregister_con_driver(&fb_con);
2911 void fbcon_remap_all(struct fb_info *info)
2913 int i, idx = info->node;
2916 if (deferred_takeover) {
2917 for (i = first_fb_vc; i <= last_fb_vc; i++)
2918 con2fb_map_boot[i] = idx;
2919 fbcon_map_override();
2924 for (i = first_fb_vc; i <= last_fb_vc; i++)
2925 set_con2fb_map(i, idx, 0);
2927 if (con_is_bound(&fb_con)) {
2928 printk(KERN_INFO "fbcon: Remapping primary device, "
2929 "fb%i, to tty %i-%i\n", idx,
2930 first_fb_vc + 1, last_fb_vc + 1);
2936 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2937 static void fbcon_select_primary(struct fb_info *info)
2939 if (!map_override && primary_device == -1 &&
2940 fb_is_primary_device(info)) {
2943 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2944 info->fix.id, info->node);
2945 primary_device = info->node;
2947 for (i = first_fb_vc; i <= last_fb_vc; i++)
2948 con2fb_map_boot[i] = primary_device;
2950 if (con_is_bound(&fb_con)) {
2951 printk(KERN_INFO "fbcon: Remapping primary device, "
2952 "fb%i, to tty %i-%i\n", info->node,
2953 first_fb_vc + 1, last_fb_vc + 1);
2954 info_idx = primary_device;
2960 static inline void fbcon_select_primary(struct fb_info *info)
2964 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2966 /* called with console_lock held */
2967 int fbcon_fb_registered(struct fb_info *info)
2969 int ret = 0, i, idx;
2971 WARN_CONSOLE_UNLOCKED();
2974 fbcon_select_primary(info);
2976 if (deferred_takeover) {
2977 pr_info("fbcon: Deferring console take-over\n");
2981 if (info_idx == -1) {
2982 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2983 if (con2fb_map_boot[i] == idx) {
2990 ret = do_fbcon_takeover(1);
2992 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2993 if (con2fb_map_boot[i] == idx)
2994 set_con2fb_map(i, idx, 0);
3001 void fbcon_fb_blanked(struct fb_info *info, int blank)
3003 struct fbcon_ops *ops = info->fbcon_par;
3006 if (!ops || ops->currcon < 0)
3009 vc = vc_cons[ops->currcon].d;
3010 if (vc->vc_mode != KD_TEXT ||
3011 registered_fb[con2fb_map[ops->currcon]] != info)
3014 if (con_is_visible(vc)) {
3018 do_unblank_screen(0);
3020 ops->blank_state = blank;
3023 void fbcon_new_modelist(struct fb_info *info)
3027 struct fb_var_screeninfo var;
3028 const struct fb_videomode *mode;
3030 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3031 if (registered_fb[con2fb_map[i]] != info)
3033 if (!fb_display[i].mode)
3036 display_to_var(&var, &fb_display[i]);
3037 mode = fb_find_nearest_mode(fb_display[i].mode,
3039 fb_videomode_to_var(&var, mode);
3040 fbcon_set_disp(info, &var, vc->vc_num);
3044 void fbcon_get_requirement(struct fb_info *info,
3045 struct fb_blit_caps *caps)
3052 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3054 if (vc && vc->vc_mode == KD_TEXT &&
3055 info->node == con2fb_map[i]) {
3056 caps->x |= 1 << (vc->vc_font.width - 1);
3057 caps->y |= 1 << (vc->vc_font.height - 1);
3058 charcnt = vc->vc_font.charcount;
3059 if (caps->len < charcnt)
3060 caps->len = charcnt;
3064 vc = vc_cons[fg_console].d;
3066 if (vc && vc->vc_mode == KD_TEXT &&
3067 info->node == con2fb_map[fg_console]) {
3068 caps->x = 1 << (vc->vc_font.width - 1);
3069 caps->y = 1 << (vc->vc_font.height - 1);
3070 caps->len = vc->vc_font.charcount;
3075 int fbcon_set_con2fb_map_ioctl(void __user *argp)
3077 struct fb_con2fbmap con2fb;
3080 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3082 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3084 if (con2fb.framebuffer >= FB_MAX)
3086 if (!registered_fb[con2fb.framebuffer])
3087 request_module("fb%d", con2fb.framebuffer);
3088 if (!registered_fb[con2fb.framebuffer]) {
3093 ret = set_con2fb_map(con2fb.console - 1,
3094 con2fb.framebuffer, 1);
3100 int fbcon_get_con2fb_map_ioctl(void __user *argp)
3102 struct fb_con2fbmap con2fb;
3104 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
3106 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
3110 con2fb.framebuffer = con2fb_map[con2fb.console - 1];
3113 return copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
3117 * The console `switch' structure for the frame buffer based console
3120 static const struct consw fb_con = {
3121 .owner = THIS_MODULE,
3122 .con_startup = fbcon_startup,
3123 .con_init = fbcon_init,
3124 .con_deinit = fbcon_deinit,
3125 .con_clear = fbcon_clear,
3126 .con_putc = fbcon_putc,
3127 .con_putcs = fbcon_putcs,
3128 .con_cursor = fbcon_cursor,
3129 .con_scroll = fbcon_scroll,
3130 .con_switch = fbcon_switch,
3131 .con_blank = fbcon_blank,
3132 .con_font_set = fbcon_set_font,
3133 .con_font_get = fbcon_get_font,
3134 .con_font_default = fbcon_set_def_font,
3135 .con_set_palette = fbcon_set_palette,
3136 .con_invert_region = fbcon_invert_region,
3137 .con_screen_pos = fbcon_screen_pos,
3138 .con_getxy = fbcon_getxy,
3139 .con_resize = fbcon_resize,
3140 .con_debug_enter = fbcon_debug_enter,
3141 .con_debug_leave = fbcon_debug_leave,
3144 static ssize_t store_rotate(struct device *device,
3145 struct device_attribute *attr, const char *buf,
3148 struct fb_info *info;
3153 idx = con2fb_map[fg_console];
3155 if (idx == -1 || registered_fb[idx] == NULL)
3158 info = registered_fb[idx];
3159 rotate = simple_strtoul(buf, last, 0);
3160 fbcon_rotate(info, rotate);
3166 static ssize_t store_rotate_all(struct device *device,
3167 struct device_attribute *attr,const char *buf,
3170 struct fb_info *info;
3175 idx = con2fb_map[fg_console];
3177 if (idx == -1 || registered_fb[idx] == NULL)
3180 info = registered_fb[idx];
3181 rotate = simple_strtoul(buf, last, 0);
3182 fbcon_rotate_all(info, rotate);
3188 static ssize_t show_rotate(struct device *device,
3189 struct device_attribute *attr,char *buf)
3191 struct fb_info *info;
3192 int rotate = 0, idx;
3195 idx = con2fb_map[fg_console];
3197 if (idx == -1 || registered_fb[idx] == NULL)
3200 info = registered_fb[idx];
3201 rotate = fbcon_get_rotate(info);
3204 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3207 static ssize_t show_cursor_blink(struct device *device,
3208 struct device_attribute *attr, char *buf)
3210 struct fb_info *info;
3211 struct fbcon_ops *ops;
3212 int idx, blink = -1;
3215 idx = con2fb_map[fg_console];
3217 if (idx == -1 || registered_fb[idx] == NULL)
3220 info = registered_fb[idx];
3221 ops = info->fbcon_par;
3226 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3229 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3232 static ssize_t store_cursor_blink(struct device *device,
3233 struct device_attribute *attr,
3234 const char *buf, size_t count)
3236 struct fb_info *info;
3241 idx = con2fb_map[fg_console];
3243 if (idx == -1 || registered_fb[idx] == NULL)
3246 info = registered_fb[idx];
3248 if (!info->fbcon_par)
3251 blink = simple_strtoul(buf, last, 0);
3254 fbcon_cursor_noblink = 0;
3255 fbcon_add_cursor_timer(info);
3257 fbcon_cursor_noblink = 1;
3258 fbcon_del_cursor_timer(info);
3266 static struct device_attribute device_attrs[] = {
3267 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3268 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3269 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3270 store_cursor_blink),
3273 static int fbcon_init_device(void)
3277 fbcon_has_sysfs = 1;
3279 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3280 error = device_create_file(fbcon_device, &device_attrs[i]);
3288 device_remove_file(fbcon_device, &device_attrs[i]);
3290 fbcon_has_sysfs = 0;
3296 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3297 static void fbcon_register_existing_fbs(struct work_struct *work)
3303 deferred_takeover = false;
3304 logo_shown = FBCON_LOGO_DONTSHOW;
3306 for_each_registered_fb(i)
3307 fbcon_fb_registered(registered_fb[i]);
3312 static struct notifier_block fbcon_output_nb;
3313 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3315 static int fbcon_output_notifier(struct notifier_block *nb,
3316 unsigned long action, void *data)
3318 WARN_CONSOLE_UNLOCKED();
3320 pr_info("fbcon: Taking over console\n");
3322 dummycon_unregister_output_notifier(&fbcon_output_nb);
3324 /* We may get called in atomic context */
3325 schedule_work(&fbcon_deferred_takeover_work);
3331 static void fbcon_start(void)
3333 WARN_CONSOLE_UNLOCKED();
3335 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3336 if (conswitchp != &dummy_con)
3337 deferred_takeover = false;
3339 if (deferred_takeover) {
3340 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3341 dummycon_register_output_notifier(&fbcon_output_nb);
3346 if (num_registered_fb) {
3349 for_each_registered_fb(i) {
3354 do_fbcon_takeover(0);
3358 static void fbcon_exit(void)
3360 struct fb_info *info;
3363 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3364 if (deferred_takeover) {
3365 dummycon_unregister_output_notifier(&fbcon_output_nb);
3366 deferred_takeover = false;
3370 for_each_registered_fb(i) {
3374 info = registered_fb[i];
3376 if (info->queue.func)
3377 pending = cancel_work_sync(&info->queue);
3378 pr_debug("fbcon: %s pending work\n", (pending ? "canceled" : "no"));
3380 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3381 if (con2fb_map[j] == i) {
3388 if (info->fbops->fb_release)
3389 info->fbops->fb_release(info, 0);
3390 module_put(info->fbops->owner);
3392 if (info->fbcon_par) {
3393 struct fbcon_ops *ops = info->fbcon_par;
3395 fbcon_del_cursor_timer(info);
3396 kfree(ops->cursor_src);
3397 kfree(ops->cursor_state.mask);
3398 kfree(info->fbcon_par);
3399 info->fbcon_par = NULL;
3402 if (info->queue.func == fb_flashcursor)
3403 info->queue.func = NULL;
3408 void __init fb_console_init(void)
3413 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3416 if (IS_ERR(fbcon_device)) {
3417 printk(KERN_WARNING "Unable to create device "
3418 "for fbcon; errno = %ld\n",
3419 PTR_ERR(fbcon_device));
3420 fbcon_device = NULL;
3422 fbcon_init_device();
3424 for (i = 0; i < MAX_NR_CONSOLES; i++)
3433 static void __exit fbcon_deinit_device(void)
3437 if (fbcon_has_sysfs) {
3438 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3439 device_remove_file(fbcon_device, &device_attrs[i]);
3441 fbcon_has_sysfs = 0;
3445 void __exit fb_console_exit(void)
3448 fbcon_deinit_device();
3449 device_destroy(fb_class, MKDEV(0, 0));
3451 do_unregister_con_driver(&fb_con);