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/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
84 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
86 # define DPRINTK(fmt, args...)
90 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
91 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
92 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
95 static struct display fb_display[MAX_NR_CONSOLES];
97 static signed char con2fb_map[MAX_NR_CONSOLES];
98 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
100 static int logo_lines;
101 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
103 static int logo_shown = FBCON_LOGO_CANSHOW;
104 /* console mappings */
105 static int first_fb_vc;
106 static int last_fb_vc = MAX_NR_CONSOLES - 1;
107 static int fbcon_is_default = 1;
108 static int fbcon_has_exited;
109 static int primary_device = -1;
110 static int fbcon_has_console_bind;
112 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
113 static int map_override;
115 static inline void fbcon_map_override(void)
120 static inline void fbcon_map_override(void)
123 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
126 static char fontname[40];
128 /* current fb_info */
129 static int info_idx = -1;
131 /* console rotation */
132 static int initial_rotation;
133 static int fbcon_has_sysfs;
135 static const struct consw fb_con;
137 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
139 static int fbcon_set_origin(struct vc_data *);
141 static int fbcon_cursor_noblink;
143 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
146 * Interface used by the world
149 static const char *fbcon_startup(void);
150 static void fbcon_init(struct vc_data *vc, int init);
151 static void fbcon_deinit(struct vc_data *vc);
152 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
154 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
155 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
156 int count, int ypos, int xpos);
157 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
158 static void fbcon_cursor(struct vc_data *vc, int mode);
159 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
161 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
162 int height, int width);
163 static int fbcon_switch(struct vc_data *vc);
164 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
165 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
170 static __inline__ void ywrap_up(struct vc_data *vc, int count);
171 static __inline__ void ywrap_down(struct vc_data *vc, int count);
172 static __inline__ void ypan_up(struct vc_data *vc, int count);
173 static __inline__ void ypan_down(struct vc_data *vc, int count);
174 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
175 int dy, int dx, int height, int width, u_int y_break);
176 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
178 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
179 int line, int count, int dy);
180 static void fbcon_modechanged(struct fb_info *info);
181 static void fbcon_set_all_vcs(struct fb_info *info);
182 static void fbcon_start(void);
183 static void fbcon_exit(void);
184 static struct device *fbcon_device;
186 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
187 static inline void fbcon_set_rotation(struct fb_info *info)
189 struct fbcon_ops *ops = info->fbcon_par;
191 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
192 ops->p->con_rotate < 4)
193 ops->rotate = ops->p->con_rotate;
198 static void fbcon_rotate(struct fb_info *info, u32 rotate)
200 struct fbcon_ops *ops= info->fbcon_par;
201 struct fb_info *fb_info;
203 if (!ops || ops->currcon == -1)
206 fb_info = registered_fb[con2fb_map[ops->currcon]];
208 if (info == fb_info) {
209 struct display *p = &fb_display[ops->currcon];
212 p->con_rotate = rotate;
216 fbcon_modechanged(info);
220 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
222 struct fbcon_ops *ops = info->fbcon_par;
227 if (!ops || ops->currcon < 0 || rotate > 3)
230 for (i = first_fb_vc; i <= last_fb_vc; i++) {
232 if (!vc || vc->vc_mode != KD_TEXT ||
233 registered_fb[con2fb_map[i]] != info)
236 p = &fb_display[vc->vc_num];
237 p->con_rotate = rotate;
240 fbcon_set_all_vcs(info);
243 static inline void fbcon_set_rotation(struct fb_info *info)
245 struct fbcon_ops *ops = info->fbcon_par;
247 ops->rotate = FB_ROTATE_UR;
250 static void fbcon_rotate(struct fb_info *info, u32 rotate)
255 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
259 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
261 static int fbcon_get_rotate(struct fb_info *info)
263 struct fbcon_ops *ops = info->fbcon_par;
265 return (ops) ? ops->rotate : 0;
268 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
270 struct fbcon_ops *ops = info->fbcon_par;
272 return (info->state != FBINFO_STATE_RUNNING ||
273 vc->vc_mode != KD_TEXT || ops->graphics) &&
274 !vt_force_oops_output(vc);
277 static int get_color(struct vc_data *vc, struct fb_info *info,
280 int depth = fb_get_color_depth(&info->var, &info->fix);
283 if (console_blanked) {
284 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
286 c = vc->vc_video_erase_char & charmask;
290 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
291 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
296 int col = mono_col(info);
298 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
299 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
304 color = (is_fg) ? fg : bg;
309 * Scale down 16-colors to 4 colors. Default 4-color palette
310 * is grayscale. However, simply dividing the values by 4
311 * will not work, as colors 1, 2 and 3 will be scaled-down
312 * to zero rendering them invisible. So empirically convert
313 * colors to a sane 4-level grayscale.
317 color = 0; /* black */
320 color = 2; /* white */
323 color = 1; /* gray */
326 color = 3; /* intense white */
332 * Last 8 entries of default 16-color palette is a more intense
333 * version of the first 8 (i.e., same chrominance, different
344 static void fb_flashcursor(struct work_struct *work)
346 struct fb_info *info = container_of(work, struct fb_info, queue);
347 struct fbcon_ops *ops = info->fbcon_par;
348 struct vc_data *vc = NULL;
353 /* FIXME: we should sort out the unbind locking instead */
354 /* instead we just fail to flash the cursor if we can't get
355 * the lock instead of blocking fbcon deinit */
356 ret = console_trylock();
360 if (ops && ops->currcon != -1)
361 vc = vc_cons[ops->currcon].d;
363 if (!vc || !con_is_visible(vc) ||
364 registered_fb[con2fb_map[vc->vc_num]] != info ||
370 c = scr_readw((u16 *) vc->vc_pos);
371 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
373 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
374 get_color(vc, info, c, 0));
378 static void cursor_timer_handler(unsigned long dev_addr)
380 struct fb_info *info = (struct fb_info *) dev_addr;
381 struct fbcon_ops *ops = info->fbcon_par;
383 queue_work(system_power_efficient_wq, &info->queue);
384 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
387 static void fbcon_add_cursor_timer(struct fb_info *info)
389 struct fbcon_ops *ops = info->fbcon_par;
391 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
392 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
393 !fbcon_cursor_noblink) {
394 if (!info->queue.func)
395 INIT_WORK(&info->queue, fb_flashcursor);
397 init_timer(&ops->cursor_timer);
398 ops->cursor_timer.function = cursor_timer_handler;
399 ops->cursor_timer.expires = jiffies + ops->cur_blink_jiffies;
400 ops->cursor_timer.data = (unsigned long ) info;
401 add_timer(&ops->cursor_timer);
402 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
406 static void fbcon_del_cursor_timer(struct fb_info *info)
408 struct fbcon_ops *ops = info->fbcon_par;
410 if (info->queue.func == fb_flashcursor &&
411 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
412 del_timer_sync(&ops->cursor_timer);
413 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
418 static int __init fb_console_setup(char *this_opt)
423 if (!this_opt || !*this_opt)
426 while ((options = strsep(&this_opt, ",")) != NULL) {
427 if (!strncmp(options, "font:", 5)) {
428 strlcpy(fontname, options + 5, sizeof(fontname));
432 if (!strncmp(options, "scrollback:", 11)) {
433 pr_warn("Ignoring scrollback size option\n");
437 if (!strncmp(options, "map:", 4)) {
440 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
444 (options[j++]-'0') % FB_MAX;
447 fbcon_map_override();
452 if (!strncmp(options, "vc:", 3)) {
455 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
458 if (*options++ == '-')
459 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
460 fbcon_is_default = 0;
464 if (!strncmp(options, "rotate:", 7)) {
467 initial_rotation = simple_strtoul(options, &options, 0);
468 if (initial_rotation > 3)
469 initial_rotation = 0;
476 __setup("fbcon=", fb_console_setup);
479 static int search_fb_in_map(int idx)
483 for (i = first_fb_vc; i <= last_fb_vc; i++) {
484 if (con2fb_map[i] == idx)
490 static int search_for_mapped_con(void)
494 for (i = first_fb_vc; i <= last_fb_vc; i++) {
495 if (con2fb_map[i] != -1)
501 static int do_fbcon_takeover(int show_logo)
505 if (!num_registered_fb)
509 logo_shown = FBCON_LOGO_DONTSHOW;
511 for (i = first_fb_vc; i <= last_fb_vc; i++)
512 con2fb_map[i] = info_idx;
514 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
518 for (i = first_fb_vc; i <= last_fb_vc; i++)
522 fbcon_has_console_bind = 1;
529 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
530 int cols, int rows, int new_cols, int new_rows)
532 logo_shown = FBCON_LOGO_DONTSHOW;
535 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
536 int cols, int rows, int new_cols, int new_rows)
538 /* Need to make room for the logo */
539 struct fbcon_ops *ops = info->fbcon_par;
540 int cnt, erase = vc->vc_video_erase_char, step;
541 unsigned short *save = NULL, *r, *q;
544 if (info->flags & FBINFO_MODULE) {
545 logo_shown = FBCON_LOGO_DONTSHOW;
550 * remove underline attribute from erase character
551 * if black and white framebuffer.
553 if (fb_get_color_depth(&info->var, &info->fix) == 1)
555 logo_height = fb_prepare_logo(info, ops->rotate);
556 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
557 q = (unsigned short *) (vc->vc_origin +
558 vc->vc_size_row * rows);
559 step = logo_lines * cols;
560 for (r = q - logo_lines * cols; r < q; r++)
561 if (scr_readw(r) != vc->vc_video_erase_char)
563 if (r != q && new_rows >= rows + logo_lines) {
564 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
566 int i = cols < new_cols ? cols : new_cols;
567 scr_memsetw(save, erase, logo_lines * new_cols * 2);
569 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
570 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
575 /* We can scroll screen down */
577 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
578 scr_memcpyw(r + step, r, vc->vc_size_row);
583 if (vc->vc_y + logo_lines >= rows)
584 lines = rows - vc->vc_y - 1;
588 vc->vc_pos += lines * vc->vc_size_row;
591 scr_memsetw((unsigned short *) vc->vc_origin,
593 vc->vc_size_row * logo_lines);
595 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
596 fbcon_clear_margins(vc, 0);
601 q = (unsigned short *) (vc->vc_origin +
604 scr_memcpyw(q, save, logo_lines * new_cols * 2);
605 vc->vc_y += logo_lines;
606 vc->vc_pos += logo_lines * vc->vc_size_row;
610 if (logo_lines > vc->vc_bottom) {
611 logo_shown = FBCON_LOGO_CANSHOW;
613 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
614 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
615 logo_shown = FBCON_LOGO_DRAW;
616 vc->vc_top = logo_lines;
621 #ifdef CONFIG_FB_TILEBLITTING
622 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
624 struct fbcon_ops *ops = info->fbcon_par;
626 ops->p = &fb_display[vc->vc_num];
628 if ((info->flags & FBINFO_MISC_TILEBLITTING))
629 fbcon_set_tileops(vc, info);
631 fbcon_set_rotation(info);
632 fbcon_set_bitops(ops);
636 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
640 if (info->flags & FBINFO_MISC_TILEBLITTING &&
641 info->tileops->fb_get_tilemax(info) < charcount)
647 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
649 struct fbcon_ops *ops = info->fbcon_par;
651 info->flags &= ~FBINFO_MISC_TILEBLITTING;
652 ops->p = &fb_display[vc->vc_num];
653 fbcon_set_rotation(info);
654 fbcon_set_bitops(ops);
657 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
662 #endif /* CONFIG_MISC_TILEBLITTING */
665 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
666 int unit, int oldidx)
668 struct fbcon_ops *ops = NULL;
671 if (!try_module_get(info->fbops->owner))
674 if (!err && info->fbops->fb_open &&
675 info->fbops->fb_open(info, 0))
679 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
685 ops->cur_blink_jiffies = HZ / 5;
686 info->fbcon_par = ops;
689 set_blitting_type(vc, info);
693 con2fb_map[unit] = oldidx;
694 module_put(info->fbops->owner);
700 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
701 struct fb_info *newinfo, int unit,
702 int oldidx, int found)
704 struct fbcon_ops *ops = oldinfo->fbcon_par;
707 if (oldinfo->fbops->fb_release &&
708 oldinfo->fbops->fb_release(oldinfo, 0)) {
709 con2fb_map[unit] = oldidx;
710 if (!found && newinfo->fbops->fb_release)
711 newinfo->fbops->fb_release(newinfo, 0);
713 module_put(newinfo->fbops->owner);
718 fbcon_del_cursor_timer(oldinfo);
719 kfree(ops->cursor_state.mask);
720 kfree(ops->cursor_data);
721 kfree(ops->cursor_src);
722 kfree(ops->fontbuffer);
723 kfree(oldinfo->fbcon_par);
724 oldinfo->fbcon_par = NULL;
725 module_put(oldinfo->fbops->owner);
727 If oldinfo and newinfo are driving the same hardware,
728 the fb_release() method of oldinfo may attempt to
729 restore the hardware state. This will leave the
730 newinfo in an undefined state. Thus, a call to
731 fb_set_par() may be needed for the newinfo.
733 if (newinfo && newinfo->fbops->fb_set_par) {
734 ret = newinfo->fbops->fb_set_par(newinfo);
737 printk(KERN_ERR "con2fb_release_oldinfo: "
738 "detected unhandled fb_set_par error, "
739 "error code %d\n", ret);
746 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
747 int unit, int show_logo)
749 struct fbcon_ops *ops = info->fbcon_par;
752 ops->currcon = fg_console;
754 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
755 ret = info->fbops->fb_set_par(info);
758 printk(KERN_ERR "con2fb_init_display: detected "
759 "unhandled fb_set_par error, "
760 "error code %d\n", ret);
763 ops->flags |= FBCON_FLAGS_INIT;
765 fbcon_set_disp(info, &info->var, unit);
768 struct vc_data *fg_vc = vc_cons[fg_console].d;
769 struct fb_info *fg_info =
770 registered_fb[con2fb_map[fg_console]];
772 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
773 fg_vc->vc_rows, fg_vc->vc_cols,
777 update_screen(vc_cons[fg_console].d);
781 * set_con2fb_map - map console to frame buffer device
782 * @unit: virtual console number to map
783 * @newidx: frame buffer index to map virtual console to
784 * @user: user request
786 * Maps a virtual console @unit to a frame buffer device
789 * This should be called with the console lock held.
791 static int set_con2fb_map(int unit, int newidx, int user)
793 struct vc_data *vc = vc_cons[unit].d;
794 int oldidx = con2fb_map[unit];
795 struct fb_info *info = registered_fb[newidx];
796 struct fb_info *oldinfo = NULL;
799 if (oldidx == newidx)
805 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
807 return do_fbcon_takeover(0);
811 oldinfo = registered_fb[oldidx];
813 found = search_fb_in_map(newidx);
815 con2fb_map[unit] = newidx;
817 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
821 * If old fb is not mapped to any of the consoles,
822 * fbcon should release it.
824 if (!err && oldinfo && !search_fb_in_map(oldidx))
825 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
829 int show_logo = (fg_console == 0 && !user &&
830 logo_shown != FBCON_LOGO_DONTSHOW);
833 fbcon_add_cursor_timer(info);
834 con2fb_map_boot[unit] = newidx;
835 con2fb_init_display(vc, info, unit, show_logo);
838 if (!search_fb_in_map(info_idx))
845 * Low Level Operations
847 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
848 static int var_to_display(struct display *disp,
849 struct fb_var_screeninfo *var,
850 struct fb_info *info)
852 disp->xres_virtual = var->xres_virtual;
853 disp->yres_virtual = var->yres_virtual;
854 disp->bits_per_pixel = var->bits_per_pixel;
855 disp->grayscale = var->grayscale;
856 disp->nonstd = var->nonstd;
857 disp->accel_flags = var->accel_flags;
858 disp->height = var->height;
859 disp->width = var->width;
860 disp->red = var->red;
861 disp->green = var->green;
862 disp->blue = var->blue;
863 disp->transp = var->transp;
864 disp->rotate = var->rotate;
865 disp->mode = fb_match_mode(var, &info->modelist);
866 if (disp->mode == NULL)
867 /* This should not happen */
872 static void display_to_var(struct fb_var_screeninfo *var,
873 struct display *disp)
875 fb_videomode_to_var(var, disp->mode);
876 var->xres_virtual = disp->xres_virtual;
877 var->yres_virtual = disp->yres_virtual;
878 var->bits_per_pixel = disp->bits_per_pixel;
879 var->grayscale = disp->grayscale;
880 var->nonstd = disp->nonstd;
881 var->accel_flags = disp->accel_flags;
882 var->height = disp->height;
883 var->width = disp->width;
884 var->red = disp->red;
885 var->green = disp->green;
886 var->blue = disp->blue;
887 var->transp = disp->transp;
888 var->rotate = disp->rotate;
891 static const char *fbcon_startup(void)
893 const char *display_desc = "frame buffer device";
894 struct display *p = &fb_display[fg_console];
895 struct vc_data *vc = vc_cons[fg_console].d;
896 const struct font_desc *font = NULL;
897 struct module *owner;
898 struct fb_info *info = NULL;
899 struct fbcon_ops *ops;
903 * If num_registered_fb is zero, this is a call for the dummy part.
904 * The frame buffer devices weren't initialized yet.
906 if (!num_registered_fb || info_idx == -1)
909 * Instead of blindly using registered_fb[0], we use info_idx, set by
912 info = registered_fb[info_idx];
916 owner = info->fbops->owner;
917 if (!try_module_get(owner))
919 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
924 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
932 ops->cur_rotate = -1;
933 ops->cur_blink_jiffies = HZ / 5;
934 info->fbcon_par = ops;
935 p->con_rotate = initial_rotation;
936 set_blitting_type(vc, info);
938 /* Setup default font */
939 if (!p->fontdata && !vc->vc_font.data) {
940 if (!fontname[0] || !(font = find_font(fontname)))
941 font = get_default_font(info->var.xres,
944 info->pixmap.blit_y);
945 vc->vc_font.width = font->width;
946 vc->vc_font.height = font->height;
947 vc->vc_font.data = (void *)(p->fontdata = font->data);
948 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
950 p->fontdata = vc->vc_font.data;
953 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
954 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
955 cols /= vc->vc_font.width;
956 rows /= vc->vc_font.height;
957 vc_resize(vc, cols, rows);
959 DPRINTK("mode: %s\n", info->fix.id);
960 DPRINTK("visual: %d\n", info->fix.visual);
961 DPRINTK("res: %dx%d-%d\n", info->var.xres,
963 info->var.bits_per_pixel);
965 fbcon_add_cursor_timer(info);
966 fbcon_has_exited = 0;
970 static void fbcon_init(struct vc_data *vc, int init)
972 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
973 struct fbcon_ops *ops;
974 struct vc_data **default_mode = vc->vc_display_fg;
975 struct vc_data *svc = *default_mode;
976 struct display *t, *p = &fb_display[vc->vc_num];
977 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
980 if (info_idx == -1 || info == NULL)
985 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
986 (info->fix.type == FB_TYPE_TEXT))
989 if (var_to_display(p, &info->var, info))
992 if (!info->fbcon_par)
993 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
995 /* If we are not the first console on this
996 fb, copy the font from that console */
997 t = &fb_display[fg_console];
1000 struct vc_data *fvc = vc_cons[fg_console].d;
1002 vc->vc_font.data = (void *)(p->fontdata =
1004 vc->vc_font.width = fvc->vc_font.width;
1005 vc->vc_font.height = fvc->vc_font.height;
1006 p->userfont = t->userfont;
1009 REFCOUNT(p->fontdata)++;
1011 const struct font_desc *font = NULL;
1013 if (!fontname[0] || !(font = find_font(fontname)))
1014 font = get_default_font(info->var.xres,
1016 info->pixmap.blit_x,
1017 info->pixmap.blit_y);
1018 vc->vc_font.width = font->width;
1019 vc->vc_font.height = font->height;
1020 vc->vc_font.data = (void *)(p->fontdata = font->data);
1021 vc->vc_font.charcount = 256; /* FIXME Need to
1022 support more fonts */
1027 charcnt = FNTCHARCNT(p->fontdata);
1029 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1030 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1031 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1032 if (charcnt == 256) {
1033 vc->vc_hi_font_mask = 0;
1035 vc->vc_hi_font_mask = 0x100;
1036 if (vc->vc_can_do_color)
1037 vc->vc_complement_mask <<= 1;
1040 if (!*svc->vc_uni_pagedir_loc)
1041 con_set_default_unimap(svc);
1042 if (!*vc->vc_uni_pagedir_loc)
1043 con_copy_unimap(vc, svc);
1045 ops = info->fbcon_par;
1046 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1047 p->con_rotate = initial_rotation;
1048 set_blitting_type(vc, info);
1052 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1053 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1054 new_cols /= vc->vc_font.width;
1055 new_rows /= vc->vc_font.height;
1058 * We must always set the mode. The mode of the previous console
1059 * driver could be in the same resolution but we are using different
1060 * hardware so we have to initialize the hardware.
1062 * We need to do it in fbcon_init() to prevent screen corruption.
1064 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1065 if (info->fbops->fb_set_par &&
1066 !(ops->flags & FBCON_FLAGS_INIT)) {
1067 ret = info->fbops->fb_set_par(info);
1070 printk(KERN_ERR "fbcon_init: detected "
1071 "unhandled fb_set_par error, "
1072 "error code %d\n", ret);
1075 ops->flags |= FBCON_FLAGS_INIT;
1080 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1081 !(cap & FBINFO_HWACCEL_DISABLED))
1082 p->scrollmode = SCROLL_MOVE;
1083 else /* default to something safe */
1084 p->scrollmode = SCROLL_REDRAW;
1087 * ++guenther: console.c:vc_allocate() relies on initializing
1088 * vc_{cols,rows}, but we must not set those if we are only
1089 * resizing the console.
1092 vc->vc_cols = new_cols;
1093 vc->vc_rows = new_rows;
1095 vc_resize(vc, new_cols, new_rows);
1098 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1100 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1101 ops->rotate = FB_ROTATE_UR;
1102 set_blitting_type(vc, info);
1105 ops->p = &fb_display[fg_console];
1108 static void fbcon_free_font(struct display *p, bool freefont)
1110 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1111 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1116 static void set_vc_hi_font(struct vc_data *vc, bool set);
1118 static void fbcon_deinit(struct vc_data *vc)
1120 struct display *p = &fb_display[vc->vc_num];
1121 struct fb_info *info;
1122 struct fbcon_ops *ops;
1124 bool free_font = true;
1126 idx = con2fb_map[vc->vc_num];
1131 info = registered_fb[idx];
1136 if (info->flags & FBINFO_MISC_FIRMWARE)
1138 ops = info->fbcon_par;
1143 if (con_is_visible(vc))
1144 fbcon_del_cursor_timer(info);
1146 ops->flags &= ~FBCON_FLAGS_INIT;
1149 fbcon_free_font(p, free_font);
1151 vc->vc_font.data = NULL;
1153 if (vc->vc_hi_font_mask)
1154 set_vc_hi_font(vc, false);
1156 if (!con_is_bound(&fb_con))
1162 /* ====================================================================== */
1164 /* fbcon_XXX routines - interface used by the world
1166 * This system is now divided into two levels because of complications
1167 * caused by hardware scrolling. Top level functions:
1169 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1171 * handles y values in range [0, scr_height-1] that correspond to real
1172 * screen positions. y_wrap shift means that first line of bitmap may be
1173 * anywhere on this display. These functions convert lineoffsets to
1174 * bitmap offsets and deal with the wrap-around case by splitting blits.
1176 * fbcon_bmove_physical_8() -- These functions fast implementations
1177 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1178 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1182 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1183 * Implies should only really hardware scroll in rows. Only reason for
1184 * restriction is simplicity & efficiency at the moment.
1187 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1190 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1191 struct fbcon_ops *ops = info->fbcon_par;
1193 struct display *p = &fb_display[vc->vc_num];
1196 if (fbcon_is_inactive(vc, info))
1199 if (!height || !width)
1202 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1205 * If the font dimensions are not an integral of the display
1206 * dimensions then the ops->clear below won't end up clearing
1207 * the margins. Call clear_margins here in case the logo
1208 * bitmap stretched into the margin area.
1210 fbcon_clear_margins(vc, 0);
1213 /* Split blits that cross physical y_wrap boundary */
1215 y_break = p->vrows - p->yscroll;
1216 if (sy < y_break && sy + height - 1 >= y_break) {
1217 u_int b = y_break - sy;
1218 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1219 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1222 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1225 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1226 int count, int ypos, int xpos)
1228 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1229 struct display *p = &fb_display[vc->vc_num];
1230 struct fbcon_ops *ops = info->fbcon_par;
1232 if (!fbcon_is_inactive(vc, info))
1233 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1234 get_color(vc, info, scr_readw(s), 1),
1235 get_color(vc, info, scr_readw(s), 0));
1238 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1242 scr_writew(c, &chr);
1243 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1246 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1248 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1249 struct fbcon_ops *ops = info->fbcon_par;
1251 if (!fbcon_is_inactive(vc, info))
1252 ops->clear_margins(vc, info, bottom_only);
1255 static void fbcon_cursor(struct vc_data *vc, int mode)
1257 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1258 struct fbcon_ops *ops = info->fbcon_par;
1259 int c = scr_readw((u16 *) vc->vc_pos);
1261 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1263 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1266 if (vc->vc_cursor_type & 0x10)
1267 fbcon_del_cursor_timer(info);
1269 fbcon_add_cursor_timer(info);
1271 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1273 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1274 get_color(vc, info, c, 0));
1277 static int scrollback_phys_max = 0;
1278 static int scrollback_max = 0;
1279 static int scrollback_current = 0;
1281 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1284 struct display *p, *t;
1285 struct vc_data **default_mode, *vc;
1286 struct vc_data *svc;
1287 struct fbcon_ops *ops = info->fbcon_par;
1288 int rows, cols, charcnt = 256;
1290 p = &fb_display[unit];
1292 if (var_to_display(p, var, info))
1295 vc = vc_cons[unit].d;
1300 default_mode = vc->vc_display_fg;
1301 svc = *default_mode;
1302 t = &fb_display[svc->vc_num];
1304 if (!vc->vc_font.data) {
1305 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1306 vc->vc_font.width = (*default_mode)->vc_font.width;
1307 vc->vc_font.height = (*default_mode)->vc_font.height;
1308 p->userfont = t->userfont;
1310 REFCOUNT(p->fontdata)++;
1313 charcnt = FNTCHARCNT(p->fontdata);
1315 var->activate = FB_ACTIVATE_NOW;
1316 info->var.activate = var->activate;
1317 var->yoffset = info->var.yoffset;
1318 var->xoffset = info->var.xoffset;
1319 fb_set_var(info, var);
1320 ops->var = info->var;
1321 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1322 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1323 if (charcnt == 256) {
1324 vc->vc_hi_font_mask = 0;
1326 vc->vc_hi_font_mask = 0x100;
1327 if (vc->vc_can_do_color)
1328 vc->vc_complement_mask <<= 1;
1331 if (!*svc->vc_uni_pagedir_loc)
1332 con_set_default_unimap(svc);
1333 if (!*vc->vc_uni_pagedir_loc)
1334 con_copy_unimap(vc, svc);
1336 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1337 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1338 cols /= vc->vc_font.width;
1339 rows /= vc->vc_font.height;
1340 vc_resize(vc, cols, rows);
1342 if (con_is_visible(vc)) {
1347 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1349 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1350 struct fbcon_ops *ops = info->fbcon_par;
1351 struct display *p = &fb_display[vc->vc_num];
1353 p->yscroll += count;
1354 if (p->yscroll >= p->vrows) /* Deal with wrap */
1355 p->yscroll -= p->vrows;
1356 ops->var.xoffset = 0;
1357 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1358 ops->var.vmode |= FB_VMODE_YWRAP;
1359 ops->update_start(info);
1360 scrollback_max += count;
1361 if (scrollback_max > scrollback_phys_max)
1362 scrollback_max = scrollback_phys_max;
1363 scrollback_current = 0;
1366 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1368 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1369 struct fbcon_ops *ops = info->fbcon_par;
1370 struct display *p = &fb_display[vc->vc_num];
1372 p->yscroll -= count;
1373 if (p->yscroll < 0) /* Deal with wrap */
1374 p->yscroll += p->vrows;
1375 ops->var.xoffset = 0;
1376 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1377 ops->var.vmode |= FB_VMODE_YWRAP;
1378 ops->update_start(info);
1379 scrollback_max -= count;
1380 if (scrollback_max < 0)
1382 scrollback_current = 0;
1385 static __inline__ void ypan_up(struct vc_data *vc, int count)
1387 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1388 struct display *p = &fb_display[vc->vc_num];
1389 struct fbcon_ops *ops = info->fbcon_par;
1391 p->yscroll += count;
1392 if (p->yscroll > p->vrows - vc->vc_rows) {
1393 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1394 0, 0, 0, vc->vc_rows, vc->vc_cols);
1395 p->yscroll -= p->vrows - vc->vc_rows;
1398 ops->var.xoffset = 0;
1399 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1400 ops->var.vmode &= ~FB_VMODE_YWRAP;
1401 ops->update_start(info);
1402 fbcon_clear_margins(vc, 1);
1403 scrollback_max += count;
1404 if (scrollback_max > scrollback_phys_max)
1405 scrollback_max = scrollback_phys_max;
1406 scrollback_current = 0;
1409 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1411 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1412 struct fbcon_ops *ops = info->fbcon_par;
1413 struct display *p = &fb_display[vc->vc_num];
1415 p->yscroll += count;
1417 if (p->yscroll > p->vrows - vc->vc_rows) {
1418 p->yscroll -= p->vrows - vc->vc_rows;
1419 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1422 ops->var.xoffset = 0;
1423 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1424 ops->var.vmode &= ~FB_VMODE_YWRAP;
1425 ops->update_start(info);
1426 fbcon_clear_margins(vc, 1);
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 ypan_down(struct vc_data *vc, int count)
1435 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1436 struct display *p = &fb_display[vc->vc_num];
1437 struct fbcon_ops *ops = info->fbcon_par;
1439 p->yscroll -= count;
1440 if (p->yscroll < 0) {
1441 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1442 0, vc->vc_rows, vc->vc_cols);
1443 p->yscroll += p->vrows - vc->vc_rows;
1446 ops->var.xoffset = 0;
1447 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1448 ops->var.vmode &= ~FB_VMODE_YWRAP;
1449 ops->update_start(info);
1450 fbcon_clear_margins(vc, 1);
1451 scrollback_max -= count;
1452 if (scrollback_max < 0)
1454 scrollback_current = 0;
1457 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1459 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1460 struct fbcon_ops *ops = info->fbcon_par;
1461 struct display *p = &fb_display[vc->vc_num];
1463 p->yscroll -= count;
1465 if (p->yscroll < 0) {
1466 p->yscroll += p->vrows - vc->vc_rows;
1467 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1470 ops->var.xoffset = 0;
1471 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1472 ops->var.vmode &= ~FB_VMODE_YWRAP;
1473 ops->update_start(info);
1474 fbcon_clear_margins(vc, 1);
1475 scrollback_max -= count;
1476 if (scrollback_max < 0)
1478 scrollback_current = 0;
1481 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1482 int line, int count, int dy)
1484 unsigned short *s = (unsigned short *)
1485 (vc->vc_origin + vc->vc_size_row * line);
1488 unsigned short *start = s;
1489 unsigned short *le = advance_row(s, 1);
1492 unsigned short attr = 1;
1496 if (attr != (c & 0xff00)) {
1499 fbcon_putcs(vc, start, s - start,
1505 console_conditional_schedule();
1509 fbcon_putcs(vc, start, s - start, dy, x);
1510 console_conditional_schedule();
1515 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1516 struct display *p, int line, int count, int ycount)
1518 int offset = ycount * vc->vc_cols;
1519 unsigned short *d = (unsigned short *)
1520 (vc->vc_origin + vc->vc_size_row * line);
1521 unsigned short *s = d + offset;
1522 struct fbcon_ops *ops = info->fbcon_par;
1525 unsigned short *start = s;
1526 unsigned short *le = advance_row(s, 1);
1533 if (c == scr_readw(d)) {
1535 ops->bmove(vc, info, line + ycount, x,
1536 line, x, 1, s-start);
1546 console_conditional_schedule();
1551 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1553 console_conditional_schedule();
1558 /* NOTE: We subtract two lines from these pointers */
1559 s -= vc->vc_size_row;
1560 d -= vc->vc_size_row;
1565 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1566 int line, int count, int offset)
1568 unsigned short *d = (unsigned short *)
1569 (vc->vc_origin + vc->vc_size_row * line);
1570 unsigned short *s = d + offset;
1573 unsigned short *start = s;
1574 unsigned short *le = advance_row(s, 1);
1577 unsigned short attr = 1;
1581 if (attr != (c & 0xff00)) {
1584 fbcon_putcs(vc, start, s - start,
1590 if (c == scr_readw(d)) {
1592 fbcon_putcs(vc, start, s - start,
1602 console_conditional_schedule();
1607 fbcon_putcs(vc, start, s - start, line, x);
1608 console_conditional_schedule();
1613 /* NOTE: We subtract two lines from these pointers */
1614 s -= vc->vc_size_row;
1615 d -= vc->vc_size_row;
1620 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1623 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1624 struct display *p = &fb_display[vc->vc_num];
1625 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1627 if (fbcon_is_inactive(vc, info))
1630 fbcon_cursor(vc, CM_ERASE);
1633 * ++Geert: Only use ywrap/ypan if the console is in text mode
1634 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1635 * whole screen (prevents flicker).
1640 if (count > vc->vc_rows) /* Maximum realistic size */
1641 count = vc->vc_rows;
1642 if (logo_shown >= 0)
1644 switch (p->scrollmode) {
1646 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1648 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1649 scr_memsetw((unsigned short *) (vc->vc_origin +
1652 vc->vc_video_erase_char,
1653 vc->vc_size_row * count);
1657 case SCROLL_WRAP_MOVE:
1658 if (b - t - count > 3 * vc->vc_rows >> 2) {
1660 fbcon_bmove(vc, 0, 0, count, 0, t,
1662 ywrap_up(vc, count);
1663 if (vc->vc_rows - b > 0)
1664 fbcon_bmove(vc, b - count, 0, b, 0,
1667 } else if (info->flags & FBINFO_READS_FAST)
1668 fbcon_bmove(vc, t + count, 0, t, 0,
1669 b - t - count, vc->vc_cols);
1672 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1675 case SCROLL_PAN_REDRAW:
1676 if ((p->yscroll + count <=
1677 2 * (p->vrows - vc->vc_rows))
1678 && ((!scroll_partial && (b - t == vc->vc_rows))
1681 3 * vc->vc_rows >> 2)))) {
1683 fbcon_redraw_move(vc, p, 0, t, count);
1684 ypan_up_redraw(vc, t, count);
1685 if (vc->vc_rows - b > 0)
1686 fbcon_redraw_move(vc, p, b,
1687 vc->vc_rows - b, b);
1689 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1690 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1693 case SCROLL_PAN_MOVE:
1694 if ((p->yscroll + count <=
1695 2 * (p->vrows - vc->vc_rows))
1696 && ((!scroll_partial && (b - t == vc->vc_rows))
1699 3 * vc->vc_rows >> 2)))) {
1701 fbcon_bmove(vc, 0, 0, count, 0, t,
1704 if (vc->vc_rows - b > 0)
1705 fbcon_bmove(vc, b - count, 0, b, 0,
1708 } else if (info->flags & FBINFO_READS_FAST)
1709 fbcon_bmove(vc, t + count, 0, t, 0,
1710 b - t - count, vc->vc_cols);
1713 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1718 fbcon_redraw(vc, p, t, b - t - count,
1719 count * vc->vc_cols);
1720 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1721 scr_memsetw((unsigned short *) (vc->vc_origin +
1724 vc->vc_video_erase_char,
1725 vc->vc_size_row * count);
1731 if (count > vc->vc_rows) /* Maximum realistic size */
1732 count = vc->vc_rows;
1733 if (logo_shown >= 0)
1735 switch (p->scrollmode) {
1737 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1739 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1740 scr_memsetw((unsigned short *) (vc->vc_origin +
1743 vc->vc_video_erase_char,
1744 vc->vc_size_row * count);
1748 case SCROLL_WRAP_MOVE:
1749 if (b - t - count > 3 * vc->vc_rows >> 2) {
1750 if (vc->vc_rows - b > 0)
1751 fbcon_bmove(vc, b, 0, b - count, 0,
1754 ywrap_down(vc, count);
1756 fbcon_bmove(vc, count, 0, 0, 0, t,
1758 } else if (info->flags & FBINFO_READS_FAST)
1759 fbcon_bmove(vc, t, 0, t + count, 0,
1760 b - t - count, vc->vc_cols);
1763 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1766 case SCROLL_PAN_MOVE:
1767 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1768 && ((!scroll_partial && (b - t == vc->vc_rows))
1771 3 * vc->vc_rows >> 2)))) {
1772 if (vc->vc_rows - b > 0)
1773 fbcon_bmove(vc, b, 0, b - count, 0,
1776 ypan_down(vc, count);
1778 fbcon_bmove(vc, count, 0, 0, 0, t,
1780 } else if (info->flags & FBINFO_READS_FAST)
1781 fbcon_bmove(vc, t, 0, t + count, 0,
1782 b - t - count, vc->vc_cols);
1785 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1788 case SCROLL_PAN_REDRAW:
1789 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1790 && ((!scroll_partial && (b - t == vc->vc_rows))
1793 3 * vc->vc_rows >> 2)))) {
1794 if (vc->vc_rows - b > 0)
1795 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1797 ypan_down_redraw(vc, t, count);
1799 fbcon_redraw_move(vc, p, count, t, 0);
1801 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1802 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1807 fbcon_redraw(vc, p, b - 1, b - t - count,
1808 -count * vc->vc_cols);
1809 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1810 scr_memsetw((unsigned short *) (vc->vc_origin +
1813 vc->vc_video_erase_char,
1814 vc->vc_size_row * count);
1822 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1823 int height, int width)
1825 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1826 struct display *p = &fb_display[vc->vc_num];
1828 if (fbcon_is_inactive(vc, info))
1831 if (!width || !height)
1834 /* Split blits that cross physical y_wrap case.
1835 * Pathological case involves 4 blits, better to use recursive
1836 * code rather than unrolled case
1838 * Recursive invocations don't need to erase the cursor over and
1839 * over again, so we use fbcon_bmove_rec()
1841 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1842 p->vrows - p->yscroll);
1845 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1846 int dy, int dx, int height, int width, u_int y_break)
1848 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1849 struct fbcon_ops *ops = info->fbcon_par;
1852 if (sy < y_break && sy + height > y_break) {
1854 if (dy < sy) { /* Avoid trashing self */
1855 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1857 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1858 height - b, width, y_break);
1860 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1861 height - b, width, y_break);
1862 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1868 if (dy < y_break && dy + height > y_break) {
1870 if (dy < sy) { /* Avoid trashing self */
1871 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1873 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1874 height - b, width, y_break);
1876 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1877 height - b, width, y_break);
1878 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1883 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1887 static void updatescrollmode(struct display *p,
1888 struct fb_info *info,
1891 struct fbcon_ops *ops = info->fbcon_par;
1892 int fh = vc->vc_font.height;
1893 int cap = info->flags;
1895 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1896 info->fix.xpanstep);
1897 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1898 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1899 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1900 info->var.xres_virtual);
1901 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1902 divides(ypan, vc->vc_font.height) && vyres > yres;
1903 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1904 divides(ywrap, vc->vc_font.height) &&
1905 divides(vc->vc_font.height, vyres) &&
1906 divides(vc->vc_font.height, yres);
1907 int reading_fast = cap & FBINFO_READS_FAST;
1908 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1909 !(cap & FBINFO_HWACCEL_DISABLED);
1910 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1911 !(cap & FBINFO_HWACCEL_DISABLED);
1913 p->vrows = vyres/fh;
1914 if (yres > (fh * (vc->vc_rows + 1)))
1915 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1916 if ((yres % fh) && (vyres % fh < yres % fh))
1919 if (good_wrap || good_pan) {
1920 if (reading_fast || fast_copyarea)
1921 p->scrollmode = good_wrap ?
1922 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1924 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1927 if (reading_fast || (fast_copyarea && !fast_imageblit))
1928 p->scrollmode = SCROLL_MOVE;
1930 p->scrollmode = SCROLL_REDRAW;
1934 #define PITCH(w) (((w) + 7) >> 3)
1935 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
1937 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1938 unsigned int height, unsigned int user)
1940 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1941 struct fbcon_ops *ops = info->fbcon_par;
1942 struct display *p = &fb_display[vc->vc_num];
1943 struct fb_var_screeninfo var = info->var;
1944 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
1946 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
1948 int pitch = PITCH(vc->vc_font.width);
1951 * If user font, ensure that a possible change to user font
1952 * height or width will not allow a font data out-of-bounds access.
1953 * NOTE: must use original charcount in calculation as font
1954 * charcount can change and cannot be used to determine the
1955 * font data allocated size.
1959 size = CALC_FONTSZ(vc->vc_font.height, pitch, FNTCHARCNT(vc->vc_font.data));
1960 if (size > FNTSIZE(vc->vc_font.data))
1964 virt_w = FBCON_SWAP(ops->rotate, width, height);
1965 virt_h = FBCON_SWAP(ops->rotate, height, width);
1966 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
1967 vc->vc_font.height);
1968 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
1970 var.xres = virt_w * virt_fw;
1971 var.yres = virt_h * virt_fh;
1972 x_diff = info->var.xres - var.xres;
1973 y_diff = info->var.yres - var.yres;
1974 if (x_diff < 0 || x_diff > virt_fw ||
1975 y_diff < 0 || y_diff > virt_fh) {
1976 const struct fb_videomode *mode;
1978 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
1979 mode = fb_find_best_mode(&var, &info->modelist);
1982 display_to_var(&var, p);
1983 fb_videomode_to_var(&var, mode);
1985 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
1988 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
1989 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1990 var.activate = FB_ACTIVATE_NOW |
1992 fb_set_var(info, &var);
1994 var_to_display(p, &info->var, info);
1995 ops->var = info->var;
1997 updatescrollmode(p, info, vc);
2001 static int fbcon_switch(struct vc_data *vc)
2003 struct fb_info *info, *old_info = NULL;
2004 struct fbcon_ops *ops;
2005 struct display *p = &fb_display[vc->vc_num];
2006 struct fb_var_screeninfo var;
2007 int i, ret, prev_console, charcnt = 256;
2009 info = registered_fb[con2fb_map[vc->vc_num]];
2010 ops = info->fbcon_par;
2012 if (logo_shown >= 0) {
2013 struct vc_data *conp2 = vc_cons[logo_shown].d;
2015 if (conp2->vc_top == logo_lines
2016 && conp2->vc_bottom == conp2->vc_rows)
2018 logo_shown = FBCON_LOGO_CANSHOW;
2021 prev_console = ops->currcon;
2022 if (prev_console != -1)
2023 old_info = registered_fb[con2fb_map[prev_console]];
2025 * FIXME: If we have multiple fbdev's loaded, we need to
2026 * update all info->currcon. Perhaps, we can place this
2027 * in a centralized structure, but this might break some
2030 * info->currcon = vc->vc_num;
2032 for (i = 0; i < FB_MAX; i++) {
2033 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2034 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2036 o->currcon = vc->vc_num;
2039 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2040 display_to_var(&var, p);
2041 var.activate = FB_ACTIVATE_NOW;
2044 * make sure we don't unnecessarily trip the memcmp()
2047 info->var.activate = var.activate;
2048 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2049 fb_set_var(info, &var);
2050 ops->var = info->var;
2052 if (old_info != NULL && (old_info != info ||
2053 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2054 if (info->fbops->fb_set_par) {
2055 ret = info->fbops->fb_set_par(info);
2058 printk(KERN_ERR "fbcon_switch: detected "
2059 "unhandled fb_set_par error, "
2060 "error code %d\n", ret);
2063 if (old_info != info)
2064 fbcon_del_cursor_timer(old_info);
2067 if (fbcon_is_inactive(vc, info) ||
2068 ops->blank_state != FB_BLANK_UNBLANK)
2069 fbcon_del_cursor_timer(info);
2071 fbcon_add_cursor_timer(info);
2073 set_blitting_type(vc, info);
2074 ops->cursor_reset = 1;
2076 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2077 ops->rotate = FB_ROTATE_UR;
2078 set_blitting_type(vc, info);
2081 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2082 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2085 charcnt = FNTCHARCNT(vc->vc_font.data);
2088 vc->vc_complement_mask <<= 1;
2090 updatescrollmode(p, info, vc);
2092 switch (p->scrollmode) {
2093 case SCROLL_WRAP_MOVE:
2094 scrollback_phys_max = p->vrows - vc->vc_rows;
2096 case SCROLL_PAN_MOVE:
2097 case SCROLL_PAN_REDRAW:
2098 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2099 if (scrollback_phys_max < 0)
2100 scrollback_phys_max = 0;
2103 scrollback_phys_max = 0;
2108 scrollback_current = 0;
2110 if (!fbcon_is_inactive(vc, info)) {
2111 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2112 ops->update_start(info);
2115 fbcon_set_palette(vc, color_table);
2116 fbcon_clear_margins(vc, 0);
2118 if (logo_shown == FBCON_LOGO_DRAW) {
2120 logo_shown = fg_console;
2121 /* This is protected above by initmem_freed */
2122 fb_show_logo(info, ops->rotate);
2124 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2125 vc->vc_size_row * (vc->vc_bottom -
2132 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2135 struct fb_event event;
2138 unsigned short charmask = vc->vc_hi_font_mask ?
2140 unsigned short oldc;
2142 oldc = vc->vc_video_erase_char;
2143 vc->vc_video_erase_char &= charmask;
2144 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2145 vc->vc_video_erase_char = oldc;
2149 if (!lock_fb_info(info))
2152 event.data = ␣
2153 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2154 unlock_fb_info(info);
2157 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2159 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2160 struct fbcon_ops *ops = info->fbcon_par;
2163 struct fb_var_screeninfo var = info->var;
2168 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2169 fb_set_var(info, &var);
2171 ops->var = info->var;
2175 if (!fbcon_is_inactive(vc, info)) {
2176 if (ops->blank_state != blank) {
2177 ops->blank_state = blank;
2178 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2179 ops->cursor_flash = (!blank);
2181 if (!(info->flags & FBINFO_MISC_USEREVENT))
2182 if (fb_blank(info, blank))
2183 fbcon_generic_blank(vc, info, blank);
2190 if (mode_switch || fbcon_is_inactive(vc, info) ||
2191 ops->blank_state != FB_BLANK_UNBLANK)
2192 fbcon_del_cursor_timer(info);
2194 fbcon_add_cursor_timer(info);
2199 static int fbcon_debug_enter(struct vc_data *vc)
2201 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2202 struct fbcon_ops *ops = info->fbcon_par;
2204 ops->save_graphics = ops->graphics;
2206 if (info->fbops->fb_debug_enter)
2207 info->fbops->fb_debug_enter(info);
2208 fbcon_set_palette(vc, color_table);
2212 static int fbcon_debug_leave(struct vc_data *vc)
2214 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2215 struct fbcon_ops *ops = info->fbcon_par;
2217 ops->graphics = ops->save_graphics;
2218 if (info->fbops->fb_debug_leave)
2219 info->fbops->fb_debug_leave(info);
2223 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2225 u8 *fontdata = vc->vc_font.data;
2226 u8 *data = font->data;
2229 font->width = vc->vc_font.width;
2230 font->height = vc->vc_font.height;
2231 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2235 if (font->width <= 8) {
2236 j = vc->vc_font.height;
2237 if (font->charcount * j > FNTSIZE(fontdata))
2240 for (i = 0; i < font->charcount; i++) {
2241 memcpy(data, fontdata, j);
2242 memset(data + j, 0, 32 - j);
2246 } else if (font->width <= 16) {
2247 j = vc->vc_font.height * 2;
2248 if (font->charcount * j > FNTSIZE(fontdata))
2251 for (i = 0; i < font->charcount; i++) {
2252 memcpy(data, fontdata, j);
2253 memset(data + j, 0, 64 - j);
2257 } else if (font->width <= 24) {
2258 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
2261 for (i = 0; i < font->charcount; i++) {
2262 for (j = 0; j < vc->vc_font.height; j++) {
2263 *data++ = fontdata[0];
2264 *data++ = fontdata[1];
2265 *data++ = fontdata[2];
2266 fontdata += sizeof(u32);
2268 memset(data, 0, 3 * (32 - j));
2269 data += 3 * (32 - j);
2272 j = vc->vc_font.height * 4;
2273 if (font->charcount * j > FNTSIZE(fontdata))
2276 for (i = 0; i < font->charcount; i++) {
2277 memcpy(data, fontdata, j);
2278 memset(data + j, 0, 128 - j);
2286 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2287 static void set_vc_hi_font(struct vc_data *vc, bool set)
2290 vc->vc_hi_font_mask = 0;
2291 if (vc->vc_can_do_color) {
2292 vc->vc_complement_mask >>= 1;
2293 vc->vc_s_complement_mask >>= 1;
2296 /* ++Edmund: reorder the attribute bits */
2297 if (vc->vc_can_do_color) {
2298 unsigned short *cp =
2299 (unsigned short *) vc->vc_origin;
2300 int count = vc->vc_screenbuf_size / 2;
2302 for (; count > 0; count--, cp++) {
2304 scr_writew(((c & 0xfe00) >> 1) |
2307 c = vc->vc_video_erase_char;
2308 vc->vc_video_erase_char =
2309 ((c & 0xfe00) >> 1) | (c & 0xff);
2313 vc->vc_hi_font_mask = 0x100;
2314 if (vc->vc_can_do_color) {
2315 vc->vc_complement_mask <<= 1;
2316 vc->vc_s_complement_mask <<= 1;
2319 /* ++Edmund: reorder the attribute bits */
2321 unsigned short *cp =
2322 (unsigned short *) vc->vc_origin;
2323 int count = vc->vc_screenbuf_size / 2;
2325 for (; count > 0; count--, cp++) {
2326 unsigned short newc;
2328 if (vc->vc_can_do_color)
2330 ((c & 0xff00) << 1) | (c &
2334 scr_writew(newc, cp);
2336 c = vc->vc_video_erase_char;
2337 if (vc->vc_can_do_color) {
2338 vc->vc_video_erase_char =
2339 ((c & 0xff00) << 1) | (c & 0xff);
2342 vc->vc_video_erase_char = c & ~0x100;
2347 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2348 const u8 * data, int userfont)
2350 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2351 struct fbcon_ops *ops = info->fbcon_par;
2352 struct display *p = &fb_display[vc->vc_num];
2355 char *old_data = NULL;
2357 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2359 old_data = vc->vc_font.data;
2361 cnt = FNTCHARCNT(data);
2364 vc->vc_font.data = (void *)(p->fontdata = data);
2365 if ((p->userfont = userfont))
2367 vc->vc_font.width = w;
2368 vc->vc_font.height = h;
2369 if (vc->vc_hi_font_mask && cnt == 256)
2370 set_vc_hi_font(vc, false);
2371 else if (!vc->vc_hi_font_mask && cnt == 512)
2372 set_vc_hi_font(vc, true);
2377 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2378 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2381 vc_resize(vc, cols, rows);
2382 } else if (con_is_visible(vc)
2383 && vc->vc_mode == KD_TEXT) {
2384 fbcon_clear_margins(vc, 0);
2388 if (old_data && (--REFCOUNT(old_data) == 0))
2389 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2393 static int fbcon_copy_font(struct vc_data *vc, int con)
2395 struct display *od = &fb_display[con];
2396 struct console_font *f = &vc->vc_font;
2398 if (od->fontdata == f->data)
2399 return 0; /* already the same font... */
2400 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2404 * User asked to set font; we are guaranteed that
2405 * a) width and height are in range 1..32
2406 * b) charcount does not exceed 512
2407 * but lets not assume that, since someone might someday want to use larger
2408 * fonts. And charcount of 512 is small for unicode support.
2410 * However, user space gives the font in 32 rows , regardless of
2411 * actual font height. So a new API is needed if support for larger fonts
2412 * is ever implemented.
2415 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2417 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2418 unsigned charcount = font->charcount;
2419 int w = font->width;
2420 int h = font->height;
2423 u8 *new_data, *data = font->data;
2424 int pitch = PITCH(font->width);
2426 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2427 * If not this check should be changed to charcount < 256 */
2428 if (charcount != 256 && charcount != 512)
2431 /* Make sure drawing engine can handle the font */
2432 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2433 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2436 /* Make sure driver can handle the font length */
2437 if (fbcon_invalid_charcount(info, charcount))
2440 size = CALC_FONTSZ(h, pitch, charcount);
2442 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2447 new_data += FONT_EXTRA_WORDS * sizeof(int);
2448 FNTSIZE(new_data) = size;
2449 FNTCHARCNT(new_data) = charcount;
2450 REFCOUNT(new_data) = 0; /* usage counter */
2451 for (i=0; i< charcount; i++) {
2452 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2455 /* Since linux has a nice crc32 function use it for counting font
2457 csum = crc32(0, new_data, size);
2459 FNTSUM(new_data) = csum;
2460 /* Check if the same font is on some other console already */
2461 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2462 struct vc_data *tmp = vc_cons[i].d;
2464 if (fb_display[i].userfont &&
2465 fb_display[i].fontdata &&
2466 FNTSUM(fb_display[i].fontdata) == csum &&
2467 FNTSIZE(fb_display[i].fontdata) == size &&
2468 tmp->vc_font.width == w &&
2469 !memcmp(fb_display[i].fontdata, new_data, size)) {
2470 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2471 new_data = (u8 *)fb_display[i].fontdata;
2475 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2478 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2480 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2481 const struct font_desc *f;
2484 f = get_default_font(info->var.xres, info->var.yres,
2485 info->pixmap.blit_x, info->pixmap.blit_y);
2486 else if (!(f = find_font(name)))
2489 font->width = f->width;
2490 font->height = f->height;
2491 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2494 static u16 palette_red[16];
2495 static u16 palette_green[16];
2496 static u16 palette_blue[16];
2498 static struct fb_cmap palette_cmap = {
2499 0, 16, palette_red, palette_green, palette_blue, NULL
2502 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2504 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2508 if (fbcon_is_inactive(vc, info))
2511 if (!con_is_visible(vc))
2514 depth = fb_get_color_depth(&info->var, &info->fix);
2516 for (i = j = 0; i < 16; i++) {
2518 val = vc->vc_palette[j++];
2519 palette_red[k] = (val << 8) | val;
2520 val = vc->vc_palette[j++];
2521 palette_green[k] = (val << 8) | val;
2522 val = vc->vc_palette[j++];
2523 palette_blue[k] = (val << 8) | val;
2525 palette_cmap.len = 16;
2526 palette_cmap.start = 0;
2528 * If framebuffer is capable of less than 16 colors,
2529 * use default palette of fbcon.
2532 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2534 fb_set_cmap(&palette_cmap, info);
2537 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2539 return (u16 *) (vc->vc_origin + offset);
2542 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2548 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2549 unsigned long offset = (pos - vc->vc_origin) / 2;
2551 x = offset % vc->vc_cols;
2552 y = offset / vc->vc_cols;
2553 ret = pos + (vc->vc_cols - x) * 2;
2555 /* Should not happen */
2557 ret = vc->vc_origin;
2566 /* As we might be inside of softback, we may work with non-contiguous buffer,
2567 that's why we have to use a separate routine. */
2568 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2571 u16 a = scr_readw(p);
2572 if (!vc->vc_can_do_color)
2574 else if (vc->vc_hi_font_mask == 0x100)
2575 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2576 (((a) & 0x0e00) << 4);
2578 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2579 (((a) & 0x0700) << 4);
2584 static int fbcon_set_origin(struct vc_data *vc)
2589 static void fbcon_suspended(struct fb_info *info)
2591 struct vc_data *vc = NULL;
2592 struct fbcon_ops *ops = info->fbcon_par;
2594 if (!ops || ops->currcon < 0)
2596 vc = vc_cons[ops->currcon].d;
2598 /* Clear cursor, restore saved data */
2599 fbcon_cursor(vc, CM_ERASE);
2602 static void fbcon_resumed(struct fb_info *info)
2605 struct fbcon_ops *ops = info->fbcon_par;
2607 if (!ops || ops->currcon < 0)
2609 vc = vc_cons[ops->currcon].d;
2614 static void fbcon_modechanged(struct fb_info *info)
2616 struct fbcon_ops *ops = info->fbcon_par;
2621 if (!ops || ops->currcon < 0)
2623 vc = vc_cons[ops->currcon].d;
2624 if (vc->vc_mode != KD_TEXT ||
2625 registered_fb[con2fb_map[ops->currcon]] != info)
2628 p = &fb_display[vc->vc_num];
2629 set_blitting_type(vc, info);
2631 if (con_is_visible(vc)) {
2632 var_to_display(p, &info->var, info);
2633 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2634 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2635 cols /= vc->vc_font.width;
2636 rows /= vc->vc_font.height;
2637 vc_resize(vc, cols, rows);
2638 updatescrollmode(p, info, vc);
2640 scrollback_current = 0;
2642 if (!fbcon_is_inactive(vc, info)) {
2643 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2644 ops->update_start(info);
2647 fbcon_set_palette(vc, color_table);
2652 static void fbcon_set_all_vcs(struct fb_info *info)
2654 struct fbcon_ops *ops = info->fbcon_par;
2657 int i, rows, cols, fg = -1;
2659 if (!ops || ops->currcon < 0)
2662 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2664 if (!vc || vc->vc_mode != KD_TEXT ||
2665 registered_fb[con2fb_map[i]] != info)
2668 if (con_is_visible(vc)) {
2673 p = &fb_display[vc->vc_num];
2674 set_blitting_type(vc, info);
2675 var_to_display(p, &info->var, info);
2676 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2677 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2678 cols /= vc->vc_font.width;
2679 rows /= vc->vc_font.height;
2680 vc_resize(vc, cols, rows);
2684 fbcon_modechanged(info);
2687 static int fbcon_mode_deleted(struct fb_info *info,
2688 struct fb_videomode *mode)
2690 struct fb_info *fb_info;
2692 int i, j, found = 0;
2694 /* before deletion, ensure that mode is not in use */
2695 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2699 fb_info = registered_fb[j];
2700 if (fb_info != info)
2705 if (fb_mode_is_equal(p->mode, mode)) {
2713 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2714 static int fbcon_unbind(void)
2718 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2722 fbcon_has_console_bind = 0;
2727 static inline int fbcon_unbind(void)
2731 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2733 /* called with console_lock held */
2734 static int fbcon_fb_unbind(int idx)
2736 int i, new_idx = -1, ret = 0;
2738 if (!fbcon_has_console_bind)
2741 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2742 if (con2fb_map[i] != idx &&
2743 con2fb_map[i] != -1) {
2744 new_idx = con2fb_map[i];
2749 if (new_idx != -1) {
2750 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2751 if (con2fb_map[i] == idx)
2752 set_con2fb_map(i, new_idx, 0);
2755 struct fb_info *info = registered_fb[idx];
2757 /* This is sort of like set_con2fb_map, except it maps
2758 * the consoles to no device and then releases the
2759 * oldinfo to free memory and cancel the cursor blink
2760 * timer. I can imagine this just becoming part of
2761 * set_con2fb_map where new_idx is -1
2763 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2764 if (con2fb_map[i] == idx) {
2766 if (!search_fb_in_map(idx)) {
2767 ret = con2fb_release_oldinfo(vc_cons[i].d,
2771 con2fb_map[i] = idx;
2777 ret = fbcon_unbind();
2783 /* called with console_lock held */
2784 static int fbcon_fb_unregistered(struct fb_info *info)
2789 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2790 if (con2fb_map[i] == idx)
2794 if (idx == info_idx) {
2797 for (i = 0; i < FB_MAX; i++) {
2798 if (registered_fb[i] != NULL) {
2805 if (info_idx != -1) {
2806 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2807 if (con2fb_map[i] == -1)
2808 con2fb_map[i] = info_idx;
2812 if (primary_device == idx)
2813 primary_device = -1;
2815 if (!num_registered_fb)
2816 do_unregister_con_driver(&fb_con);
2821 /* called with console_lock held */
2822 static void fbcon_remap_all(int idx)
2825 for (i = first_fb_vc; i <= last_fb_vc; i++)
2826 set_con2fb_map(i, idx, 0);
2828 if (con_is_bound(&fb_con)) {
2829 printk(KERN_INFO "fbcon: Remapping primary device, "
2830 "fb%i, to tty %i-%i\n", idx,
2831 first_fb_vc + 1, last_fb_vc + 1);
2836 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2837 static void fbcon_select_primary(struct fb_info *info)
2839 if (!map_override && primary_device == -1 &&
2840 fb_is_primary_device(info)) {
2843 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2844 info->fix.id, info->node);
2845 primary_device = info->node;
2847 for (i = first_fb_vc; i <= last_fb_vc; i++)
2848 con2fb_map_boot[i] = primary_device;
2850 if (con_is_bound(&fb_con)) {
2851 printk(KERN_INFO "fbcon: Remapping primary device, "
2852 "fb%i, to tty %i-%i\n", info->node,
2853 first_fb_vc + 1, last_fb_vc + 1);
2854 info_idx = primary_device;
2860 static inline void fbcon_select_primary(struct fb_info *info)
2864 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2866 /* called with console_lock held */
2867 static int fbcon_fb_registered(struct fb_info *info)
2869 int ret = 0, i, idx;
2872 fbcon_select_primary(info);
2874 if (info_idx == -1) {
2875 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2876 if (con2fb_map_boot[i] == idx) {
2883 ret = do_fbcon_takeover(1);
2885 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2886 if (con2fb_map_boot[i] == idx)
2887 set_con2fb_map(i, idx, 0);
2894 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2896 struct fbcon_ops *ops = info->fbcon_par;
2899 if (!ops || ops->currcon < 0)
2902 vc = vc_cons[ops->currcon].d;
2903 if (vc->vc_mode != KD_TEXT ||
2904 registered_fb[con2fb_map[ops->currcon]] != info)
2907 if (con_is_visible(vc)) {
2911 do_unblank_screen(0);
2913 ops->blank_state = blank;
2916 static void fbcon_new_modelist(struct fb_info *info)
2920 struct fb_var_screeninfo var;
2921 const struct fb_videomode *mode;
2923 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2924 if (registered_fb[con2fb_map[i]] != info)
2926 if (!fb_display[i].mode)
2929 display_to_var(&var, &fb_display[i]);
2930 mode = fb_find_nearest_mode(fb_display[i].mode,
2932 fb_videomode_to_var(&var, mode);
2933 fbcon_set_disp(info, &var, vc->vc_num);
2937 static void fbcon_get_requirement(struct fb_info *info,
2938 struct fb_blit_caps *caps)
2946 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2948 if (vc && vc->vc_mode == KD_TEXT &&
2949 info->node == con2fb_map[i]) {
2951 caps->x |= 1 << (vc->vc_font.width - 1);
2952 caps->y |= 1 << (vc->vc_font.height - 1);
2953 charcnt = (p->userfont) ?
2954 FNTCHARCNT(p->fontdata) : 256;
2955 if (caps->len < charcnt)
2956 caps->len = charcnt;
2960 vc = vc_cons[fg_console].d;
2962 if (vc && vc->vc_mode == KD_TEXT &&
2963 info->node == con2fb_map[fg_console]) {
2964 p = &fb_display[fg_console];
2965 caps->x = 1 << (vc->vc_font.width - 1);
2966 caps->y = 1 << (vc->vc_font.height - 1);
2967 caps->len = (p->userfont) ?
2968 FNTCHARCNT(p->fontdata) : 256;
2973 static int fbcon_event_notify(struct notifier_block *self,
2974 unsigned long action, void *data)
2976 struct fb_event *event = data;
2977 struct fb_info *info = event->info;
2978 struct fb_videomode *mode;
2979 struct fb_con2fbmap *con2fb;
2980 struct fb_blit_caps *caps;
2984 * ignore all events except driver registration and deregistration
2985 * if fbcon is not active
2987 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
2988 action == FB_EVENT_FB_UNREGISTERED))
2992 case FB_EVENT_SUSPEND:
2993 fbcon_suspended(info);
2995 case FB_EVENT_RESUME:
2996 fbcon_resumed(info);
2998 case FB_EVENT_MODE_CHANGE:
2999 fbcon_modechanged(info);
3001 case FB_EVENT_MODE_CHANGE_ALL:
3002 fbcon_set_all_vcs(info);
3004 case FB_EVENT_MODE_DELETE:
3006 ret = fbcon_mode_deleted(info, mode);
3008 case FB_EVENT_FB_UNBIND:
3010 ret = fbcon_fb_unbind(idx);
3012 case FB_EVENT_FB_REGISTERED:
3013 ret = fbcon_fb_registered(info);
3015 case FB_EVENT_FB_UNREGISTERED:
3016 ret = fbcon_fb_unregistered(info);
3018 case FB_EVENT_SET_CONSOLE_MAP:
3019 /* called with console lock held */
3020 con2fb = event->data;
3021 ret = set_con2fb_map(con2fb->console - 1,
3022 con2fb->framebuffer, 1);
3024 case FB_EVENT_GET_CONSOLE_MAP:
3025 con2fb = event->data;
3026 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3028 case FB_EVENT_BLANK:
3029 fbcon_fb_blanked(info, *(int *)event->data);
3031 case FB_EVENT_NEW_MODELIST:
3032 fbcon_new_modelist(info);
3034 case FB_EVENT_GET_REQ:
3036 fbcon_get_requirement(info, caps);
3038 case FB_EVENT_REMAP_ALL_CONSOLE:
3040 fbcon_remap_all(idx);
3048 * The console `switch' structure for the frame buffer based console
3051 static const struct consw fb_con = {
3052 .owner = THIS_MODULE,
3053 .con_startup = fbcon_startup,
3054 .con_init = fbcon_init,
3055 .con_deinit = fbcon_deinit,
3056 .con_clear = fbcon_clear,
3057 .con_putc = fbcon_putc,
3058 .con_putcs = fbcon_putcs,
3059 .con_cursor = fbcon_cursor,
3060 .con_scroll = fbcon_scroll,
3061 .con_switch = fbcon_switch,
3062 .con_blank = fbcon_blank,
3063 .con_font_set = fbcon_set_font,
3064 .con_font_get = fbcon_get_font,
3065 .con_font_default = fbcon_set_def_font,
3066 .con_font_copy = fbcon_copy_font,
3067 .con_set_palette = fbcon_set_palette,
3068 .con_set_origin = fbcon_set_origin,
3069 .con_invert_region = fbcon_invert_region,
3070 .con_screen_pos = fbcon_screen_pos,
3071 .con_getxy = fbcon_getxy,
3072 .con_resize = fbcon_resize,
3073 .con_debug_enter = fbcon_debug_enter,
3074 .con_debug_leave = fbcon_debug_leave,
3077 static struct notifier_block fbcon_event_notifier = {
3078 .notifier_call = fbcon_event_notify,
3081 static ssize_t store_rotate(struct device *device,
3082 struct device_attribute *attr, const char *buf,
3085 struct fb_info *info;
3089 if (fbcon_has_exited)
3093 idx = con2fb_map[fg_console];
3095 if (idx == -1 || registered_fb[idx] == NULL)
3098 info = registered_fb[idx];
3099 rotate = simple_strtoul(buf, last, 0);
3100 fbcon_rotate(info, rotate);
3106 static ssize_t store_rotate_all(struct device *device,
3107 struct device_attribute *attr,const char *buf,
3110 struct fb_info *info;
3114 if (fbcon_has_exited)
3118 idx = con2fb_map[fg_console];
3120 if (idx == -1 || registered_fb[idx] == NULL)
3123 info = registered_fb[idx];
3124 rotate = simple_strtoul(buf, last, 0);
3125 fbcon_rotate_all(info, rotate);
3131 static ssize_t show_rotate(struct device *device,
3132 struct device_attribute *attr,char *buf)
3134 struct fb_info *info;
3135 int rotate = 0, idx;
3137 if (fbcon_has_exited)
3141 idx = con2fb_map[fg_console];
3143 if (idx == -1 || registered_fb[idx] == NULL)
3146 info = registered_fb[idx];
3147 rotate = fbcon_get_rotate(info);
3150 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3153 static ssize_t show_cursor_blink(struct device *device,
3154 struct device_attribute *attr, char *buf)
3156 struct fb_info *info;
3157 struct fbcon_ops *ops;
3158 int idx, blink = -1;
3160 if (fbcon_has_exited)
3164 idx = con2fb_map[fg_console];
3166 if (idx == -1 || registered_fb[idx] == NULL)
3169 info = registered_fb[idx];
3170 ops = info->fbcon_par;
3175 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3178 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3181 static ssize_t store_cursor_blink(struct device *device,
3182 struct device_attribute *attr,
3183 const char *buf, size_t count)
3185 struct fb_info *info;
3189 if (fbcon_has_exited)
3193 idx = con2fb_map[fg_console];
3195 if (idx == -1 || registered_fb[idx] == NULL)
3198 info = registered_fb[idx];
3200 if (!info->fbcon_par)
3203 blink = simple_strtoul(buf, last, 0);
3206 fbcon_cursor_noblink = 0;
3207 fbcon_add_cursor_timer(info);
3209 fbcon_cursor_noblink = 1;
3210 fbcon_del_cursor_timer(info);
3218 static struct device_attribute device_attrs[] = {
3219 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3220 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3221 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3222 store_cursor_blink),
3225 static int fbcon_init_device(void)
3229 fbcon_has_sysfs = 1;
3231 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3232 error = device_create_file(fbcon_device, &device_attrs[i]);
3240 device_remove_file(fbcon_device, &device_attrs[i]);
3242 fbcon_has_sysfs = 0;
3248 static void fbcon_start(void)
3250 if (num_registered_fb) {
3255 for (i = 0; i < FB_MAX; i++) {
3256 if (registered_fb[i] != NULL) {
3262 do_fbcon_takeover(0);
3268 static void fbcon_exit(void)
3270 struct fb_info *info;
3273 if (fbcon_has_exited)
3276 for (i = 0; i < FB_MAX; i++) {
3280 info = registered_fb[i];
3285 if (info->queue.func)
3286 pending = cancel_work_sync(&info->queue);
3287 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3290 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3291 if (con2fb_map[j] == i) {
3298 if (info->fbops->fb_release)
3299 info->fbops->fb_release(info, 0);
3300 module_put(info->fbops->owner);
3302 if (info->fbcon_par) {
3303 struct fbcon_ops *ops = info->fbcon_par;
3305 fbcon_del_cursor_timer(info);
3306 kfree(ops->cursor_src);
3307 kfree(ops->cursor_state.mask);
3308 kfree(info->fbcon_par);
3309 info->fbcon_par = NULL;
3312 if (info->queue.func == fb_flashcursor)
3313 info->queue.func = NULL;
3317 fbcon_has_exited = 1;
3320 static int __init fb_console_init(void)
3325 fb_register_client(&fbcon_event_notifier);
3326 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3329 if (IS_ERR(fbcon_device)) {
3330 printk(KERN_WARNING "Unable to create device "
3331 "for fbcon; errno = %ld\n",
3332 PTR_ERR(fbcon_device));
3333 fbcon_device = NULL;
3335 fbcon_init_device();
3337 for (i = 0; i < MAX_NR_CONSOLES; i++)
3345 fs_initcall(fb_console_init);
3349 static void __exit fbcon_deinit_device(void)
3353 if (fbcon_has_sysfs) {
3354 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3355 device_remove_file(fbcon_device, &device_attrs[i]);
3357 fbcon_has_sysfs = 0;
3361 static void __exit fb_console_exit(void)
3364 fb_unregister_client(&fbcon_event_notifier);
3365 fbcon_deinit_device();
3366 device_destroy(fb_class, MKDEV(0, 0));
3368 do_unregister_con_driver(&fb_con);
3372 module_exit(fb_console_exit);
3376 MODULE_LICENSE("GPL");