2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
96 static struct display fb_display
[MAX_NR_CONSOLES
];
98 static signed char con2fb_map
[MAX_NR_CONSOLES
];
99 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
101 static int logo_lines
;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown
= FBCON_LOGO_CANSHOW
;
105 /* Software scrollback */
106 static int fbcon_softback_size
= 32768;
107 static unsigned long softback_buf
, softback_curr
;
108 static unsigned long softback_in
;
109 static unsigned long softback_top
, softback_end
;
110 static int softback_lines
;
111 /* console mappings */
112 static int first_fb_vc
;
113 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
114 static int fbcon_is_default
= 1;
115 static int fbcon_has_exited
;
116 static int primary_device
= -1;
117 static int fbcon_has_console_bind
;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override
;
122 static inline void fbcon_map_override(void)
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
133 static char fontname
[40];
135 /* current fb_info */
136 static int info_idx
= -1;
138 /* console rotation */
139 static int initial_rotation
= -1;
140 static int fbcon_has_sysfs
;
141 static int margin_color
;
143 static const struct consw fb_con
;
145 #define CM_SOFTBACK (8)
147 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
149 static int fbcon_set_origin(struct vc_data
*);
151 static int fbcon_cursor_noblink
;
153 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
156 * Interface used by the world
159 static const char *fbcon_startup(void);
160 static void fbcon_init(struct vc_data
*vc
, int init
);
161 static void fbcon_deinit(struct vc_data
*vc
);
162 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
164 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
165 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
166 int count
, int ypos
, int xpos
);
167 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
168 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
169 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
170 int height
, int width
);
171 static int fbcon_switch(struct vc_data
*vc
);
172 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
173 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
);
178 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
179 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
180 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
181 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
182 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
183 int dy
, int dx
, int height
, int width
, u_int y_break
);
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 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
);
190 static void fbcon_start(void);
191 static void fbcon_exit(void);
192 static struct device
*fbcon_device
;
194 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
195 static inline void fbcon_set_rotation(struct fb_info
*info
)
197 struct fbcon_ops
*ops
= info
->fbcon_par
;
199 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
200 ops
->p
->con_rotate
< 4)
201 ops
->rotate
= ops
->p
->con_rotate
;
206 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
208 struct fbcon_ops
*ops
= info
->fbcon_par
;
209 struct fb_info
*fb_info
;
211 if (!ops
|| ops
->currcon
== -1)
214 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
216 if (info
== fb_info
) {
217 struct display
*p
= &fb_display
[ops
->currcon
];
220 p
->con_rotate
= rotate
;
224 fbcon_modechanged(info
);
228 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
230 struct fbcon_ops
*ops
= info
->fbcon_par
;
235 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
238 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
240 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
241 registered_fb
[con2fb_map
[i
]] != info
)
244 p
= &fb_display
[vc
->vc_num
];
245 p
->con_rotate
= rotate
;
248 fbcon_set_all_vcs(info
);
251 static inline void fbcon_set_rotation(struct fb_info
*info
)
253 struct fbcon_ops
*ops
= info
->fbcon_par
;
255 ops
->rotate
= FB_ROTATE_UR
;
258 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
263 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
267 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
269 static int fbcon_get_rotate(struct fb_info
*info
)
271 struct fbcon_ops
*ops
= info
->fbcon_par
;
273 return (ops
) ? ops
->rotate
: 0;
276 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
278 struct fbcon_ops
*ops
= info
->fbcon_par
;
280 return (info
->state
!= FBINFO_STATE_RUNNING
||
281 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
) &&
282 !vt_force_oops_output(vc
);
285 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
288 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
291 if (console_blanked
) {
292 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
294 c
= vc
->vc_video_erase_char
& charmask
;
298 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
299 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
304 int col
= mono_col(info
);
306 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
307 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
312 color
= (is_fg
) ? fg
: bg
;
317 * Scale down 16-colors to 4 colors. Default 4-color palette
318 * is grayscale. However, simply dividing the values by 4
319 * will not work, as colors 1, 2 and 3 will be scaled-down
320 * to zero rendering them invisible. So empirically convert
321 * colors to a sane 4-level grayscale.
325 color
= 0; /* black */
328 color
= 2; /* white */
331 color
= 1; /* gray */
334 color
= 3; /* intense white */
340 * Last 8 entries of default 16-color palette is a more intense
341 * version of the first 8 (i.e., same chrominance, different
352 static void fbcon_update_softback(struct vc_data
*vc
)
354 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
357 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
359 /* Smaller scrollback makes no sense, and 0 would screw
360 the operation totally */
364 static void fb_flashcursor(struct work_struct
*work
)
366 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
367 struct fbcon_ops
*ops
= info
->fbcon_par
;
368 struct vc_data
*vc
= NULL
;
373 /* FIXME: we should sort out the unbind locking instead */
374 /* instead we just fail to flash the cursor if we can't get
375 * the lock instead of blocking fbcon deinit */
376 ret
= console_trylock();
380 if (ops
&& ops
->currcon
!= -1)
381 vc
= vc_cons
[ops
->currcon
].d
;
383 if (!vc
|| !con_is_visible(vc
) ||
384 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
390 c
= scr_readw((u16
*) vc
->vc_pos
);
391 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
393 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
394 get_color(vc
, info
, c
, 0));
398 static void cursor_timer_handler(unsigned long dev_addr
)
400 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
401 struct fbcon_ops
*ops
= info
->fbcon_par
;
403 queue_work(system_power_efficient_wq
, &info
->queue
);
404 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
407 static void fbcon_add_cursor_timer(struct fb_info
*info
)
409 struct fbcon_ops
*ops
= info
->fbcon_par
;
411 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
412 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
413 !fbcon_cursor_noblink
) {
414 if (!info
->queue
.func
)
415 INIT_WORK(&info
->queue
, fb_flashcursor
);
417 setup_timer(&ops
->cursor_timer
, cursor_timer_handler
,
418 (unsigned long) info
);
419 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
420 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
424 static void fbcon_del_cursor_timer(struct fb_info
*info
)
426 struct fbcon_ops
*ops
= info
->fbcon_par
;
428 if (info
->queue
.func
== fb_flashcursor
&&
429 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
430 del_timer_sync(&ops
->cursor_timer
);
431 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
436 static int __init
fb_console_setup(char *this_opt
)
441 if (!this_opt
|| !*this_opt
)
444 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
445 if (!strncmp(options
, "font:", 5)) {
446 strlcpy(fontname
, options
+ 5, sizeof(fontname
));
450 if (!strncmp(options
, "scrollback:", 11)) {
453 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
454 if (*options
== 'k' || *options
== 'K') {
455 fbcon_softback_size
*= 1024;
461 if (!strncmp(options
, "map:", 4)) {
464 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
468 (options
[j
++]-'0') % FB_MAX
;
471 fbcon_map_override();
476 if (!strncmp(options
, "vc:", 3)) {
479 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
482 if (*options
++ == '-')
483 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
484 fbcon_is_default
= 0;
488 if (!strncmp(options
, "rotate:", 7)) {
491 initial_rotation
= simple_strtoul(options
, &options
, 0);
492 if (initial_rotation
> 3)
493 initial_rotation
= 0;
497 if (!strncmp(options
, "margin:", 7)) {
500 margin_color
= simple_strtoul(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
)
521 static int search_for_mapped_con(void)
525 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
526 if (con2fb_map
[i
] != -1)
532 static int do_fbcon_takeover(int show_logo
)
536 if (!num_registered_fb
)
540 logo_shown
= FBCON_LOGO_DONTSHOW
;
542 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
543 con2fb_map
[i
] = info_idx
;
545 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
549 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
553 fbcon_has_console_bind
= 1;
560 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
561 int cols
, int rows
, int new_cols
, int new_rows
)
563 logo_shown
= FBCON_LOGO_DONTSHOW
;
566 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
567 int cols
, int rows
, int new_cols
, int new_rows
)
569 /* Need to make room for the logo */
570 struct fbcon_ops
*ops
= info
->fbcon_par
;
571 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
572 unsigned short *save
= NULL
, *r
, *q
;
575 if (info
->fbops
->owner
) {
576 logo_shown
= FBCON_LOGO_DONTSHOW
;
581 * remove underline attribute from erase character
582 * if black and white framebuffer.
584 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
586 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
587 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
588 q
= (unsigned short *) (vc
->vc_origin
+
589 vc
->vc_size_row
* rows
);
590 step
= logo_lines
* cols
;
591 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
592 if (scr_readw(r
) != vc
->vc_video_erase_char
)
594 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
595 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
597 int i
= cols
< new_cols
? cols
: new_cols
;
598 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
600 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
601 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
606 /* We can scroll screen down */
608 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
609 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
614 if (vc
->vc_y
+ logo_lines
>= rows
)
615 lines
= rows
- vc
->vc_y
- 1;
619 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
622 scr_memsetw((unsigned short *) vc
->vc_origin
,
624 vc
->vc_size_row
* logo_lines
);
626 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
627 fbcon_clear_margins(vc
, 0);
632 q
= (unsigned short *) (vc
->vc_origin
+
635 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
636 vc
->vc_y
+= logo_lines
;
637 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
641 if (logo_lines
> vc
->vc_bottom
) {
642 logo_shown
= FBCON_LOGO_CANSHOW
;
644 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
645 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
646 logo_shown
= FBCON_LOGO_DRAW
;
647 vc
->vc_top
= logo_lines
;
652 #ifdef CONFIG_FB_TILEBLITTING
653 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
655 struct fbcon_ops
*ops
= info
->fbcon_par
;
657 ops
->p
= &fb_display
[vc
->vc_num
];
659 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
660 fbcon_set_tileops(vc
, info
);
662 fbcon_set_rotation(info
);
663 fbcon_set_bitops(ops
);
667 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
671 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
672 info
->tileops
->fb_get_tilemax(info
) < charcount
)
678 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
680 struct fbcon_ops
*ops
= info
->fbcon_par
;
682 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
683 ops
->p
= &fb_display
[vc
->vc_num
];
684 fbcon_set_rotation(info
);
685 fbcon_set_bitops(ops
);
688 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
693 #endif /* CONFIG_MISC_TILEBLITTING */
696 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
697 int unit
, int oldidx
)
699 struct fbcon_ops
*ops
= NULL
;
702 if (!try_module_get(info
->fbops
->owner
))
705 if (!err
&& info
->fbops
->fb_open
&&
706 info
->fbops
->fb_open(info
, 0))
710 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
716 ops
->cur_blink_jiffies
= HZ
/ 5;
717 info
->fbcon_par
= ops
;
720 set_blitting_type(vc
, info
);
724 con2fb_map
[unit
] = oldidx
;
725 module_put(info
->fbops
->owner
);
731 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
732 struct fb_info
*newinfo
, int unit
,
733 int oldidx
, int found
)
735 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
738 if (oldinfo
->fbops
->fb_release
&&
739 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
740 con2fb_map
[unit
] = oldidx
;
741 if (!found
&& newinfo
->fbops
->fb_release
)
742 newinfo
->fbops
->fb_release(newinfo
, 0);
744 module_put(newinfo
->fbops
->owner
);
749 fbcon_del_cursor_timer(oldinfo
);
750 kfree(ops
->cursor_state
.mask
);
751 kfree(ops
->cursor_data
);
752 kfree(ops
->cursor_src
);
753 kfree(ops
->fontbuffer
);
754 kfree(oldinfo
->fbcon_par
);
755 oldinfo
->fbcon_par
= NULL
;
756 module_put(oldinfo
->fbops
->owner
);
758 If oldinfo and newinfo are driving the same hardware,
759 the fb_release() method of oldinfo may attempt to
760 restore the hardware state. This will leave the
761 newinfo in an undefined state. Thus, a call to
762 fb_set_par() may be needed for the newinfo.
764 if (newinfo
&& newinfo
->fbops
->fb_set_par
) {
765 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
768 printk(KERN_ERR
"con2fb_release_oldinfo: "
769 "detected unhandled fb_set_par error, "
770 "error code %d\n", ret
);
777 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
778 int unit
, int show_logo
)
780 struct fbcon_ops
*ops
= info
->fbcon_par
;
783 ops
->currcon
= fg_console
;
785 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
786 ret
= info
->fbops
->fb_set_par(info
);
789 printk(KERN_ERR
"con2fb_init_display: detected "
790 "unhandled fb_set_par error, "
791 "error code %d\n", ret
);
794 ops
->flags
|= FBCON_FLAGS_INIT
;
796 fbcon_set_disp(info
, &info
->var
, unit
);
799 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
800 struct fb_info
*fg_info
=
801 registered_fb
[con2fb_map
[fg_console
]];
803 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
804 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
808 update_screen(vc_cons
[fg_console
].d
);
812 * set_con2fb_map - map console to frame buffer device
813 * @unit: virtual console number to map
814 * @newidx: frame buffer index to map virtual console to
815 * @user: user request
817 * Maps a virtual console @unit to a frame buffer device
820 * This should be called with the console lock held.
822 static int set_con2fb_map(int unit
, int newidx
, int user
)
824 struct vc_data
*vc
= vc_cons
[unit
].d
;
825 int oldidx
= con2fb_map
[unit
];
826 struct fb_info
*info
= registered_fb
[newidx
];
827 struct fb_info
*oldinfo
= NULL
;
830 if (oldidx
== newidx
)
836 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
838 return do_fbcon_takeover(0);
842 oldinfo
= registered_fb
[oldidx
];
844 found
= search_fb_in_map(newidx
);
846 con2fb_map
[unit
] = newidx
;
848 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
852 * If old fb is not mapped to any of the consoles,
853 * fbcon should release it.
855 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
856 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
860 int show_logo
= (fg_console
== 0 && !user
&&
861 logo_shown
!= FBCON_LOGO_DONTSHOW
);
864 fbcon_add_cursor_timer(info
);
865 con2fb_map_boot
[unit
] = newidx
;
866 con2fb_init_display(vc
, info
, unit
, show_logo
);
869 if (!search_fb_in_map(info_idx
))
876 * Low Level Operations
878 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
879 static int var_to_display(struct display
*disp
,
880 struct fb_var_screeninfo
*var
,
881 struct fb_info
*info
)
883 disp
->xres_virtual
= var
->xres_virtual
;
884 disp
->yres_virtual
= var
->yres_virtual
;
885 disp
->bits_per_pixel
= var
->bits_per_pixel
;
886 disp
->grayscale
= var
->grayscale
;
887 disp
->nonstd
= var
->nonstd
;
888 disp
->accel_flags
= var
->accel_flags
;
889 disp
->height
= var
->height
;
890 disp
->width
= var
->width
;
891 disp
->red
= var
->red
;
892 disp
->green
= var
->green
;
893 disp
->blue
= var
->blue
;
894 disp
->transp
= var
->transp
;
895 disp
->rotate
= var
->rotate
;
896 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
897 if (disp
->mode
== NULL
)
898 /* This should not happen */
903 static void display_to_var(struct fb_var_screeninfo
*var
,
904 struct display
*disp
)
906 fb_videomode_to_var(var
, disp
->mode
);
907 var
->xres_virtual
= disp
->xres_virtual
;
908 var
->yres_virtual
= disp
->yres_virtual
;
909 var
->bits_per_pixel
= disp
->bits_per_pixel
;
910 var
->grayscale
= disp
->grayscale
;
911 var
->nonstd
= disp
->nonstd
;
912 var
->accel_flags
= disp
->accel_flags
;
913 var
->height
= disp
->height
;
914 var
->width
= disp
->width
;
915 var
->red
= disp
->red
;
916 var
->green
= disp
->green
;
917 var
->blue
= disp
->blue
;
918 var
->transp
= disp
->transp
;
919 var
->rotate
= disp
->rotate
;
922 static const char *fbcon_startup(void)
924 const char *display_desc
= "frame buffer device";
925 struct display
*p
= &fb_display
[fg_console
];
926 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
927 const struct font_desc
*font
= NULL
;
928 struct module
*owner
;
929 struct fb_info
*info
= NULL
;
930 struct fbcon_ops
*ops
;
934 * If num_registered_fb is zero, this is a call for the dummy part.
935 * The frame buffer devices weren't initialized yet.
937 if (!num_registered_fb
|| info_idx
== -1)
940 * Instead of blindly using registered_fb[0], we use info_idx, set by
943 info
= registered_fb
[info_idx
];
947 owner
= info
->fbops
->owner
;
948 if (!try_module_get(owner
))
950 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
955 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
963 ops
->cur_rotate
= -1;
964 ops
->cur_blink_jiffies
= HZ
/ 5;
965 info
->fbcon_par
= ops
;
966 if (initial_rotation
!= -1)
967 p
->con_rotate
= initial_rotation
;
969 p
->con_rotate
= fbcon_platform_get_rotate(info
);
970 set_blitting_type(vc
, info
);
972 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
973 if (fbcon_softback_size
) {
977 kmalloc(fbcon_softback_size
,
980 fbcon_softback_size
= 0;
986 kfree((void *) softback_buf
);
992 softback_in
= softback_top
= softback_curr
=
997 /* Setup default font */
998 if (!p
->fontdata
&& !vc
->vc_font
.data
) {
999 if (!fontname
[0] || !(font
= find_font(fontname
)))
1000 font
= get_default_font(info
->var
.xres
,
1002 info
->pixmap
.blit_x
,
1003 info
->pixmap
.blit_y
);
1004 vc
->vc_font
.width
= font
->width
;
1005 vc
->vc_font
.height
= font
->height
;
1006 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1007 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1009 p
->fontdata
= vc
->vc_font
.data
;
1012 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1013 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1014 cols
/= vc
->vc_font
.width
;
1015 rows
/= vc
->vc_font
.height
;
1016 vc_resize(vc
, cols
, rows
);
1018 DPRINTK("mode: %s\n", info
->fix
.id
);
1019 DPRINTK("visual: %d\n", info
->fix
.visual
);
1020 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1022 info
->var
.bits_per_pixel
);
1024 fbcon_add_cursor_timer(info
);
1025 fbcon_has_exited
= 0;
1026 return display_desc
;
1029 static void fbcon_init(struct vc_data
*vc
, int init
)
1031 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1032 struct fbcon_ops
*ops
;
1033 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1034 struct vc_data
*svc
= *default_mode
;
1035 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1036 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1039 if (info_idx
== -1 || info
== NULL
)
1044 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1045 (info
->fix
.type
== FB_TYPE_TEXT
))
1048 if (var_to_display(p
, &info
->var
, info
))
1051 if (!info
->fbcon_par
)
1052 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1054 /* If we are not the first console on this
1055 fb, copy the font from that console */
1056 t
= &fb_display
[fg_console
];
1059 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1061 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1063 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1064 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1065 p
->userfont
= t
->userfont
;
1068 REFCOUNT(p
->fontdata
)++;
1070 const struct font_desc
*font
= NULL
;
1072 if (!fontname
[0] || !(font
= find_font(fontname
)))
1073 font
= get_default_font(info
->var
.xres
,
1075 info
->pixmap
.blit_x
,
1076 info
->pixmap
.blit_y
);
1077 vc
->vc_font
.width
= font
->width
;
1078 vc
->vc_font
.height
= font
->height
;
1079 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1080 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1081 support more fonts */
1086 charcnt
= FNTCHARCNT(p
->fontdata
);
1088 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1089 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1090 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1091 if (charcnt
== 256) {
1092 vc
->vc_hi_font_mask
= 0;
1094 vc
->vc_hi_font_mask
= 0x100;
1095 if (vc
->vc_can_do_color
)
1096 vc
->vc_complement_mask
<<= 1;
1099 if (!*svc
->vc_uni_pagedir_loc
)
1100 con_set_default_unimap(svc
);
1101 if (!*vc
->vc_uni_pagedir_loc
)
1102 con_copy_unimap(vc
, svc
);
1104 ops
= info
->fbcon_par
;
1105 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1106 if (initial_rotation
!= -1)
1107 p
->con_rotate
= initial_rotation
;
1109 p
->con_rotate
= fbcon_platform_get_rotate(info
);
1110 set_blitting_type(vc
, info
);
1114 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1115 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1116 new_cols
/= vc
->vc_font
.width
;
1117 new_rows
/= vc
->vc_font
.height
;
1120 * We must always set the mode. The mode of the previous console
1121 * driver could be in the same resolution but we are using different
1122 * hardware so we have to initialize the hardware.
1124 * We need to do it in fbcon_init() to prevent screen corruption.
1126 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
1127 if (info
->fbops
->fb_set_par
&&
1128 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1129 ret
= info
->fbops
->fb_set_par(info
);
1132 printk(KERN_ERR
"fbcon_init: detected "
1133 "unhandled fb_set_par error, "
1134 "error code %d\n", ret
);
1137 ops
->flags
|= FBCON_FLAGS_INIT
;
1142 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1143 !(cap
& FBINFO_HWACCEL_DISABLED
))
1144 p
->scrollmode
= SCROLL_MOVE
;
1145 else /* default to something safe */
1146 p
->scrollmode
= SCROLL_REDRAW
;
1149 * ++guenther: console.c:vc_allocate() relies on initializing
1150 * vc_{cols,rows}, but we must not set those if we are only
1151 * resizing the console.
1154 vc
->vc_cols
= new_cols
;
1155 vc
->vc_rows
= new_rows
;
1157 vc_resize(vc
, new_cols
, new_rows
);
1160 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1162 if (vc
== svc
&& softback_buf
)
1163 fbcon_update_softback(vc
);
1165 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1166 ops
->rotate
= FB_ROTATE_UR
;
1167 set_blitting_type(vc
, info
);
1170 ops
->p
= &fb_display
[fg_console
];
1173 static void fbcon_free_font(struct display
*p
, bool freefont
)
1175 if (freefont
&& p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1176 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1181 static void set_vc_hi_font(struct vc_data
*vc
, bool set
);
1183 static void fbcon_deinit(struct vc_data
*vc
)
1185 struct display
*p
= &fb_display
[vc
->vc_num
];
1186 struct fb_info
*info
;
1187 struct fbcon_ops
*ops
;
1189 bool free_font
= true;
1191 idx
= con2fb_map
[vc
->vc_num
];
1196 info
= registered_fb
[idx
];
1201 if (info
->flags
& FBINFO_MISC_FIRMWARE
)
1203 ops
= info
->fbcon_par
;
1208 if (con_is_visible(vc
))
1209 fbcon_del_cursor_timer(info
);
1211 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1214 fbcon_free_font(p
, free_font
);
1216 vc
->vc_font
.data
= NULL
;
1218 if (vc
->vc_hi_font_mask
)
1219 set_vc_hi_font(vc
, false);
1221 if (!con_is_bound(&fb_con
))
1227 /* ====================================================================== */
1229 /* fbcon_XXX routines - interface used by the world
1231 * This system is now divided into two levels because of complications
1232 * caused by hardware scrolling. Top level functions:
1234 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1236 * handles y values in range [0, scr_height-1] that correspond to real
1237 * screen positions. y_wrap shift means that first line of bitmap may be
1238 * anywhere on this display. These functions convert lineoffsets to
1239 * bitmap offsets and deal with the wrap-around case by splitting blits.
1241 * fbcon_bmove_physical_8() -- These functions fast implementations
1242 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1243 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1247 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1248 * Implies should only really hardware scroll in rows. Only reason for
1249 * restriction is simplicity & efficiency at the moment.
1252 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1255 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1256 struct fbcon_ops
*ops
= info
->fbcon_par
;
1258 struct display
*p
= &fb_display
[vc
->vc_num
];
1261 if (fbcon_is_inactive(vc
, info
))
1264 if (!height
|| !width
)
1267 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1270 * If the font dimensions are not an integral of the display
1271 * dimensions then the ops->clear below won't end up clearing
1272 * the margins. Call clear_margins here in case the logo
1273 * bitmap stretched into the margin area.
1275 fbcon_clear_margins(vc
, 0);
1278 /* Split blits that cross physical y_wrap boundary */
1280 y_break
= p
->vrows
- p
->yscroll
;
1281 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1282 u_int b
= y_break
- sy
;
1283 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1284 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1287 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1290 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1291 int count
, int ypos
, int xpos
)
1293 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1294 struct display
*p
= &fb_display
[vc
->vc_num
];
1295 struct fbcon_ops
*ops
= info
->fbcon_par
;
1297 if (!fbcon_is_inactive(vc
, info
))
1298 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1299 get_color(vc
, info
, scr_readw(s
), 1),
1300 get_color(vc
, info
, scr_readw(s
), 0));
1303 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1307 scr_writew(c
, &chr
);
1308 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1311 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1313 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1314 struct fbcon_ops
*ops
= info
->fbcon_par
;
1316 if (!fbcon_is_inactive(vc
, info
))
1317 ops
->clear_margins(vc
, info
, margin_color
, bottom_only
);
1320 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1322 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1323 struct fbcon_ops
*ops
= info
->fbcon_par
;
1325 int c
= scr_readw((u16
*) vc
->vc_pos
);
1327 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1329 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1332 if (vc
->vc_cursor_type
& 0x10)
1333 fbcon_del_cursor_timer(info
);
1335 fbcon_add_cursor_timer(info
);
1337 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1338 if (mode
& CM_SOFTBACK
) {
1339 mode
&= ~CM_SOFTBACK
;
1343 fbcon_set_origin(vc
);
1347 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1348 get_color(vc
, info
, c
, 0));
1351 static int scrollback_phys_max
= 0;
1352 static int scrollback_max
= 0;
1353 static int scrollback_current
= 0;
1355 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1358 struct display
*p
, *t
;
1359 struct vc_data
**default_mode
, *vc
;
1360 struct vc_data
*svc
;
1361 struct fbcon_ops
*ops
= info
->fbcon_par
;
1362 int rows
, cols
, charcnt
= 256;
1364 p
= &fb_display
[unit
];
1366 if (var_to_display(p
, var
, info
))
1369 vc
= vc_cons
[unit
].d
;
1374 default_mode
= vc
->vc_display_fg
;
1375 svc
= *default_mode
;
1376 t
= &fb_display
[svc
->vc_num
];
1378 if (!vc
->vc_font
.data
) {
1379 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1380 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1381 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1382 p
->userfont
= t
->userfont
;
1384 REFCOUNT(p
->fontdata
)++;
1387 charcnt
= FNTCHARCNT(p
->fontdata
);
1389 var
->activate
= FB_ACTIVATE_NOW
;
1390 info
->var
.activate
= var
->activate
;
1391 var
->yoffset
= info
->var
.yoffset
;
1392 var
->xoffset
= info
->var
.xoffset
;
1393 fb_set_var(info
, var
);
1394 ops
->var
= info
->var
;
1395 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1396 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1397 if (charcnt
== 256) {
1398 vc
->vc_hi_font_mask
= 0;
1400 vc
->vc_hi_font_mask
= 0x100;
1401 if (vc
->vc_can_do_color
)
1402 vc
->vc_complement_mask
<<= 1;
1405 if (!*svc
->vc_uni_pagedir_loc
)
1406 con_set_default_unimap(svc
);
1407 if (!*vc
->vc_uni_pagedir_loc
)
1408 con_copy_unimap(vc
, svc
);
1410 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1411 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1412 cols
/= vc
->vc_font
.width
;
1413 rows
/= vc
->vc_font
.height
;
1414 vc_resize(vc
, cols
, rows
);
1416 if (con_is_visible(vc
)) {
1419 fbcon_update_softback(vc
);
1423 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1425 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1426 struct fbcon_ops
*ops
= info
->fbcon_par
;
1427 struct display
*p
= &fb_display
[vc
->vc_num
];
1429 p
->yscroll
+= count
;
1430 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1431 p
->yscroll
-= p
->vrows
;
1432 ops
->var
.xoffset
= 0;
1433 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1434 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1435 ops
->update_start(info
);
1436 scrollback_max
+= count
;
1437 if (scrollback_max
> scrollback_phys_max
)
1438 scrollback_max
= scrollback_phys_max
;
1439 scrollback_current
= 0;
1442 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1444 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1445 struct fbcon_ops
*ops
= info
->fbcon_par
;
1446 struct display
*p
= &fb_display
[vc
->vc_num
];
1448 p
->yscroll
-= count
;
1449 if (p
->yscroll
< 0) /* Deal with wrap */
1450 p
->yscroll
+= p
->vrows
;
1451 ops
->var
.xoffset
= 0;
1452 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1453 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1454 ops
->update_start(info
);
1455 scrollback_max
-= count
;
1456 if (scrollback_max
< 0)
1458 scrollback_current
= 0;
1461 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1463 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1464 struct display
*p
= &fb_display
[vc
->vc_num
];
1465 struct fbcon_ops
*ops
= info
->fbcon_par
;
1467 p
->yscroll
+= count
;
1468 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1469 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1470 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1471 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1474 ops
->var
.xoffset
= 0;
1475 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1476 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1477 ops
->update_start(info
);
1478 fbcon_clear_margins(vc
, 1);
1479 scrollback_max
+= count
;
1480 if (scrollback_max
> scrollback_phys_max
)
1481 scrollback_max
= scrollback_phys_max
;
1482 scrollback_current
= 0;
1485 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1487 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1488 struct fbcon_ops
*ops
= info
->fbcon_par
;
1489 struct display
*p
= &fb_display
[vc
->vc_num
];
1491 p
->yscroll
+= count
;
1493 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1494 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1495 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1498 ops
->var
.xoffset
= 0;
1499 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1500 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1501 ops
->update_start(info
);
1502 fbcon_clear_margins(vc
, 1);
1503 scrollback_max
+= count
;
1504 if (scrollback_max
> scrollback_phys_max
)
1505 scrollback_max
= scrollback_phys_max
;
1506 scrollback_current
= 0;
1509 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1511 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1512 struct display
*p
= &fb_display
[vc
->vc_num
];
1513 struct fbcon_ops
*ops
= info
->fbcon_par
;
1515 p
->yscroll
-= count
;
1516 if (p
->yscroll
< 0) {
1517 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1518 0, vc
->vc_rows
, vc
->vc_cols
);
1519 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1522 ops
->var
.xoffset
= 0;
1523 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1524 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1525 ops
->update_start(info
);
1526 fbcon_clear_margins(vc
, 1);
1527 scrollback_max
-= count
;
1528 if (scrollback_max
< 0)
1530 scrollback_current
= 0;
1533 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1535 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1536 struct fbcon_ops
*ops
= info
->fbcon_par
;
1537 struct display
*p
= &fb_display
[vc
->vc_num
];
1539 p
->yscroll
-= count
;
1541 if (p
->yscroll
< 0) {
1542 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1543 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1546 ops
->var
.xoffset
= 0;
1547 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1548 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1549 ops
->update_start(info
);
1550 fbcon_clear_margins(vc
, 1);
1551 scrollback_max
-= count
;
1552 if (scrollback_max
< 0)
1554 scrollback_current
= 0;
1557 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1560 int count
= vc
->vc_rows
;
1561 unsigned short *d
, *s
;
1565 d
= (u16
*) softback_curr
;
1566 if (d
== (u16
*) softback_in
)
1567 d
= (u16
*) vc
->vc_origin
;
1568 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1569 softback_lines
-= delta
;
1571 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1572 n
+= softback_end
- softback_buf
;
1573 if (n
< softback_top
) {
1575 (softback_top
- n
) / vc
->vc_size_row
;
1578 } else if (softback_curr
>= softback_top
1579 && n
< softback_top
) {
1581 (softback_top
- n
) / vc
->vc_size_row
;
1585 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1586 n
+= softback_buf
- softback_end
;
1587 if (n
> softback_in
) {
1591 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1596 if (n
== softback_curr
)
1599 s
= (u16
*) softback_curr
;
1600 if (s
== (u16
*) softback_in
)
1601 s
= (u16
*) vc
->vc_origin
;
1603 unsigned short *start
;
1607 unsigned short attr
= 1;
1610 le
= advance_row(s
, 1);
1613 if (attr
!= (c
& 0xff00)) {
1616 fbcon_putcs(vc
, start
, s
- start
,
1622 if (c
== scr_readw(d
)) {
1624 fbcon_putcs(vc
, start
, s
- start
,
1637 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1639 if (d
== (u16
*) softback_end
)
1640 d
= (u16
*) softback_buf
;
1641 if (d
== (u16
*) softback_in
)
1642 d
= (u16
*) vc
->vc_origin
;
1643 if (s
== (u16
*) softback_end
)
1644 s
= (u16
*) softback_buf
;
1645 if (s
== (u16
*) softback_in
)
1646 s
= (u16
*) vc
->vc_origin
;
1650 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1651 int line
, int count
, int dy
)
1653 unsigned short *s
= (unsigned short *)
1654 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1657 unsigned short *start
= s
;
1658 unsigned short *le
= advance_row(s
, 1);
1661 unsigned short attr
= 1;
1665 if (attr
!= (c
& 0xff00)) {
1668 fbcon_putcs(vc
, start
, s
- start
,
1674 console_conditional_schedule();
1678 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1679 console_conditional_schedule();
1684 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1685 struct display
*p
, int line
, int count
, int ycount
)
1687 int offset
= ycount
* vc
->vc_cols
;
1688 unsigned short *d
= (unsigned short *)
1689 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1690 unsigned short *s
= d
+ offset
;
1691 struct fbcon_ops
*ops
= info
->fbcon_par
;
1694 unsigned short *start
= s
;
1695 unsigned short *le
= advance_row(s
, 1);
1702 if (c
== scr_readw(d
)) {
1704 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1705 line
, x
, 1, s
-start
);
1715 console_conditional_schedule();
1720 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1722 console_conditional_schedule();
1727 /* NOTE: We subtract two lines from these pointers */
1728 s
-= vc
->vc_size_row
;
1729 d
-= vc
->vc_size_row
;
1734 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1735 int line
, int count
, int offset
)
1737 unsigned short *d
= (unsigned short *)
1738 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1739 unsigned short *s
= d
+ offset
;
1742 unsigned short *start
= s
;
1743 unsigned short *le
= advance_row(s
, 1);
1746 unsigned short attr
= 1;
1750 if (attr
!= (c
& 0xff00)) {
1753 fbcon_putcs(vc
, start
, s
- start
,
1759 if (c
== scr_readw(d
)) {
1761 fbcon_putcs(vc
, start
, s
- start
,
1771 console_conditional_schedule();
1776 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1777 console_conditional_schedule();
1782 /* NOTE: We subtract two lines from these pointers */
1783 s
-= vc
->vc_size_row
;
1784 d
-= vc
->vc_size_row
;
1789 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1794 if (vc
->vc_num
!= fg_console
)
1796 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1799 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1801 p
= advance_row(p
, 1);
1802 softback_in
+= vc
->vc_size_row
;
1803 if (softback_in
== softback_end
)
1804 softback_in
= softback_buf
;
1805 if (softback_in
== softback_top
) {
1806 softback_top
+= vc
->vc_size_row
;
1807 if (softback_top
== softback_end
)
1808 softback_top
= softback_buf
;
1811 softback_curr
= softback_in
;
1814 static bool fbcon_scroll(struct vc_data
*vc
, unsigned int t
, unsigned int b
,
1815 enum con_scroll dir
, unsigned int count
)
1817 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1818 struct display
*p
= &fb_display
[vc
->vc_num
];
1819 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1821 if (fbcon_is_inactive(vc
, info
))
1824 fbcon_cursor(vc
, CM_ERASE
);
1827 * ++Geert: Only use ywrap/ypan if the console is in text mode
1828 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1829 * whole screen (prevents flicker).
1834 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1835 count
= vc
->vc_rows
;
1837 fbcon_softback_note(vc
, t
, count
);
1838 if (logo_shown
>= 0)
1840 switch (p
->scrollmode
) {
1842 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1844 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1845 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1848 vc
->vc_video_erase_char
,
1849 vc
->vc_size_row
* count
);
1853 case SCROLL_WRAP_MOVE
:
1854 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1856 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1858 ywrap_up(vc
, count
);
1859 if (vc
->vc_rows
- b
> 0)
1860 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1863 } else if (info
->flags
& FBINFO_READS_FAST
)
1864 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1865 b
- t
- count
, vc
->vc_cols
);
1868 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1871 case SCROLL_PAN_REDRAW
:
1872 if ((p
->yscroll
+ count
<=
1873 2 * (p
->vrows
- vc
->vc_rows
))
1874 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1877 3 * vc
->vc_rows
>> 2)))) {
1879 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1880 ypan_up_redraw(vc
, t
, count
);
1881 if (vc
->vc_rows
- b
> 0)
1882 fbcon_redraw_move(vc
, p
, b
,
1883 vc
->vc_rows
- b
, b
);
1885 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1886 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1889 case SCROLL_PAN_MOVE
:
1890 if ((p
->yscroll
+ count
<=
1891 2 * (p
->vrows
- vc
->vc_rows
))
1892 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1895 3 * vc
->vc_rows
>> 2)))) {
1897 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1900 if (vc
->vc_rows
- b
> 0)
1901 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1904 } else if (info
->flags
& FBINFO_READS_FAST
)
1905 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1906 b
- t
- count
, vc
->vc_cols
);
1909 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1914 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1915 count
* vc
->vc_cols
);
1916 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1917 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1920 vc
->vc_video_erase_char
,
1921 vc
->vc_size_row
* count
);
1927 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1928 count
= vc
->vc_rows
;
1929 if (logo_shown
>= 0)
1931 switch (p
->scrollmode
) {
1933 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1935 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1936 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1939 vc
->vc_video_erase_char
,
1940 vc
->vc_size_row
* count
);
1944 case SCROLL_WRAP_MOVE
:
1945 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1946 if (vc
->vc_rows
- b
> 0)
1947 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1950 ywrap_down(vc
, count
);
1952 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1954 } else if (info
->flags
& FBINFO_READS_FAST
)
1955 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1956 b
- t
- count
, vc
->vc_cols
);
1959 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1962 case SCROLL_PAN_MOVE
:
1963 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1964 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1967 3 * vc
->vc_rows
>> 2)))) {
1968 if (vc
->vc_rows
- b
> 0)
1969 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1972 ypan_down(vc
, count
);
1974 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1976 } else if (info
->flags
& FBINFO_READS_FAST
)
1977 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1978 b
- t
- count
, vc
->vc_cols
);
1981 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1984 case SCROLL_PAN_REDRAW
:
1985 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1986 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1989 3 * vc
->vc_rows
>> 2)))) {
1990 if (vc
->vc_rows
- b
> 0)
1991 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1993 ypan_down_redraw(vc
, t
, count
);
1995 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1997 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1998 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2003 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
2004 -count
* vc
->vc_cols
);
2005 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2006 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2009 vc
->vc_video_erase_char
,
2010 vc
->vc_size_row
* count
);
2018 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2019 int height
, int width
)
2021 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2022 struct display
*p
= &fb_display
[vc
->vc_num
];
2024 if (fbcon_is_inactive(vc
, info
))
2027 if (!width
|| !height
)
2030 /* Split blits that cross physical y_wrap case.
2031 * Pathological case involves 4 blits, better to use recursive
2032 * code rather than unrolled case
2034 * Recursive invocations don't need to erase the cursor over and
2035 * over again, so we use fbcon_bmove_rec()
2037 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2038 p
->vrows
- p
->yscroll
);
2041 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2042 int dy
, int dx
, int height
, int width
, u_int y_break
)
2044 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2045 struct fbcon_ops
*ops
= info
->fbcon_par
;
2048 if (sy
< y_break
&& sy
+ height
> y_break
) {
2050 if (dy
< sy
) { /* Avoid trashing self */
2051 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2053 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2054 height
- b
, width
, y_break
);
2056 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2057 height
- b
, width
, y_break
);
2058 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2064 if (dy
< y_break
&& dy
+ height
> y_break
) {
2066 if (dy
< sy
) { /* Avoid trashing self */
2067 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2069 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2070 height
- b
, width
, y_break
);
2072 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2073 height
- b
, width
, y_break
);
2074 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2079 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2083 static void updatescrollmode(struct display
*p
,
2084 struct fb_info
*info
,
2087 struct fbcon_ops
*ops
= info
->fbcon_par
;
2088 int fh
= vc
->vc_font
.height
;
2089 int cap
= info
->flags
;
2091 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2092 info
->fix
.xpanstep
);
2093 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2094 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2095 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2096 info
->var
.xres_virtual
);
2097 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2098 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2099 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2100 divides(ywrap
, vc
->vc_font
.height
) &&
2101 divides(vc
->vc_font
.height
, vyres
) &&
2102 divides(vc
->vc_font
.height
, yres
);
2103 int reading_fast
= cap
& FBINFO_READS_FAST
;
2104 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2105 !(cap
& FBINFO_HWACCEL_DISABLED
);
2106 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2107 !(cap
& FBINFO_HWACCEL_DISABLED
);
2109 p
->vrows
= vyres
/fh
;
2110 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2111 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2112 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2115 if (good_wrap
|| good_pan
) {
2116 if (reading_fast
|| fast_copyarea
)
2117 p
->scrollmode
= good_wrap
?
2118 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2120 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2123 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2124 p
->scrollmode
= SCROLL_MOVE
;
2126 p
->scrollmode
= SCROLL_REDRAW
;
2130 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2131 unsigned int height
, unsigned int user
)
2133 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2134 struct fbcon_ops
*ops
= info
->fbcon_par
;
2135 struct display
*p
= &fb_display
[vc
->vc_num
];
2136 struct fb_var_screeninfo var
= info
->var
;
2137 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2139 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2140 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2141 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2142 vc
->vc_font
.height
);
2143 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2145 var
.xres
= virt_w
* virt_fw
;
2146 var
.yres
= virt_h
* virt_fh
;
2147 x_diff
= info
->var
.xres
- var
.xres
;
2148 y_diff
= info
->var
.yres
- var
.yres
;
2149 if (x_diff
< 0 || x_diff
> virt_fw
||
2150 y_diff
< 0 || y_diff
> virt_fh
) {
2151 const struct fb_videomode
*mode
;
2153 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2154 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2157 display_to_var(&var
, p
);
2158 fb_videomode_to_var(&var
, mode
);
2160 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2163 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2164 if (con_is_visible(vc
)) {
2165 var
.activate
= FB_ACTIVATE_NOW
|
2167 fb_set_var(info
, &var
);
2169 var_to_display(p
, &info
->var
, info
);
2170 ops
->var
= info
->var
;
2172 updatescrollmode(p
, info
, vc
);
2176 static int fbcon_switch(struct vc_data
*vc
)
2178 struct fb_info
*info
, *old_info
= NULL
;
2179 struct fbcon_ops
*ops
;
2180 struct display
*p
= &fb_display
[vc
->vc_num
];
2181 struct fb_var_screeninfo var
;
2182 int i
, ret
, prev_console
, charcnt
= 256;
2184 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2185 ops
= info
->fbcon_par
;
2189 fbcon_set_origin(vc
);
2190 softback_top
= softback_curr
= softback_in
= softback_buf
;
2192 fbcon_update_softback(vc
);
2195 if (logo_shown
>= 0) {
2196 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2198 if (conp2
->vc_top
== logo_lines
2199 && conp2
->vc_bottom
== conp2
->vc_rows
)
2201 logo_shown
= FBCON_LOGO_CANSHOW
;
2204 prev_console
= ops
->currcon
;
2205 if (prev_console
!= -1)
2206 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2208 * FIXME: If we have multiple fbdev's loaded, we need to
2209 * update all info->currcon. Perhaps, we can place this
2210 * in a centralized structure, but this might break some
2213 * info->currcon = vc->vc_num;
2215 for (i
= 0; i
< FB_MAX
; i
++) {
2216 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2217 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2219 o
->currcon
= vc
->vc_num
;
2222 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2223 display_to_var(&var
, p
);
2224 var
.activate
= FB_ACTIVATE_NOW
;
2227 * make sure we don't unnecessarily trip the memcmp()
2230 info
->var
.activate
= var
.activate
;
2231 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2232 fb_set_var(info
, &var
);
2233 ops
->var
= info
->var
;
2235 if (old_info
!= NULL
&& (old_info
!= info
||
2236 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2237 if (info
->fbops
->fb_set_par
) {
2238 ret
= info
->fbops
->fb_set_par(info
);
2241 printk(KERN_ERR
"fbcon_switch: detected "
2242 "unhandled fb_set_par error, "
2243 "error code %d\n", ret
);
2246 if (old_info
!= info
)
2247 fbcon_del_cursor_timer(old_info
);
2250 if (fbcon_is_inactive(vc
, info
) ||
2251 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2252 fbcon_del_cursor_timer(info
);
2254 fbcon_add_cursor_timer(info
);
2256 set_blitting_type(vc
, info
);
2257 ops
->cursor_reset
= 1;
2259 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2260 ops
->rotate
= FB_ROTATE_UR
;
2261 set_blitting_type(vc
, info
);
2264 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2265 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2268 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2271 vc
->vc_complement_mask
<<= 1;
2273 updatescrollmode(p
, info
, vc
);
2275 switch (p
->scrollmode
) {
2276 case SCROLL_WRAP_MOVE
:
2277 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2279 case SCROLL_PAN_MOVE
:
2280 case SCROLL_PAN_REDRAW
:
2281 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2282 if (scrollback_phys_max
< 0)
2283 scrollback_phys_max
= 0;
2286 scrollback_phys_max
= 0;
2291 scrollback_current
= 0;
2293 if (!fbcon_is_inactive(vc
, info
)) {
2294 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2295 ops
->update_start(info
);
2298 fbcon_set_palette(vc
, color_table
);
2299 fbcon_clear_margins(vc
, 0);
2301 if (logo_shown
== FBCON_LOGO_DRAW
) {
2303 logo_shown
= fg_console
;
2304 /* This is protected above by initmem_freed */
2305 fb_show_logo(info
, ops
->rotate
);
2307 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2308 vc
->vc_size_row
* (vc
->vc_bottom
-
2315 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2318 struct fb_event event
;
2321 unsigned short charmask
= vc
->vc_hi_font_mask
?
2323 unsigned short oldc
;
2325 oldc
= vc
->vc_video_erase_char
;
2326 vc
->vc_video_erase_char
&= charmask
;
2327 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2328 vc
->vc_video_erase_char
= oldc
;
2332 if (!lock_fb_info(info
))
2335 event
.data
= &blank
;
2336 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2337 unlock_fb_info(info
);
2340 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2342 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2343 struct fbcon_ops
*ops
= info
->fbcon_par
;
2346 struct fb_var_screeninfo var
= info
->var
;
2351 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2352 fb_set_var(info
, &var
);
2354 ops
->var
= info
->var
;
2358 if (!fbcon_is_inactive(vc
, info
)) {
2359 if (ops
->blank_state
!= blank
) {
2360 ops
->blank_state
= blank
;
2361 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2362 ops
->cursor_flash
= (!blank
);
2364 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2365 if (fb_blank(info
, blank
))
2366 fbcon_generic_blank(vc
, info
, blank
);
2373 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2374 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2375 fbcon_del_cursor_timer(info
);
2377 fbcon_add_cursor_timer(info
);
2382 static int fbcon_debug_enter(struct vc_data
*vc
)
2384 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2385 struct fbcon_ops
*ops
= info
->fbcon_par
;
2387 ops
->save_graphics
= ops
->graphics
;
2389 if (info
->fbops
->fb_debug_enter
)
2390 info
->fbops
->fb_debug_enter(info
);
2391 fbcon_set_palette(vc
, color_table
);
2395 static int fbcon_debug_leave(struct vc_data
*vc
)
2397 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2398 struct fbcon_ops
*ops
= info
->fbcon_par
;
2400 ops
->graphics
= ops
->save_graphics
;
2401 if (info
->fbops
->fb_debug_leave
)
2402 info
->fbops
->fb_debug_leave(info
);
2406 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2408 u8
*fontdata
= vc
->vc_font
.data
;
2409 u8
*data
= font
->data
;
2412 font
->width
= vc
->vc_font
.width
;
2413 font
->height
= vc
->vc_font
.height
;
2414 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2418 if (font
->width
<= 8) {
2419 j
= vc
->vc_font
.height
;
2420 for (i
= 0; i
< font
->charcount
; i
++) {
2421 memcpy(data
, fontdata
, j
);
2422 memset(data
+ j
, 0, 32 - j
);
2426 } else if (font
->width
<= 16) {
2427 j
= vc
->vc_font
.height
* 2;
2428 for (i
= 0; i
< font
->charcount
; i
++) {
2429 memcpy(data
, fontdata
, j
);
2430 memset(data
+ j
, 0, 64 - j
);
2434 } else if (font
->width
<= 24) {
2435 for (i
= 0; i
< font
->charcount
; i
++) {
2436 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2437 *data
++ = fontdata
[0];
2438 *data
++ = fontdata
[1];
2439 *data
++ = fontdata
[2];
2440 fontdata
+= sizeof(u32
);
2442 memset(data
, 0, 3 * (32 - j
));
2443 data
+= 3 * (32 - j
);
2446 j
= vc
->vc_font
.height
* 4;
2447 for (i
= 0; i
< font
->charcount
; i
++) {
2448 memcpy(data
, fontdata
, j
);
2449 memset(data
+ j
, 0, 128 - j
);
2457 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2458 static void set_vc_hi_font(struct vc_data
*vc
, bool set
)
2461 vc
->vc_hi_font_mask
= 0;
2462 if (vc
->vc_can_do_color
) {
2463 vc
->vc_complement_mask
>>= 1;
2464 vc
->vc_s_complement_mask
>>= 1;
2467 /* ++Edmund: reorder the attribute bits */
2468 if (vc
->vc_can_do_color
) {
2469 unsigned short *cp
=
2470 (unsigned short *) vc
->vc_origin
;
2471 int count
= vc
->vc_screenbuf_size
/ 2;
2473 for (; count
> 0; count
--, cp
++) {
2475 scr_writew(((c
& 0xfe00) >> 1) |
2478 c
= vc
->vc_video_erase_char
;
2479 vc
->vc_video_erase_char
=
2480 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2484 vc
->vc_hi_font_mask
= 0x100;
2485 if (vc
->vc_can_do_color
) {
2486 vc
->vc_complement_mask
<<= 1;
2487 vc
->vc_s_complement_mask
<<= 1;
2490 /* ++Edmund: reorder the attribute bits */
2492 unsigned short *cp
=
2493 (unsigned short *) vc
->vc_origin
;
2494 int count
= vc
->vc_screenbuf_size
/ 2;
2496 for (; count
> 0; count
--, cp
++) {
2497 unsigned short newc
;
2499 if (vc
->vc_can_do_color
)
2501 ((c
& 0xff00) << 1) | (c
&
2505 scr_writew(newc
, cp
);
2507 c
= vc
->vc_video_erase_char
;
2508 if (vc
->vc_can_do_color
) {
2509 vc
->vc_video_erase_char
=
2510 ((c
& 0xff00) << 1) | (c
& 0xff);
2513 vc
->vc_video_erase_char
= c
& ~0x100;
2518 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2519 const u8
* data
, int userfont
)
2521 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2522 struct fbcon_ops
*ops
= info
->fbcon_par
;
2523 struct display
*p
= &fb_display
[vc
->vc_num
];
2526 char *old_data
= NULL
;
2528 if (con_is_visible(vc
) && softback_lines
)
2529 fbcon_set_origin(vc
);
2531 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2533 old_data
= vc
->vc_font
.data
;
2535 cnt
= FNTCHARCNT(data
);
2538 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2539 if ((p
->userfont
= userfont
))
2541 vc
->vc_font
.width
= w
;
2542 vc
->vc_font
.height
= h
;
2543 if (vc
->vc_hi_font_mask
&& cnt
== 256)
2544 set_vc_hi_font(vc
, false);
2545 else if (!vc
->vc_hi_font_mask
&& cnt
== 512)
2546 set_vc_hi_font(vc
, true);
2551 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2552 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2555 vc_resize(vc
, cols
, rows
);
2556 if (con_is_visible(vc
) && softback_buf
)
2557 fbcon_update_softback(vc
);
2558 } else if (con_is_visible(vc
)
2559 && vc
->vc_mode
== KD_TEXT
) {
2560 fbcon_clear_margins(vc
, 0);
2564 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2565 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2569 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2571 struct display
*od
= &fb_display
[con
];
2572 struct console_font
*f
= &vc
->vc_font
;
2574 if (od
->fontdata
== f
->data
)
2575 return 0; /* already the same font... */
2576 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2580 * User asked to set font; we are guaranteed that
2581 * a) width and height are in range 1..32
2582 * b) charcount does not exceed 512
2583 * but lets not assume that, since someone might someday want to use larger
2584 * fonts. And charcount of 512 is small for unicode support.
2586 * However, user space gives the font in 32 rows , regardless of
2587 * actual font height. So a new API is needed if support for larger fonts
2588 * is ever implemented.
2591 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2593 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2594 unsigned charcount
= font
->charcount
;
2595 int w
= font
->width
;
2596 int h
= font
->height
;
2599 u8
*new_data
, *data
= font
->data
;
2600 int pitch
= (font
->width
+7) >> 3;
2602 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2603 * If not this check should be changed to charcount < 256 */
2604 if (charcount
!= 256 && charcount
!= 512)
2607 /* Make sure drawing engine can handle the font */
2608 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2609 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2612 /* Make sure driver can handle the font length */
2613 if (fbcon_invalid_charcount(info
, charcount
))
2616 size
= h
* pitch
* charcount
;
2618 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2623 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2624 FNTSIZE(new_data
) = size
;
2625 FNTCHARCNT(new_data
) = charcount
;
2626 REFCOUNT(new_data
) = 0; /* usage counter */
2627 for (i
=0; i
< charcount
; i
++) {
2628 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2631 /* Since linux has a nice crc32 function use it for counting font
2633 csum
= crc32(0, new_data
, size
);
2635 FNTSUM(new_data
) = csum
;
2636 /* Check if the same font is on some other console already */
2637 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2638 struct vc_data
*tmp
= vc_cons
[i
].d
;
2640 if (fb_display
[i
].userfont
&&
2641 fb_display
[i
].fontdata
&&
2642 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2643 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2644 tmp
->vc_font
.width
== w
&&
2645 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2646 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2647 new_data
= (u8
*)fb_display
[i
].fontdata
;
2651 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2654 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2656 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2657 const struct font_desc
*f
;
2660 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2661 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2662 else if (!(f
= find_font(name
)))
2665 font
->width
= f
->width
;
2666 font
->height
= f
->height
;
2667 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2670 static u16 palette_red
[16];
2671 static u16 palette_green
[16];
2672 static u16 palette_blue
[16];
2674 static struct fb_cmap palette_cmap
= {
2675 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2678 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
)
2680 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2684 if (fbcon_is_inactive(vc
, info
))
2687 if (!con_is_visible(vc
))
2690 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2692 for (i
= j
= 0; i
< 16; i
++) {
2694 val
= vc
->vc_palette
[j
++];
2695 palette_red
[k
] = (val
<< 8) | val
;
2696 val
= vc
->vc_palette
[j
++];
2697 palette_green
[k
] = (val
<< 8) | val
;
2698 val
= vc
->vc_palette
[j
++];
2699 palette_blue
[k
] = (val
<< 8) | val
;
2701 palette_cmap
.len
= 16;
2702 palette_cmap
.start
= 0;
2704 * If framebuffer is capable of less than 16 colors,
2705 * use default palette of fbcon.
2708 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2710 fb_set_cmap(&palette_cmap
, info
);
2713 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2718 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2719 return (u16
*) (vc
->vc_origin
+ offset
);
2720 line
= offset
/ vc
->vc_size_row
;
2721 if (line
>= softback_lines
)
2722 return (u16
*) (vc
->vc_origin
+ offset
-
2723 softback_lines
* vc
->vc_size_row
);
2724 p
= softback_curr
+ offset
;
2725 if (p
>= softback_end
)
2726 p
+= softback_buf
- softback_end
;
2730 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2736 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2737 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2739 x
= offset
% vc
->vc_cols
;
2740 y
= offset
/ vc
->vc_cols
;
2741 if (vc
->vc_num
== fg_console
)
2742 y
+= softback_lines
;
2743 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2744 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2745 unsigned long offset
= pos
- softback_curr
;
2747 if (pos
< softback_curr
)
2748 offset
+= softback_end
- softback_buf
;
2750 x
= offset
% vc
->vc_cols
;
2751 y
= offset
/ vc
->vc_cols
;
2752 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2753 if (ret
== softback_end
)
2755 if (ret
== softback_in
)
2756 ret
= vc
->vc_origin
;
2758 /* Should not happen */
2760 ret
= vc
->vc_origin
;
2769 /* As we might be inside of softback, we may work with non-contiguous buffer,
2770 that's why we have to use a separate routine. */
2771 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2774 u16 a
= scr_readw(p
);
2775 if (!vc
->vc_can_do_color
)
2777 else if (vc
->vc_hi_font_mask
== 0x100)
2778 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2779 (((a
) & 0x0e00) << 4);
2781 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2782 (((a
) & 0x0700) << 4);
2784 if (p
== (u16
*) softback_end
)
2785 p
= (u16
*) softback_buf
;
2786 if (p
== (u16
*) softback_in
)
2787 p
= (u16
*) vc
->vc_origin
;
2791 static void fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2793 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2794 struct fbcon_ops
*ops
= info
->fbcon_par
;
2795 struct display
*disp
= &fb_display
[fg_console
];
2796 int offset
, limit
, scrollback_old
;
2799 if (vc
->vc_num
!= fg_console
)
2801 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2803 if (logo_shown
>= 0) {
2804 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2806 if (conp2
->vc_top
== logo_lines
2807 && conp2
->vc_bottom
== conp2
->vc_rows
)
2809 if (logo_shown
== vc
->vc_num
) {
2815 logo_lines
* vc
->vc_size_row
;
2816 for (i
= 0; i
< logo_lines
; i
++) {
2817 if (p
== softback_top
)
2819 if (p
== softback_buf
)
2821 p
-= vc
->vc_size_row
;
2822 q
-= vc
->vc_size_row
;
2823 scr_memcpyw((u16
*) q
, (u16
*) p
,
2826 softback_in
= softback_curr
= p
;
2827 update_region(vc
, vc
->vc_origin
,
2828 logo_lines
* vc
->vc_cols
);
2830 logo_shown
= FBCON_LOGO_CANSHOW
;
2832 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2833 fbcon_redraw_softback(vc
, disp
, lines
);
2834 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2838 if (!scrollback_phys_max
)
2841 scrollback_old
= scrollback_current
;
2842 scrollback_current
-= lines
;
2843 if (scrollback_current
< 0)
2844 scrollback_current
= 0;
2845 else if (scrollback_current
> scrollback_max
)
2846 scrollback_current
= scrollback_max
;
2847 if (scrollback_current
== scrollback_old
)
2850 if (fbcon_is_inactive(vc
, info
))
2853 fbcon_cursor(vc
, CM_ERASE
);
2855 offset
= disp
->yscroll
- scrollback_current
;
2856 limit
= disp
->vrows
;
2857 switch (disp
->scrollmode
) {
2858 case SCROLL_WRAP_MOVE
:
2859 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2861 case SCROLL_PAN_MOVE
:
2862 case SCROLL_PAN_REDRAW
:
2863 limit
-= vc
->vc_rows
;
2864 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2869 else if (offset
>= limit
)
2872 ops
->var
.xoffset
= 0;
2873 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2874 ops
->update_start(info
);
2876 if (!scrollback_current
)
2877 fbcon_cursor(vc
, CM_DRAW
);
2880 static int fbcon_set_origin(struct vc_data
*vc
)
2883 fbcon_scrolldelta(vc
, softback_lines
);
2887 static void fbcon_suspended(struct fb_info
*info
)
2889 struct vc_data
*vc
= NULL
;
2890 struct fbcon_ops
*ops
= info
->fbcon_par
;
2892 if (!ops
|| ops
->currcon
< 0)
2894 vc
= vc_cons
[ops
->currcon
].d
;
2896 /* Clear cursor, restore saved data */
2897 fbcon_cursor(vc
, CM_ERASE
);
2900 static void fbcon_resumed(struct fb_info
*info
)
2903 struct fbcon_ops
*ops
= info
->fbcon_par
;
2905 if (!ops
|| ops
->currcon
< 0)
2907 vc
= vc_cons
[ops
->currcon
].d
;
2912 static void fbcon_modechanged(struct fb_info
*info
)
2914 struct fbcon_ops
*ops
= info
->fbcon_par
;
2919 if (!ops
|| ops
->currcon
< 0)
2921 vc
= vc_cons
[ops
->currcon
].d
;
2922 if (vc
->vc_mode
!= KD_TEXT
||
2923 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2926 p
= &fb_display
[vc
->vc_num
];
2927 set_blitting_type(vc
, info
);
2929 if (con_is_visible(vc
)) {
2930 var_to_display(p
, &info
->var
, info
);
2931 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2932 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2933 cols
/= vc
->vc_font
.width
;
2934 rows
/= vc
->vc_font
.height
;
2935 vc_resize(vc
, cols
, rows
);
2936 updatescrollmode(p
, info
, vc
);
2938 scrollback_current
= 0;
2940 if (!fbcon_is_inactive(vc
, info
)) {
2941 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2942 ops
->update_start(info
);
2945 fbcon_set_palette(vc
, color_table
);
2948 fbcon_update_softback(vc
);
2952 static void fbcon_set_all_vcs(struct fb_info
*info
)
2954 struct fbcon_ops
*ops
= info
->fbcon_par
;
2957 int i
, rows
, cols
, fg
= -1;
2959 if (!ops
|| ops
->currcon
< 0)
2962 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2964 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2965 registered_fb
[con2fb_map
[i
]] != info
)
2968 if (con_is_visible(vc
)) {
2973 p
= &fb_display
[vc
->vc_num
];
2974 set_blitting_type(vc
, info
);
2975 var_to_display(p
, &info
->var
, info
);
2976 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2977 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2978 cols
/= vc
->vc_font
.width
;
2979 rows
/= vc
->vc_font
.height
;
2980 vc_resize(vc
, cols
, rows
);
2984 fbcon_modechanged(info
);
2987 static int fbcon_mode_deleted(struct fb_info
*info
,
2988 struct fb_videomode
*mode
)
2990 struct fb_info
*fb_info
;
2992 int i
, j
, found
= 0;
2994 /* before deletion, ensure that mode is not in use */
2995 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2999 fb_info
= registered_fb
[j
];
3000 if (fb_info
!= info
)
3005 if (fb_mode_is_equal(p
->mode
, mode
)) {
3013 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3014 static int fbcon_unbind(void)
3018 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3022 fbcon_has_console_bind
= 0;
3027 static inline int fbcon_unbind(void)
3031 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3033 /* called with console_lock held */
3034 static int fbcon_fb_unbind(int idx
)
3036 int i
, new_idx
= -1, ret
= 0;
3038 if (!fbcon_has_console_bind
)
3041 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3042 if (con2fb_map
[i
] != idx
&&
3043 con2fb_map
[i
] != -1) {
3049 if (new_idx
!= -1) {
3050 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3051 if (con2fb_map
[i
] == idx
)
3052 set_con2fb_map(i
, new_idx
, 0);
3055 struct fb_info
*info
= registered_fb
[idx
];
3057 /* This is sort of like set_con2fb_map, except it maps
3058 * the consoles to no device and then releases the
3059 * oldinfo to free memory and cancel the cursor blink
3060 * timer. I can imagine this just becoming part of
3061 * set_con2fb_map where new_idx is -1
3063 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3064 if (con2fb_map
[i
] == idx
) {
3066 if (!search_fb_in_map(idx
)) {
3067 ret
= con2fb_release_oldinfo(vc_cons
[i
].d
,
3071 con2fb_map
[i
] = idx
;
3077 ret
= fbcon_unbind();
3083 /* called with console_lock held */
3084 static int fbcon_fb_unregistered(struct fb_info
*info
)
3089 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3090 if (con2fb_map
[i
] == idx
)
3094 if (idx
== info_idx
) {
3097 for (i
= 0; i
< FB_MAX
; i
++) {
3098 if (registered_fb
[i
] != NULL
) {
3105 if (info_idx
!= -1) {
3106 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3107 if (con2fb_map
[i
] == -1)
3108 con2fb_map
[i
] = info_idx
;
3112 if (primary_device
== idx
)
3113 primary_device
= -1;
3115 if (!num_registered_fb
)
3116 do_unregister_con_driver(&fb_con
);
3121 /* called with console_lock held */
3122 static void fbcon_remap_all(int idx
)
3125 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3126 set_con2fb_map(i
, idx
, 0);
3128 if (con_is_bound(&fb_con
)) {
3129 printk(KERN_INFO
"fbcon: Remapping primary device, "
3130 "fb%i, to tty %i-%i\n", idx
,
3131 first_fb_vc
+ 1, last_fb_vc
+ 1);
3136 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3137 static void fbcon_select_primary(struct fb_info
*info
)
3139 if (!map_override
&& primary_device
== -1 &&
3140 fb_is_primary_device(info
)) {
3143 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3144 info
->fix
.id
, info
->node
);
3145 primary_device
= info
->node
;
3147 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3148 con2fb_map_boot
[i
] = primary_device
;
3150 if (con_is_bound(&fb_con
)) {
3151 printk(KERN_INFO
"fbcon: Remapping primary device, "
3152 "fb%i, to tty %i-%i\n", info
->node
,
3153 first_fb_vc
+ 1, last_fb_vc
+ 1);
3154 info_idx
= primary_device
;
3160 static inline void fbcon_select_primary(struct fb_info
*info
)
3164 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3166 /* called with console_lock held */
3167 static int fbcon_fb_registered(struct fb_info
*info
)
3169 int ret
= 0, i
, idx
;
3172 fbcon_select_primary(info
);
3174 if (info_idx
== -1) {
3175 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3176 if (con2fb_map_boot
[i
] == idx
) {
3183 ret
= do_fbcon_takeover(1);
3185 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3186 if (con2fb_map_boot
[i
] == idx
)
3187 set_con2fb_map(i
, idx
, 0);
3194 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3196 struct fbcon_ops
*ops
= info
->fbcon_par
;
3199 if (!ops
|| ops
->currcon
< 0)
3202 vc
= vc_cons
[ops
->currcon
].d
;
3203 if (vc
->vc_mode
!= KD_TEXT
||
3204 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3207 if (con_is_visible(vc
)) {
3211 do_unblank_screen(0);
3213 ops
->blank_state
= blank
;
3216 static void fbcon_new_modelist(struct fb_info
*info
)
3220 struct fb_var_screeninfo var
;
3221 const struct fb_videomode
*mode
;
3223 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3224 if (registered_fb
[con2fb_map
[i
]] != info
)
3226 if (!fb_display
[i
].mode
)
3229 display_to_var(&var
, &fb_display
[i
]);
3230 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3232 fb_videomode_to_var(&var
, mode
);
3233 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3237 static void fbcon_get_requirement(struct fb_info
*info
,
3238 struct fb_blit_caps
*caps
)
3246 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3248 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3249 info
->node
== con2fb_map
[i
]) {
3251 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3252 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3253 charcnt
= (p
->userfont
) ?
3254 FNTCHARCNT(p
->fontdata
) : 256;
3255 if (caps
->len
< charcnt
)
3256 caps
->len
= charcnt
;
3260 vc
= vc_cons
[fg_console
].d
;
3262 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3263 info
->node
== con2fb_map
[fg_console
]) {
3264 p
= &fb_display
[fg_console
];
3265 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3266 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3267 caps
->len
= (p
->userfont
) ?
3268 FNTCHARCNT(p
->fontdata
) : 256;
3273 static int fbcon_event_notify(struct notifier_block
*self
,
3274 unsigned long action
, void *data
)
3276 struct fb_event
*event
= data
;
3277 struct fb_info
*info
= event
->info
;
3278 struct fb_videomode
*mode
;
3279 struct fb_con2fbmap
*con2fb
;
3280 struct fb_blit_caps
*caps
;
3284 * ignore all events except driver registration and deregistration
3285 * if fbcon is not active
3287 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3288 action
== FB_EVENT_FB_UNREGISTERED
))
3292 case FB_EVENT_SUSPEND
:
3293 fbcon_suspended(info
);
3295 case FB_EVENT_RESUME
:
3296 fbcon_resumed(info
);
3298 case FB_EVENT_MODE_CHANGE
:
3299 fbcon_modechanged(info
);
3301 case FB_EVENT_MODE_CHANGE_ALL
:
3302 fbcon_set_all_vcs(info
);
3304 case FB_EVENT_MODE_DELETE
:
3306 ret
= fbcon_mode_deleted(info
, mode
);
3308 case FB_EVENT_FB_UNBIND
:
3310 ret
= fbcon_fb_unbind(idx
);
3312 case FB_EVENT_FB_REGISTERED
:
3313 ret
= fbcon_fb_registered(info
);
3315 case FB_EVENT_FB_UNREGISTERED
:
3316 ret
= fbcon_fb_unregistered(info
);
3318 case FB_EVENT_SET_CONSOLE_MAP
:
3319 /* called with console lock held */
3320 con2fb
= event
->data
;
3321 ret
= set_con2fb_map(con2fb
->console
- 1,
3322 con2fb
->framebuffer
, 1);
3324 case FB_EVENT_GET_CONSOLE_MAP
:
3325 con2fb
= event
->data
;
3326 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3328 case FB_EVENT_BLANK
:
3329 fbcon_fb_blanked(info
, *(int *)event
->data
);
3331 case FB_EVENT_NEW_MODELIST
:
3332 fbcon_new_modelist(info
);
3334 case FB_EVENT_GET_REQ
:
3336 fbcon_get_requirement(info
, caps
);
3338 case FB_EVENT_REMAP_ALL_CONSOLE
:
3340 fbcon_remap_all(idx
);
3348 * The console `switch' structure for the frame buffer based console
3351 static const struct consw fb_con
= {
3352 .owner
= THIS_MODULE
,
3353 .con_startup
= fbcon_startup
,
3354 .con_init
= fbcon_init
,
3355 .con_deinit
= fbcon_deinit
,
3356 .con_clear
= fbcon_clear
,
3357 .con_putc
= fbcon_putc
,
3358 .con_putcs
= fbcon_putcs
,
3359 .con_cursor
= fbcon_cursor
,
3360 .con_scroll
= fbcon_scroll
,
3361 .con_switch
= fbcon_switch
,
3362 .con_blank
= fbcon_blank
,
3363 .con_font_set
= fbcon_set_font
,
3364 .con_font_get
= fbcon_get_font
,
3365 .con_font_default
= fbcon_set_def_font
,
3366 .con_font_copy
= fbcon_copy_font
,
3367 .con_set_palette
= fbcon_set_palette
,
3368 .con_scrolldelta
= fbcon_scrolldelta
,
3369 .con_set_origin
= fbcon_set_origin
,
3370 .con_invert_region
= fbcon_invert_region
,
3371 .con_screen_pos
= fbcon_screen_pos
,
3372 .con_getxy
= fbcon_getxy
,
3373 .con_resize
= fbcon_resize
,
3374 .con_debug_enter
= fbcon_debug_enter
,
3375 .con_debug_leave
= fbcon_debug_leave
,
3378 static struct notifier_block fbcon_event_notifier
= {
3379 .notifier_call
= fbcon_event_notify
,
3382 static ssize_t
store_rotate(struct device
*device
,
3383 struct device_attribute
*attr
, const char *buf
,
3386 struct fb_info
*info
;
3390 if (fbcon_has_exited
)
3394 idx
= con2fb_map
[fg_console
];
3396 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3399 info
= registered_fb
[idx
];
3400 rotate
= simple_strtoul(buf
, last
, 0);
3401 fbcon_rotate(info
, rotate
);
3407 static ssize_t
store_rotate_all(struct device
*device
,
3408 struct device_attribute
*attr
,const char *buf
,
3411 struct fb_info
*info
;
3415 if (fbcon_has_exited
)
3419 idx
= con2fb_map
[fg_console
];
3421 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3424 info
= registered_fb
[idx
];
3425 rotate
= simple_strtoul(buf
, last
, 0);
3426 fbcon_rotate_all(info
, rotate
);
3432 static ssize_t
show_rotate(struct device
*device
,
3433 struct device_attribute
*attr
,char *buf
)
3435 struct fb_info
*info
;
3436 int rotate
= 0, idx
;
3438 if (fbcon_has_exited
)
3442 idx
= con2fb_map
[fg_console
];
3444 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3447 info
= registered_fb
[idx
];
3448 rotate
= fbcon_get_rotate(info
);
3451 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3454 static ssize_t
show_cursor_blink(struct device
*device
,
3455 struct device_attribute
*attr
, char *buf
)
3457 struct fb_info
*info
;
3458 struct fbcon_ops
*ops
;
3459 int idx
, blink
= -1;
3461 if (fbcon_has_exited
)
3465 idx
= con2fb_map
[fg_console
];
3467 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3470 info
= registered_fb
[idx
];
3471 ops
= info
->fbcon_par
;
3476 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3479 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3482 static ssize_t
store_cursor_blink(struct device
*device
,
3483 struct device_attribute
*attr
,
3484 const char *buf
, size_t count
)
3486 struct fb_info
*info
;
3490 if (fbcon_has_exited
)
3494 idx
= con2fb_map
[fg_console
];
3496 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3499 info
= registered_fb
[idx
];
3501 if (!info
->fbcon_par
)
3504 blink
= simple_strtoul(buf
, last
, 0);
3507 fbcon_cursor_noblink
= 0;
3508 fbcon_add_cursor_timer(info
);
3510 fbcon_cursor_noblink
= 1;
3511 fbcon_del_cursor_timer(info
);
3519 static struct device_attribute device_attrs
[] = {
3520 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3521 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3522 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3523 store_cursor_blink
),
3526 static int fbcon_init_device(void)
3530 fbcon_has_sysfs
= 1;
3532 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3533 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3541 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3543 fbcon_has_sysfs
= 0;
3549 static void fbcon_start(void)
3551 if (num_registered_fb
) {
3556 for (i
= 0; i
< FB_MAX
; i
++) {
3557 if (registered_fb
[i
] != NULL
) {
3563 do_fbcon_takeover(0);
3569 static void fbcon_exit(void)
3571 struct fb_info
*info
;
3574 if (fbcon_has_exited
)
3577 kfree((void *)softback_buf
);
3580 for (i
= 0; i
< FB_MAX
; i
++) {
3584 info
= registered_fb
[i
];
3589 if (info
->queue
.func
)
3590 pending
= cancel_work_sync(&info
->queue
);
3591 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3594 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3595 if (con2fb_map
[j
] == i
) {
3602 if (info
->fbops
->fb_release
)
3603 info
->fbops
->fb_release(info
, 0);
3604 module_put(info
->fbops
->owner
);
3606 if (info
->fbcon_par
) {
3607 struct fbcon_ops
*ops
= info
->fbcon_par
;
3609 fbcon_del_cursor_timer(info
);
3610 kfree(ops
->cursor_src
);
3611 kfree(ops
->cursor_state
.mask
);
3612 kfree(info
->fbcon_par
);
3613 info
->fbcon_par
= NULL
;
3616 if (info
->queue
.func
== fb_flashcursor
)
3617 info
->queue
.func
= NULL
;
3621 fbcon_has_exited
= 1;
3624 void __init
fb_console_init(void)
3629 fb_register_client(&fbcon_event_notifier
);
3630 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3633 if (IS_ERR(fbcon_device
)) {
3634 printk(KERN_WARNING
"Unable to create device "
3635 "for fbcon; errno = %ld\n",
3636 PTR_ERR(fbcon_device
));
3637 fbcon_device
= NULL
;
3639 fbcon_init_device();
3641 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3650 static void __exit
fbcon_deinit_device(void)
3654 if (fbcon_has_sysfs
) {
3655 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3656 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3658 fbcon_has_sysfs
= 0;
3662 void __exit
fb_console_exit(void)
3665 fb_unregister_client(&fbcon_event_notifier
);
3666 fbcon_deinit_device();
3667 device_destroy(fb_class
, MKDEV(0, 0));
3669 do_unregister_con_driver(&fb_con
);