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/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
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 */
132 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
133 static bool deferred_takeover
= true;
135 #define deferred_takeover false
139 static char fontname
[40];
141 /* current fb_info */
142 static int info_idx
= -1;
144 /* console rotation */
145 static int initial_rotation
= -1;
146 static int fbcon_has_sysfs
;
147 static int margin_color
;
149 static const struct consw fb_con
;
151 #define CM_SOFTBACK (8)
153 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
155 static int fbcon_set_origin(struct vc_data
*);
157 static int fbcon_cursor_noblink
;
159 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
162 * Interface used by the world
165 static const char *fbcon_startup(void);
166 static void fbcon_init(struct vc_data
*vc
, int init
);
167 static void fbcon_deinit(struct vc_data
*vc
);
168 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
170 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
171 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
172 int count
, int ypos
, int xpos
);
173 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
174 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
175 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
176 int height
, int width
);
177 static int fbcon_switch(struct vc_data
*vc
);
178 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
179 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
);
184 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
185 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
186 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
187 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
188 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
189 int dy
, int dx
, int height
, int width
, u_int y_break
);
190 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
192 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
193 int line
, int count
, int dy
);
194 static void fbcon_modechanged(struct fb_info
*info
);
195 static void fbcon_set_all_vcs(struct fb_info
*info
);
196 static void fbcon_start(void);
197 static void fbcon_exit(void);
198 static struct device
*fbcon_device
;
200 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
201 static inline void fbcon_set_rotation(struct fb_info
*info
)
203 struct fbcon_ops
*ops
= info
->fbcon_par
;
205 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
206 ops
->p
->con_rotate
< 4)
207 ops
->rotate
= ops
->p
->con_rotate
;
212 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
214 struct fbcon_ops
*ops
= info
->fbcon_par
;
215 struct fb_info
*fb_info
;
217 if (!ops
|| ops
->currcon
== -1)
220 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
222 if (info
== fb_info
) {
223 struct display
*p
= &fb_display
[ops
->currcon
];
226 p
->con_rotate
= rotate
;
230 fbcon_modechanged(info
);
234 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
236 struct fbcon_ops
*ops
= info
->fbcon_par
;
241 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
244 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
246 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
247 registered_fb
[con2fb_map
[i
]] != info
)
250 p
= &fb_display
[vc
->vc_num
];
251 p
->con_rotate
= rotate
;
254 fbcon_set_all_vcs(info
);
257 static inline void fbcon_set_rotation(struct fb_info
*info
)
259 struct fbcon_ops
*ops
= info
->fbcon_par
;
261 ops
->rotate
= FB_ROTATE_UR
;
264 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
269 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
273 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
275 static int fbcon_get_rotate(struct fb_info
*info
)
277 struct fbcon_ops
*ops
= info
->fbcon_par
;
279 return (ops
) ? ops
->rotate
: 0;
282 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
284 struct fbcon_ops
*ops
= info
->fbcon_par
;
286 return (info
->state
!= FBINFO_STATE_RUNNING
||
287 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
) &&
288 !vt_force_oops_output(vc
);
291 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
294 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
297 if (console_blanked
) {
298 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
300 c
= vc
->vc_video_erase_char
& charmask
;
304 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
305 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
310 int col
= mono_col(info
);
312 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
313 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
318 color
= (is_fg
) ? fg
: bg
;
323 * Scale down 16-colors to 4 colors. Default 4-color palette
324 * is grayscale. However, simply dividing the values by 4
325 * will not work, as colors 1, 2 and 3 will be scaled-down
326 * to zero rendering them invisible. So empirically convert
327 * colors to a sane 4-level grayscale.
331 color
= 0; /* black */
334 color
= 2; /* white */
337 color
= 1; /* gray */
340 color
= 3; /* intense white */
346 * Last 8 entries of default 16-color palette is a more intense
347 * version of the first 8 (i.e., same chrominance, different
358 static void fbcon_update_softback(struct vc_data
*vc
)
360 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
363 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
365 /* Smaller scrollback makes no sense, and 0 would screw
366 the operation totally */
370 static void fb_flashcursor(struct work_struct
*work
)
372 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
373 struct fbcon_ops
*ops
= info
->fbcon_par
;
374 struct vc_data
*vc
= NULL
;
379 /* FIXME: we should sort out the unbind locking instead */
380 /* instead we just fail to flash the cursor if we can't get
381 * the lock instead of blocking fbcon deinit */
382 ret
= console_trylock();
386 if (ops
&& ops
->currcon
!= -1)
387 vc
= vc_cons
[ops
->currcon
].d
;
389 if (!vc
|| !con_is_visible(vc
) ||
390 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
396 c
= scr_readw((u16
*) vc
->vc_pos
);
397 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
399 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
400 get_color(vc
, info
, c
, 0));
404 static void cursor_timer_handler(struct timer_list
*t
)
406 struct fbcon_ops
*ops
= from_timer(ops
, t
, cursor_timer
);
407 struct fb_info
*info
= ops
->info
;
409 queue_work(system_power_efficient_wq
, &info
->queue
);
410 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
413 static void fbcon_add_cursor_timer(struct fb_info
*info
)
415 struct fbcon_ops
*ops
= info
->fbcon_par
;
417 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
418 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
419 !fbcon_cursor_noblink
) {
420 if (!info
->queue
.func
)
421 INIT_WORK(&info
->queue
, fb_flashcursor
);
423 timer_setup(&ops
->cursor_timer
, cursor_timer_handler
, 0);
424 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
425 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
429 static void fbcon_del_cursor_timer(struct fb_info
*info
)
431 struct fbcon_ops
*ops
= info
->fbcon_par
;
433 if (info
->queue
.func
== fb_flashcursor
&&
434 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
435 del_timer_sync(&ops
->cursor_timer
);
436 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
441 static int __init
fb_console_setup(char *this_opt
)
446 if (!this_opt
|| !*this_opt
)
449 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
450 if (!strncmp(options
, "font:", 5)) {
451 strlcpy(fontname
, options
+ 5, sizeof(fontname
));
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;
466 if (!strncmp(options
, "map:", 4)) {
469 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
473 (options
[j
++]-'0') % FB_MAX
;
476 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;
493 if (!strncmp(options
, "rotate:", 7)) {
496 initial_rotation
= simple_strtoul(options
, &options
, 0);
497 if (initial_rotation
> 3)
498 initial_rotation
= 0;
502 if (!strncmp(options
, "margin:", 7)) {
505 margin_color
= simple_strtoul(options
, &options
, 0);
508 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
509 if (!strcmp(options
, "nodefer")) {
510 deferred_takeover
= false;
518 __setup("fbcon=", fb_console_setup
);
521 static int search_fb_in_map(int idx
)
525 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
526 if (con2fb_map
[i
] == idx
)
532 static int search_for_mapped_con(void)
536 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
537 if (con2fb_map
[i
] != -1)
543 static int do_fbcon_takeover(int show_logo
)
547 if (!num_registered_fb
)
551 logo_shown
= FBCON_LOGO_DONTSHOW
;
553 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
554 con2fb_map
[i
] = info_idx
;
556 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
560 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
564 fbcon_has_console_bind
= 1;
571 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
572 int cols
, int rows
, int new_cols
, int new_rows
)
574 logo_shown
= FBCON_LOGO_DONTSHOW
;
577 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
578 int cols
, int rows
, int new_cols
, int new_rows
)
580 /* Need to make room for the logo */
581 struct fbcon_ops
*ops
= info
->fbcon_par
;
582 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
583 unsigned short *save
= NULL
, *r
, *q
;
586 if (info
->fbops
->owner
) {
587 logo_shown
= FBCON_LOGO_DONTSHOW
;
592 * remove underline attribute from erase character
593 * if black and white framebuffer.
595 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
597 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
598 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
599 q
= (unsigned short *) (vc
->vc_origin
+
600 vc
->vc_size_row
* rows
);
601 step
= logo_lines
* cols
;
602 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
603 if (scr_readw(r
) != vc
->vc_video_erase_char
)
605 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
606 save
= kmalloc(array3_size(logo_lines
, new_cols
, 2),
609 int i
= cols
< new_cols
? cols
: new_cols
;
610 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
612 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
613 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
618 /* We can scroll screen down */
620 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
621 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
626 if (vc
->vc_y
+ logo_lines
>= rows
)
627 lines
= rows
- vc
->vc_y
- 1;
631 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
634 scr_memsetw((unsigned short *) vc
->vc_origin
,
636 vc
->vc_size_row
* logo_lines
);
638 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
639 fbcon_clear_margins(vc
, 0);
644 q
= (unsigned short *) (vc
->vc_origin
+
647 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
648 vc
->vc_y
+= logo_lines
;
649 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
653 if (logo_lines
> vc
->vc_bottom
) {
654 logo_shown
= FBCON_LOGO_CANSHOW
;
656 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
657 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
658 logo_shown
= FBCON_LOGO_DRAW
;
659 vc
->vc_top
= logo_lines
;
664 #ifdef CONFIG_FB_TILEBLITTING
665 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
667 struct fbcon_ops
*ops
= info
->fbcon_par
;
669 ops
->p
= &fb_display
[vc
->vc_num
];
671 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
672 fbcon_set_tileops(vc
, info
);
674 fbcon_set_rotation(info
);
675 fbcon_set_bitops(ops
);
679 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
683 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
684 info
->tileops
->fb_get_tilemax(info
) < charcount
)
690 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
692 struct fbcon_ops
*ops
= info
->fbcon_par
;
694 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
695 ops
->p
= &fb_display
[vc
->vc_num
];
696 fbcon_set_rotation(info
);
697 fbcon_set_bitops(ops
);
700 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
705 #endif /* CONFIG_MISC_TILEBLITTING */
708 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
709 int unit
, int oldidx
)
711 struct fbcon_ops
*ops
= NULL
;
714 if (!try_module_get(info
->fbops
->owner
))
717 if (!err
&& info
->fbops
->fb_open
&&
718 info
->fbops
->fb_open(info
, 0))
722 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
728 ops
->cur_blink_jiffies
= HZ
/ 5;
730 info
->fbcon_par
= ops
;
733 set_blitting_type(vc
, info
);
737 con2fb_map
[unit
] = oldidx
;
738 module_put(info
->fbops
->owner
);
744 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
745 struct fb_info
*newinfo
, int unit
,
746 int oldidx
, int found
)
748 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
751 if (oldinfo
->fbops
->fb_release
&&
752 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
753 con2fb_map
[unit
] = oldidx
;
754 if (!found
&& newinfo
->fbops
->fb_release
)
755 newinfo
->fbops
->fb_release(newinfo
, 0);
757 module_put(newinfo
->fbops
->owner
);
762 fbcon_del_cursor_timer(oldinfo
);
763 kfree(ops
->cursor_state
.mask
);
764 kfree(ops
->cursor_data
);
765 kfree(ops
->cursor_src
);
766 kfree(ops
->fontbuffer
);
767 kfree(oldinfo
->fbcon_par
);
768 oldinfo
->fbcon_par
= NULL
;
769 module_put(oldinfo
->fbops
->owner
);
771 If oldinfo and newinfo are driving the same hardware,
772 the fb_release() method of oldinfo may attempt to
773 restore the hardware state. This will leave the
774 newinfo in an undefined state. Thus, a call to
775 fb_set_par() may be needed for the newinfo.
777 if (newinfo
&& newinfo
->fbops
->fb_set_par
) {
778 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
781 printk(KERN_ERR
"con2fb_release_oldinfo: "
782 "detected unhandled fb_set_par error, "
783 "error code %d\n", ret
);
790 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
791 int unit
, int show_logo
)
793 struct fbcon_ops
*ops
= info
->fbcon_par
;
796 ops
->currcon
= fg_console
;
798 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
799 ret
= info
->fbops
->fb_set_par(info
);
802 printk(KERN_ERR
"con2fb_init_display: detected "
803 "unhandled fb_set_par error, "
804 "error code %d\n", ret
);
807 ops
->flags
|= FBCON_FLAGS_INIT
;
809 fbcon_set_disp(info
, &info
->var
, unit
);
812 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
813 struct fb_info
*fg_info
=
814 registered_fb
[con2fb_map
[fg_console
]];
816 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
817 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
821 update_screen(vc_cons
[fg_console
].d
);
825 * set_con2fb_map - map console to frame buffer device
826 * @unit: virtual console number to map
827 * @newidx: frame buffer index to map virtual console to
828 * @user: user request
830 * Maps a virtual console @unit to a frame buffer device
833 * This should be called with the console lock held.
835 static int set_con2fb_map(int unit
, int newidx
, int user
)
837 struct vc_data
*vc
= vc_cons
[unit
].d
;
838 int oldidx
= con2fb_map
[unit
];
839 struct fb_info
*info
= registered_fb
[newidx
];
840 struct fb_info
*oldinfo
= NULL
;
843 WARN_CONSOLE_UNLOCKED();
845 if (oldidx
== newidx
)
851 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
853 return do_fbcon_takeover(0);
857 oldinfo
= registered_fb
[oldidx
];
859 found
= search_fb_in_map(newidx
);
861 con2fb_map
[unit
] = newidx
;
863 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
867 * If old fb is not mapped to any of the consoles,
868 * fbcon should release it.
870 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
871 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
875 int show_logo
= (fg_console
== 0 && !user
&&
876 logo_shown
!= FBCON_LOGO_DONTSHOW
);
879 fbcon_add_cursor_timer(info
);
880 con2fb_map_boot
[unit
] = newidx
;
881 con2fb_init_display(vc
, info
, unit
, show_logo
);
884 if (!search_fb_in_map(info_idx
))
891 * Low Level Operations
893 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
894 static int var_to_display(struct display
*disp
,
895 struct fb_var_screeninfo
*var
,
896 struct fb_info
*info
)
898 disp
->xres_virtual
= var
->xres_virtual
;
899 disp
->yres_virtual
= var
->yres_virtual
;
900 disp
->bits_per_pixel
= var
->bits_per_pixel
;
901 disp
->grayscale
= var
->grayscale
;
902 disp
->nonstd
= var
->nonstd
;
903 disp
->accel_flags
= var
->accel_flags
;
904 disp
->height
= var
->height
;
905 disp
->width
= var
->width
;
906 disp
->red
= var
->red
;
907 disp
->green
= var
->green
;
908 disp
->blue
= var
->blue
;
909 disp
->transp
= var
->transp
;
910 disp
->rotate
= var
->rotate
;
911 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
912 if (disp
->mode
== NULL
)
913 /* This should not happen */
918 static void display_to_var(struct fb_var_screeninfo
*var
,
919 struct display
*disp
)
921 fb_videomode_to_var(var
, disp
->mode
);
922 var
->xres_virtual
= disp
->xres_virtual
;
923 var
->yres_virtual
= disp
->yres_virtual
;
924 var
->bits_per_pixel
= disp
->bits_per_pixel
;
925 var
->grayscale
= disp
->grayscale
;
926 var
->nonstd
= disp
->nonstd
;
927 var
->accel_flags
= disp
->accel_flags
;
928 var
->height
= disp
->height
;
929 var
->width
= disp
->width
;
930 var
->red
= disp
->red
;
931 var
->green
= disp
->green
;
932 var
->blue
= disp
->blue
;
933 var
->transp
= disp
->transp
;
934 var
->rotate
= disp
->rotate
;
937 static const char *fbcon_startup(void)
939 const char *display_desc
= "frame buffer device";
940 struct display
*p
= &fb_display
[fg_console
];
941 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
942 const struct font_desc
*font
= NULL
;
943 struct module
*owner
;
944 struct fb_info
*info
= NULL
;
945 struct fbcon_ops
*ops
;
949 * If num_registered_fb is zero, this is a call for the dummy part.
950 * The frame buffer devices weren't initialized yet.
952 if (!num_registered_fb
|| info_idx
== -1)
955 * Instead of blindly using registered_fb[0], we use info_idx, set by
958 info
= registered_fb
[info_idx
];
962 owner
= info
->fbops
->owner
;
963 if (!try_module_get(owner
))
965 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
970 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
978 ops
->cur_rotate
= -1;
979 ops
->cur_blink_jiffies
= HZ
/ 5;
981 info
->fbcon_par
= ops
;
983 p
->con_rotate
= initial_rotation
;
984 if (p
->con_rotate
== -1)
985 p
->con_rotate
= info
->fbcon_rotate_hint
;
986 if (p
->con_rotate
== -1)
987 p
->con_rotate
= FB_ROTATE_UR
;
989 set_blitting_type(vc
, info
);
991 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
992 if (fbcon_softback_size
) {
996 kmalloc(fbcon_softback_size
,
999 fbcon_softback_size
= 0;
1005 kfree((void *) softback_buf
);
1011 softback_in
= softback_top
= softback_curr
=
1016 /* Setup default font */
1017 if (!p
->fontdata
&& !vc
->vc_font
.data
) {
1018 if (!fontname
[0] || !(font
= find_font(fontname
)))
1019 font
= get_default_font(info
->var
.xres
,
1021 info
->pixmap
.blit_x
,
1022 info
->pixmap
.blit_y
);
1023 vc
->vc_font
.width
= font
->width
;
1024 vc
->vc_font
.height
= font
->height
;
1025 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1026 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1028 p
->fontdata
= vc
->vc_font
.data
;
1031 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1032 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1033 cols
/= vc
->vc_font
.width
;
1034 rows
/= vc
->vc_font
.height
;
1035 vc_resize(vc
, cols
, rows
);
1037 DPRINTK("mode: %s\n", info
->fix
.id
);
1038 DPRINTK("visual: %d\n", info
->fix
.visual
);
1039 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1041 info
->var
.bits_per_pixel
);
1043 fbcon_add_cursor_timer(info
);
1044 fbcon_has_exited
= 0;
1045 return display_desc
;
1048 static void fbcon_init(struct vc_data
*vc
, int init
)
1050 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1051 struct fbcon_ops
*ops
;
1052 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1053 struct vc_data
*svc
= *default_mode
;
1054 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1055 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1058 if (info_idx
== -1 || info
== NULL
)
1063 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1064 (info
->fix
.type
== FB_TYPE_TEXT
))
1067 if (var_to_display(p
, &info
->var
, info
))
1070 if (!info
->fbcon_par
)
1071 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1073 /* If we are not the first console on this
1074 fb, copy the font from that console */
1075 t
= &fb_display
[fg_console
];
1078 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1080 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1082 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1083 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1084 p
->userfont
= t
->userfont
;
1087 REFCOUNT(p
->fontdata
)++;
1089 const struct font_desc
*font
= NULL
;
1091 if (!fontname
[0] || !(font
= find_font(fontname
)))
1092 font
= get_default_font(info
->var
.xres
,
1094 info
->pixmap
.blit_x
,
1095 info
->pixmap
.blit_y
);
1096 vc
->vc_font
.width
= font
->width
;
1097 vc
->vc_font
.height
= font
->height
;
1098 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1099 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1100 support more fonts */
1105 charcnt
= FNTCHARCNT(p
->fontdata
);
1107 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1108 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1109 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1110 if (charcnt
== 256) {
1111 vc
->vc_hi_font_mask
= 0;
1113 vc
->vc_hi_font_mask
= 0x100;
1114 if (vc
->vc_can_do_color
)
1115 vc
->vc_complement_mask
<<= 1;
1118 if (!*svc
->vc_uni_pagedir_loc
)
1119 con_set_default_unimap(svc
);
1120 if (!*vc
->vc_uni_pagedir_loc
)
1121 con_copy_unimap(vc
, svc
);
1123 ops
= info
->fbcon_par
;
1124 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1126 p
->con_rotate
= initial_rotation
;
1127 if (p
->con_rotate
== -1)
1128 p
->con_rotate
= info
->fbcon_rotate_hint
;
1129 if (p
->con_rotate
== -1)
1130 p
->con_rotate
= FB_ROTATE_UR
;
1132 set_blitting_type(vc
, info
);
1136 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1137 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1138 new_cols
/= vc
->vc_font
.width
;
1139 new_rows
/= vc
->vc_font
.height
;
1142 * We must always set the mode. The mode of the previous console
1143 * driver could be in the same resolution but we are using different
1144 * hardware so we have to initialize the hardware.
1146 * We need to do it in fbcon_init() to prevent screen corruption.
1148 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
1149 if (info
->fbops
->fb_set_par
&&
1150 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1151 ret
= info
->fbops
->fb_set_par(info
);
1154 printk(KERN_ERR
"fbcon_init: detected "
1155 "unhandled fb_set_par error, "
1156 "error code %d\n", ret
);
1159 ops
->flags
|= FBCON_FLAGS_INIT
;
1164 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1165 !(cap
& FBINFO_HWACCEL_DISABLED
))
1166 p
->scrollmode
= SCROLL_MOVE
;
1167 else /* default to something safe */
1168 p
->scrollmode
= SCROLL_REDRAW
;
1171 * ++guenther: console.c:vc_allocate() relies on initializing
1172 * vc_{cols,rows}, but we must not set those if we are only
1173 * resizing the console.
1176 vc
->vc_cols
= new_cols
;
1177 vc
->vc_rows
= new_rows
;
1179 vc_resize(vc
, new_cols
, new_rows
);
1182 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1184 if (vc
== svc
&& softback_buf
)
1185 fbcon_update_softback(vc
);
1187 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1188 ops
->rotate
= FB_ROTATE_UR
;
1189 set_blitting_type(vc
, info
);
1192 ops
->p
= &fb_display
[fg_console
];
1195 static void fbcon_free_font(struct display
*p
, bool freefont
)
1197 if (freefont
&& p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1198 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1203 static void set_vc_hi_font(struct vc_data
*vc
, bool set
);
1205 static void fbcon_deinit(struct vc_data
*vc
)
1207 struct display
*p
= &fb_display
[vc
->vc_num
];
1208 struct fb_info
*info
;
1209 struct fbcon_ops
*ops
;
1211 bool free_font
= true;
1213 idx
= con2fb_map
[vc
->vc_num
];
1218 info
= registered_fb
[idx
];
1223 if (info
->flags
& FBINFO_MISC_FIRMWARE
)
1225 ops
= info
->fbcon_par
;
1230 if (con_is_visible(vc
))
1231 fbcon_del_cursor_timer(info
);
1233 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1236 fbcon_free_font(p
, free_font
);
1238 vc
->vc_font
.data
= NULL
;
1240 if (vc
->vc_hi_font_mask
&& vc
->vc_screenbuf
)
1241 set_vc_hi_font(vc
, false);
1243 if (!con_is_bound(&fb_con
))
1246 if (vc
->vc_num
== logo_shown
)
1247 logo_shown
= FBCON_LOGO_CANSHOW
;
1252 /* ====================================================================== */
1254 /* fbcon_XXX routines - interface used by the world
1256 * This system is now divided into two levels because of complications
1257 * caused by hardware scrolling. Top level functions:
1259 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1261 * handles y values in range [0, scr_height-1] that correspond to real
1262 * screen positions. y_wrap shift means that first line of bitmap may be
1263 * anywhere on this display. These functions convert lineoffsets to
1264 * bitmap offsets and deal with the wrap-around case by splitting blits.
1266 * fbcon_bmove_physical_8() -- These functions fast implementations
1267 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1268 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1272 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1273 * Implies should only really hardware scroll in rows. Only reason for
1274 * restriction is simplicity & efficiency at the moment.
1277 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1280 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1281 struct fbcon_ops
*ops
= info
->fbcon_par
;
1283 struct display
*p
= &fb_display
[vc
->vc_num
];
1286 if (fbcon_is_inactive(vc
, info
))
1289 if (!height
|| !width
)
1292 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1295 * If the font dimensions are not an integral of the display
1296 * dimensions then the ops->clear below won't end up clearing
1297 * the margins. Call clear_margins here in case the logo
1298 * bitmap stretched into the margin area.
1300 fbcon_clear_margins(vc
, 0);
1303 /* Split blits that cross physical y_wrap boundary */
1305 y_break
= p
->vrows
- p
->yscroll
;
1306 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1307 u_int b
= y_break
- sy
;
1308 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1309 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1312 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1315 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1316 int count
, int ypos
, int xpos
)
1318 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1319 struct display
*p
= &fb_display
[vc
->vc_num
];
1320 struct fbcon_ops
*ops
= info
->fbcon_par
;
1322 if (!fbcon_is_inactive(vc
, info
))
1323 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1324 get_color(vc
, info
, scr_readw(s
), 1),
1325 get_color(vc
, info
, scr_readw(s
), 0));
1328 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1332 scr_writew(c
, &chr
);
1333 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1336 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1338 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1339 struct fbcon_ops
*ops
= info
->fbcon_par
;
1341 if (!fbcon_is_inactive(vc
, info
))
1342 ops
->clear_margins(vc
, info
, margin_color
, bottom_only
);
1345 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1347 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1348 struct fbcon_ops
*ops
= info
->fbcon_par
;
1350 int c
= scr_readw((u16
*) vc
->vc_pos
);
1352 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1354 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1357 if (vc
->vc_cursor_type
& 0x10)
1358 fbcon_del_cursor_timer(info
);
1360 fbcon_add_cursor_timer(info
);
1362 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1363 if (mode
& CM_SOFTBACK
) {
1364 mode
&= ~CM_SOFTBACK
;
1368 fbcon_set_origin(vc
);
1372 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1373 get_color(vc
, info
, c
, 0));
1376 static int scrollback_phys_max
= 0;
1377 static int scrollback_max
= 0;
1378 static int scrollback_current
= 0;
1380 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1383 struct display
*p
, *t
;
1384 struct vc_data
**default_mode
, *vc
;
1385 struct vc_data
*svc
;
1386 struct fbcon_ops
*ops
= info
->fbcon_par
;
1387 int rows
, cols
, charcnt
= 256;
1389 p
= &fb_display
[unit
];
1391 if (var_to_display(p
, var
, info
))
1394 vc
= vc_cons
[unit
].d
;
1399 default_mode
= vc
->vc_display_fg
;
1400 svc
= *default_mode
;
1401 t
= &fb_display
[svc
->vc_num
];
1403 if (!vc
->vc_font
.data
) {
1404 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1405 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1406 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1407 p
->userfont
= t
->userfont
;
1409 REFCOUNT(p
->fontdata
)++;
1412 charcnt
= FNTCHARCNT(p
->fontdata
);
1414 var
->activate
= FB_ACTIVATE_NOW
;
1415 info
->var
.activate
= var
->activate
;
1416 var
->yoffset
= info
->var
.yoffset
;
1417 var
->xoffset
= info
->var
.xoffset
;
1418 fb_set_var(info
, var
);
1419 ops
->var
= info
->var
;
1420 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1421 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1422 if (charcnt
== 256) {
1423 vc
->vc_hi_font_mask
= 0;
1425 vc
->vc_hi_font_mask
= 0x100;
1426 if (vc
->vc_can_do_color
)
1427 vc
->vc_complement_mask
<<= 1;
1430 if (!*svc
->vc_uni_pagedir_loc
)
1431 con_set_default_unimap(svc
);
1432 if (!*vc
->vc_uni_pagedir_loc
)
1433 con_copy_unimap(vc
, svc
);
1435 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1436 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1437 cols
/= vc
->vc_font
.width
;
1438 rows
/= vc
->vc_font
.height
;
1439 vc_resize(vc
, cols
, rows
);
1441 if (con_is_visible(vc
)) {
1444 fbcon_update_softback(vc
);
1448 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1450 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1451 struct fbcon_ops
*ops
= info
->fbcon_par
;
1452 struct display
*p
= &fb_display
[vc
->vc_num
];
1454 p
->yscroll
+= count
;
1455 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1456 p
->yscroll
-= p
->vrows
;
1457 ops
->var
.xoffset
= 0;
1458 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1459 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1460 ops
->update_start(info
);
1461 scrollback_max
+= count
;
1462 if (scrollback_max
> scrollback_phys_max
)
1463 scrollback_max
= scrollback_phys_max
;
1464 scrollback_current
= 0;
1467 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1469 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1470 struct fbcon_ops
*ops
= info
->fbcon_par
;
1471 struct display
*p
= &fb_display
[vc
->vc_num
];
1473 p
->yscroll
-= count
;
1474 if (p
->yscroll
< 0) /* Deal with wrap */
1475 p
->yscroll
+= p
->vrows
;
1476 ops
->var
.xoffset
= 0;
1477 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1478 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1479 ops
->update_start(info
);
1480 scrollback_max
-= count
;
1481 if (scrollback_max
< 0)
1483 scrollback_current
= 0;
1486 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1488 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1489 struct display
*p
= &fb_display
[vc
->vc_num
];
1490 struct fbcon_ops
*ops
= info
->fbcon_par
;
1492 p
->yscroll
+= count
;
1493 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1494 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1495 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1496 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1499 ops
->var
.xoffset
= 0;
1500 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1501 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1502 ops
->update_start(info
);
1503 fbcon_clear_margins(vc
, 1);
1504 scrollback_max
+= count
;
1505 if (scrollback_max
> scrollback_phys_max
)
1506 scrollback_max
= scrollback_phys_max
;
1507 scrollback_current
= 0;
1510 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1512 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1513 struct fbcon_ops
*ops
= info
->fbcon_par
;
1514 struct display
*p
= &fb_display
[vc
->vc_num
];
1516 p
->yscroll
+= count
;
1518 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1519 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1520 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1523 ops
->var
.xoffset
= 0;
1524 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1525 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1526 ops
->update_start(info
);
1527 fbcon_clear_margins(vc
, 1);
1528 scrollback_max
+= count
;
1529 if (scrollback_max
> scrollback_phys_max
)
1530 scrollback_max
= scrollback_phys_max
;
1531 scrollback_current
= 0;
1534 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1536 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1537 struct display
*p
= &fb_display
[vc
->vc_num
];
1538 struct fbcon_ops
*ops
= info
->fbcon_par
;
1540 p
->yscroll
-= count
;
1541 if (p
->yscroll
< 0) {
1542 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1543 0, vc
->vc_rows
, vc
->vc_cols
);
1544 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1547 ops
->var
.xoffset
= 0;
1548 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1549 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1550 ops
->update_start(info
);
1551 fbcon_clear_margins(vc
, 1);
1552 scrollback_max
-= count
;
1553 if (scrollback_max
< 0)
1555 scrollback_current
= 0;
1558 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1560 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1561 struct fbcon_ops
*ops
= info
->fbcon_par
;
1562 struct display
*p
= &fb_display
[vc
->vc_num
];
1564 p
->yscroll
-= count
;
1566 if (p
->yscroll
< 0) {
1567 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1568 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1571 ops
->var
.xoffset
= 0;
1572 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1573 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1574 ops
->update_start(info
);
1575 fbcon_clear_margins(vc
, 1);
1576 scrollback_max
-= count
;
1577 if (scrollback_max
< 0)
1579 scrollback_current
= 0;
1582 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1585 int count
= vc
->vc_rows
;
1586 unsigned short *d
, *s
;
1590 d
= (u16
*) softback_curr
;
1591 if (d
== (u16
*) softback_in
)
1592 d
= (u16
*) vc
->vc_origin
;
1593 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1594 softback_lines
-= delta
;
1596 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1597 n
+= softback_end
- softback_buf
;
1598 if (n
< softback_top
) {
1600 (softback_top
- n
) / vc
->vc_size_row
;
1603 } else if (softback_curr
>= softback_top
1604 && n
< softback_top
) {
1606 (softback_top
- n
) / vc
->vc_size_row
;
1610 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1611 n
+= softback_buf
- softback_end
;
1612 if (n
> softback_in
) {
1616 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1621 if (n
== softback_curr
)
1624 s
= (u16
*) softback_curr
;
1625 if (s
== (u16
*) softback_in
)
1626 s
= (u16
*) vc
->vc_origin
;
1628 unsigned short *start
;
1632 unsigned short attr
= 1;
1635 le
= advance_row(s
, 1);
1638 if (attr
!= (c
& 0xff00)) {
1641 fbcon_putcs(vc
, start
, s
- start
,
1647 if (c
== scr_readw(d
)) {
1649 fbcon_putcs(vc
, start
, s
- start
,
1662 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1664 if (d
== (u16
*) softback_end
)
1665 d
= (u16
*) softback_buf
;
1666 if (d
== (u16
*) softback_in
)
1667 d
= (u16
*) vc
->vc_origin
;
1668 if (s
== (u16
*) softback_end
)
1669 s
= (u16
*) softback_buf
;
1670 if (s
== (u16
*) softback_in
)
1671 s
= (u16
*) vc
->vc_origin
;
1675 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1676 int line
, int count
, int dy
)
1678 unsigned short *s
= (unsigned short *)
1679 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1682 unsigned short *start
= s
;
1683 unsigned short *le
= advance_row(s
, 1);
1686 unsigned short attr
= 1;
1690 if (attr
!= (c
& 0xff00)) {
1693 fbcon_putcs(vc
, start
, s
- start
,
1699 console_conditional_schedule();
1703 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1704 console_conditional_schedule();
1709 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1710 struct display
*p
, int line
, int count
, int ycount
)
1712 int offset
= ycount
* vc
->vc_cols
;
1713 unsigned short *d
= (unsigned short *)
1714 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1715 unsigned short *s
= d
+ offset
;
1716 struct fbcon_ops
*ops
= info
->fbcon_par
;
1719 unsigned short *start
= s
;
1720 unsigned short *le
= advance_row(s
, 1);
1727 if (c
== scr_readw(d
)) {
1729 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1730 line
, x
, 1, s
-start
);
1740 console_conditional_schedule();
1745 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
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 void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1760 int line
, int count
, int offset
)
1762 unsigned short *d
= (unsigned short *)
1763 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1764 unsigned short *s
= d
+ offset
;
1767 unsigned short *start
= s
;
1768 unsigned short *le
= advance_row(s
, 1);
1771 unsigned short attr
= 1;
1775 if (attr
!= (c
& 0xff00)) {
1778 fbcon_putcs(vc
, start
, s
- start
,
1784 if (c
== scr_readw(d
)) {
1786 fbcon_putcs(vc
, start
, s
- start
,
1796 console_conditional_schedule();
1801 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1802 console_conditional_schedule();
1807 /* NOTE: We subtract two lines from these pointers */
1808 s
-= vc
->vc_size_row
;
1809 d
-= vc
->vc_size_row
;
1814 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1819 if (vc
->vc_num
!= fg_console
)
1821 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1824 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1826 p
= advance_row(p
, 1);
1827 softback_in
+= vc
->vc_size_row
;
1828 if (softback_in
== softback_end
)
1829 softback_in
= softback_buf
;
1830 if (softback_in
== softback_top
) {
1831 softback_top
+= vc
->vc_size_row
;
1832 if (softback_top
== softback_end
)
1833 softback_top
= softback_buf
;
1836 softback_curr
= softback_in
;
1839 static bool fbcon_scroll(struct vc_data
*vc
, unsigned int t
, unsigned int b
,
1840 enum con_scroll dir
, unsigned int count
)
1842 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1843 struct display
*p
= &fb_display
[vc
->vc_num
];
1844 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1846 if (fbcon_is_inactive(vc
, info
))
1849 fbcon_cursor(vc
, CM_ERASE
);
1852 * ++Geert: Only use ywrap/ypan if the console is in text mode
1853 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1854 * whole screen (prevents flicker).
1859 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1860 count
= vc
->vc_rows
;
1862 fbcon_softback_note(vc
, t
, count
);
1863 if (logo_shown
>= 0)
1865 switch (p
->scrollmode
) {
1867 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1869 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1870 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1873 vc
->vc_video_erase_char
,
1874 vc
->vc_size_row
* count
);
1878 case SCROLL_WRAP_MOVE
:
1879 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1881 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1883 ywrap_up(vc
, count
);
1884 if (vc
->vc_rows
- b
> 0)
1885 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1888 } else if (info
->flags
& FBINFO_READS_FAST
)
1889 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1890 b
- t
- count
, vc
->vc_cols
);
1893 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1896 case SCROLL_PAN_REDRAW
:
1897 if ((p
->yscroll
+ count
<=
1898 2 * (p
->vrows
- vc
->vc_rows
))
1899 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1902 3 * vc
->vc_rows
>> 2)))) {
1904 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1905 ypan_up_redraw(vc
, t
, count
);
1906 if (vc
->vc_rows
- b
> 0)
1907 fbcon_redraw_move(vc
, p
, b
,
1908 vc
->vc_rows
- b
, b
);
1910 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1911 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1914 case SCROLL_PAN_MOVE
:
1915 if ((p
->yscroll
+ count
<=
1916 2 * (p
->vrows
- vc
->vc_rows
))
1917 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1920 3 * vc
->vc_rows
>> 2)))) {
1922 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1925 if (vc
->vc_rows
- b
> 0)
1926 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1929 } else if (info
->flags
& FBINFO_READS_FAST
)
1930 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1931 b
- t
- count
, vc
->vc_cols
);
1934 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1939 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1940 count
* vc
->vc_cols
);
1941 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1942 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1945 vc
->vc_video_erase_char
,
1946 vc
->vc_size_row
* count
);
1952 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1953 count
= vc
->vc_rows
;
1954 if (logo_shown
>= 0)
1956 switch (p
->scrollmode
) {
1958 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1960 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1961 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1964 vc
->vc_video_erase_char
,
1965 vc
->vc_size_row
* count
);
1969 case SCROLL_WRAP_MOVE
:
1970 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1971 if (vc
->vc_rows
- b
> 0)
1972 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1975 ywrap_down(vc
, count
);
1977 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1979 } else if (info
->flags
& FBINFO_READS_FAST
)
1980 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1981 b
- t
- count
, vc
->vc_cols
);
1984 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1987 case SCROLL_PAN_MOVE
:
1988 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1989 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1992 3 * vc
->vc_rows
>> 2)))) {
1993 if (vc
->vc_rows
- b
> 0)
1994 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1997 ypan_down(vc
, count
);
1999 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
2001 } else if (info
->flags
& FBINFO_READS_FAST
)
2002 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
2003 b
- t
- count
, vc
->vc_cols
);
2006 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2009 case SCROLL_PAN_REDRAW
:
2010 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2011 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2014 3 * vc
->vc_rows
>> 2)))) {
2015 if (vc
->vc_rows
- b
> 0)
2016 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
2018 ypan_down_redraw(vc
, t
, count
);
2020 fbcon_redraw_move(vc
, p
, count
, t
, 0);
2022 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
2023 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2028 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
2029 -count
* vc
->vc_cols
);
2030 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2031 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2034 vc
->vc_video_erase_char
,
2035 vc
->vc_size_row
* count
);
2043 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2044 int height
, int width
)
2046 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2047 struct display
*p
= &fb_display
[vc
->vc_num
];
2049 if (fbcon_is_inactive(vc
, info
))
2052 if (!width
|| !height
)
2055 /* Split blits that cross physical y_wrap case.
2056 * Pathological case involves 4 blits, better to use recursive
2057 * code rather than unrolled case
2059 * Recursive invocations don't need to erase the cursor over and
2060 * over again, so we use fbcon_bmove_rec()
2062 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2063 p
->vrows
- p
->yscroll
);
2066 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2067 int dy
, int dx
, int height
, int width
, u_int y_break
)
2069 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2070 struct fbcon_ops
*ops
= info
->fbcon_par
;
2073 if (sy
< y_break
&& sy
+ height
> y_break
) {
2075 if (dy
< sy
) { /* Avoid trashing self */
2076 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2078 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2079 height
- b
, width
, y_break
);
2081 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2082 height
- b
, width
, y_break
);
2083 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2089 if (dy
< y_break
&& dy
+ height
> y_break
) {
2091 if (dy
< sy
) { /* Avoid trashing self */
2092 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2094 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2095 height
- b
, width
, y_break
);
2097 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2098 height
- b
, width
, y_break
);
2099 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2104 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2108 static void updatescrollmode(struct display
*p
,
2109 struct fb_info
*info
,
2112 struct fbcon_ops
*ops
= info
->fbcon_par
;
2113 int fh
= vc
->vc_font
.height
;
2114 int cap
= info
->flags
;
2116 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2117 info
->fix
.xpanstep
);
2118 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2119 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2120 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2121 info
->var
.xres_virtual
);
2122 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2123 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2124 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2125 divides(ywrap
, vc
->vc_font
.height
) &&
2126 divides(vc
->vc_font
.height
, vyres
) &&
2127 divides(vc
->vc_font
.height
, yres
);
2128 int reading_fast
= cap
& FBINFO_READS_FAST
;
2129 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2130 !(cap
& FBINFO_HWACCEL_DISABLED
);
2131 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2132 !(cap
& FBINFO_HWACCEL_DISABLED
);
2134 p
->vrows
= vyres
/fh
;
2135 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2136 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2137 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2140 if (good_wrap
|| good_pan
) {
2141 if (reading_fast
|| fast_copyarea
)
2142 p
->scrollmode
= good_wrap
?
2143 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2145 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2148 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2149 p
->scrollmode
= SCROLL_MOVE
;
2151 p
->scrollmode
= SCROLL_REDRAW
;
2155 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2156 unsigned int height
, unsigned int user
)
2158 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2159 struct fbcon_ops
*ops
= info
->fbcon_par
;
2160 struct display
*p
= &fb_display
[vc
->vc_num
];
2161 struct fb_var_screeninfo var
= info
->var
;
2162 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2164 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2165 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2166 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2167 vc
->vc_font
.height
);
2168 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2170 var
.xres
= virt_w
* virt_fw
;
2171 var
.yres
= virt_h
* virt_fh
;
2172 x_diff
= info
->var
.xres
- var
.xres
;
2173 y_diff
= info
->var
.yres
- var
.yres
;
2174 if (x_diff
< 0 || x_diff
> virt_fw
||
2175 y_diff
< 0 || y_diff
> virt_fh
) {
2176 const struct fb_videomode
*mode
;
2178 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2179 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2182 display_to_var(&var
, p
);
2183 fb_videomode_to_var(&var
, mode
);
2185 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2188 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2189 if (con_is_visible(vc
)) {
2190 var
.activate
= FB_ACTIVATE_NOW
|
2192 fb_set_var(info
, &var
);
2194 var_to_display(p
, &info
->var
, info
);
2195 ops
->var
= info
->var
;
2197 updatescrollmode(p
, info
, vc
);
2201 static int fbcon_switch(struct vc_data
*vc
)
2203 struct fb_info
*info
, *old_info
= NULL
;
2204 struct fbcon_ops
*ops
;
2205 struct display
*p
= &fb_display
[vc
->vc_num
];
2206 struct fb_var_screeninfo var
;
2207 int i
, ret
, prev_console
, charcnt
= 256;
2209 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2210 ops
= info
->fbcon_par
;
2214 fbcon_set_origin(vc
);
2215 softback_top
= softback_curr
= softback_in
= softback_buf
;
2217 fbcon_update_softback(vc
);
2220 if (logo_shown
>= 0) {
2221 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2223 if (conp2
->vc_top
== logo_lines
2224 && conp2
->vc_bottom
== conp2
->vc_rows
)
2226 logo_shown
= FBCON_LOGO_CANSHOW
;
2229 prev_console
= ops
->currcon
;
2230 if (prev_console
!= -1)
2231 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2233 * FIXME: If we have multiple fbdev's loaded, we need to
2234 * update all info->currcon. Perhaps, we can place this
2235 * in a centralized structure, but this might break some
2238 * info->currcon = vc->vc_num;
2240 for_each_registered_fb(i
) {
2241 if (registered_fb
[i
]->fbcon_par
) {
2242 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2244 o
->currcon
= vc
->vc_num
;
2247 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2248 display_to_var(&var
, p
);
2249 var
.activate
= FB_ACTIVATE_NOW
;
2252 * make sure we don't unnecessarily trip the memcmp()
2255 info
->var
.activate
= var
.activate
;
2256 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2257 fb_set_var(info
, &var
);
2258 ops
->var
= info
->var
;
2260 if (old_info
!= NULL
&& (old_info
!= info
||
2261 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2262 if (info
->fbops
->fb_set_par
) {
2263 ret
= info
->fbops
->fb_set_par(info
);
2266 printk(KERN_ERR
"fbcon_switch: detected "
2267 "unhandled fb_set_par error, "
2268 "error code %d\n", ret
);
2271 if (old_info
!= info
)
2272 fbcon_del_cursor_timer(old_info
);
2275 if (fbcon_is_inactive(vc
, info
) ||
2276 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2277 fbcon_del_cursor_timer(info
);
2279 fbcon_add_cursor_timer(info
);
2281 set_blitting_type(vc
, info
);
2282 ops
->cursor_reset
= 1;
2284 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2285 ops
->rotate
= FB_ROTATE_UR
;
2286 set_blitting_type(vc
, info
);
2289 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2290 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2293 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2296 vc
->vc_complement_mask
<<= 1;
2298 updatescrollmode(p
, info
, vc
);
2300 switch (p
->scrollmode
) {
2301 case SCROLL_WRAP_MOVE
:
2302 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2304 case SCROLL_PAN_MOVE
:
2305 case SCROLL_PAN_REDRAW
:
2306 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2307 if (scrollback_phys_max
< 0)
2308 scrollback_phys_max
= 0;
2311 scrollback_phys_max
= 0;
2316 scrollback_current
= 0;
2318 if (!fbcon_is_inactive(vc
, info
)) {
2319 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2320 ops
->update_start(info
);
2323 fbcon_set_palette(vc
, color_table
);
2324 fbcon_clear_margins(vc
, 0);
2326 if (logo_shown
== FBCON_LOGO_DRAW
) {
2328 logo_shown
= fg_console
;
2329 /* This is protected above by initmem_freed */
2330 fb_show_logo(info
, ops
->rotate
);
2332 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2333 vc
->vc_size_row
* (vc
->vc_bottom
-
2340 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2343 struct fb_event event
;
2346 unsigned short charmask
= vc
->vc_hi_font_mask
?
2348 unsigned short oldc
;
2350 oldc
= vc
->vc_video_erase_char
;
2351 vc
->vc_video_erase_char
&= charmask
;
2352 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2353 vc
->vc_video_erase_char
= oldc
;
2357 if (!lock_fb_info(info
))
2360 event
.data
= &blank
;
2361 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2362 unlock_fb_info(info
);
2365 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2367 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2368 struct fbcon_ops
*ops
= info
->fbcon_par
;
2371 struct fb_var_screeninfo var
= info
->var
;
2376 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2377 fb_set_var(info
, &var
);
2379 ops
->var
= info
->var
;
2383 if (!fbcon_is_inactive(vc
, info
)) {
2384 if (ops
->blank_state
!= blank
) {
2385 ops
->blank_state
= blank
;
2386 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2387 ops
->cursor_flash
= (!blank
);
2389 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2390 if (fb_blank(info
, blank
))
2391 fbcon_generic_blank(vc
, info
, blank
);
2398 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2399 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2400 fbcon_del_cursor_timer(info
);
2402 fbcon_add_cursor_timer(info
);
2407 static int fbcon_debug_enter(struct vc_data
*vc
)
2409 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2410 struct fbcon_ops
*ops
= info
->fbcon_par
;
2412 ops
->save_graphics
= ops
->graphics
;
2414 if (info
->fbops
->fb_debug_enter
)
2415 info
->fbops
->fb_debug_enter(info
);
2416 fbcon_set_palette(vc
, color_table
);
2420 static int fbcon_debug_leave(struct vc_data
*vc
)
2422 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2423 struct fbcon_ops
*ops
= info
->fbcon_par
;
2425 ops
->graphics
= ops
->save_graphics
;
2426 if (info
->fbops
->fb_debug_leave
)
2427 info
->fbops
->fb_debug_leave(info
);
2431 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2433 u8
*fontdata
= vc
->vc_font
.data
;
2434 u8
*data
= font
->data
;
2437 font
->width
= vc
->vc_font
.width
;
2438 font
->height
= vc
->vc_font
.height
;
2439 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2443 if (font
->width
<= 8) {
2444 j
= vc
->vc_font
.height
;
2445 for (i
= 0; i
< font
->charcount
; i
++) {
2446 memcpy(data
, fontdata
, j
);
2447 memset(data
+ j
, 0, 32 - j
);
2451 } else if (font
->width
<= 16) {
2452 j
= vc
->vc_font
.height
* 2;
2453 for (i
= 0; i
< font
->charcount
; i
++) {
2454 memcpy(data
, fontdata
, j
);
2455 memset(data
+ j
, 0, 64 - j
);
2459 } else if (font
->width
<= 24) {
2460 for (i
= 0; i
< font
->charcount
; i
++) {
2461 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2462 *data
++ = fontdata
[0];
2463 *data
++ = fontdata
[1];
2464 *data
++ = fontdata
[2];
2465 fontdata
+= sizeof(u32
);
2467 memset(data
, 0, 3 * (32 - j
));
2468 data
+= 3 * (32 - j
);
2471 j
= vc
->vc_font
.height
* 4;
2472 for (i
= 0; i
< font
->charcount
; i
++) {
2473 memcpy(data
, fontdata
, j
);
2474 memset(data
+ j
, 0, 128 - j
);
2482 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2483 static void set_vc_hi_font(struct vc_data
*vc
, bool set
)
2486 vc
->vc_hi_font_mask
= 0;
2487 if (vc
->vc_can_do_color
) {
2488 vc
->vc_complement_mask
>>= 1;
2489 vc
->vc_s_complement_mask
>>= 1;
2492 /* ++Edmund: reorder the attribute bits */
2493 if (vc
->vc_can_do_color
) {
2494 unsigned short *cp
=
2495 (unsigned short *) vc
->vc_origin
;
2496 int count
= vc
->vc_screenbuf_size
/ 2;
2498 for (; count
> 0; count
--, cp
++) {
2500 scr_writew(((c
& 0xfe00) >> 1) |
2503 c
= vc
->vc_video_erase_char
;
2504 vc
->vc_video_erase_char
=
2505 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2509 vc
->vc_hi_font_mask
= 0x100;
2510 if (vc
->vc_can_do_color
) {
2511 vc
->vc_complement_mask
<<= 1;
2512 vc
->vc_s_complement_mask
<<= 1;
2515 /* ++Edmund: reorder the attribute bits */
2517 unsigned short *cp
=
2518 (unsigned short *) vc
->vc_origin
;
2519 int count
= vc
->vc_screenbuf_size
/ 2;
2521 for (; count
> 0; count
--, cp
++) {
2522 unsigned short newc
;
2524 if (vc
->vc_can_do_color
)
2526 ((c
& 0xff00) << 1) | (c
&
2530 scr_writew(newc
, cp
);
2532 c
= vc
->vc_video_erase_char
;
2533 if (vc
->vc_can_do_color
) {
2534 vc
->vc_video_erase_char
=
2535 ((c
& 0xff00) << 1) | (c
& 0xff);
2538 vc
->vc_video_erase_char
= c
& ~0x100;
2543 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2544 const u8
* data
, int userfont
)
2546 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2547 struct fbcon_ops
*ops
= info
->fbcon_par
;
2548 struct display
*p
= &fb_display
[vc
->vc_num
];
2551 char *old_data
= NULL
;
2553 if (con_is_visible(vc
) && softback_lines
)
2554 fbcon_set_origin(vc
);
2556 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2558 old_data
= vc
->vc_font
.data
;
2560 cnt
= FNTCHARCNT(data
);
2563 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2564 if ((p
->userfont
= userfont
))
2566 vc
->vc_font
.width
= w
;
2567 vc
->vc_font
.height
= h
;
2568 if (vc
->vc_hi_font_mask
&& cnt
== 256)
2569 set_vc_hi_font(vc
, false);
2570 else if (!vc
->vc_hi_font_mask
&& cnt
== 512)
2571 set_vc_hi_font(vc
, true);
2576 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2577 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2580 vc_resize(vc
, cols
, rows
);
2581 if (con_is_visible(vc
) && softback_buf
)
2582 fbcon_update_softback(vc
);
2583 } else if (con_is_visible(vc
)
2584 && vc
->vc_mode
== KD_TEXT
) {
2585 fbcon_clear_margins(vc
, 0);
2589 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2590 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2594 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2596 struct display
*od
= &fb_display
[con
];
2597 struct console_font
*f
= &vc
->vc_font
;
2599 if (od
->fontdata
== f
->data
)
2600 return 0; /* already the same font... */
2601 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2605 * User asked to set font; we are guaranteed that
2606 * a) width and height are in range 1..32
2607 * b) charcount does not exceed 512
2608 * but lets not assume that, since someone might someday want to use larger
2609 * fonts. And charcount of 512 is small for unicode support.
2611 * However, user space gives the font in 32 rows , regardless of
2612 * actual font height. So a new API is needed if support for larger fonts
2613 * is ever implemented.
2616 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
,
2619 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2620 unsigned charcount
= font
->charcount
;
2621 int w
= font
->width
;
2622 int h
= font
->height
;
2625 u8
*new_data
, *data
= font
->data
;
2626 int pitch
= (font
->width
+7) >> 3;
2628 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2629 * If not this check should be changed to charcount < 256 */
2630 if (charcount
!= 256 && charcount
!= 512)
2633 /* Make sure drawing engine can handle the font */
2634 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2635 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2638 /* Make sure driver can handle the font length */
2639 if (fbcon_invalid_charcount(info
, charcount
))
2642 size
= h
* pitch
* charcount
;
2644 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2649 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2650 FNTSIZE(new_data
) = size
;
2651 FNTCHARCNT(new_data
) = charcount
;
2652 REFCOUNT(new_data
) = 0; /* usage counter */
2653 for (i
=0; i
< charcount
; i
++) {
2654 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2657 /* Since linux has a nice crc32 function use it for counting font
2659 csum
= crc32(0, new_data
, size
);
2661 FNTSUM(new_data
) = csum
;
2662 /* Check if the same font is on some other console already */
2663 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2664 struct vc_data
*tmp
= vc_cons
[i
].d
;
2666 if (fb_display
[i
].userfont
&&
2667 fb_display
[i
].fontdata
&&
2668 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2669 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2670 tmp
->vc_font
.width
== w
&&
2671 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2672 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2673 new_data
= (u8
*)fb_display
[i
].fontdata
;
2677 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2680 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2682 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2683 const struct font_desc
*f
;
2686 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2687 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2688 else if (!(f
= find_font(name
)))
2691 font
->width
= f
->width
;
2692 font
->height
= f
->height
;
2693 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2696 static u16 palette_red
[16];
2697 static u16 palette_green
[16];
2698 static u16 palette_blue
[16];
2700 static struct fb_cmap palette_cmap
= {
2701 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2704 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
)
2706 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2710 if (fbcon_is_inactive(vc
, info
))
2713 if (!con_is_visible(vc
))
2716 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2718 for (i
= j
= 0; i
< 16; i
++) {
2720 val
= vc
->vc_palette
[j
++];
2721 palette_red
[k
] = (val
<< 8) | val
;
2722 val
= vc
->vc_palette
[j
++];
2723 palette_green
[k
] = (val
<< 8) | val
;
2724 val
= vc
->vc_palette
[j
++];
2725 palette_blue
[k
] = (val
<< 8) | val
;
2727 palette_cmap
.len
= 16;
2728 palette_cmap
.start
= 0;
2730 * If framebuffer is capable of less than 16 colors,
2731 * use default palette of fbcon.
2734 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2736 fb_set_cmap(&palette_cmap
, info
);
2739 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2744 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2745 return (u16
*) (vc
->vc_origin
+ offset
);
2746 line
= offset
/ vc
->vc_size_row
;
2747 if (line
>= softback_lines
)
2748 return (u16
*) (vc
->vc_origin
+ offset
-
2749 softback_lines
* vc
->vc_size_row
);
2750 p
= softback_curr
+ offset
;
2751 if (p
>= softback_end
)
2752 p
+= softback_buf
- softback_end
;
2756 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2762 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2763 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2765 x
= offset
% vc
->vc_cols
;
2766 y
= offset
/ vc
->vc_cols
;
2767 if (vc
->vc_num
== fg_console
)
2768 y
+= softback_lines
;
2769 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2770 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2771 unsigned long offset
= pos
- softback_curr
;
2773 if (pos
< softback_curr
)
2774 offset
+= softback_end
- softback_buf
;
2776 x
= offset
% vc
->vc_cols
;
2777 y
= offset
/ vc
->vc_cols
;
2778 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2779 if (ret
== softback_end
)
2781 if (ret
== softback_in
)
2782 ret
= vc
->vc_origin
;
2784 /* Should not happen */
2786 ret
= vc
->vc_origin
;
2795 /* As we might be inside of softback, we may work with non-contiguous buffer,
2796 that's why we have to use a separate routine. */
2797 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2800 u16 a
= scr_readw(p
);
2801 if (!vc
->vc_can_do_color
)
2803 else if (vc
->vc_hi_font_mask
== 0x100)
2804 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2805 (((a
) & 0x0e00) << 4);
2807 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2808 (((a
) & 0x0700) << 4);
2810 if (p
== (u16
*) softback_end
)
2811 p
= (u16
*) softback_buf
;
2812 if (p
== (u16
*) softback_in
)
2813 p
= (u16
*) vc
->vc_origin
;
2817 static void fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2819 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2820 struct fbcon_ops
*ops
= info
->fbcon_par
;
2821 struct display
*disp
= &fb_display
[fg_console
];
2822 int offset
, limit
, scrollback_old
;
2825 if (vc
->vc_num
!= fg_console
)
2827 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2829 if (logo_shown
>= 0) {
2830 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2832 if (conp2
->vc_top
== logo_lines
2833 && conp2
->vc_bottom
== conp2
->vc_rows
)
2835 if (logo_shown
== vc
->vc_num
) {
2841 logo_lines
* vc
->vc_size_row
;
2842 for (i
= 0; i
< logo_lines
; i
++) {
2843 if (p
== softback_top
)
2845 if (p
== softback_buf
)
2847 p
-= vc
->vc_size_row
;
2848 q
-= vc
->vc_size_row
;
2849 scr_memcpyw((u16
*) q
, (u16
*) p
,
2852 softback_in
= softback_curr
= p
;
2853 update_region(vc
, vc
->vc_origin
,
2854 logo_lines
* vc
->vc_cols
);
2856 logo_shown
= FBCON_LOGO_CANSHOW
;
2858 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2859 fbcon_redraw_softback(vc
, disp
, lines
);
2860 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2864 if (!scrollback_phys_max
)
2867 scrollback_old
= scrollback_current
;
2868 scrollback_current
-= lines
;
2869 if (scrollback_current
< 0)
2870 scrollback_current
= 0;
2871 else if (scrollback_current
> scrollback_max
)
2872 scrollback_current
= scrollback_max
;
2873 if (scrollback_current
== scrollback_old
)
2876 if (fbcon_is_inactive(vc
, info
))
2879 fbcon_cursor(vc
, CM_ERASE
);
2881 offset
= disp
->yscroll
- scrollback_current
;
2882 limit
= disp
->vrows
;
2883 switch (disp
->scrollmode
) {
2884 case SCROLL_WRAP_MOVE
:
2885 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2887 case SCROLL_PAN_MOVE
:
2888 case SCROLL_PAN_REDRAW
:
2889 limit
-= vc
->vc_rows
;
2890 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2895 else if (offset
>= limit
)
2898 ops
->var
.xoffset
= 0;
2899 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2900 ops
->update_start(info
);
2902 if (!scrollback_current
)
2903 fbcon_cursor(vc
, CM_DRAW
);
2906 static int fbcon_set_origin(struct vc_data
*vc
)
2909 fbcon_scrolldelta(vc
, softback_lines
);
2913 static void fbcon_suspended(struct fb_info
*info
)
2915 struct vc_data
*vc
= NULL
;
2916 struct fbcon_ops
*ops
= info
->fbcon_par
;
2918 if (!ops
|| ops
->currcon
< 0)
2920 vc
= vc_cons
[ops
->currcon
].d
;
2922 /* Clear cursor, restore saved data */
2923 fbcon_cursor(vc
, CM_ERASE
);
2926 static void fbcon_resumed(struct fb_info
*info
)
2929 struct fbcon_ops
*ops
= info
->fbcon_par
;
2931 if (!ops
|| ops
->currcon
< 0)
2933 vc
= vc_cons
[ops
->currcon
].d
;
2938 static void fbcon_modechanged(struct fb_info
*info
)
2940 struct fbcon_ops
*ops
= info
->fbcon_par
;
2945 if (!ops
|| ops
->currcon
< 0)
2947 vc
= vc_cons
[ops
->currcon
].d
;
2948 if (vc
->vc_mode
!= KD_TEXT
||
2949 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2952 p
= &fb_display
[vc
->vc_num
];
2953 set_blitting_type(vc
, info
);
2955 if (con_is_visible(vc
)) {
2956 var_to_display(p
, &info
->var
, info
);
2957 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2958 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2959 cols
/= vc
->vc_font
.width
;
2960 rows
/= vc
->vc_font
.height
;
2961 vc_resize(vc
, cols
, rows
);
2962 updatescrollmode(p
, info
, vc
);
2964 scrollback_current
= 0;
2966 if (!fbcon_is_inactive(vc
, info
)) {
2967 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2968 ops
->update_start(info
);
2971 fbcon_set_palette(vc
, color_table
);
2974 fbcon_update_softback(vc
);
2978 static void fbcon_set_all_vcs(struct fb_info
*info
)
2980 struct fbcon_ops
*ops
= info
->fbcon_par
;
2983 int i
, rows
, cols
, fg
= -1;
2985 if (!ops
|| ops
->currcon
< 0)
2988 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2990 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2991 registered_fb
[con2fb_map
[i
]] != info
)
2994 if (con_is_visible(vc
)) {
2999 p
= &fb_display
[vc
->vc_num
];
3000 set_blitting_type(vc
, info
);
3001 var_to_display(p
, &info
->var
, info
);
3002 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
3003 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
3004 cols
/= vc
->vc_font
.width
;
3005 rows
/= vc
->vc_font
.height
;
3006 vc_resize(vc
, cols
, rows
);
3010 fbcon_modechanged(info
);
3013 static int fbcon_mode_deleted(struct fb_info
*info
,
3014 struct fb_videomode
*mode
)
3016 struct fb_info
*fb_info
;
3018 int i
, j
, found
= 0;
3020 /* before deletion, ensure that mode is not in use */
3021 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3025 fb_info
= registered_fb
[j
];
3026 if (fb_info
!= info
)
3031 if (fb_mode_is_equal(p
->mode
, mode
)) {
3039 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3040 static int fbcon_unbind(void)
3044 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3048 fbcon_has_console_bind
= 0;
3053 static inline int fbcon_unbind(void)
3057 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3059 /* called with console_lock held */
3060 static int fbcon_fb_unbind(int idx
)
3062 int i
, new_idx
= -1, ret
= 0;
3064 WARN_CONSOLE_UNLOCKED();
3066 if (!fbcon_has_console_bind
)
3069 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3070 if (con2fb_map
[i
] != idx
&&
3071 con2fb_map
[i
] != -1) {
3072 new_idx
= con2fb_map
[i
];
3077 if (new_idx
!= -1) {
3078 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3079 if (con2fb_map
[i
] == idx
)
3080 set_con2fb_map(i
, new_idx
, 0);
3083 struct fb_info
*info
= registered_fb
[idx
];
3085 /* This is sort of like set_con2fb_map, except it maps
3086 * the consoles to no device and then releases the
3087 * oldinfo to free memory and cancel the cursor blink
3088 * timer. I can imagine this just becoming part of
3089 * set_con2fb_map where new_idx is -1
3091 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3092 if (con2fb_map
[i
] == idx
) {
3094 if (!search_fb_in_map(idx
)) {
3095 ret
= con2fb_release_oldinfo(vc_cons
[i
].d
,
3099 con2fb_map
[i
] = idx
;
3105 ret
= fbcon_unbind();
3111 /* called with console_lock held */
3112 static int fbcon_fb_unregistered(struct fb_info
*info
)
3116 WARN_CONSOLE_UNLOCKED();
3118 if (deferred_takeover
)
3122 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3123 if (con2fb_map
[i
] == idx
)
3127 if (idx
== info_idx
) {
3130 for_each_registered_fb(i
) {
3136 if (info_idx
!= -1) {
3137 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3138 if (con2fb_map
[i
] == -1)
3139 con2fb_map
[i
] = info_idx
;
3143 if (primary_device
== idx
)
3144 primary_device
= -1;
3146 if (!num_registered_fb
)
3147 do_unregister_con_driver(&fb_con
);
3152 /* called with console_lock held */
3153 static void fbcon_remap_all(int idx
)
3157 WARN_CONSOLE_UNLOCKED();
3159 if (deferred_takeover
) {
3160 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3161 con2fb_map_boot
[i
] = idx
;
3162 fbcon_map_override();
3166 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3167 set_con2fb_map(i
, idx
, 0);
3169 if (con_is_bound(&fb_con
)) {
3170 printk(KERN_INFO
"fbcon: Remapping primary device, "
3171 "fb%i, to tty %i-%i\n", idx
,
3172 first_fb_vc
+ 1, last_fb_vc
+ 1);
3177 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3178 static void fbcon_select_primary(struct fb_info
*info
)
3180 if (!map_override
&& primary_device
== -1 &&
3181 fb_is_primary_device(info
)) {
3184 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3185 info
->fix
.id
, info
->node
);
3186 primary_device
= info
->node
;
3188 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3189 con2fb_map_boot
[i
] = primary_device
;
3191 if (con_is_bound(&fb_con
)) {
3192 printk(KERN_INFO
"fbcon: Remapping primary device, "
3193 "fb%i, to tty %i-%i\n", info
->node
,
3194 first_fb_vc
+ 1, last_fb_vc
+ 1);
3195 info_idx
= primary_device
;
3201 static inline void fbcon_select_primary(struct fb_info
*info
)
3205 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3207 /* called with console_lock held */
3208 static int fbcon_fb_registered(struct fb_info
*info
)
3210 int ret
= 0, i
, idx
;
3212 WARN_CONSOLE_UNLOCKED();
3215 fbcon_select_primary(info
);
3217 if (deferred_takeover
) {
3218 pr_info("fbcon: Deferring console take-over\n");
3222 if (info_idx
== -1) {
3223 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3224 if (con2fb_map_boot
[i
] == idx
) {
3231 ret
= do_fbcon_takeover(1);
3233 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3234 if (con2fb_map_boot
[i
] == idx
)
3235 set_con2fb_map(i
, idx
, 0);
3242 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3244 struct fbcon_ops
*ops
= info
->fbcon_par
;
3247 if (!ops
|| ops
->currcon
< 0)
3250 vc
= vc_cons
[ops
->currcon
].d
;
3251 if (vc
->vc_mode
!= KD_TEXT
||
3252 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3255 if (con_is_visible(vc
)) {
3259 do_unblank_screen(0);
3261 ops
->blank_state
= blank
;
3264 static void fbcon_new_modelist(struct fb_info
*info
)
3268 struct fb_var_screeninfo var
;
3269 const struct fb_videomode
*mode
;
3271 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3272 if (registered_fb
[con2fb_map
[i
]] != info
)
3274 if (!fb_display
[i
].mode
)
3277 display_to_var(&var
, &fb_display
[i
]);
3278 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3280 fb_videomode_to_var(&var
, mode
);
3281 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3285 static void fbcon_get_requirement(struct fb_info
*info
,
3286 struct fb_blit_caps
*caps
)
3294 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3296 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3297 info
->node
== con2fb_map
[i
]) {
3299 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3300 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3301 charcnt
= (p
->userfont
) ?
3302 FNTCHARCNT(p
->fontdata
) : 256;
3303 if (caps
->len
< charcnt
)
3304 caps
->len
= charcnt
;
3308 vc
= vc_cons
[fg_console
].d
;
3310 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3311 info
->node
== con2fb_map
[fg_console
]) {
3312 p
= &fb_display
[fg_console
];
3313 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3314 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3315 caps
->len
= (p
->userfont
) ?
3316 FNTCHARCNT(p
->fontdata
) : 256;
3321 static int fbcon_event_notify(struct notifier_block
*self
,
3322 unsigned long action
, void *data
)
3324 struct fb_event
*event
= data
;
3325 struct fb_info
*info
= event
->info
;
3326 struct fb_videomode
*mode
;
3327 struct fb_con2fbmap
*con2fb
;
3328 struct fb_blit_caps
*caps
;
3332 * ignore all events except driver registration and deregistration
3333 * if fbcon is not active
3335 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3336 action
== FB_EVENT_FB_UNREGISTERED
))
3340 case FB_EVENT_SUSPEND
:
3341 fbcon_suspended(info
);
3343 case FB_EVENT_RESUME
:
3344 fbcon_resumed(info
);
3346 case FB_EVENT_MODE_CHANGE
:
3347 fbcon_modechanged(info
);
3349 case FB_EVENT_MODE_CHANGE_ALL
:
3350 fbcon_set_all_vcs(info
);
3352 case FB_EVENT_MODE_DELETE
:
3354 ret
= fbcon_mode_deleted(info
, mode
);
3356 case FB_EVENT_FB_UNBIND
:
3358 ret
= fbcon_fb_unbind(idx
);
3360 case FB_EVENT_FB_REGISTERED
:
3361 ret
= fbcon_fb_registered(info
);
3363 case FB_EVENT_FB_UNREGISTERED
:
3364 ret
= fbcon_fb_unregistered(info
);
3366 case FB_EVENT_SET_CONSOLE_MAP
:
3367 /* called with console lock held */
3368 con2fb
= event
->data
;
3369 ret
= set_con2fb_map(con2fb
->console
- 1,
3370 con2fb
->framebuffer
, 1);
3372 case FB_EVENT_GET_CONSOLE_MAP
:
3373 con2fb
= event
->data
;
3374 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3376 case FB_EVENT_BLANK
:
3377 fbcon_fb_blanked(info
, *(int *)event
->data
);
3379 case FB_EVENT_NEW_MODELIST
:
3380 fbcon_new_modelist(info
);
3382 case FB_EVENT_GET_REQ
:
3384 fbcon_get_requirement(info
, caps
);
3386 case FB_EVENT_REMAP_ALL_CONSOLE
:
3388 fbcon_remap_all(idx
);
3396 * The console `switch' structure for the frame buffer based console
3399 static const struct consw fb_con
= {
3400 .owner
= THIS_MODULE
,
3401 .con_startup
= fbcon_startup
,
3402 .con_init
= fbcon_init
,
3403 .con_deinit
= fbcon_deinit
,
3404 .con_clear
= fbcon_clear
,
3405 .con_putc
= fbcon_putc
,
3406 .con_putcs
= fbcon_putcs
,
3407 .con_cursor
= fbcon_cursor
,
3408 .con_scroll
= fbcon_scroll
,
3409 .con_switch
= fbcon_switch
,
3410 .con_blank
= fbcon_blank
,
3411 .con_font_set
= fbcon_set_font
,
3412 .con_font_get
= fbcon_get_font
,
3413 .con_font_default
= fbcon_set_def_font
,
3414 .con_font_copy
= fbcon_copy_font
,
3415 .con_set_palette
= fbcon_set_palette
,
3416 .con_scrolldelta
= fbcon_scrolldelta
,
3417 .con_set_origin
= fbcon_set_origin
,
3418 .con_invert_region
= fbcon_invert_region
,
3419 .con_screen_pos
= fbcon_screen_pos
,
3420 .con_getxy
= fbcon_getxy
,
3421 .con_resize
= fbcon_resize
,
3422 .con_debug_enter
= fbcon_debug_enter
,
3423 .con_debug_leave
= fbcon_debug_leave
,
3426 static struct notifier_block fbcon_event_notifier
= {
3427 .notifier_call
= fbcon_event_notify
,
3430 static ssize_t
store_rotate(struct device
*device
,
3431 struct device_attribute
*attr
, const char *buf
,
3434 struct fb_info
*info
;
3438 if (fbcon_has_exited
)
3442 idx
= con2fb_map
[fg_console
];
3444 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3447 info
= registered_fb
[idx
];
3448 rotate
= simple_strtoul(buf
, last
, 0);
3449 fbcon_rotate(info
, rotate
);
3455 static ssize_t
store_rotate_all(struct device
*device
,
3456 struct device_attribute
*attr
,const char *buf
,
3459 struct fb_info
*info
;
3463 if (fbcon_has_exited
)
3467 idx
= con2fb_map
[fg_console
];
3469 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3472 info
= registered_fb
[idx
];
3473 rotate
= simple_strtoul(buf
, last
, 0);
3474 fbcon_rotate_all(info
, rotate
);
3480 static ssize_t
show_rotate(struct device
*device
,
3481 struct device_attribute
*attr
,char *buf
)
3483 struct fb_info
*info
;
3484 int rotate
= 0, idx
;
3486 if (fbcon_has_exited
)
3490 idx
= con2fb_map
[fg_console
];
3492 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3495 info
= registered_fb
[idx
];
3496 rotate
= fbcon_get_rotate(info
);
3499 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3502 static ssize_t
show_cursor_blink(struct device
*device
,
3503 struct device_attribute
*attr
, char *buf
)
3505 struct fb_info
*info
;
3506 struct fbcon_ops
*ops
;
3507 int idx
, blink
= -1;
3509 if (fbcon_has_exited
)
3513 idx
= con2fb_map
[fg_console
];
3515 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3518 info
= registered_fb
[idx
];
3519 ops
= info
->fbcon_par
;
3524 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3527 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3530 static ssize_t
store_cursor_blink(struct device
*device
,
3531 struct device_attribute
*attr
,
3532 const char *buf
, size_t count
)
3534 struct fb_info
*info
;
3538 if (fbcon_has_exited
)
3542 idx
= con2fb_map
[fg_console
];
3544 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3547 info
= registered_fb
[idx
];
3549 if (!info
->fbcon_par
)
3552 blink
= simple_strtoul(buf
, last
, 0);
3555 fbcon_cursor_noblink
= 0;
3556 fbcon_add_cursor_timer(info
);
3558 fbcon_cursor_noblink
= 1;
3559 fbcon_del_cursor_timer(info
);
3567 static struct device_attribute device_attrs
[] = {
3568 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3569 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3570 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3571 store_cursor_blink
),
3574 static int fbcon_init_device(void)
3578 fbcon_has_sysfs
= 1;
3580 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3581 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3589 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3591 fbcon_has_sysfs
= 0;
3597 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3598 static void fbcon_register_existing_fbs(struct work_struct
*work
)
3604 for_each_registered_fb(i
)
3605 fbcon_fb_registered(registered_fb
[i
]);
3610 static struct notifier_block fbcon_output_nb
;
3611 static DECLARE_WORK(fbcon_deferred_takeover_work
, fbcon_register_existing_fbs
);
3613 static int fbcon_output_notifier(struct notifier_block
*nb
,
3614 unsigned long action
, void *data
)
3616 WARN_CONSOLE_UNLOCKED();
3618 pr_info("fbcon: Taking over console\n");
3620 dummycon_unregister_output_notifier(&fbcon_output_nb
);
3621 deferred_takeover
= false;
3622 logo_shown
= FBCON_LOGO_DONTSHOW
;
3624 /* We may get called in atomic context */
3625 schedule_work(&fbcon_deferred_takeover_work
);
3631 static void fbcon_start(void)
3633 WARN_CONSOLE_UNLOCKED();
3635 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3636 if (conswitchp
!= &dummy_con
)
3637 deferred_takeover
= false;
3639 if (deferred_takeover
) {
3640 fbcon_output_nb
.notifier_call
= fbcon_output_notifier
;
3641 dummycon_register_output_notifier(&fbcon_output_nb
);
3646 if (num_registered_fb
) {
3649 for_each_registered_fb(i
) {
3654 do_fbcon_takeover(0);
3658 static void fbcon_exit(void)
3660 struct fb_info
*info
;
3663 if (fbcon_has_exited
)
3666 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3667 if (deferred_takeover
) {
3668 dummycon_unregister_output_notifier(&fbcon_output_nb
);
3669 deferred_takeover
= false;
3673 kfree((void *)softback_buf
);
3676 for_each_registered_fb(i
) {
3680 info
= registered_fb
[i
];
3682 if (info
->queue
.func
)
3683 pending
= cancel_work_sync(&info
->queue
);
3684 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3687 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3688 if (con2fb_map
[j
] == i
) {
3695 if (info
->fbops
->fb_release
)
3696 info
->fbops
->fb_release(info
, 0);
3697 module_put(info
->fbops
->owner
);
3699 if (info
->fbcon_par
) {
3700 struct fbcon_ops
*ops
= info
->fbcon_par
;
3702 fbcon_del_cursor_timer(info
);
3703 kfree(ops
->cursor_src
);
3704 kfree(ops
->cursor_state
.mask
);
3705 kfree(info
->fbcon_par
);
3706 info
->fbcon_par
= NULL
;
3709 if (info
->queue
.func
== fb_flashcursor
)
3710 info
->queue
.func
= NULL
;
3714 fbcon_has_exited
= 1;
3717 void __init
fb_console_init(void)
3722 fb_register_client(&fbcon_event_notifier
);
3723 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3726 if (IS_ERR(fbcon_device
)) {
3727 printk(KERN_WARNING
"Unable to create device "
3728 "for fbcon; errno = %ld\n",
3729 PTR_ERR(fbcon_device
));
3730 fbcon_device
= NULL
;
3732 fbcon_init_device();
3734 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3743 static void __exit
fbcon_deinit_device(void)
3747 if (fbcon_has_sysfs
) {
3748 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3749 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3751 fbcon_has_sysfs
= 0;
3755 void __exit
fb_console_exit(void)
3758 fb_unregister_client(&fbcon_event_notifier
);
3759 fbcon_deinit_device();
3760 device_destroy(fb_class
, MKDEV(0, 0));
3762 do_unregister_con_driver(&fb_con
);