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>
93 #include "fbcondecor.h"
96 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
98 # define DPRINTK(fmt, args...)
102 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
103 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
104 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
107 static struct display fb_display
[MAX_NR_CONSOLES
];
109 signed char con2fb_map
[MAX_NR_CONSOLES
];
110 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
112 static int logo_lines
;
113 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
115 static int logo_shown
= FBCON_LOGO_CANSHOW
;
116 /* Software scrollback */
117 static int fbcon_softback_size
= 32768;
118 static unsigned long softback_buf
, softback_curr
;
119 static unsigned long softback_in
;
120 static unsigned long softback_top
, softback_end
;
121 static int softback_lines
;
122 /* console mappings */
123 static int first_fb_vc
;
124 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
125 static int fbcon_is_default
= 1;
126 static int fbcon_has_exited
;
127 static int primary_device
= -1;
129 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
130 static int map_override
;
132 static inline void fbcon_map_override(void)
137 static inline void fbcon_map_override(void)
140 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
143 static char fontname
[40];
145 /* current fb_info */
146 static int info_idx
= -1;
148 /* console rotation */
149 static int initial_rotation
;
150 static int fbcon_has_sysfs
;
152 static const struct consw fb_con
;
154 #define CM_SOFTBACK (8)
156 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
158 static int fbcon_set_origin(struct vc_data
*);
160 #define CURSOR_DRAW_DELAY (1)
162 /* # VBL ints between cursor state changes */
163 #define ATARI_CURSOR_BLINK_RATE (42)
164 #define MAC_CURSOR_BLINK_RATE (32)
165 #define DEFAULT_CURSOR_BLINK_RATE (20)
167 static int vbl_cursor_cnt
;
168 static int fbcon_cursor_noblink
;
170 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
173 * Interface used by the world
176 static const char *fbcon_startup(void);
177 static void fbcon_init(struct vc_data
*vc
, int init
);
178 static void fbcon_deinit(struct vc_data
*vc
);
179 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
181 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
182 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
183 int count
, int ypos
, int xpos
);
184 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
185 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
186 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
188 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
189 int height
, int width
);
190 static int fbcon_switch(struct vc_data
*vc
);
191 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
192 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
193 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
198 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
199 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
200 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
201 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
202 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
203 int dy
, int dx
, int height
, int width
, u_int y_break
);
204 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
206 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
207 int line
, int count
, int dy
);
208 static void fbcon_modechanged(struct fb_info
*info
);
209 static void fbcon_set_all_vcs(struct fb_info
*info
);
210 static void fbcon_start(void);
211 static void fbcon_exit(void);
212 static struct device
*fbcon_device
;
216 * On the Macintoy, there may or may not be a working VBL int. We need to probe
218 static int vbl_detected
;
220 static irqreturn_t
fb_vbl_detect(int irq
, void *dummy
)
227 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
228 static inline void fbcon_set_rotation(struct fb_info
*info
)
230 struct fbcon_ops
*ops
= info
->fbcon_par
;
232 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
233 ops
->p
->con_rotate
< 4)
234 ops
->rotate
= ops
->p
->con_rotate
;
239 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
241 struct fbcon_ops
*ops
= info
->fbcon_par
;
242 struct fb_info
*fb_info
;
244 if (!ops
|| ops
->currcon
== -1)
247 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
249 if (info
== fb_info
) {
250 struct display
*p
= &fb_display
[ops
->currcon
];
253 p
->con_rotate
= rotate
;
257 fbcon_modechanged(info
);
261 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
263 struct fbcon_ops
*ops
= info
->fbcon_par
;
268 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
271 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
273 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
274 registered_fb
[con2fb_map
[i
]] != info
)
277 p
= &fb_display
[vc
->vc_num
];
278 p
->con_rotate
= rotate
;
281 fbcon_set_all_vcs(info
);
284 static inline void fbcon_set_rotation(struct fb_info
*info
)
286 struct fbcon_ops
*ops
= info
->fbcon_par
;
288 ops
->rotate
= FB_ROTATE_UR
;
291 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
296 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
300 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
302 static int fbcon_get_rotate(struct fb_info
*info
)
304 struct fbcon_ops
*ops
= info
->fbcon_par
;
306 return (ops
) ? ops
->rotate
: 0;
309 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
311 struct fbcon_ops
*ops
= info
->fbcon_par
;
313 return (info
->state
!= FBINFO_STATE_RUNNING
||
314 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
317 inline int get_color(struct vc_data
*vc
, struct fb_info
*info
,
320 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
323 if (console_blanked
) {
324 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
326 c
= vc
->vc_video_erase_char
& charmask
;
330 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
331 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
336 int col
= mono_col(info
);
338 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
339 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
344 color
= (is_fg
) ? fg
: bg
;
349 * Scale down 16-colors to 4 colors. Default 4-color palette
350 * is grayscale. However, simply dividing the values by 4
351 * will not work, as colors 1, 2 and 3 will be scaled-down
352 * to zero rendering them invisible. So empirically convert
353 * colors to a sane 4-level grayscale.
357 color
= 0; /* black */
360 color
= 2; /* white */
363 color
= 1; /* gray */
366 color
= 3; /* intense white */
372 * Last 8 entries of default 16-color palette is a more intense
373 * version of the first 8 (i.e., same chrominance, different
384 static void fbcon_update_softback(struct vc_data
*vc
)
386 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
389 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
391 /* Smaller scrollback makes no sense, and 0 would screw
392 the operation totally */
396 static void fb_flashcursor(struct work_struct
*work
)
398 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
399 struct fbcon_ops
*ops
= info
->fbcon_par
;
401 struct vc_data
*vc
= NULL
;
405 acquire_console_sem();
406 if (ops
&& ops
->currcon
!= -1)
407 vc
= vc_cons
[ops
->currcon
].d
;
409 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
410 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
412 release_console_sem();
416 p
= &fb_display
[vc
->vc_num
];
417 c
= scr_readw((u16
*) vc
->vc_pos
);
418 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
420 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
421 get_color(vc
, info
, c
, 0));
423 release_console_sem();
426 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
427 static int cursor_blink_rate
;
428 static irqreturn_t
fb_vbl_handler(int irq
, void *dev_id
)
430 struct fb_info
*info
= dev_id
;
432 if (vbl_cursor_cnt
&& --vbl_cursor_cnt
== 0) {
433 schedule_work(&info
->queue
);
434 vbl_cursor_cnt
= cursor_blink_rate
;
440 static void cursor_timer_handler(unsigned long dev_addr
)
442 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
443 struct fbcon_ops
*ops
= info
->fbcon_par
;
445 schedule_work(&info
->queue
);
446 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
449 static void fbcon_add_cursor_timer(struct fb_info
*info
)
451 struct fbcon_ops
*ops
= info
->fbcon_par
;
453 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
454 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
455 !fbcon_cursor_noblink
) {
456 if (!info
->queue
.func
)
457 INIT_WORK(&info
->queue
, fb_flashcursor
);
459 init_timer(&ops
->cursor_timer
);
460 ops
->cursor_timer
.function
= cursor_timer_handler
;
461 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
462 ops
->cursor_timer
.data
= (unsigned long ) info
;
463 add_timer(&ops
->cursor_timer
);
464 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
468 static void fbcon_del_cursor_timer(struct fb_info
*info
)
470 struct fbcon_ops
*ops
= info
->fbcon_par
;
472 if (info
->queue
.func
== fb_flashcursor
&&
473 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
474 del_timer_sync(&ops
->cursor_timer
);
475 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
480 static int __init
fb_console_setup(char *this_opt
)
485 if (!this_opt
|| !*this_opt
)
488 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
489 if (!strncmp(options
, "font:", 5))
490 strcpy(fontname
, options
+ 5);
492 if (!strncmp(options
, "scrollback:", 11)) {
495 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
496 if (*options
== 'k' || *options
== 'K') {
497 fbcon_softback_size
*= 1024;
507 if (!strncmp(options
, "map:", 4)) {
510 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
514 (options
[j
++]-'0') % FB_MAX
;
517 fbcon_map_override();
523 if (!strncmp(options
, "vc:", 3)) {
526 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
529 if (*options
++ == '-')
530 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
531 fbcon_is_default
= 0;
534 if (!strncmp(options
, "rotate:", 7)) {
537 initial_rotation
= simple_strtoul(options
, &options
, 0);
538 if (initial_rotation
> 3)
539 initial_rotation
= 0;
545 __setup("fbcon=", fb_console_setup
);
548 static int search_fb_in_map(int idx
)
552 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
553 if (con2fb_map
[i
] == idx
)
559 static int search_for_mapped_con(void)
563 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
564 if (con2fb_map
[i
] != -1)
570 static int fbcon_takeover(int show_logo
)
574 if (!num_registered_fb
)
578 logo_shown
= FBCON_LOGO_DONTSHOW
;
580 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
581 con2fb_map
[i
] = info_idx
;
583 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
587 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
599 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
600 int cols
, int rows
, int new_cols
, int new_rows
)
602 logo_shown
= FBCON_LOGO_DONTSHOW
;
605 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
606 int cols
, int rows
, int new_cols
, int new_rows
)
608 /* Need to make room for the logo */
609 struct fbcon_ops
*ops
= info
->fbcon_par
;
610 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
611 unsigned short *save
= NULL
, *r
, *q
;
614 if (info
->flags
& FBINFO_MODULE
) {
615 logo_shown
= FBCON_LOGO_DONTSHOW
;
620 * remove underline attribute from erase character
621 * if black and white framebuffer.
623 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
625 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
626 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
627 q
= (unsigned short *) (vc
->vc_origin
+
628 vc
->vc_size_row
* rows
);
629 step
= logo_lines
* cols
;
630 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
631 if (scr_readw(r
) != vc
->vc_video_erase_char
)
633 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
634 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
636 int i
= cols
< new_cols
? cols
: new_cols
;
637 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
639 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
640 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
645 /* We can scroll screen down */
647 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
648 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
653 if (vc
->vc_y
+ logo_lines
>= rows
)
654 lines
= rows
- vc
->vc_y
- 1;
658 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
661 scr_memsetw((unsigned short *) vc
->vc_origin
,
663 vc
->vc_size_row
* logo_lines
);
665 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
666 fbcon_clear_margins(vc
, 0);
671 q
= (unsigned short *) (vc
->vc_origin
+
674 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
675 vc
->vc_y
+= logo_lines
;
676 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
680 if (logo_lines
> vc
->vc_bottom
) {
681 logo_shown
= FBCON_LOGO_CANSHOW
;
683 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
684 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
685 logo_shown
= FBCON_LOGO_DRAW
;
686 vc
->vc_top
= logo_lines
;
691 #ifdef CONFIG_FB_TILEBLITTING
692 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
694 struct fbcon_ops
*ops
= info
->fbcon_par
;
696 ops
->p
= &fb_display
[vc
->vc_num
];
698 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
699 fbcon_set_tileops(vc
, info
);
701 fbcon_set_rotation(info
);
702 fbcon_set_bitops(ops
);
706 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
710 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
711 info
->tileops
->fb_get_tilemax(info
) < charcount
)
717 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
719 struct fbcon_ops
*ops
= info
->fbcon_par
;
721 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
722 ops
->p
= &fb_display
[vc
->vc_num
];
723 fbcon_set_rotation(info
);
724 fbcon_set_bitops(ops
);
727 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
732 #endif /* CONFIG_MISC_TILEBLITTING */
735 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
736 int unit
, int oldidx
)
738 struct fbcon_ops
*ops
= NULL
;
741 if (!try_module_get(info
->fbops
->owner
))
744 if (!err
&& info
->fbops
->fb_open
&&
745 info
->fbops
->fb_open(info
, 0))
749 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
755 info
->fbcon_par
= ops
;
758 set_blitting_type(vc
, info
);
762 con2fb_map
[unit
] = oldidx
;
763 module_put(info
->fbops
->owner
);
769 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
770 struct fb_info
*newinfo
, int unit
,
771 int oldidx
, int found
)
773 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
776 if (oldinfo
->fbops
->fb_release
&&
777 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
778 con2fb_map
[unit
] = oldidx
;
779 if (!found
&& newinfo
->fbops
->fb_release
)
780 newinfo
->fbops
->fb_release(newinfo
, 0);
782 module_put(newinfo
->fbops
->owner
);
787 fbcon_del_cursor_timer(oldinfo
);
788 kfree(ops
->cursor_state
.mask
);
789 kfree(ops
->cursor_data
);
790 kfree(ops
->fontbuffer
);
791 kfree(oldinfo
->fbcon_par
);
792 oldinfo
->fbcon_par
= NULL
;
793 module_put(oldinfo
->fbops
->owner
);
795 If oldinfo and newinfo are driving the same hardware,
796 the fb_release() method of oldinfo may attempt to
797 restore the hardware state. This will leave the
798 newinfo in an undefined state. Thus, a call to
799 fb_set_par() may be needed for the newinfo.
801 if (newinfo
->fbops
->fb_set_par
)
802 newinfo
->fbops
->fb_set_par(newinfo
);
808 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
809 int unit
, int show_logo
)
811 struct fbcon_ops
*ops
= info
->fbcon_par
;
813 ops
->currcon
= fg_console
;
815 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
))
816 info
->fbops
->fb_set_par(info
);
818 ops
->flags
|= FBCON_FLAGS_INIT
;
820 fbcon_set_disp(info
, &info
->var
, unit
);
823 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
824 struct fb_info
*fg_info
=
825 registered_fb
[con2fb_map
[fg_console
]];
827 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
828 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
832 update_screen(vc_cons
[fg_console
].d
);
836 * set_con2fb_map - map console to frame buffer device
837 * @unit: virtual console number to map
838 * @newidx: frame buffer index to map virtual console to
839 * @user: user request
841 * Maps a virtual console @unit to a frame buffer device
844 static int set_con2fb_map(int unit
, int newidx
, int user
)
846 struct vc_data
*vc
= vc_cons
[unit
].d
;
847 int oldidx
= con2fb_map
[unit
];
848 struct fb_info
*info
= registered_fb
[newidx
];
849 struct fb_info
*oldinfo
= NULL
;
852 if (oldidx
== newidx
)
855 if (!info
|| fbcon_has_exited
)
858 if (!err
&& !search_for_mapped_con()) {
860 return fbcon_takeover(0);
864 oldinfo
= registered_fb
[oldidx
];
866 found
= search_fb_in_map(newidx
);
868 acquire_console_sem();
869 con2fb_map
[unit
] = newidx
;
871 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
875 * If old fb is not mapped to any of the consoles,
876 * fbcon should release it.
878 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
879 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
883 int show_logo
= (fg_console
== 0 && !user
&&
884 logo_shown
!= FBCON_LOGO_DONTSHOW
);
887 fbcon_add_cursor_timer(info
);
888 con2fb_map_boot
[unit
] = newidx
;
889 con2fb_init_display(vc
, info
, unit
, show_logo
);
892 if (!search_fb_in_map(info_idx
))
895 release_console_sem();
900 * Low Level Operations
902 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
903 static int var_to_display(struct display
*disp
,
904 struct fb_var_screeninfo
*var
,
905 struct fb_info
*info
)
907 disp
->xres_virtual
= var
->xres_virtual
;
908 disp
->yres_virtual
= var
->yres_virtual
;
909 disp
->bits_per_pixel
= var
->bits_per_pixel
;
910 disp
->grayscale
= var
->grayscale
;
911 disp
->nonstd
= var
->nonstd
;
912 disp
->accel_flags
= var
->accel_flags
;
913 disp
->height
= var
->height
;
914 disp
->width
= var
->width
;
915 disp
->red
= var
->red
;
916 disp
->green
= var
->green
;
917 disp
->blue
= var
->blue
;
918 disp
->transp
= var
->transp
;
919 disp
->rotate
= var
->rotate
;
920 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
921 if (disp
->mode
== NULL
)
922 /* This should not happen */
927 static void display_to_var(struct fb_var_screeninfo
*var
,
928 struct display
*disp
)
930 fb_videomode_to_var(var
, disp
->mode
);
931 var
->xres_virtual
= disp
->xres_virtual
;
932 var
->yres_virtual
= disp
->yres_virtual
;
933 var
->bits_per_pixel
= disp
->bits_per_pixel
;
934 var
->grayscale
= disp
->grayscale
;
935 var
->nonstd
= disp
->nonstd
;
936 var
->accel_flags
= disp
->accel_flags
;
937 var
->height
= disp
->height
;
938 var
->width
= disp
->width
;
939 var
->red
= disp
->red
;
940 var
->green
= disp
->green
;
941 var
->blue
= disp
->blue
;
942 var
->transp
= disp
->transp
;
943 var
->rotate
= disp
->rotate
;
946 static const char *fbcon_startup(void)
948 const char *display_desc
= "frame buffer device";
949 struct display
*p
= &fb_display
[fg_console
];
950 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
951 const struct font_desc
*font
= NULL
;
952 struct module
*owner
;
953 struct fb_info
*info
= NULL
;
954 struct fbcon_ops
*ops
;
960 * If num_registered_fb is zero, this is a call for the dummy part.
961 * The frame buffer devices weren't initialized yet.
963 if (!num_registered_fb
|| info_idx
== -1)
966 * Instead of blindly using registered_fb[0], we use info_idx, set by
969 info
= registered_fb
[info_idx
];
973 owner
= info
->fbops
->owner
;
974 if (!try_module_get(owner
))
976 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
981 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
989 ops
->cur_rotate
= -1;
990 info
->fbcon_par
= ops
;
991 p
->con_rotate
= initial_rotation
;
992 set_blitting_type(vc
, info
);
994 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
995 if (fbcon_softback_size
) {
999 kmalloc(fbcon_softback_size
,
1001 if (!softback_buf
) {
1002 fbcon_softback_size
= 0;
1008 kfree((void *) softback_buf
);
1014 softback_in
= softback_top
= softback_curr
=
1019 /* Setup default font */
1021 if (!fontname
[0] || !(font
= find_font(fontname
)))
1022 font
= get_default_font(info
->var
.xres
,
1024 info
->pixmap
.blit_x
,
1025 info
->pixmap
.blit_y
);
1026 vc
->vc_font
.width
= font
->width
;
1027 vc
->vc_font
.height
= font
->height
;
1028 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1029 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1032 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1033 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1034 cols
/= vc
->vc_font
.width
;
1035 rows
/= vc
->vc_font
.height
;
1037 if (fbcon_decor_active(info
, vc
)) {
1038 cols
= vc
->vc_decor
.twidth
/ vc
->vc_font
.width
;
1039 rows
= vc
->vc_decor
.theight
/ vc
->vc_font
.height
;
1042 vc_resize(vc
, cols
, rows
);
1044 DPRINTK("mode: %s\n", info
->fix
.id
);
1045 DPRINTK("visual: %d\n", info
->fix
.visual
);
1046 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1048 info
->var
.bits_per_pixel
);
1051 if (MACH_IS_ATARI
) {
1052 cursor_blink_rate
= ATARI_CURSOR_BLINK_RATE
;
1054 request_irq(IRQ_AUTO_4
, fb_vbl_handler
,
1055 IRQ_TYPE_PRIO
, "framebuffer vbl",
1058 #endif /* CONFIG_ATARI */
1062 * On a Macintoy, the VBL interrupt may or may not be active.
1063 * As interrupt based cursor is more reliable and race free, we
1064 * probe for VBL interrupts.
1069 * Probe for VBL: set temp. handler ...
1071 irqres
= request_irq(IRQ_MAC_VBL
, fb_vbl_detect
, 0,
1072 "framebuffer vbl", info
);
1076 * ... and spin for 20 ms ...
1078 while (!vbl_detected
&& ++ct
< 1000)
1083 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1085 free_irq(IRQ_MAC_VBL
, fb_vbl_detect
);
1089 * interrupt based cursor ok
1091 cursor_blink_rate
= MAC_CURSOR_BLINK_RATE
;
1093 request_irq(IRQ_MAC_VBL
, fb_vbl_handler
, 0,
1094 "framebuffer vbl", info
);
1097 * VBL not detected: fall through, use timer based cursor
1102 #endif /* CONFIG_MAC */
1104 fbcon_add_cursor_timer(info
);
1105 fbcon_has_exited
= 0;
1106 return display_desc
;
1109 static void fbcon_init(struct vc_data
*vc
, int init
)
1111 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1112 struct fbcon_ops
*ops
;
1113 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1114 struct vc_data
*svc
= *default_mode
;
1115 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1116 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1119 if (info_idx
== -1 || info
== NULL
)
1124 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1125 (info
->fix
.type
== FB_TYPE_TEXT
) || fbcon_decor_active(info
, vc
))
1128 if (var_to_display(p
, &info
->var
, info
))
1131 if (!info
->fbcon_par
)
1132 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1134 /* If we are not the first console on this
1135 fb, copy the font from that console */
1136 t
= &fb_display
[fg_console
];
1139 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1141 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1143 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1144 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1145 p
->userfont
= t
->userfont
;
1148 REFCOUNT(p
->fontdata
)++;
1150 const struct font_desc
*font
= NULL
;
1152 if (!fontname
[0] || !(font
= find_font(fontname
)))
1153 font
= get_default_font(info
->var
.xres
,
1155 info
->pixmap
.blit_x
,
1156 info
->pixmap
.blit_y
);
1157 vc
->vc_font
.width
= font
->width
;
1158 vc
->vc_font
.height
= font
->height
;
1159 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1160 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1161 support more fonts */
1166 charcnt
= FNTCHARCNT(p
->fontdata
);
1168 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1169 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1170 if (charcnt
== 256) {
1171 vc
->vc_hi_font_mask
= 0;
1173 vc
->vc_hi_font_mask
= 0x100;
1174 if (vc
->vc_can_do_color
)
1175 vc
->vc_complement_mask
<<= 1;
1178 if (!*svc
->vc_uni_pagedir_loc
)
1179 con_set_default_unimap(svc
);
1180 if (!*vc
->vc_uni_pagedir_loc
)
1181 con_copy_unimap(vc
, svc
);
1183 ops
= info
->fbcon_par
;
1184 p
->con_rotate
= initial_rotation
;
1185 set_blitting_type(vc
, info
);
1189 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1190 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1191 new_cols
/= vc
->vc_font
.width
;
1192 new_rows
/= vc
->vc_font
.height
;
1193 vc_resize(vc
, new_cols
, new_rows
);
1196 * We must always set the mode. The mode of the previous console
1197 * driver could be in the same resolution but we are using different
1198 * hardware so we have to initialize the hardware.
1200 * We need to do it in fbcon_init() to prevent screen corruption.
1202 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1203 if (info
->fbops
->fb_set_par
&&
1204 !(ops
->flags
& FBCON_FLAGS_INIT
))
1205 info
->fbops
->fb_set_par(info
);
1206 ops
->flags
|= FBCON_FLAGS_INIT
;
1211 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1212 !(cap
& FBINFO_HWACCEL_DISABLED
))
1213 p
->scrollmode
= SCROLL_MOVE
;
1214 else /* default to something safe */
1215 p
->scrollmode
= SCROLL_REDRAW
;
1218 * ++guenther: console.c:vc_allocate() relies on initializing
1219 * vc_{cols,rows}, but we must not set those if we are only
1220 * resizing the console.
1223 vc
->vc_cols
= new_cols
;
1224 vc
->vc_rows
= new_rows
;
1228 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1230 if (vc
== svc
&& softback_buf
)
1231 fbcon_update_softback(vc
);
1233 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1234 ops
->rotate
= FB_ROTATE_UR
;
1235 set_blitting_type(vc
, info
);
1238 ops
->p
= &fb_display
[fg_console
];
1241 static void fbcon_free_font(struct display
*p
)
1243 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1244 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1249 static void fbcon_deinit(struct vc_data
*vc
)
1251 struct display
*p
= &fb_display
[vc
->vc_num
];
1252 struct fb_info
*info
;
1253 struct fbcon_ops
*ops
;
1257 idx
= con2fb_map
[vc
->vc_num
];
1262 info
= registered_fb
[idx
];
1267 ops
= info
->fbcon_par
;
1272 if (CON_IS_VISIBLE(vc
))
1273 fbcon_del_cursor_timer(info
);
1275 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1278 if (!con_is_bound(&fb_con
))
1284 /* ====================================================================== */
1286 /* fbcon_XXX routines - interface used by the world
1288 * This system is now divided into two levels because of complications
1289 * caused by hardware scrolling. Top level functions:
1291 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1293 * handles y values in range [0, scr_height-1] that correspond to real
1294 * screen positions. y_wrap shift means that first line of bitmap may be
1295 * anywhere on this display. These functions convert lineoffsets to
1296 * bitmap offsets and deal with the wrap-around case by splitting blits.
1298 * fbcon_bmove_physical_8() -- These functions fast implementations
1299 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1300 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1304 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1305 * Implies should only really hardware scroll in rows. Only reason for
1306 * restriction is simplicity & efficiency at the moment.
1309 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1312 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1313 struct fbcon_ops
*ops
= info
->fbcon_par
;
1315 struct display
*p
= &fb_display
[vc
->vc_num
];
1318 if (fbcon_is_inactive(vc
, info
))
1321 if (!height
|| !width
)
1324 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
)
1327 if (fbcon_decor_active(info
, vc
)) {
1328 fbcon_decor_clear(vc
, info
, sy
, sx
, height
, width
);
1332 /* Split blits that cross physical y_wrap boundary */
1334 y_break
= p
->vrows
- p
->yscroll
;
1335 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1336 u_int b
= y_break
- sy
;
1337 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1338 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1341 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1344 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1345 int count
, int ypos
, int xpos
)
1347 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1348 struct display
*p
= &fb_display
[vc
->vc_num
];
1349 struct fbcon_ops
*ops
= info
->fbcon_par
;
1351 if (!fbcon_is_inactive(vc
, info
)) {
1353 if (fbcon_decor_active(info
, vc
))
1354 fbcon_decor_putcs(vc
, info
, s
, count
, ypos
, xpos
);
1356 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1357 get_color(vc
, info
, scr_readw(s
), 1),
1358 get_color(vc
, info
, scr_readw(s
), 0));
1362 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1366 scr_writew(c
, &chr
);
1367 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1370 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1372 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1373 struct fbcon_ops
*ops
= info
->fbcon_par
;
1375 if (!fbcon_is_inactive(vc
, info
)) {
1376 if (fbcon_decor_active(info
, vc
)) {
1377 fbcon_decor_clear_margins(vc
, info
, bottom_only
);
1379 ops
->clear_margins(vc
, info
, bottom_only
);
1384 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1386 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1387 struct fbcon_ops
*ops
= info
->fbcon_par
;
1389 int c
= scr_readw((u16
*) vc
->vc_pos
);
1391 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1394 if (vc
->vc_cursor_type
& 0x10)
1395 fbcon_del_cursor_timer(info
);
1397 fbcon_add_cursor_timer(info
);
1399 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1400 if (mode
& CM_SOFTBACK
) {
1401 mode
&= ~CM_SOFTBACK
;
1405 fbcon_set_origin(vc
);
1409 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1410 get_color(vc
, info
, c
, 0));
1411 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1414 static int scrollback_phys_max
= 0;
1415 static int scrollback_max
= 0;
1416 static int scrollback_current
= 0;
1418 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1421 struct display
*p
, *t
;
1422 struct vc_data
**default_mode
, *vc
;
1423 struct vc_data
*svc
;
1424 struct fbcon_ops
*ops
= info
->fbcon_par
;
1425 int rows
, cols
, charcnt
= 256;
1427 p
= &fb_display
[unit
];
1429 if (var_to_display(p
, var
, info
))
1432 vc
= vc_cons
[unit
].d
;
1437 default_mode
= vc
->vc_display_fg
;
1438 svc
= *default_mode
;
1439 t
= &fb_display
[svc
->vc_num
];
1441 if (!vc
->vc_font
.data
) {
1442 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1443 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1444 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1445 p
->userfont
= t
->userfont
;
1447 REFCOUNT(p
->fontdata
)++;
1450 charcnt
= FNTCHARCNT(p
->fontdata
);
1452 var
->activate
= FB_ACTIVATE_NOW
;
1453 info
->var
.activate
= var
->activate
;
1454 var
->yoffset
= info
->var
.yoffset
;
1455 var
->xoffset
= info
->var
.xoffset
;
1456 fb_set_var(info
, var
);
1457 ops
->var
= info
->var
;
1458 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1459 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1460 if (charcnt
== 256) {
1461 vc
->vc_hi_font_mask
= 0;
1463 vc
->vc_hi_font_mask
= 0x100;
1464 if (vc
->vc_can_do_color
)
1465 vc
->vc_complement_mask
<<= 1;
1468 if (!*svc
->vc_uni_pagedir_loc
)
1469 con_set_default_unimap(svc
);
1470 if (!*vc
->vc_uni_pagedir_loc
)
1471 con_copy_unimap(vc
, svc
);
1473 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1474 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1475 cols
/= vc
->vc_font
.width
;
1476 rows
/= vc
->vc_font
.height
;
1477 vc_resize(vc
, cols
, rows
);
1479 if (CON_IS_VISIBLE(vc
)) {
1482 fbcon_update_softback(vc
);
1486 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1488 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1489 struct fbcon_ops
*ops
= info
->fbcon_par
;
1490 struct display
*p
= &fb_display
[vc
->vc_num
];
1492 p
->yscroll
+= count
;
1493 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1494 p
->yscroll
-= p
->vrows
;
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 scrollback_max
+= count
;
1500 if (scrollback_max
> scrollback_phys_max
)
1501 scrollback_max
= scrollback_phys_max
;
1502 scrollback_current
= 0;
1505 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1507 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1508 struct fbcon_ops
*ops
= info
->fbcon_par
;
1509 struct display
*p
= &fb_display
[vc
->vc_num
];
1511 p
->yscroll
-= count
;
1512 if (p
->yscroll
< 0) /* Deal with wrap */
1513 p
->yscroll
+= p
->vrows
;
1514 ops
->var
.xoffset
= 0;
1515 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1516 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1517 ops
->update_start(info
);
1518 scrollback_max
-= count
;
1519 if (scrollback_max
< 0)
1521 scrollback_current
= 0;
1524 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1526 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1527 struct display
*p
= &fb_display
[vc
->vc_num
];
1528 struct fbcon_ops
*ops
= info
->fbcon_par
;
1530 p
->yscroll
+= count
;
1531 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1532 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1533 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1534 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1537 ops
->var
.xoffset
= 0;
1538 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1539 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1540 ops
->update_start(info
);
1541 fbcon_clear_margins(vc
, 1);
1542 scrollback_max
+= count
;
1543 if (scrollback_max
> scrollback_phys_max
)
1544 scrollback_max
= scrollback_phys_max
;
1545 scrollback_current
= 0;
1548 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1550 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1551 struct fbcon_ops
*ops
= info
->fbcon_par
;
1552 struct display
*p
= &fb_display
[vc
->vc_num
];
1554 p
->yscroll
+= count
;
1556 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1557 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1558 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1561 ops
->var
.xoffset
= 0;
1562 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1563 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1564 ops
->update_start(info
);
1565 fbcon_clear_margins(vc
, 1);
1566 scrollback_max
+= count
;
1567 if (scrollback_max
> scrollback_phys_max
)
1568 scrollback_max
= scrollback_phys_max
;
1569 scrollback_current
= 0;
1572 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1574 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1575 struct display
*p
= &fb_display
[vc
->vc_num
];
1576 struct fbcon_ops
*ops
= info
->fbcon_par
;
1578 p
->yscroll
-= count
;
1579 if (p
->yscroll
< 0) {
1580 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1581 0, vc
->vc_rows
, vc
->vc_cols
);
1582 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1585 ops
->var
.xoffset
= 0;
1586 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1587 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1588 ops
->update_start(info
);
1589 fbcon_clear_margins(vc
, 1);
1590 scrollback_max
-= count
;
1591 if (scrollback_max
< 0)
1593 scrollback_current
= 0;
1596 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1598 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1599 struct fbcon_ops
*ops
= info
->fbcon_par
;
1600 struct display
*p
= &fb_display
[vc
->vc_num
];
1602 p
->yscroll
-= count
;
1604 if (p
->yscroll
< 0) {
1605 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1606 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1609 ops
->var
.xoffset
= 0;
1610 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1611 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1612 ops
->update_start(info
);
1613 fbcon_clear_margins(vc
, 1);
1614 scrollback_max
-= count
;
1615 if (scrollback_max
< 0)
1617 scrollback_current
= 0;
1620 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1623 int count
= vc
->vc_rows
;
1624 unsigned short *d
, *s
;
1628 d
= (u16
*) softback_curr
;
1629 if (d
== (u16
*) softback_in
)
1630 d
= (u16
*) vc
->vc_origin
;
1631 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1632 softback_lines
-= delta
;
1634 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1635 n
+= softback_end
- softback_buf
;
1636 if (n
< softback_top
) {
1638 (softback_top
- n
) / vc
->vc_size_row
;
1641 } else if (softback_curr
>= softback_top
1642 && n
< softback_top
) {
1644 (softback_top
- n
) / vc
->vc_size_row
;
1648 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1649 n
+= softback_buf
- softback_end
;
1650 if (n
> softback_in
) {
1654 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1659 if (n
== softback_curr
)
1662 s
= (u16
*) softback_curr
;
1663 if (s
== (u16
*) softback_in
)
1664 s
= (u16
*) vc
->vc_origin
;
1666 unsigned short *start
;
1670 unsigned short attr
= 1;
1673 le
= advance_row(s
, 1);
1676 if (attr
!= (c
& 0xff00)) {
1679 fbcon_putcs(vc
, start
, s
- start
,
1685 if (c
== scr_readw(d
)) {
1687 fbcon_putcs(vc
, start
, s
- start
,
1700 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1702 if (d
== (u16
*) softback_end
)
1703 d
= (u16
*) softback_buf
;
1704 if (d
== (u16
*) softback_in
)
1705 d
= (u16
*) vc
->vc_origin
;
1706 if (s
== (u16
*) softback_end
)
1707 s
= (u16
*) softback_buf
;
1708 if (s
== (u16
*) softback_in
)
1709 s
= (u16
*) vc
->vc_origin
;
1713 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1714 int line
, int count
, int dy
)
1716 unsigned short *s
= (unsigned short *)
1717 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1720 unsigned short *start
= s
;
1721 unsigned short *le
= advance_row(s
, 1);
1724 unsigned short attr
= 1;
1728 if (attr
!= (c
& 0xff00)) {
1731 fbcon_putcs(vc
, start
, s
- start
,
1737 console_conditional_schedule();
1741 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1742 console_conditional_schedule();
1747 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1748 struct display
*p
, int line
, int count
, int ycount
)
1750 int offset
= ycount
* vc
->vc_cols
;
1751 unsigned short *d
= (unsigned short *)
1752 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1753 unsigned short *s
= d
+ offset
;
1754 struct fbcon_ops
*ops
= info
->fbcon_par
;
1757 unsigned short *start
= s
;
1758 unsigned short *le
= advance_row(s
, 1);
1765 if (c
== scr_readw(d
)) {
1767 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1768 line
, x
, 1, s
-start
);
1778 console_conditional_schedule();
1783 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1785 console_conditional_schedule();
1790 /* NOTE: We subtract two lines from these pointers */
1791 s
-= vc
->vc_size_row
;
1792 d
-= vc
->vc_size_row
;
1797 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1798 int line
, int count
, int offset
)
1800 unsigned short *d
= (unsigned short *)
1801 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1802 unsigned short *s
= d
+ offset
;
1805 unsigned short *start
= s
;
1806 unsigned short *le
= advance_row(s
, 1);
1809 unsigned short attr
= 1;
1813 if (attr
!= (c
& 0xff00)) {
1816 fbcon_putcs(vc
, start
, s
- start
,
1822 if (c
== scr_readw(d
)) {
1824 fbcon_putcs(vc
, start
, s
- start
,
1834 console_conditional_schedule();
1839 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1840 console_conditional_schedule();
1845 /* NOTE: We subtract two lines from these pointers */
1846 s
-= vc
->vc_size_row
;
1847 d
-= vc
->vc_size_row
;
1852 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1857 if (vc
->vc_num
!= fg_console
)
1859 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1862 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1864 p
= advance_row(p
, 1);
1865 softback_in
+= vc
->vc_size_row
;
1866 if (softback_in
== softback_end
)
1867 softback_in
= softback_buf
;
1868 if (softback_in
== softback_top
) {
1869 softback_top
+= vc
->vc_size_row
;
1870 if (softback_top
== softback_end
)
1871 softback_top
= softback_buf
;
1874 softback_curr
= softback_in
;
1877 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1880 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1881 struct display
*p
= &fb_display
[vc
->vc_num
];
1882 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1884 if (fbcon_is_inactive(vc
, info
))
1887 fbcon_cursor(vc
, CM_ERASE
);
1890 * ++Geert: Only use ywrap/ypan if the console is in text mode
1891 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1892 * whole screen (prevents flicker).
1897 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1898 count
= vc
->vc_rows
;
1900 fbcon_softback_note(vc
, t
, count
);
1901 if (logo_shown
>= 0 || fbcon_decor_active(info
, vc
))
1903 switch (p
->scrollmode
) {
1905 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1907 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1908 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1911 vc
->vc_video_erase_char
,
1912 vc
->vc_size_row
* count
);
1916 case SCROLL_WRAP_MOVE
:
1917 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1919 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1921 ywrap_up(vc
, count
);
1922 if (vc
->vc_rows
- b
> 0)
1923 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1926 } else if (info
->flags
& FBINFO_READS_FAST
)
1927 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1928 b
- t
- count
, vc
->vc_cols
);
1931 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1934 case SCROLL_PAN_REDRAW
:
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_redraw_move(vc
, p
, 0, t
, count
);
1943 ypan_up_redraw(vc
, t
, count
);
1944 if (vc
->vc_rows
- b
> 0)
1945 fbcon_redraw_move(vc
, p
, b
,
1946 vc
->vc_rows
- b
, b
);
1948 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1949 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1952 case SCROLL_PAN_MOVE
:
1953 if ((p
->yscroll
+ count
<=
1954 2 * (p
->vrows
- vc
->vc_rows
))
1955 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1958 3 * vc
->vc_rows
>> 2)))) {
1960 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1963 if (vc
->vc_rows
- b
> 0)
1964 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1967 } else if (info
->flags
& FBINFO_READS_FAST
)
1968 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1969 b
- t
- count
, vc
->vc_cols
);
1972 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1977 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1978 count
* vc
->vc_cols
);
1979 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1980 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1983 vc
->vc_video_erase_char
,
1984 vc
->vc_size_row
* count
);
1990 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1991 count
= vc
->vc_rows
;
1992 if (logo_shown
>= 0)
1994 if (fbcon_decor_active(info
, vc
))
1996 switch (p
->scrollmode
) {
1998 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
2000 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2001 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2004 vc
->vc_video_erase_char
,
2005 vc
->vc_size_row
* count
);
2009 case SCROLL_WRAP_MOVE
:
2010 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
2011 if (vc
->vc_rows
- b
> 0)
2012 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
2015 ywrap_down(vc
, count
);
2017 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
2019 } else if (info
->flags
& FBINFO_READS_FAST
)
2020 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
2021 b
- t
- count
, vc
->vc_cols
);
2024 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2027 case SCROLL_PAN_MOVE
:
2028 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2029 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2032 3 * vc
->vc_rows
>> 2)))) {
2033 if (vc
->vc_rows
- b
> 0)
2034 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
2037 ypan_down(vc
, count
);
2039 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
2041 } else if (info
->flags
& FBINFO_READS_FAST
)
2042 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
2043 b
- t
- count
, vc
->vc_cols
);
2046 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2049 case SCROLL_PAN_REDRAW
:
2050 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2051 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2054 3 * vc
->vc_rows
>> 2)))) {
2055 if (vc
->vc_rows
- b
> 0)
2056 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
2058 ypan_down_redraw(vc
, t
, count
);
2060 fbcon_redraw_move(vc
, p
, count
, t
, 0);
2062 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
2063 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2068 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
2069 -count
* vc
->vc_cols
);
2070 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2071 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2074 vc
->vc_video_erase_char
,
2075 vc
->vc_size_row
* count
);
2083 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2084 int height
, int width
)
2086 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2087 struct display
*p
= &fb_display
[vc
->vc_num
];
2089 if (fbcon_is_inactive(vc
, info
))
2092 if (!width
|| !height
)
2095 /* Split blits that cross physical y_wrap case.
2096 * Pathological case involves 4 blits, better to use recursive
2097 * code rather than unrolled case
2099 * Recursive invocations don't need to erase the cursor over and
2100 * over again, so we use fbcon_bmove_rec()
2102 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2103 p
->vrows
- p
->yscroll
);
2106 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2107 int dy
, int dx
, int height
, int width
, u_int y_break
)
2109 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2110 struct fbcon_ops
*ops
= info
->fbcon_par
;
2113 if (sy
< y_break
&& sy
+ 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
,
2129 if (dy
< y_break
&& dy
+ height
> y_break
) {
2131 if (dy
< sy
) { /* Avoid trashing self */
2132 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2134 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2135 height
- b
, width
, y_break
);
2137 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2138 height
- b
, width
, y_break
);
2139 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2145 if (fbcon_decor_active(info
, vc
) && sy
== dy
&& height
== 1) {
2146 /* must use slower redraw bmove to keep background pic intact */
2147 fbcon_decor_bmove_redraw(vc
, info
, sy
, sx
, dx
, width
);
2151 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2155 static void updatescrollmode(struct display
*p
,
2156 struct fb_info
*info
,
2159 struct fbcon_ops
*ops
= info
->fbcon_par
;
2160 int fh
= vc
->vc_font
.height
;
2161 int cap
= info
->flags
;
2163 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2164 info
->fix
.xpanstep
);
2165 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2166 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2167 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2168 info
->var
.xres_virtual
);
2169 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2170 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2171 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2172 divides(ywrap
, vc
->vc_font
.height
) &&
2173 divides(vc
->vc_font
.height
, vyres
) &&
2174 divides(vc
->vc_font
.height
, yres
);
2175 int reading_fast
= cap
& FBINFO_READS_FAST
;
2176 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2177 !(cap
& FBINFO_HWACCEL_DISABLED
);
2178 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2179 !(cap
& FBINFO_HWACCEL_DISABLED
);
2181 p
->vrows
= vyres
/fh
;
2182 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2183 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2184 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2187 if (good_wrap
|| good_pan
) {
2188 if (reading_fast
|| fast_copyarea
)
2189 p
->scrollmode
= good_wrap
?
2190 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2192 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2195 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2196 p
->scrollmode
= SCROLL_MOVE
;
2198 p
->scrollmode
= SCROLL_REDRAW
;
2202 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2203 unsigned int height
, unsigned int user
)
2205 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2206 struct fbcon_ops
*ops
= info
->fbcon_par
;
2207 struct display
*p
= &fb_display
[vc
->vc_num
];
2208 struct fb_var_screeninfo var
= info
->var
;
2209 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2211 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2212 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2213 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2214 vc
->vc_font
.height
);
2215 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2217 var
.xres
= virt_w
* virt_fw
;
2218 var
.yres
= virt_h
* virt_fh
;
2219 x_diff
= info
->var
.xres
- var
.xres
;
2220 y_diff
= info
->var
.yres
- var
.yres
;
2221 if ((x_diff
< 0 || x_diff
> virt_fw
||
2222 y_diff
< 0 || y_diff
> virt_fh
) && !vc
->vc_decor
.state
) {
2223 const struct fb_videomode
*mode
;
2225 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2226 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2229 display_to_var(&var
, p
);
2230 fb_videomode_to_var(&var
, mode
);
2232 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2235 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2236 if (CON_IS_VISIBLE(vc
)) {
2237 var
.activate
= FB_ACTIVATE_NOW
|
2239 fb_set_var(info
, &var
);
2241 var_to_display(p
, &info
->var
, info
);
2242 ops
->var
= info
->var
;
2244 updatescrollmode(p
, info
, vc
);
2248 static int fbcon_switch(struct vc_data
*vc
)
2250 struct fb_info
*info
, *old_info
= NULL
;
2251 struct fbcon_ops
*ops
;
2252 struct display
*p
= &fb_display
[vc
->vc_num
];
2253 struct fb_var_screeninfo var
;
2254 int i
, prev_console
, charcnt
= 256;
2256 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2257 ops
= info
->fbcon_par
;
2258 prev_console
= ops
->currcon
;
2259 if (prev_console
!= -1)
2260 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2262 if (!fbcon_decor_active_vc(vc
) && info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
2263 struct vc_data
*vc_curr
= vc_cons
[prev_console
].d
;
2264 if (vc_curr
&& fbcon_decor_active_vc(vc_curr
)) {
2265 /* Clear the screen to avoid displaying funky colors during
2266 * palette updates. */
2267 memset((u8
*)info
->screen_base
+ info
->fix
.line_length
* info
->var
.yoffset
,
2268 0, info
->var
.yres
* info
->fix
.line_length
);
2274 fbcon_set_origin(vc
);
2275 softback_top
= softback_curr
= softback_in
= softback_buf
;
2277 fbcon_update_softback(vc
);
2280 if (logo_shown
>= 0) {
2281 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2283 if (conp2
->vc_top
== logo_lines
2284 && conp2
->vc_bottom
== conp2
->vc_rows
)
2286 logo_shown
= FBCON_LOGO_CANSHOW
;
2290 * FIXME: If we have multiple fbdev's loaded, we need to
2291 * update all info->currcon. Perhaps, we can place this
2292 * in a centralized structure, but this might break some
2295 * info->currcon = vc->vc_num;
2297 for (i
= 0; i
< FB_MAX
; i
++) {
2298 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2299 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2301 o
->currcon
= vc
->vc_num
;
2304 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2305 display_to_var(&var
, p
);
2306 var
.activate
= FB_ACTIVATE_NOW
;
2309 * make sure we don't unnecessarily trip the memcmp()
2312 info
->var
.activate
= var
.activate
;
2313 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2314 fb_set_var(info
, &var
);
2315 ops
->var
= info
->var
;
2317 if (old_info
!= NULL
&& (old_info
!= info
||
2318 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2319 if (info
->fbops
->fb_set_par
)
2320 info
->fbops
->fb_set_par(info
);
2322 if (old_info
!= info
)
2323 fbcon_del_cursor_timer(old_info
);
2326 if (fbcon_decor_active_vc(vc
)) {
2327 struct vc_data
*vc_curr
= vc_cons
[prev_console
].d
;
2329 if (!vc_curr
->vc_decor
.theme
||
2330 strcmp(vc
->vc_decor
.theme
, vc_curr
->vc_decor
.theme
) ||
2331 (fbcon_decor_active_nores(info
, vc_curr
) &&
2332 !fbcon_decor_active(info
, vc_curr
))) {
2333 if (fbcon_decor_call_helper("modechange", vc
->vc_num
))
2334 fbcon_decor_disable(vc
, 0);
2338 if (fbcon_is_inactive(vc
, info
) ||
2339 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2340 fbcon_del_cursor_timer(info
);
2342 fbcon_add_cursor_timer(info
);
2344 set_blitting_type(vc
, info
);
2345 ops
->cursor_reset
= 1;
2347 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2348 ops
->rotate
= FB_ROTATE_UR
;
2349 set_blitting_type(vc
, info
);
2352 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2353 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2356 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2359 vc
->vc_complement_mask
<<= 1;
2361 updatescrollmode(p
, info
, vc
);
2363 switch (p
->scrollmode
) {
2364 case SCROLL_WRAP_MOVE
:
2365 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2367 case SCROLL_PAN_MOVE
:
2368 case SCROLL_PAN_REDRAW
:
2369 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2370 if (scrollback_phys_max
< 0)
2371 scrollback_phys_max
= 0;
2374 scrollback_phys_max
= 0;
2379 scrollback_current
= 0;
2381 if (!fbcon_is_inactive(vc
, info
)) {
2382 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2383 ops
->update_start(info
);
2386 fbcon_set_palette(vc
, color_table
);
2387 fbcon_clear_margins(vc
, 0);
2389 if (logo_shown
== FBCON_LOGO_DRAW
) {
2391 logo_shown
= fg_console
;
2392 /* This is protected above by initmem_freed */
2393 fb_show_logo(info
, ops
->rotate
);
2395 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2396 vc
->vc_size_row
* (vc
->vc_bottom
-
2403 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2406 struct fb_event event
;
2409 unsigned short charmask
= vc
->vc_hi_font_mask
?
2411 unsigned short oldc
;
2413 oldc
= vc
->vc_video_erase_char
;
2414 vc
->vc_video_erase_char
&= charmask
;
2415 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2416 vc
->vc_video_erase_char
= oldc
;
2421 event
.data
= &blank
;
2422 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2425 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2427 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2428 struct fbcon_ops
*ops
= info
->fbcon_par
;
2431 struct fb_var_screeninfo var
= info
->var
;
2436 if (info
->fbops
->fb_save_state
)
2437 info
->fbops
->fb_save_state(info
);
2438 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2439 fb_set_var(info
, &var
);
2441 ops
->var
= info
->var
;
2442 } else if (info
->fbops
->fb_restore_state
)
2443 info
->fbops
->fb_restore_state(info
);
2446 if (!fbcon_is_inactive(vc
, info
)) {
2447 if (ops
->blank_state
!= blank
) {
2448 ops
->blank_state
= blank
;
2449 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2450 ops
->cursor_flash
= (!blank
);
2452 if (info
->fbops
->fb_blank
)
2453 if(info
->fbops
->fb_blank(blank
, info
)) {
2454 if (fbcon_decor_active(info
, vc
))
2455 fbcon_decor_blank(vc
, info
, blank
);
2457 fbcon_generic_blank(vc
, info
, blank
);
2460 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2461 if (fb_blank(info
, blank
))
2462 fbcon_generic_blank(vc
, info
, blank
);
2469 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2470 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2471 fbcon_del_cursor_timer(info
);
2473 fbcon_add_cursor_timer(info
);
2478 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2480 u8
*fontdata
= vc
->vc_font
.data
;
2481 u8
*data
= font
->data
;
2484 font
->width
= vc
->vc_font
.width
;
2485 font
->height
= vc
->vc_font
.height
;
2486 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2490 if (font
->width
<= 8) {
2491 j
= vc
->vc_font
.height
;
2492 for (i
= 0; i
< font
->charcount
; i
++) {
2493 memcpy(data
, fontdata
, j
);
2494 memset(data
+ j
, 0, 32 - j
);
2498 } else if (font
->width
<= 16) {
2499 j
= vc
->vc_font
.height
* 2;
2500 for (i
= 0; i
< font
->charcount
; i
++) {
2501 memcpy(data
, fontdata
, j
);
2502 memset(data
+ j
, 0, 64 - j
);
2506 } else if (font
->width
<= 24) {
2507 for (i
= 0; i
< font
->charcount
; i
++) {
2508 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2509 *data
++ = fontdata
[0];
2510 *data
++ = fontdata
[1];
2511 *data
++ = fontdata
[2];
2512 fontdata
+= sizeof(u32
);
2514 memset(data
, 0, 3 * (32 - j
));
2515 data
+= 3 * (32 - j
);
2518 j
= vc
->vc_font
.height
* 4;
2519 for (i
= 0; i
< font
->charcount
; i
++) {
2520 memcpy(data
, fontdata
, j
);
2521 memset(data
+ j
, 0, 128 - j
);
2529 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2530 const u8
* data
, int userfont
)
2532 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2533 struct fbcon_ops
*ops
= info
->fbcon_par
;
2534 struct display
*p
= &fb_display
[vc
->vc_num
];
2537 char *old_data
= NULL
;
2539 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2540 fbcon_set_origin(vc
);
2542 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2544 old_data
= vc
->vc_font
.data
;
2546 cnt
= FNTCHARCNT(data
);
2549 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2550 if ((p
->userfont
= userfont
))
2552 vc
->vc_font
.width
= w
;
2553 vc
->vc_font
.height
= h
;
2554 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2555 vc
->vc_hi_font_mask
= 0;
2556 if (vc
->vc_can_do_color
) {
2557 vc
->vc_complement_mask
>>= 1;
2558 vc
->vc_s_complement_mask
>>= 1;
2561 /* ++Edmund: reorder the attribute bits */
2562 if (vc
->vc_can_do_color
) {
2563 unsigned short *cp
=
2564 (unsigned short *) vc
->vc_origin
;
2565 int count
= vc
->vc_screenbuf_size
/ 2;
2567 for (; count
> 0; count
--, cp
++) {
2569 scr_writew(((c
& 0xfe00) >> 1) |
2572 c
= vc
->vc_video_erase_char
;
2573 vc
->vc_video_erase_char
=
2574 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2577 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2578 vc
->vc_hi_font_mask
= 0x100;
2579 if (vc
->vc_can_do_color
) {
2580 vc
->vc_complement_mask
<<= 1;
2581 vc
->vc_s_complement_mask
<<= 1;
2584 /* ++Edmund: reorder the attribute bits */
2586 unsigned short *cp
=
2587 (unsigned short *) vc
->vc_origin
;
2588 int count
= vc
->vc_screenbuf_size
/ 2;
2590 for (; count
> 0; count
--, cp
++) {
2591 unsigned short newc
;
2593 if (vc
->vc_can_do_color
)
2595 ((c
& 0xff00) << 1) | (c
&
2599 scr_writew(newc
, cp
);
2601 c
= vc
->vc_video_erase_char
;
2602 if (vc
->vc_can_do_color
) {
2603 vc
->vc_video_erase_char
=
2604 ((c
& 0xff00) << 1) | (c
& 0xff);
2607 vc
->vc_video_erase_char
= c
& ~0x100;
2613 /* reset wrap/pan */
2616 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2617 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2619 info
->var
.xoffset
= info
->var
.yoffset
= p
->yscroll
= 0;
2620 if (fbcon_decor_active(info
, vc
)) {
2621 cols
= vc
->vc_decor
.twidth
;
2622 rows
= vc
->vc_decor
.theight
;
2627 vc_resize(vc
, cols
, rows
);
2629 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2630 fbcon_update_softback(vc
);
2631 } else if (CON_IS_VISIBLE(vc
)
2632 && vc
->vc_mode
== KD_TEXT
) {
2633 fbcon_clear_margins(vc
, 0);
2637 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2638 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2642 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2644 struct display
*od
= &fb_display
[con
];
2645 struct console_font
*f
= &vc
->vc_font
;
2647 if (od
->fontdata
== f
->data
)
2648 return 0; /* already the same font... */
2649 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2653 * User asked to set font; we are guaranteed that
2654 * a) width and height are in range 1..32
2655 * b) charcount does not exceed 512
2656 * but lets not assume that, since someone might someday want to use larger
2657 * fonts. And charcount of 512 is small for unicode support.
2659 * However, user space gives the font in 32 rows , regardless of
2660 * actual font height. So a new API is needed if support for larger fonts
2661 * is ever implemented.
2664 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2666 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2667 unsigned charcount
= font
->charcount
;
2668 int w
= font
->width
;
2669 int h
= font
->height
;
2672 u8
*new_data
, *data
= font
->data
;
2673 int pitch
= (font
->width
+7) >> 3;
2675 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2676 * If not this check should be changed to charcount < 256 */
2677 if (charcount
!= 256 && charcount
!= 512)
2680 /* Make sure drawing engine can handle the font */
2681 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2682 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2685 /* Make sure driver can handle the font length */
2686 if (fbcon_invalid_charcount(info
, charcount
))
2689 size
= h
* pitch
* charcount
;
2691 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2696 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2697 FNTSIZE(new_data
) = size
;
2698 FNTCHARCNT(new_data
) = charcount
;
2699 REFCOUNT(new_data
) = 0; /* usage counter */
2700 for (i
=0; i
< charcount
; i
++) {
2701 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2704 /* Since linux has a nice crc32 function use it for counting font
2706 csum
= crc32(0, new_data
, size
);
2708 FNTSUM(new_data
) = csum
;
2709 /* Check if the same font is on some other console already */
2710 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2711 struct vc_data
*tmp
= vc_cons
[i
].d
;
2713 if (fb_display
[i
].userfont
&&
2714 fb_display
[i
].fontdata
&&
2715 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2716 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2717 tmp
->vc_font
.width
== w
&&
2718 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2719 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2720 new_data
= (u8
*)fb_display
[i
].fontdata
;
2724 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2727 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2729 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2730 const struct font_desc
*f
;
2733 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2734 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2735 else if (!(f
= find_font(name
)))
2738 font
->width
= f
->width
;
2739 font
->height
= f
->height
;
2740 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2743 static u16 palette_red
[16];
2744 static u16 palette_green
[16];
2745 static u16 palette_blue
[16];
2747 static struct fb_cmap palette_cmap
= {
2748 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2751 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2753 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2757 if (fbcon_is_inactive(vc
, info
) || vc
->vc_num
!= fg_console
)
2760 if (!CON_IS_VISIBLE(vc
))
2763 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2765 for (i
= j
= 0; i
< 16; i
++) {
2767 val
= vc
->vc_palette
[j
++];
2768 palette_red
[k
] = (val
<< 8) | val
;
2769 val
= vc
->vc_palette
[j
++];
2770 palette_green
[k
] = (val
<< 8) | val
;
2771 val
= vc
->vc_palette
[j
++];
2772 palette_blue
[k
] = (val
<< 8) | val
;
2774 palette_cmap
.len
= 16;
2775 palette_cmap
.start
= 0;
2777 * If framebuffer is capable of less than 16 colors,
2778 * use default palette of fbcon.
2781 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2783 if (fbcon_decor_active(info
, vc_cons
[fg_console
].d
) &&
2784 info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
2786 u16
*red
, *green
, *blue
;
2787 int minlen
= min(min(info
->var
.red
.length
, info
->var
.green
.length
),
2788 info
->var
.blue
.length
);
2791 struct fb_cmap cmap
= {
2793 .len
= (1 << minlen
),
2800 red
= kmalloc(256 * sizeof(u16
) * 3, GFP_KERNEL
);
2811 for (i
= 0; i
< cmap
.len
; i
++) {
2812 red
[i
] = green
[i
] = blue
[i
] = (0xffff * i
)/(cmap
.len
-1);
2815 h
= fb_set_cmap(&cmap
, info
);
2816 fbcon_decor_fix_pseudo_pal(info
, vc_cons
[fg_console
].d
);
2821 } else if (fbcon_decor_active(info
, vc_cons
[fg_console
].d
) &&
2822 info
->var
.bits_per_pixel
== 8 && info
->bgdecor
.cmap
.red
!= NULL
)
2823 fb_set_cmap(&info
->bgdecor
.cmap
, info
);
2825 out
: return fb_set_cmap(&palette_cmap
, info
);
2828 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2833 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2834 return (u16
*) (vc
->vc_origin
+ offset
);
2835 line
= offset
/ vc
->vc_size_row
;
2836 if (line
>= softback_lines
)
2837 return (u16
*) (vc
->vc_origin
+ offset
-
2838 softback_lines
* vc
->vc_size_row
);
2839 p
= softback_curr
+ offset
;
2840 if (p
>= softback_end
)
2841 p
+= softback_buf
- softback_end
;
2845 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2851 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2852 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2854 x
= offset
% vc
->vc_cols
;
2855 y
= offset
/ vc
->vc_cols
;
2856 if (vc
->vc_num
== fg_console
)
2857 y
+= softback_lines
;
2858 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2859 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2860 unsigned long offset
= pos
- softback_curr
;
2862 if (pos
< softback_curr
)
2863 offset
+= softback_end
- softback_buf
;
2865 x
= offset
% vc
->vc_cols
;
2866 y
= offset
/ vc
->vc_cols
;
2867 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2868 if (ret
== softback_end
)
2870 if (ret
== softback_in
)
2871 ret
= vc
->vc_origin
;
2873 /* Should not happen */
2875 ret
= vc
->vc_origin
;
2884 /* As we might be inside of softback, we may work with non-contiguous buffer,
2885 that's why we have to use a separate routine. */
2886 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2889 u16 a
= scr_readw(p
);
2890 if (!vc
->vc_can_do_color
)
2892 else if (vc
->vc_hi_font_mask
== 0x100)
2893 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2894 (((a
) & 0x0e00) << 4);
2896 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2897 (((a
) & 0x0700) << 4);
2899 if (p
== (u16
*) softback_end
)
2900 p
= (u16
*) softback_buf
;
2901 if (p
== (u16
*) softback_in
)
2902 p
= (u16
*) vc
->vc_origin
;
2906 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2908 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2909 struct fbcon_ops
*ops
= info
->fbcon_par
;
2910 struct display
*disp
= &fb_display
[fg_console
];
2911 int offset
, limit
, scrollback_old
;
2914 if (vc
->vc_num
!= fg_console
)
2916 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2918 if (logo_shown
>= 0) {
2919 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2921 if (conp2
->vc_top
== logo_lines
2922 && conp2
->vc_bottom
== conp2
->vc_rows
)
2924 if (logo_shown
== vc
->vc_num
) {
2930 logo_lines
* vc
->vc_size_row
;
2931 for (i
= 0; i
< logo_lines
; i
++) {
2932 if (p
== softback_top
)
2934 if (p
== softback_buf
)
2936 p
-= vc
->vc_size_row
;
2937 q
-= vc
->vc_size_row
;
2938 scr_memcpyw((u16
*) q
, (u16
*) p
,
2941 softback_in
= softback_curr
= p
;
2942 update_region(vc
, vc
->vc_origin
,
2943 logo_lines
* vc
->vc_cols
);
2945 logo_shown
= FBCON_LOGO_CANSHOW
;
2947 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2948 fbcon_redraw_softback(vc
, disp
, lines
);
2949 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2953 if (!scrollback_phys_max
)
2956 scrollback_old
= scrollback_current
;
2957 scrollback_current
-= lines
;
2958 if (scrollback_current
< 0)
2959 scrollback_current
= 0;
2960 else if (scrollback_current
> scrollback_max
)
2961 scrollback_current
= scrollback_max
;
2962 if (scrollback_current
== scrollback_old
)
2965 if (fbcon_is_inactive(vc
, info
))
2968 fbcon_cursor(vc
, CM_ERASE
);
2970 offset
= disp
->yscroll
- scrollback_current
;
2971 limit
= disp
->vrows
;
2972 switch (disp
->scrollmode
) {
2973 case SCROLL_WRAP_MOVE
:
2974 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2976 case SCROLL_PAN_MOVE
:
2977 case SCROLL_PAN_REDRAW
:
2978 limit
-= vc
->vc_rows
;
2979 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2984 else if (offset
>= limit
)
2987 ops
->var
.xoffset
= 0;
2988 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2989 ops
->update_start(info
);
2991 if (!scrollback_current
)
2992 fbcon_cursor(vc
, CM_DRAW
);
2996 static int fbcon_set_origin(struct vc_data
*vc
)
2999 fbcon_scrolldelta(vc
, softback_lines
);
3003 static void fbcon_suspended(struct fb_info
*info
)
3005 struct vc_data
*vc
= NULL
;
3006 struct fbcon_ops
*ops
= info
->fbcon_par
;
3008 if (!ops
|| ops
->currcon
< 0)
3010 vc
= vc_cons
[ops
->currcon
].d
;
3012 /* Clear cursor, restore saved data */
3013 fbcon_cursor(vc
, CM_ERASE
);
3016 static void fbcon_resumed(struct fb_info
*info
)
3019 struct fbcon_ops
*ops
= info
->fbcon_par
;
3021 if (!ops
|| ops
->currcon
< 0)
3023 vc
= vc_cons
[ops
->currcon
].d
;
3028 static void fbcon_modechanged(struct fb_info
*info
)
3030 struct fbcon_ops
*ops
= info
->fbcon_par
;
3035 if (!ops
|| ops
->currcon
< 0)
3037 vc
= vc_cons
[ops
->currcon
].d
;
3038 if (vc
->vc_mode
!= KD_TEXT
||
3039 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3042 p
= &fb_display
[vc
->vc_num
];
3043 set_blitting_type(vc
, info
);
3045 if (CON_IS_VISIBLE(vc
)) {
3046 var_to_display(p
, &info
->var
, info
);
3047 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
3048 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
3049 cols
/= vc
->vc_font
.width
;
3050 rows
/= vc
->vc_font
.height
;
3052 if (!fbcon_decor_active_nores(info
, vc
)) {
3053 vc_resize(vc
, cols
, rows
);
3055 if (fbcon_decor_call_helper("modechange", vc
->vc_num
))
3056 fbcon_decor_disable(vc
, 0);
3059 updatescrollmode(p
, info
, vc
);
3061 scrollback_current
= 0;
3063 if (!fbcon_is_inactive(vc
, info
)) {
3064 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
3065 ops
->update_start(info
);
3068 fbcon_set_palette(vc
, color_table
);
3071 fbcon_update_softback(vc
);
3075 static void fbcon_set_all_vcs(struct fb_info
*info
)
3077 struct fbcon_ops
*ops
= info
->fbcon_par
;
3080 int i
, rows
, cols
, fg
= -1;
3082 if (!ops
|| ops
->currcon
< 0)
3085 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3087 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
3088 registered_fb
[con2fb_map
[i
]] != info
)
3091 if (CON_IS_VISIBLE(vc
)) {
3096 p
= &fb_display
[vc
->vc_num
];
3097 set_blitting_type(vc
, info
);
3098 var_to_display(p
, &info
->var
, info
);
3099 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
3100 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
3101 cols
/= vc
->vc_font
.width
;
3102 rows
/= vc
->vc_font
.height
;
3103 vc_resize(vc
, cols
, rows
);
3107 fbcon_modechanged(info
);
3110 static int fbcon_mode_deleted(struct fb_info
*info
,
3111 struct fb_videomode
*mode
)
3113 struct fb_info
*fb_info
;
3115 int i
, j
, found
= 0;
3117 /* before deletion, ensure that mode is not in use */
3118 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3122 fb_info
= registered_fb
[j
];
3123 if (fb_info
!= info
)
3128 if (fb_mode_is_equal(p
->mode
, mode
)) {
3136 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3137 static int fbcon_unbind(void)
3141 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3146 static inline int fbcon_unbind(void)
3150 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3152 static int fbcon_fb_unbind(int idx
)
3154 int i
, new_idx
= -1, ret
= 0;
3156 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3157 if (con2fb_map
[i
] != idx
&&
3158 con2fb_map
[i
] != -1) {
3164 if (new_idx
!= -1) {
3165 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3166 if (con2fb_map
[i
] == idx
)
3167 set_con2fb_map(i
, new_idx
, 0);
3170 ret
= fbcon_unbind();
3175 static int fbcon_fb_unregistered(struct fb_info
*info
)
3177 int i
, idx
= info
->node
;
3179 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3180 if (con2fb_map
[i
] == idx
)
3184 if (idx
== info_idx
) {
3187 for (i
= 0; i
< FB_MAX
; i
++) {
3188 if (registered_fb
[i
] != NULL
) {
3195 if (info_idx
!= -1) {
3196 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3197 if (con2fb_map
[i
] == -1)
3198 con2fb_map
[i
] = info_idx
;
3202 if (!num_registered_fb
)
3203 unregister_con_driver(&fb_con
);
3206 if (primary_device
== idx
)
3207 primary_device
= -1;
3212 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3213 static void fbcon_select_primary(struct fb_info
*info
)
3215 if (!map_override
&& primary_device
== -1 &&
3216 fb_is_primary_device(info
)) {
3219 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3220 info
->fix
.id
, info
->node
);
3221 primary_device
= info
->node
;
3223 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3224 con2fb_map_boot
[i
] = primary_device
;
3226 if (con_is_bound(&fb_con
)) {
3227 printk(KERN_INFO
"fbcon: Remapping primary device, "
3228 "fb%i, to tty %i-%i\n", info
->node
,
3229 first_fb_vc
+ 1, last_fb_vc
+ 1);
3230 info_idx
= primary_device
;
3236 static inline void fbcon_select_primary(struct fb_info
*info
)
3240 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3242 static int fbcon_fb_registered(struct fb_info
*info
)
3244 int ret
= 0, i
, idx
= info
->node
;
3246 fbcon_select_primary(info
);
3248 if (info_idx
== -1) {
3249 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3250 if (con2fb_map_boot
[i
] == idx
) {
3257 ret
= fbcon_takeover(1);
3259 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3260 if (con2fb_map_boot
[i
] == idx
)
3261 set_con2fb_map(i
, idx
, 0);
3268 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3270 struct fbcon_ops
*ops
= info
->fbcon_par
;
3273 if (!ops
|| ops
->currcon
< 0)
3276 vc
= vc_cons
[ops
->currcon
].d
;
3277 if (vc
->vc_mode
!= KD_TEXT
||
3278 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3281 if (CON_IS_VISIBLE(vc
)) {
3285 do_unblank_screen(0);
3287 ops
->blank_state
= blank
;
3290 static void fbcon_new_modelist(struct fb_info
*info
)
3294 struct fb_var_screeninfo var
;
3295 const struct fb_videomode
*mode
;
3297 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3298 if (registered_fb
[con2fb_map
[i
]] != info
)
3300 if (!fb_display
[i
].mode
)
3303 display_to_var(&var
, &fb_display
[i
]);
3304 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3306 fb_videomode_to_var(&var
, mode
);
3307 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3311 static void fbcon_get_requirement(struct fb_info
*info
,
3312 struct fb_blit_caps
*caps
)
3320 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3322 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3323 info
->node
== con2fb_map
[i
]) {
3325 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3326 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3327 charcnt
= (p
->userfont
) ?
3328 FNTCHARCNT(p
->fontdata
) : 256;
3329 if (caps
->len
< charcnt
)
3330 caps
->len
= charcnt
;
3334 vc
= vc_cons
[fg_console
].d
;
3336 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3337 info
->node
== con2fb_map
[fg_console
]) {
3338 p
= &fb_display
[fg_console
];
3339 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3340 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3341 caps
->len
= (p
->userfont
) ?
3342 FNTCHARCNT(p
->fontdata
) : 256;
3347 static int fbcon_event_notify(struct notifier_block
*self
,
3348 unsigned long action
, void *data
)
3350 struct fb_event
*event
= data
;
3351 struct fb_info
*info
= event
->info
;
3352 struct fb_videomode
*mode
;
3353 struct fb_con2fbmap
*con2fb
;
3354 struct fb_blit_caps
*caps
;
3358 * ignore all events except driver registration and deregistration
3359 * if fbcon is not active
3361 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3362 action
== FB_EVENT_FB_UNREGISTERED
))
3366 case FB_EVENT_SUSPEND
:
3367 fbcon_suspended(info
);
3369 case FB_EVENT_RESUME
:
3370 fbcon_resumed(info
);
3372 case FB_EVENT_MODE_CHANGE
:
3373 fbcon_modechanged(info
);
3375 case FB_EVENT_MODE_CHANGE_ALL
:
3376 fbcon_set_all_vcs(info
);
3378 case FB_EVENT_MODE_DELETE
:
3380 ret
= fbcon_mode_deleted(info
, mode
);
3382 case FB_EVENT_FB_UNBIND
:
3383 ret
= fbcon_fb_unbind(info
->node
);
3385 case FB_EVENT_FB_REGISTERED
:
3386 ret
= fbcon_fb_registered(info
);
3388 case FB_EVENT_FB_UNREGISTERED
:
3389 ret
= fbcon_fb_unregistered(info
);
3391 case FB_EVENT_SET_CONSOLE_MAP
:
3392 con2fb
= event
->data
;
3393 ret
= set_con2fb_map(con2fb
->console
- 1,
3394 con2fb
->framebuffer
, 1);
3396 case FB_EVENT_GET_CONSOLE_MAP
:
3397 con2fb
= event
->data
;
3398 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3400 case FB_EVENT_BLANK
:
3401 fbcon_fb_blanked(info
, *(int *)event
->data
);
3403 case FB_EVENT_NEW_MODELIST
:
3404 fbcon_new_modelist(info
);
3406 case FB_EVENT_GET_REQ
:
3408 fbcon_get_requirement(info
, caps
);
3417 * The console `switch' structure for the frame buffer based console
3420 static const struct consw fb_con
= {
3421 .owner
= THIS_MODULE
,
3422 .con_startup
= fbcon_startup
,
3423 .con_init
= fbcon_init
,
3424 .con_deinit
= fbcon_deinit
,
3425 .con_clear
= fbcon_clear
,
3426 .con_putc
= fbcon_putc
,
3427 .con_putcs
= fbcon_putcs
,
3428 .con_cursor
= fbcon_cursor
,
3429 .con_scroll
= fbcon_scroll
,
3430 .con_bmove
= fbcon_bmove
,
3431 .con_switch
= fbcon_switch
,
3432 .con_blank
= fbcon_blank
,
3433 .con_font_set
= fbcon_set_font
,
3434 .con_font_get
= fbcon_get_font
,
3435 .con_font_default
= fbcon_set_def_font
,
3436 .con_font_copy
= fbcon_copy_font
,
3437 .con_set_palette
= fbcon_set_palette
,
3438 .con_scrolldelta
= fbcon_scrolldelta
,
3439 .con_set_origin
= fbcon_set_origin
,
3440 .con_invert_region
= fbcon_invert_region
,
3441 .con_screen_pos
= fbcon_screen_pos
,
3442 .con_getxy
= fbcon_getxy
,
3443 .con_resize
= fbcon_resize
,
3446 static struct notifier_block fbcon_event_notifier
= {
3447 .notifier_call
= fbcon_event_notify
,
3450 static ssize_t
store_rotate(struct device
*device
,
3451 struct device_attribute
*attr
, const char *buf
,
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
];
3468 rotate
= simple_strtoul(buf
, last
, 0);
3469 fbcon_rotate(info
, rotate
);
3471 release_console_sem();
3475 static ssize_t
store_rotate_all(struct device
*device
,
3476 struct device_attribute
*attr
,const char *buf
,
3479 struct fb_info
*info
;
3483 if (fbcon_has_exited
)
3486 acquire_console_sem();
3487 idx
= con2fb_map
[fg_console
];
3489 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3492 info
= registered_fb
[idx
];
3493 rotate
= simple_strtoul(buf
, last
, 0);
3494 fbcon_rotate_all(info
, rotate
);
3496 release_console_sem();
3500 static ssize_t
show_rotate(struct device
*device
,
3501 struct device_attribute
*attr
,char *buf
)
3503 struct fb_info
*info
;
3504 int rotate
= 0, idx
;
3506 if (fbcon_has_exited
)
3509 acquire_console_sem();
3510 idx
= con2fb_map
[fg_console
];
3512 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3515 info
= registered_fb
[idx
];
3516 rotate
= fbcon_get_rotate(info
);
3518 release_console_sem();
3519 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3522 static ssize_t
show_cursor_blink(struct device
*device
,
3523 struct device_attribute
*attr
, char *buf
)
3525 struct fb_info
*info
;
3526 struct fbcon_ops
*ops
;
3527 int idx
, blink
= -1;
3529 if (fbcon_has_exited
)
3532 acquire_console_sem();
3533 idx
= con2fb_map
[fg_console
];
3535 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3538 info
= registered_fb
[idx
];
3539 ops
= info
->fbcon_par
;
3544 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3546 release_console_sem();
3547 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3550 static ssize_t
store_cursor_blink(struct device
*device
,
3551 struct device_attribute
*attr
,
3552 const char *buf
, size_t count
)
3554 struct fb_info
*info
;
3558 if (fbcon_has_exited
)
3561 acquire_console_sem();
3562 idx
= con2fb_map
[fg_console
];
3564 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3567 info
= registered_fb
[idx
];
3569 if (!info
->fbcon_par
)
3572 blink
= simple_strtoul(buf
, last
, 0);
3575 fbcon_cursor_noblink
= 0;
3576 fbcon_add_cursor_timer(info
);
3578 fbcon_cursor_noblink
= 1;
3579 fbcon_del_cursor_timer(info
);
3583 release_console_sem();
3587 static struct device_attribute device_attrs
[] = {
3588 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3589 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3590 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3591 store_cursor_blink
),
3594 static int fbcon_init_device(void)
3598 fbcon_has_sysfs
= 1;
3600 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3601 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3609 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3611 fbcon_has_sysfs
= 0;
3617 static void fbcon_start(void)
3619 if (num_registered_fb
) {
3622 acquire_console_sem();
3624 for (i
= 0; i
< FB_MAX
; i
++) {
3625 if (registered_fb
[i
] != NULL
) {
3631 release_console_sem();
3636 static void fbcon_exit(void)
3638 struct fb_info
*info
;
3641 if (fbcon_has_exited
)
3645 free_irq(IRQ_AUTO_4
, fb_vbl_handler
);
3648 if (MACH_IS_MAC
&& vbl_detected
)
3649 free_irq(IRQ_MAC_VBL
, fb_vbl_handler
);
3652 kfree((void *)softback_buf
);
3655 for (i
= 0; i
< FB_MAX
; i
++) {
3657 info
= registered_fb
[i
];
3662 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3663 if (con2fb_map
[j
] == i
)
3668 if (info
->fbops
->fb_release
)
3669 info
->fbops
->fb_release(info
, 0);
3670 module_put(info
->fbops
->owner
);
3672 if (info
->fbcon_par
) {
3673 struct fbcon_ops
*ops
= info
->fbcon_par
;
3675 fbcon_del_cursor_timer(info
);
3676 kfree(ops
->cursor_src
);
3677 kfree(info
->fbcon_par
);
3678 info
->fbcon_par
= NULL
;
3681 if (info
->queue
.func
== fb_flashcursor
)
3682 info
->queue
.func
= NULL
;
3687 fbcon_has_exited
= 1;
3690 static int __init
fb_console_init(void)
3694 acquire_console_sem();
3695 fb_register_client(&fbcon_event_notifier
);
3696 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3699 if (IS_ERR(fbcon_device
)) {
3700 printk(KERN_WARNING
"Unable to create device "
3701 "for fbcon; errno = %ld\n",
3702 PTR_ERR(fbcon_device
));
3703 fbcon_device
= NULL
;
3705 fbcon_init_device();
3707 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3710 release_console_sem();
3715 module_init(fb_console_init
);
3719 static void __exit
fbcon_deinit_device(void)
3723 if (fbcon_has_sysfs
) {
3724 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3725 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3727 fbcon_has_sysfs
= 0;
3731 static void __exit
fb_console_exit(void)
3733 acquire_console_sem();
3734 fb_unregister_client(&fbcon_event_notifier
);
3735 fbcon_deinit_device();
3736 device_destroy(fb_class
, MKDEV(0, 0));
3738 release_console_sem();
3739 unregister_con_driver(&fb_con
);
3742 module_exit(fb_console_exit
);
3746 MODULE_LICENSE("GPL");