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 static struct display fb_display[MAX_NR_CONSOLES];
111 static signed char con2fb_map[MAX_NR_CONSOLES];
112 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
113 static int logo_height;
114 static int logo_lines;
115 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
117 static int logo_shown = FBCON_LOGO_CANSHOW;
118 /* Software scrollback */
119 static int fbcon_softback_size = 32768;
120 static unsigned long softback_buf, softback_curr;
121 static unsigned long softback_in;
122 static unsigned long softback_top, softback_end;
123 static int softback_lines;
124 /* console mappings */
125 static int first_fb_vc;
126 static int last_fb_vc = MAX_NR_CONSOLES - 1;
127 static int fbcon_is_default = 1;
129 static char fontname[40];
131 /* current fb_info */
132 static int info_idx = -1;
134 /* console rotation */
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 void fbcon_free_font(struct display *);
144 static int fbcon_set_origin(struct vc_data *);
146 #define CURSOR_DRAW_DELAY (1)
148 /* # VBL ints between cursor state changes */
149 #define ATARI_CURSOR_BLINK_RATE (42)
150 #define MAC_CURSOR_BLINK_RATE (32)
151 #define DEFAULT_CURSOR_BLINK_RATE (20)
153 static int vbl_cursor_cnt;
155 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
158 * Interface used by the world
161 static const char *fbcon_startup(void);
162 static void fbcon_init(struct vc_data *vc, int init);
163 static void fbcon_deinit(struct vc_data *vc);
164 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
166 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
167 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
168 int count, int ypos, int xpos);
169 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
170 static void fbcon_cursor(struct vc_data *vc, int mode);
171 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
173 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
174 int height, int width);
175 static int fbcon_switch(struct vc_data *vc);
176 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
177 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
178 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
183 static __inline__ void ywrap_up(struct vc_data *vc, int count);
184 static __inline__ void ywrap_down(struct vc_data *vc, int count);
185 static __inline__ void ypan_up(struct vc_data *vc, int count);
186 static __inline__ void ypan_down(struct vc_data *vc, int count);
187 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
188 int dy, int dx, int height, int width, u_int y_break);
189 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
193 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
194 int line, int count, int dy);
195 static void fbcon_modechanged(struct fb_info *info);
196 static void fbcon_set_all_vcs(struct fb_info *info);
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, struct pt_regs *fp)
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 = 0; i < MAX_NR_CONSOLES; 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(void *private)
387 struct fb_info *info = private;
388 struct fbcon_ops *ops = info->fbcon_par;
390 struct vc_data *vc = NULL;
394 if (ops->currcon != -1)
395 vc = vc_cons[ops->currcon].d;
397 if (!vc || !CON_IS_VISIBLE(vc) ||
398 fbcon_is_inactive(vc, info) ||
399 registered_fb[con2fb_map[vc->vc_num]] != info ||
400 vc_cons[ops->currcon].d->vc_deccm != 1)
402 acquire_console_sem();
403 p = &fb_display[vc->vc_num];
404 c = scr_readw((u16 *) vc->vc_pos);
405 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
407 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
408 get_color(vc, info, c, 0));
409 release_console_sem();
412 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
413 static int cursor_blink_rate;
414 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
416 struct fb_info *info = dev_id;
418 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
419 schedule_work(&info->queue);
420 vbl_cursor_cnt = cursor_blink_rate;
426 static void cursor_timer_handler(unsigned long dev_addr)
428 struct fb_info *info = (struct fb_info *) dev_addr;
429 struct fbcon_ops *ops = info->fbcon_par;
431 schedule_work(&info->queue);
432 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
435 static void fbcon_add_cursor_timer(struct fb_info *info)
437 struct fbcon_ops *ops = info->fbcon_par;
439 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
440 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
441 if (!info->queue.func)
442 INIT_WORK(&info->queue, fb_flashcursor, info);
444 init_timer(&ops->cursor_timer);
445 ops->cursor_timer.function = cursor_timer_handler;
446 ops->cursor_timer.expires = jiffies + HZ / 5;
447 ops->cursor_timer.data = (unsigned long ) info;
448 add_timer(&ops->cursor_timer);
449 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
453 static void fbcon_del_cursor_timer(struct fb_info *info)
455 struct fbcon_ops *ops = info->fbcon_par;
457 if (info->queue.func == fb_flashcursor &&
458 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
459 del_timer_sync(&ops->cursor_timer);
460 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
465 static int __init fb_console_setup(char *this_opt)
470 if (!this_opt || !*this_opt)
473 while ((options = strsep(&this_opt, ",")) != NULL) {
474 if (!strncmp(options, "font:", 5))
475 strcpy(fontname, options + 5);
477 if (!strncmp(options, "scrollback:", 11)) {
480 fbcon_softback_size = simple_strtoul(options, &options, 0);
481 if (*options == 'k' || *options == 'K') {
482 fbcon_softback_size *= 1024;
492 if (!strncmp(options, "map:", 4)) {
495 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
499 (options[j++]-'0') % FB_MAX;
504 if (!strncmp(options, "vc:", 3)) {
507 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
510 if (*options++ == '-')
511 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
512 fbcon_is_default = 0;
515 if (!strncmp(options, "rotate:", 7)) {
518 rotate = simple_strtoul(options, &options, 0);
526 __setup("fbcon=", fb_console_setup);
529 static int search_fb_in_map(int idx)
533 for (i = 0; i < MAX_NR_CONSOLES; i++) {
534 if (con2fb_map[i] == idx)
540 static int search_for_mapped_con(void)
544 for (i = 0; i < MAX_NR_CONSOLES; i++) {
545 if (con2fb_map[i] != -1)
551 static int fbcon_takeover(int show_logo)
555 if (!num_registered_fb)
559 logo_shown = FBCON_LOGO_DONTSHOW;
561 for (i = first_fb_vc; i <= last_fb_vc; i++)
562 con2fb_map[i] = info_idx;
564 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
567 for (i = first_fb_vc; i <= last_fb_vc; i++) {
576 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
577 int cols, int rows, int new_cols, int new_rows)
579 /* Need to make room for the logo */
580 struct fbcon_ops *ops = info->fbcon_par;
581 int cnt, erase = vc->vc_video_erase_char, step;
582 unsigned short *save = NULL, *r, *q;
585 * remove underline attribute from erase character
586 * if black and white framebuffer.
588 if (fb_get_color_depth(&info->var, &info->fix) == 1)
590 logo_height = fb_prepare_logo(info, ops->rotate);
591 logo_lines = (logo_height + vc->vc_font.height - 1) /
593 q = (unsigned short *) (vc->vc_origin +
594 vc->vc_size_row * rows);
595 step = logo_lines * cols;
596 for (r = q - logo_lines * cols; r < q; r++)
597 if (scr_readw(r) != vc->vc_video_erase_char)
599 if (r != q && new_rows >= rows + logo_lines) {
600 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
602 int i = cols < new_cols ? cols : new_cols;
603 scr_memsetw(save, erase, logo_lines * new_cols * 2);
605 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
606 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
611 /* We can scroll screen down */
613 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
614 scr_memcpyw(r + step, r, vc->vc_size_row);
618 vc->vc_y += logo_lines;
619 vc->vc_pos += logo_lines * vc->vc_size_row;
622 scr_memsetw((unsigned short *) vc->vc_origin,
624 vc->vc_size_row * logo_lines);
626 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
627 fbcon_clear_margins(vc, 0);
632 q = (unsigned short *) (vc->vc_origin +
635 scr_memcpyw(q, save, logo_lines * new_cols * 2);
636 vc->vc_y += logo_lines;
637 vc->vc_pos += logo_lines * vc->vc_size_row;
641 if (logo_lines > vc->vc_bottom) {
642 logo_shown = FBCON_LOGO_CANSHOW;
644 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
645 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
646 logo_shown = FBCON_LOGO_DRAW;
647 vc->vc_top = logo_lines;
651 #ifdef CONFIG_FB_TILEBLITTING
652 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
654 struct fbcon_ops *ops = info->fbcon_par;
656 ops->p = &fb_display[vc->vc_num];
658 if ((info->flags & FBINFO_MISC_TILEBLITTING))
659 fbcon_set_tileops(vc, info);
661 fbcon_set_rotation(info);
662 fbcon_set_bitops(ops);
666 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
668 struct fbcon_ops *ops = info->fbcon_par;
670 info->flags &= ~FBINFO_MISC_TILEBLITTING;
671 ops->p = &fb_display[vc->vc_num];
672 fbcon_set_rotation(info);
673 fbcon_set_bitops(ops);
675 #endif /* CONFIG_MISC_TILEBLITTING */
678 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
679 int unit, int oldidx)
681 struct fbcon_ops *ops = NULL;
684 if (!try_module_get(info->fbops->owner))
687 if (!err && info->fbops->fb_open &&
688 info->fbops->fb_open(info, 0))
692 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
698 info->fbcon_par = ops;
699 set_blitting_type(vc, info);
703 con2fb_map[unit] = oldidx;
704 module_put(info->fbops->owner);
710 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
711 struct fb_info *newinfo, int unit,
712 int oldidx, int found)
714 struct fbcon_ops *ops = oldinfo->fbcon_par;
717 if (oldinfo->fbops->fb_release &&
718 oldinfo->fbops->fb_release(oldinfo, 0)) {
719 con2fb_map[unit] = oldidx;
720 if (!found && newinfo->fbops->fb_release)
721 newinfo->fbops->fb_release(newinfo, 0);
723 module_put(newinfo->fbops->owner);
728 fbcon_del_cursor_timer(oldinfo);
729 kfree(ops->cursor_state.mask);
730 kfree(ops->cursor_data);
731 kfree(ops->fontbuffer);
732 kfree(oldinfo->fbcon_par);
733 oldinfo->fbcon_par = NULL;
734 module_put(oldinfo->fbops->owner);
736 If oldinfo and newinfo are driving the same hardware,
737 the fb_release() method of oldinfo may attempt to
738 restore the hardware state. This will leave the
739 newinfo in an undefined state. Thus, a call to
740 fb_set_par() may be needed for the newinfo.
742 if (newinfo->fbops->fb_set_par)
743 newinfo->fbops->fb_set_par(newinfo);
749 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
750 int unit, int show_logo)
752 struct fbcon_ops *ops = info->fbcon_par;
754 ops->currcon = fg_console;
756 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
757 info->fbops->fb_set_par(info);
759 ops->flags |= FBCON_FLAGS_INIT;
763 fbcon_set_disp(info, &info->var, vc);
765 fbcon_preset_disp(info, &info->var, unit);
768 struct vc_data *fg_vc = vc_cons[fg_console].d;
769 struct fb_info *fg_info =
770 registered_fb[con2fb_map[fg_console]];
772 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
773 fg_vc->vc_rows, fg_vc->vc_cols,
777 update_screen(vc_cons[fg_console].d);
781 * set_con2fb_map - map console to frame buffer device
782 * @unit: virtual console number to map
783 * @newidx: frame buffer index to map virtual console to
784 * @user: user request
786 * Maps a virtual console @unit to a frame buffer device
789 static int set_con2fb_map(int unit, int newidx, int user)
791 struct vc_data *vc = vc_cons[unit].d;
792 int oldidx = con2fb_map[unit];
793 struct fb_info *info = registered_fb[newidx];
794 struct fb_info *oldinfo = NULL;
797 if (oldidx == newidx)
803 if (!err && !search_for_mapped_con()) {
805 return fbcon_takeover(0);
809 oldinfo = registered_fb[oldidx];
811 found = search_fb_in_map(newidx);
813 acquire_console_sem();
814 con2fb_map[unit] = newidx;
816 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
820 * If old fb is not mapped to any of the consoles,
821 * fbcon should release it.
823 if (!err && oldinfo && !search_fb_in_map(oldidx))
824 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
828 int show_logo = (fg_console == 0 && !user &&
829 logo_shown != FBCON_LOGO_DONTSHOW);
832 fbcon_add_cursor_timer(info);
833 con2fb_map_boot[unit] = newidx;
834 con2fb_init_display(vc, info, unit, show_logo);
837 release_console_sem();
842 * Low Level Operations
844 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
845 static int var_to_display(struct display *disp,
846 struct fb_var_screeninfo *var,
847 struct fb_info *info)
849 disp->xres_virtual = var->xres_virtual;
850 disp->yres_virtual = var->yres_virtual;
851 disp->bits_per_pixel = var->bits_per_pixel;
852 disp->grayscale = var->grayscale;
853 disp->nonstd = var->nonstd;
854 disp->accel_flags = var->accel_flags;
855 disp->height = var->height;
856 disp->width = var->width;
857 disp->red = var->red;
858 disp->green = var->green;
859 disp->blue = var->blue;
860 disp->transp = var->transp;
861 disp->rotate = var->rotate;
862 disp->mode = fb_match_mode(var, &info->modelist);
863 if (disp->mode == NULL)
864 /* This should not happen */
869 static void display_to_var(struct fb_var_screeninfo *var,
870 struct display *disp)
872 fb_videomode_to_var(var, disp->mode);
873 var->xres_virtual = disp->xres_virtual;
874 var->yres_virtual = disp->yres_virtual;
875 var->bits_per_pixel = disp->bits_per_pixel;
876 var->grayscale = disp->grayscale;
877 var->nonstd = disp->nonstd;
878 var->accel_flags = disp->accel_flags;
879 var->height = disp->height;
880 var->width = disp->width;
881 var->red = disp->red;
882 var->green = disp->green;
883 var->blue = disp->blue;
884 var->transp = disp->transp;
885 var->rotate = disp->rotate;
888 static const char *fbcon_startup(void)
890 const char *display_desc = "frame buffer device";
891 struct display *p = &fb_display[fg_console];
892 struct vc_data *vc = vc_cons[fg_console].d;
893 const struct font_desc *font = NULL;
894 struct module *owner;
895 struct fb_info *info = NULL;
896 struct fbcon_ops *ops;
902 * If num_registered_fb is zero, this is a call for the dummy part.
903 * The frame buffer devices weren't initialized yet.
905 if (!num_registered_fb || info_idx == -1)
908 * Instead of blindly using registered_fb[0], we use info_idx, set by
911 info = registered_fb[info_idx];
915 owner = info->fbops->owner;
916 if (!try_module_get(owner))
918 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
923 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
931 ops->cur_rotate = -1;
932 info->fbcon_par = ops;
933 p->con_rotate = rotate;
934 set_blitting_type(vc, info);
936 if (info->fix.type != FB_TYPE_TEXT) {
937 if (fbcon_softback_size) {
941 kmalloc(fbcon_softback_size,
944 fbcon_softback_size = 0;
950 kfree((void *) softback_buf);
956 softback_in = softback_top = softback_curr =
961 /* Setup default font */
963 if (!fontname[0] || !(font = find_font(fontname)))
964 font = get_default_font(info->var.xres,
966 vc->vc_font.width = font->width;
967 vc->vc_font.height = font->height;
968 vc->vc_font.data = (void *)(p->fontdata = font->data);
969 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
972 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
973 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
974 cols /= vc->vc_font.width;
975 rows /= vc->vc_font.height;
976 vc_resize(vc, cols, rows);
978 DPRINTK("mode: %s\n", info->fix.id);
979 DPRINTK("visual: %d\n", info->fix.visual);
980 DPRINTK("res: %dx%d-%d\n", info->var.xres,
982 info->var.bits_per_pixel);
986 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
988 request_irq(IRQ_AUTO_4, fb_vbl_handler,
989 IRQ_TYPE_PRIO, "framebuffer vbl",
992 #endif /* CONFIG_ATARI */
996 * On a Macintoy, the VBL interrupt may or may not be active.
997 * As interrupt based cursor is more reliable and race free, we
998 * probe for VBL interrupts.
1003 * Probe for VBL: set temp. handler ...
1005 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1006 "framebuffer vbl", info);
1010 * ... and spin for 20 ms ...
1012 while (!vbl_detected && ++ct < 1000)
1017 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1019 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1023 * interrupt based cursor ok
1025 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1027 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1028 "framebuffer vbl", info);
1031 * VBL not detected: fall through, use timer based cursor
1036 #endif /* CONFIG_MAC */
1038 fbcon_add_cursor_timer(info);
1039 return display_desc;
1042 static void fbcon_init(struct vc_data *vc, int init)
1044 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1045 struct fbcon_ops *ops;
1046 struct vc_data **default_mode = vc->vc_display_fg;
1047 struct vc_data *svc = *default_mode;
1048 struct display *t, *p = &fb_display[vc->vc_num];
1049 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1052 if (info_idx == -1 || info == NULL)
1057 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1058 (info->fix.type == FB_TYPE_TEXT))
1061 if (var_to_display(p, &info->var, info))
1064 /* If we are not the first console on this
1065 fb, copy the font from that console */
1066 t = &fb_display[svc->vc_num];
1067 if (!vc->vc_font.data) {
1068 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1069 vc->vc_font.width = (*default_mode)->vc_font.width;
1070 vc->vc_font.height = (*default_mode)->vc_font.height;
1071 p->userfont = t->userfont;
1073 REFCOUNT(p->fontdata)++;
1076 charcnt = FNTCHARCNT(p->fontdata);
1077 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1078 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1079 if (charcnt == 256) {
1080 vc->vc_hi_font_mask = 0;
1082 vc->vc_hi_font_mask = 0x100;
1083 if (vc->vc_can_do_color)
1084 vc->vc_complement_mask <<= 1;
1087 if (!*svc->vc_uni_pagedir_loc)
1088 con_set_default_unimap(svc);
1089 if (!*vc->vc_uni_pagedir_loc)
1090 con_copy_unimap(vc, svc);
1092 ops = info->fbcon_par;
1093 p->con_rotate = rotate;
1094 set_blitting_type(vc, info);
1098 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1099 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1100 new_cols /= vc->vc_font.width;
1101 new_rows /= vc->vc_font.height;
1102 vc_resize(vc, new_cols, new_rows);
1105 * We must always set the mode. The mode of the previous console
1106 * driver could be in the same resolution but we are using different
1107 * hardware so we have to initialize the hardware.
1109 * We need to do it in fbcon_init() to prevent screen corruption.
1111 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1112 if (info->fbops->fb_set_par &&
1113 !(ops->flags & FBCON_FLAGS_INIT))
1114 info->fbops->fb_set_par(info);
1115 ops->flags |= FBCON_FLAGS_INIT;
1120 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1121 !(cap & FBINFO_HWACCEL_DISABLED))
1122 p->scrollmode = SCROLL_MOVE;
1123 else /* default to something safe */
1124 p->scrollmode = SCROLL_REDRAW;
1127 * ++guenther: console.c:vc_allocate() relies on initializing
1128 * vc_{cols,rows}, but we must not set those if we are only
1129 * resizing the console.
1132 vc->vc_cols = new_cols;
1133 vc->vc_rows = new_rows;
1137 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1139 if (vc == svc && softback_buf)
1140 fbcon_update_softback(vc);
1142 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1143 ops->rotate = FB_ROTATE_UR;
1144 set_blitting_type(vc, info);
1147 ops->p = &fb_display[fg_console];
1150 static void fbcon_deinit(struct vc_data *vc)
1152 struct display *p = &fb_display[vc->vc_num];
1159 /* ====================================================================== */
1161 /* fbcon_XXX routines - interface used by the world
1163 * This system is now divided into two levels because of complications
1164 * caused by hardware scrolling. Top level functions:
1166 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1168 * handles y values in range [0, scr_height-1] that correspond to real
1169 * screen positions. y_wrap shift means that first line of bitmap may be
1170 * anywhere on this display. These functions convert lineoffsets to
1171 * bitmap offsets and deal with the wrap-around case by splitting blits.
1173 * fbcon_bmove_physical_8() -- These functions fast implementations
1174 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1175 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1179 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1180 * Implies should only really hardware scroll in rows. Only reason for
1181 * restriction is simplicity & efficiency at the moment.
1184 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1187 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1188 struct fbcon_ops *ops = info->fbcon_par;
1190 struct display *p = &fb_display[vc->vc_num];
1193 if (fbcon_is_inactive(vc, info))
1196 if (!height || !width)
1199 /* Split blits that cross physical y_wrap boundary */
1201 y_break = p->vrows - p->yscroll;
1202 if (sy < y_break && sy + height - 1 >= y_break) {
1203 u_int b = y_break - sy;
1204 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1205 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1208 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1211 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1212 int count, int ypos, int xpos)
1214 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1215 struct display *p = &fb_display[vc->vc_num];
1216 struct fbcon_ops *ops = info->fbcon_par;
1218 if (!fbcon_is_inactive(vc, info))
1219 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1220 get_color(vc, info, scr_readw(s), 1),
1221 get_color(vc, info, scr_readw(s), 0));
1224 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1228 scr_writew(c, &chr);
1229 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1232 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1234 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1235 struct fbcon_ops *ops = info->fbcon_par;
1237 if (!fbcon_is_inactive(vc, info))
1238 ops->clear_margins(vc, info, bottom_only);
1241 static void fbcon_cursor(struct vc_data *vc, int mode)
1243 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1244 struct fbcon_ops *ops = info->fbcon_par;
1246 int c = scr_readw((u16 *) vc->vc_pos);
1248 if (fbcon_is_inactive(vc, info))
1251 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1252 if (mode & CM_SOFTBACK) {
1253 mode &= ~CM_SOFTBACK;
1257 fbcon_set_origin(vc);
1261 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1262 get_color(vc, info, c, 0));
1263 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1266 static int scrollback_phys_max = 0;
1267 static int scrollback_max = 0;
1268 static int scrollback_current = 0;
1271 * If no vc is existent yet, just set struct display
1273 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1276 struct display *p = &fb_display[unit];
1277 struct display *t = &fb_display[fg_console];
1279 if (var_to_display(p, var, info))
1282 p->fontdata = t->fontdata;
1283 p->userfont = t->userfont;
1285 REFCOUNT(p->fontdata)++;
1288 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1291 struct display *p = &fb_display[vc->vc_num], *t;
1292 struct vc_data **default_mode = vc->vc_display_fg;
1293 struct vc_data *svc = *default_mode;
1294 struct fbcon_ops *ops = info->fbcon_par;
1295 int rows, cols, charcnt = 256;
1297 if (var_to_display(p, var, info))
1299 t = &fb_display[svc->vc_num];
1300 if (!vc->vc_font.data) {
1301 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1302 vc->vc_font.width = (*default_mode)->vc_font.width;
1303 vc->vc_font.height = (*default_mode)->vc_font.height;
1304 p->userfont = t->userfont;
1306 REFCOUNT(p->fontdata)++;
1309 charcnt = FNTCHARCNT(p->fontdata);
1311 var->activate = FB_ACTIVATE_NOW;
1312 info->var.activate = var->activate;
1313 var->yoffset = info->var.yoffset;
1314 var->xoffset = info->var.xoffset;
1315 fb_set_var(info, var);
1316 ops->var = info->var;
1317 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1318 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1319 if (charcnt == 256) {
1320 vc->vc_hi_font_mask = 0;
1322 vc->vc_hi_font_mask = 0x100;
1323 if (vc->vc_can_do_color)
1324 vc->vc_complement_mask <<= 1;
1327 if (!*svc->vc_uni_pagedir_loc)
1328 con_set_default_unimap(svc);
1329 if (!*vc->vc_uni_pagedir_loc)
1330 con_copy_unimap(vc, svc);
1332 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1333 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1334 cols /= vc->vc_font.width;
1335 rows /= vc->vc_font.height;
1336 vc_resize(vc, cols, rows);
1338 if (CON_IS_VISIBLE(vc)) {
1341 fbcon_update_softback(vc);
1345 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1347 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1348 struct fbcon_ops *ops = info->fbcon_par;
1349 struct display *p = &fb_display[vc->vc_num];
1351 p->yscroll += count;
1352 if (p->yscroll >= p->vrows) /* Deal with wrap */
1353 p->yscroll -= p->vrows;
1354 ops->var.xoffset = 0;
1355 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1356 ops->var.vmode |= FB_VMODE_YWRAP;
1357 ops->update_start(info);
1358 scrollback_max += count;
1359 if (scrollback_max > scrollback_phys_max)
1360 scrollback_max = scrollback_phys_max;
1361 scrollback_current = 0;
1364 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1366 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1367 struct fbcon_ops *ops = info->fbcon_par;
1368 struct display *p = &fb_display[vc->vc_num];
1370 p->yscroll -= count;
1371 if (p->yscroll < 0) /* Deal with wrap */
1372 p->yscroll += p->vrows;
1373 ops->var.xoffset = 0;
1374 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1375 ops->var.vmode |= FB_VMODE_YWRAP;
1376 ops->update_start(info);
1377 scrollback_max -= count;
1378 if (scrollback_max < 0)
1380 scrollback_current = 0;
1383 static __inline__ void ypan_up(struct vc_data *vc, int count)
1385 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1386 struct display *p = &fb_display[vc->vc_num];
1387 struct fbcon_ops *ops = info->fbcon_par;
1389 p->yscroll += count;
1390 if (p->yscroll > p->vrows - vc->vc_rows) {
1391 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1392 0, 0, 0, vc->vc_rows, vc->vc_cols);
1393 p->yscroll -= p->vrows - vc->vc_rows;
1396 ops->var.xoffset = 0;
1397 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1398 ops->var.vmode &= ~FB_VMODE_YWRAP;
1399 ops->update_start(info);
1400 fbcon_clear_margins(vc, 1);
1401 scrollback_max += count;
1402 if (scrollback_max > scrollback_phys_max)
1403 scrollback_max = scrollback_phys_max;
1404 scrollback_current = 0;
1407 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1409 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1410 struct fbcon_ops *ops = info->fbcon_par;
1411 struct display *p = &fb_display[vc->vc_num];
1413 p->yscroll += count;
1415 if (p->yscroll > p->vrows - vc->vc_rows) {
1416 p->yscroll -= p->vrows - vc->vc_rows;
1417 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1420 ops->var.xoffset = 0;
1421 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1422 ops->var.vmode &= ~FB_VMODE_YWRAP;
1423 ops->update_start(info);
1424 fbcon_clear_margins(vc, 1);
1425 scrollback_max += count;
1426 if (scrollback_max > scrollback_phys_max)
1427 scrollback_max = scrollback_phys_max;
1428 scrollback_current = 0;
1431 static __inline__ void ypan_down(struct vc_data *vc, int count)
1433 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1434 struct display *p = &fb_display[vc->vc_num];
1435 struct fbcon_ops *ops = info->fbcon_par;
1437 p->yscroll -= count;
1438 if (p->yscroll < 0) {
1439 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1440 0, vc->vc_rows, vc->vc_cols);
1441 p->yscroll += p->vrows - vc->vc_rows;
1444 ops->var.xoffset = 0;
1445 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1446 ops->var.vmode &= ~FB_VMODE_YWRAP;
1447 ops->update_start(info);
1448 fbcon_clear_margins(vc, 1);
1449 scrollback_max -= count;
1450 if (scrollback_max < 0)
1452 scrollback_current = 0;
1455 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1457 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1458 struct fbcon_ops *ops = info->fbcon_par;
1459 struct display *p = &fb_display[vc->vc_num];
1461 p->yscroll -= count;
1463 if (p->yscroll < 0) {
1464 p->yscroll += p->vrows - vc->vc_rows;
1465 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1468 ops->var.xoffset = 0;
1469 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1470 ops->var.vmode &= ~FB_VMODE_YWRAP;
1471 ops->update_start(info);
1472 fbcon_clear_margins(vc, 1);
1473 scrollback_max -= count;
1474 if (scrollback_max < 0)
1476 scrollback_current = 0;
1479 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1482 int count = vc->vc_rows;
1483 unsigned short *d, *s;
1487 d = (u16 *) softback_curr;
1488 if (d == (u16 *) softback_in)
1489 d = (u16 *) vc->vc_origin;
1490 n = softback_curr + delta * vc->vc_size_row;
1491 softback_lines -= delta;
1493 if (softback_curr < softback_top && n < softback_buf) {
1494 n += softback_end - softback_buf;
1495 if (n < softback_top) {
1497 (softback_top - n) / vc->vc_size_row;
1500 } else if (softback_curr >= softback_top
1501 && n < softback_top) {
1503 (softback_top - n) / vc->vc_size_row;
1507 if (softback_curr > softback_in && n >= softback_end) {
1508 n += softback_buf - softback_end;
1509 if (n > softback_in) {
1513 } else if (softback_curr <= softback_in && n > softback_in) {
1518 if (n == softback_curr)
1521 s = (u16 *) softback_curr;
1522 if (s == (u16 *) softback_in)
1523 s = (u16 *) vc->vc_origin;
1525 unsigned short *start;
1529 unsigned short attr = 1;
1532 le = advance_row(s, 1);
1535 if (attr != (c & 0xff00)) {
1538 fbcon_putcs(vc, start, s - start,
1544 if (c == scr_readw(d)) {
1546 fbcon_putcs(vc, start, s - start,
1559 fbcon_putcs(vc, start, s - start, line, x);
1561 if (d == (u16 *) softback_end)
1562 d = (u16 *) softback_buf;
1563 if (d == (u16 *) softback_in)
1564 d = (u16 *) vc->vc_origin;
1565 if (s == (u16 *) softback_end)
1566 s = (u16 *) softback_buf;
1567 if (s == (u16 *) softback_in)
1568 s = (u16 *) vc->vc_origin;
1572 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1573 int line, int count, int dy)
1575 unsigned short *s = (unsigned short *)
1576 (vc->vc_origin + vc->vc_size_row * line);
1579 unsigned short *start = s;
1580 unsigned short *le = advance_row(s, 1);
1583 unsigned short attr = 1;
1587 if (attr != (c & 0xff00)) {
1590 fbcon_putcs(vc, start, s - start,
1596 console_conditional_schedule();
1600 fbcon_putcs(vc, start, s - start, dy, x);
1601 console_conditional_schedule();
1606 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1607 int line, int count, int offset)
1609 unsigned short *d = (unsigned short *)
1610 (vc->vc_origin + vc->vc_size_row * line);
1611 unsigned short *s = d + offset;
1614 unsigned short *start = s;
1615 unsigned short *le = advance_row(s, 1);
1618 unsigned short attr = 1;
1622 if (attr != (c & 0xff00)) {
1625 fbcon_putcs(vc, start, s - start,
1631 if (c == scr_readw(d)) {
1633 fbcon_putcs(vc, start, s - start,
1643 console_conditional_schedule();
1648 fbcon_putcs(vc, start, s - start, line, x);
1649 console_conditional_schedule();
1654 /* NOTE: We subtract two lines from these pointers */
1655 s -= vc->vc_size_row;
1656 d -= vc->vc_size_row;
1661 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1666 if (vc->vc_num != fg_console)
1668 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1671 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1673 p = advance_row(p, 1);
1674 softback_in += vc->vc_size_row;
1675 if (softback_in == softback_end)
1676 softback_in = softback_buf;
1677 if (softback_in == softback_top) {
1678 softback_top += vc->vc_size_row;
1679 if (softback_top == softback_end)
1680 softback_top = softback_buf;
1683 softback_curr = softback_in;
1686 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1689 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1690 struct display *p = &fb_display[vc->vc_num];
1691 struct fbcon_ops *ops = info->fbcon_par;
1692 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1694 if (fbcon_is_inactive(vc, info))
1697 fbcon_cursor(vc, CM_ERASE);
1700 * ++Geert: Only use ywrap/ypan if the console is in text mode
1701 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1702 * whole screen (prevents flicker).
1707 if (count > vc->vc_rows) /* Maximum realistic size */
1708 count = vc->vc_rows;
1710 fbcon_softback_note(vc, t, count);
1711 if (logo_shown >= 0)
1713 switch (p->scrollmode) {
1715 ops->bmove(vc, info, t + count, 0, t, 0,
1716 b - t - count, vc->vc_cols);
1717 ops->clear(vc, info, b - count, 0, count,
1721 case SCROLL_WRAP_MOVE:
1722 if (b - t - count > 3 * vc->vc_rows >> 2) {
1724 fbcon_bmove(vc, 0, 0, count, 0, t,
1726 ywrap_up(vc, count);
1727 if (vc->vc_rows - b > 0)
1728 fbcon_bmove(vc, b - count, 0, b, 0,
1731 } else if (info->flags & FBINFO_READS_FAST)
1732 fbcon_bmove(vc, t + count, 0, t, 0,
1733 b - t - count, vc->vc_cols);
1736 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1739 case SCROLL_PAN_REDRAW:
1740 if ((p->yscroll + count <=
1741 2 * (p->vrows - vc->vc_rows))
1742 && ((!scroll_partial && (b - t == vc->vc_rows))
1745 3 * vc->vc_rows >> 2)))) {
1747 fbcon_redraw_move(vc, p, 0, t, count);
1748 ypan_up_redraw(vc, t, count);
1749 if (vc->vc_rows - b > 0)
1750 fbcon_redraw_move(vc, p, b,
1751 vc->vc_rows - b, b);
1753 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1754 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1757 case SCROLL_PAN_MOVE:
1758 if ((p->yscroll + count <=
1759 2 * (p->vrows - vc->vc_rows))
1760 && ((!scroll_partial && (b - t == vc->vc_rows))
1763 3 * vc->vc_rows >> 2)))) {
1765 fbcon_bmove(vc, 0, 0, count, 0, t,
1768 if (vc->vc_rows - b > 0)
1769 fbcon_bmove(vc, b - count, 0, b, 0,
1772 } else if (info->flags & FBINFO_READS_FAST)
1773 fbcon_bmove(vc, t + count, 0, t, 0,
1774 b - t - count, vc->vc_cols);
1777 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1782 fbcon_redraw(vc, p, t, b - t - count,
1783 count * vc->vc_cols);
1784 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1785 scr_memsetw((unsigned short *) (vc->vc_origin +
1788 vc->vc_video_erase_char,
1789 vc->vc_size_row * count);
1795 if (count > vc->vc_rows) /* Maximum realistic size */
1796 count = vc->vc_rows;
1797 if (logo_shown >= 0)
1799 switch (p->scrollmode) {
1801 ops->bmove(vc, info, t, 0, t + count, 0,
1802 b - t - count, vc->vc_cols);
1803 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1806 case SCROLL_WRAP_MOVE:
1807 if (b - t - count > 3 * vc->vc_rows >> 2) {
1808 if (vc->vc_rows - b > 0)
1809 fbcon_bmove(vc, b, 0, b - count, 0,
1812 ywrap_down(vc, count);
1814 fbcon_bmove(vc, count, 0, 0, 0, t,
1816 } else if (info->flags & FBINFO_READS_FAST)
1817 fbcon_bmove(vc, t, 0, t + count, 0,
1818 b - t - count, vc->vc_cols);
1821 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1824 case SCROLL_PAN_MOVE:
1825 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1826 && ((!scroll_partial && (b - t == vc->vc_rows))
1829 3 * vc->vc_rows >> 2)))) {
1830 if (vc->vc_rows - b > 0)
1831 fbcon_bmove(vc, b, 0, b - count, 0,
1834 ypan_down(vc, count);
1836 fbcon_bmove(vc, count, 0, 0, 0, t,
1838 } else if (info->flags & FBINFO_READS_FAST)
1839 fbcon_bmove(vc, t, 0, t + count, 0,
1840 b - t - count, vc->vc_cols);
1843 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1846 case SCROLL_PAN_REDRAW:
1847 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1848 && ((!scroll_partial && (b - t == vc->vc_rows))
1851 3 * vc->vc_rows >> 2)))) {
1852 if (vc->vc_rows - b > 0)
1853 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1855 ypan_down_redraw(vc, t, count);
1857 fbcon_redraw_move(vc, p, count, t, 0);
1859 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1860 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1865 fbcon_redraw(vc, p, b - 1, b - t - count,
1866 -count * vc->vc_cols);
1867 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1868 scr_memsetw((unsigned short *) (vc->vc_origin +
1871 vc->vc_video_erase_char,
1872 vc->vc_size_row * count);
1880 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1881 int height, int width)
1883 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1884 struct display *p = &fb_display[vc->vc_num];
1886 if (fbcon_is_inactive(vc, info))
1889 if (!width || !height)
1892 /* Split blits that cross physical y_wrap case.
1893 * Pathological case involves 4 blits, better to use recursive
1894 * code rather than unrolled case
1896 * Recursive invocations don't need to erase the cursor over and
1897 * over again, so we use fbcon_bmove_rec()
1899 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1900 p->vrows - p->yscroll);
1903 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1904 int dy, int dx, int height, int width, u_int y_break)
1906 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1907 struct fbcon_ops *ops = info->fbcon_par;
1910 if (sy < y_break && sy + height > y_break) {
1912 if (dy < sy) { /* Avoid trashing self */
1913 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1915 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1916 height - b, width, y_break);
1918 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1919 height - b, width, y_break);
1920 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1926 if (dy < y_break && dy + height > y_break) {
1928 if (dy < sy) { /* Avoid trashing self */
1929 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1931 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1932 height - b, width, y_break);
1934 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1935 height - b, width, y_break);
1936 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1941 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1945 static __inline__ void updatescrollmode(struct display *p,
1946 struct fb_info *info,
1949 struct fbcon_ops *ops = info->fbcon_par;
1950 int fh = vc->vc_font.height;
1951 int cap = info->flags;
1953 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1954 info->fix.xpanstep);
1955 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1956 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1957 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1958 info->var.xres_virtual);
1959 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1960 divides(ypan, vc->vc_font.height) && vyres > yres;
1961 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1962 divides(ywrap, vc->vc_font.height) &&
1963 divides(vc->vc_font.height, vyres) &&
1964 divides(vc->vc_font.height, yres);
1965 int reading_fast = cap & FBINFO_READS_FAST;
1966 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1967 !(cap & FBINFO_HWACCEL_DISABLED);
1968 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1969 !(cap & FBINFO_HWACCEL_DISABLED);
1971 p->vrows = vyres/fh;
1972 if (yres > (fh * (vc->vc_rows + 1)))
1973 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1974 if ((yres % fh) && (vyres % fh < yres % fh))
1977 if (good_wrap || good_pan) {
1978 if (reading_fast || fast_copyarea)
1979 p->scrollmode = good_wrap ?
1980 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1982 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1985 if (reading_fast || (fast_copyarea && !fast_imageblit))
1986 p->scrollmode = SCROLL_MOVE;
1988 p->scrollmode = SCROLL_REDRAW;
1992 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1993 unsigned int height)
1995 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1996 struct fbcon_ops *ops = info->fbcon_par;
1997 struct display *p = &fb_display[vc->vc_num];
1998 struct fb_var_screeninfo var = info->var;
1999 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2001 virt_w = FBCON_SWAP(ops->rotate, width, height);
2002 virt_h = FBCON_SWAP(ops->rotate, height, width);
2003 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2004 vc->vc_font.height);
2005 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2007 var.xres = virt_w * virt_fw;
2008 var.yres = virt_h * virt_fh;
2009 x_diff = info->var.xres - var.xres;
2010 y_diff = info->var.yres - var.yres;
2011 if (x_diff < 0 || x_diff > virt_fw ||
2012 y_diff < 0 || y_diff > virt_fh) {
2013 struct fb_videomode *mode;
2015 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2016 mode = fb_find_best_mode(&var, &info->modelist);
2019 display_to_var(&var, p);
2020 fb_videomode_to_var(&var, mode);
2022 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2025 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2026 if (CON_IS_VISIBLE(vc)) {
2027 var.activate = FB_ACTIVATE_NOW |
2029 fb_set_var(info, &var);
2031 var_to_display(p, &info->var, info);
2032 ops->var = info->var;
2034 updatescrollmode(p, info, vc);
2038 static int fbcon_switch(struct vc_data *vc)
2040 struct fb_info *info, *old_info = NULL;
2041 struct fbcon_ops *ops;
2042 struct display *p = &fb_display[vc->vc_num];
2043 struct fb_var_screeninfo var;
2044 int i, prev_console, charcnt = 256;
2046 info = registered_fb[con2fb_map[vc->vc_num]];
2047 ops = info->fbcon_par;
2051 fbcon_set_origin(vc);
2052 softback_top = softback_curr = softback_in = softback_buf;
2054 fbcon_update_softback(vc);
2057 if (logo_shown >= 0) {
2058 struct vc_data *conp2 = vc_cons[logo_shown].d;
2060 if (conp2->vc_top == logo_lines
2061 && conp2->vc_bottom == conp2->vc_rows)
2063 logo_shown = FBCON_LOGO_CANSHOW;
2066 prev_console = ops->currcon;
2067 if (prev_console != -1)
2068 old_info = registered_fb[con2fb_map[prev_console]];
2070 * FIXME: If we have multiple fbdev's loaded, we need to
2071 * update all info->currcon. Perhaps, we can place this
2072 * in a centralized structure, but this might break some
2075 * info->currcon = vc->vc_num;
2077 for (i = 0; i < FB_MAX; i++) {
2078 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2079 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2081 o->currcon = vc->vc_num;
2084 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2085 display_to_var(&var, p);
2086 var.activate = FB_ACTIVATE_NOW;
2089 * make sure we don't unnecessarily trip the memcmp()
2092 info->var.activate = var.activate;
2093 var.yoffset = info->var.yoffset;
2094 var.xoffset = info->var.xoffset;
2095 var.vmode = info->var.vmode;
2096 fb_set_var(info, &var);
2097 ops->var = info->var;
2099 if (old_info != NULL && (old_info != info ||
2100 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2101 if (info->fbops->fb_set_par)
2102 info->fbops->fb_set_par(info);
2104 if (old_info != info) {
2105 fbcon_del_cursor_timer(old_info);
2106 fbcon_add_cursor_timer(info);
2110 set_blitting_type(vc, info);
2111 ops->cursor_reset = 1;
2113 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2114 ops->rotate = FB_ROTATE_UR;
2115 set_blitting_type(vc, info);
2118 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2119 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2122 charcnt = FNTCHARCNT(vc->vc_font.data);
2125 vc->vc_complement_mask <<= 1;
2127 updatescrollmode(p, info, vc);
2129 switch (p->scrollmode) {
2130 case SCROLL_WRAP_MOVE:
2131 scrollback_phys_max = p->vrows - vc->vc_rows;
2133 case SCROLL_PAN_MOVE:
2134 case SCROLL_PAN_REDRAW:
2135 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2136 if (scrollback_phys_max < 0)
2137 scrollback_phys_max = 0;
2140 scrollback_phys_max = 0;
2145 scrollback_current = 0;
2147 if (!fbcon_is_inactive(vc, info)) {
2148 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2149 ops->update_start(info);
2152 fbcon_set_palette(vc, color_table);
2153 fbcon_clear_margins(vc, 0);
2155 if (logo_shown == FBCON_LOGO_DRAW) {
2157 logo_shown = fg_console;
2158 /* This is protected above by initmem_freed */
2159 fb_show_logo(info, ops->rotate);
2161 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2162 vc->vc_size_row * (vc->vc_bottom -
2169 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2173 unsigned short charmask = vc->vc_hi_font_mask ?
2175 unsigned short oldc;
2177 oldc = vc->vc_video_erase_char;
2178 vc->vc_video_erase_char &= charmask;
2179 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2180 vc->vc_video_erase_char = oldc;
2184 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2186 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2187 struct fbcon_ops *ops = info->fbcon_par;
2190 struct fb_var_screeninfo var = info->var;
2195 if (info->fbops->fb_save_state)
2196 info->fbops->fb_save_state(info);
2197 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2198 fb_set_var(info, &var);
2200 ops->var = info->var;
2201 } else if (info->fbops->fb_restore_state)
2202 info->fbops->fb_restore_state(info);
2205 if (!fbcon_is_inactive(vc, info)) {
2206 if (ops->blank_state != blank) {
2207 ops->blank_state = blank;
2208 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2209 ops->cursor_flash = (!blank);
2211 if (fb_blank(info, blank))
2212 fbcon_generic_blank(vc, info, blank);
2220 fbcon_add_cursor_timer(info);
2222 fbcon_del_cursor_timer(info);
2227 static void fbcon_free_font(struct display *p)
2229 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2230 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2235 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2237 u8 *fontdata = vc->vc_font.data;
2238 u8 *data = font->data;
2241 font->width = vc->vc_font.width;
2242 font->height = vc->vc_font.height;
2243 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2247 if (font->width <= 8) {
2248 j = vc->vc_font.height;
2249 for (i = 0; i < font->charcount; i++) {
2250 memcpy(data, fontdata, j);
2251 memset(data + j, 0, 32 - j);
2255 } else if (font->width <= 16) {
2256 j = vc->vc_font.height * 2;
2257 for (i = 0; i < font->charcount; i++) {
2258 memcpy(data, fontdata, j);
2259 memset(data + j, 0, 64 - j);
2263 } else if (font->width <= 24) {
2264 for (i = 0; i < font->charcount; i++) {
2265 for (j = 0; j < vc->vc_font.height; j++) {
2266 *data++ = fontdata[0];
2267 *data++ = fontdata[1];
2268 *data++ = fontdata[2];
2269 fontdata += sizeof(u32);
2271 memset(data, 0, 3 * (32 - j));
2272 data += 3 * (32 - j);
2275 j = vc->vc_font.height * 4;
2276 for (i = 0; i < font->charcount; i++) {
2277 memcpy(data, fontdata, j);
2278 memset(data + j, 0, 128 - j);
2286 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2287 const u8 * data, int userfont)
2289 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2290 struct fbcon_ops *ops = info->fbcon_par;
2291 struct display *p = &fb_display[vc->vc_num];
2294 char *old_data = NULL;
2296 if (CON_IS_VISIBLE(vc) && softback_lines)
2297 fbcon_set_origin(vc);
2299 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2301 old_data = vc->vc_font.data;
2303 cnt = FNTCHARCNT(data);
2306 vc->vc_font.data = (void *)(p->fontdata = data);
2307 if ((p->userfont = userfont))
2309 vc->vc_font.width = w;
2310 vc->vc_font.height = h;
2311 if (vc->vc_hi_font_mask && cnt == 256) {
2312 vc->vc_hi_font_mask = 0;
2313 if (vc->vc_can_do_color) {
2314 vc->vc_complement_mask >>= 1;
2315 vc->vc_s_complement_mask >>= 1;
2318 /* ++Edmund: reorder the attribute bits */
2319 if (vc->vc_can_do_color) {
2320 unsigned short *cp =
2321 (unsigned short *) vc->vc_origin;
2322 int count = vc->vc_screenbuf_size / 2;
2324 for (; count > 0; count--, cp++) {
2326 scr_writew(((c & 0xfe00) >> 1) |
2329 c = vc->vc_video_erase_char;
2330 vc->vc_video_erase_char =
2331 ((c & 0xfe00) >> 1) | (c & 0xff);
2334 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2335 vc->vc_hi_font_mask = 0x100;
2336 if (vc->vc_can_do_color) {
2337 vc->vc_complement_mask <<= 1;
2338 vc->vc_s_complement_mask <<= 1;
2341 /* ++Edmund: reorder the attribute bits */
2343 unsigned short *cp =
2344 (unsigned short *) vc->vc_origin;
2345 int count = vc->vc_screenbuf_size / 2;
2347 for (; count > 0; count--, cp++) {
2348 unsigned short newc;
2350 if (vc->vc_can_do_color)
2352 ((c & 0xff00) << 1) | (c &
2356 scr_writew(newc, cp);
2358 c = vc->vc_video_erase_char;
2359 if (vc->vc_can_do_color) {
2360 vc->vc_video_erase_char =
2361 ((c & 0xff00) << 1) | (c & 0xff);
2364 vc->vc_video_erase_char = c & ~0x100;
2372 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2373 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2376 vc_resize(vc, cols, rows);
2377 if (CON_IS_VISIBLE(vc) && softback_buf)
2378 fbcon_update_softback(vc);
2379 } else if (CON_IS_VISIBLE(vc)
2380 && vc->vc_mode == KD_TEXT) {
2381 fbcon_clear_margins(vc, 0);
2385 if (old_data && (--REFCOUNT(old_data) == 0))
2386 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2390 static int fbcon_copy_font(struct vc_data *vc, int con)
2392 struct display *od = &fb_display[con];
2393 struct console_font *f = &vc->vc_font;
2395 if (od->fontdata == f->data)
2396 return 0; /* already the same font... */
2397 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2401 * User asked to set font; we are guaranteed that
2402 * a) width and height are in range 1..32
2403 * b) charcount does not exceed 512
2404 * but lets not assume that, since someone might someday want to use larger
2405 * fonts. And charcount of 512 is small for unicode support.
2407 * However, user space gives the font in 32 rows , regardless of
2408 * actual font height. So a new API is needed if support for larger fonts
2409 * is ever implemented.
2412 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2414 unsigned charcount = font->charcount;
2415 int w = font->width;
2416 int h = font->height;
2419 u8 *new_data, *data = font->data;
2420 int pitch = (font->width+7) >> 3;
2422 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2423 * If not this check should be changed to charcount < 256 */
2424 if (charcount != 256 && charcount != 512)
2427 size = h * pitch * charcount;
2429 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2434 new_data += FONT_EXTRA_WORDS * sizeof(int);
2435 FNTSIZE(new_data) = size;
2436 FNTCHARCNT(new_data) = charcount;
2437 REFCOUNT(new_data) = 0; /* usage counter */
2438 for (i=0; i< charcount; i++) {
2439 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2442 /* Since linux has a nice crc32 function use it for counting font
2444 csum = crc32(0, new_data, size);
2446 FNTSUM(new_data) = csum;
2447 /* Check if the same font is on some other console already */
2448 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2449 struct vc_data *tmp = vc_cons[i].d;
2451 if (fb_display[i].userfont &&
2452 fb_display[i].fontdata &&
2453 FNTSUM(fb_display[i].fontdata) == csum &&
2454 FNTSIZE(fb_display[i].fontdata) == size &&
2455 tmp->vc_font.width == w &&
2456 !memcmp(fb_display[i].fontdata, new_data, size)) {
2457 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2458 new_data = (u8 *)fb_display[i].fontdata;
2462 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2465 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2467 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2468 const struct font_desc *f;
2471 f = get_default_font(info->var.xres, info->var.yres);
2472 else if (!(f = find_font(name)))
2475 font->width = f->width;
2476 font->height = f->height;
2477 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2480 static u16 palette_red[16];
2481 static u16 palette_green[16];
2482 static u16 palette_blue[16];
2484 static struct fb_cmap palette_cmap = {
2485 0, 16, palette_red, palette_green, palette_blue, NULL
2488 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2490 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2494 if (fbcon_is_inactive(vc, info))
2497 if (!CON_IS_VISIBLE(vc))
2500 depth = fb_get_color_depth(&info->var, &info->fix);
2502 for (i = j = 0; i < 16; i++) {
2504 val = vc->vc_palette[j++];
2505 palette_red[k] = (val << 8) | val;
2506 val = vc->vc_palette[j++];
2507 palette_green[k] = (val << 8) | val;
2508 val = vc->vc_palette[j++];
2509 palette_blue[k] = (val << 8) | val;
2511 palette_cmap.len = 16;
2512 palette_cmap.start = 0;
2514 * If framebuffer is capable of less than 16 colors,
2515 * use default palette of fbcon.
2518 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2520 return fb_set_cmap(&palette_cmap, info);
2523 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2528 if (vc->vc_num != fg_console || !softback_lines)
2529 return (u16 *) (vc->vc_origin + offset);
2530 line = offset / vc->vc_size_row;
2531 if (line >= softback_lines)
2532 return (u16 *) (vc->vc_origin + offset -
2533 softback_lines * vc->vc_size_row);
2534 p = softback_curr + offset;
2535 if (p >= softback_end)
2536 p += softback_buf - softback_end;
2540 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2546 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2547 unsigned long offset = (pos - vc->vc_origin) / 2;
2549 x = offset % vc->vc_cols;
2550 y = offset / vc->vc_cols;
2551 if (vc->vc_num == fg_console)
2552 y += softback_lines;
2553 ret = pos + (vc->vc_cols - x) * 2;
2554 } else if (vc->vc_num == fg_console && softback_lines) {
2555 unsigned long offset = pos - softback_curr;
2557 if (pos < softback_curr)
2558 offset += softback_end - softback_buf;
2560 x = offset % vc->vc_cols;
2561 y = offset / vc->vc_cols;
2562 ret = pos + (vc->vc_cols - x) * 2;
2563 if (ret == softback_end)
2565 if (ret == softback_in)
2566 ret = vc->vc_origin;
2568 /* Should not happen */
2570 ret = vc->vc_origin;
2579 /* As we might be inside of softback, we may work with non-contiguous buffer,
2580 that's why we have to use a separate routine. */
2581 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2584 u16 a = scr_readw(p);
2585 if (!vc->vc_can_do_color)
2587 else if (vc->vc_hi_font_mask == 0x100)
2588 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2589 (((a) & 0x0e00) << 4);
2591 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2592 (((a) & 0x0700) << 4);
2594 if (p == (u16 *) softback_end)
2595 p = (u16 *) softback_buf;
2596 if (p == (u16 *) softback_in)
2597 p = (u16 *) vc->vc_origin;
2601 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2603 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2604 struct fbcon_ops *ops = info->fbcon_par;
2605 struct display *p = &fb_display[fg_console];
2606 int offset, limit, scrollback_old;
2609 if (vc->vc_num != fg_console)
2611 if (vc->vc_mode != KD_TEXT || !lines)
2613 if (logo_shown >= 0) {
2614 struct vc_data *conp2 = vc_cons[logo_shown].d;
2616 if (conp2->vc_top == logo_lines
2617 && conp2->vc_bottom == conp2->vc_rows)
2619 if (logo_shown == vc->vc_num) {
2625 logo_lines * vc->vc_size_row;
2626 for (i = 0; i < logo_lines; i++) {
2627 if (p == softback_top)
2629 if (p == softback_buf)
2631 p -= vc->vc_size_row;
2632 q -= vc->vc_size_row;
2633 scr_memcpyw((u16 *) q, (u16 *) p,
2636 softback_in = softback_curr = p;
2637 update_region(vc, vc->vc_origin,
2638 logo_lines * vc->vc_cols);
2640 logo_shown = FBCON_LOGO_CANSHOW;
2642 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2643 fbcon_redraw_softback(vc, p, lines);
2644 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2648 if (!scrollback_phys_max)
2651 scrollback_old = scrollback_current;
2652 scrollback_current -= lines;
2653 if (scrollback_current < 0)
2654 scrollback_current = 0;
2655 else if (scrollback_current > scrollback_max)
2656 scrollback_current = scrollback_max;
2657 if (scrollback_current == scrollback_old)
2660 if (fbcon_is_inactive(vc, info))
2663 fbcon_cursor(vc, CM_ERASE);
2665 offset = p->yscroll - scrollback_current;
2667 switch (p->scrollmode) {
2668 case SCROLL_WRAP_MOVE:
2669 info->var.vmode |= FB_VMODE_YWRAP;
2671 case SCROLL_PAN_MOVE:
2672 case SCROLL_PAN_REDRAW:
2673 limit -= vc->vc_rows;
2674 info->var.vmode &= ~FB_VMODE_YWRAP;
2679 else if (offset >= limit)
2682 ops->var.xoffset = 0;
2683 ops->var.yoffset = offset * vc->vc_font.height;
2684 ops->update_start(info);
2686 if (!scrollback_current)
2687 fbcon_cursor(vc, CM_DRAW);
2691 static int fbcon_set_origin(struct vc_data *vc)
2694 fbcon_scrolldelta(vc, softback_lines);
2698 static void fbcon_suspended(struct fb_info *info)
2700 struct vc_data *vc = NULL;
2701 struct fbcon_ops *ops = info->fbcon_par;
2703 if (!ops || ops->currcon < 0)
2705 vc = vc_cons[ops->currcon].d;
2707 /* Clear cursor, restore saved data */
2708 fbcon_cursor(vc, CM_ERASE);
2711 static void fbcon_resumed(struct fb_info *info)
2714 struct fbcon_ops *ops = info->fbcon_par;
2716 if (!ops || ops->currcon < 0)
2718 vc = vc_cons[ops->currcon].d;
2723 static void fbcon_modechanged(struct fb_info *info)
2725 struct fbcon_ops *ops = info->fbcon_par;
2730 if (!ops || ops->currcon < 0)
2732 vc = vc_cons[ops->currcon].d;
2733 if (vc->vc_mode != KD_TEXT ||
2734 registered_fb[con2fb_map[ops->currcon]] != info)
2737 p = &fb_display[vc->vc_num];
2738 set_blitting_type(vc, info);
2740 if (CON_IS_VISIBLE(vc)) {
2741 var_to_display(p, &info->var, info);
2742 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2743 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2744 cols /= vc->vc_font.width;
2745 rows /= vc->vc_font.height;
2746 vc_resize(vc, cols, rows);
2747 updatescrollmode(p, info, vc);
2749 scrollback_current = 0;
2751 if (!fbcon_is_inactive(vc, info)) {
2752 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2753 ops->update_start(info);
2756 fbcon_set_palette(vc, color_table);
2759 fbcon_update_softback(vc);
2763 static void fbcon_set_all_vcs(struct fb_info *info)
2765 struct fbcon_ops *ops = info->fbcon_par;
2770 if (!ops || ops->currcon < 0)
2773 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2775 if (!vc || vc->vc_mode != KD_TEXT ||
2776 registered_fb[con2fb_map[i]] != info)
2779 p = &fb_display[vc->vc_num];
2780 set_blitting_type(vc, info);
2781 var_to_display(p, &info->var, info);
2782 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2783 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2784 cols /= vc->vc_font.width;
2785 rows /= vc->vc_font.height;
2786 vc_resize(vc, cols, rows);
2788 if (CON_IS_VISIBLE(vc)) {
2789 updatescrollmode(p, info, vc);
2791 scrollback_current = 0;
2793 if (!fbcon_is_inactive(vc, info)) {
2794 ops->var.xoffset = ops->var.yoffset =
2796 ops->update_start(info);
2799 fbcon_set_palette(vc, color_table);
2802 fbcon_update_softback(vc);
2806 ops->p = &fb_display[ops->currcon];
2809 static int fbcon_mode_deleted(struct fb_info *info,
2810 struct fb_videomode *mode)
2812 struct fb_info *fb_info;
2814 int i, j, found = 0;
2816 /* before deletion, ensure that mode is not in use */
2817 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2821 fb_info = registered_fb[j];
2822 if (fb_info != info)
2827 if (fb_mode_is_equal(p->mode, mode)) {
2835 static int fbcon_fb_registered(int idx)
2839 if (info_idx == -1) {
2840 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2841 if (con2fb_map_boot[i] == idx) {
2847 ret = fbcon_takeover(1);
2849 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2850 if (con2fb_map_boot[i] == idx)
2851 set_con2fb_map(i, idx, 0);
2858 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2860 struct fbcon_ops *ops = info->fbcon_par;
2863 if (!ops || ops->currcon < 0)
2866 vc = vc_cons[ops->currcon].d;
2867 if (vc->vc_mode != KD_TEXT ||
2868 registered_fb[con2fb_map[ops->currcon]] != info)
2871 if (CON_IS_VISIBLE(vc)) {
2875 do_unblank_screen(0);
2877 ops->blank_state = blank;
2880 static void fbcon_new_modelist(struct fb_info *info)
2884 struct fb_var_screeninfo var;
2885 struct fb_videomode *mode;
2887 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2888 if (registered_fb[con2fb_map[i]] != info)
2890 if (!fb_display[i].mode)
2893 display_to_var(&var, &fb_display[i]);
2894 mode = fb_find_nearest_mode(fb_display[i].mode,
2896 fb_videomode_to_var(&var, mode);
2899 fbcon_set_disp(info, &var, vc);
2901 fbcon_preset_disp(info, &var, i);
2906 static int fbcon_event_notify(struct notifier_block *self,
2907 unsigned long action, void *data)
2909 struct fb_event *event = data;
2910 struct fb_info *info = event->info;
2911 struct fb_videomode *mode;
2912 struct fb_con2fbmap *con2fb;
2916 case FB_EVENT_SUSPEND:
2917 fbcon_suspended(info);
2919 case FB_EVENT_RESUME:
2920 fbcon_resumed(info);
2922 case FB_EVENT_MODE_CHANGE:
2923 fbcon_modechanged(info);
2925 case FB_EVENT_MODE_CHANGE_ALL:
2926 fbcon_set_all_vcs(info);
2928 case FB_EVENT_MODE_DELETE:
2930 ret = fbcon_mode_deleted(info, mode);
2932 case FB_EVENT_FB_REGISTERED:
2933 ret = fbcon_fb_registered(info->node);
2935 case FB_EVENT_SET_CONSOLE_MAP:
2936 con2fb = event->data;
2937 ret = set_con2fb_map(con2fb->console - 1,
2938 con2fb->framebuffer, 1);
2940 case FB_EVENT_GET_CONSOLE_MAP:
2941 con2fb = event->data;
2942 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2944 case FB_EVENT_BLANK:
2945 fbcon_fb_blanked(info, *(int *)event->data);
2947 case FB_EVENT_NEW_MODELIST:
2948 fbcon_new_modelist(info);
2956 * The console `switch' structure for the frame buffer based console
2959 static const struct consw fb_con = {
2960 .owner = THIS_MODULE,
2961 .con_startup = fbcon_startup,
2962 .con_init = fbcon_init,
2963 .con_deinit = fbcon_deinit,
2964 .con_clear = fbcon_clear,
2965 .con_putc = fbcon_putc,
2966 .con_putcs = fbcon_putcs,
2967 .con_cursor = fbcon_cursor,
2968 .con_scroll = fbcon_scroll,
2969 .con_bmove = fbcon_bmove,
2970 .con_switch = fbcon_switch,
2971 .con_blank = fbcon_blank,
2972 .con_font_set = fbcon_set_font,
2973 .con_font_get = fbcon_get_font,
2974 .con_font_default = fbcon_set_def_font,
2975 .con_font_copy = fbcon_copy_font,
2976 .con_set_palette = fbcon_set_palette,
2977 .con_scrolldelta = fbcon_scrolldelta,
2978 .con_set_origin = fbcon_set_origin,
2979 .con_invert_region = fbcon_invert_region,
2980 .con_screen_pos = fbcon_screen_pos,
2981 .con_getxy = fbcon_getxy,
2982 .con_resize = fbcon_resize,
2985 static struct notifier_block fbcon_event_notifier = {
2986 .notifier_call = fbcon_event_notify,
2989 static ssize_t store_rotate(struct class_device *class_device,
2990 const char *buf, size_t count)
2992 struct fb_info *info;
2996 acquire_console_sem();
2997 idx = con2fb_map[fg_console];
2999 if (idx == -1 || registered_fb[idx] == NULL)
3002 info = registered_fb[idx];
3003 rotate = simple_strtoul(buf, last, 0);
3004 fbcon_rotate(info, rotate);
3006 release_console_sem();
3010 static ssize_t store_rotate_all(struct class_device *class_device,
3011 const char *buf, size_t count)
3013 struct fb_info *info;
3017 acquire_console_sem();
3018 idx = con2fb_map[fg_console];
3020 if (idx == -1 || registered_fb[idx] == NULL)
3023 info = registered_fb[idx];
3024 rotate = simple_strtoul(buf, last, 0);
3025 fbcon_rotate_all(info, rotate);
3027 release_console_sem();
3031 static ssize_t show_rotate(struct class_device *class_device, char *buf)
3033 struct fb_info *info;
3034 int rotate = 0, idx;
3036 acquire_console_sem();
3037 idx = con2fb_map[fg_console];
3039 if (idx == -1 || registered_fb[idx] == NULL)
3042 info = registered_fb[idx];
3043 rotate = fbcon_get_rotate(info);
3045 release_console_sem();
3046 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3049 static struct class_device_attribute class_device_attrs[] = {
3050 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3051 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3054 static int fbcon_init_class_device(void)
3058 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3059 class_device_create_file(fbcon_class_device,
3060 &class_device_attrs[i]);
3064 static int __init fb_console_init(void)
3068 acquire_console_sem();
3069 fb_register_client(&fbcon_event_notifier);
3070 release_console_sem();
3072 fbcon_class_device =
3073 class_device_create(fb_class, NULL,
3074 MKDEV(FB_MAJOR, FB_MAX), NULL,
3076 if (IS_ERR(fbcon_class_device)) {
3077 printk(KERN_WARNING "Unable to create class_device "
3078 "for fbcon; errno = %ld\n",
3079 PTR_ERR(fbcon_class_device));
3080 fbcon_class_device = NULL;
3082 fbcon_init_class_device();
3084 for (i = 0; i < MAX_NR_CONSOLES; i++)
3087 if (num_registered_fb) {
3088 for (i = 0; i < FB_MAX; i++) {
3089 if (registered_fb[i] != NULL) {
3100 module_init(fb_console_init);
3104 static void __exit fbcon_deinit_class_device(void)
3108 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3109 class_device_remove_file(fbcon_class_device,
3110 &class_device_attrs[i]);
3113 static void __exit fbcon_exit(void)
3115 struct fb_info *info;
3118 for (i = 0; i < FB_MAX; i++) {
3119 info = registered_fb[i];
3121 if (info && info->fbcon_par)
3122 fbcon_del_cursor_timer(info);
3126 free_irq(IRQ_AUTO_4, fbcon_vbl_handler);
3129 if (MACH_IS_MAC && vbl_detected)
3130 free_irq(IRQ_MAC_VBL, fbcon_vbl_handler);
3133 kfree((void *)softback_buf);
3135 for (i = 0; i < FB_MAX; i++) {
3137 info = registered_fb[i];
3142 for (j = 0; j < MAX_NR_CONSOLES; j++) {
3143 if (con2fb_map[j] == i) {
3150 if (info->fbops->fb_release)
3151 info->fbops->fb_release(info, 0);
3152 module_put(info->fbops->owner);
3153 kfree(info->fbcon_par);
3154 info->fbcon_par = NULL;
3158 fbcon_deinit_class_device();
3159 class_device_destroy(fb_class, MKDEV(FB_MAJOR, FB_MAX));
3162 static void __exit fb_console_exit(void)
3164 acquire_console_sem();
3165 fb_unregister_client(&fbcon_event_notifier);
3167 release_console_sem();
3168 give_up_console(&fb_con);
3171 module_exit(fb_console_exit);
3175 MODULE_LICENSE("GPL");