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 */
80 #include <asm/system.h>
83 #include <linux/bootsplash.h>
86 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
88 # define DPRINTK(fmt, args...)
92 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
93 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
94 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
97 static struct display fb_display[MAX_NR_CONSOLES];
99 #ifdef CONFIG_BOOTSPLASH
100 signed char con2fb_map[MAX_NR_CONSOLES];
102 static signed char con2fb_map[MAX_NR_CONSOLES];
104 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
106 static int logo_lines;
107 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
109 static int logo_shown = FBCON_LOGO_CANSHOW;
110 /* Software scrollback */
111 static int fbcon_softback_size = 32768;
112 static unsigned long softback_buf, softback_curr;
113 static unsigned long softback_in;
114 static unsigned long softback_top, softback_end;
115 static int softback_lines;
116 /* console mappings */
117 static int first_fb_vc;
118 static int last_fb_vc = MAX_NR_CONSOLES - 1;
119 static int fbcon_is_default = 1;
120 static int fbcon_has_exited;
121 static int primary_device = -1;
122 static int fbcon_has_console_bind;
124 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
125 static int map_override;
127 static inline void fbcon_map_override(void)
132 static inline void fbcon_map_override(void)
135 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
138 static char fontname[40];
140 /* current fb_info */
141 static int info_idx = -1;
143 /* console rotation */
144 static int initial_rotation;
145 static int fbcon_has_sysfs;
147 static const struct consw fb_con;
149 #define CM_SOFTBACK (8)
151 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
153 static int fbcon_set_origin(struct vc_data *);
155 #define CURSOR_DRAW_DELAY (1)
157 static int vbl_cursor_cnt;
158 static int fbcon_cursor_noblink;
160 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
163 * Interface used by the world
166 static const char *fbcon_startup(void);
167 static void fbcon_init(struct vc_data *vc, int init);
168 static void fbcon_deinit(struct vc_data *vc);
169 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
171 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
172 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
173 int count, int ypos, int xpos);
174 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
175 static void fbcon_cursor(struct vc_data *vc, int mode);
176 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
178 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
179 int height, int width);
180 static int fbcon_switch(struct vc_data *vc);
181 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
182 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
183 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
188 static __inline__ void ywrap_up(struct vc_data *vc, int count);
189 static __inline__ void ywrap_down(struct vc_data *vc, int count);
190 static __inline__ void ypan_up(struct vc_data *vc, int count);
191 static __inline__ void ypan_down(struct vc_data *vc, int count);
192 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
193 int dy, int dx, int height, int width, u_int y_break);
194 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
196 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
197 int line, int count, int dy);
198 static void fbcon_modechanged(struct fb_info *info);
199 static void fbcon_set_all_vcs(struct fb_info *info);
200 static void fbcon_start(void);
201 static void fbcon_exit(void);
202 static struct device *fbcon_device;
204 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
205 static inline void fbcon_set_rotation(struct fb_info *info)
207 struct fbcon_ops *ops = info->fbcon_par;
209 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
210 ops->p->con_rotate < 4)
211 ops->rotate = ops->p->con_rotate;
216 static void fbcon_rotate(struct fb_info *info, u32 rotate)
218 struct fbcon_ops *ops= info->fbcon_par;
219 struct fb_info *fb_info;
221 if (!ops || ops->currcon == -1)
224 fb_info = registered_fb[con2fb_map[ops->currcon]];
226 if (info == fb_info) {
227 struct display *p = &fb_display[ops->currcon];
230 p->con_rotate = rotate;
234 fbcon_modechanged(info);
238 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
240 struct fbcon_ops *ops = info->fbcon_par;
245 if (!ops || ops->currcon < 0 || rotate > 3)
248 for (i = first_fb_vc; i <= last_fb_vc; i++) {
250 if (!vc || vc->vc_mode != KD_TEXT ||
251 registered_fb[con2fb_map[i]] != info)
254 p = &fb_display[vc->vc_num];
255 p->con_rotate = rotate;
258 fbcon_set_all_vcs(info);
261 static inline void fbcon_set_rotation(struct fb_info *info)
263 struct fbcon_ops *ops = info->fbcon_par;
265 ops->rotate = FB_ROTATE_UR;
268 static void fbcon_rotate(struct fb_info *info, u32 rotate)
273 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
277 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
279 static int fbcon_get_rotate(struct fb_info *info)
281 struct fbcon_ops *ops = info->fbcon_par;
283 return (ops) ? ops->rotate : 0;
286 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
288 struct fbcon_ops *ops = info->fbcon_par;
290 return (info->state != FBINFO_STATE_RUNNING ||
291 vc->vc_mode != KD_TEXT || ops->graphics) &&
292 !vt_force_oops_output(vc);
295 static int get_color(struct vc_data *vc, struct fb_info *info,
298 int depth = fb_get_color_depth(&info->var, &info->fix);
301 if (console_blanked) {
302 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
304 c = vc->vc_video_erase_char & charmask;
308 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
309 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
314 int col = mono_col(info);
316 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
317 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
322 color = (is_fg) ? fg : bg;
327 * Scale down 16-colors to 4 colors. Default 4-color palette
328 * is grayscale. However, simply dividing the values by 4
329 * will not work, as colors 1, 2 and 3 will be scaled-down
330 * to zero rendering them invisible. So empirically convert
331 * colors to a sane 4-level grayscale.
335 color = 0; /* black */
338 color = 2; /* white */
341 color = 1; /* gray */
344 color = 3; /* intense white */
350 * Last 8 entries of default 16-color palette is a more intense
351 * version of the first 8 (i.e., same chrominance, different
362 static void fbcon_update_softback(struct vc_data *vc)
364 int l = fbcon_softback_size / vc->vc_size_row;
367 softback_end = softback_buf + l * vc->vc_size_row;
369 /* Smaller scrollback makes no sense, and 0 would screw
370 the operation totally */
374 static void fb_flashcursor(struct work_struct *work)
376 struct fb_info *info = container_of(work, struct fb_info, queue);
377 struct fbcon_ops *ops = info->fbcon_par;
378 struct vc_data *vc = NULL;
383 if (ops && ops->currcon != -1)
384 vc = vc_cons[ops->currcon].d;
386 if (!vc || !CON_IS_VISIBLE(vc) ||
387 registered_fb[con2fb_map[vc->vc_num]] != info ||
393 c = scr_readw((u16 *) vc->vc_pos);
394 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
396 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
397 get_color(vc, info, c, 0));
401 static void cursor_timer_handler(unsigned long dev_addr)
403 struct fb_info *info = (struct fb_info *) dev_addr;
404 struct fbcon_ops *ops = info->fbcon_par;
406 schedule_work(&info->queue);
407 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
410 static void fbcon_add_cursor_timer(struct fb_info *info)
412 struct fbcon_ops *ops = info->fbcon_par;
414 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
415 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
416 !fbcon_cursor_noblink) {
417 if (!info->queue.func)
418 INIT_WORK(&info->queue, fb_flashcursor);
420 init_timer(&ops->cursor_timer);
421 ops->cursor_timer.function = cursor_timer_handler;
422 ops->cursor_timer.expires = jiffies + HZ / 5;
423 ops->cursor_timer.data = (unsigned long ) info;
424 add_timer(&ops->cursor_timer);
425 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
429 static void fbcon_del_cursor_timer(struct fb_info *info)
431 struct fbcon_ops *ops = info->fbcon_par;
433 if (info->queue.func == fb_flashcursor &&
434 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
435 del_timer_sync(&ops->cursor_timer);
436 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
441 static int __init fb_console_setup(char *this_opt)
446 if (!this_opt || !*this_opt)
449 while ((options = strsep(&this_opt, ",")) != NULL) {
450 if (!strncmp(options, "font:", 5))
451 strcpy(fontname, options + 5);
453 if (!strncmp(options, "scrollback:", 11)) {
456 fbcon_softback_size = simple_strtoul(options, &options, 0);
457 if (*options == 'k' || *options == 'K') {
458 fbcon_softback_size *= 1024;
468 if (!strncmp(options, "map:", 4)) {
471 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
475 (options[j++]-'0') % FB_MAX;
478 fbcon_map_override();
484 if (!strncmp(options, "vc:", 3)) {
487 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
490 if (*options++ == '-')
491 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
492 fbcon_is_default = 0;
495 if (!strncmp(options, "rotate:", 7)) {
498 initial_rotation = simple_strtoul(options, &options, 0);
499 if (initial_rotation > 3)
500 initial_rotation = 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 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;
546 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
550 for (i = first_fb_vc; i <= last_fb_vc; i++) {
555 fbcon_has_console_bind = 1;
562 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
563 int cols, int rows, int new_cols, int new_rows)
565 logo_shown = FBCON_LOGO_DONTSHOW;
568 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
569 int cols, int rows, int new_cols, int new_rows)
571 /* Need to make room for the logo */
572 struct fbcon_ops *ops = info->fbcon_par;
573 int cnt, erase = vc->vc_video_erase_char, step;
574 unsigned short *save = NULL, *r, *q;
577 if (info->flags & FBINFO_MODULE) {
578 logo_shown = FBCON_LOGO_DONTSHOW;
583 * remove underline attribute from erase character
584 * if black and white framebuffer.
586 if (fb_get_color_depth(&info->var, &info->fix) == 1)
588 logo_height = fb_prepare_logo(info, ops->rotate);
589 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
590 q = (unsigned short *) (vc->vc_origin +
591 vc->vc_size_row * rows);
592 step = logo_lines * cols;
593 for (r = q - logo_lines * cols; r < q; r++)
594 if (scr_readw(r) != vc->vc_video_erase_char)
596 if (r != q && new_rows >= rows + logo_lines) {
597 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
599 int i = cols < new_cols ? cols : new_cols;
600 scr_memsetw(save, erase, logo_lines * new_cols * 2);
602 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
603 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
608 /* We can scroll screen down */
610 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
611 scr_memcpyw(r + step, r, vc->vc_size_row);
616 if (vc->vc_y + logo_lines >= rows)
617 lines = rows - vc->vc_y - 1;
621 vc->vc_pos += lines * vc->vc_size_row;
624 scr_memsetw((unsigned short *) vc->vc_origin,
626 vc->vc_size_row * logo_lines);
628 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
629 fbcon_clear_margins(vc, 0);
634 q = (unsigned short *) (vc->vc_origin +
637 scr_memcpyw(q, save, logo_lines * new_cols * 2);
638 vc->vc_y += logo_lines;
639 vc->vc_pos += logo_lines * vc->vc_size_row;
643 if (logo_lines > vc->vc_bottom) {
644 logo_shown = FBCON_LOGO_CANSHOW;
646 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
647 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
648 logo_shown = FBCON_LOGO_DRAW;
649 vc->vc_top = logo_lines;
654 #ifdef CONFIG_FB_TILEBLITTING
655 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
657 struct fbcon_ops *ops = info->fbcon_par;
659 ops->p = &fb_display[vc->vc_num];
661 if ((info->flags & FBINFO_MISC_TILEBLITTING))
662 fbcon_set_tileops(vc, info);
664 fbcon_set_rotation(info);
665 fbcon_set_bitops(ops);
669 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
673 if (info->flags & FBINFO_MISC_TILEBLITTING &&
674 info->tileops->fb_get_tilemax(info) < charcount)
680 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
682 struct fbcon_ops *ops = info->fbcon_par;
684 info->flags &= ~FBINFO_MISC_TILEBLITTING;
685 ops->p = &fb_display[vc->vc_num];
686 fbcon_set_rotation(info);
687 fbcon_set_bitops(ops);
690 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
695 #endif /* CONFIG_MISC_TILEBLITTING */
698 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
699 int unit, int oldidx)
701 struct fbcon_ops *ops = NULL;
704 if (!try_module_get(info->fbops->owner))
707 if (!err && info->fbops->fb_open &&
708 info->fbops->fb_open(info, 0))
712 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
718 info->fbcon_par = ops;
721 set_blitting_type(vc, info);
725 con2fb_map[unit] = oldidx;
726 module_put(info->fbops->owner);
732 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
733 struct fb_info *newinfo, int unit,
734 int oldidx, int found)
736 struct fbcon_ops *ops = oldinfo->fbcon_par;
739 if (oldinfo->fbops->fb_release &&
740 oldinfo->fbops->fb_release(oldinfo, 0)) {
741 con2fb_map[unit] = oldidx;
742 if (!found && newinfo->fbops->fb_release)
743 newinfo->fbops->fb_release(newinfo, 0);
745 module_put(newinfo->fbops->owner);
750 fbcon_del_cursor_timer(oldinfo);
751 kfree(ops->cursor_state.mask);
752 kfree(ops->cursor_data);
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->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 static int set_con2fb_map(int unit, int newidx, int user)
822 struct vc_data *vc = vc_cons[unit].d;
823 int oldidx = con2fb_map[unit];
824 struct fb_info *info = registered_fb[newidx];
825 struct fb_info *oldinfo = NULL;
828 if (oldidx == newidx)
834 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
836 return fbcon_takeover(0);
840 oldinfo = registered_fb[oldidx];
842 found = search_fb_in_map(newidx);
845 con2fb_map[unit] = newidx;
847 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
851 * If old fb is not mapped to any of the consoles,
852 * fbcon should release it.
854 if (!err && oldinfo && !search_fb_in_map(oldidx))
855 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
859 int show_logo = (fg_console == 0 && !user &&
860 logo_shown != FBCON_LOGO_DONTSHOW);
863 fbcon_add_cursor_timer(info);
864 con2fb_map_boot[unit] = newidx;
865 con2fb_init_display(vc, info, unit, show_logo);
868 if (!search_fb_in_map(info_idx))
876 * Low Level Operations
878 /* NOTE: fbcon cannot be __init: it may be called from 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 info->fbcon_par = ops;
965 p->con_rotate = initial_rotation;
966 set_blitting_type(vc, info);
968 if (info->fix.type != FB_TYPE_TEXT) {
969 if (fbcon_softback_size) {
973 kmalloc(fbcon_softback_size,
976 fbcon_softback_size = 0;
982 kfree((void *) softback_buf);
988 softback_in = softback_top = softback_curr =
993 /* Setup default font */
995 if (!fontname[0] || !(font = find_font(fontname)))
996 font = get_default_font(info->var.xres,
999 info->pixmap.blit_y);
1000 vc->vc_font.width = font->width;
1001 vc->vc_font.height = font->height;
1002 vc->vc_font.data = (void *)(p->fontdata = font->data);
1003 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1006 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1007 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1008 cols /= vc->vc_font.width;
1009 rows /= vc->vc_font.height;
1010 vc_resize(vc, cols, rows);
1012 DPRINTK("mode: %s\n", info->fix.id);
1013 DPRINTK("visual: %d\n", info->fix.visual);
1014 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1016 info->var.bits_per_pixel);
1018 fbcon_add_cursor_timer(info);
1019 fbcon_has_exited = 0;
1020 return display_desc;
1023 static void fbcon_init(struct vc_data *vc, int init)
1025 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1026 struct fbcon_ops *ops;
1027 struct vc_data **default_mode = vc->vc_display_fg;
1028 struct vc_data *svc = *default_mode;
1029 struct display *t, *p = &fb_display[vc->vc_num];
1030 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1033 if (info_idx == -1 || info == NULL)
1038 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1039 (info->fix.type == FB_TYPE_TEXT))
1042 if (var_to_display(p, &info->var, info))
1045 if (!info->fbcon_par)
1046 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1048 /* If we are not the first console on this
1049 fb, copy the font from that console */
1050 t = &fb_display[fg_console];
1053 struct vc_data *fvc = vc_cons[fg_console].d;
1055 vc->vc_font.data = (void *)(p->fontdata =
1057 vc->vc_font.width = fvc->vc_font.width;
1058 vc->vc_font.height = fvc->vc_font.height;
1059 p->userfont = t->userfont;
1062 REFCOUNT(p->fontdata)++;
1064 const struct font_desc *font = NULL;
1066 if (!fontname[0] || !(font = find_font(fontname)))
1067 font = get_default_font(info->var.xres,
1069 info->pixmap.blit_x,
1070 info->pixmap.blit_y);
1071 vc->vc_font.width = font->width;
1072 vc->vc_font.height = font->height;
1073 vc->vc_font.data = (void *)(p->fontdata = font->data);
1074 vc->vc_font.charcount = 256; /* FIXME Need to
1075 support more fonts */
1080 charcnt = FNTCHARCNT(p->fontdata);
1082 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1083 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1084 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1085 if (charcnt == 256) {
1086 vc->vc_hi_font_mask = 0;
1088 vc->vc_hi_font_mask = 0x100;
1089 if (vc->vc_can_do_color)
1090 vc->vc_complement_mask <<= 1;
1093 if (!*svc->vc_uni_pagedir_loc)
1094 con_set_default_unimap(svc);
1095 if (!*vc->vc_uni_pagedir_loc)
1096 con_copy_unimap(vc, svc);
1098 ops = info->fbcon_par;
1099 p->con_rotate = initial_rotation;
1100 set_blitting_type(vc, info);
1104 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1105 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1106 new_cols /= vc->vc_font.width;
1107 new_rows /= vc->vc_font.height;
1109 #ifdef CONFIG_BOOTSPLASH
1110 if (vc->vc_splash_data && vc->vc_splash_data->splash_state) {
1111 new_cols = vc->vc_splash_data->splash_vc_text_wi
1112 / vc->vc_font.width;
1113 new_rows = vc->vc_splash_data->splash_vc_text_he
1114 / vc->vc_font.height;
1116 con_remap_def_color(vc,
1117 (vc->vc_splash_data->imgd->splash_color
1119 vc->vc_splash_data->imgd->splash_fg_color);
1125 * We must always set the mode. The mode of the previous console
1126 * driver could be in the same resolution but we are using different
1127 * hardware so we have to initialize the hardware.
1129 * We need to do it in fbcon_init() to prevent screen corruption.
1131 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1132 if (info->fbops->fb_set_par &&
1133 !(ops->flags & FBCON_FLAGS_INIT)) {
1134 ret = info->fbops->fb_set_par(info);
1137 printk(KERN_ERR "fbcon_init: detected "
1138 "unhandled fb_set_par error, "
1139 "error code %d\n", ret);
1142 ops->flags |= FBCON_FLAGS_INIT;
1147 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1148 !(cap & FBINFO_HWACCEL_DISABLED))
1149 p->scrollmode = SCROLL_MOVE;
1150 else /* default to something safe */
1151 p->scrollmode = SCROLL_REDRAW;
1154 * ++guenther: console.c:vc_allocate() relies on initializing
1155 * vc_{cols,rows}, but we must not set those if we are only
1156 * resizing the console.
1159 vc->vc_cols = new_cols;
1160 vc->vc_rows = new_rows;
1162 vc_resize(vc, new_cols, new_rows);
1165 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1167 if (vc == svc && softback_buf)
1168 fbcon_update_softback(vc);
1170 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1171 ops->rotate = FB_ROTATE_UR;
1172 set_blitting_type(vc, info);
1175 ops->p = &fb_display[fg_console];
1178 static void fbcon_free_font(struct display *p)
1180 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1181 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1186 static void fbcon_deinit(struct vc_data *vc)
1188 struct display *p = &fb_display[vc->vc_num];
1189 struct fb_info *info;
1190 struct fbcon_ops *ops;
1194 idx = con2fb_map[vc->vc_num];
1199 info = registered_fb[idx];
1204 ops = info->fbcon_par;
1209 if (CON_IS_VISIBLE(vc))
1210 fbcon_del_cursor_timer(info);
1212 ops->flags &= ~FBCON_FLAGS_INIT;
1215 if (!con_is_bound(&fb_con))
1221 /* ====================================================================== */
1223 /* fbcon_XXX routines - interface used by the world
1225 * This system is now divided into two levels because of complications
1226 * caused by hardware scrolling. Top level functions:
1228 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1230 * handles y values in range [0, scr_height-1] that correspond to real
1231 * screen positions. y_wrap shift means that first line of bitmap may be
1232 * anywhere on this display. These functions convert lineoffsets to
1233 * bitmap offsets and deal with the wrap-around case by splitting blits.
1235 * fbcon_bmove_physical_8() -- These functions fast implementations
1236 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1237 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1241 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1242 * Implies should only really hardware scroll in rows. Only reason for
1243 * restriction is simplicity & efficiency at the moment.
1246 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1249 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1250 struct fbcon_ops *ops = info->fbcon_par;
1252 struct display *p = &fb_display[vc->vc_num];
1255 if (fbcon_is_inactive(vc, info))
1258 if (!height || !width)
1261 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1264 /* Split blits that cross physical y_wrap boundary */
1266 y_break = p->vrows - p->yscroll;
1267 if (sy < y_break && sy + height - 1 >= y_break) {
1268 u_int b = y_break - sy;
1269 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1270 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1273 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1276 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1277 int count, int ypos, int xpos)
1279 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1280 struct display *p = &fb_display[vc->vc_num];
1281 struct fbcon_ops *ops = info->fbcon_par;
1283 if (!fbcon_is_inactive(vc, info))
1284 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1285 get_color(vc, info, scr_readw(s), 1),
1286 get_color(vc, info, scr_readw(s), 0));
1289 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1293 scr_writew(c, &chr);
1294 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1297 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1299 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1300 struct fbcon_ops *ops = info->fbcon_par;
1302 if (!fbcon_is_inactive(vc, info))
1303 ops->clear_margins(vc, info, bottom_only);
1306 static void fbcon_cursor(struct vc_data *vc, int mode)
1308 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1309 struct fbcon_ops *ops = info->fbcon_par;
1311 int c = scr_readw((u16 *) vc->vc_pos);
1313 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1316 if (vc->vc_cursor_type & 0x10)
1317 fbcon_del_cursor_timer(info);
1319 fbcon_add_cursor_timer(info);
1321 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1322 if (mode & CM_SOFTBACK) {
1323 mode &= ~CM_SOFTBACK;
1327 fbcon_set_origin(vc);
1331 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1332 get_color(vc, info, c, 0));
1333 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1336 static int scrollback_phys_max = 0;
1337 static int scrollback_max = 0;
1338 static int scrollback_current = 0;
1340 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1343 struct display *p, *t;
1344 struct vc_data **default_mode, *vc;
1345 struct vc_data *svc;
1346 struct fbcon_ops *ops = info->fbcon_par;
1347 int rows, cols, charcnt = 256;
1349 p = &fb_display[unit];
1351 if (var_to_display(p, var, info))
1354 vc = vc_cons[unit].d;
1359 default_mode = vc->vc_display_fg;
1360 svc = *default_mode;
1361 t = &fb_display[svc->vc_num];
1363 if (!vc->vc_font.data) {
1364 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1365 vc->vc_font.width = (*default_mode)->vc_font.width;
1366 vc->vc_font.height = (*default_mode)->vc_font.height;
1367 p->userfont = t->userfont;
1369 REFCOUNT(p->fontdata)++;
1372 charcnt = FNTCHARCNT(p->fontdata);
1374 var->activate = FB_ACTIVATE_NOW;
1375 info->var.activate = var->activate;
1376 var->yoffset = info->var.yoffset;
1377 var->xoffset = info->var.xoffset;
1378 fb_set_var(info, var);
1379 ops->var = info->var;
1380 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1381 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1382 if (charcnt == 256) {
1383 vc->vc_hi_font_mask = 0;
1385 vc->vc_hi_font_mask = 0x100;
1386 if (vc->vc_can_do_color)
1387 vc->vc_complement_mask <<= 1;
1390 if (!*svc->vc_uni_pagedir_loc)
1391 con_set_default_unimap(svc);
1392 if (!*vc->vc_uni_pagedir_loc)
1393 con_copy_unimap(vc, svc);
1395 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1396 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1397 cols /= vc->vc_font.width;
1398 rows /= vc->vc_font.height;
1399 vc_resize(vc, cols, rows);
1401 if (CON_IS_VISIBLE(vc)) {
1404 fbcon_update_softback(vc);
1408 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1410 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1411 struct fbcon_ops *ops = info->fbcon_par;
1412 struct display *p = &fb_display[vc->vc_num];
1414 p->yscroll += count;
1415 if (p->yscroll >= p->vrows) /* Deal with wrap */
1416 p->yscroll -= p->vrows;
1417 ops->var.xoffset = 0;
1418 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1419 ops->var.vmode |= FB_VMODE_YWRAP;
1420 ops->update_start(info);
1421 scrollback_max += count;
1422 if (scrollback_max > scrollback_phys_max)
1423 scrollback_max = scrollback_phys_max;
1424 scrollback_current = 0;
1427 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1429 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1430 struct fbcon_ops *ops = info->fbcon_par;
1431 struct display *p = &fb_display[vc->vc_num];
1433 p->yscroll -= count;
1434 if (p->yscroll < 0) /* Deal with wrap */
1435 p->yscroll += p->vrows;
1436 ops->var.xoffset = 0;
1437 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1438 ops->var.vmode |= FB_VMODE_YWRAP;
1439 ops->update_start(info);
1440 scrollback_max -= count;
1441 if (scrollback_max < 0)
1443 scrollback_current = 0;
1446 static __inline__ void ypan_up(struct vc_data *vc, int count)
1448 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1449 struct display *p = &fb_display[vc->vc_num];
1450 struct fbcon_ops *ops = info->fbcon_par;
1452 p->yscroll += count;
1453 if (p->yscroll > p->vrows - vc->vc_rows) {
1454 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1455 0, 0, 0, vc->vc_rows, vc->vc_cols);
1456 p->yscroll -= p->vrows - vc->vc_rows;
1459 ops->var.xoffset = 0;
1460 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1461 ops->var.vmode &= ~FB_VMODE_YWRAP;
1462 ops->update_start(info);
1463 fbcon_clear_margins(vc, 1);
1464 scrollback_max += count;
1465 if (scrollback_max > scrollback_phys_max)
1466 scrollback_max = scrollback_phys_max;
1467 scrollback_current = 0;
1470 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1472 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1473 struct fbcon_ops *ops = info->fbcon_par;
1474 struct display *p = &fb_display[vc->vc_num];
1476 p->yscroll += count;
1478 if (p->yscroll > p->vrows - vc->vc_rows) {
1479 p->yscroll -= p->vrows - vc->vc_rows;
1480 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1483 ops->var.xoffset = 0;
1484 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1485 ops->var.vmode &= ~FB_VMODE_YWRAP;
1486 ops->update_start(info);
1487 fbcon_clear_margins(vc, 1);
1488 scrollback_max += count;
1489 if (scrollback_max > scrollback_phys_max)
1490 scrollback_max = scrollback_phys_max;
1491 scrollback_current = 0;
1494 static __inline__ void ypan_down(struct vc_data *vc, int count)
1496 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1497 struct display *p = &fb_display[vc->vc_num];
1498 struct fbcon_ops *ops = info->fbcon_par;
1500 p->yscroll -= count;
1501 if (p->yscroll < 0) {
1502 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1503 0, vc->vc_rows, vc->vc_cols);
1504 p->yscroll += p->vrows - vc->vc_rows;
1507 ops->var.xoffset = 0;
1508 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1509 ops->var.vmode &= ~FB_VMODE_YWRAP;
1510 ops->update_start(info);
1511 fbcon_clear_margins(vc, 1);
1512 scrollback_max -= count;
1513 if (scrollback_max < 0)
1515 scrollback_current = 0;
1518 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1520 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1521 struct fbcon_ops *ops = info->fbcon_par;
1522 struct display *p = &fb_display[vc->vc_num];
1524 p->yscroll -= count;
1526 if (p->yscroll < 0) {
1527 p->yscroll += p->vrows - vc->vc_rows;
1528 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1531 ops->var.xoffset = 0;
1532 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1533 ops->var.vmode &= ~FB_VMODE_YWRAP;
1534 ops->update_start(info);
1535 fbcon_clear_margins(vc, 1);
1536 scrollback_max -= count;
1537 if (scrollback_max < 0)
1539 scrollback_current = 0;
1542 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1545 int count = vc->vc_rows;
1546 unsigned short *d, *s;
1550 d = (u16 *) softback_curr;
1551 if (d == (u16 *) softback_in)
1552 d = (u16 *) vc->vc_origin;
1553 n = softback_curr + delta * vc->vc_size_row;
1554 softback_lines -= delta;
1556 if (softback_curr < softback_top && n < softback_buf) {
1557 n += softback_end - softback_buf;
1558 if (n < softback_top) {
1560 (softback_top - n) / vc->vc_size_row;
1563 } else if (softback_curr >= softback_top
1564 && n < softback_top) {
1566 (softback_top - n) / vc->vc_size_row;
1570 if (softback_curr > softback_in && n >= softback_end) {
1571 n += softback_buf - softback_end;
1572 if (n > softback_in) {
1576 } else if (softback_curr <= softback_in && n > softback_in) {
1581 if (n == softback_curr)
1584 s = (u16 *) softback_curr;
1585 if (s == (u16 *) softback_in)
1586 s = (u16 *) vc->vc_origin;
1588 unsigned short *start;
1592 unsigned short attr = 1;
1595 le = advance_row(s, 1);
1598 if (attr != (c & 0xff00)) {
1601 fbcon_putcs(vc, start, s - start,
1607 if (c == scr_readw(d)) {
1609 fbcon_putcs(vc, start, s - start,
1622 fbcon_putcs(vc, start, s - start, line, x);
1624 if (d == (u16 *) softback_end)
1625 d = (u16 *) softback_buf;
1626 if (d == (u16 *) softback_in)
1627 d = (u16 *) vc->vc_origin;
1628 if (s == (u16 *) softback_end)
1629 s = (u16 *) softback_buf;
1630 if (s == (u16 *) softback_in)
1631 s = (u16 *) vc->vc_origin;
1635 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1636 int line, int count, int dy)
1638 unsigned short *s = (unsigned short *)
1639 (vc->vc_origin + vc->vc_size_row * line);
1642 unsigned short *start = s;
1643 unsigned short *le = advance_row(s, 1);
1646 unsigned short attr = 1;
1650 if (attr != (c & 0xff00)) {
1653 fbcon_putcs(vc, start, s - start,
1659 console_conditional_schedule();
1663 fbcon_putcs(vc, start, s - start, dy, x);
1664 console_conditional_schedule();
1669 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1670 struct display *p, int line, int count, int ycount)
1672 int offset = ycount * vc->vc_cols;
1673 unsigned short *d = (unsigned short *)
1674 (vc->vc_origin + vc->vc_size_row * line);
1675 unsigned short *s = d + offset;
1676 struct fbcon_ops *ops = info->fbcon_par;
1679 unsigned short *start = s;
1680 unsigned short *le = advance_row(s, 1);
1687 if (c == scr_readw(d)) {
1689 ops->bmove(vc, info, line + ycount, x,
1690 line, x, 1, s-start);
1700 console_conditional_schedule();
1705 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1707 console_conditional_schedule();
1712 /* NOTE: We subtract two lines from these pointers */
1713 s -= vc->vc_size_row;
1714 d -= vc->vc_size_row;
1719 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1720 int line, int count, int offset)
1722 unsigned short *d = (unsigned short *)
1723 (vc->vc_origin + vc->vc_size_row * line);
1724 unsigned short *s = d + offset;
1727 unsigned short *start = s;
1728 unsigned short *le = advance_row(s, 1);
1731 unsigned short attr = 1;
1735 if (attr != (c & 0xff00)) {
1738 fbcon_putcs(vc, start, s - start,
1744 if (c == scr_readw(d)) {
1746 fbcon_putcs(vc, start, s - start,
1756 console_conditional_schedule();
1761 fbcon_putcs(vc, start, s - start, line, x);
1762 console_conditional_schedule();
1767 /* NOTE: We subtract two lines from these pointers */
1768 s -= vc->vc_size_row;
1769 d -= vc->vc_size_row;
1774 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1779 if (vc->vc_num != fg_console)
1781 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1784 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1786 p = advance_row(p, 1);
1787 softback_in += vc->vc_size_row;
1788 if (softback_in == softback_end)
1789 softback_in = softback_buf;
1790 if (softback_in == softback_top) {
1791 softback_top += vc->vc_size_row;
1792 if (softback_top == softback_end)
1793 softback_top = softback_buf;
1796 softback_curr = softback_in;
1799 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1802 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1803 struct display *p = &fb_display[vc->vc_num];
1804 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1806 if (fbcon_is_inactive(vc, info))
1809 fbcon_cursor(vc, CM_ERASE);
1812 * ++Geert: Only use ywrap/ypan if the console is in text mode
1813 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1814 * whole screen (prevents flicker).
1819 if (count > vc->vc_rows) /* Maximum realistic size */
1820 count = vc->vc_rows;
1822 fbcon_softback_note(vc, t, count);
1823 if (logo_shown >= 0)
1825 if (SPLASH_DATA(info))
1827 switch (p->scrollmode) {
1829 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1831 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1832 scr_memsetw((unsigned short *) (vc->vc_origin +
1835 vc->vc_video_erase_char,
1836 vc->vc_size_row * count);
1840 case SCROLL_WRAP_MOVE:
1841 if (b - t - count > 3 * vc->vc_rows >> 2) {
1843 fbcon_bmove(vc, 0, 0, count, 0, t,
1845 ywrap_up(vc, count);
1846 if (vc->vc_rows - b > 0)
1847 fbcon_bmove(vc, b - count, 0, b, 0,
1850 } else if (info->flags & FBINFO_READS_FAST)
1851 fbcon_bmove(vc, t + count, 0, t, 0,
1852 b - t - count, vc->vc_cols);
1855 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1858 case SCROLL_PAN_REDRAW:
1859 if ((p->yscroll + count <=
1860 2 * (p->vrows - vc->vc_rows))
1861 && ((!scroll_partial && (b - t == vc->vc_rows))
1864 3 * vc->vc_rows >> 2)))) {
1866 fbcon_redraw_move(vc, p, 0, t, count);
1867 ypan_up_redraw(vc, t, count);
1868 if (vc->vc_rows - b > 0)
1869 fbcon_redraw_move(vc, p, b,
1870 vc->vc_rows - b, b);
1872 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1873 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1876 case SCROLL_PAN_MOVE:
1877 if ((p->yscroll + count <=
1878 2 * (p->vrows - vc->vc_rows))
1879 && ((!scroll_partial && (b - t == vc->vc_rows))
1882 3 * vc->vc_rows >> 2)))) {
1884 fbcon_bmove(vc, 0, 0, count, 0, t,
1887 if (vc->vc_rows - b > 0)
1888 fbcon_bmove(vc, b - count, 0, b, 0,
1891 } else if (info->flags & FBINFO_READS_FAST)
1892 fbcon_bmove(vc, t + count, 0, t, 0,
1893 b - t - count, vc->vc_cols);
1896 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1901 fbcon_redraw(vc, p, t, b - t - count,
1902 count * vc->vc_cols);
1903 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1904 scr_memsetw((unsigned short *) (vc->vc_origin +
1907 vc->vc_video_erase_char,
1908 vc->vc_size_row * count);
1914 if (count > vc->vc_rows) /* Maximum realistic size */
1915 count = vc->vc_rows;
1916 if (logo_shown >= 0)
1918 if (SPLASH_DATA(info))
1920 switch (p->scrollmode) {
1922 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1924 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1925 scr_memsetw((unsigned short *) (vc->vc_origin +
1928 vc->vc_video_erase_char,
1929 vc->vc_size_row * count);
1933 case SCROLL_WRAP_MOVE:
1934 if (b - t - count > 3 * vc->vc_rows >> 2) {
1935 if (vc->vc_rows - b > 0)
1936 fbcon_bmove(vc, b, 0, b - count, 0,
1939 ywrap_down(vc, count);
1941 fbcon_bmove(vc, count, 0, 0, 0, t,
1943 } else if (info->flags & FBINFO_READS_FAST)
1944 fbcon_bmove(vc, t, 0, t + count, 0,
1945 b - t - count, vc->vc_cols);
1948 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1951 case SCROLL_PAN_MOVE:
1952 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1953 && ((!scroll_partial && (b - t == vc->vc_rows))
1956 3 * vc->vc_rows >> 2)))) {
1957 if (vc->vc_rows - b > 0)
1958 fbcon_bmove(vc, b, 0, b - count, 0,
1961 ypan_down(vc, count);
1963 fbcon_bmove(vc, count, 0, 0, 0, t,
1965 } else if (info->flags & FBINFO_READS_FAST)
1966 fbcon_bmove(vc, t, 0, t + count, 0,
1967 b - t - count, vc->vc_cols);
1970 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1973 case SCROLL_PAN_REDRAW:
1974 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1975 && ((!scroll_partial && (b - t == vc->vc_rows))
1978 3 * vc->vc_rows >> 2)))) {
1979 if (vc->vc_rows - b > 0)
1980 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1982 ypan_down_redraw(vc, t, count);
1984 fbcon_redraw_move(vc, p, count, t, 0);
1986 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1987 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1992 fbcon_redraw(vc, p, b - 1, b - t - count,
1993 -count * vc->vc_cols);
1994 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1995 scr_memsetw((unsigned short *) (vc->vc_origin +
1998 vc->vc_video_erase_char,
1999 vc->vc_size_row * count);
2007 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2008 int height, int width)
2010 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2011 struct display *p = &fb_display[vc->vc_num];
2013 if (fbcon_is_inactive(vc, info))
2016 if (!width || !height)
2019 /* Split blits that cross physical y_wrap case.
2020 * Pathological case involves 4 blits, better to use recursive
2021 * code rather than unrolled case
2023 * Recursive invocations don't need to erase the cursor over and
2024 * over again, so we use fbcon_bmove_rec()
2026 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2027 p->vrows - p->yscroll);
2030 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2031 int dy, int dx, int height, int width, u_int y_break)
2033 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2034 struct fbcon_ops *ops = info->fbcon_par;
2037 if (sy < y_break && sy + height > y_break) {
2039 if (dy < sy) { /* Avoid trashing self */
2040 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2042 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2043 height - b, width, y_break);
2045 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2046 height - b, width, y_break);
2047 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2053 if (dy < y_break && dy + height > y_break) {
2055 if (dy < sy) { /* Avoid trashing self */
2056 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2058 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2059 height - b, width, y_break);
2061 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2062 height - b, width, y_break);
2063 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2069 if (SPLASH_DATA(info) && sy == dy && height == 1) {
2070 /*must use slower redraw bmove to keep background pic intact*/
2071 splash_bmove_redraw(vc, info, sy, sx, dx, width);
2074 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2078 static void updatescrollmode(struct display *p,
2079 struct fb_info *info,
2082 struct fbcon_ops *ops = info->fbcon_par;
2083 int fh = vc->vc_font.height;
2084 int cap = info->flags;
2086 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2087 info->fix.xpanstep);
2088 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2089 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2090 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2091 info->var.xres_virtual);
2092 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2093 divides(ypan, vc->vc_font.height) && vyres > yres;
2094 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2095 divides(ywrap, vc->vc_font.height) &&
2096 divides(vc->vc_font.height, vyres) &&
2097 divides(vc->vc_font.height, yres);
2098 int reading_fast = cap & FBINFO_READS_FAST;
2099 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2100 !(cap & FBINFO_HWACCEL_DISABLED);
2101 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2102 !(cap & FBINFO_HWACCEL_DISABLED);
2104 p->vrows = vyres/fh;
2105 if (yres > (fh * (vc->vc_rows + 1)))
2106 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2107 if ((yres % fh) && (vyres % fh < yres % fh))
2110 if (good_wrap || good_pan) {
2111 if (reading_fast || fast_copyarea)
2112 p->scrollmode = good_wrap ?
2113 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2115 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2118 if (reading_fast || (fast_copyarea && !fast_imageblit))
2119 p->scrollmode = SCROLL_MOVE;
2121 p->scrollmode = SCROLL_REDRAW;
2125 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2126 unsigned int height, unsigned int user)
2128 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2129 struct fbcon_ops *ops = info->fbcon_par;
2130 struct display *p = &fb_display[vc->vc_num];
2131 struct fb_var_screeninfo var = info->var;
2132 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2134 virt_w = FBCON_SWAP(ops->rotate, width, height);
2135 virt_h = FBCON_SWAP(ops->rotate, height, width);
2136 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2137 vc->vc_font.height);
2138 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2140 var.xres = virt_w * virt_fw;
2141 var.yres = virt_h * virt_fh;
2142 x_diff = info->var.xres - var.xres;
2143 y_diff = info->var.yres - var.yres;
2144 if (x_diff < 0 || x_diff > virt_fw ||
2145 y_diff < 0 || y_diff > virt_fh) {
2146 const struct fb_videomode *mode;
2148 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2149 mode = fb_find_best_mode(&var, &info->modelist);
2152 display_to_var(&var, p);
2153 fb_videomode_to_var(&var, mode);
2155 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2158 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2159 if (CON_IS_VISIBLE(vc)) {
2160 var.activate = FB_ACTIVATE_NOW |
2162 fb_set_var(info, &var);
2164 var_to_display(p, &info->var, info);
2165 ops->var = info->var;
2167 updatescrollmode(p, info, vc);
2171 static int fbcon_switch(struct vc_data *vc)
2173 struct fb_info *info, *old_info = NULL;
2174 struct fbcon_ops *ops;
2175 struct display *p = &fb_display[vc->vc_num];
2176 struct fb_var_screeninfo var;
2177 int i, ret, prev_console, charcnt = 256;
2179 info = registered_fb[con2fb_map[vc->vc_num]];
2180 ops = info->fbcon_par;
2182 #ifdef CONFIG_BOOTSPLASH
2184 struct splash_data *prev_sd = vc->vc_splash_data;
2185 splash_prepare(vc, info);
2186 if (vc->vc_splash_data && vc->vc_splash_data->splash_state &&
2187 vc->vc_splash_data != prev_sd) {
2188 vc_resize(vc, vc->vc_splash_data->splash_vc_text_wi
2189 / vc->vc_font.width,
2190 vc->vc_splash_data->splash_vc_text_he
2191 / vc->vc_font.height);
2192 con_remap_def_color(vc,
2193 vc->vc_splash_data->imgd->splash_color << 4
2194 | vc->vc_splash_data->imgd->splash_fg_color);
2201 fbcon_set_origin(vc);
2202 softback_top = softback_curr = softback_in = softback_buf;
2204 fbcon_update_softback(vc);
2207 if (logo_shown >= 0) {
2208 struct vc_data *conp2 = vc_cons[logo_shown].d;
2210 if (conp2->vc_top == logo_lines
2211 && conp2->vc_bottom == conp2->vc_rows)
2213 logo_shown = FBCON_LOGO_CANSHOW;
2216 prev_console = ops->currcon;
2217 if (prev_console != -1)
2218 old_info = registered_fb[con2fb_map[prev_console]];
2220 * FIXME: If we have multiple fbdev's loaded, we need to
2221 * update all info->currcon. Perhaps, we can place this
2222 * in a centralized structure, but this might break some
2225 * info->currcon = vc->vc_num;
2227 for (i = 0; i < FB_MAX; i++) {
2228 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2229 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2231 o->currcon = vc->vc_num;
2234 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2235 display_to_var(&var, p);
2236 var.activate = FB_ACTIVATE_NOW;
2239 * make sure we don't unnecessarily trip the memcmp()
2242 info->var.activate = var.activate;
2243 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2244 fb_set_var(info, &var);
2245 ops->var = info->var;
2247 if (old_info != NULL && (old_info != info ||
2248 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2249 if (info->fbops->fb_set_par) {
2250 ret = info->fbops->fb_set_par(info);
2253 printk(KERN_ERR "fbcon_switch: detected "
2254 "unhandled fb_set_par error, "
2255 "error code %d\n", ret);
2258 if (old_info != info)
2259 fbcon_del_cursor_timer(old_info);
2262 if (fbcon_is_inactive(vc, info) ||
2263 ops->blank_state != FB_BLANK_UNBLANK)
2264 fbcon_del_cursor_timer(info);
2266 fbcon_add_cursor_timer(info);
2268 set_blitting_type(vc, info);
2269 ops->cursor_reset = 1;
2271 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2272 ops->rotate = FB_ROTATE_UR;
2273 set_blitting_type(vc, info);
2276 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2277 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2280 charcnt = FNTCHARCNT(vc->vc_font.data);
2283 vc->vc_complement_mask <<= 1;
2285 updatescrollmode(p, info, vc);
2287 switch (p->scrollmode) {
2288 case SCROLL_WRAP_MOVE:
2289 scrollback_phys_max = p->vrows - vc->vc_rows;
2291 case SCROLL_PAN_MOVE:
2292 case SCROLL_PAN_REDRAW:
2293 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2294 if (scrollback_phys_max < 0)
2295 scrollback_phys_max = 0;
2298 scrollback_phys_max = 0;
2303 scrollback_current = 0;
2305 if (!fbcon_is_inactive(vc, info)) {
2306 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2307 ops->update_start(info);
2310 fbcon_set_palette(vc, color_table);
2311 fbcon_clear_margins(vc, 0);
2313 if (logo_shown == FBCON_LOGO_DRAW) {
2315 logo_shown = fg_console;
2316 /* This is protected above by initmem_freed */
2317 fb_show_logo(info, ops->rotate);
2319 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2320 vc->vc_size_row * (vc->vc_bottom -
2327 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2330 struct fb_event event;
2332 if (SPLASH_DATA(info)) {
2333 splash_blank(vc, info, blank);
2338 unsigned short charmask = vc->vc_hi_font_mask ?
2340 unsigned short oldc;
2342 oldc = vc->vc_video_erase_char;
2343 vc->vc_video_erase_char &= charmask;
2344 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2345 vc->vc_video_erase_char = oldc;
2349 if (!lock_fb_info(info))
2352 event.data = ␣
2353 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2354 unlock_fb_info(info);
2357 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2359 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2360 struct fbcon_ops *ops = info->fbcon_par;
2363 struct fb_var_screeninfo var = info->var;
2368 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2369 fb_set_var(info, &var);
2371 ops->var = info->var;
2375 if (!fbcon_is_inactive(vc, info)) {
2376 if (ops->blank_state != blank) {
2377 ops->blank_state = blank;
2378 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2379 ops->cursor_flash = (!blank);
2381 if (!(info->flags & FBINFO_MISC_USEREVENT))
2382 if (fb_blank(info, blank))
2383 fbcon_generic_blank(vc, info, blank);
2390 if (mode_switch || fbcon_is_inactive(vc, info) ||
2391 ops->blank_state != FB_BLANK_UNBLANK)
2392 fbcon_del_cursor_timer(info);
2394 fbcon_add_cursor_timer(info);
2399 static int fbcon_debug_enter(struct vc_data *vc)
2401 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2402 struct fbcon_ops *ops = info->fbcon_par;
2404 ops->save_graphics = ops->graphics;
2406 if (info->fbops->fb_debug_enter)
2407 info->fbops->fb_debug_enter(info);
2408 fbcon_set_palette(vc, color_table);
2412 static int fbcon_debug_leave(struct vc_data *vc)
2414 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2415 struct fbcon_ops *ops = info->fbcon_par;
2417 ops->graphics = ops->save_graphics;
2418 if (info->fbops->fb_debug_leave)
2419 info->fbops->fb_debug_leave(info);
2423 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2425 u8 *fontdata = vc->vc_font.data;
2426 u8 *data = font->data;
2429 font->width = vc->vc_font.width;
2430 font->height = vc->vc_font.height;
2431 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2435 if (font->width <= 8) {
2436 j = vc->vc_font.height;
2437 for (i = 0; i < font->charcount; i++) {
2438 memcpy(data, fontdata, j);
2439 memset(data + j, 0, 32 - j);
2443 } else if (font->width <= 16) {
2444 j = vc->vc_font.height * 2;
2445 for (i = 0; i < font->charcount; i++) {
2446 memcpy(data, fontdata, j);
2447 memset(data + j, 0, 64 - j);
2451 } else if (font->width <= 24) {
2452 for (i = 0; i < font->charcount; i++) {
2453 for (j = 0; j < vc->vc_font.height; j++) {
2454 *data++ = fontdata[0];
2455 *data++ = fontdata[1];
2456 *data++ = fontdata[2];
2457 fontdata += sizeof(u32);
2459 memset(data, 0, 3 * (32 - j));
2460 data += 3 * (32 - j);
2463 j = vc->vc_font.height * 4;
2464 for (i = 0; i < font->charcount; i++) {
2465 memcpy(data, fontdata, j);
2466 memset(data + j, 0, 128 - j);
2474 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2475 const u8 * data, int userfont)
2477 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2478 struct fbcon_ops *ops = info->fbcon_par;
2479 struct display *p = &fb_display[vc->vc_num];
2482 char *old_data = NULL;
2484 if (CON_IS_VISIBLE(vc) && softback_lines)
2485 fbcon_set_origin(vc);
2487 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2489 old_data = vc->vc_font.data;
2491 cnt = FNTCHARCNT(data);
2494 vc->vc_font.data = (void *)(p->fontdata = data);
2495 if ((p->userfont = userfont))
2497 vc->vc_font.width = w;
2498 vc->vc_font.height = h;
2499 if (vc->vc_hi_font_mask && cnt == 256) {
2500 vc->vc_hi_font_mask = 0;
2501 if (vc->vc_can_do_color) {
2502 vc->vc_complement_mask >>= 1;
2503 vc->vc_s_complement_mask >>= 1;
2506 /* ++Edmund: reorder the attribute bits */
2507 if (vc->vc_can_do_color) {
2508 unsigned short *cp =
2509 (unsigned short *) vc->vc_origin;
2510 int count = vc->vc_screenbuf_size / 2;
2512 for (; count > 0; count--, cp++) {
2514 scr_writew(((c & 0xfe00) >> 1) |
2517 c = vc->vc_video_erase_char;
2518 vc->vc_video_erase_char =
2519 ((c & 0xfe00) >> 1) | (c & 0xff);
2522 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2523 vc->vc_hi_font_mask = 0x100;
2524 if (vc->vc_can_do_color) {
2525 vc->vc_complement_mask <<= 1;
2526 vc->vc_s_complement_mask <<= 1;
2529 /* ++Edmund: reorder the attribute bits */
2531 unsigned short *cp =
2532 (unsigned short *) vc->vc_origin;
2533 int count = vc->vc_screenbuf_size / 2;
2535 for (; count > 0; count--, cp++) {
2536 unsigned short newc;
2538 if (vc->vc_can_do_color)
2540 ((c & 0xff00) << 1) | (c &
2544 scr_writew(newc, cp);
2546 c = vc->vc_video_erase_char;
2547 if (vc->vc_can_do_color) {
2548 vc->vc_video_erase_char =
2549 ((c & 0xff00) << 1) | (c & 0xff);
2552 vc->vc_video_erase_char = c & ~0x100;
2560 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2561 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2562 if (SPLASH_DATA(info)) {
2563 cols = TEXT_WIDTH_FROM_SPLASH_DATA(info);
2564 rows = TEXT_HIGHT_FROM_SPLASH_DATA(info);
2568 vc_resize(vc, cols, rows);
2569 if (CON_IS_VISIBLE(vc) && softback_buf)
2570 fbcon_update_softback(vc);
2571 } else if (CON_IS_VISIBLE(vc)
2572 && vc->vc_mode == KD_TEXT) {
2573 fbcon_clear_margins(vc, 0);
2577 if (old_data && (--REFCOUNT(old_data) == 0))
2578 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2582 static int fbcon_copy_font(struct vc_data *vc, int con)
2584 struct display *od = &fb_display[con];
2585 struct console_font *f = &vc->vc_font;
2587 if (od->fontdata == f->data)
2588 return 0; /* already the same font... */
2589 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2593 * User asked to set font; we are guaranteed that
2594 * a) width and height are in range 1..32
2595 * b) charcount does not exceed 512
2596 * but lets not assume that, since someone might someday want to use larger
2597 * fonts. And charcount of 512 is small for unicode support.
2599 * However, user space gives the font in 32 rows , regardless of
2600 * actual font height. So a new API is needed if support for larger fonts
2601 * is ever implemented.
2604 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2606 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2607 unsigned charcount = font->charcount;
2608 int w = font->width;
2609 int h = font->height;
2612 u8 *new_data, *data = font->data;
2613 int pitch = (font->width+7) >> 3;
2615 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2616 * If not this check should be changed to charcount < 256 */
2617 if (charcount != 256 && charcount != 512)
2620 /* Make sure drawing engine can handle the font */
2621 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2622 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2625 /* Make sure driver can handle the font length */
2626 if (fbcon_invalid_charcount(info, charcount))
2629 size = h * pitch * charcount;
2631 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2636 new_data += FONT_EXTRA_WORDS * sizeof(int);
2637 FNTSIZE(new_data) = size;
2638 FNTCHARCNT(new_data) = charcount;
2639 REFCOUNT(new_data) = 0; /* usage counter */
2640 for (i=0; i< charcount; i++) {
2641 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2644 /* Since linux has a nice crc32 function use it for counting font
2646 csum = crc32(0, new_data, size);
2648 FNTSUM(new_data) = csum;
2649 /* Check if the same font is on some other console already */
2650 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2651 struct vc_data *tmp = vc_cons[i].d;
2653 if (fb_display[i].userfont &&
2654 fb_display[i].fontdata &&
2655 FNTSUM(fb_display[i].fontdata) == csum &&
2656 FNTSIZE(fb_display[i].fontdata) == size &&
2657 tmp->vc_font.width == w &&
2658 !memcmp(fb_display[i].fontdata, new_data, size)) {
2659 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2660 new_data = (u8 *)fb_display[i].fontdata;
2664 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2667 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2669 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2670 const struct font_desc *f;
2673 f = get_default_font(info->var.xres, info->var.yres,
2674 info->pixmap.blit_x, info->pixmap.blit_y);
2675 else if (!(f = find_font(name)))
2678 font->width = f->width;
2679 font->height = f->height;
2680 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2683 static u16 palette_red[16];
2684 static u16 palette_green[16];
2685 static u16 palette_blue[16];
2687 static struct fb_cmap palette_cmap = {
2688 0, 16, palette_red, palette_green, palette_blue, NULL
2691 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2693 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2697 if (fbcon_is_inactive(vc, info))
2700 if (!CON_IS_VISIBLE(vc))
2703 depth = fb_get_color_depth(&info->var, &info->fix);
2705 for (i = j = 0; i < 16; i++) {
2707 val = vc->vc_palette[j++];
2708 palette_red[k] = (val << 8) | val;
2709 val = vc->vc_palette[j++];
2710 palette_green[k] = (val << 8) | val;
2711 val = vc->vc_palette[j++];
2712 palette_blue[k] = (val << 8) | val;
2714 palette_cmap.len = 16;
2715 palette_cmap.start = 0;
2717 * If framebuffer is capable of less than 16 colors,
2718 * use default palette of fbcon.
2721 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2723 return fb_set_cmap(&palette_cmap, info);
2726 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2731 if (vc->vc_num != fg_console || !softback_lines)
2732 return (u16 *) (vc->vc_origin + offset);
2733 line = offset / vc->vc_size_row;
2734 if (line >= softback_lines)
2735 return (u16 *) (vc->vc_origin + offset -
2736 softback_lines * vc->vc_size_row);
2737 p = softback_curr + offset;
2738 if (p >= softback_end)
2739 p += softback_buf - softback_end;
2743 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2749 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2750 unsigned long offset = (pos - vc->vc_origin) / 2;
2752 x = offset % vc->vc_cols;
2753 y = offset / vc->vc_cols;
2754 if (vc->vc_num == fg_console)
2755 y += softback_lines;
2756 ret = pos + (vc->vc_cols - x) * 2;
2757 } else if (vc->vc_num == fg_console && softback_lines) {
2758 unsigned long offset = pos - softback_curr;
2760 if (pos < softback_curr)
2761 offset += softback_end - softback_buf;
2763 x = offset % vc->vc_cols;
2764 y = offset / vc->vc_cols;
2765 ret = pos + (vc->vc_cols - x) * 2;
2766 if (ret == softback_end)
2768 if (ret == softback_in)
2769 ret = vc->vc_origin;
2771 /* Should not happen */
2773 ret = vc->vc_origin;
2782 /* As we might be inside of softback, we may work with non-contiguous buffer,
2783 that's why we have to use a separate routine. */
2784 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2787 u16 a = scr_readw(p);
2788 if (!vc->vc_can_do_color)
2790 else if (vc->vc_hi_font_mask == 0x100)
2791 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2792 (((a) & 0x0e00) << 4);
2794 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2795 (((a) & 0x0700) << 4);
2797 if (p == (u16 *) softback_end)
2798 p = (u16 *) softback_buf;
2799 if (p == (u16 *) softback_in)
2800 p = (u16 *) vc->vc_origin;
2804 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2806 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2807 struct fbcon_ops *ops = info->fbcon_par;
2808 struct display *disp = &fb_display[fg_console];
2809 int offset, limit, scrollback_old;
2812 if (vc->vc_num != fg_console)
2814 if (vc->vc_mode != KD_TEXT || !lines)
2816 if (logo_shown >= 0) {
2817 struct vc_data *conp2 = vc_cons[logo_shown].d;
2819 if (conp2->vc_top == logo_lines
2820 && conp2->vc_bottom == conp2->vc_rows)
2822 if (logo_shown == vc->vc_num) {
2828 logo_lines * vc->vc_size_row;
2829 for (i = 0; i < logo_lines; i++) {
2830 if (p == softback_top)
2832 if (p == softback_buf)
2834 p -= vc->vc_size_row;
2835 q -= vc->vc_size_row;
2836 scr_memcpyw((u16 *) q, (u16 *) p,
2839 softback_in = softback_curr = p;
2840 update_region(vc, vc->vc_origin,
2841 logo_lines * vc->vc_cols);
2843 logo_shown = FBCON_LOGO_CANSHOW;
2845 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2846 fbcon_redraw_softback(vc, disp, lines);
2847 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2851 if (!scrollback_phys_max)
2854 scrollback_old = scrollback_current;
2855 scrollback_current -= lines;
2856 if (scrollback_current < 0)
2857 scrollback_current = 0;
2858 else if (scrollback_current > scrollback_max)
2859 scrollback_current = scrollback_max;
2860 if (scrollback_current == scrollback_old)
2863 if (fbcon_is_inactive(vc, info))
2866 fbcon_cursor(vc, CM_ERASE);
2868 offset = disp->yscroll - scrollback_current;
2869 limit = disp->vrows;
2870 switch (disp->scrollmode) {
2871 case SCROLL_WRAP_MOVE:
2872 info->var.vmode |= FB_VMODE_YWRAP;
2874 case SCROLL_PAN_MOVE:
2875 case SCROLL_PAN_REDRAW:
2876 limit -= vc->vc_rows;
2877 info->var.vmode &= ~FB_VMODE_YWRAP;
2882 else if (offset >= limit)
2885 ops->var.xoffset = 0;
2886 ops->var.yoffset = offset * vc->vc_font.height;
2887 ops->update_start(info);
2889 if (!scrollback_current)
2890 fbcon_cursor(vc, CM_DRAW);
2894 static int fbcon_set_origin(struct vc_data *vc)
2897 fbcon_scrolldelta(vc, softback_lines);
2901 static void fbcon_suspended(struct fb_info *info)
2903 struct vc_data *vc = NULL;
2904 struct fbcon_ops *ops = info->fbcon_par;
2906 if (!ops || ops->currcon < 0)
2908 vc = vc_cons[ops->currcon].d;
2910 /* Clear cursor, restore saved data */
2911 fbcon_cursor(vc, CM_ERASE);
2914 static void fbcon_resumed(struct fb_info *info)
2917 struct fbcon_ops *ops = info->fbcon_par;
2919 if (!ops || ops->currcon < 0)
2921 vc = vc_cons[ops->currcon].d;
2926 static void fbcon_modechanged(struct fb_info *info)
2928 struct fbcon_ops *ops = info->fbcon_par;
2933 if (!ops || ops->currcon < 0)
2935 vc = vc_cons[ops->currcon].d;
2936 if (vc->vc_mode != KD_TEXT ||
2937 registered_fb[con2fb_map[ops->currcon]] != info)
2940 p = &fb_display[vc->vc_num];
2941 set_blitting_type(vc, info);
2943 if (CON_IS_VISIBLE(vc)) {
2944 var_to_display(p, &info->var, info);
2945 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2946 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2947 cols /= vc->vc_font.width;
2948 rows /= vc->vc_font.height;
2949 vc_resize(vc, cols, rows);
2950 updatescrollmode(p, info, vc);
2952 scrollback_current = 0;
2954 if (!fbcon_is_inactive(vc, info)) {
2955 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2956 ops->update_start(info);
2959 fbcon_set_palette(vc, color_table);
2962 fbcon_update_softback(vc);
2966 static void fbcon_set_all_vcs(struct fb_info *info)
2968 struct fbcon_ops *ops = info->fbcon_par;
2971 int i, rows, cols, fg = -1;
2973 if (!ops || ops->currcon < 0)
2976 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2978 if (!vc || vc->vc_mode != KD_TEXT ||
2979 registered_fb[con2fb_map[i]] != info)
2982 if (CON_IS_VISIBLE(vc)) {
2987 p = &fb_display[vc->vc_num];
2988 set_blitting_type(vc, info);
2989 var_to_display(p, &info->var, info);
2990 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2991 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2992 cols /= vc->vc_font.width;
2993 rows /= vc->vc_font.height;
2994 vc_resize(vc, cols, rows);
2998 fbcon_modechanged(info);
3001 static int fbcon_mode_deleted(struct fb_info *info,
3002 struct fb_videomode *mode)
3004 struct fb_info *fb_info;
3006 int i, j, found = 0;
3008 /* before deletion, ensure that mode is not in use */
3009 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3013 fb_info = registered_fb[j];
3014 if (fb_info != info)
3019 if (fb_mode_is_equal(p->mode, mode)) {
3027 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3028 static int fbcon_unbind(void)
3032 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3036 fbcon_has_console_bind = 0;
3041 static inline int fbcon_unbind(void)
3045 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3047 static int fbcon_fb_unbind(int idx)
3049 int i, new_idx = -1, ret = 0;
3051 if (!fbcon_has_console_bind)
3054 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3055 if (con2fb_map[i] != idx &&
3056 con2fb_map[i] != -1) {
3062 if (new_idx != -1) {
3063 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3064 if (con2fb_map[i] == idx)
3065 set_con2fb_map(i, new_idx, 0);
3068 ret = fbcon_unbind();
3073 static int fbcon_fb_unregistered(struct fb_info *info)
3078 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3079 if (con2fb_map[i] == idx)
3083 if (idx == info_idx) {
3086 for (i = 0; i < FB_MAX; i++) {
3087 if (registered_fb[i] != NULL) {
3094 if (info_idx != -1) {
3095 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3096 if (con2fb_map[i] == -1)
3097 con2fb_map[i] = info_idx;
3101 if (primary_device == idx)
3102 primary_device = -1;
3104 if (!num_registered_fb)
3105 unregister_con_driver(&fb_con);
3110 static void fbcon_remap_all(int idx)
3113 for (i = first_fb_vc; i <= last_fb_vc; i++)
3114 set_con2fb_map(i, idx, 0);
3116 if (con_is_bound(&fb_con)) {
3117 printk(KERN_INFO "fbcon: Remapping primary device, "
3118 "fb%i, to tty %i-%i\n", idx,
3119 first_fb_vc + 1, last_fb_vc + 1);
3124 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3125 static void fbcon_select_primary(struct fb_info *info)
3127 if (!map_override && primary_device == -1 &&
3128 fb_is_primary_device(info)) {
3131 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3132 info->fix.id, info->node);
3133 primary_device = info->node;
3135 for (i = first_fb_vc; i <= last_fb_vc; i++)
3136 con2fb_map_boot[i] = primary_device;
3138 if (con_is_bound(&fb_con)) {
3139 printk(KERN_INFO "fbcon: Remapping primary device, "
3140 "fb%i, to tty %i-%i\n", info->node,
3141 first_fb_vc + 1, last_fb_vc + 1);
3142 info_idx = primary_device;
3148 static inline void fbcon_select_primary(struct fb_info *info)
3152 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3154 static int fbcon_fb_registered(struct fb_info *info)
3156 int ret = 0, i, idx;
3159 fbcon_select_primary(info);
3161 if (info_idx == -1) {
3162 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3163 if (con2fb_map_boot[i] == idx) {
3170 ret = fbcon_takeover(1);
3172 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3173 if (con2fb_map_boot[i] == idx)
3174 set_con2fb_map(i, idx, 0);
3181 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3183 struct fbcon_ops *ops = info->fbcon_par;
3186 if (!ops || ops->currcon < 0)
3189 vc = vc_cons[ops->currcon].d;
3190 if (vc->vc_mode != KD_TEXT ||
3191 registered_fb[con2fb_map[ops->currcon]] != info)
3194 if (CON_IS_VISIBLE(vc)) {
3198 do_unblank_screen(0);
3200 ops->blank_state = blank;
3203 static void fbcon_new_modelist(struct fb_info *info)
3207 struct fb_var_screeninfo var;
3208 const struct fb_videomode *mode;
3210 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3211 if (registered_fb[con2fb_map[i]] != info)
3213 if (!fb_display[i].mode)
3216 display_to_var(&var, &fb_display[i]);
3217 mode = fb_find_nearest_mode(fb_display[i].mode,
3219 fb_videomode_to_var(&var, mode);
3220 fbcon_set_disp(info, &var, vc->vc_num);
3224 static void fbcon_get_requirement(struct fb_info *info,
3225 struct fb_blit_caps *caps)
3233 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3235 if (vc && vc->vc_mode == KD_TEXT &&
3236 info->node == con2fb_map[i]) {
3238 caps->x |= 1 << (vc->vc_font.width - 1);
3239 caps->y |= 1 << (vc->vc_font.height - 1);
3240 charcnt = (p->userfont) ?
3241 FNTCHARCNT(p->fontdata) : 256;
3242 if (caps->len < charcnt)
3243 caps->len = charcnt;
3247 vc = vc_cons[fg_console].d;
3249 if (vc && vc->vc_mode == KD_TEXT &&
3250 info->node == con2fb_map[fg_console]) {
3251 p = &fb_display[fg_console];
3252 caps->x = 1 << (vc->vc_font.width - 1);
3253 caps->y = 1 << (vc->vc_font.height - 1);
3254 caps->len = (p->userfont) ?
3255 FNTCHARCNT(p->fontdata) : 256;
3260 static int fbcon_event_notify(struct notifier_block *self,
3261 unsigned long action, void *data)
3263 struct fb_event *event = data;
3264 struct fb_info *info = event->info;
3265 struct fb_videomode *mode;
3266 struct fb_con2fbmap *con2fb;
3267 struct fb_blit_caps *caps;
3271 * ignore all events except driver registration and deregistration
3272 * if fbcon is not active
3274 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3275 action == FB_EVENT_FB_UNREGISTERED))
3279 case FB_EVENT_SUSPEND:
3280 fbcon_suspended(info);
3282 case FB_EVENT_RESUME:
3283 fbcon_resumed(info);
3285 case FB_EVENT_MODE_CHANGE:
3286 fbcon_modechanged(info);
3288 case FB_EVENT_MODE_CHANGE_ALL:
3289 fbcon_set_all_vcs(info);
3291 case FB_EVENT_MODE_DELETE:
3293 ret = fbcon_mode_deleted(info, mode);
3295 case FB_EVENT_FB_UNBIND:
3297 ret = fbcon_fb_unbind(idx);
3299 case FB_EVENT_FB_REGISTERED:
3300 ret = fbcon_fb_registered(info);
3302 case FB_EVENT_FB_UNREGISTERED:
3303 ret = fbcon_fb_unregistered(info);
3305 case FB_EVENT_SET_CONSOLE_MAP:
3306 con2fb = event->data;
3307 ret = set_con2fb_map(con2fb->console - 1,
3308 con2fb->framebuffer, 1);
3310 case FB_EVENT_GET_CONSOLE_MAP:
3311 con2fb = event->data;
3312 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3314 case FB_EVENT_BLANK:
3315 fbcon_fb_blanked(info, *(int *)event->data);
3317 case FB_EVENT_NEW_MODELIST:
3318 fbcon_new_modelist(info);
3320 case FB_EVENT_GET_REQ:
3322 fbcon_get_requirement(info, caps);
3324 case FB_EVENT_REMAP_ALL_CONSOLE:
3326 fbcon_remap_all(idx);
3334 * The console `switch' structure for the frame buffer based console
3337 static const struct consw fb_con = {
3338 .owner = THIS_MODULE,
3339 .con_startup = fbcon_startup,
3340 .con_init = fbcon_init,
3341 .con_deinit = fbcon_deinit,
3342 .con_clear = fbcon_clear,
3343 .con_putc = fbcon_putc,
3344 .con_putcs = fbcon_putcs,
3345 .con_cursor = fbcon_cursor,
3346 .con_scroll = fbcon_scroll,
3347 .con_bmove = fbcon_bmove,
3348 .con_switch = fbcon_switch,
3349 .con_blank = fbcon_blank,
3350 .con_font_set = fbcon_set_font,
3351 .con_font_get = fbcon_get_font,
3352 .con_font_default = fbcon_set_def_font,
3353 .con_font_copy = fbcon_copy_font,
3354 .con_set_palette = fbcon_set_palette,
3355 .con_scrolldelta = fbcon_scrolldelta,
3356 .con_set_origin = fbcon_set_origin,
3357 .con_invert_region = fbcon_invert_region,
3358 .con_screen_pos = fbcon_screen_pos,
3359 .con_getxy = fbcon_getxy,
3360 .con_resize = fbcon_resize,
3361 .con_debug_enter = fbcon_debug_enter,
3362 .con_debug_leave = fbcon_debug_leave,
3365 static struct notifier_block fbcon_event_notifier = {
3366 .notifier_call = fbcon_event_notify,
3369 static ssize_t store_rotate(struct device *device,
3370 struct device_attribute *attr, const char *buf,
3373 struct fb_info *info;
3377 if (fbcon_has_exited)
3381 idx = con2fb_map[fg_console];
3383 if (idx == -1 || registered_fb[idx] == NULL)
3386 info = registered_fb[idx];
3387 rotate = simple_strtoul(buf, last, 0);
3388 fbcon_rotate(info, rotate);
3394 static ssize_t store_rotate_all(struct device *device,
3395 struct device_attribute *attr,const char *buf,
3398 struct fb_info *info;
3402 if (fbcon_has_exited)
3406 idx = con2fb_map[fg_console];
3408 if (idx == -1 || registered_fb[idx] == NULL)
3411 info = registered_fb[idx];
3412 rotate = simple_strtoul(buf, last, 0);
3413 fbcon_rotate_all(info, rotate);
3419 static ssize_t show_rotate(struct device *device,
3420 struct device_attribute *attr,char *buf)
3422 struct fb_info *info;
3423 int rotate = 0, idx;
3425 if (fbcon_has_exited)
3429 idx = con2fb_map[fg_console];
3431 if (idx == -1 || registered_fb[idx] == NULL)
3434 info = registered_fb[idx];
3435 rotate = fbcon_get_rotate(info);
3438 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3441 static ssize_t show_cursor_blink(struct device *device,
3442 struct device_attribute *attr, char *buf)
3444 struct fb_info *info;
3445 struct fbcon_ops *ops;
3446 int idx, blink = -1;
3448 if (fbcon_has_exited)
3452 idx = con2fb_map[fg_console];
3454 if (idx == -1 || registered_fb[idx] == NULL)
3457 info = registered_fb[idx];
3458 ops = info->fbcon_par;
3463 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3466 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3469 static ssize_t store_cursor_blink(struct device *device,
3470 struct device_attribute *attr,
3471 const char *buf, size_t count)
3473 struct fb_info *info;
3477 if (fbcon_has_exited)
3481 idx = con2fb_map[fg_console];
3483 if (idx == -1 || registered_fb[idx] == NULL)
3486 info = registered_fb[idx];
3488 if (!info->fbcon_par)
3491 blink = simple_strtoul(buf, last, 0);
3494 fbcon_cursor_noblink = 0;
3495 fbcon_add_cursor_timer(info);
3497 fbcon_cursor_noblink = 1;
3498 fbcon_del_cursor_timer(info);
3506 static struct device_attribute device_attrs[] = {
3507 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3508 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3509 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3510 store_cursor_blink),
3513 static int fbcon_init_device(void)
3517 fbcon_has_sysfs = 1;
3519 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3520 error = device_create_file(fbcon_device, &device_attrs[i]);
3528 device_remove_file(fbcon_device, &device_attrs[i]);
3530 fbcon_has_sysfs = 0;
3536 static void fbcon_start(void)
3538 if (num_registered_fb) {
3543 for (i = 0; i < FB_MAX; i++) {
3544 if (registered_fb[i] != NULL) {
3555 static void fbcon_exit(void)
3557 struct fb_info *info;
3560 if (fbcon_has_exited)
3563 kfree((void *)softback_buf);
3566 for (i = 0; i < FB_MAX; i++) {
3570 info = registered_fb[i];
3575 if (info->queue.func)
3576 pending = cancel_work_sync(&info->queue);
3577 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3580 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3581 if (con2fb_map[j] == i)
3586 if (info->fbops->fb_release)
3587 info->fbops->fb_release(info, 0);
3588 module_put(info->fbops->owner);
3590 if (info->fbcon_par) {
3591 struct fbcon_ops *ops = info->fbcon_par;
3593 fbcon_del_cursor_timer(info);
3594 kfree(ops->cursor_src);
3595 kfree(info->fbcon_par);
3596 info->fbcon_par = NULL;
3599 if (info->queue.func == fb_flashcursor)
3600 info->queue.func = NULL;
3604 fbcon_has_exited = 1;
3607 static int __init fb_console_init(void)
3612 fb_register_client(&fbcon_event_notifier);
3613 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3616 if (IS_ERR(fbcon_device)) {
3617 printk(KERN_WARNING "Unable to create device "
3618 "for fbcon; errno = %ld\n",
3619 PTR_ERR(fbcon_device));
3620 fbcon_device = NULL;
3622 fbcon_init_device();
3624 for (i = 0; i < MAX_NR_CONSOLES; i++)
3632 module_init(fb_console_init);
3636 static void __exit fbcon_deinit_device(void)
3640 if (fbcon_has_sysfs) {
3641 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3642 device_remove_file(fbcon_device, &device_attrs[i]);
3644 fbcon_has_sysfs = 0;
3648 static void __exit fb_console_exit(void)
3651 fb_unregister_client(&fbcon_event_notifier);
3652 fbcon_deinit_device();
3653 device_destroy(fb_class, MKDEV(0, 0));
3656 unregister_con_driver(&fb_con);
3659 module_exit(fb_console_exit);
3663 MODULE_LICENSE("GPL");