Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / video / console / fbcon.c
blob47ba1a79adcd350e6487b42d1d5e6b1a4e1b6c7a
1 /*
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
10 * Greg Harp
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
14 * Geert Uytterhoeven
15 * Jes Sorensen (jds@kom.auc.dk)
16 * Martin Apel
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
21 * Roman Hodek
23 * with work by Guenther Kelleter
24 * Martin Schaller
25 * Andreas Schwab
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
46 * o mfb Monochrome
47 * o vga VGA characters/attributes
49 * To do:
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
56 * more details.
59 #undef FBCONDEBUG
61 #include <linux/config.h>
62 #include <linux/module.h>
63 #include <linux/types.h>
64 #include <linux/sched.h>
65 #include <linux/fs.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>
71 #include <linux/kd.h>
72 #include <linux/slab.h>
73 #include <linux/fb.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 */
81 #include <asm/irq.h>
82 #include <asm/system.h>
83 #include <asm/uaccess.h>
84 #ifdef CONFIG_ATARI
85 #include <asm/atariints.h>
86 #endif
87 #ifdef CONFIG_MAC
88 #include <asm/macints.h>
89 #endif
90 #if defined(__mc68000__) || defined(CONFIG_APUS)
91 #include <asm/machdep.h>
92 #include <asm/setup.h>
93 #endif
95 #include "fbcon.h"
97 #ifdef FBCONDEBUG
98 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
99 #else
100 # define DPRINTK(fmt, args...)
101 #endif
103 enum {
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
116 enums. */
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 /* font data */
129 static char fontname[40];
131 /* current fb_info */
132 static int info_idx = -1;
134 /* console rotation */
135 static int rotate;
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 void fbcon_free_font(struct display *);
144 static int fbcon_set_origin(struct vc_data *);
146 #define CURSOR_DRAW_DELAY (1)
148 /* # VBL ints between cursor state changes */
149 #define ATARI_CURSOR_BLINK_RATE (42)
150 #define MAC_CURSOR_BLINK_RATE (32)
151 #define DEFAULT_CURSOR_BLINK_RATE (20)
153 static int vbl_cursor_cnt;
155 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
158 * Interface used by the world
161 static const char *fbcon_startup(void);
162 static void fbcon_init(struct vc_data *vc, int init);
163 static void fbcon_deinit(struct vc_data *vc);
164 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
165 int width);
166 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
167 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
168 int count, int ypos, int xpos);
169 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
170 static void fbcon_cursor(struct vc_data *vc, int mode);
171 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
172 int count);
173 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
174 int height, int width);
175 static int fbcon_switch(struct vc_data *vc);
176 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
177 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
178 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
181 * Internal routines
183 static __inline__ void ywrap_up(struct vc_data *vc, int count);
184 static __inline__ void ywrap_down(struct vc_data *vc, int count);
185 static __inline__ void ypan_up(struct vc_data *vc, int count);
186 static __inline__ void ypan_down(struct vc_data *vc, int count);
187 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
188 int dy, int dx, int height, int width, u_int y_break);
189 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
190 struct vc_data *vc);
191 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
192 int unit);
193 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
194 int line, int count, int dy);
195 static void fbcon_modechanged(struct fb_info *info);
196 static void fbcon_set_all_vcs(struct fb_info *info);
198 #ifdef CONFIG_MAC
200 * On the Macintoy, there may or may not be a working VBL int. We need to probe
202 static int vbl_detected;
204 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
206 vbl_detected++;
207 return IRQ_HANDLED;
209 #endif
211 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
212 static inline void fbcon_set_rotation(struct fb_info *info)
214 struct fbcon_ops *ops = info->fbcon_par;
216 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
217 ops->p->con_rotate < 4)
218 ops->rotate = ops->p->con_rotate;
219 else
220 ops->rotate = 0;
223 static void fbcon_rotate(struct fb_info *info, u32 rotate)
225 struct fbcon_ops *ops= info->fbcon_par;
226 struct fb_info *fb_info;
228 if (!ops || ops->currcon == -1)
229 return;
231 fb_info = registered_fb[con2fb_map[ops->currcon]];
233 if (info == fb_info) {
234 struct display *p = &fb_display[ops->currcon];
236 if (rotate < 4)
237 p->con_rotate = rotate;
238 else
239 p->con_rotate = 0;
241 fbcon_modechanged(info);
245 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
247 struct fbcon_ops *ops = info->fbcon_par;
248 struct vc_data *vc;
249 struct display *p;
250 int i;
252 if (!ops || ops->currcon < 0 || rotate > 3)
253 return;
255 for (i = 0; i < MAX_NR_CONSOLES; i++) {
256 vc = vc_cons[i].d;
257 if (!vc || vc->vc_mode != KD_TEXT ||
258 registered_fb[con2fb_map[i]] != info)
259 continue;
261 p = &fb_display[vc->vc_num];
262 p->con_rotate = rotate;
265 fbcon_set_all_vcs(info);
267 #else
268 static inline void fbcon_set_rotation(struct fb_info *info)
270 struct fbcon_ops *ops = info->fbcon_par;
272 ops->rotate = FB_ROTATE_UR;
275 static void fbcon_rotate(struct fb_info *info, u32 rotate)
277 return;
280 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
282 return;
284 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
286 static int fbcon_get_rotate(struct fb_info *info)
288 struct fbcon_ops *ops = info->fbcon_par;
290 return (ops) ? ops->rotate : 0;
293 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
295 struct fbcon_ops *ops = info->fbcon_par;
297 return (info->state != FBINFO_STATE_RUNNING ||
298 vc->vc_mode != KD_TEXT || ops->graphics);
301 static inline int get_color(struct vc_data *vc, struct fb_info *info,
302 u16 c, int is_fg)
304 int depth = fb_get_color_depth(&info->var, &info->fix);
305 int color = 0;
307 if (console_blanked) {
308 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
310 c = vc->vc_video_erase_char & charmask;
313 if (depth != 1)
314 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
315 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
317 switch (depth) {
318 case 1:
320 int col = ~(0xfff << (max(info->var.green.length,
321 max(info->var.red.length,
322 info->var.blue.length)))) & 0xff;
324 /* 0 or 1 */
325 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
326 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
328 if (console_blanked)
329 fg = bg;
331 color = (is_fg) ? fg : bg;
332 break;
334 case 2:
336 * Scale down 16-colors to 4 colors. Default 4-color palette
337 * is grayscale. However, simply dividing the values by 4
338 * will not work, as colors 1, 2 and 3 will be scaled-down
339 * to zero rendering them invisible. So empirically convert
340 * colors to a sane 4-level grayscale.
342 switch (color) {
343 case 0:
344 color = 0; /* black */
345 break;
346 case 1 ... 6:
347 color = 2; /* white */
348 break;
349 case 7 ... 8:
350 color = 1; /* gray */
351 break;
352 default:
353 color = 3; /* intense white */
354 break;
356 break;
357 case 3:
359 * Last 8 entries of default 16-color palette is a more intense
360 * version of the first 8 (i.e., same chrominance, different
361 * luminance).
363 color &= 7;
364 break;
368 return color;
371 static void fbcon_update_softback(struct vc_data *vc)
373 int l = fbcon_softback_size / vc->vc_size_row;
375 if (l > 5)
376 softback_end = softback_buf + l * vc->vc_size_row;
377 else
378 /* Smaller scrollback makes no sense, and 0 would screw
379 the operation totally */
380 softback_top = 0;
383 static void fb_flashcursor(void *private)
385 struct fb_info *info = private;
386 struct fbcon_ops *ops = info->fbcon_par;
387 struct display *p;
388 struct vc_data *vc = NULL;
389 int c;
390 int mode;
392 if (ops->currcon != -1)
393 vc = vc_cons[ops->currcon].d;
395 if (!vc || !CON_IS_VISIBLE(vc) ||
396 fbcon_is_inactive(vc, info) ||
397 registered_fb[con2fb_map[vc->vc_num]] != info ||
398 vc_cons[ops->currcon].d->vc_deccm != 1)
399 return;
400 acquire_console_sem();
401 p = &fb_display[vc->vc_num];
402 c = scr_readw((u16 *) vc->vc_pos);
403 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
404 CM_ERASE : CM_DRAW;
405 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
406 get_color(vc, info, c, 0));
407 release_console_sem();
410 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
411 static int cursor_blink_rate;
412 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
414 struct fb_info *info = dev_id;
416 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
417 schedule_work(&info->queue);
418 vbl_cursor_cnt = cursor_blink_rate;
420 return IRQ_HANDLED;
422 #endif
424 static void cursor_timer_handler(unsigned long dev_addr)
426 struct fb_info *info = (struct fb_info *) dev_addr;
427 struct fbcon_ops *ops = info->fbcon_par;
429 schedule_work(&info->queue);
430 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
433 static void fbcon_add_cursor_timer(struct fb_info *info)
435 struct fbcon_ops *ops = info->fbcon_par;
437 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
438 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
439 if (!info->queue.func)
440 INIT_WORK(&info->queue, fb_flashcursor, info);
442 init_timer(&ops->cursor_timer);
443 ops->cursor_timer.function = cursor_timer_handler;
444 ops->cursor_timer.expires = jiffies + HZ / 5;
445 ops->cursor_timer.data = (unsigned long ) info;
446 add_timer(&ops->cursor_timer);
447 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
451 static void fbcon_del_cursor_timer(struct fb_info *info)
453 struct fbcon_ops *ops = info->fbcon_par;
455 if (info->queue.func == fb_flashcursor &&
456 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
457 del_timer_sync(&ops->cursor_timer);
458 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
462 #ifndef MODULE
463 static int __init fb_console_setup(char *this_opt)
465 char *options;
466 int i, j;
468 if (!this_opt || !*this_opt)
469 return 1;
471 while ((options = strsep(&this_opt, ",")) != NULL) {
472 if (!strncmp(options, "font:", 5))
473 strcpy(fontname, options + 5);
475 if (!strncmp(options, "scrollback:", 11)) {
476 options += 11;
477 if (*options) {
478 fbcon_softback_size = simple_strtoul(options, &options, 0);
479 if (*options == 'k' || *options == 'K') {
480 fbcon_softback_size *= 1024;
481 options++;
483 if (*options != ',')
484 return 1;
485 options++;
486 } else
487 return 1;
490 if (!strncmp(options, "map:", 4)) {
491 options += 4;
492 if (*options)
493 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
494 if (!options[j])
495 j = 0;
496 con2fb_map_boot[i] =
497 (options[j++]-'0') % FB_MAX;
499 return 1;
502 if (!strncmp(options, "vc:", 3)) {
503 options += 3;
504 if (*options)
505 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
506 if (first_fb_vc < 0)
507 first_fb_vc = 0;
508 if (*options++ == '-')
509 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
510 fbcon_is_default = 0;
513 if (!strncmp(options, "rotate:", 7)) {
514 options += 7;
515 if (*options)
516 rotate = simple_strtoul(options, &options, 0);
517 if (rotate > 3)
518 rotate = 0;
521 return 1;
524 __setup("fbcon=", fb_console_setup);
525 #endif
527 static int search_fb_in_map(int idx)
529 int i, retval = 0;
531 for (i = 0; i < MAX_NR_CONSOLES; i++) {
532 if (con2fb_map[i] == idx)
533 retval = 1;
535 return retval;
538 static int search_for_mapped_con(void)
540 int i, retval = 0;
542 for (i = 0; i < MAX_NR_CONSOLES; i++) {
543 if (con2fb_map[i] != -1)
544 retval = 1;
546 return retval;
549 static int fbcon_takeover(int show_logo)
551 int err, i;
553 if (!num_registered_fb)
554 return -ENODEV;
556 if (!show_logo)
557 logo_shown = FBCON_LOGO_DONTSHOW;
559 for (i = first_fb_vc; i <= last_fb_vc; i++)
560 con2fb_map[i] = info_idx;
562 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
563 fbcon_is_default);
564 if (err) {
565 for (i = first_fb_vc; i <= last_fb_vc; i++) {
566 con2fb_map[i] = -1;
568 info_idx = -1;
571 return err;
574 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
575 int cols, int rows, int new_cols, int new_rows)
577 /* Need to make room for the logo */
578 struct fbcon_ops *ops = info->fbcon_par;
579 int cnt, erase = vc->vc_video_erase_char, step;
580 unsigned short *save = NULL, *r, *q;
583 * remove underline attribute from erase character
584 * if black and white framebuffer.
586 if (fb_get_color_depth(&info->var, &info->fix) == 1)
587 erase &= ~0x400;
588 logo_height = fb_prepare_logo(info, ops->rotate);
589 logo_lines = (logo_height + vc->vc_font.height - 1) /
590 vc->vc_font.height;
591 q = (unsigned short *) (vc->vc_origin +
592 vc->vc_size_row * rows);
593 step = logo_lines * cols;
594 for (r = q - logo_lines * cols; r < q; r++)
595 if (scr_readw(r) != vc->vc_video_erase_char)
596 break;
597 if (r != q && new_rows >= rows + logo_lines) {
598 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
599 if (save) {
600 int i = cols < new_cols ? cols : new_cols;
601 scr_memsetw(save, erase, logo_lines * new_cols * 2);
602 r = q - step;
603 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
604 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
605 r = q;
608 if (r == q) {
609 /* We can scroll screen down */
610 r = q - step - cols;
611 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
612 scr_memcpyw(r + step, r, vc->vc_size_row);
613 r -= cols;
615 if (!save) {
616 vc->vc_y += logo_lines;
617 vc->vc_pos += logo_lines * vc->vc_size_row;
620 scr_memsetw((unsigned short *) vc->vc_origin,
621 erase,
622 vc->vc_size_row * logo_lines);
624 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
625 fbcon_clear_margins(vc, 0);
626 update_screen(vc);
629 if (save) {
630 q = (unsigned short *) (vc->vc_origin +
631 vc->vc_size_row *
632 rows);
633 scr_memcpyw(q, save, logo_lines * new_cols * 2);
634 vc->vc_y += logo_lines;
635 vc->vc_pos += logo_lines * vc->vc_size_row;
636 kfree(save);
639 if (logo_lines > vc->vc_bottom) {
640 logo_shown = FBCON_LOGO_CANSHOW;
641 printk(KERN_INFO
642 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
643 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
644 logo_shown = FBCON_LOGO_DRAW;
645 vc->vc_top = logo_lines;
649 #ifdef CONFIG_FB_TILEBLITTING
650 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
652 struct fbcon_ops *ops = info->fbcon_par;
654 ops->p = &fb_display[vc->vc_num];
656 if ((info->flags & FBINFO_MISC_TILEBLITTING))
657 fbcon_set_tileops(vc, info);
658 else {
659 fbcon_set_rotation(info);
660 fbcon_set_bitops(ops);
663 #else
664 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
666 struct fbcon_ops *ops = info->fbcon_par;
668 info->flags &= ~FBINFO_MISC_TILEBLITTING;
669 ops->p = &fb_display[vc->vc_num];
670 fbcon_set_rotation(info);
671 fbcon_set_bitops(ops);
673 #endif /* CONFIG_MISC_TILEBLITTING */
676 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
677 int unit, int oldidx)
679 struct fbcon_ops *ops = NULL;
680 int err = 0;
682 if (!try_module_get(info->fbops->owner))
683 err = -ENODEV;
685 if (!err && info->fbops->fb_open &&
686 info->fbops->fb_open(info, 0))
687 err = -ENODEV;
689 if (!err) {
690 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
691 if (!ops)
692 err = -ENOMEM;
695 if (!err) {
696 info->fbcon_par = ops;
697 set_blitting_type(vc, info);
700 if (err) {
701 con2fb_map[unit] = oldidx;
702 module_put(info->fbops->owner);
705 return err;
708 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
709 struct fb_info *newinfo, int unit,
710 int oldidx, int found)
712 struct fbcon_ops *ops = oldinfo->fbcon_par;
713 int err = 0;
715 if (oldinfo->fbops->fb_release &&
716 oldinfo->fbops->fb_release(oldinfo, 0)) {
717 con2fb_map[unit] = oldidx;
718 if (!found && newinfo->fbops->fb_release)
719 newinfo->fbops->fb_release(newinfo, 0);
720 if (!found)
721 module_put(newinfo->fbops->owner);
722 err = -ENODEV;
725 if (!err) {
726 fbcon_del_cursor_timer(oldinfo);
727 kfree(ops->cursor_state.mask);
728 kfree(ops->cursor_data);
729 kfree(ops->fontbuffer);
730 kfree(oldinfo->fbcon_par);
731 oldinfo->fbcon_par = NULL;
732 module_put(oldinfo->fbops->owner);
734 If oldinfo and newinfo are driving the same hardware,
735 the fb_release() method of oldinfo may attempt to
736 restore the hardware state. This will leave the
737 newinfo in an undefined state. Thus, a call to
738 fb_set_par() may be needed for the newinfo.
740 if (newinfo->fbops->fb_set_par)
741 newinfo->fbops->fb_set_par(newinfo);
744 return err;
747 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
748 int unit, int show_logo)
750 struct fbcon_ops *ops = info->fbcon_par;
752 ops->currcon = fg_console;
754 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
755 info->fbops->fb_set_par(info);
757 ops->flags |= FBCON_FLAGS_INIT;
758 ops->graphics = 0;
760 if (vc)
761 fbcon_set_disp(info, &info->var, vc);
762 else
763 fbcon_preset_disp(info, &info->var, unit);
765 if (show_logo) {
766 struct vc_data *fg_vc = vc_cons[fg_console].d;
767 struct fb_info *fg_info =
768 registered_fb[con2fb_map[fg_console]];
770 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
771 fg_vc->vc_rows, fg_vc->vc_cols,
772 fg_vc->vc_rows);
775 update_screen(vc_cons[fg_console].d);
779 * set_con2fb_map - map console to frame buffer device
780 * @unit: virtual console number to map
781 * @newidx: frame buffer index to map virtual console to
782 * @user: user request
784 * Maps a virtual console @unit to a frame buffer device
785 * @newidx.
787 static int set_con2fb_map(int unit, int newidx, int user)
789 struct vc_data *vc = vc_cons[unit].d;
790 int oldidx = con2fb_map[unit];
791 struct fb_info *info = registered_fb[newidx];
792 struct fb_info *oldinfo = NULL;
793 int found, err = 0;
795 if (oldidx == newidx)
796 return 0;
798 if (!info)
799 err = -EINVAL;
801 if (!err && !search_for_mapped_con()) {
802 info_idx = newidx;
803 return fbcon_takeover(0);
806 if (oldidx != -1)
807 oldinfo = registered_fb[oldidx];
809 found = search_fb_in_map(newidx);
811 acquire_console_sem();
812 con2fb_map[unit] = newidx;
813 if (!err && !found)
814 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
818 * If old fb is not mapped to any of the consoles,
819 * fbcon should release it.
821 if (!err && oldinfo && !search_fb_in_map(oldidx))
822 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
823 found);
825 if (!err) {
826 int show_logo = (fg_console == 0 && !user &&
827 logo_shown != FBCON_LOGO_DONTSHOW);
829 if (!found)
830 fbcon_add_cursor_timer(info);
831 con2fb_map_boot[unit] = newidx;
832 con2fb_init_display(vc, info, unit, show_logo);
835 release_console_sem();
836 return err;
840 * Low Level Operations
842 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
843 static int var_to_display(struct display *disp,
844 struct fb_var_screeninfo *var,
845 struct fb_info *info)
847 disp->xres_virtual = var->xres_virtual;
848 disp->yres_virtual = var->yres_virtual;
849 disp->bits_per_pixel = var->bits_per_pixel;
850 disp->grayscale = var->grayscale;
851 disp->nonstd = var->nonstd;
852 disp->accel_flags = var->accel_flags;
853 disp->height = var->height;
854 disp->width = var->width;
855 disp->red = var->red;
856 disp->green = var->green;
857 disp->blue = var->blue;
858 disp->transp = var->transp;
859 disp->rotate = var->rotate;
860 disp->mode = fb_match_mode(var, &info->modelist);
861 if (disp->mode == NULL)
862 /* This should not happen */
863 return -EINVAL;
864 return 0;
867 static void display_to_var(struct fb_var_screeninfo *var,
868 struct display *disp)
870 fb_videomode_to_var(var, disp->mode);
871 var->xres_virtual = disp->xres_virtual;
872 var->yres_virtual = disp->yres_virtual;
873 var->bits_per_pixel = disp->bits_per_pixel;
874 var->grayscale = disp->grayscale;
875 var->nonstd = disp->nonstd;
876 var->accel_flags = disp->accel_flags;
877 var->height = disp->height;
878 var->width = disp->width;
879 var->red = disp->red;
880 var->green = disp->green;
881 var->blue = disp->blue;
882 var->transp = disp->transp;
883 var->rotate = disp->rotate;
886 static const char *fbcon_startup(void)
888 const char *display_desc = "frame buffer device";
889 struct display *p = &fb_display[fg_console];
890 struct vc_data *vc = vc_cons[fg_console].d;
891 const struct font_desc *font = NULL;
892 struct module *owner;
893 struct fb_info *info = NULL;
894 struct fbcon_ops *ops;
895 int rows, cols;
896 int irqres;
898 irqres = 1;
900 * If num_registered_fb is zero, this is a call for the dummy part.
901 * The frame buffer devices weren't initialized yet.
903 if (!num_registered_fb || info_idx == -1)
904 return display_desc;
906 * Instead of blindly using registered_fb[0], we use info_idx, set by
907 * fb_console_init();
909 info = registered_fb[info_idx];
910 if (!info)
911 return NULL;
913 owner = info->fbops->owner;
914 if (!try_module_get(owner))
915 return NULL;
916 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
917 module_put(owner);
918 return NULL;
921 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
922 if (!ops) {
923 module_put(owner);
924 return NULL;
927 ops->currcon = -1;
928 ops->graphics = 1;
929 ops->cur_rotate = -1;
930 info->fbcon_par = ops;
931 p->con_rotate = rotate;
932 set_blitting_type(vc, info);
934 if (info->fix.type != FB_TYPE_TEXT) {
935 if (fbcon_softback_size) {
936 if (!softback_buf) {
937 softback_buf =
938 (unsigned long)
939 kmalloc(fbcon_softback_size,
940 GFP_KERNEL);
941 if (!softback_buf) {
942 fbcon_softback_size = 0;
943 softback_top = 0;
946 } else {
947 if (softback_buf) {
948 kfree((void *) softback_buf);
949 softback_buf = 0;
950 softback_top = 0;
953 if (softback_buf)
954 softback_in = softback_top = softback_curr =
955 softback_buf;
956 softback_lines = 0;
959 /* Setup default font */
960 if (!p->fontdata) {
961 if (!fontname[0] || !(font = find_font(fontname)))
962 font = get_default_font(info->var.xres,
963 info->var.yres);
964 vc->vc_font.width = font->width;
965 vc->vc_font.height = font->height;
966 vc->vc_font.data = (void *)(p->fontdata = font->data);
967 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
970 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
971 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
972 cols /= vc->vc_font.width;
973 rows /= vc->vc_font.height;
974 vc_resize(vc, cols, rows);
976 DPRINTK("mode: %s\n", info->fix.id);
977 DPRINTK("visual: %d\n", info->fix.visual);
978 DPRINTK("res: %dx%d-%d\n", info->var.xres,
979 info->var.yres,
980 info->var.bits_per_pixel);
982 #ifdef CONFIG_ATARI
983 if (MACH_IS_ATARI) {
984 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
985 irqres =
986 request_irq(IRQ_AUTO_4, fb_vbl_handler,
987 IRQ_TYPE_PRIO, "framebuffer vbl",
988 info);
990 #endif /* CONFIG_ATARI */
992 #ifdef CONFIG_MAC
994 * On a Macintoy, the VBL interrupt may or may not be active.
995 * As interrupt based cursor is more reliable and race free, we
996 * probe for VBL interrupts.
998 if (MACH_IS_MAC) {
999 int ct = 0;
1001 * Probe for VBL: set temp. handler ...
1003 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1004 "framebuffer vbl", info);
1005 vbl_detected = 0;
1008 * ... and spin for 20 ms ...
1010 while (!vbl_detected && ++ct < 1000)
1011 udelay(20);
1013 if (ct == 1000)
1014 printk
1015 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1017 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1019 if (vbl_detected) {
1021 * interrupt based cursor ok
1023 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1024 irqres =
1025 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1026 "framebuffer vbl", info);
1027 } else {
1029 * VBL not detected: fall through, use timer based cursor
1031 irqres = 1;
1034 #endif /* CONFIG_MAC */
1036 fbcon_add_cursor_timer(info);
1037 return display_desc;
1040 static void fbcon_init(struct vc_data *vc, int init)
1042 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1043 struct fbcon_ops *ops;
1044 struct vc_data **default_mode = vc->vc_display_fg;
1045 struct vc_data *svc = *default_mode;
1046 struct display *t, *p = &fb_display[vc->vc_num];
1047 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1048 int cap;
1050 if (info_idx == -1 || info == NULL)
1051 return;
1053 cap = info->flags;
1055 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1056 (info->fix.type == FB_TYPE_TEXT))
1057 logo = 0;
1059 if (var_to_display(p, &info->var, info))
1060 return;
1062 /* If we are not the first console on this
1063 fb, copy the font from that console */
1064 t = &fb_display[svc->vc_num];
1065 if (!vc->vc_font.data) {
1066 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1067 vc->vc_font.width = (*default_mode)->vc_font.width;
1068 vc->vc_font.height = (*default_mode)->vc_font.height;
1069 p->userfont = t->userfont;
1070 if (p->userfont)
1071 REFCOUNT(p->fontdata)++;
1073 if (p->userfont)
1074 charcnt = FNTCHARCNT(p->fontdata);
1075 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1076 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1077 if (charcnt == 256) {
1078 vc->vc_hi_font_mask = 0;
1079 } else {
1080 vc->vc_hi_font_mask = 0x100;
1081 if (vc->vc_can_do_color)
1082 vc->vc_complement_mask <<= 1;
1085 if (!*svc->vc_uni_pagedir_loc)
1086 con_set_default_unimap(svc);
1087 if (!*vc->vc_uni_pagedir_loc)
1088 con_copy_unimap(vc, svc);
1090 ops = info->fbcon_par;
1091 p->con_rotate = rotate;
1092 set_blitting_type(vc, info);
1094 cols = vc->vc_cols;
1095 rows = vc->vc_rows;
1096 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1097 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1098 new_cols /= vc->vc_font.width;
1099 new_rows /= vc->vc_font.height;
1100 vc_resize(vc, new_cols, new_rows);
1103 * We must always set the mode. The mode of the previous console
1104 * driver could be in the same resolution but we are using different
1105 * hardware so we have to initialize the hardware.
1107 * We need to do it in fbcon_init() to prevent screen corruption.
1109 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1110 if (info->fbops->fb_set_par &&
1111 !(ops->flags & FBCON_FLAGS_INIT))
1112 info->fbops->fb_set_par(info);
1113 ops->flags |= FBCON_FLAGS_INIT;
1116 ops->graphics = 0;
1118 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1119 !(cap & FBINFO_HWACCEL_DISABLED))
1120 p->scrollmode = SCROLL_MOVE;
1121 else /* default to something safe */
1122 p->scrollmode = SCROLL_REDRAW;
1125 * ++guenther: console.c:vc_allocate() relies on initializing
1126 * vc_{cols,rows}, but we must not set those if we are only
1127 * resizing the console.
1129 if (!init) {
1130 vc->vc_cols = new_cols;
1131 vc->vc_rows = new_rows;
1134 if (logo)
1135 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1137 if (vc == svc && softback_buf)
1138 fbcon_update_softback(vc);
1140 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1141 ops->rotate = FB_ROTATE_UR;
1142 set_blitting_type(vc, info);
1145 ops->p = &fb_display[fg_console];
1148 static void fbcon_deinit(struct vc_data *vc)
1150 struct display *p = &fb_display[vc->vc_num];
1152 if (info_idx != -1)
1153 return;
1154 fbcon_free_font(p);
1157 /* ====================================================================== */
1159 /* fbcon_XXX routines - interface used by the world
1161 * This system is now divided into two levels because of complications
1162 * caused by hardware scrolling. Top level functions:
1164 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1166 * handles y values in range [0, scr_height-1] that correspond to real
1167 * screen positions. y_wrap shift means that first line of bitmap may be
1168 * anywhere on this display. These functions convert lineoffsets to
1169 * bitmap offsets and deal with the wrap-around case by splitting blits.
1171 * fbcon_bmove_physical_8() -- These functions fast implementations
1172 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1173 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1175 * WARNING:
1177 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1178 * Implies should only really hardware scroll in rows. Only reason for
1179 * restriction is simplicity & efficiency at the moment.
1182 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1183 int width)
1185 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1186 struct fbcon_ops *ops = info->fbcon_par;
1188 struct display *p = &fb_display[vc->vc_num];
1189 u_int y_break;
1191 if (fbcon_is_inactive(vc, info))
1192 return;
1194 if (!height || !width)
1195 return;
1197 /* Split blits that cross physical y_wrap boundary */
1199 y_break = p->vrows - p->yscroll;
1200 if (sy < y_break && sy + height - 1 >= y_break) {
1201 u_int b = y_break - sy;
1202 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1203 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1204 width);
1205 } else
1206 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1209 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1210 int count, int ypos, int xpos)
1212 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1213 struct display *p = &fb_display[vc->vc_num];
1214 struct fbcon_ops *ops = info->fbcon_par;
1216 if (!fbcon_is_inactive(vc, info))
1217 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1218 get_color(vc, info, scr_readw(s), 1),
1219 get_color(vc, info, scr_readw(s), 0));
1222 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1224 unsigned short chr;
1226 scr_writew(c, &chr);
1227 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1230 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1232 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1233 struct fbcon_ops *ops = info->fbcon_par;
1235 if (!fbcon_is_inactive(vc, info))
1236 ops->clear_margins(vc, info, bottom_only);
1239 static void fbcon_cursor(struct vc_data *vc, int mode)
1241 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1242 struct fbcon_ops *ops = info->fbcon_par;
1243 int y;
1244 int c = scr_readw((u16 *) vc->vc_pos);
1246 if (fbcon_is_inactive(vc, info))
1247 return;
1249 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1250 if (mode & CM_SOFTBACK) {
1251 mode &= ~CM_SOFTBACK;
1252 y = softback_lines;
1253 } else {
1254 if (softback_lines)
1255 fbcon_set_origin(vc);
1256 y = 0;
1259 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1260 get_color(vc, info, c, 0));
1261 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1264 static int scrollback_phys_max = 0;
1265 static int scrollback_max = 0;
1266 static int scrollback_current = 0;
1269 * If no vc is existent yet, just set struct display
1271 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1272 int unit)
1274 struct display *p = &fb_display[unit];
1275 struct display *t = &fb_display[fg_console];
1277 if (var_to_display(p, var, info))
1278 return;
1280 p->fontdata = t->fontdata;
1281 p->userfont = t->userfont;
1282 if (p->userfont)
1283 REFCOUNT(p->fontdata)++;
1286 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1287 struct vc_data *vc)
1289 struct display *p = &fb_display[vc->vc_num], *t;
1290 struct vc_data **default_mode = vc->vc_display_fg;
1291 struct vc_data *svc = *default_mode;
1292 struct fbcon_ops *ops = info->fbcon_par;
1293 int rows, cols, charcnt = 256;
1295 if (var_to_display(p, var, info))
1296 return;
1297 t = &fb_display[svc->vc_num];
1298 if (!vc->vc_font.data) {
1299 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1300 vc->vc_font.width = (*default_mode)->vc_font.width;
1301 vc->vc_font.height = (*default_mode)->vc_font.height;
1302 p->userfont = t->userfont;
1303 if (p->userfont)
1304 REFCOUNT(p->fontdata)++;
1306 if (p->userfont)
1307 charcnt = FNTCHARCNT(p->fontdata);
1309 var->activate = FB_ACTIVATE_NOW;
1310 info->var.activate = var->activate;
1311 var->yoffset = info->var.yoffset;
1312 var->xoffset = info->var.xoffset;
1313 fb_set_var(info, var);
1314 ops->var = info->var;
1315 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1316 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1317 if (charcnt == 256) {
1318 vc->vc_hi_font_mask = 0;
1319 } else {
1320 vc->vc_hi_font_mask = 0x100;
1321 if (vc->vc_can_do_color)
1322 vc->vc_complement_mask <<= 1;
1325 if (!*svc->vc_uni_pagedir_loc)
1326 con_set_default_unimap(svc);
1327 if (!*vc->vc_uni_pagedir_loc)
1328 con_copy_unimap(vc, svc);
1330 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1331 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1332 cols /= vc->vc_font.width;
1333 rows /= vc->vc_font.height;
1334 vc_resize(vc, cols, rows);
1336 if (CON_IS_VISIBLE(vc)) {
1337 update_screen(vc);
1338 if (softback_buf)
1339 fbcon_update_softback(vc);
1343 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1345 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1346 struct fbcon_ops *ops = info->fbcon_par;
1347 struct display *p = &fb_display[vc->vc_num];
1349 p->yscroll += count;
1350 if (p->yscroll >= p->vrows) /* Deal with wrap */
1351 p->yscroll -= p->vrows;
1352 ops->var.xoffset = 0;
1353 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1354 ops->var.vmode |= FB_VMODE_YWRAP;
1355 ops->update_start(info);
1356 scrollback_max += count;
1357 if (scrollback_max > scrollback_phys_max)
1358 scrollback_max = scrollback_phys_max;
1359 scrollback_current = 0;
1362 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1364 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1365 struct fbcon_ops *ops = info->fbcon_par;
1366 struct display *p = &fb_display[vc->vc_num];
1368 p->yscroll -= count;
1369 if (p->yscroll < 0) /* Deal with wrap */
1370 p->yscroll += p->vrows;
1371 ops->var.xoffset = 0;
1372 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1373 ops->var.vmode |= FB_VMODE_YWRAP;
1374 ops->update_start(info);
1375 scrollback_max -= count;
1376 if (scrollback_max < 0)
1377 scrollback_max = 0;
1378 scrollback_current = 0;
1381 static __inline__ void ypan_up(struct vc_data *vc, int count)
1383 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1384 struct display *p = &fb_display[vc->vc_num];
1385 struct fbcon_ops *ops = info->fbcon_par;
1387 p->yscroll += count;
1388 if (p->yscroll > p->vrows - vc->vc_rows) {
1389 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1390 0, 0, 0, vc->vc_rows, vc->vc_cols);
1391 p->yscroll -= p->vrows - vc->vc_rows;
1394 ops->var.xoffset = 0;
1395 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1396 ops->var.vmode &= ~FB_VMODE_YWRAP;
1397 ops->update_start(info);
1398 fbcon_clear_margins(vc, 1);
1399 scrollback_max += count;
1400 if (scrollback_max > scrollback_phys_max)
1401 scrollback_max = scrollback_phys_max;
1402 scrollback_current = 0;
1405 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1407 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1408 struct fbcon_ops *ops = info->fbcon_par;
1409 struct display *p = &fb_display[vc->vc_num];
1411 p->yscroll += count;
1413 if (p->yscroll > p->vrows - vc->vc_rows) {
1414 p->yscroll -= p->vrows - vc->vc_rows;
1415 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1418 ops->var.xoffset = 0;
1419 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1420 ops->var.vmode &= ~FB_VMODE_YWRAP;
1421 ops->update_start(info);
1422 fbcon_clear_margins(vc, 1);
1423 scrollback_max += count;
1424 if (scrollback_max > scrollback_phys_max)
1425 scrollback_max = scrollback_phys_max;
1426 scrollback_current = 0;
1429 static __inline__ void ypan_down(struct vc_data *vc, int count)
1431 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1432 struct display *p = &fb_display[vc->vc_num];
1433 struct fbcon_ops *ops = info->fbcon_par;
1435 p->yscroll -= count;
1436 if (p->yscroll < 0) {
1437 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1438 0, vc->vc_rows, vc->vc_cols);
1439 p->yscroll += p->vrows - vc->vc_rows;
1442 ops->var.xoffset = 0;
1443 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1444 ops->var.vmode &= ~FB_VMODE_YWRAP;
1445 ops->update_start(info);
1446 fbcon_clear_margins(vc, 1);
1447 scrollback_max -= count;
1448 if (scrollback_max < 0)
1449 scrollback_max = 0;
1450 scrollback_current = 0;
1453 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1455 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1456 struct fbcon_ops *ops = info->fbcon_par;
1457 struct display *p = &fb_display[vc->vc_num];
1459 p->yscroll -= count;
1461 if (p->yscroll < 0) {
1462 p->yscroll += p->vrows - vc->vc_rows;
1463 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1466 ops->var.xoffset = 0;
1467 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1468 ops->var.vmode &= ~FB_VMODE_YWRAP;
1469 ops->update_start(info);
1470 fbcon_clear_margins(vc, 1);
1471 scrollback_max -= count;
1472 if (scrollback_max < 0)
1473 scrollback_max = 0;
1474 scrollback_current = 0;
1477 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1478 long delta)
1480 int count = vc->vc_rows;
1481 unsigned short *d, *s;
1482 unsigned long n;
1483 int line = 0;
1485 d = (u16 *) softback_curr;
1486 if (d == (u16 *) softback_in)
1487 d = (u16 *) vc->vc_origin;
1488 n = softback_curr + delta * vc->vc_size_row;
1489 softback_lines -= delta;
1490 if (delta < 0) {
1491 if (softback_curr < softback_top && n < softback_buf) {
1492 n += softback_end - softback_buf;
1493 if (n < softback_top) {
1494 softback_lines -=
1495 (softback_top - n) / vc->vc_size_row;
1496 n = softback_top;
1498 } else if (softback_curr >= softback_top
1499 && n < softback_top) {
1500 softback_lines -=
1501 (softback_top - n) / vc->vc_size_row;
1502 n = softback_top;
1504 } else {
1505 if (softback_curr > softback_in && n >= softback_end) {
1506 n += softback_buf - softback_end;
1507 if (n > softback_in) {
1508 n = softback_in;
1509 softback_lines = 0;
1511 } else if (softback_curr <= softback_in && n > softback_in) {
1512 n = softback_in;
1513 softback_lines = 0;
1516 if (n == softback_curr)
1517 return;
1518 softback_curr = n;
1519 s = (u16 *) softback_curr;
1520 if (s == (u16 *) softback_in)
1521 s = (u16 *) vc->vc_origin;
1522 while (count--) {
1523 unsigned short *start;
1524 unsigned short *le;
1525 unsigned short c;
1526 int x = 0;
1527 unsigned short attr = 1;
1529 start = s;
1530 le = advance_row(s, 1);
1531 do {
1532 c = scr_readw(s);
1533 if (attr != (c & 0xff00)) {
1534 attr = c & 0xff00;
1535 if (s > start) {
1536 fbcon_putcs(vc, start, s - start,
1537 line, x);
1538 x += s - start;
1539 start = s;
1542 if (c == scr_readw(d)) {
1543 if (s > start) {
1544 fbcon_putcs(vc, start, s - start,
1545 line, x);
1546 x += s - start + 1;
1547 start = s + 1;
1548 } else {
1549 x++;
1550 start++;
1553 s++;
1554 d++;
1555 } while (s < le);
1556 if (s > start)
1557 fbcon_putcs(vc, start, s - start, line, x);
1558 line++;
1559 if (d == (u16 *) softback_end)
1560 d = (u16 *) softback_buf;
1561 if (d == (u16 *) softback_in)
1562 d = (u16 *) vc->vc_origin;
1563 if (s == (u16 *) softback_end)
1564 s = (u16 *) softback_buf;
1565 if (s == (u16 *) softback_in)
1566 s = (u16 *) vc->vc_origin;
1570 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1571 int line, int count, int dy)
1573 unsigned short *s = (unsigned short *)
1574 (vc->vc_origin + vc->vc_size_row * line);
1576 while (count--) {
1577 unsigned short *start = s;
1578 unsigned short *le = advance_row(s, 1);
1579 unsigned short c;
1580 int x = 0;
1581 unsigned short attr = 1;
1583 do {
1584 c = scr_readw(s);
1585 if (attr != (c & 0xff00)) {
1586 attr = c & 0xff00;
1587 if (s > start) {
1588 fbcon_putcs(vc, start, s - start,
1589 dy, x);
1590 x += s - start;
1591 start = s;
1594 console_conditional_schedule();
1595 s++;
1596 } while (s < le);
1597 if (s > start)
1598 fbcon_putcs(vc, start, s - start, dy, x);
1599 console_conditional_schedule();
1600 dy++;
1604 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1605 int line, int count, int offset)
1607 unsigned short *d = (unsigned short *)
1608 (vc->vc_origin + vc->vc_size_row * line);
1609 unsigned short *s = d + offset;
1611 while (count--) {
1612 unsigned short *start = s;
1613 unsigned short *le = advance_row(s, 1);
1614 unsigned short c;
1615 int x = 0;
1616 unsigned short attr = 1;
1618 do {
1619 c = scr_readw(s);
1620 if (attr != (c & 0xff00)) {
1621 attr = c & 0xff00;
1622 if (s > start) {
1623 fbcon_putcs(vc, start, s - start,
1624 line, x);
1625 x += s - start;
1626 start = s;
1629 if (c == scr_readw(d)) {
1630 if (s > start) {
1631 fbcon_putcs(vc, start, s - start,
1632 line, x);
1633 x += s - start + 1;
1634 start = s + 1;
1635 } else {
1636 x++;
1637 start++;
1640 scr_writew(c, d);
1641 console_conditional_schedule();
1642 s++;
1643 d++;
1644 } while (s < le);
1645 if (s > start)
1646 fbcon_putcs(vc, start, s - start, line, x);
1647 console_conditional_schedule();
1648 if (offset > 0)
1649 line++;
1650 else {
1651 line--;
1652 /* NOTE: We subtract two lines from these pointers */
1653 s -= vc->vc_size_row;
1654 d -= vc->vc_size_row;
1659 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1660 int count)
1662 unsigned short *p;
1664 if (vc->vc_num != fg_console)
1665 return;
1666 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1668 while (count) {
1669 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1670 count--;
1671 p = advance_row(p, 1);
1672 softback_in += vc->vc_size_row;
1673 if (softback_in == softback_end)
1674 softback_in = softback_buf;
1675 if (softback_in == softback_top) {
1676 softback_top += vc->vc_size_row;
1677 if (softback_top == softback_end)
1678 softback_top = softback_buf;
1681 softback_curr = softback_in;
1684 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1685 int count)
1687 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1688 struct display *p = &fb_display[vc->vc_num];
1689 struct fbcon_ops *ops = info->fbcon_par;
1690 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1692 if (fbcon_is_inactive(vc, info))
1693 return -EINVAL;
1695 fbcon_cursor(vc, CM_ERASE);
1698 * ++Geert: Only use ywrap/ypan if the console is in text mode
1699 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1700 * whole screen (prevents flicker).
1703 switch (dir) {
1704 case SM_UP:
1705 if (count > vc->vc_rows) /* Maximum realistic size */
1706 count = vc->vc_rows;
1707 if (softback_top)
1708 fbcon_softback_note(vc, t, count);
1709 if (logo_shown >= 0)
1710 goto redraw_up;
1711 switch (p->scrollmode) {
1712 case SCROLL_MOVE:
1713 ops->bmove(vc, info, t + count, 0, t, 0,
1714 b - t - count, vc->vc_cols);
1715 ops->clear(vc, info, b - count, 0, count,
1716 vc->vc_cols);
1717 break;
1719 case SCROLL_WRAP_MOVE:
1720 if (b - t - count > 3 * vc->vc_rows >> 2) {
1721 if (t > 0)
1722 fbcon_bmove(vc, 0, 0, count, 0, t,
1723 vc->vc_cols);
1724 ywrap_up(vc, count);
1725 if (vc->vc_rows - b > 0)
1726 fbcon_bmove(vc, b - count, 0, b, 0,
1727 vc->vc_rows - b,
1728 vc->vc_cols);
1729 } else if (info->flags & FBINFO_READS_FAST)
1730 fbcon_bmove(vc, t + count, 0, t, 0,
1731 b - t - count, vc->vc_cols);
1732 else
1733 goto redraw_up;
1734 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1735 break;
1737 case SCROLL_PAN_REDRAW:
1738 if ((p->yscroll + count <=
1739 2 * (p->vrows - vc->vc_rows))
1740 && ((!scroll_partial && (b - t == vc->vc_rows))
1741 || (scroll_partial
1742 && (b - t - count >
1743 3 * vc->vc_rows >> 2)))) {
1744 if (t > 0)
1745 fbcon_redraw_move(vc, p, 0, t, count);
1746 ypan_up_redraw(vc, t, count);
1747 if (vc->vc_rows - b > 0)
1748 fbcon_redraw_move(vc, p, b,
1749 vc->vc_rows - b, b);
1750 } else
1751 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1752 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1753 break;
1755 case SCROLL_PAN_MOVE:
1756 if ((p->yscroll + count <=
1757 2 * (p->vrows - vc->vc_rows))
1758 && ((!scroll_partial && (b - t == vc->vc_rows))
1759 || (scroll_partial
1760 && (b - t - count >
1761 3 * vc->vc_rows >> 2)))) {
1762 if (t > 0)
1763 fbcon_bmove(vc, 0, 0, count, 0, t,
1764 vc->vc_cols);
1765 ypan_up(vc, count);
1766 if (vc->vc_rows - b > 0)
1767 fbcon_bmove(vc, b - count, 0, b, 0,
1768 vc->vc_rows - b,
1769 vc->vc_cols);
1770 } else if (info->flags & FBINFO_READS_FAST)
1771 fbcon_bmove(vc, t + count, 0, t, 0,
1772 b - t - count, vc->vc_cols);
1773 else
1774 goto redraw_up;
1775 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1776 break;
1778 case SCROLL_REDRAW:
1779 redraw_up:
1780 fbcon_redraw(vc, p, t, b - t - count,
1781 count * vc->vc_cols);
1782 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1783 scr_memsetw((unsigned short *) (vc->vc_origin +
1784 vc->vc_size_row *
1785 (b - count)),
1786 vc->vc_video_erase_char,
1787 vc->vc_size_row * count);
1788 return 1;
1790 break;
1792 case SM_DOWN:
1793 if (count > vc->vc_rows) /* Maximum realistic size */
1794 count = vc->vc_rows;
1795 if (logo_shown >= 0)
1796 goto redraw_down;
1797 switch (p->scrollmode) {
1798 case SCROLL_MOVE:
1799 ops->bmove(vc, info, t, 0, t + count, 0,
1800 b - t - count, vc->vc_cols);
1801 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1802 break;
1804 case SCROLL_WRAP_MOVE:
1805 if (b - t - count > 3 * vc->vc_rows >> 2) {
1806 if (vc->vc_rows - b > 0)
1807 fbcon_bmove(vc, b, 0, b - count, 0,
1808 vc->vc_rows - b,
1809 vc->vc_cols);
1810 ywrap_down(vc, count);
1811 if (t > 0)
1812 fbcon_bmove(vc, count, 0, 0, 0, t,
1813 vc->vc_cols);
1814 } else if (info->flags & FBINFO_READS_FAST)
1815 fbcon_bmove(vc, t, 0, t + count, 0,
1816 b - t - count, vc->vc_cols);
1817 else
1818 goto redraw_down;
1819 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1820 break;
1822 case SCROLL_PAN_MOVE:
1823 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1824 && ((!scroll_partial && (b - t == vc->vc_rows))
1825 || (scroll_partial
1826 && (b - t - count >
1827 3 * vc->vc_rows >> 2)))) {
1828 if (vc->vc_rows - b > 0)
1829 fbcon_bmove(vc, b, 0, b - count, 0,
1830 vc->vc_rows - b,
1831 vc->vc_cols);
1832 ypan_down(vc, count);
1833 if (t > 0)
1834 fbcon_bmove(vc, count, 0, 0, 0, t,
1835 vc->vc_cols);
1836 } else if (info->flags & FBINFO_READS_FAST)
1837 fbcon_bmove(vc, t, 0, t + count, 0,
1838 b - t - count, vc->vc_cols);
1839 else
1840 goto redraw_down;
1841 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1842 break;
1844 case SCROLL_PAN_REDRAW:
1845 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1846 && ((!scroll_partial && (b - t == vc->vc_rows))
1847 || (scroll_partial
1848 && (b - t - count >
1849 3 * vc->vc_rows >> 2)))) {
1850 if (vc->vc_rows - b > 0)
1851 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1852 b - count);
1853 ypan_down_redraw(vc, t, count);
1854 if (t > 0)
1855 fbcon_redraw_move(vc, p, count, t, 0);
1856 } else
1857 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1858 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1859 break;
1861 case SCROLL_REDRAW:
1862 redraw_down:
1863 fbcon_redraw(vc, p, b - 1, b - t - count,
1864 -count * vc->vc_cols);
1865 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1866 scr_memsetw((unsigned short *) (vc->vc_origin +
1867 vc->vc_size_row *
1869 vc->vc_video_erase_char,
1870 vc->vc_size_row * count);
1871 return 1;
1874 return 0;
1878 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1879 int height, int width)
1881 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1882 struct display *p = &fb_display[vc->vc_num];
1884 if (fbcon_is_inactive(vc, info))
1885 return;
1887 if (!width || !height)
1888 return;
1890 /* Split blits that cross physical y_wrap case.
1891 * Pathological case involves 4 blits, better to use recursive
1892 * code rather than unrolled case
1894 * Recursive invocations don't need to erase the cursor over and
1895 * over again, so we use fbcon_bmove_rec()
1897 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1898 p->vrows - p->yscroll);
1901 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1902 int dy, int dx, int height, int width, u_int y_break)
1904 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1905 struct fbcon_ops *ops = info->fbcon_par;
1906 u_int b;
1908 if (sy < y_break && sy + height > y_break) {
1909 b = y_break - sy;
1910 if (dy < sy) { /* Avoid trashing self */
1911 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1912 y_break);
1913 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1914 height - b, width, y_break);
1915 } else {
1916 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1917 height - b, width, y_break);
1918 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1919 y_break);
1921 return;
1924 if (dy < y_break && dy + height > y_break) {
1925 b = y_break - dy;
1926 if (dy < sy) { /* Avoid trashing self */
1927 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1928 y_break);
1929 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1930 height - b, width, y_break);
1931 } else {
1932 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1933 height - b, width, y_break);
1934 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1935 y_break);
1937 return;
1939 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1940 height, width);
1943 static __inline__ void updatescrollmode(struct display *p,
1944 struct fb_info *info,
1945 struct vc_data *vc)
1947 struct fbcon_ops *ops = info->fbcon_par;
1948 int fh = vc->vc_font.height;
1949 int cap = info->flags;
1950 u16 t = 0;
1951 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1952 info->fix.xpanstep);
1953 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1954 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1955 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1956 info->var.xres_virtual);
1957 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1958 divides(ypan, vc->vc_font.height) && vyres > yres;
1959 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1960 divides(ywrap, vc->vc_font.height) &&
1961 divides(vc->vc_font.height, vyres) &&
1962 divides(vc->vc_font.height, yres);
1963 int reading_fast = cap & FBINFO_READS_FAST;
1964 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1965 !(cap & FBINFO_HWACCEL_DISABLED);
1966 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1967 !(cap & FBINFO_HWACCEL_DISABLED);
1969 p->vrows = vyres/fh;
1970 if (yres > (fh * (vc->vc_rows + 1)))
1971 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1972 if ((yres % fh) && (vyres % fh < yres % fh))
1973 p->vrows--;
1975 if (good_wrap || good_pan) {
1976 if (reading_fast || fast_copyarea)
1977 p->scrollmode = good_wrap ?
1978 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1979 else
1980 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1981 SCROLL_PAN_REDRAW;
1982 } else {
1983 if (reading_fast || (fast_copyarea && !fast_imageblit))
1984 p->scrollmode = SCROLL_MOVE;
1985 else
1986 p->scrollmode = SCROLL_REDRAW;
1990 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1991 unsigned int height)
1993 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1994 struct fbcon_ops *ops = info->fbcon_par;
1995 struct display *p = &fb_display[vc->vc_num];
1996 struct fb_var_screeninfo var = info->var;
1997 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
1999 virt_w = FBCON_SWAP(ops->rotate, width, height);
2000 virt_h = FBCON_SWAP(ops->rotate, height, width);
2001 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2002 vc->vc_font.height);
2003 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2004 vc->vc_font.width);
2005 var.xres = virt_w * virt_fw;
2006 var.yres = virt_h * virt_fh;
2007 x_diff = info->var.xres - var.xres;
2008 y_diff = info->var.yres - var.yres;
2009 if (x_diff < 0 || x_diff > virt_fw ||
2010 y_diff < 0 || y_diff > virt_fh) {
2011 struct fb_videomode *mode;
2013 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2014 mode = fb_find_best_mode(&var, &info->modelist);
2015 if (mode == NULL)
2016 return -EINVAL;
2017 display_to_var(&var, p);
2018 fb_videomode_to_var(&var, mode);
2020 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2021 return -EINVAL;
2023 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2024 if (CON_IS_VISIBLE(vc)) {
2025 var.activate = FB_ACTIVATE_NOW |
2026 FB_ACTIVATE_FORCE;
2027 fb_set_var(info, &var);
2029 var_to_display(p, &info->var, info);
2030 ops->var = info->var;
2032 updatescrollmode(p, info, vc);
2033 return 0;
2036 static int fbcon_switch(struct vc_data *vc)
2038 struct fb_info *info, *old_info = NULL;
2039 struct fbcon_ops *ops;
2040 struct display *p = &fb_display[vc->vc_num];
2041 struct fb_var_screeninfo var;
2042 int i, prev_console, charcnt = 256;
2044 info = registered_fb[con2fb_map[vc->vc_num]];
2045 ops = info->fbcon_par;
2047 if (softback_top) {
2048 if (softback_lines)
2049 fbcon_set_origin(vc);
2050 softback_top = softback_curr = softback_in = softback_buf;
2051 softback_lines = 0;
2052 fbcon_update_softback(vc);
2055 if (logo_shown >= 0) {
2056 struct vc_data *conp2 = vc_cons[logo_shown].d;
2058 if (conp2->vc_top == logo_lines
2059 && conp2->vc_bottom == conp2->vc_rows)
2060 conp2->vc_top = 0;
2061 logo_shown = FBCON_LOGO_CANSHOW;
2064 prev_console = ops->currcon;
2065 if (prev_console != -1)
2066 old_info = registered_fb[con2fb_map[prev_console]];
2068 * FIXME: If we have multiple fbdev's loaded, we need to
2069 * update all info->currcon. Perhaps, we can place this
2070 * in a centralized structure, but this might break some
2071 * drivers.
2073 * info->currcon = vc->vc_num;
2075 for (i = 0; i < FB_MAX; i++) {
2076 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2077 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2079 o->currcon = vc->vc_num;
2082 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2083 display_to_var(&var, p);
2084 var.activate = FB_ACTIVATE_NOW;
2087 * make sure we don't unnecessarily trip the memcmp()
2088 * in fb_set_var()
2090 info->var.activate = var.activate;
2091 var.yoffset = info->var.yoffset;
2092 var.xoffset = info->var.xoffset;
2093 var.vmode = info->var.vmode;
2094 fb_set_var(info, &var);
2095 ops->var = info->var;
2097 if (old_info != NULL && (old_info != info ||
2098 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2099 if (info->fbops->fb_set_par)
2100 info->fbops->fb_set_par(info);
2102 if (old_info != info) {
2103 fbcon_del_cursor_timer(old_info);
2104 fbcon_add_cursor_timer(info);
2108 set_blitting_type(vc, info);
2109 ops->cursor_reset = 1;
2111 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2112 ops->rotate = FB_ROTATE_UR;
2113 set_blitting_type(vc, info);
2116 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2117 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2119 if (p->userfont)
2120 charcnt = FNTCHARCNT(vc->vc_font.data);
2122 if (charcnt > 256)
2123 vc->vc_complement_mask <<= 1;
2125 updatescrollmode(p, info, vc);
2127 switch (p->scrollmode) {
2128 case SCROLL_WRAP_MOVE:
2129 scrollback_phys_max = p->vrows - vc->vc_rows;
2130 break;
2131 case SCROLL_PAN_MOVE:
2132 case SCROLL_PAN_REDRAW:
2133 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2134 if (scrollback_phys_max < 0)
2135 scrollback_phys_max = 0;
2136 break;
2137 default:
2138 scrollback_phys_max = 0;
2139 break;
2142 scrollback_max = 0;
2143 scrollback_current = 0;
2145 if (!fbcon_is_inactive(vc, info)) {
2146 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2147 ops->update_start(info);
2150 fbcon_set_palette(vc, color_table);
2151 fbcon_clear_margins(vc, 0);
2153 if (logo_shown == FBCON_LOGO_DRAW) {
2155 logo_shown = fg_console;
2156 /* This is protected above by initmem_freed */
2157 fb_show_logo(info, ops->rotate);
2158 update_region(vc,
2159 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2160 vc->vc_size_row * (vc->vc_bottom -
2161 vc->vc_top) / 2);
2162 return 0;
2164 return 1;
2167 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2168 int blank)
2170 if (blank) {
2171 unsigned short charmask = vc->vc_hi_font_mask ?
2172 0x1ff : 0xff;
2173 unsigned short oldc;
2175 oldc = vc->vc_video_erase_char;
2176 vc->vc_video_erase_char &= charmask;
2177 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2178 vc->vc_video_erase_char = oldc;
2182 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2184 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2185 struct fbcon_ops *ops = info->fbcon_par;
2187 if (mode_switch) {
2188 struct fb_var_screeninfo var = info->var;
2190 ops->graphics = 1;
2192 if (!blank) {
2193 if (info->fbops->fb_save_state)
2194 info->fbops->fb_save_state(info);
2195 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2196 fb_set_var(info, &var);
2197 ops->graphics = 0;
2198 ops->var = info->var;
2199 } else if (info->fbops->fb_restore_state)
2200 info->fbops->fb_restore_state(info);
2203 if (!fbcon_is_inactive(vc, info)) {
2204 if (ops->blank_state != blank) {
2205 ops->blank_state = blank;
2206 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2207 ops->cursor_flash = (!blank);
2209 if (fb_blank(info, blank))
2210 fbcon_generic_blank(vc, info, blank);
2213 if (!blank)
2214 update_screen(vc);
2217 if (!blank)
2218 fbcon_add_cursor_timer(info);
2219 else
2220 fbcon_del_cursor_timer(info);
2222 return 0;
2225 static void fbcon_free_font(struct display *p)
2227 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2228 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2229 p->fontdata = NULL;
2230 p->userfont = 0;
2233 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2235 u8 *fontdata = vc->vc_font.data;
2236 u8 *data = font->data;
2237 int i, j;
2239 font->width = vc->vc_font.width;
2240 font->height = vc->vc_font.height;
2241 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2242 if (!font->data)
2243 return 0;
2245 if (font->width <= 8) {
2246 j = vc->vc_font.height;
2247 for (i = 0; i < font->charcount; i++) {
2248 memcpy(data, fontdata, j);
2249 memset(data + j, 0, 32 - j);
2250 data += 32;
2251 fontdata += j;
2253 } else if (font->width <= 16) {
2254 j = vc->vc_font.height * 2;
2255 for (i = 0; i < font->charcount; i++) {
2256 memcpy(data, fontdata, j);
2257 memset(data + j, 0, 64 - j);
2258 data += 64;
2259 fontdata += j;
2261 } else if (font->width <= 24) {
2262 for (i = 0; i < font->charcount; i++) {
2263 for (j = 0; j < vc->vc_font.height; j++) {
2264 *data++ = fontdata[0];
2265 *data++ = fontdata[1];
2266 *data++ = fontdata[2];
2267 fontdata += sizeof(u32);
2269 memset(data, 0, 3 * (32 - j));
2270 data += 3 * (32 - j);
2272 } else {
2273 j = vc->vc_font.height * 4;
2274 for (i = 0; i < font->charcount; i++) {
2275 memcpy(data, fontdata, j);
2276 memset(data + j, 0, 128 - j);
2277 data += 128;
2278 fontdata += j;
2281 return 0;
2284 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2285 const u8 * data, int userfont)
2287 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2288 struct fbcon_ops *ops = info->fbcon_par;
2289 struct display *p = &fb_display[vc->vc_num];
2290 int resize;
2291 int cnt;
2292 char *old_data = NULL;
2294 if (CON_IS_VISIBLE(vc) && softback_lines)
2295 fbcon_set_origin(vc);
2297 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2298 if (p->userfont)
2299 old_data = vc->vc_font.data;
2300 if (userfont)
2301 cnt = FNTCHARCNT(data);
2302 else
2303 cnt = 256;
2304 vc->vc_font.data = (void *)(p->fontdata = data);
2305 if ((p->userfont = userfont))
2306 REFCOUNT(data)++;
2307 vc->vc_font.width = w;
2308 vc->vc_font.height = h;
2309 if (vc->vc_hi_font_mask && cnt == 256) {
2310 vc->vc_hi_font_mask = 0;
2311 if (vc->vc_can_do_color) {
2312 vc->vc_complement_mask >>= 1;
2313 vc->vc_s_complement_mask >>= 1;
2316 /* ++Edmund: reorder the attribute bits */
2317 if (vc->vc_can_do_color) {
2318 unsigned short *cp =
2319 (unsigned short *) vc->vc_origin;
2320 int count = vc->vc_screenbuf_size / 2;
2321 unsigned short c;
2322 for (; count > 0; count--, cp++) {
2323 c = scr_readw(cp);
2324 scr_writew(((c & 0xfe00) >> 1) |
2325 (c & 0xff), cp);
2327 c = vc->vc_video_erase_char;
2328 vc->vc_video_erase_char =
2329 ((c & 0xfe00) >> 1) | (c & 0xff);
2330 vc->vc_attr >>= 1;
2332 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2333 vc->vc_hi_font_mask = 0x100;
2334 if (vc->vc_can_do_color) {
2335 vc->vc_complement_mask <<= 1;
2336 vc->vc_s_complement_mask <<= 1;
2339 /* ++Edmund: reorder the attribute bits */
2341 unsigned short *cp =
2342 (unsigned short *) vc->vc_origin;
2343 int count = vc->vc_screenbuf_size / 2;
2344 unsigned short c;
2345 for (; count > 0; count--, cp++) {
2346 unsigned short newc;
2347 c = scr_readw(cp);
2348 if (vc->vc_can_do_color)
2349 newc =
2350 ((c & 0xff00) << 1) | (c &
2351 0xff);
2352 else
2353 newc = c & ~0x100;
2354 scr_writew(newc, cp);
2356 c = vc->vc_video_erase_char;
2357 if (vc->vc_can_do_color) {
2358 vc->vc_video_erase_char =
2359 ((c & 0xff00) << 1) | (c & 0xff);
2360 vc->vc_attr <<= 1;
2361 } else
2362 vc->vc_video_erase_char = c & ~0x100;
2367 if (resize) {
2368 int cols, rows;
2370 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2371 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2372 cols /= w;
2373 rows /= h;
2374 vc_resize(vc, cols, rows);
2375 if (CON_IS_VISIBLE(vc) && softback_buf)
2376 fbcon_update_softback(vc);
2377 } else if (CON_IS_VISIBLE(vc)
2378 && vc->vc_mode == KD_TEXT) {
2379 fbcon_clear_margins(vc, 0);
2380 update_screen(vc);
2383 if (old_data && (--REFCOUNT(old_data) == 0))
2384 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2385 return 0;
2388 static int fbcon_copy_font(struct vc_data *vc, int con)
2390 struct display *od = &fb_display[con];
2391 struct console_font *f = &vc->vc_font;
2393 if (od->fontdata == f->data)
2394 return 0; /* already the same font... */
2395 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2399 * User asked to set font; we are guaranteed that
2400 * a) width and height are in range 1..32
2401 * b) charcount does not exceed 512
2402 * but lets not assume that, since someone might someday want to use larger
2403 * fonts. And charcount of 512 is small for unicode support.
2405 * However, user space gives the font in 32 rows , regardless of
2406 * actual font height. So a new API is needed if support for larger fonts
2407 * is ever implemented.
2410 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2412 unsigned charcount = font->charcount;
2413 int w = font->width;
2414 int h = font->height;
2415 int size;
2416 int i, csum;
2417 u8 *new_data, *data = font->data;
2418 int pitch = (font->width+7) >> 3;
2420 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2421 * If not this check should be changed to charcount < 256 */
2422 if (charcount != 256 && charcount != 512)
2423 return -EINVAL;
2425 size = h * pitch * charcount;
2427 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2429 if (!new_data)
2430 return -ENOMEM;
2432 new_data += FONT_EXTRA_WORDS * sizeof(int);
2433 FNTSIZE(new_data) = size;
2434 FNTCHARCNT(new_data) = charcount;
2435 REFCOUNT(new_data) = 0; /* usage counter */
2436 for (i=0; i< charcount; i++) {
2437 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2440 /* Since linux has a nice crc32 function use it for counting font
2441 * checksums. */
2442 csum = crc32(0, new_data, size);
2444 FNTSUM(new_data) = csum;
2445 /* Check if the same font is on some other console already */
2446 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2447 struct vc_data *tmp = vc_cons[i].d;
2449 if (fb_display[i].userfont &&
2450 fb_display[i].fontdata &&
2451 FNTSUM(fb_display[i].fontdata) == csum &&
2452 FNTSIZE(fb_display[i].fontdata) == size &&
2453 tmp->vc_font.width == w &&
2454 !memcmp(fb_display[i].fontdata, new_data, size)) {
2455 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2456 new_data = (u8 *)fb_display[i].fontdata;
2457 break;
2460 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2463 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2465 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2466 const struct font_desc *f;
2468 if (!name)
2469 f = get_default_font(info->var.xres, info->var.yres);
2470 else if (!(f = find_font(name)))
2471 return -ENOENT;
2473 font->width = f->width;
2474 font->height = f->height;
2475 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2478 static u16 palette_red[16];
2479 static u16 palette_green[16];
2480 static u16 palette_blue[16];
2482 static struct fb_cmap palette_cmap = {
2483 0, 16, palette_red, palette_green, palette_blue, NULL
2486 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2488 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2489 int i, j, k, depth;
2490 u8 val;
2492 if (fbcon_is_inactive(vc, info))
2493 return -EINVAL;
2495 if (!CON_IS_VISIBLE(vc))
2496 return 0;
2498 depth = fb_get_color_depth(&info->var, &info->fix);
2499 if (depth > 3) {
2500 for (i = j = 0; i < 16; i++) {
2501 k = table[i];
2502 val = vc->vc_palette[j++];
2503 palette_red[k] = (val << 8) | val;
2504 val = vc->vc_palette[j++];
2505 palette_green[k] = (val << 8) | val;
2506 val = vc->vc_palette[j++];
2507 palette_blue[k] = (val << 8) | val;
2509 palette_cmap.len = 16;
2510 palette_cmap.start = 0;
2512 * If framebuffer is capable of less than 16 colors,
2513 * use default palette of fbcon.
2515 } else
2516 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2518 return fb_set_cmap(&palette_cmap, info);
2521 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2523 unsigned long p;
2524 int line;
2526 if (vc->vc_num != fg_console || !softback_lines)
2527 return (u16 *) (vc->vc_origin + offset);
2528 line = offset / vc->vc_size_row;
2529 if (line >= softback_lines)
2530 return (u16 *) (vc->vc_origin + offset -
2531 softback_lines * vc->vc_size_row);
2532 p = softback_curr + offset;
2533 if (p >= softback_end)
2534 p += softback_buf - softback_end;
2535 return (u16 *) p;
2538 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2539 int *px, int *py)
2541 unsigned long ret;
2542 int x, y;
2544 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2545 unsigned long offset = (pos - vc->vc_origin) / 2;
2547 x = offset % vc->vc_cols;
2548 y = offset / vc->vc_cols;
2549 if (vc->vc_num == fg_console)
2550 y += softback_lines;
2551 ret = pos + (vc->vc_cols - x) * 2;
2552 } else if (vc->vc_num == fg_console && softback_lines) {
2553 unsigned long offset = pos - softback_curr;
2555 if (pos < softback_curr)
2556 offset += softback_end - softback_buf;
2557 offset /= 2;
2558 x = offset % vc->vc_cols;
2559 y = offset / vc->vc_cols;
2560 ret = pos + (vc->vc_cols - x) * 2;
2561 if (ret == softback_end)
2562 ret = softback_buf;
2563 if (ret == softback_in)
2564 ret = vc->vc_origin;
2565 } else {
2566 /* Should not happen */
2567 x = y = 0;
2568 ret = vc->vc_origin;
2570 if (px)
2571 *px = x;
2572 if (py)
2573 *py = y;
2574 return ret;
2577 /* As we might be inside of softback, we may work with non-contiguous buffer,
2578 that's why we have to use a separate routine. */
2579 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2581 while (cnt--) {
2582 u16 a = scr_readw(p);
2583 if (!vc->vc_can_do_color)
2584 a ^= 0x0800;
2585 else if (vc->vc_hi_font_mask == 0x100)
2586 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2587 (((a) & 0x0e00) << 4);
2588 else
2589 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2590 (((a) & 0x0700) << 4);
2591 scr_writew(a, p++);
2592 if (p == (u16 *) softback_end)
2593 p = (u16 *) softback_buf;
2594 if (p == (u16 *) softback_in)
2595 p = (u16 *) vc->vc_origin;
2599 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2601 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2602 struct fbcon_ops *ops = info->fbcon_par;
2603 struct display *p = &fb_display[fg_console];
2604 int offset, limit, scrollback_old;
2606 if (softback_top) {
2607 if (vc->vc_num != fg_console)
2608 return 0;
2609 if (vc->vc_mode != KD_TEXT || !lines)
2610 return 0;
2611 if (logo_shown >= 0) {
2612 struct vc_data *conp2 = vc_cons[logo_shown].d;
2614 if (conp2->vc_top == logo_lines
2615 && conp2->vc_bottom == conp2->vc_rows)
2616 conp2->vc_top = 0;
2617 if (logo_shown == vc->vc_num) {
2618 unsigned long p, q;
2619 int i;
2621 p = softback_in;
2622 q = vc->vc_origin +
2623 logo_lines * vc->vc_size_row;
2624 for (i = 0; i < logo_lines; i++) {
2625 if (p == softback_top)
2626 break;
2627 if (p == softback_buf)
2628 p = softback_end;
2629 p -= vc->vc_size_row;
2630 q -= vc->vc_size_row;
2631 scr_memcpyw((u16 *) q, (u16 *) p,
2632 vc->vc_size_row);
2634 softback_in = softback_curr = p;
2635 update_region(vc, vc->vc_origin,
2636 logo_lines * vc->vc_cols);
2638 logo_shown = FBCON_LOGO_CANSHOW;
2640 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2641 fbcon_redraw_softback(vc, p, lines);
2642 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2643 return 0;
2646 if (!scrollback_phys_max)
2647 return -ENOSYS;
2649 scrollback_old = scrollback_current;
2650 scrollback_current -= lines;
2651 if (scrollback_current < 0)
2652 scrollback_current = 0;
2653 else if (scrollback_current > scrollback_max)
2654 scrollback_current = scrollback_max;
2655 if (scrollback_current == scrollback_old)
2656 return 0;
2658 if (fbcon_is_inactive(vc, info))
2659 return 0;
2661 fbcon_cursor(vc, CM_ERASE);
2663 offset = p->yscroll - scrollback_current;
2664 limit = p->vrows;
2665 switch (p->scrollmode) {
2666 case SCROLL_WRAP_MOVE:
2667 info->var.vmode |= FB_VMODE_YWRAP;
2668 break;
2669 case SCROLL_PAN_MOVE:
2670 case SCROLL_PAN_REDRAW:
2671 limit -= vc->vc_rows;
2672 info->var.vmode &= ~FB_VMODE_YWRAP;
2673 break;
2675 if (offset < 0)
2676 offset += limit;
2677 else if (offset >= limit)
2678 offset -= limit;
2680 ops->var.xoffset = 0;
2681 ops->var.yoffset = offset * vc->vc_font.height;
2682 ops->update_start(info);
2684 if (!scrollback_current)
2685 fbcon_cursor(vc, CM_DRAW);
2686 return 0;
2689 static int fbcon_set_origin(struct vc_data *vc)
2691 if (softback_lines)
2692 fbcon_scrolldelta(vc, softback_lines);
2693 return 0;
2696 static void fbcon_suspended(struct fb_info *info)
2698 struct vc_data *vc = NULL;
2699 struct fbcon_ops *ops = info->fbcon_par;
2701 if (!ops || ops->currcon < 0)
2702 return;
2703 vc = vc_cons[ops->currcon].d;
2705 /* Clear cursor, restore saved data */
2706 fbcon_cursor(vc, CM_ERASE);
2709 static void fbcon_resumed(struct fb_info *info)
2711 struct vc_data *vc;
2712 struct fbcon_ops *ops = info->fbcon_par;
2714 if (!ops || ops->currcon < 0)
2715 return;
2716 vc = vc_cons[ops->currcon].d;
2718 update_screen(vc);
2721 static void fbcon_modechanged(struct fb_info *info)
2723 struct fbcon_ops *ops = info->fbcon_par;
2724 struct vc_data *vc;
2725 struct display *p;
2726 int rows, cols;
2728 if (!ops || ops->currcon < 0)
2729 return;
2730 vc = vc_cons[ops->currcon].d;
2731 if (vc->vc_mode != KD_TEXT ||
2732 registered_fb[con2fb_map[ops->currcon]] != info)
2733 return;
2735 p = &fb_display[vc->vc_num];
2736 set_blitting_type(vc, info);
2738 if (CON_IS_VISIBLE(vc)) {
2739 var_to_display(p, &info->var, info);
2740 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2741 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2742 cols /= vc->vc_font.width;
2743 rows /= vc->vc_font.height;
2744 vc_resize(vc, cols, rows);
2745 updatescrollmode(p, info, vc);
2746 scrollback_max = 0;
2747 scrollback_current = 0;
2749 if (!fbcon_is_inactive(vc, info)) {
2750 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2751 ops->update_start(info);
2754 fbcon_set_palette(vc, color_table);
2755 update_screen(vc);
2756 if (softback_buf)
2757 fbcon_update_softback(vc);
2761 static void fbcon_set_all_vcs(struct fb_info *info)
2763 struct fbcon_ops *ops = info->fbcon_par;
2764 struct vc_data *vc;
2765 struct display *p;
2766 int i, rows, cols;
2768 if (!ops || ops->currcon < 0)
2769 return;
2771 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2772 vc = vc_cons[i].d;
2773 if (!vc || vc->vc_mode != KD_TEXT ||
2774 registered_fb[con2fb_map[i]] != info)
2775 continue;
2777 p = &fb_display[vc->vc_num];
2778 set_blitting_type(vc, info);
2779 var_to_display(p, &info->var, info);
2780 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2781 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2782 cols /= vc->vc_font.width;
2783 rows /= vc->vc_font.height;
2784 vc_resize(vc, cols, rows);
2786 if (CON_IS_VISIBLE(vc)) {
2787 updatescrollmode(p, info, vc);
2788 scrollback_max = 0;
2789 scrollback_current = 0;
2791 if (!fbcon_is_inactive(vc, info)) {
2792 ops->var.xoffset = ops->var.yoffset =
2793 p->yscroll = 0;
2794 ops->update_start(info);
2797 fbcon_set_palette(vc, color_table);
2798 update_screen(vc);
2799 if (softback_buf)
2800 fbcon_update_softback(vc);
2804 ops->p = &fb_display[ops->currcon];
2807 static int fbcon_mode_deleted(struct fb_info *info,
2808 struct fb_videomode *mode)
2810 struct fb_info *fb_info;
2811 struct display *p;
2812 int i, j, found = 0;
2814 /* before deletion, ensure that mode is not in use */
2815 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2816 j = con2fb_map[i];
2817 if (j == -1)
2818 continue;
2819 fb_info = registered_fb[j];
2820 if (fb_info != info)
2821 continue;
2822 p = &fb_display[i];
2823 if (!p || !p->mode)
2824 continue;
2825 if (fb_mode_is_equal(p->mode, mode)) {
2826 found = 1;
2827 break;
2830 return found;
2833 static int fbcon_fb_registered(int idx)
2835 int ret = 0, i;
2837 if (info_idx == -1) {
2838 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2839 if (con2fb_map_boot[i] == idx) {
2840 info_idx = idx;
2841 break;
2844 if (info_idx != -1)
2845 ret = fbcon_takeover(1);
2846 } else {
2847 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2848 if (con2fb_map_boot[i] == idx)
2849 set_con2fb_map(i, idx, 0);
2853 return ret;
2856 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2858 struct fbcon_ops *ops = info->fbcon_par;
2859 struct vc_data *vc;
2861 if (!ops || ops->currcon < 0)
2862 return;
2864 vc = vc_cons[ops->currcon].d;
2865 if (vc->vc_mode != KD_TEXT ||
2866 registered_fb[con2fb_map[ops->currcon]] != info)
2867 return;
2869 if (CON_IS_VISIBLE(vc)) {
2870 if (blank)
2871 do_blank_screen(0);
2872 else
2873 do_unblank_screen(0);
2875 ops->blank_state = blank;
2878 static void fbcon_new_modelist(struct fb_info *info)
2880 int i;
2881 struct vc_data *vc;
2882 struct fb_var_screeninfo var;
2883 struct fb_videomode *mode;
2885 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2886 if (registered_fb[con2fb_map[i]] != info)
2887 continue;
2888 if (!fb_display[i].mode)
2889 continue;
2890 vc = vc_cons[i].d;
2891 display_to_var(&var, &fb_display[i]);
2892 mode = fb_find_nearest_mode(fb_display[i].mode,
2893 &info->modelist);
2894 fb_videomode_to_var(&var, mode);
2896 if (vc)
2897 fbcon_set_disp(info, &var, vc);
2898 else
2899 fbcon_preset_disp(info, &var, i);
2904 static int fbcon_event_notify(struct notifier_block *self,
2905 unsigned long action, void *data)
2907 struct fb_event *event = data;
2908 struct fb_info *info = event->info;
2909 struct fb_videomode *mode;
2910 struct fb_con2fbmap *con2fb;
2911 int ret = 0;
2913 switch(action) {
2914 case FB_EVENT_SUSPEND:
2915 fbcon_suspended(info);
2916 break;
2917 case FB_EVENT_RESUME:
2918 fbcon_resumed(info);
2919 break;
2920 case FB_EVENT_MODE_CHANGE:
2921 fbcon_modechanged(info);
2922 break;
2923 case FB_EVENT_MODE_CHANGE_ALL:
2924 fbcon_set_all_vcs(info);
2925 break;
2926 case FB_EVENT_MODE_DELETE:
2927 mode = event->data;
2928 ret = fbcon_mode_deleted(info, mode);
2929 break;
2930 case FB_EVENT_FB_REGISTERED:
2931 ret = fbcon_fb_registered(info->node);
2932 break;
2933 case FB_EVENT_SET_CONSOLE_MAP:
2934 con2fb = event->data;
2935 ret = set_con2fb_map(con2fb->console - 1,
2936 con2fb->framebuffer, 1);
2937 break;
2938 case FB_EVENT_GET_CONSOLE_MAP:
2939 con2fb = event->data;
2940 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2941 break;
2942 case FB_EVENT_BLANK:
2943 fbcon_fb_blanked(info, *(int *)event->data);
2944 break;
2945 case FB_EVENT_NEW_MODELIST:
2946 fbcon_new_modelist(info);
2947 break;
2948 case FB_EVENT_SET_CON_ROTATE:
2949 fbcon_rotate(info, *(int *)event->data);
2950 break;
2951 case FB_EVENT_GET_CON_ROTATE:
2952 ret = fbcon_get_rotate(info);
2953 break;
2954 case FB_EVENT_SET_CON_ROTATE_ALL:
2955 fbcon_rotate_all(info, *(int *)event->data);
2958 return ret;
2962 * The console `switch' structure for the frame buffer based console
2965 static const struct consw fb_con = {
2966 .owner = THIS_MODULE,
2967 .con_startup = fbcon_startup,
2968 .con_init = fbcon_init,
2969 .con_deinit = fbcon_deinit,
2970 .con_clear = fbcon_clear,
2971 .con_putc = fbcon_putc,
2972 .con_putcs = fbcon_putcs,
2973 .con_cursor = fbcon_cursor,
2974 .con_scroll = fbcon_scroll,
2975 .con_bmove = fbcon_bmove,
2976 .con_switch = fbcon_switch,
2977 .con_blank = fbcon_blank,
2978 .con_font_set = fbcon_set_font,
2979 .con_font_get = fbcon_get_font,
2980 .con_font_default = fbcon_set_def_font,
2981 .con_font_copy = fbcon_copy_font,
2982 .con_set_palette = fbcon_set_palette,
2983 .con_scrolldelta = fbcon_scrolldelta,
2984 .con_set_origin = fbcon_set_origin,
2985 .con_invert_region = fbcon_invert_region,
2986 .con_screen_pos = fbcon_screen_pos,
2987 .con_getxy = fbcon_getxy,
2988 .con_resize = fbcon_resize,
2991 static struct notifier_block fbcon_event_notifier = {
2992 .notifier_call = fbcon_event_notify,
2995 static int __init fb_console_init(void)
2997 int i;
2999 acquire_console_sem();
3000 fb_register_client(&fbcon_event_notifier);
3001 release_console_sem();
3003 for (i = 0; i < MAX_NR_CONSOLES; i++)
3004 con2fb_map[i] = -1;
3006 if (num_registered_fb) {
3007 for (i = 0; i < FB_MAX; i++) {
3008 if (registered_fb[i] != NULL) {
3009 info_idx = i;
3010 break;
3013 fbcon_takeover(0);
3016 return 0;
3019 module_init(fb_console_init);
3021 #ifdef MODULE
3023 static void __exit fb_console_exit(void)
3025 acquire_console_sem();
3026 fb_unregister_client(&fbcon_event_notifier);
3027 release_console_sem();
3028 give_up_console(&fb_con);
3031 module_exit(fb_console_exit);
3033 #endif
3035 MODULE_LICENSE("GPL");