2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
15 * Jes Sorensen (jds@kom.auc.dk)
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
23 * with work by Guenther Kelleter
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
47 * o vga VGA characters/attributes
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
61 #include <linux/module.h>
62 #include <linux/types.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
69 #include <linux/slab.h>
71 #include <linux/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
84 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
86 # define DPRINTK(fmt, args...)
90 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
91 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
92 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
95 static struct display fb_display
[MAX_NR_CONSOLES
];
97 static signed char con2fb_map
[MAX_NR_CONSOLES
];
98 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
100 static int logo_lines
;
101 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
103 static int logo_shown
= FBCON_LOGO_CANSHOW
;
104 /* Software scrollback */
105 static int fbcon_softback_size
= 32768;
106 static unsigned long softback_buf
, softback_curr
;
107 static unsigned long softback_in
;
108 static unsigned long softback_top
, softback_end
;
109 static int softback_lines
;
110 /* console mappings */
111 static int first_fb_vc
;
112 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
113 static int fbcon_is_default
= 1;
114 static int fbcon_has_exited
;
115 static int primary_device
= -1;
116 static int fbcon_has_console_bind
;
118 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
119 static int map_override
;
121 static inline void fbcon_map_override(void)
126 static inline void fbcon_map_override(void)
129 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
132 static char fontname
[40];
134 /* current fb_info */
135 static int info_idx
= -1;
137 /* console rotation */
138 static int initial_rotation
;
139 static int fbcon_has_sysfs
;
141 static const struct consw fb_con
;
143 #define CM_SOFTBACK (8)
145 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
147 static int fbcon_set_origin(struct vc_data
*);
149 static int fbcon_cursor_noblink
;
151 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
154 * Interface used by the world
157 static const char *fbcon_startup(void);
158 static void fbcon_init(struct vc_data
*vc
, int init
);
159 static void fbcon_deinit(struct vc_data
*vc
);
160 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
162 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
163 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
164 int count
, int ypos
, int xpos
);
165 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
166 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
167 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
169 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
170 int height
, int width
);
171 static int fbcon_switch(struct vc_data
*vc
);
172 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
173 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
174 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
179 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
180 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
181 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
182 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
183 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
184 int dy
, int dx
, int height
, int width
, u_int y_break
);
185 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
187 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
188 int line
, int count
, int dy
);
189 static void fbcon_modechanged(struct fb_info
*info
);
190 static void fbcon_set_all_vcs(struct fb_info
*info
);
191 static void fbcon_start(void);
192 static void fbcon_exit(void);
193 static struct device
*fbcon_device
;
195 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
196 static inline void fbcon_set_rotation(struct fb_info
*info
)
198 struct fbcon_ops
*ops
= info
->fbcon_par
;
200 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
201 ops
->p
->con_rotate
< 4)
202 ops
->rotate
= ops
->p
->con_rotate
;
207 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
209 struct fbcon_ops
*ops
= info
->fbcon_par
;
210 struct fb_info
*fb_info
;
212 if (!ops
|| ops
->currcon
== -1)
215 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
217 if (info
== fb_info
) {
218 struct display
*p
= &fb_display
[ops
->currcon
];
221 p
->con_rotate
= rotate
;
225 fbcon_modechanged(info
);
229 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
231 struct fbcon_ops
*ops
= info
->fbcon_par
;
236 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
239 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
241 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
242 registered_fb
[con2fb_map
[i
]] != info
)
245 p
= &fb_display
[vc
->vc_num
];
246 p
->con_rotate
= rotate
;
249 fbcon_set_all_vcs(info
);
252 static inline void fbcon_set_rotation(struct fb_info
*info
)
254 struct fbcon_ops
*ops
= info
->fbcon_par
;
256 ops
->rotate
= FB_ROTATE_UR
;
259 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
264 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
268 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
270 static int fbcon_get_rotate(struct fb_info
*info
)
272 struct fbcon_ops
*ops
= info
->fbcon_par
;
274 return (ops
) ? ops
->rotate
: 0;
277 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
279 struct fbcon_ops
*ops
= info
->fbcon_par
;
281 return (info
->state
!= FBINFO_STATE_RUNNING
||
282 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
) &&
283 !vt_force_oops_output(vc
);
286 static int get_color(struct vc_data
*vc
, struct fb_info
*info
,
289 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
292 if (console_blanked
) {
293 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
295 c
= vc
->vc_video_erase_char
& charmask
;
299 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
300 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
305 int col
= mono_col(info
);
307 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
308 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
313 color
= (is_fg
) ? fg
: bg
;
318 * Scale down 16-colors to 4 colors. Default 4-color palette
319 * is grayscale. However, simply dividing the values by 4
320 * will not work, as colors 1, 2 and 3 will be scaled-down
321 * to zero rendering them invisible. So empirically convert
322 * colors to a sane 4-level grayscale.
326 color
= 0; /* black */
329 color
= 2; /* white */
332 color
= 1; /* gray */
335 color
= 3; /* intense white */
341 * Last 8 entries of default 16-color palette is a more intense
342 * version of the first 8 (i.e., same chrominance, different
353 static void fbcon_update_softback(struct vc_data
*vc
)
355 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
358 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
360 /* Smaller scrollback makes no sense, and 0 would screw
361 the operation totally */
365 static void fb_flashcursor(struct work_struct
*work
)
367 struct fb_info
*info
= container_of(work
, struct fb_info
, queue
);
368 struct fbcon_ops
*ops
= info
->fbcon_par
;
369 struct vc_data
*vc
= NULL
;
374 /* FIXME: we should sort out the unbind locking instead */
375 /* instead we just fail to flash the cursor if we can't get
376 * the lock instead of blocking fbcon deinit */
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 queue_work(system_power_efficient_wq
, &info
->queue
);
405 mod_timer(&ops
->cursor_timer
, jiffies
+ ops
->cur_blink_jiffies
);
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
+ ops
->cur_blink_jiffies
;
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 strlcpy(fontname
, options
+ 5, sizeof(fontname
));
453 if (!strncmp(options
, "scrollback:", 11)) {
456 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
457 if (*options
== 'k' || *options
== 'K') {
458 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();
479 if (!strncmp(options
, "vc:", 3)) {
482 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
485 if (*options
++ == '-')
486 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
487 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;
503 __setup("fbcon=", fb_console_setup
);
506 static int search_fb_in_map(int idx
)
510 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
511 if (con2fb_map
[i
] == idx
)
517 static int search_for_mapped_con(void)
521 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
522 if (con2fb_map
[i
] != -1)
528 static int do_fbcon_takeover(int show_logo
)
532 if (!num_registered_fb
)
536 logo_shown
= FBCON_LOGO_DONTSHOW
;
538 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
539 con2fb_map
[i
] = info_idx
;
541 err
= do_take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
545 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
->cursor_src
);
748 kfree(ops
->fontbuffer
);
749 kfree(oldinfo
->fbcon_par
);
750 oldinfo
->fbcon_par
= NULL
;
751 module_put(oldinfo
->fbops
->owner
);
753 If oldinfo and newinfo are driving the same hardware,
754 the fb_release() method of oldinfo may attempt to
755 restore the hardware state. This will leave the
756 newinfo in an undefined state. Thus, a call to
757 fb_set_par() may be needed for the newinfo.
759 if (newinfo
&& newinfo
->fbops
->fb_set_par
) {
760 ret
= newinfo
->fbops
->fb_set_par(newinfo
);
763 printk(KERN_ERR
"con2fb_release_oldinfo: "
764 "detected unhandled fb_set_par error, "
765 "error code %d\n", ret
);
772 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
773 int unit
, int show_logo
)
775 struct fbcon_ops
*ops
= info
->fbcon_par
;
778 ops
->currcon
= fg_console
;
780 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
)) {
781 ret
= info
->fbops
->fb_set_par(info
);
784 printk(KERN_ERR
"con2fb_init_display: detected "
785 "unhandled fb_set_par error, "
786 "error code %d\n", ret
);
789 ops
->flags
|= FBCON_FLAGS_INIT
;
791 fbcon_set_disp(info
, &info
->var
, unit
);
794 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
795 struct fb_info
*fg_info
=
796 registered_fb
[con2fb_map
[fg_console
]];
798 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
799 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
803 update_screen(vc_cons
[fg_console
].d
);
807 * set_con2fb_map - map console to frame buffer device
808 * @unit: virtual console number to map
809 * @newidx: frame buffer index to map virtual console to
810 * @user: user request
812 * Maps a virtual console @unit to a frame buffer device
815 * This should be called with the console lock held.
817 static int set_con2fb_map(int unit
, int newidx
, int user
)
819 struct vc_data
*vc
= vc_cons
[unit
].d
;
820 int oldidx
= con2fb_map
[unit
];
821 struct fb_info
*info
= registered_fb
[newidx
];
822 struct fb_info
*oldinfo
= NULL
;
825 if (oldidx
== newidx
)
831 if (!search_for_mapped_con() || !con_is_bound(&fb_con
)) {
833 return do_fbcon_takeover(0);
837 oldinfo
= registered_fb
[oldidx
];
839 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
))
871 * Low Level Operations
873 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
874 static int var_to_display(struct display
*disp
,
875 struct fb_var_screeninfo
*var
,
876 struct fb_info
*info
)
878 disp
->xres_virtual
= var
->xres_virtual
;
879 disp
->yres_virtual
= var
->yres_virtual
;
880 disp
->bits_per_pixel
= var
->bits_per_pixel
;
881 disp
->grayscale
= var
->grayscale
;
882 disp
->nonstd
= var
->nonstd
;
883 disp
->accel_flags
= var
->accel_flags
;
884 disp
->height
= var
->height
;
885 disp
->width
= var
->width
;
886 disp
->red
= var
->red
;
887 disp
->green
= var
->green
;
888 disp
->blue
= var
->blue
;
889 disp
->transp
= var
->transp
;
890 disp
->rotate
= var
->rotate
;
891 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
892 if (disp
->mode
== NULL
)
893 /* This should not happen */
898 static void display_to_var(struct fb_var_screeninfo
*var
,
899 struct display
*disp
)
901 fb_videomode_to_var(var
, disp
->mode
);
902 var
->xres_virtual
= disp
->xres_virtual
;
903 var
->yres_virtual
= disp
->yres_virtual
;
904 var
->bits_per_pixel
= disp
->bits_per_pixel
;
905 var
->grayscale
= disp
->grayscale
;
906 var
->nonstd
= disp
->nonstd
;
907 var
->accel_flags
= disp
->accel_flags
;
908 var
->height
= disp
->height
;
909 var
->width
= disp
->width
;
910 var
->red
= disp
->red
;
911 var
->green
= disp
->green
;
912 var
->blue
= disp
->blue
;
913 var
->transp
= disp
->transp
;
914 var
->rotate
= disp
->rotate
;
917 static const char *fbcon_startup(void)
919 const char *display_desc
= "frame buffer device";
920 struct display
*p
= &fb_display
[fg_console
];
921 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
922 const struct font_desc
*font
= NULL
;
923 struct module
*owner
;
924 struct fb_info
*info
= NULL
;
925 struct fbcon_ops
*ops
;
929 * If num_registered_fb is zero, this is a call for the dummy part.
930 * The frame buffer devices weren't initialized yet.
932 if (!num_registered_fb
|| info_idx
== -1)
935 * Instead of blindly using registered_fb[0], we use info_idx, set by
938 info
= registered_fb
[info_idx
];
942 owner
= info
->fbops
->owner
;
943 if (!try_module_get(owner
))
945 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
950 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
958 ops
->cur_rotate
= -1;
959 info
->fbcon_par
= ops
;
960 p
->con_rotate
= initial_rotation
;
961 set_blitting_type(vc
, info
);
963 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
964 if (fbcon_softback_size
) {
968 kmalloc(fbcon_softback_size
,
971 fbcon_softback_size
= 0;
977 kfree((void *) softback_buf
);
983 softback_in
= softback_top
= softback_curr
=
988 /* Setup default font */
989 if (!p
->fontdata
&& !vc
->vc_font
.data
) {
990 if (!fontname
[0] || !(font
= find_font(fontname
)))
991 font
= get_default_font(info
->var
.xres
,
994 info
->pixmap
.blit_y
);
995 vc
->vc_font
.width
= font
->width
;
996 vc
->vc_font
.height
= font
->height
;
997 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
998 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
1000 p
->fontdata
= vc
->vc_font
.data
;
1003 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1004 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1005 cols
/= vc
->vc_font
.width
;
1006 rows
/= vc
->vc_font
.height
;
1007 vc_resize(vc
, cols
, rows
);
1009 DPRINTK("mode: %s\n", info
->fix
.id
);
1010 DPRINTK("visual: %d\n", info
->fix
.visual
);
1011 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
1013 info
->var
.bits_per_pixel
);
1015 fbcon_add_cursor_timer(info
);
1016 fbcon_has_exited
= 0;
1017 return display_desc
;
1020 static void fbcon_init(struct vc_data
*vc
, int init
)
1022 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1023 struct fbcon_ops
*ops
;
1024 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1025 struct vc_data
*svc
= *default_mode
;
1026 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1027 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1030 if (info_idx
== -1 || info
== NULL
)
1035 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1036 (info
->fix
.type
== FB_TYPE_TEXT
))
1039 if (var_to_display(p
, &info
->var
, info
))
1042 if (!info
->fbcon_par
)
1043 con2fb_acquire_newinfo(vc
, info
, vc
->vc_num
, -1);
1045 /* If we are not the first console on this
1046 fb, copy the font from that console */
1047 t
= &fb_display
[fg_console
];
1050 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1052 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1054 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1055 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1056 p
->userfont
= t
->userfont
;
1059 REFCOUNT(p
->fontdata
)++;
1061 const struct font_desc
*font
= NULL
;
1063 if (!fontname
[0] || !(font
= find_font(fontname
)))
1064 font
= get_default_font(info
->var
.xres
,
1066 info
->pixmap
.blit_x
,
1067 info
->pixmap
.blit_y
);
1068 vc
->vc_font
.width
= font
->width
;
1069 vc
->vc_font
.height
= font
->height
;
1070 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1071 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1072 support more fonts */
1077 charcnt
= FNTCHARCNT(p
->fontdata
);
1079 vc
->vc_panic_force_write
= !!(info
->flags
& FBINFO_CAN_FORCE_OUTPUT
);
1080 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1081 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1082 if (charcnt
== 256) {
1083 vc
->vc_hi_font_mask
= 0;
1085 vc
->vc_hi_font_mask
= 0x100;
1086 if (vc
->vc_can_do_color
)
1087 vc
->vc_complement_mask
<<= 1;
1090 if (!*svc
->vc_uni_pagedir_loc
)
1091 con_set_default_unimap(svc
);
1092 if (!*vc
->vc_uni_pagedir_loc
)
1093 con_copy_unimap(vc
, svc
);
1095 ops
= info
->fbcon_par
;
1096 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1097 p
->con_rotate
= initial_rotation
;
1098 set_blitting_type(vc
, info
);
1102 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1103 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1104 new_cols
/= vc
->vc_font
.width
;
1105 new_rows
/= vc
->vc_font
.height
;
1108 * We must always set the mode. The mode of the previous console
1109 * driver could be in the same resolution but we are using different
1110 * hardware so we have to initialize the hardware.
1112 * We need to do it in fbcon_init() to prevent screen corruption.
1114 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1115 if (info
->fbops
->fb_set_par
&&
1116 !(ops
->flags
& FBCON_FLAGS_INIT
)) {
1117 ret
= info
->fbops
->fb_set_par(info
);
1120 printk(KERN_ERR
"fbcon_init: detected "
1121 "unhandled fb_set_par error, "
1122 "error code %d\n", ret
);
1125 ops
->flags
|= FBCON_FLAGS_INIT
;
1130 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1131 !(cap
& FBINFO_HWACCEL_DISABLED
))
1132 p
->scrollmode
= SCROLL_MOVE
;
1133 else /* default to something safe */
1134 p
->scrollmode
= SCROLL_REDRAW
;
1137 * ++guenther: console.c:vc_allocate() relies on initializing
1138 * vc_{cols,rows}, but we must not set those if we are only
1139 * resizing the console.
1142 vc
->vc_cols
= new_cols
;
1143 vc
->vc_rows
= new_rows
;
1145 vc_resize(vc
, new_cols
, new_rows
);
1148 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1150 if (vc
== svc
&& softback_buf
)
1151 fbcon_update_softback(vc
);
1153 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1154 ops
->rotate
= FB_ROTATE_UR
;
1155 set_blitting_type(vc
, info
);
1158 ops
->p
= &fb_display
[fg_console
];
1161 static void fbcon_free_font(struct display
*p
, bool freefont
)
1163 if (freefont
&& p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1164 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1169 static void fbcon_deinit(struct vc_data
*vc
)
1171 struct display
*p
= &fb_display
[vc
->vc_num
];
1172 struct fb_info
*info
;
1173 struct fbcon_ops
*ops
;
1175 bool free_font
= true;
1177 idx
= con2fb_map
[vc
->vc_num
];
1182 info
= registered_fb
[idx
];
1187 if (info
->flags
& FBINFO_MISC_FIRMWARE
)
1189 ops
= info
->fbcon_par
;
1194 if (CON_IS_VISIBLE(vc
))
1195 fbcon_del_cursor_timer(info
);
1197 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1200 fbcon_free_font(p
, free_font
);
1202 vc
->vc_font
.data
= NULL
;
1204 if (!con_is_bound(&fb_con
))
1210 /* ====================================================================== */
1212 /* fbcon_XXX routines - interface used by the world
1214 * This system is now divided into two levels because of complications
1215 * caused by hardware scrolling. Top level functions:
1217 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1219 * handles y values in range [0, scr_height-1] that correspond to real
1220 * screen positions. y_wrap shift means that first line of bitmap may be
1221 * anywhere on this display. These functions convert lineoffsets to
1222 * bitmap offsets and deal with the wrap-around case by splitting blits.
1224 * fbcon_bmove_physical_8() -- These functions fast implementations
1225 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1226 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1230 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1231 * Implies should only really hardware scroll in rows. Only reason for
1232 * restriction is simplicity & efficiency at the moment.
1235 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1238 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1239 struct fbcon_ops
*ops
= info
->fbcon_par
;
1241 struct display
*p
= &fb_display
[vc
->vc_num
];
1244 if (fbcon_is_inactive(vc
, info
))
1247 if (!height
|| !width
)
1250 if (sy
< vc
->vc_top
&& vc
->vc_top
== logo_lines
) {
1253 * If the font dimensions are not an integral of the display
1254 * dimensions then the ops->clear below won't end up clearing
1255 * the margins. Call clear_margins here in case the logo
1256 * bitmap stretched into the margin area.
1258 fbcon_clear_margins(vc
, 0);
1261 /* Split blits that cross physical y_wrap boundary */
1263 y_break
= p
->vrows
- p
->yscroll
;
1264 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1265 u_int b
= y_break
- sy
;
1266 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1267 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1270 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1273 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1274 int count
, int ypos
, int xpos
)
1276 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1277 struct display
*p
= &fb_display
[vc
->vc_num
];
1278 struct fbcon_ops
*ops
= info
->fbcon_par
;
1280 if (!fbcon_is_inactive(vc
, info
))
1281 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1282 get_color(vc
, info
, scr_readw(s
), 1),
1283 get_color(vc
, info
, scr_readw(s
), 0));
1286 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1290 scr_writew(c
, &chr
);
1291 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1294 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1296 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1297 struct fbcon_ops
*ops
= info
->fbcon_par
;
1299 if (!fbcon_is_inactive(vc
, info
))
1300 ops
->clear_margins(vc
, info
, bottom_only
);
1303 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1305 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1306 struct fbcon_ops
*ops
= info
->fbcon_par
;
1308 int c
= scr_readw((u16
*) vc
->vc_pos
);
1310 ops
->cur_blink_jiffies
= msecs_to_jiffies(vc
->vc_cur_blink_ms
);
1312 if (fbcon_is_inactive(vc
, info
) || vc
->vc_deccm
!= 1)
1315 if (vc
->vc_cursor_type
& 0x10)
1316 fbcon_del_cursor_timer(info
);
1318 fbcon_add_cursor_timer(info
);
1320 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1321 if (mode
& CM_SOFTBACK
) {
1322 mode
&= ~CM_SOFTBACK
;
1326 fbcon_set_origin(vc
);
1330 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1331 get_color(vc
, info
, c
, 0));
1334 static int scrollback_phys_max
= 0;
1335 static int scrollback_max
= 0;
1336 static int scrollback_current
= 0;
1338 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1341 struct display
*p
, *t
;
1342 struct vc_data
**default_mode
, *vc
;
1343 struct vc_data
*svc
;
1344 struct fbcon_ops
*ops
= info
->fbcon_par
;
1345 int rows
, cols
, charcnt
= 256;
1347 p
= &fb_display
[unit
];
1349 if (var_to_display(p
, var
, info
))
1352 vc
= vc_cons
[unit
].d
;
1357 default_mode
= vc
->vc_display_fg
;
1358 svc
= *default_mode
;
1359 t
= &fb_display
[svc
->vc_num
];
1361 if (!vc
->vc_font
.data
) {
1362 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1363 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1364 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1365 p
->userfont
= t
->userfont
;
1367 REFCOUNT(p
->fontdata
)++;
1370 charcnt
= FNTCHARCNT(p
->fontdata
);
1372 var
->activate
= FB_ACTIVATE_NOW
;
1373 info
->var
.activate
= var
->activate
;
1374 var
->yoffset
= info
->var
.yoffset
;
1375 var
->xoffset
= info
->var
.xoffset
;
1376 fb_set_var(info
, var
);
1377 ops
->var
= info
->var
;
1378 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1379 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1380 if (charcnt
== 256) {
1381 vc
->vc_hi_font_mask
= 0;
1383 vc
->vc_hi_font_mask
= 0x100;
1384 if (vc
->vc_can_do_color
)
1385 vc
->vc_complement_mask
<<= 1;
1388 if (!*svc
->vc_uni_pagedir_loc
)
1389 con_set_default_unimap(svc
);
1390 if (!*vc
->vc_uni_pagedir_loc
)
1391 con_copy_unimap(vc
, svc
);
1393 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1394 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1395 cols
/= vc
->vc_font
.width
;
1396 rows
/= vc
->vc_font
.height
;
1397 vc_resize(vc
, cols
, rows
);
1399 if (CON_IS_VISIBLE(vc
)) {
1402 fbcon_update_softback(vc
);
1406 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1408 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1409 struct fbcon_ops
*ops
= info
->fbcon_par
;
1410 struct display
*p
= &fb_display
[vc
->vc_num
];
1412 p
->yscroll
+= count
;
1413 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1414 p
->yscroll
-= p
->vrows
;
1415 ops
->var
.xoffset
= 0;
1416 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1417 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1418 ops
->update_start(info
);
1419 scrollback_max
+= count
;
1420 if (scrollback_max
> scrollback_phys_max
)
1421 scrollback_max
= scrollback_phys_max
;
1422 scrollback_current
= 0;
1425 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1427 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1428 struct fbcon_ops
*ops
= info
->fbcon_par
;
1429 struct display
*p
= &fb_display
[vc
->vc_num
];
1431 p
->yscroll
-= count
;
1432 if (p
->yscroll
< 0) /* Deal with wrap */
1433 p
->yscroll
+= p
->vrows
;
1434 ops
->var
.xoffset
= 0;
1435 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1436 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1437 ops
->update_start(info
);
1438 scrollback_max
-= count
;
1439 if (scrollback_max
< 0)
1441 scrollback_current
= 0;
1444 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1446 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1447 struct display
*p
= &fb_display
[vc
->vc_num
];
1448 struct fbcon_ops
*ops
= info
->fbcon_par
;
1450 p
->yscroll
+= count
;
1451 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1452 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1453 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1454 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1457 ops
->var
.xoffset
= 0;
1458 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1459 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1460 ops
->update_start(info
);
1461 fbcon_clear_margins(vc
, 1);
1462 scrollback_max
+= count
;
1463 if (scrollback_max
> scrollback_phys_max
)
1464 scrollback_max
= scrollback_phys_max
;
1465 scrollback_current
= 0;
1468 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1470 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1471 struct fbcon_ops
*ops
= info
->fbcon_par
;
1472 struct display
*p
= &fb_display
[vc
->vc_num
];
1474 p
->yscroll
+= count
;
1476 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1477 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1478 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1481 ops
->var
.xoffset
= 0;
1482 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1483 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1484 ops
->update_start(info
);
1485 fbcon_clear_margins(vc
, 1);
1486 scrollback_max
+= count
;
1487 if (scrollback_max
> scrollback_phys_max
)
1488 scrollback_max
= scrollback_phys_max
;
1489 scrollback_current
= 0;
1492 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1494 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1495 struct display
*p
= &fb_display
[vc
->vc_num
];
1496 struct fbcon_ops
*ops
= info
->fbcon_par
;
1498 p
->yscroll
-= count
;
1499 if (p
->yscroll
< 0) {
1500 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1501 0, vc
->vc_rows
, vc
->vc_cols
);
1502 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1505 ops
->var
.xoffset
= 0;
1506 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1507 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1508 ops
->update_start(info
);
1509 fbcon_clear_margins(vc
, 1);
1510 scrollback_max
-= count
;
1511 if (scrollback_max
< 0)
1513 scrollback_current
= 0;
1516 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1518 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1519 struct fbcon_ops
*ops
= info
->fbcon_par
;
1520 struct display
*p
= &fb_display
[vc
->vc_num
];
1522 p
->yscroll
-= count
;
1524 if (p
->yscroll
< 0) {
1525 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1526 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1529 ops
->var
.xoffset
= 0;
1530 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1531 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1532 ops
->update_start(info
);
1533 fbcon_clear_margins(vc
, 1);
1534 scrollback_max
-= count
;
1535 if (scrollback_max
< 0)
1537 scrollback_current
= 0;
1540 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1543 int count
= vc
->vc_rows
;
1544 unsigned short *d
, *s
;
1548 d
= (u16
*) softback_curr
;
1549 if (d
== (u16
*) softback_in
)
1550 d
= (u16
*) vc
->vc_origin
;
1551 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1552 softback_lines
-= delta
;
1554 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1555 n
+= softback_end
- softback_buf
;
1556 if (n
< softback_top
) {
1558 (softback_top
- n
) / vc
->vc_size_row
;
1561 } else if (softback_curr
>= softback_top
1562 && n
< softback_top
) {
1564 (softback_top
- n
) / vc
->vc_size_row
;
1568 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1569 n
+= softback_buf
- softback_end
;
1570 if (n
> softback_in
) {
1574 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1579 if (n
== softback_curr
)
1582 s
= (u16
*) softback_curr
;
1583 if (s
== (u16
*) softback_in
)
1584 s
= (u16
*) vc
->vc_origin
;
1586 unsigned short *start
;
1590 unsigned short attr
= 1;
1593 le
= advance_row(s
, 1);
1596 if (attr
!= (c
& 0xff00)) {
1599 fbcon_putcs(vc
, start
, s
- start
,
1605 if (c
== scr_readw(d
)) {
1607 fbcon_putcs(vc
, start
, s
- start
,
1620 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1622 if (d
== (u16
*) softback_end
)
1623 d
= (u16
*) softback_buf
;
1624 if (d
== (u16
*) softback_in
)
1625 d
= (u16
*) vc
->vc_origin
;
1626 if (s
== (u16
*) softback_end
)
1627 s
= (u16
*) softback_buf
;
1628 if (s
== (u16
*) softback_in
)
1629 s
= (u16
*) vc
->vc_origin
;
1633 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1634 int line
, int count
, int dy
)
1636 unsigned short *s
= (unsigned short *)
1637 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1640 unsigned short *start
= s
;
1641 unsigned short *le
= advance_row(s
, 1);
1644 unsigned short attr
= 1;
1648 if (attr
!= (c
& 0xff00)) {
1651 fbcon_putcs(vc
, start
, s
- start
,
1657 console_conditional_schedule();
1661 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1662 console_conditional_schedule();
1667 static void fbcon_redraw_blit(struct vc_data
*vc
, struct fb_info
*info
,
1668 struct display
*p
, int line
, int count
, int ycount
)
1670 int offset
= ycount
* vc
->vc_cols
;
1671 unsigned short *d
= (unsigned short *)
1672 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1673 unsigned short *s
= d
+ offset
;
1674 struct fbcon_ops
*ops
= info
->fbcon_par
;
1677 unsigned short *start
= s
;
1678 unsigned short *le
= advance_row(s
, 1);
1685 if (c
== scr_readw(d
)) {
1687 ops
->bmove(vc
, info
, line
+ ycount
, x
,
1688 line
, x
, 1, s
-start
);
1698 console_conditional_schedule();
1703 ops
->bmove(vc
, info
, line
+ ycount
, x
, line
, x
, 1,
1705 console_conditional_schedule();
1710 /* NOTE: We subtract two lines from these pointers */
1711 s
-= vc
->vc_size_row
;
1712 d
-= vc
->vc_size_row
;
1717 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1718 int line
, int count
, int offset
)
1720 unsigned short *d
= (unsigned short *)
1721 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1722 unsigned short *s
= d
+ offset
;
1725 unsigned short *start
= s
;
1726 unsigned short *le
= advance_row(s
, 1);
1729 unsigned short attr
= 1;
1733 if (attr
!= (c
& 0xff00)) {
1736 fbcon_putcs(vc
, start
, s
- start
,
1742 if (c
== scr_readw(d
)) {
1744 fbcon_putcs(vc
, start
, s
- start
,
1754 console_conditional_schedule();
1759 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1760 console_conditional_schedule();
1765 /* NOTE: We subtract two lines from these pointers */
1766 s
-= vc
->vc_size_row
;
1767 d
-= vc
->vc_size_row
;
1772 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1777 if (vc
->vc_num
!= fg_console
)
1779 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1782 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1784 p
= advance_row(p
, 1);
1785 softback_in
+= vc
->vc_size_row
;
1786 if (softback_in
== softback_end
)
1787 softback_in
= softback_buf
;
1788 if (softback_in
== softback_top
) {
1789 softback_top
+= vc
->vc_size_row
;
1790 if (softback_top
== softback_end
)
1791 softback_top
= softback_buf
;
1794 softback_curr
= softback_in
;
1797 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1800 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1801 struct display
*p
= &fb_display
[vc
->vc_num
];
1802 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1804 if (fbcon_is_inactive(vc
, info
))
1807 fbcon_cursor(vc
, CM_ERASE
);
1810 * ++Geert: Only use ywrap/ypan if the console is in text mode
1811 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1812 * whole screen (prevents flicker).
1817 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1818 count
= vc
->vc_rows
;
1820 fbcon_softback_note(vc
, t
, count
);
1821 if (logo_shown
>= 0)
1823 switch (p
->scrollmode
) {
1825 fbcon_redraw_blit(vc
, info
, p
, t
, b
- t
- count
,
1827 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1828 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1831 vc
->vc_video_erase_char
,
1832 vc
->vc_size_row
* count
);
1836 case SCROLL_WRAP_MOVE
:
1837 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1839 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1841 ywrap_up(vc
, count
);
1842 if (vc
->vc_rows
- b
> 0)
1843 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1846 } else if (info
->flags
& FBINFO_READS_FAST
)
1847 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1848 b
- t
- count
, vc
->vc_cols
);
1851 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1854 case SCROLL_PAN_REDRAW
:
1855 if ((p
->yscroll
+ count
<=
1856 2 * (p
->vrows
- vc
->vc_rows
))
1857 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1860 3 * vc
->vc_rows
>> 2)))) {
1862 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1863 ypan_up_redraw(vc
, t
, count
);
1864 if (vc
->vc_rows
- b
> 0)
1865 fbcon_redraw_move(vc
, p
, b
,
1866 vc
->vc_rows
- b
, b
);
1868 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1869 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1872 case SCROLL_PAN_MOVE
:
1873 if ((p
->yscroll
+ count
<=
1874 2 * (p
->vrows
- vc
->vc_rows
))
1875 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1878 3 * vc
->vc_rows
>> 2)))) {
1880 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1883 if (vc
->vc_rows
- b
> 0)
1884 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1887 } else if (info
->flags
& FBINFO_READS_FAST
)
1888 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1889 b
- t
- count
, vc
->vc_cols
);
1892 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1897 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1898 count
* vc
->vc_cols
);
1899 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1900 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1903 vc
->vc_video_erase_char
,
1904 vc
->vc_size_row
* count
);
1910 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1911 count
= vc
->vc_rows
;
1912 if (logo_shown
>= 0)
1914 switch (p
->scrollmode
) {
1916 fbcon_redraw_blit(vc
, info
, p
, b
- 1, b
- t
- count
,
1918 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1919 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1922 vc
->vc_video_erase_char
,
1923 vc
->vc_size_row
* count
);
1927 case SCROLL_WRAP_MOVE
:
1928 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1929 if (vc
->vc_rows
- b
> 0)
1930 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1933 ywrap_down(vc
, count
);
1935 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1937 } else if (info
->flags
& FBINFO_READS_FAST
)
1938 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1939 b
- t
- count
, vc
->vc_cols
);
1942 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1945 case SCROLL_PAN_MOVE
:
1946 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1947 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1950 3 * vc
->vc_rows
>> 2)))) {
1951 if (vc
->vc_rows
- b
> 0)
1952 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1955 ypan_down(vc
, count
);
1957 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1959 } else if (info
->flags
& FBINFO_READS_FAST
)
1960 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1961 b
- t
- count
, vc
->vc_cols
);
1964 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1967 case SCROLL_PAN_REDRAW
:
1968 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1969 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1972 3 * vc
->vc_rows
>> 2)))) {
1973 if (vc
->vc_rows
- b
> 0)
1974 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1976 ypan_down_redraw(vc
, t
, count
);
1978 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1980 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1981 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1986 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1987 -count
* vc
->vc_cols
);
1988 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1989 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1992 vc
->vc_video_erase_char
,
1993 vc
->vc_size_row
* count
);
2001 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
2002 int height
, int width
)
2004 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2005 struct display
*p
= &fb_display
[vc
->vc_num
];
2007 if (fbcon_is_inactive(vc
, info
))
2010 if (!width
|| !height
)
2013 /* Split blits that cross physical y_wrap case.
2014 * Pathological case involves 4 blits, better to use recursive
2015 * code rather than unrolled case
2017 * Recursive invocations don't need to erase the cursor over and
2018 * over again, so we use fbcon_bmove_rec()
2020 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
2021 p
->vrows
- p
->yscroll
);
2024 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
2025 int dy
, int dx
, int height
, int width
, u_int y_break
)
2027 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2028 struct fbcon_ops
*ops
= info
->fbcon_par
;
2031 if (sy
< y_break
&& sy
+ height
> y_break
) {
2033 if (dy
< sy
) { /* Avoid trashing self */
2034 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2036 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2037 height
- b
, width
, y_break
);
2039 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2040 height
- b
, width
, y_break
);
2041 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2047 if (dy
< y_break
&& dy
+ height
> y_break
) {
2049 if (dy
< sy
) { /* Avoid trashing self */
2050 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2052 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2053 height
- b
, width
, y_break
);
2055 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
2056 height
- b
, width
, y_break
);
2057 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2062 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2066 static void updatescrollmode(struct display
*p
,
2067 struct fb_info
*info
,
2070 struct fbcon_ops
*ops
= info
->fbcon_par
;
2071 int fh
= vc
->vc_font
.height
;
2072 int cap
= info
->flags
;
2074 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2075 info
->fix
.xpanstep
);
2076 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2077 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2078 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2079 info
->var
.xres_virtual
);
2080 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2081 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2082 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2083 divides(ywrap
, vc
->vc_font
.height
) &&
2084 divides(vc
->vc_font
.height
, vyres
) &&
2085 divides(vc
->vc_font
.height
, yres
);
2086 int reading_fast
= cap
& FBINFO_READS_FAST
;
2087 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2088 !(cap
& FBINFO_HWACCEL_DISABLED
);
2089 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2090 !(cap
& FBINFO_HWACCEL_DISABLED
);
2092 p
->vrows
= vyres
/fh
;
2093 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2094 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2095 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2098 if (good_wrap
|| good_pan
) {
2099 if (reading_fast
|| fast_copyarea
)
2100 p
->scrollmode
= good_wrap
?
2101 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2103 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2106 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2107 p
->scrollmode
= SCROLL_MOVE
;
2109 p
->scrollmode
= SCROLL_REDRAW
;
2113 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2114 unsigned int height
, unsigned int user
)
2116 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2117 struct fbcon_ops
*ops
= info
->fbcon_par
;
2118 struct display
*p
= &fb_display
[vc
->vc_num
];
2119 struct fb_var_screeninfo var
= info
->var
;
2120 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2122 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2123 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2124 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2125 vc
->vc_font
.height
);
2126 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2128 var
.xres
= virt_w
* virt_fw
;
2129 var
.yres
= virt_h
* virt_fh
;
2130 x_diff
= info
->var
.xres
- var
.xres
;
2131 y_diff
= info
->var
.yres
- var
.yres
;
2132 if (x_diff
< 0 || x_diff
> virt_fw
||
2133 y_diff
< 0 || y_diff
> virt_fh
) {
2134 const struct fb_videomode
*mode
;
2136 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2137 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2140 display_to_var(&var
, p
);
2141 fb_videomode_to_var(&var
, mode
);
2143 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2146 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2147 if (CON_IS_VISIBLE(vc
)) {
2148 var
.activate
= FB_ACTIVATE_NOW
|
2150 fb_set_var(info
, &var
);
2152 var_to_display(p
, &info
->var
, info
);
2153 ops
->var
= info
->var
;
2155 updatescrollmode(p
, info
, vc
);
2159 static int fbcon_switch(struct vc_data
*vc
)
2161 struct fb_info
*info
, *old_info
= NULL
;
2162 struct fbcon_ops
*ops
;
2163 struct display
*p
= &fb_display
[vc
->vc_num
];
2164 struct fb_var_screeninfo var
;
2165 int i
, ret
, prev_console
, charcnt
= 256;
2167 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2168 ops
= info
->fbcon_par
;
2172 fbcon_set_origin(vc
);
2173 softback_top
= softback_curr
= softback_in
= softback_buf
;
2175 fbcon_update_softback(vc
);
2178 if (logo_shown
>= 0) {
2179 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2181 if (conp2
->vc_top
== logo_lines
2182 && conp2
->vc_bottom
== conp2
->vc_rows
)
2184 logo_shown
= FBCON_LOGO_CANSHOW
;
2187 prev_console
= ops
->currcon
;
2188 if (prev_console
!= -1)
2189 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2191 * FIXME: If we have multiple fbdev's loaded, we need to
2192 * update all info->currcon. Perhaps, we can place this
2193 * in a centralized structure, but this might break some
2196 * info->currcon = vc->vc_num;
2198 for (i
= 0; i
< FB_MAX
; i
++) {
2199 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2200 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2202 o
->currcon
= vc
->vc_num
;
2205 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2206 display_to_var(&var
, p
);
2207 var
.activate
= FB_ACTIVATE_NOW
;
2210 * make sure we don't unnecessarily trip the memcmp()
2213 info
->var
.activate
= var
.activate
;
2214 var
.vmode
|= info
->var
.vmode
& ~FB_VMODE_MASK
;
2215 fb_set_var(info
, &var
);
2216 ops
->var
= info
->var
;
2218 if (old_info
!= NULL
&& (old_info
!= info
||
2219 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2220 if (info
->fbops
->fb_set_par
) {
2221 ret
= info
->fbops
->fb_set_par(info
);
2224 printk(KERN_ERR
"fbcon_switch: detected "
2225 "unhandled fb_set_par error, "
2226 "error code %d\n", ret
);
2229 if (old_info
!= info
)
2230 fbcon_del_cursor_timer(old_info
);
2233 if (fbcon_is_inactive(vc
, info
) ||
2234 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2235 fbcon_del_cursor_timer(info
);
2237 fbcon_add_cursor_timer(info
);
2239 set_blitting_type(vc
, info
);
2240 ops
->cursor_reset
= 1;
2242 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2243 ops
->rotate
= FB_ROTATE_UR
;
2244 set_blitting_type(vc
, info
);
2247 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2248 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2251 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2254 vc
->vc_complement_mask
<<= 1;
2256 updatescrollmode(p
, info
, vc
);
2258 switch (p
->scrollmode
) {
2259 case SCROLL_WRAP_MOVE
:
2260 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2262 case SCROLL_PAN_MOVE
:
2263 case SCROLL_PAN_REDRAW
:
2264 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2265 if (scrollback_phys_max
< 0)
2266 scrollback_phys_max
= 0;
2269 scrollback_phys_max
= 0;
2274 scrollback_current
= 0;
2276 if (!fbcon_is_inactive(vc
, info
)) {
2277 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2278 ops
->update_start(info
);
2281 fbcon_set_palette(vc
, color_table
);
2282 fbcon_clear_margins(vc
, 0);
2284 if (logo_shown
== FBCON_LOGO_DRAW
) {
2286 logo_shown
= fg_console
;
2287 /* This is protected above by initmem_freed */
2288 fb_show_logo(info
, ops
->rotate
);
2290 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2291 vc
->vc_size_row
* (vc
->vc_bottom
-
2298 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2301 struct fb_event event
;
2304 unsigned short charmask
= vc
->vc_hi_font_mask
?
2306 unsigned short oldc
;
2308 oldc
= vc
->vc_video_erase_char
;
2309 vc
->vc_video_erase_char
&= charmask
;
2310 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2311 vc
->vc_video_erase_char
= oldc
;
2315 if (!lock_fb_info(info
))
2318 event
.data
= &blank
;
2319 fb_notifier_call_chain(FB_EVENT_CONBLANK
, &event
);
2320 unlock_fb_info(info
);
2323 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2325 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2326 struct fbcon_ops
*ops
= info
->fbcon_par
;
2329 struct fb_var_screeninfo var
= info
->var
;
2334 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2335 fb_set_var(info
, &var
);
2337 ops
->var
= info
->var
;
2341 if (!fbcon_is_inactive(vc
, info
)) {
2342 if (ops
->blank_state
!= blank
) {
2343 ops
->blank_state
= blank
;
2344 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2345 ops
->cursor_flash
= (!blank
);
2347 if (!(info
->flags
& FBINFO_MISC_USEREVENT
))
2348 if (fb_blank(info
, blank
))
2349 fbcon_generic_blank(vc
, info
, blank
);
2356 if (mode_switch
|| fbcon_is_inactive(vc
, info
) ||
2357 ops
->blank_state
!= FB_BLANK_UNBLANK
)
2358 fbcon_del_cursor_timer(info
);
2360 fbcon_add_cursor_timer(info
);
2365 static int fbcon_debug_enter(struct vc_data
*vc
)
2367 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2368 struct fbcon_ops
*ops
= info
->fbcon_par
;
2370 ops
->save_graphics
= ops
->graphics
;
2372 if (info
->fbops
->fb_debug_enter
)
2373 info
->fbops
->fb_debug_enter(info
);
2374 fbcon_set_palette(vc
, color_table
);
2378 static int fbcon_debug_leave(struct vc_data
*vc
)
2380 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2381 struct fbcon_ops
*ops
= info
->fbcon_par
;
2383 ops
->graphics
= ops
->save_graphics
;
2384 if (info
->fbops
->fb_debug_leave
)
2385 info
->fbops
->fb_debug_leave(info
);
2389 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2391 u8
*fontdata
= vc
->vc_font
.data
;
2392 u8
*data
= font
->data
;
2395 font
->width
= vc
->vc_font
.width
;
2396 font
->height
= vc
->vc_font
.height
;
2397 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2401 if (font
->width
<= 8) {
2402 j
= vc
->vc_font
.height
;
2403 for (i
= 0; i
< font
->charcount
; i
++) {
2404 memcpy(data
, fontdata
, j
);
2405 memset(data
+ j
, 0, 32 - j
);
2409 } else if (font
->width
<= 16) {
2410 j
= vc
->vc_font
.height
* 2;
2411 for (i
= 0; i
< font
->charcount
; i
++) {
2412 memcpy(data
, fontdata
, j
);
2413 memset(data
+ j
, 0, 64 - j
);
2417 } else if (font
->width
<= 24) {
2418 for (i
= 0; i
< font
->charcount
; i
++) {
2419 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2420 *data
++ = fontdata
[0];
2421 *data
++ = fontdata
[1];
2422 *data
++ = fontdata
[2];
2423 fontdata
+= sizeof(u32
);
2425 memset(data
, 0, 3 * (32 - j
));
2426 data
+= 3 * (32 - j
);
2429 j
= vc
->vc_font
.height
* 4;
2430 for (i
= 0; i
< font
->charcount
; i
++) {
2431 memcpy(data
, fontdata
, j
);
2432 memset(data
+ j
, 0, 128 - j
);
2440 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2441 const u8
* data
, int userfont
)
2443 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2444 struct fbcon_ops
*ops
= info
->fbcon_par
;
2445 struct display
*p
= &fb_display
[vc
->vc_num
];
2448 char *old_data
= NULL
;
2450 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2451 fbcon_set_origin(vc
);
2453 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2455 old_data
= vc
->vc_font
.data
;
2457 cnt
= FNTCHARCNT(data
);
2460 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2461 if ((p
->userfont
= userfont
))
2463 vc
->vc_font
.width
= w
;
2464 vc
->vc_font
.height
= h
;
2465 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2466 vc
->vc_hi_font_mask
= 0;
2467 if (vc
->vc_can_do_color
) {
2468 vc
->vc_complement_mask
>>= 1;
2469 vc
->vc_s_complement_mask
>>= 1;
2472 /* ++Edmund: reorder the attribute bits */
2473 if (vc
->vc_can_do_color
) {
2474 unsigned short *cp
=
2475 (unsigned short *) vc
->vc_origin
;
2476 int count
= vc
->vc_screenbuf_size
/ 2;
2478 for (; count
> 0; count
--, cp
++) {
2480 scr_writew(((c
& 0xfe00) >> 1) |
2483 c
= vc
->vc_video_erase_char
;
2484 vc
->vc_video_erase_char
=
2485 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2488 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2489 vc
->vc_hi_font_mask
= 0x100;
2490 if (vc
->vc_can_do_color
) {
2491 vc
->vc_complement_mask
<<= 1;
2492 vc
->vc_s_complement_mask
<<= 1;
2495 /* ++Edmund: reorder the attribute bits */
2497 unsigned short *cp
=
2498 (unsigned short *) vc
->vc_origin
;
2499 int count
= vc
->vc_screenbuf_size
/ 2;
2501 for (; count
> 0; count
--, cp
++) {
2502 unsigned short newc
;
2504 if (vc
->vc_can_do_color
)
2506 ((c
& 0xff00) << 1) | (c
&
2510 scr_writew(newc
, cp
);
2512 c
= vc
->vc_video_erase_char
;
2513 if (vc
->vc_can_do_color
) {
2514 vc
->vc_video_erase_char
=
2515 ((c
& 0xff00) << 1) | (c
& 0xff);
2518 vc
->vc_video_erase_char
= c
& ~0x100;
2526 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2527 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2530 vc_resize(vc
, cols
, rows
);
2531 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2532 fbcon_update_softback(vc
);
2533 } else if (CON_IS_VISIBLE(vc
)
2534 && vc
->vc_mode
== KD_TEXT
) {
2535 fbcon_clear_margins(vc
, 0);
2539 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2540 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2544 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2546 struct display
*od
= &fb_display
[con
];
2547 struct console_font
*f
= &vc
->vc_font
;
2549 if (od
->fontdata
== f
->data
)
2550 return 0; /* already the same font... */
2551 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2555 * User asked to set font; we are guaranteed that
2556 * a) width and height are in range 1..32
2557 * b) charcount does not exceed 512
2558 * but lets not assume that, since someone might someday want to use larger
2559 * fonts. And charcount of 512 is small for unicode support.
2561 * However, user space gives the font in 32 rows , regardless of
2562 * actual font height. So a new API is needed if support for larger fonts
2563 * is ever implemented.
2566 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2568 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2569 unsigned charcount
= font
->charcount
;
2570 int w
= font
->width
;
2571 int h
= font
->height
;
2574 u8
*new_data
, *data
= font
->data
;
2575 int pitch
= (font
->width
+7) >> 3;
2577 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2578 * If not this check should be changed to charcount < 256 */
2579 if (charcount
!= 256 && charcount
!= 512)
2582 /* Make sure drawing engine can handle the font */
2583 if (!(info
->pixmap
.blit_x
& (1 << (font
->width
- 1))) ||
2584 !(info
->pixmap
.blit_y
& (1 << (font
->height
- 1))))
2587 /* Make sure driver can handle the font length */
2588 if (fbcon_invalid_charcount(info
, charcount
))
2591 size
= h
* pitch
* charcount
;
2593 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2598 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2599 FNTSIZE(new_data
) = size
;
2600 FNTCHARCNT(new_data
) = charcount
;
2601 REFCOUNT(new_data
) = 0; /* usage counter */
2602 for (i
=0; i
< charcount
; i
++) {
2603 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2606 /* Since linux has a nice crc32 function use it for counting font
2608 csum
= crc32(0, new_data
, size
);
2610 FNTSUM(new_data
) = csum
;
2611 /* Check if the same font is on some other console already */
2612 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2613 struct vc_data
*tmp
= vc_cons
[i
].d
;
2615 if (fb_display
[i
].userfont
&&
2616 fb_display
[i
].fontdata
&&
2617 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2618 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2619 tmp
->vc_font
.width
== w
&&
2620 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2621 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2622 new_data
= (u8
*)fb_display
[i
].fontdata
;
2626 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2629 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2631 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2632 const struct font_desc
*f
;
2635 f
= get_default_font(info
->var
.xres
, info
->var
.yres
,
2636 info
->pixmap
.blit_x
, info
->pixmap
.blit_y
);
2637 else if (!(f
= find_font(name
)))
2640 font
->width
= f
->width
;
2641 font
->height
= f
->height
;
2642 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2645 static u16 palette_red
[16];
2646 static u16 palette_green
[16];
2647 static u16 palette_blue
[16];
2649 static struct fb_cmap palette_cmap
= {
2650 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2653 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2655 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2659 if (fbcon_is_inactive(vc
, info
))
2662 if (!CON_IS_VISIBLE(vc
))
2665 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2667 for (i
= j
= 0; i
< 16; i
++) {
2669 val
= vc
->vc_palette
[j
++];
2670 palette_red
[k
] = (val
<< 8) | val
;
2671 val
= vc
->vc_palette
[j
++];
2672 palette_green
[k
] = (val
<< 8) | val
;
2673 val
= vc
->vc_palette
[j
++];
2674 palette_blue
[k
] = (val
<< 8) | val
;
2676 palette_cmap
.len
= 16;
2677 palette_cmap
.start
= 0;
2679 * If framebuffer is capable of less than 16 colors,
2680 * use default palette of fbcon.
2683 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2685 return fb_set_cmap(&palette_cmap
, info
);
2688 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2693 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2694 return (u16
*) (vc
->vc_origin
+ offset
);
2695 line
= offset
/ vc
->vc_size_row
;
2696 if (line
>= softback_lines
)
2697 return (u16
*) (vc
->vc_origin
+ offset
-
2698 softback_lines
* vc
->vc_size_row
);
2699 p
= softback_curr
+ offset
;
2700 if (p
>= softback_end
)
2701 p
+= softback_buf
- softback_end
;
2705 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2711 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2712 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2714 x
= offset
% vc
->vc_cols
;
2715 y
= offset
/ vc
->vc_cols
;
2716 if (vc
->vc_num
== fg_console
)
2717 y
+= softback_lines
;
2718 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2719 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2720 unsigned long offset
= pos
- softback_curr
;
2722 if (pos
< softback_curr
)
2723 offset
+= softback_end
- softback_buf
;
2725 x
= offset
% vc
->vc_cols
;
2726 y
= offset
/ vc
->vc_cols
;
2727 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2728 if (ret
== softback_end
)
2730 if (ret
== softback_in
)
2731 ret
= vc
->vc_origin
;
2733 /* Should not happen */
2735 ret
= vc
->vc_origin
;
2744 /* As we might be inside of softback, we may work with non-contiguous buffer,
2745 that's why we have to use a separate routine. */
2746 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2749 u16 a
= scr_readw(p
);
2750 if (!vc
->vc_can_do_color
)
2752 else if (vc
->vc_hi_font_mask
== 0x100)
2753 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2754 (((a
) & 0x0e00) << 4);
2756 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2757 (((a
) & 0x0700) << 4);
2759 if (p
== (u16
*) softback_end
)
2760 p
= (u16
*) softback_buf
;
2761 if (p
== (u16
*) softback_in
)
2762 p
= (u16
*) vc
->vc_origin
;
2766 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2768 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2769 struct fbcon_ops
*ops
= info
->fbcon_par
;
2770 struct display
*disp
= &fb_display
[fg_console
];
2771 int offset
, limit
, scrollback_old
;
2774 if (vc
->vc_num
!= fg_console
)
2776 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2778 if (logo_shown
>= 0) {
2779 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2781 if (conp2
->vc_top
== logo_lines
2782 && conp2
->vc_bottom
== conp2
->vc_rows
)
2784 if (logo_shown
== vc
->vc_num
) {
2790 logo_lines
* vc
->vc_size_row
;
2791 for (i
= 0; i
< logo_lines
; i
++) {
2792 if (p
== softback_top
)
2794 if (p
== softback_buf
)
2796 p
-= vc
->vc_size_row
;
2797 q
-= vc
->vc_size_row
;
2798 scr_memcpyw((u16
*) q
, (u16
*) p
,
2801 softback_in
= softback_curr
= p
;
2802 update_region(vc
, vc
->vc_origin
,
2803 logo_lines
* vc
->vc_cols
);
2805 logo_shown
= FBCON_LOGO_CANSHOW
;
2807 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2808 fbcon_redraw_softback(vc
, disp
, lines
);
2809 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2813 if (!scrollback_phys_max
)
2816 scrollback_old
= scrollback_current
;
2817 scrollback_current
-= lines
;
2818 if (scrollback_current
< 0)
2819 scrollback_current
= 0;
2820 else if (scrollback_current
> scrollback_max
)
2821 scrollback_current
= scrollback_max
;
2822 if (scrollback_current
== scrollback_old
)
2825 if (fbcon_is_inactive(vc
, info
))
2828 fbcon_cursor(vc
, CM_ERASE
);
2830 offset
= disp
->yscroll
- scrollback_current
;
2831 limit
= disp
->vrows
;
2832 switch (disp
->scrollmode
) {
2833 case SCROLL_WRAP_MOVE
:
2834 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2836 case SCROLL_PAN_MOVE
:
2837 case SCROLL_PAN_REDRAW
:
2838 limit
-= vc
->vc_rows
;
2839 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2844 else if (offset
>= limit
)
2847 ops
->var
.xoffset
= 0;
2848 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2849 ops
->update_start(info
);
2851 if (!scrollback_current
)
2852 fbcon_cursor(vc
, CM_DRAW
);
2856 static int fbcon_set_origin(struct vc_data
*vc
)
2859 fbcon_scrolldelta(vc
, softback_lines
);
2863 static void fbcon_suspended(struct fb_info
*info
)
2865 struct vc_data
*vc
= NULL
;
2866 struct fbcon_ops
*ops
= info
->fbcon_par
;
2868 if (!ops
|| ops
->currcon
< 0)
2870 vc
= vc_cons
[ops
->currcon
].d
;
2872 /* Clear cursor, restore saved data */
2873 fbcon_cursor(vc
, CM_ERASE
);
2876 static void fbcon_resumed(struct fb_info
*info
)
2879 struct fbcon_ops
*ops
= info
->fbcon_par
;
2881 if (!ops
|| ops
->currcon
< 0)
2883 vc
= vc_cons
[ops
->currcon
].d
;
2888 static void fbcon_modechanged(struct fb_info
*info
)
2890 struct fbcon_ops
*ops
= info
->fbcon_par
;
2895 if (!ops
|| ops
->currcon
< 0)
2897 vc
= vc_cons
[ops
->currcon
].d
;
2898 if (vc
->vc_mode
!= KD_TEXT
||
2899 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2902 p
= &fb_display
[vc
->vc_num
];
2903 set_blitting_type(vc
, info
);
2905 if (CON_IS_VISIBLE(vc
)) {
2906 var_to_display(p
, &info
->var
, info
);
2907 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2908 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2909 cols
/= vc
->vc_font
.width
;
2910 rows
/= vc
->vc_font
.height
;
2911 vc_resize(vc
, cols
, rows
);
2912 updatescrollmode(p
, info
, vc
);
2914 scrollback_current
= 0;
2916 if (!fbcon_is_inactive(vc
, info
)) {
2917 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2918 ops
->update_start(info
);
2921 fbcon_set_palette(vc
, color_table
);
2924 fbcon_update_softback(vc
);
2928 static void fbcon_set_all_vcs(struct fb_info
*info
)
2930 struct fbcon_ops
*ops
= info
->fbcon_par
;
2933 int i
, rows
, cols
, fg
= -1;
2935 if (!ops
|| ops
->currcon
< 0)
2938 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2940 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2941 registered_fb
[con2fb_map
[i
]] != info
)
2944 if (CON_IS_VISIBLE(vc
)) {
2949 p
= &fb_display
[vc
->vc_num
];
2950 set_blitting_type(vc
, info
);
2951 var_to_display(p
, &info
->var
, info
);
2952 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2953 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2954 cols
/= vc
->vc_font
.width
;
2955 rows
/= vc
->vc_font
.height
;
2956 vc_resize(vc
, cols
, rows
);
2960 fbcon_modechanged(info
);
2963 static int fbcon_mode_deleted(struct fb_info
*info
,
2964 struct fb_videomode
*mode
)
2966 struct fb_info
*fb_info
;
2968 int i
, j
, found
= 0;
2970 /* before deletion, ensure that mode is not in use */
2971 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2975 fb_info
= registered_fb
[j
];
2976 if (fb_info
!= info
)
2981 if (fb_mode_is_equal(p
->mode
, mode
)) {
2989 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2990 static int fbcon_unbind(void)
2994 ret
= do_unbind_con_driver(&fb_con
, first_fb_vc
, last_fb_vc
,
2998 fbcon_has_console_bind
= 0;
3003 static inline int fbcon_unbind(void)
3007 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3009 /* called with console_lock held */
3010 static int fbcon_fb_unbind(int idx
)
3012 int i
, new_idx
= -1, ret
= 0;
3014 if (!fbcon_has_console_bind
)
3017 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3018 if (con2fb_map
[i
] != idx
&&
3019 con2fb_map
[i
] != -1) {
3025 if (new_idx
!= -1) {
3026 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3027 if (con2fb_map
[i
] == idx
)
3028 set_con2fb_map(i
, new_idx
, 0);
3031 struct fb_info
*info
= registered_fb
[idx
];
3033 /* This is sort of like set_con2fb_map, except it maps
3034 * the consoles to no device and then releases the
3035 * oldinfo to free memory and cancel the cursor blink
3036 * timer. I can imagine this just becoming part of
3037 * set_con2fb_map where new_idx is -1
3039 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3040 if (con2fb_map
[i
] == idx
) {
3042 if (!search_fb_in_map(idx
)) {
3043 ret
= con2fb_release_oldinfo(vc_cons
[i
].d
,
3047 con2fb_map
[i
] = idx
;
3053 ret
= fbcon_unbind();
3059 /* called with console_lock held */
3060 static int fbcon_fb_unregistered(struct fb_info
*info
)
3065 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3066 if (con2fb_map
[i
] == idx
)
3070 if (idx
== info_idx
) {
3073 for (i
= 0; i
< FB_MAX
; i
++) {
3074 if (registered_fb
[i
] != NULL
) {
3081 if (info_idx
!= -1) {
3082 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3083 if (con2fb_map
[i
] == -1)
3084 con2fb_map
[i
] = info_idx
;
3088 if (primary_device
== idx
)
3089 primary_device
= -1;
3091 if (!num_registered_fb
)
3092 do_unregister_con_driver(&fb_con
);
3097 /* called with console_lock held */
3098 static void fbcon_remap_all(int idx
)
3101 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3102 set_con2fb_map(i
, idx
, 0);
3104 if (con_is_bound(&fb_con
)) {
3105 printk(KERN_INFO
"fbcon: Remapping primary device, "
3106 "fb%i, to tty %i-%i\n", idx
,
3107 first_fb_vc
+ 1, last_fb_vc
+ 1);
3112 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3113 static void fbcon_select_primary(struct fb_info
*info
)
3115 if (!map_override
&& primary_device
== -1 &&
3116 fb_is_primary_device(info
)) {
3119 printk(KERN_INFO
"fbcon: %s (fb%i) is primary device\n",
3120 info
->fix
.id
, info
->node
);
3121 primary_device
= info
->node
;
3123 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
3124 con2fb_map_boot
[i
] = primary_device
;
3126 if (con_is_bound(&fb_con
)) {
3127 printk(KERN_INFO
"fbcon: Remapping primary device, "
3128 "fb%i, to tty %i-%i\n", info
->node
,
3129 first_fb_vc
+ 1, last_fb_vc
+ 1);
3130 info_idx
= primary_device
;
3136 static inline void fbcon_select_primary(struct fb_info
*info
)
3140 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3142 /* called with console_lock held */
3143 static int fbcon_fb_registered(struct fb_info
*info
)
3145 int ret
= 0, i
, idx
;
3148 fbcon_select_primary(info
);
3150 if (info_idx
== -1) {
3151 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3152 if (con2fb_map_boot
[i
] == idx
) {
3159 ret
= do_fbcon_takeover(1);
3161 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3162 if (con2fb_map_boot
[i
] == idx
)
3163 set_con2fb_map(i
, idx
, 0);
3170 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
3172 struct fbcon_ops
*ops
= info
->fbcon_par
;
3175 if (!ops
|| ops
->currcon
< 0)
3178 vc
= vc_cons
[ops
->currcon
].d
;
3179 if (vc
->vc_mode
!= KD_TEXT
||
3180 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
3183 if (CON_IS_VISIBLE(vc
)) {
3187 do_unblank_screen(0);
3189 ops
->blank_state
= blank
;
3192 static void fbcon_new_modelist(struct fb_info
*info
)
3196 struct fb_var_screeninfo var
;
3197 const struct fb_videomode
*mode
;
3199 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3200 if (registered_fb
[con2fb_map
[i
]] != info
)
3202 if (!fb_display
[i
].mode
)
3205 display_to_var(&var
, &fb_display
[i
]);
3206 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
3208 fb_videomode_to_var(&var
, mode
);
3209 fbcon_set_disp(info
, &var
, vc
->vc_num
);
3213 static void fbcon_get_requirement(struct fb_info
*info
,
3214 struct fb_blit_caps
*caps
)
3222 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
3224 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3225 info
->node
== con2fb_map
[i
]) {
3227 caps
->x
|= 1 << (vc
->vc_font
.width
- 1);
3228 caps
->y
|= 1 << (vc
->vc_font
.height
- 1);
3229 charcnt
= (p
->userfont
) ?
3230 FNTCHARCNT(p
->fontdata
) : 256;
3231 if (caps
->len
< charcnt
)
3232 caps
->len
= charcnt
;
3236 vc
= vc_cons
[fg_console
].d
;
3238 if (vc
&& vc
->vc_mode
== KD_TEXT
&&
3239 info
->node
== con2fb_map
[fg_console
]) {
3240 p
= &fb_display
[fg_console
];
3241 caps
->x
= 1 << (vc
->vc_font
.width
- 1);
3242 caps
->y
= 1 << (vc
->vc_font
.height
- 1);
3243 caps
->len
= (p
->userfont
) ?
3244 FNTCHARCNT(p
->fontdata
) : 256;
3249 static int fbcon_event_notify(struct notifier_block
*self
,
3250 unsigned long action
, void *data
)
3252 struct fb_event
*event
= data
;
3253 struct fb_info
*info
= event
->info
;
3254 struct fb_videomode
*mode
;
3255 struct fb_con2fbmap
*con2fb
;
3256 struct fb_blit_caps
*caps
;
3260 * ignore all events except driver registration and deregistration
3261 * if fbcon is not active
3263 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3264 action
== FB_EVENT_FB_UNREGISTERED
))
3268 case FB_EVENT_SUSPEND
:
3269 fbcon_suspended(info
);
3271 case FB_EVENT_RESUME
:
3272 fbcon_resumed(info
);
3274 case FB_EVENT_MODE_CHANGE
:
3275 fbcon_modechanged(info
);
3277 case FB_EVENT_MODE_CHANGE_ALL
:
3278 fbcon_set_all_vcs(info
);
3280 case FB_EVENT_MODE_DELETE
:
3282 ret
= fbcon_mode_deleted(info
, mode
);
3284 case FB_EVENT_FB_UNBIND
:
3286 ret
= fbcon_fb_unbind(idx
);
3288 case FB_EVENT_FB_REGISTERED
:
3289 ret
= fbcon_fb_registered(info
);
3291 case FB_EVENT_FB_UNREGISTERED
:
3292 ret
= fbcon_fb_unregistered(info
);
3294 case FB_EVENT_SET_CONSOLE_MAP
:
3295 /* called with console lock held */
3296 con2fb
= event
->data
;
3297 ret
= set_con2fb_map(con2fb
->console
- 1,
3298 con2fb
->framebuffer
, 1);
3300 case FB_EVENT_GET_CONSOLE_MAP
:
3301 con2fb
= event
->data
;
3302 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3304 case FB_EVENT_BLANK
:
3305 fbcon_fb_blanked(info
, *(int *)event
->data
);
3307 case FB_EVENT_NEW_MODELIST
:
3308 fbcon_new_modelist(info
);
3310 case FB_EVENT_GET_REQ
:
3312 fbcon_get_requirement(info
, caps
);
3314 case FB_EVENT_REMAP_ALL_CONSOLE
:
3316 fbcon_remap_all(idx
);
3324 * The console `switch' structure for the frame buffer based console
3327 static const struct consw fb_con
= {
3328 .owner
= THIS_MODULE
,
3329 .con_startup
= fbcon_startup
,
3330 .con_init
= fbcon_init
,
3331 .con_deinit
= fbcon_deinit
,
3332 .con_clear
= fbcon_clear
,
3333 .con_putc
= fbcon_putc
,
3334 .con_putcs
= fbcon_putcs
,
3335 .con_cursor
= fbcon_cursor
,
3336 .con_scroll
= fbcon_scroll
,
3337 .con_bmove
= fbcon_bmove
,
3338 .con_switch
= fbcon_switch
,
3339 .con_blank
= fbcon_blank
,
3340 .con_font_set
= fbcon_set_font
,
3341 .con_font_get
= fbcon_get_font
,
3342 .con_font_default
= fbcon_set_def_font
,
3343 .con_font_copy
= fbcon_copy_font
,
3344 .con_set_palette
= fbcon_set_palette
,
3345 .con_scrolldelta
= fbcon_scrolldelta
,
3346 .con_set_origin
= fbcon_set_origin
,
3347 .con_invert_region
= fbcon_invert_region
,
3348 .con_screen_pos
= fbcon_screen_pos
,
3349 .con_getxy
= fbcon_getxy
,
3350 .con_resize
= fbcon_resize
,
3351 .con_debug_enter
= fbcon_debug_enter
,
3352 .con_debug_leave
= fbcon_debug_leave
,
3355 static struct notifier_block fbcon_event_notifier
= {
3356 .notifier_call
= fbcon_event_notify
,
3359 static ssize_t
store_rotate(struct device
*device
,
3360 struct device_attribute
*attr
, const char *buf
,
3363 struct fb_info
*info
;
3367 if (fbcon_has_exited
)
3371 idx
= con2fb_map
[fg_console
];
3373 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3376 info
= registered_fb
[idx
];
3377 rotate
= simple_strtoul(buf
, last
, 0);
3378 fbcon_rotate(info
, rotate
);
3384 static ssize_t
store_rotate_all(struct device
*device
,
3385 struct device_attribute
*attr
,const char *buf
,
3388 struct fb_info
*info
;
3392 if (fbcon_has_exited
)
3396 idx
= con2fb_map
[fg_console
];
3398 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3401 info
= registered_fb
[idx
];
3402 rotate
= simple_strtoul(buf
, last
, 0);
3403 fbcon_rotate_all(info
, rotate
);
3409 static ssize_t
show_rotate(struct device
*device
,
3410 struct device_attribute
*attr
,char *buf
)
3412 struct fb_info
*info
;
3413 int rotate
= 0, idx
;
3415 if (fbcon_has_exited
)
3419 idx
= con2fb_map
[fg_console
];
3421 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3424 info
= registered_fb
[idx
];
3425 rotate
= fbcon_get_rotate(info
);
3428 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3431 static ssize_t
show_cursor_blink(struct device
*device
,
3432 struct device_attribute
*attr
, char *buf
)
3434 struct fb_info
*info
;
3435 struct fbcon_ops
*ops
;
3436 int idx
, blink
= -1;
3438 if (fbcon_has_exited
)
3442 idx
= con2fb_map
[fg_console
];
3444 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3447 info
= registered_fb
[idx
];
3448 ops
= info
->fbcon_par
;
3453 blink
= (ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) ? 1 : 0;
3456 return snprintf(buf
, PAGE_SIZE
, "%d\n", blink
);
3459 static ssize_t
store_cursor_blink(struct device
*device
,
3460 struct device_attribute
*attr
,
3461 const char *buf
, size_t count
)
3463 struct fb_info
*info
;
3467 if (fbcon_has_exited
)
3471 idx
= con2fb_map
[fg_console
];
3473 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3476 info
= registered_fb
[idx
];
3478 if (!info
->fbcon_par
)
3481 blink
= simple_strtoul(buf
, last
, 0);
3484 fbcon_cursor_noblink
= 0;
3485 fbcon_add_cursor_timer(info
);
3487 fbcon_cursor_noblink
= 1;
3488 fbcon_del_cursor_timer(info
);
3496 static struct device_attribute device_attrs
[] = {
3497 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3498 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3499 __ATTR(cursor_blink
, S_IRUGO
|S_IWUSR
, show_cursor_blink
,
3500 store_cursor_blink
),
3503 static int fbcon_init_device(void)
3507 fbcon_has_sysfs
= 1;
3509 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++) {
3510 error
= device_create_file(fbcon_device
, &device_attrs
[i
]);
3518 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3520 fbcon_has_sysfs
= 0;
3526 static void fbcon_start(void)
3528 if (num_registered_fb
) {
3533 for (i
= 0; i
< FB_MAX
; i
++) {
3534 if (registered_fb
[i
] != NULL
) {
3540 do_fbcon_takeover(0);
3546 static void fbcon_exit(void)
3548 struct fb_info
*info
;
3551 if (fbcon_has_exited
)
3554 kfree((void *)softback_buf
);
3557 for (i
= 0; i
< FB_MAX
; i
++) {
3561 info
= registered_fb
[i
];
3566 if (info
->queue
.func
)
3567 pending
= cancel_work_sync(&info
->queue
);
3568 DPRINTK("fbcon: %s pending work\n", (pending
? "canceled" :
3571 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3572 if (con2fb_map
[j
] == i
) {
3579 if (info
->fbops
->fb_release
)
3580 info
->fbops
->fb_release(info
, 0);
3581 module_put(info
->fbops
->owner
);
3583 if (info
->fbcon_par
) {
3584 struct fbcon_ops
*ops
= info
->fbcon_par
;
3586 fbcon_del_cursor_timer(info
);
3587 kfree(ops
->cursor_src
);
3588 kfree(ops
->cursor_state
.mask
);
3589 kfree(info
->fbcon_par
);
3590 info
->fbcon_par
= NULL
;
3593 if (info
->queue
.func
== fb_flashcursor
)
3594 info
->queue
.func
= NULL
;
3598 fbcon_has_exited
= 1;
3601 static int __init
fb_console_init(void)
3606 fb_register_client(&fbcon_event_notifier
);
3607 fbcon_device
= device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
,
3610 if (IS_ERR(fbcon_device
)) {
3611 printk(KERN_WARNING
"Unable to create device "
3612 "for fbcon; errno = %ld\n",
3613 PTR_ERR(fbcon_device
));
3614 fbcon_device
= NULL
;
3616 fbcon_init_device();
3618 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3626 fs_initcall(fb_console_init
);
3630 static void __exit
fbcon_deinit_device(void)
3634 if (fbcon_has_sysfs
) {
3635 for (i
= 0; i
< ARRAY_SIZE(device_attrs
); i
++)
3636 device_remove_file(fbcon_device
, &device_attrs
[i
]);
3638 fbcon_has_sysfs
= 0;
3642 static void __exit
fb_console_exit(void)
3645 fb_unregister_client(&fbcon_event_notifier
);
3646 fbcon_deinit_device();
3647 device_destroy(fb_class
, MKDEV(0, 0));
3649 do_unregister_con_driver(&fb_con
);
3653 module_exit(fb_console_exit
);
3657 MODULE_LICENSE("GPL");