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/config.h>
62 #include <linux/module.h>
63 #include <linux/types.h>
64 #include <linux/sched.h>
66 #include <linux/kernel.h>
67 #include <linux/delay.h> /* MSch: for IRQ probe */
68 #include <linux/tty.h>
69 #include <linux/console.h>
70 #include <linux/string.h>
72 #include <linux/slab.h>
74 #include <linux/vt_kern.h>
75 #include <linux/selection.h>
76 #include <linux/font.h>
77 #include <linux/smp.h>
78 #include <linux/init.h>
79 #include <linux/interrupt.h>
80 #include <linux/crc32.h> /* For counting font checksums */
82 #include <asm/system.h>
83 #include <asm/uaccess.h>
85 #include <asm/atariints.h>
88 #include <asm/macints.h>
90 #if defined(__mc68000__) || defined(CONFIG_APUS)
91 #include <asm/machdep.h>
92 #include <asm/setup.h>
98 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
100 # define DPRINTK(fmt, args...)
104 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
105 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
106 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
109 struct display fb_display[MAX_NR_CONSOLES];
110 static signed char con2fb_map[MAX_NR_CONSOLES];
111 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
112 static int logo_height;
113 static int logo_lines;
114 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
116 static int logo_shown = FBCON_LOGO_CANSHOW;
117 /* Software scrollback */
118 static int fbcon_softback_size = 32768;
119 static unsigned long softback_buf, softback_curr;
120 static unsigned long softback_in;
121 static unsigned long softback_top, softback_end;
122 static int softback_lines;
123 /* console mappings */
124 static int first_fb_vc;
125 static int last_fb_vc = MAX_NR_CONSOLES - 1;
126 static int fbcon_is_default = 1;
128 static char fontname[40];
130 /* current fb_info */
131 static int info_idx = -1;
133 static const struct consw fb_con;
135 #define CM_SOFTBACK (8)
137 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
139 static void fbcon_free_font(struct display *);
140 static int fbcon_set_origin(struct vc_data *);
142 #define CURSOR_DRAW_DELAY (1)
144 /* # VBL ints between cursor state changes */
145 #define ATARI_CURSOR_BLINK_RATE (42)
146 #define MAC_CURSOR_BLINK_RATE (32)
147 #define DEFAULT_CURSOR_BLINK_RATE (20)
149 static int vbl_cursor_cnt;
151 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
154 * Interface used by the world
157 static const char *fbcon_startup(void);
158 static void fbcon_init(struct vc_data *vc, int init);
159 static void fbcon_deinit(struct vc_data *vc);
160 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
162 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
163 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
164 int count, int ypos, int xpos);
165 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
166 static void fbcon_cursor(struct vc_data *vc, int mode);
167 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
169 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
170 int height, int width);
171 static int fbcon_switch(struct vc_data *vc);
172 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
173 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
174 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
179 static __inline__ int real_y(struct display *p, int ypos);
180 static __inline__ void ywrap_up(struct vc_data *vc, int count);
181 static __inline__ void ywrap_down(struct vc_data *vc, int count);
182 static __inline__ void ypan_up(struct vc_data *vc, int count);
183 static __inline__ void ypan_down(struct vc_data *vc, int count);
184 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
185 int dy, int dx, int height, int width, u_int y_break);
186 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
188 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
190 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
191 int line, int count, int dy);
195 * On the Macintoy, there may or may not be a working VBL int. We need to probe
197 static int vbl_detected;
199 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
206 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
208 struct fbcon_ops *ops = info->fbcon_par;
210 return (info->state != FBINFO_STATE_RUNNING ||
211 vc->vc_mode != KD_TEXT || ops->graphics);
214 static inline int get_color(struct vc_data *vc, struct fb_info *info,
217 int depth = fb_get_color_depth(&info->var, &info->fix);
220 if (console_blanked) {
221 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
223 c = vc->vc_video_erase_char & charmask;
227 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
228 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
233 int col = ~(0xfff << (max(info->var.green.length,
234 max(info->var.red.length,
235 info->var.blue.length)))) & 0xff;
238 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
239 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
244 color = (is_fg) ? fg : bg;
249 * Scale down 16-colors to 4 colors. Default 4-color palette
250 * is grayscale. However, simply dividing the values by 4
251 * will not work, as colors 1, 2 and 3 will be scaled-down
252 * to zero rendering them invisible. So empirically convert
253 * colors to a sane 4-level grayscale.
257 color = 0; /* black */
260 color = 2; /* white */
263 color = 1; /* gray */
266 color = 3; /* intense white */
272 * Last 8 entries of default 16-color palette is a more intense
273 * version of the first 8 (i.e., same chrominance, different
284 static void fbcon_update_softback(struct vc_data *vc)
286 int l = fbcon_softback_size / vc->vc_size_row;
289 softback_end = softback_buf + l * vc->vc_size_row;
291 /* Smaller scrollback makes no sense, and 0 would screw
292 the operation totally */
296 static void fb_flashcursor(void *private)
298 struct fb_info *info = private;
299 struct fbcon_ops *ops = info->fbcon_par;
301 struct vc_data *vc = NULL;
305 if (ops->currcon != -1)
306 vc = vc_cons[ops->currcon].d;
308 if (!vc || !CON_IS_VISIBLE(vc) ||
309 fbcon_is_inactive(vc, info) ||
310 registered_fb[con2fb_map[vc->vc_num]] != info ||
311 vc_cons[ops->currcon].d->vc_deccm != 1)
313 acquire_console_sem();
314 p = &fb_display[vc->vc_num];
315 c = scr_readw((u16 *) vc->vc_pos);
316 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
318 ops->cursor(vc, info, p, mode, softback_lines, get_color(vc, info, c, 1),
319 get_color(vc, info, c, 0));
320 release_console_sem();
323 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
324 static int cursor_blink_rate;
325 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
327 struct fb_info *info = dev_id;
329 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
330 schedule_work(&info->queue);
331 vbl_cursor_cnt = cursor_blink_rate;
337 static void cursor_timer_handler(unsigned long dev_addr)
339 struct fb_info *info = (struct fb_info *) dev_addr;
340 struct fbcon_ops *ops = info->fbcon_par;
342 schedule_work(&info->queue);
343 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
346 static void fbcon_add_cursor_timer(struct fb_info *info)
348 struct fbcon_ops *ops = info->fbcon_par;
350 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
351 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
352 if (!info->queue.func)
353 INIT_WORK(&info->queue, fb_flashcursor, info);
355 init_timer(&ops->cursor_timer);
356 ops->cursor_timer.function = cursor_timer_handler;
357 ops->cursor_timer.expires = jiffies + HZ / 5;
358 ops->cursor_timer.data = (unsigned long ) info;
359 add_timer(&ops->cursor_timer);
360 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
364 static void fbcon_del_cursor_timer(struct fb_info *info)
366 struct fbcon_ops *ops = info->fbcon_par;
368 if (info->queue.func == fb_flashcursor &&
369 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
370 del_timer_sync(&ops->cursor_timer);
371 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
376 static int __init fb_console_setup(char *this_opt)
381 if (!this_opt || !*this_opt)
384 while ((options = strsep(&this_opt, ",")) != NULL) {
385 if (!strncmp(options, "font:", 5))
386 strcpy(fontname, options + 5);
388 if (!strncmp(options, "scrollback:", 11)) {
391 fbcon_softback_size = simple_strtoul(options, &options, 0);
392 if (*options == 'k' || *options == 'K') {
393 fbcon_softback_size *= 1024;
403 if (!strncmp(options, "map:", 4)) {
406 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
410 (options[j++]-'0') % FB_MAX;
415 if (!strncmp(options, "vc:", 3)) {
418 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
421 if (*options++ == '-')
422 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
423 fbcon_is_default = 0;
429 __setup("fbcon=", fb_console_setup);
432 static int search_fb_in_map(int idx)
436 for (i = 0; i < MAX_NR_CONSOLES; i++) {
437 if (con2fb_map[i] == idx)
443 static int search_for_mapped_con(void)
447 for (i = 0; i < MAX_NR_CONSOLES; i++) {
448 if (con2fb_map[i] != -1)
454 static int fbcon_takeover(int show_logo)
458 if (!num_registered_fb)
462 logo_shown = FBCON_LOGO_DONTSHOW;
464 for (i = first_fb_vc; i <= last_fb_vc; i++)
465 con2fb_map[i] = info_idx;
467 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
470 for (i = first_fb_vc; i <= last_fb_vc; i++) {
479 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
480 int cols, int rows, int new_cols, int new_rows)
482 /* Need to make room for the logo */
483 int cnt, erase = vc->vc_video_erase_char, step;
484 unsigned short *save = NULL, *r, *q;
487 * remove underline attribute from erase character
488 * if black and white framebuffer.
490 if (fb_get_color_depth(&info->var, &info->fix) == 1)
492 logo_height = fb_prepare_logo(info);
493 logo_lines = (logo_height + vc->vc_font.height - 1) /
495 q = (unsigned short *) (vc->vc_origin +
496 vc->vc_size_row * rows);
497 step = logo_lines * cols;
498 for (r = q - logo_lines * cols; r < q; r++)
499 if (scr_readw(r) != vc->vc_video_erase_char)
501 if (r != q && new_rows >= rows + logo_lines) {
502 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
504 int i = cols < new_cols ? cols : new_cols;
505 scr_memsetw(save, erase, logo_lines * new_cols * 2);
507 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
508 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
513 /* We can scroll screen down */
515 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
516 scr_memcpyw(r + step, r, vc->vc_size_row);
520 vc->vc_y += logo_lines;
521 vc->vc_pos += logo_lines * vc->vc_size_row;
524 scr_memsetw((unsigned short *) vc->vc_origin,
526 vc->vc_size_row * logo_lines);
528 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
529 fbcon_clear_margins(vc, 0);
534 q = (unsigned short *) (vc->vc_origin +
537 scr_memcpyw(q, save, logo_lines * new_cols * 2);
538 vc->vc_y += logo_lines;
539 vc->vc_pos += logo_lines * vc->vc_size_row;
543 if (logo_lines > vc->vc_bottom) {
544 logo_shown = FBCON_LOGO_CANSHOW;
546 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
547 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
548 logo_shown = FBCON_LOGO_DRAW;
549 vc->vc_top = logo_lines;
553 #ifdef CONFIG_FB_TILEBLITTING
554 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
557 struct fbcon_ops *ops = info->fbcon_par;
559 if ((info->flags & FBINFO_MISC_TILEBLITTING))
560 fbcon_set_tileops(vc, info, p, ops);
562 fbcon_set_bitops(ops);
565 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
568 struct fbcon_ops *ops = info->fbcon_par;
570 info->flags &= ~FBINFO_MISC_TILEBLITTING;
571 fbcon_set_bitops(ops);
573 #endif /* CONFIG_MISC_TILEBLITTING */
576 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
577 int unit, int oldidx)
579 struct fbcon_ops *ops = NULL;
582 if (!try_module_get(info->fbops->owner))
585 if (!err && info->fbops->fb_open &&
586 info->fbops->fb_open(info, 0))
590 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
596 memset(ops, 0, sizeof(struct fbcon_ops));
597 info->fbcon_par = ops;
598 set_blitting_type(vc, info, NULL);
602 con2fb_map[unit] = oldidx;
603 module_put(info->fbops->owner);
609 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
610 struct fb_info *newinfo, int unit,
611 int oldidx, int found)
613 struct fbcon_ops *ops = oldinfo->fbcon_par;
616 if (oldinfo->fbops->fb_release &&
617 oldinfo->fbops->fb_release(oldinfo, 0)) {
618 con2fb_map[unit] = oldidx;
619 if (!found && newinfo->fbops->fb_release)
620 newinfo->fbops->fb_release(newinfo, 0);
622 module_put(newinfo->fbops->owner);
627 fbcon_del_cursor_timer(oldinfo);
628 kfree(ops->cursor_state.mask);
629 kfree(ops->cursor_data);
630 kfree(oldinfo->fbcon_par);
631 oldinfo->fbcon_par = NULL;
632 module_put(oldinfo->fbops->owner);
634 If oldinfo and newinfo are driving the same hardware,
635 the fb_release() method of oldinfo may attempt to
636 restore the hardware state. This will leave the
637 newinfo in an undefined state. Thus, a call to
638 fb_set_par() may be needed for the newinfo.
640 if (newinfo->fbops->fb_set_par)
641 newinfo->fbops->fb_set_par(newinfo);
647 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
648 int unit, int show_logo)
650 struct fbcon_ops *ops = info->fbcon_par;
652 ops->currcon = fg_console;
654 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
655 info->fbops->fb_set_par(info);
657 ops->flags |= FBCON_FLAGS_INIT;
661 fbcon_set_disp(info, &info->var, vc);
663 fbcon_preset_disp(info, &info->var, unit);
666 struct vc_data *fg_vc = vc_cons[fg_console].d;
667 struct fb_info *fg_info =
668 registered_fb[con2fb_map[fg_console]];
670 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
671 fg_vc->vc_rows, fg_vc->vc_cols,
675 update_screen(vc_cons[fg_console].d);
679 * set_con2fb_map - map console to frame buffer device
680 * @unit: virtual console number to map
681 * @newidx: frame buffer index to map virtual console to
682 * @user: user request
684 * Maps a virtual console @unit to a frame buffer device
687 static int set_con2fb_map(int unit, int newidx, int user)
689 struct vc_data *vc = vc_cons[unit].d;
690 int oldidx = con2fb_map[unit];
691 struct fb_info *info = registered_fb[newidx];
692 struct fb_info *oldinfo = NULL;
695 if (oldidx == newidx)
701 if (!err && !search_for_mapped_con()) {
703 return fbcon_takeover(0);
707 oldinfo = registered_fb[oldidx];
709 found = search_fb_in_map(newidx);
711 acquire_console_sem();
712 con2fb_map[unit] = newidx;
714 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
718 * If old fb is not mapped to any of the consoles,
719 * fbcon should release it.
721 if (!err && oldinfo && !search_fb_in_map(oldidx))
722 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
726 int show_logo = (fg_console == 0 && !user &&
727 logo_shown != FBCON_LOGO_DONTSHOW);
730 fbcon_add_cursor_timer(info);
731 con2fb_map_boot[unit] = newidx;
732 con2fb_init_display(vc, info, unit, show_logo);
735 release_console_sem();
740 * Low Level Operations
742 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
743 static int var_to_display(struct display *disp,
744 struct fb_var_screeninfo *var,
745 struct fb_info *info)
747 disp->xres_virtual = var->xres_virtual;
748 disp->yres_virtual = var->yres_virtual;
749 disp->bits_per_pixel = var->bits_per_pixel;
750 disp->grayscale = var->grayscale;
751 disp->nonstd = var->nonstd;
752 disp->accel_flags = var->accel_flags;
753 disp->height = var->height;
754 disp->width = var->width;
755 disp->red = var->red;
756 disp->green = var->green;
757 disp->blue = var->blue;
758 disp->transp = var->transp;
759 disp->rotate = var->rotate;
760 disp->mode = fb_match_mode(var, &info->modelist);
761 if (disp->mode == NULL)
762 /* This should not happen */
767 static void display_to_var(struct fb_var_screeninfo *var,
768 struct display *disp)
770 fb_videomode_to_var(var, disp->mode);
771 var->xres_virtual = disp->xres_virtual;
772 var->yres_virtual = disp->yres_virtual;
773 var->bits_per_pixel = disp->bits_per_pixel;
774 var->grayscale = disp->grayscale;
775 var->nonstd = disp->nonstd;
776 var->accel_flags = disp->accel_flags;
777 var->height = disp->height;
778 var->width = disp->width;
779 var->red = disp->red;
780 var->green = disp->green;
781 var->blue = disp->blue;
782 var->transp = disp->transp;
783 var->rotate = disp->rotate;
786 static const char *fbcon_startup(void)
788 const char *display_desc = "frame buffer device";
789 struct display *p = &fb_display[fg_console];
790 struct vc_data *vc = vc_cons[fg_console].d;
791 const struct font_desc *font = NULL;
792 struct module *owner;
793 struct fb_info *info = NULL;
794 struct fbcon_ops *ops;
800 * If num_registered_fb is zero, this is a call for the dummy part.
801 * The frame buffer devices weren't initialized yet.
803 if (!num_registered_fb || info_idx == -1)
806 * Instead of blindly using registered_fb[0], we use info_idx, set by
809 info = registered_fb[info_idx];
813 owner = info->fbops->owner;
814 if (!try_module_get(owner))
816 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
821 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
827 memset(ops, 0, sizeof(struct fbcon_ops));
830 info->fbcon_par = ops;
831 set_blitting_type(vc, info, NULL);
833 if (info->fix.type != FB_TYPE_TEXT) {
834 if (fbcon_softback_size) {
838 kmalloc(fbcon_softback_size,
841 fbcon_softback_size = 0;
847 kfree((void *) softback_buf);
853 softback_in = softback_top = softback_curr =
858 /* Setup default font */
860 if (!fontname[0] || !(font = find_font(fontname)))
861 font = get_default_font(info->var.xres,
863 vc->vc_font.width = font->width;
864 vc->vc_font.height = font->height;
865 vc->vc_font.data = (void *)(p->fontdata = font->data);
866 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
869 cols = info->var.xres / vc->vc_font.width;
870 rows = info->var.yres / vc->vc_font.height;
871 vc_resize(vc, cols, rows);
873 DPRINTK("mode: %s\n", info->fix.id);
874 DPRINTK("visual: %d\n", info->fix.visual);
875 DPRINTK("res: %dx%d-%d\n", info->var.xres,
877 info->var.bits_per_pixel);
881 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
883 request_irq(IRQ_AUTO_4, fb_vbl_handler,
884 IRQ_TYPE_PRIO, "framebuffer vbl",
887 #endif /* CONFIG_ATARI */
891 * On a Macintoy, the VBL interrupt may or may not be active.
892 * As interrupt based cursor is more reliable and race free, we
893 * probe for VBL interrupts.
898 * Probe for VBL: set temp. handler ...
900 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
901 "framebuffer vbl", info);
905 * ... and spin for 20 ms ...
907 while (!vbl_detected && ++ct < 1000)
912 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
914 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
918 * interrupt based cursor ok
920 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
922 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
923 "framebuffer vbl", info);
926 * VBL not detected: fall through, use timer based cursor
931 #endif /* CONFIG_MAC */
933 fbcon_add_cursor_timer(info);
937 static void fbcon_init(struct vc_data *vc, int init)
939 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
940 struct fbcon_ops *ops;
941 struct vc_data **default_mode = vc->vc_display_fg;
942 struct vc_data *svc = *default_mode;
943 struct display *t, *p = &fb_display[vc->vc_num];
944 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
947 if (info_idx == -1 || info == NULL)
952 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
953 (info->fix.type == FB_TYPE_TEXT))
956 info->var.xoffset = info->var.yoffset = p->yscroll = 0; /* reset wrap/pan */
958 if (var_to_display(p, &info->var, info))
961 /* If we are not the first console on this
962 fb, copy the font from that console */
963 t = &fb_display[svc->vc_num];
964 if (!vc->vc_font.data) {
965 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
966 vc->vc_font.width = (*default_mode)->vc_font.width;
967 vc->vc_font.height = (*default_mode)->vc_font.height;
968 p->userfont = t->userfont;
970 REFCOUNT(p->fontdata)++;
973 charcnt = FNTCHARCNT(p->fontdata);
974 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
975 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
976 if (charcnt == 256) {
977 vc->vc_hi_font_mask = 0;
979 vc->vc_hi_font_mask = 0x100;
980 if (vc->vc_can_do_color)
981 vc->vc_complement_mask <<= 1;
984 if (!*svc->vc_uni_pagedir_loc)
985 con_set_default_unimap(svc);
986 if (!*vc->vc_uni_pagedir_loc)
987 con_copy_unimap(vc, svc);
991 new_cols = info->var.xres / vc->vc_font.width;
992 new_rows = info->var.yres / vc->vc_font.height;
993 vc_resize(vc, new_cols, new_rows);
995 ops = info->fbcon_par;
997 * We must always set the mode. The mode of the previous console
998 * driver could be in the same resolution but we are using different
999 * hardware so we have to initialize the hardware.
1001 * We need to do it in fbcon_init() to prevent screen corruption.
1003 if (CON_IS_VISIBLE(vc)) {
1004 if (info->fbops->fb_set_par &&
1005 !(ops->flags & FBCON_FLAGS_INIT))
1006 info->fbops->fb_set_par(info);
1007 ops->flags |= FBCON_FLAGS_INIT;
1012 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1013 !(cap & FBINFO_HWACCEL_DISABLED))
1014 p->scrollmode = SCROLL_MOVE;
1015 else /* default to something safe */
1016 p->scrollmode = SCROLL_REDRAW;
1019 * ++guenther: console.c:vc_allocate() relies on initializing
1020 * vc_{cols,rows}, but we must not set those if we are only
1021 * resizing the console.
1024 vc->vc_cols = new_cols;
1025 vc->vc_rows = new_rows;
1029 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1031 if (vc == svc && softback_buf)
1032 fbcon_update_softback(vc);
1035 static void fbcon_deinit(struct vc_data *vc)
1037 struct display *p = &fb_display[vc->vc_num];
1044 /* ====================================================================== */
1046 /* fbcon_XXX routines - interface used by the world
1048 * This system is now divided into two levels because of complications
1049 * caused by hardware scrolling. Top level functions:
1051 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1053 * handles y values in range [0, scr_height-1] that correspond to real
1054 * screen positions. y_wrap shift means that first line of bitmap may be
1055 * anywhere on this display. These functions convert lineoffsets to
1056 * bitmap offsets and deal with the wrap-around case by splitting blits.
1058 * fbcon_bmove_physical_8() -- These functions fast implementations
1059 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1060 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1064 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1065 * Implies should only really hardware scroll in rows. Only reason for
1066 * restriction is simplicity & efficiency at the moment.
1069 static __inline__ int real_y(struct display *p, int ypos)
1071 int rows = p->vrows;
1074 return ypos < rows ? ypos : ypos - rows;
1078 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1081 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1082 struct fbcon_ops *ops = info->fbcon_par;
1084 struct display *p = &fb_display[vc->vc_num];
1087 if (fbcon_is_inactive(vc, info))
1090 if (!height || !width)
1093 /* Split blits that cross physical y_wrap boundary */
1095 y_break = p->vrows - p->yscroll;
1096 if (sy < y_break && sy + height - 1 >= y_break) {
1097 u_int b = y_break - sy;
1098 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1099 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1102 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1105 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1106 int count, int ypos, int xpos)
1108 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1109 struct display *p = &fb_display[vc->vc_num];
1110 struct fbcon_ops *ops = info->fbcon_par;
1112 if (!fbcon_is_inactive(vc, info))
1113 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1114 get_color(vc, info, scr_readw(s), 1),
1115 get_color(vc, info, scr_readw(s), 0));
1118 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1122 scr_writew(c, &chr);
1123 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1126 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1128 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1129 struct fbcon_ops *ops = info->fbcon_par;
1131 if (!fbcon_is_inactive(vc, info))
1132 ops->clear_margins(vc, info, bottom_only);
1135 static void fbcon_cursor(struct vc_data *vc, int mode)
1137 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1138 struct fbcon_ops *ops = info->fbcon_par;
1139 struct display *p = &fb_display[vc->vc_num];
1141 int c = scr_readw((u16 *) vc->vc_pos);
1143 if (fbcon_is_inactive(vc, info))
1146 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1147 if (mode & CM_SOFTBACK) {
1148 mode &= ~CM_SOFTBACK;
1152 fbcon_set_origin(vc);
1156 ops->cursor(vc, info, p, mode, y, get_color(vc, info, c, 1),
1157 get_color(vc, info, c, 0));
1158 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1161 static int scrollback_phys_max = 0;
1162 static int scrollback_max = 0;
1163 static int scrollback_current = 0;
1165 static int update_var(int con, struct fb_info *info)
1167 if (con == ((struct fbcon_ops *)info->fbcon_par)->currcon)
1168 return fb_pan_display(info, &info->var);
1173 * If no vc is existent yet, just set struct display
1175 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1178 struct display *p = &fb_display[unit];
1179 struct display *t = &fb_display[fg_console];
1181 var->xoffset = var->yoffset = p->yscroll = 0;
1182 if (var_to_display(p, var, info))
1185 p->fontdata = t->fontdata;
1186 p->userfont = t->userfont;
1188 REFCOUNT(p->fontdata)++;
1191 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1194 struct display *p = &fb_display[vc->vc_num], *t;
1195 struct vc_data **default_mode = vc->vc_display_fg;
1196 struct vc_data *svc = *default_mode;
1197 int rows, cols, charcnt = 256;
1199 var->xoffset = var->yoffset = p->yscroll = 0;
1200 if (var_to_display(p, var, info))
1202 t = &fb_display[svc->vc_num];
1203 if (!vc->vc_font.data) {
1204 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1205 vc->vc_font.width = (*default_mode)->vc_font.width;
1206 vc->vc_font.height = (*default_mode)->vc_font.height;
1207 p->userfont = t->userfont;
1209 REFCOUNT(p->fontdata)++;
1212 charcnt = FNTCHARCNT(p->fontdata);
1214 var->activate = FB_ACTIVATE_NOW;
1215 info->var.activate = var->activate;
1216 info->var.yoffset = info->var.xoffset = 0;
1217 fb_set_var(info, var);
1219 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1220 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1221 if (charcnt == 256) {
1222 vc->vc_hi_font_mask = 0;
1224 vc->vc_hi_font_mask = 0x100;
1225 if (vc->vc_can_do_color)
1226 vc->vc_complement_mask <<= 1;
1229 if (!*svc->vc_uni_pagedir_loc)
1230 con_set_default_unimap(svc);
1231 if (!*vc->vc_uni_pagedir_loc)
1232 con_copy_unimap(vc, svc);
1234 cols = var->xres / vc->vc_font.width;
1235 rows = var->yres / vc->vc_font.height;
1236 vc_resize(vc, cols, rows);
1237 if (CON_IS_VISIBLE(vc)) {
1240 fbcon_update_softback(vc);
1244 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1246 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1247 struct display *p = &fb_display[vc->vc_num];
1249 p->yscroll += count;
1250 if (p->yscroll >= p->vrows) /* Deal with wrap */
1251 p->yscroll -= p->vrows;
1252 info->var.xoffset = 0;
1253 info->var.yoffset = p->yscroll * vc->vc_font.height;
1254 info->var.vmode |= FB_VMODE_YWRAP;
1255 update_var(vc->vc_num, info);
1256 scrollback_max += count;
1257 if (scrollback_max > scrollback_phys_max)
1258 scrollback_max = scrollback_phys_max;
1259 scrollback_current = 0;
1262 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1264 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1265 struct display *p = &fb_display[vc->vc_num];
1267 p->yscroll -= count;
1268 if (p->yscroll < 0) /* Deal with wrap */
1269 p->yscroll += p->vrows;
1270 info->var.xoffset = 0;
1271 info->var.yoffset = p->yscroll * vc->vc_font.height;
1272 info->var.vmode |= FB_VMODE_YWRAP;
1273 update_var(vc->vc_num, info);
1274 scrollback_max -= count;
1275 if (scrollback_max < 0)
1277 scrollback_current = 0;
1280 static __inline__ void ypan_up(struct vc_data *vc, int count)
1282 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1283 struct display *p = &fb_display[vc->vc_num];
1284 struct fbcon_ops *ops = info->fbcon_par;
1286 p->yscroll += count;
1287 if (p->yscroll > p->vrows - vc->vc_rows) {
1288 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1289 0, 0, 0, vc->vc_rows, vc->vc_cols);
1290 p->yscroll -= p->vrows - vc->vc_rows;
1292 info->var.xoffset = 0;
1293 info->var.yoffset = p->yscroll * vc->vc_font.height;
1294 info->var.vmode &= ~FB_VMODE_YWRAP;
1295 update_var(vc->vc_num, info);
1296 fbcon_clear_margins(vc, 1);
1297 scrollback_max += count;
1298 if (scrollback_max > scrollback_phys_max)
1299 scrollback_max = scrollback_phys_max;
1300 scrollback_current = 0;
1303 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1305 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1306 struct display *p = &fb_display[vc->vc_num];
1309 p->yscroll += count;
1310 if (p->yscroll > p->vrows - vc->vc_rows) {
1311 p->yscroll -= p->vrows - vc->vc_rows;
1315 info->var.xoffset = 0;
1316 info->var.yoffset = p->yscroll * vc->vc_font.height;
1317 info->var.vmode &= ~FB_VMODE_YWRAP;
1319 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1320 update_var(vc->vc_num, info);
1321 fbcon_clear_margins(vc, 1);
1322 scrollback_max += count;
1323 if (scrollback_max > scrollback_phys_max)
1324 scrollback_max = scrollback_phys_max;
1325 scrollback_current = 0;
1328 static __inline__ void ypan_down(struct vc_data *vc, int count)
1330 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1331 struct display *p = &fb_display[vc->vc_num];
1332 struct fbcon_ops *ops = info->fbcon_par;
1334 p->yscroll -= count;
1335 if (p->yscroll < 0) {
1336 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1337 0, vc->vc_rows, vc->vc_cols);
1338 p->yscroll += p->vrows - vc->vc_rows;
1340 info->var.xoffset = 0;
1341 info->var.yoffset = p->yscroll * vc->vc_font.height;
1342 info->var.vmode &= ~FB_VMODE_YWRAP;
1343 update_var(vc->vc_num, info);
1344 fbcon_clear_margins(vc, 1);
1345 scrollback_max -= count;
1346 if (scrollback_max < 0)
1348 scrollback_current = 0;
1351 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1353 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1354 struct display *p = &fb_display[vc->vc_num];
1357 p->yscroll -= count;
1358 if (p->yscroll < 0) {
1359 p->yscroll += p->vrows - vc->vc_rows;
1362 info->var.xoffset = 0;
1363 info->var.yoffset = p->yscroll * vc->vc_font.height;
1364 info->var.vmode &= ~FB_VMODE_YWRAP;
1366 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1367 update_var(vc->vc_num, info);
1368 fbcon_clear_margins(vc, 1);
1369 scrollback_max -= count;
1370 if (scrollback_max < 0)
1372 scrollback_current = 0;
1375 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1378 int count = vc->vc_rows;
1379 unsigned short *d, *s;
1383 d = (u16 *) softback_curr;
1384 if (d == (u16 *) softback_in)
1385 d = (u16 *) vc->vc_origin;
1386 n = softback_curr + delta * vc->vc_size_row;
1387 softback_lines -= delta;
1389 if (softback_curr < softback_top && n < softback_buf) {
1390 n += softback_end - softback_buf;
1391 if (n < softback_top) {
1393 (softback_top - n) / vc->vc_size_row;
1396 } else if (softback_curr >= softback_top
1397 && n < softback_top) {
1399 (softback_top - n) / vc->vc_size_row;
1403 if (softback_curr > softback_in && n >= softback_end) {
1404 n += softback_buf - softback_end;
1405 if (n > softback_in) {
1409 } else if (softback_curr <= softback_in && n > softback_in) {
1414 if (n == softback_curr)
1417 s = (u16 *) softback_curr;
1418 if (s == (u16 *) softback_in)
1419 s = (u16 *) vc->vc_origin;
1421 unsigned short *start;
1425 unsigned short attr = 1;
1428 le = advance_row(s, 1);
1431 if (attr != (c & 0xff00)) {
1434 fbcon_putcs(vc, start, s - start,
1440 if (c == scr_readw(d)) {
1442 fbcon_putcs(vc, start, s - start,
1455 fbcon_putcs(vc, start, s - start, line, x);
1457 if (d == (u16 *) softback_end)
1458 d = (u16 *) softback_buf;
1459 if (d == (u16 *) softback_in)
1460 d = (u16 *) vc->vc_origin;
1461 if (s == (u16 *) softback_end)
1462 s = (u16 *) softback_buf;
1463 if (s == (u16 *) softback_in)
1464 s = (u16 *) vc->vc_origin;
1468 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1469 int line, int count, int dy)
1471 unsigned short *s = (unsigned short *)
1472 (vc->vc_origin + vc->vc_size_row * line);
1475 unsigned short *start = s;
1476 unsigned short *le = advance_row(s, 1);
1479 unsigned short attr = 1;
1483 if (attr != (c & 0xff00)) {
1486 fbcon_putcs(vc, start, s - start,
1492 console_conditional_schedule();
1496 fbcon_putcs(vc, start, s - start, dy, x);
1497 console_conditional_schedule();
1502 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1503 int line, int count, int offset)
1505 unsigned short *d = (unsigned short *)
1506 (vc->vc_origin + vc->vc_size_row * line);
1507 unsigned short *s = d + offset;
1510 unsigned short *start = s;
1511 unsigned short *le = advance_row(s, 1);
1514 unsigned short attr = 1;
1518 if (attr != (c & 0xff00)) {
1521 fbcon_putcs(vc, start, s - start,
1527 if (c == scr_readw(d)) {
1529 fbcon_putcs(vc, start, s - start,
1539 console_conditional_schedule();
1544 fbcon_putcs(vc, start, s - start, line, x);
1545 console_conditional_schedule();
1550 /* NOTE: We subtract two lines from these pointers */
1551 s -= vc->vc_size_row;
1552 d -= vc->vc_size_row;
1557 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1562 if (vc->vc_num != fg_console)
1564 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1567 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1569 p = advance_row(p, 1);
1570 softback_in += vc->vc_size_row;
1571 if (softback_in == softback_end)
1572 softback_in = softback_buf;
1573 if (softback_in == softback_top) {
1574 softback_top += vc->vc_size_row;
1575 if (softback_top == softback_end)
1576 softback_top = softback_buf;
1579 softback_curr = softback_in;
1582 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1585 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1586 struct display *p = &fb_display[vc->vc_num];
1587 struct fbcon_ops *ops = info->fbcon_par;
1588 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1590 if (fbcon_is_inactive(vc, info))
1593 fbcon_cursor(vc, CM_ERASE);
1596 * ++Geert: Only use ywrap/ypan if the console is in text mode
1597 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1598 * whole screen (prevents flicker).
1603 if (count > vc->vc_rows) /* Maximum realistic size */
1604 count = vc->vc_rows;
1606 fbcon_softback_note(vc, t, count);
1607 if (logo_shown >= 0)
1609 switch (p->scrollmode) {
1611 ops->bmove(vc, info, t + count, 0, t, 0,
1612 b - t - count, vc->vc_cols);
1613 ops->clear(vc, info, b - count, 0, count,
1617 case SCROLL_WRAP_MOVE:
1618 if (b - t - count > 3 * vc->vc_rows >> 2) {
1620 fbcon_bmove(vc, 0, 0, count, 0, t,
1622 ywrap_up(vc, count);
1623 if (vc->vc_rows - b > 0)
1624 fbcon_bmove(vc, b - count, 0, b, 0,
1627 } else if (info->flags & FBINFO_READS_FAST)
1628 fbcon_bmove(vc, t + count, 0, t, 0,
1629 b - t - count, vc->vc_cols);
1632 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1635 case SCROLL_PAN_REDRAW:
1636 if ((p->yscroll + count <=
1637 2 * (p->vrows - vc->vc_rows))
1638 && ((!scroll_partial && (b - t == vc->vc_rows))
1641 3 * vc->vc_rows >> 2)))) {
1643 fbcon_redraw_move(vc, p, 0, t, count);
1644 ypan_up_redraw(vc, t, count);
1645 if (vc->vc_rows - b > 0)
1646 fbcon_redraw_move(vc, p, b - count,
1647 vc->vc_rows - b, b);
1649 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1650 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1653 case SCROLL_PAN_MOVE:
1654 if ((p->yscroll + count <=
1655 2 * (p->vrows - vc->vc_rows))
1656 && ((!scroll_partial && (b - t == vc->vc_rows))
1659 3 * vc->vc_rows >> 2)))) {
1661 fbcon_bmove(vc, 0, 0, count, 0, t,
1664 if (vc->vc_rows - b > 0)
1665 fbcon_bmove(vc, b - count, 0, b, 0,
1668 } else if (info->flags & FBINFO_READS_FAST)
1669 fbcon_bmove(vc, t + count, 0, t, 0,
1670 b - t - count, vc->vc_cols);
1673 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1678 fbcon_redraw(vc, p, t, b - t - count,
1679 count * vc->vc_cols);
1680 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1681 scr_memsetw((unsigned short *) (vc->vc_origin +
1684 vc->vc_video_erase_char,
1685 vc->vc_size_row * count);
1691 if (count > vc->vc_rows) /* Maximum realistic size */
1692 count = vc->vc_rows;
1693 if (logo_shown >= 0)
1695 switch (p->scrollmode) {
1697 ops->bmove(vc, info, t, 0, t + count, 0,
1698 b - t - count, vc->vc_cols);
1699 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1702 case SCROLL_WRAP_MOVE:
1703 if (b - t - count > 3 * vc->vc_rows >> 2) {
1704 if (vc->vc_rows - b > 0)
1705 fbcon_bmove(vc, b, 0, b - count, 0,
1708 ywrap_down(vc, count);
1710 fbcon_bmove(vc, count, 0, 0, 0, t,
1712 } else if (info->flags & FBINFO_READS_FAST)
1713 fbcon_bmove(vc, t, 0, t + count, 0,
1714 b - t - count, vc->vc_cols);
1717 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1720 case SCROLL_PAN_MOVE:
1721 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1722 && ((!scroll_partial && (b - t == vc->vc_rows))
1725 3 * vc->vc_rows >> 2)))) {
1726 if (vc->vc_rows - b > 0)
1727 fbcon_bmove(vc, b, 0, b - count, 0,
1730 ypan_down(vc, count);
1732 fbcon_bmove(vc, count, 0, 0, 0, t,
1734 } else if (info->flags & FBINFO_READS_FAST)
1735 fbcon_bmove(vc, t, 0, t + count, 0,
1736 b - t - count, vc->vc_cols);
1739 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1742 case SCROLL_PAN_REDRAW:
1743 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1744 && ((!scroll_partial && (b - t == vc->vc_rows))
1747 3 * vc->vc_rows >> 2)))) {
1748 if (vc->vc_rows - b > 0)
1749 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1751 ypan_down_redraw(vc, t, count);
1753 fbcon_redraw_move(vc, p, count, t, 0);
1755 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1756 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1761 fbcon_redraw(vc, p, b - 1, b - t - count,
1762 -count * vc->vc_cols);
1763 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1764 scr_memsetw((unsigned short *) (vc->vc_origin +
1767 vc->vc_video_erase_char,
1768 vc->vc_size_row * count);
1776 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1777 int height, int width)
1779 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1780 struct display *p = &fb_display[vc->vc_num];
1782 if (fbcon_is_inactive(vc, info))
1785 if (!width || !height)
1788 /* Split blits that cross physical y_wrap case.
1789 * Pathological case involves 4 blits, better to use recursive
1790 * code rather than unrolled case
1792 * Recursive invocations don't need to erase the cursor over and
1793 * over again, so we use fbcon_bmove_rec()
1795 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1796 p->vrows - p->yscroll);
1799 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1800 int dy, int dx, int height, int width, u_int y_break)
1802 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1803 struct fbcon_ops *ops = info->fbcon_par;
1806 if (sy < y_break && sy + height > y_break) {
1808 if (dy < sy) { /* Avoid trashing self */
1809 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1811 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1812 height - b, width, y_break);
1814 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1815 height - b, width, y_break);
1816 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1822 if (dy < y_break && dy + height > y_break) {
1824 if (dy < sy) { /* Avoid trashing self */
1825 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1827 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1828 height - b, width, y_break);
1830 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1831 height - b, width, y_break);
1832 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1837 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1841 static __inline__ void updatescrollmode(struct display *p, struct fb_info *info,
1844 int fh = vc->vc_font.height;
1845 int cap = info->flags;
1846 int good_pan = (cap & FBINFO_HWACCEL_YPAN)
1847 && divides(info->fix.ypanstep, vc->vc_font.height)
1848 && info->var.yres_virtual > info->var.yres;
1849 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP)
1850 && divides(info->fix.ywrapstep, vc->vc_font.height)
1851 && divides(vc->vc_font.height, info->var.yres_virtual);
1852 int reading_fast = cap & FBINFO_READS_FAST;
1853 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) && !(cap & FBINFO_HWACCEL_DISABLED);
1854 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) && !(cap & FBINFO_HWACCEL_DISABLED);
1856 p->vrows = info->var.yres_virtual/fh;
1857 if (info->var.yres > (fh * (vc->vc_rows + 1)))
1858 p->vrows -= (info->var.yres - (fh * vc->vc_rows)) / fh;
1859 if ((info->var.yres % fh) && (info->var.yres_virtual % fh <
1860 info->var.yres % fh))
1863 if (good_wrap || good_pan) {
1864 if (reading_fast || fast_copyarea)
1865 p->scrollmode = good_wrap ? SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1867 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1870 if (reading_fast || (fast_copyarea && !fast_imageblit))
1871 p->scrollmode = SCROLL_MOVE;
1873 p->scrollmode = SCROLL_REDRAW;
1877 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1878 unsigned int height)
1880 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1881 struct display *p = &fb_display[vc->vc_num];
1882 struct fb_var_screeninfo var = info->var;
1884 int fw = vc->vc_font.width;
1885 int fh = vc->vc_font.height;
1887 var.xres = width * fw;
1888 var.yres = height * fh;
1889 x_diff = info->var.xres - var.xres;
1890 y_diff = info->var.yres - var.yres;
1891 if (x_diff < 0 || x_diff > fw || (y_diff < 0 || y_diff > fh)) {
1892 struct fb_videomode *mode;
1894 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
1895 mode = fb_find_best_mode(&var, &info->modelist);
1898 display_to_var(&var, p);
1899 fb_videomode_to_var(&var, mode);
1901 if (width > var.xres/fw || height > var.yres/fh)
1904 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
1905 if (CON_IS_VISIBLE(vc)) {
1906 var.activate = FB_ACTIVATE_NOW |
1908 fb_set_var(info, &var);
1910 var_to_display(p, &info->var, info);
1912 updatescrollmode(p, info, vc);
1916 static int fbcon_switch(struct vc_data *vc)
1918 struct fb_info *info, *old_info = NULL;
1919 struct display *p = &fb_display[vc->vc_num];
1920 struct fb_var_screeninfo var;
1921 int i, prev_console;
1923 info = registered_fb[con2fb_map[vc->vc_num]];
1927 fbcon_set_origin(vc);
1928 softback_top = softback_curr = softback_in = softback_buf;
1930 fbcon_update_softback(vc);
1933 if (logo_shown >= 0) {
1934 struct vc_data *conp2 = vc_cons[logo_shown].d;
1936 if (conp2->vc_top == logo_lines
1937 && conp2->vc_bottom == conp2->vc_rows)
1939 logo_shown = FBCON_LOGO_CANSHOW;
1942 prev_console = ((struct fbcon_ops *)info->fbcon_par)->currcon;
1943 if (prev_console != -1)
1944 old_info = registered_fb[con2fb_map[prev_console]];
1946 * FIXME: If we have multiple fbdev's loaded, we need to
1947 * update all info->currcon. Perhaps, we can place this
1948 * in a centralized structure, but this might break some
1951 * info->currcon = vc->vc_num;
1953 for (i = 0; i < FB_MAX; i++) {
1954 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
1955 struct fbcon_ops *ops = registered_fb[i]->fbcon_par;
1957 ops->currcon = vc->vc_num;
1960 memset(&var, 0, sizeof(struct fb_var_screeninfo));
1961 display_to_var(&var, p);
1962 var.activate = FB_ACTIVATE_NOW;
1965 * make sure we don't unnecessarily trip the memcmp()
1968 info->var.activate = var.activate;
1969 info->var.yoffset = info->var.xoffset = p->yscroll = 0;
1970 fb_set_var(info, &var);
1972 if (old_info != NULL && old_info != info) {
1973 if (info->fbops->fb_set_par)
1974 info->fbops->fb_set_par(info);
1975 fbcon_del_cursor_timer(old_info);
1976 fbcon_add_cursor_timer(info);
1979 set_blitting_type(vc, info, p);
1980 ((struct fbcon_ops *)info->fbcon_par)->cursor_reset = 1;
1982 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1983 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1984 updatescrollmode(p, info, vc);
1986 switch (p->scrollmode) {
1987 case SCROLL_WRAP_MOVE:
1988 scrollback_phys_max = p->vrows - vc->vc_rows;
1990 case SCROLL_PAN_MOVE:
1991 case SCROLL_PAN_REDRAW:
1992 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
1993 if (scrollback_phys_max < 0)
1994 scrollback_phys_max = 0;
1997 scrollback_phys_max = 0;
2001 scrollback_current = 0;
2003 update_var(vc->vc_num, info);
2004 fbcon_set_palette(vc, color_table);
2005 fbcon_clear_margins(vc, 0);
2007 if (logo_shown == FBCON_LOGO_DRAW) {
2009 logo_shown = fg_console;
2010 /* This is protected above by initmem_freed */
2013 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2014 vc->vc_size_row * (vc->vc_bottom -
2021 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2025 unsigned short charmask = vc->vc_hi_font_mask ?
2027 unsigned short oldc;
2029 oldc = vc->vc_video_erase_char;
2030 vc->vc_video_erase_char &= charmask;
2031 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2032 vc->vc_video_erase_char = oldc;
2036 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2038 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2039 struct fbcon_ops *ops = info->fbcon_par;
2042 struct fb_var_screeninfo var = info->var;
2047 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2048 fb_set_var(info, &var);
2053 if (!fbcon_is_inactive(vc, info)) {
2054 if (ops->blank_state != blank) {
2055 ops->blank_state = blank;
2056 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2057 ops->cursor_flash = (!blank);
2059 if (fb_blank(info, blank))
2060 fbcon_generic_blank(vc, info, blank);
2068 fbcon_add_cursor_timer(info);
2070 fbcon_del_cursor_timer(info);
2075 static void fbcon_free_font(struct display *p)
2077 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2078 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2083 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2085 u8 *fontdata = vc->vc_font.data;
2086 u8 *data = font->data;
2089 font->width = vc->vc_font.width;
2090 font->height = vc->vc_font.height;
2091 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2095 if (font->width <= 8) {
2096 j = vc->vc_font.height;
2097 for (i = 0; i < font->charcount; i++) {
2098 memcpy(data, fontdata, j);
2099 memset(data + j, 0, 32 - j);
2103 } else if (font->width <= 16) {
2104 j = vc->vc_font.height * 2;
2105 for (i = 0; i < font->charcount; i++) {
2106 memcpy(data, fontdata, j);
2107 memset(data + j, 0, 64 - j);
2111 } else if (font->width <= 24) {
2112 for (i = 0; i < font->charcount; i++) {
2113 for (j = 0; j < vc->vc_font.height; j++) {
2114 *data++ = fontdata[0];
2115 *data++ = fontdata[1];
2116 *data++ = fontdata[2];
2117 fontdata += sizeof(u32);
2119 memset(data, 0, 3 * (32 - j));
2120 data += 3 * (32 - j);
2123 j = vc->vc_font.height * 4;
2124 for (i = 0; i < font->charcount; i++) {
2125 memcpy(data, fontdata, j);
2126 memset(data + j, 0, 128 - j);
2134 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2135 const u8 * data, int userfont)
2137 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2138 struct display *p = &fb_display[vc->vc_num];
2141 char *old_data = NULL;
2143 if (CON_IS_VISIBLE(vc) && softback_lines)
2144 fbcon_set_origin(vc);
2146 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2148 old_data = vc->vc_font.data;
2150 cnt = FNTCHARCNT(data);
2153 vc->vc_font.data = (void *)(p->fontdata = data);
2154 if ((p->userfont = userfont))
2156 vc->vc_font.width = w;
2157 vc->vc_font.height = h;
2158 if (vc->vc_hi_font_mask && cnt == 256) {
2159 vc->vc_hi_font_mask = 0;
2160 if (vc->vc_can_do_color) {
2161 vc->vc_complement_mask >>= 1;
2162 vc->vc_s_complement_mask >>= 1;
2165 /* ++Edmund: reorder the attribute bits */
2166 if (vc->vc_can_do_color) {
2167 unsigned short *cp =
2168 (unsigned short *) vc->vc_origin;
2169 int count = vc->vc_screenbuf_size / 2;
2171 for (; count > 0; count--, cp++) {
2173 scr_writew(((c & 0xfe00) >> 1) |
2176 c = vc->vc_video_erase_char;
2177 vc->vc_video_erase_char =
2178 ((c & 0xfe00) >> 1) | (c & 0xff);
2181 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2182 vc->vc_hi_font_mask = 0x100;
2183 if (vc->vc_can_do_color) {
2184 vc->vc_complement_mask <<= 1;
2185 vc->vc_s_complement_mask <<= 1;
2188 /* ++Edmund: reorder the attribute bits */
2190 unsigned short *cp =
2191 (unsigned short *) vc->vc_origin;
2192 int count = vc->vc_screenbuf_size / 2;
2194 for (; count > 0; count--, cp++) {
2195 unsigned short newc;
2197 if (vc->vc_can_do_color)
2199 ((c & 0xff00) << 1) | (c &
2203 scr_writew(newc, cp);
2205 c = vc->vc_video_erase_char;
2206 if (vc->vc_can_do_color) {
2207 vc->vc_video_erase_char =
2208 ((c & 0xff00) << 1) | (c & 0xff);
2211 vc->vc_video_erase_char = c & ~0x100;
2217 /* reset wrap/pan */
2218 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2219 vc_resize(vc, info->var.xres / w, info->var.yres / h);
2220 if (CON_IS_VISIBLE(vc) && softback_buf)
2221 fbcon_update_softback(vc);
2222 } else if (CON_IS_VISIBLE(vc)
2223 && vc->vc_mode == KD_TEXT) {
2224 fbcon_clear_margins(vc, 0);
2228 if (old_data && (--REFCOUNT(old_data) == 0))
2229 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2233 static int fbcon_copy_font(struct vc_data *vc, int con)
2235 struct display *od = &fb_display[con];
2236 struct console_font *f = &vc->vc_font;
2238 if (od->fontdata == f->data)
2239 return 0; /* already the same font... */
2240 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2244 * User asked to set font; we are guaranteed that
2245 * a) width and height are in range 1..32
2246 * b) charcount does not exceed 512
2247 * but lets not assume that, since someone might someday want to use larger
2248 * fonts. And charcount of 512 is small for unicode support.
2250 * However, user space gives the font in 32 rows , regardless of
2251 * actual font height. So a new API is needed if support for larger fonts
2252 * is ever implemented.
2255 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2257 unsigned charcount = font->charcount;
2258 int w = font->width;
2259 int h = font->height;
2262 u8 *new_data, *data = font->data;
2263 int pitch = (font->width+7) >> 3;
2265 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2266 * If not this check should be changed to charcount < 256 */
2267 if (charcount != 256 && charcount != 512)
2270 size = h * pitch * charcount;
2272 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2277 new_data += FONT_EXTRA_WORDS * sizeof(int);
2278 FNTSIZE(new_data) = size;
2279 FNTCHARCNT(new_data) = charcount;
2280 REFCOUNT(new_data) = 0; /* usage counter */
2281 for (i=0; i< charcount; i++) {
2282 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2285 /* Since linux has a nice crc32 function use it for counting font
2287 csum = crc32(0, new_data, size);
2289 FNTSUM(new_data) = csum;
2290 /* Check if the same font is on some other console already */
2291 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2292 struct vc_data *tmp = vc_cons[i].d;
2294 if (fb_display[i].userfont &&
2295 fb_display[i].fontdata &&
2296 FNTSUM(fb_display[i].fontdata) == csum &&
2297 FNTSIZE(fb_display[i].fontdata) == size &&
2298 tmp->vc_font.width == w &&
2299 !memcmp(fb_display[i].fontdata, new_data, size)) {
2300 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2301 new_data = (u8 *)fb_display[i].fontdata;
2305 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2308 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2310 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2311 const struct font_desc *f;
2314 f = get_default_font(info->var.xres, info->var.yres);
2315 else if (!(f = find_font(name)))
2318 font->width = f->width;
2319 font->height = f->height;
2320 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2323 static u16 palette_red[16];
2324 static u16 palette_green[16];
2325 static u16 palette_blue[16];
2327 static struct fb_cmap palette_cmap = {
2328 0, 16, palette_red, palette_green, palette_blue, NULL
2331 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2333 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2337 if (fbcon_is_inactive(vc, info))
2340 if (!CON_IS_VISIBLE(vc))
2343 depth = fb_get_color_depth(&info->var, &info->fix);
2345 for (i = j = 0; i < 16; i++) {
2347 val = vc->vc_palette[j++];
2348 palette_red[k] = (val << 8) | val;
2349 val = vc->vc_palette[j++];
2350 palette_green[k] = (val << 8) | val;
2351 val = vc->vc_palette[j++];
2352 palette_blue[k] = (val << 8) | val;
2354 palette_cmap.len = 16;
2355 palette_cmap.start = 0;
2357 * If framebuffer is capable of less than 16 colors,
2358 * use default palette of fbcon.
2361 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2363 return fb_set_cmap(&palette_cmap, info);
2366 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2371 if (vc->vc_num != fg_console || !softback_lines)
2372 return (u16 *) (vc->vc_origin + offset);
2373 line = offset / vc->vc_size_row;
2374 if (line >= softback_lines)
2375 return (u16 *) (vc->vc_origin + offset -
2376 softback_lines * vc->vc_size_row);
2377 p = softback_curr + offset;
2378 if (p >= softback_end)
2379 p += softback_buf - softback_end;
2383 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2389 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2390 unsigned long offset = (pos - vc->vc_origin) / 2;
2392 x = offset % vc->vc_cols;
2393 y = offset / vc->vc_cols;
2394 if (vc->vc_num == fg_console)
2395 y += softback_lines;
2396 ret = pos + (vc->vc_cols - x) * 2;
2397 } else if (vc->vc_num == fg_console && softback_lines) {
2398 unsigned long offset = pos - softback_curr;
2400 if (pos < softback_curr)
2401 offset += softback_end - softback_buf;
2403 x = offset % vc->vc_cols;
2404 y = offset / vc->vc_cols;
2405 ret = pos + (vc->vc_cols - x) * 2;
2406 if (ret == softback_end)
2408 if (ret == softback_in)
2409 ret = vc->vc_origin;
2411 /* Should not happen */
2413 ret = vc->vc_origin;
2422 /* As we might be inside of softback, we may work with non-contiguous buffer,
2423 that's why we have to use a separate routine. */
2424 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2427 u16 a = scr_readw(p);
2428 if (!vc->vc_can_do_color)
2430 else if (vc->vc_hi_font_mask == 0x100)
2431 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2432 (((a) & 0x0e00) << 4);
2434 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2435 (((a) & 0x0700) << 4);
2437 if (p == (u16 *) softback_end)
2438 p = (u16 *) softback_buf;
2439 if (p == (u16 *) softback_in)
2440 p = (u16 *) vc->vc_origin;
2444 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2446 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2447 struct display *p = &fb_display[fg_console];
2448 int offset, limit, scrollback_old;
2451 if (vc->vc_num != fg_console)
2453 if (vc->vc_mode != KD_TEXT || !lines)
2455 if (logo_shown >= 0) {
2456 struct vc_data *conp2 = vc_cons[logo_shown].d;
2458 if (conp2->vc_top == logo_lines
2459 && conp2->vc_bottom == conp2->vc_rows)
2461 if (logo_shown == vc->vc_num) {
2467 logo_lines * vc->vc_size_row;
2468 for (i = 0; i < logo_lines; i++) {
2469 if (p == softback_top)
2471 if (p == softback_buf)
2473 p -= vc->vc_size_row;
2474 q -= vc->vc_size_row;
2475 scr_memcpyw((u16 *) q, (u16 *) p,
2479 update_region(vc, vc->vc_origin,
2480 logo_lines * vc->vc_cols);
2482 logo_shown = FBCON_LOGO_CANSHOW;
2484 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2485 fbcon_redraw_softback(vc, p, lines);
2486 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2490 if (!scrollback_phys_max)
2493 scrollback_old = scrollback_current;
2494 scrollback_current -= lines;
2495 if (scrollback_current < 0)
2496 scrollback_current = 0;
2497 else if (scrollback_current > scrollback_max)
2498 scrollback_current = scrollback_max;
2499 if (scrollback_current == scrollback_old)
2502 if (fbcon_is_inactive(vc, info))
2505 fbcon_cursor(vc, CM_ERASE);
2507 offset = p->yscroll - scrollback_current;
2509 switch (p->scrollmode) {
2510 case SCROLL_WRAP_MOVE:
2511 info->var.vmode |= FB_VMODE_YWRAP;
2513 case SCROLL_PAN_MOVE:
2514 case SCROLL_PAN_REDRAW:
2515 limit -= vc->vc_rows;
2516 info->var.vmode &= ~FB_VMODE_YWRAP;
2521 else if (offset >= limit)
2523 info->var.xoffset = 0;
2524 info->var.yoffset = offset * vc->vc_font.height;
2525 update_var(vc->vc_num, info);
2526 if (!scrollback_current)
2527 fbcon_cursor(vc, CM_DRAW);
2531 static int fbcon_set_origin(struct vc_data *vc)
2534 fbcon_scrolldelta(vc, softback_lines);
2538 static void fbcon_suspended(struct fb_info *info)
2540 struct vc_data *vc = NULL;
2541 struct fbcon_ops *ops = info->fbcon_par;
2543 if (!ops || ops->currcon < 0)
2545 vc = vc_cons[ops->currcon].d;
2547 /* Clear cursor, restore saved data */
2548 fbcon_cursor(vc, CM_ERASE);
2551 static void fbcon_resumed(struct fb_info *info)
2554 struct fbcon_ops *ops = info->fbcon_par;
2556 if (!ops || ops->currcon < 0)
2558 vc = vc_cons[ops->currcon].d;
2563 static void fbcon_modechanged(struct fb_info *info)
2565 struct fbcon_ops *ops = info->fbcon_par;
2570 if (!ops || ops->currcon < 0)
2572 vc = vc_cons[ops->currcon].d;
2573 if (vc->vc_mode != KD_TEXT || registered_fb[con2fb_map[ops->currcon]] != info)
2576 p = &fb_display[vc->vc_num];
2578 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2580 if (CON_IS_VISIBLE(vc)) {
2581 var_to_display(p, &info->var, info);
2582 cols = info->var.xres / vc->vc_font.width;
2583 rows = info->var.yres / vc->vc_font.height;
2584 vc_resize(vc, cols, rows);
2585 updatescrollmode(p, info, vc);
2587 scrollback_current = 0;
2588 update_var(vc->vc_num, info);
2589 fbcon_set_palette(vc, color_table);
2592 fbcon_update_softback(vc);
2596 static void fbcon_set_all_vcs(struct fb_info *info)
2598 struct fbcon_ops *ops = info->fbcon_par;
2603 if (!ops || ops->currcon < 0)
2606 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2608 if (!vc || vc->vc_mode != KD_TEXT ||
2609 registered_fb[con2fb_map[i]] != info)
2612 p = &fb_display[vc->vc_num];
2614 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2615 var_to_display(p, &info->var, info);
2616 cols = info->var.xres / vc->vc_font.width;
2617 rows = info->var.yres / vc->vc_font.height;
2618 vc_resize(vc, cols, rows);
2620 if (CON_IS_VISIBLE(vc)) {
2621 updatescrollmode(p, info, vc);
2623 scrollback_current = 0;
2624 update_var(vc->vc_num, info);
2625 fbcon_set_palette(vc, color_table);
2628 fbcon_update_softback(vc);
2633 static int fbcon_mode_deleted(struct fb_info *info,
2634 struct fb_videomode *mode)
2636 struct fb_info *fb_info;
2638 int i, j, found = 0;
2640 /* before deletion, ensure that mode is not in use */
2641 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2645 fb_info = registered_fb[j];
2646 if (fb_info != info)
2651 if (fb_mode_is_equal(p->mode, mode)) {
2659 static int fbcon_fb_registered(int idx)
2663 if (info_idx == -1) {
2664 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2665 if (con2fb_map_boot[i] == idx) {
2671 ret = fbcon_takeover(1);
2673 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2674 if (con2fb_map_boot[i] == idx)
2675 set_con2fb_map(i, idx, 0);
2682 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2684 struct fbcon_ops *ops = info->fbcon_par;
2687 if (!ops || ops->currcon < 0)
2690 vc = vc_cons[ops->currcon].d;
2691 if (vc->vc_mode != KD_TEXT ||
2692 registered_fb[con2fb_map[ops->currcon]] != info)
2695 if (CON_IS_VISIBLE(vc)) {
2699 do_unblank_screen(0);
2701 ops->blank_state = blank;
2704 static void fbcon_new_modelist(struct fb_info *info)
2708 struct fb_var_screeninfo var;
2709 struct fb_videomode *mode;
2711 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2712 if (registered_fb[con2fb_map[i]] != info)
2714 if (!fb_display[i].mode)
2717 display_to_var(&var, &fb_display[i]);
2718 mode = fb_find_nearest_mode(fb_display[i].mode,
2720 fb_videomode_to_var(&var, mode);
2723 fbcon_set_disp(info, &var, vc);
2725 fbcon_preset_disp(info, &var, i);
2730 static int fbcon_event_notify(struct notifier_block *self,
2731 unsigned long action, void *data)
2733 struct fb_event *event = data;
2734 struct fb_info *info = event->info;
2735 struct fb_videomode *mode;
2736 struct fb_con2fbmap *con2fb;
2740 case FB_EVENT_SUSPEND:
2741 fbcon_suspended(info);
2743 case FB_EVENT_RESUME:
2744 fbcon_resumed(info);
2746 case FB_EVENT_MODE_CHANGE:
2747 fbcon_modechanged(info);
2749 case FB_EVENT_MODE_CHANGE_ALL:
2750 fbcon_set_all_vcs(info);
2752 case FB_EVENT_MODE_DELETE:
2754 ret = fbcon_mode_deleted(info, mode);
2756 case FB_EVENT_FB_REGISTERED:
2757 ret = fbcon_fb_registered(info->node);
2759 case FB_EVENT_SET_CONSOLE_MAP:
2760 con2fb = event->data;
2761 ret = set_con2fb_map(con2fb->console - 1,
2762 con2fb->framebuffer, 1);
2764 case FB_EVENT_GET_CONSOLE_MAP:
2765 con2fb = event->data;
2766 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2768 case FB_EVENT_BLANK:
2769 fbcon_fb_blanked(info, *(int *)event->data);
2771 case FB_EVENT_NEW_MODELIST:
2772 fbcon_new_modelist(info);
2780 * The console `switch' structure for the frame buffer based console
2783 static const struct consw fb_con = {
2784 .owner = THIS_MODULE,
2785 .con_startup = fbcon_startup,
2786 .con_init = fbcon_init,
2787 .con_deinit = fbcon_deinit,
2788 .con_clear = fbcon_clear,
2789 .con_putc = fbcon_putc,
2790 .con_putcs = fbcon_putcs,
2791 .con_cursor = fbcon_cursor,
2792 .con_scroll = fbcon_scroll,
2793 .con_bmove = fbcon_bmove,
2794 .con_switch = fbcon_switch,
2795 .con_blank = fbcon_blank,
2796 .con_font_set = fbcon_set_font,
2797 .con_font_get = fbcon_get_font,
2798 .con_font_default = fbcon_set_def_font,
2799 .con_font_copy = fbcon_copy_font,
2800 .con_set_palette = fbcon_set_palette,
2801 .con_scrolldelta = fbcon_scrolldelta,
2802 .con_set_origin = fbcon_set_origin,
2803 .con_invert_region = fbcon_invert_region,
2804 .con_screen_pos = fbcon_screen_pos,
2805 .con_getxy = fbcon_getxy,
2806 .con_resize = fbcon_resize,
2809 static struct notifier_block fbcon_event_notifier = {
2810 .notifier_call = fbcon_event_notify,
2813 static int __init fb_console_init(void)
2817 acquire_console_sem();
2818 fb_register_client(&fbcon_event_notifier);
2819 release_console_sem();
2821 for (i = 0; i < MAX_NR_CONSOLES; i++)
2824 if (num_registered_fb) {
2825 for (i = 0; i < FB_MAX; i++) {
2826 if (registered_fb[i] != NULL) {
2837 module_init(fb_console_init);
2841 static void __exit fb_console_exit(void)
2843 acquire_console_sem();
2844 fb_unregister_client(&fbcon_event_notifier);
2845 release_console_sem();
2846 give_up_console(&fb_con);
2849 module_exit(fb_console_exit);
2853 MODULE_LICENSE("GPL");