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>
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
87 # define DPRINTK(fmt, args...)
91 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
96 static struct display fb_display
[MAX_NR_CONSOLES
];
98 static signed char con2fb_map
[MAX_NR_CONSOLES
];
99 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
101 static int logo_lines
;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
104 static int logo_shown
= FBCON_LOGO_CANSHOW
;
105 /* Software scrollback */
106 static int fbcon_softback_size
= 32768;
107 static unsigned long softback_buf
, softback_curr
;
108 static unsigned long softback_in
;
109 static unsigned long softback_top
, softback_end
;
110 static int softback_lines
;
111 /* console mappings */
112 static int first_fb_vc
;
113 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
114 static int fbcon_is_default
= 1;
115 static int fbcon_has_exited
;
116 static int primary_device
= -1;
117 static int fbcon_has_console_bind
;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override
;
122 static inline void fbcon_map_override(void)
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
133 static char fontname
[40];
135 /* current fb_info */
136 static int info_idx
= -1;
138 /* console rotation */
139 static int initial_rotation
;
140 static int fbcon_has_sysfs
;
142 static const struct consw fb_con
;
144 #define CM_SOFTBACK (8)
146 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
148 static int fbcon_set_origin(struct vc_data
*);
150 #define CURSOR_DRAW_DELAY (1)
152 static int vbl_cursor_cnt
;
153 static int fbcon_cursor_noblink
;
155 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
158 * Interface used by the world
161 static const char *fbcon_startup(void);
162 static void fbcon_init(struct vc_data
*vc
, int init
);
163 static void fbcon_deinit(struct vc_data
*vc
);
164 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
166 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
167 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
168 int count
, int ypos
, int xpos
);
169 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
170 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
171 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
173 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
174 int height
, int width
);
175 static int fbcon_switch(struct vc_data
*vc
);
176 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
177 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
178 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
183 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
184 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
185 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
186 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
187 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
188 int dy
, int dx
, int height
, int width
, u_int y_break
);
189 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
191 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
192 int line
, int count
, int dy
);
193 static void fbcon_modechanged(struct fb_info
*info
);
194 static void fbcon_set_all_vcs(struct fb_info
*info
);
195 static void fbcon_start(void);
196 static void fbcon_exit(void);
197 static struct device
*fbcon_device
;
199 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
200 static inline void fbcon_set_rotation(struct fb_info
*info
)
202 struct fbcon_ops
*ops
= info
->fbcon_par
;
204 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
205 ops
->p
->con_rotate
< 4)
206 ops
->rotate
= ops
->p
->con_rotate
;
211 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
213 struct fbcon_ops
*ops
= info
->fbcon_par
;
214 struct fb_info
*fb_info
;
216 if (!ops
|| ops
->currcon
== -1)
219 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
221 if (info
== fb_info
) {
222 struct display
*p
= &fb_display
[ops
->currcon
];
225 p
->con_rotate
= rotate
;
229 fbcon_modechanged(info
);
233 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
235 struct fbcon_ops
*ops
= info
->fbcon_par
;
240 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
243 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
245 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
246 registered_fb
[con2fb_map
[i
]] != info
)
249 p
= &fb_display
[vc
->vc_num
];
250 p
->con_rotate
= rotate
;
253 fbcon_set_all_vcs(info
);
256 static inline void fbcon_set_rotation(struct fb_info
*info
)
258 struct fbcon_ops
*ops
= info
->fbcon_par
;
260 ops
->rotate
= FB_ROTATE_UR
;
263 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
268 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
272 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
274 static int fbcon_get_rotate(struct fb_info
*info
)
276 struct fbcon_ops
*ops
= info
->fbcon_par
;
278 return (ops
) ? ops
->rotate
: 0;
281 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
283 struct fbcon_ops
*ops
= info
->fbcon_par
;
285 return (info
->state
!= FBINFO_STATE_RUNNING
||
286 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
289 static inline 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
;
373 struct vc_data
*vc
= NULL
;
377 acquire_console_sem();
378 if (ops
&& ops
->currcon
!= -1)
379 vc
= vc_cons
[ops
->currcon
].d
;
381 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
382 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
384 release_console_sem();
388 p
= &fb_display
[vc
->vc_num
];
389 c
= scr_readw((u16
*) vc
->vc_pos
);
390 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
392 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
393 get_color(vc
, info
, c
, 0));
394 release_console_sem();
397 static void cursor_timer_handler(unsigned long dev_addr
)
399 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
400 struct fbcon_ops
*ops
= info
->fbcon_par
;
402 schedule_work(&info
->queue
);
403 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
406 static void fbcon_add_cursor_timer(struct fb_info
*info
)
408 struct fbcon_ops
*ops
= info
->fbcon_par
;
410 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
411 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) &&
412 !fbcon_cursor_noblink
) {
413 if (!info
->queue
.func
)
414 INIT_WORK(&info
->queue
, fb_flashcursor
);
416 init_timer(&ops
->cursor_timer
);
417 ops
->cursor_timer
.function
= cursor_timer_handler
;
418 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
419 ops
->cursor_timer
.data
= (unsigned long ) info
;
420 add_timer(&ops
->cursor_timer
);
421 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
425 static void fbcon_del_cursor_timer(struct fb_info
*info
)
427 struct fbcon_ops
*ops
= info
->fbcon_par
;
429 if (info
->queue
.func
== fb_flashcursor
&&
430 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
431 del_timer_sync(&ops
->cursor_timer
);
432 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
437 static int __init
fb_console_setup(char *this_opt
)
442 if (!this_opt
|| !*this_opt
)
445 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
446 if (!strncmp(options
, "font:", 5))
447 strcpy(fontname
, options
+ 5);
449 if (!strncmp(options
, "scrollback:", 11)) {
452 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
453 if (*options
== 'k' || *options
== 'K') {
454 fbcon_softback_size
*= 1024;
464 if (!strncmp(options
, "map:", 4)) {
467 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
471 (options
[j
++]-'0') % FB_MAX
;
474 fbcon_map_override();
480 if (!strncmp(options
, "vc:", 3)) {
483 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
486 if (*options
++ == '-')
487 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
488 fbcon_is_default
= 0;
491 if (!strncmp(options
, "rotate:", 7)) {
494 initial_rotation
= simple_strtoul(options
, &options
, 0);
495 if (initial_rotation
> 3)
496 initial_rotation
= 0;
502 __setup("fbcon=", fb_console_setup
);
505 static int search_fb_in_map(int idx
)
509 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
510 if (con2fb_map
[i
] == idx
)
516 static int search_for_mapped_con(void)
520 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
521 if (con2fb_map
[i
] != -1)
527 static int fbcon_takeover(int show_logo
)
531 if (!num_registered_fb
)
535 logo_shown
= FBCON_LOGO_DONTSHOW
;
537 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
538 con2fb_map
[i
] = info_idx
;
540 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
544 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
549 fbcon_has_console_bind
= 1;
556 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
557 int cols
, int rows
, int new_cols
, int new_rows
)
559 logo_shown
= FBCON_LOGO_DONTSHOW
;
562 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
563 int cols
, int rows
, int new_cols
, int new_rows
)
565 /* Need to make room for the logo */
566 struct fbcon_ops
*ops
= info
->fbcon_par
;
567 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
568 unsigned short *save
= NULL
, *r
, *q
;
571 if (info
->flags
& FBINFO_MODULE
) {
572 logo_shown
= FBCON_LOGO_DONTSHOW
;
577 * remove underline attribute from erase character
578 * if black and white framebuffer.
580 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
582 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
583 logo_lines
= DIV_ROUND_UP(logo_height
, vc
->vc_font
.height
);
584 q
= (unsigned short *) (vc
->vc_origin
+
585 vc
->vc_size_row
* rows
);
586 step
= logo_lines
* cols
;
587 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
588 if (scr_readw(r
) != vc
->vc_video_erase_char
)
590 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
591 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
593 int i
= cols
< new_cols
? cols
: new_cols
;
594 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
596 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
597 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
602 /* We can scroll screen down */
604 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
605 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
610 if (vc
->vc_y
+ logo_lines
>= rows
)
611 lines
= rows
- vc
->vc_y
- 1;
615 vc
->vc_pos
+= lines
* vc
->vc_size_row
;
618 scr_memsetw((unsigned short *) vc
->vc_origin
,
620 vc
->vc_size_row
* logo_lines
);
622 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
623 fbcon_clear_margins(vc
, 0);
628 q
= (unsigned short *) (vc
->vc_origin
+
631 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
632 vc
->vc_y
+= logo_lines
;
633 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
637 if (logo_lines
> vc
->vc_bottom
) {
638 logo_shown
= FBCON_LOGO_CANSHOW
;
640 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
641 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
642 logo_shown
= FBCON_LOGO_DRAW
;
643 vc
->vc_top
= logo_lines
;
648 #ifdef CONFIG_FB_TILEBLITTING
649 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
651 struct fbcon_ops
*ops
= info
->fbcon_par
;
653 ops
->p
= &fb_display
[vc
->vc_num
];
655 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
656 fbcon_set_tileops(vc
, info
);
658 fbcon_set_rotation(info
);
659 fbcon_set_bitops(ops
);
663 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
667 if (info
->flags
& FBINFO_MISC_TILEBLITTING
&&
668 info
->tileops
->fb_get_tilemax(info
) < charcount
)
674 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
676 struct fbcon_ops
*ops
= info
->fbcon_par
;
678 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
679 ops
->p
= &fb_display
[vc
->vc_num
];
680 fbcon_set_rotation(info
);
681 fbcon_set_bitops(ops
);
684 static int fbcon_invalid_charcount(struct fb_info
*info
, unsigned charcount
)
689 #endif /* CONFIG_MISC_TILEBLITTING */
692 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
693 int unit
, int oldidx
)
695 struct fbcon_ops
*ops
= NULL
;
698 if (!try_module_get(info
->fbops
->owner
))
701 if (!err
&& info
->fbops
->fb_open
&&
702 info
->fbops
->fb_open(info
, 0))
706 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
712 info
->fbcon_par
= ops
;
715 set_blitting_type(vc
, info
);
719 con2fb_map
[unit
] = oldidx
;
720 module_put(info
->fbops
->owner
);
726 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
727 struct fb_info
*newinfo
, int unit
,
728 int oldidx
, int found
)
730 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
733 if (oldinfo
->fbops
->fb_release
&&
734 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
735 con2fb_map
[unit
] = oldidx
;
736 if (!found
&& newinfo
->fbops
->fb_release
)
737 newinfo
->fbops
->fb_release(newinfo
, 0);
739 module_put(newinfo
->fbops
->owner
);
744 fbcon_del_cursor_timer(oldinfo
);
745 kfree(ops
->cursor_state
.mask
);
746 kfree(ops
->cursor_data
);
747 kfree(ops
->fontbuffer
);
748 kfree(oldinfo
->fbcon_par
);
749 oldinfo
->fbcon_par
= NULL
;
750 module_put(oldinfo
->fbops
->owner
);
752 If oldinfo and newinfo are driving the same hardware,
753 the fb_release() method of oldinfo may attempt to
754 restore the hardware state. This will leave the
755 newinfo in an undefined state. Thus, a call to
756 fb_set_par() may be needed for the newinfo.
758 if (newinfo
->fbops
->fb_set_par
) {
759 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
762 printk(KERN_ERR
"con2fb_release_oldinfo: "
763 "detected unhandled fb_set_par error, "
764 "error code %d\n", ret
);
771 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
772 int unit
, int show_logo
)
774 struct fbcon_ops
*ops
= info
->fbcon_par
;
777 ops
->currcon
= fg_console
;
779 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
780 ret
= info
->fbops
->fb_set_par(info
);
783 printk(KERN_ERR
"con2fb_init_display: detected "
784 "unhandled fb_set_par error, "
785 "error code %d\n", ret
);
788 ops
->flags
|= FBCON_FLAGS_INIT
;
790 fbcon_set_disp(info
, &info
->var
, unit
);
793 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
794 struct fb_info
*fg_info
=
795 registered_fb
[con2fb_map
[fg_console
]];
797 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
798 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
802 update_screen(vc_cons
[fg_console
].d
);
806 * set_con2fb_map - map console to frame buffer device
807 * @unit: virtual console number to map
808 * @newidx: frame buffer index to map virtual console to
809 * @user: user request
811 * Maps a virtual console @unit to a frame buffer device
814 static int set_con2fb_map(int unit
, int newidx
, int user
)
816 struct vc_data
*vc
= vc_cons
[unit
].d
;
817 int oldidx
= con2fb_map
[unit
];
818 struct fb_info
*info
= registered_fb
[newidx
];
819 struct fb_info
*oldinfo
= NULL
;
822 if (oldidx
== newidx
)
825 if (!info
|| fbcon_has_exited
)
828 if (!err
&& !search_for_mapped_con()) {
830 return fbcon_takeover(0);
834 oldinfo
= registered_fb
[oldidx
];
836 found
= search_fb_in_map(newidx
);
838 acquire_console_sem();
839 con2fb_map
[unit
] = newidx
;
841 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
845 * If old fb is not mapped to any of the consoles,
846 * fbcon should release it.
848 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
849 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
853 int show_logo
= (fg_console
== 0 && !user
&&
854 logo_shown
!= FBCON_LOGO_DONTSHOW
);
857 fbcon_add_cursor_timer(info
);
858 con2fb_map_boot
[unit
] = newidx
;
859 con2fb_init_display(vc
, info
, unit
, show_logo
);
862 if (!search_fb_in_map(info_idx
))
865 release_console_sem();
870 * Low Level Operations
872 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
873 static int var_to_display(struct display
*disp
,
874 struct fb_var_screeninfo
*var
,
875 struct fb_info
*info
)
877 disp
->xres_virtual
= var
->xres_virtual
;
878 disp
->yres_virtual
= var
->yres_virtual
;
879 disp
->bits_per_pixel
= var
->bits_per_pixel
;
880 disp
->grayscale
= var
->grayscale
;
881 disp
->nonstd
= var
->nonstd
;
882 disp
->accel_flags
= var
->accel_flags
;
883 disp
->height
= var
->height
;
884 disp
->width
= var
->width
;
885 disp
->red
= var
->red
;
886 disp
->green
= var
->green
;
887 disp
->blue
= var
->blue
;
888 disp
->transp
= var
->transp
;
889 disp
->rotate
= var
->rotate
;
890 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
891 if (disp
->mode
== NULL
)
892 /* This should not happen */
897 static void display_to_var(struct fb_var_screeninfo
*var
,
898 struct display
*disp
)
900 fb_videomode_to_var(var
, disp
->mode
);
901 var
->xres_virtual
= disp
->xres_virtual
;
902 var
->yres_virtual
= disp
->yres_virtual
;
903 var
->bits_per_pixel
= disp
->bits_per_pixel
;
904 var
->grayscale
= disp
->grayscale
;
905 var
->nonstd
= disp
->nonstd
;
906 var
->accel_flags
= disp
->accel_flags
;
907 var
->height
= disp
->height
;
908 var
->width
= disp
->width
;
909 var
->red
= disp
->red
;
910 var
->green
= disp
->green
;
911 var
->blue
= disp
->blue
;
912 var
->transp
= disp
->transp
;
913 var
->rotate
= disp
->rotate
;
916 static const char *fbcon_startup(void)
918 const char *display_desc
= "frame buffer device";
919 struct display
*p
= &fb_display
[fg_console
];
920 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
921 const struct font_desc
*font
= NULL
;
922 struct module
*owner
;
923 struct fb_info
*info
= NULL
;
924 struct fbcon_ops
*ops
;
928 * If num_registered_fb is zero, this is a call for the dummy part.
929 * The frame buffer devices weren't initialized yet.
931 if (!num_registered_fb
|| info_idx
== -1)
934 * Instead of blindly using registered_fb[0], we use info_idx, set by
937 info
= registered_fb
[info_idx
];
941 owner
= info
->fbops
->owner
;
942 if (!try_module_get(owner
))
944 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
949 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
957 ops
->cur_rotate
= -1;
958 info
->fbcon_par
= ops
;
959 p
->con_rotate
= initial_rotation
;
960 set_blitting_type(vc
, info
);
962 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
963 if (fbcon_softback_size
) {
967 kmalloc(fbcon_softback_size
,
970 fbcon_softback_size
= 0;
976 kfree((void *) softback_buf
);
982 softback_in
= softback_top
= softback_curr
=
987 /* Setup default font */
989 if (!fontname
[0] || !(font
= find_font(fontname
)))
990 font
= get_default_font(info
->var
.xres
,
993 info
->pixmap
.blit_y
);
994 vc
->vc_font
.width
= font
->width
;
995 vc
->vc_font
.height
= font
->height
;
996 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
997 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1000 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1001 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1002 cols
/= vc
->vc_font
.width
;
1003 rows
/= vc
->vc_font
.height
;
1004 vc_resize(vc
, cols
, rows
);
1006 DPRINTK("mode: %s\n", info
->fix
.id
);
1007 DPRINTK("visual: %d\n", info
->fix
.visual
);
1008 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1010 info
->var
.bits_per_pixel
);
1012 fbcon_add_cursor_timer(info
);
1013 fbcon_has_exited
= 0;
1014 return display_desc
;
1017 static void fbcon_init(struct vc_data
*vc
, int init
)
1019 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1020 struct fbcon_ops
*ops
;
1021 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1022 struct vc_data
*svc
= *default_mode
;
1023 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1024 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1027 if (info_idx
== -1 || info
== NULL
)
1032 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1033 (info
->fix
.type
== FB_TYPE_TEXT
))
1036 if (var_to_display(p
, &info
->var
, info
))
1039 if (!info
->fbcon_par
)
1040 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1042 /* If we are not the first console on this
1043 fb, copy the font from that console */
1044 t
= &fb_display
[fg_console
];
1047 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1049 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1051 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1052 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1053 p
->userfont
= t
->userfont
;
1056 REFCOUNT(p
->fontdata
)++;
1058 const struct font_desc
*font
= NULL
;
1060 if (!fontname
[0] || !(font
= find_font(fontname
)))
1061 font
= get_default_font(info
->var
.xres
,
1063 info
->pixmap
.blit_x
,
1064 info
->pixmap
.blit_y
);
1065 vc
->vc_font
.width
= font
->width
;
1066 vc
->vc_font
.height
= font
->height
;
1067 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1068 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1069 support more fonts */
1074 charcnt
= FNTCHARCNT(p
->fontdata
);
1076 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1077 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1078 if (charcnt
== 256) {
1079 vc
->vc_hi_font_mask
= 0;
1081 vc
->vc_hi_font_mask
= 0x100;
1082 if (vc
->vc_can_do_color
)
1083 vc
->vc_complement_mask
<<= 1;
1086 if (!*svc
->vc_uni_pagedir_loc
)
1087 con_set_default_unimap(svc
);
1088 if (!*vc
->vc_uni_pagedir_loc
)
1089 con_copy_unimap(vc
, svc
);
1091 ops
= info
->fbcon_par
;
1092 p
->con_rotate
= initial_rotation
;
1093 set_blitting_type(vc
, info
);
1097 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1098 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1099 new_cols
/= vc
->vc_font
.width
;
1100 new_rows
/= vc
->vc_font
.height
;
1103 * We must always set the mode. The mode of the previous console
1104 * driver could be in the same resolution but we are using different
1105 * hardware so we have to initialize the hardware.
1107 * We need to do it in fbcon_init() to prevent screen corruption.
1109 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1110 if (info
->fbops
->fb_set_par
&&
1111 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1112 ret
= info
->fbops
->fb_set_par(info
);
1115 printk(KERN_ERR
"fbcon_init: detected "
1116 "unhandled fb_set_par error, "
1117 "error code %d\n", ret
);
1120 ops
->flags
|= FBCON_FLAGS_INIT
;
1125 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1126 !(cap
& FBINFO_HWACCEL_DISABLED
))
1127 p
->scrollmode
= SCROLL_MOVE
;
1128 else /* default to something safe */
1129 p
->scrollmode
= SCROLL_REDRAW
;
1132 * ++guenther: console.c:vc_allocate() relies on initializing
1133 * vc_{cols,rows}, but we must not set those if we are only
1134 * resizing the console.
1137 vc
->vc_cols
= new_cols
;
1138 vc
->vc_rows
= new_rows
;
1140 vc_resize(vc
, new_cols
, new_rows
);
1143 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1145 if (vc
== svc
&& softback_buf
)
1146 fbcon_update_softback(vc
);
1148 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1149 ops
->rotate
= FB_ROTATE_UR
;
1150 set_blitting_type(vc
, info
);
1153 ops
->p
= &fb_display
[fg_console
];
1156 static void fbcon_free_font(struct display
*p
)
1158 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1159 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1164 static void fbcon_deinit(struct vc_data
*vc
)
1166 struct display
*p
= &fb_display
[vc
->vc_num
];
1167 struct fb_info
*info
;
1168 struct fbcon_ops
*ops
;
1172 idx
= con2fb_map
[vc
->vc_num
];
1177 info
= registered_fb
[idx
];
1182 ops
= info
->fbcon_par
;
1187 if (CON_IS_VISIBLE(vc
))
1188 fbcon_del_cursor_timer(info
);
1190 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1193 if (!con_is_bound(&fb_con
))
1199 /* ====================================================================== */
1201 /* fbcon_XXX routines - interface used by the world
1203 * This system is now divided into two levels because of complications
1204 * caused by hardware scrolling. Top level functions:
1206 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1208 * handles y values in range [0, scr_height-1] that correspond to real
1209 * screen positions. y_wrap shift means that first line of bitmap may be
1210 * anywhere on this display. These functions convert lineoffsets to
1211 * bitmap offsets and deal with the wrap-around case by splitting blits.
1213 * fbcon_bmove_physical_8() -- These functions fast implementations
1214 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1215 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1219 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1220 * Implies should only really hardware scroll in rows. Only reason for
1221 * restriction is simplicity & efficiency at the moment.
1224 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1227 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1228 struct fbcon_ops
*ops
= info
->fbcon_par
;
1230 struct display
*p
= &fb_display
[vc
->vc_num
];
1233 if (fbcon_is_inactive(vc
, info
))
1236 if (!height
|| !width
)
1239 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
)
1242 /* Split blits that cross physical y_wrap boundary */
1244 y_break
= p
->vrows
- p
->yscroll
;
1245 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1246 u_int b
= y_break
- sy
;
1247 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1248 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1251 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1254 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1255 int count
, int ypos
, int xpos
)
1257 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1258 struct display
*p
= &fb_display
[vc
->vc_num
];
1259 struct fbcon_ops
*ops
= info
->fbcon_par
;
1261 if (!fbcon_is_inactive(vc
, info
))
1262 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1263 get_color(vc
, info
, scr_readw(s
), 1),
1264 get_color(vc
, info
, scr_readw(s
), 0));
1267 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1271 scr_writew(c
, &chr
);
1272 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1275 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1277 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1278 struct fbcon_ops
*ops
= info
->fbcon_par
;
1280 if (!fbcon_is_inactive(vc
, info
))
1281 ops
->clear_margins(vc
, info
, bottom_only
);
1284 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1286 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1287 struct fbcon_ops
*ops
= info
->fbcon_par
;
1289 int c
= scr_readw((u16
*) vc
->vc_pos
);
1291 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1294 if (vc
->vc_cursor_type
& 0x10)
1295 fbcon_del_cursor_timer(info
);
1297 fbcon_add_cursor_timer(info
);
1299 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1300 if (mode
& CM_SOFTBACK
) {
1301 mode
&= ~CM_SOFTBACK
;
1305 fbcon_set_origin(vc
);
1309 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1310 get_color(vc
, info
, c
, 0));
1311 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1314 static int scrollback_phys_max
= 0;
1315 static int scrollback_max
= 0;
1316 static int scrollback_current
= 0;
1318 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1321 struct display
*p
, *t
;
1322 struct vc_data
**default_mode
, *vc
;
1323 struct vc_data
*svc
;
1324 struct fbcon_ops
*ops
= info
->fbcon_par
;
1325 int rows
, cols
, charcnt
= 256;
1327 p
= &fb_display
[unit
];
1329 if (var_to_display(p
, var
, info
))
1332 vc
= vc_cons
[unit
].d
;
1337 default_mode
= vc
->vc_display_fg
;
1338 svc
= *default_mode
;
1339 t
= &fb_display
[svc
->vc_num
];
1341 if (!vc
->vc_font
.data
) {
1342 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1343 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1344 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1345 p
->userfont
= t
->userfont
;
1347 REFCOUNT(p
->fontdata
)++;
1350 charcnt
= FNTCHARCNT(p
->fontdata
);
1352 var
->activate
= FB_ACTIVATE_NOW
;
1353 info
->var
.activate
= var
->activate
;
1354 var
->yoffset
= info
->var
.yoffset
;
1355 var
->xoffset
= info
->var
.xoffset
;
1356 fb_set_var(info
, var
);
1357 ops
->var
= info
->var
;
1358 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1359 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1360 if (charcnt
== 256) {
1361 vc
->vc_hi_font_mask
= 0;
1363 vc
->vc_hi_font_mask
= 0x100;
1364 if (vc
->vc_can_do_color
)
1365 vc
->vc_complement_mask
<<= 1;
1368 if (!*svc
->vc_uni_pagedir_loc
)
1369 con_set_default_unimap(svc
);
1370 if (!*vc
->vc_uni_pagedir_loc
)
1371 con_copy_unimap(vc
, svc
);
1373 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1374 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1375 cols
/= vc
->vc_font
.width
;
1376 rows
/= vc
->vc_font
.height
;
1377 vc_resize(vc
, cols
, rows
);
1379 if (CON_IS_VISIBLE(vc
)) {
1382 fbcon_update_softback(vc
);
1386 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1388 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1389 struct fbcon_ops
*ops
= info
->fbcon_par
;
1390 struct display
*p
= &fb_display
[vc
->vc_num
];
1392 p
->yscroll
+= count
;
1393 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1394 p
->yscroll
-= p
->vrows
;
1395 ops
->var
.xoffset
= 0;
1396 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1397 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1398 ops
->update_start(info
);
1399 scrollback_max
+= count
;
1400 if (scrollback_max
> scrollback_phys_max
)
1401 scrollback_max
= scrollback_phys_max
;
1402 scrollback_current
= 0;
1405 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1407 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1408 struct fbcon_ops
*ops
= info
->fbcon_par
;
1409 struct display
*p
= &fb_display
[vc
->vc_num
];
1411 p
->yscroll
-= count
;
1412 if (p
->yscroll
< 0) /* Deal with wrap */
1413 p
->yscroll
+= p
->vrows
;
1414 ops
->var
.xoffset
= 0;
1415 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1416 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1417 ops
->update_start(info
);
1418 scrollback_max
-= count
;
1419 if (scrollback_max
< 0)
1421 scrollback_current
= 0;
1424 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1426 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1427 struct display
*p
= &fb_display
[vc
->vc_num
];
1428 struct fbcon_ops
*ops
= info
->fbcon_par
;
1430 p
->yscroll
+= count
;
1431 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1432 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1433 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1434 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1437 ops
->var
.xoffset
= 0;
1438 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1439 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1440 ops
->update_start(info
);
1441 fbcon_clear_margins(vc
, 1);
1442 scrollback_max
+= count
;
1443 if (scrollback_max
> scrollback_phys_max
)
1444 scrollback_max
= scrollback_phys_max
;
1445 scrollback_current
= 0;
1448 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1450 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1451 struct fbcon_ops
*ops
= info
->fbcon_par
;
1452 struct display
*p
= &fb_display
[vc
->vc_num
];
1454 p
->yscroll
+= count
;
1456 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1457 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1458 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1461 ops
->var
.xoffset
= 0;
1462 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1463 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1464 ops
->update_start(info
);
1465 fbcon_clear_margins(vc
, 1);
1466 scrollback_max
+= count
;
1467 if (scrollback_max
> scrollback_phys_max
)
1468 scrollback_max
= scrollback_phys_max
;
1469 scrollback_current
= 0;
1472 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1474 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1475 struct display
*p
= &fb_display
[vc
->vc_num
];
1476 struct fbcon_ops
*ops
= info
->fbcon_par
;
1478 p
->yscroll
-= count
;
1479 if (p
->yscroll
< 0) {
1480 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1481 0, vc
->vc_rows
, vc
->vc_cols
);
1482 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1485 ops
->var
.xoffset
= 0;
1486 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1487 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1488 ops
->update_start(info
);
1489 fbcon_clear_margins(vc
, 1);
1490 scrollback_max
-= count
;
1491 if (scrollback_max
< 0)
1493 scrollback_current
= 0;
1496 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1498 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1499 struct fbcon_ops
*ops
= info
->fbcon_par
;
1500 struct display
*p
= &fb_display
[vc
->vc_num
];
1502 p
->yscroll
-= count
;
1504 if (p
->yscroll
< 0) {
1505 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1506 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1509 ops
->var
.xoffset
= 0;
1510 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1511 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1512 ops
->update_start(info
);
1513 fbcon_clear_margins(vc
, 1);
1514 scrollback_max
-= count
;
1515 if (scrollback_max
< 0)
1517 scrollback_current
= 0;
1520 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1523 int count
= vc
->vc_rows
;
1524 unsigned short *d
, *s
;
1528 d
= (u16
*) softback_curr
;
1529 if (d
== (u16
*) softback_in
)
1530 d
= (u16
*) vc
->vc_origin
;
1531 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1532 softback_lines
-= delta
;
1534 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1535 n
+= softback_end
- softback_buf
;
1536 if (n
< softback_top
) {
1538 (softback_top
- n
) / vc
->vc_size_row
;
1541 } else if (softback_curr
>= softback_top
1542 && n
< softback_top
) {
1544 (softback_top
- n
) / vc
->vc_size_row
;
1548 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1549 n
+= softback_buf
- softback_end
;
1550 if (n
> softback_in
) {
1554 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1559 if (n
== softback_curr
)
1562 s
= (u16
*) softback_curr
;
1563 if (s
== (u16
*) softback_in
)
1564 s
= (u16
*) vc
->vc_origin
;
1566 unsigned short *start
;
1570 unsigned short attr
= 1;
1573 le
= advance_row(s
, 1);
1576 if (attr
!= (c
& 0xff00)) {
1579 fbcon_putcs(vc
, start
, s
- start
,
1585 if (c
== scr_readw(d
)) {
1587 fbcon_putcs(vc
, start
, s
- start
,
1600 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1602 if (d
== (u16
*) softback_end
)
1603 d
= (u16
*) softback_buf
;
1604 if (d
== (u16
*) softback_in
)
1605 d
= (u16
*) vc
->vc_origin
;
1606 if (s
== (u16
*) softback_end
)
1607 s
= (u16
*) softback_buf
;
1608 if (s
== (u16
*) softback_in
)
1609 s
= (u16
*) vc
->vc_origin
;
1613 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1614 int line
, int count
, int dy
)
1616 unsigned short *s
= (unsigned short *)
1617 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1620 unsigned short *start
= s
;
1621 unsigned short *le
= advance_row(s
, 1);
1624 unsigned short attr
= 1;
1628 if (attr
!= (c
& 0xff00)) {
1631 fbcon_putcs(vc
, start
, s
- start
,
1637 console_conditional_schedule();
1641 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1642 console_conditional_schedule();
1647 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1648 struct display
*p
, int line
, int count
, int ycount
)
1650 int offset
= ycount
* vc
->vc_cols
;
1651 unsigned short *d
= (unsigned short *)
1652 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1653 unsigned short *s
= d
+ offset
;
1654 struct fbcon_ops
*ops
= info
->fbcon_par
;
1657 unsigned short *start
= s
;
1658 unsigned short *le
= advance_row(s
, 1);
1665 if (c
== scr_readw(d
)) {
1667 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1668 line
, x
, 1, s
-start
);
1678 console_conditional_schedule();
1683 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1685 console_conditional_schedule();
1690 /* NOTE: We subtract two lines from these pointers */
1691 s
-= vc
->vc_size_row
;
1692 d
-= vc
->vc_size_row
;
1697 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1698 int line
, int count
, int offset
)
1700 unsigned short *d
= (unsigned short *)
1701 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1702 unsigned short *s
= d
+ offset
;
1705 unsigned short *start
= s
;
1706 unsigned short *le
= advance_row(s
, 1);
1709 unsigned short attr
= 1;
1713 if (attr
!= (c
& 0xff00)) {
1716 fbcon_putcs(vc
, start
, s
- start
,
1722 if (c
== scr_readw(d
)) {
1724 fbcon_putcs(vc
, start
, s
- start
,
1734 console_conditional_schedule();
1739 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1740 console_conditional_schedule();
1745 /* NOTE: We subtract two lines from these pointers */
1746 s
-= vc
->vc_size_row
;
1747 d
-= vc
->vc_size_row
;
1752 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1757 if (vc
->vc_num
!= fg_console
)
1759 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1762 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1764 p
= advance_row(p
, 1);
1765 softback_in
+= vc
->vc_size_row
;
1766 if (softback_in
== softback_end
)
1767 softback_in
= softback_buf
;
1768 if (softback_in
== softback_top
) {
1769 softback_top
+= vc
->vc_size_row
;
1770 if (softback_top
== softback_end
)
1771 softback_top
= softback_buf
;
1774 softback_curr
= softback_in
;
1777 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1780 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1781 struct display
*p
= &fb_display
[vc
->vc_num
];
1782 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1784 if (fbcon_is_inactive(vc
, info
))
1787 fbcon_cursor(vc
, CM_ERASE
);
1790 * ++Geert: Only use ywrap/ypan if the console is in text mode
1791 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1792 * whole screen (prevents flicker).
1797 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1798 count
= vc
->vc_rows
;
1800 fbcon_softback_note(vc
, t
, count
);
1801 if (logo_shown
>= 0)
1803 switch (p
->scrollmode
) {
1805 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1807 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1808 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1811 vc
->vc_video_erase_char
,
1812 vc
->vc_size_row
* count
);
1816 case SCROLL_WRAP_MOVE
:
1817 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1819 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1821 ywrap_up(vc
, count
);
1822 if (vc
->vc_rows
- b
> 0)
1823 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1826 } else if (info
->flags
& FBINFO_READS_FAST
)
1827 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1828 b
- t
- count
, vc
->vc_cols
);
1831 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1834 case SCROLL_PAN_REDRAW
:
1835 if ((p
->yscroll
+ count
<=
1836 2 * (p
->vrows
- vc
->vc_rows
))
1837 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1840 3 * vc
->vc_rows
>> 2)))) {
1842 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1843 ypan_up_redraw(vc
, t
, count
);
1844 if (vc
->vc_rows
- b
> 0)
1845 fbcon_redraw_move(vc
, p
, b
,
1846 vc
->vc_rows
- b
, b
);
1848 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1849 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1852 case SCROLL_PAN_MOVE
:
1853 if ((p
->yscroll
+ count
<=
1854 2 * (p
->vrows
- vc
->vc_rows
))
1855 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1858 3 * vc
->vc_rows
>> 2)))) {
1860 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1863 if (vc
->vc_rows
- b
> 0)
1864 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1867 } else if (info
->flags
& FBINFO_READS_FAST
)
1868 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1869 b
- t
- count
, vc
->vc_cols
);
1872 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1877 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1878 count
* vc
->vc_cols
);
1879 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1880 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1883 vc
->vc_video_erase_char
,
1884 vc
->vc_size_row
* count
);
1890 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1891 count
= vc
->vc_rows
;
1892 if (logo_shown
>= 0)
1894 switch (p
->scrollmode
) {
1896 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1898 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1899 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1902 vc
->vc_video_erase_char
,
1903 vc
->vc_size_row
* count
);
1907 case SCROLL_WRAP_MOVE
:
1908 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1909 if (vc
->vc_rows
- b
> 0)
1910 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1913 ywrap_down(vc
, count
);
1915 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1917 } else if (info
->flags
& FBINFO_READS_FAST
)
1918 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1919 b
- t
- count
, vc
->vc_cols
);
1922 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1925 case SCROLL_PAN_MOVE
:
1926 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1927 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1930 3 * vc
->vc_rows
>> 2)))) {
1931 if (vc
->vc_rows
- b
> 0)
1932 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1935 ypan_down(vc
, count
);
1937 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1939 } else if (info
->flags
& FBINFO_READS_FAST
)
1940 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1941 b
- t
- count
, vc
->vc_cols
);
1944 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1947 case SCROLL_PAN_REDRAW
:
1948 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1949 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1952 3 * vc
->vc_rows
>> 2)))) {
1953 if (vc
->vc_rows
- b
> 0)
1954 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1956 ypan_down_redraw(vc
, t
, count
);
1958 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1960 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1961 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1966 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1967 -count
* vc
->vc_cols
);
1968 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1969 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1972 vc
->vc_video_erase_char
,
1973 vc
->vc_size_row
* count
);
1981 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1982 int height
, int width
)
1984 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1985 struct display
*p
= &fb_display
[vc
->vc_num
];
1987 if (fbcon_is_inactive(vc
, info
))
1990 if (!width
|| !height
)
1993 /* Split blits that cross physical y_wrap case.
1994 * Pathological case involves 4 blits, better to use recursive
1995 * code rather than unrolled case
1997 * Recursive invocations don't need to erase the cursor over and
1998 * over again, so we use fbcon_bmove_rec()
2000 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2001 p
->vrows
- p
->yscroll
);
2004 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2005 int dy
, int dx
, int height
, int width
, u_int y_break
)
2007 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2008 struct fbcon_ops
*ops
= info
->fbcon_par
;
2011 if (sy
< y_break
&& sy
+ height
> y_break
) {
2013 if (dy
< sy
) { /* Avoid trashing self */
2014 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2016 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2017 height
- b
, width
, y_break
);
2019 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2020 height
- b
, width
, y_break
);
2021 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2027 if (dy
< y_break
&& dy
+ height
> y_break
) {
2029 if (dy
< sy
) { /* Avoid trashing self */
2030 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2032 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2033 height
- b
, width
, y_break
);
2035 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2036 height
- b
, width
, y_break
);
2037 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2042 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2046 static void updatescrollmode(struct display
*p
,
2047 struct fb_info
*info
,
2050 struct fbcon_ops
*ops
= info
->fbcon_par
;
2051 int fh
= vc
->vc_font
.height
;
2052 int cap
= info
->flags
;
2054 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2055 info
->fix
.xpanstep
);
2056 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2057 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2058 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2059 info
->var
.xres_virtual
);
2060 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2061 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2062 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2063 divides(ywrap
, vc
->vc_font
.height
) &&
2064 divides(vc
->vc_font
.height
, vyres
) &&
2065 divides(vc
->vc_font
.height
, yres
);
2066 int reading_fast
= cap
& FBINFO_READS_FAST
;
2067 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2068 !(cap
& FBINFO_HWACCEL_DISABLED
);
2069 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2070 !(cap
& FBINFO_HWACCEL_DISABLED
);
2072 p
->vrows
= vyres
/fh
;
2073 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2074 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2075 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2078 if (good_wrap
|| good_pan
) {
2079 if (reading_fast
|| fast_copyarea
)
2080 p
->scrollmode
= good_wrap
?
2081 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2083 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2086 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2087 p
->scrollmode
= SCROLL_MOVE
;
2089 p
->scrollmode
= SCROLL_REDRAW
;
2093 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2094 unsigned int height
, unsigned int user
)
2096 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2097 struct fbcon_ops
*ops
= info
->fbcon_par
;
2098 struct display
*p
= &fb_display
[vc
->vc_num
];
2099 struct fb_var_screeninfo var
= info
->var
;
2100 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2102 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2103 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2104 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2105 vc
->vc_font
.height
);
2106 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2108 var
.xres
= virt_w
* virt_fw
;
2109 var
.yres
= virt_h
* virt_fh
;
2110 x_diff
= info
->var
.xres
- var
.xres
;
2111 y_diff
= info
->var
.yres
- var
.yres
;
2112 if (x_diff
< 0 || x_diff
> virt_fw
||
2113 y_diff
< 0 || y_diff
> virt_fh
) {
2114 const struct fb_videomode
*mode
;
2116 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2117 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2120 display_to_var(&var
, p
);
2121 fb_videomode_to_var(&var
, mode
);
2123 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2126 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2127 if (CON_IS_VISIBLE(vc
)) {
2128 var
.activate
= FB_ACTIVATE_NOW
|
2130 fb_set_var(info
, &var
);
2132 var_to_display(p
, &info
->var
, info
);
2133 ops
->var
= info
->var
;
2135 updatescrollmode(p
, info
, vc
);
2139 static int fbcon_switch(struct vc_data
*vc
)
2141 struct fb_info
*info
, *old_info
= NULL
;
2142 struct fbcon_ops
*ops
;
2143 struct display
*p
= &fb_display
[vc
->vc_num
];
2144 struct fb_var_screeninfo var
;
2145 int i
, ret
, prev_console
, charcnt
= 256;
2147 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2148 ops
= info
->fbcon_par
;
2152 fbcon_set_origin(vc
);
2153 softback_top
= softback_curr
= softback_in
= softback_buf
;
2155 fbcon_update_softback(vc
);
2158 if (logo_shown
>= 0) {
2159 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2161 if (conp2
->vc_top
== logo_lines
2162 && conp2
->vc_bottom
== conp2
->vc_rows
)
2164 logo_shown
= FBCON_LOGO_CANSHOW
;
2167 prev_console
= ops
->currcon
;
2168 if (prev_console
!= -1)
2169 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2171 * FIXME: If we have multiple fbdev's loaded, we need to
2172 * update all info->currcon. Perhaps, we can place this
2173 * in a centralized structure, but this might break some
2176 * info->currcon = vc->vc_num;
2178 for (i
= 0; i
< FB_MAX
; i
++) {
2179 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2180 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2182 o
->currcon
= vc
->vc_num
;
2185 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2186 display_to_var(&var
, p
);
2187 var
.activate
= FB_ACTIVATE_NOW
;
2190 * make sure we don't unnecessarily trip the memcmp()
2193 info
->var
.activate
= var
.activate
;
2194 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2195 fb_set_var(info
, &var
);
2196 ops
->var
= info
->var
;
2198 if (old_info
!= NULL
&& (old_info
!= info
||
2199 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2200 if (info
->fbops
->fb_set_par
) {
2201 ret
= info
->fbops
->fb_set_par(info
);
2204 printk(KERN_ERR
"fbcon_switch: detected "
2205 "unhandled fb_set_par error, "
2206 "error code %d\n", ret
);
2209 if (old_info
!= info
)
2210 fbcon_del_cursor_timer(old_info
);
2213 if (fbcon_is_inactive(vc
, info
) ||
2214 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2215 fbcon_del_cursor_timer(info
);
2217 fbcon_add_cursor_timer(info
);
2219 set_blitting_type(vc
, info
);
2220 ops
->cursor_reset
= 1;
2222 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2223 ops
->rotate
= FB_ROTATE_UR
;
2224 set_blitting_type(vc
, info
);
2227 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2228 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2231 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2234 vc
->vc_complement_mask
<<= 1;
2236 updatescrollmode(p
, info
, vc
);
2238 switch (p
->scrollmode
) {
2239 case SCROLL_WRAP_MOVE
:
2240 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2242 case SCROLL_PAN_MOVE
:
2243 case SCROLL_PAN_REDRAW
:
2244 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2245 if (scrollback_phys_max
< 0)
2246 scrollback_phys_max
= 0;
2249 scrollback_phys_max
= 0;
2254 scrollback_current
= 0;
2256 if (!fbcon_is_inactive(vc
, info
)) {
2257 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2258 ops
->update_start(info
);
2261 fbcon_set_palette(vc
, color_table
);
2262 fbcon_clear_margins(vc
, 0);
2264 if (logo_shown
== FBCON_LOGO_DRAW
) {
2266 logo_shown
= fg_console
;
2267 /* This is protected above by initmem_freed */
2268 fb_show_logo(info
, ops
->rotate
);
2270 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2271 vc
->vc_size_row
* (vc
->vc_bottom
-
2278 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2281 struct fb_event event
;
2284 unsigned short charmask
= vc
->vc_hi_font_mask
?
2286 unsigned short oldc
;
2288 oldc
= vc
->vc_video_erase_char
;
2289 vc
->vc_video_erase_char
&= charmask
;
2290 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2291 vc
->vc_video_erase_char
= oldc
;
2295 if (!lock_fb_info(info
))
2298 event
.data
= &blank
;
2299 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2300 unlock_fb_info(info
);
2303 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2305 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2306 struct fbcon_ops
*ops
= info
->fbcon_par
;
2309 struct fb_var_screeninfo var
= info
->var
;
2314 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2315 fb_set_var(info
, &var
);
2317 ops
->var
= info
->var
;
2321 if (!fbcon_is_inactive(vc
, info
)) {
2322 if (ops
->blank_state
!= blank
) {
2323 ops
->blank_state
= blank
;
2324 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2325 ops
->cursor_flash
= (!blank
);
2327 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2328 if (fb_blank(info
, blank
))
2329 fbcon_generic_blank(vc
, info
, blank
);
2336 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2337 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2338 fbcon_del_cursor_timer(info
);
2340 fbcon_add_cursor_timer(info
);
2345 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2347 u8
*fontdata
= vc
->vc_font
.data
;
2348 u8
*data
= font
->data
;
2351 font
->width
= vc
->vc_font
.width
;
2352 font
->height
= vc
->vc_font
.height
;
2353 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2357 if (font
->width
<= 8) {
2358 j
= vc
->vc_font
.height
;
2359 for (i
= 0; i
< font
->charcount
; i
++) {
2360 memcpy(data
, fontdata
, j
);
2361 memset(data
+ j
, 0, 32 - j
);
2365 } else if (font
->width
<= 16) {
2366 j
= vc
->vc_font
.height
* 2;
2367 for (i
= 0; i
< font
->charcount
; i
++) {
2368 memcpy(data
, fontdata
, j
);
2369 memset(data
+ j
, 0, 64 - j
);
2373 } else if (font
->width
<= 24) {
2374 for (i
= 0; i
< font
->charcount
; i
++) {
2375 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2376 *data
++ = fontdata
[0];
2377 *data
++ = fontdata
[1];
2378 *data
++ = fontdata
[2];
2379 fontdata
+= sizeof(u32
);
2381 memset(data
, 0, 3 * (32 - j
));
2382 data
+= 3 * (32 - j
);
2385 j
= vc
->vc_font
.height
* 4;
2386 for (i
= 0; i
< font
->charcount
; i
++) {
2387 memcpy(data
, fontdata
, j
);
2388 memset(data
+ j
, 0, 128 - j
);
2396 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2397 const u8
* data
, int userfont
)
2399 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2400 struct fbcon_ops
*ops
= info
->fbcon_par
;
2401 struct display
*p
= &fb_display
[vc
->vc_num
];
2404 char *old_data
= NULL
;
2406 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2407 fbcon_set_origin(vc
);
2409 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2411 old_data
= vc
->vc_font
.data
;
2413 cnt
= FNTCHARCNT(data
);
2416 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2417 if ((p
->userfont
= userfont
))
2419 vc
->vc_font
.width
= w
;
2420 vc
->vc_font
.height
= h
;
2421 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2422 vc
->vc_hi_font_mask
= 0;
2423 if (vc
->vc_can_do_color
) {
2424 vc
->vc_complement_mask
>>= 1;
2425 vc
->vc_s_complement_mask
>>= 1;
2428 /* ++Edmund: reorder the attribute bits */
2429 if (vc
->vc_can_do_color
) {
2430 unsigned short *cp
=
2431 (unsigned short *) vc
->vc_origin
;
2432 int count
= vc
->vc_screenbuf_size
/ 2;
2434 for (; count
> 0; count
--, cp
++) {
2436 scr_writew(((c
& 0xfe00) >> 1) |
2439 c
= vc
->vc_video_erase_char
;
2440 vc
->vc_video_erase_char
=
2441 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2444 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2445 vc
->vc_hi_font_mask
= 0x100;
2446 if (vc
->vc_can_do_color
) {
2447 vc
->vc_complement_mask
<<= 1;
2448 vc
->vc_s_complement_mask
<<= 1;
2451 /* ++Edmund: reorder the attribute bits */
2453 unsigned short *cp
=
2454 (unsigned short *) vc
->vc_origin
;
2455 int count
= vc
->vc_screenbuf_size
/ 2;
2457 for (; count
> 0; count
--, cp
++) {
2458 unsigned short newc
;
2460 if (vc
->vc_can_do_color
)
2462 ((c
& 0xff00) << 1) | (c
&
2466 scr_writew(newc
, cp
);
2468 c
= vc
->vc_video_erase_char
;
2469 if (vc
->vc_can_do_color
) {
2470 vc
->vc_video_erase_char
=
2471 ((c
& 0xff00) << 1) | (c
& 0xff);
2474 vc
->vc_video_erase_char
= c
& ~0x100;
2482 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2483 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2486 vc_resize(vc
, cols
, rows
);
2487 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2488 fbcon_update_softback(vc
);
2489 } else if (CON_IS_VISIBLE(vc
)
2490 && vc
->vc_mode
== KD_TEXT
) {
2491 fbcon_clear_margins(vc
, 0);
2495 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2496 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2500 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2502 struct display
*od
= &fb_display
[con
];
2503 struct console_font
*f
= &vc
->vc_font
;
2505 if (od
->fontdata
== f
->data
)
2506 return 0; /* already the same font... */
2507 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2511 * User asked to set font; we are guaranteed that
2512 * a) width and height are in range 1..32
2513 * b) charcount does not exceed 512
2514 * but lets not assume that, since someone might someday want to use larger
2515 * fonts. And charcount of 512 is small for unicode support.
2517 * However, user space gives the font in 32 rows , regardless of
2518 * actual font height. So a new API is needed if support for larger fonts
2519 * is ever implemented.
2522 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2524 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2525 unsigned charcount
= font
->charcount
;
2526 int w
= font
->width
;
2527 int h
= font
->height
;
2530 u8
*new_data
, *data
= font
->data
;
2531 int pitch
= (font
->width
+7) >> 3;
2533 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2534 * If not this check should be changed to charcount < 256 */
2535 if (charcount
!= 256 && charcount
!= 512)
2538 /* Make sure drawing engine can handle the font */
2539 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2540 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2543 /* Make sure driver can handle the font length */
2544 if (fbcon_invalid_charcount(info
, charcount
))
2547 size
= h
* pitch
* charcount
;
2549 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2554 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2555 FNTSIZE(new_data
) = size
;
2556 FNTCHARCNT(new_data
) = charcount
;
2557 REFCOUNT(new_data
) = 0; /* usage counter */
2558 for (i
=0; i
< charcount
; i
++) {
2559 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2562 /* Since linux has a nice crc32 function use it for counting font
2564 csum
= crc32(0, new_data
, size
);
2566 FNTSUM(new_data
) = csum
;
2567 /* Check if the same font is on some other console already */
2568 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2569 struct vc_data
*tmp
= vc_cons
[i
].d
;
2571 if (fb_display
[i
].userfont
&&
2572 fb_display
[i
].fontdata
&&
2573 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2574 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2575 tmp
->vc_font
.width
== w
&&
2576 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2577 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2578 new_data
= (u8
*)fb_display
[i
].fontdata
;
2582 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2585 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2587 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2588 const struct font_desc
*f
;
2591 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2592 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2593 else if (!(f
= find_font(name
)))
2596 font
->width
= f
->width
;
2597 font
->height
= f
->height
;
2598 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2601 static u16 palette_red
[16];
2602 static u16 palette_green
[16];
2603 static u16 palette_blue
[16];
2605 static struct fb_cmap palette_cmap
= {
2606 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2609 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2611 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2615 if (fbcon_is_inactive(vc
, info
))
2618 if (!CON_IS_VISIBLE(vc
))
2621 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2623 for (i
= j
= 0; i
< 16; i
++) {
2625 val
= vc
->vc_palette
[j
++];
2626 palette_red
[k
] = (val
<< 8) | val
;
2627 val
= vc
->vc_palette
[j
++];
2628 palette_green
[k
] = (val
<< 8) | val
;
2629 val
= vc
->vc_palette
[j
++];
2630 palette_blue
[k
] = (val
<< 8) | val
;
2632 palette_cmap
.len
= 16;
2633 palette_cmap
.start
= 0;
2635 * If framebuffer is capable of less than 16 colors,
2636 * use default palette of fbcon.
2639 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2641 return fb_set_cmap(&palette_cmap
, info
);
2644 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2649 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2650 return (u16
*) (vc
->vc_origin
+ offset
);
2651 line
= offset
/ vc
->vc_size_row
;
2652 if (line
>= softback_lines
)
2653 return (u16
*) (vc
->vc_origin
+ offset
-
2654 softback_lines
* vc
->vc_size_row
);
2655 p
= softback_curr
+ offset
;
2656 if (p
>= softback_end
)
2657 p
+= softback_buf
- softback_end
;
2661 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2667 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2668 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2670 x
= offset
% vc
->vc_cols
;
2671 y
= offset
/ vc
->vc_cols
;
2672 if (vc
->vc_num
== fg_console
)
2673 y
+= softback_lines
;
2674 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2675 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2676 unsigned long offset
= pos
- softback_curr
;
2678 if (pos
< softback_curr
)
2679 offset
+= softback_end
- softback_buf
;
2681 x
= offset
% vc
->vc_cols
;
2682 y
= offset
/ vc
->vc_cols
;
2683 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2684 if (ret
== softback_end
)
2686 if (ret
== softback_in
)
2687 ret
= vc
->vc_origin
;
2689 /* Should not happen */
2691 ret
= vc
->vc_origin
;
2700 /* As we might be inside of softback, we may work with non-contiguous buffer,
2701 that's why we have to use a separate routine. */
2702 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2705 u16 a
= scr_readw(p
);
2706 if (!vc
->vc_can_do_color
)
2708 else if (vc
->vc_hi_font_mask
== 0x100)
2709 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2710 (((a
) & 0x0e00) << 4);
2712 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2713 (((a
) & 0x0700) << 4);
2715 if (p
== (u16
*) softback_end
)
2716 p
= (u16
*) softback_buf
;
2717 if (p
== (u16
*) softback_in
)
2718 p
= (u16
*) vc
->vc_origin
;
2722 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2724 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2725 struct fbcon_ops
*ops
= info
->fbcon_par
;
2726 struct display
*disp
= &fb_display
[fg_console
];
2727 int offset
, limit
, scrollback_old
;
2730 if (vc
->vc_num
!= fg_console
)
2732 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2734 if (logo_shown
>= 0) {
2735 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2737 if (conp2
->vc_top
== logo_lines
2738 && conp2
->vc_bottom
== conp2
->vc_rows
)
2740 if (logo_shown
== vc
->vc_num
) {
2746 logo_lines
* vc
->vc_size_row
;
2747 for (i
= 0; i
< logo_lines
; i
++) {
2748 if (p
== softback_top
)
2750 if (p
== softback_buf
)
2752 p
-= vc
->vc_size_row
;
2753 q
-= vc
->vc_size_row
;
2754 scr_memcpyw((u16
*) q
, (u16
*) p
,
2757 softback_in
= softback_curr
= p
;
2758 update_region(vc
, vc
->vc_origin
,
2759 logo_lines
* vc
->vc_cols
);
2761 logo_shown
= FBCON_LOGO_CANSHOW
;
2763 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2764 fbcon_redraw_softback(vc
, disp
, lines
);
2765 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2769 if (!scrollback_phys_max
)
2772 scrollback_old
= scrollback_current
;
2773 scrollback_current
-= lines
;
2774 if (scrollback_current
< 0)
2775 scrollback_current
= 0;
2776 else if (scrollback_current
> scrollback_max
)
2777 scrollback_current
= scrollback_max
;
2778 if (scrollback_current
== scrollback_old
)
2781 if (fbcon_is_inactive(vc
, info
))
2784 fbcon_cursor(vc
, CM_ERASE
);
2786 offset
= disp
->yscroll
- scrollback_current
;
2787 limit
= disp
->vrows
;
2788 switch (disp
->scrollmode
) {
2789 case SCROLL_WRAP_MOVE
:
2790 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2792 case SCROLL_PAN_MOVE
:
2793 case SCROLL_PAN_REDRAW
:
2794 limit
-= vc
->vc_rows
;
2795 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2800 else if (offset
>= limit
)
2803 ops
->var
.xoffset
= 0;
2804 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2805 ops
->update_start(info
);
2807 if (!scrollback_current
)
2808 fbcon_cursor(vc
, CM_DRAW
);
2812 static int fbcon_set_origin(struct vc_data
*vc
)
2815 fbcon_scrolldelta(vc
, softback_lines
);
2819 static void fbcon_suspended(struct fb_info
*info
)
2821 struct vc_data
*vc
= NULL
;
2822 struct fbcon_ops
*ops
= info
->fbcon_par
;
2824 if (!ops
|| ops
->currcon
< 0)
2826 vc
= vc_cons
[ops
->currcon
].d
;
2828 /* Clear cursor, restore saved data */
2829 fbcon_cursor(vc
, CM_ERASE
);
2832 static void fbcon_resumed(struct fb_info
*info
)
2835 struct fbcon_ops
*ops
= info
->fbcon_par
;
2837 if (!ops
|| ops
->currcon
< 0)
2839 vc
= vc_cons
[ops
->currcon
].d
;
2844 static void fbcon_modechanged(struct fb_info
*info
)
2846 struct fbcon_ops
*ops
= info
->fbcon_par
;
2851 if (!ops
|| ops
->currcon
< 0)
2853 vc
= vc_cons
[ops
->currcon
].d
;
2854 if (vc
->vc_mode
!= KD_TEXT
||
2855 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2858 p
= &fb_display
[vc
->vc_num
];
2859 set_blitting_type(vc
, info
);
2861 if (CON_IS_VISIBLE(vc
)) {
2862 var_to_display(p
, &info
->var
, info
);
2863 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2864 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2865 cols
/= vc
->vc_font
.width
;
2866 rows
/= vc
->vc_font
.height
;
2867 vc_resize(vc
, cols
, rows
);
2868 updatescrollmode(p
, info
, vc
);
2870 scrollback_current
= 0;
2872 if (!fbcon_is_inactive(vc
, info
)) {
2873 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2874 ops
->update_start(info
);
2877 fbcon_set_palette(vc
, color_table
);
2880 fbcon_update_softback(vc
);
2884 static void fbcon_set_all_vcs(struct fb_info
*info
)
2886 struct fbcon_ops
*ops
= info
->fbcon_par
;
2889 int i
, rows
, cols
, fg
= -1;
2891 if (!ops
|| ops
->currcon
< 0)
2894 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2896 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2897 registered_fb
[con2fb_map
[i
]] != info
)
2900 if (CON_IS_VISIBLE(vc
)) {
2905 p
= &fb_display
[vc
->vc_num
];
2906 set_blitting_type(vc
, info
);
2907 var_to_display(p
, &info
->var
, info
);
2908 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2909 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2910 cols
/= vc
->vc_font
.width
;
2911 rows
/= vc
->vc_font
.height
;
2912 vc_resize(vc
, cols
, rows
);
2916 fbcon_modechanged(info
);
2919 static int fbcon_mode_deleted(struct fb_info
*info
,
2920 struct fb_videomode
*mode
)
2922 struct fb_info
*fb_info
;
2924 int i
, j
, found
= 0;
2926 /* before deletion, ensure that mode is not in use */
2927 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2931 fb_info
= registered_fb
[j
];
2932 if (fb_info
!= info
)
2937 if (fb_mode_is_equal(p
->mode
, mode
)) {
2945 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2946 static int fbcon_unbind(void)
2950 ret
= unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2954 fbcon_has_console_bind
= 0;
2959 static inline int fbcon_unbind(void)
2963 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2965 static int fbcon_fb_unbind(int idx
)
2967 int i
, new_idx
= -1, ret
= 0;
2969 if (!fbcon_has_console_bind
)
2972 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2973 if (con2fb_map
[i
] != idx
&&
2974 con2fb_map
[i
] != -1) {
2980 if (new_idx
!= -1) {
2981 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2982 if (con2fb_map
[i
] == idx
)
2983 set_con2fb_map(i
, new_idx
, 0);
2986 ret
= fbcon_unbind();
2991 static int fbcon_fb_unregistered(struct fb_info
*info
)
2996 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2997 if (con2fb_map
[i
] == idx
)
3001 if (idx
== info_idx
) {
3004 for (i
= 0; i
< FB_MAX
; i
++) {
3005 if (registered_fb
[i
] != NULL
) {
3012 if (info_idx
!= -1) {
3013 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3014 if (con2fb_map
[i
] == -1)
3015 con2fb_map
[i
] = info_idx
;
3019 if (primary_device
== idx
)
3020 primary_device
= -1;
3022 if (!num_registered_fb
)
3023 unregister_con_driver(&fb_con
);
3028 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3029 static void fbcon_select_primary(struct fb_info
*info
)
3031 if (!map_override
&& primary_device
== -1 &&
3032 fb_is_primary_device(info
)) {
3035 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3036 info
->fix
.id
, info
->node
);
3037 primary_device
= info
->node
;
3039 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3040 con2fb_map_boot
[i
] = primary_device
;
3042 if (con_is_bound(&fb_con
)) {
3043 printk(KERN_INFO
"fbcon: Remapping primary device, "
3044 "fb%i, to tty %i-%i\n", info
->node
,
3045 first_fb_vc
+ 1, last_fb_vc
+ 1);
3046 info_idx
= primary_device
;
3052 static inline void fbcon_select_primary(struct fb_info
*info
)
3056 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3058 static int fbcon_fb_registered(struct fb_info
*info
)
3060 int ret
= 0, i
, idx
;
3063 fbcon_select_primary(info
);
3065 if (info_idx
== -1) {
3066 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3067 if (con2fb_map_boot
[i
] == idx
) {
3074 ret
= fbcon_takeover(1);
3076 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3077 if (con2fb_map_boot
[i
] == idx
)
3078 set_con2fb_map(i
, idx
, 0);
3085 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3087 struct fbcon_ops
*ops
= info
->fbcon_par
;
3090 if (!ops
|| ops
->currcon
< 0)
3093 vc
= vc_cons
[ops
->currcon
].d
;
3094 if (vc
->vc_mode
!= KD_TEXT
||
3095 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3098 if (CON_IS_VISIBLE(vc
)) {
3102 do_unblank_screen(0);
3104 ops
->blank_state
= blank
;
3107 static void fbcon_new_modelist(struct fb_info
*info
)
3111 struct fb_var_screeninfo var
;
3112 const struct fb_videomode
*mode
;
3114 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3115 if (registered_fb
[con2fb_map
[i
]] != info
)
3117 if (!fb_display
[i
].mode
)
3120 display_to_var(&var
, &fb_display
[i
]);
3121 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3123 fb_videomode_to_var(&var
, mode
);
3124 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3128 static void fbcon_get_requirement(struct fb_info
*info
,
3129 struct fb_blit_caps
*caps
)
3137 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3139 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3140 info
->node
== con2fb_map
[i
]) {
3142 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3143 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3144 charcnt
= (p
->userfont
) ?
3145 FNTCHARCNT(p
->fontdata
) : 256;
3146 if (caps
->len
< charcnt
)
3147 caps
->len
= charcnt
;
3151 vc
= vc_cons
[fg_console
].d
;
3153 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3154 info
->node
== con2fb_map
[fg_console
]) {
3155 p
= &fb_display
[fg_console
];
3156 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3157 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3158 caps
->len
= (p
->userfont
) ?
3159 FNTCHARCNT(p
->fontdata
) : 256;
3164 static int fbcon_event_notify(struct notifier_block
*self
,
3165 unsigned long action
, void *data
)
3167 struct fb_event
*event
= data
;
3168 struct fb_info
*info
= event
->info
;
3169 struct fb_videomode
*mode
;
3170 struct fb_con2fbmap
*con2fb
;
3171 struct fb_blit_caps
*caps
;
3175 * ignore all events except driver registration and deregistration
3176 * if fbcon is not active
3178 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3179 action
== FB_EVENT_FB_UNREGISTERED
))
3183 case FB_EVENT_SUSPEND
:
3184 fbcon_suspended(info
);
3186 case FB_EVENT_RESUME
:
3187 fbcon_resumed(info
);
3189 case FB_EVENT_MODE_CHANGE
:
3190 fbcon_modechanged(info
);
3192 case FB_EVENT_MODE_CHANGE_ALL
:
3193 fbcon_set_all_vcs(info
);
3195 case FB_EVENT_MODE_DELETE
:
3197 ret
= fbcon_mode_deleted(info
, mode
);
3199 case FB_EVENT_FB_UNBIND
:
3201 ret
= fbcon_fb_unbind(idx
);
3203 case FB_EVENT_FB_REGISTERED
:
3204 ret
= fbcon_fb_registered(info
);
3206 case FB_EVENT_FB_UNREGISTERED
:
3207 ret
= fbcon_fb_unregistered(info
);
3209 case FB_EVENT_SET_CONSOLE_MAP
:
3210 con2fb
= event
->data
;
3211 ret
= set_con2fb_map(con2fb
->console
- 1,
3212 con2fb
->framebuffer
, 1);
3214 case FB_EVENT_GET_CONSOLE_MAP
:
3215 con2fb
= event
->data
;
3216 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3218 case FB_EVENT_BLANK
:
3219 fbcon_fb_blanked(info
, *(int *)event
->data
);
3221 case FB_EVENT_NEW_MODELIST
:
3222 fbcon_new_modelist(info
);
3224 case FB_EVENT_GET_REQ
:
3226 fbcon_get_requirement(info
, caps
);
3234 * The console `switch' structure for the frame buffer based console
3237 static const struct consw fb_con
= {
3238 .owner
= THIS_MODULE
,
3239 .con_startup
= fbcon_startup
,
3240 .con_init
= fbcon_init
,
3241 .con_deinit
= fbcon_deinit
,
3242 .con_clear
= fbcon_clear
,
3243 .con_putc
= fbcon_putc
,
3244 .con_putcs
= fbcon_putcs
,
3245 .con_cursor
= fbcon_cursor
,
3246 .con_scroll
= fbcon_scroll
,
3247 .con_bmove
= fbcon_bmove
,
3248 .con_switch
= fbcon_switch
,
3249 .con_blank
= fbcon_blank
,
3250 .con_font_set
= fbcon_set_font
,
3251 .con_font_get
= fbcon_get_font
,
3252 .con_font_default
= fbcon_set_def_font
,
3253 .con_font_copy
= fbcon_copy_font
,
3254 .con_set_palette
= fbcon_set_palette
,
3255 .con_scrolldelta
= fbcon_scrolldelta
,
3256 .con_set_origin
= fbcon_set_origin
,
3257 .con_invert_region
= fbcon_invert_region
,
3258 .con_screen_pos
= fbcon_screen_pos
,
3259 .con_getxy
= fbcon_getxy
,
3260 .con_resize
= fbcon_resize
,
3263 static struct notifier_block fbcon_event_notifier
= {
3264 .notifier_call
= fbcon_event_notify
,
3267 static ssize_t
store_rotate(struct device
*device
,
3268 struct device_attribute
*attr
, const char *buf
,
3271 struct fb_info
*info
;
3275 if (fbcon_has_exited
)
3278 acquire_console_sem();
3279 idx
= con2fb_map
[fg_console
];
3281 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3284 info
= registered_fb
[idx
];
3285 rotate
= simple_strtoul(buf
, last
, 0);
3286 fbcon_rotate(info
, rotate
);
3288 release_console_sem();
3292 static ssize_t
store_rotate_all(struct device
*device
,
3293 struct device_attribute
*attr
,const char *buf
,
3296 struct fb_info
*info
;
3300 if (fbcon_has_exited
)
3303 acquire_console_sem();
3304 idx
= con2fb_map
[fg_console
];
3306 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3309 info
= registered_fb
[idx
];
3310 rotate
= simple_strtoul(buf
, last
, 0);
3311 fbcon_rotate_all(info
, rotate
);
3313 release_console_sem();
3317 static ssize_t
show_rotate(struct device
*device
,
3318 struct device_attribute
*attr
,char *buf
)
3320 struct fb_info
*info
;
3321 int rotate
= 0, idx
;
3323 if (fbcon_has_exited
)
3326 acquire_console_sem();
3327 idx
= con2fb_map
[fg_console
];
3329 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3332 info
= registered_fb
[idx
];
3333 rotate
= fbcon_get_rotate(info
);
3335 release_console_sem();
3336 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3339 static ssize_t
show_cursor_blink(struct device
*device
,
3340 struct device_attribute
*attr
, char *buf
)
3342 struct fb_info
*info
;
3343 struct fbcon_ops
*ops
;
3344 int idx
, blink
= -1;
3346 if (fbcon_has_exited
)
3349 acquire_console_sem();
3350 idx
= con2fb_map
[fg_console
];
3352 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3355 info
= registered_fb
[idx
];
3356 ops
= info
->fbcon_par
;
3361 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3363 release_console_sem();
3364 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3367 static ssize_t
store_cursor_blink(struct device
*device
,
3368 struct device_attribute
*attr
,
3369 const char *buf
, size_t count
)
3371 struct fb_info
*info
;
3375 if (fbcon_has_exited
)
3378 acquire_console_sem();
3379 idx
= con2fb_map
[fg_console
];
3381 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3384 info
= registered_fb
[idx
];
3386 if (!info
->fbcon_par
)
3389 blink
= simple_strtoul(buf
, last
, 0);
3392 fbcon_cursor_noblink
= 0;
3393 fbcon_add_cursor_timer(info
);
3395 fbcon_cursor_noblink
= 1;
3396 fbcon_del_cursor_timer(info
);
3400 release_console_sem();
3404 static struct device_attribute device_attrs
[] = {
3405 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3406 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3407 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3408 store_cursor_blink
),
3411 static int fbcon_init_device(void)
3415 fbcon_has_sysfs
= 1;
3417 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3418 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3426 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3428 fbcon_has_sysfs
= 0;
3434 static void fbcon_start(void)
3436 if (num_registered_fb
) {
3439 acquire_console_sem();
3441 for (i
= 0; i
< FB_MAX
; i
++) {
3442 if (registered_fb
[i
] != NULL
) {
3448 release_console_sem();
3453 static void fbcon_exit(void)
3455 struct fb_info
*info
;
3458 if (fbcon_has_exited
)
3461 kfree((void *)softback_buf
);
3464 for (i
= 0; i
< FB_MAX
; i
++) {
3468 info
= registered_fb
[i
];
3473 pending
= cancel_work_sync(&info
->queue
);
3474 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3477 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3478 if (con2fb_map
[j
] == i
)
3483 if (info
->fbops
->fb_release
)
3484 info
->fbops
->fb_release(info
, 0);
3485 module_put(info
->fbops
->owner
);
3487 if (info
->fbcon_par
) {
3488 struct fbcon_ops
*ops
= info
->fbcon_par
;
3490 fbcon_del_cursor_timer(info
);
3491 kfree(ops
->cursor_src
);
3492 kfree(info
->fbcon_par
);
3493 info
->fbcon_par
= NULL
;
3496 if (info
->queue
.func
== fb_flashcursor
)
3497 info
->queue
.func
= NULL
;
3501 fbcon_has_exited
= 1;
3504 static int __init
fb_console_init(void)
3508 acquire_console_sem();
3509 fb_register_client(&fbcon_event_notifier
);
3510 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3513 if (IS_ERR(fbcon_device
)) {
3514 printk(KERN_WARNING
"Unable to create device "
3515 "for fbcon; errno = %ld\n",
3516 PTR_ERR(fbcon_device
));
3517 fbcon_device
= NULL
;
3519 fbcon_init_device();
3521 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3524 release_console_sem();
3529 module_init(fb_console_init
);
3533 static void __exit
fbcon_deinit_device(void)
3537 if (fbcon_has_sysfs
) {
3538 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3539 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3541 fbcon_has_sysfs
= 0;
3545 static void __exit
fb_console_exit(void)
3547 acquire_console_sem();
3548 fb_unregister_client(&fbcon_event_notifier
);
3549 fbcon_deinit_device();
3550 device_destroy(fb_class
, MKDEV(0, 0));
3552 release_console_sem();
3553 unregister_con_driver(&fb_con
);
3556 module_exit(fb_console_exit
);
3560 MODULE_LICENSE("GPL");