fix fbcon.c
[linux-2.6/zen-sources.git] / drivers / video / console / fbcon.c
blob216ea5ac4ab34b49f1643c9fcd7b1d5f21a33d28
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/module.h>
62 #include <linux/types.h>
63 #include <linux/fs.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
68 #include <linux/kd.h>
69 #include <linux/slab.h>
70 #include <linux/fb.h>
71 #include <linux/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
78 #include <asm/fb.h>
79 #include <asm/irq.h>
80 #include <asm/system.h>
81 #ifdef CONFIG_ATARI
82 #include <asm/atariints.h>
83 #endif
84 #ifdef CONFIG_MAC
85 #include <asm/macints.h>
86 #endif
87 #if defined(__mc68000__)
88 #include <asm/machdep.h>
89 #include <asm/setup.h>
90 #endif
92 #include "fbcon.h"
93 #include "fbcondecor.h"
95 #ifdef FBCONDEBUG
96 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
97 #else
98 # define DPRINTK(fmt, args...)
99 #endif
101 enum {
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 signed char con2fb_map[MAX_NR_CONSOLES];
110 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
112 static int logo_lines;
113 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
114 enums. */
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;
127 static int primary_device = -1;
129 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
130 static int map_override;
132 static inline void fbcon_map_override(void)
134 map_override = 1;
136 #else
137 static inline void fbcon_map_override(void)
140 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
142 /* font data */
143 static char fontname[40];
145 /* current fb_info */
146 static int info_idx = -1;
148 /* console rotation */
149 static int initial_rotation;
150 static int fbcon_has_sysfs;
152 static const struct consw fb_con;
154 #define CM_SOFTBACK (8)
156 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
158 static int fbcon_set_origin(struct vc_data *);
160 #define CURSOR_DRAW_DELAY (1)
162 /* # VBL ints between cursor state changes */
163 #define ATARI_CURSOR_BLINK_RATE (42)
164 #define MAC_CURSOR_BLINK_RATE (32)
165 #define DEFAULT_CURSOR_BLINK_RATE (20)
167 static int vbl_cursor_cnt;
168 static int fbcon_cursor_noblink;
170 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
173 * Interface used by the world
176 static const char *fbcon_startup(void);
177 static void fbcon_init(struct vc_data *vc, int init);
178 static void fbcon_deinit(struct vc_data *vc);
179 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
180 int width);
181 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
182 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
183 int count, int ypos, int xpos);
184 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
185 static void fbcon_cursor(struct vc_data *vc, int mode);
186 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
187 int count);
188 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
189 int height, int width);
190 static int fbcon_switch(struct vc_data *vc);
191 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
192 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
193 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
196 * Internal routines
198 static __inline__ void ywrap_up(struct vc_data *vc, int count);
199 static __inline__ void ywrap_down(struct vc_data *vc, int count);
200 static __inline__ void ypan_up(struct vc_data *vc, int count);
201 static __inline__ void ypan_down(struct vc_data *vc, int count);
202 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
203 int dy, int dx, int height, int width, u_int y_break);
204 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
205 int unit);
206 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
207 int line, int count, int dy);
208 static void fbcon_modechanged(struct fb_info *info);
209 static void fbcon_set_all_vcs(struct fb_info *info);
210 static void fbcon_start(void);
211 static void fbcon_exit(void);
212 static struct device *fbcon_device;
214 #ifdef CONFIG_MAC
216 * On the Macintoy, there may or may not be a working VBL int. We need to probe
218 static int vbl_detected;
220 static irqreturn_t fb_vbl_detect(int irq, void *dummy)
222 vbl_detected++;
223 return IRQ_HANDLED;
225 #endif
227 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
228 static inline void fbcon_set_rotation(struct fb_info *info)
230 struct fbcon_ops *ops = info->fbcon_par;
232 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
233 ops->p->con_rotate < 4)
234 ops->rotate = ops->p->con_rotate;
235 else
236 ops->rotate = 0;
239 static void fbcon_rotate(struct fb_info *info, u32 rotate)
241 struct fbcon_ops *ops= info->fbcon_par;
242 struct fb_info *fb_info;
244 if (!ops || ops->currcon == -1)
245 return;
247 fb_info = registered_fb[con2fb_map[ops->currcon]];
249 if (info == fb_info) {
250 struct display *p = &fb_display[ops->currcon];
252 if (rotate < 4)
253 p->con_rotate = rotate;
254 else
255 p->con_rotate = 0;
257 fbcon_modechanged(info);
261 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
263 struct fbcon_ops *ops = info->fbcon_par;
264 struct vc_data *vc;
265 struct display *p;
266 int i;
268 if (!ops || ops->currcon < 0 || rotate > 3)
269 return;
271 for (i = first_fb_vc; i <= last_fb_vc; i++) {
272 vc = vc_cons[i].d;
273 if (!vc || vc->vc_mode != KD_TEXT ||
274 registered_fb[con2fb_map[i]] != info)
275 continue;
277 p = &fb_display[vc->vc_num];
278 p->con_rotate = rotate;
281 fbcon_set_all_vcs(info);
283 #else
284 static inline void fbcon_set_rotation(struct fb_info *info)
286 struct fbcon_ops *ops = info->fbcon_par;
288 ops->rotate = FB_ROTATE_UR;
291 static void fbcon_rotate(struct fb_info *info, u32 rotate)
293 return;
296 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
298 return;
300 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
302 static int fbcon_get_rotate(struct fb_info *info)
304 struct fbcon_ops *ops = info->fbcon_par;
306 return (ops) ? ops->rotate : 0;
309 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
311 struct fbcon_ops *ops = info->fbcon_par;
313 return (info->state != FBINFO_STATE_RUNNING ||
314 vc->vc_mode != KD_TEXT || ops->graphics);
317 inline int get_color(struct vc_data *vc, struct fb_info *info,
318 u16 c, int is_fg)
320 int depth = fb_get_color_depth(&info->var, &info->fix);
321 int color = 0;
323 if (console_blanked) {
324 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
326 c = vc->vc_video_erase_char & charmask;
329 if (depth != 1)
330 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
331 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
333 switch (depth) {
334 case 1:
336 int col = mono_col(info);
337 /* 0 or 1 */
338 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
339 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
341 if (console_blanked)
342 fg = bg;
344 color = (is_fg) ? fg : bg;
345 break;
347 case 2:
349 * Scale down 16-colors to 4 colors. Default 4-color palette
350 * is grayscale. However, simply dividing the values by 4
351 * will not work, as colors 1, 2 and 3 will be scaled-down
352 * to zero rendering them invisible. So empirically convert
353 * colors to a sane 4-level grayscale.
355 switch (color) {
356 case 0:
357 color = 0; /* black */
358 break;
359 case 1 ... 6:
360 color = 2; /* white */
361 break;
362 case 7 ... 8:
363 color = 1; /* gray */
364 break;
365 default:
366 color = 3; /* intense white */
367 break;
369 break;
370 case 3:
372 * Last 8 entries of default 16-color palette is a more intense
373 * version of the first 8 (i.e., same chrominance, different
374 * luminance).
376 color &= 7;
377 break;
381 return color;
384 static void fbcon_update_softback(struct vc_data *vc)
386 int l = fbcon_softback_size / vc->vc_size_row;
388 if (l > 5)
389 softback_end = softback_buf + l * vc->vc_size_row;
390 else
391 /* Smaller scrollback makes no sense, and 0 would screw
392 the operation totally */
393 softback_top = 0;
396 static void fb_flashcursor(struct work_struct *work)
398 struct fb_info *info = container_of(work, struct fb_info, queue);
399 struct fbcon_ops *ops = info->fbcon_par;
400 struct display *p;
401 struct vc_data *vc = NULL;
402 int c;
403 int mode;
405 acquire_console_sem();
406 if (ops && ops->currcon != -1)
407 vc = vc_cons[ops->currcon].d;
409 if (!vc || !CON_IS_VISIBLE(vc) ||
410 registered_fb[con2fb_map[vc->vc_num]] != info ||
411 vc->vc_deccm != 1) {
412 release_console_sem();
413 return;
416 p = &fb_display[vc->vc_num];
417 c = scr_readw((u16 *) vc->vc_pos);
418 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
419 CM_ERASE : CM_DRAW;
420 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
421 get_color(vc, info, c, 0));
423 release_console_sem();
426 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
427 static int cursor_blink_rate;
428 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
430 struct fb_info *info = dev_id;
432 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
433 schedule_work(&info->queue);
434 vbl_cursor_cnt = cursor_blink_rate;
436 return IRQ_HANDLED;
438 #endif
440 static void cursor_timer_handler(unsigned long dev_addr)
442 struct fb_info *info = (struct fb_info *) dev_addr;
443 struct fbcon_ops *ops = info->fbcon_par;
445 schedule_work(&info->queue);
446 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
449 static void fbcon_add_cursor_timer(struct fb_info *info)
451 struct fbcon_ops *ops = info->fbcon_par;
453 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
454 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
455 !fbcon_cursor_noblink) {
456 if (!info->queue.func)
457 INIT_WORK(&info->queue, fb_flashcursor);
459 init_timer(&ops->cursor_timer);
460 ops->cursor_timer.function = cursor_timer_handler;
461 ops->cursor_timer.expires = jiffies + HZ / 5;
462 ops->cursor_timer.data = (unsigned long ) info;
463 add_timer(&ops->cursor_timer);
464 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
468 static void fbcon_del_cursor_timer(struct fb_info *info)
470 struct fbcon_ops *ops = info->fbcon_par;
472 if (info->queue.func == fb_flashcursor &&
473 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
474 del_timer_sync(&ops->cursor_timer);
475 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
479 #ifndef MODULE
480 static int __init fb_console_setup(char *this_opt)
482 char *options;
483 int i, j;
485 if (!this_opt || !*this_opt)
486 return 1;
488 while ((options = strsep(&this_opt, ",")) != NULL) {
489 if (!strncmp(options, "font:", 5))
490 strcpy(fontname, options + 5);
492 if (!strncmp(options, "scrollback:", 11)) {
493 options += 11;
494 if (*options) {
495 fbcon_softback_size = simple_strtoul(options, &options, 0);
496 if (*options == 'k' || *options == 'K') {
497 fbcon_softback_size *= 1024;
498 options++;
500 if (*options != ',')
501 return 1;
502 options++;
503 } else
504 return 1;
507 if (!strncmp(options, "map:", 4)) {
508 options += 4;
509 if (*options) {
510 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
511 if (!options[j])
512 j = 0;
513 con2fb_map_boot[i] =
514 (options[j++]-'0') % FB_MAX;
517 fbcon_map_override();
520 return 1;
523 if (!strncmp(options, "vc:", 3)) {
524 options += 3;
525 if (*options)
526 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
527 if (first_fb_vc < 0)
528 first_fb_vc = 0;
529 if (*options++ == '-')
530 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
531 fbcon_is_default = 0;
534 if (!strncmp(options, "rotate:", 7)) {
535 options += 7;
536 if (*options)
537 initial_rotation = simple_strtoul(options, &options, 0);
538 if (initial_rotation > 3)
539 initial_rotation = 0;
542 return 1;
545 __setup("fbcon=", fb_console_setup);
546 #endif
548 static int search_fb_in_map(int idx)
550 int i, retval = 0;
552 for (i = first_fb_vc; i <= last_fb_vc; i++) {
553 if (con2fb_map[i] == idx)
554 retval = 1;
556 return retval;
559 static int search_for_mapped_con(void)
561 int i, retval = 0;
563 for (i = first_fb_vc; i <= last_fb_vc; i++) {
564 if (con2fb_map[i] != -1)
565 retval = 1;
567 return retval;
570 static int fbcon_takeover(int show_logo)
572 int err, i;
574 if (!num_registered_fb)
575 return -ENODEV;
577 if (!show_logo)
578 logo_shown = FBCON_LOGO_DONTSHOW;
580 for (i = first_fb_vc; i <= last_fb_vc; i++)
581 con2fb_map[i] = info_idx;
583 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
584 fbcon_is_default);
586 if (err) {
587 for (i = first_fb_vc; i <= last_fb_vc; i++) {
588 con2fb_map[i] = -1;
590 info_idx = -1;
593 fbcon_decor_init();
595 return err;
598 #ifdef MODULE
599 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
600 int cols, int rows, int new_cols, int new_rows)
602 logo_shown = FBCON_LOGO_DONTSHOW;
604 #else
605 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
606 int cols, int rows, int new_cols, int new_rows)
608 /* Need to make room for the logo */
609 struct fbcon_ops *ops = info->fbcon_par;
610 int cnt, erase = vc->vc_video_erase_char, step;
611 unsigned short *save = NULL, *r, *q;
612 int logo_height;
614 if (info->flags & FBINFO_MODULE) {
615 logo_shown = FBCON_LOGO_DONTSHOW;
616 return;
620 * remove underline attribute from erase character
621 * if black and white framebuffer.
623 if (fb_get_color_depth(&info->var, &info->fix) == 1)
624 erase &= ~0x400;
625 logo_height = fb_prepare_logo(info, ops->rotate);
626 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
627 q = (unsigned short *) (vc->vc_origin +
628 vc->vc_size_row * rows);
629 step = logo_lines * cols;
630 for (r = q - logo_lines * cols; r < q; r++)
631 if (scr_readw(r) != vc->vc_video_erase_char)
632 break;
633 if (r != q && new_rows >= rows + logo_lines) {
634 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
635 if (save) {
636 int i = cols < new_cols ? cols : new_cols;
637 scr_memsetw(save, erase, logo_lines * new_cols * 2);
638 r = q - step;
639 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
640 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
641 r = q;
644 if (r == q) {
645 /* We can scroll screen down */
646 r = q - step - cols;
647 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
648 scr_memcpyw(r + step, r, vc->vc_size_row);
649 r -= cols;
651 if (!save) {
652 int lines;
653 if (vc->vc_y + logo_lines >= rows)
654 lines = rows - vc->vc_y - 1;
655 else
656 lines = logo_lines;
657 vc->vc_y += lines;
658 vc->vc_pos += lines * vc->vc_size_row;
661 scr_memsetw((unsigned short *) vc->vc_origin,
662 erase,
663 vc->vc_size_row * logo_lines);
665 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
666 fbcon_clear_margins(vc, 0);
667 update_screen(vc);
670 if (save) {
671 q = (unsigned short *) (vc->vc_origin +
672 vc->vc_size_row *
673 rows);
674 scr_memcpyw(q, save, logo_lines * new_cols * 2);
675 vc->vc_y += logo_lines;
676 vc->vc_pos += logo_lines * vc->vc_size_row;
677 kfree(save);
680 if (logo_lines > vc->vc_bottom) {
681 logo_shown = FBCON_LOGO_CANSHOW;
682 printk(KERN_INFO
683 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
684 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
685 logo_shown = FBCON_LOGO_DRAW;
686 vc->vc_top = logo_lines;
689 #endif /* MODULE */
691 #ifdef CONFIG_FB_TILEBLITTING
692 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
694 struct fbcon_ops *ops = info->fbcon_par;
696 ops->p = &fb_display[vc->vc_num];
698 if ((info->flags & FBINFO_MISC_TILEBLITTING))
699 fbcon_set_tileops(vc, info);
700 else {
701 fbcon_set_rotation(info);
702 fbcon_set_bitops(ops);
706 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
708 int err = 0;
710 if (info->flags & FBINFO_MISC_TILEBLITTING &&
711 info->tileops->fb_get_tilemax(info) < charcount)
712 err = 1;
714 return err;
716 #else
717 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
719 struct fbcon_ops *ops = info->fbcon_par;
721 info->flags &= ~FBINFO_MISC_TILEBLITTING;
722 ops->p = &fb_display[vc->vc_num];
723 fbcon_set_rotation(info);
724 fbcon_set_bitops(ops);
727 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
729 return 0;
732 #endif /* CONFIG_MISC_TILEBLITTING */
735 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
736 int unit, int oldidx)
738 struct fbcon_ops *ops = NULL;
739 int err = 0;
741 if (!try_module_get(info->fbops->owner))
742 err = -ENODEV;
744 if (!err && info->fbops->fb_open &&
745 info->fbops->fb_open(info, 0))
746 err = -ENODEV;
748 if (!err) {
749 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
750 if (!ops)
751 err = -ENOMEM;
754 if (!err) {
755 info->fbcon_par = ops;
757 if (vc)
758 set_blitting_type(vc, info);
761 if (err) {
762 con2fb_map[unit] = oldidx;
763 module_put(info->fbops->owner);
766 return err;
769 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
770 struct fb_info *newinfo, int unit,
771 int oldidx, int found)
773 struct fbcon_ops *ops = oldinfo->fbcon_par;
774 int err = 0;
776 if (oldinfo->fbops->fb_release &&
777 oldinfo->fbops->fb_release(oldinfo, 0)) {
778 con2fb_map[unit] = oldidx;
779 if (!found && newinfo->fbops->fb_release)
780 newinfo->fbops->fb_release(newinfo, 0);
781 if (!found)
782 module_put(newinfo->fbops->owner);
783 err = -ENODEV;
786 if (!err) {
787 fbcon_del_cursor_timer(oldinfo);
788 kfree(ops->cursor_state.mask);
789 kfree(ops->cursor_data);
790 kfree(ops->fontbuffer);
791 kfree(oldinfo->fbcon_par);
792 oldinfo->fbcon_par = NULL;
793 module_put(oldinfo->fbops->owner);
795 If oldinfo and newinfo are driving the same hardware,
796 the fb_release() method of oldinfo may attempt to
797 restore the hardware state. This will leave the
798 newinfo in an undefined state. Thus, a call to
799 fb_set_par() may be needed for the newinfo.
801 if (newinfo->fbops->fb_set_par)
802 newinfo->fbops->fb_set_par(newinfo);
805 return err;
808 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
809 int unit, int show_logo)
811 struct fbcon_ops *ops = info->fbcon_par;
813 ops->currcon = fg_console;
815 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
816 info->fbops->fb_set_par(info);
818 ops->flags |= FBCON_FLAGS_INIT;
819 ops->graphics = 0;
820 fbcon_set_disp(info, &info->var, unit);
822 if (show_logo) {
823 struct vc_data *fg_vc = vc_cons[fg_console].d;
824 struct fb_info *fg_info =
825 registered_fb[con2fb_map[fg_console]];
827 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
828 fg_vc->vc_rows, fg_vc->vc_cols,
829 fg_vc->vc_rows);
832 update_screen(vc_cons[fg_console].d);
836 * set_con2fb_map - map console to frame buffer device
837 * @unit: virtual console number to map
838 * @newidx: frame buffer index to map virtual console to
839 * @user: user request
841 * Maps a virtual console @unit to a frame buffer device
842 * @newidx.
844 static int set_con2fb_map(int unit, int newidx, int user)
846 struct vc_data *vc = vc_cons[unit].d;
847 int oldidx = con2fb_map[unit];
848 struct fb_info *info = registered_fb[newidx];
849 struct fb_info *oldinfo = NULL;
850 int found, err = 0;
852 if (oldidx == newidx)
853 return 0;
855 if (!info || fbcon_has_exited)
856 return -EINVAL;
858 if (!err && !search_for_mapped_con()) {
859 info_idx = newidx;
860 return fbcon_takeover(0);
863 if (oldidx != -1)
864 oldinfo = registered_fb[oldidx];
866 found = search_fb_in_map(newidx);
868 acquire_console_sem();
869 con2fb_map[unit] = newidx;
870 if (!err && !found)
871 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
875 * If old fb is not mapped to any of the consoles,
876 * fbcon should release it.
878 if (!err && oldinfo && !search_fb_in_map(oldidx))
879 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
880 found);
882 if (!err) {
883 int show_logo = (fg_console == 0 && !user &&
884 logo_shown != FBCON_LOGO_DONTSHOW);
886 if (!found)
887 fbcon_add_cursor_timer(info);
888 con2fb_map_boot[unit] = newidx;
889 con2fb_init_display(vc, info, unit, show_logo);
892 if (!search_fb_in_map(info_idx))
893 info_idx = newidx;
895 release_console_sem();
896 return err;
900 * Low Level Operations
902 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
903 static int var_to_display(struct display *disp,
904 struct fb_var_screeninfo *var,
905 struct fb_info *info)
907 disp->xres_virtual = var->xres_virtual;
908 disp->yres_virtual = var->yres_virtual;
909 disp->bits_per_pixel = var->bits_per_pixel;
910 disp->grayscale = var->grayscale;
911 disp->nonstd = var->nonstd;
912 disp->accel_flags = var->accel_flags;
913 disp->height = var->height;
914 disp->width = var->width;
915 disp->red = var->red;
916 disp->green = var->green;
917 disp->blue = var->blue;
918 disp->transp = var->transp;
919 disp->rotate = var->rotate;
920 disp->mode = fb_match_mode(var, &info->modelist);
921 if (disp->mode == NULL)
922 /* This should not happen */
923 return -EINVAL;
924 return 0;
927 static void display_to_var(struct fb_var_screeninfo *var,
928 struct display *disp)
930 fb_videomode_to_var(var, disp->mode);
931 var->xres_virtual = disp->xres_virtual;
932 var->yres_virtual = disp->yres_virtual;
933 var->bits_per_pixel = disp->bits_per_pixel;
934 var->grayscale = disp->grayscale;
935 var->nonstd = disp->nonstd;
936 var->accel_flags = disp->accel_flags;
937 var->height = disp->height;
938 var->width = disp->width;
939 var->red = disp->red;
940 var->green = disp->green;
941 var->blue = disp->blue;
942 var->transp = disp->transp;
943 var->rotate = disp->rotate;
946 static const char *fbcon_startup(void)
948 const char *display_desc = "frame buffer device";
949 struct display *p = &fb_display[fg_console];
950 struct vc_data *vc = vc_cons[fg_console].d;
951 const struct font_desc *font = NULL;
952 struct module *owner;
953 struct fb_info *info = NULL;
954 struct fbcon_ops *ops;
955 int rows, cols;
956 int irqres;
958 irqres = 1;
960 * If num_registered_fb is zero, this is a call for the dummy part.
961 * The frame buffer devices weren't initialized yet.
963 if (!num_registered_fb || info_idx == -1)
964 return display_desc;
966 * Instead of blindly using registered_fb[0], we use info_idx, set by
967 * fb_console_init();
969 info = registered_fb[info_idx];
970 if (!info)
971 return NULL;
973 owner = info->fbops->owner;
974 if (!try_module_get(owner))
975 return NULL;
976 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
977 module_put(owner);
978 return NULL;
981 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
982 if (!ops) {
983 module_put(owner);
984 return NULL;
987 ops->currcon = -1;
988 ops->graphics = 1;
989 ops->cur_rotate = -1;
990 info->fbcon_par = ops;
991 p->con_rotate = initial_rotation;
992 set_blitting_type(vc, info);
994 if (info->fix.type != FB_TYPE_TEXT) {
995 if (fbcon_softback_size) {
996 if (!softback_buf) {
997 softback_buf =
998 (unsigned long)
999 kmalloc(fbcon_softback_size,
1000 GFP_KERNEL);
1001 if (!softback_buf) {
1002 fbcon_softback_size = 0;
1003 softback_top = 0;
1006 } else {
1007 if (softback_buf) {
1008 kfree((void *) softback_buf);
1009 softback_buf = 0;
1010 softback_top = 0;
1013 if (softback_buf)
1014 softback_in = softback_top = softback_curr =
1015 softback_buf;
1016 softback_lines = 0;
1019 /* Setup default font */
1020 if (!p->fontdata) {
1021 if (!fontname[0] || !(font = find_font(fontname)))
1022 font = get_default_font(info->var.xres,
1023 info->var.yres,
1024 info->pixmap.blit_x,
1025 info->pixmap.blit_y);
1026 vc->vc_font.width = font->width;
1027 vc->vc_font.height = font->height;
1028 vc->vc_font.data = (void *)(p->fontdata = font->data);
1029 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1032 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1033 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1034 cols /= vc->vc_font.width;
1035 rows /= vc->vc_font.height;
1037 if (fbcon_decor_active(info, vc)) {
1038 cols = vc->vc_decor.twidth / vc->vc_font.width;
1039 rows = vc->vc_decor.theight / vc->vc_font.height;
1042 vc_resize(vc, cols, rows);
1044 DPRINTK("mode: %s\n", info->fix.id);
1045 DPRINTK("visual: %d\n", info->fix.visual);
1046 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1047 info->var.yres,
1048 info->var.bits_per_pixel);
1050 #ifdef CONFIG_ATARI
1051 if (MACH_IS_ATARI) {
1052 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1053 irqres =
1054 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1055 IRQ_TYPE_PRIO, "framebuffer vbl",
1056 info);
1058 #endif /* CONFIG_ATARI */
1060 #ifdef CONFIG_MAC
1062 * On a Macintoy, the VBL interrupt may or may not be active.
1063 * As interrupt based cursor is more reliable and race free, we
1064 * probe for VBL interrupts.
1066 if (MACH_IS_MAC) {
1067 int ct = 0;
1069 * Probe for VBL: set temp. handler ...
1071 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1072 "framebuffer vbl", info);
1073 vbl_detected = 0;
1076 * ... and spin for 20 ms ...
1078 while (!vbl_detected && ++ct < 1000)
1079 udelay(20);
1081 if (ct == 1000)
1082 printk
1083 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1085 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1087 if (vbl_detected) {
1089 * interrupt based cursor ok
1091 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1092 irqres =
1093 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1094 "framebuffer vbl", info);
1095 } else {
1097 * VBL not detected: fall through, use timer based cursor
1099 irqres = 1;
1102 #endif /* CONFIG_MAC */
1104 fbcon_add_cursor_timer(info);
1105 fbcon_has_exited = 0;
1106 return display_desc;
1109 static void fbcon_init(struct vc_data *vc, int init)
1111 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1112 struct fbcon_ops *ops;
1113 struct vc_data **default_mode = vc->vc_display_fg;
1114 struct vc_data *svc = *default_mode;
1115 struct display *t, *p = &fb_display[vc->vc_num];
1116 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1117 int cap;
1119 if (info_idx == -1 || info == NULL)
1120 return;
1122 cap = info->flags;
1124 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1125 (info->fix.type == FB_TYPE_TEXT) || fbcon_decor_active(info, vc))
1126 logo = 0;
1128 if (var_to_display(p, &info->var, info))
1129 return;
1131 if (!info->fbcon_par)
1132 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1134 /* If we are not the first console on this
1135 fb, copy the font from that console */
1136 t = &fb_display[fg_console];
1137 if (!p->fontdata) {
1138 if (t->fontdata) {
1139 struct vc_data *fvc = vc_cons[fg_console].d;
1141 vc->vc_font.data = (void *)(p->fontdata =
1142 fvc->vc_font.data);
1143 vc->vc_font.width = fvc->vc_font.width;
1144 vc->vc_font.height = fvc->vc_font.height;
1145 p->userfont = t->userfont;
1147 if (p->userfont)
1148 REFCOUNT(p->fontdata)++;
1149 } else {
1150 const struct font_desc *font = NULL;
1152 if (!fontname[0] || !(font = find_font(fontname)))
1153 font = get_default_font(info->var.xres,
1154 info->var.yres,
1155 info->pixmap.blit_x,
1156 info->pixmap.blit_y);
1157 vc->vc_font.width = font->width;
1158 vc->vc_font.height = font->height;
1159 vc->vc_font.data = (void *)(p->fontdata = font->data);
1160 vc->vc_font.charcount = 256; /* FIXME Need to
1161 support more fonts */
1165 if (p->userfont)
1166 charcnt = FNTCHARCNT(p->fontdata);
1168 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1169 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1170 if (charcnt == 256) {
1171 vc->vc_hi_font_mask = 0;
1172 } else {
1173 vc->vc_hi_font_mask = 0x100;
1174 if (vc->vc_can_do_color)
1175 vc->vc_complement_mask <<= 1;
1178 if (!*svc->vc_uni_pagedir_loc)
1179 con_set_default_unimap(svc);
1180 if (!*vc->vc_uni_pagedir_loc)
1181 con_copy_unimap(vc, svc);
1183 ops = info->fbcon_par;
1184 p->con_rotate = initial_rotation;
1185 set_blitting_type(vc, info);
1187 cols = vc->vc_cols;
1188 rows = vc->vc_rows;
1189 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1190 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1191 new_cols /= vc->vc_font.width;
1192 new_rows /= vc->vc_font.height;
1193 vc_resize(vc, new_cols, new_rows);
1196 * We must always set the mode. The mode of the previous console
1197 * driver could be in the same resolution but we are using different
1198 * hardware so we have to initialize the hardware.
1200 * We need to do it in fbcon_init() to prevent screen corruption.
1202 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1203 if (info->fbops->fb_set_par &&
1204 !(ops->flags & FBCON_FLAGS_INIT))
1205 info->fbops->fb_set_par(info);
1206 ops->flags |= FBCON_FLAGS_INIT;
1209 ops->graphics = 0;
1211 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1212 !(cap & FBINFO_HWACCEL_DISABLED))
1213 p->scrollmode = SCROLL_MOVE;
1214 else /* default to something safe */
1215 p->scrollmode = SCROLL_REDRAW;
1218 * ++guenther: console.c:vc_allocate() relies on initializing
1219 * vc_{cols,rows}, but we must not set those if we are only
1220 * resizing the console.
1222 if (!init) {
1223 vc->vc_cols = new_cols;
1224 vc->vc_rows = new_rows;
1227 if (logo)
1228 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1230 if (vc == svc && softback_buf)
1231 fbcon_update_softback(vc);
1233 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1234 ops->rotate = FB_ROTATE_UR;
1235 set_blitting_type(vc, info);
1238 ops->p = &fb_display[fg_console];
1241 static void fbcon_free_font(struct display *p)
1243 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1244 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1245 p->fontdata = NULL;
1246 p->userfont = 0;
1249 static void fbcon_deinit(struct vc_data *vc)
1251 struct display *p = &fb_display[vc->vc_num];
1252 struct fb_info *info;
1253 struct fbcon_ops *ops;
1254 int idx;
1256 fbcon_free_font(p);
1257 idx = con2fb_map[vc->vc_num];
1259 if (idx == -1)
1260 goto finished;
1262 info = registered_fb[idx];
1264 if (!info)
1265 goto finished;
1267 ops = info->fbcon_par;
1269 if (!ops)
1270 goto finished;
1272 if (CON_IS_VISIBLE(vc))
1273 fbcon_del_cursor_timer(info);
1275 ops->flags &= ~FBCON_FLAGS_INIT;
1276 finished:
1278 if (!con_is_bound(&fb_con))
1279 fbcon_exit();
1281 return;
1284 /* ====================================================================== */
1286 /* fbcon_XXX routines - interface used by the world
1288 * This system is now divided into two levels because of complications
1289 * caused by hardware scrolling. Top level functions:
1291 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1293 * handles y values in range [0, scr_height-1] that correspond to real
1294 * screen positions. y_wrap shift means that first line of bitmap may be
1295 * anywhere on this display. These functions convert lineoffsets to
1296 * bitmap offsets and deal with the wrap-around case by splitting blits.
1298 * fbcon_bmove_physical_8() -- These functions fast implementations
1299 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1300 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1302 * WARNING:
1304 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1305 * Implies should only really hardware scroll in rows. Only reason for
1306 * restriction is simplicity & efficiency at the moment.
1309 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1310 int width)
1312 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1313 struct fbcon_ops *ops = info->fbcon_par;
1315 struct display *p = &fb_display[vc->vc_num];
1316 u_int y_break;
1318 if (fbcon_is_inactive(vc, info))
1319 return;
1321 if (!height || !width)
1322 return;
1324 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1325 vc->vc_top = 0;
1327 if (fbcon_decor_active(info, vc)) {
1328 fbcon_decor_clear(vc, info, sy, sx, height, width);
1329 return;
1332 /* Split blits that cross physical y_wrap boundary */
1334 y_break = p->vrows - p->yscroll;
1335 if (sy < y_break && sy + height - 1 >= y_break) {
1336 u_int b = y_break - sy;
1337 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1338 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1339 width);
1340 } else
1341 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1344 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1345 int count, int ypos, int xpos)
1347 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1348 struct display *p = &fb_display[vc->vc_num];
1349 struct fbcon_ops *ops = info->fbcon_par;
1351 if (!fbcon_is_inactive(vc, info)) {
1353 if (fbcon_decor_active(info, vc))
1354 fbcon_decor_putcs(vc, info, s, count, ypos, xpos);
1355 else
1356 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1357 get_color(vc, info, scr_readw(s), 1),
1358 get_color(vc, info, scr_readw(s), 0));
1362 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1364 unsigned short chr;
1366 scr_writew(c, &chr);
1367 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1370 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1372 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1373 struct fbcon_ops *ops = info->fbcon_par;
1375 if (!fbcon_is_inactive(vc, info)) {
1376 if (fbcon_decor_active(info, vc)) {
1377 fbcon_decor_clear_margins(vc, info, bottom_only);
1378 } else {
1379 ops->clear_margins(vc, info, bottom_only);
1384 static void fbcon_cursor(struct vc_data *vc, int mode)
1386 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1387 struct fbcon_ops *ops = info->fbcon_par;
1388 int y;
1389 int c = scr_readw((u16 *) vc->vc_pos);
1391 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1392 return;
1394 if (vc->vc_cursor_type & 0x10)
1395 fbcon_del_cursor_timer(info);
1396 else
1397 fbcon_add_cursor_timer(info);
1399 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1400 if (mode & CM_SOFTBACK) {
1401 mode &= ~CM_SOFTBACK;
1402 y = softback_lines;
1403 } else {
1404 if (softback_lines)
1405 fbcon_set_origin(vc);
1406 y = 0;
1409 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1410 get_color(vc, info, c, 0));
1411 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1414 static int scrollback_phys_max = 0;
1415 static int scrollback_max = 0;
1416 static int scrollback_current = 0;
1418 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1419 int unit)
1421 struct display *p, *t;
1422 struct vc_data **default_mode, *vc;
1423 struct vc_data *svc;
1424 struct fbcon_ops *ops = info->fbcon_par;
1425 int rows, cols, charcnt = 256;
1427 p = &fb_display[unit];
1429 if (var_to_display(p, var, info))
1430 return;
1432 vc = vc_cons[unit].d;
1434 if (!vc)
1435 return;
1437 default_mode = vc->vc_display_fg;
1438 svc = *default_mode;
1439 t = &fb_display[svc->vc_num];
1441 if (!vc->vc_font.data) {
1442 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1443 vc->vc_font.width = (*default_mode)->vc_font.width;
1444 vc->vc_font.height = (*default_mode)->vc_font.height;
1445 p->userfont = t->userfont;
1446 if (p->userfont)
1447 REFCOUNT(p->fontdata)++;
1449 if (p->userfont)
1450 charcnt = FNTCHARCNT(p->fontdata);
1452 var->activate = FB_ACTIVATE_NOW;
1453 info->var.activate = var->activate;
1454 var->yoffset = info->var.yoffset;
1455 var->xoffset = info->var.xoffset;
1456 fb_set_var(info, var);
1457 ops->var = info->var;
1458 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1459 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1460 if (charcnt == 256) {
1461 vc->vc_hi_font_mask = 0;
1462 } else {
1463 vc->vc_hi_font_mask = 0x100;
1464 if (vc->vc_can_do_color)
1465 vc->vc_complement_mask <<= 1;
1468 if (!*svc->vc_uni_pagedir_loc)
1469 con_set_default_unimap(svc);
1470 if (!*vc->vc_uni_pagedir_loc)
1471 con_copy_unimap(vc, svc);
1473 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1474 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1475 cols /= vc->vc_font.width;
1476 rows /= vc->vc_font.height;
1477 vc_resize(vc, cols, rows);
1479 if (CON_IS_VISIBLE(vc)) {
1480 update_screen(vc);
1481 if (softback_buf)
1482 fbcon_update_softback(vc);
1486 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1488 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1489 struct fbcon_ops *ops = info->fbcon_par;
1490 struct display *p = &fb_display[vc->vc_num];
1492 p->yscroll += count;
1493 if (p->yscroll >= p->vrows) /* Deal with wrap */
1494 p->yscroll -= p->vrows;
1495 ops->var.xoffset = 0;
1496 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1497 ops->var.vmode |= FB_VMODE_YWRAP;
1498 ops->update_start(info);
1499 scrollback_max += count;
1500 if (scrollback_max > scrollback_phys_max)
1501 scrollback_max = scrollback_phys_max;
1502 scrollback_current = 0;
1505 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1507 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1508 struct fbcon_ops *ops = info->fbcon_par;
1509 struct display *p = &fb_display[vc->vc_num];
1511 p->yscroll -= count;
1512 if (p->yscroll < 0) /* Deal with wrap */
1513 p->yscroll += p->vrows;
1514 ops->var.xoffset = 0;
1515 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1516 ops->var.vmode |= FB_VMODE_YWRAP;
1517 ops->update_start(info);
1518 scrollback_max -= count;
1519 if (scrollback_max < 0)
1520 scrollback_max = 0;
1521 scrollback_current = 0;
1524 static __inline__ void ypan_up(struct vc_data *vc, int count)
1526 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1527 struct display *p = &fb_display[vc->vc_num];
1528 struct fbcon_ops *ops = info->fbcon_par;
1530 p->yscroll += count;
1531 if (p->yscroll > p->vrows - vc->vc_rows) {
1532 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1533 0, 0, 0, vc->vc_rows, vc->vc_cols);
1534 p->yscroll -= p->vrows - vc->vc_rows;
1537 ops->var.xoffset = 0;
1538 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1539 ops->var.vmode &= ~FB_VMODE_YWRAP;
1540 ops->update_start(info);
1541 fbcon_clear_margins(vc, 1);
1542 scrollback_max += count;
1543 if (scrollback_max > scrollback_phys_max)
1544 scrollback_max = scrollback_phys_max;
1545 scrollback_current = 0;
1548 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1550 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1551 struct fbcon_ops *ops = info->fbcon_par;
1552 struct display *p = &fb_display[vc->vc_num];
1554 p->yscroll += count;
1556 if (p->yscroll > p->vrows - vc->vc_rows) {
1557 p->yscroll -= p->vrows - vc->vc_rows;
1558 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1561 ops->var.xoffset = 0;
1562 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1563 ops->var.vmode &= ~FB_VMODE_YWRAP;
1564 ops->update_start(info);
1565 fbcon_clear_margins(vc, 1);
1566 scrollback_max += count;
1567 if (scrollback_max > scrollback_phys_max)
1568 scrollback_max = scrollback_phys_max;
1569 scrollback_current = 0;
1572 static __inline__ void ypan_down(struct vc_data *vc, int count)
1574 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1575 struct display *p = &fb_display[vc->vc_num];
1576 struct fbcon_ops *ops = info->fbcon_par;
1578 p->yscroll -= count;
1579 if (p->yscroll < 0) {
1580 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1581 0, vc->vc_rows, vc->vc_cols);
1582 p->yscroll += p->vrows - vc->vc_rows;
1585 ops->var.xoffset = 0;
1586 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1587 ops->var.vmode &= ~FB_VMODE_YWRAP;
1588 ops->update_start(info);
1589 fbcon_clear_margins(vc, 1);
1590 scrollback_max -= count;
1591 if (scrollback_max < 0)
1592 scrollback_max = 0;
1593 scrollback_current = 0;
1596 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1598 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1599 struct fbcon_ops *ops = info->fbcon_par;
1600 struct display *p = &fb_display[vc->vc_num];
1602 p->yscroll -= count;
1604 if (p->yscroll < 0) {
1605 p->yscroll += p->vrows - vc->vc_rows;
1606 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1609 ops->var.xoffset = 0;
1610 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1611 ops->var.vmode &= ~FB_VMODE_YWRAP;
1612 ops->update_start(info);
1613 fbcon_clear_margins(vc, 1);
1614 scrollback_max -= count;
1615 if (scrollback_max < 0)
1616 scrollback_max = 0;
1617 scrollback_current = 0;
1620 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1621 long delta)
1623 int count = vc->vc_rows;
1624 unsigned short *d, *s;
1625 unsigned long n;
1626 int line = 0;
1628 d = (u16 *) softback_curr;
1629 if (d == (u16 *) softback_in)
1630 d = (u16 *) vc->vc_origin;
1631 n = softback_curr + delta * vc->vc_size_row;
1632 softback_lines -= delta;
1633 if (delta < 0) {
1634 if (softback_curr < softback_top && n < softback_buf) {
1635 n += softback_end - softback_buf;
1636 if (n < softback_top) {
1637 softback_lines -=
1638 (softback_top - n) / vc->vc_size_row;
1639 n = softback_top;
1641 } else if (softback_curr >= softback_top
1642 && n < softback_top) {
1643 softback_lines -=
1644 (softback_top - n) / vc->vc_size_row;
1645 n = softback_top;
1647 } else {
1648 if (softback_curr > softback_in && n >= softback_end) {
1649 n += softback_buf - softback_end;
1650 if (n > softback_in) {
1651 n = softback_in;
1652 softback_lines = 0;
1654 } else if (softback_curr <= softback_in && n > softback_in) {
1655 n = softback_in;
1656 softback_lines = 0;
1659 if (n == softback_curr)
1660 return;
1661 softback_curr = n;
1662 s = (u16 *) softback_curr;
1663 if (s == (u16 *) softback_in)
1664 s = (u16 *) vc->vc_origin;
1665 while (count--) {
1666 unsigned short *start;
1667 unsigned short *le;
1668 unsigned short c;
1669 int x = 0;
1670 unsigned short attr = 1;
1672 start = s;
1673 le = advance_row(s, 1);
1674 do {
1675 c = scr_readw(s);
1676 if (attr != (c & 0xff00)) {
1677 attr = c & 0xff00;
1678 if (s > start) {
1679 fbcon_putcs(vc, start, s - start,
1680 line, x);
1681 x += s - start;
1682 start = s;
1685 if (c == scr_readw(d)) {
1686 if (s > start) {
1687 fbcon_putcs(vc, start, s - start,
1688 line, x);
1689 x += s - start + 1;
1690 start = s + 1;
1691 } else {
1692 x++;
1693 start++;
1696 s++;
1697 d++;
1698 } while (s < le);
1699 if (s > start)
1700 fbcon_putcs(vc, start, s - start, line, x);
1701 line++;
1702 if (d == (u16 *) softback_end)
1703 d = (u16 *) softback_buf;
1704 if (d == (u16 *) softback_in)
1705 d = (u16 *) vc->vc_origin;
1706 if (s == (u16 *) softback_end)
1707 s = (u16 *) softback_buf;
1708 if (s == (u16 *) softback_in)
1709 s = (u16 *) vc->vc_origin;
1713 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1714 int line, int count, int dy)
1716 unsigned short *s = (unsigned short *)
1717 (vc->vc_origin + vc->vc_size_row * line);
1719 while (count--) {
1720 unsigned short *start = s;
1721 unsigned short *le = advance_row(s, 1);
1722 unsigned short c;
1723 int x = 0;
1724 unsigned short attr = 1;
1726 do {
1727 c = scr_readw(s);
1728 if (attr != (c & 0xff00)) {
1729 attr = c & 0xff00;
1730 if (s > start) {
1731 fbcon_putcs(vc, start, s - start,
1732 dy, x);
1733 x += s - start;
1734 start = s;
1737 console_conditional_schedule();
1738 s++;
1739 } while (s < le);
1740 if (s > start)
1741 fbcon_putcs(vc, start, s - start, dy, x);
1742 console_conditional_schedule();
1743 dy++;
1747 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1748 struct display *p, int line, int count, int ycount)
1750 int offset = ycount * vc->vc_cols;
1751 unsigned short *d = (unsigned short *)
1752 (vc->vc_origin + vc->vc_size_row * line);
1753 unsigned short *s = d + offset;
1754 struct fbcon_ops *ops = info->fbcon_par;
1756 while (count--) {
1757 unsigned short *start = s;
1758 unsigned short *le = advance_row(s, 1);
1759 unsigned short c;
1760 int x = 0;
1762 do {
1763 c = scr_readw(s);
1765 if (c == scr_readw(d)) {
1766 if (s > start) {
1767 ops->bmove(vc, info, line + ycount, x,
1768 line, x, 1, s-start);
1769 x += s - start + 1;
1770 start = s + 1;
1771 } else {
1772 x++;
1773 start++;
1777 scr_writew(c, d);
1778 console_conditional_schedule();
1779 s++;
1780 d++;
1781 } while (s < le);
1782 if (s > start)
1783 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1784 s-start);
1785 console_conditional_schedule();
1786 if (ycount > 0)
1787 line++;
1788 else {
1789 line--;
1790 /* NOTE: We subtract two lines from these pointers */
1791 s -= vc->vc_size_row;
1792 d -= vc->vc_size_row;
1797 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1798 int line, int count, int offset)
1800 unsigned short *d = (unsigned short *)
1801 (vc->vc_origin + vc->vc_size_row * line);
1802 unsigned short *s = d + offset;
1804 while (count--) {
1805 unsigned short *start = s;
1806 unsigned short *le = advance_row(s, 1);
1807 unsigned short c;
1808 int x = 0;
1809 unsigned short attr = 1;
1811 do {
1812 c = scr_readw(s);
1813 if (attr != (c & 0xff00)) {
1814 attr = c & 0xff00;
1815 if (s > start) {
1816 fbcon_putcs(vc, start, s - start,
1817 line, x);
1818 x += s - start;
1819 start = s;
1822 if (c == scr_readw(d)) {
1823 if (s > start) {
1824 fbcon_putcs(vc, start, s - start,
1825 line, x);
1826 x += s - start + 1;
1827 start = s + 1;
1828 } else {
1829 x++;
1830 start++;
1833 scr_writew(c, d);
1834 console_conditional_schedule();
1835 s++;
1836 d++;
1837 } while (s < le);
1838 if (s > start)
1839 fbcon_putcs(vc, start, s - start, line, x);
1840 console_conditional_schedule();
1841 if (offset > 0)
1842 line++;
1843 else {
1844 line--;
1845 /* NOTE: We subtract two lines from these pointers */
1846 s -= vc->vc_size_row;
1847 d -= vc->vc_size_row;
1852 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1853 int count)
1855 unsigned short *p;
1857 if (vc->vc_num != fg_console)
1858 return;
1859 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1861 while (count) {
1862 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1863 count--;
1864 p = advance_row(p, 1);
1865 softback_in += vc->vc_size_row;
1866 if (softback_in == softback_end)
1867 softback_in = softback_buf;
1868 if (softback_in == softback_top) {
1869 softback_top += vc->vc_size_row;
1870 if (softback_top == softback_end)
1871 softback_top = softback_buf;
1874 softback_curr = softback_in;
1877 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1878 int count)
1880 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1881 struct display *p = &fb_display[vc->vc_num];
1882 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1884 if (fbcon_is_inactive(vc, info))
1885 return -EINVAL;
1887 fbcon_cursor(vc, CM_ERASE);
1890 * ++Geert: Only use ywrap/ypan if the console is in text mode
1891 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1892 * whole screen (prevents flicker).
1895 switch (dir) {
1896 case SM_UP:
1897 if (count > vc->vc_rows) /* Maximum realistic size */
1898 count = vc->vc_rows;
1899 if (softback_top)
1900 fbcon_softback_note(vc, t, count);
1901 if (logo_shown >= 0 || fbcon_decor_active(info, vc))
1902 goto redraw_up;
1903 switch (p->scrollmode) {
1904 case SCROLL_MOVE:
1905 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1906 count);
1907 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1908 scr_memsetw((unsigned short *) (vc->vc_origin +
1909 vc->vc_size_row *
1910 (b - count)),
1911 vc->vc_video_erase_char,
1912 vc->vc_size_row * count);
1913 return 1;
1914 break;
1916 case SCROLL_WRAP_MOVE:
1917 if (b - t - count > 3 * vc->vc_rows >> 2) {
1918 if (t > 0)
1919 fbcon_bmove(vc, 0, 0, count, 0, t,
1920 vc->vc_cols);
1921 ywrap_up(vc, count);
1922 if (vc->vc_rows - b > 0)
1923 fbcon_bmove(vc, b - count, 0, b, 0,
1924 vc->vc_rows - b,
1925 vc->vc_cols);
1926 } else if (info->flags & FBINFO_READS_FAST)
1927 fbcon_bmove(vc, t + count, 0, t, 0,
1928 b - t - count, vc->vc_cols);
1929 else
1930 goto redraw_up;
1931 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1932 break;
1934 case SCROLL_PAN_REDRAW:
1935 if ((p->yscroll + count <=
1936 2 * (p->vrows - vc->vc_rows))
1937 && ((!scroll_partial && (b - t == vc->vc_rows))
1938 || (scroll_partial
1939 && (b - t - count >
1940 3 * vc->vc_rows >> 2)))) {
1941 if (t > 0)
1942 fbcon_redraw_move(vc, p, 0, t, count);
1943 ypan_up_redraw(vc, t, count);
1944 if (vc->vc_rows - b > 0)
1945 fbcon_redraw_move(vc, p, b,
1946 vc->vc_rows - b, b);
1947 } else
1948 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1949 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1950 break;
1952 case SCROLL_PAN_MOVE:
1953 if ((p->yscroll + count <=
1954 2 * (p->vrows - vc->vc_rows))
1955 && ((!scroll_partial && (b - t == vc->vc_rows))
1956 || (scroll_partial
1957 && (b - t - count >
1958 3 * vc->vc_rows >> 2)))) {
1959 if (t > 0)
1960 fbcon_bmove(vc, 0, 0, count, 0, t,
1961 vc->vc_cols);
1962 ypan_up(vc, count);
1963 if (vc->vc_rows - b > 0)
1964 fbcon_bmove(vc, b - count, 0, b, 0,
1965 vc->vc_rows - b,
1966 vc->vc_cols);
1967 } else if (info->flags & FBINFO_READS_FAST)
1968 fbcon_bmove(vc, t + count, 0, t, 0,
1969 b - t - count, vc->vc_cols);
1970 else
1971 goto redraw_up;
1972 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1973 break;
1975 case SCROLL_REDRAW:
1976 redraw_up:
1977 fbcon_redraw(vc, p, t, b - t - count,
1978 count * vc->vc_cols);
1979 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1980 scr_memsetw((unsigned short *) (vc->vc_origin +
1981 vc->vc_size_row *
1982 (b - count)),
1983 vc->vc_video_erase_char,
1984 vc->vc_size_row * count);
1985 return 1;
1987 break;
1989 case SM_DOWN:
1990 if (count > vc->vc_rows) /* Maximum realistic size */
1991 count = vc->vc_rows;
1992 if (logo_shown >= 0)
1993 goto redraw_down;
1994 if (fbcon_decor_active(info, vc))
1995 goto redraw_down;
1996 switch (p->scrollmode) {
1997 case SCROLL_MOVE:
1998 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1999 -count);
2000 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2001 scr_memsetw((unsigned short *) (vc->vc_origin +
2002 vc->vc_size_row *
2004 vc->vc_video_erase_char,
2005 vc->vc_size_row * count);
2006 return 1;
2007 break;
2009 case SCROLL_WRAP_MOVE:
2010 if (b - t - count > 3 * vc->vc_rows >> 2) {
2011 if (vc->vc_rows - b > 0)
2012 fbcon_bmove(vc, b, 0, b - count, 0,
2013 vc->vc_rows - b,
2014 vc->vc_cols);
2015 ywrap_down(vc, count);
2016 if (t > 0)
2017 fbcon_bmove(vc, count, 0, 0, 0, t,
2018 vc->vc_cols);
2019 } else if (info->flags & FBINFO_READS_FAST)
2020 fbcon_bmove(vc, t, 0, t + count, 0,
2021 b - t - count, vc->vc_cols);
2022 else
2023 goto redraw_down;
2024 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2025 break;
2027 case SCROLL_PAN_MOVE:
2028 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2029 && ((!scroll_partial && (b - t == vc->vc_rows))
2030 || (scroll_partial
2031 && (b - t - count >
2032 3 * vc->vc_rows >> 2)))) {
2033 if (vc->vc_rows - b > 0)
2034 fbcon_bmove(vc, b, 0, b - count, 0,
2035 vc->vc_rows - b,
2036 vc->vc_cols);
2037 ypan_down(vc, count);
2038 if (t > 0)
2039 fbcon_bmove(vc, count, 0, 0, 0, t,
2040 vc->vc_cols);
2041 } else if (info->flags & FBINFO_READS_FAST)
2042 fbcon_bmove(vc, t, 0, t + count, 0,
2043 b - t - count, vc->vc_cols);
2044 else
2045 goto redraw_down;
2046 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2047 break;
2049 case SCROLL_PAN_REDRAW:
2050 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2051 && ((!scroll_partial && (b - t == vc->vc_rows))
2052 || (scroll_partial
2053 && (b - t - count >
2054 3 * vc->vc_rows >> 2)))) {
2055 if (vc->vc_rows - b > 0)
2056 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2057 b - count);
2058 ypan_down_redraw(vc, t, count);
2059 if (t > 0)
2060 fbcon_redraw_move(vc, p, count, t, 0);
2061 } else
2062 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2063 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2064 break;
2066 case SCROLL_REDRAW:
2067 redraw_down:
2068 fbcon_redraw(vc, p, b - 1, b - t - count,
2069 -count * vc->vc_cols);
2070 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2071 scr_memsetw((unsigned short *) (vc->vc_origin +
2072 vc->vc_size_row *
2074 vc->vc_video_erase_char,
2075 vc->vc_size_row * count);
2076 return 1;
2079 return 0;
2083 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2084 int height, int width)
2086 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2087 struct display *p = &fb_display[vc->vc_num];
2089 if (fbcon_is_inactive(vc, info))
2090 return;
2092 if (!width || !height)
2093 return;
2095 /* Split blits that cross physical y_wrap case.
2096 * Pathological case involves 4 blits, better to use recursive
2097 * code rather than unrolled case
2099 * Recursive invocations don't need to erase the cursor over and
2100 * over again, so we use fbcon_bmove_rec()
2102 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2103 p->vrows - p->yscroll);
2106 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2107 int dy, int dx, int height, int width, u_int y_break)
2109 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2110 struct fbcon_ops *ops = info->fbcon_par;
2111 u_int b;
2113 if (sy < y_break && sy + height > y_break) {
2114 b = y_break - sy;
2115 if (dy < sy) { /* Avoid trashing self */
2116 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2117 y_break);
2118 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2119 height - b, width, y_break);
2120 } else {
2121 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2122 height - b, width, y_break);
2123 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2124 y_break);
2126 return;
2129 if (dy < y_break && dy + height > y_break) {
2130 b = y_break - dy;
2131 if (dy < sy) { /* Avoid trashing self */
2132 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2133 y_break);
2134 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2135 height - b, width, y_break);
2136 } else {
2137 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2138 height - b, width, y_break);
2139 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2140 y_break);
2142 return;
2145 if (fbcon_decor_active(info, vc) && sy == dy && height == 1) {
2146 /* must use slower redraw bmove to keep background pic intact */
2147 fbcon_decor_bmove_redraw(vc, info, sy, sx, dx, width);
2148 return;
2151 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2152 height, width);
2155 static void updatescrollmode(struct display *p,
2156 struct fb_info *info,
2157 struct vc_data *vc)
2159 struct fbcon_ops *ops = info->fbcon_par;
2160 int fh = vc->vc_font.height;
2161 int cap = info->flags;
2162 u16 t = 0;
2163 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2164 info->fix.xpanstep);
2165 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2166 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2167 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2168 info->var.xres_virtual);
2169 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2170 divides(ypan, vc->vc_font.height) && vyres > yres;
2171 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2172 divides(ywrap, vc->vc_font.height) &&
2173 divides(vc->vc_font.height, vyres) &&
2174 divides(vc->vc_font.height, yres);
2175 int reading_fast = cap & FBINFO_READS_FAST;
2176 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2177 !(cap & FBINFO_HWACCEL_DISABLED);
2178 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2179 !(cap & FBINFO_HWACCEL_DISABLED);
2181 p->vrows = vyres/fh;
2182 if (yres > (fh * (vc->vc_rows + 1)))
2183 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2184 if ((yres % fh) && (vyres % fh < yres % fh))
2185 p->vrows--;
2187 if (good_wrap || good_pan) {
2188 if (reading_fast || fast_copyarea)
2189 p->scrollmode = good_wrap ?
2190 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2191 else
2192 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2193 SCROLL_PAN_REDRAW;
2194 } else {
2195 if (reading_fast || (fast_copyarea && !fast_imageblit))
2196 p->scrollmode = SCROLL_MOVE;
2197 else
2198 p->scrollmode = SCROLL_REDRAW;
2202 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2203 unsigned int height, unsigned int user)
2205 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2206 struct fbcon_ops *ops = info->fbcon_par;
2207 struct display *p = &fb_display[vc->vc_num];
2208 struct fb_var_screeninfo var = info->var;
2209 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2211 virt_w = FBCON_SWAP(ops->rotate, width, height);
2212 virt_h = FBCON_SWAP(ops->rotate, height, width);
2213 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2214 vc->vc_font.height);
2215 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2216 vc->vc_font.width);
2217 var.xres = virt_w * virt_fw;
2218 var.yres = virt_h * virt_fh;
2219 x_diff = info->var.xres - var.xres;
2220 y_diff = info->var.yres - var.yres;
2221 if ((x_diff < 0 || x_diff > virt_fw ||
2222 y_diff < 0 || y_diff > virt_fh) && !vc->vc_decor.state) {
2223 const struct fb_videomode *mode;
2225 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2226 mode = fb_find_best_mode(&var, &info->modelist);
2227 if (mode == NULL)
2228 return -EINVAL;
2229 display_to_var(&var, p);
2230 fb_videomode_to_var(&var, mode);
2232 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2233 return -EINVAL;
2235 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2236 if (CON_IS_VISIBLE(vc)) {
2237 var.activate = FB_ACTIVATE_NOW |
2238 FB_ACTIVATE_FORCE;
2239 fb_set_var(info, &var);
2241 var_to_display(p, &info->var, info);
2242 ops->var = info->var;
2244 updatescrollmode(p, info, vc);
2245 return 0;
2248 static int fbcon_switch(struct vc_data *vc)
2250 struct fb_info *info, *old_info = NULL;
2251 struct fbcon_ops *ops;
2252 struct display *p = &fb_display[vc->vc_num];
2253 struct fb_var_screeninfo var;
2254 int i, prev_console, charcnt = 256;
2256 info = registered_fb[con2fb_map[vc->vc_num]];
2257 ops = info->fbcon_par;
2258 prev_console = ops->currcon;
2259 if (prev_console != -1)
2260 old_info = registered_fb[con2fb_map[prev_console]];
2262 if (!fbcon_decor_active_vc(vc) && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
2263 struct vc_data *vc_curr = vc_cons[prev_console].d;
2264 if (vc_curr && fbcon_decor_active_vc(vc_curr)) {
2265 /* Clear the screen to avoid displaying funky colors during
2266 * palette updates. */
2267 memset((u8*)info->screen_base + info->fix.line_length * info->var.yoffset,
2268 0, info->var.yres * info->fix.line_length);
2272 if (softback_top) {
2273 if (softback_lines)
2274 fbcon_set_origin(vc);
2275 softback_top = softback_curr = softback_in = softback_buf;
2276 softback_lines = 0;
2277 fbcon_update_softback(vc);
2280 if (logo_shown >= 0) {
2281 struct vc_data *conp2 = vc_cons[logo_shown].d;
2283 if (conp2->vc_top == logo_lines
2284 && conp2->vc_bottom == conp2->vc_rows)
2285 conp2->vc_top = 0;
2286 logo_shown = FBCON_LOGO_CANSHOW;
2290 * FIXME: If we have multiple fbdev's loaded, we need to
2291 * update all info->currcon. Perhaps, we can place this
2292 * in a centralized structure, but this might break some
2293 * drivers.
2295 * info->currcon = vc->vc_num;
2297 for (i = 0; i < FB_MAX; i++) {
2298 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2299 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2301 o->currcon = vc->vc_num;
2304 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2305 display_to_var(&var, p);
2306 var.activate = FB_ACTIVATE_NOW;
2309 * make sure we don't unnecessarily trip the memcmp()
2310 * in fb_set_var()
2312 info->var.activate = var.activate;
2313 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2314 fb_set_var(info, &var);
2315 ops->var = info->var;
2317 if (old_info != NULL && (old_info != info ||
2318 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2319 if (info->fbops->fb_set_par)
2320 info->fbops->fb_set_par(info);
2322 if (old_info != info)
2323 fbcon_del_cursor_timer(old_info);
2326 if (fbcon_decor_active_vc(vc)) {
2327 struct vc_data *vc_curr = vc_cons[prev_console].d;
2329 if (!vc_curr->vc_decor.theme ||
2330 strcmp(vc->vc_decor.theme, vc_curr->vc_decor.theme) ||
2331 (fbcon_decor_active_nores(info, vc_curr) &&
2332 !fbcon_decor_active(info, vc_curr))) {
2333 if (fbcon_decor_call_helper("modechange", vc->vc_num))
2334 fbcon_decor_disable(vc, 0);
2338 if (fbcon_is_inactive(vc, info) ||
2339 ops->blank_state != FB_BLANK_UNBLANK)
2340 fbcon_del_cursor_timer(info);
2341 else
2342 fbcon_add_cursor_timer(info);
2344 set_blitting_type(vc, info);
2345 ops->cursor_reset = 1;
2347 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2348 ops->rotate = FB_ROTATE_UR;
2349 set_blitting_type(vc, info);
2352 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2353 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2355 if (p->userfont)
2356 charcnt = FNTCHARCNT(vc->vc_font.data);
2358 if (charcnt > 256)
2359 vc->vc_complement_mask <<= 1;
2361 updatescrollmode(p, info, vc);
2363 switch (p->scrollmode) {
2364 case SCROLL_WRAP_MOVE:
2365 scrollback_phys_max = p->vrows - vc->vc_rows;
2366 break;
2367 case SCROLL_PAN_MOVE:
2368 case SCROLL_PAN_REDRAW:
2369 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2370 if (scrollback_phys_max < 0)
2371 scrollback_phys_max = 0;
2372 break;
2373 default:
2374 scrollback_phys_max = 0;
2375 break;
2378 scrollback_max = 0;
2379 scrollback_current = 0;
2381 if (!fbcon_is_inactive(vc, info)) {
2382 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2383 ops->update_start(info);
2386 fbcon_set_palette(vc, color_table);
2387 fbcon_clear_margins(vc, 0);
2389 if (logo_shown == FBCON_LOGO_DRAW) {
2391 logo_shown = fg_console;
2392 /* This is protected above by initmem_freed */
2393 fb_show_logo(info, ops->rotate);
2394 update_region(vc,
2395 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2396 vc->vc_size_row * (vc->vc_bottom -
2397 vc->vc_top) / 2);
2398 return 0;
2400 return 1;
2403 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2404 int blank)
2406 struct fb_event event;
2408 if (blank) {
2409 unsigned short charmask = vc->vc_hi_font_mask ?
2410 0x1ff : 0xff;
2411 unsigned short oldc;
2413 oldc = vc->vc_video_erase_char;
2414 vc->vc_video_erase_char &= charmask;
2415 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2416 vc->vc_video_erase_char = oldc;
2420 event.info = info;
2421 event.data = &blank;
2422 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2425 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2427 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2428 struct fbcon_ops *ops = info->fbcon_par;
2430 if (mode_switch) {
2431 struct fb_var_screeninfo var = info->var;
2433 ops->graphics = 1;
2435 if (!blank) {
2436 if (info->fbops->fb_save_state)
2437 info->fbops->fb_save_state(info);
2438 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2439 fb_set_var(info, &var);
2440 ops->graphics = 0;
2441 ops->var = info->var;
2442 } else if (info->fbops->fb_restore_state)
2443 info->fbops->fb_restore_state(info);
2446 if (!fbcon_is_inactive(vc, info)) {
2447 if (ops->blank_state != blank) {
2448 ops->blank_state = blank;
2449 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2450 ops->cursor_flash = (!blank);
2452 if (info->fbops->fb_blank)
2453 if(info->fbops->fb_blank(blank, info)) {
2454 if (fbcon_decor_active(info, vc))
2455 fbcon_decor_blank(vc, info, blank);
2456 else
2457 fbcon_generic_blank(vc, info, blank);
2460 if (!(info->flags & FBINFO_MISC_USEREVENT))
2461 if (fb_blank(info, blank))
2462 fbcon_generic_blank(vc, info, blank);
2465 if (!blank)
2466 update_screen(vc);
2469 if (mode_switch || fbcon_is_inactive(vc, info) ||
2470 ops->blank_state != FB_BLANK_UNBLANK)
2471 fbcon_del_cursor_timer(info);
2472 else
2473 fbcon_add_cursor_timer(info);
2475 return 0;
2478 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2480 u8 *fontdata = vc->vc_font.data;
2481 u8 *data = font->data;
2482 int i, j;
2484 font->width = vc->vc_font.width;
2485 font->height = vc->vc_font.height;
2486 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2487 if (!font->data)
2488 return 0;
2490 if (font->width <= 8) {
2491 j = vc->vc_font.height;
2492 for (i = 0; i < font->charcount; i++) {
2493 memcpy(data, fontdata, j);
2494 memset(data + j, 0, 32 - j);
2495 data += 32;
2496 fontdata += j;
2498 } else if (font->width <= 16) {
2499 j = vc->vc_font.height * 2;
2500 for (i = 0; i < font->charcount; i++) {
2501 memcpy(data, fontdata, j);
2502 memset(data + j, 0, 64 - j);
2503 data += 64;
2504 fontdata += j;
2506 } else if (font->width <= 24) {
2507 for (i = 0; i < font->charcount; i++) {
2508 for (j = 0; j < vc->vc_font.height; j++) {
2509 *data++ = fontdata[0];
2510 *data++ = fontdata[1];
2511 *data++ = fontdata[2];
2512 fontdata += sizeof(u32);
2514 memset(data, 0, 3 * (32 - j));
2515 data += 3 * (32 - j);
2517 } else {
2518 j = vc->vc_font.height * 4;
2519 for (i = 0; i < font->charcount; i++) {
2520 memcpy(data, fontdata, j);
2521 memset(data + j, 0, 128 - j);
2522 data += 128;
2523 fontdata += j;
2526 return 0;
2529 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2530 const u8 * data, int userfont)
2532 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2533 struct fbcon_ops *ops = info->fbcon_par;
2534 struct display *p = &fb_display[vc->vc_num];
2535 int resize;
2536 int cnt;
2537 char *old_data = NULL;
2539 if (CON_IS_VISIBLE(vc) && softback_lines)
2540 fbcon_set_origin(vc);
2542 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2543 if (p->userfont)
2544 old_data = vc->vc_font.data;
2545 if (userfont)
2546 cnt = FNTCHARCNT(data);
2547 else
2548 cnt = 256;
2549 vc->vc_font.data = (void *)(p->fontdata = data);
2550 if ((p->userfont = userfont))
2551 REFCOUNT(data)++;
2552 vc->vc_font.width = w;
2553 vc->vc_font.height = h;
2554 if (vc->vc_hi_font_mask && cnt == 256) {
2555 vc->vc_hi_font_mask = 0;
2556 if (vc->vc_can_do_color) {
2557 vc->vc_complement_mask >>= 1;
2558 vc->vc_s_complement_mask >>= 1;
2561 /* ++Edmund: reorder the attribute bits */
2562 if (vc->vc_can_do_color) {
2563 unsigned short *cp =
2564 (unsigned short *) vc->vc_origin;
2565 int count = vc->vc_screenbuf_size / 2;
2566 unsigned short c;
2567 for (; count > 0; count--, cp++) {
2568 c = scr_readw(cp);
2569 scr_writew(((c & 0xfe00) >> 1) |
2570 (c & 0xff), cp);
2572 c = vc->vc_video_erase_char;
2573 vc->vc_video_erase_char =
2574 ((c & 0xfe00) >> 1) | (c & 0xff);
2575 vc->vc_attr >>= 1;
2577 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2578 vc->vc_hi_font_mask = 0x100;
2579 if (vc->vc_can_do_color) {
2580 vc->vc_complement_mask <<= 1;
2581 vc->vc_s_complement_mask <<= 1;
2584 /* ++Edmund: reorder the attribute bits */
2586 unsigned short *cp =
2587 (unsigned short *) vc->vc_origin;
2588 int count = vc->vc_screenbuf_size / 2;
2589 unsigned short c;
2590 for (; count > 0; count--, cp++) {
2591 unsigned short newc;
2592 c = scr_readw(cp);
2593 if (vc->vc_can_do_color)
2594 newc =
2595 ((c & 0xff00) << 1) | (c &
2596 0xff);
2597 else
2598 newc = c & ~0x100;
2599 scr_writew(newc, cp);
2601 c = vc->vc_video_erase_char;
2602 if (vc->vc_can_do_color) {
2603 vc->vc_video_erase_char =
2604 ((c & 0xff00) << 1) | (c & 0xff);
2605 vc->vc_attr <<= 1;
2606 } else
2607 vc->vc_video_erase_char = c & ~0x100;
2612 if (resize) {
2613 /* reset wrap/pan */
2614 int cols, rows;
2616 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2617 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2619 info->var.xoffset = info->var.yoffset = p->yscroll = 0;
2620 if (fbcon_decor_active(info, vc)) {
2621 cols = vc->vc_decor.twidth;
2622 rows = vc->vc_decor.theight;
2624 cols /= w;
2625 rows /= h;
2627 vc_resize(vc, cols, rows);
2629 if (CON_IS_VISIBLE(vc) && softback_buf)
2630 fbcon_update_softback(vc);
2631 } else if (CON_IS_VISIBLE(vc)
2632 && vc->vc_mode == KD_TEXT) {
2633 fbcon_clear_margins(vc, 0);
2634 update_screen(vc);
2637 if (old_data && (--REFCOUNT(old_data) == 0))
2638 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2639 return 0;
2642 static int fbcon_copy_font(struct vc_data *vc, int con)
2644 struct display *od = &fb_display[con];
2645 struct console_font *f = &vc->vc_font;
2647 if (od->fontdata == f->data)
2648 return 0; /* already the same font... */
2649 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2653 * User asked to set font; we are guaranteed that
2654 * a) width and height are in range 1..32
2655 * b) charcount does not exceed 512
2656 * but lets not assume that, since someone might someday want to use larger
2657 * fonts. And charcount of 512 is small for unicode support.
2659 * However, user space gives the font in 32 rows , regardless of
2660 * actual font height. So a new API is needed if support for larger fonts
2661 * is ever implemented.
2664 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2666 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2667 unsigned charcount = font->charcount;
2668 int w = font->width;
2669 int h = font->height;
2670 int size;
2671 int i, csum;
2672 u8 *new_data, *data = font->data;
2673 int pitch = (font->width+7) >> 3;
2675 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2676 * If not this check should be changed to charcount < 256 */
2677 if (charcount != 256 && charcount != 512)
2678 return -EINVAL;
2680 /* Make sure drawing engine can handle the font */
2681 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2682 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2683 return -EINVAL;
2685 /* Make sure driver can handle the font length */
2686 if (fbcon_invalid_charcount(info, charcount))
2687 return -EINVAL;
2689 size = h * pitch * charcount;
2691 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2693 if (!new_data)
2694 return -ENOMEM;
2696 new_data += FONT_EXTRA_WORDS * sizeof(int);
2697 FNTSIZE(new_data) = size;
2698 FNTCHARCNT(new_data) = charcount;
2699 REFCOUNT(new_data) = 0; /* usage counter */
2700 for (i=0; i< charcount; i++) {
2701 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2704 /* Since linux has a nice crc32 function use it for counting font
2705 * checksums. */
2706 csum = crc32(0, new_data, size);
2708 FNTSUM(new_data) = csum;
2709 /* Check if the same font is on some other console already */
2710 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2711 struct vc_data *tmp = vc_cons[i].d;
2713 if (fb_display[i].userfont &&
2714 fb_display[i].fontdata &&
2715 FNTSUM(fb_display[i].fontdata) == csum &&
2716 FNTSIZE(fb_display[i].fontdata) == size &&
2717 tmp->vc_font.width == w &&
2718 !memcmp(fb_display[i].fontdata, new_data, size)) {
2719 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2720 new_data = (u8 *)fb_display[i].fontdata;
2721 break;
2724 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2727 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2729 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2730 const struct font_desc *f;
2732 if (!name)
2733 f = get_default_font(info->var.xres, info->var.yres,
2734 info->pixmap.blit_x, info->pixmap.blit_y);
2735 else if (!(f = find_font(name)))
2736 return -ENOENT;
2738 font->width = f->width;
2739 font->height = f->height;
2740 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2743 static u16 palette_red[16];
2744 static u16 palette_green[16];
2745 static u16 palette_blue[16];
2747 static struct fb_cmap palette_cmap = {
2748 0, 16, palette_red, palette_green, palette_blue, NULL
2751 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2753 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2754 int i, j, k, depth;
2755 u8 val;
2757 if (fbcon_is_inactive(vc, info) || vc->vc_num != fg_console)
2758 return -EINVAL;
2760 if (!CON_IS_VISIBLE(vc))
2761 return 0;
2763 depth = fb_get_color_depth(&info->var, &info->fix);
2764 if (depth > 3) {
2765 for (i = j = 0; i < 16; i++) {
2766 k = table[i];
2767 val = vc->vc_palette[j++];
2768 palette_red[k] = (val << 8) | val;
2769 val = vc->vc_palette[j++];
2770 palette_green[k] = (val << 8) | val;
2771 val = vc->vc_palette[j++];
2772 palette_blue[k] = (val << 8) | val;
2774 palette_cmap.len = 16;
2775 palette_cmap.start = 0;
2777 * If framebuffer is capable of less than 16 colors,
2778 * use default palette of fbcon.
2780 } else
2781 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2783 if (fbcon_decor_active(info, vc_cons[fg_console].d) &&
2784 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
2786 u16 *red, *green, *blue;
2787 int minlen = min(min(info->var.red.length, info->var.green.length),
2788 info->var.blue.length);
2789 int h;
2791 struct fb_cmap cmap = {
2792 .start = 0,
2793 .len = (1 << minlen),
2794 .red = NULL,
2795 .green = NULL,
2796 .blue = NULL,
2797 .transp = NULL
2800 red = kmalloc(256 * sizeof(u16) * 3, GFP_KERNEL);
2802 if (!red)
2803 goto out;
2805 green = red + 256;
2806 blue = green + 256;
2807 cmap.red = red;
2808 cmap.green = green;
2809 cmap.blue = blue;
2811 for (i = 0; i < cmap.len; i++) {
2812 red[i] = green[i] = blue[i] = (0xffff * i)/(cmap.len-1);
2815 h = fb_set_cmap(&cmap, info);
2816 fbcon_decor_fix_pseudo_pal(info, vc_cons[fg_console].d);
2817 kfree(red);
2819 return h;
2821 } else if (fbcon_decor_active(info, vc_cons[fg_console].d) &&
2822 info->var.bits_per_pixel == 8 && info->bgdecor.cmap.red != NULL)
2823 fb_set_cmap(&info->bgdecor.cmap, info);
2825 out: return fb_set_cmap(&palette_cmap, info);
2828 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2830 unsigned long p;
2831 int line;
2833 if (vc->vc_num != fg_console || !softback_lines)
2834 return (u16 *) (vc->vc_origin + offset);
2835 line = offset / vc->vc_size_row;
2836 if (line >= softback_lines)
2837 return (u16 *) (vc->vc_origin + offset -
2838 softback_lines * vc->vc_size_row);
2839 p = softback_curr + offset;
2840 if (p >= softback_end)
2841 p += softback_buf - softback_end;
2842 return (u16 *) p;
2845 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2846 int *px, int *py)
2848 unsigned long ret;
2849 int x, y;
2851 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2852 unsigned long offset = (pos - vc->vc_origin) / 2;
2854 x = offset % vc->vc_cols;
2855 y = offset / vc->vc_cols;
2856 if (vc->vc_num == fg_console)
2857 y += softback_lines;
2858 ret = pos + (vc->vc_cols - x) * 2;
2859 } else if (vc->vc_num == fg_console && softback_lines) {
2860 unsigned long offset = pos - softback_curr;
2862 if (pos < softback_curr)
2863 offset += softback_end - softback_buf;
2864 offset /= 2;
2865 x = offset % vc->vc_cols;
2866 y = offset / vc->vc_cols;
2867 ret = pos + (vc->vc_cols - x) * 2;
2868 if (ret == softback_end)
2869 ret = softback_buf;
2870 if (ret == softback_in)
2871 ret = vc->vc_origin;
2872 } else {
2873 /* Should not happen */
2874 x = y = 0;
2875 ret = vc->vc_origin;
2877 if (px)
2878 *px = x;
2879 if (py)
2880 *py = y;
2881 return ret;
2884 /* As we might be inside of softback, we may work with non-contiguous buffer,
2885 that's why we have to use a separate routine. */
2886 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2888 while (cnt--) {
2889 u16 a = scr_readw(p);
2890 if (!vc->vc_can_do_color)
2891 a ^= 0x0800;
2892 else if (vc->vc_hi_font_mask == 0x100)
2893 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2894 (((a) & 0x0e00) << 4);
2895 else
2896 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2897 (((a) & 0x0700) << 4);
2898 scr_writew(a, p++);
2899 if (p == (u16 *) softback_end)
2900 p = (u16 *) softback_buf;
2901 if (p == (u16 *) softback_in)
2902 p = (u16 *) vc->vc_origin;
2906 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2908 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2909 struct fbcon_ops *ops = info->fbcon_par;
2910 struct display *disp = &fb_display[fg_console];
2911 int offset, limit, scrollback_old;
2913 if (softback_top) {
2914 if (vc->vc_num != fg_console)
2915 return 0;
2916 if (vc->vc_mode != KD_TEXT || !lines)
2917 return 0;
2918 if (logo_shown >= 0) {
2919 struct vc_data *conp2 = vc_cons[logo_shown].d;
2921 if (conp2->vc_top == logo_lines
2922 && conp2->vc_bottom == conp2->vc_rows)
2923 conp2->vc_top = 0;
2924 if (logo_shown == vc->vc_num) {
2925 unsigned long p, q;
2926 int i;
2928 p = softback_in;
2929 q = vc->vc_origin +
2930 logo_lines * vc->vc_size_row;
2931 for (i = 0; i < logo_lines; i++) {
2932 if (p == softback_top)
2933 break;
2934 if (p == softback_buf)
2935 p = softback_end;
2936 p -= vc->vc_size_row;
2937 q -= vc->vc_size_row;
2938 scr_memcpyw((u16 *) q, (u16 *) p,
2939 vc->vc_size_row);
2941 softback_in = softback_curr = p;
2942 update_region(vc, vc->vc_origin,
2943 logo_lines * vc->vc_cols);
2945 logo_shown = FBCON_LOGO_CANSHOW;
2947 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2948 fbcon_redraw_softback(vc, disp, lines);
2949 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2950 return 0;
2953 if (!scrollback_phys_max)
2954 return -ENOSYS;
2956 scrollback_old = scrollback_current;
2957 scrollback_current -= lines;
2958 if (scrollback_current < 0)
2959 scrollback_current = 0;
2960 else if (scrollback_current > scrollback_max)
2961 scrollback_current = scrollback_max;
2962 if (scrollback_current == scrollback_old)
2963 return 0;
2965 if (fbcon_is_inactive(vc, info))
2966 return 0;
2968 fbcon_cursor(vc, CM_ERASE);
2970 offset = disp->yscroll - scrollback_current;
2971 limit = disp->vrows;
2972 switch (disp->scrollmode) {
2973 case SCROLL_WRAP_MOVE:
2974 info->var.vmode |= FB_VMODE_YWRAP;
2975 break;
2976 case SCROLL_PAN_MOVE:
2977 case SCROLL_PAN_REDRAW:
2978 limit -= vc->vc_rows;
2979 info->var.vmode &= ~FB_VMODE_YWRAP;
2980 break;
2982 if (offset < 0)
2983 offset += limit;
2984 else if (offset >= limit)
2985 offset -= limit;
2987 ops->var.xoffset = 0;
2988 ops->var.yoffset = offset * vc->vc_font.height;
2989 ops->update_start(info);
2991 if (!scrollback_current)
2992 fbcon_cursor(vc, CM_DRAW);
2993 return 0;
2996 static int fbcon_set_origin(struct vc_data *vc)
2998 if (softback_lines)
2999 fbcon_scrolldelta(vc, softback_lines);
3000 return 0;
3003 static void fbcon_suspended(struct fb_info *info)
3005 struct vc_data *vc = NULL;
3006 struct fbcon_ops *ops = info->fbcon_par;
3008 if (!ops || ops->currcon < 0)
3009 return;
3010 vc = vc_cons[ops->currcon].d;
3012 /* Clear cursor, restore saved data */
3013 fbcon_cursor(vc, CM_ERASE);
3016 static void fbcon_resumed(struct fb_info *info)
3018 struct vc_data *vc;
3019 struct fbcon_ops *ops = info->fbcon_par;
3021 if (!ops || ops->currcon < 0)
3022 return;
3023 vc = vc_cons[ops->currcon].d;
3025 update_screen(vc);
3028 static void fbcon_modechanged(struct fb_info *info)
3030 struct fbcon_ops *ops = info->fbcon_par;
3031 struct vc_data *vc;
3032 struct display *p;
3033 int rows, cols;
3035 if (!ops || ops->currcon < 0)
3036 return;
3037 vc = vc_cons[ops->currcon].d;
3038 if (vc->vc_mode != KD_TEXT ||
3039 registered_fb[con2fb_map[ops->currcon]] != info)
3040 return;
3042 p = &fb_display[vc->vc_num];
3043 set_blitting_type(vc, info);
3045 if (CON_IS_VISIBLE(vc)) {
3046 var_to_display(p, &info->var, info);
3047 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3048 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3049 cols /= vc->vc_font.width;
3050 rows /= vc->vc_font.height;
3052 if (!fbcon_decor_active_nores(info, vc)) {
3053 vc_resize(vc, cols, rows);
3054 } else {
3055 if (fbcon_decor_call_helper("modechange", vc->vc_num))
3056 fbcon_decor_disable(vc, 0);
3059 updatescrollmode(p, info, vc);
3060 scrollback_max = 0;
3061 scrollback_current = 0;
3063 if (!fbcon_is_inactive(vc, info)) {
3064 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
3065 ops->update_start(info);
3068 fbcon_set_palette(vc, color_table);
3069 update_screen(vc);
3070 if (softback_buf)
3071 fbcon_update_softback(vc);
3075 static void fbcon_set_all_vcs(struct fb_info *info)
3077 struct fbcon_ops *ops = info->fbcon_par;
3078 struct vc_data *vc;
3079 struct display *p;
3080 int i, rows, cols, fg = -1;
3082 if (!ops || ops->currcon < 0)
3083 return;
3085 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3086 vc = vc_cons[i].d;
3087 if (!vc || vc->vc_mode != KD_TEXT ||
3088 registered_fb[con2fb_map[i]] != info)
3089 continue;
3091 if (CON_IS_VISIBLE(vc)) {
3092 fg = i;
3093 continue;
3096 p = &fb_display[vc->vc_num];
3097 set_blitting_type(vc, info);
3098 var_to_display(p, &info->var, info);
3099 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3100 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3101 cols /= vc->vc_font.width;
3102 rows /= vc->vc_font.height;
3103 vc_resize(vc, cols, rows);
3106 if (fg != -1)
3107 fbcon_modechanged(info);
3110 static int fbcon_mode_deleted(struct fb_info *info,
3111 struct fb_videomode *mode)
3113 struct fb_info *fb_info;
3114 struct display *p;
3115 int i, j, found = 0;
3117 /* before deletion, ensure that mode is not in use */
3118 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3119 j = con2fb_map[i];
3120 if (j == -1)
3121 continue;
3122 fb_info = registered_fb[j];
3123 if (fb_info != info)
3124 continue;
3125 p = &fb_display[i];
3126 if (!p || !p->mode)
3127 continue;
3128 if (fb_mode_is_equal(p->mode, mode)) {
3129 found = 1;
3130 break;
3133 return found;
3136 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3137 static int fbcon_unbind(void)
3139 int ret;
3141 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3142 fbcon_is_default);
3143 return ret;
3145 #else
3146 static inline int fbcon_unbind(void)
3148 return -EINVAL;
3150 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3152 static int fbcon_fb_unbind(int idx)
3154 int i, new_idx = -1, ret = 0;
3156 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3157 if (con2fb_map[i] != idx &&
3158 con2fb_map[i] != -1) {
3159 new_idx = i;
3160 break;
3164 if (new_idx != -1) {
3165 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3166 if (con2fb_map[i] == idx)
3167 set_con2fb_map(i, new_idx, 0);
3169 } else
3170 ret = fbcon_unbind();
3172 return ret;
3175 static int fbcon_fb_unregistered(struct fb_info *info)
3177 int i, idx = info->node;
3179 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3180 if (con2fb_map[i] == idx)
3181 con2fb_map[i] = -1;
3184 if (idx == info_idx) {
3185 info_idx = -1;
3187 for (i = 0; i < FB_MAX; i++) {
3188 if (registered_fb[i] != NULL) {
3189 info_idx = i;
3190 break;
3195 if (info_idx != -1) {
3196 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3197 if (con2fb_map[i] == -1)
3198 con2fb_map[i] = info_idx;
3202 if (!num_registered_fb)
3203 unregister_con_driver(&fb_con);
3206 if (primary_device == idx)
3207 primary_device = -1;
3209 return 0;
3212 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3213 static void fbcon_select_primary(struct fb_info *info)
3215 if (!map_override && primary_device == -1 &&
3216 fb_is_primary_device(info)) {
3217 int i;
3219 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3220 info->fix.id, info->node);
3221 primary_device = info->node;
3223 for (i = first_fb_vc; i <= last_fb_vc; i++)
3224 con2fb_map_boot[i] = primary_device;
3226 if (con_is_bound(&fb_con)) {
3227 printk(KERN_INFO "fbcon: Remapping primary device, "
3228 "fb%i, to tty %i-%i\n", info->node,
3229 first_fb_vc + 1, last_fb_vc + 1);
3230 info_idx = primary_device;
3235 #else
3236 static inline void fbcon_select_primary(struct fb_info *info)
3238 return;
3240 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3242 static int fbcon_fb_registered(struct fb_info *info)
3244 int ret = 0, i, idx = info->node;
3246 fbcon_select_primary(info);
3248 if (info_idx == -1) {
3249 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3250 if (con2fb_map_boot[i] == idx) {
3251 info_idx = idx;
3252 break;
3256 if (info_idx != -1)
3257 ret = fbcon_takeover(1);
3258 } else {
3259 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3260 if (con2fb_map_boot[i] == idx)
3261 set_con2fb_map(i, idx, 0);
3265 return ret;
3268 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3270 struct fbcon_ops *ops = info->fbcon_par;
3271 struct vc_data *vc;
3273 if (!ops || ops->currcon < 0)
3274 return;
3276 vc = vc_cons[ops->currcon].d;
3277 if (vc->vc_mode != KD_TEXT ||
3278 registered_fb[con2fb_map[ops->currcon]] != info)
3279 return;
3281 if (CON_IS_VISIBLE(vc)) {
3282 if (blank)
3283 do_blank_screen(0);
3284 else
3285 do_unblank_screen(0);
3287 ops->blank_state = blank;
3290 static void fbcon_new_modelist(struct fb_info *info)
3292 int i;
3293 struct vc_data *vc;
3294 struct fb_var_screeninfo var;
3295 const struct fb_videomode *mode;
3297 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3298 if (registered_fb[con2fb_map[i]] != info)
3299 continue;
3300 if (!fb_display[i].mode)
3301 continue;
3302 vc = vc_cons[i].d;
3303 display_to_var(&var, &fb_display[i]);
3304 mode = fb_find_nearest_mode(fb_display[i].mode,
3305 &info->modelist);
3306 fb_videomode_to_var(&var, mode);
3307 fbcon_set_disp(info, &var, vc->vc_num);
3311 static void fbcon_get_requirement(struct fb_info *info,
3312 struct fb_blit_caps *caps)
3314 struct vc_data *vc;
3315 struct display *p;
3317 if (caps->flags) {
3318 int i, charcnt;
3320 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3321 vc = vc_cons[i].d;
3322 if (vc && vc->vc_mode == KD_TEXT &&
3323 info->node == con2fb_map[i]) {
3324 p = &fb_display[i];
3325 caps->x |= 1 << (vc->vc_font.width - 1);
3326 caps->y |= 1 << (vc->vc_font.height - 1);
3327 charcnt = (p->userfont) ?
3328 FNTCHARCNT(p->fontdata) : 256;
3329 if (caps->len < charcnt)
3330 caps->len = charcnt;
3333 } else {
3334 vc = vc_cons[fg_console].d;
3336 if (vc && vc->vc_mode == KD_TEXT &&
3337 info->node == con2fb_map[fg_console]) {
3338 p = &fb_display[fg_console];
3339 caps->x = 1 << (vc->vc_font.width - 1);
3340 caps->y = 1 << (vc->vc_font.height - 1);
3341 caps->len = (p->userfont) ?
3342 FNTCHARCNT(p->fontdata) : 256;
3347 static int fbcon_event_notify(struct notifier_block *self,
3348 unsigned long action, void *data)
3350 struct fb_event *event = data;
3351 struct fb_info *info = event->info;
3352 struct fb_videomode *mode;
3353 struct fb_con2fbmap *con2fb;
3354 struct fb_blit_caps *caps;
3355 int ret = 0;
3358 * ignore all events except driver registration and deregistration
3359 * if fbcon is not active
3361 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3362 action == FB_EVENT_FB_UNREGISTERED))
3363 goto done;
3365 switch(action) {
3366 case FB_EVENT_SUSPEND:
3367 fbcon_suspended(info);
3368 break;
3369 case FB_EVENT_RESUME:
3370 fbcon_resumed(info);
3371 break;
3372 case FB_EVENT_MODE_CHANGE:
3373 fbcon_modechanged(info);
3374 break;
3375 case FB_EVENT_MODE_CHANGE_ALL:
3376 fbcon_set_all_vcs(info);
3377 break;
3378 case FB_EVENT_MODE_DELETE:
3379 mode = event->data;
3380 ret = fbcon_mode_deleted(info, mode);
3381 break;
3382 case FB_EVENT_FB_UNBIND:
3383 ret = fbcon_fb_unbind(info->node);
3384 break;
3385 case FB_EVENT_FB_REGISTERED:
3386 ret = fbcon_fb_registered(info);
3387 break;
3388 case FB_EVENT_FB_UNREGISTERED:
3389 ret = fbcon_fb_unregistered(info);
3390 break;
3391 case FB_EVENT_SET_CONSOLE_MAP:
3392 con2fb = event->data;
3393 ret = set_con2fb_map(con2fb->console - 1,
3394 con2fb->framebuffer, 1);
3395 break;
3396 case FB_EVENT_GET_CONSOLE_MAP:
3397 con2fb = event->data;
3398 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3399 break;
3400 case FB_EVENT_BLANK:
3401 fbcon_fb_blanked(info, *(int *)event->data);
3402 break;
3403 case FB_EVENT_NEW_MODELIST:
3404 fbcon_new_modelist(info);
3405 break;
3406 case FB_EVENT_GET_REQ:
3407 caps = event->data;
3408 fbcon_get_requirement(info, caps);
3409 break;
3412 done:
3413 return ret;
3417 * The console `switch' structure for the frame buffer based console
3420 static const struct consw fb_con = {
3421 .owner = THIS_MODULE,
3422 .con_startup = fbcon_startup,
3423 .con_init = fbcon_init,
3424 .con_deinit = fbcon_deinit,
3425 .con_clear = fbcon_clear,
3426 .con_putc = fbcon_putc,
3427 .con_putcs = fbcon_putcs,
3428 .con_cursor = fbcon_cursor,
3429 .con_scroll = fbcon_scroll,
3430 .con_bmove = fbcon_bmove,
3431 .con_switch = fbcon_switch,
3432 .con_blank = fbcon_blank,
3433 .con_font_set = fbcon_set_font,
3434 .con_font_get = fbcon_get_font,
3435 .con_font_default = fbcon_set_def_font,
3436 .con_font_copy = fbcon_copy_font,
3437 .con_set_palette = fbcon_set_palette,
3438 .con_scrolldelta = fbcon_scrolldelta,
3439 .con_set_origin = fbcon_set_origin,
3440 .con_invert_region = fbcon_invert_region,
3441 .con_screen_pos = fbcon_screen_pos,
3442 .con_getxy = fbcon_getxy,
3443 .con_resize = fbcon_resize,
3446 static struct notifier_block fbcon_event_notifier = {
3447 .notifier_call = fbcon_event_notify,
3450 static ssize_t store_rotate(struct device *device,
3451 struct device_attribute *attr, const char *buf,
3452 size_t count)
3454 struct fb_info *info;
3455 int rotate, idx;
3456 char **last = NULL;
3458 if (fbcon_has_exited)
3459 return count;
3461 acquire_console_sem();
3462 idx = con2fb_map[fg_console];
3464 if (idx == -1 || registered_fb[idx] == NULL)
3465 goto err;
3467 info = registered_fb[idx];
3468 rotate = simple_strtoul(buf, last, 0);
3469 fbcon_rotate(info, rotate);
3470 err:
3471 release_console_sem();
3472 return count;
3475 static ssize_t store_rotate_all(struct device *device,
3476 struct device_attribute *attr,const char *buf,
3477 size_t count)
3479 struct fb_info *info;
3480 int rotate, idx;
3481 char **last = NULL;
3483 if (fbcon_has_exited)
3484 return count;
3486 acquire_console_sem();
3487 idx = con2fb_map[fg_console];
3489 if (idx == -1 || registered_fb[idx] == NULL)
3490 goto err;
3492 info = registered_fb[idx];
3493 rotate = simple_strtoul(buf, last, 0);
3494 fbcon_rotate_all(info, rotate);
3495 err:
3496 release_console_sem();
3497 return count;
3500 static ssize_t show_rotate(struct device *device,
3501 struct device_attribute *attr,char *buf)
3503 struct fb_info *info;
3504 int rotate = 0, idx;
3506 if (fbcon_has_exited)
3507 return 0;
3509 acquire_console_sem();
3510 idx = con2fb_map[fg_console];
3512 if (idx == -1 || registered_fb[idx] == NULL)
3513 goto err;
3515 info = registered_fb[idx];
3516 rotate = fbcon_get_rotate(info);
3517 err:
3518 release_console_sem();
3519 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3522 static ssize_t show_cursor_blink(struct device *device,
3523 struct device_attribute *attr, char *buf)
3525 struct fb_info *info;
3526 struct fbcon_ops *ops;
3527 int idx, blink = -1;
3529 if (fbcon_has_exited)
3530 return 0;
3532 acquire_console_sem();
3533 idx = con2fb_map[fg_console];
3535 if (idx == -1 || registered_fb[idx] == NULL)
3536 goto err;
3538 info = registered_fb[idx];
3539 ops = info->fbcon_par;
3541 if (!ops)
3542 goto err;
3544 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3545 err:
3546 release_console_sem();
3547 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3550 static ssize_t store_cursor_blink(struct device *device,
3551 struct device_attribute *attr,
3552 const char *buf, size_t count)
3554 struct fb_info *info;
3555 int blink, idx;
3556 char **last = NULL;
3558 if (fbcon_has_exited)
3559 return count;
3561 acquire_console_sem();
3562 idx = con2fb_map[fg_console];
3564 if (idx == -1 || registered_fb[idx] == NULL)
3565 goto err;
3567 info = registered_fb[idx];
3569 if (!info->fbcon_par)
3570 goto err;
3572 blink = simple_strtoul(buf, last, 0);
3574 if (blink) {
3575 fbcon_cursor_noblink = 0;
3576 fbcon_add_cursor_timer(info);
3577 } else {
3578 fbcon_cursor_noblink = 1;
3579 fbcon_del_cursor_timer(info);
3582 err:
3583 release_console_sem();
3584 return count;
3587 static struct device_attribute device_attrs[] = {
3588 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3589 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3590 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3591 store_cursor_blink),
3594 static int fbcon_init_device(void)
3596 int i, error = 0;
3598 fbcon_has_sysfs = 1;
3600 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3601 error = device_create_file(fbcon_device, &device_attrs[i]);
3603 if (error)
3604 break;
3607 if (error) {
3608 while (--i >= 0)
3609 device_remove_file(fbcon_device, &device_attrs[i]);
3611 fbcon_has_sysfs = 0;
3614 return 0;
3617 static void fbcon_start(void)
3619 if (num_registered_fb) {
3620 int i;
3622 acquire_console_sem();
3624 for (i = 0; i < FB_MAX; i++) {
3625 if (registered_fb[i] != NULL) {
3626 info_idx = i;
3627 break;
3631 release_console_sem();
3632 fbcon_takeover(0);
3636 static void fbcon_exit(void)
3638 struct fb_info *info;
3639 int i, j, mapped;
3641 if (fbcon_has_exited)
3642 return;
3644 #ifdef CONFIG_ATARI
3645 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3646 #endif
3647 #ifdef CONFIG_MAC
3648 if (MACH_IS_MAC && vbl_detected)
3649 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
3650 #endif
3652 kfree((void *)softback_buf);
3653 softback_buf = 0UL;
3655 for (i = 0; i < FB_MAX; i++) {
3656 mapped = 0;
3657 info = registered_fb[i];
3659 if (info == NULL)
3660 continue;
3662 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3663 if (con2fb_map[j] == i)
3664 mapped = 1;
3667 if (mapped) {
3668 if (info->fbops->fb_release)
3669 info->fbops->fb_release(info, 0);
3670 module_put(info->fbops->owner);
3672 if (info->fbcon_par) {
3673 struct fbcon_ops *ops = info->fbcon_par;
3675 fbcon_del_cursor_timer(info);
3676 kfree(ops->cursor_src);
3677 kfree(info->fbcon_par);
3678 info->fbcon_par = NULL;
3681 if (info->queue.func == fb_flashcursor)
3682 info->queue.func = NULL;
3686 fbcon_decor_exit();
3687 fbcon_has_exited = 1;
3690 static int __init fb_console_init(void)
3692 int i;
3694 acquire_console_sem();
3695 fb_register_client(&fbcon_event_notifier);
3696 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3697 "fbcon");
3699 if (IS_ERR(fbcon_device)) {
3700 printk(KERN_WARNING "Unable to create device "
3701 "for fbcon; errno = %ld\n",
3702 PTR_ERR(fbcon_device));
3703 fbcon_device = NULL;
3704 } else
3705 fbcon_init_device();
3707 for (i = 0; i < MAX_NR_CONSOLES; i++)
3708 con2fb_map[i] = -1;
3710 release_console_sem();
3711 fbcon_start();
3712 return 0;
3715 module_init(fb_console_init);
3717 #ifdef MODULE
3719 static void __exit fbcon_deinit_device(void)
3721 int i;
3723 if (fbcon_has_sysfs) {
3724 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3725 device_remove_file(fbcon_device, &device_attrs[i]);
3727 fbcon_has_sysfs = 0;
3731 static void __exit fb_console_exit(void)
3733 acquire_console_sem();
3734 fb_unregister_client(&fbcon_event_notifier);
3735 fbcon_deinit_device();
3736 device_destroy(fb_class, MKDEV(0, 0));
3737 fbcon_exit();
3738 release_console_sem();
3739 unregister_con_driver(&fb_con);
3742 module_exit(fb_console_exit);
3744 #endif
3746 MODULE_LICENSE("GPL");