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>
81 #include <asm/uaccess.h>
83 #include <asm/atariints.h>
86 #include <asm/macints.h>
88 #if defined(__mc68000__) || defined(CONFIG_APUS)
89 #include <asm/machdep.h>
90 #include <asm/setup.h>
96 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
98 # define DPRINTK(fmt, args...)
102 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
103 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
104 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
107 static struct display fb_display[MAX_NR_CONSOLES];
109 static signed char con2fb_map[MAX_NR_CONSOLES];
110 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
112 static int logo_height;
114 static int logo_lines;
115 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
117 static int logo_shown = FBCON_LOGO_CANSHOW;
118 /* Software scrollback */
119 static int fbcon_softback_size = 32768;
120 static unsigned long softback_buf, softback_curr;
121 static unsigned long softback_in;
122 static unsigned long softback_top, softback_end;
123 static int softback_lines;
124 /* console mappings */
125 static int first_fb_vc;
126 static int last_fb_vc = MAX_NR_CONSOLES - 1;
127 static int fbcon_is_default = 1;
128 static int fbcon_has_exited;
129 static int primary_device = -1;
130 static int map_override;
133 static char fontname[40];
135 /* current fb_info */
136 static int info_idx = -1;
138 /* console 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 /* # VBL ints between cursor state changes */
153 #define ATARI_CURSOR_BLINK_RATE (42)
154 #define MAC_CURSOR_BLINK_RATE (32)
155 #define DEFAULT_CURSOR_BLINK_RATE (20)
157 static int vbl_cursor_cnt;
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_scroll(struct vc_data *vc, int t, int b, int dir,
178 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
179 int height, int width);
180 static int fbcon_switch(struct vc_data *vc);
181 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
182 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
183 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
188 static __inline__ void ywrap_up(struct vc_data *vc, int count);
189 static __inline__ void ywrap_down(struct vc_data *vc, int count);
190 static __inline__ void ypan_up(struct vc_data *vc, int count);
191 static __inline__ void ypan_down(struct vc_data *vc, int count);
192 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
193 int dy, int dx, int height, int width, u_int y_break);
194 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
196 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
197 int line, int count, int dy);
198 static void fbcon_modechanged(struct fb_info *info);
199 static void fbcon_set_all_vcs(struct fb_info *info);
200 static void fbcon_start(void);
201 static void fbcon_exit(void);
202 static struct device *fbcon_device;
206 * On the Macintoy, there may or may not be a working VBL int. We need to probe
208 static int vbl_detected;
210 static irqreturn_t fb_vbl_detect(int irq, void *dummy)
217 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
218 static inline void fbcon_set_rotation(struct fb_info *info)
220 struct fbcon_ops *ops = info->fbcon_par;
222 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
223 ops->p->con_rotate < 4)
224 ops->rotate = ops->p->con_rotate;
229 static void fbcon_rotate(struct fb_info *info, u32 rotate)
231 struct fbcon_ops *ops= info->fbcon_par;
232 struct fb_info *fb_info;
234 if (!ops || ops->currcon == -1)
237 fb_info = registered_fb[con2fb_map[ops->currcon]];
239 if (info == fb_info) {
240 struct display *p = &fb_display[ops->currcon];
243 p->con_rotate = rotate;
247 fbcon_modechanged(info);
251 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
253 struct fbcon_ops *ops = info->fbcon_par;
258 if (!ops || ops->currcon < 0 || rotate > 3)
261 for (i = first_fb_vc; i <= last_fb_vc; i++) {
263 if (!vc || vc->vc_mode != KD_TEXT ||
264 registered_fb[con2fb_map[i]] != info)
267 p = &fb_display[vc->vc_num];
268 p->con_rotate = rotate;
271 fbcon_set_all_vcs(info);
274 static inline void fbcon_set_rotation(struct fb_info *info)
276 struct fbcon_ops *ops = info->fbcon_par;
278 ops->rotate = FB_ROTATE_UR;
281 static void fbcon_rotate(struct fb_info *info, u32 rotate)
286 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
290 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
292 static int fbcon_get_rotate(struct fb_info *info)
294 struct fbcon_ops *ops = info->fbcon_par;
296 return (ops) ? ops->rotate : 0;
299 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
301 struct fbcon_ops *ops = info->fbcon_par;
303 return (info->state != FBINFO_STATE_RUNNING ||
304 vc->vc_mode != KD_TEXT || ops->graphics);
307 static inline int get_color(struct vc_data *vc, struct fb_info *info,
310 int depth = fb_get_color_depth(&info->var, &info->fix);
313 if (console_blanked) {
314 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
316 c = vc->vc_video_erase_char & charmask;
320 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
321 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
326 int col = ~(0xfff << (max(info->var.green.length,
327 max(info->var.red.length,
328 info->var.blue.length)))) & 0xff;
331 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
332 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
337 color = (is_fg) ? fg : bg;
342 * Scale down 16-colors to 4 colors. Default 4-color palette
343 * is grayscale. However, simply dividing the values by 4
344 * will not work, as colors 1, 2 and 3 will be scaled-down
345 * to zero rendering them invisible. So empirically convert
346 * colors to a sane 4-level grayscale.
350 color = 0; /* black */
353 color = 2; /* white */
356 color = 1; /* gray */
359 color = 3; /* intense white */
365 * Last 8 entries of default 16-color palette is a more intense
366 * version of the first 8 (i.e., same chrominance, different
377 static void fbcon_update_softback(struct vc_data *vc)
379 int l = fbcon_softback_size / vc->vc_size_row;
382 softback_end = softback_buf + l * vc->vc_size_row;
384 /* Smaller scrollback makes no sense, and 0 would screw
385 the operation totally */
389 static void fb_flashcursor(struct work_struct *work)
391 struct fb_info *info = container_of(work, struct fb_info, queue);
392 struct fbcon_ops *ops = info->fbcon_par;
394 struct vc_data *vc = NULL;
398 acquire_console_sem();
399 if (ops && ops->currcon != -1)
400 vc = vc_cons[ops->currcon].d;
402 if (!vc || !CON_IS_VISIBLE(vc) ||
403 registered_fb[con2fb_map[vc->vc_num]] != info ||
405 release_console_sem();
409 p = &fb_display[vc->vc_num];
410 c = scr_readw((u16 *) vc->vc_pos);
411 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
413 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
414 get_color(vc, info, c, 0));
415 release_console_sem();
418 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
419 static int cursor_blink_rate;
420 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
422 struct fb_info *info = dev_id;
424 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
425 schedule_work(&info->queue);
426 vbl_cursor_cnt = cursor_blink_rate;
432 static void cursor_timer_handler(unsigned long dev_addr)
434 struct fb_info *info = (struct fb_info *) dev_addr;
435 struct fbcon_ops *ops = info->fbcon_par;
437 schedule_work(&info->queue);
438 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
441 static void fbcon_add_cursor_timer(struct fb_info *info)
443 struct fbcon_ops *ops = info->fbcon_par;
445 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
446 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
447 !fbcon_cursor_noblink) {
448 if (!info->queue.func)
449 INIT_WORK(&info->queue, fb_flashcursor);
451 init_timer(&ops->cursor_timer);
452 ops->cursor_timer.function = cursor_timer_handler;
453 ops->cursor_timer.expires = jiffies + HZ / 5;
454 ops->cursor_timer.data = (unsigned long ) info;
455 add_timer(&ops->cursor_timer);
456 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
460 static void fbcon_del_cursor_timer(struct fb_info *info)
462 struct fbcon_ops *ops = info->fbcon_par;
464 if (info->queue.func == fb_flashcursor &&
465 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
466 del_timer_sync(&ops->cursor_timer);
467 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
472 static int __init fb_console_setup(char *this_opt)
477 if (!this_opt || !*this_opt)
480 while ((options = strsep(&this_opt, ",")) != NULL) {
481 if (!strncmp(options, "font:", 5))
482 strcpy(fontname, options + 5);
484 if (!strncmp(options, "scrollback:", 11)) {
487 fbcon_softback_size = simple_strtoul(options, &options, 0);
488 if (*options == 'k' || *options == 'K') {
489 fbcon_softback_size *= 1024;
499 if (!strncmp(options, "map:", 4)) {
502 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
506 (options[j++]-'0') % FB_MAX;
515 if (!strncmp(options, "vc:", 3)) {
518 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
521 if (*options++ == '-')
522 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
523 fbcon_is_default = 0;
526 if (!strncmp(options, "rotate:", 7)) {
529 rotate = simple_strtoul(options, &options, 0);
537 __setup("fbcon=", fb_console_setup);
540 static int search_fb_in_map(int idx)
544 for (i = first_fb_vc; i <= last_fb_vc; i++) {
545 if (con2fb_map[i] == idx)
551 static int search_for_mapped_con(void)
555 for (i = first_fb_vc; i <= last_fb_vc; i++) {
556 if (con2fb_map[i] != -1)
562 static int fbcon_takeover(int show_logo)
566 if (!num_registered_fb)
570 logo_shown = FBCON_LOGO_DONTSHOW;
572 for (i = first_fb_vc; i <= last_fb_vc; i++)
573 con2fb_map[i] = info_idx;
575 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
579 for (i = first_fb_vc; i <= last_fb_vc; i++) {
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;
603 if (info->flags & FBINFO_MODULE) {
604 logo_shown = FBCON_LOGO_DONTSHOW;
609 * remove underline attribute from erase character
610 * if black and white framebuffer.
612 if (fb_get_color_depth(&info->var, &info->fix) == 1)
614 logo_height = fb_prepare_logo(info, ops->rotate);
615 logo_lines = (logo_height + vc->vc_font.height - 1) /
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 newinfo->fbops->fb_set_par(newinfo);
798 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
799 int unit, int show_logo)
801 struct fbcon_ops *ops = info->fbcon_par;
803 ops->currcon = fg_console;
805 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
806 info->fbops->fb_set_par(info);
808 ops->flags |= FBCON_FLAGS_INIT;
810 fbcon_set_disp(info, &info->var, unit);
813 struct vc_data *fg_vc = vc_cons[fg_console].d;
814 struct fb_info *fg_info =
815 registered_fb[con2fb_map[fg_console]];
817 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
818 fg_vc->vc_rows, fg_vc->vc_cols,
822 update_screen(vc_cons[fg_console].d);
826 * set_con2fb_map - map console to frame buffer device
827 * @unit: virtual console number to map
828 * @newidx: frame buffer index to map virtual console to
829 * @user: user request
831 * Maps a virtual console @unit to a frame buffer device
834 static int set_con2fb_map(int unit, int newidx, int user)
836 struct vc_data *vc = vc_cons[unit].d;
837 int oldidx = con2fb_map[unit];
838 struct fb_info *info = registered_fb[newidx];
839 struct fb_info *oldinfo = NULL;
842 if (oldidx == newidx)
845 if (!info || fbcon_has_exited)
848 if (!err && !search_for_mapped_con()) {
850 return fbcon_takeover(0);
854 oldinfo = registered_fb[oldidx];
856 found = search_fb_in_map(newidx);
858 acquire_console_sem();
859 con2fb_map[unit] = newidx;
861 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
865 * If old fb is not mapped to any of the consoles,
866 * fbcon should release it.
868 if (!err && oldinfo && !search_fb_in_map(oldidx))
869 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
873 int show_logo = (fg_console == 0 && !user &&
874 logo_shown != FBCON_LOGO_DONTSHOW);
877 fbcon_add_cursor_timer(info);
878 con2fb_map_boot[unit] = newidx;
879 con2fb_init_display(vc, info, unit, show_logo);
882 if (!search_fb_in_map(info_idx))
885 release_console_sem();
890 * Low Level Operations
892 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
893 static int var_to_display(struct display *disp,
894 struct fb_var_screeninfo *var,
895 struct fb_info *info)
897 disp->xres_virtual = var->xres_virtual;
898 disp->yres_virtual = var->yres_virtual;
899 disp->bits_per_pixel = var->bits_per_pixel;
900 disp->grayscale = var->grayscale;
901 disp->nonstd = var->nonstd;
902 disp->accel_flags = var->accel_flags;
903 disp->height = var->height;
904 disp->width = var->width;
905 disp->red = var->red;
906 disp->green = var->green;
907 disp->blue = var->blue;
908 disp->transp = var->transp;
909 disp->rotate = var->rotate;
910 disp->mode = fb_match_mode(var, &info->modelist);
911 if (disp->mode == NULL)
912 /* This should not happen */
917 static void display_to_var(struct fb_var_screeninfo *var,
918 struct display *disp)
920 fb_videomode_to_var(var, disp->mode);
921 var->xres_virtual = disp->xres_virtual;
922 var->yres_virtual = disp->yres_virtual;
923 var->bits_per_pixel = disp->bits_per_pixel;
924 var->grayscale = disp->grayscale;
925 var->nonstd = disp->nonstd;
926 var->accel_flags = disp->accel_flags;
927 var->height = disp->height;
928 var->width = disp->width;
929 var->red = disp->red;
930 var->green = disp->green;
931 var->blue = disp->blue;
932 var->transp = disp->transp;
933 var->rotate = disp->rotate;
936 static const char *fbcon_startup(void)
938 const char *display_desc = "frame buffer device";
939 struct display *p = &fb_display[fg_console];
940 struct vc_data *vc = vc_cons[fg_console].d;
941 const struct font_desc *font = NULL;
942 struct module *owner;
943 struct fb_info *info = NULL;
944 struct fbcon_ops *ops;
950 * If num_registered_fb is zero, this is a call for the dummy part.
951 * The frame buffer devices weren't initialized yet.
953 if (!num_registered_fb || info_idx == -1)
956 * Instead of blindly using registered_fb[0], we use info_idx, set by
959 info = registered_fb[info_idx];
963 owner = info->fbops->owner;
964 if (!try_module_get(owner))
966 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
971 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
979 ops->cur_rotate = -1;
980 info->fbcon_par = ops;
981 p->con_rotate = rotate;
982 set_blitting_type(vc, info);
984 if (info->fix.type != FB_TYPE_TEXT) {
985 if (fbcon_softback_size) {
989 kmalloc(fbcon_softback_size,
992 fbcon_softback_size = 0;
998 kfree((void *) softback_buf);
1004 softback_in = softback_top = softback_curr =
1009 /* Setup default font */
1011 if (!fontname[0] || !(font = find_font(fontname)))
1012 font = get_default_font(info->var.xres,
1014 info->pixmap.blit_x,
1015 info->pixmap.blit_y);
1016 vc->vc_font.width = font->width;
1017 vc->vc_font.height = font->height;
1018 vc->vc_font.data = (void *)(p->fontdata = font->data);
1019 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1022 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1023 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1024 cols /= vc->vc_font.width;
1025 rows /= vc->vc_font.height;
1026 vc_resize(vc, cols, rows);
1028 DPRINTK("mode: %s\n", info->fix.id);
1029 DPRINTK("visual: %d\n", info->fix.visual);
1030 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1032 info->var.bits_per_pixel);
1035 if (MACH_IS_ATARI) {
1036 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1038 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1039 IRQ_TYPE_PRIO, "framebuffer vbl",
1042 #endif /* CONFIG_ATARI */
1046 * On a Macintoy, the VBL interrupt may or may not be active.
1047 * As interrupt based cursor is more reliable and race free, we
1048 * probe for VBL interrupts.
1053 * Probe for VBL: set temp. handler ...
1055 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1056 "framebuffer vbl", info);
1060 * ... and spin for 20 ms ...
1062 while (!vbl_detected && ++ct < 1000)
1067 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1069 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1073 * interrupt based cursor ok
1075 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1077 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1078 "framebuffer vbl", info);
1081 * VBL not detected: fall through, use timer based cursor
1086 #endif /* CONFIG_MAC */
1088 fbcon_add_cursor_timer(info);
1089 fbcon_has_exited = 0;
1090 return display_desc;
1093 static void fbcon_init(struct vc_data *vc, int init)
1095 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1096 struct fbcon_ops *ops;
1097 struct vc_data **default_mode = vc->vc_display_fg;
1098 struct vc_data *svc = *default_mode;
1099 struct display *t, *p = &fb_display[vc->vc_num];
1100 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1103 if (info_idx == -1 || info == NULL)
1108 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1109 (info->fix.type == FB_TYPE_TEXT))
1112 if (var_to_display(p, &info->var, info))
1115 if (!info->fbcon_par)
1116 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1118 /* If we are not the first console on this
1119 fb, copy the font from that console */
1120 t = &fb_display[fg_console];
1123 struct vc_data *fvc = vc_cons[fg_console].d;
1125 vc->vc_font.data = (void *)(p->fontdata =
1127 vc->vc_font.width = fvc->vc_font.width;
1128 vc->vc_font.height = fvc->vc_font.height;
1129 p->userfont = t->userfont;
1132 REFCOUNT(p->fontdata)++;
1134 const struct font_desc *font = NULL;
1136 if (!fontname[0] || !(font = find_font(fontname)))
1137 font = get_default_font(info->var.xres,
1139 info->pixmap.blit_x,
1140 info->pixmap.blit_y);
1141 vc->vc_font.width = font->width;
1142 vc->vc_font.height = font->height;
1143 vc->vc_font.data = (void *)(p->fontdata = font->data);
1144 vc->vc_font.charcount = 256; /* FIXME Need to
1145 support more fonts */
1150 charcnt = FNTCHARCNT(p->fontdata);
1152 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1153 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1154 if (charcnt == 256) {
1155 vc->vc_hi_font_mask = 0;
1157 vc->vc_hi_font_mask = 0x100;
1158 if (vc->vc_can_do_color)
1159 vc->vc_complement_mask <<= 1;
1162 if (!*svc->vc_uni_pagedir_loc)
1163 con_set_default_unimap(svc);
1164 if (!*vc->vc_uni_pagedir_loc)
1165 con_copy_unimap(vc, svc);
1167 ops = info->fbcon_par;
1168 p->con_rotate = rotate;
1169 set_blitting_type(vc, info);
1173 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1174 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1175 new_cols /= vc->vc_font.width;
1176 new_rows /= vc->vc_font.height;
1177 vc_resize(vc, new_cols, new_rows);
1180 * We must always set the mode. The mode of the previous console
1181 * driver could be in the same resolution but we are using different
1182 * hardware so we have to initialize the hardware.
1184 * We need to do it in fbcon_init() to prevent screen corruption.
1186 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1187 if (info->fbops->fb_set_par &&
1188 !(ops->flags & FBCON_FLAGS_INIT))
1189 info->fbops->fb_set_par(info);
1190 ops->flags |= FBCON_FLAGS_INIT;
1195 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1196 !(cap & FBINFO_HWACCEL_DISABLED))
1197 p->scrollmode = SCROLL_MOVE;
1198 else /* default to something safe */
1199 p->scrollmode = SCROLL_REDRAW;
1202 * ++guenther: console.c:vc_allocate() relies on initializing
1203 * vc_{cols,rows}, but we must not set those if we are only
1204 * resizing the console.
1207 vc->vc_cols = new_cols;
1208 vc->vc_rows = new_rows;
1212 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1214 if (vc == svc && softback_buf)
1215 fbcon_update_softback(vc);
1217 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1218 ops->rotate = FB_ROTATE_UR;
1219 set_blitting_type(vc, info);
1222 ops->p = &fb_display[fg_console];
1225 static void fbcon_free_font(struct display *p)
1227 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1228 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1233 static void fbcon_deinit(struct vc_data *vc)
1235 struct display *p = &fb_display[vc->vc_num];
1236 struct fb_info *info;
1237 struct fbcon_ops *ops;
1241 idx = con2fb_map[vc->vc_num];
1246 info = registered_fb[idx];
1251 ops = info->fbcon_par;
1256 if (CON_IS_VISIBLE(vc))
1257 fbcon_del_cursor_timer(info);
1259 ops->flags &= ~FBCON_FLAGS_INIT;
1262 if (!con_is_bound(&fb_con))
1268 /* ====================================================================== */
1270 /* fbcon_XXX routines - interface used by the world
1272 * This system is now divided into two levels because of complications
1273 * caused by hardware scrolling. Top level functions:
1275 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1277 * handles y values in range [0, scr_height-1] that correspond to real
1278 * screen positions. y_wrap shift means that first line of bitmap may be
1279 * anywhere on this display. These functions convert lineoffsets to
1280 * bitmap offsets and deal with the wrap-around case by splitting blits.
1282 * fbcon_bmove_physical_8() -- These functions fast implementations
1283 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1284 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1288 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1289 * Implies should only really hardware scroll in rows. Only reason for
1290 * restriction is simplicity & efficiency at the moment.
1293 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1296 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1297 struct fbcon_ops *ops = info->fbcon_par;
1299 struct display *p = &fb_display[vc->vc_num];
1302 if (fbcon_is_inactive(vc, info))
1305 if (!height || !width)
1308 /* Split blits that cross physical y_wrap boundary */
1310 y_break = p->vrows - p->yscroll;
1311 if (sy < y_break && sy + height - 1 >= y_break) {
1312 u_int b = y_break - sy;
1313 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1314 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1317 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1320 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1321 int count, int ypos, int xpos)
1323 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1324 struct display *p = &fb_display[vc->vc_num];
1325 struct fbcon_ops *ops = info->fbcon_par;
1327 if (!fbcon_is_inactive(vc, info))
1328 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1329 get_color(vc, info, scr_readw(s), 1),
1330 get_color(vc, info, scr_readw(s), 0));
1333 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1337 scr_writew(c, &chr);
1338 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1341 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1343 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1344 struct fbcon_ops *ops = info->fbcon_par;
1346 if (!fbcon_is_inactive(vc, info))
1347 ops->clear_margins(vc, info, bottom_only);
1350 static void fbcon_cursor(struct vc_data *vc, int mode)
1352 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1353 struct fbcon_ops *ops = info->fbcon_par;
1355 int c = scr_readw((u16 *) vc->vc_pos);
1357 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1360 if (vc->vc_cursor_type & 0x10)
1361 fbcon_del_cursor_timer(info);
1363 fbcon_add_cursor_timer(info);
1365 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1366 if (mode & CM_SOFTBACK) {
1367 mode &= ~CM_SOFTBACK;
1371 fbcon_set_origin(vc);
1375 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1376 get_color(vc, info, c, 0));
1377 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1380 static int scrollback_phys_max = 0;
1381 static int scrollback_max = 0;
1382 static int scrollback_current = 0;
1384 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1387 struct display *p, *t;
1388 struct vc_data **default_mode, *vc;
1389 struct vc_data *svc;
1390 struct fbcon_ops *ops = info->fbcon_par;
1391 int rows, cols, charcnt = 256;
1393 p = &fb_display[unit];
1395 if (var_to_display(p, var, info))
1398 vc = vc_cons[unit].d;
1403 default_mode = vc->vc_display_fg;
1404 svc = *default_mode;
1405 t = &fb_display[svc->vc_num];
1407 if (!vc->vc_font.data) {
1408 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1409 vc->vc_font.width = (*default_mode)->vc_font.width;
1410 vc->vc_font.height = (*default_mode)->vc_font.height;
1411 p->userfont = t->userfont;
1413 REFCOUNT(p->fontdata)++;
1416 charcnt = FNTCHARCNT(p->fontdata);
1418 var->activate = FB_ACTIVATE_NOW;
1419 info->var.activate = var->activate;
1420 var->yoffset = info->var.yoffset;
1421 var->xoffset = info->var.xoffset;
1422 fb_set_var(info, var);
1423 ops->var = info->var;
1424 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1425 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1426 if (charcnt == 256) {
1427 vc->vc_hi_font_mask = 0;
1429 vc->vc_hi_font_mask = 0x100;
1430 if (vc->vc_can_do_color)
1431 vc->vc_complement_mask <<= 1;
1434 if (!*svc->vc_uni_pagedir_loc)
1435 con_set_default_unimap(svc);
1436 if (!*vc->vc_uni_pagedir_loc)
1437 con_copy_unimap(vc, svc);
1439 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1440 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1441 cols /= vc->vc_font.width;
1442 rows /= vc->vc_font.height;
1443 vc_resize(vc, cols, rows);
1445 if (CON_IS_VISIBLE(vc)) {
1448 fbcon_update_softback(vc);
1452 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1454 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1455 struct fbcon_ops *ops = info->fbcon_par;
1456 struct display *p = &fb_display[vc->vc_num];
1458 p->yscroll += count;
1459 if (p->yscroll >= p->vrows) /* Deal with wrap */
1460 p->yscroll -= p->vrows;
1461 ops->var.xoffset = 0;
1462 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1463 ops->var.vmode |= FB_VMODE_YWRAP;
1464 ops->update_start(info);
1465 scrollback_max += count;
1466 if (scrollback_max > scrollback_phys_max)
1467 scrollback_max = scrollback_phys_max;
1468 scrollback_current = 0;
1471 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1473 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1474 struct fbcon_ops *ops = info->fbcon_par;
1475 struct display *p = &fb_display[vc->vc_num];
1477 p->yscroll -= count;
1478 if (p->yscroll < 0) /* Deal with wrap */
1479 p->yscroll += p->vrows;
1480 ops->var.xoffset = 0;
1481 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1482 ops->var.vmode |= FB_VMODE_YWRAP;
1483 ops->update_start(info);
1484 scrollback_max -= count;
1485 if (scrollback_max < 0)
1487 scrollback_current = 0;
1490 static __inline__ void ypan_up(struct vc_data *vc, int count)
1492 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1493 struct display *p = &fb_display[vc->vc_num];
1494 struct fbcon_ops *ops = info->fbcon_par;
1496 p->yscroll += count;
1497 if (p->yscroll > p->vrows - vc->vc_rows) {
1498 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1499 0, 0, 0, vc->vc_rows, vc->vc_cols);
1500 p->yscroll -= p->vrows - vc->vc_rows;
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_up_redraw(struct vc_data *vc, int t, int count)
1516 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1517 struct fbcon_ops *ops = info->fbcon_par;
1518 struct display *p = &fb_display[vc->vc_num];
1520 p->yscroll += count;
1522 if (p->yscroll > p->vrows - vc->vc_rows) {
1523 p->yscroll -= p->vrows - vc->vc_rows;
1524 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
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 > scrollback_phys_max)
1534 scrollback_max = scrollback_phys_max;
1535 scrollback_current = 0;
1538 static __inline__ void ypan_down(struct vc_data *vc, int count)
1540 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1541 struct display *p = &fb_display[vc->vc_num];
1542 struct fbcon_ops *ops = info->fbcon_par;
1544 p->yscroll -= count;
1545 if (p->yscroll < 0) {
1546 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1547 0, vc->vc_rows, vc->vc_cols);
1548 p->yscroll += p->vrows - vc->vc_rows;
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 __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1564 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1565 struct fbcon_ops *ops = info->fbcon_par;
1566 struct display *p = &fb_display[vc->vc_num];
1568 p->yscroll -= count;
1570 if (p->yscroll < 0) {
1571 p->yscroll += p->vrows - vc->vc_rows;
1572 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1575 ops->var.xoffset = 0;
1576 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1577 ops->var.vmode &= ~FB_VMODE_YWRAP;
1578 ops->update_start(info);
1579 fbcon_clear_margins(vc, 1);
1580 scrollback_max -= count;
1581 if (scrollback_max < 0)
1583 scrollback_current = 0;
1586 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1589 int count = vc->vc_rows;
1590 unsigned short *d, *s;
1594 d = (u16 *) softback_curr;
1595 if (d == (u16 *) softback_in)
1596 d = (u16 *) vc->vc_origin;
1597 n = softback_curr + delta * vc->vc_size_row;
1598 softback_lines -= delta;
1600 if (softback_curr < softback_top && n < softback_buf) {
1601 n += softback_end - softback_buf;
1602 if (n < softback_top) {
1604 (softback_top - n) / vc->vc_size_row;
1607 } else if (softback_curr >= softback_top
1608 && n < softback_top) {
1610 (softback_top - n) / vc->vc_size_row;
1614 if (softback_curr > softback_in && n >= softback_end) {
1615 n += softback_buf - softback_end;
1616 if (n > softback_in) {
1620 } else if (softback_curr <= softback_in && n > softback_in) {
1625 if (n == softback_curr)
1628 s = (u16 *) softback_curr;
1629 if (s == (u16 *) softback_in)
1630 s = (u16 *) vc->vc_origin;
1632 unsigned short *start;
1636 unsigned short attr = 1;
1639 le = advance_row(s, 1);
1642 if (attr != (c & 0xff00)) {
1645 fbcon_putcs(vc, start, s - start,
1651 if (c == scr_readw(d)) {
1653 fbcon_putcs(vc, start, s - start,
1666 fbcon_putcs(vc, start, s - start, line, x);
1668 if (d == (u16 *) softback_end)
1669 d = (u16 *) softback_buf;
1670 if (d == (u16 *) softback_in)
1671 d = (u16 *) vc->vc_origin;
1672 if (s == (u16 *) softback_end)
1673 s = (u16 *) softback_buf;
1674 if (s == (u16 *) softback_in)
1675 s = (u16 *) vc->vc_origin;
1679 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1680 int line, int count, int dy)
1682 unsigned short *s = (unsigned short *)
1683 (vc->vc_origin + vc->vc_size_row * line);
1686 unsigned short *start = s;
1687 unsigned short *le = advance_row(s, 1);
1690 unsigned short attr = 1;
1694 if (attr != (c & 0xff00)) {
1697 fbcon_putcs(vc, start, s - start,
1703 console_conditional_schedule();
1707 fbcon_putcs(vc, start, s - start, dy, x);
1708 console_conditional_schedule();
1713 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1714 struct display *p, int line, int count, int ycount)
1716 int offset = ycount * vc->vc_cols;
1717 unsigned short *d = (unsigned short *)
1718 (vc->vc_origin + vc->vc_size_row * line);
1719 unsigned short *s = d + offset;
1720 struct fbcon_ops *ops = info->fbcon_par;
1723 unsigned short *start = s;
1724 unsigned short *le = advance_row(s, 1);
1731 if (c == scr_readw(d)) {
1733 ops->bmove(vc, info, line + ycount, x,
1734 line, x, 1, s-start);
1744 console_conditional_schedule();
1749 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1751 console_conditional_schedule();
1756 /* NOTE: We subtract two lines from these pointers */
1757 s -= vc->vc_size_row;
1758 d -= vc->vc_size_row;
1763 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1764 int line, int count, int offset)
1766 unsigned short *d = (unsigned short *)
1767 (vc->vc_origin + vc->vc_size_row * line);
1768 unsigned short *s = d + offset;
1771 unsigned short *start = s;
1772 unsigned short *le = advance_row(s, 1);
1775 unsigned short attr = 1;
1779 if (attr != (c & 0xff00)) {
1782 fbcon_putcs(vc, start, s - start,
1788 if (c == scr_readw(d)) {
1790 fbcon_putcs(vc, start, s - start,
1800 console_conditional_schedule();
1805 fbcon_putcs(vc, start, s - start, line, x);
1806 console_conditional_schedule();
1811 /* NOTE: We subtract two lines from these pointers */
1812 s -= vc->vc_size_row;
1813 d -= vc->vc_size_row;
1818 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1823 if (vc->vc_num != fg_console)
1825 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1828 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1830 p = advance_row(p, 1);
1831 softback_in += vc->vc_size_row;
1832 if (softback_in == softback_end)
1833 softback_in = softback_buf;
1834 if (softback_in == softback_top) {
1835 softback_top += vc->vc_size_row;
1836 if (softback_top == softback_end)
1837 softback_top = softback_buf;
1840 softback_curr = softback_in;
1843 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1846 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1847 struct display *p = &fb_display[vc->vc_num];
1848 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1850 if (fbcon_is_inactive(vc, info))
1853 fbcon_cursor(vc, CM_ERASE);
1856 * ++Geert: Only use ywrap/ypan if the console is in text mode
1857 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1858 * whole screen (prevents flicker).
1863 if (count > vc->vc_rows) /* Maximum realistic size */
1864 count = vc->vc_rows;
1866 fbcon_softback_note(vc, t, count);
1867 if (logo_shown >= 0)
1869 switch (p->scrollmode) {
1871 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1873 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1874 scr_memsetw((unsigned short *) (vc->vc_origin +
1877 vc->vc_video_erase_char,
1878 vc->vc_size_row * count);
1882 case SCROLL_WRAP_MOVE:
1883 if (b - t - count > 3 * vc->vc_rows >> 2) {
1885 fbcon_bmove(vc, 0, 0, count, 0, t,
1887 ywrap_up(vc, count);
1888 if (vc->vc_rows - b > 0)
1889 fbcon_bmove(vc, b - count, 0, b, 0,
1892 } else if (info->flags & FBINFO_READS_FAST)
1893 fbcon_bmove(vc, t + count, 0, t, 0,
1894 b - t - count, vc->vc_cols);
1897 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1900 case SCROLL_PAN_REDRAW:
1901 if ((p->yscroll + count <=
1902 2 * (p->vrows - vc->vc_rows))
1903 && ((!scroll_partial && (b - t == vc->vc_rows))
1906 3 * vc->vc_rows >> 2)))) {
1908 fbcon_redraw_move(vc, p, 0, t, count);
1909 ypan_up_redraw(vc, t, count);
1910 if (vc->vc_rows - b > 0)
1911 fbcon_redraw_move(vc, p, b,
1912 vc->vc_rows - b, b);
1914 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1915 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1918 case SCROLL_PAN_MOVE:
1919 if ((p->yscroll + count <=
1920 2 * (p->vrows - vc->vc_rows))
1921 && ((!scroll_partial && (b - t == vc->vc_rows))
1924 3 * vc->vc_rows >> 2)))) {
1926 fbcon_bmove(vc, 0, 0, count, 0, t,
1929 if (vc->vc_rows - b > 0)
1930 fbcon_bmove(vc, b - count, 0, b, 0,
1933 } else if (info->flags & FBINFO_READS_FAST)
1934 fbcon_bmove(vc, t + count, 0, t, 0,
1935 b - t - count, vc->vc_cols);
1938 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1943 fbcon_redraw(vc, p, t, b - t - count,
1944 count * vc->vc_cols);
1945 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1946 scr_memsetw((unsigned short *) (vc->vc_origin +
1949 vc->vc_video_erase_char,
1950 vc->vc_size_row * count);
1956 if (count > vc->vc_rows) /* Maximum realistic size */
1957 count = vc->vc_rows;
1958 if (logo_shown >= 0)
1960 switch (p->scrollmode) {
1962 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1964 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1965 scr_memsetw((unsigned short *) (vc->vc_origin +
1968 vc->vc_video_erase_char,
1969 vc->vc_size_row * count);
1973 case SCROLL_WRAP_MOVE:
1974 if (b - t - count > 3 * vc->vc_rows >> 2) {
1975 if (vc->vc_rows - b > 0)
1976 fbcon_bmove(vc, b, 0, b - count, 0,
1979 ywrap_down(vc, count);
1981 fbcon_bmove(vc, count, 0, 0, 0, t,
1983 } else if (info->flags & FBINFO_READS_FAST)
1984 fbcon_bmove(vc, t, 0, t + count, 0,
1985 b - t - count, vc->vc_cols);
1988 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1991 case SCROLL_PAN_MOVE:
1992 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1993 && ((!scroll_partial && (b - t == vc->vc_rows))
1996 3 * vc->vc_rows >> 2)))) {
1997 if (vc->vc_rows - b > 0)
1998 fbcon_bmove(vc, b, 0, b - count, 0,
2001 ypan_down(vc, count);
2003 fbcon_bmove(vc, count, 0, 0, 0, t,
2005 } else if (info->flags & FBINFO_READS_FAST)
2006 fbcon_bmove(vc, t, 0, t + count, 0,
2007 b - t - count, vc->vc_cols);
2010 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2013 case SCROLL_PAN_REDRAW:
2014 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2015 && ((!scroll_partial && (b - t == vc->vc_rows))
2018 3 * vc->vc_rows >> 2)))) {
2019 if (vc->vc_rows - b > 0)
2020 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2022 ypan_down_redraw(vc, t, count);
2024 fbcon_redraw_move(vc, p, count, t, 0);
2026 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2027 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2032 fbcon_redraw(vc, p, b - 1, b - t - count,
2033 -count * vc->vc_cols);
2034 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2035 scr_memsetw((unsigned short *) (vc->vc_origin +
2038 vc->vc_video_erase_char,
2039 vc->vc_size_row * count);
2047 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2048 int height, int width)
2050 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2051 struct display *p = &fb_display[vc->vc_num];
2053 if (fbcon_is_inactive(vc, info))
2056 if (!width || !height)
2059 /* Split blits that cross physical y_wrap case.
2060 * Pathological case involves 4 blits, better to use recursive
2061 * code rather than unrolled case
2063 * Recursive invocations don't need to erase the cursor over and
2064 * over again, so we use fbcon_bmove_rec()
2066 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2067 p->vrows - p->yscroll);
2070 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2071 int dy, int dx, int height, int width, u_int y_break)
2073 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2074 struct fbcon_ops *ops = info->fbcon_par;
2077 if (sy < y_break && sy + height > y_break) {
2079 if (dy < sy) { /* Avoid trashing self */
2080 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2082 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2083 height - b, width, y_break);
2085 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2086 height - b, width, y_break);
2087 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2093 if (dy < y_break && dy + height > y_break) {
2095 if (dy < sy) { /* Avoid trashing self */
2096 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2098 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2099 height - b, width, y_break);
2101 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2102 height - b, width, y_break);
2103 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2108 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2112 static __inline__ void updatescrollmode(struct display *p,
2113 struct fb_info *info,
2116 struct fbcon_ops *ops = info->fbcon_par;
2117 int fh = vc->vc_font.height;
2118 int cap = info->flags;
2120 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2121 info->fix.xpanstep);
2122 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2123 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2124 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2125 info->var.xres_virtual);
2126 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2127 divides(ypan, vc->vc_font.height) && vyres > yres;
2128 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2129 divides(ywrap, vc->vc_font.height) &&
2130 divides(vc->vc_font.height, vyres) &&
2131 divides(vc->vc_font.height, yres);
2132 int reading_fast = cap & FBINFO_READS_FAST;
2133 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2134 !(cap & FBINFO_HWACCEL_DISABLED);
2135 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2136 !(cap & FBINFO_HWACCEL_DISABLED);
2138 p->vrows = vyres/fh;
2139 if (yres > (fh * (vc->vc_rows + 1)))
2140 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2141 if ((yres % fh) && (vyres % fh < yres % fh))
2144 if (good_wrap || good_pan) {
2145 if (reading_fast || fast_copyarea)
2146 p->scrollmode = good_wrap ?
2147 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2149 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2152 if (reading_fast || (fast_copyarea && !fast_imageblit))
2153 p->scrollmode = SCROLL_MOVE;
2155 p->scrollmode = SCROLL_REDRAW;
2159 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2160 unsigned int height)
2162 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2163 struct fbcon_ops *ops = info->fbcon_par;
2164 struct display *p = &fb_display[vc->vc_num];
2165 struct fb_var_screeninfo var = info->var;
2166 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2168 virt_w = FBCON_SWAP(ops->rotate, width, height);
2169 virt_h = FBCON_SWAP(ops->rotate, height, width);
2170 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2171 vc->vc_font.height);
2172 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2174 var.xres = virt_w * virt_fw;
2175 var.yres = virt_h * virt_fh;
2176 x_diff = info->var.xres - var.xres;
2177 y_diff = info->var.yres - var.yres;
2178 if (x_diff < 0 || x_diff > virt_fw ||
2179 y_diff < 0 || y_diff > virt_fh) {
2180 const struct fb_videomode *mode;
2182 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2183 mode = fb_find_best_mode(&var, &info->modelist);
2186 display_to_var(&var, p);
2187 fb_videomode_to_var(&var, mode);
2189 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2192 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2193 if (CON_IS_VISIBLE(vc)) {
2194 var.activate = FB_ACTIVATE_NOW |
2196 fb_set_var(info, &var);
2198 var_to_display(p, &info->var, info);
2199 ops->var = info->var;
2201 updatescrollmode(p, info, vc);
2205 static int fbcon_switch(struct vc_data *vc)
2207 struct fb_info *info, *old_info = NULL;
2208 struct fbcon_ops *ops;
2209 struct display *p = &fb_display[vc->vc_num];
2210 struct fb_var_screeninfo var;
2211 int i, prev_console, charcnt = 256;
2213 info = registered_fb[con2fb_map[vc->vc_num]];
2214 ops = info->fbcon_par;
2218 fbcon_set_origin(vc);
2219 softback_top = softback_curr = softback_in = softback_buf;
2221 fbcon_update_softback(vc);
2224 if (logo_shown >= 0) {
2225 struct vc_data *conp2 = vc_cons[logo_shown].d;
2227 if (conp2->vc_top == logo_lines
2228 && conp2->vc_bottom == conp2->vc_rows)
2230 logo_shown = FBCON_LOGO_CANSHOW;
2233 prev_console = ops->currcon;
2234 if (prev_console != -1)
2235 old_info = registered_fb[con2fb_map[prev_console]];
2237 * FIXME: If we have multiple fbdev's loaded, we need to
2238 * update all info->currcon. Perhaps, we can place this
2239 * in a centralized structure, but this might break some
2242 * info->currcon = vc->vc_num;
2244 for (i = 0; i < FB_MAX; i++) {
2245 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2246 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2248 o->currcon = vc->vc_num;
2251 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2252 display_to_var(&var, p);
2253 var.activate = FB_ACTIVATE_NOW;
2256 * make sure we don't unnecessarily trip the memcmp()
2259 info->var.activate = var.activate;
2260 var.yoffset = info->var.yoffset;
2261 var.xoffset = info->var.xoffset;
2262 var.vmode = info->var.vmode;
2263 fb_set_var(info, &var);
2264 ops->var = info->var;
2266 if (old_info != NULL && (old_info != info ||
2267 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2268 if (info->fbops->fb_set_par)
2269 info->fbops->fb_set_par(info);
2271 if (old_info != info)
2272 fbcon_del_cursor_timer(old_info);
2275 if (fbcon_is_inactive(vc, info) ||
2276 ops->blank_state != FB_BLANK_UNBLANK)
2277 fbcon_del_cursor_timer(info);
2279 fbcon_add_cursor_timer(info);
2281 set_blitting_type(vc, info);
2282 ops->cursor_reset = 1;
2284 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2285 ops->rotate = FB_ROTATE_UR;
2286 set_blitting_type(vc, info);
2289 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2290 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2293 charcnt = FNTCHARCNT(vc->vc_font.data);
2296 vc->vc_complement_mask <<= 1;
2298 updatescrollmode(p, info, vc);
2300 switch (p->scrollmode) {
2301 case SCROLL_WRAP_MOVE:
2302 scrollback_phys_max = p->vrows - vc->vc_rows;
2304 case SCROLL_PAN_MOVE:
2305 case SCROLL_PAN_REDRAW:
2306 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2307 if (scrollback_phys_max < 0)
2308 scrollback_phys_max = 0;
2311 scrollback_phys_max = 0;
2316 scrollback_current = 0;
2318 if (!fbcon_is_inactive(vc, info)) {
2319 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2320 ops->update_start(info);
2323 fbcon_set_palette(vc, color_table);
2324 fbcon_clear_margins(vc, 0);
2326 if (logo_shown == FBCON_LOGO_DRAW) {
2328 logo_shown = fg_console;
2329 /* This is protected above by initmem_freed */
2330 fb_show_logo(info, ops->rotate);
2332 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2333 vc->vc_size_row * (vc->vc_bottom -
2340 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2343 struct fb_event event;
2346 unsigned short charmask = vc->vc_hi_font_mask ?
2348 unsigned short oldc;
2350 oldc = vc->vc_video_erase_char;
2351 vc->vc_video_erase_char &= charmask;
2352 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2353 vc->vc_video_erase_char = oldc;
2358 event.data = ␣
2359 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2362 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2364 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2365 struct fbcon_ops *ops = info->fbcon_par;
2368 struct fb_var_screeninfo var = info->var;
2373 if (info->fbops->fb_save_state)
2374 info->fbops->fb_save_state(info);
2375 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2376 fb_set_var(info, &var);
2378 ops->var = info->var;
2379 } else if (info->fbops->fb_restore_state)
2380 info->fbops->fb_restore_state(info);
2383 if (!fbcon_is_inactive(vc, info)) {
2384 if (ops->blank_state != blank) {
2385 ops->blank_state = blank;
2386 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2387 ops->cursor_flash = (!blank);
2389 if (fb_blank(info, blank))
2390 fbcon_generic_blank(vc, info, blank);
2397 if (fbcon_is_inactive(vc, info) ||
2398 ops->blank_state != FB_BLANK_UNBLANK)
2399 fbcon_del_cursor_timer(info);
2401 fbcon_add_cursor_timer(info);
2406 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2408 u8 *fontdata = vc->vc_font.data;
2409 u8 *data = font->data;
2412 font->width = vc->vc_font.width;
2413 font->height = vc->vc_font.height;
2414 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2418 if (font->width <= 8) {
2419 j = vc->vc_font.height;
2420 for (i = 0; i < font->charcount; i++) {
2421 memcpy(data, fontdata, j);
2422 memset(data + j, 0, 32 - j);
2426 } else if (font->width <= 16) {
2427 j = vc->vc_font.height * 2;
2428 for (i = 0; i < font->charcount; i++) {
2429 memcpy(data, fontdata, j);
2430 memset(data + j, 0, 64 - j);
2434 } else if (font->width <= 24) {
2435 for (i = 0; i < font->charcount; i++) {
2436 for (j = 0; j < vc->vc_font.height; j++) {
2437 *data++ = fontdata[0];
2438 *data++ = fontdata[1];
2439 *data++ = fontdata[2];
2440 fontdata += sizeof(u32);
2442 memset(data, 0, 3 * (32 - j));
2443 data += 3 * (32 - j);
2446 j = vc->vc_font.height * 4;
2447 for (i = 0; i < font->charcount; i++) {
2448 memcpy(data, fontdata, j);
2449 memset(data + j, 0, 128 - j);
2457 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2458 const u8 * data, int userfont)
2460 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2461 struct fbcon_ops *ops = info->fbcon_par;
2462 struct display *p = &fb_display[vc->vc_num];
2465 char *old_data = NULL;
2467 if (CON_IS_VISIBLE(vc) && softback_lines)
2468 fbcon_set_origin(vc);
2470 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2472 old_data = vc->vc_font.data;
2474 cnt = FNTCHARCNT(data);
2477 vc->vc_font.data = (void *)(p->fontdata = data);
2478 if ((p->userfont = userfont))
2480 vc->vc_font.width = w;
2481 vc->vc_font.height = h;
2482 if (vc->vc_hi_font_mask && cnt == 256) {
2483 vc->vc_hi_font_mask = 0;
2484 if (vc->vc_can_do_color) {
2485 vc->vc_complement_mask >>= 1;
2486 vc->vc_s_complement_mask >>= 1;
2489 /* ++Edmund: reorder the attribute bits */
2490 if (vc->vc_can_do_color) {
2491 unsigned short *cp =
2492 (unsigned short *) vc->vc_origin;
2493 int count = vc->vc_screenbuf_size / 2;
2495 for (; count > 0; count--, cp++) {
2497 scr_writew(((c & 0xfe00) >> 1) |
2500 c = vc->vc_video_erase_char;
2501 vc->vc_video_erase_char =
2502 ((c & 0xfe00) >> 1) | (c & 0xff);
2505 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2506 vc->vc_hi_font_mask = 0x100;
2507 if (vc->vc_can_do_color) {
2508 vc->vc_complement_mask <<= 1;
2509 vc->vc_s_complement_mask <<= 1;
2512 /* ++Edmund: reorder the attribute bits */
2514 unsigned short *cp =
2515 (unsigned short *) vc->vc_origin;
2516 int count = vc->vc_screenbuf_size / 2;
2518 for (; count > 0; count--, cp++) {
2519 unsigned short newc;
2521 if (vc->vc_can_do_color)
2523 ((c & 0xff00) << 1) | (c &
2527 scr_writew(newc, cp);
2529 c = vc->vc_video_erase_char;
2530 if (vc->vc_can_do_color) {
2531 vc->vc_video_erase_char =
2532 ((c & 0xff00) << 1) | (c & 0xff);
2535 vc->vc_video_erase_char = c & ~0x100;
2543 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2544 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2547 vc_resize(vc, cols, rows);
2548 if (CON_IS_VISIBLE(vc) && softback_buf)
2549 fbcon_update_softback(vc);
2550 } else if (CON_IS_VISIBLE(vc)
2551 && vc->vc_mode == KD_TEXT) {
2552 fbcon_clear_margins(vc, 0);
2556 if (old_data && (--REFCOUNT(old_data) == 0))
2557 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2561 static int fbcon_copy_font(struct vc_data *vc, int con)
2563 struct display *od = &fb_display[con];
2564 struct console_font *f = &vc->vc_font;
2566 if (od->fontdata == f->data)
2567 return 0; /* already the same font... */
2568 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2572 * User asked to set font; we are guaranteed that
2573 * a) width and height are in range 1..32
2574 * b) charcount does not exceed 512
2575 * but lets not assume that, since someone might someday want to use larger
2576 * fonts. And charcount of 512 is small for unicode support.
2578 * However, user space gives the font in 32 rows , regardless of
2579 * actual font height. So a new API is needed if support for larger fonts
2580 * is ever implemented.
2583 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2585 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2586 unsigned charcount = font->charcount;
2587 int w = font->width;
2588 int h = font->height;
2591 u8 *new_data, *data = font->data;
2592 int pitch = (font->width+7) >> 3;
2594 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2595 * If not this check should be changed to charcount < 256 */
2596 if (charcount != 256 && charcount != 512)
2599 /* Make sure drawing engine can handle the font */
2600 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2601 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2604 /* Make sure driver can handle the font length */
2605 if (fbcon_invalid_charcount(info, charcount))
2608 size = h * pitch * charcount;
2610 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2615 new_data += FONT_EXTRA_WORDS * sizeof(int);
2616 FNTSIZE(new_data) = size;
2617 FNTCHARCNT(new_data) = charcount;
2618 REFCOUNT(new_data) = 0; /* usage counter */
2619 for (i=0; i< charcount; i++) {
2620 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2623 /* Since linux has a nice crc32 function use it for counting font
2625 csum = crc32(0, new_data, size);
2627 FNTSUM(new_data) = csum;
2628 /* Check if the same font is on some other console already */
2629 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2630 struct vc_data *tmp = vc_cons[i].d;
2632 if (fb_display[i].userfont &&
2633 fb_display[i].fontdata &&
2634 FNTSUM(fb_display[i].fontdata) == csum &&
2635 FNTSIZE(fb_display[i].fontdata) == size &&
2636 tmp->vc_font.width == w &&
2637 !memcmp(fb_display[i].fontdata, new_data, size)) {
2638 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2639 new_data = (u8 *)fb_display[i].fontdata;
2643 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2646 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2648 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2649 const struct font_desc *f;
2652 f = get_default_font(info->var.xres, info->var.yres,
2653 info->pixmap.blit_x, info->pixmap.blit_y);
2654 else if (!(f = find_font(name)))
2657 font->width = f->width;
2658 font->height = f->height;
2659 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2662 static u16 palette_red[16];
2663 static u16 palette_green[16];
2664 static u16 palette_blue[16];
2666 static struct fb_cmap palette_cmap = {
2667 0, 16, palette_red, palette_green, palette_blue, NULL
2670 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2672 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2676 if (fbcon_is_inactive(vc, info))
2679 if (!CON_IS_VISIBLE(vc))
2682 depth = fb_get_color_depth(&info->var, &info->fix);
2684 for (i = j = 0; i < 16; i++) {
2686 val = vc->vc_palette[j++];
2687 palette_red[k] = (val << 8) | val;
2688 val = vc->vc_palette[j++];
2689 palette_green[k] = (val << 8) | val;
2690 val = vc->vc_palette[j++];
2691 palette_blue[k] = (val << 8) | val;
2693 palette_cmap.len = 16;
2694 palette_cmap.start = 0;
2696 * If framebuffer is capable of less than 16 colors,
2697 * use default palette of fbcon.
2700 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2702 return fb_set_cmap(&palette_cmap, info);
2705 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2710 if (vc->vc_num != fg_console || !softback_lines)
2711 return (u16 *) (vc->vc_origin + offset);
2712 line = offset / vc->vc_size_row;
2713 if (line >= softback_lines)
2714 return (u16 *) (vc->vc_origin + offset -
2715 softback_lines * vc->vc_size_row);
2716 p = softback_curr + offset;
2717 if (p >= softback_end)
2718 p += softback_buf - softback_end;
2722 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2728 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2729 unsigned long offset = (pos - vc->vc_origin) / 2;
2731 x = offset % vc->vc_cols;
2732 y = offset / vc->vc_cols;
2733 if (vc->vc_num == fg_console)
2734 y += softback_lines;
2735 ret = pos + (vc->vc_cols - x) * 2;
2736 } else if (vc->vc_num == fg_console && softback_lines) {
2737 unsigned long offset = pos - softback_curr;
2739 if (pos < softback_curr)
2740 offset += softback_end - softback_buf;
2742 x = offset % vc->vc_cols;
2743 y = offset / vc->vc_cols;
2744 ret = pos + (vc->vc_cols - x) * 2;
2745 if (ret == softback_end)
2747 if (ret == softback_in)
2748 ret = vc->vc_origin;
2750 /* Should not happen */
2752 ret = vc->vc_origin;
2761 /* As we might be inside of softback, we may work with non-contiguous buffer,
2762 that's why we have to use a separate routine. */
2763 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2766 u16 a = scr_readw(p);
2767 if (!vc->vc_can_do_color)
2769 else if (vc->vc_hi_font_mask == 0x100)
2770 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2771 (((a) & 0x0e00) << 4);
2773 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2774 (((a) & 0x0700) << 4);
2776 if (p == (u16 *) softback_end)
2777 p = (u16 *) softback_buf;
2778 if (p == (u16 *) softback_in)
2779 p = (u16 *) vc->vc_origin;
2783 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2785 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2786 struct fbcon_ops *ops = info->fbcon_par;
2787 struct display *p = &fb_display[fg_console];
2788 int offset, limit, scrollback_old;
2791 if (vc->vc_num != fg_console)
2793 if (vc->vc_mode != KD_TEXT || !lines)
2795 if (logo_shown >= 0) {
2796 struct vc_data *conp2 = vc_cons[logo_shown].d;
2798 if (conp2->vc_top == logo_lines
2799 && conp2->vc_bottom == conp2->vc_rows)
2801 if (logo_shown == vc->vc_num) {
2807 logo_lines * vc->vc_size_row;
2808 for (i = 0; i < logo_lines; i++) {
2809 if (p == softback_top)
2811 if (p == softback_buf)
2813 p -= vc->vc_size_row;
2814 q -= vc->vc_size_row;
2815 scr_memcpyw((u16 *) q, (u16 *) p,
2818 softback_in = softback_curr = p;
2819 update_region(vc, vc->vc_origin,
2820 logo_lines * vc->vc_cols);
2822 logo_shown = FBCON_LOGO_CANSHOW;
2824 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2825 fbcon_redraw_softback(vc, p, lines);
2826 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2830 if (!scrollback_phys_max)
2833 scrollback_old = scrollback_current;
2834 scrollback_current -= lines;
2835 if (scrollback_current < 0)
2836 scrollback_current = 0;
2837 else if (scrollback_current > scrollback_max)
2838 scrollback_current = scrollback_max;
2839 if (scrollback_current == scrollback_old)
2842 if (fbcon_is_inactive(vc, info))
2845 fbcon_cursor(vc, CM_ERASE);
2847 offset = p->yscroll - scrollback_current;
2849 switch (p->scrollmode) {
2850 case SCROLL_WRAP_MOVE:
2851 info->var.vmode |= FB_VMODE_YWRAP;
2853 case SCROLL_PAN_MOVE:
2854 case SCROLL_PAN_REDRAW:
2855 limit -= vc->vc_rows;
2856 info->var.vmode &= ~FB_VMODE_YWRAP;
2861 else if (offset >= limit)
2864 ops->var.xoffset = 0;
2865 ops->var.yoffset = offset * vc->vc_font.height;
2866 ops->update_start(info);
2868 if (!scrollback_current)
2869 fbcon_cursor(vc, CM_DRAW);
2873 static int fbcon_set_origin(struct vc_data *vc)
2876 fbcon_scrolldelta(vc, softback_lines);
2880 static void fbcon_suspended(struct fb_info *info)
2882 struct vc_data *vc = NULL;
2883 struct fbcon_ops *ops = info->fbcon_par;
2885 if (!ops || ops->currcon < 0)
2887 vc = vc_cons[ops->currcon].d;
2889 /* Clear cursor, restore saved data */
2890 fbcon_cursor(vc, CM_ERASE);
2893 static void fbcon_resumed(struct fb_info *info)
2896 struct fbcon_ops *ops = info->fbcon_par;
2898 if (!ops || ops->currcon < 0)
2900 vc = vc_cons[ops->currcon].d;
2905 static void fbcon_modechanged(struct fb_info *info)
2907 struct fbcon_ops *ops = info->fbcon_par;
2912 if (!ops || ops->currcon < 0)
2914 vc = vc_cons[ops->currcon].d;
2915 if (vc->vc_mode != KD_TEXT ||
2916 registered_fb[con2fb_map[ops->currcon]] != info)
2919 p = &fb_display[vc->vc_num];
2920 set_blitting_type(vc, info);
2922 if (CON_IS_VISIBLE(vc)) {
2923 var_to_display(p, &info->var, info);
2924 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2925 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2926 cols /= vc->vc_font.width;
2927 rows /= vc->vc_font.height;
2928 vc_resize(vc, cols, rows);
2929 updatescrollmode(p, info, vc);
2931 scrollback_current = 0;
2933 if (!fbcon_is_inactive(vc, info)) {
2934 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2935 ops->update_start(info);
2938 fbcon_set_palette(vc, color_table);
2941 fbcon_update_softback(vc);
2945 static void fbcon_set_all_vcs(struct fb_info *info)
2947 struct fbcon_ops *ops = info->fbcon_par;
2950 int i, rows, cols, fg = -1;
2952 if (!ops || ops->currcon < 0)
2955 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2957 if (!vc || vc->vc_mode != KD_TEXT ||
2958 registered_fb[con2fb_map[i]] != info)
2961 if (CON_IS_VISIBLE(vc)) {
2966 p = &fb_display[vc->vc_num];
2967 set_blitting_type(vc, info);
2968 var_to_display(p, &info->var, info);
2969 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2970 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
2971 cols /= vc->vc_font.width;
2972 rows /= vc->vc_font.height;
2973 vc_resize(vc, cols, rows);
2977 fbcon_modechanged(info);
2980 static int fbcon_mode_deleted(struct fb_info *info,
2981 struct fb_videomode *mode)
2983 struct fb_info *fb_info;
2985 int i, j, found = 0;
2987 /* before deletion, ensure that mode is not in use */
2988 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2992 fb_info = registered_fb[j];
2993 if (fb_info != info)
2998 if (fb_mode_is_equal(p->mode, mode)) {
3006 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3007 static int fbcon_unbind(void)
3011 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3016 static inline int fbcon_unbind(void)
3020 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3022 static int fbcon_fb_unbind(int idx)
3024 int i, new_idx = -1, ret = 0;
3026 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3027 if (con2fb_map[i] != idx &&
3028 con2fb_map[i] != -1) {
3034 if (new_idx != -1) {
3035 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3036 if (con2fb_map[i] == idx)
3037 set_con2fb_map(i, new_idx, 0);
3040 ret = fbcon_unbind();
3045 static int fbcon_fb_unregistered(struct fb_info *info)
3047 int i, idx = info->node;
3049 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3050 if (con2fb_map[i] == idx)
3054 if (idx == info_idx) {
3057 for (i = 0; i < FB_MAX; i++) {
3058 if (registered_fb[i] != NULL) {
3065 if (info_idx != -1) {
3066 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3067 if (con2fb_map[i] == -1)
3068 con2fb_map[i] = info_idx;
3072 if (!num_registered_fb)
3073 unregister_con_driver(&fb_con);
3076 if (primary_device == idx)
3077 primary_device = -1;
3082 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3083 static void fbcon_select_primary(struct fb_info *info)
3085 if (!map_override && primary_device == -1 &&
3086 fb_is_primary_device(info)) {
3089 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3090 info->fix.id, info->node);
3091 primary_device = info->node;
3093 for (i = first_fb_vc; i <= last_fb_vc; i++)
3094 con2fb_map_boot[i] = primary_device;
3096 if (con_is_bound(&fb_con)) {
3097 printk(KERN_INFO "fbcon: Remapping primary device, "
3098 "fb%i, to tty %i-%i\n", info->node,
3099 first_fb_vc + 1, last_fb_vc + 1);
3100 info_idx = primary_device;
3106 static inline void fbcon_select_primary(struct fb_info *info)
3110 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3112 static int fbcon_fb_registered(struct fb_info *info)
3114 int ret = 0, i, idx = info->node;
3116 fbcon_select_primary(info);
3118 if (info_idx == -1) {
3119 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3120 if (con2fb_map_boot[i] == idx) {
3127 ret = fbcon_takeover(1);
3129 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3130 if (con2fb_map_boot[i] == idx)
3131 set_con2fb_map(i, idx, 0);
3138 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3140 struct fbcon_ops *ops = info->fbcon_par;
3143 if (!ops || ops->currcon < 0)
3146 vc = vc_cons[ops->currcon].d;
3147 if (vc->vc_mode != KD_TEXT ||
3148 registered_fb[con2fb_map[ops->currcon]] != info)
3151 if (CON_IS_VISIBLE(vc)) {
3155 do_unblank_screen(0);
3157 ops->blank_state = blank;
3160 static void fbcon_new_modelist(struct fb_info *info)
3164 struct fb_var_screeninfo var;
3165 const struct fb_videomode *mode;
3167 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3168 if (registered_fb[con2fb_map[i]] != info)
3170 if (!fb_display[i].mode)
3173 display_to_var(&var, &fb_display[i]);
3174 mode = fb_find_nearest_mode(fb_display[i].mode,
3176 fb_videomode_to_var(&var, mode);
3177 fbcon_set_disp(info, &var, vc->vc_num);
3181 static void fbcon_get_requirement(struct fb_info *info,
3182 struct fb_blit_caps *caps)
3190 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3192 if (vc && vc->vc_mode == KD_TEXT &&
3193 info->node == con2fb_map[i]) {
3195 caps->x |= 1 << (vc->vc_font.width - 1);
3196 caps->y |= 1 << (vc->vc_font.height - 1);
3197 charcnt = (p->userfont) ?
3198 FNTCHARCNT(p->fontdata) : 256;
3199 if (caps->len < charcnt)
3200 caps->len = charcnt;
3204 vc = vc_cons[fg_console].d;
3206 if (vc && vc->vc_mode == KD_TEXT &&
3207 info->node == con2fb_map[fg_console]) {
3208 p = &fb_display[fg_console];
3209 caps->x = 1 << (vc->vc_font.width - 1);
3210 caps->y = 1 << (vc->vc_font.height - 1);
3211 caps->len = (p->userfont) ?
3212 FNTCHARCNT(p->fontdata) : 256;
3217 static int fbcon_event_notify(struct notifier_block *self,
3218 unsigned long action, void *data)
3220 struct fb_event *event = data;
3221 struct fb_info *info = event->info;
3222 struct fb_videomode *mode;
3223 struct fb_con2fbmap *con2fb;
3224 struct fb_blit_caps *caps;
3228 * ignore all events except driver registration and deregistration
3229 * if fbcon is not active
3231 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3232 action == FB_EVENT_FB_UNREGISTERED))
3236 case FB_EVENT_SUSPEND:
3237 fbcon_suspended(info);
3239 case FB_EVENT_RESUME:
3240 fbcon_resumed(info);
3242 case FB_EVENT_MODE_CHANGE:
3243 fbcon_modechanged(info);
3245 case FB_EVENT_MODE_CHANGE_ALL:
3246 fbcon_set_all_vcs(info);
3248 case FB_EVENT_MODE_DELETE:
3250 ret = fbcon_mode_deleted(info, mode);
3252 case FB_EVENT_FB_UNBIND:
3253 ret = fbcon_fb_unbind(info->node);
3255 case FB_EVENT_FB_REGISTERED:
3256 ret = fbcon_fb_registered(info);
3258 case FB_EVENT_FB_UNREGISTERED:
3259 ret = fbcon_fb_unregistered(info);
3261 case FB_EVENT_SET_CONSOLE_MAP:
3262 con2fb = event->data;
3263 ret = set_con2fb_map(con2fb->console - 1,
3264 con2fb->framebuffer, 1);
3266 case FB_EVENT_GET_CONSOLE_MAP:
3267 con2fb = event->data;
3268 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3270 case FB_EVENT_BLANK:
3271 fbcon_fb_blanked(info, *(int *)event->data);
3273 case FB_EVENT_NEW_MODELIST:
3274 fbcon_new_modelist(info);
3276 case FB_EVENT_GET_REQ:
3278 fbcon_get_requirement(info, caps);
3287 * The console `switch' structure for the frame buffer based console
3290 static const struct consw fb_con = {
3291 .owner = THIS_MODULE,
3292 .con_startup = fbcon_startup,
3293 .con_init = fbcon_init,
3294 .con_deinit = fbcon_deinit,
3295 .con_clear = fbcon_clear,
3296 .con_putc = fbcon_putc,
3297 .con_putcs = fbcon_putcs,
3298 .con_cursor = fbcon_cursor,
3299 .con_scroll = fbcon_scroll,
3300 .con_bmove = fbcon_bmove,
3301 .con_switch = fbcon_switch,
3302 .con_blank = fbcon_blank,
3303 .con_font_set = fbcon_set_font,
3304 .con_font_get = fbcon_get_font,
3305 .con_font_default = fbcon_set_def_font,
3306 .con_font_copy = fbcon_copy_font,
3307 .con_set_palette = fbcon_set_palette,
3308 .con_scrolldelta = fbcon_scrolldelta,
3309 .con_set_origin = fbcon_set_origin,
3310 .con_invert_region = fbcon_invert_region,
3311 .con_screen_pos = fbcon_screen_pos,
3312 .con_getxy = fbcon_getxy,
3313 .con_resize = fbcon_resize,
3316 static struct notifier_block fbcon_event_notifier = {
3317 .notifier_call = fbcon_event_notify,
3320 static ssize_t store_rotate(struct device *device,
3321 struct device_attribute *attr, const char *buf,
3324 struct fb_info *info;
3328 if (fbcon_has_exited)
3331 acquire_console_sem();
3332 idx = con2fb_map[fg_console];
3334 if (idx == -1 || registered_fb[idx] == NULL)
3337 info = registered_fb[idx];
3338 rotate = simple_strtoul(buf, last, 0);
3339 fbcon_rotate(info, rotate);
3341 release_console_sem();
3345 static ssize_t store_rotate_all(struct device *device,
3346 struct device_attribute *attr,const char *buf,
3349 struct fb_info *info;
3353 if (fbcon_has_exited)
3356 acquire_console_sem();
3357 idx = con2fb_map[fg_console];
3359 if (idx == -1 || registered_fb[idx] == NULL)
3362 info = registered_fb[idx];
3363 rotate = simple_strtoul(buf, last, 0);
3364 fbcon_rotate_all(info, rotate);
3366 release_console_sem();
3370 static ssize_t show_rotate(struct device *device,
3371 struct device_attribute *attr,char *buf)
3373 struct fb_info *info;
3374 int rotate = 0, idx;
3376 if (fbcon_has_exited)
3379 acquire_console_sem();
3380 idx = con2fb_map[fg_console];
3382 if (idx == -1 || registered_fb[idx] == NULL)
3385 info = registered_fb[idx];
3386 rotate = fbcon_get_rotate(info);
3388 release_console_sem();
3389 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3392 static ssize_t show_cursor_blink(struct device *device,
3393 struct device_attribute *attr, char *buf)
3395 struct fb_info *info;
3396 struct fbcon_ops *ops;
3397 int idx, blink = -1;
3399 if (fbcon_has_exited)
3402 acquire_console_sem();
3403 idx = con2fb_map[fg_console];
3405 if (idx == -1 || registered_fb[idx] == NULL)
3408 info = registered_fb[idx];
3409 ops = info->fbcon_par;
3414 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3416 release_console_sem();
3417 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3420 static ssize_t store_cursor_blink(struct device *device,
3421 struct device_attribute *attr,
3422 const char *buf, size_t count)
3424 struct fb_info *info;
3428 if (fbcon_has_exited)
3431 acquire_console_sem();
3432 idx = con2fb_map[fg_console];
3434 if (idx == -1 || registered_fb[idx] == NULL)
3437 info = registered_fb[idx];
3439 if (!info->fbcon_par)
3442 blink = simple_strtoul(buf, last, 0);
3445 fbcon_cursor_noblink = 0;
3446 fbcon_add_cursor_timer(info);
3448 fbcon_cursor_noblink = 1;
3449 fbcon_del_cursor_timer(info);
3453 release_console_sem();
3457 static struct device_attribute device_attrs[] = {
3458 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3459 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3460 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3461 store_cursor_blink),
3464 static int fbcon_init_device(void)
3468 fbcon_has_sysfs = 1;
3470 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3471 error = device_create_file(fbcon_device, &device_attrs[i]);
3479 device_remove_file(fbcon_device, &device_attrs[i]);
3481 fbcon_has_sysfs = 0;
3487 static void fbcon_start(void)
3489 if (num_registered_fb) {
3492 acquire_console_sem();
3494 for (i = 0; i < FB_MAX; i++) {
3495 if (registered_fb[i] != NULL) {
3501 release_console_sem();
3506 static void fbcon_exit(void)
3508 struct fb_info *info;
3511 if (fbcon_has_exited)
3515 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3518 if (MACH_IS_MAC && vbl_detected)
3519 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
3522 kfree((void *)softback_buf);
3525 for (i = 0; i < FB_MAX; i++) {
3527 info = registered_fb[i];
3532 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3533 if (con2fb_map[j] == i)
3538 if (info->fbops->fb_release)
3539 info->fbops->fb_release(info, 0);
3540 module_put(info->fbops->owner);
3542 if (info->fbcon_par) {
3543 struct fbcon_ops *ops = info->fbcon_par;
3545 fbcon_del_cursor_timer(info);
3546 kfree(ops->cursor_src);
3547 kfree(info->fbcon_par);
3548 info->fbcon_par = NULL;
3551 if (info->queue.func == fb_flashcursor)
3552 info->queue.func = NULL;
3556 fbcon_has_exited = 1;
3559 static int __init fb_console_init(void)
3563 acquire_console_sem();
3564 fb_register_client(&fbcon_event_notifier);
3565 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), "fbcon");
3567 if (IS_ERR(fbcon_device)) {
3568 printk(KERN_WARNING "Unable to create device "
3569 "for fbcon; errno = %ld\n",
3570 PTR_ERR(fbcon_device));
3571 fbcon_device = NULL;
3573 fbcon_init_device();
3575 for (i = 0; i < MAX_NR_CONSOLES; i++)
3578 release_console_sem();
3583 module_init(fb_console_init);
3587 static void __exit fbcon_deinit_device(void)
3591 if (fbcon_has_sysfs) {
3592 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3593 device_remove_file(fbcon_device, &device_attrs[i]);
3595 fbcon_has_sysfs = 0;
3599 static void __exit fb_console_exit(void)
3601 acquire_console_sem();
3602 fb_unregister_client(&fbcon_event_notifier);
3603 fbcon_deinit_device();
3604 device_destroy(fb_class, MKDEV(0, 0));
3606 release_console_sem();
3607 unregister_con_driver(&fb_con);
3610 module_exit(fb_console_exit);
3614 MODULE_LICENSE("GPL");