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
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
34 * 2001 - Documented with DocBook
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
96 static struct display fb_display[MAX_NR_CONSOLES];
98 static signed char con2fb_map[MAX_NR_CONSOLES];
99 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
101 static int logo_lines;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown = FBCON_LOGO_CANSHOW;
105 /* Software scrollback */
106 static int fbcon_softback_size = 32768;
107 static unsigned long softback_buf, softback_curr;
108 static unsigned long softback_in;
109 static unsigned long softback_top, softback_end;
110 static int softback_lines;
111 /* console mappings */
112 static int first_fb_vc;
113 static int last_fb_vc = MAX_NR_CONSOLES - 1;
114 static int fbcon_is_default = 1;
115 static int fbcon_has_exited;
116 static int primary_device = -1;
117 static int fbcon_has_console_bind;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override;
122 static inline void fbcon_map_override(void)
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
132 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
133 static bool deferred_takeover = true;
135 #define deferred_takeover false
139 static char fontname[40];
141 /* current fb_info */
142 static int info_idx = -1;
144 /* console rotation */
145 static int initial_rotation = -1;
146 static int fbcon_has_sysfs;
147 static int margin_color;
149 static const struct consw fb_con;
151 #define CM_SOFTBACK (8)
153 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
155 static int fbcon_set_origin(struct vc_data *);
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 void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
176 int height, int width);
177 static int fbcon_switch(struct vc_data *vc);
178 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
179 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
184 static __inline__ void ywrap_up(struct vc_data *vc, int count);
185 static __inline__ void ywrap_down(struct vc_data *vc, int count);
186 static __inline__ void ypan_up(struct vc_data *vc, int count);
187 static __inline__ void ypan_down(struct vc_data *vc, int count);
188 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
192 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
193 int line, int count, int dy);
194 static void fbcon_modechanged(struct fb_info *info);
195 static void fbcon_set_all_vcs(struct fb_info *info);
196 static void fbcon_start(void);
197 static void fbcon_exit(void);
198 static struct device *fbcon_device;
200 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
201 static inline void fbcon_set_rotation(struct fb_info *info)
203 struct fbcon_ops *ops = info->fbcon_par;
205 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
206 ops->p->con_rotate < 4)
207 ops->rotate = ops->p->con_rotate;
212 static void fbcon_rotate(struct fb_info *info, u32 rotate)
214 struct fbcon_ops *ops= info->fbcon_par;
215 struct fb_info *fb_info;
217 if (!ops || ops->currcon == -1)
220 fb_info = registered_fb[con2fb_map[ops->currcon]];
222 if (info == fb_info) {
223 struct display *p = &fb_display[ops->currcon];
226 p->con_rotate = rotate;
230 fbcon_modechanged(info);
234 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
236 struct fbcon_ops *ops = info->fbcon_par;
241 if (!ops || ops->currcon < 0 || rotate > 3)
244 for (i = first_fb_vc; i <= last_fb_vc; i++) {
246 if (!vc || vc->vc_mode != KD_TEXT ||
247 registered_fb[con2fb_map[i]] != info)
250 p = &fb_display[vc->vc_num];
251 p->con_rotate = rotate;
254 fbcon_set_all_vcs(info);
257 static inline void fbcon_set_rotation(struct fb_info *info)
259 struct fbcon_ops *ops = info->fbcon_par;
261 ops->rotate = FB_ROTATE_UR;
264 static void fbcon_rotate(struct fb_info *info, u32 rotate)
269 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
273 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
275 static int fbcon_get_rotate(struct fb_info *info)
277 struct fbcon_ops *ops = info->fbcon_par;
279 return (ops) ? ops->rotate : 0;
282 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
284 struct fbcon_ops *ops = info->fbcon_par;
286 return (info->state != FBINFO_STATE_RUNNING ||
287 vc->vc_mode != KD_TEXT || ops->graphics);
290 static int get_color(struct vc_data *vc, struct fb_info *info,
293 int depth = fb_get_color_depth(&info->var, &info->fix);
296 if (console_blanked) {
297 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
299 c = vc->vc_video_erase_char & charmask;
303 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
304 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
309 int col = mono_col(info);
311 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
312 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
317 color = (is_fg) ? fg : bg;
322 * Scale down 16-colors to 4 colors. Default 4-color palette
323 * is grayscale. However, simply dividing the values by 4
324 * will not work, as colors 1, 2 and 3 will be scaled-down
325 * to zero rendering them invisible. So empirically convert
326 * colors to a sane 4-level grayscale.
330 color = 0; /* black */
333 color = 2; /* white */
336 color = 1; /* gray */
339 color = 3; /* intense white */
345 * Last 8 entries of default 16-color palette is a more intense
346 * version of the first 8 (i.e., same chrominance, different
357 static void fbcon_update_softback(struct vc_data *vc)
359 int l = fbcon_softback_size / vc->vc_size_row;
362 softback_end = softback_buf + l * vc->vc_size_row;
364 /* Smaller scrollback makes no sense, and 0 would screw
365 the operation totally */
369 static void fb_flashcursor(struct work_struct *work)
371 struct fb_info *info = container_of(work, struct fb_info, queue);
372 struct fbcon_ops *ops = info->fbcon_par;
373 struct vc_data *vc = NULL;
378 /* FIXME: we should sort out the unbind locking instead */
379 /* instead we just fail to flash the cursor if we can't get
380 * the lock instead of blocking fbcon deinit */
381 ret = console_trylock();
385 if (ops && ops->currcon != -1)
386 vc = vc_cons[ops->currcon].d;
388 if (!vc || !con_is_visible(vc) ||
389 registered_fb[con2fb_map[vc->vc_num]] != info ||
395 c = scr_readw((u16 *) vc->vc_pos);
396 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
398 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
399 get_color(vc, info, c, 0));
403 static void cursor_timer_handler(struct timer_list *t)
405 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
406 struct fb_info *info = ops->info;
408 queue_work(system_power_efficient_wq, &info->queue);
409 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
412 static void fbcon_add_cursor_timer(struct fb_info *info)
414 struct fbcon_ops *ops = info->fbcon_par;
416 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
417 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
418 !fbcon_cursor_noblink) {
419 if (!info->queue.func)
420 INIT_WORK(&info->queue, fb_flashcursor);
422 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
423 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
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 strlcpy(fontname, options + 5, sizeof(fontname));
454 if (!strncmp(options, "scrollback:", 11)) {
457 fbcon_softback_size = simple_strtoul(options, &options, 0);
458 if (*options == 'k' || *options == 'K') {
459 fbcon_softback_size *= 1024;
465 if (!strncmp(options, "map:", 4)) {
468 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
472 (options[j++]-'0') % FB_MAX;
475 fbcon_map_override();
480 if (!strncmp(options, "vc:", 3)) {
483 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
486 if (*options++ == '-')
487 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
488 fbcon_is_default = 0;
492 if (!strncmp(options, "rotate:", 7)) {
495 initial_rotation = simple_strtoul(options, &options, 0);
496 if (initial_rotation > 3)
497 initial_rotation = 0;
501 if (!strncmp(options, "margin:", 7)) {
504 margin_color = simple_strtoul(options, &options, 0);
507 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
508 if (!strcmp(options, "nodefer")) {
509 deferred_takeover = false;
517 __setup("fbcon=", fb_console_setup);
520 static int search_fb_in_map(int idx)
524 for (i = first_fb_vc; i <= last_fb_vc; i++) {
525 if (con2fb_map[i] == idx)
531 static int search_for_mapped_con(void)
535 for (i = first_fb_vc; i <= last_fb_vc; i++) {
536 if (con2fb_map[i] != -1)
542 static int do_fbcon_takeover(int show_logo)
546 if (!num_registered_fb)
550 logo_shown = FBCON_LOGO_DONTSHOW;
552 for (i = first_fb_vc; i <= last_fb_vc; i++)
553 con2fb_map[i] = info_idx;
555 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
559 for (i = first_fb_vc; i <= last_fb_vc; i++)
563 fbcon_has_console_bind = 1;
570 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
571 int cols, int rows, int new_cols, int new_rows)
573 logo_shown = FBCON_LOGO_DONTSHOW;
576 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
577 int cols, int rows, int new_cols, int new_rows)
579 /* Need to make room for the logo */
580 struct fbcon_ops *ops = info->fbcon_par;
581 int cnt, erase = vc->vc_video_erase_char, step;
582 unsigned short *save = NULL, *r, *q;
585 if (info->fbops->owner) {
586 logo_shown = FBCON_LOGO_DONTSHOW;
591 * remove underline attribute from erase character
592 * if black and white framebuffer.
594 if (fb_get_color_depth(&info->var, &info->fix) == 1)
596 logo_height = fb_prepare_logo(info, ops->rotate);
597 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
598 q = (unsigned short *) (vc->vc_origin +
599 vc->vc_size_row * rows);
600 step = logo_lines * cols;
601 for (r = q - logo_lines * cols; r < q; r++)
602 if (scr_readw(r) != vc->vc_video_erase_char)
604 if (r != q && new_rows >= rows + logo_lines) {
605 save = kmalloc(array3_size(logo_lines, new_cols, 2),
608 int i = cols < new_cols ? cols : new_cols;
609 scr_memsetw(save, erase, logo_lines * new_cols * 2);
611 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
612 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
617 /* We can scroll screen down */
619 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
620 scr_memcpyw(r + step, r, vc->vc_size_row);
625 if (vc->vc_y + logo_lines >= rows)
626 lines = rows - vc->vc_y - 1;
630 vc->vc_pos += lines * vc->vc_size_row;
633 scr_memsetw((unsigned short *) vc->vc_origin,
635 vc->vc_size_row * logo_lines);
637 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
638 fbcon_clear_margins(vc, 0);
643 q = (unsigned short *) (vc->vc_origin +
646 scr_memcpyw(q, save, logo_lines * new_cols * 2);
647 vc->vc_y += logo_lines;
648 vc->vc_pos += logo_lines * vc->vc_size_row;
652 if (logo_lines > vc->vc_bottom) {
653 logo_shown = FBCON_LOGO_CANSHOW;
655 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
656 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
657 logo_shown = FBCON_LOGO_DRAW;
658 vc->vc_top = logo_lines;
663 #ifdef CONFIG_FB_TILEBLITTING
664 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
666 struct fbcon_ops *ops = info->fbcon_par;
668 ops->p = &fb_display[vc->vc_num];
670 if ((info->flags & FBINFO_MISC_TILEBLITTING))
671 fbcon_set_tileops(vc, info);
673 fbcon_set_rotation(info);
674 fbcon_set_bitops(ops);
678 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
682 if (info->flags & FBINFO_MISC_TILEBLITTING &&
683 info->tileops->fb_get_tilemax(info) < charcount)
689 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
691 struct fbcon_ops *ops = info->fbcon_par;
693 info->flags &= ~FBINFO_MISC_TILEBLITTING;
694 ops->p = &fb_display[vc->vc_num];
695 fbcon_set_rotation(info);
696 fbcon_set_bitops(ops);
699 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
704 #endif /* CONFIG_MISC_TILEBLITTING */
707 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
708 int unit, int oldidx)
710 struct fbcon_ops *ops = NULL;
713 if (!try_module_get(info->fbops->owner))
716 if (!err && info->fbops->fb_open &&
717 info->fbops->fb_open(info, 0))
721 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
727 ops->cur_blink_jiffies = HZ / 5;
729 info->fbcon_par = ops;
732 set_blitting_type(vc, info);
736 con2fb_map[unit] = oldidx;
737 module_put(info->fbops->owner);
743 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
744 struct fb_info *newinfo, int unit,
745 int oldidx, int found)
747 struct fbcon_ops *ops = oldinfo->fbcon_par;
750 if (oldinfo->fbops->fb_release &&
751 oldinfo->fbops->fb_release(oldinfo, 0)) {
752 con2fb_map[unit] = oldidx;
753 if (!found && newinfo->fbops->fb_release)
754 newinfo->fbops->fb_release(newinfo, 0);
756 module_put(newinfo->fbops->owner);
761 fbcon_del_cursor_timer(oldinfo);
762 kfree(ops->cursor_state.mask);
763 kfree(ops->cursor_data);
764 kfree(ops->cursor_src);
765 kfree(ops->fontbuffer);
766 kfree(oldinfo->fbcon_par);
767 oldinfo->fbcon_par = NULL;
768 module_put(oldinfo->fbops->owner);
770 If oldinfo and newinfo are driving the same hardware,
771 the fb_release() method of oldinfo may attempt to
772 restore the hardware state. This will leave the
773 newinfo in an undefined state. Thus, a call to
774 fb_set_par() may be needed for the newinfo.
776 if (newinfo && newinfo->fbops->fb_set_par) {
777 ret = newinfo->fbops->fb_set_par(newinfo);
780 printk(KERN_ERR "con2fb_release_oldinfo: "
781 "detected unhandled fb_set_par error, "
782 "error code %d\n", ret);
789 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
790 int unit, int show_logo)
792 struct fbcon_ops *ops = info->fbcon_par;
795 ops->currcon = fg_console;
797 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
798 ret = info->fbops->fb_set_par(info);
801 printk(KERN_ERR "con2fb_init_display: detected "
802 "unhandled fb_set_par error, "
803 "error code %d\n", ret);
806 ops->flags |= FBCON_FLAGS_INIT;
808 fbcon_set_disp(info, &info->var, unit);
811 struct vc_data *fg_vc = vc_cons[fg_console].d;
812 struct fb_info *fg_info =
813 registered_fb[con2fb_map[fg_console]];
815 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
816 fg_vc->vc_rows, fg_vc->vc_cols,
820 update_screen(vc_cons[fg_console].d);
824 * set_con2fb_map - map console to frame buffer device
825 * @unit: virtual console number to map
826 * @newidx: frame buffer index to map virtual console to
827 * @user: user request
829 * Maps a virtual console @unit to a frame buffer device
832 * This should be called with the console lock held.
834 static int set_con2fb_map(int unit, int newidx, int user)
836 struct vc_data *vc = vc_cons[unit].d;
837 int oldidx = con2fb_map[unit];
838 struct fb_info *info = registered_fb[newidx];
839 struct fb_info *oldinfo = NULL;
842 WARN_CONSOLE_UNLOCKED();
844 if (oldidx == newidx)
850 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
852 return do_fbcon_takeover(0);
856 oldinfo = registered_fb[oldidx];
858 found = search_fb_in_map(newidx);
860 con2fb_map[unit] = newidx;
862 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
866 * If old fb is not mapped to any of the consoles,
867 * fbcon should release it.
869 if (!err && oldinfo && !search_fb_in_map(oldidx))
870 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
874 int show_logo = (fg_console == 0 && !user &&
875 logo_shown != FBCON_LOGO_DONTSHOW);
878 fbcon_add_cursor_timer(info);
879 con2fb_map_boot[unit] = newidx;
880 con2fb_init_display(vc, info, unit, show_logo);
883 if (!search_fb_in_map(info_idx))
890 * Low Level Operations
892 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
893 static int var_to_display(struct display *disp,
894 struct fb_var_screeninfo *var,
895 struct fb_info *info)
897 disp->xres_virtual = var->xres_virtual;
898 disp->yres_virtual = var->yres_virtual;
899 disp->bits_per_pixel = var->bits_per_pixel;
900 disp->grayscale = var->grayscale;
901 disp->nonstd = var->nonstd;
902 disp->accel_flags = var->accel_flags;
903 disp->height = var->height;
904 disp->width = var->width;
905 disp->red = var->red;
906 disp->green = var->green;
907 disp->blue = var->blue;
908 disp->transp = var->transp;
909 disp->rotate = var->rotate;
910 disp->mode = fb_match_mode(var, &info->modelist);
911 if (disp->mode == NULL)
912 /* This should not happen */
917 static void display_to_var(struct fb_var_screeninfo *var,
918 struct display *disp)
920 fb_videomode_to_var(var, disp->mode);
921 var->xres_virtual = disp->xres_virtual;
922 var->yres_virtual = disp->yres_virtual;
923 var->bits_per_pixel = disp->bits_per_pixel;
924 var->grayscale = disp->grayscale;
925 var->nonstd = disp->nonstd;
926 var->accel_flags = disp->accel_flags;
927 var->height = disp->height;
928 var->width = disp->width;
929 var->red = disp->red;
930 var->green = disp->green;
931 var->blue = disp->blue;
932 var->transp = disp->transp;
933 var->rotate = disp->rotate;
936 static const char *fbcon_startup(void)
938 const char *display_desc = "frame buffer device";
939 struct display *p = &fb_display[fg_console];
940 struct vc_data *vc = vc_cons[fg_console].d;
941 const struct font_desc *font = NULL;
942 struct module *owner;
943 struct fb_info *info = NULL;
944 struct fbcon_ops *ops;
948 * If num_registered_fb is zero, this is a call for the dummy part.
949 * The frame buffer devices weren't initialized yet.
951 if (!num_registered_fb || info_idx == -1)
954 * Instead of blindly using registered_fb[0], we use info_idx, set by
957 info = registered_fb[info_idx];
961 owner = info->fbops->owner;
962 if (!try_module_get(owner))
964 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
969 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
977 ops->cur_rotate = -1;
978 ops->cur_blink_jiffies = HZ / 5;
980 info->fbcon_par = ops;
982 p->con_rotate = initial_rotation;
983 if (p->con_rotate == -1)
984 p->con_rotate = info->fbcon_rotate_hint;
985 if (p->con_rotate == -1)
986 p->con_rotate = FB_ROTATE_UR;
988 set_blitting_type(vc, info);
990 if (info->fix.type != FB_TYPE_TEXT) {
991 if (fbcon_softback_size) {
995 kmalloc(fbcon_softback_size,
998 fbcon_softback_size = 0;
1004 kfree((void *) softback_buf);
1010 softback_in = softback_top = softback_curr =
1015 /* Setup default font */
1016 if (!p->fontdata && !vc->vc_font.data) {
1017 if (!fontname[0] || !(font = find_font(fontname)))
1018 font = get_default_font(info->var.xres,
1020 info->pixmap.blit_x,
1021 info->pixmap.blit_y);
1022 vc->vc_font.width = font->width;
1023 vc->vc_font.height = font->height;
1024 vc->vc_font.data = (void *)(p->fontdata = font->data);
1025 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1027 p->fontdata = vc->vc_font.data;
1030 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1031 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1032 cols /= vc->vc_font.width;
1033 rows /= vc->vc_font.height;
1034 vc_resize(vc, cols, rows);
1036 DPRINTK("mode: %s\n", info->fix.id);
1037 DPRINTK("visual: %d\n", info->fix.visual);
1038 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1040 info->var.bits_per_pixel);
1042 fbcon_add_cursor_timer(info);
1043 fbcon_has_exited = 0;
1044 return display_desc;
1047 static void fbcon_init(struct vc_data *vc, int init)
1049 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1050 struct fbcon_ops *ops;
1051 struct vc_data **default_mode = vc->vc_display_fg;
1052 struct vc_data *svc = *default_mode;
1053 struct display *t, *p = &fb_display[vc->vc_num];
1054 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1057 if (info_idx == -1 || info == NULL)
1062 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1063 (info->fix.type == FB_TYPE_TEXT))
1066 if (var_to_display(p, &info->var, info))
1069 if (!info->fbcon_par)
1070 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1072 /* If we are not the first console on this
1073 fb, copy the font from that console */
1074 t = &fb_display[fg_console];
1077 struct vc_data *fvc = vc_cons[fg_console].d;
1079 vc->vc_font.data = (void *)(p->fontdata =
1081 vc->vc_font.width = fvc->vc_font.width;
1082 vc->vc_font.height = fvc->vc_font.height;
1083 p->userfont = t->userfont;
1086 REFCOUNT(p->fontdata)++;
1088 const struct font_desc *font = NULL;
1090 if (!fontname[0] || !(font = find_font(fontname)))
1091 font = get_default_font(info->var.xres,
1093 info->pixmap.blit_x,
1094 info->pixmap.blit_y);
1095 vc->vc_font.width = font->width;
1096 vc->vc_font.height = font->height;
1097 vc->vc_font.data = (void *)(p->fontdata = font->data);
1098 vc->vc_font.charcount = 256; /* FIXME Need to
1099 support more fonts */
1104 charcnt = FNTCHARCNT(p->fontdata);
1106 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1107 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1108 if (charcnt == 256) {
1109 vc->vc_hi_font_mask = 0;
1111 vc->vc_hi_font_mask = 0x100;
1112 if (vc->vc_can_do_color)
1113 vc->vc_complement_mask <<= 1;
1116 if (!*svc->vc_uni_pagedir_loc)
1117 con_set_default_unimap(svc);
1118 if (!*vc->vc_uni_pagedir_loc)
1119 con_copy_unimap(vc, svc);
1121 ops = info->fbcon_par;
1122 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1124 p->con_rotate = initial_rotation;
1125 if (p->con_rotate == -1)
1126 p->con_rotate = info->fbcon_rotate_hint;
1127 if (p->con_rotate == -1)
1128 p->con_rotate = FB_ROTATE_UR;
1130 set_blitting_type(vc, info);
1134 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1135 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1136 new_cols /= vc->vc_font.width;
1137 new_rows /= vc->vc_font.height;
1140 * We must always set the mode. The mode of the previous console
1141 * driver could be in the same resolution but we are using different
1142 * hardware so we have to initialize the hardware.
1144 * We need to do it in fbcon_init() to prevent screen corruption.
1146 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1147 if (info->fbops->fb_set_par &&
1148 !(ops->flags & FBCON_FLAGS_INIT)) {
1149 ret = info->fbops->fb_set_par(info);
1152 printk(KERN_ERR "fbcon_init: detected "
1153 "unhandled fb_set_par error, "
1154 "error code %d\n", ret);
1157 ops->flags |= FBCON_FLAGS_INIT;
1162 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1163 !(cap & FBINFO_HWACCEL_DISABLED))
1164 p->scrollmode = SCROLL_MOVE;
1165 else /* default to something safe */
1166 p->scrollmode = SCROLL_REDRAW;
1169 * ++guenther: console.c:vc_allocate() relies on initializing
1170 * vc_{cols,rows}, but we must not set those if we are only
1171 * resizing the console.
1174 vc->vc_cols = new_cols;
1175 vc->vc_rows = new_rows;
1177 vc_resize(vc, new_cols, new_rows);
1180 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1182 if (vc == svc && softback_buf)
1183 fbcon_update_softback(vc);
1185 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1186 ops->rotate = FB_ROTATE_UR;
1187 set_blitting_type(vc, info);
1190 ops->p = &fb_display[fg_console];
1193 static void fbcon_free_font(struct display *p, bool freefont)
1195 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1196 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1201 static void set_vc_hi_font(struct vc_data *vc, bool set);
1203 static void fbcon_deinit(struct vc_data *vc)
1205 struct display *p = &fb_display[vc->vc_num];
1206 struct fb_info *info;
1207 struct fbcon_ops *ops;
1209 bool free_font = true;
1211 idx = con2fb_map[vc->vc_num];
1216 info = registered_fb[idx];
1221 if (info->flags & FBINFO_MISC_FIRMWARE)
1223 ops = info->fbcon_par;
1228 if (con_is_visible(vc))
1229 fbcon_del_cursor_timer(info);
1231 ops->flags &= ~FBCON_FLAGS_INIT;
1234 fbcon_free_font(p, free_font);
1236 vc->vc_font.data = NULL;
1238 if (vc->vc_hi_font_mask)
1239 set_vc_hi_font(vc, false);
1241 if (!con_is_bound(&fb_con))
1247 /* ====================================================================== */
1249 /* fbcon_XXX routines - interface used by the world
1251 * This system is now divided into two levels because of complications
1252 * caused by hardware scrolling. Top level functions:
1254 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1256 * handles y values in range [0, scr_height-1] that correspond to real
1257 * screen positions. y_wrap shift means that first line of bitmap may be
1258 * anywhere on this display. These functions convert lineoffsets to
1259 * bitmap offsets and deal with the wrap-around case by splitting blits.
1261 * fbcon_bmove_physical_8() -- These functions fast implementations
1262 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1263 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1267 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1268 * Implies should only really hardware scroll in rows. Only reason for
1269 * restriction is simplicity & efficiency at the moment.
1272 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1275 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1276 struct fbcon_ops *ops = info->fbcon_par;
1278 struct display *p = &fb_display[vc->vc_num];
1281 if (fbcon_is_inactive(vc, info))
1284 if (!height || !width)
1287 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1290 * If the font dimensions are not an integral of the display
1291 * dimensions then the ops->clear below won't end up clearing
1292 * the margins. Call clear_margins here in case the logo
1293 * bitmap stretched into the margin area.
1295 fbcon_clear_margins(vc, 0);
1298 /* Split blits that cross physical y_wrap boundary */
1300 y_break = p->vrows - p->yscroll;
1301 if (sy < y_break && sy + height - 1 >= y_break) {
1302 u_int b = y_break - sy;
1303 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1304 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1307 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1310 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1311 int count, int ypos, int xpos)
1313 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1314 struct display *p = &fb_display[vc->vc_num];
1315 struct fbcon_ops *ops = info->fbcon_par;
1317 if (!fbcon_is_inactive(vc, info))
1318 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1319 get_color(vc, info, scr_readw(s), 1),
1320 get_color(vc, info, scr_readw(s), 0));
1323 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1327 scr_writew(c, &chr);
1328 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1331 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1333 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1334 struct fbcon_ops *ops = info->fbcon_par;
1336 if (!fbcon_is_inactive(vc, info))
1337 ops->clear_margins(vc, info, margin_color, bottom_only);
1340 static void fbcon_cursor(struct vc_data *vc, int mode)
1342 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1343 struct fbcon_ops *ops = info->fbcon_par;
1345 int c = scr_readw((u16 *) vc->vc_pos);
1347 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1349 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1352 if (vc->vc_cursor_type & 0x10)
1353 fbcon_del_cursor_timer(info);
1355 fbcon_add_cursor_timer(info);
1357 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1358 if (mode & CM_SOFTBACK) {
1359 mode &= ~CM_SOFTBACK;
1363 fbcon_set_origin(vc);
1367 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1368 get_color(vc, info, c, 0));
1371 static int scrollback_phys_max = 0;
1372 static int scrollback_max = 0;
1373 static int scrollback_current = 0;
1375 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1378 struct display *p, *t;
1379 struct vc_data **default_mode, *vc;
1380 struct vc_data *svc;
1381 struct fbcon_ops *ops = info->fbcon_par;
1382 int rows, cols, charcnt = 256;
1384 p = &fb_display[unit];
1386 if (var_to_display(p, var, info))
1389 vc = vc_cons[unit].d;
1394 default_mode = vc->vc_display_fg;
1395 svc = *default_mode;
1396 t = &fb_display[svc->vc_num];
1398 if (!vc->vc_font.data) {
1399 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1400 vc->vc_font.width = (*default_mode)->vc_font.width;
1401 vc->vc_font.height = (*default_mode)->vc_font.height;
1402 p->userfont = t->userfont;
1404 REFCOUNT(p->fontdata)++;
1407 charcnt = FNTCHARCNT(p->fontdata);
1409 var->activate = FB_ACTIVATE_NOW;
1410 info->var.activate = var->activate;
1411 var->yoffset = info->var.yoffset;
1412 var->xoffset = info->var.xoffset;
1413 fb_set_var(info, var);
1414 ops->var = info->var;
1415 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1416 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1417 if (charcnt == 256) {
1418 vc->vc_hi_font_mask = 0;
1420 vc->vc_hi_font_mask = 0x100;
1421 if (vc->vc_can_do_color)
1422 vc->vc_complement_mask <<= 1;
1425 if (!*svc->vc_uni_pagedir_loc)
1426 con_set_default_unimap(svc);
1427 if (!*vc->vc_uni_pagedir_loc)
1428 con_copy_unimap(vc, svc);
1430 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1431 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1432 cols /= vc->vc_font.width;
1433 rows /= vc->vc_font.height;
1434 vc_resize(vc, cols, rows);
1436 if (con_is_visible(vc)) {
1439 fbcon_update_softback(vc);
1443 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1445 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1446 struct fbcon_ops *ops = info->fbcon_par;
1447 struct display *p = &fb_display[vc->vc_num];
1449 p->yscroll += count;
1450 if (p->yscroll >= p->vrows) /* Deal with wrap */
1451 p->yscroll -= p->vrows;
1452 ops->var.xoffset = 0;
1453 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1454 ops->var.vmode |= FB_VMODE_YWRAP;
1455 ops->update_start(info);
1456 scrollback_max += count;
1457 if (scrollback_max > scrollback_phys_max)
1458 scrollback_max = scrollback_phys_max;
1459 scrollback_current = 0;
1462 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1464 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1465 struct fbcon_ops *ops = info->fbcon_par;
1466 struct display *p = &fb_display[vc->vc_num];
1468 p->yscroll -= count;
1469 if (p->yscroll < 0) /* Deal with wrap */
1470 p->yscroll += p->vrows;
1471 ops->var.xoffset = 0;
1472 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1473 ops->var.vmode |= FB_VMODE_YWRAP;
1474 ops->update_start(info);
1475 scrollback_max -= count;
1476 if (scrollback_max < 0)
1478 scrollback_current = 0;
1481 static __inline__ void ypan_up(struct vc_data *vc, int count)
1483 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1484 struct display *p = &fb_display[vc->vc_num];
1485 struct fbcon_ops *ops = info->fbcon_par;
1487 p->yscroll += count;
1488 if (p->yscroll > p->vrows - vc->vc_rows) {
1489 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1490 0, 0, 0, vc->vc_rows, vc->vc_cols);
1491 p->yscroll -= p->vrows - vc->vc_rows;
1494 ops->var.xoffset = 0;
1495 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1496 ops->var.vmode &= ~FB_VMODE_YWRAP;
1497 ops->update_start(info);
1498 fbcon_clear_margins(vc, 1);
1499 scrollback_max += count;
1500 if (scrollback_max > scrollback_phys_max)
1501 scrollback_max = scrollback_phys_max;
1502 scrollback_current = 0;
1505 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1507 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1508 struct fbcon_ops *ops = info->fbcon_par;
1509 struct display *p = &fb_display[vc->vc_num];
1511 p->yscroll += count;
1513 if (p->yscroll > p->vrows - vc->vc_rows) {
1514 p->yscroll -= p->vrows - vc->vc_rows;
1515 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1518 ops->var.xoffset = 0;
1519 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1520 ops->var.vmode &= ~FB_VMODE_YWRAP;
1521 ops->update_start(info);
1522 fbcon_clear_margins(vc, 1);
1523 scrollback_max += count;
1524 if (scrollback_max > scrollback_phys_max)
1525 scrollback_max = scrollback_phys_max;
1526 scrollback_current = 0;
1529 static __inline__ void ypan_down(struct vc_data *vc, int count)
1531 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1532 struct display *p = &fb_display[vc->vc_num];
1533 struct fbcon_ops *ops = info->fbcon_par;
1535 p->yscroll -= count;
1536 if (p->yscroll < 0) {
1537 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1538 0, vc->vc_rows, vc->vc_cols);
1539 p->yscroll += p->vrows - vc->vc_rows;
1542 ops->var.xoffset = 0;
1543 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1544 ops->var.vmode &= ~FB_VMODE_YWRAP;
1545 ops->update_start(info);
1546 fbcon_clear_margins(vc, 1);
1547 scrollback_max -= count;
1548 if (scrollback_max < 0)
1550 scrollback_current = 0;
1553 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1555 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1556 struct fbcon_ops *ops = info->fbcon_par;
1557 struct display *p = &fb_display[vc->vc_num];
1559 p->yscroll -= count;
1561 if (p->yscroll < 0) {
1562 p->yscroll += p->vrows - vc->vc_rows;
1563 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1566 ops->var.xoffset = 0;
1567 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1568 ops->var.vmode &= ~FB_VMODE_YWRAP;
1569 ops->update_start(info);
1570 fbcon_clear_margins(vc, 1);
1571 scrollback_max -= count;
1572 if (scrollback_max < 0)
1574 scrollback_current = 0;
1577 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1580 int count = vc->vc_rows;
1581 unsigned short *d, *s;
1585 d = (u16 *) softback_curr;
1586 if (d == (u16 *) softback_in)
1587 d = (u16 *) vc->vc_origin;
1588 n = softback_curr + delta * vc->vc_size_row;
1589 softback_lines -= delta;
1591 if (softback_curr < softback_top && n < softback_buf) {
1592 n += softback_end - softback_buf;
1593 if (n < softback_top) {
1595 (softback_top - n) / vc->vc_size_row;
1598 } else if (softback_curr >= softback_top
1599 && n < softback_top) {
1601 (softback_top - n) / vc->vc_size_row;
1605 if (softback_curr > softback_in && n >= softback_end) {
1606 n += softback_buf - softback_end;
1607 if (n > softback_in) {
1611 } else if (softback_curr <= softback_in && n > softback_in) {
1616 if (n == softback_curr)
1619 s = (u16 *) softback_curr;
1620 if (s == (u16 *) softback_in)
1621 s = (u16 *) vc->vc_origin;
1623 unsigned short *start;
1627 unsigned short attr = 1;
1630 le = advance_row(s, 1);
1633 if (attr != (c & 0xff00)) {
1636 fbcon_putcs(vc, start, s - start,
1642 if (c == scr_readw(d)) {
1644 fbcon_putcs(vc, start, s - start,
1657 fbcon_putcs(vc, start, s - start, line, x);
1659 if (d == (u16 *) softback_end)
1660 d = (u16 *) softback_buf;
1661 if (d == (u16 *) softback_in)
1662 d = (u16 *) vc->vc_origin;
1663 if (s == (u16 *) softback_end)
1664 s = (u16 *) softback_buf;
1665 if (s == (u16 *) softback_in)
1666 s = (u16 *) vc->vc_origin;
1670 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1671 int line, int count, int dy)
1673 unsigned short *s = (unsigned short *)
1674 (vc->vc_origin + vc->vc_size_row * line);
1677 unsigned short *start = s;
1678 unsigned short *le = advance_row(s, 1);
1681 unsigned short attr = 1;
1685 if (attr != (c & 0xff00)) {
1688 fbcon_putcs(vc, start, s - start,
1694 console_conditional_schedule();
1698 fbcon_putcs(vc, start, s - start, dy, x);
1699 console_conditional_schedule();
1704 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1705 struct display *p, int line, int count, int ycount)
1707 int offset = ycount * vc->vc_cols;
1708 unsigned short *d = (unsigned short *)
1709 (vc->vc_origin + vc->vc_size_row * line);
1710 unsigned short *s = d + offset;
1711 struct fbcon_ops *ops = info->fbcon_par;
1714 unsigned short *start = s;
1715 unsigned short *le = advance_row(s, 1);
1722 if (c == scr_readw(d)) {
1724 ops->bmove(vc, info, line + ycount, x,
1725 line, x, 1, s-start);
1735 console_conditional_schedule();
1740 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1742 console_conditional_schedule();
1747 /* NOTE: We subtract two lines from these pointers */
1748 s -= vc->vc_size_row;
1749 d -= vc->vc_size_row;
1754 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1755 int line, int count, int offset)
1757 unsigned short *d = (unsigned short *)
1758 (vc->vc_origin + vc->vc_size_row * line);
1759 unsigned short *s = d + offset;
1762 unsigned short *start = s;
1763 unsigned short *le = advance_row(s, 1);
1766 unsigned short attr = 1;
1770 if (attr != (c & 0xff00)) {
1773 fbcon_putcs(vc, start, s - start,
1779 if (c == scr_readw(d)) {
1781 fbcon_putcs(vc, start, s - start,
1791 console_conditional_schedule();
1796 fbcon_putcs(vc, start, s - start, line, x);
1797 console_conditional_schedule();
1802 /* NOTE: We subtract two lines from these pointers */
1803 s -= vc->vc_size_row;
1804 d -= vc->vc_size_row;
1809 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1814 if (vc->vc_num != fg_console)
1816 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1819 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1821 p = advance_row(p, 1);
1822 softback_in += vc->vc_size_row;
1823 if (softback_in == softback_end)
1824 softback_in = softback_buf;
1825 if (softback_in == softback_top) {
1826 softback_top += vc->vc_size_row;
1827 if (softback_top == softback_end)
1828 softback_top = softback_buf;
1831 softback_curr = softback_in;
1834 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1835 enum con_scroll dir, unsigned int count)
1837 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1838 struct display *p = &fb_display[vc->vc_num];
1839 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1841 if (fbcon_is_inactive(vc, info))
1844 fbcon_cursor(vc, CM_ERASE);
1847 * ++Geert: Only use ywrap/ypan if the console is in text mode
1848 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1849 * whole screen (prevents flicker).
1854 if (count > vc->vc_rows) /* Maximum realistic size */
1855 count = vc->vc_rows;
1857 fbcon_softback_note(vc, t, count);
1858 if (logo_shown >= 0)
1860 switch (p->scrollmode) {
1862 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1864 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1865 scr_memsetw((unsigned short *) (vc->vc_origin +
1868 vc->vc_video_erase_char,
1869 vc->vc_size_row * count);
1873 case SCROLL_WRAP_MOVE:
1874 if (b - t - count > 3 * vc->vc_rows >> 2) {
1876 fbcon_bmove(vc, 0, 0, count, 0, t,
1878 ywrap_up(vc, count);
1879 if (vc->vc_rows - b > 0)
1880 fbcon_bmove(vc, b - count, 0, b, 0,
1883 } else if (info->flags & FBINFO_READS_FAST)
1884 fbcon_bmove(vc, t + count, 0, t, 0,
1885 b - t - count, vc->vc_cols);
1888 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1891 case SCROLL_PAN_REDRAW:
1892 if ((p->yscroll + count <=
1893 2 * (p->vrows - vc->vc_rows))
1894 && ((!scroll_partial && (b - t == vc->vc_rows))
1897 3 * vc->vc_rows >> 2)))) {
1899 fbcon_redraw_move(vc, p, 0, t, count);
1900 ypan_up_redraw(vc, t, count);
1901 if (vc->vc_rows - b > 0)
1902 fbcon_redraw_move(vc, p, b,
1903 vc->vc_rows - b, b);
1905 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1906 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1909 case SCROLL_PAN_MOVE:
1910 if ((p->yscroll + count <=
1911 2 * (p->vrows - vc->vc_rows))
1912 && ((!scroll_partial && (b - t == vc->vc_rows))
1915 3 * vc->vc_rows >> 2)))) {
1917 fbcon_bmove(vc, 0, 0, count, 0, t,
1920 if (vc->vc_rows - b > 0)
1921 fbcon_bmove(vc, b - count, 0, b, 0,
1924 } else if (info->flags & FBINFO_READS_FAST)
1925 fbcon_bmove(vc, t + count, 0, t, 0,
1926 b - t - count, vc->vc_cols);
1929 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1934 fbcon_redraw(vc, p, t, b - t - count,
1935 count * vc->vc_cols);
1936 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1937 scr_memsetw((unsigned short *) (vc->vc_origin +
1940 vc->vc_video_erase_char,
1941 vc->vc_size_row * count);
1947 if (count > vc->vc_rows) /* Maximum realistic size */
1948 count = vc->vc_rows;
1949 if (logo_shown >= 0)
1951 switch (p->scrollmode) {
1953 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1955 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1956 scr_memsetw((unsigned short *) (vc->vc_origin +
1959 vc->vc_video_erase_char,
1960 vc->vc_size_row * count);
1964 case SCROLL_WRAP_MOVE:
1965 if (b - t - count > 3 * vc->vc_rows >> 2) {
1966 if (vc->vc_rows - b > 0)
1967 fbcon_bmove(vc, b, 0, b - count, 0,
1970 ywrap_down(vc, count);
1972 fbcon_bmove(vc, count, 0, 0, 0, t,
1974 } else if (info->flags & FBINFO_READS_FAST)
1975 fbcon_bmove(vc, t, 0, t + count, 0,
1976 b - t - count, vc->vc_cols);
1979 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1982 case SCROLL_PAN_MOVE:
1983 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1984 && ((!scroll_partial && (b - t == vc->vc_rows))
1987 3 * vc->vc_rows >> 2)))) {
1988 if (vc->vc_rows - b > 0)
1989 fbcon_bmove(vc, b, 0, b - count, 0,
1992 ypan_down(vc, count);
1994 fbcon_bmove(vc, count, 0, 0, 0, t,
1996 } else if (info->flags & FBINFO_READS_FAST)
1997 fbcon_bmove(vc, t, 0, t + count, 0,
1998 b - t - count, vc->vc_cols);
2001 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2004 case SCROLL_PAN_REDRAW:
2005 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2006 && ((!scroll_partial && (b - t == vc->vc_rows))
2009 3 * vc->vc_rows >> 2)))) {
2010 if (vc->vc_rows - b > 0)
2011 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2013 ypan_down_redraw(vc, t, count);
2015 fbcon_redraw_move(vc, p, count, t, 0);
2017 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2018 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2023 fbcon_redraw(vc, p, b - 1, b - t - count,
2024 -count * vc->vc_cols);
2025 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2026 scr_memsetw((unsigned short *) (vc->vc_origin +
2029 vc->vc_video_erase_char,
2030 vc->vc_size_row * count);
2038 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2039 int height, int width)
2041 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2042 struct display *p = &fb_display[vc->vc_num];
2044 if (fbcon_is_inactive(vc, info))
2047 if (!width || !height)
2050 /* Split blits that cross physical y_wrap case.
2051 * Pathological case involves 4 blits, better to use recursive
2052 * code rather than unrolled case
2054 * Recursive invocations don't need to erase the cursor over and
2055 * over again, so we use fbcon_bmove_rec()
2057 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2058 p->vrows - p->yscroll);
2061 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2062 int dy, int dx, int height, int width, u_int y_break)
2064 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2065 struct fbcon_ops *ops = info->fbcon_par;
2068 if (sy < y_break && sy + height > y_break) {
2070 if (dy < sy) { /* Avoid trashing self */
2071 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2073 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2074 height - b, width, y_break);
2076 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2077 height - b, width, y_break);
2078 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2084 if (dy < y_break && dy + height > y_break) {
2086 if (dy < sy) { /* Avoid trashing self */
2087 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2089 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2090 height - b, width, y_break);
2092 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2093 height - b, width, y_break);
2094 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2099 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2103 static void updatescrollmode(struct display *p,
2104 struct fb_info *info,
2107 struct fbcon_ops *ops = info->fbcon_par;
2108 int fh = vc->vc_font.height;
2109 int cap = info->flags;
2111 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2112 info->fix.xpanstep);
2113 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2114 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2115 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2116 info->var.xres_virtual);
2117 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2118 divides(ypan, vc->vc_font.height) && vyres > yres;
2119 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2120 divides(ywrap, vc->vc_font.height) &&
2121 divides(vc->vc_font.height, vyres) &&
2122 divides(vc->vc_font.height, yres);
2123 int reading_fast = cap & FBINFO_READS_FAST;
2124 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2125 !(cap & FBINFO_HWACCEL_DISABLED);
2126 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2127 !(cap & FBINFO_HWACCEL_DISABLED);
2129 p->vrows = vyres/fh;
2130 if (yres > (fh * (vc->vc_rows + 1)))
2131 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2132 if ((yres % fh) && (vyres % fh < yres % fh))
2135 if (good_wrap || good_pan) {
2136 if (reading_fast || fast_copyarea)
2137 p->scrollmode = good_wrap ?
2138 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2140 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2143 if (reading_fast || (fast_copyarea && !fast_imageblit))
2144 p->scrollmode = SCROLL_MOVE;
2146 p->scrollmode = SCROLL_REDRAW;
2150 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2151 unsigned int height, unsigned int user)
2153 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2154 struct fbcon_ops *ops = info->fbcon_par;
2155 struct display *p = &fb_display[vc->vc_num];
2156 struct fb_var_screeninfo var = info->var;
2157 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2159 virt_w = FBCON_SWAP(ops->rotate, width, height);
2160 virt_h = FBCON_SWAP(ops->rotate, height, width);
2161 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2162 vc->vc_font.height);
2163 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2165 var.xres = virt_w * virt_fw;
2166 var.yres = virt_h * virt_fh;
2167 x_diff = info->var.xres - var.xres;
2168 y_diff = info->var.yres - var.yres;
2169 if (x_diff < 0 || x_diff > virt_fw ||
2170 y_diff < 0 || y_diff > virt_fh) {
2171 const struct fb_videomode *mode;
2173 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2174 mode = fb_find_best_mode(&var, &info->modelist);
2177 display_to_var(&var, p);
2178 fb_videomode_to_var(&var, mode);
2180 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2183 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2184 if (con_is_visible(vc)) {
2185 var.activate = FB_ACTIVATE_NOW |
2187 fb_set_var(info, &var);
2189 var_to_display(p, &info->var, info);
2190 ops->var = info->var;
2192 updatescrollmode(p, info, vc);
2196 static int fbcon_switch(struct vc_data *vc)
2198 struct fb_info *info, *old_info = NULL;
2199 struct fbcon_ops *ops;
2200 struct display *p = &fb_display[vc->vc_num];
2201 struct fb_var_screeninfo var;
2202 int i, ret, prev_console, charcnt = 256;
2204 info = registered_fb[con2fb_map[vc->vc_num]];
2205 ops = info->fbcon_par;
2209 fbcon_set_origin(vc);
2210 softback_top = softback_curr = softback_in = softback_buf;
2212 fbcon_update_softback(vc);
2215 if (logo_shown >= 0) {
2216 struct vc_data *conp2 = vc_cons[logo_shown].d;
2218 if (conp2->vc_top == logo_lines
2219 && conp2->vc_bottom == conp2->vc_rows)
2221 logo_shown = FBCON_LOGO_CANSHOW;
2224 prev_console = ops->currcon;
2225 if (prev_console != -1)
2226 old_info = registered_fb[con2fb_map[prev_console]];
2228 * FIXME: If we have multiple fbdev's loaded, we need to
2229 * update all info->currcon. Perhaps, we can place this
2230 * in a centralized structure, but this might break some
2233 * info->currcon = vc->vc_num;
2235 for_each_registered_fb(i) {
2236 if (registered_fb[i]->fbcon_par) {
2237 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2239 o->currcon = vc->vc_num;
2242 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2243 display_to_var(&var, p);
2244 var.activate = FB_ACTIVATE_NOW;
2247 * make sure we don't unnecessarily trip the memcmp()
2250 info->var.activate = var.activate;
2251 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2252 fb_set_var(info, &var);
2253 ops->var = info->var;
2255 if (old_info != NULL && (old_info != info ||
2256 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2257 if (info->fbops->fb_set_par) {
2258 ret = info->fbops->fb_set_par(info);
2261 printk(KERN_ERR "fbcon_switch: detected "
2262 "unhandled fb_set_par error, "
2263 "error code %d\n", ret);
2266 if (old_info != info)
2267 fbcon_del_cursor_timer(old_info);
2270 if (fbcon_is_inactive(vc, info) ||
2271 ops->blank_state != FB_BLANK_UNBLANK)
2272 fbcon_del_cursor_timer(info);
2274 fbcon_add_cursor_timer(info);
2276 set_blitting_type(vc, info);
2277 ops->cursor_reset = 1;
2279 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2280 ops->rotate = FB_ROTATE_UR;
2281 set_blitting_type(vc, info);
2284 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2285 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2288 charcnt = FNTCHARCNT(vc->vc_font.data);
2291 vc->vc_complement_mask <<= 1;
2293 updatescrollmode(p, info, vc);
2295 switch (p->scrollmode) {
2296 case SCROLL_WRAP_MOVE:
2297 scrollback_phys_max = p->vrows - vc->vc_rows;
2299 case SCROLL_PAN_MOVE:
2300 case SCROLL_PAN_REDRAW:
2301 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2302 if (scrollback_phys_max < 0)
2303 scrollback_phys_max = 0;
2306 scrollback_phys_max = 0;
2311 scrollback_current = 0;
2313 if (!fbcon_is_inactive(vc, info)) {
2314 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2315 ops->update_start(info);
2318 fbcon_set_palette(vc, color_table);
2319 fbcon_clear_margins(vc, 0);
2321 if (logo_shown == FBCON_LOGO_DRAW) {
2323 logo_shown = fg_console;
2324 /* This is protected above by initmem_freed */
2325 fb_show_logo(info, ops->rotate);
2327 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2328 vc->vc_size_row * (vc->vc_bottom -
2335 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2338 struct fb_event event;
2341 unsigned short charmask = vc->vc_hi_font_mask ?
2343 unsigned short oldc;
2345 oldc = vc->vc_video_erase_char;
2346 vc->vc_video_erase_char &= charmask;
2347 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2348 vc->vc_video_erase_char = oldc;
2352 if (!lock_fb_info(info))
2355 event.data = ␣
2356 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2357 unlock_fb_info(info);
2360 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2362 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2363 struct fbcon_ops *ops = info->fbcon_par;
2366 struct fb_var_screeninfo var = info->var;
2371 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2372 fb_set_var(info, &var);
2374 ops->var = info->var;
2378 if (!fbcon_is_inactive(vc, info)) {
2379 if (ops->blank_state != blank) {
2380 ops->blank_state = blank;
2381 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2382 ops->cursor_flash = (!blank);
2384 if (!(info->flags & FBINFO_MISC_USEREVENT))
2385 if (fb_blank(info, blank))
2386 fbcon_generic_blank(vc, info, blank);
2393 if (mode_switch || fbcon_is_inactive(vc, info) ||
2394 ops->blank_state != FB_BLANK_UNBLANK)
2395 fbcon_del_cursor_timer(info);
2397 fbcon_add_cursor_timer(info);
2402 static int fbcon_debug_enter(struct vc_data *vc)
2404 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2405 struct fbcon_ops *ops = info->fbcon_par;
2407 ops->save_graphics = ops->graphics;
2409 if (info->fbops->fb_debug_enter)
2410 info->fbops->fb_debug_enter(info);
2411 fbcon_set_palette(vc, color_table);
2415 static int fbcon_debug_leave(struct vc_data *vc)
2417 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2418 struct fbcon_ops *ops = info->fbcon_par;
2420 ops->graphics = ops->save_graphics;
2421 if (info->fbops->fb_debug_leave)
2422 info->fbops->fb_debug_leave(info);
2426 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2428 u8 *fontdata = vc->vc_font.data;
2429 u8 *data = font->data;
2432 font->width = vc->vc_font.width;
2433 font->height = vc->vc_font.height;
2434 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2438 if (font->width <= 8) {
2439 j = vc->vc_font.height;
2440 for (i = 0; i < font->charcount; i++) {
2441 memcpy(data, fontdata, j);
2442 memset(data + j, 0, 32 - j);
2446 } else if (font->width <= 16) {
2447 j = vc->vc_font.height * 2;
2448 for (i = 0; i < font->charcount; i++) {
2449 memcpy(data, fontdata, j);
2450 memset(data + j, 0, 64 - j);
2454 } else if (font->width <= 24) {
2455 for (i = 0; i < font->charcount; i++) {
2456 for (j = 0; j < vc->vc_font.height; j++) {
2457 *data++ = fontdata[0];
2458 *data++ = fontdata[1];
2459 *data++ = fontdata[2];
2460 fontdata += sizeof(u32);
2462 memset(data, 0, 3 * (32 - j));
2463 data += 3 * (32 - j);
2466 j = vc->vc_font.height * 4;
2467 for (i = 0; i < font->charcount; i++) {
2468 memcpy(data, fontdata, j);
2469 memset(data + j, 0, 128 - j);
2477 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2478 static void set_vc_hi_font(struct vc_data *vc, bool set)
2481 vc->vc_hi_font_mask = 0;
2482 if (vc->vc_can_do_color) {
2483 vc->vc_complement_mask >>= 1;
2484 vc->vc_s_complement_mask >>= 1;
2487 /* ++Edmund: reorder the attribute bits */
2488 if (vc->vc_can_do_color) {
2489 unsigned short *cp =
2490 (unsigned short *) vc->vc_origin;
2491 int count = vc->vc_screenbuf_size / 2;
2493 for (; count > 0; count--, cp++) {
2495 scr_writew(((c & 0xfe00) >> 1) |
2498 c = vc->vc_video_erase_char;
2499 vc->vc_video_erase_char =
2500 ((c & 0xfe00) >> 1) | (c & 0xff);
2504 vc->vc_hi_font_mask = 0x100;
2505 if (vc->vc_can_do_color) {
2506 vc->vc_complement_mask <<= 1;
2507 vc->vc_s_complement_mask <<= 1;
2510 /* ++Edmund: reorder the attribute bits */
2512 unsigned short *cp =
2513 (unsigned short *) vc->vc_origin;
2514 int count = vc->vc_screenbuf_size / 2;
2516 for (; count > 0; count--, cp++) {
2517 unsigned short newc;
2519 if (vc->vc_can_do_color)
2521 ((c & 0xff00) << 1) | (c &
2525 scr_writew(newc, cp);
2527 c = vc->vc_video_erase_char;
2528 if (vc->vc_can_do_color) {
2529 vc->vc_video_erase_char =
2530 ((c & 0xff00) << 1) | (c & 0xff);
2533 vc->vc_video_erase_char = c & ~0x100;
2538 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2539 const u8 * data, int userfont)
2541 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2542 struct fbcon_ops *ops = info->fbcon_par;
2543 struct display *p = &fb_display[vc->vc_num];
2546 char *old_data = NULL;
2548 if (con_is_visible(vc) && softback_lines)
2549 fbcon_set_origin(vc);
2551 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2553 old_data = vc->vc_font.data;
2555 cnt = FNTCHARCNT(data);
2558 vc->vc_font.data = (void *)(p->fontdata = data);
2559 if ((p->userfont = userfont))
2561 vc->vc_font.width = w;
2562 vc->vc_font.height = h;
2563 if (vc->vc_hi_font_mask && cnt == 256)
2564 set_vc_hi_font(vc, false);
2565 else if (!vc->vc_hi_font_mask && cnt == 512)
2566 set_vc_hi_font(vc, true);
2571 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2572 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2575 vc_resize(vc, cols, rows);
2576 if (con_is_visible(vc) && softback_buf)
2577 fbcon_update_softback(vc);
2578 } else if (con_is_visible(vc)
2579 && vc->vc_mode == KD_TEXT) {
2580 fbcon_clear_margins(vc, 0);
2584 if (old_data && (--REFCOUNT(old_data) == 0))
2585 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2589 static int fbcon_copy_font(struct vc_data *vc, int con)
2591 struct display *od = &fb_display[con];
2592 struct console_font *f = &vc->vc_font;
2594 if (od->fontdata == f->data)
2595 return 0; /* already the same font... */
2596 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2600 * User asked to set font; we are guaranteed that
2601 * a) width and height are in range 1..32
2602 * b) charcount does not exceed 512
2603 * but lets not assume that, since someone might someday want to use larger
2604 * fonts. And charcount of 512 is small for unicode support.
2606 * However, user space gives the font in 32 rows , regardless of
2607 * actual font height. So a new API is needed if support for larger fonts
2608 * is ever implemented.
2611 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2614 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2615 unsigned charcount = font->charcount;
2616 int w = font->width;
2617 int h = font->height;
2620 u8 *new_data, *data = font->data;
2621 int pitch = (font->width+7) >> 3;
2623 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2624 * If not this check should be changed to charcount < 256 */
2625 if (charcount != 256 && charcount != 512)
2628 /* Make sure drawing engine can handle the font */
2629 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2630 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2633 /* Make sure driver can handle the font length */
2634 if (fbcon_invalid_charcount(info, charcount))
2637 size = h * pitch * charcount;
2639 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2644 new_data += FONT_EXTRA_WORDS * sizeof(int);
2645 FNTSIZE(new_data) = size;
2646 FNTCHARCNT(new_data) = charcount;
2647 REFCOUNT(new_data) = 0; /* usage counter */
2648 for (i=0; i< charcount; i++) {
2649 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2652 /* Since linux has a nice crc32 function use it for counting font
2654 csum = crc32(0, new_data, size);
2656 FNTSUM(new_data) = csum;
2657 /* Check if the same font is on some other console already */
2658 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2659 struct vc_data *tmp = vc_cons[i].d;
2661 if (fb_display[i].userfont &&
2662 fb_display[i].fontdata &&
2663 FNTSUM(fb_display[i].fontdata) == csum &&
2664 FNTSIZE(fb_display[i].fontdata) == size &&
2665 tmp->vc_font.width == w &&
2666 !memcmp(fb_display[i].fontdata, new_data, size)) {
2667 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2668 new_data = (u8 *)fb_display[i].fontdata;
2672 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2675 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2677 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2678 const struct font_desc *f;
2681 f = get_default_font(info->var.xres, info->var.yres,
2682 info->pixmap.blit_x, info->pixmap.blit_y);
2683 else if (!(f = find_font(name)))
2686 font->width = f->width;
2687 font->height = f->height;
2688 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2691 static u16 palette_red[16];
2692 static u16 palette_green[16];
2693 static u16 palette_blue[16];
2695 static struct fb_cmap palette_cmap = {
2696 0, 16, palette_red, palette_green, palette_blue, NULL
2699 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2701 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2705 if (fbcon_is_inactive(vc, info))
2708 if (!con_is_visible(vc))
2711 depth = fb_get_color_depth(&info->var, &info->fix);
2713 for (i = j = 0; i < 16; i++) {
2715 val = vc->vc_palette[j++];
2716 palette_red[k] = (val << 8) | val;
2717 val = vc->vc_palette[j++];
2718 palette_green[k] = (val << 8) | val;
2719 val = vc->vc_palette[j++];
2720 palette_blue[k] = (val << 8) | val;
2722 palette_cmap.len = 16;
2723 palette_cmap.start = 0;
2725 * If framebuffer is capable of less than 16 colors,
2726 * use default palette of fbcon.
2729 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2731 fb_set_cmap(&palette_cmap, info);
2734 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2739 if (vc->vc_num != fg_console || !softback_lines)
2740 return (u16 *) (vc->vc_origin + offset);
2741 line = offset / vc->vc_size_row;
2742 if (line >= softback_lines)
2743 return (u16 *) (vc->vc_origin + offset -
2744 softback_lines * vc->vc_size_row);
2745 p = softback_curr + offset;
2746 if (p >= softback_end)
2747 p += softback_buf - softback_end;
2751 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2757 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2758 unsigned long offset = (pos - vc->vc_origin) / 2;
2760 x = offset % vc->vc_cols;
2761 y = offset / vc->vc_cols;
2762 if (vc->vc_num == fg_console)
2763 y += softback_lines;
2764 ret = pos + (vc->vc_cols - x) * 2;
2765 } else if (vc->vc_num == fg_console && softback_lines) {
2766 unsigned long offset = pos - softback_curr;
2768 if (pos < softback_curr)
2769 offset += softback_end - softback_buf;
2771 x = offset % vc->vc_cols;
2772 y = offset / vc->vc_cols;
2773 ret = pos + (vc->vc_cols - x) * 2;
2774 if (ret == softback_end)
2776 if (ret == softback_in)
2777 ret = vc->vc_origin;
2779 /* Should not happen */
2781 ret = vc->vc_origin;
2790 /* As we might be inside of softback, we may work with non-contiguous buffer,
2791 that's why we have to use a separate routine. */
2792 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2795 u16 a = scr_readw(p);
2796 if (!vc->vc_can_do_color)
2798 else if (vc->vc_hi_font_mask == 0x100)
2799 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2800 (((a) & 0x0e00) << 4);
2802 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2803 (((a) & 0x0700) << 4);
2805 if (p == (u16 *) softback_end)
2806 p = (u16 *) softback_buf;
2807 if (p == (u16 *) softback_in)
2808 p = (u16 *) vc->vc_origin;
2812 static void fbcon_scrolldelta(struct vc_data *vc, int lines)
2814 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2815 struct fbcon_ops *ops = info->fbcon_par;
2816 struct display *disp = &fb_display[fg_console];
2817 int offset, limit, scrollback_old;
2820 if (vc->vc_num != fg_console)
2822 if (vc->vc_mode != KD_TEXT || !lines)
2824 if (logo_shown >= 0) {
2825 struct vc_data *conp2 = vc_cons[logo_shown].d;
2827 if (conp2->vc_top == logo_lines
2828 && conp2->vc_bottom == conp2->vc_rows)
2830 if (logo_shown == vc->vc_num) {
2836 logo_lines * vc->vc_size_row;
2837 for (i = 0; i < logo_lines; i++) {
2838 if (p == softback_top)
2840 if (p == softback_buf)
2842 p -= vc->vc_size_row;
2843 q -= vc->vc_size_row;
2844 scr_memcpyw((u16 *) q, (u16 *) p,
2847 softback_in = softback_curr = p;
2848 update_region(vc, vc->vc_origin,
2849 logo_lines * vc->vc_cols);
2851 logo_shown = FBCON_LOGO_CANSHOW;
2853 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2854 fbcon_redraw_softback(vc, disp, lines);
2855 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2859 if (!scrollback_phys_max)
2862 scrollback_old = scrollback_current;
2863 scrollback_current -= lines;
2864 if (scrollback_current < 0)
2865 scrollback_current = 0;
2866 else if (scrollback_current > scrollback_max)
2867 scrollback_current = scrollback_max;
2868 if (scrollback_current == scrollback_old)
2871 if (fbcon_is_inactive(vc, info))
2874 fbcon_cursor(vc, CM_ERASE);
2876 offset = disp->yscroll - scrollback_current;
2877 limit = disp->vrows;
2878 switch (disp->scrollmode) {
2879 case SCROLL_WRAP_MOVE:
2880 info->var.vmode |= FB_VMODE_YWRAP;
2882 case SCROLL_PAN_MOVE:
2883 case SCROLL_PAN_REDRAW:
2884 limit -= vc->vc_rows;
2885 info->var.vmode &= ~FB_VMODE_YWRAP;
2890 else if (offset >= limit)
2893 ops->var.xoffset = 0;
2894 ops->var.yoffset = offset * vc->vc_font.height;
2895 ops->update_start(info);
2897 if (!scrollback_current)
2898 fbcon_cursor(vc, CM_DRAW);
2901 static int fbcon_set_origin(struct vc_data *vc)
2904 fbcon_scrolldelta(vc, softback_lines);
2908 static void fbcon_suspended(struct fb_info *info)
2910 struct vc_data *vc = NULL;
2911 struct fbcon_ops *ops = info->fbcon_par;
2913 if (!ops || ops->currcon < 0)
2915 vc = vc_cons[ops->currcon].d;
2917 /* Clear cursor, restore saved data */
2918 fbcon_cursor(vc, CM_ERASE);
2921 static void fbcon_resumed(struct fb_info *info)
2924 struct fbcon_ops *ops = info->fbcon_par;
2926 if (!ops || ops->currcon < 0)
2928 vc = vc_cons[ops->currcon].d;
2933 static void fbcon_modechanged(struct fb_info *info)
2935 struct fbcon_ops *ops = info->fbcon_par;
2940 if (!ops || ops->currcon < 0)
2942 vc = vc_cons[ops->currcon].d;
2943 if (vc->vc_mode != KD_TEXT ||
2944 registered_fb[con2fb_map[ops->currcon]] != info)
2947 p = &fb_display[vc->vc_num];
2948 set_blitting_type(vc, info);
2950 if (con_is_visible(vc)) {
2951 var_to_display(p, &info->var, info);
2952 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2953 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2954 cols /= vc->vc_font.width;
2955 rows /= vc->vc_font.height;
2956 vc_resize(vc, cols, rows);
2957 updatescrollmode(p, info, vc);
2959 scrollback_current = 0;
2961 if (!fbcon_is_inactive(vc, info)) {
2962 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2963 ops->update_start(info);
2966 fbcon_set_palette(vc, color_table);
2969 fbcon_update_softback(vc);
2973 static void fbcon_set_all_vcs(struct fb_info *info)
2975 struct fbcon_ops *ops = info->fbcon_par;
2978 int i, rows, cols, fg = -1;
2980 if (!ops || ops->currcon < 0)
2983 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2985 if (!vc || vc->vc_mode != KD_TEXT ||
2986 registered_fb[con2fb_map[i]] != info)
2989 if (con_is_visible(vc)) {
2994 p = &fb_display[vc->vc_num];
2995 set_blitting_type(vc, info);
2996 var_to_display(p, &info->var, info);
2997 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2998 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2999 cols /= vc->vc_font.width;
3000 rows /= vc->vc_font.height;
3001 vc_resize(vc, cols, rows);
3005 fbcon_modechanged(info);
3008 static int fbcon_mode_deleted(struct fb_info *info,
3009 struct fb_videomode *mode)
3011 struct fb_info *fb_info;
3013 int i, j, found = 0;
3015 /* before deletion, ensure that mode is not in use */
3016 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3020 fb_info = registered_fb[j];
3021 if (fb_info != info)
3026 if (fb_mode_is_equal(p->mode, mode)) {
3034 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3035 static int fbcon_unbind(void)
3039 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3043 fbcon_has_console_bind = 0;
3048 static inline int fbcon_unbind(void)
3052 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3054 /* called with console_lock held */
3055 static int fbcon_fb_unbind(int idx)
3057 int i, new_idx = -1, ret = 0;
3059 WARN_CONSOLE_UNLOCKED();
3061 if (!fbcon_has_console_bind)
3064 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3065 if (con2fb_map[i] != idx &&
3066 con2fb_map[i] != -1) {
3072 if (new_idx != -1) {
3073 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3074 if (con2fb_map[i] == idx)
3075 set_con2fb_map(i, new_idx, 0);
3078 struct fb_info *info = registered_fb[idx];
3080 /* This is sort of like set_con2fb_map, except it maps
3081 * the consoles to no device and then releases the
3082 * oldinfo to free memory and cancel the cursor blink
3083 * timer. I can imagine this just becoming part of
3084 * set_con2fb_map where new_idx is -1
3086 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3087 if (con2fb_map[i] == idx) {
3089 if (!search_fb_in_map(idx)) {
3090 ret = con2fb_release_oldinfo(vc_cons[i].d,
3094 con2fb_map[i] = idx;
3100 ret = fbcon_unbind();
3106 /* called with console_lock held */
3107 static int fbcon_fb_unregistered(struct fb_info *info)
3111 WARN_CONSOLE_UNLOCKED();
3113 if (deferred_takeover)
3117 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3118 if (con2fb_map[i] == idx)
3122 if (idx == info_idx) {
3125 for_each_registered_fb(i) {
3131 if (info_idx != -1) {
3132 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3133 if (con2fb_map[i] == -1)
3134 con2fb_map[i] = info_idx;
3138 if (primary_device == idx)
3139 primary_device = -1;
3141 if (!num_registered_fb)
3142 do_unregister_con_driver(&fb_con);
3147 /* called with console_lock held */
3148 static void fbcon_remap_all(int idx)
3152 WARN_CONSOLE_UNLOCKED();
3154 if (deferred_takeover) {
3155 for (i = first_fb_vc; i <= last_fb_vc; i++)
3156 con2fb_map_boot[i] = idx;
3157 fbcon_map_override();
3161 for (i = first_fb_vc; i <= last_fb_vc; i++)
3162 set_con2fb_map(i, idx, 0);
3164 if (con_is_bound(&fb_con)) {
3165 printk(KERN_INFO "fbcon: Remapping primary device, "
3166 "fb%i, to tty %i-%i\n", idx,
3167 first_fb_vc + 1, last_fb_vc + 1);
3172 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3173 static void fbcon_select_primary(struct fb_info *info)
3175 if (!map_override && primary_device == -1 &&
3176 fb_is_primary_device(info)) {
3179 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3180 info->fix.id, info->node);
3181 primary_device = info->node;
3183 for (i = first_fb_vc; i <= last_fb_vc; i++)
3184 con2fb_map_boot[i] = primary_device;
3186 if (con_is_bound(&fb_con)) {
3187 printk(KERN_INFO "fbcon: Remapping primary device, "
3188 "fb%i, to tty %i-%i\n", info->node,
3189 first_fb_vc + 1, last_fb_vc + 1);
3190 info_idx = primary_device;
3196 static inline void fbcon_select_primary(struct fb_info *info)
3200 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3202 /* called with console_lock held */
3203 static int fbcon_fb_registered(struct fb_info *info)
3205 int ret = 0, i, idx;
3207 WARN_CONSOLE_UNLOCKED();
3210 fbcon_select_primary(info);
3212 if (deferred_takeover) {
3213 pr_info("fbcon: Deferring console take-over\n");
3217 if (info_idx == -1) {
3218 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3219 if (con2fb_map_boot[i] == idx) {
3226 ret = do_fbcon_takeover(1);
3228 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3229 if (con2fb_map_boot[i] == idx)
3230 set_con2fb_map(i, idx, 0);
3237 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3239 struct fbcon_ops *ops = info->fbcon_par;
3242 if (!ops || ops->currcon < 0)
3245 vc = vc_cons[ops->currcon].d;
3246 if (vc->vc_mode != KD_TEXT ||
3247 registered_fb[con2fb_map[ops->currcon]] != info)
3250 if (con_is_visible(vc)) {
3254 do_unblank_screen(0);
3256 ops->blank_state = blank;
3259 static void fbcon_new_modelist(struct fb_info *info)
3263 struct fb_var_screeninfo var;
3264 const struct fb_videomode *mode;
3266 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3267 if (registered_fb[con2fb_map[i]] != info)
3269 if (!fb_display[i].mode)
3272 display_to_var(&var, &fb_display[i]);
3273 mode = fb_find_nearest_mode(fb_display[i].mode,
3275 fb_videomode_to_var(&var, mode);
3276 fbcon_set_disp(info, &var, vc->vc_num);
3280 static void fbcon_get_requirement(struct fb_info *info,
3281 struct fb_blit_caps *caps)
3289 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3291 if (vc && vc->vc_mode == KD_TEXT &&
3292 info->node == con2fb_map[i]) {
3294 caps->x |= 1 << (vc->vc_font.width - 1);
3295 caps->y |= 1 << (vc->vc_font.height - 1);
3296 charcnt = (p->userfont) ?
3297 FNTCHARCNT(p->fontdata) : 256;
3298 if (caps->len < charcnt)
3299 caps->len = charcnt;
3303 vc = vc_cons[fg_console].d;
3305 if (vc && vc->vc_mode == KD_TEXT &&
3306 info->node == con2fb_map[fg_console]) {
3307 p = &fb_display[fg_console];
3308 caps->x = 1 << (vc->vc_font.width - 1);
3309 caps->y = 1 << (vc->vc_font.height - 1);
3310 caps->len = (p->userfont) ?
3311 FNTCHARCNT(p->fontdata) : 256;
3316 static int fbcon_event_notify(struct notifier_block *self,
3317 unsigned long action, void *data)
3319 struct fb_event *event = data;
3320 struct fb_info *info = event->info;
3321 struct fb_videomode *mode;
3322 struct fb_con2fbmap *con2fb;
3323 struct fb_blit_caps *caps;
3327 * ignore all events except driver registration and deregistration
3328 * if fbcon is not active
3330 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3331 action == FB_EVENT_FB_UNREGISTERED))
3335 case FB_EVENT_SUSPEND:
3336 fbcon_suspended(info);
3338 case FB_EVENT_RESUME:
3339 fbcon_resumed(info);
3341 case FB_EVENT_MODE_CHANGE:
3342 fbcon_modechanged(info);
3344 case FB_EVENT_MODE_CHANGE_ALL:
3345 fbcon_set_all_vcs(info);
3347 case FB_EVENT_MODE_DELETE:
3349 ret = fbcon_mode_deleted(info, mode);
3351 case FB_EVENT_FB_UNBIND:
3353 ret = fbcon_fb_unbind(idx);
3355 case FB_EVENT_FB_REGISTERED:
3356 ret = fbcon_fb_registered(info);
3358 case FB_EVENT_FB_UNREGISTERED:
3359 ret = fbcon_fb_unregistered(info);
3361 case FB_EVENT_SET_CONSOLE_MAP:
3362 /* called with console lock held */
3363 con2fb = event->data;
3364 ret = set_con2fb_map(con2fb->console - 1,
3365 con2fb->framebuffer, 1);
3367 case FB_EVENT_GET_CONSOLE_MAP:
3368 con2fb = event->data;
3369 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3371 case FB_EVENT_BLANK:
3372 fbcon_fb_blanked(info, *(int *)event->data);
3374 case FB_EVENT_NEW_MODELIST:
3375 fbcon_new_modelist(info);
3377 case FB_EVENT_GET_REQ:
3379 fbcon_get_requirement(info, caps);
3381 case FB_EVENT_REMAP_ALL_CONSOLE:
3383 fbcon_remap_all(idx);
3391 * The console `switch' structure for the frame buffer based console
3394 static const struct consw fb_con = {
3395 .owner = THIS_MODULE,
3396 .con_startup = fbcon_startup,
3397 .con_init = fbcon_init,
3398 .con_deinit = fbcon_deinit,
3399 .con_clear = fbcon_clear,
3400 .con_putc = fbcon_putc,
3401 .con_putcs = fbcon_putcs,
3402 .con_cursor = fbcon_cursor,
3403 .con_scroll = fbcon_scroll,
3404 .con_switch = fbcon_switch,
3405 .con_blank = fbcon_blank,
3406 .con_font_set = fbcon_set_font,
3407 .con_font_get = fbcon_get_font,
3408 .con_font_default = fbcon_set_def_font,
3409 .con_font_copy = fbcon_copy_font,
3410 .con_set_palette = fbcon_set_palette,
3411 .con_scrolldelta = fbcon_scrolldelta,
3412 .con_set_origin = fbcon_set_origin,
3413 .con_invert_region = fbcon_invert_region,
3414 .con_screen_pos = fbcon_screen_pos,
3415 .con_getxy = fbcon_getxy,
3416 .con_resize = fbcon_resize,
3417 .con_debug_enter = fbcon_debug_enter,
3418 .con_debug_leave = fbcon_debug_leave,
3421 static struct notifier_block fbcon_event_notifier = {
3422 .notifier_call = fbcon_event_notify,
3425 static ssize_t store_rotate(struct device *device,
3426 struct device_attribute *attr, const char *buf,
3429 struct fb_info *info;
3433 if (fbcon_has_exited)
3437 idx = con2fb_map[fg_console];
3439 if (idx == -1 || registered_fb[idx] == NULL)
3442 info = registered_fb[idx];
3443 rotate = simple_strtoul(buf, last, 0);
3444 fbcon_rotate(info, rotate);
3450 static ssize_t store_rotate_all(struct device *device,
3451 struct device_attribute *attr,const char *buf,
3454 struct fb_info *info;
3458 if (fbcon_has_exited)
3462 idx = con2fb_map[fg_console];
3464 if (idx == -1 || registered_fb[idx] == NULL)
3467 info = registered_fb[idx];
3468 rotate = simple_strtoul(buf, last, 0);
3469 fbcon_rotate_all(info, rotate);
3475 static ssize_t show_rotate(struct device *device,
3476 struct device_attribute *attr,char *buf)
3478 struct fb_info *info;
3479 int rotate = 0, idx;
3481 if (fbcon_has_exited)
3485 idx = con2fb_map[fg_console];
3487 if (idx == -1 || registered_fb[idx] == NULL)
3490 info = registered_fb[idx];
3491 rotate = fbcon_get_rotate(info);
3494 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3497 static ssize_t show_cursor_blink(struct device *device,
3498 struct device_attribute *attr, char *buf)
3500 struct fb_info *info;
3501 struct fbcon_ops *ops;
3502 int idx, blink = -1;
3504 if (fbcon_has_exited)
3508 idx = con2fb_map[fg_console];
3510 if (idx == -1 || registered_fb[idx] == NULL)
3513 info = registered_fb[idx];
3514 ops = info->fbcon_par;
3519 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3522 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3525 static ssize_t store_cursor_blink(struct device *device,
3526 struct device_attribute *attr,
3527 const char *buf, size_t count)
3529 struct fb_info *info;
3533 if (fbcon_has_exited)
3537 idx = con2fb_map[fg_console];
3539 if (idx == -1 || registered_fb[idx] == NULL)
3542 info = registered_fb[idx];
3544 if (!info->fbcon_par)
3547 blink = simple_strtoul(buf, last, 0);
3550 fbcon_cursor_noblink = 0;
3551 fbcon_add_cursor_timer(info);
3553 fbcon_cursor_noblink = 1;
3554 fbcon_del_cursor_timer(info);
3562 static struct device_attribute device_attrs[] = {
3563 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3564 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3565 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3566 store_cursor_blink),
3569 static int fbcon_init_device(void)
3573 fbcon_has_sysfs = 1;
3575 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3576 error = device_create_file(fbcon_device, &device_attrs[i]);
3584 device_remove_file(fbcon_device, &device_attrs[i]);
3586 fbcon_has_sysfs = 0;
3592 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3593 static void fbcon_register_existing_fbs(struct work_struct *work)
3599 for_each_registered_fb(i)
3600 fbcon_fb_registered(registered_fb[i]);
3605 static struct notifier_block fbcon_output_nb;
3606 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3608 static int fbcon_output_notifier(struct notifier_block *nb,
3609 unsigned long action, void *data)
3611 WARN_CONSOLE_UNLOCKED();
3613 pr_info("fbcon: Taking over console\n");
3615 dummycon_unregister_output_notifier(&fbcon_output_nb);
3616 deferred_takeover = false;
3617 logo_shown = FBCON_LOGO_DONTSHOW;
3619 /* We may get called in atomic context */
3620 schedule_work(&fbcon_deferred_takeover_work);
3626 static void fbcon_start(void)
3628 WARN_CONSOLE_UNLOCKED();
3630 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3631 if (conswitchp != &dummy_con)
3632 deferred_takeover = false;
3634 if (deferred_takeover) {
3635 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3636 dummycon_register_output_notifier(&fbcon_output_nb);
3641 if (num_registered_fb) {
3644 for_each_registered_fb(i) {
3649 do_fbcon_takeover(0);
3653 static void fbcon_exit(void)
3655 struct fb_info *info;
3658 if (fbcon_has_exited)
3661 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3662 if (deferred_takeover) {
3663 dummycon_unregister_output_notifier(&fbcon_output_nb);
3664 deferred_takeover = false;
3668 kfree((void *)softback_buf);
3671 for_each_registered_fb(i) {
3675 info = registered_fb[i];
3677 if (info->queue.func)
3678 pending = cancel_work_sync(&info->queue);
3679 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3682 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3683 if (con2fb_map[j] == i) {
3690 if (info->fbops->fb_release)
3691 info->fbops->fb_release(info, 0);
3692 module_put(info->fbops->owner);
3694 if (info->fbcon_par) {
3695 struct fbcon_ops *ops = info->fbcon_par;
3697 fbcon_del_cursor_timer(info);
3698 kfree(ops->cursor_src);
3699 kfree(ops->cursor_state.mask);
3700 kfree(info->fbcon_par);
3701 info->fbcon_par = NULL;
3704 if (info->queue.func == fb_flashcursor)
3705 info->queue.func = NULL;
3709 fbcon_has_exited = 1;
3712 void __init fb_console_init(void)
3717 fb_register_client(&fbcon_event_notifier);
3718 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3721 if (IS_ERR(fbcon_device)) {
3722 printk(KERN_WARNING "Unable to create device "
3723 "for fbcon; errno = %ld\n",
3724 PTR_ERR(fbcon_device));
3725 fbcon_device = NULL;
3727 fbcon_init_device();
3729 for (i = 0; i < MAX_NR_CONSOLES; i++)
3738 static void __exit fbcon_deinit_device(void)
3742 if (fbcon_has_sysfs) {
3743 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3744 device_remove_file(fbcon_device, &device_attrs[i]);
3746 fbcon_has_sysfs = 0;
3750 void __exit fb_console_exit(void)
3753 fb_unregister_client(&fbcon_event_notifier);
3754 fbcon_deinit_device();
3755 device_destroy(fb_class, MKDEV(0, 0));
3757 do_unregister_con_driver(&fb_con);