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>
84 #if defined(__mc68000__)
85 #include <asm/machdep.h>
86 #include <asm/setup.h>
92 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
94 # define DPRINTK(fmt, args...)
98 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
99 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
100 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
103 static struct display fb_display
[MAX_NR_CONSOLES
];
105 static signed char con2fb_map
[MAX_NR_CONSOLES
];
106 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
108 static int logo_lines
;
109 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
111 static int logo_shown
= FBCON_LOGO_CANSHOW
;
112 /* Software scrollback */
113 static int fbcon_softback_size
= 32768;
114 static unsigned long softback_buf
, softback_curr
;
115 static unsigned long softback_in
;
116 static unsigned long softback_top
, softback_end
;
117 static int softback_lines
;
118 /* console mappings */
119 static int first_fb_vc
;
120 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
121 static int fbcon_is_default
= 1;
122 static int fbcon_has_exited
;
123 static int primary_device
= -1;
125 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
126 static int map_override
;
128 static inline void fbcon_map_override(void)
133 static inline void fbcon_map_override(void)
136 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
139 static char fontname
[40];
141 /* current fb_info */
142 static int info_idx
= -1;
144 /* console rotation */
145 static int initial_rotation
;
146 static int fbcon_has_sysfs
;
148 static const struct consw fb_con
;
150 #define CM_SOFTBACK (8)
152 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
154 static int fbcon_set_origin(struct vc_data
*);
156 #define CURSOR_DRAW_DELAY (1)
158 /* # VBL ints between cursor state changes */
159 #define ATARI_CURSOR_BLINK_RATE (42)
161 static int vbl_cursor_cnt
;
162 static int fbcon_cursor_noblink
;
164 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
167 * Interface used by the world
170 static const char *fbcon_startup(void);
171 static void fbcon_init(struct vc_data
*vc
, int init
);
172 static void fbcon_deinit(struct vc_data
*vc
);
173 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
175 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
176 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
177 int count
, int ypos
, int xpos
);
178 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
179 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
180 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
182 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
183 int height
, int width
);
184 static int fbcon_switch(struct vc_data
*vc
);
185 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
186 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
187 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
192 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
193 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
194 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
195 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
196 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
197 int dy
, int dx
, int height
, int width
, u_int y_break
);
198 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
200 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
201 int line
, int count
, int dy
);
202 static void fbcon_modechanged(struct fb_info
*info
);
203 static void fbcon_set_all_vcs(struct fb_info
*info
);
204 static void fbcon_start(void);
205 static void fbcon_exit(void);
206 static struct device
*fbcon_device
;
208 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
209 static inline void fbcon_set_rotation(struct fb_info
*info
)
211 struct fbcon_ops
*ops
= info
->fbcon_par
;
213 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
214 ops
->p
->con_rotate
< 4)
215 ops
->rotate
= ops
->p
->con_rotate
;
220 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
222 struct fbcon_ops
*ops
= info
->fbcon_par
;
223 struct fb_info
*fb_info
;
225 if (!ops
|| ops
->currcon
== -1)
228 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
230 if (info
== fb_info
) {
231 struct display
*p
= &fb_display
[ops
->currcon
];
234 p
->con_rotate
= rotate
;
238 fbcon_modechanged(info
);
242 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
244 struct fbcon_ops
*ops
= info
->fbcon_par
;
249 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
252 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
254 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
255 registered_fb
[con2fb_map
[i
]] != info
)
258 p
= &fb_display
[vc
->vc_num
];
259 p
->con_rotate
= rotate
;
262 fbcon_set_all_vcs(info
);
265 static inline void fbcon_set_rotation(struct fb_info
*info
)
267 struct fbcon_ops
*ops
= info
->fbcon_par
;
269 ops
->rotate
= FB_ROTATE_UR
;
272 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
277 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
281 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
283 static int fbcon_get_rotate(struct fb_info
*info
)
285 struct fbcon_ops
*ops
= info
->fbcon_par
;
287 return (ops
) ? ops
->rotate
: 0;
290 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
292 struct fbcon_ops
*ops
= info
->fbcon_par
;
294 return (info
->state
!= FBINFO_STATE_RUNNING
||
295 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
298 static inline int get_color(struct vc_data
*vc
, struct fb_info
*info
,
301 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
304 if (console_blanked
) {
305 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
307 c
= vc
->vc_video_erase_char
& charmask
;
311 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
312 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
317 int col
= mono_col(info
);
319 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
320 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
325 color
= (is_fg
) ? fg
: bg
;
330 * Scale down 16-colors to 4 colors. Default 4-color palette
331 * is grayscale. However, simply dividing the values by 4
332 * will not work, as colors 1, 2 and 3 will be scaled-down
333 * to zero rendering them invisible. So empirically convert
334 * colors to a sane 4-level grayscale.
338 color
= 0; /* black */
341 color
= 2; /* white */
344 color
= 1; /* gray */
347 color
= 3; /* intense white */
353 * Last 8 entries of default 16-color palette is a more intense
354 * version of the first 8 (i.e., same chrominance, different
365 static void fbcon_update_softback(struct vc_data
*vc
)
367 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
370 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
372 /* Smaller scrollback makes no sense, and 0 would screw
373 the operation totally */
377 static void fb_flashcursor(struct work_struct
*work
)
379 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
380 struct fbcon_ops
*ops
= info
->fbcon_par
;
382 struct vc_data
*vc
= NULL
;
386 acquire_console_sem();
387 if (ops
&& ops
->currcon
!= -1)
388 vc
= vc_cons
[ops
->currcon
].d
;
390 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
391 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
393 release_console_sem();
397 p
= &fb_display
[vc
->vc_num
];
398 c
= scr_readw((u16
*) vc
->vc_pos
);
399 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
401 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
402 get_color(vc
, info
, c
, 0));
403 release_console_sem();
407 static int cursor_blink_rate
;
408 static irqreturn_t
fb_vbl_handler(int irq
, void *dev_id
)
410 struct fb_info
*info
= dev_id
;
412 if (vbl_cursor_cnt
&& --vbl_cursor_cnt
== 0) {
413 schedule_work(&info
->queue
);
414 vbl_cursor_cnt
= cursor_blink_rate
;
420 static void cursor_timer_handler(unsigned long dev_addr
)
422 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
423 struct fbcon_ops
*ops
= info
->fbcon_par
;
425 schedule_work(&info
->queue
);
426 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
429 static void fbcon_add_cursor_timer(struct fb_info
*info
)
431 struct fbcon_ops
*ops
= info
->fbcon_par
;
433 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
434 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
435 !fbcon_cursor_noblink
) {
436 if (!info
->queue
.func
)
437 INIT_WORK(&info
->queue
, fb_flashcursor
);
439 init_timer(&ops
->cursor_timer
);
440 ops
->cursor_timer
.function
= cursor_timer_handler
;
441 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
442 ops
->cursor_timer
.data
= (unsigned long ) info
;
443 add_timer(&ops
->cursor_timer
);
444 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
448 static void fbcon_del_cursor_timer(struct fb_info
*info
)
450 struct fbcon_ops
*ops
= info
->fbcon_par
;
452 if (info
->queue
.func
== fb_flashcursor
&&
453 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
454 del_timer_sync(&ops
->cursor_timer
);
455 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
460 static int __init
fb_console_setup(char *this_opt
)
465 if (!this_opt
|| !*this_opt
)
468 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
469 if (!strncmp(options
, "font:", 5))
470 strcpy(fontname
, options
+ 5);
472 if (!strncmp(options
, "scrollback:", 11)) {
475 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
476 if (*options
== 'k' || *options
== 'K') {
477 fbcon_softback_size
*= 1024;
487 if (!strncmp(options
, "map:", 4)) {
490 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
494 (options
[j
++]-'0') % FB_MAX
;
497 fbcon_map_override();
503 if (!strncmp(options
, "vc:", 3)) {
506 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
509 if (*options
++ == '-')
510 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
511 fbcon_is_default
= 0;
514 if (!strncmp(options
, "rotate:", 7)) {
517 initial_rotation
= simple_strtoul(options
, &options
, 0);
518 if (initial_rotation
> 3)
519 initial_rotation
= 0;
525 __setup("fbcon=", fb_console_setup
);
528 static int search_fb_in_map(int idx
)
532 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
533 if (con2fb_map
[i
] == idx
)
539 static int search_for_mapped_con(void)
543 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
544 if (con2fb_map
[i
] != -1)
550 static int fbcon_takeover(int show_logo
)
554 if (!num_registered_fb
)
558 logo_shown
= FBCON_LOGO_DONTSHOW
;
560 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
561 con2fb_map
[i
] = info_idx
;
563 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
567 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
577 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
578 int cols
, int rows
, int new_cols
, int new_rows
)
580 logo_shown
= FBCON_LOGO_DONTSHOW
;
583 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
584 int cols
, int rows
, int new_cols
, int new_rows
)
586 /* Need to make room for the logo */
587 struct fbcon_ops
*ops
= info
->fbcon_par
;
588 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
589 unsigned short *save
= NULL
, *r
, *q
;
592 if (info
->flags
& FBINFO_MODULE
) {
593 logo_shown
= FBCON_LOGO_DONTSHOW
;
598 * remove underline attribute from erase character
599 * if black and white framebuffer.
601 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
603 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
604 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
605 q
= (unsigned short *) (vc
->vc_origin
+
606 vc
->vc_size_row
* rows
);
607 step
= logo_lines
* cols
;
608 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
609 if (scr_readw(r
) != vc
->vc_video_erase_char
)
611 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
612 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
614 int i
= cols
< new_cols
? cols
: new_cols
;
615 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
617 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
618 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
623 /* We can scroll screen down */
625 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
626 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
631 if (vc
->vc_y
+ logo_lines
>= rows
)
632 lines
= rows
- vc
->vc_y
- 1;
636 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
639 scr_memsetw((unsigned short *) vc
->vc_origin
,
641 vc
->vc_size_row
* logo_lines
);
643 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
644 fbcon_clear_margins(vc
, 0);
649 q
= (unsigned short *) (vc
->vc_origin
+
652 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
653 vc
->vc_y
+= logo_lines
;
654 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
658 if (logo_lines
> vc
->vc_bottom
) {
659 logo_shown
= FBCON_LOGO_CANSHOW
;
661 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
662 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
663 logo_shown
= FBCON_LOGO_DRAW
;
664 vc
->vc_top
= logo_lines
;
669 #ifdef CONFIG_FB_TILEBLITTING
670 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
672 struct fbcon_ops
*ops
= info
->fbcon_par
;
674 ops
->p
= &fb_display
[vc
->vc_num
];
676 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
677 fbcon_set_tileops(vc
, info
);
679 fbcon_set_rotation(info
);
680 fbcon_set_bitops(ops
);
684 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
688 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
689 info
->tileops
->fb_get_tilemax(info
) < charcount
)
695 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
697 struct fbcon_ops
*ops
= info
->fbcon_par
;
699 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
700 ops
->p
= &fb_display
[vc
->vc_num
];
701 fbcon_set_rotation(info
);
702 fbcon_set_bitops(ops
);
705 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
710 #endif /* CONFIG_MISC_TILEBLITTING */
713 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
714 int unit
, int oldidx
)
716 struct fbcon_ops
*ops
= NULL
;
719 if (!try_module_get(info
->fbops
->owner
))
722 if (!err
&& info
->fbops
->fb_open
&&
723 info
->fbops
->fb_open(info
, 0))
727 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
733 info
->fbcon_par
= ops
;
736 set_blitting_type(vc
, info
);
740 con2fb_map
[unit
] = oldidx
;
741 module_put(info
->fbops
->owner
);
747 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
748 struct fb_info
*newinfo
, int unit
,
749 int oldidx
, int found
)
751 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
754 if (oldinfo
->fbops
->fb_release
&&
755 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
756 con2fb_map
[unit
] = oldidx
;
757 if (!found
&& newinfo
->fbops
->fb_release
)
758 newinfo
->fbops
->fb_release(newinfo
, 0);
760 module_put(newinfo
->fbops
->owner
);
765 fbcon_del_cursor_timer(oldinfo
);
766 kfree(ops
->cursor_state
.mask
);
767 kfree(ops
->cursor_data
);
768 kfree(ops
->fontbuffer
);
769 kfree(oldinfo
->fbcon_par
);
770 oldinfo
->fbcon_par
= NULL
;
771 module_put(oldinfo
->fbops
->owner
);
773 If oldinfo and newinfo are driving the same hardware,
774 the fb_release() method of oldinfo may attempt to
775 restore the hardware state. This will leave the
776 newinfo in an undefined state. Thus, a call to
777 fb_set_par() may be needed for the newinfo.
779 if (newinfo
->fbops
->fb_set_par
)
780 newinfo
->fbops
->fb_set_par(newinfo
);
786 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
787 int unit
, int show_logo
)
789 struct fbcon_ops
*ops
= info
->fbcon_par
;
791 ops
->currcon
= fg_console
;
793 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
))
794 info
->fbops
->fb_set_par(info
);
796 ops
->flags
|= FBCON_FLAGS_INIT
;
798 fbcon_set_disp(info
, &info
->var
, unit
);
801 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
802 struct fb_info
*fg_info
=
803 registered_fb
[con2fb_map
[fg_console
]];
805 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
806 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
810 update_screen(vc_cons
[fg_console
].d
);
814 * set_con2fb_map - map console to frame buffer device
815 * @unit: virtual console number to map
816 * @newidx: frame buffer index to map virtual console to
817 * @user: user request
819 * Maps a virtual console @unit to a frame buffer device
822 static int set_con2fb_map(int unit
, int newidx
, int user
)
824 struct vc_data
*vc
= vc_cons
[unit
].d
;
825 int oldidx
= con2fb_map
[unit
];
826 struct fb_info
*info
= registered_fb
[newidx
];
827 struct fb_info
*oldinfo
= NULL
;
830 if (oldidx
== newidx
)
833 if (!info
|| fbcon_has_exited
)
836 if (!err
&& !search_for_mapped_con()) {
838 return fbcon_takeover(0);
842 oldinfo
= registered_fb
[oldidx
];
844 found
= search_fb_in_map(newidx
);
846 acquire_console_sem();
847 con2fb_map
[unit
] = newidx
;
849 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
853 * If old fb is not mapped to any of the consoles,
854 * fbcon should release it.
856 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
857 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
861 int show_logo
= (fg_console
== 0 && !user
&&
862 logo_shown
!= FBCON_LOGO_DONTSHOW
);
865 fbcon_add_cursor_timer(info
);
866 con2fb_map_boot
[unit
] = newidx
;
867 con2fb_init_display(vc
, info
, unit
, show_logo
);
870 if (!search_fb_in_map(info_idx
))
873 release_console_sem();
878 * Low Level Operations
880 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
881 static int var_to_display(struct display
*disp
,
882 struct fb_var_screeninfo
*var
,
883 struct fb_info
*info
)
885 disp
->xres_virtual
= var
->xres_virtual
;
886 disp
->yres_virtual
= var
->yres_virtual
;
887 disp
->bits_per_pixel
= var
->bits_per_pixel
;
888 disp
->grayscale
= var
->grayscale
;
889 disp
->nonstd
= var
->nonstd
;
890 disp
->accel_flags
= var
->accel_flags
;
891 disp
->height
= var
->height
;
892 disp
->width
= var
->width
;
893 disp
->red
= var
->red
;
894 disp
->green
= var
->green
;
895 disp
->blue
= var
->blue
;
896 disp
->transp
= var
->transp
;
897 disp
->rotate
= var
->rotate
;
898 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
899 if (disp
->mode
== NULL
)
900 /* This should not happen */
905 static void display_to_var(struct fb_var_screeninfo
*var
,
906 struct display
*disp
)
908 fb_videomode_to_var(var
, disp
->mode
);
909 var
->xres_virtual
= disp
->xres_virtual
;
910 var
->yres_virtual
= disp
->yres_virtual
;
911 var
->bits_per_pixel
= disp
->bits_per_pixel
;
912 var
->grayscale
= disp
->grayscale
;
913 var
->nonstd
= disp
->nonstd
;
914 var
->accel_flags
= disp
->accel_flags
;
915 var
->height
= disp
->height
;
916 var
->width
= disp
->width
;
917 var
->red
= disp
->red
;
918 var
->green
= disp
->green
;
919 var
->blue
= disp
->blue
;
920 var
->transp
= disp
->transp
;
921 var
->rotate
= disp
->rotate
;
924 static const char *fbcon_startup(void)
926 const char *display_desc
= "frame buffer device";
927 struct display
*p
= &fb_display
[fg_console
];
928 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
929 const struct font_desc
*font
= NULL
;
930 struct module
*owner
;
931 struct fb_info
*info
= NULL
;
932 struct fbcon_ops
*ops
;
936 * If num_registered_fb is zero, this is a call for the dummy part.
937 * The frame buffer devices weren't initialized yet.
939 if (!num_registered_fb
|| info_idx
== -1)
942 * Instead of blindly using registered_fb[0], we use info_idx, set by
945 info
= registered_fb
[info_idx
];
949 owner
= info
->fbops
->owner
;
950 if (!try_module_get(owner
))
952 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
957 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
965 ops
->cur_rotate
= -1;
966 info
->fbcon_par
= ops
;
967 p
->con_rotate
= initial_rotation
;
968 set_blitting_type(vc
, info
);
970 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
971 if (fbcon_softback_size
) {
975 kmalloc(fbcon_softback_size
,
978 fbcon_softback_size
= 0;
984 kfree((void *) softback_buf
);
990 softback_in
= softback_top
= softback_curr
=
995 /* Setup default font */
997 if (!fontname
[0] || !(font
= find_font(fontname
)))
998 font
= get_default_font(info
->var
.xres
,
1000 info
->pixmap
.blit_x
,
1001 info
->pixmap
.blit_y
);
1002 vc
->vc_font
.width
= font
->width
;
1003 vc
->vc_font
.height
= font
->height
;
1004 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1005 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1008 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1009 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1010 cols
/= vc
->vc_font
.width
;
1011 rows
/= vc
->vc_font
.height
;
1012 vc_resize(vc
, cols
, rows
);
1014 DPRINTK("mode: %s\n", info
->fix
.id
);
1015 DPRINTK("visual: %d\n", info
->fix
.visual
);
1016 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1018 info
->var
.bits_per_pixel
);
1021 if (MACH_IS_ATARI
) {
1022 cursor_blink_rate
= ATARI_CURSOR_BLINK_RATE
;
1023 (void)request_irq(IRQ_AUTO_4
, fb_vbl_handler
,
1024 IRQ_TYPE_PRIO
, "framebuffer vbl",
1027 #endif /* CONFIG_ATARI */
1029 fbcon_add_cursor_timer(info
);
1030 fbcon_has_exited
= 0;
1031 return display_desc
;
1034 static void fbcon_init(struct vc_data
*vc
, int init
)
1036 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1037 struct fbcon_ops
*ops
;
1038 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1039 struct vc_data
*svc
= *default_mode
;
1040 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1041 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1044 if (info_idx
== -1 || info
== NULL
)
1049 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1050 (info
->fix
.type
== FB_TYPE_TEXT
))
1053 if (var_to_display(p
, &info
->var
, info
))
1056 if (!info
->fbcon_par
)
1057 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1059 /* If we are not the first console on this
1060 fb, copy the font from that console */
1061 t
= &fb_display
[fg_console
];
1064 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1066 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1068 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1069 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1070 p
->userfont
= t
->userfont
;
1073 REFCOUNT(p
->fontdata
)++;
1075 const struct font_desc
*font
= NULL
;
1077 if (!fontname
[0] || !(font
= find_font(fontname
)))
1078 font
= get_default_font(info
->var
.xres
,
1080 info
->pixmap
.blit_x
,
1081 info
->pixmap
.blit_y
);
1082 vc
->vc_font
.width
= font
->width
;
1083 vc
->vc_font
.height
= font
->height
;
1084 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1085 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1086 support more fonts */
1091 charcnt
= FNTCHARCNT(p
->fontdata
);
1093 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1094 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1095 if (charcnt
== 256) {
1096 vc
->vc_hi_font_mask
= 0;
1098 vc
->vc_hi_font_mask
= 0x100;
1099 if (vc
->vc_can_do_color
)
1100 vc
->vc_complement_mask
<<= 1;
1103 if (!*svc
->vc_uni_pagedir_loc
)
1104 con_set_default_unimap(svc
);
1105 if (!*vc
->vc_uni_pagedir_loc
)
1106 con_copy_unimap(vc
, svc
);
1108 ops
= info
->fbcon_par
;
1109 p
->con_rotate
= initial_rotation
;
1110 set_blitting_type(vc
, info
);
1114 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1115 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1116 new_cols
/= vc
->vc_font
.width
;
1117 new_rows
/= vc
->vc_font
.height
;
1118 vc_resize(vc
, new_cols
, new_rows
);
1121 * We must always set the mode. The mode of the previous console
1122 * driver could be in the same resolution but we are using different
1123 * hardware so we have to initialize the hardware.
1125 * We need to do it in fbcon_init() to prevent screen corruption.
1127 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1128 if (info
->fbops
->fb_set_par
&&
1129 !(ops
->flags
& FBCON_FLAGS_INIT
))
1130 info
->fbops
->fb_set_par(info
);
1131 ops
->flags
|= FBCON_FLAGS_INIT
;
1136 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1137 !(cap
& FBINFO_HWACCEL_DISABLED
))
1138 p
->scrollmode
= SCROLL_MOVE
;
1139 else /* default to something safe */
1140 p
->scrollmode
= SCROLL_REDRAW
;
1143 * ++guenther: console.c:vc_allocate() relies on initializing
1144 * vc_{cols,rows}, but we must not set those if we are only
1145 * resizing the console.
1148 vc
->vc_cols
= new_cols
;
1149 vc
->vc_rows
= new_rows
;
1153 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1155 if (vc
== svc
&& softback_buf
)
1156 fbcon_update_softback(vc
);
1158 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1159 ops
->rotate
= FB_ROTATE_UR
;
1160 set_blitting_type(vc
, info
);
1163 ops
->p
= &fb_display
[fg_console
];
1166 static void fbcon_free_font(struct display
*p
)
1168 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1169 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1174 static void fbcon_deinit(struct vc_data
*vc
)
1176 struct display
*p
= &fb_display
[vc
->vc_num
];
1177 struct fb_info
*info
;
1178 struct fbcon_ops
*ops
;
1182 idx
= con2fb_map
[vc
->vc_num
];
1187 info
= registered_fb
[idx
];
1192 ops
= info
->fbcon_par
;
1197 if (CON_IS_VISIBLE(vc
))
1198 fbcon_del_cursor_timer(info
);
1200 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1203 if (!con_is_bound(&fb_con
))
1209 /* ====================================================================== */
1211 /* fbcon_XXX routines - interface used by the world
1213 * This system is now divided into two levels because of complications
1214 * caused by hardware scrolling. Top level functions:
1216 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1218 * handles y values in range [0, scr_height-1] that correspond to real
1219 * screen positions. y_wrap shift means that first line of bitmap may be
1220 * anywhere on this display. These functions convert lineoffsets to
1221 * bitmap offsets and deal with the wrap-around case by splitting blits.
1223 * fbcon_bmove_physical_8() -- These functions fast implementations
1224 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1225 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1229 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1230 * Implies should only really hardware scroll in rows. Only reason for
1231 * restriction is simplicity & efficiency at the moment.
1234 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1237 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1238 struct fbcon_ops
*ops
= info
->fbcon_par
;
1240 struct display
*p
= &fb_display
[vc
->vc_num
];
1243 if (fbcon_is_inactive(vc
, info
))
1246 if (!height
|| !width
)
1249 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
)
1252 /* Split blits that cross physical y_wrap boundary */
1254 y_break
= p
->vrows
- p
->yscroll
;
1255 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1256 u_int b
= y_break
- sy
;
1257 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1258 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1261 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1264 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1265 int count
, int ypos
, int xpos
)
1267 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1268 struct display
*p
= &fb_display
[vc
->vc_num
];
1269 struct fbcon_ops
*ops
= info
->fbcon_par
;
1271 if (!fbcon_is_inactive(vc
, info
))
1272 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1273 get_color(vc
, info
, scr_readw(s
), 1),
1274 get_color(vc
, info
, scr_readw(s
), 0));
1277 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1281 scr_writew(c
, &chr
);
1282 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1285 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1287 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1288 struct fbcon_ops
*ops
= info
->fbcon_par
;
1290 if (!fbcon_is_inactive(vc
, info
))
1291 ops
->clear_margins(vc
, info
, bottom_only
);
1294 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1296 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1297 struct fbcon_ops
*ops
= info
->fbcon_par
;
1299 int c
= scr_readw((u16
*) vc
->vc_pos
);
1301 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1304 if (vc
->vc_cursor_type
& 0x10)
1305 fbcon_del_cursor_timer(info
);
1307 fbcon_add_cursor_timer(info
);
1309 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1310 if (mode
& CM_SOFTBACK
) {
1311 mode
&= ~CM_SOFTBACK
;
1315 fbcon_set_origin(vc
);
1319 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1320 get_color(vc
, info
, c
, 0));
1321 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1324 static int scrollback_phys_max
= 0;
1325 static int scrollback_max
= 0;
1326 static int scrollback_current
= 0;
1328 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1331 struct display
*p
, *t
;
1332 struct vc_data
**default_mode
, *vc
;
1333 struct vc_data
*svc
;
1334 struct fbcon_ops
*ops
= info
->fbcon_par
;
1335 int rows
, cols
, charcnt
= 256;
1337 p
= &fb_display
[unit
];
1339 if (var_to_display(p
, var
, info
))
1342 vc
= vc_cons
[unit
].d
;
1347 default_mode
= vc
->vc_display_fg
;
1348 svc
= *default_mode
;
1349 t
= &fb_display
[svc
->vc_num
];
1351 if (!vc
->vc_font
.data
) {
1352 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1353 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1354 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1355 p
->userfont
= t
->userfont
;
1357 REFCOUNT(p
->fontdata
)++;
1360 charcnt
= FNTCHARCNT(p
->fontdata
);
1362 var
->activate
= FB_ACTIVATE_NOW
;
1363 info
->var
.activate
= var
->activate
;
1364 var
->yoffset
= info
->var
.yoffset
;
1365 var
->xoffset
= info
->var
.xoffset
;
1366 fb_set_var(info
, var
);
1367 ops
->var
= info
->var
;
1368 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1369 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1370 if (charcnt
== 256) {
1371 vc
->vc_hi_font_mask
= 0;
1373 vc
->vc_hi_font_mask
= 0x100;
1374 if (vc
->vc_can_do_color
)
1375 vc
->vc_complement_mask
<<= 1;
1378 if (!*svc
->vc_uni_pagedir_loc
)
1379 con_set_default_unimap(svc
);
1380 if (!*vc
->vc_uni_pagedir_loc
)
1381 con_copy_unimap(vc
, svc
);
1383 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1384 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1385 cols
/= vc
->vc_font
.width
;
1386 rows
/= vc
->vc_font
.height
;
1387 vc_resize(vc
, cols
, rows
);
1389 if (CON_IS_VISIBLE(vc
)) {
1392 fbcon_update_softback(vc
);
1396 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1398 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1399 struct fbcon_ops
*ops
= info
->fbcon_par
;
1400 struct display
*p
= &fb_display
[vc
->vc_num
];
1402 p
->yscroll
+= count
;
1403 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1404 p
->yscroll
-= p
->vrows
;
1405 ops
->var
.xoffset
= 0;
1406 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1407 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1408 ops
->update_start(info
);
1409 scrollback_max
+= count
;
1410 if (scrollback_max
> scrollback_phys_max
)
1411 scrollback_max
= scrollback_phys_max
;
1412 scrollback_current
= 0;
1415 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1417 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1418 struct fbcon_ops
*ops
= info
->fbcon_par
;
1419 struct display
*p
= &fb_display
[vc
->vc_num
];
1421 p
->yscroll
-= count
;
1422 if (p
->yscroll
< 0) /* Deal with wrap */
1423 p
->yscroll
+= p
->vrows
;
1424 ops
->var
.xoffset
= 0;
1425 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1426 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1427 ops
->update_start(info
);
1428 scrollback_max
-= count
;
1429 if (scrollback_max
< 0)
1431 scrollback_current
= 0;
1434 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1436 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1437 struct display
*p
= &fb_display
[vc
->vc_num
];
1438 struct fbcon_ops
*ops
= info
->fbcon_par
;
1440 p
->yscroll
+= count
;
1441 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1442 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1443 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1444 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1447 ops
->var
.xoffset
= 0;
1448 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1449 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1450 ops
->update_start(info
);
1451 fbcon_clear_margins(vc
, 1);
1452 scrollback_max
+= count
;
1453 if (scrollback_max
> scrollback_phys_max
)
1454 scrollback_max
= scrollback_phys_max
;
1455 scrollback_current
= 0;
1458 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1460 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1461 struct fbcon_ops
*ops
= info
->fbcon_par
;
1462 struct display
*p
= &fb_display
[vc
->vc_num
];
1464 p
->yscroll
+= count
;
1466 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1467 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1468 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1471 ops
->var
.xoffset
= 0;
1472 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1473 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1474 ops
->update_start(info
);
1475 fbcon_clear_margins(vc
, 1);
1476 scrollback_max
+= count
;
1477 if (scrollback_max
> scrollback_phys_max
)
1478 scrollback_max
= scrollback_phys_max
;
1479 scrollback_current
= 0;
1482 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1484 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1485 struct display
*p
= &fb_display
[vc
->vc_num
];
1486 struct fbcon_ops
*ops
= info
->fbcon_par
;
1488 p
->yscroll
-= count
;
1489 if (p
->yscroll
< 0) {
1490 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1491 0, vc
->vc_rows
, vc
->vc_cols
);
1492 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1495 ops
->var
.xoffset
= 0;
1496 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1497 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1498 ops
->update_start(info
);
1499 fbcon_clear_margins(vc
, 1);
1500 scrollback_max
-= count
;
1501 if (scrollback_max
< 0)
1503 scrollback_current
= 0;
1506 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1508 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1509 struct fbcon_ops
*ops
= info
->fbcon_par
;
1510 struct display
*p
= &fb_display
[vc
->vc_num
];
1512 p
->yscroll
-= count
;
1514 if (p
->yscroll
< 0) {
1515 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1516 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1519 ops
->var
.xoffset
= 0;
1520 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1521 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1522 ops
->update_start(info
);
1523 fbcon_clear_margins(vc
, 1);
1524 scrollback_max
-= count
;
1525 if (scrollback_max
< 0)
1527 scrollback_current
= 0;
1530 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1533 int count
= vc
->vc_rows
;
1534 unsigned short *d
, *s
;
1538 d
= (u16
*) softback_curr
;
1539 if (d
== (u16
*) softback_in
)
1540 d
= (u16
*) vc
->vc_origin
;
1541 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1542 softback_lines
-= delta
;
1544 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1545 n
+= softback_end
- softback_buf
;
1546 if (n
< softback_top
) {
1548 (softback_top
- n
) / vc
->vc_size_row
;
1551 } else if (softback_curr
>= softback_top
1552 && n
< softback_top
) {
1554 (softback_top
- n
) / vc
->vc_size_row
;
1558 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1559 n
+= softback_buf
- softback_end
;
1560 if (n
> softback_in
) {
1564 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1569 if (n
== softback_curr
)
1572 s
= (u16
*) softback_curr
;
1573 if (s
== (u16
*) softback_in
)
1574 s
= (u16
*) vc
->vc_origin
;
1576 unsigned short *start
;
1580 unsigned short attr
= 1;
1583 le
= advance_row(s
, 1);
1586 if (attr
!= (c
& 0xff00)) {
1589 fbcon_putcs(vc
, start
, s
- start
,
1595 if (c
== scr_readw(d
)) {
1597 fbcon_putcs(vc
, start
, s
- start
,
1610 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1612 if (d
== (u16
*) softback_end
)
1613 d
= (u16
*) softback_buf
;
1614 if (d
== (u16
*) softback_in
)
1615 d
= (u16
*) vc
->vc_origin
;
1616 if (s
== (u16
*) softback_end
)
1617 s
= (u16
*) softback_buf
;
1618 if (s
== (u16
*) softback_in
)
1619 s
= (u16
*) vc
->vc_origin
;
1623 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1624 int line
, int count
, int dy
)
1626 unsigned short *s
= (unsigned short *)
1627 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1630 unsigned short *start
= s
;
1631 unsigned short *le
= advance_row(s
, 1);
1634 unsigned short attr
= 1;
1638 if (attr
!= (c
& 0xff00)) {
1641 fbcon_putcs(vc
, start
, s
- start
,
1647 console_conditional_schedule();
1651 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1652 console_conditional_schedule();
1657 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1658 struct display
*p
, int line
, int count
, int ycount
)
1660 int offset
= ycount
* vc
->vc_cols
;
1661 unsigned short *d
= (unsigned short *)
1662 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1663 unsigned short *s
= d
+ offset
;
1664 struct fbcon_ops
*ops
= info
->fbcon_par
;
1667 unsigned short *start
= s
;
1668 unsigned short *le
= advance_row(s
, 1);
1675 if (c
== scr_readw(d
)) {
1677 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1678 line
, x
, 1, s
-start
);
1688 console_conditional_schedule();
1693 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1695 console_conditional_schedule();
1700 /* NOTE: We subtract two lines from these pointers */
1701 s
-= vc
->vc_size_row
;
1702 d
-= vc
->vc_size_row
;
1707 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1708 int line
, int count
, int offset
)
1710 unsigned short *d
= (unsigned short *)
1711 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1712 unsigned short *s
= d
+ offset
;
1715 unsigned short *start
= s
;
1716 unsigned short *le
= advance_row(s
, 1);
1719 unsigned short attr
= 1;
1723 if (attr
!= (c
& 0xff00)) {
1726 fbcon_putcs(vc
, start
, s
- start
,
1732 if (c
== scr_readw(d
)) {
1734 fbcon_putcs(vc
, start
, s
- start
,
1744 console_conditional_schedule();
1749 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1750 console_conditional_schedule();
1755 /* NOTE: We subtract two lines from these pointers */
1756 s
-= vc
->vc_size_row
;
1757 d
-= vc
->vc_size_row
;
1762 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1767 if (vc
->vc_num
!= fg_console
)
1769 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1772 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1774 p
= advance_row(p
, 1);
1775 softback_in
+= vc
->vc_size_row
;
1776 if (softback_in
== softback_end
)
1777 softback_in
= softback_buf
;
1778 if (softback_in
== softback_top
) {
1779 softback_top
+= vc
->vc_size_row
;
1780 if (softback_top
== softback_end
)
1781 softback_top
= softback_buf
;
1784 softback_curr
= softback_in
;
1787 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1790 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1791 struct display
*p
= &fb_display
[vc
->vc_num
];
1792 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1794 if (fbcon_is_inactive(vc
, info
))
1797 fbcon_cursor(vc
, CM_ERASE
);
1800 * ++Geert: Only use ywrap/ypan if the console is in text mode
1801 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1802 * whole screen (prevents flicker).
1807 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1808 count
= vc
->vc_rows
;
1810 fbcon_softback_note(vc
, t
, count
);
1811 if (logo_shown
>= 0)
1813 switch (p
->scrollmode
) {
1815 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1817 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1818 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1821 vc
->vc_video_erase_char
,
1822 vc
->vc_size_row
* count
);
1826 case SCROLL_WRAP_MOVE
:
1827 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1829 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1831 ywrap_up(vc
, count
);
1832 if (vc
->vc_rows
- b
> 0)
1833 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1836 } else if (info
->flags
& FBINFO_READS_FAST
)
1837 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1838 b
- t
- count
, vc
->vc_cols
);
1841 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1844 case SCROLL_PAN_REDRAW
:
1845 if ((p
->yscroll
+ count
<=
1846 2 * (p
->vrows
- vc
->vc_rows
))
1847 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1850 3 * vc
->vc_rows
>> 2)))) {
1852 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1853 ypan_up_redraw(vc
, t
, count
);
1854 if (vc
->vc_rows
- b
> 0)
1855 fbcon_redraw_move(vc
, p
, b
,
1856 vc
->vc_rows
- b
, b
);
1858 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1859 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1862 case SCROLL_PAN_MOVE
:
1863 if ((p
->yscroll
+ count
<=
1864 2 * (p
->vrows
- vc
->vc_rows
))
1865 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1868 3 * vc
->vc_rows
>> 2)))) {
1870 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1873 if (vc
->vc_rows
- b
> 0)
1874 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1877 } else if (info
->flags
& FBINFO_READS_FAST
)
1878 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1879 b
- t
- count
, vc
->vc_cols
);
1882 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1887 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1888 count
* vc
->vc_cols
);
1889 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1890 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1893 vc
->vc_video_erase_char
,
1894 vc
->vc_size_row
* count
);
1900 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1901 count
= vc
->vc_rows
;
1902 if (logo_shown
>= 0)
1904 switch (p
->scrollmode
) {
1906 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1908 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1909 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1912 vc
->vc_video_erase_char
,
1913 vc
->vc_size_row
* count
);
1917 case SCROLL_WRAP_MOVE
:
1918 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1919 if (vc
->vc_rows
- b
> 0)
1920 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1923 ywrap_down(vc
, count
);
1925 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1927 } else if (info
->flags
& FBINFO_READS_FAST
)
1928 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1929 b
- t
- count
, vc
->vc_cols
);
1932 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1935 case SCROLL_PAN_MOVE
:
1936 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1937 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1940 3 * vc
->vc_rows
>> 2)))) {
1941 if (vc
->vc_rows
- b
> 0)
1942 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1945 ypan_down(vc
, count
);
1947 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1949 } else if (info
->flags
& FBINFO_READS_FAST
)
1950 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1951 b
- t
- count
, vc
->vc_cols
);
1954 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1957 case SCROLL_PAN_REDRAW
:
1958 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1959 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1962 3 * vc
->vc_rows
>> 2)))) {
1963 if (vc
->vc_rows
- b
> 0)
1964 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1966 ypan_down_redraw(vc
, t
, count
);
1968 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1970 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1971 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1976 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1977 -count
* vc
->vc_cols
);
1978 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1979 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1982 vc
->vc_video_erase_char
,
1983 vc
->vc_size_row
* count
);
1991 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1992 int height
, int width
)
1994 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1995 struct display
*p
= &fb_display
[vc
->vc_num
];
1997 if (fbcon_is_inactive(vc
, info
))
2000 if (!width
|| !height
)
2003 /* Split blits that cross physical y_wrap case.
2004 * Pathological case involves 4 blits, better to use recursive
2005 * code rather than unrolled case
2007 * Recursive invocations don't need to erase the cursor over and
2008 * over again, so we use fbcon_bmove_rec()
2010 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2011 p
->vrows
- p
->yscroll
);
2014 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2015 int dy
, int dx
, int height
, int width
, u_int y_break
)
2017 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2018 struct fbcon_ops
*ops
= info
->fbcon_par
;
2021 if (sy
< y_break
&& sy
+ height
> y_break
) {
2023 if (dy
< sy
) { /* Avoid trashing self */
2024 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2026 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2027 height
- b
, width
, y_break
);
2029 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2030 height
- b
, width
, y_break
);
2031 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2037 if (dy
< y_break
&& dy
+ height
> y_break
) {
2039 if (dy
< sy
) { /* Avoid trashing self */
2040 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2042 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2043 height
- b
, width
, y_break
);
2045 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2046 height
- b
, width
, y_break
);
2047 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2052 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2056 static void updatescrollmode(struct display
*p
,
2057 struct fb_info
*info
,
2060 struct fbcon_ops
*ops
= info
->fbcon_par
;
2061 int fh
= vc
->vc_font
.height
;
2062 int cap
= info
->flags
;
2064 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2065 info
->fix
.xpanstep
);
2066 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2067 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2068 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2069 info
->var
.xres_virtual
);
2070 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2071 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2072 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2073 divides(ywrap
, vc
->vc_font
.height
) &&
2074 divides(vc
->vc_font
.height
, vyres
) &&
2075 divides(vc
->vc_font
.height
, yres
);
2076 int reading_fast
= cap
& FBINFO_READS_FAST
;
2077 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2078 !(cap
& FBINFO_HWACCEL_DISABLED
);
2079 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2080 !(cap
& FBINFO_HWACCEL_DISABLED
);
2082 p
->vrows
= vyres
/fh
;
2083 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2084 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2085 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2088 if (good_wrap
|| good_pan
) {
2089 if (reading_fast
|| fast_copyarea
)
2090 p
->scrollmode
= good_wrap
?
2091 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2093 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2096 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2097 p
->scrollmode
= SCROLL_MOVE
;
2099 p
->scrollmode
= SCROLL_REDRAW
;
2103 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2104 unsigned int height
, unsigned int user
)
2106 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2107 struct fbcon_ops
*ops
= info
->fbcon_par
;
2108 struct display
*p
= &fb_display
[vc
->vc_num
];
2109 struct fb_var_screeninfo var
= info
->var
;
2110 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2112 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2113 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2114 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2115 vc
->vc_font
.height
);
2116 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2118 var
.xres
= virt_w
* virt_fw
;
2119 var
.yres
= virt_h
* virt_fh
;
2120 x_diff
= info
->var
.xres
- var
.xres
;
2121 y_diff
= info
->var
.yres
- var
.yres
;
2122 if (x_diff
< 0 || x_diff
> virt_fw
||
2123 y_diff
< 0 || y_diff
> virt_fh
) {
2124 const struct fb_videomode
*mode
;
2126 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2127 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2130 display_to_var(&var
, p
);
2131 fb_videomode_to_var(&var
, mode
);
2133 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2136 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2137 if (CON_IS_VISIBLE(vc
)) {
2138 var
.activate
= FB_ACTIVATE_NOW
|
2140 fb_set_var(info
, &var
);
2142 var_to_display(p
, &info
->var
, info
);
2143 ops
->var
= info
->var
;
2145 updatescrollmode(p
, info
, vc
);
2149 static int fbcon_switch(struct vc_data
*vc
)
2151 struct fb_info
*info
, *old_info
= NULL
;
2152 struct fbcon_ops
*ops
;
2153 struct display
*p
= &fb_display
[vc
->vc_num
];
2154 struct fb_var_screeninfo var
;
2155 int i
, prev_console
, charcnt
= 256;
2157 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2158 ops
= info
->fbcon_par
;
2162 fbcon_set_origin(vc
);
2163 softback_top
= softback_curr
= softback_in
= softback_buf
;
2165 fbcon_update_softback(vc
);
2168 if (logo_shown
>= 0) {
2169 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2171 if (conp2
->vc_top
== logo_lines
2172 && conp2
->vc_bottom
== conp2
->vc_rows
)
2174 logo_shown
= FBCON_LOGO_CANSHOW
;
2177 prev_console
= ops
->currcon
;
2178 if (prev_console
!= -1)
2179 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2181 * FIXME: If we have multiple fbdev's loaded, we need to
2182 * update all info->currcon. Perhaps, we can place this
2183 * in a centralized structure, but this might break some
2186 * info->currcon = vc->vc_num;
2188 for (i
= 0; i
< FB_MAX
; i
++) {
2189 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2190 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2192 o
->currcon
= vc
->vc_num
;
2195 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2196 display_to_var(&var
, p
);
2197 var
.activate
= FB_ACTIVATE_NOW
;
2200 * make sure we don't unnecessarily trip the memcmp()
2203 info
->var
.activate
= var
.activate
;
2204 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2205 fb_set_var(info
, &var
);
2206 ops
->var
= info
->var
;
2208 if (old_info
!= NULL
&& (old_info
!= info
||
2209 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2210 if (info
->fbops
->fb_set_par
)
2211 info
->fbops
->fb_set_par(info
);
2213 if (old_info
!= info
)
2214 fbcon_del_cursor_timer(old_info
);
2217 if (fbcon_is_inactive(vc
, info
) ||
2218 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2219 fbcon_del_cursor_timer(info
);
2221 fbcon_add_cursor_timer(info
);
2223 set_blitting_type(vc
, info
);
2224 ops
->cursor_reset
= 1;
2226 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2227 ops
->rotate
= FB_ROTATE_UR
;
2228 set_blitting_type(vc
, info
);
2231 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2232 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2235 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2238 vc
->vc_complement_mask
<<= 1;
2240 updatescrollmode(p
, info
, vc
);
2242 switch (p
->scrollmode
) {
2243 case SCROLL_WRAP_MOVE
:
2244 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2246 case SCROLL_PAN_MOVE
:
2247 case SCROLL_PAN_REDRAW
:
2248 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2249 if (scrollback_phys_max
< 0)
2250 scrollback_phys_max
= 0;
2253 scrollback_phys_max
= 0;
2258 scrollback_current
= 0;
2260 if (!fbcon_is_inactive(vc
, info
)) {
2261 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2262 ops
->update_start(info
);
2265 fbcon_set_palette(vc
, color_table
);
2266 fbcon_clear_margins(vc
, 0);
2268 if (logo_shown
== FBCON_LOGO_DRAW
) {
2270 logo_shown
= fg_console
;
2271 /* This is protected above by initmem_freed */
2272 fb_show_logo(info
, ops
->rotate
);
2274 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2275 vc
->vc_size_row
* (vc
->vc_bottom
-
2282 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2285 struct fb_event event
;
2288 unsigned short charmask
= vc
->vc_hi_font_mask
?
2290 unsigned short oldc
;
2292 oldc
= vc
->vc_video_erase_char
;
2293 vc
->vc_video_erase_char
&= charmask
;
2294 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2295 vc
->vc_video_erase_char
= oldc
;
2300 event
.data
= &blank
;
2301 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2304 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2306 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2307 struct fbcon_ops
*ops
= info
->fbcon_par
;
2310 struct fb_var_screeninfo var
= info
->var
;
2315 if (info
->fbops
->fb_save_state
)
2316 info
->fbops
->fb_save_state(info
);
2317 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2318 fb_set_var(info
, &var
);
2320 ops
->var
= info
->var
;
2321 } else if (info
->fbops
->fb_restore_state
)
2322 info
->fbops
->fb_restore_state(info
);
2325 if (!fbcon_is_inactive(vc
, info
)) {
2326 if (ops
->blank_state
!= blank
) {
2327 ops
->blank_state
= blank
;
2328 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2329 ops
->cursor_flash
= (!blank
);
2331 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2332 if (fb_blank(info
, blank
))
2333 fbcon_generic_blank(vc
, info
, blank
);
2340 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2341 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2342 fbcon_del_cursor_timer(info
);
2344 fbcon_add_cursor_timer(info
);
2349 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2351 u8
*fontdata
= vc
->vc_font
.data
;
2352 u8
*data
= font
->data
;
2355 font
->width
= vc
->vc_font
.width
;
2356 font
->height
= vc
->vc_font
.height
;
2357 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2361 if (font
->width
<= 8) {
2362 j
= vc
->vc_font
.height
;
2363 for (i
= 0; i
< font
->charcount
; i
++) {
2364 memcpy(data
, fontdata
, j
);
2365 memset(data
+ j
, 0, 32 - j
);
2369 } else if (font
->width
<= 16) {
2370 j
= vc
->vc_font
.height
* 2;
2371 for (i
= 0; i
< font
->charcount
; i
++) {
2372 memcpy(data
, fontdata
, j
);
2373 memset(data
+ j
, 0, 64 - j
);
2377 } else if (font
->width
<= 24) {
2378 for (i
= 0; i
< font
->charcount
; i
++) {
2379 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2380 *data
++ = fontdata
[0];
2381 *data
++ = fontdata
[1];
2382 *data
++ = fontdata
[2];
2383 fontdata
+= sizeof(u32
);
2385 memset(data
, 0, 3 * (32 - j
));
2386 data
+= 3 * (32 - j
);
2389 j
= vc
->vc_font
.height
* 4;
2390 for (i
= 0; i
< font
->charcount
; i
++) {
2391 memcpy(data
, fontdata
, j
);
2392 memset(data
+ j
, 0, 128 - j
);
2400 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2401 const u8
* data
, int userfont
)
2403 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2404 struct fbcon_ops
*ops
= info
->fbcon_par
;
2405 struct display
*p
= &fb_display
[vc
->vc_num
];
2408 char *old_data
= NULL
;
2410 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2411 fbcon_set_origin(vc
);
2413 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2415 old_data
= vc
->vc_font
.data
;
2417 cnt
= FNTCHARCNT(data
);
2420 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2421 if ((p
->userfont
= userfont
))
2423 vc
->vc_font
.width
= w
;
2424 vc
->vc_font
.height
= h
;
2425 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2426 vc
->vc_hi_font_mask
= 0;
2427 if (vc
->vc_can_do_color
) {
2428 vc
->vc_complement_mask
>>= 1;
2429 vc
->vc_s_complement_mask
>>= 1;
2432 /* ++Edmund: reorder the attribute bits */
2433 if (vc
->vc_can_do_color
) {
2434 unsigned short *cp
=
2435 (unsigned short *) vc
->vc_origin
;
2436 int count
= vc
->vc_screenbuf_size
/ 2;
2438 for (; count
> 0; count
--, cp
++) {
2440 scr_writew(((c
& 0xfe00) >> 1) |
2443 c
= vc
->vc_video_erase_char
;
2444 vc
->vc_video_erase_char
=
2445 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2448 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2449 vc
->vc_hi_font_mask
= 0x100;
2450 if (vc
->vc_can_do_color
) {
2451 vc
->vc_complement_mask
<<= 1;
2452 vc
->vc_s_complement_mask
<<= 1;
2455 /* ++Edmund: reorder the attribute bits */
2457 unsigned short *cp
=
2458 (unsigned short *) vc
->vc_origin
;
2459 int count
= vc
->vc_screenbuf_size
/ 2;
2461 for (; count
> 0; count
--, cp
++) {
2462 unsigned short newc
;
2464 if (vc
->vc_can_do_color
)
2466 ((c
& 0xff00) << 1) | (c
&
2470 scr_writew(newc
, cp
);
2472 c
= vc
->vc_video_erase_char
;
2473 if (vc
->vc_can_do_color
) {
2474 vc
->vc_video_erase_char
=
2475 ((c
& 0xff00) << 1) | (c
& 0xff);
2478 vc
->vc_video_erase_char
= c
& ~0x100;
2486 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2487 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2490 vc_resize(vc
, cols
, rows
);
2491 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2492 fbcon_update_softback(vc
);
2493 } else if (CON_IS_VISIBLE(vc
)
2494 && vc
->vc_mode
== KD_TEXT
) {
2495 fbcon_clear_margins(vc
, 0);
2499 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2500 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2504 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2506 struct display
*od
= &fb_display
[con
];
2507 struct console_font
*f
= &vc
->vc_font
;
2509 if (od
->fontdata
== f
->data
)
2510 return 0; /* already the same font... */
2511 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2515 * User asked to set font; we are guaranteed that
2516 * a) width and height are in range 1..32
2517 * b) charcount does not exceed 512
2518 * but lets not assume that, since someone might someday want to use larger
2519 * fonts. And charcount of 512 is small for unicode support.
2521 * However, user space gives the font in 32 rows , regardless of
2522 * actual font height. So a new API is needed if support for larger fonts
2523 * is ever implemented.
2526 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2528 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2529 unsigned charcount
= font
->charcount
;
2530 int w
= font
->width
;
2531 int h
= font
->height
;
2534 u8
*new_data
, *data
= font
->data
;
2535 int pitch
= (font
->width
+7) >> 3;
2537 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2538 * If not this check should be changed to charcount < 256 */
2539 if (charcount
!= 256 && charcount
!= 512)
2542 /* Make sure drawing engine can handle the font */
2543 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2544 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2547 /* Make sure driver can handle the font length */
2548 if (fbcon_invalid_charcount(info
, charcount
))
2551 size
= h
* pitch
* charcount
;
2553 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2558 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2559 FNTSIZE(new_data
) = size
;
2560 FNTCHARCNT(new_data
) = charcount
;
2561 REFCOUNT(new_data
) = 0; /* usage counter */
2562 for (i
=0; i
< charcount
; i
++) {
2563 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2566 /* Since linux has a nice crc32 function use it for counting font
2568 csum
= crc32(0, new_data
, size
);
2570 FNTSUM(new_data
) = csum
;
2571 /* Check if the same font is on some other console already */
2572 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2573 struct vc_data
*tmp
= vc_cons
[i
].d
;
2575 if (fb_display
[i
].userfont
&&
2576 fb_display
[i
].fontdata
&&
2577 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2578 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2579 tmp
->vc_font
.width
== w
&&
2580 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2581 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2582 new_data
= (u8
*)fb_display
[i
].fontdata
;
2586 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2589 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2591 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2592 const struct font_desc
*f
;
2595 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2596 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2597 else if (!(f
= find_font(name
)))
2600 font
->width
= f
->width
;
2601 font
->height
= f
->height
;
2602 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2605 static u16 palette_red
[16];
2606 static u16 palette_green
[16];
2607 static u16 palette_blue
[16];
2609 static struct fb_cmap palette_cmap
= {
2610 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2613 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2615 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2619 if (fbcon_is_inactive(vc
, info
))
2622 if (!CON_IS_VISIBLE(vc
))
2625 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2627 for (i
= j
= 0; i
< 16; i
++) {
2629 val
= vc
->vc_palette
[j
++];
2630 palette_red
[k
] = (val
<< 8) | val
;
2631 val
= vc
->vc_palette
[j
++];
2632 palette_green
[k
] = (val
<< 8) | val
;
2633 val
= vc
->vc_palette
[j
++];
2634 palette_blue
[k
] = (val
<< 8) | val
;
2636 palette_cmap
.len
= 16;
2637 palette_cmap
.start
= 0;
2639 * If framebuffer is capable of less than 16 colors,
2640 * use default palette of fbcon.
2643 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2645 return fb_set_cmap(&palette_cmap
, info
);
2648 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2653 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2654 return (u16
*) (vc
->vc_origin
+ offset
);
2655 line
= offset
/ vc
->vc_size_row
;
2656 if (line
>= softback_lines
)
2657 return (u16
*) (vc
->vc_origin
+ offset
-
2658 softback_lines
* vc
->vc_size_row
);
2659 p
= softback_curr
+ offset
;
2660 if (p
>= softback_end
)
2661 p
+= softback_buf
- softback_end
;
2665 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2671 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2672 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2674 x
= offset
% vc
->vc_cols
;
2675 y
= offset
/ vc
->vc_cols
;
2676 if (vc
->vc_num
== fg_console
)
2677 y
+= softback_lines
;
2678 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2679 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2680 unsigned long offset
= pos
- softback_curr
;
2682 if (pos
< softback_curr
)
2683 offset
+= softback_end
- softback_buf
;
2685 x
= offset
% vc
->vc_cols
;
2686 y
= offset
/ vc
->vc_cols
;
2687 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2688 if (ret
== softback_end
)
2690 if (ret
== softback_in
)
2691 ret
= vc
->vc_origin
;
2693 /* Should not happen */
2695 ret
= vc
->vc_origin
;
2704 /* As we might be inside of softback, we may work with non-contiguous buffer,
2705 that's why we have to use a separate routine. */
2706 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2709 u16 a
= scr_readw(p
);
2710 if (!vc
->vc_can_do_color
)
2712 else if (vc
->vc_hi_font_mask
== 0x100)
2713 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2714 (((a
) & 0x0e00) << 4);
2716 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2717 (((a
) & 0x0700) << 4);
2719 if (p
== (u16
*) softback_end
)
2720 p
= (u16
*) softback_buf
;
2721 if (p
== (u16
*) softback_in
)
2722 p
= (u16
*) vc
->vc_origin
;
2726 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2728 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2729 struct fbcon_ops
*ops
= info
->fbcon_par
;
2730 struct display
*disp
= &fb_display
[fg_console
];
2731 int offset
, limit
, scrollback_old
;
2734 if (vc
->vc_num
!= fg_console
)
2736 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2738 if (logo_shown
>= 0) {
2739 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2741 if (conp2
->vc_top
== logo_lines
2742 && conp2
->vc_bottom
== conp2
->vc_rows
)
2744 if (logo_shown
== vc
->vc_num
) {
2750 logo_lines
* vc
->vc_size_row
;
2751 for (i
= 0; i
< logo_lines
; i
++) {
2752 if (p
== softback_top
)
2754 if (p
== softback_buf
)
2756 p
-= vc
->vc_size_row
;
2757 q
-= vc
->vc_size_row
;
2758 scr_memcpyw((u16
*) q
, (u16
*) p
,
2761 softback_in
= softback_curr
= p
;
2762 update_region(vc
, vc
->vc_origin
,
2763 logo_lines
* vc
->vc_cols
);
2765 logo_shown
= FBCON_LOGO_CANSHOW
;
2767 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2768 fbcon_redraw_softback(vc
, disp
, lines
);
2769 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2773 if (!scrollback_phys_max
)
2776 scrollback_old
= scrollback_current
;
2777 scrollback_current
-= lines
;
2778 if (scrollback_current
< 0)
2779 scrollback_current
= 0;
2780 else if (scrollback_current
> scrollback_max
)
2781 scrollback_current
= scrollback_max
;
2782 if (scrollback_current
== scrollback_old
)
2785 if (fbcon_is_inactive(vc
, info
))
2788 fbcon_cursor(vc
, CM_ERASE
);
2790 offset
= disp
->yscroll
- scrollback_current
;
2791 limit
= disp
->vrows
;
2792 switch (disp
->scrollmode
) {
2793 case SCROLL_WRAP_MOVE
:
2794 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2796 case SCROLL_PAN_MOVE
:
2797 case SCROLL_PAN_REDRAW
:
2798 limit
-= vc
->vc_rows
;
2799 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2804 else if (offset
>= limit
)
2807 ops
->var
.xoffset
= 0;
2808 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2809 ops
->update_start(info
);
2811 if (!scrollback_current
)
2812 fbcon_cursor(vc
, CM_DRAW
);
2816 static int fbcon_set_origin(struct vc_data
*vc
)
2819 fbcon_scrolldelta(vc
, softback_lines
);
2823 static void fbcon_suspended(struct fb_info
*info
)
2825 struct vc_data
*vc
= NULL
;
2826 struct fbcon_ops
*ops
= info
->fbcon_par
;
2828 if (!ops
|| ops
->currcon
< 0)
2830 vc
= vc_cons
[ops
->currcon
].d
;
2832 /* Clear cursor, restore saved data */
2833 fbcon_cursor(vc
, CM_ERASE
);
2836 static void fbcon_resumed(struct fb_info
*info
)
2839 struct fbcon_ops
*ops
= info
->fbcon_par
;
2841 if (!ops
|| ops
->currcon
< 0)
2843 vc
= vc_cons
[ops
->currcon
].d
;
2848 static void fbcon_modechanged(struct fb_info
*info
)
2850 struct fbcon_ops
*ops
= info
->fbcon_par
;
2855 if (!ops
|| ops
->currcon
< 0)
2857 vc
= vc_cons
[ops
->currcon
].d
;
2858 if (vc
->vc_mode
!= KD_TEXT
||
2859 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2862 p
= &fb_display
[vc
->vc_num
];
2863 set_blitting_type(vc
, info
);
2865 if (CON_IS_VISIBLE(vc
)) {
2866 var_to_display(p
, &info
->var
, info
);
2867 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2868 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2869 cols
/= vc
->vc_font
.width
;
2870 rows
/= vc
->vc_font
.height
;
2871 vc_resize(vc
, cols
, rows
);
2872 updatescrollmode(p
, info
, vc
);
2874 scrollback_current
= 0;
2876 if (!fbcon_is_inactive(vc
, info
)) {
2877 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2878 ops
->update_start(info
);
2881 fbcon_set_palette(vc
, color_table
);
2884 fbcon_update_softback(vc
);
2888 static void fbcon_set_all_vcs(struct fb_info
*info
)
2890 struct fbcon_ops
*ops
= info
->fbcon_par
;
2893 int i
, rows
, cols
, fg
= -1;
2895 if (!ops
|| ops
->currcon
< 0)
2898 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2900 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2901 registered_fb
[con2fb_map
[i
]] != info
)
2904 if (CON_IS_VISIBLE(vc
)) {
2909 p
= &fb_display
[vc
->vc_num
];
2910 set_blitting_type(vc
, info
);
2911 var_to_display(p
, &info
->var
, info
);
2912 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2913 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2914 cols
/= vc
->vc_font
.width
;
2915 rows
/= vc
->vc_font
.height
;
2916 vc_resize(vc
, cols
, rows
);
2920 fbcon_modechanged(info
);
2923 static int fbcon_mode_deleted(struct fb_info
*info
,
2924 struct fb_videomode
*mode
)
2926 struct fb_info
*fb_info
;
2928 int i
, j
, found
= 0;
2930 /* before deletion, ensure that mode is not in use */
2931 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2935 fb_info
= registered_fb
[j
];
2936 if (fb_info
!= info
)
2941 if (fb_mode_is_equal(p
->mode
, mode
)) {
2949 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2950 static int fbcon_unbind(void)
2954 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2959 static inline int fbcon_unbind(void)
2963 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2965 static int fbcon_fb_unbind(int idx
)
2967 int i
, new_idx
= -1, ret
= 0;
2969 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2970 if (con2fb_map
[i
] != idx
&&
2971 con2fb_map
[i
] != -1) {
2977 if (new_idx
!= -1) {
2978 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2979 if (con2fb_map
[i
] == idx
)
2980 set_con2fb_map(i
, new_idx
, 0);
2983 ret
= fbcon_unbind();
2988 static int fbcon_fb_unregistered(struct fb_info
*info
)
2990 int i
, idx
= info
->node
;
2992 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2993 if (con2fb_map
[i
] == idx
)
2997 if (idx
== info_idx
) {
3000 for (i
= 0; i
< FB_MAX
; i
++) {
3001 if (registered_fb
[i
] != NULL
) {
3008 if (info_idx
!= -1) {
3009 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3010 if (con2fb_map
[i
] == -1)
3011 con2fb_map
[i
] = info_idx
;
3015 if (!num_registered_fb
)
3016 unregister_con_driver(&fb_con
);
3019 if (primary_device
== idx
)
3020 primary_device
= -1;
3025 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3026 static void fbcon_select_primary(struct fb_info
*info
)
3028 if (!map_override
&& primary_device
== -1 &&
3029 fb_is_primary_device(info
)) {
3032 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3033 info
->fix
.id
, info
->node
);
3034 primary_device
= info
->node
;
3036 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3037 con2fb_map_boot
[i
] = primary_device
;
3039 if (con_is_bound(&fb_con
)) {
3040 printk(KERN_INFO
"fbcon: Remapping primary device, "
3041 "fb%i, to tty %i-%i\n", info
->node
,
3042 first_fb_vc
+ 1, last_fb_vc
+ 1);
3043 info_idx
= primary_device
;
3049 static inline void fbcon_select_primary(struct fb_info
*info
)
3053 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3055 static int fbcon_fb_registered(struct fb_info
*info
)
3057 int ret
= 0, i
, idx
= info
->node
;
3059 fbcon_select_primary(info
);
3061 if (info_idx
== -1) {
3062 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3063 if (con2fb_map_boot
[i
] == idx
) {
3070 ret
= fbcon_takeover(1);
3072 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3073 if (con2fb_map_boot
[i
] == idx
)
3074 set_con2fb_map(i
, idx
, 0);
3081 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3083 struct fbcon_ops
*ops
= info
->fbcon_par
;
3086 if (!ops
|| ops
->currcon
< 0)
3089 vc
= vc_cons
[ops
->currcon
].d
;
3090 if (vc
->vc_mode
!= KD_TEXT
||
3091 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3094 if (CON_IS_VISIBLE(vc
)) {
3098 do_unblank_screen(0);
3100 ops
->blank_state
= blank
;
3103 static void fbcon_new_modelist(struct fb_info
*info
)
3107 struct fb_var_screeninfo var
;
3108 const struct fb_videomode
*mode
;
3110 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3111 if (registered_fb
[con2fb_map
[i
]] != info
)
3113 if (!fb_display
[i
].mode
)
3116 display_to_var(&var
, &fb_display
[i
]);
3117 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3119 fb_videomode_to_var(&var
, mode
);
3120 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3124 static void fbcon_get_requirement(struct fb_info
*info
,
3125 struct fb_blit_caps
*caps
)
3133 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3135 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3136 info
->node
== con2fb_map
[i
]) {
3138 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3139 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3140 charcnt
= (p
->userfont
) ?
3141 FNTCHARCNT(p
->fontdata
) : 256;
3142 if (caps
->len
< charcnt
)
3143 caps
->len
= charcnt
;
3147 vc
= vc_cons
[fg_console
].d
;
3149 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3150 info
->node
== con2fb_map
[fg_console
]) {
3151 p
= &fb_display
[fg_console
];
3152 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3153 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3154 caps
->len
= (p
->userfont
) ?
3155 FNTCHARCNT(p
->fontdata
) : 256;
3160 static int fbcon_event_notify(struct notifier_block
*self
,
3161 unsigned long action
, void *data
)
3163 struct fb_event
*event
= data
;
3164 struct fb_info
*info
= event
->info
;
3165 struct fb_videomode
*mode
;
3166 struct fb_con2fbmap
*con2fb
;
3167 struct fb_blit_caps
*caps
;
3171 * ignore all events except driver registration and deregistration
3172 * if fbcon is not active
3174 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3175 action
== FB_EVENT_FB_UNREGISTERED
))
3179 case FB_EVENT_SUSPEND
:
3180 fbcon_suspended(info
);
3182 case FB_EVENT_RESUME
:
3183 fbcon_resumed(info
);
3185 case FB_EVENT_MODE_CHANGE
:
3186 fbcon_modechanged(info
);
3188 case FB_EVENT_MODE_CHANGE_ALL
:
3189 fbcon_set_all_vcs(info
);
3191 case FB_EVENT_MODE_DELETE
:
3193 ret
= fbcon_mode_deleted(info
, mode
);
3195 case FB_EVENT_FB_UNBIND
:
3196 ret
= fbcon_fb_unbind(info
->node
);
3198 case FB_EVENT_FB_REGISTERED
:
3199 ret
= fbcon_fb_registered(info
);
3201 case FB_EVENT_FB_UNREGISTERED
:
3202 ret
= fbcon_fb_unregistered(info
);
3204 case FB_EVENT_SET_CONSOLE_MAP
:
3205 con2fb
= event
->data
;
3206 ret
= set_con2fb_map(con2fb
->console
- 1,
3207 con2fb
->framebuffer
, 1);
3209 case FB_EVENT_GET_CONSOLE_MAP
:
3210 con2fb
= event
->data
;
3211 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3213 case FB_EVENT_BLANK
:
3214 fbcon_fb_blanked(info
, *(int *)event
->data
);
3216 case FB_EVENT_NEW_MODELIST
:
3217 fbcon_new_modelist(info
);
3219 case FB_EVENT_GET_REQ
:
3221 fbcon_get_requirement(info
, caps
);
3230 * The console `switch' structure for the frame buffer based console
3233 static const struct consw fb_con
= {
3234 .owner
= THIS_MODULE
,
3235 .con_startup
= fbcon_startup
,
3236 .con_init
= fbcon_init
,
3237 .con_deinit
= fbcon_deinit
,
3238 .con_clear
= fbcon_clear
,
3239 .con_putc
= fbcon_putc
,
3240 .con_putcs
= fbcon_putcs
,
3241 .con_cursor
= fbcon_cursor
,
3242 .con_scroll
= fbcon_scroll
,
3243 .con_bmove
= fbcon_bmove
,
3244 .con_switch
= fbcon_switch
,
3245 .con_blank
= fbcon_blank
,
3246 .con_font_set
= fbcon_set_font
,
3247 .con_font_get
= fbcon_get_font
,
3248 .con_font_default
= fbcon_set_def_font
,
3249 .con_font_copy
= fbcon_copy_font
,
3250 .con_set_palette
= fbcon_set_palette
,
3251 .con_scrolldelta
= fbcon_scrolldelta
,
3252 .con_set_origin
= fbcon_set_origin
,
3253 .con_invert_region
= fbcon_invert_region
,
3254 .con_screen_pos
= fbcon_screen_pos
,
3255 .con_getxy
= fbcon_getxy
,
3256 .con_resize
= fbcon_resize
,
3259 static struct notifier_block fbcon_event_notifier
= {
3260 .notifier_call
= fbcon_event_notify
,
3263 static ssize_t
store_rotate(struct device
*device
,
3264 struct device_attribute
*attr
, const char *buf
,
3267 struct fb_info
*info
;
3271 if (fbcon_has_exited
)
3274 acquire_console_sem();
3275 idx
= con2fb_map
[fg_console
];
3277 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3280 info
= registered_fb
[idx
];
3281 rotate
= simple_strtoul(buf
, last
, 0);
3282 fbcon_rotate(info
, rotate
);
3284 release_console_sem();
3288 static ssize_t
store_rotate_all(struct device
*device
,
3289 struct device_attribute
*attr
,const char *buf
,
3292 struct fb_info
*info
;
3296 if (fbcon_has_exited
)
3299 acquire_console_sem();
3300 idx
= con2fb_map
[fg_console
];
3302 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3305 info
= registered_fb
[idx
];
3306 rotate
= simple_strtoul(buf
, last
, 0);
3307 fbcon_rotate_all(info
, rotate
);
3309 release_console_sem();
3313 static ssize_t
show_rotate(struct device
*device
,
3314 struct device_attribute
*attr
,char *buf
)
3316 struct fb_info
*info
;
3317 int rotate
= 0, idx
;
3319 if (fbcon_has_exited
)
3322 acquire_console_sem();
3323 idx
= con2fb_map
[fg_console
];
3325 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3328 info
= registered_fb
[idx
];
3329 rotate
= fbcon_get_rotate(info
);
3331 release_console_sem();
3332 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3335 static ssize_t
show_cursor_blink(struct device
*device
,
3336 struct device_attribute
*attr
, char *buf
)
3338 struct fb_info
*info
;
3339 struct fbcon_ops
*ops
;
3340 int idx
, blink
= -1;
3342 if (fbcon_has_exited
)
3345 acquire_console_sem();
3346 idx
= con2fb_map
[fg_console
];
3348 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3351 info
= registered_fb
[idx
];
3352 ops
= info
->fbcon_par
;
3357 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3359 release_console_sem();
3360 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3363 static ssize_t
store_cursor_blink(struct device
*device
,
3364 struct device_attribute
*attr
,
3365 const char *buf
, size_t count
)
3367 struct fb_info
*info
;
3371 if (fbcon_has_exited
)
3374 acquire_console_sem();
3375 idx
= con2fb_map
[fg_console
];
3377 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3380 info
= registered_fb
[idx
];
3382 if (!info
->fbcon_par
)
3385 blink
= simple_strtoul(buf
, last
, 0);
3388 fbcon_cursor_noblink
= 0;
3389 fbcon_add_cursor_timer(info
);
3391 fbcon_cursor_noblink
= 1;
3392 fbcon_del_cursor_timer(info
);
3396 release_console_sem();
3400 static struct device_attribute device_attrs
[] = {
3401 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3402 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3403 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3404 store_cursor_blink
),
3407 static int fbcon_init_device(void)
3411 fbcon_has_sysfs
= 1;
3413 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3414 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3422 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3424 fbcon_has_sysfs
= 0;
3430 static void fbcon_start(void)
3432 if (num_registered_fb
) {
3435 acquire_console_sem();
3437 for (i
= 0; i
< FB_MAX
; i
++) {
3438 if (registered_fb
[i
] != NULL
) {
3444 release_console_sem();
3449 static void fbcon_exit(void)
3451 struct fb_info
*info
;
3454 if (fbcon_has_exited
)
3459 free_irq(IRQ_AUTO_4
, fb_vbl_handler
);
3462 kfree((void *)softback_buf
);
3465 for (i
= 0; i
< FB_MAX
; i
++) {
3469 info
= registered_fb
[i
];
3474 pending
= cancel_work_sync(&info
->queue
);
3475 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3478 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3479 if (con2fb_map
[j
] == i
)
3484 if (info
->fbops
->fb_release
)
3485 info
->fbops
->fb_release(info
, 0);
3486 module_put(info
->fbops
->owner
);
3488 if (info
->fbcon_par
) {
3489 struct fbcon_ops
*ops
= info
->fbcon_par
;
3491 fbcon_del_cursor_timer(info
);
3492 kfree(ops
->cursor_src
);
3493 kfree(info
->fbcon_par
);
3494 info
->fbcon_par
= NULL
;
3497 if (info
->queue
.func
== fb_flashcursor
)
3498 info
->queue
.func
= NULL
;
3502 fbcon_has_exited
= 1;
3505 static int __init
fb_console_init(void)
3509 acquire_console_sem();
3510 fb_register_client(&fbcon_event_notifier
);
3511 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3514 if (IS_ERR(fbcon_device
)) {
3515 printk(KERN_WARNING
"Unable to create device "
3516 "for fbcon; errno = %ld\n",
3517 PTR_ERR(fbcon_device
));
3518 fbcon_device
= NULL
;
3520 fbcon_init_device();
3522 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3525 release_console_sem();
3530 module_init(fb_console_init
);
3534 static void __exit
fbcon_deinit_device(void)
3538 if (fbcon_has_sysfs
) {
3539 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3540 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3542 fbcon_has_sysfs
= 0;
3546 static void __exit
fb_console_exit(void)
3548 acquire_console_sem();
3549 fb_unregister_client(&fbcon_event_notifier
);
3550 fbcon_deinit_device();
3551 device_destroy(fb_class
, MKDEV(0, 0));
3553 release_console_sem();
3554 unregister_con_driver(&fb_con
);
3557 module_exit(fb_console_exit
);
3561 MODULE_LICENSE("GPL");