fbcon: Protect free_irq() by MACH_IS_ATARI check
[linux-2.6/x86.git] / drivers / video / console / fbcon.c
blob4bcff81b50e03afa91f6dbf8eeef0784a2f12f12
1 /*
2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
4 * Copyright (C) 1995 Geert Uytterhoeven
7 * This file is based on the original Amiga console driver (amicon.c):
9 * Copyright (C) 1993 Hamish Macdonald
10 * Greg Harp
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
14 * Geert Uytterhoeven
15 * Jes Sorensen (jds@kom.auc.dk)
16 * Martin Apel
18 * and on the original Atari console driver (atacon.c):
20 * Copyright (C) 1993 Bjoern Brauel
21 * Roman Hodek
23 * with work by Guenther Kelleter
24 * Martin Schaller
25 * Andreas Schwab
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
32 * Random hacking by Martin Mares <mj@ucw.cz>
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
40 * Currently the following organizations are supported:
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
46 * o mfb Monochrome
47 * o vga VGA characters/attributes
49 * To do:
51 * - Implement 16 plane mode (iplan2p16)
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
56 * more details.
59 #undef FBCONDEBUG
61 #include <linux/module.h>
62 #include <linux/types.h>
63 #include <linux/fs.h>
64 #include <linux/kernel.h>
65 #include <linux/delay.h> /* MSch: for IRQ probe */
66 #include <linux/console.h>
67 #include <linux/string.h>
68 #include <linux/kd.h>
69 #include <linux/slab.h>
70 #include <linux/fb.h>
71 #include <linux/vt_kern.h>
72 #include <linux/selection.h>
73 #include <linux/font.h>
74 #include <linux/smp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/crc32.h> /* For counting font checksums */
78 #include <asm/fb.h>
79 #include <asm/irq.h>
80 #include <asm/system.h>
81 #ifdef CONFIG_ATARI
82 #include <asm/atariints.h>
83 #endif
84 #if defined(__mc68000__)
85 #include <asm/machdep.h>
86 #include <asm/setup.h>
87 #endif
89 #include "fbcon.h"
91 #ifdef FBCONDEBUG
92 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
93 #else
94 # define DPRINTK(fmt, args...)
95 #endif
97 enum {
98 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
99 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
100 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
103 static struct display fb_display[MAX_NR_CONSOLES];
105 static signed char con2fb_map[MAX_NR_CONSOLES];
106 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
108 static int logo_lines;
109 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
110 enums. */
111 static int logo_shown = FBCON_LOGO_CANSHOW;
112 /* Software scrollback */
113 static int fbcon_softback_size = 32768;
114 static unsigned long softback_buf, softback_curr;
115 static unsigned long softback_in;
116 static unsigned long softback_top, softback_end;
117 static int softback_lines;
118 /* console mappings */
119 static int first_fb_vc;
120 static int last_fb_vc = MAX_NR_CONSOLES - 1;
121 static int fbcon_is_default = 1;
122 static int fbcon_has_exited;
123 static int primary_device = -1;
125 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
126 static int map_override;
128 static inline void fbcon_map_override(void)
130 map_override = 1;
132 #else
133 static inline void fbcon_map_override(void)
136 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
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;
146 static int fbcon_has_sysfs;
148 static const struct consw fb_con;
150 #define CM_SOFTBACK (8)
152 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
154 static int fbcon_set_origin(struct vc_data *);
156 #define CURSOR_DRAW_DELAY (1)
158 /* # VBL ints between cursor state changes */
159 #define ATARI_CURSOR_BLINK_RATE (42)
161 static int vbl_cursor_cnt;
162 static int fbcon_cursor_noblink;
164 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
167 * Interface used by the world
170 static const char *fbcon_startup(void);
171 static void fbcon_init(struct vc_data *vc, int init);
172 static void fbcon_deinit(struct vc_data *vc);
173 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
174 int width);
175 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
176 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
177 int count, int ypos, int xpos);
178 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
179 static void fbcon_cursor(struct vc_data *vc, int mode);
180 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
181 int count);
182 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
183 int height, int width);
184 static int fbcon_switch(struct vc_data *vc);
185 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
186 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
187 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
190 * Internal routines
192 static __inline__ void ywrap_up(struct vc_data *vc, int count);
193 static __inline__ void ywrap_down(struct vc_data *vc, int count);
194 static __inline__ void ypan_up(struct vc_data *vc, int count);
195 static __inline__ void ypan_down(struct vc_data *vc, int count);
196 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
197 int dy, int dx, int height, int width, u_int y_break);
198 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
199 int unit);
200 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
201 int line, int count, int dy);
202 static void fbcon_modechanged(struct fb_info *info);
203 static void fbcon_set_all_vcs(struct fb_info *info);
204 static void fbcon_start(void);
205 static void fbcon_exit(void);
206 static struct device *fbcon_device;
208 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
209 static inline void fbcon_set_rotation(struct fb_info *info)
211 struct fbcon_ops *ops = info->fbcon_par;
213 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
214 ops->p->con_rotate < 4)
215 ops->rotate = ops->p->con_rotate;
216 else
217 ops->rotate = 0;
220 static void fbcon_rotate(struct fb_info *info, u32 rotate)
222 struct fbcon_ops *ops= info->fbcon_par;
223 struct fb_info *fb_info;
225 if (!ops || ops->currcon == -1)
226 return;
228 fb_info = registered_fb[con2fb_map[ops->currcon]];
230 if (info == fb_info) {
231 struct display *p = &fb_display[ops->currcon];
233 if (rotate < 4)
234 p->con_rotate = rotate;
235 else
236 p->con_rotate = 0;
238 fbcon_modechanged(info);
242 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
244 struct fbcon_ops *ops = info->fbcon_par;
245 struct vc_data *vc;
246 struct display *p;
247 int i;
249 if (!ops || ops->currcon < 0 || rotate > 3)
250 return;
252 for (i = first_fb_vc; i <= last_fb_vc; i++) {
253 vc = vc_cons[i].d;
254 if (!vc || vc->vc_mode != KD_TEXT ||
255 registered_fb[con2fb_map[i]] != info)
256 continue;
258 p = &fb_display[vc->vc_num];
259 p->con_rotate = rotate;
262 fbcon_set_all_vcs(info);
264 #else
265 static inline void fbcon_set_rotation(struct fb_info *info)
267 struct fbcon_ops *ops = info->fbcon_par;
269 ops->rotate = FB_ROTATE_UR;
272 static void fbcon_rotate(struct fb_info *info, u32 rotate)
274 return;
277 static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
279 return;
281 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
283 static int fbcon_get_rotate(struct fb_info *info)
285 struct fbcon_ops *ops = info->fbcon_par;
287 return (ops) ? ops->rotate : 0;
290 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
292 struct fbcon_ops *ops = info->fbcon_par;
294 return (info->state != FBINFO_STATE_RUNNING ||
295 vc->vc_mode != KD_TEXT || ops->graphics);
298 static inline int get_color(struct vc_data *vc, struct fb_info *info,
299 u16 c, int is_fg)
301 int depth = fb_get_color_depth(&info->var, &info->fix);
302 int color = 0;
304 if (console_blanked) {
305 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
307 c = vc->vc_video_erase_char & charmask;
310 if (depth != 1)
311 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
312 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
314 switch (depth) {
315 case 1:
317 int col = mono_col(info);
318 /* 0 or 1 */
319 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
320 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
322 if (console_blanked)
323 fg = bg;
325 color = (is_fg) ? fg : bg;
326 break;
328 case 2:
330 * Scale down 16-colors to 4 colors. Default 4-color palette
331 * is grayscale. However, simply dividing the values by 4
332 * will not work, as colors 1, 2 and 3 will be scaled-down
333 * to zero rendering them invisible. So empirically convert
334 * colors to a sane 4-level grayscale.
336 switch (color) {
337 case 0:
338 color = 0; /* black */
339 break;
340 case 1 ... 6:
341 color = 2; /* white */
342 break;
343 case 7 ... 8:
344 color = 1; /* gray */
345 break;
346 default:
347 color = 3; /* intense white */
348 break;
350 break;
351 case 3:
353 * Last 8 entries of default 16-color palette is a more intense
354 * version of the first 8 (i.e., same chrominance, different
355 * luminance).
357 color &= 7;
358 break;
362 return color;
365 static void fbcon_update_softback(struct vc_data *vc)
367 int l = fbcon_softback_size / vc->vc_size_row;
369 if (l > 5)
370 softback_end = softback_buf + l * vc->vc_size_row;
371 else
372 /* Smaller scrollback makes no sense, and 0 would screw
373 the operation totally */
374 softback_top = 0;
377 static void fb_flashcursor(struct work_struct *work)
379 struct fb_info *info = container_of(work, struct fb_info, queue);
380 struct fbcon_ops *ops = info->fbcon_par;
381 struct display *p;
382 struct vc_data *vc = NULL;
383 int c;
384 int mode;
386 acquire_console_sem();
387 if (ops && ops->currcon != -1)
388 vc = vc_cons[ops->currcon].d;
390 if (!vc || !CON_IS_VISIBLE(vc) ||
391 registered_fb[con2fb_map[vc->vc_num]] != info ||
392 vc->vc_deccm != 1) {
393 release_console_sem();
394 return;
397 p = &fb_display[vc->vc_num];
398 c = scr_readw((u16 *) vc->vc_pos);
399 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
400 CM_ERASE : CM_DRAW;
401 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
402 get_color(vc, info, c, 0));
403 release_console_sem();
406 #ifdef CONFIG_ATARI
407 static int cursor_blink_rate;
408 static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
410 struct fb_info *info = dev_id;
412 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
413 schedule_work(&info->queue);
414 vbl_cursor_cnt = cursor_blink_rate;
416 return IRQ_HANDLED;
418 #endif
420 static void cursor_timer_handler(unsigned long dev_addr)
422 struct fb_info *info = (struct fb_info *) dev_addr;
423 struct fbcon_ops *ops = info->fbcon_par;
425 schedule_work(&info->queue);
426 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
429 static void fbcon_add_cursor_timer(struct fb_info *info)
431 struct fbcon_ops *ops = info->fbcon_par;
433 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
434 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
435 !fbcon_cursor_noblink) {
436 if (!info->queue.func)
437 INIT_WORK(&info->queue, fb_flashcursor);
439 init_timer(&ops->cursor_timer);
440 ops->cursor_timer.function = cursor_timer_handler;
441 ops->cursor_timer.expires = jiffies + HZ / 5;
442 ops->cursor_timer.data = (unsigned long ) info;
443 add_timer(&ops->cursor_timer);
444 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
448 static void fbcon_del_cursor_timer(struct fb_info *info)
450 struct fbcon_ops *ops = info->fbcon_par;
452 if (info->queue.func == fb_flashcursor &&
453 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
454 del_timer_sync(&ops->cursor_timer);
455 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
459 #ifndef MODULE
460 static int __init fb_console_setup(char *this_opt)
462 char *options;
463 int i, j;
465 if (!this_opt || !*this_opt)
466 return 1;
468 while ((options = strsep(&this_opt, ",")) != NULL) {
469 if (!strncmp(options, "font:", 5))
470 strcpy(fontname, options + 5);
472 if (!strncmp(options, "scrollback:", 11)) {
473 options += 11;
474 if (*options) {
475 fbcon_softback_size = simple_strtoul(options, &options, 0);
476 if (*options == 'k' || *options == 'K') {
477 fbcon_softback_size *= 1024;
478 options++;
480 if (*options != ',')
481 return 1;
482 options++;
483 } else
484 return 1;
487 if (!strncmp(options, "map:", 4)) {
488 options += 4;
489 if (*options) {
490 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
491 if (!options[j])
492 j = 0;
493 con2fb_map_boot[i] =
494 (options[j++]-'0') % FB_MAX;
497 fbcon_map_override();
500 return 1;
503 if (!strncmp(options, "vc:", 3)) {
504 options += 3;
505 if (*options)
506 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
507 if (first_fb_vc < 0)
508 first_fb_vc = 0;
509 if (*options++ == '-')
510 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
511 fbcon_is_default = 0;
514 if (!strncmp(options, "rotate:", 7)) {
515 options += 7;
516 if (*options)
517 initial_rotation = simple_strtoul(options, &options, 0);
518 if (initial_rotation > 3)
519 initial_rotation = 0;
522 return 1;
525 __setup("fbcon=", fb_console_setup);
526 #endif
528 static int search_fb_in_map(int idx)
530 int i, retval = 0;
532 for (i = first_fb_vc; i <= last_fb_vc; i++) {
533 if (con2fb_map[i] == idx)
534 retval = 1;
536 return retval;
539 static int search_for_mapped_con(void)
541 int i, retval = 0;
543 for (i = first_fb_vc; i <= last_fb_vc; i++) {
544 if (con2fb_map[i] != -1)
545 retval = 1;
547 return retval;
550 static int fbcon_takeover(int show_logo)
552 int err, i;
554 if (!num_registered_fb)
555 return -ENODEV;
557 if (!show_logo)
558 logo_shown = FBCON_LOGO_DONTSHOW;
560 for (i = first_fb_vc; i <= last_fb_vc; i++)
561 con2fb_map[i] = info_idx;
563 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
564 fbcon_is_default);
566 if (err) {
567 for (i = first_fb_vc; i <= last_fb_vc; i++) {
568 con2fb_map[i] = -1;
570 info_idx = -1;
573 return err;
576 #ifdef MODULE
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 logo_shown = FBCON_LOGO_DONTSHOW;
582 #else
583 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
584 int cols, int rows, int new_cols, int new_rows)
586 /* Need to make room for the logo */
587 struct fbcon_ops *ops = info->fbcon_par;
588 int cnt, erase = vc->vc_video_erase_char, step;
589 unsigned short *save = NULL, *r, *q;
590 int logo_height;
592 if (info->flags & FBINFO_MODULE) {
593 logo_shown = FBCON_LOGO_DONTSHOW;
594 return;
598 * remove underline attribute from erase character
599 * if black and white framebuffer.
601 if (fb_get_color_depth(&info->var, &info->fix) == 1)
602 erase &= ~0x400;
603 logo_height = fb_prepare_logo(info, ops->rotate);
604 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
605 q = (unsigned short *) (vc->vc_origin +
606 vc->vc_size_row * rows);
607 step = logo_lines * cols;
608 for (r = q - logo_lines * cols; r < q; r++)
609 if (scr_readw(r) != vc->vc_video_erase_char)
610 break;
611 if (r != q && new_rows >= rows + logo_lines) {
612 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
613 if (save) {
614 int i = cols < new_cols ? cols : new_cols;
615 scr_memsetw(save, erase, logo_lines * new_cols * 2);
616 r = q - step;
617 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
618 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
619 r = q;
622 if (r == q) {
623 /* We can scroll screen down */
624 r = q - step - cols;
625 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
626 scr_memcpyw(r + step, r, vc->vc_size_row);
627 r -= cols;
629 if (!save) {
630 int lines;
631 if (vc->vc_y + logo_lines >= rows)
632 lines = rows - vc->vc_y - 1;
633 else
634 lines = logo_lines;
635 vc->vc_y += lines;
636 vc->vc_pos += lines * vc->vc_size_row;
639 scr_memsetw((unsigned short *) vc->vc_origin,
640 erase,
641 vc->vc_size_row * logo_lines);
643 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
644 fbcon_clear_margins(vc, 0);
645 update_screen(vc);
648 if (save) {
649 q = (unsigned short *) (vc->vc_origin +
650 vc->vc_size_row *
651 rows);
652 scr_memcpyw(q, save, logo_lines * new_cols * 2);
653 vc->vc_y += logo_lines;
654 vc->vc_pos += logo_lines * vc->vc_size_row;
655 kfree(save);
658 if (logo_lines > vc->vc_bottom) {
659 logo_shown = FBCON_LOGO_CANSHOW;
660 printk(KERN_INFO
661 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
662 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
663 logo_shown = FBCON_LOGO_DRAW;
664 vc->vc_top = logo_lines;
667 #endif /* MODULE */
669 #ifdef CONFIG_FB_TILEBLITTING
670 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
672 struct fbcon_ops *ops = info->fbcon_par;
674 ops->p = &fb_display[vc->vc_num];
676 if ((info->flags & FBINFO_MISC_TILEBLITTING))
677 fbcon_set_tileops(vc, info);
678 else {
679 fbcon_set_rotation(info);
680 fbcon_set_bitops(ops);
684 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
686 int err = 0;
688 if (info->flags & FBINFO_MISC_TILEBLITTING &&
689 info->tileops->fb_get_tilemax(info) < charcount)
690 err = 1;
692 return err;
694 #else
695 static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
697 struct fbcon_ops *ops = info->fbcon_par;
699 info->flags &= ~FBINFO_MISC_TILEBLITTING;
700 ops->p = &fb_display[vc->vc_num];
701 fbcon_set_rotation(info);
702 fbcon_set_bitops(ops);
705 static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
707 return 0;
710 #endif /* CONFIG_MISC_TILEBLITTING */
713 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
714 int unit, int oldidx)
716 struct fbcon_ops *ops = NULL;
717 int err = 0;
719 if (!try_module_get(info->fbops->owner))
720 err = -ENODEV;
722 if (!err && info->fbops->fb_open &&
723 info->fbops->fb_open(info, 0))
724 err = -ENODEV;
726 if (!err) {
727 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
728 if (!ops)
729 err = -ENOMEM;
732 if (!err) {
733 info->fbcon_par = ops;
735 if (vc)
736 set_blitting_type(vc, info);
739 if (err) {
740 con2fb_map[unit] = oldidx;
741 module_put(info->fbops->owner);
744 return err;
747 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
748 struct fb_info *newinfo, int unit,
749 int oldidx, int found)
751 struct fbcon_ops *ops = oldinfo->fbcon_par;
752 int err = 0;
754 if (oldinfo->fbops->fb_release &&
755 oldinfo->fbops->fb_release(oldinfo, 0)) {
756 con2fb_map[unit] = oldidx;
757 if (!found && newinfo->fbops->fb_release)
758 newinfo->fbops->fb_release(newinfo, 0);
759 if (!found)
760 module_put(newinfo->fbops->owner);
761 err = -ENODEV;
764 if (!err) {
765 fbcon_del_cursor_timer(oldinfo);
766 kfree(ops->cursor_state.mask);
767 kfree(ops->cursor_data);
768 kfree(ops->fontbuffer);
769 kfree(oldinfo->fbcon_par);
770 oldinfo->fbcon_par = NULL;
771 module_put(oldinfo->fbops->owner);
773 If oldinfo and newinfo are driving the same hardware,
774 the fb_release() method of oldinfo may attempt to
775 restore the hardware state. This will leave the
776 newinfo in an undefined state. Thus, a call to
777 fb_set_par() may be needed for the newinfo.
779 if (newinfo->fbops->fb_set_par)
780 newinfo->fbops->fb_set_par(newinfo);
783 return err;
786 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
787 int unit, int show_logo)
789 struct fbcon_ops *ops = info->fbcon_par;
791 ops->currcon = fg_console;
793 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
794 info->fbops->fb_set_par(info);
796 ops->flags |= FBCON_FLAGS_INIT;
797 ops->graphics = 0;
798 fbcon_set_disp(info, &info->var, unit);
800 if (show_logo) {
801 struct vc_data *fg_vc = vc_cons[fg_console].d;
802 struct fb_info *fg_info =
803 registered_fb[con2fb_map[fg_console]];
805 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
806 fg_vc->vc_rows, fg_vc->vc_cols,
807 fg_vc->vc_rows);
810 update_screen(vc_cons[fg_console].d);
814 * set_con2fb_map - map console to frame buffer device
815 * @unit: virtual console number to map
816 * @newidx: frame buffer index to map virtual console to
817 * @user: user request
819 * Maps a virtual console @unit to a frame buffer device
820 * @newidx.
822 static int set_con2fb_map(int unit, int newidx, int user)
824 struct vc_data *vc = vc_cons[unit].d;
825 int oldidx = con2fb_map[unit];
826 struct fb_info *info = registered_fb[newidx];
827 struct fb_info *oldinfo = NULL;
828 int found, err = 0;
830 if (oldidx == newidx)
831 return 0;
833 if (!info || fbcon_has_exited)
834 return -EINVAL;
836 if (!err && !search_for_mapped_con()) {
837 info_idx = newidx;
838 return fbcon_takeover(0);
841 if (oldidx != -1)
842 oldinfo = registered_fb[oldidx];
844 found = search_fb_in_map(newidx);
846 acquire_console_sem();
847 con2fb_map[unit] = newidx;
848 if (!err && !found)
849 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
853 * If old fb is not mapped to any of the consoles,
854 * fbcon should release it.
856 if (!err && oldinfo && !search_fb_in_map(oldidx))
857 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
858 found);
860 if (!err) {
861 int show_logo = (fg_console == 0 && !user &&
862 logo_shown != FBCON_LOGO_DONTSHOW);
864 if (!found)
865 fbcon_add_cursor_timer(info);
866 con2fb_map_boot[unit] = newidx;
867 con2fb_init_display(vc, info, unit, show_logo);
870 if (!search_fb_in_map(info_idx))
871 info_idx = newidx;
873 release_console_sem();
874 return err;
878 * Low Level Operations
880 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
881 static int var_to_display(struct display *disp,
882 struct fb_var_screeninfo *var,
883 struct fb_info *info)
885 disp->xres_virtual = var->xres_virtual;
886 disp->yres_virtual = var->yres_virtual;
887 disp->bits_per_pixel = var->bits_per_pixel;
888 disp->grayscale = var->grayscale;
889 disp->nonstd = var->nonstd;
890 disp->accel_flags = var->accel_flags;
891 disp->height = var->height;
892 disp->width = var->width;
893 disp->red = var->red;
894 disp->green = var->green;
895 disp->blue = var->blue;
896 disp->transp = var->transp;
897 disp->rotate = var->rotate;
898 disp->mode = fb_match_mode(var, &info->modelist);
899 if (disp->mode == NULL)
900 /* This should not happen */
901 return -EINVAL;
902 return 0;
905 static void display_to_var(struct fb_var_screeninfo *var,
906 struct display *disp)
908 fb_videomode_to_var(var, disp->mode);
909 var->xres_virtual = disp->xres_virtual;
910 var->yres_virtual = disp->yres_virtual;
911 var->bits_per_pixel = disp->bits_per_pixel;
912 var->grayscale = disp->grayscale;
913 var->nonstd = disp->nonstd;
914 var->accel_flags = disp->accel_flags;
915 var->height = disp->height;
916 var->width = disp->width;
917 var->red = disp->red;
918 var->green = disp->green;
919 var->blue = disp->blue;
920 var->transp = disp->transp;
921 var->rotate = disp->rotate;
924 static const char *fbcon_startup(void)
926 const char *display_desc = "frame buffer device";
927 struct display *p = &fb_display[fg_console];
928 struct vc_data *vc = vc_cons[fg_console].d;
929 const struct font_desc *font = NULL;
930 struct module *owner;
931 struct fb_info *info = NULL;
932 struct fbcon_ops *ops;
933 int rows, cols;
936 * If num_registered_fb is zero, this is a call for the dummy part.
937 * The frame buffer devices weren't initialized yet.
939 if (!num_registered_fb || info_idx == -1)
940 return display_desc;
942 * Instead of blindly using registered_fb[0], we use info_idx, set by
943 * fb_console_init();
945 info = registered_fb[info_idx];
946 if (!info)
947 return NULL;
949 owner = info->fbops->owner;
950 if (!try_module_get(owner))
951 return NULL;
952 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
953 module_put(owner);
954 return NULL;
957 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
958 if (!ops) {
959 module_put(owner);
960 return NULL;
963 ops->currcon = -1;
964 ops->graphics = 1;
965 ops->cur_rotate = -1;
966 info->fbcon_par = ops;
967 p->con_rotate = initial_rotation;
968 set_blitting_type(vc, info);
970 if (info->fix.type != FB_TYPE_TEXT) {
971 if (fbcon_softback_size) {
972 if (!softback_buf) {
973 softback_buf =
974 (unsigned long)
975 kmalloc(fbcon_softback_size,
976 GFP_KERNEL);
977 if (!softback_buf) {
978 fbcon_softback_size = 0;
979 softback_top = 0;
982 } else {
983 if (softback_buf) {
984 kfree((void *) softback_buf);
985 softback_buf = 0;
986 softback_top = 0;
989 if (softback_buf)
990 softback_in = softback_top = softback_curr =
991 softback_buf;
992 softback_lines = 0;
995 /* Setup default font */
996 if (!p->fontdata) {
997 if (!fontname[0] || !(font = find_font(fontname)))
998 font = get_default_font(info->var.xres,
999 info->var.yres,
1000 info->pixmap.blit_x,
1001 info->pixmap.blit_y);
1002 vc->vc_font.width = font->width;
1003 vc->vc_font.height = font->height;
1004 vc->vc_font.data = (void *)(p->fontdata = font->data);
1005 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1008 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1009 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1010 cols /= vc->vc_font.width;
1011 rows /= vc->vc_font.height;
1012 vc_resize(vc, cols, rows);
1014 DPRINTK("mode: %s\n", info->fix.id);
1015 DPRINTK("visual: %d\n", info->fix.visual);
1016 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1017 info->var.yres,
1018 info->var.bits_per_pixel);
1020 #ifdef CONFIG_ATARI
1021 if (MACH_IS_ATARI) {
1022 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1023 (void)request_irq(IRQ_AUTO_4, fb_vbl_handler,
1024 IRQ_TYPE_PRIO, "framebuffer vbl",
1025 info);
1027 #endif /* CONFIG_ATARI */
1029 fbcon_add_cursor_timer(info);
1030 fbcon_has_exited = 0;
1031 return display_desc;
1034 static void fbcon_init(struct vc_data *vc, int init)
1036 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1037 struct fbcon_ops *ops;
1038 struct vc_data **default_mode = vc->vc_display_fg;
1039 struct vc_data *svc = *default_mode;
1040 struct display *t, *p = &fb_display[vc->vc_num];
1041 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
1042 int cap;
1044 if (info_idx == -1 || info == NULL)
1045 return;
1047 cap = info->flags;
1049 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1050 (info->fix.type == FB_TYPE_TEXT))
1051 logo = 0;
1053 if (var_to_display(p, &info->var, info))
1054 return;
1056 if (!info->fbcon_par)
1057 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1059 /* If we are not the first console on this
1060 fb, copy the font from that console */
1061 t = &fb_display[fg_console];
1062 if (!p->fontdata) {
1063 if (t->fontdata) {
1064 struct vc_data *fvc = vc_cons[fg_console].d;
1066 vc->vc_font.data = (void *)(p->fontdata =
1067 fvc->vc_font.data);
1068 vc->vc_font.width = fvc->vc_font.width;
1069 vc->vc_font.height = fvc->vc_font.height;
1070 p->userfont = t->userfont;
1072 if (p->userfont)
1073 REFCOUNT(p->fontdata)++;
1074 } else {
1075 const struct font_desc *font = NULL;
1077 if (!fontname[0] || !(font = find_font(fontname)))
1078 font = get_default_font(info->var.xres,
1079 info->var.yres,
1080 info->pixmap.blit_x,
1081 info->pixmap.blit_y);
1082 vc->vc_font.width = font->width;
1083 vc->vc_font.height = font->height;
1084 vc->vc_font.data = (void *)(p->fontdata = font->data);
1085 vc->vc_font.charcount = 256; /* FIXME Need to
1086 support more fonts */
1090 if (p->userfont)
1091 charcnt = FNTCHARCNT(p->fontdata);
1093 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1094 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1095 if (charcnt == 256) {
1096 vc->vc_hi_font_mask = 0;
1097 } else {
1098 vc->vc_hi_font_mask = 0x100;
1099 if (vc->vc_can_do_color)
1100 vc->vc_complement_mask <<= 1;
1103 if (!*svc->vc_uni_pagedir_loc)
1104 con_set_default_unimap(svc);
1105 if (!*vc->vc_uni_pagedir_loc)
1106 con_copy_unimap(vc, svc);
1108 ops = info->fbcon_par;
1109 p->con_rotate = initial_rotation;
1110 set_blitting_type(vc, info);
1112 cols = vc->vc_cols;
1113 rows = vc->vc_rows;
1114 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1115 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1116 new_cols /= vc->vc_font.width;
1117 new_rows /= vc->vc_font.height;
1118 vc_resize(vc, new_cols, new_rows);
1121 * We must always set the mode. The mode of the previous console
1122 * driver could be in the same resolution but we are using different
1123 * hardware so we have to initialize the hardware.
1125 * We need to do it in fbcon_init() to prevent screen corruption.
1127 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
1128 if (info->fbops->fb_set_par &&
1129 !(ops->flags & FBCON_FLAGS_INIT))
1130 info->fbops->fb_set_par(info);
1131 ops->flags |= FBCON_FLAGS_INIT;
1134 ops->graphics = 0;
1136 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1137 !(cap & FBINFO_HWACCEL_DISABLED))
1138 p->scrollmode = SCROLL_MOVE;
1139 else /* default to something safe */
1140 p->scrollmode = SCROLL_REDRAW;
1143 * ++guenther: console.c:vc_allocate() relies on initializing
1144 * vc_{cols,rows}, but we must not set those if we are only
1145 * resizing the console.
1147 if (!init) {
1148 vc->vc_cols = new_cols;
1149 vc->vc_rows = new_rows;
1152 if (logo)
1153 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1155 if (vc == svc && softback_buf)
1156 fbcon_update_softback(vc);
1158 if (ops->rotate_font && ops->rotate_font(info, vc)) {
1159 ops->rotate = FB_ROTATE_UR;
1160 set_blitting_type(vc, info);
1163 ops->p = &fb_display[fg_console];
1166 static void fbcon_free_font(struct display *p)
1168 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1169 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1170 p->fontdata = NULL;
1171 p->userfont = 0;
1174 static void fbcon_deinit(struct vc_data *vc)
1176 struct display *p = &fb_display[vc->vc_num];
1177 struct fb_info *info;
1178 struct fbcon_ops *ops;
1179 int idx;
1181 fbcon_free_font(p);
1182 idx = con2fb_map[vc->vc_num];
1184 if (idx == -1)
1185 goto finished;
1187 info = registered_fb[idx];
1189 if (!info)
1190 goto finished;
1192 ops = info->fbcon_par;
1194 if (!ops)
1195 goto finished;
1197 if (CON_IS_VISIBLE(vc))
1198 fbcon_del_cursor_timer(info);
1200 ops->flags &= ~FBCON_FLAGS_INIT;
1201 finished:
1203 if (!con_is_bound(&fb_con))
1204 fbcon_exit();
1206 return;
1209 /* ====================================================================== */
1211 /* fbcon_XXX routines - interface used by the world
1213 * This system is now divided into two levels because of complications
1214 * caused by hardware scrolling. Top level functions:
1216 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1218 * handles y values in range [0, scr_height-1] that correspond to real
1219 * screen positions. y_wrap shift means that first line of bitmap may be
1220 * anywhere on this display. These functions convert lineoffsets to
1221 * bitmap offsets and deal with the wrap-around case by splitting blits.
1223 * fbcon_bmove_physical_8() -- These functions fast implementations
1224 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1225 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1227 * WARNING:
1229 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1230 * Implies should only really hardware scroll in rows. Only reason for
1231 * restriction is simplicity & efficiency at the moment.
1234 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1235 int width)
1237 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1238 struct fbcon_ops *ops = info->fbcon_par;
1240 struct display *p = &fb_display[vc->vc_num];
1241 u_int y_break;
1243 if (fbcon_is_inactive(vc, info))
1244 return;
1246 if (!height || !width)
1247 return;
1249 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1250 vc->vc_top = 0;
1252 /* Split blits that cross physical y_wrap boundary */
1254 y_break = p->vrows - p->yscroll;
1255 if (sy < y_break && sy + height - 1 >= y_break) {
1256 u_int b = y_break - sy;
1257 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1258 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1259 width);
1260 } else
1261 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1264 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1265 int count, int ypos, int xpos)
1267 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1268 struct display *p = &fb_display[vc->vc_num];
1269 struct fbcon_ops *ops = info->fbcon_par;
1271 if (!fbcon_is_inactive(vc, info))
1272 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1273 get_color(vc, info, scr_readw(s), 1),
1274 get_color(vc, info, scr_readw(s), 0));
1277 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1279 unsigned short chr;
1281 scr_writew(c, &chr);
1282 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1285 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1287 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1288 struct fbcon_ops *ops = info->fbcon_par;
1290 if (!fbcon_is_inactive(vc, info))
1291 ops->clear_margins(vc, info, bottom_only);
1294 static void fbcon_cursor(struct vc_data *vc, int mode)
1296 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1297 struct fbcon_ops *ops = info->fbcon_par;
1298 int y;
1299 int c = scr_readw((u16 *) vc->vc_pos);
1301 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1302 return;
1304 if (vc->vc_cursor_type & 0x10)
1305 fbcon_del_cursor_timer(info);
1306 else
1307 fbcon_add_cursor_timer(info);
1309 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1310 if (mode & CM_SOFTBACK) {
1311 mode &= ~CM_SOFTBACK;
1312 y = softback_lines;
1313 } else {
1314 if (softback_lines)
1315 fbcon_set_origin(vc);
1316 y = 0;
1319 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1320 get_color(vc, info, c, 0));
1321 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1324 static int scrollback_phys_max = 0;
1325 static int scrollback_max = 0;
1326 static int scrollback_current = 0;
1328 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1329 int unit)
1331 struct display *p, *t;
1332 struct vc_data **default_mode, *vc;
1333 struct vc_data *svc;
1334 struct fbcon_ops *ops = info->fbcon_par;
1335 int rows, cols, charcnt = 256;
1337 p = &fb_display[unit];
1339 if (var_to_display(p, var, info))
1340 return;
1342 vc = vc_cons[unit].d;
1344 if (!vc)
1345 return;
1347 default_mode = vc->vc_display_fg;
1348 svc = *default_mode;
1349 t = &fb_display[svc->vc_num];
1351 if (!vc->vc_font.data) {
1352 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1353 vc->vc_font.width = (*default_mode)->vc_font.width;
1354 vc->vc_font.height = (*default_mode)->vc_font.height;
1355 p->userfont = t->userfont;
1356 if (p->userfont)
1357 REFCOUNT(p->fontdata)++;
1359 if (p->userfont)
1360 charcnt = FNTCHARCNT(p->fontdata);
1362 var->activate = FB_ACTIVATE_NOW;
1363 info->var.activate = var->activate;
1364 var->yoffset = info->var.yoffset;
1365 var->xoffset = info->var.xoffset;
1366 fb_set_var(info, var);
1367 ops->var = info->var;
1368 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1369 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1370 if (charcnt == 256) {
1371 vc->vc_hi_font_mask = 0;
1372 } else {
1373 vc->vc_hi_font_mask = 0x100;
1374 if (vc->vc_can_do_color)
1375 vc->vc_complement_mask <<= 1;
1378 if (!*svc->vc_uni_pagedir_loc)
1379 con_set_default_unimap(svc);
1380 if (!*vc->vc_uni_pagedir_loc)
1381 con_copy_unimap(vc, svc);
1383 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1384 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1385 cols /= vc->vc_font.width;
1386 rows /= vc->vc_font.height;
1387 vc_resize(vc, cols, rows);
1389 if (CON_IS_VISIBLE(vc)) {
1390 update_screen(vc);
1391 if (softback_buf)
1392 fbcon_update_softback(vc);
1396 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1398 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1399 struct fbcon_ops *ops = info->fbcon_par;
1400 struct display *p = &fb_display[vc->vc_num];
1402 p->yscroll += count;
1403 if (p->yscroll >= p->vrows) /* Deal with wrap */
1404 p->yscroll -= p->vrows;
1405 ops->var.xoffset = 0;
1406 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1407 ops->var.vmode |= FB_VMODE_YWRAP;
1408 ops->update_start(info);
1409 scrollback_max += count;
1410 if (scrollback_max > scrollback_phys_max)
1411 scrollback_max = scrollback_phys_max;
1412 scrollback_current = 0;
1415 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1417 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1418 struct fbcon_ops *ops = info->fbcon_par;
1419 struct display *p = &fb_display[vc->vc_num];
1421 p->yscroll -= count;
1422 if (p->yscroll < 0) /* Deal with wrap */
1423 p->yscroll += p->vrows;
1424 ops->var.xoffset = 0;
1425 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1426 ops->var.vmode |= FB_VMODE_YWRAP;
1427 ops->update_start(info);
1428 scrollback_max -= count;
1429 if (scrollback_max < 0)
1430 scrollback_max = 0;
1431 scrollback_current = 0;
1434 static __inline__ void ypan_up(struct vc_data *vc, int count)
1436 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1437 struct display *p = &fb_display[vc->vc_num];
1438 struct fbcon_ops *ops = info->fbcon_par;
1440 p->yscroll += count;
1441 if (p->yscroll > p->vrows - vc->vc_rows) {
1442 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1443 0, 0, 0, vc->vc_rows, vc->vc_cols);
1444 p->yscroll -= p->vrows - vc->vc_rows;
1447 ops->var.xoffset = 0;
1448 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1449 ops->var.vmode &= ~FB_VMODE_YWRAP;
1450 ops->update_start(info);
1451 fbcon_clear_margins(vc, 1);
1452 scrollback_max += count;
1453 if (scrollback_max > scrollback_phys_max)
1454 scrollback_max = scrollback_phys_max;
1455 scrollback_current = 0;
1458 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1460 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1461 struct fbcon_ops *ops = info->fbcon_par;
1462 struct display *p = &fb_display[vc->vc_num];
1464 p->yscroll += count;
1466 if (p->yscroll > p->vrows - vc->vc_rows) {
1467 p->yscroll -= p->vrows - vc->vc_rows;
1468 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1471 ops->var.xoffset = 0;
1472 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1473 ops->var.vmode &= ~FB_VMODE_YWRAP;
1474 ops->update_start(info);
1475 fbcon_clear_margins(vc, 1);
1476 scrollback_max += count;
1477 if (scrollback_max > scrollback_phys_max)
1478 scrollback_max = scrollback_phys_max;
1479 scrollback_current = 0;
1482 static __inline__ void ypan_down(struct vc_data *vc, int count)
1484 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1485 struct display *p = &fb_display[vc->vc_num];
1486 struct fbcon_ops *ops = info->fbcon_par;
1488 p->yscroll -= count;
1489 if (p->yscroll < 0) {
1490 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1491 0, vc->vc_rows, vc->vc_cols);
1492 p->yscroll += p->vrows - vc->vc_rows;
1495 ops->var.xoffset = 0;
1496 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1497 ops->var.vmode &= ~FB_VMODE_YWRAP;
1498 ops->update_start(info);
1499 fbcon_clear_margins(vc, 1);
1500 scrollback_max -= count;
1501 if (scrollback_max < 0)
1502 scrollback_max = 0;
1503 scrollback_current = 0;
1506 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1508 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1509 struct fbcon_ops *ops = info->fbcon_par;
1510 struct display *p = &fb_display[vc->vc_num];
1512 p->yscroll -= count;
1514 if (p->yscroll < 0) {
1515 p->yscroll += p->vrows - vc->vc_rows;
1516 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1519 ops->var.xoffset = 0;
1520 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1521 ops->var.vmode &= ~FB_VMODE_YWRAP;
1522 ops->update_start(info);
1523 fbcon_clear_margins(vc, 1);
1524 scrollback_max -= count;
1525 if (scrollback_max < 0)
1526 scrollback_max = 0;
1527 scrollback_current = 0;
1530 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1531 long delta)
1533 int count = vc->vc_rows;
1534 unsigned short *d, *s;
1535 unsigned long n;
1536 int line = 0;
1538 d = (u16 *) softback_curr;
1539 if (d == (u16 *) softback_in)
1540 d = (u16 *) vc->vc_origin;
1541 n = softback_curr + delta * vc->vc_size_row;
1542 softback_lines -= delta;
1543 if (delta < 0) {
1544 if (softback_curr < softback_top && n < softback_buf) {
1545 n += softback_end - softback_buf;
1546 if (n < softback_top) {
1547 softback_lines -=
1548 (softback_top - n) / vc->vc_size_row;
1549 n = softback_top;
1551 } else if (softback_curr >= softback_top
1552 && n < softback_top) {
1553 softback_lines -=
1554 (softback_top - n) / vc->vc_size_row;
1555 n = softback_top;
1557 } else {
1558 if (softback_curr > softback_in && n >= softback_end) {
1559 n += softback_buf - softback_end;
1560 if (n > softback_in) {
1561 n = softback_in;
1562 softback_lines = 0;
1564 } else if (softback_curr <= softback_in && n > softback_in) {
1565 n = softback_in;
1566 softback_lines = 0;
1569 if (n == softback_curr)
1570 return;
1571 softback_curr = n;
1572 s = (u16 *) softback_curr;
1573 if (s == (u16 *) softback_in)
1574 s = (u16 *) vc->vc_origin;
1575 while (count--) {
1576 unsigned short *start;
1577 unsigned short *le;
1578 unsigned short c;
1579 int x = 0;
1580 unsigned short attr = 1;
1582 start = s;
1583 le = advance_row(s, 1);
1584 do {
1585 c = scr_readw(s);
1586 if (attr != (c & 0xff00)) {
1587 attr = c & 0xff00;
1588 if (s > start) {
1589 fbcon_putcs(vc, start, s - start,
1590 line, x);
1591 x += s - start;
1592 start = s;
1595 if (c == scr_readw(d)) {
1596 if (s > start) {
1597 fbcon_putcs(vc, start, s - start,
1598 line, x);
1599 x += s - start + 1;
1600 start = s + 1;
1601 } else {
1602 x++;
1603 start++;
1606 s++;
1607 d++;
1608 } while (s < le);
1609 if (s > start)
1610 fbcon_putcs(vc, start, s - start, line, x);
1611 line++;
1612 if (d == (u16 *) softback_end)
1613 d = (u16 *) softback_buf;
1614 if (d == (u16 *) softback_in)
1615 d = (u16 *) vc->vc_origin;
1616 if (s == (u16 *) softback_end)
1617 s = (u16 *) softback_buf;
1618 if (s == (u16 *) softback_in)
1619 s = (u16 *) vc->vc_origin;
1623 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1624 int line, int count, int dy)
1626 unsigned short *s = (unsigned short *)
1627 (vc->vc_origin + vc->vc_size_row * line);
1629 while (count--) {
1630 unsigned short *start = s;
1631 unsigned short *le = advance_row(s, 1);
1632 unsigned short c;
1633 int x = 0;
1634 unsigned short attr = 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 dy, x);
1643 x += s - start;
1644 start = s;
1647 console_conditional_schedule();
1648 s++;
1649 } while (s < le);
1650 if (s > start)
1651 fbcon_putcs(vc, start, s - start, dy, x);
1652 console_conditional_schedule();
1653 dy++;
1657 static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1658 struct display *p, int line, int count, int ycount)
1660 int offset = ycount * vc->vc_cols;
1661 unsigned short *d = (unsigned short *)
1662 (vc->vc_origin + vc->vc_size_row * line);
1663 unsigned short *s = d + offset;
1664 struct fbcon_ops *ops = info->fbcon_par;
1666 while (count--) {
1667 unsigned short *start = s;
1668 unsigned short *le = advance_row(s, 1);
1669 unsigned short c;
1670 int x = 0;
1672 do {
1673 c = scr_readw(s);
1675 if (c == scr_readw(d)) {
1676 if (s > start) {
1677 ops->bmove(vc, info, line + ycount, x,
1678 line, x, 1, s-start);
1679 x += s - start + 1;
1680 start = s + 1;
1681 } else {
1682 x++;
1683 start++;
1687 scr_writew(c, d);
1688 console_conditional_schedule();
1689 s++;
1690 d++;
1691 } while (s < le);
1692 if (s > start)
1693 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1694 s-start);
1695 console_conditional_schedule();
1696 if (ycount > 0)
1697 line++;
1698 else {
1699 line--;
1700 /* NOTE: We subtract two lines from these pointers */
1701 s -= vc->vc_size_row;
1702 d -= vc->vc_size_row;
1707 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1708 int line, int count, int offset)
1710 unsigned short *d = (unsigned short *)
1711 (vc->vc_origin + vc->vc_size_row * line);
1712 unsigned short *s = d + offset;
1714 while (count--) {
1715 unsigned short *start = s;
1716 unsigned short *le = advance_row(s, 1);
1717 unsigned short c;
1718 int x = 0;
1719 unsigned short attr = 1;
1721 do {
1722 c = scr_readw(s);
1723 if (attr != (c & 0xff00)) {
1724 attr = c & 0xff00;
1725 if (s > start) {
1726 fbcon_putcs(vc, start, s - start,
1727 line, x);
1728 x += s - start;
1729 start = s;
1732 if (c == scr_readw(d)) {
1733 if (s > start) {
1734 fbcon_putcs(vc, start, s - start,
1735 line, x);
1736 x += s - start + 1;
1737 start = s + 1;
1738 } else {
1739 x++;
1740 start++;
1743 scr_writew(c, d);
1744 console_conditional_schedule();
1745 s++;
1746 d++;
1747 } while (s < le);
1748 if (s > start)
1749 fbcon_putcs(vc, start, s - start, line, x);
1750 console_conditional_schedule();
1751 if (offset > 0)
1752 line++;
1753 else {
1754 line--;
1755 /* NOTE: We subtract two lines from these pointers */
1756 s -= vc->vc_size_row;
1757 d -= vc->vc_size_row;
1762 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1763 int count)
1765 unsigned short *p;
1767 if (vc->vc_num != fg_console)
1768 return;
1769 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1771 while (count) {
1772 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1773 count--;
1774 p = advance_row(p, 1);
1775 softback_in += vc->vc_size_row;
1776 if (softback_in == softback_end)
1777 softback_in = softback_buf;
1778 if (softback_in == softback_top) {
1779 softback_top += vc->vc_size_row;
1780 if (softback_top == softback_end)
1781 softback_top = softback_buf;
1784 softback_curr = softback_in;
1787 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1788 int count)
1790 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1791 struct display *p = &fb_display[vc->vc_num];
1792 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1794 if (fbcon_is_inactive(vc, info))
1795 return -EINVAL;
1797 fbcon_cursor(vc, CM_ERASE);
1800 * ++Geert: Only use ywrap/ypan if the console is in text mode
1801 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1802 * whole screen (prevents flicker).
1805 switch (dir) {
1806 case SM_UP:
1807 if (count > vc->vc_rows) /* Maximum realistic size */
1808 count = vc->vc_rows;
1809 if (softback_top)
1810 fbcon_softback_note(vc, t, count);
1811 if (logo_shown >= 0)
1812 goto redraw_up;
1813 switch (p->scrollmode) {
1814 case SCROLL_MOVE:
1815 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1816 count);
1817 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1818 scr_memsetw((unsigned short *) (vc->vc_origin +
1819 vc->vc_size_row *
1820 (b - count)),
1821 vc->vc_video_erase_char,
1822 vc->vc_size_row * count);
1823 return 1;
1824 break;
1826 case SCROLL_WRAP_MOVE:
1827 if (b - t - count > 3 * vc->vc_rows >> 2) {
1828 if (t > 0)
1829 fbcon_bmove(vc, 0, 0, count, 0, t,
1830 vc->vc_cols);
1831 ywrap_up(vc, count);
1832 if (vc->vc_rows - b > 0)
1833 fbcon_bmove(vc, b - count, 0, b, 0,
1834 vc->vc_rows - b,
1835 vc->vc_cols);
1836 } else if (info->flags & FBINFO_READS_FAST)
1837 fbcon_bmove(vc, t + count, 0, t, 0,
1838 b - t - count, vc->vc_cols);
1839 else
1840 goto redraw_up;
1841 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1842 break;
1844 case SCROLL_PAN_REDRAW:
1845 if ((p->yscroll + count <=
1846 2 * (p->vrows - vc->vc_rows))
1847 && ((!scroll_partial && (b - t == vc->vc_rows))
1848 || (scroll_partial
1849 && (b - t - count >
1850 3 * vc->vc_rows >> 2)))) {
1851 if (t > 0)
1852 fbcon_redraw_move(vc, p, 0, t, count);
1853 ypan_up_redraw(vc, t, count);
1854 if (vc->vc_rows - b > 0)
1855 fbcon_redraw_move(vc, p, b,
1856 vc->vc_rows - b, b);
1857 } else
1858 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1859 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1860 break;
1862 case SCROLL_PAN_MOVE:
1863 if ((p->yscroll + count <=
1864 2 * (p->vrows - vc->vc_rows))
1865 && ((!scroll_partial && (b - t == vc->vc_rows))
1866 || (scroll_partial
1867 && (b - t - count >
1868 3 * vc->vc_rows >> 2)))) {
1869 if (t > 0)
1870 fbcon_bmove(vc, 0, 0, count, 0, t,
1871 vc->vc_cols);
1872 ypan_up(vc, count);
1873 if (vc->vc_rows - b > 0)
1874 fbcon_bmove(vc, b - count, 0, b, 0,
1875 vc->vc_rows - b,
1876 vc->vc_cols);
1877 } else if (info->flags & FBINFO_READS_FAST)
1878 fbcon_bmove(vc, t + count, 0, t, 0,
1879 b - t - count, vc->vc_cols);
1880 else
1881 goto redraw_up;
1882 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1883 break;
1885 case SCROLL_REDRAW:
1886 redraw_up:
1887 fbcon_redraw(vc, p, t, b - t - count,
1888 count * vc->vc_cols);
1889 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1890 scr_memsetw((unsigned short *) (vc->vc_origin +
1891 vc->vc_size_row *
1892 (b - count)),
1893 vc->vc_video_erase_char,
1894 vc->vc_size_row * count);
1895 return 1;
1897 break;
1899 case SM_DOWN:
1900 if (count > vc->vc_rows) /* Maximum realistic size */
1901 count = vc->vc_rows;
1902 if (logo_shown >= 0)
1903 goto redraw_down;
1904 switch (p->scrollmode) {
1905 case SCROLL_MOVE:
1906 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1907 -count);
1908 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1909 scr_memsetw((unsigned short *) (vc->vc_origin +
1910 vc->vc_size_row *
1912 vc->vc_video_erase_char,
1913 vc->vc_size_row * count);
1914 return 1;
1915 break;
1917 case SCROLL_WRAP_MOVE:
1918 if (b - t - count > 3 * vc->vc_rows >> 2) {
1919 if (vc->vc_rows - b > 0)
1920 fbcon_bmove(vc, b, 0, b - count, 0,
1921 vc->vc_rows - b,
1922 vc->vc_cols);
1923 ywrap_down(vc, count);
1924 if (t > 0)
1925 fbcon_bmove(vc, count, 0, 0, 0, t,
1926 vc->vc_cols);
1927 } else if (info->flags & FBINFO_READS_FAST)
1928 fbcon_bmove(vc, t, 0, t + count, 0,
1929 b - t - count, vc->vc_cols);
1930 else
1931 goto redraw_down;
1932 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1933 break;
1935 case SCROLL_PAN_MOVE:
1936 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1937 && ((!scroll_partial && (b - t == vc->vc_rows))
1938 || (scroll_partial
1939 && (b - t - count >
1940 3 * vc->vc_rows >> 2)))) {
1941 if (vc->vc_rows - b > 0)
1942 fbcon_bmove(vc, b, 0, b - count, 0,
1943 vc->vc_rows - b,
1944 vc->vc_cols);
1945 ypan_down(vc, count);
1946 if (t > 0)
1947 fbcon_bmove(vc, count, 0, 0, 0, t,
1948 vc->vc_cols);
1949 } else if (info->flags & FBINFO_READS_FAST)
1950 fbcon_bmove(vc, t, 0, t + count, 0,
1951 b - t - count, vc->vc_cols);
1952 else
1953 goto redraw_down;
1954 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1955 break;
1957 case SCROLL_PAN_REDRAW:
1958 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1959 && ((!scroll_partial && (b - t == vc->vc_rows))
1960 || (scroll_partial
1961 && (b - t - count >
1962 3 * vc->vc_rows >> 2)))) {
1963 if (vc->vc_rows - b > 0)
1964 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1965 b - count);
1966 ypan_down_redraw(vc, t, count);
1967 if (t > 0)
1968 fbcon_redraw_move(vc, p, count, t, 0);
1969 } else
1970 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1971 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1972 break;
1974 case SCROLL_REDRAW:
1975 redraw_down:
1976 fbcon_redraw(vc, p, b - 1, b - t - count,
1977 -count * vc->vc_cols);
1978 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1979 scr_memsetw((unsigned short *) (vc->vc_origin +
1980 vc->vc_size_row *
1982 vc->vc_video_erase_char,
1983 vc->vc_size_row * count);
1984 return 1;
1987 return 0;
1991 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1992 int height, int width)
1994 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1995 struct display *p = &fb_display[vc->vc_num];
1997 if (fbcon_is_inactive(vc, info))
1998 return;
2000 if (!width || !height)
2001 return;
2003 /* Split blits that cross physical y_wrap case.
2004 * Pathological case involves 4 blits, better to use recursive
2005 * code rather than unrolled case
2007 * Recursive invocations don't need to erase the cursor over and
2008 * over again, so we use fbcon_bmove_rec()
2010 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2011 p->vrows - p->yscroll);
2014 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2015 int dy, int dx, int height, int width, u_int y_break)
2017 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2018 struct fbcon_ops *ops = info->fbcon_par;
2019 u_int b;
2021 if (sy < y_break && sy + height > y_break) {
2022 b = y_break - sy;
2023 if (dy < sy) { /* Avoid trashing self */
2024 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2025 y_break);
2026 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2027 height - b, width, y_break);
2028 } else {
2029 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2030 height - b, width, y_break);
2031 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2032 y_break);
2034 return;
2037 if (dy < y_break && dy + height > y_break) {
2038 b = y_break - dy;
2039 if (dy < sy) { /* Avoid trashing self */
2040 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2041 y_break);
2042 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2043 height - b, width, y_break);
2044 } else {
2045 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2046 height - b, width, y_break);
2047 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2048 y_break);
2050 return;
2052 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2053 height, width);
2056 static void updatescrollmode(struct display *p,
2057 struct fb_info *info,
2058 struct vc_data *vc)
2060 struct fbcon_ops *ops = info->fbcon_par;
2061 int fh = vc->vc_font.height;
2062 int cap = info->flags;
2063 u16 t = 0;
2064 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2065 info->fix.xpanstep);
2066 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2067 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2068 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2069 info->var.xres_virtual);
2070 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2071 divides(ypan, vc->vc_font.height) && vyres > yres;
2072 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2073 divides(ywrap, vc->vc_font.height) &&
2074 divides(vc->vc_font.height, vyres) &&
2075 divides(vc->vc_font.height, yres);
2076 int reading_fast = cap & FBINFO_READS_FAST;
2077 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2078 !(cap & FBINFO_HWACCEL_DISABLED);
2079 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2080 !(cap & FBINFO_HWACCEL_DISABLED);
2082 p->vrows = vyres/fh;
2083 if (yres > (fh * (vc->vc_rows + 1)))
2084 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2085 if ((yres % fh) && (vyres % fh < yres % fh))
2086 p->vrows--;
2088 if (good_wrap || good_pan) {
2089 if (reading_fast || fast_copyarea)
2090 p->scrollmode = good_wrap ?
2091 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
2092 else
2093 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2094 SCROLL_PAN_REDRAW;
2095 } else {
2096 if (reading_fast || (fast_copyarea && !fast_imageblit))
2097 p->scrollmode = SCROLL_MOVE;
2098 else
2099 p->scrollmode = SCROLL_REDRAW;
2103 static int fbcon_resize(struct vc_data *vc, unsigned int width,
2104 unsigned int height, unsigned int user)
2106 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2107 struct fbcon_ops *ops = info->fbcon_par;
2108 struct display *p = &fb_display[vc->vc_num];
2109 struct fb_var_screeninfo var = info->var;
2110 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2112 virt_w = FBCON_SWAP(ops->rotate, width, height);
2113 virt_h = FBCON_SWAP(ops->rotate, height, width);
2114 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2115 vc->vc_font.height);
2116 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2117 vc->vc_font.width);
2118 var.xres = virt_w * virt_fw;
2119 var.yres = virt_h * virt_fh;
2120 x_diff = info->var.xres - var.xres;
2121 y_diff = info->var.yres - var.yres;
2122 if (x_diff < 0 || x_diff > virt_fw ||
2123 y_diff < 0 || y_diff > virt_fh) {
2124 const struct fb_videomode *mode;
2126 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2127 mode = fb_find_best_mode(&var, &info->modelist);
2128 if (mode == NULL)
2129 return -EINVAL;
2130 display_to_var(&var, p);
2131 fb_videomode_to_var(&var, mode);
2133 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
2134 return -EINVAL;
2136 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2137 if (CON_IS_VISIBLE(vc)) {
2138 var.activate = FB_ACTIVATE_NOW |
2139 FB_ACTIVATE_FORCE;
2140 fb_set_var(info, &var);
2142 var_to_display(p, &info->var, info);
2143 ops->var = info->var;
2145 updatescrollmode(p, info, vc);
2146 return 0;
2149 static int fbcon_switch(struct vc_data *vc)
2151 struct fb_info *info, *old_info = NULL;
2152 struct fbcon_ops *ops;
2153 struct display *p = &fb_display[vc->vc_num];
2154 struct fb_var_screeninfo var;
2155 int i, prev_console, charcnt = 256;
2157 info = registered_fb[con2fb_map[vc->vc_num]];
2158 ops = info->fbcon_par;
2160 if (softback_top) {
2161 if (softback_lines)
2162 fbcon_set_origin(vc);
2163 softback_top = softback_curr = softback_in = softback_buf;
2164 softback_lines = 0;
2165 fbcon_update_softback(vc);
2168 if (logo_shown >= 0) {
2169 struct vc_data *conp2 = vc_cons[logo_shown].d;
2171 if (conp2->vc_top == logo_lines
2172 && conp2->vc_bottom == conp2->vc_rows)
2173 conp2->vc_top = 0;
2174 logo_shown = FBCON_LOGO_CANSHOW;
2177 prev_console = ops->currcon;
2178 if (prev_console != -1)
2179 old_info = registered_fb[con2fb_map[prev_console]];
2181 * FIXME: If we have multiple fbdev's loaded, we need to
2182 * update all info->currcon. Perhaps, we can place this
2183 * in a centralized structure, but this might break some
2184 * drivers.
2186 * info->currcon = vc->vc_num;
2188 for (i = 0; i < FB_MAX; i++) {
2189 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2190 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2192 o->currcon = vc->vc_num;
2195 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2196 display_to_var(&var, p);
2197 var.activate = FB_ACTIVATE_NOW;
2200 * make sure we don't unnecessarily trip the memcmp()
2201 * in fb_set_var()
2203 info->var.activate = var.activate;
2204 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
2205 fb_set_var(info, &var);
2206 ops->var = info->var;
2208 if (old_info != NULL && (old_info != info ||
2209 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
2210 if (info->fbops->fb_set_par)
2211 info->fbops->fb_set_par(info);
2213 if (old_info != info)
2214 fbcon_del_cursor_timer(old_info);
2217 if (fbcon_is_inactive(vc, info) ||
2218 ops->blank_state != FB_BLANK_UNBLANK)
2219 fbcon_del_cursor_timer(info);
2220 else
2221 fbcon_add_cursor_timer(info);
2223 set_blitting_type(vc, info);
2224 ops->cursor_reset = 1;
2226 if (ops->rotate_font && ops->rotate_font(info, vc)) {
2227 ops->rotate = FB_ROTATE_UR;
2228 set_blitting_type(vc, info);
2231 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2232 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2234 if (p->userfont)
2235 charcnt = FNTCHARCNT(vc->vc_font.data);
2237 if (charcnt > 256)
2238 vc->vc_complement_mask <<= 1;
2240 updatescrollmode(p, info, vc);
2242 switch (p->scrollmode) {
2243 case SCROLL_WRAP_MOVE:
2244 scrollback_phys_max = p->vrows - vc->vc_rows;
2245 break;
2246 case SCROLL_PAN_MOVE:
2247 case SCROLL_PAN_REDRAW:
2248 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2249 if (scrollback_phys_max < 0)
2250 scrollback_phys_max = 0;
2251 break;
2252 default:
2253 scrollback_phys_max = 0;
2254 break;
2257 scrollback_max = 0;
2258 scrollback_current = 0;
2260 if (!fbcon_is_inactive(vc, info)) {
2261 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2262 ops->update_start(info);
2265 fbcon_set_palette(vc, color_table);
2266 fbcon_clear_margins(vc, 0);
2268 if (logo_shown == FBCON_LOGO_DRAW) {
2270 logo_shown = fg_console;
2271 /* This is protected above by initmem_freed */
2272 fb_show_logo(info, ops->rotate);
2273 update_region(vc,
2274 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2275 vc->vc_size_row * (vc->vc_bottom -
2276 vc->vc_top) / 2);
2277 return 0;
2279 return 1;
2282 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2283 int blank)
2285 struct fb_event event;
2287 if (blank) {
2288 unsigned short charmask = vc->vc_hi_font_mask ?
2289 0x1ff : 0xff;
2290 unsigned short oldc;
2292 oldc = vc->vc_video_erase_char;
2293 vc->vc_video_erase_char &= charmask;
2294 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2295 vc->vc_video_erase_char = oldc;
2299 event.info = info;
2300 event.data = &blank;
2301 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
2304 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2306 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2307 struct fbcon_ops *ops = info->fbcon_par;
2309 if (mode_switch) {
2310 struct fb_var_screeninfo var = info->var;
2312 ops->graphics = 1;
2314 if (!blank) {
2315 if (info->fbops->fb_save_state)
2316 info->fbops->fb_save_state(info);
2317 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2318 fb_set_var(info, &var);
2319 ops->graphics = 0;
2320 ops->var = info->var;
2321 } else if (info->fbops->fb_restore_state)
2322 info->fbops->fb_restore_state(info);
2325 if (!fbcon_is_inactive(vc, info)) {
2326 if (ops->blank_state != blank) {
2327 ops->blank_state = blank;
2328 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2329 ops->cursor_flash = (!blank);
2331 if (!(info->flags & FBINFO_MISC_USEREVENT))
2332 if (fb_blank(info, blank))
2333 fbcon_generic_blank(vc, info, blank);
2336 if (!blank)
2337 update_screen(vc);
2340 if (mode_switch || fbcon_is_inactive(vc, info) ||
2341 ops->blank_state != FB_BLANK_UNBLANK)
2342 fbcon_del_cursor_timer(info);
2343 else
2344 fbcon_add_cursor_timer(info);
2346 return 0;
2349 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2351 u8 *fontdata = vc->vc_font.data;
2352 u8 *data = font->data;
2353 int i, j;
2355 font->width = vc->vc_font.width;
2356 font->height = vc->vc_font.height;
2357 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2358 if (!font->data)
2359 return 0;
2361 if (font->width <= 8) {
2362 j = vc->vc_font.height;
2363 for (i = 0; i < font->charcount; i++) {
2364 memcpy(data, fontdata, j);
2365 memset(data + j, 0, 32 - j);
2366 data += 32;
2367 fontdata += j;
2369 } else if (font->width <= 16) {
2370 j = vc->vc_font.height * 2;
2371 for (i = 0; i < font->charcount; i++) {
2372 memcpy(data, fontdata, j);
2373 memset(data + j, 0, 64 - j);
2374 data += 64;
2375 fontdata += j;
2377 } else if (font->width <= 24) {
2378 for (i = 0; i < font->charcount; i++) {
2379 for (j = 0; j < vc->vc_font.height; j++) {
2380 *data++ = fontdata[0];
2381 *data++ = fontdata[1];
2382 *data++ = fontdata[2];
2383 fontdata += sizeof(u32);
2385 memset(data, 0, 3 * (32 - j));
2386 data += 3 * (32 - j);
2388 } else {
2389 j = vc->vc_font.height * 4;
2390 for (i = 0; i < font->charcount; i++) {
2391 memcpy(data, fontdata, j);
2392 memset(data + j, 0, 128 - j);
2393 data += 128;
2394 fontdata += j;
2397 return 0;
2400 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2401 const u8 * data, int userfont)
2403 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2404 struct fbcon_ops *ops = info->fbcon_par;
2405 struct display *p = &fb_display[vc->vc_num];
2406 int resize;
2407 int cnt;
2408 char *old_data = NULL;
2410 if (CON_IS_VISIBLE(vc) && softback_lines)
2411 fbcon_set_origin(vc);
2413 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2414 if (p->userfont)
2415 old_data = vc->vc_font.data;
2416 if (userfont)
2417 cnt = FNTCHARCNT(data);
2418 else
2419 cnt = 256;
2420 vc->vc_font.data = (void *)(p->fontdata = data);
2421 if ((p->userfont = userfont))
2422 REFCOUNT(data)++;
2423 vc->vc_font.width = w;
2424 vc->vc_font.height = h;
2425 if (vc->vc_hi_font_mask && cnt == 256) {
2426 vc->vc_hi_font_mask = 0;
2427 if (vc->vc_can_do_color) {
2428 vc->vc_complement_mask >>= 1;
2429 vc->vc_s_complement_mask >>= 1;
2432 /* ++Edmund: reorder the attribute bits */
2433 if (vc->vc_can_do_color) {
2434 unsigned short *cp =
2435 (unsigned short *) vc->vc_origin;
2436 int count = vc->vc_screenbuf_size / 2;
2437 unsigned short c;
2438 for (; count > 0; count--, cp++) {
2439 c = scr_readw(cp);
2440 scr_writew(((c & 0xfe00) >> 1) |
2441 (c & 0xff), cp);
2443 c = vc->vc_video_erase_char;
2444 vc->vc_video_erase_char =
2445 ((c & 0xfe00) >> 1) | (c & 0xff);
2446 vc->vc_attr >>= 1;
2448 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2449 vc->vc_hi_font_mask = 0x100;
2450 if (vc->vc_can_do_color) {
2451 vc->vc_complement_mask <<= 1;
2452 vc->vc_s_complement_mask <<= 1;
2455 /* ++Edmund: reorder the attribute bits */
2457 unsigned short *cp =
2458 (unsigned short *) vc->vc_origin;
2459 int count = vc->vc_screenbuf_size / 2;
2460 unsigned short c;
2461 for (; count > 0; count--, cp++) {
2462 unsigned short newc;
2463 c = scr_readw(cp);
2464 if (vc->vc_can_do_color)
2465 newc =
2466 ((c & 0xff00) << 1) | (c &
2467 0xff);
2468 else
2469 newc = c & ~0x100;
2470 scr_writew(newc, cp);
2472 c = vc->vc_video_erase_char;
2473 if (vc->vc_can_do_color) {
2474 vc->vc_video_erase_char =
2475 ((c & 0xff00) << 1) | (c & 0xff);
2476 vc->vc_attr <<= 1;
2477 } else
2478 vc->vc_video_erase_char = c & ~0x100;
2483 if (resize) {
2484 int cols, rows;
2486 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2487 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2488 cols /= w;
2489 rows /= h;
2490 vc_resize(vc, cols, rows);
2491 if (CON_IS_VISIBLE(vc) && softback_buf)
2492 fbcon_update_softback(vc);
2493 } else if (CON_IS_VISIBLE(vc)
2494 && vc->vc_mode == KD_TEXT) {
2495 fbcon_clear_margins(vc, 0);
2496 update_screen(vc);
2499 if (old_data && (--REFCOUNT(old_data) == 0))
2500 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2501 return 0;
2504 static int fbcon_copy_font(struct vc_data *vc, int con)
2506 struct display *od = &fb_display[con];
2507 struct console_font *f = &vc->vc_font;
2509 if (od->fontdata == f->data)
2510 return 0; /* already the same font... */
2511 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2515 * User asked to set font; we are guaranteed that
2516 * a) width and height are in range 1..32
2517 * b) charcount does not exceed 512
2518 * but lets not assume that, since someone might someday want to use larger
2519 * fonts. And charcount of 512 is small for unicode support.
2521 * However, user space gives the font in 32 rows , regardless of
2522 * actual font height. So a new API is needed if support for larger fonts
2523 * is ever implemented.
2526 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2528 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2529 unsigned charcount = font->charcount;
2530 int w = font->width;
2531 int h = font->height;
2532 int size;
2533 int i, csum;
2534 u8 *new_data, *data = font->data;
2535 int pitch = (font->width+7) >> 3;
2537 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2538 * If not this check should be changed to charcount < 256 */
2539 if (charcount != 256 && charcount != 512)
2540 return -EINVAL;
2542 /* Make sure drawing engine can handle the font */
2543 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2544 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2545 return -EINVAL;
2547 /* Make sure driver can handle the font length */
2548 if (fbcon_invalid_charcount(info, charcount))
2549 return -EINVAL;
2551 size = h * pitch * charcount;
2553 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2555 if (!new_data)
2556 return -ENOMEM;
2558 new_data += FONT_EXTRA_WORDS * sizeof(int);
2559 FNTSIZE(new_data) = size;
2560 FNTCHARCNT(new_data) = charcount;
2561 REFCOUNT(new_data) = 0; /* usage counter */
2562 for (i=0; i< charcount; i++) {
2563 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2566 /* Since linux has a nice crc32 function use it for counting font
2567 * checksums. */
2568 csum = crc32(0, new_data, size);
2570 FNTSUM(new_data) = csum;
2571 /* Check if the same font is on some other console already */
2572 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2573 struct vc_data *tmp = vc_cons[i].d;
2575 if (fb_display[i].userfont &&
2576 fb_display[i].fontdata &&
2577 FNTSUM(fb_display[i].fontdata) == csum &&
2578 FNTSIZE(fb_display[i].fontdata) == size &&
2579 tmp->vc_font.width == w &&
2580 !memcmp(fb_display[i].fontdata, new_data, size)) {
2581 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2582 new_data = (u8 *)fb_display[i].fontdata;
2583 break;
2586 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2589 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2591 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2592 const struct font_desc *f;
2594 if (!name)
2595 f = get_default_font(info->var.xres, info->var.yres,
2596 info->pixmap.blit_x, info->pixmap.blit_y);
2597 else if (!(f = find_font(name)))
2598 return -ENOENT;
2600 font->width = f->width;
2601 font->height = f->height;
2602 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2605 static u16 palette_red[16];
2606 static u16 palette_green[16];
2607 static u16 palette_blue[16];
2609 static struct fb_cmap palette_cmap = {
2610 0, 16, palette_red, palette_green, palette_blue, NULL
2613 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2615 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2616 int i, j, k, depth;
2617 u8 val;
2619 if (fbcon_is_inactive(vc, info))
2620 return -EINVAL;
2622 if (!CON_IS_VISIBLE(vc))
2623 return 0;
2625 depth = fb_get_color_depth(&info->var, &info->fix);
2626 if (depth > 3) {
2627 for (i = j = 0; i < 16; i++) {
2628 k = table[i];
2629 val = vc->vc_palette[j++];
2630 palette_red[k] = (val << 8) | val;
2631 val = vc->vc_palette[j++];
2632 palette_green[k] = (val << 8) | val;
2633 val = vc->vc_palette[j++];
2634 palette_blue[k] = (val << 8) | val;
2636 palette_cmap.len = 16;
2637 palette_cmap.start = 0;
2639 * If framebuffer is capable of less than 16 colors,
2640 * use default palette of fbcon.
2642 } else
2643 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2645 return fb_set_cmap(&palette_cmap, info);
2648 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2650 unsigned long p;
2651 int line;
2653 if (vc->vc_num != fg_console || !softback_lines)
2654 return (u16 *) (vc->vc_origin + offset);
2655 line = offset / vc->vc_size_row;
2656 if (line >= softback_lines)
2657 return (u16 *) (vc->vc_origin + offset -
2658 softback_lines * vc->vc_size_row);
2659 p = softback_curr + offset;
2660 if (p >= softback_end)
2661 p += softback_buf - softback_end;
2662 return (u16 *) p;
2665 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2666 int *px, int *py)
2668 unsigned long ret;
2669 int x, y;
2671 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2672 unsigned long offset = (pos - vc->vc_origin) / 2;
2674 x = offset % vc->vc_cols;
2675 y = offset / vc->vc_cols;
2676 if (vc->vc_num == fg_console)
2677 y += softback_lines;
2678 ret = pos + (vc->vc_cols - x) * 2;
2679 } else if (vc->vc_num == fg_console && softback_lines) {
2680 unsigned long offset = pos - softback_curr;
2682 if (pos < softback_curr)
2683 offset += softback_end - softback_buf;
2684 offset /= 2;
2685 x = offset % vc->vc_cols;
2686 y = offset / vc->vc_cols;
2687 ret = pos + (vc->vc_cols - x) * 2;
2688 if (ret == softback_end)
2689 ret = softback_buf;
2690 if (ret == softback_in)
2691 ret = vc->vc_origin;
2692 } else {
2693 /* Should not happen */
2694 x = y = 0;
2695 ret = vc->vc_origin;
2697 if (px)
2698 *px = x;
2699 if (py)
2700 *py = y;
2701 return ret;
2704 /* As we might be inside of softback, we may work with non-contiguous buffer,
2705 that's why we have to use a separate routine. */
2706 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2708 while (cnt--) {
2709 u16 a = scr_readw(p);
2710 if (!vc->vc_can_do_color)
2711 a ^= 0x0800;
2712 else if (vc->vc_hi_font_mask == 0x100)
2713 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2714 (((a) & 0x0e00) << 4);
2715 else
2716 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2717 (((a) & 0x0700) << 4);
2718 scr_writew(a, p++);
2719 if (p == (u16 *) softback_end)
2720 p = (u16 *) softback_buf;
2721 if (p == (u16 *) softback_in)
2722 p = (u16 *) vc->vc_origin;
2726 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2728 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2729 struct fbcon_ops *ops = info->fbcon_par;
2730 struct display *disp = &fb_display[fg_console];
2731 int offset, limit, scrollback_old;
2733 if (softback_top) {
2734 if (vc->vc_num != fg_console)
2735 return 0;
2736 if (vc->vc_mode != KD_TEXT || !lines)
2737 return 0;
2738 if (logo_shown >= 0) {
2739 struct vc_data *conp2 = vc_cons[logo_shown].d;
2741 if (conp2->vc_top == logo_lines
2742 && conp2->vc_bottom == conp2->vc_rows)
2743 conp2->vc_top = 0;
2744 if (logo_shown == vc->vc_num) {
2745 unsigned long p, q;
2746 int i;
2748 p = softback_in;
2749 q = vc->vc_origin +
2750 logo_lines * vc->vc_size_row;
2751 for (i = 0; i < logo_lines; i++) {
2752 if (p == softback_top)
2753 break;
2754 if (p == softback_buf)
2755 p = softback_end;
2756 p -= vc->vc_size_row;
2757 q -= vc->vc_size_row;
2758 scr_memcpyw((u16 *) q, (u16 *) p,
2759 vc->vc_size_row);
2761 softback_in = softback_curr = p;
2762 update_region(vc, vc->vc_origin,
2763 logo_lines * vc->vc_cols);
2765 logo_shown = FBCON_LOGO_CANSHOW;
2767 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2768 fbcon_redraw_softback(vc, disp, lines);
2769 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2770 return 0;
2773 if (!scrollback_phys_max)
2774 return -ENOSYS;
2776 scrollback_old = scrollback_current;
2777 scrollback_current -= lines;
2778 if (scrollback_current < 0)
2779 scrollback_current = 0;
2780 else if (scrollback_current > scrollback_max)
2781 scrollback_current = scrollback_max;
2782 if (scrollback_current == scrollback_old)
2783 return 0;
2785 if (fbcon_is_inactive(vc, info))
2786 return 0;
2788 fbcon_cursor(vc, CM_ERASE);
2790 offset = disp->yscroll - scrollback_current;
2791 limit = disp->vrows;
2792 switch (disp->scrollmode) {
2793 case SCROLL_WRAP_MOVE:
2794 info->var.vmode |= FB_VMODE_YWRAP;
2795 break;
2796 case SCROLL_PAN_MOVE:
2797 case SCROLL_PAN_REDRAW:
2798 limit -= vc->vc_rows;
2799 info->var.vmode &= ~FB_VMODE_YWRAP;
2800 break;
2802 if (offset < 0)
2803 offset += limit;
2804 else if (offset >= limit)
2805 offset -= limit;
2807 ops->var.xoffset = 0;
2808 ops->var.yoffset = offset * vc->vc_font.height;
2809 ops->update_start(info);
2811 if (!scrollback_current)
2812 fbcon_cursor(vc, CM_DRAW);
2813 return 0;
2816 static int fbcon_set_origin(struct vc_data *vc)
2818 if (softback_lines)
2819 fbcon_scrolldelta(vc, softback_lines);
2820 return 0;
2823 static void fbcon_suspended(struct fb_info *info)
2825 struct vc_data *vc = NULL;
2826 struct fbcon_ops *ops = info->fbcon_par;
2828 if (!ops || ops->currcon < 0)
2829 return;
2830 vc = vc_cons[ops->currcon].d;
2832 /* Clear cursor, restore saved data */
2833 fbcon_cursor(vc, CM_ERASE);
2836 static void fbcon_resumed(struct fb_info *info)
2838 struct vc_data *vc;
2839 struct fbcon_ops *ops = info->fbcon_par;
2841 if (!ops || ops->currcon < 0)
2842 return;
2843 vc = vc_cons[ops->currcon].d;
2845 update_screen(vc);
2848 static void fbcon_modechanged(struct fb_info *info)
2850 struct fbcon_ops *ops = info->fbcon_par;
2851 struct vc_data *vc;
2852 struct display *p;
2853 int rows, cols;
2855 if (!ops || ops->currcon < 0)
2856 return;
2857 vc = vc_cons[ops->currcon].d;
2858 if (vc->vc_mode != KD_TEXT ||
2859 registered_fb[con2fb_map[ops->currcon]] != info)
2860 return;
2862 p = &fb_display[vc->vc_num];
2863 set_blitting_type(vc, info);
2865 if (CON_IS_VISIBLE(vc)) {
2866 var_to_display(p, &info->var, info);
2867 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2868 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2869 cols /= vc->vc_font.width;
2870 rows /= vc->vc_font.height;
2871 vc_resize(vc, cols, rows);
2872 updatescrollmode(p, info, vc);
2873 scrollback_max = 0;
2874 scrollback_current = 0;
2876 if (!fbcon_is_inactive(vc, info)) {
2877 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2878 ops->update_start(info);
2881 fbcon_set_palette(vc, color_table);
2882 update_screen(vc);
2883 if (softback_buf)
2884 fbcon_update_softback(vc);
2888 static void fbcon_set_all_vcs(struct fb_info *info)
2890 struct fbcon_ops *ops = info->fbcon_par;
2891 struct vc_data *vc;
2892 struct display *p;
2893 int i, rows, cols, fg = -1;
2895 if (!ops || ops->currcon < 0)
2896 return;
2898 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2899 vc = vc_cons[i].d;
2900 if (!vc || vc->vc_mode != KD_TEXT ||
2901 registered_fb[con2fb_map[i]] != info)
2902 continue;
2904 if (CON_IS_VISIBLE(vc)) {
2905 fg = i;
2906 continue;
2909 p = &fb_display[vc->vc_num];
2910 set_blitting_type(vc, info);
2911 var_to_display(p, &info->var, info);
2912 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2913 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2914 cols /= vc->vc_font.width;
2915 rows /= vc->vc_font.height;
2916 vc_resize(vc, cols, rows);
2919 if (fg != -1)
2920 fbcon_modechanged(info);
2923 static int fbcon_mode_deleted(struct fb_info *info,
2924 struct fb_videomode *mode)
2926 struct fb_info *fb_info;
2927 struct display *p;
2928 int i, j, found = 0;
2930 /* before deletion, ensure that mode is not in use */
2931 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2932 j = con2fb_map[i];
2933 if (j == -1)
2934 continue;
2935 fb_info = registered_fb[j];
2936 if (fb_info != info)
2937 continue;
2938 p = &fb_display[i];
2939 if (!p || !p->mode)
2940 continue;
2941 if (fb_mode_is_equal(p->mode, mode)) {
2942 found = 1;
2943 break;
2946 return found;
2949 #ifdef CONFIG_VT_HW_CONSOLE_BINDING
2950 static int fbcon_unbind(void)
2952 int ret;
2954 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2955 fbcon_is_default);
2956 return ret;
2958 #else
2959 static inline int fbcon_unbind(void)
2961 return -EINVAL;
2963 #endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2965 static int fbcon_fb_unbind(int idx)
2967 int i, new_idx = -1, ret = 0;
2969 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2970 if (con2fb_map[i] != idx &&
2971 con2fb_map[i] != -1) {
2972 new_idx = i;
2973 break;
2977 if (new_idx != -1) {
2978 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2979 if (con2fb_map[i] == idx)
2980 set_con2fb_map(i, new_idx, 0);
2982 } else
2983 ret = fbcon_unbind();
2985 return ret;
2988 static int fbcon_fb_unregistered(struct fb_info *info)
2990 int i, idx = info->node;
2992 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2993 if (con2fb_map[i] == idx)
2994 con2fb_map[i] = -1;
2997 if (idx == info_idx) {
2998 info_idx = -1;
3000 for (i = 0; i < FB_MAX; i++) {
3001 if (registered_fb[i] != NULL) {
3002 info_idx = i;
3003 break;
3008 if (info_idx != -1) {
3009 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3010 if (con2fb_map[i] == -1)
3011 con2fb_map[i] = info_idx;
3015 if (!num_registered_fb)
3016 unregister_con_driver(&fb_con);
3019 if (primary_device == idx)
3020 primary_device = -1;
3022 return 0;
3025 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3026 static void fbcon_select_primary(struct fb_info *info)
3028 if (!map_override && primary_device == -1 &&
3029 fb_is_primary_device(info)) {
3030 int i;
3032 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3033 info->fix.id, info->node);
3034 primary_device = info->node;
3036 for (i = first_fb_vc; i <= last_fb_vc; i++)
3037 con2fb_map_boot[i] = primary_device;
3039 if (con_is_bound(&fb_con)) {
3040 printk(KERN_INFO "fbcon: Remapping primary device, "
3041 "fb%i, to tty %i-%i\n", info->node,
3042 first_fb_vc + 1, last_fb_vc + 1);
3043 info_idx = primary_device;
3048 #else
3049 static inline void fbcon_select_primary(struct fb_info *info)
3051 return;
3053 #endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3055 static int fbcon_fb_registered(struct fb_info *info)
3057 int ret = 0, i, idx = info->node;
3059 fbcon_select_primary(info);
3061 if (info_idx == -1) {
3062 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3063 if (con2fb_map_boot[i] == idx) {
3064 info_idx = idx;
3065 break;
3069 if (info_idx != -1)
3070 ret = fbcon_takeover(1);
3071 } else {
3072 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3073 if (con2fb_map_boot[i] == idx)
3074 set_con2fb_map(i, idx, 0);
3078 return ret;
3081 static void fbcon_fb_blanked(struct fb_info *info, int blank)
3083 struct fbcon_ops *ops = info->fbcon_par;
3084 struct vc_data *vc;
3086 if (!ops || ops->currcon < 0)
3087 return;
3089 vc = vc_cons[ops->currcon].d;
3090 if (vc->vc_mode != KD_TEXT ||
3091 registered_fb[con2fb_map[ops->currcon]] != info)
3092 return;
3094 if (CON_IS_VISIBLE(vc)) {
3095 if (blank)
3096 do_blank_screen(0);
3097 else
3098 do_unblank_screen(0);
3100 ops->blank_state = blank;
3103 static void fbcon_new_modelist(struct fb_info *info)
3105 int i;
3106 struct vc_data *vc;
3107 struct fb_var_screeninfo var;
3108 const struct fb_videomode *mode;
3110 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3111 if (registered_fb[con2fb_map[i]] != info)
3112 continue;
3113 if (!fb_display[i].mode)
3114 continue;
3115 vc = vc_cons[i].d;
3116 display_to_var(&var, &fb_display[i]);
3117 mode = fb_find_nearest_mode(fb_display[i].mode,
3118 &info->modelist);
3119 fb_videomode_to_var(&var, mode);
3120 fbcon_set_disp(info, &var, vc->vc_num);
3124 static void fbcon_get_requirement(struct fb_info *info,
3125 struct fb_blit_caps *caps)
3127 struct vc_data *vc;
3128 struct display *p;
3130 if (caps->flags) {
3131 int i, charcnt;
3133 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3134 vc = vc_cons[i].d;
3135 if (vc && vc->vc_mode == KD_TEXT &&
3136 info->node == con2fb_map[i]) {
3137 p = &fb_display[i];
3138 caps->x |= 1 << (vc->vc_font.width - 1);
3139 caps->y |= 1 << (vc->vc_font.height - 1);
3140 charcnt = (p->userfont) ?
3141 FNTCHARCNT(p->fontdata) : 256;
3142 if (caps->len < charcnt)
3143 caps->len = charcnt;
3146 } else {
3147 vc = vc_cons[fg_console].d;
3149 if (vc && vc->vc_mode == KD_TEXT &&
3150 info->node == con2fb_map[fg_console]) {
3151 p = &fb_display[fg_console];
3152 caps->x = 1 << (vc->vc_font.width - 1);
3153 caps->y = 1 << (vc->vc_font.height - 1);
3154 caps->len = (p->userfont) ?
3155 FNTCHARCNT(p->fontdata) : 256;
3160 static int fbcon_event_notify(struct notifier_block *self,
3161 unsigned long action, void *data)
3163 struct fb_event *event = data;
3164 struct fb_info *info = event->info;
3165 struct fb_videomode *mode;
3166 struct fb_con2fbmap *con2fb;
3167 struct fb_blit_caps *caps;
3168 int ret = 0;
3171 * ignore all events except driver registration and deregistration
3172 * if fbcon is not active
3174 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3175 action == FB_EVENT_FB_UNREGISTERED))
3176 goto done;
3178 switch(action) {
3179 case FB_EVENT_SUSPEND:
3180 fbcon_suspended(info);
3181 break;
3182 case FB_EVENT_RESUME:
3183 fbcon_resumed(info);
3184 break;
3185 case FB_EVENT_MODE_CHANGE:
3186 fbcon_modechanged(info);
3187 break;
3188 case FB_EVENT_MODE_CHANGE_ALL:
3189 fbcon_set_all_vcs(info);
3190 break;
3191 case FB_EVENT_MODE_DELETE:
3192 mode = event->data;
3193 ret = fbcon_mode_deleted(info, mode);
3194 break;
3195 case FB_EVENT_FB_UNBIND:
3196 ret = fbcon_fb_unbind(info->node);
3197 break;
3198 case FB_EVENT_FB_REGISTERED:
3199 ret = fbcon_fb_registered(info);
3200 break;
3201 case FB_EVENT_FB_UNREGISTERED:
3202 ret = fbcon_fb_unregistered(info);
3203 break;
3204 case FB_EVENT_SET_CONSOLE_MAP:
3205 con2fb = event->data;
3206 ret = set_con2fb_map(con2fb->console - 1,
3207 con2fb->framebuffer, 1);
3208 break;
3209 case FB_EVENT_GET_CONSOLE_MAP:
3210 con2fb = event->data;
3211 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3212 break;
3213 case FB_EVENT_BLANK:
3214 fbcon_fb_blanked(info, *(int *)event->data);
3215 break;
3216 case FB_EVENT_NEW_MODELIST:
3217 fbcon_new_modelist(info);
3218 break;
3219 case FB_EVENT_GET_REQ:
3220 caps = event->data;
3221 fbcon_get_requirement(info, caps);
3222 break;
3225 done:
3226 return ret;
3230 * The console `switch' structure for the frame buffer based console
3233 static const struct consw fb_con = {
3234 .owner = THIS_MODULE,
3235 .con_startup = fbcon_startup,
3236 .con_init = fbcon_init,
3237 .con_deinit = fbcon_deinit,
3238 .con_clear = fbcon_clear,
3239 .con_putc = fbcon_putc,
3240 .con_putcs = fbcon_putcs,
3241 .con_cursor = fbcon_cursor,
3242 .con_scroll = fbcon_scroll,
3243 .con_bmove = fbcon_bmove,
3244 .con_switch = fbcon_switch,
3245 .con_blank = fbcon_blank,
3246 .con_font_set = fbcon_set_font,
3247 .con_font_get = fbcon_get_font,
3248 .con_font_default = fbcon_set_def_font,
3249 .con_font_copy = fbcon_copy_font,
3250 .con_set_palette = fbcon_set_palette,
3251 .con_scrolldelta = fbcon_scrolldelta,
3252 .con_set_origin = fbcon_set_origin,
3253 .con_invert_region = fbcon_invert_region,
3254 .con_screen_pos = fbcon_screen_pos,
3255 .con_getxy = fbcon_getxy,
3256 .con_resize = fbcon_resize,
3259 static struct notifier_block fbcon_event_notifier = {
3260 .notifier_call = fbcon_event_notify,
3263 static ssize_t store_rotate(struct device *device,
3264 struct device_attribute *attr, const char *buf,
3265 size_t count)
3267 struct fb_info *info;
3268 int rotate, idx;
3269 char **last = NULL;
3271 if (fbcon_has_exited)
3272 return count;
3274 acquire_console_sem();
3275 idx = con2fb_map[fg_console];
3277 if (idx == -1 || registered_fb[idx] == NULL)
3278 goto err;
3280 info = registered_fb[idx];
3281 rotate = simple_strtoul(buf, last, 0);
3282 fbcon_rotate(info, rotate);
3283 err:
3284 release_console_sem();
3285 return count;
3288 static ssize_t store_rotate_all(struct device *device,
3289 struct device_attribute *attr,const char *buf,
3290 size_t count)
3292 struct fb_info *info;
3293 int rotate, idx;
3294 char **last = NULL;
3296 if (fbcon_has_exited)
3297 return count;
3299 acquire_console_sem();
3300 idx = con2fb_map[fg_console];
3302 if (idx == -1 || registered_fb[idx] == NULL)
3303 goto err;
3305 info = registered_fb[idx];
3306 rotate = simple_strtoul(buf, last, 0);
3307 fbcon_rotate_all(info, rotate);
3308 err:
3309 release_console_sem();
3310 return count;
3313 static ssize_t show_rotate(struct device *device,
3314 struct device_attribute *attr,char *buf)
3316 struct fb_info *info;
3317 int rotate = 0, idx;
3319 if (fbcon_has_exited)
3320 return 0;
3322 acquire_console_sem();
3323 idx = con2fb_map[fg_console];
3325 if (idx == -1 || registered_fb[idx] == NULL)
3326 goto err;
3328 info = registered_fb[idx];
3329 rotate = fbcon_get_rotate(info);
3330 err:
3331 release_console_sem();
3332 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3335 static ssize_t show_cursor_blink(struct device *device,
3336 struct device_attribute *attr, char *buf)
3338 struct fb_info *info;
3339 struct fbcon_ops *ops;
3340 int idx, blink = -1;
3342 if (fbcon_has_exited)
3343 return 0;
3345 acquire_console_sem();
3346 idx = con2fb_map[fg_console];
3348 if (idx == -1 || registered_fb[idx] == NULL)
3349 goto err;
3351 info = registered_fb[idx];
3352 ops = info->fbcon_par;
3354 if (!ops)
3355 goto err;
3357 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3358 err:
3359 release_console_sem();
3360 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3363 static ssize_t store_cursor_blink(struct device *device,
3364 struct device_attribute *attr,
3365 const char *buf, size_t count)
3367 struct fb_info *info;
3368 int blink, idx;
3369 char **last = NULL;
3371 if (fbcon_has_exited)
3372 return count;
3374 acquire_console_sem();
3375 idx = con2fb_map[fg_console];
3377 if (idx == -1 || registered_fb[idx] == NULL)
3378 goto err;
3380 info = registered_fb[idx];
3382 if (!info->fbcon_par)
3383 goto err;
3385 blink = simple_strtoul(buf, last, 0);
3387 if (blink) {
3388 fbcon_cursor_noblink = 0;
3389 fbcon_add_cursor_timer(info);
3390 } else {
3391 fbcon_cursor_noblink = 1;
3392 fbcon_del_cursor_timer(info);
3395 err:
3396 release_console_sem();
3397 return count;
3400 static struct device_attribute device_attrs[] = {
3401 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3402 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3403 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3404 store_cursor_blink),
3407 static int fbcon_init_device(void)
3409 int i, error = 0;
3411 fbcon_has_sysfs = 1;
3413 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3414 error = device_create_file(fbcon_device, &device_attrs[i]);
3416 if (error)
3417 break;
3420 if (error) {
3421 while (--i >= 0)
3422 device_remove_file(fbcon_device, &device_attrs[i]);
3424 fbcon_has_sysfs = 0;
3427 return 0;
3430 static void fbcon_start(void)
3432 if (num_registered_fb) {
3433 int i;
3435 acquire_console_sem();
3437 for (i = 0; i < FB_MAX; i++) {
3438 if (registered_fb[i] != NULL) {
3439 info_idx = i;
3440 break;
3444 release_console_sem();
3445 fbcon_takeover(0);
3449 static void fbcon_exit(void)
3451 struct fb_info *info;
3452 int i, j, mapped;
3454 if (fbcon_has_exited)
3455 return;
3457 #ifdef CONFIG_ATARI
3458 if (MACH_IS_ATARI)
3459 free_irq(IRQ_AUTO_4, fb_vbl_handler);
3460 #endif
3462 kfree((void *)softback_buf);
3463 softback_buf = 0UL;
3465 for (i = 0; i < FB_MAX; i++) {
3466 int pending;
3468 mapped = 0;
3469 info = registered_fb[i];
3471 if (info == NULL)
3472 continue;
3474 pending = cancel_work_sync(&info->queue);
3475 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3476 "no"));
3478 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3479 if (con2fb_map[j] == i)
3480 mapped = 1;
3483 if (mapped) {
3484 if (info->fbops->fb_release)
3485 info->fbops->fb_release(info, 0);
3486 module_put(info->fbops->owner);
3488 if (info->fbcon_par) {
3489 struct fbcon_ops *ops = info->fbcon_par;
3491 fbcon_del_cursor_timer(info);
3492 kfree(ops->cursor_src);
3493 kfree(info->fbcon_par);
3494 info->fbcon_par = NULL;
3497 if (info->queue.func == fb_flashcursor)
3498 info->queue.func = NULL;
3502 fbcon_has_exited = 1;
3505 static int __init fb_console_init(void)
3507 int i;
3509 acquire_console_sem();
3510 fb_register_client(&fbcon_event_notifier);
3511 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3512 "fbcon");
3514 if (IS_ERR(fbcon_device)) {
3515 printk(KERN_WARNING "Unable to create device "
3516 "for fbcon; errno = %ld\n",
3517 PTR_ERR(fbcon_device));
3518 fbcon_device = NULL;
3519 } else
3520 fbcon_init_device();
3522 for (i = 0; i < MAX_NR_CONSOLES; i++)
3523 con2fb_map[i] = -1;
3525 release_console_sem();
3526 fbcon_start();
3527 return 0;
3530 module_init(fb_console_init);
3532 #ifdef MODULE
3534 static void __exit fbcon_deinit_device(void)
3536 int i;
3538 if (fbcon_has_sysfs) {
3539 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3540 device_remove_file(fbcon_device, &device_attrs[i]);
3542 fbcon_has_sysfs = 0;
3546 static void __exit fb_console_exit(void)
3548 acquire_console_sem();
3549 fb_unregister_client(&fbcon_event_notifier);
3550 fbcon_deinit_device();
3551 device_destroy(fb_class, MKDEV(0, 0));
3552 fbcon_exit();
3553 release_console_sem();
3554 unregister_con_driver(&fb_con);
3557 module_exit(fb_console_exit);
3559 #endif
3561 MODULE_LICENSE("GPL");