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(struct timer_list
*t
)
400 struct fbcon_ops
*ops
= from_timer(ops
, t
, cursor_timer
);
401 struct fb_info
*info
= ops
->info
;
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 timer_setup(&ops
->cursor_timer
, cursor_timer_handler
, 0);
418 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
419 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
423 static void fbcon_del_cursor_timer(struct fb_info
*info
)
425 struct fbcon_ops
*ops
= info
->fbcon_par
;
427 if (info
->queue
.func
== fb_flashcursor
&&
428 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
429 del_timer_sync(&ops
->cursor_timer
);
430 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
435 static int __init
fb_console_setup(char *this_opt
)
440 if (!this_opt
|| !*this_opt
)
443 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
444 if (!strncmp(options
, "font:", 5)) {
445 strlcpy(fontname
, options
+ 5, sizeof(fontname
));
449 if (!strncmp(options
, "scrollback:", 11)) {
452 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
453 if (*options
== 'k' || *options
== 'K') {
454 fbcon_softback_size
*= 1024;
460 if (!strncmp(options
, "map:", 4)) {
463 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
467 (options
[j
++]-'0') % FB_MAX
;
470 fbcon_map_override();
475 if (!strncmp(options
, "vc:", 3)) {
478 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
481 if (*options
++ == '-')
482 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
483 fbcon_is_default
= 0;
487 if (!strncmp(options
, "rotate:", 7)) {
490 initial_rotation
= simple_strtoul(options
, &options
, 0);
491 if (initial_rotation
> 3)
492 initial_rotation
= 0;
496 if (!strncmp(options
, "margin:", 7)) {
499 margin_color
= simple_strtoul(options
, &options
, 0);
506 __setup("fbcon=", fb_console_setup
);
509 static int search_fb_in_map(int idx
)
513 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
514 if (con2fb_map
[i
] == idx
)
520 static int search_for_mapped_con(void)
524 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
525 if (con2fb_map
[i
] != -1)
531 static int do_fbcon_takeover(int show_logo
)
535 if (!num_registered_fb
)
539 logo_shown
= FBCON_LOGO_DONTSHOW
;
541 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
542 con2fb_map
[i
] = info_idx
;
544 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
548 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
552 fbcon_has_console_bind
= 1;
559 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
560 int cols
, int rows
, int new_cols
, int new_rows
)
562 logo_shown
= FBCON_LOGO_DONTSHOW
;
565 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
566 int cols
, int rows
, int new_cols
, int new_rows
)
568 /* Need to make room for the logo */
569 struct fbcon_ops
*ops
= info
->fbcon_par
;
570 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
571 unsigned short *save
= NULL
, *r
, *q
;
574 if (info
->fbops
->owner
) {
575 logo_shown
= FBCON_LOGO_DONTSHOW
;
580 * remove underline attribute from erase character
581 * if black and white framebuffer.
583 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
585 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
586 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
587 q
= (unsigned short *) (vc
->vc_origin
+
588 vc
->vc_size_row
* rows
);
589 step
= logo_lines
* cols
;
590 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
591 if (scr_readw(r
) != vc
->vc_video_erase_char
)
593 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
594 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
596 int i
= cols
< new_cols
? cols
: new_cols
;
597 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
599 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
600 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
605 /* We can scroll screen down */
607 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
608 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
613 if (vc
->vc_y
+ logo_lines
>= rows
)
614 lines
= rows
- vc
->vc_y
- 1;
618 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
621 scr_memsetw((unsigned short *) vc
->vc_origin
,
623 vc
->vc_size_row
* logo_lines
);
625 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
626 fbcon_clear_margins(vc
, 0);
631 q
= (unsigned short *) (vc
->vc_origin
+
634 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
635 vc
->vc_y
+= logo_lines
;
636 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
640 if (logo_lines
> vc
->vc_bottom
) {
641 logo_shown
= FBCON_LOGO_CANSHOW
;
643 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
644 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
645 logo_shown
= FBCON_LOGO_DRAW
;
646 vc
->vc_top
= logo_lines
;
651 #ifdef CONFIG_FB_TILEBLITTING
652 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
654 struct fbcon_ops
*ops
= info
->fbcon_par
;
656 ops
->p
= &fb_display
[vc
->vc_num
];
658 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
659 fbcon_set_tileops(vc
, info
);
661 fbcon_set_rotation(info
);
662 fbcon_set_bitops(ops
);
666 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
670 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
671 info
->tileops
->fb_get_tilemax(info
) < charcount
)
677 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
679 struct fbcon_ops
*ops
= info
->fbcon_par
;
681 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
682 ops
->p
= &fb_display
[vc
->vc_num
];
683 fbcon_set_rotation(info
);
684 fbcon_set_bitops(ops
);
687 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
692 #endif /* CONFIG_MISC_TILEBLITTING */
695 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
696 int unit
, int oldidx
)
698 struct fbcon_ops
*ops
= NULL
;
701 if (!try_module_get(info
->fbops
->owner
))
704 if (!err
&& info
->fbops
->fb_open
&&
705 info
->fbops
->fb_open(info
, 0))
709 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
715 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;
966 info
->fbcon_par
= ops
;
968 p
->con_rotate
= initial_rotation
;
969 if (p
->con_rotate
== -1)
970 p
->con_rotate
= info
->fbcon_rotate_hint
;
971 if (p
->con_rotate
== -1)
972 p
->con_rotate
= FB_ROTATE_UR
;
974 set_blitting_type(vc
, info
);
976 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
977 if (fbcon_softback_size
) {
981 kmalloc(fbcon_softback_size
,
984 fbcon_softback_size
= 0;
990 kfree((void *) softback_buf
);
996 softback_in
= softback_top
= softback_curr
=
1001 /* Setup default font */
1002 if (!p
->fontdata
&& !vc
->vc_font
.data
) {
1003 if (!fontname
[0] || !(font
= find_font(fontname
)))
1004 font
= get_default_font(info
->var
.xres
,
1006 info
->pixmap
.blit_x
,
1007 info
->pixmap
.blit_y
);
1008 vc
->vc_font
.width
= font
->width
;
1009 vc
->vc_font
.height
= font
->height
;
1010 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1011 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1013 p
->fontdata
= vc
->vc_font
.data
;
1016 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1017 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1018 cols
/= vc
->vc_font
.width
;
1019 rows
/= vc
->vc_font
.height
;
1020 vc_resize(vc
, cols
, rows
);
1022 DPRINTK("mode: %s\n", info
->fix
.id
);
1023 DPRINTK("visual: %d\n", info
->fix
.visual
);
1024 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1026 info
->var
.bits_per_pixel
);
1028 fbcon_add_cursor_timer(info
);
1029 fbcon_has_exited
= 0;
1030 return display_desc
;
1033 static void fbcon_init(struct vc_data
*vc
, int init
)
1035 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1036 struct fbcon_ops
*ops
;
1037 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1038 struct vc_data
*svc
= *default_mode
;
1039 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1040 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1043 if (info_idx
== -1 || info
== NULL
)
1048 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1049 (info
->fix
.type
== FB_TYPE_TEXT
))
1052 if (var_to_display(p
, &info
->var
, info
))
1055 if (!info
->fbcon_par
)
1056 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1058 /* If we are not the first console on this
1059 fb, copy the font from that console */
1060 t
= &fb_display
[fg_console
];
1063 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1065 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1067 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1068 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1069 p
->userfont
= t
->userfont
;
1072 REFCOUNT(p
->fontdata
)++;
1074 const struct font_desc
*font
= NULL
;
1076 if (!fontname
[0] || !(font
= find_font(fontname
)))
1077 font
= get_default_font(info
->var
.xres
,
1079 info
->pixmap
.blit_x
,
1080 info
->pixmap
.blit_y
);
1081 vc
->vc_font
.width
= font
->width
;
1082 vc
->vc_font
.height
= font
->height
;
1083 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1084 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1085 support more fonts */
1090 charcnt
= FNTCHARCNT(p
->fontdata
);
1092 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1093 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1094 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1095 if (charcnt
== 256) {
1096 vc
->vc_hi_font_mask
= 0;
1098 vc
->vc_hi_font_mask
= 0x100;
1099 if (vc
->vc_can_do_color
)
1100 vc
->vc_complement_mask
<<= 1;
1103 if (!*svc
->vc_uni_pagedir_loc
)
1104 con_set_default_unimap(svc
);
1105 if (!*vc
->vc_uni_pagedir_loc
)
1106 con_copy_unimap(vc
, svc
);
1108 ops
= info
->fbcon_par
;
1109 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1111 p
->con_rotate
= initial_rotation
;
1112 if (p
->con_rotate
== -1)
1113 p
->con_rotate
= info
->fbcon_rotate_hint
;
1114 if (p
->con_rotate
== -1)
1115 p
->con_rotate
= FB_ROTATE_UR
;
1117 set_blitting_type(vc
, info
);
1121 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1122 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1123 new_cols
/= vc
->vc_font
.width
;
1124 new_rows
/= vc
->vc_font
.height
;
1127 * We must always set the mode. The mode of the previous console
1128 * driver could be in the same resolution but we are using different
1129 * hardware so we have to initialize the hardware.
1131 * We need to do it in fbcon_init() to prevent screen corruption.
1133 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
1134 if (info
->fbops
->fb_set_par
&&
1135 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1136 ret
= info
->fbops
->fb_set_par(info
);
1139 printk(KERN_ERR
"fbcon_init: detected "
1140 "unhandled fb_set_par error, "
1141 "error code %d\n", ret
);
1144 ops
->flags
|= FBCON_FLAGS_INIT
;
1149 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1150 !(cap
& FBINFO_HWACCEL_DISABLED
))
1151 p
->scrollmode
= SCROLL_MOVE
;
1152 else /* default to something safe */
1153 p
->scrollmode
= SCROLL_REDRAW
;
1156 * ++guenther: console.c:vc_allocate() relies on initializing
1157 * vc_{cols,rows}, but we must not set those if we are only
1158 * resizing the console.
1161 vc
->vc_cols
= new_cols
;
1162 vc
->vc_rows
= new_rows
;
1164 vc_resize(vc
, new_cols
, new_rows
);
1167 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1169 if (vc
== svc
&& softback_buf
)
1170 fbcon_update_softback(vc
);
1172 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1173 ops
->rotate
= FB_ROTATE_UR
;
1174 set_blitting_type(vc
, info
);
1177 ops
->p
= &fb_display
[fg_console
];
1180 static void fbcon_free_font(struct display
*p
, bool freefont
)
1182 if (freefont
&& p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1183 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1188 static void set_vc_hi_font(struct vc_data
*vc
, bool set
);
1190 static void fbcon_deinit(struct vc_data
*vc
)
1192 struct display
*p
= &fb_display
[vc
->vc_num
];
1193 struct fb_info
*info
;
1194 struct fbcon_ops
*ops
;
1196 bool free_font
= true;
1198 idx
= con2fb_map
[vc
->vc_num
];
1203 info
= registered_fb
[idx
];
1208 if (info
->flags
& FBINFO_MISC_FIRMWARE
)
1210 ops
= info
->fbcon_par
;
1215 if (con_is_visible(vc
))
1216 fbcon_del_cursor_timer(info
);
1218 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1221 fbcon_free_font(p
, free_font
);
1223 vc
->vc_font
.data
= NULL
;
1225 if (vc
->vc_hi_font_mask
)
1226 set_vc_hi_font(vc
, false);
1228 if (!con_is_bound(&fb_con
))
1234 /* ====================================================================== */
1236 /* fbcon_XXX routines - interface used by the world
1238 * This system is now divided into two levels because of complications
1239 * caused by hardware scrolling. Top level functions:
1241 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1243 * handles y values in range [0, scr_height-1] that correspond to real
1244 * screen positions. y_wrap shift means that first line of bitmap may be
1245 * anywhere on this display. These functions convert lineoffsets to
1246 * bitmap offsets and deal with the wrap-around case by splitting blits.
1248 * fbcon_bmove_physical_8() -- These functions fast implementations
1249 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1250 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1254 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1255 * Implies should only really hardware scroll in rows. Only reason for
1256 * restriction is simplicity & efficiency at the moment.
1259 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1262 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1263 struct fbcon_ops
*ops
= info
->fbcon_par
;
1265 struct display
*p
= &fb_display
[vc
->vc_num
];
1268 if (fbcon_is_inactive(vc
, info
))
1271 if (!height
|| !width
)
1274 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1277 * If the font dimensions are not an integral of the display
1278 * dimensions then the ops->clear below won't end up clearing
1279 * the margins. Call clear_margins here in case the logo
1280 * bitmap stretched into the margin area.
1282 fbcon_clear_margins(vc
, 0);
1285 /* Split blits that cross physical y_wrap boundary */
1287 y_break
= p
->vrows
- p
->yscroll
;
1288 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1289 u_int b
= y_break
- sy
;
1290 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1291 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1294 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1297 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1298 int count
, int ypos
, int xpos
)
1300 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1301 struct display
*p
= &fb_display
[vc
->vc_num
];
1302 struct fbcon_ops
*ops
= info
->fbcon_par
;
1304 if (!fbcon_is_inactive(vc
, info
))
1305 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1306 get_color(vc
, info
, scr_readw(s
), 1),
1307 get_color(vc
, info
, scr_readw(s
), 0));
1310 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1314 scr_writew(c
, &chr
);
1315 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1318 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1320 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1321 struct fbcon_ops
*ops
= info
->fbcon_par
;
1323 if (!fbcon_is_inactive(vc
, info
))
1324 ops
->clear_margins(vc
, info
, margin_color
, bottom_only
);
1327 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1329 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1330 struct fbcon_ops
*ops
= info
->fbcon_par
;
1332 int c
= scr_readw((u16
*) vc
->vc_pos
);
1334 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1336 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1339 if (vc
->vc_cursor_type
& 0x10)
1340 fbcon_del_cursor_timer(info
);
1342 fbcon_add_cursor_timer(info
);
1344 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1345 if (mode
& CM_SOFTBACK
) {
1346 mode
&= ~CM_SOFTBACK
;
1350 fbcon_set_origin(vc
);
1354 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1355 get_color(vc
, info
, c
, 0));
1358 static int scrollback_phys_max
= 0;
1359 static int scrollback_max
= 0;
1360 static int scrollback_current
= 0;
1362 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1365 struct display
*p
, *t
;
1366 struct vc_data
**default_mode
, *vc
;
1367 struct vc_data
*svc
;
1368 struct fbcon_ops
*ops
= info
->fbcon_par
;
1369 int rows
, cols
, charcnt
= 256;
1371 p
= &fb_display
[unit
];
1373 if (var_to_display(p
, var
, info
))
1376 vc
= vc_cons
[unit
].d
;
1381 default_mode
= vc
->vc_display_fg
;
1382 svc
= *default_mode
;
1383 t
= &fb_display
[svc
->vc_num
];
1385 if (!vc
->vc_font
.data
) {
1386 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1387 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1388 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1389 p
->userfont
= t
->userfont
;
1391 REFCOUNT(p
->fontdata
)++;
1394 charcnt
= FNTCHARCNT(p
->fontdata
);
1396 var
->activate
= FB_ACTIVATE_NOW
;
1397 info
->var
.activate
= var
->activate
;
1398 var
->yoffset
= info
->var
.yoffset
;
1399 var
->xoffset
= info
->var
.xoffset
;
1400 fb_set_var(info
, var
);
1401 ops
->var
= info
->var
;
1402 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1403 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1404 if (charcnt
== 256) {
1405 vc
->vc_hi_font_mask
= 0;
1407 vc
->vc_hi_font_mask
= 0x100;
1408 if (vc
->vc_can_do_color
)
1409 vc
->vc_complement_mask
<<= 1;
1412 if (!*svc
->vc_uni_pagedir_loc
)
1413 con_set_default_unimap(svc
);
1414 if (!*vc
->vc_uni_pagedir_loc
)
1415 con_copy_unimap(vc
, svc
);
1417 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1418 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1419 cols
/= vc
->vc_font
.width
;
1420 rows
/= vc
->vc_font
.height
;
1421 vc_resize(vc
, cols
, rows
);
1423 if (con_is_visible(vc
)) {
1426 fbcon_update_softback(vc
);
1430 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1432 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1433 struct fbcon_ops
*ops
= info
->fbcon_par
;
1434 struct display
*p
= &fb_display
[vc
->vc_num
];
1436 p
->yscroll
+= count
;
1437 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1438 p
->yscroll
-= p
->vrows
;
1439 ops
->var
.xoffset
= 0;
1440 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1441 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1442 ops
->update_start(info
);
1443 scrollback_max
+= count
;
1444 if (scrollback_max
> scrollback_phys_max
)
1445 scrollback_max
= scrollback_phys_max
;
1446 scrollback_current
= 0;
1449 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1451 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1452 struct fbcon_ops
*ops
= info
->fbcon_par
;
1453 struct display
*p
= &fb_display
[vc
->vc_num
];
1455 p
->yscroll
-= count
;
1456 if (p
->yscroll
< 0) /* Deal with wrap */
1457 p
->yscroll
+= p
->vrows
;
1458 ops
->var
.xoffset
= 0;
1459 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1460 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1461 ops
->update_start(info
);
1462 scrollback_max
-= count
;
1463 if (scrollback_max
< 0)
1465 scrollback_current
= 0;
1468 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1470 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1471 struct display
*p
= &fb_display
[vc
->vc_num
];
1472 struct fbcon_ops
*ops
= info
->fbcon_par
;
1474 p
->yscroll
+= count
;
1475 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1476 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1477 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1478 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1481 ops
->var
.xoffset
= 0;
1482 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1483 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1484 ops
->update_start(info
);
1485 fbcon_clear_margins(vc
, 1);
1486 scrollback_max
+= count
;
1487 if (scrollback_max
> scrollback_phys_max
)
1488 scrollback_max
= scrollback_phys_max
;
1489 scrollback_current
= 0;
1492 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1494 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1495 struct fbcon_ops
*ops
= info
->fbcon_par
;
1496 struct display
*p
= &fb_display
[vc
->vc_num
];
1498 p
->yscroll
+= count
;
1500 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1501 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1502 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1505 ops
->var
.xoffset
= 0;
1506 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1507 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1508 ops
->update_start(info
);
1509 fbcon_clear_margins(vc
, 1);
1510 scrollback_max
+= count
;
1511 if (scrollback_max
> scrollback_phys_max
)
1512 scrollback_max
= scrollback_phys_max
;
1513 scrollback_current
= 0;
1516 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1518 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1519 struct display
*p
= &fb_display
[vc
->vc_num
];
1520 struct fbcon_ops
*ops
= info
->fbcon_par
;
1522 p
->yscroll
-= count
;
1523 if (p
->yscroll
< 0) {
1524 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1525 0, vc
->vc_rows
, vc
->vc_cols
);
1526 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1529 ops
->var
.xoffset
= 0;
1530 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1531 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1532 ops
->update_start(info
);
1533 fbcon_clear_margins(vc
, 1);
1534 scrollback_max
-= count
;
1535 if (scrollback_max
< 0)
1537 scrollback_current
= 0;
1540 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1542 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1543 struct fbcon_ops
*ops
= info
->fbcon_par
;
1544 struct display
*p
= &fb_display
[vc
->vc_num
];
1546 p
->yscroll
-= count
;
1548 if (p
->yscroll
< 0) {
1549 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1550 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1553 ops
->var
.xoffset
= 0;
1554 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1555 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1556 ops
->update_start(info
);
1557 fbcon_clear_margins(vc
, 1);
1558 scrollback_max
-= count
;
1559 if (scrollback_max
< 0)
1561 scrollback_current
= 0;
1564 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1567 int count
= vc
->vc_rows
;
1568 unsigned short *d
, *s
;
1572 d
= (u16
*) softback_curr
;
1573 if (d
== (u16
*) softback_in
)
1574 d
= (u16
*) vc
->vc_origin
;
1575 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1576 softback_lines
-= delta
;
1578 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1579 n
+= softback_end
- softback_buf
;
1580 if (n
< softback_top
) {
1582 (softback_top
- n
) / vc
->vc_size_row
;
1585 } else if (softback_curr
>= softback_top
1586 && n
< softback_top
) {
1588 (softback_top
- n
) / vc
->vc_size_row
;
1592 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1593 n
+= softback_buf
- softback_end
;
1594 if (n
> softback_in
) {
1598 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1603 if (n
== softback_curr
)
1606 s
= (u16
*) softback_curr
;
1607 if (s
== (u16
*) softback_in
)
1608 s
= (u16
*) vc
->vc_origin
;
1610 unsigned short *start
;
1614 unsigned short attr
= 1;
1617 le
= advance_row(s
, 1);
1620 if (attr
!= (c
& 0xff00)) {
1623 fbcon_putcs(vc
, start
, s
- start
,
1629 if (c
== scr_readw(d
)) {
1631 fbcon_putcs(vc
, start
, s
- start
,
1644 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1646 if (d
== (u16
*) softback_end
)
1647 d
= (u16
*) softback_buf
;
1648 if (d
== (u16
*) softback_in
)
1649 d
= (u16
*) vc
->vc_origin
;
1650 if (s
== (u16
*) softback_end
)
1651 s
= (u16
*) softback_buf
;
1652 if (s
== (u16
*) softback_in
)
1653 s
= (u16
*) vc
->vc_origin
;
1657 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1658 int line
, int count
, int dy
)
1660 unsigned short *s
= (unsigned short *)
1661 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1664 unsigned short *start
= s
;
1665 unsigned short *le
= advance_row(s
, 1);
1668 unsigned short attr
= 1;
1672 if (attr
!= (c
& 0xff00)) {
1675 fbcon_putcs(vc
, start
, s
- start
,
1681 console_conditional_schedule();
1685 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1686 console_conditional_schedule();
1691 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1692 struct display
*p
, int line
, int count
, int ycount
)
1694 int offset
= ycount
* vc
->vc_cols
;
1695 unsigned short *d
= (unsigned short *)
1696 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1697 unsigned short *s
= d
+ offset
;
1698 struct fbcon_ops
*ops
= info
->fbcon_par
;
1701 unsigned short *start
= s
;
1702 unsigned short *le
= advance_row(s
, 1);
1709 if (c
== scr_readw(d
)) {
1711 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1712 line
, x
, 1, s
-start
);
1722 console_conditional_schedule();
1727 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1729 console_conditional_schedule();
1734 /* NOTE: We subtract two lines from these pointers */
1735 s
-= vc
->vc_size_row
;
1736 d
-= vc
->vc_size_row
;
1741 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1742 int line
, int count
, int offset
)
1744 unsigned short *d
= (unsigned short *)
1745 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1746 unsigned short *s
= d
+ offset
;
1749 unsigned short *start
= s
;
1750 unsigned short *le
= advance_row(s
, 1);
1753 unsigned short attr
= 1;
1757 if (attr
!= (c
& 0xff00)) {
1760 fbcon_putcs(vc
, start
, s
- start
,
1766 if (c
== scr_readw(d
)) {
1768 fbcon_putcs(vc
, start
, s
- start
,
1778 console_conditional_schedule();
1783 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1784 console_conditional_schedule();
1789 /* NOTE: We subtract two lines from these pointers */
1790 s
-= vc
->vc_size_row
;
1791 d
-= vc
->vc_size_row
;
1796 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1801 if (vc
->vc_num
!= fg_console
)
1803 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1806 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1808 p
= advance_row(p
, 1);
1809 softback_in
+= vc
->vc_size_row
;
1810 if (softback_in
== softback_end
)
1811 softback_in
= softback_buf
;
1812 if (softback_in
== softback_top
) {
1813 softback_top
+= vc
->vc_size_row
;
1814 if (softback_top
== softback_end
)
1815 softback_top
= softback_buf
;
1818 softback_curr
= softback_in
;
1821 static bool fbcon_scroll(struct vc_data
*vc
, unsigned int t
, unsigned int b
,
1822 enum con_scroll dir
, unsigned int count
)
1824 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1825 struct display
*p
= &fb_display
[vc
->vc_num
];
1826 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1828 if (fbcon_is_inactive(vc
, info
))
1831 fbcon_cursor(vc
, CM_ERASE
);
1834 * ++Geert: Only use ywrap/ypan if the console is in text mode
1835 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1836 * whole screen (prevents flicker).
1841 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1842 count
= vc
->vc_rows
;
1844 fbcon_softback_note(vc
, t
, count
);
1845 if (logo_shown
>= 0)
1847 switch (p
->scrollmode
) {
1849 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1851 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1852 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1855 vc
->vc_video_erase_char
,
1856 vc
->vc_size_row
* count
);
1860 case SCROLL_WRAP_MOVE
:
1861 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1863 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1865 ywrap_up(vc
, count
);
1866 if (vc
->vc_rows
- b
> 0)
1867 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1870 } else if (info
->flags
& FBINFO_READS_FAST
)
1871 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1872 b
- t
- count
, vc
->vc_cols
);
1875 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1878 case SCROLL_PAN_REDRAW
:
1879 if ((p
->yscroll
+ count
<=
1880 2 * (p
->vrows
- vc
->vc_rows
))
1881 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1884 3 * vc
->vc_rows
>> 2)))) {
1886 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1887 ypan_up_redraw(vc
, t
, count
);
1888 if (vc
->vc_rows
- b
> 0)
1889 fbcon_redraw_move(vc
, p
, b
,
1890 vc
->vc_rows
- b
, b
);
1892 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1893 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1896 case SCROLL_PAN_MOVE
:
1897 if ((p
->yscroll
+ count
<=
1898 2 * (p
->vrows
- vc
->vc_rows
))
1899 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1902 3 * vc
->vc_rows
>> 2)))) {
1904 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1907 if (vc
->vc_rows
- b
> 0)
1908 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1911 } else if (info
->flags
& FBINFO_READS_FAST
)
1912 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1913 b
- t
- count
, vc
->vc_cols
);
1916 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1921 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1922 count
* vc
->vc_cols
);
1923 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1924 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1927 vc
->vc_video_erase_char
,
1928 vc
->vc_size_row
* count
);
1934 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1935 count
= vc
->vc_rows
;
1936 if (logo_shown
>= 0)
1938 switch (p
->scrollmode
) {
1940 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1942 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1943 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1946 vc
->vc_video_erase_char
,
1947 vc
->vc_size_row
* count
);
1951 case SCROLL_WRAP_MOVE
:
1952 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1953 if (vc
->vc_rows
- b
> 0)
1954 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1957 ywrap_down(vc
, count
);
1959 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1961 } else if (info
->flags
& FBINFO_READS_FAST
)
1962 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1963 b
- t
- count
, vc
->vc_cols
);
1966 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1969 case SCROLL_PAN_MOVE
:
1970 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1971 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1974 3 * vc
->vc_rows
>> 2)))) {
1975 if (vc
->vc_rows
- b
> 0)
1976 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1979 ypan_down(vc
, count
);
1981 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1983 } else if (info
->flags
& FBINFO_READS_FAST
)
1984 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1985 b
- t
- count
, vc
->vc_cols
);
1988 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1991 case SCROLL_PAN_REDRAW
:
1992 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1993 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1996 3 * vc
->vc_rows
>> 2)))) {
1997 if (vc
->vc_rows
- b
> 0)
1998 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
2000 ypan_down_redraw(vc
, t
, count
);
2002 fbcon_redraw_move(vc
, p
, count
, t
, 0);
2004 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
2005 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2010 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
2011 -count
* vc
->vc_cols
);
2012 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2013 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2016 vc
->vc_video_erase_char
,
2017 vc
->vc_size_row
* count
);
2025 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2026 int height
, int width
)
2028 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2029 struct display
*p
= &fb_display
[vc
->vc_num
];
2031 if (fbcon_is_inactive(vc
, info
))
2034 if (!width
|| !height
)
2037 /* Split blits that cross physical y_wrap case.
2038 * Pathological case involves 4 blits, better to use recursive
2039 * code rather than unrolled case
2041 * Recursive invocations don't need to erase the cursor over and
2042 * over again, so we use fbcon_bmove_rec()
2044 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2045 p
->vrows
- p
->yscroll
);
2048 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2049 int dy
, int dx
, int height
, int width
, u_int y_break
)
2051 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2052 struct fbcon_ops
*ops
= info
->fbcon_par
;
2055 if (sy
< y_break
&& sy
+ height
> y_break
) {
2057 if (dy
< sy
) { /* Avoid trashing self */
2058 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2060 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2061 height
- b
, width
, y_break
);
2063 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2064 height
- b
, width
, y_break
);
2065 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2071 if (dy
< y_break
&& dy
+ height
> y_break
) {
2073 if (dy
< sy
) { /* Avoid trashing self */
2074 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2076 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2077 height
- b
, width
, y_break
);
2079 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2080 height
- b
, width
, y_break
);
2081 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2086 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2090 static void updatescrollmode(struct display
*p
,
2091 struct fb_info
*info
,
2094 struct fbcon_ops
*ops
= info
->fbcon_par
;
2095 int fh
= vc
->vc_font
.height
;
2096 int cap
= info
->flags
;
2098 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2099 info
->fix
.xpanstep
);
2100 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2101 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2102 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2103 info
->var
.xres_virtual
);
2104 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2105 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2106 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2107 divides(ywrap
, vc
->vc_font
.height
) &&
2108 divides(vc
->vc_font
.height
, vyres
) &&
2109 divides(vc
->vc_font
.height
, yres
);
2110 int reading_fast
= cap
& FBINFO_READS_FAST
;
2111 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2112 !(cap
& FBINFO_HWACCEL_DISABLED
);
2113 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2114 !(cap
& FBINFO_HWACCEL_DISABLED
);
2116 p
->vrows
= vyres
/fh
;
2117 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2118 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2119 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2122 if (good_wrap
|| good_pan
) {
2123 if (reading_fast
|| fast_copyarea
)
2124 p
->scrollmode
= good_wrap
?
2125 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2127 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2130 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2131 p
->scrollmode
= SCROLL_MOVE
;
2133 p
->scrollmode
= SCROLL_REDRAW
;
2137 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2138 unsigned int height
, unsigned int user
)
2140 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2141 struct fbcon_ops
*ops
= info
->fbcon_par
;
2142 struct display
*p
= &fb_display
[vc
->vc_num
];
2143 struct fb_var_screeninfo var
= info
->var
;
2144 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2146 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2147 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2148 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2149 vc
->vc_font
.height
);
2150 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2152 var
.xres
= virt_w
* virt_fw
;
2153 var
.yres
= virt_h
* virt_fh
;
2154 x_diff
= info
->var
.xres
- var
.xres
;
2155 y_diff
= info
->var
.yres
- var
.yres
;
2156 if (x_diff
< 0 || x_diff
> virt_fw
||
2157 y_diff
< 0 || y_diff
> virt_fh
) {
2158 const struct fb_videomode
*mode
;
2160 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2161 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2164 display_to_var(&var
, p
);
2165 fb_videomode_to_var(&var
, mode
);
2167 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2170 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2171 if (con_is_visible(vc
)) {
2172 var
.activate
= FB_ACTIVATE_NOW
|
2174 fb_set_var(info
, &var
);
2176 var_to_display(p
, &info
->var
, info
);
2177 ops
->var
= info
->var
;
2179 updatescrollmode(p
, info
, vc
);
2183 static int fbcon_switch(struct vc_data
*vc
)
2185 struct fb_info
*info
, *old_info
= NULL
;
2186 struct fbcon_ops
*ops
;
2187 struct display
*p
= &fb_display
[vc
->vc_num
];
2188 struct fb_var_screeninfo var
;
2189 int i
, ret
, prev_console
, charcnt
= 256;
2191 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2192 ops
= info
->fbcon_par
;
2196 fbcon_set_origin(vc
);
2197 softback_top
= softback_curr
= softback_in
= softback_buf
;
2199 fbcon_update_softback(vc
);
2202 if (logo_shown
>= 0) {
2203 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2205 if (conp2
->vc_top
== logo_lines
2206 && conp2
->vc_bottom
== conp2
->vc_rows
)
2208 logo_shown
= FBCON_LOGO_CANSHOW
;
2211 prev_console
= ops
->currcon
;
2212 if (prev_console
!= -1)
2213 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2215 * FIXME: If we have multiple fbdev's loaded, we need to
2216 * update all info->currcon. Perhaps, we can place this
2217 * in a centralized structure, but this might break some
2220 * info->currcon = vc->vc_num;
2222 for (i
= 0; i
< FB_MAX
; i
++) {
2223 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2224 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2226 o
->currcon
= vc
->vc_num
;
2229 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2230 display_to_var(&var
, p
);
2231 var
.activate
= FB_ACTIVATE_NOW
;
2234 * make sure we don't unnecessarily trip the memcmp()
2237 info
->var
.activate
= var
.activate
;
2238 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2239 fb_set_var(info
, &var
);
2240 ops
->var
= info
->var
;
2242 if (old_info
!= NULL
&& (old_info
!= info
||
2243 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2244 if (info
->fbops
->fb_set_par
) {
2245 ret
= info
->fbops
->fb_set_par(info
);
2248 printk(KERN_ERR
"fbcon_switch: detected "
2249 "unhandled fb_set_par error, "
2250 "error code %d\n", ret
);
2253 if (old_info
!= info
)
2254 fbcon_del_cursor_timer(old_info
);
2257 if (fbcon_is_inactive(vc
, info
) ||
2258 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2259 fbcon_del_cursor_timer(info
);
2261 fbcon_add_cursor_timer(info
);
2263 set_blitting_type(vc
, info
);
2264 ops
->cursor_reset
= 1;
2266 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2267 ops
->rotate
= FB_ROTATE_UR
;
2268 set_blitting_type(vc
, info
);
2271 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2272 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2275 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2278 vc
->vc_complement_mask
<<= 1;
2280 updatescrollmode(p
, info
, vc
);
2282 switch (p
->scrollmode
) {
2283 case SCROLL_WRAP_MOVE
:
2284 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2286 case SCROLL_PAN_MOVE
:
2287 case SCROLL_PAN_REDRAW
:
2288 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2289 if (scrollback_phys_max
< 0)
2290 scrollback_phys_max
= 0;
2293 scrollback_phys_max
= 0;
2298 scrollback_current
= 0;
2300 if (!fbcon_is_inactive(vc
, info
)) {
2301 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2302 ops
->update_start(info
);
2305 fbcon_set_palette(vc
, color_table
);
2306 fbcon_clear_margins(vc
, 0);
2308 if (logo_shown
== FBCON_LOGO_DRAW
) {
2310 logo_shown
= fg_console
;
2311 /* This is protected above by initmem_freed */
2312 fb_show_logo(info
, ops
->rotate
);
2314 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2315 vc
->vc_size_row
* (vc
->vc_bottom
-
2322 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2325 struct fb_event event
;
2328 unsigned short charmask
= vc
->vc_hi_font_mask
?
2330 unsigned short oldc
;
2332 oldc
= vc
->vc_video_erase_char
;
2333 vc
->vc_video_erase_char
&= charmask
;
2334 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2335 vc
->vc_video_erase_char
= oldc
;
2339 if (!lock_fb_info(info
))
2342 event
.data
= &blank
;
2343 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2344 unlock_fb_info(info
);
2347 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2349 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2350 struct fbcon_ops
*ops
= info
->fbcon_par
;
2353 struct fb_var_screeninfo var
= info
->var
;
2358 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2359 fb_set_var(info
, &var
);
2361 ops
->var
= info
->var
;
2365 if (!fbcon_is_inactive(vc
, info
)) {
2366 if (ops
->blank_state
!= blank
) {
2367 ops
->blank_state
= blank
;
2368 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2369 ops
->cursor_flash
= (!blank
);
2371 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2372 if (fb_blank(info
, blank
))
2373 fbcon_generic_blank(vc
, info
, blank
);
2380 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2381 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2382 fbcon_del_cursor_timer(info
);
2384 fbcon_add_cursor_timer(info
);
2389 static int fbcon_debug_enter(struct vc_data
*vc
)
2391 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2392 struct fbcon_ops
*ops
= info
->fbcon_par
;
2394 ops
->save_graphics
= ops
->graphics
;
2396 if (info
->fbops
->fb_debug_enter
)
2397 info
->fbops
->fb_debug_enter(info
);
2398 fbcon_set_palette(vc
, color_table
);
2402 static int fbcon_debug_leave(struct vc_data
*vc
)
2404 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2405 struct fbcon_ops
*ops
= info
->fbcon_par
;
2407 ops
->graphics
= ops
->save_graphics
;
2408 if (info
->fbops
->fb_debug_leave
)
2409 info
->fbops
->fb_debug_leave(info
);
2413 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2415 u8
*fontdata
= vc
->vc_font
.data
;
2416 u8
*data
= font
->data
;
2419 font
->width
= vc
->vc_font
.width
;
2420 font
->height
= vc
->vc_font
.height
;
2421 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2425 if (font
->width
<= 8) {
2426 j
= vc
->vc_font
.height
;
2427 for (i
= 0; i
< font
->charcount
; i
++) {
2428 memcpy(data
, fontdata
, j
);
2429 memset(data
+ j
, 0, 32 - j
);
2433 } else if (font
->width
<= 16) {
2434 j
= vc
->vc_font
.height
* 2;
2435 for (i
= 0; i
< font
->charcount
; i
++) {
2436 memcpy(data
, fontdata
, j
);
2437 memset(data
+ j
, 0, 64 - j
);
2441 } else if (font
->width
<= 24) {
2442 for (i
= 0; i
< font
->charcount
; i
++) {
2443 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2444 *data
++ = fontdata
[0];
2445 *data
++ = fontdata
[1];
2446 *data
++ = fontdata
[2];
2447 fontdata
+= sizeof(u32
);
2449 memset(data
, 0, 3 * (32 - j
));
2450 data
+= 3 * (32 - j
);
2453 j
= vc
->vc_font
.height
* 4;
2454 for (i
= 0; i
< font
->charcount
; i
++) {
2455 memcpy(data
, fontdata
, j
);
2456 memset(data
+ j
, 0, 128 - j
);
2464 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2465 static void set_vc_hi_font(struct vc_data
*vc
, bool set
)
2468 vc
->vc_hi_font_mask
= 0;
2469 if (vc
->vc_can_do_color
) {
2470 vc
->vc_complement_mask
>>= 1;
2471 vc
->vc_s_complement_mask
>>= 1;
2474 /* ++Edmund: reorder the attribute bits */
2475 if (vc
->vc_can_do_color
) {
2476 unsigned short *cp
=
2477 (unsigned short *) vc
->vc_origin
;
2478 int count
= vc
->vc_screenbuf_size
/ 2;
2480 for (; count
> 0; count
--, cp
++) {
2482 scr_writew(((c
& 0xfe00) >> 1) |
2485 c
= vc
->vc_video_erase_char
;
2486 vc
->vc_video_erase_char
=
2487 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2491 vc
->vc_hi_font_mask
= 0x100;
2492 if (vc
->vc_can_do_color
) {
2493 vc
->vc_complement_mask
<<= 1;
2494 vc
->vc_s_complement_mask
<<= 1;
2497 /* ++Edmund: reorder the attribute bits */
2499 unsigned short *cp
=
2500 (unsigned short *) vc
->vc_origin
;
2501 int count
= vc
->vc_screenbuf_size
/ 2;
2503 for (; count
> 0; count
--, cp
++) {
2504 unsigned short newc
;
2506 if (vc
->vc_can_do_color
)
2508 ((c
& 0xff00) << 1) | (c
&
2512 scr_writew(newc
, cp
);
2514 c
= vc
->vc_video_erase_char
;
2515 if (vc
->vc_can_do_color
) {
2516 vc
->vc_video_erase_char
=
2517 ((c
& 0xff00) << 1) | (c
& 0xff);
2520 vc
->vc_video_erase_char
= c
& ~0x100;
2525 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2526 const u8
* data
, int userfont
)
2528 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2529 struct fbcon_ops
*ops
= info
->fbcon_par
;
2530 struct display
*p
= &fb_display
[vc
->vc_num
];
2533 char *old_data
= NULL
;
2535 if (con_is_visible(vc
) && softback_lines
)
2536 fbcon_set_origin(vc
);
2538 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2540 old_data
= vc
->vc_font
.data
;
2542 cnt
= FNTCHARCNT(data
);
2545 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2546 if ((p
->userfont
= userfont
))
2548 vc
->vc_font
.width
= w
;
2549 vc
->vc_font
.height
= h
;
2550 if (vc
->vc_hi_font_mask
&& cnt
== 256)
2551 set_vc_hi_font(vc
, false);
2552 else if (!vc
->vc_hi_font_mask
&& cnt
== 512)
2553 set_vc_hi_font(vc
, true);
2558 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2559 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2562 vc_resize(vc
, cols
, rows
);
2563 if (con_is_visible(vc
) && softback_buf
)
2564 fbcon_update_softback(vc
);
2565 } else if (con_is_visible(vc
)
2566 && vc
->vc_mode
== KD_TEXT
) {
2567 fbcon_clear_margins(vc
, 0);
2571 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2572 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2576 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2578 struct display
*od
= &fb_display
[con
];
2579 struct console_font
*f
= &vc
->vc_font
;
2581 if (od
->fontdata
== f
->data
)
2582 return 0; /* already the same font... */
2583 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2587 * User asked to set font; we are guaranteed that
2588 * a) width and height are in range 1..32
2589 * b) charcount does not exceed 512
2590 * but lets not assume that, since someone might someday want to use larger
2591 * fonts. And charcount of 512 is small for unicode support.
2593 * However, user space gives the font in 32 rows , regardless of
2594 * actual font height. So a new API is needed if support for larger fonts
2595 * is ever implemented.
2598 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2600 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2601 unsigned charcount
= font
->charcount
;
2602 int w
= font
->width
;
2603 int h
= font
->height
;
2606 u8
*new_data
, *data
= font
->data
;
2607 int pitch
= (font
->width
+7) >> 3;
2609 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2610 * If not this check should be changed to charcount < 256 */
2611 if (charcount
!= 256 && charcount
!= 512)
2614 /* Make sure drawing engine can handle the font */
2615 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2616 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2619 /* Make sure driver can handle the font length */
2620 if (fbcon_invalid_charcount(info
, charcount
))
2623 size
= h
* pitch
* charcount
;
2625 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2630 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2631 FNTSIZE(new_data
) = size
;
2632 FNTCHARCNT(new_data
) = charcount
;
2633 REFCOUNT(new_data
) = 0; /* usage counter */
2634 for (i
=0; i
< charcount
; i
++) {
2635 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2638 /* Since linux has a nice crc32 function use it for counting font
2640 csum
= crc32(0, new_data
, size
);
2642 FNTSUM(new_data
) = csum
;
2643 /* Check if the same font is on some other console already */
2644 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2645 struct vc_data
*tmp
= vc_cons
[i
].d
;
2647 if (fb_display
[i
].userfont
&&
2648 fb_display
[i
].fontdata
&&
2649 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2650 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2651 tmp
->vc_font
.width
== w
&&
2652 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2653 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2654 new_data
= (u8
*)fb_display
[i
].fontdata
;
2658 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2661 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2663 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2664 const struct font_desc
*f
;
2667 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2668 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2669 else if (!(f
= find_font(name
)))
2672 font
->width
= f
->width
;
2673 font
->height
= f
->height
;
2674 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2677 static u16 palette_red
[16];
2678 static u16 palette_green
[16];
2679 static u16 palette_blue
[16];
2681 static struct fb_cmap palette_cmap
= {
2682 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2685 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
)
2687 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2691 if (fbcon_is_inactive(vc
, info
))
2694 if (!con_is_visible(vc
))
2697 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2699 for (i
= j
= 0; i
< 16; i
++) {
2701 val
= vc
->vc_palette
[j
++];
2702 palette_red
[k
] = (val
<< 8) | val
;
2703 val
= vc
->vc_palette
[j
++];
2704 palette_green
[k
] = (val
<< 8) | val
;
2705 val
= vc
->vc_palette
[j
++];
2706 palette_blue
[k
] = (val
<< 8) | val
;
2708 palette_cmap
.len
= 16;
2709 palette_cmap
.start
= 0;
2711 * If framebuffer is capable of less than 16 colors,
2712 * use default palette of fbcon.
2715 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2717 fb_set_cmap(&palette_cmap
, info
);
2720 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2725 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2726 return (u16
*) (vc
->vc_origin
+ offset
);
2727 line
= offset
/ vc
->vc_size_row
;
2728 if (line
>= softback_lines
)
2729 return (u16
*) (vc
->vc_origin
+ offset
-
2730 softback_lines
* vc
->vc_size_row
);
2731 p
= softback_curr
+ offset
;
2732 if (p
>= softback_end
)
2733 p
+= softback_buf
- softback_end
;
2737 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2743 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2744 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2746 x
= offset
% vc
->vc_cols
;
2747 y
= offset
/ vc
->vc_cols
;
2748 if (vc
->vc_num
== fg_console
)
2749 y
+= softback_lines
;
2750 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2751 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2752 unsigned long offset
= pos
- softback_curr
;
2754 if (pos
< softback_curr
)
2755 offset
+= softback_end
- softback_buf
;
2757 x
= offset
% vc
->vc_cols
;
2758 y
= offset
/ vc
->vc_cols
;
2759 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2760 if (ret
== softback_end
)
2762 if (ret
== softback_in
)
2763 ret
= vc
->vc_origin
;
2765 /* Should not happen */
2767 ret
= vc
->vc_origin
;
2776 /* As we might be inside of softback, we may work with non-contiguous buffer,
2777 that's why we have to use a separate routine. */
2778 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2781 u16 a
= scr_readw(p
);
2782 if (!vc
->vc_can_do_color
)
2784 else if (vc
->vc_hi_font_mask
== 0x100)
2785 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2786 (((a
) & 0x0e00) << 4);
2788 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2789 (((a
) & 0x0700) << 4);
2791 if (p
== (u16
*) softback_end
)
2792 p
= (u16
*) softback_buf
;
2793 if (p
== (u16
*) softback_in
)
2794 p
= (u16
*) vc
->vc_origin
;
2798 static void fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2800 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2801 struct fbcon_ops
*ops
= info
->fbcon_par
;
2802 struct display
*disp
= &fb_display
[fg_console
];
2803 int offset
, limit
, scrollback_old
;
2806 if (vc
->vc_num
!= fg_console
)
2808 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2810 if (logo_shown
>= 0) {
2811 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2813 if (conp2
->vc_top
== logo_lines
2814 && conp2
->vc_bottom
== conp2
->vc_rows
)
2816 if (logo_shown
== vc
->vc_num
) {
2822 logo_lines
* vc
->vc_size_row
;
2823 for (i
= 0; i
< logo_lines
; i
++) {
2824 if (p
== softback_top
)
2826 if (p
== softback_buf
)
2828 p
-= vc
->vc_size_row
;
2829 q
-= vc
->vc_size_row
;
2830 scr_memcpyw((u16
*) q
, (u16
*) p
,
2833 softback_in
= softback_curr
= p
;
2834 update_region(vc
, vc
->vc_origin
,
2835 logo_lines
* vc
->vc_cols
);
2837 logo_shown
= FBCON_LOGO_CANSHOW
;
2839 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2840 fbcon_redraw_softback(vc
, disp
, lines
);
2841 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2845 if (!scrollback_phys_max
)
2848 scrollback_old
= scrollback_current
;
2849 scrollback_current
-= lines
;
2850 if (scrollback_current
< 0)
2851 scrollback_current
= 0;
2852 else if (scrollback_current
> scrollback_max
)
2853 scrollback_current
= scrollback_max
;
2854 if (scrollback_current
== scrollback_old
)
2857 if (fbcon_is_inactive(vc
, info
))
2860 fbcon_cursor(vc
, CM_ERASE
);
2862 offset
= disp
->yscroll
- scrollback_current
;
2863 limit
= disp
->vrows
;
2864 switch (disp
->scrollmode
) {
2865 case SCROLL_WRAP_MOVE
:
2866 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2868 case SCROLL_PAN_MOVE
:
2869 case SCROLL_PAN_REDRAW
:
2870 limit
-= vc
->vc_rows
;
2871 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2876 else if (offset
>= limit
)
2879 ops
->var
.xoffset
= 0;
2880 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2881 ops
->update_start(info
);
2883 if (!scrollback_current
)
2884 fbcon_cursor(vc
, CM_DRAW
);
2887 static int fbcon_set_origin(struct vc_data
*vc
)
2890 fbcon_scrolldelta(vc
, softback_lines
);
2894 static void fbcon_suspended(struct fb_info
*info
)
2896 struct vc_data
*vc
= NULL
;
2897 struct fbcon_ops
*ops
= info
->fbcon_par
;
2899 if (!ops
|| ops
->currcon
< 0)
2901 vc
= vc_cons
[ops
->currcon
].d
;
2903 /* Clear cursor, restore saved data */
2904 fbcon_cursor(vc
, CM_ERASE
);
2907 static void fbcon_resumed(struct fb_info
*info
)
2910 struct fbcon_ops
*ops
= info
->fbcon_par
;
2912 if (!ops
|| ops
->currcon
< 0)
2914 vc
= vc_cons
[ops
->currcon
].d
;
2919 static void fbcon_modechanged(struct fb_info
*info
)
2921 struct fbcon_ops
*ops
= info
->fbcon_par
;
2926 if (!ops
|| ops
->currcon
< 0)
2928 vc
= vc_cons
[ops
->currcon
].d
;
2929 if (vc
->vc_mode
!= KD_TEXT
||
2930 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2933 p
= &fb_display
[vc
->vc_num
];
2934 set_blitting_type(vc
, info
);
2936 if (con_is_visible(vc
)) {
2937 var_to_display(p
, &info
->var
, info
);
2938 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2939 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2940 cols
/= vc
->vc_font
.width
;
2941 rows
/= vc
->vc_font
.height
;
2942 vc_resize(vc
, cols
, rows
);
2943 updatescrollmode(p
, info
, vc
);
2945 scrollback_current
= 0;
2947 if (!fbcon_is_inactive(vc
, info
)) {
2948 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2949 ops
->update_start(info
);
2952 fbcon_set_palette(vc
, color_table
);
2955 fbcon_update_softback(vc
);
2959 static void fbcon_set_all_vcs(struct fb_info
*info
)
2961 struct fbcon_ops
*ops
= info
->fbcon_par
;
2964 int i
, rows
, cols
, fg
= -1;
2966 if (!ops
|| ops
->currcon
< 0)
2969 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2971 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2972 registered_fb
[con2fb_map
[i
]] != info
)
2975 if (con_is_visible(vc
)) {
2980 p
= &fb_display
[vc
->vc_num
];
2981 set_blitting_type(vc
, info
);
2982 var_to_display(p
, &info
->var
, info
);
2983 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2984 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2985 cols
/= vc
->vc_font
.width
;
2986 rows
/= vc
->vc_font
.height
;
2987 vc_resize(vc
, cols
, rows
);
2991 fbcon_modechanged(info
);
2994 static int fbcon_mode_deleted(struct fb_info
*info
,
2995 struct fb_videomode
*mode
)
2997 struct fb_info
*fb_info
;
2999 int i
, j
, found
= 0;
3001 /* before deletion, ensure that mode is not in use */
3002 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3006 fb_info
= registered_fb
[j
];
3007 if (fb_info
!= info
)
3012 if (fb_mode_is_equal(p
->mode
, mode
)) {
3020 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3021 static int fbcon_unbind(void)
3025 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3029 fbcon_has_console_bind
= 0;
3034 static inline int fbcon_unbind(void)
3038 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3040 /* called with console_lock held */
3041 static int fbcon_fb_unbind(int idx
)
3043 int i
, new_idx
= -1, ret
= 0;
3045 if (!fbcon_has_console_bind
)
3048 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3049 if (con2fb_map
[i
] != idx
&&
3050 con2fb_map
[i
] != -1) {
3056 if (new_idx
!= -1) {
3057 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3058 if (con2fb_map
[i
] == idx
)
3059 set_con2fb_map(i
, new_idx
, 0);
3062 struct fb_info
*info
= registered_fb
[idx
];
3064 /* This is sort of like set_con2fb_map, except it maps
3065 * the consoles to no device and then releases the
3066 * oldinfo to free memory and cancel the cursor blink
3067 * timer. I can imagine this just becoming part of
3068 * set_con2fb_map where new_idx is -1
3070 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3071 if (con2fb_map
[i
] == idx
) {
3073 if (!search_fb_in_map(idx
)) {
3074 ret
= con2fb_release_oldinfo(vc_cons
[i
].d
,
3078 con2fb_map
[i
] = idx
;
3084 ret
= fbcon_unbind();
3090 /* called with console_lock held */
3091 static int fbcon_fb_unregistered(struct fb_info
*info
)
3096 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3097 if (con2fb_map
[i
] == idx
)
3101 if (idx
== info_idx
) {
3104 for (i
= 0; i
< FB_MAX
; i
++) {
3105 if (registered_fb
[i
] != NULL
) {
3112 if (info_idx
!= -1) {
3113 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3114 if (con2fb_map
[i
] == -1)
3115 con2fb_map
[i
] = info_idx
;
3119 if (primary_device
== idx
)
3120 primary_device
= -1;
3122 if (!num_registered_fb
)
3123 do_unregister_con_driver(&fb_con
);
3128 /* called with console_lock held */
3129 static void fbcon_remap_all(int idx
)
3132 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3133 set_con2fb_map(i
, idx
, 0);
3135 if (con_is_bound(&fb_con
)) {
3136 printk(KERN_INFO
"fbcon: Remapping primary device, "
3137 "fb%i, to tty %i-%i\n", idx
,
3138 first_fb_vc
+ 1, last_fb_vc
+ 1);
3143 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3144 static void fbcon_select_primary(struct fb_info
*info
)
3146 if (!map_override
&& primary_device
== -1 &&
3147 fb_is_primary_device(info
)) {
3150 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3151 info
->fix
.id
, info
->node
);
3152 primary_device
= info
->node
;
3154 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3155 con2fb_map_boot
[i
] = primary_device
;
3157 if (con_is_bound(&fb_con
)) {
3158 printk(KERN_INFO
"fbcon: Remapping primary device, "
3159 "fb%i, to tty %i-%i\n", info
->node
,
3160 first_fb_vc
+ 1, last_fb_vc
+ 1);
3161 info_idx
= primary_device
;
3167 static inline void fbcon_select_primary(struct fb_info
*info
)
3171 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3173 /* called with console_lock held */
3174 static int fbcon_fb_registered(struct fb_info
*info
)
3176 int ret
= 0, i
, idx
;
3179 fbcon_select_primary(info
);
3181 if (info_idx
== -1) {
3182 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3183 if (con2fb_map_boot
[i
] == idx
) {
3190 ret
= do_fbcon_takeover(1);
3192 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3193 if (con2fb_map_boot
[i
] == idx
)
3194 set_con2fb_map(i
, idx
, 0);
3201 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3203 struct fbcon_ops
*ops
= info
->fbcon_par
;
3206 if (!ops
|| ops
->currcon
< 0)
3209 vc
= vc_cons
[ops
->currcon
].d
;
3210 if (vc
->vc_mode
!= KD_TEXT
||
3211 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3214 if (con_is_visible(vc
)) {
3218 do_unblank_screen(0);
3220 ops
->blank_state
= blank
;
3223 static void fbcon_new_modelist(struct fb_info
*info
)
3227 struct fb_var_screeninfo var
;
3228 const struct fb_videomode
*mode
;
3230 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3231 if (registered_fb
[con2fb_map
[i
]] != info
)
3233 if (!fb_display
[i
].mode
)
3236 display_to_var(&var
, &fb_display
[i
]);
3237 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3239 fb_videomode_to_var(&var
, mode
);
3240 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3244 static void fbcon_get_requirement(struct fb_info
*info
,
3245 struct fb_blit_caps
*caps
)
3253 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3255 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3256 info
->node
== con2fb_map
[i
]) {
3258 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3259 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3260 charcnt
= (p
->userfont
) ?
3261 FNTCHARCNT(p
->fontdata
) : 256;
3262 if (caps
->len
< charcnt
)
3263 caps
->len
= charcnt
;
3267 vc
= vc_cons
[fg_console
].d
;
3269 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3270 info
->node
== con2fb_map
[fg_console
]) {
3271 p
= &fb_display
[fg_console
];
3272 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3273 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3274 caps
->len
= (p
->userfont
) ?
3275 FNTCHARCNT(p
->fontdata
) : 256;
3280 static int fbcon_event_notify(struct notifier_block
*self
,
3281 unsigned long action
, void *data
)
3283 struct fb_event
*event
= data
;
3284 struct fb_info
*info
= event
->info
;
3285 struct fb_videomode
*mode
;
3286 struct fb_con2fbmap
*con2fb
;
3287 struct fb_blit_caps
*caps
;
3291 * ignore all events except driver registration and deregistration
3292 * if fbcon is not active
3294 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3295 action
== FB_EVENT_FB_UNREGISTERED
))
3299 case FB_EVENT_SUSPEND
:
3300 fbcon_suspended(info
);
3302 case FB_EVENT_RESUME
:
3303 fbcon_resumed(info
);
3305 case FB_EVENT_MODE_CHANGE
:
3306 fbcon_modechanged(info
);
3308 case FB_EVENT_MODE_CHANGE_ALL
:
3309 fbcon_set_all_vcs(info
);
3311 case FB_EVENT_MODE_DELETE
:
3313 ret
= fbcon_mode_deleted(info
, mode
);
3315 case FB_EVENT_FB_UNBIND
:
3317 ret
= fbcon_fb_unbind(idx
);
3319 case FB_EVENT_FB_REGISTERED
:
3320 ret
= fbcon_fb_registered(info
);
3322 case FB_EVENT_FB_UNREGISTERED
:
3323 ret
= fbcon_fb_unregistered(info
);
3325 case FB_EVENT_SET_CONSOLE_MAP
:
3326 /* called with console lock held */
3327 con2fb
= event
->data
;
3328 ret
= set_con2fb_map(con2fb
->console
- 1,
3329 con2fb
->framebuffer
, 1);
3331 case FB_EVENT_GET_CONSOLE_MAP
:
3332 con2fb
= event
->data
;
3333 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3335 case FB_EVENT_BLANK
:
3336 fbcon_fb_blanked(info
, *(int *)event
->data
);
3338 case FB_EVENT_NEW_MODELIST
:
3339 fbcon_new_modelist(info
);
3341 case FB_EVENT_GET_REQ
:
3343 fbcon_get_requirement(info
, caps
);
3345 case FB_EVENT_REMAP_ALL_CONSOLE
:
3347 fbcon_remap_all(idx
);
3355 * The console `switch' structure for the frame buffer based console
3358 static const struct consw fb_con
= {
3359 .owner
= THIS_MODULE
,
3360 .con_startup
= fbcon_startup
,
3361 .con_init
= fbcon_init
,
3362 .con_deinit
= fbcon_deinit
,
3363 .con_clear
= fbcon_clear
,
3364 .con_putc
= fbcon_putc
,
3365 .con_putcs
= fbcon_putcs
,
3366 .con_cursor
= fbcon_cursor
,
3367 .con_scroll
= fbcon_scroll
,
3368 .con_switch
= fbcon_switch
,
3369 .con_blank
= fbcon_blank
,
3370 .con_font_set
= fbcon_set_font
,
3371 .con_font_get
= fbcon_get_font
,
3372 .con_font_default
= fbcon_set_def_font
,
3373 .con_font_copy
= fbcon_copy_font
,
3374 .con_set_palette
= fbcon_set_palette
,
3375 .con_scrolldelta
= fbcon_scrolldelta
,
3376 .con_set_origin
= fbcon_set_origin
,
3377 .con_invert_region
= fbcon_invert_region
,
3378 .con_screen_pos
= fbcon_screen_pos
,
3379 .con_getxy
= fbcon_getxy
,
3380 .con_resize
= fbcon_resize
,
3381 .con_debug_enter
= fbcon_debug_enter
,
3382 .con_debug_leave
= fbcon_debug_leave
,
3385 static struct notifier_block fbcon_event_notifier
= {
3386 .notifier_call
= fbcon_event_notify
,
3389 static ssize_t
store_rotate(struct device
*device
,
3390 struct device_attribute
*attr
, const char *buf
,
3393 struct fb_info
*info
;
3397 if (fbcon_has_exited
)
3401 idx
= con2fb_map
[fg_console
];
3403 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3406 info
= registered_fb
[idx
];
3407 rotate
= simple_strtoul(buf
, last
, 0);
3408 fbcon_rotate(info
, rotate
);
3414 static ssize_t
store_rotate_all(struct device
*device
,
3415 struct device_attribute
*attr
,const char *buf
,
3418 struct fb_info
*info
;
3422 if (fbcon_has_exited
)
3426 idx
= con2fb_map
[fg_console
];
3428 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3431 info
= registered_fb
[idx
];
3432 rotate
= simple_strtoul(buf
, last
, 0);
3433 fbcon_rotate_all(info
, rotate
);
3439 static ssize_t
show_rotate(struct device
*device
,
3440 struct device_attribute
*attr
,char *buf
)
3442 struct fb_info
*info
;
3443 int rotate
= 0, idx
;
3445 if (fbcon_has_exited
)
3449 idx
= con2fb_map
[fg_console
];
3451 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3454 info
= registered_fb
[idx
];
3455 rotate
= fbcon_get_rotate(info
);
3458 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3461 static ssize_t
show_cursor_blink(struct device
*device
,
3462 struct device_attribute
*attr
, char *buf
)
3464 struct fb_info
*info
;
3465 struct fbcon_ops
*ops
;
3466 int idx
, blink
= -1;
3468 if (fbcon_has_exited
)
3472 idx
= con2fb_map
[fg_console
];
3474 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3477 info
= registered_fb
[idx
];
3478 ops
= info
->fbcon_par
;
3483 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3486 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3489 static ssize_t
store_cursor_blink(struct device
*device
,
3490 struct device_attribute
*attr
,
3491 const char *buf
, size_t count
)
3493 struct fb_info
*info
;
3497 if (fbcon_has_exited
)
3501 idx
= con2fb_map
[fg_console
];
3503 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3506 info
= registered_fb
[idx
];
3508 if (!info
->fbcon_par
)
3511 blink
= simple_strtoul(buf
, last
, 0);
3514 fbcon_cursor_noblink
= 0;
3515 fbcon_add_cursor_timer(info
);
3517 fbcon_cursor_noblink
= 1;
3518 fbcon_del_cursor_timer(info
);
3526 static struct device_attribute device_attrs
[] = {
3527 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3528 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3529 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3530 store_cursor_blink
),
3533 static int fbcon_init_device(void)
3537 fbcon_has_sysfs
= 1;
3539 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3540 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3548 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3550 fbcon_has_sysfs
= 0;
3556 static void fbcon_start(void)
3558 if (num_registered_fb
) {
3563 for (i
= 0; i
< FB_MAX
; i
++) {
3564 if (registered_fb
[i
] != NULL
) {
3570 do_fbcon_takeover(0);
3576 static void fbcon_exit(void)
3578 struct fb_info
*info
;
3581 if (fbcon_has_exited
)
3584 kfree((void *)softback_buf
);
3587 for (i
= 0; i
< FB_MAX
; i
++) {
3591 info
= registered_fb
[i
];
3596 if (info
->queue
.func
)
3597 pending
= cancel_work_sync(&info
->queue
);
3598 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3601 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3602 if (con2fb_map
[j
] == i
) {
3609 if (info
->fbops
->fb_release
)
3610 info
->fbops
->fb_release(info
, 0);
3611 module_put(info
->fbops
->owner
);
3613 if (info
->fbcon_par
) {
3614 struct fbcon_ops
*ops
= info
->fbcon_par
;
3616 fbcon_del_cursor_timer(info
);
3617 kfree(ops
->cursor_src
);
3618 kfree(ops
->cursor_state
.mask
);
3619 kfree(info
->fbcon_par
);
3620 info
->fbcon_par
= NULL
;
3623 if (info
->queue
.func
== fb_flashcursor
)
3624 info
->queue
.func
= NULL
;
3628 fbcon_has_exited
= 1;
3631 void __init
fb_console_init(void)
3636 fb_register_client(&fbcon_event_notifier
);
3637 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3640 if (IS_ERR(fbcon_device
)) {
3641 printk(KERN_WARNING
"Unable to create device "
3642 "for fbcon; errno = %ld\n",
3643 PTR_ERR(fbcon_device
));
3644 fbcon_device
= NULL
;
3646 fbcon_init_device();
3648 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3657 static void __exit
fbcon_deinit_device(void)
3661 if (fbcon_has_sysfs
) {
3662 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3663 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3665 fbcon_has_sysfs
= 0;
3669 void __exit
fb_console_exit(void)
3672 fb_unregister_client(&fbcon_event_notifier
);
3673 fbcon_deinit_device();
3674 device_destroy(fb_class
, MKDEV(0, 0));
3676 do_unregister_con_driver(&fb_con
);