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/config.h>
62 #include <linux/module.h>
63 #include <linux/types.h>
64 #include <linux/sched.h>
66 #include <linux/kernel.h>
67 #include <linux/delay.h> /* MSch: for IRQ probe */
68 #include <linux/tty.h>
69 #include <linux/console.h>
70 #include <linux/string.h>
72 #include <linux/slab.h>
74 #include <linux/vt_kern.h>
75 #include <linux/selection.h>
76 #include <linux/font.h>
77 #include <linux/smp.h>
78 #include <linux/init.h>
79 #include <linux/interrupt.h>
80 #include <linux/crc32.h> /* For counting font checksums */
82 #include <asm/system.h>
83 #include <asm/uaccess.h>
85 #include <asm/atariints.h>
88 #include <asm/macints.h>
90 #if defined(__mc68000__) || defined(CONFIG_APUS)
91 #include <asm/machdep.h>
92 #include <asm/setup.h>
98 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
100 # define DPRINTK(fmt, args...)
104 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
105 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
106 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
109 static struct display fb_display
[MAX_NR_CONSOLES
];
111 static signed char con2fb_map
[MAX_NR_CONSOLES
];
112 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
113 static int logo_height
;
114 static int logo_lines
;
115 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
117 static int logo_shown
= FBCON_LOGO_CANSHOW
;
118 /* Software scrollback */
119 static int fbcon_softback_size
= 32768;
120 static unsigned long softback_buf
, softback_curr
;
121 static unsigned long softback_in
;
122 static unsigned long softback_top
, softback_end
;
123 static int softback_lines
;
124 /* console mappings */
125 static int first_fb_vc
;
126 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
127 static int fbcon_is_default
= 1;
128 static int fbcon_has_exited
;
131 static char fontname
[40];
133 /* current fb_info */
134 static int info_idx
= -1;
136 /* console rotation */
139 static const struct consw fb_con
;
141 #define CM_SOFTBACK (8)
143 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
145 static int fbcon_set_origin(struct vc_data
*);
147 #define CURSOR_DRAW_DELAY (1)
149 /* # VBL ints between cursor state changes */
150 #define ATARI_CURSOR_BLINK_RATE (42)
151 #define MAC_CURSOR_BLINK_RATE (32)
152 #define DEFAULT_CURSOR_BLINK_RATE (20)
154 static int vbl_cursor_cnt
;
156 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
159 * Interface used by the world
162 static const char *fbcon_startup(void);
163 static void fbcon_init(struct vc_data
*vc
, int init
);
164 static void fbcon_deinit(struct vc_data
*vc
);
165 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
167 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
168 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
169 int count
, int ypos
, int xpos
);
170 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
171 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
172 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
174 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
175 int height
, int width
);
176 static int fbcon_switch(struct vc_data
*vc
);
177 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
178 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
179 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
184 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
185 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
186 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
187 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
188 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
189 int dy
, int dx
, int height
, int width
, u_int y_break
);
190 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
192 static void fbcon_preset_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
194 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
195 int line
, int count
, int dy
);
196 static void fbcon_modechanged(struct fb_info
*info
);
197 static void fbcon_set_all_vcs(struct fb_info
*info
);
198 static void fbcon_start(void);
199 static void fbcon_exit(void);
200 static struct class_device
*fbcon_class_device
;
204 * On the Macintoy, there may or may not be a working VBL int. We need to probe
206 static int vbl_detected
;
208 static irqreturn_t
fb_vbl_detect(int irq
, void *dummy
, struct pt_regs
*fp
)
215 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
216 static inline void fbcon_set_rotation(struct fb_info
*info
)
218 struct fbcon_ops
*ops
= info
->fbcon_par
;
220 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
221 ops
->p
->con_rotate
< 4)
222 ops
->rotate
= ops
->p
->con_rotate
;
227 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
229 struct fbcon_ops
*ops
= info
->fbcon_par
;
230 struct fb_info
*fb_info
;
232 if (!ops
|| ops
->currcon
== -1)
235 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
237 if (info
== fb_info
) {
238 struct display
*p
= &fb_display
[ops
->currcon
];
241 p
->con_rotate
= rotate
;
245 fbcon_modechanged(info
);
249 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
251 struct fbcon_ops
*ops
= info
->fbcon_par
;
256 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
259 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
261 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
262 registered_fb
[con2fb_map
[i
]] != info
)
265 p
= &fb_display
[vc
->vc_num
];
266 p
->con_rotate
= rotate
;
269 fbcon_set_all_vcs(info
);
272 static inline void fbcon_set_rotation(struct fb_info
*info
)
274 struct fbcon_ops
*ops
= info
->fbcon_par
;
276 ops
->rotate
= FB_ROTATE_UR
;
279 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
284 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
288 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
290 static int fbcon_get_rotate(struct fb_info
*info
)
292 struct fbcon_ops
*ops
= info
->fbcon_par
;
294 return (ops
) ? ops
->rotate
: 0;
297 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
299 struct fbcon_ops
*ops
= info
->fbcon_par
;
301 return (info
->state
!= FBINFO_STATE_RUNNING
||
302 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
305 static inline int get_color(struct vc_data
*vc
, struct fb_info
*info
,
308 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
311 if (console_blanked
) {
312 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
314 c
= vc
->vc_video_erase_char
& charmask
;
318 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
319 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
324 int col
= ~(0xfff << (max(info
->var
.green
.length
,
325 max(info
->var
.red
.length
,
326 info
->var
.blue
.length
)))) & 0xff;
329 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
330 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
335 color
= (is_fg
) ? fg
: bg
;
340 * Scale down 16-colors to 4 colors. Default 4-color palette
341 * is grayscale. However, simply dividing the values by 4
342 * will not work, as colors 1, 2 and 3 will be scaled-down
343 * to zero rendering them invisible. So empirically convert
344 * colors to a sane 4-level grayscale.
348 color
= 0; /* black */
351 color
= 2; /* white */
354 color
= 1; /* gray */
357 color
= 3; /* intense white */
363 * Last 8 entries of default 16-color palette is a more intense
364 * version of the first 8 (i.e., same chrominance, different
375 static void fbcon_update_softback(struct vc_data
*vc
)
377 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
380 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
382 /* Smaller scrollback makes no sense, and 0 would screw
383 the operation totally */
387 static void fb_flashcursor(void *private)
389 struct fb_info
*info
= private;
390 struct fbcon_ops
*ops
= info
->fbcon_par
;
392 struct vc_data
*vc
= NULL
;
396 acquire_console_sem();
397 if (ops
&& ops
->currcon
!= -1)
398 vc
= vc_cons
[ops
->currcon
].d
;
400 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
401 fbcon_is_inactive(vc
, info
) ||
402 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
403 vc_cons
[ops
->currcon
].d
->vc_deccm
!= 1) {
404 release_console_sem();
408 p
= &fb_display
[vc
->vc_num
];
409 c
= scr_readw((u16
*) vc
->vc_pos
);
410 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
412 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
413 get_color(vc
, info
, c
, 0));
414 release_console_sem();
417 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
418 static int cursor_blink_rate
;
419 static irqreturn_t
fb_vbl_handler(int irq
, void *dev_id
, struct pt_regs
*fp
)
421 struct fb_info
*info
= dev_id
;
423 if (vbl_cursor_cnt
&& --vbl_cursor_cnt
== 0) {
424 schedule_work(&info
->queue
);
425 vbl_cursor_cnt
= cursor_blink_rate
;
431 static void cursor_timer_handler(unsigned long dev_addr
)
433 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
434 struct fbcon_ops
*ops
= info
->fbcon_par
;
436 schedule_work(&info
->queue
);
437 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
440 static void fbcon_add_cursor_timer(struct fb_info
*info
)
442 struct fbcon_ops
*ops
= info
->fbcon_par
;
444 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
445 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
)) {
446 if (!info
->queue
.func
)
447 INIT_WORK(&info
->queue
, fb_flashcursor
, info
);
449 init_timer(&ops
->cursor_timer
);
450 ops
->cursor_timer
.function
= cursor_timer_handler
;
451 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
452 ops
->cursor_timer
.data
= (unsigned long ) info
;
453 add_timer(&ops
->cursor_timer
);
454 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
458 static void fbcon_del_cursor_timer(struct fb_info
*info
)
460 struct fbcon_ops
*ops
= info
->fbcon_par
;
462 if (info
->queue
.func
== fb_flashcursor
&&
463 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
464 del_timer_sync(&ops
->cursor_timer
);
465 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
470 static int __init
fb_console_setup(char *this_opt
)
475 if (!this_opt
|| !*this_opt
)
478 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
479 if (!strncmp(options
, "font:", 5))
480 strcpy(fontname
, options
+ 5);
482 if (!strncmp(options
, "scrollback:", 11)) {
485 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
486 if (*options
== 'k' || *options
== 'K') {
487 fbcon_softback_size
*= 1024;
497 if (!strncmp(options
, "map:", 4)) {
500 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
504 (options
[j
++]-'0') % FB_MAX
;
509 if (!strncmp(options
, "vc:", 3)) {
512 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
515 if (*options
++ == '-')
516 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
517 fbcon_is_default
= 0;
520 if (!strncmp(options
, "rotate:", 7)) {
523 rotate
= simple_strtoul(options
, &options
, 0);
531 __setup("fbcon=", fb_console_setup
);
534 static int search_fb_in_map(int idx
)
538 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
539 if (con2fb_map
[i
] == idx
)
545 static int search_for_mapped_con(void)
549 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
550 if (con2fb_map
[i
] != -1)
556 static int fbcon_takeover(int show_logo
)
560 if (!num_registered_fb
)
564 logo_shown
= FBCON_LOGO_DONTSHOW
;
566 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
567 con2fb_map
[i
] = info_idx
;
569 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
573 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
582 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
583 int cols
, int rows
, int new_cols
, int new_rows
)
585 /* Need to make room for the logo */
586 struct fbcon_ops
*ops
= info
->fbcon_par
;
587 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
588 unsigned short *save
= NULL
, *r
, *q
;
591 * remove underline attribute from erase character
592 * if black and white framebuffer.
594 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
596 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
597 logo_lines
= (logo_height
+ vc
->vc_font
.height
- 1) /
599 q
= (unsigned short *) (vc
->vc_origin
+
600 vc
->vc_size_row
* rows
);
601 step
= logo_lines
* cols
;
602 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
603 if (scr_readw(r
) != vc
->vc_video_erase_char
)
605 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
606 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
608 int i
= cols
< new_cols
? cols
: new_cols
;
609 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
611 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
612 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
617 /* We can scroll screen down */
619 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
620 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
624 vc
->vc_y
+= logo_lines
;
625 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
628 scr_memsetw((unsigned short *) vc
->vc_origin
,
630 vc
->vc_size_row
* logo_lines
);
632 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
633 fbcon_clear_margins(vc
, 0);
638 q
= (unsigned short *) (vc
->vc_origin
+
641 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
642 vc
->vc_y
+= logo_lines
;
643 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
647 if (logo_lines
> vc
->vc_bottom
) {
648 logo_shown
= FBCON_LOGO_CANSHOW
;
650 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
651 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
652 logo_shown
= FBCON_LOGO_DRAW
;
653 vc
->vc_top
= logo_lines
;
657 #ifdef CONFIG_FB_TILEBLITTING
658 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
660 struct fbcon_ops
*ops
= info
->fbcon_par
;
662 ops
->p
= &fb_display
[vc
->vc_num
];
664 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
665 fbcon_set_tileops(vc
, info
);
667 fbcon_set_rotation(info
);
668 fbcon_set_bitops(ops
);
672 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
674 struct fbcon_ops
*ops
= info
->fbcon_par
;
676 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
677 ops
->p
= &fb_display
[vc
->vc_num
];
678 fbcon_set_rotation(info
);
679 fbcon_set_bitops(ops
);
681 #endif /* CONFIG_MISC_TILEBLITTING */
684 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
685 int unit
, int oldidx
)
687 struct fbcon_ops
*ops
= NULL
;
690 if (!try_module_get(info
->fbops
->owner
))
693 if (!err
&& info
->fbops
->fb_open
&&
694 info
->fbops
->fb_open(info
, 0))
698 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
704 info
->fbcon_par
= ops
;
705 set_blitting_type(vc
, info
);
709 con2fb_map
[unit
] = oldidx
;
710 module_put(info
->fbops
->owner
);
716 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
717 struct fb_info
*newinfo
, int unit
,
718 int oldidx
, int found
)
720 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
723 if (oldinfo
->fbops
->fb_release
&&
724 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
725 con2fb_map
[unit
] = oldidx
;
726 if (!found
&& newinfo
->fbops
->fb_release
)
727 newinfo
->fbops
->fb_release(newinfo
, 0);
729 module_put(newinfo
->fbops
->owner
);
734 fbcon_del_cursor_timer(oldinfo
);
735 kfree(ops
->cursor_state
.mask
);
736 kfree(ops
->cursor_data
);
737 kfree(ops
->fontbuffer
);
738 kfree(oldinfo
->fbcon_par
);
739 oldinfo
->fbcon_par
= NULL
;
740 module_put(oldinfo
->fbops
->owner
);
742 If oldinfo and newinfo are driving the same hardware,
743 the fb_release() method of oldinfo may attempt to
744 restore the hardware state. This will leave the
745 newinfo in an undefined state. Thus, a call to
746 fb_set_par() may be needed for the newinfo.
748 if (newinfo
->fbops
->fb_set_par
)
749 newinfo
->fbops
->fb_set_par(newinfo
);
755 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
756 int unit
, int show_logo
)
758 struct fbcon_ops
*ops
= info
->fbcon_par
;
760 ops
->currcon
= fg_console
;
762 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
))
763 info
->fbops
->fb_set_par(info
);
765 ops
->flags
|= FBCON_FLAGS_INIT
;
769 fbcon_set_disp(info
, &info
->var
, vc
);
771 fbcon_preset_disp(info
, &info
->var
, unit
);
774 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
775 struct fb_info
*fg_info
=
776 registered_fb
[con2fb_map
[fg_console
]];
778 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
779 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
783 update_screen(vc_cons
[fg_console
].d
);
787 * set_con2fb_map - map console to frame buffer device
788 * @unit: virtual console number to map
789 * @newidx: frame buffer index to map virtual console to
790 * @user: user request
792 * Maps a virtual console @unit to a frame buffer device
795 static int set_con2fb_map(int unit
, int newidx
, int user
)
797 struct vc_data
*vc
= vc_cons
[unit
].d
;
798 int oldidx
= con2fb_map
[unit
];
799 struct fb_info
*info
= registered_fb
[newidx
];
800 struct fb_info
*oldinfo
= NULL
;
803 if (oldidx
== newidx
)
806 if (!info
|| fbcon_has_exited
)
809 if (!err
&& !search_for_mapped_con()) {
811 return fbcon_takeover(0);
815 oldinfo
= registered_fb
[oldidx
];
817 found
= search_fb_in_map(newidx
);
819 acquire_console_sem();
820 con2fb_map
[unit
] = newidx
;
822 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
826 * If old fb is not mapped to any of the consoles,
827 * fbcon should release it.
829 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
830 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
834 int show_logo
= (fg_console
== 0 && !user
&&
835 logo_shown
!= FBCON_LOGO_DONTSHOW
);
838 fbcon_add_cursor_timer(info
);
839 con2fb_map_boot
[unit
] = newidx
;
840 con2fb_init_display(vc
, info
, unit
, show_logo
);
843 if (!search_fb_in_map(info_idx
))
846 release_console_sem();
851 * Low Level Operations
853 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
854 static int var_to_display(struct display
*disp
,
855 struct fb_var_screeninfo
*var
,
856 struct fb_info
*info
)
858 disp
->xres_virtual
= var
->xres_virtual
;
859 disp
->yres_virtual
= var
->yres_virtual
;
860 disp
->bits_per_pixel
= var
->bits_per_pixel
;
861 disp
->grayscale
= var
->grayscale
;
862 disp
->nonstd
= var
->nonstd
;
863 disp
->accel_flags
= var
->accel_flags
;
864 disp
->height
= var
->height
;
865 disp
->width
= var
->width
;
866 disp
->red
= var
->red
;
867 disp
->green
= var
->green
;
868 disp
->blue
= var
->blue
;
869 disp
->transp
= var
->transp
;
870 disp
->rotate
= var
->rotate
;
871 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
872 if (disp
->mode
== NULL
)
873 /* This should not happen */
878 static void display_to_var(struct fb_var_screeninfo
*var
,
879 struct display
*disp
)
881 fb_videomode_to_var(var
, disp
->mode
);
882 var
->xres_virtual
= disp
->xres_virtual
;
883 var
->yres_virtual
= disp
->yres_virtual
;
884 var
->bits_per_pixel
= disp
->bits_per_pixel
;
885 var
->grayscale
= disp
->grayscale
;
886 var
->nonstd
= disp
->nonstd
;
887 var
->accel_flags
= disp
->accel_flags
;
888 var
->height
= disp
->height
;
889 var
->width
= disp
->width
;
890 var
->red
= disp
->red
;
891 var
->green
= disp
->green
;
892 var
->blue
= disp
->blue
;
893 var
->transp
= disp
->transp
;
894 var
->rotate
= disp
->rotate
;
897 static const char *fbcon_startup(void)
899 const char *display_desc
= "frame buffer device";
900 struct display
*p
= &fb_display
[fg_console
];
901 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
902 const struct font_desc
*font
= NULL
;
903 struct module
*owner
;
904 struct fb_info
*info
= NULL
;
905 struct fbcon_ops
*ops
;
911 * If num_registered_fb is zero, this is a call for the dummy part.
912 * The frame buffer devices weren't initialized yet.
914 if (!num_registered_fb
|| info_idx
== -1)
917 * Instead of blindly using registered_fb[0], we use info_idx, set by
920 info
= registered_fb
[info_idx
];
924 owner
= info
->fbops
->owner
;
925 if (!try_module_get(owner
))
927 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
932 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
940 ops
->cur_rotate
= -1;
941 info
->fbcon_par
= ops
;
942 p
->con_rotate
= rotate
;
943 set_blitting_type(vc
, info
);
945 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
946 if (fbcon_softback_size
) {
950 kmalloc(fbcon_softback_size
,
953 fbcon_softback_size
= 0;
959 kfree((void *) softback_buf
);
965 softback_in
= softback_top
= softback_curr
=
970 /* Setup default font */
972 if (!fontname
[0] || !(font
= find_font(fontname
)))
973 font
= get_default_font(info
->var
.xres
,
975 vc
->vc_font
.width
= font
->width
;
976 vc
->vc_font
.height
= font
->height
;
977 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
978 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
981 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
982 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
983 cols
/= vc
->vc_font
.width
;
984 rows
/= vc
->vc_font
.height
;
985 vc_resize(vc
, cols
, rows
);
987 DPRINTK("mode: %s\n", info
->fix
.id
);
988 DPRINTK("visual: %d\n", info
->fix
.visual
);
989 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
991 info
->var
.bits_per_pixel
);
995 cursor_blink_rate
= ATARI_CURSOR_BLINK_RATE
;
997 request_irq(IRQ_AUTO_4
, fb_vbl_handler
,
998 IRQ_TYPE_PRIO
, "framebuffer vbl",
1001 #endif /* CONFIG_ATARI */
1005 * On a Macintoy, the VBL interrupt may or may not be active.
1006 * As interrupt based cursor is more reliable and race free, we
1007 * probe for VBL interrupts.
1012 * Probe for VBL: set temp. handler ...
1014 irqres
= request_irq(IRQ_MAC_VBL
, fb_vbl_detect
, 0,
1015 "framebuffer vbl", info
);
1019 * ... and spin for 20 ms ...
1021 while (!vbl_detected
&& ++ct
< 1000)
1026 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1028 free_irq(IRQ_MAC_VBL
, fb_vbl_detect
);
1032 * interrupt based cursor ok
1034 cursor_blink_rate
= MAC_CURSOR_BLINK_RATE
;
1036 request_irq(IRQ_MAC_VBL
, fb_vbl_handler
, 0,
1037 "framebuffer vbl", info
);
1040 * VBL not detected: fall through, use timer based cursor
1045 #endif /* CONFIG_MAC */
1047 fbcon_add_cursor_timer(info
);
1048 fbcon_has_exited
= 0;
1049 return display_desc
;
1052 static void fbcon_init(struct vc_data
*vc
, int init
)
1054 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1055 struct fbcon_ops
*ops
;
1056 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1057 struct vc_data
*svc
= *default_mode
;
1058 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1059 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1062 if (info_idx
== -1 || info
== NULL
)
1067 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1068 (info
->fix
.type
== FB_TYPE_TEXT
))
1071 if (var_to_display(p
, &info
->var
, info
))
1074 /* If we are not the first console on this
1075 fb, copy the font from that console */
1076 t
= &fb_display
[fg_console
];
1079 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1081 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1083 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1084 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1085 p
->userfont
= t
->userfont
;
1088 REFCOUNT(p
->fontdata
)++;
1090 const struct font_desc
*font
= NULL
;
1092 if (!fontname
[0] || !(font
= find_font(fontname
)))
1093 font
= get_default_font(info
->var
.xres
,
1095 vc
->vc_font
.width
= font
->width
;
1096 vc
->vc_font
.height
= font
->height
;
1097 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1098 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1099 support more fonts */
1104 charcnt
= FNTCHARCNT(p
->fontdata
);
1106 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1107 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1108 if (charcnt
== 256) {
1109 vc
->vc_hi_font_mask
= 0;
1111 vc
->vc_hi_font_mask
= 0x100;
1112 if (vc
->vc_can_do_color
)
1113 vc
->vc_complement_mask
<<= 1;
1116 if (!*svc
->vc_uni_pagedir_loc
)
1117 con_set_default_unimap(svc
);
1118 if (!*vc
->vc_uni_pagedir_loc
)
1119 con_copy_unimap(vc
, svc
);
1121 ops
= info
->fbcon_par
;
1122 p
->con_rotate
= rotate
;
1123 set_blitting_type(vc
, info
);
1127 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1128 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1129 new_cols
/= vc
->vc_font
.width
;
1130 new_rows
/= vc
->vc_font
.height
;
1131 vc_resize(vc
, new_cols
, new_rows
);
1134 * We must always set the mode. The mode of the previous console
1135 * driver could be in the same resolution but we are using different
1136 * hardware so we have to initialize the hardware.
1138 * We need to do it in fbcon_init() to prevent screen corruption.
1140 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1141 if (info
->fbops
->fb_set_par
&&
1142 !(ops
->flags
& FBCON_FLAGS_INIT
))
1143 info
->fbops
->fb_set_par(info
);
1144 ops
->flags
|= FBCON_FLAGS_INIT
;
1149 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1150 !(cap
& FBINFO_HWACCEL_DISABLED
))
1151 p
->scrollmode
= SCROLL_MOVE
;
1152 else /* default to something safe */
1153 p
->scrollmode
= SCROLL_REDRAW
;
1156 * ++guenther: console.c:vc_allocate() relies on initializing
1157 * vc_{cols,rows}, but we must not set those if we are only
1158 * resizing the console.
1161 vc
->vc_cols
= new_cols
;
1162 vc
->vc_rows
= new_rows
;
1166 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1168 if (vc
== svc
&& softback_buf
)
1169 fbcon_update_softback(vc
);
1171 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1172 ops
->rotate
= FB_ROTATE_UR
;
1173 set_blitting_type(vc
, info
);
1176 ops
->p
= &fb_display
[fg_console
];
1179 static void fbcon_free_font(struct display
*p
)
1181 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1182 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1187 static void fbcon_deinit(struct vc_data
*vc
)
1189 struct display
*p
= &fb_display
[vc
->vc_num
];
1190 struct fb_info
*info
;
1191 struct fbcon_ops
*ops
;
1195 idx
= con2fb_map
[vc
->vc_num
];
1200 info
= registered_fb
[idx
];
1205 ops
= info
->fbcon_par
;
1210 if (CON_IS_VISIBLE(vc
))
1211 fbcon_del_cursor_timer(info
);
1213 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1216 if (!con_is_bound(&fb_con
))
1222 /* ====================================================================== */
1224 /* fbcon_XXX routines - interface used by the world
1226 * This system is now divided into two levels because of complications
1227 * caused by hardware scrolling. Top level functions:
1229 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1231 * handles y values in range [0, scr_height-1] that correspond to real
1232 * screen positions. y_wrap shift means that first line of bitmap may be
1233 * anywhere on this display. These functions convert lineoffsets to
1234 * bitmap offsets and deal with the wrap-around case by splitting blits.
1236 * fbcon_bmove_physical_8() -- These functions fast implementations
1237 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1238 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1242 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1243 * Implies should only really hardware scroll in rows. Only reason for
1244 * restriction is simplicity & efficiency at the moment.
1247 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1250 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1251 struct fbcon_ops
*ops
= info
->fbcon_par
;
1253 struct display
*p
= &fb_display
[vc
->vc_num
];
1256 if (fbcon_is_inactive(vc
, info
))
1259 if (!height
|| !width
)
1262 /* Split blits that cross physical y_wrap boundary */
1264 y_break
= p
->vrows
- p
->yscroll
;
1265 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1266 u_int b
= y_break
- sy
;
1267 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1268 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1271 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1274 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1275 int count
, int ypos
, int xpos
)
1277 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1278 struct display
*p
= &fb_display
[vc
->vc_num
];
1279 struct fbcon_ops
*ops
= info
->fbcon_par
;
1281 if (!fbcon_is_inactive(vc
, info
))
1282 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1283 get_color(vc
, info
, scr_readw(s
), 1),
1284 get_color(vc
, info
, scr_readw(s
), 0));
1287 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1291 scr_writew(c
, &chr
);
1292 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1295 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1297 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1298 struct fbcon_ops
*ops
= info
->fbcon_par
;
1300 if (!fbcon_is_inactive(vc
, info
))
1301 ops
->clear_margins(vc
, info
, bottom_only
);
1304 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1306 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1307 struct fbcon_ops
*ops
= info
->fbcon_par
;
1309 int c
= scr_readw((u16
*) vc
->vc_pos
);
1311 if (fbcon_is_inactive(vc
, info
))
1314 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1315 if (mode
& CM_SOFTBACK
) {
1316 mode
&= ~CM_SOFTBACK
;
1320 fbcon_set_origin(vc
);
1324 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1325 get_color(vc
, info
, c
, 0));
1326 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1329 static int scrollback_phys_max
= 0;
1330 static int scrollback_max
= 0;
1331 static int scrollback_current
= 0;
1334 * If no vc is existent yet, just set struct display
1336 static void fbcon_preset_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1339 struct display
*p
= &fb_display
[unit
];
1340 struct display
*t
= &fb_display
[fg_console
];
1342 if (var_to_display(p
, var
, info
))
1345 p
->fontdata
= t
->fontdata
;
1346 p
->userfont
= t
->userfont
;
1348 REFCOUNT(p
->fontdata
)++;
1351 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1354 struct display
*p
= &fb_display
[vc
->vc_num
], *t
;
1355 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1356 struct vc_data
*svc
= *default_mode
;
1357 struct fbcon_ops
*ops
= info
->fbcon_par
;
1358 int rows
, cols
, charcnt
= 256;
1360 if (var_to_display(p
, var
, info
))
1362 t
= &fb_display
[svc
->vc_num
];
1363 if (!vc
->vc_font
.data
) {
1364 vc
->vc_font
.data
= (void *)(p
->fontdata
= t
->fontdata
);
1365 vc
->vc_font
.width
= (*default_mode
)->vc_font
.width
;
1366 vc
->vc_font
.height
= (*default_mode
)->vc_font
.height
;
1367 p
->userfont
= t
->userfont
;
1369 REFCOUNT(p
->fontdata
)++;
1372 charcnt
= FNTCHARCNT(p
->fontdata
);
1374 var
->activate
= FB_ACTIVATE_NOW
;
1375 info
->var
.activate
= var
->activate
;
1376 var
->yoffset
= info
->var
.yoffset
;
1377 var
->xoffset
= info
->var
.xoffset
;
1378 fb_set_var(info
, var
);
1379 ops
->var
= info
->var
;
1380 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1381 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1382 if (charcnt
== 256) {
1383 vc
->vc_hi_font_mask
= 0;
1385 vc
->vc_hi_font_mask
= 0x100;
1386 if (vc
->vc_can_do_color
)
1387 vc
->vc_complement_mask
<<= 1;
1390 if (!*svc
->vc_uni_pagedir_loc
)
1391 con_set_default_unimap(svc
);
1392 if (!*vc
->vc_uni_pagedir_loc
)
1393 con_copy_unimap(vc
, svc
);
1395 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1396 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1397 cols
/= vc
->vc_font
.width
;
1398 rows
/= vc
->vc_font
.height
;
1399 vc_resize(vc
, cols
, rows
);
1401 if (CON_IS_VISIBLE(vc
)) {
1404 fbcon_update_softback(vc
);
1408 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
)
1410 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1411 struct fbcon_ops
*ops
= info
->fbcon_par
;
1412 struct display
*p
= &fb_display
[vc
->vc_num
];
1414 p
->yscroll
+= count
;
1415 if (p
->yscroll
>= p
->vrows
) /* Deal with wrap */
1416 p
->yscroll
-= p
->vrows
;
1417 ops
->var
.xoffset
= 0;
1418 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1419 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1420 ops
->update_start(info
);
1421 scrollback_max
+= count
;
1422 if (scrollback_max
> scrollback_phys_max
)
1423 scrollback_max
= scrollback_phys_max
;
1424 scrollback_current
= 0;
1427 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
)
1429 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1430 struct fbcon_ops
*ops
= info
->fbcon_par
;
1431 struct display
*p
= &fb_display
[vc
->vc_num
];
1433 p
->yscroll
-= count
;
1434 if (p
->yscroll
< 0) /* Deal with wrap */
1435 p
->yscroll
+= p
->vrows
;
1436 ops
->var
.xoffset
= 0;
1437 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1438 ops
->var
.vmode
|= FB_VMODE_YWRAP
;
1439 ops
->update_start(info
);
1440 scrollback_max
-= count
;
1441 if (scrollback_max
< 0)
1443 scrollback_current
= 0;
1446 static __inline__
void ypan_up(struct vc_data
*vc
, int count
)
1448 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1449 struct display
*p
= &fb_display
[vc
->vc_num
];
1450 struct fbcon_ops
*ops
= info
->fbcon_par
;
1452 p
->yscroll
+= count
;
1453 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1454 ops
->bmove(vc
, info
, p
->vrows
- vc
->vc_rows
,
1455 0, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
1456 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1459 ops
->var
.xoffset
= 0;
1460 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1461 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1462 ops
->update_start(info
);
1463 fbcon_clear_margins(vc
, 1);
1464 scrollback_max
+= count
;
1465 if (scrollback_max
> scrollback_phys_max
)
1466 scrollback_max
= scrollback_phys_max
;
1467 scrollback_current
= 0;
1470 static __inline__
void ypan_up_redraw(struct vc_data
*vc
, int t
, int count
)
1472 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1473 struct fbcon_ops
*ops
= info
->fbcon_par
;
1474 struct display
*p
= &fb_display
[vc
->vc_num
];
1476 p
->yscroll
+= count
;
1478 if (p
->yscroll
> p
->vrows
- vc
->vc_rows
) {
1479 p
->yscroll
-= p
->vrows
- vc
->vc_rows
;
1480 fbcon_redraw_move(vc
, p
, t
+ count
, vc
->vc_rows
- count
, t
);
1483 ops
->var
.xoffset
= 0;
1484 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1485 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1486 ops
->update_start(info
);
1487 fbcon_clear_margins(vc
, 1);
1488 scrollback_max
+= count
;
1489 if (scrollback_max
> scrollback_phys_max
)
1490 scrollback_max
= scrollback_phys_max
;
1491 scrollback_current
= 0;
1494 static __inline__
void ypan_down(struct vc_data
*vc
, int count
)
1496 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1497 struct display
*p
= &fb_display
[vc
->vc_num
];
1498 struct fbcon_ops
*ops
= info
->fbcon_par
;
1500 p
->yscroll
-= count
;
1501 if (p
->yscroll
< 0) {
1502 ops
->bmove(vc
, info
, 0, 0, p
->vrows
- vc
->vc_rows
,
1503 0, vc
->vc_rows
, vc
->vc_cols
);
1504 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1507 ops
->var
.xoffset
= 0;
1508 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1509 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1510 ops
->update_start(info
);
1511 fbcon_clear_margins(vc
, 1);
1512 scrollback_max
-= count
;
1513 if (scrollback_max
< 0)
1515 scrollback_current
= 0;
1518 static __inline__
void ypan_down_redraw(struct vc_data
*vc
, int t
, int count
)
1520 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1521 struct fbcon_ops
*ops
= info
->fbcon_par
;
1522 struct display
*p
= &fb_display
[vc
->vc_num
];
1524 p
->yscroll
-= count
;
1526 if (p
->yscroll
< 0) {
1527 p
->yscroll
+= p
->vrows
- vc
->vc_rows
;
1528 fbcon_redraw_move(vc
, p
, t
, vc
->vc_rows
- count
, t
+ count
);
1531 ops
->var
.xoffset
= 0;
1532 ops
->var
.yoffset
= p
->yscroll
* vc
->vc_font
.height
;
1533 ops
->var
.vmode
&= ~FB_VMODE_YWRAP
;
1534 ops
->update_start(info
);
1535 fbcon_clear_margins(vc
, 1);
1536 scrollback_max
-= count
;
1537 if (scrollback_max
< 0)
1539 scrollback_current
= 0;
1542 static void fbcon_redraw_softback(struct vc_data
*vc
, struct display
*p
,
1545 int count
= vc
->vc_rows
;
1546 unsigned short *d
, *s
;
1550 d
= (u16
*) softback_curr
;
1551 if (d
== (u16
*) softback_in
)
1552 d
= (u16
*) vc
->vc_origin
;
1553 n
= softback_curr
+ delta
* vc
->vc_size_row
;
1554 softback_lines
-= delta
;
1556 if (softback_curr
< softback_top
&& n
< softback_buf
) {
1557 n
+= softback_end
- softback_buf
;
1558 if (n
< softback_top
) {
1560 (softback_top
- n
) / vc
->vc_size_row
;
1563 } else if (softback_curr
>= softback_top
1564 && n
< softback_top
) {
1566 (softback_top
- n
) / vc
->vc_size_row
;
1570 if (softback_curr
> softback_in
&& n
>= softback_end
) {
1571 n
+= softback_buf
- softback_end
;
1572 if (n
> softback_in
) {
1576 } else if (softback_curr
<= softback_in
&& n
> softback_in
) {
1581 if (n
== softback_curr
)
1584 s
= (u16
*) softback_curr
;
1585 if (s
== (u16
*) softback_in
)
1586 s
= (u16
*) vc
->vc_origin
;
1588 unsigned short *start
;
1592 unsigned short attr
= 1;
1595 le
= advance_row(s
, 1);
1598 if (attr
!= (c
& 0xff00)) {
1601 fbcon_putcs(vc
, start
, s
- start
,
1607 if (c
== scr_readw(d
)) {
1609 fbcon_putcs(vc
, start
, s
- start
,
1622 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1624 if (d
== (u16
*) softback_end
)
1625 d
= (u16
*) softback_buf
;
1626 if (d
== (u16
*) softback_in
)
1627 d
= (u16
*) vc
->vc_origin
;
1628 if (s
== (u16
*) softback_end
)
1629 s
= (u16
*) softback_buf
;
1630 if (s
== (u16
*) softback_in
)
1631 s
= (u16
*) vc
->vc_origin
;
1635 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
1636 int line
, int count
, int dy
)
1638 unsigned short *s
= (unsigned short *)
1639 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1642 unsigned short *start
= s
;
1643 unsigned short *le
= advance_row(s
, 1);
1646 unsigned short attr
= 1;
1650 if (attr
!= (c
& 0xff00)) {
1653 fbcon_putcs(vc
, start
, s
- start
,
1659 console_conditional_schedule();
1663 fbcon_putcs(vc
, start
, s
- start
, dy
, x
);
1664 console_conditional_schedule();
1669 static void fbcon_redraw(struct vc_data
*vc
, struct display
*p
,
1670 int line
, int count
, int offset
)
1672 unsigned short *d
= (unsigned short *)
1673 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1674 unsigned short *s
= d
+ offset
;
1677 unsigned short *start
= s
;
1678 unsigned short *le
= advance_row(s
, 1);
1681 unsigned short attr
= 1;
1685 if (attr
!= (c
& 0xff00)) {
1688 fbcon_putcs(vc
, start
, s
- start
,
1694 if (c
== scr_readw(d
)) {
1696 fbcon_putcs(vc
, start
, s
- start
,
1706 console_conditional_schedule();
1711 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1712 console_conditional_schedule();
1717 /* NOTE: We subtract two lines from these pointers */
1718 s
-= vc
->vc_size_row
;
1719 d
-= vc
->vc_size_row
;
1724 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1729 if (vc
->vc_num
!= fg_console
)
1731 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1734 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1736 p
= advance_row(p
, 1);
1737 softback_in
+= vc
->vc_size_row
;
1738 if (softback_in
== softback_end
)
1739 softback_in
= softback_buf
;
1740 if (softback_in
== softback_top
) {
1741 softback_top
+= vc
->vc_size_row
;
1742 if (softback_top
== softback_end
)
1743 softback_top
= softback_buf
;
1746 softback_curr
= softback_in
;
1749 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1752 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1753 struct display
*p
= &fb_display
[vc
->vc_num
];
1754 struct fbcon_ops
*ops
= info
->fbcon_par
;
1755 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1757 if (fbcon_is_inactive(vc
, info
))
1760 fbcon_cursor(vc
, CM_ERASE
);
1763 * ++Geert: Only use ywrap/ypan if the console is in text mode
1764 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1765 * whole screen (prevents flicker).
1770 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1771 count
= vc
->vc_rows
;
1773 fbcon_softback_note(vc
, t
, count
);
1774 if (logo_shown
>= 0)
1776 switch (p
->scrollmode
) {
1778 ops
->bmove(vc
, info
, t
+ count
, 0, t
, 0,
1779 b
- t
- count
, vc
->vc_cols
);
1780 ops
->clear(vc
, info
, b
- count
, 0, count
,
1784 case SCROLL_WRAP_MOVE
:
1785 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1787 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1789 ywrap_up(vc
, count
);
1790 if (vc
->vc_rows
- b
> 0)
1791 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1794 } else if (info
->flags
& FBINFO_READS_FAST
)
1795 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1796 b
- t
- count
, vc
->vc_cols
);
1799 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1802 case SCROLL_PAN_REDRAW
:
1803 if ((p
->yscroll
+ count
<=
1804 2 * (p
->vrows
- vc
->vc_rows
))
1805 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1808 3 * vc
->vc_rows
>> 2)))) {
1810 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1811 ypan_up_redraw(vc
, t
, count
);
1812 if (vc
->vc_rows
- b
> 0)
1813 fbcon_redraw_move(vc
, p
, b
,
1814 vc
->vc_rows
- b
, b
);
1816 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1817 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1820 case SCROLL_PAN_MOVE
:
1821 if ((p
->yscroll
+ count
<=
1822 2 * (p
->vrows
- vc
->vc_rows
))
1823 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1826 3 * vc
->vc_rows
>> 2)))) {
1828 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1831 if (vc
->vc_rows
- b
> 0)
1832 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1835 } else if (info
->flags
& FBINFO_READS_FAST
)
1836 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1837 b
- t
- count
, vc
->vc_cols
);
1840 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1845 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1846 count
* vc
->vc_cols
);
1847 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1848 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1851 vc
->vc_video_erase_char
,
1852 vc
->vc_size_row
* count
);
1858 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1859 count
= vc
->vc_rows
;
1860 if (logo_shown
>= 0)
1862 switch (p
->scrollmode
) {
1864 ops
->bmove(vc
, info
, t
, 0, t
+ count
, 0,
1865 b
- t
- count
, vc
->vc_cols
);
1866 ops
->clear(vc
, info
, t
, 0, count
, vc
->vc_cols
);
1869 case SCROLL_WRAP_MOVE
:
1870 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1871 if (vc
->vc_rows
- b
> 0)
1872 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1875 ywrap_down(vc
, count
);
1877 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1879 } else if (info
->flags
& FBINFO_READS_FAST
)
1880 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1881 b
- t
- count
, vc
->vc_cols
);
1884 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1887 case SCROLL_PAN_MOVE
:
1888 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1889 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1892 3 * vc
->vc_rows
>> 2)))) {
1893 if (vc
->vc_rows
- b
> 0)
1894 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1897 ypan_down(vc
, count
);
1899 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1901 } else if (info
->flags
& FBINFO_READS_FAST
)
1902 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1903 b
- t
- count
, vc
->vc_cols
);
1906 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1909 case SCROLL_PAN_REDRAW
:
1910 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1911 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1914 3 * vc
->vc_rows
>> 2)))) {
1915 if (vc
->vc_rows
- b
> 0)
1916 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1918 ypan_down_redraw(vc
, t
, count
);
1920 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1922 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1923 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1928 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1929 -count
* vc
->vc_cols
);
1930 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1931 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1934 vc
->vc_video_erase_char
,
1935 vc
->vc_size_row
* count
);
1943 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1944 int height
, int width
)
1946 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1947 struct display
*p
= &fb_display
[vc
->vc_num
];
1949 if (fbcon_is_inactive(vc
, info
))
1952 if (!width
|| !height
)
1955 /* Split blits that cross physical y_wrap case.
1956 * Pathological case involves 4 blits, better to use recursive
1957 * code rather than unrolled case
1959 * Recursive invocations don't need to erase the cursor over and
1960 * over again, so we use fbcon_bmove_rec()
1962 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
1963 p
->vrows
- p
->yscroll
);
1966 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
1967 int dy
, int dx
, int height
, int width
, u_int y_break
)
1969 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1970 struct fbcon_ops
*ops
= info
->fbcon_par
;
1973 if (sy
< y_break
&& sy
+ height
> y_break
) {
1975 if (dy
< sy
) { /* Avoid trashing self */
1976 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1978 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1979 height
- b
, width
, y_break
);
1981 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1982 height
- b
, width
, y_break
);
1983 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1989 if (dy
< y_break
&& dy
+ height
> y_break
) {
1991 if (dy
< sy
) { /* Avoid trashing self */
1992 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1994 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1995 height
- b
, width
, y_break
);
1997 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1998 height
- b
, width
, y_break
);
1999 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2004 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2008 static __inline__
void updatescrollmode(struct display
*p
,
2009 struct fb_info
*info
,
2012 struct fbcon_ops
*ops
= info
->fbcon_par
;
2013 int fh
= vc
->vc_font
.height
;
2014 int cap
= info
->flags
;
2016 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2017 info
->fix
.xpanstep
);
2018 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2019 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2020 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2021 info
->var
.xres_virtual
);
2022 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2023 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2024 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2025 divides(ywrap
, vc
->vc_font
.height
) &&
2026 divides(vc
->vc_font
.height
, vyres
) &&
2027 divides(vc
->vc_font
.height
, yres
);
2028 int reading_fast
= cap
& FBINFO_READS_FAST
;
2029 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2030 !(cap
& FBINFO_HWACCEL_DISABLED
);
2031 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2032 !(cap
& FBINFO_HWACCEL_DISABLED
);
2034 p
->vrows
= vyres
/fh
;
2035 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2036 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2037 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2040 if (good_wrap
|| good_pan
) {
2041 if (reading_fast
|| fast_copyarea
)
2042 p
->scrollmode
= good_wrap
?
2043 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2045 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2048 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2049 p
->scrollmode
= SCROLL_MOVE
;
2051 p
->scrollmode
= SCROLL_REDRAW
;
2055 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2056 unsigned int height
)
2058 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2059 struct fbcon_ops
*ops
= info
->fbcon_par
;
2060 struct display
*p
= &fb_display
[vc
->vc_num
];
2061 struct fb_var_screeninfo var
= info
->var
;
2062 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2064 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2065 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2066 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2067 vc
->vc_font
.height
);
2068 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2070 var
.xres
= virt_w
* virt_fw
;
2071 var
.yres
= virt_h
* virt_fh
;
2072 x_diff
= info
->var
.xres
- var
.xres
;
2073 y_diff
= info
->var
.yres
- var
.yres
;
2074 if (x_diff
< 0 || x_diff
> virt_fw
||
2075 y_diff
< 0 || y_diff
> virt_fh
) {
2076 struct fb_videomode
*mode
;
2078 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2079 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2082 display_to_var(&var
, p
);
2083 fb_videomode_to_var(&var
, mode
);
2085 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2088 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2089 if (CON_IS_VISIBLE(vc
)) {
2090 var
.activate
= FB_ACTIVATE_NOW
|
2092 fb_set_var(info
, &var
);
2094 var_to_display(p
, &info
->var
, info
);
2095 ops
->var
= info
->var
;
2097 updatescrollmode(p
, info
, vc
);
2101 static int fbcon_switch(struct vc_data
*vc
)
2103 struct fb_info
*info
, *old_info
= NULL
;
2104 struct fbcon_ops
*ops
;
2105 struct display
*p
= &fb_display
[vc
->vc_num
];
2106 struct fb_var_screeninfo var
;
2107 int i
, prev_console
, charcnt
= 256;
2109 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2110 ops
= info
->fbcon_par
;
2114 fbcon_set_origin(vc
);
2115 softback_top
= softback_curr
= softback_in
= softback_buf
;
2117 fbcon_update_softback(vc
);
2120 if (logo_shown
>= 0) {
2121 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2123 if (conp2
->vc_top
== logo_lines
2124 && conp2
->vc_bottom
== conp2
->vc_rows
)
2126 logo_shown
= FBCON_LOGO_CANSHOW
;
2129 prev_console
= ops
->currcon
;
2130 if (prev_console
!= -1)
2131 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2133 * FIXME: If we have multiple fbdev's loaded, we need to
2134 * update all info->currcon. Perhaps, we can place this
2135 * in a centralized structure, but this might break some
2138 * info->currcon = vc->vc_num;
2140 for (i
= 0; i
< FB_MAX
; i
++) {
2141 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2142 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2144 o
->currcon
= vc
->vc_num
;
2147 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2148 display_to_var(&var
, p
);
2149 var
.activate
= FB_ACTIVATE_NOW
;
2152 * make sure we don't unnecessarily trip the memcmp()
2155 info
->var
.activate
= var
.activate
;
2156 var
.yoffset
= info
->var
.yoffset
;
2157 var
.xoffset
= info
->var
.xoffset
;
2158 var
.vmode
= info
->var
.vmode
;
2159 fb_set_var(info
, &var
);
2160 ops
->var
= info
->var
;
2162 if (old_info
!= NULL
&& (old_info
!= info
||
2163 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2164 if (info
->fbops
->fb_set_par
)
2165 info
->fbops
->fb_set_par(info
);
2167 if (old_info
!= info
)
2168 fbcon_del_cursor_timer(old_info
);
2171 fbcon_add_cursor_timer(info
);
2172 set_blitting_type(vc
, info
);
2173 ops
->cursor_reset
= 1;
2175 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2176 ops
->rotate
= FB_ROTATE_UR
;
2177 set_blitting_type(vc
, info
);
2180 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2181 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2184 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2187 vc
->vc_complement_mask
<<= 1;
2189 updatescrollmode(p
, info
, vc
);
2191 switch (p
->scrollmode
) {
2192 case SCROLL_WRAP_MOVE
:
2193 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2195 case SCROLL_PAN_MOVE
:
2196 case SCROLL_PAN_REDRAW
:
2197 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2198 if (scrollback_phys_max
< 0)
2199 scrollback_phys_max
= 0;
2202 scrollback_phys_max
= 0;
2207 scrollback_current
= 0;
2209 if (!fbcon_is_inactive(vc
, info
)) {
2210 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2211 ops
->update_start(info
);
2214 fbcon_set_palette(vc
, color_table
);
2215 fbcon_clear_margins(vc
, 0);
2217 if (logo_shown
== FBCON_LOGO_DRAW
) {
2219 logo_shown
= fg_console
;
2220 /* This is protected above by initmem_freed */
2221 fb_show_logo(info
, ops
->rotate
);
2223 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2224 vc
->vc_size_row
* (vc
->vc_bottom
-
2231 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2235 unsigned short charmask
= vc
->vc_hi_font_mask
?
2237 unsigned short oldc
;
2239 oldc
= vc
->vc_video_erase_char
;
2240 vc
->vc_video_erase_char
&= charmask
;
2241 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2242 vc
->vc_video_erase_char
= oldc
;
2246 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2248 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2249 struct fbcon_ops
*ops
= info
->fbcon_par
;
2252 struct fb_var_screeninfo var
= info
->var
;
2257 if (info
->fbops
->fb_save_state
)
2258 info
->fbops
->fb_save_state(info
);
2259 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2260 fb_set_var(info
, &var
);
2262 ops
->var
= info
->var
;
2263 } else if (info
->fbops
->fb_restore_state
)
2264 info
->fbops
->fb_restore_state(info
);
2267 if (!fbcon_is_inactive(vc
, info
)) {
2268 if (ops
->blank_state
!= blank
) {
2269 ops
->blank_state
= blank
;
2270 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2271 ops
->cursor_flash
= (!blank
);
2273 if (fb_blank(info
, blank
))
2274 fbcon_generic_blank(vc
, info
, blank
);
2282 fbcon_add_cursor_timer(info
);
2284 fbcon_del_cursor_timer(info
);
2289 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2291 u8
*fontdata
= vc
->vc_font
.data
;
2292 u8
*data
= font
->data
;
2295 font
->width
= vc
->vc_font
.width
;
2296 font
->height
= vc
->vc_font
.height
;
2297 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2301 if (font
->width
<= 8) {
2302 j
= vc
->vc_font
.height
;
2303 for (i
= 0; i
< font
->charcount
; i
++) {
2304 memcpy(data
, fontdata
, j
);
2305 memset(data
+ j
, 0, 32 - j
);
2309 } else if (font
->width
<= 16) {
2310 j
= vc
->vc_font
.height
* 2;
2311 for (i
= 0; i
< font
->charcount
; i
++) {
2312 memcpy(data
, fontdata
, j
);
2313 memset(data
+ j
, 0, 64 - j
);
2317 } else if (font
->width
<= 24) {
2318 for (i
= 0; i
< font
->charcount
; i
++) {
2319 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2320 *data
++ = fontdata
[0];
2321 *data
++ = fontdata
[1];
2322 *data
++ = fontdata
[2];
2323 fontdata
+= sizeof(u32
);
2325 memset(data
, 0, 3 * (32 - j
));
2326 data
+= 3 * (32 - j
);
2329 j
= vc
->vc_font
.height
* 4;
2330 for (i
= 0; i
< font
->charcount
; i
++) {
2331 memcpy(data
, fontdata
, j
);
2332 memset(data
+ j
, 0, 128 - j
);
2340 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2341 const u8
* data
, int userfont
)
2343 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2344 struct fbcon_ops
*ops
= info
->fbcon_par
;
2345 struct display
*p
= &fb_display
[vc
->vc_num
];
2348 char *old_data
= NULL
;
2350 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2351 fbcon_set_origin(vc
);
2353 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2355 old_data
= vc
->vc_font
.data
;
2357 cnt
= FNTCHARCNT(data
);
2360 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2361 if ((p
->userfont
= userfont
))
2363 vc
->vc_font
.width
= w
;
2364 vc
->vc_font
.height
= h
;
2365 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2366 vc
->vc_hi_font_mask
= 0;
2367 if (vc
->vc_can_do_color
) {
2368 vc
->vc_complement_mask
>>= 1;
2369 vc
->vc_s_complement_mask
>>= 1;
2372 /* ++Edmund: reorder the attribute bits */
2373 if (vc
->vc_can_do_color
) {
2374 unsigned short *cp
=
2375 (unsigned short *) vc
->vc_origin
;
2376 int count
= vc
->vc_screenbuf_size
/ 2;
2378 for (; count
> 0; count
--, cp
++) {
2380 scr_writew(((c
& 0xfe00) >> 1) |
2383 c
= vc
->vc_video_erase_char
;
2384 vc
->vc_video_erase_char
=
2385 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2388 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2389 vc
->vc_hi_font_mask
= 0x100;
2390 if (vc
->vc_can_do_color
) {
2391 vc
->vc_complement_mask
<<= 1;
2392 vc
->vc_s_complement_mask
<<= 1;
2395 /* ++Edmund: reorder the attribute bits */
2397 unsigned short *cp
=
2398 (unsigned short *) vc
->vc_origin
;
2399 int count
= vc
->vc_screenbuf_size
/ 2;
2401 for (; count
> 0; count
--, cp
++) {
2402 unsigned short newc
;
2404 if (vc
->vc_can_do_color
)
2406 ((c
& 0xff00) << 1) | (c
&
2410 scr_writew(newc
, cp
);
2412 c
= vc
->vc_video_erase_char
;
2413 if (vc
->vc_can_do_color
) {
2414 vc
->vc_video_erase_char
=
2415 ((c
& 0xff00) << 1) | (c
& 0xff);
2418 vc
->vc_video_erase_char
= c
& ~0x100;
2426 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2427 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2430 vc_resize(vc
, cols
, rows
);
2431 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2432 fbcon_update_softback(vc
);
2433 } else if (CON_IS_VISIBLE(vc
)
2434 && vc
->vc_mode
== KD_TEXT
) {
2435 fbcon_clear_margins(vc
, 0);
2439 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2440 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2444 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2446 struct display
*od
= &fb_display
[con
];
2447 struct console_font
*f
= &vc
->vc_font
;
2449 if (od
->fontdata
== f
->data
)
2450 return 0; /* already the same font... */
2451 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2455 * User asked to set font; we are guaranteed that
2456 * a) width and height are in range 1..32
2457 * b) charcount does not exceed 512
2458 * but lets not assume that, since someone might someday want to use larger
2459 * fonts. And charcount of 512 is small for unicode support.
2461 * However, user space gives the font in 32 rows , regardless of
2462 * actual font height. So a new API is needed if support for larger fonts
2463 * is ever implemented.
2466 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2468 unsigned charcount
= font
->charcount
;
2469 int w
= font
->width
;
2470 int h
= font
->height
;
2473 u8
*new_data
, *data
= font
->data
;
2474 int pitch
= (font
->width
+7) >> 3;
2476 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2477 * If not this check should be changed to charcount < 256 */
2478 if (charcount
!= 256 && charcount
!= 512)
2481 size
= h
* pitch
* charcount
;
2483 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2488 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2489 FNTSIZE(new_data
) = size
;
2490 FNTCHARCNT(new_data
) = charcount
;
2491 REFCOUNT(new_data
) = 0; /* usage counter */
2492 for (i
=0; i
< charcount
; i
++) {
2493 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2496 /* Since linux has a nice crc32 function use it for counting font
2498 csum
= crc32(0, new_data
, size
);
2500 FNTSUM(new_data
) = csum
;
2501 /* Check if the same font is on some other console already */
2502 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2503 struct vc_data
*tmp
= vc_cons
[i
].d
;
2505 if (fb_display
[i
].userfont
&&
2506 fb_display
[i
].fontdata
&&
2507 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2508 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2509 tmp
->vc_font
.width
== w
&&
2510 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2511 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2512 new_data
= (u8
*)fb_display
[i
].fontdata
;
2516 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2519 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2521 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2522 const struct font_desc
*f
;
2525 f
= get_default_font(info
->var
.xres
, info
->var
.yres
);
2526 else if (!(f
= find_font(name
)))
2529 font
->width
= f
->width
;
2530 font
->height
= f
->height
;
2531 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2534 static u16 palette_red
[16];
2535 static u16 palette_green
[16];
2536 static u16 palette_blue
[16];
2538 static struct fb_cmap palette_cmap
= {
2539 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2542 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2544 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2548 if (fbcon_is_inactive(vc
, info
))
2551 if (!CON_IS_VISIBLE(vc
))
2554 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2556 for (i
= j
= 0; i
< 16; i
++) {
2558 val
= vc
->vc_palette
[j
++];
2559 palette_red
[k
] = (val
<< 8) | val
;
2560 val
= vc
->vc_palette
[j
++];
2561 palette_green
[k
] = (val
<< 8) | val
;
2562 val
= vc
->vc_palette
[j
++];
2563 palette_blue
[k
] = (val
<< 8) | val
;
2565 palette_cmap
.len
= 16;
2566 palette_cmap
.start
= 0;
2568 * If framebuffer is capable of less than 16 colors,
2569 * use default palette of fbcon.
2572 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2574 return fb_set_cmap(&palette_cmap
, info
);
2577 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2582 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2583 return (u16
*) (vc
->vc_origin
+ offset
);
2584 line
= offset
/ vc
->vc_size_row
;
2585 if (line
>= softback_lines
)
2586 return (u16
*) (vc
->vc_origin
+ offset
-
2587 softback_lines
* vc
->vc_size_row
);
2588 p
= softback_curr
+ offset
;
2589 if (p
>= softback_end
)
2590 p
+= softback_buf
- softback_end
;
2594 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2600 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2601 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2603 x
= offset
% vc
->vc_cols
;
2604 y
= offset
/ vc
->vc_cols
;
2605 if (vc
->vc_num
== fg_console
)
2606 y
+= softback_lines
;
2607 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2608 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2609 unsigned long offset
= pos
- softback_curr
;
2611 if (pos
< softback_curr
)
2612 offset
+= softback_end
- softback_buf
;
2614 x
= offset
% vc
->vc_cols
;
2615 y
= offset
/ vc
->vc_cols
;
2616 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2617 if (ret
== softback_end
)
2619 if (ret
== softback_in
)
2620 ret
= vc
->vc_origin
;
2622 /* Should not happen */
2624 ret
= vc
->vc_origin
;
2633 /* As we might be inside of softback, we may work with non-contiguous buffer,
2634 that's why we have to use a separate routine. */
2635 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2638 u16 a
= scr_readw(p
);
2639 if (!vc
->vc_can_do_color
)
2641 else if (vc
->vc_hi_font_mask
== 0x100)
2642 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2643 (((a
) & 0x0e00) << 4);
2645 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2646 (((a
) & 0x0700) << 4);
2648 if (p
== (u16
*) softback_end
)
2649 p
= (u16
*) softback_buf
;
2650 if (p
== (u16
*) softback_in
)
2651 p
= (u16
*) vc
->vc_origin
;
2655 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2657 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2658 struct fbcon_ops
*ops
= info
->fbcon_par
;
2659 struct display
*p
= &fb_display
[fg_console
];
2660 int offset
, limit
, scrollback_old
;
2663 if (vc
->vc_num
!= fg_console
)
2665 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2667 if (logo_shown
>= 0) {
2668 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2670 if (conp2
->vc_top
== logo_lines
2671 && conp2
->vc_bottom
== conp2
->vc_rows
)
2673 if (logo_shown
== vc
->vc_num
) {
2679 logo_lines
* vc
->vc_size_row
;
2680 for (i
= 0; i
< logo_lines
; i
++) {
2681 if (p
== softback_top
)
2683 if (p
== softback_buf
)
2685 p
-= vc
->vc_size_row
;
2686 q
-= vc
->vc_size_row
;
2687 scr_memcpyw((u16
*) q
, (u16
*) p
,
2690 softback_in
= softback_curr
= p
;
2691 update_region(vc
, vc
->vc_origin
,
2692 logo_lines
* vc
->vc_cols
);
2694 logo_shown
= FBCON_LOGO_CANSHOW
;
2696 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2697 fbcon_redraw_softback(vc
, p
, lines
);
2698 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2702 if (!scrollback_phys_max
)
2705 scrollback_old
= scrollback_current
;
2706 scrollback_current
-= lines
;
2707 if (scrollback_current
< 0)
2708 scrollback_current
= 0;
2709 else if (scrollback_current
> scrollback_max
)
2710 scrollback_current
= scrollback_max
;
2711 if (scrollback_current
== scrollback_old
)
2714 if (fbcon_is_inactive(vc
, info
))
2717 fbcon_cursor(vc
, CM_ERASE
);
2719 offset
= p
->yscroll
- scrollback_current
;
2721 switch (p
->scrollmode
) {
2722 case SCROLL_WRAP_MOVE
:
2723 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2725 case SCROLL_PAN_MOVE
:
2726 case SCROLL_PAN_REDRAW
:
2727 limit
-= vc
->vc_rows
;
2728 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2733 else if (offset
>= limit
)
2736 ops
->var
.xoffset
= 0;
2737 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2738 ops
->update_start(info
);
2740 if (!scrollback_current
)
2741 fbcon_cursor(vc
, CM_DRAW
);
2745 static int fbcon_set_origin(struct vc_data
*vc
)
2748 fbcon_scrolldelta(vc
, softback_lines
);
2752 static void fbcon_suspended(struct fb_info
*info
)
2754 struct vc_data
*vc
= NULL
;
2755 struct fbcon_ops
*ops
= info
->fbcon_par
;
2757 if (!ops
|| ops
->currcon
< 0)
2759 vc
= vc_cons
[ops
->currcon
].d
;
2761 /* Clear cursor, restore saved data */
2762 fbcon_cursor(vc
, CM_ERASE
);
2765 static void fbcon_resumed(struct fb_info
*info
)
2768 struct fbcon_ops
*ops
= info
->fbcon_par
;
2770 if (!ops
|| ops
->currcon
< 0)
2772 vc
= vc_cons
[ops
->currcon
].d
;
2777 static void fbcon_modechanged(struct fb_info
*info
)
2779 struct fbcon_ops
*ops
= info
->fbcon_par
;
2784 if (!ops
|| ops
->currcon
< 0)
2786 vc
= vc_cons
[ops
->currcon
].d
;
2787 if (vc
->vc_mode
!= KD_TEXT
||
2788 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2791 p
= &fb_display
[vc
->vc_num
];
2792 set_blitting_type(vc
, info
);
2794 if (CON_IS_VISIBLE(vc
)) {
2795 var_to_display(p
, &info
->var
, info
);
2796 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2797 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2798 cols
/= vc
->vc_font
.width
;
2799 rows
/= vc
->vc_font
.height
;
2800 vc_resize(vc
, cols
, rows
);
2801 updatescrollmode(p
, info
, vc
);
2803 scrollback_current
= 0;
2805 if (!fbcon_is_inactive(vc
, info
)) {
2806 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2807 ops
->update_start(info
);
2810 fbcon_set_palette(vc
, color_table
);
2813 fbcon_update_softback(vc
);
2817 static void fbcon_set_all_vcs(struct fb_info
*info
)
2819 struct fbcon_ops
*ops
= info
->fbcon_par
;
2824 if (!ops
|| ops
->currcon
< 0)
2827 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2829 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2830 registered_fb
[con2fb_map
[i
]] != info
)
2833 p
= &fb_display
[vc
->vc_num
];
2834 set_blitting_type(vc
, info
);
2835 var_to_display(p
, &info
->var
, info
);
2836 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2837 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2838 cols
/= vc
->vc_font
.width
;
2839 rows
/= vc
->vc_font
.height
;
2840 vc_resize(vc
, cols
, rows
);
2842 if (CON_IS_VISIBLE(vc
)) {
2843 updatescrollmode(p
, info
, vc
);
2845 scrollback_current
= 0;
2847 if (!fbcon_is_inactive(vc
, info
)) {
2848 ops
->var
.xoffset
= ops
->var
.yoffset
=
2850 ops
->update_start(info
);
2853 fbcon_set_palette(vc
, color_table
);
2856 fbcon_update_softback(vc
);
2860 ops
->p
= &fb_display
[ops
->currcon
];
2863 static int fbcon_mode_deleted(struct fb_info
*info
,
2864 struct fb_videomode
*mode
)
2866 struct fb_info
*fb_info
;
2868 int i
, j
, found
= 0;
2870 /* before deletion, ensure that mode is not in use */
2871 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2875 fb_info
= registered_fb
[j
];
2876 if (fb_info
!= info
)
2881 if (fb_mode_is_equal(p
->mode
, mode
)) {
2889 static int fbcon_fb_unregistered(int idx
)
2893 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2894 if (con2fb_map
[i
] == idx
)
2898 if (idx
== info_idx
) {
2901 for (i
= 0; i
< FB_MAX
; i
++) {
2902 if (registered_fb
[i
] != NULL
) {
2909 if (info_idx
!= -1) {
2910 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2911 if (con2fb_map
[i
] == -1)
2912 con2fb_map
[i
] = info_idx
;
2916 if (!num_registered_fb
)
2917 unregister_con_driver(&fb_con
);
2922 static int fbcon_fb_registered(int idx
)
2926 if (info_idx
== -1) {
2927 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2928 if (con2fb_map_boot
[i
] == idx
) {
2935 ret
= fbcon_takeover(1);
2937 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2938 if (con2fb_map_boot
[i
] == idx
&&
2939 con2fb_map
[i
] == -1)
2940 set_con2fb_map(i
, idx
, 0);
2947 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
2949 struct fbcon_ops
*ops
= info
->fbcon_par
;
2952 if (!ops
|| ops
->currcon
< 0)
2955 vc
= vc_cons
[ops
->currcon
].d
;
2956 if (vc
->vc_mode
!= KD_TEXT
||
2957 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2960 if (CON_IS_VISIBLE(vc
)) {
2964 do_unblank_screen(0);
2966 ops
->blank_state
= blank
;
2969 static void fbcon_new_modelist(struct fb_info
*info
)
2973 struct fb_var_screeninfo var
;
2974 struct fb_videomode
*mode
;
2976 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2977 if (registered_fb
[con2fb_map
[i
]] != info
)
2979 if (!fb_display
[i
].mode
)
2982 display_to_var(&var
, &fb_display
[i
]);
2983 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
2985 fb_videomode_to_var(&var
, mode
);
2988 fbcon_set_disp(info
, &var
, vc
);
2990 fbcon_preset_disp(info
, &var
, i
);
2995 static int fbcon_event_notify(struct notifier_block
*self
,
2996 unsigned long action
, void *data
)
2998 struct fb_event
*event
= data
;
2999 struct fb_info
*info
= event
->info
;
3000 struct fb_videomode
*mode
;
3001 struct fb_con2fbmap
*con2fb
;
3005 * ignore all events except driver registration and deregistration
3006 * if fbcon is not active
3008 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3009 action
== FB_EVENT_FB_UNREGISTERED
))
3013 case FB_EVENT_SUSPEND
:
3014 fbcon_suspended(info
);
3016 case FB_EVENT_RESUME
:
3017 fbcon_resumed(info
);
3019 case FB_EVENT_MODE_CHANGE
:
3020 fbcon_modechanged(info
);
3022 case FB_EVENT_MODE_CHANGE_ALL
:
3023 fbcon_set_all_vcs(info
);
3025 case FB_EVENT_MODE_DELETE
:
3027 ret
= fbcon_mode_deleted(info
, mode
);
3029 case FB_EVENT_FB_REGISTERED
:
3030 ret
= fbcon_fb_registered(info
->node
);
3032 case FB_EVENT_FB_UNREGISTERED
:
3033 ret
= fbcon_fb_unregistered(info
->node
);
3035 case FB_EVENT_SET_CONSOLE_MAP
:
3036 con2fb
= event
->data
;
3037 ret
= set_con2fb_map(con2fb
->console
- 1,
3038 con2fb
->framebuffer
, 1);
3040 case FB_EVENT_GET_CONSOLE_MAP
:
3041 con2fb
= event
->data
;
3042 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3044 case FB_EVENT_BLANK
:
3045 fbcon_fb_blanked(info
, *(int *)event
->data
);
3047 case FB_EVENT_NEW_MODELIST
:
3048 fbcon_new_modelist(info
);
3057 * The console `switch' structure for the frame buffer based console
3060 static const struct consw fb_con
= {
3061 .owner
= THIS_MODULE
,
3062 .con_startup
= fbcon_startup
,
3063 .con_init
= fbcon_init
,
3064 .con_deinit
= fbcon_deinit
,
3065 .con_clear
= fbcon_clear
,
3066 .con_putc
= fbcon_putc
,
3067 .con_putcs
= fbcon_putcs
,
3068 .con_cursor
= fbcon_cursor
,
3069 .con_scroll
= fbcon_scroll
,
3070 .con_bmove
= fbcon_bmove
,
3071 .con_switch
= fbcon_switch
,
3072 .con_blank
= fbcon_blank
,
3073 .con_font_set
= fbcon_set_font
,
3074 .con_font_get
= fbcon_get_font
,
3075 .con_font_default
= fbcon_set_def_font
,
3076 .con_font_copy
= fbcon_copy_font
,
3077 .con_set_palette
= fbcon_set_palette
,
3078 .con_scrolldelta
= fbcon_scrolldelta
,
3079 .con_set_origin
= fbcon_set_origin
,
3080 .con_invert_region
= fbcon_invert_region
,
3081 .con_screen_pos
= fbcon_screen_pos
,
3082 .con_getxy
= fbcon_getxy
,
3083 .con_resize
= fbcon_resize
,
3086 static struct notifier_block fbcon_event_notifier
= {
3087 .notifier_call
= fbcon_event_notify
,
3090 static ssize_t
store_rotate(struct class_device
*class_device
,
3091 const char *buf
, size_t count
)
3093 struct fb_info
*info
;
3097 if (fbcon_has_exited
)
3100 acquire_console_sem();
3101 idx
= con2fb_map
[fg_console
];
3103 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3106 info
= registered_fb
[idx
];
3107 rotate
= simple_strtoul(buf
, last
, 0);
3108 fbcon_rotate(info
, rotate
);
3110 release_console_sem();
3114 static ssize_t
store_rotate_all(struct class_device
*class_device
,
3115 const char *buf
, size_t count
)
3117 struct fb_info
*info
;
3121 if (fbcon_has_exited
)
3124 acquire_console_sem();
3125 idx
= con2fb_map
[fg_console
];
3127 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3130 info
= registered_fb
[idx
];
3131 rotate
= simple_strtoul(buf
, last
, 0);
3132 fbcon_rotate_all(info
, rotate
);
3134 release_console_sem();
3138 static ssize_t
show_rotate(struct class_device
*class_device
, char *buf
)
3140 struct fb_info
*info
;
3141 int rotate
= 0, idx
;
3143 if (fbcon_has_exited
)
3146 acquire_console_sem();
3147 idx
= con2fb_map
[fg_console
];
3149 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3152 info
= registered_fb
[idx
];
3153 rotate
= fbcon_get_rotate(info
);
3155 release_console_sem();
3156 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3159 static struct class_device_attribute class_device_attrs
[] = {
3160 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3161 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3164 static int fbcon_init_class_device(void)
3168 for (i
= 0; i
< ARRAY_SIZE(class_device_attrs
); i
++)
3169 class_device_create_file(fbcon_class_device
,
3170 &class_device_attrs
[i
]);
3174 static void fbcon_start(void)
3176 if (num_registered_fb
) {
3179 acquire_console_sem();
3181 for (i
= 0; i
< FB_MAX
; i
++) {
3182 if (registered_fb
[i
] != NULL
) {
3188 release_console_sem();
3193 static void fbcon_exit(void)
3195 struct fb_info
*info
;
3198 if (fbcon_has_exited
)
3202 free_irq(IRQ_AUTO_4
, fbcon_vbl_handler
);
3205 if (MACH_IS_MAC
&& vbl_detected
)
3206 free_irq(IRQ_MAC_VBL
, fbcon_vbl_handler
);
3209 kfree((void *)softback_buf
);
3212 for (i
= 0; i
< FB_MAX
; i
++) {
3214 info
= registered_fb
[i
];
3219 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3220 if (con2fb_map
[j
] == i
)
3225 if (info
->fbops
->fb_release
)
3226 info
->fbops
->fb_release(info
, 0);
3227 module_put(info
->fbops
->owner
);
3229 if (info
->fbcon_par
) {
3230 fbcon_del_cursor_timer(info
);
3231 kfree(info
->fbcon_par
);
3232 info
->fbcon_par
= NULL
;
3235 if (info
->queue
.func
== fb_flashcursor
)
3236 info
->queue
.func
= NULL
;
3240 fbcon_has_exited
= 1;
3243 static int __init
fb_console_init(void)
3247 acquire_console_sem();
3248 fb_register_client(&fbcon_event_notifier
);
3249 fbcon_class_device
=
3250 class_device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
, "fbcon");
3252 if (IS_ERR(fbcon_class_device
)) {
3253 printk(KERN_WARNING
"Unable to create class_device "
3254 "for fbcon; errno = %ld\n",
3255 PTR_ERR(fbcon_class_device
));
3256 fbcon_class_device
= NULL
;
3258 fbcon_init_class_device();
3260 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3263 release_console_sem();
3268 module_init(fb_console_init
);
3272 static void __exit
fbcon_deinit_class_device(void)
3276 for (i
= 0; i
< ARRAY_SIZE(class_device_attrs
); i
++)
3277 class_device_remove_file(fbcon_class_device
,
3278 &class_device_attrs
[i
]);
3281 static void __exit
fb_console_exit(void)
3283 acquire_console_sem();
3284 fb_unregister_client(&fbcon_event_notifier
);
3285 fbcon_deinit_class_device();
3286 class_device_destroy(fb_class
, MKDEV(0, 0));
3288 release_console_sem();
3289 unregister_con_driver(&fb_con
);
3292 module_exit(fb_console_exit
);
3296 MODULE_LICENSE("GPL");