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
59 #include <linux/module.h>
60 #include <linux/types.h>
62 #include <linux/kernel.h>
63 #include <linux/delay.h> /* MSch: for IRQ probe */
64 #include <linux/console.h>
65 #include <linux/string.h>
67 #include <linux/slab.h>
69 #include <linux/fbcon.h>
70 #include <linux/vt_kern.h>
71 #include <linux/selection.h>
72 #include <linux/font.h>
73 #include <linux/smp.h>
74 #include <linux/init.h>
75 #include <linux/interrupt.h>
76 #include <linux/crc32.h> /* For counting font checksums */
77 #include <linux/uaccess.h>
86 * - fbcon state itself is protected by the console_lock, and the code does a
87 * pretty good job at making sure that lock is held everywhere it's needed.
89 * - access to the registered_fb array is entirely unprotected. This should use
90 * proper object lifetime handling, i.e. get/put_fb_info. This also means
91 * switching from indices to proper pointers for fb_info everywhere.
93 * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since it
94 * means concurrent access to the same fbdev from both fbcon and userspace
95 * will blow up. To fix this all fbcon calls from fbmem.c need to be moved out
96 * of fb_lock/unlock protected sections, since otherwise we'll recurse and
97 * deadlock eventually. Aside: Due to these deadlock issues the fbdev code in
98 * fbmem.c cannot use locking asserts, and there's lots of callers which get
99 * the rules wrong, e.g. fbsysfs.c entirely missed fb_lock/unlock calls too.
103 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
104 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
105 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
108 static struct fbcon_display fb_display[MAX_NR_CONSOLES];
110 static signed char con2fb_map[MAX_NR_CONSOLES];
111 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
113 static int logo_lines;
114 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
116 static int logo_shown = FBCON_LOGO_CANSHOW;
117 /* console mappings */
118 static int first_fb_vc;
119 static int last_fb_vc = MAX_NR_CONSOLES - 1;
120 static int fbcon_is_default = 1;
121 static int primary_device = -1;
122 static int fbcon_has_console_bind;
124 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
125 static int map_override;
127 static inline void fbcon_map_override(void)
132 static inline void fbcon_map_override(void)
135 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
137 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
138 static bool deferred_takeover = true;
140 #define deferred_takeover false
144 static char fontname[40];
146 /* current fb_info */
147 static int info_idx = -1;
149 /* console rotation */
150 static int initial_rotation = -1;
151 static int fbcon_has_sysfs;
152 static int margin_color;
154 static const struct consw fb_con;
156 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
158 static int fbcon_cursor_noblink;
160 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
163 * Interface used by the world
166 static const char *fbcon_startup(void);
167 static void fbcon_init(struct vc_data *vc, int init);
168 static void fbcon_deinit(struct vc_data *vc);
169 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
171 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
172 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
173 int count, int ypos, int xpos);
174 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
175 static void fbcon_cursor(struct vc_data *vc, int mode);
176 static int fbcon_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 void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
185 static void fbcon_modechanged(struct fb_info *info);
186 static void fbcon_set_all_vcs(struct fb_info *info);
187 static void fbcon_start(void);
188 static void fbcon_exit(void);
189 static struct device *fbcon_device;
191 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
192 static inline void fbcon_set_rotation(struct fb_info *info)
194 struct fbcon_ops *ops = info->fbcon_par;
196 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
197 ops->p->con_rotate < 4)
198 ops->rotate = ops->p->con_rotate;
203 static void fbcon_rotate(struct fb_info *info, u32 rotate)
205 struct fbcon_ops *ops= info->fbcon_par;
206 struct fb_info *fb_info;
208 if (!ops || ops->currcon == -1)
211 fb_info = registered_fb[con2fb_map[ops->currcon]];
213 if (info == fb_info) {
214 struct fbcon_display *p = &fb_display[ops->currcon];
217 p->con_rotate = rotate;
221 fbcon_modechanged(info);
225 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
227 struct fbcon_ops *ops = info->fbcon_par;
229 struct fbcon_display *p;
232 if (!ops || ops->currcon < 0 || rotate > 3)
235 for (i = first_fb_vc; i <= last_fb_vc; i++) {
237 if (!vc || vc->vc_mode != KD_TEXT ||
238 registered_fb[con2fb_map[i]] != info)
241 p = &fb_display[vc->vc_num];
242 p->con_rotate = rotate;
245 fbcon_set_all_vcs(info);
248 static inline void fbcon_set_rotation(struct fb_info *info)
250 struct fbcon_ops *ops = info->fbcon_par;
252 ops->rotate = FB_ROTATE_UR;
255 static void fbcon_rotate(struct fb_info *info, u32 rotate)
260 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
264 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
266 static int fbcon_get_rotate(struct fb_info *info)
268 struct fbcon_ops *ops = info->fbcon_par;
270 return (ops) ? ops->rotate : 0;
273 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
275 struct fbcon_ops *ops = info->fbcon_par;
277 return (info->state != FBINFO_STATE_RUNNING ||
278 vc->vc_mode != KD_TEXT || ops->graphics);
281 static int get_color(struct vc_data *vc, struct fb_info *info,
284 int depth = fb_get_color_depth(&info->var, &info->fix);
287 if (console_blanked) {
288 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
290 c = vc->vc_video_erase_char & charmask;
294 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
295 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
300 int col = mono_col(info);
302 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
303 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
308 color = (is_fg) ? fg : bg;
313 * Scale down 16-colors to 4 colors. Default 4-color palette
314 * is grayscale. However, simply dividing the values by 4
315 * will not work, as colors 1, 2 and 3 will be scaled-down
316 * to zero rendering them invisible. So empirically convert
317 * colors to a sane 4-level grayscale.
321 color = 0; /* black */
324 color = 2; /* white */
327 color = 1; /* gray */
330 color = 3; /* intense white */
336 * Last 8 entries of default 16-color palette is a more intense
337 * version of the first 8 (i.e., same chrominance, different
348 static void fb_flashcursor(struct work_struct *work)
350 struct fb_info *info = container_of(work, struct fb_info, queue);
351 struct fbcon_ops *ops = info->fbcon_par;
352 struct vc_data *vc = NULL;
357 /* FIXME: we should sort out the unbind locking instead */
358 /* instead we just fail to flash the cursor if we can't get
359 * the lock instead of blocking fbcon deinit */
360 ret = console_trylock();
364 if (ops && ops->currcon != -1)
365 vc = vc_cons[ops->currcon].d;
367 if (!vc || !con_is_visible(vc) ||
368 registered_fb[con2fb_map[vc->vc_num]] != info ||
374 c = scr_readw((u16 *) vc->vc_pos);
375 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
377 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
378 get_color(vc, info, c, 0));
382 static void cursor_timer_handler(struct timer_list *t)
384 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
385 struct fb_info *info = ops->info;
387 queue_work(system_power_efficient_wq, &info->queue);
388 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
391 static void fbcon_add_cursor_timer(struct fb_info *info)
393 struct fbcon_ops *ops = info->fbcon_par;
395 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
396 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
397 !fbcon_cursor_noblink) {
398 if (!info->queue.func)
399 INIT_WORK(&info->queue, fb_flashcursor);
401 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
402 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
403 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
407 static void fbcon_del_cursor_timer(struct fb_info *info)
409 struct fbcon_ops *ops = info->fbcon_par;
411 if (info->queue.func == fb_flashcursor &&
412 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
413 del_timer_sync(&ops->cursor_timer);
414 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
419 static int __init fb_console_setup(char *this_opt)
424 if (!this_opt || !*this_opt)
427 while ((options = strsep(&this_opt, ",")) != NULL) {
428 if (!strncmp(options, "font:", 5)) {
429 strlcpy(fontname, options + 5, sizeof(fontname));
433 if (!strncmp(options, "scrollback:", 11)) {
434 pr_warn("Ignoring scrollback size option\n");
438 if (!strncmp(options, "map:", 4)) {
441 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
445 (options[j++]-'0') % FB_MAX;
448 fbcon_map_override();
453 if (!strncmp(options, "vc:", 3)) {
456 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
459 if (*options++ == '-')
460 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
461 fbcon_is_default = 0;
465 if (!strncmp(options, "rotate:", 7)) {
468 initial_rotation = simple_strtoul(options, &options, 0);
469 if (initial_rotation > 3)
470 initial_rotation = 0;
474 if (!strncmp(options, "margin:", 7)) {
477 margin_color = simple_strtoul(options, &options, 0);
480 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
481 if (!strcmp(options, "nodefer")) {
482 deferred_takeover = false;
487 if (!strncmp(options, "logo-pos:", 9)) {
489 if (!strcmp(options, "center"))
490 fb_center_logo = true;
494 if (!strncmp(options, "logo-count:", 11)) {
497 fb_logo_count = simple_strtol(options, &options, 0);
504 __setup("fbcon=", fb_console_setup);
507 static int search_fb_in_map(int idx)
511 for (i = first_fb_vc; i <= last_fb_vc; i++) {
512 if (con2fb_map[i] == idx)
518 static int search_for_mapped_con(void)
522 for (i = first_fb_vc; i <= last_fb_vc; i++) {
523 if (con2fb_map[i] != -1)
529 static int do_fbcon_takeover(int show_logo)
533 if (!num_registered_fb)
537 logo_shown = FBCON_LOGO_DONTSHOW;
539 for (i = first_fb_vc; i <= last_fb_vc; i++)
540 con2fb_map[i] = info_idx;
542 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
546 for (i = first_fb_vc; i <= last_fb_vc; i++)
550 fbcon_has_console_bind = 1;
557 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
558 int cols, int rows, int new_cols, int new_rows)
560 logo_shown = FBCON_LOGO_DONTSHOW;
563 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
564 int cols, int rows, int new_cols, int new_rows)
566 /* Need to make room for the logo */
567 struct fbcon_ops *ops = info->fbcon_par;
568 int cnt, erase = vc->vc_video_erase_char, step;
569 unsigned short *save = NULL, *r, *q;
572 if (info->fbops->owner) {
573 logo_shown = FBCON_LOGO_DONTSHOW;
578 * remove underline attribute from erase character
579 * if black and white framebuffer.
581 if (fb_get_color_depth(&info->var, &info->fix) == 1)
583 logo_height = fb_prepare_logo(info, ops->rotate);
584 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
585 q = (unsigned short *) (vc->vc_origin +
586 vc->vc_size_row * rows);
587 step = logo_lines * cols;
588 for (r = q - logo_lines * cols; r < q; r++)
589 if (scr_readw(r) != vc->vc_video_erase_char)
591 if (r != q && new_rows >= rows + logo_lines) {
592 save = kmalloc(array3_size(logo_lines, new_cols, 2),
595 int i = cols < new_cols ? cols : new_cols;
596 scr_memsetw(save, erase, array3_size(logo_lines, new_cols, 2));
598 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
599 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
604 /* We can scroll screen down */
606 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
607 scr_memcpyw(r + step, r, vc->vc_size_row);
612 if (vc->state.y + logo_lines >= rows)
613 lines = rows - vc->state.y - 1;
616 vc->state.y += lines;
617 vc->vc_pos += lines * vc->vc_size_row;
620 scr_memsetw((unsigned short *) vc->vc_origin,
622 vc->vc_size_row * logo_lines);
624 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
625 fbcon_clear_margins(vc, 0);
630 q = (unsigned short *) (vc->vc_origin +
633 scr_memcpyw(q, save, array3_size(logo_lines, new_cols, 2));
634 vc->state.y += logo_lines;
635 vc->vc_pos += logo_lines * vc->vc_size_row;
639 if (logo_shown == FBCON_LOGO_DONTSHOW)
642 if (logo_lines > vc->vc_bottom) {
643 logo_shown = FBCON_LOGO_CANSHOW;
645 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
647 logo_shown = FBCON_LOGO_DRAW;
648 vc->vc_top = logo_lines;
653 #ifdef CONFIG_FB_TILEBLITTING
654 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
656 struct fbcon_ops *ops = info->fbcon_par;
658 ops->p = &fb_display[vc->vc_num];
660 if ((info->flags & FBINFO_MISC_TILEBLITTING))
661 fbcon_set_tileops(vc, info);
663 fbcon_set_rotation(info);
664 fbcon_set_bitops(ops);
668 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
672 if (info->flags & FBINFO_MISC_TILEBLITTING &&
673 info->tileops->fb_get_tilemax(info) < charcount)
679 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
681 struct fbcon_ops *ops = info->fbcon_par;
683 info->flags &= ~FBINFO_MISC_TILEBLITTING;
684 ops->p = &fb_display[vc->vc_num];
685 fbcon_set_rotation(info);
686 fbcon_set_bitops(ops);
689 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
694 #endif /* CONFIG_MISC_TILEBLITTING */
697 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
698 int unit, int oldidx)
700 struct fbcon_ops *ops = NULL;
703 if (!try_module_get(info->fbops->owner))
706 if (!err && info->fbops->fb_open &&
707 info->fbops->fb_open(info, 0))
711 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
717 ops->cur_blink_jiffies = HZ / 5;
719 info->fbcon_par = ops;
722 set_blitting_type(vc, info);
726 con2fb_map[unit] = oldidx;
727 module_put(info->fbops->owner);
733 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
734 struct fb_info *newinfo, int unit,
735 int oldidx, int found)
737 struct fbcon_ops *ops = oldinfo->fbcon_par;
740 if (oldinfo->fbops->fb_release &&
741 oldinfo->fbops->fb_release(oldinfo, 0)) {
742 con2fb_map[unit] = oldidx;
743 if (!found && newinfo->fbops->fb_release)
744 newinfo->fbops->fb_release(newinfo, 0);
746 module_put(newinfo->fbops->owner);
751 fbcon_del_cursor_timer(oldinfo);
752 kfree(ops->cursor_state.mask);
753 kfree(ops->cursor_data);
754 kfree(ops->cursor_src);
755 kfree(ops->fontbuffer);
756 kfree(oldinfo->fbcon_par);
757 oldinfo->fbcon_par = NULL;
758 module_put(oldinfo->fbops->owner);
760 If oldinfo and newinfo are driving the same hardware,
761 the fb_release() method of oldinfo may attempt to
762 restore the hardware state. This will leave the
763 newinfo in an undefined state. Thus, a call to
764 fb_set_par() may be needed for the newinfo.
766 if (newinfo && newinfo->fbops->fb_set_par) {
767 ret = newinfo->fbops->fb_set_par(newinfo);
770 printk(KERN_ERR "con2fb_release_oldinfo: "
771 "detected unhandled fb_set_par error, "
772 "error code %d\n", ret);
779 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
780 int unit, int show_logo)
782 struct fbcon_ops *ops = info->fbcon_par;
785 ops->currcon = fg_console;
787 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
788 ret = info->fbops->fb_set_par(info);
791 printk(KERN_ERR "con2fb_init_display: detected "
792 "unhandled fb_set_par error, "
793 "error code %d\n", ret);
796 ops->flags |= FBCON_FLAGS_INIT;
798 fbcon_set_disp(info, &info->var, unit);
801 struct vc_data *fg_vc = vc_cons[fg_console].d;
802 struct fb_info *fg_info =
803 registered_fb[con2fb_map[fg_console]];
805 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
806 fg_vc->vc_rows, fg_vc->vc_cols,
810 update_screen(vc_cons[fg_console].d);
814 * set_con2fb_map - map console to frame buffer device
815 * @unit: virtual console number to map
816 * @newidx: frame buffer index to map virtual console to
817 * @user: user request
819 * Maps a virtual console @unit to a frame buffer device
822 * This should be called with the console lock held.
824 static int set_con2fb_map(int unit, int newidx, int user)
826 struct vc_data *vc = vc_cons[unit].d;
827 int oldidx = con2fb_map[unit];
828 struct fb_info *info = registered_fb[newidx];
829 struct fb_info *oldinfo = NULL;
832 WARN_CONSOLE_UNLOCKED();
834 if (oldidx == newidx)
840 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
842 return do_fbcon_takeover(0);
846 oldinfo = registered_fb[oldidx];
848 found = search_fb_in_map(newidx);
850 con2fb_map[unit] = newidx;
852 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
855 * If old fb is not mapped to any of the consoles,
856 * fbcon should release it.
858 if (!err && oldinfo && !search_fb_in_map(oldidx))
859 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
863 int show_logo = (fg_console == 0 && !user &&
864 logo_shown != FBCON_LOGO_DONTSHOW);
867 fbcon_add_cursor_timer(info);
868 con2fb_map_boot[unit] = newidx;
869 con2fb_init_display(vc, info, unit, show_logo);
872 if (!search_fb_in_map(info_idx))
879 * Low Level Operations
881 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
882 static int var_to_display(struct fbcon_display *disp,
883 struct fb_var_screeninfo *var,
884 struct fb_info *info)
886 disp->xres_virtual = var->xres_virtual;
887 disp->yres_virtual = var->yres_virtual;
888 disp->bits_per_pixel = var->bits_per_pixel;
889 disp->grayscale = var->grayscale;
890 disp->nonstd = var->nonstd;
891 disp->accel_flags = var->accel_flags;
892 disp->height = var->height;
893 disp->width = var->width;
894 disp->red = var->red;
895 disp->green = var->green;
896 disp->blue = var->blue;
897 disp->transp = var->transp;
898 disp->rotate = var->rotate;
899 disp->mode = fb_match_mode(var, &info->modelist);
900 if (disp->mode == NULL)
901 /* This should not happen */
906 static void display_to_var(struct fb_var_screeninfo *var,
907 struct fbcon_display *disp)
909 fb_videomode_to_var(var, disp->mode);
910 var->xres_virtual = disp->xres_virtual;
911 var->yres_virtual = disp->yres_virtual;
912 var->bits_per_pixel = disp->bits_per_pixel;
913 var->grayscale = disp->grayscale;
914 var->nonstd = disp->nonstd;
915 var->accel_flags = disp->accel_flags;
916 var->height = disp->height;
917 var->width = disp->width;
918 var->red = disp->red;
919 var->green = disp->green;
920 var->blue = disp->blue;
921 var->transp = disp->transp;
922 var->rotate = disp->rotate;
925 static const char *fbcon_startup(void)
927 const char *display_desc = "frame buffer device";
928 struct fbcon_display *p = &fb_display[fg_console];
929 struct vc_data *vc = vc_cons[fg_console].d;
930 const struct font_desc *font = NULL;
931 struct module *owner;
932 struct fb_info *info = NULL;
933 struct fbcon_ops *ops;
937 * If num_registered_fb is zero, this is a call for the dummy part.
938 * The frame buffer devices weren't initialized yet.
940 if (!num_registered_fb || info_idx == -1)
943 * Instead of blindly using registered_fb[0], we use info_idx, set by
946 info = registered_fb[info_idx];
950 owner = info->fbops->owner;
951 if (!try_module_get(owner))
953 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
958 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
966 ops->cur_rotate = -1;
967 ops->cur_blink_jiffies = HZ / 5;
969 info->fbcon_par = ops;
971 p->con_rotate = initial_rotation;
972 if (p->con_rotate == -1)
973 p->con_rotate = info->fbcon_rotate_hint;
974 if (p->con_rotate == -1)
975 p->con_rotate = FB_ROTATE_UR;
977 set_blitting_type(vc, info);
979 /* Setup default font */
980 if (!p->fontdata && !vc->vc_font.data) {
981 if (!fontname[0] || !(font = find_font(fontname)))
982 font = get_default_font(info->var.xres,
985 info->pixmap.blit_y);
986 vc->vc_font.width = font->width;
987 vc->vc_font.height = font->height;
988 vc->vc_font.data = (void *)(p->fontdata = font->data);
989 vc->vc_font.charcount = font->charcount;
991 p->fontdata = vc->vc_font.data;
994 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
995 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
996 cols /= vc->vc_font.width;
997 rows /= vc->vc_font.height;
998 vc_resize(vc, cols, rows);
1000 pr_debug("mode: %s\n", info->fix.id);
1001 pr_debug("visual: %d\n", info->fix.visual);
1002 pr_debug("res: %dx%d-%d\n", info->var.xres,
1004 info->var.bits_per_pixel);
1006 fbcon_add_cursor_timer(info);
1007 return display_desc;
1010 static void fbcon_init(struct vc_data *vc, int init)
1012 struct fb_info *info;
1013 struct fbcon_ops *ops;
1014 struct vc_data **default_mode = vc->vc_display_fg;
1015 struct vc_data *svc = *default_mode;
1016 struct fbcon_display *t, *p = &fb_display[vc->vc_num];
1017 int logo = 1, new_rows, new_cols, rows, cols;
1020 if (WARN_ON(info_idx == -1))
1023 if (con2fb_map[vc->vc_num] == -1)
1024 con2fb_map[vc->vc_num] = info_idx;
1026 info = registered_fb[con2fb_map[vc->vc_num]];
1028 if (logo_shown < 0 && console_loglevel <= CONSOLE_LOGLEVEL_QUIET)
1029 logo_shown = FBCON_LOGO_DONTSHOW;
1031 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1032 (info->fix.type == FB_TYPE_TEXT))
1035 if (var_to_display(p, &info->var, info))
1038 if (!info->fbcon_par)
1039 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1041 /* If we are not the first console on this
1042 fb, copy the font from that console */
1043 t = &fb_display[fg_console];
1046 struct vc_data *fvc = vc_cons[fg_console].d;
1048 vc->vc_font.data = (void *)(p->fontdata =
1050 vc->vc_font.width = fvc->vc_font.width;
1051 vc->vc_font.height = fvc->vc_font.height;
1052 vc->vc_font.charcount = fvc->vc_font.charcount;
1053 p->userfont = t->userfont;
1056 REFCOUNT(p->fontdata)++;
1058 const struct font_desc *font = NULL;
1060 if (!fontname[0] || !(font = find_font(fontname)))
1061 font = get_default_font(info->var.xres,
1063 info->pixmap.blit_x,
1064 info->pixmap.blit_y);
1065 vc->vc_font.width = font->width;
1066 vc->vc_font.height = font->height;
1067 vc->vc_font.data = (void *)(p->fontdata = font->data);
1068 vc->vc_font.charcount = font->charcount;
1072 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1073 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1074 if (vc->vc_font.charcount == 256) {
1075 vc->vc_hi_font_mask = 0;
1077 vc->vc_hi_font_mask = 0x100;
1078 if (vc->vc_can_do_color)
1079 vc->vc_complement_mask <<= 1;
1082 if (!*svc->vc_uni_pagedir_loc)
1083 con_set_default_unimap(svc);
1084 if (!*vc->vc_uni_pagedir_loc)
1085 con_copy_unimap(vc, svc);
1087 ops = info->fbcon_par;
1088 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1090 p->con_rotate = initial_rotation;
1091 if (p->con_rotate == -1)
1092 p->con_rotate = info->fbcon_rotate_hint;
1093 if (p->con_rotate == -1)
1094 p->con_rotate = FB_ROTATE_UR;
1096 set_blitting_type(vc, info);
1100 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1101 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1102 new_cols /= vc->vc_font.width;
1103 new_rows /= vc->vc_font.height;
1106 * We must always set the mode. The mode of the previous console
1107 * driver could be in the same resolution but we are using different
1108 * hardware so we have to initialize the hardware.
1110 * We need to do it in fbcon_init() to prevent screen corruption.
1112 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1113 if (info->fbops->fb_set_par &&
1114 !(ops->flags & FBCON_FLAGS_INIT)) {
1115 ret = info->fbops->fb_set_par(info);
1118 printk(KERN_ERR "fbcon_init: detected "
1119 "unhandled fb_set_par error, "
1120 "error code %d\n", ret);
1123 ops->flags |= FBCON_FLAGS_INIT;
1129 * ++guenther: console.c:vc_allocate() relies on initializing
1130 * vc_{cols,rows}, but we must not set those if we are only
1131 * resizing the console.
1134 vc->vc_cols = new_cols;
1135 vc->vc_rows = new_rows;
1137 vc_resize(vc, new_cols, new_rows);
1140 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1142 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1143 ops->rotate = FB_ROTATE_UR;
1144 set_blitting_type(vc, info);
1147 ops->p = &fb_display[fg_console];
1150 static void fbcon_free_font(struct fbcon_display *p, bool freefont)
1152 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1153 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1158 static void set_vc_hi_font(struct vc_data *vc, bool set);
1160 static void fbcon_deinit(struct vc_data *vc)
1162 struct fbcon_display *p = &fb_display[vc->vc_num];
1163 struct fb_info *info;
1164 struct fbcon_ops *ops;
1166 bool free_font = true;
1168 idx = con2fb_map[vc->vc_num];
1173 info = registered_fb[idx];
1178 if (info->flags & FBINFO_MISC_FIRMWARE)
1180 ops = info->fbcon_par;
1185 if (con_is_visible(vc))
1186 fbcon_del_cursor_timer(info);
1188 ops->flags &= ~FBCON_FLAGS_INIT;
1191 fbcon_free_font(p, free_font);
1193 vc->vc_font.data = NULL;
1195 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1196 set_vc_hi_font(vc, false);
1198 if (!con_is_bound(&fb_con))
1201 if (vc->vc_num == logo_shown)
1202 logo_shown = FBCON_LOGO_CANSHOW;
1207 /* ====================================================================== */
1209 /* fbcon_XXX routines - interface used by the world
1211 * This system is now divided into two levels because of complications
1212 * caused by hardware scrolling. Top level functions:
1214 * fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1216 * handles y values in range [0, scr_height-1] that correspond to real
1217 * screen positions. y_wrap shift means that first line of bitmap may be
1218 * anywhere on this display. These functions convert lineoffsets to
1219 * bitmap offsets and deal with the wrap-around case by splitting blits.
1221 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1222 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1226 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1227 * Implies should only really hardware scroll in rows. Only reason for
1228 * restriction is simplicity & efficiency at the moment.
1231 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1234 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1235 struct fbcon_ops *ops = info->fbcon_par;
1237 struct fbcon_display *p = &fb_display[vc->vc_num];
1240 if (fbcon_is_inactive(vc, info))
1243 if (!height || !width)
1246 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1249 * If the font dimensions are not an integral of the display
1250 * dimensions then the ops->clear below won't end up clearing
1251 * the margins. Call clear_margins here in case the logo
1252 * bitmap stretched into the margin area.
1254 fbcon_clear_margins(vc, 0);
1257 /* Split blits that cross physical y_wrap boundary */
1259 y_break = p->vrows - p->yscroll;
1260 if (sy < y_break && sy + height - 1 >= y_break) {
1261 u_int b = y_break - sy;
1262 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1263 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1266 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1269 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1270 int count, int ypos, int xpos)
1272 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1273 struct fbcon_display *p = &fb_display[vc->vc_num];
1274 struct fbcon_ops *ops = info->fbcon_par;
1276 if (!fbcon_is_inactive(vc, info))
1277 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1278 get_color(vc, info, scr_readw(s), 1),
1279 get_color(vc, info, scr_readw(s), 0));
1282 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1286 scr_writew(c, &chr);
1287 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1290 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1292 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1293 struct fbcon_ops *ops = info->fbcon_par;
1295 if (!fbcon_is_inactive(vc, info))
1296 ops->clear_margins(vc, info, margin_color, bottom_only);
1299 static void fbcon_cursor(struct vc_data *vc, int mode)
1301 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1302 struct fbcon_ops *ops = info->fbcon_par;
1303 int c = scr_readw((u16 *) vc->vc_pos);
1305 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1307 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1310 if (vc->vc_cursor_type & CUR_SW)
1311 fbcon_del_cursor_timer(info);
1313 fbcon_add_cursor_timer(info);
1315 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1320 ops->cursor(vc, info, mode, get_color(vc, info, c, 1),
1321 get_color(vc, info, c, 0));
1324 static int scrollback_phys_max = 0;
1325 static int scrollback_max = 0;
1326 static int scrollback_current = 0;
1328 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1331 struct fbcon_display *p, *t;
1332 struct vc_data **default_mode, *vc;
1333 struct vc_data *svc;
1334 struct fbcon_ops *ops = info->fbcon_par;
1337 p = &fb_display[unit];
1339 if (var_to_display(p, var, info))
1342 vc = vc_cons[unit].d;
1347 default_mode = vc->vc_display_fg;
1348 svc = *default_mode;
1349 t = &fb_display[svc->vc_num];
1351 if (!vc->vc_font.data) {
1352 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1353 vc->vc_font.width = (*default_mode)->vc_font.width;
1354 vc->vc_font.height = (*default_mode)->vc_font.height;
1355 vc->vc_font.charcount = (*default_mode)->vc_font.charcount;
1356 p->userfont = t->userfont;
1358 REFCOUNT(p->fontdata)++;
1361 var->activate = FB_ACTIVATE_NOW;
1362 info->var.activate = var->activate;
1363 var->yoffset = info->var.yoffset;
1364 var->xoffset = info->var.xoffset;
1365 fb_set_var(info, var);
1366 ops->var = info->var;
1367 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1368 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1369 if (vc->vc_font.charcount == 256) {
1370 vc->vc_hi_font_mask = 0;
1372 vc->vc_hi_font_mask = 0x100;
1373 if (vc->vc_can_do_color)
1374 vc->vc_complement_mask <<= 1;
1377 if (!*svc->vc_uni_pagedir_loc)
1378 con_set_default_unimap(svc);
1379 if (!*vc->vc_uni_pagedir_loc)
1380 con_copy_unimap(vc, svc);
1382 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1383 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1384 cols /= vc->vc_font.width;
1385 rows /= vc->vc_font.height;
1386 vc_resize(vc, cols, rows);
1388 if (con_is_visible(vc)) {
1393 static void fbcon_redraw(struct vc_data *vc, struct fbcon_display *p,
1394 int line, int count, int offset)
1396 unsigned short *d = (unsigned short *)
1397 (vc->vc_origin + vc->vc_size_row * line);
1398 unsigned short *s = d + offset;
1401 unsigned short *start = s;
1402 unsigned short *le = advance_row(s, 1);
1405 unsigned short attr = 1;
1409 if (attr != (c & 0xff00)) {
1412 fbcon_putcs(vc, start, s - start,
1418 if (c == scr_readw(d)) {
1420 fbcon_putcs(vc, start, s - start,
1430 console_conditional_schedule();
1435 fbcon_putcs(vc, start, s - start, line, x);
1436 console_conditional_schedule();
1441 /* NOTE: We subtract two lines from these pointers */
1442 s -= vc->vc_size_row;
1443 d -= vc->vc_size_row;
1448 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1449 enum con_scroll dir, unsigned int count)
1451 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1452 struct fbcon_display *p = &fb_display[vc->vc_num];
1454 if (fbcon_is_inactive(vc, info))
1457 fbcon_cursor(vc, CM_ERASE);
1460 * ++Geert: Only use ywrap/ypan if the console is in text mode
1461 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1462 * whole screen (prevents flicker).
1467 if (count > vc->vc_rows) /* Maximum realistic size */
1468 count = vc->vc_rows;
1469 fbcon_redraw(vc, p, t, b - t - count,
1470 count * vc->vc_cols);
1471 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1472 scr_memsetw((unsigned short *) (vc->vc_origin +
1475 vc->vc_video_erase_char,
1476 vc->vc_size_row * count);
1480 if (count > vc->vc_rows) /* Maximum realistic size */
1481 count = vc->vc_rows;
1482 fbcon_redraw(vc, p, b - 1, b - t - count,
1483 -count * vc->vc_cols);
1484 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1485 scr_memsetw((unsigned short *) (vc->vc_origin +
1488 vc->vc_video_erase_char,
1489 vc->vc_size_row * count);
1495 static void updatescrollmode(struct fbcon_display *p,
1496 struct fb_info *info,
1499 struct fbcon_ops *ops = info->fbcon_par;
1500 int fh = vc->vc_font.height;
1501 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1502 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1503 info->var.xres_virtual);
1505 p->vrows = vyres/fh;
1506 if (yres > (fh * (vc->vc_rows + 1)))
1507 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1508 if ((yres % fh) && (vyres % fh < yres % fh))
1512 #define PITCH(w) (((w) + 7) >> 3)
1513 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
1515 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1516 unsigned int height, unsigned int user)
1518 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1519 struct fbcon_ops *ops = info->fbcon_par;
1520 struct fbcon_display *p = &fb_display[vc->vc_num];
1521 struct fb_var_screeninfo var = info->var;
1522 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
1524 if (p->userfont && FNTSIZE(vc->vc_font.data)) {
1526 int pitch = PITCH(vc->vc_font.width);
1529 * If user font, ensure that a possible change to user font
1530 * height or width will not allow a font data out-of-bounds access.
1531 * NOTE: must use original charcount in calculation as font
1532 * charcount can change and cannot be used to determine the
1533 * font data allocated size.
1537 size = CALC_FONTSZ(vc->vc_font.height, pitch, vc->vc_font.charcount);
1538 if (size > FNTSIZE(vc->vc_font.data))
1542 virt_w = FBCON_SWAP(ops->rotate, width, height);
1543 virt_h = FBCON_SWAP(ops->rotate, height, width);
1544 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
1545 vc->vc_font.height);
1546 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
1548 var.xres = virt_w * virt_fw;
1549 var.yres = virt_h * virt_fh;
1550 x_diff = info->var.xres - var.xres;
1551 y_diff = info->var.yres - var.yres;
1552 if (x_diff < 0 || x_diff > virt_fw ||
1553 y_diff < 0 || y_diff > virt_fh) {
1554 const struct fb_videomode *mode;
1556 pr_debug("attempting resize %ix%i\n", var.xres, var.yres);
1557 mode = fb_find_best_mode(&var, &info->modelist);
1560 display_to_var(&var, p);
1561 fb_videomode_to_var(&var, mode);
1563 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
1566 pr_debug("resize now %ix%i\n", var.xres, var.yres);
1567 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1568 var.activate = FB_ACTIVATE_NOW |
1570 fb_set_var(info, &var);
1572 var_to_display(p, &info->var, info);
1573 ops->var = info->var;
1575 updatescrollmode(p, info, vc);
1579 static int fbcon_switch(struct vc_data *vc)
1581 struct fb_info *info, *old_info = NULL;
1582 struct fbcon_ops *ops;
1583 struct fbcon_display *p = &fb_display[vc->vc_num];
1584 struct fb_var_screeninfo var;
1585 int i, ret, prev_console;
1587 info = registered_fb[con2fb_map[vc->vc_num]];
1588 ops = info->fbcon_par;
1590 if (logo_shown >= 0) {
1591 struct vc_data *conp2 = vc_cons[logo_shown].d;
1593 if (conp2->vc_top == logo_lines
1594 && conp2->vc_bottom == conp2->vc_rows)
1596 logo_shown = FBCON_LOGO_CANSHOW;
1599 prev_console = ops->currcon;
1600 if (prev_console != -1)
1601 old_info = registered_fb[con2fb_map[prev_console]];
1603 * FIXME: If we have multiple fbdev's loaded, we need to
1604 * update all info->currcon. Perhaps, we can place this
1605 * in a centralized structure, but this might break some
1608 * info->currcon = vc->vc_num;
1610 for_each_registered_fb(i) {
1611 if (registered_fb[i]->fbcon_par) {
1612 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
1614 o->currcon = vc->vc_num;
1617 memset(&var, 0, sizeof(struct fb_var_screeninfo));
1618 display_to_var(&var, p);
1619 var.activate = FB_ACTIVATE_NOW;
1622 * make sure we don't unnecessarily trip the memcmp()
1625 info->var.activate = var.activate;
1626 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
1627 fb_set_var(info, &var);
1628 ops->var = info->var;
1630 if (old_info != NULL && (old_info != info ||
1631 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
1632 if (info->fbops->fb_set_par) {
1633 ret = info->fbops->fb_set_par(info);
1636 printk(KERN_ERR "fbcon_switch: detected "
1637 "unhandled fb_set_par error, "
1638 "error code %d\n", ret);
1641 if (old_info != info)
1642 fbcon_del_cursor_timer(old_info);
1645 if (fbcon_is_inactive(vc, info) ||
1646 ops->blank_state != FB_BLANK_UNBLANK)
1647 fbcon_del_cursor_timer(info);
1649 fbcon_add_cursor_timer(info);
1651 set_blitting_type(vc, info);
1652 ops->cursor_reset = 1;
1654 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1655 ops->rotate = FB_ROTATE_UR;
1656 set_blitting_type(vc, info);
1659 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1660 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1662 if (vc->vc_font.charcount > 256)
1663 vc->vc_complement_mask <<= 1;
1665 updatescrollmode(p, info, vc);
1667 scrollback_phys_max = 0;
1669 scrollback_current = 0;
1671 if (!fbcon_is_inactive(vc, info)) {
1672 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
1673 ops->update_start(info);
1676 fbcon_set_palette(vc, color_table);
1677 fbcon_clear_margins(vc, 0);
1679 if (logo_shown == FBCON_LOGO_DRAW) {
1681 logo_shown = fg_console;
1682 /* This is protected above by initmem_freed */
1683 fb_show_logo(info, ops->rotate);
1685 vc->vc_origin + vc->vc_size_row * vc->vc_top,
1686 vc->vc_size_row * (vc->vc_bottom -
1693 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
1697 unsigned short charmask = vc->vc_hi_font_mask ?
1699 unsigned short oldc;
1701 oldc = vc->vc_video_erase_char;
1702 vc->vc_video_erase_char &= charmask;
1703 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
1704 vc->vc_video_erase_char = oldc;
1708 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
1710 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1711 struct fbcon_ops *ops = info->fbcon_par;
1714 struct fb_var_screeninfo var = info->var;
1719 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE |
1720 FB_ACTIVATE_KD_TEXT;
1721 fb_set_var(info, &var);
1723 ops->var = info->var;
1727 if (!fbcon_is_inactive(vc, info)) {
1728 if (ops->blank_state != blank) {
1729 ops->blank_state = blank;
1730 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
1731 ops->cursor_flash = (!blank);
1733 if (fb_blank(info, blank))
1734 fbcon_generic_blank(vc, info, blank);
1741 if (mode_switch || fbcon_is_inactive(vc, info) ||
1742 ops->blank_state != FB_BLANK_UNBLANK)
1743 fbcon_del_cursor_timer(info);
1745 fbcon_add_cursor_timer(info);
1750 static int fbcon_debug_enter(struct vc_data *vc)
1752 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1753 struct fbcon_ops *ops = info->fbcon_par;
1755 ops->save_graphics = ops->graphics;
1757 if (info->fbops->fb_debug_enter)
1758 info->fbops->fb_debug_enter(info);
1759 fbcon_set_palette(vc, color_table);
1763 static int fbcon_debug_leave(struct vc_data *vc)
1765 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1766 struct fbcon_ops *ops = info->fbcon_par;
1768 ops->graphics = ops->save_graphics;
1769 if (info->fbops->fb_debug_leave)
1770 info->fbops->fb_debug_leave(info);
1774 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
1776 u8 *fontdata = vc->vc_font.data;
1777 u8 *data = font->data;
1780 font->width = vc->vc_font.width;
1781 font->height = vc->vc_font.height;
1782 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
1786 if (font->width <= 8) {
1787 j = vc->vc_font.height;
1788 if (font->charcount * j > FNTSIZE(fontdata))
1791 for (i = 0; i < font->charcount; i++) {
1792 memcpy(data, fontdata, j);
1793 memset(data + j, 0, 32 - j);
1797 } else if (font->width <= 16) {
1798 j = vc->vc_font.height * 2;
1799 if (font->charcount * j > FNTSIZE(fontdata))
1802 for (i = 0; i < font->charcount; i++) {
1803 memcpy(data, fontdata, j);
1804 memset(data + j, 0, 64 - j);
1808 } else if (font->width <= 24) {
1809 if (font->charcount * (vc->vc_font.height * sizeof(u32)) > FNTSIZE(fontdata))
1812 for (i = 0; i < font->charcount; i++) {
1813 for (j = 0; j < vc->vc_font.height; j++) {
1814 *data++ = fontdata[0];
1815 *data++ = fontdata[1];
1816 *data++ = fontdata[2];
1817 fontdata += sizeof(u32);
1819 memset(data, 0, 3 * (32 - j));
1820 data += 3 * (32 - j);
1823 j = vc->vc_font.height * 4;
1824 if (font->charcount * j > FNTSIZE(fontdata))
1827 for (i = 0; i < font->charcount; i++) {
1828 memcpy(data, fontdata, j);
1829 memset(data + j, 0, 128 - j);
1837 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
1838 static void set_vc_hi_font(struct vc_data *vc, bool set)
1841 vc->vc_hi_font_mask = 0;
1842 if (vc->vc_can_do_color) {
1843 vc->vc_complement_mask >>= 1;
1844 vc->vc_s_complement_mask >>= 1;
1847 /* ++Edmund: reorder the attribute bits */
1848 if (vc->vc_can_do_color) {
1849 unsigned short *cp =
1850 (unsigned short *) vc->vc_origin;
1851 int count = vc->vc_screenbuf_size / 2;
1853 for (; count > 0; count--, cp++) {
1855 scr_writew(((c & 0xfe00) >> 1) |
1858 c = vc->vc_video_erase_char;
1859 vc->vc_video_erase_char =
1860 ((c & 0xfe00) >> 1) | (c & 0xff);
1864 vc->vc_hi_font_mask = 0x100;
1865 if (vc->vc_can_do_color) {
1866 vc->vc_complement_mask <<= 1;
1867 vc->vc_s_complement_mask <<= 1;
1870 /* ++Edmund: reorder the attribute bits */
1872 unsigned short *cp =
1873 (unsigned short *) vc->vc_origin;
1874 int count = vc->vc_screenbuf_size / 2;
1876 for (; count > 0; count--, cp++) {
1877 unsigned short newc;
1879 if (vc->vc_can_do_color)
1881 ((c & 0xff00) << 1) | (c &
1885 scr_writew(newc, cp);
1887 c = vc->vc_video_erase_char;
1888 if (vc->vc_can_do_color) {
1889 vc->vc_video_erase_char =
1890 ((c & 0xff00) << 1) | (c & 0xff);
1893 vc->vc_video_erase_char = c & ~0x100;
1898 static int fbcon_do_set_font(struct vc_data *vc, int w, int h, int charcount,
1899 const u8 * data, int userfont)
1901 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1902 struct fbcon_ops *ops = info->fbcon_par;
1903 struct fbcon_display *p = &fb_display[vc->vc_num];
1905 char *old_data = NULL;
1907 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
1909 old_data = vc->vc_font.data;
1910 vc->vc_font.data = (void *)(p->fontdata = data);
1911 if ((p->userfont = userfont))
1913 vc->vc_font.width = w;
1914 vc->vc_font.height = h;
1915 vc->vc_font.charcount = charcount;
1916 if (vc->vc_hi_font_mask && charcount == 256)
1917 set_vc_hi_font(vc, false);
1918 else if (!vc->vc_hi_font_mask && charcount == 512)
1919 set_vc_hi_font(vc, true);
1924 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1925 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1928 vc_resize(vc, cols, rows);
1929 } else if (con_is_visible(vc)
1930 && vc->vc_mode == KD_TEXT) {
1931 fbcon_clear_margins(vc, 0);
1935 if (old_data && (--REFCOUNT(old_data) == 0))
1936 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
1941 * User asked to set font; we are guaranteed that
1942 * a) width and height are in range 1..32
1943 * b) charcount does not exceed 512
1944 * but lets not assume that, since someone might someday want to use larger
1945 * fonts. And charcount of 512 is small for unicode support.
1947 * However, user space gives the font in 32 rows , regardless of
1948 * actual font height. So a new API is needed if support for larger fonts
1949 * is ever implemented.
1952 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
1955 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1956 unsigned charcount = font->charcount;
1957 int w = font->width;
1958 int h = font->height;
1961 u8 *new_data, *data = font->data;
1962 int pitch = PITCH(font->width);
1964 /* Is there a reason why fbconsole couldn't handle any charcount >256?
1965 * If not this check should be changed to charcount < 256 */
1966 if (charcount != 256 && charcount != 512)
1969 /* Make sure drawing engine can handle the font */
1970 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
1971 !(info->pixmap.blit_y & (1 << (font->height - 1))))
1974 /* Make sure driver can handle the font length */
1975 if (fbcon_invalid_charcount(info, charcount))
1978 size = CALC_FONTSZ(h, pitch, charcount);
1980 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
1985 memset(new_data, 0, FONT_EXTRA_WORDS * sizeof(int));
1987 new_data += FONT_EXTRA_WORDS * sizeof(int);
1988 FNTSIZE(new_data) = size;
1989 REFCOUNT(new_data) = 0; /* usage counter */
1990 for (i=0; i< charcount; i++) {
1991 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
1994 /* Since linux has a nice crc32 function use it for counting font
1996 csum = crc32(0, new_data, size);
1998 FNTSUM(new_data) = csum;
1999 /* Check if the same font is on some other console already */
2000 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2001 struct vc_data *tmp = vc_cons[i].d;
2003 if (fb_display[i].userfont &&
2004 fb_display[i].fontdata &&
2005 FNTSUM(fb_display[i].fontdata) == csum &&
2006 FNTSIZE(fb_display[i].fontdata) == size &&
2007 tmp->vc_font.width == w &&
2008 !memcmp(fb_display[i].fontdata, new_data, size)) {
2009 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2010 new_data = (u8 *)fb_display[i].fontdata;
2014 return fbcon_do_set_font(vc, font->width, font->height, charcount, new_data, 1);
2017 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2019 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2020 const struct font_desc *f;
2023 f = get_default_font(info->var.xres, info->var.yres,
2024 info->pixmap.blit_x, info->pixmap.blit_y);
2025 else if (!(f = find_font(name)))
2028 font->width = f->width;
2029 font->height = f->height;
2030 return fbcon_do_set_font(vc, f->width, f->height, f->charcount, f->data, 0);
2033 static u16 palette_red[16];
2034 static u16 palette_green[16];
2035 static u16 palette_blue[16];
2037 static struct fb_cmap palette_cmap = {
2038 0, 16, palette_red, palette_green, palette_blue, NULL
2041 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2043 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2047 if (fbcon_is_inactive(vc, info))
2050 if (!con_is_visible(vc))
2053 depth = fb_get_color_depth(&info->var, &info->fix);
2055 for (i = j = 0; i < 16; i++) {
2057 val = vc->vc_palette[j++];
2058 palette_red[k] = (val << 8) | val;
2059 val = vc->vc_palette[j++];
2060 palette_green[k] = (val << 8) | val;
2061 val = vc->vc_palette[j++];
2062 palette_blue[k] = (val << 8) | val;
2064 palette_cmap.len = 16;
2065 palette_cmap.start = 0;
2067 * If framebuffer is capable of less than 16 colors,
2068 * use default palette of fbcon.
2071 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2073 fb_set_cmap(&palette_cmap, info);
2076 static u16 *fbcon_screen_pos(const struct vc_data *vc, int offset)
2078 return (u16 *) (vc->vc_origin + offset);
2081 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2087 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2088 unsigned long offset = (pos - vc->vc_origin) / 2;
2090 x = offset % vc->vc_cols;
2091 y = offset / vc->vc_cols;
2092 ret = pos + (vc->vc_cols - x) * 2;
2094 /* Should not happen */
2096 ret = vc->vc_origin;
2105 /* As we might be inside of softback, we may work with non-contiguous buffer,
2106 that's why we have to use a separate routine. */
2107 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2110 u16 a = scr_readw(p);
2111 if (!vc->vc_can_do_color)
2113 else if (vc->vc_hi_font_mask == 0x100)
2114 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2115 (((a) & 0x0e00) << 4);
2117 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2118 (((a) & 0x0700) << 4);
2123 void fbcon_suspended(struct fb_info *info)
2125 struct vc_data *vc = NULL;
2126 struct fbcon_ops *ops = info->fbcon_par;
2128 if (!ops || ops->currcon < 0)
2130 vc = vc_cons[ops->currcon].d;
2132 /* Clear cursor, restore saved data */
2133 fbcon_cursor(vc, CM_ERASE);
2136 void fbcon_resumed(struct fb_info *info)
2139 struct fbcon_ops *ops = info->fbcon_par;
2141 if (!ops || ops->currcon < 0)
2143 vc = vc_cons[ops->currcon].d;
2148 static void fbcon_modechanged(struct fb_info *info)
2150 struct fbcon_ops *ops = info->fbcon_par;
2152 struct fbcon_display *p;
2155 if (!ops || ops->currcon < 0)
2157 vc = vc_cons[ops->currcon].d;
2158 if (vc->vc_mode != KD_TEXT ||
2159 registered_fb[con2fb_map[ops->currcon]] != info)
2162 p = &fb_display[vc->vc_num];
2163 set_blitting_type(vc, info);
2165 if (con_is_visible(vc)) {
2166 var_to_display(p, &info->var, info);
2167 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2168 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2169 cols /= vc->vc_font.width;
2170 rows /= vc->vc_font.height;
2171 vc_resize(vc, cols, rows);
2172 updatescrollmode(p, info, vc);
2174 scrollback_current = 0;
2176 if (!fbcon_is_inactive(vc, info)) {
2177 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2178 ops->update_start(info);
2181 fbcon_set_palette(vc, color_table);
2186 static void fbcon_set_all_vcs(struct fb_info *info)
2188 struct fbcon_ops *ops = info->fbcon_par;
2190 struct fbcon_display *p;
2191 int i, rows, cols, fg = -1;
2193 if (!ops || ops->currcon < 0)
2196 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2198 if (!vc || vc->vc_mode != KD_TEXT ||
2199 registered_fb[con2fb_map[i]] != info)
2202 if (con_is_visible(vc)) {
2207 p = &fb_display[vc->vc_num];
2208 set_blitting_type(vc, info);
2209 var_to_display(p, &info->var, info);
2210 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2211 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2212 cols /= vc->vc_font.width;
2213 rows /= vc->vc_font.height;
2214 vc_resize(vc, cols, rows);
2218 fbcon_modechanged(info);
2222 void fbcon_update_vcs(struct fb_info *info, bool all)
2225 fbcon_set_all_vcs(info);
2227 fbcon_modechanged(info);
2229 EXPORT_SYMBOL(fbcon_update_vcs);
2231 int fbcon_mode_deleted(struct fb_info *info,
2232 struct fb_videomode *mode)
2234 struct fb_info *fb_info;
2235 struct fbcon_display *p;
2236 int i, j, found = 0;
2238 /* before deletion, ensure that mode is not in use */
2239 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2243 fb_info = registered_fb[j];
2244 if (fb_info != info)
2249 if (fb_mode_is_equal(p->mode, mode)) {
2257 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2258 static void fbcon_unbind(void)
2262 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2266 fbcon_has_console_bind = 0;
2269 static inline void fbcon_unbind(void) {}
2270 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2272 /* called with console_lock held */
2273 void fbcon_fb_unbind(struct fb_info *info)
2275 int i, new_idx = -1, ret = 0;
2276 int idx = info->node;
2278 WARN_CONSOLE_UNLOCKED();
2280 if (!fbcon_has_console_bind)
2283 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2284 if (con2fb_map[i] != idx &&
2285 con2fb_map[i] != -1) {
2286 new_idx = con2fb_map[i];
2291 if (new_idx != -1) {
2292 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2293 if (con2fb_map[i] == idx)
2294 set_con2fb_map(i, new_idx, 0);
2297 struct fb_info *info = registered_fb[idx];
2299 /* This is sort of like set_con2fb_map, except it maps
2300 * the consoles to no device and then releases the
2301 * oldinfo to free memory and cancel the cursor blink
2302 * timer. I can imagine this just becoming part of
2303 * set_con2fb_map where new_idx is -1
2305 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2306 if (con2fb_map[i] == idx) {
2308 if (!search_fb_in_map(idx)) {
2309 ret = con2fb_release_oldinfo(vc_cons[i].d,
2313 con2fb_map[i] = idx;
2323 /* called with console_lock held */
2324 void fbcon_fb_unregistered(struct fb_info *info)
2328 WARN_CONSOLE_UNLOCKED();
2330 if (deferred_takeover)
2334 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2335 if (con2fb_map[i] == idx)
2339 if (idx == info_idx) {
2342 for_each_registered_fb(i) {
2348 if (info_idx != -1) {
2349 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2350 if (con2fb_map[i] == -1)
2351 con2fb_map[i] = info_idx;
2355 if (primary_device == idx)
2356 primary_device = -1;
2358 if (!num_registered_fb)
2359 do_unregister_con_driver(&fb_con);
2362 void fbcon_remap_all(struct fb_info *info)
2364 int i, idx = info->node;
2367 if (deferred_takeover) {
2368 for (i = first_fb_vc; i <= last_fb_vc; i++)
2369 con2fb_map_boot[i] = idx;
2370 fbcon_map_override();
2375 for (i = first_fb_vc; i <= last_fb_vc; i++)
2376 set_con2fb_map(i, idx, 0);
2378 if (con_is_bound(&fb_con)) {
2379 printk(KERN_INFO "fbcon: Remapping primary device, "
2380 "fb%i, to tty %i-%i\n", idx,
2381 first_fb_vc + 1, last_fb_vc + 1);
2387 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2388 static void fbcon_select_primary(struct fb_info *info)
2390 if (!map_override && primary_device == -1 &&
2391 fb_is_primary_device(info)) {
2394 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
2395 info->fix.id, info->node);
2396 primary_device = info->node;
2398 for (i = first_fb_vc; i <= last_fb_vc; i++)
2399 con2fb_map_boot[i] = primary_device;
2401 if (con_is_bound(&fb_con)) {
2402 printk(KERN_INFO "fbcon: Remapping primary device, "
2403 "fb%i, to tty %i-%i\n", info->node,
2404 first_fb_vc + 1, last_fb_vc + 1);
2405 info_idx = primary_device;
2411 static inline void fbcon_select_primary(struct fb_info *info)
2415 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2417 /* called with console_lock held */
2418 int fbcon_fb_registered(struct fb_info *info)
2420 int ret = 0, i, idx;
2422 WARN_CONSOLE_UNLOCKED();
2425 fbcon_select_primary(info);
2427 if (deferred_takeover) {
2428 pr_info("fbcon: Deferring console take-over\n");
2432 if (info_idx == -1) {
2433 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2434 if (con2fb_map_boot[i] == idx) {
2441 ret = do_fbcon_takeover(1);
2443 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2444 if (con2fb_map_boot[i] == idx)
2445 set_con2fb_map(i, idx, 0);
2452 void fbcon_fb_blanked(struct fb_info *info, int blank)
2454 struct fbcon_ops *ops = info->fbcon_par;
2457 if (!ops || ops->currcon < 0)
2460 vc = vc_cons[ops->currcon].d;
2461 if (vc->vc_mode != KD_TEXT ||
2462 registered_fb[con2fb_map[ops->currcon]] != info)
2465 if (con_is_visible(vc)) {
2469 do_unblank_screen(0);
2471 ops->blank_state = blank;
2474 void fbcon_new_modelist(struct fb_info *info)
2478 struct fb_var_screeninfo var;
2479 const struct fb_videomode *mode;
2481 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2482 if (registered_fb[con2fb_map[i]] != info)
2484 if (!fb_display[i].mode)
2487 display_to_var(&var, &fb_display[i]);
2488 mode = fb_find_nearest_mode(fb_display[i].mode,
2490 fb_videomode_to_var(&var, mode);
2491 fbcon_set_disp(info, &var, vc->vc_num);
2495 void fbcon_get_requirement(struct fb_info *info,
2496 struct fb_blit_caps *caps)
2503 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2505 if (vc && vc->vc_mode == KD_TEXT &&
2506 info->node == con2fb_map[i]) {
2507 caps->x |= 1 << (vc->vc_font.width - 1);
2508 caps->y |= 1 << (vc->vc_font.height - 1);
2509 charcnt = vc->vc_font.charcount;
2510 if (caps->len < charcnt)
2511 caps->len = charcnt;
2515 vc = vc_cons[fg_console].d;
2517 if (vc && vc->vc_mode == KD_TEXT &&
2518 info->node == con2fb_map[fg_console]) {
2519 caps->x = 1 << (vc->vc_font.width - 1);
2520 caps->y = 1 << (vc->vc_font.height - 1);
2521 caps->len = vc->vc_font.charcount;
2526 int fbcon_set_con2fb_map_ioctl(void __user *argp)
2528 struct fb_con2fbmap con2fb;
2531 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
2533 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
2535 if (con2fb.framebuffer >= FB_MAX)
2537 if (!registered_fb[con2fb.framebuffer])
2538 request_module("fb%d", con2fb.framebuffer);
2539 if (!registered_fb[con2fb.framebuffer]) {
2544 ret = set_con2fb_map(con2fb.console - 1,
2545 con2fb.framebuffer, 1);
2551 int fbcon_get_con2fb_map_ioctl(void __user *argp)
2553 struct fb_con2fbmap con2fb;
2555 if (copy_from_user(&con2fb, argp, sizeof(con2fb)))
2557 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
2561 con2fb.framebuffer = con2fb_map[con2fb.console - 1];
2564 return copy_to_user(argp, &con2fb, sizeof(con2fb)) ? -EFAULT : 0;
2568 * The console `switch' structure for the frame buffer based console
2571 static const struct consw fb_con = {
2572 .owner = THIS_MODULE,
2573 .con_startup = fbcon_startup,
2574 .con_init = fbcon_init,
2575 .con_deinit = fbcon_deinit,
2576 .con_clear = fbcon_clear,
2577 .con_putc = fbcon_putc,
2578 .con_putcs = fbcon_putcs,
2579 .con_cursor = fbcon_cursor,
2580 .con_scroll = fbcon_scroll,
2581 .con_switch = fbcon_switch,
2582 .con_blank = fbcon_blank,
2583 .con_font_set = fbcon_set_font,
2584 .con_font_get = fbcon_get_font,
2585 .con_font_default = fbcon_set_def_font,
2586 .con_set_palette = fbcon_set_palette,
2587 .con_invert_region = fbcon_invert_region,
2588 .con_screen_pos = fbcon_screen_pos,
2589 .con_getxy = fbcon_getxy,
2590 .con_resize = fbcon_resize,
2591 .con_debug_enter = fbcon_debug_enter,
2592 .con_debug_leave = fbcon_debug_leave,
2595 static ssize_t store_rotate(struct device *device,
2596 struct device_attribute *attr, const char *buf,
2599 struct fb_info *info;
2604 idx = con2fb_map[fg_console];
2606 if (idx == -1 || registered_fb[idx] == NULL)
2609 info = registered_fb[idx];
2610 rotate = simple_strtoul(buf, last, 0);
2611 fbcon_rotate(info, rotate);
2617 static ssize_t store_rotate_all(struct device *device,
2618 struct device_attribute *attr,const char *buf,
2621 struct fb_info *info;
2626 idx = con2fb_map[fg_console];
2628 if (idx == -1 || registered_fb[idx] == NULL)
2631 info = registered_fb[idx];
2632 rotate = simple_strtoul(buf, last, 0);
2633 fbcon_rotate_all(info, rotate);
2639 static ssize_t show_rotate(struct device *device,
2640 struct device_attribute *attr,char *buf)
2642 struct fb_info *info;
2643 int rotate = 0, idx;
2646 idx = con2fb_map[fg_console];
2648 if (idx == -1 || registered_fb[idx] == NULL)
2651 info = registered_fb[idx];
2652 rotate = fbcon_get_rotate(info);
2655 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
2658 static ssize_t show_cursor_blink(struct device *device,
2659 struct device_attribute *attr, char *buf)
2661 struct fb_info *info;
2662 struct fbcon_ops *ops;
2663 int idx, blink = -1;
2666 idx = con2fb_map[fg_console];
2668 if (idx == -1 || registered_fb[idx] == NULL)
2671 info = registered_fb[idx];
2672 ops = info->fbcon_par;
2677 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
2680 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
2683 static ssize_t store_cursor_blink(struct device *device,
2684 struct device_attribute *attr,
2685 const char *buf, size_t count)
2687 struct fb_info *info;
2692 idx = con2fb_map[fg_console];
2694 if (idx == -1 || registered_fb[idx] == NULL)
2697 info = registered_fb[idx];
2699 if (!info->fbcon_par)
2702 blink = simple_strtoul(buf, last, 0);
2705 fbcon_cursor_noblink = 0;
2706 fbcon_add_cursor_timer(info);
2708 fbcon_cursor_noblink = 1;
2709 fbcon_del_cursor_timer(info);
2717 static struct device_attribute device_attrs[] = {
2718 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
2719 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
2720 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
2721 store_cursor_blink),
2724 static int fbcon_init_device(void)
2728 fbcon_has_sysfs = 1;
2730 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
2731 error = device_create_file(fbcon_device, &device_attrs[i]);
2739 device_remove_file(fbcon_device, &device_attrs[i]);
2741 fbcon_has_sysfs = 0;
2747 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
2748 static void fbcon_register_existing_fbs(struct work_struct *work)
2754 for_each_registered_fb(i)
2755 fbcon_fb_registered(registered_fb[i]);
2760 static struct notifier_block fbcon_output_nb;
2761 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
2763 static int fbcon_output_notifier(struct notifier_block *nb,
2764 unsigned long action, void *data)
2766 WARN_CONSOLE_UNLOCKED();
2768 pr_info("fbcon: Taking over console\n");
2770 dummycon_unregister_output_notifier(&fbcon_output_nb);
2771 deferred_takeover = false;
2772 logo_shown = FBCON_LOGO_DONTSHOW;
2774 /* We may get called in atomic context */
2775 schedule_work(&fbcon_deferred_takeover_work);
2781 static void fbcon_start(void)
2783 WARN_CONSOLE_UNLOCKED();
2785 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
2786 if (conswitchp != &dummy_con)
2787 deferred_takeover = false;
2789 if (deferred_takeover) {
2790 fbcon_output_nb.notifier_call = fbcon_output_notifier;
2791 dummycon_register_output_notifier(&fbcon_output_nb);
2796 if (num_registered_fb) {
2799 for_each_registered_fb(i) {
2804 do_fbcon_takeover(0);
2808 static void fbcon_exit(void)
2810 struct fb_info *info;
2813 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
2814 if (deferred_takeover) {
2815 dummycon_unregister_output_notifier(&fbcon_output_nb);
2816 deferred_takeover = false;
2820 for_each_registered_fb(i) {
2824 info = registered_fb[i];
2826 if (info->queue.func)
2827 pending = cancel_work_sync(&info->queue);
2828 pr_debug("fbcon: %s pending work\n", (pending ? "canceled" : "no"));
2830 for (j = first_fb_vc; j <= last_fb_vc; j++) {
2831 if (con2fb_map[j] == i) {
2838 if (info->fbops->fb_release)
2839 info->fbops->fb_release(info, 0);
2840 module_put(info->fbops->owner);
2842 if (info->fbcon_par) {
2843 struct fbcon_ops *ops = info->fbcon_par;
2845 fbcon_del_cursor_timer(info);
2846 kfree(ops->cursor_src);
2847 kfree(ops->cursor_state.mask);
2848 kfree(info->fbcon_par);
2849 info->fbcon_par = NULL;
2852 if (info->queue.func == fb_flashcursor)
2853 info->queue.func = NULL;
2858 void __init fb_console_init(void)
2863 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
2866 if (IS_ERR(fbcon_device)) {
2867 printk(KERN_WARNING "Unable to create device "
2868 "for fbcon; errno = %ld\n",
2869 PTR_ERR(fbcon_device));
2870 fbcon_device = NULL;
2872 fbcon_init_device();
2874 for (i = 0; i < MAX_NR_CONSOLES; i++)
2883 static void __exit fbcon_deinit_device(void)
2887 if (fbcon_has_sysfs) {
2888 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
2889 device_remove_file(fbcon_device, &device_attrs[i]);
2891 fbcon_has_sysfs = 0;
2895 void __exit fb_console_exit(void)
2898 fbcon_deinit_device();
2899 device_destroy(fb_class, MKDEV(0, 0));
2901 do_unregister_con_driver(&fb_con);