Linux 4.19.133
[linux/fpc-iii.git] / drivers / video / fbdev / core / fbcon.c
blobcb93a6b3816092860f8ebb9173cb0963a3910dc9
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/fbcon.h>
72 #include <linux/vt_kern.h>
73 #include <linux/selection.h>
74 #include <linux/font.h>
75 #include <linux/smp.h>
76 #include <linux/init.h>
77 #include <linux/interrupt.h>
78 #include <linux/crc32.h> /* For counting font checksums */
79 #include <asm/fb.h>
80 #include <asm/irq.h>
82 #include "fbcon.h"
84 #ifdef FBCONDEBUG
85 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
86 #else
87 # define DPRINTK(fmt, args...)
88 #endif
90 enum {
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
96 static struct display fb_display[MAX_NR_CONSOLES];
98 static signed char con2fb_map[MAX_NR_CONSOLES];
99 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
101 static int logo_lines;
102 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
103 enums. */
104 static int logo_shown = FBCON_LOGO_CANSHOW;
105 /* Software scrollback */
106 static int fbcon_softback_size = 32768;
107 static unsigned long softback_buf, softback_curr;
108 static unsigned long softback_in;
109 static unsigned long softback_top, softback_end;
110 static int softback_lines;
111 /* console mappings */
112 static int first_fb_vc;
113 static int last_fb_vc = MAX_NR_CONSOLES - 1;
114 static int fbcon_is_default = 1;
115 static int fbcon_has_exited;
116 static int primary_device = -1;
117 static int fbcon_has_console_bind;
119 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
120 static int map_override;
122 static inline void fbcon_map_override(void)
124 map_override = 1;
126 #else
127 static inline void fbcon_map_override(void)
130 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
132 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
133 static bool deferred_takeover = true;
134 #else
135 #define deferred_takeover false
136 #endif
138 /* font data */
139 static char fontname[40];
141 /* current fb_info */
142 static int info_idx = -1;
144 /* console rotation */
145 static int initial_rotation = -1;
146 static int fbcon_has_sysfs;
147 static int margin_color;
149 static const struct consw fb_con;
151 #define CM_SOFTBACK (8)
153 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
155 static int fbcon_set_origin(struct vc_data *);
157 static int fbcon_cursor_noblink;
159 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
162 * Interface used by the world
165 static const char *fbcon_startup(void);
166 static void fbcon_init(struct vc_data *vc, int init);
167 static void fbcon_deinit(struct vc_data *vc);
168 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
169 int width);
170 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
171 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
172 int count, int ypos, int xpos);
173 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
174 static void fbcon_cursor(struct vc_data *vc, int mode);
175 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
176 int height, int width);
177 static int fbcon_switch(struct vc_data *vc);
178 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
179 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
182 * Internal routines
184 static __inline__ void ywrap_up(struct vc_data *vc, int count);
185 static __inline__ void ywrap_down(struct vc_data *vc, int count);
186 static __inline__ void ypan_up(struct vc_data *vc, int count);
187 static __inline__ void ypan_down(struct vc_data *vc, int count);
188 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 int unit);
192 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
193 int line, int count, int dy);
194 static void fbcon_modechanged(struct fb_info *info);
195 static void fbcon_set_all_vcs(struct fb_info *info);
196 static void fbcon_start(void);
197 static void fbcon_exit(void);
198 static struct device *fbcon_device;
200 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
201 static inline void fbcon_set_rotation(struct fb_info *info)
203 struct fbcon_ops *ops = info->fbcon_par;
205 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
206 ops->p->con_rotate < 4)
207 ops->rotate = ops->p->con_rotate;
208 else
209 ops->rotate = 0;
212 static void fbcon_rotate(struct fb_info *info, u32 rotate)
214 struct fbcon_ops *ops= info->fbcon_par;
215 struct fb_info *fb_info;
217 if (!ops || ops->currcon == -1)
218 return;
220 fb_info = registered_fb[con2fb_map[ops->currcon]];
222 if (info == fb_info) {
223 struct display *p = &fb_display[ops->currcon];
225 if (rotate < 4)
226 p->con_rotate = rotate;
227 else
228 p->con_rotate = 0;
230 fbcon_modechanged(info);
234 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
236 struct fbcon_ops *ops = info->fbcon_par;
237 struct vc_data *vc;
238 struct display *p;
239 int i;
241 if (!ops || ops->currcon < 0 || rotate > 3)
242 return;
244 for (i = first_fb_vc; i <= last_fb_vc; i++) {
245 vc = vc_cons[i].d;
246 if (!vc || vc->vc_mode != KD_TEXT ||
247 registered_fb[con2fb_map[i]] != info)
248 continue;
250 p = &fb_display[vc->vc_num];
251 p->con_rotate = rotate;
254 fbcon_set_all_vcs(info);
256 #else
257 static inline void fbcon_set_rotation(struct fb_info *info)
259 struct fbcon_ops *ops = info->fbcon_par;
261 ops->rotate = FB_ROTATE_UR;
264 static void fbcon_rotate(struct fb_info *info, u32 rotate)
266 return;
269 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
271 return;
273 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
275 static int fbcon_get_rotate(struct fb_info *info)
277 struct fbcon_ops *ops = info->fbcon_par;
279 return (ops) ? ops->rotate : 0;
282 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
284 struct fbcon_ops *ops = info->fbcon_par;
286 return (info->state != FBINFO_STATE_RUNNING ||
287 vc->vc_mode != KD_TEXT || ops->graphics) &&
288 !vt_force_oops_output(vc);
291 static int get_color(struct vc_data *vc, struct fb_info *info,
292 u16 c, int is_fg)
294 int depth = fb_get_color_depth(&info->var, &info->fix);
295 int color = 0;
297 if (console_blanked) {
298 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
300 c = vc->vc_video_erase_char & charmask;
303 if (depth != 1)
304 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
305 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
307 switch (depth) {
308 case 1:
310 int col = mono_col(info);
311 /* 0 or 1 */
312 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
313 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
315 if (console_blanked)
316 fg = bg;
318 color = (is_fg) ? fg : bg;
319 break;
321 case 2:
323 * Scale down 16-colors to 4 colors. Default 4-color palette
324 * is grayscale. However, simply dividing the values by 4
325 * will not work, as colors 1, 2 and 3 will be scaled-down
326 * to zero rendering them invisible. So empirically convert
327 * colors to a sane 4-level grayscale.
329 switch (color) {
330 case 0:
331 color = 0; /* black */
332 break;
333 case 1 ... 6:
334 color = 2; /* white */
335 break;
336 case 7 ... 8:
337 color = 1; /* gray */
338 break;
339 default:
340 color = 3; /* intense white */
341 break;
343 break;
344 case 3:
346 * Last 8 entries of default 16-color palette is a more intense
347 * version of the first 8 (i.e., same chrominance, different
348 * luminance).
350 color &= 7;
351 break;
355 return color;
358 static void fbcon_update_softback(struct vc_data *vc)
360 int l = fbcon_softback_size / vc->vc_size_row;
362 if (l > 5)
363 softback_end = softback_buf + l * vc->vc_size_row;
364 else
365 /* Smaller scrollback makes no sense, and 0 would screw
366 the operation totally */
367 softback_top = 0;
370 static void fb_flashcursor(struct work_struct *work)
372 struct fb_info *info = container_of(work, struct fb_info, queue);
373 struct fbcon_ops *ops = info->fbcon_par;
374 struct vc_data *vc = NULL;
375 int c;
376 int mode;
377 int ret;
379 /* FIXME: we should sort out the unbind locking instead */
380 /* instead we just fail to flash the cursor if we can't get
381 * the lock instead of blocking fbcon deinit */
382 ret = console_trylock();
383 if (ret == 0)
384 return;
386 if (ops && ops->currcon != -1)
387 vc = vc_cons[ops->currcon].d;
389 if (!vc || !con_is_visible(vc) ||
390 registered_fb[con2fb_map[vc->vc_num]] != info ||
391 vc->vc_deccm != 1) {
392 console_unlock();
393 return;
396 c = scr_readw((u16 *) vc->vc_pos);
397 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
398 CM_ERASE : CM_DRAW;
399 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
400 get_color(vc, info, c, 0));
401 console_unlock();
404 static void cursor_timer_handler(struct timer_list *t)
406 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
407 struct fb_info *info = ops->info;
409 queue_work(system_power_efficient_wq, &info->queue);
410 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
413 static void fbcon_add_cursor_timer(struct fb_info *info)
415 struct fbcon_ops *ops = info->fbcon_par;
417 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
418 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
419 !fbcon_cursor_noblink) {
420 if (!info->queue.func)
421 INIT_WORK(&info->queue, fb_flashcursor);
423 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
424 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
425 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
429 static void fbcon_del_cursor_timer(struct fb_info *info)
431 struct fbcon_ops *ops = info->fbcon_par;
433 if (info->queue.func == fb_flashcursor &&
434 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
435 del_timer_sync(&ops->cursor_timer);
436 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
440 #ifndef MODULE
441 static int __init fb_console_setup(char *this_opt)
443 char *options;
444 int i, j;
446 if (!this_opt || !*this_opt)
447 return 1;
449 while ((options = strsep(&this_opt, ",")) != NULL) {
450 if (!strncmp(options, "font:", 5)) {
451 strlcpy(fontname, options + 5, sizeof(fontname));
452 continue;
455 if (!strncmp(options, "scrollback:", 11)) {
456 options += 11;
457 if (*options) {
458 fbcon_softback_size = simple_strtoul(options, &options, 0);
459 if (*options == 'k' || *options == 'K') {
460 fbcon_softback_size *= 1024;
463 continue;
466 if (!strncmp(options, "map:", 4)) {
467 options += 4;
468 if (*options) {
469 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
470 if (!options[j])
471 j = 0;
472 con2fb_map_boot[i] =
473 (options[j++]-'0') % FB_MAX;
476 fbcon_map_override();
478 continue;
481 if (!strncmp(options, "vc:", 3)) {
482 options += 3;
483 if (*options)
484 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
485 if (first_fb_vc < 0)
486 first_fb_vc = 0;
487 if (*options++ == '-')
488 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
489 fbcon_is_default = 0;
490 continue;
493 if (!strncmp(options, "rotate:", 7)) {
494 options += 7;
495 if (*options)
496 initial_rotation = simple_strtoul(options, &options, 0);
497 if (initial_rotation > 3)
498 initial_rotation = 0;
499 continue;
502 if (!strncmp(options, "margin:", 7)) {
503 options += 7;
504 if (*options)
505 margin_color = simple_strtoul(options, &options, 0);
506 continue;
508 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
509 if (!strcmp(options, "nodefer")) {
510 deferred_takeover = false;
511 continue;
513 #endif
515 return 1;
518 __setup("fbcon=", fb_console_setup);
519 #endif
521 static int search_fb_in_map(int idx)
523 int i, retval = 0;
525 for (i = first_fb_vc; i <= last_fb_vc; i++) {
526 if (con2fb_map[i] == idx)
527 retval = 1;
529 return retval;
532 static int search_for_mapped_con(void)
534 int i, retval = 0;
536 for (i = first_fb_vc; i <= last_fb_vc; i++) {
537 if (con2fb_map[i] != -1)
538 retval = 1;
540 return retval;
543 static int do_fbcon_takeover(int show_logo)
545 int err, i;
547 if (!num_registered_fb)
548 return -ENODEV;
550 if (!show_logo)
551 logo_shown = FBCON_LOGO_DONTSHOW;
553 for (i = first_fb_vc; i <= last_fb_vc; i++)
554 con2fb_map[i] = info_idx;
556 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
557 fbcon_is_default);
559 if (err) {
560 for (i = first_fb_vc; i <= last_fb_vc; i++)
561 con2fb_map[i] = -1;
562 info_idx = -1;
563 } else {
564 fbcon_has_console_bind = 1;
567 return err;
570 #ifdef MODULE
571 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
572 int cols, int rows, int new_cols, int new_rows)
574 logo_shown = FBCON_LOGO_DONTSHOW;
576 #else
577 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
578 int cols, int rows, int new_cols, int new_rows)
580 /* Need to make room for the logo */
581 struct fbcon_ops *ops = info->fbcon_par;
582 int cnt, erase = vc->vc_video_erase_char, step;
583 unsigned short *save = NULL, *r, *q;
584 int logo_height;
586 if (info->fbops->owner) {
587 logo_shown = FBCON_LOGO_DONTSHOW;
588 return;
592 * remove underline attribute from erase character
593 * if black and white framebuffer.
595 if (fb_get_color_depth(&info->var, &info->fix) == 1)
596 erase &= ~0x400;
597 logo_height = fb_prepare_logo(info, ops->rotate);
598 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
599 q = (unsigned short *) (vc->vc_origin +
600 vc->vc_size_row * rows);
601 step = logo_lines * cols;
602 for (r = q - logo_lines * cols; r < q; r++)
603 if (scr_readw(r) != vc->vc_video_erase_char)
604 break;
605 if (r != q && new_rows >= rows + logo_lines) {
606 save = kmalloc(array3_size(logo_lines, new_cols, 2),
607 GFP_KERNEL);
608 if (save) {
609 int i = cols < new_cols ? cols : new_cols;
610 scr_memsetw(save, erase, logo_lines * new_cols * 2);
611 r = q - step;
612 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
613 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
614 r = q;
617 if (r == q) {
618 /* We can scroll screen down */
619 r = q - step - cols;
620 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
621 scr_memcpyw(r + step, r, vc->vc_size_row);
622 r -= cols;
624 if (!save) {
625 int lines;
626 if (vc->vc_y + logo_lines >= rows)
627 lines = rows - vc->vc_y - 1;
628 else
629 lines = logo_lines;
630 vc->vc_y += lines;
631 vc->vc_pos += lines * vc->vc_size_row;
634 scr_memsetw((unsigned short *) vc->vc_origin,
635 erase,
636 vc->vc_size_row * logo_lines);
638 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
639 fbcon_clear_margins(vc, 0);
640 update_screen(vc);
643 if (save) {
644 q = (unsigned short *) (vc->vc_origin +
645 vc->vc_size_row *
646 rows);
647 scr_memcpyw(q, save, logo_lines * new_cols * 2);
648 vc->vc_y += logo_lines;
649 vc->vc_pos += logo_lines * vc->vc_size_row;
650 kfree(save);
653 if (logo_lines > vc->vc_bottom) {
654 logo_shown = FBCON_LOGO_CANSHOW;
655 printk(KERN_INFO
656 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
657 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
658 logo_shown = FBCON_LOGO_DRAW;
659 vc->vc_top = logo_lines;
662 #endif /* MODULE */
664 #ifdef CONFIG_FB_TILEBLITTING
665 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
667 struct fbcon_ops *ops = info->fbcon_par;
669 ops->p = &fb_display[vc->vc_num];
671 if ((info->flags & FBINFO_MISC_TILEBLITTING))
672 fbcon_set_tileops(vc, info);
673 else {
674 fbcon_set_rotation(info);
675 fbcon_set_bitops(ops);
679 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
681 int err = 0;
683 if (info->flags & FBINFO_MISC_TILEBLITTING &&
684 info->tileops->fb_get_tilemax(info) < charcount)
685 err = 1;
687 return err;
689 #else
690 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
692 struct fbcon_ops *ops = info->fbcon_par;
694 info->flags &= ~FBINFO_MISC_TILEBLITTING;
695 ops->p = &fb_display[vc->vc_num];
696 fbcon_set_rotation(info);
697 fbcon_set_bitops(ops);
700 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
702 return 0;
705 #endif /* CONFIG_MISC_TILEBLITTING */
708 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
709 int unit, int oldidx)
711 struct fbcon_ops *ops = NULL;
712 int err = 0;
714 if (!try_module_get(info->fbops->owner))
715 err = -ENODEV;
717 if (!err && info->fbops->fb_open &&
718 info->fbops->fb_open(info, 0))
719 err = -ENODEV;
721 if (!err) {
722 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
723 if (!ops)
724 err = -ENOMEM;
727 if (!err) {
728 ops->cur_blink_jiffies = HZ / 5;
729 ops->info = info;
730 info->fbcon_par = ops;
732 if (vc)
733 set_blitting_type(vc, info);
736 if (err) {
737 con2fb_map[unit] = oldidx;
738 module_put(info->fbops->owner);
741 return err;
744 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
745 struct fb_info *newinfo, int unit,
746 int oldidx, int found)
748 struct fbcon_ops *ops = oldinfo->fbcon_par;
749 int err = 0, ret;
751 if (oldinfo->fbops->fb_release &&
752 oldinfo->fbops->fb_release(oldinfo, 0)) {
753 con2fb_map[unit] = oldidx;
754 if (!found && newinfo->fbops->fb_release)
755 newinfo->fbops->fb_release(newinfo, 0);
756 if (!found)
757 module_put(newinfo->fbops->owner);
758 err = -ENODEV;
761 if (!err) {
762 fbcon_del_cursor_timer(oldinfo);
763 kfree(ops->cursor_state.mask);
764 kfree(ops->cursor_data);
765 kfree(ops->cursor_src);
766 kfree(ops->fontbuffer);
767 kfree(oldinfo->fbcon_par);
768 oldinfo->fbcon_par = NULL;
769 module_put(oldinfo->fbops->owner);
771 If oldinfo and newinfo are driving the same hardware,
772 the fb_release() method of oldinfo may attempt to
773 restore the hardware state. This will leave the
774 newinfo in an undefined state. Thus, a call to
775 fb_set_par() may be needed for the newinfo.
777 if (newinfo && newinfo->fbops->fb_set_par) {
778 ret = newinfo->fbops->fb_set_par(newinfo);
780 if (ret)
781 printk(KERN_ERR "con2fb_release_oldinfo: "
782 "detected unhandled fb_set_par error, "
783 "error code %d\n", ret);
787 return err;
790 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
791 int unit, int show_logo)
793 struct fbcon_ops *ops = info->fbcon_par;
794 int ret;
796 ops->currcon = fg_console;
798 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
799 ret = info->fbops->fb_set_par(info);
801 if (ret)
802 printk(KERN_ERR "con2fb_init_display: detected "
803 "unhandled fb_set_par error, "
804 "error code %d\n", ret);
807 ops->flags |= FBCON_FLAGS_INIT;
808 ops->graphics = 0;
809 fbcon_set_disp(info, &info->var, unit);
811 if (show_logo) {
812 struct vc_data *fg_vc = vc_cons[fg_console].d;
813 struct fb_info *fg_info =
814 registered_fb[con2fb_map[fg_console]];
816 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
817 fg_vc->vc_rows, fg_vc->vc_cols,
818 fg_vc->vc_rows);
821 update_screen(vc_cons[fg_console].d);
825 * set_con2fb_map - map console to frame buffer device
826 * @unit: virtual console number to map
827 * @newidx: frame buffer index to map virtual console to
828 * @user: user request
830 * Maps a virtual console @unit to a frame buffer device
831 * @newidx.
833 * This should be called with the console lock held.
835 static int set_con2fb_map(int unit, int newidx, int user)
837 struct vc_data *vc = vc_cons[unit].d;
838 int oldidx = con2fb_map[unit];
839 struct fb_info *info = registered_fb[newidx];
840 struct fb_info *oldinfo = NULL;
841 int found, err = 0;
843 WARN_CONSOLE_UNLOCKED();
845 if (oldidx == newidx)
846 return 0;
848 if (!info)
849 return -EINVAL;
851 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
852 info_idx = newidx;
853 return do_fbcon_takeover(0);
856 if (oldidx != -1)
857 oldinfo = registered_fb[oldidx];
859 found = search_fb_in_map(newidx);
861 con2fb_map[unit] = newidx;
862 if (!err && !found)
863 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
867 * If old fb is not mapped to any of the consoles,
868 * fbcon should release it.
870 if (!err && oldinfo && !search_fb_in_map(oldidx))
871 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
872 found);
874 if (!err) {
875 int show_logo = (fg_console == 0 && !user &&
876 logo_shown != FBCON_LOGO_DONTSHOW);
878 if (!found)
879 fbcon_add_cursor_timer(info);
880 con2fb_map_boot[unit] = newidx;
881 con2fb_init_display(vc, info, unit, show_logo);
884 if (!search_fb_in_map(info_idx))
885 info_idx = newidx;
887 return err;
891 * Low Level Operations
893 /* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
894 static int var_to_display(struct display *disp,
895 struct fb_var_screeninfo *var,
896 struct fb_info *info)
898 disp->xres_virtual = var->xres_virtual;
899 disp->yres_virtual = var->yres_virtual;
900 disp->bits_per_pixel = var->bits_per_pixel;
901 disp->grayscale = var->grayscale;
902 disp->nonstd = var->nonstd;
903 disp->accel_flags = var->accel_flags;
904 disp->height = var->height;
905 disp->width = var->width;
906 disp->red = var->red;
907 disp->green = var->green;
908 disp->blue = var->blue;
909 disp->transp = var->transp;
910 disp->rotate = var->rotate;
911 disp->mode = fb_match_mode(var, &info->modelist);
912 if (disp->mode == NULL)
913 /* This should not happen */
914 return -EINVAL;
915 return 0;
918 static void display_to_var(struct fb_var_screeninfo *var,
919 struct display *disp)
921 fb_videomode_to_var(var, disp->mode);
922 var->xres_virtual = disp->xres_virtual;
923 var->yres_virtual = disp->yres_virtual;
924 var->bits_per_pixel = disp->bits_per_pixel;
925 var->grayscale = disp->grayscale;
926 var->nonstd = disp->nonstd;
927 var->accel_flags = disp->accel_flags;
928 var->height = disp->height;
929 var->width = disp->width;
930 var->red = disp->red;
931 var->green = disp->green;
932 var->blue = disp->blue;
933 var->transp = disp->transp;
934 var->rotate = disp->rotate;
937 static const char *fbcon_startup(void)
939 const char *display_desc = "frame buffer device";
940 struct display *p = &fb_display[fg_console];
941 struct vc_data *vc = vc_cons[fg_console].d;
942 const struct font_desc *font = NULL;
943 struct module *owner;
944 struct fb_info *info = NULL;
945 struct fbcon_ops *ops;
946 int rows, cols;
949 * If num_registered_fb is zero, this is a call for the dummy part.
950 * The frame buffer devices weren't initialized yet.
952 if (!num_registered_fb || info_idx == -1)
953 return display_desc;
955 * Instead of blindly using registered_fb[0], we use info_idx, set by
956 * fb_console_init();
958 info = registered_fb[info_idx];
959 if (!info)
960 return NULL;
962 owner = info->fbops->owner;
963 if (!try_module_get(owner))
964 return NULL;
965 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
966 module_put(owner);
967 return NULL;
970 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
971 if (!ops) {
972 module_put(owner);
973 return NULL;
976 ops->currcon = -1;
977 ops->graphics = 1;
978 ops->cur_rotate = -1;
979 ops->cur_blink_jiffies = HZ / 5;
980 ops->info = info;
981 info->fbcon_par = ops;
983 p->con_rotate = initial_rotation;
984 if (p->con_rotate == -1)
985 p->con_rotate = info->fbcon_rotate_hint;
986 if (p->con_rotate == -1)
987 p->con_rotate = FB_ROTATE_UR;
989 set_blitting_type(vc, info);
991 if (info->fix.type != FB_TYPE_TEXT) {
992 if (fbcon_softback_size) {
993 if (!softback_buf) {
994 softback_buf =
995 (unsigned long)
996 kmalloc(fbcon_softback_size,
997 GFP_KERNEL);
998 if (!softback_buf) {
999 fbcon_softback_size = 0;
1000 softback_top = 0;
1003 } else {
1004 if (softback_buf) {
1005 kfree((void *) softback_buf);
1006 softback_buf = 0;
1007 softback_top = 0;
1010 if (softback_buf)
1011 softback_in = softback_top = softback_curr =
1012 softback_buf;
1013 softback_lines = 0;
1016 /* Setup default font */
1017 if (!p->fontdata && !vc->vc_font.data) {
1018 if (!fontname[0] || !(font = find_font(fontname)))
1019 font = get_default_font(info->var.xres,
1020 info->var.yres,
1021 info->pixmap.blit_x,
1022 info->pixmap.blit_y);
1023 vc->vc_font.width = font->width;
1024 vc->vc_font.height = font->height;
1025 vc->vc_font.data = (void *)(p->fontdata = font->data);
1026 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1027 } else {
1028 p->fontdata = vc->vc_font.data;
1031 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1032 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1033 cols /= vc->vc_font.width;
1034 rows /= vc->vc_font.height;
1035 vc_resize(vc, cols, rows);
1037 DPRINTK("mode: %s\n", info->fix.id);
1038 DPRINTK("visual: %d\n", info->fix.visual);
1039 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1040 info->var.yres,
1041 info->var.bits_per_pixel);
1043 fbcon_add_cursor_timer(info);
1044 fbcon_has_exited = 0;
1045 return display_desc;
1048 static void fbcon_init(struct vc_data *vc, int init)
1050 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1051 struct fbcon_ops *ops;
1052 struct vc_data **default_mode = vc->vc_display_fg;
1053 struct vc_data *svc = *default_mode;
1054 struct display *t, *p = &fb_display[vc->vc_num];
1055 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1056 int cap, ret;
1058 if (info_idx == -1 || info == NULL)
1059 return;
1061 cap = info->flags;
1063 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1064 (info->fix.type == FB_TYPE_TEXT))
1065 logo = 0;
1067 if (var_to_display(p, &info->var, info))
1068 return;
1070 if (!info->fbcon_par)
1071 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1073 /* If we are not the first console on this
1074 fb, copy the font from that console */
1075 t = &fb_display[fg_console];
1076 if (!p->fontdata) {
1077 if (t->fontdata) {
1078 struct vc_data *fvc = vc_cons[fg_console].d;
1080 vc->vc_font.data = (void *)(p->fontdata =
1081 fvc->vc_font.data);
1082 vc->vc_font.width = fvc->vc_font.width;
1083 vc->vc_font.height = fvc->vc_font.height;
1084 p->userfont = t->userfont;
1086 if (p->userfont)
1087 REFCOUNT(p->fontdata)++;
1088 } else {
1089 const struct font_desc *font = NULL;
1091 if (!fontname[0] || !(font = find_font(fontname)))
1092 font = get_default_font(info->var.xres,
1093 info->var.yres,
1094 info->pixmap.blit_x,
1095 info->pixmap.blit_y);
1096 vc->vc_font.width = font->width;
1097 vc->vc_font.height = font->height;
1098 vc->vc_font.data = (void *)(p->fontdata = font->data);
1099 vc->vc_font.charcount = 256; /* FIXME Need to
1100 support more fonts */
1104 if (p->userfont)
1105 charcnt = FNTCHARCNT(p->fontdata);
1107 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
1108 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1109 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1110 if (charcnt == 256) {
1111 vc->vc_hi_font_mask = 0;
1112 } else {
1113 vc->vc_hi_font_mask = 0x100;
1114 if (vc->vc_can_do_color)
1115 vc->vc_complement_mask <<= 1;
1118 if (!*svc->vc_uni_pagedir_loc)
1119 con_set_default_unimap(svc);
1120 if (!*vc->vc_uni_pagedir_loc)
1121 con_copy_unimap(vc, svc);
1123 ops = info->fbcon_par;
1124 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1126 p->con_rotate = initial_rotation;
1127 if (p->con_rotate == -1)
1128 p->con_rotate = info->fbcon_rotate_hint;
1129 if (p->con_rotate == -1)
1130 p->con_rotate = FB_ROTATE_UR;
1132 set_blitting_type(vc, info);
1134 cols = vc->vc_cols;
1135 rows = vc->vc_rows;
1136 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1137 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1138 new_cols /= vc->vc_font.width;
1139 new_rows /= vc->vc_font.height;
1142 * We must always set the mode. The mode of the previous console
1143 * driver could be in the same resolution but we are using different
1144 * hardware so we have to initialize the hardware.
1146 * We need to do it in fbcon_init() to prevent screen corruption.
1148 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1149 if (info->fbops->fb_set_par &&
1150 !(ops->flags & FBCON_FLAGS_INIT)) {
1151 ret = info->fbops->fb_set_par(info);
1153 if (ret)
1154 printk(KERN_ERR "fbcon_init: detected "
1155 "unhandled fb_set_par error, "
1156 "error code %d\n", ret);
1159 ops->flags |= FBCON_FLAGS_INIT;
1162 ops->graphics = 0;
1164 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1165 !(cap & FBINFO_HWACCEL_DISABLED))
1166 p->scrollmode = SCROLL_MOVE;
1167 else /* default to something safe */
1168 p->scrollmode = SCROLL_REDRAW;
1171 * ++guenther: console.c:vc_allocate() relies on initializing
1172 * vc_{cols,rows}, but we must not set those if we are only
1173 * resizing the console.
1175 if (init) {
1176 vc->vc_cols = new_cols;
1177 vc->vc_rows = new_rows;
1178 } else
1179 vc_resize(vc, new_cols, new_rows);
1181 if (logo)
1182 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1184 if (vc == svc && softback_buf)
1185 fbcon_update_softback(vc);
1187 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1188 ops->rotate = FB_ROTATE_UR;
1189 set_blitting_type(vc, info);
1192 ops->p = &fb_display[fg_console];
1195 static void fbcon_free_font(struct display *p, bool freefont)
1197 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1198 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1199 p->fontdata = NULL;
1200 p->userfont = 0;
1203 static void set_vc_hi_font(struct vc_data *vc, bool set);
1205 static void fbcon_deinit(struct vc_data *vc)
1207 struct display *p = &fb_display[vc->vc_num];
1208 struct fb_info *info;
1209 struct fbcon_ops *ops;
1210 int idx;
1211 bool free_font = true;
1213 idx = con2fb_map[vc->vc_num];
1215 if (idx == -1)
1216 goto finished;
1218 info = registered_fb[idx];
1220 if (!info)
1221 goto finished;
1223 if (info->flags & FBINFO_MISC_FIRMWARE)
1224 free_font = false;
1225 ops = info->fbcon_par;
1227 if (!ops)
1228 goto finished;
1230 if (con_is_visible(vc))
1231 fbcon_del_cursor_timer(info);
1233 ops->flags &= ~FBCON_FLAGS_INIT;
1234 finished:
1236 fbcon_free_font(p, free_font);
1237 if (free_font)
1238 vc->vc_font.data = NULL;
1240 if (vc->vc_hi_font_mask && vc->vc_screenbuf)
1241 set_vc_hi_font(vc, false);
1243 if (!con_is_bound(&fb_con))
1244 fbcon_exit();
1246 if (vc->vc_num == logo_shown)
1247 logo_shown = FBCON_LOGO_CANSHOW;
1249 return;
1252 /* ====================================================================== */
1254 /* fbcon_XXX routines - interface used by the world
1256 * This system is now divided into two levels because of complications
1257 * caused by hardware scrolling. Top level functions:
1259 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1261 * handles y values in range [0, scr_height-1] that correspond to real
1262 * screen positions. y_wrap shift means that first line of bitmap may be
1263 * anywhere on this display. These functions convert lineoffsets to
1264 * bitmap offsets and deal with the wrap-around case by splitting blits.
1266 * fbcon_bmove_physical_8() -- These functions fast implementations
1267 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1268 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1270 * WARNING:
1272 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1273 * Implies should only really hardware scroll in rows. Only reason for
1274 * restriction is simplicity & efficiency at the moment.
1277 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1278 int width)
1280 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1281 struct fbcon_ops *ops = info->fbcon_par;
1283 struct display *p = &fb_display[vc->vc_num];
1284 u_int y_break;
1286 if (fbcon_is_inactive(vc, info))
1287 return;
1289 if (!height || !width)
1290 return;
1292 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
1293 vc->vc_top = 0;
1295 * If the font dimensions are not an integral of the display
1296 * dimensions then the ops->clear below won't end up clearing
1297 * the margins. Call clear_margins here in case the logo
1298 * bitmap stretched into the margin area.
1300 fbcon_clear_margins(vc, 0);
1303 /* Split blits that cross physical y_wrap boundary */
1305 y_break = p->vrows - p->yscroll;
1306 if (sy < y_break && sy + height - 1 >= y_break) {
1307 u_int b = y_break - sy;
1308 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1309 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1310 width);
1311 } else
1312 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1315 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1316 int count, int ypos, int xpos)
1318 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1319 struct display *p = &fb_display[vc->vc_num];
1320 struct fbcon_ops *ops = info->fbcon_par;
1322 if (!fbcon_is_inactive(vc, info))
1323 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1324 get_color(vc, info, scr_readw(s), 1),
1325 get_color(vc, info, scr_readw(s), 0));
1328 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1330 unsigned short chr;
1332 scr_writew(c, &chr);
1333 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1336 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1338 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1339 struct fbcon_ops *ops = info->fbcon_par;
1341 if (!fbcon_is_inactive(vc, info))
1342 ops->clear_margins(vc, info, margin_color, bottom_only);
1345 static void fbcon_cursor(struct vc_data *vc, int mode)
1347 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1348 struct fbcon_ops *ops = info->fbcon_par;
1349 int y;
1350 int c = scr_readw((u16 *) vc->vc_pos);
1352 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1354 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1355 return;
1357 if (vc->vc_cursor_type & 0x10)
1358 fbcon_del_cursor_timer(info);
1359 else
1360 fbcon_add_cursor_timer(info);
1362 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1363 if (mode & CM_SOFTBACK) {
1364 mode &= ~CM_SOFTBACK;
1365 y = softback_lines;
1366 } else {
1367 if (softback_lines)
1368 fbcon_set_origin(vc);
1369 y = 0;
1372 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1373 get_color(vc, info, c, 0));
1376 static int scrollback_phys_max = 0;
1377 static int scrollback_max = 0;
1378 static int scrollback_current = 0;
1380 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1381 int unit)
1383 struct display *p, *t;
1384 struct vc_data **default_mode, *vc;
1385 struct vc_data *svc;
1386 struct fbcon_ops *ops = info->fbcon_par;
1387 int rows, cols, charcnt = 256;
1389 p = &fb_display[unit];
1391 if (var_to_display(p, var, info))
1392 return;
1394 vc = vc_cons[unit].d;
1396 if (!vc)
1397 return;
1399 default_mode = vc->vc_display_fg;
1400 svc = *default_mode;
1401 t = &fb_display[svc->vc_num];
1403 if (!vc->vc_font.data) {
1404 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1405 vc->vc_font.width = (*default_mode)->vc_font.width;
1406 vc->vc_font.height = (*default_mode)->vc_font.height;
1407 p->userfont = t->userfont;
1408 if (p->userfont)
1409 REFCOUNT(p->fontdata)++;
1411 if (p->userfont)
1412 charcnt = FNTCHARCNT(p->fontdata);
1414 var->activate = FB_ACTIVATE_NOW;
1415 info->var.activate = var->activate;
1416 var->yoffset = info->var.yoffset;
1417 var->xoffset = info->var.xoffset;
1418 fb_set_var(info, var);
1419 ops->var = info->var;
1420 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1421 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1422 if (charcnt == 256) {
1423 vc->vc_hi_font_mask = 0;
1424 } else {
1425 vc->vc_hi_font_mask = 0x100;
1426 if (vc->vc_can_do_color)
1427 vc->vc_complement_mask <<= 1;
1430 if (!*svc->vc_uni_pagedir_loc)
1431 con_set_default_unimap(svc);
1432 if (!*vc->vc_uni_pagedir_loc)
1433 con_copy_unimap(vc, svc);
1435 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1436 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1437 cols /= vc->vc_font.width;
1438 rows /= vc->vc_font.height;
1439 vc_resize(vc, cols, rows);
1441 if (con_is_visible(vc)) {
1442 update_screen(vc);
1443 if (softback_buf)
1444 fbcon_update_softback(vc);
1448 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1450 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1451 struct fbcon_ops *ops = info->fbcon_par;
1452 struct display *p = &fb_display[vc->vc_num];
1454 p->yscroll += count;
1455 if (p->yscroll >= p->vrows) /* Deal with wrap */
1456 p->yscroll -= p->vrows;
1457 ops->var.xoffset = 0;
1458 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1459 ops->var.vmode |= FB_VMODE_YWRAP;
1460 ops->update_start(info);
1461 scrollback_max += count;
1462 if (scrollback_max > scrollback_phys_max)
1463 scrollback_max = scrollback_phys_max;
1464 scrollback_current = 0;
1467 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1470 struct fbcon_ops *ops = info->fbcon_par;
1471 struct display *p = &fb_display[vc->vc_num];
1473 p->yscroll -= count;
1474 if (p->yscroll < 0) /* Deal with wrap */
1475 p->yscroll += p->vrows;
1476 ops->var.xoffset = 0;
1477 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1478 ops->var.vmode |= FB_VMODE_YWRAP;
1479 ops->update_start(info);
1480 scrollback_max -= count;
1481 if (scrollback_max < 0)
1482 scrollback_max = 0;
1483 scrollback_current = 0;
1486 static __inline__ void ypan_up(struct vc_data *vc, int count)
1488 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1489 struct display *p = &fb_display[vc->vc_num];
1490 struct fbcon_ops *ops = info->fbcon_par;
1492 p->yscroll += count;
1493 if (p->yscroll > p->vrows - vc->vc_rows) {
1494 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1495 0, 0, 0, vc->vc_rows, vc->vc_cols);
1496 p->yscroll -= p->vrows - vc->vc_rows;
1499 ops->var.xoffset = 0;
1500 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1501 ops->var.vmode &= ~FB_VMODE_YWRAP;
1502 ops->update_start(info);
1503 fbcon_clear_margins(vc, 1);
1504 scrollback_max += count;
1505 if (scrollback_max > scrollback_phys_max)
1506 scrollback_max = scrollback_phys_max;
1507 scrollback_current = 0;
1510 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1512 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1513 struct fbcon_ops *ops = info->fbcon_par;
1514 struct display *p = &fb_display[vc->vc_num];
1516 p->yscroll += count;
1518 if (p->yscroll > p->vrows - vc->vc_rows) {
1519 p->yscroll -= p->vrows - vc->vc_rows;
1520 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1523 ops->var.xoffset = 0;
1524 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1525 ops->var.vmode &= ~FB_VMODE_YWRAP;
1526 ops->update_start(info);
1527 fbcon_clear_margins(vc, 1);
1528 scrollback_max += count;
1529 if (scrollback_max > scrollback_phys_max)
1530 scrollback_max = scrollback_phys_max;
1531 scrollback_current = 0;
1534 static __inline__ void ypan_down(struct vc_data *vc, int count)
1536 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1537 struct display *p = &fb_display[vc->vc_num];
1538 struct fbcon_ops *ops = info->fbcon_par;
1540 p->yscroll -= count;
1541 if (p->yscroll < 0) {
1542 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1543 0, vc->vc_rows, vc->vc_cols);
1544 p->yscroll += p->vrows - vc->vc_rows;
1547 ops->var.xoffset = 0;
1548 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1549 ops->var.vmode &= ~FB_VMODE_YWRAP;
1550 ops->update_start(info);
1551 fbcon_clear_margins(vc, 1);
1552 scrollback_max -= count;
1553 if (scrollback_max < 0)
1554 scrollback_max = 0;
1555 scrollback_current = 0;
1558 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1560 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1561 struct fbcon_ops *ops = info->fbcon_par;
1562 struct display *p = &fb_display[vc->vc_num];
1564 p->yscroll -= count;
1566 if (p->yscroll < 0) {
1567 p->yscroll += p->vrows - vc->vc_rows;
1568 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1571 ops->var.xoffset = 0;
1572 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1573 ops->var.vmode &= ~FB_VMODE_YWRAP;
1574 ops->update_start(info);
1575 fbcon_clear_margins(vc, 1);
1576 scrollback_max -= count;
1577 if (scrollback_max < 0)
1578 scrollback_max = 0;
1579 scrollback_current = 0;
1582 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1583 long delta)
1585 int count = vc->vc_rows;
1586 unsigned short *d, *s;
1587 unsigned long n;
1588 int line = 0;
1590 d = (u16 *) softback_curr;
1591 if (d == (u16 *) softback_in)
1592 d = (u16 *) vc->vc_origin;
1593 n = softback_curr + delta * vc->vc_size_row;
1594 softback_lines -= delta;
1595 if (delta < 0) {
1596 if (softback_curr < softback_top && n < softback_buf) {
1597 n += softback_end - softback_buf;
1598 if (n < softback_top) {
1599 softback_lines -=
1600 (softback_top - n) / vc->vc_size_row;
1601 n = softback_top;
1603 } else if (softback_curr >= softback_top
1604 && n < softback_top) {
1605 softback_lines -=
1606 (softback_top - n) / vc->vc_size_row;
1607 n = softback_top;
1609 } else {
1610 if (softback_curr > softback_in && n >= softback_end) {
1611 n += softback_buf - softback_end;
1612 if (n > softback_in) {
1613 n = softback_in;
1614 softback_lines = 0;
1616 } else if (softback_curr <= softback_in && n > softback_in) {
1617 n = softback_in;
1618 softback_lines = 0;
1621 if (n == softback_curr)
1622 return;
1623 softback_curr = n;
1624 s = (u16 *) softback_curr;
1625 if (s == (u16 *) softback_in)
1626 s = (u16 *) vc->vc_origin;
1627 while (count--) {
1628 unsigned short *start;
1629 unsigned short *le;
1630 unsigned short c;
1631 int x = 0;
1632 unsigned short attr = 1;
1634 start = s;
1635 le = advance_row(s, 1);
1636 do {
1637 c = scr_readw(s);
1638 if (attr != (c & 0xff00)) {
1639 attr = c & 0xff00;
1640 if (s > start) {
1641 fbcon_putcs(vc, start, s - start,
1642 line, x);
1643 x += s - start;
1644 start = s;
1647 if (c == scr_readw(d)) {
1648 if (s > start) {
1649 fbcon_putcs(vc, start, s - start,
1650 line, x);
1651 x += s - start + 1;
1652 start = s + 1;
1653 } else {
1654 x++;
1655 start++;
1658 s++;
1659 d++;
1660 } while (s < le);
1661 if (s > start)
1662 fbcon_putcs(vc, start, s - start, line, x);
1663 line++;
1664 if (d == (u16 *) softback_end)
1665 d = (u16 *) softback_buf;
1666 if (d == (u16 *) softback_in)
1667 d = (u16 *) vc->vc_origin;
1668 if (s == (u16 *) softback_end)
1669 s = (u16 *) softback_buf;
1670 if (s == (u16 *) softback_in)
1671 s = (u16 *) vc->vc_origin;
1675 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1676 int line, int count, int dy)
1678 unsigned short *s = (unsigned short *)
1679 (vc->vc_origin + vc->vc_size_row * line);
1681 while (count--) {
1682 unsigned short *start = s;
1683 unsigned short *le = advance_row(s, 1);
1684 unsigned short c;
1685 int x = 0;
1686 unsigned short attr = 1;
1688 do {
1689 c = scr_readw(s);
1690 if (attr != (c & 0xff00)) {
1691 attr = c & 0xff00;
1692 if (s > start) {
1693 fbcon_putcs(vc, start, s - start,
1694 dy, x);
1695 x += s - start;
1696 start = s;
1699 console_conditional_schedule();
1700 s++;
1701 } while (s < le);
1702 if (s > start)
1703 fbcon_putcs(vc, start, s - start, dy, x);
1704 console_conditional_schedule();
1705 dy++;
1709 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1710 struct display *p, int line, int count, int ycount)
1712 int offset = ycount * vc->vc_cols;
1713 unsigned short *d = (unsigned short *)
1714 (vc->vc_origin + vc->vc_size_row * line);
1715 unsigned short *s = d + offset;
1716 struct fbcon_ops *ops = info->fbcon_par;
1718 while (count--) {
1719 unsigned short *start = s;
1720 unsigned short *le = advance_row(s, 1);
1721 unsigned short c;
1722 int x = 0;
1724 do {
1725 c = scr_readw(s);
1727 if (c == scr_readw(d)) {
1728 if (s > start) {
1729 ops->bmove(vc, info, line + ycount, x,
1730 line, x, 1, s-start);
1731 x += s - start + 1;
1732 start = s + 1;
1733 } else {
1734 x++;
1735 start++;
1739 scr_writew(c, d);
1740 console_conditional_schedule();
1741 s++;
1742 d++;
1743 } while (s < le);
1744 if (s > start)
1745 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1746 s-start);
1747 console_conditional_schedule();
1748 if (ycount > 0)
1749 line++;
1750 else {
1751 line--;
1752 /* NOTE: We subtract two lines from these pointers */
1753 s -= vc->vc_size_row;
1754 d -= vc->vc_size_row;
1759 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1760 int line, int count, int offset)
1762 unsigned short *d = (unsigned short *)
1763 (vc->vc_origin + vc->vc_size_row * line);
1764 unsigned short *s = d + offset;
1766 while (count--) {
1767 unsigned short *start = s;
1768 unsigned short *le = advance_row(s, 1);
1769 unsigned short c;
1770 int x = 0;
1771 unsigned short attr = 1;
1773 do {
1774 c = scr_readw(s);
1775 if (attr != (c & 0xff00)) {
1776 attr = c & 0xff00;
1777 if (s > start) {
1778 fbcon_putcs(vc, start, s - start,
1779 line, x);
1780 x += s - start;
1781 start = s;
1784 if (c == scr_readw(d)) {
1785 if (s > start) {
1786 fbcon_putcs(vc, start, s - start,
1787 line, x);
1788 x += s - start + 1;
1789 start = s + 1;
1790 } else {
1791 x++;
1792 start++;
1795 scr_writew(c, d);
1796 console_conditional_schedule();
1797 s++;
1798 d++;
1799 } while (s < le);
1800 if (s > start)
1801 fbcon_putcs(vc, start, s - start, line, x);
1802 console_conditional_schedule();
1803 if (offset > 0)
1804 line++;
1805 else {
1806 line--;
1807 /* NOTE: We subtract two lines from these pointers */
1808 s -= vc->vc_size_row;
1809 d -= vc->vc_size_row;
1814 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1815 int count)
1817 unsigned short *p;
1819 if (vc->vc_num != fg_console)
1820 return;
1821 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1823 while (count) {
1824 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1825 count--;
1826 p = advance_row(p, 1);
1827 softback_in += vc->vc_size_row;
1828 if (softback_in == softback_end)
1829 softback_in = softback_buf;
1830 if (softback_in == softback_top) {
1831 softback_top += vc->vc_size_row;
1832 if (softback_top == softback_end)
1833 softback_top = softback_buf;
1836 softback_curr = softback_in;
1839 static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1840 enum con_scroll dir, unsigned int count)
1842 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1843 struct display *p = &fb_display[vc->vc_num];
1844 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1846 if (fbcon_is_inactive(vc, info))
1847 return true;
1849 fbcon_cursor(vc, CM_ERASE);
1852 * ++Geert: Only use ywrap/ypan if the console is in text mode
1853 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1854 * whole screen (prevents flicker).
1857 switch (dir) {
1858 case SM_UP:
1859 if (count > vc->vc_rows) /* Maximum realistic size */
1860 count = vc->vc_rows;
1861 if (softback_top)
1862 fbcon_softback_note(vc, t, count);
1863 if (logo_shown >= 0)
1864 goto redraw_up;
1865 switch (p->scrollmode) {
1866 case SCROLL_MOVE:
1867 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1868 count);
1869 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1870 scr_memsetw((unsigned short *) (vc->vc_origin +
1871 vc->vc_size_row *
1872 (b - count)),
1873 vc->vc_video_erase_char,
1874 vc->vc_size_row * count);
1875 return true;
1876 break;
1878 case SCROLL_WRAP_MOVE:
1879 if (b - t - count > 3 * vc->vc_rows >> 2) {
1880 if (t > 0)
1881 fbcon_bmove(vc, 0, 0, count, 0, t,
1882 vc->vc_cols);
1883 ywrap_up(vc, count);
1884 if (vc->vc_rows - b > 0)
1885 fbcon_bmove(vc, b - count, 0, b, 0,
1886 vc->vc_rows - b,
1887 vc->vc_cols);
1888 } else if (info->flags & FBINFO_READS_FAST)
1889 fbcon_bmove(vc, t + count, 0, t, 0,
1890 b - t - count, vc->vc_cols);
1891 else
1892 goto redraw_up;
1893 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1894 break;
1896 case SCROLL_PAN_REDRAW:
1897 if ((p->yscroll + count <=
1898 2 * (p->vrows - vc->vc_rows))
1899 && ((!scroll_partial && (b - t == vc->vc_rows))
1900 || (scroll_partial
1901 && (b - t - count >
1902 3 * vc->vc_rows >> 2)))) {
1903 if (t > 0)
1904 fbcon_redraw_move(vc, p, 0, t, count);
1905 ypan_up_redraw(vc, t, count);
1906 if (vc->vc_rows - b > 0)
1907 fbcon_redraw_move(vc, p, b,
1908 vc->vc_rows - b, b);
1909 } else
1910 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1911 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1912 break;
1914 case SCROLL_PAN_MOVE:
1915 if ((p->yscroll + count <=
1916 2 * (p->vrows - vc->vc_rows))
1917 && ((!scroll_partial && (b - t == vc->vc_rows))
1918 || (scroll_partial
1919 && (b - t - count >
1920 3 * vc->vc_rows >> 2)))) {
1921 if (t > 0)
1922 fbcon_bmove(vc, 0, 0, count, 0, t,
1923 vc->vc_cols);
1924 ypan_up(vc, count);
1925 if (vc->vc_rows - b > 0)
1926 fbcon_bmove(vc, b - count, 0, b, 0,
1927 vc->vc_rows - b,
1928 vc->vc_cols);
1929 } else if (info->flags & FBINFO_READS_FAST)
1930 fbcon_bmove(vc, t + count, 0, t, 0,
1931 b - t - count, vc->vc_cols);
1932 else
1933 goto redraw_up;
1934 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1935 break;
1937 case SCROLL_REDRAW:
1938 redraw_up:
1939 fbcon_redraw(vc, p, t, b - t - count,
1940 count * vc->vc_cols);
1941 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1942 scr_memsetw((unsigned short *) (vc->vc_origin +
1943 vc->vc_size_row *
1944 (b - count)),
1945 vc->vc_video_erase_char,
1946 vc->vc_size_row * count);
1947 return true;
1949 break;
1951 case SM_DOWN:
1952 if (count > vc->vc_rows) /* Maximum realistic size */
1953 count = vc->vc_rows;
1954 if (logo_shown >= 0)
1955 goto redraw_down;
1956 switch (p->scrollmode) {
1957 case SCROLL_MOVE:
1958 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1959 -count);
1960 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1961 scr_memsetw((unsigned short *) (vc->vc_origin +
1962 vc->vc_size_row *
1964 vc->vc_video_erase_char,
1965 vc->vc_size_row * count);
1966 return true;
1967 break;
1969 case SCROLL_WRAP_MOVE:
1970 if (b - t - count > 3 * vc->vc_rows >> 2) {
1971 if (vc->vc_rows - b > 0)
1972 fbcon_bmove(vc, b, 0, b - count, 0,
1973 vc->vc_rows - b,
1974 vc->vc_cols);
1975 ywrap_down(vc, count);
1976 if (t > 0)
1977 fbcon_bmove(vc, count, 0, 0, 0, t,
1978 vc->vc_cols);
1979 } else if (info->flags & FBINFO_READS_FAST)
1980 fbcon_bmove(vc, t, 0, t + count, 0,
1981 b - t - count, vc->vc_cols);
1982 else
1983 goto redraw_down;
1984 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1985 break;
1987 case SCROLL_PAN_MOVE:
1988 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1989 && ((!scroll_partial && (b - t == vc->vc_rows))
1990 || (scroll_partial
1991 && (b - t - count >
1992 3 * vc->vc_rows >> 2)))) {
1993 if (vc->vc_rows - b > 0)
1994 fbcon_bmove(vc, b, 0, b - count, 0,
1995 vc->vc_rows - b,
1996 vc->vc_cols);
1997 ypan_down(vc, count);
1998 if (t > 0)
1999 fbcon_bmove(vc, count, 0, 0, 0, t,
2000 vc->vc_cols);
2001 } else if (info->flags & FBINFO_READS_FAST)
2002 fbcon_bmove(vc, t, 0, t + count, 0,
2003 b - t - count, vc->vc_cols);
2004 else
2005 goto redraw_down;
2006 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2007 break;
2009 case SCROLL_PAN_REDRAW:
2010 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2011 && ((!scroll_partial && (b - t == vc->vc_rows))
2012 || (scroll_partial
2013 && (b - t - count >
2014 3 * vc->vc_rows >> 2)))) {
2015 if (vc->vc_rows - b > 0)
2016 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2017 b - count);
2018 ypan_down_redraw(vc, t, count);
2019 if (t > 0)
2020 fbcon_redraw_move(vc, p, count, t, 0);
2021 } else
2022 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2023 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2024 break;
2026 case SCROLL_REDRAW:
2027 redraw_down:
2028 fbcon_redraw(vc, p, b - 1, b - t - count,
2029 -count * vc->vc_cols);
2030 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2031 scr_memsetw((unsigned short *) (vc->vc_origin +
2032 vc->vc_size_row *
2034 vc->vc_video_erase_char,
2035 vc->vc_size_row * count);
2036 return true;
2039 return false;
2043 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2044 int height, int width)
2046 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2047 struct display *p = &fb_display[vc->vc_num];
2049 if (fbcon_is_inactive(vc, info))
2050 return;
2052 if (!width || !height)
2053 return;
2055 /* Split blits that cross physical y_wrap case.
2056 * Pathological case involves 4 blits, better to use recursive
2057 * code rather than unrolled case
2059 * Recursive invocations don't need to erase the cursor over and
2060 * over again, so we use fbcon_bmove_rec()
2062 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2063 p->vrows - p->yscroll);
2066 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2067 int dy, int dx, int height, int width, u_int y_break)
2069 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2070 struct fbcon_ops *ops = info->fbcon_par;
2071 u_int b;
2073 if (sy < y_break && sy + height > y_break) {
2074 b = y_break - sy;
2075 if (dy < sy) { /* Avoid trashing self */
2076 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2077 y_break);
2078 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2079 height - b, width, y_break);
2080 } else {
2081 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2082 height - b, width, y_break);
2083 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2084 y_break);
2086 return;
2089 if (dy < y_break && dy + height > y_break) {
2090 b = y_break - dy;
2091 if (dy < sy) { /* Avoid trashing self */
2092 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2093 y_break);
2094 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2095 height - b, width, y_break);
2096 } else {
2097 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2098 height - b, width, y_break);
2099 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2100 y_break);
2102 return;
2104 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2105 height, width);
2108 static void updatescrollmode(struct display *p,
2109 struct fb_info *info,
2110 struct vc_data *vc)
2112 struct fbcon_ops *ops = info->fbcon_par;
2113 int fh = vc->vc_font.height;
2114 int cap = info->flags;
2115 u16 t = 0;
2116 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2117 info->fix.xpanstep);
2118 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2119 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2120 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2121 info->var.xres_virtual);
2122 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2123 divides(ypan, vc->vc_font.height) && vyres > yres;
2124 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2125 divides(ywrap, vc->vc_font.height) &&
2126 divides(vc->vc_font.height, vyres) &&
2127 divides(vc->vc_font.height, yres);
2128 int reading_fast = cap & FBINFO_READS_FAST;
2129 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2130 !(cap & FBINFO_HWACCEL_DISABLED);
2131 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2132 !(cap & FBINFO_HWACCEL_DISABLED);
2134 p->vrows = vyres/fh;
2135 if (yres > (fh * (vc->vc_rows + 1)))
2136 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2137 if ((yres % fh) && (vyres % fh < yres % fh))
2138 p->vrows--;
2140 if (good_wrap || good_pan) {
2141 if (reading_fast || fast_copyarea)
2142 p->scrollmode = good_wrap ?
2143 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2144 else
2145 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2146 SCROLL_PAN_REDRAW;
2147 } else {
2148 if (reading_fast || (fast_copyarea && !fast_imageblit))
2149 p->scrollmode = SCROLL_MOVE;
2150 else
2151 p->scrollmode = SCROLL_REDRAW;
2155 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2156 unsigned int height, unsigned int user)
2158 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2159 struct fbcon_ops *ops = info->fbcon_par;
2160 struct display *p = &fb_display[vc->vc_num];
2161 struct fb_var_screeninfo var = info->var;
2162 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2164 virt_w = FBCON_SWAP(ops->rotate, width, height);
2165 virt_h = FBCON_SWAP(ops->rotate, height, width);
2166 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2167 vc->vc_font.height);
2168 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2169 vc->vc_font.width);
2170 var.xres = virt_w * virt_fw;
2171 var.yres = virt_h * virt_fh;
2172 x_diff = info->var.xres - var.xres;
2173 y_diff = info->var.yres - var.yres;
2174 if (x_diff < 0 || x_diff > virt_fw ||
2175 y_diff < 0 || y_diff > virt_fh) {
2176 const struct fb_videomode *mode;
2178 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2179 mode = fb_find_best_mode(&var, &info->modelist);
2180 if (mode == NULL)
2181 return -EINVAL;
2182 display_to_var(&var, p);
2183 fb_videomode_to_var(&var, mode);
2185 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2186 return -EINVAL;
2188 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2189 if (con_is_visible(vc)) {
2190 var.activate = FB_ACTIVATE_NOW |
2191 FB_ACTIVATE_FORCE;
2192 fb_set_var(info, &var);
2194 var_to_display(p, &info->var, info);
2195 ops->var = info->var;
2197 updatescrollmode(p, info, vc);
2198 return 0;
2201 static int fbcon_switch(struct vc_data *vc)
2203 struct fb_info *info, *old_info = NULL;
2204 struct fbcon_ops *ops;
2205 struct display *p = &fb_display[vc->vc_num];
2206 struct fb_var_screeninfo var;
2207 int i, ret, prev_console, charcnt = 256;
2209 info = registered_fb[con2fb_map[vc->vc_num]];
2210 ops = info->fbcon_par;
2212 if (softback_top) {
2213 if (softback_lines)
2214 fbcon_set_origin(vc);
2215 softback_top = softback_curr = softback_in = softback_buf;
2216 softback_lines = 0;
2217 fbcon_update_softback(vc);
2220 if (logo_shown >= 0) {
2221 struct vc_data *conp2 = vc_cons[logo_shown].d;
2223 if (conp2->vc_top == logo_lines
2224 && conp2->vc_bottom == conp2->vc_rows)
2225 conp2->vc_top = 0;
2226 logo_shown = FBCON_LOGO_CANSHOW;
2229 prev_console = ops->currcon;
2230 if (prev_console != -1)
2231 old_info = registered_fb[con2fb_map[prev_console]];
2233 * FIXME: If we have multiple fbdev's loaded, we need to
2234 * update all info->currcon. Perhaps, we can place this
2235 * in a centralized structure, but this might break some
2236 * drivers.
2238 * info->currcon = vc->vc_num;
2240 for_each_registered_fb(i) {
2241 if (registered_fb[i]->fbcon_par) {
2242 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2244 o->currcon = vc->vc_num;
2247 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2248 display_to_var(&var, p);
2249 var.activate = FB_ACTIVATE_NOW;
2252 * make sure we don't unnecessarily trip the memcmp()
2253 * in fb_set_var()
2255 info->var.activate = var.activate;
2256 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2257 fb_set_var(info, &var);
2258 ops->var = info->var;
2260 if (old_info != NULL && (old_info != info ||
2261 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2262 if (info->fbops->fb_set_par) {
2263 ret = info->fbops->fb_set_par(info);
2265 if (ret)
2266 printk(KERN_ERR "fbcon_switch: detected "
2267 "unhandled fb_set_par error, "
2268 "error code %d\n", ret);
2271 if (old_info != info)
2272 fbcon_del_cursor_timer(old_info);
2275 if (fbcon_is_inactive(vc, info) ||
2276 ops->blank_state != FB_BLANK_UNBLANK)
2277 fbcon_del_cursor_timer(info);
2278 else
2279 fbcon_add_cursor_timer(info);
2281 set_blitting_type(vc, info);
2282 ops->cursor_reset = 1;
2284 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2285 ops->rotate = FB_ROTATE_UR;
2286 set_blitting_type(vc, info);
2289 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2290 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2292 if (p->userfont)
2293 charcnt = FNTCHARCNT(vc->vc_font.data);
2295 if (charcnt > 256)
2296 vc->vc_complement_mask <<= 1;
2298 updatescrollmode(p, info, vc);
2300 switch (p->scrollmode) {
2301 case SCROLL_WRAP_MOVE:
2302 scrollback_phys_max = p->vrows - vc->vc_rows;
2303 break;
2304 case SCROLL_PAN_MOVE:
2305 case SCROLL_PAN_REDRAW:
2306 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2307 if (scrollback_phys_max < 0)
2308 scrollback_phys_max = 0;
2309 break;
2310 default:
2311 scrollback_phys_max = 0;
2312 break;
2315 scrollback_max = 0;
2316 scrollback_current = 0;
2318 if (!fbcon_is_inactive(vc, info)) {
2319 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2320 ops->update_start(info);
2323 fbcon_set_palette(vc, color_table);
2324 fbcon_clear_margins(vc, 0);
2326 if (logo_shown == FBCON_LOGO_DRAW) {
2328 logo_shown = fg_console;
2329 /* This is protected above by initmem_freed */
2330 fb_show_logo(info, ops->rotate);
2331 update_region(vc,
2332 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2333 vc->vc_size_row * (vc->vc_bottom -
2334 vc->vc_top) / 2);
2335 return 0;
2337 return 1;
2340 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2341 int blank)
2343 struct fb_event event;
2345 if (blank) {
2346 unsigned short charmask = vc->vc_hi_font_mask ?
2347 0x1ff : 0xff;
2348 unsigned short oldc;
2350 oldc = vc->vc_video_erase_char;
2351 vc->vc_video_erase_char &= charmask;
2352 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2353 vc->vc_video_erase_char = oldc;
2357 if (!lock_fb_info(info))
2358 return;
2359 event.info = info;
2360 event.data = &blank;
2361 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2362 unlock_fb_info(info);
2365 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2367 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2368 struct fbcon_ops *ops = info->fbcon_par;
2370 if (mode_switch) {
2371 struct fb_var_screeninfo var = info->var;
2373 ops->graphics = 1;
2375 if (!blank) {
2376 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2377 fb_set_var(info, &var);
2378 ops->graphics = 0;
2379 ops->var = info->var;
2383 if (!fbcon_is_inactive(vc, info)) {
2384 if (ops->blank_state != blank) {
2385 ops->blank_state = blank;
2386 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2387 ops->cursor_flash = (!blank);
2389 if (!(info->flags & FBINFO_MISC_USEREVENT))
2390 if (fb_blank(info, blank))
2391 fbcon_generic_blank(vc, info, blank);
2394 if (!blank)
2395 update_screen(vc);
2398 if (mode_switch || fbcon_is_inactive(vc, info) ||
2399 ops->blank_state != FB_BLANK_UNBLANK)
2400 fbcon_del_cursor_timer(info);
2401 else
2402 fbcon_add_cursor_timer(info);
2404 return 0;
2407 static int fbcon_debug_enter(struct vc_data *vc)
2409 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2410 struct fbcon_ops *ops = info->fbcon_par;
2412 ops->save_graphics = ops->graphics;
2413 ops->graphics = 0;
2414 if (info->fbops->fb_debug_enter)
2415 info->fbops->fb_debug_enter(info);
2416 fbcon_set_palette(vc, color_table);
2417 return 0;
2420 static int fbcon_debug_leave(struct vc_data *vc)
2422 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2423 struct fbcon_ops *ops = info->fbcon_par;
2425 ops->graphics = ops->save_graphics;
2426 if (info->fbops->fb_debug_leave)
2427 info->fbops->fb_debug_leave(info);
2428 return 0;
2431 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2433 u8 *fontdata = vc->vc_font.data;
2434 u8 *data = font->data;
2435 int i, j;
2437 font->width = vc->vc_font.width;
2438 font->height = vc->vc_font.height;
2439 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2440 if (!font->data)
2441 return 0;
2443 if (font->width <= 8) {
2444 j = vc->vc_font.height;
2445 for (i = 0; i < font->charcount; i++) {
2446 memcpy(data, fontdata, j);
2447 memset(data + j, 0, 32 - j);
2448 data += 32;
2449 fontdata += j;
2451 } else if (font->width <= 16) {
2452 j = vc->vc_font.height * 2;
2453 for (i = 0; i < font->charcount; i++) {
2454 memcpy(data, fontdata, j);
2455 memset(data + j, 0, 64 - j);
2456 data += 64;
2457 fontdata += j;
2459 } else if (font->width <= 24) {
2460 for (i = 0; i < font->charcount; i++) {
2461 for (j = 0; j < vc->vc_font.height; j++) {
2462 *data++ = fontdata[0];
2463 *data++ = fontdata[1];
2464 *data++ = fontdata[2];
2465 fontdata += sizeof(u32);
2467 memset(data, 0, 3 * (32 - j));
2468 data += 3 * (32 - j);
2470 } else {
2471 j = vc->vc_font.height * 4;
2472 for (i = 0; i < font->charcount; i++) {
2473 memcpy(data, fontdata, j);
2474 memset(data + j, 0, 128 - j);
2475 data += 128;
2476 fontdata += j;
2479 return 0;
2482 /* set/clear vc_hi_font_mask and update vc attrs accordingly */
2483 static void set_vc_hi_font(struct vc_data *vc, bool set)
2485 if (!set) {
2486 vc->vc_hi_font_mask = 0;
2487 if (vc->vc_can_do_color) {
2488 vc->vc_complement_mask >>= 1;
2489 vc->vc_s_complement_mask >>= 1;
2492 /* ++Edmund: reorder the attribute bits */
2493 if (vc->vc_can_do_color) {
2494 unsigned short *cp =
2495 (unsigned short *) vc->vc_origin;
2496 int count = vc->vc_screenbuf_size / 2;
2497 unsigned short c;
2498 for (; count > 0; count--, cp++) {
2499 c = scr_readw(cp);
2500 scr_writew(((c & 0xfe00) >> 1) |
2501 (c & 0xff), cp);
2503 c = vc->vc_video_erase_char;
2504 vc->vc_video_erase_char =
2505 ((c & 0xfe00) >> 1) | (c & 0xff);
2506 vc->vc_attr >>= 1;
2508 } else {
2509 vc->vc_hi_font_mask = 0x100;
2510 if (vc->vc_can_do_color) {
2511 vc->vc_complement_mask <<= 1;
2512 vc->vc_s_complement_mask <<= 1;
2515 /* ++Edmund: reorder the attribute bits */
2517 unsigned short *cp =
2518 (unsigned short *) vc->vc_origin;
2519 int count = vc->vc_screenbuf_size / 2;
2520 unsigned short c;
2521 for (; count > 0; count--, cp++) {
2522 unsigned short newc;
2523 c = scr_readw(cp);
2524 if (vc->vc_can_do_color)
2525 newc =
2526 ((c & 0xff00) << 1) | (c &
2527 0xff);
2528 else
2529 newc = c & ~0x100;
2530 scr_writew(newc, cp);
2532 c = vc->vc_video_erase_char;
2533 if (vc->vc_can_do_color) {
2534 vc->vc_video_erase_char =
2535 ((c & 0xff00) << 1) | (c & 0xff);
2536 vc->vc_attr <<= 1;
2537 } else
2538 vc->vc_video_erase_char = c & ~0x100;
2543 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2544 const u8 * data, int userfont)
2546 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2547 struct fbcon_ops *ops = info->fbcon_par;
2548 struct display *p = &fb_display[vc->vc_num];
2549 int resize;
2550 int cnt;
2551 char *old_data = NULL;
2553 if (con_is_visible(vc) && softback_lines)
2554 fbcon_set_origin(vc);
2556 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2557 if (p->userfont)
2558 old_data = vc->vc_font.data;
2559 if (userfont)
2560 cnt = FNTCHARCNT(data);
2561 else
2562 cnt = 256;
2563 vc->vc_font.data = (void *)(p->fontdata = data);
2564 if ((p->userfont = userfont))
2565 REFCOUNT(data)++;
2566 vc->vc_font.width = w;
2567 vc->vc_font.height = h;
2568 if (vc->vc_hi_font_mask && cnt == 256)
2569 set_vc_hi_font(vc, false);
2570 else if (!vc->vc_hi_font_mask && cnt == 512)
2571 set_vc_hi_font(vc, true);
2573 if (resize) {
2574 int cols, rows;
2576 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2577 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2578 cols /= w;
2579 rows /= h;
2580 vc_resize(vc, cols, rows);
2581 if (con_is_visible(vc) && softback_buf)
2582 fbcon_update_softback(vc);
2583 } else if (con_is_visible(vc)
2584 && vc->vc_mode == KD_TEXT) {
2585 fbcon_clear_margins(vc, 0);
2586 update_screen(vc);
2589 if (old_data && (--REFCOUNT(old_data) == 0))
2590 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2591 return 0;
2594 static int fbcon_copy_font(struct vc_data *vc, int con)
2596 struct display *od = &fb_display[con];
2597 struct console_font *f = &vc->vc_font;
2599 if (od->fontdata == f->data)
2600 return 0; /* already the same font... */
2601 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2605 * User asked to set font; we are guaranteed that
2606 * a) width and height are in range 1..32
2607 * b) charcount does not exceed 512
2608 * but lets not assume that, since someone might someday want to use larger
2609 * fonts. And charcount of 512 is small for unicode support.
2611 * However, user space gives the font in 32 rows , regardless of
2612 * actual font height. So a new API is needed if support for larger fonts
2613 * is ever implemented.
2616 static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2617 unsigned int flags)
2619 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2620 unsigned charcount = font->charcount;
2621 int w = font->width;
2622 int h = font->height;
2623 int size;
2624 int i, csum;
2625 u8 *new_data, *data = font->data;
2626 int pitch = (font->width+7) >> 3;
2628 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2629 * If not this check should be changed to charcount < 256 */
2630 if (charcount != 256 && charcount != 512)
2631 return -EINVAL;
2633 /* Make sure drawing engine can handle the font */
2634 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2635 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2636 return -EINVAL;
2638 /* Make sure driver can handle the font length */
2639 if (fbcon_invalid_charcount(info, charcount))
2640 return -EINVAL;
2642 size = h * pitch * charcount;
2644 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2646 if (!new_data)
2647 return -ENOMEM;
2649 new_data += FONT_EXTRA_WORDS * sizeof(int);
2650 FNTSIZE(new_data) = size;
2651 FNTCHARCNT(new_data) = charcount;
2652 REFCOUNT(new_data) = 0; /* usage counter */
2653 for (i=0; i< charcount; i++) {
2654 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2657 /* Since linux has a nice crc32 function use it for counting font
2658 * checksums. */
2659 csum = crc32(0, new_data, size);
2661 FNTSUM(new_data) = csum;
2662 /* Check if the same font is on some other console already */
2663 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2664 struct vc_data *tmp = vc_cons[i].d;
2666 if (fb_display[i].userfont &&
2667 fb_display[i].fontdata &&
2668 FNTSUM(fb_display[i].fontdata) == csum &&
2669 FNTSIZE(fb_display[i].fontdata) == size &&
2670 tmp->vc_font.width == w &&
2671 !memcmp(fb_display[i].fontdata, new_data, size)) {
2672 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2673 new_data = (u8 *)fb_display[i].fontdata;
2674 break;
2677 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2680 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2682 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2683 const struct font_desc *f;
2685 if (!name)
2686 f = get_default_font(info->var.xres, info->var.yres,
2687 info->pixmap.blit_x, info->pixmap.blit_y);
2688 else if (!(f = find_font(name)))
2689 return -ENOENT;
2691 font->width = f->width;
2692 font->height = f->height;
2693 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2696 static u16 palette_red[16];
2697 static u16 palette_green[16];
2698 static u16 palette_blue[16];
2700 static struct fb_cmap palette_cmap = {
2701 0, 16, palette_red, palette_green, palette_blue, NULL
2704 static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
2706 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2707 int i, j, k, depth;
2708 u8 val;
2710 if (fbcon_is_inactive(vc, info))
2711 return;
2713 if (!con_is_visible(vc))
2714 return;
2716 depth = fb_get_color_depth(&info->var, &info->fix);
2717 if (depth > 3) {
2718 for (i = j = 0; i < 16; i++) {
2719 k = table[i];
2720 val = vc->vc_palette[j++];
2721 palette_red[k] = (val << 8) | val;
2722 val = vc->vc_palette[j++];
2723 palette_green[k] = (val << 8) | val;
2724 val = vc->vc_palette[j++];
2725 palette_blue[k] = (val << 8) | val;
2727 palette_cmap.len = 16;
2728 palette_cmap.start = 0;
2730 * If framebuffer is capable of less than 16 colors,
2731 * use default palette of fbcon.
2733 } else
2734 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2736 fb_set_cmap(&palette_cmap, info);
2739 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2741 unsigned long p;
2742 int line;
2744 if (vc->vc_num != fg_console || !softback_lines)
2745 return (u16 *) (vc->vc_origin + offset);
2746 line = offset / vc->vc_size_row;
2747 if (line >= softback_lines)
2748 return (u16 *) (vc->vc_origin + offset -
2749 softback_lines * vc->vc_size_row);
2750 p = softback_curr + offset;
2751 if (p >= softback_end)
2752 p += softback_buf - softback_end;
2753 return (u16 *) p;
2756 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2757 int *px, int *py)
2759 unsigned long ret;
2760 int x, y;
2762 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2763 unsigned long offset = (pos - vc->vc_origin) / 2;
2765 x = offset % vc->vc_cols;
2766 y = offset / vc->vc_cols;
2767 if (vc->vc_num == fg_console)
2768 y += softback_lines;
2769 ret = pos + (vc->vc_cols - x) * 2;
2770 } else if (vc->vc_num == fg_console && softback_lines) {
2771 unsigned long offset = pos - softback_curr;
2773 if (pos < softback_curr)
2774 offset += softback_end - softback_buf;
2775 offset /= 2;
2776 x = offset % vc->vc_cols;
2777 y = offset / vc->vc_cols;
2778 ret = pos + (vc->vc_cols - x) * 2;
2779 if (ret == softback_end)
2780 ret = softback_buf;
2781 if (ret == softback_in)
2782 ret = vc->vc_origin;
2783 } else {
2784 /* Should not happen */
2785 x = y = 0;
2786 ret = vc->vc_origin;
2788 if (px)
2789 *px = x;
2790 if (py)
2791 *py = y;
2792 return ret;
2795 /* As we might be inside of softback, we may work with non-contiguous buffer,
2796 that's why we have to use a separate routine. */
2797 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2799 while (cnt--) {
2800 u16 a = scr_readw(p);
2801 if (!vc->vc_can_do_color)
2802 a ^= 0x0800;
2803 else if (vc->vc_hi_font_mask == 0x100)
2804 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2805 (((a) & 0x0e00) << 4);
2806 else
2807 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2808 (((a) & 0x0700) << 4);
2809 scr_writew(a, p++);
2810 if (p == (u16 *) softback_end)
2811 p = (u16 *) softback_buf;
2812 if (p == (u16 *) softback_in)
2813 p = (u16 *) vc->vc_origin;
2817 static void fbcon_scrolldelta(struct vc_data *vc, int lines)
2819 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2820 struct fbcon_ops *ops = info->fbcon_par;
2821 struct display *disp = &fb_display[fg_console];
2822 int offset, limit, scrollback_old;
2824 if (softback_top) {
2825 if (vc->vc_num != fg_console)
2826 return;
2827 if (vc->vc_mode != KD_TEXT || !lines)
2828 return;
2829 if (logo_shown >= 0) {
2830 struct vc_data *conp2 = vc_cons[logo_shown].d;
2832 if (conp2->vc_top == logo_lines
2833 && conp2->vc_bottom == conp2->vc_rows)
2834 conp2->vc_top = 0;
2835 if (logo_shown == vc->vc_num) {
2836 unsigned long p, q;
2837 int i;
2839 p = softback_in;
2840 q = vc->vc_origin +
2841 logo_lines * vc->vc_size_row;
2842 for (i = 0; i < logo_lines; i++) {
2843 if (p == softback_top)
2844 break;
2845 if (p == softback_buf)
2846 p = softback_end;
2847 p -= vc->vc_size_row;
2848 q -= vc->vc_size_row;
2849 scr_memcpyw((u16 *) q, (u16 *) p,
2850 vc->vc_size_row);
2852 softback_in = softback_curr = p;
2853 update_region(vc, vc->vc_origin,
2854 logo_lines * vc->vc_cols);
2856 logo_shown = FBCON_LOGO_CANSHOW;
2858 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2859 fbcon_redraw_softback(vc, disp, lines);
2860 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2861 return;
2864 if (!scrollback_phys_max)
2865 return;
2867 scrollback_old = scrollback_current;
2868 scrollback_current -= lines;
2869 if (scrollback_current < 0)
2870 scrollback_current = 0;
2871 else if (scrollback_current > scrollback_max)
2872 scrollback_current = scrollback_max;
2873 if (scrollback_current == scrollback_old)
2874 return;
2876 if (fbcon_is_inactive(vc, info))
2877 return;
2879 fbcon_cursor(vc, CM_ERASE);
2881 offset = disp->yscroll - scrollback_current;
2882 limit = disp->vrows;
2883 switch (disp->scrollmode) {
2884 case SCROLL_WRAP_MOVE:
2885 info->var.vmode |= FB_VMODE_YWRAP;
2886 break;
2887 case SCROLL_PAN_MOVE:
2888 case SCROLL_PAN_REDRAW:
2889 limit -= vc->vc_rows;
2890 info->var.vmode &= ~FB_VMODE_YWRAP;
2891 break;
2893 if (offset < 0)
2894 offset += limit;
2895 else if (offset >= limit)
2896 offset -= limit;
2898 ops->var.xoffset = 0;
2899 ops->var.yoffset = offset * vc->vc_font.height;
2900 ops->update_start(info);
2902 if (!scrollback_current)
2903 fbcon_cursor(vc, CM_DRAW);
2906 static int fbcon_set_origin(struct vc_data *vc)
2908 if (softback_lines)
2909 fbcon_scrolldelta(vc, softback_lines);
2910 return 0;
2913 static void fbcon_suspended(struct fb_info *info)
2915 struct vc_data *vc = NULL;
2916 struct fbcon_ops *ops = info->fbcon_par;
2918 if (!ops || ops->currcon < 0)
2919 return;
2920 vc = vc_cons[ops->currcon].d;
2922 /* Clear cursor, restore saved data */
2923 fbcon_cursor(vc, CM_ERASE);
2926 static void fbcon_resumed(struct fb_info *info)
2928 struct vc_data *vc;
2929 struct fbcon_ops *ops = info->fbcon_par;
2931 if (!ops || ops->currcon < 0)
2932 return;
2933 vc = vc_cons[ops->currcon].d;
2935 update_screen(vc);
2938 static void fbcon_modechanged(struct fb_info *info)
2940 struct fbcon_ops *ops = info->fbcon_par;
2941 struct vc_data *vc;
2942 struct display *p;
2943 int rows, cols;
2945 if (!ops || ops->currcon < 0)
2946 return;
2947 vc = vc_cons[ops->currcon].d;
2948 if (vc->vc_mode != KD_TEXT ||
2949 registered_fb[con2fb_map[ops->currcon]] != info)
2950 return;
2952 p = &fb_display[vc->vc_num];
2953 set_blitting_type(vc, info);
2955 if (con_is_visible(vc)) {
2956 var_to_display(p, &info->var, info);
2957 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2958 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2959 cols /= vc->vc_font.width;
2960 rows /= vc->vc_font.height;
2961 vc_resize(vc, cols, rows);
2962 updatescrollmode(p, info, vc);
2963 scrollback_max = 0;
2964 scrollback_current = 0;
2966 if (!fbcon_is_inactive(vc, info)) {
2967 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2968 ops->update_start(info);
2971 fbcon_set_palette(vc, color_table);
2972 update_screen(vc);
2973 if (softback_buf)
2974 fbcon_update_softback(vc);
2978 static void fbcon_set_all_vcs(struct fb_info *info)
2980 struct fbcon_ops *ops = info->fbcon_par;
2981 struct vc_data *vc;
2982 struct display *p;
2983 int i, rows, cols, fg = -1;
2985 if (!ops || ops->currcon < 0)
2986 return;
2988 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2989 vc = vc_cons[i].d;
2990 if (!vc || vc->vc_mode != KD_TEXT ||
2991 registered_fb[con2fb_map[i]] != info)
2992 continue;
2994 if (con_is_visible(vc)) {
2995 fg = i;
2996 continue;
2999 p = &fb_display[vc->vc_num];
3000 set_blitting_type(vc, info);
3001 var_to_display(p, &info->var, info);
3002 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3003 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3004 cols /= vc->vc_font.width;
3005 rows /= vc->vc_font.height;
3006 vc_resize(vc, cols, rows);
3009 if (fg != -1)
3010 fbcon_modechanged(info);
3013 static int fbcon_mode_deleted(struct fb_info *info,
3014 struct fb_videomode *mode)
3016 struct fb_info *fb_info;
3017 struct display *p;
3018 int i, j, found = 0;
3020 /* before deletion, ensure that mode is not in use */
3021 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3022 j = con2fb_map[i];
3023 if (j == -1)
3024 continue;
3025 fb_info = registered_fb[j];
3026 if (fb_info != info)
3027 continue;
3028 p = &fb_display[i];
3029 if (!p || !p->mode)
3030 continue;
3031 if (fb_mode_is_equal(p->mode, mode)) {
3032 found = 1;
3033 break;
3036 return found;
3039 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
3040 static int fbcon_unbind(void)
3042 int ret;
3044 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3045 fbcon_is_default);
3047 if (!ret)
3048 fbcon_has_console_bind = 0;
3050 return ret;
3052 #else
3053 static inline int fbcon_unbind(void)
3055 return -EINVAL;
3057 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3059 /* called with console_lock held */
3060 static int fbcon_fb_unbind(int idx)
3062 int i, new_idx = -1, ret = 0;
3064 WARN_CONSOLE_UNLOCKED();
3066 if (!fbcon_has_console_bind)
3067 return 0;
3069 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3070 if (con2fb_map[i] != idx &&
3071 con2fb_map[i] != -1) {
3072 new_idx = con2fb_map[i];
3073 break;
3077 if (new_idx != -1) {
3078 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3079 if (con2fb_map[i] == idx)
3080 set_con2fb_map(i, new_idx, 0);
3082 } else {
3083 struct fb_info *info = registered_fb[idx];
3085 /* This is sort of like set_con2fb_map, except it maps
3086 * the consoles to no device and then releases the
3087 * oldinfo to free memory and cancel the cursor blink
3088 * timer. I can imagine this just becoming part of
3089 * set_con2fb_map where new_idx is -1
3091 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3092 if (con2fb_map[i] == idx) {
3093 con2fb_map[i] = -1;
3094 if (!search_fb_in_map(idx)) {
3095 ret = con2fb_release_oldinfo(vc_cons[i].d,
3096 info, NULL, i,
3097 idx, 0);
3098 if (ret) {
3099 con2fb_map[i] = idx;
3100 return ret;
3105 ret = fbcon_unbind();
3108 return ret;
3111 /* called with console_lock held */
3112 static int fbcon_fb_unregistered(struct fb_info *info)
3114 int i, idx;
3116 WARN_CONSOLE_UNLOCKED();
3118 if (deferred_takeover)
3119 return 0;
3121 idx = info->node;
3122 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3123 if (con2fb_map[i] == idx)
3124 con2fb_map[i] = -1;
3127 if (idx == info_idx) {
3128 info_idx = -1;
3130 for_each_registered_fb(i) {
3131 info_idx = i;
3132 break;
3136 if (info_idx != -1) {
3137 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3138 if (con2fb_map[i] == -1)
3139 con2fb_map[i] = info_idx;
3143 if (primary_device == idx)
3144 primary_device = -1;
3146 if (!num_registered_fb)
3147 do_unregister_con_driver(&fb_con);
3149 return 0;
3152 /* called with console_lock held */
3153 static void fbcon_remap_all(int idx)
3155 int i;
3157 WARN_CONSOLE_UNLOCKED();
3159 if (deferred_takeover) {
3160 for (i = first_fb_vc; i <= last_fb_vc; i++)
3161 con2fb_map_boot[i] = idx;
3162 fbcon_map_override();
3163 return;
3166 for (i = first_fb_vc; i <= last_fb_vc; i++)
3167 set_con2fb_map(i, idx, 0);
3169 if (con_is_bound(&fb_con)) {
3170 printk(KERN_INFO "fbcon: Remapping primary device, "
3171 "fb%i, to tty %i-%i\n", idx,
3172 first_fb_vc + 1, last_fb_vc + 1);
3173 info_idx = idx;
3177 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3178 static void fbcon_select_primary(struct fb_info *info)
3180 if (!map_override && primary_device == -1 &&
3181 fb_is_primary_device(info)) {
3182 int i;
3184 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3185 info->fix.id, info->node);
3186 primary_device = info->node;
3188 for (i = first_fb_vc; i <= last_fb_vc; i++)
3189 con2fb_map_boot[i] = primary_device;
3191 if (con_is_bound(&fb_con)) {
3192 printk(KERN_INFO "fbcon: Remapping primary device, "
3193 "fb%i, to tty %i-%i\n", info->node,
3194 first_fb_vc + 1, last_fb_vc + 1);
3195 info_idx = primary_device;
3200 #else
3201 static inline void fbcon_select_primary(struct fb_info *info)
3203 return;
3205 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3207 /* called with console_lock held */
3208 static int fbcon_fb_registered(struct fb_info *info)
3210 int ret = 0, i, idx;
3212 WARN_CONSOLE_UNLOCKED();
3214 idx = info->node;
3215 fbcon_select_primary(info);
3217 if (deferred_takeover) {
3218 pr_info("fbcon: Deferring console take-over\n");
3219 return 0;
3222 if (info_idx == -1) {
3223 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3224 if (con2fb_map_boot[i] == idx) {
3225 info_idx = idx;
3226 break;
3230 if (info_idx != -1)
3231 ret = do_fbcon_takeover(1);
3232 } else {
3233 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3234 if (con2fb_map_boot[i] == idx)
3235 set_con2fb_map(i, idx, 0);
3239 return ret;
3242 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3244 struct fbcon_ops *ops = info->fbcon_par;
3245 struct vc_data *vc;
3247 if (!ops || ops->currcon < 0)
3248 return;
3250 vc = vc_cons[ops->currcon].d;
3251 if (vc->vc_mode != KD_TEXT ||
3252 registered_fb[con2fb_map[ops->currcon]] != info)
3253 return;
3255 if (con_is_visible(vc)) {
3256 if (blank)
3257 do_blank_screen(0);
3258 else
3259 do_unblank_screen(0);
3261 ops->blank_state = blank;
3264 static void fbcon_new_modelist(struct fb_info *info)
3266 int i;
3267 struct vc_data *vc;
3268 struct fb_var_screeninfo var;
3269 const struct fb_videomode *mode;
3271 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3272 if (registered_fb[con2fb_map[i]] != info)
3273 continue;
3274 if (!fb_display[i].mode)
3275 continue;
3276 vc = vc_cons[i].d;
3277 display_to_var(&var, &fb_display[i]);
3278 mode = fb_find_nearest_mode(fb_display[i].mode,
3279 &info->modelist);
3280 fb_videomode_to_var(&var, mode);
3281 fbcon_set_disp(info, &var, vc->vc_num);
3285 static void fbcon_get_requirement(struct fb_info *info,
3286 struct fb_blit_caps *caps)
3288 struct vc_data *vc;
3289 struct display *p;
3291 if (caps->flags) {
3292 int i, charcnt;
3294 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3295 vc = vc_cons[i].d;
3296 if (vc && vc->vc_mode == KD_TEXT &&
3297 info->node == con2fb_map[i]) {
3298 p = &fb_display[i];
3299 caps->x |= 1 << (vc->vc_font.width - 1);
3300 caps->y |= 1 << (vc->vc_font.height - 1);
3301 charcnt = (p->userfont) ?
3302 FNTCHARCNT(p->fontdata) : 256;
3303 if (caps->len < charcnt)
3304 caps->len = charcnt;
3307 } else {
3308 vc = vc_cons[fg_console].d;
3310 if (vc && vc->vc_mode == KD_TEXT &&
3311 info->node == con2fb_map[fg_console]) {
3312 p = &fb_display[fg_console];
3313 caps->x = 1 << (vc->vc_font.width - 1);
3314 caps->y = 1 << (vc->vc_font.height - 1);
3315 caps->len = (p->userfont) ?
3316 FNTCHARCNT(p->fontdata) : 256;
3321 static int fbcon_event_notify(struct notifier_block *self,
3322 unsigned long action, void *data)
3324 struct fb_event *event = data;
3325 struct fb_info *info = event->info;
3326 struct fb_videomode *mode;
3327 struct fb_con2fbmap *con2fb;
3328 struct fb_blit_caps *caps;
3329 int idx, ret = 0;
3332 * ignore all events except driver registration and deregistration
3333 * if fbcon is not active
3335 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3336 action == FB_EVENT_FB_UNREGISTERED))
3337 goto done;
3339 switch(action) {
3340 case FB_EVENT_SUSPEND:
3341 fbcon_suspended(info);
3342 break;
3343 case FB_EVENT_RESUME:
3344 fbcon_resumed(info);
3345 break;
3346 case FB_EVENT_MODE_CHANGE:
3347 fbcon_modechanged(info);
3348 break;
3349 case FB_EVENT_MODE_CHANGE_ALL:
3350 fbcon_set_all_vcs(info);
3351 break;
3352 case FB_EVENT_MODE_DELETE:
3353 mode = event->data;
3354 ret = fbcon_mode_deleted(info, mode);
3355 break;
3356 case FB_EVENT_FB_UNBIND:
3357 idx = info->node;
3358 ret = fbcon_fb_unbind(idx);
3359 break;
3360 case FB_EVENT_FB_REGISTERED:
3361 ret = fbcon_fb_registered(info);
3362 break;
3363 case FB_EVENT_FB_UNREGISTERED:
3364 ret = fbcon_fb_unregistered(info);
3365 break;
3366 case FB_EVENT_SET_CONSOLE_MAP:
3367 /* called with console lock held */
3368 con2fb = event->data;
3369 ret = set_con2fb_map(con2fb->console - 1,
3370 con2fb->framebuffer, 1);
3371 break;
3372 case FB_EVENT_GET_CONSOLE_MAP:
3373 con2fb = event->data;
3374 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3375 break;
3376 case FB_EVENT_BLANK:
3377 fbcon_fb_blanked(info, *(int *)event->data);
3378 break;
3379 case FB_EVENT_NEW_MODELIST:
3380 fbcon_new_modelist(info);
3381 break;
3382 case FB_EVENT_GET_REQ:
3383 caps = event->data;
3384 fbcon_get_requirement(info, caps);
3385 break;
3386 case FB_EVENT_REMAP_ALL_CONSOLE:
3387 idx = info->node;
3388 fbcon_remap_all(idx);
3389 break;
3391 done:
3392 return ret;
3396 * The console `switch' structure for the frame buffer based console
3399 static const struct consw fb_con = {
3400 .owner = THIS_MODULE,
3401 .con_startup = fbcon_startup,
3402 .con_init = fbcon_init,
3403 .con_deinit = fbcon_deinit,
3404 .con_clear = fbcon_clear,
3405 .con_putc = fbcon_putc,
3406 .con_putcs = fbcon_putcs,
3407 .con_cursor = fbcon_cursor,
3408 .con_scroll = fbcon_scroll,
3409 .con_switch = fbcon_switch,
3410 .con_blank = fbcon_blank,
3411 .con_font_set = fbcon_set_font,
3412 .con_font_get = fbcon_get_font,
3413 .con_font_default = fbcon_set_def_font,
3414 .con_font_copy = fbcon_copy_font,
3415 .con_set_palette = fbcon_set_palette,
3416 .con_scrolldelta = fbcon_scrolldelta,
3417 .con_set_origin = fbcon_set_origin,
3418 .con_invert_region = fbcon_invert_region,
3419 .con_screen_pos = fbcon_screen_pos,
3420 .con_getxy = fbcon_getxy,
3421 .con_resize = fbcon_resize,
3422 .con_debug_enter = fbcon_debug_enter,
3423 .con_debug_leave = fbcon_debug_leave,
3426 static struct notifier_block fbcon_event_notifier = {
3427 .notifier_call = fbcon_event_notify,
3430 static ssize_t store_rotate(struct device *device,
3431 struct device_attribute *attr, const char *buf,
3432 size_t count)
3434 struct fb_info *info;
3435 int rotate, idx;
3436 char **last = NULL;
3438 if (fbcon_has_exited)
3439 return count;
3441 console_lock();
3442 idx = con2fb_map[fg_console];
3444 if (idx == -1 || registered_fb[idx] == NULL)
3445 goto err;
3447 info = registered_fb[idx];
3448 rotate = simple_strtoul(buf, last, 0);
3449 fbcon_rotate(info, rotate);
3450 err:
3451 console_unlock();
3452 return count;
3455 static ssize_t store_rotate_all(struct device *device,
3456 struct device_attribute *attr,const char *buf,
3457 size_t count)
3459 struct fb_info *info;
3460 int rotate, idx;
3461 char **last = NULL;
3463 if (fbcon_has_exited)
3464 return count;
3466 console_lock();
3467 idx = con2fb_map[fg_console];
3469 if (idx == -1 || registered_fb[idx] == NULL)
3470 goto err;
3472 info = registered_fb[idx];
3473 rotate = simple_strtoul(buf, last, 0);
3474 fbcon_rotate_all(info, rotate);
3475 err:
3476 console_unlock();
3477 return count;
3480 static ssize_t show_rotate(struct device *device,
3481 struct device_attribute *attr,char *buf)
3483 struct fb_info *info;
3484 int rotate = 0, idx;
3486 if (fbcon_has_exited)
3487 return 0;
3489 console_lock();
3490 idx = con2fb_map[fg_console];
3492 if (idx == -1 || registered_fb[idx] == NULL)
3493 goto err;
3495 info = registered_fb[idx];
3496 rotate = fbcon_get_rotate(info);
3497 err:
3498 console_unlock();
3499 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3502 static ssize_t show_cursor_blink(struct device *device,
3503 struct device_attribute *attr, char *buf)
3505 struct fb_info *info;
3506 struct fbcon_ops *ops;
3507 int idx, blink = -1;
3509 if (fbcon_has_exited)
3510 return 0;
3512 console_lock();
3513 idx = con2fb_map[fg_console];
3515 if (idx == -1 || registered_fb[idx] == NULL)
3516 goto err;
3518 info = registered_fb[idx];
3519 ops = info->fbcon_par;
3521 if (!ops)
3522 goto err;
3524 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3525 err:
3526 console_unlock();
3527 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3530 static ssize_t store_cursor_blink(struct device *device,
3531 struct device_attribute *attr,
3532 const char *buf, size_t count)
3534 struct fb_info *info;
3535 int blink, idx;
3536 char **last = NULL;
3538 if (fbcon_has_exited)
3539 return count;
3541 console_lock();
3542 idx = con2fb_map[fg_console];
3544 if (idx == -1 || registered_fb[idx] == NULL)
3545 goto err;
3547 info = registered_fb[idx];
3549 if (!info->fbcon_par)
3550 goto err;
3552 blink = simple_strtoul(buf, last, 0);
3554 if (blink) {
3555 fbcon_cursor_noblink = 0;
3556 fbcon_add_cursor_timer(info);
3557 } else {
3558 fbcon_cursor_noblink = 1;
3559 fbcon_del_cursor_timer(info);
3562 err:
3563 console_unlock();
3564 return count;
3567 static struct device_attribute device_attrs[] = {
3568 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3569 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3570 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3571 store_cursor_blink),
3574 static int fbcon_init_device(void)
3576 int i, error = 0;
3578 fbcon_has_sysfs = 1;
3580 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3581 error = device_create_file(fbcon_device, &device_attrs[i]);
3583 if (error)
3584 break;
3587 if (error) {
3588 while (--i >= 0)
3589 device_remove_file(fbcon_device, &device_attrs[i]);
3591 fbcon_has_sysfs = 0;
3594 return 0;
3597 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3598 static void fbcon_register_existing_fbs(struct work_struct *work)
3600 int i;
3602 console_lock();
3604 for_each_registered_fb(i)
3605 fbcon_fb_registered(registered_fb[i]);
3607 console_unlock();
3610 static struct notifier_block fbcon_output_nb;
3611 static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
3613 static int fbcon_output_notifier(struct notifier_block *nb,
3614 unsigned long action, void *data)
3616 WARN_CONSOLE_UNLOCKED();
3618 pr_info("fbcon: Taking over console\n");
3620 dummycon_unregister_output_notifier(&fbcon_output_nb);
3621 deferred_takeover = false;
3622 logo_shown = FBCON_LOGO_DONTSHOW;
3624 /* We may get called in atomic context */
3625 schedule_work(&fbcon_deferred_takeover_work);
3627 return NOTIFY_OK;
3629 #endif
3631 static void fbcon_start(void)
3633 WARN_CONSOLE_UNLOCKED();
3635 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3636 if (conswitchp != &dummy_con)
3637 deferred_takeover = false;
3639 if (deferred_takeover) {
3640 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3641 dummycon_register_output_notifier(&fbcon_output_nb);
3642 return;
3644 #endif
3646 if (num_registered_fb) {
3647 int i;
3649 for_each_registered_fb(i) {
3650 info_idx = i;
3651 break;
3654 do_fbcon_takeover(0);
3658 static void fbcon_exit(void)
3660 struct fb_info *info;
3661 int i, j, mapped;
3663 if (fbcon_has_exited)
3664 return;
3666 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3667 if (deferred_takeover) {
3668 dummycon_unregister_output_notifier(&fbcon_output_nb);
3669 deferred_takeover = false;
3671 #endif
3673 kfree((void *)softback_buf);
3674 softback_buf = 0UL;
3676 for_each_registered_fb(i) {
3677 int pending = 0;
3679 mapped = 0;
3680 info = registered_fb[i];
3682 if (info->queue.func)
3683 pending = cancel_work_sync(&info->queue);
3684 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3685 "no"));
3687 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3688 if (con2fb_map[j] == i) {
3689 mapped = 1;
3690 break;
3694 if (mapped) {
3695 if (info->fbops->fb_release)
3696 info->fbops->fb_release(info, 0);
3697 module_put(info->fbops->owner);
3699 if (info->fbcon_par) {
3700 struct fbcon_ops *ops = info->fbcon_par;
3702 fbcon_del_cursor_timer(info);
3703 kfree(ops->cursor_src);
3704 kfree(ops->cursor_state.mask);
3705 kfree(info->fbcon_par);
3706 info->fbcon_par = NULL;
3709 if (info->queue.func == fb_flashcursor)
3710 info->queue.func = NULL;
3714 fbcon_has_exited = 1;
3717 void __init fb_console_init(void)
3719 int i;
3721 console_lock();
3722 fb_register_client(&fbcon_event_notifier);
3723 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3724 "fbcon");
3726 if (IS_ERR(fbcon_device)) {
3727 printk(KERN_WARNING "Unable to create device "
3728 "for fbcon; errno = %ld\n",
3729 PTR_ERR(fbcon_device));
3730 fbcon_device = NULL;
3731 } else
3732 fbcon_init_device();
3734 for (i = 0; i < MAX_NR_CONSOLES; i++)
3735 con2fb_map[i] = -1;
3737 fbcon_start();
3738 console_unlock();
3741 #ifdef MODULE
3743 static void __exit fbcon_deinit_device(void)
3745 int i;
3747 if (fbcon_has_sysfs) {
3748 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3749 device_remove_file(fbcon_device, &device_attrs[i]);
3751 fbcon_has_sysfs = 0;
3755 void __exit fb_console_exit(void)
3757 console_lock();
3758 fb_unregister_client(&fbcon_event_notifier);
3759 fbcon_deinit_device();
3760 device_destroy(fb_class, MKDEV(0, 0));
3761 fbcon_exit();
3762 do_unregister_con_driver(&fb_con);
3763 console_unlock();
3765 #endif