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,
992 vc->vc_font.width = font->width;
993 vc->vc_font.height = font->height;
994 vc->vc_font.data = (void *)(p->fontdata = font->data);
995 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
998 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
999 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1000 cols /= vc->vc_font.width;
1001 rows /= vc->vc_font.height;
1002 vc_resize(vc, cols, rows);
1004 DPRINTK("mode: %s\n", info->fix.id);
1005 DPRINTK("visual: %d\n", info->fix.visual);
1006 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1008 info->var.bits_per_pixel);
1011 if (MACH_IS_ATARI) {
1012 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1014 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1015 IRQ_TYPE_PRIO, "framebuffer vbl",
1018 #endif /* CONFIG_ATARI */
1022 * On a Macintoy, the VBL interrupt may or may not be active.
1023 * As interrupt based cursor is more reliable and race free, we
1024 * probe for VBL interrupts.
1029 * Probe for VBL: set temp. handler ...
1031 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1032 "framebuffer vbl", info);
1036 * ... and spin for 20 ms ...
1038 while (!vbl_detected && ++ct < 1000)
1043 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1045 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1049 * interrupt based cursor ok
1051 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1053 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1054 "framebuffer vbl", info);
1057 * VBL not detected: fall through, use timer based cursor
1062 #endif /* CONFIG_MAC */
1064 fbcon_add_cursor_timer(info);
1065 fbcon_has_exited = 0;
1066 return display_desc;
1069 static void fbcon_init(struct vc_data *vc, int init)
1071 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1072 struct fbcon_ops *ops;
1073 struct vc_data **default_mode = vc->vc_display_fg;
1074 struct vc_data *svc = *default_mode;
1075 struct display *t, *p = &fb_display[vc->vc_num];
1076 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1079 if (info_idx == -1 || info == NULL)
1084 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1085 (info->fix.type == FB_TYPE_TEXT))
1088 if (var_to_display(p, &info->var, info))
1091 /* If we are not the first console on this
1092 fb, copy the font from that console */
1093 t = &fb_display[fg_console];
1096 struct vc_data *fvc = vc_cons[fg_console].d;
1098 vc->vc_font.data = (void *)(p->fontdata =
1100 vc->vc_font.width = fvc->vc_font.width;
1101 vc->vc_font.height = fvc->vc_font.height;
1102 p->userfont = t->userfont;
1105 REFCOUNT(p->fontdata)++;
1107 const struct font_desc *font = NULL;
1109 if (!fontname[0] || !(font = find_font(fontname)))
1110 font = get_default_font(info->var.xres,
1112 vc->vc_font.width = font->width;
1113 vc->vc_font.height = font->height;
1114 vc->vc_font.data = (void *)(p->fontdata = font->data);
1115 vc->vc_font.charcount = 256; /* FIXME Need to
1116 support more fonts */
1121 charcnt = FNTCHARCNT(p->fontdata);
1123 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1124 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1125 if (charcnt == 256) {
1126 vc->vc_hi_font_mask = 0;
1128 vc->vc_hi_font_mask = 0x100;
1129 if (vc->vc_can_do_color)
1130 vc->vc_complement_mask <<= 1;
1133 if (!*svc->vc_uni_pagedir_loc)
1134 con_set_default_unimap(svc);
1135 if (!*vc->vc_uni_pagedir_loc)
1136 con_copy_unimap(vc, svc);
1138 ops = info->fbcon_par;
1139 p->con_rotate = rotate;
1140 set_blitting_type(vc, info);
1144 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1145 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1146 new_cols /= vc->vc_font.width;
1147 new_rows /= vc->vc_font.height;
1148 vc_resize(vc, new_cols, new_rows);
1151 * We must always set the mode. The mode of the previous console
1152 * driver could be in the same resolution but we are using different
1153 * hardware so we have to initialize the hardware.
1155 * We need to do it in fbcon_init() to prevent screen corruption.
1157 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1158 if (info->fbops->fb_set_par &&
1159 !(ops->flags & FBCON_FLAGS_INIT))
1160 info->fbops->fb_set_par(info);
1161 ops->flags |= FBCON_FLAGS_INIT;
1166 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1167 !(cap & FBINFO_HWACCEL_DISABLED))
1168 p->scrollmode = SCROLL_MOVE;
1169 else /* default to something safe */
1170 p->scrollmode = SCROLL_REDRAW;
1173 * ++guenther: console.c:vc_allocate() relies on initializing
1174 * vc_{cols,rows}, but we must not set those if we are only
1175 * resizing the console.
1178 vc->vc_cols = new_cols;
1179 vc->vc_rows = new_rows;
1183 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1185 if (vc == svc && softback_buf)
1186 fbcon_update_softback(vc);
1188 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1189 ops->rotate = FB_ROTATE_UR;
1190 set_blitting_type(vc, info);
1193 ops->p = &fb_display[fg_console];
1196 static void fbcon_free_font(struct display *p)
1198 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1199 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1204 static void fbcon_deinit(struct vc_data *vc)
1206 struct display *p = &fb_display[vc->vc_num];
1207 struct fb_info *info;
1208 struct fbcon_ops *ops;
1212 idx = con2fb_map[vc->vc_num];
1217 info = registered_fb[idx];
1222 ops = info->fbcon_par;
1227 if (CON_IS_VISIBLE(vc))
1228 fbcon_del_cursor_timer(info);
1230 ops->flags &= ~FBCON_FLAGS_INIT;
1233 if (!con_is_bound(&fb_con))
1239 /* ====================================================================== */
1241 /* fbcon_XXX routines - interface used by the world
1243 * This system is now divided into two levels because of complications
1244 * caused by hardware scrolling. Top level functions:
1246 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1248 * handles y values in range [0, scr_height-1] that correspond to real
1249 * screen positions. y_wrap shift means that first line of bitmap may be
1250 * anywhere on this display. These functions convert lineoffsets to
1251 * bitmap offsets and deal with the wrap-around case by splitting blits.
1253 * fbcon_bmove_physical_8() -- These functions fast implementations
1254 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1255 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1259 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1260 * Implies should only really hardware scroll in rows. Only reason for
1261 * restriction is simplicity & efficiency at the moment.
1264 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1267 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1268 struct fbcon_ops *ops = info->fbcon_par;
1270 struct display *p = &fb_display[vc->vc_num];
1273 if (fbcon_is_inactive(vc, info))
1276 if (!height || !width)
1279 /* Split blits that cross physical y_wrap boundary */
1281 y_break = p->vrows - p->yscroll;
1282 if (sy < y_break && sy + height - 1 >= y_break) {
1283 u_int b = y_break - sy;
1284 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1285 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1288 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1291 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1292 int count, int ypos, int xpos)
1294 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1295 struct display *p = &fb_display[vc->vc_num];
1296 struct fbcon_ops *ops = info->fbcon_par;
1298 if (!fbcon_is_inactive(vc, info))
1299 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1300 get_color(vc, info, scr_readw(s), 1),
1301 get_color(vc, info, scr_readw(s), 0));
1304 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1308 scr_writew(c, &chr);
1309 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1312 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1314 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1315 struct fbcon_ops *ops = info->fbcon_par;
1317 if (!fbcon_is_inactive(vc, info))
1318 ops->clear_margins(vc, info, bottom_only);
1321 static void fbcon_cursor(struct vc_data *vc, int mode)
1323 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1324 struct fbcon_ops *ops = info->fbcon_par;
1326 int c = scr_readw((u16 *) vc->vc_pos);
1328 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1331 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1332 if (mode & CM_SOFTBACK) {
1333 mode &= ~CM_SOFTBACK;
1337 fbcon_set_origin(vc);
1341 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1342 get_color(vc, info, c, 0));
1343 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1346 static int scrollback_phys_max = 0;
1347 static int scrollback_max = 0;
1348 static int scrollback_current = 0;
1351 * If no vc is existent yet, just set struct display
1353 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1356 struct display *p = &fb_display[unit];
1357 struct display *t = &fb_display[fg_console];
1359 if (var_to_display(p, var, info))
1362 p->fontdata = t->fontdata;
1363 p->userfont = t->userfont;
1365 REFCOUNT(p->fontdata)++;
1368 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1371 struct display *p = &fb_display[vc->vc_num], *t;
1372 struct vc_data **default_mode = vc->vc_display_fg;
1373 struct vc_data *svc = *default_mode;
1374 struct fbcon_ops *ops = info->fbcon_par;
1375 int rows, cols, charcnt = 256;
1377 if (var_to_display(p, var, info))
1379 t = &fb_display[svc->vc_num];
1380 if (!vc->vc_font.data) {
1381 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1382 vc->vc_font.width = (*default_mode)->vc_font.width;
1383 vc->vc_font.height = (*default_mode)->vc_font.height;
1384 p->userfont = t->userfont;
1386 REFCOUNT(p->fontdata)++;
1389 charcnt = FNTCHARCNT(p->fontdata);
1391 var->activate = FB_ACTIVATE_NOW;
1392 info->var.activate = var->activate;
1393 var->yoffset = info->var.yoffset;
1394 var->xoffset = info->var.xoffset;
1395 fb_set_var(info, var);
1396 ops->var = info->var;
1397 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1398 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1399 if (charcnt == 256) {
1400 vc->vc_hi_font_mask = 0;
1402 vc->vc_hi_font_mask = 0x100;
1403 if (vc->vc_can_do_color)
1404 vc->vc_complement_mask <<= 1;
1407 if (!*svc->vc_uni_pagedir_loc)
1408 con_set_default_unimap(svc);
1409 if (!*vc->vc_uni_pagedir_loc)
1410 con_copy_unimap(vc, svc);
1412 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1413 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1414 cols /= vc->vc_font.width;
1415 rows /= vc->vc_font.height;
1416 vc_resize(vc, cols, rows);
1418 if (CON_IS_VISIBLE(vc)) {
1421 fbcon_update_softback(vc);
1425 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1427 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1428 struct fbcon_ops *ops = info->fbcon_par;
1429 struct display *p = &fb_display[vc->vc_num];
1431 p->yscroll += count;
1432 if (p->yscroll >= p->vrows) /* Deal with wrap */
1433 p->yscroll -= p->vrows;
1434 ops->var.xoffset = 0;
1435 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1436 ops->var.vmode |= FB_VMODE_YWRAP;
1437 ops->update_start(info);
1438 scrollback_max += count;
1439 if (scrollback_max > scrollback_phys_max)
1440 scrollback_max = scrollback_phys_max;
1441 scrollback_current = 0;
1444 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1446 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1447 struct fbcon_ops *ops = info->fbcon_par;
1448 struct display *p = &fb_display[vc->vc_num];
1450 p->yscroll -= count;
1451 if (p->yscroll < 0) /* Deal with wrap */
1452 p->yscroll += p->vrows;
1453 ops->var.xoffset = 0;
1454 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1455 ops->var.vmode |= FB_VMODE_YWRAP;
1456 ops->update_start(info);
1457 scrollback_max -= count;
1458 if (scrollback_max < 0)
1460 scrollback_current = 0;
1463 static __inline__ void ypan_up(struct vc_data *vc, int count)
1465 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1466 struct display *p = &fb_display[vc->vc_num];
1467 struct fbcon_ops *ops = info->fbcon_par;
1469 p->yscroll += count;
1470 if (p->yscroll > p->vrows - vc->vc_rows) {
1471 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1472 0, 0, 0, vc->vc_rows, vc->vc_cols);
1473 p->yscroll -= p->vrows - vc->vc_rows;
1476 ops->var.xoffset = 0;
1477 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1478 ops->var.vmode &= ~FB_VMODE_YWRAP;
1479 ops->update_start(info);
1480 fbcon_clear_margins(vc, 1);
1481 scrollback_max += count;
1482 if (scrollback_max > scrollback_phys_max)
1483 scrollback_max = scrollback_phys_max;
1484 scrollback_current = 0;
1487 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1489 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1490 struct fbcon_ops *ops = info->fbcon_par;
1491 struct display *p = &fb_display[vc->vc_num];
1493 p->yscroll += count;
1495 if (p->yscroll > p->vrows - vc->vc_rows) {
1496 p->yscroll -= p->vrows - vc->vc_rows;
1497 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1500 ops->var.xoffset = 0;
1501 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1502 ops->var.vmode &= ~FB_VMODE_YWRAP;
1503 ops->update_start(info);
1504 fbcon_clear_margins(vc, 1);
1505 scrollback_max += count;
1506 if (scrollback_max > scrollback_phys_max)
1507 scrollback_max = scrollback_phys_max;
1508 scrollback_current = 0;
1511 static __inline__ void ypan_down(struct vc_data *vc, int count)
1513 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1514 struct display *p = &fb_display[vc->vc_num];
1515 struct fbcon_ops *ops = info->fbcon_par;
1517 p->yscroll -= count;
1518 if (p->yscroll < 0) {
1519 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1520 0, vc->vc_rows, vc->vc_cols);
1521 p->yscroll += p->vrows - vc->vc_rows;
1524 ops->var.xoffset = 0;
1525 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1526 ops->var.vmode &= ~FB_VMODE_YWRAP;
1527 ops->update_start(info);
1528 fbcon_clear_margins(vc, 1);
1529 scrollback_max -= count;
1530 if (scrollback_max < 0)
1532 scrollback_current = 0;
1535 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1537 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1538 struct fbcon_ops *ops = info->fbcon_par;
1539 struct display *p = &fb_display[vc->vc_num];
1541 p->yscroll -= count;
1543 if (p->yscroll < 0) {
1544 p->yscroll += p->vrows - vc->vc_rows;
1545 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1548 ops->var.xoffset = 0;
1549 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1550 ops->var.vmode &= ~FB_VMODE_YWRAP;
1551 ops->update_start(info);
1552 fbcon_clear_margins(vc, 1);
1553 scrollback_max -= count;
1554 if (scrollback_max < 0)
1556 scrollback_current = 0;
1559 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1562 int count = vc->vc_rows;
1563 unsigned short *d, *s;
1567 d = (u16 *) softback_curr;
1568 if (d == (u16 *) softback_in)
1569 d = (u16 *) vc->vc_origin;
1570 n = softback_curr + delta * vc->vc_size_row;
1571 softback_lines -= delta;
1573 if (softback_curr < softback_top && n < softback_buf) {
1574 n += softback_end - softback_buf;
1575 if (n < softback_top) {
1577 (softback_top - n) / vc->vc_size_row;
1580 } else if (softback_curr >= softback_top
1581 && n < softback_top) {
1583 (softback_top - n) / vc->vc_size_row;
1587 if (softback_curr > softback_in && n >= softback_end) {
1588 n += softback_buf - softback_end;
1589 if (n > softback_in) {
1593 } else if (softback_curr <= softback_in && n > softback_in) {
1598 if (n == softback_curr)
1601 s = (u16 *) softback_curr;
1602 if (s == (u16 *) softback_in)
1603 s = (u16 *) vc->vc_origin;
1605 unsigned short *start;
1609 unsigned short attr = 1;
1612 le = advance_row(s, 1);
1615 if (attr != (c & 0xff00)) {
1618 fbcon_putcs(vc, start, s - start,
1624 if (c == scr_readw(d)) {
1626 fbcon_putcs(vc, start, s - start,
1639 fbcon_putcs(vc, start, s - start, line, x);
1641 if (d == (u16 *) softback_end)
1642 d = (u16 *) softback_buf;
1643 if (d == (u16 *) softback_in)
1644 d = (u16 *) vc->vc_origin;
1645 if (s == (u16 *) softback_end)
1646 s = (u16 *) softback_buf;
1647 if (s == (u16 *) softback_in)
1648 s = (u16 *) vc->vc_origin;
1652 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1653 int line, int count, int dy)
1655 unsigned short *s = (unsigned short *)
1656 (vc->vc_origin + vc->vc_size_row * line);
1659 unsigned short *start = s;
1660 unsigned short *le = advance_row(s, 1);
1663 unsigned short attr = 1;
1667 if (attr != (c & 0xff00)) {
1670 fbcon_putcs(vc, start, s - start,
1676 console_conditional_schedule();
1680 fbcon_putcs(vc, start, s - start, dy, x);
1681 console_conditional_schedule();
1686 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1687 int line, int count, int offset)
1689 unsigned short *d = (unsigned short *)
1690 (vc->vc_origin + vc->vc_size_row * line);
1691 unsigned short *s = d + offset;
1694 unsigned short *start = s;
1695 unsigned short *le = advance_row(s, 1);
1698 unsigned short attr = 1;
1702 if (attr != (c & 0xff00)) {
1705 fbcon_putcs(vc, start, s - start,
1711 if (c == scr_readw(d)) {
1713 fbcon_putcs(vc, start, s - start,
1723 console_conditional_schedule();
1728 fbcon_putcs(vc, start, s - start, line, x);
1729 console_conditional_schedule();
1734 /* NOTE: We subtract two lines from these pointers */
1735 s -= vc->vc_size_row;
1736 d -= vc->vc_size_row;
1741 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1746 if (vc->vc_num != fg_console)
1748 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1751 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1753 p = advance_row(p, 1);
1754 softback_in += vc->vc_size_row;
1755 if (softback_in == softback_end)
1756 softback_in = softback_buf;
1757 if (softback_in == softback_top) {
1758 softback_top += vc->vc_size_row;
1759 if (softback_top == softback_end)
1760 softback_top = softback_buf;
1763 softback_curr = softback_in;
1766 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1769 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1770 struct display *p = &fb_display[vc->vc_num];
1771 struct fbcon_ops *ops = info->fbcon_par;
1772 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1774 if (fbcon_is_inactive(vc, info))
1777 fbcon_cursor(vc, CM_ERASE);
1780 * ++Geert: Only use ywrap/ypan if the console is in text mode
1781 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1782 * whole screen (prevents flicker).
1787 if (count > vc->vc_rows) /* Maximum realistic size */
1788 count = vc->vc_rows;
1790 fbcon_softback_note(vc, t, count);
1791 if (logo_shown >= 0)
1793 switch (p->scrollmode) {
1795 ops->bmove(vc, info, t + count, 0, t, 0,
1796 b - t - count, vc->vc_cols);
1797 ops->clear(vc, info, b - count, 0, count,
1801 case SCROLL_WRAP_MOVE:
1802 if (b - t - count > 3 * vc->vc_rows >> 2) {
1804 fbcon_bmove(vc, 0, 0, count, 0, t,
1806 ywrap_up(vc, count);
1807 if (vc->vc_rows - b > 0)
1808 fbcon_bmove(vc, b - count, 0, b, 0,
1811 } else if (info->flags & FBINFO_READS_FAST)
1812 fbcon_bmove(vc, t + count, 0, t, 0,
1813 b - t - count, vc->vc_cols);
1816 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1819 case SCROLL_PAN_REDRAW:
1820 if ((p->yscroll + count <=
1821 2 * (p->vrows - vc->vc_rows))
1822 && ((!scroll_partial && (b - t == vc->vc_rows))
1825 3 * vc->vc_rows >> 2)))) {
1827 fbcon_redraw_move(vc, p, 0, t, count);
1828 ypan_up_redraw(vc, t, count);
1829 if (vc->vc_rows - b > 0)
1830 fbcon_redraw_move(vc, p, b,
1831 vc->vc_rows - b, b);
1833 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1834 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1837 case SCROLL_PAN_MOVE:
1838 if ((p->yscroll + count <=
1839 2 * (p->vrows - vc->vc_rows))
1840 && ((!scroll_partial && (b - t == vc->vc_rows))
1843 3 * vc->vc_rows >> 2)))) {
1845 fbcon_bmove(vc, 0, 0, count, 0, t,
1848 if (vc->vc_rows - b > 0)
1849 fbcon_bmove(vc, b - count, 0, b, 0,
1852 } else if (info->flags & FBINFO_READS_FAST)
1853 fbcon_bmove(vc, t + count, 0, t, 0,
1854 b - t - count, vc->vc_cols);
1857 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1862 fbcon_redraw(vc, p, t, b - t - count,
1863 count * vc->vc_cols);
1864 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1865 scr_memsetw((unsigned short *) (vc->vc_origin +
1868 vc->vc_video_erase_char,
1869 vc->vc_size_row * count);
1875 if (count > vc->vc_rows) /* Maximum realistic size */
1876 count = vc->vc_rows;
1877 if (logo_shown >= 0)
1879 switch (p->scrollmode) {
1881 ops->bmove(vc, info, t, 0, t + count, 0,
1882 b - t - count, vc->vc_cols);
1883 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1886 case SCROLL_WRAP_MOVE:
1887 if (b - t - count > 3 * vc->vc_rows >> 2) {
1888 if (vc->vc_rows - b > 0)
1889 fbcon_bmove(vc, b, 0, b - count, 0,
1892 ywrap_down(vc, count);
1894 fbcon_bmove(vc, count, 0, 0, 0, t,
1896 } else if (info->flags & FBINFO_READS_FAST)
1897 fbcon_bmove(vc, t, 0, t + count, 0,
1898 b - t - count, vc->vc_cols);
1901 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1904 case SCROLL_PAN_MOVE:
1905 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1906 && ((!scroll_partial && (b - t == vc->vc_rows))
1909 3 * vc->vc_rows >> 2)))) {
1910 if (vc->vc_rows - b > 0)
1911 fbcon_bmove(vc, b, 0, b - count, 0,
1914 ypan_down(vc, count);
1916 fbcon_bmove(vc, count, 0, 0, 0, t,
1918 } else if (info->flags & FBINFO_READS_FAST)
1919 fbcon_bmove(vc, t, 0, t + count, 0,
1920 b - t - count, vc->vc_cols);
1923 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1926 case SCROLL_PAN_REDRAW:
1927 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1928 && ((!scroll_partial && (b - t == vc->vc_rows))
1931 3 * vc->vc_rows >> 2)))) {
1932 if (vc->vc_rows - b > 0)
1933 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1935 ypan_down_redraw(vc, t, count);
1937 fbcon_redraw_move(vc, p, count, t, 0);
1939 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1940 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1945 fbcon_redraw(vc, p, b - 1, b - t - count,
1946 -count * vc->vc_cols);
1947 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1948 scr_memsetw((unsigned short *) (vc->vc_origin +
1951 vc->vc_video_erase_char,
1952 vc->vc_size_row * count);
1960 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1961 int height, int width)
1963 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1964 struct display *p = &fb_display[vc->vc_num];
1966 if (fbcon_is_inactive(vc, info))
1969 if (!width || !height)
1972 /* Split blits that cross physical y_wrap case.
1973 * Pathological case involves 4 blits, better to use recursive
1974 * code rather than unrolled case
1976 * Recursive invocations don't need to erase the cursor over and
1977 * over again, so we use fbcon_bmove_rec()
1979 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1980 p->vrows - p->yscroll);
1983 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1984 int dy, int dx, int height, int width, u_int y_break)
1986 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1987 struct fbcon_ops *ops = info->fbcon_par;
1990 if (sy < y_break && sy + height > y_break) {
1992 if (dy < sy) { /* Avoid trashing self */
1993 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1995 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1996 height - b, width, y_break);
1998 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1999 height - b, width, y_break);
2000 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2006 if (dy < y_break && dy + height > y_break) {
2008 if (dy < sy) { /* Avoid trashing self */
2009 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2011 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2012 height - b, width, y_break);
2014 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2015 height - b, width, y_break);
2016 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2021 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2025 static __inline__ void updatescrollmode(struct display *p,
2026 struct fb_info *info,
2029 struct fbcon_ops *ops = info->fbcon_par;
2030 int fh = vc->vc_font.height;
2031 int cap = info->flags;
2033 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2034 info->fix.xpanstep);
2035 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2036 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2037 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2038 info->var.xres_virtual);
2039 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2040 divides(ypan, vc->vc_font.height) && vyres > yres;
2041 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2042 divides(ywrap, vc->vc_font.height) &&
2043 divides(vc->vc_font.height, vyres) &&
2044 divides(vc->vc_font.height, yres);
2045 int reading_fast = cap & FBINFO_READS_FAST;
2046 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2047 !(cap & FBINFO_HWACCEL_DISABLED);
2048 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2049 !(cap & FBINFO_HWACCEL_DISABLED);
2051 p->vrows = vyres/fh;
2052 if (yres > (fh * (vc->vc_rows + 1)))
2053 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2054 if ((yres % fh) && (vyres % fh < yres % fh))
2057 if (good_wrap || good_pan) {
2058 if (reading_fast || fast_copyarea)
2059 p->scrollmode = good_wrap ?
2060 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2062 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2065 if (reading_fast || (fast_copyarea && !fast_imageblit))
2066 p->scrollmode = SCROLL_MOVE;
2068 p->scrollmode = SCROLL_REDRAW;
2072 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2073 unsigned int height)
2075 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2076 struct fbcon_ops *ops = info->fbcon_par;
2077 struct display *p = &fb_display[vc->vc_num];
2078 struct fb_var_screeninfo var = info->var;
2079 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2081 virt_w = FBCON_SWAP(ops->rotate, width, height);
2082 virt_h = FBCON_SWAP(ops->rotate, height, width);
2083 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2084 vc->vc_font.height);
2085 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2087 var.xres = virt_w * virt_fw;
2088 var.yres = virt_h * virt_fh;
2089 x_diff = info->var.xres - var.xres;
2090 y_diff = info->var.yres - var.yres;
2091 if (x_diff < 0 || x_diff > virt_fw ||
2092 y_diff < 0 || y_diff > virt_fh) {
2093 const struct fb_videomode *mode;
2095 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2096 mode = fb_find_best_mode(&var, &info->modelist);
2099 display_to_var(&var, p);
2100 fb_videomode_to_var(&var, mode);
2102 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2105 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2106 if (CON_IS_VISIBLE(vc)) {
2107 var.activate = FB_ACTIVATE_NOW |
2109 fb_set_var(info, &var);
2111 var_to_display(p, &info->var, info);
2112 ops->var = info->var;
2114 updatescrollmode(p, info, vc);
2118 static int fbcon_switch(struct vc_data *vc)
2120 struct fb_info *info, *old_info = NULL;
2121 struct fbcon_ops *ops;
2122 struct display *p = &fb_display[vc->vc_num];
2123 struct fb_var_screeninfo var;
2124 int i, prev_console, charcnt = 256;
2126 info = registered_fb[con2fb_map[vc->vc_num]];
2127 ops = info->fbcon_par;
2131 fbcon_set_origin(vc);
2132 softback_top = softback_curr = softback_in = softback_buf;
2134 fbcon_update_softback(vc);
2137 if (logo_shown >= 0) {
2138 struct vc_data *conp2 = vc_cons[logo_shown].d;
2140 if (conp2->vc_top == logo_lines
2141 && conp2->vc_bottom == conp2->vc_rows)
2143 logo_shown = FBCON_LOGO_CANSHOW;
2146 prev_console = ops->currcon;
2147 if (prev_console != -1)
2148 old_info = registered_fb[con2fb_map[prev_console]];
2150 * FIXME: If we have multiple fbdev's loaded, we need to
2151 * update all info->currcon. Perhaps, we can place this
2152 * in a centralized structure, but this might break some
2155 * info->currcon = vc->vc_num;
2157 for (i = 0; i < FB_MAX; i++) {
2158 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2159 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2161 o->currcon = vc->vc_num;
2164 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2165 display_to_var(&var, p);
2166 var.activate = FB_ACTIVATE_NOW;
2169 * make sure we don't unnecessarily trip the memcmp()
2172 info->var.activate = var.activate;
2173 var.yoffset = info->var.yoffset;
2174 var.xoffset = info->var.xoffset;
2175 var.vmode = info->var.vmode;
2176 fb_set_var(info, &var);
2177 ops->var = info->var;
2179 if (old_info != NULL && (old_info != info ||
2180 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2181 if (info->fbops->fb_set_par)
2182 info->fbops->fb_set_par(info);
2184 if (old_info != info)
2185 fbcon_del_cursor_timer(old_info);
2188 if (fbcon_is_inactive(vc, info) ||
2189 ops->blank_state != FB_BLANK_UNBLANK)
2190 fbcon_del_cursor_timer(info);
2192 fbcon_add_cursor_timer(info);
2194 set_blitting_type(vc, info);
2195 ops->cursor_reset = 1;
2197 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2198 ops->rotate = FB_ROTATE_UR;
2199 set_blitting_type(vc, info);
2202 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2203 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2206 charcnt = FNTCHARCNT(vc->vc_font.data);
2209 vc->vc_complement_mask <<= 1;
2211 updatescrollmode(p, info, vc);
2213 switch (p->scrollmode) {
2214 case SCROLL_WRAP_MOVE:
2215 scrollback_phys_max = p->vrows - vc->vc_rows;
2217 case SCROLL_PAN_MOVE:
2218 case SCROLL_PAN_REDRAW:
2219 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2220 if (scrollback_phys_max < 0)
2221 scrollback_phys_max = 0;
2224 scrollback_phys_max = 0;
2229 scrollback_current = 0;
2231 if (!fbcon_is_inactive(vc, info)) {
2232 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2233 ops->update_start(info);
2236 fbcon_set_palette(vc, color_table);
2237 fbcon_clear_margins(vc, 0);
2239 if (logo_shown == FBCON_LOGO_DRAW) {
2241 logo_shown = fg_console;
2242 /* This is protected above by initmem_freed */
2243 fb_show_logo(info, ops->rotate);
2245 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2246 vc->vc_size_row * (vc->vc_bottom -
2253 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2256 struct fb_event event;
2259 unsigned short charmask = vc->vc_hi_font_mask ?
2261 unsigned short oldc;
2263 oldc = vc->vc_video_erase_char;
2264 vc->vc_video_erase_char &= charmask;
2265 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2266 vc->vc_video_erase_char = oldc;
2271 event.data = ␣
2272 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2275 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2277 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2278 struct fbcon_ops *ops = info->fbcon_par;
2281 struct fb_var_screeninfo var = info->var;
2286 if (info->fbops->fb_save_state)
2287 info->fbops->fb_save_state(info);
2288 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2289 fb_set_var(info, &var);
2291 ops->var = info->var;
2292 } else if (info->fbops->fb_restore_state)
2293 info->fbops->fb_restore_state(info);
2296 if (!fbcon_is_inactive(vc, info)) {
2297 if (ops->blank_state != blank) {
2298 ops->blank_state = blank;
2299 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2300 ops->cursor_flash = (!blank);
2302 if (fb_blank(info, blank))
2303 fbcon_generic_blank(vc, info, blank);
2310 if (fbcon_is_inactive(vc, info) ||
2311 ops->blank_state != FB_BLANK_UNBLANK)
2312 fbcon_del_cursor_timer(info);
2314 fbcon_add_cursor_timer(info);
2319 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2321 u8 *fontdata = vc->vc_font.data;
2322 u8 *data = font->data;
2325 font->width = vc->vc_font.width;
2326 font->height = vc->vc_font.height;
2327 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2331 if (font->width <= 8) {
2332 j = vc->vc_font.height;
2333 for (i = 0; i < font->charcount; i++) {
2334 memcpy(data, fontdata, j);
2335 memset(data + j, 0, 32 - j);
2339 } else if (font->width <= 16) {
2340 j = vc->vc_font.height * 2;
2341 for (i = 0; i < font->charcount; i++) {
2342 memcpy(data, fontdata, j);
2343 memset(data + j, 0, 64 - j);
2347 } else if (font->width <= 24) {
2348 for (i = 0; i < font->charcount; i++) {
2349 for (j = 0; j < vc->vc_font.height; j++) {
2350 *data++ = fontdata[0];
2351 *data++ = fontdata[1];
2352 *data++ = fontdata[2];
2353 fontdata += sizeof(u32);
2355 memset(data, 0, 3 * (32 - j));
2356 data += 3 * (32 - j);
2359 j = vc->vc_font.height * 4;
2360 for (i = 0; i < font->charcount; i++) {
2361 memcpy(data, fontdata, j);
2362 memset(data + j, 0, 128 - j);
2370 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2371 const u8 * data, int userfont)
2373 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2374 struct fbcon_ops *ops = info->fbcon_par;
2375 struct display *p = &fb_display[vc->vc_num];
2378 char *old_data = NULL;
2380 if (CON_IS_VISIBLE(vc) && softback_lines)
2381 fbcon_set_origin(vc);
2383 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2385 old_data = vc->vc_font.data;
2387 cnt = FNTCHARCNT(data);
2390 vc->vc_font.data = (void *)(p->fontdata = data);
2391 if ((p->userfont = userfont))
2393 vc->vc_font.width = w;
2394 vc->vc_font.height = h;
2395 if (vc->vc_hi_font_mask && cnt == 256) {
2396 vc->vc_hi_font_mask = 0;
2397 if (vc->vc_can_do_color) {
2398 vc->vc_complement_mask >>= 1;
2399 vc->vc_s_complement_mask >>= 1;
2402 /* ++Edmund: reorder the attribute bits */
2403 if (vc->vc_can_do_color) {
2404 unsigned short *cp =
2405 (unsigned short *) vc->vc_origin;
2406 int count = vc->vc_screenbuf_size / 2;
2408 for (; count > 0; count--, cp++) {
2410 scr_writew(((c & 0xfe00) >> 1) |
2413 c = vc->vc_video_erase_char;
2414 vc->vc_video_erase_char =
2415 ((c & 0xfe00) >> 1) | (c & 0xff);
2418 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2419 vc->vc_hi_font_mask = 0x100;
2420 if (vc->vc_can_do_color) {
2421 vc->vc_complement_mask <<= 1;
2422 vc->vc_s_complement_mask <<= 1;
2425 /* ++Edmund: reorder the attribute bits */
2427 unsigned short *cp =
2428 (unsigned short *) vc->vc_origin;
2429 int count = vc->vc_screenbuf_size / 2;
2431 for (; count > 0; count--, cp++) {
2432 unsigned short newc;
2434 if (vc->vc_can_do_color)
2436 ((c & 0xff00) << 1) | (c &
2440 scr_writew(newc, cp);
2442 c = vc->vc_video_erase_char;
2443 if (vc->vc_can_do_color) {
2444 vc->vc_video_erase_char =
2445 ((c & 0xff00) << 1) | (c & 0xff);
2448 vc->vc_video_erase_char = c & ~0x100;
2456 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2457 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2460 vc_resize(vc, cols, rows);
2461 if (CON_IS_VISIBLE(vc) && softback_buf)
2462 fbcon_update_softback(vc);
2463 } else if (CON_IS_VISIBLE(vc)
2464 && vc->vc_mode == KD_TEXT) {
2465 fbcon_clear_margins(vc, 0);
2469 if (old_data && (--REFCOUNT(old_data) == 0))
2470 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2474 static int fbcon_copy_font(struct vc_data *vc, int con)
2476 struct display *od = &fb_display[con];
2477 struct console_font *f = &vc->vc_font;
2479 if (od->fontdata == f->data)
2480 return 0; /* already the same font... */
2481 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2485 * User asked to set font; we are guaranteed that
2486 * a) width and height are in range 1..32
2487 * b) charcount does not exceed 512
2488 * but lets not assume that, since someone might someday want to use larger
2489 * fonts. And charcount of 512 is small for unicode support.
2491 * However, user space gives the font in 32 rows , regardless of
2492 * actual font height. So a new API is needed if support for larger fonts
2493 * is ever implemented.
2496 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2498 unsigned charcount = font->charcount;
2499 int w = font->width;
2500 int h = font->height;
2503 u8 *new_data, *data = font->data;
2504 int pitch = (font->width+7) >> 3;
2506 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2507 * If not this check should be changed to charcount < 256 */
2508 if (charcount != 256 && charcount != 512)
2511 size = h * pitch * charcount;
2513 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2518 new_data += FONT_EXTRA_WORDS * sizeof(int);
2519 FNTSIZE(new_data) = size;
2520 FNTCHARCNT(new_data) = charcount;
2521 REFCOUNT(new_data) = 0; /* usage counter */
2522 for (i=0; i< charcount; i++) {
2523 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2526 /* Since linux has a nice crc32 function use it for counting font
2528 csum = crc32(0, new_data, size);
2530 FNTSUM(new_data) = csum;
2531 /* Check if the same font is on some other console already */
2532 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2533 struct vc_data *tmp = vc_cons[i].d;
2535 if (fb_display[i].userfont &&
2536 fb_display[i].fontdata &&
2537 FNTSUM(fb_display[i].fontdata) == csum &&
2538 FNTSIZE(fb_display[i].fontdata) == size &&
2539 tmp->vc_font.width == w &&
2540 !memcmp(fb_display[i].fontdata, new_data, size)) {
2541 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2542 new_data = (u8 *)fb_display[i].fontdata;
2546 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2549 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2551 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2552 const struct font_desc *f;
2555 f = get_default_font(info->var.xres, info->var.yres);
2556 else if (!(f = find_font(name)))
2559 font->width = f->width;
2560 font->height = f->height;
2561 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2564 static u16 palette_red[16];
2565 static u16 palette_green[16];
2566 static u16 palette_blue[16];
2568 static struct fb_cmap palette_cmap = {
2569 0, 16, palette_red, palette_green, palette_blue, NULL
2572 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2574 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2578 if (fbcon_is_inactive(vc, info))
2581 if (!CON_IS_VISIBLE(vc))
2584 depth = fb_get_color_depth(&info->var, &info->fix);
2586 for (i = j = 0; i < 16; i++) {
2588 val = vc->vc_palette[j++];
2589 palette_red[k] = (val << 8) | val;
2590 val = vc->vc_palette[j++];
2591 palette_green[k] = (val << 8) | val;
2592 val = vc->vc_palette[j++];
2593 palette_blue[k] = (val << 8) | val;
2595 palette_cmap.len = 16;
2596 palette_cmap.start = 0;
2598 * If framebuffer is capable of less than 16 colors,
2599 * use default palette of fbcon.
2602 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2604 return fb_set_cmap(&palette_cmap, info);
2607 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2612 if (vc->vc_num != fg_console || !softback_lines)
2613 return (u16 *) (vc->vc_origin + offset);
2614 line = offset / vc->vc_size_row;
2615 if (line >= softback_lines)
2616 return (u16 *) (vc->vc_origin + offset -
2617 softback_lines * vc->vc_size_row);
2618 p = softback_curr + offset;
2619 if (p >= softback_end)
2620 p += softback_buf - softback_end;
2624 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2630 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2631 unsigned long offset = (pos - vc->vc_origin) / 2;
2633 x = offset % vc->vc_cols;
2634 y = offset / vc->vc_cols;
2635 if (vc->vc_num == fg_console)
2636 y += softback_lines;
2637 ret = pos + (vc->vc_cols - x) * 2;
2638 } else if (vc->vc_num == fg_console && softback_lines) {
2639 unsigned long offset = pos - softback_curr;
2641 if (pos < softback_curr)
2642 offset += softback_end - softback_buf;
2644 x = offset % vc->vc_cols;
2645 y = offset / vc->vc_cols;
2646 ret = pos + (vc->vc_cols - x) * 2;
2647 if (ret == softback_end)
2649 if (ret == softback_in)
2650 ret = vc->vc_origin;
2652 /* Should not happen */
2654 ret = vc->vc_origin;
2663 /* As we might be inside of softback, we may work with non-contiguous buffer,
2664 that's why we have to use a separate routine. */
2665 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2668 u16 a = scr_readw(p);
2669 if (!vc->vc_can_do_color)
2671 else if (vc->vc_hi_font_mask == 0x100)
2672 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2673 (((a) & 0x0e00) << 4);
2675 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2676 (((a) & 0x0700) << 4);
2678 if (p == (u16 *) softback_end)
2679 p = (u16 *) softback_buf;
2680 if (p == (u16 *) softback_in)
2681 p = (u16 *) vc->vc_origin;
2685 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2687 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2688 struct fbcon_ops *ops = info->fbcon_par;
2689 struct display *p = &fb_display[fg_console];
2690 int offset, limit, scrollback_old;
2693 if (vc->vc_num != fg_console)
2695 if (vc->vc_mode != KD_TEXT || !lines)
2697 if (logo_shown >= 0) {
2698 struct vc_data *conp2 = vc_cons[logo_shown].d;
2700 if (conp2->vc_top == logo_lines
2701 && conp2->vc_bottom == conp2->vc_rows)
2703 if (logo_shown == vc->vc_num) {
2709 logo_lines * vc->vc_size_row;
2710 for (i = 0; i < logo_lines; i++) {
2711 if (p == softback_top)
2713 if (p == softback_buf)
2715 p -= vc->vc_size_row;
2716 q -= vc->vc_size_row;
2717 scr_memcpyw((u16 *) q, (u16 *) p,
2720 softback_in = softback_curr = p;
2721 update_region(vc, vc->vc_origin,
2722 logo_lines * vc->vc_cols);
2724 logo_shown = FBCON_LOGO_CANSHOW;
2726 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2727 fbcon_redraw_softback(vc, p, lines);
2728 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2732 if (!scrollback_phys_max)
2735 scrollback_old = scrollback_current;
2736 scrollback_current -= lines;
2737 if (scrollback_current < 0)
2738 scrollback_current = 0;
2739 else if (scrollback_current > scrollback_max)
2740 scrollback_current = scrollback_max;
2741 if (scrollback_current == scrollback_old)
2744 if (fbcon_is_inactive(vc, info))
2747 fbcon_cursor(vc, CM_ERASE);
2749 offset = p->yscroll - scrollback_current;
2751 switch (p->scrollmode) {
2752 case SCROLL_WRAP_MOVE:
2753 info->var.vmode |= FB_VMODE_YWRAP;
2755 case SCROLL_PAN_MOVE:
2756 case SCROLL_PAN_REDRAW:
2757 limit -= vc->vc_rows;
2758 info->var.vmode &= ~FB_VMODE_YWRAP;
2763 else if (offset >= limit)
2766 ops->var.xoffset = 0;
2767 ops->var.yoffset = offset * vc->vc_font.height;
2768 ops->update_start(info);
2770 if (!scrollback_current)
2771 fbcon_cursor(vc, CM_DRAW);
2775 static int fbcon_set_origin(struct vc_data *vc)
2778 fbcon_scrolldelta(vc, softback_lines);
2782 static void fbcon_suspended(struct fb_info *info)
2784 struct vc_data *vc = NULL;
2785 struct fbcon_ops *ops = info->fbcon_par;
2787 if (!ops || ops->currcon < 0)
2789 vc = vc_cons[ops->currcon].d;
2791 /* Clear cursor, restore saved data */
2792 fbcon_cursor(vc, CM_ERASE);
2795 static void fbcon_resumed(struct fb_info *info)
2798 struct fbcon_ops *ops = info->fbcon_par;
2800 if (!ops || ops->currcon < 0)
2802 vc = vc_cons[ops->currcon].d;
2807 static void fbcon_modechanged(struct fb_info *info)
2809 struct fbcon_ops *ops = info->fbcon_par;
2814 if (!ops || ops->currcon < 0)
2816 vc = vc_cons[ops->currcon].d;
2817 if (vc->vc_mode != KD_TEXT ||
2818 registered_fb[con2fb_map[ops->currcon]] != info)
2821 p = &fb_display[vc->vc_num];
2822 set_blitting_type(vc, info);
2824 if (CON_IS_VISIBLE(vc)) {
2825 var_to_display(p, &info->var, info);
2826 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2827 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2828 cols /= vc->vc_font.width;
2829 rows /= vc->vc_font.height;
2830 vc_resize(vc, cols, rows);
2831 updatescrollmode(p, info, vc);
2833 scrollback_current = 0;
2835 if (!fbcon_is_inactive(vc, info)) {
2836 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2837 ops->update_start(info);
2840 fbcon_set_palette(vc, color_table);
2843 fbcon_update_softback(vc);
2847 static void fbcon_set_all_vcs(struct fb_info *info)
2849 struct fbcon_ops *ops = info->fbcon_par;
2854 if (!ops || ops->currcon < 0)
2857 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2859 if (!vc || vc->vc_mode != KD_TEXT ||
2860 registered_fb[con2fb_map[i]] != info)
2863 p = &fb_display[vc->vc_num];
2864 set_blitting_type(vc, info);
2865 var_to_display(p, &info->var, info);
2866 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2867 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2868 cols /= vc->vc_font.width;
2869 rows /= vc->vc_font.height;
2870 vc_resize(vc, cols, rows);
2872 if (CON_IS_VISIBLE(vc)) {
2873 updatescrollmode(p, info, vc);
2875 scrollback_current = 0;
2877 if (!fbcon_is_inactive(vc, info)) {
2878 ops->var.xoffset = ops->var.yoffset =
2880 ops->update_start(info);
2883 fbcon_set_palette(vc, color_table);
2886 fbcon_update_softback(vc);
2890 ops->p = &fb_display[ops->currcon];
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");