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
;
374 struct vc_data
*vc
= NULL
;
379 if (ops
&& ops
->currcon
!= -1)
380 vc
= vc_cons
[ops
->currcon
].d
;
382 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
383 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
389 p
= &fb_display
[vc
->vc_num
];
390 c
= scr_readw((u16
*) vc
->vc_pos
);
391 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
393 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
394 get_color(vc
, info
, c
, 0));
398 static void cursor_timer_handler(unsigned long dev_addr
)
400 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
401 struct fbcon_ops
*ops
= info
->fbcon_par
;
403 schedule_work(&info
->queue
);
404 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
407 static void fbcon_add_cursor_timer(struct fb_info
*info
)
409 struct fbcon_ops
*ops
= info
->fbcon_par
;
411 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
412 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
413 !fbcon_cursor_noblink
) {
414 if (!info
->queue
.func
)
415 INIT_WORK(&info
->queue
, fb_flashcursor
);
417 init_timer(&ops
->cursor_timer
);
418 ops
->cursor_timer
.function
= cursor_timer_handler
;
419 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
420 ops
->cursor_timer
.data
= (unsigned long ) info
;
421 add_timer(&ops
->cursor_timer
);
422 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
426 static void fbcon_del_cursor_timer(struct fb_info
*info
)
428 struct fbcon_ops
*ops
= info
->fbcon_par
;
430 if (info
->queue
.func
== fb_flashcursor
&&
431 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
432 del_timer_sync(&ops
->cursor_timer
);
433 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
438 static int __init
fb_console_setup(char *this_opt
)
443 if (!this_opt
|| !*this_opt
)
446 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
447 if (!strncmp(options
, "font:", 5))
448 strcpy(fontname
, options
+ 5);
450 if (!strncmp(options
, "scrollback:", 11)) {
453 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
454 if (*options
== 'k' || *options
== 'K') {
455 fbcon_softback_size
*= 1024;
465 if (!strncmp(options
, "map:", 4)) {
468 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
472 (options
[j
++]-'0') % FB_MAX
;
475 fbcon_map_override();
481 if (!strncmp(options
, "vc:", 3)) {
484 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
487 if (*options
++ == '-')
488 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
489 fbcon_is_default
= 0;
492 if (!strncmp(options
, "rotate:", 7)) {
495 initial_rotation
= simple_strtoul(options
, &options
, 0);
496 if (initial_rotation
> 3)
497 initial_rotation
= 0;
503 __setup("fbcon=", fb_console_setup
);
506 static int search_fb_in_map(int idx
)
510 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
511 if (con2fb_map
[i
] == idx
)
517 static int search_for_mapped_con(void)
521 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
522 if (con2fb_map
[i
] != -1)
528 static int fbcon_takeover(int show_logo
)
532 if (!num_registered_fb
)
536 logo_shown
= FBCON_LOGO_DONTSHOW
;
538 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
539 con2fb_map
[i
] = info_idx
;
541 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
545 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
550 fbcon_has_console_bind
= 1;
557 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
558 int cols
, int rows
, int new_cols
, int new_rows
)
560 logo_shown
= FBCON_LOGO_DONTSHOW
;
563 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
564 int cols
, int rows
, int new_cols
, int new_rows
)
566 /* Need to make room for the logo */
567 struct fbcon_ops
*ops
= info
->fbcon_par
;
568 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
569 unsigned short *save
= NULL
, *r
, *q
;
572 if (info
->flags
& FBINFO_MODULE
) {
573 logo_shown
= FBCON_LOGO_DONTSHOW
;
578 * remove underline attribute from erase character
579 * if black and white framebuffer.
581 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
583 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
584 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
585 q
= (unsigned short *) (vc
->vc_origin
+
586 vc
->vc_size_row
* rows
);
587 step
= logo_lines
* cols
;
588 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
589 if (scr_readw(r
) != vc
->vc_video_erase_char
)
591 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
592 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
594 int i
= cols
< new_cols
? cols
: new_cols
;
595 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
597 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
598 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
603 /* We can scroll screen down */
605 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
606 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
611 if (vc
->vc_y
+ logo_lines
>= rows
)
612 lines
= rows
- vc
->vc_y
- 1;
616 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
619 scr_memsetw((unsigned short *) vc
->vc_origin
,
621 vc
->vc_size_row
* logo_lines
);
623 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
624 fbcon_clear_margins(vc
, 0);
629 q
= (unsigned short *) (vc
->vc_origin
+
632 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
633 vc
->vc_y
+= logo_lines
;
634 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
638 if (logo_lines
> vc
->vc_bottom
) {
639 logo_shown
= FBCON_LOGO_CANSHOW
;
641 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
642 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
643 logo_shown
= FBCON_LOGO_DRAW
;
644 vc
->vc_top
= logo_lines
;
649 #ifdef CONFIG_FB_TILEBLITTING
650 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
652 struct fbcon_ops
*ops
= info
->fbcon_par
;
654 ops
->p
= &fb_display
[vc
->vc_num
];
656 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
657 fbcon_set_tileops(vc
, info
);
659 fbcon_set_rotation(info
);
660 fbcon_set_bitops(ops
);
664 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
668 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
669 info
->tileops
->fb_get_tilemax(info
) < charcount
)
675 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
677 struct fbcon_ops
*ops
= info
->fbcon_par
;
679 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
680 ops
->p
= &fb_display
[vc
->vc_num
];
681 fbcon_set_rotation(info
);
682 fbcon_set_bitops(ops
);
685 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
690 #endif /* CONFIG_MISC_TILEBLITTING */
693 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
694 int unit
, int oldidx
)
696 struct fbcon_ops
*ops
= NULL
;
699 if (!try_module_get(info
->fbops
->owner
))
702 if (!err
&& info
->fbops
->fb_open
&&
703 info
->fbops
->fb_open(info
, 0))
707 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
713 info
->fbcon_par
= ops
;
716 set_blitting_type(vc
, info
);
720 con2fb_map
[unit
] = oldidx
;
721 module_put(info
->fbops
->owner
);
727 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
728 struct fb_info
*newinfo
, int unit
,
729 int oldidx
, int found
)
731 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
734 if (oldinfo
->fbops
->fb_release
&&
735 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
736 con2fb_map
[unit
] = oldidx
;
737 if (!found
&& newinfo
->fbops
->fb_release
)
738 newinfo
->fbops
->fb_release(newinfo
, 0);
740 module_put(newinfo
->fbops
->owner
);
745 fbcon_del_cursor_timer(oldinfo
);
746 kfree(ops
->cursor_state
.mask
);
747 kfree(ops
->cursor_data
);
748 kfree(ops
->fontbuffer
);
749 kfree(oldinfo
->fbcon_par
);
750 oldinfo
->fbcon_par
= NULL
;
751 module_put(oldinfo
->fbops
->owner
);
753 If oldinfo and newinfo are driving the same hardware,
754 the fb_release() method of oldinfo may attempt to
755 restore the hardware state. This will leave the
756 newinfo in an undefined state. Thus, a call to
757 fb_set_par() may be needed for the newinfo.
759 if (newinfo
->fbops
->fb_set_par
) {
760 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
763 printk(KERN_ERR
"con2fb_release_oldinfo: "
764 "detected unhandled fb_set_par error, "
765 "error code %d\n", ret
);
772 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
773 int unit
, int show_logo
)
775 struct fbcon_ops
*ops
= info
->fbcon_par
;
778 ops
->currcon
= fg_console
;
780 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
781 ret
= info
->fbops
->fb_set_par(info
);
784 printk(KERN_ERR
"con2fb_init_display: detected "
785 "unhandled fb_set_par error, "
786 "error code %d\n", ret
);
789 ops
->flags
|= FBCON_FLAGS_INIT
;
791 fbcon_set_disp(info
, &info
->var
, unit
);
794 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
795 struct fb_info
*fg_info
=
796 registered_fb
[con2fb_map
[fg_console
]];
798 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
799 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
803 update_screen(vc_cons
[fg_console
].d
);
807 * set_con2fb_map - map console to frame buffer device
808 * @unit: virtual console number to map
809 * @newidx: frame buffer index to map virtual console to
810 * @user: user request
812 * Maps a virtual console @unit to a frame buffer device
815 static int set_con2fb_map(int unit
, int newidx
, int user
)
817 struct vc_data
*vc
= vc_cons
[unit
].d
;
818 int oldidx
= con2fb_map
[unit
];
819 struct fb_info
*info
= registered_fb
[newidx
];
820 struct fb_info
*oldinfo
= NULL
;
823 if (oldidx
== newidx
)
826 if (!info
|| fbcon_has_exited
)
829 if (!err
&& !search_for_mapped_con()) {
831 return fbcon_takeover(0);
835 oldinfo
= registered_fb
[oldidx
];
837 found
= search_fb_in_map(newidx
);
840 con2fb_map
[unit
] = newidx
;
842 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
846 * If old fb is not mapped to any of the consoles,
847 * fbcon should release it.
849 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
850 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
854 int show_logo
= (fg_console
== 0 && !user
&&
855 logo_shown
!= FBCON_LOGO_DONTSHOW
);
858 fbcon_add_cursor_timer(info
);
859 con2fb_map_boot
[unit
] = newidx
;
860 con2fb_init_display(vc
, info
, unit
, show_logo
);
863 if (!search_fb_in_map(info_idx
))
871 * Low Level Operations
873 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
874 static int var_to_display(struct display
*disp
,
875 struct fb_var_screeninfo
*var
,
876 struct fb_info
*info
)
878 disp
->xres_virtual
= var
->xres_virtual
;
879 disp
->yres_virtual
= var
->yres_virtual
;
880 disp
->bits_per_pixel
= var
->bits_per_pixel
;
881 disp
->grayscale
= var
->grayscale
;
882 disp
->nonstd
= var
->nonstd
;
883 disp
->accel_flags
= var
->accel_flags
;
884 disp
->height
= var
->height
;
885 disp
->width
= var
->width
;
886 disp
->red
= var
->red
;
887 disp
->green
= var
->green
;
888 disp
->blue
= var
->blue
;
889 disp
->transp
= var
->transp
;
890 disp
->rotate
= var
->rotate
;
891 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
892 if (disp
->mode
== NULL
)
893 /* This should not happen */
898 static void display_to_var(struct fb_var_screeninfo
*var
,
899 struct display
*disp
)
901 fb_videomode_to_var(var
, disp
->mode
);
902 var
->xres_virtual
= disp
->xres_virtual
;
903 var
->yres_virtual
= disp
->yres_virtual
;
904 var
->bits_per_pixel
= disp
->bits_per_pixel
;
905 var
->grayscale
= disp
->grayscale
;
906 var
->nonstd
= disp
->nonstd
;
907 var
->accel_flags
= disp
->accel_flags
;
908 var
->height
= disp
->height
;
909 var
->width
= disp
->width
;
910 var
->red
= disp
->red
;
911 var
->green
= disp
->green
;
912 var
->blue
= disp
->blue
;
913 var
->transp
= disp
->transp
;
914 var
->rotate
= disp
->rotate
;
917 static const char *fbcon_startup(void)
919 const char *display_desc
= "frame buffer device";
920 struct display
*p
= &fb_display
[fg_console
];
921 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
922 const struct font_desc
*font
= NULL
;
923 struct module
*owner
;
924 struct fb_info
*info
= NULL
;
925 struct fbcon_ops
*ops
;
929 * If num_registered_fb is zero, this is a call for the dummy part.
930 * The frame buffer devices weren't initialized yet.
932 if (!num_registered_fb
|| info_idx
== -1)
935 * Instead of blindly using registered_fb[0], we use info_idx, set by
938 info
= registered_fb
[info_idx
];
942 owner
= info
->fbops
->owner
;
943 if (!try_module_get(owner
))
945 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
950 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
958 ops
->cur_rotate
= -1;
959 info
->fbcon_par
= ops
;
960 p
->con_rotate
= initial_rotation
;
961 set_blitting_type(vc
, info
);
963 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
964 if (fbcon_softback_size
) {
968 kmalloc(fbcon_softback_size
,
971 fbcon_softback_size
= 0;
977 kfree((void *) softback_buf
);
983 softback_in
= softback_top
= softback_curr
=
988 /* Setup default font */
990 if (!fontname
[0] || !(font
= find_font(fontname
)))
991 font
= get_default_font(info
->var
.xres
,
994 info
->pixmap
.blit_y
);
995 vc
->vc_font
.width
= font
->width
;
996 vc
->vc_font
.height
= font
->height
;
997 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
998 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1001 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1002 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1003 cols
/= vc
->vc_font
.width
;
1004 rows
/= vc
->vc_font
.height
;
1005 vc_resize(vc
, cols
, rows
);
1007 DPRINTK("mode: %s\n", info
->fix
.id
);
1008 DPRINTK("visual: %d\n", info
->fix
.visual
);
1009 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1011 info
->var
.bits_per_pixel
);
1013 fbcon_add_cursor_timer(info
);
1014 fbcon_has_exited
= 0;
1015 return display_desc
;
1018 static void fbcon_init(struct vc_data
*vc
, int init
)
1020 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1021 struct fbcon_ops
*ops
;
1022 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1023 struct vc_data
*svc
= *default_mode
;
1024 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1025 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1028 if (info_idx
== -1 || info
== NULL
)
1033 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1034 (info
->fix
.type
== FB_TYPE_TEXT
))
1037 if (var_to_display(p
, &info
->var
, info
))
1040 if (!info
->fbcon_par
)
1041 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1043 /* If we are not the first console on this
1044 fb, copy the font from that console */
1045 t
= &fb_display
[fg_console
];
1048 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1050 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1052 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1053 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1054 p
->userfont
= t
->userfont
;
1057 REFCOUNT(p
->fontdata
)++;
1059 const struct font_desc
*font
= NULL
;
1061 if (!fontname
[0] || !(font
= find_font(fontname
)))
1062 font
= get_default_font(info
->var
.xres
,
1064 info
->pixmap
.blit_x
,
1065 info
->pixmap
.blit_y
);
1066 vc
->vc_font
.width
= font
->width
;
1067 vc
->vc_font
.height
= font
->height
;
1068 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1069 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1070 support more fonts */
1075 charcnt
= FNTCHARCNT(p
->fontdata
);
1077 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1078 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1079 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1080 if (charcnt
== 256) {
1081 vc
->vc_hi_font_mask
= 0;
1083 vc
->vc_hi_font_mask
= 0x100;
1084 if (vc
->vc_can_do_color
)
1085 vc
->vc_complement_mask
<<= 1;
1088 if (!*svc
->vc_uni_pagedir_loc
)
1089 con_set_default_unimap(svc
);
1090 if (!*vc
->vc_uni_pagedir_loc
)
1091 con_copy_unimap(vc
, svc
);
1093 ops
= info
->fbcon_par
;
1094 p
->con_rotate
= initial_rotation
;
1095 set_blitting_type(vc
, info
);
1099 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1100 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1101 new_cols
/= vc
->vc_font
.width
;
1102 new_rows
/= vc
->vc_font
.height
;
1105 * We must always set the mode. The mode of the previous console
1106 * driver could be in the same resolution but we are using different
1107 * hardware so we have to initialize the hardware.
1109 * We need to do it in fbcon_init() to prevent screen corruption.
1111 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1112 if (info
->fbops
->fb_set_par
&&
1113 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1114 ret
= info
->fbops
->fb_set_par(info
);
1117 printk(KERN_ERR
"fbcon_init: detected "
1118 "unhandled fb_set_par error, "
1119 "error code %d\n", ret
);
1122 ops
->flags
|= FBCON_FLAGS_INIT
;
1127 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1128 !(cap
& FBINFO_HWACCEL_DISABLED
))
1129 p
->scrollmode
= SCROLL_MOVE
;
1130 else /* default to something safe */
1131 p
->scrollmode
= SCROLL_REDRAW
;
1134 * ++guenther: console.c:vc_allocate() relies on initializing
1135 * vc_{cols,rows}, but we must not set those if we are only
1136 * resizing the console.
1139 vc
->vc_cols
= new_cols
;
1140 vc
->vc_rows
= new_rows
;
1142 vc_resize(vc
, new_cols
, new_rows
);
1145 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1147 if (vc
== svc
&& softback_buf
)
1148 fbcon_update_softback(vc
);
1150 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1151 ops
->rotate
= FB_ROTATE_UR
;
1152 set_blitting_type(vc
, info
);
1155 ops
->p
= &fb_display
[fg_console
];
1158 static void fbcon_free_font(struct display
*p
)
1160 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1161 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1166 static void fbcon_deinit(struct vc_data
*vc
)
1168 struct display
*p
= &fb_display
[vc
->vc_num
];
1169 struct fb_info
*info
;
1170 struct fbcon_ops
*ops
;
1174 idx
= con2fb_map
[vc
->vc_num
];
1179 info
= registered_fb
[idx
];
1184 ops
= info
->fbcon_par
;
1189 if (CON_IS_VISIBLE(vc
))
1190 fbcon_del_cursor_timer(info
);
1192 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1195 if (!con_is_bound(&fb_con
))
1201 /* ====================================================================== */
1203 /* fbcon_XXX routines - interface used by the world
1205 * This system is now divided into two levels because of complications
1206 * caused by hardware scrolling. Top level functions:
1208 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1210 * handles y values in range [0, scr_height-1] that correspond to real
1211 * screen positions. y_wrap shift means that first line of bitmap may be
1212 * anywhere on this display. These functions convert lineoffsets to
1213 * bitmap offsets and deal with the wrap-around case by splitting blits.
1215 * fbcon_bmove_physical_8() -- These functions fast implementations
1216 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1217 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1221 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1222 * Implies should only really hardware scroll in rows. Only reason for
1223 * restriction is simplicity & efficiency at the moment.
1226 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1229 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1230 struct fbcon_ops
*ops
= info
->fbcon_par
;
1232 struct display
*p
= &fb_display
[vc
->vc_num
];
1235 if (fbcon_is_inactive(vc
, info
))
1238 if (!height
|| !width
)
1241 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
)
1244 /* Split blits that cross physical y_wrap boundary */
1246 y_break
= p
->vrows
- p
->yscroll
;
1247 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1248 u_int b
= y_break
- sy
;
1249 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1250 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1253 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1256 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1257 int count
, int ypos
, int xpos
)
1259 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1260 struct display
*p
= &fb_display
[vc
->vc_num
];
1261 struct fbcon_ops
*ops
= info
->fbcon_par
;
1263 if (!fbcon_is_inactive(vc
, info
))
1264 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1265 get_color(vc
, info
, scr_readw(s
), 1),
1266 get_color(vc
, info
, scr_readw(s
), 0));
1269 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1273 scr_writew(c
, &chr
);
1274 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1277 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1279 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1280 struct fbcon_ops
*ops
= info
->fbcon_par
;
1282 if (!fbcon_is_inactive(vc
, info
))
1283 ops
->clear_margins(vc
, info
, bottom_only
);
1286 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1288 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1289 struct fbcon_ops
*ops
= info
->fbcon_par
;
1291 int c
= scr_readw((u16
*) vc
->vc_pos
);
1293 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1296 if (vc
->vc_cursor_type
& 0x10)
1297 fbcon_del_cursor_timer(info
);
1299 fbcon_add_cursor_timer(info
);
1301 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1302 if (mode
& CM_SOFTBACK
) {
1303 mode
&= ~CM_SOFTBACK
;
1307 fbcon_set_origin(vc
);
1311 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1312 get_color(vc
, info
, c
, 0));
1313 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1316 static int scrollback_phys_max
= 0;
1317 static int scrollback_max
= 0;
1318 static int scrollback_current
= 0;
1320 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1323 struct display
*p
, *t
;
1324 struct vc_data
**default_mode
, *vc
;
1325 struct vc_data
*svc
;
1326 struct fbcon_ops
*ops
= info
->fbcon_par
;
1327 int rows
, cols
, charcnt
= 256;
1329 p
= &fb_display
[unit
];
1331 if (var_to_display(p
, var
, info
))
1334 vc
= vc_cons
[unit
].d
;
1339 default_mode
= vc
->vc_display_fg
;
1340 svc
= *default_mode
;
1341 t
= &fb_display
[svc
->vc_num
];
1343 if (!vc
->vc_font
.data
) {
1344 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1345 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1346 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1347 p
->userfont
= t
->userfont
;
1349 REFCOUNT(p
->fontdata
)++;
1352 charcnt
= FNTCHARCNT(p
->fontdata
);
1354 var
->activate
= FB_ACTIVATE_NOW
;
1355 info
->var
.activate
= var
->activate
;
1356 var
->yoffset
= info
->var
.yoffset
;
1357 var
->xoffset
= info
->var
.xoffset
;
1358 fb_set_var(info
, var
);
1359 ops
->var
= info
->var
;
1360 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1361 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1362 if (charcnt
== 256) {
1363 vc
->vc_hi_font_mask
= 0;
1365 vc
->vc_hi_font_mask
= 0x100;
1366 if (vc
->vc_can_do_color
)
1367 vc
->vc_complement_mask
<<= 1;
1370 if (!*svc
->vc_uni_pagedir_loc
)
1371 con_set_default_unimap(svc
);
1372 if (!*vc
->vc_uni_pagedir_loc
)
1373 con_copy_unimap(vc
, svc
);
1375 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1376 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1377 cols
/= vc
->vc_font
.width
;
1378 rows
/= vc
->vc_font
.height
;
1379 vc_resize(vc
, cols
, rows
);
1381 if (CON_IS_VISIBLE(vc
)) {
1384 fbcon_update_softback(vc
);
1388 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1390 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1391 struct fbcon_ops
*ops
= info
->fbcon_par
;
1392 struct display
*p
= &fb_display
[vc
->vc_num
];
1394 p
->yscroll
+= count
;
1395 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1396 p
->yscroll
-= p
->vrows
;
1397 ops
->var
.xoffset
= 0;
1398 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1399 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1400 ops
->update_start(info
);
1401 scrollback_max
+= count
;
1402 if (scrollback_max
> scrollback_phys_max
)
1403 scrollback_max
= scrollback_phys_max
;
1404 scrollback_current
= 0;
1407 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1409 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1410 struct fbcon_ops
*ops
= info
->fbcon_par
;
1411 struct display
*p
= &fb_display
[vc
->vc_num
];
1413 p
->yscroll
-= count
;
1414 if (p
->yscroll
< 0) /* Deal with wrap */
1415 p
->yscroll
+= p
->vrows
;
1416 ops
->var
.xoffset
= 0;
1417 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1418 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1419 ops
->update_start(info
);
1420 scrollback_max
-= count
;
1421 if (scrollback_max
< 0)
1423 scrollback_current
= 0;
1426 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1428 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1429 struct display
*p
= &fb_display
[vc
->vc_num
];
1430 struct fbcon_ops
*ops
= info
->fbcon_par
;
1432 p
->yscroll
+= count
;
1433 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1434 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1435 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1436 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1439 ops
->var
.xoffset
= 0;
1440 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1441 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1442 ops
->update_start(info
);
1443 fbcon_clear_margins(vc
, 1);
1444 scrollback_max
+= count
;
1445 if (scrollback_max
> scrollback_phys_max
)
1446 scrollback_max
= scrollback_phys_max
;
1447 scrollback_current
= 0;
1450 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1452 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1453 struct fbcon_ops
*ops
= info
->fbcon_par
;
1454 struct display
*p
= &fb_display
[vc
->vc_num
];
1456 p
->yscroll
+= count
;
1458 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1459 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1460 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1463 ops
->var
.xoffset
= 0;
1464 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1465 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1466 ops
->update_start(info
);
1467 fbcon_clear_margins(vc
, 1);
1468 scrollback_max
+= count
;
1469 if (scrollback_max
> scrollback_phys_max
)
1470 scrollback_max
= scrollback_phys_max
;
1471 scrollback_current
= 0;
1474 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1476 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1477 struct display
*p
= &fb_display
[vc
->vc_num
];
1478 struct fbcon_ops
*ops
= info
->fbcon_par
;
1480 p
->yscroll
-= count
;
1481 if (p
->yscroll
< 0) {
1482 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1483 0, vc
->vc_rows
, vc
->vc_cols
);
1484 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1487 ops
->var
.xoffset
= 0;
1488 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1489 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1490 ops
->update_start(info
);
1491 fbcon_clear_margins(vc
, 1);
1492 scrollback_max
-= count
;
1493 if (scrollback_max
< 0)
1495 scrollback_current
= 0;
1498 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1500 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1501 struct fbcon_ops
*ops
= info
->fbcon_par
;
1502 struct display
*p
= &fb_display
[vc
->vc_num
];
1504 p
->yscroll
-= count
;
1506 if (p
->yscroll
< 0) {
1507 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1508 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1511 ops
->var
.xoffset
= 0;
1512 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1513 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1514 ops
->update_start(info
);
1515 fbcon_clear_margins(vc
, 1);
1516 scrollback_max
-= count
;
1517 if (scrollback_max
< 0)
1519 scrollback_current
= 0;
1522 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1525 int count
= vc
->vc_rows
;
1526 unsigned short *d
, *s
;
1530 d
= (u16
*) softback_curr
;
1531 if (d
== (u16
*) softback_in
)
1532 d
= (u16
*) vc
->vc_origin
;
1533 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1534 softback_lines
-= delta
;
1536 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1537 n
+= softback_end
- softback_buf
;
1538 if (n
< softback_top
) {
1540 (softback_top
- n
) / vc
->vc_size_row
;
1543 } else if (softback_curr
>= softback_top
1544 && n
< softback_top
) {
1546 (softback_top
- n
) / vc
->vc_size_row
;
1550 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1551 n
+= softback_buf
- softback_end
;
1552 if (n
> softback_in
) {
1556 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1561 if (n
== softback_curr
)
1564 s
= (u16
*) softback_curr
;
1565 if (s
== (u16
*) softback_in
)
1566 s
= (u16
*) vc
->vc_origin
;
1568 unsigned short *start
;
1572 unsigned short attr
= 1;
1575 le
= advance_row(s
, 1);
1578 if (attr
!= (c
& 0xff00)) {
1581 fbcon_putcs(vc
, start
, s
- start
,
1587 if (c
== scr_readw(d
)) {
1589 fbcon_putcs(vc
, start
, s
- start
,
1602 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1604 if (d
== (u16
*) softback_end
)
1605 d
= (u16
*) softback_buf
;
1606 if (d
== (u16
*) softback_in
)
1607 d
= (u16
*) vc
->vc_origin
;
1608 if (s
== (u16
*) softback_end
)
1609 s
= (u16
*) softback_buf
;
1610 if (s
== (u16
*) softback_in
)
1611 s
= (u16
*) vc
->vc_origin
;
1615 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1616 int line
, int count
, int dy
)
1618 unsigned short *s
= (unsigned short *)
1619 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1622 unsigned short *start
= s
;
1623 unsigned short *le
= advance_row(s
, 1);
1626 unsigned short attr
= 1;
1630 if (attr
!= (c
& 0xff00)) {
1633 fbcon_putcs(vc
, start
, s
- start
,
1639 console_conditional_schedule();
1643 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1644 console_conditional_schedule();
1649 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1650 struct display
*p
, int line
, int count
, int ycount
)
1652 int offset
= ycount
* vc
->vc_cols
;
1653 unsigned short *d
= (unsigned short *)
1654 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1655 unsigned short *s
= d
+ offset
;
1656 struct fbcon_ops
*ops
= info
->fbcon_par
;
1659 unsigned short *start
= s
;
1660 unsigned short *le
= advance_row(s
, 1);
1667 if (c
== scr_readw(d
)) {
1669 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1670 line
, x
, 1, s
-start
);
1680 console_conditional_schedule();
1685 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1687 console_conditional_schedule();
1692 /* NOTE: We subtract two lines from these pointers */
1693 s
-= vc
->vc_size_row
;
1694 d
-= vc
->vc_size_row
;
1699 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1700 int line
, int count
, int offset
)
1702 unsigned short *d
= (unsigned short *)
1703 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1704 unsigned short *s
= d
+ offset
;
1707 unsigned short *start
= s
;
1708 unsigned short *le
= advance_row(s
, 1);
1711 unsigned short attr
= 1;
1715 if (attr
!= (c
& 0xff00)) {
1718 fbcon_putcs(vc
, start
, s
- start
,
1724 if (c
== scr_readw(d
)) {
1726 fbcon_putcs(vc
, start
, s
- start
,
1736 console_conditional_schedule();
1741 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1742 console_conditional_schedule();
1747 /* NOTE: We subtract two lines from these pointers */
1748 s
-= vc
->vc_size_row
;
1749 d
-= vc
->vc_size_row
;
1754 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1759 if (vc
->vc_num
!= fg_console
)
1761 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1764 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1766 p
= advance_row(p
, 1);
1767 softback_in
+= vc
->vc_size_row
;
1768 if (softback_in
== softback_end
)
1769 softback_in
= softback_buf
;
1770 if (softback_in
== softback_top
) {
1771 softback_top
+= vc
->vc_size_row
;
1772 if (softback_top
== softback_end
)
1773 softback_top
= softback_buf
;
1776 softback_curr
= softback_in
;
1779 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1782 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1783 struct display
*p
= &fb_display
[vc
->vc_num
];
1784 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1786 if (fbcon_is_inactive(vc
, info
))
1789 fbcon_cursor(vc
, CM_ERASE
);
1792 * ++Geert: Only use ywrap/ypan if the console is in text mode
1793 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1794 * whole screen (prevents flicker).
1799 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1800 count
= vc
->vc_rows
;
1802 fbcon_softback_note(vc
, t
, count
);
1803 if (logo_shown
>= 0)
1805 switch (p
->scrollmode
) {
1807 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1809 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1810 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1813 vc
->vc_video_erase_char
,
1814 vc
->vc_size_row
* count
);
1818 case SCROLL_WRAP_MOVE
:
1819 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1821 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1823 ywrap_up(vc
, count
);
1824 if (vc
->vc_rows
- b
> 0)
1825 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1828 } else if (info
->flags
& FBINFO_READS_FAST
)
1829 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1830 b
- t
- count
, vc
->vc_cols
);
1833 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1836 case SCROLL_PAN_REDRAW
:
1837 if ((p
->yscroll
+ count
<=
1838 2 * (p
->vrows
- vc
->vc_rows
))
1839 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1842 3 * vc
->vc_rows
>> 2)))) {
1844 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1845 ypan_up_redraw(vc
, t
, count
);
1846 if (vc
->vc_rows
- b
> 0)
1847 fbcon_redraw_move(vc
, p
, b
,
1848 vc
->vc_rows
- b
, b
);
1850 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1851 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1854 case SCROLL_PAN_MOVE
:
1855 if ((p
->yscroll
+ count
<=
1856 2 * (p
->vrows
- vc
->vc_rows
))
1857 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1860 3 * vc
->vc_rows
>> 2)))) {
1862 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1865 if (vc
->vc_rows
- b
> 0)
1866 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1869 } else if (info
->flags
& FBINFO_READS_FAST
)
1870 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1871 b
- t
- count
, vc
->vc_cols
);
1874 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1879 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1880 count
* vc
->vc_cols
);
1881 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1882 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1885 vc
->vc_video_erase_char
,
1886 vc
->vc_size_row
* count
);
1892 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1893 count
= vc
->vc_rows
;
1894 if (logo_shown
>= 0)
1896 switch (p
->scrollmode
) {
1898 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1900 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1901 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1904 vc
->vc_video_erase_char
,
1905 vc
->vc_size_row
* count
);
1909 case SCROLL_WRAP_MOVE
:
1910 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1911 if (vc
->vc_rows
- b
> 0)
1912 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1915 ywrap_down(vc
, count
);
1917 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1919 } else if (info
->flags
& FBINFO_READS_FAST
)
1920 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1921 b
- t
- count
, vc
->vc_cols
);
1924 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1927 case SCROLL_PAN_MOVE
:
1928 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1929 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1932 3 * vc
->vc_rows
>> 2)))) {
1933 if (vc
->vc_rows
- b
> 0)
1934 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1937 ypan_down(vc
, count
);
1939 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1941 } else if (info
->flags
& FBINFO_READS_FAST
)
1942 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1943 b
- t
- count
, vc
->vc_cols
);
1946 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1949 case SCROLL_PAN_REDRAW
:
1950 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1951 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1954 3 * vc
->vc_rows
>> 2)))) {
1955 if (vc
->vc_rows
- b
> 0)
1956 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1958 ypan_down_redraw(vc
, t
, count
);
1960 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1962 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1963 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1968 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1969 -count
* vc
->vc_cols
);
1970 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1971 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1974 vc
->vc_video_erase_char
,
1975 vc
->vc_size_row
* count
);
1983 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1984 int height
, int width
)
1986 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1987 struct display
*p
= &fb_display
[vc
->vc_num
];
1989 if (fbcon_is_inactive(vc
, info
))
1992 if (!width
|| !height
)
1995 /* Split blits that cross physical y_wrap case.
1996 * Pathological case involves 4 blits, better to use recursive
1997 * code rather than unrolled case
1999 * Recursive invocations don't need to erase the cursor over and
2000 * over again, so we use fbcon_bmove_rec()
2002 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2003 p
->vrows
- p
->yscroll
);
2006 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2007 int dy
, int dx
, int height
, int width
, u_int y_break
)
2009 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2010 struct fbcon_ops
*ops
= info
->fbcon_par
;
2013 if (sy
< y_break
&& sy
+ height
> y_break
) {
2015 if (dy
< sy
) { /* Avoid trashing self */
2016 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2018 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2019 height
- b
, width
, y_break
);
2021 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2022 height
- b
, width
, y_break
);
2023 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2029 if (dy
< y_break
&& dy
+ height
> y_break
) {
2031 if (dy
< sy
) { /* Avoid trashing self */
2032 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2034 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2035 height
- b
, width
, y_break
);
2037 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2038 height
- b
, width
, y_break
);
2039 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2044 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2048 static void updatescrollmode(struct display
*p
,
2049 struct fb_info
*info
,
2052 struct fbcon_ops
*ops
= info
->fbcon_par
;
2053 int fh
= vc
->vc_font
.height
;
2054 int cap
= info
->flags
;
2056 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2057 info
->fix
.xpanstep
);
2058 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2059 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2060 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2061 info
->var
.xres_virtual
);
2062 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2063 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2064 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2065 divides(ywrap
, vc
->vc_font
.height
) &&
2066 divides(vc
->vc_font
.height
, vyres
) &&
2067 divides(vc
->vc_font
.height
, yres
);
2068 int reading_fast
= cap
& FBINFO_READS_FAST
;
2069 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2070 !(cap
& FBINFO_HWACCEL_DISABLED
);
2071 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2072 !(cap
& FBINFO_HWACCEL_DISABLED
);
2074 p
->vrows
= vyres
/fh
;
2075 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2076 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2077 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2080 if (good_wrap
|| good_pan
) {
2081 if (reading_fast
|| fast_copyarea
)
2082 p
->scrollmode
= good_wrap
?
2083 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2085 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2088 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2089 p
->scrollmode
= SCROLL_MOVE
;
2091 p
->scrollmode
= SCROLL_REDRAW
;
2095 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2096 unsigned int height
, unsigned int user
)
2098 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2099 struct fbcon_ops
*ops
= info
->fbcon_par
;
2100 struct display
*p
= &fb_display
[vc
->vc_num
];
2101 struct fb_var_screeninfo var
= info
->var
;
2102 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2104 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2105 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2106 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2107 vc
->vc_font
.height
);
2108 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2110 var
.xres
= virt_w
* virt_fw
;
2111 var
.yres
= virt_h
* virt_fh
;
2112 x_diff
= info
->var
.xres
- var
.xres
;
2113 y_diff
= info
->var
.yres
- var
.yres
;
2114 if (x_diff
< 0 || x_diff
> virt_fw
||
2115 y_diff
< 0 || y_diff
> virt_fh
) {
2116 const struct fb_videomode
*mode
;
2118 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2119 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2122 display_to_var(&var
, p
);
2123 fb_videomode_to_var(&var
, mode
);
2125 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2128 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2129 if (CON_IS_VISIBLE(vc
)) {
2130 var
.activate
= FB_ACTIVATE_NOW
|
2132 fb_set_var(info
, &var
);
2134 var_to_display(p
, &info
->var
, info
);
2135 ops
->var
= info
->var
;
2137 updatescrollmode(p
, info
, vc
);
2141 static int fbcon_switch(struct vc_data
*vc
)
2143 struct fb_info
*info
, *old_info
= NULL
;
2144 struct fbcon_ops
*ops
;
2145 struct display
*p
= &fb_display
[vc
->vc_num
];
2146 struct fb_var_screeninfo var
;
2147 int i
, ret
, prev_console
, charcnt
= 256;
2149 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2150 ops
= info
->fbcon_par
;
2154 fbcon_set_origin(vc
);
2155 softback_top
= softback_curr
= softback_in
= softback_buf
;
2157 fbcon_update_softback(vc
);
2160 if (logo_shown
>= 0) {
2161 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2163 if (conp2
->vc_top
== logo_lines
2164 && conp2
->vc_bottom
== conp2
->vc_rows
)
2166 logo_shown
= FBCON_LOGO_CANSHOW
;
2169 prev_console
= ops
->currcon
;
2170 if (prev_console
!= -1)
2171 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2173 * FIXME: If we have multiple fbdev's loaded, we need to
2174 * update all info->currcon. Perhaps, we can place this
2175 * in a centralized structure, but this might break some
2178 * info->currcon = vc->vc_num;
2180 for (i
= 0; i
< FB_MAX
; i
++) {
2181 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2182 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2184 o
->currcon
= vc
->vc_num
;
2187 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2188 display_to_var(&var
, p
);
2189 var
.activate
= FB_ACTIVATE_NOW
;
2192 * make sure we don't unnecessarily trip the memcmp()
2195 info
->var
.activate
= var
.activate
;
2196 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2197 fb_set_var(info
, &var
);
2198 ops
->var
= info
->var
;
2200 if (old_info
!= NULL
&& (old_info
!= info
||
2201 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2202 if (info
->fbops
->fb_set_par
) {
2203 ret
= info
->fbops
->fb_set_par(info
);
2206 printk(KERN_ERR
"fbcon_switch: detected "
2207 "unhandled fb_set_par error, "
2208 "error code %d\n", ret
);
2211 if (old_info
!= info
)
2212 fbcon_del_cursor_timer(old_info
);
2215 if (fbcon_is_inactive(vc
, info
) ||
2216 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2217 fbcon_del_cursor_timer(info
);
2219 fbcon_add_cursor_timer(info
);
2221 set_blitting_type(vc
, info
);
2222 ops
->cursor_reset
= 1;
2224 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2225 ops
->rotate
= FB_ROTATE_UR
;
2226 set_blitting_type(vc
, info
);
2229 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2230 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2233 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2236 vc
->vc_complement_mask
<<= 1;
2238 updatescrollmode(p
, info
, vc
);
2240 switch (p
->scrollmode
) {
2241 case SCROLL_WRAP_MOVE
:
2242 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2244 case SCROLL_PAN_MOVE
:
2245 case SCROLL_PAN_REDRAW
:
2246 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2247 if (scrollback_phys_max
< 0)
2248 scrollback_phys_max
= 0;
2251 scrollback_phys_max
= 0;
2256 scrollback_current
= 0;
2258 if (!fbcon_is_inactive(vc
, info
)) {
2259 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2260 ops
->update_start(info
);
2263 fbcon_set_palette(vc
, color_table
);
2264 fbcon_clear_margins(vc
, 0);
2266 if (logo_shown
== FBCON_LOGO_DRAW
) {
2268 logo_shown
= fg_console
;
2269 /* This is protected above by initmem_freed */
2270 fb_show_logo(info
, ops
->rotate
);
2272 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2273 vc
->vc_size_row
* (vc
->vc_bottom
-
2280 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2283 struct fb_event event
;
2286 unsigned short charmask
= vc
->vc_hi_font_mask
?
2288 unsigned short oldc
;
2290 oldc
= vc
->vc_video_erase_char
;
2291 vc
->vc_video_erase_char
&= charmask
;
2292 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2293 vc
->vc_video_erase_char
= oldc
;
2297 if (!lock_fb_info(info
))
2300 event
.data
= &blank
;
2301 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2302 unlock_fb_info(info
);
2305 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2307 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2308 struct fbcon_ops
*ops
= info
->fbcon_par
;
2311 struct fb_var_screeninfo var
= info
->var
;
2316 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2317 fb_set_var(info
, &var
);
2319 ops
->var
= info
->var
;
2323 if (!fbcon_is_inactive(vc
, info
)) {
2324 if (ops
->blank_state
!= blank
) {
2325 ops
->blank_state
= blank
;
2326 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2327 ops
->cursor_flash
= (!blank
);
2329 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2330 if (fb_blank(info
, blank
))
2331 fbcon_generic_blank(vc
, info
, blank
);
2338 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2339 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2340 fbcon_del_cursor_timer(info
);
2342 fbcon_add_cursor_timer(info
);
2347 static int fbcon_debug_enter(struct vc_data
*vc
)
2349 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2350 struct fbcon_ops
*ops
= info
->fbcon_par
;
2352 ops
->save_graphics
= ops
->graphics
;
2354 if (info
->fbops
->fb_debug_enter
)
2355 info
->fbops
->fb_debug_enter(info
);
2356 fbcon_set_palette(vc
, color_table
);
2360 static int fbcon_debug_leave(struct vc_data
*vc
)
2362 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2363 struct fbcon_ops
*ops
= info
->fbcon_par
;
2365 ops
->graphics
= ops
->save_graphics
;
2366 if (info
->fbops
->fb_debug_leave
)
2367 info
->fbops
->fb_debug_leave(info
);
2371 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2373 u8
*fontdata
= vc
->vc_font
.data
;
2374 u8
*data
= font
->data
;
2377 font
->width
= vc
->vc_font
.width
;
2378 font
->height
= vc
->vc_font
.height
;
2379 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2383 if (font
->width
<= 8) {
2384 j
= vc
->vc_font
.height
;
2385 for (i
= 0; i
< font
->charcount
; i
++) {
2386 memcpy(data
, fontdata
, j
);
2387 memset(data
+ j
, 0, 32 - j
);
2391 } else if (font
->width
<= 16) {
2392 j
= vc
->vc_font
.height
* 2;
2393 for (i
= 0; i
< font
->charcount
; i
++) {
2394 memcpy(data
, fontdata
, j
);
2395 memset(data
+ j
, 0, 64 - j
);
2399 } else if (font
->width
<= 24) {
2400 for (i
= 0; i
< font
->charcount
; i
++) {
2401 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2402 *data
++ = fontdata
[0];
2403 *data
++ = fontdata
[1];
2404 *data
++ = fontdata
[2];
2405 fontdata
+= sizeof(u32
);
2407 memset(data
, 0, 3 * (32 - j
));
2408 data
+= 3 * (32 - j
);
2411 j
= vc
->vc_font
.height
* 4;
2412 for (i
= 0; i
< font
->charcount
; i
++) {
2413 memcpy(data
, fontdata
, j
);
2414 memset(data
+ j
, 0, 128 - j
);
2422 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2423 const u8
* data
, int userfont
)
2425 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2426 struct fbcon_ops
*ops
= info
->fbcon_par
;
2427 struct display
*p
= &fb_display
[vc
->vc_num
];
2430 char *old_data
= NULL
;
2432 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2433 fbcon_set_origin(vc
);
2435 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2437 old_data
= vc
->vc_font
.data
;
2439 cnt
= FNTCHARCNT(data
);
2442 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2443 if ((p
->userfont
= userfont
))
2445 vc
->vc_font
.width
= w
;
2446 vc
->vc_font
.height
= h
;
2447 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2448 vc
->vc_hi_font_mask
= 0;
2449 if (vc
->vc_can_do_color
) {
2450 vc
->vc_complement_mask
>>= 1;
2451 vc
->vc_s_complement_mask
>>= 1;
2454 /* ++Edmund: reorder the attribute bits */
2455 if (vc
->vc_can_do_color
) {
2456 unsigned short *cp
=
2457 (unsigned short *) vc
->vc_origin
;
2458 int count
= vc
->vc_screenbuf_size
/ 2;
2460 for (; count
> 0; count
--, cp
++) {
2462 scr_writew(((c
& 0xfe00) >> 1) |
2465 c
= vc
->vc_video_erase_char
;
2466 vc
->vc_video_erase_char
=
2467 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2470 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2471 vc
->vc_hi_font_mask
= 0x100;
2472 if (vc
->vc_can_do_color
) {
2473 vc
->vc_complement_mask
<<= 1;
2474 vc
->vc_s_complement_mask
<<= 1;
2477 /* ++Edmund: reorder the attribute bits */
2479 unsigned short *cp
=
2480 (unsigned short *) vc
->vc_origin
;
2481 int count
= vc
->vc_screenbuf_size
/ 2;
2483 for (; count
> 0; count
--, cp
++) {
2484 unsigned short newc
;
2486 if (vc
->vc_can_do_color
)
2488 ((c
& 0xff00) << 1) | (c
&
2492 scr_writew(newc
, cp
);
2494 c
= vc
->vc_video_erase_char
;
2495 if (vc
->vc_can_do_color
) {
2496 vc
->vc_video_erase_char
=
2497 ((c
& 0xff00) << 1) | (c
& 0xff);
2500 vc
->vc_video_erase_char
= c
& ~0x100;
2508 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2509 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2512 vc_resize(vc
, cols
, rows
);
2513 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2514 fbcon_update_softback(vc
);
2515 } else if (CON_IS_VISIBLE(vc
)
2516 && vc
->vc_mode
== KD_TEXT
) {
2517 fbcon_clear_margins(vc
, 0);
2521 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2522 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2526 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2528 struct display
*od
= &fb_display
[con
];
2529 struct console_font
*f
= &vc
->vc_font
;
2531 if (od
->fontdata
== f
->data
)
2532 return 0; /* already the same font... */
2533 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2537 * User asked to set font; we are guaranteed that
2538 * a) width and height are in range 1..32
2539 * b) charcount does not exceed 512
2540 * but lets not assume that, since someone might someday want to use larger
2541 * fonts. And charcount of 512 is small for unicode support.
2543 * However, user space gives the font in 32 rows , regardless of
2544 * actual font height. So a new API is needed if support for larger fonts
2545 * is ever implemented.
2548 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2550 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2551 unsigned charcount
= font
->charcount
;
2552 int w
= font
->width
;
2553 int h
= font
->height
;
2556 u8
*new_data
, *data
= font
->data
;
2557 int pitch
= (font
->width
+7) >> 3;
2559 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2560 * If not this check should be changed to charcount < 256 */
2561 if (charcount
!= 256 && charcount
!= 512)
2564 /* Make sure drawing engine can handle the font */
2565 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2566 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2569 /* Make sure driver can handle the font length */
2570 if (fbcon_invalid_charcount(info
, charcount
))
2573 size
= h
* pitch
* charcount
;
2575 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2580 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2581 FNTSIZE(new_data
) = size
;
2582 FNTCHARCNT(new_data
) = charcount
;
2583 REFCOUNT(new_data
) = 0; /* usage counter */
2584 for (i
=0; i
< charcount
; i
++) {
2585 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2588 /* Since linux has a nice crc32 function use it for counting font
2590 csum
= crc32(0, new_data
, size
);
2592 FNTSUM(new_data
) = csum
;
2593 /* Check if the same font is on some other console already */
2594 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2595 struct vc_data
*tmp
= vc_cons
[i
].d
;
2597 if (fb_display
[i
].userfont
&&
2598 fb_display
[i
].fontdata
&&
2599 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2600 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2601 tmp
->vc_font
.width
== w
&&
2602 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2603 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2604 new_data
= (u8
*)fb_display
[i
].fontdata
;
2608 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2611 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2613 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2614 const struct font_desc
*f
;
2617 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2618 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2619 else if (!(f
= find_font(name
)))
2622 font
->width
= f
->width
;
2623 font
->height
= f
->height
;
2624 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2627 static u16 palette_red
[16];
2628 static u16 palette_green
[16];
2629 static u16 palette_blue
[16];
2631 static struct fb_cmap palette_cmap
= {
2632 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2635 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2637 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2641 if (fbcon_is_inactive(vc
, info
))
2644 if (!CON_IS_VISIBLE(vc
))
2647 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2649 for (i
= j
= 0; i
< 16; i
++) {
2651 val
= vc
->vc_palette
[j
++];
2652 palette_red
[k
] = (val
<< 8) | val
;
2653 val
= vc
->vc_palette
[j
++];
2654 palette_green
[k
] = (val
<< 8) | val
;
2655 val
= vc
->vc_palette
[j
++];
2656 palette_blue
[k
] = (val
<< 8) | val
;
2658 palette_cmap
.len
= 16;
2659 palette_cmap
.start
= 0;
2661 * If framebuffer is capable of less than 16 colors,
2662 * use default palette of fbcon.
2665 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2667 return fb_set_cmap(&palette_cmap
, info
);
2670 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2675 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2676 return (u16
*) (vc
->vc_origin
+ offset
);
2677 line
= offset
/ vc
->vc_size_row
;
2678 if (line
>= softback_lines
)
2679 return (u16
*) (vc
->vc_origin
+ offset
-
2680 softback_lines
* vc
->vc_size_row
);
2681 p
= softback_curr
+ offset
;
2682 if (p
>= softback_end
)
2683 p
+= softback_buf
- softback_end
;
2687 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2693 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2694 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2696 x
= offset
% vc
->vc_cols
;
2697 y
= offset
/ vc
->vc_cols
;
2698 if (vc
->vc_num
== fg_console
)
2699 y
+= softback_lines
;
2700 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2701 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2702 unsigned long offset
= pos
- softback_curr
;
2704 if (pos
< softback_curr
)
2705 offset
+= softback_end
- softback_buf
;
2707 x
= offset
% vc
->vc_cols
;
2708 y
= offset
/ vc
->vc_cols
;
2709 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2710 if (ret
== softback_end
)
2712 if (ret
== softback_in
)
2713 ret
= vc
->vc_origin
;
2715 /* Should not happen */
2717 ret
= vc
->vc_origin
;
2726 /* As we might be inside of softback, we may work with non-contiguous buffer,
2727 that's why we have to use a separate routine. */
2728 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2731 u16 a
= scr_readw(p
);
2732 if (!vc
->vc_can_do_color
)
2734 else if (vc
->vc_hi_font_mask
== 0x100)
2735 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2736 (((a
) & 0x0e00) << 4);
2738 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2739 (((a
) & 0x0700) << 4);
2741 if (p
== (u16
*) softback_end
)
2742 p
= (u16
*) softback_buf
;
2743 if (p
== (u16
*) softback_in
)
2744 p
= (u16
*) vc
->vc_origin
;
2748 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2750 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2751 struct fbcon_ops
*ops
= info
->fbcon_par
;
2752 struct display
*disp
= &fb_display
[fg_console
];
2753 int offset
, limit
, scrollback_old
;
2756 if (vc
->vc_num
!= fg_console
)
2758 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2760 if (logo_shown
>= 0) {
2761 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2763 if (conp2
->vc_top
== logo_lines
2764 && conp2
->vc_bottom
== conp2
->vc_rows
)
2766 if (logo_shown
== vc
->vc_num
) {
2772 logo_lines
* vc
->vc_size_row
;
2773 for (i
= 0; i
< logo_lines
; i
++) {
2774 if (p
== softback_top
)
2776 if (p
== softback_buf
)
2778 p
-= vc
->vc_size_row
;
2779 q
-= vc
->vc_size_row
;
2780 scr_memcpyw((u16
*) q
, (u16
*) p
,
2783 softback_in
= softback_curr
= p
;
2784 update_region(vc
, vc
->vc_origin
,
2785 logo_lines
* vc
->vc_cols
);
2787 logo_shown
= FBCON_LOGO_CANSHOW
;
2789 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2790 fbcon_redraw_softback(vc
, disp
, lines
);
2791 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2795 if (!scrollback_phys_max
)
2798 scrollback_old
= scrollback_current
;
2799 scrollback_current
-= lines
;
2800 if (scrollback_current
< 0)
2801 scrollback_current
= 0;
2802 else if (scrollback_current
> scrollback_max
)
2803 scrollback_current
= scrollback_max
;
2804 if (scrollback_current
== scrollback_old
)
2807 if (fbcon_is_inactive(vc
, info
))
2810 fbcon_cursor(vc
, CM_ERASE
);
2812 offset
= disp
->yscroll
- scrollback_current
;
2813 limit
= disp
->vrows
;
2814 switch (disp
->scrollmode
) {
2815 case SCROLL_WRAP_MOVE
:
2816 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2818 case SCROLL_PAN_MOVE
:
2819 case SCROLL_PAN_REDRAW
:
2820 limit
-= vc
->vc_rows
;
2821 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2826 else if (offset
>= limit
)
2829 ops
->var
.xoffset
= 0;
2830 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2831 ops
->update_start(info
);
2833 if (!scrollback_current
)
2834 fbcon_cursor(vc
, CM_DRAW
);
2838 static int fbcon_set_origin(struct vc_data
*vc
)
2841 fbcon_scrolldelta(vc
, softback_lines
);
2845 static void fbcon_suspended(struct fb_info
*info
)
2847 struct vc_data
*vc
= NULL
;
2848 struct fbcon_ops
*ops
= info
->fbcon_par
;
2850 if (!ops
|| ops
->currcon
< 0)
2852 vc
= vc_cons
[ops
->currcon
].d
;
2854 /* Clear cursor, restore saved data */
2855 fbcon_cursor(vc
, CM_ERASE
);
2858 static void fbcon_resumed(struct fb_info
*info
)
2861 struct fbcon_ops
*ops
= info
->fbcon_par
;
2863 if (!ops
|| ops
->currcon
< 0)
2865 vc
= vc_cons
[ops
->currcon
].d
;
2870 static void fbcon_modechanged(struct fb_info
*info
)
2872 struct fbcon_ops
*ops
= info
->fbcon_par
;
2877 if (!ops
|| ops
->currcon
< 0)
2879 vc
= vc_cons
[ops
->currcon
].d
;
2880 if (vc
->vc_mode
!= KD_TEXT
||
2881 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2884 p
= &fb_display
[vc
->vc_num
];
2885 set_blitting_type(vc
, info
);
2887 if (CON_IS_VISIBLE(vc
)) {
2888 var_to_display(p
, &info
->var
, info
);
2889 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2890 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2891 cols
/= vc
->vc_font
.width
;
2892 rows
/= vc
->vc_font
.height
;
2893 vc_resize(vc
, cols
, rows
);
2894 updatescrollmode(p
, info
, vc
);
2896 scrollback_current
= 0;
2898 if (!fbcon_is_inactive(vc
, info
)) {
2899 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2900 ops
->update_start(info
);
2903 fbcon_set_palette(vc
, color_table
);
2906 fbcon_update_softback(vc
);
2910 static void fbcon_set_all_vcs(struct fb_info
*info
)
2912 struct fbcon_ops
*ops
= info
->fbcon_par
;
2915 int i
, rows
, cols
, fg
= -1;
2917 if (!ops
|| ops
->currcon
< 0)
2920 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2922 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2923 registered_fb
[con2fb_map
[i
]] != info
)
2926 if (CON_IS_VISIBLE(vc
)) {
2931 p
= &fb_display
[vc
->vc_num
];
2932 set_blitting_type(vc
, info
);
2933 var_to_display(p
, &info
->var
, info
);
2934 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2935 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2936 cols
/= vc
->vc_font
.width
;
2937 rows
/= vc
->vc_font
.height
;
2938 vc_resize(vc
, cols
, rows
);
2942 fbcon_modechanged(info
);
2945 static int fbcon_mode_deleted(struct fb_info
*info
,
2946 struct fb_videomode
*mode
)
2948 struct fb_info
*fb_info
;
2950 int i
, j
, found
= 0;
2952 /* before deletion, ensure that mode is not in use */
2953 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2957 fb_info
= registered_fb
[j
];
2958 if (fb_info
!= info
)
2963 if (fb_mode_is_equal(p
->mode
, mode
)) {
2971 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2972 static int fbcon_unbind(void)
2976 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2980 fbcon_has_console_bind
= 0;
2985 static inline int fbcon_unbind(void)
2989 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2991 static int fbcon_fb_unbind(int idx
)
2993 int i
, new_idx
= -1, ret
= 0;
2995 if (!fbcon_has_console_bind
)
2998 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2999 if (con2fb_map
[i
] != idx
&&
3000 con2fb_map
[i
] != -1) {
3006 if (new_idx
!= -1) {
3007 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3008 if (con2fb_map
[i
] == idx
)
3009 set_con2fb_map(i
, new_idx
, 0);
3012 ret
= fbcon_unbind();
3017 static int fbcon_fb_unregistered(struct fb_info
*info
)
3022 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3023 if (con2fb_map
[i
] == idx
)
3027 if (idx
== info_idx
) {
3030 for (i
= 0; i
< FB_MAX
; i
++) {
3031 if (registered_fb
[i
] != NULL
) {
3038 if (info_idx
!= -1) {
3039 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3040 if (con2fb_map
[i
] == -1)
3041 con2fb_map
[i
] = info_idx
;
3045 if (primary_device
== idx
)
3046 primary_device
= -1;
3048 if (!num_registered_fb
)
3049 unregister_con_driver(&fb_con
);
3054 static void fbcon_remap_all(int idx
)
3057 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3058 set_con2fb_map(i
, idx
, 0);
3060 if (con_is_bound(&fb_con
)) {
3061 printk(KERN_INFO
"fbcon: Remapping primary device, "
3062 "fb%i, to tty %i-%i\n", idx
,
3063 first_fb_vc
+ 1, last_fb_vc
+ 1);
3068 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3069 static void fbcon_select_primary(struct fb_info
*info
)
3071 if (!map_override
&& primary_device
== -1 &&
3072 fb_is_primary_device(info
)) {
3075 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3076 info
->fix
.id
, info
->node
);
3077 primary_device
= info
->node
;
3079 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3080 con2fb_map_boot
[i
] = primary_device
;
3082 if (con_is_bound(&fb_con
)) {
3083 printk(KERN_INFO
"fbcon: Remapping primary device, "
3084 "fb%i, to tty %i-%i\n", info
->node
,
3085 first_fb_vc
+ 1, last_fb_vc
+ 1);
3086 info_idx
= primary_device
;
3092 static inline void fbcon_select_primary(struct fb_info
*info
)
3096 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3098 static int fbcon_fb_registered(struct fb_info
*info
)
3100 int ret
= 0, i
, idx
;
3103 fbcon_select_primary(info
);
3105 if (info_idx
== -1) {
3106 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3107 if (con2fb_map_boot
[i
] == idx
) {
3114 ret
= fbcon_takeover(1);
3116 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3117 if (con2fb_map_boot
[i
] == idx
)
3118 set_con2fb_map(i
, idx
, 0);
3125 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3127 struct fbcon_ops
*ops
= info
->fbcon_par
;
3130 if (!ops
|| ops
->currcon
< 0)
3133 vc
= vc_cons
[ops
->currcon
].d
;
3134 if (vc
->vc_mode
!= KD_TEXT
||
3135 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3138 if (CON_IS_VISIBLE(vc
)) {
3142 do_unblank_screen(0);
3144 ops
->blank_state
= blank
;
3147 static void fbcon_new_modelist(struct fb_info
*info
)
3151 struct fb_var_screeninfo var
;
3152 const struct fb_videomode
*mode
;
3154 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3155 if (registered_fb
[con2fb_map
[i
]] != info
)
3157 if (!fb_display
[i
].mode
)
3160 display_to_var(&var
, &fb_display
[i
]);
3161 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3163 fb_videomode_to_var(&var
, mode
);
3164 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3168 static void fbcon_get_requirement(struct fb_info
*info
,
3169 struct fb_blit_caps
*caps
)
3177 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3179 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3180 info
->node
== con2fb_map
[i
]) {
3182 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3183 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3184 charcnt
= (p
->userfont
) ?
3185 FNTCHARCNT(p
->fontdata
) : 256;
3186 if (caps
->len
< charcnt
)
3187 caps
->len
= charcnt
;
3191 vc
= vc_cons
[fg_console
].d
;
3193 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3194 info
->node
== con2fb_map
[fg_console
]) {
3195 p
= &fb_display
[fg_console
];
3196 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3197 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3198 caps
->len
= (p
->userfont
) ?
3199 FNTCHARCNT(p
->fontdata
) : 256;
3204 static int fbcon_event_notify(struct notifier_block
*self
,
3205 unsigned long action
, void *data
)
3207 struct fb_event
*event
= data
;
3208 struct fb_info
*info
= event
->info
;
3209 struct fb_videomode
*mode
;
3210 struct fb_con2fbmap
*con2fb
;
3211 struct fb_blit_caps
*caps
;
3215 * ignore all events except driver registration and deregistration
3216 * if fbcon is not active
3218 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3219 action
== FB_EVENT_FB_UNREGISTERED
))
3223 case FB_EVENT_SUSPEND
:
3224 fbcon_suspended(info
);
3226 case FB_EVENT_RESUME
:
3227 fbcon_resumed(info
);
3229 case FB_EVENT_MODE_CHANGE
:
3230 fbcon_modechanged(info
);
3232 case FB_EVENT_MODE_CHANGE_ALL
:
3233 fbcon_set_all_vcs(info
);
3235 case FB_EVENT_MODE_DELETE
:
3237 ret
= fbcon_mode_deleted(info
, mode
);
3239 case FB_EVENT_FB_UNBIND
:
3241 ret
= fbcon_fb_unbind(idx
);
3243 case FB_EVENT_FB_REGISTERED
:
3244 ret
= fbcon_fb_registered(info
);
3246 case FB_EVENT_FB_UNREGISTERED
:
3247 ret
= fbcon_fb_unregistered(info
);
3249 case FB_EVENT_SET_CONSOLE_MAP
:
3250 con2fb
= event
->data
;
3251 ret
= set_con2fb_map(con2fb
->console
- 1,
3252 con2fb
->framebuffer
, 1);
3254 case FB_EVENT_GET_CONSOLE_MAP
:
3255 con2fb
= event
->data
;
3256 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3258 case FB_EVENT_BLANK
:
3259 fbcon_fb_blanked(info
, *(int *)event
->data
);
3261 case FB_EVENT_NEW_MODELIST
:
3262 fbcon_new_modelist(info
);
3264 case FB_EVENT_GET_REQ
:
3266 fbcon_get_requirement(info
, caps
);
3268 case FB_EVENT_REMAP_ALL_CONSOLE
:
3270 fbcon_remap_all(idx
);
3278 * The console `switch' structure for the frame buffer based console
3281 static const struct consw fb_con
= {
3282 .owner
= THIS_MODULE
,
3283 .con_startup
= fbcon_startup
,
3284 .con_init
= fbcon_init
,
3285 .con_deinit
= fbcon_deinit
,
3286 .con_clear
= fbcon_clear
,
3287 .con_putc
= fbcon_putc
,
3288 .con_putcs
= fbcon_putcs
,
3289 .con_cursor
= fbcon_cursor
,
3290 .con_scroll
= fbcon_scroll
,
3291 .con_bmove
= fbcon_bmove
,
3292 .con_switch
= fbcon_switch
,
3293 .con_blank
= fbcon_blank
,
3294 .con_font_set
= fbcon_set_font
,
3295 .con_font_get
= fbcon_get_font
,
3296 .con_font_default
= fbcon_set_def_font
,
3297 .con_font_copy
= fbcon_copy_font
,
3298 .con_set_palette
= fbcon_set_palette
,
3299 .con_scrolldelta
= fbcon_scrolldelta
,
3300 .con_set_origin
= fbcon_set_origin
,
3301 .con_invert_region
= fbcon_invert_region
,
3302 .con_screen_pos
= fbcon_screen_pos
,
3303 .con_getxy
= fbcon_getxy
,
3304 .con_resize
= fbcon_resize
,
3305 .con_debug_enter
= fbcon_debug_enter
,
3306 .con_debug_leave
= fbcon_debug_leave
,
3309 static struct notifier_block fbcon_event_notifier
= {
3310 .notifier_call
= fbcon_event_notify
,
3313 static ssize_t
store_rotate(struct device
*device
,
3314 struct device_attribute
*attr
, const char *buf
,
3317 struct fb_info
*info
;
3321 if (fbcon_has_exited
)
3325 idx
= con2fb_map
[fg_console
];
3327 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3330 info
= registered_fb
[idx
];
3331 rotate
= simple_strtoul(buf
, last
, 0);
3332 fbcon_rotate(info
, rotate
);
3338 static ssize_t
store_rotate_all(struct device
*device
,
3339 struct device_attribute
*attr
,const char *buf
,
3342 struct fb_info
*info
;
3346 if (fbcon_has_exited
)
3350 idx
= con2fb_map
[fg_console
];
3352 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3355 info
= registered_fb
[idx
];
3356 rotate
= simple_strtoul(buf
, last
, 0);
3357 fbcon_rotate_all(info
, rotate
);
3363 static ssize_t
show_rotate(struct device
*device
,
3364 struct device_attribute
*attr
,char *buf
)
3366 struct fb_info
*info
;
3367 int rotate
= 0, idx
;
3369 if (fbcon_has_exited
)
3373 idx
= con2fb_map
[fg_console
];
3375 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3378 info
= registered_fb
[idx
];
3379 rotate
= fbcon_get_rotate(info
);
3382 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3385 static ssize_t
show_cursor_blink(struct device
*device
,
3386 struct device_attribute
*attr
, char *buf
)
3388 struct fb_info
*info
;
3389 struct fbcon_ops
*ops
;
3390 int idx
, blink
= -1;
3392 if (fbcon_has_exited
)
3396 idx
= con2fb_map
[fg_console
];
3398 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3401 info
= registered_fb
[idx
];
3402 ops
= info
->fbcon_par
;
3407 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3410 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3413 static ssize_t
store_cursor_blink(struct device
*device
,
3414 struct device_attribute
*attr
,
3415 const char *buf
, size_t count
)
3417 struct fb_info
*info
;
3421 if (fbcon_has_exited
)
3425 idx
= con2fb_map
[fg_console
];
3427 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3430 info
= registered_fb
[idx
];
3432 if (!info
->fbcon_par
)
3435 blink
= simple_strtoul(buf
, last
, 0);
3438 fbcon_cursor_noblink
= 0;
3439 fbcon_add_cursor_timer(info
);
3441 fbcon_cursor_noblink
= 1;
3442 fbcon_del_cursor_timer(info
);
3450 static struct device_attribute device_attrs
[] = {
3451 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3452 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3453 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3454 store_cursor_blink
),
3457 static int fbcon_init_device(void)
3461 fbcon_has_sysfs
= 1;
3463 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3464 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3472 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3474 fbcon_has_sysfs
= 0;
3480 static void fbcon_start(void)
3482 if (num_registered_fb
) {
3487 for (i
= 0; i
< FB_MAX
; i
++) {
3488 if (registered_fb
[i
] != NULL
) {
3499 static void fbcon_exit(void)
3501 struct fb_info
*info
;
3504 if (fbcon_has_exited
)
3507 kfree((void *)softback_buf
);
3510 for (i
= 0; i
< FB_MAX
; i
++) {
3514 info
= registered_fb
[i
];
3519 if (info
->queue
.func
)
3520 pending
= cancel_work_sync(&info
->queue
);
3521 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3524 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3525 if (con2fb_map
[j
] == i
)
3530 if (info
->fbops
->fb_release
)
3531 info
->fbops
->fb_release(info
, 0);
3532 module_put(info
->fbops
->owner
);
3534 if (info
->fbcon_par
) {
3535 struct fbcon_ops
*ops
= info
->fbcon_par
;
3537 fbcon_del_cursor_timer(info
);
3538 kfree(ops
->cursor_src
);
3539 kfree(info
->fbcon_par
);
3540 info
->fbcon_par
= NULL
;
3543 if (info
->queue
.func
== fb_flashcursor
)
3544 info
->queue
.func
= NULL
;
3548 fbcon_has_exited
= 1;
3551 static int __init
fb_console_init(void)
3556 fb_register_client(&fbcon_event_notifier
);
3557 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3560 if (IS_ERR(fbcon_device
)) {
3561 printk(KERN_WARNING
"Unable to create device "
3562 "for fbcon; errno = %ld\n",
3563 PTR_ERR(fbcon_device
));
3564 fbcon_device
= NULL
;
3566 fbcon_init_device();
3568 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3576 module_init(fb_console_init
);
3580 static void __exit
fbcon_deinit_device(void)
3584 if (fbcon_has_sysfs
) {
3585 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3586 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3588 fbcon_has_sysfs
= 0;
3592 static void __exit
fb_console_exit(void)
3595 fb_unregister_client(&fbcon_event_notifier
);
3596 fbcon_deinit_device();
3597 device_destroy(fb_class
, MKDEV(0, 0));
3600 unregister_con_driver(&fb_con
);
3603 module_exit(fb_console_exit
);
3607 MODULE_LICENSE("GPL");