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 signed char con2fb_map[MAX_NR_CONSOLES];
111 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 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 #define CM_SOFTBACK (8)
135 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
137 static void fbcon_free_font(struct display *);
138 static int fbcon_set_origin(struct vc_data *);
140 #define CURSOR_DRAW_DELAY (1)
142 /* # VBL ints between cursor state changes */
143 #define ARM_CURSOR_BLINK_RATE (10)
144 #define ATARI_CURSOR_BLINK_RATE (42)
145 #define MAC_CURSOR_BLINK_RATE (32)
146 #define DEFAULT_CURSOR_BLINK_RATE (20)
148 static int vbl_cursor_cnt;
150 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
153 * Interface used by the world
156 static const char *fbcon_startup(void);
157 static void fbcon_init(struct vc_data *vc, int init);
158 static void fbcon_deinit(struct vc_data *vc);
159 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
161 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
162 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
163 int count, int ypos, int xpos);
164 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
165 static void fbcon_cursor(struct vc_data *vc, int mode);
166 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
168 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
169 int height, int width);
170 static int fbcon_switch(struct vc_data *vc);
171 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
172 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
173 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
178 static __inline__ int real_y(struct display *p, int ypos);
179 static __inline__ void ywrap_up(struct vc_data *vc, int count);
180 static __inline__ void ywrap_down(struct vc_data *vc, int count);
181 static __inline__ void ypan_up(struct vc_data *vc, int count);
182 static __inline__ void ypan_down(struct vc_data *vc, int count);
183 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
184 int dy, int dx, int height, int width, u_int y_break);
185 static void fbcon_set_disp(struct fb_info *info, struct vc_data *vc);
186 static void fbcon_preset_disp(struct fb_info *info, int unit);
187 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
188 int line, int count, int dy);
192 * On the Macintoy, there may or may not be a working VBL int. We need to probe
194 static int vbl_detected;
196 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
203 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
205 return (info->state != FBINFO_STATE_RUNNING ||
206 vt_cons[vc->vc_num]->vc_mode != KD_TEXT);
209 static inline int get_color(struct vc_data *vc, struct fb_info *info,
212 int depth = fb_get_color_depth(info);
215 if (console_blanked) {
216 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
218 c = vc->vc_video_erase_char & charmask;
222 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
223 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
229 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? 1 : 0;
230 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : 1;
235 color = (is_fg) ? fg : bg;
240 * Scale down 16-colors to 4 colors. Default 4-color palette
247 * Last 8 entries of default 16-color palette is a more intense
248 * version of the first 8 (i.e., same chrominance, different
259 static void fb_flashcursor(void *private)
261 struct fb_info *info = private;
262 struct fbcon_ops *ops = info->fbcon_par;
264 struct vc_data *vc = NULL;
268 if (ops->currcon != -1)
269 vc = vc_cons[ops->currcon].d;
271 if (!vc || !CON_IS_VISIBLE(vc) ||
272 fbcon_is_inactive(vc, info) ||
273 registered_fb[con2fb_map[vc->vc_num]] != info)
275 acquire_console_sem();
276 p = &fb_display[vc->vc_num];
277 c = scr_readw((u16 *) vc->vc_pos);
278 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
280 ops->cursor(vc, info, p, mode, get_color(vc, info, c, 1),
281 get_color(vc, info, c, 0));
282 release_console_sem();
285 #if (defined(__arm__) && defined(IRQ_VSYNCPULSE)) || defined(CONFIG_ATARI) || defined(CONFIG_MAC)
286 static int cursor_blink_rate;
287 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
289 struct fb_info *info = dev_id;
291 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
292 schedule_work(&info->queue);
293 vbl_cursor_cnt = cursor_blink_rate;
299 static void cursor_timer_handler(unsigned long dev_addr)
301 struct fb_info *info = (struct fb_info *) dev_addr;
302 struct fbcon_ops *ops = info->fbcon_par;
304 schedule_work(&info->queue);
305 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
308 int __init fb_console_setup(char *this_opt)
313 if (!this_opt || !*this_opt)
316 while ((options = strsep(&this_opt, ",")) != NULL) {
317 if (!strncmp(options, "font:", 5))
318 strcpy(fontname, options + 5);
320 if (!strncmp(options, "scrollback:", 11)) {
323 fbcon_softback_size = simple_strtoul(options, &options, 0);
324 if (*options == 'k' || *options == 'K') {
325 fbcon_softback_size *= 1024;
335 if (!strncmp(options, "map:", 4)) {
338 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
342 (options[j++]-'0') % FB_MAX;
347 if (!strncmp(options, "vc:", 3)) {
350 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
353 if (*options++ == '-')
354 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
355 fbcon_is_default = 0;
361 __setup("fbcon=", fb_console_setup);
363 static int search_fb_in_map(int idx)
367 for (i = 0; i < MAX_NR_CONSOLES; i++) {
368 if (con2fb_map[i] == idx)
374 static int search_for_mapped_con(void)
378 for (i = 0; i < MAX_NR_CONSOLES; i++) {
379 if (con2fb_map[i] != -1)
385 static int fbcon_takeover(int show_logo)
389 if (!num_registered_fb)
393 logo_shown = FBCON_LOGO_DONTSHOW;
395 for (i = first_fb_vc; i <= last_fb_vc; i++)
396 con2fb_map[i] = info_idx;
398 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
401 for (i = first_fb_vc; i <= last_fb_vc; i++) {
410 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
411 int cols, int rows, int new_cols, int new_rows)
413 /* Need to make room for the logo */
414 int cnt, erase = vc->vc_video_erase_char, step;
415 unsigned short *save = NULL, *r, *q;
418 * remove underline attribute from erase character
419 * if black and white framebuffer.
421 if (fb_get_color_depth(info) == 1)
423 logo_height = fb_prepare_logo(info);
424 logo_lines = (logo_height + vc->vc_font.height - 1) /
426 q = (unsigned short *) (vc->vc_origin +
427 vc->vc_size_row * rows);
428 step = logo_lines * cols;
429 for (r = q - logo_lines * cols; r < q; r++)
430 if (scr_readw(r) != vc->vc_video_erase_char)
432 if (r != q && new_rows >= rows + logo_lines) {
433 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
435 int i = cols < new_cols ? cols : new_cols;
436 scr_memsetw(save, erase, logo_lines * new_cols * 2);
438 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
439 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
444 /* We can scroll screen down */
446 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
447 scr_memcpyw(r + step, r, vc->vc_size_row);
451 vc->vc_y += logo_lines;
452 vc->vc_pos += logo_lines * vc->vc_size_row;
455 scr_memsetw((unsigned short *) vc->vc_origin,
457 vc->vc_size_row * logo_lines);
459 if (CON_IS_VISIBLE(vc) && vt_cons[vc->vc_num]->vc_mode == KD_TEXT) {
460 fbcon_clear_margins(vc, 0);
461 update_screen(vc->vc_num);
465 q = (unsigned short *) (vc->vc_origin +
468 scr_memcpyw(q, save, logo_lines * new_cols * 2);
469 vc->vc_y += logo_lines;
470 vc->vc_pos += logo_lines * vc->vc_size_row;
474 if (logo_lines > vc->vc_bottom) {
475 logo_shown = FBCON_LOGO_CANSHOW;
477 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
478 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
479 logo_shown = FBCON_LOGO_DRAW;
480 vc->vc_top = logo_lines;
484 #ifdef CONFIG_FB_TILEBLITTING
485 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
488 struct fbcon_ops *ops = info->fbcon_par;
490 if ((info->flags & FBINFO_MISC_TILEBLITTING))
491 fbcon_set_tileops(vc, info, p, ops);
493 fbcon_set_bitops(ops);
496 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
499 struct fbcon_ops *ops = info->fbcon_par;
501 info->flags &= ~FBINFO_MISC_TILEBLITTING;
502 fbcon_set_bitops(ops);
504 #endif /* CONFIG_MISC_TILEBLITTING */
507 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
508 int unit, int oldidx)
510 struct fbcon_ops *ops = NULL;
513 if (!try_module_get(info->fbops->owner))
516 if (!err && info->fbops->fb_open &&
517 info->fbops->fb_open(info, 0))
521 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
527 memset(ops, 0, sizeof(struct fbcon_ops));
528 info->fbcon_par = ops;
529 set_blitting_type(vc, info, NULL);
533 con2fb_map[unit] = oldidx;
534 module_put(info->fbops->owner);
540 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
541 struct fb_info *newinfo, int unit,
542 int oldidx, int found)
544 struct fbcon_ops *ops = oldinfo->fbcon_par;
547 if (oldinfo->fbops->fb_release &&
548 oldinfo->fbops->fb_release(oldinfo, 0)) {
549 con2fb_map[unit] = oldidx;
550 if (!found && newinfo->fbops->fb_release)
551 newinfo->fbops->fb_release(newinfo, 0);
553 module_put(newinfo->fbops->owner);
558 if (oldinfo->queue.func == fb_flashcursor)
559 del_timer_sync(&ops->cursor_timer);
561 kfree(ops->cursor_state.mask);
562 kfree(ops->cursor_data);
563 kfree(oldinfo->fbcon_par);
564 oldinfo->fbcon_par = NULL;
565 module_put(oldinfo->fbops->owner);
571 static void con2fb_init_newinfo(struct fb_info *info)
573 if (!info->queue.func || info->queue.func == fb_flashcursor) {
574 struct fbcon_ops *ops = info->fbcon_par;
576 if (!info->queue.func)
577 INIT_WORK(&info->queue, fb_flashcursor, info);
579 init_timer(&ops->cursor_timer);
580 ops->cursor_timer.function = cursor_timer_handler;
581 ops->cursor_timer.expires = jiffies + HZ / 5;
582 ops->cursor_timer.data = (unsigned long ) info;
583 add_timer(&ops->cursor_timer);
587 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
588 int unit, int show_logo)
590 struct fbcon_ops *ops = info->fbcon_par;
592 ops->currcon = fg_console;
594 if (info->fbops->fb_set_par)
595 info->fbops->fb_set_par(info);
598 fbcon_set_disp(info, vc);
600 fbcon_preset_disp(info, unit);
603 struct vc_data *fg_vc = vc_cons[fg_console].d;
604 struct fb_info *fg_info =
605 registered_fb[con2fb_map[fg_console]];
607 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
608 fg_vc->vc_rows, fg_vc->vc_cols,
612 switch_screen(fg_console);
616 * set_con2fb_map - map console to frame buffer device
617 * @unit: virtual console number to map
618 * @newidx: frame buffer index to map virtual console to
619 * @user: user request
621 * Maps a virtual console @unit to a frame buffer device
624 static int set_con2fb_map(int unit, int newidx, int user)
626 struct vc_data *vc = vc_cons[unit].d;
627 int oldidx = con2fb_map[unit];
628 struct fb_info *info = registered_fb[newidx];
629 struct fb_info *oldinfo = NULL;
632 if (oldidx == newidx)
638 if (!err && !search_for_mapped_con()) {
640 return fbcon_takeover(0);
644 oldinfo = registered_fb[oldidx];
646 found = search_fb_in_map(newidx);
648 acquire_console_sem();
649 con2fb_map[unit] = newidx;
651 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
655 * If old fb is not mapped to any of the consoles,
656 * fbcon should release it.
658 if (!err && oldinfo && !search_fb_in_map(oldidx))
659 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
663 int show_logo = (fg_console == 0 && !user &&
664 logo_shown != FBCON_LOGO_DONTSHOW);
667 con2fb_init_newinfo(info);
668 con2fb_map_boot[unit] = newidx;
669 con2fb_init_display(vc, info, unit, show_logo);
672 release_console_sem();
677 * Low Level Operations
679 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
680 static int var_to_display(struct display *disp,
681 struct fb_var_screeninfo *var,
682 struct fb_info *info)
684 disp->xres_virtual = var->xres_virtual;
685 disp->yres_virtual = var->yres_virtual;
686 disp->bits_per_pixel = var->bits_per_pixel;
687 disp->grayscale = var->grayscale;
688 disp->nonstd = var->nonstd;
689 disp->accel_flags = var->accel_flags;
690 disp->height = var->height;
691 disp->width = var->width;
692 disp->red = var->red;
693 disp->green = var->green;
694 disp->blue = var->blue;
695 disp->transp = var->transp;
696 disp->mode = fb_match_mode(var, &info->modelist);
697 if (disp->mode == NULL)
698 /* This should not happen */
703 static void display_to_var(struct fb_var_screeninfo *var,
704 struct display *disp)
706 fb_videomode_to_var(var, disp->mode);
707 var->xres_virtual = disp->xres_virtual;
708 var->yres_virtual = disp->yres_virtual;
709 var->bits_per_pixel = disp->bits_per_pixel;
710 var->grayscale = disp->grayscale;
711 var->nonstd = disp->nonstd;
712 var->accel_flags = disp->accel_flags;
713 var->height = disp->height;
714 var->width = disp->width;
715 var->red = disp->red;
716 var->green = disp->green;
717 var->blue = disp->blue;
718 var->transp = disp->transp;
721 static const char *fbcon_startup(void)
723 const char *display_desc = "frame buffer device";
724 struct display *p = &fb_display[fg_console];
725 struct vc_data *vc = vc_cons[fg_console].d;
726 struct font_desc *font = NULL;
727 struct module *owner;
728 struct fb_info *info = NULL;
729 struct fbcon_ops *ops;
735 * If num_registered_fb is zero, this is a call for the dummy part.
736 * The frame buffer devices weren't initialized yet.
738 if (!num_registered_fb || info_idx == -1)
741 * Instead of blindly using registered_fb[0], we use info_idx, set by
744 info = registered_fb[info_idx];
748 owner = info->fbops->owner;
749 if (!try_module_get(owner))
751 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
756 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
762 memset(ops, 0, sizeof(struct fbcon_ops));
764 info->fbcon_par = ops;
765 set_blitting_type(vc, info, NULL);
767 if (info->fix.type != FB_TYPE_TEXT) {
768 if (fbcon_softback_size) {
772 kmalloc(fbcon_softback_size,
775 fbcon_softback_size = 0;
781 kfree((void *) softback_buf);
787 softback_in = softback_top = softback_curr =
792 /* Setup default font */
794 if (!fontname[0] || !(font = find_font(fontname)))
795 font = get_default_font(info->var.xres,
797 vc->vc_font.width = font->width;
798 vc->vc_font.height = font->height;
799 vc->vc_font.data = p->fontdata = font->data;
800 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
803 cols = info->var.xres / vc->vc_font.width;
804 rows = info->var.yres / vc->vc_font.height;
805 vc_resize(vc->vc_num, cols, rows);
807 DPRINTK("mode: %s\n", info->fix.id);
808 DPRINTK("visual: %d\n", info->fix.visual);
809 DPRINTK("res: %dx%d-%d\n", info->var.xres,
811 info->var.bits_per_pixel);
815 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
817 request_irq(IRQ_AUTO_4, fb_vbl_handler,
818 IRQ_TYPE_PRIO, "framebuffer vbl",
821 #endif /* CONFIG_ATARI */
825 * On a Macintoy, the VBL interrupt may or may not be active.
826 * As interrupt based cursor is more reliable and race free, we
827 * probe for VBL interrupts.
832 * Probe for VBL: set temp. handler ...
834 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
835 "framebuffer vbl", info);
839 * ... and spin for 20 ms ...
841 while (!vbl_detected && ++ct < 1000)
846 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
848 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
852 * interrupt based cursor ok
854 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
856 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
857 "framebuffer vbl", info);
860 * VBL not detected: fall through, use timer based cursor
865 #endif /* CONFIG_MAC */
867 #if defined(__arm__) && defined(IRQ_VSYNCPULSE)
868 cursor_blink_rate = ARM_CURSOR_BLINK_RATE;
869 irqres = request_irq(IRQ_VSYNCPULSE, fb_vbl_handler, SA_SHIRQ,
870 "framebuffer vbl", info);
872 /* Initialize the work queue. If the driver provides its
873 * own work queue this means it will use something besides
874 * default timer to flash the cursor. */
875 if (!info->queue.func) {
876 INIT_WORK(&info->queue, fb_flashcursor, info);
878 init_timer(&ops->cursor_timer);
879 ops->cursor_timer.function = cursor_timer_handler;
880 ops->cursor_timer.expires = jiffies + HZ / 5;
881 ops->cursor_timer.data = (unsigned long ) info;
882 add_timer(&ops->cursor_timer);
887 static void fbcon_init(struct vc_data *vc, int init)
889 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
890 struct vc_data **default_mode = vc->vc_display_fg;
891 struct vc_data *svc = *default_mode;
892 struct display *t, *p = &fb_display[vc->vc_num];
893 int display_fg = (*default_mode)->vc_num;
894 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
895 int cap = info->flags;
897 if (info_idx == -1 || info == NULL)
899 if (vc->vc_num != display_fg || logo_shown == FBCON_LOGO_DONTSHOW ||
900 (info->fix.type == FB_TYPE_TEXT))
903 info->var.xoffset = info->var.yoffset = p->yscroll = 0; /* reset wrap/pan */
905 if (var_to_display(p, &info->var, info))
908 /* If we are not the first console on this
909 fb, copy the font from that console */
910 t = &fb_display[display_fg];
911 if (!vc->vc_font.data) {
912 vc->vc_font.data = p->fontdata = t->fontdata;
913 vc->vc_font.width = (*default_mode)->vc_font.width;
914 vc->vc_font.height = (*default_mode)->vc_font.height;
915 p->userfont = t->userfont;
917 REFCOUNT(p->fontdata)++;
920 charcnt = FNTCHARCNT(p->fontdata);
921 vc->vc_can_do_color = (fb_get_color_depth(info) != 1);
922 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
923 if (charcnt == 256) {
924 vc->vc_hi_font_mask = 0;
926 vc->vc_hi_font_mask = 0x100;
927 if (vc->vc_can_do_color)
928 vc->vc_complement_mask <<= 1;
931 if (!*svc->vc_uni_pagedir_loc)
932 con_set_default_unimap(display_fg);
933 if (!*vc->vc_uni_pagedir_loc)
934 con_copy_unimap(vc->vc_num, display_fg);
938 new_cols = info->var.xres / vc->vc_font.width;
939 new_rows = info->var.yres / vc->vc_font.height;
940 vc_resize(vc->vc_num, new_cols, new_rows);
942 * We must always set the mode. The mode of the previous console
943 * driver could be in the same resolution but we are using different
944 * hardware so we have to initialize the hardware.
946 * We need to do it in fbcon_init() to prevent screen corruption.
948 if (CON_IS_VISIBLE(vc) && info->fbops->fb_set_par)
949 info->fbops->fb_set_par(info);
952 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
953 !(cap & FBINFO_HWACCEL_DISABLED))
954 p->scrollmode = SCROLL_MOVE;
955 else /* default to something safe */
956 p->scrollmode = SCROLL_REDRAW;
959 * ++guenther: console.c:vc_allocate() relies on initializing
960 * vc_{cols,rows}, but we must not set those if we are only
961 * resizing the console.
964 vc->vc_cols = new_cols;
965 vc->vc_rows = new_rows;
969 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
971 if (vc->vc_num == display_fg && softback_buf) {
972 int l = fbcon_softback_size / vc->vc_size_row;
974 softback_end = softback_buf + l * vc->vc_size_row;
976 /* Smaller scrollback makes no sense, and 0 would screw
977 the operation totally */
983 static void fbcon_deinit(struct vc_data *vc)
985 struct display *p = &fb_display[vc->vc_num];
992 /* ====================================================================== */
994 /* fbcon_XXX routines - interface used by the world
996 * This system is now divided into two levels because of complications
997 * caused by hardware scrolling. Top level functions:
999 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1001 * handles y values in range [0, scr_height-1] that correspond to real
1002 * screen positions. y_wrap shift means that first line of bitmap may be
1003 * anywhere on this display. These functions convert lineoffsets to
1004 * bitmap offsets and deal with the wrap-around case by splitting blits.
1006 * fbcon_bmove_physical_8() -- These functions fast implementations
1007 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1008 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1012 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1013 * Implies should only really hardware scroll in rows. Only reason for
1014 * restriction is simplicity & efficiency at the moment.
1017 static __inline__ int real_y(struct display *p, int ypos)
1019 int rows = p->vrows;
1022 return ypos < rows ? ypos : ypos - rows;
1026 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1029 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1030 struct fbcon_ops *ops = info->fbcon_par;
1032 struct display *p = &fb_display[vc->vc_num];
1035 if (fbcon_is_inactive(vc, info))
1038 if (!height || !width)
1041 /* Split blits that cross physical y_wrap boundary */
1043 y_break = p->vrows - p->yscroll;
1044 if (sy < y_break && sy + height - 1 >= y_break) {
1045 u_int b = y_break - sy;
1046 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1047 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1050 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1053 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1054 int count, int ypos, int xpos)
1056 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1057 struct display *p = &fb_display[vc->vc_num];
1058 struct fbcon_ops *ops = info->fbcon_par;
1060 if (!fbcon_is_inactive(vc, info))
1061 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1062 get_color(vc, info, scr_readw(s), 1),
1063 get_color(vc, info, scr_readw(s), 0));
1066 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1070 scr_writew(c, &chr);
1071 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1074 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1076 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1077 struct fbcon_ops *ops = info->fbcon_par;
1079 if (!fbcon_is_inactive(vc, info))
1080 ops->clear_margins(vc, info, bottom_only);
1083 static void fbcon_cursor(struct vc_data *vc, int mode)
1085 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1086 struct fbcon_ops *ops = info->fbcon_par;
1087 struct display *p = &fb_display[vc->vc_num];
1088 int y = real_y(p, vc->vc_y);
1089 int c = scr_readw((u16 *) vc->vc_pos);
1091 if (fbcon_is_inactive(vc, info))
1094 ops->cursor_flash = 1;
1095 if (mode & CM_SOFTBACK) {
1096 mode &= ~CM_SOFTBACK;
1097 if (softback_lines) {
1098 if (y + softback_lines >= vc->vc_rows) {
1100 ops->cursor_flash = 0;
1103 y += softback_lines;
1105 } else if (softback_lines)
1106 fbcon_set_origin(vc);
1108 ops->cursor(vc, info, p, mode, get_color(vc, info, c, 1),
1109 get_color(vc, info, c, 0));
1110 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1113 static int scrollback_phys_max = 0;
1114 static int scrollback_max = 0;
1115 static int scrollback_current = 0;
1117 int update_var(int con, struct fb_info *info)
1119 if (con == ((struct fbcon_ops *)info->fbcon_par)->currcon)
1120 return fb_pan_display(info, &info->var);
1125 * If no vc is existent yet, just set struct display
1127 static void fbcon_preset_disp(struct fb_info *info, int unit)
1129 struct display *p = &fb_display[unit];
1130 struct display *t = &fb_display[fg_console];
1132 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
1133 if (var_to_display(p, &info->var, info))
1136 p->fontdata = t->fontdata;
1137 p->userfont = t->userfont;
1139 REFCOUNT(p->fontdata)++;
1142 static void fbcon_set_disp(struct fb_info *info, struct vc_data *vc)
1144 struct display *p = &fb_display[vc->vc_num], *t;
1145 struct vc_data **default_mode = vc->vc_display_fg;
1146 struct vc_data *svc = *default_mode;
1147 int display_fg = (*default_mode)->vc_num;
1148 int rows, cols, charcnt = 256;
1150 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
1151 if (var_to_display(p, &info->var, info))
1153 t = &fb_display[display_fg];
1154 if (!vc->vc_font.data) {
1155 vc->vc_font.data = p->fontdata = t->fontdata;
1156 vc->vc_font.width = (*default_mode)->vc_font.width;
1157 vc->vc_font.height = (*default_mode)->vc_font.height;
1158 p->userfont = t->userfont;
1160 REFCOUNT(p->fontdata)++;
1163 charcnt = FNTCHARCNT(p->fontdata);
1165 vc->vc_can_do_color = (fb_get_color_depth(info) != 1);
1166 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1167 if (charcnt == 256) {
1168 vc->vc_hi_font_mask = 0;
1170 vc->vc_hi_font_mask = 0x100;
1171 if (vc->vc_can_do_color)
1172 vc->vc_complement_mask <<= 1;
1175 if (!*svc->vc_uni_pagedir_loc)
1176 con_set_default_unimap(display_fg);
1177 if (!*vc->vc_uni_pagedir_loc)
1178 con_copy_unimap(vc->vc_num, display_fg);
1180 cols = info->var.xres / vc->vc_font.width;
1181 rows = info->var.yres / vc->vc_font.height;
1182 vc_resize(vc->vc_num, cols, rows);
1183 if (CON_IS_VISIBLE(vc)) {
1184 update_screen(vc->vc_num);
1186 int l = fbcon_softback_size / vc->vc_size_row;
1189 softback_end = softback_buf + l *
1192 /* Smaller scrollback makes no sense, and 0
1193 would screw the operation totally */
1200 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1202 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1203 struct display *p = &fb_display[vc->vc_num];
1205 p->yscroll += count;
1206 if (p->yscroll >= p->vrows) /* Deal with wrap */
1207 p->yscroll -= p->vrows;
1208 info->var.xoffset = 0;
1209 info->var.yoffset = p->yscroll * vc->vc_font.height;
1210 info->var.vmode |= FB_VMODE_YWRAP;
1211 update_var(vc->vc_num, info);
1212 scrollback_max += count;
1213 if (scrollback_max > scrollback_phys_max)
1214 scrollback_max = scrollback_phys_max;
1215 scrollback_current = 0;
1218 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1220 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1221 struct display *p = &fb_display[vc->vc_num];
1223 p->yscroll -= count;
1224 if (p->yscroll < 0) /* Deal with wrap */
1225 p->yscroll += p->vrows;
1226 info->var.xoffset = 0;
1227 info->var.yoffset = p->yscroll * vc->vc_font.height;
1228 info->var.vmode |= FB_VMODE_YWRAP;
1229 update_var(vc->vc_num, info);
1230 scrollback_max -= count;
1231 if (scrollback_max < 0)
1233 scrollback_current = 0;
1236 static __inline__ void ypan_up(struct vc_data *vc, int count)
1238 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1239 struct display *p = &fb_display[vc->vc_num];
1240 struct fbcon_ops *ops = info->fbcon_par;
1242 p->yscroll += count;
1243 if (p->yscroll > p->vrows - vc->vc_rows) {
1244 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1245 0, 0, 0, vc->vc_rows, vc->vc_cols);
1246 p->yscroll -= p->vrows - vc->vc_rows;
1248 info->var.xoffset = 0;
1249 info->var.yoffset = p->yscroll * vc->vc_font.height;
1250 info->var.vmode &= ~FB_VMODE_YWRAP;
1251 update_var(vc->vc_num, info);
1252 fbcon_clear_margins(vc, 1);
1253 scrollback_max += count;
1254 if (scrollback_max > scrollback_phys_max)
1255 scrollback_max = scrollback_phys_max;
1256 scrollback_current = 0;
1259 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1261 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1262 struct display *p = &fb_display[vc->vc_num];
1265 p->yscroll += count;
1266 if (p->yscroll > p->vrows - vc->vc_rows) {
1267 p->yscroll -= p->vrows - vc->vc_rows;
1271 info->var.xoffset = 0;
1272 info->var.yoffset = p->yscroll * vc->vc_font.height;
1273 info->var.vmode &= ~FB_VMODE_YWRAP;
1275 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1276 update_var(vc->vc_num, info);
1277 fbcon_clear_margins(vc, 1);
1278 scrollback_max += count;
1279 if (scrollback_max > scrollback_phys_max)
1280 scrollback_max = scrollback_phys_max;
1281 scrollback_current = 0;
1284 static __inline__ void ypan_down(struct vc_data *vc, int count)
1286 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1287 struct display *p = &fb_display[vc->vc_num];
1288 struct fbcon_ops *ops = info->fbcon_par;
1290 p->yscroll -= count;
1291 if (p->yscroll < 0) {
1292 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1293 0, vc->vc_rows, vc->vc_cols);
1294 p->yscroll += p->vrows - vc->vc_rows;
1296 info->var.xoffset = 0;
1297 info->var.yoffset = p->yscroll * vc->vc_font.height;
1298 info->var.vmode &= ~FB_VMODE_YWRAP;
1299 update_var(vc->vc_num, info);
1300 fbcon_clear_margins(vc, 1);
1301 scrollback_max -= count;
1302 if (scrollback_max < 0)
1304 scrollback_current = 0;
1307 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1309 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1310 struct display *p = &fb_display[vc->vc_num];
1313 p->yscroll -= count;
1314 if (p->yscroll < 0) {
1315 p->yscroll += p->vrows - vc->vc_rows;
1318 info->var.xoffset = 0;
1319 info->var.yoffset = p->yscroll * vc->vc_font.height;
1320 info->var.vmode &= ~FB_VMODE_YWRAP;
1322 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1323 update_var(vc->vc_num, info);
1324 fbcon_clear_margins(vc, 1);
1325 scrollback_max -= count;
1326 if (scrollback_max < 0)
1328 scrollback_current = 0;
1331 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1334 int count = vc->vc_rows;
1335 unsigned short *d, *s;
1339 d = (u16 *) softback_curr;
1340 if (d == (u16 *) softback_in)
1341 d = (u16 *) vc->vc_origin;
1342 n = softback_curr + delta * vc->vc_size_row;
1343 softback_lines -= delta;
1345 if (softback_curr < softback_top && n < softback_buf) {
1346 n += softback_end - softback_buf;
1347 if (n < softback_top) {
1349 (softback_top - n) / vc->vc_size_row;
1352 } else if (softback_curr >= softback_top
1353 && n < softback_top) {
1355 (softback_top - n) / vc->vc_size_row;
1359 if (softback_curr > softback_in && n >= softback_end) {
1360 n += softback_buf - softback_end;
1361 if (n > softback_in) {
1365 } else if (softback_curr <= softback_in && n > softback_in) {
1370 if (n == softback_curr)
1373 s = (u16 *) softback_curr;
1374 if (s == (u16 *) softback_in)
1375 s = (u16 *) vc->vc_origin;
1377 unsigned short *start;
1381 unsigned short attr = 1;
1384 le = advance_row(s, 1);
1387 if (attr != (c & 0xff00)) {
1390 fbcon_putcs(vc, start, s - start,
1396 if (c == scr_readw(d)) {
1398 fbcon_putcs(vc, start, s - start,
1411 fbcon_putcs(vc, start, s - start, line, x);
1413 if (d == (u16 *) softback_end)
1414 d = (u16 *) softback_buf;
1415 if (d == (u16 *) softback_in)
1416 d = (u16 *) vc->vc_origin;
1417 if (s == (u16 *) softback_end)
1418 s = (u16 *) softback_buf;
1419 if (s == (u16 *) softback_in)
1420 s = (u16 *) vc->vc_origin;
1424 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1425 int line, int count, int dy)
1427 unsigned short *s = (unsigned short *)
1428 (vc->vc_origin + vc->vc_size_row * line);
1431 unsigned short *start = s;
1432 unsigned short *le = advance_row(s, 1);
1435 unsigned short attr = 1;
1439 if (attr != (c & 0xff00)) {
1442 fbcon_putcs(vc, start, s - start,
1448 console_conditional_schedule();
1452 fbcon_putcs(vc, start, s - start, dy, x);
1453 console_conditional_schedule();
1458 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1459 int line, int count, int offset)
1461 unsigned short *d = (unsigned short *)
1462 (vc->vc_origin + vc->vc_size_row * line);
1463 unsigned short *s = d + offset;
1466 unsigned short *start = s;
1467 unsigned short *le = advance_row(s, 1);
1470 unsigned short attr = 1;
1474 if (attr != (c & 0xff00)) {
1477 fbcon_putcs(vc, start, s - start,
1483 if (c == scr_readw(d)) {
1485 fbcon_putcs(vc, start, s - start,
1495 console_conditional_schedule();
1500 fbcon_putcs(vc, start, s - start, line, x);
1501 console_conditional_schedule();
1506 /* NOTE: We subtract two lines from these pointers */
1507 s -= vc->vc_size_row;
1508 d -= vc->vc_size_row;
1513 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1518 if (vc->vc_num != fg_console)
1520 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1523 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1525 p = advance_row(p, 1);
1526 softback_in += vc->vc_size_row;
1527 if (softback_in == softback_end)
1528 softback_in = softback_buf;
1529 if (softback_in == softback_top) {
1530 softback_top += vc->vc_size_row;
1531 if (softback_top == softback_end)
1532 softback_top = softback_buf;
1535 softback_curr = softback_in;
1538 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1541 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1542 struct display *p = &fb_display[vc->vc_num];
1543 struct fbcon_ops *ops = info->fbcon_par;
1544 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1546 if (fbcon_is_inactive(vc, info))
1549 fbcon_cursor(vc, CM_ERASE);
1552 * ++Geert: Only use ywrap/ypan if the console is in text mode
1553 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1554 * whole screen (prevents flicker).
1559 if (count > vc->vc_rows) /* Maximum realistic size */
1560 count = vc->vc_rows;
1562 fbcon_softback_note(vc, t, count);
1563 if (logo_shown >= 0)
1565 switch (p->scrollmode) {
1567 ops->bmove(vc, info, t + count, 0, t, 0,
1568 b - t - count, vc->vc_cols);
1569 ops->clear(vc, info, b - count, 0, count,
1573 case SCROLL_WRAP_MOVE:
1574 if (b - t - count > 3 * vc->vc_rows >> 2) {
1576 fbcon_bmove(vc, 0, 0, count, 0, t,
1578 ywrap_up(vc, count);
1579 if (vc->vc_rows - b > 0)
1580 fbcon_bmove(vc, b - count, 0, b, 0,
1583 } else if (info->flags & FBINFO_READS_FAST)
1584 fbcon_bmove(vc, t + count, 0, t, 0,
1585 b - t - count, vc->vc_cols);
1588 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1591 case SCROLL_PAN_REDRAW:
1592 if ((p->yscroll + count <=
1593 2 * (p->vrows - vc->vc_rows))
1594 && ((!scroll_partial && (b - t == vc->vc_rows))
1597 3 * vc->vc_rows >> 2)))) {
1599 fbcon_redraw_move(vc, p, 0, t, count);
1600 ypan_up_redraw(vc, t, count);
1601 if (vc->vc_rows - b > 0)
1602 fbcon_redraw_move(vc, p, b - count,
1603 vc->vc_rows - b, b);
1605 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1606 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1609 case SCROLL_PAN_MOVE:
1610 if ((p->yscroll + count <=
1611 2 * (p->vrows - vc->vc_rows))
1612 && ((!scroll_partial && (b - t == vc->vc_rows))
1615 3 * vc->vc_rows >> 2)))) {
1617 fbcon_bmove(vc, 0, 0, count, 0, t,
1620 if (vc->vc_rows - b > 0)
1621 fbcon_bmove(vc, b - count, 0, b, 0,
1624 } else if (info->flags & FBINFO_READS_FAST)
1625 fbcon_bmove(vc, t + count, 0, t, 0,
1626 b - t - count, vc->vc_cols);
1629 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1634 fbcon_redraw(vc, p, t, b - t - count,
1635 count * vc->vc_cols);
1636 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1637 scr_memsetw((unsigned short *) (vc->vc_origin +
1640 vc->vc_video_erase_char,
1641 vc->vc_size_row * count);
1647 if (count > vc->vc_rows) /* Maximum realistic size */
1648 count = vc->vc_rows;
1649 switch (p->scrollmode) {
1651 ops->bmove(vc, info, t, 0, t + count, 0,
1652 b - t - count, vc->vc_cols);
1653 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1656 case SCROLL_WRAP_MOVE:
1657 if (b - t - count > 3 * vc->vc_rows >> 2) {
1658 if (vc->vc_rows - b > 0)
1659 fbcon_bmove(vc, b, 0, b - count, 0,
1662 ywrap_down(vc, count);
1664 fbcon_bmove(vc, count, 0, 0, 0, t,
1666 } else if (info->flags & FBINFO_READS_FAST)
1667 fbcon_bmove(vc, t, 0, t + count, 0,
1668 b - t - count, vc->vc_cols);
1671 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1674 case SCROLL_PAN_MOVE:
1675 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1676 && ((!scroll_partial && (b - t == vc->vc_rows))
1679 3 * vc->vc_rows >> 2)))) {
1680 if (vc->vc_rows - b > 0)
1681 fbcon_bmove(vc, b, 0, b - count, 0,
1684 ypan_down(vc, count);
1686 fbcon_bmove(vc, count, 0, 0, 0, t,
1688 } else if (info->flags & FBINFO_READS_FAST)
1689 fbcon_bmove(vc, t, 0, t + count, 0,
1690 b - t - count, vc->vc_cols);
1693 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1696 case SCROLL_PAN_REDRAW:
1697 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1698 && ((!scroll_partial && (b - t == vc->vc_rows))
1701 3 * vc->vc_rows >> 2)))) {
1702 if (vc->vc_rows - b > 0)
1703 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1705 ypan_down_redraw(vc, t, count);
1707 fbcon_redraw_move(vc, p, count, t, 0);
1709 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1710 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1715 fbcon_redraw(vc, p, b - 1, b - t - count,
1716 -count * vc->vc_cols);
1717 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1718 scr_memsetw((unsigned short *) (vc->vc_origin +
1721 vc->vc_video_erase_char,
1722 vc->vc_size_row * count);
1730 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1731 int height, int width)
1733 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1734 struct display *p = &fb_display[vc->vc_num];
1736 if (fbcon_is_inactive(vc, info))
1739 if (!width || !height)
1742 /* Split blits that cross physical y_wrap case.
1743 * Pathological case involves 4 blits, better to use recursive
1744 * code rather than unrolled case
1746 * Recursive invocations don't need to erase the cursor over and
1747 * over again, so we use fbcon_bmove_rec()
1749 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1750 p->vrows - p->yscroll);
1753 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1754 int dy, int dx, int height, int width, u_int y_break)
1756 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1757 struct fbcon_ops *ops = info->fbcon_par;
1760 if (sy < y_break && sy + height > y_break) {
1762 if (dy < sy) { /* Avoid trashing self */
1763 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1765 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1766 height - b, width, y_break);
1768 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1769 height - b, width, y_break);
1770 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1776 if (dy < y_break && dy + height > y_break) {
1778 if (dy < sy) { /* Avoid trashing self */
1779 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1781 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1782 height - b, width, y_break);
1784 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1785 height - b, width, y_break);
1786 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1791 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1795 static __inline__ void updatescrollmode(struct display *p, struct fb_info *info,
1798 int fh = vc->vc_font.height;
1799 int cap = info->flags;
1800 int good_pan = (cap & FBINFO_HWACCEL_YPAN)
1801 && divides(info->fix.ypanstep, vc->vc_font.height)
1802 && info->var.yres_virtual > info->var.yres;
1803 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP)
1804 && divides(info->fix.ywrapstep, vc->vc_font.height)
1805 && divides(vc->vc_font.height, info->var.yres_virtual);
1806 int reading_fast = cap & FBINFO_READS_FAST;
1807 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) && !(cap & FBINFO_HWACCEL_DISABLED);
1808 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) && !(cap & FBINFO_HWACCEL_DISABLED);
1810 p->vrows = info->var.yres_virtual/fh;
1811 if (info->var.yres > (fh * (vc->vc_rows + 1)))
1812 p->vrows -= (info->var.yres - (fh * vc->vc_rows)) / fh;
1813 if ((info->var.yres % fh) && (info->var.yres_virtual % fh <
1814 info->var.yres % fh))
1817 if (good_wrap || good_pan) {
1818 if (reading_fast || fast_copyarea)
1819 p->scrollmode = good_wrap ? SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1821 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1824 if (reading_fast || (fast_copyarea && !fast_imageblit))
1825 p->scrollmode = SCROLL_MOVE;
1827 p->scrollmode = SCROLL_REDRAW;
1831 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1832 unsigned int height)
1834 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1835 struct display *p = &fb_display[vc->vc_num];
1836 struct fb_var_screeninfo var = info->var;
1838 int fw = vc->vc_font.width;
1839 int fh = vc->vc_font.height;
1841 var.xres = width * fw;
1842 var.yres = height * fh;
1843 x_diff = info->var.xres - var.xres;
1844 y_diff = info->var.yres - var.yres;
1845 if (x_diff < 0 || x_diff > fw || (y_diff < 0 || y_diff > fh)) {
1846 struct fb_videomode *mode;
1848 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
1849 mode = fb_find_best_mode(&var, &info->modelist);
1852 fb_videomode_to_var(&var, mode);
1853 if (width > var.xres/fw || height > var.yres/fh)
1856 * The following can probably have any value... Do we need to
1859 var.bits_per_pixel = p->bits_per_pixel;
1860 var.xres_virtual = p->xres_virtual;
1861 var.yres_virtual = p->yres_virtual;
1862 var.accel_flags = p->accel_flags;
1863 var.width = p->width;
1864 var.height = p->height;
1866 var.green = p->green;
1868 var.transp = p->transp;
1869 var.nonstd = p->nonstd;
1871 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
1872 if (CON_IS_VISIBLE(vc)) {
1873 var.activate = FB_ACTIVATE_NOW |
1875 fb_set_var(info, &var);
1876 info->flags &= ~FBINFO_MISC_MODESWITCH;
1878 var_to_display(p, &info->var, info);
1880 updatescrollmode(p, info, vc);
1884 static int fbcon_switch(struct vc_data *vc)
1886 struct fb_info *info;
1887 struct display *p = &fb_display[vc->vc_num];
1888 struct fb_var_screeninfo var;
1889 int i, prev_console, do_set_par = 0;
1891 info = registered_fb[con2fb_map[vc->vc_num]];
1894 int l = fbcon_softback_size / vc->vc_size_row;
1896 fbcon_set_origin(vc);
1897 softback_top = softback_curr = softback_in = softback_buf;
1901 softback_end = softback_buf + l * vc->vc_size_row;
1903 /* Smaller scrollback makes no sense, and 0 would screw
1904 the operation totally */
1909 if (logo_shown >= 0) {
1910 struct vc_data *conp2 = vc_cons[logo_shown].d;
1912 if (conp2->vc_top == logo_lines
1913 && conp2->vc_bottom == conp2->vc_rows)
1915 logo_shown = FBCON_LOGO_CANSHOW;
1918 prev_console = ((struct fbcon_ops *)info->fbcon_par)->currcon;
1921 * FIXME: If we have multiple fbdev's loaded, we need to
1922 * update all info->currcon. Perhaps, we can place this
1923 * in a centralized structure, but this might break some
1926 * info->currcon = vc->vc_num;
1928 for (i = 0; i < FB_MAX; i++) {
1929 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
1930 struct fbcon_ops *ops = registered_fb[i]->fbcon_par;
1932 ops->currcon = vc->vc_num;
1935 memset(&var, 0, sizeof(struct fb_var_screeninfo));
1936 display_to_var(&var, p);
1937 var.activate = FB_ACTIVATE_NOW;
1940 * make sure we don't unnecessarily trip the memcmp()
1943 info->var.activate = var.activate;
1944 info->var.yoffset = info->var.xoffset = p->yscroll = 0;
1945 fb_set_var(info, &var);
1947 if (prev_console != -1 &&
1948 registered_fb[con2fb_map[prev_console]] != info)
1951 if (do_set_par || info->flags & FBINFO_MISC_MODESWITCH) {
1952 if (info->fbops->fb_set_par)
1953 info->fbops->fb_set_par(info);
1954 info->flags &= ~FBINFO_MISC_MODESWITCH;
1957 set_blitting_type(vc, info, p);
1958 ((struct fbcon_ops *)info->fbcon_par)->cursor_reset = 1;
1960 vc->vc_can_do_color = (fb_get_color_depth(info) != 1);
1961 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1962 updatescrollmode(p, info, vc);
1964 switch (p->scrollmode) {
1965 case SCROLL_WRAP_MOVE:
1966 scrollback_phys_max = p->vrows - vc->vc_rows;
1968 case SCROLL_PAN_MOVE:
1969 case SCROLL_PAN_REDRAW:
1970 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
1971 if (scrollback_phys_max < 0)
1972 scrollback_phys_max = 0;
1975 scrollback_phys_max = 0;
1979 scrollback_current = 0;
1981 update_var(vc->vc_num, info);
1982 fbcon_set_palette(vc, color_table);
1983 fbcon_clear_margins(vc, 0);
1985 if (logo_shown == FBCON_LOGO_DRAW) {
1987 logo_shown = fg_console;
1988 /* This is protected above by initmem_freed */
1990 update_region(fg_console,
1991 vc->vc_origin + vc->vc_size_row * vc->vc_top,
1992 vc->vc_size_row * (vc->vc_bottom -
1999 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2003 unsigned short charmask = vc->vc_hi_font_mask ?
2005 unsigned short oldc;
2007 oldc = vc->vc_video_erase_char;
2008 vc->vc_video_erase_char &= charmask;
2009 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2010 vc->vc_video_erase_char = oldc;
2014 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2016 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2017 struct fbcon_ops *ops = info->fbcon_par;
2018 int active = !fbcon_is_inactive(vc, info);
2021 struct fb_var_screeninfo var = info->var;
2023 * HACK ALERT: Some hardware will require reinitializion at this stage,
2024 * others will require it to be done as late as possible.
2025 * For now, we differentiate this with the
2026 * FBINFO_MISC_MODESWITCHLATE bitflag. Worst case will be
2027 * hardware that requires it here and another one later.
2028 * A definitive solution may require fixing X or the VT
2031 if (info->flags & FBINFO_MISC_MODESWITCHLATE)
2032 info->flags |= FBINFO_MISC_MODESWITCH;
2034 if (!blank && !(info->flags & FBINFO_MISC_MODESWITCHLATE)) {
2035 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2036 fb_set_var(info, &var);
2041 if (ops->blank_state != blank) {
2042 ops->blank_state = blank;
2043 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2044 ops->cursor_flash = (!blank);
2046 if (fb_blank(info, blank))
2047 fbcon_generic_blank(vc, info, blank);
2051 update_screen(vc->vc_num);
2057 static void fbcon_free_font(struct display *p)
2059 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2060 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2065 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2067 u8 *fontdata = vc->vc_font.data;
2068 u8 *data = font->data;
2071 font->width = vc->vc_font.width;
2072 font->height = vc->vc_font.height;
2073 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2077 if (font->width <= 8) {
2078 j = vc->vc_font.height;
2079 for (i = 0; i < font->charcount; i++) {
2080 memcpy(data, fontdata, j);
2081 memset(data + j, 0, 32 - j);
2085 } else if (font->width <= 16) {
2086 j = vc->vc_font.height * 2;
2087 for (i = 0; i < font->charcount; i++) {
2088 memcpy(data, fontdata, j);
2089 memset(data + j, 0, 64 - j);
2093 } else if (font->width <= 24) {
2094 for (i = 0; i < font->charcount; i++) {
2095 for (j = 0; j < vc->vc_font.height; j++) {
2096 *data++ = fontdata[0];
2097 *data++ = fontdata[1];
2098 *data++ = fontdata[2];
2099 fontdata += sizeof(u32);
2101 memset(data, 0, 3 * (32 - j));
2102 data += 3 * (32 - j);
2105 j = vc->vc_font.height * 4;
2106 for (i = 0; i < font->charcount; i++) {
2107 memcpy(data, fontdata, j);
2108 memset(data + j, 0, 128 - j);
2116 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2117 u8 * data, int userfont)
2119 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2120 struct display *p = &fb_display[vc->vc_num];
2123 char *old_data = NULL;
2125 if (CON_IS_VISIBLE(vc) && softback_lines)
2126 fbcon_set_origin(vc);
2128 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2130 old_data = vc->vc_font.data;
2132 cnt = FNTCHARCNT(data);
2135 vc->vc_font.data = p->fontdata = data;
2136 if ((p->userfont = userfont))
2138 vc->vc_font.width = w;
2139 vc->vc_font.height = h;
2140 if (vc->vc_hi_font_mask && cnt == 256) {
2141 vc->vc_hi_font_mask = 0;
2142 if (vc->vc_can_do_color) {
2143 vc->vc_complement_mask >>= 1;
2144 vc->vc_s_complement_mask >>= 1;
2147 /* ++Edmund: reorder the attribute bits */
2148 if (vc->vc_can_do_color) {
2149 unsigned short *cp =
2150 (unsigned short *) vc->vc_origin;
2151 int count = vc->vc_screenbuf_size / 2;
2153 for (; count > 0; count--, cp++) {
2155 scr_writew(((c & 0xfe00) >> 1) |
2158 c = vc->vc_video_erase_char;
2159 vc->vc_video_erase_char =
2160 ((c & 0xfe00) >> 1) | (c & 0xff);
2163 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2164 vc->vc_hi_font_mask = 0x100;
2165 if (vc->vc_can_do_color) {
2166 vc->vc_complement_mask <<= 1;
2167 vc->vc_s_complement_mask <<= 1;
2170 /* ++Edmund: reorder the attribute bits */
2172 unsigned short *cp =
2173 (unsigned short *) vc->vc_origin;
2174 int count = vc->vc_screenbuf_size / 2;
2176 for (; count > 0; count--, cp++) {
2177 unsigned short newc;
2179 if (vc->vc_can_do_color)
2181 ((c & 0xff00) << 1) | (c &
2185 scr_writew(newc, cp);
2187 c = vc->vc_video_erase_char;
2188 if (vc->vc_can_do_color) {
2189 vc->vc_video_erase_char =
2190 ((c & 0xff00) << 1) | (c & 0xff);
2193 vc->vc_video_erase_char = c & ~0x100;
2199 /* reset wrap/pan */
2200 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2201 vc_resize(vc->vc_num, info->var.xres / w, info->var.yres / h);
2202 if (CON_IS_VISIBLE(vc) && softback_buf) {
2203 int l = fbcon_softback_size / vc->vc_size_row;
2206 softback_buf + l * vc->vc_size_row;
2208 /* Smaller scrollback makes no sense, and 0 would screw
2209 the operation totally */
2213 } else if (CON_IS_VISIBLE(vc)
2214 && vt_cons[vc->vc_num]->vc_mode == KD_TEXT) {
2215 fbcon_clear_margins(vc, 0);
2216 update_screen(vc->vc_num);
2219 if (old_data && (--REFCOUNT(old_data) == 0))
2220 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2224 static int fbcon_copy_font(struct vc_data *vc, int con)
2226 struct display *od = &fb_display[con];
2227 struct console_font *f = &vc->vc_font;
2229 if (od->fontdata == f->data)
2230 return 0; /* already the same font... */
2231 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2235 * User asked to set font; we are guaranteed that
2236 * a) width and height are in range 1..32
2237 * b) charcount does not exceed 512
2238 * but lets not assume that, since someone might someday want to use larger
2239 * fonts. And charcount of 512 is small for unicode support.
2241 * However, user space gives the font in 32 rows , regardless of
2242 * actual font height. So a new API is needed if support for larger fonts
2243 * is ever implemented.
2246 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2248 unsigned charcount = font->charcount;
2249 int w = font->width;
2250 int h = font->height;
2253 u8 *new_data, *data = font->data;
2254 int pitch = (font->width+7) >> 3;
2256 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2257 * If not this check should be changed to charcount < 256 */
2258 if (charcount != 256 && charcount != 512)
2261 size = h * pitch * charcount;
2263 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2268 new_data += FONT_EXTRA_WORDS * sizeof(int);
2269 FNTSIZE(new_data) = size;
2270 FNTCHARCNT(new_data) = charcount;
2271 REFCOUNT(new_data) = 0; /* usage counter */
2272 for (i=0; i< charcount; i++) {
2273 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2276 /* Since linux has a nice crc32 function use it for counting font
2278 csum = crc32(0, new_data, size);
2280 FNTSUM(new_data) = csum;
2281 /* Check if the same font is on some other console already */
2282 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2283 struct vc_data *tmp = vc_cons[i].d;
2285 if (fb_display[i].userfont &&
2286 fb_display[i].fontdata &&
2287 FNTSUM(fb_display[i].fontdata) == csum &&
2288 FNTSIZE(fb_display[i].fontdata) == size &&
2289 tmp->vc_font.width == w &&
2290 !memcmp(fb_display[i].fontdata, new_data, size)) {
2291 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2292 new_data = fb_display[i].fontdata;
2296 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2299 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2301 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2302 struct font_desc *f;
2305 f = get_default_font(info->var.xres, info->var.yres);
2306 else if (!(f = find_font(name)))
2309 font->width = f->width;
2310 font->height = f->height;
2311 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2314 static u16 palette_red[16];
2315 static u16 palette_green[16];
2316 static u16 palette_blue[16];
2318 static struct fb_cmap palette_cmap = {
2319 0, 16, palette_red, palette_green, palette_blue, NULL
2322 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2324 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2328 if (fbcon_is_inactive(vc, info))
2331 depth = fb_get_color_depth(info);
2333 for (i = j = 0; i < 16; i++) {
2335 val = vc->vc_palette[j++];
2336 palette_red[k] = (val << 8) | val;
2337 val = vc->vc_palette[j++];
2338 palette_green[k] = (val << 8) | val;
2339 val = vc->vc_palette[j++];
2340 palette_blue[k] = (val << 8) | val;
2342 palette_cmap.len = 16;
2343 palette_cmap.start = 0;
2345 * If framebuffer is capable of less than 16 colors,
2346 * use default palette of fbcon.
2349 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2351 return fb_set_cmap(&palette_cmap, info);
2354 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2359 if (vc->vc_num != fg_console || !softback_lines)
2360 return (u16 *) (vc->vc_origin + offset);
2361 line = offset / vc->vc_size_row;
2362 if (line >= softback_lines)
2363 return (u16 *) (vc->vc_origin + offset -
2364 softback_lines * vc->vc_size_row);
2365 p = softback_curr + offset;
2366 if (p >= softback_end)
2367 p += softback_buf - softback_end;
2371 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2377 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2378 unsigned long offset = (pos - vc->vc_origin) / 2;
2380 x = offset % vc->vc_cols;
2381 y = offset / vc->vc_cols;
2382 if (vc->vc_num == fg_console)
2383 y += softback_lines;
2384 ret = pos + (vc->vc_cols - x) * 2;
2385 } else if (vc->vc_num == fg_console && softback_lines) {
2386 unsigned long offset = pos - softback_curr;
2388 if (pos < softback_curr)
2389 offset += softback_end - softback_buf;
2391 x = offset % vc->vc_cols;
2392 y = offset / vc->vc_cols;
2393 ret = pos + (vc->vc_cols - x) * 2;
2394 if (ret == softback_end)
2396 if (ret == softback_in)
2397 ret = vc->vc_origin;
2399 /* Should not happen */
2401 ret = vc->vc_origin;
2410 /* As we might be inside of softback, we may work with non-contiguous buffer,
2411 that's why we have to use a separate routine. */
2412 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2415 u16 a = scr_readw(p);
2416 if (!vc->vc_can_do_color)
2418 else if (vc->vc_hi_font_mask == 0x100)
2419 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2420 (((a) & 0x0e00) << 4);
2422 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2423 (((a) & 0x0700) << 4);
2425 if (p == (u16 *) softback_end)
2426 p = (u16 *) softback_buf;
2427 if (p == (u16 *) softback_in)
2428 p = (u16 *) vc->vc_origin;
2432 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2434 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2435 struct display *p = &fb_display[fg_console];
2436 int offset, limit, scrollback_old;
2439 if (vc->vc_num != fg_console)
2441 if (vt_cons[vc->vc_num]->vc_mode != KD_TEXT || !lines)
2443 if (logo_shown >= 0) {
2444 struct vc_data *conp2 = vc_cons[logo_shown].d;
2446 if (conp2->vc_top == logo_lines
2447 && conp2->vc_bottom == conp2->vc_rows)
2449 if (logo_shown == vc->vc_num) {
2455 logo_lines * vc->vc_size_row;
2456 for (i = 0; i < logo_lines; i++) {
2457 if (p == softback_top)
2459 if (p == softback_buf)
2461 p -= vc->vc_size_row;
2462 q -= vc->vc_size_row;
2463 scr_memcpyw((u16 *) q, (u16 *) p,
2467 update_region(vc->vc_num, vc->vc_origin,
2468 logo_lines * vc->vc_cols);
2470 logo_shown = FBCON_LOGO_CANSHOW;
2472 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2473 fbcon_redraw_softback(vc, p, lines);
2474 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2478 if (!scrollback_phys_max)
2481 scrollback_old = scrollback_current;
2482 scrollback_current -= lines;
2483 if (scrollback_current < 0)
2484 scrollback_current = 0;
2485 else if (scrollback_current > scrollback_max)
2486 scrollback_current = scrollback_max;
2487 if (scrollback_current == scrollback_old)
2490 if (fbcon_is_inactive(vc, info))
2493 fbcon_cursor(vc, CM_ERASE);
2495 offset = p->yscroll - scrollback_current;
2497 switch (p->scrollmode) {
2498 case SCROLL_WRAP_MOVE:
2499 info->var.vmode |= FB_VMODE_YWRAP;
2501 case SCROLL_PAN_MOVE:
2502 case SCROLL_PAN_REDRAW:
2503 limit -= vc->vc_rows;
2504 info->var.vmode &= ~FB_VMODE_YWRAP;
2509 else if (offset >= limit)
2511 info->var.xoffset = 0;
2512 info->var.yoffset = offset * vc->vc_font.height;
2513 update_var(vc->vc_num, info);
2514 if (!scrollback_current)
2515 fbcon_cursor(vc, CM_DRAW);
2519 static int fbcon_set_origin(struct vc_data *vc)
2522 fbcon_scrolldelta(vc, softback_lines);
2526 static void fbcon_suspended(struct fb_info *info)
2528 struct vc_data *vc = NULL;
2529 struct fbcon_ops *ops = info->fbcon_par;
2531 if (!ops || ops->currcon < 0)
2533 vc = vc_cons[ops->currcon].d;
2535 /* Clear cursor, restore saved data */
2536 fbcon_cursor(vc, CM_ERASE);
2539 static void fbcon_resumed(struct fb_info *info)
2542 struct fbcon_ops *ops = info->fbcon_par;
2544 if (!ops || ops->currcon < 0)
2546 vc = vc_cons[ops->currcon].d;
2548 update_screen(vc->vc_num);
2551 static void fbcon_modechanged(struct fb_info *info)
2553 struct fbcon_ops *ops = info->fbcon_par;
2558 if (!ops || ops->currcon < 0 || vt_cons[ops->currcon]->vc_mode !=
2559 KD_TEXT || registered_fb[con2fb_map[ops->currcon]] != info)
2562 vc = vc_cons[ops->currcon].d;
2564 p = &fb_display[vc->vc_num];
2566 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2568 if (CON_IS_VISIBLE(vc)) {
2569 var_to_display(p, &info->var, info);
2570 cols = info->var.xres / vc->vc_font.width;
2571 rows = info->var.yres / vc->vc_font.height;
2572 vc_resize(vc->vc_num, cols, rows);
2573 updatescrollmode(p, info, vc);
2575 scrollback_current = 0;
2576 update_var(vc->vc_num, info);
2577 fbcon_set_palette(vc, color_table);
2578 update_screen(vc->vc_num);
2580 int l = fbcon_softback_size / vc->vc_size_row;
2582 softback_end = softback_buf + l * vc->vc_size_row;
2584 /* Smaller scrollback makes no sense, and 0
2585 would screw the operation totally */
2592 static int fbcon_mode_deleted(struct fb_info *info,
2593 struct fb_videomode *mode)
2595 struct fb_info *fb_info;
2597 int i, j, found = 0;
2599 /* before deletion, ensure that mode is not in use */
2600 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2604 fb_info = registered_fb[j];
2605 if (fb_info != info)
2610 if (fb_mode_is_equal(p->mode, mode)) {
2618 static int fbcon_fb_registered(int idx)
2622 if (info_idx == -1) {
2623 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2624 if (con2fb_map_boot[i] == idx) {
2630 ret = fbcon_takeover(1);
2632 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2633 if (con2fb_map_boot[i] == idx)
2634 set_con2fb_map(i, idx, 0);
2641 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2643 struct fbcon_ops *ops = info->fbcon_par;
2646 if (!ops || ops->currcon < 0 ||
2647 vt_cons[ops->currcon]->vc_mode != KD_TEXT ||
2648 registered_fb[con2fb_map[ops->currcon]] != info)
2654 vc = vc_cons[ops->currcon].d;
2656 if (CON_IS_VISIBLE(vc)) {
2660 do_unblank_screen(0);
2662 ops->blank_state = blank;
2666 static int fbcon_event_notify(struct notifier_block *self,
2667 unsigned long action, void *data)
2669 struct fb_event *event = data;
2670 struct fb_info *info = event->info;
2671 struct fb_videomode *mode;
2672 struct fb_con2fbmap *con2fb;
2676 case FB_EVENT_SUSPEND:
2677 fbcon_suspended(info);
2679 case FB_EVENT_RESUME:
2680 fbcon_resumed(info);
2682 case FB_EVENT_MODE_CHANGE:
2683 fbcon_modechanged(info);
2685 case FB_EVENT_MODE_DELETE:
2687 ret = fbcon_mode_deleted(info, mode);
2689 case FB_EVENT_FB_REGISTERED:
2690 ret = fbcon_fb_registered(info->node);
2692 case FB_EVENT_SET_CONSOLE_MAP:
2693 con2fb = event->data;
2694 ret = set_con2fb_map(con2fb->console - 1,
2695 con2fb->framebuffer, 1);
2697 case FB_EVENT_GET_CONSOLE_MAP:
2698 con2fb = event->data;
2699 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2701 case FB_EVENT_BLANK:
2702 fbcon_fb_blanked(info, *(int *)event->data);
2710 * The console `switch' structure for the frame buffer based console
2713 const struct consw fb_con = {
2714 .owner = THIS_MODULE,
2715 .con_startup = fbcon_startup,
2716 .con_init = fbcon_init,
2717 .con_deinit = fbcon_deinit,
2718 .con_clear = fbcon_clear,
2719 .con_putc = fbcon_putc,
2720 .con_putcs = fbcon_putcs,
2721 .con_cursor = fbcon_cursor,
2722 .con_scroll = fbcon_scroll,
2723 .con_bmove = fbcon_bmove,
2724 .con_switch = fbcon_switch,
2725 .con_blank = fbcon_blank,
2726 .con_font_set = fbcon_set_font,
2727 .con_font_get = fbcon_get_font,
2728 .con_font_default = fbcon_set_def_font,
2729 .con_font_copy = fbcon_copy_font,
2730 .con_set_palette = fbcon_set_palette,
2731 .con_scrolldelta = fbcon_scrolldelta,
2732 .con_set_origin = fbcon_set_origin,
2733 .con_invert_region = fbcon_invert_region,
2734 .con_screen_pos = fbcon_screen_pos,
2735 .con_getxy = fbcon_getxy,
2736 .con_resize = fbcon_resize,
2739 static struct notifier_block fbcon_event_notifier = {
2740 .notifier_call = fbcon_event_notify,
2743 int __init fb_console_init(void)
2747 acquire_console_sem();
2748 fb_register_client(&fbcon_event_notifier);
2749 release_console_sem();
2751 for (i = 0; i < MAX_NR_CONSOLES; i++)
2754 if (num_registered_fb) {
2755 for (i = 0; i < FB_MAX; i++) {
2756 if (registered_fb[i] != NULL) {
2767 module_init(fb_console_init);
2771 void __exit fb_console_exit(void)
2773 acquire_console_sem();
2774 fb_unregister_client(&fbcon_event_notifier);
2775 release_console_sem();
2776 give_up_console(&fb_con);
2779 module_exit(fb_console_exit);
2784 * Visible symbols for modules
2787 EXPORT_SYMBOL(fb_con);
2789 MODULE_LICENSE("GPL");