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 #define CURSOR_DRAW_DELAY (1)
151 static int vbl_cursor_cnt
;
152 static int fbcon_cursor_noblink
;
154 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
157 * Interface used by the world
160 static const char *fbcon_startup(void);
161 static void fbcon_init(struct vc_data
*vc
, int init
);
162 static void fbcon_deinit(struct vc_data
*vc
);
163 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
165 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
166 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
167 int count
, int ypos
, int xpos
);
168 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
169 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
170 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
172 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
173 int height
, int width
);
174 static int fbcon_switch(struct vc_data
*vc
);
175 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
176 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
177 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
182 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
183 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
184 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
185 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
186 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
187 int dy
, int dx
, int height
, int width
, u_int y_break
);
188 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
190 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
191 int line
, int count
, int dy
);
192 static void fbcon_modechanged(struct fb_info
*info
);
193 static void fbcon_set_all_vcs(struct fb_info
*info
);
194 static void fbcon_start(void);
195 static void fbcon_exit(void);
196 static struct device
*fbcon_device
;
198 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
199 static inline void fbcon_set_rotation(struct fb_info
*info
)
201 struct fbcon_ops
*ops
= info
->fbcon_par
;
203 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
204 ops
->p
->con_rotate
< 4)
205 ops
->rotate
= ops
->p
->con_rotate
;
210 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
212 struct fbcon_ops
*ops
= info
->fbcon_par
;
213 struct fb_info
*fb_info
;
215 if (!ops
|| ops
->currcon
== -1)
218 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
220 if (info
== fb_info
) {
221 struct display
*p
= &fb_display
[ops
->currcon
];
224 p
->con_rotate
= rotate
;
228 fbcon_modechanged(info
);
232 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
234 struct fbcon_ops
*ops
= info
->fbcon_par
;
239 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
242 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
244 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
245 registered_fb
[con2fb_map
[i
]] != info
)
248 p
= &fb_display
[vc
->vc_num
];
249 p
->con_rotate
= rotate
;
252 fbcon_set_all_vcs(info
);
255 static inline void fbcon_set_rotation(struct fb_info
*info
)
257 struct fbcon_ops
*ops
= info
->fbcon_par
;
259 ops
->rotate
= FB_ROTATE_UR
;
262 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
267 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
271 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
273 static int fbcon_get_rotate(struct fb_info
*info
)
275 struct fbcon_ops
*ops
= info
->fbcon_par
;
277 return (ops
) ? ops
->rotate
: 0;
280 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
282 struct fbcon_ops
*ops
= info
->fbcon_par
;
284 return (info
->state
!= FBINFO_STATE_RUNNING
||
285 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
) &&
286 !vt_force_oops_output(vc
);
289 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
292 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
295 if (console_blanked
) {
296 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
298 c
= vc
->vc_video_erase_char
& charmask
;
302 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
303 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
308 int col
= mono_col(info
);
310 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
311 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
316 color
= (is_fg
) ? fg
: bg
;
321 * Scale down 16-colors to 4 colors. Default 4-color palette
322 * is grayscale. However, simply dividing the values by 4
323 * will not work, as colors 1, 2 and 3 will be scaled-down
324 * to zero rendering them invisible. So empirically convert
325 * colors to a sane 4-level grayscale.
329 color
= 0; /* black */
332 color
= 2; /* white */
335 color
= 1; /* gray */
338 color
= 3; /* intense white */
344 * Last 8 entries of default 16-color palette is a more intense
345 * version of the first 8 (i.e., same chrominance, different
356 static void fbcon_update_softback(struct vc_data
*vc
)
358 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
361 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
363 /* Smaller scrollback makes no sense, and 0 would screw
364 the operation totally */
368 static void fb_flashcursor(struct work_struct
*work
)
370 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
371 struct fbcon_ops
*ops
= info
->fbcon_par
;
372 struct vc_data
*vc
= NULL
;
377 ret
= console_trylock();
381 if (ops
&& ops
->currcon
!= -1)
382 vc
= vc_cons
[ops
->currcon
].d
;
384 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
385 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
391 c
= scr_readw((u16
*) vc
->vc_pos
);
392 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
394 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
395 get_color(vc
, info
, c
, 0));
399 static void cursor_timer_handler(unsigned long dev_addr
)
401 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
402 struct fbcon_ops
*ops
= info
->fbcon_par
;
404 schedule_work(&info
->queue
);
405 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
408 static void fbcon_add_cursor_timer(struct fb_info
*info
)
410 struct fbcon_ops
*ops
= info
->fbcon_par
;
412 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
413 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
414 !fbcon_cursor_noblink
) {
415 if (!info
->queue
.func
)
416 INIT_WORK(&info
->queue
, fb_flashcursor
);
418 init_timer(&ops
->cursor_timer
);
419 ops
->cursor_timer
.function
= cursor_timer_handler
;
420 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
421 ops
->cursor_timer
.data
= (unsigned long ) info
;
422 add_timer(&ops
->cursor_timer
);
423 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
427 static void fbcon_del_cursor_timer(struct fb_info
*info
)
429 struct fbcon_ops
*ops
= info
->fbcon_par
;
431 if (info
->queue
.func
== fb_flashcursor
&&
432 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
433 del_timer_sync(&ops
->cursor_timer
);
434 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
439 static int __init
fb_console_setup(char *this_opt
)
444 if (!this_opt
|| !*this_opt
)
447 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
448 if (!strncmp(options
, "font:", 5))
449 strcpy(fontname
, options
+ 5);
451 if (!strncmp(options
, "scrollback:", 11)) {
454 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
455 if (*options
== 'k' || *options
== 'K') {
456 fbcon_softback_size
*= 1024;
466 if (!strncmp(options
, "map:", 4)) {
469 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
473 (options
[j
++]-'0') % FB_MAX
;
476 fbcon_map_override();
482 if (!strncmp(options
, "vc:", 3)) {
485 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
488 if (*options
++ == '-')
489 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
490 fbcon_is_default
= 0;
493 if (!strncmp(options
, "rotate:", 7)) {
496 initial_rotation
= simple_strtoul(options
, &options
, 0);
497 if (initial_rotation
> 3)
498 initial_rotation
= 0;
504 __setup("fbcon=", fb_console_setup
);
507 static int search_fb_in_map(int idx
)
511 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
512 if (con2fb_map
[i
] == idx
)
518 static int search_for_mapped_con(void)
522 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
523 if (con2fb_map
[i
] != -1)
529 static int fbcon_takeover(int show_logo
)
533 if (!num_registered_fb
)
537 logo_shown
= FBCON_LOGO_DONTSHOW
;
539 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
540 con2fb_map
[i
] = info_idx
;
542 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
546 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
551 fbcon_has_console_bind
= 1;
558 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
559 int cols
, int rows
, int new_cols
, int new_rows
)
561 logo_shown
= FBCON_LOGO_DONTSHOW
;
564 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
565 int cols
, int rows
, int new_cols
, int new_rows
)
567 /* Need to make room for the logo */
568 struct fbcon_ops
*ops
= info
->fbcon_par
;
569 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
570 unsigned short *save
= NULL
, *r
, *q
;
573 if (info
->flags
& FBINFO_MODULE
) {
574 logo_shown
= FBCON_LOGO_DONTSHOW
;
579 * remove underline attribute from erase character
580 * if black and white framebuffer.
582 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
584 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
585 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
586 q
= (unsigned short *) (vc
->vc_origin
+
587 vc
->vc_size_row
* rows
);
588 step
= logo_lines
* cols
;
589 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
590 if (scr_readw(r
) != vc
->vc_video_erase_char
)
592 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
593 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
595 int i
= cols
< new_cols
? cols
: new_cols
;
596 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
598 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
599 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
604 /* We can scroll screen down */
606 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
607 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
612 if (vc
->vc_y
+ logo_lines
>= rows
)
613 lines
= rows
- vc
->vc_y
- 1;
617 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
620 scr_memsetw((unsigned short *) vc
->vc_origin
,
622 vc
->vc_size_row
* logo_lines
);
624 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
625 fbcon_clear_margins(vc
, 0);
630 q
= (unsigned short *) (vc
->vc_origin
+
633 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
634 vc
->vc_y
+= logo_lines
;
635 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
639 if (logo_lines
> vc
->vc_bottom
) {
640 logo_shown
= FBCON_LOGO_CANSHOW
;
642 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
643 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
644 logo_shown
= FBCON_LOGO_DRAW
;
645 vc
->vc_top
= logo_lines
;
650 #ifdef CONFIG_FB_TILEBLITTING
651 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
653 struct fbcon_ops
*ops
= info
->fbcon_par
;
655 ops
->p
= &fb_display
[vc
->vc_num
];
657 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
658 fbcon_set_tileops(vc
, info
);
660 fbcon_set_rotation(info
);
661 fbcon_set_bitops(ops
);
665 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
669 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
670 info
->tileops
->fb_get_tilemax(info
) < charcount
)
676 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
678 struct fbcon_ops
*ops
= info
->fbcon_par
;
680 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
681 ops
->p
= &fb_display
[vc
->vc_num
];
682 fbcon_set_rotation(info
);
683 fbcon_set_bitops(ops
);
686 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
691 #endif /* CONFIG_MISC_TILEBLITTING */
694 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
695 int unit
, int oldidx
)
697 struct fbcon_ops
*ops
= NULL
;
700 if (!try_module_get(info
->fbops
->owner
))
703 if (!err
&& info
->fbops
->fb_open
&&
704 info
->fbops
->fb_open(info
, 0))
708 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
714 info
->fbcon_par
= ops
;
717 set_blitting_type(vc
, info
);
721 con2fb_map
[unit
] = oldidx
;
722 module_put(info
->fbops
->owner
);
728 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
729 struct fb_info
*newinfo
, int unit
,
730 int oldidx
, int found
)
732 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
735 if (oldinfo
->fbops
->fb_release
&&
736 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
737 con2fb_map
[unit
] = oldidx
;
738 if (!found
&& newinfo
->fbops
->fb_release
)
739 newinfo
->fbops
->fb_release(newinfo
, 0);
741 module_put(newinfo
->fbops
->owner
);
746 fbcon_del_cursor_timer(oldinfo
);
747 kfree(ops
->cursor_state
.mask
);
748 kfree(ops
->cursor_data
);
749 kfree(ops
->fontbuffer
);
750 kfree(oldinfo
->fbcon_par
);
751 oldinfo
->fbcon_par
= NULL
;
752 module_put(oldinfo
->fbops
->owner
);
754 If oldinfo and newinfo are driving the same hardware,
755 the fb_release() method of oldinfo may attempt to
756 restore the hardware state. This will leave the
757 newinfo in an undefined state. Thus, a call to
758 fb_set_par() may be needed for the newinfo.
760 if (newinfo
->fbops
->fb_set_par
) {
761 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
764 printk(KERN_ERR
"con2fb_release_oldinfo: "
765 "detected unhandled fb_set_par error, "
766 "error code %d\n", ret
);
773 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
774 int unit
, int show_logo
)
776 struct fbcon_ops
*ops
= info
->fbcon_par
;
779 ops
->currcon
= fg_console
;
781 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
782 ret
= info
->fbops
->fb_set_par(info
);
785 printk(KERN_ERR
"con2fb_init_display: detected "
786 "unhandled fb_set_par error, "
787 "error code %d\n", ret
);
790 ops
->flags
|= FBCON_FLAGS_INIT
;
792 fbcon_set_disp(info
, &info
->var
, unit
);
795 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
796 struct fb_info
*fg_info
=
797 registered_fb
[con2fb_map
[fg_console
]];
799 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
800 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
804 update_screen(vc_cons
[fg_console
].d
);
808 * set_con2fb_map - map console to frame buffer device
809 * @unit: virtual console number to map
810 * @newidx: frame buffer index to map virtual console to
811 * @user: user request
813 * Maps a virtual console @unit to a frame buffer device
816 static int set_con2fb_map(int unit
, int newidx
, int user
)
818 struct vc_data
*vc
= vc_cons
[unit
].d
;
819 int oldidx
= con2fb_map
[unit
];
820 struct fb_info
*info
= registered_fb
[newidx
];
821 struct fb_info
*oldinfo
= NULL
;
824 if (oldidx
== newidx
)
830 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
832 return fbcon_takeover(0);
836 oldinfo
= registered_fb
[oldidx
];
838 found
= search_fb_in_map(newidx
);
841 con2fb_map
[unit
] = newidx
;
843 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
847 * If old fb is not mapped to any of the consoles,
848 * fbcon should release it.
850 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
851 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
855 int show_logo
= (fg_console
== 0 && !user
&&
856 logo_shown
!= FBCON_LOGO_DONTSHOW
);
859 fbcon_add_cursor_timer(info
);
860 con2fb_map_boot
[unit
] = newidx
;
861 con2fb_init_display(vc
, info
, unit
, show_logo
);
864 if (!search_fb_in_map(info_idx
))
872 * Low Level Operations
874 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
875 static int var_to_display(struct display
*disp
,
876 struct fb_var_screeninfo
*var
,
877 struct fb_info
*info
)
879 disp
->xres_virtual
= var
->xres_virtual
;
880 disp
->yres_virtual
= var
->yres_virtual
;
881 disp
->bits_per_pixel
= var
->bits_per_pixel
;
882 disp
->grayscale
= var
->grayscale
;
883 disp
->nonstd
= var
->nonstd
;
884 disp
->accel_flags
= var
->accel_flags
;
885 disp
->height
= var
->height
;
886 disp
->width
= var
->width
;
887 disp
->red
= var
->red
;
888 disp
->green
= var
->green
;
889 disp
->blue
= var
->blue
;
890 disp
->transp
= var
->transp
;
891 disp
->rotate
= var
->rotate
;
892 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
893 if (disp
->mode
== NULL
)
894 /* This should not happen */
899 static void display_to_var(struct fb_var_screeninfo
*var
,
900 struct display
*disp
)
902 fb_videomode_to_var(var
, disp
->mode
);
903 var
->xres_virtual
= disp
->xres_virtual
;
904 var
->yres_virtual
= disp
->yres_virtual
;
905 var
->bits_per_pixel
= disp
->bits_per_pixel
;
906 var
->grayscale
= disp
->grayscale
;
907 var
->nonstd
= disp
->nonstd
;
908 var
->accel_flags
= disp
->accel_flags
;
909 var
->height
= disp
->height
;
910 var
->width
= disp
->width
;
911 var
->red
= disp
->red
;
912 var
->green
= disp
->green
;
913 var
->blue
= disp
->blue
;
914 var
->transp
= disp
->transp
;
915 var
->rotate
= disp
->rotate
;
918 static const char *fbcon_startup(void)
920 const char *display_desc
= "frame buffer device";
921 struct display
*p
= &fb_display
[fg_console
];
922 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
923 const struct font_desc
*font
= NULL
;
924 struct module
*owner
;
925 struct fb_info
*info
= NULL
;
926 struct fbcon_ops
*ops
;
930 * If num_registered_fb is zero, this is a call for the dummy part.
931 * The frame buffer devices weren't initialized yet.
933 if (!num_registered_fb
|| info_idx
== -1)
936 * Instead of blindly using registered_fb[0], we use info_idx, set by
939 info
= registered_fb
[info_idx
];
943 owner
= info
->fbops
->owner
;
944 if (!try_module_get(owner
))
946 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
951 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
959 ops
->cur_rotate
= -1;
960 info
->fbcon_par
= ops
;
961 p
->con_rotate
= initial_rotation
;
962 set_blitting_type(vc
, info
);
964 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
965 if (fbcon_softback_size
) {
969 kmalloc(fbcon_softback_size
,
972 fbcon_softback_size
= 0;
978 kfree((void *) softback_buf
);
984 softback_in
= softback_top
= softback_curr
=
989 /* Setup default font */
991 if (!fontname
[0] || !(font
= find_font(fontname
)))
992 font
= get_default_font(info
->var
.xres
,
995 info
->pixmap
.blit_y
);
996 vc
->vc_font
.width
= font
->width
;
997 vc
->vc_font
.height
= font
->height
;
998 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
999 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1002 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1003 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1004 cols
/= vc
->vc_font
.width
;
1005 rows
/= vc
->vc_font
.height
;
1006 vc_resize(vc
, cols
, rows
);
1008 DPRINTK("mode: %s\n", info
->fix
.id
);
1009 DPRINTK("visual: %d\n", info
->fix
.visual
);
1010 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1012 info
->var
.bits_per_pixel
);
1014 fbcon_add_cursor_timer(info
);
1015 fbcon_has_exited
= 0;
1016 return display_desc
;
1019 static void fbcon_init(struct vc_data
*vc
, int init
)
1021 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1022 struct fbcon_ops
*ops
;
1023 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1024 struct vc_data
*svc
= *default_mode
;
1025 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1026 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1029 if (info_idx
== -1 || info
== NULL
)
1034 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1035 (info
->fix
.type
== FB_TYPE_TEXT
))
1038 if (var_to_display(p
, &info
->var
, info
))
1041 if (!info
->fbcon_par
)
1042 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1044 /* If we are not the first console on this
1045 fb, copy the font from that console */
1046 t
= &fb_display
[fg_console
];
1049 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1051 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1053 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1054 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1055 p
->userfont
= t
->userfont
;
1058 REFCOUNT(p
->fontdata
)++;
1060 const struct font_desc
*font
= NULL
;
1062 if (!fontname
[0] || !(font
= find_font(fontname
)))
1063 font
= get_default_font(info
->var
.xres
,
1065 info
->pixmap
.blit_x
,
1066 info
->pixmap
.blit_y
);
1067 vc
->vc_font
.width
= font
->width
;
1068 vc
->vc_font
.height
= font
->height
;
1069 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1070 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1071 support more fonts */
1076 charcnt
= FNTCHARCNT(p
->fontdata
);
1078 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1079 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1080 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1081 if (charcnt
== 256) {
1082 vc
->vc_hi_font_mask
= 0;
1084 vc
->vc_hi_font_mask
= 0x100;
1085 if (vc
->vc_can_do_color
)
1086 vc
->vc_complement_mask
<<= 1;
1089 if (!*svc
->vc_uni_pagedir_loc
)
1090 con_set_default_unimap(svc
);
1091 if (!*vc
->vc_uni_pagedir_loc
)
1092 con_copy_unimap(vc
, svc
);
1094 ops
= info
->fbcon_par
;
1095 p
->con_rotate
= initial_rotation
;
1096 set_blitting_type(vc
, info
);
1100 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1101 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1102 new_cols
/= vc
->vc_font
.width
;
1103 new_rows
/= vc
->vc_font
.height
;
1106 * We must always set the mode. The mode of the previous console
1107 * driver could be in the same resolution but we are using different
1108 * hardware so we have to initialize the hardware.
1110 * We need to do it in fbcon_init() to prevent screen corruption.
1112 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1113 if (info
->fbops
->fb_set_par
&&
1114 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1115 ret
= info
->fbops
->fb_set_par(info
);
1118 printk(KERN_ERR
"fbcon_init: detected "
1119 "unhandled fb_set_par error, "
1120 "error code %d\n", ret
);
1123 ops
->flags
|= FBCON_FLAGS_INIT
;
1128 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1129 !(cap
& FBINFO_HWACCEL_DISABLED
))
1130 p
->scrollmode
= SCROLL_MOVE
;
1131 else /* default to something safe */
1132 p
->scrollmode
= SCROLL_REDRAW
;
1135 * ++guenther: console.c:vc_allocate() relies on initializing
1136 * vc_{cols,rows}, but we must not set those if we are only
1137 * resizing the console.
1140 vc
->vc_cols
= new_cols
;
1141 vc
->vc_rows
= new_rows
;
1143 vc_resize(vc
, new_cols
, new_rows
);
1146 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1148 if (vc
== svc
&& softback_buf
)
1149 fbcon_update_softback(vc
);
1151 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1152 ops
->rotate
= FB_ROTATE_UR
;
1153 set_blitting_type(vc
, info
);
1156 ops
->p
= &fb_display
[fg_console
];
1159 static void fbcon_free_font(struct display
*p
)
1161 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1162 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1167 static void fbcon_deinit(struct vc_data
*vc
)
1169 struct display
*p
= &fb_display
[vc
->vc_num
];
1170 struct fb_info
*info
;
1171 struct fbcon_ops
*ops
;
1175 idx
= con2fb_map
[vc
->vc_num
];
1180 info
= registered_fb
[idx
];
1185 ops
= info
->fbcon_par
;
1190 if (CON_IS_VISIBLE(vc
))
1191 fbcon_del_cursor_timer(info
);
1193 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1196 if (!con_is_bound(&fb_con
))
1202 /* ====================================================================== */
1204 /* fbcon_XXX routines - interface used by the world
1206 * This system is now divided into two levels because of complications
1207 * caused by hardware scrolling. Top level functions:
1209 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1211 * handles y values in range [0, scr_height-1] that correspond to real
1212 * screen positions. y_wrap shift means that first line of bitmap may be
1213 * anywhere on this display. These functions convert lineoffsets to
1214 * bitmap offsets and deal with the wrap-around case by splitting blits.
1216 * fbcon_bmove_physical_8() -- These functions fast implementations
1217 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1218 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1222 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1223 * Implies should only really hardware scroll in rows. Only reason for
1224 * restriction is simplicity & efficiency at the moment.
1227 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1230 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1231 struct fbcon_ops
*ops
= info
->fbcon_par
;
1233 struct display
*p
= &fb_display
[vc
->vc_num
];
1236 if (fbcon_is_inactive(vc
, info
))
1239 if (!height
|| !width
)
1242 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
)
1245 /* Split blits that cross physical y_wrap boundary */
1247 y_break
= p
->vrows
- p
->yscroll
;
1248 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1249 u_int b
= y_break
- sy
;
1250 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1251 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1254 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1257 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1258 int count
, int ypos
, int xpos
)
1260 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1261 struct display
*p
= &fb_display
[vc
->vc_num
];
1262 struct fbcon_ops
*ops
= info
->fbcon_par
;
1264 if (!fbcon_is_inactive(vc
, info
))
1265 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1266 get_color(vc
, info
, scr_readw(s
), 1),
1267 get_color(vc
, info
, scr_readw(s
), 0));
1270 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1274 scr_writew(c
, &chr
);
1275 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1278 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1280 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1281 struct fbcon_ops
*ops
= info
->fbcon_par
;
1283 if (!fbcon_is_inactive(vc
, info
))
1284 ops
->clear_margins(vc
, info
, bottom_only
);
1287 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1289 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1290 struct fbcon_ops
*ops
= info
->fbcon_par
;
1292 int c
= scr_readw((u16
*) vc
->vc_pos
);
1294 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1297 if (vc
->vc_cursor_type
& 0x10)
1298 fbcon_del_cursor_timer(info
);
1300 fbcon_add_cursor_timer(info
);
1302 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1303 if (mode
& CM_SOFTBACK
) {
1304 mode
&= ~CM_SOFTBACK
;
1308 fbcon_set_origin(vc
);
1312 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1313 get_color(vc
, info
, c
, 0));
1314 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1317 static int scrollback_phys_max
= 0;
1318 static int scrollback_max
= 0;
1319 static int scrollback_current
= 0;
1321 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1324 struct display
*p
, *t
;
1325 struct vc_data
**default_mode
, *vc
;
1326 struct vc_data
*svc
;
1327 struct fbcon_ops
*ops
= info
->fbcon_par
;
1328 int rows
, cols
, charcnt
= 256;
1330 p
= &fb_display
[unit
];
1332 if (var_to_display(p
, var
, info
))
1335 vc
= vc_cons
[unit
].d
;
1340 default_mode
= vc
->vc_display_fg
;
1341 svc
= *default_mode
;
1342 t
= &fb_display
[svc
->vc_num
];
1344 if (!vc
->vc_font
.data
) {
1345 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1346 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1347 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1348 p
->userfont
= t
->userfont
;
1350 REFCOUNT(p
->fontdata
)++;
1353 charcnt
= FNTCHARCNT(p
->fontdata
);
1355 var
->activate
= FB_ACTIVATE_NOW
;
1356 info
->var
.activate
= var
->activate
;
1357 var
->yoffset
= info
->var
.yoffset
;
1358 var
->xoffset
= info
->var
.xoffset
;
1359 fb_set_var(info
, var
);
1360 ops
->var
= info
->var
;
1361 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1362 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1363 if (charcnt
== 256) {
1364 vc
->vc_hi_font_mask
= 0;
1366 vc
->vc_hi_font_mask
= 0x100;
1367 if (vc
->vc_can_do_color
)
1368 vc
->vc_complement_mask
<<= 1;
1371 if (!*svc
->vc_uni_pagedir_loc
)
1372 con_set_default_unimap(svc
);
1373 if (!*vc
->vc_uni_pagedir_loc
)
1374 con_copy_unimap(vc
, svc
);
1376 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1377 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1378 cols
/= vc
->vc_font
.width
;
1379 rows
/= vc
->vc_font
.height
;
1380 vc_resize(vc
, cols
, rows
);
1382 if (CON_IS_VISIBLE(vc
)) {
1385 fbcon_update_softback(vc
);
1389 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1391 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1392 struct fbcon_ops
*ops
= info
->fbcon_par
;
1393 struct display
*p
= &fb_display
[vc
->vc_num
];
1395 p
->yscroll
+= count
;
1396 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1397 p
->yscroll
-= p
->vrows
;
1398 ops
->var
.xoffset
= 0;
1399 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1400 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1401 ops
->update_start(info
);
1402 scrollback_max
+= count
;
1403 if (scrollback_max
> scrollback_phys_max
)
1404 scrollback_max
= scrollback_phys_max
;
1405 scrollback_current
= 0;
1408 static __inline__
void ywrap_down(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
< 0) /* 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
< 0)
1424 scrollback_current
= 0;
1427 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1429 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1430 struct display
*p
= &fb_display
[vc
->vc_num
];
1431 struct fbcon_ops
*ops
= info
->fbcon_par
;
1433 p
->yscroll
+= count
;
1434 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1435 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1436 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1437 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1440 ops
->var
.xoffset
= 0;
1441 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1442 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1443 ops
->update_start(info
);
1444 fbcon_clear_margins(vc
, 1);
1445 scrollback_max
+= count
;
1446 if (scrollback_max
> scrollback_phys_max
)
1447 scrollback_max
= scrollback_phys_max
;
1448 scrollback_current
= 0;
1451 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1453 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1454 struct fbcon_ops
*ops
= info
->fbcon_par
;
1455 struct display
*p
= &fb_display
[vc
->vc_num
];
1457 p
->yscroll
+= count
;
1459 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1460 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1461 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1464 ops
->var
.xoffset
= 0;
1465 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1466 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1467 ops
->update_start(info
);
1468 fbcon_clear_margins(vc
, 1);
1469 scrollback_max
+= count
;
1470 if (scrollback_max
> scrollback_phys_max
)
1471 scrollback_max
= scrollback_phys_max
;
1472 scrollback_current
= 0;
1475 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1477 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1478 struct display
*p
= &fb_display
[vc
->vc_num
];
1479 struct fbcon_ops
*ops
= info
->fbcon_par
;
1481 p
->yscroll
-= count
;
1482 if (p
->yscroll
< 0) {
1483 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1484 0, vc
->vc_rows
, vc
->vc_cols
);
1485 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1488 ops
->var
.xoffset
= 0;
1489 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1490 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1491 ops
->update_start(info
);
1492 fbcon_clear_margins(vc
, 1);
1493 scrollback_max
-= count
;
1494 if (scrollback_max
< 0)
1496 scrollback_current
= 0;
1499 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1501 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1502 struct fbcon_ops
*ops
= info
->fbcon_par
;
1503 struct display
*p
= &fb_display
[vc
->vc_num
];
1505 p
->yscroll
-= count
;
1507 if (p
->yscroll
< 0) {
1508 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1509 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1512 ops
->var
.xoffset
= 0;
1513 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1514 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1515 ops
->update_start(info
);
1516 fbcon_clear_margins(vc
, 1);
1517 scrollback_max
-= count
;
1518 if (scrollback_max
< 0)
1520 scrollback_current
= 0;
1523 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1526 int count
= vc
->vc_rows
;
1527 unsigned short *d
, *s
;
1531 d
= (u16
*) softback_curr
;
1532 if (d
== (u16
*) softback_in
)
1533 d
= (u16
*) vc
->vc_origin
;
1534 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1535 softback_lines
-= delta
;
1537 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1538 n
+= softback_end
- softback_buf
;
1539 if (n
< softback_top
) {
1541 (softback_top
- n
) / vc
->vc_size_row
;
1544 } else if (softback_curr
>= softback_top
1545 && n
< softback_top
) {
1547 (softback_top
- n
) / vc
->vc_size_row
;
1551 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1552 n
+= softback_buf
- softback_end
;
1553 if (n
> softback_in
) {
1557 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1562 if (n
== softback_curr
)
1565 s
= (u16
*) softback_curr
;
1566 if (s
== (u16
*) softback_in
)
1567 s
= (u16
*) vc
->vc_origin
;
1569 unsigned short *start
;
1573 unsigned short attr
= 1;
1576 le
= advance_row(s
, 1);
1579 if (attr
!= (c
& 0xff00)) {
1582 fbcon_putcs(vc
, start
, s
- start
,
1588 if (c
== scr_readw(d
)) {
1590 fbcon_putcs(vc
, start
, s
- start
,
1603 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1605 if (d
== (u16
*) softback_end
)
1606 d
= (u16
*) softback_buf
;
1607 if (d
== (u16
*) softback_in
)
1608 d
= (u16
*) vc
->vc_origin
;
1609 if (s
== (u16
*) softback_end
)
1610 s
= (u16
*) softback_buf
;
1611 if (s
== (u16
*) softback_in
)
1612 s
= (u16
*) vc
->vc_origin
;
1616 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1617 int line
, int count
, int dy
)
1619 unsigned short *s
= (unsigned short *)
1620 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1623 unsigned short *start
= s
;
1624 unsigned short *le
= advance_row(s
, 1);
1627 unsigned short attr
= 1;
1631 if (attr
!= (c
& 0xff00)) {
1634 fbcon_putcs(vc
, start
, s
- start
,
1640 console_conditional_schedule();
1644 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1645 console_conditional_schedule();
1650 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1651 struct display
*p
, int line
, int count
, int ycount
)
1653 int offset
= ycount
* vc
->vc_cols
;
1654 unsigned short *d
= (unsigned short *)
1655 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1656 unsigned short *s
= d
+ offset
;
1657 struct fbcon_ops
*ops
= info
->fbcon_par
;
1660 unsigned short *start
= s
;
1661 unsigned short *le
= advance_row(s
, 1);
1668 if (c
== scr_readw(d
)) {
1670 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1671 line
, x
, 1, s
-start
);
1681 console_conditional_schedule();
1686 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1688 console_conditional_schedule();
1693 /* NOTE: We subtract two lines from these pointers */
1694 s
-= vc
->vc_size_row
;
1695 d
-= vc
->vc_size_row
;
1700 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1701 int line
, int count
, int offset
)
1703 unsigned short *d
= (unsigned short *)
1704 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1705 unsigned short *s
= d
+ offset
;
1708 unsigned short *start
= s
;
1709 unsigned short *le
= advance_row(s
, 1);
1712 unsigned short attr
= 1;
1716 if (attr
!= (c
& 0xff00)) {
1719 fbcon_putcs(vc
, start
, s
- start
,
1725 if (c
== scr_readw(d
)) {
1727 fbcon_putcs(vc
, start
, s
- start
,
1737 console_conditional_schedule();
1742 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1743 console_conditional_schedule();
1748 /* NOTE: We subtract two lines from these pointers */
1749 s
-= vc
->vc_size_row
;
1750 d
-= vc
->vc_size_row
;
1755 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1760 if (vc
->vc_num
!= fg_console
)
1762 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1765 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1767 p
= advance_row(p
, 1);
1768 softback_in
+= vc
->vc_size_row
;
1769 if (softback_in
== softback_end
)
1770 softback_in
= softback_buf
;
1771 if (softback_in
== softback_top
) {
1772 softback_top
+= vc
->vc_size_row
;
1773 if (softback_top
== softback_end
)
1774 softback_top
= softback_buf
;
1777 softback_curr
= softback_in
;
1780 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1783 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1784 struct display
*p
= &fb_display
[vc
->vc_num
];
1785 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1787 if (fbcon_is_inactive(vc
, info
))
1790 fbcon_cursor(vc
, CM_ERASE
);
1793 * ++Geert: Only use ywrap/ypan if the console is in text mode
1794 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1795 * whole screen (prevents flicker).
1800 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1801 count
= vc
->vc_rows
;
1803 fbcon_softback_note(vc
, t
, count
);
1804 if (logo_shown
>= 0)
1806 switch (p
->scrollmode
) {
1808 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1810 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1811 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1814 vc
->vc_video_erase_char
,
1815 vc
->vc_size_row
* count
);
1819 case SCROLL_WRAP_MOVE
:
1820 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1822 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1824 ywrap_up(vc
, count
);
1825 if (vc
->vc_rows
- b
> 0)
1826 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1829 } else if (info
->flags
& FBINFO_READS_FAST
)
1830 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1831 b
- t
- count
, vc
->vc_cols
);
1834 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1837 case SCROLL_PAN_REDRAW
:
1838 if ((p
->yscroll
+ count
<=
1839 2 * (p
->vrows
- vc
->vc_rows
))
1840 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1843 3 * vc
->vc_rows
>> 2)))) {
1845 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1846 ypan_up_redraw(vc
, t
, count
);
1847 if (vc
->vc_rows
- b
> 0)
1848 fbcon_redraw_move(vc
, p
, b
,
1849 vc
->vc_rows
- b
, b
);
1851 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1852 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1855 case SCROLL_PAN_MOVE
:
1856 if ((p
->yscroll
+ count
<=
1857 2 * (p
->vrows
- vc
->vc_rows
))
1858 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1861 3 * vc
->vc_rows
>> 2)))) {
1863 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1866 if (vc
->vc_rows
- b
> 0)
1867 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1870 } else if (info
->flags
& FBINFO_READS_FAST
)
1871 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1872 b
- t
- count
, vc
->vc_cols
);
1875 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1880 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1881 count
* vc
->vc_cols
);
1882 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1883 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1886 vc
->vc_video_erase_char
,
1887 vc
->vc_size_row
* count
);
1893 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1894 count
= vc
->vc_rows
;
1895 if (logo_shown
>= 0)
1897 switch (p
->scrollmode
) {
1899 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1901 fbcon_clear(vc
, t
, 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
);
1910 case SCROLL_WRAP_MOVE
:
1911 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1912 if (vc
->vc_rows
- b
> 0)
1913 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1916 ywrap_down(vc
, count
);
1918 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1920 } else if (info
->flags
& FBINFO_READS_FAST
)
1921 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1922 b
- t
- count
, vc
->vc_cols
);
1925 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1928 case SCROLL_PAN_MOVE
:
1929 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1930 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1933 3 * vc
->vc_rows
>> 2)))) {
1934 if (vc
->vc_rows
- b
> 0)
1935 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1938 ypan_down(vc
, count
);
1940 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1942 } else if (info
->flags
& FBINFO_READS_FAST
)
1943 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1944 b
- t
- count
, vc
->vc_cols
);
1947 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1950 case SCROLL_PAN_REDRAW
:
1951 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1952 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1955 3 * vc
->vc_rows
>> 2)))) {
1956 if (vc
->vc_rows
- b
> 0)
1957 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1959 ypan_down_redraw(vc
, t
, count
);
1961 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1963 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1964 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1969 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1970 -count
* vc
->vc_cols
);
1971 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1972 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1975 vc
->vc_video_erase_char
,
1976 vc
->vc_size_row
* count
);
1984 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1985 int height
, int width
)
1987 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1988 struct display
*p
= &fb_display
[vc
->vc_num
];
1990 if (fbcon_is_inactive(vc
, info
))
1993 if (!width
|| !height
)
1996 /* Split blits that cross physical y_wrap case.
1997 * Pathological case involves 4 blits, better to use recursive
1998 * code rather than unrolled case
2000 * Recursive invocations don't need to erase the cursor over and
2001 * over again, so we use fbcon_bmove_rec()
2003 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2004 p
->vrows
- p
->yscroll
);
2007 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2008 int dy
, int dx
, int height
, int width
, u_int y_break
)
2010 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2011 struct fbcon_ops
*ops
= info
->fbcon_par
;
2014 if (sy
< y_break
&& sy
+ height
> y_break
) {
2016 if (dy
< sy
) { /* Avoid trashing self */
2017 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2019 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2020 height
- b
, width
, y_break
);
2022 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2023 height
- b
, width
, y_break
);
2024 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2030 if (dy
< y_break
&& dy
+ height
> y_break
) {
2032 if (dy
< sy
) { /* Avoid trashing self */
2033 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2035 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2036 height
- b
, width
, y_break
);
2038 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2039 height
- b
, width
, y_break
);
2040 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2045 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2049 static void updatescrollmode(struct display
*p
,
2050 struct fb_info
*info
,
2053 struct fbcon_ops
*ops
= info
->fbcon_par
;
2054 int fh
= vc
->vc_font
.height
;
2055 int cap
= info
->flags
;
2057 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2058 info
->fix
.xpanstep
);
2059 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2060 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2061 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2062 info
->var
.xres_virtual
);
2063 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2064 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2065 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2066 divides(ywrap
, vc
->vc_font
.height
) &&
2067 divides(vc
->vc_font
.height
, vyres
) &&
2068 divides(vc
->vc_font
.height
, yres
);
2069 int reading_fast
= cap
& FBINFO_READS_FAST
;
2070 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2071 !(cap
& FBINFO_HWACCEL_DISABLED
);
2072 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2073 !(cap
& FBINFO_HWACCEL_DISABLED
);
2075 p
->vrows
= vyres
/fh
;
2076 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2077 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2078 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2081 if (good_wrap
|| good_pan
) {
2082 if (reading_fast
|| fast_copyarea
)
2083 p
->scrollmode
= good_wrap
?
2084 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2086 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2089 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2090 p
->scrollmode
= SCROLL_MOVE
;
2092 p
->scrollmode
= SCROLL_REDRAW
;
2096 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2097 unsigned int height
, unsigned int user
)
2099 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2100 struct fbcon_ops
*ops
= info
->fbcon_par
;
2101 struct display
*p
= &fb_display
[vc
->vc_num
];
2102 struct fb_var_screeninfo var
= info
->var
;
2103 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2105 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2106 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2107 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2108 vc
->vc_font
.height
);
2109 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2111 var
.xres
= virt_w
* virt_fw
;
2112 var
.yres
= virt_h
* virt_fh
;
2113 x_diff
= info
->var
.xres
- var
.xres
;
2114 y_diff
= info
->var
.yres
- var
.yres
;
2115 if (x_diff
< 0 || x_diff
> virt_fw
||
2116 y_diff
< 0 || y_diff
> virt_fh
) {
2117 const struct fb_videomode
*mode
;
2119 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2120 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2123 display_to_var(&var
, p
);
2124 fb_videomode_to_var(&var
, mode
);
2126 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2129 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2130 if (CON_IS_VISIBLE(vc
)) {
2131 var
.activate
= FB_ACTIVATE_NOW
|
2133 fb_set_var(info
, &var
);
2135 var_to_display(p
, &info
->var
, info
);
2136 ops
->var
= info
->var
;
2138 updatescrollmode(p
, info
, vc
);
2142 static int fbcon_switch(struct vc_data
*vc
)
2144 struct fb_info
*info
, *old_info
= NULL
;
2145 struct fbcon_ops
*ops
;
2146 struct display
*p
= &fb_display
[vc
->vc_num
];
2147 struct fb_var_screeninfo var
;
2148 int i
, ret
, prev_console
, charcnt
= 256;
2150 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2151 ops
= info
->fbcon_par
;
2155 fbcon_set_origin(vc
);
2156 softback_top
= softback_curr
= softback_in
= softback_buf
;
2158 fbcon_update_softback(vc
);
2161 if (logo_shown
>= 0) {
2162 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2164 if (conp2
->vc_top
== logo_lines
2165 && conp2
->vc_bottom
== conp2
->vc_rows
)
2167 logo_shown
= FBCON_LOGO_CANSHOW
;
2170 prev_console
= ops
->currcon
;
2171 if (prev_console
!= -1)
2172 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2174 * FIXME: If we have multiple fbdev's loaded, we need to
2175 * update all info->currcon. Perhaps, we can place this
2176 * in a centralized structure, but this might break some
2179 * info->currcon = vc->vc_num;
2181 for (i
= 0; i
< FB_MAX
; i
++) {
2182 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2183 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2185 o
->currcon
= vc
->vc_num
;
2188 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2189 display_to_var(&var
, p
);
2190 var
.activate
= FB_ACTIVATE_NOW
;
2193 * make sure we don't unnecessarily trip the memcmp()
2196 info
->var
.activate
= var
.activate
;
2197 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2198 fb_set_var(info
, &var
);
2199 ops
->var
= info
->var
;
2201 if (old_info
!= NULL
&& (old_info
!= info
||
2202 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2203 if (info
->fbops
->fb_set_par
) {
2204 ret
= info
->fbops
->fb_set_par(info
);
2207 printk(KERN_ERR
"fbcon_switch: detected "
2208 "unhandled fb_set_par error, "
2209 "error code %d\n", ret
);
2212 if (old_info
!= info
)
2213 fbcon_del_cursor_timer(old_info
);
2216 if (fbcon_is_inactive(vc
, info
) ||
2217 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2218 fbcon_del_cursor_timer(info
);
2220 fbcon_add_cursor_timer(info
);
2222 set_blitting_type(vc
, info
);
2223 ops
->cursor_reset
= 1;
2225 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2226 ops
->rotate
= FB_ROTATE_UR
;
2227 set_blitting_type(vc
, info
);
2230 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2231 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2234 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2237 vc
->vc_complement_mask
<<= 1;
2239 updatescrollmode(p
, info
, vc
);
2241 switch (p
->scrollmode
) {
2242 case SCROLL_WRAP_MOVE
:
2243 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2245 case SCROLL_PAN_MOVE
:
2246 case SCROLL_PAN_REDRAW
:
2247 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2248 if (scrollback_phys_max
< 0)
2249 scrollback_phys_max
= 0;
2252 scrollback_phys_max
= 0;
2257 scrollback_current
= 0;
2259 if (!fbcon_is_inactive(vc
, info
)) {
2260 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2261 ops
->update_start(info
);
2264 fbcon_set_palette(vc
, color_table
);
2265 fbcon_clear_margins(vc
, 0);
2267 if (logo_shown
== FBCON_LOGO_DRAW
) {
2269 logo_shown
= fg_console
;
2270 /* This is protected above by initmem_freed */
2271 fb_show_logo(info
, ops
->rotate
);
2273 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2274 vc
->vc_size_row
* (vc
->vc_bottom
-
2281 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2284 struct fb_event event
;
2287 unsigned short charmask
= vc
->vc_hi_font_mask
?
2289 unsigned short oldc
;
2291 oldc
= vc
->vc_video_erase_char
;
2292 vc
->vc_video_erase_char
&= charmask
;
2293 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2294 vc
->vc_video_erase_char
= oldc
;
2298 if (!lock_fb_info(info
))
2301 event
.data
= &blank
;
2302 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2303 unlock_fb_info(info
);
2306 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2308 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2309 struct fbcon_ops
*ops
= info
->fbcon_par
;
2312 struct fb_var_screeninfo var
= info
->var
;
2317 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2318 fb_set_var(info
, &var
);
2320 ops
->var
= info
->var
;
2324 if (!fbcon_is_inactive(vc
, info
)) {
2325 if (ops
->blank_state
!= blank
) {
2326 ops
->blank_state
= blank
;
2327 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2328 ops
->cursor_flash
= (!blank
);
2330 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2331 if (fb_blank(info
, blank
))
2332 fbcon_generic_blank(vc
, info
, blank
);
2339 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2340 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2341 fbcon_del_cursor_timer(info
);
2343 fbcon_add_cursor_timer(info
);
2348 static int fbcon_debug_enter(struct vc_data
*vc
)
2350 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2351 struct fbcon_ops
*ops
= info
->fbcon_par
;
2353 ops
->save_graphics
= ops
->graphics
;
2355 if (info
->fbops
->fb_debug_enter
)
2356 info
->fbops
->fb_debug_enter(info
);
2357 fbcon_set_palette(vc
, color_table
);
2361 static int fbcon_debug_leave(struct vc_data
*vc
)
2363 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2364 struct fbcon_ops
*ops
= info
->fbcon_par
;
2366 ops
->graphics
= ops
->save_graphics
;
2367 if (info
->fbops
->fb_debug_leave
)
2368 info
->fbops
->fb_debug_leave(info
);
2372 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2374 u8
*fontdata
= vc
->vc_font
.data
;
2375 u8
*data
= font
->data
;
2378 font
->width
= vc
->vc_font
.width
;
2379 font
->height
= vc
->vc_font
.height
;
2380 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2384 if (font
->width
<= 8) {
2385 j
= vc
->vc_font
.height
;
2386 for (i
= 0; i
< font
->charcount
; i
++) {
2387 memcpy(data
, fontdata
, j
);
2388 memset(data
+ j
, 0, 32 - j
);
2392 } else if (font
->width
<= 16) {
2393 j
= vc
->vc_font
.height
* 2;
2394 for (i
= 0; i
< font
->charcount
; i
++) {
2395 memcpy(data
, fontdata
, j
);
2396 memset(data
+ j
, 0, 64 - j
);
2400 } else if (font
->width
<= 24) {
2401 for (i
= 0; i
< font
->charcount
; i
++) {
2402 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2403 *data
++ = fontdata
[0];
2404 *data
++ = fontdata
[1];
2405 *data
++ = fontdata
[2];
2406 fontdata
+= sizeof(u32
);
2408 memset(data
, 0, 3 * (32 - j
));
2409 data
+= 3 * (32 - j
);
2412 j
= vc
->vc_font
.height
* 4;
2413 for (i
= 0; i
< font
->charcount
; i
++) {
2414 memcpy(data
, fontdata
, j
);
2415 memset(data
+ j
, 0, 128 - j
);
2423 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2424 const u8
* data
, int userfont
)
2426 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2427 struct fbcon_ops
*ops
= info
->fbcon_par
;
2428 struct display
*p
= &fb_display
[vc
->vc_num
];
2431 char *old_data
= NULL
;
2433 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2434 fbcon_set_origin(vc
);
2436 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2438 old_data
= vc
->vc_font
.data
;
2440 cnt
= FNTCHARCNT(data
);
2443 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2444 if ((p
->userfont
= userfont
))
2446 vc
->vc_font
.width
= w
;
2447 vc
->vc_font
.height
= h
;
2448 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2449 vc
->vc_hi_font_mask
= 0;
2450 if (vc
->vc_can_do_color
) {
2451 vc
->vc_complement_mask
>>= 1;
2452 vc
->vc_s_complement_mask
>>= 1;
2455 /* ++Edmund: reorder the attribute bits */
2456 if (vc
->vc_can_do_color
) {
2457 unsigned short *cp
=
2458 (unsigned short *) vc
->vc_origin
;
2459 int count
= vc
->vc_screenbuf_size
/ 2;
2461 for (; count
> 0; count
--, cp
++) {
2463 scr_writew(((c
& 0xfe00) >> 1) |
2466 c
= vc
->vc_video_erase_char
;
2467 vc
->vc_video_erase_char
=
2468 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2471 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2472 vc
->vc_hi_font_mask
= 0x100;
2473 if (vc
->vc_can_do_color
) {
2474 vc
->vc_complement_mask
<<= 1;
2475 vc
->vc_s_complement_mask
<<= 1;
2478 /* ++Edmund: reorder the attribute bits */
2480 unsigned short *cp
=
2481 (unsigned short *) vc
->vc_origin
;
2482 int count
= vc
->vc_screenbuf_size
/ 2;
2484 for (; count
> 0; count
--, cp
++) {
2485 unsigned short newc
;
2487 if (vc
->vc_can_do_color
)
2489 ((c
& 0xff00) << 1) | (c
&
2493 scr_writew(newc
, cp
);
2495 c
= vc
->vc_video_erase_char
;
2496 if (vc
->vc_can_do_color
) {
2497 vc
->vc_video_erase_char
=
2498 ((c
& 0xff00) << 1) | (c
& 0xff);
2501 vc
->vc_video_erase_char
= c
& ~0x100;
2509 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2510 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2513 vc_resize(vc
, cols
, rows
);
2514 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2515 fbcon_update_softback(vc
);
2516 } else if (CON_IS_VISIBLE(vc
)
2517 && vc
->vc_mode
== KD_TEXT
) {
2518 fbcon_clear_margins(vc
, 0);
2522 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2523 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2527 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2529 struct display
*od
= &fb_display
[con
];
2530 struct console_font
*f
= &vc
->vc_font
;
2532 if (od
->fontdata
== f
->data
)
2533 return 0; /* already the same font... */
2534 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2538 * User asked to set font; we are guaranteed that
2539 * a) width and height are in range 1..32
2540 * b) charcount does not exceed 512
2541 * but lets not assume that, since someone might someday want to use larger
2542 * fonts. And charcount of 512 is small for unicode support.
2544 * However, user space gives the font in 32 rows , regardless of
2545 * actual font height. So a new API is needed if support for larger fonts
2546 * is ever implemented.
2549 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2551 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2552 unsigned charcount
= font
->charcount
;
2553 int w
= font
->width
;
2554 int h
= font
->height
;
2557 u8
*new_data
, *data
= font
->data
;
2558 int pitch
= (font
->width
+7) >> 3;
2560 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2561 * If not this check should be changed to charcount < 256 */
2562 if (charcount
!= 256 && charcount
!= 512)
2565 /* Make sure drawing engine can handle the font */
2566 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2567 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2570 /* Make sure driver can handle the font length */
2571 if (fbcon_invalid_charcount(info
, charcount
))
2574 size
= h
* pitch
* charcount
;
2576 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2581 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2582 FNTSIZE(new_data
) = size
;
2583 FNTCHARCNT(new_data
) = charcount
;
2584 REFCOUNT(new_data
) = 0; /* usage counter */
2585 for (i
=0; i
< charcount
; i
++) {
2586 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2589 /* Since linux has a nice crc32 function use it for counting font
2591 csum
= crc32(0, new_data
, size
);
2593 FNTSUM(new_data
) = csum
;
2594 /* Check if the same font is on some other console already */
2595 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2596 struct vc_data
*tmp
= vc_cons
[i
].d
;
2598 if (fb_display
[i
].userfont
&&
2599 fb_display
[i
].fontdata
&&
2600 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2601 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2602 tmp
->vc_font
.width
== w
&&
2603 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2604 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2605 new_data
= (u8
*)fb_display
[i
].fontdata
;
2609 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2612 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2614 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2615 const struct font_desc
*f
;
2618 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2619 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2620 else if (!(f
= find_font(name
)))
2623 font
->width
= f
->width
;
2624 font
->height
= f
->height
;
2625 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2628 static u16 palette_red
[16];
2629 static u16 palette_green
[16];
2630 static u16 palette_blue
[16];
2632 static struct fb_cmap palette_cmap
= {
2633 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2636 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2638 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2642 if (fbcon_is_inactive(vc
, info
))
2645 if (!CON_IS_VISIBLE(vc
))
2648 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2650 for (i
= j
= 0; i
< 16; i
++) {
2652 val
= vc
->vc_palette
[j
++];
2653 palette_red
[k
] = (val
<< 8) | val
;
2654 val
= vc
->vc_palette
[j
++];
2655 palette_green
[k
] = (val
<< 8) | val
;
2656 val
= vc
->vc_palette
[j
++];
2657 palette_blue
[k
] = (val
<< 8) | val
;
2659 palette_cmap
.len
= 16;
2660 palette_cmap
.start
= 0;
2662 * If framebuffer is capable of less than 16 colors,
2663 * use default palette of fbcon.
2666 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2668 return fb_set_cmap(&palette_cmap
, info
);
2671 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2676 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2677 return (u16
*) (vc
->vc_origin
+ offset
);
2678 line
= offset
/ vc
->vc_size_row
;
2679 if (line
>= softback_lines
)
2680 return (u16
*) (vc
->vc_origin
+ offset
-
2681 softback_lines
* vc
->vc_size_row
);
2682 p
= softback_curr
+ offset
;
2683 if (p
>= softback_end
)
2684 p
+= softback_buf
- softback_end
;
2688 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2694 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2695 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2697 x
= offset
% vc
->vc_cols
;
2698 y
= offset
/ vc
->vc_cols
;
2699 if (vc
->vc_num
== fg_console
)
2700 y
+= softback_lines
;
2701 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2702 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2703 unsigned long offset
= pos
- softback_curr
;
2705 if (pos
< softback_curr
)
2706 offset
+= softback_end
- softback_buf
;
2708 x
= offset
% vc
->vc_cols
;
2709 y
= offset
/ vc
->vc_cols
;
2710 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2711 if (ret
== softback_end
)
2713 if (ret
== softback_in
)
2714 ret
= vc
->vc_origin
;
2716 /* Should not happen */
2718 ret
= vc
->vc_origin
;
2727 /* As we might be inside of softback, we may work with non-contiguous buffer,
2728 that's why we have to use a separate routine. */
2729 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2732 u16 a
= scr_readw(p
);
2733 if (!vc
->vc_can_do_color
)
2735 else if (vc
->vc_hi_font_mask
== 0x100)
2736 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2737 (((a
) & 0x0e00) << 4);
2739 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2740 (((a
) & 0x0700) << 4);
2742 if (p
== (u16
*) softback_end
)
2743 p
= (u16
*) softback_buf
;
2744 if (p
== (u16
*) softback_in
)
2745 p
= (u16
*) vc
->vc_origin
;
2749 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2751 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2752 struct fbcon_ops
*ops
= info
->fbcon_par
;
2753 struct display
*disp
= &fb_display
[fg_console
];
2754 int offset
, limit
, scrollback_old
;
2757 if (vc
->vc_num
!= fg_console
)
2759 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2761 if (logo_shown
>= 0) {
2762 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2764 if (conp2
->vc_top
== logo_lines
2765 && conp2
->vc_bottom
== conp2
->vc_rows
)
2767 if (logo_shown
== vc
->vc_num
) {
2773 logo_lines
* vc
->vc_size_row
;
2774 for (i
= 0; i
< logo_lines
; i
++) {
2775 if (p
== softback_top
)
2777 if (p
== softback_buf
)
2779 p
-= vc
->vc_size_row
;
2780 q
-= vc
->vc_size_row
;
2781 scr_memcpyw((u16
*) q
, (u16
*) p
,
2784 softback_in
= softback_curr
= p
;
2785 update_region(vc
, vc
->vc_origin
,
2786 logo_lines
* vc
->vc_cols
);
2788 logo_shown
= FBCON_LOGO_CANSHOW
;
2790 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2791 fbcon_redraw_softback(vc
, disp
, lines
);
2792 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2796 if (!scrollback_phys_max
)
2799 scrollback_old
= scrollback_current
;
2800 scrollback_current
-= lines
;
2801 if (scrollback_current
< 0)
2802 scrollback_current
= 0;
2803 else if (scrollback_current
> scrollback_max
)
2804 scrollback_current
= scrollback_max
;
2805 if (scrollback_current
== scrollback_old
)
2808 if (fbcon_is_inactive(vc
, info
))
2811 fbcon_cursor(vc
, CM_ERASE
);
2813 offset
= disp
->yscroll
- scrollback_current
;
2814 limit
= disp
->vrows
;
2815 switch (disp
->scrollmode
) {
2816 case SCROLL_WRAP_MOVE
:
2817 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2819 case SCROLL_PAN_MOVE
:
2820 case SCROLL_PAN_REDRAW
:
2821 limit
-= vc
->vc_rows
;
2822 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2827 else if (offset
>= limit
)
2830 ops
->var
.xoffset
= 0;
2831 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2832 ops
->update_start(info
);
2834 if (!scrollback_current
)
2835 fbcon_cursor(vc
, CM_DRAW
);
2839 static int fbcon_set_origin(struct vc_data
*vc
)
2842 fbcon_scrolldelta(vc
, softback_lines
);
2846 static void fbcon_suspended(struct fb_info
*info
)
2848 struct vc_data
*vc
= NULL
;
2849 struct fbcon_ops
*ops
= info
->fbcon_par
;
2851 if (!ops
|| ops
->currcon
< 0)
2853 vc
= vc_cons
[ops
->currcon
].d
;
2855 /* Clear cursor, restore saved data */
2856 fbcon_cursor(vc
, CM_ERASE
);
2859 static void fbcon_resumed(struct fb_info
*info
)
2862 struct fbcon_ops
*ops
= info
->fbcon_par
;
2864 if (!ops
|| ops
->currcon
< 0)
2866 vc
= vc_cons
[ops
->currcon
].d
;
2871 static void fbcon_modechanged(struct fb_info
*info
)
2873 struct fbcon_ops
*ops
= info
->fbcon_par
;
2878 if (!ops
|| ops
->currcon
< 0)
2880 vc
= vc_cons
[ops
->currcon
].d
;
2881 if (vc
->vc_mode
!= KD_TEXT
||
2882 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2885 p
= &fb_display
[vc
->vc_num
];
2886 set_blitting_type(vc
, info
);
2888 if (CON_IS_VISIBLE(vc
)) {
2889 var_to_display(p
, &info
->var
, info
);
2890 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2891 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2892 cols
/= vc
->vc_font
.width
;
2893 rows
/= vc
->vc_font
.height
;
2894 vc_resize(vc
, cols
, rows
);
2895 updatescrollmode(p
, info
, vc
);
2897 scrollback_current
= 0;
2899 if (!fbcon_is_inactive(vc
, info
)) {
2900 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2901 ops
->update_start(info
);
2904 fbcon_set_palette(vc
, color_table
);
2907 fbcon_update_softback(vc
);
2911 static void fbcon_set_all_vcs(struct fb_info
*info
)
2913 struct fbcon_ops
*ops
= info
->fbcon_par
;
2916 int i
, rows
, cols
, fg
= -1;
2918 if (!ops
|| ops
->currcon
< 0)
2921 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2923 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2924 registered_fb
[con2fb_map
[i
]] != info
)
2927 if (CON_IS_VISIBLE(vc
)) {
2932 p
= &fb_display
[vc
->vc_num
];
2933 set_blitting_type(vc
, info
);
2934 var_to_display(p
, &info
->var
, info
);
2935 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2936 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2937 cols
/= vc
->vc_font
.width
;
2938 rows
/= vc
->vc_font
.height
;
2939 vc_resize(vc
, cols
, rows
);
2943 fbcon_modechanged(info
);
2946 static int fbcon_mode_deleted(struct fb_info
*info
,
2947 struct fb_videomode
*mode
)
2949 struct fb_info
*fb_info
;
2951 int i
, j
, found
= 0;
2953 /* before deletion, ensure that mode is not in use */
2954 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2958 fb_info
= registered_fb
[j
];
2959 if (fb_info
!= info
)
2964 if (fb_mode_is_equal(p
->mode
, mode
)) {
2972 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2973 static int fbcon_unbind(void)
2977 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2981 fbcon_has_console_bind
= 0;
2986 static inline int fbcon_unbind(void)
2990 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2992 static int fbcon_fb_unbind(int idx
)
2994 int i
, new_idx
= -1, ret
= 0;
2996 if (!fbcon_has_console_bind
)
2999 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3000 if (con2fb_map
[i
] != idx
&&
3001 con2fb_map
[i
] != -1) {
3007 if (new_idx
!= -1) {
3008 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3009 if (con2fb_map
[i
] == idx
)
3010 set_con2fb_map(i
, new_idx
, 0);
3013 ret
= fbcon_unbind();
3018 static int fbcon_fb_unregistered(struct fb_info
*info
)
3023 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3024 if (con2fb_map
[i
] == idx
)
3028 if (idx
== info_idx
) {
3031 for (i
= 0; i
< FB_MAX
; i
++) {
3032 if (registered_fb
[i
] != NULL
) {
3039 if (info_idx
!= -1) {
3040 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3041 if (con2fb_map
[i
] == -1)
3042 con2fb_map
[i
] = info_idx
;
3046 if (primary_device
== idx
)
3047 primary_device
= -1;
3049 if (!num_registered_fb
)
3050 unregister_con_driver(&fb_con
);
3055 static void fbcon_remap_all(int idx
)
3058 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3059 set_con2fb_map(i
, idx
, 0);
3061 if (con_is_bound(&fb_con
)) {
3062 printk(KERN_INFO
"fbcon: Remapping primary device, "
3063 "fb%i, to tty %i-%i\n", idx
,
3064 first_fb_vc
+ 1, last_fb_vc
+ 1);
3069 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3070 static void fbcon_select_primary(struct fb_info
*info
)
3072 if (!map_override
&& primary_device
== -1 &&
3073 fb_is_primary_device(info
)) {
3076 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3077 info
->fix
.id
, info
->node
);
3078 primary_device
= info
->node
;
3080 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3081 con2fb_map_boot
[i
] = primary_device
;
3083 if (con_is_bound(&fb_con
)) {
3084 printk(KERN_INFO
"fbcon: Remapping primary device, "
3085 "fb%i, to tty %i-%i\n", info
->node
,
3086 first_fb_vc
+ 1, last_fb_vc
+ 1);
3087 info_idx
= primary_device
;
3093 static inline void fbcon_select_primary(struct fb_info
*info
)
3097 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3099 static int fbcon_fb_registered(struct fb_info
*info
)
3101 int ret
= 0, i
, idx
;
3104 fbcon_select_primary(info
);
3106 if (info_idx
== -1) {
3107 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3108 if (con2fb_map_boot
[i
] == idx
) {
3115 ret
= fbcon_takeover(1);
3117 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3118 if (con2fb_map_boot
[i
] == idx
)
3119 set_con2fb_map(i
, idx
, 0);
3126 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3128 struct fbcon_ops
*ops
= info
->fbcon_par
;
3131 if (!ops
|| ops
->currcon
< 0)
3134 vc
= vc_cons
[ops
->currcon
].d
;
3135 if (vc
->vc_mode
!= KD_TEXT
||
3136 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3139 if (CON_IS_VISIBLE(vc
)) {
3143 do_unblank_screen(0);
3145 ops
->blank_state
= blank
;
3148 static void fbcon_new_modelist(struct fb_info
*info
)
3152 struct fb_var_screeninfo var
;
3153 const struct fb_videomode
*mode
;
3155 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3156 if (registered_fb
[con2fb_map
[i
]] != info
)
3158 if (!fb_display
[i
].mode
)
3161 display_to_var(&var
, &fb_display
[i
]);
3162 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3164 fb_videomode_to_var(&var
, mode
);
3165 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3169 static void fbcon_get_requirement(struct fb_info
*info
,
3170 struct fb_blit_caps
*caps
)
3178 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3180 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3181 info
->node
== con2fb_map
[i
]) {
3183 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3184 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3185 charcnt
= (p
->userfont
) ?
3186 FNTCHARCNT(p
->fontdata
) : 256;
3187 if (caps
->len
< charcnt
)
3188 caps
->len
= charcnt
;
3192 vc
= vc_cons
[fg_console
].d
;
3194 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3195 info
->node
== con2fb_map
[fg_console
]) {
3196 p
= &fb_display
[fg_console
];
3197 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3198 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3199 caps
->len
= (p
->userfont
) ?
3200 FNTCHARCNT(p
->fontdata
) : 256;
3205 static int fbcon_event_notify(struct notifier_block
*self
,
3206 unsigned long action
, void *data
)
3208 struct fb_event
*event
= data
;
3209 struct fb_info
*info
= event
->info
;
3210 struct fb_videomode
*mode
;
3211 struct fb_con2fbmap
*con2fb
;
3212 struct fb_blit_caps
*caps
;
3216 * ignore all events except driver registration and deregistration
3217 * if fbcon is not active
3219 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3220 action
== FB_EVENT_FB_UNREGISTERED
))
3224 case FB_EVENT_SUSPEND
:
3225 fbcon_suspended(info
);
3227 case FB_EVENT_RESUME
:
3228 fbcon_resumed(info
);
3230 case FB_EVENT_MODE_CHANGE
:
3231 fbcon_modechanged(info
);
3233 case FB_EVENT_MODE_CHANGE_ALL
:
3234 fbcon_set_all_vcs(info
);
3236 case FB_EVENT_MODE_DELETE
:
3238 ret
= fbcon_mode_deleted(info
, mode
);
3240 case FB_EVENT_FB_UNBIND
:
3242 ret
= fbcon_fb_unbind(idx
);
3244 case FB_EVENT_FB_REGISTERED
:
3245 ret
= fbcon_fb_registered(info
);
3247 case FB_EVENT_FB_UNREGISTERED
:
3248 ret
= fbcon_fb_unregistered(info
);
3250 case FB_EVENT_SET_CONSOLE_MAP
:
3251 con2fb
= event
->data
;
3252 ret
= set_con2fb_map(con2fb
->console
- 1,
3253 con2fb
->framebuffer
, 1);
3255 case FB_EVENT_GET_CONSOLE_MAP
:
3256 con2fb
= event
->data
;
3257 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3259 case FB_EVENT_BLANK
:
3260 fbcon_fb_blanked(info
, *(int *)event
->data
);
3262 case FB_EVENT_NEW_MODELIST
:
3263 fbcon_new_modelist(info
);
3265 case FB_EVENT_GET_REQ
:
3267 fbcon_get_requirement(info
, caps
);
3269 case FB_EVENT_REMAP_ALL_CONSOLE
:
3271 fbcon_remap_all(idx
);
3279 * The console `switch' structure for the frame buffer based console
3282 static const struct consw fb_con
= {
3283 .owner
= THIS_MODULE
,
3284 .con_startup
= fbcon_startup
,
3285 .con_init
= fbcon_init
,
3286 .con_deinit
= fbcon_deinit
,
3287 .con_clear
= fbcon_clear
,
3288 .con_putc
= fbcon_putc
,
3289 .con_putcs
= fbcon_putcs
,
3290 .con_cursor
= fbcon_cursor
,
3291 .con_scroll
= fbcon_scroll
,
3292 .con_bmove
= fbcon_bmove
,
3293 .con_switch
= fbcon_switch
,
3294 .con_blank
= fbcon_blank
,
3295 .con_font_set
= fbcon_set_font
,
3296 .con_font_get
= fbcon_get_font
,
3297 .con_font_default
= fbcon_set_def_font
,
3298 .con_font_copy
= fbcon_copy_font
,
3299 .con_set_palette
= fbcon_set_palette
,
3300 .con_scrolldelta
= fbcon_scrolldelta
,
3301 .con_set_origin
= fbcon_set_origin
,
3302 .con_invert_region
= fbcon_invert_region
,
3303 .con_screen_pos
= fbcon_screen_pos
,
3304 .con_getxy
= fbcon_getxy
,
3305 .con_resize
= fbcon_resize
,
3306 .con_debug_enter
= fbcon_debug_enter
,
3307 .con_debug_leave
= fbcon_debug_leave
,
3310 static struct notifier_block fbcon_event_notifier
= {
3311 .notifier_call
= fbcon_event_notify
,
3314 static ssize_t
store_rotate(struct device
*device
,
3315 struct device_attribute
*attr
, const char *buf
,
3318 struct fb_info
*info
;
3322 if (fbcon_has_exited
)
3326 idx
= con2fb_map
[fg_console
];
3328 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3331 info
= registered_fb
[idx
];
3332 rotate
= simple_strtoul(buf
, last
, 0);
3333 fbcon_rotate(info
, rotate
);
3339 static ssize_t
store_rotate_all(struct device
*device
,
3340 struct device_attribute
*attr
,const char *buf
,
3343 struct fb_info
*info
;
3347 if (fbcon_has_exited
)
3351 idx
= con2fb_map
[fg_console
];
3353 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3356 info
= registered_fb
[idx
];
3357 rotate
= simple_strtoul(buf
, last
, 0);
3358 fbcon_rotate_all(info
, rotate
);
3364 static ssize_t
show_rotate(struct device
*device
,
3365 struct device_attribute
*attr
,char *buf
)
3367 struct fb_info
*info
;
3368 int rotate
= 0, idx
;
3370 if (fbcon_has_exited
)
3374 idx
= con2fb_map
[fg_console
];
3376 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3379 info
= registered_fb
[idx
];
3380 rotate
= fbcon_get_rotate(info
);
3383 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3386 static ssize_t
show_cursor_blink(struct device
*device
,
3387 struct device_attribute
*attr
, char *buf
)
3389 struct fb_info
*info
;
3390 struct fbcon_ops
*ops
;
3391 int idx
, blink
= -1;
3393 if (fbcon_has_exited
)
3397 idx
= con2fb_map
[fg_console
];
3399 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3402 info
= registered_fb
[idx
];
3403 ops
= info
->fbcon_par
;
3408 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3411 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3414 static ssize_t
store_cursor_blink(struct device
*device
,
3415 struct device_attribute
*attr
,
3416 const char *buf
, size_t count
)
3418 struct fb_info
*info
;
3422 if (fbcon_has_exited
)
3426 idx
= con2fb_map
[fg_console
];
3428 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3431 info
= registered_fb
[idx
];
3433 if (!info
->fbcon_par
)
3436 blink
= simple_strtoul(buf
, last
, 0);
3439 fbcon_cursor_noblink
= 0;
3440 fbcon_add_cursor_timer(info
);
3442 fbcon_cursor_noblink
= 1;
3443 fbcon_del_cursor_timer(info
);
3451 static struct device_attribute device_attrs
[] = {
3452 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3453 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3454 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3455 store_cursor_blink
),
3458 static int fbcon_init_device(void)
3462 fbcon_has_sysfs
= 1;
3464 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3465 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3473 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3475 fbcon_has_sysfs
= 0;
3481 static void fbcon_start(void)
3483 if (num_registered_fb
) {
3488 for (i
= 0; i
< FB_MAX
; i
++) {
3489 if (registered_fb
[i
] != NULL
) {
3500 static void fbcon_exit(void)
3502 struct fb_info
*info
;
3505 if (fbcon_has_exited
)
3508 kfree((void *)softback_buf
);
3511 for (i
= 0; i
< FB_MAX
; i
++) {
3515 info
= registered_fb
[i
];
3520 if (info
->queue
.func
)
3521 pending
= cancel_work_sync(&info
->queue
);
3522 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3525 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3526 if (con2fb_map
[j
] == i
)
3531 if (info
->fbops
->fb_release
)
3532 info
->fbops
->fb_release(info
, 0);
3533 module_put(info
->fbops
->owner
);
3535 if (info
->fbcon_par
) {
3536 struct fbcon_ops
*ops
= info
->fbcon_par
;
3538 fbcon_del_cursor_timer(info
);
3539 kfree(ops
->cursor_src
);
3540 kfree(info
->fbcon_par
);
3541 info
->fbcon_par
= NULL
;
3544 if (info
->queue
.func
== fb_flashcursor
)
3545 info
->queue
.func
= NULL
;
3549 fbcon_has_exited
= 1;
3552 static int __init
fb_console_init(void)
3557 fb_register_client(&fbcon_event_notifier
);
3558 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3561 if (IS_ERR(fbcon_device
)) {
3562 printk(KERN_WARNING
"Unable to create device "
3563 "for fbcon; errno = %ld\n",
3564 PTR_ERR(fbcon_device
));
3565 fbcon_device
= NULL
;
3567 fbcon_init_device();
3569 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3577 module_init(fb_console_init
);
3581 static void __exit
fbcon_deinit_device(void)
3585 if (fbcon_has_sysfs
) {
3586 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3587 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3589 fbcon_has_sysfs
= 0;
3593 static void __exit
fb_console_exit(void)
3596 fb_unregister_client(&fbcon_event_notifier
);
3597 fbcon_deinit_device();
3598 device_destroy(fb_class
, MKDEV(0, 0));
3601 unregister_con_driver(&fb_con
);
3604 module_exit(fb_console_exit
);
3608 MODULE_LICENSE("GPL");