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 */
79 #include <linux/uaccess.h>
86 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
88 # define DPRINTK(fmt, args...)
94 * - fbcon state itself is protected by the console_lock, and the code does a
95 * pretty good job at making sure that lock is held everywhere it's needed.
97 * - access to the registered_fb array is entirely unprotected. This should use
98 * proper object lifetime handling, i.e. get/put_fb_info. This also means
99 * switching from indices to proper pointers for fb_info everywhere.
101 * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since it
102 * means concurrent access to the same fbdev from both fbcon and userspace
103 * will blow up. To fix this all fbcon calls from fbmem.c need to be moved out
104 * of fb_lock/unlock protected sections, since otherwise we'll recurse and
105 * deadlock eventually. Aside: Due to these deadlock issues the fbdev code in
106 * fbmem.c cannot use locking asserts, and there's lots of callers which get
107 * the rules wrong, e.g. fbsysfs.c entirely missed fb_lock/unlock calls too.
111 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
112 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
113 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
116 static struct fbcon_display fb_display
[MAX_NR_CONSOLES
];
118 static signed char con2fb_map
[MAX_NR_CONSOLES
];
119 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
121 static int logo_lines
;
122 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
124 static int logo_shown
= FBCON_LOGO_CANSHOW
;
125 /* Software scrollback */
126 static int fbcon_softback_size
= 32768;
127 static unsigned long softback_buf
, softback_curr
;
128 static unsigned long softback_in
;
129 static unsigned long softback_top
, softback_end
;
130 static int softback_lines
;
131 /* console mappings */
132 static int first_fb_vc
;
133 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
134 static int fbcon_is_default
= 1;
135 static int primary_device
= -1;
136 static int fbcon_has_console_bind
;
138 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
139 static int map_override
;
141 static inline void fbcon_map_override(void)
146 static inline void fbcon_map_override(void)
149 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
151 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
152 static bool deferred_takeover
= true;
154 #define deferred_takeover false
158 static char fontname
[40];
160 /* current fb_info */
161 static int info_idx
= -1;
163 /* console rotation */
164 static int initial_rotation
= -1;
165 static int fbcon_has_sysfs
;
166 static int margin_color
;
168 static const struct consw fb_con
;
170 #define CM_SOFTBACK (8)
172 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
174 static int fbcon_set_origin(struct vc_data
*);
176 static int fbcon_cursor_noblink
;
178 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
181 * Interface used by the world
184 static const char *fbcon_startup(void);
185 static void fbcon_init(struct vc_data
*vc
, int init
);
186 static void fbcon_deinit(struct vc_data
*vc
);
187 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
189 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
190 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
191 int count
, int ypos
, int xpos
);
192 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
193 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
194 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
195 int height
, int width
);
196 static int fbcon_switch(struct vc_data
*vc
);
197 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
198 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
);
203 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
204 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
205 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
206 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
207 static void fbcon_bmove_rec(struct vc_data
*vc
, struct fbcon_display
*p
, int sy
, int sx
,
208 int dy
, int dx
, int height
, int width
, u_int y_break
);
209 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
211 static void fbcon_redraw_move(struct vc_data
*vc
, struct fbcon_display
*p
,
212 int line
, int count
, int dy
);
213 static void fbcon_modechanged(struct fb_info
*info
);
214 static void fbcon_set_all_vcs(struct fb_info
*info
);
215 static void fbcon_start(void);
216 static void fbcon_exit(void);
217 static struct device
*fbcon_device
;
219 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
220 static inline void fbcon_set_rotation(struct fb_info
*info
)
222 struct fbcon_ops
*ops
= info
->fbcon_par
;
224 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
225 ops
->p
->con_rotate
< 4)
226 ops
->rotate
= ops
->p
->con_rotate
;
231 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
233 struct fbcon_ops
*ops
= info
->fbcon_par
;
234 struct fb_info
*fb_info
;
236 if (!ops
|| ops
->currcon
== -1)
239 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
241 if (info
== fb_info
) {
242 struct fbcon_display
*p
= &fb_display
[ops
->currcon
];
245 p
->con_rotate
= rotate
;
249 fbcon_modechanged(info
);
253 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
255 struct fbcon_ops
*ops
= info
->fbcon_par
;
257 struct fbcon_display
*p
;
260 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
263 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
265 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
266 registered_fb
[con2fb_map
[i
]] != info
)
269 p
= &fb_display
[vc
->vc_num
];
270 p
->con_rotate
= rotate
;
273 fbcon_set_all_vcs(info
);
276 static inline void fbcon_set_rotation(struct fb_info
*info
)
278 struct fbcon_ops
*ops
= info
->fbcon_par
;
280 ops
->rotate
= FB_ROTATE_UR
;
283 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
288 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
292 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
294 static int fbcon_get_rotate(struct fb_info
*info
)
296 struct fbcon_ops
*ops
= info
->fbcon_par
;
298 return (ops
) ? ops
->rotate
: 0;
301 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
303 struct fbcon_ops
*ops
= info
->fbcon_par
;
305 return (info
->state
!= FBINFO_STATE_RUNNING
||
306 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
309 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
312 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
315 if (console_blanked
) {
316 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
318 c
= vc
->vc_video_erase_char
& charmask
;
322 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
323 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
328 int col
= mono_col(info
);
330 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
331 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
336 color
= (is_fg
) ? fg
: bg
;
341 * Scale down 16-colors to 4 colors. Default 4-color palette
342 * is grayscale. However, simply dividing the values by 4
343 * will not work, as colors 1, 2 and 3 will be scaled-down
344 * to zero rendering them invisible. So empirically convert
345 * colors to a sane 4-level grayscale.
349 color
= 0; /* black */
352 color
= 2; /* white */
355 color
= 1; /* gray */
358 color
= 3; /* intense white */
364 * Last 8 entries of default 16-color palette is a more intense
365 * version of the first 8 (i.e., same chrominance, different
376 static void fbcon_update_softback(struct vc_data
*vc
)
378 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
381 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
383 /* Smaller scrollback makes no sense, and 0 would screw
384 the operation totally */
388 static void fb_flashcursor(struct work_struct
*work
)
390 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
391 struct fbcon_ops
*ops
= info
->fbcon_par
;
392 struct vc_data
*vc
= NULL
;
397 /* FIXME: we should sort out the unbind locking instead */
398 /* instead we just fail to flash the cursor if we can't get
399 * the lock instead of blocking fbcon deinit */
400 ret
= console_trylock();
404 if (ops
&& ops
->currcon
!= -1)
405 vc
= vc_cons
[ops
->currcon
].d
;
407 if (!vc
|| !con_is_visible(vc
) ||
408 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
414 c
= scr_readw((u16
*) vc
->vc_pos
);
415 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
417 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
418 get_color(vc
, info
, c
, 0));
422 static void cursor_timer_handler(struct timer_list
*t
)
424 struct fbcon_ops
*ops
= from_timer(ops
, t
, cursor_timer
);
425 struct fb_info
*info
= ops
->info
;
427 queue_work(system_power_efficient_wq
, &info
->queue
);
428 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
431 static void fbcon_add_cursor_timer(struct fb_info
*info
)
433 struct fbcon_ops
*ops
= info
->fbcon_par
;
435 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
436 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
437 !fbcon_cursor_noblink
) {
438 if (!info
->queue
.func
)
439 INIT_WORK(&info
->queue
, fb_flashcursor
);
441 timer_setup(&ops
->cursor_timer
, cursor_timer_handler
, 0);
442 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
443 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
447 static void fbcon_del_cursor_timer(struct fb_info
*info
)
449 struct fbcon_ops
*ops
= info
->fbcon_par
;
451 if (info
->queue
.func
== fb_flashcursor
&&
452 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
453 del_timer_sync(&ops
->cursor_timer
);
454 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
459 static int __init
fb_console_setup(char *this_opt
)
464 if (!this_opt
|| !*this_opt
)
467 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
468 if (!strncmp(options
, "font:", 5)) {
469 strlcpy(fontname
, options
+ 5, sizeof(fontname
));
473 if (!strncmp(options
, "scrollback:", 11)) {
476 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
477 if (*options
== 'k' || *options
== 'K') {
478 fbcon_softback_size
*= 1024;
484 if (!strncmp(options
, "map:", 4)) {
487 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
491 (options
[j
++]-'0') % FB_MAX
;
494 fbcon_map_override();
499 if (!strncmp(options
, "vc:", 3)) {
502 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
505 if (*options
++ == '-')
506 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
507 fbcon_is_default
= 0;
511 if (!strncmp(options
, "rotate:", 7)) {
514 initial_rotation
= simple_strtoul(options
, &options
, 0);
515 if (initial_rotation
> 3)
516 initial_rotation
= 0;
520 if (!strncmp(options
, "margin:", 7)) {
523 margin_color
= simple_strtoul(options
, &options
, 0);
526 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
527 if (!strcmp(options
, "nodefer")) {
528 deferred_takeover
= false;
533 if (!strncmp(options
, "logo-pos:", 9)) {
535 if (!strcmp(options
, "center"))
536 fb_center_logo
= true;
540 if (!strncmp(options
, "logo-count:", 11)) {
543 fb_logo_count
= simple_strtol(options
, &options
, 0);
550 __setup("fbcon=", fb_console_setup
);
553 static int search_fb_in_map(int idx
)
557 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
558 if (con2fb_map
[i
] == idx
)
564 static int search_for_mapped_con(void)
568 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
569 if (con2fb_map
[i
] != -1)
575 static int do_fbcon_takeover(int show_logo
)
579 if (!num_registered_fb
)
583 logo_shown
= FBCON_LOGO_DONTSHOW
;
585 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
586 con2fb_map
[i
] = info_idx
;
588 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
592 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
596 fbcon_has_console_bind
= 1;
603 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
604 int cols
, int rows
, int new_cols
, int new_rows
)
606 logo_shown
= FBCON_LOGO_DONTSHOW
;
609 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
610 int cols
, int rows
, int new_cols
, int new_rows
)
612 /* Need to make room for the logo */
613 struct fbcon_ops
*ops
= info
->fbcon_par
;
614 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
615 unsigned short *save
= NULL
, *r
, *q
;
618 if (info
->fbops
->owner
) {
619 logo_shown
= FBCON_LOGO_DONTSHOW
;
624 * remove underline attribute from erase character
625 * if black and white framebuffer.
627 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
629 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
630 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
631 q
= (unsigned short *) (vc
->vc_origin
+
632 vc
->vc_size_row
* rows
);
633 step
= logo_lines
* cols
;
634 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
635 if (scr_readw(r
) != vc
->vc_video_erase_char
)
637 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
638 save
= kmalloc(array3_size(logo_lines
, new_cols
, 2),
641 int i
= cols
< new_cols
? cols
: new_cols
;
642 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
644 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
645 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
650 /* We can scroll screen down */
652 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
653 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
658 if (vc
->vc_y
+ logo_lines
>= rows
)
659 lines
= rows
- vc
->vc_y
- 1;
663 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
666 scr_memsetw((unsigned short *) vc
->vc_origin
,
668 vc
->vc_size_row
* logo_lines
);
670 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
671 fbcon_clear_margins(vc
, 0);
676 q
= (unsigned short *) (vc
->vc_origin
+
679 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
680 vc
->vc_y
+= logo_lines
;
681 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
685 if (logo_shown
== FBCON_LOGO_DONTSHOW
)
688 if (logo_lines
> vc
->vc_bottom
) {
689 logo_shown
= FBCON_LOGO_CANSHOW
;
691 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
693 logo_shown
= FBCON_LOGO_DRAW
;
694 vc
->vc_top
= logo_lines
;
699 #ifdef CONFIG_FB_TILEBLITTING
700 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
702 struct fbcon_ops
*ops
= info
->fbcon_par
;
704 ops
->p
= &fb_display
[vc
->vc_num
];
706 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
707 fbcon_set_tileops(vc
, info
);
709 fbcon_set_rotation(info
);
710 fbcon_set_bitops(ops
);
714 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
718 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
719 info
->tileops
->fb_get_tilemax(info
) < charcount
)
725 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
727 struct fbcon_ops
*ops
= info
->fbcon_par
;
729 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
730 ops
->p
= &fb_display
[vc
->vc_num
];
731 fbcon_set_rotation(info
);
732 fbcon_set_bitops(ops
);
735 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
740 #endif /* CONFIG_MISC_TILEBLITTING */
743 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
744 int unit
, int oldidx
)
746 struct fbcon_ops
*ops
= NULL
;
749 if (!try_module_get(info
->fbops
->owner
))
752 if (!err
&& info
->fbops
->fb_open
&&
753 info
->fbops
->fb_open(info
, 0))
757 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
763 ops
->cur_blink_jiffies
= HZ
/ 5;
765 info
->fbcon_par
= ops
;
768 set_blitting_type(vc
, info
);
772 con2fb_map
[unit
] = oldidx
;
773 module_put(info
->fbops
->owner
);
779 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
780 struct fb_info
*newinfo
, int unit
,
781 int oldidx
, int found
)
783 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
786 if (oldinfo
->fbops
->fb_release
&&
787 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
788 con2fb_map
[unit
] = oldidx
;
789 if (!found
&& newinfo
->fbops
->fb_release
)
790 newinfo
->fbops
->fb_release(newinfo
, 0);
792 module_put(newinfo
->fbops
->owner
);
797 fbcon_del_cursor_timer(oldinfo
);
798 kfree(ops
->cursor_state
.mask
);
799 kfree(ops
->cursor_data
);
800 kfree(ops
->cursor_src
);
801 kfree(ops
->fontbuffer
);
802 kfree(oldinfo
->fbcon_par
);
803 oldinfo
->fbcon_par
= NULL
;
804 module_put(oldinfo
->fbops
->owner
);
806 If oldinfo and newinfo are driving the same hardware,
807 the fb_release() method of oldinfo may attempt to
808 restore the hardware state. This will leave the
809 newinfo in an undefined state. Thus, a call to
810 fb_set_par() may be needed for the newinfo.
812 if (newinfo
&& newinfo
->fbops
->fb_set_par
) {
813 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
816 printk(KERN_ERR
"con2fb_release_oldinfo: "
817 "detected unhandled fb_set_par error, "
818 "error code %d\n", ret
);
825 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
826 int unit
, int show_logo
)
828 struct fbcon_ops
*ops
= info
->fbcon_par
;
831 ops
->currcon
= fg_console
;
833 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
834 ret
= info
->fbops
->fb_set_par(info
);
837 printk(KERN_ERR
"con2fb_init_display: detected "
838 "unhandled fb_set_par error, "
839 "error code %d\n", ret
);
842 ops
->flags
|= FBCON_FLAGS_INIT
;
844 fbcon_set_disp(info
, &info
->var
, unit
);
847 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
848 struct fb_info
*fg_info
=
849 registered_fb
[con2fb_map
[fg_console
]];
851 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
852 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
856 update_screen(vc_cons
[fg_console
].d
);
860 * set_con2fb_map - map console to frame buffer device
861 * @unit: virtual console number to map
862 * @newidx: frame buffer index to map virtual console to
863 * @user: user request
865 * Maps a virtual console @unit to a frame buffer device
868 * This should be called with the console lock held.
870 static int set_con2fb_map(int unit
, int newidx
, int user
)
872 struct vc_data
*vc
= vc_cons
[unit
].d
;
873 int oldidx
= con2fb_map
[unit
];
874 struct fb_info
*info
= registered_fb
[newidx
];
875 struct fb_info
*oldinfo
= NULL
;
878 WARN_CONSOLE_UNLOCKED();
880 if (oldidx
== newidx
)
886 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
888 return do_fbcon_takeover(0);
892 oldinfo
= registered_fb
[oldidx
];
894 found
= search_fb_in_map(newidx
);
896 con2fb_map
[unit
] = newidx
;
898 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
901 * If old fb is not mapped to any of the consoles,
902 * fbcon should release it.
904 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
905 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
909 int show_logo
= (fg_console
== 0 && !user
&&
910 logo_shown
!= FBCON_LOGO_DONTSHOW
);
913 fbcon_add_cursor_timer(info
);
914 con2fb_map_boot
[unit
] = newidx
;
915 con2fb_init_display(vc
, info
, unit
, show_logo
);
918 if (!search_fb_in_map(info_idx
))
925 * Low Level Operations
927 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
928 static int var_to_display(struct fbcon_display
*disp
,
929 struct fb_var_screeninfo
*var
,
930 struct fb_info
*info
)
932 disp
->xres_virtual
= var
->xres_virtual
;
933 disp
->yres_virtual
= var
->yres_virtual
;
934 disp
->bits_per_pixel
= var
->bits_per_pixel
;
935 disp
->grayscale
= var
->grayscale
;
936 disp
->nonstd
= var
->nonstd
;
937 disp
->accel_flags
= var
->accel_flags
;
938 disp
->height
= var
->height
;
939 disp
->width
= var
->width
;
940 disp
->red
= var
->red
;
941 disp
->green
= var
->green
;
942 disp
->blue
= var
->blue
;
943 disp
->transp
= var
->transp
;
944 disp
->rotate
= var
->rotate
;
945 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
946 if (disp
->mode
== NULL
)
947 /* This should not happen */
952 static void display_to_var(struct fb_var_screeninfo
*var
,
953 struct fbcon_display
*disp
)
955 fb_videomode_to_var(var
, disp
->mode
);
956 var
->xres_virtual
= disp
->xres_virtual
;
957 var
->yres_virtual
= disp
->yres_virtual
;
958 var
->bits_per_pixel
= disp
->bits_per_pixel
;
959 var
->grayscale
= disp
->grayscale
;
960 var
->nonstd
= disp
->nonstd
;
961 var
->accel_flags
= disp
->accel_flags
;
962 var
->height
= disp
->height
;
963 var
->width
= disp
->width
;
964 var
->red
= disp
->red
;
965 var
->green
= disp
->green
;
966 var
->blue
= disp
->blue
;
967 var
->transp
= disp
->transp
;
968 var
->rotate
= disp
->rotate
;
971 static const char *fbcon_startup(void)
973 const char *display_desc
= "frame buffer device";
974 struct fbcon_display
*p
= &fb_display
[fg_console
];
975 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
976 const struct font_desc
*font
= NULL
;
977 struct module
*owner
;
978 struct fb_info
*info
= NULL
;
979 struct fbcon_ops
*ops
;
983 * If num_registered_fb is zero, this is a call for the dummy part.
984 * The frame buffer devices weren't initialized yet.
986 if (!num_registered_fb
|| info_idx
== -1)
989 * Instead of blindly using registered_fb[0], we use info_idx, set by
992 info
= registered_fb
[info_idx
];
996 owner
= info
->fbops
->owner
;
997 if (!try_module_get(owner
))
999 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
1004 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
1012 ops
->cur_rotate
= -1;
1013 ops
->cur_blink_jiffies
= HZ
/ 5;
1015 info
->fbcon_par
= ops
;
1017 p
->con_rotate
= initial_rotation
;
1018 if (p
->con_rotate
== -1)
1019 p
->con_rotate
= info
->fbcon_rotate_hint
;
1020 if (p
->con_rotate
== -1)
1021 p
->con_rotate
= FB_ROTATE_UR
;
1023 set_blitting_type(vc
, info
);
1025 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
1026 if (fbcon_softback_size
) {
1027 if (!softback_buf
) {
1030 kvmalloc(fbcon_softback_size
,
1032 if (!softback_buf
) {
1033 fbcon_softback_size
= 0;
1039 kvfree((void *) softback_buf
);
1045 softback_in
= softback_top
= softback_curr
=
1050 /* Setup default font */
1051 if (!p
->fontdata
&& !vc
->vc_font
.data
) {
1052 if (!fontname
[0] || !(font
= find_font(fontname
)))
1053 font
= get_default_font(info
->var
.xres
,
1055 info
->pixmap
.blit_x
,
1056 info
->pixmap
.blit_y
);
1057 vc
->vc_font
.width
= font
->width
;
1058 vc
->vc_font
.height
= font
->height
;
1059 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1060 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1062 p
->fontdata
= vc
->vc_font
.data
;
1065 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1066 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1067 cols
/= vc
->vc_font
.width
;
1068 rows
/= vc
->vc_font
.height
;
1069 vc_resize(vc
, cols
, rows
);
1071 DPRINTK("mode: %s\n", info
->fix
.id
);
1072 DPRINTK("visual: %d\n", info
->fix
.visual
);
1073 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1075 info
->var
.bits_per_pixel
);
1077 fbcon_add_cursor_timer(info
);
1078 return display_desc
;
1081 static void fbcon_init(struct vc_data
*vc
, int init
)
1083 struct fb_info
*info
;
1084 struct fbcon_ops
*ops
;
1085 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1086 struct vc_data
*svc
= *default_mode
;
1087 struct fbcon_display
*t
, *p
= &fb_display
[vc
->vc_num
];
1088 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1091 if (WARN_ON(info_idx
== -1))
1094 if (con2fb_map
[vc
->vc_num
] == -1)
1095 con2fb_map
[vc
->vc_num
] = info_idx
;
1097 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1100 if (logo_shown
< 0 && console_loglevel
<= CONSOLE_LOGLEVEL_QUIET
)
1101 logo_shown
= FBCON_LOGO_DONTSHOW
;
1103 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1104 (info
->fix
.type
== FB_TYPE_TEXT
))
1107 if (var_to_display(p
, &info
->var
, info
))
1110 if (!info
->fbcon_par
)
1111 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1113 /* If we are not the first console on this
1114 fb, copy the font from that console */
1115 t
= &fb_display
[fg_console
];
1118 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1120 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1122 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1123 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1124 p
->userfont
= t
->userfont
;
1127 REFCOUNT(p
->fontdata
)++;
1129 const struct font_desc
*font
= NULL
;
1131 if (!fontname
[0] || !(font
= find_font(fontname
)))
1132 font
= get_default_font(info
->var
.xres
,
1134 info
->pixmap
.blit_x
,
1135 info
->pixmap
.blit_y
);
1136 vc
->vc_font
.width
= font
->width
;
1137 vc
->vc_font
.height
= font
->height
;
1138 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1139 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1140 support more fonts */
1145 charcnt
= FNTCHARCNT(p
->fontdata
);
1147 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1148 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1149 if (charcnt
== 256) {
1150 vc
->vc_hi_font_mask
= 0;
1152 vc
->vc_hi_font_mask
= 0x100;
1153 if (vc
->vc_can_do_color
)
1154 vc
->vc_complement_mask
<<= 1;
1157 if (!*svc
->vc_uni_pagedir_loc
)
1158 con_set_default_unimap(svc
);
1159 if (!*vc
->vc_uni_pagedir_loc
)
1160 con_copy_unimap(vc
, svc
);
1162 ops
= info
->fbcon_par
;
1163 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1165 p
->con_rotate
= initial_rotation
;
1166 if (p
->con_rotate
== -1)
1167 p
->con_rotate
= info
->fbcon_rotate_hint
;
1168 if (p
->con_rotate
== -1)
1169 p
->con_rotate
= FB_ROTATE_UR
;
1171 set_blitting_type(vc
, info
);
1175 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1176 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1177 new_cols
/= vc
->vc_font
.width
;
1178 new_rows
/= vc
->vc_font
.height
;
1181 * We must always set the mode. The mode of the previous console
1182 * driver could be in the same resolution but we are using different
1183 * hardware so we have to initialize the hardware.
1185 * We need to do it in fbcon_init() to prevent screen corruption.
1187 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
1188 if (info
->fbops
->fb_set_par
&&
1189 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1190 ret
= info
->fbops
->fb_set_par(info
);
1193 printk(KERN_ERR
"fbcon_init: detected "
1194 "unhandled fb_set_par error, "
1195 "error code %d\n", ret
);
1198 ops
->flags
|= FBCON_FLAGS_INIT
;
1203 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1204 !(cap
& FBINFO_HWACCEL_DISABLED
))
1205 p
->scrollmode
= SCROLL_MOVE
;
1206 else /* default to something safe */
1207 p
->scrollmode
= SCROLL_REDRAW
;
1210 * ++guenther: console.c:vc_allocate() relies on initializing
1211 * vc_{cols,rows}, but we must not set those if we are only
1212 * resizing the console.
1215 vc
->vc_cols
= new_cols
;
1216 vc
->vc_rows
= new_rows
;
1218 vc_resize(vc
, new_cols
, new_rows
);
1221 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1223 if (vc
== svc
&& softback_buf
)
1224 fbcon_update_softback(vc
);
1226 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1227 ops
->rotate
= FB_ROTATE_UR
;
1228 set_blitting_type(vc
, info
);
1231 ops
->p
= &fb_display
[fg_console
];
1234 static void fbcon_free_font(struct fbcon_display
*p
, bool freefont
)
1236 if (freefont
&& p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1237 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1242 static void set_vc_hi_font(struct vc_data
*vc
, bool set
);
1244 static void fbcon_deinit(struct vc_data
*vc
)
1246 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1247 struct fb_info
*info
;
1248 struct fbcon_ops
*ops
;
1250 bool free_font
= true;
1252 idx
= con2fb_map
[vc
->vc_num
];
1257 info
= registered_fb
[idx
];
1262 if (info
->flags
& FBINFO_MISC_FIRMWARE
)
1264 ops
= info
->fbcon_par
;
1269 if (con_is_visible(vc
))
1270 fbcon_del_cursor_timer(info
);
1272 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1275 fbcon_free_font(p
, free_font
);
1277 vc
->vc_font
.data
= NULL
;
1279 if (vc
->vc_hi_font_mask
&& vc
->vc_screenbuf
)
1280 set_vc_hi_font(vc
, false);
1282 if (!con_is_bound(&fb_con
))
1285 if (vc
->vc_num
== logo_shown
)
1286 logo_shown
= FBCON_LOGO_CANSHOW
;
1291 /* ====================================================================== */
1293 /* fbcon_XXX routines - interface used by the world
1295 * This system is now divided into two levels because of complications
1296 * caused by hardware scrolling. Top level functions:
1298 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1300 * handles y values in range [0, scr_height-1] that correspond to real
1301 * screen positions. y_wrap shift means that first line of bitmap may be
1302 * anywhere on this display. These functions convert lineoffsets to
1303 * bitmap offsets and deal with the wrap-around case by splitting blits.
1305 * fbcon_bmove_physical_8() -- These functions fast implementations
1306 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1307 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1311 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1312 * Implies should only really hardware scroll in rows. Only reason for
1313 * restriction is simplicity & efficiency at the moment.
1316 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1319 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1320 struct fbcon_ops
*ops
= info
->fbcon_par
;
1322 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1325 if (fbcon_is_inactive(vc
, info
))
1328 if (!height
|| !width
)
1331 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1334 * If the font dimensions are not an integral of the display
1335 * dimensions then the ops->clear below won't end up clearing
1336 * the margins. Call clear_margins here in case the logo
1337 * bitmap stretched into the margin area.
1339 fbcon_clear_margins(vc
, 0);
1342 /* Split blits that cross physical y_wrap boundary */
1344 y_break
= p
->vrows
- p
->yscroll
;
1345 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1346 u_int b
= y_break
- sy
;
1347 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1348 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1351 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1354 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1355 int count
, int ypos
, int xpos
)
1357 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1358 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1359 struct fbcon_ops
*ops
= info
->fbcon_par
;
1361 if (!fbcon_is_inactive(vc
, info
))
1362 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1363 get_color(vc
, info
, scr_readw(s
), 1),
1364 get_color(vc
, info
, scr_readw(s
), 0));
1367 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1371 scr_writew(c
, &chr
);
1372 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1375 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1377 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1378 struct fbcon_ops
*ops
= info
->fbcon_par
;
1380 if (!fbcon_is_inactive(vc
, info
))
1381 ops
->clear_margins(vc
, info
, margin_color
, bottom_only
);
1384 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1386 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1387 struct fbcon_ops
*ops
= info
->fbcon_par
;
1389 int c
= scr_readw((u16
*) vc
->vc_pos
);
1391 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1393 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1396 if (vc
->vc_cursor_type
& 0x10)
1397 fbcon_del_cursor_timer(info
);
1399 fbcon_add_cursor_timer(info
);
1401 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1402 if (mode
& CM_SOFTBACK
) {
1403 mode
&= ~CM_SOFTBACK
;
1407 fbcon_set_origin(vc
);
1411 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1412 get_color(vc
, info
, c
, 0));
1415 static int scrollback_phys_max
= 0;
1416 static int scrollback_max
= 0;
1417 static int scrollback_current
= 0;
1419 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1422 struct fbcon_display
*p
, *t
;
1423 struct vc_data
**default_mode
, *vc
;
1424 struct vc_data
*svc
;
1425 struct fbcon_ops
*ops
= info
->fbcon_par
;
1426 int rows
, cols
, charcnt
= 256;
1428 p
= &fb_display
[unit
];
1430 if (var_to_display(p
, var
, info
))
1433 vc
= vc_cons
[unit
].d
;
1438 default_mode
= vc
->vc_display_fg
;
1439 svc
= *default_mode
;
1440 t
= &fb_display
[svc
->vc_num
];
1442 if (!vc
->vc_font
.data
) {
1443 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1444 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1445 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1446 p
->userfont
= t
->userfont
;
1448 REFCOUNT(p
->fontdata
)++;
1451 charcnt
= FNTCHARCNT(p
->fontdata
);
1453 var
->activate
= FB_ACTIVATE_NOW
;
1454 info
->var
.activate
= var
->activate
;
1455 var
->yoffset
= info
->var
.yoffset
;
1456 var
->xoffset
= info
->var
.xoffset
;
1457 fb_set_var(info
, var
);
1458 ops
->var
= info
->var
;
1459 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1460 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1461 if (charcnt
== 256) {
1462 vc
->vc_hi_font_mask
= 0;
1464 vc
->vc_hi_font_mask
= 0x100;
1465 if (vc
->vc_can_do_color
)
1466 vc
->vc_complement_mask
<<= 1;
1469 if (!*svc
->vc_uni_pagedir_loc
)
1470 con_set_default_unimap(svc
);
1471 if (!*vc
->vc_uni_pagedir_loc
)
1472 con_copy_unimap(vc
, svc
);
1474 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1475 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1476 cols
/= vc
->vc_font
.width
;
1477 rows
/= vc
->vc_font
.height
;
1478 vc_resize(vc
, cols
, rows
);
1480 if (con_is_visible(vc
)) {
1483 fbcon_update_softback(vc
);
1487 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1489 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1490 struct fbcon_ops
*ops
= info
->fbcon_par
;
1491 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1493 p
->yscroll
+= count
;
1494 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1495 p
->yscroll
-= p
->vrows
;
1496 ops
->var
.xoffset
= 0;
1497 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1498 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1499 ops
->update_start(info
);
1500 scrollback_max
+= count
;
1501 if (scrollback_max
> scrollback_phys_max
)
1502 scrollback_max
= scrollback_phys_max
;
1503 scrollback_current
= 0;
1506 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1508 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1509 struct fbcon_ops
*ops
= info
->fbcon_par
;
1510 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1512 p
->yscroll
-= count
;
1513 if (p
->yscroll
< 0) /* Deal with wrap */
1514 p
->yscroll
+= p
->vrows
;
1515 ops
->var
.xoffset
= 0;
1516 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1517 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1518 ops
->update_start(info
);
1519 scrollback_max
-= count
;
1520 if (scrollback_max
< 0)
1522 scrollback_current
= 0;
1525 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1527 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1528 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1529 struct fbcon_ops
*ops
= info
->fbcon_par
;
1531 p
->yscroll
+= count
;
1532 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1533 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1534 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1535 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1538 ops
->var
.xoffset
= 0;
1539 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1540 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1541 ops
->update_start(info
);
1542 fbcon_clear_margins(vc
, 1);
1543 scrollback_max
+= count
;
1544 if (scrollback_max
> scrollback_phys_max
)
1545 scrollback_max
= scrollback_phys_max
;
1546 scrollback_current
= 0;
1549 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1551 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1552 struct fbcon_ops
*ops
= info
->fbcon_par
;
1553 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1555 p
->yscroll
+= count
;
1557 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1558 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1559 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1562 ops
->var
.xoffset
= 0;
1563 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1564 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1565 ops
->update_start(info
);
1566 fbcon_clear_margins(vc
, 1);
1567 scrollback_max
+= count
;
1568 if (scrollback_max
> scrollback_phys_max
)
1569 scrollback_max
= scrollback_phys_max
;
1570 scrollback_current
= 0;
1573 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1575 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1576 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1577 struct fbcon_ops
*ops
= info
->fbcon_par
;
1579 p
->yscroll
-= count
;
1580 if (p
->yscroll
< 0) {
1581 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1582 0, vc
->vc_rows
, vc
->vc_cols
);
1583 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1586 ops
->var
.xoffset
= 0;
1587 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1588 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1589 ops
->update_start(info
);
1590 fbcon_clear_margins(vc
, 1);
1591 scrollback_max
-= count
;
1592 if (scrollback_max
< 0)
1594 scrollback_current
= 0;
1597 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1599 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1600 struct fbcon_ops
*ops
= info
->fbcon_par
;
1601 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1603 p
->yscroll
-= count
;
1605 if (p
->yscroll
< 0) {
1606 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1607 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1610 ops
->var
.xoffset
= 0;
1611 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1612 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1613 ops
->update_start(info
);
1614 fbcon_clear_margins(vc
, 1);
1615 scrollback_max
-= count
;
1616 if (scrollback_max
< 0)
1618 scrollback_current
= 0;
1621 static void fbcon_redraw_softback(struct vc_data
*vc
, struct fbcon_display
*p
,
1624 int count
= vc
->vc_rows
;
1625 unsigned short *d
, *s
;
1629 d
= (u16
*) softback_curr
;
1630 if (d
== (u16
*) softback_in
)
1631 d
= (u16
*) vc
->vc_origin
;
1632 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1633 softback_lines
-= delta
;
1635 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1636 n
+= softback_end
- softback_buf
;
1637 if (n
< softback_top
) {
1639 (softback_top
- n
) / vc
->vc_size_row
;
1642 } else if (softback_curr
>= softback_top
1643 && n
< softback_top
) {
1645 (softback_top
- n
) / vc
->vc_size_row
;
1649 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1650 n
+= softback_buf
- softback_end
;
1651 if (n
> softback_in
) {
1655 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1660 if (n
== softback_curr
)
1663 s
= (u16
*) softback_curr
;
1664 if (s
== (u16
*) softback_in
)
1665 s
= (u16
*) vc
->vc_origin
;
1667 unsigned short *start
;
1671 unsigned short attr
= 1;
1674 le
= advance_row(s
, 1);
1677 if (attr
!= (c
& 0xff00)) {
1680 fbcon_putcs(vc
, start
, s
- start
,
1686 if (c
== scr_readw(d
)) {
1688 fbcon_putcs(vc
, start
, s
- start
,
1701 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1703 if (d
== (u16
*) softback_end
)
1704 d
= (u16
*) softback_buf
;
1705 if (d
== (u16
*) softback_in
)
1706 d
= (u16
*) vc
->vc_origin
;
1707 if (s
== (u16
*) softback_end
)
1708 s
= (u16
*) softback_buf
;
1709 if (s
== (u16
*) softback_in
)
1710 s
= (u16
*) vc
->vc_origin
;
1714 static void fbcon_redraw_move(struct vc_data
*vc
, struct fbcon_display
*p
,
1715 int line
, int count
, int dy
)
1717 unsigned short *s
= (unsigned short *)
1718 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1721 unsigned short *start
= s
;
1722 unsigned short *le
= advance_row(s
, 1);
1725 unsigned short attr
= 1;
1729 if (attr
!= (c
& 0xff00)) {
1732 fbcon_putcs(vc
, start
, s
- start
,
1738 console_conditional_schedule();
1742 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1743 console_conditional_schedule();
1748 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1749 struct fbcon_display
*p
, int line
, int count
, int ycount
)
1751 int offset
= ycount
* vc
->vc_cols
;
1752 unsigned short *d
= (unsigned short *)
1753 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1754 unsigned short *s
= d
+ offset
;
1755 struct fbcon_ops
*ops
= info
->fbcon_par
;
1758 unsigned short *start
= s
;
1759 unsigned short *le
= advance_row(s
, 1);
1766 if (c
== scr_readw(d
)) {
1768 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1769 line
, x
, 1, s
-start
);
1779 console_conditional_schedule();
1784 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1786 console_conditional_schedule();
1791 /* NOTE: We subtract two lines from these pointers */
1792 s
-= vc
->vc_size_row
;
1793 d
-= vc
->vc_size_row
;
1798 static void fbcon_redraw(struct vc_data
*vc
, struct fbcon_display
*p
,
1799 int line
, int count
, int offset
)
1801 unsigned short *d
= (unsigned short *)
1802 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1803 unsigned short *s
= d
+ offset
;
1806 unsigned short *start
= s
;
1807 unsigned short *le
= advance_row(s
, 1);
1810 unsigned short attr
= 1;
1814 if (attr
!= (c
& 0xff00)) {
1817 fbcon_putcs(vc
, start
, s
- start
,
1823 if (c
== scr_readw(d
)) {
1825 fbcon_putcs(vc
, start
, s
- start
,
1835 console_conditional_schedule();
1840 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1841 console_conditional_schedule();
1846 /* NOTE: We subtract two lines from these pointers */
1847 s
-= vc
->vc_size_row
;
1848 d
-= vc
->vc_size_row
;
1853 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1858 if (vc
->vc_num
!= fg_console
)
1860 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1863 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1865 p
= advance_row(p
, 1);
1866 softback_in
+= vc
->vc_size_row
;
1867 if (softback_in
== softback_end
)
1868 softback_in
= softback_buf
;
1869 if (softback_in
== softback_top
) {
1870 softback_top
+= vc
->vc_size_row
;
1871 if (softback_top
== softback_end
)
1872 softback_top
= softback_buf
;
1875 softback_curr
= softback_in
;
1878 static bool fbcon_scroll(struct vc_data
*vc
, unsigned int t
, unsigned int b
,
1879 enum con_scroll dir
, unsigned int count
)
1881 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1882 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1883 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1885 if (fbcon_is_inactive(vc
, info
))
1888 fbcon_cursor(vc
, CM_ERASE
);
1891 * ++Geert: Only use ywrap/ypan if the console is in text mode
1892 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1893 * whole screen (prevents flicker).
1898 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1899 count
= vc
->vc_rows
;
1901 fbcon_softback_note(vc
, t
, count
);
1902 if (logo_shown
>= 0)
1904 switch (p
->scrollmode
) {
1906 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1908 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1909 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1912 vc
->vc_video_erase_char
,
1913 vc
->vc_size_row
* count
);
1917 case SCROLL_WRAP_MOVE
:
1918 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1920 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1922 ywrap_up(vc
, count
);
1923 if (vc
->vc_rows
- b
> 0)
1924 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1927 } else if (info
->flags
& FBINFO_READS_FAST
)
1928 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1929 b
- t
- count
, vc
->vc_cols
);
1932 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1935 case SCROLL_PAN_REDRAW
:
1936 if ((p
->yscroll
+ count
<=
1937 2 * (p
->vrows
- vc
->vc_rows
))
1938 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1941 3 * vc
->vc_rows
>> 2)))) {
1943 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1944 ypan_up_redraw(vc
, t
, count
);
1945 if (vc
->vc_rows
- b
> 0)
1946 fbcon_redraw_move(vc
, p
, b
,
1947 vc
->vc_rows
- b
, b
);
1949 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1950 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1953 case SCROLL_PAN_MOVE
:
1954 if ((p
->yscroll
+ count
<=
1955 2 * (p
->vrows
- vc
->vc_rows
))
1956 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1959 3 * vc
->vc_rows
>> 2)))) {
1961 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1964 if (vc
->vc_rows
- b
> 0)
1965 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1968 } else if (info
->flags
& FBINFO_READS_FAST
)
1969 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1970 b
- t
- count
, vc
->vc_cols
);
1973 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1978 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1979 count
* vc
->vc_cols
);
1980 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1981 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1984 vc
->vc_video_erase_char
,
1985 vc
->vc_size_row
* count
);
1991 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1992 count
= vc
->vc_rows
;
1993 if (logo_shown
>= 0)
1995 switch (p
->scrollmode
) {
1997 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1999 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2000 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2003 vc
->vc_video_erase_char
,
2004 vc
->vc_size_row
* count
);
2008 case SCROLL_WRAP_MOVE
:
2009 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
2010 if (vc
->vc_rows
- b
> 0)
2011 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
2014 ywrap_down(vc
, count
);
2016 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
2018 } else if (info
->flags
& FBINFO_READS_FAST
)
2019 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
2020 b
- t
- count
, vc
->vc_cols
);
2023 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2026 case SCROLL_PAN_MOVE
:
2027 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2028 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2031 3 * vc
->vc_rows
>> 2)))) {
2032 if (vc
->vc_rows
- b
> 0)
2033 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
2036 ypan_down(vc
, count
);
2038 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
2040 } else if (info
->flags
& FBINFO_READS_FAST
)
2041 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
2042 b
- t
- count
, vc
->vc_cols
);
2045 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2048 case SCROLL_PAN_REDRAW
:
2049 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2050 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2053 3 * vc
->vc_rows
>> 2)))) {
2054 if (vc
->vc_rows
- b
> 0)
2055 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
2057 ypan_down_redraw(vc
, t
, count
);
2059 fbcon_redraw_move(vc
, p
, count
, t
, 0);
2061 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
2062 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2067 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
2068 -count
* vc
->vc_cols
);
2069 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2070 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2073 vc
->vc_video_erase_char
,
2074 vc
->vc_size_row
* count
);
2082 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2083 int height
, int width
)
2085 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2086 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2088 if (fbcon_is_inactive(vc
, info
))
2091 if (!width
|| !height
)
2094 /* Split blits that cross physical y_wrap case.
2095 * Pathological case involves 4 blits, better to use recursive
2096 * code rather than unrolled case
2098 * Recursive invocations don't need to erase the cursor over and
2099 * over again, so we use fbcon_bmove_rec()
2101 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2102 p
->vrows
- p
->yscroll
);
2105 static void fbcon_bmove_rec(struct vc_data
*vc
, struct fbcon_display
*p
, int sy
, int sx
,
2106 int dy
, int dx
, int height
, int width
, u_int y_break
)
2108 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2109 struct fbcon_ops
*ops
= info
->fbcon_par
;
2112 if (sy
< y_break
&& sy
+ height
> y_break
) {
2114 if (dy
< sy
) { /* Avoid trashing self */
2115 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2117 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2118 height
- b
, width
, y_break
);
2120 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2121 height
- b
, width
, y_break
);
2122 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2128 if (dy
< y_break
&& dy
+ height
> y_break
) {
2130 if (dy
< sy
) { /* Avoid trashing self */
2131 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2133 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2134 height
- b
, width
, y_break
);
2136 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2137 height
- b
, width
, y_break
);
2138 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2143 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2147 static void updatescrollmode(struct fbcon_display
*p
,
2148 struct fb_info
*info
,
2151 struct fbcon_ops
*ops
= info
->fbcon_par
;
2152 int fh
= vc
->vc_font
.height
;
2153 int cap
= info
->flags
;
2155 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2156 info
->fix
.xpanstep
);
2157 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2158 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2159 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2160 info
->var
.xres_virtual
);
2161 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2162 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2163 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2164 divides(ywrap
, vc
->vc_font
.height
) &&
2165 divides(vc
->vc_font
.height
, vyres
) &&
2166 divides(vc
->vc_font
.height
, yres
);
2167 int reading_fast
= cap
& FBINFO_READS_FAST
;
2168 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2169 !(cap
& FBINFO_HWACCEL_DISABLED
);
2170 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2171 !(cap
& FBINFO_HWACCEL_DISABLED
);
2173 p
->vrows
= vyres
/fh
;
2174 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2175 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2176 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2179 if (good_wrap
|| good_pan
) {
2180 if (reading_fast
|| fast_copyarea
)
2181 p
->scrollmode
= good_wrap
?
2182 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2184 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2187 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2188 p
->scrollmode
= SCROLL_MOVE
;
2190 p
->scrollmode
= SCROLL_REDRAW
;
2194 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2195 unsigned int height
, unsigned int user
)
2197 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2198 struct fbcon_ops
*ops
= info
->fbcon_par
;
2199 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2200 struct fb_var_screeninfo var
= info
->var
;
2201 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2203 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2204 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2205 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2206 vc
->vc_font
.height
);
2207 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2209 var
.xres
= virt_w
* virt_fw
;
2210 var
.yres
= virt_h
* virt_fh
;
2211 x_diff
= info
->var
.xres
- var
.xres
;
2212 y_diff
= info
->var
.yres
- var
.yres
;
2213 if (x_diff
< 0 || x_diff
> virt_fw
||
2214 y_diff
< 0 || y_diff
> virt_fh
) {
2215 const struct fb_videomode
*mode
;
2217 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2218 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2221 display_to_var(&var
, p
);
2222 fb_videomode_to_var(&var
, mode
);
2224 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2227 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2228 if (con_is_visible(vc
)) {
2229 var
.activate
= FB_ACTIVATE_NOW
|
2231 fb_set_var(info
, &var
);
2233 var_to_display(p
, &info
->var
, info
);
2234 ops
->var
= info
->var
;
2236 updatescrollmode(p
, info
, vc
);
2240 static int fbcon_switch(struct vc_data
*vc
)
2242 struct fb_info
*info
, *old_info
= NULL
;
2243 struct fbcon_ops
*ops
;
2244 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2245 struct fb_var_screeninfo var
;
2246 int i
, ret
, prev_console
, charcnt
= 256;
2248 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2249 ops
= info
->fbcon_par
;
2253 fbcon_set_origin(vc
);
2254 softback_top
= softback_curr
= softback_in
= softback_buf
;
2256 fbcon_update_softback(vc
);
2259 if (logo_shown
>= 0) {
2260 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2262 if (conp2
->vc_top
== logo_lines
2263 && conp2
->vc_bottom
== conp2
->vc_rows
)
2265 logo_shown
= FBCON_LOGO_CANSHOW
;
2268 prev_console
= ops
->currcon
;
2269 if (prev_console
!= -1)
2270 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2272 * FIXME: If we have multiple fbdev's loaded, we need to
2273 * update all info->currcon. Perhaps, we can place this
2274 * in a centralized structure, but this might break some
2277 * info->currcon = vc->vc_num;
2279 for_each_registered_fb(i
) {
2280 if (registered_fb
[i
]->fbcon_par
) {
2281 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2283 o
->currcon
= vc
->vc_num
;
2286 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2287 display_to_var(&var
, p
);
2288 var
.activate
= FB_ACTIVATE_NOW
;
2291 * make sure we don't unnecessarily trip the memcmp()
2294 info
->var
.activate
= var
.activate
;
2295 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2296 fb_set_var(info
, &var
);
2297 ops
->var
= info
->var
;
2299 if (old_info
!= NULL
&& (old_info
!= info
||
2300 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2301 if (info
->fbops
->fb_set_par
) {
2302 ret
= info
->fbops
->fb_set_par(info
);
2305 printk(KERN_ERR
"fbcon_switch: detected "
2306 "unhandled fb_set_par error, "
2307 "error code %d\n", ret
);
2310 if (old_info
!= info
)
2311 fbcon_del_cursor_timer(old_info
);
2314 if (fbcon_is_inactive(vc
, info
) ||
2315 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2316 fbcon_del_cursor_timer(info
);
2318 fbcon_add_cursor_timer(info
);
2320 set_blitting_type(vc
, info
);
2321 ops
->cursor_reset
= 1;
2323 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2324 ops
->rotate
= FB_ROTATE_UR
;
2325 set_blitting_type(vc
, info
);
2328 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2329 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2332 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2335 vc
->vc_complement_mask
<<= 1;
2337 updatescrollmode(p
, info
, vc
);
2339 switch (p
->scrollmode
) {
2340 case SCROLL_WRAP_MOVE
:
2341 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2343 case SCROLL_PAN_MOVE
:
2344 case SCROLL_PAN_REDRAW
:
2345 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2346 if (scrollback_phys_max
< 0)
2347 scrollback_phys_max
= 0;
2350 scrollback_phys_max
= 0;
2355 scrollback_current
= 0;
2357 if (!fbcon_is_inactive(vc
, info
)) {
2358 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2359 ops
->update_start(info
);
2362 fbcon_set_palette(vc
, color_table
);
2363 fbcon_clear_margins(vc
, 0);
2365 if (logo_shown
== FBCON_LOGO_DRAW
) {
2367 logo_shown
= fg_console
;
2368 /* This is protected above by initmem_freed */
2369 fb_show_logo(info
, ops
->rotate
);
2371 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2372 vc
->vc_size_row
* (vc
->vc_bottom
-
2379 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2383 unsigned short charmask
= vc
->vc_hi_font_mask
?
2385 unsigned short oldc
;
2387 oldc
= vc
->vc_video_erase_char
;
2388 vc
->vc_video_erase_char
&= charmask
;
2389 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2390 vc
->vc_video_erase_char
= oldc
;
2394 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2396 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2397 struct fbcon_ops
*ops
= info
->fbcon_par
;
2400 struct fb_var_screeninfo var
= info
->var
;
2405 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2406 fb_set_var(info
, &var
);
2408 ops
->var
= info
->var
;
2412 if (!fbcon_is_inactive(vc
, info
)) {
2413 if (ops
->blank_state
!= blank
) {
2414 ops
->blank_state
= blank
;
2415 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2416 ops
->cursor_flash
= (!blank
);
2418 if (fb_blank(info
, blank
))
2419 fbcon_generic_blank(vc
, info
, blank
);
2426 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2427 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2428 fbcon_del_cursor_timer(info
);
2430 fbcon_add_cursor_timer(info
);
2435 static int fbcon_debug_enter(struct vc_data
*vc
)
2437 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2438 struct fbcon_ops
*ops
= info
->fbcon_par
;
2440 ops
->save_graphics
= ops
->graphics
;
2442 if (info
->fbops
->fb_debug_enter
)
2443 info
->fbops
->fb_debug_enter(info
);
2444 fbcon_set_palette(vc
, color_table
);
2448 static int fbcon_debug_leave(struct vc_data
*vc
)
2450 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2451 struct fbcon_ops
*ops
= info
->fbcon_par
;
2453 ops
->graphics
= ops
->save_graphics
;
2454 if (info
->fbops
->fb_debug_leave
)
2455 info
->fbops
->fb_debug_leave(info
);
2459 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2461 u8
*fontdata
= vc
->vc_font
.data
;
2462 u8
*data
= font
->data
;
2465 font
->width
= vc
->vc_font
.width
;
2466 font
->height
= vc
->vc_font
.height
;
2467 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2471 if (font
->width
<= 8) {
2472 j
= vc
->vc_font
.height
;
2473 for (i
= 0; i
< font
->charcount
; i
++) {
2474 memcpy(data
, fontdata
, j
);
2475 memset(data
+ j
, 0, 32 - j
);
2479 } else if (font
->width
<= 16) {
2480 j
= vc
->vc_font
.height
* 2;
2481 for (i
= 0; i
< font
->charcount
; i
++) {
2482 memcpy(data
, fontdata
, j
);
2483 memset(data
+ j
, 0, 64 - j
);
2487 } else if (font
->width
<= 24) {
2488 for (i
= 0; i
< font
->charcount
; i
++) {
2489 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2490 *data
++ = fontdata
[0];
2491 *data
++ = fontdata
[1];
2492 *data
++ = fontdata
[2];
2493 fontdata
+= sizeof(u32
);
2495 memset(data
, 0, 3 * (32 - j
));
2496 data
+= 3 * (32 - j
);
2499 j
= vc
->vc_font
.height
* 4;
2500 for (i
= 0; i
< font
->charcount
; i
++) {
2501 memcpy(data
, fontdata
, j
);
2502 memset(data
+ j
, 0, 128 - j
);
2510 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2511 static void set_vc_hi_font(struct vc_data
*vc
, bool set
)
2514 vc
->vc_hi_font_mask
= 0;
2515 if (vc
->vc_can_do_color
) {
2516 vc
->vc_complement_mask
>>= 1;
2517 vc
->vc_s_complement_mask
>>= 1;
2520 /* ++Edmund: reorder the attribute bits */
2521 if (vc
->vc_can_do_color
) {
2522 unsigned short *cp
=
2523 (unsigned short *) vc
->vc_origin
;
2524 int count
= vc
->vc_screenbuf_size
/ 2;
2526 for (; count
> 0; count
--, cp
++) {
2528 scr_writew(((c
& 0xfe00) >> 1) |
2531 c
= vc
->vc_video_erase_char
;
2532 vc
->vc_video_erase_char
=
2533 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2537 vc
->vc_hi_font_mask
= 0x100;
2538 if (vc
->vc_can_do_color
) {
2539 vc
->vc_complement_mask
<<= 1;
2540 vc
->vc_s_complement_mask
<<= 1;
2543 /* ++Edmund: reorder the attribute bits */
2545 unsigned short *cp
=
2546 (unsigned short *) vc
->vc_origin
;
2547 int count
= vc
->vc_screenbuf_size
/ 2;
2549 for (; count
> 0; count
--, cp
++) {
2550 unsigned short newc
;
2552 if (vc
->vc_can_do_color
)
2554 ((c
& 0xff00) << 1) | (c
&
2558 scr_writew(newc
, cp
);
2560 c
= vc
->vc_video_erase_char
;
2561 if (vc
->vc_can_do_color
) {
2562 vc
->vc_video_erase_char
=
2563 ((c
& 0xff00) << 1) | (c
& 0xff);
2566 vc
->vc_video_erase_char
= c
& ~0x100;
2571 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2572 const u8
* data
, int userfont
)
2574 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2575 struct fbcon_ops
*ops
= info
->fbcon_par
;
2576 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2579 char *old_data
= NULL
;
2581 if (con_is_visible(vc
) && softback_lines
)
2582 fbcon_set_origin(vc
);
2584 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2586 old_data
= vc
->vc_font
.data
;
2588 cnt
= FNTCHARCNT(data
);
2591 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2592 if ((p
->userfont
= userfont
))
2594 vc
->vc_font
.width
= w
;
2595 vc
->vc_font
.height
= h
;
2596 if (vc
->vc_hi_font_mask
&& cnt
== 256)
2597 set_vc_hi_font(vc
, false);
2598 else if (!vc
->vc_hi_font_mask
&& cnt
== 512)
2599 set_vc_hi_font(vc
, true);
2604 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2605 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2608 vc_resize(vc
, cols
, rows
);
2609 if (con_is_visible(vc
) && softback_buf
)
2610 fbcon_update_softback(vc
);
2611 } else if (con_is_visible(vc
)
2612 && vc
->vc_mode
== KD_TEXT
) {
2613 fbcon_clear_margins(vc
, 0);
2617 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2618 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2622 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2624 struct fbcon_display
*od
= &fb_display
[con
];
2625 struct console_font
*f
= &vc
->vc_font
;
2627 if (od
->fontdata
== f
->data
)
2628 return 0; /* already the same font... */
2629 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2633 * User asked to set font; we are guaranteed that
2634 * a) width and height are in range 1..32
2635 * b) charcount does not exceed 512
2636 * but lets not assume that, since someone might someday want to use larger
2637 * fonts. And charcount of 512 is small for unicode support.
2639 * However, user space gives the font in 32 rows , regardless of
2640 * actual font height. So a new API is needed if support for larger fonts
2641 * is ever implemented.
2644 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
,
2647 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2648 unsigned charcount
= font
->charcount
;
2649 int w
= font
->width
;
2650 int h
= font
->height
;
2653 u8
*new_data
, *data
= font
->data
;
2654 int pitch
= (font
->width
+7) >> 3;
2656 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2657 * If not this check should be changed to charcount < 256 */
2658 if (charcount
!= 256 && charcount
!= 512)
2661 /* Make sure drawing engine can handle the font */
2662 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2663 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2666 /* Make sure driver can handle the font length */
2667 if (fbcon_invalid_charcount(info
, charcount
))
2670 size
= h
* pitch
* charcount
;
2672 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2677 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2678 FNTSIZE(new_data
) = size
;
2679 FNTCHARCNT(new_data
) = charcount
;
2680 REFCOUNT(new_data
) = 0; /* usage counter */
2681 for (i
=0; i
< charcount
; i
++) {
2682 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2685 /* Since linux has a nice crc32 function use it for counting font
2687 csum
= crc32(0, new_data
, size
);
2689 FNTSUM(new_data
) = csum
;
2690 /* Check if the same font is on some other console already */
2691 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2692 struct vc_data
*tmp
= vc_cons
[i
].d
;
2694 if (fb_display
[i
].userfont
&&
2695 fb_display
[i
].fontdata
&&
2696 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2697 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2698 tmp
->vc_font
.width
== w
&&
2699 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2700 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2701 new_data
= (u8
*)fb_display
[i
].fontdata
;
2705 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2708 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2710 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2711 const struct font_desc
*f
;
2714 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2715 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2716 else if (!(f
= find_font(name
)))
2719 font
->width
= f
->width
;
2720 font
->height
= f
->height
;
2721 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2724 static u16 palette_red
[16];
2725 static u16 palette_green
[16];
2726 static u16 palette_blue
[16];
2728 static struct fb_cmap palette_cmap
= {
2729 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2732 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
)
2734 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2738 if (fbcon_is_inactive(vc
, info
))
2741 if (!con_is_visible(vc
))
2744 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2746 for (i
= j
= 0; i
< 16; i
++) {
2748 val
= vc
->vc_palette
[j
++];
2749 palette_red
[k
] = (val
<< 8) | val
;
2750 val
= vc
->vc_palette
[j
++];
2751 palette_green
[k
] = (val
<< 8) | val
;
2752 val
= vc
->vc_palette
[j
++];
2753 palette_blue
[k
] = (val
<< 8) | val
;
2755 palette_cmap
.len
= 16;
2756 palette_cmap
.start
= 0;
2758 * If framebuffer is capable of less than 16 colors,
2759 * use default palette of fbcon.
2762 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2764 fb_set_cmap(&palette_cmap
, info
);
2767 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2772 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2773 return (u16
*) (vc
->vc_origin
+ offset
);
2774 line
= offset
/ vc
->vc_size_row
;
2775 if (line
>= softback_lines
)
2776 return (u16
*) (vc
->vc_origin
+ offset
-
2777 softback_lines
* vc
->vc_size_row
);
2778 p
= softback_curr
+ offset
;
2779 if (p
>= softback_end
)
2780 p
+= softback_buf
- softback_end
;
2784 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2790 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2791 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2793 x
= offset
% vc
->vc_cols
;
2794 y
= offset
/ vc
->vc_cols
;
2795 if (vc
->vc_num
== fg_console
)
2796 y
+= softback_lines
;
2797 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2798 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2799 unsigned long offset
= pos
- softback_curr
;
2801 if (pos
< softback_curr
)
2802 offset
+= softback_end
- softback_buf
;
2804 x
= offset
% vc
->vc_cols
;
2805 y
= offset
/ vc
->vc_cols
;
2806 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2807 if (ret
== softback_end
)
2809 if (ret
== softback_in
)
2810 ret
= vc
->vc_origin
;
2812 /* Should not happen */
2814 ret
= vc
->vc_origin
;
2823 /* As we might be inside of softback, we may work with non-contiguous buffer,
2824 that's why we have to use a separate routine. */
2825 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2828 u16 a
= scr_readw(p
);
2829 if (!vc
->vc_can_do_color
)
2831 else if (vc
->vc_hi_font_mask
== 0x100)
2832 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2833 (((a
) & 0x0e00) << 4);
2835 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2836 (((a
) & 0x0700) << 4);
2838 if (p
== (u16
*) softback_end
)
2839 p
= (u16
*) softback_buf
;
2840 if (p
== (u16
*) softback_in
)
2841 p
= (u16
*) vc
->vc_origin
;
2845 static void fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2847 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2848 struct fbcon_ops
*ops
= info
->fbcon_par
;
2849 struct fbcon_display
*disp
= &fb_display
[fg_console
];
2850 int offset
, limit
, scrollback_old
;
2853 if (vc
->vc_num
!= fg_console
)
2855 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2857 if (logo_shown
>= 0) {
2858 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2860 if (conp2
->vc_top
== logo_lines
2861 && conp2
->vc_bottom
== conp2
->vc_rows
)
2863 if (logo_shown
== vc
->vc_num
) {
2869 logo_lines
* vc
->vc_size_row
;
2870 for (i
= 0; i
< logo_lines
; i
++) {
2871 if (p
== softback_top
)
2873 if (p
== softback_buf
)
2875 p
-= vc
->vc_size_row
;
2876 q
-= vc
->vc_size_row
;
2877 scr_memcpyw((u16
*) q
, (u16
*) p
,
2880 softback_in
= softback_curr
= p
;
2881 update_region(vc
, vc
->vc_origin
,
2882 logo_lines
* vc
->vc_cols
);
2884 logo_shown
= FBCON_LOGO_CANSHOW
;
2886 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2887 fbcon_redraw_softback(vc
, disp
, lines
);
2888 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2892 if (!scrollback_phys_max
)
2895 scrollback_old
= scrollback_current
;
2896 scrollback_current
-= lines
;
2897 if (scrollback_current
< 0)
2898 scrollback_current
= 0;
2899 else if (scrollback_current
> scrollback_max
)
2900 scrollback_current
= scrollback_max
;
2901 if (scrollback_current
== scrollback_old
)
2904 if (fbcon_is_inactive(vc
, info
))
2907 fbcon_cursor(vc
, CM_ERASE
);
2909 offset
= disp
->yscroll
- scrollback_current
;
2910 limit
= disp
->vrows
;
2911 switch (disp
->scrollmode
) {
2912 case SCROLL_WRAP_MOVE
:
2913 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2915 case SCROLL_PAN_MOVE
:
2916 case SCROLL_PAN_REDRAW
:
2917 limit
-= vc
->vc_rows
;
2918 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2923 else if (offset
>= limit
)
2926 ops
->var
.xoffset
= 0;
2927 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2928 ops
->update_start(info
);
2930 if (!scrollback_current
)
2931 fbcon_cursor(vc
, CM_DRAW
);
2934 static int fbcon_set_origin(struct vc_data
*vc
)
2937 fbcon_scrolldelta(vc
, softback_lines
);
2941 void fbcon_suspended(struct fb_info
*info
)
2943 struct vc_data
*vc
= NULL
;
2944 struct fbcon_ops
*ops
= info
->fbcon_par
;
2946 if (!ops
|| ops
->currcon
< 0)
2948 vc
= vc_cons
[ops
->currcon
].d
;
2950 /* Clear cursor, restore saved data */
2951 fbcon_cursor(vc
, CM_ERASE
);
2954 void fbcon_resumed(struct fb_info
*info
)
2957 struct fbcon_ops
*ops
= info
->fbcon_par
;
2959 if (!ops
|| ops
->currcon
< 0)
2961 vc
= vc_cons
[ops
->currcon
].d
;
2966 static void fbcon_modechanged(struct fb_info
*info
)
2968 struct fbcon_ops
*ops
= info
->fbcon_par
;
2970 struct fbcon_display
*p
;
2973 if (!ops
|| ops
->currcon
< 0)
2975 vc
= vc_cons
[ops
->currcon
].d
;
2976 if (vc
->vc_mode
!= KD_TEXT
||
2977 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2980 p
= &fb_display
[vc
->vc_num
];
2981 set_blitting_type(vc
, info
);
2983 if (con_is_visible(vc
)) {
2984 var_to_display(p
, &info
->var
, info
);
2985 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2986 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2987 cols
/= vc
->vc_font
.width
;
2988 rows
/= vc
->vc_font
.height
;
2989 vc_resize(vc
, cols
, rows
);
2990 updatescrollmode(p
, info
, vc
);
2992 scrollback_current
= 0;
2994 if (!fbcon_is_inactive(vc
, info
)) {
2995 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2996 ops
->update_start(info
);
2999 fbcon_set_palette(vc
, color_table
);
3002 fbcon_update_softback(vc
);
3006 static void fbcon_set_all_vcs(struct fb_info
*info
)
3008 struct fbcon_ops
*ops
= info
->fbcon_par
;
3010 struct fbcon_display
*p
;
3011 int i
, rows
, cols
, fg
= -1;
3013 if (!ops
|| ops
->currcon
< 0)
3016 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3018 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
3019 registered_fb
[con2fb_map
[i
]] != info
)
3022 if (con_is_visible(vc
)) {
3027 p
= &fb_display
[vc
->vc_num
];
3028 set_blitting_type(vc
, info
);
3029 var_to_display(p
, &info
->var
, info
);
3030 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
3031 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
3032 cols
/= vc
->vc_font
.width
;
3033 rows
/= vc
->vc_font
.height
;
3034 vc_resize(vc
, cols
, rows
);
3038 fbcon_modechanged(info
);
3042 void fbcon_update_vcs(struct fb_info
*info
, bool all
)
3045 fbcon_set_all_vcs(info
);
3047 fbcon_modechanged(info
);
3049 EXPORT_SYMBOL(fbcon_update_vcs
);
3051 int fbcon_mode_deleted(struct fb_info
*info
,
3052 struct fb_videomode
*mode
)
3054 struct fb_info
*fb_info
;
3055 struct fbcon_display
*p
;
3056 int i
, j
, found
= 0;
3058 /* before deletion, ensure that mode is not in use */
3059 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3063 fb_info
= registered_fb
[j
];
3064 if (fb_info
!= info
)
3069 if (fb_mode_is_equal(p
->mode
, mode
)) {
3077 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3078 static void fbcon_unbind(void)
3082 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3086 fbcon_has_console_bind
= 0;
3089 static inline void fbcon_unbind(void) {}
3090 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3092 /* called with console_lock held */
3093 void fbcon_fb_unbind(struct fb_info
*info
)
3095 int i
, new_idx
= -1, ret
= 0;
3096 int idx
= info
->node
;
3098 WARN_CONSOLE_UNLOCKED();
3100 if (!fbcon_has_console_bind
)
3103 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3104 if (con2fb_map
[i
] != idx
&&
3105 con2fb_map
[i
] != -1) {
3106 new_idx
= con2fb_map
[i
];
3111 if (new_idx
!= -1) {
3112 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3113 if (con2fb_map
[i
] == idx
)
3114 set_con2fb_map(i
, new_idx
, 0);
3117 struct fb_info
*info
= registered_fb
[idx
];
3119 /* This is sort of like set_con2fb_map, except it maps
3120 * the consoles to no device and then releases the
3121 * oldinfo to free memory and cancel the cursor blink
3122 * timer. I can imagine this just becoming part of
3123 * set_con2fb_map where new_idx is -1
3125 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3126 if (con2fb_map
[i
] == idx
) {
3128 if (!search_fb_in_map(idx
)) {
3129 ret
= con2fb_release_oldinfo(vc_cons
[i
].d
,
3133 con2fb_map
[i
] = idx
;
3143 /* called with console_lock held */
3144 void fbcon_fb_unregistered(struct fb_info
*info
)
3148 WARN_CONSOLE_UNLOCKED();
3150 if (deferred_takeover
)
3154 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3155 if (con2fb_map
[i
] == idx
)
3159 if (idx
== info_idx
) {
3162 for_each_registered_fb(i
) {
3168 if (info_idx
!= -1) {
3169 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3170 if (con2fb_map
[i
] == -1)
3171 con2fb_map
[i
] = info_idx
;
3175 if (primary_device
== idx
)
3176 primary_device
= -1;
3178 if (!num_registered_fb
)
3179 do_unregister_con_driver(&fb_con
);
3182 void fbcon_remap_all(struct fb_info
*info
)
3184 int i
, idx
= info
->node
;
3187 if (deferred_takeover
) {
3188 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3189 con2fb_map_boot
[i
] = idx
;
3190 fbcon_map_override();
3195 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3196 set_con2fb_map(i
, idx
, 0);
3198 if (con_is_bound(&fb_con
)) {
3199 printk(KERN_INFO
"fbcon: Remapping primary device, "
3200 "fb%i, to tty %i-%i\n", idx
,
3201 first_fb_vc
+ 1, last_fb_vc
+ 1);
3207 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3208 static void fbcon_select_primary(struct fb_info
*info
)
3210 if (!map_override
&& primary_device
== -1 &&
3211 fb_is_primary_device(info
)) {
3214 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3215 info
->fix
.id
, info
->node
);
3216 primary_device
= info
->node
;
3218 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3219 con2fb_map_boot
[i
] = primary_device
;
3221 if (con_is_bound(&fb_con
)) {
3222 printk(KERN_INFO
"fbcon: Remapping primary device, "
3223 "fb%i, to tty %i-%i\n", info
->node
,
3224 first_fb_vc
+ 1, last_fb_vc
+ 1);
3225 info_idx
= primary_device
;
3231 static inline void fbcon_select_primary(struct fb_info
*info
)
3235 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3237 /* called with console_lock held */
3238 int fbcon_fb_registered(struct fb_info
*info
)
3240 int ret
= 0, i
, idx
;
3242 WARN_CONSOLE_UNLOCKED();
3245 fbcon_select_primary(info
);
3247 if (deferred_takeover
) {
3248 pr_info("fbcon: Deferring console take-over\n");
3252 if (info_idx
== -1) {
3253 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3254 if (con2fb_map_boot
[i
] == idx
) {
3261 ret
= do_fbcon_takeover(1);
3263 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3264 if (con2fb_map_boot
[i
] == idx
)
3265 set_con2fb_map(i
, idx
, 0);
3272 void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3274 struct fbcon_ops
*ops
= info
->fbcon_par
;
3277 if (!ops
|| ops
->currcon
< 0)
3280 vc
= vc_cons
[ops
->currcon
].d
;
3281 if (vc
->vc_mode
!= KD_TEXT
||
3282 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3285 if (con_is_visible(vc
)) {
3289 do_unblank_screen(0);
3291 ops
->blank_state
= blank
;
3294 void fbcon_new_modelist(struct fb_info
*info
)
3298 struct fb_var_screeninfo var
;
3299 const struct fb_videomode
*mode
;
3301 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3302 if (registered_fb
[con2fb_map
[i
]] != info
)
3304 if (!fb_display
[i
].mode
)
3307 display_to_var(&var
, &fb_display
[i
]);
3308 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3310 fb_videomode_to_var(&var
, mode
);
3311 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3315 void fbcon_get_requirement(struct fb_info
*info
,
3316 struct fb_blit_caps
*caps
)
3319 struct fbcon_display
*p
;
3324 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3326 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3327 info
->node
== con2fb_map
[i
]) {
3329 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3330 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3331 charcnt
= (p
->userfont
) ?
3332 FNTCHARCNT(p
->fontdata
) : 256;
3333 if (caps
->len
< charcnt
)
3334 caps
->len
= charcnt
;
3338 vc
= vc_cons
[fg_console
].d
;
3340 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3341 info
->node
== con2fb_map
[fg_console
]) {
3342 p
= &fb_display
[fg_console
];
3343 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3344 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3345 caps
->len
= (p
->userfont
) ?
3346 FNTCHARCNT(p
->fontdata
) : 256;
3351 int fbcon_set_con2fb_map_ioctl(void __user
*argp
)
3353 struct fb_con2fbmap con2fb
;
3356 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
3358 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
3360 if (con2fb
.framebuffer
>= FB_MAX
)
3362 if (!registered_fb
[con2fb
.framebuffer
])
3363 request_module("fb%d", con2fb
.framebuffer
);
3364 if (!registered_fb
[con2fb
.framebuffer
]) {
3369 ret
= set_con2fb_map(con2fb
.console
- 1,
3370 con2fb
.framebuffer
, 1);
3376 int fbcon_get_con2fb_map_ioctl(void __user
*argp
)
3378 struct fb_con2fbmap con2fb
;
3380 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
3382 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
3386 con2fb
.framebuffer
= con2fb_map
[con2fb
.console
- 1];
3389 return copy_to_user(argp
, &con2fb
, sizeof(con2fb
)) ? -EFAULT
: 0;
3393 * The console `switch' structure for the frame buffer based console
3396 static const struct consw fb_con
= {
3397 .owner
= THIS_MODULE
,
3398 .con_startup
= fbcon_startup
,
3399 .con_init
= fbcon_init
,
3400 .con_deinit
= fbcon_deinit
,
3401 .con_clear
= fbcon_clear
,
3402 .con_putc
= fbcon_putc
,
3403 .con_putcs
= fbcon_putcs
,
3404 .con_cursor
= fbcon_cursor
,
3405 .con_scroll
= fbcon_scroll
,
3406 .con_switch
= fbcon_switch
,
3407 .con_blank
= fbcon_blank
,
3408 .con_font_set
= fbcon_set_font
,
3409 .con_font_get
= fbcon_get_font
,
3410 .con_font_default
= fbcon_set_def_font
,
3411 .con_font_copy
= fbcon_copy_font
,
3412 .con_set_palette
= fbcon_set_palette
,
3413 .con_scrolldelta
= fbcon_scrolldelta
,
3414 .con_set_origin
= fbcon_set_origin
,
3415 .con_invert_region
= fbcon_invert_region
,
3416 .con_screen_pos
= fbcon_screen_pos
,
3417 .con_getxy
= fbcon_getxy
,
3418 .con_resize
= fbcon_resize
,
3419 .con_debug_enter
= fbcon_debug_enter
,
3420 .con_debug_leave
= fbcon_debug_leave
,
3423 static ssize_t
store_rotate(struct device
*device
,
3424 struct device_attribute
*attr
, const char *buf
,
3427 struct fb_info
*info
;
3432 idx
= con2fb_map
[fg_console
];
3434 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3437 info
= registered_fb
[idx
];
3438 rotate
= simple_strtoul(buf
, last
, 0);
3439 fbcon_rotate(info
, rotate
);
3445 static ssize_t
store_rotate_all(struct device
*device
,
3446 struct device_attribute
*attr
,const char *buf
,
3449 struct fb_info
*info
;
3454 idx
= con2fb_map
[fg_console
];
3456 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3459 info
= registered_fb
[idx
];
3460 rotate
= simple_strtoul(buf
, last
, 0);
3461 fbcon_rotate_all(info
, rotate
);
3467 static ssize_t
show_rotate(struct device
*device
,
3468 struct device_attribute
*attr
,char *buf
)
3470 struct fb_info
*info
;
3471 int rotate
= 0, idx
;
3474 idx
= con2fb_map
[fg_console
];
3476 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3479 info
= registered_fb
[idx
];
3480 rotate
= fbcon_get_rotate(info
);
3483 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3486 static ssize_t
show_cursor_blink(struct device
*device
,
3487 struct device_attribute
*attr
, char *buf
)
3489 struct fb_info
*info
;
3490 struct fbcon_ops
*ops
;
3491 int idx
, blink
= -1;
3494 idx
= con2fb_map
[fg_console
];
3496 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3499 info
= registered_fb
[idx
];
3500 ops
= info
->fbcon_par
;
3505 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3508 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3511 static ssize_t
store_cursor_blink(struct device
*device
,
3512 struct device_attribute
*attr
,
3513 const char *buf
, size_t count
)
3515 struct fb_info
*info
;
3520 idx
= con2fb_map
[fg_console
];
3522 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3525 info
= registered_fb
[idx
];
3527 if (!info
->fbcon_par
)
3530 blink
= simple_strtoul(buf
, last
, 0);
3533 fbcon_cursor_noblink
= 0;
3534 fbcon_add_cursor_timer(info
);
3536 fbcon_cursor_noblink
= 1;
3537 fbcon_del_cursor_timer(info
);
3545 static struct device_attribute device_attrs
[] = {
3546 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3547 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3548 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3549 store_cursor_blink
),
3552 static int fbcon_init_device(void)
3556 fbcon_has_sysfs
= 1;
3558 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3559 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3567 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3569 fbcon_has_sysfs
= 0;
3575 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3576 static void fbcon_register_existing_fbs(struct work_struct
*work
)
3582 for_each_registered_fb(i
)
3583 fbcon_fb_registered(registered_fb
[i
]);
3588 static struct notifier_block fbcon_output_nb
;
3589 static DECLARE_WORK(fbcon_deferred_takeover_work
, fbcon_register_existing_fbs
);
3591 static int fbcon_output_notifier(struct notifier_block
*nb
,
3592 unsigned long action
, void *data
)
3594 WARN_CONSOLE_UNLOCKED();
3596 pr_info("fbcon: Taking over console\n");
3598 dummycon_unregister_output_notifier(&fbcon_output_nb
);
3599 deferred_takeover
= false;
3600 logo_shown
= FBCON_LOGO_DONTSHOW
;
3602 /* We may get called in atomic context */
3603 schedule_work(&fbcon_deferred_takeover_work
);
3609 static void fbcon_start(void)
3611 WARN_CONSOLE_UNLOCKED();
3613 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3614 if (conswitchp
!= &dummy_con
)
3615 deferred_takeover
= false;
3617 if (deferred_takeover
) {
3618 fbcon_output_nb
.notifier_call
= fbcon_output_notifier
;
3619 dummycon_register_output_notifier(&fbcon_output_nb
);
3624 if (num_registered_fb
) {
3627 for_each_registered_fb(i
) {
3632 do_fbcon_takeover(0);
3636 static void fbcon_exit(void)
3638 struct fb_info
*info
;
3641 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3642 if (deferred_takeover
) {
3643 dummycon_unregister_output_notifier(&fbcon_output_nb
);
3644 deferred_takeover
= false;
3648 kvfree((void *)softback_buf
);
3651 for_each_registered_fb(i
) {
3655 info
= registered_fb
[i
];
3657 if (info
->queue
.func
)
3658 pending
= cancel_work_sync(&info
->queue
);
3659 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3662 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3663 if (con2fb_map
[j
] == i
) {
3670 if (info
->fbops
->fb_release
)
3671 info
->fbops
->fb_release(info
, 0);
3672 module_put(info
->fbops
->owner
);
3674 if (info
->fbcon_par
) {
3675 struct fbcon_ops
*ops
= info
->fbcon_par
;
3677 fbcon_del_cursor_timer(info
);
3678 kfree(ops
->cursor_src
);
3679 kfree(ops
->cursor_state
.mask
);
3680 kfree(info
->fbcon_par
);
3681 info
->fbcon_par
= NULL
;
3684 if (info
->queue
.func
== fb_flashcursor
)
3685 info
->queue
.func
= NULL
;
3690 void __init
fb_console_init(void)
3695 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3698 if (IS_ERR(fbcon_device
)) {
3699 printk(KERN_WARNING
"Unable to create device "
3700 "for fbcon; errno = %ld\n",
3701 PTR_ERR(fbcon_device
));
3702 fbcon_device
= NULL
;
3704 fbcon_init_device();
3706 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3715 static void __exit
fbcon_deinit_device(void)
3719 if (fbcon_has_sysfs
) {
3720 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3721 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3723 fbcon_has_sysfs
= 0;
3727 void __exit
fb_console_exit(void)
3730 fbcon_deinit_device();
3731 device_destroy(fb_class
, MKDEV(0, 0));
3733 do_unregister_con_driver(&fb_con
);