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 */
82 #include <linux/bootsplash.h>
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 #ifdef CONFIG_BOOTSPLASH
99 signed char con2fb_map[MAX_NR_CONSOLES];
101 static signed char con2fb_map[MAX_NR_CONSOLES];
103 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
105 static int logo_lines;
106 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
108 static int logo_shown = FBCON_LOGO_CANSHOW;
109 /* Software scrollback */
110 static int fbcon_softback_size = 32768;
111 static unsigned long softback_buf, softback_curr;
112 static unsigned long softback_in;
113 static unsigned long softback_top, softback_end;
114 static int softback_lines;
115 /* console mappings */
116 static int first_fb_vc;
117 static int last_fb_vc = MAX_NR_CONSOLES - 1;
118 static int fbcon_is_default = 1;
119 static int fbcon_has_exited;
120 static int primary_device = -1;
121 static int fbcon_has_console_bind;
123 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
124 static int map_override;
126 static inline void fbcon_map_override(void)
131 static inline void fbcon_map_override(void)
134 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
137 static char fontname[40];
139 /* current fb_info */
140 static int info_idx = -1;
142 /* console rotation */
143 static int initial_rotation;
144 static int fbcon_has_sysfs;
146 static const struct consw fb_con;
148 #define CM_SOFTBACK (8)
150 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
152 static int fbcon_set_origin(struct vc_data *);
154 #define CURSOR_DRAW_DELAY (1)
156 static int vbl_cursor_cnt;
157 static int fbcon_cursor_noblink;
159 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
162 * Interface used by the world
165 static const char *fbcon_startup(void);
166 static void fbcon_init(struct vc_data *vc, int init);
167 static void fbcon_deinit(struct vc_data *vc);
168 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
170 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
171 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
172 int count, int ypos, int xpos);
173 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
174 static void fbcon_cursor(struct vc_data *vc, int mode);
175 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
177 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
178 int height, int width);
179 static int fbcon_switch(struct vc_data *vc);
180 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
181 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
182 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
187 static __inline__ void ywrap_up(struct vc_data *vc, int count);
188 static __inline__ void ywrap_down(struct vc_data *vc, int count);
189 static __inline__ void ypan_up(struct vc_data *vc, int count);
190 static __inline__ void ypan_down(struct vc_data *vc, int count);
191 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
192 int dy, int dx, int height, int width, u_int y_break);
193 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
195 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
196 int line, int count, int dy);
197 static void fbcon_modechanged(struct fb_info *info);
198 static void fbcon_set_all_vcs(struct fb_info *info);
199 static void fbcon_start(void);
200 static void fbcon_exit(void);
201 static struct device *fbcon_device;
203 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
204 static inline void fbcon_set_rotation(struct fb_info *info)
206 struct fbcon_ops *ops = info->fbcon_par;
208 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
209 ops->p->con_rotate < 4)
210 ops->rotate = ops->p->con_rotate;
215 static void fbcon_rotate(struct fb_info *info, u32 rotate)
217 struct fbcon_ops *ops= info->fbcon_par;
218 struct fb_info *fb_info;
220 if (!ops || ops->currcon == -1)
223 fb_info = registered_fb[con2fb_map[ops->currcon]];
225 if (info == fb_info) {
226 struct display *p = &fb_display[ops->currcon];
229 p->con_rotate = rotate;
233 fbcon_modechanged(info);
237 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
239 struct fbcon_ops *ops = info->fbcon_par;
244 if (!ops || ops->currcon < 0 || rotate > 3)
247 for (i = first_fb_vc; i <= last_fb_vc; i++) {
249 if (!vc || vc->vc_mode != KD_TEXT ||
250 registered_fb[con2fb_map[i]] != info)
253 p = &fb_display[vc->vc_num];
254 p->con_rotate = rotate;
257 fbcon_set_all_vcs(info);
260 static inline void fbcon_set_rotation(struct fb_info *info)
262 struct fbcon_ops *ops = info->fbcon_par;
264 ops->rotate = FB_ROTATE_UR;
267 static void fbcon_rotate(struct fb_info *info, u32 rotate)
272 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
276 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
278 static int fbcon_get_rotate(struct fb_info *info)
280 struct fbcon_ops *ops = info->fbcon_par;
282 return (ops) ? ops->rotate : 0;
285 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
287 struct fbcon_ops *ops = info->fbcon_par;
289 return (info->state != FBINFO_STATE_RUNNING ||
290 vc->vc_mode != KD_TEXT || ops->graphics) &&
291 !vt_force_oops_output(vc);
294 static int get_color(struct vc_data *vc, struct fb_info *info,
297 int depth = fb_get_color_depth(&info->var, &info->fix);
300 if (console_blanked) {
301 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
303 c = vc->vc_video_erase_char & charmask;
307 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
308 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
313 int col = mono_col(info);
315 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
316 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
321 color = (is_fg) ? fg : bg;
326 * Scale down 16-colors to 4 colors. Default 4-color palette
327 * is grayscale. However, simply dividing the values by 4
328 * will not work, as colors 1, 2 and 3 will be scaled-down
329 * to zero rendering them invisible. So empirically convert
330 * colors to a sane 4-level grayscale.
334 color = 0; /* black */
337 color = 2; /* white */
340 color = 1; /* gray */
343 color = 3; /* intense white */
349 * Last 8 entries of default 16-color palette is a more intense
350 * version of the first 8 (i.e., same chrominance, different
361 static void fbcon_update_softback(struct vc_data *vc)
363 int l = fbcon_softback_size / vc->vc_size_row;
366 softback_end = softback_buf + l * vc->vc_size_row;
368 /* Smaller scrollback makes no sense, and 0 would screw
369 the operation totally */
373 static void fb_flashcursor(struct work_struct *work)
375 struct fb_info *info = container_of(work, struct fb_info, queue);
376 struct fbcon_ops *ops = info->fbcon_par;
377 struct vc_data *vc = NULL;
382 if (ops && ops->currcon != -1)
383 vc = vc_cons[ops->currcon].d;
385 if (!vc || !CON_IS_VISIBLE(vc) ||
386 registered_fb[con2fb_map[vc->vc_num]] != info ||
392 c = scr_readw((u16 *) vc->vc_pos);
393 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
395 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
396 get_color(vc, info, c, 0));
400 static void cursor_timer_handler(unsigned long dev_addr)
402 struct fb_info *info = (struct fb_info *) dev_addr;
403 struct fbcon_ops *ops = info->fbcon_par;
405 schedule_work(&info->queue);
406 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
409 static void fbcon_add_cursor_timer(struct fb_info *info)
411 struct fbcon_ops *ops = info->fbcon_par;
413 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
414 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
415 !fbcon_cursor_noblink) {
416 if (!info->queue.func)
417 INIT_WORK(&info->queue, fb_flashcursor);
419 init_timer(&ops->cursor_timer);
420 ops->cursor_timer.function = cursor_timer_handler;
421 ops->cursor_timer.expires = jiffies + HZ / 5;
422 ops->cursor_timer.data = (unsigned long ) info;
423 add_timer(&ops->cursor_timer);
424 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
428 static void fbcon_del_cursor_timer(struct fb_info *info)
430 struct fbcon_ops *ops = info->fbcon_par;
432 if (info->queue.func == fb_flashcursor &&
433 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
434 del_timer_sync(&ops->cursor_timer);
435 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
440 static int __init fb_console_setup(char *this_opt)
445 if (!this_opt || !*this_opt)
448 while ((options = strsep(&this_opt, ",")) != NULL) {
449 if (!strncmp(options, "font:", 5))
450 strcpy(fontname, options + 5);
452 if (!strncmp(options, "scrollback:", 11)) {
455 fbcon_softback_size = simple_strtoul(options, &options, 0);
456 if (*options == 'k' || *options == 'K') {
457 fbcon_softback_size *= 1024;
467 if (!strncmp(options, "map:", 4)) {
470 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
474 (options[j++]-'0') % FB_MAX;
477 fbcon_map_override();
483 if (!strncmp(options, "vc:", 3)) {
486 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
489 if (*options++ == '-')
490 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
491 fbcon_is_default = 0;
494 if (!strncmp(options, "rotate:", 7)) {
497 initial_rotation = simple_strtoul(options, &options, 0);
498 if (initial_rotation > 3)
499 initial_rotation = 0;
505 __setup("fbcon=", fb_console_setup);
508 static int search_fb_in_map(int idx)
512 for (i = first_fb_vc; i <= last_fb_vc; i++) {
513 if (con2fb_map[i] == idx)
519 static int search_for_mapped_con(void)
523 for (i = first_fb_vc; i <= last_fb_vc; i++) {
524 if (con2fb_map[i] != -1)
530 static int fbcon_takeover(int show_logo)
534 if (!num_registered_fb)
538 logo_shown = FBCON_LOGO_DONTSHOW;
540 for (i = first_fb_vc; i <= last_fb_vc; i++)
541 con2fb_map[i] = info_idx;
545 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
549 for (i = first_fb_vc; i <= last_fb_vc; i++) {
554 fbcon_has_console_bind = 1;
561 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
562 int cols, int rows, int new_cols, int new_rows)
564 logo_shown = FBCON_LOGO_DONTSHOW;
567 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
568 int cols, int rows, int new_cols, int new_rows)
570 /* Need to make room for the logo */
571 struct fbcon_ops *ops = info->fbcon_par;
572 int cnt, erase = vc->vc_video_erase_char, step;
573 unsigned short *save = NULL, *r, *q;
576 if (info->flags & FBINFO_MODULE) {
577 logo_shown = FBCON_LOGO_DONTSHOW;
582 * remove underline attribute from erase character
583 * if black and white framebuffer.
585 if (fb_get_color_depth(&info->var, &info->fix) == 1)
587 logo_height = fb_prepare_logo(info, ops->rotate);
588 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
589 q = (unsigned short *) (vc->vc_origin +
590 vc->vc_size_row * rows);
591 step = logo_lines * cols;
592 for (r = q - logo_lines * cols; r < q; r++)
593 if (scr_readw(r) != vc->vc_video_erase_char)
595 if (r != q && new_rows >= rows + logo_lines) {
596 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
598 int i = cols < new_cols ? cols : new_cols;
599 scr_memsetw(save, erase, logo_lines * new_cols * 2);
601 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
602 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
607 /* We can scroll screen down */
609 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
610 scr_memcpyw(r + step, r, vc->vc_size_row);
615 if (vc->vc_y + logo_lines >= rows)
616 lines = rows - vc->vc_y - 1;
620 vc->vc_pos += lines * vc->vc_size_row;
623 scr_memsetw((unsigned short *) vc->vc_origin,
625 vc->vc_size_row * logo_lines);
627 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
628 fbcon_clear_margins(vc, 0);
633 q = (unsigned short *) (vc->vc_origin +
636 scr_memcpyw(q, save, logo_lines * new_cols * 2);
637 vc->vc_y += logo_lines;
638 vc->vc_pos += logo_lines * vc->vc_size_row;
642 if (logo_lines > vc->vc_bottom) {
643 logo_shown = FBCON_LOGO_CANSHOW;
645 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
646 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
647 logo_shown = FBCON_LOGO_DRAW;
648 vc->vc_top = logo_lines;
653 #ifdef CONFIG_FB_TILEBLITTING
654 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
656 struct fbcon_ops *ops = info->fbcon_par;
658 ops->p = &fb_display[vc->vc_num];
660 if ((info->flags & FBINFO_MISC_TILEBLITTING))
661 fbcon_set_tileops(vc, info);
663 fbcon_set_rotation(info);
664 fbcon_set_bitops(ops);
668 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
672 if (info->flags & FBINFO_MISC_TILEBLITTING &&
673 info->tileops->fb_get_tilemax(info) < charcount)
679 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
681 struct fbcon_ops *ops = info->fbcon_par;
683 info->flags &= ~FBINFO_MISC_TILEBLITTING;
684 ops->p = &fb_display[vc->vc_num];
685 fbcon_set_rotation(info);
686 fbcon_set_bitops(ops);
689 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
694 #endif /* CONFIG_MISC_TILEBLITTING */
697 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
698 int unit, int oldidx)
700 struct fbcon_ops *ops = NULL;
703 if (!try_module_get(info->fbops->owner))
706 if (!err && info->fbops->fb_open &&
707 info->fbops->fb_open(info, 0))
711 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
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->fontbuffer);
753 kfree(oldinfo->fbcon_par);
754 oldinfo->fbcon_par = NULL;
755 module_put(oldinfo->fbops->owner);
757 If oldinfo and newinfo are driving the same hardware,
758 the fb_release() method of oldinfo may attempt to
759 restore the hardware state. This will leave the
760 newinfo in an undefined state. Thus, a call to
761 fb_set_par() may be needed for the newinfo.
763 if (newinfo->fbops->fb_set_par) {
764 ret = newinfo->fbops->fb_set_par(newinfo);
767 printk(KERN_ERR "con2fb_release_oldinfo: "
768 "detected unhandled fb_set_par error, "
769 "error code %d\n", ret);
776 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
777 int unit, int show_logo)
779 struct fbcon_ops *ops = info->fbcon_par;
782 ops->currcon = fg_console;
784 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
785 ret = info->fbops->fb_set_par(info);
788 printk(KERN_ERR "con2fb_init_display: detected "
789 "unhandled fb_set_par error, "
790 "error code %d\n", ret);
793 ops->flags |= FBCON_FLAGS_INIT;
795 fbcon_set_disp(info, &info->var, unit);
798 struct vc_data *fg_vc = vc_cons[fg_console].d;
799 struct fb_info *fg_info =
800 registered_fb[con2fb_map[fg_console]];
802 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
803 fg_vc->vc_rows, fg_vc->vc_cols,
807 update_screen(vc_cons[fg_console].d);
811 * set_con2fb_map - map console to frame buffer device
812 * @unit: virtual console number to map
813 * @newidx: frame buffer index to map virtual console to
814 * @user: user request
816 * Maps a virtual console @unit to a frame buffer device
819 static int set_con2fb_map(int unit, int newidx, int user)
821 struct vc_data *vc = vc_cons[unit].d;
822 int oldidx = con2fb_map[unit];
823 struct fb_info *info = registered_fb[newidx];
824 struct fb_info *oldinfo = NULL;
827 if (oldidx == newidx)
833 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
835 return fbcon_takeover(0);
839 oldinfo = registered_fb[oldidx];
841 found = search_fb_in_map(newidx);
844 con2fb_map[unit] = newidx;
846 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
850 * If old fb is not mapped to any of the consoles,
851 * fbcon should release it.
853 if (!err && oldinfo && !search_fb_in_map(oldidx))
854 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
858 int show_logo = (fg_console == 0 && !user &&
859 logo_shown != FBCON_LOGO_DONTSHOW);
862 fbcon_add_cursor_timer(info);
863 con2fb_map_boot[unit] = newidx;
864 con2fb_init_display(vc, info, unit, show_logo);
867 if (!search_fb_in_map(info_idx))
875 * Low Level Operations
877 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
878 static int var_to_display(struct display *disp,
879 struct fb_var_screeninfo *var,
880 struct fb_info *info)
882 disp->xres_virtual = var->xres_virtual;
883 disp->yres_virtual = var->yres_virtual;
884 disp->bits_per_pixel = var->bits_per_pixel;
885 disp->grayscale = var->grayscale;
886 disp->nonstd = var->nonstd;
887 disp->accel_flags = var->accel_flags;
888 disp->height = var->height;
889 disp->width = var->width;
890 disp->red = var->red;
891 disp->green = var->green;
892 disp->blue = var->blue;
893 disp->transp = var->transp;
894 disp->rotate = var->rotate;
895 disp->mode = fb_match_mode(var, &info->modelist);
896 if (disp->mode == NULL)
897 /* This should not happen */
902 static void display_to_var(struct fb_var_screeninfo *var,
903 struct display *disp)
905 fb_videomode_to_var(var, disp->mode);
906 var->xres_virtual = disp->xres_virtual;
907 var->yres_virtual = disp->yres_virtual;
908 var->bits_per_pixel = disp->bits_per_pixel;
909 var->grayscale = disp->grayscale;
910 var->nonstd = disp->nonstd;
911 var->accel_flags = disp->accel_flags;
912 var->height = disp->height;
913 var->width = disp->width;
914 var->red = disp->red;
915 var->green = disp->green;
916 var->blue = disp->blue;
917 var->transp = disp->transp;
918 var->rotate = disp->rotate;
921 static const char *fbcon_startup(void)
923 const char *display_desc = "frame buffer device";
924 struct display *p = &fb_display[fg_console];
925 struct vc_data *vc = vc_cons[fg_console].d;
926 const struct font_desc *font = NULL;
927 struct module *owner;
928 struct fb_info *info = NULL;
929 struct fbcon_ops *ops;
933 * If num_registered_fb is zero, this is a call for the dummy part.
934 * The frame buffer devices weren't initialized yet.
936 if (!num_registered_fb || info_idx == -1)
939 * Instead of blindly using registered_fb[0], we use info_idx, set by
942 info = registered_fb[info_idx];
946 owner = info->fbops->owner;
947 if (!try_module_get(owner))
949 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
954 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
962 ops->cur_rotate = -1;
963 info->fbcon_par = ops;
964 p->con_rotate = initial_rotation;
965 set_blitting_type(vc, info);
967 if (info->fix.type != FB_TYPE_TEXT) {
968 if (fbcon_softback_size) {
972 kmalloc(fbcon_softback_size,
975 fbcon_softback_size = 0;
981 kfree((void *) softback_buf);
987 softback_in = softback_top = softback_curr =
992 /* Setup default font */
994 if (!fontname[0] || !(font = find_font(fontname)))
995 font = get_default_font(info->var.xres,
998 info->pixmap.blit_y);
999 vc->vc_font.width = font->width;
1000 vc->vc_font.height = font->height;
1001 vc->vc_font.data = (void *)(p->fontdata = font->data);
1002 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1005 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1006 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1007 cols /= vc->vc_font.width;
1008 rows /= vc->vc_font.height;
1009 vc_resize(vc, cols, rows);
1011 DPRINTK("mode: %s\n", info->fix.id);
1012 DPRINTK("visual: %d\n", info->fix.visual);
1013 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1015 info->var.bits_per_pixel);
1017 fbcon_add_cursor_timer(info);
1018 fbcon_has_exited = 0;
1019 return display_desc;
1022 static void fbcon_init(struct vc_data *vc, int init)
1024 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1025 struct fbcon_ops *ops;
1026 struct vc_data **default_mode = vc->vc_display_fg;
1027 struct vc_data *svc = *default_mode;
1028 struct display *t, *p = &fb_display[vc->vc_num];
1029 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1032 if (info_idx == -1 || info == NULL)
1037 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1038 (info->fix.type == FB_TYPE_TEXT))
1041 if (var_to_display(p, &info->var, info))
1044 if (!info->fbcon_par)
1045 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1047 /* If we are not the first console on this
1048 fb, copy the font from that console */
1049 t = &fb_display[fg_console];
1052 struct vc_data *fvc = vc_cons[fg_console].d;
1054 vc->vc_font.data = (void *)(p->fontdata =
1056 vc->vc_font.width = fvc->vc_font.width;
1057 vc->vc_font.height = fvc->vc_font.height;
1058 p->userfont = t->userfont;
1061 REFCOUNT(p->fontdata)++;
1063 const struct font_desc *font = NULL;
1065 if (!fontname[0] || !(font = find_font(fontname)))
1066 font = get_default_font(info->var.xres,
1068 info->pixmap.blit_x,
1069 info->pixmap.blit_y);
1070 vc->vc_font.width = font->width;
1071 vc->vc_font.height = font->height;
1072 vc->vc_font.data = (void *)(p->fontdata = font->data);
1073 vc->vc_font.charcount = 256; /* FIXME Need to
1074 support more fonts */
1079 charcnt = FNTCHARCNT(p->fontdata);
1081 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1082 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1083 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1084 if (charcnt == 256) {
1085 vc->vc_hi_font_mask = 0;
1087 vc->vc_hi_font_mask = 0x100;
1088 if (vc->vc_can_do_color)
1089 vc->vc_complement_mask <<= 1;
1092 if (!*svc->vc_uni_pagedir_loc)
1093 con_set_default_unimap(svc);
1094 if (!*vc->vc_uni_pagedir_loc)
1095 con_copy_unimap(vc, svc);
1097 ops = info->fbcon_par;
1098 p->con_rotate = initial_rotation;
1099 set_blitting_type(vc, info);
1103 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1104 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1105 new_cols /= vc->vc_font.width;
1106 new_rows /= vc->vc_font.height;
1108 #ifdef CONFIG_BOOTSPLASH
1109 if (vc->vc_splash_data && vc->vc_splash_data->splash_state) {
1110 new_cols = vc->vc_splash_data->splash_vc_text_wi
1111 / vc->vc_font.width;
1112 new_rows = vc->vc_splash_data->splash_vc_text_he
1113 / vc->vc_font.height;
1115 con_remap_def_color(vc,
1116 (vc->vc_splash_data->imgd->splash_color
1118 vc->vc_splash_data->imgd->splash_fg_color);
1124 * We must always set the mode. The mode of the previous console
1125 * driver could be in the same resolution but we are using different
1126 * hardware so we have to initialize the hardware.
1128 * We need to do it in fbcon_init() to prevent screen corruption.
1130 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1131 if (info->fbops->fb_set_par &&
1132 !(ops->flags & FBCON_FLAGS_INIT)) {
1133 ret = info->fbops->fb_set_par(info);
1136 printk(KERN_ERR "fbcon_init: detected "
1137 "unhandled fb_set_par error, "
1138 "error code %d\n", ret);
1141 ops->flags |= FBCON_FLAGS_INIT;
1146 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1147 !(cap & FBINFO_HWACCEL_DISABLED))
1148 p->scrollmode = SCROLL_MOVE;
1149 else /* default to something safe */
1150 p->scrollmode = SCROLL_REDRAW;
1153 * ++guenther: console.c:vc_allocate() relies on initializing
1154 * vc_{cols,rows}, but we must not set those if we are only
1155 * resizing the console.
1158 vc->vc_cols = new_cols;
1159 vc->vc_rows = new_rows;
1161 vc_resize(vc, new_cols, new_rows);
1164 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1166 if (vc == svc && softback_buf)
1167 fbcon_update_softback(vc);
1169 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1170 ops->rotate = FB_ROTATE_UR;
1171 set_blitting_type(vc, info);
1174 ops->p = &fb_display[fg_console];
1177 static void fbcon_free_font(struct display *p)
1179 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1180 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1185 static void fbcon_deinit(struct vc_data *vc)
1187 struct display *p = &fb_display[vc->vc_num];
1188 struct fb_info *info;
1189 struct fbcon_ops *ops;
1193 idx = con2fb_map[vc->vc_num];
1198 info = registered_fb[idx];
1203 ops = info->fbcon_par;
1208 if (CON_IS_VISIBLE(vc))
1209 fbcon_del_cursor_timer(info);
1211 ops->flags &= ~FBCON_FLAGS_INIT;
1214 if (!con_is_bound(&fb_con))
1220 /* ====================================================================== */
1222 /* fbcon_XXX routines - interface used by the world
1224 * This system is now divided into two levels because of complications
1225 * caused by hardware scrolling. Top level functions:
1227 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1229 * handles y values in range [0, scr_height-1] that correspond to real
1230 * screen positions. y_wrap shift means that first line of bitmap may be
1231 * anywhere on this display. These functions convert lineoffsets to
1232 * bitmap offsets and deal with the wrap-around case by splitting blits.
1234 * fbcon_bmove_physical_8() -- These functions fast implementations
1235 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1236 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1240 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1241 * Implies should only really hardware scroll in rows. Only reason for
1242 * restriction is simplicity & efficiency at the moment.
1245 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1248 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1249 struct fbcon_ops *ops = info->fbcon_par;
1251 struct display *p = &fb_display[vc->vc_num];
1254 if (fbcon_is_inactive(vc, info))
1257 if (!height || !width)
1260 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1263 /* Split blits that cross physical y_wrap boundary */
1265 y_break = p->vrows - p->yscroll;
1266 if (sy < y_break && sy + height - 1 >= y_break) {
1267 u_int b = y_break - sy;
1268 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1269 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1272 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1275 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1276 int count, int ypos, int xpos)
1278 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1279 struct display *p = &fb_display[vc->vc_num];
1280 struct fbcon_ops *ops = info->fbcon_par;
1282 if (!fbcon_is_inactive(vc, info))
1283 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1284 get_color(vc, info, scr_readw(s), 1),
1285 get_color(vc, info, scr_readw(s), 0));
1288 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1292 scr_writew(c, &chr);
1293 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1296 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1299 struct fbcon_ops *ops = info->fbcon_par;
1301 if (!fbcon_is_inactive(vc, info))
1302 ops->clear_margins(vc, info, bottom_only);
1305 static void fbcon_cursor(struct vc_data *vc, int mode)
1307 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1308 struct fbcon_ops *ops = info->fbcon_par;
1310 int c = scr_readw((u16 *) vc->vc_pos);
1312 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1315 if (vc->vc_cursor_type & 0x10)
1316 fbcon_del_cursor_timer(info);
1318 fbcon_add_cursor_timer(info);
1320 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1321 if (mode & CM_SOFTBACK) {
1322 mode &= ~CM_SOFTBACK;
1326 fbcon_set_origin(vc);
1330 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1331 get_color(vc, info, c, 0));
1332 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1335 static int scrollback_phys_max = 0;
1336 static int scrollback_max = 0;
1337 static int scrollback_current = 0;
1339 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1342 struct display *p, *t;
1343 struct vc_data **default_mode, *vc;
1344 struct vc_data *svc;
1345 struct fbcon_ops *ops = info->fbcon_par;
1346 int rows, cols, charcnt = 256;
1348 p = &fb_display[unit];
1350 if (var_to_display(p, var, info))
1353 vc = vc_cons[unit].d;
1358 default_mode = vc->vc_display_fg;
1359 svc = *default_mode;
1360 t = &fb_display[svc->vc_num];
1362 if (!vc->vc_font.data) {
1363 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1364 vc->vc_font.width = (*default_mode)->vc_font.width;
1365 vc->vc_font.height = (*default_mode)->vc_font.height;
1366 p->userfont = t->userfont;
1368 REFCOUNT(p->fontdata)++;
1371 charcnt = FNTCHARCNT(p->fontdata);
1373 var->activate = FB_ACTIVATE_NOW;
1374 info->var.activate = var->activate;
1375 var->yoffset = info->var.yoffset;
1376 var->xoffset = info->var.xoffset;
1377 fb_set_var(info, var);
1378 ops->var = info->var;
1379 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1380 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1381 if (charcnt == 256) {
1382 vc->vc_hi_font_mask = 0;
1384 vc->vc_hi_font_mask = 0x100;
1385 if (vc->vc_can_do_color)
1386 vc->vc_complement_mask <<= 1;
1389 if (!*svc->vc_uni_pagedir_loc)
1390 con_set_default_unimap(svc);
1391 if (!*vc->vc_uni_pagedir_loc)
1392 con_copy_unimap(vc, svc);
1394 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1395 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1396 cols /= vc->vc_font.width;
1397 rows /= vc->vc_font.height;
1398 vc_resize(vc, cols, rows);
1400 if (CON_IS_VISIBLE(vc)) {
1403 fbcon_update_softback(vc);
1407 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1409 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1410 struct fbcon_ops *ops = info->fbcon_par;
1411 struct display *p = &fb_display[vc->vc_num];
1413 p->yscroll += count;
1414 if (p->yscroll >= p->vrows) /* Deal with wrap */
1415 p->yscroll -= p->vrows;
1416 ops->var.xoffset = 0;
1417 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1418 ops->var.vmode |= FB_VMODE_YWRAP;
1419 ops->update_start(info);
1420 scrollback_max += count;
1421 if (scrollback_max > scrollback_phys_max)
1422 scrollback_max = scrollback_phys_max;
1423 scrollback_current = 0;
1426 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1428 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1429 struct fbcon_ops *ops = info->fbcon_par;
1430 struct display *p = &fb_display[vc->vc_num];
1432 p->yscroll -= count;
1433 if (p->yscroll < 0) /* Deal with wrap */
1434 p->yscroll += p->vrows;
1435 ops->var.xoffset = 0;
1436 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1437 ops->var.vmode |= FB_VMODE_YWRAP;
1438 ops->update_start(info);
1439 scrollback_max -= count;
1440 if (scrollback_max < 0)
1442 scrollback_current = 0;
1445 static __inline__ void ypan_up(struct vc_data *vc, int count)
1447 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1448 struct display *p = &fb_display[vc->vc_num];
1449 struct fbcon_ops *ops = info->fbcon_par;
1451 p->yscroll += count;
1452 if (p->yscroll > p->vrows - vc->vc_rows) {
1453 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1454 0, 0, 0, vc->vc_rows, vc->vc_cols);
1455 p->yscroll -= p->vrows - vc->vc_rows;
1458 ops->var.xoffset = 0;
1459 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1460 ops->var.vmode &= ~FB_VMODE_YWRAP;
1461 ops->update_start(info);
1462 fbcon_clear_margins(vc, 1);
1463 scrollback_max += count;
1464 if (scrollback_max > scrollback_phys_max)
1465 scrollback_max = scrollback_phys_max;
1466 scrollback_current = 0;
1469 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1471 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1472 struct fbcon_ops *ops = info->fbcon_par;
1473 struct display *p = &fb_display[vc->vc_num];
1475 p->yscroll += count;
1477 if (p->yscroll > p->vrows - vc->vc_rows) {
1478 p->yscroll -= p->vrows - vc->vc_rows;
1479 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1482 ops->var.xoffset = 0;
1483 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1484 ops->var.vmode &= ~FB_VMODE_YWRAP;
1485 ops->update_start(info);
1486 fbcon_clear_margins(vc, 1);
1487 scrollback_max += count;
1488 if (scrollback_max > scrollback_phys_max)
1489 scrollback_max = scrollback_phys_max;
1490 scrollback_current = 0;
1493 static __inline__ void ypan_down(struct vc_data *vc, int count)
1495 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1496 struct display *p = &fb_display[vc->vc_num];
1497 struct fbcon_ops *ops = info->fbcon_par;
1499 p->yscroll -= count;
1500 if (p->yscroll < 0) {
1501 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1502 0, vc->vc_rows, vc->vc_cols);
1503 p->yscroll += p->vrows - vc->vc_rows;
1506 ops->var.xoffset = 0;
1507 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1508 ops->var.vmode &= ~FB_VMODE_YWRAP;
1509 ops->update_start(info);
1510 fbcon_clear_margins(vc, 1);
1511 scrollback_max -= count;
1512 if (scrollback_max < 0)
1514 scrollback_current = 0;
1517 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1519 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1520 struct fbcon_ops *ops = info->fbcon_par;
1521 struct display *p = &fb_display[vc->vc_num];
1523 p->yscroll -= count;
1525 if (p->yscroll < 0) {
1526 p->yscroll += p->vrows - vc->vc_rows;
1527 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1530 ops->var.xoffset = 0;
1531 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1532 ops->var.vmode &= ~FB_VMODE_YWRAP;
1533 ops->update_start(info);
1534 fbcon_clear_margins(vc, 1);
1535 scrollback_max -= count;
1536 if (scrollback_max < 0)
1538 scrollback_current = 0;
1541 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1544 int count = vc->vc_rows;
1545 unsigned short *d, *s;
1549 d = (u16 *) softback_curr;
1550 if (d == (u16 *) softback_in)
1551 d = (u16 *) vc->vc_origin;
1552 n = softback_curr + delta * vc->vc_size_row;
1553 softback_lines -= delta;
1555 if (softback_curr < softback_top && n < softback_buf) {
1556 n += softback_end - softback_buf;
1557 if (n < softback_top) {
1559 (softback_top - n) / vc->vc_size_row;
1562 } else if (softback_curr >= softback_top
1563 && n < softback_top) {
1565 (softback_top - n) / vc->vc_size_row;
1569 if (softback_curr > softback_in && n >= softback_end) {
1570 n += softback_buf - softback_end;
1571 if (n > softback_in) {
1575 } else if (softback_curr <= softback_in && n > softback_in) {
1580 if (n == softback_curr)
1583 s = (u16 *) softback_curr;
1584 if (s == (u16 *) softback_in)
1585 s = (u16 *) vc->vc_origin;
1587 unsigned short *start;
1591 unsigned short attr = 1;
1594 le = advance_row(s, 1);
1597 if (attr != (c & 0xff00)) {
1600 fbcon_putcs(vc, start, s - start,
1606 if (c == scr_readw(d)) {
1608 fbcon_putcs(vc, start, s - start,
1621 fbcon_putcs(vc, start, s - start, line, x);
1623 if (d == (u16 *) softback_end)
1624 d = (u16 *) softback_buf;
1625 if (d == (u16 *) softback_in)
1626 d = (u16 *) vc->vc_origin;
1627 if (s == (u16 *) softback_end)
1628 s = (u16 *) softback_buf;
1629 if (s == (u16 *) softback_in)
1630 s = (u16 *) vc->vc_origin;
1634 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1635 int line, int count, int dy)
1637 unsigned short *s = (unsigned short *)
1638 (vc->vc_origin + vc->vc_size_row * line);
1641 unsigned short *start = s;
1642 unsigned short *le = advance_row(s, 1);
1645 unsigned short attr = 1;
1649 if (attr != (c & 0xff00)) {
1652 fbcon_putcs(vc, start, s - start,
1658 console_conditional_schedule();
1662 fbcon_putcs(vc, start, s - start, dy, x);
1663 console_conditional_schedule();
1668 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1669 struct display *p, int line, int count, int ycount)
1671 int offset = ycount * vc->vc_cols;
1672 unsigned short *d = (unsigned short *)
1673 (vc->vc_origin + vc->vc_size_row * line);
1674 unsigned short *s = d + offset;
1675 struct fbcon_ops *ops = info->fbcon_par;
1678 unsigned short *start = s;
1679 unsigned short *le = advance_row(s, 1);
1686 if (c == scr_readw(d)) {
1688 ops->bmove(vc, info, line + ycount, x,
1689 line, x, 1, s-start);
1699 console_conditional_schedule();
1704 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1706 console_conditional_schedule();
1711 /* NOTE: We subtract two lines from these pointers */
1712 s -= vc->vc_size_row;
1713 d -= vc->vc_size_row;
1718 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1719 int line, int count, int offset)
1721 unsigned short *d = (unsigned short *)
1722 (vc->vc_origin + vc->vc_size_row * line);
1723 unsigned short *s = d + offset;
1726 unsigned short *start = s;
1727 unsigned short *le = advance_row(s, 1);
1730 unsigned short attr = 1;
1734 if (attr != (c & 0xff00)) {
1737 fbcon_putcs(vc, start, s - start,
1743 if (c == scr_readw(d)) {
1745 fbcon_putcs(vc, start, s - start,
1755 console_conditional_schedule();
1760 fbcon_putcs(vc, start, s - start, line, x);
1761 console_conditional_schedule();
1766 /* NOTE: We subtract two lines from these pointers */
1767 s -= vc->vc_size_row;
1768 d -= vc->vc_size_row;
1773 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1778 if (vc->vc_num != fg_console)
1780 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1783 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1785 p = advance_row(p, 1);
1786 softback_in += vc->vc_size_row;
1787 if (softback_in == softback_end)
1788 softback_in = softback_buf;
1789 if (softback_in == softback_top) {
1790 softback_top += vc->vc_size_row;
1791 if (softback_top == softback_end)
1792 softback_top = softback_buf;
1795 softback_curr = softback_in;
1798 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1801 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1802 struct display *p = &fb_display[vc->vc_num];
1803 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1805 if (fbcon_is_inactive(vc, info))
1808 fbcon_cursor(vc, CM_ERASE);
1811 * ++Geert: Only use ywrap/ypan if the console is in text mode
1812 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1813 * whole screen (prevents flicker).
1818 if (count > vc->vc_rows) /* Maximum realistic size */
1819 count = vc->vc_rows;
1821 fbcon_softback_note(vc, t, count);
1822 if (logo_shown >= 0)
1824 if (SPLASH_DATA(info))
1826 switch (p->scrollmode) {
1828 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1830 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1831 scr_memsetw((unsigned short *) (vc->vc_origin +
1834 vc->vc_video_erase_char,
1835 vc->vc_size_row * count);
1839 case SCROLL_WRAP_MOVE:
1840 if (b - t - count > 3 * vc->vc_rows >> 2) {
1842 fbcon_bmove(vc, 0, 0, count, 0, t,
1844 ywrap_up(vc, count);
1845 if (vc->vc_rows - b > 0)
1846 fbcon_bmove(vc, b - count, 0, b, 0,
1849 } else if (info->flags & FBINFO_READS_FAST)
1850 fbcon_bmove(vc, t + count, 0, t, 0,
1851 b - t - count, vc->vc_cols);
1854 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1857 case SCROLL_PAN_REDRAW:
1858 if ((p->yscroll + count <=
1859 2 * (p->vrows - vc->vc_rows))
1860 && ((!scroll_partial && (b - t == vc->vc_rows))
1863 3 * vc->vc_rows >> 2)))) {
1865 fbcon_redraw_move(vc, p, 0, t, count);
1866 ypan_up_redraw(vc, t, count);
1867 if (vc->vc_rows - b > 0)
1868 fbcon_redraw_move(vc, p, b,
1869 vc->vc_rows - b, b);
1871 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1872 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1875 case SCROLL_PAN_MOVE:
1876 if ((p->yscroll + count <=
1877 2 * (p->vrows - vc->vc_rows))
1878 && ((!scroll_partial && (b - t == vc->vc_rows))
1881 3 * vc->vc_rows >> 2)))) {
1883 fbcon_bmove(vc, 0, 0, count, 0, t,
1886 if (vc->vc_rows - b > 0)
1887 fbcon_bmove(vc, b - count, 0, b, 0,
1890 } else if (info->flags & FBINFO_READS_FAST)
1891 fbcon_bmove(vc, t + count, 0, t, 0,
1892 b - t - count, vc->vc_cols);
1895 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1900 fbcon_redraw(vc, p, t, b - t - count,
1901 count * vc->vc_cols);
1902 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1903 scr_memsetw((unsigned short *) (vc->vc_origin +
1906 vc->vc_video_erase_char,
1907 vc->vc_size_row * count);
1913 if (count > vc->vc_rows) /* Maximum realistic size */
1914 count = vc->vc_rows;
1915 if (logo_shown >= 0)
1917 if (SPLASH_DATA(info))
1919 switch (p->scrollmode) {
1921 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1923 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1924 scr_memsetw((unsigned short *) (vc->vc_origin +
1927 vc->vc_video_erase_char,
1928 vc->vc_size_row * count);
1932 case SCROLL_WRAP_MOVE:
1933 if (b - t - count > 3 * vc->vc_rows >> 2) {
1934 if (vc->vc_rows - b > 0)
1935 fbcon_bmove(vc, b, 0, b - count, 0,
1938 ywrap_down(vc, count);
1940 fbcon_bmove(vc, count, 0, 0, 0, t,
1942 } else if (info->flags & FBINFO_READS_FAST)
1943 fbcon_bmove(vc, t, 0, t + count, 0,
1944 b - t - count, vc->vc_cols);
1947 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1950 case SCROLL_PAN_MOVE:
1951 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1952 && ((!scroll_partial && (b - t == vc->vc_rows))
1955 3 * vc->vc_rows >> 2)))) {
1956 if (vc->vc_rows - b > 0)
1957 fbcon_bmove(vc, b, 0, b - count, 0,
1960 ypan_down(vc, count);
1962 fbcon_bmove(vc, count, 0, 0, 0, t,
1964 } else if (info->flags & FBINFO_READS_FAST)
1965 fbcon_bmove(vc, t, 0, t + count, 0,
1966 b - t - count, vc->vc_cols);
1969 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1972 case SCROLL_PAN_REDRAW:
1973 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1974 && ((!scroll_partial && (b - t == vc->vc_rows))
1977 3 * vc->vc_rows >> 2)))) {
1978 if (vc->vc_rows - b > 0)
1979 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1981 ypan_down_redraw(vc, t, count);
1983 fbcon_redraw_move(vc, p, count, t, 0);
1985 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1986 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1991 fbcon_redraw(vc, p, b - 1, b - t - count,
1992 -count * vc->vc_cols);
1993 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1994 scr_memsetw((unsigned short *) (vc->vc_origin +
1997 vc->vc_video_erase_char,
1998 vc->vc_size_row * count);
2006 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2007 int height, int width)
2009 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2010 struct display *p = &fb_display[vc->vc_num];
2012 if (fbcon_is_inactive(vc, info))
2015 if (!width || !height)
2018 /* Split blits that cross physical y_wrap case.
2019 * Pathological case involves 4 blits, better to use recursive
2020 * code rather than unrolled case
2022 * Recursive invocations don't need to erase the cursor over and
2023 * over again, so we use fbcon_bmove_rec()
2025 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2026 p->vrows - p->yscroll);
2029 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2030 int dy, int dx, int height, int width, u_int y_break)
2032 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2033 struct fbcon_ops *ops = info->fbcon_par;
2036 if (sy < y_break && sy + height > y_break) {
2038 if (dy < sy) { /* Avoid trashing self */
2039 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2041 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2042 height - b, width, y_break);
2044 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2045 height - b, width, y_break);
2046 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2052 if (dy < y_break && dy + height > y_break) {
2054 if (dy < sy) { /* Avoid trashing self */
2055 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2057 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2058 height - b, width, y_break);
2060 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2061 height - b, width, y_break);
2062 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2068 if (SPLASH_DATA(info) && sy == dy && height == 1) {
2069 /*must use slower redraw bmove to keep background pic intact*/
2070 splash_bmove_redraw(vc, info, sy, sx, dx, width);
2073 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2077 static void updatescrollmode(struct display *p,
2078 struct fb_info *info,
2081 struct fbcon_ops *ops = info->fbcon_par;
2082 int fh = vc->vc_font.height;
2083 int cap = info->flags;
2085 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2086 info->fix.xpanstep);
2087 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2088 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2089 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2090 info->var.xres_virtual);
2091 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2092 divides(ypan, vc->vc_font.height) && vyres > yres;
2093 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2094 divides(ywrap, vc->vc_font.height) &&
2095 divides(vc->vc_font.height, vyres) &&
2096 divides(vc->vc_font.height, yres);
2097 int reading_fast = cap & FBINFO_READS_FAST;
2098 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2099 !(cap & FBINFO_HWACCEL_DISABLED);
2100 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2101 !(cap & FBINFO_HWACCEL_DISABLED);
2103 p->vrows = vyres/fh;
2104 if (yres > (fh * (vc->vc_rows + 1)))
2105 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2106 if ((yres % fh) && (vyres % fh < yres % fh))
2109 if (good_wrap || good_pan) {
2110 if (reading_fast || fast_copyarea)
2111 p->scrollmode = good_wrap ?
2112 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2114 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2117 if (reading_fast || (fast_copyarea && !fast_imageblit))
2118 p->scrollmode = SCROLL_MOVE;
2120 p->scrollmode = SCROLL_REDRAW;
2124 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2125 unsigned int height, unsigned int user)
2127 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2128 struct fbcon_ops *ops = info->fbcon_par;
2129 struct display *p = &fb_display[vc->vc_num];
2130 struct fb_var_screeninfo var = info->var;
2131 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2133 virt_w = FBCON_SWAP(ops->rotate, width, height);
2134 virt_h = FBCON_SWAP(ops->rotate, height, width);
2135 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2136 vc->vc_font.height);
2137 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2139 var.xres = virt_w * virt_fw;
2140 var.yres = virt_h * virt_fh;
2141 x_diff = info->var.xres - var.xres;
2142 y_diff = info->var.yres - var.yres;
2143 if (x_diff < 0 || x_diff > virt_fw ||
2144 y_diff < 0 || y_diff > virt_fh) {
2145 const struct fb_videomode *mode;
2147 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2148 mode = fb_find_best_mode(&var, &info->modelist);
2151 display_to_var(&var, p);
2152 fb_videomode_to_var(&var, mode);
2154 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2157 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2158 if (CON_IS_VISIBLE(vc)) {
2159 var.activate = FB_ACTIVATE_NOW |
2161 fb_set_var(info, &var);
2163 var_to_display(p, &info->var, info);
2164 ops->var = info->var;
2166 updatescrollmode(p, info, vc);
2170 static int fbcon_switch(struct vc_data *vc)
2172 struct fb_info *info, *old_info = NULL;
2173 struct fbcon_ops *ops;
2174 struct display *p = &fb_display[vc->vc_num];
2175 struct fb_var_screeninfo var;
2176 int i, ret, prev_console, charcnt = 256;
2178 info = registered_fb[con2fb_map[vc->vc_num]];
2179 ops = info->fbcon_par;
2181 #ifdef CONFIG_BOOTSPLASH
2183 struct splash_data *prev_sd = vc->vc_splash_data;
2184 splash_prepare(vc, info);
2185 if (vc->vc_splash_data && vc->vc_splash_data->splash_state &&
2186 vc->vc_splash_data != prev_sd) {
2187 vc_resize(vc, vc->vc_splash_data->splash_vc_text_wi
2188 / vc->vc_font.width,
2189 vc->vc_splash_data->splash_vc_text_he
2190 / vc->vc_font.height);
2191 con_remap_def_color(vc,
2192 vc->vc_splash_data->imgd->splash_color << 4
2193 | vc->vc_splash_data->imgd->splash_fg_color);
2200 fbcon_set_origin(vc);
2201 softback_top = softback_curr = softback_in = softback_buf;
2203 fbcon_update_softback(vc);
2206 if (logo_shown >= 0) {
2207 struct vc_data *conp2 = vc_cons[logo_shown].d;
2209 if (conp2->vc_top == logo_lines
2210 && conp2->vc_bottom == conp2->vc_rows)
2212 logo_shown = FBCON_LOGO_CANSHOW;
2215 prev_console = ops->currcon;
2216 if (prev_console != -1)
2217 old_info = registered_fb[con2fb_map[prev_console]];
2219 * FIXME: If we have multiple fbdev's loaded, we need to
2220 * update all info->currcon. Perhaps, we can place this
2221 * in a centralized structure, but this might break some
2224 * info->currcon = vc->vc_num;
2226 for (i = 0; i < FB_MAX; i++) {
2227 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2228 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2230 o->currcon = vc->vc_num;
2233 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2234 display_to_var(&var, p);
2235 var.activate = FB_ACTIVATE_NOW;
2238 * make sure we don't unnecessarily trip the memcmp()
2241 info->var.activate = var.activate;
2242 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2243 fb_set_var(info, &var);
2244 ops->var = info->var;
2246 if (old_info != NULL && (old_info != info ||
2247 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2248 if (info->fbops->fb_set_par) {
2249 ret = info->fbops->fb_set_par(info);
2252 printk(KERN_ERR "fbcon_switch: detected "
2253 "unhandled fb_set_par error, "
2254 "error code %d\n", ret);
2257 if (old_info != info)
2258 fbcon_del_cursor_timer(old_info);
2261 if (fbcon_is_inactive(vc, info) ||
2262 ops->blank_state != FB_BLANK_UNBLANK)
2263 fbcon_del_cursor_timer(info);
2265 fbcon_add_cursor_timer(info);
2267 set_blitting_type(vc, info);
2268 ops->cursor_reset = 1;
2270 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2271 ops->rotate = FB_ROTATE_UR;
2272 set_blitting_type(vc, info);
2275 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2276 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2279 charcnt = FNTCHARCNT(vc->vc_font.data);
2282 vc->vc_complement_mask <<= 1;
2284 updatescrollmode(p, info, vc);
2286 switch (p->scrollmode) {
2287 case SCROLL_WRAP_MOVE:
2288 scrollback_phys_max = p->vrows - vc->vc_rows;
2290 case SCROLL_PAN_MOVE:
2291 case SCROLL_PAN_REDRAW:
2292 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2293 if (scrollback_phys_max < 0)
2294 scrollback_phys_max = 0;
2297 scrollback_phys_max = 0;
2302 scrollback_current = 0;
2304 if (!fbcon_is_inactive(vc, info)) {
2305 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2306 ops->update_start(info);
2309 fbcon_set_palette(vc, color_table);
2310 fbcon_clear_margins(vc, 0);
2312 if (logo_shown == FBCON_LOGO_DRAW) {
2314 logo_shown = fg_console;
2315 /* This is protected above by initmem_freed */
2316 fb_show_logo(info, ops->rotate);
2318 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2319 vc->vc_size_row * (vc->vc_bottom -
2326 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2329 struct fb_event event;
2331 if (SPLASH_DATA(info)) {
2332 splash_blank(vc, info, blank);
2337 unsigned short charmask = vc->vc_hi_font_mask ?
2339 unsigned short oldc;
2341 oldc = vc->vc_video_erase_char;
2342 vc->vc_video_erase_char &= charmask;
2343 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2344 vc->vc_video_erase_char = oldc;
2348 if (!lock_fb_info(info))
2351 event.data = ␣
2352 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2353 unlock_fb_info(info);
2356 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2358 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2359 struct fbcon_ops *ops = info->fbcon_par;
2362 struct fb_var_screeninfo var = info->var;
2367 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2368 fb_set_var(info, &var);
2370 ops->var = info->var;
2374 if (!fbcon_is_inactive(vc, info)) {
2375 if (ops->blank_state != blank) {
2376 ops->blank_state = blank;
2377 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2378 ops->cursor_flash = (!blank);
2380 if (!(info->flags & FBINFO_MISC_USEREVENT))
2381 if (fb_blank(info, blank))
2382 fbcon_generic_blank(vc, info, blank);
2389 if (mode_switch || fbcon_is_inactive(vc, info) ||
2390 ops->blank_state != FB_BLANK_UNBLANK)
2391 fbcon_del_cursor_timer(info);
2393 fbcon_add_cursor_timer(info);
2398 static int fbcon_debug_enter(struct vc_data *vc)
2400 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2401 struct fbcon_ops *ops = info->fbcon_par;
2403 ops->save_graphics = ops->graphics;
2405 if (info->fbops->fb_debug_enter)
2406 info->fbops->fb_debug_enter(info);
2407 fbcon_set_palette(vc, color_table);
2411 static int fbcon_debug_leave(struct vc_data *vc)
2413 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2414 struct fbcon_ops *ops = info->fbcon_par;
2416 ops->graphics = ops->save_graphics;
2417 if (info->fbops->fb_debug_leave)
2418 info->fbops->fb_debug_leave(info);
2422 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2424 u8 *fontdata = vc->vc_font.data;
2425 u8 *data = font->data;
2428 font->width = vc->vc_font.width;
2429 font->height = vc->vc_font.height;
2430 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2434 if (font->width <= 8) {
2435 j = vc->vc_font.height;
2436 for (i = 0; i < font->charcount; i++) {
2437 memcpy(data, fontdata, j);
2438 memset(data + j, 0, 32 - j);
2442 } else if (font->width <= 16) {
2443 j = vc->vc_font.height * 2;
2444 for (i = 0; i < font->charcount; i++) {
2445 memcpy(data, fontdata, j);
2446 memset(data + j, 0, 64 - j);
2450 } else if (font->width <= 24) {
2451 for (i = 0; i < font->charcount; i++) {
2452 for (j = 0; j < vc->vc_font.height; j++) {
2453 *data++ = fontdata[0];
2454 *data++ = fontdata[1];
2455 *data++ = fontdata[2];
2456 fontdata += sizeof(u32);
2458 memset(data, 0, 3 * (32 - j));
2459 data += 3 * (32 - j);
2462 j = vc->vc_font.height * 4;
2463 for (i = 0; i < font->charcount; i++) {
2464 memcpy(data, fontdata, j);
2465 memset(data + j, 0, 128 - j);
2473 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2474 const u8 * data, int userfont)
2476 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2477 struct fbcon_ops *ops = info->fbcon_par;
2478 struct display *p = &fb_display[vc->vc_num];
2481 char *old_data = NULL;
2483 if (CON_IS_VISIBLE(vc) && softback_lines)
2484 fbcon_set_origin(vc);
2486 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2488 old_data = vc->vc_font.data;
2490 cnt = FNTCHARCNT(data);
2493 vc->vc_font.data = (void *)(p->fontdata = data);
2494 if ((p->userfont = userfont))
2496 vc->vc_font.width = w;
2497 vc->vc_font.height = h;
2498 if (vc->vc_hi_font_mask && cnt == 256) {
2499 vc->vc_hi_font_mask = 0;
2500 if (vc->vc_can_do_color) {
2501 vc->vc_complement_mask >>= 1;
2502 vc->vc_s_complement_mask >>= 1;
2505 /* ++Edmund: reorder the attribute bits */
2506 if (vc->vc_can_do_color) {
2507 unsigned short *cp =
2508 (unsigned short *) vc->vc_origin;
2509 int count = vc->vc_screenbuf_size / 2;
2511 for (; count > 0; count--, cp++) {
2513 scr_writew(((c & 0xfe00) >> 1) |
2516 c = vc->vc_video_erase_char;
2517 vc->vc_video_erase_char =
2518 ((c & 0xfe00) >> 1) | (c & 0xff);
2521 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2522 vc->vc_hi_font_mask = 0x100;
2523 if (vc->vc_can_do_color) {
2524 vc->vc_complement_mask <<= 1;
2525 vc->vc_s_complement_mask <<= 1;
2528 /* ++Edmund: reorder the attribute bits */
2530 unsigned short *cp =
2531 (unsigned short *) vc->vc_origin;
2532 int count = vc->vc_screenbuf_size / 2;
2534 for (; count > 0; count--, cp++) {
2535 unsigned short newc;
2537 if (vc->vc_can_do_color)
2539 ((c & 0xff00) << 1) | (c &
2543 scr_writew(newc, cp);
2545 c = vc->vc_video_erase_char;
2546 if (vc->vc_can_do_color) {
2547 vc->vc_video_erase_char =
2548 ((c & 0xff00) << 1) | (c & 0xff);
2551 vc->vc_video_erase_char = c & ~0x100;
2559 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2560 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2561 if (SPLASH_DATA(info)) {
2562 cols = TEXT_WIDTH_FROM_SPLASH_DATA(info);
2563 rows = TEXT_HIGHT_FROM_SPLASH_DATA(info);
2567 vc_resize(vc, cols, rows);
2568 if (CON_IS_VISIBLE(vc) && softback_buf)
2569 fbcon_update_softback(vc);
2570 } else if (CON_IS_VISIBLE(vc)
2571 && vc->vc_mode == KD_TEXT) {
2572 fbcon_clear_margins(vc, 0);
2576 if (old_data && (--REFCOUNT(old_data) == 0))
2577 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2581 static int fbcon_copy_font(struct vc_data *vc, int con)
2583 struct display *od = &fb_display[con];
2584 struct console_font *f = &vc->vc_font;
2586 if (od->fontdata == f->data)
2587 return 0; /* already the same font... */
2588 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2592 * User asked to set font; we are guaranteed that
2593 * a) width and height are in range 1..32
2594 * b) charcount does not exceed 512
2595 * but lets not assume that, since someone might someday want to use larger
2596 * fonts. And charcount of 512 is small for unicode support.
2598 * However, user space gives the font in 32 rows , regardless of
2599 * actual font height. So a new API is needed if support for larger fonts
2600 * is ever implemented.
2603 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2605 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2606 unsigned charcount = font->charcount;
2607 int w = font->width;
2608 int h = font->height;
2611 u8 *new_data, *data = font->data;
2612 int pitch = (font->width+7) >> 3;
2614 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2615 * If not this check should be changed to charcount < 256 */
2616 if (charcount != 256 && charcount != 512)
2619 /* Make sure drawing engine can handle the font */
2620 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2621 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2624 /* Make sure driver can handle the font length */
2625 if (fbcon_invalid_charcount(info, charcount))
2628 size = h * pitch * charcount;
2630 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2635 new_data += FONT_EXTRA_WORDS * sizeof(int);
2636 FNTSIZE(new_data) = size;
2637 FNTCHARCNT(new_data) = charcount;
2638 REFCOUNT(new_data) = 0; /* usage counter */
2639 for (i=0; i< charcount; i++) {
2640 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2643 /* Since linux has a nice crc32 function use it for counting font
2645 csum = crc32(0, new_data, size);
2647 FNTSUM(new_data) = csum;
2648 /* Check if the same font is on some other console already */
2649 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2650 struct vc_data *tmp = vc_cons[i].d;
2652 if (fb_display[i].userfont &&
2653 fb_display[i].fontdata &&
2654 FNTSUM(fb_display[i].fontdata) == csum &&
2655 FNTSIZE(fb_display[i].fontdata) == size &&
2656 tmp->vc_font.width == w &&
2657 !memcmp(fb_display[i].fontdata, new_data, size)) {
2658 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2659 new_data = (u8 *)fb_display[i].fontdata;
2663 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2666 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2668 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2669 const struct font_desc *f;
2672 f = get_default_font(info->var.xres, info->var.yres,
2673 info->pixmap.blit_x, info->pixmap.blit_y);
2674 else if (!(f = find_font(name)))
2677 font->width = f->width;
2678 font->height = f->height;
2679 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2682 static u16 palette_red[16];
2683 static u16 palette_green[16];
2684 static u16 palette_blue[16];
2686 static struct fb_cmap palette_cmap = {
2687 0, 16, palette_red, palette_green, palette_blue, NULL
2690 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2692 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2696 if (fbcon_is_inactive(vc, info))
2699 if (!CON_IS_VISIBLE(vc))
2702 depth = fb_get_color_depth(&info->var, &info->fix);
2704 for (i = j = 0; i < 16; i++) {
2706 val = vc->vc_palette[j++];
2707 palette_red[k] = (val << 8) | val;
2708 val = vc->vc_palette[j++];
2709 palette_green[k] = (val << 8) | val;
2710 val = vc->vc_palette[j++];
2711 palette_blue[k] = (val << 8) | val;
2713 palette_cmap.len = 16;
2714 palette_cmap.start = 0;
2716 * If framebuffer is capable of less than 16 colors,
2717 * use default palette of fbcon.
2720 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2722 return fb_set_cmap(&palette_cmap, info);
2725 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2730 if (vc->vc_num != fg_console || !softback_lines)
2731 return (u16 *) (vc->vc_origin + offset);
2732 line = offset / vc->vc_size_row;
2733 if (line >= softback_lines)
2734 return (u16 *) (vc->vc_origin + offset -
2735 softback_lines * vc->vc_size_row);
2736 p = softback_curr + offset;
2737 if (p >= softback_end)
2738 p += softback_buf - softback_end;
2742 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2748 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2749 unsigned long offset = (pos - vc->vc_origin) / 2;
2751 x = offset % vc->vc_cols;
2752 y = offset / vc->vc_cols;
2753 if (vc->vc_num == fg_console)
2754 y += softback_lines;
2755 ret = pos + (vc->vc_cols - x) * 2;
2756 } else if (vc->vc_num == fg_console && softback_lines) {
2757 unsigned long offset = pos - softback_curr;
2759 if (pos < softback_curr)
2760 offset += softback_end - softback_buf;
2762 x = offset % vc->vc_cols;
2763 y = offset / vc->vc_cols;
2764 ret = pos + (vc->vc_cols - x) * 2;
2765 if (ret == softback_end)
2767 if (ret == softback_in)
2768 ret = vc->vc_origin;
2770 /* Should not happen */
2772 ret = vc->vc_origin;
2781 /* As we might be inside of softback, we may work with non-contiguous buffer,
2782 that's why we have to use a separate routine. */
2783 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2786 u16 a = scr_readw(p);
2787 if (!vc->vc_can_do_color)
2789 else if (vc->vc_hi_font_mask == 0x100)
2790 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2791 (((a) & 0x0e00) << 4);
2793 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2794 (((a) & 0x0700) << 4);
2796 if (p == (u16 *) softback_end)
2797 p = (u16 *) softback_buf;
2798 if (p == (u16 *) softback_in)
2799 p = (u16 *) vc->vc_origin;
2803 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2805 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2806 struct fbcon_ops *ops = info->fbcon_par;
2807 struct display *disp = &fb_display[fg_console];
2808 int offset, limit, scrollback_old;
2811 if (vc->vc_num != fg_console)
2813 if (vc->vc_mode != KD_TEXT || !lines)
2815 if (logo_shown >= 0) {
2816 struct vc_data *conp2 = vc_cons[logo_shown].d;
2818 if (conp2->vc_top == logo_lines
2819 && conp2->vc_bottom == conp2->vc_rows)
2821 if (logo_shown == vc->vc_num) {
2827 logo_lines * vc->vc_size_row;
2828 for (i = 0; i < logo_lines; i++) {
2829 if (p == softback_top)
2831 if (p == softback_buf)
2833 p -= vc->vc_size_row;
2834 q -= vc->vc_size_row;
2835 scr_memcpyw((u16 *) q, (u16 *) p,
2838 softback_in = softback_curr = p;
2839 update_region(vc, vc->vc_origin,
2840 logo_lines * vc->vc_cols);
2842 logo_shown = FBCON_LOGO_CANSHOW;
2844 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2845 fbcon_redraw_softback(vc, disp, lines);
2846 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2850 if (!scrollback_phys_max)
2853 scrollback_old = scrollback_current;
2854 scrollback_current -= lines;
2855 if (scrollback_current < 0)
2856 scrollback_current = 0;
2857 else if (scrollback_current > scrollback_max)
2858 scrollback_current = scrollback_max;
2859 if (scrollback_current == scrollback_old)
2862 if (fbcon_is_inactive(vc, info))
2865 fbcon_cursor(vc, CM_ERASE);
2867 offset = disp->yscroll - scrollback_current;
2868 limit = disp->vrows;
2869 switch (disp->scrollmode) {
2870 case SCROLL_WRAP_MOVE:
2871 info->var.vmode |= FB_VMODE_YWRAP;
2873 case SCROLL_PAN_MOVE:
2874 case SCROLL_PAN_REDRAW:
2875 limit -= vc->vc_rows;
2876 info->var.vmode &= ~FB_VMODE_YWRAP;
2881 else if (offset >= limit)
2884 ops->var.xoffset = 0;
2885 ops->var.yoffset = offset * vc->vc_font.height;
2886 ops->update_start(info);
2888 if (!scrollback_current)
2889 fbcon_cursor(vc, CM_DRAW);
2893 static int fbcon_set_origin(struct vc_data *vc)
2896 fbcon_scrolldelta(vc, softback_lines);
2900 static void fbcon_suspended(struct fb_info *info)
2902 struct vc_data *vc = NULL;
2903 struct fbcon_ops *ops = info->fbcon_par;
2905 if (!ops || ops->currcon < 0)
2907 vc = vc_cons[ops->currcon].d;
2909 /* Clear cursor, restore saved data */
2910 fbcon_cursor(vc, CM_ERASE);
2913 static void fbcon_resumed(struct fb_info *info)
2916 struct fbcon_ops *ops = info->fbcon_par;
2918 if (!ops || ops->currcon < 0)
2920 vc = vc_cons[ops->currcon].d;
2925 static void fbcon_modechanged(struct fb_info *info)
2927 struct fbcon_ops *ops = info->fbcon_par;
2932 if (!ops || ops->currcon < 0)
2934 vc = vc_cons[ops->currcon].d;
2935 if (vc->vc_mode != KD_TEXT ||
2936 registered_fb[con2fb_map[ops->currcon]] != info)
2939 p = &fb_display[vc->vc_num];
2940 set_blitting_type(vc, info);
2942 if (CON_IS_VISIBLE(vc)) {
2943 var_to_display(p, &info->var, info);
2944 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2945 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2946 cols /= vc->vc_font.width;
2947 rows /= vc->vc_font.height;
2948 vc_resize(vc, cols, rows);
2949 updatescrollmode(p, info, vc);
2951 scrollback_current = 0;
2953 if (!fbcon_is_inactive(vc, info)) {
2954 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2955 ops->update_start(info);
2958 fbcon_set_palette(vc, color_table);
2961 fbcon_update_softback(vc);
2965 static void fbcon_set_all_vcs(struct fb_info *info)
2967 struct fbcon_ops *ops = info->fbcon_par;
2970 int i, rows, cols, fg = -1;
2972 if (!ops || ops->currcon < 0)
2975 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2977 if (!vc || vc->vc_mode != KD_TEXT ||
2978 registered_fb[con2fb_map[i]] != info)
2981 if (CON_IS_VISIBLE(vc)) {
2986 p = &fb_display[vc->vc_num];
2987 set_blitting_type(vc, info);
2988 var_to_display(p, &info->var, info);
2989 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2990 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2991 cols /= vc->vc_font.width;
2992 rows /= vc->vc_font.height;
2993 vc_resize(vc, cols, rows);
2997 fbcon_modechanged(info);
3000 static int fbcon_mode_deleted(struct fb_info *info,
3001 struct fb_videomode *mode)
3003 struct fb_info *fb_info;
3005 int i, j, found = 0;
3007 /* before deletion, ensure that mode is not in use */
3008 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3012 fb_info = registered_fb[j];
3013 if (fb_info != info)
3018 if (fb_mode_is_equal(p->mode, mode)) {
3026 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3027 static int fbcon_unbind(void)
3031 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3035 fbcon_has_console_bind = 0;
3040 static inline int fbcon_unbind(void)
3044 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3046 static int fbcon_fb_unbind(int idx)
3048 int i, new_idx = -1, ret = 0;
3050 if (!fbcon_has_console_bind)
3053 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3054 if (con2fb_map[i] != idx &&
3055 con2fb_map[i] != -1) {
3061 if (new_idx != -1) {
3062 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3063 if (con2fb_map[i] == idx)
3064 set_con2fb_map(i, new_idx, 0);
3067 ret = fbcon_unbind();
3072 static int fbcon_fb_unregistered(struct fb_info *info)
3077 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3078 if (con2fb_map[i] == idx)
3082 if (idx == info_idx) {
3085 for (i = 0; i < FB_MAX; i++) {
3086 if (registered_fb[i] != NULL) {
3093 if (info_idx != -1) {
3094 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3095 if (con2fb_map[i] == -1)
3096 con2fb_map[i] = info_idx;
3100 if (primary_device == idx)
3101 primary_device = -1;
3103 if (!num_registered_fb)
3104 unregister_con_driver(&fb_con);
3109 static void fbcon_remap_all(int idx)
3112 for (i = first_fb_vc; i <= last_fb_vc; i++)
3113 set_con2fb_map(i, idx, 0);
3115 if (con_is_bound(&fb_con)) {
3116 printk(KERN_INFO "fbcon: Remapping primary device, "
3117 "fb%i, to tty %i-%i\n", idx,
3118 first_fb_vc + 1, last_fb_vc + 1);
3123 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3124 static void fbcon_select_primary(struct fb_info *info)
3126 if (!map_override && primary_device == -1 &&
3127 fb_is_primary_device(info)) {
3130 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3131 info->fix.id, info->node);
3132 primary_device = info->node;
3134 for (i = first_fb_vc; i <= last_fb_vc; i++)
3135 con2fb_map_boot[i] = primary_device;
3137 if (con_is_bound(&fb_con)) {
3138 printk(KERN_INFO "fbcon: Remapping primary device, "
3139 "fb%i, to tty %i-%i\n", info->node,
3140 first_fb_vc + 1, last_fb_vc + 1);
3141 info_idx = primary_device;
3147 static inline void fbcon_select_primary(struct fb_info *info)
3151 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3153 static int fbcon_fb_registered(struct fb_info *info)
3155 int ret = 0, i, idx;
3158 fbcon_select_primary(info);
3160 if (info_idx == -1) {
3161 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3162 if (con2fb_map_boot[i] == idx) {
3169 ret = fbcon_takeover(1);
3171 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3172 if (con2fb_map_boot[i] == idx)
3173 set_con2fb_map(i, idx, 0);
3180 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3182 struct fbcon_ops *ops = info->fbcon_par;
3185 if (!ops || ops->currcon < 0)
3188 vc = vc_cons[ops->currcon].d;
3189 if (vc->vc_mode != KD_TEXT ||
3190 registered_fb[con2fb_map[ops->currcon]] != info)
3193 if (CON_IS_VISIBLE(vc)) {
3197 do_unblank_screen(0);
3199 ops->blank_state = blank;
3202 static void fbcon_new_modelist(struct fb_info *info)
3206 struct fb_var_screeninfo var;
3207 const struct fb_videomode *mode;
3209 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3210 if (registered_fb[con2fb_map[i]] != info)
3212 if (!fb_display[i].mode)
3215 display_to_var(&var, &fb_display[i]);
3216 mode = fb_find_nearest_mode(fb_display[i].mode,
3218 fb_videomode_to_var(&var, mode);
3219 fbcon_set_disp(info, &var, vc->vc_num);
3223 static void fbcon_get_requirement(struct fb_info *info,
3224 struct fb_blit_caps *caps)
3232 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3234 if (vc && vc->vc_mode == KD_TEXT &&
3235 info->node == con2fb_map[i]) {
3237 caps->x |= 1 << (vc->vc_font.width - 1);
3238 caps->y |= 1 << (vc->vc_font.height - 1);
3239 charcnt = (p->userfont) ?
3240 FNTCHARCNT(p->fontdata) : 256;
3241 if (caps->len < charcnt)
3242 caps->len = charcnt;
3246 vc = vc_cons[fg_console].d;
3248 if (vc && vc->vc_mode == KD_TEXT &&
3249 info->node == con2fb_map[fg_console]) {
3250 p = &fb_display[fg_console];
3251 caps->x = 1 << (vc->vc_font.width - 1);
3252 caps->y = 1 << (vc->vc_font.height - 1);
3253 caps->len = (p->userfont) ?
3254 FNTCHARCNT(p->fontdata) : 256;
3259 static int fbcon_event_notify(struct notifier_block *self,
3260 unsigned long action, void *data)
3262 struct fb_event *event = data;
3263 struct fb_info *info = event->info;
3264 struct fb_videomode *mode;
3265 struct fb_con2fbmap *con2fb;
3266 struct fb_blit_caps *caps;
3270 * ignore all events except driver registration and deregistration
3271 * if fbcon is not active
3273 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3274 action == FB_EVENT_FB_UNREGISTERED))
3278 case FB_EVENT_SUSPEND:
3279 fbcon_suspended(info);
3281 case FB_EVENT_RESUME:
3282 fbcon_resumed(info);
3284 case FB_EVENT_MODE_CHANGE:
3285 fbcon_modechanged(info);
3287 case FB_EVENT_MODE_CHANGE_ALL:
3288 fbcon_set_all_vcs(info);
3290 case FB_EVENT_MODE_DELETE:
3292 ret = fbcon_mode_deleted(info, mode);
3294 case FB_EVENT_FB_UNBIND:
3296 ret = fbcon_fb_unbind(idx);
3298 case FB_EVENT_FB_REGISTERED:
3299 ret = fbcon_fb_registered(info);
3301 case FB_EVENT_FB_UNREGISTERED:
3302 ret = fbcon_fb_unregistered(info);
3304 case FB_EVENT_SET_CONSOLE_MAP:
3305 con2fb = event->data;
3306 ret = set_con2fb_map(con2fb->console - 1,
3307 con2fb->framebuffer, 1);
3309 case FB_EVENT_GET_CONSOLE_MAP:
3310 con2fb = event->data;
3311 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3313 case FB_EVENT_BLANK:
3314 fbcon_fb_blanked(info, *(int *)event->data);
3316 case FB_EVENT_NEW_MODELIST:
3317 fbcon_new_modelist(info);
3319 case FB_EVENT_GET_REQ:
3321 fbcon_get_requirement(info, caps);
3323 case FB_EVENT_REMAP_ALL_CONSOLE:
3325 fbcon_remap_all(idx);
3333 * The console `switch' structure for the frame buffer based console
3336 static const struct consw fb_con = {
3337 .owner = THIS_MODULE,
3338 .con_startup = fbcon_startup,
3339 .con_init = fbcon_init,
3340 .con_deinit = fbcon_deinit,
3341 .con_clear = fbcon_clear,
3342 .con_putc = fbcon_putc,
3343 .con_putcs = fbcon_putcs,
3344 .con_cursor = fbcon_cursor,
3345 .con_scroll = fbcon_scroll,
3346 .con_bmove = fbcon_bmove,
3347 .con_switch = fbcon_switch,
3348 .con_blank = fbcon_blank,
3349 .con_font_set = fbcon_set_font,
3350 .con_font_get = fbcon_get_font,
3351 .con_font_default = fbcon_set_def_font,
3352 .con_font_copy = fbcon_copy_font,
3353 .con_set_palette = fbcon_set_palette,
3354 .con_scrolldelta = fbcon_scrolldelta,
3355 .con_set_origin = fbcon_set_origin,
3356 .con_invert_region = fbcon_invert_region,
3357 .con_screen_pos = fbcon_screen_pos,
3358 .con_getxy = fbcon_getxy,
3359 .con_resize = fbcon_resize,
3360 .con_debug_enter = fbcon_debug_enter,
3361 .con_debug_leave = fbcon_debug_leave,
3364 static struct notifier_block fbcon_event_notifier = {
3365 .notifier_call = fbcon_event_notify,
3368 static ssize_t store_rotate(struct device *device,
3369 struct device_attribute *attr, const char *buf,
3372 struct fb_info *info;
3376 if (fbcon_has_exited)
3380 idx = con2fb_map[fg_console];
3382 if (idx == -1 || registered_fb[idx] == NULL)
3385 info = registered_fb[idx];
3386 rotate = simple_strtoul(buf, last, 0);
3387 fbcon_rotate(info, rotate);
3393 static ssize_t store_rotate_all(struct device *device,
3394 struct device_attribute *attr,const char *buf,
3397 struct fb_info *info;
3401 if (fbcon_has_exited)
3405 idx = con2fb_map[fg_console];
3407 if (idx == -1 || registered_fb[idx] == NULL)
3410 info = registered_fb[idx];
3411 rotate = simple_strtoul(buf, last, 0);
3412 fbcon_rotate_all(info, rotate);
3418 static ssize_t show_rotate(struct device *device,
3419 struct device_attribute *attr,char *buf)
3421 struct fb_info *info;
3422 int rotate = 0, idx;
3424 if (fbcon_has_exited)
3428 idx = con2fb_map[fg_console];
3430 if (idx == -1 || registered_fb[idx] == NULL)
3433 info = registered_fb[idx];
3434 rotate = fbcon_get_rotate(info);
3437 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3440 static ssize_t show_cursor_blink(struct device *device,
3441 struct device_attribute *attr, char *buf)
3443 struct fb_info *info;
3444 struct fbcon_ops *ops;
3445 int idx, blink = -1;
3447 if (fbcon_has_exited)
3451 idx = con2fb_map[fg_console];
3453 if (idx == -1 || registered_fb[idx] == NULL)
3456 info = registered_fb[idx];
3457 ops = info->fbcon_par;
3462 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3465 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3468 static ssize_t store_cursor_blink(struct device *device,
3469 struct device_attribute *attr,
3470 const char *buf, size_t count)
3472 struct fb_info *info;
3476 if (fbcon_has_exited)
3480 idx = con2fb_map[fg_console];
3482 if (idx == -1 || registered_fb[idx] == NULL)
3485 info = registered_fb[idx];
3487 if (!info->fbcon_par)
3490 blink = simple_strtoul(buf, last, 0);
3493 fbcon_cursor_noblink = 0;
3494 fbcon_add_cursor_timer(info);
3496 fbcon_cursor_noblink = 1;
3497 fbcon_del_cursor_timer(info);
3505 static struct device_attribute device_attrs[] = {
3506 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3507 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3508 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3509 store_cursor_blink),
3512 static int fbcon_init_device(void)
3516 fbcon_has_sysfs = 1;
3518 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3519 error = device_create_file(fbcon_device, &device_attrs[i]);
3527 device_remove_file(fbcon_device, &device_attrs[i]);
3529 fbcon_has_sysfs = 0;
3535 static void fbcon_start(void)
3537 if (num_registered_fb) {
3542 for (i = 0; i < FB_MAX; i++) {
3543 if (registered_fb[i] != NULL) {
3554 static void fbcon_exit(void)
3556 struct fb_info *info;
3559 if (fbcon_has_exited)
3562 kfree((void *)softback_buf);
3565 for (i = 0; i < FB_MAX; i++) {
3569 info = registered_fb[i];
3574 if (info->queue.func)
3575 pending = cancel_work_sync(&info->queue);
3576 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3579 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3580 if (con2fb_map[j] == i)
3585 if (info->fbops->fb_release)
3586 info->fbops->fb_release(info, 0);
3587 module_put(info->fbops->owner);
3589 if (info->fbcon_par) {
3590 struct fbcon_ops *ops = info->fbcon_par;
3592 fbcon_del_cursor_timer(info);
3593 kfree(ops->cursor_src);
3594 kfree(info->fbcon_par);
3595 info->fbcon_par = NULL;
3598 if (info->queue.func == fb_flashcursor)
3599 info->queue.func = NULL;
3603 fbcon_has_exited = 1;
3606 static int __init fb_console_init(void)
3611 fb_register_client(&fbcon_event_notifier);
3612 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3615 if (IS_ERR(fbcon_device)) {
3616 printk(KERN_WARNING "Unable to create device "
3617 "for fbcon; errno = %ld\n",
3618 PTR_ERR(fbcon_device));
3619 fbcon_device = NULL;
3621 fbcon_init_device();
3623 for (i = 0; i < MAX_NR_CONSOLES; i++)
3631 module_init(fb_console_init);
3635 static void __exit fbcon_deinit_device(void)
3639 if (fbcon_has_sysfs) {
3640 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3641 device_remove_file(fbcon_device, &device_attrs[i]);
3643 fbcon_has_sysfs = 0;
3647 static void __exit fb_console_exit(void)
3650 fb_unregister_client(&fbcon_event_notifier);
3651 fbcon_deinit_device();
3652 device_destroy(fb_class, MKDEV(0, 0));
3655 unregister_con_driver(&fb_con);
3658 module_exit(fb_console_exit);
3662 MODULE_LICENSE("GPL");