2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
96 static struct display fb_display[MAX_NR_CONSOLES];
98 static signed char con2fb_map[MAX_NR_CONSOLES];
99 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
101 static int logo_lines;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown = FBCON_LOGO_CANSHOW;
105 /* Software scrollback */
106 static int fbcon_softback_size = 32768;
107 static unsigned long softback_buf, softback_curr;
108 static unsigned long softback_in;
109 static unsigned long softback_top, softback_end;
110 static int softback_lines;
111 /* console mappings */
112 static int first_fb_vc;
113 static int last_fb_vc = MAX_NR_CONSOLES - 1;
114 static int fbcon_is_default = 1;
115 static int fbcon_has_exited;
116 static int primary_device = -1;
117 static int fbcon_has_console_bind;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override;
122 static inline void fbcon_map_override(void)
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
133 static char fontname[40];
135 /* current fb_info */
136 static int info_idx = -1;
138 /* console rotation */
139 static int initial_rotation = -1;
140 static int fbcon_has_sysfs;
141 static int margin_color;
143 static const struct consw fb_con;
145 #define CM_SOFTBACK (8)
147 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
149 static int fbcon_set_origin(struct vc_data *);
151 static int fbcon_cursor_noblink;
153 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
156 * Interface used by the world
159 static const char *fbcon_startup(void);
160 static void fbcon_init(struct vc_data *vc, int init);
161 static void fbcon_deinit(struct vc_data *vc);
162 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
164 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
165 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
166 int count, int ypos, int xpos);
167 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
168 static void fbcon_cursor(struct vc_data *vc, int mode);
169 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
170 int height, int width);
171 static int fbcon_switch(struct vc_data *vc);
172 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
173 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
178 static __inline__ void ywrap_up(struct vc_data *vc, int count);
179 static __inline__ void ywrap_down(struct vc_data *vc, int count);
180 static __inline__ void ypan_up(struct vc_data *vc, int count);
181 static __inline__ void ypan_down(struct vc_data *vc, int count);
182 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
183 int dy, int dx, int height, int width, u_int y_break);
184 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
186 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
187 int line, int count, int dy);
188 static void fbcon_modechanged(struct fb_info *info);
189 static void fbcon_set_all_vcs(struct fb_info *info);
190 static void fbcon_start(void);
191 static void fbcon_exit(void);
192 static struct device *fbcon_device;
194 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
195 static inline void fbcon_set_rotation(struct fb_info *info)
197 struct fbcon_ops *ops = info->fbcon_par;
199 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
200 ops->p->con_rotate < 4)
201 ops->rotate = ops->p->con_rotate;
206 static void fbcon_rotate(struct fb_info *info, u32 rotate)
208 struct fbcon_ops *ops= info->fbcon_par;
209 struct fb_info *fb_info;
211 if (!ops || ops->currcon == -1)
214 fb_info = registered_fb[con2fb_map[ops->currcon]];
216 if (info == fb_info) {
217 struct display *p = &fb_display[ops->currcon];
220 p->con_rotate = rotate;
224 fbcon_modechanged(info);
228 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
230 struct fbcon_ops *ops = info->fbcon_par;
235 if (!ops || ops->currcon < 0 || rotate > 3)
238 for (i = first_fb_vc; i <= last_fb_vc; i++) {
240 if (!vc || vc->vc_mode != KD_TEXT ||
241 registered_fb[con2fb_map[i]] != info)
244 p = &fb_display[vc->vc_num];
245 p->con_rotate = rotate;
248 fbcon_set_all_vcs(info);
251 static inline void fbcon_set_rotation(struct fb_info *info)
253 struct fbcon_ops *ops = info->fbcon_par;
255 ops->rotate = FB_ROTATE_UR;
258 static void fbcon_rotate(struct fb_info *info, u32 rotate)
263 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
267 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
269 static int fbcon_get_rotate(struct fb_info *info)
271 struct fbcon_ops *ops = info->fbcon_par;
273 return (ops) ? ops->rotate : 0;
276 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
278 struct fbcon_ops *ops = info->fbcon_par;
280 return (info->state != FBINFO_STATE_RUNNING ||
281 vc->vc_mode != KD_TEXT || ops->graphics) &&
282 !vt_force_oops_output(vc);
285 static int get_color(struct vc_data *vc, struct fb_info *info,
288 int depth = fb_get_color_depth(&info->var, &info->fix);
291 if (console_blanked) {
292 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
294 c = vc->vc_video_erase_char & charmask;
298 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
299 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
304 int col = mono_col(info);
306 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
307 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
312 color = (is_fg) ? fg : bg;
317 * Scale down 16-colors to 4 colors. Default 4-color palette
318 * is grayscale. However, simply dividing the values by 4
319 * will not work, as colors 1, 2 and 3 will be scaled-down
320 * to zero rendering them invisible. So empirically convert
321 * colors to a sane 4-level grayscale.
325 color = 0; /* black */
328 color = 2; /* white */
331 color = 1; /* gray */
334 color = 3; /* intense white */
340 * Last 8 entries of default 16-color palette is a more intense
341 * version of the first 8 (i.e., same chrominance, different
352 static void fbcon_update_softback(struct vc_data *vc)
354 int l = fbcon_softback_size / vc->vc_size_row;
357 softback_end = softback_buf + l * vc->vc_size_row;
359 /* Smaller scrollback makes no sense, and 0 would screw
360 the operation totally */
364 static void fb_flashcursor(struct work_struct *work)
366 struct fb_info *info = container_of(work, struct fb_info, queue);
367 struct fbcon_ops *ops = info->fbcon_par;
368 struct vc_data *vc = NULL;
373 /* FIXME: we should sort out the unbind locking instead */
374 /* instead we just fail to flash the cursor if we can't get
375 * the lock instead of blocking fbcon deinit */
376 ret = console_trylock();
380 if (ops && ops->currcon != -1)
381 vc = vc_cons[ops->currcon].d;
383 if (!vc || !con_is_visible(vc) ||
384 registered_fb[con2fb_map[vc->vc_num]] != info ||
390 c = scr_readw((u16 *) vc->vc_pos);
391 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
393 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
394 get_color(vc, info, c, 0));
398 static void cursor_timer_handler(struct timer_list *t)
400 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
401 struct fb_info *info = ops->info;
403 queue_work(system_power_efficient_wq, &info->queue);
404 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
407 static void fbcon_add_cursor_timer(struct fb_info *info)
409 struct fbcon_ops *ops = info->fbcon_par;
411 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
412 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
413 !fbcon_cursor_noblink) {
414 if (!info->queue.func)
415 INIT_WORK(&info->queue, fb_flashcursor);
417 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
418 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
419 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
423 static void fbcon_del_cursor_timer(struct fb_info *info)
425 struct fbcon_ops *ops = info->fbcon_par;
427 if (info->queue.func == fb_flashcursor &&
428 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
429 del_timer_sync(&ops->cursor_timer);
430 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
435 static int __init fb_console_setup(char *this_opt)
440 if (!this_opt || !*this_opt)
443 while ((options = strsep(&this_opt, ",")) != NULL) {
444 if (!strncmp(options, "font:", 5)) {
445 strlcpy(fontname, options + 5, sizeof(fontname));
449 if (!strncmp(options, "scrollback:", 11)) {
452 fbcon_softback_size = simple_strtoul(options, &options, 0);
453 if (*options == 'k' || *options == 'K') {
454 fbcon_softback_size *= 1024;
460 if (!strncmp(options, "map:", 4)) {
463 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
467 (options[j++]-'0') % FB_MAX;
470 fbcon_map_override();
475 if (!strncmp(options, "vc:", 3)) {
478 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
481 if (*options++ == '-')
482 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
483 fbcon_is_default = 0;
487 if (!strncmp(options, "rotate:", 7)) {
490 initial_rotation = simple_strtoul(options, &options, 0);
491 if (initial_rotation > 3)
492 initial_rotation = 0;
496 if (!strncmp(options, "margin:", 7)) {
499 margin_color = simple_strtoul(options, &options, 0);
506 __setup("fbcon=", fb_console_setup);
509 static int search_fb_in_map(int idx)
513 for (i = first_fb_vc; i <= last_fb_vc; i++) {
514 if (con2fb_map[i] == idx)
520 static int search_for_mapped_con(void)
524 for (i = first_fb_vc; i <= last_fb_vc; i++) {
525 if (con2fb_map[i] != -1)
531 static int do_fbcon_takeover(int show_logo)
535 if (!num_registered_fb)
539 logo_shown = FBCON_LOGO_DONTSHOW;
541 for (i = first_fb_vc; i <= last_fb_vc; i++)
542 con2fb_map[i] = info_idx;
544 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
548 for (i = first_fb_vc; i <= last_fb_vc; i++)
552 fbcon_has_console_bind = 1;
559 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
560 int cols, int rows, int new_cols, int new_rows)
562 logo_shown = FBCON_LOGO_DONTSHOW;
565 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
566 int cols, int rows, int new_cols, int new_rows)
568 /* Need to make room for the logo */
569 struct fbcon_ops *ops = info->fbcon_par;
570 int cnt, erase = vc->vc_video_erase_char, step;
571 unsigned short *save = NULL, *r, *q;
574 if (info->fbops->owner) {
575 logo_shown = FBCON_LOGO_DONTSHOW;
580 * remove underline attribute from erase character
581 * if black and white framebuffer.
583 if (fb_get_color_depth(&info->var, &info->fix) == 1)
585 logo_height = fb_prepare_logo(info, ops->rotate);
586 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
587 q = (unsigned short *) (vc->vc_origin +
588 vc->vc_size_row * rows);
589 step = logo_lines * cols;
590 for (r = q - logo_lines * cols; r < q; r++)
591 if (scr_readw(r) != vc->vc_video_erase_char)
593 if (r != q && new_rows >= rows + logo_lines) {
594 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
596 int i = cols < new_cols ? cols : new_cols;
597 scr_memsetw(save, erase, logo_lines * new_cols * 2);
599 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
600 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
605 /* We can scroll screen down */
607 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
608 scr_memcpyw(r + step, r, vc->vc_size_row);
613 if (vc->vc_y + logo_lines >= rows)
614 lines = rows - vc->vc_y - 1;
618 vc->vc_pos += lines * vc->vc_size_row;
621 scr_memsetw((unsigned short *) vc->vc_origin,
623 vc->vc_size_row * logo_lines);
625 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
626 fbcon_clear_margins(vc, 0);
631 q = (unsigned short *) (vc->vc_origin +
634 scr_memcpyw(q, save, logo_lines * new_cols * 2);
635 vc->vc_y += logo_lines;
636 vc->vc_pos += logo_lines * vc->vc_size_row;
640 if (logo_lines > vc->vc_bottom) {
641 logo_shown = FBCON_LOGO_CANSHOW;
643 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
644 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
645 logo_shown = FBCON_LOGO_DRAW;
646 vc->vc_top = logo_lines;
651 #ifdef CONFIG_FB_TILEBLITTING
652 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
654 struct fbcon_ops *ops = info->fbcon_par;
656 ops->p = &fb_display[vc->vc_num];
658 if ((info->flags & FBINFO_MISC_TILEBLITTING))
659 fbcon_set_tileops(vc, info);
661 fbcon_set_rotation(info);
662 fbcon_set_bitops(ops);
666 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
670 if (info->flags & FBINFO_MISC_TILEBLITTING &&
671 info->tileops->fb_get_tilemax(info) < charcount)
677 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
679 struct fbcon_ops *ops = info->fbcon_par;
681 info->flags &= ~FBINFO_MISC_TILEBLITTING;
682 ops->p = &fb_display[vc->vc_num];
683 fbcon_set_rotation(info);
684 fbcon_set_bitops(ops);
687 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
692 #endif /* CONFIG_MISC_TILEBLITTING */
695 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
696 int unit, int oldidx)
698 struct fbcon_ops *ops = NULL;
701 if (!try_module_get(info->fbops->owner))
704 if (!err && info->fbops->fb_open &&
705 info->fbops->fb_open(info, 0))
709 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
715 ops->cur_blink_jiffies = HZ / 5;
717 info->fbcon_par = ops;
720 set_blitting_type(vc, info);
724 con2fb_map[unit] = oldidx;
725 module_put(info->fbops->owner);
731 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
732 struct fb_info *newinfo, int unit,
733 int oldidx, int found)
735 struct fbcon_ops *ops = oldinfo->fbcon_par;
738 if (oldinfo->fbops->fb_release &&
739 oldinfo->fbops->fb_release(oldinfo, 0)) {
740 con2fb_map[unit] = oldidx;
741 if (!found && newinfo->fbops->fb_release)
742 newinfo->fbops->fb_release(newinfo, 0);
744 module_put(newinfo->fbops->owner);
749 fbcon_del_cursor_timer(oldinfo);
750 kfree(ops->cursor_state.mask);
751 kfree(ops->cursor_data);
752 kfree(ops->cursor_src);
753 kfree(ops->fontbuffer);
754 kfree(oldinfo->fbcon_par);
755 oldinfo->fbcon_par = NULL;
756 module_put(oldinfo->fbops->owner);
758 If oldinfo and newinfo are driving the same hardware,
759 the fb_release() method of oldinfo may attempt to
760 restore the hardware state. This will leave the
761 newinfo in an undefined state. Thus, a call to
762 fb_set_par() may be needed for the newinfo.
764 if (newinfo && newinfo->fbops->fb_set_par) {
765 ret = newinfo->fbops->fb_set_par(newinfo);
768 printk(KERN_ERR "con2fb_release_oldinfo: "
769 "detected unhandled fb_set_par error, "
770 "error code %d\n", ret);
777 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
778 int unit, int show_logo)
780 struct fbcon_ops *ops = info->fbcon_par;
783 ops->currcon = fg_console;
785 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
786 ret = info->fbops->fb_set_par(info);
789 printk(KERN_ERR "con2fb_init_display: detected "
790 "unhandled fb_set_par error, "
791 "error code %d\n", ret);
794 ops->flags |= FBCON_FLAGS_INIT;
796 fbcon_set_disp(info, &info->var, unit);
799 struct vc_data *fg_vc = vc_cons[fg_console].d;
800 struct fb_info *fg_info =
801 registered_fb[con2fb_map[fg_console]];
803 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
804 fg_vc->vc_rows, fg_vc->vc_cols,
808 update_screen(vc_cons[fg_console].d);
812 * set_con2fb_map - map console to frame buffer device
813 * @unit: virtual console number to map
814 * @newidx: frame buffer index to map virtual console to
815 * @user: user request
817 * Maps a virtual console @unit to a frame buffer device
820 * This should be called with the console lock held.
822 static int set_con2fb_map(int unit, int newidx, int user)
824 struct vc_data *vc = vc_cons[unit].d;
825 int oldidx = con2fb_map[unit];
826 struct fb_info *info = registered_fb[newidx];
827 struct fb_info *oldinfo = NULL;
830 if (oldidx == newidx)
836 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
838 return do_fbcon_takeover(0);
842 oldinfo = registered_fb[oldidx];
844 found = search_fb_in_map(newidx);
846 con2fb_map[unit] = newidx;
848 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
852 * If old fb is not mapped to any of the consoles,
853 * fbcon should release it.
855 if (!err && oldinfo && !search_fb_in_map(oldidx))
856 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
860 int show_logo = (fg_console == 0 && !user &&
861 logo_shown != FBCON_LOGO_DONTSHOW);
864 fbcon_add_cursor_timer(info);
865 con2fb_map_boot[unit] = newidx;
866 con2fb_init_display(vc, info, unit, show_logo);
869 if (!search_fb_in_map(info_idx))
876 * Low Level Operations
878 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
879 static int var_to_display(struct display *disp,
880 struct fb_var_screeninfo *var,
881 struct fb_info *info)
883 disp->xres_virtual = var->xres_virtual;
884 disp->yres_virtual = var->yres_virtual;
885 disp->bits_per_pixel = var->bits_per_pixel;
886 disp->grayscale = var->grayscale;
887 disp->nonstd = var->nonstd;
888 disp->accel_flags = var->accel_flags;
889 disp->height = var->height;
890 disp->width = var->width;
891 disp->red = var->red;
892 disp->green = var->green;
893 disp->blue = var->blue;
894 disp->transp = var->transp;
895 disp->rotate = var->rotate;
896 disp->mode = fb_match_mode(var, &info->modelist);
897 if (disp->mode == NULL)
898 /* This should not happen */
903 static void display_to_var(struct fb_var_screeninfo *var,
904 struct display *disp)
906 fb_videomode_to_var(var, disp->mode);
907 var->xres_virtual = disp->xres_virtual;
908 var->yres_virtual = disp->yres_virtual;
909 var->bits_per_pixel = disp->bits_per_pixel;
910 var->grayscale = disp->grayscale;
911 var->nonstd = disp->nonstd;
912 var->accel_flags = disp->accel_flags;
913 var->height = disp->height;
914 var->width = disp->width;
915 var->red = disp->red;
916 var->green = disp->green;
917 var->blue = disp->blue;
918 var->transp = disp->transp;
919 var->rotate = disp->rotate;
922 static const char *fbcon_startup(void)
924 const char *display_desc = "frame buffer device";
925 struct display *p = &fb_display[fg_console];
926 struct vc_data *vc = vc_cons[fg_console].d;
927 const struct font_desc *font = NULL;
928 struct module *owner;
929 struct fb_info *info = NULL;
930 struct fbcon_ops *ops;
934 * If num_registered_fb is zero, this is a call for the dummy part.
935 * The frame buffer devices weren't initialized yet.
937 if (!num_registered_fb || info_idx == -1)
940 * Instead of blindly using registered_fb[0], we use info_idx, set by
943 info = registered_fb[info_idx];
947 owner = info->fbops->owner;
948 if (!try_module_get(owner))
950 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
955 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
963 ops->cur_rotate = -1;
964 ops->cur_blink_jiffies = HZ / 5;
966 info->fbcon_par = ops;
967 if (initial_rotation != -1)
968 p->con_rotate = initial_rotation;
970 p->con_rotate = fbcon_platform_get_rotate(info);
971 set_blitting_type(vc, info);
973 if (info->fix.type != FB_TYPE_TEXT) {
974 if (fbcon_softback_size) {
978 kmalloc(fbcon_softback_size,
981 fbcon_softback_size = 0;
987 kfree((void *) softback_buf);
993 softback_in = softback_top = softback_curr =
998 /* Setup default font */
999 if (!p->fontdata && !vc->vc_font.data) {
1000 if (!fontname[0] || !(font = find_font(fontname)))
1001 font = get_default_font(info->var.xres,
1003 info->pixmap.blit_x,
1004 info->pixmap.blit_y);
1005 vc->vc_font.width = font->width;
1006 vc->vc_font.height = font->height;
1007 vc->vc_font.data = (void *)(p->fontdata = font->data);
1008 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1010 p->fontdata = vc->vc_font.data;
1013 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1014 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1015 cols /= vc->vc_font.width;
1016 rows /= vc->vc_font.height;
1017 vc_resize(vc, cols, rows);
1019 DPRINTK("mode: %s\n", info->fix.id);
1020 DPRINTK("visual: %d\n", info->fix.visual);
1021 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1023 info->var.bits_per_pixel);
1025 fbcon_add_cursor_timer(info);
1026 fbcon_has_exited = 0;
1027 return display_desc;
1030 static void fbcon_init(struct vc_data *vc, int init)
1032 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1033 struct fbcon_ops *ops;
1034 struct vc_data **default_mode = vc->vc_display_fg;
1035 struct vc_data *svc = *default_mode;
1036 struct display *t, *p = &fb_display[vc->vc_num];
1037 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1040 if (info_idx == -1 || info == NULL)
1045 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1046 (info->fix.type == FB_TYPE_TEXT))
1049 if (var_to_display(p, &info->var, info))
1052 if (!info->fbcon_par)
1053 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1055 /* If we are not the first console on this
1056 fb, copy the font from that console */
1057 t = &fb_display[fg_console];
1060 struct vc_data *fvc = vc_cons[fg_console].d;
1062 vc->vc_font.data = (void *)(p->fontdata =
1064 vc->vc_font.width = fvc->vc_font.width;
1065 vc->vc_font.height = fvc->vc_font.height;
1066 p->userfont = t->userfont;
1069 REFCOUNT(p->fontdata)++;
1071 const struct font_desc *font = NULL;
1073 if (!fontname[0] || !(font = find_font(fontname)))
1074 font = get_default_font(info->var.xres,
1076 info->pixmap.blit_x,
1077 info->pixmap.blit_y);
1078 vc->vc_font.width = font->width;
1079 vc->vc_font.height = font->height;
1080 vc->vc_font.data = (void *)(p->fontdata = font->data);
1081 vc->vc_font.charcount = 256; /* FIXME Need to
1082 support more fonts */
1087 charcnt = FNTCHARCNT(p->fontdata);
1089 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1090 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1091 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1092 if (charcnt == 256) {
1093 vc->vc_hi_font_mask = 0;
1095 vc->vc_hi_font_mask = 0x100;
1096 if (vc->vc_can_do_color)
1097 vc->vc_complement_mask <<= 1;
1100 if (!*svc->vc_uni_pagedir_loc)
1101 con_set_default_unimap(svc);
1102 if (!*vc->vc_uni_pagedir_loc)
1103 con_copy_unimap(vc, svc);
1105 ops = info->fbcon_par;
1106 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1107 if (initial_rotation != -1)
1108 p->con_rotate = initial_rotation;
1110 p->con_rotate = fbcon_platform_get_rotate(info);
1111 set_blitting_type(vc, info);
1115 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1116 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1117 new_cols /= vc->vc_font.width;
1118 new_rows /= vc->vc_font.height;
1121 * We must always set the mode. The mode of the previous console
1122 * driver could be in the same resolution but we are using different
1123 * hardware so we have to initialize the hardware.
1125 * We need to do it in fbcon_init() to prevent screen corruption.
1127 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1128 if (info->fbops->fb_set_par &&
1129 !(ops->flags & FBCON_FLAGS_INIT)) {
1130 ret = info->fbops->fb_set_par(info);
1133 printk(KERN_ERR "fbcon_init: detected "
1134 "unhandled fb_set_par error, "
1135 "error code %d\n", ret);
1138 ops->flags |= FBCON_FLAGS_INIT;
1143 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1144 !(cap & FBINFO_HWACCEL_DISABLED))
1145 p->scrollmode = SCROLL_MOVE;
1146 else /* default to something safe */
1147 p->scrollmode = SCROLL_REDRAW;
1150 * ++guenther: console.c:vc_allocate() relies on initializing
1151 * vc_{cols,rows}, but we must not set those if we are only
1152 * resizing the console.
1155 vc->vc_cols = new_cols;
1156 vc->vc_rows = new_rows;
1158 vc_resize(vc, new_cols, new_rows);
1161 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1163 if (vc == svc && softback_buf)
1164 fbcon_update_softback(vc);
1166 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1167 ops->rotate = FB_ROTATE_UR;
1168 set_blitting_type(vc, info);
1171 ops->p = &fb_display[fg_console];
1174 static void fbcon_free_font(struct display *p, bool freefont)
1176 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1177 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1182 static void set_vc_hi_font(struct vc_data *vc, bool set);
1184 static void fbcon_deinit(struct vc_data *vc)
1186 struct display *p = &fb_display[vc->vc_num];
1187 struct fb_info *info;
1188 struct fbcon_ops *ops;
1190 bool free_font = true;
1192 idx = con2fb_map[vc->vc_num];
1197 info = registered_fb[idx];
1202 if (info->flags & FBINFO_MISC_FIRMWARE)
1204 ops = info->fbcon_par;
1209 if (con_is_visible(vc))
1210 fbcon_del_cursor_timer(info);
1212 ops->flags &= ~FBCON_FLAGS_INIT;
1215 fbcon_free_font(p, free_font);
1217 vc->vc_font.data = NULL;
1219 if (vc->vc_hi_font_mask)
1220 set_vc_hi_font(vc, false);
1222 if (!con_is_bound(&fb_con))
1228 /* ====================================================================== */
1230 /* fbcon_XXX routines - interface used by the world
1232 * This system is now divided into two levels because of complications
1233 * caused by hardware scrolling. Top level functions:
1235 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1237 * handles y values in range [0, scr_height-1] that correspond to real
1238 * screen positions. y_wrap shift means that first line of bitmap may be
1239 * anywhere on this display. These functions convert lineoffsets to
1240 * bitmap offsets and deal with the wrap-around case by splitting blits.
1242 * fbcon_bmove_physical_8() -- These functions fast implementations
1243 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1244 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1248 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1249 * Implies should only really hardware scroll in rows. Only reason for
1250 * restriction is simplicity & efficiency at the moment.
1253 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1256 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1257 struct fbcon_ops *ops = info->fbcon_par;
1259 struct display *p = &fb_display[vc->vc_num];
1262 if (fbcon_is_inactive(vc, info))
1265 if (!height || !width)
1268 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1271 * If the font dimensions are not an integral of the display
1272 * dimensions then the ops->clear below won't end up clearing
1273 * the margins. Call clear_margins here in case the logo
1274 * bitmap stretched into the margin area.
1276 fbcon_clear_margins(vc, 0);
1279 /* Split blits that cross physical y_wrap boundary */
1281 y_break = p->vrows - p->yscroll;
1282 if (sy < y_break && sy + height - 1 >= y_break) {
1283 u_int b = y_break - sy;
1284 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1285 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1288 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1291 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1292 int count, int ypos, int xpos)
1294 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1295 struct display *p = &fb_display[vc->vc_num];
1296 struct fbcon_ops *ops = info->fbcon_par;
1298 if (!fbcon_is_inactive(vc, info))
1299 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1300 get_color(vc, info, scr_readw(s), 1),
1301 get_color(vc, info, scr_readw(s), 0));
1304 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1308 scr_writew(c, &chr);
1309 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1312 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1314 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1315 struct fbcon_ops *ops = info->fbcon_par;
1317 if (!fbcon_is_inactive(vc, info))
1318 ops->clear_margins(vc, info, margin_color, bottom_only);
1321 static void fbcon_cursor(struct vc_data *vc, int mode)
1323 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1324 struct fbcon_ops *ops = info->fbcon_par;
1326 int c = scr_readw((u16 *) vc->vc_pos);
1328 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1330 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1333 if (vc->vc_cursor_type & 0x10)
1334 fbcon_del_cursor_timer(info);
1336 fbcon_add_cursor_timer(info);
1338 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1339 if (mode & CM_SOFTBACK) {
1340 mode &= ~CM_SOFTBACK;
1344 fbcon_set_origin(vc);
1348 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1349 get_color(vc, info, c, 0));
1352 static int scrollback_phys_max = 0;
1353 static int scrollback_max = 0;
1354 static int scrollback_current = 0;
1356 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1359 struct display *p, *t;
1360 struct vc_data **default_mode, *vc;
1361 struct vc_data *svc;
1362 struct fbcon_ops *ops = info->fbcon_par;
1363 int rows, cols, charcnt = 256;
1365 p = &fb_display[unit];
1367 if (var_to_display(p, var, info))
1370 vc = vc_cons[unit].d;
1375 default_mode = vc->vc_display_fg;
1376 svc = *default_mode;
1377 t = &fb_display[svc->vc_num];
1379 if (!vc->vc_font.data) {
1380 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1381 vc->vc_font.width = (*default_mode)->vc_font.width;
1382 vc->vc_font.height = (*default_mode)->vc_font.height;
1383 p->userfont = t->userfont;
1385 REFCOUNT(p->fontdata)++;
1388 charcnt = FNTCHARCNT(p->fontdata);
1390 var->activate = FB_ACTIVATE_NOW;
1391 info->var.activate = var->activate;
1392 var->yoffset = info->var.yoffset;
1393 var->xoffset = info->var.xoffset;
1394 fb_set_var(info, var);
1395 ops->var = info->var;
1396 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1397 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1398 if (charcnt == 256) {
1399 vc->vc_hi_font_mask = 0;
1401 vc->vc_hi_font_mask = 0x100;
1402 if (vc->vc_can_do_color)
1403 vc->vc_complement_mask <<= 1;
1406 if (!*svc->vc_uni_pagedir_loc)
1407 con_set_default_unimap(svc);
1408 if (!*vc->vc_uni_pagedir_loc)
1409 con_copy_unimap(vc, svc);
1411 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1412 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1413 cols /= vc->vc_font.width;
1414 rows /= vc->vc_font.height;
1415 vc_resize(vc, cols, rows);
1417 if (con_is_visible(vc)) {
1420 fbcon_update_softback(vc);
1424 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1426 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1427 struct fbcon_ops *ops = info->fbcon_par;
1428 struct display *p = &fb_display[vc->vc_num];
1430 p->yscroll += count;
1431 if (p->yscroll >= p->vrows) /* Deal with wrap */
1432 p->yscroll -= p->vrows;
1433 ops->var.xoffset = 0;
1434 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1435 ops->var.vmode |= FB_VMODE_YWRAP;
1436 ops->update_start(info);
1437 scrollback_max += count;
1438 if (scrollback_max > scrollback_phys_max)
1439 scrollback_max = scrollback_phys_max;
1440 scrollback_current = 0;
1443 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1445 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1446 struct fbcon_ops *ops = info->fbcon_par;
1447 struct display *p = &fb_display[vc->vc_num];
1449 p->yscroll -= count;
1450 if (p->yscroll < 0) /* Deal with wrap */
1451 p->yscroll += p->vrows;
1452 ops->var.xoffset = 0;
1453 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1454 ops->var.vmode |= FB_VMODE_YWRAP;
1455 ops->update_start(info);
1456 scrollback_max -= count;
1457 if (scrollback_max < 0)
1459 scrollback_current = 0;
1462 static __inline__ void ypan_up(struct vc_data *vc, int count)
1464 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1465 struct display *p = &fb_display[vc->vc_num];
1466 struct fbcon_ops *ops = info->fbcon_par;
1468 p->yscroll += count;
1469 if (p->yscroll > p->vrows - vc->vc_rows) {
1470 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1471 0, 0, 0, vc->vc_rows, vc->vc_cols);
1472 p->yscroll -= p->vrows - vc->vc_rows;
1475 ops->var.xoffset = 0;
1476 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1477 ops->var.vmode &= ~FB_VMODE_YWRAP;
1478 ops->update_start(info);
1479 fbcon_clear_margins(vc, 1);
1480 scrollback_max += count;
1481 if (scrollback_max > scrollback_phys_max)
1482 scrollback_max = scrollback_phys_max;
1483 scrollback_current = 0;
1486 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1488 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1489 struct fbcon_ops *ops = info->fbcon_par;
1490 struct display *p = &fb_display[vc->vc_num];
1492 p->yscroll += count;
1494 if (p->yscroll > p->vrows - vc->vc_rows) {
1495 p->yscroll -= p->vrows - vc->vc_rows;
1496 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1499 ops->var.xoffset = 0;
1500 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1501 ops->var.vmode &= ~FB_VMODE_YWRAP;
1502 ops->update_start(info);
1503 fbcon_clear_margins(vc, 1);
1504 scrollback_max += count;
1505 if (scrollback_max > scrollback_phys_max)
1506 scrollback_max = scrollback_phys_max;
1507 scrollback_current = 0;
1510 static __inline__ void ypan_down(struct vc_data *vc, int count)
1512 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1513 struct display *p = &fb_display[vc->vc_num];
1514 struct fbcon_ops *ops = info->fbcon_par;
1516 p->yscroll -= count;
1517 if (p->yscroll < 0) {
1518 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1519 0, vc->vc_rows, vc->vc_cols);
1520 p->yscroll += p->vrows - vc->vc_rows;
1523 ops->var.xoffset = 0;
1524 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1525 ops->var.vmode &= ~FB_VMODE_YWRAP;
1526 ops->update_start(info);
1527 fbcon_clear_margins(vc, 1);
1528 scrollback_max -= count;
1529 if (scrollback_max < 0)
1531 scrollback_current = 0;
1534 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1536 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1537 struct fbcon_ops *ops = info->fbcon_par;
1538 struct display *p = &fb_display[vc->vc_num];
1540 p->yscroll -= count;
1542 if (p->yscroll < 0) {
1543 p->yscroll += p->vrows - vc->vc_rows;
1544 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1547 ops->var.xoffset = 0;
1548 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1549 ops->var.vmode &= ~FB_VMODE_YWRAP;
1550 ops->update_start(info);
1551 fbcon_clear_margins(vc, 1);
1552 scrollback_max -= count;
1553 if (scrollback_max < 0)
1555 scrollback_current = 0;
1558 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1561 int count = vc->vc_rows;
1562 unsigned short *d, *s;
1566 d = (u16 *) softback_curr;
1567 if (d == (u16 *) softback_in)
1568 d = (u16 *) vc->vc_origin;
1569 n = softback_curr + delta * vc->vc_size_row;
1570 softback_lines -= delta;
1572 if (softback_curr < softback_top && n < softback_buf) {
1573 n += softback_end - softback_buf;
1574 if (n < softback_top) {
1576 (softback_top - n) / vc->vc_size_row;
1579 } else if (softback_curr >= softback_top
1580 && n < softback_top) {
1582 (softback_top - n) / vc->vc_size_row;
1586 if (softback_curr > softback_in && n >= softback_end) {
1587 n += softback_buf - softback_end;
1588 if (n > softback_in) {
1592 } else if (softback_curr <= softback_in && n > softback_in) {
1597 if (n == softback_curr)
1600 s = (u16 *) softback_curr;
1601 if (s == (u16 *) softback_in)
1602 s = (u16 *) vc->vc_origin;
1604 unsigned short *start;
1608 unsigned short attr = 1;
1611 le = advance_row(s, 1);
1614 if (attr != (c & 0xff00)) {
1617 fbcon_putcs(vc, start, s - start,
1623 if (c == scr_readw(d)) {
1625 fbcon_putcs(vc, start, s - start,
1638 fbcon_putcs(vc, start, s - start, line, x);
1640 if (d == (u16 *) softback_end)
1641 d = (u16 *) softback_buf;
1642 if (d == (u16 *) softback_in)
1643 d = (u16 *) vc->vc_origin;
1644 if (s == (u16 *) softback_end)
1645 s = (u16 *) softback_buf;
1646 if (s == (u16 *) softback_in)
1647 s = (u16 *) vc->vc_origin;
1651 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1652 int line, int count, int dy)
1654 unsigned short *s = (unsigned short *)
1655 (vc->vc_origin + vc->vc_size_row * line);
1658 unsigned short *start = s;
1659 unsigned short *le = advance_row(s, 1);
1662 unsigned short attr = 1;
1666 if (attr != (c & 0xff00)) {
1669 fbcon_putcs(vc, start, s - start,
1675 console_conditional_schedule();
1679 fbcon_putcs(vc, start, s - start, dy, x);
1680 console_conditional_schedule();
1685 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1686 struct display *p, int line, int count, int ycount)
1688 int offset = ycount * vc->vc_cols;
1689 unsigned short *d = (unsigned short *)
1690 (vc->vc_origin + vc->vc_size_row * line);
1691 unsigned short *s = d + offset;
1692 struct fbcon_ops *ops = info->fbcon_par;
1695 unsigned short *start = s;
1696 unsigned short *le = advance_row(s, 1);
1703 if (c == scr_readw(d)) {
1705 ops->bmove(vc, info, line + ycount, x,
1706 line, x, 1, s-start);
1716 console_conditional_schedule();
1721 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1723 console_conditional_schedule();
1728 /* NOTE: We subtract two lines from these pointers */
1729 s -= vc->vc_size_row;
1730 d -= vc->vc_size_row;
1735 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1736 int line, int count, int offset)
1738 unsigned short *d = (unsigned short *)
1739 (vc->vc_origin + vc->vc_size_row * line);
1740 unsigned short *s = d + offset;
1743 unsigned short *start = s;
1744 unsigned short *le = advance_row(s, 1);
1747 unsigned short attr = 1;
1751 if (attr != (c & 0xff00)) {
1754 fbcon_putcs(vc, start, s - start,
1760 if (c == scr_readw(d)) {
1762 fbcon_putcs(vc, start, s - start,
1772 console_conditional_schedule();
1777 fbcon_putcs(vc, start, s - start, line, x);
1778 console_conditional_schedule();
1783 /* NOTE: We subtract two lines from these pointers */
1784 s -= vc->vc_size_row;
1785 d -= vc->vc_size_row;
1790 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1795 if (vc->vc_num != fg_console)
1797 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1800 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1802 p = advance_row(p, 1);
1803 softback_in += vc->vc_size_row;
1804 if (softback_in == softback_end)
1805 softback_in = softback_buf;
1806 if (softback_in == softback_top) {
1807 softback_top += vc->vc_size_row;
1808 if (softback_top == softback_end)
1809 softback_top = softback_buf;
1812 softback_curr = softback_in;
1815 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1816 enum con_scroll dir, unsigned int count)
1818 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1819 struct display *p = &fb_display[vc->vc_num];
1820 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1822 if (fbcon_is_inactive(vc, info))
1825 fbcon_cursor(vc, CM_ERASE);
1828 * ++Geert: Only use ywrap/ypan if the console is in text mode
1829 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1830 * whole screen (prevents flicker).
1835 if (count > vc->vc_rows) /* Maximum realistic size */
1836 count = vc->vc_rows;
1838 fbcon_softback_note(vc, t, count);
1839 if (logo_shown >= 0)
1841 switch (p->scrollmode) {
1843 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1845 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1846 scr_memsetw((unsigned short *) (vc->vc_origin +
1849 vc->vc_video_erase_char,
1850 vc->vc_size_row * count);
1854 case SCROLL_WRAP_MOVE:
1855 if (b - t - count > 3 * vc->vc_rows >> 2) {
1857 fbcon_bmove(vc, 0, 0, count, 0, t,
1859 ywrap_up(vc, count);
1860 if (vc->vc_rows - b > 0)
1861 fbcon_bmove(vc, b - count, 0, b, 0,
1864 } else if (info->flags & FBINFO_READS_FAST)
1865 fbcon_bmove(vc, t + count, 0, t, 0,
1866 b - t - count, vc->vc_cols);
1869 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1872 case SCROLL_PAN_REDRAW:
1873 if ((p->yscroll + count <=
1874 2 * (p->vrows - vc->vc_rows))
1875 && ((!scroll_partial && (b - t == vc->vc_rows))
1878 3 * vc->vc_rows >> 2)))) {
1880 fbcon_redraw_move(vc, p, 0, t, count);
1881 ypan_up_redraw(vc, t, count);
1882 if (vc->vc_rows - b > 0)
1883 fbcon_redraw_move(vc, p, b,
1884 vc->vc_rows - b, b);
1886 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1887 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1890 case SCROLL_PAN_MOVE:
1891 if ((p->yscroll + count <=
1892 2 * (p->vrows - vc->vc_rows))
1893 && ((!scroll_partial && (b - t == vc->vc_rows))
1896 3 * vc->vc_rows >> 2)))) {
1898 fbcon_bmove(vc, 0, 0, count, 0, t,
1901 if (vc->vc_rows - b > 0)
1902 fbcon_bmove(vc, b - count, 0, b, 0,
1905 } else if (info->flags & FBINFO_READS_FAST)
1906 fbcon_bmove(vc, t + count, 0, t, 0,
1907 b - t - count, vc->vc_cols);
1910 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1915 fbcon_redraw(vc, p, t, b - t - count,
1916 count * vc->vc_cols);
1917 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1918 scr_memsetw((unsigned short *) (vc->vc_origin +
1921 vc->vc_video_erase_char,
1922 vc->vc_size_row * count);
1928 if (count > vc->vc_rows) /* Maximum realistic size */
1929 count = vc->vc_rows;
1930 if (logo_shown >= 0)
1932 switch (p->scrollmode) {
1934 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1936 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1937 scr_memsetw((unsigned short *) (vc->vc_origin +
1940 vc->vc_video_erase_char,
1941 vc->vc_size_row * count);
1945 case SCROLL_WRAP_MOVE:
1946 if (b - t - count > 3 * vc->vc_rows >> 2) {
1947 if (vc->vc_rows - b > 0)
1948 fbcon_bmove(vc, b, 0, b - count, 0,
1951 ywrap_down(vc, count);
1953 fbcon_bmove(vc, count, 0, 0, 0, t,
1955 } else if (info->flags & FBINFO_READS_FAST)
1956 fbcon_bmove(vc, t, 0, t + count, 0,
1957 b - t - count, vc->vc_cols);
1960 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1963 case SCROLL_PAN_MOVE:
1964 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1965 && ((!scroll_partial && (b - t == vc->vc_rows))
1968 3 * vc->vc_rows >> 2)))) {
1969 if (vc->vc_rows - b > 0)
1970 fbcon_bmove(vc, b, 0, b - count, 0,
1973 ypan_down(vc, count);
1975 fbcon_bmove(vc, count, 0, 0, 0, t,
1977 } else if (info->flags & FBINFO_READS_FAST)
1978 fbcon_bmove(vc, t, 0, t + count, 0,
1979 b - t - count, vc->vc_cols);
1982 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1985 case SCROLL_PAN_REDRAW:
1986 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1987 && ((!scroll_partial && (b - t == vc->vc_rows))
1990 3 * vc->vc_rows >> 2)))) {
1991 if (vc->vc_rows - b > 0)
1992 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1994 ypan_down_redraw(vc, t, count);
1996 fbcon_redraw_move(vc, p, count, t, 0);
1998 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1999 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2004 fbcon_redraw(vc, p, b - 1, b - t - count,
2005 -count * vc->vc_cols);
2006 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2007 scr_memsetw((unsigned short *) (vc->vc_origin +
2010 vc->vc_video_erase_char,
2011 vc->vc_size_row * count);
2019 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2020 int height, int width)
2022 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2023 struct display *p = &fb_display[vc->vc_num];
2025 if (fbcon_is_inactive(vc, info))
2028 if (!width || !height)
2031 /* Split blits that cross physical y_wrap case.
2032 * Pathological case involves 4 blits, better to use recursive
2033 * code rather than unrolled case
2035 * Recursive invocations don't need to erase the cursor over and
2036 * over again, so we use fbcon_bmove_rec()
2038 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2039 p->vrows - p->yscroll);
2042 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2043 int dy, int dx, int height, int width, u_int y_break)
2045 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2046 struct fbcon_ops *ops = info->fbcon_par;
2049 if (sy < y_break && sy + height > y_break) {
2051 if (dy < sy) { /* Avoid trashing self */
2052 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2054 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2055 height - b, width, y_break);
2057 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2058 height - b, width, y_break);
2059 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2065 if (dy < y_break && dy + height > y_break) {
2067 if (dy < sy) { /* Avoid trashing self */
2068 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2070 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2071 height - b, width, y_break);
2073 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2074 height - b, width, y_break);
2075 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2080 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2084 static void updatescrollmode(struct display *p,
2085 struct fb_info *info,
2088 struct fbcon_ops *ops = info->fbcon_par;
2089 int fh = vc->vc_font.height;
2090 int cap = info->flags;
2092 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2093 info->fix.xpanstep);
2094 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2095 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2096 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2097 info->var.xres_virtual);
2098 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2099 divides(ypan, vc->vc_font.height) && vyres > yres;
2100 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2101 divides(ywrap, vc->vc_font.height) &&
2102 divides(vc->vc_font.height, vyres) &&
2103 divides(vc->vc_font.height, yres);
2104 int reading_fast = cap & FBINFO_READS_FAST;
2105 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2106 !(cap & FBINFO_HWACCEL_DISABLED);
2107 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2108 !(cap & FBINFO_HWACCEL_DISABLED);
2110 p->vrows = vyres/fh;
2111 if (yres > (fh * (vc->vc_rows + 1)))
2112 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2113 if ((yres % fh) && (vyres % fh < yres % fh))
2116 if (good_wrap || good_pan) {
2117 if (reading_fast || fast_copyarea)
2118 p->scrollmode = good_wrap ?
2119 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2121 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2124 if (reading_fast || (fast_copyarea && !fast_imageblit))
2125 p->scrollmode = SCROLL_MOVE;
2127 p->scrollmode = SCROLL_REDRAW;
2131 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2132 unsigned int height, unsigned int user)
2134 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2135 struct fbcon_ops *ops = info->fbcon_par;
2136 struct display *p = &fb_display[vc->vc_num];
2137 struct fb_var_screeninfo var = info->var;
2138 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2140 virt_w = FBCON_SWAP(ops->rotate, width, height);
2141 virt_h = FBCON_SWAP(ops->rotate, height, width);
2142 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2143 vc->vc_font.height);
2144 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2146 var.xres = virt_w * virt_fw;
2147 var.yres = virt_h * virt_fh;
2148 x_diff = info->var.xres - var.xres;
2149 y_diff = info->var.yres - var.yres;
2150 if (x_diff < 0 || x_diff > virt_fw ||
2151 y_diff < 0 || y_diff > virt_fh) {
2152 const struct fb_videomode *mode;
2154 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2155 mode = fb_find_best_mode(&var, &info->modelist);
2158 display_to_var(&var, p);
2159 fb_videomode_to_var(&var, mode);
2161 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2164 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2165 if (con_is_visible(vc)) {
2166 var.activate = FB_ACTIVATE_NOW |
2168 fb_set_var(info, &var);
2170 var_to_display(p, &info->var, info);
2171 ops->var = info->var;
2173 updatescrollmode(p, info, vc);
2177 static int fbcon_switch(struct vc_data *vc)
2179 struct fb_info *info, *old_info = NULL;
2180 struct fbcon_ops *ops;
2181 struct display *p = &fb_display[vc->vc_num];
2182 struct fb_var_screeninfo var;
2183 int i, ret, prev_console, charcnt = 256;
2185 info = registered_fb[con2fb_map[vc->vc_num]];
2186 ops = info->fbcon_par;
2190 fbcon_set_origin(vc);
2191 softback_top = softback_curr = softback_in = softback_buf;
2193 fbcon_update_softback(vc);
2196 if (logo_shown >= 0) {
2197 struct vc_data *conp2 = vc_cons[logo_shown].d;
2199 if (conp2->vc_top == logo_lines
2200 && conp2->vc_bottom == conp2->vc_rows)
2202 logo_shown = FBCON_LOGO_CANSHOW;
2205 prev_console = ops->currcon;
2206 if (prev_console != -1)
2207 old_info = registered_fb[con2fb_map[prev_console]];
2209 * FIXME: If we have multiple fbdev's loaded, we need to
2210 * update all info->currcon. Perhaps, we can place this
2211 * in a centralized structure, but this might break some
2214 * info->currcon = vc->vc_num;
2216 for (i = 0; i < FB_MAX; i++) {
2217 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2218 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2220 o->currcon = vc->vc_num;
2223 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2224 display_to_var(&var, p);
2225 var.activate = FB_ACTIVATE_NOW;
2228 * make sure we don't unnecessarily trip the memcmp()
2231 info->var.activate = var.activate;
2232 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2233 fb_set_var(info, &var);
2234 ops->var = info->var;
2236 if (old_info != NULL && (old_info != info ||
2237 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2238 if (info->fbops->fb_set_par) {
2239 ret = info->fbops->fb_set_par(info);
2242 printk(KERN_ERR "fbcon_switch: detected "
2243 "unhandled fb_set_par error, "
2244 "error code %d\n", ret);
2247 if (old_info != info)
2248 fbcon_del_cursor_timer(old_info);
2251 if (fbcon_is_inactive(vc, info) ||
2252 ops->blank_state != FB_BLANK_UNBLANK)
2253 fbcon_del_cursor_timer(info);
2255 fbcon_add_cursor_timer(info);
2257 set_blitting_type(vc, info);
2258 ops->cursor_reset = 1;
2260 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2261 ops->rotate = FB_ROTATE_UR;
2262 set_blitting_type(vc, info);
2265 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2266 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2269 charcnt = FNTCHARCNT(vc->vc_font.data);
2272 vc->vc_complement_mask <<= 1;
2274 updatescrollmode(p, info, vc);
2276 switch (p->scrollmode) {
2277 case SCROLL_WRAP_MOVE:
2278 scrollback_phys_max = p->vrows - vc->vc_rows;
2280 case SCROLL_PAN_MOVE:
2281 case SCROLL_PAN_REDRAW:
2282 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2283 if (scrollback_phys_max < 0)
2284 scrollback_phys_max = 0;
2287 scrollback_phys_max = 0;
2292 scrollback_current = 0;
2294 if (!fbcon_is_inactive(vc, info)) {
2295 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2296 ops->update_start(info);
2299 fbcon_set_palette(vc, color_table);
2300 fbcon_clear_margins(vc, 0);
2302 if (logo_shown == FBCON_LOGO_DRAW) {
2304 logo_shown = fg_console;
2305 /* This is protected above by initmem_freed */
2306 fb_show_logo(info, ops->rotate);
2308 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2309 vc->vc_size_row * (vc->vc_bottom -
2316 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2319 struct fb_event event;
2322 unsigned short charmask = vc->vc_hi_font_mask ?
2324 unsigned short oldc;
2326 oldc = vc->vc_video_erase_char;
2327 vc->vc_video_erase_char &= charmask;
2328 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2329 vc->vc_video_erase_char = oldc;
2333 if (!lock_fb_info(info))
2336 event.data = ␣
2337 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2338 unlock_fb_info(info);
2341 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2343 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2344 struct fbcon_ops *ops = info->fbcon_par;
2347 struct fb_var_screeninfo var = info->var;
2352 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2353 fb_set_var(info, &var);
2355 ops->var = info->var;
2359 if (!fbcon_is_inactive(vc, info)) {
2360 if (ops->blank_state != blank) {
2361 ops->blank_state = blank;
2362 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2363 ops->cursor_flash = (!blank);
2365 if (!(info->flags & FBINFO_MISC_USEREVENT))
2366 if (fb_blank(info, blank))
2367 fbcon_generic_blank(vc, info, blank);
2374 if (mode_switch || fbcon_is_inactive(vc, info) ||
2375 ops->blank_state != FB_BLANK_UNBLANK)
2376 fbcon_del_cursor_timer(info);
2378 fbcon_add_cursor_timer(info);
2383 static int fbcon_debug_enter(struct vc_data *vc)
2385 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2386 struct fbcon_ops *ops = info->fbcon_par;
2388 ops->save_graphics = ops->graphics;
2390 if (info->fbops->fb_debug_enter)
2391 info->fbops->fb_debug_enter(info);
2392 fbcon_set_palette(vc, color_table);
2396 static int fbcon_debug_leave(struct vc_data *vc)
2398 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2399 struct fbcon_ops *ops = info->fbcon_par;
2401 ops->graphics = ops->save_graphics;
2402 if (info->fbops->fb_debug_leave)
2403 info->fbops->fb_debug_leave(info);
2407 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2409 u8 *fontdata = vc->vc_font.data;
2410 u8 *data = font->data;
2413 font->width = vc->vc_font.width;
2414 font->height = vc->vc_font.height;
2415 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2419 if (font->width <= 8) {
2420 j = vc->vc_font.height;
2421 for (i = 0; i < font->charcount; i++) {
2422 memcpy(data, fontdata, j);
2423 memset(data + j, 0, 32 - j);
2427 } else if (font->width <= 16) {
2428 j = vc->vc_font.height * 2;
2429 for (i = 0; i < font->charcount; i++) {
2430 memcpy(data, fontdata, j);
2431 memset(data + j, 0, 64 - j);
2435 } else if (font->width <= 24) {
2436 for (i = 0; i < font->charcount; i++) {
2437 for (j = 0; j < vc->vc_font.height; j++) {
2438 *data++ = fontdata[0];
2439 *data++ = fontdata[1];
2440 *data++ = fontdata[2];
2441 fontdata += sizeof(u32);
2443 memset(data, 0, 3 * (32 - j));
2444 data += 3 * (32 - j);
2447 j = vc->vc_font.height * 4;
2448 for (i = 0; i < font->charcount; i++) {
2449 memcpy(data, fontdata, j);
2450 memset(data + j, 0, 128 - j);
2458 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2459 static void set_vc_hi_font(struct vc_data *vc, bool set)
2462 vc->vc_hi_font_mask = 0;
2463 if (vc->vc_can_do_color) {
2464 vc->vc_complement_mask >>= 1;
2465 vc->vc_s_complement_mask >>= 1;
2468 /* ++Edmund: reorder the attribute bits */
2469 if (vc->vc_can_do_color) {
2470 unsigned short *cp =
2471 (unsigned short *) vc->vc_origin;
2472 int count = vc->vc_screenbuf_size / 2;
2474 for (; count > 0; count--, cp++) {
2476 scr_writew(((c & 0xfe00) >> 1) |
2479 c = vc->vc_video_erase_char;
2480 vc->vc_video_erase_char =
2481 ((c & 0xfe00) >> 1) | (c & 0xff);
2485 vc->vc_hi_font_mask = 0x100;
2486 if (vc->vc_can_do_color) {
2487 vc->vc_complement_mask <<= 1;
2488 vc->vc_s_complement_mask <<= 1;
2491 /* ++Edmund: reorder the attribute bits */
2493 unsigned short *cp =
2494 (unsigned short *) vc->vc_origin;
2495 int count = vc->vc_screenbuf_size / 2;
2497 for (; count > 0; count--, cp++) {
2498 unsigned short newc;
2500 if (vc->vc_can_do_color)
2502 ((c & 0xff00) << 1) | (c &
2506 scr_writew(newc, cp);
2508 c = vc->vc_video_erase_char;
2509 if (vc->vc_can_do_color) {
2510 vc->vc_video_erase_char =
2511 ((c & 0xff00) << 1) | (c & 0xff);
2514 vc->vc_video_erase_char = c & ~0x100;
2519 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2520 const u8 * data, int userfont)
2522 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2523 struct fbcon_ops *ops = info->fbcon_par;
2524 struct display *p = &fb_display[vc->vc_num];
2527 char *old_data = NULL;
2529 if (con_is_visible(vc) && softback_lines)
2530 fbcon_set_origin(vc);
2532 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2534 old_data = vc->vc_font.data;
2536 cnt = FNTCHARCNT(data);
2539 vc->vc_font.data = (void *)(p->fontdata = data);
2540 if ((p->userfont = userfont))
2542 vc->vc_font.width = w;
2543 vc->vc_font.height = h;
2544 if (vc->vc_hi_font_mask && cnt == 256)
2545 set_vc_hi_font(vc, false);
2546 else if (!vc->vc_hi_font_mask && cnt == 512)
2547 set_vc_hi_font(vc, true);
2552 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2553 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2556 vc_resize(vc, cols, rows);
2557 if (con_is_visible(vc) && softback_buf)
2558 fbcon_update_softback(vc);
2559 } else if (con_is_visible(vc)
2560 && vc->vc_mode == KD_TEXT) {
2561 fbcon_clear_margins(vc, 0);
2565 if (old_data && (--REFCOUNT(old_data) == 0))
2566 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2570 static int fbcon_copy_font(struct vc_data *vc, int con)
2572 struct display *od = &fb_display[con];
2573 struct console_font *f = &vc->vc_font;
2575 if (od->fontdata == f->data)
2576 return 0; /* already the same font... */
2577 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2581 * User asked to set font; we are guaranteed that
2582 * a) width and height are in range 1..32
2583 * b) charcount does not exceed 512
2584 * but lets not assume that, since someone might someday want to use larger
2585 * fonts. And charcount of 512 is small for unicode support.
2587 * However, user space gives the font in 32 rows , regardless of
2588 * actual font height. So a new API is needed if support for larger fonts
2589 * is ever implemented.
2592 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2594 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2595 unsigned charcount = font->charcount;
2596 int w = font->width;
2597 int h = font->height;
2600 u8 *new_data, *data = font->data;
2601 int pitch = (font->width+7) >> 3;
2603 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2604 * If not this check should be changed to charcount < 256 */
2605 if (charcount != 256 && charcount != 512)
2608 /* Make sure drawing engine can handle the font */
2609 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2610 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2613 /* Make sure driver can handle the font length */
2614 if (fbcon_invalid_charcount(info, charcount))
2617 size = h * pitch * charcount;
2619 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2624 new_data += FONT_EXTRA_WORDS * sizeof(int);
2625 FNTSIZE(new_data) = size;
2626 FNTCHARCNT(new_data) = charcount;
2627 REFCOUNT(new_data) = 0; /* usage counter */
2628 for (i=0; i< charcount; i++) {
2629 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2632 /* Since linux has a nice crc32 function use it for counting font
2634 csum = crc32(0, new_data, size);
2636 FNTSUM(new_data) = csum;
2637 /* Check if the same font is on some other console already */
2638 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2639 struct vc_data *tmp = vc_cons[i].d;
2641 if (fb_display[i].userfont &&
2642 fb_display[i].fontdata &&
2643 FNTSUM(fb_display[i].fontdata) == csum &&
2644 FNTSIZE(fb_display[i].fontdata) == size &&
2645 tmp->vc_font.width == w &&
2646 !memcmp(fb_display[i].fontdata, new_data, size)) {
2647 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2648 new_data = (u8 *)fb_display[i].fontdata;
2652 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2655 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2657 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2658 const struct font_desc *f;
2661 f = get_default_font(info->var.xres, info->var.yres,
2662 info->pixmap.blit_x, info->pixmap.blit_y);
2663 else if (!(f = find_font(name)))
2666 font->width = f->width;
2667 font->height = f->height;
2668 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2671 static u16 palette_red[16];
2672 static u16 palette_green[16];
2673 static u16 palette_blue[16];
2675 static struct fb_cmap palette_cmap = {
2676 0, 16, palette_red, palette_green, palette_blue, NULL
2679 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2681 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2685 if (fbcon_is_inactive(vc, info))
2688 if (!con_is_visible(vc))
2691 depth = fb_get_color_depth(&info->var, &info->fix);
2693 for (i = j = 0; i < 16; i++) {
2695 val = vc->vc_palette[j++];
2696 palette_red[k] = (val << 8) | val;
2697 val = vc->vc_palette[j++];
2698 palette_green[k] = (val << 8) | val;
2699 val = vc->vc_palette[j++];
2700 palette_blue[k] = (val << 8) | val;
2702 palette_cmap.len = 16;
2703 palette_cmap.start = 0;
2705 * If framebuffer is capable of less than 16 colors,
2706 * use default palette of fbcon.
2709 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2711 fb_set_cmap(&palette_cmap, info);
2714 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2719 if (vc->vc_num != fg_console || !softback_lines)
2720 return (u16 *) (vc->vc_origin + offset);
2721 line = offset / vc->vc_size_row;
2722 if (line >= softback_lines)
2723 return (u16 *) (vc->vc_origin + offset -
2724 softback_lines * vc->vc_size_row);
2725 p = softback_curr + offset;
2726 if (p >= softback_end)
2727 p += softback_buf - softback_end;
2731 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2737 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2738 unsigned long offset = (pos - vc->vc_origin) / 2;
2740 x = offset % vc->vc_cols;
2741 y = offset / vc->vc_cols;
2742 if (vc->vc_num == fg_console)
2743 y += softback_lines;
2744 ret = pos + (vc->vc_cols - x) * 2;
2745 } else if (vc->vc_num == fg_console && softback_lines) {
2746 unsigned long offset = pos - softback_curr;
2748 if (pos < softback_curr)
2749 offset += softback_end - softback_buf;
2751 x = offset % vc->vc_cols;
2752 y = offset / vc->vc_cols;
2753 ret = pos + (vc->vc_cols - x) * 2;
2754 if (ret == softback_end)
2756 if (ret == softback_in)
2757 ret = vc->vc_origin;
2759 /* Should not happen */
2761 ret = vc->vc_origin;
2770 /* As we might be inside of softback, we may work with non-contiguous buffer,
2771 that's why we have to use a separate routine. */
2772 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2775 u16 a = scr_readw(p);
2776 if (!vc->vc_can_do_color)
2778 else if (vc->vc_hi_font_mask == 0x100)
2779 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2780 (((a) & 0x0e00) << 4);
2782 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2783 (((a) & 0x0700) << 4);
2785 if (p == (u16 *) softback_end)
2786 p = (u16 *) softback_buf;
2787 if (p == (u16 *) softback_in)
2788 p = (u16 *) vc->vc_origin;
2792 static void fbcon_scrolldelta(struct vc_data *vc, int lines)
2794 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2795 struct fbcon_ops *ops = info->fbcon_par;
2796 struct display *disp = &fb_display[fg_console];
2797 int offset, limit, scrollback_old;
2800 if (vc->vc_num != fg_console)
2802 if (vc->vc_mode != KD_TEXT || !lines)
2804 if (logo_shown >= 0) {
2805 struct vc_data *conp2 = vc_cons[logo_shown].d;
2807 if (conp2->vc_top == logo_lines
2808 && conp2->vc_bottom == conp2->vc_rows)
2810 if (logo_shown == vc->vc_num) {
2816 logo_lines * vc->vc_size_row;
2817 for (i = 0; i < logo_lines; i++) {
2818 if (p == softback_top)
2820 if (p == softback_buf)
2822 p -= vc->vc_size_row;
2823 q -= vc->vc_size_row;
2824 scr_memcpyw((u16 *) q, (u16 *) p,
2827 softback_in = softback_curr = p;
2828 update_region(vc, vc->vc_origin,
2829 logo_lines * vc->vc_cols);
2831 logo_shown = FBCON_LOGO_CANSHOW;
2833 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2834 fbcon_redraw_softback(vc, disp, lines);
2835 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2839 if (!scrollback_phys_max)
2842 scrollback_old = scrollback_current;
2843 scrollback_current -= lines;
2844 if (scrollback_current < 0)
2845 scrollback_current = 0;
2846 else if (scrollback_current > scrollback_max)
2847 scrollback_current = scrollback_max;
2848 if (scrollback_current == scrollback_old)
2851 if (fbcon_is_inactive(vc, info))
2854 fbcon_cursor(vc, CM_ERASE);
2856 offset = disp->yscroll - scrollback_current;
2857 limit = disp->vrows;
2858 switch (disp->scrollmode) {
2859 case SCROLL_WRAP_MOVE:
2860 info->var.vmode |= FB_VMODE_YWRAP;
2862 case SCROLL_PAN_MOVE:
2863 case SCROLL_PAN_REDRAW:
2864 limit -= vc->vc_rows;
2865 info->var.vmode &= ~FB_VMODE_YWRAP;
2870 else if (offset >= limit)
2873 ops->var.xoffset = 0;
2874 ops->var.yoffset = offset * vc->vc_font.height;
2875 ops->update_start(info);
2877 if (!scrollback_current)
2878 fbcon_cursor(vc, CM_DRAW);
2881 static int fbcon_set_origin(struct vc_data *vc)
2884 fbcon_scrolldelta(vc, softback_lines);
2888 static void fbcon_suspended(struct fb_info *info)
2890 struct vc_data *vc = NULL;
2891 struct fbcon_ops *ops = info->fbcon_par;
2893 if (!ops || ops->currcon < 0)
2895 vc = vc_cons[ops->currcon].d;
2897 /* Clear cursor, restore saved data */
2898 fbcon_cursor(vc, CM_ERASE);
2901 static void fbcon_resumed(struct fb_info *info)
2904 struct fbcon_ops *ops = info->fbcon_par;
2906 if (!ops || ops->currcon < 0)
2908 vc = vc_cons[ops->currcon].d;
2913 static void fbcon_modechanged(struct fb_info *info)
2915 struct fbcon_ops *ops = info->fbcon_par;
2920 if (!ops || ops->currcon < 0)
2922 vc = vc_cons[ops->currcon].d;
2923 if (vc->vc_mode != KD_TEXT ||
2924 registered_fb[con2fb_map[ops->currcon]] != info)
2927 p = &fb_display[vc->vc_num];
2928 set_blitting_type(vc, info);
2930 if (con_is_visible(vc)) {
2931 var_to_display(p, &info->var, info);
2932 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2933 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2934 cols /= vc->vc_font.width;
2935 rows /= vc->vc_font.height;
2936 vc_resize(vc, cols, rows);
2937 updatescrollmode(p, info, vc);
2939 scrollback_current = 0;
2941 if (!fbcon_is_inactive(vc, info)) {
2942 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2943 ops->update_start(info);
2946 fbcon_set_palette(vc, color_table);
2949 fbcon_update_softback(vc);
2953 static void fbcon_set_all_vcs(struct fb_info *info)
2955 struct fbcon_ops *ops = info->fbcon_par;
2958 int i, rows, cols, fg = -1;
2960 if (!ops || ops->currcon < 0)
2963 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2965 if (!vc || vc->vc_mode != KD_TEXT ||
2966 registered_fb[con2fb_map[i]] != info)
2969 if (con_is_visible(vc)) {
2974 p = &fb_display[vc->vc_num];
2975 set_blitting_type(vc, info);
2976 var_to_display(p, &info->var, info);
2977 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2978 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2979 cols /= vc->vc_font.width;
2980 rows /= vc->vc_font.height;
2981 vc_resize(vc, cols, rows);
2985 fbcon_modechanged(info);
2988 static int fbcon_mode_deleted(struct fb_info *info,
2989 struct fb_videomode *mode)
2991 struct fb_info *fb_info;
2993 int i, j, found = 0;
2995 /* before deletion, ensure that mode is not in use */
2996 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3000 fb_info = registered_fb[j];
3001 if (fb_info != info)
3006 if (fb_mode_is_equal(p->mode, mode)) {
3014 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3015 static int fbcon_unbind(void)
3019 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3023 fbcon_has_console_bind = 0;
3028 static inline int fbcon_unbind(void)
3032 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3034 /* called with console_lock held */
3035 static int fbcon_fb_unbind(int idx)
3037 int i, new_idx = -1, ret = 0;
3039 if (!fbcon_has_console_bind)
3042 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3043 if (con2fb_map[i] != idx &&
3044 con2fb_map[i] != -1) {
3050 if (new_idx != -1) {
3051 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3052 if (con2fb_map[i] == idx)
3053 set_con2fb_map(i, new_idx, 0);
3056 struct fb_info *info = registered_fb[idx];
3058 /* This is sort of like set_con2fb_map, except it maps
3059 * the consoles to no device and then releases the
3060 * oldinfo to free memory and cancel the cursor blink
3061 * timer. I can imagine this just becoming part of
3062 * set_con2fb_map where new_idx is -1
3064 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3065 if (con2fb_map[i] == idx) {
3067 if (!search_fb_in_map(idx)) {
3068 ret = con2fb_release_oldinfo(vc_cons[i].d,
3072 con2fb_map[i] = idx;
3078 ret = fbcon_unbind();
3084 /* called with console_lock held */
3085 static int fbcon_fb_unregistered(struct fb_info *info)
3090 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3091 if (con2fb_map[i] == idx)
3095 if (idx == info_idx) {
3098 for (i = 0; i < FB_MAX; i++) {
3099 if (registered_fb[i] != NULL) {
3106 if (info_idx != -1) {
3107 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3108 if (con2fb_map[i] == -1)
3109 con2fb_map[i] = info_idx;
3113 if (primary_device == idx)
3114 primary_device = -1;
3116 if (!num_registered_fb)
3117 do_unregister_con_driver(&fb_con);
3122 /* called with console_lock held */
3123 static void fbcon_remap_all(int idx)
3126 for (i = first_fb_vc; i <= last_fb_vc; i++)
3127 set_con2fb_map(i, idx, 0);
3129 if (con_is_bound(&fb_con)) {
3130 printk(KERN_INFO "fbcon: Remapping primary device, "
3131 "fb%i, to tty %i-%i\n", idx,
3132 first_fb_vc + 1, last_fb_vc + 1);
3137 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3138 static void fbcon_select_primary(struct fb_info *info)
3140 if (!map_override && primary_device == -1 &&
3141 fb_is_primary_device(info)) {
3144 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3145 info->fix.id, info->node);
3146 primary_device = info->node;
3148 for (i = first_fb_vc; i <= last_fb_vc; i++)
3149 con2fb_map_boot[i] = primary_device;
3151 if (con_is_bound(&fb_con)) {
3152 printk(KERN_INFO "fbcon: Remapping primary device, "
3153 "fb%i, to tty %i-%i\n", info->node,
3154 first_fb_vc + 1, last_fb_vc + 1);
3155 info_idx = primary_device;
3161 static inline void fbcon_select_primary(struct fb_info *info)
3165 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3167 /* called with console_lock held */
3168 static int fbcon_fb_registered(struct fb_info *info)
3170 int ret = 0, i, idx;
3173 fbcon_select_primary(info);
3175 if (info_idx == -1) {
3176 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3177 if (con2fb_map_boot[i] == idx) {
3184 ret = do_fbcon_takeover(1);
3186 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3187 if (con2fb_map_boot[i] == idx)
3188 set_con2fb_map(i, idx, 0);
3195 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3197 struct fbcon_ops *ops = info->fbcon_par;
3200 if (!ops || ops->currcon < 0)
3203 vc = vc_cons[ops->currcon].d;
3204 if (vc->vc_mode != KD_TEXT ||
3205 registered_fb[con2fb_map[ops->currcon]] != info)
3208 if (con_is_visible(vc)) {
3212 do_unblank_screen(0);
3214 ops->blank_state = blank;
3217 static void fbcon_new_modelist(struct fb_info *info)
3221 struct fb_var_screeninfo var;
3222 const struct fb_videomode *mode;
3224 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3225 if (registered_fb[con2fb_map[i]] != info)
3227 if (!fb_display[i].mode)
3230 display_to_var(&var, &fb_display[i]);
3231 mode = fb_find_nearest_mode(fb_display[i].mode,
3233 fb_videomode_to_var(&var, mode);
3234 fbcon_set_disp(info, &var, vc->vc_num);
3238 static void fbcon_get_requirement(struct fb_info *info,
3239 struct fb_blit_caps *caps)
3247 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3249 if (vc && vc->vc_mode == KD_TEXT &&
3250 info->node == con2fb_map[i]) {
3252 caps->x |= 1 << (vc->vc_font.width - 1);
3253 caps->y |= 1 << (vc->vc_font.height - 1);
3254 charcnt = (p->userfont) ?
3255 FNTCHARCNT(p->fontdata) : 256;
3256 if (caps->len < charcnt)
3257 caps->len = charcnt;
3261 vc = vc_cons[fg_console].d;
3263 if (vc && vc->vc_mode == KD_TEXT &&
3264 info->node == con2fb_map[fg_console]) {
3265 p = &fb_display[fg_console];
3266 caps->x = 1 << (vc->vc_font.width - 1);
3267 caps->y = 1 << (vc->vc_font.height - 1);
3268 caps->len = (p->userfont) ?
3269 FNTCHARCNT(p->fontdata) : 256;
3274 static int fbcon_event_notify(struct notifier_block *self,
3275 unsigned long action, void *data)
3277 struct fb_event *event = data;
3278 struct fb_info *info = event->info;
3279 struct fb_videomode *mode;
3280 struct fb_con2fbmap *con2fb;
3281 struct fb_blit_caps *caps;
3285 * ignore all events except driver registration and deregistration
3286 * if fbcon is not active
3288 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3289 action == FB_EVENT_FB_UNREGISTERED))
3293 case FB_EVENT_SUSPEND:
3294 fbcon_suspended(info);
3296 case FB_EVENT_RESUME:
3297 fbcon_resumed(info);
3299 case FB_EVENT_MODE_CHANGE:
3300 fbcon_modechanged(info);
3302 case FB_EVENT_MODE_CHANGE_ALL:
3303 fbcon_set_all_vcs(info);
3305 case FB_EVENT_MODE_DELETE:
3307 ret = fbcon_mode_deleted(info, mode);
3309 case FB_EVENT_FB_UNBIND:
3311 ret = fbcon_fb_unbind(idx);
3313 case FB_EVENT_FB_REGISTERED:
3314 ret = fbcon_fb_registered(info);
3316 case FB_EVENT_FB_UNREGISTERED:
3317 ret = fbcon_fb_unregistered(info);
3319 case FB_EVENT_SET_CONSOLE_MAP:
3320 /* called with console lock held */
3321 con2fb = event->data;
3322 ret = set_con2fb_map(con2fb->console - 1,
3323 con2fb->framebuffer, 1);
3325 case FB_EVENT_GET_CONSOLE_MAP:
3326 con2fb = event->data;
3327 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3329 case FB_EVENT_BLANK:
3330 fbcon_fb_blanked(info, *(int *)event->data);
3332 case FB_EVENT_NEW_MODELIST:
3333 fbcon_new_modelist(info);
3335 case FB_EVENT_GET_REQ:
3337 fbcon_get_requirement(info, caps);
3339 case FB_EVENT_REMAP_ALL_CONSOLE:
3341 fbcon_remap_all(idx);
3349 * The console `switch' structure for the frame buffer based console
3352 static const struct consw fb_con = {
3353 .owner = THIS_MODULE,
3354 .con_startup = fbcon_startup,
3355 .con_init = fbcon_init,
3356 .con_deinit = fbcon_deinit,
3357 .con_clear = fbcon_clear,
3358 .con_putc = fbcon_putc,
3359 .con_putcs = fbcon_putcs,
3360 .con_cursor = fbcon_cursor,
3361 .con_scroll = fbcon_scroll,
3362 .con_switch = fbcon_switch,
3363 .con_blank = fbcon_blank,
3364 .con_font_set = fbcon_set_font,
3365 .con_font_get = fbcon_get_font,
3366 .con_font_default = fbcon_set_def_font,
3367 .con_font_copy = fbcon_copy_font,
3368 .con_set_palette = fbcon_set_palette,
3369 .con_scrolldelta = fbcon_scrolldelta,
3370 .con_set_origin = fbcon_set_origin,
3371 .con_invert_region = fbcon_invert_region,
3372 .con_screen_pos = fbcon_screen_pos,
3373 .con_getxy = fbcon_getxy,
3374 .con_resize = fbcon_resize,
3375 .con_debug_enter = fbcon_debug_enter,
3376 .con_debug_leave = fbcon_debug_leave,
3379 static struct notifier_block fbcon_event_notifier = {
3380 .notifier_call = fbcon_event_notify,
3383 static ssize_t store_rotate(struct device *device,
3384 struct device_attribute *attr, const char *buf,
3387 struct fb_info *info;
3391 if (fbcon_has_exited)
3395 idx = con2fb_map[fg_console];
3397 if (idx == -1 || registered_fb[idx] == NULL)
3400 info = registered_fb[idx];
3401 rotate = simple_strtoul(buf, last, 0);
3402 fbcon_rotate(info, rotate);
3408 static ssize_t store_rotate_all(struct device *device,
3409 struct device_attribute *attr,const char *buf,
3412 struct fb_info *info;
3416 if (fbcon_has_exited)
3420 idx = con2fb_map[fg_console];
3422 if (idx == -1 || registered_fb[idx] == NULL)
3425 info = registered_fb[idx];
3426 rotate = simple_strtoul(buf, last, 0);
3427 fbcon_rotate_all(info, rotate);
3433 static ssize_t show_rotate(struct device *device,
3434 struct device_attribute *attr,char *buf)
3436 struct fb_info *info;
3437 int rotate = 0, idx;
3439 if (fbcon_has_exited)
3443 idx = con2fb_map[fg_console];
3445 if (idx == -1 || registered_fb[idx] == NULL)
3448 info = registered_fb[idx];
3449 rotate = fbcon_get_rotate(info);
3452 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3455 static ssize_t show_cursor_blink(struct device *device,
3456 struct device_attribute *attr, char *buf)
3458 struct fb_info *info;
3459 struct fbcon_ops *ops;
3460 int idx, blink = -1;
3462 if (fbcon_has_exited)
3466 idx = con2fb_map[fg_console];
3468 if (idx == -1 || registered_fb[idx] == NULL)
3471 info = registered_fb[idx];
3472 ops = info->fbcon_par;
3477 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3480 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3483 static ssize_t store_cursor_blink(struct device *device,
3484 struct device_attribute *attr,
3485 const char *buf, size_t count)
3487 struct fb_info *info;
3491 if (fbcon_has_exited)
3495 idx = con2fb_map[fg_console];
3497 if (idx == -1 || registered_fb[idx] == NULL)
3500 info = registered_fb[idx];
3502 if (!info->fbcon_par)
3505 blink = simple_strtoul(buf, last, 0);
3508 fbcon_cursor_noblink = 0;
3509 fbcon_add_cursor_timer(info);
3511 fbcon_cursor_noblink = 1;
3512 fbcon_del_cursor_timer(info);
3520 static struct device_attribute device_attrs[] = {
3521 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3522 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3523 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3524 store_cursor_blink),
3527 static int fbcon_init_device(void)
3531 fbcon_has_sysfs = 1;
3533 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3534 error = device_create_file(fbcon_device, &device_attrs[i]);
3542 device_remove_file(fbcon_device, &device_attrs[i]);
3544 fbcon_has_sysfs = 0;
3550 static void fbcon_start(void)
3552 if (num_registered_fb) {
3557 for (i = 0; i < FB_MAX; i++) {
3558 if (registered_fb[i] != NULL) {
3564 do_fbcon_takeover(0);
3570 static void fbcon_exit(void)
3572 struct fb_info *info;
3575 if (fbcon_has_exited)
3578 kfree((void *)softback_buf);
3581 for (i = 0; i < FB_MAX; i++) {
3585 info = registered_fb[i];
3590 if (info->queue.func)
3591 pending = cancel_work_sync(&info->queue);
3592 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3595 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3596 if (con2fb_map[j] == i) {
3603 if (info->fbops->fb_release)
3604 info->fbops->fb_release(info, 0);
3605 module_put(info->fbops->owner);
3607 if (info->fbcon_par) {
3608 struct fbcon_ops *ops = info->fbcon_par;
3610 fbcon_del_cursor_timer(info);
3611 kfree(ops->cursor_src);
3612 kfree(ops->cursor_state.mask);
3613 kfree(info->fbcon_par);
3614 info->fbcon_par = NULL;
3617 if (info->queue.func == fb_flashcursor)
3618 info->queue.func = NULL;
3622 fbcon_has_exited = 1;
3625 void __init fb_console_init(void)
3630 fb_register_client(&fbcon_event_notifier);
3631 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3634 if (IS_ERR(fbcon_device)) {
3635 printk(KERN_WARNING "Unable to create device "
3636 "for fbcon; errno = %ld\n",
3637 PTR_ERR(fbcon_device));
3638 fbcon_device = NULL;
3640 fbcon_init_device();
3642 for (i = 0; i < MAX_NR_CONSOLES; i++)
3651 static void __exit fbcon_deinit_device(void)
3655 if (fbcon_has_sysfs) {
3656 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3657 device_remove_file(fbcon_device, &device_attrs[i]);
3659 fbcon_has_sysfs = 0;
3663 void __exit fb_console_exit(void)
3666 fb_unregister_client(&fbcon_event_notifier);
3667 fbcon_deinit_device();
3668 device_destroy(fb_class, MKDEV(0, 0));
3670 do_unregister_con_driver(&fb_con);