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
59 #include <linux/module.h>
60 #include <linux/types.h>
62 #include <linux/kernel.h>
63 #include <linux/delay.h> /* MSch: for IRQ probe */
64 #include <linux/console.h>
65 #include <linux/string.h>
67 #include <linux/panic.h>
68 #include <linux/printk.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>
83 #include "fb_internal.h"
88 * - fbcon state itself is protected by the console_lock, and the code does a
89 * pretty good job at making sure that lock is held everywhere it's needed.
91 * - fbcon doesn't bother with fb_lock/unlock at all. This is buggy, since it
92 * means concurrent access to the same fbdev from both fbcon and userspace
93 * will blow up. To fix this all fbcon calls from fbmem.c need to be moved out
94 * of fb_lock/unlock protected sections, since otherwise we'll recurse and
95 * deadlock eventually. Aside: Due to these deadlock issues the fbdev code in
96 * fbmem.c cannot use locking asserts, and there's lots of callers which get
97 * the rules wrong, e.g. fbsysfs.c entirely missed fb_lock/unlock calls too.
101 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
106 static struct fbcon_display fb_display
[MAX_NR_CONSOLES
];
108 static struct fb_info
*fbcon_registered_fb
[FB_MAX
];
109 static int fbcon_num_registered_fb
;
111 #define fbcon_for_each_registered_fb(i) \
112 for (i = 0; WARN_CONSOLE_UNLOCKED(), i < FB_MAX; i++) \
113 if (!fbcon_registered_fb[i]) {} else
115 static signed char con2fb_map
[MAX_NR_CONSOLES
];
116 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
118 static struct fb_info
*fbcon_info_from_console(int console
)
120 WARN_CONSOLE_UNLOCKED();
122 return fbcon_registered_fb
[con2fb_map
[console
]];
125 static int logo_lines
;
126 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
128 static int logo_shown
= FBCON_LOGO_CANSHOW
;
129 /* console mappings */
130 static unsigned int first_fb_vc
;
131 static unsigned int last_fb_vc
= MAX_NR_CONSOLES
- 1;
132 static int fbcon_is_default
= 1;
133 static int primary_device
= -1;
134 static int fbcon_has_console_bind
;
136 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
137 static int map_override
;
139 static inline void fbcon_map_override(void)
144 static inline void fbcon_map_override(void)
147 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
149 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
150 static bool deferred_takeover
= true;
152 #define deferred_takeover false
156 static char fontname
[40];
158 /* current fb_info */
159 static int info_idx
= -1;
161 /* console rotation */
162 static int initial_rotation
= -1;
163 static int fbcon_has_sysfs
;
164 static int margin_color
;
166 static const struct consw fb_con
;
168 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
170 static int fbcon_cursor_noblink
;
172 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
175 * Interface used by the world
178 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
179 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
);
184 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
186 static void fbcon_redraw_move(struct vc_data
*vc
, struct fbcon_display
*p
,
187 int line
, int count
, int dy
);
188 static void fbcon_modechanged(struct fb_info
*info
);
189 static void fbcon_set_all_vcs(struct fb_info
*info
);
191 static struct device
*fbcon_device
;
193 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
194 static inline void fbcon_set_rotation(struct fb_info
*info
)
196 struct fbcon_ops
*ops
= info
->fbcon_par
;
198 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
199 ops
->p
->con_rotate
< 4)
200 ops
->rotate
= ops
->p
->con_rotate
;
205 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
207 struct fbcon_ops
*ops
= info
->fbcon_par
;
208 struct fb_info
*fb_info
;
210 if (!ops
|| ops
->currcon
== -1)
213 fb_info
= fbcon_info_from_console(ops
->currcon
);
215 if (info
== fb_info
) {
216 struct fbcon_display
*p
= &fb_display
[ops
->currcon
];
219 p
->con_rotate
= rotate
;
223 fbcon_modechanged(info
);
227 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
229 struct fbcon_ops
*ops
= info
->fbcon_par
;
231 struct fbcon_display
*p
;
234 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
237 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
239 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
240 fbcon_info_from_console(i
) != info
)
243 p
= &fb_display
[vc
->vc_num
];
244 p
->con_rotate
= rotate
;
247 fbcon_set_all_vcs(info
);
250 static inline void fbcon_set_rotation(struct fb_info
*info
)
252 struct fbcon_ops
*ops
= info
->fbcon_par
;
254 ops
->rotate
= FB_ROTATE_UR
;
257 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
262 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
266 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
268 static int fbcon_get_rotate(struct fb_info
*info
)
270 struct fbcon_ops
*ops
= info
->fbcon_par
;
272 return (ops
) ? ops
->rotate
: 0;
275 static bool fbcon_skip_panic(struct fb_info
*info
)
277 /* panic_cpu is not exported, and can't be used if built as module. Use
278 * oops_in_progress instead, but non-fatal oops won't be printed.
281 return (info
->skip_panic
&& unlikely(oops_in_progress
));
283 return (info
->skip_panic
&& unlikely(atomic_read(&panic_cpu
) != PANIC_CPU_INVALID
));
287 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
289 struct fbcon_ops
*ops
= info
->fbcon_par
;
291 return (info
->state
!= FBINFO_STATE_RUNNING
||
292 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
|| fbcon_skip_panic(info
));
295 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
298 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
301 if (console_blanked
) {
302 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
304 c
= vc
->vc_video_erase_char
& charmask
;
308 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
309 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
314 int col
= mono_col(info
);
316 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
317 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
322 color
= (is_fg
) ? fg
: bg
;
327 * Scale down 16-colors to 4 colors. Default 4-color palette
328 * is grayscale. However, simply dividing the values by 4
329 * will not work, as colors 1, 2 and 3 will be scaled-down
330 * to zero rendering them invisible. So empirically convert
331 * colors to a sane 4-level grayscale.
335 color
= 0; /* black */
338 color
= 2; /* white */
341 color
= 1; /* gray */
344 color
= 3; /* intense white */
350 * Last 8 entries of default 16-color palette is a more intense
351 * version of the first 8 (i.e., same chrominance, different
362 static void fb_flashcursor(struct work_struct
*work
)
364 struct fbcon_ops
*ops
= container_of(work
, struct fbcon_ops
, cursor_work
.work
);
365 struct fb_info
*info
;
366 struct vc_data
*vc
= NULL
;
371 /* FIXME: we should sort out the unbind locking instead */
372 /* instead we just fail to flash the cursor if we can't get
373 * the lock instead of blocking fbcon deinit */
374 ret
= console_trylock();
378 /* protected by console_lock */
381 if (ops
->currcon
!= -1)
382 vc
= vc_cons
[ops
->currcon
].d
;
384 if (!vc
|| !con_is_visible(vc
) ||
385 fbcon_info_from_console(vc
->vc_num
) != info
||
391 c
= scr_readw((u16
*) vc
->vc_pos
);
392 enable
= ops
->cursor_flash
&& !ops
->cursor_state
.enable
;
393 ops
->cursor(vc
, info
, enable
, get_color(vc
, info
, c
, 1),
394 get_color(vc
, info
, c
, 0));
397 queue_delayed_work(system_power_efficient_wq
, &ops
->cursor_work
,
398 ops
->cur_blink_jiffies
);
401 static void fbcon_add_cursor_work(struct fb_info
*info
)
403 struct fbcon_ops
*ops
= info
->fbcon_par
;
405 if (!fbcon_cursor_noblink
)
406 queue_delayed_work(system_power_efficient_wq
, &ops
->cursor_work
,
407 ops
->cur_blink_jiffies
);
410 static void fbcon_del_cursor_work(struct fb_info
*info
)
412 struct fbcon_ops
*ops
= info
->fbcon_par
;
414 cancel_delayed_work_sync(&ops
->cursor_work
);
418 static int __init
fb_console_setup(char *this_opt
)
423 if (!this_opt
|| !*this_opt
)
426 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
427 if (!strncmp(options
, "font:", 5)) {
428 strscpy(fontname
, options
+ 5, sizeof(fontname
));
432 if (!strncmp(options
, "scrollback:", 11)) {
433 pr_warn("Ignoring scrollback size option\n");
437 if (!strncmp(options
, "map:", 4)) {
440 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
444 (options
[j
++]-'0') % FB_MAX
;
447 fbcon_map_override();
452 if (!strncmp(options
, "vc:", 3)) {
455 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
456 if (first_fb_vc
>= MAX_NR_CONSOLES
)
458 if (*options
++ == '-')
459 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
460 if (last_fb_vc
< first_fb_vc
|| last_fb_vc
>= MAX_NR_CONSOLES
)
461 last_fb_vc
= MAX_NR_CONSOLES
- 1;
462 fbcon_is_default
= 0;
466 if (!strncmp(options
, "rotate:", 7)) {
469 initial_rotation
= simple_strtoul(options
, &options
, 0);
470 if (initial_rotation
> 3)
471 initial_rotation
= 0;
475 if (!strncmp(options
, "margin:", 7)) {
478 margin_color
= simple_strtoul(options
, &options
, 0);
481 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
482 if (!strcmp(options
, "nodefer")) {
483 deferred_takeover
= false;
489 if (!strncmp(options
, "logo-pos:", 9)) {
491 if (!strcmp(options
, "center"))
492 fb_center_logo
= true;
496 if (!strncmp(options
, "logo-count:", 11)) {
499 fb_logo_count
= simple_strtol(options
, &options
, 0);
507 __setup("fbcon=", fb_console_setup
);
510 static int search_fb_in_map(int idx
)
514 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
515 if (con2fb_map
[i
] == idx
) {
523 static int search_for_mapped_con(void)
527 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
528 if (con2fb_map
[i
] != -1) {
536 static int do_fbcon_takeover(int show_logo
)
540 if (!fbcon_num_registered_fb
)
544 logo_shown
= FBCON_LOGO_DONTSHOW
;
546 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
547 con2fb_map
[i
] = info_idx
;
549 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
553 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
557 fbcon_has_console_bind
= 1;
564 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
565 int cols
, int rows
, int new_cols
, int new_rows
)
567 logo_shown
= FBCON_LOGO_DONTSHOW
;
570 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
571 int cols
, int rows
, int new_cols
, int new_rows
)
573 /* Need to make room for the logo */
574 struct fbcon_ops
*ops
= info
->fbcon_par
;
575 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
576 unsigned short *save
= NULL
, *r
, *q
;
579 if (info
->fbops
->owner
) {
580 logo_shown
= FBCON_LOGO_DONTSHOW
;
585 * remove underline attribute from erase character
586 * if black and white framebuffer.
588 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
590 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
591 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
592 q
= (unsigned short *) (vc
->vc_origin
+
593 vc
->vc_size_row
* rows
);
594 step
= logo_lines
* cols
;
595 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
596 if (scr_readw(r
) != vc
->vc_video_erase_char
)
598 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
599 save
= kmalloc(array3_size(logo_lines
, new_cols
, 2),
602 int i
= min(cols
, new_cols
);
603 scr_memsetw(save
, erase
, array3_size(logo_lines
, new_cols
, 2));
605 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
606 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
611 /* We can scroll screen down */
613 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
614 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
619 if (vc
->state
.y
+ logo_lines
>= rows
)
620 lines
= rows
- vc
->state
.y
- 1;
623 vc
->state
.y
+= lines
;
624 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
627 scr_memsetw((unsigned short *) vc
->vc_origin
,
629 vc
->vc_size_row
* logo_lines
);
631 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
632 fbcon_clear_margins(vc
, 0);
637 q
= (unsigned short *) (vc
->vc_origin
+
640 scr_memcpyw(q
, save
, array3_size(logo_lines
, new_cols
, 2));
641 vc
->state
.y
+= logo_lines
;
642 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
646 if (logo_shown
== FBCON_LOGO_DONTSHOW
)
649 if (logo_lines
> vc
->vc_bottom
) {
650 logo_shown
= FBCON_LOGO_CANSHOW
;
651 pr_info("fbcon: disable boot-logo (boot-logo bigger than screen).\n");
653 logo_shown
= FBCON_LOGO_DRAW
;
654 vc
->vc_top
= logo_lines
;
659 #ifdef CONFIG_FB_TILEBLITTING
660 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
662 struct fbcon_ops
*ops
= info
->fbcon_par
;
664 ops
->p
= &fb_display
[vc
->vc_num
];
666 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
667 fbcon_set_tileops(vc
, info
);
669 fbcon_set_rotation(info
);
670 fbcon_set_bitops(ops
);
674 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
678 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
679 info
->tileops
->fb_get_tilemax(info
) < charcount
)
685 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
687 struct fbcon_ops
*ops
= info
->fbcon_par
;
689 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
690 ops
->p
= &fb_display
[vc
->vc_num
];
691 fbcon_set_rotation(info
);
692 fbcon_set_bitops(ops
);
695 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
700 #endif /* CONFIG_MISC_TILEBLITTING */
702 static void fbcon_release(struct fb_info
*info
)
705 if (info
->fbops
->fb_release
)
706 info
->fbops
->fb_release(info
, 0);
707 unlock_fb_info(info
);
709 module_put(info
->fbops
->owner
);
711 if (info
->fbcon_par
) {
712 struct fbcon_ops
*ops
= info
->fbcon_par
;
714 fbcon_del_cursor_work(info
);
715 kfree(ops
->cursor_state
.mask
);
716 kfree(ops
->cursor_data
);
717 kfree(ops
->cursor_src
);
718 kfree(ops
->fontbuffer
);
719 kfree(info
->fbcon_par
);
720 info
->fbcon_par
= NULL
;
724 static int fbcon_open(struct fb_info
*info
)
726 struct fbcon_ops
*ops
;
728 if (!try_module_get(info
->fbops
->owner
))
732 if (info
->fbops
->fb_open
&&
733 info
->fbops
->fb_open(info
, 0)) {
734 unlock_fb_info(info
);
735 module_put(info
->fbops
->owner
);
738 unlock_fb_info(info
);
740 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
746 INIT_DELAYED_WORK(&ops
->cursor_work
, fb_flashcursor
);
748 info
->fbcon_par
= ops
;
749 ops
->cur_blink_jiffies
= HZ
/ 5;
754 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
759 err
= fbcon_open(info
);
764 set_blitting_type(vc
, info
);
769 static void con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
770 struct fb_info
*newinfo
)
774 fbcon_release(oldinfo
);
777 If oldinfo and newinfo are driving the same hardware,
778 the fb_release() method of oldinfo may attempt to
779 restore the hardware state. This will leave the
780 newinfo in an undefined state. Thus, a call to
781 fb_set_par() may be needed for the newinfo.
783 if (newinfo
&& newinfo
->fbops
->fb_set_par
) {
784 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
787 printk(KERN_ERR
"con2fb_release_oldinfo: "
788 "detected unhandled fb_set_par error, "
789 "error code %d\n", ret
);
793 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
794 int unit
, int show_logo
)
796 struct fbcon_ops
*ops
= info
->fbcon_par
;
799 ops
->currcon
= fg_console
;
801 if (info
->fbops
->fb_set_par
&& !ops
->initialized
) {
802 ret
= info
->fbops
->fb_set_par(info
);
805 printk(KERN_ERR
"con2fb_init_display: detected "
806 "unhandled fb_set_par error, "
807 "error code %d\n", ret
);
810 ops
->initialized
= true;
812 fbcon_set_disp(info
, &info
->var
, unit
);
815 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
816 struct fb_info
*fg_info
=
817 fbcon_info_from_console(fg_console
);
819 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
820 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
824 update_screen(vc_cons
[fg_console
].d
);
828 * set_con2fb_map - map console to frame buffer device
829 * @unit: virtual console number to map
830 * @newidx: frame buffer index to map virtual console to
831 * @user: user request
833 * Maps a virtual console @unit to a frame buffer device
836 * This should be called with the console lock held.
838 static int set_con2fb_map(int unit
, int newidx
, int user
)
840 struct vc_data
*vc
= vc_cons
[unit
].d
;
841 int oldidx
= con2fb_map
[unit
];
842 struct fb_info
*info
= fbcon_registered_fb
[newidx
];
843 struct fb_info
*oldinfo
= NULL
;
844 int err
= 0, show_logo
;
846 WARN_CONSOLE_UNLOCKED();
848 if (oldidx
== newidx
)
854 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
856 return do_fbcon_takeover(0);
860 oldinfo
= fbcon_registered_fb
[oldidx
];
862 if (!search_fb_in_map(newidx
)) {
863 err
= con2fb_acquire_newinfo(vc
, info
, unit
);
867 fbcon_add_cursor_work(info
);
869 set_blitting_type(vc
, info
);
872 con2fb_map
[unit
] = newidx
;
875 * If old fb is not mapped to any of the consoles,
876 * fbcon should release it.
878 if (oldinfo
&& !search_fb_in_map(oldidx
))
879 con2fb_release_oldinfo(vc
, oldinfo
, info
);
881 show_logo
= (fg_console
== 0 && !user
&&
882 logo_shown
!= FBCON_LOGO_DONTSHOW
);
884 con2fb_map_boot
[unit
] = newidx
;
885 con2fb_init_display(vc
, info
, unit
, show_logo
);
887 if (!search_fb_in_map(info_idx
))
894 * Low Level Operations
896 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
897 static int var_to_display(struct fbcon_display
*disp
,
898 struct fb_var_screeninfo
*var
,
899 struct fb_info
*info
)
901 disp
->xres_virtual
= var
->xres_virtual
;
902 disp
->yres_virtual
= var
->yres_virtual
;
903 disp
->bits_per_pixel
= var
->bits_per_pixel
;
904 disp
->grayscale
= var
->grayscale
;
905 disp
->nonstd
= var
->nonstd
;
906 disp
->accel_flags
= var
->accel_flags
;
907 disp
->height
= var
->height
;
908 disp
->width
= var
->width
;
909 disp
->red
= var
->red
;
910 disp
->green
= var
->green
;
911 disp
->blue
= var
->blue
;
912 disp
->transp
= var
->transp
;
913 disp
->rotate
= var
->rotate
;
914 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
915 if (disp
->mode
== NULL
)
916 /* This should not happen */
921 static void display_to_var(struct fb_var_screeninfo
*var
,
922 struct fbcon_display
*disp
)
924 fb_videomode_to_var(var
, disp
->mode
);
925 var
->xres_virtual
= disp
->xres_virtual
;
926 var
->yres_virtual
= disp
->yres_virtual
;
927 var
->bits_per_pixel
= disp
->bits_per_pixel
;
928 var
->grayscale
= disp
->grayscale
;
929 var
->nonstd
= disp
->nonstd
;
930 var
->accel_flags
= disp
->accel_flags
;
931 var
->height
= disp
->height
;
932 var
->width
= disp
->width
;
933 var
->red
= disp
->red
;
934 var
->green
= disp
->green
;
935 var
->blue
= disp
->blue
;
936 var
->transp
= disp
->transp
;
937 var
->rotate
= disp
->rotate
;
940 static const char *fbcon_startup(void)
942 static const char display_desc
[] = "frame buffer device";
943 struct fbcon_display
*p
= &fb_display
[fg_console
];
944 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
945 const struct font_desc
*font
= NULL
;
946 struct fb_info
*info
= NULL
;
947 struct fbcon_ops
*ops
;
951 * If num_registered_fb is zero, this is a call for the dummy part.
952 * The frame buffer devices weren't initialized yet.
954 if (!fbcon_num_registered_fb
|| info_idx
== -1)
957 * Instead of blindly using registered_fb[0], we use info_idx, set by
958 * fbcon_fb_registered();
960 info
= fbcon_registered_fb
[info_idx
];
964 if (fbcon_open(info
))
967 ops
= info
->fbcon_par
;
970 ops
->cur_rotate
= -1;
972 p
->con_rotate
= initial_rotation
;
973 if (p
->con_rotate
== -1)
974 p
->con_rotate
= info
->fbcon_rotate_hint
;
975 if (p
->con_rotate
== -1)
976 p
->con_rotate
= FB_ROTATE_UR
;
978 set_blitting_type(vc
, info
);
980 /* Setup default font */
982 if (!fontname
[0] || !(font
= find_font(fontname
)))
983 font
= get_default_font(info
->var
.xres
,
986 info
->pixmap
.blit_y
);
987 vc
->vc_font
.width
= font
->width
;
988 vc
->vc_font
.height
= font
->height
;
989 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
990 vc
->vc_font
.charcount
= font
->charcount
;
993 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
994 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
995 cols
/= vc
->vc_font
.width
;
996 rows
/= vc
->vc_font
.height
;
997 vc_resize(vc
, cols
, rows
);
999 pr_debug("mode: %s\n", info
->fix
.id
);
1000 pr_debug("visual: %d\n", info
->fix
.visual
);
1001 pr_debug("res: %dx%d-%d\n", info
->var
.xres
,
1003 info
->var
.bits_per_pixel
);
1005 fbcon_add_cursor_work(info
);
1006 return display_desc
;
1009 static void fbcon_init(struct vc_data
*vc
, bool init
)
1011 struct fb_info
*info
;
1012 struct fbcon_ops
*ops
;
1013 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1014 struct vc_data
*svc
= *default_mode
;
1015 struct fbcon_display
*t
, *p
= &fb_display
[vc
->vc_num
];
1016 int logo
= 1, new_rows
, new_cols
, rows
, cols
;
1019 if (WARN_ON(info_idx
== -1))
1022 if (con2fb_map
[vc
->vc_num
] == -1)
1023 con2fb_map
[vc
->vc_num
] = info_idx
;
1025 info
= fbcon_info_from_console(vc
->vc_num
);
1027 if (logo_shown
< 0 && console_loglevel
<= CONSOLE_LOGLEVEL_QUIET
)
1028 logo_shown
= FBCON_LOGO_DONTSHOW
;
1030 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1031 (info
->fix
.type
== FB_TYPE_TEXT
))
1034 if (var_to_display(p
, &info
->var
, info
))
1037 if (!info
->fbcon_par
)
1038 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
);
1040 /* If we are not the first console on this
1041 fb, copy the font from that console */
1042 t
= &fb_display
[fg_console
];
1045 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1047 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1049 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1050 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1051 vc
->vc_font
.charcount
= fvc
->vc_font
.charcount
;
1052 p
->userfont
= t
->userfont
;
1055 REFCOUNT(p
->fontdata
)++;
1057 const struct font_desc
*font
= NULL
;
1059 if (!fontname
[0] || !(font
= find_font(fontname
)))
1060 font
= get_default_font(info
->var
.xres
,
1062 info
->pixmap
.blit_x
,
1063 info
->pixmap
.blit_y
);
1064 vc
->vc_font
.width
= font
->width
;
1065 vc
->vc_font
.height
= font
->height
;
1066 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1067 vc
->vc_font
.charcount
= font
->charcount
;
1071 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1072 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1073 if (vc
->vc_font
.charcount
== 256) {
1074 vc
->vc_hi_font_mask
= 0;
1076 vc
->vc_hi_font_mask
= 0x100;
1077 if (vc
->vc_can_do_color
)
1078 vc
->vc_complement_mask
<<= 1;
1081 if (!*svc
->uni_pagedict_loc
)
1082 con_set_default_unimap(svc
);
1083 if (!*vc
->uni_pagedict_loc
)
1084 con_copy_unimap(vc
, svc
);
1086 ops
= info
->fbcon_par
;
1087 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1089 p
->con_rotate
= initial_rotation
;
1090 if (p
->con_rotate
== -1)
1091 p
->con_rotate
= info
->fbcon_rotate_hint
;
1092 if (p
->con_rotate
== -1)
1093 p
->con_rotate
= FB_ROTATE_UR
;
1095 set_blitting_type(vc
, info
);
1099 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1100 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1101 new_cols
/= vc
->vc_font
.width
;
1102 new_rows
/= vc
->vc_font
.height
;
1105 * We must always set the mode. The mode of the previous console
1106 * driver could be in the same resolution but we are using different
1107 * hardware so we have to initialize the hardware.
1109 * We need to do it in fbcon_init() to prevent screen corruption.
1111 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
1112 if (info
->fbops
->fb_set_par
&& !ops
->initialized
) {
1113 ret
= info
->fbops
->fb_set_par(info
);
1116 printk(KERN_ERR
"fbcon_init: detected "
1117 "unhandled fb_set_par error, "
1118 "error code %d\n", ret
);
1121 ops
->initialized
= true;
1126 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1127 if ((info
->flags
& FBINFO_HWACCEL_COPYAREA
) &&
1128 !(info
->flags
& FBINFO_HWACCEL_DISABLED
))
1129 p
->scrollmode
= SCROLL_MOVE
;
1130 else /* default to something safe */
1131 p
->scrollmode
= SCROLL_REDRAW
;
1135 * ++guenther: console.c:vc_allocate() relies on initializing
1136 * vc_{cols,rows}, but we must not set those if we are only
1137 * resizing the console.
1140 vc
->vc_cols
= new_cols
;
1141 vc
->vc_rows
= new_rows
;
1143 vc_resize(vc
, new_cols
, new_rows
);
1146 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1148 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1149 ops
->rotate
= FB_ROTATE_UR
;
1150 set_blitting_type(vc
, info
);
1153 ops
->p
= &fb_display
[fg_console
];
1156 static void fbcon_free_font(struct fbcon_display
*p
)
1158 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1159 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1164 static void set_vc_hi_font(struct vc_data
*vc
, bool set
);
1166 static void fbcon_release_all(void)
1168 struct fb_info
*info
;
1171 fbcon_for_each_registered_fb(i
) {
1173 info
= fbcon_registered_fb
[i
];
1175 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
1176 if (con2fb_map
[j
] == i
) {
1183 fbcon_release(info
);
1187 static void fbcon_deinit(struct vc_data
*vc
)
1189 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1190 struct fb_info
*info
;
1191 struct fbcon_ops
*ops
;
1195 idx
= con2fb_map
[vc
->vc_num
];
1200 info
= fbcon_registered_fb
[idx
];
1205 ops
= info
->fbcon_par
;
1210 if (con_is_visible(vc
))
1211 fbcon_del_cursor_work(info
);
1213 ops
->initialized
= false;
1217 vc
->vc_font
.data
= NULL
;
1219 if (vc
->vc_hi_font_mask
&& vc
->vc_screenbuf
)
1220 set_vc_hi_font(vc
, false);
1222 if (!con_is_bound(&fb_con
))
1223 fbcon_release_all();
1225 if (vc
->vc_num
== logo_shown
)
1226 logo_shown
= FBCON_LOGO_CANSHOW
;
1231 /* ====================================================================== */
1233 /* fbcon_XXX routines - interface used by the world
1235 * This system is now divided into two levels because of complications
1236 * caused by hardware scrolling. Top level functions:
1238 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1240 * handles y values in range [0, scr_height-1] that correspond to real
1241 * screen positions. y_wrap shift means that first line of bitmap may be
1242 * anywhere on this display. These functions convert lineoffsets to
1243 * bitmap offsets and deal with the wrap-around case by splitting blits.
1245 * fbcon_bmove_physical_8() -- These functions fast implementations
1246 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1247 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1251 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1252 * Implies should only really hardware scroll in rows. Only reason for
1253 * restriction is simplicity & efficiency at the moment.
1256 static void __fbcon_clear(struct vc_data
*vc
, unsigned int sy
, unsigned int sx
,
1257 unsigned int height
, unsigned int width
)
1259 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1260 struct fbcon_ops
*ops
= info
->fbcon_par
;
1262 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1265 if (fbcon_is_inactive(vc
, info
))
1268 if (!height
|| !width
)
1271 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1274 * If the font dimensions are not an integral of the display
1275 * dimensions then the ops->clear below won't end up clearing
1276 * the margins. Call clear_margins here in case the logo
1277 * bitmap stretched into the margin area.
1279 fbcon_clear_margins(vc
, 0);
1282 /* Split blits that cross physical y_wrap boundary */
1284 y_break
= p
->vrows
- p
->yscroll
;
1285 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1286 u_int b
= y_break
- sy
;
1287 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1288 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1291 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1294 static void fbcon_clear(struct vc_data
*vc
, unsigned int sy
, unsigned int sx
,
1297 __fbcon_clear(vc
, sy
, sx
, 1, width
);
1300 static void fbcon_putcs(struct vc_data
*vc
, const u16
*s
, unsigned int count
,
1301 unsigned int ypos
, unsigned int xpos
)
1303 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1304 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1305 struct fbcon_ops
*ops
= info
->fbcon_par
;
1307 if (!fbcon_is_inactive(vc
, info
))
1308 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1309 get_color(vc
, info
, scr_readw(s
), 1),
1310 get_color(vc
, info
, scr_readw(s
), 0));
1313 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1315 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1316 struct fbcon_ops
*ops
= info
->fbcon_par
;
1318 if (!fbcon_is_inactive(vc
, info
))
1319 ops
->clear_margins(vc
, info
, margin_color
, bottom_only
);
1322 static void fbcon_cursor(struct vc_data
*vc
, bool enable
)
1324 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1325 struct fbcon_ops
*ops
= info
->fbcon_par
;
1326 int c
= scr_readw((u16
*) vc
->vc_pos
);
1328 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1330 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1333 if (vc
->vc_cursor_type
& CUR_SW
)
1334 fbcon_del_cursor_work(info
);
1336 fbcon_add_cursor_work(info
);
1338 ops
->cursor_flash
= enable
;
1343 ops
->cursor(vc
, info
, enable
, get_color(vc
, info
, c
, 1),
1344 get_color(vc
, info
, c
, 0));
1347 static int scrollback_phys_max
= 0;
1348 static int scrollback_max
= 0;
1349 static int scrollback_current
= 0;
1351 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1354 struct fbcon_display
*p
, *t
;
1355 struct vc_data
**default_mode
, *vc
;
1356 struct vc_data
*svc
;
1357 struct fbcon_ops
*ops
= info
->fbcon_par
;
1360 p
= &fb_display
[unit
];
1362 if (var_to_display(p
, var
, info
))
1365 vc
= vc_cons
[unit
].d
;
1370 default_mode
= vc
->vc_display_fg
;
1371 svc
= *default_mode
;
1372 t
= &fb_display
[svc
->vc_num
];
1374 if (!vc
->vc_font
.data
) {
1375 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1376 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1377 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1378 vc
->vc_font
.charcount
= (*default_mode
)->vc_font
.charcount
;
1379 p
->userfont
= t
->userfont
;
1381 REFCOUNT(p
->fontdata
)++;
1384 var
->activate
= FB_ACTIVATE_NOW
;
1385 info
->var
.activate
= var
->activate
;
1386 var
->yoffset
= info
->var
.yoffset
;
1387 var
->xoffset
= info
->var
.xoffset
;
1388 fb_set_var(info
, var
);
1389 ops
->var
= info
->var
;
1390 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1391 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1392 if (vc
->vc_font
.charcount
== 256) {
1393 vc
->vc_hi_font_mask
= 0;
1395 vc
->vc_hi_font_mask
= 0x100;
1396 if (vc
->vc_can_do_color
)
1397 vc
->vc_complement_mask
<<= 1;
1400 if (!*svc
->uni_pagedict_loc
)
1401 con_set_default_unimap(svc
);
1402 if (!*vc
->uni_pagedict_loc
)
1403 con_copy_unimap(vc
, svc
);
1405 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1406 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1407 cols
/= vc
->vc_font
.width
;
1408 rows
/= vc
->vc_font
.height
;
1409 vc_resize(vc
, cols
, rows
);
1411 if (con_is_visible(vc
)) {
1416 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1418 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1419 struct fbcon_ops
*ops
= info
->fbcon_par
;
1420 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1422 p
->yscroll
+= count
;
1423 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1424 p
->yscroll
-= p
->vrows
;
1425 ops
->var
.xoffset
= 0;
1426 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1427 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1428 ops
->update_start(info
);
1429 scrollback_max
+= count
;
1430 if (scrollback_max
> scrollback_phys_max
)
1431 scrollback_max
= scrollback_phys_max
;
1432 scrollback_current
= 0;
1435 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1437 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1438 struct fbcon_ops
*ops
= info
->fbcon_par
;
1439 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1441 p
->yscroll
-= count
;
1442 if (p
->yscroll
< 0) /* Deal with wrap */
1443 p
->yscroll
+= p
->vrows
;
1444 ops
->var
.xoffset
= 0;
1445 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1446 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1447 ops
->update_start(info
);
1448 scrollback_max
-= count
;
1449 if (scrollback_max
< 0)
1451 scrollback_current
= 0;
1454 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1456 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1457 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1458 struct fbcon_ops
*ops
= info
->fbcon_par
;
1460 p
->yscroll
+= count
;
1461 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1462 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1463 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1464 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1467 ops
->var
.xoffset
= 0;
1468 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1469 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1470 ops
->update_start(info
);
1471 fbcon_clear_margins(vc
, 1);
1472 scrollback_max
+= count
;
1473 if (scrollback_max
> scrollback_phys_max
)
1474 scrollback_max
= scrollback_phys_max
;
1475 scrollback_current
= 0;
1478 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1480 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1481 struct fbcon_ops
*ops
= info
->fbcon_par
;
1482 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1484 p
->yscroll
+= count
;
1486 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1487 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1488 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1491 ops
->var
.xoffset
= 0;
1492 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1493 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1494 ops
->update_start(info
);
1495 fbcon_clear_margins(vc
, 1);
1496 scrollback_max
+= count
;
1497 if (scrollback_max
> scrollback_phys_max
)
1498 scrollback_max
= scrollback_phys_max
;
1499 scrollback_current
= 0;
1502 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1504 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1505 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1506 struct fbcon_ops
*ops
= info
->fbcon_par
;
1508 p
->yscroll
-= count
;
1509 if (p
->yscroll
< 0) {
1510 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1511 0, vc
->vc_rows
, vc
->vc_cols
);
1512 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
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 fbcon_clear_margins(vc
, 1);
1520 scrollback_max
-= count
;
1521 if (scrollback_max
< 0)
1523 scrollback_current
= 0;
1526 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1528 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1529 struct fbcon_ops
*ops
= info
->fbcon_par
;
1530 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1532 p
->yscroll
-= count
;
1534 if (p
->yscroll
< 0) {
1535 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1536 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1539 ops
->var
.xoffset
= 0;
1540 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1541 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1542 ops
->update_start(info
);
1543 fbcon_clear_margins(vc
, 1);
1544 scrollback_max
-= count
;
1545 if (scrollback_max
< 0)
1547 scrollback_current
= 0;
1550 static void fbcon_redraw_move(struct vc_data
*vc
, struct fbcon_display
*p
,
1551 int line
, int count
, int dy
)
1553 unsigned short *s
= (unsigned short *)
1554 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1557 unsigned short *start
= s
;
1558 unsigned short *le
= advance_row(s
, 1);
1561 unsigned short attr
= 1;
1565 if (attr
!= (c
& 0xff00)) {
1568 fbcon_putcs(vc
, start
, s
- start
,
1574 console_conditional_schedule();
1578 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1579 console_conditional_schedule();
1584 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1585 struct fbcon_display
*p
, int line
, int count
, int ycount
)
1587 int offset
= ycount
* vc
->vc_cols
;
1588 unsigned short *d
= (unsigned short *)
1589 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1590 unsigned short *s
= d
+ offset
;
1591 struct fbcon_ops
*ops
= info
->fbcon_par
;
1594 unsigned short *start
= s
;
1595 unsigned short *le
= advance_row(s
, 1);
1602 if (c
== scr_readw(d
)) {
1604 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1605 line
, x
, 1, s
-start
);
1615 console_conditional_schedule();
1620 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1622 console_conditional_schedule();
1627 /* NOTE: We subtract two lines from these pointers */
1628 s
-= vc
->vc_size_row
;
1629 d
-= vc
->vc_size_row
;
1634 static void fbcon_redraw(struct vc_data
*vc
, int line
, int count
, int offset
)
1636 unsigned short *d
= (unsigned short *)
1637 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1638 unsigned short *s
= d
+ offset
;
1641 unsigned short *start
= s
;
1642 unsigned short *le
= advance_row(s
, 1);
1645 unsigned short attr
= 1;
1649 if (attr
!= (c
& 0xff00)) {
1652 fbcon_putcs(vc
, start
, s
- start
,
1658 if (c
== scr_readw(d
)) {
1660 fbcon_putcs(vc
, start
, s
- start
,
1670 console_conditional_schedule();
1675 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1676 console_conditional_schedule();
1681 /* NOTE: We subtract two lines from these pointers */
1682 s
-= vc
->vc_size_row
;
1683 d
-= vc
->vc_size_row
;
1688 static void fbcon_bmove_rec(struct vc_data
*vc
, struct fbcon_display
*p
, int sy
, int sx
,
1689 int dy
, int dx
, int height
, int width
, u_int y_break
)
1691 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1692 struct fbcon_ops
*ops
= info
->fbcon_par
;
1695 if (sy
< y_break
&& sy
+ height
> y_break
) {
1697 if (dy
< sy
) { /* Avoid trashing self */
1698 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1700 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1701 height
- b
, width
, y_break
);
1703 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1704 height
- b
, width
, y_break
);
1705 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1711 if (dy
< y_break
&& dy
+ height
> y_break
) {
1713 if (dy
< sy
) { /* Avoid trashing self */
1714 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1716 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1717 height
- b
, width
, y_break
);
1719 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1720 height
- b
, width
, y_break
);
1721 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1726 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
1730 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1731 int height
, int width
)
1733 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1734 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1736 if (fbcon_is_inactive(vc
, info
))
1739 if (!width
|| !height
)
1742 /* Split blits that cross physical y_wrap case.
1743 * Pathological case involves 4 blits, better to use recursive
1744 * code rather than unrolled case
1746 * Recursive invocations don't need to erase the cursor over and
1747 * over again, so we use fbcon_bmove_rec()
1749 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
1750 p
->vrows
- p
->yscroll
);
1753 static bool fbcon_scroll(struct vc_data
*vc
, unsigned int t
, unsigned int b
,
1754 enum con_scroll dir
, unsigned int count
)
1756 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
1757 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
1758 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1760 if (fbcon_is_inactive(vc
, info
))
1763 fbcon_cursor(vc
, false);
1766 * ++Geert: Only use ywrap/ypan if the console is in text mode
1767 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1768 * whole screen (prevents flicker).
1773 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1774 count
= vc
->vc_rows
;
1775 switch (fb_scrollmode(p
)) {
1777 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1779 __fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1780 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1783 vc
->vc_video_erase_char
,
1784 vc
->vc_size_row
* count
);
1787 case SCROLL_WRAP_MOVE
:
1788 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1790 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1792 ywrap_up(vc
, count
);
1793 if (vc
->vc_rows
- b
> 0)
1794 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1797 } else if (info
->flags
& FBINFO_READS_FAST
)
1798 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1799 b
- t
- count
, vc
->vc_cols
);
1802 __fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1805 case SCROLL_PAN_REDRAW
:
1806 if ((p
->yscroll
+ count
<=
1807 2 * (p
->vrows
- vc
->vc_rows
))
1808 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1811 3 * vc
->vc_rows
>> 2)))) {
1813 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1814 ypan_up_redraw(vc
, t
, count
);
1815 if (vc
->vc_rows
- b
> 0)
1816 fbcon_redraw_move(vc
, p
, b
,
1817 vc
->vc_rows
- b
, b
);
1819 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1820 __fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1823 case SCROLL_PAN_MOVE
:
1824 if ((p
->yscroll
+ count
<=
1825 2 * (p
->vrows
- vc
->vc_rows
))
1826 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1829 3 * vc
->vc_rows
>> 2)))) {
1831 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1834 if (vc
->vc_rows
- b
> 0)
1835 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1838 } else if (info
->flags
& FBINFO_READS_FAST
)
1839 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1840 b
- t
- count
, vc
->vc_cols
);
1843 __fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1848 fbcon_redraw(vc
, t
, b
- t
- count
,
1849 count
* vc
->vc_cols
);
1850 __fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1851 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1854 vc
->vc_video_erase_char
,
1855 vc
->vc_size_row
* count
);
1861 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1862 count
= vc
->vc_rows
;
1863 switch (fb_scrollmode(p
)) {
1865 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1867 __fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1868 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1871 vc
->vc_video_erase_char
,
1872 vc
->vc_size_row
* count
);
1875 case SCROLL_WRAP_MOVE
:
1876 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1877 if (vc
->vc_rows
- b
> 0)
1878 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1881 ywrap_down(vc
, count
);
1883 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1885 } else if (info
->flags
& FBINFO_READS_FAST
)
1886 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1887 b
- t
- count
, vc
->vc_cols
);
1890 __fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1893 case SCROLL_PAN_MOVE
:
1894 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1895 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1898 3 * vc
->vc_rows
>> 2)))) {
1899 if (vc
->vc_rows
- b
> 0)
1900 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1903 ypan_down(vc
, count
);
1905 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1907 } else if (info
->flags
& FBINFO_READS_FAST
)
1908 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1909 b
- t
- count
, vc
->vc_cols
);
1912 __fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1915 case SCROLL_PAN_REDRAW
:
1916 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1917 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1920 3 * vc
->vc_rows
>> 2)))) {
1921 if (vc
->vc_rows
- b
> 0)
1922 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1924 ypan_down_redraw(vc
, t
, count
);
1926 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1928 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1929 __fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1934 fbcon_redraw(vc
, b
- 1, b
- t
- count
,
1935 -count
* vc
->vc_cols
);
1936 __fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1937 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1940 vc
->vc_video_erase_char
,
1941 vc
->vc_size_row
* count
);
1949 static void updatescrollmode_accel(struct fbcon_display
*p
,
1950 struct fb_info
*info
,
1953 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION
1954 struct fbcon_ops
*ops
= info
->fbcon_par
;
1955 int cap
= info
->flags
;
1957 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
1958 info
->fix
.xpanstep
);
1959 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
1960 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1961 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
1962 info
->var
.xres_virtual
);
1963 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
1964 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
1965 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
1966 divides(ywrap
, vc
->vc_font
.height
) &&
1967 divides(vc
->vc_font
.height
, vyres
) &&
1968 divides(vc
->vc_font
.height
, yres
);
1969 int reading_fast
= cap
& FBINFO_READS_FAST
;
1970 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
1971 !(cap
& FBINFO_HWACCEL_DISABLED
);
1972 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
1973 !(cap
& FBINFO_HWACCEL_DISABLED
);
1975 if (good_wrap
|| good_pan
) {
1976 if (reading_fast
|| fast_copyarea
)
1977 p
->scrollmode
= good_wrap
?
1978 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
1980 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
1983 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
1984 p
->scrollmode
= SCROLL_MOVE
;
1986 p
->scrollmode
= SCROLL_REDRAW
;
1991 static void updatescrollmode(struct fbcon_display
*p
,
1992 struct fb_info
*info
,
1995 struct fbcon_ops
*ops
= info
->fbcon_par
;
1996 int fh
= vc
->vc_font
.height
;
1997 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1998 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
1999 info
->var
.xres_virtual
);
2001 p
->vrows
= vyres
/fh
;
2002 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2003 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2004 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2007 /* update scrollmode in case hardware acceleration is used */
2008 updatescrollmode_accel(p
, info
, vc
);
2011 #define PITCH(w) (((w) + 7) >> 3)
2012 #define CALC_FONTSZ(h, p, c) ((h) * (p) * (c)) /* size = height * pitch * charcount */
2014 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2015 unsigned int height
, bool from_user
)
2017 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2018 struct fbcon_ops
*ops
= info
->fbcon_par
;
2019 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2020 struct fb_var_screeninfo var
= info
->var
;
2021 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2023 if (p
->userfont
&& FNTSIZE(vc
->vc_font
.data
)) {
2025 int pitch
= PITCH(vc
->vc_font
.width
);
2028 * If user font, ensure that a possible change to user font
2029 * height or width will not allow a font data out-of-bounds access.
2030 * NOTE: must use original charcount in calculation as font
2031 * charcount can change and cannot be used to determine the
2032 * font data allocated size.
2036 size
= CALC_FONTSZ(vc
->vc_font
.height
, pitch
, vc
->vc_font
.charcount
);
2037 if (size
> FNTSIZE(vc
->vc_font
.data
))
2041 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2042 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2043 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2044 vc
->vc_font
.height
);
2045 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2047 var
.xres
= virt_w
* virt_fw
;
2048 var
.yres
= virt_h
* virt_fh
;
2049 x_diff
= info
->var
.xres
- var
.xres
;
2050 y_diff
= info
->var
.yres
- var
.yres
;
2051 if (x_diff
< 0 || x_diff
> virt_fw
||
2052 y_diff
< 0 || y_diff
> virt_fh
) {
2053 const struct fb_videomode
*mode
;
2055 pr_debug("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2056 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2059 display_to_var(&var
, p
);
2060 fb_videomode_to_var(&var
, mode
);
2062 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2065 pr_debug("resize now %ix%i\n", var
.xres
, var
.yres
);
2066 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
2067 var
.activate
= FB_ACTIVATE_NOW
|
2069 fb_set_var(info
, &var
);
2071 var_to_display(p
, &info
->var
, info
);
2072 ops
->var
= info
->var
;
2074 updatescrollmode(p
, info
, vc
);
2078 static bool fbcon_switch(struct vc_data
*vc
)
2080 struct fb_info
*info
, *old_info
= NULL
;
2081 struct fbcon_ops
*ops
;
2082 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2083 struct fb_var_screeninfo var
;
2084 int i
, ret
, prev_console
;
2086 info
= fbcon_info_from_console(vc
->vc_num
);
2087 ops
= info
->fbcon_par
;
2089 if (logo_shown
>= 0) {
2090 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2092 if (conp2
->vc_top
== logo_lines
2093 && conp2
->vc_bottom
== conp2
->vc_rows
)
2095 logo_shown
= FBCON_LOGO_CANSHOW
;
2098 prev_console
= ops
->currcon
;
2099 if (prev_console
!= -1)
2100 old_info
= fbcon_info_from_console(prev_console
);
2102 * FIXME: If we have multiple fbdev's loaded, we need to
2103 * update all info->currcon. Perhaps, we can place this
2104 * in a centralized structure, but this might break some
2107 * info->currcon = vc->vc_num;
2109 fbcon_for_each_registered_fb(i
) {
2110 if (fbcon_registered_fb
[i
]->fbcon_par
) {
2111 struct fbcon_ops
*o
= fbcon_registered_fb
[i
]->fbcon_par
;
2113 o
->currcon
= vc
->vc_num
;
2116 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2117 display_to_var(&var
, p
);
2118 var
.activate
= FB_ACTIVATE_NOW
;
2121 * make sure we don't unnecessarily trip the memcmp()
2124 info
->var
.activate
= var
.activate
;
2125 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2126 fb_set_var(info
, &var
);
2127 ops
->var
= info
->var
;
2129 if (old_info
!= NULL
&& (old_info
!= info
||
2130 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2131 if (info
->fbops
->fb_set_par
) {
2132 ret
= info
->fbops
->fb_set_par(info
);
2135 printk(KERN_ERR
"fbcon_switch: detected "
2136 "unhandled fb_set_par error, "
2137 "error code %d\n", ret
);
2140 if (old_info
!= info
)
2141 fbcon_del_cursor_work(old_info
);
2144 if (fbcon_is_inactive(vc
, info
) ||
2145 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2146 fbcon_del_cursor_work(info
);
2148 fbcon_add_cursor_work(info
);
2150 set_blitting_type(vc
, info
);
2151 ops
->cursor_reset
= 1;
2153 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2154 ops
->rotate
= FB_ROTATE_UR
;
2155 set_blitting_type(vc
, info
);
2158 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2159 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2161 if (vc
->vc_font
.charcount
> 256)
2162 vc
->vc_complement_mask
<<= 1;
2164 updatescrollmode(p
, info
, vc
);
2166 switch (fb_scrollmode(p
)) {
2167 case SCROLL_WRAP_MOVE
:
2168 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2170 case SCROLL_PAN_MOVE
:
2171 case SCROLL_PAN_REDRAW
:
2172 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2173 if (scrollback_phys_max
< 0)
2174 scrollback_phys_max
= 0;
2177 scrollback_phys_max
= 0;
2182 scrollback_current
= 0;
2184 if (!fbcon_is_inactive(vc
, info
)) {
2185 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2186 ops
->update_start(info
);
2189 fbcon_set_palette(vc
, color_table
);
2190 fbcon_clear_margins(vc
, 0);
2192 if (logo_shown
== FBCON_LOGO_DRAW
) {
2194 logo_shown
= fg_console
;
2195 fb_show_logo(info
, ops
->rotate
);
2197 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2198 vc
->vc_size_row
* (vc
->vc_bottom
-
2205 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2209 unsigned short charmask
= vc
->vc_hi_font_mask
?
2211 unsigned short oldc
;
2213 oldc
= vc
->vc_video_erase_char
;
2214 vc
->vc_video_erase_char
&= charmask
;
2215 __fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2216 vc
->vc_video_erase_char
= oldc
;
2220 static bool fbcon_blank(struct vc_data
*vc
, enum vesa_blank_mode blank
,
2223 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2224 struct fbcon_ops
*ops
= info
->fbcon_par
;
2227 struct fb_var_screeninfo var
= info
->var
;
2232 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
|
2233 FB_ACTIVATE_KD_TEXT
;
2234 fb_set_var(info
, &var
);
2236 ops
->var
= info
->var
;
2240 if (!fbcon_is_inactive(vc
, info
)) {
2241 if (ops
->blank_state
!= blank
) {
2242 ops
->blank_state
= blank
;
2243 fbcon_cursor(vc
, !blank
);
2244 ops
->cursor_flash
= (!blank
);
2246 if (fb_blank(info
, blank
))
2247 fbcon_generic_blank(vc
, info
, blank
);
2254 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2255 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2256 fbcon_del_cursor_work(info
);
2258 fbcon_add_cursor_work(info
);
2263 static void fbcon_debug_enter(struct vc_data
*vc
)
2265 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2266 struct fbcon_ops
*ops
= info
->fbcon_par
;
2268 ops
->save_graphics
= ops
->graphics
;
2270 if (info
->fbops
->fb_debug_enter
)
2271 info
->fbops
->fb_debug_enter(info
);
2272 fbcon_set_palette(vc
, color_table
);
2275 static void fbcon_debug_leave(struct vc_data
*vc
)
2277 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2278 struct fbcon_ops
*ops
= info
->fbcon_par
;
2280 ops
->graphics
= ops
->save_graphics
;
2281 if (info
->fbops
->fb_debug_leave
)
2282 info
->fbops
->fb_debug_leave(info
);
2285 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
, unsigned int vpitch
)
2287 u8
*fontdata
= vc
->vc_font
.data
;
2288 u8
*data
= font
->data
;
2291 font
->width
= vc
->vc_font
.width
;
2292 font
->height
= vc
->vc_font
.height
;
2293 if (font
->height
> vpitch
)
2295 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2299 if (font
->width
<= 8) {
2300 j
= vc
->vc_font
.height
;
2301 if (font
->charcount
* j
> FNTSIZE(fontdata
))
2304 for (i
= 0; i
< font
->charcount
; i
++) {
2305 memcpy(data
, fontdata
, j
);
2306 memset(data
+ j
, 0, vpitch
- j
);
2310 } else if (font
->width
<= 16) {
2311 j
= vc
->vc_font
.height
* 2;
2312 if (font
->charcount
* j
> FNTSIZE(fontdata
))
2315 for (i
= 0; i
< font
->charcount
; i
++) {
2316 memcpy(data
, fontdata
, j
);
2317 memset(data
+ j
, 0, 2*vpitch
- j
);
2321 } else if (font
->width
<= 24) {
2322 if (font
->charcount
* (vc
->vc_font
.height
* sizeof(u32
)) > FNTSIZE(fontdata
))
2325 for (i
= 0; i
< font
->charcount
; i
++) {
2326 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2327 *data
++ = fontdata
[0];
2328 *data
++ = fontdata
[1];
2329 *data
++ = fontdata
[2];
2330 fontdata
+= sizeof(u32
);
2332 memset(data
, 0, 3 * (vpitch
- j
));
2333 data
+= 3 * (vpitch
- j
);
2336 j
= vc
->vc_font
.height
* 4;
2337 if (font
->charcount
* j
> FNTSIZE(fontdata
))
2340 for (i
= 0; i
< font
->charcount
; i
++) {
2341 memcpy(data
, fontdata
, j
);
2342 memset(data
+ j
, 0, 4 * vpitch
- j
);
2350 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2351 static void set_vc_hi_font(struct vc_data
*vc
, bool set
)
2354 vc
->vc_hi_font_mask
= 0;
2355 if (vc
->vc_can_do_color
) {
2356 vc
->vc_complement_mask
>>= 1;
2357 vc
->vc_s_complement_mask
>>= 1;
2360 /* ++Edmund: reorder the attribute bits */
2361 if (vc
->vc_can_do_color
) {
2362 unsigned short *cp
=
2363 (unsigned short *) vc
->vc_origin
;
2364 int count
= vc
->vc_screenbuf_size
/ 2;
2366 for (; count
> 0; count
--, cp
++) {
2368 scr_writew(((c
& 0xfe00) >> 1) |
2371 c
= vc
->vc_video_erase_char
;
2372 vc
->vc_video_erase_char
=
2373 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2377 vc
->vc_hi_font_mask
= 0x100;
2378 if (vc
->vc_can_do_color
) {
2379 vc
->vc_complement_mask
<<= 1;
2380 vc
->vc_s_complement_mask
<<= 1;
2383 /* ++Edmund: reorder the attribute bits */
2385 unsigned short *cp
=
2386 (unsigned short *) vc
->vc_origin
;
2387 int count
= vc
->vc_screenbuf_size
/ 2;
2389 for (; count
> 0; count
--, cp
++) {
2390 unsigned short newc
;
2392 if (vc
->vc_can_do_color
)
2394 ((c
& 0xff00) << 1) | (c
&
2398 scr_writew(newc
, cp
);
2400 c
= vc
->vc_video_erase_char
;
2401 if (vc
->vc_can_do_color
) {
2402 vc
->vc_video_erase_char
=
2403 ((c
& 0xff00) << 1) | (c
& 0xff);
2406 vc
->vc_video_erase_char
= c
& ~0x100;
2411 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
, int charcount
,
2412 const u8
* data
, int userfont
)
2414 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2415 struct fbcon_ops
*ops
= info
->fbcon_par
;
2416 struct fbcon_display
*p
= &fb_display
[vc
->vc_num
];
2417 int resize
, ret
, old_userfont
, old_width
, old_height
, old_charcount
;
2418 u8
*old_data
= vc
->vc_font
.data
;
2420 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2421 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2422 old_userfont
= p
->userfont
;
2423 if ((p
->userfont
= userfont
))
2426 old_width
= vc
->vc_font
.width
;
2427 old_height
= vc
->vc_font
.height
;
2428 old_charcount
= vc
->vc_font
.charcount
;
2430 vc
->vc_font
.width
= w
;
2431 vc
->vc_font
.height
= h
;
2432 vc
->vc_font
.charcount
= charcount
;
2433 if (vc
->vc_hi_font_mask
&& charcount
== 256)
2434 set_vc_hi_font(vc
, false);
2435 else if (!vc
->vc_hi_font_mask
&& charcount
== 512)
2436 set_vc_hi_font(vc
, true);
2441 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2442 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2445 ret
= vc_resize(vc
, cols
, rows
);
2448 } else if (con_is_visible(vc
)
2449 && vc
->vc_mode
== KD_TEXT
) {
2450 fbcon_clear_margins(vc
, 0);
2454 if (old_userfont
&& (--REFCOUNT(old_data
) == 0))
2455 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2459 p
->fontdata
= old_data
;
2460 vc
->vc_font
.data
= old_data
;
2463 p
->userfont
= old_userfont
;
2464 if (--REFCOUNT(data
) == 0)
2465 kfree(data
- FONT_EXTRA_WORDS
* sizeof(int));
2468 vc
->vc_font
.width
= old_width
;
2469 vc
->vc_font
.height
= old_height
;
2470 vc
->vc_font
.charcount
= old_charcount
;
2476 * User asked to set font; we are guaranteed that charcount does not exceed 512
2477 * but lets not assume that, since charcount of 512 is small for unicode support.
2480 static int fbcon_set_font(struct vc_data
*vc
, const struct console_font
*font
,
2481 unsigned int vpitch
, unsigned int flags
)
2483 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2484 unsigned charcount
= font
->charcount
;
2485 int w
= font
->width
;
2486 int h
= font
->height
;
2489 u8
*new_data
, *data
= font
->data
;
2490 int pitch
= PITCH(font
->width
);
2492 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2493 * If not this check should be changed to charcount < 256 */
2494 if (charcount
!= 256 && charcount
!= 512)
2497 /* font bigger than screen resolution ? */
2498 if (w
> FBCON_SWAP(info
->var
.rotate
, info
->var
.xres
, info
->var
.yres
) ||
2499 h
> FBCON_SWAP(info
->var
.rotate
, info
->var
.yres
, info
->var
.xres
))
2502 if (font
->width
> FB_MAX_BLIT_WIDTH
|| font
->height
> FB_MAX_BLIT_HEIGHT
)
2505 /* Make sure drawing engine can handle the font */
2506 if (!test_bit(font
->width
- 1, info
->pixmap
.blit_x
) ||
2507 !test_bit(font
->height
- 1, info
->pixmap
.blit_y
))
2510 /* Make sure driver can handle the font length */
2511 if (fbcon_invalid_charcount(info
, charcount
))
2514 size
= CALC_FONTSZ(h
, pitch
, charcount
);
2516 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2521 memset(new_data
, 0, FONT_EXTRA_WORDS
* sizeof(int));
2523 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2524 FNTSIZE(new_data
) = size
;
2525 REFCOUNT(new_data
) = 0; /* usage counter */
2526 for (i
=0; i
< charcount
; i
++) {
2527 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*vpitch
*pitch
, h
*pitch
);
2530 /* Since linux has a nice crc32 function use it for counting font
2532 csum
= crc32(0, new_data
, size
);
2534 FNTSUM(new_data
) = csum
;
2535 /* Check if the same font is on some other console already */
2536 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2537 struct vc_data
*tmp
= vc_cons
[i
].d
;
2539 if (fb_display
[i
].userfont
&&
2540 fb_display
[i
].fontdata
&&
2541 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2542 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2543 tmp
->vc_font
.width
== w
&&
2544 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2545 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2546 new_data
= (u8
*)fb_display
[i
].fontdata
;
2550 return fbcon_do_set_font(vc
, font
->width
, font
->height
, charcount
, new_data
, 1);
2553 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
,
2556 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2557 const struct font_desc
*f
;
2560 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2561 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2562 else if (!(f
= find_font(name
)))
2565 font
->width
= f
->width
;
2566 font
->height
= f
->height
;
2567 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->charcount
, f
->data
, 0);
2570 static u16 palette_red
[16];
2571 static u16 palette_green
[16];
2572 static u16 palette_blue
[16];
2574 static struct fb_cmap palette_cmap
= {
2575 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2578 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
)
2580 struct fb_info
*info
= fbcon_info_from_console(vc
->vc_num
);
2584 if (fbcon_is_inactive(vc
, info
))
2587 if (!con_is_visible(vc
))
2590 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2592 for (i
= j
= 0; i
< 16; i
++) {
2594 val
= vc
->vc_palette
[j
++];
2595 palette_red
[k
] = (val
<< 8) | val
;
2596 val
= vc
->vc_palette
[j
++];
2597 palette_green
[k
] = (val
<< 8) | val
;
2598 val
= vc
->vc_palette
[j
++];
2599 palette_blue
[k
] = (val
<< 8) | val
;
2601 palette_cmap
.len
= 16;
2602 palette_cmap
.start
= 0;
2604 * If framebuffer is capable of less than 16 colors,
2605 * use default palette of fbcon.
2608 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2610 fb_set_cmap(&palette_cmap
, info
);
2613 /* As we might be inside of softback, we may work with non-contiguous buffer,
2614 that's why we have to use a separate routine. */
2615 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2618 u16 a
= scr_readw(p
);
2619 if (!vc
->vc_can_do_color
)
2621 else if (vc
->vc_hi_font_mask
== 0x100)
2622 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2623 (((a
) & 0x0e00) << 4);
2625 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2626 (((a
) & 0x0700) << 4);
2631 void fbcon_suspended(struct fb_info
*info
)
2633 struct vc_data
*vc
= NULL
;
2634 struct fbcon_ops
*ops
= info
->fbcon_par
;
2636 if (!ops
|| ops
->currcon
< 0)
2638 vc
= vc_cons
[ops
->currcon
].d
;
2640 /* Clear cursor, restore saved data */
2641 fbcon_cursor(vc
, false);
2644 void fbcon_resumed(struct fb_info
*info
)
2647 struct fbcon_ops
*ops
= info
->fbcon_par
;
2649 if (!ops
|| ops
->currcon
< 0)
2651 vc
= vc_cons
[ops
->currcon
].d
;
2656 static void fbcon_modechanged(struct fb_info
*info
)
2658 struct fbcon_ops
*ops
= info
->fbcon_par
;
2660 struct fbcon_display
*p
;
2663 if (!ops
|| ops
->currcon
< 0)
2665 vc
= vc_cons
[ops
->currcon
].d
;
2666 if (vc
->vc_mode
!= KD_TEXT
||
2667 fbcon_info_from_console(ops
->currcon
) != info
)
2670 p
= &fb_display
[vc
->vc_num
];
2671 set_blitting_type(vc
, info
);
2673 if (con_is_visible(vc
)) {
2674 var_to_display(p
, &info
->var
, info
);
2675 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2676 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2677 cols
/= vc
->vc_font
.width
;
2678 rows
/= vc
->vc_font
.height
;
2679 vc_resize(vc
, cols
, rows
);
2680 updatescrollmode(p
, info
, vc
);
2682 scrollback_current
= 0;
2684 if (!fbcon_is_inactive(vc
, info
)) {
2685 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2686 ops
->update_start(info
);
2689 fbcon_set_palette(vc
, color_table
);
2694 static void fbcon_set_all_vcs(struct fb_info
*info
)
2696 struct fbcon_ops
*ops
= info
->fbcon_par
;
2698 struct fbcon_display
*p
;
2699 int i
, rows
, cols
, fg
= -1;
2701 if (!ops
|| ops
->currcon
< 0)
2704 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2706 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2707 fbcon_info_from_console(i
) != info
)
2710 if (con_is_visible(vc
)) {
2715 p
= &fb_display
[vc
->vc_num
];
2716 set_blitting_type(vc
, info
);
2717 var_to_display(p
, &info
->var
, info
);
2718 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2719 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2720 cols
/= vc
->vc_font
.width
;
2721 rows
/= vc
->vc_font
.height
;
2722 vc_resize(vc
, cols
, rows
);
2726 fbcon_modechanged(info
);
2730 void fbcon_update_vcs(struct fb_info
*info
, bool all
)
2733 fbcon_set_all_vcs(info
);
2735 fbcon_modechanged(info
);
2737 EXPORT_SYMBOL(fbcon_update_vcs
);
2739 /* let fbcon check if it supports a new screen resolution */
2740 int fbcon_modechange_possible(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
2742 struct fbcon_ops
*ops
= info
->fbcon_par
;
2746 WARN_CONSOLE_UNLOCKED();
2751 /* prevent setting a screen size which is smaller than font size */
2752 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2754 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2755 fbcon_info_from_console(i
) != info
)
2758 if (vc
->vc_font
.width
> FBCON_SWAP(var
->rotate
, var
->xres
, var
->yres
) ||
2759 vc
->vc_font
.height
> FBCON_SWAP(var
->rotate
, var
->yres
, var
->xres
))
2765 EXPORT_SYMBOL_GPL(fbcon_modechange_possible
);
2767 int fbcon_mode_deleted(struct fb_info
*info
,
2768 struct fb_videomode
*mode
)
2770 struct fb_info
*fb_info
;
2771 struct fbcon_display
*p
;
2772 int i
, j
, found
= 0;
2774 /* before deletion, ensure that mode is not in use */
2775 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2779 fb_info
= fbcon_registered_fb
[j
];
2780 if (fb_info
!= info
)
2785 if (fb_mode_is_equal(p
->mode
, mode
)) {
2793 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2794 static void fbcon_unbind(void)
2798 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2802 fbcon_has_console_bind
= 0;
2805 static inline void fbcon_unbind(void) {}
2806 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2808 void fbcon_fb_unbind(struct fb_info
*info
)
2810 int i
, new_idx
= -1;
2811 int idx
= info
->node
;
2815 if (!fbcon_has_console_bind
) {
2820 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2821 if (con2fb_map
[i
] != idx
&&
2822 con2fb_map
[i
] != -1) {
2823 new_idx
= con2fb_map
[i
];
2828 if (new_idx
!= -1) {
2829 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2830 if (con2fb_map
[i
] == idx
)
2831 set_con2fb_map(i
, new_idx
, 0);
2834 struct fb_info
*info
= fbcon_registered_fb
[idx
];
2836 /* This is sort of like set_con2fb_map, except it maps
2837 * the consoles to no device and then releases the
2838 * oldinfo to free memory and cancel the cursor blink
2839 * timer. I can imagine this just becoming part of
2840 * set_con2fb_map where new_idx is -1
2842 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2843 if (con2fb_map
[i
] == idx
) {
2845 if (!search_fb_in_map(idx
)) {
2846 con2fb_release_oldinfo(vc_cons
[i
].d
,
2857 void fbcon_fb_unregistered(struct fb_info
*info
)
2863 fbcon_registered_fb
[info
->node
] = NULL
;
2864 fbcon_num_registered_fb
--;
2866 if (deferred_takeover
) {
2872 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2873 if (con2fb_map
[i
] == idx
)
2877 if (idx
== info_idx
) {
2880 fbcon_for_each_registered_fb(i
) {
2886 if (info_idx
!= -1) {
2887 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2888 if (con2fb_map
[i
] == -1)
2889 con2fb_map
[i
] = info_idx
;
2893 if (primary_device
== idx
)
2894 primary_device
= -1;
2896 if (!fbcon_num_registered_fb
)
2897 do_unregister_con_driver(&fb_con
);
2901 void fbcon_remap_all(struct fb_info
*info
)
2903 int i
, idx
= info
->node
;
2906 if (deferred_takeover
) {
2907 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
2908 con2fb_map_boot
[i
] = idx
;
2909 fbcon_map_override();
2914 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
2915 set_con2fb_map(i
, idx
, 0);
2917 if (con_is_bound(&fb_con
)) {
2918 printk(KERN_INFO
"fbcon: Remapping primary device, "
2919 "fb%i, to tty %i-%i\n", idx
,
2920 first_fb_vc
+ 1, last_fb_vc
+ 1);
2926 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
2927 static void fbcon_select_primary(struct fb_info
*info
)
2929 if (!map_override
&& primary_device
== -1 &&
2930 video_is_primary_device(info
->device
)) {
2933 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
2934 info
->fix
.id
, info
->node
);
2935 primary_device
= info
->node
;
2937 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
2938 con2fb_map_boot
[i
] = primary_device
;
2940 if (con_is_bound(&fb_con
)) {
2941 printk(KERN_INFO
"fbcon: Remapping primary device, "
2942 "fb%i, to tty %i-%i\n", info
->node
,
2943 first_fb_vc
+ 1, last_fb_vc
+ 1);
2944 info_idx
= primary_device
;
2950 static inline void fbcon_select_primary(struct fb_info
*info
)
2954 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
2956 static bool lockless_register_fb
;
2957 module_param_named_unsafe(lockless_register_fb
, lockless_register_fb
, bool, 0400);
2958 MODULE_PARM_DESC(lockless_register_fb
,
2959 "Lockless framebuffer registration for debugging [default=off]");
2961 /* called with console_lock held */
2962 static int do_fb_registered(struct fb_info
*info
)
2964 int ret
= 0, i
, idx
;
2966 WARN_CONSOLE_UNLOCKED();
2968 fbcon_registered_fb
[info
->node
] = info
;
2969 fbcon_num_registered_fb
++;
2972 fbcon_select_primary(info
);
2974 if (deferred_takeover
) {
2975 pr_info("fbcon: Deferring console take-over\n");
2979 if (info_idx
== -1) {
2980 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2981 if (con2fb_map_boot
[i
] == idx
) {
2988 ret
= do_fbcon_takeover(1);
2990 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2991 if (con2fb_map_boot
[i
] == idx
)
2992 set_con2fb_map(i
, idx
, 0);
2999 int fbcon_fb_registered(struct fb_info
*info
)
3003 if (!lockless_register_fb
)
3006 atomic_inc(&ignore_console_lock_warning
);
3008 ret
= do_fb_registered(info
);
3010 if (!lockless_register_fb
)
3013 atomic_dec(&ignore_console_lock_warning
);
3018 void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3020 struct fbcon_ops
*ops
= info
->fbcon_par
;
3023 if (!ops
|| ops
->currcon
< 0)
3026 vc
= vc_cons
[ops
->currcon
].d
;
3027 if (vc
->vc_mode
!= KD_TEXT
||
3028 fbcon_info_from_console(ops
->currcon
) != info
)
3031 if (con_is_visible(vc
)) {
3035 do_unblank_screen(0);
3037 ops
->blank_state
= blank
;
3040 void fbcon_new_modelist(struct fb_info
*info
)
3044 struct fb_var_screeninfo var
;
3045 const struct fb_videomode
*mode
;
3047 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3048 if (fbcon_info_from_console(i
) != info
)
3050 if (!fb_display
[i
].mode
)
3053 display_to_var(&var
, &fb_display
[i
]);
3054 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3056 fb_videomode_to_var(&var
, mode
);
3057 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3061 void fbcon_get_requirement(struct fb_info
*info
,
3062 struct fb_blit_caps
*caps
)
3069 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3071 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3072 info
->node
== con2fb_map
[i
]) {
3073 set_bit(vc
->vc_font
.width
- 1, caps
->x
);
3074 set_bit(vc
->vc_font
.height
- 1, caps
->y
);
3075 charcnt
= vc
->vc_font
.charcount
;
3076 if (caps
->len
< charcnt
)
3077 caps
->len
= charcnt
;
3081 vc
= vc_cons
[fg_console
].d
;
3083 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3084 info
->node
== con2fb_map
[fg_console
]) {
3085 bitmap_zero(caps
->x
, FB_MAX_BLIT_WIDTH
);
3086 set_bit(vc
->vc_font
.width
- 1, caps
->x
);
3087 bitmap_zero(caps
->y
, FB_MAX_BLIT_HEIGHT
);
3088 set_bit(vc
->vc_font
.height
- 1, caps
->y
);
3089 caps
->len
= vc
->vc_font
.charcount
;
3094 int fbcon_set_con2fb_map_ioctl(void __user
*argp
)
3096 struct fb_con2fbmap con2fb
;
3099 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
3101 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
3103 if (con2fb
.framebuffer
>= FB_MAX
)
3105 if (!fbcon_registered_fb
[con2fb
.framebuffer
])
3106 request_module("fb%d", con2fb
.framebuffer
);
3107 if (!fbcon_registered_fb
[con2fb
.framebuffer
]) {
3112 ret
= set_con2fb_map(con2fb
.console
- 1,
3113 con2fb
.framebuffer
, 1);
3119 int fbcon_get_con2fb_map_ioctl(void __user
*argp
)
3121 struct fb_con2fbmap con2fb
;
3123 if (copy_from_user(&con2fb
, argp
, sizeof(con2fb
)))
3125 if (con2fb
.console
< 1 || con2fb
.console
> MAX_NR_CONSOLES
)
3129 con2fb
.framebuffer
= con2fb_map
[con2fb
.console
- 1];
3132 return copy_to_user(argp
, &con2fb
, sizeof(con2fb
)) ? -EFAULT
: 0;
3136 * The console `switch' structure for the frame buffer based console
3139 static const struct consw fb_con
= {
3140 .owner
= THIS_MODULE
,
3141 .con_startup
= fbcon_startup
,
3142 .con_init
= fbcon_init
,
3143 .con_deinit
= fbcon_deinit
,
3144 .con_clear
= fbcon_clear
,
3145 .con_putcs
= fbcon_putcs
,
3146 .con_cursor
= fbcon_cursor
,
3147 .con_scroll
= fbcon_scroll
,
3148 .con_switch
= fbcon_switch
,
3149 .con_blank
= fbcon_blank
,
3150 .con_font_set
= fbcon_set_font
,
3151 .con_font_get
= fbcon_get_font
,
3152 .con_font_default
= fbcon_set_def_font
,
3153 .con_set_palette
= fbcon_set_palette
,
3154 .con_invert_region
= fbcon_invert_region
,
3155 .con_resize
= fbcon_resize
,
3156 .con_debug_enter
= fbcon_debug_enter
,
3157 .con_debug_leave
= fbcon_debug_leave
,
3160 static ssize_t
store_rotate(struct device
*device
,
3161 struct device_attribute
*attr
, const char *buf
,
3164 struct fb_info
*info
;
3169 idx
= con2fb_map
[fg_console
];
3171 if (idx
== -1 || fbcon_registered_fb
[idx
] == NULL
)
3174 info
= fbcon_registered_fb
[idx
];
3175 rotate
= simple_strtoul(buf
, last
, 0);
3176 fbcon_rotate(info
, rotate
);
3182 static ssize_t
store_rotate_all(struct device
*device
,
3183 struct device_attribute
*attr
,const char *buf
,
3186 struct fb_info
*info
;
3191 idx
= con2fb_map
[fg_console
];
3193 if (idx
== -1 || fbcon_registered_fb
[idx
] == NULL
)
3196 info
= fbcon_registered_fb
[idx
];
3197 rotate
= simple_strtoul(buf
, last
, 0);
3198 fbcon_rotate_all(info
, rotate
);
3204 static ssize_t
show_rotate(struct device
*device
,
3205 struct device_attribute
*attr
,char *buf
)
3207 struct fb_info
*info
;
3208 int rotate
= 0, idx
;
3211 idx
= con2fb_map
[fg_console
];
3213 if (idx
== -1 || fbcon_registered_fb
[idx
] == NULL
)
3216 info
= fbcon_registered_fb
[idx
];
3217 rotate
= fbcon_get_rotate(info
);
3220 return sysfs_emit(buf
, "%d\n", rotate
);
3223 static ssize_t
show_cursor_blink(struct device
*device
,
3224 struct device_attribute
*attr
, char *buf
)
3226 struct fb_info
*info
;
3227 struct fbcon_ops
*ops
;
3228 int idx
, blink
= -1;
3231 idx
= con2fb_map
[fg_console
];
3233 if (idx
== -1 || fbcon_registered_fb
[idx
] == NULL
)
3236 info
= fbcon_registered_fb
[idx
];
3237 ops
= info
->fbcon_par
;
3242 blink
= delayed_work_pending(&ops
->cursor_work
);
3245 return sysfs_emit(buf
, "%d\n", blink
);
3248 static ssize_t
store_cursor_blink(struct device
*device
,
3249 struct device_attribute
*attr
,
3250 const char *buf
, size_t count
)
3252 struct fb_info
*info
;
3257 idx
= con2fb_map
[fg_console
];
3259 if (idx
== -1 || fbcon_registered_fb
[idx
] == NULL
)
3262 info
= fbcon_registered_fb
[idx
];
3264 if (!info
->fbcon_par
)
3267 blink
= simple_strtoul(buf
, last
, 0);
3270 fbcon_cursor_noblink
= 0;
3271 fbcon_add_cursor_work(info
);
3273 fbcon_cursor_noblink
= 1;
3274 fbcon_del_cursor_work(info
);
3282 static struct device_attribute device_attrs
[] = {
3283 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3284 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3285 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3286 store_cursor_blink
),
3289 static int fbcon_init_device(void)
3293 fbcon_has_sysfs
= 1;
3295 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3296 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3304 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3306 fbcon_has_sysfs
= 0;
3312 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3313 static void fbcon_register_existing_fbs(struct work_struct
*work
)
3319 deferred_takeover
= false;
3320 logo_shown
= FBCON_LOGO_DONTSHOW
;
3322 fbcon_for_each_registered_fb(i
)
3323 do_fb_registered(fbcon_registered_fb
[i
]);
3328 static struct notifier_block fbcon_output_nb
;
3329 static DECLARE_WORK(fbcon_deferred_takeover_work
, fbcon_register_existing_fbs
);
3331 static int fbcon_output_notifier(struct notifier_block
*nb
,
3332 unsigned long action
, void *data
)
3334 WARN_CONSOLE_UNLOCKED();
3336 pr_info("fbcon: Taking over console\n");
3338 dummycon_unregister_output_notifier(&fbcon_output_nb
);
3340 /* We may get called in atomic context */
3341 schedule_work(&fbcon_deferred_takeover_work
);
3347 static void fbcon_start(void)
3349 WARN_CONSOLE_UNLOCKED();
3351 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3352 if (conswitchp
!= &dummy_con
)
3353 deferred_takeover
= false;
3355 if (deferred_takeover
) {
3356 fbcon_output_nb
.notifier_call
= fbcon_output_notifier
;
3357 dummycon_register_output_notifier(&fbcon_output_nb
);
3363 void __init
fb_console_init(void)
3368 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3371 if (IS_ERR(fbcon_device
)) {
3372 printk(KERN_WARNING
"Unable to create device "
3373 "for fbcon; errno = %ld\n",
3374 PTR_ERR(fbcon_device
));
3375 fbcon_device
= NULL
;
3377 fbcon_init_device();
3379 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3388 static void __exit
fbcon_deinit_device(void)
3392 if (fbcon_has_sysfs
) {
3393 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3394 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3396 fbcon_has_sysfs
= 0;
3400 void __exit
fb_console_exit(void)
3402 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3404 if (deferred_takeover
)
3405 dummycon_unregister_output_notifier(&fbcon_output_nb
);
3408 cancel_work_sync(&fbcon_deferred_takeover_work
);
3412 fbcon_deinit_device();
3413 device_destroy(fb_class
, MKDEV(0, 0));
3415 do_unregister_con_driver(&fb_con
);