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];
111 static int logo_height;
113 static int logo_lines;
114 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
116 static int logo_shown = FBCON_LOGO_CANSHOW;
117 /* Software scrollback */
118 static int fbcon_softback_size = 32768;
119 static unsigned long softback_buf, softback_curr;
120 static unsigned long softback_in;
121 static unsigned long softback_top, softback_end;
122 static int softback_lines;
123 /* console mappings */
124 static int first_fb_vc;
125 static int last_fb_vc = MAX_NR_CONSOLES - 1;
126 static int fbcon_is_default = 1;
127 static int fbcon_has_exited;
130 static char fontname[40];
132 /* current fb_info */
133 static int info_idx = -1;
135 /* console rotation */
137 static int fbcon_has_sysfs;
139 static const struct consw fb_con;
141 #define CM_SOFTBACK (8)
143 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
145 static int fbcon_set_origin(struct vc_data *);
147 #define CURSOR_DRAW_DELAY (1)
149 /* # VBL ints between cursor state changes */
150 #define ATARI_CURSOR_BLINK_RATE (42)
151 #define MAC_CURSOR_BLINK_RATE (32)
152 #define DEFAULT_CURSOR_BLINK_RATE (20)
154 static int vbl_cursor_cnt;
156 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
159 * Interface used by the world
162 static const char *fbcon_startup(void);
163 static void fbcon_init(struct vc_data *vc, int init);
164 static void fbcon_deinit(struct vc_data *vc);
165 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
167 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
168 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
169 int count, int ypos, int xpos);
170 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
171 static void fbcon_cursor(struct vc_data *vc, int mode);
172 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
174 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
175 int height, int width);
176 static int fbcon_switch(struct vc_data *vc);
177 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
178 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
179 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
184 static __inline__ void ywrap_up(struct vc_data *vc, int count);
185 static __inline__ void ywrap_down(struct vc_data *vc, int count);
186 static __inline__ void ypan_up(struct vc_data *vc, int count);
187 static __inline__ void ypan_down(struct vc_data *vc, int count);
188 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
192 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
194 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
195 int line, int count, int dy);
196 static void fbcon_modechanged(struct fb_info *info);
197 static void fbcon_set_all_vcs(struct fb_info *info);
198 static void fbcon_start(void);
199 static void fbcon_exit(void);
200 static struct class_device *fbcon_class_device;
204 * On the Macintoy, there may or may not be a working VBL int. We need to probe
206 static int vbl_detected;
208 static irqreturn_t fb_vbl_detect(int irq, void *dummy)
215 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
216 static inline void fbcon_set_rotation(struct fb_info *info)
218 struct fbcon_ops *ops = info->fbcon_par;
220 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
221 ops->p->con_rotate < 4)
222 ops->rotate = ops->p->con_rotate;
227 static void fbcon_rotate(struct fb_info *info, u32 rotate)
229 struct fbcon_ops *ops= info->fbcon_par;
230 struct fb_info *fb_info;
232 if (!ops || ops->currcon == -1)
235 fb_info = registered_fb[con2fb_map[ops->currcon]];
237 if (info == fb_info) {
238 struct display *p = &fb_display[ops->currcon];
241 p->con_rotate = rotate;
245 fbcon_modechanged(info);
249 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
251 struct fbcon_ops *ops = info->fbcon_par;
256 if (!ops || ops->currcon < 0 || rotate > 3)
259 for (i = first_fb_vc; i <= last_fb_vc; i++) {
261 if (!vc || vc->vc_mode != KD_TEXT ||
262 registered_fb[con2fb_map[i]] != info)
265 p = &fb_display[vc->vc_num];
266 p->con_rotate = rotate;
269 fbcon_set_all_vcs(info);
272 static inline void fbcon_set_rotation(struct fb_info *info)
274 struct fbcon_ops *ops = info->fbcon_par;
276 ops->rotate = FB_ROTATE_UR;
279 static void fbcon_rotate(struct fb_info *info, u32 rotate)
284 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
288 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
290 static int fbcon_get_rotate(struct fb_info *info)
292 struct fbcon_ops *ops = info->fbcon_par;
294 return (ops) ? ops->rotate : 0;
297 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
299 struct fbcon_ops *ops = info->fbcon_par;
301 return (info->state != FBINFO_STATE_RUNNING ||
302 vc->vc_mode != KD_TEXT || ops->graphics);
305 static inline int get_color(struct vc_data *vc, struct fb_info *info,
308 int depth = fb_get_color_depth(&info->var, &info->fix);
311 if (console_blanked) {
312 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
314 c = vc->vc_video_erase_char & charmask;
318 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
319 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
324 int col = ~(0xfff << (max(info->var.green.length,
325 max(info->var.red.length,
326 info->var.blue.length)))) & 0xff;
329 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
330 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
335 color = (is_fg) ? fg : bg;
340 * Scale down 16-colors to 4 colors. Default 4-color palette
341 * is grayscale. However, simply dividing the values by 4
342 * will not work, as colors 1, 2 and 3 will be scaled-down
343 * to zero rendering them invisible. So empirically convert
344 * colors to a sane 4-level grayscale.
348 color = 0; /* black */
351 color = 2; /* white */
354 color = 1; /* gray */
357 color = 3; /* intense white */
363 * Last 8 entries of default 16-color palette is a more intense
364 * version of the first 8 (i.e., same chrominance, different
375 static void fbcon_update_softback(struct vc_data *vc)
377 int l = fbcon_softback_size / vc->vc_size_row;
380 softback_end = softback_buf + l * vc->vc_size_row;
382 /* Smaller scrollback makes no sense, and 0 would screw
383 the operation totally */
387 static void fb_flashcursor(struct work_struct *work)
389 struct fb_info *info = container_of(work, struct fb_info, queue);
390 struct fbcon_ops *ops = info->fbcon_par;
392 struct vc_data *vc = NULL;
396 acquire_console_sem();
397 if (ops && ops->currcon != -1)
398 vc = vc_cons[ops->currcon].d;
400 if (!vc || !CON_IS_VISIBLE(vc) ||
401 registered_fb[con2fb_map[vc->vc_num]] != info ||
403 release_console_sem();
407 p = &fb_display[vc->vc_num];
408 c = scr_readw((u16 *) vc->vc_pos);
409 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
411 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
412 get_color(vc, info, c, 0));
413 release_console_sem();
416 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
417 static int cursor_blink_rate;
418 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
420 struct fb_info *info = dev_id;
422 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
423 schedule_work(&info->queue);
424 vbl_cursor_cnt = cursor_blink_rate;
430 static void cursor_timer_handler(unsigned long dev_addr)
432 struct fb_info *info = (struct fb_info *) dev_addr;
433 struct fbcon_ops *ops = info->fbcon_par;
435 schedule_work(&info->queue);
436 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
439 static void fbcon_add_cursor_timer(struct fb_info *info)
441 struct fbcon_ops *ops = info->fbcon_par;
443 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
444 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
445 if (!info->queue.func)
446 INIT_WORK(&info->queue, fb_flashcursor);
448 init_timer(&ops->cursor_timer);
449 ops->cursor_timer.function = cursor_timer_handler;
450 ops->cursor_timer.expires = jiffies + HZ / 5;
451 ops->cursor_timer.data = (unsigned long ) info;
452 add_timer(&ops->cursor_timer);
453 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
457 static void fbcon_del_cursor_timer(struct fb_info *info)
459 struct fbcon_ops *ops = info->fbcon_par;
461 if (info->queue.func == fb_flashcursor &&
462 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
463 del_timer_sync(&ops->cursor_timer);
464 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
469 static int __init fb_console_setup(char *this_opt)
474 if (!this_opt || !*this_opt)
477 while ((options = strsep(&this_opt, ",")) != NULL) {
478 if (!strncmp(options, "font:", 5))
479 strcpy(fontname, options + 5);
481 if (!strncmp(options, "scrollback:", 11)) {
484 fbcon_softback_size = simple_strtoul(options, &options, 0);
485 if (*options == 'k' || *options == 'K') {
486 fbcon_softback_size *= 1024;
496 if (!strncmp(options, "map:", 4)) {
499 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
503 (options[j++]-'0') % FB_MAX;
508 if (!strncmp(options, "vc:", 3)) {
511 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
514 if (*options++ == '-')
515 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
516 fbcon_is_default = 0;
519 if (!strncmp(options, "rotate:", 7)) {
522 rotate = simple_strtoul(options, &options, 0);
530 __setup("fbcon=", fb_console_setup);
533 static int search_fb_in_map(int idx)
537 for (i = first_fb_vc; i <= last_fb_vc; i++) {
538 if (con2fb_map[i] == idx)
544 static int search_for_mapped_con(void)
548 for (i = first_fb_vc; i <= last_fb_vc; i++) {
549 if (con2fb_map[i] != -1)
555 static int fbcon_takeover(int show_logo)
559 if (!num_registered_fb)
563 logo_shown = FBCON_LOGO_DONTSHOW;
565 for (i = first_fb_vc; i <= last_fb_vc; i++)
566 con2fb_map[i] = info_idx;
568 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
572 for (i = first_fb_vc; i <= last_fb_vc; i++) {
582 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
583 int cols, int rows, int new_cols, int new_rows)
585 logo_shown = FBCON_LOGO_DONTSHOW;
588 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
589 int cols, int rows, int new_cols, int new_rows)
591 /* Need to make room for the logo */
592 struct fbcon_ops *ops = info->fbcon_par;
593 int cnt, erase = vc->vc_video_erase_char, step;
594 unsigned short *save = NULL, *r, *q;
596 if (info->flags & FBINFO_MODULE) {
597 logo_shown = FBCON_LOGO_DONTSHOW;
602 * remove underline attribute from erase character
603 * if black and white framebuffer.
605 if (fb_get_color_depth(&info->var, &info->fix) == 1)
607 logo_height = fb_prepare_logo(info, ops->rotate);
608 logo_lines = (logo_height + vc->vc_font.height - 1) /
610 q = (unsigned short *) (vc->vc_origin +
611 vc->vc_size_row * rows);
612 step = logo_lines * cols;
613 for (r = q - logo_lines * cols; r < q; r++)
614 if (scr_readw(r) != vc->vc_video_erase_char)
616 if (r != q && new_rows >= rows + logo_lines) {
617 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
619 int i = cols < new_cols ? cols : new_cols;
620 scr_memsetw(save, erase, logo_lines * new_cols * 2);
622 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
623 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
628 /* We can scroll screen down */
630 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
631 scr_memcpyw(r + step, r, vc->vc_size_row);
636 if (vc->vc_y + logo_lines >= rows)
637 lines = rows - vc->vc_y - 1;
641 vc->vc_pos += lines * vc->vc_size_row;
644 scr_memsetw((unsigned short *) vc->vc_origin,
646 vc->vc_size_row * logo_lines);
648 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
649 fbcon_clear_margins(vc, 0);
654 q = (unsigned short *) (vc->vc_origin +
657 scr_memcpyw(q, save, logo_lines * new_cols * 2);
658 vc->vc_y += logo_lines;
659 vc->vc_pos += logo_lines * vc->vc_size_row;
663 if (logo_lines > vc->vc_bottom) {
664 logo_shown = FBCON_LOGO_CANSHOW;
666 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
667 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
668 logo_shown = FBCON_LOGO_DRAW;
669 vc->vc_top = logo_lines;
674 #ifdef CONFIG_FB_TILEBLITTING
675 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
677 struct fbcon_ops *ops = info->fbcon_par;
679 ops->p = &fb_display[vc->vc_num];
681 if ((info->flags & FBINFO_MISC_TILEBLITTING))
682 fbcon_set_tileops(vc, info);
684 fbcon_set_rotation(info);
685 fbcon_set_bitops(ops);
689 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
691 struct fbcon_ops *ops = info->fbcon_par;
693 info->flags &= ~FBINFO_MISC_TILEBLITTING;
694 ops->p = &fb_display[vc->vc_num];
695 fbcon_set_rotation(info);
696 fbcon_set_bitops(ops);
698 #endif /* CONFIG_MISC_TILEBLITTING */
701 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
702 int unit, int oldidx)
704 struct fbcon_ops *ops = NULL;
707 if (!try_module_get(info->fbops->owner))
710 if (!err && info->fbops->fb_open &&
711 info->fbops->fb_open(info, 0))
715 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
721 info->fbcon_par = ops;
722 set_blitting_type(vc, info);
726 con2fb_map[unit] = oldidx;
727 module_put(info->fbops->owner);
733 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
734 struct fb_info *newinfo, int unit,
735 int oldidx, int found)
737 struct fbcon_ops *ops = oldinfo->fbcon_par;
740 if (oldinfo->fbops->fb_release &&
741 oldinfo->fbops->fb_release(oldinfo, 0)) {
742 con2fb_map[unit] = oldidx;
743 if (!found && newinfo->fbops->fb_release)
744 newinfo->fbops->fb_release(newinfo, 0);
746 module_put(newinfo->fbops->owner);
751 fbcon_del_cursor_timer(oldinfo);
752 kfree(ops->cursor_state.mask);
753 kfree(ops->cursor_data);
754 kfree(ops->fontbuffer);
755 kfree(oldinfo->fbcon_par);
756 oldinfo->fbcon_par = NULL;
757 module_put(oldinfo->fbops->owner);
759 If oldinfo and newinfo are driving the same hardware,
760 the fb_release() method of oldinfo may attempt to
761 restore the hardware state. This will leave the
762 newinfo in an undefined state. Thus, a call to
763 fb_set_par() may be needed for the newinfo.
765 if (newinfo->fbops->fb_set_par)
766 newinfo->fbops->fb_set_par(newinfo);
772 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
773 int unit, int show_logo)
775 struct fbcon_ops *ops = info->fbcon_par;
777 ops->currcon = fg_console;
779 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
780 info->fbops->fb_set_par(info);
782 ops->flags |= FBCON_FLAGS_INIT;
786 fbcon_set_disp(info, &info->var, vc);
788 fbcon_preset_disp(info, &info->var, unit);
791 struct vc_data *fg_vc = vc_cons[fg_console].d;
792 struct fb_info *fg_info =
793 registered_fb[con2fb_map[fg_console]];
795 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
796 fg_vc->vc_rows, fg_vc->vc_cols,
800 update_screen(vc_cons[fg_console].d);
804 * set_con2fb_map - map console to frame buffer device
805 * @unit: virtual console number to map
806 * @newidx: frame buffer index to map virtual console to
807 * @user: user request
809 * Maps a virtual console @unit to a frame buffer device
812 static int set_con2fb_map(int unit, int newidx, int user)
814 struct vc_data *vc = vc_cons[unit].d;
815 int oldidx = con2fb_map[unit];
816 struct fb_info *info = registered_fb[newidx];
817 struct fb_info *oldinfo = NULL;
820 if (oldidx == newidx)
823 if (!info || fbcon_has_exited)
826 if (!err && !search_for_mapped_con()) {
828 return fbcon_takeover(0);
832 oldinfo = registered_fb[oldidx];
834 found = search_fb_in_map(newidx);
836 acquire_console_sem();
837 con2fb_map[unit] = newidx;
839 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
843 * If old fb is not mapped to any of the consoles,
844 * fbcon should release it.
846 if (!err && oldinfo && !search_fb_in_map(oldidx))
847 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
851 int show_logo = (fg_console == 0 && !user &&
852 logo_shown != FBCON_LOGO_DONTSHOW);
855 fbcon_add_cursor_timer(info);
856 con2fb_map_boot[unit] = newidx;
857 con2fb_init_display(vc, info, unit, show_logo);
860 if (!search_fb_in_map(info_idx))
863 release_console_sem();
868 * Low Level Operations
870 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
871 static int var_to_display(struct display *disp,
872 struct fb_var_screeninfo *var,
873 struct fb_info *info)
875 disp->xres_virtual = var->xres_virtual;
876 disp->yres_virtual = var->yres_virtual;
877 disp->bits_per_pixel = var->bits_per_pixel;
878 disp->grayscale = var->grayscale;
879 disp->nonstd = var->nonstd;
880 disp->accel_flags = var->accel_flags;
881 disp->height = var->height;
882 disp->width = var->width;
883 disp->red = var->red;
884 disp->green = var->green;
885 disp->blue = var->blue;
886 disp->transp = var->transp;
887 disp->rotate = var->rotate;
888 disp->mode = fb_match_mode(var, &info->modelist);
889 if (disp->mode == NULL)
890 /* This should not happen */
895 static void display_to_var(struct fb_var_screeninfo *var,
896 struct display *disp)
898 fb_videomode_to_var(var, disp->mode);
899 var->xres_virtual = disp->xres_virtual;
900 var->yres_virtual = disp->yres_virtual;
901 var->bits_per_pixel = disp->bits_per_pixel;
902 var->grayscale = disp->grayscale;
903 var->nonstd = disp->nonstd;
904 var->accel_flags = disp->accel_flags;
905 var->height = disp->height;
906 var->width = disp->width;
907 var->red = disp->red;
908 var->green = disp->green;
909 var->blue = disp->blue;
910 var->transp = disp->transp;
911 var->rotate = disp->rotate;
914 static const char *fbcon_startup(void)
916 const char *display_desc = "frame buffer device";
917 struct display *p = &fb_display[fg_console];
918 struct vc_data *vc = vc_cons[fg_console].d;
919 const struct font_desc *font = NULL;
920 struct module *owner;
921 struct fb_info *info = NULL;
922 struct fbcon_ops *ops;
928 * If num_registered_fb is zero, this is a call for the dummy part.
929 * The frame buffer devices weren't initialized yet.
931 if (!num_registered_fb || info_idx == -1)
934 * Instead of blindly using registered_fb[0], we use info_idx, set by
937 info = registered_fb[info_idx];
941 owner = info->fbops->owner;
942 if (!try_module_get(owner))
944 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
949 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
957 ops->cur_rotate = -1;
958 info->fbcon_par = ops;
959 p->con_rotate = rotate;
960 set_blitting_type(vc, info);
962 if (info->fix.type != FB_TYPE_TEXT) {
963 if (fbcon_softback_size) {
967 kmalloc(fbcon_softback_size,
970 fbcon_softback_size = 0;
976 kfree((void *) softback_buf);
982 softback_in = softback_top = softback_curr =
987 /* Setup default font */
989 if (!fontname[0] || !(font = find_font(fontname)))
990 font = get_default_font(info->var.xres,
993 info->pixmap.blit_y);
994 vc->vc_font.width = font->width;
995 vc->vc_font.height = font->height;
996 vc->vc_font.data = (void *)(p->fontdata = font->data);
997 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1000 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1001 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1002 cols /= vc->vc_font.width;
1003 rows /= vc->vc_font.height;
1004 vc_resize(vc, cols, rows);
1006 DPRINTK("mode: %s\n", info->fix.id);
1007 DPRINTK("visual: %d\n", info->fix.visual);
1008 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1010 info->var.bits_per_pixel);
1013 if (MACH_IS_ATARI) {
1014 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1016 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1017 IRQ_TYPE_PRIO, "framebuffer vbl",
1020 #endif /* CONFIG_ATARI */
1024 * On a Macintoy, the VBL interrupt may or may not be active.
1025 * As interrupt based cursor is more reliable and race free, we
1026 * probe for VBL interrupts.
1031 * Probe for VBL: set temp. handler ...
1033 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1034 "framebuffer vbl", info);
1038 * ... and spin for 20 ms ...
1040 while (!vbl_detected && ++ct < 1000)
1045 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1047 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1051 * interrupt based cursor ok
1053 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1055 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1056 "framebuffer vbl", info);
1059 * VBL not detected: fall through, use timer based cursor
1064 #endif /* CONFIG_MAC */
1066 fbcon_add_cursor_timer(info);
1067 fbcon_has_exited = 0;
1068 return display_desc;
1071 static void fbcon_init(struct vc_data *vc, int init)
1073 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1074 struct fbcon_ops *ops;
1075 struct vc_data **default_mode = vc->vc_display_fg;
1076 struct vc_data *svc = *default_mode;
1077 struct display *t, *p = &fb_display[vc->vc_num];
1078 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1081 if (info_idx == -1 || info == NULL)
1086 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1087 (info->fix.type == FB_TYPE_TEXT))
1090 if (var_to_display(p, &info->var, info))
1093 /* If we are not the first console on this
1094 fb, copy the font from that console */
1095 t = &fb_display[fg_console];
1098 struct vc_data *fvc = vc_cons[fg_console].d;
1100 vc->vc_font.data = (void *)(p->fontdata =
1102 vc->vc_font.width = fvc->vc_font.width;
1103 vc->vc_font.height = fvc->vc_font.height;
1104 p->userfont = t->userfont;
1107 REFCOUNT(p->fontdata)++;
1109 const struct font_desc *font = NULL;
1111 if (!fontname[0] || !(font = find_font(fontname)))
1112 font = get_default_font(info->var.xres,
1114 info->pixmap.blit_x,
1115 info->pixmap.blit_y);
1116 vc->vc_font.width = font->width;
1117 vc->vc_font.height = font->height;
1118 vc->vc_font.data = (void *)(p->fontdata = font->data);
1119 vc->vc_font.charcount = 256; /* FIXME Need to
1120 support more fonts */
1125 charcnt = FNTCHARCNT(p->fontdata);
1127 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1128 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1129 if (charcnt == 256) {
1130 vc->vc_hi_font_mask = 0;
1132 vc->vc_hi_font_mask = 0x100;
1133 if (vc->vc_can_do_color)
1134 vc->vc_complement_mask <<= 1;
1137 if (!*svc->vc_uni_pagedir_loc)
1138 con_set_default_unimap(svc);
1139 if (!*vc->vc_uni_pagedir_loc)
1140 con_copy_unimap(vc, svc);
1142 ops = info->fbcon_par;
1143 p->con_rotate = rotate;
1144 set_blitting_type(vc, info);
1148 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1149 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1150 new_cols /= vc->vc_font.width;
1151 new_rows /= vc->vc_font.height;
1152 vc_resize(vc, new_cols, new_rows);
1155 * We must always set the mode. The mode of the previous console
1156 * driver could be in the same resolution but we are using different
1157 * hardware so we have to initialize the hardware.
1159 * We need to do it in fbcon_init() to prevent screen corruption.
1161 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1162 if (info->fbops->fb_set_par &&
1163 !(ops->flags & FBCON_FLAGS_INIT))
1164 info->fbops->fb_set_par(info);
1165 ops->flags |= FBCON_FLAGS_INIT;
1170 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1171 !(cap & FBINFO_HWACCEL_DISABLED))
1172 p->scrollmode = SCROLL_MOVE;
1173 else /* default to something safe */
1174 p->scrollmode = SCROLL_REDRAW;
1177 * ++guenther: console.c:vc_allocate() relies on initializing
1178 * vc_{cols,rows}, but we must not set those if we are only
1179 * resizing the console.
1182 vc->vc_cols = new_cols;
1183 vc->vc_rows = new_rows;
1187 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1189 if (vc == svc && softback_buf)
1190 fbcon_update_softback(vc);
1192 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1193 ops->rotate = FB_ROTATE_UR;
1194 set_blitting_type(vc, info);
1197 ops->p = &fb_display[fg_console];
1200 static void fbcon_free_font(struct display *p)
1202 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1203 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1208 static void fbcon_deinit(struct vc_data *vc)
1210 struct display *p = &fb_display[vc->vc_num];
1211 struct fb_info *info;
1212 struct fbcon_ops *ops;
1216 idx = con2fb_map[vc->vc_num];
1221 info = registered_fb[idx];
1226 ops = info->fbcon_par;
1231 if (CON_IS_VISIBLE(vc))
1232 fbcon_del_cursor_timer(info);
1234 ops->flags &= ~FBCON_FLAGS_INIT;
1237 if (!con_is_bound(&fb_con))
1243 /* ====================================================================== */
1245 /* fbcon_XXX routines - interface used by the world
1247 * This system is now divided into two levels because of complications
1248 * caused by hardware scrolling. Top level functions:
1250 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1252 * handles y values in range [0, scr_height-1] that correspond to real
1253 * screen positions. y_wrap shift means that first line of bitmap may be
1254 * anywhere on this display. These functions convert lineoffsets to
1255 * bitmap offsets and deal with the wrap-around case by splitting blits.
1257 * fbcon_bmove_physical_8() -- These functions fast implementations
1258 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1259 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1263 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1264 * Implies should only really hardware scroll in rows. Only reason for
1265 * restriction is simplicity & efficiency at the moment.
1268 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1271 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1272 struct fbcon_ops *ops = info->fbcon_par;
1274 struct display *p = &fb_display[vc->vc_num];
1277 if (fbcon_is_inactive(vc, info))
1280 if (!height || !width)
1283 /* Split blits that cross physical y_wrap boundary */
1285 y_break = p->vrows - p->yscroll;
1286 if (sy < y_break && sy + height - 1 >= y_break) {
1287 u_int b = y_break - sy;
1288 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1289 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1292 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1295 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1296 int count, int ypos, int xpos)
1298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1299 struct display *p = &fb_display[vc->vc_num];
1300 struct fbcon_ops *ops = info->fbcon_par;
1302 if (!fbcon_is_inactive(vc, info))
1303 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1304 get_color(vc, info, scr_readw(s), 1),
1305 get_color(vc, info, scr_readw(s), 0));
1308 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1312 scr_writew(c, &chr);
1313 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1316 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1318 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1319 struct fbcon_ops *ops = info->fbcon_par;
1321 if (!fbcon_is_inactive(vc, info))
1322 ops->clear_margins(vc, info, bottom_only);
1325 static void fbcon_cursor(struct vc_data *vc, int mode)
1327 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1328 struct fbcon_ops *ops = info->fbcon_par;
1330 int c = scr_readw((u16 *) vc->vc_pos);
1332 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1335 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1336 if (mode & CM_SOFTBACK) {
1337 mode &= ~CM_SOFTBACK;
1341 fbcon_set_origin(vc);
1345 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1346 get_color(vc, info, c, 0));
1347 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1350 static int scrollback_phys_max = 0;
1351 static int scrollback_max = 0;
1352 static int scrollback_current = 0;
1355 * If no vc is existent yet, just set struct display
1357 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1360 struct display *p = &fb_display[unit];
1361 struct display *t = &fb_display[fg_console];
1363 if (var_to_display(p, var, info))
1366 p->fontdata = t->fontdata;
1367 p->userfont = t->userfont;
1369 REFCOUNT(p->fontdata)++;
1372 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1375 struct display *p = &fb_display[vc->vc_num], *t;
1376 struct vc_data **default_mode = vc->vc_display_fg;
1377 struct vc_data *svc = *default_mode;
1378 struct fbcon_ops *ops = info->fbcon_par;
1379 int rows, cols, charcnt = 256;
1381 if (var_to_display(p, var, info))
1383 t = &fb_display[svc->vc_num];
1384 if (!vc->vc_font.data) {
1385 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1386 vc->vc_font.width = (*default_mode)->vc_font.width;
1387 vc->vc_font.height = (*default_mode)->vc_font.height;
1388 p->userfont = t->userfont;
1390 REFCOUNT(p->fontdata)++;
1393 charcnt = FNTCHARCNT(p->fontdata);
1395 var->activate = FB_ACTIVATE_NOW;
1396 info->var.activate = var->activate;
1397 var->yoffset = info->var.yoffset;
1398 var->xoffset = info->var.xoffset;
1399 fb_set_var(info, var);
1400 ops->var = info->var;
1401 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1402 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1403 if (charcnt == 256) {
1404 vc->vc_hi_font_mask = 0;
1406 vc->vc_hi_font_mask = 0x100;
1407 if (vc->vc_can_do_color)
1408 vc->vc_complement_mask <<= 1;
1411 if (!*svc->vc_uni_pagedir_loc)
1412 con_set_default_unimap(svc);
1413 if (!*vc->vc_uni_pagedir_loc)
1414 con_copy_unimap(vc, svc);
1416 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1417 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1418 cols /= vc->vc_font.width;
1419 rows /= vc->vc_font.height;
1420 vc_resize(vc, cols, rows);
1422 if (CON_IS_VISIBLE(vc)) {
1425 fbcon_update_softback(vc);
1429 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1431 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1432 struct fbcon_ops *ops = info->fbcon_par;
1433 struct display *p = &fb_display[vc->vc_num];
1435 p->yscroll += count;
1436 if (p->yscroll >= p->vrows) /* Deal with wrap */
1437 p->yscroll -= p->vrows;
1438 ops->var.xoffset = 0;
1439 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1440 ops->var.vmode |= FB_VMODE_YWRAP;
1441 ops->update_start(info);
1442 scrollback_max += count;
1443 if (scrollback_max > scrollback_phys_max)
1444 scrollback_max = scrollback_phys_max;
1445 scrollback_current = 0;
1448 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1450 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1451 struct fbcon_ops *ops = info->fbcon_par;
1452 struct display *p = &fb_display[vc->vc_num];
1454 p->yscroll -= count;
1455 if (p->yscroll < 0) /* Deal with wrap */
1456 p->yscroll += p->vrows;
1457 ops->var.xoffset = 0;
1458 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1459 ops->var.vmode |= FB_VMODE_YWRAP;
1460 ops->update_start(info);
1461 scrollback_max -= count;
1462 if (scrollback_max < 0)
1464 scrollback_current = 0;
1467 static __inline__ void ypan_up(struct vc_data *vc, int count)
1469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1470 struct display *p = &fb_display[vc->vc_num];
1471 struct fbcon_ops *ops = info->fbcon_par;
1473 p->yscroll += count;
1474 if (p->yscroll > p->vrows - vc->vc_rows) {
1475 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1476 0, 0, 0, vc->vc_rows, vc->vc_cols);
1477 p->yscroll -= p->vrows - vc->vc_rows;
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_up_redraw(struct vc_data *vc, int t, int count)
1493 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1494 struct fbcon_ops *ops = info->fbcon_par;
1495 struct display *p = &fb_display[vc->vc_num];
1497 p->yscroll += count;
1499 if (p->yscroll > p->vrows - vc->vc_rows) {
1500 p->yscroll -= p->vrows - vc->vc_rows;
1501 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
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 > scrollback_phys_max)
1511 scrollback_max = scrollback_phys_max;
1512 scrollback_current = 0;
1515 static __inline__ void ypan_down(struct vc_data *vc, int count)
1517 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1518 struct display *p = &fb_display[vc->vc_num];
1519 struct fbcon_ops *ops = info->fbcon_par;
1521 p->yscroll -= count;
1522 if (p->yscroll < 0) {
1523 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1524 0, vc->vc_rows, vc->vc_cols);
1525 p->yscroll += p->vrows - vc->vc_rows;
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 __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1541 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1542 struct fbcon_ops *ops = info->fbcon_par;
1543 struct display *p = &fb_display[vc->vc_num];
1545 p->yscroll -= count;
1547 if (p->yscroll < 0) {
1548 p->yscroll += p->vrows - vc->vc_rows;
1549 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1552 ops->var.xoffset = 0;
1553 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1554 ops->var.vmode &= ~FB_VMODE_YWRAP;
1555 ops->update_start(info);
1556 fbcon_clear_margins(vc, 1);
1557 scrollback_max -= count;
1558 if (scrollback_max < 0)
1560 scrollback_current = 0;
1563 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1566 int count = vc->vc_rows;
1567 unsigned short *d, *s;
1571 d = (u16 *) softback_curr;
1572 if (d == (u16 *) softback_in)
1573 d = (u16 *) vc->vc_origin;
1574 n = softback_curr + delta * vc->vc_size_row;
1575 softback_lines -= delta;
1577 if (softback_curr < softback_top && n < softback_buf) {
1578 n += softback_end - softback_buf;
1579 if (n < softback_top) {
1581 (softback_top - n) / vc->vc_size_row;
1584 } else if (softback_curr >= softback_top
1585 && n < softback_top) {
1587 (softback_top - n) / vc->vc_size_row;
1591 if (softback_curr > softback_in && n >= softback_end) {
1592 n += softback_buf - softback_end;
1593 if (n > softback_in) {
1597 } else if (softback_curr <= softback_in && n > softback_in) {
1602 if (n == softback_curr)
1605 s = (u16 *) softback_curr;
1606 if (s == (u16 *) softback_in)
1607 s = (u16 *) vc->vc_origin;
1609 unsigned short *start;
1613 unsigned short attr = 1;
1616 le = advance_row(s, 1);
1619 if (attr != (c & 0xff00)) {
1622 fbcon_putcs(vc, start, s - start,
1628 if (c == scr_readw(d)) {
1630 fbcon_putcs(vc, start, s - start,
1643 fbcon_putcs(vc, start, s - start, line, x);
1645 if (d == (u16 *) softback_end)
1646 d = (u16 *) softback_buf;
1647 if (d == (u16 *) softback_in)
1648 d = (u16 *) vc->vc_origin;
1649 if (s == (u16 *) softback_end)
1650 s = (u16 *) softback_buf;
1651 if (s == (u16 *) softback_in)
1652 s = (u16 *) vc->vc_origin;
1656 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1657 int line, int count, int dy)
1659 unsigned short *s = (unsigned short *)
1660 (vc->vc_origin + vc->vc_size_row * line);
1663 unsigned short *start = s;
1664 unsigned short *le = advance_row(s, 1);
1667 unsigned short attr = 1;
1671 if (attr != (c & 0xff00)) {
1674 fbcon_putcs(vc, start, s - start,
1680 console_conditional_schedule();
1684 fbcon_putcs(vc, start, s - start, dy, x);
1685 console_conditional_schedule();
1690 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1691 int line, int count, int offset)
1693 unsigned short *d = (unsigned short *)
1694 (vc->vc_origin + vc->vc_size_row * line);
1695 unsigned short *s = d + offset;
1698 unsigned short *start = s;
1699 unsigned short *le = advance_row(s, 1);
1702 unsigned short attr = 1;
1706 if (attr != (c & 0xff00)) {
1709 fbcon_putcs(vc, start, s - start,
1715 if (c == scr_readw(d)) {
1717 fbcon_putcs(vc, start, s - start,
1727 console_conditional_schedule();
1732 fbcon_putcs(vc, start, s - start, line, x);
1733 console_conditional_schedule();
1738 /* NOTE: We subtract two lines from these pointers */
1739 s -= vc->vc_size_row;
1740 d -= vc->vc_size_row;
1745 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1750 if (vc->vc_num != fg_console)
1752 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1755 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1757 p = advance_row(p, 1);
1758 softback_in += vc->vc_size_row;
1759 if (softback_in == softback_end)
1760 softback_in = softback_buf;
1761 if (softback_in == softback_top) {
1762 softback_top += vc->vc_size_row;
1763 if (softback_top == softback_end)
1764 softback_top = softback_buf;
1767 softback_curr = softback_in;
1770 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1773 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1774 struct display *p = &fb_display[vc->vc_num];
1775 struct fbcon_ops *ops = info->fbcon_par;
1776 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1778 if (fbcon_is_inactive(vc, info))
1781 fbcon_cursor(vc, CM_ERASE);
1784 * ++Geert: Only use ywrap/ypan if the console is in text mode
1785 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1786 * whole screen (prevents flicker).
1791 if (count > vc->vc_rows) /* Maximum realistic size */
1792 count = vc->vc_rows;
1794 fbcon_softback_note(vc, t, count);
1795 if (logo_shown >= 0)
1797 switch (p->scrollmode) {
1799 ops->bmove(vc, info, t + count, 0, t, 0,
1800 b - t - count, vc->vc_cols);
1801 ops->clear(vc, info, b - count, 0, count,
1805 case SCROLL_WRAP_MOVE:
1806 if (b - t - count > 3 * vc->vc_rows >> 2) {
1808 fbcon_bmove(vc, 0, 0, count, 0, t,
1810 ywrap_up(vc, count);
1811 if (vc->vc_rows - b > 0)
1812 fbcon_bmove(vc, b - count, 0, b, 0,
1815 } else if (info->flags & FBINFO_READS_FAST)
1816 fbcon_bmove(vc, t + count, 0, t, 0,
1817 b - t - count, vc->vc_cols);
1820 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1823 case SCROLL_PAN_REDRAW:
1824 if ((p->yscroll + count <=
1825 2 * (p->vrows - vc->vc_rows))
1826 && ((!scroll_partial && (b - t == vc->vc_rows))
1829 3 * vc->vc_rows >> 2)))) {
1831 fbcon_redraw_move(vc, p, 0, t, count);
1832 ypan_up_redraw(vc, t, count);
1833 if (vc->vc_rows - b > 0)
1834 fbcon_redraw_move(vc, p, b,
1835 vc->vc_rows - b, b);
1837 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1838 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1841 case SCROLL_PAN_MOVE:
1842 if ((p->yscroll + count <=
1843 2 * (p->vrows - vc->vc_rows))
1844 && ((!scroll_partial && (b - t == vc->vc_rows))
1847 3 * vc->vc_rows >> 2)))) {
1849 fbcon_bmove(vc, 0, 0, count, 0, t,
1852 if (vc->vc_rows - b > 0)
1853 fbcon_bmove(vc, b - count, 0, b, 0,
1856 } else if (info->flags & FBINFO_READS_FAST)
1857 fbcon_bmove(vc, t + count, 0, t, 0,
1858 b - t - count, vc->vc_cols);
1861 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1866 fbcon_redraw(vc, p, t, b - t - count,
1867 count * vc->vc_cols);
1868 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1869 scr_memsetw((unsigned short *) (vc->vc_origin +
1872 vc->vc_video_erase_char,
1873 vc->vc_size_row * count);
1879 if (count > vc->vc_rows) /* Maximum realistic size */
1880 count = vc->vc_rows;
1881 if (logo_shown >= 0)
1883 switch (p->scrollmode) {
1885 ops->bmove(vc, info, t, 0, t + count, 0,
1886 b - t - count, vc->vc_cols);
1887 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1890 case SCROLL_WRAP_MOVE:
1891 if (b - t - count > 3 * vc->vc_rows >> 2) {
1892 if (vc->vc_rows - b > 0)
1893 fbcon_bmove(vc, b, 0, b - count, 0,
1896 ywrap_down(vc, count);
1898 fbcon_bmove(vc, count, 0, 0, 0, t,
1900 } else if (info->flags & FBINFO_READS_FAST)
1901 fbcon_bmove(vc, t, 0, t + count, 0,
1902 b - t - count, vc->vc_cols);
1905 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1908 case SCROLL_PAN_MOVE:
1909 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1910 && ((!scroll_partial && (b - t == vc->vc_rows))
1913 3 * vc->vc_rows >> 2)))) {
1914 if (vc->vc_rows - b > 0)
1915 fbcon_bmove(vc, b, 0, b - count, 0,
1918 ypan_down(vc, count);
1920 fbcon_bmove(vc, count, 0, 0, 0, t,
1922 } else if (info->flags & FBINFO_READS_FAST)
1923 fbcon_bmove(vc, t, 0, t + count, 0,
1924 b - t - count, vc->vc_cols);
1927 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1930 case SCROLL_PAN_REDRAW:
1931 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1932 && ((!scroll_partial && (b - t == vc->vc_rows))
1935 3 * vc->vc_rows >> 2)))) {
1936 if (vc->vc_rows - b > 0)
1937 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1939 ypan_down_redraw(vc, t, count);
1941 fbcon_redraw_move(vc, p, count, t, 0);
1943 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1944 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1949 fbcon_redraw(vc, p, b - 1, b - t - count,
1950 -count * vc->vc_cols);
1951 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1952 scr_memsetw((unsigned short *) (vc->vc_origin +
1955 vc->vc_video_erase_char,
1956 vc->vc_size_row * count);
1964 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1965 int height, int width)
1967 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1968 struct display *p = &fb_display[vc->vc_num];
1970 if (fbcon_is_inactive(vc, info))
1973 if (!width || !height)
1976 /* Split blits that cross physical y_wrap case.
1977 * Pathological case involves 4 blits, better to use recursive
1978 * code rather than unrolled case
1980 * Recursive invocations don't need to erase the cursor over and
1981 * over again, so we use fbcon_bmove_rec()
1983 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1984 p->vrows - p->yscroll);
1987 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1988 int dy, int dx, int height, int width, u_int y_break)
1990 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1991 struct fbcon_ops *ops = info->fbcon_par;
1994 if (sy < y_break && sy + height > y_break) {
1996 if (dy < sy) { /* Avoid trashing self */
1997 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1999 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2000 height - b, width, y_break);
2002 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2003 height - b, width, y_break);
2004 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2010 if (dy < y_break && dy + height > y_break) {
2012 if (dy < sy) { /* Avoid trashing self */
2013 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2015 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2016 height - b, width, y_break);
2018 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2019 height - b, width, y_break);
2020 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2025 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2029 static __inline__ void updatescrollmode(struct display *p,
2030 struct fb_info *info,
2033 struct fbcon_ops *ops = info->fbcon_par;
2034 int fh = vc->vc_font.height;
2035 int cap = info->flags;
2037 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2038 info->fix.xpanstep);
2039 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2040 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2041 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2042 info->var.xres_virtual);
2043 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2044 divides(ypan, vc->vc_font.height) && vyres > yres;
2045 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2046 divides(ywrap, vc->vc_font.height) &&
2047 divides(vc->vc_font.height, vyres) &&
2048 divides(vc->vc_font.height, yres);
2049 int reading_fast = cap & FBINFO_READS_FAST;
2050 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2051 !(cap & FBINFO_HWACCEL_DISABLED);
2052 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2053 !(cap & FBINFO_HWACCEL_DISABLED);
2055 p->vrows = vyres/fh;
2056 if (yres > (fh * (vc->vc_rows + 1)))
2057 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2058 if ((yres % fh) && (vyres % fh < yres % fh))
2061 if (good_wrap || good_pan) {
2062 if (reading_fast || fast_copyarea)
2063 p->scrollmode = good_wrap ?
2064 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2066 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2069 if (reading_fast || (fast_copyarea && !fast_imageblit))
2070 p->scrollmode = SCROLL_MOVE;
2072 p->scrollmode = SCROLL_REDRAW;
2076 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2077 unsigned int height)
2079 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2080 struct fbcon_ops *ops = info->fbcon_par;
2081 struct display *p = &fb_display[vc->vc_num];
2082 struct fb_var_screeninfo var = info->var;
2083 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2085 virt_w = FBCON_SWAP(ops->rotate, width, height);
2086 virt_h = FBCON_SWAP(ops->rotate, height, width);
2087 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2088 vc->vc_font.height);
2089 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2091 var.xres = virt_w * virt_fw;
2092 var.yres = virt_h * virt_fh;
2093 x_diff = info->var.xres - var.xres;
2094 y_diff = info->var.yres - var.yres;
2095 if (x_diff < 0 || x_diff > virt_fw ||
2096 y_diff < 0 || y_diff > virt_fh) {
2097 const struct fb_videomode *mode;
2099 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2100 mode = fb_find_best_mode(&var, &info->modelist);
2103 display_to_var(&var, p);
2104 fb_videomode_to_var(&var, mode);
2106 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2109 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2110 if (CON_IS_VISIBLE(vc)) {
2111 var.activate = FB_ACTIVATE_NOW |
2113 fb_set_var(info, &var);
2115 var_to_display(p, &info->var, info);
2116 ops->var = info->var;
2118 updatescrollmode(p, info, vc);
2122 static int fbcon_switch(struct vc_data *vc)
2124 struct fb_info *info, *old_info = NULL;
2125 struct fbcon_ops *ops;
2126 struct display *p = &fb_display[vc->vc_num];
2127 struct fb_var_screeninfo var;
2128 int i, prev_console, charcnt = 256;
2130 info = registered_fb[con2fb_map[vc->vc_num]];
2131 ops = info->fbcon_par;
2135 fbcon_set_origin(vc);
2136 softback_top = softback_curr = softback_in = softback_buf;
2138 fbcon_update_softback(vc);
2141 if (logo_shown >= 0) {
2142 struct vc_data *conp2 = vc_cons[logo_shown].d;
2144 if (conp2->vc_top == logo_lines
2145 && conp2->vc_bottom == conp2->vc_rows)
2147 logo_shown = FBCON_LOGO_CANSHOW;
2150 prev_console = ops->currcon;
2151 if (prev_console != -1)
2152 old_info = registered_fb[con2fb_map[prev_console]];
2154 * FIXME: If we have multiple fbdev's loaded, we need to
2155 * update all info->currcon. Perhaps, we can place this
2156 * in a centralized structure, but this might break some
2159 * info->currcon = vc->vc_num;
2161 for (i = 0; i < FB_MAX; i++) {
2162 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2163 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2165 o->currcon = vc->vc_num;
2168 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2169 display_to_var(&var, p);
2170 var.activate = FB_ACTIVATE_NOW;
2173 * make sure we don't unnecessarily trip the memcmp()
2176 info->var.activate = var.activate;
2177 var.yoffset = info->var.yoffset;
2178 var.xoffset = info->var.xoffset;
2179 var.vmode = info->var.vmode;
2180 fb_set_var(info, &var);
2181 ops->var = info->var;
2183 if (old_info != NULL && (old_info != info ||
2184 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2185 if (info->fbops->fb_set_par)
2186 info->fbops->fb_set_par(info);
2188 if (old_info != info)
2189 fbcon_del_cursor_timer(old_info);
2192 if (fbcon_is_inactive(vc, info) ||
2193 ops->blank_state != FB_BLANK_UNBLANK)
2194 fbcon_del_cursor_timer(info);
2196 fbcon_add_cursor_timer(info);
2198 set_blitting_type(vc, info);
2199 ops->cursor_reset = 1;
2201 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2202 ops->rotate = FB_ROTATE_UR;
2203 set_blitting_type(vc, info);
2206 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2207 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2210 charcnt = FNTCHARCNT(vc->vc_font.data);
2213 vc->vc_complement_mask <<= 1;
2215 updatescrollmode(p, info, vc);
2217 switch (p->scrollmode) {
2218 case SCROLL_WRAP_MOVE:
2219 scrollback_phys_max = p->vrows - vc->vc_rows;
2221 case SCROLL_PAN_MOVE:
2222 case SCROLL_PAN_REDRAW:
2223 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2224 if (scrollback_phys_max < 0)
2225 scrollback_phys_max = 0;
2228 scrollback_phys_max = 0;
2233 scrollback_current = 0;
2235 if (!fbcon_is_inactive(vc, info)) {
2236 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2237 ops->update_start(info);
2240 fbcon_set_palette(vc, color_table);
2241 fbcon_clear_margins(vc, 0);
2243 if (logo_shown == FBCON_LOGO_DRAW) {
2245 logo_shown = fg_console;
2246 /* This is protected above by initmem_freed */
2247 fb_show_logo(info, ops->rotate);
2249 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2250 vc->vc_size_row * (vc->vc_bottom -
2257 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2260 struct fb_event event;
2263 unsigned short charmask = vc->vc_hi_font_mask ?
2265 unsigned short oldc;
2267 oldc = vc->vc_video_erase_char;
2268 vc->vc_video_erase_char &= charmask;
2269 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2270 vc->vc_video_erase_char = oldc;
2275 event.data = ␣
2276 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2279 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2281 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2282 struct fbcon_ops *ops = info->fbcon_par;
2285 struct fb_var_screeninfo var = info->var;
2290 if (info->fbops->fb_save_state)
2291 info->fbops->fb_save_state(info);
2292 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2293 fb_set_var(info, &var);
2295 ops->var = info->var;
2296 } else if (info->fbops->fb_restore_state)
2297 info->fbops->fb_restore_state(info);
2300 if (!fbcon_is_inactive(vc, info)) {
2301 if (ops->blank_state != blank) {
2302 ops->blank_state = blank;
2303 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2304 ops->cursor_flash = (!blank);
2306 if (fb_blank(info, blank))
2307 fbcon_generic_blank(vc, info, blank);
2314 if (fbcon_is_inactive(vc, info) ||
2315 ops->blank_state != FB_BLANK_UNBLANK)
2316 fbcon_del_cursor_timer(info);
2318 fbcon_add_cursor_timer(info);
2323 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2325 u8 *fontdata = vc->vc_font.data;
2326 u8 *data = font->data;
2329 font->width = vc->vc_font.width;
2330 font->height = vc->vc_font.height;
2331 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2335 if (font->width <= 8) {
2336 j = vc->vc_font.height;
2337 for (i = 0; i < font->charcount; i++) {
2338 memcpy(data, fontdata, j);
2339 memset(data + j, 0, 32 - j);
2343 } else if (font->width <= 16) {
2344 j = vc->vc_font.height * 2;
2345 for (i = 0; i < font->charcount; i++) {
2346 memcpy(data, fontdata, j);
2347 memset(data + j, 0, 64 - j);
2351 } else if (font->width <= 24) {
2352 for (i = 0; i < font->charcount; i++) {
2353 for (j = 0; j < vc->vc_font.height; j++) {
2354 *data++ = fontdata[0];
2355 *data++ = fontdata[1];
2356 *data++ = fontdata[2];
2357 fontdata += sizeof(u32);
2359 memset(data, 0, 3 * (32 - j));
2360 data += 3 * (32 - j);
2363 j = vc->vc_font.height * 4;
2364 for (i = 0; i < font->charcount; i++) {
2365 memcpy(data, fontdata, j);
2366 memset(data + j, 0, 128 - j);
2374 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2375 const u8 * data, int userfont)
2377 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2378 struct fbcon_ops *ops = info->fbcon_par;
2379 struct display *p = &fb_display[vc->vc_num];
2382 char *old_data = NULL;
2384 if (CON_IS_VISIBLE(vc) && softback_lines)
2385 fbcon_set_origin(vc);
2387 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2389 old_data = vc->vc_font.data;
2391 cnt = FNTCHARCNT(data);
2394 vc->vc_font.data = (void *)(p->fontdata = data);
2395 if ((p->userfont = userfont))
2397 vc->vc_font.width = w;
2398 vc->vc_font.height = h;
2399 if (vc->vc_hi_font_mask && cnt == 256) {
2400 vc->vc_hi_font_mask = 0;
2401 if (vc->vc_can_do_color) {
2402 vc->vc_complement_mask >>= 1;
2403 vc->vc_s_complement_mask >>= 1;
2406 /* ++Edmund: reorder the attribute bits */
2407 if (vc->vc_can_do_color) {
2408 unsigned short *cp =
2409 (unsigned short *) vc->vc_origin;
2410 int count = vc->vc_screenbuf_size / 2;
2412 for (; count > 0; count--, cp++) {
2414 scr_writew(((c & 0xfe00) >> 1) |
2417 c = vc->vc_video_erase_char;
2418 vc->vc_video_erase_char =
2419 ((c & 0xfe00) >> 1) | (c & 0xff);
2422 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2423 vc->vc_hi_font_mask = 0x100;
2424 if (vc->vc_can_do_color) {
2425 vc->vc_complement_mask <<= 1;
2426 vc->vc_s_complement_mask <<= 1;
2429 /* ++Edmund: reorder the attribute bits */
2431 unsigned short *cp =
2432 (unsigned short *) vc->vc_origin;
2433 int count = vc->vc_screenbuf_size / 2;
2435 for (; count > 0; count--, cp++) {
2436 unsigned short newc;
2438 if (vc->vc_can_do_color)
2440 ((c & 0xff00) << 1) | (c &
2444 scr_writew(newc, cp);
2446 c = vc->vc_video_erase_char;
2447 if (vc->vc_can_do_color) {
2448 vc->vc_video_erase_char =
2449 ((c & 0xff00) << 1) | (c & 0xff);
2452 vc->vc_video_erase_char = c & ~0x100;
2460 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2461 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2464 vc_resize(vc, cols, rows);
2465 if (CON_IS_VISIBLE(vc) && softback_buf)
2466 fbcon_update_softback(vc);
2467 } else if (CON_IS_VISIBLE(vc)
2468 && vc->vc_mode == KD_TEXT) {
2469 fbcon_clear_margins(vc, 0);
2473 if (old_data && (--REFCOUNT(old_data) == 0))
2474 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2478 static int fbcon_copy_font(struct vc_data *vc, int con)
2480 struct display *od = &fb_display[con];
2481 struct console_font *f = &vc->vc_font;
2483 if (od->fontdata == f->data)
2484 return 0; /* already the same font... */
2485 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2489 * User asked to set font; we are guaranteed that
2490 * a) width and height are in range 1..32
2491 * b) charcount does not exceed 512
2492 * but lets not assume that, since someone might someday want to use larger
2493 * fonts. And charcount of 512 is small for unicode support.
2495 * However, user space gives the font in 32 rows , regardless of
2496 * actual font height. So a new API is needed if support for larger fonts
2497 * is ever implemented.
2500 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2502 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2503 unsigned charcount = font->charcount;
2504 int w = font->width;
2505 int h = font->height;
2508 u8 *new_data, *data = font->data;
2509 int pitch = (font->width+7) >> 3;
2511 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2512 * If not this check should be changed to charcount < 256 */
2513 if (charcount != 256 && charcount != 512)
2516 /* Make sure drawing engine can handle the font */
2517 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2518 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2521 size = h * pitch * charcount;
2523 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2528 new_data += FONT_EXTRA_WORDS * sizeof(int);
2529 FNTSIZE(new_data) = size;
2530 FNTCHARCNT(new_data) = charcount;
2531 REFCOUNT(new_data) = 0; /* usage counter */
2532 for (i=0; i< charcount; i++) {
2533 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2536 /* Since linux has a nice crc32 function use it for counting font
2538 csum = crc32(0, new_data, size);
2540 FNTSUM(new_data) = csum;
2541 /* Check if the same font is on some other console already */
2542 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2543 struct vc_data *tmp = vc_cons[i].d;
2545 if (fb_display[i].userfont &&
2546 fb_display[i].fontdata &&
2547 FNTSUM(fb_display[i].fontdata) == csum &&
2548 FNTSIZE(fb_display[i].fontdata) == size &&
2549 tmp->vc_font.width == w &&
2550 !memcmp(fb_display[i].fontdata, new_data, size)) {
2551 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2552 new_data = (u8 *)fb_display[i].fontdata;
2556 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2559 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2561 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2562 const struct font_desc *f;
2565 f = get_default_font(info->var.xres, info->var.yres,
2566 info->pixmap.blit_x, info->pixmap.blit_y);
2567 else if (!(f = find_font(name)))
2570 font->width = f->width;
2571 font->height = f->height;
2572 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2575 static u16 palette_red[16];
2576 static u16 palette_green[16];
2577 static u16 palette_blue[16];
2579 static struct fb_cmap palette_cmap = {
2580 0, 16, palette_red, palette_green, palette_blue, NULL
2583 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2585 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2589 if (fbcon_is_inactive(vc, info))
2592 if (!CON_IS_VISIBLE(vc))
2595 depth = fb_get_color_depth(&info->var, &info->fix);
2597 for (i = j = 0; i < 16; i++) {
2599 val = vc->vc_palette[j++];
2600 palette_red[k] = (val << 8) | val;
2601 val = vc->vc_palette[j++];
2602 palette_green[k] = (val << 8) | val;
2603 val = vc->vc_palette[j++];
2604 palette_blue[k] = (val << 8) | val;
2606 palette_cmap.len = 16;
2607 palette_cmap.start = 0;
2609 * If framebuffer is capable of less than 16 colors,
2610 * use default palette of fbcon.
2613 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2615 return fb_set_cmap(&palette_cmap, info);
2618 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2623 if (vc->vc_num != fg_console || !softback_lines)
2624 return (u16 *) (vc->vc_origin + offset);
2625 line = offset / vc->vc_size_row;
2626 if (line >= softback_lines)
2627 return (u16 *) (vc->vc_origin + offset -
2628 softback_lines * vc->vc_size_row);
2629 p = softback_curr + offset;
2630 if (p >= softback_end)
2631 p += softback_buf - softback_end;
2635 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2641 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2642 unsigned long offset = (pos - vc->vc_origin) / 2;
2644 x = offset % vc->vc_cols;
2645 y = offset / vc->vc_cols;
2646 if (vc->vc_num == fg_console)
2647 y += softback_lines;
2648 ret = pos + (vc->vc_cols - x) * 2;
2649 } else if (vc->vc_num == fg_console && softback_lines) {
2650 unsigned long offset = pos - softback_curr;
2652 if (pos < softback_curr)
2653 offset += softback_end - softback_buf;
2655 x = offset % vc->vc_cols;
2656 y = offset / vc->vc_cols;
2657 ret = pos + (vc->vc_cols - x) * 2;
2658 if (ret == softback_end)
2660 if (ret == softback_in)
2661 ret = vc->vc_origin;
2663 /* Should not happen */
2665 ret = vc->vc_origin;
2674 /* As we might be inside of softback, we may work with non-contiguous buffer,
2675 that's why we have to use a separate routine. */
2676 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2679 u16 a = scr_readw(p);
2680 if (!vc->vc_can_do_color)
2682 else if (vc->vc_hi_font_mask == 0x100)
2683 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2684 (((a) & 0x0e00) << 4);
2686 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2687 (((a) & 0x0700) << 4);
2689 if (p == (u16 *) softback_end)
2690 p = (u16 *) softback_buf;
2691 if (p == (u16 *) softback_in)
2692 p = (u16 *) vc->vc_origin;
2696 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2698 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2699 struct fbcon_ops *ops = info->fbcon_par;
2700 struct display *p = &fb_display[fg_console];
2701 int offset, limit, scrollback_old;
2704 if (vc->vc_num != fg_console)
2706 if (vc->vc_mode != KD_TEXT || !lines)
2708 if (logo_shown >= 0) {
2709 struct vc_data *conp2 = vc_cons[logo_shown].d;
2711 if (conp2->vc_top == logo_lines
2712 && conp2->vc_bottom == conp2->vc_rows)
2714 if (logo_shown == vc->vc_num) {
2720 logo_lines * vc->vc_size_row;
2721 for (i = 0; i < logo_lines; i++) {
2722 if (p == softback_top)
2724 if (p == softback_buf)
2726 p -= vc->vc_size_row;
2727 q -= vc->vc_size_row;
2728 scr_memcpyw((u16 *) q, (u16 *) p,
2731 softback_in = softback_curr = p;
2732 update_region(vc, vc->vc_origin,
2733 logo_lines * vc->vc_cols);
2735 logo_shown = FBCON_LOGO_CANSHOW;
2737 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2738 fbcon_redraw_softback(vc, p, lines);
2739 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2743 if (!scrollback_phys_max)
2746 scrollback_old = scrollback_current;
2747 scrollback_current -= lines;
2748 if (scrollback_current < 0)
2749 scrollback_current = 0;
2750 else if (scrollback_current > scrollback_max)
2751 scrollback_current = scrollback_max;
2752 if (scrollback_current == scrollback_old)
2755 if (fbcon_is_inactive(vc, info))
2758 fbcon_cursor(vc, CM_ERASE);
2760 offset = p->yscroll - scrollback_current;
2762 switch (p->scrollmode) {
2763 case SCROLL_WRAP_MOVE:
2764 info->var.vmode |= FB_VMODE_YWRAP;
2766 case SCROLL_PAN_MOVE:
2767 case SCROLL_PAN_REDRAW:
2768 limit -= vc->vc_rows;
2769 info->var.vmode &= ~FB_VMODE_YWRAP;
2774 else if (offset >= limit)
2777 ops->var.xoffset = 0;
2778 ops->var.yoffset = offset * vc->vc_font.height;
2779 ops->update_start(info);
2781 if (!scrollback_current)
2782 fbcon_cursor(vc, CM_DRAW);
2786 static int fbcon_set_origin(struct vc_data *vc)
2789 fbcon_scrolldelta(vc, softback_lines);
2793 static void fbcon_suspended(struct fb_info *info)
2795 struct vc_data *vc = NULL;
2796 struct fbcon_ops *ops = info->fbcon_par;
2798 if (!ops || ops->currcon < 0)
2800 vc = vc_cons[ops->currcon].d;
2802 /* Clear cursor, restore saved data */
2803 fbcon_cursor(vc, CM_ERASE);
2806 static void fbcon_resumed(struct fb_info *info)
2809 struct fbcon_ops *ops = info->fbcon_par;
2811 if (!ops || ops->currcon < 0)
2813 vc = vc_cons[ops->currcon].d;
2818 static void fbcon_modechanged(struct fb_info *info)
2820 struct fbcon_ops *ops = info->fbcon_par;
2825 if (!ops || ops->currcon < 0)
2827 vc = vc_cons[ops->currcon].d;
2828 if (vc->vc_mode != KD_TEXT ||
2829 registered_fb[con2fb_map[ops->currcon]] != info)
2832 p = &fb_display[vc->vc_num];
2833 set_blitting_type(vc, info);
2835 if (CON_IS_VISIBLE(vc)) {
2836 var_to_display(p, &info->var, info);
2837 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2838 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2839 cols /= vc->vc_font.width;
2840 rows /= vc->vc_font.height;
2841 vc_resize(vc, cols, rows);
2842 updatescrollmode(p, info, vc);
2844 scrollback_current = 0;
2846 if (!fbcon_is_inactive(vc, info)) {
2847 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2848 ops->update_start(info);
2851 fbcon_set_palette(vc, color_table);
2854 fbcon_update_softback(vc);
2858 static void fbcon_set_all_vcs(struct fb_info *info)
2860 struct fbcon_ops *ops = info->fbcon_par;
2863 int i, rows, cols, fg = -1;
2865 if (!ops || ops->currcon < 0)
2868 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2870 if (!vc || vc->vc_mode != KD_TEXT ||
2871 registered_fb[con2fb_map[i]] != info)
2874 if (CON_IS_VISIBLE(vc)) {
2879 p = &fb_display[vc->vc_num];
2880 set_blitting_type(vc, info);
2881 var_to_display(p, &info->var, info);
2882 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2883 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
2884 cols /= vc->vc_font.width;
2885 rows /= vc->vc_font.height;
2886 vc_resize(vc, cols, rows);
2890 fbcon_modechanged(info);
2893 static int fbcon_mode_deleted(struct fb_info *info,
2894 struct fb_videomode *mode)
2896 struct fb_info *fb_info;
2898 int i, j, found = 0;
2900 /* before deletion, ensure that mode is not in use */
2901 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2905 fb_info = registered_fb[j];
2906 if (fb_info != info)
2911 if (fb_mode_is_equal(p->mode, mode)) {
2919 static int fbcon_fb_unregistered(int idx)
2923 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2924 if (con2fb_map[i] == idx)
2928 if (idx == info_idx) {
2931 for (i = 0; i < FB_MAX; i++) {
2932 if (registered_fb[i] != NULL) {
2939 if (info_idx != -1) {
2940 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2941 if (con2fb_map[i] == -1)
2942 con2fb_map[i] = info_idx;
2946 if (!num_registered_fb)
2947 unregister_con_driver(&fb_con);
2952 static int fbcon_fb_registered(int idx)
2956 if (info_idx == -1) {
2957 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2958 if (con2fb_map_boot[i] == idx) {
2965 ret = fbcon_takeover(1);
2967 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2968 if (con2fb_map_boot[i] == idx &&
2969 con2fb_map[i] == -1)
2970 set_con2fb_map(i, idx, 0);
2977 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2979 struct fbcon_ops *ops = info->fbcon_par;
2982 if (!ops || ops->currcon < 0)
2985 vc = vc_cons[ops->currcon].d;
2986 if (vc->vc_mode != KD_TEXT ||
2987 registered_fb[con2fb_map[ops->currcon]] != info)
2990 if (CON_IS_VISIBLE(vc)) {
2994 do_unblank_screen(0);
2996 ops->blank_state = blank;
2999 static void fbcon_new_modelist(struct fb_info *info)
3003 struct fb_var_screeninfo var;
3004 const struct fb_videomode *mode;
3006 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3007 if (registered_fb[con2fb_map[i]] != info)
3009 if (!fb_display[i].mode)
3012 display_to_var(&var, &fb_display[i]);
3013 mode = fb_find_nearest_mode(fb_display[i].mode,
3015 fb_videomode_to_var(&var, mode);
3018 fbcon_set_disp(info, &var, vc);
3020 fbcon_preset_disp(info, &var, i);
3025 static int fbcon_event_notify(struct notifier_block *self,
3026 unsigned long action, void *data)
3028 struct fb_event *event = data;
3029 struct fb_info *info = event->info;
3030 struct fb_videomode *mode;
3031 struct fb_con2fbmap *con2fb;
3035 * ignore all events except driver registration and deregistration
3036 * if fbcon is not active
3038 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3039 action == FB_EVENT_FB_UNREGISTERED))
3043 case FB_EVENT_SUSPEND:
3044 fbcon_suspended(info);
3046 case FB_EVENT_RESUME:
3047 fbcon_resumed(info);
3049 case FB_EVENT_MODE_CHANGE:
3050 fbcon_modechanged(info);
3052 case FB_EVENT_MODE_CHANGE_ALL:
3053 fbcon_set_all_vcs(info);
3055 case FB_EVENT_MODE_DELETE:
3057 ret = fbcon_mode_deleted(info, mode);
3059 case FB_EVENT_FB_REGISTERED:
3060 ret = fbcon_fb_registered(info->node);
3062 case FB_EVENT_FB_UNREGISTERED:
3063 ret = fbcon_fb_unregistered(info->node);
3065 case FB_EVENT_SET_CONSOLE_MAP:
3066 con2fb = event->data;
3067 ret = set_con2fb_map(con2fb->console - 1,
3068 con2fb->framebuffer, 1);
3070 case FB_EVENT_GET_CONSOLE_MAP:
3071 con2fb = event->data;
3072 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3074 case FB_EVENT_BLANK:
3075 fbcon_fb_blanked(info, *(int *)event->data);
3077 case FB_EVENT_NEW_MODELIST:
3078 fbcon_new_modelist(info);
3087 * The console `switch' structure for the frame buffer based console
3090 static const struct consw fb_con = {
3091 .owner = THIS_MODULE,
3092 .con_startup = fbcon_startup,
3093 .con_init = fbcon_init,
3094 .con_deinit = fbcon_deinit,
3095 .con_clear = fbcon_clear,
3096 .con_putc = fbcon_putc,
3097 .con_putcs = fbcon_putcs,
3098 .con_cursor = fbcon_cursor,
3099 .con_scroll = fbcon_scroll,
3100 .con_bmove = fbcon_bmove,
3101 .con_switch = fbcon_switch,
3102 .con_blank = fbcon_blank,
3103 .con_font_set = fbcon_set_font,
3104 .con_font_get = fbcon_get_font,
3105 .con_font_default = fbcon_set_def_font,
3106 .con_font_copy = fbcon_copy_font,
3107 .con_set_palette = fbcon_set_palette,
3108 .con_scrolldelta = fbcon_scrolldelta,
3109 .con_set_origin = fbcon_set_origin,
3110 .con_invert_region = fbcon_invert_region,
3111 .con_screen_pos = fbcon_screen_pos,
3112 .con_getxy = fbcon_getxy,
3113 .con_resize = fbcon_resize,
3116 static struct notifier_block fbcon_event_notifier = {
3117 .notifier_call = fbcon_event_notify,
3120 static ssize_t store_rotate(struct class_device *class_device,
3121 const char *buf, size_t count)
3123 struct fb_info *info;
3127 if (fbcon_has_exited)
3130 acquire_console_sem();
3131 idx = con2fb_map[fg_console];
3133 if (idx == -1 || registered_fb[idx] == NULL)
3136 info = registered_fb[idx];
3137 rotate = simple_strtoul(buf, last, 0);
3138 fbcon_rotate(info, rotate);
3140 release_console_sem();
3144 static ssize_t store_rotate_all(struct class_device *class_device,
3145 const char *buf, size_t count)
3147 struct fb_info *info;
3151 if (fbcon_has_exited)
3154 acquire_console_sem();
3155 idx = con2fb_map[fg_console];
3157 if (idx == -1 || registered_fb[idx] == NULL)
3160 info = registered_fb[idx];
3161 rotate = simple_strtoul(buf, last, 0);
3162 fbcon_rotate_all(info, rotate);
3164 release_console_sem();
3168 static ssize_t show_rotate(struct class_device *class_device, char *buf)
3170 struct fb_info *info;
3171 int rotate = 0, idx;
3173 if (fbcon_has_exited)
3176 acquire_console_sem();
3177 idx = con2fb_map[fg_console];
3179 if (idx == -1 || registered_fb[idx] == NULL)
3182 info = registered_fb[idx];
3183 rotate = fbcon_get_rotate(info);
3185 release_console_sem();
3186 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3189 static struct class_device_attribute class_device_attrs[] = {
3190 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3191 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3194 static int fbcon_init_class_device(void)
3198 fbcon_has_sysfs = 1;
3200 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3201 error = class_device_create_file(fbcon_class_device,
3202 &class_device_attrs[i]);
3210 class_device_remove_file(fbcon_class_device,
3211 &class_device_attrs[i]);
3213 fbcon_has_sysfs = 0;
3219 static void fbcon_start(void)
3221 if (num_registered_fb) {
3224 acquire_console_sem();
3226 for (i = 0; i < FB_MAX; i++) {
3227 if (registered_fb[i] != NULL) {
3233 release_console_sem();
3238 static void fbcon_exit(void)
3240 struct fb_info *info;
3243 if (fbcon_has_exited)
3247 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3250 if (MACH_IS_MAC && vbl_detected)
3251 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
3254 kfree((void *)softback_buf);
3257 for (i = 0; i < FB_MAX; i++) {
3259 info = registered_fb[i];
3264 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3265 if (con2fb_map[j] == i)
3270 if (info->fbops->fb_release)
3271 info->fbops->fb_release(info, 0);
3272 module_put(info->fbops->owner);
3274 if (info->fbcon_par) {
3275 struct fbcon_ops *ops = info->fbcon_par;
3277 fbcon_del_cursor_timer(info);
3278 kfree(ops->cursor_src);
3279 kfree(info->fbcon_par);
3280 info->fbcon_par = NULL;
3283 if (info->queue.func == fb_flashcursor)
3284 info->queue.func = NULL;
3288 fbcon_has_exited = 1;
3291 static int __init fb_console_init(void)
3295 acquire_console_sem();
3296 fb_register_client(&fbcon_event_notifier);
3297 fbcon_class_device =
3298 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
3300 if (IS_ERR(fbcon_class_device)) {
3301 printk(KERN_WARNING "Unable to create class_device "
3302 "for fbcon; errno = %ld\n",
3303 PTR_ERR(fbcon_class_device));
3304 fbcon_class_device = NULL;
3306 fbcon_init_class_device();
3308 for (i = 0; i < MAX_NR_CONSOLES; i++)
3311 release_console_sem();
3316 module_init(fb_console_init);
3320 static void __exit fbcon_deinit_class_device(void)
3324 if (fbcon_has_sysfs) {
3325 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3326 class_device_remove_file(fbcon_class_device,
3327 &class_device_attrs[i]);
3329 fbcon_has_sysfs = 0;
3333 static void __exit fb_console_exit(void)
3335 acquire_console_sem();
3336 fb_unregister_client(&fbcon_event_notifier);
3337 fbcon_deinit_class_device();
3338 class_device_destroy(fb_class, MKDEV(0, 0));
3340 release_console_sem();
3341 unregister_con_driver(&fb_con);
3344 module_exit(fb_console_exit);
3348 MODULE_LICENSE("GPL");