2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
96 static struct display fb_display[MAX_NR_CONSOLES];
98 static signed char con2fb_map[MAX_NR_CONSOLES];
99 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
101 static int logo_lines;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown = FBCON_LOGO_CANSHOW;
105 /* Software scrollback */
106 static int fbcon_softback_size = 32768;
107 static unsigned long softback_buf, softback_curr;
108 static unsigned long softback_in;
109 static unsigned long softback_top, softback_end;
110 static int softback_lines;
111 /* console mappings */
112 static int first_fb_vc;
113 static int last_fb_vc = MAX_NR_CONSOLES - 1;
114 static int fbcon_is_default = 1;
115 static int fbcon_has_exited;
116 static int primary_device = -1;
117 static int fbcon_has_console_bind;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override;
122 static inline void fbcon_map_override(void)
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
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;
514 if (!strncmp(options, "logo-pos:", 9)) {
516 if (!strcmp(options, "center"))
517 fb_center_logo = true;
524 __setup("fbcon=", fb_console_setup);
527 static int search_fb_in_map(int idx)
531 for (i = first_fb_vc; i <= last_fb_vc; i++) {
532 if (con2fb_map[i] == idx)
538 static int search_for_mapped_con(void)
542 for (i = first_fb_vc; i <= last_fb_vc; i++) {
543 if (con2fb_map[i] != -1)
549 static int do_fbcon_takeover(int show_logo)
553 if (!num_registered_fb)
557 logo_shown = FBCON_LOGO_DONTSHOW;
559 for (i = first_fb_vc; i <= last_fb_vc; i++)
560 con2fb_map[i] = info_idx;
562 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
566 for (i = first_fb_vc; i <= last_fb_vc; i++)
570 fbcon_has_console_bind = 1;
577 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
578 int cols, int rows, int new_cols, int new_rows)
580 logo_shown = FBCON_LOGO_DONTSHOW;
583 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
584 int cols, int rows, int new_cols, int new_rows)
586 /* Need to make room for the logo */
587 struct fbcon_ops *ops = info->fbcon_par;
588 int cnt, erase = vc->vc_video_erase_char, step;
589 unsigned short *save = NULL, *r, *q;
592 if (info->fbops->owner) {
593 logo_shown = FBCON_LOGO_DONTSHOW;
598 * remove underline attribute from erase character
599 * if black and white framebuffer.
601 if (fb_get_color_depth(&info->var, &info->fix) == 1)
603 logo_height = fb_prepare_logo(info, ops->rotate);
604 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
605 q = (unsigned short *) (vc->vc_origin +
606 vc->vc_size_row * rows);
607 step = logo_lines * cols;
608 for (r = q - logo_lines * cols; r < q; r++)
609 if (scr_readw(r) != vc->vc_video_erase_char)
611 if (r != q && new_rows >= rows + logo_lines) {
612 save = kmalloc(array3_size(logo_lines, new_cols, 2),
615 int i = cols < new_cols ? cols : new_cols;
616 scr_memsetw(save, erase, logo_lines * new_cols * 2);
618 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
619 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
624 /* We can scroll screen down */
626 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
627 scr_memcpyw(r + step, r, vc->vc_size_row);
632 if (vc->vc_y + logo_lines >= rows)
633 lines = rows - vc->vc_y - 1;
637 vc->vc_pos += lines * vc->vc_size_row;
640 scr_memsetw((unsigned short *) vc->vc_origin,
642 vc->vc_size_row * logo_lines);
644 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
645 fbcon_clear_margins(vc, 0);
650 q = (unsigned short *) (vc->vc_origin +
653 scr_memcpyw(q, save, logo_lines * new_cols * 2);
654 vc->vc_y += logo_lines;
655 vc->vc_pos += logo_lines * vc->vc_size_row;
659 if (logo_lines > vc->vc_bottom) {
660 logo_shown = FBCON_LOGO_CANSHOW;
662 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
663 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
664 logo_shown = FBCON_LOGO_DRAW;
665 vc->vc_top = logo_lines;
670 #ifdef CONFIG_FB_TILEBLITTING
671 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
673 struct fbcon_ops *ops = info->fbcon_par;
675 ops->p = &fb_display[vc->vc_num];
677 if ((info->flags & FBINFO_MISC_TILEBLITTING))
678 fbcon_set_tileops(vc, info);
680 fbcon_set_rotation(info);
681 fbcon_set_bitops(ops);
685 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
689 if (info->flags & FBINFO_MISC_TILEBLITTING &&
690 info->tileops->fb_get_tilemax(info) < charcount)
696 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
698 struct fbcon_ops *ops = info->fbcon_par;
700 info->flags &= ~FBINFO_MISC_TILEBLITTING;
701 ops->p = &fb_display[vc->vc_num];
702 fbcon_set_rotation(info);
703 fbcon_set_bitops(ops);
706 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
711 #endif /* CONFIG_MISC_TILEBLITTING */
714 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
715 int unit, int oldidx)
717 struct fbcon_ops *ops = NULL;
720 if (!try_module_get(info->fbops->owner))
723 if (!err && info->fbops->fb_open &&
724 info->fbops->fb_open(info, 0))
728 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
734 ops->cur_blink_jiffies = HZ / 5;
736 info->fbcon_par = ops;
739 set_blitting_type(vc, info);
743 con2fb_map[unit] = oldidx;
744 module_put(info->fbops->owner);
750 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
751 struct fb_info *newinfo, int unit,
752 int oldidx, int found)
754 struct fbcon_ops *ops = oldinfo->fbcon_par;
757 if (oldinfo->fbops->fb_release &&
758 oldinfo->fbops->fb_release(oldinfo, 0)) {
759 con2fb_map[unit] = oldidx;
760 if (!found && newinfo->fbops->fb_release)
761 newinfo->fbops->fb_release(newinfo, 0);
763 module_put(newinfo->fbops->owner);
768 fbcon_del_cursor_timer(oldinfo);
769 kfree(ops->cursor_state.mask);
770 kfree(ops->cursor_data);
771 kfree(ops->cursor_src);
772 kfree(ops->fontbuffer);
773 kfree(oldinfo->fbcon_par);
774 oldinfo->fbcon_par = NULL;
775 module_put(oldinfo->fbops->owner);
777 If oldinfo and newinfo are driving the same hardware,
778 the fb_release() method of oldinfo may attempt to
779 restore the hardware state. This will leave the
780 newinfo in an undefined state. Thus, a call to
781 fb_set_par() may be needed for the newinfo.
783 if (newinfo && newinfo->fbops->fb_set_par) {
784 ret = newinfo->fbops->fb_set_par(newinfo);
787 printk(KERN_ERR "con2fb_release_oldinfo: "
788 "detected unhandled fb_set_par error, "
789 "error code %d\n", ret);
796 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
797 int unit, int show_logo)
799 struct fbcon_ops *ops = info->fbcon_par;
802 ops->currcon = fg_console;
804 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
805 ret = info->fbops->fb_set_par(info);
808 printk(KERN_ERR "con2fb_init_display: detected "
809 "unhandled fb_set_par error, "
810 "error code %d\n", ret);
813 ops->flags |= FBCON_FLAGS_INIT;
815 fbcon_set_disp(info, &info->var, unit);
818 struct vc_data *fg_vc = vc_cons[fg_console].d;
819 struct fb_info *fg_info =
820 registered_fb[con2fb_map[fg_console]];
822 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
823 fg_vc->vc_rows, fg_vc->vc_cols,
827 update_screen(vc_cons[fg_console].d);
831 * set_con2fb_map - map console to frame buffer device
832 * @unit: virtual console number to map
833 * @newidx: frame buffer index to map virtual console to
834 * @user: user request
836 * Maps a virtual console @unit to a frame buffer device
839 * This should be called with the console lock held.
841 static int set_con2fb_map(int unit, int newidx, int user)
843 struct vc_data *vc = vc_cons[unit].d;
844 int oldidx = con2fb_map[unit];
845 struct fb_info *info = registered_fb[newidx];
846 struct fb_info *oldinfo = NULL;
849 WARN_CONSOLE_UNLOCKED();
851 if (oldidx == newidx)
857 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
859 return do_fbcon_takeover(0);
863 oldinfo = registered_fb[oldidx];
865 found = search_fb_in_map(newidx);
867 con2fb_map[unit] = newidx;
869 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
873 * If old fb is not mapped to any of the consoles,
874 * fbcon should release it.
876 if (!err && oldinfo && !search_fb_in_map(oldidx))
877 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
881 int show_logo = (fg_console == 0 && !user &&
882 logo_shown != FBCON_LOGO_DONTSHOW);
885 fbcon_add_cursor_timer(info);
886 con2fb_map_boot[unit] = newidx;
887 con2fb_init_display(vc, info, unit, show_logo);
890 if (!search_fb_in_map(info_idx))
897 * Low Level Operations
899 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
900 static int var_to_display(struct display *disp,
901 struct fb_var_screeninfo *var,
902 struct fb_info *info)
904 disp->xres_virtual = var->xres_virtual;
905 disp->yres_virtual = var->yres_virtual;
906 disp->bits_per_pixel = var->bits_per_pixel;
907 disp->grayscale = var->grayscale;
908 disp->nonstd = var->nonstd;
909 disp->accel_flags = var->accel_flags;
910 disp->height = var->height;
911 disp->width = var->width;
912 disp->red = var->red;
913 disp->green = var->green;
914 disp->blue = var->blue;
915 disp->transp = var->transp;
916 disp->rotate = var->rotate;
917 disp->mode = fb_match_mode(var, &info->modelist);
918 if (disp->mode == NULL)
919 /* This should not happen */
924 static void display_to_var(struct fb_var_screeninfo *var,
925 struct display *disp)
927 fb_videomode_to_var(var, disp->mode);
928 var->xres_virtual = disp->xres_virtual;
929 var->yres_virtual = disp->yres_virtual;
930 var->bits_per_pixel = disp->bits_per_pixel;
931 var->grayscale = disp->grayscale;
932 var->nonstd = disp->nonstd;
933 var->accel_flags = disp->accel_flags;
934 var->height = disp->height;
935 var->width = disp->width;
936 var->red = disp->red;
937 var->green = disp->green;
938 var->blue = disp->blue;
939 var->transp = disp->transp;
940 var->rotate = disp->rotate;
943 static const char *fbcon_startup(void)
945 const char *display_desc = "frame buffer device";
946 struct display *p = &fb_display[fg_console];
947 struct vc_data *vc = vc_cons[fg_console].d;
948 const struct font_desc *font = NULL;
949 struct module *owner;
950 struct fb_info *info = NULL;
951 struct fbcon_ops *ops;
955 * If num_registered_fb is zero, this is a call for the dummy part.
956 * The frame buffer devices weren't initialized yet.
958 if (!num_registered_fb || info_idx == -1)
961 * Instead of blindly using registered_fb[0], we use info_idx, set by
964 info = registered_fb[info_idx];
968 owner = info->fbops->owner;
969 if (!try_module_get(owner))
971 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
976 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
984 ops->cur_rotate = -1;
985 ops->cur_blink_jiffies = HZ / 5;
987 info->fbcon_par = ops;
989 p->con_rotate = initial_rotation;
990 if (p->con_rotate == -1)
991 p->con_rotate = info->fbcon_rotate_hint;
992 if (p->con_rotate == -1)
993 p->con_rotate = FB_ROTATE_UR;
995 set_blitting_type(vc, info);
997 if (info->fix.type != FB_TYPE_TEXT) {
998 if (fbcon_softback_size) {
1002 kmalloc(fbcon_softback_size,
1004 if (!softback_buf) {
1005 fbcon_softback_size = 0;
1011 kfree((void *) softback_buf);
1017 softback_in = softback_top = softback_curr =
1022 /* Setup default font */
1023 if (!p->fontdata && !vc->vc_font.data) {
1024 if (!fontname[0] || !(font = find_font(fontname)))
1025 font = get_default_font(info->var.xres,
1027 info->pixmap.blit_x,
1028 info->pixmap.blit_y);
1029 vc->vc_font.width = font->width;
1030 vc->vc_font.height = font->height;
1031 vc->vc_font.data = (void *)(p->fontdata = font->data);
1032 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1034 p->fontdata = vc->vc_font.data;
1037 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1038 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1039 cols /= vc->vc_font.width;
1040 rows /= vc->vc_font.height;
1041 vc_resize(vc, cols, rows);
1043 DPRINTK("mode: %s\n", info->fix.id);
1044 DPRINTK("visual: %d\n", info->fix.visual);
1045 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1047 info->var.bits_per_pixel);
1049 fbcon_add_cursor_timer(info);
1050 fbcon_has_exited = 0;
1051 return display_desc;
1054 static void fbcon_init(struct vc_data *vc, int init)
1056 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1057 struct fbcon_ops *ops;
1058 struct vc_data **default_mode = vc->vc_display_fg;
1059 struct vc_data *svc = *default_mode;
1060 struct display *t, *p = &fb_display[vc->vc_num];
1061 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1064 if (info_idx == -1 || info == NULL)
1069 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1070 (info->fix.type == FB_TYPE_TEXT))
1073 if (var_to_display(p, &info->var, info))
1076 if (!info->fbcon_par)
1077 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1079 /* If we are not the first console on this
1080 fb, copy the font from that console */
1081 t = &fb_display[fg_console];
1084 struct vc_data *fvc = vc_cons[fg_console].d;
1086 vc->vc_font.data = (void *)(p->fontdata =
1088 vc->vc_font.width = fvc->vc_font.width;
1089 vc->vc_font.height = fvc->vc_font.height;
1090 p->userfont = t->userfont;
1093 REFCOUNT(p->fontdata)++;
1095 const struct font_desc *font = NULL;
1097 if (!fontname[0] || !(font = find_font(fontname)))
1098 font = get_default_font(info->var.xres,
1100 info->pixmap.blit_x,
1101 info->pixmap.blit_y);
1102 vc->vc_font.width = font->width;
1103 vc->vc_font.height = font->height;
1104 vc->vc_font.data = (void *)(p->fontdata = font->data);
1105 vc->vc_font.charcount = 256; /* FIXME Need to
1106 support more fonts */
1111 charcnt = FNTCHARCNT(p->fontdata);
1113 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1114 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1115 if (charcnt == 256) {
1116 vc->vc_hi_font_mask = 0;
1118 vc->vc_hi_font_mask = 0x100;
1119 if (vc->vc_can_do_color)
1120 vc->vc_complement_mask <<= 1;
1123 if (!*svc->vc_uni_pagedir_loc)
1124 con_set_default_unimap(svc);
1125 if (!*vc->vc_uni_pagedir_loc)
1126 con_copy_unimap(vc, svc);
1128 ops = info->fbcon_par;
1129 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1131 p->con_rotate = initial_rotation;
1132 if (p->con_rotate == -1)
1133 p->con_rotate = info->fbcon_rotate_hint;
1134 if (p->con_rotate == -1)
1135 p->con_rotate = FB_ROTATE_UR;
1137 set_blitting_type(vc, info);
1141 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1142 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1143 new_cols /= vc->vc_font.width;
1144 new_rows /= vc->vc_font.height;
1147 * We must always set the mode. The mode of the previous console
1148 * driver could be in the same resolution but we are using different
1149 * hardware so we have to initialize the hardware.
1151 * We need to do it in fbcon_init() to prevent screen corruption.
1153 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1154 if (info->fbops->fb_set_par &&
1155 !(ops->flags & FBCON_FLAGS_INIT)) {
1156 ret = info->fbops->fb_set_par(info);
1159 printk(KERN_ERR "fbcon_init: detected "
1160 "unhandled fb_set_par error, "
1161 "error code %d\n", ret);
1164 ops->flags |= FBCON_FLAGS_INIT;
1169 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1170 !(cap & FBINFO_HWACCEL_DISABLED))
1171 p->scrollmode = SCROLL_MOVE;
1172 else /* default to something safe */
1173 p->scrollmode = SCROLL_REDRAW;
1176 * ++guenther: console.c:vc_allocate() relies on initializing
1177 * vc_{cols,rows}, but we must not set those if we are only
1178 * resizing the console.
1181 vc->vc_cols = new_cols;
1182 vc->vc_rows = new_rows;
1184 vc_resize(vc, new_cols, new_rows);
1187 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1189 if (vc == svc && softback_buf)
1190 fbcon_update_softback(vc);
1192 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1193 ops->rotate = FB_ROTATE_UR;
1194 set_blitting_type(vc, info);
1197 ops->p = &fb_display[fg_console];
1200 static void fbcon_free_font(struct display *p, bool freefont)
1202 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1203 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1208 static void set_vc_hi_font(struct vc_data *vc, bool set);
1210 static void fbcon_deinit(struct vc_data *vc)
1212 struct display *p = &fb_display[vc->vc_num];
1213 struct fb_info *info;
1214 struct fbcon_ops *ops;
1216 bool free_font = true;
1218 idx = con2fb_map[vc->vc_num];
1223 info = registered_fb[idx];
1228 if (info->flags & FBINFO_MISC_FIRMWARE)
1230 ops = info->fbcon_par;
1235 if (con_is_visible(vc))
1236 fbcon_del_cursor_timer(info);
1238 ops->flags &= ~FBCON_FLAGS_INIT;
1241 fbcon_free_font(p, free_font);
1243 vc->vc_font.data = NULL;
1245 if (vc->vc_hi_font_mask)
1246 set_vc_hi_font(vc, false);
1248 if (!con_is_bound(&fb_con))
1254 /* ====================================================================== */
1256 /* fbcon_XXX routines - interface used by the world
1258 * This system is now divided into two levels because of complications
1259 * caused by hardware scrolling. Top level functions:
1261 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1263 * handles y values in range [0, scr_height-1] that correspond to real
1264 * screen positions. y_wrap shift means that first line of bitmap may be
1265 * anywhere on this display. These functions convert lineoffsets to
1266 * bitmap offsets and deal with the wrap-around case by splitting blits.
1268 * fbcon_bmove_physical_8() -- These functions fast implementations
1269 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1270 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1274 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1275 * Implies should only really hardware scroll in rows. Only reason for
1276 * restriction is simplicity & efficiency at the moment.
1279 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1282 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1283 struct fbcon_ops *ops = info->fbcon_par;
1285 struct display *p = &fb_display[vc->vc_num];
1288 if (fbcon_is_inactive(vc, info))
1291 if (!height || !width)
1294 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1297 * If the font dimensions are not an integral of the display
1298 * dimensions then the ops->clear below won't end up clearing
1299 * the margins. Call clear_margins here in case the logo
1300 * bitmap stretched into the margin area.
1302 fbcon_clear_margins(vc, 0);
1305 /* Split blits that cross physical y_wrap boundary */
1307 y_break = p->vrows - p->yscroll;
1308 if (sy < y_break && sy + height - 1 >= y_break) {
1309 u_int b = y_break - sy;
1310 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1311 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1314 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1317 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1318 int count, int ypos, int xpos)
1320 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1321 struct display *p = &fb_display[vc->vc_num];
1322 struct fbcon_ops *ops = info->fbcon_par;
1324 if (!fbcon_is_inactive(vc, info))
1325 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1326 get_color(vc, info, scr_readw(s), 1),
1327 get_color(vc, info, scr_readw(s), 0));
1330 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1334 scr_writew(c, &chr);
1335 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1338 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1340 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1341 struct fbcon_ops *ops = info->fbcon_par;
1343 if (!fbcon_is_inactive(vc, info))
1344 ops->clear_margins(vc, info, margin_color, bottom_only);
1347 static void fbcon_cursor(struct vc_data *vc, int mode)
1349 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1350 struct fbcon_ops *ops = info->fbcon_par;
1352 int c = scr_readw((u16 *) vc->vc_pos);
1354 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1356 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1359 if (vc->vc_cursor_type & 0x10)
1360 fbcon_del_cursor_timer(info);
1362 fbcon_add_cursor_timer(info);
1364 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1365 if (mode & CM_SOFTBACK) {
1366 mode &= ~CM_SOFTBACK;
1370 fbcon_set_origin(vc);
1374 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1375 get_color(vc, info, c, 0));
1378 static int scrollback_phys_max = 0;
1379 static int scrollback_max = 0;
1380 static int scrollback_current = 0;
1382 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1385 struct display *p, *t;
1386 struct vc_data **default_mode, *vc;
1387 struct vc_data *svc;
1388 struct fbcon_ops *ops = info->fbcon_par;
1389 int rows, cols, charcnt = 256;
1391 p = &fb_display[unit];
1393 if (var_to_display(p, var, info))
1396 vc = vc_cons[unit].d;
1401 default_mode = vc->vc_display_fg;
1402 svc = *default_mode;
1403 t = &fb_display[svc->vc_num];
1405 if (!vc->vc_font.data) {
1406 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1407 vc->vc_font.width = (*default_mode)->vc_font.width;
1408 vc->vc_font.height = (*default_mode)->vc_font.height;
1409 p->userfont = t->userfont;
1411 REFCOUNT(p->fontdata)++;
1414 charcnt = FNTCHARCNT(p->fontdata);
1416 var->activate = FB_ACTIVATE_NOW;
1417 info->var.activate = var->activate;
1418 var->yoffset = info->var.yoffset;
1419 var->xoffset = info->var.xoffset;
1420 fb_set_var(info, var);
1421 ops->var = info->var;
1422 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1423 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1424 if (charcnt == 256) {
1425 vc->vc_hi_font_mask = 0;
1427 vc->vc_hi_font_mask = 0x100;
1428 if (vc->vc_can_do_color)
1429 vc->vc_complement_mask <<= 1;
1432 if (!*svc->vc_uni_pagedir_loc)
1433 con_set_default_unimap(svc);
1434 if (!*vc->vc_uni_pagedir_loc)
1435 con_copy_unimap(vc, svc);
1437 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1438 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1439 cols /= vc->vc_font.width;
1440 rows /= vc->vc_font.height;
1441 vc_resize(vc, cols, rows);
1443 if (con_is_visible(vc)) {
1446 fbcon_update_softback(vc);
1450 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1452 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1453 struct fbcon_ops *ops = info->fbcon_par;
1454 struct display *p = &fb_display[vc->vc_num];
1456 p->yscroll += count;
1457 if (p->yscroll >= p->vrows) /* Deal with wrap */
1458 p->yscroll -= p->vrows;
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 scrollback_max += count;
1464 if (scrollback_max > scrollback_phys_max)
1465 scrollback_max = scrollback_phys_max;
1466 scrollback_current = 0;
1469 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1471 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1472 struct fbcon_ops *ops = info->fbcon_par;
1473 struct display *p = &fb_display[vc->vc_num];
1475 p->yscroll -= count;
1476 if (p->yscroll < 0) /* Deal with wrap */
1477 p->yscroll += p->vrows;
1478 ops->var.xoffset = 0;
1479 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1480 ops->var.vmode |= FB_VMODE_YWRAP;
1481 ops->update_start(info);
1482 scrollback_max -= count;
1483 if (scrollback_max < 0)
1485 scrollback_current = 0;
1488 static __inline__ void ypan_up(struct vc_data *vc, int count)
1490 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1491 struct display *p = &fb_display[vc->vc_num];
1492 struct fbcon_ops *ops = info->fbcon_par;
1494 p->yscroll += count;
1495 if (p->yscroll > p->vrows - vc->vc_rows) {
1496 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1497 0, 0, 0, vc->vc_rows, vc->vc_cols);
1498 p->yscroll -= p->vrows - vc->vc_rows;
1501 ops->var.xoffset = 0;
1502 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1503 ops->var.vmode &= ~FB_VMODE_YWRAP;
1504 ops->update_start(info);
1505 fbcon_clear_margins(vc, 1);
1506 scrollback_max += count;
1507 if (scrollback_max > scrollback_phys_max)
1508 scrollback_max = scrollback_phys_max;
1509 scrollback_current = 0;
1512 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1514 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1515 struct fbcon_ops *ops = info->fbcon_par;
1516 struct display *p = &fb_display[vc->vc_num];
1518 p->yscroll += count;
1520 if (p->yscroll > p->vrows - vc->vc_rows) {
1521 p->yscroll -= p->vrows - vc->vc_rows;
1522 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1525 ops->var.xoffset = 0;
1526 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1527 ops->var.vmode &= ~FB_VMODE_YWRAP;
1528 ops->update_start(info);
1529 fbcon_clear_margins(vc, 1);
1530 scrollback_max += count;
1531 if (scrollback_max > scrollback_phys_max)
1532 scrollback_max = scrollback_phys_max;
1533 scrollback_current = 0;
1536 static __inline__ void ypan_down(struct vc_data *vc, int count)
1538 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1539 struct display *p = &fb_display[vc->vc_num];
1540 struct fbcon_ops *ops = info->fbcon_par;
1542 p->yscroll -= count;
1543 if (p->yscroll < 0) {
1544 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1545 0, vc->vc_rows, vc->vc_cols);
1546 p->yscroll += p->vrows - vc->vc_rows;
1549 ops->var.xoffset = 0;
1550 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1551 ops->var.vmode &= ~FB_VMODE_YWRAP;
1552 ops->update_start(info);
1553 fbcon_clear_margins(vc, 1);
1554 scrollback_max -= count;
1555 if (scrollback_max < 0)
1557 scrollback_current = 0;
1560 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1562 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1563 struct fbcon_ops *ops = info->fbcon_par;
1564 struct display *p = &fb_display[vc->vc_num];
1566 p->yscroll -= count;
1568 if (p->yscroll < 0) {
1569 p->yscroll += p->vrows - vc->vc_rows;
1570 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1573 ops->var.xoffset = 0;
1574 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1575 ops->var.vmode &= ~FB_VMODE_YWRAP;
1576 ops->update_start(info);
1577 fbcon_clear_margins(vc, 1);
1578 scrollback_max -= count;
1579 if (scrollback_max < 0)
1581 scrollback_current = 0;
1584 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1587 int count = vc->vc_rows;
1588 unsigned short *d, *s;
1592 d = (u16 *) softback_curr;
1593 if (d == (u16 *) softback_in)
1594 d = (u16 *) vc->vc_origin;
1595 n = softback_curr + delta * vc->vc_size_row;
1596 softback_lines -= delta;
1598 if (softback_curr < softback_top && n < softback_buf) {
1599 n += softback_end - softback_buf;
1600 if (n < softback_top) {
1602 (softback_top - n) / vc->vc_size_row;
1605 } else if (softback_curr >= softback_top
1606 && n < softback_top) {
1608 (softback_top - n) / vc->vc_size_row;
1612 if (softback_curr > softback_in && n >= softback_end) {
1613 n += softback_buf - softback_end;
1614 if (n > softback_in) {
1618 } else if (softback_curr <= softback_in && n > softback_in) {
1623 if (n == softback_curr)
1626 s = (u16 *) softback_curr;
1627 if (s == (u16 *) softback_in)
1628 s = (u16 *) vc->vc_origin;
1630 unsigned short *start;
1634 unsigned short attr = 1;
1637 le = advance_row(s, 1);
1640 if (attr != (c & 0xff00)) {
1643 fbcon_putcs(vc, start, s - start,
1649 if (c == scr_readw(d)) {
1651 fbcon_putcs(vc, start, s - start,
1664 fbcon_putcs(vc, start, s - start, line, x);
1666 if (d == (u16 *) softback_end)
1667 d = (u16 *) softback_buf;
1668 if (d == (u16 *) softback_in)
1669 d = (u16 *) vc->vc_origin;
1670 if (s == (u16 *) softback_end)
1671 s = (u16 *) softback_buf;
1672 if (s == (u16 *) softback_in)
1673 s = (u16 *) vc->vc_origin;
1677 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1678 int line, int count, int dy)
1680 unsigned short *s = (unsigned short *)
1681 (vc->vc_origin + vc->vc_size_row * line);
1684 unsigned short *start = s;
1685 unsigned short *le = advance_row(s, 1);
1688 unsigned short attr = 1;
1692 if (attr != (c & 0xff00)) {
1695 fbcon_putcs(vc, start, s - start,
1701 console_conditional_schedule();
1705 fbcon_putcs(vc, start, s - start, dy, x);
1706 console_conditional_schedule();
1711 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1712 struct display *p, int line, int count, int ycount)
1714 int offset = ycount * vc->vc_cols;
1715 unsigned short *d = (unsigned short *)
1716 (vc->vc_origin + vc->vc_size_row * line);
1717 unsigned short *s = d + offset;
1718 struct fbcon_ops *ops = info->fbcon_par;
1721 unsigned short *start = s;
1722 unsigned short *le = advance_row(s, 1);
1729 if (c == scr_readw(d)) {
1731 ops->bmove(vc, info, line + ycount, x,
1732 line, x, 1, s-start);
1742 console_conditional_schedule();
1747 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1749 console_conditional_schedule();
1754 /* NOTE: We subtract two lines from these pointers */
1755 s -= vc->vc_size_row;
1756 d -= vc->vc_size_row;
1761 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1762 int line, int count, int offset)
1764 unsigned short *d = (unsigned short *)
1765 (vc->vc_origin + vc->vc_size_row * line);
1766 unsigned short *s = d + offset;
1769 unsigned short *start = s;
1770 unsigned short *le = advance_row(s, 1);
1773 unsigned short attr = 1;
1777 if (attr != (c & 0xff00)) {
1780 fbcon_putcs(vc, start, s - start,
1786 if (c == scr_readw(d)) {
1788 fbcon_putcs(vc, start, s - start,
1798 console_conditional_schedule();
1803 fbcon_putcs(vc, start, s - start, line, x);
1804 console_conditional_schedule();
1809 /* NOTE: We subtract two lines from these pointers */
1810 s -= vc->vc_size_row;
1811 d -= vc->vc_size_row;
1816 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1821 if (vc->vc_num != fg_console)
1823 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1826 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1828 p = advance_row(p, 1);
1829 softback_in += vc->vc_size_row;
1830 if (softback_in == softback_end)
1831 softback_in = softback_buf;
1832 if (softback_in == softback_top) {
1833 softback_top += vc->vc_size_row;
1834 if (softback_top == softback_end)
1835 softback_top = softback_buf;
1838 softback_curr = softback_in;
1841 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1842 enum con_scroll dir, unsigned int count)
1844 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1845 struct display *p = &fb_display[vc->vc_num];
1846 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1848 if (fbcon_is_inactive(vc, info))
1851 fbcon_cursor(vc, CM_ERASE);
1854 * ++Geert: Only use ywrap/ypan if the console is in text mode
1855 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1856 * whole screen (prevents flicker).
1861 if (count > vc->vc_rows) /* Maximum realistic size */
1862 count = vc->vc_rows;
1864 fbcon_softback_note(vc, t, count);
1865 if (logo_shown >= 0)
1867 switch (p->scrollmode) {
1869 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1871 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1872 scr_memsetw((unsigned short *) (vc->vc_origin +
1875 vc->vc_video_erase_char,
1876 vc->vc_size_row * count);
1880 case SCROLL_WRAP_MOVE:
1881 if (b - t - count > 3 * vc->vc_rows >> 2) {
1883 fbcon_bmove(vc, 0, 0, count, 0, t,
1885 ywrap_up(vc, count);
1886 if (vc->vc_rows - b > 0)
1887 fbcon_bmove(vc, b - count, 0, b, 0,
1890 } else if (info->flags & FBINFO_READS_FAST)
1891 fbcon_bmove(vc, t + count, 0, t, 0,
1892 b - t - count, vc->vc_cols);
1895 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1898 case SCROLL_PAN_REDRAW:
1899 if ((p->yscroll + count <=
1900 2 * (p->vrows - vc->vc_rows))
1901 && ((!scroll_partial && (b - t == vc->vc_rows))
1904 3 * vc->vc_rows >> 2)))) {
1906 fbcon_redraw_move(vc, p, 0, t, count);
1907 ypan_up_redraw(vc, t, count);
1908 if (vc->vc_rows - b > 0)
1909 fbcon_redraw_move(vc, p, b,
1910 vc->vc_rows - b, b);
1912 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1913 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1916 case SCROLL_PAN_MOVE:
1917 if ((p->yscroll + count <=
1918 2 * (p->vrows - vc->vc_rows))
1919 && ((!scroll_partial && (b - t == vc->vc_rows))
1922 3 * vc->vc_rows >> 2)))) {
1924 fbcon_bmove(vc, 0, 0, count, 0, t,
1927 if (vc->vc_rows - b > 0)
1928 fbcon_bmove(vc, b - count, 0, b, 0,
1931 } else if (info->flags & FBINFO_READS_FAST)
1932 fbcon_bmove(vc, t + count, 0, t, 0,
1933 b - t - count, vc->vc_cols);
1936 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1941 fbcon_redraw(vc, p, t, b - t - count,
1942 count * vc->vc_cols);
1943 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1944 scr_memsetw((unsigned short *) (vc->vc_origin +
1947 vc->vc_video_erase_char,
1948 vc->vc_size_row * count);
1954 if (count > vc->vc_rows) /* Maximum realistic size */
1955 count = vc->vc_rows;
1956 if (logo_shown >= 0)
1958 switch (p->scrollmode) {
1960 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1962 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1963 scr_memsetw((unsigned short *) (vc->vc_origin +
1966 vc->vc_video_erase_char,
1967 vc->vc_size_row * count);
1971 case SCROLL_WRAP_MOVE:
1972 if (b - t - count > 3 * vc->vc_rows >> 2) {
1973 if (vc->vc_rows - b > 0)
1974 fbcon_bmove(vc, b, 0, b - count, 0,
1977 ywrap_down(vc, count);
1979 fbcon_bmove(vc, count, 0, 0, 0, t,
1981 } else if (info->flags & FBINFO_READS_FAST)
1982 fbcon_bmove(vc, t, 0, t + count, 0,
1983 b - t - count, vc->vc_cols);
1986 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1989 case SCROLL_PAN_MOVE:
1990 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1991 && ((!scroll_partial && (b - t == vc->vc_rows))
1994 3 * vc->vc_rows >> 2)))) {
1995 if (vc->vc_rows - b > 0)
1996 fbcon_bmove(vc, b, 0, b - count, 0,
1999 ypan_down(vc, count);
2001 fbcon_bmove(vc, count, 0, 0, 0, t,
2003 } else if (info->flags & FBINFO_READS_FAST)
2004 fbcon_bmove(vc, t, 0, t + count, 0,
2005 b - t - count, vc->vc_cols);
2008 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2011 case SCROLL_PAN_REDRAW:
2012 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2013 && ((!scroll_partial && (b - t == vc->vc_rows))
2016 3 * vc->vc_rows >> 2)))) {
2017 if (vc->vc_rows - b > 0)
2018 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2020 ypan_down_redraw(vc, t, count);
2022 fbcon_redraw_move(vc, p, count, t, 0);
2024 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2025 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2030 fbcon_redraw(vc, p, b - 1, b - t - count,
2031 -count * vc->vc_cols);
2032 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2033 scr_memsetw((unsigned short *) (vc->vc_origin +
2036 vc->vc_video_erase_char,
2037 vc->vc_size_row * count);
2045 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2046 int height, int width)
2048 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2049 struct display *p = &fb_display[vc->vc_num];
2051 if (fbcon_is_inactive(vc, info))
2054 if (!width || !height)
2057 /* Split blits that cross physical y_wrap case.
2058 * Pathological case involves 4 blits, better to use recursive
2059 * code rather than unrolled case
2061 * Recursive invocations don't need to erase the cursor over and
2062 * over again, so we use fbcon_bmove_rec()
2064 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2065 p->vrows - p->yscroll);
2068 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2069 int dy, int dx, int height, int width, u_int y_break)
2071 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2072 struct fbcon_ops *ops = info->fbcon_par;
2075 if (sy < y_break && sy + height > y_break) {
2077 if (dy < sy) { /* Avoid trashing self */
2078 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2080 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2081 height - b, width, y_break);
2083 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2084 height - b, width, y_break);
2085 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2091 if (dy < y_break && dy + height > y_break) {
2093 if (dy < sy) { /* Avoid trashing self */
2094 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2096 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2097 height - b, width, y_break);
2099 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2100 height - b, width, y_break);
2101 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2106 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2110 static void updatescrollmode(struct display *p,
2111 struct fb_info *info,
2114 struct fbcon_ops *ops = info->fbcon_par;
2115 int fh = vc->vc_font.height;
2116 int cap = info->flags;
2118 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2119 info->fix.xpanstep);
2120 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2121 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2122 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2123 info->var.xres_virtual);
2124 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2125 divides(ypan, vc->vc_font.height) && vyres > yres;
2126 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2127 divides(ywrap, vc->vc_font.height) &&
2128 divides(vc->vc_font.height, vyres) &&
2129 divides(vc->vc_font.height, yres);
2130 int reading_fast = cap & FBINFO_READS_FAST;
2131 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2132 !(cap & FBINFO_HWACCEL_DISABLED);
2133 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2134 !(cap & FBINFO_HWACCEL_DISABLED);
2136 p->vrows = vyres/fh;
2137 if (yres > (fh * (vc->vc_rows + 1)))
2138 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2139 if ((yres % fh) && (vyres % fh < yres % fh))
2142 if (good_wrap || good_pan) {
2143 if (reading_fast || fast_copyarea)
2144 p->scrollmode = good_wrap ?
2145 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2147 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2150 if (reading_fast || (fast_copyarea && !fast_imageblit))
2151 p->scrollmode = SCROLL_MOVE;
2153 p->scrollmode = SCROLL_REDRAW;
2157 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2158 unsigned int height, unsigned int user)
2160 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2161 struct fbcon_ops *ops = info->fbcon_par;
2162 struct display *p = &fb_display[vc->vc_num];
2163 struct fb_var_screeninfo var = info->var;
2164 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2166 virt_w = FBCON_SWAP(ops->rotate, width, height);
2167 virt_h = FBCON_SWAP(ops->rotate, height, width);
2168 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2169 vc->vc_font.height);
2170 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2172 var.xres = virt_w * virt_fw;
2173 var.yres = virt_h * virt_fh;
2174 x_diff = info->var.xres - var.xres;
2175 y_diff = info->var.yres - var.yres;
2176 if (x_diff < 0 || x_diff > virt_fw ||
2177 y_diff < 0 || y_diff > virt_fh) {
2178 const struct fb_videomode *mode;
2180 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2181 mode = fb_find_best_mode(&var, &info->modelist);
2184 display_to_var(&var, p);
2185 fb_videomode_to_var(&var, mode);
2187 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2190 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2191 if (con_is_visible(vc)) {
2192 var.activate = FB_ACTIVATE_NOW |
2194 fb_set_var(info, &var);
2196 var_to_display(p, &info->var, info);
2197 ops->var = info->var;
2199 updatescrollmode(p, info, vc);
2203 static int fbcon_switch(struct vc_data *vc)
2205 struct fb_info *info, *old_info = NULL;
2206 struct fbcon_ops *ops;
2207 struct display *p = &fb_display[vc->vc_num];
2208 struct fb_var_screeninfo var;
2209 int i, ret, prev_console, charcnt = 256;
2211 info = registered_fb[con2fb_map[vc->vc_num]];
2212 ops = info->fbcon_par;
2216 fbcon_set_origin(vc);
2217 softback_top = softback_curr = softback_in = softback_buf;
2219 fbcon_update_softback(vc);
2222 if (logo_shown >= 0) {
2223 struct vc_data *conp2 = vc_cons[logo_shown].d;
2225 if (conp2->vc_top == logo_lines
2226 && conp2->vc_bottom == conp2->vc_rows)
2228 logo_shown = FBCON_LOGO_CANSHOW;
2231 prev_console = ops->currcon;
2232 if (prev_console != -1)
2233 old_info = registered_fb[con2fb_map[prev_console]];
2235 * FIXME: If we have multiple fbdev's loaded, we need to
2236 * update all info->currcon. Perhaps, we can place this
2237 * in a centralized structure, but this might break some
2240 * info->currcon = vc->vc_num;
2242 for_each_registered_fb(i) {
2243 if (registered_fb[i]->fbcon_par) {
2244 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2246 o->currcon = vc->vc_num;
2249 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2250 display_to_var(&var, p);
2251 var.activate = FB_ACTIVATE_NOW;
2254 * make sure we don't unnecessarily trip the memcmp()
2257 info->var.activate = var.activate;
2258 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2259 fb_set_var(info, &var);
2260 ops->var = info->var;
2262 if (old_info != NULL && (old_info != info ||
2263 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2264 if (info->fbops->fb_set_par) {
2265 ret = info->fbops->fb_set_par(info);
2268 printk(KERN_ERR "fbcon_switch: detected "
2269 "unhandled fb_set_par error, "
2270 "error code %d\n", ret);
2273 if (old_info != info)
2274 fbcon_del_cursor_timer(old_info);
2277 if (fbcon_is_inactive(vc, info) ||
2278 ops->blank_state != FB_BLANK_UNBLANK)
2279 fbcon_del_cursor_timer(info);
2281 fbcon_add_cursor_timer(info);
2283 set_blitting_type(vc, info);
2284 ops->cursor_reset = 1;
2286 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2287 ops->rotate = FB_ROTATE_UR;
2288 set_blitting_type(vc, info);
2291 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2292 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2295 charcnt = FNTCHARCNT(vc->vc_font.data);
2298 vc->vc_complement_mask <<= 1;
2300 updatescrollmode(p, info, vc);
2302 switch (p->scrollmode) {
2303 case SCROLL_WRAP_MOVE:
2304 scrollback_phys_max = p->vrows - vc->vc_rows;
2306 case SCROLL_PAN_MOVE:
2307 case SCROLL_PAN_REDRAW:
2308 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2309 if (scrollback_phys_max < 0)
2310 scrollback_phys_max = 0;
2313 scrollback_phys_max = 0;
2318 scrollback_current = 0;
2320 if (!fbcon_is_inactive(vc, info)) {
2321 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2322 ops->update_start(info);
2325 fbcon_set_palette(vc, color_table);
2326 fbcon_clear_margins(vc, 0);
2328 if (logo_shown == FBCON_LOGO_DRAW) {
2330 logo_shown = fg_console;
2331 /* This is protected above by initmem_freed */
2332 fb_show_logo(info, ops->rotate);
2334 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2335 vc->vc_size_row * (vc->vc_bottom -
2342 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2345 struct fb_event event;
2348 unsigned short charmask = vc->vc_hi_font_mask ?
2350 unsigned short oldc;
2352 oldc = vc->vc_video_erase_char;
2353 vc->vc_video_erase_char &= charmask;
2354 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2355 vc->vc_video_erase_char = oldc;
2359 if (!lock_fb_info(info))
2362 event.data = ␣
2363 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2364 unlock_fb_info(info);
2367 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2369 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2370 struct fbcon_ops *ops = info->fbcon_par;
2373 struct fb_var_screeninfo var = info->var;
2378 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2379 fb_set_var(info, &var);
2381 ops->var = info->var;
2385 if (!fbcon_is_inactive(vc, info)) {
2386 if (ops->blank_state != blank) {
2387 ops->blank_state = blank;
2388 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2389 ops->cursor_flash = (!blank);
2391 if (!(info->flags & FBINFO_MISC_USEREVENT))
2392 if (fb_blank(info, blank))
2393 fbcon_generic_blank(vc, info, blank);
2400 if (mode_switch || fbcon_is_inactive(vc, info) ||
2401 ops->blank_state != FB_BLANK_UNBLANK)
2402 fbcon_del_cursor_timer(info);
2404 fbcon_add_cursor_timer(info);
2409 static int fbcon_debug_enter(struct vc_data *vc)
2411 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2412 struct fbcon_ops *ops = info->fbcon_par;
2414 ops->save_graphics = ops->graphics;
2416 if (info->fbops->fb_debug_enter)
2417 info->fbops->fb_debug_enter(info);
2418 fbcon_set_palette(vc, color_table);
2422 static int fbcon_debug_leave(struct vc_data *vc)
2424 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2425 struct fbcon_ops *ops = info->fbcon_par;
2427 ops->graphics = ops->save_graphics;
2428 if (info->fbops->fb_debug_leave)
2429 info->fbops->fb_debug_leave(info);
2433 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2435 u8 *fontdata = vc->vc_font.data;
2436 u8 *data = font->data;
2439 font->width = vc->vc_font.width;
2440 font->height = vc->vc_font.height;
2441 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2445 if (font->width <= 8) {
2446 j = vc->vc_font.height;
2447 for (i = 0; i < font->charcount; i++) {
2448 memcpy(data, fontdata, j);
2449 memset(data + j, 0, 32 - j);
2453 } else if (font->width <= 16) {
2454 j = vc->vc_font.height * 2;
2455 for (i = 0; i < font->charcount; i++) {
2456 memcpy(data, fontdata, j);
2457 memset(data + j, 0, 64 - j);
2461 } else if (font->width <= 24) {
2462 for (i = 0; i < font->charcount; i++) {
2463 for (j = 0; j < vc->vc_font.height; j++) {
2464 *data++ = fontdata[0];
2465 *data++ = fontdata[1];
2466 *data++ = fontdata[2];
2467 fontdata += sizeof(u32);
2469 memset(data, 0, 3 * (32 - j));
2470 data += 3 * (32 - j);
2473 j = vc->vc_font.height * 4;
2474 for (i = 0; i < font->charcount; i++) {
2475 memcpy(data, fontdata, j);
2476 memset(data + j, 0, 128 - j);
2484 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2485 static void set_vc_hi_font(struct vc_data *vc, bool set)
2488 vc->vc_hi_font_mask = 0;
2489 if (vc->vc_can_do_color) {
2490 vc->vc_complement_mask >>= 1;
2491 vc->vc_s_complement_mask >>= 1;
2494 /* ++Edmund: reorder the attribute bits */
2495 if (vc->vc_can_do_color) {
2496 unsigned short *cp =
2497 (unsigned short *) vc->vc_origin;
2498 int count = vc->vc_screenbuf_size / 2;
2500 for (; count > 0; count--, cp++) {
2502 scr_writew(((c & 0xfe00) >> 1) |
2505 c = vc->vc_video_erase_char;
2506 vc->vc_video_erase_char =
2507 ((c & 0xfe00) >> 1) | (c & 0xff);
2511 vc->vc_hi_font_mask = 0x100;
2512 if (vc->vc_can_do_color) {
2513 vc->vc_complement_mask <<= 1;
2514 vc->vc_s_complement_mask <<= 1;
2517 /* ++Edmund: reorder the attribute bits */
2519 unsigned short *cp =
2520 (unsigned short *) vc->vc_origin;
2521 int count = vc->vc_screenbuf_size / 2;
2523 for (; count > 0; count--, cp++) {
2524 unsigned short newc;
2526 if (vc->vc_can_do_color)
2528 ((c & 0xff00) << 1) | (c &
2532 scr_writew(newc, cp);
2534 c = vc->vc_video_erase_char;
2535 if (vc->vc_can_do_color) {
2536 vc->vc_video_erase_char =
2537 ((c & 0xff00) << 1) | (c & 0xff);
2540 vc->vc_video_erase_char = c & ~0x100;
2545 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2546 const u8 * data, int userfont)
2548 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2549 struct fbcon_ops *ops = info->fbcon_par;
2550 struct display *p = &fb_display[vc->vc_num];
2553 char *old_data = NULL;
2555 if (con_is_visible(vc) && softback_lines)
2556 fbcon_set_origin(vc);
2558 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2560 old_data = vc->vc_font.data;
2562 cnt = FNTCHARCNT(data);
2565 vc->vc_font.data = (void *)(p->fontdata = data);
2566 if ((p->userfont = userfont))
2568 vc->vc_font.width = w;
2569 vc->vc_font.height = h;
2570 if (vc->vc_hi_font_mask && cnt == 256)
2571 set_vc_hi_font(vc, false);
2572 else if (!vc->vc_hi_font_mask && cnt == 512)
2573 set_vc_hi_font(vc, true);
2578 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2579 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2582 vc_resize(vc, cols, rows);
2583 if (con_is_visible(vc) && softback_buf)
2584 fbcon_update_softback(vc);
2585 } else if (con_is_visible(vc)
2586 && vc->vc_mode == KD_TEXT) {
2587 fbcon_clear_margins(vc, 0);
2591 if (old_data && (--REFCOUNT(old_data) == 0))
2592 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2596 static int fbcon_copy_font(struct vc_data *vc, int con)
2598 struct display *od = &fb_display[con];
2599 struct console_font *f = &vc->vc_font;
2601 if (od->fontdata == f->data)
2602 return 0; /* already the same font... */
2603 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2607 * User asked to set font; we are guaranteed that
2608 * a) width and height are in range 1..32
2609 * b) charcount does not exceed 512
2610 * but lets not assume that, since someone might someday want to use larger
2611 * fonts. And charcount of 512 is small for unicode support.
2613 * However, user space gives the font in 32 rows , regardless of
2614 * actual font height. So a new API is needed if support for larger fonts
2615 * is ever implemented.
2618 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2621 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2622 unsigned charcount = font->charcount;
2623 int w = font->width;
2624 int h = font->height;
2627 u8 *new_data, *data = font->data;
2628 int pitch = (font->width+7) >> 3;
2630 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2631 * If not this check should be changed to charcount < 256 */
2632 if (charcount != 256 && charcount != 512)
2635 /* Make sure drawing engine can handle the font */
2636 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2637 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2640 /* Make sure driver can handle the font length */
2641 if (fbcon_invalid_charcount(info, charcount))
2644 size = h * pitch * charcount;
2646 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2651 new_data += FONT_EXTRA_WORDS * sizeof(int);
2652 FNTSIZE(new_data) = size;
2653 FNTCHARCNT(new_data) = charcount;
2654 REFCOUNT(new_data) = 0; /* usage counter */
2655 for (i=0; i< charcount; i++) {
2656 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2659 /* Since linux has a nice crc32 function use it for counting font
2661 csum = crc32(0, new_data, size);
2663 FNTSUM(new_data) = csum;
2664 /* Check if the same font is on some other console already */
2665 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2666 struct vc_data *tmp = vc_cons[i].d;
2668 if (fb_display[i].userfont &&
2669 fb_display[i].fontdata &&
2670 FNTSUM(fb_display[i].fontdata) == csum &&
2671 FNTSIZE(fb_display[i].fontdata) == size &&
2672 tmp->vc_font.width == w &&
2673 !memcmp(fb_display[i].fontdata, new_data, size)) {
2674 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2675 new_data = (u8 *)fb_display[i].fontdata;
2679 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2682 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2684 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2685 const struct font_desc *f;
2688 f = get_default_font(info->var.xres, info->var.yres,
2689 info->pixmap.blit_x, info->pixmap.blit_y);
2690 else if (!(f = find_font(name)))
2693 font->width = f->width;
2694 font->height = f->height;
2695 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2698 static u16 palette_red[16];
2699 static u16 palette_green[16];
2700 static u16 palette_blue[16];
2702 static struct fb_cmap palette_cmap = {
2703 0, 16, palette_red, palette_green, palette_blue, NULL
2706 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2708 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2712 if (fbcon_is_inactive(vc, info))
2715 if (!con_is_visible(vc))
2718 depth = fb_get_color_depth(&info->var, &info->fix);
2720 for (i = j = 0; i < 16; i++) {
2722 val = vc->vc_palette[j++];
2723 palette_red[k] = (val << 8) | val;
2724 val = vc->vc_palette[j++];
2725 palette_green[k] = (val << 8) | val;
2726 val = vc->vc_palette[j++];
2727 palette_blue[k] = (val << 8) | val;
2729 palette_cmap.len = 16;
2730 palette_cmap.start = 0;
2732 * If framebuffer is capable of less than 16 colors,
2733 * use default palette of fbcon.
2736 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2738 fb_set_cmap(&palette_cmap, info);
2741 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2746 if (vc->vc_num != fg_console || !softback_lines)
2747 return (u16 *) (vc->vc_origin + offset);
2748 line = offset / vc->vc_size_row;
2749 if (line >= softback_lines)
2750 return (u16 *) (vc->vc_origin + offset -
2751 softback_lines * vc->vc_size_row);
2752 p = softback_curr + offset;
2753 if (p >= softback_end)
2754 p += softback_buf - softback_end;
2758 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2764 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2765 unsigned long offset = (pos - vc->vc_origin) / 2;
2767 x = offset % vc->vc_cols;
2768 y = offset / vc->vc_cols;
2769 if (vc->vc_num == fg_console)
2770 y += softback_lines;
2771 ret = pos + (vc->vc_cols - x) * 2;
2772 } else if (vc->vc_num == fg_console && softback_lines) {
2773 unsigned long offset = pos - softback_curr;
2775 if (pos < softback_curr)
2776 offset += softback_end - softback_buf;
2778 x = offset % vc->vc_cols;
2779 y = offset / vc->vc_cols;
2780 ret = pos + (vc->vc_cols - x) * 2;
2781 if (ret == softback_end)
2783 if (ret == softback_in)
2784 ret = vc->vc_origin;
2786 /* Should not happen */
2788 ret = vc->vc_origin;
2797 /* As we might be inside of softback, we may work with non-contiguous buffer,
2798 that's why we have to use a separate routine. */
2799 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2802 u16 a = scr_readw(p);
2803 if (!vc->vc_can_do_color)
2805 else if (vc->vc_hi_font_mask == 0x100)
2806 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2807 (((a) & 0x0e00) << 4);
2809 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2810 (((a) & 0x0700) << 4);
2812 if (p == (u16 *) softback_end)
2813 p = (u16 *) softback_buf;
2814 if (p == (u16 *) softback_in)
2815 p = (u16 *) vc->vc_origin;
2819 static void fbcon_scrolldelta(struct vc_data *vc, int lines)
2821 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2822 struct fbcon_ops *ops = info->fbcon_par;
2823 struct display *disp = &fb_display[fg_console];
2824 int offset, limit, scrollback_old;
2827 if (vc->vc_num != fg_console)
2829 if (vc->vc_mode != KD_TEXT || !lines)
2831 if (logo_shown >= 0) {
2832 struct vc_data *conp2 = vc_cons[logo_shown].d;
2834 if (conp2->vc_top == logo_lines
2835 && conp2->vc_bottom == conp2->vc_rows)
2837 if (logo_shown == vc->vc_num) {
2843 logo_lines * vc->vc_size_row;
2844 for (i = 0; i < logo_lines; i++) {
2845 if (p == softback_top)
2847 if (p == softback_buf)
2849 p -= vc->vc_size_row;
2850 q -= vc->vc_size_row;
2851 scr_memcpyw((u16 *) q, (u16 *) p,
2854 softback_in = softback_curr = p;
2855 update_region(vc, vc->vc_origin,
2856 logo_lines * vc->vc_cols);
2858 logo_shown = FBCON_LOGO_CANSHOW;
2860 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2861 fbcon_redraw_softback(vc, disp, lines);
2862 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2866 if (!scrollback_phys_max)
2869 scrollback_old = scrollback_current;
2870 scrollback_current -= lines;
2871 if (scrollback_current < 0)
2872 scrollback_current = 0;
2873 else if (scrollback_current > scrollback_max)
2874 scrollback_current = scrollback_max;
2875 if (scrollback_current == scrollback_old)
2878 if (fbcon_is_inactive(vc, info))
2881 fbcon_cursor(vc, CM_ERASE);
2883 offset = disp->yscroll - scrollback_current;
2884 limit = disp->vrows;
2885 switch (disp->scrollmode) {
2886 case SCROLL_WRAP_MOVE:
2887 info->var.vmode |= FB_VMODE_YWRAP;
2889 case SCROLL_PAN_MOVE:
2890 case SCROLL_PAN_REDRAW:
2891 limit -= vc->vc_rows;
2892 info->var.vmode &= ~FB_VMODE_YWRAP;
2897 else if (offset >= limit)
2900 ops->var.xoffset = 0;
2901 ops->var.yoffset = offset * vc->vc_font.height;
2902 ops->update_start(info);
2904 if (!scrollback_current)
2905 fbcon_cursor(vc, CM_DRAW);
2908 static int fbcon_set_origin(struct vc_data *vc)
2911 fbcon_scrolldelta(vc, softback_lines);
2915 static void fbcon_suspended(struct fb_info *info)
2917 struct vc_data *vc = NULL;
2918 struct fbcon_ops *ops = info->fbcon_par;
2920 if (!ops || ops->currcon < 0)
2922 vc = vc_cons[ops->currcon].d;
2924 /* Clear cursor, restore saved data */
2925 fbcon_cursor(vc, CM_ERASE);
2928 static void fbcon_resumed(struct fb_info *info)
2931 struct fbcon_ops *ops = info->fbcon_par;
2933 if (!ops || ops->currcon < 0)
2935 vc = vc_cons[ops->currcon].d;
2940 static void fbcon_modechanged(struct fb_info *info)
2942 struct fbcon_ops *ops = info->fbcon_par;
2947 if (!ops || ops->currcon < 0)
2949 vc = vc_cons[ops->currcon].d;
2950 if (vc->vc_mode != KD_TEXT ||
2951 registered_fb[con2fb_map[ops->currcon]] != info)
2954 p = &fb_display[vc->vc_num];
2955 set_blitting_type(vc, info);
2957 if (con_is_visible(vc)) {
2958 var_to_display(p, &info->var, info);
2959 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2960 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2961 cols /= vc->vc_font.width;
2962 rows /= vc->vc_font.height;
2963 vc_resize(vc, cols, rows);
2964 updatescrollmode(p, info, vc);
2966 scrollback_current = 0;
2968 if (!fbcon_is_inactive(vc, info)) {
2969 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2970 ops->update_start(info);
2973 fbcon_set_palette(vc, color_table);
2976 fbcon_update_softback(vc);
2980 static void fbcon_set_all_vcs(struct fb_info *info)
2982 struct fbcon_ops *ops = info->fbcon_par;
2985 int i, rows, cols, fg = -1;
2987 if (!ops || ops->currcon < 0)
2990 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2992 if (!vc || vc->vc_mode != KD_TEXT ||
2993 registered_fb[con2fb_map[i]] != info)
2996 if (con_is_visible(vc)) {
3001 p = &fb_display[vc->vc_num];
3002 set_blitting_type(vc, info);
3003 var_to_display(p, &info->var, info);
3004 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3005 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3006 cols /= vc->vc_font.width;
3007 rows /= vc->vc_font.height;
3008 vc_resize(vc, cols, rows);
3012 fbcon_modechanged(info);
3015 static int fbcon_mode_deleted(struct fb_info *info,
3016 struct fb_videomode *mode)
3018 struct fb_info *fb_info;
3020 int i, j, found = 0;
3022 /* before deletion, ensure that mode is not in use */
3023 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3027 fb_info = registered_fb[j];
3028 if (fb_info != info)
3033 if (fb_mode_is_equal(p->mode, mode)) {
3041 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3042 static int fbcon_unbind(void)
3046 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3050 fbcon_has_console_bind = 0;
3055 static inline int fbcon_unbind(void)
3059 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3061 /* called with console_lock held */
3062 static int fbcon_fb_unbind(int idx)
3064 int i, new_idx = -1, ret = 0;
3066 WARN_CONSOLE_UNLOCKED();
3068 if (!fbcon_has_console_bind)
3071 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3072 if (con2fb_map[i] != idx &&
3073 con2fb_map[i] != -1) {
3074 new_idx = con2fb_map[i];
3079 if (new_idx != -1) {
3080 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3081 if (con2fb_map[i] == idx)
3082 set_con2fb_map(i, new_idx, 0);
3085 struct fb_info *info = registered_fb[idx];
3087 /* This is sort of like set_con2fb_map, except it maps
3088 * the consoles to no device and then releases the
3089 * oldinfo to free memory and cancel the cursor blink
3090 * timer. I can imagine this just becoming part of
3091 * set_con2fb_map where new_idx is -1
3093 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3094 if (con2fb_map[i] == idx) {
3096 if (!search_fb_in_map(idx)) {
3097 ret = con2fb_release_oldinfo(vc_cons[i].d,
3101 con2fb_map[i] = idx;
3107 ret = fbcon_unbind();
3113 /* called with console_lock held */
3114 static int fbcon_fb_unregistered(struct fb_info *info)
3118 WARN_CONSOLE_UNLOCKED();
3120 if (deferred_takeover)
3124 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3125 if (con2fb_map[i] == idx)
3129 if (idx == info_idx) {
3132 for_each_registered_fb(i) {
3138 if (info_idx != -1) {
3139 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3140 if (con2fb_map[i] == -1)
3141 con2fb_map[i] = info_idx;
3145 if (primary_device == idx)
3146 primary_device = -1;
3148 if (!num_registered_fb)
3149 do_unregister_con_driver(&fb_con);
3154 /* called with console_lock held */
3155 static void fbcon_remap_all(int idx)
3159 WARN_CONSOLE_UNLOCKED();
3161 if (deferred_takeover) {
3162 for (i = first_fb_vc; i <= last_fb_vc; i++)
3163 con2fb_map_boot[i] = idx;
3164 fbcon_map_override();
3168 for (i = first_fb_vc; i <= last_fb_vc; i++)
3169 set_con2fb_map(i, idx, 0);
3171 if (con_is_bound(&fb_con)) {
3172 printk(KERN_INFO "fbcon: Remapping primary device, "
3173 "fb%i, to tty %i-%i\n", idx,
3174 first_fb_vc + 1, last_fb_vc + 1);
3179 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3180 static void fbcon_select_primary(struct fb_info *info)
3182 if (!map_override && primary_device == -1 &&
3183 fb_is_primary_device(info)) {
3186 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3187 info->fix.id, info->node);
3188 primary_device = info->node;
3190 for (i = first_fb_vc; i <= last_fb_vc; i++)
3191 con2fb_map_boot[i] = primary_device;
3193 if (con_is_bound(&fb_con)) {
3194 printk(KERN_INFO "fbcon: Remapping primary device, "
3195 "fb%i, to tty %i-%i\n", info->node,
3196 first_fb_vc + 1, last_fb_vc + 1);
3197 info_idx = primary_device;
3203 static inline void fbcon_select_primary(struct fb_info *info)
3207 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3209 /* called with console_lock held */
3210 static int fbcon_fb_registered(struct fb_info *info)
3212 int ret = 0, i, idx;
3214 WARN_CONSOLE_UNLOCKED();
3217 fbcon_select_primary(info);
3219 if (deferred_takeover) {
3220 pr_info("fbcon: Deferring console take-over\n");
3224 if (info_idx == -1) {
3225 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3226 if (con2fb_map_boot[i] == idx) {
3233 ret = do_fbcon_takeover(1);
3235 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3236 if (con2fb_map_boot[i] == idx)
3237 set_con2fb_map(i, idx, 0);
3244 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3246 struct fbcon_ops *ops = info->fbcon_par;
3249 if (!ops || ops->currcon < 0)
3252 vc = vc_cons[ops->currcon].d;
3253 if (vc->vc_mode != KD_TEXT ||
3254 registered_fb[con2fb_map[ops->currcon]] != info)
3257 if (con_is_visible(vc)) {
3261 do_unblank_screen(0);
3263 ops->blank_state = blank;
3266 static void fbcon_new_modelist(struct fb_info *info)
3270 struct fb_var_screeninfo var;
3271 const struct fb_videomode *mode;
3273 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3274 if (registered_fb[con2fb_map[i]] != info)
3276 if (!fb_display[i].mode)
3279 display_to_var(&var, &fb_display[i]);
3280 mode = fb_find_nearest_mode(fb_display[i].mode,
3282 fb_videomode_to_var(&var, mode);
3283 fbcon_set_disp(info, &var, vc->vc_num);
3287 static void fbcon_get_requirement(struct fb_info *info,
3288 struct fb_blit_caps *caps)
3296 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3298 if (vc && vc->vc_mode == KD_TEXT &&
3299 info->node == con2fb_map[i]) {
3301 caps->x |= 1 << (vc->vc_font.width - 1);
3302 caps->y |= 1 << (vc->vc_font.height - 1);
3303 charcnt = (p->userfont) ?
3304 FNTCHARCNT(p->fontdata) : 256;
3305 if (caps->len < charcnt)
3306 caps->len = charcnt;
3310 vc = vc_cons[fg_console].d;
3312 if (vc && vc->vc_mode == KD_TEXT &&
3313 info->node == con2fb_map[fg_console]) {
3314 p = &fb_display[fg_console];
3315 caps->x = 1 << (vc->vc_font.width - 1);
3316 caps->y = 1 << (vc->vc_font.height - 1);
3317 caps->len = (p->userfont) ?
3318 FNTCHARCNT(p->fontdata) : 256;
3323 static int fbcon_event_notify(struct notifier_block *self,
3324 unsigned long action, void *data)
3326 struct fb_event *event = data;
3327 struct fb_info *info = event->info;
3328 struct fb_videomode *mode;
3329 struct fb_con2fbmap *con2fb;
3330 struct fb_blit_caps *caps;
3334 * ignore all events except driver registration and deregistration
3335 * if fbcon is not active
3337 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3338 action == FB_EVENT_FB_UNREGISTERED))
3342 case FB_EVENT_SUSPEND:
3343 fbcon_suspended(info);
3345 case FB_EVENT_RESUME:
3346 fbcon_resumed(info);
3348 case FB_EVENT_MODE_CHANGE:
3349 fbcon_modechanged(info);
3351 case FB_EVENT_MODE_CHANGE_ALL:
3352 fbcon_set_all_vcs(info);
3354 case FB_EVENT_MODE_DELETE:
3356 ret = fbcon_mode_deleted(info, mode);
3358 case FB_EVENT_FB_UNBIND:
3360 ret = fbcon_fb_unbind(idx);
3362 case FB_EVENT_FB_REGISTERED:
3363 ret = fbcon_fb_registered(info);
3365 case FB_EVENT_FB_UNREGISTERED:
3366 ret = fbcon_fb_unregistered(info);
3368 case FB_EVENT_SET_CONSOLE_MAP:
3369 /* called with console lock held */
3370 con2fb = event->data;
3371 ret = set_con2fb_map(con2fb->console - 1,
3372 con2fb->framebuffer, 1);
3374 case FB_EVENT_GET_CONSOLE_MAP:
3375 con2fb = event->data;
3376 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3378 case FB_EVENT_BLANK:
3379 fbcon_fb_blanked(info, *(int *)event->data);
3381 case FB_EVENT_NEW_MODELIST:
3382 fbcon_new_modelist(info);
3384 case FB_EVENT_GET_REQ:
3386 fbcon_get_requirement(info, caps);
3388 case FB_EVENT_REMAP_ALL_CONSOLE:
3390 fbcon_remap_all(idx);
3398 * The console `switch' structure for the frame buffer based console
3401 static const struct consw fb_con = {
3402 .owner = THIS_MODULE,
3403 .con_startup = fbcon_startup,
3404 .con_init = fbcon_init,
3405 .con_deinit = fbcon_deinit,
3406 .con_clear = fbcon_clear,
3407 .con_putc = fbcon_putc,
3408 .con_putcs = fbcon_putcs,
3409 .con_cursor = fbcon_cursor,
3410 .con_scroll = fbcon_scroll,
3411 .con_switch = fbcon_switch,
3412 .con_blank = fbcon_blank,
3413 .con_font_set = fbcon_set_font,
3414 .con_font_get = fbcon_get_font,
3415 .con_font_default = fbcon_set_def_font,
3416 .con_font_copy = fbcon_copy_font,
3417 .con_set_palette = fbcon_set_palette,
3418 .con_scrolldelta = fbcon_scrolldelta,
3419 .con_set_origin = fbcon_set_origin,
3420 .con_invert_region = fbcon_invert_region,
3421 .con_screen_pos = fbcon_screen_pos,
3422 .con_getxy = fbcon_getxy,
3423 .con_resize = fbcon_resize,
3424 .con_debug_enter = fbcon_debug_enter,
3425 .con_debug_leave = fbcon_debug_leave,
3428 static struct notifier_block fbcon_event_notifier = {
3429 .notifier_call = fbcon_event_notify,
3432 static ssize_t store_rotate(struct device *device,
3433 struct device_attribute *attr, const char *buf,
3436 struct fb_info *info;
3440 if (fbcon_has_exited)
3444 idx = con2fb_map[fg_console];
3446 if (idx == -1 || registered_fb[idx] == NULL)
3449 info = registered_fb[idx];
3450 rotate = simple_strtoul(buf, last, 0);
3451 fbcon_rotate(info, rotate);
3457 static ssize_t store_rotate_all(struct device *device,
3458 struct device_attribute *attr,const char *buf,
3461 struct fb_info *info;
3465 if (fbcon_has_exited)
3469 idx = con2fb_map[fg_console];
3471 if (idx == -1 || registered_fb[idx] == NULL)
3474 info = registered_fb[idx];
3475 rotate = simple_strtoul(buf, last, 0);
3476 fbcon_rotate_all(info, rotate);
3482 static ssize_t show_rotate(struct device *device,
3483 struct device_attribute *attr,char *buf)
3485 struct fb_info *info;
3486 int rotate = 0, idx;
3488 if (fbcon_has_exited)
3492 idx = con2fb_map[fg_console];
3494 if (idx == -1 || registered_fb[idx] == NULL)
3497 info = registered_fb[idx];
3498 rotate = fbcon_get_rotate(info);
3501 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3504 static ssize_t show_cursor_blink(struct device *device,
3505 struct device_attribute *attr, char *buf)
3507 struct fb_info *info;
3508 struct fbcon_ops *ops;
3509 int idx, blink = -1;
3511 if (fbcon_has_exited)
3515 idx = con2fb_map[fg_console];
3517 if (idx == -1 || registered_fb[idx] == NULL)
3520 info = registered_fb[idx];
3521 ops = info->fbcon_par;
3526 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3529 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3532 static ssize_t store_cursor_blink(struct device *device,
3533 struct device_attribute *attr,
3534 const char *buf, size_t count)
3536 struct fb_info *info;
3540 if (fbcon_has_exited)
3544 idx = con2fb_map[fg_console];
3546 if (idx == -1 || registered_fb[idx] == NULL)
3549 info = registered_fb[idx];
3551 if (!info->fbcon_par)
3554 blink = simple_strtoul(buf, last, 0);
3557 fbcon_cursor_noblink = 0;
3558 fbcon_add_cursor_timer(info);
3560 fbcon_cursor_noblink = 1;
3561 fbcon_del_cursor_timer(info);
3569 static struct device_attribute device_attrs[] = {
3570 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3571 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3572 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3573 store_cursor_blink),
3576 static int fbcon_init_device(void)
3580 fbcon_has_sysfs = 1;
3582 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3583 error = device_create_file(fbcon_device, &device_attrs[i]);
3591 device_remove_file(fbcon_device, &device_attrs[i]);
3593 fbcon_has_sysfs = 0;
3599 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3600 static void fbcon_register_existing_fbs(struct work_struct *work)
3606 for_each_registered_fb(i)
3607 fbcon_fb_registered(registered_fb[i]);
3612 static struct notifier_block fbcon_output_nb;
3613 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3615 static int fbcon_output_notifier(struct notifier_block *nb,
3616 unsigned long action, void *data)
3618 WARN_CONSOLE_UNLOCKED();
3620 pr_info("fbcon: Taking over console\n");
3622 dummycon_unregister_output_notifier(&fbcon_output_nb);
3623 deferred_takeover = false;
3624 logo_shown = FBCON_LOGO_DONTSHOW;
3626 /* We may get called in atomic context */
3627 schedule_work(&fbcon_deferred_takeover_work);
3633 static void fbcon_start(void)
3635 WARN_CONSOLE_UNLOCKED();
3637 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3638 if (conswitchp != &dummy_con)
3639 deferred_takeover = false;
3641 if (deferred_takeover) {
3642 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3643 dummycon_register_output_notifier(&fbcon_output_nb);
3648 if (num_registered_fb) {
3651 for_each_registered_fb(i) {
3656 do_fbcon_takeover(0);
3660 static void fbcon_exit(void)
3662 struct fb_info *info;
3665 if (fbcon_has_exited)
3668 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3669 if (deferred_takeover) {
3670 dummycon_unregister_output_notifier(&fbcon_output_nb);
3671 deferred_takeover = false;
3675 kfree((void *)softback_buf);
3678 for_each_registered_fb(i) {
3682 info = registered_fb[i];
3684 if (info->queue.func)
3685 pending = cancel_work_sync(&info->queue);
3686 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3689 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3690 if (con2fb_map[j] == i) {
3697 if (info->fbops->fb_release)
3698 info->fbops->fb_release(info, 0);
3699 module_put(info->fbops->owner);
3701 if (info->fbcon_par) {
3702 struct fbcon_ops *ops = info->fbcon_par;
3704 fbcon_del_cursor_timer(info);
3705 kfree(ops->cursor_src);
3706 kfree(ops->cursor_state.mask);
3707 kfree(info->fbcon_par);
3708 info->fbcon_par = NULL;
3711 if (info->queue.func == fb_flashcursor)
3712 info->queue.func = NULL;
3716 fbcon_has_exited = 1;
3719 void __init fb_console_init(void)
3724 fb_register_client(&fbcon_event_notifier);
3725 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3728 if (IS_ERR(fbcon_device)) {
3729 printk(KERN_WARNING "Unable to create device "
3730 "for fbcon; errno = %ld\n",
3731 PTR_ERR(fbcon_device));
3732 fbcon_device = NULL;
3734 fbcon_init_device();
3736 for (i = 0; i < MAX_NR_CONSOLES; i++)
3745 static void __exit fbcon_deinit_device(void)
3749 if (fbcon_has_sysfs) {
3750 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3751 device_remove_file(fbcon_device, &device_attrs[i]);
3753 fbcon_has_sysfs = 0;
3757 void __exit fb_console_exit(void)
3760 fb_unregister_client(&fbcon_event_notifier);
3761 fbcon_deinit_device();
3762 device_destroy(fb_class, MKDEV(0, 0));
3764 do_unregister_con_driver(&fb_con);