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 */
80 #include <asm/system.h>
82 #include <asm/atariints.h>
85 #include <asm/macints.h>
87 #if defined(__mc68000__)
88 #include <asm/machdep.h>
89 #include <asm/setup.h>
95 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## 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_lines;
112 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
114 static int logo_shown = FBCON_LOGO_CANSHOW;
115 /* Software scrollback */
116 static int fbcon_softback_size = 32768;
117 static unsigned long softback_buf, softback_curr;
118 static unsigned long softback_in;
119 static unsigned long softback_top, softback_end;
120 static int softback_lines;
121 /* console mappings */
122 static int first_fb_vc;
123 static int last_fb_vc = MAX_NR_CONSOLES - 1;
124 static int fbcon_is_default = 1;
125 static int fbcon_has_exited;
126 static int primary_device = -1;
128 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
129 static int map_override;
131 static inline void fbcon_map_override(void)
136 static inline void fbcon_map_override(void)
139 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
142 static char fontname[40];
144 /* current fb_info */
145 static int info_idx = -1;
147 /* console rotation */
148 static int initial_rotation;
149 static int fbcon_has_sysfs;
151 static const struct consw fb_con;
153 #define CM_SOFTBACK (8)
155 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
157 static int fbcon_set_origin(struct vc_data *);
159 #define CURSOR_DRAW_DELAY (1)
161 /* # VBL ints between cursor state changes */
162 #define ATARI_CURSOR_BLINK_RATE (42)
163 #define MAC_CURSOR_BLINK_RATE (32)
164 #define DEFAULT_CURSOR_BLINK_RATE (20)
166 static int vbl_cursor_cnt;
167 static int fbcon_cursor_noblink;
169 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
172 * Interface used by the world
175 static const char *fbcon_startup(void);
176 static void fbcon_init(struct vc_data *vc, int init);
177 static void fbcon_deinit(struct vc_data *vc);
178 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
180 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
181 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
182 int count, int ypos, int xpos);
183 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
184 static void fbcon_cursor(struct vc_data *vc, int mode);
185 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
187 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
188 int height, int width);
189 static int fbcon_switch(struct vc_data *vc);
190 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
191 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
192 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
197 static __inline__ void ywrap_up(struct vc_data *vc, int count);
198 static __inline__ void ywrap_down(struct vc_data *vc, int count);
199 static __inline__ void ypan_up(struct vc_data *vc, int count);
200 static __inline__ void ypan_down(struct vc_data *vc, int count);
201 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
202 int dy, int dx, int height, int width, u_int y_break);
203 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
205 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
206 int line, int count, int dy);
207 static void fbcon_modechanged(struct fb_info *info);
208 static void fbcon_set_all_vcs(struct fb_info *info);
209 static void fbcon_start(void);
210 static void fbcon_exit(void);
211 static struct device *fbcon_device;
215 * On the Macintoy, there may or may not be a working VBL int. We need to probe
217 static int vbl_detected;
219 static irqreturn_t fb_vbl_detect(int irq, void *dummy)
226 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
227 static inline void fbcon_set_rotation(struct fb_info *info)
229 struct fbcon_ops *ops = info->fbcon_par;
231 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
232 ops->p->con_rotate < 4)
233 ops->rotate = ops->p->con_rotate;
238 static void fbcon_rotate(struct fb_info *info, u32 rotate)
240 struct fbcon_ops *ops= info->fbcon_par;
241 struct fb_info *fb_info;
243 if (!ops || ops->currcon == -1)
246 fb_info = registered_fb[con2fb_map[ops->currcon]];
248 if (info == fb_info) {
249 struct display *p = &fb_display[ops->currcon];
252 p->con_rotate = rotate;
256 fbcon_modechanged(info);
260 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
262 struct fbcon_ops *ops = info->fbcon_par;
267 if (!ops || ops->currcon < 0 || rotate > 3)
270 for (i = first_fb_vc; i <= last_fb_vc; i++) {
272 if (!vc || vc->vc_mode != KD_TEXT ||
273 registered_fb[con2fb_map[i]] != info)
276 p = &fb_display[vc->vc_num];
277 p->con_rotate = rotate;
280 fbcon_set_all_vcs(info);
283 static inline void fbcon_set_rotation(struct fb_info *info)
285 struct fbcon_ops *ops = info->fbcon_par;
287 ops->rotate = FB_ROTATE_UR;
290 static void fbcon_rotate(struct fb_info *info, u32 rotate)
295 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
299 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
301 static int fbcon_get_rotate(struct fb_info *info)
303 struct fbcon_ops *ops = info->fbcon_par;
305 return (ops) ? ops->rotate : 0;
308 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
310 struct fbcon_ops *ops = info->fbcon_par;
312 return (info->state != FBINFO_STATE_RUNNING ||
313 vc->vc_mode != KD_TEXT || ops->graphics);
316 static inline int get_color(struct vc_data *vc, struct fb_info *info,
319 int depth = fb_get_color_depth(&info->var, &info->fix);
322 if (console_blanked) {
323 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
325 c = vc->vc_video_erase_char & charmask;
329 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
330 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
335 int col = mono_col(info);
337 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
338 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
343 color = (is_fg) ? fg : bg;
348 * Scale down 16-colors to 4 colors. Default 4-color palette
349 * is grayscale. However, simply dividing the values by 4
350 * will not work, as colors 1, 2 and 3 will be scaled-down
351 * to zero rendering them invisible. So empirically convert
352 * colors to a sane 4-level grayscale.
356 color = 0; /* black */
359 color = 2; /* white */
362 color = 1; /* gray */
365 color = 3; /* intense white */
371 * Last 8 entries of default 16-color palette is a more intense
372 * version of the first 8 (i.e., same chrominance, different
383 static void fbcon_update_softback(struct vc_data *vc)
385 int l = fbcon_softback_size / vc->vc_size_row;
388 softback_end = softback_buf + l * vc->vc_size_row;
390 /* Smaller scrollback makes no sense, and 0 would screw
391 the operation totally */
395 static void fb_flashcursor(struct work_struct *work)
397 struct fb_info *info = container_of(work, struct fb_info, queue);
398 struct fbcon_ops *ops = info->fbcon_par;
400 struct vc_data *vc = NULL;
404 acquire_console_sem();
405 if (ops && ops->currcon != -1)
406 vc = vc_cons[ops->currcon].d;
408 if (!vc || !CON_IS_VISIBLE(vc) ||
409 registered_fb[con2fb_map[vc->vc_num]] != info ||
411 release_console_sem();
415 p = &fb_display[vc->vc_num];
416 c = scr_readw((u16 *) vc->vc_pos);
417 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
419 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
420 get_color(vc, info, c, 0));
421 release_console_sem();
424 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
425 static int cursor_blink_rate;
426 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
428 struct fb_info *info = dev_id;
430 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
431 schedule_work(&info->queue);
432 vbl_cursor_cnt = cursor_blink_rate;
438 static void cursor_timer_handler(unsigned long dev_addr)
440 struct fb_info *info = (struct fb_info *) dev_addr;
441 struct fbcon_ops *ops = info->fbcon_par;
443 schedule_work(&info->queue);
444 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
447 static void fbcon_add_cursor_timer(struct fb_info *info)
449 struct fbcon_ops *ops = info->fbcon_par;
451 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
452 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
453 !fbcon_cursor_noblink) {
454 if (!info->queue.func)
455 INIT_WORK(&info->queue, fb_flashcursor);
457 init_timer(&ops->cursor_timer);
458 ops->cursor_timer.function = cursor_timer_handler;
459 ops->cursor_timer.expires = jiffies + HZ / 5;
460 ops->cursor_timer.data = (unsigned long ) info;
461 add_timer(&ops->cursor_timer);
462 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
466 static void fbcon_del_cursor_timer(struct fb_info *info)
468 struct fbcon_ops *ops = info->fbcon_par;
470 if (info->queue.func == fb_flashcursor &&
471 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
472 del_timer_sync(&ops->cursor_timer);
473 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
478 static int __init fb_console_setup(char *this_opt)
483 if (!this_opt || !*this_opt)
486 while ((options = strsep(&this_opt, ",")) != NULL) {
487 if (!strncmp(options, "font:", 5))
488 strcpy(fontname, options + 5);
490 if (!strncmp(options, "scrollback:", 11)) {
493 fbcon_softback_size = simple_strtoul(options, &options, 0);
494 if (*options == 'k' || *options == 'K') {
495 fbcon_softback_size *= 1024;
505 if (!strncmp(options, "map:", 4)) {
508 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
512 (options[j++]-'0') % FB_MAX;
515 fbcon_map_override();
521 if (!strncmp(options, "vc:", 3)) {
524 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
527 if (*options++ == '-')
528 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
529 fbcon_is_default = 0;
532 if (!strncmp(options, "rotate:", 7)) {
535 initial_rotation = simple_strtoul(options, &options, 0);
536 if (initial_rotation > 3)
537 initial_rotation = 0;
543 __setup("fbcon=", fb_console_setup);
546 static int search_fb_in_map(int idx)
550 for (i = first_fb_vc; i <= last_fb_vc; i++) {
551 if (con2fb_map[i] == idx)
557 static int search_for_mapped_con(void)
561 for (i = first_fb_vc; i <= last_fb_vc; i++) {
562 if (con2fb_map[i] != -1)
568 static int fbcon_takeover(int show_logo)
572 if (!num_registered_fb)
576 logo_shown = FBCON_LOGO_DONTSHOW;
578 for (i = first_fb_vc; i <= last_fb_vc; i++)
579 con2fb_map[i] = info_idx;
581 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
585 for (i = first_fb_vc; i <= last_fb_vc; i++) {
595 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
596 int cols, int rows, int new_cols, int new_rows)
598 logo_shown = FBCON_LOGO_DONTSHOW;
601 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
602 int cols, int rows, int new_cols, int new_rows)
604 /* Need to make room for the logo */
605 struct fbcon_ops *ops = info->fbcon_par;
606 int cnt, erase = vc->vc_video_erase_char, step;
607 unsigned short *save = NULL, *r, *q;
610 if (info->flags & FBINFO_MODULE) {
611 logo_shown = FBCON_LOGO_DONTSHOW;
616 * remove underline attribute from erase character
617 * if black and white framebuffer.
619 if (fb_get_color_depth(&info->var, &info->fix) == 1)
621 logo_height = fb_prepare_logo(info, ops->rotate);
622 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
623 q = (unsigned short *) (vc->vc_origin +
624 vc->vc_size_row * rows);
625 step = logo_lines * cols;
626 for (r = q - logo_lines * cols; r < q; r++)
627 if (scr_readw(r) != vc->vc_video_erase_char)
629 if (r != q && new_rows >= rows + logo_lines) {
630 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
632 int i = cols < new_cols ? cols : new_cols;
633 scr_memsetw(save, erase, logo_lines * new_cols * 2);
635 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
636 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
641 /* We can scroll screen down */
643 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
644 scr_memcpyw(r + step, r, vc->vc_size_row);
649 if (vc->vc_y + logo_lines >= rows)
650 lines = rows - vc->vc_y - 1;
654 vc->vc_pos += lines * vc->vc_size_row;
657 scr_memsetw((unsigned short *) vc->vc_origin,
659 vc->vc_size_row * logo_lines);
661 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
662 fbcon_clear_margins(vc, 0);
667 q = (unsigned short *) (vc->vc_origin +
670 scr_memcpyw(q, save, logo_lines * new_cols * 2);
671 vc->vc_y += logo_lines;
672 vc->vc_pos += logo_lines * vc->vc_size_row;
676 if (logo_lines > vc->vc_bottom) {
677 logo_shown = FBCON_LOGO_CANSHOW;
679 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
680 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
681 logo_shown = FBCON_LOGO_DRAW;
682 vc->vc_top = logo_lines;
687 #ifdef CONFIG_FB_TILEBLITTING
688 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
690 struct fbcon_ops *ops = info->fbcon_par;
692 ops->p = &fb_display[vc->vc_num];
694 if ((info->flags & FBINFO_MISC_TILEBLITTING))
695 fbcon_set_tileops(vc, info);
697 fbcon_set_rotation(info);
698 fbcon_set_bitops(ops);
702 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
706 if (info->flags & FBINFO_MISC_TILEBLITTING &&
707 info->tileops->fb_get_tilemax(info) < charcount)
713 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
715 struct fbcon_ops *ops = info->fbcon_par;
717 info->flags &= ~FBINFO_MISC_TILEBLITTING;
718 ops->p = &fb_display[vc->vc_num];
719 fbcon_set_rotation(info);
720 fbcon_set_bitops(ops);
723 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
728 #endif /* CONFIG_MISC_TILEBLITTING */
731 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
732 int unit, int oldidx)
734 struct fbcon_ops *ops = NULL;
737 if (!try_module_get(info->fbops->owner))
740 if (!err && info->fbops->fb_open &&
741 info->fbops->fb_open(info, 0))
745 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
751 info->fbcon_par = ops;
754 set_blitting_type(vc, info);
758 con2fb_map[unit] = oldidx;
759 module_put(info->fbops->owner);
765 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
766 struct fb_info *newinfo, int unit,
767 int oldidx, int found)
769 struct fbcon_ops *ops = oldinfo->fbcon_par;
772 if (oldinfo->fbops->fb_release &&
773 oldinfo->fbops->fb_release(oldinfo, 0)) {
774 con2fb_map[unit] = oldidx;
775 if (!found && newinfo->fbops->fb_release)
776 newinfo->fbops->fb_release(newinfo, 0);
778 module_put(newinfo->fbops->owner);
783 fbcon_del_cursor_timer(oldinfo);
784 kfree(ops->cursor_state.mask);
785 kfree(ops->cursor_data);
786 kfree(ops->fontbuffer);
787 kfree(oldinfo->fbcon_par);
788 oldinfo->fbcon_par = NULL;
789 module_put(oldinfo->fbops->owner);
791 If oldinfo and newinfo are driving the same hardware,
792 the fb_release() method of oldinfo may attempt to
793 restore the hardware state. This will leave the
794 newinfo in an undefined state. Thus, a call to
795 fb_set_par() may be needed for the newinfo.
797 if (newinfo->fbops->fb_set_par)
798 newinfo->fbops->fb_set_par(newinfo);
804 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
805 int unit, int show_logo)
807 struct fbcon_ops *ops = info->fbcon_par;
809 ops->currcon = fg_console;
811 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
812 info->fbops->fb_set_par(info);
814 ops->flags |= FBCON_FLAGS_INIT;
816 fbcon_set_disp(info, &info->var, unit);
819 struct vc_data *fg_vc = vc_cons[fg_console].d;
820 struct fb_info *fg_info =
821 registered_fb[con2fb_map[fg_console]];
823 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
824 fg_vc->vc_rows, fg_vc->vc_cols,
828 update_screen(vc_cons[fg_console].d);
832 * set_con2fb_map - map console to frame buffer device
833 * @unit: virtual console number to map
834 * @newidx: frame buffer index to map virtual console to
835 * @user: user request
837 * Maps a virtual console @unit to a frame buffer device
840 static int set_con2fb_map(int unit, int newidx, int user)
842 struct vc_data *vc = vc_cons[unit].d;
843 int oldidx = con2fb_map[unit];
844 struct fb_info *info = registered_fb[newidx];
845 struct fb_info *oldinfo = NULL;
848 if (oldidx == newidx)
851 if (!info || fbcon_has_exited)
854 if (!err && !search_for_mapped_con()) {
856 return fbcon_takeover(0);
860 oldinfo = registered_fb[oldidx];
862 found = search_fb_in_map(newidx);
864 acquire_console_sem();
865 con2fb_map[unit] = newidx;
867 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
871 * If old fb is not mapped to any of the consoles,
872 * fbcon should release it.
874 if (!err && oldinfo && !search_fb_in_map(oldidx))
875 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
879 int show_logo = (fg_console == 0 && !user &&
880 logo_shown != FBCON_LOGO_DONTSHOW);
883 fbcon_add_cursor_timer(info);
884 con2fb_map_boot[unit] = newidx;
885 con2fb_init_display(vc, info, unit, show_logo);
888 if (!search_fb_in_map(info_idx))
891 release_console_sem();
896 * Low Level Operations
898 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
899 static int var_to_display(struct display *disp,
900 struct fb_var_screeninfo *var,
901 struct fb_info *info)
903 disp->xres_virtual = var->xres_virtual;
904 disp->yres_virtual = var->yres_virtual;
905 disp->bits_per_pixel = var->bits_per_pixel;
906 disp->grayscale = var->grayscale;
907 disp->nonstd = var->nonstd;
908 disp->accel_flags = var->accel_flags;
909 disp->height = var->height;
910 disp->width = var->width;
911 disp->red = var->red;
912 disp->green = var->green;
913 disp->blue = var->blue;
914 disp->transp = var->transp;
915 disp->rotate = var->rotate;
916 disp->mode = fb_match_mode(var, &info->modelist);
917 if (disp->mode == NULL)
918 /* This should not happen */
923 static void display_to_var(struct fb_var_screeninfo *var,
924 struct display *disp)
926 fb_videomode_to_var(var, disp->mode);
927 var->xres_virtual = disp->xres_virtual;
928 var->yres_virtual = disp->yres_virtual;
929 var->bits_per_pixel = disp->bits_per_pixel;
930 var->grayscale = disp->grayscale;
931 var->nonstd = disp->nonstd;
932 var->accel_flags = disp->accel_flags;
933 var->height = disp->height;
934 var->width = disp->width;
935 var->red = disp->red;
936 var->green = disp->green;
937 var->blue = disp->blue;
938 var->transp = disp->transp;
939 var->rotate = disp->rotate;
942 static const char *fbcon_startup(void)
944 const char *display_desc = "frame buffer device";
945 struct display *p = &fb_display[fg_console];
946 struct vc_data *vc = vc_cons[fg_console].d;
947 const struct font_desc *font = NULL;
948 struct module *owner;
949 struct fb_info *info = NULL;
950 struct fbcon_ops *ops;
956 * If num_registered_fb is zero, this is a call for the dummy part.
957 * The frame buffer devices weren't initialized yet.
959 if (!num_registered_fb || info_idx == -1)
962 * Instead of blindly using registered_fb[0], we use info_idx, set by
965 info = registered_fb[info_idx];
969 owner = info->fbops->owner;
970 if (!try_module_get(owner))
972 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
977 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
985 ops->cur_rotate = -1;
986 info->fbcon_par = ops;
987 p->con_rotate = initial_rotation;
988 set_blitting_type(vc, info);
990 if (info->fix.type != FB_TYPE_TEXT) {
991 if (fbcon_softback_size) {
995 kmalloc(fbcon_softback_size,
998 fbcon_softback_size = 0;
1004 kfree((void *) softback_buf);
1010 softback_in = softback_top = softback_curr =
1015 /* Setup default font */
1017 if (!fontname[0] || !(font = find_font(fontname)))
1018 font = get_default_font(info->var.xres,
1020 info->pixmap.blit_x,
1021 info->pixmap.blit_y);
1022 vc->vc_font.width = font->width;
1023 vc->vc_font.height = font->height;
1024 vc->vc_font.data = (void *)(p->fontdata = font->data);
1025 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1028 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1029 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1030 cols /= vc->vc_font.width;
1031 rows /= vc->vc_font.height;
1032 vc_resize(vc, cols, rows);
1034 DPRINTK("mode: %s\n", info->fix.id);
1035 DPRINTK("visual: %d\n", info->fix.visual);
1036 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1038 info->var.bits_per_pixel);
1041 if (MACH_IS_ATARI) {
1042 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1044 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1045 IRQ_TYPE_PRIO, "framebuffer vbl",
1048 #endif /* CONFIG_ATARI */
1052 * On a Macintoy, the VBL interrupt may or may not be active.
1053 * As interrupt based cursor is more reliable and race free, we
1054 * probe for VBL interrupts.
1059 * Probe for VBL: set temp. handler ...
1061 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1062 "framebuffer vbl", info);
1066 * ... and spin for 20 ms ...
1068 while (!vbl_detected && ++ct < 1000)
1073 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1075 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1079 * interrupt based cursor ok
1081 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1083 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1084 "framebuffer vbl", info);
1087 * VBL not detected: fall through, use timer based cursor
1092 #endif /* CONFIG_MAC */
1094 fbcon_add_cursor_timer(info);
1095 fbcon_has_exited = 0;
1096 return display_desc;
1099 static void fbcon_init(struct vc_data *vc, int init)
1101 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1102 struct fbcon_ops *ops;
1103 struct vc_data **default_mode = vc->vc_display_fg;
1104 struct vc_data *svc = *default_mode;
1105 struct display *t, *p = &fb_display[vc->vc_num];
1106 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1109 if (info_idx == -1 || info == NULL)
1114 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1115 (info->fix.type == FB_TYPE_TEXT))
1118 if (var_to_display(p, &info->var, info))
1121 if (!info->fbcon_par)
1122 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1124 /* If we are not the first console on this
1125 fb, copy the font from that console */
1126 t = &fb_display[fg_console];
1129 struct vc_data *fvc = vc_cons[fg_console].d;
1131 vc->vc_font.data = (void *)(p->fontdata =
1133 vc->vc_font.width = fvc->vc_font.width;
1134 vc->vc_font.height = fvc->vc_font.height;
1135 p->userfont = t->userfont;
1138 REFCOUNT(p->fontdata)++;
1140 const struct font_desc *font = NULL;
1142 if (!fontname[0] || !(font = find_font(fontname)))
1143 font = get_default_font(info->var.xres,
1145 info->pixmap.blit_x,
1146 info->pixmap.blit_y);
1147 vc->vc_font.width = font->width;
1148 vc->vc_font.height = font->height;
1149 vc->vc_font.data = (void *)(p->fontdata = font->data);
1150 vc->vc_font.charcount = 256; /* FIXME Need to
1151 support more fonts */
1156 charcnt = FNTCHARCNT(p->fontdata);
1158 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1159 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1160 if (charcnt == 256) {
1161 vc->vc_hi_font_mask = 0;
1163 vc->vc_hi_font_mask = 0x100;
1164 if (vc->vc_can_do_color)
1165 vc->vc_complement_mask <<= 1;
1168 if (!*svc->vc_uni_pagedir_loc)
1169 con_set_default_unimap(svc);
1170 if (!*vc->vc_uni_pagedir_loc)
1171 con_copy_unimap(vc, svc);
1173 ops = info->fbcon_par;
1174 p->con_rotate = initial_rotation;
1175 set_blitting_type(vc, info);
1179 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1180 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1181 new_cols /= vc->vc_font.width;
1182 new_rows /= vc->vc_font.height;
1183 vc_resize(vc, new_cols, new_rows);
1186 * We must always set the mode. The mode of the previous console
1187 * driver could be in the same resolution but we are using different
1188 * hardware so we have to initialize the hardware.
1190 * We need to do it in fbcon_init() to prevent screen corruption.
1192 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1193 if (info->fbops->fb_set_par &&
1194 !(ops->flags & FBCON_FLAGS_INIT))
1195 info->fbops->fb_set_par(info);
1196 ops->flags |= FBCON_FLAGS_INIT;
1201 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1202 !(cap & FBINFO_HWACCEL_DISABLED))
1203 p->scrollmode = SCROLL_MOVE;
1204 else /* default to something safe */
1205 p->scrollmode = SCROLL_REDRAW;
1208 * ++guenther: console.c:vc_allocate() relies on initializing
1209 * vc_{cols,rows}, but we must not set those if we are only
1210 * resizing the console.
1213 vc->vc_cols = new_cols;
1214 vc->vc_rows = new_rows;
1218 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1220 if (vc == svc && softback_buf)
1221 fbcon_update_softback(vc);
1223 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1224 ops->rotate = FB_ROTATE_UR;
1225 set_blitting_type(vc, info);
1228 ops->p = &fb_display[fg_console];
1231 static void fbcon_free_font(struct display *p)
1233 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1234 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1239 static void fbcon_deinit(struct vc_data *vc)
1241 struct display *p = &fb_display[vc->vc_num];
1242 struct fb_info *info;
1243 struct fbcon_ops *ops;
1247 idx = con2fb_map[vc->vc_num];
1252 info = registered_fb[idx];
1257 ops = info->fbcon_par;
1262 if (CON_IS_VISIBLE(vc))
1263 fbcon_del_cursor_timer(info);
1265 ops->flags &= ~FBCON_FLAGS_INIT;
1268 if (!con_is_bound(&fb_con))
1274 /* ====================================================================== */
1276 /* fbcon_XXX routines - interface used by the world
1278 * This system is now divided into two levels because of complications
1279 * caused by hardware scrolling. Top level functions:
1281 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1283 * handles y values in range [0, scr_height-1] that correspond to real
1284 * screen positions. y_wrap shift means that first line of bitmap may be
1285 * anywhere on this display. These functions convert lineoffsets to
1286 * bitmap offsets and deal with the wrap-around case by splitting blits.
1288 * fbcon_bmove_physical_8() -- These functions fast implementations
1289 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1290 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1294 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1295 * Implies should only really hardware scroll in rows. Only reason for
1296 * restriction is simplicity & efficiency at the moment.
1299 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1302 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1303 struct fbcon_ops *ops = info->fbcon_par;
1305 struct display *p = &fb_display[vc->vc_num];
1308 if (fbcon_is_inactive(vc, info))
1311 if (!height || !width)
1314 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1317 /* Split blits that cross physical y_wrap boundary */
1319 y_break = p->vrows - p->yscroll;
1320 if (sy < y_break && sy + height - 1 >= y_break) {
1321 u_int b = y_break - sy;
1322 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1323 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1326 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1329 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1330 int count, int ypos, int xpos)
1332 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1333 struct display *p = &fb_display[vc->vc_num];
1334 struct fbcon_ops *ops = info->fbcon_par;
1336 if (!fbcon_is_inactive(vc, info))
1337 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1338 get_color(vc, info, scr_readw(s), 1),
1339 get_color(vc, info, scr_readw(s), 0));
1342 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1346 scr_writew(c, &chr);
1347 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1350 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1352 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1353 struct fbcon_ops *ops = info->fbcon_par;
1355 if (!fbcon_is_inactive(vc, info))
1356 ops->clear_margins(vc, info, bottom_only);
1359 static void fbcon_cursor(struct vc_data *vc, int mode)
1361 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1362 struct fbcon_ops *ops = info->fbcon_par;
1364 int c = scr_readw((u16 *) vc->vc_pos);
1366 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1369 if (vc->vc_cursor_type & 0x10)
1370 fbcon_del_cursor_timer(info);
1372 fbcon_add_cursor_timer(info);
1374 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1375 if (mode & CM_SOFTBACK) {
1376 mode &= ~CM_SOFTBACK;
1380 fbcon_set_origin(vc);
1384 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1385 get_color(vc, info, c, 0));
1386 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1389 static int scrollback_phys_max = 0;
1390 static int scrollback_max = 0;
1391 static int scrollback_current = 0;
1393 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1396 struct display *p, *t;
1397 struct vc_data **default_mode, *vc;
1398 struct vc_data *svc;
1399 struct fbcon_ops *ops = info->fbcon_par;
1400 int rows, cols, charcnt = 256;
1402 p = &fb_display[unit];
1404 if (var_to_display(p, var, info))
1407 vc = vc_cons[unit].d;
1412 default_mode = vc->vc_display_fg;
1413 svc = *default_mode;
1414 t = &fb_display[svc->vc_num];
1416 if (!vc->vc_font.data) {
1417 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1418 vc->vc_font.width = (*default_mode)->vc_font.width;
1419 vc->vc_font.height = (*default_mode)->vc_font.height;
1420 p->userfont = t->userfont;
1422 REFCOUNT(p->fontdata)++;
1425 charcnt = FNTCHARCNT(p->fontdata);
1427 var->activate = FB_ACTIVATE_NOW;
1428 info->var.activate = var->activate;
1429 var->yoffset = info->var.yoffset;
1430 var->xoffset = info->var.xoffset;
1431 fb_set_var(info, var);
1432 ops->var = info->var;
1433 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1434 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1435 if (charcnt == 256) {
1436 vc->vc_hi_font_mask = 0;
1438 vc->vc_hi_font_mask = 0x100;
1439 if (vc->vc_can_do_color)
1440 vc->vc_complement_mask <<= 1;
1443 if (!*svc->vc_uni_pagedir_loc)
1444 con_set_default_unimap(svc);
1445 if (!*vc->vc_uni_pagedir_loc)
1446 con_copy_unimap(vc, svc);
1448 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1449 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1450 cols /= vc->vc_font.width;
1451 rows /= vc->vc_font.height;
1452 vc_resize(vc, cols, rows);
1454 if (CON_IS_VISIBLE(vc)) {
1457 fbcon_update_softback(vc);
1461 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1463 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1464 struct fbcon_ops *ops = info->fbcon_par;
1465 struct display *p = &fb_display[vc->vc_num];
1467 p->yscroll += count;
1468 if (p->yscroll >= p->vrows) /* Deal with wrap */
1469 p->yscroll -= p->vrows;
1470 ops->var.xoffset = 0;
1471 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1472 ops->var.vmode |= FB_VMODE_YWRAP;
1473 ops->update_start(info);
1474 scrollback_max += count;
1475 if (scrollback_max > scrollback_phys_max)
1476 scrollback_max = scrollback_phys_max;
1477 scrollback_current = 0;
1480 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1482 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1483 struct fbcon_ops *ops = info->fbcon_par;
1484 struct display *p = &fb_display[vc->vc_num];
1486 p->yscroll -= count;
1487 if (p->yscroll < 0) /* Deal with wrap */
1488 p->yscroll += p->vrows;
1489 ops->var.xoffset = 0;
1490 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1491 ops->var.vmode |= FB_VMODE_YWRAP;
1492 ops->update_start(info);
1493 scrollback_max -= count;
1494 if (scrollback_max < 0)
1496 scrollback_current = 0;
1499 static __inline__ void ypan_up(struct vc_data *vc, int count)
1501 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1502 struct display *p = &fb_display[vc->vc_num];
1503 struct fbcon_ops *ops = info->fbcon_par;
1505 p->yscroll += count;
1506 if (p->yscroll > p->vrows - vc->vc_rows) {
1507 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1508 0, 0, 0, vc->vc_rows, vc->vc_cols);
1509 p->yscroll -= p->vrows - vc->vc_rows;
1512 ops->var.xoffset = 0;
1513 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1514 ops->var.vmode &= ~FB_VMODE_YWRAP;
1515 ops->update_start(info);
1516 fbcon_clear_margins(vc, 1);
1517 scrollback_max += count;
1518 if (scrollback_max > scrollback_phys_max)
1519 scrollback_max = scrollback_phys_max;
1520 scrollback_current = 0;
1523 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1525 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1526 struct fbcon_ops *ops = info->fbcon_par;
1527 struct display *p = &fb_display[vc->vc_num];
1529 p->yscroll += count;
1531 if (p->yscroll > p->vrows - vc->vc_rows) {
1532 p->yscroll -= p->vrows - vc->vc_rows;
1533 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1536 ops->var.xoffset = 0;
1537 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1538 ops->var.vmode &= ~FB_VMODE_YWRAP;
1539 ops->update_start(info);
1540 fbcon_clear_margins(vc, 1);
1541 scrollback_max += count;
1542 if (scrollback_max > scrollback_phys_max)
1543 scrollback_max = scrollback_phys_max;
1544 scrollback_current = 0;
1547 static __inline__ void ypan_down(struct vc_data *vc, int count)
1549 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1550 struct display *p = &fb_display[vc->vc_num];
1551 struct fbcon_ops *ops = info->fbcon_par;
1553 p->yscroll -= count;
1554 if (p->yscroll < 0) {
1555 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1556 0, vc->vc_rows, vc->vc_cols);
1557 p->yscroll += p->vrows - vc->vc_rows;
1560 ops->var.xoffset = 0;
1561 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1562 ops->var.vmode &= ~FB_VMODE_YWRAP;
1563 ops->update_start(info);
1564 fbcon_clear_margins(vc, 1);
1565 scrollback_max -= count;
1566 if (scrollback_max < 0)
1568 scrollback_current = 0;
1571 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1573 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1574 struct fbcon_ops *ops = info->fbcon_par;
1575 struct display *p = &fb_display[vc->vc_num];
1577 p->yscroll -= count;
1579 if (p->yscroll < 0) {
1580 p->yscroll += p->vrows - vc->vc_rows;
1581 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1584 ops->var.xoffset = 0;
1585 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1586 ops->var.vmode &= ~FB_VMODE_YWRAP;
1587 ops->update_start(info);
1588 fbcon_clear_margins(vc, 1);
1589 scrollback_max -= count;
1590 if (scrollback_max < 0)
1592 scrollback_current = 0;
1595 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1598 int count = vc->vc_rows;
1599 unsigned short *d, *s;
1603 d = (u16 *) softback_curr;
1604 if (d == (u16 *) softback_in)
1605 d = (u16 *) vc->vc_origin;
1606 n = softback_curr + delta * vc->vc_size_row;
1607 softback_lines -= delta;
1609 if (softback_curr < softback_top && n < softback_buf) {
1610 n += softback_end - softback_buf;
1611 if (n < softback_top) {
1613 (softback_top - n) / vc->vc_size_row;
1616 } else if (softback_curr >= softback_top
1617 && n < softback_top) {
1619 (softback_top - n) / vc->vc_size_row;
1623 if (softback_curr > softback_in && n >= softback_end) {
1624 n += softback_buf - softback_end;
1625 if (n > softback_in) {
1629 } else if (softback_curr <= softback_in && n > softback_in) {
1634 if (n == softback_curr)
1637 s = (u16 *) softback_curr;
1638 if (s == (u16 *) softback_in)
1639 s = (u16 *) vc->vc_origin;
1641 unsigned short *start;
1645 unsigned short attr = 1;
1648 le = advance_row(s, 1);
1651 if (attr != (c & 0xff00)) {
1654 fbcon_putcs(vc, start, s - start,
1660 if (c == scr_readw(d)) {
1662 fbcon_putcs(vc, start, s - start,
1675 fbcon_putcs(vc, start, s - start, line, x);
1677 if (d == (u16 *) softback_end)
1678 d = (u16 *) softback_buf;
1679 if (d == (u16 *) softback_in)
1680 d = (u16 *) vc->vc_origin;
1681 if (s == (u16 *) softback_end)
1682 s = (u16 *) softback_buf;
1683 if (s == (u16 *) softback_in)
1684 s = (u16 *) vc->vc_origin;
1688 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1689 int line, int count, int dy)
1691 unsigned short *s = (unsigned short *)
1692 (vc->vc_origin + vc->vc_size_row * line);
1695 unsigned short *start = s;
1696 unsigned short *le = advance_row(s, 1);
1699 unsigned short attr = 1;
1703 if (attr != (c & 0xff00)) {
1706 fbcon_putcs(vc, start, s - start,
1712 console_conditional_schedule();
1716 fbcon_putcs(vc, start, s - start, dy, x);
1717 console_conditional_schedule();
1722 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1723 struct display *p, int line, int count, int ycount)
1725 int offset = ycount * vc->vc_cols;
1726 unsigned short *d = (unsigned short *)
1727 (vc->vc_origin + vc->vc_size_row * line);
1728 unsigned short *s = d + offset;
1729 struct fbcon_ops *ops = info->fbcon_par;
1732 unsigned short *start = s;
1733 unsigned short *le = advance_row(s, 1);
1740 if (c == scr_readw(d)) {
1742 ops->bmove(vc, info, line + ycount, x,
1743 line, x, 1, s-start);
1753 console_conditional_schedule();
1758 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1760 console_conditional_schedule();
1765 /* NOTE: We subtract two lines from these pointers */
1766 s -= vc->vc_size_row;
1767 d -= vc->vc_size_row;
1772 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1773 int line, int count, int offset)
1775 unsigned short *d = (unsigned short *)
1776 (vc->vc_origin + vc->vc_size_row * line);
1777 unsigned short *s = d + offset;
1780 unsigned short *start = s;
1781 unsigned short *le = advance_row(s, 1);
1784 unsigned short attr = 1;
1788 if (attr != (c & 0xff00)) {
1791 fbcon_putcs(vc, start, s - start,
1797 if (c == scr_readw(d)) {
1799 fbcon_putcs(vc, start, s - start,
1809 console_conditional_schedule();
1814 fbcon_putcs(vc, start, s - start, line, x);
1815 console_conditional_schedule();
1820 /* NOTE: We subtract two lines from these pointers */
1821 s -= vc->vc_size_row;
1822 d -= vc->vc_size_row;
1827 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1832 if (vc->vc_num != fg_console)
1834 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1837 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1839 p = advance_row(p, 1);
1840 softback_in += vc->vc_size_row;
1841 if (softback_in == softback_end)
1842 softback_in = softback_buf;
1843 if (softback_in == softback_top) {
1844 softback_top += vc->vc_size_row;
1845 if (softback_top == softback_end)
1846 softback_top = softback_buf;
1849 softback_curr = softback_in;
1852 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1855 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1856 struct display *p = &fb_display[vc->vc_num];
1857 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1858 unsigned short saved_ec;
1861 if (fbcon_is_inactive(vc, info))
1864 fbcon_cursor(vc, CM_ERASE);
1867 * ++Geert: Only use ywrap/ypan if the console is in text mode
1868 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1869 * whole screen (prevents flicker).
1872 saved_ec = vc->vc_video_erase_char;
1873 vc->vc_video_erase_char = vc->vc_scrl_erase_char;
1879 if (count > vc->vc_rows) /* Maximum realistic size */
1880 count = vc->vc_rows;
1882 fbcon_softback_note(vc, t, count);
1883 if (logo_shown >= 0)
1885 switch (p->scrollmode) {
1887 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1889 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1890 scr_memsetw((unsigned short *) (vc->vc_origin +
1893 vc->vc_scrl_erase_char,
1894 vc->vc_size_row * count);
1898 case SCROLL_WRAP_MOVE:
1899 if (b - t - count > 3 * vc->vc_rows >> 2) {
1901 fbcon_bmove(vc, 0, 0, count, 0, t,
1903 ywrap_up(vc, count);
1904 if (vc->vc_rows - b > 0)
1905 fbcon_bmove(vc, b - count, 0, b, 0,
1908 } else if (info->flags & FBINFO_READS_FAST)
1909 fbcon_bmove(vc, t + count, 0, t, 0,
1910 b - t - count, vc->vc_cols);
1913 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1916 case SCROLL_PAN_REDRAW:
1917 if ((p->yscroll + count <=
1918 2 * (p->vrows - vc->vc_rows))
1919 && ((!scroll_partial && (b - t == vc->vc_rows))
1922 3 * vc->vc_rows >> 2)))) {
1924 fbcon_redraw_move(vc, p, 0, t, count);
1925 ypan_up_redraw(vc, t, count);
1926 if (vc->vc_rows - b > 0)
1927 fbcon_redraw_move(vc, p, b,
1928 vc->vc_rows - b, b);
1930 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1931 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1934 case SCROLL_PAN_MOVE:
1935 if ((p->yscroll + count <=
1936 2 * (p->vrows - vc->vc_rows))
1937 && ((!scroll_partial && (b - t == vc->vc_rows))
1940 3 * vc->vc_rows >> 2)))) {
1942 fbcon_bmove(vc, 0, 0, count, 0, t,
1945 if (vc->vc_rows - b > 0)
1946 fbcon_bmove(vc, b - count, 0, b, 0,
1949 } else if (info->flags & FBINFO_READS_FAST)
1950 fbcon_bmove(vc, t + count, 0, t, 0,
1951 b - t - count, vc->vc_cols);
1954 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1959 fbcon_redraw(vc, p, t, b - t - count,
1960 count * vc->vc_cols);
1961 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1962 scr_memsetw((unsigned short *) (vc->vc_origin +
1965 vc->vc_scrl_erase_char,
1966 vc->vc_size_row * count);
1973 if (count > vc->vc_rows) /* Maximum realistic size */
1974 count = vc->vc_rows;
1975 if (logo_shown >= 0)
1977 switch (p->scrollmode) {
1979 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1981 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1982 scr_memsetw((unsigned short *) (vc->vc_origin +
1985 vc->vc_scrl_erase_char,
1986 vc->vc_size_row * count);
1990 case SCROLL_WRAP_MOVE:
1991 if (b - t - count > 3 * vc->vc_rows >> 2) {
1992 if (vc->vc_rows - b > 0)
1993 fbcon_bmove(vc, b, 0, b - count, 0,
1996 ywrap_down(vc, count);
1998 fbcon_bmove(vc, count, 0, 0, 0, t,
2000 } else if (info->flags & FBINFO_READS_FAST)
2001 fbcon_bmove(vc, t, 0, t + count, 0,
2002 b - t - count, vc->vc_cols);
2005 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2008 case SCROLL_PAN_MOVE:
2009 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2010 && ((!scroll_partial && (b - t == vc->vc_rows))
2013 3 * vc->vc_rows >> 2)))) {
2014 if (vc->vc_rows - b > 0)
2015 fbcon_bmove(vc, b, 0, b - count, 0,
2018 ypan_down(vc, count);
2020 fbcon_bmove(vc, count, 0, 0, 0, t,
2022 } else if (info->flags & FBINFO_READS_FAST)
2023 fbcon_bmove(vc, t, 0, t + count, 0,
2024 b - t - count, vc->vc_cols);
2027 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2030 case SCROLL_PAN_REDRAW:
2031 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2032 && ((!scroll_partial && (b - t == vc->vc_rows))
2035 3 * vc->vc_rows >> 2)))) {
2036 if (vc->vc_rows - b > 0)
2037 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2039 ypan_down_redraw(vc, t, count);
2041 fbcon_redraw_move(vc, p, count, t, 0);
2043 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2044 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2049 fbcon_redraw(vc, p, b - 1, b - t - count,
2050 -count * vc->vc_cols);
2051 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2052 scr_memsetw((unsigned short *) (vc->vc_origin +
2055 vc->vc_scrl_erase_char,
2056 vc->vc_size_row * count);
2062 vc->vc_video_erase_char = saved_ec;
2067 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2068 int height, int width)
2070 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2071 struct display *p = &fb_display[vc->vc_num];
2073 if (fbcon_is_inactive(vc, info))
2076 if (!width || !height)
2079 /* Split blits that cross physical y_wrap case.
2080 * Pathological case involves 4 blits, better to use recursive
2081 * code rather than unrolled case
2083 * Recursive invocations don't need to erase the cursor over and
2084 * over again, so we use fbcon_bmove_rec()
2086 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2087 p->vrows - p->yscroll);
2090 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2091 int dy, int dx, int height, int width, u_int y_break)
2093 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2094 struct fbcon_ops *ops = info->fbcon_par;
2097 if (sy < y_break && sy + height > y_break) {
2099 if (dy < sy) { /* Avoid trashing self */
2100 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2102 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2103 height - b, width, y_break);
2105 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2106 height - b, width, y_break);
2107 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2113 if (dy < y_break && dy + height > y_break) {
2115 if (dy < sy) { /* Avoid trashing self */
2116 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2118 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2119 height - b, width, y_break);
2121 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2122 height - b, width, y_break);
2123 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2128 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2132 static __inline__ void updatescrollmode(struct display *p,
2133 struct fb_info *info,
2136 struct fbcon_ops *ops = info->fbcon_par;
2137 int fh = vc->vc_font.height;
2138 int cap = info->flags;
2140 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2141 info->fix.xpanstep);
2142 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2143 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2144 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2145 info->var.xres_virtual);
2146 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2147 divides(ypan, vc->vc_font.height) && vyres > yres;
2148 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2149 divides(ywrap, vc->vc_font.height) &&
2150 divides(vc->vc_font.height, vyres) &&
2151 divides(vc->vc_font.height, yres);
2152 int reading_fast = cap & FBINFO_READS_FAST;
2153 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2154 !(cap & FBINFO_HWACCEL_DISABLED);
2155 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2156 !(cap & FBINFO_HWACCEL_DISABLED);
2158 p->vrows = vyres/fh;
2159 if (yres > (fh * (vc->vc_rows + 1)))
2160 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2161 if ((yres % fh) && (vyres % fh < yres % fh))
2164 if (good_wrap || good_pan) {
2165 if (reading_fast || fast_copyarea)
2166 p->scrollmode = good_wrap ?
2167 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2169 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2172 if (reading_fast || (fast_copyarea && !fast_imageblit))
2173 p->scrollmode = SCROLL_MOVE;
2175 p->scrollmode = SCROLL_REDRAW;
2179 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2180 unsigned int height, unsigned int user)
2182 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2183 struct fbcon_ops *ops = info->fbcon_par;
2184 struct display *p = &fb_display[vc->vc_num];
2185 struct fb_var_screeninfo var = info->var;
2186 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2188 virt_w = FBCON_SWAP(ops->rotate, width, height);
2189 virt_h = FBCON_SWAP(ops->rotate, height, width);
2190 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2191 vc->vc_font.height);
2192 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2194 var.xres = virt_w * virt_fw;
2195 var.yres = virt_h * virt_fh;
2196 x_diff = info->var.xres - var.xres;
2197 y_diff = info->var.yres - var.yres;
2198 if (x_diff < 0 || x_diff > virt_fw ||
2199 y_diff < 0 || y_diff > virt_fh) {
2200 const struct fb_videomode *mode;
2202 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2203 mode = fb_find_best_mode(&var, &info->modelist);
2206 display_to_var(&var, p);
2207 fb_videomode_to_var(&var, mode);
2209 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2212 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2213 if (CON_IS_VISIBLE(vc)) {
2214 var.activate = FB_ACTIVATE_NOW |
2216 fb_set_var(info, &var);
2218 var_to_display(p, &info->var, info);
2219 ops->var = info->var;
2221 updatescrollmode(p, info, vc);
2225 static int fbcon_switch(struct vc_data *vc)
2227 struct fb_info *info, *old_info = NULL;
2228 struct fbcon_ops *ops;
2229 struct display *p = &fb_display[vc->vc_num];
2230 struct fb_var_screeninfo var;
2231 int i, prev_console, charcnt = 256;
2233 info = registered_fb[con2fb_map[vc->vc_num]];
2234 ops = info->fbcon_par;
2238 fbcon_set_origin(vc);
2239 softback_top = softback_curr = softback_in = softback_buf;
2241 fbcon_update_softback(vc);
2244 if (logo_shown >= 0) {
2245 struct vc_data *conp2 = vc_cons[logo_shown].d;
2247 if (conp2->vc_top == logo_lines
2248 && conp2->vc_bottom == conp2->vc_rows)
2250 logo_shown = FBCON_LOGO_CANSHOW;
2253 prev_console = ops->currcon;
2254 if (prev_console != -1)
2255 old_info = registered_fb[con2fb_map[prev_console]];
2257 * FIXME: If we have multiple fbdev's loaded, we need to
2258 * update all info->currcon. Perhaps, we can place this
2259 * in a centralized structure, but this might break some
2262 * info->currcon = vc->vc_num;
2264 for (i = 0; i < FB_MAX; i++) {
2265 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2266 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2268 o->currcon = vc->vc_num;
2271 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2272 display_to_var(&var, p);
2273 var.activate = FB_ACTIVATE_NOW;
2276 * make sure we don't unnecessarily trip the memcmp()
2279 info->var.activate = var.activate;
2280 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2281 fb_set_var(info, &var);
2282 ops->var = info->var;
2284 if (old_info != NULL && (old_info != info ||
2285 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2286 if (info->fbops->fb_set_par)
2287 info->fbops->fb_set_par(info);
2289 if (old_info != info)
2290 fbcon_del_cursor_timer(old_info);
2293 if (fbcon_is_inactive(vc, info) ||
2294 ops->blank_state != FB_BLANK_UNBLANK)
2295 fbcon_del_cursor_timer(info);
2297 fbcon_add_cursor_timer(info);
2299 set_blitting_type(vc, info);
2300 ops->cursor_reset = 1;
2302 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2303 ops->rotate = FB_ROTATE_UR;
2304 set_blitting_type(vc, info);
2307 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2308 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2311 charcnt = FNTCHARCNT(vc->vc_font.data);
2314 vc->vc_complement_mask <<= 1;
2316 updatescrollmode(p, info, vc);
2318 switch (p->scrollmode) {
2319 case SCROLL_WRAP_MOVE:
2320 scrollback_phys_max = p->vrows - vc->vc_rows;
2322 case SCROLL_PAN_MOVE:
2323 case SCROLL_PAN_REDRAW:
2324 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2325 if (scrollback_phys_max < 0)
2326 scrollback_phys_max = 0;
2329 scrollback_phys_max = 0;
2334 scrollback_current = 0;
2336 if (!fbcon_is_inactive(vc, info)) {
2337 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2338 ops->update_start(info);
2341 fbcon_set_palette(vc, color_table);
2342 fbcon_clear_margins(vc, 0);
2344 if (logo_shown == FBCON_LOGO_DRAW) {
2346 logo_shown = fg_console;
2347 /* This is protected above by initmem_freed */
2348 fb_show_logo(info, ops->rotate);
2350 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2351 vc->vc_size_row * (vc->vc_bottom -
2358 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2361 struct fb_event event;
2364 unsigned short charmask = vc->vc_hi_font_mask ?
2366 unsigned short oldc;
2368 oldc = vc->vc_video_erase_char;
2369 vc->vc_video_erase_char &= charmask;
2370 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2371 vc->vc_video_erase_char = oldc;
2376 event.data = ␣
2377 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2380 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2382 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2383 struct fbcon_ops *ops = info->fbcon_par;
2386 struct fb_var_screeninfo var = info->var;
2391 if (info->fbops->fb_save_state)
2392 info->fbops->fb_save_state(info);
2393 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2394 fb_set_var(info, &var);
2396 ops->var = info->var;
2397 } else if (info->fbops->fb_restore_state)
2398 info->fbops->fb_restore_state(info);
2401 if (!fbcon_is_inactive(vc, info)) {
2402 if (ops->blank_state != blank) {
2405 ops->blank_state = blank;
2406 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2407 ops->cursor_flash = (!blank);
2409 if (info->fbops->fb_blank)
2410 ret = info->fbops->fb_blank(blank, info);
2412 fbcon_generic_blank(vc, info, blank);
2419 if (mode_switch || fbcon_is_inactive(vc, info) ||
2420 ops->blank_state != FB_BLANK_UNBLANK)
2421 fbcon_del_cursor_timer(info);
2423 fbcon_add_cursor_timer(info);
2428 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2430 u8 *fontdata = vc->vc_font.data;
2431 u8 *data = font->data;
2434 font->width = vc->vc_font.width;
2435 font->height = vc->vc_font.height;
2436 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2440 if (font->width <= 8) {
2441 j = vc->vc_font.height;
2442 for (i = 0; i < font->charcount; i++) {
2443 memcpy(data, fontdata, j);
2444 memset(data + j, 0, 32 - j);
2448 } else if (font->width <= 16) {
2449 j = vc->vc_font.height * 2;
2450 for (i = 0; i < font->charcount; i++) {
2451 memcpy(data, fontdata, j);
2452 memset(data + j, 0, 64 - j);
2456 } else if (font->width <= 24) {
2457 for (i = 0; i < font->charcount; i++) {
2458 for (j = 0; j < vc->vc_font.height; j++) {
2459 *data++ = fontdata[0];
2460 *data++ = fontdata[1];
2461 *data++ = fontdata[2];
2462 fontdata += sizeof(u32);
2464 memset(data, 0, 3 * (32 - j));
2465 data += 3 * (32 - j);
2468 j = vc->vc_font.height * 4;
2469 for (i = 0; i < font->charcount; i++) {
2470 memcpy(data, fontdata, j);
2471 memset(data + j, 0, 128 - j);
2479 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2480 const u8 * data, int userfont)
2482 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2483 struct fbcon_ops *ops = info->fbcon_par;
2484 struct display *p = &fb_display[vc->vc_num];
2487 char *old_data = NULL;
2489 if (CON_IS_VISIBLE(vc) && softback_lines)
2490 fbcon_set_origin(vc);
2492 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2494 old_data = vc->vc_font.data;
2496 cnt = FNTCHARCNT(data);
2499 vc->vc_font.data = (void *)(p->fontdata = data);
2500 if ((p->userfont = userfont))
2502 vc->vc_font.width = w;
2503 vc->vc_font.height = h;
2504 if (vc->vc_hi_font_mask && cnt == 256) {
2505 vc->vc_hi_font_mask = 0;
2506 if (vc->vc_can_do_color) {
2507 vc->vc_complement_mask >>= 1;
2508 vc->vc_s_complement_mask >>= 1;
2511 /* ++Edmund: reorder the attribute bits */
2512 if (vc->vc_can_do_color) {
2513 unsigned short *cp =
2514 (unsigned short *) vc->vc_origin;
2515 int count = vc->vc_screenbuf_size / 2;
2517 for (; count > 0; count--, cp++) {
2519 scr_writew(((c & 0xfe00) >> 1) |
2522 c = vc->vc_video_erase_char;
2523 vc->vc_video_erase_char =
2524 ((c & 0xfe00) >> 1) | (c & 0xff);
2525 c = vc->vc_scrl_erase_char;
2526 vc->vc_scrl_erase_char =
2527 ((c & 0xFE00) >> 1) | (c & 0xFF);
2530 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2531 vc->vc_hi_font_mask = 0x100;
2532 if (vc->vc_can_do_color) {
2533 vc->vc_complement_mask <<= 1;
2534 vc->vc_s_complement_mask <<= 1;
2537 /* ++Edmund: reorder the attribute bits */
2539 unsigned short *cp =
2540 (unsigned short *) vc->vc_origin;
2541 int count = vc->vc_screenbuf_size / 2;
2543 for (; count > 0; count--, cp++) {
2544 unsigned short newc;
2546 if (vc->vc_can_do_color)
2548 ((c & 0xff00) << 1) | (c &
2552 scr_writew(newc, cp);
2554 c = vc->vc_video_erase_char;
2555 if (vc->vc_can_do_color) {
2556 vc->vc_video_erase_char =
2557 ((c & 0xff00) << 1) | (c & 0xff);
2558 c = vc->vc_scrl_erase_char;
2559 vc->vc_scrl_erase_char =
2560 ((c & 0xFF00) << 1) | (c & 0xFF);
2563 vc->vc_video_erase_char = c & ~0x100;
2564 vc->vc_scrl_erase_char = c & ~0x100;
2573 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2574 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2577 vc_resize(vc, cols, rows);
2578 if (CON_IS_VISIBLE(vc) && softback_buf)
2579 fbcon_update_softback(vc);
2580 } else if (CON_IS_VISIBLE(vc)
2581 && vc->vc_mode == KD_TEXT) {
2582 fbcon_clear_margins(vc, 0);
2586 if (old_data && (--REFCOUNT(old_data) == 0))
2587 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2591 static int fbcon_copy_font(struct vc_data *vc, int con)
2593 struct display *od = &fb_display[con];
2594 struct console_font *f = &vc->vc_font;
2596 if (od->fontdata == f->data)
2597 return 0; /* already the same font... */
2598 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2602 * User asked to set font; we are guaranteed that
2603 * a) width and height are in range 1..32
2604 * b) charcount does not exceed 512
2605 * but lets not assume that, since someone might someday want to use larger
2606 * fonts. And charcount of 512 is small for unicode support.
2608 * However, user space gives the font in 32 rows , regardless of
2609 * actual font height. So a new API is needed if support for larger fonts
2610 * is ever implemented.
2613 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2615 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2616 unsigned charcount = font->charcount;
2617 int w = font->width;
2618 int h = font->height;
2621 u8 *new_data, *data = font->data;
2622 int pitch = (font->width+7) >> 3;
2624 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2625 * If not this check should be changed to charcount < 256 */
2626 if (charcount != 256 && charcount != 512)
2629 /* Make sure drawing engine can handle the font */
2630 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2631 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2634 /* Make sure driver can handle the font length */
2635 if (fbcon_invalid_charcount(info, charcount))
2638 size = h * pitch * charcount;
2640 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2645 new_data += FONT_EXTRA_WORDS * sizeof(int);
2646 FNTSIZE(new_data) = size;
2647 FNTCHARCNT(new_data) = charcount;
2648 REFCOUNT(new_data) = 0; /* usage counter */
2649 for (i=0; i< charcount; i++) {
2650 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2653 /* Since linux has a nice crc32 function use it for counting font
2655 csum = crc32(0, new_data, size);
2657 FNTSUM(new_data) = csum;
2658 /* Check if the same font is on some other console already */
2659 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2660 struct vc_data *tmp = vc_cons[i].d;
2662 if (fb_display[i].userfont &&
2663 fb_display[i].fontdata &&
2664 FNTSUM(fb_display[i].fontdata) == csum &&
2665 FNTSIZE(fb_display[i].fontdata) == size &&
2666 tmp->vc_font.width == w &&
2667 !memcmp(fb_display[i].fontdata, new_data, size)) {
2668 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2669 new_data = (u8 *)fb_display[i].fontdata;
2673 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2676 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2678 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2679 const struct font_desc *f;
2682 f = get_default_font(info->var.xres, info->var.yres,
2683 info->pixmap.blit_x, info->pixmap.blit_y);
2684 else if (!(f = find_font(name)))
2687 font->width = f->width;
2688 font->height = f->height;
2689 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2692 static u16 palette_red[16];
2693 static u16 palette_green[16];
2694 static u16 palette_blue[16];
2696 static struct fb_cmap palette_cmap = {
2697 0, 16, palette_red, palette_green, palette_blue, NULL
2700 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2702 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2706 if (fbcon_is_inactive(vc, info))
2709 if (!CON_IS_VISIBLE(vc))
2712 depth = fb_get_color_depth(&info->var, &info->fix);
2714 for (i = j = 0; i < 16; i++) {
2716 val = vc->vc_palette[j++];
2717 palette_red[k] = (val << 8) | val;
2718 val = vc->vc_palette[j++];
2719 palette_green[k] = (val << 8) | val;
2720 val = vc->vc_palette[j++];
2721 palette_blue[k] = (val << 8) | val;
2723 palette_cmap.len = 16;
2724 palette_cmap.start = 0;
2726 * If framebuffer is capable of less than 16 colors,
2727 * use default palette of fbcon.
2730 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2732 return fb_set_cmap(&palette_cmap, info);
2735 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2740 if (vc->vc_num != fg_console || !softback_lines)
2741 return (u16 *) (vc->vc_origin + offset);
2742 line = offset / vc->vc_size_row;
2743 if (line >= softback_lines)
2744 return (u16 *) (vc->vc_origin + offset -
2745 softback_lines * vc->vc_size_row);
2746 p = softback_curr + offset;
2747 if (p >= softback_end)
2748 p += softback_buf - softback_end;
2752 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2758 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2759 unsigned long offset = (pos - vc->vc_origin) / 2;
2761 x = offset % vc->vc_cols;
2762 y = offset / vc->vc_cols;
2763 if (vc->vc_num == fg_console)
2764 y += softback_lines;
2765 ret = pos + (vc->vc_cols - x) * 2;
2766 } else if (vc->vc_num == fg_console && softback_lines) {
2767 unsigned long offset = pos - softback_curr;
2769 if (pos < softback_curr)
2770 offset += softback_end - softback_buf;
2772 x = offset % vc->vc_cols;
2773 y = offset / vc->vc_cols;
2774 ret = pos + (vc->vc_cols - x) * 2;
2775 if (ret == softback_end)
2777 if (ret == softback_in)
2778 ret = vc->vc_origin;
2780 /* Should not happen */
2782 ret = vc->vc_origin;
2791 /* As we might be inside of softback, we may work with non-contiguous buffer,
2792 that's why we have to use a separate routine. */
2793 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2796 u16 a = scr_readw(p);
2797 if (!vc->vc_can_do_color)
2799 else if (vc->vc_hi_font_mask == 0x100)
2800 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2801 (((a) & 0x0e00) << 4);
2803 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2804 (((a) & 0x0700) << 4);
2806 if (p == (u16 *) softback_end)
2807 p = (u16 *) softback_buf;
2808 if (p == (u16 *) softback_in)
2809 p = (u16 *) vc->vc_origin;
2813 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2815 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2816 struct fbcon_ops *ops = info->fbcon_par;
2817 struct display *disp = &fb_display[fg_console];
2818 int offset, limit, scrollback_old;
2821 if (vc->vc_num != fg_console)
2823 if (vc->vc_mode != KD_TEXT || !lines)
2825 if (logo_shown >= 0) {
2826 struct vc_data *conp2 = vc_cons[logo_shown].d;
2828 if (conp2->vc_top == logo_lines
2829 && conp2->vc_bottom == conp2->vc_rows)
2831 if (logo_shown == vc->vc_num) {
2837 logo_lines * vc->vc_size_row;
2838 for (i = 0; i < logo_lines; i++) {
2839 if (p == softback_top)
2841 if (p == softback_buf)
2843 p -= vc->vc_size_row;
2844 q -= vc->vc_size_row;
2845 scr_memcpyw((u16 *) q, (u16 *) p,
2848 softback_in = softback_curr = p;
2849 update_region(vc, vc->vc_origin,
2850 logo_lines * vc->vc_cols);
2852 logo_shown = FBCON_LOGO_CANSHOW;
2854 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2855 fbcon_redraw_softback(vc, disp, lines);
2856 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2860 if (!scrollback_phys_max)
2863 scrollback_old = scrollback_current;
2864 scrollback_current -= lines;
2865 if (scrollback_current < 0)
2866 scrollback_current = 0;
2867 else if (scrollback_current > scrollback_max)
2868 scrollback_current = scrollback_max;
2869 if (scrollback_current == scrollback_old)
2872 if (fbcon_is_inactive(vc, info))
2875 fbcon_cursor(vc, CM_ERASE);
2877 offset = disp->yscroll - scrollback_current;
2878 limit = disp->vrows;
2879 switch (disp->scrollmode) {
2880 case SCROLL_WRAP_MOVE:
2881 info->var.vmode |= FB_VMODE_YWRAP;
2883 case SCROLL_PAN_MOVE:
2884 case SCROLL_PAN_REDRAW:
2885 limit -= vc->vc_rows;
2886 info->var.vmode &= ~FB_VMODE_YWRAP;
2891 else if (offset >= limit)
2894 ops->var.xoffset = 0;
2895 ops->var.yoffset = offset * vc->vc_font.height;
2896 ops->update_start(info);
2898 if (!scrollback_current)
2899 fbcon_cursor(vc, CM_DRAW);
2903 static int fbcon_set_origin(struct vc_data *vc)
2906 fbcon_scrolldelta(vc, softback_lines);
2910 static void fbcon_suspended(struct fb_info *info)
2912 struct vc_data *vc = NULL;
2913 struct fbcon_ops *ops = info->fbcon_par;
2915 if (!ops || ops->currcon < 0)
2917 vc = vc_cons[ops->currcon].d;
2919 /* Clear cursor, restore saved data */
2920 fbcon_cursor(vc, CM_ERASE);
2923 static void fbcon_resumed(struct fb_info *info)
2926 struct fbcon_ops *ops = info->fbcon_par;
2928 if (!ops || ops->currcon < 0)
2930 vc = vc_cons[ops->currcon].d;
2935 static void fbcon_modechanged(struct fb_info *info)
2937 struct fbcon_ops *ops = info->fbcon_par;
2942 if (!ops || ops->currcon < 0)
2944 vc = vc_cons[ops->currcon].d;
2945 if (vc->vc_mode != KD_TEXT ||
2946 registered_fb[con2fb_map[ops->currcon]] != info)
2949 p = &fb_display[vc->vc_num];
2950 set_blitting_type(vc, info);
2952 if (CON_IS_VISIBLE(vc)) {
2953 var_to_display(p, &info->var, info);
2954 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2955 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2956 cols /= vc->vc_font.width;
2957 rows /= vc->vc_font.height;
2958 vc_resize(vc, cols, rows);
2959 updatescrollmode(p, info, vc);
2961 scrollback_current = 0;
2963 if (!fbcon_is_inactive(vc, info)) {
2964 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2965 ops->update_start(info);
2968 fbcon_set_palette(vc, color_table);
2971 fbcon_update_softback(vc);
2975 static void fbcon_set_all_vcs(struct fb_info *info)
2977 struct fbcon_ops *ops = info->fbcon_par;
2980 int i, rows, cols, fg = -1;
2982 if (!ops || ops->currcon < 0)
2985 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2987 if (!vc || vc->vc_mode != KD_TEXT ||
2988 registered_fb[con2fb_map[i]] != info)
2991 if (CON_IS_VISIBLE(vc)) {
2996 p = &fb_display[vc->vc_num];
2997 set_blitting_type(vc, info);
2998 var_to_display(p, &info->var, info);
2999 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
3000 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
3001 cols /= vc->vc_font.width;
3002 rows /= vc->vc_font.height;
3003 vc_resize(vc, cols, rows);
3007 fbcon_modechanged(info);
3010 static int fbcon_mode_deleted(struct fb_info *info,
3011 struct fb_videomode *mode)
3013 struct fb_info *fb_info;
3015 int i, j, found = 0;
3017 /* before deletion, ensure that mode is not in use */
3018 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3022 fb_info = registered_fb[j];
3023 if (fb_info != info)
3028 if (fb_mode_is_equal(p->mode, mode)) {
3036 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3037 static int fbcon_unbind(void)
3041 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3046 static inline int fbcon_unbind(void)
3050 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3052 static int fbcon_fb_unbind(int idx)
3054 int i, new_idx = -1, ret = 0;
3056 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3057 if (con2fb_map[i] != idx &&
3058 con2fb_map[i] != -1) {
3064 if (new_idx != -1) {
3065 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3066 if (con2fb_map[i] == idx)
3067 set_con2fb_map(i, new_idx, 0);
3070 ret = fbcon_unbind();
3075 static int fbcon_fb_unregistered(struct fb_info *info)
3077 int i, idx = info->node;
3079 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3080 if (con2fb_map[i] == idx)
3084 if (idx == info_idx) {
3087 for (i = 0; i < FB_MAX; i++) {
3088 if (registered_fb[i] != NULL) {
3095 if (info_idx != -1) {
3096 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3097 if (con2fb_map[i] == -1)
3098 con2fb_map[i] = info_idx;
3102 if (!num_registered_fb)
3103 unregister_con_driver(&fb_con);
3106 if (primary_device == idx)
3107 primary_device = -1;
3112 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3113 static void fbcon_select_primary(struct fb_info *info)
3115 if (!map_override && primary_device == -1 &&
3116 fb_is_primary_device(info)) {
3119 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3120 info->fix.id, info->node);
3121 primary_device = info->node;
3123 for (i = first_fb_vc; i <= last_fb_vc; i++)
3124 con2fb_map_boot[i] = primary_device;
3126 if (con_is_bound(&fb_con)) {
3127 printk(KERN_INFO "fbcon: Remapping primary device, "
3128 "fb%i, to tty %i-%i\n", info->node,
3129 first_fb_vc + 1, last_fb_vc + 1);
3130 info_idx = primary_device;
3136 static inline void fbcon_select_primary(struct fb_info *info)
3140 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3142 static int fbcon_fb_registered(struct fb_info *info)
3144 int ret = 0, i, idx = info->node;
3146 fbcon_select_primary(info);
3148 if (info_idx == -1) {
3149 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3150 if (con2fb_map_boot[i] == idx) {
3157 ret = fbcon_takeover(1);
3159 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3160 if (con2fb_map_boot[i] == idx)
3161 set_con2fb_map(i, idx, 0);
3168 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3170 struct fbcon_ops *ops = info->fbcon_par;
3173 if (!ops || ops->currcon < 0)
3176 vc = vc_cons[ops->currcon].d;
3177 if (vc->vc_mode != KD_TEXT ||
3178 registered_fb[con2fb_map[ops->currcon]] != info)
3181 if (CON_IS_VISIBLE(vc)) {
3185 do_unblank_screen(0);
3187 ops->blank_state = blank;
3190 static void fbcon_new_modelist(struct fb_info *info)
3194 struct fb_var_screeninfo var;
3195 const struct fb_videomode *mode;
3197 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3198 if (registered_fb[con2fb_map[i]] != info)
3200 if (!fb_display[i].mode)
3203 display_to_var(&var, &fb_display[i]);
3204 mode = fb_find_nearest_mode(fb_display[i].mode,
3206 fb_videomode_to_var(&var, mode);
3207 fbcon_set_disp(info, &var, vc->vc_num);
3211 static void fbcon_get_requirement(struct fb_info *info,
3212 struct fb_blit_caps *caps)
3220 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3222 if (vc && vc->vc_mode == KD_TEXT &&
3223 info->node == con2fb_map[i]) {
3225 caps->x |= 1 << (vc->vc_font.width - 1);
3226 caps->y |= 1 << (vc->vc_font.height - 1);
3227 charcnt = (p->userfont) ?
3228 FNTCHARCNT(p->fontdata) : 256;
3229 if (caps->len < charcnt)
3230 caps->len = charcnt;
3234 vc = vc_cons[fg_console].d;
3236 if (vc && vc->vc_mode == KD_TEXT &&
3237 info->node == con2fb_map[fg_console]) {
3238 p = &fb_display[fg_console];
3239 caps->x = 1 << (vc->vc_font.width - 1);
3240 caps->y = 1 << (vc->vc_font.height - 1);
3241 caps->len = (p->userfont) ?
3242 FNTCHARCNT(p->fontdata) : 256;
3247 static int fbcon_event_notify(struct notifier_block *self,
3248 unsigned long action, void *data)
3250 struct fb_event *event = data;
3251 struct fb_info *info = event->info;
3252 struct fb_videomode *mode;
3253 struct fb_con2fbmap *con2fb;
3254 struct fb_blit_caps *caps;
3258 * ignore all events except driver registration and deregistration
3259 * if fbcon is not active
3261 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3262 action == FB_EVENT_FB_UNREGISTERED))
3266 case FB_EVENT_SUSPEND:
3267 fbcon_suspended(info);
3269 case FB_EVENT_RESUME:
3270 fbcon_resumed(info);
3272 case FB_EVENT_MODE_CHANGE:
3273 fbcon_modechanged(info);
3275 case FB_EVENT_MODE_CHANGE_ALL:
3276 fbcon_set_all_vcs(info);
3278 case FB_EVENT_MODE_DELETE:
3280 ret = fbcon_mode_deleted(info, mode);
3282 case FB_EVENT_FB_UNBIND:
3283 ret = fbcon_fb_unbind(info->node);
3285 case FB_EVENT_FB_REGISTERED:
3286 ret = fbcon_fb_registered(info);
3288 case FB_EVENT_FB_UNREGISTERED:
3289 ret = fbcon_fb_unregistered(info);
3291 case FB_EVENT_SET_CONSOLE_MAP:
3292 con2fb = event->data;
3293 ret = set_con2fb_map(con2fb->console - 1,
3294 con2fb->framebuffer, 1);
3296 case FB_EVENT_GET_CONSOLE_MAP:
3297 con2fb = event->data;
3298 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3300 case FB_EVENT_BLANK:
3301 fbcon_fb_blanked(info, *(int *)event->data);
3303 case FB_EVENT_NEW_MODELIST:
3304 fbcon_new_modelist(info);
3306 case FB_EVENT_GET_REQ:
3308 fbcon_get_requirement(info, caps);
3317 * The console `switch' structure for the frame buffer based console
3320 static const struct consw fb_con = {
3321 .owner = THIS_MODULE,
3322 .con_startup = fbcon_startup,
3323 .con_init = fbcon_init,
3324 .con_deinit = fbcon_deinit,
3325 .con_clear = fbcon_clear,
3326 .con_putc = fbcon_putc,
3327 .con_putcs = fbcon_putcs,
3328 .con_cursor = fbcon_cursor,
3329 .con_scroll = fbcon_scroll,
3330 .con_bmove = fbcon_bmove,
3331 .con_switch = fbcon_switch,
3332 .con_blank = fbcon_blank,
3333 .con_font_set = fbcon_set_font,
3334 .con_font_get = fbcon_get_font,
3335 .con_font_default = fbcon_set_def_font,
3336 .con_font_copy = fbcon_copy_font,
3337 .con_set_palette = fbcon_set_palette,
3338 .con_scrolldelta = fbcon_scrolldelta,
3339 .con_set_origin = fbcon_set_origin,
3340 .con_invert_region = fbcon_invert_region,
3341 .con_screen_pos = fbcon_screen_pos,
3342 .con_getxy = fbcon_getxy,
3343 .con_resize = fbcon_resize,
3346 static struct notifier_block fbcon_event_notifier = {
3347 .notifier_call = fbcon_event_notify,
3350 static ssize_t store_rotate(struct device *device,
3351 struct device_attribute *attr, const char *buf,
3354 struct fb_info *info;
3358 if (fbcon_has_exited)
3361 acquire_console_sem();
3362 idx = con2fb_map[fg_console];
3364 if (idx == -1 || registered_fb[idx] == NULL)
3367 info = registered_fb[idx];
3368 rotate = simple_strtoul(buf, last, 0);
3369 fbcon_rotate(info, rotate);
3371 release_console_sem();
3375 static ssize_t store_rotate_all(struct device *device,
3376 struct device_attribute *attr,const char *buf,
3379 struct fb_info *info;
3383 if (fbcon_has_exited)
3386 acquire_console_sem();
3387 idx = con2fb_map[fg_console];
3389 if (idx == -1 || registered_fb[idx] == NULL)
3392 info = registered_fb[idx];
3393 rotate = simple_strtoul(buf, last, 0);
3394 fbcon_rotate_all(info, rotate);
3396 release_console_sem();
3400 static ssize_t show_rotate(struct device *device,
3401 struct device_attribute *attr,char *buf)
3403 struct fb_info *info;
3404 int rotate = 0, idx;
3406 if (fbcon_has_exited)
3409 acquire_console_sem();
3410 idx = con2fb_map[fg_console];
3412 if (idx == -1 || registered_fb[idx] == NULL)
3415 info = registered_fb[idx];
3416 rotate = fbcon_get_rotate(info);
3418 release_console_sem();
3419 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3422 static ssize_t show_cursor_blink(struct device *device,
3423 struct device_attribute *attr, char *buf)
3425 struct fb_info *info;
3426 struct fbcon_ops *ops;
3427 int idx, blink = -1;
3429 if (fbcon_has_exited)
3432 acquire_console_sem();
3433 idx = con2fb_map[fg_console];
3435 if (idx == -1 || registered_fb[idx] == NULL)
3438 info = registered_fb[idx];
3439 ops = info->fbcon_par;
3444 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3446 release_console_sem();
3447 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3450 static ssize_t store_cursor_blink(struct device *device,
3451 struct device_attribute *attr,
3452 const char *buf, size_t count)
3454 struct fb_info *info;
3458 if (fbcon_has_exited)
3461 acquire_console_sem();
3462 idx = con2fb_map[fg_console];
3464 if (idx == -1 || registered_fb[idx] == NULL)
3467 info = registered_fb[idx];
3469 if (!info->fbcon_par)
3472 blink = simple_strtoul(buf, last, 0);
3475 fbcon_cursor_noblink = 0;
3476 fbcon_add_cursor_timer(info);
3478 fbcon_cursor_noblink = 1;
3479 fbcon_del_cursor_timer(info);
3483 release_console_sem();
3487 static struct device_attribute device_attrs[] = {
3488 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3489 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3490 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3491 store_cursor_blink),
3494 static int fbcon_init_device(void)
3498 fbcon_has_sysfs = 1;
3500 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3501 error = device_create_file(fbcon_device, &device_attrs[i]);
3509 device_remove_file(fbcon_device, &device_attrs[i]);
3511 fbcon_has_sysfs = 0;
3517 static void fbcon_start(void)
3519 if (num_registered_fb) {
3522 acquire_console_sem();
3524 for (i = 0; i < FB_MAX; i++) {
3525 if (registered_fb[i] != NULL) {
3531 release_console_sem();
3536 static void fbcon_exit(void)
3538 struct fb_info *info;
3541 if (fbcon_has_exited)
3545 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3548 if (MACH_IS_MAC && vbl_detected)
3549 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
3552 kfree((void *)softback_buf);
3555 for (i = 0; i < FB_MAX; i++) {
3557 info = registered_fb[i];
3562 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3563 if (con2fb_map[j] == i)
3568 if (info->fbops->fb_release)
3569 info->fbops->fb_release(info, 0);
3570 module_put(info->fbops->owner);
3572 if (info->fbcon_par) {
3573 struct fbcon_ops *ops = info->fbcon_par;
3575 fbcon_del_cursor_timer(info);
3576 kfree(ops->cursor_src);
3577 kfree(info->fbcon_par);
3578 info->fbcon_par = NULL;
3581 if (info->queue.func == fb_flashcursor)
3582 info->queue.func = NULL;
3586 fbcon_has_exited = 1;
3589 static int __init fb_console_init(void)
3593 acquire_console_sem();
3594 fb_register_client(&fbcon_event_notifier);
3595 fbcon_device = device_create_drvdata(fb_class, NULL, MKDEV(0, 0),
3598 if (IS_ERR(fbcon_device)) {
3599 printk(KERN_WARNING "Unable to create device "
3600 "for fbcon; errno = %ld\n",
3601 PTR_ERR(fbcon_device));
3602 fbcon_device = NULL;
3604 fbcon_init_device();
3606 for (i = 0; i < MAX_NR_CONSOLES; i++)
3609 release_console_sem();
3614 module_init(fb_console_init);
3618 static void __exit fbcon_deinit_device(void)
3622 if (fbcon_has_sysfs) {
3623 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3624 device_remove_file(fbcon_device, &device_attrs[i]);
3626 fbcon_has_sysfs = 0;
3630 static void __exit fb_console_exit(void)
3632 acquire_console_sem();
3633 fb_unregister_client(&fbcon_event_notifier);
3634 fbcon_deinit_device();
3635 device_destroy(fb_class, MKDEV(0, 0));
3637 release_console_sem();
3638 unregister_con_driver(&fb_con);
3641 module_exit(fb_console_exit);
3645 MODULE_LICENSE("GPL");