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>
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
96 static struct display fb_display
[MAX_NR_CONSOLES
];
98 static signed char con2fb_map
[MAX_NR_CONSOLES
];
99 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
101 static int logo_lines
;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown
= FBCON_LOGO_CANSHOW
;
105 /* Software scrollback */
106 static int fbcon_softback_size
= 32768;
107 static unsigned long softback_buf
, softback_curr
;
108 static unsigned long softback_in
;
109 static unsigned long softback_top
, softback_end
;
110 static int softback_lines
;
111 /* console mappings */
112 static int first_fb_vc
;
113 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
114 static int fbcon_is_default
= 1;
115 static int fbcon_has_exited
;
116 static int primary_device
= -1;
117 static int fbcon_has_console_bind
;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override
;
122 static inline void fbcon_map_override(void)
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
133 static char fontname
[40];
135 /* current fb_info */
136 static int info_idx
= -1;
138 /* console rotation */
139 static int initial_rotation
;
140 static int fbcon_has_sysfs
;
142 static const struct consw fb_con
;
144 #define CM_SOFTBACK (8)
146 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
148 static int fbcon_set_origin(struct vc_data
*);
150 #define CURSOR_DRAW_DELAY (1)
152 static int vbl_cursor_cnt
;
153 static int fbcon_cursor_noblink
;
155 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
158 * Interface used by the world
161 static const char *fbcon_startup(void);
162 static void fbcon_init(struct vc_data
*vc
, int init
);
163 static void fbcon_deinit(struct vc_data
*vc
);
164 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
166 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
167 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
168 int count
, int ypos
, int xpos
);
169 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
170 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
171 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
173 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
174 int height
, int width
);
175 static int fbcon_switch(struct vc_data
*vc
);
176 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
177 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
178 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
183 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
184 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
185 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
186 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
187 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
188 int dy
, int dx
, int height
, int width
, u_int y_break
);
189 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
191 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
192 int line
, int count
, int dy
);
193 static void fbcon_modechanged(struct fb_info
*info
);
194 static void fbcon_set_all_vcs(struct fb_info
*info
);
195 static void fbcon_start(void);
196 static void fbcon_exit(void);
197 static struct device
*fbcon_device
;
199 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
200 static inline void fbcon_set_rotation(struct fb_info
*info
)
202 struct fbcon_ops
*ops
= info
->fbcon_par
;
204 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
205 ops
->p
->con_rotate
< 4)
206 ops
->rotate
= ops
->p
->con_rotate
;
211 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
213 struct fbcon_ops
*ops
= info
->fbcon_par
;
214 struct fb_info
*fb_info
;
216 if (!ops
|| ops
->currcon
== -1)
219 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
221 if (info
== fb_info
) {
222 struct display
*p
= &fb_display
[ops
->currcon
];
225 p
->con_rotate
= rotate
;
229 fbcon_modechanged(info
);
233 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
235 struct fbcon_ops
*ops
= info
->fbcon_par
;
240 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
243 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
245 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
246 registered_fb
[con2fb_map
[i
]] != info
)
249 p
= &fb_display
[vc
->vc_num
];
250 p
->con_rotate
= rotate
;
253 fbcon_set_all_vcs(info
);
256 static inline void fbcon_set_rotation(struct fb_info
*info
)
258 struct fbcon_ops
*ops
= info
->fbcon_par
;
260 ops
->rotate
= FB_ROTATE_UR
;
263 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
268 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
272 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
274 static int fbcon_get_rotate(struct fb_info
*info
)
276 struct fbcon_ops
*ops
= info
->fbcon_par
;
278 return (ops
) ? ops
->rotate
: 0;
281 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
283 struct fbcon_ops
*ops
= info
->fbcon_par
;
285 return (info
->state
!= FBINFO_STATE_RUNNING
||
286 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
) &&
287 !vt_force_oops_output(vc
);
290 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
293 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
296 if (console_blanked
) {
297 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
299 c
= vc
->vc_video_erase_char
& charmask
;
303 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
304 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
309 int col
= mono_col(info
);
311 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
312 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
317 color
= (is_fg
) ? fg
: bg
;
322 * Scale down 16-colors to 4 colors. Default 4-color palette
323 * is grayscale. However, simply dividing the values by 4
324 * will not work, as colors 1, 2 and 3 will be scaled-down
325 * to zero rendering them invisible. So empirically convert
326 * colors to a sane 4-level grayscale.
330 color
= 0; /* black */
333 color
= 2; /* white */
336 color
= 1; /* gray */
339 color
= 3; /* intense white */
345 * Last 8 entries of default 16-color palette is a more intense
346 * version of the first 8 (i.e., same chrominance, different
357 static void fbcon_update_softback(struct vc_data
*vc
)
359 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
362 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
364 /* Smaller scrollback makes no sense, and 0 would screw
365 the operation totally */
369 static void fb_flashcursor(struct work_struct
*work
)
371 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
372 struct fbcon_ops
*ops
= info
->fbcon_par
;
373 struct vc_data
*vc
= NULL
;
378 /* FIXME: we should sort out the unbind locking instead */
379 /* instead we just fail to flash the cursor if we can't get
380 * the lock instead of blocking fbcon deinit */
381 ret
= console_trylock();
385 if (ops
&& ops
->currcon
!= -1)
386 vc
= vc_cons
[ops
->currcon
].d
;
388 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
389 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
395 c
= scr_readw((u16
*) vc
->vc_pos
);
396 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
398 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
399 get_color(vc
, info
, c
, 0));
403 static void cursor_timer_handler(unsigned long dev_addr
)
405 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
406 struct fbcon_ops
*ops
= info
->fbcon_par
;
408 schedule_work(&info
->queue
);
409 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
412 static void fbcon_add_cursor_timer(struct fb_info
*info
)
414 struct fbcon_ops
*ops
= info
->fbcon_par
;
416 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
417 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
418 !fbcon_cursor_noblink
) {
419 if (!info
->queue
.func
)
420 INIT_WORK(&info
->queue
, fb_flashcursor
);
422 init_timer(&ops
->cursor_timer
);
423 ops
->cursor_timer
.function
= cursor_timer_handler
;
424 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
425 ops
->cursor_timer
.data
= (unsigned long ) info
;
426 add_timer(&ops
->cursor_timer
);
427 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
431 static void fbcon_del_cursor_timer(struct fb_info
*info
)
433 struct fbcon_ops
*ops
= info
->fbcon_par
;
435 if (info
->queue
.func
== fb_flashcursor
&&
436 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
437 del_timer_sync(&ops
->cursor_timer
);
438 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
443 static int __init
fb_console_setup(char *this_opt
)
448 if (!this_opt
|| !*this_opt
)
451 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
452 if (!strncmp(options
, "font:", 5))
453 strcpy(fontname
, options
+ 5);
455 if (!strncmp(options
, "scrollback:", 11)) {
458 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
459 if (*options
== 'k' || *options
== 'K') {
460 fbcon_softback_size
*= 1024;
470 if (!strncmp(options
, "map:", 4)) {
473 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
477 (options
[j
++]-'0') % FB_MAX
;
480 fbcon_map_override();
486 if (!strncmp(options
, "vc:", 3)) {
489 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
492 if (*options
++ == '-')
493 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
494 fbcon_is_default
= 0;
497 if (!strncmp(options
, "rotate:", 7)) {
500 initial_rotation
= simple_strtoul(options
, &options
, 0);
501 if (initial_rotation
> 3)
502 initial_rotation
= 0;
508 __setup("fbcon=", fb_console_setup
);
511 static int search_fb_in_map(int idx
)
515 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
516 if (con2fb_map
[i
] == idx
)
522 static int search_for_mapped_con(void)
526 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
527 if (con2fb_map
[i
] != -1)
533 static int fbcon_takeover(int show_logo
)
537 if (!num_registered_fb
)
541 logo_shown
= FBCON_LOGO_DONTSHOW
;
543 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
544 con2fb_map
[i
] = info_idx
;
546 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
550 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
555 fbcon_has_console_bind
= 1;
562 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
563 int cols
, int rows
, int new_cols
, int new_rows
)
565 logo_shown
= FBCON_LOGO_DONTSHOW
;
568 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
569 int cols
, int rows
, int new_cols
, int new_rows
)
571 /* Need to make room for the logo */
572 struct fbcon_ops
*ops
= info
->fbcon_par
;
573 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
574 unsigned short *save
= NULL
, *r
, *q
;
577 if (info
->flags
& FBINFO_MODULE
) {
578 logo_shown
= FBCON_LOGO_DONTSHOW
;
583 * remove underline attribute from erase character
584 * if black and white framebuffer.
586 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
588 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
589 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
590 q
= (unsigned short *) (vc
->vc_origin
+
591 vc
->vc_size_row
* rows
);
592 step
= logo_lines
* cols
;
593 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
594 if (scr_readw(r
) != vc
->vc_video_erase_char
)
596 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
597 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
599 int i
= cols
< new_cols
? cols
: new_cols
;
600 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
602 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
603 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
608 /* We can scroll screen down */
610 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
611 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
616 if (vc
->vc_y
+ logo_lines
>= rows
)
617 lines
= rows
- vc
->vc_y
- 1;
621 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
624 scr_memsetw((unsigned short *) vc
->vc_origin
,
626 vc
->vc_size_row
* logo_lines
);
628 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
629 fbcon_clear_margins(vc
, 0);
634 q
= (unsigned short *) (vc
->vc_origin
+
637 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
638 vc
->vc_y
+= logo_lines
;
639 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
643 if (logo_lines
> vc
->vc_bottom
) {
644 logo_shown
= FBCON_LOGO_CANSHOW
;
646 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
647 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
648 logo_shown
= FBCON_LOGO_DRAW
;
649 vc
->vc_top
= logo_lines
;
654 #ifdef CONFIG_FB_TILEBLITTING
655 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
657 struct fbcon_ops
*ops
= info
->fbcon_par
;
659 ops
->p
= &fb_display
[vc
->vc_num
];
661 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
662 fbcon_set_tileops(vc
, info
);
664 fbcon_set_rotation(info
);
665 fbcon_set_bitops(ops
);
669 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
673 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
674 info
->tileops
->fb_get_tilemax(info
) < charcount
)
680 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
682 struct fbcon_ops
*ops
= info
->fbcon_par
;
684 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
685 ops
->p
= &fb_display
[vc
->vc_num
];
686 fbcon_set_rotation(info
);
687 fbcon_set_bitops(ops
);
690 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
695 #endif /* CONFIG_MISC_TILEBLITTING */
698 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
699 int unit
, int oldidx
)
701 struct fbcon_ops
*ops
= NULL
;
704 if (!try_module_get(info
->fbops
->owner
))
707 if (!err
&& info
->fbops
->fb_open
&&
708 info
->fbops
->fb_open(info
, 0))
712 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
718 info
->fbcon_par
= ops
;
721 set_blitting_type(vc
, info
);
725 con2fb_map
[unit
] = oldidx
;
726 module_put(info
->fbops
->owner
);
732 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
733 struct fb_info
*newinfo
, int unit
,
734 int oldidx
, int found
)
736 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
739 if (oldinfo
->fbops
->fb_release
&&
740 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
741 con2fb_map
[unit
] = oldidx
;
742 if (!found
&& newinfo
->fbops
->fb_release
)
743 newinfo
->fbops
->fb_release(newinfo
, 0);
745 module_put(newinfo
->fbops
->owner
);
750 fbcon_del_cursor_timer(oldinfo
);
751 kfree(ops
->cursor_state
.mask
);
752 kfree(ops
->cursor_data
);
753 kfree(ops
->fontbuffer
);
754 kfree(oldinfo
->fbcon_par
);
755 oldinfo
->fbcon_par
= NULL
;
756 module_put(oldinfo
->fbops
->owner
);
758 If oldinfo and newinfo are driving the same hardware,
759 the fb_release() method of oldinfo may attempt to
760 restore the hardware state. This will leave the
761 newinfo in an undefined state. Thus, a call to
762 fb_set_par() may be needed for the newinfo.
764 if (newinfo
->fbops
->fb_set_par
) {
765 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
768 printk(KERN_ERR
"con2fb_release_oldinfo: "
769 "detected unhandled fb_set_par error, "
770 "error code %d\n", ret
);
777 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
778 int unit
, int show_logo
)
780 struct fbcon_ops
*ops
= info
->fbcon_par
;
783 ops
->currcon
= fg_console
;
785 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
786 ret
= info
->fbops
->fb_set_par(info
);
789 printk(KERN_ERR
"con2fb_init_display: detected "
790 "unhandled fb_set_par error, "
791 "error code %d\n", ret
);
794 ops
->flags
|= FBCON_FLAGS_INIT
;
796 fbcon_set_disp(info
, &info
->var
, unit
);
799 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
800 struct fb_info
*fg_info
=
801 registered_fb
[con2fb_map
[fg_console
]];
803 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
804 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
808 update_screen(vc_cons
[fg_console
].d
);
812 * set_con2fb_map - map console to frame buffer device
813 * @unit: virtual console number to map
814 * @newidx: frame buffer index to map virtual console to
815 * @user: user request
817 * Maps a virtual console @unit to a frame buffer device
820 static int set_con2fb_map(int unit
, int newidx
, int user
)
822 struct vc_data
*vc
= vc_cons
[unit
].d
;
823 int oldidx
= con2fb_map
[unit
];
824 struct fb_info
*info
= registered_fb
[newidx
];
825 struct fb_info
*oldinfo
= NULL
;
828 if (oldidx
== newidx
)
834 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
836 return fbcon_takeover(0);
840 oldinfo
= registered_fb
[oldidx
];
842 found
= search_fb_in_map(newidx
);
845 con2fb_map
[unit
] = newidx
;
847 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
851 * If old fb is not mapped to any of the consoles,
852 * fbcon should release it.
854 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
855 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
859 int show_logo
= (fg_console
== 0 && !user
&&
860 logo_shown
!= FBCON_LOGO_DONTSHOW
);
863 fbcon_add_cursor_timer(info
);
864 con2fb_map_boot
[unit
] = newidx
;
865 con2fb_init_display(vc
, info
, unit
, show_logo
);
868 if (!search_fb_in_map(info_idx
))
876 * Low Level Operations
878 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
879 static int var_to_display(struct display
*disp
,
880 struct fb_var_screeninfo
*var
,
881 struct fb_info
*info
)
883 disp
->xres_virtual
= var
->xres_virtual
;
884 disp
->yres_virtual
= var
->yres_virtual
;
885 disp
->bits_per_pixel
= var
->bits_per_pixel
;
886 disp
->grayscale
= var
->grayscale
;
887 disp
->nonstd
= var
->nonstd
;
888 disp
->accel_flags
= var
->accel_flags
;
889 disp
->height
= var
->height
;
890 disp
->width
= var
->width
;
891 disp
->red
= var
->red
;
892 disp
->green
= var
->green
;
893 disp
->blue
= var
->blue
;
894 disp
->transp
= var
->transp
;
895 disp
->rotate
= var
->rotate
;
896 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
897 if (disp
->mode
== NULL
)
898 /* This should not happen */
903 static void display_to_var(struct fb_var_screeninfo
*var
,
904 struct display
*disp
)
906 fb_videomode_to_var(var
, disp
->mode
);
907 var
->xres_virtual
= disp
->xres_virtual
;
908 var
->yres_virtual
= disp
->yres_virtual
;
909 var
->bits_per_pixel
= disp
->bits_per_pixel
;
910 var
->grayscale
= disp
->grayscale
;
911 var
->nonstd
= disp
->nonstd
;
912 var
->accel_flags
= disp
->accel_flags
;
913 var
->height
= disp
->height
;
914 var
->width
= disp
->width
;
915 var
->red
= disp
->red
;
916 var
->green
= disp
->green
;
917 var
->blue
= disp
->blue
;
918 var
->transp
= disp
->transp
;
919 var
->rotate
= disp
->rotate
;
922 static const char *fbcon_startup(void)
924 const char *display_desc
= "frame buffer device";
925 struct display
*p
= &fb_display
[fg_console
];
926 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
927 const struct font_desc
*font
= NULL
;
928 struct module
*owner
;
929 struct fb_info
*info
= NULL
;
930 struct fbcon_ops
*ops
;
934 * If num_registered_fb is zero, this is a call for the dummy part.
935 * The frame buffer devices weren't initialized yet.
937 if (!num_registered_fb
|| info_idx
== -1)
940 * Instead of blindly using registered_fb[0], we use info_idx, set by
943 info
= registered_fb
[info_idx
];
947 owner
= info
->fbops
->owner
;
948 if (!try_module_get(owner
))
950 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
955 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
963 ops
->cur_rotate
= -1;
964 info
->fbcon_par
= ops
;
965 p
->con_rotate
= initial_rotation
;
966 set_blitting_type(vc
, info
);
968 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
969 if (fbcon_softback_size
) {
973 kmalloc(fbcon_softback_size
,
976 fbcon_softback_size
= 0;
982 kfree((void *) softback_buf
);
988 softback_in
= softback_top
= softback_curr
=
993 /* Setup default font */
995 if (!fontname
[0] || !(font
= find_font(fontname
)))
996 font
= get_default_font(info
->var
.xres
,
999 info
->pixmap
.blit_y
);
1000 vc
->vc_font
.width
= font
->width
;
1001 vc
->vc_font
.height
= font
->height
;
1002 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1003 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1006 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1007 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1008 cols
/= vc
->vc_font
.width
;
1009 rows
/= vc
->vc_font
.height
;
1010 vc_resize(vc
, cols
, rows
);
1012 DPRINTK("mode: %s\n", info
->fix
.id
);
1013 DPRINTK("visual: %d\n", info
->fix
.visual
);
1014 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1016 info
->var
.bits_per_pixel
);
1018 fbcon_add_cursor_timer(info
);
1019 fbcon_has_exited
= 0;
1020 return display_desc
;
1023 static void fbcon_init(struct vc_data
*vc
, int init
)
1025 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1026 struct fbcon_ops
*ops
;
1027 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1028 struct vc_data
*svc
= *default_mode
;
1029 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1030 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1033 if (info_idx
== -1 || info
== NULL
)
1038 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1039 (info
->fix
.type
== FB_TYPE_TEXT
))
1042 if (var_to_display(p
, &info
->var
, info
))
1045 if (!info
->fbcon_par
)
1046 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1048 /* If we are not the first console on this
1049 fb, copy the font from that console */
1050 t
= &fb_display
[fg_console
];
1053 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1055 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1057 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1058 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1059 p
->userfont
= t
->userfont
;
1062 REFCOUNT(p
->fontdata
)++;
1064 const struct font_desc
*font
= NULL
;
1066 if (!fontname
[0] || !(font
= find_font(fontname
)))
1067 font
= get_default_font(info
->var
.xres
,
1069 info
->pixmap
.blit_x
,
1070 info
->pixmap
.blit_y
);
1071 vc
->vc_font
.width
= font
->width
;
1072 vc
->vc_font
.height
= font
->height
;
1073 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1074 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1075 support more fonts */
1080 charcnt
= FNTCHARCNT(p
->fontdata
);
1082 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1083 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1084 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1085 if (charcnt
== 256) {
1086 vc
->vc_hi_font_mask
= 0;
1088 vc
->vc_hi_font_mask
= 0x100;
1089 if (vc
->vc_can_do_color
)
1090 vc
->vc_complement_mask
<<= 1;
1093 if (!*svc
->vc_uni_pagedir_loc
)
1094 con_set_default_unimap(svc
);
1095 if (!*vc
->vc_uni_pagedir_loc
)
1096 con_copy_unimap(vc
, svc
);
1098 ops
= info
->fbcon_par
;
1099 p
->con_rotate
= initial_rotation
;
1100 set_blitting_type(vc
, info
);
1104 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1105 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1106 new_cols
/= vc
->vc_font
.width
;
1107 new_rows
/= vc
->vc_font
.height
;
1110 * We must always set the mode. The mode of the previous console
1111 * driver could be in the same resolution but we are using different
1112 * hardware so we have to initialize the hardware.
1114 * We need to do it in fbcon_init() to prevent screen corruption.
1116 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1117 if (info
->fbops
->fb_set_par
&&
1118 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1119 ret
= info
->fbops
->fb_set_par(info
);
1122 printk(KERN_ERR
"fbcon_init: detected "
1123 "unhandled fb_set_par error, "
1124 "error code %d\n", ret
);
1127 ops
->flags
|= FBCON_FLAGS_INIT
;
1132 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1133 !(cap
& FBINFO_HWACCEL_DISABLED
))
1134 p
->scrollmode
= SCROLL_MOVE
;
1135 else /* default to something safe */
1136 p
->scrollmode
= SCROLL_REDRAW
;
1139 * ++guenther: console.c:vc_allocate() relies on initializing
1140 * vc_{cols,rows}, but we must not set those if we are only
1141 * resizing the console.
1144 vc
->vc_cols
= new_cols
;
1145 vc
->vc_rows
= new_rows
;
1147 vc_resize(vc
, new_cols
, new_rows
);
1150 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1152 if (vc
== svc
&& softback_buf
)
1153 fbcon_update_softback(vc
);
1155 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1156 ops
->rotate
= FB_ROTATE_UR
;
1157 set_blitting_type(vc
, info
);
1160 ops
->p
= &fb_display
[fg_console
];
1163 static void fbcon_free_font(struct display
*p
)
1165 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1166 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1171 static void fbcon_deinit(struct vc_data
*vc
)
1173 struct display
*p
= &fb_display
[vc
->vc_num
];
1174 struct fb_info
*info
;
1175 struct fbcon_ops
*ops
;
1179 idx
= con2fb_map
[vc
->vc_num
];
1184 info
= registered_fb
[idx
];
1189 ops
= info
->fbcon_par
;
1194 if (CON_IS_VISIBLE(vc
))
1195 fbcon_del_cursor_timer(info
);
1197 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1200 if (!con_is_bound(&fb_con
))
1206 /* ====================================================================== */
1208 /* fbcon_XXX routines - interface used by the world
1210 * This system is now divided into two levels because of complications
1211 * caused by hardware scrolling. Top level functions:
1213 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1215 * handles y values in range [0, scr_height-1] that correspond to real
1216 * screen positions. y_wrap shift means that first line of bitmap may be
1217 * anywhere on this display. These functions convert lineoffsets to
1218 * bitmap offsets and deal with the wrap-around case by splitting blits.
1220 * fbcon_bmove_physical_8() -- These functions fast implementations
1221 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1222 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1226 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1227 * Implies should only really hardware scroll in rows. Only reason for
1228 * restriction is simplicity & efficiency at the moment.
1231 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1234 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1235 struct fbcon_ops
*ops
= info
->fbcon_par
;
1237 struct display
*p
= &fb_display
[vc
->vc_num
];
1240 if (fbcon_is_inactive(vc
, info
))
1243 if (!height
|| !width
)
1246 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
)
1249 /* Split blits that cross physical y_wrap boundary */
1251 y_break
= p
->vrows
- p
->yscroll
;
1252 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1253 u_int b
= y_break
- sy
;
1254 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1255 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1258 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1261 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1262 int count
, int ypos
, int xpos
)
1264 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1265 struct display
*p
= &fb_display
[vc
->vc_num
];
1266 struct fbcon_ops
*ops
= info
->fbcon_par
;
1268 if (!fbcon_is_inactive(vc
, info
))
1269 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1270 get_color(vc
, info
, scr_readw(s
), 1),
1271 get_color(vc
, info
, scr_readw(s
), 0));
1274 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1278 scr_writew(c
, &chr
);
1279 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1282 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1284 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1285 struct fbcon_ops
*ops
= info
->fbcon_par
;
1287 if (!fbcon_is_inactive(vc
, info
))
1288 ops
->clear_margins(vc
, info
, bottom_only
);
1291 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1293 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1294 struct fbcon_ops
*ops
= info
->fbcon_par
;
1296 int c
= scr_readw((u16
*) vc
->vc_pos
);
1298 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1301 if (vc
->vc_cursor_type
& 0x10)
1302 fbcon_del_cursor_timer(info
);
1304 fbcon_add_cursor_timer(info
);
1306 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1307 if (mode
& CM_SOFTBACK
) {
1308 mode
&= ~CM_SOFTBACK
;
1312 fbcon_set_origin(vc
);
1316 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1317 get_color(vc
, info
, c
, 0));
1318 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1321 static int scrollback_phys_max
= 0;
1322 static int scrollback_max
= 0;
1323 static int scrollback_current
= 0;
1325 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1328 struct display
*p
, *t
;
1329 struct vc_data
**default_mode
, *vc
;
1330 struct vc_data
*svc
;
1331 struct fbcon_ops
*ops
= info
->fbcon_par
;
1332 int rows
, cols
, charcnt
= 256;
1334 p
= &fb_display
[unit
];
1336 if (var_to_display(p
, var
, info
))
1339 vc
= vc_cons
[unit
].d
;
1344 default_mode
= vc
->vc_display_fg
;
1345 svc
= *default_mode
;
1346 t
= &fb_display
[svc
->vc_num
];
1348 if (!vc
->vc_font
.data
) {
1349 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1350 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1351 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1352 p
->userfont
= t
->userfont
;
1354 REFCOUNT(p
->fontdata
)++;
1357 charcnt
= FNTCHARCNT(p
->fontdata
);
1359 var
->activate
= FB_ACTIVATE_NOW
;
1360 info
->var
.activate
= var
->activate
;
1361 var
->yoffset
= info
->var
.yoffset
;
1362 var
->xoffset
= info
->var
.xoffset
;
1363 fb_set_var(info
, var
);
1364 ops
->var
= info
->var
;
1365 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1366 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1367 if (charcnt
== 256) {
1368 vc
->vc_hi_font_mask
= 0;
1370 vc
->vc_hi_font_mask
= 0x100;
1371 if (vc
->vc_can_do_color
)
1372 vc
->vc_complement_mask
<<= 1;
1375 if (!*svc
->vc_uni_pagedir_loc
)
1376 con_set_default_unimap(svc
);
1377 if (!*vc
->vc_uni_pagedir_loc
)
1378 con_copy_unimap(vc
, svc
);
1380 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1381 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1382 cols
/= vc
->vc_font
.width
;
1383 rows
/= vc
->vc_font
.height
;
1384 vc_resize(vc
, cols
, rows
);
1386 if (CON_IS_VISIBLE(vc
)) {
1389 fbcon_update_softback(vc
);
1393 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1395 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1396 struct fbcon_ops
*ops
= info
->fbcon_par
;
1397 struct display
*p
= &fb_display
[vc
->vc_num
];
1399 p
->yscroll
+= count
;
1400 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1401 p
->yscroll
-= p
->vrows
;
1402 ops
->var
.xoffset
= 0;
1403 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1404 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1405 ops
->update_start(info
);
1406 scrollback_max
+= count
;
1407 if (scrollback_max
> scrollback_phys_max
)
1408 scrollback_max
= scrollback_phys_max
;
1409 scrollback_current
= 0;
1412 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1414 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1415 struct fbcon_ops
*ops
= info
->fbcon_par
;
1416 struct display
*p
= &fb_display
[vc
->vc_num
];
1418 p
->yscroll
-= count
;
1419 if (p
->yscroll
< 0) /* Deal with wrap */
1420 p
->yscroll
+= p
->vrows
;
1421 ops
->var
.xoffset
= 0;
1422 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1423 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1424 ops
->update_start(info
);
1425 scrollback_max
-= count
;
1426 if (scrollback_max
< 0)
1428 scrollback_current
= 0;
1431 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1433 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1434 struct display
*p
= &fb_display
[vc
->vc_num
];
1435 struct fbcon_ops
*ops
= info
->fbcon_par
;
1437 p
->yscroll
+= count
;
1438 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1439 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1440 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1441 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1444 ops
->var
.xoffset
= 0;
1445 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1446 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1447 ops
->update_start(info
);
1448 fbcon_clear_margins(vc
, 1);
1449 scrollback_max
+= count
;
1450 if (scrollback_max
> scrollback_phys_max
)
1451 scrollback_max
= scrollback_phys_max
;
1452 scrollback_current
= 0;
1455 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1457 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1458 struct fbcon_ops
*ops
= info
->fbcon_par
;
1459 struct display
*p
= &fb_display
[vc
->vc_num
];
1461 p
->yscroll
+= count
;
1463 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1464 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1465 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1468 ops
->var
.xoffset
= 0;
1469 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1470 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1471 ops
->update_start(info
);
1472 fbcon_clear_margins(vc
, 1);
1473 scrollback_max
+= count
;
1474 if (scrollback_max
> scrollback_phys_max
)
1475 scrollback_max
= scrollback_phys_max
;
1476 scrollback_current
= 0;
1479 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1481 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1482 struct display
*p
= &fb_display
[vc
->vc_num
];
1483 struct fbcon_ops
*ops
= info
->fbcon_par
;
1485 p
->yscroll
-= count
;
1486 if (p
->yscroll
< 0) {
1487 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1488 0, vc
->vc_rows
, vc
->vc_cols
);
1489 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1492 ops
->var
.xoffset
= 0;
1493 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1494 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1495 ops
->update_start(info
);
1496 fbcon_clear_margins(vc
, 1);
1497 scrollback_max
-= count
;
1498 if (scrollback_max
< 0)
1500 scrollback_current
= 0;
1503 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1505 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1506 struct fbcon_ops
*ops
= info
->fbcon_par
;
1507 struct display
*p
= &fb_display
[vc
->vc_num
];
1509 p
->yscroll
-= count
;
1511 if (p
->yscroll
< 0) {
1512 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1513 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1516 ops
->var
.xoffset
= 0;
1517 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1518 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1519 ops
->update_start(info
);
1520 fbcon_clear_margins(vc
, 1);
1521 scrollback_max
-= count
;
1522 if (scrollback_max
< 0)
1524 scrollback_current
= 0;
1527 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1530 int count
= vc
->vc_rows
;
1531 unsigned short *d
, *s
;
1535 d
= (u16
*) softback_curr
;
1536 if (d
== (u16
*) softback_in
)
1537 d
= (u16
*) vc
->vc_origin
;
1538 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1539 softback_lines
-= delta
;
1541 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1542 n
+= softback_end
- softback_buf
;
1543 if (n
< softback_top
) {
1545 (softback_top
- n
) / vc
->vc_size_row
;
1548 } else if (softback_curr
>= softback_top
1549 && n
< softback_top
) {
1551 (softback_top
- n
) / vc
->vc_size_row
;
1555 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1556 n
+= softback_buf
- softback_end
;
1557 if (n
> softback_in
) {
1561 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1566 if (n
== softback_curr
)
1569 s
= (u16
*) softback_curr
;
1570 if (s
== (u16
*) softback_in
)
1571 s
= (u16
*) vc
->vc_origin
;
1573 unsigned short *start
;
1577 unsigned short attr
= 1;
1580 le
= advance_row(s
, 1);
1583 if (attr
!= (c
& 0xff00)) {
1586 fbcon_putcs(vc
, start
, s
- start
,
1592 if (c
== scr_readw(d
)) {
1594 fbcon_putcs(vc
, start
, s
- start
,
1607 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1609 if (d
== (u16
*) softback_end
)
1610 d
= (u16
*) softback_buf
;
1611 if (d
== (u16
*) softback_in
)
1612 d
= (u16
*) vc
->vc_origin
;
1613 if (s
== (u16
*) softback_end
)
1614 s
= (u16
*) softback_buf
;
1615 if (s
== (u16
*) softback_in
)
1616 s
= (u16
*) vc
->vc_origin
;
1620 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1621 int line
, int count
, int dy
)
1623 unsigned short *s
= (unsigned short *)
1624 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1627 unsigned short *start
= s
;
1628 unsigned short *le
= advance_row(s
, 1);
1631 unsigned short attr
= 1;
1635 if (attr
!= (c
& 0xff00)) {
1638 fbcon_putcs(vc
, start
, s
- start
,
1644 console_conditional_schedule();
1648 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1649 console_conditional_schedule();
1654 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1655 struct display
*p
, int line
, int count
, int ycount
)
1657 int offset
= ycount
* vc
->vc_cols
;
1658 unsigned short *d
= (unsigned short *)
1659 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1660 unsigned short *s
= d
+ offset
;
1661 struct fbcon_ops
*ops
= info
->fbcon_par
;
1664 unsigned short *start
= s
;
1665 unsigned short *le
= advance_row(s
, 1);
1672 if (c
== scr_readw(d
)) {
1674 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1675 line
, x
, 1, s
-start
);
1685 console_conditional_schedule();
1690 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1692 console_conditional_schedule();
1697 /* NOTE: We subtract two lines from these pointers */
1698 s
-= vc
->vc_size_row
;
1699 d
-= vc
->vc_size_row
;
1704 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1705 int line
, int count
, int offset
)
1707 unsigned short *d
= (unsigned short *)
1708 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1709 unsigned short *s
= d
+ offset
;
1712 unsigned short *start
= s
;
1713 unsigned short *le
= advance_row(s
, 1);
1716 unsigned short attr
= 1;
1720 if (attr
!= (c
& 0xff00)) {
1723 fbcon_putcs(vc
, start
, s
- start
,
1729 if (c
== scr_readw(d
)) {
1731 fbcon_putcs(vc
, start
, s
- start
,
1741 console_conditional_schedule();
1746 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1747 console_conditional_schedule();
1752 /* NOTE: We subtract two lines from these pointers */
1753 s
-= vc
->vc_size_row
;
1754 d
-= vc
->vc_size_row
;
1759 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1764 if (vc
->vc_num
!= fg_console
)
1766 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1769 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1771 p
= advance_row(p
, 1);
1772 softback_in
+= vc
->vc_size_row
;
1773 if (softback_in
== softback_end
)
1774 softback_in
= softback_buf
;
1775 if (softback_in
== softback_top
) {
1776 softback_top
+= vc
->vc_size_row
;
1777 if (softback_top
== softback_end
)
1778 softback_top
= softback_buf
;
1781 softback_curr
= softback_in
;
1784 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1787 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1788 struct display
*p
= &fb_display
[vc
->vc_num
];
1789 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1791 if (fbcon_is_inactive(vc
, info
))
1794 fbcon_cursor(vc
, CM_ERASE
);
1797 * ++Geert: Only use ywrap/ypan if the console is in text mode
1798 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1799 * whole screen (prevents flicker).
1804 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1805 count
= vc
->vc_rows
;
1807 fbcon_softback_note(vc
, t
, count
);
1808 if (logo_shown
>= 0)
1810 switch (p
->scrollmode
) {
1812 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1814 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1815 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1818 vc
->vc_video_erase_char
,
1819 vc
->vc_size_row
* count
);
1823 case SCROLL_WRAP_MOVE
:
1824 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1826 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1828 ywrap_up(vc
, count
);
1829 if (vc
->vc_rows
- b
> 0)
1830 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1833 } else if (info
->flags
& FBINFO_READS_FAST
)
1834 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1835 b
- t
- count
, vc
->vc_cols
);
1838 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1841 case SCROLL_PAN_REDRAW
:
1842 if ((p
->yscroll
+ count
<=
1843 2 * (p
->vrows
- vc
->vc_rows
))
1844 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1847 3 * vc
->vc_rows
>> 2)))) {
1849 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1850 ypan_up_redraw(vc
, t
, count
);
1851 if (vc
->vc_rows
- b
> 0)
1852 fbcon_redraw_move(vc
, p
, b
,
1853 vc
->vc_rows
- b
, b
);
1855 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1856 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1859 case SCROLL_PAN_MOVE
:
1860 if ((p
->yscroll
+ count
<=
1861 2 * (p
->vrows
- vc
->vc_rows
))
1862 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1865 3 * vc
->vc_rows
>> 2)))) {
1867 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1870 if (vc
->vc_rows
- b
> 0)
1871 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1874 } else if (info
->flags
& FBINFO_READS_FAST
)
1875 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1876 b
- t
- count
, vc
->vc_cols
);
1879 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1884 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1885 count
* vc
->vc_cols
);
1886 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1887 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1890 vc
->vc_video_erase_char
,
1891 vc
->vc_size_row
* count
);
1897 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1898 count
= vc
->vc_rows
;
1899 if (logo_shown
>= 0)
1901 switch (p
->scrollmode
) {
1903 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1905 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1906 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1909 vc
->vc_video_erase_char
,
1910 vc
->vc_size_row
* count
);
1914 case SCROLL_WRAP_MOVE
:
1915 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1916 if (vc
->vc_rows
- b
> 0)
1917 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1920 ywrap_down(vc
, count
);
1922 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1924 } else if (info
->flags
& FBINFO_READS_FAST
)
1925 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1926 b
- t
- count
, vc
->vc_cols
);
1929 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1932 case SCROLL_PAN_MOVE
:
1933 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1934 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1937 3 * vc
->vc_rows
>> 2)))) {
1938 if (vc
->vc_rows
- b
> 0)
1939 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1942 ypan_down(vc
, count
);
1944 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1946 } else if (info
->flags
& FBINFO_READS_FAST
)
1947 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1948 b
- t
- count
, vc
->vc_cols
);
1951 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1954 case SCROLL_PAN_REDRAW
:
1955 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1956 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1959 3 * vc
->vc_rows
>> 2)))) {
1960 if (vc
->vc_rows
- b
> 0)
1961 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1963 ypan_down_redraw(vc
, t
, count
);
1965 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1967 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1968 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1973 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1974 -count
* vc
->vc_cols
);
1975 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1976 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1979 vc
->vc_video_erase_char
,
1980 vc
->vc_size_row
* count
);
1988 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1989 int height
, int width
)
1991 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1992 struct display
*p
= &fb_display
[vc
->vc_num
];
1994 if (fbcon_is_inactive(vc
, info
))
1997 if (!width
|| !height
)
2000 /* Split blits that cross physical y_wrap case.
2001 * Pathological case involves 4 blits, better to use recursive
2002 * code rather than unrolled case
2004 * Recursive invocations don't need to erase the cursor over and
2005 * over again, so we use fbcon_bmove_rec()
2007 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2008 p
->vrows
- p
->yscroll
);
2011 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2012 int dy
, int dx
, int height
, int width
, u_int y_break
)
2014 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2015 struct fbcon_ops
*ops
= info
->fbcon_par
;
2018 if (sy
< y_break
&& sy
+ height
> y_break
) {
2020 if (dy
< sy
) { /* Avoid trashing self */
2021 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2023 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2024 height
- b
, width
, y_break
);
2026 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2027 height
- b
, width
, y_break
);
2028 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2034 if (dy
< y_break
&& dy
+ height
> y_break
) {
2036 if (dy
< sy
) { /* Avoid trashing self */
2037 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2039 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2040 height
- b
, width
, y_break
);
2042 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2043 height
- b
, width
, y_break
);
2044 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2049 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2053 static void updatescrollmode(struct display
*p
,
2054 struct fb_info
*info
,
2057 struct fbcon_ops
*ops
= info
->fbcon_par
;
2058 int fh
= vc
->vc_font
.height
;
2059 int cap
= info
->flags
;
2061 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2062 info
->fix
.xpanstep
);
2063 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2064 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2065 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2066 info
->var
.xres_virtual
);
2067 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2068 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2069 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2070 divides(ywrap
, vc
->vc_font
.height
) &&
2071 divides(vc
->vc_font
.height
, vyres
) &&
2072 divides(vc
->vc_font
.height
, yres
);
2073 int reading_fast
= cap
& FBINFO_READS_FAST
;
2074 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2075 !(cap
& FBINFO_HWACCEL_DISABLED
);
2076 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2077 !(cap
& FBINFO_HWACCEL_DISABLED
);
2079 p
->vrows
= vyres
/fh
;
2080 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2081 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2082 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2085 if (good_wrap
|| good_pan
) {
2086 if (reading_fast
|| fast_copyarea
)
2087 p
->scrollmode
= good_wrap
?
2088 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2090 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2093 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2094 p
->scrollmode
= SCROLL_MOVE
;
2096 p
->scrollmode
= SCROLL_REDRAW
;
2100 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2101 unsigned int height
, unsigned int user
)
2103 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2104 struct fbcon_ops
*ops
= info
->fbcon_par
;
2105 struct display
*p
= &fb_display
[vc
->vc_num
];
2106 struct fb_var_screeninfo var
= info
->var
;
2107 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2109 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2110 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2111 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2112 vc
->vc_font
.height
);
2113 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2115 var
.xres
= virt_w
* virt_fw
;
2116 var
.yres
= virt_h
* virt_fh
;
2117 x_diff
= info
->var
.xres
- var
.xres
;
2118 y_diff
= info
->var
.yres
- var
.yres
;
2119 if (x_diff
< 0 || x_diff
> virt_fw
||
2120 y_diff
< 0 || y_diff
> virt_fh
) {
2121 const struct fb_videomode
*mode
;
2123 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2124 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2127 display_to_var(&var
, p
);
2128 fb_videomode_to_var(&var
, mode
);
2130 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2133 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2134 if (CON_IS_VISIBLE(vc
)) {
2135 var
.activate
= FB_ACTIVATE_NOW
|
2137 fb_set_var(info
, &var
);
2139 var_to_display(p
, &info
->var
, info
);
2140 ops
->var
= info
->var
;
2142 updatescrollmode(p
, info
, vc
);
2146 static int fbcon_switch(struct vc_data
*vc
)
2148 struct fb_info
*info
, *old_info
= NULL
;
2149 struct fbcon_ops
*ops
;
2150 struct display
*p
= &fb_display
[vc
->vc_num
];
2151 struct fb_var_screeninfo var
;
2152 int i
, ret
, prev_console
, charcnt
= 256;
2154 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2155 ops
= info
->fbcon_par
;
2159 fbcon_set_origin(vc
);
2160 softback_top
= softback_curr
= softback_in
= softback_buf
;
2162 fbcon_update_softback(vc
);
2165 if (logo_shown
>= 0) {
2166 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2168 if (conp2
->vc_top
== logo_lines
2169 && conp2
->vc_bottom
== conp2
->vc_rows
)
2171 logo_shown
= FBCON_LOGO_CANSHOW
;
2174 prev_console
= ops
->currcon
;
2175 if (prev_console
!= -1)
2176 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2178 * FIXME: If we have multiple fbdev's loaded, we need to
2179 * update all info->currcon. Perhaps, we can place this
2180 * in a centralized structure, but this might break some
2183 * info->currcon = vc->vc_num;
2185 for (i
= 0; i
< FB_MAX
; i
++) {
2186 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2187 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2189 o
->currcon
= vc
->vc_num
;
2192 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2193 display_to_var(&var
, p
);
2194 var
.activate
= FB_ACTIVATE_NOW
;
2197 * make sure we don't unnecessarily trip the memcmp()
2200 info
->var
.activate
= var
.activate
;
2201 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2202 fb_set_var(info
, &var
);
2203 ops
->var
= info
->var
;
2205 if (old_info
!= NULL
&& (old_info
!= info
||
2206 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2207 if (info
->fbops
->fb_set_par
) {
2208 ret
= info
->fbops
->fb_set_par(info
);
2211 printk(KERN_ERR
"fbcon_switch: detected "
2212 "unhandled fb_set_par error, "
2213 "error code %d\n", ret
);
2216 if (old_info
!= info
)
2217 fbcon_del_cursor_timer(old_info
);
2220 if (fbcon_is_inactive(vc
, info
) ||
2221 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2222 fbcon_del_cursor_timer(info
);
2224 fbcon_add_cursor_timer(info
);
2226 set_blitting_type(vc
, info
);
2227 ops
->cursor_reset
= 1;
2229 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2230 ops
->rotate
= FB_ROTATE_UR
;
2231 set_blitting_type(vc
, info
);
2234 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2235 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2238 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2241 vc
->vc_complement_mask
<<= 1;
2243 updatescrollmode(p
, info
, vc
);
2245 switch (p
->scrollmode
) {
2246 case SCROLL_WRAP_MOVE
:
2247 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2249 case SCROLL_PAN_MOVE
:
2250 case SCROLL_PAN_REDRAW
:
2251 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2252 if (scrollback_phys_max
< 0)
2253 scrollback_phys_max
= 0;
2256 scrollback_phys_max
= 0;
2261 scrollback_current
= 0;
2263 if (!fbcon_is_inactive(vc
, info
)) {
2264 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2265 ops
->update_start(info
);
2268 fbcon_set_palette(vc
, color_table
);
2269 fbcon_clear_margins(vc
, 0);
2271 if (logo_shown
== FBCON_LOGO_DRAW
) {
2273 logo_shown
= fg_console
;
2274 /* This is protected above by initmem_freed */
2275 fb_show_logo(info
, ops
->rotate
);
2277 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2278 vc
->vc_size_row
* (vc
->vc_bottom
-
2285 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2288 struct fb_event event
;
2291 unsigned short charmask
= vc
->vc_hi_font_mask
?
2293 unsigned short oldc
;
2295 oldc
= vc
->vc_video_erase_char
;
2296 vc
->vc_video_erase_char
&= charmask
;
2297 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2298 vc
->vc_video_erase_char
= oldc
;
2302 if (!lock_fb_info(info
))
2305 event
.data
= &blank
;
2306 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2307 unlock_fb_info(info
);
2310 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2312 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2313 struct fbcon_ops
*ops
= info
->fbcon_par
;
2316 struct fb_var_screeninfo var
= info
->var
;
2321 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2322 fb_set_var(info
, &var
);
2324 ops
->var
= info
->var
;
2328 if (!fbcon_is_inactive(vc
, info
)) {
2329 if (ops
->blank_state
!= blank
) {
2330 ops
->blank_state
= blank
;
2331 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2332 ops
->cursor_flash
= (!blank
);
2334 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2335 if (fb_blank(info
, blank
))
2336 fbcon_generic_blank(vc
, info
, blank
);
2343 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2344 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2345 fbcon_del_cursor_timer(info
);
2347 fbcon_add_cursor_timer(info
);
2352 static int fbcon_debug_enter(struct vc_data
*vc
)
2354 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2355 struct fbcon_ops
*ops
= info
->fbcon_par
;
2357 ops
->save_graphics
= ops
->graphics
;
2359 if (info
->fbops
->fb_debug_enter
)
2360 info
->fbops
->fb_debug_enter(info
);
2361 fbcon_set_palette(vc
, color_table
);
2365 static int fbcon_debug_leave(struct vc_data
*vc
)
2367 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2368 struct fbcon_ops
*ops
= info
->fbcon_par
;
2370 ops
->graphics
= ops
->save_graphics
;
2371 if (info
->fbops
->fb_debug_leave
)
2372 info
->fbops
->fb_debug_leave(info
);
2376 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2378 u8
*fontdata
= vc
->vc_font
.data
;
2379 u8
*data
= font
->data
;
2382 font
->width
= vc
->vc_font
.width
;
2383 font
->height
= vc
->vc_font
.height
;
2384 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2388 if (font
->width
<= 8) {
2389 j
= vc
->vc_font
.height
;
2390 for (i
= 0; i
< font
->charcount
; i
++) {
2391 memcpy(data
, fontdata
, j
);
2392 memset(data
+ j
, 0, 32 - j
);
2396 } else if (font
->width
<= 16) {
2397 j
= vc
->vc_font
.height
* 2;
2398 for (i
= 0; i
< font
->charcount
; i
++) {
2399 memcpy(data
, fontdata
, j
);
2400 memset(data
+ j
, 0, 64 - j
);
2404 } else if (font
->width
<= 24) {
2405 for (i
= 0; i
< font
->charcount
; i
++) {
2406 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2407 *data
++ = fontdata
[0];
2408 *data
++ = fontdata
[1];
2409 *data
++ = fontdata
[2];
2410 fontdata
+= sizeof(u32
);
2412 memset(data
, 0, 3 * (32 - j
));
2413 data
+= 3 * (32 - j
);
2416 j
= vc
->vc_font
.height
* 4;
2417 for (i
= 0; i
< font
->charcount
; i
++) {
2418 memcpy(data
, fontdata
, j
);
2419 memset(data
+ j
, 0, 128 - j
);
2427 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2428 const u8
* data
, int userfont
)
2430 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2431 struct fbcon_ops
*ops
= info
->fbcon_par
;
2432 struct display
*p
= &fb_display
[vc
->vc_num
];
2435 char *old_data
= NULL
;
2437 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2438 fbcon_set_origin(vc
);
2440 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2442 old_data
= vc
->vc_font
.data
;
2444 cnt
= FNTCHARCNT(data
);
2447 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2448 if ((p
->userfont
= userfont
))
2450 vc
->vc_font
.width
= w
;
2451 vc
->vc_font
.height
= h
;
2452 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2453 vc
->vc_hi_font_mask
= 0;
2454 if (vc
->vc_can_do_color
) {
2455 vc
->vc_complement_mask
>>= 1;
2456 vc
->vc_s_complement_mask
>>= 1;
2459 /* ++Edmund: reorder the attribute bits */
2460 if (vc
->vc_can_do_color
) {
2461 unsigned short *cp
=
2462 (unsigned short *) vc
->vc_origin
;
2463 int count
= vc
->vc_screenbuf_size
/ 2;
2465 for (; count
> 0; count
--, cp
++) {
2467 scr_writew(((c
& 0xfe00) >> 1) |
2470 c
= vc
->vc_video_erase_char
;
2471 vc
->vc_video_erase_char
=
2472 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2475 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2476 vc
->vc_hi_font_mask
= 0x100;
2477 if (vc
->vc_can_do_color
) {
2478 vc
->vc_complement_mask
<<= 1;
2479 vc
->vc_s_complement_mask
<<= 1;
2482 /* ++Edmund: reorder the attribute bits */
2484 unsigned short *cp
=
2485 (unsigned short *) vc
->vc_origin
;
2486 int count
= vc
->vc_screenbuf_size
/ 2;
2488 for (; count
> 0; count
--, cp
++) {
2489 unsigned short newc
;
2491 if (vc
->vc_can_do_color
)
2493 ((c
& 0xff00) << 1) | (c
&
2497 scr_writew(newc
, cp
);
2499 c
= vc
->vc_video_erase_char
;
2500 if (vc
->vc_can_do_color
) {
2501 vc
->vc_video_erase_char
=
2502 ((c
& 0xff00) << 1) | (c
& 0xff);
2505 vc
->vc_video_erase_char
= c
& ~0x100;
2513 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2514 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2517 vc_resize(vc
, cols
, rows
);
2518 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2519 fbcon_update_softback(vc
);
2520 } else if (CON_IS_VISIBLE(vc
)
2521 && vc
->vc_mode
== KD_TEXT
) {
2522 fbcon_clear_margins(vc
, 0);
2526 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2527 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2531 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2533 struct display
*od
= &fb_display
[con
];
2534 struct console_font
*f
= &vc
->vc_font
;
2536 if (od
->fontdata
== f
->data
)
2537 return 0; /* already the same font... */
2538 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2542 * User asked to set font; we are guaranteed that
2543 * a) width and height are in range 1..32
2544 * b) charcount does not exceed 512
2545 * but lets not assume that, since someone might someday want to use larger
2546 * fonts. And charcount of 512 is small for unicode support.
2548 * However, user space gives the font in 32 rows , regardless of
2549 * actual font height. So a new API is needed if support for larger fonts
2550 * is ever implemented.
2553 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2555 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2556 unsigned charcount
= font
->charcount
;
2557 int w
= font
->width
;
2558 int h
= font
->height
;
2561 u8
*new_data
, *data
= font
->data
;
2562 int pitch
= (font
->width
+7) >> 3;
2564 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2565 * If not this check should be changed to charcount < 256 */
2566 if (charcount
!= 256 && charcount
!= 512)
2569 /* Make sure drawing engine can handle the font */
2570 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2571 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2574 /* Make sure driver can handle the font length */
2575 if (fbcon_invalid_charcount(info
, charcount
))
2578 size
= h
* pitch
* charcount
;
2580 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2585 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2586 FNTSIZE(new_data
) = size
;
2587 FNTCHARCNT(new_data
) = charcount
;
2588 REFCOUNT(new_data
) = 0; /* usage counter */
2589 for (i
=0; i
< charcount
; i
++) {
2590 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2593 /* Since linux has a nice crc32 function use it for counting font
2595 csum
= crc32(0, new_data
, size
);
2597 FNTSUM(new_data
) = csum
;
2598 /* Check if the same font is on some other console already */
2599 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2600 struct vc_data
*tmp
= vc_cons
[i
].d
;
2602 if (fb_display
[i
].userfont
&&
2603 fb_display
[i
].fontdata
&&
2604 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2605 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2606 tmp
->vc_font
.width
== w
&&
2607 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2608 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2609 new_data
= (u8
*)fb_display
[i
].fontdata
;
2613 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2616 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2618 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2619 const struct font_desc
*f
;
2622 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2623 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2624 else if (!(f
= find_font(name
)))
2627 font
->width
= f
->width
;
2628 font
->height
= f
->height
;
2629 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2632 static u16 palette_red
[16];
2633 static u16 palette_green
[16];
2634 static u16 palette_blue
[16];
2636 static struct fb_cmap palette_cmap
= {
2637 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2640 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2642 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2646 if (fbcon_is_inactive(vc
, info
))
2649 if (!CON_IS_VISIBLE(vc
))
2652 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2654 for (i
= j
= 0; i
< 16; i
++) {
2656 val
= vc
->vc_palette
[j
++];
2657 palette_red
[k
] = (val
<< 8) | val
;
2658 val
= vc
->vc_palette
[j
++];
2659 palette_green
[k
] = (val
<< 8) | val
;
2660 val
= vc
->vc_palette
[j
++];
2661 palette_blue
[k
] = (val
<< 8) | val
;
2663 palette_cmap
.len
= 16;
2664 palette_cmap
.start
= 0;
2666 * If framebuffer is capable of less than 16 colors,
2667 * use default palette of fbcon.
2670 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2672 return fb_set_cmap(&palette_cmap
, info
);
2675 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2680 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2681 return (u16
*) (vc
->vc_origin
+ offset
);
2682 line
= offset
/ vc
->vc_size_row
;
2683 if (line
>= softback_lines
)
2684 return (u16
*) (vc
->vc_origin
+ offset
-
2685 softback_lines
* vc
->vc_size_row
);
2686 p
= softback_curr
+ offset
;
2687 if (p
>= softback_end
)
2688 p
+= softback_buf
- softback_end
;
2692 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2698 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2699 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2701 x
= offset
% vc
->vc_cols
;
2702 y
= offset
/ vc
->vc_cols
;
2703 if (vc
->vc_num
== fg_console
)
2704 y
+= softback_lines
;
2705 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2706 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2707 unsigned long offset
= pos
- softback_curr
;
2709 if (pos
< softback_curr
)
2710 offset
+= softback_end
- softback_buf
;
2712 x
= offset
% vc
->vc_cols
;
2713 y
= offset
/ vc
->vc_cols
;
2714 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2715 if (ret
== softback_end
)
2717 if (ret
== softback_in
)
2718 ret
= vc
->vc_origin
;
2720 /* Should not happen */
2722 ret
= vc
->vc_origin
;
2731 /* As we might be inside of softback, we may work with non-contiguous buffer,
2732 that's why we have to use a separate routine. */
2733 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2736 u16 a
= scr_readw(p
);
2737 if (!vc
->vc_can_do_color
)
2739 else if (vc
->vc_hi_font_mask
== 0x100)
2740 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2741 (((a
) & 0x0e00) << 4);
2743 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2744 (((a
) & 0x0700) << 4);
2746 if (p
== (u16
*) softback_end
)
2747 p
= (u16
*) softback_buf
;
2748 if (p
== (u16
*) softback_in
)
2749 p
= (u16
*) vc
->vc_origin
;
2753 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2755 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2756 struct fbcon_ops
*ops
= info
->fbcon_par
;
2757 struct display
*disp
= &fb_display
[fg_console
];
2758 int offset
, limit
, scrollback_old
;
2761 if (vc
->vc_num
!= fg_console
)
2763 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2765 if (logo_shown
>= 0) {
2766 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2768 if (conp2
->vc_top
== logo_lines
2769 && conp2
->vc_bottom
== conp2
->vc_rows
)
2771 if (logo_shown
== vc
->vc_num
) {
2777 logo_lines
* vc
->vc_size_row
;
2778 for (i
= 0; i
< logo_lines
; i
++) {
2779 if (p
== softback_top
)
2781 if (p
== softback_buf
)
2783 p
-= vc
->vc_size_row
;
2784 q
-= vc
->vc_size_row
;
2785 scr_memcpyw((u16
*) q
, (u16
*) p
,
2788 softback_in
= softback_curr
= p
;
2789 update_region(vc
, vc
->vc_origin
,
2790 logo_lines
* vc
->vc_cols
);
2792 logo_shown
= FBCON_LOGO_CANSHOW
;
2794 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2795 fbcon_redraw_softback(vc
, disp
, lines
);
2796 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2800 if (!scrollback_phys_max
)
2803 scrollback_old
= scrollback_current
;
2804 scrollback_current
-= lines
;
2805 if (scrollback_current
< 0)
2806 scrollback_current
= 0;
2807 else if (scrollback_current
> scrollback_max
)
2808 scrollback_current
= scrollback_max
;
2809 if (scrollback_current
== scrollback_old
)
2812 if (fbcon_is_inactive(vc
, info
))
2815 fbcon_cursor(vc
, CM_ERASE
);
2817 offset
= disp
->yscroll
- scrollback_current
;
2818 limit
= disp
->vrows
;
2819 switch (disp
->scrollmode
) {
2820 case SCROLL_WRAP_MOVE
:
2821 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2823 case SCROLL_PAN_MOVE
:
2824 case SCROLL_PAN_REDRAW
:
2825 limit
-= vc
->vc_rows
;
2826 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2831 else if (offset
>= limit
)
2834 ops
->var
.xoffset
= 0;
2835 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2836 ops
->update_start(info
);
2838 if (!scrollback_current
)
2839 fbcon_cursor(vc
, CM_DRAW
);
2843 static int fbcon_set_origin(struct vc_data
*vc
)
2846 fbcon_scrolldelta(vc
, softback_lines
);
2850 static void fbcon_suspended(struct fb_info
*info
)
2852 struct vc_data
*vc
= NULL
;
2853 struct fbcon_ops
*ops
= info
->fbcon_par
;
2855 if (!ops
|| ops
->currcon
< 0)
2857 vc
= vc_cons
[ops
->currcon
].d
;
2859 /* Clear cursor, restore saved data */
2860 fbcon_cursor(vc
, CM_ERASE
);
2863 static void fbcon_resumed(struct fb_info
*info
)
2866 struct fbcon_ops
*ops
= info
->fbcon_par
;
2868 if (!ops
|| ops
->currcon
< 0)
2870 vc
= vc_cons
[ops
->currcon
].d
;
2875 static void fbcon_modechanged(struct fb_info
*info
)
2877 struct fbcon_ops
*ops
= info
->fbcon_par
;
2882 if (!ops
|| ops
->currcon
< 0)
2884 vc
= vc_cons
[ops
->currcon
].d
;
2885 if (vc
->vc_mode
!= KD_TEXT
||
2886 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2889 p
= &fb_display
[vc
->vc_num
];
2890 set_blitting_type(vc
, info
);
2892 if (CON_IS_VISIBLE(vc
)) {
2893 var_to_display(p
, &info
->var
, info
);
2894 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2895 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2896 cols
/= vc
->vc_font
.width
;
2897 rows
/= vc
->vc_font
.height
;
2898 vc_resize(vc
, cols
, rows
);
2899 updatescrollmode(p
, info
, vc
);
2901 scrollback_current
= 0;
2903 if (!fbcon_is_inactive(vc
, info
)) {
2904 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2905 ops
->update_start(info
);
2908 fbcon_set_palette(vc
, color_table
);
2911 fbcon_update_softback(vc
);
2915 static void fbcon_set_all_vcs(struct fb_info
*info
)
2917 struct fbcon_ops
*ops
= info
->fbcon_par
;
2920 int i
, rows
, cols
, fg
= -1;
2922 if (!ops
|| ops
->currcon
< 0)
2925 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2927 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2928 registered_fb
[con2fb_map
[i
]] != info
)
2931 if (CON_IS_VISIBLE(vc
)) {
2936 p
= &fb_display
[vc
->vc_num
];
2937 set_blitting_type(vc
, info
);
2938 var_to_display(p
, &info
->var
, info
);
2939 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2940 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2941 cols
/= vc
->vc_font
.width
;
2942 rows
/= vc
->vc_font
.height
;
2943 vc_resize(vc
, cols
, rows
);
2947 fbcon_modechanged(info
);
2950 static int fbcon_mode_deleted(struct fb_info
*info
,
2951 struct fb_videomode
*mode
)
2953 struct fb_info
*fb_info
;
2955 int i
, j
, found
= 0;
2957 /* before deletion, ensure that mode is not in use */
2958 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2962 fb_info
= registered_fb
[j
];
2963 if (fb_info
!= info
)
2968 if (fb_mode_is_equal(p
->mode
, mode
)) {
2976 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2977 static int fbcon_unbind(void)
2981 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2985 fbcon_has_console_bind
= 0;
2990 static inline int fbcon_unbind(void)
2994 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2996 static int fbcon_fb_unbind(int idx
)
2998 int i
, new_idx
= -1, ret
= 0;
3000 if (!fbcon_has_console_bind
)
3003 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3004 if (con2fb_map
[i
] != idx
&&
3005 con2fb_map
[i
] != -1) {
3011 if (new_idx
!= -1) {
3012 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3013 if (con2fb_map
[i
] == idx
)
3014 set_con2fb_map(i
, new_idx
, 0);
3017 ret
= fbcon_unbind();
3022 static int fbcon_fb_unregistered(struct fb_info
*info
)
3027 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3028 if (con2fb_map
[i
] == idx
)
3032 if (idx
== info_idx
) {
3035 for (i
= 0; i
< FB_MAX
; i
++) {
3036 if (registered_fb
[i
] != NULL
) {
3043 if (info_idx
!= -1) {
3044 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3045 if (con2fb_map
[i
] == -1)
3046 con2fb_map
[i
] = info_idx
;
3050 if (primary_device
== idx
)
3051 primary_device
= -1;
3053 if (!num_registered_fb
)
3054 unregister_con_driver(&fb_con
);
3059 static void fbcon_remap_all(int idx
)
3062 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3063 set_con2fb_map(i
, idx
, 0);
3065 if (con_is_bound(&fb_con
)) {
3066 printk(KERN_INFO
"fbcon: Remapping primary device, "
3067 "fb%i, to tty %i-%i\n", idx
,
3068 first_fb_vc
+ 1, last_fb_vc
+ 1);
3073 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3074 static void fbcon_select_primary(struct fb_info
*info
)
3076 if (!map_override
&& primary_device
== -1 &&
3077 fb_is_primary_device(info
)) {
3080 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3081 info
->fix
.id
, info
->node
);
3082 primary_device
= info
->node
;
3084 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3085 con2fb_map_boot
[i
] = primary_device
;
3087 if (con_is_bound(&fb_con
)) {
3088 printk(KERN_INFO
"fbcon: Remapping primary device, "
3089 "fb%i, to tty %i-%i\n", info
->node
,
3090 first_fb_vc
+ 1, last_fb_vc
+ 1);
3091 info_idx
= primary_device
;
3097 static inline void fbcon_select_primary(struct fb_info
*info
)
3101 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3103 static int fbcon_fb_registered(struct fb_info
*info
)
3105 int ret
= 0, i
, idx
;
3108 fbcon_select_primary(info
);
3110 if (info_idx
== -1) {
3111 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3112 if (con2fb_map_boot
[i
] == idx
) {
3119 ret
= fbcon_takeover(1);
3121 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3122 if (con2fb_map_boot
[i
] == idx
)
3123 set_con2fb_map(i
, idx
, 0);
3130 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3132 struct fbcon_ops
*ops
= info
->fbcon_par
;
3135 if (!ops
|| ops
->currcon
< 0)
3138 vc
= vc_cons
[ops
->currcon
].d
;
3139 if (vc
->vc_mode
!= KD_TEXT
||
3140 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3143 if (CON_IS_VISIBLE(vc
)) {
3147 do_unblank_screen(0);
3149 ops
->blank_state
= blank
;
3152 static void fbcon_new_modelist(struct fb_info
*info
)
3156 struct fb_var_screeninfo var
;
3157 const struct fb_videomode
*mode
;
3159 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3160 if (registered_fb
[con2fb_map
[i
]] != info
)
3162 if (!fb_display
[i
].mode
)
3165 display_to_var(&var
, &fb_display
[i
]);
3166 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3168 fb_videomode_to_var(&var
, mode
);
3169 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3173 static void fbcon_get_requirement(struct fb_info
*info
,
3174 struct fb_blit_caps
*caps
)
3182 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3184 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3185 info
->node
== con2fb_map
[i
]) {
3187 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3188 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3189 charcnt
= (p
->userfont
) ?
3190 FNTCHARCNT(p
->fontdata
) : 256;
3191 if (caps
->len
< charcnt
)
3192 caps
->len
= charcnt
;
3196 vc
= vc_cons
[fg_console
].d
;
3198 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3199 info
->node
== con2fb_map
[fg_console
]) {
3200 p
= &fb_display
[fg_console
];
3201 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3202 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3203 caps
->len
= (p
->userfont
) ?
3204 FNTCHARCNT(p
->fontdata
) : 256;
3209 static int fbcon_event_notify(struct notifier_block
*self
,
3210 unsigned long action
, void *data
)
3212 struct fb_event
*event
= data
;
3213 struct fb_info
*info
= event
->info
;
3214 struct fb_videomode
*mode
;
3215 struct fb_con2fbmap
*con2fb
;
3216 struct fb_blit_caps
*caps
;
3220 * ignore all events except driver registration and deregistration
3221 * if fbcon is not active
3223 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3224 action
== FB_EVENT_FB_UNREGISTERED
))
3228 case FB_EVENT_SUSPEND
:
3229 fbcon_suspended(info
);
3231 case FB_EVENT_RESUME
:
3232 fbcon_resumed(info
);
3234 case FB_EVENT_MODE_CHANGE
:
3235 fbcon_modechanged(info
);
3237 case FB_EVENT_MODE_CHANGE_ALL
:
3238 fbcon_set_all_vcs(info
);
3240 case FB_EVENT_MODE_DELETE
:
3242 ret
= fbcon_mode_deleted(info
, mode
);
3244 case FB_EVENT_FB_UNBIND
:
3246 ret
= fbcon_fb_unbind(idx
);
3248 case FB_EVENT_FB_REGISTERED
:
3249 ret
= fbcon_fb_registered(info
);
3251 case FB_EVENT_FB_UNREGISTERED
:
3252 ret
= fbcon_fb_unregistered(info
);
3254 case FB_EVENT_SET_CONSOLE_MAP
:
3255 con2fb
= event
->data
;
3256 ret
= set_con2fb_map(con2fb
->console
- 1,
3257 con2fb
->framebuffer
, 1);
3259 case FB_EVENT_GET_CONSOLE_MAP
:
3260 con2fb
= event
->data
;
3261 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3263 case FB_EVENT_BLANK
:
3264 fbcon_fb_blanked(info
, *(int *)event
->data
);
3266 case FB_EVENT_NEW_MODELIST
:
3267 fbcon_new_modelist(info
);
3269 case FB_EVENT_GET_REQ
:
3271 fbcon_get_requirement(info
, caps
);
3273 case FB_EVENT_REMAP_ALL_CONSOLE
:
3275 fbcon_remap_all(idx
);
3283 * The console `switch' structure for the frame buffer based console
3286 static const struct consw fb_con
= {
3287 .owner
= THIS_MODULE
,
3288 .con_startup
= fbcon_startup
,
3289 .con_init
= fbcon_init
,
3290 .con_deinit
= fbcon_deinit
,
3291 .con_clear
= fbcon_clear
,
3292 .con_putc
= fbcon_putc
,
3293 .con_putcs
= fbcon_putcs
,
3294 .con_cursor
= fbcon_cursor
,
3295 .con_scroll
= fbcon_scroll
,
3296 .con_bmove
= fbcon_bmove
,
3297 .con_switch
= fbcon_switch
,
3298 .con_blank
= fbcon_blank
,
3299 .con_font_set
= fbcon_set_font
,
3300 .con_font_get
= fbcon_get_font
,
3301 .con_font_default
= fbcon_set_def_font
,
3302 .con_font_copy
= fbcon_copy_font
,
3303 .con_set_palette
= fbcon_set_palette
,
3304 .con_scrolldelta
= fbcon_scrolldelta
,
3305 .con_set_origin
= fbcon_set_origin
,
3306 .con_invert_region
= fbcon_invert_region
,
3307 .con_screen_pos
= fbcon_screen_pos
,
3308 .con_getxy
= fbcon_getxy
,
3309 .con_resize
= fbcon_resize
,
3310 .con_debug_enter
= fbcon_debug_enter
,
3311 .con_debug_leave
= fbcon_debug_leave
,
3314 static struct notifier_block fbcon_event_notifier
= {
3315 .notifier_call
= fbcon_event_notify
,
3318 static ssize_t
store_rotate(struct device
*device
,
3319 struct device_attribute
*attr
, const char *buf
,
3322 struct fb_info
*info
;
3326 if (fbcon_has_exited
)
3330 idx
= con2fb_map
[fg_console
];
3332 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3335 info
= registered_fb
[idx
];
3336 rotate
= simple_strtoul(buf
, last
, 0);
3337 fbcon_rotate(info
, rotate
);
3343 static ssize_t
store_rotate_all(struct device
*device
,
3344 struct device_attribute
*attr
,const char *buf
,
3347 struct fb_info
*info
;
3351 if (fbcon_has_exited
)
3355 idx
= con2fb_map
[fg_console
];
3357 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3360 info
= registered_fb
[idx
];
3361 rotate
= simple_strtoul(buf
, last
, 0);
3362 fbcon_rotate_all(info
, rotate
);
3368 static ssize_t
show_rotate(struct device
*device
,
3369 struct device_attribute
*attr
,char *buf
)
3371 struct fb_info
*info
;
3372 int rotate
= 0, idx
;
3374 if (fbcon_has_exited
)
3378 idx
= con2fb_map
[fg_console
];
3380 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3383 info
= registered_fb
[idx
];
3384 rotate
= fbcon_get_rotate(info
);
3387 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3390 static ssize_t
show_cursor_blink(struct device
*device
,
3391 struct device_attribute
*attr
, char *buf
)
3393 struct fb_info
*info
;
3394 struct fbcon_ops
*ops
;
3395 int idx
, blink
= -1;
3397 if (fbcon_has_exited
)
3401 idx
= con2fb_map
[fg_console
];
3403 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3406 info
= registered_fb
[idx
];
3407 ops
= info
->fbcon_par
;
3412 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3415 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3418 static ssize_t
store_cursor_blink(struct device
*device
,
3419 struct device_attribute
*attr
,
3420 const char *buf
, size_t count
)
3422 struct fb_info
*info
;
3426 if (fbcon_has_exited
)
3430 idx
= con2fb_map
[fg_console
];
3432 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3435 info
= registered_fb
[idx
];
3437 if (!info
->fbcon_par
)
3440 blink
= simple_strtoul(buf
, last
, 0);
3443 fbcon_cursor_noblink
= 0;
3444 fbcon_add_cursor_timer(info
);
3446 fbcon_cursor_noblink
= 1;
3447 fbcon_del_cursor_timer(info
);
3455 static struct device_attribute device_attrs
[] = {
3456 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3457 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3458 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3459 store_cursor_blink
),
3462 static int fbcon_init_device(void)
3466 fbcon_has_sysfs
= 1;
3468 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3469 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3477 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3479 fbcon_has_sysfs
= 0;
3485 static void fbcon_start(void)
3487 if (num_registered_fb
) {
3492 for (i
= 0; i
< FB_MAX
; i
++) {
3493 if (registered_fb
[i
] != NULL
) {
3504 static void fbcon_exit(void)
3506 struct fb_info
*info
;
3509 if (fbcon_has_exited
)
3512 kfree((void *)softback_buf
);
3515 for (i
= 0; i
< FB_MAX
; i
++) {
3519 info
= registered_fb
[i
];
3524 if (info
->queue
.func
)
3525 pending
= cancel_work_sync(&info
->queue
);
3526 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3529 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3530 if (con2fb_map
[j
] == i
)
3535 if (info
->fbops
->fb_release
)
3536 info
->fbops
->fb_release(info
, 0);
3537 module_put(info
->fbops
->owner
);
3539 if (info
->fbcon_par
) {
3540 struct fbcon_ops
*ops
= info
->fbcon_par
;
3542 fbcon_del_cursor_timer(info
);
3543 kfree(ops
->cursor_src
);
3544 kfree(info
->fbcon_par
);
3545 info
->fbcon_par
= NULL
;
3548 if (info
->queue
.func
== fb_flashcursor
)
3549 info
->queue
.func
= NULL
;
3553 fbcon_has_exited
= 1;
3556 static int __init
fb_console_init(void)
3561 fb_register_client(&fbcon_event_notifier
);
3562 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3565 if (IS_ERR(fbcon_device
)) {
3566 printk(KERN_WARNING
"Unable to create device "
3567 "for fbcon; errno = %ld\n",
3568 PTR_ERR(fbcon_device
));
3569 fbcon_device
= NULL
;
3571 fbcon_init_device();
3573 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3581 module_init(fb_console_init
);
3585 static void __exit
fbcon_deinit_device(void)
3589 if (fbcon_has_sysfs
) {
3590 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3591 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3593 fbcon_has_sysfs
= 0;
3597 static void __exit
fb_console_exit(void)
3600 fb_unregister_client(&fbcon_event_notifier
);
3601 fbcon_deinit_device();
3602 device_destroy(fb_class
, MKDEV(0, 0));
3605 unregister_con_driver(&fb_con
);
3608 module_exit(fb_console_exit
);
3612 MODULE_LICENSE("GPL");