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/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
84 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
86 # define DPRINTK(fmt, args...)
90 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
91 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
92 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
95 static struct display fb_display
[MAX_NR_CONSOLES
];
97 static signed char con2fb_map
[MAX_NR_CONSOLES
];
98 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
100 static int logo_lines
;
101 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
103 static int logo_shown
= FBCON_LOGO_CANSHOW
;
104 /* Software scrollback */
105 static int fbcon_softback_size
= 32768;
106 static unsigned long softback_buf
, softback_curr
;
107 static unsigned long softback_in
;
108 static unsigned long softback_top
, softback_end
;
109 static int softback_lines
;
110 /* console mappings */
111 static int first_fb_vc
;
112 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
113 static int fbcon_is_default
= 1;
114 static int fbcon_has_exited
;
115 static int primary_device
= -1;
116 static int fbcon_has_console_bind
;
118 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
119 static int map_override
;
121 static inline void fbcon_map_override(void)
126 static inline void fbcon_map_override(void)
129 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
132 static char fontname
[40];
134 /* current fb_info */
135 static int info_idx
= -1;
137 /* console rotation */
138 static int initial_rotation
;
139 static int fbcon_has_sysfs
;
141 static const struct consw fb_con
;
143 #define CM_SOFTBACK (8)
145 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
147 static int fbcon_set_origin(struct vc_data
*);
149 static int fbcon_cursor_noblink
;
151 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
154 * Interface used by the world
157 static const char *fbcon_startup(void);
158 static void fbcon_init(struct vc_data
*vc
, int init
);
159 static void fbcon_deinit(struct vc_data
*vc
);
160 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
162 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
163 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
164 int count
, int ypos
, int xpos
);
165 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
166 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
167 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
168 int height
, int width
);
169 static int fbcon_switch(struct vc_data
*vc
);
170 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
171 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
);
176 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
177 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
178 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
179 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
180 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
181 int dy
, int dx
, int height
, int width
, u_int y_break
);
182 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
184 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
185 int line
, int count
, int dy
);
186 static void fbcon_modechanged(struct fb_info
*info
);
187 static void fbcon_set_all_vcs(struct fb_info
*info
);
188 static void fbcon_start(void);
189 static void fbcon_exit(void);
190 static struct device
*fbcon_device
;
192 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
193 static inline void fbcon_set_rotation(struct fb_info
*info
)
195 struct fbcon_ops
*ops
= info
->fbcon_par
;
197 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
198 ops
->p
->con_rotate
< 4)
199 ops
->rotate
= ops
->p
->con_rotate
;
204 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
206 struct fbcon_ops
*ops
= info
->fbcon_par
;
207 struct fb_info
*fb_info
;
209 if (!ops
|| ops
->currcon
== -1)
212 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
214 if (info
== fb_info
) {
215 struct display
*p
= &fb_display
[ops
->currcon
];
218 p
->con_rotate
= rotate
;
222 fbcon_modechanged(info
);
226 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
228 struct fbcon_ops
*ops
= info
->fbcon_par
;
233 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
236 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
238 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
239 registered_fb
[con2fb_map
[i
]] != info
)
242 p
= &fb_display
[vc
->vc_num
];
243 p
->con_rotate
= rotate
;
246 fbcon_set_all_vcs(info
);
249 static inline void fbcon_set_rotation(struct fb_info
*info
)
251 struct fbcon_ops
*ops
= info
->fbcon_par
;
253 ops
->rotate
= FB_ROTATE_UR
;
256 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
261 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
265 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
267 static int fbcon_get_rotate(struct fb_info
*info
)
269 struct fbcon_ops
*ops
= info
->fbcon_par
;
271 return (ops
) ? ops
->rotate
: 0;
274 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
276 struct fbcon_ops
*ops
= info
->fbcon_par
;
278 return (info
->state
!= FBINFO_STATE_RUNNING
||
279 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
) &&
280 !vt_force_oops_output(vc
);
283 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
286 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
289 if (console_blanked
) {
290 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
292 c
= vc
->vc_video_erase_char
& charmask
;
296 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
297 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
302 int col
= mono_col(info
);
304 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
305 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
310 color
= (is_fg
) ? fg
: bg
;
315 * Scale down 16-colors to 4 colors. Default 4-color palette
316 * is grayscale. However, simply dividing the values by 4
317 * will not work, as colors 1, 2 and 3 will be scaled-down
318 * to zero rendering them invisible. So empirically convert
319 * colors to a sane 4-level grayscale.
323 color
= 0; /* black */
326 color
= 2; /* white */
329 color
= 1; /* gray */
332 color
= 3; /* intense white */
338 * Last 8 entries of default 16-color palette is a more intense
339 * version of the first 8 (i.e., same chrominance, different
350 static void fbcon_update_softback(struct vc_data
*vc
)
352 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
355 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
357 /* Smaller scrollback makes no sense, and 0 would screw
358 the operation totally */
362 static void fb_flashcursor(struct work_struct
*work
)
364 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
365 struct fbcon_ops
*ops
= info
->fbcon_par
;
366 struct vc_data
*vc
= NULL
;
371 /* FIXME: we should sort out the unbind locking instead */
372 /* instead we just fail to flash the cursor if we can't get
373 * the lock instead of blocking fbcon deinit */
374 ret
= console_trylock();
378 if (ops
&& ops
->currcon
!= -1)
379 vc
= vc_cons
[ops
->currcon
].d
;
381 if (!vc
|| !con_is_visible(vc
) ||
382 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
388 c
= scr_readw((u16
*) vc
->vc_pos
);
389 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
391 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
392 get_color(vc
, info
, c
, 0));
396 static void cursor_timer_handler(unsigned long dev_addr
)
398 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
399 struct fbcon_ops
*ops
= info
->fbcon_par
;
401 queue_work(system_power_efficient_wq
, &info
->queue
);
402 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
405 static void fbcon_add_cursor_timer(struct fb_info
*info
)
407 struct fbcon_ops
*ops
= info
->fbcon_par
;
409 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
410 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
411 !fbcon_cursor_noblink
) {
412 if (!info
->queue
.func
)
413 INIT_WORK(&info
->queue
, fb_flashcursor
);
415 setup_timer(&ops
->cursor_timer
, cursor_timer_handler
,
416 (unsigned long) info
);
417 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
418 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
422 static void fbcon_del_cursor_timer(struct fb_info
*info
)
424 struct fbcon_ops
*ops
= info
->fbcon_par
;
426 if (info
->queue
.func
== fb_flashcursor
&&
427 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
428 del_timer_sync(&ops
->cursor_timer
);
429 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
434 static int __init
fb_console_setup(char *this_opt
)
439 if (!this_opt
|| !*this_opt
)
442 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
443 if (!strncmp(options
, "font:", 5)) {
444 strlcpy(fontname
, options
+ 5, sizeof(fontname
));
448 if (!strncmp(options
, "scrollback:", 11)) {
451 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
452 if (*options
== 'k' || *options
== 'K') {
453 fbcon_softback_size
*= 1024;
459 if (!strncmp(options
, "map:", 4)) {
462 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
466 (options
[j
++]-'0') % FB_MAX
;
469 fbcon_map_override();
474 if (!strncmp(options
, "vc:", 3)) {
477 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
480 if (*options
++ == '-')
481 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
482 fbcon_is_default
= 0;
486 if (!strncmp(options
, "rotate:", 7)) {
489 initial_rotation
= simple_strtoul(options
, &options
, 0);
490 if (initial_rotation
> 3)
491 initial_rotation
= 0;
498 __setup("fbcon=", fb_console_setup
);
501 static int search_fb_in_map(int idx
)
505 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
506 if (con2fb_map
[i
] == idx
)
512 static int search_for_mapped_con(void)
516 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
517 if (con2fb_map
[i
] != -1)
523 static int do_fbcon_takeover(int show_logo
)
527 if (!num_registered_fb
)
531 logo_shown
= FBCON_LOGO_DONTSHOW
;
533 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
534 con2fb_map
[i
] = info_idx
;
536 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
540 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
544 fbcon_has_console_bind
= 1;
551 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
552 int cols
, int rows
, int new_cols
, int new_rows
)
554 logo_shown
= FBCON_LOGO_DONTSHOW
;
557 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
558 int cols
, int rows
, int new_cols
, int new_rows
)
560 /* Need to make room for the logo */
561 struct fbcon_ops
*ops
= info
->fbcon_par
;
562 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
563 unsigned short *save
= NULL
, *r
, *q
;
566 if (info
->flags
& FBINFO_MODULE
) {
567 logo_shown
= FBCON_LOGO_DONTSHOW
;
572 * remove underline attribute from erase character
573 * if black and white framebuffer.
575 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
577 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
578 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
579 q
= (unsigned short *) (vc
->vc_origin
+
580 vc
->vc_size_row
* rows
);
581 step
= logo_lines
* cols
;
582 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
583 if (scr_readw(r
) != vc
->vc_video_erase_char
)
585 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
586 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
588 int i
= cols
< new_cols
? cols
: new_cols
;
589 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
591 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
592 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
597 /* We can scroll screen down */
599 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
600 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
605 if (vc
->vc_y
+ logo_lines
>= rows
)
606 lines
= rows
- vc
->vc_y
- 1;
610 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
613 scr_memsetw((unsigned short *) vc
->vc_origin
,
615 vc
->vc_size_row
* logo_lines
);
617 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
618 fbcon_clear_margins(vc
, 0);
623 q
= (unsigned short *) (vc
->vc_origin
+
626 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
627 vc
->vc_y
+= logo_lines
;
628 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
632 if (logo_lines
> vc
->vc_bottom
) {
633 logo_shown
= FBCON_LOGO_CANSHOW
;
635 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
636 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
637 logo_shown
= FBCON_LOGO_DRAW
;
638 vc
->vc_top
= logo_lines
;
643 #ifdef CONFIG_FB_TILEBLITTING
644 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
646 struct fbcon_ops
*ops
= info
->fbcon_par
;
648 ops
->p
= &fb_display
[vc
->vc_num
];
650 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
651 fbcon_set_tileops(vc
, info
);
653 fbcon_set_rotation(info
);
654 fbcon_set_bitops(ops
);
658 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
662 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
663 info
->tileops
->fb_get_tilemax(info
) < charcount
)
669 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
671 struct fbcon_ops
*ops
= info
->fbcon_par
;
673 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
674 ops
->p
= &fb_display
[vc
->vc_num
];
675 fbcon_set_rotation(info
);
676 fbcon_set_bitops(ops
);
679 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
684 #endif /* CONFIG_MISC_TILEBLITTING */
687 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
688 int unit
, int oldidx
)
690 struct fbcon_ops
*ops
= NULL
;
693 if (!try_module_get(info
->fbops
->owner
))
696 if (!err
&& info
->fbops
->fb_open
&&
697 info
->fbops
->fb_open(info
, 0))
701 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
707 ops
->cur_blink_jiffies
= HZ
/ 5;
708 info
->fbcon_par
= ops
;
711 set_blitting_type(vc
, info
);
715 con2fb_map
[unit
] = oldidx
;
716 module_put(info
->fbops
->owner
);
722 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
723 struct fb_info
*newinfo
, int unit
,
724 int oldidx
, int found
)
726 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
729 if (oldinfo
->fbops
->fb_release
&&
730 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
731 con2fb_map
[unit
] = oldidx
;
732 if (!found
&& newinfo
->fbops
->fb_release
)
733 newinfo
->fbops
->fb_release(newinfo
, 0);
735 module_put(newinfo
->fbops
->owner
);
740 fbcon_del_cursor_timer(oldinfo
);
741 kfree(ops
->cursor_state
.mask
);
742 kfree(ops
->cursor_data
);
743 kfree(ops
->cursor_src
);
744 kfree(ops
->fontbuffer
);
745 kfree(oldinfo
->fbcon_par
);
746 oldinfo
->fbcon_par
= NULL
;
747 module_put(oldinfo
->fbops
->owner
);
749 If oldinfo and newinfo are driving the same hardware,
750 the fb_release() method of oldinfo may attempt to
751 restore the hardware state. This will leave the
752 newinfo in an undefined state. Thus, a call to
753 fb_set_par() may be needed for the newinfo.
755 if (newinfo
&& newinfo
->fbops
->fb_set_par
) {
756 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
759 printk(KERN_ERR
"con2fb_release_oldinfo: "
760 "detected unhandled fb_set_par error, "
761 "error code %d\n", ret
);
768 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
769 int unit
, int show_logo
)
771 struct fbcon_ops
*ops
= info
->fbcon_par
;
774 ops
->currcon
= fg_console
;
776 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
777 ret
= info
->fbops
->fb_set_par(info
);
780 printk(KERN_ERR
"con2fb_init_display: detected "
781 "unhandled fb_set_par error, "
782 "error code %d\n", ret
);
785 ops
->flags
|= FBCON_FLAGS_INIT
;
787 fbcon_set_disp(info
, &info
->var
, unit
);
790 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
791 struct fb_info
*fg_info
=
792 registered_fb
[con2fb_map
[fg_console
]];
794 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
795 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
799 update_screen(vc_cons
[fg_console
].d
);
803 * set_con2fb_map - map console to frame buffer device
804 * @unit: virtual console number to map
805 * @newidx: frame buffer index to map virtual console to
806 * @user: user request
808 * Maps a virtual console @unit to a frame buffer device
811 * This should be called with the console lock held.
813 static int set_con2fb_map(int unit
, int newidx
, int user
)
815 struct vc_data
*vc
= vc_cons
[unit
].d
;
816 int oldidx
= con2fb_map
[unit
];
817 struct fb_info
*info
= registered_fb
[newidx
];
818 struct fb_info
*oldinfo
= NULL
;
821 if (oldidx
== newidx
)
827 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
829 return do_fbcon_takeover(0);
833 oldinfo
= registered_fb
[oldidx
];
835 found
= search_fb_in_map(newidx
);
837 con2fb_map
[unit
] = newidx
;
839 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
843 * If old fb is not mapped to any of the consoles,
844 * fbcon should release it.
846 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
847 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
851 int show_logo
= (fg_console
== 0 && !user
&&
852 logo_shown
!= FBCON_LOGO_DONTSHOW
);
855 fbcon_add_cursor_timer(info
);
856 con2fb_map_boot
[unit
] = newidx
;
857 con2fb_init_display(vc
, info
, unit
, show_logo
);
860 if (!search_fb_in_map(info_idx
))
867 * Low Level Operations
869 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
870 static int var_to_display(struct display
*disp
,
871 struct fb_var_screeninfo
*var
,
872 struct fb_info
*info
)
874 disp
->xres_virtual
= var
->xres_virtual
;
875 disp
->yres_virtual
= var
->yres_virtual
;
876 disp
->bits_per_pixel
= var
->bits_per_pixel
;
877 disp
->grayscale
= var
->grayscale
;
878 disp
->nonstd
= var
->nonstd
;
879 disp
->accel_flags
= var
->accel_flags
;
880 disp
->height
= var
->height
;
881 disp
->width
= var
->width
;
882 disp
->red
= var
->red
;
883 disp
->green
= var
->green
;
884 disp
->blue
= var
->blue
;
885 disp
->transp
= var
->transp
;
886 disp
->rotate
= var
->rotate
;
887 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
888 if (disp
->mode
== NULL
)
889 /* This should not happen */
894 static void display_to_var(struct fb_var_screeninfo
*var
,
895 struct display
*disp
)
897 fb_videomode_to_var(var
, disp
->mode
);
898 var
->xres_virtual
= disp
->xres_virtual
;
899 var
->yres_virtual
= disp
->yres_virtual
;
900 var
->bits_per_pixel
= disp
->bits_per_pixel
;
901 var
->grayscale
= disp
->grayscale
;
902 var
->nonstd
= disp
->nonstd
;
903 var
->accel_flags
= disp
->accel_flags
;
904 var
->height
= disp
->height
;
905 var
->width
= disp
->width
;
906 var
->red
= disp
->red
;
907 var
->green
= disp
->green
;
908 var
->blue
= disp
->blue
;
909 var
->transp
= disp
->transp
;
910 var
->rotate
= disp
->rotate
;
913 static const char *fbcon_startup(void)
915 const char *display_desc
= "frame buffer device";
916 struct display
*p
= &fb_display
[fg_console
];
917 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
918 const struct font_desc
*font
= NULL
;
919 struct module
*owner
;
920 struct fb_info
*info
= NULL
;
921 struct fbcon_ops
*ops
;
925 * If num_registered_fb is zero, this is a call for the dummy part.
926 * The frame buffer devices weren't initialized yet.
928 if (!num_registered_fb
|| info_idx
== -1)
931 * Instead of blindly using registered_fb[0], we use info_idx, set by
934 info
= registered_fb
[info_idx
];
938 owner
= info
->fbops
->owner
;
939 if (!try_module_get(owner
))
941 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
946 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
954 ops
->cur_rotate
= -1;
955 ops
->cur_blink_jiffies
= HZ
/ 5;
956 info
->fbcon_par
= ops
;
957 p
->con_rotate
= initial_rotation
;
958 set_blitting_type(vc
, info
);
960 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
961 if (fbcon_softback_size
) {
965 kmalloc(fbcon_softback_size
,
968 fbcon_softback_size
= 0;
974 kfree((void *) softback_buf
);
980 softback_in
= softback_top
= softback_curr
=
985 /* Setup default font */
986 if (!p
->fontdata
&& !vc
->vc_font
.data
) {
987 if (!fontname
[0] || !(font
= find_font(fontname
)))
988 font
= get_default_font(info
->var
.xres
,
991 info
->pixmap
.blit_y
);
992 vc
->vc_font
.width
= font
->width
;
993 vc
->vc_font
.height
= font
->height
;
994 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
995 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
997 p
->fontdata
= vc
->vc_font
.data
;
1000 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1001 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1002 cols
/= vc
->vc_font
.width
;
1003 rows
/= vc
->vc_font
.height
;
1004 vc_resize(vc
, cols
, rows
);
1006 DPRINTK("mode: %s\n", info
->fix
.id
);
1007 DPRINTK("visual: %d\n", info
->fix
.visual
);
1008 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1010 info
->var
.bits_per_pixel
);
1012 fbcon_add_cursor_timer(info
);
1013 fbcon_has_exited
= 0;
1014 return display_desc
;
1017 static void fbcon_init(struct vc_data
*vc
, int init
)
1019 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1020 struct fbcon_ops
*ops
;
1021 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1022 struct vc_data
*svc
= *default_mode
;
1023 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1024 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1027 if (info_idx
== -1 || info
== NULL
)
1032 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1033 (info
->fix
.type
== FB_TYPE_TEXT
))
1036 if (var_to_display(p
, &info
->var
, info
))
1039 if (!info
->fbcon_par
)
1040 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1042 /* If we are not the first console on this
1043 fb, copy the font from that console */
1044 t
= &fb_display
[fg_console
];
1047 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1049 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1051 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1052 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1053 p
->userfont
= t
->userfont
;
1056 REFCOUNT(p
->fontdata
)++;
1058 const struct font_desc
*font
= NULL
;
1060 if (!fontname
[0] || !(font
= find_font(fontname
)))
1061 font
= get_default_font(info
->var
.xres
,
1063 info
->pixmap
.blit_x
,
1064 info
->pixmap
.blit_y
);
1065 vc
->vc_font
.width
= font
->width
;
1066 vc
->vc_font
.height
= font
->height
;
1067 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1068 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1069 support more fonts */
1074 charcnt
= FNTCHARCNT(p
->fontdata
);
1076 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1077 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1078 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1079 if (charcnt
== 256) {
1080 vc
->vc_hi_font_mask
= 0;
1082 vc
->vc_hi_font_mask
= 0x100;
1083 if (vc
->vc_can_do_color
)
1084 vc
->vc_complement_mask
<<= 1;
1087 if (!*svc
->vc_uni_pagedir_loc
)
1088 con_set_default_unimap(svc
);
1089 if (!*vc
->vc_uni_pagedir_loc
)
1090 con_copy_unimap(vc
, svc
);
1092 ops
= info
->fbcon_par
;
1093 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1094 p
->con_rotate
= initial_rotation
;
1095 set_blitting_type(vc
, info
);
1099 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1100 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1101 new_cols
/= vc
->vc_font
.width
;
1102 new_rows
/= vc
->vc_font
.height
;
1105 * We must always set the mode. The mode of the previous console
1106 * driver could be in the same resolution but we are using different
1107 * hardware so we have to initialize the hardware.
1109 * We need to do it in fbcon_init() to prevent screen corruption.
1111 if (con_is_visible(vc
) && vc
->vc_mode
== KD_TEXT
) {
1112 if (info
->fbops
->fb_set_par
&&
1113 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1114 ret
= info
->fbops
->fb_set_par(info
);
1117 printk(KERN_ERR
"fbcon_init: detected "
1118 "unhandled fb_set_par error, "
1119 "error code %d\n", ret
);
1122 ops
->flags
|= FBCON_FLAGS_INIT
;
1127 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1128 !(cap
& FBINFO_HWACCEL_DISABLED
))
1129 p
->scrollmode
= SCROLL_MOVE
;
1130 else /* default to something safe */
1131 p
->scrollmode
= SCROLL_REDRAW
;
1134 * ++guenther: console.c:vc_allocate() relies on initializing
1135 * vc_{cols,rows}, but we must not set those if we are only
1136 * resizing the console.
1139 vc
->vc_cols
= new_cols
;
1140 vc
->vc_rows
= new_rows
;
1142 vc_resize(vc
, new_cols
, new_rows
);
1145 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1147 if (vc
== svc
&& softback_buf
)
1148 fbcon_update_softback(vc
);
1150 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1151 ops
->rotate
= FB_ROTATE_UR
;
1152 set_blitting_type(vc
, info
);
1155 ops
->p
= &fb_display
[fg_console
];
1158 static void fbcon_free_font(struct display
*p
, bool freefont
)
1160 if (freefont
&& p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1161 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1166 static void set_vc_hi_font(struct vc_data
*vc
, bool set
);
1168 static void fbcon_deinit(struct vc_data
*vc
)
1170 struct display
*p
= &fb_display
[vc
->vc_num
];
1171 struct fb_info
*info
;
1172 struct fbcon_ops
*ops
;
1174 bool free_font
= true;
1176 idx
= con2fb_map
[vc
->vc_num
];
1181 info
= registered_fb
[idx
];
1186 if (info
->flags
& FBINFO_MISC_FIRMWARE
)
1188 ops
= info
->fbcon_par
;
1193 if (con_is_visible(vc
))
1194 fbcon_del_cursor_timer(info
);
1196 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1199 fbcon_free_font(p
, free_font
);
1201 vc
->vc_font
.data
= NULL
;
1203 if (vc
->vc_hi_font_mask
)
1204 set_vc_hi_font(vc
, false);
1206 if (!con_is_bound(&fb_con
))
1212 /* ====================================================================== */
1214 /* fbcon_XXX routines - interface used by the world
1216 * This system is now divided into two levels because of complications
1217 * caused by hardware scrolling. Top level functions:
1219 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1221 * handles y values in range [0, scr_height-1] that correspond to real
1222 * screen positions. y_wrap shift means that first line of bitmap may be
1223 * anywhere on this display. These functions convert lineoffsets to
1224 * bitmap offsets and deal with the wrap-around case by splitting blits.
1226 * fbcon_bmove_physical_8() -- These functions fast implementations
1227 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1228 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1232 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1233 * Implies should only really hardware scroll in rows. Only reason for
1234 * restriction is simplicity & efficiency at the moment.
1237 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1240 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1241 struct fbcon_ops
*ops
= info
->fbcon_par
;
1243 struct display
*p
= &fb_display
[vc
->vc_num
];
1246 if (fbcon_is_inactive(vc
, info
))
1249 if (!height
|| !width
)
1252 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1255 * If the font dimensions are not an integral of the display
1256 * dimensions then the ops->clear below won't end up clearing
1257 * the margins. Call clear_margins here in case the logo
1258 * bitmap stretched into the margin area.
1260 fbcon_clear_margins(vc
, 0);
1263 /* Split blits that cross physical y_wrap boundary */
1265 y_break
= p
->vrows
- p
->yscroll
;
1266 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1267 u_int b
= y_break
- sy
;
1268 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1269 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1272 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1275 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1276 int count
, int ypos
, int xpos
)
1278 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1279 struct display
*p
= &fb_display
[vc
->vc_num
];
1280 struct fbcon_ops
*ops
= info
->fbcon_par
;
1282 if (!fbcon_is_inactive(vc
, info
))
1283 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1284 get_color(vc
, info
, scr_readw(s
), 1),
1285 get_color(vc
, info
, scr_readw(s
), 0));
1288 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1292 scr_writew(c
, &chr
);
1293 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1296 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1298 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1299 struct fbcon_ops
*ops
= info
->fbcon_par
;
1301 if (!fbcon_is_inactive(vc
, info
))
1302 ops
->clear_margins(vc
, info
, bottom_only
);
1305 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1307 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1308 struct fbcon_ops
*ops
= info
->fbcon_par
;
1310 int c
= scr_readw((u16
*) vc
->vc_pos
);
1312 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1314 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1317 if (vc
->vc_cursor_type
& 0x10)
1318 fbcon_del_cursor_timer(info
);
1320 fbcon_add_cursor_timer(info
);
1322 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1323 if (mode
& CM_SOFTBACK
) {
1324 mode
&= ~CM_SOFTBACK
;
1328 fbcon_set_origin(vc
);
1332 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1333 get_color(vc
, info
, c
, 0));
1336 static int scrollback_phys_max
= 0;
1337 static int scrollback_max
= 0;
1338 static int scrollback_current
= 0;
1340 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1343 struct display
*p
, *t
;
1344 struct vc_data
**default_mode
, *vc
;
1345 struct vc_data
*svc
;
1346 struct fbcon_ops
*ops
= info
->fbcon_par
;
1347 int rows
, cols
, charcnt
= 256;
1349 p
= &fb_display
[unit
];
1351 if (var_to_display(p
, var
, info
))
1354 vc
= vc_cons
[unit
].d
;
1359 default_mode
= vc
->vc_display_fg
;
1360 svc
= *default_mode
;
1361 t
= &fb_display
[svc
->vc_num
];
1363 if (!vc
->vc_font
.data
) {
1364 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1365 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1366 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1367 p
->userfont
= t
->userfont
;
1369 REFCOUNT(p
->fontdata
)++;
1372 charcnt
= FNTCHARCNT(p
->fontdata
);
1374 var
->activate
= FB_ACTIVATE_NOW
;
1375 info
->var
.activate
= var
->activate
;
1376 var
->yoffset
= info
->var
.yoffset
;
1377 var
->xoffset
= info
->var
.xoffset
;
1378 fb_set_var(info
, var
);
1379 ops
->var
= info
->var
;
1380 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1381 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1382 if (charcnt
== 256) {
1383 vc
->vc_hi_font_mask
= 0;
1385 vc
->vc_hi_font_mask
= 0x100;
1386 if (vc
->vc_can_do_color
)
1387 vc
->vc_complement_mask
<<= 1;
1390 if (!*svc
->vc_uni_pagedir_loc
)
1391 con_set_default_unimap(svc
);
1392 if (!*vc
->vc_uni_pagedir_loc
)
1393 con_copy_unimap(vc
, svc
);
1395 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1396 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1397 cols
/= vc
->vc_font
.width
;
1398 rows
/= vc
->vc_font
.height
;
1399 vc_resize(vc
, cols
, rows
);
1401 if (con_is_visible(vc
)) {
1404 fbcon_update_softback(vc
);
1408 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1410 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1411 struct fbcon_ops
*ops
= info
->fbcon_par
;
1412 struct display
*p
= &fb_display
[vc
->vc_num
];
1414 p
->yscroll
+= count
;
1415 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1416 p
->yscroll
-= p
->vrows
;
1417 ops
->var
.xoffset
= 0;
1418 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1419 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1420 ops
->update_start(info
);
1421 scrollback_max
+= count
;
1422 if (scrollback_max
> scrollback_phys_max
)
1423 scrollback_max
= scrollback_phys_max
;
1424 scrollback_current
= 0;
1427 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1429 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1430 struct fbcon_ops
*ops
= info
->fbcon_par
;
1431 struct display
*p
= &fb_display
[vc
->vc_num
];
1433 p
->yscroll
-= count
;
1434 if (p
->yscroll
< 0) /* Deal with wrap */
1435 p
->yscroll
+= p
->vrows
;
1436 ops
->var
.xoffset
= 0;
1437 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1438 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1439 ops
->update_start(info
);
1440 scrollback_max
-= count
;
1441 if (scrollback_max
< 0)
1443 scrollback_current
= 0;
1446 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1448 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1449 struct display
*p
= &fb_display
[vc
->vc_num
];
1450 struct fbcon_ops
*ops
= info
->fbcon_par
;
1452 p
->yscroll
+= count
;
1453 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1454 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1455 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1456 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1459 ops
->var
.xoffset
= 0;
1460 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1461 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1462 ops
->update_start(info
);
1463 fbcon_clear_margins(vc
, 1);
1464 scrollback_max
+= count
;
1465 if (scrollback_max
> scrollback_phys_max
)
1466 scrollback_max
= scrollback_phys_max
;
1467 scrollback_current
= 0;
1470 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1472 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1473 struct fbcon_ops
*ops
= info
->fbcon_par
;
1474 struct display
*p
= &fb_display
[vc
->vc_num
];
1476 p
->yscroll
+= count
;
1478 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1479 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1480 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1483 ops
->var
.xoffset
= 0;
1484 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1485 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1486 ops
->update_start(info
);
1487 fbcon_clear_margins(vc
, 1);
1488 scrollback_max
+= count
;
1489 if (scrollback_max
> scrollback_phys_max
)
1490 scrollback_max
= scrollback_phys_max
;
1491 scrollback_current
= 0;
1494 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1496 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1497 struct display
*p
= &fb_display
[vc
->vc_num
];
1498 struct fbcon_ops
*ops
= info
->fbcon_par
;
1500 p
->yscroll
-= count
;
1501 if (p
->yscroll
< 0) {
1502 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1503 0, vc
->vc_rows
, vc
->vc_cols
);
1504 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1507 ops
->var
.xoffset
= 0;
1508 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1509 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1510 ops
->update_start(info
);
1511 fbcon_clear_margins(vc
, 1);
1512 scrollback_max
-= count
;
1513 if (scrollback_max
< 0)
1515 scrollback_current
= 0;
1518 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1520 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1521 struct fbcon_ops
*ops
= info
->fbcon_par
;
1522 struct display
*p
= &fb_display
[vc
->vc_num
];
1524 p
->yscroll
-= count
;
1526 if (p
->yscroll
< 0) {
1527 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1528 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1531 ops
->var
.xoffset
= 0;
1532 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1533 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1534 ops
->update_start(info
);
1535 fbcon_clear_margins(vc
, 1);
1536 scrollback_max
-= count
;
1537 if (scrollback_max
< 0)
1539 scrollback_current
= 0;
1542 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1545 int count
= vc
->vc_rows
;
1546 unsigned short *d
, *s
;
1550 d
= (u16
*) softback_curr
;
1551 if (d
== (u16
*) softback_in
)
1552 d
= (u16
*) vc
->vc_origin
;
1553 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1554 softback_lines
-= delta
;
1556 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1557 n
+= softback_end
- softback_buf
;
1558 if (n
< softback_top
) {
1560 (softback_top
- n
) / vc
->vc_size_row
;
1563 } else if (softback_curr
>= softback_top
1564 && n
< softback_top
) {
1566 (softback_top
- n
) / vc
->vc_size_row
;
1570 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1571 n
+= softback_buf
- softback_end
;
1572 if (n
> softback_in
) {
1576 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1581 if (n
== softback_curr
)
1584 s
= (u16
*) softback_curr
;
1585 if (s
== (u16
*) softback_in
)
1586 s
= (u16
*) vc
->vc_origin
;
1588 unsigned short *start
;
1592 unsigned short attr
= 1;
1595 le
= advance_row(s
, 1);
1598 if (attr
!= (c
& 0xff00)) {
1601 fbcon_putcs(vc
, start
, s
- start
,
1607 if (c
== scr_readw(d
)) {
1609 fbcon_putcs(vc
, start
, s
- start
,
1622 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1624 if (d
== (u16
*) softback_end
)
1625 d
= (u16
*) softback_buf
;
1626 if (d
== (u16
*) softback_in
)
1627 d
= (u16
*) vc
->vc_origin
;
1628 if (s
== (u16
*) softback_end
)
1629 s
= (u16
*) softback_buf
;
1630 if (s
== (u16
*) softback_in
)
1631 s
= (u16
*) vc
->vc_origin
;
1635 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1636 int line
, int count
, int dy
)
1638 unsigned short *s
= (unsigned short *)
1639 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1642 unsigned short *start
= s
;
1643 unsigned short *le
= advance_row(s
, 1);
1646 unsigned short attr
= 1;
1650 if (attr
!= (c
& 0xff00)) {
1653 fbcon_putcs(vc
, start
, s
- start
,
1659 console_conditional_schedule();
1663 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1664 console_conditional_schedule();
1669 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1670 struct display
*p
, int line
, int count
, int ycount
)
1672 int offset
= ycount
* vc
->vc_cols
;
1673 unsigned short *d
= (unsigned short *)
1674 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1675 unsigned short *s
= d
+ offset
;
1676 struct fbcon_ops
*ops
= info
->fbcon_par
;
1679 unsigned short *start
= s
;
1680 unsigned short *le
= advance_row(s
, 1);
1687 if (c
== scr_readw(d
)) {
1689 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1690 line
, x
, 1, s
-start
);
1700 console_conditional_schedule();
1705 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1707 console_conditional_schedule();
1712 /* NOTE: We subtract two lines from these pointers */
1713 s
-= vc
->vc_size_row
;
1714 d
-= vc
->vc_size_row
;
1719 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1720 int line
, int count
, int offset
)
1722 unsigned short *d
= (unsigned short *)
1723 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1724 unsigned short *s
= d
+ offset
;
1727 unsigned short *start
= s
;
1728 unsigned short *le
= advance_row(s
, 1);
1731 unsigned short attr
= 1;
1735 if (attr
!= (c
& 0xff00)) {
1738 fbcon_putcs(vc
, start
, s
- start
,
1744 if (c
== scr_readw(d
)) {
1746 fbcon_putcs(vc
, start
, s
- start
,
1756 console_conditional_schedule();
1761 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1762 console_conditional_schedule();
1767 /* NOTE: We subtract two lines from these pointers */
1768 s
-= vc
->vc_size_row
;
1769 d
-= vc
->vc_size_row
;
1774 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1779 if (vc
->vc_num
!= fg_console
)
1781 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1784 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1786 p
= advance_row(p
, 1);
1787 softback_in
+= vc
->vc_size_row
;
1788 if (softback_in
== softback_end
)
1789 softback_in
= softback_buf
;
1790 if (softback_in
== softback_top
) {
1791 softback_top
+= vc
->vc_size_row
;
1792 if (softback_top
== softback_end
)
1793 softback_top
= softback_buf
;
1796 softback_curr
= softback_in
;
1799 static bool fbcon_scroll(struct vc_data
*vc
, unsigned int t
, unsigned int b
,
1800 enum con_scroll dir
, unsigned int count
)
1802 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1803 struct display
*p
= &fb_display
[vc
->vc_num
];
1804 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1806 if (fbcon_is_inactive(vc
, info
))
1809 fbcon_cursor(vc
, CM_ERASE
);
1812 * ++Geert: Only use ywrap/ypan if the console is in text mode
1813 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1814 * whole screen (prevents flicker).
1819 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1820 count
= vc
->vc_rows
;
1822 fbcon_softback_note(vc
, t
, count
);
1823 if (logo_shown
>= 0)
1825 switch (p
->scrollmode
) {
1827 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1829 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1830 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1833 vc
->vc_video_erase_char
,
1834 vc
->vc_size_row
* count
);
1838 case SCROLL_WRAP_MOVE
:
1839 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1841 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1843 ywrap_up(vc
, count
);
1844 if (vc
->vc_rows
- b
> 0)
1845 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1848 } else if (info
->flags
& FBINFO_READS_FAST
)
1849 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1850 b
- t
- count
, vc
->vc_cols
);
1853 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1856 case SCROLL_PAN_REDRAW
:
1857 if ((p
->yscroll
+ count
<=
1858 2 * (p
->vrows
- vc
->vc_rows
))
1859 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1862 3 * vc
->vc_rows
>> 2)))) {
1864 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1865 ypan_up_redraw(vc
, t
, count
);
1866 if (vc
->vc_rows
- b
> 0)
1867 fbcon_redraw_move(vc
, p
, b
,
1868 vc
->vc_rows
- b
, b
);
1870 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1871 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1874 case SCROLL_PAN_MOVE
:
1875 if ((p
->yscroll
+ count
<=
1876 2 * (p
->vrows
- vc
->vc_rows
))
1877 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1880 3 * vc
->vc_rows
>> 2)))) {
1882 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1885 if (vc
->vc_rows
- b
> 0)
1886 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1889 } else if (info
->flags
& FBINFO_READS_FAST
)
1890 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1891 b
- t
- count
, vc
->vc_cols
);
1894 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1899 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1900 count
* vc
->vc_cols
);
1901 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1902 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1905 vc
->vc_video_erase_char
,
1906 vc
->vc_size_row
* count
);
1912 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1913 count
= vc
->vc_rows
;
1914 if (logo_shown
>= 0)
1916 switch (p
->scrollmode
) {
1918 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1920 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1921 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1924 vc
->vc_video_erase_char
,
1925 vc
->vc_size_row
* count
);
1929 case SCROLL_WRAP_MOVE
:
1930 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1931 if (vc
->vc_rows
- b
> 0)
1932 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1935 ywrap_down(vc
, count
);
1937 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1939 } else if (info
->flags
& FBINFO_READS_FAST
)
1940 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1941 b
- t
- count
, vc
->vc_cols
);
1944 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1947 case SCROLL_PAN_MOVE
:
1948 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1949 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1952 3 * vc
->vc_rows
>> 2)))) {
1953 if (vc
->vc_rows
- b
> 0)
1954 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1957 ypan_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_REDRAW
:
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_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1978 ypan_down_redraw(vc
, t
, count
);
1980 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1982 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1983 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1988 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1989 -count
* vc
->vc_cols
);
1990 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1991 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1994 vc
->vc_video_erase_char
,
1995 vc
->vc_size_row
* count
);
2003 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2004 int height
, int width
)
2006 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2007 struct display
*p
= &fb_display
[vc
->vc_num
];
2009 if (fbcon_is_inactive(vc
, info
))
2012 if (!width
|| !height
)
2015 /* Split blits that cross physical y_wrap case.
2016 * Pathological case involves 4 blits, better to use recursive
2017 * code rather than unrolled case
2019 * Recursive invocations don't need to erase the cursor over and
2020 * over again, so we use fbcon_bmove_rec()
2022 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2023 p
->vrows
- p
->yscroll
);
2026 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2027 int dy
, int dx
, int height
, int width
, u_int y_break
)
2029 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2030 struct fbcon_ops
*ops
= info
->fbcon_par
;
2033 if (sy
< y_break
&& sy
+ height
> y_break
) {
2035 if (dy
< sy
) { /* Avoid trashing self */
2036 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2038 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2039 height
- b
, width
, y_break
);
2041 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2042 height
- b
, width
, y_break
);
2043 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2049 if (dy
< y_break
&& dy
+ height
> y_break
) {
2051 if (dy
< sy
) { /* Avoid trashing self */
2052 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2054 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2055 height
- b
, width
, y_break
);
2057 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2058 height
- b
, width
, y_break
);
2059 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2064 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2068 static void updatescrollmode(struct display
*p
,
2069 struct fb_info
*info
,
2072 struct fbcon_ops
*ops
= info
->fbcon_par
;
2073 int fh
= vc
->vc_font
.height
;
2074 int cap
= info
->flags
;
2076 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2077 info
->fix
.xpanstep
);
2078 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2079 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2080 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2081 info
->var
.xres_virtual
);
2082 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2083 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2084 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2085 divides(ywrap
, vc
->vc_font
.height
) &&
2086 divides(vc
->vc_font
.height
, vyres
) &&
2087 divides(vc
->vc_font
.height
, yres
);
2088 int reading_fast
= cap
& FBINFO_READS_FAST
;
2089 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2090 !(cap
& FBINFO_HWACCEL_DISABLED
);
2091 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2092 !(cap
& FBINFO_HWACCEL_DISABLED
);
2094 p
->vrows
= vyres
/fh
;
2095 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2096 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2097 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2100 if (good_wrap
|| good_pan
) {
2101 if (reading_fast
|| fast_copyarea
)
2102 p
->scrollmode
= good_wrap
?
2103 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2105 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2108 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2109 p
->scrollmode
= SCROLL_MOVE
;
2111 p
->scrollmode
= SCROLL_REDRAW
;
2115 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2116 unsigned int height
, unsigned int user
)
2118 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2119 struct fbcon_ops
*ops
= info
->fbcon_par
;
2120 struct display
*p
= &fb_display
[vc
->vc_num
];
2121 struct fb_var_screeninfo var
= info
->var
;
2122 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2124 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2125 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2126 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2127 vc
->vc_font
.height
);
2128 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2130 var
.xres
= virt_w
* virt_fw
;
2131 var
.yres
= virt_h
* virt_fh
;
2132 x_diff
= info
->var
.xres
- var
.xres
;
2133 y_diff
= info
->var
.yres
- var
.yres
;
2134 if (x_diff
< 0 || x_diff
> virt_fw
||
2135 y_diff
< 0 || y_diff
> virt_fh
) {
2136 const struct fb_videomode
*mode
;
2138 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2139 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2142 display_to_var(&var
, p
);
2143 fb_videomode_to_var(&var
, mode
);
2145 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2148 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2149 if (con_is_visible(vc
)) {
2150 var
.activate
= FB_ACTIVATE_NOW
|
2152 fb_set_var(info
, &var
);
2154 var_to_display(p
, &info
->var
, info
);
2155 ops
->var
= info
->var
;
2157 updatescrollmode(p
, info
, vc
);
2161 static int fbcon_switch(struct vc_data
*vc
)
2163 struct fb_info
*info
, *old_info
= NULL
;
2164 struct fbcon_ops
*ops
;
2165 struct display
*p
= &fb_display
[vc
->vc_num
];
2166 struct fb_var_screeninfo var
;
2167 int i
, ret
, prev_console
, charcnt
= 256;
2169 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2170 ops
= info
->fbcon_par
;
2174 fbcon_set_origin(vc
);
2175 softback_top
= softback_curr
= softback_in
= softback_buf
;
2177 fbcon_update_softback(vc
);
2180 if (logo_shown
>= 0) {
2181 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2183 if (conp2
->vc_top
== logo_lines
2184 && conp2
->vc_bottom
== conp2
->vc_rows
)
2186 logo_shown
= FBCON_LOGO_CANSHOW
;
2189 prev_console
= ops
->currcon
;
2190 if (prev_console
!= -1)
2191 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2193 * FIXME: If we have multiple fbdev's loaded, we need to
2194 * update all info->currcon. Perhaps, we can place this
2195 * in a centralized structure, but this might break some
2198 * info->currcon = vc->vc_num;
2200 for (i
= 0; i
< FB_MAX
; i
++) {
2201 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2202 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2204 o
->currcon
= vc
->vc_num
;
2207 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2208 display_to_var(&var
, p
);
2209 var
.activate
= FB_ACTIVATE_NOW
;
2212 * make sure we don't unnecessarily trip the memcmp()
2215 info
->var
.activate
= var
.activate
;
2216 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2217 fb_set_var(info
, &var
);
2218 ops
->var
= info
->var
;
2220 if (old_info
!= NULL
&& (old_info
!= info
||
2221 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2222 if (info
->fbops
->fb_set_par
) {
2223 ret
= info
->fbops
->fb_set_par(info
);
2226 printk(KERN_ERR
"fbcon_switch: detected "
2227 "unhandled fb_set_par error, "
2228 "error code %d\n", ret
);
2231 if (old_info
!= info
)
2232 fbcon_del_cursor_timer(old_info
);
2235 if (fbcon_is_inactive(vc
, info
) ||
2236 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2237 fbcon_del_cursor_timer(info
);
2239 fbcon_add_cursor_timer(info
);
2241 set_blitting_type(vc
, info
);
2242 ops
->cursor_reset
= 1;
2244 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2245 ops
->rotate
= FB_ROTATE_UR
;
2246 set_blitting_type(vc
, info
);
2249 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2250 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2253 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2256 vc
->vc_complement_mask
<<= 1;
2258 updatescrollmode(p
, info
, vc
);
2260 switch (p
->scrollmode
) {
2261 case SCROLL_WRAP_MOVE
:
2262 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2264 case SCROLL_PAN_MOVE
:
2265 case SCROLL_PAN_REDRAW
:
2266 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2267 if (scrollback_phys_max
< 0)
2268 scrollback_phys_max
= 0;
2271 scrollback_phys_max
= 0;
2276 scrollback_current
= 0;
2278 if (!fbcon_is_inactive(vc
, info
)) {
2279 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2280 ops
->update_start(info
);
2283 fbcon_set_palette(vc
, color_table
);
2284 fbcon_clear_margins(vc
, 0);
2286 if (logo_shown
== FBCON_LOGO_DRAW
) {
2288 logo_shown
= fg_console
;
2289 /* This is protected above by initmem_freed */
2290 fb_show_logo(info
, ops
->rotate
);
2292 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2293 vc
->vc_size_row
* (vc
->vc_bottom
-
2300 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2303 struct fb_event event
;
2306 unsigned short charmask
= vc
->vc_hi_font_mask
?
2308 unsigned short oldc
;
2310 oldc
= vc
->vc_video_erase_char
;
2311 vc
->vc_video_erase_char
&= charmask
;
2312 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2313 vc
->vc_video_erase_char
= oldc
;
2317 if (!lock_fb_info(info
))
2320 event
.data
= &blank
;
2321 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2322 unlock_fb_info(info
);
2325 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2327 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2328 struct fbcon_ops
*ops
= info
->fbcon_par
;
2331 struct fb_var_screeninfo var
= info
->var
;
2336 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2337 fb_set_var(info
, &var
);
2339 ops
->var
= info
->var
;
2343 if (!fbcon_is_inactive(vc
, info
)) {
2344 if (ops
->blank_state
!= blank
) {
2345 ops
->blank_state
= blank
;
2346 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2347 ops
->cursor_flash
= (!blank
);
2349 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2350 if (fb_blank(info
, blank
))
2351 fbcon_generic_blank(vc
, info
, blank
);
2358 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2359 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2360 fbcon_del_cursor_timer(info
);
2362 fbcon_add_cursor_timer(info
);
2367 static int fbcon_debug_enter(struct vc_data
*vc
)
2369 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2370 struct fbcon_ops
*ops
= info
->fbcon_par
;
2372 ops
->save_graphics
= ops
->graphics
;
2374 if (info
->fbops
->fb_debug_enter
)
2375 info
->fbops
->fb_debug_enter(info
);
2376 fbcon_set_palette(vc
, color_table
);
2380 static int fbcon_debug_leave(struct vc_data
*vc
)
2382 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2383 struct fbcon_ops
*ops
= info
->fbcon_par
;
2385 ops
->graphics
= ops
->save_graphics
;
2386 if (info
->fbops
->fb_debug_leave
)
2387 info
->fbops
->fb_debug_leave(info
);
2391 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2393 u8
*fontdata
= vc
->vc_font
.data
;
2394 u8
*data
= font
->data
;
2397 font
->width
= vc
->vc_font
.width
;
2398 font
->height
= vc
->vc_font
.height
;
2399 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2403 if (font
->width
<= 8) {
2404 j
= vc
->vc_font
.height
;
2405 for (i
= 0; i
< font
->charcount
; i
++) {
2406 memcpy(data
, fontdata
, j
);
2407 memset(data
+ j
, 0, 32 - j
);
2411 } else if (font
->width
<= 16) {
2412 j
= vc
->vc_font
.height
* 2;
2413 for (i
= 0; i
< font
->charcount
; i
++) {
2414 memcpy(data
, fontdata
, j
);
2415 memset(data
+ j
, 0, 64 - j
);
2419 } else if (font
->width
<= 24) {
2420 for (i
= 0; i
< font
->charcount
; i
++) {
2421 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2422 *data
++ = fontdata
[0];
2423 *data
++ = fontdata
[1];
2424 *data
++ = fontdata
[2];
2425 fontdata
+= sizeof(u32
);
2427 memset(data
, 0, 3 * (32 - j
));
2428 data
+= 3 * (32 - j
);
2431 j
= vc
->vc_font
.height
* 4;
2432 for (i
= 0; i
< font
->charcount
; i
++) {
2433 memcpy(data
, fontdata
, j
);
2434 memset(data
+ j
, 0, 128 - j
);
2442 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2443 static void set_vc_hi_font(struct vc_data
*vc
, bool set
)
2446 vc
->vc_hi_font_mask
= 0;
2447 if (vc
->vc_can_do_color
) {
2448 vc
->vc_complement_mask
>>= 1;
2449 vc
->vc_s_complement_mask
>>= 1;
2452 /* ++Edmund: reorder the attribute bits */
2453 if (vc
->vc_can_do_color
) {
2454 unsigned short *cp
=
2455 (unsigned short *) vc
->vc_origin
;
2456 int count
= vc
->vc_screenbuf_size
/ 2;
2458 for (; count
> 0; count
--, cp
++) {
2460 scr_writew(((c
& 0xfe00) >> 1) |
2463 c
= vc
->vc_video_erase_char
;
2464 vc
->vc_video_erase_char
=
2465 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2469 vc
->vc_hi_font_mask
= 0x100;
2470 if (vc
->vc_can_do_color
) {
2471 vc
->vc_complement_mask
<<= 1;
2472 vc
->vc_s_complement_mask
<<= 1;
2475 /* ++Edmund: reorder the attribute bits */
2477 unsigned short *cp
=
2478 (unsigned short *) vc
->vc_origin
;
2479 int count
= vc
->vc_screenbuf_size
/ 2;
2481 for (; count
> 0; count
--, cp
++) {
2482 unsigned short newc
;
2484 if (vc
->vc_can_do_color
)
2486 ((c
& 0xff00) << 1) | (c
&
2490 scr_writew(newc
, cp
);
2492 c
= vc
->vc_video_erase_char
;
2493 if (vc
->vc_can_do_color
) {
2494 vc
->vc_video_erase_char
=
2495 ((c
& 0xff00) << 1) | (c
& 0xff);
2498 vc
->vc_video_erase_char
= c
& ~0x100;
2503 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2504 const u8
* data
, int userfont
)
2506 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2507 struct fbcon_ops
*ops
= info
->fbcon_par
;
2508 struct display
*p
= &fb_display
[vc
->vc_num
];
2511 char *old_data
= NULL
;
2513 if (con_is_visible(vc
) && softback_lines
)
2514 fbcon_set_origin(vc
);
2516 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2518 old_data
= vc
->vc_font
.data
;
2520 cnt
= FNTCHARCNT(data
);
2523 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2524 if ((p
->userfont
= userfont
))
2526 vc
->vc_font
.width
= w
;
2527 vc
->vc_font
.height
= h
;
2528 if (vc
->vc_hi_font_mask
&& cnt
== 256)
2529 set_vc_hi_font(vc
, false);
2530 else if (!vc
->vc_hi_font_mask
&& cnt
== 512)
2531 set_vc_hi_font(vc
, true);
2536 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2537 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2540 vc_resize(vc
, cols
, rows
);
2541 if (con_is_visible(vc
) && softback_buf
)
2542 fbcon_update_softback(vc
);
2543 } else if (con_is_visible(vc
)
2544 && vc
->vc_mode
== KD_TEXT
) {
2545 fbcon_clear_margins(vc
, 0);
2549 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2550 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2554 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2556 struct display
*od
= &fb_display
[con
];
2557 struct console_font
*f
= &vc
->vc_font
;
2559 if (od
->fontdata
== f
->data
)
2560 return 0; /* already the same font... */
2561 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2565 * User asked to set font; we are guaranteed that
2566 * a) width and height are in range 1..32
2567 * b) charcount does not exceed 512
2568 * but lets not assume that, since someone might someday want to use larger
2569 * fonts. And charcount of 512 is small for unicode support.
2571 * However, user space gives the font in 32 rows , regardless of
2572 * actual font height. So a new API is needed if support for larger fonts
2573 * is ever implemented.
2576 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2578 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2579 unsigned charcount
= font
->charcount
;
2580 int w
= font
->width
;
2581 int h
= font
->height
;
2584 u8
*new_data
, *data
= font
->data
;
2585 int pitch
= (font
->width
+7) >> 3;
2587 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2588 * If not this check should be changed to charcount < 256 */
2589 if (charcount
!= 256 && charcount
!= 512)
2592 /* Make sure drawing engine can handle the font */
2593 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2594 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2597 /* Make sure driver can handle the font length */
2598 if (fbcon_invalid_charcount(info
, charcount
))
2601 size
= h
* pitch
* charcount
;
2603 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2608 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2609 FNTSIZE(new_data
) = size
;
2610 FNTCHARCNT(new_data
) = charcount
;
2611 REFCOUNT(new_data
) = 0; /* usage counter */
2612 for (i
=0; i
< charcount
; i
++) {
2613 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2616 /* Since linux has a nice crc32 function use it for counting font
2618 csum
= crc32(0, new_data
, size
);
2620 FNTSUM(new_data
) = csum
;
2621 /* Check if the same font is on some other console already */
2622 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2623 struct vc_data
*tmp
= vc_cons
[i
].d
;
2625 if (fb_display
[i
].userfont
&&
2626 fb_display
[i
].fontdata
&&
2627 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2628 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2629 tmp
->vc_font
.width
== w
&&
2630 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2631 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2632 new_data
= (u8
*)fb_display
[i
].fontdata
;
2636 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2639 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2641 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2642 const struct font_desc
*f
;
2645 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2646 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2647 else if (!(f
= find_font(name
)))
2650 font
->width
= f
->width
;
2651 font
->height
= f
->height
;
2652 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2655 static u16 palette_red
[16];
2656 static u16 palette_green
[16];
2657 static u16 palette_blue
[16];
2659 static struct fb_cmap palette_cmap
= {
2660 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2663 static void fbcon_set_palette(struct vc_data
*vc
, const unsigned char *table
)
2665 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2669 if (fbcon_is_inactive(vc
, info
))
2672 if (!con_is_visible(vc
))
2675 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2677 for (i
= j
= 0; i
< 16; i
++) {
2679 val
= vc
->vc_palette
[j
++];
2680 palette_red
[k
] = (val
<< 8) | val
;
2681 val
= vc
->vc_palette
[j
++];
2682 palette_green
[k
] = (val
<< 8) | val
;
2683 val
= vc
->vc_palette
[j
++];
2684 palette_blue
[k
] = (val
<< 8) | val
;
2686 palette_cmap
.len
= 16;
2687 palette_cmap
.start
= 0;
2689 * If framebuffer is capable of less than 16 colors,
2690 * use default palette of fbcon.
2693 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2695 fb_set_cmap(&palette_cmap
, info
);
2698 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2703 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2704 return (u16
*) (vc
->vc_origin
+ offset
);
2705 line
= offset
/ vc
->vc_size_row
;
2706 if (line
>= softback_lines
)
2707 return (u16
*) (vc
->vc_origin
+ offset
-
2708 softback_lines
* vc
->vc_size_row
);
2709 p
= softback_curr
+ offset
;
2710 if (p
>= softback_end
)
2711 p
+= softback_buf
- softback_end
;
2715 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2721 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2722 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2724 x
= offset
% vc
->vc_cols
;
2725 y
= offset
/ vc
->vc_cols
;
2726 if (vc
->vc_num
== fg_console
)
2727 y
+= softback_lines
;
2728 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2729 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2730 unsigned long offset
= pos
- softback_curr
;
2732 if (pos
< softback_curr
)
2733 offset
+= softback_end
- softback_buf
;
2735 x
= offset
% vc
->vc_cols
;
2736 y
= offset
/ vc
->vc_cols
;
2737 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2738 if (ret
== softback_end
)
2740 if (ret
== softback_in
)
2741 ret
= vc
->vc_origin
;
2743 /* Should not happen */
2745 ret
= vc
->vc_origin
;
2754 /* As we might be inside of softback, we may work with non-contiguous buffer,
2755 that's why we have to use a separate routine. */
2756 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2759 u16 a
= scr_readw(p
);
2760 if (!vc
->vc_can_do_color
)
2762 else if (vc
->vc_hi_font_mask
== 0x100)
2763 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2764 (((a
) & 0x0e00) << 4);
2766 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2767 (((a
) & 0x0700) << 4);
2769 if (p
== (u16
*) softback_end
)
2770 p
= (u16
*) softback_buf
;
2771 if (p
== (u16
*) softback_in
)
2772 p
= (u16
*) vc
->vc_origin
;
2776 static void fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2778 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2779 struct fbcon_ops
*ops
= info
->fbcon_par
;
2780 struct display
*disp
= &fb_display
[fg_console
];
2781 int offset
, limit
, scrollback_old
;
2784 if (vc
->vc_num
!= fg_console
)
2786 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2788 if (logo_shown
>= 0) {
2789 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2791 if (conp2
->vc_top
== logo_lines
2792 && conp2
->vc_bottom
== conp2
->vc_rows
)
2794 if (logo_shown
== vc
->vc_num
) {
2800 logo_lines
* vc
->vc_size_row
;
2801 for (i
= 0; i
< logo_lines
; i
++) {
2802 if (p
== softback_top
)
2804 if (p
== softback_buf
)
2806 p
-= vc
->vc_size_row
;
2807 q
-= vc
->vc_size_row
;
2808 scr_memcpyw((u16
*) q
, (u16
*) p
,
2811 softback_in
= softback_curr
= p
;
2812 update_region(vc
, vc
->vc_origin
,
2813 logo_lines
* vc
->vc_cols
);
2815 logo_shown
= FBCON_LOGO_CANSHOW
;
2817 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2818 fbcon_redraw_softback(vc
, disp
, lines
);
2819 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2823 if (!scrollback_phys_max
)
2826 scrollback_old
= scrollback_current
;
2827 scrollback_current
-= lines
;
2828 if (scrollback_current
< 0)
2829 scrollback_current
= 0;
2830 else if (scrollback_current
> scrollback_max
)
2831 scrollback_current
= scrollback_max
;
2832 if (scrollback_current
== scrollback_old
)
2835 if (fbcon_is_inactive(vc
, info
))
2838 fbcon_cursor(vc
, CM_ERASE
);
2840 offset
= disp
->yscroll
- scrollback_current
;
2841 limit
= disp
->vrows
;
2842 switch (disp
->scrollmode
) {
2843 case SCROLL_WRAP_MOVE
:
2844 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2846 case SCROLL_PAN_MOVE
:
2847 case SCROLL_PAN_REDRAW
:
2848 limit
-= vc
->vc_rows
;
2849 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2854 else if (offset
>= limit
)
2857 ops
->var
.xoffset
= 0;
2858 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2859 ops
->update_start(info
);
2861 if (!scrollback_current
)
2862 fbcon_cursor(vc
, CM_DRAW
);
2865 static int fbcon_set_origin(struct vc_data
*vc
)
2868 fbcon_scrolldelta(vc
, softback_lines
);
2872 static void fbcon_suspended(struct fb_info
*info
)
2874 struct vc_data
*vc
= NULL
;
2875 struct fbcon_ops
*ops
= info
->fbcon_par
;
2877 if (!ops
|| ops
->currcon
< 0)
2879 vc
= vc_cons
[ops
->currcon
].d
;
2881 /* Clear cursor, restore saved data */
2882 fbcon_cursor(vc
, CM_ERASE
);
2885 static void fbcon_resumed(struct fb_info
*info
)
2888 struct fbcon_ops
*ops
= info
->fbcon_par
;
2890 if (!ops
|| ops
->currcon
< 0)
2892 vc
= vc_cons
[ops
->currcon
].d
;
2897 static void fbcon_modechanged(struct fb_info
*info
)
2899 struct fbcon_ops
*ops
= info
->fbcon_par
;
2904 if (!ops
|| ops
->currcon
< 0)
2906 vc
= vc_cons
[ops
->currcon
].d
;
2907 if (vc
->vc_mode
!= KD_TEXT
||
2908 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2911 p
= &fb_display
[vc
->vc_num
];
2912 set_blitting_type(vc
, info
);
2914 if (con_is_visible(vc
)) {
2915 var_to_display(p
, &info
->var
, info
);
2916 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2917 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2918 cols
/= vc
->vc_font
.width
;
2919 rows
/= vc
->vc_font
.height
;
2920 vc_resize(vc
, cols
, rows
);
2921 updatescrollmode(p
, info
, vc
);
2923 scrollback_current
= 0;
2925 if (!fbcon_is_inactive(vc
, info
)) {
2926 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2927 ops
->update_start(info
);
2930 fbcon_set_palette(vc
, color_table
);
2933 fbcon_update_softback(vc
);
2937 static void fbcon_set_all_vcs(struct fb_info
*info
)
2939 struct fbcon_ops
*ops
= info
->fbcon_par
;
2942 int i
, rows
, cols
, fg
= -1;
2944 if (!ops
|| ops
->currcon
< 0)
2947 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2949 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2950 registered_fb
[con2fb_map
[i
]] != info
)
2953 if (con_is_visible(vc
)) {
2958 p
= &fb_display
[vc
->vc_num
];
2959 set_blitting_type(vc
, info
);
2960 var_to_display(p
, &info
->var
, info
);
2961 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2962 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2963 cols
/= vc
->vc_font
.width
;
2964 rows
/= vc
->vc_font
.height
;
2965 vc_resize(vc
, cols
, rows
);
2969 fbcon_modechanged(info
);
2972 static int fbcon_mode_deleted(struct fb_info
*info
,
2973 struct fb_videomode
*mode
)
2975 struct fb_info
*fb_info
;
2977 int i
, j
, found
= 0;
2979 /* before deletion, ensure that mode is not in use */
2980 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2984 fb_info
= registered_fb
[j
];
2985 if (fb_info
!= info
)
2990 if (fb_mode_is_equal(p
->mode
, mode
)) {
2998 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2999 static int fbcon_unbind(void)
3003 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3007 fbcon_has_console_bind
= 0;
3012 static inline int fbcon_unbind(void)
3016 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3018 /* called with console_lock held */
3019 static int fbcon_fb_unbind(int idx
)
3021 int i
, new_idx
= -1, ret
= 0;
3023 if (!fbcon_has_console_bind
)
3026 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3027 if (con2fb_map
[i
] != idx
&&
3028 con2fb_map
[i
] != -1) {
3034 if (new_idx
!= -1) {
3035 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3036 if (con2fb_map
[i
] == idx
)
3037 set_con2fb_map(i
, new_idx
, 0);
3040 struct fb_info
*info
= registered_fb
[idx
];
3042 /* This is sort of like set_con2fb_map, except it maps
3043 * the consoles to no device and then releases the
3044 * oldinfo to free memory and cancel the cursor blink
3045 * timer. I can imagine this just becoming part of
3046 * set_con2fb_map where new_idx is -1
3048 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3049 if (con2fb_map
[i
] == idx
) {
3051 if (!search_fb_in_map(idx
)) {
3052 ret
= con2fb_release_oldinfo(vc_cons
[i
].d
,
3056 con2fb_map
[i
] = idx
;
3062 ret
= fbcon_unbind();
3068 /* called with console_lock held */
3069 static int fbcon_fb_unregistered(struct fb_info
*info
)
3074 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3075 if (con2fb_map
[i
] == idx
)
3079 if (idx
== info_idx
) {
3082 for (i
= 0; i
< FB_MAX
; i
++) {
3083 if (registered_fb
[i
] != NULL
) {
3090 if (info_idx
!= -1) {
3091 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3092 if (con2fb_map
[i
] == -1)
3093 con2fb_map
[i
] = info_idx
;
3097 if (primary_device
== idx
)
3098 primary_device
= -1;
3100 if (!num_registered_fb
)
3101 do_unregister_con_driver(&fb_con
);
3106 /* called with console_lock held */
3107 static void fbcon_remap_all(int idx
)
3110 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3111 set_con2fb_map(i
, idx
, 0);
3113 if (con_is_bound(&fb_con
)) {
3114 printk(KERN_INFO
"fbcon: Remapping primary device, "
3115 "fb%i, to tty %i-%i\n", idx
,
3116 first_fb_vc
+ 1, last_fb_vc
+ 1);
3121 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3122 static void fbcon_select_primary(struct fb_info
*info
)
3124 if (!map_override
&& primary_device
== -1 &&
3125 fb_is_primary_device(info
)) {
3128 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3129 info
->fix
.id
, info
->node
);
3130 primary_device
= info
->node
;
3132 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3133 con2fb_map_boot
[i
] = primary_device
;
3135 if (con_is_bound(&fb_con
)) {
3136 printk(KERN_INFO
"fbcon: Remapping primary device, "
3137 "fb%i, to tty %i-%i\n", info
->node
,
3138 first_fb_vc
+ 1, last_fb_vc
+ 1);
3139 info_idx
= primary_device
;
3145 static inline void fbcon_select_primary(struct fb_info
*info
)
3149 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3151 /* called with console_lock held */
3152 static int fbcon_fb_registered(struct fb_info
*info
)
3154 int ret
= 0, i
, idx
;
3157 fbcon_select_primary(info
);
3159 if (info_idx
== -1) {
3160 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3161 if (con2fb_map_boot
[i
] == idx
) {
3168 ret
= do_fbcon_takeover(1);
3170 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3171 if (con2fb_map_boot
[i
] == idx
)
3172 set_con2fb_map(i
, idx
, 0);
3179 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3181 struct fbcon_ops
*ops
= info
->fbcon_par
;
3184 if (!ops
|| ops
->currcon
< 0)
3187 vc
= vc_cons
[ops
->currcon
].d
;
3188 if (vc
->vc_mode
!= KD_TEXT
||
3189 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3192 if (con_is_visible(vc
)) {
3196 do_unblank_screen(0);
3198 ops
->blank_state
= blank
;
3201 static void fbcon_new_modelist(struct fb_info
*info
)
3205 struct fb_var_screeninfo var
;
3206 const struct fb_videomode
*mode
;
3208 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3209 if (registered_fb
[con2fb_map
[i
]] != info
)
3211 if (!fb_display
[i
].mode
)
3214 display_to_var(&var
, &fb_display
[i
]);
3215 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3217 fb_videomode_to_var(&var
, mode
);
3218 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3222 static void fbcon_get_requirement(struct fb_info
*info
,
3223 struct fb_blit_caps
*caps
)
3231 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3233 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3234 info
->node
== con2fb_map
[i
]) {
3236 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3237 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3238 charcnt
= (p
->userfont
) ?
3239 FNTCHARCNT(p
->fontdata
) : 256;
3240 if (caps
->len
< charcnt
)
3241 caps
->len
= charcnt
;
3245 vc
= vc_cons
[fg_console
].d
;
3247 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3248 info
->node
== con2fb_map
[fg_console
]) {
3249 p
= &fb_display
[fg_console
];
3250 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3251 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3252 caps
->len
= (p
->userfont
) ?
3253 FNTCHARCNT(p
->fontdata
) : 256;
3258 static int fbcon_event_notify(struct notifier_block
*self
,
3259 unsigned long action
, void *data
)
3261 struct fb_event
*event
= data
;
3262 struct fb_info
*info
= event
->info
;
3263 struct fb_videomode
*mode
;
3264 struct fb_con2fbmap
*con2fb
;
3265 struct fb_blit_caps
*caps
;
3269 * ignore all events except driver registration and deregistration
3270 * if fbcon is not active
3272 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3273 action
== FB_EVENT_FB_UNREGISTERED
))
3277 case FB_EVENT_SUSPEND
:
3278 fbcon_suspended(info
);
3280 case FB_EVENT_RESUME
:
3281 fbcon_resumed(info
);
3283 case FB_EVENT_MODE_CHANGE
:
3284 fbcon_modechanged(info
);
3286 case FB_EVENT_MODE_CHANGE_ALL
:
3287 fbcon_set_all_vcs(info
);
3289 case FB_EVENT_MODE_DELETE
:
3291 ret
= fbcon_mode_deleted(info
, mode
);
3293 case FB_EVENT_FB_UNBIND
:
3295 ret
= fbcon_fb_unbind(idx
);
3297 case FB_EVENT_FB_REGISTERED
:
3298 ret
= fbcon_fb_registered(info
);
3300 case FB_EVENT_FB_UNREGISTERED
:
3301 ret
= fbcon_fb_unregistered(info
);
3303 case FB_EVENT_SET_CONSOLE_MAP
:
3304 /* called with console lock held */
3305 con2fb
= event
->data
;
3306 ret
= set_con2fb_map(con2fb
->console
- 1,
3307 con2fb
->framebuffer
, 1);
3309 case FB_EVENT_GET_CONSOLE_MAP
:
3310 con2fb
= event
->data
;
3311 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3313 case FB_EVENT_BLANK
:
3314 fbcon_fb_blanked(info
, *(int *)event
->data
);
3316 case FB_EVENT_NEW_MODELIST
:
3317 fbcon_new_modelist(info
);
3319 case FB_EVENT_GET_REQ
:
3321 fbcon_get_requirement(info
, caps
);
3323 case FB_EVENT_REMAP_ALL_CONSOLE
:
3325 fbcon_remap_all(idx
);
3333 * The console `switch' structure for the frame buffer based console
3336 static const struct consw fb_con
= {
3337 .owner
= THIS_MODULE
,
3338 .con_startup
= fbcon_startup
,
3339 .con_init
= fbcon_init
,
3340 .con_deinit
= fbcon_deinit
,
3341 .con_clear
= fbcon_clear
,
3342 .con_putc
= fbcon_putc
,
3343 .con_putcs
= fbcon_putcs
,
3344 .con_cursor
= fbcon_cursor
,
3345 .con_scroll
= fbcon_scroll
,
3346 .con_switch
= fbcon_switch
,
3347 .con_blank
= fbcon_blank
,
3348 .con_font_set
= fbcon_set_font
,
3349 .con_font_get
= fbcon_get_font
,
3350 .con_font_default
= fbcon_set_def_font
,
3351 .con_font_copy
= fbcon_copy_font
,
3352 .con_set_palette
= fbcon_set_palette
,
3353 .con_scrolldelta
= fbcon_scrolldelta
,
3354 .con_set_origin
= fbcon_set_origin
,
3355 .con_invert_region
= fbcon_invert_region
,
3356 .con_screen_pos
= fbcon_screen_pos
,
3357 .con_getxy
= fbcon_getxy
,
3358 .con_resize
= fbcon_resize
,
3359 .con_debug_enter
= fbcon_debug_enter
,
3360 .con_debug_leave
= fbcon_debug_leave
,
3363 static struct notifier_block fbcon_event_notifier
= {
3364 .notifier_call
= fbcon_event_notify
,
3367 static ssize_t
store_rotate(struct device
*device
,
3368 struct device_attribute
*attr
, const char *buf
,
3371 struct fb_info
*info
;
3375 if (fbcon_has_exited
)
3379 idx
= con2fb_map
[fg_console
];
3381 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3384 info
= registered_fb
[idx
];
3385 rotate
= simple_strtoul(buf
, last
, 0);
3386 fbcon_rotate(info
, rotate
);
3392 static ssize_t
store_rotate_all(struct device
*device
,
3393 struct device_attribute
*attr
,const char *buf
,
3396 struct fb_info
*info
;
3400 if (fbcon_has_exited
)
3404 idx
= con2fb_map
[fg_console
];
3406 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3409 info
= registered_fb
[idx
];
3410 rotate
= simple_strtoul(buf
, last
, 0);
3411 fbcon_rotate_all(info
, rotate
);
3417 static ssize_t
show_rotate(struct device
*device
,
3418 struct device_attribute
*attr
,char *buf
)
3420 struct fb_info
*info
;
3421 int rotate
= 0, idx
;
3423 if (fbcon_has_exited
)
3427 idx
= con2fb_map
[fg_console
];
3429 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3432 info
= registered_fb
[idx
];
3433 rotate
= fbcon_get_rotate(info
);
3436 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3439 static ssize_t
show_cursor_blink(struct device
*device
,
3440 struct device_attribute
*attr
, char *buf
)
3442 struct fb_info
*info
;
3443 struct fbcon_ops
*ops
;
3444 int idx
, blink
= -1;
3446 if (fbcon_has_exited
)
3450 idx
= con2fb_map
[fg_console
];
3452 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3455 info
= registered_fb
[idx
];
3456 ops
= info
->fbcon_par
;
3461 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3464 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3467 static ssize_t
store_cursor_blink(struct device
*device
,
3468 struct device_attribute
*attr
,
3469 const char *buf
, size_t count
)
3471 struct fb_info
*info
;
3475 if (fbcon_has_exited
)
3479 idx
= con2fb_map
[fg_console
];
3481 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3484 info
= registered_fb
[idx
];
3486 if (!info
->fbcon_par
)
3489 blink
= simple_strtoul(buf
, last
, 0);
3492 fbcon_cursor_noblink
= 0;
3493 fbcon_add_cursor_timer(info
);
3495 fbcon_cursor_noblink
= 1;
3496 fbcon_del_cursor_timer(info
);
3504 static struct device_attribute device_attrs
[] = {
3505 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3506 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3507 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3508 store_cursor_blink
),
3511 static int fbcon_init_device(void)
3515 fbcon_has_sysfs
= 1;
3517 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3518 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3526 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3528 fbcon_has_sysfs
= 0;
3534 static void fbcon_start(void)
3536 if (num_registered_fb
) {
3541 for (i
= 0; i
< FB_MAX
; i
++) {
3542 if (registered_fb
[i
] != NULL
) {
3548 do_fbcon_takeover(0);
3554 static void fbcon_exit(void)
3556 struct fb_info
*info
;
3559 if (fbcon_has_exited
)
3562 kfree((void *)softback_buf
);
3565 for (i
= 0; i
< FB_MAX
; i
++) {
3569 info
= registered_fb
[i
];
3574 if (info
->queue
.func
)
3575 pending
= cancel_work_sync(&info
->queue
);
3576 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3579 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3580 if (con2fb_map
[j
] == i
) {
3587 if (info
->fbops
->fb_release
)
3588 info
->fbops
->fb_release(info
, 0);
3589 module_put(info
->fbops
->owner
);
3591 if (info
->fbcon_par
) {
3592 struct fbcon_ops
*ops
= info
->fbcon_par
;
3594 fbcon_del_cursor_timer(info
);
3595 kfree(ops
->cursor_src
);
3596 kfree(ops
->cursor_state
.mask
);
3597 kfree(info
->fbcon_par
);
3598 info
->fbcon_par
= NULL
;
3601 if (info
->queue
.func
== fb_flashcursor
)
3602 info
->queue
.func
= NULL
;
3606 fbcon_has_exited
= 1;
3609 static int __init
fb_console_init(void)
3614 fb_register_client(&fbcon_event_notifier
);
3615 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3618 if (IS_ERR(fbcon_device
)) {
3619 printk(KERN_WARNING
"Unable to create device "
3620 "for fbcon; errno = %ld\n",
3621 PTR_ERR(fbcon_device
));
3622 fbcon_device
= NULL
;
3624 fbcon_init_device();
3626 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3634 fs_initcall(fb_console_init
);
3638 static void __exit
fbcon_deinit_device(void)
3642 if (fbcon_has_sysfs
) {
3643 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3644 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3646 fbcon_has_sysfs
= 0;
3650 static void __exit
fb_console_exit(void)
3653 fb_unregister_client(&fbcon_event_notifier
);
3654 fbcon_deinit_device();
3655 device_destroy(fb_class
, MKDEV(0, 0));
3657 do_unregister_con_driver(&fb_con
);
3661 module_exit(fb_console_exit
);
3665 MODULE_LICENSE("GPL");