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 fb_flashcursor(void *private)
286 struct fb_info *info = private;
287 struct fbcon_ops *ops = info->fbcon_par;
289 struct vc_data *vc = NULL;
293 if (ops->currcon != -1)
294 vc = vc_cons[ops->currcon].d;
296 if (!vc || !CON_IS_VISIBLE(vc) ||
297 fbcon_is_inactive(vc, info) ||
298 registered_fb[con2fb_map[vc->vc_num]] != info ||
299 vc_cons[ops->currcon].d->vc_deccm != 1)
301 acquire_console_sem();
302 p = &fb_display[vc->vc_num];
303 c = scr_readw((u16 *) vc->vc_pos);
304 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
306 ops->cursor(vc, info, p, mode, softback_lines, get_color(vc, info, c, 1),
307 get_color(vc, info, c, 0));
308 release_console_sem();
311 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
312 static int cursor_blink_rate;
313 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
315 struct fb_info *info = dev_id;
317 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
318 schedule_work(&info->queue);
319 vbl_cursor_cnt = cursor_blink_rate;
325 static void cursor_timer_handler(unsigned long dev_addr)
327 struct fb_info *info = (struct fb_info *) dev_addr;
328 struct fbcon_ops *ops = info->fbcon_par;
330 schedule_work(&info->queue);
331 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
335 static int __init fb_console_setup(char *this_opt)
340 if (!this_opt || !*this_opt)
343 while ((options = strsep(&this_opt, ",")) != NULL) {
344 if (!strncmp(options, "font:", 5))
345 strcpy(fontname, options + 5);
347 if (!strncmp(options, "scrollback:", 11)) {
350 fbcon_softback_size = simple_strtoul(options, &options, 0);
351 if (*options == 'k' || *options == 'K') {
352 fbcon_softback_size *= 1024;
362 if (!strncmp(options, "map:", 4)) {
365 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
369 (options[j++]-'0') % FB_MAX;
374 if (!strncmp(options, "vc:", 3)) {
377 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
380 if (*options++ == '-')
381 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
382 fbcon_is_default = 0;
388 __setup("fbcon=", fb_console_setup);
391 static int search_fb_in_map(int idx)
395 for (i = 0; i < MAX_NR_CONSOLES; i++) {
396 if (con2fb_map[i] == idx)
402 static int search_for_mapped_con(void)
406 for (i = 0; i < MAX_NR_CONSOLES; i++) {
407 if (con2fb_map[i] != -1)
413 static int fbcon_takeover(int show_logo)
417 if (!num_registered_fb)
421 logo_shown = FBCON_LOGO_DONTSHOW;
423 for (i = first_fb_vc; i <= last_fb_vc; i++)
424 con2fb_map[i] = info_idx;
426 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
429 for (i = first_fb_vc; i <= last_fb_vc; i++) {
438 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
439 int cols, int rows, int new_cols, int new_rows)
441 /* Need to make room for the logo */
442 int cnt, erase = vc->vc_video_erase_char, step;
443 unsigned short *save = NULL, *r, *q;
446 * remove underline attribute from erase character
447 * if black and white framebuffer.
449 if (fb_get_color_depth(&info->var, &info->fix) == 1)
451 logo_height = fb_prepare_logo(info);
452 logo_lines = (logo_height + vc->vc_font.height - 1) /
454 q = (unsigned short *) (vc->vc_origin +
455 vc->vc_size_row * rows);
456 step = logo_lines * cols;
457 for (r = q - logo_lines * cols; r < q; r++)
458 if (scr_readw(r) != vc->vc_video_erase_char)
460 if (r != q && new_rows >= rows + logo_lines) {
461 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
463 int i = cols < new_cols ? cols : new_cols;
464 scr_memsetw(save, erase, logo_lines * new_cols * 2);
466 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
467 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
472 /* We can scroll screen down */
474 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
475 scr_memcpyw(r + step, r, vc->vc_size_row);
479 vc->vc_y += logo_lines;
480 vc->vc_pos += logo_lines * vc->vc_size_row;
483 scr_memsetw((unsigned short *) vc->vc_origin,
485 vc->vc_size_row * logo_lines);
487 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
488 fbcon_clear_margins(vc, 0);
493 q = (unsigned short *) (vc->vc_origin +
496 scr_memcpyw(q, save, logo_lines * new_cols * 2);
497 vc->vc_y += logo_lines;
498 vc->vc_pos += logo_lines * vc->vc_size_row;
502 if (logo_lines > vc->vc_bottom) {
503 logo_shown = FBCON_LOGO_CANSHOW;
505 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
506 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
507 logo_shown = FBCON_LOGO_DRAW;
508 vc->vc_top = logo_lines;
512 #ifdef CONFIG_FB_TILEBLITTING
513 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
516 struct fbcon_ops *ops = info->fbcon_par;
518 if ((info->flags & FBINFO_MISC_TILEBLITTING))
519 fbcon_set_tileops(vc, info, p, ops);
521 fbcon_set_bitops(ops);
524 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
527 struct fbcon_ops *ops = info->fbcon_par;
529 info->flags &= ~FBINFO_MISC_TILEBLITTING;
530 fbcon_set_bitops(ops);
532 #endif /* CONFIG_MISC_TILEBLITTING */
535 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
536 int unit, int oldidx)
538 struct fbcon_ops *ops = NULL;
541 if (!try_module_get(info->fbops->owner))
544 if (!err && info->fbops->fb_open &&
545 info->fbops->fb_open(info, 0))
549 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
555 memset(ops, 0, sizeof(struct fbcon_ops));
556 info->fbcon_par = ops;
557 set_blitting_type(vc, info, NULL);
561 con2fb_map[unit] = oldidx;
562 module_put(info->fbops->owner);
568 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
569 struct fb_info *newinfo, int unit,
570 int oldidx, int found)
572 struct fbcon_ops *ops = oldinfo->fbcon_par;
575 if (oldinfo->fbops->fb_release &&
576 oldinfo->fbops->fb_release(oldinfo, 0)) {
577 con2fb_map[unit] = oldidx;
578 if (!found && newinfo->fbops->fb_release)
579 newinfo->fbops->fb_release(newinfo, 0);
581 module_put(newinfo->fbops->owner);
586 if (oldinfo->queue.func == fb_flashcursor)
587 del_timer_sync(&ops->cursor_timer);
589 kfree(ops->cursor_state.mask);
590 kfree(ops->cursor_data);
591 kfree(oldinfo->fbcon_par);
592 oldinfo->fbcon_par = NULL;
593 module_put(oldinfo->fbops->owner);
599 static void con2fb_init_newinfo(struct fb_info *info)
601 if (!info->queue.func || info->queue.func == fb_flashcursor) {
602 struct fbcon_ops *ops = info->fbcon_par;
604 if (!info->queue.func)
605 INIT_WORK(&info->queue, fb_flashcursor, info);
607 init_timer(&ops->cursor_timer);
608 ops->cursor_timer.function = cursor_timer_handler;
609 ops->cursor_timer.expires = jiffies + HZ / 5;
610 ops->cursor_timer.data = (unsigned long ) info;
611 add_timer(&ops->cursor_timer);
615 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
616 int unit, int show_logo)
618 struct fbcon_ops *ops = info->fbcon_par;
620 ops->currcon = fg_console;
622 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
623 info->fbops->fb_set_par(info);
625 ops->flags |= FBCON_FLAGS_INIT;
629 fbcon_set_disp(info, &info->var, vc);
631 fbcon_preset_disp(info, &info->var, unit);
634 struct vc_data *fg_vc = vc_cons[fg_console].d;
635 struct fb_info *fg_info =
636 registered_fb[con2fb_map[fg_console]];
638 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
639 fg_vc->vc_rows, fg_vc->vc_cols,
643 update_screen(vc_cons[fg_console].d);
647 * set_con2fb_map - map console to frame buffer device
648 * @unit: virtual console number to map
649 * @newidx: frame buffer index to map virtual console to
650 * @user: user request
652 * Maps a virtual console @unit to a frame buffer device
655 static int set_con2fb_map(int unit, int newidx, int user)
657 struct vc_data *vc = vc_cons[unit].d;
658 int oldidx = con2fb_map[unit];
659 struct fb_info *info = registered_fb[newidx];
660 struct fb_info *oldinfo = NULL;
663 if (oldidx == newidx)
669 if (!err && !search_for_mapped_con()) {
671 return fbcon_takeover(0);
675 oldinfo = registered_fb[oldidx];
677 found = search_fb_in_map(newidx);
679 acquire_console_sem();
680 con2fb_map[unit] = newidx;
682 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
686 * If old fb is not mapped to any of the consoles,
687 * fbcon should release it.
689 if (!err && oldinfo && !search_fb_in_map(oldidx))
690 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
694 int show_logo = (fg_console == 0 && !user &&
695 logo_shown != FBCON_LOGO_DONTSHOW);
698 con2fb_init_newinfo(info);
699 con2fb_map_boot[unit] = newidx;
700 con2fb_init_display(vc, info, unit, show_logo);
703 release_console_sem();
708 * Low Level Operations
710 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
711 static int var_to_display(struct display *disp,
712 struct fb_var_screeninfo *var,
713 struct fb_info *info)
715 disp->xres_virtual = var->xres_virtual;
716 disp->yres_virtual = var->yres_virtual;
717 disp->bits_per_pixel = var->bits_per_pixel;
718 disp->grayscale = var->grayscale;
719 disp->nonstd = var->nonstd;
720 disp->accel_flags = var->accel_flags;
721 disp->height = var->height;
722 disp->width = var->width;
723 disp->red = var->red;
724 disp->green = var->green;
725 disp->blue = var->blue;
726 disp->transp = var->transp;
727 disp->rotate = var->rotate;
728 disp->mode = fb_match_mode(var, &info->modelist);
729 if (disp->mode == NULL)
730 /* This should not happen */
735 static void display_to_var(struct fb_var_screeninfo *var,
736 struct display *disp)
738 fb_videomode_to_var(var, disp->mode);
739 var->xres_virtual = disp->xres_virtual;
740 var->yres_virtual = disp->yres_virtual;
741 var->bits_per_pixel = disp->bits_per_pixel;
742 var->grayscale = disp->grayscale;
743 var->nonstd = disp->nonstd;
744 var->accel_flags = disp->accel_flags;
745 var->height = disp->height;
746 var->width = disp->width;
747 var->red = disp->red;
748 var->green = disp->green;
749 var->blue = disp->blue;
750 var->transp = disp->transp;
751 var->rotate = disp->rotate;
754 static const char *fbcon_startup(void)
756 const char *display_desc = "frame buffer device";
757 struct display *p = &fb_display[fg_console];
758 struct vc_data *vc = vc_cons[fg_console].d;
759 struct font_desc *font = NULL;
760 struct module *owner;
761 struct fb_info *info = NULL;
762 struct fbcon_ops *ops;
768 * If num_registered_fb is zero, this is a call for the dummy part.
769 * The frame buffer devices weren't initialized yet.
771 if (!num_registered_fb || info_idx == -1)
774 * Instead of blindly using registered_fb[0], we use info_idx, set by
777 info = registered_fb[info_idx];
781 owner = info->fbops->owner;
782 if (!try_module_get(owner))
784 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
789 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
795 memset(ops, 0, sizeof(struct fbcon_ops));
798 info->fbcon_par = ops;
799 set_blitting_type(vc, info, NULL);
801 if (info->fix.type != FB_TYPE_TEXT) {
802 if (fbcon_softback_size) {
806 kmalloc(fbcon_softback_size,
809 fbcon_softback_size = 0;
815 kfree((void *) softback_buf);
821 softback_in = softback_top = softback_curr =
826 /* Setup default font */
828 if (!fontname[0] || !(font = find_font(fontname)))
829 font = get_default_font(info->var.xres,
831 vc->vc_font.width = font->width;
832 vc->vc_font.height = font->height;
833 vc->vc_font.data = p->fontdata = font->data;
834 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
837 cols = info->var.xres / vc->vc_font.width;
838 rows = info->var.yres / vc->vc_font.height;
839 vc_resize(vc, cols, rows);
841 DPRINTK("mode: %s\n", info->fix.id);
842 DPRINTK("visual: %d\n", info->fix.visual);
843 DPRINTK("res: %dx%d-%d\n", info->var.xres,
845 info->var.bits_per_pixel);
849 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
851 request_irq(IRQ_AUTO_4, fb_vbl_handler,
852 IRQ_TYPE_PRIO, "framebuffer vbl",
855 #endif /* CONFIG_ATARI */
859 * On a Macintoy, the VBL interrupt may or may not be active.
860 * As interrupt based cursor is more reliable and race free, we
861 * probe for VBL interrupts.
866 * Probe for VBL: set temp. handler ...
868 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
869 "framebuffer vbl", info);
873 * ... and spin for 20 ms ...
875 while (!vbl_detected && ++ct < 1000)
880 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
882 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
886 * interrupt based cursor ok
888 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
890 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
891 "framebuffer vbl", info);
894 * VBL not detected: fall through, use timer based cursor
899 #endif /* CONFIG_MAC */
901 /* Initialize the work queue. If the driver provides its
902 * own work queue this means it will use something besides
903 * default timer to flash the cursor. */
904 if (!info->queue.func) {
905 INIT_WORK(&info->queue, fb_flashcursor, info);
907 init_timer(&ops->cursor_timer);
908 ops->cursor_timer.function = cursor_timer_handler;
909 ops->cursor_timer.expires = jiffies + HZ / 5;
910 ops->cursor_timer.data = (unsigned long ) info;
911 add_timer(&ops->cursor_timer);
916 static void fbcon_init(struct vc_data *vc, int init)
918 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
919 struct fbcon_ops *ops;
920 struct vc_data **default_mode = vc->vc_display_fg;
921 struct vc_data *svc = *default_mode;
922 struct display *t, *p = &fb_display[vc->vc_num];
923 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
926 if (info_idx == -1 || info == NULL)
931 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
932 (info->fix.type == FB_TYPE_TEXT))
935 info->var.xoffset = info->var.yoffset = p->yscroll = 0; /* reset wrap/pan */
937 if (var_to_display(p, &info->var, info))
940 /* If we are not the first console on this
941 fb, copy the font from that console */
942 t = &fb_display[svc->vc_num];
943 if (!vc->vc_font.data) {
944 vc->vc_font.data = p->fontdata = t->fontdata;
945 vc->vc_font.width = (*default_mode)->vc_font.width;
946 vc->vc_font.height = (*default_mode)->vc_font.height;
947 p->userfont = t->userfont;
949 REFCOUNT(p->fontdata)++;
952 charcnt = FNTCHARCNT(p->fontdata);
953 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
954 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
955 if (charcnt == 256) {
956 vc->vc_hi_font_mask = 0;
958 vc->vc_hi_font_mask = 0x100;
959 if (vc->vc_can_do_color)
960 vc->vc_complement_mask <<= 1;
963 if (!*svc->vc_uni_pagedir_loc)
964 con_set_default_unimap(svc);
965 if (!*vc->vc_uni_pagedir_loc)
966 con_copy_unimap(vc, svc);
970 new_cols = info->var.xres / vc->vc_font.width;
971 new_rows = info->var.yres / vc->vc_font.height;
972 vc_resize(vc, new_cols, new_rows);
974 ops = info->fbcon_par;
976 * We must always set the mode. The mode of the previous console
977 * driver could be in the same resolution but we are using different
978 * hardware so we have to initialize the hardware.
980 * We need to do it in fbcon_init() to prevent screen corruption.
982 if (CON_IS_VISIBLE(vc)) {
983 if (info->fbops->fb_set_par &&
984 !(ops->flags & FBCON_FLAGS_INIT))
985 info->fbops->fb_set_par(info);
986 ops->flags |= FBCON_FLAGS_INIT;
991 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
992 !(cap & FBINFO_HWACCEL_DISABLED))
993 p->scrollmode = SCROLL_MOVE;
994 else /* default to something safe */
995 p->scrollmode = SCROLL_REDRAW;
998 * ++guenther: console.c:vc_allocate() relies on initializing
999 * vc_{cols,rows}, but we must not set those if we are only
1000 * resizing the console.
1003 vc->vc_cols = new_cols;
1004 vc->vc_rows = new_rows;
1008 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1010 if (vc == svc && softback_buf) {
1011 int l = fbcon_softback_size / vc->vc_size_row;
1013 softback_end = softback_buf + l * vc->vc_size_row;
1015 /* Smaller scrollback makes no sense, and 0 would screw
1016 the operation totally */
1022 static void fbcon_deinit(struct vc_data *vc)
1024 struct display *p = &fb_display[vc->vc_num];
1031 /* ====================================================================== */
1033 /* fbcon_XXX routines - interface used by the world
1035 * This system is now divided into two levels because of complications
1036 * caused by hardware scrolling. Top level functions:
1038 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1040 * handles y values in range [0, scr_height-1] that correspond to real
1041 * screen positions. y_wrap shift means that first line of bitmap may be
1042 * anywhere on this display. These functions convert lineoffsets to
1043 * bitmap offsets and deal with the wrap-around case by splitting blits.
1045 * fbcon_bmove_physical_8() -- These functions fast implementations
1046 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1047 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1051 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1052 * Implies should only really hardware scroll in rows. Only reason for
1053 * restriction is simplicity & efficiency at the moment.
1056 static __inline__ int real_y(struct display *p, int ypos)
1058 int rows = p->vrows;
1061 return ypos < rows ? ypos : ypos - rows;
1065 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1068 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1069 struct fbcon_ops *ops = info->fbcon_par;
1071 struct display *p = &fb_display[vc->vc_num];
1074 if (fbcon_is_inactive(vc, info))
1077 if (!height || !width)
1080 /* Split blits that cross physical y_wrap boundary */
1082 y_break = p->vrows - p->yscroll;
1083 if (sy < y_break && sy + height - 1 >= y_break) {
1084 u_int b = y_break - sy;
1085 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1086 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1089 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1092 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1093 int count, int ypos, int xpos)
1095 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1096 struct display *p = &fb_display[vc->vc_num];
1097 struct fbcon_ops *ops = info->fbcon_par;
1099 if (!fbcon_is_inactive(vc, info))
1100 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1101 get_color(vc, info, scr_readw(s), 1),
1102 get_color(vc, info, scr_readw(s), 0));
1105 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1109 scr_writew(c, &chr);
1110 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1113 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1115 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1116 struct fbcon_ops *ops = info->fbcon_par;
1118 if (!fbcon_is_inactive(vc, info))
1119 ops->clear_margins(vc, info, bottom_only);
1122 static void fbcon_cursor(struct vc_data *vc, int mode)
1124 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1125 struct fbcon_ops *ops = info->fbcon_par;
1126 struct display *p = &fb_display[vc->vc_num];
1128 int c = scr_readw((u16 *) vc->vc_pos);
1130 if (fbcon_is_inactive(vc, info))
1133 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1134 if (mode & CM_SOFTBACK) {
1135 mode &= ~CM_SOFTBACK;
1139 fbcon_set_origin(vc);
1143 ops->cursor(vc, info, p, mode, y, get_color(vc, info, c, 1),
1144 get_color(vc, info, c, 0));
1145 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1148 static int scrollback_phys_max = 0;
1149 static int scrollback_max = 0;
1150 static int scrollback_current = 0;
1152 static int update_var(int con, struct fb_info *info)
1154 if (con == ((struct fbcon_ops *)info->fbcon_par)->currcon)
1155 return fb_pan_display(info, &info->var);
1160 * If no vc is existent yet, just set struct display
1162 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1165 struct display *p = &fb_display[unit];
1166 struct display *t = &fb_display[fg_console];
1168 var->xoffset = var->yoffset = p->yscroll = 0;
1169 if (var_to_display(p, var, info))
1172 p->fontdata = t->fontdata;
1173 p->userfont = t->userfont;
1175 REFCOUNT(p->fontdata)++;
1178 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1181 struct display *p = &fb_display[vc->vc_num], *t;
1182 struct vc_data **default_mode = vc->vc_display_fg;
1183 struct vc_data *svc = *default_mode;
1184 int rows, cols, charcnt = 256;
1186 var->xoffset = var->yoffset = p->yscroll = 0;
1187 if (var_to_display(p, var, info))
1189 t = &fb_display[svc->vc_num];
1190 if (!vc->vc_font.data) {
1191 vc->vc_font.data = p->fontdata = t->fontdata;
1192 vc->vc_font.width = (*default_mode)->vc_font.width;
1193 vc->vc_font.height = (*default_mode)->vc_font.height;
1194 p->userfont = t->userfont;
1196 REFCOUNT(p->fontdata)++;
1199 charcnt = FNTCHARCNT(p->fontdata);
1201 var->activate = FB_ACTIVATE_NOW;
1202 info->var.activate = var->activate;
1203 info->var.yoffset = info->var.xoffset = 0;
1204 fb_set_var(info, var);
1206 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1207 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1208 if (charcnt == 256) {
1209 vc->vc_hi_font_mask = 0;
1211 vc->vc_hi_font_mask = 0x100;
1212 if (vc->vc_can_do_color)
1213 vc->vc_complement_mask <<= 1;
1216 if (!*svc->vc_uni_pagedir_loc)
1217 con_set_default_unimap(svc);
1218 if (!*vc->vc_uni_pagedir_loc)
1219 con_copy_unimap(vc, svc);
1221 cols = var->xres / vc->vc_font.width;
1222 rows = var->yres / vc->vc_font.height;
1223 vc_resize(vc, cols, rows);
1224 if (CON_IS_VISIBLE(vc)) {
1227 int l = fbcon_softback_size / vc->vc_size_row;
1230 softback_end = softback_buf + l *
1233 /* Smaller scrollback makes no sense, and 0
1234 would screw the operation totally */
1241 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1243 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1244 struct display *p = &fb_display[vc->vc_num];
1246 p->yscroll += count;
1247 if (p->yscroll >= p->vrows) /* Deal with wrap */
1248 p->yscroll -= p->vrows;
1249 info->var.xoffset = 0;
1250 info->var.yoffset = p->yscroll * vc->vc_font.height;
1251 info->var.vmode |= FB_VMODE_YWRAP;
1252 update_var(vc->vc_num, info);
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 ywrap_down(struct vc_data *vc, int count)
1261 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1262 struct display *p = &fb_display[vc->vc_num];
1264 p->yscroll -= count;
1265 if (p->yscroll < 0) /* Deal with wrap */
1266 p->yscroll += p->vrows;
1267 info->var.xoffset = 0;
1268 info->var.yoffset = p->yscroll * vc->vc_font.height;
1269 info->var.vmode |= FB_VMODE_YWRAP;
1270 update_var(vc->vc_num, info);
1271 scrollback_max -= count;
1272 if (scrollback_max < 0)
1274 scrollback_current = 0;
1277 static __inline__ void ypan_up(struct vc_data *vc, int count)
1279 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1280 struct display *p = &fb_display[vc->vc_num];
1281 struct fbcon_ops *ops = info->fbcon_par;
1283 p->yscroll += count;
1284 if (p->yscroll > p->vrows - vc->vc_rows) {
1285 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1286 0, 0, 0, vc->vc_rows, vc->vc_cols);
1287 p->yscroll -= p->vrows - vc->vc_rows;
1289 info->var.xoffset = 0;
1290 info->var.yoffset = p->yscroll * vc->vc_font.height;
1291 info->var.vmode &= ~FB_VMODE_YWRAP;
1292 update_var(vc->vc_num, info);
1293 fbcon_clear_margins(vc, 1);
1294 scrollback_max += count;
1295 if (scrollback_max > scrollback_phys_max)
1296 scrollback_max = scrollback_phys_max;
1297 scrollback_current = 0;
1300 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1302 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1303 struct display *p = &fb_display[vc->vc_num];
1306 p->yscroll += count;
1307 if (p->yscroll > p->vrows - vc->vc_rows) {
1308 p->yscroll -= p->vrows - vc->vc_rows;
1312 info->var.xoffset = 0;
1313 info->var.yoffset = p->yscroll * vc->vc_font.height;
1314 info->var.vmode &= ~FB_VMODE_YWRAP;
1316 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1317 update_var(vc->vc_num, info);
1318 fbcon_clear_margins(vc, 1);
1319 scrollback_max += count;
1320 if (scrollback_max > scrollback_phys_max)
1321 scrollback_max = scrollback_phys_max;
1322 scrollback_current = 0;
1325 static __inline__ void ypan_down(struct vc_data *vc, int count)
1327 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1328 struct display *p = &fb_display[vc->vc_num];
1329 struct fbcon_ops *ops = info->fbcon_par;
1331 p->yscroll -= count;
1332 if (p->yscroll < 0) {
1333 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1334 0, vc->vc_rows, vc->vc_cols);
1335 p->yscroll += p->vrows - vc->vc_rows;
1337 info->var.xoffset = 0;
1338 info->var.yoffset = p->yscroll * vc->vc_font.height;
1339 info->var.vmode &= ~FB_VMODE_YWRAP;
1340 update_var(vc->vc_num, info);
1341 fbcon_clear_margins(vc, 1);
1342 scrollback_max -= count;
1343 if (scrollback_max < 0)
1345 scrollback_current = 0;
1348 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1350 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1351 struct display *p = &fb_display[vc->vc_num];
1354 p->yscroll -= count;
1355 if (p->yscroll < 0) {
1356 p->yscroll += p->vrows - vc->vc_rows;
1359 info->var.xoffset = 0;
1360 info->var.yoffset = p->yscroll * vc->vc_font.height;
1361 info->var.vmode &= ~FB_VMODE_YWRAP;
1363 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1364 update_var(vc->vc_num, info);
1365 fbcon_clear_margins(vc, 1);
1366 scrollback_max -= count;
1367 if (scrollback_max < 0)
1369 scrollback_current = 0;
1372 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1375 int count = vc->vc_rows;
1376 unsigned short *d, *s;
1380 d = (u16 *) softback_curr;
1381 if (d == (u16 *) softback_in)
1382 d = (u16 *) vc->vc_origin;
1383 n = softback_curr + delta * vc->vc_size_row;
1384 softback_lines -= delta;
1386 if (softback_curr < softback_top && n < softback_buf) {
1387 n += softback_end - softback_buf;
1388 if (n < softback_top) {
1390 (softback_top - n) / vc->vc_size_row;
1393 } else if (softback_curr >= softback_top
1394 && n < softback_top) {
1396 (softback_top - n) / vc->vc_size_row;
1400 if (softback_curr > softback_in && n >= softback_end) {
1401 n += softback_buf - softback_end;
1402 if (n > softback_in) {
1406 } else if (softback_curr <= softback_in && n > softback_in) {
1411 if (n == softback_curr)
1414 s = (u16 *) softback_curr;
1415 if (s == (u16 *) softback_in)
1416 s = (u16 *) vc->vc_origin;
1418 unsigned short *start;
1422 unsigned short attr = 1;
1425 le = advance_row(s, 1);
1428 if (attr != (c & 0xff00)) {
1431 fbcon_putcs(vc, start, s - start,
1437 if (c == scr_readw(d)) {
1439 fbcon_putcs(vc, start, s - start,
1452 fbcon_putcs(vc, start, s - start, line, x);
1454 if (d == (u16 *) softback_end)
1455 d = (u16 *) softback_buf;
1456 if (d == (u16 *) softback_in)
1457 d = (u16 *) vc->vc_origin;
1458 if (s == (u16 *) softback_end)
1459 s = (u16 *) softback_buf;
1460 if (s == (u16 *) softback_in)
1461 s = (u16 *) vc->vc_origin;
1465 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1466 int line, int count, int dy)
1468 unsigned short *s = (unsigned short *)
1469 (vc->vc_origin + vc->vc_size_row * line);
1472 unsigned short *start = s;
1473 unsigned short *le = advance_row(s, 1);
1476 unsigned short attr = 1;
1480 if (attr != (c & 0xff00)) {
1483 fbcon_putcs(vc, start, s - start,
1489 console_conditional_schedule();
1493 fbcon_putcs(vc, start, s - start, dy, x);
1494 console_conditional_schedule();
1499 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1500 int line, int count, int offset)
1502 unsigned short *d = (unsigned short *)
1503 (vc->vc_origin + vc->vc_size_row * line);
1504 unsigned short *s = d + offset;
1507 unsigned short *start = s;
1508 unsigned short *le = advance_row(s, 1);
1511 unsigned short attr = 1;
1515 if (attr != (c & 0xff00)) {
1518 fbcon_putcs(vc, start, s - start,
1524 if (c == scr_readw(d)) {
1526 fbcon_putcs(vc, start, s - start,
1536 console_conditional_schedule();
1541 fbcon_putcs(vc, start, s - start, line, x);
1542 console_conditional_schedule();
1547 /* NOTE: We subtract two lines from these pointers */
1548 s -= vc->vc_size_row;
1549 d -= vc->vc_size_row;
1554 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1559 if (vc->vc_num != fg_console)
1561 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1564 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1566 p = advance_row(p, 1);
1567 softback_in += vc->vc_size_row;
1568 if (softback_in == softback_end)
1569 softback_in = softback_buf;
1570 if (softback_in == softback_top) {
1571 softback_top += vc->vc_size_row;
1572 if (softback_top == softback_end)
1573 softback_top = softback_buf;
1576 softback_curr = softback_in;
1579 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1582 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1583 struct display *p = &fb_display[vc->vc_num];
1584 struct fbcon_ops *ops = info->fbcon_par;
1585 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1587 if (fbcon_is_inactive(vc, info))
1590 fbcon_cursor(vc, CM_ERASE);
1593 * ++Geert: Only use ywrap/ypan if the console is in text mode
1594 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1595 * whole screen (prevents flicker).
1600 if (count > vc->vc_rows) /* Maximum realistic size */
1601 count = vc->vc_rows;
1603 fbcon_softback_note(vc, t, count);
1604 if (logo_shown >= 0)
1606 switch (p->scrollmode) {
1608 ops->bmove(vc, info, t + count, 0, t, 0,
1609 b - t - count, vc->vc_cols);
1610 ops->clear(vc, info, b - count, 0, count,
1614 case SCROLL_WRAP_MOVE:
1615 if (b - t - count > 3 * vc->vc_rows >> 2) {
1617 fbcon_bmove(vc, 0, 0, count, 0, t,
1619 ywrap_up(vc, count);
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);
1632 case SCROLL_PAN_REDRAW:
1633 if ((p->yscroll + count <=
1634 2 * (p->vrows - vc->vc_rows))
1635 && ((!scroll_partial && (b - t == vc->vc_rows))
1638 3 * vc->vc_rows >> 2)))) {
1640 fbcon_redraw_move(vc, p, 0, t, count);
1641 ypan_up_redraw(vc, t, count);
1642 if (vc->vc_rows - b > 0)
1643 fbcon_redraw_move(vc, p, b - count,
1644 vc->vc_rows - b, b);
1646 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1647 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1650 case SCROLL_PAN_MOVE:
1651 if ((p->yscroll + count <=
1652 2 * (p->vrows - vc->vc_rows))
1653 && ((!scroll_partial && (b - t == vc->vc_rows))
1656 3 * vc->vc_rows >> 2)))) {
1658 fbcon_bmove(vc, 0, 0, count, 0, t,
1661 if (vc->vc_rows - b > 0)
1662 fbcon_bmove(vc, b - count, 0, b, 0,
1665 } else if (info->flags & FBINFO_READS_FAST)
1666 fbcon_bmove(vc, t + count, 0, t, 0,
1667 b - t - count, vc->vc_cols);
1670 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1675 fbcon_redraw(vc, p, t, b - t - count,
1676 count * vc->vc_cols);
1677 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1678 scr_memsetw((unsigned short *) (vc->vc_origin +
1681 vc->vc_video_erase_char,
1682 vc->vc_size_row * count);
1688 if (count > vc->vc_rows) /* Maximum realistic size */
1689 count = vc->vc_rows;
1690 switch (p->scrollmode) {
1692 ops->bmove(vc, info, t, 0, t + count, 0,
1693 b - t - count, vc->vc_cols);
1694 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1697 case SCROLL_WRAP_MOVE:
1698 if (b - t - count > 3 * vc->vc_rows >> 2) {
1699 if (vc->vc_rows - b > 0)
1700 fbcon_bmove(vc, b, 0, b - count, 0,
1703 ywrap_down(vc, count);
1705 fbcon_bmove(vc, count, 0, 0, 0, t,
1707 } else if (info->flags & FBINFO_READS_FAST)
1708 fbcon_bmove(vc, t, 0, t + count, 0,
1709 b - t - count, vc->vc_cols);
1712 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1715 case SCROLL_PAN_MOVE:
1716 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1717 && ((!scroll_partial && (b - t == vc->vc_rows))
1720 3 * vc->vc_rows >> 2)))) {
1721 if (vc->vc_rows - b > 0)
1722 fbcon_bmove(vc, b, 0, b - count, 0,
1725 ypan_down(vc, count);
1727 fbcon_bmove(vc, count, 0, 0, 0, t,
1729 } else if (info->flags & FBINFO_READS_FAST)
1730 fbcon_bmove(vc, t, 0, t + count, 0,
1731 b - t - count, vc->vc_cols);
1734 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1737 case SCROLL_PAN_REDRAW:
1738 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1739 && ((!scroll_partial && (b - t == vc->vc_rows))
1742 3 * vc->vc_rows >> 2)))) {
1743 if (vc->vc_rows - b > 0)
1744 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1746 ypan_down_redraw(vc, t, count);
1748 fbcon_redraw_move(vc, p, count, t, 0);
1750 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1751 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1756 fbcon_redraw(vc, p, b - 1, b - t - count,
1757 -count * vc->vc_cols);
1758 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1759 scr_memsetw((unsigned short *) (vc->vc_origin +
1762 vc->vc_video_erase_char,
1763 vc->vc_size_row * count);
1771 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1772 int height, int width)
1774 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1775 struct display *p = &fb_display[vc->vc_num];
1777 if (fbcon_is_inactive(vc, info))
1780 if (!width || !height)
1783 /* Split blits that cross physical y_wrap case.
1784 * Pathological case involves 4 blits, better to use recursive
1785 * code rather than unrolled case
1787 * Recursive invocations don't need to erase the cursor over and
1788 * over again, so we use fbcon_bmove_rec()
1790 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1791 p->vrows - p->yscroll);
1794 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1795 int dy, int dx, int height, int width, u_int y_break)
1797 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1798 struct fbcon_ops *ops = info->fbcon_par;
1801 if (sy < y_break && sy + height > y_break) {
1803 if (dy < sy) { /* Avoid trashing self */
1804 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1806 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1807 height - b, width, y_break);
1809 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1810 height - b, width, y_break);
1811 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1817 if (dy < y_break && dy + height > y_break) {
1819 if (dy < sy) { /* Avoid trashing self */
1820 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1822 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1823 height - b, width, y_break);
1825 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1826 height - b, width, y_break);
1827 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1832 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1836 static __inline__ void updatescrollmode(struct display *p, struct fb_info *info,
1839 int fh = vc->vc_font.height;
1840 int cap = info->flags;
1841 int good_pan = (cap & FBINFO_HWACCEL_YPAN)
1842 && divides(info->fix.ypanstep, vc->vc_font.height)
1843 && info->var.yres_virtual > info->var.yres;
1844 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP)
1845 && divides(info->fix.ywrapstep, vc->vc_font.height)
1846 && divides(vc->vc_font.height, info->var.yres_virtual);
1847 int reading_fast = cap & FBINFO_READS_FAST;
1848 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) && !(cap & FBINFO_HWACCEL_DISABLED);
1849 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) && !(cap & FBINFO_HWACCEL_DISABLED);
1851 p->vrows = info->var.yres_virtual/fh;
1852 if (info->var.yres > (fh * (vc->vc_rows + 1)))
1853 p->vrows -= (info->var.yres - (fh * vc->vc_rows)) / fh;
1854 if ((info->var.yres % fh) && (info->var.yres_virtual % fh <
1855 info->var.yres % fh))
1858 if (good_wrap || good_pan) {
1859 if (reading_fast || fast_copyarea)
1860 p->scrollmode = good_wrap ? SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1862 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1865 if (reading_fast || (fast_copyarea && !fast_imageblit))
1866 p->scrollmode = SCROLL_MOVE;
1868 p->scrollmode = SCROLL_REDRAW;
1872 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1873 unsigned int height)
1875 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1876 struct display *p = &fb_display[vc->vc_num];
1877 struct fb_var_screeninfo var = info->var;
1879 int fw = vc->vc_font.width;
1880 int fh = vc->vc_font.height;
1882 var.xres = width * fw;
1883 var.yres = height * fh;
1884 x_diff = info->var.xres - var.xres;
1885 y_diff = info->var.yres - var.yres;
1886 if (x_diff < 0 || x_diff > fw || (y_diff < 0 || y_diff > fh)) {
1887 struct fb_videomode *mode;
1889 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
1890 mode = fb_find_best_mode(&var, &info->modelist);
1893 fb_videomode_to_var(&var, mode);
1894 if (width > var.xres/fw || height > var.yres/fh)
1897 * The following can probably have any value... Do we need to
1900 var.bits_per_pixel = p->bits_per_pixel;
1901 var.xres_virtual = p->xres_virtual;
1902 var.yres_virtual = p->yres_virtual;
1903 var.accel_flags = p->accel_flags;
1904 var.width = p->width;
1905 var.height = p->height;
1907 var.green = p->green;
1909 var.transp = p->transp;
1910 var.nonstd = p->nonstd;
1912 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
1913 if (CON_IS_VISIBLE(vc)) {
1914 var.activate = FB_ACTIVATE_NOW |
1916 fb_set_var(info, &var);
1918 var_to_display(p, &info->var, info);
1920 updatescrollmode(p, info, vc);
1924 static int fbcon_switch(struct vc_data *vc)
1926 struct fb_info *info;
1927 struct display *p = &fb_display[vc->vc_num];
1928 struct fb_var_screeninfo var;
1929 int i, prev_console;
1931 info = registered_fb[con2fb_map[vc->vc_num]];
1934 int l = fbcon_softback_size / vc->vc_size_row;
1936 fbcon_set_origin(vc);
1937 softback_top = softback_curr = softback_in = softback_buf;
1941 softback_end = softback_buf + l * vc->vc_size_row;
1943 /* Smaller scrollback makes no sense, and 0 would screw
1944 the operation totally */
1949 if (logo_shown >= 0) {
1950 struct vc_data *conp2 = vc_cons[logo_shown].d;
1952 if (conp2->vc_top == logo_lines
1953 && conp2->vc_bottom == conp2->vc_rows)
1955 logo_shown = FBCON_LOGO_CANSHOW;
1958 prev_console = ((struct fbcon_ops *)info->fbcon_par)->currcon;
1961 * FIXME: If we have multiple fbdev's loaded, we need to
1962 * update all info->currcon. Perhaps, we can place this
1963 * in a centralized structure, but this might break some
1966 * info->currcon = vc->vc_num;
1968 for (i = 0; i < FB_MAX; i++) {
1969 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
1970 struct fbcon_ops *ops = registered_fb[i]->fbcon_par;
1972 ops->currcon = vc->vc_num;
1975 memset(&var, 0, sizeof(struct fb_var_screeninfo));
1976 display_to_var(&var, p);
1977 var.activate = FB_ACTIVATE_NOW;
1980 * make sure we don't unnecessarily trip the memcmp()
1983 info->var.activate = var.activate;
1984 info->var.yoffset = info->var.xoffset = p->yscroll = 0;
1985 fb_set_var(info, &var);
1987 if (prev_console != -1 &&
1988 registered_fb[con2fb_map[prev_console]] != info &&
1989 info->fbops->fb_set_par)
1990 info->fbops->fb_set_par(info);
1992 set_blitting_type(vc, info, p);
1993 ((struct fbcon_ops *)info->fbcon_par)->cursor_reset = 1;
1995 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1996 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1997 updatescrollmode(p, info, vc);
1999 switch (p->scrollmode) {
2000 case SCROLL_WRAP_MOVE:
2001 scrollback_phys_max = p->vrows - vc->vc_rows;
2003 case SCROLL_PAN_MOVE:
2004 case SCROLL_PAN_REDRAW:
2005 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2006 if (scrollback_phys_max < 0)
2007 scrollback_phys_max = 0;
2010 scrollback_phys_max = 0;
2014 scrollback_current = 0;
2016 update_var(vc->vc_num, info);
2017 fbcon_set_palette(vc, color_table);
2018 fbcon_clear_margins(vc, 0);
2020 if (logo_shown == FBCON_LOGO_DRAW) {
2022 logo_shown = fg_console;
2023 /* This is protected above by initmem_freed */
2026 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2027 vc->vc_size_row * (vc->vc_bottom -
2034 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2038 unsigned short charmask = vc->vc_hi_font_mask ?
2040 unsigned short oldc;
2042 oldc = vc->vc_video_erase_char;
2043 vc->vc_video_erase_char &= charmask;
2044 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2045 vc->vc_video_erase_char = oldc;
2049 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2051 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2052 struct fbcon_ops *ops = info->fbcon_par;
2055 struct fb_var_screeninfo var = info->var;
2060 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2061 fb_set_var(info, &var);
2066 if (!fbcon_is_inactive(vc, info)) {
2067 if (ops->blank_state != blank) {
2068 ops->blank_state = blank;
2069 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2070 ops->cursor_flash = (!blank);
2072 if (fb_blank(info, blank))
2073 fbcon_generic_blank(vc, info, blank);
2083 static void fbcon_free_font(struct display *p)
2085 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2086 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2091 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2093 u8 *fontdata = vc->vc_font.data;
2094 u8 *data = font->data;
2097 font->width = vc->vc_font.width;
2098 font->height = vc->vc_font.height;
2099 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2103 if (font->width <= 8) {
2104 j = vc->vc_font.height;
2105 for (i = 0; i < font->charcount; i++) {
2106 memcpy(data, fontdata, j);
2107 memset(data + j, 0, 32 - j);
2111 } else if (font->width <= 16) {
2112 j = vc->vc_font.height * 2;
2113 for (i = 0; i < font->charcount; i++) {
2114 memcpy(data, fontdata, j);
2115 memset(data + j, 0, 64 - j);
2119 } else if (font->width <= 24) {
2120 for (i = 0; i < font->charcount; i++) {
2121 for (j = 0; j < vc->vc_font.height; j++) {
2122 *data++ = fontdata[0];
2123 *data++ = fontdata[1];
2124 *data++ = fontdata[2];
2125 fontdata += sizeof(u32);
2127 memset(data, 0, 3 * (32 - j));
2128 data += 3 * (32 - j);
2131 j = vc->vc_font.height * 4;
2132 for (i = 0; i < font->charcount; i++) {
2133 memcpy(data, fontdata, j);
2134 memset(data + j, 0, 128 - j);
2142 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2143 u8 * data, int userfont)
2145 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2146 struct display *p = &fb_display[vc->vc_num];
2149 char *old_data = NULL;
2151 if (CON_IS_VISIBLE(vc) && softback_lines)
2152 fbcon_set_origin(vc);
2154 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2156 old_data = vc->vc_font.data;
2158 cnt = FNTCHARCNT(data);
2161 vc->vc_font.data = p->fontdata = data;
2162 if ((p->userfont = userfont))
2164 vc->vc_font.width = w;
2165 vc->vc_font.height = h;
2166 if (vc->vc_hi_font_mask && cnt == 256) {
2167 vc->vc_hi_font_mask = 0;
2168 if (vc->vc_can_do_color) {
2169 vc->vc_complement_mask >>= 1;
2170 vc->vc_s_complement_mask >>= 1;
2173 /* ++Edmund: reorder the attribute bits */
2174 if (vc->vc_can_do_color) {
2175 unsigned short *cp =
2176 (unsigned short *) vc->vc_origin;
2177 int count = vc->vc_screenbuf_size / 2;
2179 for (; count > 0; count--, cp++) {
2181 scr_writew(((c & 0xfe00) >> 1) |
2184 c = vc->vc_video_erase_char;
2185 vc->vc_video_erase_char =
2186 ((c & 0xfe00) >> 1) | (c & 0xff);
2189 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2190 vc->vc_hi_font_mask = 0x100;
2191 if (vc->vc_can_do_color) {
2192 vc->vc_complement_mask <<= 1;
2193 vc->vc_s_complement_mask <<= 1;
2196 /* ++Edmund: reorder the attribute bits */
2198 unsigned short *cp =
2199 (unsigned short *) vc->vc_origin;
2200 int count = vc->vc_screenbuf_size / 2;
2202 for (; count > 0; count--, cp++) {
2203 unsigned short newc;
2205 if (vc->vc_can_do_color)
2207 ((c & 0xff00) << 1) | (c &
2211 scr_writew(newc, cp);
2213 c = vc->vc_video_erase_char;
2214 if (vc->vc_can_do_color) {
2215 vc->vc_video_erase_char =
2216 ((c & 0xff00) << 1) | (c & 0xff);
2219 vc->vc_video_erase_char = c & ~0x100;
2225 /* reset wrap/pan */
2226 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2227 vc_resize(vc, info->var.xres / w, info->var.yres / h);
2228 if (CON_IS_VISIBLE(vc) && softback_buf) {
2229 int l = fbcon_softback_size / vc->vc_size_row;
2232 softback_buf + l * vc->vc_size_row;
2234 /* Smaller scrollback makes no sense, and 0 would screw
2235 the operation totally */
2239 } else if (CON_IS_VISIBLE(vc)
2240 && vc->vc_mode == KD_TEXT) {
2241 fbcon_clear_margins(vc, 0);
2245 if (old_data && (--REFCOUNT(old_data) == 0))
2246 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2250 static int fbcon_copy_font(struct vc_data *vc, int con)
2252 struct display *od = &fb_display[con];
2253 struct console_font *f = &vc->vc_font;
2255 if (od->fontdata == f->data)
2256 return 0; /* already the same font... */
2257 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2261 * User asked to set font; we are guaranteed that
2262 * a) width and height are in range 1..32
2263 * b) charcount does not exceed 512
2264 * but lets not assume that, since someone might someday want to use larger
2265 * fonts. And charcount of 512 is small for unicode support.
2267 * However, user space gives the font in 32 rows , regardless of
2268 * actual font height. So a new API is needed if support for larger fonts
2269 * is ever implemented.
2272 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2274 unsigned charcount = font->charcount;
2275 int w = font->width;
2276 int h = font->height;
2279 u8 *new_data, *data = font->data;
2280 int pitch = (font->width+7) >> 3;
2282 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2283 * If not this check should be changed to charcount < 256 */
2284 if (charcount != 256 && charcount != 512)
2287 size = h * pitch * charcount;
2289 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2294 new_data += FONT_EXTRA_WORDS * sizeof(int);
2295 FNTSIZE(new_data) = size;
2296 FNTCHARCNT(new_data) = charcount;
2297 REFCOUNT(new_data) = 0; /* usage counter */
2298 for (i=0; i< charcount; i++) {
2299 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2302 /* Since linux has a nice crc32 function use it for counting font
2304 csum = crc32(0, new_data, size);
2306 FNTSUM(new_data) = csum;
2307 /* Check if the same font is on some other console already */
2308 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2309 struct vc_data *tmp = vc_cons[i].d;
2311 if (fb_display[i].userfont &&
2312 fb_display[i].fontdata &&
2313 FNTSUM(fb_display[i].fontdata) == csum &&
2314 FNTSIZE(fb_display[i].fontdata) == size &&
2315 tmp->vc_font.width == w &&
2316 !memcmp(fb_display[i].fontdata, new_data, size)) {
2317 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2318 new_data = fb_display[i].fontdata;
2322 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2325 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2327 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2328 struct font_desc *f;
2331 f = get_default_font(info->var.xres, info->var.yres);
2332 else if (!(f = find_font(name)))
2335 font->width = f->width;
2336 font->height = f->height;
2337 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2340 static u16 palette_red[16];
2341 static u16 palette_green[16];
2342 static u16 palette_blue[16];
2344 static struct fb_cmap palette_cmap = {
2345 0, 16, palette_red, palette_green, palette_blue, NULL
2348 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2350 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2354 if (fbcon_is_inactive(vc, info))
2357 if (!CON_IS_VISIBLE(vc))
2360 depth = fb_get_color_depth(&info->var, &info->fix);
2362 for (i = j = 0; i < 16; i++) {
2364 val = vc->vc_palette[j++];
2365 palette_red[k] = (val << 8) | val;
2366 val = vc->vc_palette[j++];
2367 palette_green[k] = (val << 8) | val;
2368 val = vc->vc_palette[j++];
2369 palette_blue[k] = (val << 8) | val;
2371 palette_cmap.len = 16;
2372 palette_cmap.start = 0;
2374 * If framebuffer is capable of less than 16 colors,
2375 * use default palette of fbcon.
2378 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2380 return fb_set_cmap(&palette_cmap, info);
2383 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2388 if (vc->vc_num != fg_console || !softback_lines)
2389 return (u16 *) (vc->vc_origin + offset);
2390 line = offset / vc->vc_size_row;
2391 if (line >= softback_lines)
2392 return (u16 *) (vc->vc_origin + offset -
2393 softback_lines * vc->vc_size_row);
2394 p = softback_curr + offset;
2395 if (p >= softback_end)
2396 p += softback_buf - softback_end;
2400 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2406 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2407 unsigned long offset = (pos - vc->vc_origin) / 2;
2409 x = offset % vc->vc_cols;
2410 y = offset / vc->vc_cols;
2411 if (vc->vc_num == fg_console)
2412 y += softback_lines;
2413 ret = pos + (vc->vc_cols - x) * 2;
2414 } else if (vc->vc_num == fg_console && softback_lines) {
2415 unsigned long offset = pos - softback_curr;
2417 if (pos < softback_curr)
2418 offset += softback_end - softback_buf;
2420 x = offset % vc->vc_cols;
2421 y = offset / vc->vc_cols;
2422 ret = pos + (vc->vc_cols - x) * 2;
2423 if (ret == softback_end)
2425 if (ret == softback_in)
2426 ret = vc->vc_origin;
2428 /* Should not happen */
2430 ret = vc->vc_origin;
2439 /* As we might be inside of softback, we may work with non-contiguous buffer,
2440 that's why we have to use a separate routine. */
2441 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2444 u16 a = scr_readw(p);
2445 if (!vc->vc_can_do_color)
2447 else if (vc->vc_hi_font_mask == 0x100)
2448 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2449 (((a) & 0x0e00) << 4);
2451 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2452 (((a) & 0x0700) << 4);
2454 if (p == (u16 *) softback_end)
2455 p = (u16 *) softback_buf;
2456 if (p == (u16 *) softback_in)
2457 p = (u16 *) vc->vc_origin;
2461 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2463 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2464 struct display *p = &fb_display[fg_console];
2465 int offset, limit, scrollback_old;
2468 if (vc->vc_num != fg_console)
2470 if (vc->vc_mode != KD_TEXT || !lines)
2472 if (logo_shown >= 0) {
2473 struct vc_data *conp2 = vc_cons[logo_shown].d;
2475 if (conp2->vc_top == logo_lines
2476 && conp2->vc_bottom == conp2->vc_rows)
2478 if (logo_shown == vc->vc_num) {
2484 logo_lines * vc->vc_size_row;
2485 for (i = 0; i < logo_lines; i++) {
2486 if (p == softback_top)
2488 if (p == softback_buf)
2490 p -= vc->vc_size_row;
2491 q -= vc->vc_size_row;
2492 scr_memcpyw((u16 *) q, (u16 *) p,
2496 update_region(vc, vc->vc_origin,
2497 logo_lines * vc->vc_cols);
2499 logo_shown = FBCON_LOGO_CANSHOW;
2501 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2502 fbcon_redraw_softback(vc, p, lines);
2503 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2507 if (!scrollback_phys_max)
2510 scrollback_old = scrollback_current;
2511 scrollback_current -= lines;
2512 if (scrollback_current < 0)
2513 scrollback_current = 0;
2514 else if (scrollback_current > scrollback_max)
2515 scrollback_current = scrollback_max;
2516 if (scrollback_current == scrollback_old)
2519 if (fbcon_is_inactive(vc, info))
2522 fbcon_cursor(vc, CM_ERASE);
2524 offset = p->yscroll - scrollback_current;
2526 switch (p->scrollmode) {
2527 case SCROLL_WRAP_MOVE:
2528 info->var.vmode |= FB_VMODE_YWRAP;
2530 case SCROLL_PAN_MOVE:
2531 case SCROLL_PAN_REDRAW:
2532 limit -= vc->vc_rows;
2533 info->var.vmode &= ~FB_VMODE_YWRAP;
2538 else if (offset >= limit)
2540 info->var.xoffset = 0;
2541 info->var.yoffset = offset * vc->vc_font.height;
2542 update_var(vc->vc_num, info);
2543 if (!scrollback_current)
2544 fbcon_cursor(vc, CM_DRAW);
2548 static int fbcon_set_origin(struct vc_data *vc)
2551 fbcon_scrolldelta(vc, softback_lines);
2555 static void fbcon_suspended(struct fb_info *info)
2557 struct vc_data *vc = NULL;
2558 struct fbcon_ops *ops = info->fbcon_par;
2560 if (!ops || ops->currcon < 0)
2562 vc = vc_cons[ops->currcon].d;
2564 /* Clear cursor, restore saved data */
2565 fbcon_cursor(vc, CM_ERASE);
2568 static void fbcon_resumed(struct fb_info *info)
2571 struct fbcon_ops *ops = info->fbcon_par;
2573 if (!ops || ops->currcon < 0)
2575 vc = vc_cons[ops->currcon].d;
2580 static void fbcon_modechanged(struct fb_info *info)
2582 struct fbcon_ops *ops = info->fbcon_par;
2587 if (!ops || ops->currcon < 0)
2589 vc = vc_cons[ops->currcon].d;
2590 if (vc->vc_mode != KD_TEXT || registered_fb[con2fb_map[ops->currcon]] != info)
2593 p = &fb_display[vc->vc_num];
2595 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2597 if (CON_IS_VISIBLE(vc)) {
2598 var_to_display(p, &info->var, info);
2599 cols = info->var.xres / vc->vc_font.width;
2600 rows = info->var.yres / vc->vc_font.height;
2601 vc_resize(vc, cols, rows);
2602 updatescrollmode(p, info, vc);
2604 scrollback_current = 0;
2605 update_var(vc->vc_num, info);
2606 fbcon_set_palette(vc, color_table);
2609 int l = fbcon_softback_size / vc->vc_size_row;
2611 softback_end = softback_buf + l * vc->vc_size_row;
2613 /* Smaller scrollback makes no sense, and 0
2614 would screw the operation totally */
2621 static void fbcon_set_all_vcs(struct fb_info *info)
2623 struct fbcon_ops *ops = info->fbcon_par;
2628 if (!ops || ops->currcon < 0)
2631 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2633 if (!vc || vc->vc_mode != KD_TEXT ||
2634 registered_fb[con2fb_map[i]] != info)
2637 p = &fb_display[vc->vc_num];
2639 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2640 var_to_display(p, &info->var, info);
2641 cols = info->var.xres / vc->vc_font.width;
2642 rows = info->var.yres / vc->vc_font.height;
2643 vc_resize(vc, cols, rows);
2645 if (CON_IS_VISIBLE(vc)) {
2646 updatescrollmode(p, info, vc);
2648 scrollback_current = 0;
2649 update_var(vc->vc_num, info);
2650 fbcon_set_palette(vc, color_table);
2653 int l = fbcon_softback_size / vc->vc_size_row;
2655 softback_end = softback_buf + l * vc->vc_size_row;
2657 /* Smaller scrollback makes no sense, and 0
2658 would screw the operation totally */
2666 static int fbcon_mode_deleted(struct fb_info *info,
2667 struct fb_videomode *mode)
2669 struct fb_info *fb_info;
2671 int i, j, found = 0;
2673 /* before deletion, ensure that mode is not in use */
2674 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2678 fb_info = registered_fb[j];
2679 if (fb_info != info)
2684 if (fb_mode_is_equal(p->mode, mode)) {
2692 static int fbcon_fb_registered(int idx)
2696 if (info_idx == -1) {
2697 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2698 if (con2fb_map_boot[i] == idx) {
2704 ret = fbcon_takeover(1);
2706 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2707 if (con2fb_map_boot[i] == idx)
2708 set_con2fb_map(i, idx, 0);
2715 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2717 struct fbcon_ops *ops = info->fbcon_par;
2720 if (!ops || ops->currcon < 0)
2723 vc = vc_cons[ops->currcon].d;
2724 if (vc->vc_mode != KD_TEXT ||
2725 registered_fb[con2fb_map[ops->currcon]] != info)
2728 if (CON_IS_VISIBLE(vc)) {
2732 do_unblank_screen(0);
2734 ops->blank_state = blank;
2737 static void fbcon_new_modelist(struct fb_info *info)
2741 struct fb_var_screeninfo var;
2742 struct fb_videomode *mode;
2744 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2745 if (registered_fb[con2fb_map[i]] != info)
2747 if (!fb_display[i].mode)
2750 display_to_var(&var, &fb_display[i]);
2751 mode = fb_find_nearest_mode(&var, &info->modelist);
2752 fb_videomode_to_var(&var, mode);
2755 fbcon_set_disp(info, &var, vc);
2757 fbcon_preset_disp(info, &var, i);
2762 static int fbcon_event_notify(struct notifier_block *self,
2763 unsigned long action, void *data)
2765 struct fb_event *event = data;
2766 struct fb_info *info = event->info;
2767 struct fb_videomode *mode;
2768 struct fb_con2fbmap *con2fb;
2772 case FB_EVENT_SUSPEND:
2773 fbcon_suspended(info);
2775 case FB_EVENT_RESUME:
2776 fbcon_resumed(info);
2778 case FB_EVENT_MODE_CHANGE:
2779 fbcon_modechanged(info);
2781 case FB_EVENT_MODE_CHANGE_ALL:
2782 fbcon_set_all_vcs(info);
2784 case FB_EVENT_MODE_DELETE:
2786 ret = fbcon_mode_deleted(info, mode);
2788 case FB_EVENT_FB_REGISTERED:
2789 ret = fbcon_fb_registered(info->node);
2791 case FB_EVENT_SET_CONSOLE_MAP:
2792 con2fb = event->data;
2793 ret = set_con2fb_map(con2fb->console - 1,
2794 con2fb->framebuffer, 1);
2796 case FB_EVENT_GET_CONSOLE_MAP:
2797 con2fb = event->data;
2798 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2800 case FB_EVENT_BLANK:
2801 fbcon_fb_blanked(info, *(int *)event->data);
2803 case FB_EVENT_NEW_MODELIST:
2804 fbcon_new_modelist(info);
2812 * The console `switch' structure for the frame buffer based console
2815 static const struct consw fb_con = {
2816 .owner = THIS_MODULE,
2817 .con_startup = fbcon_startup,
2818 .con_init = fbcon_init,
2819 .con_deinit = fbcon_deinit,
2820 .con_clear = fbcon_clear,
2821 .con_putc = fbcon_putc,
2822 .con_putcs = fbcon_putcs,
2823 .con_cursor = fbcon_cursor,
2824 .con_scroll = fbcon_scroll,
2825 .con_bmove = fbcon_bmove,
2826 .con_switch = fbcon_switch,
2827 .con_blank = fbcon_blank,
2828 .con_font_set = fbcon_set_font,
2829 .con_font_get = fbcon_get_font,
2830 .con_font_default = fbcon_set_def_font,
2831 .con_font_copy = fbcon_copy_font,
2832 .con_set_palette = fbcon_set_palette,
2833 .con_scrolldelta = fbcon_scrolldelta,
2834 .con_set_origin = fbcon_set_origin,
2835 .con_invert_region = fbcon_invert_region,
2836 .con_screen_pos = fbcon_screen_pos,
2837 .con_getxy = fbcon_getxy,
2838 .con_resize = fbcon_resize,
2841 static struct notifier_block fbcon_event_notifier = {
2842 .notifier_call = fbcon_event_notify,
2845 static int __init fb_console_init(void)
2849 acquire_console_sem();
2850 fb_register_client(&fbcon_event_notifier);
2851 release_console_sem();
2853 for (i = 0; i < MAX_NR_CONSOLES; i++)
2856 if (num_registered_fb) {
2857 for (i = 0; i < FB_MAX; i++) {
2858 if (registered_fb[i] != NULL) {
2869 module_init(fb_console_init);
2873 static void __exit fb_console_exit(void)
2875 acquire_console_sem();
2876 fb_unregister_client(&fbcon_event_notifier);
2877 release_console_sem();
2878 give_up_console(&fb_con);
2881 module_exit(fb_console_exit);
2885 MODULE_LICENSE("GPL");