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>
63 #include <linux/sched.h>
65 #include <linux/kernel.h>
66 #include <linux/delay.h> /* MSch: for IRQ probe */
67 #include <linux/console.h>
68 #include <linux/string.h>
70 #include <linux/slab.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
80 #include <asm/system.h>
81 #include <asm/uaccess.h>
83 #include <asm/atariints.h>
86 #include <asm/macints.h>
88 #if defined(__mc68000__) || defined(CONFIG_APUS)
89 #include <asm/machdep.h>
90 #include <asm/setup.h>
96 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
98 # define DPRINTK(fmt, args...)
102 FBCON_LOGO_CANSHOW
= -1, /* the logo can be shown */
103 FBCON_LOGO_DRAW
= -2, /* draw the logo to a console */
104 FBCON_LOGO_DONTSHOW
= -3 /* do not show the logo */
107 static struct display fb_display
[MAX_NR_CONSOLES
];
109 static signed char con2fb_map
[MAX_NR_CONSOLES
];
110 static signed char con2fb_map_boot
[MAX_NR_CONSOLES
];
111 static int logo_height
;
112 static int logo_lines
;
113 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
115 static int logo_shown
= FBCON_LOGO_CANSHOW
;
116 /* Software scrollback */
117 static int fbcon_softback_size
= 32768;
118 static unsigned long softback_buf
, softback_curr
;
119 static unsigned long softback_in
;
120 static unsigned long softback_top
, softback_end
;
121 static int softback_lines
;
122 /* console mappings */
123 static int first_fb_vc
;
124 static int last_fb_vc
= MAX_NR_CONSOLES
- 1;
125 static int fbcon_is_default
= 1;
126 static int fbcon_has_exited
;
129 static char fontname
[40];
131 /* current fb_info */
132 static int info_idx
= -1;
134 /* console rotation */
137 static const struct consw fb_con
;
139 #define CM_SOFTBACK (8)
141 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
143 static int fbcon_set_origin(struct vc_data
*);
145 #define CURSOR_DRAW_DELAY (1)
147 /* # VBL ints between cursor state changes */
148 #define ATARI_CURSOR_BLINK_RATE (42)
149 #define MAC_CURSOR_BLINK_RATE (32)
150 #define DEFAULT_CURSOR_BLINK_RATE (20)
152 static int vbl_cursor_cnt
;
154 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
157 * Interface used by the world
160 static const char *fbcon_startup(void);
161 static void fbcon_init(struct vc_data
*vc
, int init
);
162 static void fbcon_deinit(struct vc_data
*vc
);
163 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
165 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
);
166 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
167 int count
, int ypos
, int xpos
);
168 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
);
169 static void fbcon_cursor(struct vc_data
*vc
, int mode
);
170 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
172 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
173 int height
, int width
);
174 static int fbcon_switch(struct vc_data
*vc
);
175 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
);
176 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
);
177 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
);
182 static __inline__
void ywrap_up(struct vc_data
*vc
, int count
);
183 static __inline__
void ywrap_down(struct vc_data
*vc
, int count
);
184 static __inline__
void ypan_up(struct vc_data
*vc
, int count
);
185 static __inline__
void ypan_down(struct vc_data
*vc
, int count
);
186 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
187 int dy
, int dx
, int height
, int width
, u_int y_break
);
188 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
190 static void fbcon_preset_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
192 static void fbcon_redraw_move(struct vc_data
*vc
, struct display
*p
,
193 int line
, int count
, int dy
);
194 static void fbcon_modechanged(struct fb_info
*info
);
195 static void fbcon_set_all_vcs(struct fb_info
*info
);
196 static void fbcon_start(void);
197 static void fbcon_exit(void);
198 static struct class_device
*fbcon_class_device
;
202 * On the Macintoy, there may or may not be a working VBL int. We need to probe
204 static int vbl_detected
;
206 static irqreturn_t
fb_vbl_detect(int irq
, void *dummy
, struct pt_regs
*fp
)
213 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
214 static inline void fbcon_set_rotation(struct fb_info
*info
)
216 struct fbcon_ops
*ops
= info
->fbcon_par
;
218 if (!(info
->flags
& FBINFO_MISC_TILEBLITTING
) &&
219 ops
->p
->con_rotate
< 4)
220 ops
->rotate
= ops
->p
->con_rotate
;
225 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
227 struct fbcon_ops
*ops
= info
->fbcon_par
;
228 struct fb_info
*fb_info
;
230 if (!ops
|| ops
->currcon
== -1)
233 fb_info
= registered_fb
[con2fb_map
[ops
->currcon
]];
235 if (info
== fb_info
) {
236 struct display
*p
= &fb_display
[ops
->currcon
];
239 p
->con_rotate
= rotate
;
243 fbcon_modechanged(info
);
247 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
249 struct fbcon_ops
*ops
= info
->fbcon_par
;
254 if (!ops
|| ops
->currcon
< 0 || rotate
> 3)
257 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
259 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
260 registered_fb
[con2fb_map
[i
]] != info
)
263 p
= &fb_display
[vc
->vc_num
];
264 p
->con_rotate
= rotate
;
267 fbcon_set_all_vcs(info
);
270 static inline void fbcon_set_rotation(struct fb_info
*info
)
272 struct fbcon_ops
*ops
= info
->fbcon_par
;
274 ops
->rotate
= FB_ROTATE_UR
;
277 static void fbcon_rotate(struct fb_info
*info
, u32 rotate
)
282 static void fbcon_rotate_all(struct fb_info
*info
, u32 rotate
)
286 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
288 static int fbcon_get_rotate(struct fb_info
*info
)
290 struct fbcon_ops
*ops
= info
->fbcon_par
;
292 return (ops
) ? ops
->rotate
: 0;
295 static inline int fbcon_is_inactive(struct vc_data
*vc
, struct fb_info
*info
)
297 struct fbcon_ops
*ops
= info
->fbcon_par
;
299 return (info
->state
!= FBINFO_STATE_RUNNING
||
300 vc
->vc_mode
!= KD_TEXT
|| ops
->graphics
);
303 static inline int get_color(struct vc_data
*vc
, struct fb_info
*info
,
306 int depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
309 if (console_blanked
) {
310 unsigned short charmask
= vc
->vc_hi_font_mask
? 0x1ff : 0xff;
312 c
= vc
->vc_video_erase_char
& charmask
;
316 color
= (is_fg
) ? attr_fgcol((vc
->vc_hi_font_mask
) ? 9 : 8, c
)
317 : attr_bgcol((vc
->vc_hi_font_mask
) ? 13 : 12, c
);
322 int col
= ~(0xfff << (max(info
->var
.green
.length
,
323 max(info
->var
.red
.length
,
324 info
->var
.blue
.length
)))) & 0xff;
327 int fg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? col
: 0;
328 int bg
= (info
->fix
.visual
!= FB_VISUAL_MONO01
) ? 0 : col
;
333 color
= (is_fg
) ? fg
: bg
;
338 * Scale down 16-colors to 4 colors. Default 4-color palette
339 * is grayscale. However, simply dividing the values by 4
340 * will not work, as colors 1, 2 and 3 will be scaled-down
341 * to zero rendering them invisible. So empirically convert
342 * colors to a sane 4-level grayscale.
346 color
= 0; /* black */
349 color
= 2; /* white */
352 color
= 1; /* gray */
355 color
= 3; /* intense white */
361 * Last 8 entries of default 16-color palette is a more intense
362 * version of the first 8 (i.e., same chrominance, different
373 static void fbcon_update_softback(struct vc_data
*vc
)
375 int l
= fbcon_softback_size
/ vc
->vc_size_row
;
378 softback_end
= softback_buf
+ l
* vc
->vc_size_row
;
380 /* Smaller scrollback makes no sense, and 0 would screw
381 the operation totally */
385 static void fb_flashcursor(void *private)
387 struct fb_info
*info
= private;
388 struct fbcon_ops
*ops
= info
->fbcon_par
;
390 struct vc_data
*vc
= NULL
;
394 acquire_console_sem();
395 if (ops
&& ops
->currcon
!= -1)
396 vc
= vc_cons
[ops
->currcon
].d
;
398 if (!vc
|| !CON_IS_VISIBLE(vc
) ||
399 fbcon_is_inactive(vc
, info
) ||
400 registered_fb
[con2fb_map
[vc
->vc_num
]] != info
||
401 vc_cons
[ops
->currcon
].d
->vc_deccm
!= 1) {
402 release_console_sem();
406 p
= &fb_display
[vc
->vc_num
];
407 c
= scr_readw((u16
*) vc
->vc_pos
);
408 mode
= (!ops
->cursor_flash
|| ops
->cursor_state
.enable
) ?
410 ops
->cursor(vc
, info
, mode
, softback_lines
, get_color(vc
, info
, c
, 1),
411 get_color(vc
, info
, c
, 0));
412 release_console_sem();
415 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
416 static int cursor_blink_rate
;
417 static irqreturn_t
fb_vbl_handler(int irq
, void *dev_id
, struct pt_regs
*fp
)
419 struct fb_info
*info
= dev_id
;
421 if (vbl_cursor_cnt
&& --vbl_cursor_cnt
== 0) {
422 schedule_work(&info
->queue
);
423 vbl_cursor_cnt
= cursor_blink_rate
;
429 static void cursor_timer_handler(unsigned long dev_addr
)
431 struct fb_info
*info
= (struct fb_info
*) dev_addr
;
432 struct fbcon_ops
*ops
= info
->fbcon_par
;
434 schedule_work(&info
->queue
);
435 mod_timer(&ops
->cursor_timer
, jiffies
+ HZ
/5);
438 static void fbcon_add_cursor_timer(struct fb_info
*info
)
440 struct fbcon_ops
*ops
= info
->fbcon_par
;
442 if ((!info
->queue
.func
|| info
->queue
.func
== fb_flashcursor
) &&
443 !(ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
)) {
444 if (!info
->queue
.func
)
445 INIT_WORK(&info
->queue
, fb_flashcursor
, info
);
447 init_timer(&ops
->cursor_timer
);
448 ops
->cursor_timer
.function
= cursor_timer_handler
;
449 ops
->cursor_timer
.expires
= jiffies
+ HZ
/ 5;
450 ops
->cursor_timer
.data
= (unsigned long ) info
;
451 add_timer(&ops
->cursor_timer
);
452 ops
->flags
|= FBCON_FLAGS_CURSOR_TIMER
;
456 static void fbcon_del_cursor_timer(struct fb_info
*info
)
458 struct fbcon_ops
*ops
= info
->fbcon_par
;
460 if (info
->queue
.func
== fb_flashcursor
&&
461 ops
->flags
& FBCON_FLAGS_CURSOR_TIMER
) {
462 del_timer_sync(&ops
->cursor_timer
);
463 ops
->flags
&= ~FBCON_FLAGS_CURSOR_TIMER
;
468 static int __init
fb_console_setup(char *this_opt
)
473 if (!this_opt
|| !*this_opt
)
476 while ((options
= strsep(&this_opt
, ",")) != NULL
) {
477 if (!strncmp(options
, "font:", 5))
478 strcpy(fontname
, options
+ 5);
480 if (!strncmp(options
, "scrollback:", 11)) {
483 fbcon_softback_size
= simple_strtoul(options
, &options
, 0);
484 if (*options
== 'k' || *options
== 'K') {
485 fbcon_softback_size
*= 1024;
495 if (!strncmp(options
, "map:", 4)) {
498 for (i
= 0, j
= 0; i
< MAX_NR_CONSOLES
; i
++) {
502 (options
[j
++]-'0') % FB_MAX
;
507 if (!strncmp(options
, "vc:", 3)) {
510 first_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
513 if (*options
++ == '-')
514 last_fb_vc
= simple_strtoul(options
, &options
, 10) - 1;
515 fbcon_is_default
= 0;
518 if (!strncmp(options
, "rotate:", 7)) {
521 rotate
= simple_strtoul(options
, &options
, 0);
529 __setup("fbcon=", fb_console_setup
);
532 static int search_fb_in_map(int idx
)
536 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
537 if (con2fb_map
[i
] == idx
)
543 static int search_for_mapped_con(void)
547 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
548 if (con2fb_map
[i
] != -1)
554 static int fbcon_takeover(int show_logo
)
558 if (!num_registered_fb
)
562 logo_shown
= FBCON_LOGO_DONTSHOW
;
564 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++)
565 con2fb_map
[i
] = info_idx
;
567 err
= take_over_console(&fb_con
, first_fb_vc
, last_fb_vc
,
571 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
580 static void fbcon_prepare_logo(struct vc_data
*vc
, struct fb_info
*info
,
581 int cols
, int rows
, int new_cols
, int new_rows
)
583 /* Need to make room for the logo */
584 struct fbcon_ops
*ops
= info
->fbcon_par
;
585 int cnt
, erase
= vc
->vc_video_erase_char
, step
;
586 unsigned short *save
= NULL
, *r
, *q
;
589 * remove underline attribute from erase character
590 * if black and white framebuffer.
592 if (fb_get_color_depth(&info
->var
, &info
->fix
) == 1)
594 logo_height
= fb_prepare_logo(info
, ops
->rotate
);
595 logo_lines
= (logo_height
+ vc
->vc_font
.height
- 1) /
597 q
= (unsigned short *) (vc
->vc_origin
+
598 vc
->vc_size_row
* rows
);
599 step
= logo_lines
* cols
;
600 for (r
= q
- logo_lines
* cols
; r
< q
; r
++)
601 if (scr_readw(r
) != vc
->vc_video_erase_char
)
603 if (r
!= q
&& new_rows
>= rows
+ logo_lines
) {
604 save
= kmalloc(logo_lines
* new_cols
* 2, GFP_KERNEL
);
606 int i
= cols
< new_cols
? cols
: new_cols
;
607 scr_memsetw(save
, erase
, logo_lines
* new_cols
* 2);
609 for (cnt
= 0; cnt
< logo_lines
; cnt
++, r
+= i
)
610 scr_memcpyw(save
+ cnt
* new_cols
, r
, 2 * i
);
615 /* We can scroll screen down */
617 for (cnt
= rows
- logo_lines
; cnt
> 0; cnt
--) {
618 scr_memcpyw(r
+ step
, r
, vc
->vc_size_row
);
622 vc
->vc_y
+= logo_lines
;
623 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
626 scr_memsetw((unsigned short *) vc
->vc_origin
,
628 vc
->vc_size_row
* logo_lines
);
630 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
631 fbcon_clear_margins(vc
, 0);
636 q
= (unsigned short *) (vc
->vc_origin
+
639 scr_memcpyw(q
, save
, logo_lines
* new_cols
* 2);
640 vc
->vc_y
+= logo_lines
;
641 vc
->vc_pos
+= logo_lines
* vc
->vc_size_row
;
645 if (logo_lines
> vc
->vc_bottom
) {
646 logo_shown
= FBCON_LOGO_CANSHOW
;
648 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
649 } else if (logo_shown
!= FBCON_LOGO_DONTSHOW
) {
650 logo_shown
= FBCON_LOGO_DRAW
;
651 vc
->vc_top
= logo_lines
;
655 #ifdef CONFIG_FB_TILEBLITTING
656 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
658 struct fbcon_ops
*ops
= info
->fbcon_par
;
660 ops
->p
= &fb_display
[vc
->vc_num
];
662 if ((info
->flags
& FBINFO_MISC_TILEBLITTING
))
663 fbcon_set_tileops(vc
, info
);
665 fbcon_set_rotation(info
);
666 fbcon_set_bitops(ops
);
670 static void set_blitting_type(struct vc_data
*vc
, struct fb_info
*info
)
672 struct fbcon_ops
*ops
= info
->fbcon_par
;
674 info
->flags
&= ~FBINFO_MISC_TILEBLITTING
;
675 ops
->p
= &fb_display
[vc
->vc_num
];
676 fbcon_set_rotation(info
);
677 fbcon_set_bitops(ops
);
679 #endif /* CONFIG_MISC_TILEBLITTING */
682 static int con2fb_acquire_newinfo(struct vc_data
*vc
, struct fb_info
*info
,
683 int unit
, int oldidx
)
685 struct fbcon_ops
*ops
= NULL
;
688 if (!try_module_get(info
->fbops
->owner
))
691 if (!err
&& info
->fbops
->fb_open
&&
692 info
->fbops
->fb_open(info
, 0))
696 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
702 info
->fbcon_par
= ops
;
703 set_blitting_type(vc
, info
);
707 con2fb_map
[unit
] = oldidx
;
708 module_put(info
->fbops
->owner
);
714 static int con2fb_release_oldinfo(struct vc_data
*vc
, struct fb_info
*oldinfo
,
715 struct fb_info
*newinfo
, int unit
,
716 int oldidx
, int found
)
718 struct fbcon_ops
*ops
= oldinfo
->fbcon_par
;
721 if (oldinfo
->fbops
->fb_release
&&
722 oldinfo
->fbops
->fb_release(oldinfo
, 0)) {
723 con2fb_map
[unit
] = oldidx
;
724 if (!found
&& newinfo
->fbops
->fb_release
)
725 newinfo
->fbops
->fb_release(newinfo
, 0);
727 module_put(newinfo
->fbops
->owner
);
732 fbcon_del_cursor_timer(oldinfo
);
733 kfree(ops
->cursor_state
.mask
);
734 kfree(ops
->cursor_data
);
735 kfree(ops
->fontbuffer
);
736 kfree(oldinfo
->fbcon_par
);
737 oldinfo
->fbcon_par
= NULL
;
738 module_put(oldinfo
->fbops
->owner
);
740 If oldinfo and newinfo are driving the same hardware,
741 the fb_release() method of oldinfo may attempt to
742 restore the hardware state. This will leave the
743 newinfo in an undefined state. Thus, a call to
744 fb_set_par() may be needed for the newinfo.
746 if (newinfo
->fbops
->fb_set_par
)
747 newinfo
->fbops
->fb_set_par(newinfo
);
753 static void con2fb_init_display(struct vc_data
*vc
, struct fb_info
*info
,
754 int unit
, int show_logo
)
756 struct fbcon_ops
*ops
= info
->fbcon_par
;
758 ops
->currcon
= fg_console
;
760 if (info
->fbops
->fb_set_par
&& !(ops
->flags
& FBCON_FLAGS_INIT
))
761 info
->fbops
->fb_set_par(info
);
763 ops
->flags
|= FBCON_FLAGS_INIT
;
767 fbcon_set_disp(info
, &info
->var
, vc
);
769 fbcon_preset_disp(info
, &info
->var
, unit
);
772 struct vc_data
*fg_vc
= vc_cons
[fg_console
].d
;
773 struct fb_info
*fg_info
=
774 registered_fb
[con2fb_map
[fg_console
]];
776 fbcon_prepare_logo(fg_vc
, fg_info
, fg_vc
->vc_cols
,
777 fg_vc
->vc_rows
, fg_vc
->vc_cols
,
781 update_screen(vc_cons
[fg_console
].d
);
785 * set_con2fb_map - map console to frame buffer device
786 * @unit: virtual console number to map
787 * @newidx: frame buffer index to map virtual console to
788 * @user: user request
790 * Maps a virtual console @unit to a frame buffer device
793 static int set_con2fb_map(int unit
, int newidx
, int user
)
795 struct vc_data
*vc
= vc_cons
[unit
].d
;
796 int oldidx
= con2fb_map
[unit
];
797 struct fb_info
*info
= registered_fb
[newidx
];
798 struct fb_info
*oldinfo
= NULL
;
801 if (oldidx
== newidx
)
804 if (!info
|| fbcon_has_exited
)
807 if (!err
&& !search_for_mapped_con()) {
809 return fbcon_takeover(0);
813 oldinfo
= registered_fb
[oldidx
];
815 found
= search_fb_in_map(newidx
);
817 acquire_console_sem();
818 con2fb_map
[unit
] = newidx
;
820 err
= con2fb_acquire_newinfo(vc
, info
, unit
, oldidx
);
824 * If old fb is not mapped to any of the consoles,
825 * fbcon should release it.
827 if (!err
&& oldinfo
&& !search_fb_in_map(oldidx
))
828 err
= con2fb_release_oldinfo(vc
, oldinfo
, info
, unit
, oldidx
,
832 int show_logo
= (fg_console
== 0 && !user
&&
833 logo_shown
!= FBCON_LOGO_DONTSHOW
);
836 fbcon_add_cursor_timer(info
);
837 con2fb_map_boot
[unit
] = newidx
;
838 con2fb_init_display(vc
, info
, unit
, show_logo
);
841 if (!search_fb_in_map(info_idx
))
844 release_console_sem();
849 * Low Level Operations
851 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
852 static int var_to_display(struct display
*disp
,
853 struct fb_var_screeninfo
*var
,
854 struct fb_info
*info
)
856 disp
->xres_virtual
= var
->xres_virtual
;
857 disp
->yres_virtual
= var
->yres_virtual
;
858 disp
->bits_per_pixel
= var
->bits_per_pixel
;
859 disp
->grayscale
= var
->grayscale
;
860 disp
->nonstd
= var
->nonstd
;
861 disp
->accel_flags
= var
->accel_flags
;
862 disp
->height
= var
->height
;
863 disp
->width
= var
->width
;
864 disp
->red
= var
->red
;
865 disp
->green
= var
->green
;
866 disp
->blue
= var
->blue
;
867 disp
->transp
= var
->transp
;
868 disp
->rotate
= var
->rotate
;
869 disp
->mode
= fb_match_mode(var
, &info
->modelist
);
870 if (disp
->mode
== NULL
)
871 /* This should not happen */
876 static void display_to_var(struct fb_var_screeninfo
*var
,
877 struct display
*disp
)
879 fb_videomode_to_var(var
, disp
->mode
);
880 var
->xres_virtual
= disp
->xres_virtual
;
881 var
->yres_virtual
= disp
->yres_virtual
;
882 var
->bits_per_pixel
= disp
->bits_per_pixel
;
883 var
->grayscale
= disp
->grayscale
;
884 var
->nonstd
= disp
->nonstd
;
885 var
->accel_flags
= disp
->accel_flags
;
886 var
->height
= disp
->height
;
887 var
->width
= disp
->width
;
888 var
->red
= disp
->red
;
889 var
->green
= disp
->green
;
890 var
->blue
= disp
->blue
;
891 var
->transp
= disp
->transp
;
892 var
->rotate
= disp
->rotate
;
895 static const char *fbcon_startup(void)
897 const char *display_desc
= "frame buffer device";
898 struct display
*p
= &fb_display
[fg_console
];
899 struct vc_data
*vc
= vc_cons
[fg_console
].d
;
900 const struct font_desc
*font
= NULL
;
901 struct module
*owner
;
902 struct fb_info
*info
= NULL
;
903 struct fbcon_ops
*ops
;
909 * If num_registered_fb is zero, this is a call for the dummy part.
910 * The frame buffer devices weren't initialized yet.
912 if (!num_registered_fb
|| info_idx
== -1)
915 * Instead of blindly using registered_fb[0], we use info_idx, set by
918 info
= registered_fb
[info_idx
];
922 owner
= info
->fbops
->owner
;
923 if (!try_module_get(owner
))
925 if (info
->fbops
->fb_open
&& info
->fbops
->fb_open(info
, 0)) {
930 ops
= kzalloc(sizeof(struct fbcon_ops
), GFP_KERNEL
);
938 ops
->cur_rotate
= -1;
939 info
->fbcon_par
= ops
;
940 p
->con_rotate
= rotate
;
941 set_blitting_type(vc
, info
);
943 if (info
->fix
.type
!= FB_TYPE_TEXT
) {
944 if (fbcon_softback_size
) {
948 kmalloc(fbcon_softback_size
,
951 fbcon_softback_size
= 0;
957 kfree((void *) softback_buf
);
963 softback_in
= softback_top
= softback_curr
=
968 /* Setup default font */
970 if (!fontname
[0] || !(font
= find_font(fontname
)))
971 font
= get_default_font(info
->var
.xres
,
973 vc
->vc_font
.width
= font
->width
;
974 vc
->vc_font
.height
= font
->height
;
975 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
976 vc
->vc_font
.charcount
= 256; /* FIXME Need to support more fonts */
979 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
980 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
981 cols
/= vc
->vc_font
.width
;
982 rows
/= vc
->vc_font
.height
;
983 vc_resize(vc
, cols
, rows
);
985 DPRINTK("mode: %s\n", info
->fix
.id
);
986 DPRINTK("visual: %d\n", info
->fix
.visual
);
987 DPRINTK("res: %dx%d-%d\n", info
->var
.xres
,
989 info
->var
.bits_per_pixel
);
993 cursor_blink_rate
= ATARI_CURSOR_BLINK_RATE
;
995 request_irq(IRQ_AUTO_4
, fb_vbl_handler
,
996 IRQ_TYPE_PRIO
, "framebuffer vbl",
999 #endif /* CONFIG_ATARI */
1003 * On a Macintoy, the VBL interrupt may or may not be active.
1004 * As interrupt based cursor is more reliable and race free, we
1005 * probe for VBL interrupts.
1010 * Probe for VBL: set temp. handler ...
1012 irqres
= request_irq(IRQ_MAC_VBL
, fb_vbl_detect
, 0,
1013 "framebuffer vbl", info
);
1017 * ... and spin for 20 ms ...
1019 while (!vbl_detected
&& ++ct
< 1000)
1024 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1026 free_irq(IRQ_MAC_VBL
, fb_vbl_detect
);
1030 * interrupt based cursor ok
1032 cursor_blink_rate
= MAC_CURSOR_BLINK_RATE
;
1034 request_irq(IRQ_MAC_VBL
, fb_vbl_handler
, 0,
1035 "framebuffer vbl", info
);
1038 * VBL not detected: fall through, use timer based cursor
1043 #endif /* CONFIG_MAC */
1045 fbcon_add_cursor_timer(info
);
1046 fbcon_has_exited
= 0;
1047 return display_desc
;
1050 static void fbcon_init(struct vc_data
*vc
, int init
)
1052 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1053 struct fbcon_ops
*ops
;
1054 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1055 struct vc_data
*svc
= *default_mode
;
1056 struct display
*t
, *p
= &fb_display
[vc
->vc_num
];
1057 int logo
= 1, new_rows
, new_cols
, rows
, cols
, charcnt
= 256;
1060 if (info_idx
== -1 || info
== NULL
)
1065 if (vc
!= svc
|| logo_shown
== FBCON_LOGO_DONTSHOW
||
1066 (info
->fix
.type
== FB_TYPE_TEXT
))
1069 if (var_to_display(p
, &info
->var
, info
))
1072 /* If we are not the first console on this
1073 fb, copy the font from that console */
1074 t
= &fb_display
[fg_console
];
1077 struct vc_data
*fvc
= vc_cons
[fg_console
].d
;
1079 vc
->vc_font
.data
= (void *)(p
->fontdata
=
1081 vc
->vc_font
.width
= fvc
->vc_font
.width
;
1082 vc
->vc_font
.height
= fvc
->vc_font
.height
;
1083 p
->userfont
= t
->userfont
;
1086 REFCOUNT(p
->fontdata
)++;
1088 const struct font_desc
*font
= NULL
;
1090 if (!fontname
[0] || !(font
= find_font(fontname
)))
1091 font
= get_default_font(info
->var
.xres
,
1093 vc
->vc_font
.width
= font
->width
;
1094 vc
->vc_font
.height
= font
->height
;
1095 vc
->vc_font
.data
= (void *)(p
->fontdata
= font
->data
);
1096 vc
->vc_font
.charcount
= 256; /* FIXME Need to
1097 support more fonts */
1102 charcnt
= FNTCHARCNT(p
->fontdata
);
1104 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
1105 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
1106 if (charcnt
== 256) {
1107 vc
->vc_hi_font_mask
= 0;
1109 vc
->vc_hi_font_mask
= 0x100;
1110 if (vc
->vc_can_do_color
)
1111 vc
->vc_complement_mask
<<= 1;
1114 if (!*svc
->vc_uni_pagedir_loc
)
1115 con_set_default_unimap(svc
);
1116 if (!*vc
->vc_uni_pagedir_loc
)
1117 con_copy_unimap(vc
, svc
);
1119 ops
= info
->fbcon_par
;
1120 p
->con_rotate
= rotate
;
1121 set_blitting_type(vc
, info
);
1125 new_cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
1126 new_rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
1127 new_cols
/= vc
->vc_font
.width
;
1128 new_rows
/= vc
->vc_font
.height
;
1129 vc_resize(vc
, new_cols
, new_rows
);
1132 * We must always set the mode. The mode of the previous console
1133 * driver could be in the same resolution but we are using different
1134 * hardware so we have to initialize the hardware.
1136 * We need to do it in fbcon_init() to prevent screen corruption.
1138 if (CON_IS_VISIBLE(vc
) && vc
->vc_mode
== KD_TEXT
) {
1139 if (info
->fbops
->fb_set_par
&&
1140 !(ops
->flags
& FBCON_FLAGS_INIT
))
1141 info
->fbops
->fb_set_par(info
);
1142 ops
->flags
|= FBCON_FLAGS_INIT
;
1147 if ((cap
& FBINFO_HWACCEL_COPYAREA
) &&
1148 !(cap
& FBINFO_HWACCEL_DISABLED
))
1149 p
->scrollmode
= SCROLL_MOVE
;
1150 else /* default to something safe */
1151 p
->scrollmode
= SCROLL_REDRAW
;
1154 * ++guenther: console.c:vc_allocate() relies on initializing
1155 * vc_{cols,rows}, but we must not set those if we are only
1156 * resizing the console.
1159 vc
->vc_cols
= new_cols
;
1160 vc
->vc_rows
= new_rows
;
1164 fbcon_prepare_logo(vc
, info
, cols
, rows
, new_cols
, new_rows
);
1166 if (vc
== svc
&& softback_buf
)
1167 fbcon_update_softback(vc
);
1169 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
1170 ops
->rotate
= FB_ROTATE_UR
;
1171 set_blitting_type(vc
, info
);
1174 ops
->p
= &fb_display
[fg_console
];
1177 static void fbcon_free_font(struct display
*p
)
1179 if (p
->userfont
&& p
->fontdata
&& (--REFCOUNT(p
->fontdata
) == 0))
1180 kfree(p
->fontdata
- FONT_EXTRA_WORDS
* sizeof(int));
1185 static void fbcon_deinit(struct vc_data
*vc
)
1187 struct display
*p
= &fb_display
[vc
->vc_num
];
1188 struct fb_info
*info
;
1189 struct fbcon_ops
*ops
;
1193 idx
= con2fb_map
[vc
->vc_num
];
1198 info
= registered_fb
[idx
];
1203 ops
= info
->fbcon_par
;
1208 if (CON_IS_VISIBLE(vc
))
1209 fbcon_del_cursor_timer(info
);
1211 ops
->flags
&= ~FBCON_FLAGS_INIT
;
1214 if (!con_is_bound(&fb_con
))
1220 /* ====================================================================== */
1222 /* fbcon_XXX routines - interface used by the world
1224 * This system is now divided into two levels because of complications
1225 * caused by hardware scrolling. Top level functions:
1227 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1229 * handles y values in range [0, scr_height-1] that correspond to real
1230 * screen positions. y_wrap shift means that first line of bitmap may be
1231 * anywhere on this display. These functions convert lineoffsets to
1232 * bitmap offsets and deal with the wrap-around case by splitting blits.
1234 * fbcon_bmove_physical_8() -- These functions fast implementations
1235 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1236 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1240 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1241 * Implies should only really hardware scroll in rows. Only reason for
1242 * restriction is simplicity & efficiency at the moment.
1245 static void fbcon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
1248 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1249 struct fbcon_ops
*ops
= info
->fbcon_par
;
1251 struct display
*p
= &fb_display
[vc
->vc_num
];
1254 if (fbcon_is_inactive(vc
, info
))
1257 if (!height
|| !width
)
1260 /* Split blits that cross physical y_wrap boundary */
1262 y_break
= p
->vrows
- p
->yscroll
;
1263 if (sy
< y_break
&& sy
+ height
- 1 >= y_break
) {
1264 u_int b
= y_break
- sy
;
1265 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, b
, width
);
1266 ops
->clear(vc
, info
, real_y(p
, sy
+ b
), sx
, height
- b
,
1269 ops
->clear(vc
, info
, real_y(p
, sy
), sx
, height
, width
);
1272 static void fbcon_putcs(struct vc_data
*vc
, const unsigned short *s
,
1273 int count
, int ypos
, int xpos
)
1275 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1276 struct display
*p
= &fb_display
[vc
->vc_num
];
1277 struct fbcon_ops
*ops
= info
->fbcon_par
;
1279 if (!fbcon_is_inactive(vc
, info
))
1280 ops
->putcs(vc
, info
, s
, count
, real_y(p
, ypos
), xpos
,
1281 get_color(vc
, info
, scr_readw(s
), 1),
1282 get_color(vc
, info
, scr_readw(s
), 0));
1285 static void fbcon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
1289 scr_writew(c
, &chr
);
1290 fbcon_putcs(vc
, &chr
, 1, ypos
, xpos
);
1293 static void fbcon_clear_margins(struct vc_data
*vc
, int bottom_only
)
1295 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1296 struct fbcon_ops
*ops
= info
->fbcon_par
;
1298 if (!fbcon_is_inactive(vc
, info
))
1299 ops
->clear_margins(vc
, info
, bottom_only
);
1302 static void fbcon_cursor(struct vc_data
*vc
, int mode
)
1304 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1305 struct fbcon_ops
*ops
= info
->fbcon_par
;
1307 int c
= scr_readw((u16
*) vc
->vc_pos
);
1309 if (fbcon_is_inactive(vc
, info
))
1312 ops
->cursor_flash
= (mode
== CM_ERASE
) ? 0 : 1;
1313 if (mode
& CM_SOFTBACK
) {
1314 mode
&= ~CM_SOFTBACK
;
1318 fbcon_set_origin(vc
);
1322 ops
->cursor(vc
, info
, mode
, y
, get_color(vc
, info
, c
, 1),
1323 get_color(vc
, info
, c
, 0));
1324 vbl_cursor_cnt
= CURSOR_DRAW_DELAY
;
1327 static int scrollback_phys_max
= 0;
1328 static int scrollback_max
= 0;
1329 static int scrollback_current
= 0;
1332 * If no vc is existent yet, just set struct display
1334 static void fbcon_preset_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1337 struct display
*p
= &fb_display
[unit
];
1338 struct display
*t
= &fb_display
[fg_console
];
1340 if (var_to_display(p
, var
, info
))
1343 p
->fontdata
= t
->fontdata
;
1344 p
->userfont
= t
->userfont
;
1346 REFCOUNT(p
->fontdata
)++;
1349 static void fbcon_set_disp(struct fb_info
*info
, struct fb_var_screeninfo
*var
,
1352 struct display
*p
= &fb_display
[vc
->vc_num
], *t
;
1353 struct vc_data
**default_mode
= vc
->vc_display_fg
;
1354 struct vc_data
*svc
= *default_mode
;
1355 struct fbcon_ops
*ops
= info
->fbcon_par
;
1356 int rows
, cols
, charcnt
= 256;
1358 if (var_to_display(p
, var
, info
))
1360 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(struct vc_data
*vc
, struct display
*p
,
1668 int line
, int count
, int offset
)
1670 unsigned short *d
= (unsigned short *)
1671 (vc
->vc_origin
+ vc
->vc_size_row
* line
);
1672 unsigned short *s
= d
+ offset
;
1675 unsigned short *start
= s
;
1676 unsigned short *le
= advance_row(s
, 1);
1679 unsigned short attr
= 1;
1683 if (attr
!= (c
& 0xff00)) {
1686 fbcon_putcs(vc
, start
, s
- start
,
1692 if (c
== scr_readw(d
)) {
1694 fbcon_putcs(vc
, start
, s
- start
,
1704 console_conditional_schedule();
1709 fbcon_putcs(vc
, start
, s
- start
, line
, x
);
1710 console_conditional_schedule();
1715 /* NOTE: We subtract two lines from these pointers */
1716 s
-= vc
->vc_size_row
;
1717 d
-= vc
->vc_size_row
;
1722 static inline void fbcon_softback_note(struct vc_data
*vc
, int t
,
1727 if (vc
->vc_num
!= fg_console
)
1729 p
= (unsigned short *) (vc
->vc_origin
+ t
* vc
->vc_size_row
);
1732 scr_memcpyw((u16
*) softback_in
, p
, vc
->vc_size_row
);
1734 p
= advance_row(p
, 1);
1735 softback_in
+= vc
->vc_size_row
;
1736 if (softback_in
== softback_end
)
1737 softback_in
= softback_buf
;
1738 if (softback_in
== softback_top
) {
1739 softback_top
+= vc
->vc_size_row
;
1740 if (softback_top
== softback_end
)
1741 softback_top
= softback_buf
;
1744 softback_curr
= softback_in
;
1747 static int fbcon_scroll(struct vc_data
*vc
, int t
, int b
, int dir
,
1750 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1751 struct display
*p
= &fb_display
[vc
->vc_num
];
1752 struct fbcon_ops
*ops
= info
->fbcon_par
;
1753 int scroll_partial
= info
->flags
& FBINFO_PARTIAL_PAN_OK
;
1755 if (fbcon_is_inactive(vc
, info
))
1758 fbcon_cursor(vc
, CM_ERASE
);
1761 * ++Geert: Only use ywrap/ypan if the console is in text mode
1762 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1763 * whole screen (prevents flicker).
1768 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1769 count
= vc
->vc_rows
;
1771 fbcon_softback_note(vc
, t
, count
);
1772 if (logo_shown
>= 0)
1774 switch (p
->scrollmode
) {
1776 ops
->bmove(vc
, info
, t
+ count
, 0, t
, 0,
1777 b
- t
- count
, vc
->vc_cols
);
1778 ops
->clear(vc
, info
, b
- count
, 0, count
,
1782 case SCROLL_WRAP_MOVE
:
1783 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1785 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1787 ywrap_up(vc
, count
);
1788 if (vc
->vc_rows
- b
> 0)
1789 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1792 } else if (info
->flags
& FBINFO_READS_FAST
)
1793 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1794 b
- t
- count
, vc
->vc_cols
);
1797 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1800 case SCROLL_PAN_REDRAW
:
1801 if ((p
->yscroll
+ count
<=
1802 2 * (p
->vrows
- vc
->vc_rows
))
1803 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1806 3 * vc
->vc_rows
>> 2)))) {
1808 fbcon_redraw_move(vc
, p
, 0, t
, count
);
1809 ypan_up_redraw(vc
, t
, count
);
1810 if (vc
->vc_rows
- b
> 0)
1811 fbcon_redraw_move(vc
, p
, b
,
1812 vc
->vc_rows
- b
, b
);
1814 fbcon_redraw_move(vc
, p
, t
+ count
, b
- t
- count
, t
);
1815 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1818 case SCROLL_PAN_MOVE
:
1819 if ((p
->yscroll
+ count
<=
1820 2 * (p
->vrows
- vc
->vc_rows
))
1821 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1824 3 * vc
->vc_rows
>> 2)))) {
1826 fbcon_bmove(vc
, 0, 0, count
, 0, t
,
1829 if (vc
->vc_rows
- b
> 0)
1830 fbcon_bmove(vc
, b
- count
, 0, b
, 0,
1833 } else if (info
->flags
& FBINFO_READS_FAST
)
1834 fbcon_bmove(vc
, t
+ count
, 0, t
, 0,
1835 b
- t
- count
, vc
->vc_cols
);
1838 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1843 fbcon_redraw(vc
, p
, t
, b
- t
- count
,
1844 count
* vc
->vc_cols
);
1845 fbcon_clear(vc
, b
- count
, 0, count
, vc
->vc_cols
);
1846 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1849 vc
->vc_video_erase_char
,
1850 vc
->vc_size_row
* count
);
1856 if (count
> vc
->vc_rows
) /* Maximum realistic size */
1857 count
= vc
->vc_rows
;
1858 if (logo_shown
>= 0)
1860 switch (p
->scrollmode
) {
1862 ops
->bmove(vc
, info
, t
, 0, t
+ count
, 0,
1863 b
- t
- count
, vc
->vc_cols
);
1864 ops
->clear(vc
, info
, t
, 0, count
, vc
->vc_cols
);
1867 case SCROLL_WRAP_MOVE
:
1868 if (b
- t
- count
> 3 * vc
->vc_rows
>> 2) {
1869 if (vc
->vc_rows
- b
> 0)
1870 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1873 ywrap_down(vc
, count
);
1875 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1877 } else if (info
->flags
& FBINFO_READS_FAST
)
1878 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1879 b
- t
- count
, vc
->vc_cols
);
1882 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1885 case SCROLL_PAN_MOVE
:
1886 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1887 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1890 3 * vc
->vc_rows
>> 2)))) {
1891 if (vc
->vc_rows
- b
> 0)
1892 fbcon_bmove(vc
, b
, 0, b
- count
, 0,
1895 ypan_down(vc
, count
);
1897 fbcon_bmove(vc
, count
, 0, 0, 0, t
,
1899 } else if (info
->flags
& FBINFO_READS_FAST
)
1900 fbcon_bmove(vc
, t
, 0, t
+ count
, 0,
1901 b
- t
- count
, vc
->vc_cols
);
1904 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1907 case SCROLL_PAN_REDRAW
:
1908 if ((count
- p
->yscroll
<= p
->vrows
- vc
->vc_rows
)
1909 && ((!scroll_partial
&& (b
- t
== vc
->vc_rows
))
1912 3 * vc
->vc_rows
>> 2)))) {
1913 if (vc
->vc_rows
- b
> 0)
1914 fbcon_redraw_move(vc
, p
, b
, vc
->vc_rows
- b
,
1916 ypan_down_redraw(vc
, t
, count
);
1918 fbcon_redraw_move(vc
, p
, count
, t
, 0);
1920 fbcon_redraw_move(vc
, p
, t
, b
- t
- count
, t
+ count
);
1921 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1926 fbcon_redraw(vc
, p
, b
- 1, b
- t
- count
,
1927 -count
* vc
->vc_cols
);
1928 fbcon_clear(vc
, t
, 0, count
, vc
->vc_cols
);
1929 scr_memsetw((unsigned short *) (vc
->vc_origin
+
1932 vc
->vc_video_erase_char
,
1933 vc
->vc_size_row
* count
);
1941 static void fbcon_bmove(struct vc_data
*vc
, int sy
, int sx
, int dy
, int dx
,
1942 int height
, int width
)
1944 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1945 struct display
*p
= &fb_display
[vc
->vc_num
];
1947 if (fbcon_is_inactive(vc
, info
))
1950 if (!width
|| !height
)
1953 /* Split blits that cross physical y_wrap case.
1954 * Pathological case involves 4 blits, better to use recursive
1955 * code rather than unrolled case
1957 * Recursive invocations don't need to erase the cursor over and
1958 * over again, so we use fbcon_bmove_rec()
1960 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, height
, width
,
1961 p
->vrows
- p
->yscroll
);
1964 static void fbcon_bmove_rec(struct vc_data
*vc
, struct display
*p
, int sy
, int sx
,
1965 int dy
, int dx
, int height
, int width
, u_int y_break
)
1967 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
1968 struct fbcon_ops
*ops
= info
->fbcon_par
;
1971 if (sy
< y_break
&& sy
+ height
> y_break
) {
1973 if (dy
< sy
) { /* Avoid trashing self */
1974 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1976 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1977 height
- b
, width
, y_break
);
1979 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1980 height
- b
, width
, y_break
);
1981 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1987 if (dy
< y_break
&& dy
+ height
> y_break
) {
1989 if (dy
< sy
) { /* Avoid trashing self */
1990 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
1992 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1993 height
- b
, width
, y_break
);
1995 fbcon_bmove_rec(vc
, p
, sy
+ b
, sx
, dy
+ b
, dx
,
1996 height
- b
, width
, y_break
);
1997 fbcon_bmove_rec(vc
, p
, sy
, sx
, dy
, dx
, b
, width
,
2002 ops
->bmove(vc
, info
, real_y(p
, sy
), sx
, real_y(p
, dy
), dx
,
2006 static __inline__
void updatescrollmode(struct display
*p
,
2007 struct fb_info
*info
,
2010 struct fbcon_ops
*ops
= info
->fbcon_par
;
2011 int fh
= vc
->vc_font
.height
;
2012 int cap
= info
->flags
;
2014 int ypan
= FBCON_SWAP(ops
->rotate
, info
->fix
.ypanstep
,
2015 info
->fix
.xpanstep
);
2016 int ywrap
= FBCON_SWAP(ops
->rotate
, info
->fix
.ywrapstep
, t
);
2017 int yres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2018 int vyres
= FBCON_SWAP(ops
->rotate
, info
->var
.yres_virtual
,
2019 info
->var
.xres_virtual
);
2020 int good_pan
= (cap
& FBINFO_HWACCEL_YPAN
) &&
2021 divides(ypan
, vc
->vc_font
.height
) && vyres
> yres
;
2022 int good_wrap
= (cap
& FBINFO_HWACCEL_YWRAP
) &&
2023 divides(ywrap
, vc
->vc_font
.height
) &&
2024 divides(vc
->vc_font
.height
, vyres
) &&
2025 divides(vc
->vc_font
.height
, yres
);
2026 int reading_fast
= cap
& FBINFO_READS_FAST
;
2027 int fast_copyarea
= (cap
& FBINFO_HWACCEL_COPYAREA
) &&
2028 !(cap
& FBINFO_HWACCEL_DISABLED
);
2029 int fast_imageblit
= (cap
& FBINFO_HWACCEL_IMAGEBLIT
) &&
2030 !(cap
& FBINFO_HWACCEL_DISABLED
);
2032 p
->vrows
= vyres
/fh
;
2033 if (yres
> (fh
* (vc
->vc_rows
+ 1)))
2034 p
->vrows
-= (yres
- (fh
* vc
->vc_rows
)) / fh
;
2035 if ((yres
% fh
) && (vyres
% fh
< yres
% fh
))
2038 if (good_wrap
|| good_pan
) {
2039 if (reading_fast
|| fast_copyarea
)
2040 p
->scrollmode
= good_wrap
?
2041 SCROLL_WRAP_MOVE
: SCROLL_PAN_MOVE
;
2043 p
->scrollmode
= good_wrap
? SCROLL_REDRAW
:
2046 if (reading_fast
|| (fast_copyarea
&& !fast_imageblit
))
2047 p
->scrollmode
= SCROLL_MOVE
;
2049 p
->scrollmode
= SCROLL_REDRAW
;
2053 static int fbcon_resize(struct vc_data
*vc
, unsigned int width
,
2054 unsigned int height
)
2056 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2057 struct fbcon_ops
*ops
= info
->fbcon_par
;
2058 struct display
*p
= &fb_display
[vc
->vc_num
];
2059 struct fb_var_screeninfo var
= info
->var
;
2060 int x_diff
, y_diff
, virt_w
, virt_h
, virt_fw
, virt_fh
;
2062 virt_w
= FBCON_SWAP(ops
->rotate
, width
, height
);
2063 virt_h
= FBCON_SWAP(ops
->rotate
, height
, width
);
2064 virt_fw
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.width
,
2065 vc
->vc_font
.height
);
2066 virt_fh
= FBCON_SWAP(ops
->rotate
, vc
->vc_font
.height
,
2068 var
.xres
= virt_w
* virt_fw
;
2069 var
.yres
= virt_h
* virt_fh
;
2070 x_diff
= info
->var
.xres
- var
.xres
;
2071 y_diff
= info
->var
.yres
- var
.yres
;
2072 if (x_diff
< 0 || x_diff
> virt_fw
||
2073 y_diff
< 0 || y_diff
> virt_fh
) {
2074 struct fb_videomode
*mode
;
2076 DPRINTK("attempting resize %ix%i\n", var
.xres
, var
.yres
);
2077 mode
= fb_find_best_mode(&var
, &info
->modelist
);
2080 display_to_var(&var
, p
);
2081 fb_videomode_to_var(&var
, mode
);
2083 if (virt_w
> var
.xres
/virt_fw
|| virt_h
> var
.yres
/virt_fh
)
2086 DPRINTK("resize now %ix%i\n", var
.xres
, var
.yres
);
2087 if (CON_IS_VISIBLE(vc
)) {
2088 var
.activate
= FB_ACTIVATE_NOW
|
2090 fb_set_var(info
, &var
);
2092 var_to_display(p
, &info
->var
, info
);
2093 ops
->var
= info
->var
;
2095 updatescrollmode(p
, info
, vc
);
2099 static int fbcon_switch(struct vc_data
*vc
)
2101 struct fb_info
*info
, *old_info
= NULL
;
2102 struct fbcon_ops
*ops
;
2103 struct display
*p
= &fb_display
[vc
->vc_num
];
2104 struct fb_var_screeninfo var
;
2105 int i
, prev_console
, charcnt
= 256;
2107 info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2108 ops
= info
->fbcon_par
;
2112 fbcon_set_origin(vc
);
2113 softback_top
= softback_curr
= softback_in
= softback_buf
;
2115 fbcon_update_softback(vc
);
2118 if (logo_shown
>= 0) {
2119 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2121 if (conp2
->vc_top
== logo_lines
2122 && conp2
->vc_bottom
== conp2
->vc_rows
)
2124 logo_shown
= FBCON_LOGO_CANSHOW
;
2127 prev_console
= ops
->currcon
;
2128 if (prev_console
!= -1)
2129 old_info
= registered_fb
[con2fb_map
[prev_console
]];
2131 * FIXME: If we have multiple fbdev's loaded, we need to
2132 * update all info->currcon. Perhaps, we can place this
2133 * in a centralized structure, but this might break some
2136 * info->currcon = vc->vc_num;
2138 for (i
= 0; i
< FB_MAX
; i
++) {
2139 if (registered_fb
[i
] != NULL
&& registered_fb
[i
]->fbcon_par
) {
2140 struct fbcon_ops
*o
= registered_fb
[i
]->fbcon_par
;
2142 o
->currcon
= vc
->vc_num
;
2145 memset(&var
, 0, sizeof(struct fb_var_screeninfo
));
2146 display_to_var(&var
, p
);
2147 var
.activate
= FB_ACTIVATE_NOW
;
2150 * make sure we don't unnecessarily trip the memcmp()
2153 info
->var
.activate
= var
.activate
;
2154 var
.yoffset
= info
->var
.yoffset
;
2155 var
.xoffset
= info
->var
.xoffset
;
2156 var
.vmode
= info
->var
.vmode
;
2157 fb_set_var(info
, &var
);
2158 ops
->var
= info
->var
;
2160 if (old_info
!= NULL
&& (old_info
!= info
||
2161 info
->flags
& FBINFO_MISC_ALWAYS_SETPAR
)) {
2162 if (info
->fbops
->fb_set_par
)
2163 info
->fbops
->fb_set_par(info
);
2165 if (old_info
!= info
)
2166 fbcon_del_cursor_timer(old_info
);
2169 fbcon_add_cursor_timer(info
);
2170 set_blitting_type(vc
, info
);
2171 ops
->cursor_reset
= 1;
2173 if (ops
->rotate_font
&& ops
->rotate_font(info
, vc
)) {
2174 ops
->rotate
= FB_ROTATE_UR
;
2175 set_blitting_type(vc
, info
);
2178 vc
->vc_can_do_color
= (fb_get_color_depth(&info
->var
, &info
->fix
)!=1);
2179 vc
->vc_complement_mask
= vc
->vc_can_do_color
? 0x7700 : 0x0800;
2182 charcnt
= FNTCHARCNT(vc
->vc_font
.data
);
2185 vc
->vc_complement_mask
<<= 1;
2187 updatescrollmode(p
, info
, vc
);
2189 switch (p
->scrollmode
) {
2190 case SCROLL_WRAP_MOVE
:
2191 scrollback_phys_max
= p
->vrows
- vc
->vc_rows
;
2193 case SCROLL_PAN_MOVE
:
2194 case SCROLL_PAN_REDRAW
:
2195 scrollback_phys_max
= p
->vrows
- 2 * vc
->vc_rows
;
2196 if (scrollback_phys_max
< 0)
2197 scrollback_phys_max
= 0;
2200 scrollback_phys_max
= 0;
2205 scrollback_current
= 0;
2207 if (!fbcon_is_inactive(vc
, info
)) {
2208 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2209 ops
->update_start(info
);
2212 fbcon_set_palette(vc
, color_table
);
2213 fbcon_clear_margins(vc
, 0);
2215 if (logo_shown
== FBCON_LOGO_DRAW
) {
2217 logo_shown
= fg_console
;
2218 /* This is protected above by initmem_freed */
2219 fb_show_logo(info
, ops
->rotate
);
2221 vc
->vc_origin
+ vc
->vc_size_row
* vc
->vc_top
,
2222 vc
->vc_size_row
* (vc
->vc_bottom
-
2229 static void fbcon_generic_blank(struct vc_data
*vc
, struct fb_info
*info
,
2233 unsigned short charmask
= vc
->vc_hi_font_mask
?
2235 unsigned short oldc
;
2237 oldc
= vc
->vc_video_erase_char
;
2238 vc
->vc_video_erase_char
&= charmask
;
2239 fbcon_clear(vc
, 0, 0, vc
->vc_rows
, vc
->vc_cols
);
2240 vc
->vc_video_erase_char
= oldc
;
2244 static int fbcon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
2246 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2247 struct fbcon_ops
*ops
= info
->fbcon_par
;
2250 struct fb_var_screeninfo var
= info
->var
;
2255 if (info
->fbops
->fb_save_state
)
2256 info
->fbops
->fb_save_state(info
);
2257 var
.activate
= FB_ACTIVATE_NOW
| FB_ACTIVATE_FORCE
;
2258 fb_set_var(info
, &var
);
2260 ops
->var
= info
->var
;
2261 } else if (info
->fbops
->fb_restore_state
)
2262 info
->fbops
->fb_restore_state(info
);
2265 if (!fbcon_is_inactive(vc
, info
)) {
2266 if (ops
->blank_state
!= blank
) {
2267 ops
->blank_state
= blank
;
2268 fbcon_cursor(vc
, blank
? CM_ERASE
: CM_DRAW
);
2269 ops
->cursor_flash
= (!blank
);
2271 if (fb_blank(info
, blank
))
2272 fbcon_generic_blank(vc
, info
, blank
);
2280 fbcon_add_cursor_timer(info
);
2282 fbcon_del_cursor_timer(info
);
2287 static int fbcon_get_font(struct vc_data
*vc
, struct console_font
*font
)
2289 u8
*fontdata
= vc
->vc_font
.data
;
2290 u8
*data
= font
->data
;
2293 font
->width
= vc
->vc_font
.width
;
2294 font
->height
= vc
->vc_font
.height
;
2295 font
->charcount
= vc
->vc_hi_font_mask
? 512 : 256;
2299 if (font
->width
<= 8) {
2300 j
= vc
->vc_font
.height
;
2301 for (i
= 0; i
< font
->charcount
; i
++) {
2302 memcpy(data
, fontdata
, j
);
2303 memset(data
+ j
, 0, 32 - j
);
2307 } else if (font
->width
<= 16) {
2308 j
= vc
->vc_font
.height
* 2;
2309 for (i
= 0; i
< font
->charcount
; i
++) {
2310 memcpy(data
, fontdata
, j
);
2311 memset(data
+ j
, 0, 64 - j
);
2315 } else if (font
->width
<= 24) {
2316 for (i
= 0; i
< font
->charcount
; i
++) {
2317 for (j
= 0; j
< vc
->vc_font
.height
; j
++) {
2318 *data
++ = fontdata
[0];
2319 *data
++ = fontdata
[1];
2320 *data
++ = fontdata
[2];
2321 fontdata
+= sizeof(u32
);
2323 memset(data
, 0, 3 * (32 - j
));
2324 data
+= 3 * (32 - j
);
2327 j
= vc
->vc_font
.height
* 4;
2328 for (i
= 0; i
< font
->charcount
; i
++) {
2329 memcpy(data
, fontdata
, j
);
2330 memset(data
+ j
, 0, 128 - j
);
2338 static int fbcon_do_set_font(struct vc_data
*vc
, int w
, int h
,
2339 const u8
* data
, int userfont
)
2341 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2342 struct fbcon_ops
*ops
= info
->fbcon_par
;
2343 struct display
*p
= &fb_display
[vc
->vc_num
];
2346 char *old_data
= NULL
;
2348 if (CON_IS_VISIBLE(vc
) && softback_lines
)
2349 fbcon_set_origin(vc
);
2351 resize
= (w
!= vc
->vc_font
.width
) || (h
!= vc
->vc_font
.height
);
2353 old_data
= vc
->vc_font
.data
;
2355 cnt
= FNTCHARCNT(data
);
2358 vc
->vc_font
.data
= (void *)(p
->fontdata
= data
);
2359 if ((p
->userfont
= userfont
))
2361 vc
->vc_font
.width
= w
;
2362 vc
->vc_font
.height
= h
;
2363 if (vc
->vc_hi_font_mask
&& cnt
== 256) {
2364 vc
->vc_hi_font_mask
= 0;
2365 if (vc
->vc_can_do_color
) {
2366 vc
->vc_complement_mask
>>= 1;
2367 vc
->vc_s_complement_mask
>>= 1;
2370 /* ++Edmund: reorder the attribute bits */
2371 if (vc
->vc_can_do_color
) {
2372 unsigned short *cp
=
2373 (unsigned short *) vc
->vc_origin
;
2374 int count
= vc
->vc_screenbuf_size
/ 2;
2376 for (; count
> 0; count
--, cp
++) {
2378 scr_writew(((c
& 0xfe00) >> 1) |
2381 c
= vc
->vc_video_erase_char
;
2382 vc
->vc_video_erase_char
=
2383 ((c
& 0xfe00) >> 1) | (c
& 0xff);
2386 } else if (!vc
->vc_hi_font_mask
&& cnt
== 512) {
2387 vc
->vc_hi_font_mask
= 0x100;
2388 if (vc
->vc_can_do_color
) {
2389 vc
->vc_complement_mask
<<= 1;
2390 vc
->vc_s_complement_mask
<<= 1;
2393 /* ++Edmund: reorder the attribute bits */
2395 unsigned short *cp
=
2396 (unsigned short *) vc
->vc_origin
;
2397 int count
= vc
->vc_screenbuf_size
/ 2;
2399 for (; count
> 0; count
--, cp
++) {
2400 unsigned short newc
;
2402 if (vc
->vc_can_do_color
)
2404 ((c
& 0xff00) << 1) | (c
&
2408 scr_writew(newc
, cp
);
2410 c
= vc
->vc_video_erase_char
;
2411 if (vc
->vc_can_do_color
) {
2412 vc
->vc_video_erase_char
=
2413 ((c
& 0xff00) << 1) | (c
& 0xff);
2416 vc
->vc_video_erase_char
= c
& ~0x100;
2424 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2425 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2428 vc_resize(vc
, cols
, rows
);
2429 if (CON_IS_VISIBLE(vc
) && softback_buf
)
2430 fbcon_update_softback(vc
);
2431 } else if (CON_IS_VISIBLE(vc
)
2432 && vc
->vc_mode
== KD_TEXT
) {
2433 fbcon_clear_margins(vc
, 0);
2437 if (old_data
&& (--REFCOUNT(old_data
) == 0))
2438 kfree(old_data
- FONT_EXTRA_WORDS
* sizeof(int));
2442 static int fbcon_copy_font(struct vc_data
*vc
, int con
)
2444 struct display
*od
= &fb_display
[con
];
2445 struct console_font
*f
= &vc
->vc_font
;
2447 if (od
->fontdata
== f
->data
)
2448 return 0; /* already the same font... */
2449 return fbcon_do_set_font(vc
, f
->width
, f
->height
, od
->fontdata
, od
->userfont
);
2453 * User asked to set font; we are guaranteed that
2454 * a) width and height are in range 1..32
2455 * b) charcount does not exceed 512
2456 * but lets not assume that, since someone might someday want to use larger
2457 * fonts. And charcount of 512 is small for unicode support.
2459 * However, user space gives the font in 32 rows , regardless of
2460 * actual font height. So a new API is needed if support for larger fonts
2461 * is ever implemented.
2464 static int fbcon_set_font(struct vc_data
*vc
, struct console_font
*font
, unsigned flags
)
2466 unsigned charcount
= font
->charcount
;
2467 int w
= font
->width
;
2468 int h
= font
->height
;
2471 u8
*new_data
, *data
= font
->data
;
2472 int pitch
= (font
->width
+7) >> 3;
2474 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2475 * If not this check should be changed to charcount < 256 */
2476 if (charcount
!= 256 && charcount
!= 512)
2479 size
= h
* pitch
* charcount
;
2481 new_data
= kmalloc(FONT_EXTRA_WORDS
* sizeof(int) + size
, GFP_USER
);
2486 new_data
+= FONT_EXTRA_WORDS
* sizeof(int);
2487 FNTSIZE(new_data
) = size
;
2488 FNTCHARCNT(new_data
) = charcount
;
2489 REFCOUNT(new_data
) = 0; /* usage counter */
2490 for (i
=0; i
< charcount
; i
++) {
2491 memcpy(new_data
+ i
*h
*pitch
, data
+ i
*32*pitch
, h
*pitch
);
2494 /* Since linux has a nice crc32 function use it for counting font
2496 csum
= crc32(0, new_data
, size
);
2498 FNTSUM(new_data
) = csum
;
2499 /* Check if the same font is on some other console already */
2500 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2501 struct vc_data
*tmp
= vc_cons
[i
].d
;
2503 if (fb_display
[i
].userfont
&&
2504 fb_display
[i
].fontdata
&&
2505 FNTSUM(fb_display
[i
].fontdata
) == csum
&&
2506 FNTSIZE(fb_display
[i
].fontdata
) == size
&&
2507 tmp
->vc_font
.width
== w
&&
2508 !memcmp(fb_display
[i
].fontdata
, new_data
, size
)) {
2509 kfree(new_data
- FONT_EXTRA_WORDS
* sizeof(int));
2510 new_data
= (u8
*)fb_display
[i
].fontdata
;
2514 return fbcon_do_set_font(vc
, font
->width
, font
->height
, new_data
, 1);
2517 static int fbcon_set_def_font(struct vc_data
*vc
, struct console_font
*font
, char *name
)
2519 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2520 const struct font_desc
*f
;
2523 f
= get_default_font(info
->var
.xres
, info
->var
.yres
);
2524 else if (!(f
= find_font(name
)))
2527 font
->width
= f
->width
;
2528 font
->height
= f
->height
;
2529 return fbcon_do_set_font(vc
, f
->width
, f
->height
, f
->data
, 0);
2532 static u16 palette_red
[16];
2533 static u16 palette_green
[16];
2534 static u16 palette_blue
[16];
2536 static struct fb_cmap palette_cmap
= {
2537 0, 16, palette_red
, palette_green
, palette_blue
, NULL
2540 static int fbcon_set_palette(struct vc_data
*vc
, unsigned char *table
)
2542 struct fb_info
*info
= registered_fb
[con2fb_map
[vc
->vc_num
]];
2546 if (fbcon_is_inactive(vc
, info
))
2549 if (!CON_IS_VISIBLE(vc
))
2552 depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
2554 for (i
= j
= 0; i
< 16; i
++) {
2556 val
= vc
->vc_palette
[j
++];
2557 palette_red
[k
] = (val
<< 8) | val
;
2558 val
= vc
->vc_palette
[j
++];
2559 palette_green
[k
] = (val
<< 8) | val
;
2560 val
= vc
->vc_palette
[j
++];
2561 palette_blue
[k
] = (val
<< 8) | val
;
2563 palette_cmap
.len
= 16;
2564 palette_cmap
.start
= 0;
2566 * If framebuffer is capable of less than 16 colors,
2567 * use default palette of fbcon.
2570 fb_copy_cmap(fb_default_cmap(1 << depth
), &palette_cmap
);
2572 return fb_set_cmap(&palette_cmap
, info
);
2575 static u16
*fbcon_screen_pos(struct vc_data
*vc
, int offset
)
2580 if (vc
->vc_num
!= fg_console
|| !softback_lines
)
2581 return (u16
*) (vc
->vc_origin
+ offset
);
2582 line
= offset
/ vc
->vc_size_row
;
2583 if (line
>= softback_lines
)
2584 return (u16
*) (vc
->vc_origin
+ offset
-
2585 softback_lines
* vc
->vc_size_row
);
2586 p
= softback_curr
+ offset
;
2587 if (p
>= softback_end
)
2588 p
+= softback_buf
- softback_end
;
2592 static unsigned long fbcon_getxy(struct vc_data
*vc
, unsigned long pos
,
2598 if (pos
>= vc
->vc_origin
&& pos
< vc
->vc_scr_end
) {
2599 unsigned long offset
= (pos
- vc
->vc_origin
) / 2;
2601 x
= offset
% vc
->vc_cols
;
2602 y
= offset
/ vc
->vc_cols
;
2603 if (vc
->vc_num
== fg_console
)
2604 y
+= softback_lines
;
2605 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2606 } else if (vc
->vc_num
== fg_console
&& softback_lines
) {
2607 unsigned long offset
= pos
- softback_curr
;
2609 if (pos
< softback_curr
)
2610 offset
+= softback_end
- softback_buf
;
2612 x
= offset
% vc
->vc_cols
;
2613 y
= offset
/ vc
->vc_cols
;
2614 ret
= pos
+ (vc
->vc_cols
- x
) * 2;
2615 if (ret
== softback_end
)
2617 if (ret
== softback_in
)
2618 ret
= vc
->vc_origin
;
2620 /* Should not happen */
2622 ret
= vc
->vc_origin
;
2631 /* As we might be inside of softback, we may work with non-contiguous buffer,
2632 that's why we have to use a separate routine. */
2633 static void fbcon_invert_region(struct vc_data
*vc
, u16
* p
, int cnt
)
2636 u16 a
= scr_readw(p
);
2637 if (!vc
->vc_can_do_color
)
2639 else if (vc
->vc_hi_font_mask
== 0x100)
2640 a
= ((a
) & 0x11ff) | (((a
) & 0xe000) >> 4) |
2641 (((a
) & 0x0e00) << 4);
2643 a
= ((a
) & 0x88ff) | (((a
) & 0x7000) >> 4) |
2644 (((a
) & 0x0700) << 4);
2646 if (p
== (u16
*) softback_end
)
2647 p
= (u16
*) softback_buf
;
2648 if (p
== (u16
*) softback_in
)
2649 p
= (u16
*) vc
->vc_origin
;
2653 static int fbcon_scrolldelta(struct vc_data
*vc
, int lines
)
2655 struct fb_info
*info
= registered_fb
[con2fb_map
[fg_console
]];
2656 struct fbcon_ops
*ops
= info
->fbcon_par
;
2657 struct display
*p
= &fb_display
[fg_console
];
2658 int offset
, limit
, scrollback_old
;
2661 if (vc
->vc_num
!= fg_console
)
2663 if (vc
->vc_mode
!= KD_TEXT
|| !lines
)
2665 if (logo_shown
>= 0) {
2666 struct vc_data
*conp2
= vc_cons
[logo_shown
].d
;
2668 if (conp2
->vc_top
== logo_lines
2669 && conp2
->vc_bottom
== conp2
->vc_rows
)
2671 if (logo_shown
== vc
->vc_num
) {
2677 logo_lines
* vc
->vc_size_row
;
2678 for (i
= 0; i
< logo_lines
; i
++) {
2679 if (p
== softback_top
)
2681 if (p
== softback_buf
)
2683 p
-= vc
->vc_size_row
;
2684 q
-= vc
->vc_size_row
;
2685 scr_memcpyw((u16
*) q
, (u16
*) p
,
2688 softback_in
= softback_curr
= p
;
2689 update_region(vc
, vc
->vc_origin
,
2690 logo_lines
* vc
->vc_cols
);
2692 logo_shown
= FBCON_LOGO_CANSHOW
;
2694 fbcon_cursor(vc
, CM_ERASE
| CM_SOFTBACK
);
2695 fbcon_redraw_softback(vc
, p
, lines
);
2696 fbcon_cursor(vc
, CM_DRAW
| CM_SOFTBACK
);
2700 if (!scrollback_phys_max
)
2703 scrollback_old
= scrollback_current
;
2704 scrollback_current
-= lines
;
2705 if (scrollback_current
< 0)
2706 scrollback_current
= 0;
2707 else if (scrollback_current
> scrollback_max
)
2708 scrollback_current
= scrollback_max
;
2709 if (scrollback_current
== scrollback_old
)
2712 if (fbcon_is_inactive(vc
, info
))
2715 fbcon_cursor(vc
, CM_ERASE
);
2717 offset
= p
->yscroll
- scrollback_current
;
2719 switch (p
->scrollmode
) {
2720 case SCROLL_WRAP_MOVE
:
2721 info
->var
.vmode
|= FB_VMODE_YWRAP
;
2723 case SCROLL_PAN_MOVE
:
2724 case SCROLL_PAN_REDRAW
:
2725 limit
-= vc
->vc_rows
;
2726 info
->var
.vmode
&= ~FB_VMODE_YWRAP
;
2731 else if (offset
>= limit
)
2734 ops
->var
.xoffset
= 0;
2735 ops
->var
.yoffset
= offset
* vc
->vc_font
.height
;
2736 ops
->update_start(info
);
2738 if (!scrollback_current
)
2739 fbcon_cursor(vc
, CM_DRAW
);
2743 static int fbcon_set_origin(struct vc_data
*vc
)
2746 fbcon_scrolldelta(vc
, softback_lines
);
2750 static void fbcon_suspended(struct fb_info
*info
)
2752 struct vc_data
*vc
= NULL
;
2753 struct fbcon_ops
*ops
= info
->fbcon_par
;
2755 if (!ops
|| ops
->currcon
< 0)
2757 vc
= vc_cons
[ops
->currcon
].d
;
2759 /* Clear cursor, restore saved data */
2760 fbcon_cursor(vc
, CM_ERASE
);
2763 static void fbcon_resumed(struct fb_info
*info
)
2766 struct fbcon_ops
*ops
= info
->fbcon_par
;
2768 if (!ops
|| ops
->currcon
< 0)
2770 vc
= vc_cons
[ops
->currcon
].d
;
2775 static void fbcon_modechanged(struct fb_info
*info
)
2777 struct fbcon_ops
*ops
= info
->fbcon_par
;
2782 if (!ops
|| ops
->currcon
< 0)
2784 vc
= vc_cons
[ops
->currcon
].d
;
2785 if (vc
->vc_mode
!= KD_TEXT
||
2786 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2789 p
= &fb_display
[vc
->vc_num
];
2790 set_blitting_type(vc
, info
);
2792 if (CON_IS_VISIBLE(vc
)) {
2793 var_to_display(p
, &info
->var
, info
);
2794 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2795 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2796 cols
/= vc
->vc_font
.width
;
2797 rows
/= vc
->vc_font
.height
;
2798 vc_resize(vc
, cols
, rows
);
2799 updatescrollmode(p
, info
, vc
);
2801 scrollback_current
= 0;
2803 if (!fbcon_is_inactive(vc
, info
)) {
2804 ops
->var
.xoffset
= ops
->var
.yoffset
= p
->yscroll
= 0;
2805 ops
->update_start(info
);
2808 fbcon_set_palette(vc
, color_table
);
2811 fbcon_update_softback(vc
);
2815 static void fbcon_set_all_vcs(struct fb_info
*info
)
2817 struct fbcon_ops
*ops
= info
->fbcon_par
;
2822 if (!ops
|| ops
->currcon
< 0)
2825 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2827 if (!vc
|| vc
->vc_mode
!= KD_TEXT
||
2828 registered_fb
[con2fb_map
[i
]] != info
)
2831 p
= &fb_display
[vc
->vc_num
];
2832 set_blitting_type(vc
, info
);
2833 var_to_display(p
, &info
->var
, info
);
2834 cols
= FBCON_SWAP(ops
->rotate
, info
->var
.xres
, info
->var
.yres
);
2835 rows
= FBCON_SWAP(ops
->rotate
, info
->var
.yres
, info
->var
.xres
);
2836 cols
/= vc
->vc_font
.width
;
2837 rows
/= vc
->vc_font
.height
;
2838 vc_resize(vc
, cols
, rows
);
2840 if (CON_IS_VISIBLE(vc
)) {
2841 updatescrollmode(p
, info
, vc
);
2843 scrollback_current
= 0;
2845 if (!fbcon_is_inactive(vc
, info
)) {
2846 ops
->var
.xoffset
= ops
->var
.yoffset
=
2848 ops
->update_start(info
);
2851 fbcon_set_palette(vc
, color_table
);
2854 fbcon_update_softback(vc
);
2858 ops
->p
= &fb_display
[ops
->currcon
];
2861 static int fbcon_mode_deleted(struct fb_info
*info
,
2862 struct fb_videomode
*mode
)
2864 struct fb_info
*fb_info
;
2866 int i
, j
, found
= 0;
2868 /* before deletion, ensure that mode is not in use */
2869 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2873 fb_info
= registered_fb
[j
];
2874 if (fb_info
!= info
)
2879 if (fb_mode_is_equal(p
->mode
, mode
)) {
2887 static int fbcon_fb_unregistered(int idx
)
2891 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2892 if (con2fb_map
[i
] == idx
)
2896 if (idx
== info_idx
) {
2899 for (i
= 0; i
< FB_MAX
; i
++) {
2900 if (registered_fb
[i
] != NULL
) {
2907 if (info_idx
!= -1) {
2908 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2909 if (con2fb_map
[i
] == -1)
2910 con2fb_map
[i
] = info_idx
;
2914 if (!num_registered_fb
)
2915 unregister_con_driver(&fb_con
);
2920 static int fbcon_fb_registered(int idx
)
2924 if (info_idx
== -1) {
2925 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2926 if (con2fb_map_boot
[i
] == idx
) {
2933 ret
= fbcon_takeover(1);
2935 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2936 if (con2fb_map_boot
[i
] == idx
&&
2937 con2fb_map
[i
] == -1)
2938 set_con2fb_map(i
, idx
, 0);
2945 static void fbcon_fb_blanked(struct fb_info
*info
, int blank
)
2947 struct fbcon_ops
*ops
= info
->fbcon_par
;
2950 if (!ops
|| ops
->currcon
< 0)
2953 vc
= vc_cons
[ops
->currcon
].d
;
2954 if (vc
->vc_mode
!= KD_TEXT
||
2955 registered_fb
[con2fb_map
[ops
->currcon
]] != info
)
2958 if (CON_IS_VISIBLE(vc
)) {
2962 do_unblank_screen(0);
2964 ops
->blank_state
= blank
;
2967 static void fbcon_new_modelist(struct fb_info
*info
)
2971 struct fb_var_screeninfo var
;
2972 struct fb_videomode
*mode
;
2974 for (i
= first_fb_vc
; i
<= last_fb_vc
; i
++) {
2975 if (registered_fb
[con2fb_map
[i
]] != info
)
2977 if (!fb_display
[i
].mode
)
2980 display_to_var(&var
, &fb_display
[i
]);
2981 mode
= fb_find_nearest_mode(fb_display
[i
].mode
,
2983 fb_videomode_to_var(&var
, mode
);
2986 fbcon_set_disp(info
, &var
, vc
);
2988 fbcon_preset_disp(info
, &var
, i
);
2993 static int fbcon_event_notify(struct notifier_block
*self
,
2994 unsigned long action
, void *data
)
2996 struct fb_event
*event
= data
;
2997 struct fb_info
*info
= event
->info
;
2998 struct fb_videomode
*mode
;
2999 struct fb_con2fbmap
*con2fb
;
3003 * ignore all events except driver registration and deregistration
3004 * if fbcon is not active
3006 if (fbcon_has_exited
&& !(action
== FB_EVENT_FB_REGISTERED
||
3007 action
== FB_EVENT_FB_UNREGISTERED
))
3011 case FB_EVENT_SUSPEND
:
3012 fbcon_suspended(info
);
3014 case FB_EVENT_RESUME
:
3015 fbcon_resumed(info
);
3017 case FB_EVENT_MODE_CHANGE
:
3018 fbcon_modechanged(info
);
3020 case FB_EVENT_MODE_CHANGE_ALL
:
3021 fbcon_set_all_vcs(info
);
3023 case FB_EVENT_MODE_DELETE
:
3025 ret
= fbcon_mode_deleted(info
, mode
);
3027 case FB_EVENT_FB_REGISTERED
:
3028 ret
= fbcon_fb_registered(info
->node
);
3030 case FB_EVENT_FB_UNREGISTERED
:
3031 ret
= fbcon_fb_unregistered(info
->node
);
3033 case FB_EVENT_SET_CONSOLE_MAP
:
3034 con2fb
= event
->data
;
3035 ret
= set_con2fb_map(con2fb
->console
- 1,
3036 con2fb
->framebuffer
, 1);
3038 case FB_EVENT_GET_CONSOLE_MAP
:
3039 con2fb
= event
->data
;
3040 con2fb
->framebuffer
= con2fb_map
[con2fb
->console
- 1];
3042 case FB_EVENT_BLANK
:
3043 fbcon_fb_blanked(info
, *(int *)event
->data
);
3045 case FB_EVENT_NEW_MODELIST
:
3046 fbcon_new_modelist(info
);
3055 * The console `switch' structure for the frame buffer based console
3058 static const struct consw fb_con
= {
3059 .owner
= THIS_MODULE
,
3060 .con_startup
= fbcon_startup
,
3061 .con_init
= fbcon_init
,
3062 .con_deinit
= fbcon_deinit
,
3063 .con_clear
= fbcon_clear
,
3064 .con_putc
= fbcon_putc
,
3065 .con_putcs
= fbcon_putcs
,
3066 .con_cursor
= fbcon_cursor
,
3067 .con_scroll
= fbcon_scroll
,
3068 .con_bmove
= fbcon_bmove
,
3069 .con_switch
= fbcon_switch
,
3070 .con_blank
= fbcon_blank
,
3071 .con_font_set
= fbcon_set_font
,
3072 .con_font_get
= fbcon_get_font
,
3073 .con_font_default
= fbcon_set_def_font
,
3074 .con_font_copy
= fbcon_copy_font
,
3075 .con_set_palette
= fbcon_set_palette
,
3076 .con_scrolldelta
= fbcon_scrolldelta
,
3077 .con_set_origin
= fbcon_set_origin
,
3078 .con_invert_region
= fbcon_invert_region
,
3079 .con_screen_pos
= fbcon_screen_pos
,
3080 .con_getxy
= fbcon_getxy
,
3081 .con_resize
= fbcon_resize
,
3084 static struct notifier_block fbcon_event_notifier
= {
3085 .notifier_call
= fbcon_event_notify
,
3088 static ssize_t
store_rotate(struct class_device
*class_device
,
3089 const char *buf
, size_t count
)
3091 struct fb_info
*info
;
3095 if (fbcon_has_exited
)
3098 acquire_console_sem();
3099 idx
= con2fb_map
[fg_console
];
3101 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3104 info
= registered_fb
[idx
];
3105 rotate
= simple_strtoul(buf
, last
, 0);
3106 fbcon_rotate(info
, rotate
);
3108 release_console_sem();
3112 static ssize_t
store_rotate_all(struct class_device
*class_device
,
3113 const char *buf
, size_t count
)
3115 struct fb_info
*info
;
3119 if (fbcon_has_exited
)
3122 acquire_console_sem();
3123 idx
= con2fb_map
[fg_console
];
3125 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3128 info
= registered_fb
[idx
];
3129 rotate
= simple_strtoul(buf
, last
, 0);
3130 fbcon_rotate_all(info
, rotate
);
3132 release_console_sem();
3136 static ssize_t
show_rotate(struct class_device
*class_device
, char *buf
)
3138 struct fb_info
*info
;
3139 int rotate
= 0, idx
;
3141 if (fbcon_has_exited
)
3144 acquire_console_sem();
3145 idx
= con2fb_map
[fg_console
];
3147 if (idx
== -1 || registered_fb
[idx
] == NULL
)
3150 info
= registered_fb
[idx
];
3151 rotate
= fbcon_get_rotate(info
);
3153 release_console_sem();
3154 return snprintf(buf
, PAGE_SIZE
, "%d\n", rotate
);
3157 static struct class_device_attribute class_device_attrs
[] = {
3158 __ATTR(rotate
, S_IRUGO
|S_IWUSR
, show_rotate
, store_rotate
),
3159 __ATTR(rotate_all
, S_IWUSR
, NULL
, store_rotate_all
),
3162 static int fbcon_init_class_device(void)
3166 for (i
= 0; i
< ARRAY_SIZE(class_device_attrs
); i
++)
3167 class_device_create_file(fbcon_class_device
,
3168 &class_device_attrs
[i
]);
3172 static void fbcon_start(void)
3174 if (num_registered_fb
) {
3177 acquire_console_sem();
3179 for (i
= 0; i
< FB_MAX
; i
++) {
3180 if (registered_fb
[i
] != NULL
) {
3186 release_console_sem();
3191 static void fbcon_exit(void)
3193 struct fb_info
*info
;
3196 if (fbcon_has_exited
)
3200 free_irq(IRQ_AUTO_4
, fb_vbl_handler
);
3203 if (MACH_IS_MAC
&& vbl_detected
)
3204 free_irq(IRQ_MAC_VBL
, fb_vbl_handler
);
3207 kfree((void *)softback_buf
);
3210 for (i
= 0; i
< FB_MAX
; i
++) {
3212 info
= registered_fb
[i
];
3217 for (j
= first_fb_vc
; j
<= last_fb_vc
; j
++) {
3218 if (con2fb_map
[j
] == i
)
3223 if (info
->fbops
->fb_release
)
3224 info
->fbops
->fb_release(info
, 0);
3225 module_put(info
->fbops
->owner
);
3227 if (info
->fbcon_par
) {
3228 struct fbcon_ops
*ops
= info
->fbcon_par
;
3230 fbcon_del_cursor_timer(info
);
3231 kfree(ops
->cursor_src
);
3232 kfree(info
->fbcon_par
);
3233 info
->fbcon_par
= NULL
;
3236 if (info
->queue
.func
== fb_flashcursor
)
3237 info
->queue
.func
= NULL
;
3241 fbcon_has_exited
= 1;
3244 static int __init
fb_console_init(void)
3248 acquire_console_sem();
3249 fb_register_client(&fbcon_event_notifier
);
3250 fbcon_class_device
=
3251 class_device_create(fb_class
, NULL
, MKDEV(0, 0), NULL
, "fbcon");
3253 if (IS_ERR(fbcon_class_device
)) {
3254 printk(KERN_WARNING
"Unable to create class_device "
3255 "for fbcon; errno = %ld\n",
3256 PTR_ERR(fbcon_class_device
));
3257 fbcon_class_device
= NULL
;
3259 fbcon_init_class_device();
3261 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
3264 release_console_sem();
3269 module_init(fb_console_init
);
3273 static void __exit
fbcon_deinit_class_device(void)
3277 for (i
= 0; i
< ARRAY_SIZE(class_device_attrs
); i
++)
3278 class_device_remove_file(fbcon_class_device
,
3279 &class_device_attrs
[i
]);
3282 static void __exit
fb_console_exit(void)
3284 acquire_console_sem();
3285 fb_unregister_client(&fbcon_event_notifier
);
3286 fbcon_deinit_class_device();
3287 class_device_destroy(fb_class
, MKDEV(0, 0));
3289 release_console_sem();
3290 unregister_con_driver(&fb_con
);
3293 module_exit(fb_console_exit
);
3297 MODULE_LICENSE("GPL");