2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
79 #include <asm/system.h>
80 #include <asm/uaccess.h>
82 #include <asm/atariints.h>
85 #include <asm/macints.h>
87 #if defined(__mc68000__) || defined(CONFIG_APUS)
88 #include <asm/machdep.h>
89 #include <asm/setup.h>
95 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
97 # define DPRINTK(fmt, args...)
101 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
106 static struct display fb_display[MAX_NR_CONSOLES];
108 static signed char con2fb_map[MAX_NR_CONSOLES];
109 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
110 static int logo_height;
111 static int logo_lines;
112 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
114 static int logo_shown = FBCON_LOGO_CANSHOW;
115 /* Software scrollback */
116 static int fbcon_softback_size = 32768;
117 static unsigned long softback_buf, softback_curr;
118 static unsigned long softback_in;
119 static unsigned long softback_top, softback_end;
120 static int softback_lines;
121 /* console mappings */
122 static int first_fb_vc;
123 static int last_fb_vc = MAX_NR_CONSOLES - 1;
124 static int fbcon_is_default = 1;
125 static int fbcon_has_exited;
128 static char fontname[40];
130 /* current fb_info */
131 static int info_idx = -1;
133 /* console rotation */
135 static int fbcon_has_sysfs;
137 static const struct consw fb_con;
139 #define CM_SOFTBACK (8)
141 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
143 static int fbcon_set_origin(struct vc_data *);
145 #define CURSOR_DRAW_DELAY (1)
147 /* # VBL ints between cursor state changes */
148 #define ATARI_CURSOR_BLINK_RATE (42)
149 #define MAC_CURSOR_BLINK_RATE (32)
150 #define DEFAULT_CURSOR_BLINK_RATE (20)
152 static int vbl_cursor_cnt;
154 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
157 * Interface used by the world
160 static const char *fbcon_startup(void);
161 static void fbcon_init(struct vc_data *vc, int init);
162 static void fbcon_deinit(struct vc_data *vc);
163 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
165 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
166 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
167 int count, int ypos, int xpos);
168 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
169 static void fbcon_cursor(struct vc_data *vc, int mode);
170 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
172 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
173 int height, int width);
174 static int fbcon_switch(struct vc_data *vc);
175 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
176 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
177 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
182 static __inline__ void ywrap_up(struct vc_data *vc, int count);
183 static __inline__ void ywrap_down(struct vc_data *vc, int count);
184 static __inline__ void ypan_up(struct vc_data *vc, int count);
185 static __inline__ void ypan_down(struct vc_data *vc, int count);
186 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
187 int dy, int dx, int height, int width, u_int y_break);
188 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
190 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
192 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
193 int line, int count, int dy);
194 static void fbcon_modechanged(struct fb_info *info);
195 static void fbcon_set_all_vcs(struct fb_info *info);
196 static void fbcon_start(void);
197 static void fbcon_exit(void);
198 static struct class_device *fbcon_class_device;
202 * On the Macintoy, there may or may not be a working VBL int. We need to probe
204 static int vbl_detected;
206 static irqreturn_t fb_vbl_detect(int irq, void *dummy)
213 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
214 static inline void fbcon_set_rotation(struct fb_info *info)
216 struct fbcon_ops *ops = info->fbcon_par;
218 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
219 ops->p->con_rotate < 4)
220 ops->rotate = ops->p->con_rotate;
225 static void fbcon_rotate(struct fb_info *info, u32 rotate)
227 struct fbcon_ops *ops= info->fbcon_par;
228 struct fb_info *fb_info;
230 if (!ops || ops->currcon == -1)
233 fb_info = registered_fb[con2fb_map[ops->currcon]];
235 if (info == fb_info) {
236 struct display *p = &fb_display[ops->currcon];
239 p->con_rotate = rotate;
243 fbcon_modechanged(info);
247 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
249 struct fbcon_ops *ops = info->fbcon_par;
254 if (!ops || ops->currcon < 0 || rotate > 3)
257 for (i = first_fb_vc; i <= last_fb_vc; i++) {
259 if (!vc || vc->vc_mode != KD_TEXT ||
260 registered_fb[con2fb_map[i]] != info)
263 p = &fb_display[vc->vc_num];
264 p->con_rotate = rotate;
267 fbcon_set_all_vcs(info);
270 static inline void fbcon_set_rotation(struct fb_info *info)
272 struct fbcon_ops *ops = info->fbcon_par;
274 ops->rotate = FB_ROTATE_UR;
277 static void fbcon_rotate(struct fb_info *info, u32 rotate)
282 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
286 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
288 static int fbcon_get_rotate(struct fb_info *info)
290 struct fbcon_ops *ops = info->fbcon_par;
292 return (ops) ? ops->rotate : 0;
295 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
297 struct fbcon_ops *ops = info->fbcon_par;
299 return (info->state != FBINFO_STATE_RUNNING ||
300 vc->vc_mode != KD_TEXT || ops->graphics);
303 static inline int get_color(struct vc_data *vc, struct fb_info *info,
306 int depth = fb_get_color_depth(&info->var, &info->fix);
309 if (console_blanked) {
310 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
312 c = vc->vc_video_erase_char & charmask;
316 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
317 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
322 int col = ~(0xfff << (max(info->var.green.length,
323 max(info->var.red.length,
324 info->var.blue.length)))) & 0xff;
327 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
328 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
333 color = (is_fg) ? fg : bg;
338 * Scale down 16-colors to 4 colors. Default 4-color palette
339 * is grayscale. However, simply dividing the values by 4
340 * will not work, as colors 1, 2 and 3 will be scaled-down
341 * to zero rendering them invisible. So empirically convert
342 * colors to a sane 4-level grayscale.
346 color = 0; /* black */
349 color = 2; /* white */
352 color = 1; /* gray */
355 color = 3; /* intense white */
361 * Last 8 entries of default 16-color palette is a more intense
362 * version of the first 8 (i.e., same chrominance, different
373 static void fbcon_update_softback(struct vc_data *vc)
375 int l = fbcon_softback_size / vc->vc_size_row;
378 softback_end = softback_buf + l * vc->vc_size_row;
380 /* Smaller scrollback makes no sense, and 0 would screw
381 the operation totally */
385 static void fb_flashcursor(struct work_struct *work)
387 struct fb_info *info = container_of(work, struct fb_info, queue);
388 struct fbcon_ops *ops = info->fbcon_par;
390 struct vc_data *vc = NULL;
394 acquire_console_sem();
395 if (ops && ops->currcon != -1)
396 vc = vc_cons[ops->currcon].d;
398 if (!vc || !CON_IS_VISIBLE(vc) ||
399 registered_fb[con2fb_map[vc->vc_num]] != info ||
401 release_console_sem();
405 p = &fb_display[vc->vc_num];
406 c = scr_readw((u16 *) vc->vc_pos);
407 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
409 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
410 get_color(vc, info, c, 0));
411 release_console_sem();
414 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
415 static int cursor_blink_rate;
416 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
418 struct fb_info *info = dev_id;
420 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
421 schedule_work(&info->queue);
422 vbl_cursor_cnt = cursor_blink_rate;
428 static void cursor_timer_handler(unsigned long dev_addr)
430 struct fb_info *info = (struct fb_info *) dev_addr;
431 struct fbcon_ops *ops = info->fbcon_par;
433 schedule_work(&info->queue);
434 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
437 static void fbcon_add_cursor_timer(struct fb_info *info)
439 struct fbcon_ops *ops = info->fbcon_par;
441 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
442 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
443 if (!info->queue.func)
444 INIT_WORK(&info->queue, fb_flashcursor);
446 init_timer(&ops->cursor_timer);
447 ops->cursor_timer.function = cursor_timer_handler;
448 ops->cursor_timer.expires = jiffies + HZ / 5;
449 ops->cursor_timer.data = (unsigned long ) info;
450 add_timer(&ops->cursor_timer);
451 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
455 static void fbcon_del_cursor_timer(struct fb_info *info)
457 struct fbcon_ops *ops = info->fbcon_par;
459 if (info->queue.func == fb_flashcursor &&
460 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
461 del_timer_sync(&ops->cursor_timer);
462 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
467 static int __init fb_console_setup(char *this_opt)
472 if (!this_opt || !*this_opt)
475 while ((options = strsep(&this_opt, ",")) != NULL) {
476 if (!strncmp(options, "font:", 5))
477 strcpy(fontname, options + 5);
479 if (!strncmp(options, "scrollback:", 11)) {
482 fbcon_softback_size = simple_strtoul(options, &options, 0);
483 if (*options == 'k' || *options == 'K') {
484 fbcon_softback_size *= 1024;
494 if (!strncmp(options, "map:", 4)) {
497 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
501 (options[j++]-'0') % FB_MAX;
506 if (!strncmp(options, "vc:", 3)) {
509 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
512 if (*options++ == '-')
513 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
514 fbcon_is_default = 0;
517 if (!strncmp(options, "rotate:", 7)) {
520 rotate = simple_strtoul(options, &options, 0);
528 __setup("fbcon=", fb_console_setup);
531 static int search_fb_in_map(int idx)
535 for (i = first_fb_vc; i <= last_fb_vc; i++) {
536 if (con2fb_map[i] == idx)
542 static int search_for_mapped_con(void)
546 for (i = first_fb_vc; i <= last_fb_vc; i++) {
547 if (con2fb_map[i] != -1)
553 static int fbcon_takeover(int show_logo)
557 if (!num_registered_fb)
561 logo_shown = FBCON_LOGO_DONTSHOW;
563 for (i = first_fb_vc; i <= last_fb_vc; i++)
564 con2fb_map[i] = info_idx;
566 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
570 for (i = first_fb_vc; i <= last_fb_vc; i++) {
579 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
580 int cols, int rows, int new_cols, int new_rows)
582 /* Need to make room for the logo */
583 struct fbcon_ops *ops = info->fbcon_par;
584 int cnt, erase = vc->vc_video_erase_char, step;
585 unsigned short *save = NULL, *r, *q;
588 * remove underline attribute from erase character
589 * if black and white framebuffer.
591 if (fb_get_color_depth(&info->var, &info->fix) == 1)
593 logo_height = fb_prepare_logo(info, ops->rotate);
594 logo_lines = (logo_height + vc->vc_font.height - 1) /
596 q = (unsigned short *) (vc->vc_origin +
597 vc->vc_size_row * rows);
598 step = logo_lines * cols;
599 for (r = q - logo_lines * cols; r < q; r++)
600 if (scr_readw(r) != vc->vc_video_erase_char)
602 if (r != q && new_rows >= rows + logo_lines) {
603 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
605 int i = cols < new_cols ? cols : new_cols;
606 scr_memsetw(save, erase, logo_lines * new_cols * 2);
608 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
609 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
614 /* We can scroll screen down */
616 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
617 scr_memcpyw(r + step, r, vc->vc_size_row);
621 vc->vc_y += logo_lines;
622 vc->vc_pos += logo_lines * vc->vc_size_row;
625 scr_memsetw((unsigned short *) vc->vc_origin,
627 vc->vc_size_row * logo_lines);
629 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
630 fbcon_clear_margins(vc, 0);
635 q = (unsigned short *) (vc->vc_origin +
638 scr_memcpyw(q, save, logo_lines * new_cols * 2);
639 vc->vc_y += logo_lines;
640 vc->vc_pos += logo_lines * vc->vc_size_row;
644 if (logo_lines > vc->vc_bottom) {
645 logo_shown = FBCON_LOGO_CANSHOW;
647 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
648 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
649 logo_shown = FBCON_LOGO_DRAW;
650 vc->vc_top = logo_lines;
654 #ifdef CONFIG_FB_TILEBLITTING
655 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
657 struct fbcon_ops *ops = info->fbcon_par;
659 ops->p = &fb_display[vc->vc_num];
661 if ((info->flags & FBINFO_MISC_TILEBLITTING))
662 fbcon_set_tileops(vc, info);
664 fbcon_set_rotation(info);
665 fbcon_set_bitops(ops);
669 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
671 struct fbcon_ops *ops = info->fbcon_par;
673 info->flags &= ~FBINFO_MISC_TILEBLITTING;
674 ops->p = &fb_display[vc->vc_num];
675 fbcon_set_rotation(info);
676 fbcon_set_bitops(ops);
678 #endif /* CONFIG_MISC_TILEBLITTING */
681 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
682 int unit, int oldidx)
684 struct fbcon_ops *ops = NULL;
687 if (!try_module_get(info->fbops->owner))
690 if (!err && info->fbops->fb_open &&
691 info->fbops->fb_open(info, 0))
695 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
701 info->fbcon_par = ops;
702 set_blitting_type(vc, info);
706 con2fb_map[unit] = oldidx;
707 module_put(info->fbops->owner);
713 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
714 struct fb_info *newinfo, int unit,
715 int oldidx, int found)
717 struct fbcon_ops *ops = oldinfo->fbcon_par;
720 if (oldinfo->fbops->fb_release &&
721 oldinfo->fbops->fb_release(oldinfo, 0)) {
722 con2fb_map[unit] = oldidx;
723 if (!found && newinfo->fbops->fb_release)
724 newinfo->fbops->fb_release(newinfo, 0);
726 module_put(newinfo->fbops->owner);
731 fbcon_del_cursor_timer(oldinfo);
732 kfree(ops->cursor_state.mask);
733 kfree(ops->cursor_data);
734 kfree(ops->fontbuffer);
735 kfree(oldinfo->fbcon_par);
736 oldinfo->fbcon_par = NULL;
737 module_put(oldinfo->fbops->owner);
739 If oldinfo and newinfo are driving the same hardware,
740 the fb_release() method of oldinfo may attempt to
741 restore the hardware state. This will leave the
742 newinfo in an undefined state. Thus, a call to
743 fb_set_par() may be needed for the newinfo.
745 if (newinfo->fbops->fb_set_par)
746 newinfo->fbops->fb_set_par(newinfo);
752 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
753 int unit, int show_logo)
755 struct fbcon_ops *ops = info->fbcon_par;
757 ops->currcon = fg_console;
759 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
760 info->fbops->fb_set_par(info);
762 ops->flags |= FBCON_FLAGS_INIT;
766 fbcon_set_disp(info, &info->var, vc);
768 fbcon_preset_disp(info, &info->var, unit);
771 struct vc_data *fg_vc = vc_cons[fg_console].d;
772 struct fb_info *fg_info =
773 registered_fb[con2fb_map[fg_console]];
775 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
776 fg_vc->vc_rows, fg_vc->vc_cols,
780 update_screen(vc_cons[fg_console].d);
784 * set_con2fb_map - map console to frame buffer device
785 * @unit: virtual console number to map
786 * @newidx: frame buffer index to map virtual console to
787 * @user: user request
789 * Maps a virtual console @unit to a frame buffer device
792 static int set_con2fb_map(int unit, int newidx, int user)
794 struct vc_data *vc = vc_cons[unit].d;
795 int oldidx = con2fb_map[unit];
796 struct fb_info *info = registered_fb[newidx];
797 struct fb_info *oldinfo = NULL;
800 if (oldidx == newidx)
803 if (!info || fbcon_has_exited)
806 if (!err && !search_for_mapped_con()) {
808 return fbcon_takeover(0);
812 oldinfo = registered_fb[oldidx];
814 found = search_fb_in_map(newidx);
816 acquire_console_sem();
817 con2fb_map[unit] = newidx;
819 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
823 * If old fb is not mapped to any of the consoles,
824 * fbcon should release it.
826 if (!err && oldinfo && !search_fb_in_map(oldidx))
827 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
831 int show_logo = (fg_console == 0 && !user &&
832 logo_shown != FBCON_LOGO_DONTSHOW);
835 fbcon_add_cursor_timer(info);
836 con2fb_map_boot[unit] = newidx;
837 con2fb_init_display(vc, info, unit, show_logo);
840 if (!search_fb_in_map(info_idx))
843 release_console_sem();
848 * Low Level Operations
850 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
851 static int var_to_display(struct display *disp,
852 struct fb_var_screeninfo *var,
853 struct fb_info *info)
855 disp->xres_virtual = var->xres_virtual;
856 disp->yres_virtual = var->yres_virtual;
857 disp->bits_per_pixel = var->bits_per_pixel;
858 disp->grayscale = var->grayscale;
859 disp->nonstd = var->nonstd;
860 disp->accel_flags = var->accel_flags;
861 disp->height = var->height;
862 disp->width = var->width;
863 disp->red = var->red;
864 disp->green = var->green;
865 disp->blue = var->blue;
866 disp->transp = var->transp;
867 disp->rotate = var->rotate;
868 disp->mode = fb_match_mode(var, &info->modelist);
869 if (disp->mode == NULL)
870 /* This should not happen */
875 static void display_to_var(struct fb_var_screeninfo *var,
876 struct display *disp)
878 fb_videomode_to_var(var, disp->mode);
879 var->xres_virtual = disp->xres_virtual;
880 var->yres_virtual = disp->yres_virtual;
881 var->bits_per_pixel = disp->bits_per_pixel;
882 var->grayscale = disp->grayscale;
883 var->nonstd = disp->nonstd;
884 var->accel_flags = disp->accel_flags;
885 var->height = disp->height;
886 var->width = disp->width;
887 var->red = disp->red;
888 var->green = disp->green;
889 var->blue = disp->blue;
890 var->transp = disp->transp;
891 var->rotate = disp->rotate;
894 static const char *fbcon_startup(void)
896 const char *display_desc = "frame buffer device";
897 struct display *p = &fb_display[fg_console];
898 struct vc_data *vc = vc_cons[fg_console].d;
899 const struct font_desc *font = NULL;
900 struct module *owner;
901 struct fb_info *info = NULL;
902 struct fbcon_ops *ops;
908 * If num_registered_fb is zero, this is a call for the dummy part.
909 * The frame buffer devices weren't initialized yet.
911 if (!num_registered_fb || info_idx == -1)
914 * Instead of blindly using registered_fb[0], we use info_idx, set by
917 info = registered_fb[info_idx];
921 owner = info->fbops->owner;
922 if (!try_module_get(owner))
924 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
929 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
937 ops->cur_rotate = -1;
938 info->fbcon_par = ops;
939 p->con_rotate = rotate;
940 set_blitting_type(vc, info);
942 if (info->fix.type != FB_TYPE_TEXT) {
943 if (fbcon_softback_size) {
947 kmalloc(fbcon_softback_size,
950 fbcon_softback_size = 0;
956 kfree((void *) softback_buf);
962 softback_in = softback_top = softback_curr =
967 /* Setup default font */
969 if (!fontname[0] || !(font = find_font(fontname)))
970 font = get_default_font(info->var.xres,
972 vc->vc_font.width = font->width;
973 vc->vc_font.height = font->height;
974 vc->vc_font.data = (void *)(p->fontdata = font->data);
975 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
978 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
979 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
980 cols /= vc->vc_font.width;
981 rows /= vc->vc_font.height;
982 vc_resize(vc, cols, rows);
984 DPRINTK("mode: %s\n", info->fix.id);
985 DPRINTK("visual: %d\n", info->fix.visual);
986 DPRINTK("res: %dx%d-%d\n", info->var.xres,
988 info->var.bits_per_pixel);
992 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
994 request_irq(IRQ_AUTO_4, fb_vbl_handler,
995 IRQ_TYPE_PRIO, "framebuffer vbl",
998 #endif /* CONFIG_ATARI */
1002 * On a Macintoy, the VBL interrupt may or may not be active.
1003 * As interrupt based cursor is more reliable and race free, we
1004 * probe for VBL interrupts.
1009 * Probe for VBL: set temp. handler ...
1011 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1012 "framebuffer vbl", info);
1016 * ... and spin for 20 ms ...
1018 while (!vbl_detected && ++ct < 1000)
1023 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1025 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1029 * interrupt based cursor ok
1031 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1033 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1034 "framebuffer vbl", info);
1037 * VBL not detected: fall through, use timer based cursor
1042 #endif /* CONFIG_MAC */
1044 fbcon_add_cursor_timer(info);
1045 fbcon_has_exited = 0;
1046 return display_desc;
1049 static void fbcon_init(struct vc_data *vc, int init)
1051 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1052 struct fbcon_ops *ops;
1053 struct vc_data **default_mode = vc->vc_display_fg;
1054 struct vc_data *svc = *default_mode;
1055 struct display *t, *p = &fb_display[vc->vc_num];
1056 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1059 if (info_idx == -1 || info == NULL)
1064 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1065 (info->fix.type == FB_TYPE_TEXT))
1068 if (var_to_display(p, &info->var, info))
1071 /* If we are not the first console on this
1072 fb, copy the font from that console */
1073 t = &fb_display[fg_console];
1076 struct vc_data *fvc = vc_cons[fg_console].d;
1078 vc->vc_font.data = (void *)(p->fontdata =
1080 vc->vc_font.width = fvc->vc_font.width;
1081 vc->vc_font.height = fvc->vc_font.height;
1082 p->userfont = t->userfont;
1085 REFCOUNT(p->fontdata)++;
1087 const struct font_desc *font = NULL;
1089 if (!fontname[0] || !(font = find_font(fontname)))
1090 font = get_default_font(info->var.xres,
1092 vc->vc_font.width = font->width;
1093 vc->vc_font.height = font->height;
1094 vc->vc_font.data = (void *)(p->fontdata = font->data);
1095 vc->vc_font.charcount = 256; /* FIXME Need to
1096 support more fonts */
1101 charcnt = FNTCHARCNT(p->fontdata);
1103 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1104 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1105 if (charcnt == 256) {
1106 vc->vc_hi_font_mask = 0;
1108 vc->vc_hi_font_mask = 0x100;
1109 if (vc->vc_can_do_color)
1110 vc->vc_complement_mask <<= 1;
1113 if (!*svc->vc_uni_pagedir_loc)
1114 con_set_default_unimap(svc);
1115 if (!*vc->vc_uni_pagedir_loc)
1116 con_copy_unimap(vc, svc);
1118 ops = info->fbcon_par;
1119 p->con_rotate = rotate;
1120 set_blitting_type(vc, info);
1124 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1125 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1126 new_cols /= vc->vc_font.width;
1127 new_rows /= vc->vc_font.height;
1128 vc_resize(vc, new_cols, new_rows);
1131 * We must always set the mode. The mode of the previous console
1132 * driver could be in the same resolution but we are using different
1133 * hardware so we have to initialize the hardware.
1135 * We need to do it in fbcon_init() to prevent screen corruption.
1137 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1138 if (info->fbops->fb_set_par &&
1139 !(ops->flags & FBCON_FLAGS_INIT))
1140 info->fbops->fb_set_par(info);
1141 ops->flags |= FBCON_FLAGS_INIT;
1146 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1147 !(cap & FBINFO_HWACCEL_DISABLED))
1148 p->scrollmode = SCROLL_MOVE;
1149 else /* default to something safe */
1150 p->scrollmode = SCROLL_REDRAW;
1153 * ++guenther: console.c:vc_allocate() relies on initializing
1154 * vc_{cols,rows}, but we must not set those if we are only
1155 * resizing the console.
1158 vc->vc_cols = new_cols;
1159 vc->vc_rows = new_rows;
1163 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1165 if (vc == svc && softback_buf)
1166 fbcon_update_softback(vc);
1168 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1169 ops->rotate = FB_ROTATE_UR;
1170 set_blitting_type(vc, info);
1173 ops->p = &fb_display[fg_console];
1176 static void fbcon_free_font(struct display *p)
1178 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1179 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1184 static void fbcon_deinit(struct vc_data *vc)
1186 struct display *p = &fb_display[vc->vc_num];
1187 struct fb_info *info;
1188 struct fbcon_ops *ops;
1192 idx = con2fb_map[vc->vc_num];
1197 info = registered_fb[idx];
1202 ops = info->fbcon_par;
1207 if (CON_IS_VISIBLE(vc))
1208 fbcon_del_cursor_timer(info);
1210 ops->flags &= ~FBCON_FLAGS_INIT;
1213 if (!con_is_bound(&fb_con))
1219 /* ====================================================================== */
1221 /* fbcon_XXX routines - interface used by the world
1223 * This system is now divided into two levels because of complications
1224 * caused by hardware scrolling. Top level functions:
1226 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1228 * handles y values in range [0, scr_height-1] that correspond to real
1229 * screen positions. y_wrap shift means that first line of bitmap may be
1230 * anywhere on this display. These functions convert lineoffsets to
1231 * bitmap offsets and deal with the wrap-around case by splitting blits.
1233 * fbcon_bmove_physical_8() -- These functions fast implementations
1234 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1235 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1239 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1240 * Implies should only really hardware scroll in rows. Only reason for
1241 * restriction is simplicity & efficiency at the moment.
1244 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1247 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1248 struct fbcon_ops *ops = info->fbcon_par;
1250 struct display *p = &fb_display[vc->vc_num];
1253 if (fbcon_is_inactive(vc, info))
1256 if (!height || !width)
1259 /* Split blits that cross physical y_wrap boundary */
1261 y_break = p->vrows - p->yscroll;
1262 if (sy < y_break && sy + height - 1 >= y_break) {
1263 u_int b = y_break - sy;
1264 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1265 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1268 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1271 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1272 int count, int ypos, int xpos)
1274 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1275 struct display *p = &fb_display[vc->vc_num];
1276 struct fbcon_ops *ops = info->fbcon_par;
1278 if (!fbcon_is_inactive(vc, info))
1279 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1280 get_color(vc, info, scr_readw(s), 1),
1281 get_color(vc, info, scr_readw(s), 0));
1284 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1288 scr_writew(c, &chr);
1289 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1292 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1294 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1295 struct fbcon_ops *ops = info->fbcon_par;
1297 if (!fbcon_is_inactive(vc, info))
1298 ops->clear_margins(vc, info, bottom_only);
1301 static void fbcon_cursor(struct vc_data *vc, int mode)
1303 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1304 struct fbcon_ops *ops = info->fbcon_par;
1306 int c = scr_readw((u16 *) vc->vc_pos);
1308 if (fbcon_is_inactive(vc, info))
1311 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1312 if (mode & CM_SOFTBACK) {
1313 mode &= ~CM_SOFTBACK;
1317 fbcon_set_origin(vc);
1321 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1322 get_color(vc, info, c, 0));
1323 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1326 static int scrollback_phys_max = 0;
1327 static int scrollback_max = 0;
1328 static int scrollback_current = 0;
1331 * If no vc is existent yet, just set struct display
1333 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1336 struct display *p = &fb_display[unit];
1337 struct display *t = &fb_display[fg_console];
1339 if (var_to_display(p, var, info))
1342 p->fontdata = t->fontdata;
1343 p->userfont = t->userfont;
1345 REFCOUNT(p->fontdata)++;
1348 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1351 struct display *p = &fb_display[vc->vc_num], *t;
1352 struct vc_data **default_mode = vc->vc_display_fg;
1353 struct vc_data *svc = *default_mode;
1354 struct fbcon_ops *ops = info->fbcon_par;
1355 int rows, cols, charcnt = 256;
1357 if (var_to_display(p, var, info))
1359 t = &fb_display[svc->vc_num];
1360 if (!vc->vc_font.data) {
1361 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1362 vc->vc_font.width = (*default_mode)->vc_font.width;
1363 vc->vc_font.height = (*default_mode)->vc_font.height;
1364 p->userfont = t->userfont;
1366 REFCOUNT(p->fontdata)++;
1369 charcnt = FNTCHARCNT(p->fontdata);
1371 var->activate = FB_ACTIVATE_NOW;
1372 info->var.activate = var->activate;
1373 var->yoffset = info->var.yoffset;
1374 var->xoffset = info->var.xoffset;
1375 fb_set_var(info, var);
1376 ops->var = info->var;
1377 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1378 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1379 if (charcnt == 256) {
1380 vc->vc_hi_font_mask = 0;
1382 vc->vc_hi_font_mask = 0x100;
1383 if (vc->vc_can_do_color)
1384 vc->vc_complement_mask <<= 1;
1387 if (!*svc->vc_uni_pagedir_loc)
1388 con_set_default_unimap(svc);
1389 if (!*vc->vc_uni_pagedir_loc)
1390 con_copy_unimap(vc, svc);
1392 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1393 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1394 cols /= vc->vc_font.width;
1395 rows /= vc->vc_font.height;
1396 vc_resize(vc, cols, rows);
1398 if (CON_IS_VISIBLE(vc)) {
1401 fbcon_update_softback(vc);
1405 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1407 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1408 struct fbcon_ops *ops = info->fbcon_par;
1409 struct display *p = &fb_display[vc->vc_num];
1411 p->yscroll += count;
1412 if (p->yscroll >= p->vrows) /* Deal with wrap */
1413 p->yscroll -= p->vrows;
1414 ops->var.xoffset = 0;
1415 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1416 ops->var.vmode |= FB_VMODE_YWRAP;
1417 ops->update_start(info);
1418 scrollback_max += count;
1419 if (scrollback_max > scrollback_phys_max)
1420 scrollback_max = scrollback_phys_max;
1421 scrollback_current = 0;
1424 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1426 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1427 struct fbcon_ops *ops = info->fbcon_par;
1428 struct display *p = &fb_display[vc->vc_num];
1430 p->yscroll -= count;
1431 if (p->yscroll < 0) /* Deal with wrap */
1432 p->yscroll += p->vrows;
1433 ops->var.xoffset = 0;
1434 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1435 ops->var.vmode |= FB_VMODE_YWRAP;
1436 ops->update_start(info);
1437 scrollback_max -= count;
1438 if (scrollback_max < 0)
1440 scrollback_current = 0;
1443 static __inline__ void ypan_up(struct vc_data *vc, int count)
1445 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1446 struct display *p = &fb_display[vc->vc_num];
1447 struct fbcon_ops *ops = info->fbcon_par;
1449 p->yscroll += count;
1450 if (p->yscroll > p->vrows - vc->vc_rows) {
1451 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1452 0, 0, 0, vc->vc_rows, vc->vc_cols);
1453 p->yscroll -= p->vrows - vc->vc_rows;
1456 ops->var.xoffset = 0;
1457 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1458 ops->var.vmode &= ~FB_VMODE_YWRAP;
1459 ops->update_start(info);
1460 fbcon_clear_margins(vc, 1);
1461 scrollback_max += count;
1462 if (scrollback_max > scrollback_phys_max)
1463 scrollback_max = scrollback_phys_max;
1464 scrollback_current = 0;
1467 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1470 struct fbcon_ops *ops = info->fbcon_par;
1471 struct display *p = &fb_display[vc->vc_num];
1473 p->yscroll += count;
1475 if (p->yscroll > p->vrows - vc->vc_rows) {
1476 p->yscroll -= p->vrows - vc->vc_rows;
1477 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1480 ops->var.xoffset = 0;
1481 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1482 ops->var.vmode &= ~FB_VMODE_YWRAP;
1483 ops->update_start(info);
1484 fbcon_clear_margins(vc, 1);
1485 scrollback_max += count;
1486 if (scrollback_max > scrollback_phys_max)
1487 scrollback_max = scrollback_phys_max;
1488 scrollback_current = 0;
1491 static __inline__ void ypan_down(struct vc_data *vc, int count)
1493 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1494 struct display *p = &fb_display[vc->vc_num];
1495 struct fbcon_ops *ops = info->fbcon_par;
1497 p->yscroll -= count;
1498 if (p->yscroll < 0) {
1499 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1500 0, vc->vc_rows, vc->vc_cols);
1501 p->yscroll += p->vrows - vc->vc_rows;
1504 ops->var.xoffset = 0;
1505 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1506 ops->var.vmode &= ~FB_VMODE_YWRAP;
1507 ops->update_start(info);
1508 fbcon_clear_margins(vc, 1);
1509 scrollback_max -= count;
1510 if (scrollback_max < 0)
1512 scrollback_current = 0;
1515 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1517 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1518 struct fbcon_ops *ops = info->fbcon_par;
1519 struct display *p = &fb_display[vc->vc_num];
1521 p->yscroll -= count;
1523 if (p->yscroll < 0) {
1524 p->yscroll += p->vrows - vc->vc_rows;
1525 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1528 ops->var.xoffset = 0;
1529 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1530 ops->var.vmode &= ~FB_VMODE_YWRAP;
1531 ops->update_start(info);
1532 fbcon_clear_margins(vc, 1);
1533 scrollback_max -= count;
1534 if (scrollback_max < 0)
1536 scrollback_current = 0;
1539 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1542 int count = vc->vc_rows;
1543 unsigned short *d, *s;
1547 d = (u16 *) softback_curr;
1548 if (d == (u16 *) softback_in)
1549 d = (u16 *) vc->vc_origin;
1550 n = softback_curr + delta * vc->vc_size_row;
1551 softback_lines -= delta;
1553 if (softback_curr < softback_top && n < softback_buf) {
1554 n += softback_end - softback_buf;
1555 if (n < softback_top) {
1557 (softback_top - n) / vc->vc_size_row;
1560 } else if (softback_curr >= softback_top
1561 && n < softback_top) {
1563 (softback_top - n) / vc->vc_size_row;
1567 if (softback_curr > softback_in && n >= softback_end) {
1568 n += softback_buf - softback_end;
1569 if (n > softback_in) {
1573 } else if (softback_curr <= softback_in && n > softback_in) {
1578 if (n == softback_curr)
1581 s = (u16 *) softback_curr;
1582 if (s == (u16 *) softback_in)
1583 s = (u16 *) vc->vc_origin;
1585 unsigned short *start;
1589 unsigned short attr = 1;
1592 le = advance_row(s, 1);
1595 if (attr != (c & 0xff00)) {
1598 fbcon_putcs(vc, start, s - start,
1604 if (c == scr_readw(d)) {
1606 fbcon_putcs(vc, start, s - start,
1619 fbcon_putcs(vc, start, s - start, line, x);
1621 if (d == (u16 *) softback_end)
1622 d = (u16 *) softback_buf;
1623 if (d == (u16 *) softback_in)
1624 d = (u16 *) vc->vc_origin;
1625 if (s == (u16 *) softback_end)
1626 s = (u16 *) softback_buf;
1627 if (s == (u16 *) softback_in)
1628 s = (u16 *) vc->vc_origin;
1632 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1633 int line, int count, int dy)
1635 unsigned short *s = (unsigned short *)
1636 (vc->vc_origin + vc->vc_size_row * line);
1639 unsigned short *start = s;
1640 unsigned short *le = advance_row(s, 1);
1643 unsigned short attr = 1;
1647 if (attr != (c & 0xff00)) {
1650 fbcon_putcs(vc, start, s - start,
1656 console_conditional_schedule();
1660 fbcon_putcs(vc, start, s - start, dy, x);
1661 console_conditional_schedule();
1666 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1667 int line, int count, int offset)
1669 unsigned short *d = (unsigned short *)
1670 (vc->vc_origin + vc->vc_size_row * line);
1671 unsigned short *s = d + offset;
1674 unsigned short *start = s;
1675 unsigned short *le = advance_row(s, 1);
1678 unsigned short attr = 1;
1682 if (attr != (c & 0xff00)) {
1685 fbcon_putcs(vc, start, s - start,
1691 if (c == scr_readw(d)) {
1693 fbcon_putcs(vc, start, s - start,
1703 console_conditional_schedule();
1708 fbcon_putcs(vc, start, s - start, line, x);
1709 console_conditional_schedule();
1714 /* NOTE: We subtract two lines from these pointers */
1715 s -= vc->vc_size_row;
1716 d -= vc->vc_size_row;
1721 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1726 if (vc->vc_num != fg_console)
1728 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1731 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1733 p = advance_row(p, 1);
1734 softback_in += vc->vc_size_row;
1735 if (softback_in == softback_end)
1736 softback_in = softback_buf;
1737 if (softback_in == softback_top) {
1738 softback_top += vc->vc_size_row;
1739 if (softback_top == softback_end)
1740 softback_top = softback_buf;
1743 softback_curr = softback_in;
1746 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1749 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1750 struct display *p = &fb_display[vc->vc_num];
1751 struct fbcon_ops *ops = info->fbcon_par;
1752 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1754 if (fbcon_is_inactive(vc, info))
1757 fbcon_cursor(vc, CM_ERASE);
1760 * ++Geert: Only use ywrap/ypan if the console is in text mode
1761 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1762 * whole screen (prevents flicker).
1767 if (count > vc->vc_rows) /* Maximum realistic size */
1768 count = vc->vc_rows;
1770 fbcon_softback_note(vc, t, count);
1771 if (logo_shown >= 0)
1773 switch (p->scrollmode) {
1775 ops->bmove(vc, info, t + count, 0, t, 0,
1776 b - t - count, vc->vc_cols);
1777 ops->clear(vc, info, b - count, 0, count,
1781 case SCROLL_WRAP_MOVE:
1782 if (b - t - count > 3 * vc->vc_rows >> 2) {
1784 fbcon_bmove(vc, 0, 0, count, 0, t,
1786 ywrap_up(vc, count);
1787 if (vc->vc_rows - b > 0)
1788 fbcon_bmove(vc, b - count, 0, b, 0,
1791 } else if (info->flags & FBINFO_READS_FAST)
1792 fbcon_bmove(vc, t + count, 0, t, 0,
1793 b - t - count, vc->vc_cols);
1796 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1799 case SCROLL_PAN_REDRAW:
1800 if ((p->yscroll + count <=
1801 2 * (p->vrows - vc->vc_rows))
1802 && ((!scroll_partial && (b - t == vc->vc_rows))
1805 3 * vc->vc_rows >> 2)))) {
1807 fbcon_redraw_move(vc, p, 0, t, count);
1808 ypan_up_redraw(vc, t, count);
1809 if (vc->vc_rows - b > 0)
1810 fbcon_redraw_move(vc, p, b,
1811 vc->vc_rows - b, b);
1813 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1814 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1817 case SCROLL_PAN_MOVE:
1818 if ((p->yscroll + count <=
1819 2 * (p->vrows - vc->vc_rows))
1820 && ((!scroll_partial && (b - t == vc->vc_rows))
1823 3 * vc->vc_rows >> 2)))) {
1825 fbcon_bmove(vc, 0, 0, count, 0, t,
1828 if (vc->vc_rows - b > 0)
1829 fbcon_bmove(vc, b - count, 0, b, 0,
1832 } else if (info->flags & FBINFO_READS_FAST)
1833 fbcon_bmove(vc, t + count, 0, t, 0,
1834 b - t - count, vc->vc_cols);
1837 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1842 fbcon_redraw(vc, p, t, b - t - count,
1843 count * vc->vc_cols);
1844 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1845 scr_memsetw((unsigned short *) (vc->vc_origin +
1848 vc->vc_video_erase_char,
1849 vc->vc_size_row * count);
1855 if (count > vc->vc_rows) /* Maximum realistic size */
1856 count = vc->vc_rows;
1857 if (logo_shown >= 0)
1859 switch (p->scrollmode) {
1861 ops->bmove(vc, info, t, 0, t + count, 0,
1862 b - t - count, vc->vc_cols);
1863 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1866 case SCROLL_WRAP_MOVE:
1867 if (b - t - count > 3 * vc->vc_rows >> 2) {
1868 if (vc->vc_rows - b > 0)
1869 fbcon_bmove(vc, b, 0, b - count, 0,
1872 ywrap_down(vc, count);
1874 fbcon_bmove(vc, count, 0, 0, 0, t,
1876 } else if (info->flags & FBINFO_READS_FAST)
1877 fbcon_bmove(vc, t, 0, t + count, 0,
1878 b - t - count, vc->vc_cols);
1881 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1884 case SCROLL_PAN_MOVE:
1885 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1886 && ((!scroll_partial && (b - t == vc->vc_rows))
1889 3 * vc->vc_rows >> 2)))) {
1890 if (vc->vc_rows - b > 0)
1891 fbcon_bmove(vc, b, 0, b - count, 0,
1894 ypan_down(vc, count);
1896 fbcon_bmove(vc, count, 0, 0, 0, t,
1898 } else if (info->flags & FBINFO_READS_FAST)
1899 fbcon_bmove(vc, t, 0, t + count, 0,
1900 b - t - count, vc->vc_cols);
1903 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1906 case SCROLL_PAN_REDRAW:
1907 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1908 && ((!scroll_partial && (b - t == vc->vc_rows))
1911 3 * vc->vc_rows >> 2)))) {
1912 if (vc->vc_rows - b > 0)
1913 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1915 ypan_down_redraw(vc, t, count);
1917 fbcon_redraw_move(vc, p, count, t, 0);
1919 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1920 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1925 fbcon_redraw(vc, p, b - 1, b - t - count,
1926 -count * vc->vc_cols);
1927 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1928 scr_memsetw((unsigned short *) (vc->vc_origin +
1931 vc->vc_video_erase_char,
1932 vc->vc_size_row * count);
1940 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1941 int height, int width)
1943 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1944 struct display *p = &fb_display[vc->vc_num];
1946 if (fbcon_is_inactive(vc, info))
1949 if (!width || !height)
1952 /* Split blits that cross physical y_wrap case.
1953 * Pathological case involves 4 blits, better to use recursive
1954 * code rather than unrolled case
1956 * Recursive invocations don't need to erase the cursor over and
1957 * over again, so we use fbcon_bmove_rec()
1959 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1960 p->vrows - p->yscroll);
1963 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1964 int dy, int dx, int height, int width, u_int y_break)
1966 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1967 struct fbcon_ops *ops = info->fbcon_par;
1970 if (sy < y_break && sy + height > y_break) {
1972 if (dy < sy) { /* Avoid trashing self */
1973 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1975 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1976 height - b, width, y_break);
1978 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1979 height - b, width, y_break);
1980 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1986 if (dy < y_break && dy + height > y_break) {
1988 if (dy < sy) { /* Avoid trashing self */
1989 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1991 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1992 height - b, width, y_break);
1994 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1995 height - b, width, y_break);
1996 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2001 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2005 static __inline__ void updatescrollmode(struct display *p,
2006 struct fb_info *info,
2009 struct fbcon_ops *ops = info->fbcon_par;
2010 int fh = vc->vc_font.height;
2011 int cap = info->flags;
2013 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2014 info->fix.xpanstep);
2015 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2016 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2017 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2018 info->var.xres_virtual);
2019 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2020 divides(ypan, vc->vc_font.height) && vyres > yres;
2021 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2022 divides(ywrap, vc->vc_font.height) &&
2023 divides(vc->vc_font.height, vyres) &&
2024 divides(vc->vc_font.height, yres);
2025 int reading_fast = cap & FBINFO_READS_FAST;
2026 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2027 !(cap & FBINFO_HWACCEL_DISABLED);
2028 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2029 !(cap & FBINFO_HWACCEL_DISABLED);
2031 p->vrows = vyres/fh;
2032 if (yres > (fh * (vc->vc_rows + 1)))
2033 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2034 if ((yres % fh) && (vyres % fh < yres % fh))
2037 if (good_wrap || good_pan) {
2038 if (reading_fast || fast_copyarea)
2039 p->scrollmode = good_wrap ?
2040 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2042 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2045 if (reading_fast || (fast_copyarea && !fast_imageblit))
2046 p->scrollmode = SCROLL_MOVE;
2048 p->scrollmode = SCROLL_REDRAW;
2052 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2053 unsigned int height)
2055 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2056 struct fbcon_ops *ops = info->fbcon_par;
2057 struct display *p = &fb_display[vc->vc_num];
2058 struct fb_var_screeninfo var = info->var;
2059 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2061 virt_w = FBCON_SWAP(ops->rotate, width, height);
2062 virt_h = FBCON_SWAP(ops->rotate, height, width);
2063 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2064 vc->vc_font.height);
2065 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2067 var.xres = virt_w * virt_fw;
2068 var.yres = virt_h * virt_fh;
2069 x_diff = info->var.xres - var.xres;
2070 y_diff = info->var.yres - var.yres;
2071 if (x_diff < 0 || x_diff > virt_fw ||
2072 y_diff < 0 || y_diff > virt_fh) {
2073 const struct fb_videomode *mode;
2075 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2076 mode = fb_find_best_mode(&var, &info->modelist);
2079 display_to_var(&var, p);
2080 fb_videomode_to_var(&var, mode);
2082 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2085 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2086 if (CON_IS_VISIBLE(vc)) {
2087 var.activate = FB_ACTIVATE_NOW |
2089 fb_set_var(info, &var);
2091 var_to_display(p, &info->var, info);
2092 ops->var = info->var;
2094 updatescrollmode(p, info, vc);
2098 static int fbcon_switch(struct vc_data *vc)
2100 struct fb_info *info, *old_info = NULL;
2101 struct fbcon_ops *ops;
2102 struct display *p = &fb_display[vc->vc_num];
2103 struct fb_var_screeninfo var;
2104 int i, prev_console, charcnt = 256;
2106 info = registered_fb[con2fb_map[vc->vc_num]];
2107 ops = info->fbcon_par;
2111 fbcon_set_origin(vc);
2112 softback_top = softback_curr = softback_in = softback_buf;
2114 fbcon_update_softback(vc);
2117 if (logo_shown >= 0) {
2118 struct vc_data *conp2 = vc_cons[logo_shown].d;
2120 if (conp2->vc_top == logo_lines
2121 && conp2->vc_bottom == conp2->vc_rows)
2123 logo_shown = FBCON_LOGO_CANSHOW;
2126 prev_console = ops->currcon;
2127 if (prev_console != -1)
2128 old_info = registered_fb[con2fb_map[prev_console]];
2130 * FIXME: If we have multiple fbdev's loaded, we need to
2131 * update all info->currcon. Perhaps, we can place this
2132 * in a centralized structure, but this might break some
2135 * info->currcon = vc->vc_num;
2137 for (i = 0; i < FB_MAX; i++) {
2138 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2139 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2141 o->currcon = vc->vc_num;
2144 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2145 display_to_var(&var, p);
2146 var.activate = FB_ACTIVATE_NOW;
2149 * make sure we don't unnecessarily trip the memcmp()
2152 info->var.activate = var.activate;
2153 var.yoffset = info->var.yoffset;
2154 var.xoffset = info->var.xoffset;
2155 var.vmode = info->var.vmode;
2156 fb_set_var(info, &var);
2157 ops->var = info->var;
2159 if (old_info != NULL && (old_info != info ||
2160 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2161 if (info->fbops->fb_set_par)
2162 info->fbops->fb_set_par(info);
2164 if (old_info != info)
2165 fbcon_del_cursor_timer(old_info);
2168 if (fbcon_is_inactive(vc, info) ||
2169 ops->blank_state != FB_BLANK_UNBLANK)
2170 fbcon_del_cursor_timer(info);
2172 fbcon_add_cursor_timer(info);
2174 set_blitting_type(vc, info);
2175 ops->cursor_reset = 1;
2177 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2178 ops->rotate = FB_ROTATE_UR;
2179 set_blitting_type(vc, info);
2182 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2183 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2186 charcnt = FNTCHARCNT(vc->vc_font.data);
2189 vc->vc_complement_mask <<= 1;
2191 updatescrollmode(p, info, vc);
2193 switch (p->scrollmode) {
2194 case SCROLL_WRAP_MOVE:
2195 scrollback_phys_max = p->vrows - vc->vc_rows;
2197 case SCROLL_PAN_MOVE:
2198 case SCROLL_PAN_REDRAW:
2199 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2200 if (scrollback_phys_max < 0)
2201 scrollback_phys_max = 0;
2204 scrollback_phys_max = 0;
2209 scrollback_current = 0;
2211 if (!fbcon_is_inactive(vc, info)) {
2212 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2213 ops->update_start(info);
2216 fbcon_set_palette(vc, color_table);
2217 fbcon_clear_margins(vc, 0);
2219 if (logo_shown == FBCON_LOGO_DRAW) {
2221 logo_shown = fg_console;
2222 /* This is protected above by initmem_freed */
2223 fb_show_logo(info, ops->rotate);
2225 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2226 vc->vc_size_row * (vc->vc_bottom -
2233 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2237 unsigned short charmask = vc->vc_hi_font_mask ?
2239 unsigned short oldc;
2241 oldc = vc->vc_video_erase_char;
2242 vc->vc_video_erase_char &= charmask;
2243 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2244 vc->vc_video_erase_char = oldc;
2248 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2250 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2251 struct fbcon_ops *ops = info->fbcon_par;
2254 struct fb_var_screeninfo var = info->var;
2259 if (info->fbops->fb_save_state)
2260 info->fbops->fb_save_state(info);
2261 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2262 fb_set_var(info, &var);
2264 ops->var = info->var;
2265 } else if (info->fbops->fb_restore_state)
2266 info->fbops->fb_restore_state(info);
2269 if (!fbcon_is_inactive(vc, info)) {
2270 if (ops->blank_state != blank) {
2271 ops->blank_state = blank;
2272 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2273 ops->cursor_flash = (!blank);
2275 if (fb_blank(info, blank))
2276 fbcon_generic_blank(vc, info, blank);
2283 if (fbcon_is_inactive(vc, info) ||
2284 ops->blank_state != FB_BLANK_UNBLANK)
2285 fbcon_del_cursor_timer(info);
2287 fbcon_add_cursor_timer(info);
2292 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2294 u8 *fontdata = vc->vc_font.data;
2295 u8 *data = font->data;
2298 font->width = vc->vc_font.width;
2299 font->height = vc->vc_font.height;
2300 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2304 if (font->width <= 8) {
2305 j = vc->vc_font.height;
2306 for (i = 0; i < font->charcount; i++) {
2307 memcpy(data, fontdata, j);
2308 memset(data + j, 0, 32 - j);
2312 } else if (font->width <= 16) {
2313 j = vc->vc_font.height * 2;
2314 for (i = 0; i < font->charcount; i++) {
2315 memcpy(data, fontdata, j);
2316 memset(data + j, 0, 64 - j);
2320 } else if (font->width <= 24) {
2321 for (i = 0; i < font->charcount; i++) {
2322 for (j = 0; j < vc->vc_font.height; j++) {
2323 *data++ = fontdata[0];
2324 *data++ = fontdata[1];
2325 *data++ = fontdata[2];
2326 fontdata += sizeof(u32);
2328 memset(data, 0, 3 * (32 - j));
2329 data += 3 * (32 - j);
2332 j = vc->vc_font.height * 4;
2333 for (i = 0; i < font->charcount; i++) {
2334 memcpy(data, fontdata, j);
2335 memset(data + j, 0, 128 - j);
2343 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2344 const u8 * data, int userfont)
2346 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2347 struct fbcon_ops *ops = info->fbcon_par;
2348 struct display *p = &fb_display[vc->vc_num];
2351 char *old_data = NULL;
2353 if (CON_IS_VISIBLE(vc) && softback_lines)
2354 fbcon_set_origin(vc);
2356 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2358 old_data = vc->vc_font.data;
2360 cnt = FNTCHARCNT(data);
2363 vc->vc_font.data = (void *)(p->fontdata = data);
2364 if ((p->userfont = userfont))
2366 vc->vc_font.width = w;
2367 vc->vc_font.height = h;
2368 if (vc->vc_hi_font_mask && cnt == 256) {
2369 vc->vc_hi_font_mask = 0;
2370 if (vc->vc_can_do_color) {
2371 vc->vc_complement_mask >>= 1;
2372 vc->vc_s_complement_mask >>= 1;
2375 /* ++Edmund: reorder the attribute bits */
2376 if (vc->vc_can_do_color) {
2377 unsigned short *cp =
2378 (unsigned short *) vc->vc_origin;
2379 int count = vc->vc_screenbuf_size / 2;
2381 for (; count > 0; count--, cp++) {
2383 scr_writew(((c & 0xfe00) >> 1) |
2386 c = vc->vc_video_erase_char;
2387 vc->vc_video_erase_char =
2388 ((c & 0xfe00) >> 1) | (c & 0xff);
2391 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2392 vc->vc_hi_font_mask = 0x100;
2393 if (vc->vc_can_do_color) {
2394 vc->vc_complement_mask <<= 1;
2395 vc->vc_s_complement_mask <<= 1;
2398 /* ++Edmund: reorder the attribute bits */
2400 unsigned short *cp =
2401 (unsigned short *) vc->vc_origin;
2402 int count = vc->vc_screenbuf_size / 2;
2404 for (; count > 0; count--, cp++) {
2405 unsigned short newc;
2407 if (vc->vc_can_do_color)
2409 ((c & 0xff00) << 1) | (c &
2413 scr_writew(newc, cp);
2415 c = vc->vc_video_erase_char;
2416 if (vc->vc_can_do_color) {
2417 vc->vc_video_erase_char =
2418 ((c & 0xff00) << 1) | (c & 0xff);
2421 vc->vc_video_erase_char = c & ~0x100;
2429 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2430 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2433 vc_resize(vc, cols, rows);
2434 if (CON_IS_VISIBLE(vc) && softback_buf)
2435 fbcon_update_softback(vc);
2436 } else if (CON_IS_VISIBLE(vc)
2437 && vc->vc_mode == KD_TEXT) {
2438 fbcon_clear_margins(vc, 0);
2442 if (old_data && (--REFCOUNT(old_data) == 0))
2443 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2447 static int fbcon_copy_font(struct vc_data *vc, int con)
2449 struct display *od = &fb_display[con];
2450 struct console_font *f = &vc->vc_font;
2452 if (od->fontdata == f->data)
2453 return 0; /* already the same font... */
2454 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2458 * User asked to set font; we are guaranteed that
2459 * a) width and height are in range 1..32
2460 * b) charcount does not exceed 512
2461 * but lets not assume that, since someone might someday want to use larger
2462 * fonts. And charcount of 512 is small for unicode support.
2464 * However, user space gives the font in 32 rows , regardless of
2465 * actual font height. So a new API is needed if support for larger fonts
2466 * is ever implemented.
2469 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2471 unsigned charcount = font->charcount;
2472 int w = font->width;
2473 int h = font->height;
2476 u8 *new_data, *data = font->data;
2477 int pitch = (font->width+7) >> 3;
2479 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2480 * If not this check should be changed to charcount < 256 */
2481 if (charcount != 256 && charcount != 512)
2484 size = h * pitch * charcount;
2486 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2491 new_data += FONT_EXTRA_WORDS * sizeof(int);
2492 FNTSIZE(new_data) = size;
2493 FNTCHARCNT(new_data) = charcount;
2494 REFCOUNT(new_data) = 0; /* usage counter */
2495 for (i=0; i< charcount; i++) {
2496 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2499 /* Since linux has a nice crc32 function use it for counting font
2501 csum = crc32(0, new_data, size);
2503 FNTSUM(new_data) = csum;
2504 /* Check if the same font is on some other console already */
2505 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2506 struct vc_data *tmp = vc_cons[i].d;
2508 if (fb_display[i].userfont &&
2509 fb_display[i].fontdata &&
2510 FNTSUM(fb_display[i].fontdata) == csum &&
2511 FNTSIZE(fb_display[i].fontdata) == size &&
2512 tmp->vc_font.width == w &&
2513 !memcmp(fb_display[i].fontdata, new_data, size)) {
2514 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2515 new_data = (u8 *)fb_display[i].fontdata;
2519 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2522 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2524 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2525 const struct font_desc *f;
2528 f = get_default_font(info->var.xres, info->var.yres);
2529 else if (!(f = find_font(name)))
2532 font->width = f->width;
2533 font->height = f->height;
2534 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2537 static u16 palette_red[16];
2538 static u16 palette_green[16];
2539 static u16 palette_blue[16];
2541 static struct fb_cmap palette_cmap = {
2542 0, 16, palette_red, palette_green, palette_blue, NULL
2545 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2547 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2551 if (fbcon_is_inactive(vc, info))
2554 if (!CON_IS_VISIBLE(vc))
2557 depth = fb_get_color_depth(&info->var, &info->fix);
2559 for (i = j = 0; i < 16; i++) {
2561 val = vc->vc_palette[j++];
2562 palette_red[k] = (val << 8) | val;
2563 val = vc->vc_palette[j++];
2564 palette_green[k] = (val << 8) | val;
2565 val = vc->vc_palette[j++];
2566 palette_blue[k] = (val << 8) | val;
2568 palette_cmap.len = 16;
2569 palette_cmap.start = 0;
2571 * If framebuffer is capable of less than 16 colors,
2572 * use default palette of fbcon.
2575 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2577 return fb_set_cmap(&palette_cmap, info);
2580 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2585 if (vc->vc_num != fg_console || !softback_lines)
2586 return (u16 *) (vc->vc_origin + offset);
2587 line = offset / vc->vc_size_row;
2588 if (line >= softback_lines)
2589 return (u16 *) (vc->vc_origin + offset -
2590 softback_lines * vc->vc_size_row);
2591 p = softback_curr + offset;
2592 if (p >= softback_end)
2593 p += softback_buf - softback_end;
2597 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2603 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2604 unsigned long offset = (pos - vc->vc_origin) / 2;
2606 x = offset % vc->vc_cols;
2607 y = offset / vc->vc_cols;
2608 if (vc->vc_num == fg_console)
2609 y += softback_lines;
2610 ret = pos + (vc->vc_cols - x) * 2;
2611 } else if (vc->vc_num == fg_console && softback_lines) {
2612 unsigned long offset = pos - softback_curr;
2614 if (pos < softback_curr)
2615 offset += softback_end - softback_buf;
2617 x = offset % vc->vc_cols;
2618 y = offset / vc->vc_cols;
2619 ret = pos + (vc->vc_cols - x) * 2;
2620 if (ret == softback_end)
2622 if (ret == softback_in)
2623 ret = vc->vc_origin;
2625 /* Should not happen */
2627 ret = vc->vc_origin;
2636 /* As we might be inside of softback, we may work with non-contiguous buffer,
2637 that's why we have to use a separate routine. */
2638 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2641 u16 a = scr_readw(p);
2642 if (!vc->vc_can_do_color)
2644 else if (vc->vc_hi_font_mask == 0x100)
2645 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2646 (((a) & 0x0e00) << 4);
2648 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2649 (((a) & 0x0700) << 4);
2651 if (p == (u16 *) softback_end)
2652 p = (u16 *) softback_buf;
2653 if (p == (u16 *) softback_in)
2654 p = (u16 *) vc->vc_origin;
2658 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2660 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2661 struct fbcon_ops *ops = info->fbcon_par;
2662 struct display *p = &fb_display[fg_console];
2663 int offset, limit, scrollback_old;
2666 if (vc->vc_num != fg_console)
2668 if (vc->vc_mode != KD_TEXT || !lines)
2670 if (logo_shown >= 0) {
2671 struct vc_data *conp2 = vc_cons[logo_shown].d;
2673 if (conp2->vc_top == logo_lines
2674 && conp2->vc_bottom == conp2->vc_rows)
2676 if (logo_shown == vc->vc_num) {
2682 logo_lines * vc->vc_size_row;
2683 for (i = 0; i < logo_lines; i++) {
2684 if (p == softback_top)
2686 if (p == softback_buf)
2688 p -= vc->vc_size_row;
2689 q -= vc->vc_size_row;
2690 scr_memcpyw((u16 *) q, (u16 *) p,
2693 softback_in = softback_curr = p;
2694 update_region(vc, vc->vc_origin,
2695 logo_lines * vc->vc_cols);
2697 logo_shown = FBCON_LOGO_CANSHOW;
2699 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2700 fbcon_redraw_softback(vc, p, lines);
2701 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2705 if (!scrollback_phys_max)
2708 scrollback_old = scrollback_current;
2709 scrollback_current -= lines;
2710 if (scrollback_current < 0)
2711 scrollback_current = 0;
2712 else if (scrollback_current > scrollback_max)
2713 scrollback_current = scrollback_max;
2714 if (scrollback_current == scrollback_old)
2717 if (fbcon_is_inactive(vc, info))
2720 fbcon_cursor(vc, CM_ERASE);
2722 offset = p->yscroll - scrollback_current;
2724 switch (p->scrollmode) {
2725 case SCROLL_WRAP_MOVE:
2726 info->var.vmode |= FB_VMODE_YWRAP;
2728 case SCROLL_PAN_MOVE:
2729 case SCROLL_PAN_REDRAW:
2730 limit -= vc->vc_rows;
2731 info->var.vmode &= ~FB_VMODE_YWRAP;
2736 else if (offset >= limit)
2739 ops->var.xoffset = 0;
2740 ops->var.yoffset = offset * vc->vc_font.height;
2741 ops->update_start(info);
2743 if (!scrollback_current)
2744 fbcon_cursor(vc, CM_DRAW);
2748 static int fbcon_set_origin(struct vc_data *vc)
2751 fbcon_scrolldelta(vc, softback_lines);
2755 static void fbcon_suspended(struct fb_info *info)
2757 struct vc_data *vc = NULL;
2758 struct fbcon_ops *ops = info->fbcon_par;
2760 if (!ops || ops->currcon < 0)
2762 vc = vc_cons[ops->currcon].d;
2764 /* Clear cursor, restore saved data */
2765 fbcon_cursor(vc, CM_ERASE);
2768 static void fbcon_resumed(struct fb_info *info)
2771 struct fbcon_ops *ops = info->fbcon_par;
2773 if (!ops || ops->currcon < 0)
2775 vc = vc_cons[ops->currcon].d;
2780 static void fbcon_modechanged(struct fb_info *info)
2782 struct fbcon_ops *ops = info->fbcon_par;
2787 if (!ops || ops->currcon < 0)
2789 vc = vc_cons[ops->currcon].d;
2790 if (vc->vc_mode != KD_TEXT ||
2791 registered_fb[con2fb_map[ops->currcon]] != info)
2794 p = &fb_display[vc->vc_num];
2795 set_blitting_type(vc, info);
2797 if (CON_IS_VISIBLE(vc)) {
2798 var_to_display(p, &info->var, info);
2799 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2800 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2801 cols /= vc->vc_font.width;
2802 rows /= vc->vc_font.height;
2803 vc_resize(vc, cols, rows);
2804 updatescrollmode(p, info, vc);
2806 scrollback_current = 0;
2808 if (!fbcon_is_inactive(vc, info)) {
2809 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2810 ops->update_start(info);
2813 fbcon_set_palette(vc, color_table);
2816 fbcon_update_softback(vc);
2820 static void fbcon_set_all_vcs(struct fb_info *info)
2822 struct fbcon_ops *ops = info->fbcon_par;
2827 if (!ops || ops->currcon < 0)
2830 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2832 if (!vc || vc->vc_mode != KD_TEXT ||
2833 registered_fb[con2fb_map[i]] != info)
2836 p = &fb_display[vc->vc_num];
2837 set_blitting_type(vc, info);
2838 var_to_display(p, &info->var, info);
2839 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2840 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2841 cols /= vc->vc_font.width;
2842 rows /= vc->vc_font.height;
2843 vc_resize(vc, cols, rows);
2845 if (CON_IS_VISIBLE(vc)) {
2846 updatescrollmode(p, info, vc);
2848 scrollback_current = 0;
2850 if (!fbcon_is_inactive(vc, info)) {
2851 ops->var.xoffset = ops->var.yoffset =
2853 ops->update_start(info);
2856 fbcon_set_palette(vc, color_table);
2859 fbcon_update_softback(vc);
2863 ops->p = &fb_display[ops->currcon];
2866 static int fbcon_mode_deleted(struct fb_info *info,
2867 struct fb_videomode *mode)
2869 struct fb_info *fb_info;
2871 int i, j, found = 0;
2873 /* before deletion, ensure that mode is not in use */
2874 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2878 fb_info = registered_fb[j];
2879 if (fb_info != info)
2884 if (fb_mode_is_equal(p->mode, mode)) {
2892 static int fbcon_fb_unregistered(int idx)
2896 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2897 if (con2fb_map[i] == idx)
2901 if (idx == info_idx) {
2904 for (i = 0; i < FB_MAX; i++) {
2905 if (registered_fb[i] != NULL) {
2912 if (info_idx != -1) {
2913 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2914 if (con2fb_map[i] == -1)
2915 con2fb_map[i] = info_idx;
2919 if (!num_registered_fb)
2920 unregister_con_driver(&fb_con);
2925 static int fbcon_fb_registered(int idx)
2929 if (info_idx == -1) {
2930 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2931 if (con2fb_map_boot[i] == idx) {
2938 ret = fbcon_takeover(1);
2940 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2941 if (con2fb_map_boot[i] == idx &&
2942 con2fb_map[i] == -1)
2943 set_con2fb_map(i, idx, 0);
2950 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2952 struct fbcon_ops *ops = info->fbcon_par;
2955 if (!ops || ops->currcon < 0)
2958 vc = vc_cons[ops->currcon].d;
2959 if (vc->vc_mode != KD_TEXT ||
2960 registered_fb[con2fb_map[ops->currcon]] != info)
2963 if (CON_IS_VISIBLE(vc)) {
2967 do_unblank_screen(0);
2969 ops->blank_state = blank;
2972 static void fbcon_new_modelist(struct fb_info *info)
2976 struct fb_var_screeninfo var;
2977 const struct fb_videomode *mode;
2979 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2980 if (registered_fb[con2fb_map[i]] != info)
2982 if (!fb_display[i].mode)
2985 display_to_var(&var, &fb_display[i]);
2986 mode = fb_find_nearest_mode(fb_display[i].mode,
2988 fb_videomode_to_var(&var, mode);
2991 fbcon_set_disp(info, &var, vc);
2993 fbcon_preset_disp(info, &var, i);
2998 static int fbcon_event_notify(struct notifier_block *self,
2999 unsigned long action, void *data)
3001 struct fb_event *event = data;
3002 struct fb_info *info = event->info;
3003 struct fb_videomode *mode;
3004 struct fb_con2fbmap *con2fb;
3008 * ignore all events except driver registration and deregistration
3009 * if fbcon is not active
3011 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3012 action == FB_EVENT_FB_UNREGISTERED))
3016 case FB_EVENT_SUSPEND:
3017 fbcon_suspended(info);
3019 case FB_EVENT_RESUME:
3020 fbcon_resumed(info);
3022 case FB_EVENT_MODE_CHANGE:
3023 fbcon_modechanged(info);
3025 case FB_EVENT_MODE_CHANGE_ALL:
3026 fbcon_set_all_vcs(info);
3028 case FB_EVENT_MODE_DELETE:
3030 ret = fbcon_mode_deleted(info, mode);
3032 case FB_EVENT_FB_REGISTERED:
3033 ret = fbcon_fb_registered(info->node);
3035 case FB_EVENT_FB_UNREGISTERED:
3036 ret = fbcon_fb_unregistered(info->node);
3038 case FB_EVENT_SET_CONSOLE_MAP:
3039 con2fb = event->data;
3040 ret = set_con2fb_map(con2fb->console - 1,
3041 con2fb->framebuffer, 1);
3043 case FB_EVENT_GET_CONSOLE_MAP:
3044 con2fb = event->data;
3045 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3047 case FB_EVENT_BLANK:
3048 fbcon_fb_blanked(info, *(int *)event->data);
3050 case FB_EVENT_NEW_MODELIST:
3051 fbcon_new_modelist(info);
3060 * The console `switch' structure for the frame buffer based console
3063 static const struct consw fb_con = {
3064 .owner = THIS_MODULE,
3065 .con_startup = fbcon_startup,
3066 .con_init = fbcon_init,
3067 .con_deinit = fbcon_deinit,
3068 .con_clear = fbcon_clear,
3069 .con_putc = fbcon_putc,
3070 .con_putcs = fbcon_putcs,
3071 .con_cursor = fbcon_cursor,
3072 .con_scroll = fbcon_scroll,
3073 .con_bmove = fbcon_bmove,
3074 .con_switch = fbcon_switch,
3075 .con_blank = fbcon_blank,
3076 .con_font_set = fbcon_set_font,
3077 .con_font_get = fbcon_get_font,
3078 .con_font_default = fbcon_set_def_font,
3079 .con_font_copy = fbcon_copy_font,
3080 .con_set_palette = fbcon_set_palette,
3081 .con_scrolldelta = fbcon_scrolldelta,
3082 .con_set_origin = fbcon_set_origin,
3083 .con_invert_region = fbcon_invert_region,
3084 .con_screen_pos = fbcon_screen_pos,
3085 .con_getxy = fbcon_getxy,
3086 .con_resize = fbcon_resize,
3089 static struct notifier_block fbcon_event_notifier = {
3090 .notifier_call = fbcon_event_notify,
3093 static ssize_t store_rotate(struct class_device *class_device,
3094 const char *buf, size_t count)
3096 struct fb_info *info;
3100 if (fbcon_has_exited)
3103 acquire_console_sem();
3104 idx = con2fb_map[fg_console];
3106 if (idx == -1 || registered_fb[idx] == NULL)
3109 info = registered_fb[idx];
3110 rotate = simple_strtoul(buf, last, 0);
3111 fbcon_rotate(info, rotate);
3113 release_console_sem();
3117 static ssize_t store_rotate_all(struct class_device *class_device,
3118 const char *buf, size_t count)
3120 struct fb_info *info;
3124 if (fbcon_has_exited)
3127 acquire_console_sem();
3128 idx = con2fb_map[fg_console];
3130 if (idx == -1 || registered_fb[idx] == NULL)
3133 info = registered_fb[idx];
3134 rotate = simple_strtoul(buf, last, 0);
3135 fbcon_rotate_all(info, rotate);
3137 release_console_sem();
3141 static ssize_t show_rotate(struct class_device *class_device, char *buf)
3143 struct fb_info *info;
3144 int rotate = 0, idx;
3146 if (fbcon_has_exited)
3149 acquire_console_sem();
3150 idx = con2fb_map[fg_console];
3152 if (idx == -1 || registered_fb[idx] == NULL)
3155 info = registered_fb[idx];
3156 rotate = fbcon_get_rotate(info);
3158 release_console_sem();
3159 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3162 static struct class_device_attribute class_device_attrs[] = {
3163 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3164 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3167 static int fbcon_init_class_device(void)
3171 fbcon_has_sysfs = 1;
3173 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3174 error = class_device_create_file(fbcon_class_device,
3175 &class_device_attrs[i]);
3183 class_device_remove_file(fbcon_class_device,
3184 &class_device_attrs[i]);
3186 fbcon_has_sysfs = 0;
3192 static void fbcon_start(void)
3194 if (num_registered_fb) {
3197 acquire_console_sem();
3199 for (i = 0; i < FB_MAX; i++) {
3200 if (registered_fb[i] != NULL) {
3206 release_console_sem();
3211 static void fbcon_exit(void)
3213 struct fb_info *info;
3216 if (fbcon_has_exited)
3220 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3223 if (MACH_IS_MAC && vbl_detected)
3224 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
3227 kfree((void *)softback_buf);
3230 for (i = 0; i < FB_MAX; i++) {
3232 info = registered_fb[i];
3237 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3238 if (con2fb_map[j] == i)
3243 if (info->fbops->fb_release)
3244 info->fbops->fb_release(info, 0);
3245 module_put(info->fbops->owner);
3247 if (info->fbcon_par) {
3248 struct fbcon_ops *ops = info->fbcon_par;
3250 fbcon_del_cursor_timer(info);
3251 kfree(ops->cursor_src);
3252 kfree(info->fbcon_par);
3253 info->fbcon_par = NULL;
3256 if (info->queue.func == fb_flashcursor)
3257 info->queue.func = NULL;
3261 fbcon_has_exited = 1;
3264 static int __init fb_console_init(void)
3268 acquire_console_sem();
3269 fb_register_client(&fbcon_event_notifier);
3270 fbcon_class_device =
3271 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
3273 if (IS_ERR(fbcon_class_device)) {
3274 printk(KERN_WARNING "Unable to create class_device "
3275 "for fbcon; errno = %ld\n",
3276 PTR_ERR(fbcon_class_device));
3277 fbcon_class_device = NULL;
3279 fbcon_init_class_device();
3281 for (i = 0; i < MAX_NR_CONSOLES; i++)
3284 release_console_sem();
3289 module_init(fb_console_init);
3293 static void __exit fbcon_deinit_class_device(void)
3297 if (fbcon_has_sysfs) {
3298 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3299 class_device_remove_file(fbcon_class_device,
3300 &class_device_attrs[i]);
3302 fbcon_has_sysfs = 0;
3306 static void __exit fb_console_exit(void)
3308 acquire_console_sem();
3309 fb_unregister_client(&fbcon_event_notifier);
3310 fbcon_deinit_class_device();
3311 class_device_destroy(fb_class, MKDEV(0, 0));
3313 release_console_sem();
3314 unregister_con_driver(&fb_con);
3317 module_exit(fb_console_exit);
3321 MODULE_LICENSE("GPL");