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 fbcon_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 primary_device = -1;
116 static int fbcon_has_console_bind;
118 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
119 static int map_override;
121 static inline void fbcon_map_override(void)
126 static inline void fbcon_map_override(void)
129 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
131 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
132 static bool deferred_takeover = true;
134 #define deferred_takeover false
138 static char fontname[40];
140 /* current fb_info */
141 static int info_idx = -1;
143 /* console rotation */
144 static int initial_rotation = -1;
145 static int fbcon_has_sysfs;
146 static int margin_color;
148 static const struct consw fb_con;
150 #define CM_SOFTBACK (8)
152 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
154 static int fbcon_set_origin(struct vc_data *);
156 static int fbcon_cursor_noblink;
158 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
161 * Interface used by the world
164 static const char *fbcon_startup(void);
165 static void fbcon_init(struct vc_data *vc, int init);
166 static void fbcon_deinit(struct vc_data *vc);
167 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
169 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
170 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
171 int count, int ypos, int xpos);
172 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
173 static void fbcon_cursor(struct vc_data *vc, int mode);
174 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
175 int height, int width);
176 static int fbcon_switch(struct vc_data *vc);
177 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
178 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
183 static __inline__ void ywrap_up(struct vc_data *vc, int count);
184 static __inline__ void ywrap_down(struct vc_data *vc, int count);
185 static __inline__ void ypan_up(struct vc_data *vc, int count);
186 static __inline__ void ypan_down(struct vc_data *vc, int count);
187 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
188 int dy, int dx, int height, int width, u_int y_break);
189 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
192 int line, int count, int dy);
193 static void fbcon_modechanged(struct fb_info *info);
194 static void fbcon_set_all_vcs(struct fb_info *info);
195 static void fbcon_start(void);
196 static void fbcon_exit(void);
197 static struct device *fbcon_device;
199 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
200 static inline void fbcon_set_rotation(struct fb_info *info)
202 struct fbcon_ops *ops = info->fbcon_par;
204 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
205 ops->p->con_rotate < 4)
206 ops->rotate = ops->p->con_rotate;
211 static void fbcon_rotate(struct fb_info *info, u32 rotate)
213 struct fbcon_ops *ops= info->fbcon_par;
214 struct fb_info *fb_info;
216 if (!ops || ops->currcon == -1)
219 fb_info = registered_fb[con2fb_map[ops->currcon]];
221 if (info == fb_info) {
222 struct fbcon_display *p = &fb_display[ops->currcon];
225 p->con_rotate = rotate;
229 fbcon_modechanged(info);
233 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
235 struct fbcon_ops *ops = info->fbcon_par;
237 struct fbcon_display *p;
240 if (!ops || ops->currcon < 0 || rotate > 3)
243 for (i = first_fb_vc; i <= last_fb_vc; i++) {
245 if (!vc || vc->vc_mode != KD_TEXT ||
246 registered_fb[con2fb_map[i]] != info)
249 p = &fb_display[vc->vc_num];
250 p->con_rotate = rotate;
253 fbcon_set_all_vcs(info);
256 static inline void fbcon_set_rotation(struct fb_info *info)
258 struct fbcon_ops *ops = info->fbcon_par;
260 ops->rotate = FB_ROTATE_UR;
263 static void fbcon_rotate(struct fb_info *info, u32 rotate)
268 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
272 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
274 static int fbcon_get_rotate(struct fb_info *info)
276 struct fbcon_ops *ops = info->fbcon_par;
278 return (ops) ? ops->rotate : 0;
281 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
283 struct fbcon_ops *ops = info->fbcon_par;
285 return (info->state != FBINFO_STATE_RUNNING ||
286 vc->vc_mode != KD_TEXT || ops->graphics);
289 static int get_color(struct vc_data *vc, struct fb_info *info,
292 int depth = fb_get_color_depth(&info->var, &info->fix);
295 if (console_blanked) {
296 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
298 c = vc->vc_video_erase_char & charmask;
302 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
303 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
308 int col = mono_col(info);
310 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
311 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
316 color = (is_fg) ? fg : bg;
321 * Scale down 16-colors to 4 colors. Default 4-color palette
322 * is grayscale. However, simply dividing the values by 4
323 * will not work, as colors 1, 2 and 3 will be scaled-down
324 * to zero rendering them invisible. So empirically convert
325 * colors to a sane 4-level grayscale.
329 color = 0; /* black */
332 color = 2; /* white */
335 color = 1; /* gray */
338 color = 3; /* intense white */
344 * Last 8 entries of default 16-color palette is a more intense
345 * version of the first 8 (i.e., same chrominance, different
356 static void fbcon_update_softback(struct vc_data *vc)
358 int l = fbcon_softback_size / vc->vc_size_row;
361 softback_end = softback_buf + l * vc->vc_size_row;
363 /* Smaller scrollback makes no sense, and 0 would screw
364 the operation totally */
368 static void fb_flashcursor(struct work_struct *work)
370 struct fb_info *info = container_of(work, struct fb_info, queue);
371 struct fbcon_ops *ops = info->fbcon_par;
372 struct vc_data *vc = NULL;
377 /* FIXME: we should sort out the unbind locking instead */
378 /* instead we just fail to flash the cursor if we can't get
379 * the lock instead of blocking fbcon deinit */
380 ret = console_trylock();
384 if (ops && ops->currcon != -1)
385 vc = vc_cons[ops->currcon].d;
387 if (!vc || !con_is_visible(vc) ||
388 registered_fb[con2fb_map[vc->vc_num]] != info ||
394 c = scr_readw((u16 *) vc->vc_pos);
395 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
397 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
398 get_color(vc, info, c, 0));
402 static void cursor_timer_handler(struct timer_list *t)
404 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
405 struct fb_info *info = ops->info;
407 queue_work(system_power_efficient_wq, &info->queue);
408 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
411 static void fbcon_add_cursor_timer(struct fb_info *info)
413 struct fbcon_ops *ops = info->fbcon_par;
415 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
416 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
417 !fbcon_cursor_noblink) {
418 if (!info->queue.func)
419 INIT_WORK(&info->queue, fb_flashcursor);
421 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
422 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
423 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
427 static void fbcon_del_cursor_timer(struct fb_info *info)
429 struct fbcon_ops *ops = info->fbcon_par;
431 if (info->queue.func == fb_flashcursor &&
432 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
433 del_timer_sync(&ops->cursor_timer);
434 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
439 static int __init fb_console_setup(char *this_opt)
444 if (!this_opt || !*this_opt)
447 while ((options = strsep(&this_opt, ",")) != NULL) {
448 if (!strncmp(options, "font:", 5)) {
449 strlcpy(fontname, options + 5, sizeof(fontname));
453 if (!strncmp(options, "scrollback:", 11)) {
456 fbcon_softback_size = simple_strtoul(options, &options, 0);
457 if (*options == 'k' || *options == 'K') {
458 fbcon_softback_size *= 1024;
464 if (!strncmp(options, "map:", 4)) {
467 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
471 (options[j++]-'0') % FB_MAX;
474 fbcon_map_override();
479 if (!strncmp(options, "vc:", 3)) {
482 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
485 if (*options++ == '-')
486 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
487 fbcon_is_default = 0;
491 if (!strncmp(options, "rotate:", 7)) {
494 initial_rotation = simple_strtoul(options, &options, 0);
495 if (initial_rotation > 3)
496 initial_rotation = 0;
500 if (!strncmp(options, "margin:", 7)) {
503 margin_color = simple_strtoul(options, &options, 0);
506 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
507 if (!strcmp(options, "nodefer")) {
508 deferred_takeover = false;
513 if (!strncmp(options, "logo-pos:", 9)) {
515 if (!strcmp(options, "center"))
516 fb_center_logo = true;
523 __setup("fbcon=", fb_console_setup);
526 static int search_fb_in_map(int idx)
530 for (i = first_fb_vc; i <= last_fb_vc; i++) {
531 if (con2fb_map[i] == idx)
537 static int search_for_mapped_con(void)
541 for (i = first_fb_vc; i <= last_fb_vc; i++) {
542 if (con2fb_map[i] != -1)
548 static int do_fbcon_takeover(int show_logo)
552 if (!num_registered_fb)
556 logo_shown = FBCON_LOGO_DONTSHOW;
558 for (i = first_fb_vc; i <= last_fb_vc; i++)
559 con2fb_map[i] = info_idx;
561 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
565 for (i = first_fb_vc; i <= last_fb_vc; i++)
569 fbcon_has_console_bind = 1;
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 logo_shown = FBCON_LOGO_DONTSHOW;
582 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
583 int cols, int rows, int new_cols, int new_rows)
585 /* Need to make room for the logo */
586 struct fbcon_ops *ops = info->fbcon_par;
587 int cnt, erase = vc->vc_video_erase_char, step;
588 unsigned short *save = NULL, *r, *q;
591 if (info->fbops->owner) {
592 logo_shown = FBCON_LOGO_DONTSHOW;
597 * remove underline attribute from erase character
598 * if black and white framebuffer.
600 if (fb_get_color_depth(&info->var, &info->fix) == 1)
602 logo_height = fb_prepare_logo(info, ops->rotate);
603 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
604 q = (unsigned short *) (vc->vc_origin +
605 vc->vc_size_row * rows);
606 step = logo_lines * cols;
607 for (r = q - logo_lines * cols; r < q; r++)
608 if (scr_readw(r) != vc->vc_video_erase_char)
610 if (r != q && new_rows >= rows + logo_lines) {
611 save = kmalloc(array3_size(logo_lines, new_cols, 2),
614 int i = cols < new_cols ? cols : new_cols;
615 scr_memsetw(save, erase, logo_lines * new_cols * 2);
617 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
618 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
623 /* We can scroll screen down */
625 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
626 scr_memcpyw(r + step, r, vc->vc_size_row);
631 if (vc->vc_y + logo_lines >= rows)
632 lines = rows - vc->vc_y - 1;
636 vc->vc_pos += lines * vc->vc_size_row;
639 scr_memsetw((unsigned short *) vc->vc_origin,
641 vc->vc_size_row * logo_lines);
643 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
644 fbcon_clear_margins(vc, 0);
649 q = (unsigned short *) (vc->vc_origin +
652 scr_memcpyw(q, save, logo_lines * new_cols * 2);
653 vc->vc_y += logo_lines;
654 vc->vc_pos += logo_lines * vc->vc_size_row;
658 if (logo_shown == FBCON_LOGO_DONTSHOW)
661 if (logo_lines > vc->vc_bottom) {
662 logo_shown = FBCON_LOGO_CANSHOW;
664 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
666 logo_shown = FBCON_LOGO_DRAW;
667 vc->vc_top = logo_lines;
672 #ifdef CONFIG_FB_TILEBLITTING
673 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
675 struct fbcon_ops *ops = info->fbcon_par;
677 ops->p = &fb_display[vc->vc_num];
679 if ((info->flags & FBINFO_MISC_TILEBLITTING))
680 fbcon_set_tileops(vc, info);
682 fbcon_set_rotation(info);
683 fbcon_set_bitops(ops);
687 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
691 if (info->flags & FBINFO_MISC_TILEBLITTING &&
692 info->tileops->fb_get_tilemax(info) < charcount)
698 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
700 struct fbcon_ops *ops = info->fbcon_par;
702 info->flags &= ~FBINFO_MISC_TILEBLITTING;
703 ops->p = &fb_display[vc->vc_num];
704 fbcon_set_rotation(info);
705 fbcon_set_bitops(ops);
708 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
713 #endif /* CONFIG_MISC_TILEBLITTING */
716 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
717 int unit, int oldidx)
719 struct fbcon_ops *ops = NULL;
722 if (!try_module_get(info->fbops->owner))
725 if (!err && info->fbops->fb_open &&
726 info->fbops->fb_open(info, 0))
730 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
736 ops->cur_blink_jiffies = HZ / 5;
738 info->fbcon_par = ops;
741 set_blitting_type(vc, info);
745 con2fb_map[unit] = oldidx;
746 module_put(info->fbops->owner);
752 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
753 struct fb_info *newinfo, int unit,
754 int oldidx, int found)
756 struct fbcon_ops *ops = oldinfo->fbcon_par;
759 if (oldinfo->fbops->fb_release &&
760 oldinfo->fbops->fb_release(oldinfo, 0)) {
761 con2fb_map[unit] = oldidx;
762 if (!found && newinfo->fbops->fb_release)
763 newinfo->fbops->fb_release(newinfo, 0);
765 module_put(newinfo->fbops->owner);
770 fbcon_del_cursor_timer(oldinfo);
771 kfree(ops->cursor_state.mask);
772 kfree(ops->cursor_data);
773 kfree(ops->cursor_src);
774 kfree(ops->fontbuffer);
775 kfree(oldinfo->fbcon_par);
776 oldinfo->fbcon_par = NULL;
777 module_put(oldinfo->fbops->owner);
779 If oldinfo and newinfo are driving the same hardware,
780 the fb_release() method of oldinfo may attempt to
781 restore the hardware state. This will leave the
782 newinfo in an undefined state. Thus, a call to
783 fb_set_par() may be needed for the newinfo.
785 if (newinfo && newinfo->fbops->fb_set_par) {
786 ret = newinfo->fbops->fb_set_par(newinfo);
789 printk(KERN_ERR "con2fb_release_oldinfo: "
790 "detected unhandled fb_set_par error, "
791 "error code %d\n", ret);
798 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
799 int unit, int show_logo)
801 struct fbcon_ops *ops = info->fbcon_par;
804 ops->currcon = fg_console;
806 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
807 ret = info->fbops->fb_set_par(info);
810 printk(KERN_ERR "con2fb_init_display: detected "
811 "unhandled fb_set_par error, "
812 "error code %d\n", ret);
815 ops->flags |= FBCON_FLAGS_INIT;
817 fbcon_set_disp(info, &info->var, unit);
820 struct vc_data *fg_vc = vc_cons[fg_console].d;
821 struct fb_info *fg_info =
822 registered_fb[con2fb_map[fg_console]];
824 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
825 fg_vc->vc_rows, fg_vc->vc_cols,
829 update_screen(vc_cons[fg_console].d);
833 * set_con2fb_map - map console to frame buffer device
834 * @unit: virtual console number to map
835 * @newidx: frame buffer index to map virtual console to
836 * @user: user request
838 * Maps a virtual console @unit to a frame buffer device
841 * This should be called with the console lock held.
843 static int set_con2fb_map(int unit, int newidx, int user)
845 struct vc_data *vc = vc_cons[unit].d;
846 int oldidx = con2fb_map[unit];
847 struct fb_info *info = registered_fb[newidx];
848 struct fb_info *oldinfo = NULL;
851 WARN_CONSOLE_UNLOCKED();
853 if (oldidx == newidx)
859 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
861 return do_fbcon_takeover(0);
865 oldinfo = registered_fb[oldidx];
867 found = search_fb_in_map(newidx);
869 con2fb_map[unit] = newidx;
871 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
875 * If old fb is not mapped to any of the consoles,
876 * fbcon should release it.
878 if (!err && oldinfo && !search_fb_in_map(oldidx))
879 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
883 int show_logo = (fg_console == 0 && !user &&
884 logo_shown != FBCON_LOGO_DONTSHOW);
887 fbcon_add_cursor_timer(info);
888 con2fb_map_boot[unit] = newidx;
889 con2fb_init_display(vc, info, unit, show_logo);
892 if (!search_fb_in_map(info_idx))
899 * Low Level Operations
901 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
902 static int var_to_display(struct fbcon_display *disp,
903 struct fb_var_screeninfo *var,
904 struct fb_info *info)
906 disp->xres_virtual = var->xres_virtual;
907 disp->yres_virtual = var->yres_virtual;
908 disp->bits_per_pixel = var->bits_per_pixel;
909 disp->grayscale = var->grayscale;
910 disp->nonstd = var->nonstd;
911 disp->accel_flags = var->accel_flags;
912 disp->height = var->height;
913 disp->width = var->width;
914 disp->red = var->red;
915 disp->green = var->green;
916 disp->blue = var->blue;
917 disp->transp = var->transp;
918 disp->rotate = var->rotate;
919 disp->mode = fb_match_mode(var, &info->modelist);
920 if (disp->mode == NULL)
921 /* This should not happen */
926 static void display_to_var(struct fb_var_screeninfo *var,
927 struct fbcon_display *disp)
929 fb_videomode_to_var(var, disp->mode);
930 var->xres_virtual = disp->xres_virtual;
931 var->yres_virtual = disp->yres_virtual;
932 var->bits_per_pixel = disp->bits_per_pixel;
933 var->grayscale = disp->grayscale;
934 var->nonstd = disp->nonstd;
935 var->accel_flags = disp->accel_flags;
936 var->height = disp->height;
937 var->width = disp->width;
938 var->red = disp->red;
939 var->green = disp->green;
940 var->blue = disp->blue;
941 var->transp = disp->transp;
942 var->rotate = disp->rotate;
945 static const char *fbcon_startup(void)
947 const char *display_desc = "frame buffer device";
948 struct fbcon_display *p = &fb_display[fg_console];
949 struct vc_data *vc = vc_cons[fg_console].d;
950 const struct font_desc *font = NULL;
951 struct module *owner;
952 struct fb_info *info = NULL;
953 struct fbcon_ops *ops;
957 * If num_registered_fb is zero, this is a call for the dummy part.
958 * The frame buffer devices weren't initialized yet.
960 if (!num_registered_fb || info_idx == -1)
963 * Instead of blindly using registered_fb[0], we use info_idx, set by
966 info = registered_fb[info_idx];
970 owner = info->fbops->owner;
971 if (!try_module_get(owner))
973 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
978 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
986 ops->cur_rotate = -1;
987 ops->cur_blink_jiffies = HZ / 5;
989 info->fbcon_par = ops;
991 p->con_rotate = initial_rotation;
992 if (p->con_rotate == -1)
993 p->con_rotate = info->fbcon_rotate_hint;
994 if (p->con_rotate == -1)
995 p->con_rotate = FB_ROTATE_UR;
997 set_blitting_type(vc, info);
999 if (info->fix.type != FB_TYPE_TEXT) {
1000 if (fbcon_softback_size) {
1001 if (!softback_buf) {
1004 kvmalloc(fbcon_softback_size,
1006 if (!softback_buf) {
1007 fbcon_softback_size = 0;
1013 kvfree((void *) softback_buf);
1019 softback_in = softback_top = softback_curr =
1024 /* Setup default font */
1025 if (!p->fontdata && !vc->vc_font.data) {
1026 if (!fontname[0] || !(font = find_font(fontname)))
1027 font = get_default_font(info->var.xres,
1029 info->pixmap.blit_x,
1030 info->pixmap.blit_y);
1031 vc->vc_font.width = font->width;
1032 vc->vc_font.height = font->height;
1033 vc->vc_font.data = (void *)(p->fontdata = font->data);
1034 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1036 p->fontdata = vc->vc_font.data;
1039 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1040 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1041 cols /= vc->vc_font.width;
1042 rows /= vc->vc_font.height;
1043 vc_resize(vc, cols, rows);
1045 DPRINTK("mode: %s\n", info->fix.id);
1046 DPRINTK("visual: %d\n", info->fix.visual);
1047 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1049 info->var.bits_per_pixel);
1051 fbcon_add_cursor_timer(info);
1052 return display_desc;
1055 static void fbcon_init(struct vc_data *vc, int init)
1057 struct fb_info *info;
1058 struct fbcon_ops *ops;
1059 struct vc_data **default_mode = vc->vc_display_fg;
1060 struct vc_data *svc = *default_mode;
1061 struct fbcon_display *t, *p = &fb_display[vc->vc_num];
1062 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1065 if (WARN_ON(info_idx == -1))
1068 if (con2fb_map[vc->vc_num] == -1)
1069 con2fb_map[vc->vc_num] = info_idx;
1071 info = registered_fb[con2fb_map[vc->vc_num]];
1074 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1075 logo_shown = FBCON_LOGO_DONTSHOW;
1077 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1078 (info->fix.type == FB_TYPE_TEXT))
1081 if (var_to_display(p, &info->var, info))
1084 if (!info->fbcon_par)
1085 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1087 /* If we are not the first console on this
1088 fb, copy the font from that console */
1089 t = &fb_display[fg_console];
1092 struct vc_data *fvc = vc_cons[fg_console].d;
1094 vc->vc_font.data = (void *)(p->fontdata =
1096 vc->vc_font.width = fvc->vc_font.width;
1097 vc->vc_font.height = fvc->vc_font.height;
1098 p->userfont = t->userfont;
1101 REFCOUNT(p->fontdata)++;
1103 const struct font_desc *font = NULL;
1105 if (!fontname[0] || !(font = find_font(fontname)))
1106 font = get_default_font(info->var.xres,
1108 info->pixmap.blit_x,
1109 info->pixmap.blit_y);
1110 vc->vc_font.width = font->width;
1111 vc->vc_font.height = font->height;
1112 vc->vc_font.data = (void *)(p->fontdata = font->data);
1113 vc->vc_font.charcount = 256; /* FIXME Need to
1114 support more fonts */
1119 charcnt = FNTCHARCNT(p->fontdata);
1121 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1122 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1123 if (charcnt == 256) {
1124 vc->vc_hi_font_mask = 0;
1126 vc->vc_hi_font_mask = 0x100;
1127 if (vc->vc_can_do_color)
1128 vc->vc_complement_mask <<= 1;
1131 if (!*svc->vc_uni_pagedir_loc)
1132 con_set_default_unimap(svc);
1133 if (!*vc->vc_uni_pagedir_loc)
1134 con_copy_unimap(vc, svc);
1136 ops = info->fbcon_par;
1137 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1139 p->con_rotate = initial_rotation;
1140 if (p->con_rotate == -1)
1141 p->con_rotate = info->fbcon_rotate_hint;
1142 if (p->con_rotate == -1)
1143 p->con_rotate = FB_ROTATE_UR;
1145 set_blitting_type(vc, info);
1149 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1150 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1151 new_cols /= vc->vc_font.width;
1152 new_rows /= vc->vc_font.height;
1155 * We must always set the mode. The mode of the previous console
1156 * driver could be in the same resolution but we are using different
1157 * hardware so we have to initialize the hardware.
1159 * We need to do it in fbcon_init() to prevent screen corruption.
1161 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1162 if (info->fbops->fb_set_par &&
1163 !(ops->flags & FBCON_FLAGS_INIT)) {
1164 ret = info->fbops->fb_set_par(info);
1167 printk(KERN_ERR "fbcon_init: detected "
1168 "unhandled fb_set_par error, "
1169 "error code %d\n", ret);
1172 ops->flags |= FBCON_FLAGS_INIT;
1177 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1178 !(cap & FBINFO_HWACCEL_DISABLED))
1179 p->scrollmode = SCROLL_MOVE;
1180 else /* default to something safe */
1181 p->scrollmode = SCROLL_REDRAW;
1184 * ++guenther: console.c:vc_allocate() relies on initializing
1185 * vc_{cols,rows}, but we must not set those if we are only
1186 * resizing the console.
1189 vc->vc_cols = new_cols;
1190 vc->vc_rows = new_rows;
1192 vc_resize(vc, new_cols, new_rows);
1195 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1197 if (vc == svc && softback_buf)
1198 fbcon_update_softback(vc);
1200 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1201 ops->rotate = FB_ROTATE_UR;
1202 set_blitting_type(vc, info);
1205 ops->p = &fb_display[fg_console];
1208 static void fbcon_free_font(struct fbcon_display *p, bool freefont)
1210 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1211 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1216 static void set_vc_hi_font(struct vc_data *vc, bool set);
1218 static void fbcon_deinit(struct vc_data *vc)
1220 struct fbcon_display *p = &fb_display[vc->vc_num];
1221 struct fb_info *info;
1222 struct fbcon_ops *ops;
1224 bool free_font = true;
1226 idx = con2fb_map[vc->vc_num];
1231 info = registered_fb[idx];
1236 if (info->flags & FBINFO_MISC_FIRMWARE)
1238 ops = info->fbcon_par;
1243 if (con_is_visible(vc))
1244 fbcon_del_cursor_timer(info);
1246 ops->flags &= ~FBCON_FLAGS_INIT;
1249 fbcon_free_font(p, free_font);
1251 vc->vc_font.data = NULL;
1253 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1254 set_vc_hi_font(vc, false);
1256 if (!con_is_bound(&fb_con))
1262 /* ====================================================================== */
1264 /* fbcon_XXX routines - interface used by the world
1266 * This system is now divided into two levels because of complications
1267 * caused by hardware scrolling. Top level functions:
1269 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1271 * handles y values in range [0, scr_height-1] that correspond to real
1272 * screen positions. y_wrap shift means that first line of bitmap may be
1273 * anywhere on this display. These functions convert lineoffsets to
1274 * bitmap offsets and deal with the wrap-around case by splitting blits.
1276 * fbcon_bmove_physical_8() -- These functions fast implementations
1277 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1278 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1282 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1283 * Implies should only really hardware scroll in rows. Only reason for
1284 * restriction is simplicity & efficiency at the moment.
1287 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1290 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1291 struct fbcon_ops *ops = info->fbcon_par;
1293 struct fbcon_display *p = &fb_display[vc->vc_num];
1296 if (fbcon_is_inactive(vc, info))
1299 if (!height || !width)
1302 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1305 * If the font dimensions are not an integral of the display
1306 * dimensions then the ops->clear below won't end up clearing
1307 * the margins. Call clear_margins here in case the logo
1308 * bitmap stretched into the margin area.
1310 fbcon_clear_margins(vc, 0);
1313 /* Split blits that cross physical y_wrap boundary */
1315 y_break = p->vrows - p->yscroll;
1316 if (sy < y_break && sy + height - 1 >= y_break) {
1317 u_int b = y_break - sy;
1318 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1319 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1322 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1325 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1326 int count, int ypos, int xpos)
1328 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1329 struct fbcon_display *p = &fb_display[vc->vc_num];
1330 struct fbcon_ops *ops = info->fbcon_par;
1332 if (!fbcon_is_inactive(vc, info))
1333 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1334 get_color(vc, info, scr_readw(s), 1),
1335 get_color(vc, info, scr_readw(s), 0));
1338 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1342 scr_writew(c, &chr);
1343 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1346 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1348 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1349 struct fbcon_ops *ops = info->fbcon_par;
1351 if (!fbcon_is_inactive(vc, info))
1352 ops->clear_margins(vc, info, margin_color, bottom_only);
1355 static void fbcon_cursor(struct vc_data *vc, int mode)
1357 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1358 struct fbcon_ops *ops = info->fbcon_par;
1360 int c = scr_readw((u16 *) vc->vc_pos);
1362 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1364 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1367 if (vc->vc_cursor_type & 0x10)
1368 fbcon_del_cursor_timer(info);
1370 fbcon_add_cursor_timer(info);
1372 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1373 if (mode & CM_SOFTBACK) {
1374 mode &= ~CM_SOFTBACK;
1378 fbcon_set_origin(vc);
1382 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1383 get_color(vc, info, c, 0));
1386 static int scrollback_phys_max = 0;
1387 static int scrollback_max = 0;
1388 static int scrollback_current = 0;
1390 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1393 struct fbcon_display *p, *t;
1394 struct vc_data **default_mode, *vc;
1395 struct vc_data *svc;
1396 struct fbcon_ops *ops = info->fbcon_par;
1397 int rows, cols, charcnt = 256;
1399 p = &fb_display[unit];
1401 if (var_to_display(p, var, info))
1404 vc = vc_cons[unit].d;
1409 default_mode = vc->vc_display_fg;
1410 svc = *default_mode;
1411 t = &fb_display[svc->vc_num];
1413 if (!vc->vc_font.data) {
1414 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1415 vc->vc_font.width = (*default_mode)->vc_font.width;
1416 vc->vc_font.height = (*default_mode)->vc_font.height;
1417 p->userfont = t->userfont;
1419 REFCOUNT(p->fontdata)++;
1422 charcnt = FNTCHARCNT(p->fontdata);
1424 var->activate = FB_ACTIVATE_NOW;
1425 info->var.activate = var->activate;
1426 var->yoffset = info->var.yoffset;
1427 var->xoffset = info->var.xoffset;
1428 fb_set_var(info, var);
1429 ops->var = info->var;
1430 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1431 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1432 if (charcnt == 256) {
1433 vc->vc_hi_font_mask = 0;
1435 vc->vc_hi_font_mask = 0x100;
1436 if (vc->vc_can_do_color)
1437 vc->vc_complement_mask <<= 1;
1440 if (!*svc->vc_uni_pagedir_loc)
1441 con_set_default_unimap(svc);
1442 if (!*vc->vc_uni_pagedir_loc)
1443 con_copy_unimap(vc, svc);
1445 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1446 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1447 cols /= vc->vc_font.width;
1448 rows /= vc->vc_font.height;
1449 vc_resize(vc, cols, rows);
1451 if (con_is_visible(vc)) {
1454 fbcon_update_softback(vc);
1458 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1460 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1461 struct fbcon_ops *ops = info->fbcon_par;
1462 struct fbcon_display *p = &fb_display[vc->vc_num];
1464 p->yscroll += count;
1465 if (p->yscroll >= p->vrows) /* Deal with wrap */
1466 p->yscroll -= p->vrows;
1467 ops->var.xoffset = 0;
1468 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1469 ops->var.vmode |= FB_VMODE_YWRAP;
1470 ops->update_start(info);
1471 scrollback_max += count;
1472 if (scrollback_max > scrollback_phys_max)
1473 scrollback_max = scrollback_phys_max;
1474 scrollback_current = 0;
1477 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1479 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1480 struct fbcon_ops *ops = info->fbcon_par;
1481 struct fbcon_display *p = &fb_display[vc->vc_num];
1483 p->yscroll -= count;
1484 if (p->yscroll < 0) /* Deal with wrap */
1485 p->yscroll += p->vrows;
1486 ops->var.xoffset = 0;
1487 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1488 ops->var.vmode |= FB_VMODE_YWRAP;
1489 ops->update_start(info);
1490 scrollback_max -= count;
1491 if (scrollback_max < 0)
1493 scrollback_current = 0;
1496 static __inline__ void ypan_up(struct vc_data *vc, int count)
1498 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1499 struct fbcon_display *p = &fb_display[vc->vc_num];
1500 struct fbcon_ops *ops = info->fbcon_par;
1502 p->yscroll += count;
1503 if (p->yscroll > p->vrows - vc->vc_rows) {
1504 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1505 0, 0, 0, vc->vc_rows, vc->vc_cols);
1506 p->yscroll -= p->vrows - vc->vc_rows;
1509 ops->var.xoffset = 0;
1510 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1511 ops->var.vmode &= ~FB_VMODE_YWRAP;
1512 ops->update_start(info);
1513 fbcon_clear_margins(vc, 1);
1514 scrollback_max += count;
1515 if (scrollback_max > scrollback_phys_max)
1516 scrollback_max = scrollback_phys_max;
1517 scrollback_current = 0;
1520 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1522 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1523 struct fbcon_ops *ops = info->fbcon_par;
1524 struct fbcon_display *p = &fb_display[vc->vc_num];
1526 p->yscroll += count;
1528 if (p->yscroll > p->vrows - vc->vc_rows) {
1529 p->yscroll -= p->vrows - vc->vc_rows;
1530 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1533 ops->var.xoffset = 0;
1534 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1535 ops->var.vmode &= ~FB_VMODE_YWRAP;
1536 ops->update_start(info);
1537 fbcon_clear_margins(vc, 1);
1538 scrollback_max += count;
1539 if (scrollback_max > scrollback_phys_max)
1540 scrollback_max = scrollback_phys_max;
1541 scrollback_current = 0;
1544 static __inline__ void ypan_down(struct vc_data *vc, int count)
1546 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1547 struct fbcon_display *p = &fb_display[vc->vc_num];
1548 struct fbcon_ops *ops = info->fbcon_par;
1550 p->yscroll -= count;
1551 if (p->yscroll < 0) {
1552 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1553 0, vc->vc_rows, vc->vc_cols);
1554 p->yscroll += p->vrows - vc->vc_rows;
1557 ops->var.xoffset = 0;
1558 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1559 ops->var.vmode &= ~FB_VMODE_YWRAP;
1560 ops->update_start(info);
1561 fbcon_clear_margins(vc, 1);
1562 scrollback_max -= count;
1563 if (scrollback_max < 0)
1565 scrollback_current = 0;
1568 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1570 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1571 struct fbcon_ops *ops = info->fbcon_par;
1572 struct fbcon_display *p = &fb_display[vc->vc_num];
1574 p->yscroll -= count;
1576 if (p->yscroll < 0) {
1577 p->yscroll += p->vrows - vc->vc_rows;
1578 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1581 ops->var.xoffset = 0;
1582 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1583 ops->var.vmode &= ~FB_VMODE_YWRAP;
1584 ops->update_start(info);
1585 fbcon_clear_margins(vc, 1);
1586 scrollback_max -= count;
1587 if (scrollback_max < 0)
1589 scrollback_current = 0;
1592 static void fbcon_redraw_softback(struct vc_data *vc, struct fbcon_display *p,
1595 int count = vc->vc_rows;
1596 unsigned short *d, *s;
1600 d = (u16 *) softback_curr;
1601 if (d == (u16 *) softback_in)
1602 d = (u16 *) vc->vc_origin;
1603 n = softback_curr + delta * vc->vc_size_row;
1604 softback_lines -= delta;
1606 if (softback_curr < softback_top && n < softback_buf) {
1607 n += softback_end - softback_buf;
1608 if (n < softback_top) {
1610 (softback_top - n) / vc->vc_size_row;
1613 } else if (softback_curr >= softback_top
1614 && n < softback_top) {
1616 (softback_top - n) / vc->vc_size_row;
1620 if (softback_curr > softback_in && n >= softback_end) {
1621 n += softback_buf - softback_end;
1622 if (n > softback_in) {
1626 } else if (softback_curr <= softback_in && n > softback_in) {
1631 if (n == softback_curr)
1634 s = (u16 *) softback_curr;
1635 if (s == (u16 *) softback_in)
1636 s = (u16 *) vc->vc_origin;
1638 unsigned short *start;
1642 unsigned short attr = 1;
1645 le = advance_row(s, 1);
1648 if (attr != (c & 0xff00)) {
1651 fbcon_putcs(vc, start, s - start,
1657 if (c == scr_readw(d)) {
1659 fbcon_putcs(vc, start, s - start,
1672 fbcon_putcs(vc, start, s - start, line, x);
1674 if (d == (u16 *) softback_end)
1675 d = (u16 *) softback_buf;
1676 if (d == (u16 *) softback_in)
1677 d = (u16 *) vc->vc_origin;
1678 if (s == (u16 *) softback_end)
1679 s = (u16 *) softback_buf;
1680 if (s == (u16 *) softback_in)
1681 s = (u16 *) vc->vc_origin;
1685 static void fbcon_redraw_move(struct vc_data *vc, struct fbcon_display *p,
1686 int line, int count, int dy)
1688 unsigned short *s = (unsigned short *)
1689 (vc->vc_origin + vc->vc_size_row * line);
1692 unsigned short *start = s;
1693 unsigned short *le = advance_row(s, 1);
1696 unsigned short attr = 1;
1700 if (attr != (c & 0xff00)) {
1703 fbcon_putcs(vc, start, s - start,
1709 console_conditional_schedule();
1713 fbcon_putcs(vc, start, s - start, dy, x);
1714 console_conditional_schedule();
1719 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1720 struct fbcon_display *p, int line, int count, int ycount)
1722 int offset = ycount * vc->vc_cols;
1723 unsigned short *d = (unsigned short *)
1724 (vc->vc_origin + vc->vc_size_row * line);
1725 unsigned short *s = d + offset;
1726 struct fbcon_ops *ops = info->fbcon_par;
1729 unsigned short *start = s;
1730 unsigned short *le = advance_row(s, 1);
1737 if (c == scr_readw(d)) {
1739 ops->bmove(vc, info, line + ycount, x,
1740 line, x, 1, s-start);
1750 console_conditional_schedule();
1755 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1757 console_conditional_schedule();
1762 /* NOTE: We subtract two lines from these pointers */
1763 s -= vc->vc_size_row;
1764 d -= vc->vc_size_row;
1769 static void fbcon_redraw(struct vc_data *vc, struct fbcon_display *p,
1770 int line, int count, int offset)
1772 unsigned short *d = (unsigned short *)
1773 (vc->vc_origin + vc->vc_size_row * line);
1774 unsigned short *s = d + offset;
1777 unsigned short *start = s;
1778 unsigned short *le = advance_row(s, 1);
1781 unsigned short attr = 1;
1785 if (attr != (c & 0xff00)) {
1788 fbcon_putcs(vc, start, s - start,
1794 if (c == scr_readw(d)) {
1796 fbcon_putcs(vc, start, s - start,
1806 console_conditional_schedule();
1811 fbcon_putcs(vc, start, s - start, line, x);
1812 console_conditional_schedule();
1817 /* NOTE: We subtract two lines from these pointers */
1818 s -= vc->vc_size_row;
1819 d -= vc->vc_size_row;
1824 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1829 if (vc->vc_num != fg_console)
1831 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1834 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1836 p = advance_row(p, 1);
1837 softback_in += vc->vc_size_row;
1838 if (softback_in == softback_end)
1839 softback_in = softback_buf;
1840 if (softback_in == softback_top) {
1841 softback_top += vc->vc_size_row;
1842 if (softback_top == softback_end)
1843 softback_top = softback_buf;
1846 softback_curr = softback_in;
1849 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1850 enum con_scroll dir, unsigned int count)
1852 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1853 struct fbcon_display *p = &fb_display[vc->vc_num];
1854 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1856 if (fbcon_is_inactive(vc, info))
1859 fbcon_cursor(vc, CM_ERASE);
1862 * ++Geert: Only use ywrap/ypan if the console is in text mode
1863 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1864 * whole screen (prevents flicker).
1869 if (count > vc->vc_rows) /* Maximum realistic size */
1870 count = vc->vc_rows;
1872 fbcon_softback_note(vc, t, count);
1873 if (logo_shown >= 0)
1875 switch (p->scrollmode) {
1877 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1879 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1880 scr_memsetw((unsigned short *) (vc->vc_origin +
1883 vc->vc_video_erase_char,
1884 vc->vc_size_row * count);
1888 case SCROLL_WRAP_MOVE:
1889 if (b - t - count > 3 * vc->vc_rows >> 2) {
1891 fbcon_bmove(vc, 0, 0, count, 0, t,
1893 ywrap_up(vc, count);
1894 if (vc->vc_rows - b > 0)
1895 fbcon_bmove(vc, b - count, 0, b, 0,
1898 } else if (info->flags & FBINFO_READS_FAST)
1899 fbcon_bmove(vc, t + count, 0, t, 0,
1900 b - t - count, vc->vc_cols);
1903 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1906 case SCROLL_PAN_REDRAW:
1907 if ((p->yscroll + count <=
1908 2 * (p->vrows - vc->vc_rows))
1909 && ((!scroll_partial && (b - t == vc->vc_rows))
1912 3 * vc->vc_rows >> 2)))) {
1914 fbcon_redraw_move(vc, p, 0, t, count);
1915 ypan_up_redraw(vc, t, count);
1916 if (vc->vc_rows - b > 0)
1917 fbcon_redraw_move(vc, p, b,
1918 vc->vc_rows - b, b);
1920 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1921 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1924 case SCROLL_PAN_MOVE:
1925 if ((p->yscroll + count <=
1926 2 * (p->vrows - vc->vc_rows))
1927 && ((!scroll_partial && (b - t == vc->vc_rows))
1930 3 * vc->vc_rows >> 2)))) {
1932 fbcon_bmove(vc, 0, 0, count, 0, t,
1935 if (vc->vc_rows - b > 0)
1936 fbcon_bmove(vc, b - count, 0, b, 0,
1939 } else if (info->flags & FBINFO_READS_FAST)
1940 fbcon_bmove(vc, t + count, 0, t, 0,
1941 b - t - count, vc->vc_cols);
1944 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1949 fbcon_redraw(vc, p, t, b - t - count,
1950 count * vc->vc_cols);
1951 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1952 scr_memsetw((unsigned short *) (vc->vc_origin +
1955 vc->vc_video_erase_char,
1956 vc->vc_size_row * count);
1962 if (count > vc->vc_rows) /* Maximum realistic size */
1963 count = vc->vc_rows;
1964 if (logo_shown >= 0)
1966 switch (p->scrollmode) {
1968 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1970 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1971 scr_memsetw((unsigned short *) (vc->vc_origin +
1974 vc->vc_video_erase_char,
1975 vc->vc_size_row * count);
1979 case SCROLL_WRAP_MOVE:
1980 if (b - t - count > 3 * vc->vc_rows >> 2) {
1981 if (vc->vc_rows - b > 0)
1982 fbcon_bmove(vc, b, 0, b - count, 0,
1985 ywrap_down(vc, count);
1987 fbcon_bmove(vc, count, 0, 0, 0, t,
1989 } else if (info->flags & FBINFO_READS_FAST)
1990 fbcon_bmove(vc, t, 0, t + count, 0,
1991 b - t - count, vc->vc_cols);
1994 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1997 case SCROLL_PAN_MOVE:
1998 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1999 && ((!scroll_partial && (b - t == vc->vc_rows))
2002 3 * vc->vc_rows >> 2)))) {
2003 if (vc->vc_rows - b > 0)
2004 fbcon_bmove(vc, b, 0, b - count, 0,
2007 ypan_down(vc, count);
2009 fbcon_bmove(vc, count, 0, 0, 0, t,
2011 } else if (info->flags & FBINFO_READS_FAST)
2012 fbcon_bmove(vc, t, 0, t + count, 0,
2013 b - t - count, vc->vc_cols);
2016 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2019 case SCROLL_PAN_REDRAW:
2020 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2021 && ((!scroll_partial && (b - t == vc->vc_rows))
2024 3 * vc->vc_rows >> 2)))) {
2025 if (vc->vc_rows - b > 0)
2026 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2028 ypan_down_redraw(vc, t, count);
2030 fbcon_redraw_move(vc, p, count, t, 0);
2032 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2033 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2038 fbcon_redraw(vc, p, b - 1, b - t - count,
2039 -count * vc->vc_cols);
2040 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2041 scr_memsetw((unsigned short *) (vc->vc_origin +
2044 vc->vc_video_erase_char,
2045 vc->vc_size_row * count);
2053 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2054 int height, int width)
2056 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2057 struct fbcon_display *p = &fb_display[vc->vc_num];
2059 if (fbcon_is_inactive(vc, info))
2062 if (!width || !height)
2065 /* Split blits that cross physical y_wrap case.
2066 * Pathological case involves 4 blits, better to use recursive
2067 * code rather than unrolled case
2069 * Recursive invocations don't need to erase the cursor over and
2070 * over again, so we use fbcon_bmove_rec()
2072 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2073 p->vrows - p->yscroll);
2076 static void fbcon_bmove_rec(struct vc_data *vc, struct fbcon_display *p, int sy, int sx,
2077 int dy, int dx, int height, int width, u_int y_break)
2079 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2080 struct fbcon_ops *ops = info->fbcon_par;
2083 if (sy < y_break && sy + height > y_break) {
2085 if (dy < sy) { /* Avoid trashing self */
2086 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2088 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2089 height - b, width, y_break);
2091 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2092 height - b, width, y_break);
2093 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2099 if (dy < y_break && dy + height > y_break) {
2101 if (dy < sy) { /* Avoid trashing self */
2102 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2104 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2105 height - b, width, y_break);
2107 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2108 height - b, width, y_break);
2109 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2114 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2118 static void updatescrollmode(struct fbcon_display *p,
2119 struct fb_info *info,
2122 struct fbcon_ops *ops = info->fbcon_par;
2123 int fh = vc->vc_font.height;
2124 int cap = info->flags;
2126 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2127 info->fix.xpanstep);
2128 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2129 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2130 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2131 info->var.xres_virtual);
2132 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2133 divides(ypan, vc->vc_font.height) && vyres > yres;
2134 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2135 divides(ywrap, vc->vc_font.height) &&
2136 divides(vc->vc_font.height, vyres) &&
2137 divides(vc->vc_font.height, yres);
2138 int reading_fast = cap & FBINFO_READS_FAST;
2139 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2140 !(cap & FBINFO_HWACCEL_DISABLED);
2141 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2142 !(cap & FBINFO_HWACCEL_DISABLED);
2144 p->vrows = vyres/fh;
2145 if (yres > (fh * (vc->vc_rows + 1)))
2146 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2147 if ((yres % fh) && (vyres % fh < yres % fh))
2150 if (good_wrap || good_pan) {
2151 if (reading_fast || fast_copyarea)
2152 p->scrollmode = good_wrap ?
2153 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2155 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2158 if (reading_fast || (fast_copyarea && !fast_imageblit))
2159 p->scrollmode = SCROLL_MOVE;
2161 p->scrollmode = SCROLL_REDRAW;
2165 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2166 unsigned int height, unsigned int user)
2168 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2169 struct fbcon_ops *ops = info->fbcon_par;
2170 struct fbcon_display *p = &fb_display[vc->vc_num];
2171 struct fb_var_screeninfo var = info->var;
2172 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2174 virt_w = FBCON_SWAP(ops->rotate, width, height);
2175 virt_h = FBCON_SWAP(ops->rotate, height, width);
2176 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2177 vc->vc_font.height);
2178 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2180 var.xres = virt_w * virt_fw;
2181 var.yres = virt_h * virt_fh;
2182 x_diff = info->var.xres - var.xres;
2183 y_diff = info->var.yres - var.yres;
2184 if (x_diff < 0 || x_diff > virt_fw ||
2185 y_diff < 0 || y_diff > virt_fh) {
2186 const struct fb_videomode *mode;
2188 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2189 mode = fb_find_best_mode(&var, &info->modelist);
2192 display_to_var(&var, p);
2193 fb_videomode_to_var(&var, mode);
2195 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2198 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2199 if (con_is_visible(vc)) {
2200 var.activate = FB_ACTIVATE_NOW |
2202 fb_set_var(info, &var);
2204 var_to_display(p, &info->var, info);
2205 ops->var = info->var;
2207 updatescrollmode(p, info, vc);
2211 static int fbcon_switch(struct vc_data *vc)
2213 struct fb_info *info, *old_info = NULL;
2214 struct fbcon_ops *ops;
2215 struct fbcon_display *p = &fb_display[vc->vc_num];
2216 struct fb_var_screeninfo var;
2217 int i, ret, prev_console, charcnt = 256;
2219 info = registered_fb[con2fb_map[vc->vc_num]];
2220 ops = info->fbcon_par;
2224 fbcon_set_origin(vc);
2225 softback_top = softback_curr = softback_in = softback_buf;
2227 fbcon_update_softback(vc);
2230 if (logo_shown >= 0) {
2231 struct vc_data *conp2 = vc_cons[logo_shown].d;
2233 if (conp2->vc_top == logo_lines
2234 && conp2->vc_bottom == conp2->vc_rows)
2236 logo_shown = FBCON_LOGO_CANSHOW;
2239 prev_console = ops->currcon;
2240 if (prev_console != -1)
2241 old_info = registered_fb[con2fb_map[prev_console]];
2243 * FIXME: If we have multiple fbdev's loaded, we need to
2244 * update all info->currcon. Perhaps, we can place this
2245 * in a centralized structure, but this might break some
2248 * info->currcon = vc->vc_num;
2250 for_each_registered_fb(i) {
2251 if (registered_fb[i]->fbcon_par) {
2252 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2254 o->currcon = vc->vc_num;
2257 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2258 display_to_var(&var, p);
2259 var.activate = FB_ACTIVATE_NOW;
2262 * make sure we don't unnecessarily trip the memcmp()
2265 info->var.activate = var.activate;
2266 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2267 fb_set_var(info, &var);
2268 ops->var = info->var;
2270 if (old_info != NULL && (old_info != info ||
2271 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2272 if (info->fbops->fb_set_par) {
2273 ret = info->fbops->fb_set_par(info);
2276 printk(KERN_ERR "fbcon_switch: detected "
2277 "unhandled fb_set_par error, "
2278 "error code %d\n", ret);
2281 if (old_info != info)
2282 fbcon_del_cursor_timer(old_info);
2285 if (fbcon_is_inactive(vc, info) ||
2286 ops->blank_state != FB_BLANK_UNBLANK)
2287 fbcon_del_cursor_timer(info);
2289 fbcon_add_cursor_timer(info);
2291 set_blitting_type(vc, info);
2292 ops->cursor_reset = 1;
2294 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2295 ops->rotate = FB_ROTATE_UR;
2296 set_blitting_type(vc, info);
2299 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2300 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2303 charcnt = FNTCHARCNT(vc->vc_font.data);
2306 vc->vc_complement_mask <<= 1;
2308 updatescrollmode(p, info, vc);
2310 switch (p->scrollmode) {
2311 case SCROLL_WRAP_MOVE:
2312 scrollback_phys_max = p->vrows - vc->vc_rows;
2314 case SCROLL_PAN_MOVE:
2315 case SCROLL_PAN_REDRAW:
2316 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2317 if (scrollback_phys_max < 0)
2318 scrollback_phys_max = 0;
2321 scrollback_phys_max = 0;
2326 scrollback_current = 0;
2328 if (!fbcon_is_inactive(vc, info)) {
2329 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2330 ops->update_start(info);
2333 fbcon_set_palette(vc, color_table);
2334 fbcon_clear_margins(vc, 0);
2336 if (logo_shown == FBCON_LOGO_DRAW) {
2338 logo_shown = fg_console;
2339 /* This is protected above by initmem_freed */
2340 fb_show_logo(info, ops->rotate);
2342 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2343 vc->vc_size_row * (vc->vc_bottom -
2350 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2354 unsigned short charmask = vc->vc_hi_font_mask ?
2356 unsigned short oldc;
2358 oldc = vc->vc_video_erase_char;
2359 vc->vc_video_erase_char &= charmask;
2360 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2361 vc->vc_video_erase_char = oldc;
2365 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2367 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2368 struct fbcon_ops *ops = info->fbcon_par;
2371 struct fb_var_screeninfo var = info->var;
2376 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2377 fb_set_var(info, &var);
2379 ops->var = info->var;
2383 if (!fbcon_is_inactive(vc, info)) {
2384 if (ops->blank_state != blank) {
2385 ops->blank_state = blank;
2386 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2387 ops->cursor_flash = (!blank);
2389 if (fb_blank(info, blank))
2390 fbcon_generic_blank(vc, info, blank);
2397 if (mode_switch || fbcon_is_inactive(vc, info) ||
2398 ops->blank_state != FB_BLANK_UNBLANK)
2399 fbcon_del_cursor_timer(info);
2401 fbcon_add_cursor_timer(info);
2406 static int fbcon_debug_enter(struct vc_data *vc)
2408 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2409 struct fbcon_ops *ops = info->fbcon_par;
2411 ops->save_graphics = ops->graphics;
2413 if (info->fbops->fb_debug_enter)
2414 info->fbops->fb_debug_enter(info);
2415 fbcon_set_palette(vc, color_table);
2419 static int fbcon_debug_leave(struct vc_data *vc)
2421 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2422 struct fbcon_ops *ops = info->fbcon_par;
2424 ops->graphics = ops->save_graphics;
2425 if (info->fbops->fb_debug_leave)
2426 info->fbops->fb_debug_leave(info);
2430 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2432 u8 *fontdata = vc->vc_font.data;
2433 u8 *data = font->data;
2436 font->width = vc->vc_font.width;
2437 font->height = vc->vc_font.height;
2438 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2442 if (font->width <= 8) {
2443 j = vc->vc_font.height;
2444 for (i = 0; i < font->charcount; i++) {
2445 memcpy(data, fontdata, j);
2446 memset(data + j, 0, 32 - j);
2450 } else if (font->width <= 16) {
2451 j = vc->vc_font.height * 2;
2452 for (i = 0; i < font->charcount; i++) {
2453 memcpy(data, fontdata, j);
2454 memset(data + j, 0, 64 - j);
2458 } else if (font->width <= 24) {
2459 for (i = 0; i < font->charcount; i++) {
2460 for (j = 0; j < vc->vc_font.height; j++) {
2461 *data++ = fontdata[0];
2462 *data++ = fontdata[1];
2463 *data++ = fontdata[2];
2464 fontdata += sizeof(u32);
2466 memset(data, 0, 3 * (32 - j));
2467 data += 3 * (32 - j);
2470 j = vc->vc_font.height * 4;
2471 for (i = 0; i < font->charcount; i++) {
2472 memcpy(data, fontdata, j);
2473 memset(data + j, 0, 128 - j);
2481 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2482 static void set_vc_hi_font(struct vc_data *vc, bool set)
2485 vc->vc_hi_font_mask = 0;
2486 if (vc->vc_can_do_color) {
2487 vc->vc_complement_mask >>= 1;
2488 vc->vc_s_complement_mask >>= 1;
2491 /* ++Edmund: reorder the attribute bits */
2492 if (vc->vc_can_do_color) {
2493 unsigned short *cp =
2494 (unsigned short *) vc->vc_origin;
2495 int count = vc->vc_screenbuf_size / 2;
2497 for (; count > 0; count--, cp++) {
2499 scr_writew(((c & 0xfe00) >> 1) |
2502 c = vc->vc_video_erase_char;
2503 vc->vc_video_erase_char =
2504 ((c & 0xfe00) >> 1) | (c & 0xff);
2508 vc->vc_hi_font_mask = 0x100;
2509 if (vc->vc_can_do_color) {
2510 vc->vc_complement_mask <<= 1;
2511 vc->vc_s_complement_mask <<= 1;
2514 /* ++Edmund: reorder the attribute bits */
2516 unsigned short *cp =
2517 (unsigned short *) vc->vc_origin;
2518 int count = vc->vc_screenbuf_size / 2;
2520 for (; count > 0; count--, cp++) {
2521 unsigned short newc;
2523 if (vc->vc_can_do_color)
2525 ((c & 0xff00) << 1) | (c &
2529 scr_writew(newc, cp);
2531 c = vc->vc_video_erase_char;
2532 if (vc->vc_can_do_color) {
2533 vc->vc_video_erase_char =
2534 ((c & 0xff00) << 1) | (c & 0xff);
2537 vc->vc_video_erase_char = c & ~0x100;
2542 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2543 const u8 * data, int userfont)
2545 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2546 struct fbcon_ops *ops = info->fbcon_par;
2547 struct fbcon_display *p = &fb_display[vc->vc_num];
2550 char *old_data = NULL;
2552 if (con_is_visible(vc) && softback_lines)
2553 fbcon_set_origin(vc);
2555 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2557 old_data = vc->vc_font.data;
2559 cnt = FNTCHARCNT(data);
2562 vc->vc_font.data = (void *)(p->fontdata = data);
2563 if ((p->userfont = userfont))
2565 vc->vc_font.width = w;
2566 vc->vc_font.height = h;
2567 if (vc->vc_hi_font_mask && cnt == 256)
2568 set_vc_hi_font(vc, false);
2569 else if (!vc->vc_hi_font_mask && cnt == 512)
2570 set_vc_hi_font(vc, true);
2575 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2576 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2579 vc_resize(vc, cols, rows);
2580 if (con_is_visible(vc) && softback_buf)
2581 fbcon_update_softback(vc);
2582 } else if (con_is_visible(vc)
2583 && vc->vc_mode == KD_TEXT) {
2584 fbcon_clear_margins(vc, 0);
2588 if (old_data && (--REFCOUNT(old_data) == 0))
2589 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2593 static int fbcon_copy_font(struct vc_data *vc, int con)
2595 struct fbcon_display *od = &fb_display[con];
2596 struct console_font *f = &vc->vc_font;
2598 if (od->fontdata == f->data)
2599 return 0; /* already the same font... */
2600 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2604 * User asked to set font; we are guaranteed that
2605 * a) width and height are in range 1..32
2606 * b) charcount does not exceed 512
2607 * but lets not assume that, since someone might someday want to use larger
2608 * fonts. And charcount of 512 is small for unicode support.
2610 * However, user space gives the font in 32 rows , regardless of
2611 * actual font height. So a new API is needed if support for larger fonts
2612 * is ever implemented.
2615 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2618 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2619 unsigned charcount = font->charcount;
2620 int w = font->width;
2621 int h = font->height;
2624 u8 *new_data, *data = font->data;
2625 int pitch = (font->width+7) >> 3;
2627 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2628 * If not this check should be changed to charcount < 256 */
2629 if (charcount != 256 && charcount != 512)
2632 /* Make sure drawing engine can handle the font */
2633 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2634 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2637 /* Make sure driver can handle the font length */
2638 if (fbcon_invalid_charcount(info, charcount))
2641 size = h * pitch * charcount;
2643 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2648 new_data += FONT_EXTRA_WORDS * sizeof(int);
2649 FNTSIZE(new_data) = size;
2650 FNTCHARCNT(new_data) = charcount;
2651 REFCOUNT(new_data) = 0; /* usage counter */
2652 for (i=0; i< charcount; i++) {
2653 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2656 /* Since linux has a nice crc32 function use it for counting font
2658 csum = crc32(0, new_data, size);
2660 FNTSUM(new_data) = csum;
2661 /* Check if the same font is on some other console already */
2662 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2663 struct vc_data *tmp = vc_cons[i].d;
2665 if (fb_display[i].userfont &&
2666 fb_display[i].fontdata &&
2667 FNTSUM(fb_display[i].fontdata) == csum &&
2668 FNTSIZE(fb_display[i].fontdata) == size &&
2669 tmp->vc_font.width == w &&
2670 !memcmp(fb_display[i].fontdata, new_data, size)) {
2671 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2672 new_data = (u8 *)fb_display[i].fontdata;
2676 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2679 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2681 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2682 const struct font_desc *f;
2685 f = get_default_font(info->var.xres, info->var.yres,
2686 info->pixmap.blit_x, info->pixmap.blit_y);
2687 else if (!(f = find_font(name)))
2690 font->width = f->width;
2691 font->height = f->height;
2692 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2695 static u16 palette_red[16];
2696 static u16 palette_green[16];
2697 static u16 palette_blue[16];
2699 static struct fb_cmap palette_cmap = {
2700 0, 16, palette_red, palette_green, palette_blue, NULL
2703 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2705 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2709 if (fbcon_is_inactive(vc, info))
2712 if (!con_is_visible(vc))
2715 depth = fb_get_color_depth(&info->var, &info->fix);
2717 for (i = j = 0; i < 16; i++) {
2719 val = vc->vc_palette[j++];
2720 palette_red[k] = (val << 8) | val;
2721 val = vc->vc_palette[j++];
2722 palette_green[k] = (val << 8) | val;
2723 val = vc->vc_palette[j++];
2724 palette_blue[k] = (val << 8) | val;
2726 palette_cmap.len = 16;
2727 palette_cmap.start = 0;
2729 * If framebuffer is capable of less than 16 colors,
2730 * use default palette of fbcon.
2733 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2735 fb_set_cmap(&palette_cmap, info);
2738 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2743 if (vc->vc_num != fg_console || !softback_lines)
2744 return (u16 *) (vc->vc_origin + offset);
2745 line = offset / vc->vc_size_row;
2746 if (line >= softback_lines)
2747 return (u16 *) (vc->vc_origin + offset -
2748 softback_lines * vc->vc_size_row);
2749 p = softback_curr + offset;
2750 if (p >= softback_end)
2751 p += softback_buf - softback_end;
2755 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2761 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2762 unsigned long offset = (pos - vc->vc_origin) / 2;
2764 x = offset % vc->vc_cols;
2765 y = offset / vc->vc_cols;
2766 if (vc->vc_num == fg_console)
2767 y += softback_lines;
2768 ret = pos + (vc->vc_cols - x) * 2;
2769 } else if (vc->vc_num == fg_console && softback_lines) {
2770 unsigned long offset = pos - softback_curr;
2772 if (pos < softback_curr)
2773 offset += softback_end - softback_buf;
2775 x = offset % vc->vc_cols;
2776 y = offset / vc->vc_cols;
2777 ret = pos + (vc->vc_cols - x) * 2;
2778 if (ret == softback_end)
2780 if (ret == softback_in)
2781 ret = vc->vc_origin;
2783 /* Should not happen */
2785 ret = vc->vc_origin;
2794 /* As we might be inside of softback, we may work with non-contiguous buffer,
2795 that's why we have to use a separate routine. */
2796 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2799 u16 a = scr_readw(p);
2800 if (!vc->vc_can_do_color)
2802 else if (vc->vc_hi_font_mask == 0x100)
2803 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2804 (((a) & 0x0e00) << 4);
2806 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2807 (((a) & 0x0700) << 4);
2809 if (p == (u16 *) softback_end)
2810 p = (u16 *) softback_buf;
2811 if (p == (u16 *) softback_in)
2812 p = (u16 *) vc->vc_origin;
2816 static void fbcon_scrolldelta(struct vc_data *vc, int lines)
2818 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2819 struct fbcon_ops *ops = info->fbcon_par;
2820 struct fbcon_display *disp = &fb_display[fg_console];
2821 int offset, limit, scrollback_old;
2824 if (vc->vc_num != fg_console)
2826 if (vc->vc_mode != KD_TEXT || !lines)
2828 if (logo_shown >= 0) {
2829 struct vc_data *conp2 = vc_cons[logo_shown].d;
2831 if (conp2->vc_top == logo_lines
2832 && conp2->vc_bottom == conp2->vc_rows)
2834 if (logo_shown == vc->vc_num) {
2840 logo_lines * vc->vc_size_row;
2841 for (i = 0; i < logo_lines; i++) {
2842 if (p == softback_top)
2844 if (p == softback_buf)
2846 p -= vc->vc_size_row;
2847 q -= vc->vc_size_row;
2848 scr_memcpyw((u16 *) q, (u16 *) p,
2851 softback_in = softback_curr = p;
2852 update_region(vc, vc->vc_origin,
2853 logo_lines * vc->vc_cols);
2855 logo_shown = FBCON_LOGO_CANSHOW;
2857 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2858 fbcon_redraw_softback(vc, disp, lines);
2859 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2863 if (!scrollback_phys_max)
2866 scrollback_old = scrollback_current;
2867 scrollback_current -= lines;
2868 if (scrollback_current < 0)
2869 scrollback_current = 0;
2870 else if (scrollback_current > scrollback_max)
2871 scrollback_current = scrollback_max;
2872 if (scrollback_current == scrollback_old)
2875 if (fbcon_is_inactive(vc, info))
2878 fbcon_cursor(vc, CM_ERASE);
2880 offset = disp->yscroll - scrollback_current;
2881 limit = disp->vrows;
2882 switch (disp->scrollmode) {
2883 case SCROLL_WRAP_MOVE:
2884 info->var.vmode |= FB_VMODE_YWRAP;
2886 case SCROLL_PAN_MOVE:
2887 case SCROLL_PAN_REDRAW:
2888 limit -= vc->vc_rows;
2889 info->var.vmode &= ~FB_VMODE_YWRAP;
2894 else if (offset >= limit)
2897 ops->var.xoffset = 0;
2898 ops->var.yoffset = offset * vc->vc_font.height;
2899 ops->update_start(info);
2901 if (!scrollback_current)
2902 fbcon_cursor(vc, CM_DRAW);
2905 static int fbcon_set_origin(struct vc_data *vc)
2908 fbcon_scrolldelta(vc, softback_lines);
2912 void fbcon_suspended(struct fb_info *info)
2914 struct vc_data *vc = NULL;
2915 struct fbcon_ops *ops = info->fbcon_par;
2917 if (!ops || ops->currcon < 0)
2919 vc = vc_cons[ops->currcon].d;
2921 /* Clear cursor, restore saved data */
2922 fbcon_cursor(vc, CM_ERASE);
2925 void fbcon_resumed(struct fb_info *info)
2928 struct fbcon_ops *ops = info->fbcon_par;
2930 if (!ops || ops->currcon < 0)
2932 vc = vc_cons[ops->currcon].d;
2937 static void fbcon_modechanged(struct fb_info *info)
2939 struct fbcon_ops *ops = info->fbcon_par;
2941 struct fbcon_display *p;
2944 if (!ops || ops->currcon < 0)
2946 vc = vc_cons[ops->currcon].d;
2947 if (vc->vc_mode != KD_TEXT ||
2948 registered_fb[con2fb_map[ops->currcon]] != info)
2951 p = &fb_display[vc->vc_num];
2952 set_blitting_type(vc, info);
2954 if (con_is_visible(vc)) {
2955 var_to_display(p, &info->var, info);
2956 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2957 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2958 cols /= vc->vc_font.width;
2959 rows /= vc->vc_font.height;
2960 vc_resize(vc, cols, rows);
2961 updatescrollmode(p, info, vc);
2963 scrollback_current = 0;
2965 if (!fbcon_is_inactive(vc, info)) {
2966 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2967 ops->update_start(info);
2970 fbcon_set_palette(vc, color_table);
2973 fbcon_update_softback(vc);
2977 static void fbcon_set_all_vcs(struct fb_info *info)
2979 struct fbcon_ops *ops = info->fbcon_par;
2981 struct fbcon_display *p;
2982 int i, rows, cols, fg = -1;
2984 if (!ops || ops->currcon < 0)
2987 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2989 if (!vc || vc->vc_mode != KD_TEXT ||
2990 registered_fb[con2fb_map[i]] != info)
2993 if (con_is_visible(vc)) {
2998 p = &fb_display[vc->vc_num];
2999 set_blitting_type(vc, info);
3000 var_to_display(p, &info->var, info);
3001 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3002 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3003 cols /= vc->vc_font.width;
3004 rows /= vc->vc_font.height;
3005 vc_resize(vc, cols, rows);
3009 fbcon_modechanged(info);
3012 int fbcon_mode_deleted(struct fb_info *info,
3013 struct fb_videomode *mode)
3015 struct fb_info *fb_info;
3016 struct fbcon_display *p;
3017 int i, j, found = 0;
3019 /* before deletion, ensure that mode is not in use */
3020 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3024 fb_info = registered_fb[j];
3025 if (fb_info != info)
3030 if (fb_mode_is_equal(p->mode, mode)) {
3038 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3039 static void fbcon_unbind(void)
3043 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3047 fbcon_has_console_bind = 0;
3050 static inline void fbcon_unbind(void) {}
3051 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3053 /* called with console_lock held */
3054 void fbcon_fb_unbind(struct fb_info *info)
3056 int i, new_idx = -1, ret = 0;
3057 int idx = info->node;
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) {
3067 new_idx = con2fb_map[i];
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;
3104 /* called with console_lock held */
3105 void fbcon_fb_unregistered(struct fb_info *info)
3109 WARN_CONSOLE_UNLOCKED();
3111 if (deferred_takeover)
3115 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3116 if (con2fb_map[i] == idx)
3120 if (idx == info_idx) {
3123 for_each_registered_fb(i) {
3129 if (info_idx != -1) {
3130 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3131 if (con2fb_map[i] == -1)
3132 con2fb_map[i] = info_idx;
3136 if (primary_device == idx)
3137 primary_device = -1;
3139 if (!num_registered_fb)
3140 do_unregister_con_driver(&fb_con);
3143 /* called with console_lock held */
3144 static void fbcon_remap_all(int idx)
3148 WARN_CONSOLE_UNLOCKED();
3150 if (deferred_takeover) {
3151 for (i = first_fb_vc; i <= last_fb_vc; i++)
3152 con2fb_map_boot[i] = idx;
3153 fbcon_map_override();
3157 for (i = first_fb_vc; i <= last_fb_vc; i++)
3158 set_con2fb_map(i, idx, 0);
3160 if (con_is_bound(&fb_con)) {
3161 printk(KERN_INFO "fbcon: Remapping primary device, "
3162 "fb%i, to tty %i-%i\n", idx,
3163 first_fb_vc + 1, last_fb_vc + 1);
3168 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3169 static void fbcon_select_primary(struct fb_info *info)
3171 if (!map_override && primary_device == -1 &&
3172 fb_is_primary_device(info)) {
3175 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3176 info->fix.id, info->node);
3177 primary_device = info->node;
3179 for (i = first_fb_vc; i <= last_fb_vc; i++)
3180 con2fb_map_boot[i] = primary_device;
3182 if (con_is_bound(&fb_con)) {
3183 printk(KERN_INFO "fbcon: Remapping primary device, "
3184 "fb%i, to tty %i-%i\n", info->node,
3185 first_fb_vc + 1, last_fb_vc + 1);
3186 info_idx = primary_device;
3192 static inline void fbcon_select_primary(struct fb_info *info)
3196 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3198 /* called with console_lock held */
3199 int fbcon_fb_registered(struct fb_info *info)
3201 int ret = 0, i, idx;
3203 WARN_CONSOLE_UNLOCKED();
3206 fbcon_select_primary(info);
3208 if (deferred_takeover) {
3209 pr_info("fbcon: Deferring console take-over\n");
3213 if (info_idx == -1) {
3214 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3215 if (con2fb_map_boot[i] == idx) {
3222 ret = do_fbcon_takeover(1);
3224 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3225 if (con2fb_map_boot[i] == idx)
3226 set_con2fb_map(i, idx, 0);
3233 void fbcon_fb_blanked(struct fb_info *info, int blank)
3235 struct fbcon_ops *ops = info->fbcon_par;
3238 if (!ops || ops->currcon < 0)
3241 vc = vc_cons[ops->currcon].d;
3242 if (vc->vc_mode != KD_TEXT ||
3243 registered_fb[con2fb_map[ops->currcon]] != info)
3246 if (con_is_visible(vc)) {
3250 do_unblank_screen(0);
3252 ops->blank_state = blank;
3255 void fbcon_new_modelist(struct fb_info *info)
3259 struct fb_var_screeninfo var;
3260 const struct fb_videomode *mode;
3262 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3263 if (registered_fb[con2fb_map[i]] != info)
3265 if (!fb_display[i].mode)
3268 display_to_var(&var, &fb_display[i]);
3269 mode = fb_find_nearest_mode(fb_display[i].mode,
3271 fb_videomode_to_var(&var, mode);
3272 fbcon_set_disp(info, &var, vc->vc_num);
3276 void fbcon_get_requirement(struct fb_info *info,
3277 struct fb_blit_caps *caps)
3280 struct fbcon_display *p;
3285 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3287 if (vc && vc->vc_mode == KD_TEXT &&
3288 info->node == con2fb_map[i]) {
3290 caps->x |= 1 << (vc->vc_font.width - 1);
3291 caps->y |= 1 << (vc->vc_font.height - 1);
3292 charcnt = (p->userfont) ?
3293 FNTCHARCNT(p->fontdata) : 256;
3294 if (caps->len < charcnt)
3295 caps->len = charcnt;
3299 vc = vc_cons[fg_console].d;
3301 if (vc && vc->vc_mode == KD_TEXT &&
3302 info->node == con2fb_map[fg_console]) {
3303 p = &fb_display[fg_console];
3304 caps->x = 1 << (vc->vc_font.width - 1);
3305 caps->y = 1 << (vc->vc_font.height - 1);
3306 caps->len = (p->userfont) ?
3307 FNTCHARCNT(p->fontdata) : 256;
3312 static int fbcon_event_notify(struct notifier_block *self,
3313 unsigned long action, void *data)
3315 struct fb_event *event = data;
3316 struct fb_info *info = event->info;
3317 struct fb_con2fbmap *con2fb;
3321 case FB_EVENT_MODE_CHANGE:
3322 fbcon_modechanged(info);
3324 case FB_EVENT_MODE_CHANGE_ALL:
3325 fbcon_set_all_vcs(info);
3327 case FB_EVENT_SET_CONSOLE_MAP:
3328 /* called with console lock held */
3329 con2fb = event->data;
3330 ret = set_con2fb_map(con2fb->console - 1,
3331 con2fb->framebuffer, 1);
3333 case FB_EVENT_GET_CONSOLE_MAP:
3334 con2fb = event->data;
3335 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3337 case FB_EVENT_REMAP_ALL_CONSOLE:
3339 fbcon_remap_all(idx);
3346 * The console `switch' structure for the frame buffer based console
3349 static const struct consw fb_con = {
3350 .owner = THIS_MODULE,
3351 .con_startup = fbcon_startup,
3352 .con_init = fbcon_init,
3353 .con_deinit = fbcon_deinit,
3354 .con_clear = fbcon_clear,
3355 .con_putc = fbcon_putc,
3356 .con_putcs = fbcon_putcs,
3357 .con_cursor = fbcon_cursor,
3358 .con_scroll = fbcon_scroll,
3359 .con_switch = fbcon_switch,
3360 .con_blank = fbcon_blank,
3361 .con_font_set = fbcon_set_font,
3362 .con_font_get = fbcon_get_font,
3363 .con_font_default = fbcon_set_def_font,
3364 .con_font_copy = fbcon_copy_font,
3365 .con_set_palette = fbcon_set_palette,
3366 .con_scrolldelta = fbcon_scrolldelta,
3367 .con_set_origin = fbcon_set_origin,
3368 .con_invert_region = fbcon_invert_region,
3369 .con_screen_pos = fbcon_screen_pos,
3370 .con_getxy = fbcon_getxy,
3371 .con_resize = fbcon_resize,
3372 .con_debug_enter = fbcon_debug_enter,
3373 .con_debug_leave = fbcon_debug_leave,
3376 static struct notifier_block fbcon_event_notifier = {
3377 .notifier_call = fbcon_event_notify,
3380 static ssize_t store_rotate(struct device *device,
3381 struct device_attribute *attr, const char *buf,
3384 struct fb_info *info;
3389 idx = con2fb_map[fg_console];
3391 if (idx == -1 || registered_fb[idx] == NULL)
3394 info = registered_fb[idx];
3395 rotate = simple_strtoul(buf, last, 0);
3396 fbcon_rotate(info, rotate);
3402 static ssize_t store_rotate_all(struct device *device,
3403 struct device_attribute *attr,const char *buf,
3406 struct fb_info *info;
3411 idx = con2fb_map[fg_console];
3413 if (idx == -1 || registered_fb[idx] == NULL)
3416 info = registered_fb[idx];
3417 rotate = simple_strtoul(buf, last, 0);
3418 fbcon_rotate_all(info, rotate);
3424 static ssize_t show_rotate(struct device *device,
3425 struct device_attribute *attr,char *buf)
3427 struct fb_info *info;
3428 int rotate = 0, idx;
3431 idx = con2fb_map[fg_console];
3433 if (idx == -1 || registered_fb[idx] == NULL)
3436 info = registered_fb[idx];
3437 rotate = fbcon_get_rotate(info);
3440 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3443 static ssize_t show_cursor_blink(struct device *device,
3444 struct device_attribute *attr, char *buf)
3446 struct fb_info *info;
3447 struct fbcon_ops *ops;
3448 int idx, blink = -1;
3451 idx = con2fb_map[fg_console];
3453 if (idx == -1 || registered_fb[idx] == NULL)
3456 info = registered_fb[idx];
3457 ops = info->fbcon_par;
3462 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3465 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3468 static ssize_t store_cursor_blink(struct device *device,
3469 struct device_attribute *attr,
3470 const char *buf, size_t count)
3472 struct fb_info *info;
3477 idx = con2fb_map[fg_console];
3479 if (idx == -1 || registered_fb[idx] == NULL)
3482 info = registered_fb[idx];
3484 if (!info->fbcon_par)
3487 blink = simple_strtoul(buf, last, 0);
3490 fbcon_cursor_noblink = 0;
3491 fbcon_add_cursor_timer(info);
3493 fbcon_cursor_noblink = 1;
3494 fbcon_del_cursor_timer(info);
3502 static struct device_attribute device_attrs[] = {
3503 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3504 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3505 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3506 store_cursor_blink),
3509 static int fbcon_init_device(void)
3513 fbcon_has_sysfs = 1;
3515 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3516 error = device_create_file(fbcon_device, &device_attrs[i]);
3524 device_remove_file(fbcon_device, &device_attrs[i]);
3526 fbcon_has_sysfs = 0;
3532 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3533 static void fbcon_register_existing_fbs(struct work_struct *work)
3539 for_each_registered_fb(i)
3540 fbcon_fb_registered(registered_fb[i]);
3545 static struct notifier_block fbcon_output_nb;
3546 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3548 static int fbcon_output_notifier(struct notifier_block *nb,
3549 unsigned long action, void *data)
3551 WARN_CONSOLE_UNLOCKED();
3553 pr_info("fbcon: Taking over console\n");
3555 dummycon_unregister_output_notifier(&fbcon_output_nb);
3556 deferred_takeover = false;
3557 logo_shown = FBCON_LOGO_DONTSHOW;
3559 /* We may get called in atomic context */
3560 schedule_work(&fbcon_deferred_takeover_work);
3566 static void fbcon_start(void)
3568 WARN_CONSOLE_UNLOCKED();
3570 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3571 if (conswitchp != &dummy_con)
3572 deferred_takeover = false;
3574 if (deferred_takeover) {
3575 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3576 dummycon_register_output_notifier(&fbcon_output_nb);
3581 if (num_registered_fb) {
3584 for_each_registered_fb(i) {
3589 do_fbcon_takeover(0);
3593 static void fbcon_exit(void)
3595 struct fb_info *info;
3598 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3599 if (deferred_takeover) {
3600 dummycon_unregister_output_notifier(&fbcon_output_nb);
3601 deferred_takeover = false;
3605 kvfree((void *)softback_buf);
3608 for_each_registered_fb(i) {
3612 info = registered_fb[i];
3614 if (info->queue.func)
3615 pending = cancel_work_sync(&info->queue);
3616 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3619 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3620 if (con2fb_map[j] == i) {
3627 if (info->fbops->fb_release)
3628 info->fbops->fb_release(info, 0);
3629 module_put(info->fbops->owner);
3631 if (info->fbcon_par) {
3632 struct fbcon_ops *ops = info->fbcon_par;
3634 fbcon_del_cursor_timer(info);
3635 kfree(ops->cursor_src);
3636 kfree(ops->cursor_state.mask);
3637 kfree(info->fbcon_par);
3638 info->fbcon_par = NULL;
3641 if (info->queue.func == fb_flashcursor)
3642 info->queue.func = NULL;
3647 void __init fb_console_init(void)
3652 fb_register_client(&fbcon_event_notifier);
3653 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3656 if (IS_ERR(fbcon_device)) {
3657 printk(KERN_WARNING "Unable to create device "
3658 "for fbcon; errno = %ld\n",
3659 PTR_ERR(fbcon_device));
3660 fbcon_device = NULL;
3662 fbcon_init_device();
3664 for (i = 0; i < MAX_NR_CONSOLES; i++)
3673 static void __exit fbcon_deinit_device(void)
3677 if (fbcon_has_sysfs) {
3678 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3679 device_remove_file(fbcon_device, &device_attrs[i]);
3681 fbcon_has_sysfs = 0;
3685 void __exit fb_console_exit(void)
3688 fb_unregister_client(&fbcon_event_notifier);
3689 fbcon_deinit_device();
3690 device_destroy(fb_class, MKDEV(0, 0));
3692 do_unregister_con_driver(&fb_con);