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 */
80 #include <asm/system.h>
81 #include <asm/uaccess.h>
83 #include <asm/atariints.h>
86 #include <asm/macints.h>
88 #if defined(__mc68000__) || defined(CONFIG_APUS)
89 #include <asm/machdep.h>
90 #include <asm/setup.h>
96 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
98 # define DPRINTK(fmt, args...)
102 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
103 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
104 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
107 static struct display fb_display
[MAX_NR_CONSOLES
];
109 static signed char con2fb_map
[MAX_NR_CONSOLES
];
110 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
112 static int logo_height
;
114 static int logo_lines
;
115 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
117 static int logo_shown
= FBCON_LOGO_CANSHOW
;
118 /* Software scrollback */
119 static int fbcon_softback_size
= 32768;
120 static unsigned long softback_buf
, softback_curr
;
121 static unsigned long softback_in
;
122 static unsigned long softback_top
, softback_end
;
123 static int softback_lines
;
124 /* console mappings */
125 static int first_fb_vc
;
126 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
127 static int fbcon_is_default
= 1;
128 static int fbcon_has_exited
;
129 static int primary_device
= -1;
131 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
132 static int map_override
;
134 static inline void fbcon_map_override(void)
139 static inline void fbcon_map_override(void)
142 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
145 static char fontname
[40];
147 /* current fb_info */
148 static int info_idx
= -1;
150 /* console rotation */
152 static int fbcon_has_sysfs
;
154 static const struct consw fb_con
;
156 #define CM_SOFTBACK (8)
158 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
160 static int fbcon_set_origin(struct vc_data
*);
162 #define CURSOR_DRAW_DELAY (1)
164 /* # VBL ints between cursor state changes */
165 #define ATARI_CURSOR_BLINK_RATE (42)
166 #define MAC_CURSOR_BLINK_RATE (32)
167 #define DEFAULT_CURSOR_BLINK_RATE (20)
169 static int vbl_cursor_cnt
;
170 static int fbcon_cursor_noblink
;
172 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
175 * Interface used by the world
178 static const char *fbcon_startup(void);
179 static void fbcon_init(struct vc_data
*vc
, int init
);
180 static void fbcon_deinit(struct vc_data
*vc
);
181 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
183 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
184 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
185 int count
, int ypos
, int xpos
);
186 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
187 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
188 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
190 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
191 int height
, int width
);
192 static int fbcon_switch(struct vc_data
*vc
);
193 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
194 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
195 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
200 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
201 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
202 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
203 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
204 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
205 int dy
, int dx
, int height
, int width
, u_int y_break
);
206 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
208 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
209 int line
, int count
, int dy
);
210 static void fbcon_modechanged(struct fb_info
*info
);
211 static void fbcon_set_all_vcs(struct fb_info
*info
);
212 static void fbcon_start(void);
213 static void fbcon_exit(void);
214 static struct device
*fbcon_device
;
218 * On the Macintoy, there may or may not be a working VBL int. We need to probe
220 static int vbl_detected
;
222 static irqreturn_t
fb_vbl_detect(int irq
, void *dummy
)
229 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
230 static inline void fbcon_set_rotation(struct fb_info
*info
)
232 struct fbcon_ops
*ops
= info
->fbcon_par
;
234 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
235 ops
->p
->con_rotate
< 4)
236 ops
->rotate
= ops
->p
->con_rotate
;
241 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
243 struct fbcon_ops
*ops
= info
->fbcon_par
;
244 struct fb_info
*fb_info
;
246 if (!ops
|| ops
->currcon
== -1)
249 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
251 if (info
== fb_info
) {
252 struct display
*p
= &fb_display
[ops
->currcon
];
255 p
->con_rotate
= rotate
;
259 fbcon_modechanged(info
);
263 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
265 struct fbcon_ops
*ops
= info
->fbcon_par
;
270 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
273 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
275 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
276 registered_fb
[con2fb_map
[i
]] != info
)
279 p
= &fb_display
[vc
->vc_num
];
280 p
->con_rotate
= rotate
;
283 fbcon_set_all_vcs(info
);
286 static inline void fbcon_set_rotation(struct fb_info
*info
)
288 struct fbcon_ops
*ops
= info
->fbcon_par
;
290 ops
->rotate
= FB_ROTATE_UR
;
293 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
298 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
302 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
304 static int fbcon_get_rotate(struct fb_info
*info
)
306 struct fbcon_ops
*ops
= info
->fbcon_par
;
308 return (ops
) ? ops
->rotate
: 0;
311 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
313 struct fbcon_ops
*ops
= info
->fbcon_par
;
315 return (info
->state
!= FBINFO_STATE_RUNNING
||
316 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
319 static inline int get_color(struct vc_data
*vc
, struct fb_info
*info
,
322 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
325 if (console_blanked
) {
326 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
328 c
= vc
->vc_video_erase_char
& charmask
;
332 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
333 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
338 int col
= ~(0xfff << (max(info
->var
.green
.length
,
339 max(info
->var
.red
.length
,
340 info
->var
.blue
.length
)))) & 0xff;
343 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
344 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
349 color
= (is_fg
) ? fg
: bg
;
354 * Scale down 16-colors to 4 colors. Default 4-color palette
355 * is grayscale. However, simply dividing the values by 4
356 * will not work, as colors 1, 2 and 3 will be scaled-down
357 * to zero rendering them invisible. So empirically convert
358 * colors to a sane 4-level grayscale.
362 color
= 0; /* black */
365 color
= 2; /* white */
368 color
= 1; /* gray */
371 color
= 3; /* intense white */
377 * Last 8 entries of default 16-color palette is a more intense
378 * version of the first 8 (i.e., same chrominance, different
389 static void fbcon_update_softback(struct vc_data
*vc
)
391 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
394 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
396 /* Smaller scrollback makes no sense, and 0 would screw
397 the operation totally */
401 static void fb_flashcursor(struct work_struct
*work
)
403 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
404 struct fbcon_ops
*ops
= info
->fbcon_par
;
406 struct vc_data
*vc
= NULL
;
410 acquire_console_sem();
411 if (ops
&& ops
->currcon
!= -1)
412 vc
= vc_cons
[ops
->currcon
].d
;
414 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
415 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
417 release_console_sem();
421 p
= &fb_display
[vc
->vc_num
];
422 c
= scr_readw((u16
*) vc
->vc_pos
);
423 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
425 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
426 get_color(vc
, info
, c
, 0));
427 release_console_sem();
430 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
431 static int cursor_blink_rate
;
432 static irqreturn_t
fb_vbl_handler(int irq
, void *dev_id
)
434 struct fb_info
*info
= dev_id
;
436 if (vbl_cursor_cnt
&& --vbl_cursor_cnt
== 0) {
437 schedule_work(&info
->queue
);
438 vbl_cursor_cnt
= cursor_blink_rate
;
444 static void cursor_timer_handler(unsigned long dev_addr
)
446 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
447 struct fbcon_ops
*ops
= info
->fbcon_par
;
449 schedule_work(&info
->queue
);
450 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
453 static void fbcon_add_cursor_timer(struct fb_info
*info
)
455 struct fbcon_ops
*ops
= info
->fbcon_par
;
457 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
458 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
459 !fbcon_cursor_noblink
) {
460 if (!info
->queue
.func
)
461 INIT_WORK(&info
->queue
, fb_flashcursor
);
463 init_timer(&ops
->cursor_timer
);
464 ops
->cursor_timer
.function
= cursor_timer_handler
;
465 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
466 ops
->cursor_timer
.data
= (unsigned long ) info
;
467 add_timer(&ops
->cursor_timer
);
468 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
472 static void fbcon_del_cursor_timer(struct fb_info
*info
)
474 struct fbcon_ops
*ops
= info
->fbcon_par
;
476 if (info
->queue
.func
== fb_flashcursor
&&
477 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
478 del_timer_sync(&ops
->cursor_timer
);
479 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
484 static int __init
fb_console_setup(char *this_opt
)
489 if (!this_opt
|| !*this_opt
)
492 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
493 if (!strncmp(options
, "font:", 5))
494 strcpy(fontname
, options
+ 5);
496 if (!strncmp(options
, "scrollback:", 11)) {
499 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
500 if (*options
== 'k' || *options
== 'K') {
501 fbcon_softback_size
*= 1024;
511 if (!strncmp(options
, "map:", 4)) {
514 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
518 (options
[j
++]-'0') % FB_MAX
;
521 fbcon_map_override();
527 if (!strncmp(options
, "vc:", 3)) {
530 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
533 if (*options
++ == '-')
534 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
535 fbcon_is_default
= 0;
538 if (!strncmp(options
, "rotate:", 7)) {
541 rotate
= simple_strtoul(options
, &options
, 0);
549 __setup("fbcon=", fb_console_setup
);
552 static int search_fb_in_map(int idx
)
556 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
557 if (con2fb_map
[i
] == idx
)
563 static int search_for_mapped_con(void)
567 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
568 if (con2fb_map
[i
] != -1)
574 static int fbcon_takeover(int show_logo
)
578 if (!num_registered_fb
)
582 logo_shown
= FBCON_LOGO_DONTSHOW
;
584 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
585 con2fb_map
[i
] = info_idx
;
587 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
591 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
601 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
602 int cols
, int rows
, int new_cols
, int new_rows
)
604 logo_shown
= FBCON_LOGO_DONTSHOW
;
607 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
608 int cols
, int rows
, int new_cols
, int new_rows
)
610 /* Need to make room for the logo */
611 struct fbcon_ops
*ops
= info
->fbcon_par
;
612 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
613 unsigned short *save
= NULL
, *r
, *q
;
615 if (info
->flags
& FBINFO_MODULE
) {
616 logo_shown
= FBCON_LOGO_DONTSHOW
;
621 * remove underline attribute from erase character
622 * if black and white framebuffer.
624 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
626 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
627 logo_lines
= (logo_height
+ vc
->vc_font
.height
- 1) /
629 q
= (unsigned short *) (vc
->vc_origin
+
630 vc
->vc_size_row
* rows
);
631 step
= logo_lines
* cols
;
632 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
633 if (scr_readw(r
) != vc
->vc_video_erase_char
)
635 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
636 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
638 int i
= cols
< new_cols
? cols
: new_cols
;
639 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
641 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
642 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
647 /* We can scroll screen down */
649 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
650 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
655 if (vc
->vc_y
+ logo_lines
>= rows
)
656 lines
= rows
- vc
->vc_y
- 1;
660 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
663 scr_memsetw((unsigned short *) vc
->vc_origin
,
665 vc
->vc_size_row
* logo_lines
);
667 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
668 fbcon_clear_margins(vc
, 0);
673 q
= (unsigned short *) (vc
->vc_origin
+
676 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
677 vc
->vc_y
+= logo_lines
;
678 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
682 if (logo_lines
> vc
->vc_bottom
) {
683 logo_shown
= FBCON_LOGO_CANSHOW
;
685 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
686 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
687 logo_shown
= FBCON_LOGO_DRAW
;
688 vc
->vc_top
= logo_lines
;
693 #ifdef CONFIG_FB_TILEBLITTING
694 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
696 struct fbcon_ops
*ops
= info
->fbcon_par
;
698 ops
->p
= &fb_display
[vc
->vc_num
];
700 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
701 fbcon_set_tileops(vc
, info
);
703 fbcon_set_rotation(info
);
704 fbcon_set_bitops(ops
);
708 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
712 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
713 info
->tileops
->fb_get_tilemax(info
) < charcount
)
719 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
721 struct fbcon_ops
*ops
= info
->fbcon_par
;
723 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
724 ops
->p
= &fb_display
[vc
->vc_num
];
725 fbcon_set_rotation(info
);
726 fbcon_set_bitops(ops
);
729 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
734 #endif /* CONFIG_MISC_TILEBLITTING */
737 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
738 int unit
, int oldidx
)
740 struct fbcon_ops
*ops
= NULL
;
743 if (!try_module_get(info
->fbops
->owner
))
746 if (!err
&& info
->fbops
->fb_open
&&
747 info
->fbops
->fb_open(info
, 0))
751 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
757 info
->fbcon_par
= ops
;
760 set_blitting_type(vc
, info
);
764 con2fb_map
[unit
] = oldidx
;
765 module_put(info
->fbops
->owner
);
771 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
772 struct fb_info
*newinfo
, int unit
,
773 int oldidx
, int found
)
775 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
778 if (oldinfo
->fbops
->fb_release
&&
779 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
780 con2fb_map
[unit
] = oldidx
;
781 if (!found
&& newinfo
->fbops
->fb_release
)
782 newinfo
->fbops
->fb_release(newinfo
, 0);
784 module_put(newinfo
->fbops
->owner
);
789 fbcon_del_cursor_timer(oldinfo
);
790 kfree(ops
->cursor_state
.mask
);
791 kfree(ops
->cursor_data
);
792 kfree(ops
->fontbuffer
);
793 kfree(oldinfo
->fbcon_par
);
794 oldinfo
->fbcon_par
= NULL
;
795 module_put(oldinfo
->fbops
->owner
);
797 If oldinfo and newinfo are driving the same hardware,
798 the fb_release() method of oldinfo may attempt to
799 restore the hardware state. This will leave the
800 newinfo in an undefined state. Thus, a call to
801 fb_set_par() may be needed for the newinfo.
803 if (newinfo
->fbops
->fb_set_par
)
804 newinfo
->fbops
->fb_set_par(newinfo
);
810 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
811 int unit
, int show_logo
)
813 struct fbcon_ops
*ops
= info
->fbcon_par
;
815 ops
->currcon
= fg_console
;
817 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
))
818 info
->fbops
->fb_set_par(info
);
820 ops
->flags
|= FBCON_FLAGS_INIT
;
822 fbcon_set_disp(info
, &info
->var
, unit
);
825 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
826 struct fb_info
*fg_info
=
827 registered_fb
[con2fb_map
[fg_console
]];
829 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
830 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
834 update_screen(vc_cons
[fg_console
].d
);
838 * set_con2fb_map - map console to frame buffer device
839 * @unit: virtual console number to map
840 * @newidx: frame buffer index to map virtual console to
841 * @user: user request
843 * Maps a virtual console @unit to a frame buffer device
846 static int set_con2fb_map(int unit
, int newidx
, int user
)
848 struct vc_data
*vc
= vc_cons
[unit
].d
;
849 int oldidx
= con2fb_map
[unit
];
850 struct fb_info
*info
= registered_fb
[newidx
];
851 struct fb_info
*oldinfo
= NULL
;
854 if (oldidx
== newidx
)
857 if (!info
|| fbcon_has_exited
)
860 if (!err
&& !search_for_mapped_con()) {
862 return fbcon_takeover(0);
866 oldinfo
= registered_fb
[oldidx
];
868 found
= search_fb_in_map(newidx
);
870 acquire_console_sem();
871 con2fb_map
[unit
] = newidx
;
873 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
877 * If old fb is not mapped to any of the consoles,
878 * fbcon should release it.
880 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
881 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
885 int show_logo
= (fg_console
== 0 && !user
&&
886 logo_shown
!= FBCON_LOGO_DONTSHOW
);
889 fbcon_add_cursor_timer(info
);
890 con2fb_map_boot
[unit
] = newidx
;
891 con2fb_init_display(vc
, info
, unit
, show_logo
);
894 if (!search_fb_in_map(info_idx
))
897 release_console_sem();
902 * Low Level Operations
904 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
905 static int var_to_display(struct display
*disp
,
906 struct fb_var_screeninfo
*var
,
907 struct fb_info
*info
)
909 disp
->xres_virtual
= var
->xres_virtual
;
910 disp
->yres_virtual
= var
->yres_virtual
;
911 disp
->bits_per_pixel
= var
->bits_per_pixel
;
912 disp
->grayscale
= var
->grayscale
;
913 disp
->nonstd
= var
->nonstd
;
914 disp
->accel_flags
= var
->accel_flags
;
915 disp
->height
= var
->height
;
916 disp
->width
= var
->width
;
917 disp
->red
= var
->red
;
918 disp
->green
= var
->green
;
919 disp
->blue
= var
->blue
;
920 disp
->transp
= var
->transp
;
921 disp
->rotate
= var
->rotate
;
922 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
923 if (disp
->mode
== NULL
)
924 /* This should not happen */
929 static void display_to_var(struct fb_var_screeninfo
*var
,
930 struct display
*disp
)
932 fb_videomode_to_var(var
, disp
->mode
);
933 var
->xres_virtual
= disp
->xres_virtual
;
934 var
->yres_virtual
= disp
->yres_virtual
;
935 var
->bits_per_pixel
= disp
->bits_per_pixel
;
936 var
->grayscale
= disp
->grayscale
;
937 var
->nonstd
= disp
->nonstd
;
938 var
->accel_flags
= disp
->accel_flags
;
939 var
->height
= disp
->height
;
940 var
->width
= disp
->width
;
941 var
->red
= disp
->red
;
942 var
->green
= disp
->green
;
943 var
->blue
= disp
->blue
;
944 var
->transp
= disp
->transp
;
945 var
->rotate
= disp
->rotate
;
948 static const char *fbcon_startup(void)
950 const char *display_desc
= "frame buffer device";
951 struct display
*p
= &fb_display
[fg_console
];
952 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
953 const struct font_desc
*font
= NULL
;
954 struct module
*owner
;
955 struct fb_info
*info
= NULL
;
956 struct fbcon_ops
*ops
;
962 * If num_registered_fb is zero, this is a call for the dummy part.
963 * The frame buffer devices weren't initialized yet.
965 if (!num_registered_fb
|| info_idx
== -1)
968 * Instead of blindly using registered_fb[0], we use info_idx, set by
971 info
= registered_fb
[info_idx
];
975 owner
= info
->fbops
->owner
;
976 if (!try_module_get(owner
))
978 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
983 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
991 ops
->cur_rotate
= -1;
992 info
->fbcon_par
= ops
;
993 p
->con_rotate
= rotate
;
994 set_blitting_type(vc
, info
);
996 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
997 if (fbcon_softback_size
) {
1001 kmalloc(fbcon_softback_size
,
1003 if (!softback_buf
) {
1004 fbcon_softback_size
= 0;
1010 kfree((void *) softback_buf
);
1016 softback_in
= softback_top
= softback_curr
=
1021 /* Setup default font */
1023 if (!fontname
[0] || !(font
= find_font(fontname
)))
1024 font
= get_default_font(info
->var
.xres
,
1026 info
->pixmap
.blit_x
,
1027 info
->pixmap
.blit_y
);
1028 vc
->vc_font
.width
= font
->width
;
1029 vc
->vc_font
.height
= font
->height
;
1030 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1031 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1034 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1035 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1036 cols
/= vc
->vc_font
.width
;
1037 rows
/= vc
->vc_font
.height
;
1038 vc_resize(vc
, cols
, rows
);
1040 DPRINTK("mode: %s\n", info
->fix
.id
);
1041 DPRINTK("visual: %d\n", info
->fix
.visual
);
1042 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1044 info
->var
.bits_per_pixel
);
1047 if (MACH_IS_ATARI
) {
1048 cursor_blink_rate
= ATARI_CURSOR_BLINK_RATE
;
1050 request_irq(IRQ_AUTO_4
, fb_vbl_handler
,
1051 IRQ_TYPE_PRIO
, "framebuffer vbl",
1054 #endif /* CONFIG_ATARI */
1058 * On a Macintoy, the VBL interrupt may or may not be active.
1059 * As interrupt based cursor is more reliable and race free, we
1060 * probe for VBL interrupts.
1065 * Probe for VBL: set temp. handler ...
1067 irqres
= request_irq(IRQ_MAC_VBL
, fb_vbl_detect
, 0,
1068 "framebuffer vbl", info
);
1072 * ... and spin for 20 ms ...
1074 while (!vbl_detected
&& ++ct
< 1000)
1079 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1081 free_irq(IRQ_MAC_VBL
, fb_vbl_detect
);
1085 * interrupt based cursor ok
1087 cursor_blink_rate
= MAC_CURSOR_BLINK_RATE
;
1089 request_irq(IRQ_MAC_VBL
, fb_vbl_handler
, 0,
1090 "framebuffer vbl", info
);
1093 * VBL not detected: fall through, use timer based cursor
1098 #endif /* CONFIG_MAC */
1100 fbcon_add_cursor_timer(info
);
1101 fbcon_has_exited
= 0;
1102 return display_desc
;
1105 static void fbcon_init(struct vc_data
*vc
, int init
)
1107 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1108 struct fbcon_ops
*ops
;
1109 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1110 struct vc_data
*svc
= *default_mode
;
1111 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1112 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1115 if (info_idx
== -1 || info
== NULL
)
1120 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1121 (info
->fix
.type
== FB_TYPE_TEXT
))
1124 if (var_to_display(p
, &info
->var
, info
))
1127 if (!info
->fbcon_par
)
1128 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1130 /* If we are not the first console on this
1131 fb, copy the font from that console */
1132 t
= &fb_display
[fg_console
];
1135 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1137 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1139 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1140 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1141 p
->userfont
= t
->userfont
;
1144 REFCOUNT(p
->fontdata
)++;
1146 const struct font_desc
*font
= NULL
;
1148 if (!fontname
[0] || !(font
= find_font(fontname
)))
1149 font
= get_default_font(info
->var
.xres
,
1151 info
->pixmap
.blit_x
,
1152 info
->pixmap
.blit_y
);
1153 vc
->vc_font
.width
= font
->width
;
1154 vc
->vc_font
.height
= font
->height
;
1155 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1156 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1157 support more fonts */
1162 charcnt
= FNTCHARCNT(p
->fontdata
);
1164 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1165 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1166 if (charcnt
== 256) {
1167 vc
->vc_hi_font_mask
= 0;
1169 vc
->vc_hi_font_mask
= 0x100;
1170 if (vc
->vc_can_do_color
)
1171 vc
->vc_complement_mask
<<= 1;
1174 if (!*svc
->vc_uni_pagedir_loc
)
1175 con_set_default_unimap(svc
);
1176 if (!*vc
->vc_uni_pagedir_loc
)
1177 con_copy_unimap(vc
, svc
);
1179 ops
= info
->fbcon_par
;
1180 p
->con_rotate
= rotate
;
1181 set_blitting_type(vc
, info
);
1185 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1186 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1187 new_cols
/= vc
->vc_font
.width
;
1188 new_rows
/= vc
->vc_font
.height
;
1189 vc_resize(vc
, new_cols
, new_rows
);
1192 * We must always set the mode. The mode of the previous console
1193 * driver could be in the same resolution but we are using different
1194 * hardware so we have to initialize the hardware.
1196 * We need to do it in fbcon_init() to prevent screen corruption.
1198 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1199 if (info
->fbops
->fb_set_par
&&
1200 !(ops
->flags
& FBCON_FLAGS_INIT
))
1201 info
->fbops
->fb_set_par(info
);
1202 ops
->flags
|= FBCON_FLAGS_INIT
;
1207 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1208 !(cap
& FBINFO_HWACCEL_DISABLED
))
1209 p
->scrollmode
= SCROLL_MOVE
;
1210 else /* default to something safe */
1211 p
->scrollmode
= SCROLL_REDRAW
;
1214 * ++guenther: console.c:vc_allocate() relies on initializing
1215 * vc_{cols,rows}, but we must not set those if we are only
1216 * resizing the console.
1219 vc
->vc_cols
= new_cols
;
1220 vc
->vc_rows
= new_rows
;
1224 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1226 if (vc
== svc
&& softback_buf
)
1227 fbcon_update_softback(vc
);
1229 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1230 ops
->rotate
= FB_ROTATE_UR
;
1231 set_blitting_type(vc
, info
);
1234 ops
->p
= &fb_display
[fg_console
];
1237 static void fbcon_free_font(struct display
*p
)
1239 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1240 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1245 static void fbcon_deinit(struct vc_data
*vc
)
1247 struct display
*p
= &fb_display
[vc
->vc_num
];
1248 struct fb_info
*info
;
1249 struct fbcon_ops
*ops
;
1253 idx
= con2fb_map
[vc
->vc_num
];
1258 info
= registered_fb
[idx
];
1263 ops
= info
->fbcon_par
;
1268 if (CON_IS_VISIBLE(vc
))
1269 fbcon_del_cursor_timer(info
);
1271 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1274 if (!con_is_bound(&fb_con
))
1280 /* ====================================================================== */
1282 /* fbcon_XXX routines - interface used by the world
1284 * This system is now divided into two levels because of complications
1285 * caused by hardware scrolling. Top level functions:
1287 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1289 * handles y values in range [0, scr_height-1] that correspond to real
1290 * screen positions. y_wrap shift means that first line of bitmap may be
1291 * anywhere on this display. These functions convert lineoffsets to
1292 * bitmap offsets and deal with the wrap-around case by splitting blits.
1294 * fbcon_bmove_physical_8() -- These functions fast implementations
1295 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1296 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1300 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1301 * Implies should only really hardware scroll in rows. Only reason for
1302 * restriction is simplicity & efficiency at the moment.
1305 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1308 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1309 struct fbcon_ops
*ops
= info
->fbcon_par
;
1311 struct display
*p
= &fb_display
[vc
->vc_num
];
1314 if (fbcon_is_inactive(vc
, info
))
1317 if (!height
|| !width
)
1320 /* Split blits that cross physical y_wrap boundary */
1322 y_break
= p
->vrows
- p
->yscroll
;
1323 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1324 u_int b
= y_break
- sy
;
1325 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1326 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1329 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1332 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1333 int count
, int ypos
, int xpos
)
1335 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1336 struct display
*p
= &fb_display
[vc
->vc_num
];
1337 struct fbcon_ops
*ops
= info
->fbcon_par
;
1339 if (!fbcon_is_inactive(vc
, info
))
1340 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1341 get_color(vc
, info
, scr_readw(s
), 1),
1342 get_color(vc
, info
, scr_readw(s
), 0));
1345 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1349 scr_writew(c
, &chr
);
1350 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1353 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1355 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1356 struct fbcon_ops
*ops
= info
->fbcon_par
;
1358 if (!fbcon_is_inactive(vc
, info
))
1359 ops
->clear_margins(vc
, info
, bottom_only
);
1362 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1364 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1365 struct fbcon_ops
*ops
= info
->fbcon_par
;
1367 int c
= scr_readw((u16
*) vc
->vc_pos
);
1369 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1372 if (vc
->vc_cursor_type
& 0x10)
1373 fbcon_del_cursor_timer(info
);
1375 fbcon_add_cursor_timer(info
);
1377 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1378 if (mode
& CM_SOFTBACK
) {
1379 mode
&= ~CM_SOFTBACK
;
1383 fbcon_set_origin(vc
);
1387 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1388 get_color(vc
, info
, c
, 0));
1389 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1392 static int scrollback_phys_max
= 0;
1393 static int scrollback_max
= 0;
1394 static int scrollback_current
= 0;
1396 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1399 struct display
*p
, *t
;
1400 struct vc_data
**default_mode
, *vc
;
1401 struct vc_data
*svc
;
1402 struct fbcon_ops
*ops
= info
->fbcon_par
;
1403 int rows
, cols
, charcnt
= 256;
1405 p
= &fb_display
[unit
];
1407 if (var_to_display(p
, var
, info
))
1410 vc
= vc_cons
[unit
].d
;
1415 default_mode
= vc
->vc_display_fg
;
1416 svc
= *default_mode
;
1417 t
= &fb_display
[svc
->vc_num
];
1419 if (!vc
->vc_font
.data
) {
1420 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1421 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1422 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1423 p
->userfont
= t
->userfont
;
1425 REFCOUNT(p
->fontdata
)++;
1428 charcnt
= FNTCHARCNT(p
->fontdata
);
1430 var
->activate
= FB_ACTIVATE_NOW
;
1431 info
->var
.activate
= var
->activate
;
1432 var
->yoffset
= info
->var
.yoffset
;
1433 var
->xoffset
= info
->var
.xoffset
;
1434 fb_set_var(info
, var
);
1435 ops
->var
= info
->var
;
1436 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1437 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1438 if (charcnt
== 256) {
1439 vc
->vc_hi_font_mask
= 0;
1441 vc
->vc_hi_font_mask
= 0x100;
1442 if (vc
->vc_can_do_color
)
1443 vc
->vc_complement_mask
<<= 1;
1446 if (!*svc
->vc_uni_pagedir_loc
)
1447 con_set_default_unimap(svc
);
1448 if (!*vc
->vc_uni_pagedir_loc
)
1449 con_copy_unimap(vc
, svc
);
1451 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1452 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1453 cols
/= vc
->vc_font
.width
;
1454 rows
/= vc
->vc_font
.height
;
1455 vc_resize(vc
, cols
, rows
);
1457 if (CON_IS_VISIBLE(vc
)) {
1460 fbcon_update_softback(vc
);
1464 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1466 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1467 struct fbcon_ops
*ops
= info
->fbcon_par
;
1468 struct display
*p
= &fb_display
[vc
->vc_num
];
1470 p
->yscroll
+= count
;
1471 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1472 p
->yscroll
-= p
->vrows
;
1473 ops
->var
.xoffset
= 0;
1474 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1475 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1476 ops
->update_start(info
);
1477 scrollback_max
+= count
;
1478 if (scrollback_max
> scrollback_phys_max
)
1479 scrollback_max
= scrollback_phys_max
;
1480 scrollback_current
= 0;
1483 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1485 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1486 struct fbcon_ops
*ops
= info
->fbcon_par
;
1487 struct display
*p
= &fb_display
[vc
->vc_num
];
1489 p
->yscroll
-= count
;
1490 if (p
->yscroll
< 0) /* Deal with wrap */
1491 p
->yscroll
+= p
->vrows
;
1492 ops
->var
.xoffset
= 0;
1493 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1494 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1495 ops
->update_start(info
);
1496 scrollback_max
-= count
;
1497 if (scrollback_max
< 0)
1499 scrollback_current
= 0;
1502 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1504 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1505 struct display
*p
= &fb_display
[vc
->vc_num
];
1506 struct fbcon_ops
*ops
= info
->fbcon_par
;
1508 p
->yscroll
+= count
;
1509 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1510 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1511 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1512 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1515 ops
->var
.xoffset
= 0;
1516 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1517 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1518 ops
->update_start(info
);
1519 fbcon_clear_margins(vc
, 1);
1520 scrollback_max
+= count
;
1521 if (scrollback_max
> scrollback_phys_max
)
1522 scrollback_max
= scrollback_phys_max
;
1523 scrollback_current
= 0;
1526 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1528 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1529 struct fbcon_ops
*ops
= info
->fbcon_par
;
1530 struct display
*p
= &fb_display
[vc
->vc_num
];
1532 p
->yscroll
+= count
;
1534 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1535 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1536 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1539 ops
->var
.xoffset
= 0;
1540 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1541 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1542 ops
->update_start(info
);
1543 fbcon_clear_margins(vc
, 1);
1544 scrollback_max
+= count
;
1545 if (scrollback_max
> scrollback_phys_max
)
1546 scrollback_max
= scrollback_phys_max
;
1547 scrollback_current
= 0;
1550 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1552 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1553 struct display
*p
= &fb_display
[vc
->vc_num
];
1554 struct fbcon_ops
*ops
= info
->fbcon_par
;
1556 p
->yscroll
-= count
;
1557 if (p
->yscroll
< 0) {
1558 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1559 0, vc
->vc_rows
, vc
->vc_cols
);
1560 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1563 ops
->var
.xoffset
= 0;
1564 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1565 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1566 ops
->update_start(info
);
1567 fbcon_clear_margins(vc
, 1);
1568 scrollback_max
-= count
;
1569 if (scrollback_max
< 0)
1571 scrollback_current
= 0;
1574 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1576 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1577 struct fbcon_ops
*ops
= info
->fbcon_par
;
1578 struct display
*p
= &fb_display
[vc
->vc_num
];
1580 p
->yscroll
-= count
;
1582 if (p
->yscroll
< 0) {
1583 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1584 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1587 ops
->var
.xoffset
= 0;
1588 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1589 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1590 ops
->update_start(info
);
1591 fbcon_clear_margins(vc
, 1);
1592 scrollback_max
-= count
;
1593 if (scrollback_max
< 0)
1595 scrollback_current
= 0;
1598 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1601 int count
= vc
->vc_rows
;
1602 unsigned short *d
, *s
;
1606 d
= (u16
*) softback_curr
;
1607 if (d
== (u16
*) softback_in
)
1608 d
= (u16
*) vc
->vc_origin
;
1609 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1610 softback_lines
-= delta
;
1612 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1613 n
+= softback_end
- softback_buf
;
1614 if (n
< softback_top
) {
1616 (softback_top
- n
) / vc
->vc_size_row
;
1619 } else if (softback_curr
>= softback_top
1620 && n
< softback_top
) {
1622 (softback_top
- n
) / vc
->vc_size_row
;
1626 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1627 n
+= softback_buf
- softback_end
;
1628 if (n
> softback_in
) {
1632 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1637 if (n
== softback_curr
)
1640 s
= (u16
*) softback_curr
;
1641 if (s
== (u16
*) softback_in
)
1642 s
= (u16
*) vc
->vc_origin
;
1644 unsigned short *start
;
1648 unsigned short attr
= 1;
1651 le
= advance_row(s
, 1);
1654 if (attr
!= (c
& 0xff00)) {
1657 fbcon_putcs(vc
, start
, s
- start
,
1663 if (c
== scr_readw(d
)) {
1665 fbcon_putcs(vc
, start
, s
- start
,
1678 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1680 if (d
== (u16
*) softback_end
)
1681 d
= (u16
*) softback_buf
;
1682 if (d
== (u16
*) softback_in
)
1683 d
= (u16
*) vc
->vc_origin
;
1684 if (s
== (u16
*) softback_end
)
1685 s
= (u16
*) softback_buf
;
1686 if (s
== (u16
*) softback_in
)
1687 s
= (u16
*) vc
->vc_origin
;
1691 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1692 int line
, int count
, int dy
)
1694 unsigned short *s
= (unsigned short *)
1695 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1698 unsigned short *start
= s
;
1699 unsigned short *le
= advance_row(s
, 1);
1702 unsigned short attr
= 1;
1706 if (attr
!= (c
& 0xff00)) {
1709 fbcon_putcs(vc
, start
, s
- start
,
1715 console_conditional_schedule();
1719 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1720 console_conditional_schedule();
1725 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1726 struct display
*p
, int line
, int count
, int ycount
)
1728 int offset
= ycount
* vc
->vc_cols
;
1729 unsigned short *d
= (unsigned short *)
1730 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1731 unsigned short *s
= d
+ offset
;
1732 struct fbcon_ops
*ops
= info
->fbcon_par
;
1735 unsigned short *start
= s
;
1736 unsigned short *le
= advance_row(s
, 1);
1743 if (c
== scr_readw(d
)) {
1745 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1746 line
, x
, 1, s
-start
);
1756 console_conditional_schedule();
1761 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1763 console_conditional_schedule();
1768 /* NOTE: We subtract two lines from these pointers */
1769 s
-= vc
->vc_size_row
;
1770 d
-= vc
->vc_size_row
;
1775 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1776 int line
, int count
, int offset
)
1778 unsigned short *d
= (unsigned short *)
1779 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1780 unsigned short *s
= d
+ offset
;
1783 unsigned short *start
= s
;
1784 unsigned short *le
= advance_row(s
, 1);
1787 unsigned short attr
= 1;
1791 if (attr
!= (c
& 0xff00)) {
1794 fbcon_putcs(vc
, start
, s
- start
,
1800 if (c
== scr_readw(d
)) {
1802 fbcon_putcs(vc
, start
, s
- start
,
1812 console_conditional_schedule();
1817 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1818 console_conditional_schedule();
1823 /* NOTE: We subtract two lines from these pointers */
1824 s
-= vc
->vc_size_row
;
1825 d
-= vc
->vc_size_row
;
1830 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1835 if (vc
->vc_num
!= fg_console
)
1837 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1840 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1842 p
= advance_row(p
, 1);
1843 softback_in
+= vc
->vc_size_row
;
1844 if (softback_in
== softback_end
)
1845 softback_in
= softback_buf
;
1846 if (softback_in
== softback_top
) {
1847 softback_top
+= vc
->vc_size_row
;
1848 if (softback_top
== softback_end
)
1849 softback_top
= softback_buf
;
1852 softback_curr
= softback_in
;
1855 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1858 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1859 struct display
*p
= &fb_display
[vc
->vc_num
];
1860 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1862 if (fbcon_is_inactive(vc
, info
))
1865 fbcon_cursor(vc
, CM_ERASE
);
1868 * ++Geert: Only use ywrap/ypan if the console is in text mode
1869 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1870 * whole screen (prevents flicker).
1875 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1876 count
= vc
->vc_rows
;
1878 fbcon_softback_note(vc
, t
, count
);
1879 if (logo_shown
>= 0)
1881 switch (p
->scrollmode
) {
1883 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1885 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1886 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1889 vc
->vc_video_erase_char
,
1890 vc
->vc_size_row
* count
);
1894 case SCROLL_WRAP_MOVE
:
1895 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1897 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1899 ywrap_up(vc
, count
);
1900 if (vc
->vc_rows
- b
> 0)
1901 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1904 } else if (info
->flags
& FBINFO_READS_FAST
)
1905 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1906 b
- t
- count
, vc
->vc_cols
);
1909 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1912 case SCROLL_PAN_REDRAW
:
1913 if ((p
->yscroll
+ count
<=
1914 2 * (p
->vrows
- vc
->vc_rows
))
1915 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1918 3 * vc
->vc_rows
>> 2)))) {
1920 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1921 ypan_up_redraw(vc
, t
, count
);
1922 if (vc
->vc_rows
- b
> 0)
1923 fbcon_redraw_move(vc
, p
, b
,
1924 vc
->vc_rows
- b
, b
);
1926 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1927 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1930 case SCROLL_PAN_MOVE
:
1931 if ((p
->yscroll
+ count
<=
1932 2 * (p
->vrows
- vc
->vc_rows
))
1933 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1936 3 * vc
->vc_rows
>> 2)))) {
1938 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1941 if (vc
->vc_rows
- b
> 0)
1942 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1945 } else if (info
->flags
& FBINFO_READS_FAST
)
1946 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1947 b
- t
- count
, vc
->vc_cols
);
1950 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1955 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1956 count
* vc
->vc_cols
);
1957 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1958 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1961 vc
->vc_video_erase_char
,
1962 vc
->vc_size_row
* count
);
1968 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1969 count
= vc
->vc_rows
;
1970 if (logo_shown
>= 0)
1972 switch (p
->scrollmode
) {
1974 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1976 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1977 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1980 vc
->vc_video_erase_char
,
1981 vc
->vc_size_row
* count
);
1985 case SCROLL_WRAP_MOVE
:
1986 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1987 if (vc
->vc_rows
- b
> 0)
1988 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1991 ywrap_down(vc
, count
);
1993 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1995 } else if (info
->flags
& FBINFO_READS_FAST
)
1996 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1997 b
- t
- count
, vc
->vc_cols
);
2000 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2003 case SCROLL_PAN_MOVE
:
2004 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2005 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2008 3 * vc
->vc_rows
>> 2)))) {
2009 if (vc
->vc_rows
- b
> 0)
2010 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
2013 ypan_down(vc
, count
);
2015 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
2017 } else if (info
->flags
& FBINFO_READS_FAST
)
2018 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
2019 b
- t
- count
, vc
->vc_cols
);
2022 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2025 case SCROLL_PAN_REDRAW
:
2026 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
2027 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
2030 3 * vc
->vc_rows
>> 2)))) {
2031 if (vc
->vc_rows
- b
> 0)
2032 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
2034 ypan_down_redraw(vc
, t
, count
);
2036 fbcon_redraw_move(vc
, p
, count
, t
, 0);
2038 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
2039 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2044 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
2045 -count
* vc
->vc_cols
);
2046 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
2047 scr_memsetw((unsigned short *) (vc
->vc_origin
+
2050 vc
->vc_video_erase_char
,
2051 vc
->vc_size_row
* count
);
2059 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2060 int height
, int width
)
2062 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2063 struct display
*p
= &fb_display
[vc
->vc_num
];
2065 if (fbcon_is_inactive(vc
, info
))
2068 if (!width
|| !height
)
2071 /* Split blits that cross physical y_wrap case.
2072 * Pathological case involves 4 blits, better to use recursive
2073 * code rather than unrolled case
2075 * Recursive invocations don't need to erase the cursor over and
2076 * over again, so we use fbcon_bmove_rec()
2078 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2079 p
->vrows
- p
->yscroll
);
2082 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2083 int dy
, int dx
, int height
, int width
, u_int y_break
)
2085 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2086 struct fbcon_ops
*ops
= info
->fbcon_par
;
2089 if (sy
< y_break
&& sy
+ height
> y_break
) {
2091 if (dy
< sy
) { /* Avoid trashing self */
2092 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2094 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2095 height
- b
, width
, y_break
);
2097 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2098 height
- b
, width
, y_break
);
2099 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2105 if (dy
< y_break
&& dy
+ height
> y_break
) {
2107 if (dy
< sy
) { /* Avoid trashing self */
2108 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2110 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2111 height
- b
, width
, y_break
);
2113 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2114 height
- b
, width
, y_break
);
2115 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2120 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2124 static __inline__
void updatescrollmode(struct display
*p
,
2125 struct fb_info
*info
,
2128 struct fbcon_ops
*ops
= info
->fbcon_par
;
2129 int fh
= vc
->vc_font
.height
;
2130 int cap
= info
->flags
;
2132 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2133 info
->fix
.xpanstep
);
2134 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2135 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2136 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2137 info
->var
.xres_virtual
);
2138 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2139 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2140 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2141 divides(ywrap
, vc
->vc_font
.height
) &&
2142 divides(vc
->vc_font
.height
, vyres
) &&
2143 divides(vc
->vc_font
.height
, yres
);
2144 int reading_fast
= cap
& FBINFO_READS_FAST
;
2145 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2146 !(cap
& FBINFO_HWACCEL_DISABLED
);
2147 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2148 !(cap
& FBINFO_HWACCEL_DISABLED
);
2150 p
->vrows
= vyres
/fh
;
2151 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2152 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2153 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2156 if (good_wrap
|| good_pan
) {
2157 if (reading_fast
|| fast_copyarea
)
2158 p
->scrollmode
= good_wrap
?
2159 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2161 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2164 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2165 p
->scrollmode
= SCROLL_MOVE
;
2167 p
->scrollmode
= SCROLL_REDRAW
;
2171 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2172 unsigned int height
)
2174 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2175 struct fbcon_ops
*ops
= info
->fbcon_par
;
2176 struct display
*p
= &fb_display
[vc
->vc_num
];
2177 struct fb_var_screeninfo var
= info
->var
;
2178 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2180 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2181 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2182 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2183 vc
->vc_font
.height
);
2184 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2186 var
.xres
= virt_w
* virt_fw
;
2187 var
.yres
= virt_h
* virt_fh
;
2188 x_diff
= info
->var
.xres
- var
.xres
;
2189 y_diff
= info
->var
.yres
- var
.yres
;
2190 if (x_diff
< 0 || x_diff
> virt_fw
||
2191 y_diff
< 0 || y_diff
> virt_fh
) {
2192 const struct fb_videomode
*mode
;
2194 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2195 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2198 display_to_var(&var
, p
);
2199 fb_videomode_to_var(&var
, mode
);
2201 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2204 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2205 if (CON_IS_VISIBLE(vc
)) {
2206 var
.activate
= FB_ACTIVATE_NOW
|
2208 fb_set_var(info
, &var
);
2210 var_to_display(p
, &info
->var
, info
);
2211 ops
->var
= info
->var
;
2213 updatescrollmode(p
, info
, vc
);
2217 static int fbcon_switch(struct vc_data
*vc
)
2219 struct fb_info
*info
, *old_info
= NULL
;
2220 struct fbcon_ops
*ops
;
2221 struct display
*p
= &fb_display
[vc
->vc_num
];
2222 struct fb_var_screeninfo var
;
2223 int i
, prev_console
, charcnt
= 256;
2225 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2226 ops
= info
->fbcon_par
;
2230 fbcon_set_origin(vc
);
2231 softback_top
= softback_curr
= softback_in
= softback_buf
;
2233 fbcon_update_softback(vc
);
2236 if (logo_shown
>= 0) {
2237 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2239 if (conp2
->vc_top
== logo_lines
2240 && conp2
->vc_bottom
== conp2
->vc_rows
)
2242 logo_shown
= FBCON_LOGO_CANSHOW
;
2245 prev_console
= ops
->currcon
;
2246 if (prev_console
!= -1)
2247 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2249 * FIXME: If we have multiple fbdev's loaded, we need to
2250 * update all info->currcon. Perhaps, we can place this
2251 * in a centralized structure, but this might break some
2254 * info->currcon = vc->vc_num;
2256 for (i
= 0; i
< FB_MAX
; i
++) {
2257 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2258 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2260 o
->currcon
= vc
->vc_num
;
2263 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2264 display_to_var(&var
, p
);
2265 var
.activate
= FB_ACTIVATE_NOW
;
2268 * make sure we don't unnecessarily trip the memcmp()
2271 info
->var
.activate
= var
.activate
;
2272 var
.yoffset
= info
->var
.yoffset
;
2273 var
.xoffset
= info
->var
.xoffset
;
2274 var
.vmode
= info
->var
.vmode
;
2275 fb_set_var(info
, &var
);
2276 ops
->var
= info
->var
;
2278 if (old_info
!= NULL
&& (old_info
!= info
||
2279 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2280 if (info
->fbops
->fb_set_par
)
2281 info
->fbops
->fb_set_par(info
);
2283 if (old_info
!= info
)
2284 fbcon_del_cursor_timer(old_info
);
2287 if (fbcon_is_inactive(vc
, info
) ||
2288 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2289 fbcon_del_cursor_timer(info
);
2291 fbcon_add_cursor_timer(info
);
2293 set_blitting_type(vc
, info
);
2294 ops
->cursor_reset
= 1;
2296 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2297 ops
->rotate
= FB_ROTATE_UR
;
2298 set_blitting_type(vc
, info
);
2301 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2302 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2305 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2308 vc
->vc_complement_mask
<<= 1;
2310 updatescrollmode(p
, info
, vc
);
2312 switch (p
->scrollmode
) {
2313 case SCROLL_WRAP_MOVE
:
2314 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2316 case SCROLL_PAN_MOVE
:
2317 case SCROLL_PAN_REDRAW
:
2318 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2319 if (scrollback_phys_max
< 0)
2320 scrollback_phys_max
= 0;
2323 scrollback_phys_max
= 0;
2328 scrollback_current
= 0;
2330 if (!fbcon_is_inactive(vc
, info
)) {
2331 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2332 ops
->update_start(info
);
2335 fbcon_set_palette(vc
, color_table
);
2336 fbcon_clear_margins(vc
, 0);
2338 if (logo_shown
== FBCON_LOGO_DRAW
) {
2340 logo_shown
= fg_console
;
2341 /* This is protected above by initmem_freed */
2342 fb_show_logo(info
, ops
->rotate
);
2344 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2345 vc
->vc_size_row
* (vc
->vc_bottom
-
2352 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2355 struct fb_event event
;
2358 unsigned short charmask
= vc
->vc_hi_font_mask
?
2360 unsigned short oldc
;
2362 oldc
= vc
->vc_video_erase_char
;
2363 vc
->vc_video_erase_char
&= charmask
;
2364 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2365 vc
->vc_video_erase_char
= oldc
;
2370 event
.data
= &blank
;
2371 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2374 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2376 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2377 struct fbcon_ops
*ops
= info
->fbcon_par
;
2380 struct fb_var_screeninfo var
= info
->var
;
2385 if (info
->fbops
->fb_save_state
)
2386 info
->fbops
->fb_save_state(info
);
2387 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2388 fb_set_var(info
, &var
);
2390 ops
->var
= info
->var
;
2391 } else if (info
->fbops
->fb_restore_state
)
2392 info
->fbops
->fb_restore_state(info
);
2395 if (!fbcon_is_inactive(vc
, info
)) {
2396 if (ops
->blank_state
!= blank
) {
2397 ops
->blank_state
= blank
;
2398 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2399 ops
->cursor_flash
= (!blank
);
2401 if (fb_blank(info
, blank
))
2402 fbcon_generic_blank(vc
, info
, blank
);
2409 if (fbcon_is_inactive(vc
, info
) ||
2410 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2411 fbcon_del_cursor_timer(info
);
2413 fbcon_add_cursor_timer(info
);
2418 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2420 u8
*fontdata
= vc
->vc_font
.data
;
2421 u8
*data
= font
->data
;
2424 font
->width
= vc
->vc_font
.width
;
2425 font
->height
= vc
->vc_font
.height
;
2426 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2430 if (font
->width
<= 8) {
2431 j
= vc
->vc_font
.height
;
2432 for (i
= 0; i
< font
->charcount
; i
++) {
2433 memcpy(data
, fontdata
, j
);
2434 memset(data
+ j
, 0, 32 - j
);
2438 } else if (font
->width
<= 16) {
2439 j
= vc
->vc_font
.height
* 2;
2440 for (i
= 0; i
< font
->charcount
; i
++) {
2441 memcpy(data
, fontdata
, j
);
2442 memset(data
+ j
, 0, 64 - j
);
2446 } else if (font
->width
<= 24) {
2447 for (i
= 0; i
< font
->charcount
; i
++) {
2448 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2449 *data
++ = fontdata
[0];
2450 *data
++ = fontdata
[1];
2451 *data
++ = fontdata
[2];
2452 fontdata
+= sizeof(u32
);
2454 memset(data
, 0, 3 * (32 - j
));
2455 data
+= 3 * (32 - j
);
2458 j
= vc
->vc_font
.height
* 4;
2459 for (i
= 0; i
< font
->charcount
; i
++) {
2460 memcpy(data
, fontdata
, j
);
2461 memset(data
+ j
, 0, 128 - j
);
2469 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2470 const u8
* data
, int userfont
)
2472 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2473 struct fbcon_ops
*ops
= info
->fbcon_par
;
2474 struct display
*p
= &fb_display
[vc
->vc_num
];
2477 char *old_data
= NULL
;
2479 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2480 fbcon_set_origin(vc
);
2482 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2484 old_data
= vc
->vc_font
.data
;
2486 cnt
= FNTCHARCNT(data
);
2489 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2490 if ((p
->userfont
= userfont
))
2492 vc
->vc_font
.width
= w
;
2493 vc
->vc_font
.height
= h
;
2494 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2495 vc
->vc_hi_font_mask
= 0;
2496 if (vc
->vc_can_do_color
) {
2497 vc
->vc_complement_mask
>>= 1;
2498 vc
->vc_s_complement_mask
>>= 1;
2501 /* ++Edmund: reorder the attribute bits */
2502 if (vc
->vc_can_do_color
) {
2503 unsigned short *cp
=
2504 (unsigned short *) vc
->vc_origin
;
2505 int count
= vc
->vc_screenbuf_size
/ 2;
2507 for (; count
> 0; count
--, cp
++) {
2509 scr_writew(((c
& 0xfe00) >> 1) |
2512 c
= vc
->vc_video_erase_char
;
2513 vc
->vc_video_erase_char
=
2514 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2517 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2518 vc
->vc_hi_font_mask
= 0x100;
2519 if (vc
->vc_can_do_color
) {
2520 vc
->vc_complement_mask
<<= 1;
2521 vc
->vc_s_complement_mask
<<= 1;
2524 /* ++Edmund: reorder the attribute bits */
2526 unsigned short *cp
=
2527 (unsigned short *) vc
->vc_origin
;
2528 int count
= vc
->vc_screenbuf_size
/ 2;
2530 for (; count
> 0; count
--, cp
++) {
2531 unsigned short newc
;
2533 if (vc
->vc_can_do_color
)
2535 ((c
& 0xff00) << 1) | (c
&
2539 scr_writew(newc
, cp
);
2541 c
= vc
->vc_video_erase_char
;
2542 if (vc
->vc_can_do_color
) {
2543 vc
->vc_video_erase_char
=
2544 ((c
& 0xff00) << 1) | (c
& 0xff);
2547 vc
->vc_video_erase_char
= c
& ~0x100;
2555 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2556 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2559 vc_resize(vc
, cols
, rows
);
2560 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2561 fbcon_update_softback(vc
);
2562 } else if (CON_IS_VISIBLE(vc
)
2563 && vc
->vc_mode
== KD_TEXT
) {
2564 fbcon_clear_margins(vc
, 0);
2568 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2569 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2573 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2575 struct display
*od
= &fb_display
[con
];
2576 struct console_font
*f
= &vc
->vc_font
;
2578 if (od
->fontdata
== f
->data
)
2579 return 0; /* already the same font... */
2580 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2584 * User asked to set font; we are guaranteed that
2585 * a) width and height are in range 1..32
2586 * b) charcount does not exceed 512
2587 * but lets not assume that, since someone might someday want to use larger
2588 * fonts. And charcount of 512 is small for unicode support.
2590 * However, user space gives the font in 32 rows , regardless of
2591 * actual font height. So a new API is needed if support for larger fonts
2592 * is ever implemented.
2595 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2597 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2598 unsigned charcount
= font
->charcount
;
2599 int w
= font
->width
;
2600 int h
= font
->height
;
2603 u8
*new_data
, *data
= font
->data
;
2604 int pitch
= (font
->width
+7) >> 3;
2606 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2607 * If not this check should be changed to charcount < 256 */
2608 if (charcount
!= 256 && charcount
!= 512)
2611 /* Make sure drawing engine can handle the font */
2612 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2613 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2616 /* Make sure driver can handle the font length */
2617 if (fbcon_invalid_charcount(info
, charcount
))
2620 size
= h
* pitch
* charcount
;
2622 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2627 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2628 FNTSIZE(new_data
) = size
;
2629 FNTCHARCNT(new_data
) = charcount
;
2630 REFCOUNT(new_data
) = 0; /* usage counter */
2631 for (i
=0; i
< charcount
; i
++) {
2632 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2635 /* Since linux has a nice crc32 function use it for counting font
2637 csum
= crc32(0, new_data
, size
);
2639 FNTSUM(new_data
) = csum
;
2640 /* Check if the same font is on some other console already */
2641 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2642 struct vc_data
*tmp
= vc_cons
[i
].d
;
2644 if (fb_display
[i
].userfont
&&
2645 fb_display
[i
].fontdata
&&
2646 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2647 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2648 tmp
->vc_font
.width
== w
&&
2649 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2650 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2651 new_data
= (u8
*)fb_display
[i
].fontdata
;
2655 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2658 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2660 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2661 const struct font_desc
*f
;
2664 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2665 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2666 else if (!(f
= find_font(name
)))
2669 font
->width
= f
->width
;
2670 font
->height
= f
->height
;
2671 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2674 static u16 palette_red
[16];
2675 static u16 palette_green
[16];
2676 static u16 palette_blue
[16];
2678 static struct fb_cmap palette_cmap
= {
2679 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2682 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2684 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2688 if (fbcon_is_inactive(vc
, info
))
2691 if (!CON_IS_VISIBLE(vc
))
2694 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2696 for (i
= j
= 0; i
< 16; i
++) {
2698 val
= vc
->vc_palette
[j
++];
2699 palette_red
[k
] = (val
<< 8) | val
;
2700 val
= vc
->vc_palette
[j
++];
2701 palette_green
[k
] = (val
<< 8) | val
;
2702 val
= vc
->vc_palette
[j
++];
2703 palette_blue
[k
] = (val
<< 8) | val
;
2705 palette_cmap
.len
= 16;
2706 palette_cmap
.start
= 0;
2708 * If framebuffer is capable of less than 16 colors,
2709 * use default palette of fbcon.
2712 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2714 return fb_set_cmap(&palette_cmap
, info
);
2717 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2722 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2723 return (u16
*) (vc
->vc_origin
+ offset
);
2724 line
= offset
/ vc
->vc_size_row
;
2725 if (line
>= softback_lines
)
2726 return (u16
*) (vc
->vc_origin
+ offset
-
2727 softback_lines
* vc
->vc_size_row
);
2728 p
= softback_curr
+ offset
;
2729 if (p
>= softback_end
)
2730 p
+= softback_buf
- softback_end
;
2734 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2740 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2741 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2743 x
= offset
% vc
->vc_cols
;
2744 y
= offset
/ vc
->vc_cols
;
2745 if (vc
->vc_num
== fg_console
)
2746 y
+= softback_lines
;
2747 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2748 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2749 unsigned long offset
= pos
- softback_curr
;
2751 if (pos
< softback_curr
)
2752 offset
+= softback_end
- softback_buf
;
2754 x
= offset
% vc
->vc_cols
;
2755 y
= offset
/ vc
->vc_cols
;
2756 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2757 if (ret
== softback_end
)
2759 if (ret
== softback_in
)
2760 ret
= vc
->vc_origin
;
2762 /* Should not happen */
2764 ret
= vc
->vc_origin
;
2773 /* As we might be inside of softback, we may work with non-contiguous buffer,
2774 that's why we have to use a separate routine. */
2775 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2778 u16 a
= scr_readw(p
);
2779 if (!vc
->vc_can_do_color
)
2781 else if (vc
->vc_hi_font_mask
== 0x100)
2782 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2783 (((a
) & 0x0e00) << 4);
2785 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2786 (((a
) & 0x0700) << 4);
2788 if (p
== (u16
*) softback_end
)
2789 p
= (u16
*) softback_buf
;
2790 if (p
== (u16
*) softback_in
)
2791 p
= (u16
*) vc
->vc_origin
;
2795 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2797 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2798 struct fbcon_ops
*ops
= info
->fbcon_par
;
2799 struct display
*p
= &fb_display
[fg_console
];
2800 int offset
, limit
, scrollback_old
;
2803 if (vc
->vc_num
!= fg_console
)
2805 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2807 if (logo_shown
>= 0) {
2808 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2810 if (conp2
->vc_top
== logo_lines
2811 && conp2
->vc_bottom
== conp2
->vc_rows
)
2813 if (logo_shown
== vc
->vc_num
) {
2819 logo_lines
* vc
->vc_size_row
;
2820 for (i
= 0; i
< logo_lines
; i
++) {
2821 if (p
== softback_top
)
2823 if (p
== softback_buf
)
2825 p
-= vc
->vc_size_row
;
2826 q
-= vc
->vc_size_row
;
2827 scr_memcpyw((u16
*) q
, (u16
*) p
,
2830 softback_in
= softback_curr
= p
;
2831 update_region(vc
, vc
->vc_origin
,
2832 logo_lines
* vc
->vc_cols
);
2834 logo_shown
= FBCON_LOGO_CANSHOW
;
2836 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2837 fbcon_redraw_softback(vc
, p
, lines
);
2838 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2842 if (!scrollback_phys_max
)
2845 scrollback_old
= scrollback_current
;
2846 scrollback_current
-= lines
;
2847 if (scrollback_current
< 0)
2848 scrollback_current
= 0;
2849 else if (scrollback_current
> scrollback_max
)
2850 scrollback_current
= scrollback_max
;
2851 if (scrollback_current
== scrollback_old
)
2854 if (fbcon_is_inactive(vc
, info
))
2857 fbcon_cursor(vc
, CM_ERASE
);
2859 offset
= p
->yscroll
- scrollback_current
;
2861 switch (p
->scrollmode
) {
2862 case SCROLL_WRAP_MOVE
:
2863 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2865 case SCROLL_PAN_MOVE
:
2866 case SCROLL_PAN_REDRAW
:
2867 limit
-= vc
->vc_rows
;
2868 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2873 else if (offset
>= limit
)
2876 ops
->var
.xoffset
= 0;
2877 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2878 ops
->update_start(info
);
2880 if (!scrollback_current
)
2881 fbcon_cursor(vc
, CM_DRAW
);
2885 static int fbcon_set_origin(struct vc_data
*vc
)
2888 fbcon_scrolldelta(vc
, softback_lines
);
2892 static void fbcon_suspended(struct fb_info
*info
)
2894 struct vc_data
*vc
= NULL
;
2895 struct fbcon_ops
*ops
= info
->fbcon_par
;
2897 if (!ops
|| ops
->currcon
< 0)
2899 vc
= vc_cons
[ops
->currcon
].d
;
2901 /* Clear cursor, restore saved data */
2902 fbcon_cursor(vc
, CM_ERASE
);
2905 static void fbcon_resumed(struct fb_info
*info
)
2908 struct fbcon_ops
*ops
= info
->fbcon_par
;
2910 if (!ops
|| ops
->currcon
< 0)
2912 vc
= vc_cons
[ops
->currcon
].d
;
2917 static void fbcon_modechanged(struct fb_info
*info
)
2919 struct fbcon_ops
*ops
= info
->fbcon_par
;
2924 if (!ops
|| ops
->currcon
< 0)
2926 vc
= vc_cons
[ops
->currcon
].d
;
2927 if (vc
->vc_mode
!= KD_TEXT
||
2928 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2931 p
= &fb_display
[vc
->vc_num
];
2932 set_blitting_type(vc
, info
);
2934 if (CON_IS_VISIBLE(vc
)) {
2935 var_to_display(p
, &info
->var
, info
);
2936 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2937 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2938 cols
/= vc
->vc_font
.width
;
2939 rows
/= vc
->vc_font
.height
;
2940 vc_resize(vc
, cols
, rows
);
2941 updatescrollmode(p
, info
, vc
);
2943 scrollback_current
= 0;
2945 if (!fbcon_is_inactive(vc
, info
)) {
2946 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2947 ops
->update_start(info
);
2950 fbcon_set_palette(vc
, color_table
);
2953 fbcon_update_softback(vc
);
2957 static void fbcon_set_all_vcs(struct fb_info
*info
)
2959 struct fbcon_ops
*ops
= info
->fbcon_par
;
2962 int i
, rows
, cols
, fg
= -1;
2964 if (!ops
|| ops
->currcon
< 0)
2967 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2969 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2970 registered_fb
[con2fb_map
[i
]] != info
)
2973 if (CON_IS_VISIBLE(vc
)) {
2978 p
= &fb_display
[vc
->vc_num
];
2979 set_blitting_type(vc
, info
);
2980 var_to_display(p
, &info
->var
, info
);
2981 cols
= FBCON_SWAP(p
->rotate
, info
->var
.xres
, info
->var
.yres
);
2982 rows
= FBCON_SWAP(p
->rotate
, info
->var
.yres
, info
->var
.xres
);
2983 cols
/= vc
->vc_font
.width
;
2984 rows
/= vc
->vc_font
.height
;
2985 vc_resize(vc
, cols
, rows
);
2989 fbcon_modechanged(info
);
2992 static int fbcon_mode_deleted(struct fb_info
*info
,
2993 struct fb_videomode
*mode
)
2995 struct fb_info
*fb_info
;
2997 int i
, j
, found
= 0;
2999 /* before deletion, ensure that mode is not in use */
3000 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3004 fb_info
= registered_fb
[j
];
3005 if (fb_info
!= info
)
3010 if (fb_mode_is_equal(p
->mode
, mode
)) {
3018 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3019 static int fbcon_unbind(void)
3023 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
3028 static inline int fbcon_unbind(void)
3032 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3034 static int fbcon_fb_unbind(int idx
)
3036 int i
, new_idx
= -1, ret
= 0;
3038 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3039 if (con2fb_map
[i
] != idx
&&
3040 con2fb_map
[i
] != -1) {
3046 if (new_idx
!= -1) {
3047 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3048 if (con2fb_map
[i
] == idx
)
3049 set_con2fb_map(i
, new_idx
, 0);
3052 ret
= fbcon_unbind();
3057 static int fbcon_fb_unregistered(struct fb_info
*info
)
3059 int i
, idx
= info
->node
;
3061 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3062 if (con2fb_map
[i
] == idx
)
3066 if (idx
== info_idx
) {
3069 for (i
= 0; i
< FB_MAX
; i
++) {
3070 if (registered_fb
[i
] != NULL
) {
3077 if (info_idx
!= -1) {
3078 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3079 if (con2fb_map
[i
] == -1)
3080 con2fb_map
[i
] = info_idx
;
3084 if (!num_registered_fb
)
3085 unregister_con_driver(&fb_con
);
3088 if (primary_device
== idx
)
3089 primary_device
= -1;
3094 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3095 static void fbcon_select_primary(struct fb_info
*info
)
3097 if (!map_override
&& primary_device
== -1 &&
3098 fb_is_primary_device(info
)) {
3101 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3102 info
->fix
.id
, info
->node
);
3103 primary_device
= info
->node
;
3105 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3106 con2fb_map_boot
[i
] = primary_device
;
3108 if (con_is_bound(&fb_con
)) {
3109 printk(KERN_INFO
"fbcon: Remapping primary device, "
3110 "fb%i, to tty %i-%i\n", info
->node
,
3111 first_fb_vc
+ 1, last_fb_vc
+ 1);
3112 info_idx
= primary_device
;
3118 static inline void fbcon_select_primary(struct fb_info
*info
)
3122 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3124 static int fbcon_fb_registered(struct fb_info
*info
)
3126 int ret
= 0, i
, idx
= info
->node
;
3128 fbcon_select_primary(info
);
3130 if (info_idx
== -1) {
3131 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3132 if (con2fb_map_boot
[i
] == idx
) {
3139 ret
= fbcon_takeover(1);
3141 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3142 if (con2fb_map_boot
[i
] == idx
)
3143 set_con2fb_map(i
, idx
, 0);
3150 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3152 struct fbcon_ops
*ops
= info
->fbcon_par
;
3155 if (!ops
|| ops
->currcon
< 0)
3158 vc
= vc_cons
[ops
->currcon
].d
;
3159 if (vc
->vc_mode
!= KD_TEXT
||
3160 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3163 if (CON_IS_VISIBLE(vc
)) {
3167 do_unblank_screen(0);
3169 ops
->blank_state
= blank
;
3172 static void fbcon_new_modelist(struct fb_info
*info
)
3176 struct fb_var_screeninfo var
;
3177 const struct fb_videomode
*mode
;
3179 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3180 if (registered_fb
[con2fb_map
[i
]] != info
)
3182 if (!fb_display
[i
].mode
)
3185 display_to_var(&var
, &fb_display
[i
]);
3186 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3188 fb_videomode_to_var(&var
, mode
);
3189 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3193 static void fbcon_get_requirement(struct fb_info
*info
,
3194 struct fb_blit_caps
*caps
)
3202 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3204 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3205 info
->node
== con2fb_map
[i
]) {
3207 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3208 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3209 charcnt
= (p
->userfont
) ?
3210 FNTCHARCNT(p
->fontdata
) : 256;
3211 if (caps
->len
< charcnt
)
3212 caps
->len
= charcnt
;
3216 vc
= vc_cons
[fg_console
].d
;
3218 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3219 info
->node
== con2fb_map
[fg_console
]) {
3220 p
= &fb_display
[fg_console
];
3221 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3222 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3223 caps
->len
= (p
->userfont
) ?
3224 FNTCHARCNT(p
->fontdata
) : 256;
3229 static int fbcon_event_notify(struct notifier_block
*self
,
3230 unsigned long action
, void *data
)
3232 struct fb_event
*event
= data
;
3233 struct fb_info
*info
= event
->info
;
3234 struct fb_videomode
*mode
;
3235 struct fb_con2fbmap
*con2fb
;
3236 struct fb_blit_caps
*caps
;
3240 * ignore all events except driver registration and deregistration
3241 * if fbcon is not active
3243 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3244 action
== FB_EVENT_FB_UNREGISTERED
))
3248 case FB_EVENT_SUSPEND
:
3249 fbcon_suspended(info
);
3251 case FB_EVENT_RESUME
:
3252 fbcon_resumed(info
);
3254 case FB_EVENT_MODE_CHANGE
:
3255 fbcon_modechanged(info
);
3257 case FB_EVENT_MODE_CHANGE_ALL
:
3258 fbcon_set_all_vcs(info
);
3260 case FB_EVENT_MODE_DELETE
:
3262 ret
= fbcon_mode_deleted(info
, mode
);
3264 case FB_EVENT_FB_UNBIND
:
3265 ret
= fbcon_fb_unbind(info
->node
);
3267 case FB_EVENT_FB_REGISTERED
:
3268 ret
= fbcon_fb_registered(info
);
3270 case FB_EVENT_FB_UNREGISTERED
:
3271 ret
= fbcon_fb_unregistered(info
);
3273 case FB_EVENT_SET_CONSOLE_MAP
:
3274 con2fb
= event
->data
;
3275 ret
= set_con2fb_map(con2fb
->console
- 1,
3276 con2fb
->framebuffer
, 1);
3278 case FB_EVENT_GET_CONSOLE_MAP
:
3279 con2fb
= event
->data
;
3280 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3282 case FB_EVENT_BLANK
:
3283 fbcon_fb_blanked(info
, *(int *)event
->data
);
3285 case FB_EVENT_NEW_MODELIST
:
3286 fbcon_new_modelist(info
);
3288 case FB_EVENT_GET_REQ
:
3290 fbcon_get_requirement(info
, caps
);
3299 * The console `switch' structure for the frame buffer based console
3302 static const struct consw fb_con
= {
3303 .owner
= THIS_MODULE
,
3304 .con_startup
= fbcon_startup
,
3305 .con_init
= fbcon_init
,
3306 .con_deinit
= fbcon_deinit
,
3307 .con_clear
= fbcon_clear
,
3308 .con_putc
= fbcon_putc
,
3309 .con_putcs
= fbcon_putcs
,
3310 .con_cursor
= fbcon_cursor
,
3311 .con_scroll
= fbcon_scroll
,
3312 .con_bmove
= fbcon_bmove
,
3313 .con_switch
= fbcon_switch
,
3314 .con_blank
= fbcon_blank
,
3315 .con_font_set
= fbcon_set_font
,
3316 .con_font_get
= fbcon_get_font
,
3317 .con_font_default
= fbcon_set_def_font
,
3318 .con_font_copy
= fbcon_copy_font
,
3319 .con_set_palette
= fbcon_set_palette
,
3320 .con_scrolldelta
= fbcon_scrolldelta
,
3321 .con_set_origin
= fbcon_set_origin
,
3322 .con_invert_region
= fbcon_invert_region
,
3323 .con_screen_pos
= fbcon_screen_pos
,
3324 .con_getxy
= fbcon_getxy
,
3325 .con_resize
= fbcon_resize
,
3328 static struct notifier_block fbcon_event_notifier
= {
3329 .notifier_call
= fbcon_event_notify
,
3332 static ssize_t
store_rotate(struct device
*device
,
3333 struct device_attribute
*attr
, const char *buf
,
3336 struct fb_info
*info
;
3340 if (fbcon_has_exited
)
3343 acquire_console_sem();
3344 idx
= con2fb_map
[fg_console
];
3346 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3349 info
= registered_fb
[idx
];
3350 rotate
= simple_strtoul(buf
, last
, 0);
3351 fbcon_rotate(info
, rotate
);
3353 release_console_sem();
3357 static ssize_t
store_rotate_all(struct device
*device
,
3358 struct device_attribute
*attr
,const char *buf
,
3361 struct fb_info
*info
;
3365 if (fbcon_has_exited
)
3368 acquire_console_sem();
3369 idx
= con2fb_map
[fg_console
];
3371 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3374 info
= registered_fb
[idx
];
3375 rotate
= simple_strtoul(buf
, last
, 0);
3376 fbcon_rotate_all(info
, rotate
);
3378 release_console_sem();
3382 static ssize_t
show_rotate(struct device
*device
,
3383 struct device_attribute
*attr
,char *buf
)
3385 struct fb_info
*info
;
3386 int rotate
= 0, idx
;
3388 if (fbcon_has_exited
)
3391 acquire_console_sem();
3392 idx
= con2fb_map
[fg_console
];
3394 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3397 info
= registered_fb
[idx
];
3398 rotate
= fbcon_get_rotate(info
);
3400 release_console_sem();
3401 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3404 static ssize_t
show_cursor_blink(struct device
*device
,
3405 struct device_attribute
*attr
, char *buf
)
3407 struct fb_info
*info
;
3408 struct fbcon_ops
*ops
;
3409 int idx
, blink
= -1;
3411 if (fbcon_has_exited
)
3414 acquire_console_sem();
3415 idx
= con2fb_map
[fg_console
];
3417 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3420 info
= registered_fb
[idx
];
3421 ops
= info
->fbcon_par
;
3426 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3428 release_console_sem();
3429 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3432 static ssize_t
store_cursor_blink(struct device
*device
,
3433 struct device_attribute
*attr
,
3434 const char *buf
, size_t count
)
3436 struct fb_info
*info
;
3440 if (fbcon_has_exited
)
3443 acquire_console_sem();
3444 idx
= con2fb_map
[fg_console
];
3446 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3449 info
= registered_fb
[idx
];
3451 if (!info
->fbcon_par
)
3454 blink
= simple_strtoul(buf
, last
, 0);
3457 fbcon_cursor_noblink
= 0;
3458 fbcon_add_cursor_timer(info
);
3460 fbcon_cursor_noblink
= 1;
3461 fbcon_del_cursor_timer(info
);
3465 release_console_sem();
3469 static struct device_attribute device_attrs
[] = {
3470 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3471 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3472 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3473 store_cursor_blink
),
3476 static int fbcon_init_device(void)
3480 fbcon_has_sysfs
= 1;
3482 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3483 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3491 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3493 fbcon_has_sysfs
= 0;
3499 static void fbcon_start(void)
3501 if (num_registered_fb
) {
3504 acquire_console_sem();
3506 for (i
= 0; i
< FB_MAX
; i
++) {
3507 if (registered_fb
[i
] != NULL
) {
3513 release_console_sem();
3518 static void fbcon_exit(void)
3520 struct fb_info
*info
;
3523 if (fbcon_has_exited
)
3527 free_irq(IRQ_AUTO_4
, fb_vbl_handler
);
3530 if (MACH_IS_MAC
&& vbl_detected
)
3531 free_irq(IRQ_MAC_VBL
, fb_vbl_handler
);
3534 kfree((void *)softback_buf
);
3537 for (i
= 0; i
< FB_MAX
; i
++) {
3539 info
= registered_fb
[i
];
3544 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3545 if (con2fb_map
[j
] == i
)
3550 if (info
->fbops
->fb_release
)
3551 info
->fbops
->fb_release(info
, 0);
3552 module_put(info
->fbops
->owner
);
3554 if (info
->fbcon_par
) {
3555 struct fbcon_ops
*ops
= info
->fbcon_par
;
3557 fbcon_del_cursor_timer(info
);
3558 kfree(ops
->cursor_src
);
3559 kfree(info
->fbcon_par
);
3560 info
->fbcon_par
= NULL
;
3563 if (info
->queue
.func
== fb_flashcursor
)
3564 info
->queue
.func
= NULL
;
3568 fbcon_has_exited
= 1;
3571 static int __init
fb_console_init(void)
3575 acquire_console_sem();
3576 fb_register_client(&fbcon_event_notifier
);
3577 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), "fbcon");
3579 if (IS_ERR(fbcon_device
)) {
3580 printk(KERN_WARNING
"Unable to create device "
3581 "for fbcon; errno = %ld\n",
3582 PTR_ERR(fbcon_device
));
3583 fbcon_device
= NULL
;
3585 fbcon_init_device();
3587 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3590 release_console_sem();
3595 module_init(fb_console_init
);
3599 static void __exit
fbcon_deinit_device(void)
3603 if (fbcon_has_sysfs
) {
3604 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3605 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3607 fbcon_has_sysfs
= 0;
3611 static void __exit
fb_console_exit(void)
3613 acquire_console_sem();
3614 fb_unregister_client(&fbcon_event_notifier
);
3615 fbcon_deinit_device();
3616 device_destroy(fb_class
, MKDEV(0, 0));
3618 release_console_sem();
3619 unregister_con_driver(&fb_con
);
3622 module_exit(fb_console_exit
);
3626 MODULE_LICENSE("GPL");