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_shown == FBCON_LOGO_DONTSHOW)
662 if (logo_lines > vc->vc_bottom) {
663 logo_shown = FBCON_LOGO_CANSHOW;
665 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
667 logo_shown = FBCON_LOGO_DRAW;
668 vc->vc_top = logo_lines;
673 #ifdef CONFIG_FB_TILEBLITTING
674 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
676 struct fbcon_ops *ops = info->fbcon_par;
678 ops->p = &fb_display[vc->vc_num];
680 if ((info->flags & FBINFO_MISC_TILEBLITTING))
681 fbcon_set_tileops(vc, info);
683 fbcon_set_rotation(info);
684 fbcon_set_bitops(ops);
688 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
692 if (info->flags & FBINFO_MISC_TILEBLITTING &&
693 info->tileops->fb_get_tilemax(info) < charcount)
699 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
701 struct fbcon_ops *ops = info->fbcon_par;
703 info->flags &= ~FBINFO_MISC_TILEBLITTING;
704 ops->p = &fb_display[vc->vc_num];
705 fbcon_set_rotation(info);
706 fbcon_set_bitops(ops);
709 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
714 #endif /* CONFIG_MISC_TILEBLITTING */
717 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
718 int unit, int oldidx)
720 struct fbcon_ops *ops = NULL;
723 if (!try_module_get(info->fbops->owner))
726 if (!err && info->fbops->fb_open &&
727 info->fbops->fb_open(info, 0))
731 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
737 ops->cur_blink_jiffies = HZ / 5;
739 info->fbcon_par = ops;
742 set_blitting_type(vc, info);
746 con2fb_map[unit] = oldidx;
747 module_put(info->fbops->owner);
753 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
754 struct fb_info *newinfo, int unit,
755 int oldidx, int found)
757 struct fbcon_ops *ops = oldinfo->fbcon_par;
760 if (oldinfo->fbops->fb_release &&
761 oldinfo->fbops->fb_release(oldinfo, 0)) {
762 con2fb_map[unit] = oldidx;
763 if (!found && newinfo->fbops->fb_release)
764 newinfo->fbops->fb_release(newinfo, 0);
766 module_put(newinfo->fbops->owner);
771 fbcon_del_cursor_timer(oldinfo);
772 kfree(ops->cursor_state.mask);
773 kfree(ops->cursor_data);
774 kfree(ops->cursor_src);
775 kfree(ops->fontbuffer);
776 kfree(oldinfo->fbcon_par);
777 oldinfo->fbcon_par = NULL;
778 module_put(oldinfo->fbops->owner);
780 If oldinfo and newinfo are driving the same hardware,
781 the fb_release() method of oldinfo may attempt to
782 restore the hardware state. This will leave the
783 newinfo in an undefined state. Thus, a call to
784 fb_set_par() may be needed for the newinfo.
786 if (newinfo && newinfo->fbops->fb_set_par) {
787 ret = newinfo->fbops->fb_set_par(newinfo);
790 printk(KERN_ERR "con2fb_release_oldinfo: "
791 "detected unhandled fb_set_par error, "
792 "error code %d\n", ret);
799 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
800 int unit, int show_logo)
802 struct fbcon_ops *ops = info->fbcon_par;
805 ops->currcon = fg_console;
807 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
808 ret = info->fbops->fb_set_par(info);
811 printk(KERN_ERR "con2fb_init_display: detected "
812 "unhandled fb_set_par error, "
813 "error code %d\n", ret);
816 ops->flags |= FBCON_FLAGS_INIT;
818 fbcon_set_disp(info, &info->var, unit);
821 struct vc_data *fg_vc = vc_cons[fg_console].d;
822 struct fb_info *fg_info =
823 registered_fb[con2fb_map[fg_console]];
825 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
826 fg_vc->vc_rows, fg_vc->vc_cols,
830 update_screen(vc_cons[fg_console].d);
834 * set_con2fb_map - map console to frame buffer device
835 * @unit: virtual console number to map
836 * @newidx: frame buffer index to map virtual console to
837 * @user: user request
839 * Maps a virtual console @unit to a frame buffer device
842 * This should be called with the console lock held.
844 static int set_con2fb_map(int unit, int newidx, int user)
846 struct vc_data *vc = vc_cons[unit].d;
847 int oldidx = con2fb_map[unit];
848 struct fb_info *info = registered_fb[newidx];
849 struct fb_info *oldinfo = NULL;
852 WARN_CONSOLE_UNLOCKED();
854 if (oldidx == newidx)
860 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
862 return do_fbcon_takeover(0);
866 oldinfo = registered_fb[oldidx];
868 found = search_fb_in_map(newidx);
870 con2fb_map[unit] = newidx;
872 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
876 * If old fb is not mapped to any of the consoles,
877 * fbcon should release it.
879 if (!err && oldinfo && !search_fb_in_map(oldidx))
880 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
884 int show_logo = (fg_console == 0 && !user &&
885 logo_shown != FBCON_LOGO_DONTSHOW);
888 fbcon_add_cursor_timer(info);
889 con2fb_map_boot[unit] = newidx;
890 con2fb_init_display(vc, info, unit, show_logo);
893 if (!search_fb_in_map(info_idx))
900 * Low Level Operations
902 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
903 static int var_to_display(struct display *disp,
904 struct fb_var_screeninfo *var,
905 struct fb_info *info)
907 disp->xres_virtual = var->xres_virtual;
908 disp->yres_virtual = var->yres_virtual;
909 disp->bits_per_pixel = var->bits_per_pixel;
910 disp->grayscale = var->grayscale;
911 disp->nonstd = var->nonstd;
912 disp->accel_flags = var->accel_flags;
913 disp->height = var->height;
914 disp->width = var->width;
915 disp->red = var->red;
916 disp->green = var->green;
917 disp->blue = var->blue;
918 disp->transp = var->transp;
919 disp->rotate = var->rotate;
920 disp->mode = fb_match_mode(var, &info->modelist);
921 if (disp->mode == NULL)
922 /* This should not happen */
927 static void display_to_var(struct fb_var_screeninfo *var,
928 struct display *disp)
930 fb_videomode_to_var(var, disp->mode);
931 var->xres_virtual = disp->xres_virtual;
932 var->yres_virtual = disp->yres_virtual;
933 var->bits_per_pixel = disp->bits_per_pixel;
934 var->grayscale = disp->grayscale;
935 var->nonstd = disp->nonstd;
936 var->accel_flags = disp->accel_flags;
937 var->height = disp->height;
938 var->width = disp->width;
939 var->red = disp->red;
940 var->green = disp->green;
941 var->blue = disp->blue;
942 var->transp = disp->transp;
943 var->rotate = disp->rotate;
946 static const char *fbcon_startup(void)
948 const char *display_desc = "frame buffer device";
949 struct display *p = &fb_display[fg_console];
950 struct vc_data *vc = vc_cons[fg_console].d;
951 const struct font_desc *font = NULL;
952 struct module *owner;
953 struct fb_info *info = NULL;
954 struct fbcon_ops *ops;
958 * If num_registered_fb is zero, this is a call for the dummy part.
959 * The frame buffer devices weren't initialized yet.
961 if (!num_registered_fb || info_idx == -1)
964 * Instead of blindly using registered_fb[0], we use info_idx, set by
967 info = registered_fb[info_idx];
971 owner = info->fbops->owner;
972 if (!try_module_get(owner))
974 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
979 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
987 ops->cur_rotate = -1;
988 ops->cur_blink_jiffies = HZ / 5;
990 info->fbcon_par = ops;
992 p->con_rotate = initial_rotation;
993 if (p->con_rotate == -1)
994 p->con_rotate = info->fbcon_rotate_hint;
995 if (p->con_rotate == -1)
996 p->con_rotate = FB_ROTATE_UR;
998 set_blitting_type(vc, info);
1000 if (info->fix.type != FB_TYPE_TEXT) {
1001 if (fbcon_softback_size) {
1002 if (!softback_buf) {
1005 kvmalloc(fbcon_softback_size,
1007 if (!softback_buf) {
1008 fbcon_softback_size = 0;
1014 kvfree((void *) softback_buf);
1020 softback_in = softback_top = softback_curr =
1025 /* Setup default font */
1026 if (!p->fontdata && !vc->vc_font.data) {
1027 if (!fontname[0] || !(font = find_font(fontname)))
1028 font = get_default_font(info->var.xres,
1030 info->pixmap.blit_x,
1031 info->pixmap.blit_y);
1032 vc->vc_font.width = font->width;
1033 vc->vc_font.height = font->height;
1034 vc->vc_font.data = (void *)(p->fontdata = font->data);
1035 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1037 p->fontdata = vc->vc_font.data;
1040 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1041 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1042 cols /= vc->vc_font.width;
1043 rows /= vc->vc_font.height;
1044 vc_resize(vc, cols, rows);
1046 DPRINTK("mode: %s\n", info->fix.id);
1047 DPRINTK("visual: %d\n", info->fix.visual);
1048 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1050 info->var.bits_per_pixel);
1052 fbcon_add_cursor_timer(info);
1053 fbcon_has_exited = 0;
1054 return display_desc;
1057 static void fbcon_init(struct vc_data *vc, int init)
1059 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1060 struct fbcon_ops *ops;
1061 struct vc_data **default_mode = vc->vc_display_fg;
1062 struct vc_data *svc = *default_mode;
1063 struct display *t, *p = &fb_display[vc->vc_num];
1064 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1067 if (info_idx == -1 || info == NULL)
1072 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1073 logo_shown = FBCON_LOGO_DONTSHOW;
1075 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1076 (info->fix.type == FB_TYPE_TEXT))
1079 if (var_to_display(p, &info->var, info))
1082 if (!info->fbcon_par)
1083 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1085 /* If we are not the first console on this
1086 fb, copy the font from that console */
1087 t = &fb_display[fg_console];
1090 struct vc_data *fvc = vc_cons[fg_console].d;
1092 vc->vc_font.data = (void *)(p->fontdata =
1094 vc->vc_font.width = fvc->vc_font.width;
1095 vc->vc_font.height = fvc->vc_font.height;
1096 p->userfont = t->userfont;
1099 REFCOUNT(p->fontdata)++;
1101 const struct font_desc *font = NULL;
1103 if (!fontname[0] || !(font = find_font(fontname)))
1104 font = get_default_font(info->var.xres,
1106 info->pixmap.blit_x,
1107 info->pixmap.blit_y);
1108 vc->vc_font.width = font->width;
1109 vc->vc_font.height = font->height;
1110 vc->vc_font.data = (void *)(p->fontdata = font->data);
1111 vc->vc_font.charcount = 256; /* FIXME Need to
1112 support more fonts */
1117 charcnt = FNTCHARCNT(p->fontdata);
1119 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1120 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1121 if (charcnt == 256) {
1122 vc->vc_hi_font_mask = 0;
1124 vc->vc_hi_font_mask = 0x100;
1125 if (vc->vc_can_do_color)
1126 vc->vc_complement_mask <<= 1;
1129 if (!*svc->vc_uni_pagedir_loc)
1130 con_set_default_unimap(svc);
1131 if (!*vc->vc_uni_pagedir_loc)
1132 con_copy_unimap(vc, svc);
1134 ops = info->fbcon_par;
1135 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1137 p->con_rotate = initial_rotation;
1138 if (p->con_rotate == -1)
1139 p->con_rotate = info->fbcon_rotate_hint;
1140 if (p->con_rotate == -1)
1141 p->con_rotate = FB_ROTATE_UR;
1143 set_blitting_type(vc, info);
1147 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1148 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1149 new_cols /= vc->vc_font.width;
1150 new_rows /= vc->vc_font.height;
1153 * We must always set the mode. The mode of the previous console
1154 * driver could be in the same resolution but we are using different
1155 * hardware so we have to initialize the hardware.
1157 * We need to do it in fbcon_init() to prevent screen corruption.
1159 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1160 if (info->fbops->fb_set_par &&
1161 !(ops->flags & FBCON_FLAGS_INIT)) {
1162 ret = info->fbops->fb_set_par(info);
1165 printk(KERN_ERR "fbcon_init: detected "
1166 "unhandled fb_set_par error, "
1167 "error code %d\n", ret);
1170 ops->flags |= FBCON_FLAGS_INIT;
1175 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1176 !(cap & FBINFO_HWACCEL_DISABLED))
1177 p->scrollmode = SCROLL_MOVE;
1178 else /* default to something safe */
1179 p->scrollmode = SCROLL_REDRAW;
1182 * ++guenther: console.c:vc_allocate() relies on initializing
1183 * vc_{cols,rows}, but we must not set those if we are only
1184 * resizing the console.
1187 vc->vc_cols = new_cols;
1188 vc->vc_rows = new_rows;
1190 vc_resize(vc, new_cols, new_rows);
1193 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1195 if (vc == svc && softback_buf)
1196 fbcon_update_softback(vc);
1198 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1199 ops->rotate = FB_ROTATE_UR;
1200 set_blitting_type(vc, info);
1203 ops->p = &fb_display[fg_console];
1206 static void fbcon_free_font(struct display *p, bool freefont)
1208 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1209 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1214 static void set_vc_hi_font(struct vc_data *vc, bool set);
1216 static void fbcon_deinit(struct vc_data *vc)
1218 struct display *p = &fb_display[vc->vc_num];
1219 struct fb_info *info;
1220 struct fbcon_ops *ops;
1222 bool free_font = true;
1224 idx = con2fb_map[vc->vc_num];
1229 info = registered_fb[idx];
1234 if (info->flags & FBINFO_MISC_FIRMWARE)
1236 ops = info->fbcon_par;
1241 if (con_is_visible(vc))
1242 fbcon_del_cursor_timer(info);
1244 ops->flags &= ~FBCON_FLAGS_INIT;
1247 fbcon_free_font(p, free_font);
1249 vc->vc_font.data = NULL;
1251 if (vc->vc_hi_font_mask)
1252 set_vc_hi_font(vc, false);
1254 if (!con_is_bound(&fb_con))
1260 /* ====================================================================== */
1262 /* fbcon_XXX routines - interface used by the world
1264 * This system is now divided into two levels because of complications
1265 * caused by hardware scrolling. Top level functions:
1267 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1269 * handles y values in range [0, scr_height-1] that correspond to real
1270 * screen positions. y_wrap shift means that first line of bitmap may be
1271 * anywhere on this display. These functions convert lineoffsets to
1272 * bitmap offsets and deal with the wrap-around case by splitting blits.
1274 * fbcon_bmove_physical_8() -- These functions fast implementations
1275 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1276 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1280 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1281 * Implies should only really hardware scroll in rows. Only reason for
1282 * restriction is simplicity & efficiency at the moment.
1285 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1288 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1289 struct fbcon_ops *ops = info->fbcon_par;
1291 struct display *p = &fb_display[vc->vc_num];
1294 if (fbcon_is_inactive(vc, info))
1297 if (!height || !width)
1300 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1303 * If the font dimensions are not an integral of the display
1304 * dimensions then the ops->clear below won't end up clearing
1305 * the margins. Call clear_margins here in case the logo
1306 * bitmap stretched into the margin area.
1308 fbcon_clear_margins(vc, 0);
1311 /* Split blits that cross physical y_wrap boundary */
1313 y_break = p->vrows - p->yscroll;
1314 if (sy < y_break && sy + height - 1 >= y_break) {
1315 u_int b = y_break - sy;
1316 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1317 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1320 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1323 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1324 int count, int ypos, int xpos)
1326 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1327 struct display *p = &fb_display[vc->vc_num];
1328 struct fbcon_ops *ops = info->fbcon_par;
1330 if (!fbcon_is_inactive(vc, info))
1331 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1332 get_color(vc, info, scr_readw(s), 1),
1333 get_color(vc, info, scr_readw(s), 0));
1336 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1340 scr_writew(c, &chr);
1341 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1344 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1346 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1347 struct fbcon_ops *ops = info->fbcon_par;
1349 if (!fbcon_is_inactive(vc, info))
1350 ops->clear_margins(vc, info, margin_color, bottom_only);
1353 static void fbcon_cursor(struct vc_data *vc, int mode)
1355 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1356 struct fbcon_ops *ops = info->fbcon_par;
1358 int c = scr_readw((u16 *) vc->vc_pos);
1360 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1362 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1365 if (vc->vc_cursor_type & 0x10)
1366 fbcon_del_cursor_timer(info);
1368 fbcon_add_cursor_timer(info);
1370 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1371 if (mode & CM_SOFTBACK) {
1372 mode &= ~CM_SOFTBACK;
1376 fbcon_set_origin(vc);
1380 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1381 get_color(vc, info, c, 0));
1384 static int scrollback_phys_max = 0;
1385 static int scrollback_max = 0;
1386 static int scrollback_current = 0;
1388 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1391 struct display *p, *t;
1392 struct vc_data **default_mode, *vc;
1393 struct vc_data *svc;
1394 struct fbcon_ops *ops = info->fbcon_par;
1395 int rows, cols, charcnt = 256;
1397 p = &fb_display[unit];
1399 if (var_to_display(p, var, info))
1402 vc = vc_cons[unit].d;
1407 default_mode = vc->vc_display_fg;
1408 svc = *default_mode;
1409 t = &fb_display[svc->vc_num];
1411 if (!vc->vc_font.data) {
1412 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1413 vc->vc_font.width = (*default_mode)->vc_font.width;
1414 vc->vc_font.height = (*default_mode)->vc_font.height;
1415 p->userfont = t->userfont;
1417 REFCOUNT(p->fontdata)++;
1420 charcnt = FNTCHARCNT(p->fontdata);
1422 var->activate = FB_ACTIVATE_NOW;
1423 info->var.activate = var->activate;
1424 var->yoffset = info->var.yoffset;
1425 var->xoffset = info->var.xoffset;
1426 fb_set_var(info, var);
1427 ops->var = info->var;
1428 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1429 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1430 if (charcnt == 256) {
1431 vc->vc_hi_font_mask = 0;
1433 vc->vc_hi_font_mask = 0x100;
1434 if (vc->vc_can_do_color)
1435 vc->vc_complement_mask <<= 1;
1438 if (!*svc->vc_uni_pagedir_loc)
1439 con_set_default_unimap(svc);
1440 if (!*vc->vc_uni_pagedir_loc)
1441 con_copy_unimap(vc, svc);
1443 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1444 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1445 cols /= vc->vc_font.width;
1446 rows /= vc->vc_font.height;
1447 vc_resize(vc, cols, rows);
1449 if (con_is_visible(vc)) {
1452 fbcon_update_softback(vc);
1456 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1458 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1459 struct fbcon_ops *ops = info->fbcon_par;
1460 struct display *p = &fb_display[vc->vc_num];
1462 p->yscroll += count;
1463 if (p->yscroll >= p->vrows) /* Deal with wrap */
1464 p->yscroll -= p->vrows;
1465 ops->var.xoffset = 0;
1466 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1467 ops->var.vmode |= FB_VMODE_YWRAP;
1468 ops->update_start(info);
1469 scrollback_max += count;
1470 if (scrollback_max > scrollback_phys_max)
1471 scrollback_max = scrollback_phys_max;
1472 scrollback_current = 0;
1475 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1477 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1478 struct fbcon_ops *ops = info->fbcon_par;
1479 struct display *p = &fb_display[vc->vc_num];
1481 p->yscroll -= count;
1482 if (p->yscroll < 0) /* Deal with wrap */
1483 p->yscroll += p->vrows;
1484 ops->var.xoffset = 0;
1485 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1486 ops->var.vmode |= FB_VMODE_YWRAP;
1487 ops->update_start(info);
1488 scrollback_max -= count;
1489 if (scrollback_max < 0)
1491 scrollback_current = 0;
1494 static __inline__ void ypan_up(struct vc_data *vc, int count)
1496 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1497 struct display *p = &fb_display[vc->vc_num];
1498 struct fbcon_ops *ops = info->fbcon_par;
1500 p->yscroll += count;
1501 if (p->yscroll > p->vrows - vc->vc_rows) {
1502 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1503 0, 0, 0, vc->vc_rows, vc->vc_cols);
1504 p->yscroll -= p->vrows - vc->vc_rows;
1507 ops->var.xoffset = 0;
1508 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1509 ops->var.vmode &= ~FB_VMODE_YWRAP;
1510 ops->update_start(info);
1511 fbcon_clear_margins(vc, 1);
1512 scrollback_max += count;
1513 if (scrollback_max > scrollback_phys_max)
1514 scrollback_max = scrollback_phys_max;
1515 scrollback_current = 0;
1518 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1520 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1521 struct fbcon_ops *ops = info->fbcon_par;
1522 struct display *p = &fb_display[vc->vc_num];
1524 p->yscroll += count;
1526 if (p->yscroll > p->vrows - vc->vc_rows) {
1527 p->yscroll -= p->vrows - vc->vc_rows;
1528 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1531 ops->var.xoffset = 0;
1532 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1533 ops->var.vmode &= ~FB_VMODE_YWRAP;
1534 ops->update_start(info);
1535 fbcon_clear_margins(vc, 1);
1536 scrollback_max += count;
1537 if (scrollback_max > scrollback_phys_max)
1538 scrollback_max = scrollback_phys_max;
1539 scrollback_current = 0;
1542 static __inline__ void ypan_down(struct vc_data *vc, int count)
1544 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1545 struct display *p = &fb_display[vc->vc_num];
1546 struct fbcon_ops *ops = info->fbcon_par;
1548 p->yscroll -= count;
1549 if (p->yscroll < 0) {
1550 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1551 0, vc->vc_rows, vc->vc_cols);
1552 p->yscroll += p->vrows - vc->vc_rows;
1555 ops->var.xoffset = 0;
1556 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1557 ops->var.vmode &= ~FB_VMODE_YWRAP;
1558 ops->update_start(info);
1559 fbcon_clear_margins(vc, 1);
1560 scrollback_max -= count;
1561 if (scrollback_max < 0)
1563 scrollback_current = 0;
1566 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1568 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1569 struct fbcon_ops *ops = info->fbcon_par;
1570 struct display *p = &fb_display[vc->vc_num];
1572 p->yscroll -= count;
1574 if (p->yscroll < 0) {
1575 p->yscroll += p->vrows - vc->vc_rows;
1576 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1579 ops->var.xoffset = 0;
1580 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1581 ops->var.vmode &= ~FB_VMODE_YWRAP;
1582 ops->update_start(info);
1583 fbcon_clear_margins(vc, 1);
1584 scrollback_max -= count;
1585 if (scrollback_max < 0)
1587 scrollback_current = 0;
1590 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1593 int count = vc->vc_rows;
1594 unsigned short *d, *s;
1598 d = (u16 *) softback_curr;
1599 if (d == (u16 *) softback_in)
1600 d = (u16 *) vc->vc_origin;
1601 n = softback_curr + delta * vc->vc_size_row;
1602 softback_lines -= delta;
1604 if (softback_curr < softback_top && n < softback_buf) {
1605 n += softback_end - softback_buf;
1606 if (n < softback_top) {
1608 (softback_top - n) / vc->vc_size_row;
1611 } else if (softback_curr >= softback_top
1612 && n < softback_top) {
1614 (softback_top - n) / vc->vc_size_row;
1618 if (softback_curr > softback_in && n >= softback_end) {
1619 n += softback_buf - softback_end;
1620 if (n > softback_in) {
1624 } else if (softback_curr <= softback_in && n > softback_in) {
1629 if (n == softback_curr)
1632 s = (u16 *) softback_curr;
1633 if (s == (u16 *) softback_in)
1634 s = (u16 *) vc->vc_origin;
1636 unsigned short *start;
1640 unsigned short attr = 1;
1643 le = advance_row(s, 1);
1646 if (attr != (c & 0xff00)) {
1649 fbcon_putcs(vc, start, s - start,
1655 if (c == scr_readw(d)) {
1657 fbcon_putcs(vc, start, s - start,
1670 fbcon_putcs(vc, start, s - start, line, x);
1672 if (d == (u16 *) softback_end)
1673 d = (u16 *) softback_buf;
1674 if (d == (u16 *) softback_in)
1675 d = (u16 *) vc->vc_origin;
1676 if (s == (u16 *) softback_end)
1677 s = (u16 *) softback_buf;
1678 if (s == (u16 *) softback_in)
1679 s = (u16 *) vc->vc_origin;
1683 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1684 int line, int count, int dy)
1686 unsigned short *s = (unsigned short *)
1687 (vc->vc_origin + vc->vc_size_row * line);
1690 unsigned short *start = s;
1691 unsigned short *le = advance_row(s, 1);
1694 unsigned short attr = 1;
1698 if (attr != (c & 0xff00)) {
1701 fbcon_putcs(vc, start, s - start,
1707 console_conditional_schedule();
1711 fbcon_putcs(vc, start, s - start, dy, x);
1712 console_conditional_schedule();
1717 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1718 struct display *p, int line, int count, int ycount)
1720 int offset = ycount * vc->vc_cols;
1721 unsigned short *d = (unsigned short *)
1722 (vc->vc_origin + vc->vc_size_row * line);
1723 unsigned short *s = d + offset;
1724 struct fbcon_ops *ops = info->fbcon_par;
1727 unsigned short *start = s;
1728 unsigned short *le = advance_row(s, 1);
1735 if (c == scr_readw(d)) {
1737 ops->bmove(vc, info, line + ycount, x,
1738 line, x, 1, s-start);
1748 console_conditional_schedule();
1753 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1755 console_conditional_schedule();
1760 /* NOTE: We subtract two lines from these pointers */
1761 s -= vc->vc_size_row;
1762 d -= vc->vc_size_row;
1767 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1768 int line, int count, int offset)
1770 unsigned short *d = (unsigned short *)
1771 (vc->vc_origin + vc->vc_size_row * line);
1772 unsigned short *s = d + offset;
1775 unsigned short *start = s;
1776 unsigned short *le = advance_row(s, 1);
1779 unsigned short attr = 1;
1783 if (attr != (c & 0xff00)) {
1786 fbcon_putcs(vc, start, s - start,
1792 if (c == scr_readw(d)) {
1794 fbcon_putcs(vc, start, s - start,
1804 console_conditional_schedule();
1809 fbcon_putcs(vc, start, s - start, line, x);
1810 console_conditional_schedule();
1815 /* NOTE: We subtract two lines from these pointers */
1816 s -= vc->vc_size_row;
1817 d -= vc->vc_size_row;
1822 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1827 if (vc->vc_num != fg_console)
1829 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1832 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1834 p = advance_row(p, 1);
1835 softback_in += vc->vc_size_row;
1836 if (softback_in == softback_end)
1837 softback_in = softback_buf;
1838 if (softback_in == softback_top) {
1839 softback_top += vc->vc_size_row;
1840 if (softback_top == softback_end)
1841 softback_top = softback_buf;
1844 softback_curr = softback_in;
1847 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1848 enum con_scroll dir, unsigned int count)
1850 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1851 struct display *p = &fb_display[vc->vc_num];
1852 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1854 if (fbcon_is_inactive(vc, info))
1857 fbcon_cursor(vc, CM_ERASE);
1860 * ++Geert: Only use ywrap/ypan if the console is in text mode
1861 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1862 * whole screen (prevents flicker).
1867 if (count > vc->vc_rows) /* Maximum realistic size */
1868 count = vc->vc_rows;
1870 fbcon_softback_note(vc, t, count);
1871 if (logo_shown >= 0)
1873 switch (p->scrollmode) {
1875 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1877 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1878 scr_memsetw((unsigned short *) (vc->vc_origin +
1881 vc->vc_video_erase_char,
1882 vc->vc_size_row * count);
1886 case SCROLL_WRAP_MOVE:
1887 if (b - t - count > 3 * vc->vc_rows >> 2) {
1889 fbcon_bmove(vc, 0, 0, count, 0, t,
1891 ywrap_up(vc, count);
1892 if (vc->vc_rows - b > 0)
1893 fbcon_bmove(vc, b - count, 0, b, 0,
1896 } else if (info->flags & FBINFO_READS_FAST)
1897 fbcon_bmove(vc, t + count, 0, t, 0,
1898 b - t - count, vc->vc_cols);
1901 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1904 case SCROLL_PAN_REDRAW:
1905 if ((p->yscroll + count <=
1906 2 * (p->vrows - vc->vc_rows))
1907 && ((!scroll_partial && (b - t == vc->vc_rows))
1910 3 * vc->vc_rows >> 2)))) {
1912 fbcon_redraw_move(vc, p, 0, t, count);
1913 ypan_up_redraw(vc, t, count);
1914 if (vc->vc_rows - b > 0)
1915 fbcon_redraw_move(vc, p, b,
1916 vc->vc_rows - b, b);
1918 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1919 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1922 case SCROLL_PAN_MOVE:
1923 if ((p->yscroll + count <=
1924 2 * (p->vrows - vc->vc_rows))
1925 && ((!scroll_partial && (b - t == vc->vc_rows))
1928 3 * vc->vc_rows >> 2)))) {
1930 fbcon_bmove(vc, 0, 0, count, 0, t,
1933 if (vc->vc_rows - b > 0)
1934 fbcon_bmove(vc, b - count, 0, b, 0,
1937 } else if (info->flags & FBINFO_READS_FAST)
1938 fbcon_bmove(vc, t + count, 0, t, 0,
1939 b - t - count, vc->vc_cols);
1942 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1947 fbcon_redraw(vc, p, t, b - t - count,
1948 count * vc->vc_cols);
1949 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1950 scr_memsetw((unsigned short *) (vc->vc_origin +
1953 vc->vc_video_erase_char,
1954 vc->vc_size_row * count);
1960 if (count > vc->vc_rows) /* Maximum realistic size */
1961 count = vc->vc_rows;
1962 if (logo_shown >= 0)
1964 switch (p->scrollmode) {
1966 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1968 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1969 scr_memsetw((unsigned short *) (vc->vc_origin +
1972 vc->vc_video_erase_char,
1973 vc->vc_size_row * count);
1977 case SCROLL_WRAP_MOVE:
1978 if (b - t - count > 3 * vc->vc_rows >> 2) {
1979 if (vc->vc_rows - b > 0)
1980 fbcon_bmove(vc, b, 0, b - count, 0,
1983 ywrap_down(vc, count);
1985 fbcon_bmove(vc, count, 0, 0, 0, t,
1987 } else if (info->flags & FBINFO_READS_FAST)
1988 fbcon_bmove(vc, t, 0, t + count, 0,
1989 b - t - count, vc->vc_cols);
1992 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1995 case SCROLL_PAN_MOVE:
1996 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1997 && ((!scroll_partial && (b - t == vc->vc_rows))
2000 3 * vc->vc_rows >> 2)))) {
2001 if (vc->vc_rows - b > 0)
2002 fbcon_bmove(vc, b, 0, b - count, 0,
2005 ypan_down(vc, count);
2007 fbcon_bmove(vc, count, 0, 0, 0, t,
2009 } else if (info->flags & FBINFO_READS_FAST)
2010 fbcon_bmove(vc, t, 0, t + count, 0,
2011 b - t - count, vc->vc_cols);
2014 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2017 case SCROLL_PAN_REDRAW:
2018 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2019 && ((!scroll_partial && (b - t == vc->vc_rows))
2022 3 * vc->vc_rows >> 2)))) {
2023 if (vc->vc_rows - b > 0)
2024 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2026 ypan_down_redraw(vc, t, count);
2028 fbcon_redraw_move(vc, p, count, t, 0);
2030 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2031 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2036 fbcon_redraw(vc, p, b - 1, b - t - count,
2037 -count * vc->vc_cols);
2038 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2039 scr_memsetw((unsigned short *) (vc->vc_origin +
2042 vc->vc_video_erase_char,
2043 vc->vc_size_row * count);
2051 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2052 int height, int width)
2054 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2055 struct display *p = &fb_display[vc->vc_num];
2057 if (fbcon_is_inactive(vc, info))
2060 if (!width || !height)
2063 /* Split blits that cross physical y_wrap case.
2064 * Pathological case involves 4 blits, better to use recursive
2065 * code rather than unrolled case
2067 * Recursive invocations don't need to erase the cursor over and
2068 * over again, so we use fbcon_bmove_rec()
2070 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2071 p->vrows - p->yscroll);
2074 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2075 int dy, int dx, int height, int width, u_int y_break)
2077 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2078 struct fbcon_ops *ops = info->fbcon_par;
2081 if (sy < y_break && sy + height > y_break) {
2083 if (dy < sy) { /* Avoid trashing self */
2084 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2086 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2087 height - b, width, y_break);
2089 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2090 height - b, width, y_break);
2091 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2097 if (dy < y_break && dy + height > y_break) {
2099 if (dy < sy) { /* Avoid trashing self */
2100 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2102 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2103 height - b, width, y_break);
2105 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2106 height - b, width, y_break);
2107 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2112 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2116 static void updatescrollmode(struct display *p,
2117 struct fb_info *info,
2120 struct fbcon_ops *ops = info->fbcon_par;
2121 int fh = vc->vc_font.height;
2122 int cap = info->flags;
2124 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2125 info->fix.xpanstep);
2126 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2127 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2128 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2129 info->var.xres_virtual);
2130 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2131 divides(ypan, vc->vc_font.height) && vyres > yres;
2132 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2133 divides(ywrap, vc->vc_font.height) &&
2134 divides(vc->vc_font.height, vyres) &&
2135 divides(vc->vc_font.height, yres);
2136 int reading_fast = cap & FBINFO_READS_FAST;
2137 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2138 !(cap & FBINFO_HWACCEL_DISABLED);
2139 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2140 !(cap & FBINFO_HWACCEL_DISABLED);
2142 p->vrows = vyres/fh;
2143 if (yres > (fh * (vc->vc_rows + 1)))
2144 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2145 if ((yres % fh) && (vyres % fh < yres % fh))
2148 if (good_wrap || good_pan) {
2149 if (reading_fast || fast_copyarea)
2150 p->scrollmode = good_wrap ?
2151 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2153 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2156 if (reading_fast || (fast_copyarea && !fast_imageblit))
2157 p->scrollmode = SCROLL_MOVE;
2159 p->scrollmode = SCROLL_REDRAW;
2163 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2164 unsigned int height, unsigned int user)
2166 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2167 struct fbcon_ops *ops = info->fbcon_par;
2168 struct display *p = &fb_display[vc->vc_num];
2169 struct fb_var_screeninfo var = info->var;
2170 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2172 virt_w = FBCON_SWAP(ops->rotate, width, height);
2173 virt_h = FBCON_SWAP(ops->rotate, height, width);
2174 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2175 vc->vc_font.height);
2176 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2178 var.xres = virt_w * virt_fw;
2179 var.yres = virt_h * virt_fh;
2180 x_diff = info->var.xres - var.xres;
2181 y_diff = info->var.yres - var.yres;
2182 if (x_diff < 0 || x_diff > virt_fw ||
2183 y_diff < 0 || y_diff > virt_fh) {
2184 const struct fb_videomode *mode;
2186 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2187 mode = fb_find_best_mode(&var, &info->modelist);
2190 display_to_var(&var, p);
2191 fb_videomode_to_var(&var, mode);
2193 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2196 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2197 if (con_is_visible(vc)) {
2198 var.activate = FB_ACTIVATE_NOW |
2200 fb_set_var(info, &var);
2202 var_to_display(p, &info->var, info);
2203 ops->var = info->var;
2205 updatescrollmode(p, info, vc);
2209 static int fbcon_switch(struct vc_data *vc)
2211 struct fb_info *info, *old_info = NULL;
2212 struct fbcon_ops *ops;
2213 struct display *p = &fb_display[vc->vc_num];
2214 struct fb_var_screeninfo var;
2215 int i, ret, prev_console, charcnt = 256;
2217 info = registered_fb[con2fb_map[vc->vc_num]];
2218 ops = info->fbcon_par;
2222 fbcon_set_origin(vc);
2223 softback_top = softback_curr = softback_in = softback_buf;
2225 fbcon_update_softback(vc);
2228 if (logo_shown >= 0) {
2229 struct vc_data *conp2 = vc_cons[logo_shown].d;
2231 if (conp2->vc_top == logo_lines
2232 && conp2->vc_bottom == conp2->vc_rows)
2234 logo_shown = FBCON_LOGO_CANSHOW;
2237 prev_console = ops->currcon;
2238 if (prev_console != -1)
2239 old_info = registered_fb[con2fb_map[prev_console]];
2241 * FIXME: If we have multiple fbdev's loaded, we need to
2242 * update all info->currcon. Perhaps, we can place this
2243 * in a centralized structure, but this might break some
2246 * info->currcon = vc->vc_num;
2248 for_each_registered_fb(i) {
2249 if (registered_fb[i]->fbcon_par) {
2250 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2252 o->currcon = vc->vc_num;
2255 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2256 display_to_var(&var, p);
2257 var.activate = FB_ACTIVATE_NOW;
2260 * make sure we don't unnecessarily trip the memcmp()
2263 info->var.activate = var.activate;
2264 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2265 fb_set_var(info, &var);
2266 ops->var = info->var;
2268 if (old_info != NULL && (old_info != info ||
2269 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2270 if (info->fbops->fb_set_par) {
2271 ret = info->fbops->fb_set_par(info);
2274 printk(KERN_ERR "fbcon_switch: detected "
2275 "unhandled fb_set_par error, "
2276 "error code %d\n", ret);
2279 if (old_info != info)
2280 fbcon_del_cursor_timer(old_info);
2283 if (fbcon_is_inactive(vc, info) ||
2284 ops->blank_state != FB_BLANK_UNBLANK)
2285 fbcon_del_cursor_timer(info);
2287 fbcon_add_cursor_timer(info);
2289 set_blitting_type(vc, info);
2290 ops->cursor_reset = 1;
2292 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2293 ops->rotate = FB_ROTATE_UR;
2294 set_blitting_type(vc, info);
2297 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2298 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2301 charcnt = FNTCHARCNT(vc->vc_font.data);
2304 vc->vc_complement_mask <<= 1;
2306 updatescrollmode(p, info, vc);
2308 switch (p->scrollmode) {
2309 case SCROLL_WRAP_MOVE:
2310 scrollback_phys_max = p->vrows - vc->vc_rows;
2312 case SCROLL_PAN_MOVE:
2313 case SCROLL_PAN_REDRAW:
2314 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2315 if (scrollback_phys_max < 0)
2316 scrollback_phys_max = 0;
2319 scrollback_phys_max = 0;
2324 scrollback_current = 0;
2326 if (!fbcon_is_inactive(vc, info)) {
2327 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2328 ops->update_start(info);
2331 fbcon_set_palette(vc, color_table);
2332 fbcon_clear_margins(vc, 0);
2334 if (logo_shown == FBCON_LOGO_DRAW) {
2336 logo_shown = fg_console;
2337 /* This is protected above by initmem_freed */
2338 fb_show_logo(info, ops->rotate);
2340 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2341 vc->vc_size_row * (vc->vc_bottom -
2348 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2351 struct fb_event event;
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 if (!lock_fb_info(info))
2368 event.data = ␣
2369 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2370 unlock_fb_info(info);
2373 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2375 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2376 struct fbcon_ops *ops = info->fbcon_par;
2379 struct fb_var_screeninfo var = info->var;
2384 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2385 fb_set_var(info, &var);
2387 ops->var = info->var;
2391 if (!fbcon_is_inactive(vc, info)) {
2392 if (ops->blank_state != blank) {
2393 ops->blank_state = blank;
2394 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2395 ops->cursor_flash = (!blank);
2397 if (!(info->flags & FBINFO_MISC_USEREVENT))
2398 if (fb_blank(info, blank))
2399 fbcon_generic_blank(vc, info, blank);
2406 if (mode_switch || fbcon_is_inactive(vc, info) ||
2407 ops->blank_state != FB_BLANK_UNBLANK)
2408 fbcon_del_cursor_timer(info);
2410 fbcon_add_cursor_timer(info);
2415 static int fbcon_debug_enter(struct vc_data *vc)
2417 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2418 struct fbcon_ops *ops = info->fbcon_par;
2420 ops->save_graphics = ops->graphics;
2422 if (info->fbops->fb_debug_enter)
2423 info->fbops->fb_debug_enter(info);
2424 fbcon_set_palette(vc, color_table);
2428 static int fbcon_debug_leave(struct vc_data *vc)
2430 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2431 struct fbcon_ops *ops = info->fbcon_par;
2433 ops->graphics = ops->save_graphics;
2434 if (info->fbops->fb_debug_leave)
2435 info->fbops->fb_debug_leave(info);
2439 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2441 u8 *fontdata = vc->vc_font.data;
2442 u8 *data = font->data;
2445 font->width = vc->vc_font.width;
2446 font->height = vc->vc_font.height;
2447 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2451 if (font->width <= 8) {
2452 j = vc->vc_font.height;
2453 for (i = 0; i < font->charcount; i++) {
2454 memcpy(data, fontdata, j);
2455 memset(data + j, 0, 32 - j);
2459 } else if (font->width <= 16) {
2460 j = vc->vc_font.height * 2;
2461 for (i = 0; i < font->charcount; i++) {
2462 memcpy(data, fontdata, j);
2463 memset(data + j, 0, 64 - j);
2467 } else if (font->width <= 24) {
2468 for (i = 0; i < font->charcount; i++) {
2469 for (j = 0; j < vc->vc_font.height; j++) {
2470 *data++ = fontdata[0];
2471 *data++ = fontdata[1];
2472 *data++ = fontdata[2];
2473 fontdata += sizeof(u32);
2475 memset(data, 0, 3 * (32 - j));
2476 data += 3 * (32 - j);
2479 j = vc->vc_font.height * 4;
2480 for (i = 0; i < font->charcount; i++) {
2481 memcpy(data, fontdata, j);
2482 memset(data + j, 0, 128 - j);
2490 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2491 static void set_vc_hi_font(struct vc_data *vc, bool set)
2494 vc->vc_hi_font_mask = 0;
2495 if (vc->vc_can_do_color) {
2496 vc->vc_complement_mask >>= 1;
2497 vc->vc_s_complement_mask >>= 1;
2500 /* ++Edmund: reorder the attribute bits */
2501 if (vc->vc_can_do_color) {
2502 unsigned short *cp =
2503 (unsigned short *) vc->vc_origin;
2504 int count = vc->vc_screenbuf_size / 2;
2506 for (; count > 0; count--, cp++) {
2508 scr_writew(((c & 0xfe00) >> 1) |
2511 c = vc->vc_video_erase_char;
2512 vc->vc_video_erase_char =
2513 ((c & 0xfe00) >> 1) | (c & 0xff);
2517 vc->vc_hi_font_mask = 0x100;
2518 if (vc->vc_can_do_color) {
2519 vc->vc_complement_mask <<= 1;
2520 vc->vc_s_complement_mask <<= 1;
2523 /* ++Edmund: reorder the attribute bits */
2525 unsigned short *cp =
2526 (unsigned short *) vc->vc_origin;
2527 int count = vc->vc_screenbuf_size / 2;
2529 for (; count > 0; count--, cp++) {
2530 unsigned short newc;
2532 if (vc->vc_can_do_color)
2534 ((c & 0xff00) << 1) | (c &
2538 scr_writew(newc, cp);
2540 c = vc->vc_video_erase_char;
2541 if (vc->vc_can_do_color) {
2542 vc->vc_video_erase_char =
2543 ((c & 0xff00) << 1) | (c & 0xff);
2546 vc->vc_video_erase_char = c & ~0x100;
2551 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2552 const u8 * data, int userfont)
2554 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2555 struct fbcon_ops *ops = info->fbcon_par;
2556 struct display *p = &fb_display[vc->vc_num];
2559 char *old_data = NULL;
2561 if (con_is_visible(vc) && softback_lines)
2562 fbcon_set_origin(vc);
2564 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2566 old_data = vc->vc_font.data;
2568 cnt = FNTCHARCNT(data);
2571 vc->vc_font.data = (void *)(p->fontdata = data);
2572 if ((p->userfont = userfont))
2574 vc->vc_font.width = w;
2575 vc->vc_font.height = h;
2576 if (vc->vc_hi_font_mask && cnt == 256)
2577 set_vc_hi_font(vc, false);
2578 else if (!vc->vc_hi_font_mask && cnt == 512)
2579 set_vc_hi_font(vc, true);
2584 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2585 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2588 vc_resize(vc, cols, rows);
2589 if (con_is_visible(vc) && softback_buf)
2590 fbcon_update_softback(vc);
2591 } else if (con_is_visible(vc)
2592 && vc->vc_mode == KD_TEXT) {
2593 fbcon_clear_margins(vc, 0);
2597 if (old_data && (--REFCOUNT(old_data) == 0))
2598 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2602 static int fbcon_copy_font(struct vc_data *vc, int con)
2604 struct display *od = &fb_display[con];
2605 struct console_font *f = &vc->vc_font;
2607 if (od->fontdata == f->data)
2608 return 0; /* already the same font... */
2609 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2613 * User asked to set font; we are guaranteed that
2614 * a) width and height are in range 1..32
2615 * b) charcount does not exceed 512
2616 * but lets not assume that, since someone might someday want to use larger
2617 * fonts. And charcount of 512 is small for unicode support.
2619 * However, user space gives the font in 32 rows , regardless of
2620 * actual font height. So a new API is needed if support for larger fonts
2621 * is ever implemented.
2624 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2627 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2628 unsigned charcount = font->charcount;
2629 int w = font->width;
2630 int h = font->height;
2633 u8 *new_data, *data = font->data;
2634 int pitch = (font->width+7) >> 3;
2636 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2637 * If not this check should be changed to charcount < 256 */
2638 if (charcount != 256 && charcount != 512)
2641 /* Make sure drawing engine can handle the font */
2642 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2643 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2646 /* Make sure driver can handle the font length */
2647 if (fbcon_invalid_charcount(info, charcount))
2650 size = h * pitch * charcount;
2652 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2657 new_data += FONT_EXTRA_WORDS * sizeof(int);
2658 FNTSIZE(new_data) = size;
2659 FNTCHARCNT(new_data) = charcount;
2660 REFCOUNT(new_data) = 0; /* usage counter */
2661 for (i=0; i< charcount; i++) {
2662 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2665 /* Since linux has a nice crc32 function use it for counting font
2667 csum = crc32(0, new_data, size);
2669 FNTSUM(new_data) = csum;
2670 /* Check if the same font is on some other console already */
2671 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2672 struct vc_data *tmp = vc_cons[i].d;
2674 if (fb_display[i].userfont &&
2675 fb_display[i].fontdata &&
2676 FNTSUM(fb_display[i].fontdata) == csum &&
2677 FNTSIZE(fb_display[i].fontdata) == size &&
2678 tmp->vc_font.width == w &&
2679 !memcmp(fb_display[i].fontdata, new_data, size)) {
2680 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2681 new_data = (u8 *)fb_display[i].fontdata;
2685 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2688 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2690 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2691 const struct font_desc *f;
2694 f = get_default_font(info->var.xres, info->var.yres,
2695 info->pixmap.blit_x, info->pixmap.blit_y);
2696 else if (!(f = find_font(name)))
2699 font->width = f->width;
2700 font->height = f->height;
2701 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2704 static u16 palette_red[16];
2705 static u16 palette_green[16];
2706 static u16 palette_blue[16];
2708 static struct fb_cmap palette_cmap = {
2709 0, 16, palette_red, palette_green, palette_blue, NULL
2712 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2714 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2718 if (fbcon_is_inactive(vc, info))
2721 if (!con_is_visible(vc))
2724 depth = fb_get_color_depth(&info->var, &info->fix);
2726 for (i = j = 0; i < 16; i++) {
2728 val = vc->vc_palette[j++];
2729 palette_red[k] = (val << 8) | val;
2730 val = vc->vc_palette[j++];
2731 palette_green[k] = (val << 8) | val;
2732 val = vc->vc_palette[j++];
2733 palette_blue[k] = (val << 8) | val;
2735 palette_cmap.len = 16;
2736 palette_cmap.start = 0;
2738 * If framebuffer is capable of less than 16 colors,
2739 * use default palette of fbcon.
2742 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2744 fb_set_cmap(&palette_cmap, info);
2747 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2752 if (vc->vc_num != fg_console || !softback_lines)
2753 return (u16 *) (vc->vc_origin + offset);
2754 line = offset / vc->vc_size_row;
2755 if (line >= softback_lines)
2756 return (u16 *) (vc->vc_origin + offset -
2757 softback_lines * vc->vc_size_row);
2758 p = softback_curr + offset;
2759 if (p >= softback_end)
2760 p += softback_buf - softback_end;
2764 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2770 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2771 unsigned long offset = (pos - vc->vc_origin) / 2;
2773 x = offset % vc->vc_cols;
2774 y = offset / vc->vc_cols;
2775 if (vc->vc_num == fg_console)
2776 y += softback_lines;
2777 ret = pos + (vc->vc_cols - x) * 2;
2778 } else if (vc->vc_num == fg_console && softback_lines) {
2779 unsigned long offset = pos - softback_curr;
2781 if (pos < softback_curr)
2782 offset += softback_end - softback_buf;
2784 x = offset % vc->vc_cols;
2785 y = offset / vc->vc_cols;
2786 ret = pos + (vc->vc_cols - x) * 2;
2787 if (ret == softback_end)
2789 if (ret == softback_in)
2790 ret = vc->vc_origin;
2792 /* Should not happen */
2794 ret = vc->vc_origin;
2803 /* As we might be inside of softback, we may work with non-contiguous buffer,
2804 that's why we have to use a separate routine. */
2805 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2808 u16 a = scr_readw(p);
2809 if (!vc->vc_can_do_color)
2811 else if (vc->vc_hi_font_mask == 0x100)
2812 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2813 (((a) & 0x0e00) << 4);
2815 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2816 (((a) & 0x0700) << 4);
2818 if (p == (u16 *) softback_end)
2819 p = (u16 *) softback_buf;
2820 if (p == (u16 *) softback_in)
2821 p = (u16 *) vc->vc_origin;
2825 static void fbcon_scrolldelta(struct vc_data *vc, int lines)
2827 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2828 struct fbcon_ops *ops = info->fbcon_par;
2829 struct display *disp = &fb_display[fg_console];
2830 int offset, limit, scrollback_old;
2833 if (vc->vc_num != fg_console)
2835 if (vc->vc_mode != KD_TEXT || !lines)
2837 if (logo_shown >= 0) {
2838 struct vc_data *conp2 = vc_cons[logo_shown].d;
2840 if (conp2->vc_top == logo_lines
2841 && conp2->vc_bottom == conp2->vc_rows)
2843 if (logo_shown == vc->vc_num) {
2849 logo_lines * vc->vc_size_row;
2850 for (i = 0; i < logo_lines; i++) {
2851 if (p == softback_top)
2853 if (p == softback_buf)
2855 p -= vc->vc_size_row;
2856 q -= vc->vc_size_row;
2857 scr_memcpyw((u16 *) q, (u16 *) p,
2860 softback_in = softback_curr = p;
2861 update_region(vc, vc->vc_origin,
2862 logo_lines * vc->vc_cols);
2864 logo_shown = FBCON_LOGO_CANSHOW;
2866 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2867 fbcon_redraw_softback(vc, disp, lines);
2868 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2872 if (!scrollback_phys_max)
2875 scrollback_old = scrollback_current;
2876 scrollback_current -= lines;
2877 if (scrollback_current < 0)
2878 scrollback_current = 0;
2879 else if (scrollback_current > scrollback_max)
2880 scrollback_current = scrollback_max;
2881 if (scrollback_current == scrollback_old)
2884 if (fbcon_is_inactive(vc, info))
2887 fbcon_cursor(vc, CM_ERASE);
2889 offset = disp->yscroll - scrollback_current;
2890 limit = disp->vrows;
2891 switch (disp->scrollmode) {
2892 case SCROLL_WRAP_MOVE:
2893 info->var.vmode |= FB_VMODE_YWRAP;
2895 case SCROLL_PAN_MOVE:
2896 case SCROLL_PAN_REDRAW:
2897 limit -= vc->vc_rows;
2898 info->var.vmode &= ~FB_VMODE_YWRAP;
2903 else if (offset >= limit)
2906 ops->var.xoffset = 0;
2907 ops->var.yoffset = offset * vc->vc_font.height;
2908 ops->update_start(info);
2910 if (!scrollback_current)
2911 fbcon_cursor(vc, CM_DRAW);
2914 static int fbcon_set_origin(struct vc_data *vc)
2917 fbcon_scrolldelta(vc, softback_lines);
2921 static void fbcon_suspended(struct fb_info *info)
2923 struct vc_data *vc = NULL;
2924 struct fbcon_ops *ops = info->fbcon_par;
2926 if (!ops || ops->currcon < 0)
2928 vc = vc_cons[ops->currcon].d;
2930 /* Clear cursor, restore saved data */
2931 fbcon_cursor(vc, CM_ERASE);
2934 static void fbcon_resumed(struct fb_info *info)
2937 struct fbcon_ops *ops = info->fbcon_par;
2939 if (!ops || ops->currcon < 0)
2941 vc = vc_cons[ops->currcon].d;
2946 static void fbcon_modechanged(struct fb_info *info)
2948 struct fbcon_ops *ops = info->fbcon_par;
2953 if (!ops || ops->currcon < 0)
2955 vc = vc_cons[ops->currcon].d;
2956 if (vc->vc_mode != KD_TEXT ||
2957 registered_fb[con2fb_map[ops->currcon]] != info)
2960 p = &fb_display[vc->vc_num];
2961 set_blitting_type(vc, info);
2963 if (con_is_visible(vc)) {
2964 var_to_display(p, &info->var, info);
2965 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2966 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2967 cols /= vc->vc_font.width;
2968 rows /= vc->vc_font.height;
2969 vc_resize(vc, cols, rows);
2970 updatescrollmode(p, info, vc);
2972 scrollback_current = 0;
2974 if (!fbcon_is_inactive(vc, info)) {
2975 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2976 ops->update_start(info);
2979 fbcon_set_palette(vc, color_table);
2982 fbcon_update_softback(vc);
2986 static void fbcon_set_all_vcs(struct fb_info *info)
2988 struct fbcon_ops *ops = info->fbcon_par;
2991 int i, rows, cols, fg = -1;
2993 if (!ops || ops->currcon < 0)
2996 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2998 if (!vc || vc->vc_mode != KD_TEXT ||
2999 registered_fb[con2fb_map[i]] != info)
3002 if (con_is_visible(vc)) {
3007 p = &fb_display[vc->vc_num];
3008 set_blitting_type(vc, info);
3009 var_to_display(p, &info->var, info);
3010 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3011 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3012 cols /= vc->vc_font.width;
3013 rows /= vc->vc_font.height;
3014 vc_resize(vc, cols, rows);
3018 fbcon_modechanged(info);
3021 static int fbcon_mode_deleted(struct fb_info *info,
3022 struct fb_videomode *mode)
3024 struct fb_info *fb_info;
3026 int i, j, found = 0;
3028 /* before deletion, ensure that mode is not in use */
3029 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3033 fb_info = registered_fb[j];
3034 if (fb_info != info)
3039 if (fb_mode_is_equal(p->mode, mode)) {
3047 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3048 static int fbcon_unbind(void)
3052 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3056 fbcon_has_console_bind = 0;
3061 static inline int fbcon_unbind(void)
3065 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3067 /* called with console_lock held */
3068 static int fbcon_fb_unbind(int idx)
3070 int i, new_idx = -1, ret = 0;
3072 WARN_CONSOLE_UNLOCKED();
3074 if (!fbcon_has_console_bind)
3077 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3078 if (con2fb_map[i] != idx &&
3079 con2fb_map[i] != -1) {
3080 new_idx = con2fb_map[i];
3085 if (new_idx != -1) {
3086 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3087 if (con2fb_map[i] == idx)
3088 set_con2fb_map(i, new_idx, 0);
3091 struct fb_info *info = registered_fb[idx];
3093 /* This is sort of like set_con2fb_map, except it maps
3094 * the consoles to no device and then releases the
3095 * oldinfo to free memory and cancel the cursor blink
3096 * timer. I can imagine this just becoming part of
3097 * set_con2fb_map where new_idx is -1
3099 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3100 if (con2fb_map[i] == idx) {
3102 if (!search_fb_in_map(idx)) {
3103 ret = con2fb_release_oldinfo(vc_cons[i].d,
3107 con2fb_map[i] = idx;
3113 ret = fbcon_unbind();
3119 /* called with console_lock held */
3120 static int fbcon_fb_unregistered(struct fb_info *info)
3124 WARN_CONSOLE_UNLOCKED();
3126 if (deferred_takeover)
3130 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3131 if (con2fb_map[i] == idx)
3135 if (idx == info_idx) {
3138 for_each_registered_fb(i) {
3144 if (info_idx != -1) {
3145 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3146 if (con2fb_map[i] == -1)
3147 con2fb_map[i] = info_idx;
3151 if (primary_device == idx)
3152 primary_device = -1;
3154 if (!num_registered_fb)
3155 do_unregister_con_driver(&fb_con);
3160 /* called with console_lock held */
3161 static void fbcon_remap_all(int idx)
3165 WARN_CONSOLE_UNLOCKED();
3167 if (deferred_takeover) {
3168 for (i = first_fb_vc; i <= last_fb_vc; i++)
3169 con2fb_map_boot[i] = idx;
3170 fbcon_map_override();
3174 for (i = first_fb_vc; i <= last_fb_vc; i++)
3175 set_con2fb_map(i, idx, 0);
3177 if (con_is_bound(&fb_con)) {
3178 printk(KERN_INFO "fbcon: Remapping primary device, "
3179 "fb%i, to tty %i-%i\n", idx,
3180 first_fb_vc + 1, last_fb_vc + 1);
3185 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3186 static void fbcon_select_primary(struct fb_info *info)
3188 if (!map_override && primary_device == -1 &&
3189 fb_is_primary_device(info)) {
3192 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3193 info->fix.id, info->node);
3194 primary_device = info->node;
3196 for (i = first_fb_vc; i <= last_fb_vc; i++)
3197 con2fb_map_boot[i] = primary_device;
3199 if (con_is_bound(&fb_con)) {
3200 printk(KERN_INFO "fbcon: Remapping primary device, "
3201 "fb%i, to tty %i-%i\n", info->node,
3202 first_fb_vc + 1, last_fb_vc + 1);
3203 info_idx = primary_device;
3209 static inline void fbcon_select_primary(struct fb_info *info)
3213 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3215 /* called with console_lock held */
3216 static int fbcon_fb_registered(struct fb_info *info)
3218 int ret = 0, i, idx;
3220 WARN_CONSOLE_UNLOCKED();
3223 fbcon_select_primary(info);
3225 if (deferred_takeover) {
3226 pr_info("fbcon: Deferring console take-over\n");
3230 if (info_idx == -1) {
3231 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3232 if (con2fb_map_boot[i] == idx) {
3239 ret = do_fbcon_takeover(1);
3241 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3242 if (con2fb_map_boot[i] == idx)
3243 set_con2fb_map(i, idx, 0);
3250 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3252 struct fbcon_ops *ops = info->fbcon_par;
3255 if (!ops || ops->currcon < 0)
3258 vc = vc_cons[ops->currcon].d;
3259 if (vc->vc_mode != KD_TEXT ||
3260 registered_fb[con2fb_map[ops->currcon]] != info)
3263 if (con_is_visible(vc)) {
3267 do_unblank_screen(0);
3269 ops->blank_state = blank;
3272 static void fbcon_new_modelist(struct fb_info *info)
3276 struct fb_var_screeninfo var;
3277 const struct fb_videomode *mode;
3279 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3280 if (registered_fb[con2fb_map[i]] != info)
3282 if (!fb_display[i].mode)
3285 display_to_var(&var, &fb_display[i]);
3286 mode = fb_find_nearest_mode(fb_display[i].mode,
3288 fb_videomode_to_var(&var, mode);
3289 fbcon_set_disp(info, &var, vc->vc_num);
3293 static void fbcon_get_requirement(struct fb_info *info,
3294 struct fb_blit_caps *caps)
3302 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3304 if (vc && vc->vc_mode == KD_TEXT &&
3305 info->node == con2fb_map[i]) {
3307 caps->x |= 1 << (vc->vc_font.width - 1);
3308 caps->y |= 1 << (vc->vc_font.height - 1);
3309 charcnt = (p->userfont) ?
3310 FNTCHARCNT(p->fontdata) : 256;
3311 if (caps->len < charcnt)
3312 caps->len = charcnt;
3316 vc = vc_cons[fg_console].d;
3318 if (vc && vc->vc_mode == KD_TEXT &&
3319 info->node == con2fb_map[fg_console]) {
3320 p = &fb_display[fg_console];
3321 caps->x = 1 << (vc->vc_font.width - 1);
3322 caps->y = 1 << (vc->vc_font.height - 1);
3323 caps->len = (p->userfont) ?
3324 FNTCHARCNT(p->fontdata) : 256;
3329 static int fbcon_event_notify(struct notifier_block *self,
3330 unsigned long action, void *data)
3332 struct fb_event *event = data;
3333 struct fb_info *info = event->info;
3334 struct fb_videomode *mode;
3335 struct fb_con2fbmap *con2fb;
3336 struct fb_blit_caps *caps;
3340 * ignore all events except driver registration and deregistration
3341 * if fbcon is not active
3343 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3344 action == FB_EVENT_FB_UNREGISTERED))
3348 case FB_EVENT_SUSPEND:
3349 fbcon_suspended(info);
3351 case FB_EVENT_RESUME:
3352 fbcon_resumed(info);
3354 case FB_EVENT_MODE_CHANGE:
3355 fbcon_modechanged(info);
3357 case FB_EVENT_MODE_CHANGE_ALL:
3358 fbcon_set_all_vcs(info);
3360 case FB_EVENT_MODE_DELETE:
3362 ret = fbcon_mode_deleted(info, mode);
3364 case FB_EVENT_FB_UNBIND:
3366 ret = fbcon_fb_unbind(idx);
3368 case FB_EVENT_FB_REGISTERED:
3369 ret = fbcon_fb_registered(info);
3371 case FB_EVENT_FB_UNREGISTERED:
3372 ret = fbcon_fb_unregistered(info);
3374 case FB_EVENT_SET_CONSOLE_MAP:
3375 /* called with console lock held */
3376 con2fb = event->data;
3377 ret = set_con2fb_map(con2fb->console - 1,
3378 con2fb->framebuffer, 1);
3380 case FB_EVENT_GET_CONSOLE_MAP:
3381 con2fb = event->data;
3382 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3384 case FB_EVENT_BLANK:
3385 fbcon_fb_blanked(info, *(int *)event->data);
3387 case FB_EVENT_NEW_MODELIST:
3388 fbcon_new_modelist(info);
3390 case FB_EVENT_GET_REQ:
3392 fbcon_get_requirement(info, caps);
3394 case FB_EVENT_REMAP_ALL_CONSOLE:
3396 fbcon_remap_all(idx);
3404 * The console `switch' structure for the frame buffer based console
3407 static const struct consw fb_con = {
3408 .owner = THIS_MODULE,
3409 .con_startup = fbcon_startup,
3410 .con_init = fbcon_init,
3411 .con_deinit = fbcon_deinit,
3412 .con_clear = fbcon_clear,
3413 .con_putc = fbcon_putc,
3414 .con_putcs = fbcon_putcs,
3415 .con_cursor = fbcon_cursor,
3416 .con_scroll = fbcon_scroll,
3417 .con_switch = fbcon_switch,
3418 .con_blank = fbcon_blank,
3419 .con_font_set = fbcon_set_font,
3420 .con_font_get = fbcon_get_font,
3421 .con_font_default = fbcon_set_def_font,
3422 .con_font_copy = fbcon_copy_font,
3423 .con_set_palette = fbcon_set_palette,
3424 .con_scrolldelta = fbcon_scrolldelta,
3425 .con_set_origin = fbcon_set_origin,
3426 .con_invert_region = fbcon_invert_region,
3427 .con_screen_pos = fbcon_screen_pos,
3428 .con_getxy = fbcon_getxy,
3429 .con_resize = fbcon_resize,
3430 .con_debug_enter = fbcon_debug_enter,
3431 .con_debug_leave = fbcon_debug_leave,
3434 static struct notifier_block fbcon_event_notifier = {
3435 .notifier_call = fbcon_event_notify,
3438 static ssize_t store_rotate(struct device *device,
3439 struct device_attribute *attr, const char *buf,
3442 struct fb_info *info;
3446 if (fbcon_has_exited)
3450 idx = con2fb_map[fg_console];
3452 if (idx == -1 || registered_fb[idx] == NULL)
3455 info = registered_fb[idx];
3456 rotate = simple_strtoul(buf, last, 0);
3457 fbcon_rotate(info, rotate);
3463 static ssize_t store_rotate_all(struct device *device,
3464 struct device_attribute *attr,const char *buf,
3467 struct fb_info *info;
3471 if (fbcon_has_exited)
3475 idx = con2fb_map[fg_console];
3477 if (idx == -1 || registered_fb[idx] == NULL)
3480 info = registered_fb[idx];
3481 rotate = simple_strtoul(buf, last, 0);
3482 fbcon_rotate_all(info, rotate);
3488 static ssize_t show_rotate(struct device *device,
3489 struct device_attribute *attr,char *buf)
3491 struct fb_info *info;
3492 int rotate = 0, idx;
3494 if (fbcon_has_exited)
3498 idx = con2fb_map[fg_console];
3500 if (idx == -1 || registered_fb[idx] == NULL)
3503 info = registered_fb[idx];
3504 rotate = fbcon_get_rotate(info);
3507 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3510 static ssize_t show_cursor_blink(struct device *device,
3511 struct device_attribute *attr, char *buf)
3513 struct fb_info *info;
3514 struct fbcon_ops *ops;
3515 int idx, blink = -1;
3517 if (fbcon_has_exited)
3521 idx = con2fb_map[fg_console];
3523 if (idx == -1 || registered_fb[idx] == NULL)
3526 info = registered_fb[idx];
3527 ops = info->fbcon_par;
3532 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3535 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3538 static ssize_t store_cursor_blink(struct device *device,
3539 struct device_attribute *attr,
3540 const char *buf, size_t count)
3542 struct fb_info *info;
3546 if (fbcon_has_exited)
3550 idx = con2fb_map[fg_console];
3552 if (idx == -1 || registered_fb[idx] == NULL)
3555 info = registered_fb[idx];
3557 if (!info->fbcon_par)
3560 blink = simple_strtoul(buf, last, 0);
3563 fbcon_cursor_noblink = 0;
3564 fbcon_add_cursor_timer(info);
3566 fbcon_cursor_noblink = 1;
3567 fbcon_del_cursor_timer(info);
3575 static struct device_attribute device_attrs[] = {
3576 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3577 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3578 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3579 store_cursor_blink),
3582 static int fbcon_init_device(void)
3586 fbcon_has_sysfs = 1;
3588 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3589 error = device_create_file(fbcon_device, &device_attrs[i]);
3597 device_remove_file(fbcon_device, &device_attrs[i]);
3599 fbcon_has_sysfs = 0;
3605 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3606 static void fbcon_register_existing_fbs(struct work_struct *work)
3612 for_each_registered_fb(i)
3613 fbcon_fb_registered(registered_fb[i]);
3618 static struct notifier_block fbcon_output_nb;
3619 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3621 static int fbcon_output_notifier(struct notifier_block *nb,
3622 unsigned long action, void *data)
3624 WARN_CONSOLE_UNLOCKED();
3626 pr_info("fbcon: Taking over console\n");
3628 dummycon_unregister_output_notifier(&fbcon_output_nb);
3629 deferred_takeover = false;
3630 logo_shown = FBCON_LOGO_DONTSHOW;
3632 /* We may get called in atomic context */
3633 schedule_work(&fbcon_deferred_takeover_work);
3639 static void fbcon_start(void)
3641 WARN_CONSOLE_UNLOCKED();
3643 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3644 if (conswitchp != &dummy_con)
3645 deferred_takeover = false;
3647 if (deferred_takeover) {
3648 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3649 dummycon_register_output_notifier(&fbcon_output_nb);
3654 if (num_registered_fb) {
3657 for_each_registered_fb(i) {
3662 do_fbcon_takeover(0);
3666 static void fbcon_exit(void)
3668 struct fb_info *info;
3671 if (fbcon_has_exited)
3674 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3675 if (deferred_takeover) {
3676 dummycon_unregister_output_notifier(&fbcon_output_nb);
3677 deferred_takeover = false;
3681 kvfree((void *)softback_buf);
3684 for_each_registered_fb(i) {
3688 info = registered_fb[i];
3690 if (info->queue.func)
3691 pending = cancel_work_sync(&info->queue);
3692 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3695 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3696 if (con2fb_map[j] == i) {
3703 if (info->fbops->fb_release)
3704 info->fbops->fb_release(info, 0);
3705 module_put(info->fbops->owner);
3707 if (info->fbcon_par) {
3708 struct fbcon_ops *ops = info->fbcon_par;
3710 fbcon_del_cursor_timer(info);
3711 kfree(ops->cursor_src);
3712 kfree(ops->cursor_state.mask);
3713 kfree(info->fbcon_par);
3714 info->fbcon_par = NULL;
3717 if (info->queue.func == fb_flashcursor)
3718 info->queue.func = NULL;
3722 fbcon_has_exited = 1;
3725 void __init fb_console_init(void)
3730 fb_register_client(&fbcon_event_notifier);
3731 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3734 if (IS_ERR(fbcon_device)) {
3735 printk(KERN_WARNING "Unable to create device "
3736 "for fbcon; errno = %ld\n",
3737 PTR_ERR(fbcon_device));
3738 fbcon_device = NULL;
3740 fbcon_init_device();
3742 for (i = 0; i < MAX_NR_CONSOLES; i++)
3751 static void __exit fbcon_deinit_device(void)
3755 if (fbcon_has_sysfs) {
3756 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3757 device_remove_file(fbcon_device, &device_attrs[i]);
3759 fbcon_has_sysfs = 0;
3763 void __exit fb_console_exit(void)
3766 fb_unregister_client(&fbcon_event_notifier);
3767 fbcon_deinit_device();
3768 device_destroy(fb_class, MKDEV(0, 0));
3770 do_unregister_con_driver(&fb_con);