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/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
80 #include <asm/system.h>
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 */
133 static char fontname[40];
135 /* current fb_info */
136 static int info_idx = -1;
138 /* console rotation */
139 static int initial_rotation;
140 static int fbcon_has_sysfs;
142 static const struct consw fb_con;
144 #define CM_SOFTBACK (8)
146 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
148 static int fbcon_set_origin(struct vc_data *);
150 #define CURSOR_DRAW_DELAY (1)
152 static int vbl_cursor_cnt;
153 static int fbcon_cursor_noblink;
155 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
158 * Interface used by the world
161 static const char *fbcon_startup(void);
162 static void fbcon_init(struct vc_data *vc, int init);
163 static void fbcon_deinit(struct vc_data *vc);
164 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
166 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
167 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
168 int count, int ypos, int xpos);
169 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
170 static void fbcon_cursor(struct vc_data *vc, int mode);
171 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
173 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
174 int height, int width);
175 static int fbcon_switch(struct vc_data *vc);
176 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
177 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
178 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
183 static __inline__ void ywrap_up(struct vc_data *vc, int count);
184 static __inline__ void ywrap_down(struct vc_data *vc, int count);
185 static __inline__ void ypan_up(struct vc_data *vc, int count);
186 static __inline__ void ypan_down(struct vc_data *vc, int count);
187 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
188 int dy, int dx, int height, int width, u_int y_break);
189 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
192 int line, int count, int dy);
193 static void fbcon_modechanged(struct fb_info *info);
194 static void fbcon_set_all_vcs(struct fb_info *info);
195 static void fbcon_start(void);
196 static void fbcon_exit(void);
197 static struct device *fbcon_device;
199 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
200 static inline void fbcon_set_rotation(struct fb_info *info)
202 struct fbcon_ops *ops = info->fbcon_par;
204 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
205 ops->p->con_rotate < 4)
206 ops->rotate = ops->p->con_rotate;
211 static void fbcon_rotate(struct fb_info *info, u32 rotate)
213 struct fbcon_ops *ops= info->fbcon_par;
214 struct fb_info *fb_info;
216 if (!ops || ops->currcon == -1)
219 fb_info = registered_fb[con2fb_map[ops->currcon]];
221 if (info == fb_info) {
222 struct display *p = &fb_display[ops->currcon];
225 p->con_rotate = rotate;
229 fbcon_modechanged(info);
233 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
235 struct fbcon_ops *ops = info->fbcon_par;
240 if (!ops || ops->currcon < 0 || rotate > 3)
243 for (i = first_fb_vc; i <= last_fb_vc; i++) {
245 if (!vc || vc->vc_mode != KD_TEXT ||
246 registered_fb[con2fb_map[i]] != info)
249 p = &fb_display[vc->vc_num];
250 p->con_rotate = rotate;
253 fbcon_set_all_vcs(info);
256 static inline void fbcon_set_rotation(struct fb_info *info)
258 struct fbcon_ops *ops = info->fbcon_par;
260 ops->rotate = FB_ROTATE_UR;
263 static void fbcon_rotate(struct fb_info *info, u32 rotate)
268 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
272 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
274 static int fbcon_get_rotate(struct fb_info *info)
276 struct fbcon_ops *ops = info->fbcon_par;
278 return (ops) ? ops->rotate : 0;
281 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
283 struct fbcon_ops *ops = info->fbcon_par;
285 return (info->state != FBINFO_STATE_RUNNING ||
286 vc->vc_mode != KD_TEXT || ops->graphics) &&
287 !vt_force_oops_output(vc);
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(unsigned long dev_addr)
405 struct fb_info *info = (struct fb_info *) dev_addr;
406 struct fbcon_ops *ops = info->fbcon_par;
408 schedule_work(&info->queue);
409 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
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 init_timer(&ops->cursor_timer);
423 ops->cursor_timer.function = cursor_timer_handler;
424 ops->cursor_timer.expires = jiffies + HZ / 5;
425 ops->cursor_timer.data = (unsigned long ) info;
426 add_timer(&ops->cursor_timer);
427 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
431 static void fbcon_del_cursor_timer(struct fb_info *info)
433 struct fbcon_ops *ops = info->fbcon_par;
435 if (info->queue.func == fb_flashcursor &&
436 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
437 del_timer_sync(&ops->cursor_timer);
438 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
443 static int __init fb_console_setup(char *this_opt)
448 if (!this_opt || !*this_opt)
451 while ((options = strsep(&this_opt, ",")) != NULL) {
452 if (!strncmp(options, "font:", 5))
453 strcpy(fontname, options + 5);
455 if (!strncmp(options, "scrollback:", 11)) {
458 fbcon_softback_size = simple_strtoul(options, &options, 0);
459 if (*options == 'k' || *options == 'K') {
460 fbcon_softback_size *= 1024;
470 if (!strncmp(options, "map:", 4)) {
473 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
477 (options[j++]-'0') % FB_MAX;
480 fbcon_map_override();
486 if (!strncmp(options, "vc:", 3)) {
489 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
492 if (*options++ == '-')
493 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
494 fbcon_is_default = 0;
497 if (!strncmp(options, "rotate:", 7)) {
500 initial_rotation = simple_strtoul(options, &options, 0);
501 if (initial_rotation > 3)
502 initial_rotation = 0;
508 __setup("fbcon=", fb_console_setup);
511 static int search_fb_in_map(int idx)
515 for (i = first_fb_vc; i <= last_fb_vc; i++) {
516 if (con2fb_map[i] == idx)
522 static int search_for_mapped_con(void)
526 for (i = first_fb_vc; i <= last_fb_vc; i++) {
527 if (con2fb_map[i] != -1)
533 static int do_fbcon_takeover(int show_logo)
537 if (!num_registered_fb)
541 logo_shown = FBCON_LOGO_DONTSHOW;
543 for (i = first_fb_vc; i <= last_fb_vc; i++)
544 con2fb_map[i] = info_idx;
546 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
550 for (i = first_fb_vc; i <= last_fb_vc; i++)
554 fbcon_has_console_bind = 1;
560 static int fbcon_takeover(int show_logo)
564 if (!num_registered_fb)
568 logo_shown = FBCON_LOGO_DONTSHOW;
570 for (i = first_fb_vc; i <= last_fb_vc; i++)
571 con2fb_map[i] = info_idx;
573 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
577 for (i = first_fb_vc; i <= last_fb_vc; i++) {
582 fbcon_has_console_bind = 1;
589 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
590 int cols, int rows, int new_cols, int new_rows)
592 logo_shown = FBCON_LOGO_DONTSHOW;
595 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
596 int cols, int rows, int new_cols, int new_rows)
598 /* Need to make room for the logo */
599 struct fbcon_ops *ops = info->fbcon_par;
600 int cnt, erase = vc->vc_video_erase_char, step;
601 unsigned short *save = NULL, *r, *q;
604 if (info->flags & FBINFO_MODULE) {
605 logo_shown = FBCON_LOGO_DONTSHOW;
610 * remove underline attribute from erase character
611 * if black and white framebuffer.
613 if (fb_get_color_depth(&info->var, &info->fix) == 1)
615 logo_height = fb_prepare_logo(info, ops->rotate);
616 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
617 q = (unsigned short *) (vc->vc_origin +
618 vc->vc_size_row * rows);
619 step = logo_lines * cols;
620 for (r = q - logo_lines * cols; r < q; r++)
621 if (scr_readw(r) != vc->vc_video_erase_char)
623 if (r != q && new_rows >= rows + logo_lines) {
624 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
626 int i = cols < new_cols ? cols : new_cols;
627 scr_memsetw(save, erase, logo_lines * new_cols * 2);
629 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
630 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
635 /* We can scroll screen down */
637 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
638 scr_memcpyw(r + step, r, vc->vc_size_row);
643 if (vc->vc_y + logo_lines >= rows)
644 lines = rows - vc->vc_y - 1;
648 vc->vc_pos += lines * vc->vc_size_row;
651 scr_memsetw((unsigned short *) vc->vc_origin,
653 vc->vc_size_row * logo_lines);
655 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
656 fbcon_clear_margins(vc, 0);
661 q = (unsigned short *) (vc->vc_origin +
664 scr_memcpyw(q, save, logo_lines * new_cols * 2);
665 vc->vc_y += logo_lines;
666 vc->vc_pos += logo_lines * vc->vc_size_row;
670 if (logo_lines > vc->vc_bottom) {
671 logo_shown = FBCON_LOGO_CANSHOW;
673 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
674 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
675 logo_shown = FBCON_LOGO_DRAW;
676 vc->vc_top = logo_lines;
681 #ifdef CONFIG_FB_TILEBLITTING
682 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
684 struct fbcon_ops *ops = info->fbcon_par;
686 ops->p = &fb_display[vc->vc_num];
688 if ((info->flags & FBINFO_MISC_TILEBLITTING))
689 fbcon_set_tileops(vc, info);
691 fbcon_set_rotation(info);
692 fbcon_set_bitops(ops);
696 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
700 if (info->flags & FBINFO_MISC_TILEBLITTING &&
701 info->tileops->fb_get_tilemax(info) < charcount)
707 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
709 struct fbcon_ops *ops = info->fbcon_par;
711 info->flags &= ~FBINFO_MISC_TILEBLITTING;
712 ops->p = &fb_display[vc->vc_num];
713 fbcon_set_rotation(info);
714 fbcon_set_bitops(ops);
717 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
722 #endif /* CONFIG_MISC_TILEBLITTING */
725 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
726 int unit, int oldidx)
728 struct fbcon_ops *ops = NULL;
731 if (!try_module_get(info->fbops->owner))
734 if (!err && info->fbops->fb_open &&
735 info->fbops->fb_open(info, 0))
739 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
745 info->fbcon_par = ops;
748 set_blitting_type(vc, info);
752 con2fb_map[unit] = oldidx;
753 module_put(info->fbops->owner);
759 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
760 struct fb_info *newinfo, int unit,
761 int oldidx, int found)
763 struct fbcon_ops *ops = oldinfo->fbcon_par;
766 if (oldinfo->fbops->fb_release &&
767 oldinfo->fbops->fb_release(oldinfo, 0)) {
768 con2fb_map[unit] = oldidx;
769 if (!found && newinfo->fbops->fb_release)
770 newinfo->fbops->fb_release(newinfo, 0);
772 module_put(newinfo->fbops->owner);
777 fbcon_del_cursor_timer(oldinfo);
778 kfree(ops->cursor_state.mask);
779 kfree(ops->cursor_data);
780 kfree(ops->fontbuffer);
781 kfree(oldinfo->fbcon_par);
782 oldinfo->fbcon_par = NULL;
783 module_put(oldinfo->fbops->owner);
785 If oldinfo and newinfo are driving the same hardware,
786 the fb_release() method of oldinfo may attempt to
787 restore the hardware state. This will leave the
788 newinfo in an undefined state. Thus, a call to
789 fb_set_par() may be needed for the newinfo.
791 if (newinfo->fbops->fb_set_par) {
792 ret = newinfo->fbops->fb_set_par(newinfo);
795 printk(KERN_ERR "con2fb_release_oldinfo: "
796 "detected unhandled fb_set_par error, "
797 "error code %d\n", ret);
804 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
805 int unit, int show_logo)
807 struct fbcon_ops *ops = info->fbcon_par;
810 ops->currcon = fg_console;
812 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
813 ret = info->fbops->fb_set_par(info);
816 printk(KERN_ERR "con2fb_init_display: detected "
817 "unhandled fb_set_par error, "
818 "error code %d\n", ret);
821 ops->flags |= FBCON_FLAGS_INIT;
823 fbcon_set_disp(info, &info->var, unit);
826 struct vc_data *fg_vc = vc_cons[fg_console].d;
827 struct fb_info *fg_info =
828 registered_fb[con2fb_map[fg_console]];
830 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
831 fg_vc->vc_rows, fg_vc->vc_cols,
835 update_screen(vc_cons[fg_console].d);
839 * set_con2fb_map - map console to frame buffer device
840 * @unit: virtual console number to map
841 * @newidx: frame buffer index to map virtual console to
842 * @user: user request
844 * Maps a virtual console @unit to a frame buffer device
847 * This should be called with the console lock held.
849 static int set_con2fb_map(int unit, int newidx, int user)
851 struct vc_data *vc = vc_cons[unit].d;
852 int oldidx = con2fb_map[unit];
853 struct fb_info *info = registered_fb[newidx];
854 struct fb_info *oldinfo = NULL;
857 if (oldidx == newidx)
863 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
865 return do_fbcon_takeover(0);
869 oldinfo = registered_fb[oldidx];
871 found = search_fb_in_map(newidx);
873 con2fb_map[unit] = newidx;
875 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
879 * If old fb is not mapped to any of the consoles,
880 * fbcon should release it.
882 if (!err && oldinfo && !search_fb_in_map(oldidx))
883 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
887 int show_logo = (fg_console == 0 && !user &&
888 logo_shown != FBCON_LOGO_DONTSHOW);
891 fbcon_add_cursor_timer(info);
892 con2fb_map_boot[unit] = newidx;
893 con2fb_init_display(vc, info, unit, show_logo);
896 if (!search_fb_in_map(info_idx))
903 * Low Level Operations
905 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
906 static int var_to_display(struct display *disp,
907 struct fb_var_screeninfo *var,
908 struct fb_info *info)
910 disp->xres_virtual = var->xres_virtual;
911 disp->yres_virtual = var->yres_virtual;
912 disp->bits_per_pixel = var->bits_per_pixel;
913 disp->grayscale = var->grayscale;
914 disp->nonstd = var->nonstd;
915 disp->accel_flags = var->accel_flags;
916 disp->height = var->height;
917 disp->width = var->width;
918 disp->red = var->red;
919 disp->green = var->green;
920 disp->blue = var->blue;
921 disp->transp = var->transp;
922 disp->rotate = var->rotate;
923 disp->mode = fb_match_mode(var, &info->modelist);
924 if (disp->mode == NULL)
925 /* This should not happen */
930 static void display_to_var(struct fb_var_screeninfo *var,
931 struct display *disp)
933 fb_videomode_to_var(var, disp->mode);
934 var->xres_virtual = disp->xres_virtual;
935 var->yres_virtual = disp->yres_virtual;
936 var->bits_per_pixel = disp->bits_per_pixel;
937 var->grayscale = disp->grayscale;
938 var->nonstd = disp->nonstd;
939 var->accel_flags = disp->accel_flags;
940 var->height = disp->height;
941 var->width = disp->width;
942 var->red = disp->red;
943 var->green = disp->green;
944 var->blue = disp->blue;
945 var->transp = disp->transp;
946 var->rotate = disp->rotate;
949 static const char *fbcon_startup(void)
951 const char *display_desc = "frame buffer device";
952 struct display *p = &fb_display[fg_console];
953 struct vc_data *vc = vc_cons[fg_console].d;
954 const struct font_desc *font = NULL;
955 struct module *owner;
956 struct fb_info *info = NULL;
957 struct fbcon_ops *ops;
961 * If num_registered_fb is zero, this is a call for the dummy part.
962 * The frame buffer devices weren't initialized yet.
964 if (!num_registered_fb || info_idx == -1)
967 * Instead of blindly using registered_fb[0], we use info_idx, set by
970 info = registered_fb[info_idx];
974 owner = info->fbops->owner;
975 if (!try_module_get(owner))
977 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
982 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
990 ops->cur_rotate = -1;
991 info->fbcon_par = ops;
992 p->con_rotate = initial_rotation;
993 set_blitting_type(vc, info);
995 if (info->fix.type != FB_TYPE_TEXT) {
996 if (fbcon_softback_size) {
1000 kmalloc(fbcon_softback_size,
1002 if (!softback_buf) {
1003 fbcon_softback_size = 0;
1009 kfree((void *) softback_buf);
1015 softback_in = softback_top = softback_curr =
1020 /* Setup default font */
1021 if (!p->fontdata && !vc->vc_font.data) {
1022 if (!fontname[0] || !(font = find_font(fontname)))
1023 font = get_default_font(info->var.xres,
1025 info->pixmap.blit_x,
1026 info->pixmap.blit_y);
1027 vc->vc_font.width = font->width;
1028 vc->vc_font.height = font->height;
1029 vc->vc_font.data = (void *)(p->fontdata = font->data);
1030 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1032 p->fontdata = vc->vc_font.data;
1035 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1036 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1037 cols /= vc->vc_font.width;
1038 rows /= vc->vc_font.height;
1039 vc_resize(vc, cols, rows);
1041 DPRINTK("mode: %s\n", info->fix.id);
1042 DPRINTK("visual: %d\n", info->fix.visual);
1043 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1045 info->var.bits_per_pixel);
1047 fbcon_add_cursor_timer(info);
1048 fbcon_has_exited = 0;
1049 return display_desc;
1052 static void fbcon_init(struct vc_data *vc, int init)
1054 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1055 struct fbcon_ops *ops;
1056 struct vc_data **default_mode = vc->vc_display_fg;
1057 struct vc_data *svc = *default_mode;
1058 struct display *t, *p = &fb_display[vc->vc_num];
1059 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1062 if (info_idx == -1 || info == NULL)
1067 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1068 (info->fix.type == FB_TYPE_TEXT))
1071 if (var_to_display(p, &info->var, info))
1074 if (!info->fbcon_par)
1075 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1077 /* If we are not the first console on this
1078 fb, copy the font from that console */
1079 t = &fb_display[fg_console];
1082 struct vc_data *fvc = vc_cons[fg_console].d;
1084 vc->vc_font.data = (void *)(p->fontdata =
1086 vc->vc_font.width = fvc->vc_font.width;
1087 vc->vc_font.height = fvc->vc_font.height;
1088 p->userfont = t->userfont;
1091 REFCOUNT(p->fontdata)++;
1093 const struct font_desc *font = NULL;
1095 if (!fontname[0] || !(font = find_font(fontname)))
1096 font = get_default_font(info->var.xres,
1098 info->pixmap.blit_x,
1099 info->pixmap.blit_y);
1100 vc->vc_font.width = font->width;
1101 vc->vc_font.height = font->height;
1102 vc->vc_font.data = (void *)(p->fontdata = font->data);
1103 vc->vc_font.charcount = 256; /* FIXME Need to
1104 support more fonts */
1109 charcnt = FNTCHARCNT(p->fontdata);
1111 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1112 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1113 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1114 if (charcnt == 256) {
1115 vc->vc_hi_font_mask = 0;
1117 vc->vc_hi_font_mask = 0x100;
1118 if (vc->vc_can_do_color)
1119 vc->vc_complement_mask <<= 1;
1122 if (!*svc->vc_uni_pagedir_loc)
1123 con_set_default_unimap(svc);
1124 if (!*vc->vc_uni_pagedir_loc)
1125 con_copy_unimap(vc, svc);
1127 ops = info->fbcon_par;
1128 p->con_rotate = initial_rotation;
1129 set_blitting_type(vc, info);
1133 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1134 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1135 new_cols /= vc->vc_font.width;
1136 new_rows /= vc->vc_font.height;
1139 * We must always set the mode. The mode of the previous console
1140 * driver could be in the same resolution but we are using different
1141 * hardware so we have to initialize the hardware.
1143 * We need to do it in fbcon_init() to prevent screen corruption.
1145 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1146 if (info->fbops->fb_set_par &&
1147 !(ops->flags & FBCON_FLAGS_INIT)) {
1148 ret = info->fbops->fb_set_par(info);
1151 printk(KERN_ERR "fbcon_init: detected "
1152 "unhandled fb_set_par error, "
1153 "error code %d\n", ret);
1156 ops->flags |= FBCON_FLAGS_INIT;
1161 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1162 !(cap & FBINFO_HWACCEL_DISABLED))
1163 p->scrollmode = SCROLL_MOVE;
1164 else /* default to something safe */
1165 p->scrollmode = SCROLL_REDRAW;
1168 * ++guenther: console.c:vc_allocate() relies on initializing
1169 * vc_{cols,rows}, but we must not set those if we are only
1170 * resizing the console.
1173 vc->vc_cols = new_cols;
1174 vc->vc_rows = new_rows;
1176 vc_resize(vc, new_cols, new_rows);
1179 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1181 if (vc == svc && softback_buf)
1182 fbcon_update_softback(vc);
1184 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1185 ops->rotate = FB_ROTATE_UR;
1186 set_blitting_type(vc, info);
1189 ops->p = &fb_display[fg_console];
1192 static void fbcon_free_font(struct display *p, bool freefont)
1194 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1195 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1200 static void fbcon_deinit(struct vc_data *vc)
1202 struct display *p = &fb_display[vc->vc_num];
1203 struct fb_info *info;
1204 struct fbcon_ops *ops;
1206 bool free_font = true;
1208 idx = con2fb_map[vc->vc_num];
1213 info = registered_fb[idx];
1218 if (info->flags & FBINFO_MISC_FIRMWARE)
1220 ops = info->fbcon_par;
1225 if (CON_IS_VISIBLE(vc))
1226 fbcon_del_cursor_timer(info);
1228 ops->flags &= ~FBCON_FLAGS_INIT;
1231 fbcon_free_font(p, free_font);
1233 vc->vc_font.data = NULL;
1235 if (!con_is_bound(&fb_con))
1241 /* ====================================================================== */
1243 /* fbcon_XXX routines - interface used by the world
1245 * This system is now divided into two levels because of complications
1246 * caused by hardware scrolling. Top level functions:
1248 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1250 * handles y values in range [0, scr_height-1] that correspond to real
1251 * screen positions. y_wrap shift means that first line of bitmap may be
1252 * anywhere on this display. These functions convert lineoffsets to
1253 * bitmap offsets and deal with the wrap-around case by splitting blits.
1255 * fbcon_bmove_physical_8() -- These functions fast implementations
1256 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1257 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1261 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1262 * Implies should only really hardware scroll in rows. Only reason for
1263 * restriction is simplicity & efficiency at the moment.
1266 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1269 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1270 struct fbcon_ops *ops = info->fbcon_par;
1272 struct display *p = &fb_display[vc->vc_num];
1275 if (fbcon_is_inactive(vc, info))
1278 if (!height || !width)
1281 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1284 /* Split blits that cross physical y_wrap boundary */
1286 y_break = p->vrows - p->yscroll;
1287 if (sy < y_break && sy + height - 1 >= y_break) {
1288 u_int b = y_break - sy;
1289 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1290 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1293 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1296 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1297 int count, int ypos, int xpos)
1299 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1300 struct display *p = &fb_display[vc->vc_num];
1301 struct fbcon_ops *ops = info->fbcon_par;
1303 if (!fbcon_is_inactive(vc, info))
1304 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1305 get_color(vc, info, scr_readw(s), 1),
1306 get_color(vc, info, scr_readw(s), 0));
1309 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1313 scr_writew(c, &chr);
1314 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1317 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1319 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1320 struct fbcon_ops *ops = info->fbcon_par;
1322 if (!fbcon_is_inactive(vc, info))
1323 ops->clear_margins(vc, info, bottom_only);
1326 static void fbcon_cursor(struct vc_data *vc, int mode)
1328 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1329 struct fbcon_ops *ops = info->fbcon_par;
1331 int c = scr_readw((u16 *) vc->vc_pos);
1333 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1336 if (vc->vc_cursor_type & 0x10)
1337 fbcon_del_cursor_timer(info);
1339 fbcon_add_cursor_timer(info);
1341 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1342 if (mode & CM_SOFTBACK) {
1343 mode &= ~CM_SOFTBACK;
1347 fbcon_set_origin(vc);
1351 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1352 get_color(vc, info, c, 0));
1353 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1356 static int scrollback_phys_max = 0;
1357 static int scrollback_max = 0;
1358 static int scrollback_current = 0;
1360 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1363 struct display *p, *t;
1364 struct vc_data **default_mode, *vc;
1365 struct vc_data *svc;
1366 struct fbcon_ops *ops = info->fbcon_par;
1367 int rows, cols, charcnt = 256;
1369 p = &fb_display[unit];
1371 if (var_to_display(p, var, info))
1374 vc = vc_cons[unit].d;
1379 default_mode = vc->vc_display_fg;
1380 svc = *default_mode;
1381 t = &fb_display[svc->vc_num];
1383 if (!vc->vc_font.data) {
1384 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1385 vc->vc_font.width = (*default_mode)->vc_font.width;
1386 vc->vc_font.height = (*default_mode)->vc_font.height;
1387 p->userfont = t->userfont;
1389 REFCOUNT(p->fontdata)++;
1392 charcnt = FNTCHARCNT(p->fontdata);
1394 var->activate = FB_ACTIVATE_NOW;
1395 info->var.activate = var->activate;
1396 var->yoffset = info->var.yoffset;
1397 var->xoffset = info->var.xoffset;
1398 fb_set_var(info, var);
1399 ops->var = info->var;
1400 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1401 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1402 if (charcnt == 256) {
1403 vc->vc_hi_font_mask = 0;
1405 vc->vc_hi_font_mask = 0x100;
1406 if (vc->vc_can_do_color)
1407 vc->vc_complement_mask <<= 1;
1410 if (!*svc->vc_uni_pagedir_loc)
1411 con_set_default_unimap(svc);
1412 if (!*vc->vc_uni_pagedir_loc)
1413 con_copy_unimap(vc, svc);
1415 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1416 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1417 cols /= vc->vc_font.width;
1418 rows /= vc->vc_font.height;
1419 vc_resize(vc, cols, rows);
1421 if (CON_IS_VISIBLE(vc)) {
1424 fbcon_update_softback(vc);
1428 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1430 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1431 struct fbcon_ops *ops = info->fbcon_par;
1432 struct display *p = &fb_display[vc->vc_num];
1434 p->yscroll += count;
1435 if (p->yscroll >= p->vrows) /* Deal with wrap */
1436 p->yscroll -= p->vrows;
1437 ops->var.xoffset = 0;
1438 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1439 ops->var.vmode |= FB_VMODE_YWRAP;
1440 ops->update_start(info);
1441 scrollback_max += count;
1442 if (scrollback_max > scrollback_phys_max)
1443 scrollback_max = scrollback_phys_max;
1444 scrollback_current = 0;
1447 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1449 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1450 struct fbcon_ops *ops = info->fbcon_par;
1451 struct display *p = &fb_display[vc->vc_num];
1453 p->yscroll -= count;
1454 if (p->yscroll < 0) /* Deal with wrap */
1455 p->yscroll += p->vrows;
1456 ops->var.xoffset = 0;
1457 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1458 ops->var.vmode |= FB_VMODE_YWRAP;
1459 ops->update_start(info);
1460 scrollback_max -= count;
1461 if (scrollback_max < 0)
1463 scrollback_current = 0;
1466 static __inline__ void ypan_up(struct vc_data *vc, int count)
1468 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1469 struct display *p = &fb_display[vc->vc_num];
1470 struct fbcon_ops *ops = info->fbcon_par;
1472 p->yscroll += count;
1473 if (p->yscroll > p->vrows - vc->vc_rows) {
1474 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1475 0, 0, 0, vc->vc_rows, vc->vc_cols);
1476 p->yscroll -= p->vrows - vc->vc_rows;
1479 ops->var.xoffset = 0;
1480 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1481 ops->var.vmode &= ~FB_VMODE_YWRAP;
1482 ops->update_start(info);
1483 fbcon_clear_margins(vc, 1);
1484 scrollback_max += count;
1485 if (scrollback_max > scrollback_phys_max)
1486 scrollback_max = scrollback_phys_max;
1487 scrollback_current = 0;
1490 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1492 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1493 struct fbcon_ops *ops = info->fbcon_par;
1494 struct display *p = &fb_display[vc->vc_num];
1496 p->yscroll += count;
1498 if (p->yscroll > p->vrows - vc->vc_rows) {
1499 p->yscroll -= p->vrows - vc->vc_rows;
1500 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1503 ops->var.xoffset = 0;
1504 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1505 ops->var.vmode &= ~FB_VMODE_YWRAP;
1506 ops->update_start(info);
1507 fbcon_clear_margins(vc, 1);
1508 scrollback_max += count;
1509 if (scrollback_max > scrollback_phys_max)
1510 scrollback_max = scrollback_phys_max;
1511 scrollback_current = 0;
1514 static __inline__ void ypan_down(struct vc_data *vc, int count)
1516 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1517 struct display *p = &fb_display[vc->vc_num];
1518 struct fbcon_ops *ops = info->fbcon_par;
1520 p->yscroll -= count;
1521 if (p->yscroll < 0) {
1522 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1523 0, vc->vc_rows, vc->vc_cols);
1524 p->yscroll += p->vrows - vc->vc_rows;
1527 ops->var.xoffset = 0;
1528 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1529 ops->var.vmode &= ~FB_VMODE_YWRAP;
1530 ops->update_start(info);
1531 fbcon_clear_margins(vc, 1);
1532 scrollback_max -= count;
1533 if (scrollback_max < 0)
1535 scrollback_current = 0;
1538 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1540 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1541 struct fbcon_ops *ops = info->fbcon_par;
1542 struct display *p = &fb_display[vc->vc_num];
1544 p->yscroll -= count;
1546 if (p->yscroll < 0) {
1547 p->yscroll += p->vrows - vc->vc_rows;
1548 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1551 ops->var.xoffset = 0;
1552 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1553 ops->var.vmode &= ~FB_VMODE_YWRAP;
1554 ops->update_start(info);
1555 fbcon_clear_margins(vc, 1);
1556 scrollback_max -= count;
1557 if (scrollback_max < 0)
1559 scrollback_current = 0;
1562 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1565 int count = vc->vc_rows;
1566 unsigned short *d, *s;
1570 d = (u16 *) softback_curr;
1571 if (d == (u16 *) softback_in)
1572 d = (u16 *) vc->vc_origin;
1573 n = softback_curr + delta * vc->vc_size_row;
1574 softback_lines -= delta;
1576 if (softback_curr < softback_top && n < softback_buf) {
1577 n += softback_end - softback_buf;
1578 if (n < softback_top) {
1580 (softback_top - n) / vc->vc_size_row;
1583 } else if (softback_curr >= softback_top
1584 && n < softback_top) {
1586 (softback_top - n) / vc->vc_size_row;
1590 if (softback_curr > softback_in && n >= softback_end) {
1591 n += softback_buf - softback_end;
1592 if (n > softback_in) {
1596 } else if (softback_curr <= softback_in && n > softback_in) {
1601 if (n == softback_curr)
1604 s = (u16 *) softback_curr;
1605 if (s == (u16 *) softback_in)
1606 s = (u16 *) vc->vc_origin;
1608 unsigned short *start;
1612 unsigned short attr = 1;
1615 le = advance_row(s, 1);
1618 if (attr != (c & 0xff00)) {
1621 fbcon_putcs(vc, start, s - start,
1627 if (c == scr_readw(d)) {
1629 fbcon_putcs(vc, start, s - start,
1642 fbcon_putcs(vc, start, s - start, line, x);
1644 if (d == (u16 *) softback_end)
1645 d = (u16 *) softback_buf;
1646 if (d == (u16 *) softback_in)
1647 d = (u16 *) vc->vc_origin;
1648 if (s == (u16 *) softback_end)
1649 s = (u16 *) softback_buf;
1650 if (s == (u16 *) softback_in)
1651 s = (u16 *) vc->vc_origin;
1655 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1656 int line, int count, int dy)
1658 unsigned short *s = (unsigned short *)
1659 (vc->vc_origin + vc->vc_size_row * line);
1662 unsigned short *start = s;
1663 unsigned short *le = advance_row(s, 1);
1666 unsigned short attr = 1;
1670 if (attr != (c & 0xff00)) {
1673 fbcon_putcs(vc, start, s - start,
1679 console_conditional_schedule();
1683 fbcon_putcs(vc, start, s - start, dy, x);
1684 console_conditional_schedule();
1689 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1690 struct display *p, int line, int count, int ycount)
1692 int offset = ycount * vc->vc_cols;
1693 unsigned short *d = (unsigned short *)
1694 (vc->vc_origin + vc->vc_size_row * line);
1695 unsigned short *s = d + offset;
1696 struct fbcon_ops *ops = info->fbcon_par;
1699 unsigned short *start = s;
1700 unsigned short *le = advance_row(s, 1);
1707 if (c == scr_readw(d)) {
1709 ops->bmove(vc, info, line + ycount, x,
1710 line, x, 1, s-start);
1720 console_conditional_schedule();
1725 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1727 console_conditional_schedule();
1732 /* NOTE: We subtract two lines from these pointers */
1733 s -= vc->vc_size_row;
1734 d -= vc->vc_size_row;
1739 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1740 int line, int count, int offset)
1742 unsigned short *d = (unsigned short *)
1743 (vc->vc_origin + vc->vc_size_row * line);
1744 unsigned short *s = d + offset;
1747 unsigned short *start = s;
1748 unsigned short *le = advance_row(s, 1);
1751 unsigned short attr = 1;
1755 if (attr != (c & 0xff00)) {
1758 fbcon_putcs(vc, start, s - start,
1764 if (c == scr_readw(d)) {
1766 fbcon_putcs(vc, start, s - start,
1776 console_conditional_schedule();
1781 fbcon_putcs(vc, start, s - start, line, x);
1782 console_conditional_schedule();
1787 /* NOTE: We subtract two lines from these pointers */
1788 s -= vc->vc_size_row;
1789 d -= vc->vc_size_row;
1794 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1799 if (vc->vc_num != fg_console)
1801 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1804 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1806 p = advance_row(p, 1);
1807 softback_in += vc->vc_size_row;
1808 if (softback_in == softback_end)
1809 softback_in = softback_buf;
1810 if (softback_in == softback_top) {
1811 softback_top += vc->vc_size_row;
1812 if (softback_top == softback_end)
1813 softback_top = softback_buf;
1816 softback_curr = softback_in;
1819 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1822 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1823 struct display *p = &fb_display[vc->vc_num];
1824 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1826 if (fbcon_is_inactive(vc, info))
1829 fbcon_cursor(vc, CM_ERASE);
1832 * ++Geert: Only use ywrap/ypan if the console is in text mode
1833 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1834 * whole screen (prevents flicker).
1839 if (count > vc->vc_rows) /* Maximum realistic size */
1840 count = vc->vc_rows;
1842 fbcon_softback_note(vc, t, count);
1843 if (logo_shown >= 0)
1845 switch (p->scrollmode) {
1847 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1849 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1850 scr_memsetw((unsigned short *) (vc->vc_origin +
1853 vc->vc_video_erase_char,
1854 vc->vc_size_row * count);
1858 case SCROLL_WRAP_MOVE:
1859 if (b - t - count > 3 * vc->vc_rows >> 2) {
1861 fbcon_bmove(vc, 0, 0, count, 0, t,
1863 ywrap_up(vc, count);
1864 if (vc->vc_rows - b > 0)
1865 fbcon_bmove(vc, b - count, 0, b, 0,
1868 } else if (info->flags & FBINFO_READS_FAST)
1869 fbcon_bmove(vc, t + count, 0, t, 0,
1870 b - t - count, vc->vc_cols);
1873 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1876 case SCROLL_PAN_REDRAW:
1877 if ((p->yscroll + count <=
1878 2 * (p->vrows - vc->vc_rows))
1879 && ((!scroll_partial && (b - t == vc->vc_rows))
1882 3 * vc->vc_rows >> 2)))) {
1884 fbcon_redraw_move(vc, p, 0, t, count);
1885 ypan_up_redraw(vc, t, count);
1886 if (vc->vc_rows - b > 0)
1887 fbcon_redraw_move(vc, p, b,
1888 vc->vc_rows - b, b);
1890 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1891 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1894 case SCROLL_PAN_MOVE:
1895 if ((p->yscroll + count <=
1896 2 * (p->vrows - vc->vc_rows))
1897 && ((!scroll_partial && (b - t == vc->vc_rows))
1900 3 * vc->vc_rows >> 2)))) {
1902 fbcon_bmove(vc, 0, 0, count, 0, t,
1905 if (vc->vc_rows - b > 0)
1906 fbcon_bmove(vc, b - count, 0, b, 0,
1909 } else if (info->flags & FBINFO_READS_FAST)
1910 fbcon_bmove(vc, t + count, 0, t, 0,
1911 b - t - count, vc->vc_cols);
1914 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1919 fbcon_redraw(vc, p, t, b - t - count,
1920 count * vc->vc_cols);
1921 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1922 scr_memsetw((unsigned short *) (vc->vc_origin +
1925 vc->vc_video_erase_char,
1926 vc->vc_size_row * count);
1932 if (count > vc->vc_rows) /* Maximum realistic size */
1933 count = vc->vc_rows;
1934 if (logo_shown >= 0)
1936 switch (p->scrollmode) {
1938 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1940 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1941 scr_memsetw((unsigned short *) (vc->vc_origin +
1944 vc->vc_video_erase_char,
1945 vc->vc_size_row * count);
1949 case SCROLL_WRAP_MOVE:
1950 if (b - t - count > 3 * vc->vc_rows >> 2) {
1951 if (vc->vc_rows - b > 0)
1952 fbcon_bmove(vc, b, 0, b - count, 0,
1955 ywrap_down(vc, count);
1957 fbcon_bmove(vc, count, 0, 0, 0, t,
1959 } else if (info->flags & FBINFO_READS_FAST)
1960 fbcon_bmove(vc, t, 0, t + count, 0,
1961 b - t - count, vc->vc_cols);
1964 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1967 case SCROLL_PAN_MOVE:
1968 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1969 && ((!scroll_partial && (b - t == vc->vc_rows))
1972 3 * vc->vc_rows >> 2)))) {
1973 if (vc->vc_rows - b > 0)
1974 fbcon_bmove(vc, b, 0, b - count, 0,
1977 ypan_down(vc, count);
1979 fbcon_bmove(vc, count, 0, 0, 0, t,
1981 } else if (info->flags & FBINFO_READS_FAST)
1982 fbcon_bmove(vc, t, 0, t + count, 0,
1983 b - t - count, vc->vc_cols);
1986 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1989 case SCROLL_PAN_REDRAW:
1990 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1991 && ((!scroll_partial && (b - t == vc->vc_rows))
1994 3 * vc->vc_rows >> 2)))) {
1995 if (vc->vc_rows - b > 0)
1996 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1998 ypan_down_redraw(vc, t, count);
2000 fbcon_redraw_move(vc, p, count, t, 0);
2002 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2003 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2008 fbcon_redraw(vc, p, b - 1, b - t - count,
2009 -count * vc->vc_cols);
2010 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2011 scr_memsetw((unsigned short *) (vc->vc_origin +
2014 vc->vc_video_erase_char,
2015 vc->vc_size_row * count);
2023 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2024 int height, int width)
2026 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2027 struct display *p = &fb_display[vc->vc_num];
2029 if (fbcon_is_inactive(vc, info))
2032 if (!width || !height)
2035 /* Split blits that cross physical y_wrap case.
2036 * Pathological case involves 4 blits, better to use recursive
2037 * code rather than unrolled case
2039 * Recursive invocations don't need to erase the cursor over and
2040 * over again, so we use fbcon_bmove_rec()
2042 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2043 p->vrows - p->yscroll);
2046 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2047 int dy, int dx, int height, int width, u_int y_break)
2049 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2050 struct fbcon_ops *ops = info->fbcon_par;
2053 if (sy < y_break && sy + height > y_break) {
2055 if (dy < sy) { /* Avoid trashing self */
2056 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2058 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2059 height - b, width, y_break);
2061 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2062 height - b, width, y_break);
2063 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2069 if (dy < y_break && dy + height > y_break) {
2071 if (dy < sy) { /* Avoid trashing self */
2072 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2074 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2075 height - b, width, y_break);
2077 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2078 height - b, width, y_break);
2079 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2084 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2088 static void updatescrollmode(struct display *p,
2089 struct fb_info *info,
2092 struct fbcon_ops *ops = info->fbcon_par;
2093 int fh = vc->vc_font.height;
2094 int cap = info->flags;
2096 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2097 info->fix.xpanstep);
2098 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2099 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2100 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2101 info->var.xres_virtual);
2102 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2103 divides(ypan, vc->vc_font.height) && vyres > yres;
2104 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2105 divides(ywrap, vc->vc_font.height) &&
2106 divides(vc->vc_font.height, vyres) &&
2107 divides(vc->vc_font.height, yres);
2108 int reading_fast = cap & FBINFO_READS_FAST;
2109 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2110 !(cap & FBINFO_HWACCEL_DISABLED);
2111 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2112 !(cap & FBINFO_HWACCEL_DISABLED);
2114 p->vrows = vyres/fh;
2115 if (yres > (fh * (vc->vc_rows + 1)))
2116 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2117 if ((yres % fh) && (vyres % fh < yres % fh))
2120 if (good_wrap || good_pan) {
2121 if (reading_fast || fast_copyarea)
2122 p->scrollmode = good_wrap ?
2123 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2125 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2128 if (reading_fast || (fast_copyarea && !fast_imageblit))
2129 p->scrollmode = SCROLL_MOVE;
2131 p->scrollmode = SCROLL_REDRAW;
2135 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2136 unsigned int height, unsigned int user)
2138 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2139 struct fbcon_ops *ops = info->fbcon_par;
2140 struct display *p = &fb_display[vc->vc_num];
2141 struct fb_var_screeninfo var = info->var;
2142 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2144 virt_w = FBCON_SWAP(ops->rotate, width, height);
2145 virt_h = FBCON_SWAP(ops->rotate, height, width);
2146 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2147 vc->vc_font.height);
2148 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2150 var.xres = virt_w * virt_fw;
2151 var.yres = virt_h * virt_fh;
2152 x_diff = info->var.xres - var.xres;
2153 y_diff = info->var.yres - var.yres;
2154 if (x_diff < 0 || x_diff > virt_fw ||
2155 y_diff < 0 || y_diff > virt_fh) {
2156 const struct fb_videomode *mode;
2158 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2159 mode = fb_find_best_mode(&var, &info->modelist);
2162 display_to_var(&var, p);
2163 fb_videomode_to_var(&var, mode);
2165 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2168 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2169 if (CON_IS_VISIBLE(vc)) {
2170 var.activate = FB_ACTIVATE_NOW |
2172 fb_set_var(info, &var);
2174 var_to_display(p, &info->var, info);
2175 ops->var = info->var;
2177 updatescrollmode(p, info, vc);
2181 static int fbcon_switch(struct vc_data *vc)
2183 struct fb_info *info, *old_info = NULL;
2184 struct fbcon_ops *ops;
2185 struct display *p = &fb_display[vc->vc_num];
2186 struct fb_var_screeninfo var;
2187 int i, ret, prev_console, charcnt = 256;
2189 info = registered_fb[con2fb_map[vc->vc_num]];
2190 ops = info->fbcon_par;
2194 fbcon_set_origin(vc);
2195 softback_top = softback_curr = softback_in = softback_buf;
2197 fbcon_update_softback(vc);
2200 if (logo_shown >= 0) {
2201 struct vc_data *conp2 = vc_cons[logo_shown].d;
2203 if (conp2->vc_top == logo_lines
2204 && conp2->vc_bottom == conp2->vc_rows)
2206 logo_shown = FBCON_LOGO_CANSHOW;
2209 prev_console = ops->currcon;
2210 if (prev_console != -1)
2211 old_info = registered_fb[con2fb_map[prev_console]];
2213 * FIXME: If we have multiple fbdev's loaded, we need to
2214 * update all info->currcon. Perhaps, we can place this
2215 * in a centralized structure, but this might break some
2218 * info->currcon = vc->vc_num;
2220 for (i = 0; i < FB_MAX; i++) {
2221 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2222 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2224 o->currcon = vc->vc_num;
2227 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2228 display_to_var(&var, p);
2229 var.activate = FB_ACTIVATE_NOW;
2232 * make sure we don't unnecessarily trip the memcmp()
2235 info->var.activate = var.activate;
2236 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2237 fb_set_var(info, &var);
2238 ops->var = info->var;
2240 if (old_info != NULL && (old_info != info ||
2241 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2242 if (info->fbops->fb_set_par) {
2243 ret = info->fbops->fb_set_par(info);
2246 printk(KERN_ERR "fbcon_switch: detected "
2247 "unhandled fb_set_par error, "
2248 "error code %d\n", ret);
2251 if (old_info != info)
2252 fbcon_del_cursor_timer(old_info);
2255 if (fbcon_is_inactive(vc, info) ||
2256 ops->blank_state != FB_BLANK_UNBLANK)
2257 fbcon_del_cursor_timer(info);
2259 fbcon_add_cursor_timer(info);
2261 set_blitting_type(vc, info);
2262 ops->cursor_reset = 1;
2264 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2265 ops->rotate = FB_ROTATE_UR;
2266 set_blitting_type(vc, info);
2269 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2270 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2273 charcnt = FNTCHARCNT(vc->vc_font.data);
2276 vc->vc_complement_mask <<= 1;
2278 updatescrollmode(p, info, vc);
2280 switch (p->scrollmode) {
2281 case SCROLL_WRAP_MOVE:
2282 scrollback_phys_max = p->vrows - vc->vc_rows;
2284 case SCROLL_PAN_MOVE:
2285 case SCROLL_PAN_REDRAW:
2286 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2287 if (scrollback_phys_max < 0)
2288 scrollback_phys_max = 0;
2291 scrollback_phys_max = 0;
2296 scrollback_current = 0;
2298 if (!fbcon_is_inactive(vc, info)) {
2299 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2300 ops->update_start(info);
2303 fbcon_set_palette(vc, color_table);
2304 fbcon_clear_margins(vc, 0);
2306 if (logo_shown == FBCON_LOGO_DRAW) {
2308 logo_shown = fg_console;
2309 /* This is protected above by initmem_freed */
2310 fb_show_logo(info, ops->rotate);
2312 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2313 vc->vc_size_row * (vc->vc_bottom -
2320 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2323 struct fb_event event;
2326 unsigned short charmask = vc->vc_hi_font_mask ?
2328 unsigned short oldc;
2330 oldc = vc->vc_video_erase_char;
2331 vc->vc_video_erase_char &= charmask;
2332 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2333 vc->vc_video_erase_char = oldc;
2337 if (!lock_fb_info(info))
2340 event.data = ␣
2341 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2342 unlock_fb_info(info);
2345 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2347 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2348 struct fbcon_ops *ops = info->fbcon_par;
2351 struct fb_var_screeninfo var = info->var;
2356 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2357 fb_set_var(info, &var);
2359 ops->var = info->var;
2363 if (!fbcon_is_inactive(vc, info)) {
2364 if (ops->blank_state != blank) {
2365 ops->blank_state = blank;
2366 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2367 ops->cursor_flash = (!blank);
2369 if (!(info->flags & FBINFO_MISC_USEREVENT))
2370 if (fb_blank(info, blank))
2371 fbcon_generic_blank(vc, info, blank);
2378 if (mode_switch || fbcon_is_inactive(vc, info) ||
2379 ops->blank_state != FB_BLANK_UNBLANK)
2380 fbcon_del_cursor_timer(info);
2382 fbcon_add_cursor_timer(info);
2387 static int fbcon_debug_enter(struct vc_data *vc)
2389 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2390 struct fbcon_ops *ops = info->fbcon_par;
2392 ops->save_graphics = ops->graphics;
2394 if (info->fbops->fb_debug_enter)
2395 info->fbops->fb_debug_enter(info);
2396 fbcon_set_palette(vc, color_table);
2400 static int fbcon_debug_leave(struct vc_data *vc)
2402 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2403 struct fbcon_ops *ops = info->fbcon_par;
2405 ops->graphics = ops->save_graphics;
2406 if (info->fbops->fb_debug_leave)
2407 info->fbops->fb_debug_leave(info);
2411 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2413 u8 *fontdata = vc->vc_font.data;
2414 u8 *data = font->data;
2417 font->width = vc->vc_font.width;
2418 font->height = vc->vc_font.height;
2419 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2423 if (font->width <= 8) {
2424 j = vc->vc_font.height;
2425 for (i = 0; i < font->charcount; i++) {
2426 memcpy(data, fontdata, j);
2427 memset(data + j, 0, 32 - j);
2431 } else if (font->width <= 16) {
2432 j = vc->vc_font.height * 2;
2433 for (i = 0; i < font->charcount; i++) {
2434 memcpy(data, fontdata, j);
2435 memset(data + j, 0, 64 - j);
2439 } else if (font->width <= 24) {
2440 for (i = 0; i < font->charcount; i++) {
2441 for (j = 0; j < vc->vc_font.height; j++) {
2442 *data++ = fontdata[0];
2443 *data++ = fontdata[1];
2444 *data++ = fontdata[2];
2445 fontdata += sizeof(u32);
2447 memset(data, 0, 3 * (32 - j));
2448 data += 3 * (32 - j);
2451 j = vc->vc_font.height * 4;
2452 for (i = 0; i < font->charcount; i++) {
2453 memcpy(data, fontdata, j);
2454 memset(data + j, 0, 128 - j);
2462 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2463 const u8 * data, int userfont)
2465 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2466 struct fbcon_ops *ops = info->fbcon_par;
2467 struct display *p = &fb_display[vc->vc_num];
2470 char *old_data = NULL;
2472 if (CON_IS_VISIBLE(vc) && softback_lines)
2473 fbcon_set_origin(vc);
2475 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2477 old_data = vc->vc_font.data;
2479 cnt = FNTCHARCNT(data);
2482 vc->vc_font.data = (void *)(p->fontdata = data);
2483 if ((p->userfont = userfont))
2485 vc->vc_font.width = w;
2486 vc->vc_font.height = h;
2487 if (vc->vc_hi_font_mask && cnt == 256) {
2488 vc->vc_hi_font_mask = 0;
2489 if (vc->vc_can_do_color) {
2490 vc->vc_complement_mask >>= 1;
2491 vc->vc_s_complement_mask >>= 1;
2494 /* ++Edmund: reorder the attribute bits */
2495 if (vc->vc_can_do_color) {
2496 unsigned short *cp =
2497 (unsigned short *) vc->vc_origin;
2498 int count = vc->vc_screenbuf_size / 2;
2500 for (; count > 0; count--, cp++) {
2502 scr_writew(((c & 0xfe00) >> 1) |
2505 c = vc->vc_video_erase_char;
2506 vc->vc_video_erase_char =
2507 ((c & 0xfe00) >> 1) | (c & 0xff);
2510 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2511 vc->vc_hi_font_mask = 0x100;
2512 if (vc->vc_can_do_color) {
2513 vc->vc_complement_mask <<= 1;
2514 vc->vc_s_complement_mask <<= 1;
2517 /* ++Edmund: reorder the attribute bits */
2519 unsigned short *cp =
2520 (unsigned short *) vc->vc_origin;
2521 int count = vc->vc_screenbuf_size / 2;
2523 for (; count > 0; count--, cp++) {
2524 unsigned short newc;
2526 if (vc->vc_can_do_color)
2528 ((c & 0xff00) << 1) | (c &
2532 scr_writew(newc, cp);
2534 c = vc->vc_video_erase_char;
2535 if (vc->vc_can_do_color) {
2536 vc->vc_video_erase_char =
2537 ((c & 0xff00) << 1) | (c & 0xff);
2540 vc->vc_video_erase_char = c & ~0x100;
2548 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2549 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2552 vc_resize(vc, cols, rows);
2553 if (CON_IS_VISIBLE(vc) && softback_buf)
2554 fbcon_update_softback(vc);
2555 } else if (CON_IS_VISIBLE(vc)
2556 && vc->vc_mode == KD_TEXT) {
2557 fbcon_clear_margins(vc, 0);
2561 if (old_data && (--REFCOUNT(old_data) == 0))
2562 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2566 static int fbcon_copy_font(struct vc_data *vc, int con)
2568 struct display *od = &fb_display[con];
2569 struct console_font *f = &vc->vc_font;
2571 if (od->fontdata == f->data)
2572 return 0; /* already the same font... */
2573 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2577 * User asked to set font; we are guaranteed that
2578 * a) width and height are in range 1..32
2579 * b) charcount does not exceed 512
2580 * but lets not assume that, since someone might someday want to use larger
2581 * fonts. And charcount of 512 is small for unicode support.
2583 * However, user space gives the font in 32 rows , regardless of
2584 * actual font height. So a new API is needed if support for larger fonts
2585 * is ever implemented.
2588 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2590 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2591 unsigned charcount = font->charcount;
2592 int w = font->width;
2593 int h = font->height;
2596 u8 *new_data, *data = font->data;
2597 int pitch = (font->width+7) >> 3;
2599 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2600 * If not this check should be changed to charcount < 256 */
2601 if (charcount != 256 && charcount != 512)
2604 /* Make sure drawing engine can handle the font */
2605 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2606 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2609 /* Make sure driver can handle the font length */
2610 if (fbcon_invalid_charcount(info, charcount))
2613 size = h * pitch * charcount;
2615 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2620 new_data += FONT_EXTRA_WORDS * sizeof(int);
2621 FNTSIZE(new_data) = size;
2622 FNTCHARCNT(new_data) = charcount;
2623 REFCOUNT(new_data) = 0; /* usage counter */
2624 for (i=0; i< charcount; i++) {
2625 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2628 /* Since linux has a nice crc32 function use it for counting font
2630 csum = crc32(0, new_data, size);
2632 FNTSUM(new_data) = csum;
2633 /* Check if the same font is on some other console already */
2634 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2635 struct vc_data *tmp = vc_cons[i].d;
2637 if (fb_display[i].userfont &&
2638 fb_display[i].fontdata &&
2639 FNTSUM(fb_display[i].fontdata) == csum &&
2640 FNTSIZE(fb_display[i].fontdata) == size &&
2641 tmp->vc_font.width == w &&
2642 !memcmp(fb_display[i].fontdata, new_data, size)) {
2643 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2644 new_data = (u8 *)fb_display[i].fontdata;
2648 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2651 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2653 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2654 const struct font_desc *f;
2657 f = get_default_font(info->var.xres, info->var.yres,
2658 info->pixmap.blit_x, info->pixmap.blit_y);
2659 else if (!(f = find_font(name)))
2662 font->width = f->width;
2663 font->height = f->height;
2664 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2667 static u16 palette_red[16];
2668 static u16 palette_green[16];
2669 static u16 palette_blue[16];
2671 static struct fb_cmap palette_cmap = {
2672 0, 16, palette_red, palette_green, palette_blue, NULL
2675 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2677 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2681 if (fbcon_is_inactive(vc, info))
2684 if (!CON_IS_VISIBLE(vc))
2687 depth = fb_get_color_depth(&info->var, &info->fix);
2689 for (i = j = 0; i < 16; i++) {
2691 val = vc->vc_palette[j++];
2692 palette_red[k] = (val << 8) | val;
2693 val = vc->vc_palette[j++];
2694 palette_green[k] = (val << 8) | val;
2695 val = vc->vc_palette[j++];
2696 palette_blue[k] = (val << 8) | val;
2698 palette_cmap.len = 16;
2699 palette_cmap.start = 0;
2701 * If framebuffer is capable of less than 16 colors,
2702 * use default palette of fbcon.
2705 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2707 return fb_set_cmap(&palette_cmap, info);
2710 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2715 if (vc->vc_num != fg_console || !softback_lines)
2716 return (u16 *) (vc->vc_origin + offset);
2717 line = offset / vc->vc_size_row;
2718 if (line >= softback_lines)
2719 return (u16 *) (vc->vc_origin + offset -
2720 softback_lines * vc->vc_size_row);
2721 p = softback_curr + offset;
2722 if (p >= softback_end)
2723 p += softback_buf - softback_end;
2727 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2733 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2734 unsigned long offset = (pos - vc->vc_origin) / 2;
2736 x = offset % vc->vc_cols;
2737 y = offset / vc->vc_cols;
2738 if (vc->vc_num == fg_console)
2739 y += softback_lines;
2740 ret = pos + (vc->vc_cols - x) * 2;
2741 } else if (vc->vc_num == fg_console && softback_lines) {
2742 unsigned long offset = pos - softback_curr;
2744 if (pos < softback_curr)
2745 offset += softback_end - softback_buf;
2747 x = offset % vc->vc_cols;
2748 y = offset / vc->vc_cols;
2749 ret = pos + (vc->vc_cols - x) * 2;
2750 if (ret == softback_end)
2752 if (ret == softback_in)
2753 ret = vc->vc_origin;
2755 /* Should not happen */
2757 ret = vc->vc_origin;
2766 /* As we might be inside of softback, we may work with non-contiguous buffer,
2767 that's why we have to use a separate routine. */
2768 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2771 u16 a = scr_readw(p);
2772 if (!vc->vc_can_do_color)
2774 else if (vc->vc_hi_font_mask == 0x100)
2775 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2776 (((a) & 0x0e00) << 4);
2778 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2779 (((a) & 0x0700) << 4);
2781 if (p == (u16 *) softback_end)
2782 p = (u16 *) softback_buf;
2783 if (p == (u16 *) softback_in)
2784 p = (u16 *) vc->vc_origin;
2788 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2790 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2791 struct fbcon_ops *ops = info->fbcon_par;
2792 struct display *disp = &fb_display[fg_console];
2793 int offset, limit, scrollback_old;
2796 if (vc->vc_num != fg_console)
2798 if (vc->vc_mode != KD_TEXT || !lines)
2800 if (logo_shown >= 0) {
2801 struct vc_data *conp2 = vc_cons[logo_shown].d;
2803 if (conp2->vc_top == logo_lines
2804 && conp2->vc_bottom == conp2->vc_rows)
2806 if (logo_shown == vc->vc_num) {
2812 logo_lines * vc->vc_size_row;
2813 for (i = 0; i < logo_lines; i++) {
2814 if (p == softback_top)
2816 if (p == softback_buf)
2818 p -= vc->vc_size_row;
2819 q -= vc->vc_size_row;
2820 scr_memcpyw((u16 *) q, (u16 *) p,
2823 softback_in = softback_curr = p;
2824 update_region(vc, vc->vc_origin,
2825 logo_lines * vc->vc_cols);
2827 logo_shown = FBCON_LOGO_CANSHOW;
2829 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2830 fbcon_redraw_softback(vc, disp, lines);
2831 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2835 if (!scrollback_phys_max)
2838 scrollback_old = scrollback_current;
2839 scrollback_current -= lines;
2840 if (scrollback_current < 0)
2841 scrollback_current = 0;
2842 else if (scrollback_current > scrollback_max)
2843 scrollback_current = scrollback_max;
2844 if (scrollback_current == scrollback_old)
2847 if (fbcon_is_inactive(vc, info))
2850 fbcon_cursor(vc, CM_ERASE);
2852 offset = disp->yscroll - scrollback_current;
2853 limit = disp->vrows;
2854 switch (disp->scrollmode) {
2855 case SCROLL_WRAP_MOVE:
2856 info->var.vmode |= FB_VMODE_YWRAP;
2858 case SCROLL_PAN_MOVE:
2859 case SCROLL_PAN_REDRAW:
2860 limit -= vc->vc_rows;
2861 info->var.vmode &= ~FB_VMODE_YWRAP;
2866 else if (offset >= limit)
2869 ops->var.xoffset = 0;
2870 ops->var.yoffset = offset * vc->vc_font.height;
2871 ops->update_start(info);
2873 if (!scrollback_current)
2874 fbcon_cursor(vc, CM_DRAW);
2878 static int fbcon_set_origin(struct vc_data *vc)
2881 fbcon_scrolldelta(vc, softback_lines);
2885 static void fbcon_suspended(struct fb_info *info)
2887 struct vc_data *vc = NULL;
2888 struct fbcon_ops *ops = info->fbcon_par;
2890 if (!ops || ops->currcon < 0)
2892 vc = vc_cons[ops->currcon].d;
2894 /* Clear cursor, restore saved data */
2895 fbcon_cursor(vc, CM_ERASE);
2898 static void fbcon_resumed(struct fb_info *info)
2901 struct fbcon_ops *ops = info->fbcon_par;
2903 if (!ops || ops->currcon < 0)
2905 vc = vc_cons[ops->currcon].d;
2910 static void fbcon_modechanged(struct fb_info *info)
2912 struct fbcon_ops *ops = info->fbcon_par;
2917 if (!ops || ops->currcon < 0)
2919 vc = vc_cons[ops->currcon].d;
2920 if (vc->vc_mode != KD_TEXT ||
2921 registered_fb[con2fb_map[ops->currcon]] != info)
2924 p = &fb_display[vc->vc_num];
2925 set_blitting_type(vc, info);
2927 if (CON_IS_VISIBLE(vc)) {
2928 var_to_display(p, &info->var, info);
2929 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2930 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2931 cols /= vc->vc_font.width;
2932 rows /= vc->vc_font.height;
2933 vc_resize(vc, cols, rows);
2934 updatescrollmode(p, info, vc);
2936 scrollback_current = 0;
2938 if (!fbcon_is_inactive(vc, info)) {
2939 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2940 ops->update_start(info);
2943 fbcon_set_palette(vc, color_table);
2946 fbcon_update_softback(vc);
2950 static void fbcon_set_all_vcs(struct fb_info *info)
2952 struct fbcon_ops *ops = info->fbcon_par;
2955 int i, rows, cols, fg = -1;
2957 if (!ops || ops->currcon < 0)
2960 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2962 if (!vc || vc->vc_mode != KD_TEXT ||
2963 registered_fb[con2fb_map[i]] != info)
2966 if (CON_IS_VISIBLE(vc)) {
2971 p = &fb_display[vc->vc_num];
2972 set_blitting_type(vc, info);
2973 var_to_display(p, &info->var, info);
2974 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2975 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2976 cols /= vc->vc_font.width;
2977 rows /= vc->vc_font.height;
2978 vc_resize(vc, cols, rows);
2982 fbcon_modechanged(info);
2985 static int fbcon_mode_deleted(struct fb_info *info,
2986 struct fb_videomode *mode)
2988 struct fb_info *fb_info;
2990 int i, j, found = 0;
2992 /* before deletion, ensure that mode is not in use */
2993 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2997 fb_info = registered_fb[j];
2998 if (fb_info != info)
3003 if (fb_mode_is_equal(p->mode, mode)) {
3011 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3012 static int fbcon_unbind(void)
3016 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3020 fbcon_has_console_bind = 0;
3025 static inline int fbcon_unbind(void)
3029 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3031 /* called with console_lock held */
3032 static int fbcon_fb_unbind(int idx)
3034 int i, new_idx = -1, ret = 0;
3036 if (!fbcon_has_console_bind)
3039 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3040 if (con2fb_map[i] != idx &&
3041 con2fb_map[i] != -1) {
3047 if (new_idx != -1) {
3048 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3049 if (con2fb_map[i] == idx)
3050 set_con2fb_map(i, new_idx, 0);
3053 ret = fbcon_unbind();
3058 /* called with console_lock held */
3059 static int fbcon_fb_unregistered(struct fb_info *info)
3064 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3065 if (con2fb_map[i] == idx)
3069 if (idx == info_idx) {
3072 for (i = 0; i < FB_MAX; i++) {
3073 if (registered_fb[i] != NULL) {
3080 if (info_idx != -1) {
3081 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3082 if (con2fb_map[i] == -1)
3083 con2fb_map[i] = info_idx;
3087 if (primary_device == idx)
3088 primary_device = -1;
3090 if (!num_registered_fb)
3091 do_unregister_con_driver(&fb_con);
3096 /* called with console_lock held */
3097 static void fbcon_remap_all(int idx)
3100 for (i = first_fb_vc; i <= last_fb_vc; i++)
3101 set_con2fb_map(i, idx, 0);
3103 if (con_is_bound(&fb_con)) {
3104 printk(KERN_INFO "fbcon: Remapping primary device, "
3105 "fb%i, to tty %i-%i\n", idx,
3106 first_fb_vc + 1, last_fb_vc + 1);
3111 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3112 static void fbcon_select_primary(struct fb_info *info)
3114 if (!map_override && primary_device == -1 &&
3115 fb_is_primary_device(info)) {
3118 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3119 info->fix.id, info->node);
3120 primary_device = info->node;
3122 for (i = first_fb_vc; i <= last_fb_vc; i++)
3123 con2fb_map_boot[i] = primary_device;
3125 if (con_is_bound(&fb_con)) {
3126 printk(KERN_INFO "fbcon: Remapping primary device, "
3127 "fb%i, to tty %i-%i\n", info->node,
3128 first_fb_vc + 1, last_fb_vc + 1);
3129 info_idx = primary_device;
3135 static inline void fbcon_select_primary(struct fb_info *info)
3139 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3141 /* called with console_lock held */
3142 static int fbcon_fb_registered(struct fb_info *info)
3144 int ret = 0, i, idx;
3147 fbcon_select_primary(info);
3149 if (info_idx == -1) {
3150 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3151 if (con2fb_map_boot[i] == idx) {
3158 ret = do_fbcon_takeover(1);
3160 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3161 if (con2fb_map_boot[i] == idx)
3162 set_con2fb_map(i, idx, 0);
3169 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3171 struct fbcon_ops *ops = info->fbcon_par;
3174 if (!ops || ops->currcon < 0)
3177 vc = vc_cons[ops->currcon].d;
3178 if (vc->vc_mode != KD_TEXT ||
3179 registered_fb[con2fb_map[ops->currcon]] != info)
3182 if (CON_IS_VISIBLE(vc)) {
3186 do_unblank_screen(0);
3188 ops->blank_state = blank;
3191 static void fbcon_new_modelist(struct fb_info *info)
3195 struct fb_var_screeninfo var;
3196 const struct fb_videomode *mode;
3198 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3199 if (registered_fb[con2fb_map[i]] != info)
3201 if (!fb_display[i].mode)
3204 display_to_var(&var, &fb_display[i]);
3205 mode = fb_find_nearest_mode(fb_display[i].mode,
3207 fb_videomode_to_var(&var, mode);
3208 fbcon_set_disp(info, &var, vc->vc_num);
3212 static void fbcon_get_requirement(struct fb_info *info,
3213 struct fb_blit_caps *caps)
3221 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3223 if (vc && vc->vc_mode == KD_TEXT &&
3224 info->node == con2fb_map[i]) {
3226 caps->x |= 1 << (vc->vc_font.width - 1);
3227 caps->y |= 1 << (vc->vc_font.height - 1);
3228 charcnt = (p->userfont) ?
3229 FNTCHARCNT(p->fontdata) : 256;
3230 if (caps->len < charcnt)
3231 caps->len = charcnt;
3235 vc = vc_cons[fg_console].d;
3237 if (vc && vc->vc_mode == KD_TEXT &&
3238 info->node == con2fb_map[fg_console]) {
3239 p = &fb_display[fg_console];
3240 caps->x = 1 << (vc->vc_font.width - 1);
3241 caps->y = 1 << (vc->vc_font.height - 1);
3242 caps->len = (p->userfont) ?
3243 FNTCHARCNT(p->fontdata) : 256;
3248 static int fbcon_event_notify(struct notifier_block *self,
3249 unsigned long action, void *data)
3251 struct fb_event *event = data;
3252 struct fb_info *info = event->info;
3253 struct fb_videomode *mode;
3254 struct fb_con2fbmap *con2fb;
3255 struct fb_blit_caps *caps;
3259 * ignore all events except driver registration and deregistration
3260 * if fbcon is not active
3262 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3263 action == FB_EVENT_FB_UNREGISTERED))
3267 case FB_EVENT_SUSPEND:
3268 fbcon_suspended(info);
3270 case FB_EVENT_RESUME:
3271 fbcon_resumed(info);
3273 case FB_EVENT_MODE_CHANGE:
3274 fbcon_modechanged(info);
3276 case FB_EVENT_MODE_CHANGE_ALL:
3277 fbcon_set_all_vcs(info);
3279 case FB_EVENT_MODE_DELETE:
3281 ret = fbcon_mode_deleted(info, mode);
3283 case FB_EVENT_FB_UNBIND:
3285 ret = fbcon_fb_unbind(idx);
3287 case FB_EVENT_FB_REGISTERED:
3288 ret = fbcon_fb_registered(info);
3290 case FB_EVENT_FB_UNREGISTERED:
3291 ret = fbcon_fb_unregistered(info);
3293 case FB_EVENT_SET_CONSOLE_MAP:
3294 /* called with console lock held */
3295 con2fb = event->data;
3296 ret = set_con2fb_map(con2fb->console - 1,
3297 con2fb->framebuffer, 1);
3299 case FB_EVENT_GET_CONSOLE_MAP:
3300 con2fb = event->data;
3301 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3303 case FB_EVENT_BLANK:
3304 fbcon_fb_blanked(info, *(int *)event->data);
3306 case FB_EVENT_NEW_MODELIST:
3307 fbcon_new_modelist(info);
3309 case FB_EVENT_GET_REQ:
3311 fbcon_get_requirement(info, caps);
3313 case FB_EVENT_REMAP_ALL_CONSOLE:
3315 fbcon_remap_all(idx);
3323 * The console `switch' structure for the frame buffer based console
3326 static const struct consw fb_con = {
3327 .owner = THIS_MODULE,
3328 .con_startup = fbcon_startup,
3329 .con_init = fbcon_init,
3330 .con_deinit = fbcon_deinit,
3331 .con_clear = fbcon_clear,
3332 .con_putc = fbcon_putc,
3333 .con_putcs = fbcon_putcs,
3334 .con_cursor = fbcon_cursor,
3335 .con_scroll = fbcon_scroll,
3336 .con_bmove = fbcon_bmove,
3337 .con_switch = fbcon_switch,
3338 .con_blank = fbcon_blank,
3339 .con_font_set = fbcon_set_font,
3340 .con_font_get = fbcon_get_font,
3341 .con_font_default = fbcon_set_def_font,
3342 .con_font_copy = fbcon_copy_font,
3343 .con_set_palette = fbcon_set_palette,
3344 .con_scrolldelta = fbcon_scrolldelta,
3345 .con_set_origin = fbcon_set_origin,
3346 .con_invert_region = fbcon_invert_region,
3347 .con_screen_pos = fbcon_screen_pos,
3348 .con_getxy = fbcon_getxy,
3349 .con_resize = fbcon_resize,
3350 .con_debug_enter = fbcon_debug_enter,
3351 .con_debug_leave = fbcon_debug_leave,
3354 static struct notifier_block fbcon_event_notifier = {
3355 .notifier_call = fbcon_event_notify,
3358 static ssize_t store_rotate(struct device *device,
3359 struct device_attribute *attr, const char *buf,
3362 struct fb_info *info;
3366 if (fbcon_has_exited)
3370 idx = con2fb_map[fg_console];
3372 if (idx == -1 || registered_fb[idx] == NULL)
3375 info = registered_fb[idx];
3376 rotate = simple_strtoul(buf, last, 0);
3377 fbcon_rotate(info, rotate);
3383 static ssize_t store_rotate_all(struct device *device,
3384 struct device_attribute *attr,const char *buf,
3387 struct fb_info *info;
3391 if (fbcon_has_exited)
3395 idx = con2fb_map[fg_console];
3397 if (idx == -1 || registered_fb[idx] == NULL)
3400 info = registered_fb[idx];
3401 rotate = simple_strtoul(buf, last, 0);
3402 fbcon_rotate_all(info, rotate);
3408 static ssize_t show_rotate(struct device *device,
3409 struct device_attribute *attr,char *buf)
3411 struct fb_info *info;
3412 int rotate = 0, idx;
3414 if (fbcon_has_exited)
3418 idx = con2fb_map[fg_console];
3420 if (idx == -1 || registered_fb[idx] == NULL)
3423 info = registered_fb[idx];
3424 rotate = fbcon_get_rotate(info);
3427 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3430 static ssize_t show_cursor_blink(struct device *device,
3431 struct device_attribute *attr, char *buf)
3433 struct fb_info *info;
3434 struct fbcon_ops *ops;
3435 int idx, blink = -1;
3437 if (fbcon_has_exited)
3441 idx = con2fb_map[fg_console];
3443 if (idx == -1 || registered_fb[idx] == NULL)
3446 info = registered_fb[idx];
3447 ops = info->fbcon_par;
3452 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3455 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3458 static ssize_t store_cursor_blink(struct device *device,
3459 struct device_attribute *attr,
3460 const char *buf, size_t count)
3462 struct fb_info *info;
3466 if (fbcon_has_exited)
3470 idx = con2fb_map[fg_console];
3472 if (idx == -1 || registered_fb[idx] == NULL)
3475 info = registered_fb[idx];
3477 if (!info->fbcon_par)
3480 blink = simple_strtoul(buf, last, 0);
3483 fbcon_cursor_noblink = 0;
3484 fbcon_add_cursor_timer(info);
3486 fbcon_cursor_noblink = 1;
3487 fbcon_del_cursor_timer(info);
3495 static struct device_attribute device_attrs[] = {
3496 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3497 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3498 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3499 store_cursor_blink),
3502 static int fbcon_init_device(void)
3506 fbcon_has_sysfs = 1;
3508 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3509 error = device_create_file(fbcon_device, &device_attrs[i]);
3517 device_remove_file(fbcon_device, &device_attrs[i]);
3519 fbcon_has_sysfs = 0;
3525 static void fbcon_start(void)
3527 if (num_registered_fb) {
3532 for (i = 0; i < FB_MAX; i++) {
3533 if (registered_fb[i] != NULL) {
3544 static void fbcon_exit(void)
3546 struct fb_info *info;
3549 if (fbcon_has_exited)
3552 kfree((void *)softback_buf);
3555 for (i = 0; i < FB_MAX; i++) {
3559 info = registered_fb[i];
3564 if (info->queue.func)
3565 pending = cancel_work_sync(&info->queue);
3566 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3569 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3570 if (con2fb_map[j] == i)
3575 if (info->fbops->fb_release)
3576 info->fbops->fb_release(info, 0);
3577 module_put(info->fbops->owner);
3579 if (info->fbcon_par) {
3580 struct fbcon_ops *ops = info->fbcon_par;
3582 fbcon_del_cursor_timer(info);
3583 kfree(ops->cursor_src);
3584 kfree(info->fbcon_par);
3585 info->fbcon_par = NULL;
3588 if (info->queue.func == fb_flashcursor)
3589 info->queue.func = NULL;
3593 fbcon_has_exited = 1;
3596 static int __init fb_console_init(void)
3601 fb_register_client(&fbcon_event_notifier);
3602 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3605 if (IS_ERR(fbcon_device)) {
3606 printk(KERN_WARNING "Unable to create device "
3607 "for fbcon; errno = %ld\n",
3608 PTR_ERR(fbcon_device));
3609 fbcon_device = NULL;
3611 fbcon_init_device();
3613 for (i = 0; i < MAX_NR_CONSOLES; i++)
3621 module_init(fb_console_init);
3625 static void __exit fbcon_deinit_device(void)
3629 if (fbcon_has_sysfs) {
3630 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3631 device_remove_file(fbcon_device, &device_attrs[i]);
3633 fbcon_has_sysfs = 0;
3637 static void __exit fb_console_exit(void)
3640 fb_unregister_client(&fbcon_event_notifier);
3641 fbcon_deinit_device();
3642 device_destroy(fb_class, MKDEV(0, 0));
3645 unregister_con_driver(&fb_con);
3648 module_exit(fb_console_exit);
3652 MODULE_LICENSE("GPL");