]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/video/console/fbcon.c
[PATCH] fbcon: Console Rotation - Add support for 90-degree console rotation
[mirror_ubuntu-zesty-kernel.git] / drivers / video / console / fbcon.c
1 /*
2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
3 *
4 * Copyright (C) 1995 Geert Uytterhoeven
5 *
6 *
7 * This file is based on the original Amiga console driver (amicon.c):
8 *
9 * Copyright (C) 1993 Hamish Macdonald
10 * Greg Harp
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
12 *
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
14 * Geert Uytterhoeven
15 * Jes Sorensen (jds@kom.auc.dk)
16 * Martin Apel
17 *
18 * and on the original Atari console driver (atacon.c):
19 *
20 * Copyright (C) 1993 Bjoern Brauel
21 * Roman Hodek
22 *
23 * with work by Guenther Kelleter
24 * Martin Schaller
25 * Andreas Schwab
26 *
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)
31 *
32 * Random hacking by Martin Mares <mj@ucw.cz>
33 *
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
36 *
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
39 *
40 * Currently the following organizations are supported:
41 *
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
48 *
49 * To do:
50 *
51 * - Implement 16 plane mode (iplan2p16)
52 *
53 *
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.
57 */
58
59 #undef FBCONDEBUG
60
61 #include <linux/config.h>
62 #include <linux/module.h>
63 #include <linux/types.h>
64 #include <linux/sched.h>
65 #include <linux/fs.h>
66 #include <linux/kernel.h>
67 #include <linux/delay.h> /* MSch: for IRQ probe */
68 #include <linux/tty.h>
69 #include <linux/console.h>
70 #include <linux/string.h>
71 #include <linux/kd.h>
72 #include <linux/slab.h>
73 #include <linux/fb.h>
74 #include <linux/vt_kern.h>
75 #include <linux/selection.h>
76 #include <linux/font.h>
77 #include <linux/smp.h>
78 #include <linux/init.h>
79 #include <linux/interrupt.h>
80 #include <linux/crc32.h> /* For counting font checksums */
81 #include <asm/irq.h>
82 #include <asm/system.h>
83 #include <asm/uaccess.h>
84 #ifdef CONFIG_ATARI
85 #include <asm/atariints.h>
86 #endif
87 #ifdef CONFIG_MAC
88 #include <asm/macints.h>
89 #endif
90 #if defined(__mc68000__) || defined(CONFIG_APUS)
91 #include <asm/machdep.h>
92 #include <asm/setup.h>
93 #endif
94
95 #include "fbcon.h"
96
97 #ifdef FBCONDEBUG
98 # define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
99 #else
100 # define DPRINTK(fmt, args...)
101 #endif
102
103 enum {
104 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
105 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
106 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
107 };
108
109 struct display fb_display[MAX_NR_CONSOLES];
110 EXPORT_SYMBOL(fb_display);
111
112 static signed char con2fb_map[MAX_NR_CONSOLES];
113 static signed char con2fb_map_boot[MAX_NR_CONSOLES];
114 static int logo_height;
115 static int logo_lines;
116 /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
117 enums. */
118 static int logo_shown = FBCON_LOGO_CANSHOW;
119 /* Software scrollback */
120 static int fbcon_softback_size = 32768;
121 static unsigned long softback_buf, softback_curr;
122 static unsigned long softback_in;
123 static unsigned long softback_top, softback_end;
124 static int softback_lines;
125 /* console mappings */
126 static int first_fb_vc;
127 static int last_fb_vc = MAX_NR_CONSOLES - 1;
128 static int fbcon_is_default = 1;
129 /* font data */
130 static char fontname[40];
131
132 /* current fb_info */
133 static int info_idx = -1;
134
135 /* console rotation */
136 static int rotate;
137
138 static const struct consw fb_con;
139
140 #define CM_SOFTBACK (8)
141
142 #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
143
144 static void fbcon_free_font(struct display *);
145 static int fbcon_set_origin(struct vc_data *);
146
147 #define CURSOR_DRAW_DELAY (1)
148
149 /* # VBL ints between cursor state changes */
150 #define ATARI_CURSOR_BLINK_RATE (42)
151 #define MAC_CURSOR_BLINK_RATE (32)
152 #define DEFAULT_CURSOR_BLINK_RATE (20)
153
154 static int vbl_cursor_cnt;
155
156 #define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
157
158 /*
159 * Interface used by the world
160 */
161
162 static const char *fbcon_startup(void);
163 static void fbcon_init(struct vc_data *vc, int init);
164 static void fbcon_deinit(struct vc_data *vc);
165 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
166 int width);
167 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
168 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
169 int count, int ypos, int xpos);
170 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
171 static void fbcon_cursor(struct vc_data *vc, int mode);
172 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
173 int count);
174 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
175 int height, int width);
176 static int fbcon_switch(struct vc_data *vc);
177 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
178 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
179 static int fbcon_scrolldelta(struct vc_data *vc, int lines);
180
181 /*
182 * Internal routines
183 */
184 static __inline__ void ywrap_up(struct vc_data *vc, int count);
185 static __inline__ void ywrap_down(struct vc_data *vc, int count);
186 static __inline__ void ypan_up(struct vc_data *vc, int count);
187 static __inline__ void ypan_down(struct vc_data *vc, int count);
188 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 struct vc_data *vc);
192 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
193 int unit);
194 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
195 int line, int count, int dy);
196
197 #ifdef CONFIG_MAC
198 /*
199 * On the Macintoy, there may or may not be a working VBL int. We need to probe
200 */
201 static int vbl_detected;
202
203 static irqreturn_t fb_vbl_detect(int irq, void *dummy, struct pt_regs *fp)
204 {
205 vbl_detected++;
206 return IRQ_HANDLED;
207 }
208 #endif
209
210 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
211 static inline void fbcon_set_rotation(struct fb_info *info, struct display *p)
212 {
213 struct fbcon_ops *ops = info->fbcon_par;
214
215 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
216 p->con_rotate < 4)
217 ops->rotate = p->con_rotate;
218 else
219 ops->rotate = 0;
220 }
221 #else
222 static inline void fbcon_set_rotation(struct fb_info *info, struct display *p)
223 {
224 struct fbcon_ops *ops = info->fbcon_par;
225
226 ops->rotate = FB_ROTATE_UR;
227 }
228 #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
229
230 static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
231 {
232 struct fbcon_ops *ops = info->fbcon_par;
233
234 return (info->state != FBINFO_STATE_RUNNING ||
235 vc->vc_mode != KD_TEXT || ops->graphics);
236 }
237
238 static inline int get_color(struct vc_data *vc, struct fb_info *info,
239 u16 c, int is_fg)
240 {
241 int depth = fb_get_color_depth(&info->var, &info->fix);
242 int color = 0;
243
244 if (console_blanked) {
245 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
246
247 c = vc->vc_video_erase_char & charmask;
248 }
249
250 if (depth != 1)
251 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
252 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
253
254 switch (depth) {
255 case 1:
256 {
257 int col = ~(0xfff << (max(info->var.green.length,
258 max(info->var.red.length,
259 info->var.blue.length)))) & 0xff;
260
261 /* 0 or 1 */
262 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
263 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
264
265 if (console_blanked)
266 fg = bg;
267
268 color = (is_fg) ? fg : bg;
269 break;
270 }
271 case 2:
272 /*
273 * Scale down 16-colors to 4 colors. Default 4-color palette
274 * is grayscale. However, simply dividing the values by 4
275 * will not work, as colors 1, 2 and 3 will be scaled-down
276 * to zero rendering them invisible. So empirically convert
277 * colors to a sane 4-level grayscale.
278 */
279 switch (color) {
280 case 0:
281 color = 0; /* black */
282 break;
283 case 1 ... 6:
284 color = 2; /* white */
285 break;
286 case 7 ... 8:
287 color = 1; /* gray */
288 break;
289 default:
290 color = 3; /* intense white */
291 break;
292 }
293 break;
294 case 3:
295 /*
296 * Last 8 entries of default 16-color palette is a more intense
297 * version of the first 8 (i.e., same chrominance, different
298 * luminance).
299 */
300 color &= 7;
301 break;
302 }
303
304
305 return color;
306 }
307
308 static void fbcon_update_softback(struct vc_data *vc)
309 {
310 int l = fbcon_softback_size / vc->vc_size_row;
311
312 if (l > 5)
313 softback_end = softback_buf + l * vc->vc_size_row;
314 else
315 /* Smaller scrollback makes no sense, and 0 would screw
316 the operation totally */
317 softback_top = 0;
318 }
319
320 static void fb_flashcursor(void *private)
321 {
322 struct fb_info *info = private;
323 struct fbcon_ops *ops = info->fbcon_par;
324 struct display *p;
325 struct vc_data *vc = NULL;
326 int c;
327 int mode;
328
329 if (ops->currcon != -1)
330 vc = vc_cons[ops->currcon].d;
331
332 if (!vc || !CON_IS_VISIBLE(vc) ||
333 fbcon_is_inactive(vc, info) ||
334 registered_fb[con2fb_map[vc->vc_num]] != info ||
335 vc_cons[ops->currcon].d->vc_deccm != 1)
336 return;
337 acquire_console_sem();
338 p = &fb_display[vc->vc_num];
339 c = scr_readw((u16 *) vc->vc_pos);
340 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
341 CM_ERASE : CM_DRAW;
342 ops->cursor(vc, info, p, mode, softback_lines, get_color(vc, info, c, 1),
343 get_color(vc, info, c, 0));
344 release_console_sem();
345 }
346
347 #if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
348 static int cursor_blink_rate;
349 static irqreturn_t fb_vbl_handler(int irq, void *dev_id, struct pt_regs *fp)
350 {
351 struct fb_info *info = dev_id;
352
353 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
354 schedule_work(&info->queue);
355 vbl_cursor_cnt = cursor_blink_rate;
356 }
357 return IRQ_HANDLED;
358 }
359 #endif
360
361 static void cursor_timer_handler(unsigned long dev_addr)
362 {
363 struct fb_info *info = (struct fb_info *) dev_addr;
364 struct fbcon_ops *ops = info->fbcon_par;
365
366 schedule_work(&info->queue);
367 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
368 }
369
370 static void fbcon_add_cursor_timer(struct fb_info *info)
371 {
372 struct fbcon_ops *ops = info->fbcon_par;
373
374 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
375 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
376 if (!info->queue.func)
377 INIT_WORK(&info->queue, fb_flashcursor, info);
378
379 init_timer(&ops->cursor_timer);
380 ops->cursor_timer.function = cursor_timer_handler;
381 ops->cursor_timer.expires = jiffies + HZ / 5;
382 ops->cursor_timer.data = (unsigned long ) info;
383 add_timer(&ops->cursor_timer);
384 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
385 }
386 }
387
388 static void fbcon_del_cursor_timer(struct fb_info *info)
389 {
390 struct fbcon_ops *ops = info->fbcon_par;
391
392 if (info->queue.func == fb_flashcursor &&
393 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
394 del_timer_sync(&ops->cursor_timer);
395 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
396 }
397 }
398
399 #ifndef MODULE
400 static int __init fb_console_setup(char *this_opt)
401 {
402 char *options;
403 int i, j;
404
405 if (!this_opt || !*this_opt)
406 return 0;
407
408 while ((options = strsep(&this_opt, ",")) != NULL) {
409 if (!strncmp(options, "font:", 5))
410 strcpy(fontname, options + 5);
411
412 if (!strncmp(options, "scrollback:", 11)) {
413 options += 11;
414 if (*options) {
415 fbcon_softback_size = simple_strtoul(options, &options, 0);
416 if (*options == 'k' || *options == 'K') {
417 fbcon_softback_size *= 1024;
418 options++;
419 }
420 if (*options != ',')
421 return 0;
422 options++;
423 } else
424 return 0;
425 }
426
427 if (!strncmp(options, "map:", 4)) {
428 options += 4;
429 if (*options)
430 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
431 if (!options[j])
432 j = 0;
433 con2fb_map_boot[i] =
434 (options[j++]-'0') % FB_MAX;
435 }
436 return 0;
437 }
438
439 if (!strncmp(options, "vc:", 3)) {
440 options += 3;
441 if (*options)
442 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
443 if (first_fb_vc < 0)
444 first_fb_vc = 0;
445 if (*options++ == '-')
446 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
447 fbcon_is_default = 0;
448 }
449
450 if (!strncmp(options, "rotate:", 7)) {
451 options += 7;
452 if (*options)
453 rotate = simple_strtoul(options, &options, 0);
454 if (rotate > 3)
455 rotate = 0;
456 }
457 }
458 return 0;
459 }
460
461 __setup("fbcon=", fb_console_setup);
462 #endif
463
464 static int search_fb_in_map(int idx)
465 {
466 int i, retval = 0;
467
468 for (i = 0; i < MAX_NR_CONSOLES; i++) {
469 if (con2fb_map[i] == idx)
470 retval = 1;
471 }
472 return retval;
473 }
474
475 static int search_for_mapped_con(void)
476 {
477 int i, retval = 0;
478
479 for (i = 0; i < MAX_NR_CONSOLES; i++) {
480 if (con2fb_map[i] != -1)
481 retval = 1;
482 }
483 return retval;
484 }
485
486 static int fbcon_takeover(int show_logo)
487 {
488 int err, i;
489
490 if (!num_registered_fb)
491 return -ENODEV;
492
493 if (!show_logo)
494 logo_shown = FBCON_LOGO_DONTSHOW;
495
496 for (i = first_fb_vc; i <= last_fb_vc; i++)
497 con2fb_map[i] = info_idx;
498
499 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
500 fbcon_is_default);
501 if (err) {
502 for (i = first_fb_vc; i <= last_fb_vc; i++) {
503 con2fb_map[i] = -1;
504 }
505 info_idx = -1;
506 }
507
508 return err;
509 }
510
511 static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
512 int cols, int rows, int new_cols, int new_rows)
513 {
514 /* Need to make room for the logo */
515 struct fbcon_ops *ops = info->fbcon_par;
516 int cnt, erase = vc->vc_video_erase_char, step;
517 unsigned short *save = NULL, *r, *q;
518
519 /*
520 * remove underline attribute from erase character
521 * if black and white framebuffer.
522 */
523 if (fb_get_color_depth(&info->var, &info->fix) == 1)
524 erase &= ~0x400;
525 logo_height = fb_prepare_logo(info, ops->rotate);
526 logo_lines = (logo_height + vc->vc_font.height - 1) /
527 vc->vc_font.height;
528 q = (unsigned short *) (vc->vc_origin +
529 vc->vc_size_row * rows);
530 step = logo_lines * cols;
531 for (r = q - logo_lines * cols; r < q; r++)
532 if (scr_readw(r) != vc->vc_video_erase_char)
533 break;
534 if (r != q && new_rows >= rows + logo_lines) {
535 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
536 if (save) {
537 int i = cols < new_cols ? cols : new_cols;
538 scr_memsetw(save, erase, logo_lines * new_cols * 2);
539 r = q - step;
540 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
541 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
542 r = q;
543 }
544 }
545 if (r == q) {
546 /* We can scroll screen down */
547 r = q - step - cols;
548 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
549 scr_memcpyw(r + step, r, vc->vc_size_row);
550 r -= cols;
551 }
552 if (!save) {
553 vc->vc_y += logo_lines;
554 vc->vc_pos += logo_lines * vc->vc_size_row;
555 }
556 }
557 scr_memsetw((unsigned short *) vc->vc_origin,
558 erase,
559 vc->vc_size_row * logo_lines);
560
561 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
562 fbcon_clear_margins(vc, 0);
563 update_screen(vc);
564 }
565
566 if (save) {
567 q = (unsigned short *) (vc->vc_origin +
568 vc->vc_size_row *
569 rows);
570 scr_memcpyw(q, save, logo_lines * new_cols * 2);
571 vc->vc_y += logo_lines;
572 vc->vc_pos += logo_lines * vc->vc_size_row;
573 kfree(save);
574 }
575
576 if (logo_lines > vc->vc_bottom) {
577 logo_shown = FBCON_LOGO_CANSHOW;
578 printk(KERN_INFO
579 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
580 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
581 logo_shown = FBCON_LOGO_DRAW;
582 vc->vc_top = logo_lines;
583 }
584 }
585
586 #ifdef CONFIG_FB_TILEBLITTING
587 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
588 struct display *p)
589 {
590 struct fbcon_ops *ops = info->fbcon_par;
591
592 if ((info->flags & FBINFO_MISC_TILEBLITTING))
593 fbcon_set_tileops(vc, info, p, ops);
594 else {
595 struct display *disp;
596
597 disp = (p) ? p : &fb_display[vc->vc_num];
598 fbcon_set_rotation(info, disp);
599 fbcon_set_bitops(ops);
600 }
601 }
602 #else
603 static void set_blitting_type(struct vc_data *vc, struct fb_info *info,
604 struct display *p)
605 {
606 struct fbcon_ops *ops = info->fbcon_par;
607 struct display *disp;
608
609 info->flags &= ~FBINFO_MISC_TILEBLITTING;
610 disp = (p) ? p : &fb_display[vc->vc_num];
611 fbcon_set_rotation(info, disp);
612 fbcon_set_bitops(ops);
613 }
614 #endif /* CONFIG_MISC_TILEBLITTING */
615
616
617 static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
618 int unit, int oldidx)
619 {
620 struct fbcon_ops *ops = NULL;
621 int err = 0;
622
623 if (!try_module_get(info->fbops->owner))
624 err = -ENODEV;
625
626 if (!err && info->fbops->fb_open &&
627 info->fbops->fb_open(info, 0))
628 err = -ENODEV;
629
630 if (!err) {
631 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
632 if (!ops)
633 err = -ENOMEM;
634 }
635
636 if (!err) {
637 memset(ops, 0, sizeof(struct fbcon_ops));
638 info->fbcon_par = ops;
639 set_blitting_type(vc, info, NULL);
640 }
641
642 if (err) {
643 con2fb_map[unit] = oldidx;
644 module_put(info->fbops->owner);
645 }
646
647 return err;
648 }
649
650 static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
651 struct fb_info *newinfo, int unit,
652 int oldidx, int found)
653 {
654 struct fbcon_ops *ops = oldinfo->fbcon_par;
655 int err = 0;
656
657 if (oldinfo->fbops->fb_release &&
658 oldinfo->fbops->fb_release(oldinfo, 0)) {
659 con2fb_map[unit] = oldidx;
660 if (!found && newinfo->fbops->fb_release)
661 newinfo->fbops->fb_release(newinfo, 0);
662 if (!found)
663 module_put(newinfo->fbops->owner);
664 err = -ENODEV;
665 }
666
667 if (!err) {
668 fbcon_del_cursor_timer(oldinfo);
669 kfree(ops->cursor_state.mask);
670 kfree(ops->cursor_data);
671 kfree(ops->fontbuffer);
672 kfree(oldinfo->fbcon_par);
673 oldinfo->fbcon_par = NULL;
674 module_put(oldinfo->fbops->owner);
675 /*
676 If oldinfo and newinfo are driving the same hardware,
677 the fb_release() method of oldinfo may attempt to
678 restore the hardware state. This will leave the
679 newinfo in an undefined state. Thus, a call to
680 fb_set_par() may be needed for the newinfo.
681 */
682 if (newinfo->fbops->fb_set_par)
683 newinfo->fbops->fb_set_par(newinfo);
684 }
685
686 return err;
687 }
688
689 static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
690 int unit, int show_logo)
691 {
692 struct fbcon_ops *ops = info->fbcon_par;
693
694 ops->currcon = fg_console;
695
696 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
697 info->fbops->fb_set_par(info);
698
699 ops->flags |= FBCON_FLAGS_INIT;
700 ops->graphics = 0;
701
702 if (vc)
703 fbcon_set_disp(info, &info->var, vc);
704 else
705 fbcon_preset_disp(info, &info->var, unit);
706
707 if (show_logo) {
708 struct vc_data *fg_vc = vc_cons[fg_console].d;
709 struct fb_info *fg_info =
710 registered_fb[con2fb_map[fg_console]];
711
712 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
713 fg_vc->vc_rows, fg_vc->vc_cols,
714 fg_vc->vc_rows);
715 }
716
717 update_screen(vc_cons[fg_console].d);
718 }
719
720 /**
721 * set_con2fb_map - map console to frame buffer device
722 * @unit: virtual console number to map
723 * @newidx: frame buffer index to map virtual console to
724 * @user: user request
725 *
726 * Maps a virtual console @unit to a frame buffer device
727 * @newidx.
728 */
729 static int set_con2fb_map(int unit, int newidx, int user)
730 {
731 struct vc_data *vc = vc_cons[unit].d;
732 int oldidx = con2fb_map[unit];
733 struct fb_info *info = registered_fb[newidx];
734 struct fb_info *oldinfo = NULL;
735 int found, err = 0;
736
737 if (oldidx == newidx)
738 return 0;
739
740 if (!info)
741 err = -EINVAL;
742
743 if (!err && !search_for_mapped_con()) {
744 info_idx = newidx;
745 return fbcon_takeover(0);
746 }
747
748 if (oldidx != -1)
749 oldinfo = registered_fb[oldidx];
750
751 found = search_fb_in_map(newidx);
752
753 acquire_console_sem();
754 con2fb_map[unit] = newidx;
755 if (!err && !found)
756 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
757
758
759 /*
760 * If old fb is not mapped to any of the consoles,
761 * fbcon should release it.
762 */
763 if (!err && oldinfo && !search_fb_in_map(oldidx))
764 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
765 found);
766
767 if (!err) {
768 int show_logo = (fg_console == 0 && !user &&
769 logo_shown != FBCON_LOGO_DONTSHOW);
770
771 if (!found)
772 fbcon_add_cursor_timer(info);
773 con2fb_map_boot[unit] = newidx;
774 con2fb_init_display(vc, info, unit, show_logo);
775 }
776
777 release_console_sem();
778 return err;
779 }
780
781 /*
782 * Low Level Operations
783 */
784 /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
785 static int var_to_display(struct display *disp,
786 struct fb_var_screeninfo *var,
787 struct fb_info *info)
788 {
789 disp->xres_virtual = var->xres_virtual;
790 disp->yres_virtual = var->yres_virtual;
791 disp->bits_per_pixel = var->bits_per_pixel;
792 disp->grayscale = var->grayscale;
793 disp->nonstd = var->nonstd;
794 disp->accel_flags = var->accel_flags;
795 disp->height = var->height;
796 disp->width = var->width;
797 disp->red = var->red;
798 disp->green = var->green;
799 disp->blue = var->blue;
800 disp->transp = var->transp;
801 disp->rotate = var->rotate;
802 disp->mode = fb_match_mode(var, &info->modelist);
803 if (disp->mode == NULL)
804 /* This should not happen */
805 return -EINVAL;
806 return 0;
807 }
808
809 static void display_to_var(struct fb_var_screeninfo *var,
810 struct display *disp)
811 {
812 fb_videomode_to_var(var, disp->mode);
813 var->xres_virtual = disp->xres_virtual;
814 var->yres_virtual = disp->yres_virtual;
815 var->bits_per_pixel = disp->bits_per_pixel;
816 var->grayscale = disp->grayscale;
817 var->nonstd = disp->nonstd;
818 var->accel_flags = disp->accel_flags;
819 var->height = disp->height;
820 var->width = disp->width;
821 var->red = disp->red;
822 var->green = disp->green;
823 var->blue = disp->blue;
824 var->transp = disp->transp;
825 var->rotate = disp->rotate;
826 }
827
828 static const char *fbcon_startup(void)
829 {
830 const char *display_desc = "frame buffer device";
831 struct display *p = &fb_display[fg_console];
832 struct vc_data *vc = vc_cons[fg_console].d;
833 const struct font_desc *font = NULL;
834 struct module *owner;
835 struct fb_info *info = NULL;
836 struct fbcon_ops *ops;
837 int rows, cols;
838 int irqres;
839
840 irqres = 1;
841 /*
842 * If num_registered_fb is zero, this is a call for the dummy part.
843 * The frame buffer devices weren't initialized yet.
844 */
845 if (!num_registered_fb || info_idx == -1)
846 return display_desc;
847 /*
848 * Instead of blindly using registered_fb[0], we use info_idx, set by
849 * fb_console_init();
850 */
851 info = registered_fb[info_idx];
852 if (!info)
853 return NULL;
854
855 owner = info->fbops->owner;
856 if (!try_module_get(owner))
857 return NULL;
858 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
859 module_put(owner);
860 return NULL;
861 }
862
863 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
864 if (!ops) {
865 module_put(owner);
866 return NULL;
867 }
868
869 memset(ops, 0, sizeof(struct fbcon_ops));
870 ops->currcon = -1;
871 ops->graphics = 1;
872 ops->cur_rotate = -1;
873 info->fbcon_par = ops;
874 p->con_rotate = rotate;
875 set_blitting_type(vc, info, NULL);
876
877 if (info->fix.type != FB_TYPE_TEXT) {
878 if (fbcon_softback_size) {
879 if (!softback_buf) {
880 softback_buf =
881 (unsigned long)
882 kmalloc(fbcon_softback_size,
883 GFP_KERNEL);
884 if (!softback_buf) {
885 fbcon_softback_size = 0;
886 softback_top = 0;
887 }
888 }
889 } else {
890 if (softback_buf) {
891 kfree((void *) softback_buf);
892 softback_buf = 0;
893 softback_top = 0;
894 }
895 }
896 if (softback_buf)
897 softback_in = softback_top = softback_curr =
898 softback_buf;
899 softback_lines = 0;
900 }
901
902 /* Setup default font */
903 if (!p->fontdata) {
904 if (!fontname[0] || !(font = find_font(fontname)))
905 font = get_default_font(info->var.xres,
906 info->var.yres);
907 vc->vc_font.width = font->width;
908 vc->vc_font.height = font->height;
909 vc->vc_font.data = (void *)(p->fontdata = font->data);
910 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
911 }
912
913 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
914 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
915 cols /= vc->vc_font.width;
916 rows /= vc->vc_font.height;
917 vc_resize(vc, cols, rows);
918
919 DPRINTK("mode: %s\n", info->fix.id);
920 DPRINTK("visual: %d\n", info->fix.visual);
921 DPRINTK("res: %dx%d-%d\n", info->var.xres,
922 info->var.yres,
923 info->var.bits_per_pixel);
924
925 #ifdef CONFIG_ATARI
926 if (MACH_IS_ATARI) {
927 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
928 irqres =
929 request_irq(IRQ_AUTO_4, fb_vbl_handler,
930 IRQ_TYPE_PRIO, "framebuffer vbl",
931 info);
932 }
933 #endif /* CONFIG_ATARI */
934
935 #ifdef CONFIG_MAC
936 /*
937 * On a Macintoy, the VBL interrupt may or may not be active.
938 * As interrupt based cursor is more reliable and race free, we
939 * probe for VBL interrupts.
940 */
941 if (MACH_IS_MAC) {
942 int ct = 0;
943 /*
944 * Probe for VBL: set temp. handler ...
945 */
946 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
947 "framebuffer vbl", info);
948 vbl_detected = 0;
949
950 /*
951 * ... and spin for 20 ms ...
952 */
953 while (!vbl_detected && ++ct < 1000)
954 udelay(20);
955
956 if (ct == 1000)
957 printk
958 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
959
960 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
961
962 if (vbl_detected) {
963 /*
964 * interrupt based cursor ok
965 */
966 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
967 irqres =
968 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
969 "framebuffer vbl", info);
970 } else {
971 /*
972 * VBL not detected: fall through, use timer based cursor
973 */
974 irqres = 1;
975 }
976 }
977 #endif /* CONFIG_MAC */
978
979 fbcon_add_cursor_timer(info);
980 return display_desc;
981 }
982
983 static void fbcon_init(struct vc_data *vc, int init)
984 {
985 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
986 struct fbcon_ops *ops;
987 struct vc_data **default_mode = vc->vc_display_fg;
988 struct vc_data *svc = *default_mode;
989 struct display *t, *p = &fb_display[vc->vc_num];
990 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
991 int cap;
992
993 if (info_idx == -1 || info == NULL)
994 return;
995
996 cap = info->flags;
997
998 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
999 (info->fix.type == FB_TYPE_TEXT))
1000 logo = 0;
1001
1002 if (var_to_display(p, &info->var, info))
1003 return;
1004
1005 /* If we are not the first console on this
1006 fb, copy the font from that console */
1007 t = &fb_display[svc->vc_num];
1008 if (!vc->vc_font.data) {
1009 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1010 vc->vc_font.width = (*default_mode)->vc_font.width;
1011 vc->vc_font.height = (*default_mode)->vc_font.height;
1012 p->userfont = t->userfont;
1013 if (p->userfont)
1014 REFCOUNT(p->fontdata)++;
1015 }
1016 if (p->userfont)
1017 charcnt = FNTCHARCNT(p->fontdata);
1018 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1019 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1020 if (charcnt == 256) {
1021 vc->vc_hi_font_mask = 0;
1022 } else {
1023 vc->vc_hi_font_mask = 0x100;
1024 if (vc->vc_can_do_color)
1025 vc->vc_complement_mask <<= 1;
1026 }
1027
1028 if (!*svc->vc_uni_pagedir_loc)
1029 con_set_default_unimap(svc);
1030 if (!*vc->vc_uni_pagedir_loc)
1031 con_copy_unimap(vc, svc);
1032
1033 ops = info->fbcon_par;
1034 p->con_rotate = rotate;
1035 set_blitting_type(vc, info, NULL);
1036
1037 cols = vc->vc_cols;
1038 rows = vc->vc_rows;
1039 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1040 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1041 new_cols /= vc->vc_font.width;
1042 new_rows /= vc->vc_font.height;
1043 vc_resize(vc, new_cols, new_rows);
1044
1045 /*
1046 * We must always set the mode. The mode of the previous console
1047 * driver could be in the same resolution but we are using different
1048 * hardware so we have to initialize the hardware.
1049 *
1050 * We need to do it in fbcon_init() to prevent screen corruption.
1051 */
1052 if (CON_IS_VISIBLE(vc)) {
1053 if (info->fbops->fb_set_par &&
1054 !(ops->flags & FBCON_FLAGS_INIT))
1055 info->fbops->fb_set_par(info);
1056 ops->flags |= FBCON_FLAGS_INIT;
1057 }
1058
1059 ops->graphics = 0;
1060
1061 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1062 !(cap & FBINFO_HWACCEL_DISABLED))
1063 p->scrollmode = SCROLL_MOVE;
1064 else /* default to something safe */
1065 p->scrollmode = SCROLL_REDRAW;
1066
1067 /*
1068 * ++guenther: console.c:vc_allocate() relies on initializing
1069 * vc_{cols,rows}, but we must not set those if we are only
1070 * resizing the console.
1071 */
1072 if (!init) {
1073 vc->vc_cols = new_cols;
1074 vc->vc_rows = new_rows;
1075 }
1076
1077 if (logo)
1078 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1079
1080 if (vc == svc && softback_buf)
1081 fbcon_update_softback(vc);
1082
1083 if (ops->rotate_font && ops->rotate_font(info, vc, p)) {
1084 ops->rotate = FB_ROTATE_UR;
1085 set_blitting_type(vc, info, p);
1086 }
1087
1088 }
1089
1090 static void fbcon_deinit(struct vc_data *vc)
1091 {
1092 struct display *p = &fb_display[vc->vc_num];
1093
1094 if (info_idx != -1)
1095 return;
1096 fbcon_free_font(p);
1097 }
1098
1099 /* ====================================================================== */
1100
1101 /* fbcon_XXX routines - interface used by the world
1102 *
1103 * This system is now divided into two levels because of complications
1104 * caused by hardware scrolling. Top level functions:
1105 *
1106 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1107 *
1108 * handles y values in range [0, scr_height-1] that correspond to real
1109 * screen positions. y_wrap shift means that first line of bitmap may be
1110 * anywhere on this display. These functions convert lineoffsets to
1111 * bitmap offsets and deal with the wrap-around case by splitting blits.
1112 *
1113 * fbcon_bmove_physical_8() -- These functions fast implementations
1114 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1115 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1116 *
1117 * WARNING:
1118 *
1119 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1120 * Implies should only really hardware scroll in rows. Only reason for
1121 * restriction is simplicity & efficiency at the moment.
1122 */
1123
1124 static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1125 int width)
1126 {
1127 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1128 struct fbcon_ops *ops = info->fbcon_par;
1129
1130 struct display *p = &fb_display[vc->vc_num];
1131 u_int y_break;
1132
1133 if (fbcon_is_inactive(vc, info))
1134 return;
1135
1136 if (!height || !width)
1137 return;
1138
1139 /* Split blits that cross physical y_wrap boundary */
1140
1141 y_break = p->vrows - p->yscroll;
1142 if (sy < y_break && sy + height - 1 >= y_break) {
1143 u_int b = y_break - sy;
1144 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1145 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1146 width);
1147 } else
1148 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1149 }
1150
1151 static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1152 int count, int ypos, int xpos)
1153 {
1154 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1155 struct display *p = &fb_display[vc->vc_num];
1156 struct fbcon_ops *ops = info->fbcon_par;
1157
1158 if (!fbcon_is_inactive(vc, info))
1159 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1160 get_color(vc, info, scr_readw(s), 1),
1161 get_color(vc, info, scr_readw(s), 0));
1162 }
1163
1164 static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1165 {
1166 unsigned short chr;
1167
1168 scr_writew(c, &chr);
1169 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1170 }
1171
1172 static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1173 {
1174 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1175 struct fbcon_ops *ops = info->fbcon_par;
1176
1177 if (!fbcon_is_inactive(vc, info))
1178 ops->clear_margins(vc, info, bottom_only);
1179 }
1180
1181 static void fbcon_cursor(struct vc_data *vc, int mode)
1182 {
1183 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1184 struct fbcon_ops *ops = info->fbcon_par;
1185 struct display *p = &fb_display[vc->vc_num];
1186 int y;
1187 int c = scr_readw((u16 *) vc->vc_pos);
1188
1189 if (fbcon_is_inactive(vc, info))
1190 return;
1191
1192 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1193 if (mode & CM_SOFTBACK) {
1194 mode &= ~CM_SOFTBACK;
1195 y = softback_lines;
1196 } else {
1197 if (softback_lines)
1198 fbcon_set_origin(vc);
1199 y = 0;
1200 }
1201
1202 ops->cursor(vc, info, p, mode, y, get_color(vc, info, c, 1),
1203 get_color(vc, info, c, 0));
1204 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1205 }
1206
1207 static int scrollback_phys_max = 0;
1208 static int scrollback_max = 0;
1209 static int scrollback_current = 0;
1210
1211 /*
1212 * If no vc is existent yet, just set struct display
1213 */
1214 static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1215 int unit)
1216 {
1217 struct display *p = &fb_display[unit];
1218 struct display *t = &fb_display[fg_console];
1219
1220 if (var_to_display(p, var, info))
1221 return;
1222
1223 p->fontdata = t->fontdata;
1224 p->userfont = t->userfont;
1225 if (p->userfont)
1226 REFCOUNT(p->fontdata)++;
1227 }
1228
1229 static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1230 struct vc_data *vc)
1231 {
1232 struct display *p = &fb_display[vc->vc_num], *t;
1233 struct vc_data **default_mode = vc->vc_display_fg;
1234 struct vc_data *svc = *default_mode;
1235 struct fbcon_ops *ops = info->fbcon_par;
1236 int rows, cols, charcnt = 256;
1237
1238 if (var_to_display(p, var, info))
1239 return;
1240 t = &fb_display[svc->vc_num];
1241 if (!vc->vc_font.data) {
1242 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1243 vc->vc_font.width = (*default_mode)->vc_font.width;
1244 vc->vc_font.height = (*default_mode)->vc_font.height;
1245 p->userfont = t->userfont;
1246 if (p->userfont)
1247 REFCOUNT(p->fontdata)++;
1248 }
1249 if (p->userfont)
1250 charcnt = FNTCHARCNT(p->fontdata);
1251
1252 var->activate = FB_ACTIVATE_NOW;
1253 info->var.activate = var->activate;
1254 var->yoffset = info->var.yoffset;
1255 var->xoffset = info->var.xoffset;
1256 fb_set_var(info, var);
1257 ops->var = info->var;
1258 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1259 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1260 if (charcnt == 256) {
1261 vc->vc_hi_font_mask = 0;
1262 } else {
1263 vc->vc_hi_font_mask = 0x100;
1264 if (vc->vc_can_do_color)
1265 vc->vc_complement_mask <<= 1;
1266 }
1267
1268 if (!*svc->vc_uni_pagedir_loc)
1269 con_set_default_unimap(svc);
1270 if (!*vc->vc_uni_pagedir_loc)
1271 con_copy_unimap(vc, svc);
1272
1273 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1274 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1275 cols /= vc->vc_font.width;
1276 rows /= vc->vc_font.height;
1277 vc_resize(vc, cols, rows);
1278
1279 if (CON_IS_VISIBLE(vc)) {
1280 update_screen(vc);
1281 if (softback_buf)
1282 fbcon_update_softback(vc);
1283 }
1284 }
1285
1286 static __inline__ void ywrap_up(struct vc_data *vc, int count)
1287 {
1288 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1289 struct fbcon_ops *ops = info->fbcon_par;
1290 struct display *p = &fb_display[vc->vc_num];
1291
1292 p->yscroll += count;
1293 if (p->yscroll >= p->vrows) /* Deal with wrap */
1294 p->yscroll -= p->vrows;
1295 ops->var.xoffset = 0;
1296 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1297 ops->var.vmode |= FB_VMODE_YWRAP;
1298 ops->update_start(info);
1299 scrollback_max += count;
1300 if (scrollback_max > scrollback_phys_max)
1301 scrollback_max = scrollback_phys_max;
1302 scrollback_current = 0;
1303 }
1304
1305 static __inline__ void ywrap_down(struct vc_data *vc, int count)
1306 {
1307 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1308 struct fbcon_ops *ops = info->fbcon_par;
1309 struct display *p = &fb_display[vc->vc_num];
1310
1311 p->yscroll -= count;
1312 if (p->yscroll < 0) /* Deal with wrap */
1313 p->yscroll += p->vrows;
1314 ops->var.xoffset = 0;
1315 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1316 ops->var.vmode |= FB_VMODE_YWRAP;
1317 ops->update_start(info);
1318 scrollback_max -= count;
1319 if (scrollback_max < 0)
1320 scrollback_max = 0;
1321 scrollback_current = 0;
1322 }
1323
1324 static __inline__ void ypan_up(struct vc_data *vc, int count)
1325 {
1326 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1327 struct display *p = &fb_display[vc->vc_num];
1328 struct fbcon_ops *ops = info->fbcon_par;
1329
1330 p->yscroll += count;
1331 if (p->yscroll > p->vrows - vc->vc_rows) {
1332 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1333 0, 0, 0, vc->vc_rows, vc->vc_cols);
1334 p->yscroll -= p->vrows - vc->vc_rows;
1335 }
1336
1337 ops->var.xoffset = 0;
1338 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1339 ops->var.vmode &= ~FB_VMODE_YWRAP;
1340 ops->update_start(info);
1341 fbcon_clear_margins(vc, 1);
1342 scrollback_max += count;
1343 if (scrollback_max > scrollback_phys_max)
1344 scrollback_max = scrollback_phys_max;
1345 scrollback_current = 0;
1346 }
1347
1348 static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1349 {
1350 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1351 struct fbcon_ops *ops = info->fbcon_par;
1352 struct display *p = &fb_display[vc->vc_num];
1353 int redraw = 0;
1354
1355 p->yscroll += count;
1356 if (p->yscroll > p->vrows - vc->vc_rows) {
1357 p->yscroll -= p->vrows - vc->vc_rows;
1358 redraw = 1;
1359 }
1360
1361 if (redraw)
1362 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
1363
1364 ops->var.xoffset = 0;
1365 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1366 ops->var.vmode &= ~FB_VMODE_YWRAP;
1367 ops->update_start(info);
1368 fbcon_clear_margins(vc, 1);
1369 scrollback_max += count;
1370 if (scrollback_max > scrollback_phys_max)
1371 scrollback_max = scrollback_phys_max;
1372 scrollback_current = 0;
1373 }
1374
1375 static __inline__ void ypan_down(struct vc_data *vc, int count)
1376 {
1377 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1378 struct display *p = &fb_display[vc->vc_num];
1379 struct fbcon_ops *ops = info->fbcon_par;
1380
1381 p->yscroll -= count;
1382 if (p->yscroll < 0) {
1383 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1384 0, vc->vc_rows, vc->vc_cols);
1385 p->yscroll += p->vrows - vc->vc_rows;
1386 }
1387
1388 ops->var.xoffset = 0;
1389 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1390 ops->var.vmode &= ~FB_VMODE_YWRAP;
1391 ops->update_start(info);
1392 fbcon_clear_margins(vc, 1);
1393 scrollback_max -= count;
1394 if (scrollback_max < 0)
1395 scrollback_max = 0;
1396 scrollback_current = 0;
1397 }
1398
1399 static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1400 {
1401 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1402 struct fbcon_ops *ops = info->fbcon_par;
1403 struct display *p = &fb_display[vc->vc_num];
1404 int redraw = 0;
1405
1406 p->yscroll -= count;
1407 if (p->yscroll < 0) {
1408 p->yscroll += p->vrows - vc->vc_rows;
1409 redraw = 1;
1410 }
1411
1412 if (redraw)
1413 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
1414
1415 ops->var.xoffset = 0;
1416 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1417 ops->var.vmode &= ~FB_VMODE_YWRAP;
1418 ops->update_start(info);
1419 fbcon_clear_margins(vc, 1);
1420 scrollback_max -= count;
1421 if (scrollback_max < 0)
1422 scrollback_max = 0;
1423 scrollback_current = 0;
1424 }
1425
1426 static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1427 long delta)
1428 {
1429 int count = vc->vc_rows;
1430 unsigned short *d, *s;
1431 unsigned long n;
1432 int line = 0;
1433
1434 d = (u16 *) softback_curr;
1435 if (d == (u16 *) softback_in)
1436 d = (u16 *) vc->vc_origin;
1437 n = softback_curr + delta * vc->vc_size_row;
1438 softback_lines -= delta;
1439 if (delta < 0) {
1440 if (softback_curr < softback_top && n < softback_buf) {
1441 n += softback_end - softback_buf;
1442 if (n < softback_top) {
1443 softback_lines -=
1444 (softback_top - n) / vc->vc_size_row;
1445 n = softback_top;
1446 }
1447 } else if (softback_curr >= softback_top
1448 && n < softback_top) {
1449 softback_lines -=
1450 (softback_top - n) / vc->vc_size_row;
1451 n = softback_top;
1452 }
1453 } else {
1454 if (softback_curr > softback_in && n >= softback_end) {
1455 n += softback_buf - softback_end;
1456 if (n > softback_in) {
1457 n = softback_in;
1458 softback_lines = 0;
1459 }
1460 } else if (softback_curr <= softback_in && n > softback_in) {
1461 n = softback_in;
1462 softback_lines = 0;
1463 }
1464 }
1465 if (n == softback_curr)
1466 return;
1467 softback_curr = n;
1468 s = (u16 *) softback_curr;
1469 if (s == (u16 *) softback_in)
1470 s = (u16 *) vc->vc_origin;
1471 while (count--) {
1472 unsigned short *start;
1473 unsigned short *le;
1474 unsigned short c;
1475 int x = 0;
1476 unsigned short attr = 1;
1477
1478 start = s;
1479 le = advance_row(s, 1);
1480 do {
1481 c = scr_readw(s);
1482 if (attr != (c & 0xff00)) {
1483 attr = c & 0xff00;
1484 if (s > start) {
1485 fbcon_putcs(vc, start, s - start,
1486 line, x);
1487 x += s - start;
1488 start = s;
1489 }
1490 }
1491 if (c == scr_readw(d)) {
1492 if (s > start) {
1493 fbcon_putcs(vc, start, s - start,
1494 line, x);
1495 x += s - start + 1;
1496 start = s + 1;
1497 } else {
1498 x++;
1499 start++;
1500 }
1501 }
1502 s++;
1503 d++;
1504 } while (s < le);
1505 if (s > start)
1506 fbcon_putcs(vc, start, s - start, line, x);
1507 line++;
1508 if (d == (u16 *) softback_end)
1509 d = (u16 *) softback_buf;
1510 if (d == (u16 *) softback_in)
1511 d = (u16 *) vc->vc_origin;
1512 if (s == (u16 *) softback_end)
1513 s = (u16 *) softback_buf;
1514 if (s == (u16 *) softback_in)
1515 s = (u16 *) vc->vc_origin;
1516 }
1517 }
1518
1519 static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1520 int line, int count, int dy)
1521 {
1522 unsigned short *s = (unsigned short *)
1523 (vc->vc_origin + vc->vc_size_row * line);
1524
1525 while (count--) {
1526 unsigned short *start = s;
1527 unsigned short *le = advance_row(s, 1);
1528 unsigned short c;
1529 int x = 0;
1530 unsigned short attr = 1;
1531
1532 do {
1533 c = scr_readw(s);
1534 if (attr != (c & 0xff00)) {
1535 attr = c & 0xff00;
1536 if (s > start) {
1537 fbcon_putcs(vc, start, s - start,
1538 dy, x);
1539 x += s - start;
1540 start = s;
1541 }
1542 }
1543 console_conditional_schedule();
1544 s++;
1545 } while (s < le);
1546 if (s > start)
1547 fbcon_putcs(vc, start, s - start, dy, x);
1548 console_conditional_schedule();
1549 dy++;
1550 }
1551 }
1552
1553 static void fbcon_redraw(struct vc_data *vc, struct display *p,
1554 int line, int count, int offset)
1555 {
1556 unsigned short *d = (unsigned short *)
1557 (vc->vc_origin + vc->vc_size_row * line);
1558 unsigned short *s = d + offset;
1559
1560 while (count--) {
1561 unsigned short *start = s;
1562 unsigned short *le = advance_row(s, 1);
1563 unsigned short c;
1564 int x = 0;
1565 unsigned short attr = 1;
1566
1567 do {
1568 c = scr_readw(s);
1569 if (attr != (c & 0xff00)) {
1570 attr = c & 0xff00;
1571 if (s > start) {
1572 fbcon_putcs(vc, start, s - start,
1573 line, x);
1574 x += s - start;
1575 start = s;
1576 }
1577 }
1578 if (c == scr_readw(d)) {
1579 if (s > start) {
1580 fbcon_putcs(vc, start, s - start,
1581 line, x);
1582 x += s - start + 1;
1583 start = s + 1;
1584 } else {
1585 x++;
1586 start++;
1587 }
1588 }
1589 scr_writew(c, d);
1590 console_conditional_schedule();
1591 s++;
1592 d++;
1593 } while (s < le);
1594 if (s > start)
1595 fbcon_putcs(vc, start, s - start, line, x);
1596 console_conditional_schedule();
1597 if (offset > 0)
1598 line++;
1599 else {
1600 line--;
1601 /* NOTE: We subtract two lines from these pointers */
1602 s -= vc->vc_size_row;
1603 d -= vc->vc_size_row;
1604 }
1605 }
1606 }
1607
1608 static inline void fbcon_softback_note(struct vc_data *vc, int t,
1609 int count)
1610 {
1611 unsigned short *p;
1612
1613 if (vc->vc_num != fg_console)
1614 return;
1615 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1616
1617 while (count) {
1618 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1619 count--;
1620 p = advance_row(p, 1);
1621 softback_in += vc->vc_size_row;
1622 if (softback_in == softback_end)
1623 softback_in = softback_buf;
1624 if (softback_in == softback_top) {
1625 softback_top += vc->vc_size_row;
1626 if (softback_top == softback_end)
1627 softback_top = softback_buf;
1628 }
1629 }
1630 softback_curr = softback_in;
1631 }
1632
1633 static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1634 int count)
1635 {
1636 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1637 struct display *p = &fb_display[vc->vc_num];
1638 struct fbcon_ops *ops = info->fbcon_par;
1639 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1640
1641 if (fbcon_is_inactive(vc, info))
1642 return -EINVAL;
1643
1644 fbcon_cursor(vc, CM_ERASE);
1645
1646 /*
1647 * ++Geert: Only use ywrap/ypan if the console is in text mode
1648 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1649 * whole screen (prevents flicker).
1650 */
1651
1652 switch (dir) {
1653 case SM_UP:
1654 if (count > vc->vc_rows) /* Maximum realistic size */
1655 count = vc->vc_rows;
1656 if (softback_top)
1657 fbcon_softback_note(vc, t, count);
1658 if (logo_shown >= 0)
1659 goto redraw_up;
1660 switch (p->scrollmode) {
1661 case SCROLL_MOVE:
1662 ops->bmove(vc, info, t + count, 0, t, 0,
1663 b - t - count, vc->vc_cols);
1664 ops->clear(vc, info, b - count, 0, count,
1665 vc->vc_cols);
1666 break;
1667
1668 case SCROLL_WRAP_MOVE:
1669 if (b - t - count > 3 * vc->vc_rows >> 2) {
1670 if (t > 0)
1671 fbcon_bmove(vc, 0, 0, count, 0, t,
1672 vc->vc_cols);
1673 ywrap_up(vc, count);
1674 if (vc->vc_rows - b > 0)
1675 fbcon_bmove(vc, b - count, 0, b, 0,
1676 vc->vc_rows - b,
1677 vc->vc_cols);
1678 } else if (info->flags & FBINFO_READS_FAST)
1679 fbcon_bmove(vc, t + count, 0, t, 0,
1680 b - t - count, vc->vc_cols);
1681 else
1682 goto redraw_up;
1683 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1684 break;
1685
1686 case SCROLL_PAN_REDRAW:
1687 if ((p->yscroll + count <=
1688 2 * (p->vrows - vc->vc_rows))
1689 && ((!scroll_partial && (b - t == vc->vc_rows))
1690 || (scroll_partial
1691 && (b - t - count >
1692 3 * vc->vc_rows >> 2)))) {
1693 if (t > 0)
1694 fbcon_redraw_move(vc, p, 0, t, count);
1695 ypan_up_redraw(vc, t, count);
1696 if (vc->vc_rows - b > 0)
1697 fbcon_redraw_move(vc, p, b - count,
1698 vc->vc_rows - b, b);
1699 } else
1700 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1701 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1702 break;
1703
1704 case SCROLL_PAN_MOVE:
1705 if ((p->yscroll + count <=
1706 2 * (p->vrows - vc->vc_rows))
1707 && ((!scroll_partial && (b - t == vc->vc_rows))
1708 || (scroll_partial
1709 && (b - t - count >
1710 3 * vc->vc_rows >> 2)))) {
1711 if (t > 0)
1712 fbcon_bmove(vc, 0, 0, count, 0, t,
1713 vc->vc_cols);
1714 ypan_up(vc, count);
1715 if (vc->vc_rows - b > 0)
1716 fbcon_bmove(vc, b - count, 0, b, 0,
1717 vc->vc_rows - b,
1718 vc->vc_cols);
1719 } else if (info->flags & FBINFO_READS_FAST)
1720 fbcon_bmove(vc, t + count, 0, t, 0,
1721 b - t - count, vc->vc_cols);
1722 else
1723 goto redraw_up;
1724 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1725 break;
1726
1727 case SCROLL_REDRAW:
1728 redraw_up:
1729 fbcon_redraw(vc, p, t, b - t - count,
1730 count * vc->vc_cols);
1731 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1732 scr_memsetw((unsigned short *) (vc->vc_origin +
1733 vc->vc_size_row *
1734 (b - count)),
1735 vc->vc_video_erase_char,
1736 vc->vc_size_row * count);
1737 return 1;
1738 }
1739 break;
1740
1741 case SM_DOWN:
1742 if (count > vc->vc_rows) /* Maximum realistic size */
1743 count = vc->vc_rows;
1744 if (logo_shown >= 0)
1745 goto redraw_down;
1746 switch (p->scrollmode) {
1747 case SCROLL_MOVE:
1748 ops->bmove(vc, info, t, 0, t + count, 0,
1749 b - t - count, vc->vc_cols);
1750 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1751 break;
1752
1753 case SCROLL_WRAP_MOVE:
1754 if (b - t - count > 3 * vc->vc_rows >> 2) {
1755 if (vc->vc_rows - b > 0)
1756 fbcon_bmove(vc, b, 0, b - count, 0,
1757 vc->vc_rows - b,
1758 vc->vc_cols);
1759 ywrap_down(vc, count);
1760 if (t > 0)
1761 fbcon_bmove(vc, count, 0, 0, 0, t,
1762 vc->vc_cols);
1763 } else if (info->flags & FBINFO_READS_FAST)
1764 fbcon_bmove(vc, t, 0, t + count, 0,
1765 b - t - count, vc->vc_cols);
1766 else
1767 goto redraw_down;
1768 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1769 break;
1770
1771 case SCROLL_PAN_MOVE:
1772 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1773 && ((!scroll_partial && (b - t == vc->vc_rows))
1774 || (scroll_partial
1775 && (b - t - count >
1776 3 * vc->vc_rows >> 2)))) {
1777 if (vc->vc_rows - b > 0)
1778 fbcon_bmove(vc, b, 0, b - count, 0,
1779 vc->vc_rows - b,
1780 vc->vc_cols);
1781 ypan_down(vc, count);
1782 if (t > 0)
1783 fbcon_bmove(vc, count, 0, 0, 0, t,
1784 vc->vc_cols);
1785 } else if (info->flags & FBINFO_READS_FAST)
1786 fbcon_bmove(vc, t, 0, t + count, 0,
1787 b - t - count, vc->vc_cols);
1788 else
1789 goto redraw_down;
1790 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1791 break;
1792
1793 case SCROLL_PAN_REDRAW:
1794 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1795 && ((!scroll_partial && (b - t == vc->vc_rows))
1796 || (scroll_partial
1797 && (b - t - count >
1798 3 * vc->vc_rows >> 2)))) {
1799 if (vc->vc_rows - b > 0)
1800 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1801 b - count);
1802 ypan_down_redraw(vc, t, count);
1803 if (t > 0)
1804 fbcon_redraw_move(vc, p, count, t, 0);
1805 } else
1806 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1807 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1808 break;
1809
1810 case SCROLL_REDRAW:
1811 redraw_down:
1812 fbcon_redraw(vc, p, b - 1, b - t - count,
1813 -count * vc->vc_cols);
1814 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1815 scr_memsetw((unsigned short *) (vc->vc_origin +
1816 vc->vc_size_row *
1817 t),
1818 vc->vc_video_erase_char,
1819 vc->vc_size_row * count);
1820 return 1;
1821 }
1822 }
1823 return 0;
1824 }
1825
1826
1827 static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1828 int height, int width)
1829 {
1830 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1831 struct display *p = &fb_display[vc->vc_num];
1832
1833 if (fbcon_is_inactive(vc, info))
1834 return;
1835
1836 if (!width || !height)
1837 return;
1838
1839 /* Split blits that cross physical y_wrap case.
1840 * Pathological case involves 4 blits, better to use recursive
1841 * code rather than unrolled case
1842 *
1843 * Recursive invocations don't need to erase the cursor over and
1844 * over again, so we use fbcon_bmove_rec()
1845 */
1846 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1847 p->vrows - p->yscroll);
1848 }
1849
1850 static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1851 int dy, int dx, int height, int width, u_int y_break)
1852 {
1853 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1854 struct fbcon_ops *ops = info->fbcon_par;
1855 u_int b;
1856
1857 if (sy < y_break && sy + height > y_break) {
1858 b = y_break - sy;
1859 if (dy < sy) { /* Avoid trashing self */
1860 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1861 y_break);
1862 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1863 height - b, width, y_break);
1864 } else {
1865 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1866 height - b, width, y_break);
1867 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1868 y_break);
1869 }
1870 return;
1871 }
1872
1873 if (dy < y_break && dy + height > y_break) {
1874 b = y_break - dy;
1875 if (dy < sy) { /* Avoid trashing self */
1876 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1877 y_break);
1878 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1879 height - b, width, y_break);
1880 } else {
1881 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1882 height - b, width, y_break);
1883 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1884 y_break);
1885 }
1886 return;
1887 }
1888 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1889 height, width);
1890 }
1891
1892 static __inline__ void updatescrollmode(struct display *p,
1893 struct fb_info *info,
1894 struct vc_data *vc)
1895 {
1896 struct fbcon_ops *ops = info->fbcon_par;
1897 int fh = vc->vc_font.height;
1898 int cap = info->flags;
1899 u16 t = 0;
1900 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1901 info->fix.xpanstep);
1902 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1903 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1904 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1905 info->var.xres_virtual);
1906 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1907 divides(ypan, vc->vc_font.height) && vyres > yres;
1908 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1909 divides(ywrap, vc->vc_font.height) &&
1910 divides(vc->vc_font.height, vyres);
1911 int reading_fast = cap & FBINFO_READS_FAST;
1912 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1913 !(cap & FBINFO_HWACCEL_DISABLED);
1914 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1915 !(cap & FBINFO_HWACCEL_DISABLED);
1916
1917 p->vrows = vyres/fh;
1918 if (yres > (fh * (vc->vc_rows + 1)))
1919 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1920 if ((yres % fh) && (vyres % fh < yres % fh))
1921 p->vrows--;
1922
1923 if (good_wrap || good_pan) {
1924 if (reading_fast || fast_copyarea)
1925 p->scrollmode = good_wrap ?
1926 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1927 else
1928 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1929 SCROLL_PAN_REDRAW;
1930 } else {
1931 if (reading_fast || (fast_copyarea && !fast_imageblit))
1932 p->scrollmode = SCROLL_MOVE;
1933 else
1934 p->scrollmode = SCROLL_REDRAW;
1935 }
1936 }
1937
1938 static int fbcon_resize(struct vc_data *vc, unsigned int width,
1939 unsigned int height)
1940 {
1941 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1942 struct fbcon_ops *ops = info->fbcon_par;
1943 struct display *p = &fb_display[vc->vc_num];
1944 struct fb_var_screeninfo var = info->var;
1945 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
1946
1947 virt_w = FBCON_SWAP(ops->rotate, width, height);
1948 virt_h = FBCON_SWAP(ops->rotate, height, width);
1949 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
1950 vc->vc_font.height);
1951 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
1952 vc->vc_font.width);
1953 var.xres = virt_w * virt_fw;
1954 var.yres = virt_h * virt_fh;
1955 x_diff = info->var.xres - var.xres;
1956 y_diff = info->var.yres - var.yres;
1957 if (x_diff < 0 || x_diff > virt_fw ||
1958 y_diff < 0 || y_diff > virt_fh) {
1959 struct fb_videomode *mode;
1960
1961 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
1962 mode = fb_find_best_mode(&var, &info->modelist);
1963 if (mode == NULL)
1964 return -EINVAL;
1965 display_to_var(&var, p);
1966 fb_videomode_to_var(&var, mode);
1967
1968 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
1969 return -EINVAL;
1970
1971 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
1972 if (CON_IS_VISIBLE(vc)) {
1973 var.activate = FB_ACTIVATE_NOW |
1974 FB_ACTIVATE_FORCE;
1975 fb_set_var(info, &var);
1976 }
1977 var_to_display(p, &info->var, info);
1978 ops->var = info->var;
1979 }
1980 updatescrollmode(p, info, vc);
1981 return 0;
1982 }
1983
1984 static int fbcon_switch(struct vc_data *vc)
1985 {
1986 struct fb_info *info, *old_info = NULL;
1987 struct fbcon_ops *ops;
1988 struct display *p = &fb_display[vc->vc_num];
1989 struct fb_var_screeninfo var;
1990 int i, prev_console;
1991
1992 info = registered_fb[con2fb_map[vc->vc_num]];
1993 ops = info->fbcon_par;
1994
1995 if (softback_top) {
1996 if (softback_lines)
1997 fbcon_set_origin(vc);
1998 softback_top = softback_curr = softback_in = softback_buf;
1999 softback_lines = 0;
2000 fbcon_update_softback(vc);
2001 }
2002
2003 if (logo_shown >= 0) {
2004 struct vc_data *conp2 = vc_cons[logo_shown].d;
2005
2006 if (conp2->vc_top == logo_lines
2007 && conp2->vc_bottom == conp2->vc_rows)
2008 conp2->vc_top = 0;
2009 logo_shown = FBCON_LOGO_CANSHOW;
2010 }
2011
2012 prev_console = ops->currcon;
2013 if (prev_console != -1)
2014 old_info = registered_fb[con2fb_map[prev_console]];
2015 /*
2016 * FIXME: If we have multiple fbdev's loaded, we need to
2017 * update all info->currcon. Perhaps, we can place this
2018 * in a centralized structure, but this might break some
2019 * drivers.
2020 *
2021 * info->currcon = vc->vc_num;
2022 */
2023 for (i = 0; i < FB_MAX; i++) {
2024 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
2025 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
2026
2027 o->currcon = vc->vc_num;
2028 }
2029 }
2030 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2031 display_to_var(&var, p);
2032 var.activate = FB_ACTIVATE_NOW;
2033
2034 /*
2035 * make sure we don't unnecessarily trip the memcmp()
2036 * in fb_set_var()
2037 */
2038 info->var.activate = var.activate;
2039 var.yoffset = info->var.yoffset;
2040 var.xoffset = info->var.xoffset;
2041 var.vmode = info->var.vmode;
2042 fb_set_var(info, &var);
2043 ops->var = info->var;
2044
2045 if (old_info != NULL && old_info != info) {
2046 if (info->fbops->fb_set_par)
2047 info->fbops->fb_set_par(info);
2048 fbcon_del_cursor_timer(old_info);
2049 fbcon_add_cursor_timer(info);
2050 }
2051
2052 set_blitting_type(vc, info, p);
2053 ops->cursor_reset = 1;
2054
2055 if (ops->rotate_font && ops->rotate_font(info, vc, p)) {
2056 ops->rotate = FB_ROTATE_UR;
2057 set_blitting_type(vc, info, p);
2058 }
2059
2060 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
2061 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
2062 updatescrollmode(p, info, vc);
2063
2064 switch (p->scrollmode) {
2065 case SCROLL_WRAP_MOVE:
2066 scrollback_phys_max = p->vrows - vc->vc_rows;
2067 break;
2068 case SCROLL_PAN_MOVE:
2069 case SCROLL_PAN_REDRAW:
2070 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2071 if (scrollback_phys_max < 0)
2072 scrollback_phys_max = 0;
2073 break;
2074 default:
2075 scrollback_phys_max = 0;
2076 break;
2077 }
2078
2079 scrollback_max = 0;
2080 scrollback_current = 0;
2081 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2082 ops->update_start(info);
2083 fbcon_set_palette(vc, color_table);
2084 fbcon_clear_margins(vc, 0);
2085
2086 if (logo_shown == FBCON_LOGO_DRAW) {
2087
2088 logo_shown = fg_console;
2089 /* This is protected above by initmem_freed */
2090 fb_show_logo(info, ops->rotate);
2091 update_region(vc,
2092 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2093 vc->vc_size_row * (vc->vc_bottom -
2094 vc->vc_top) / 2);
2095 return 0;
2096 }
2097 return 1;
2098 }
2099
2100 static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2101 int blank)
2102 {
2103 if (blank) {
2104 unsigned short charmask = vc->vc_hi_font_mask ?
2105 0x1ff : 0xff;
2106 unsigned short oldc;
2107
2108 oldc = vc->vc_video_erase_char;
2109 vc->vc_video_erase_char &= charmask;
2110 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2111 vc->vc_video_erase_char = oldc;
2112 }
2113 }
2114
2115 static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2116 {
2117 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2118 struct fbcon_ops *ops = info->fbcon_par;
2119
2120 if (mode_switch) {
2121 struct fb_var_screeninfo var = info->var;
2122
2123 ops->graphics = 1;
2124
2125 if (!blank) {
2126 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2127 fb_set_var(info, &var);
2128 ops->graphics = 0;
2129 ops->var = info->var;
2130 }
2131 }
2132
2133 if (!fbcon_is_inactive(vc, info)) {
2134 if (ops->blank_state != blank) {
2135 ops->blank_state = blank;
2136 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2137 ops->cursor_flash = (!blank);
2138
2139 if (fb_blank(info, blank))
2140 fbcon_generic_blank(vc, info, blank);
2141 }
2142
2143 if (!blank)
2144 update_screen(vc);
2145 }
2146
2147 if (!blank)
2148 fbcon_add_cursor_timer(info);
2149 else
2150 fbcon_del_cursor_timer(info);
2151
2152 return 0;
2153 }
2154
2155 static void fbcon_free_font(struct display *p)
2156 {
2157 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2158 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2159 p->fontdata = NULL;
2160 p->userfont = 0;
2161 }
2162
2163 static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2164 {
2165 u8 *fontdata = vc->vc_font.data;
2166 u8 *data = font->data;
2167 int i, j;
2168
2169 font->width = vc->vc_font.width;
2170 font->height = vc->vc_font.height;
2171 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2172 if (!font->data)
2173 return 0;
2174
2175 if (font->width <= 8) {
2176 j = vc->vc_font.height;
2177 for (i = 0; i < font->charcount; i++) {
2178 memcpy(data, fontdata, j);
2179 memset(data + j, 0, 32 - j);
2180 data += 32;
2181 fontdata += j;
2182 }
2183 } else if (font->width <= 16) {
2184 j = vc->vc_font.height * 2;
2185 for (i = 0; i < font->charcount; i++) {
2186 memcpy(data, fontdata, j);
2187 memset(data + j, 0, 64 - j);
2188 data += 64;
2189 fontdata += j;
2190 }
2191 } else if (font->width <= 24) {
2192 for (i = 0; i < font->charcount; i++) {
2193 for (j = 0; j < vc->vc_font.height; j++) {
2194 *data++ = fontdata[0];
2195 *data++ = fontdata[1];
2196 *data++ = fontdata[2];
2197 fontdata += sizeof(u32);
2198 }
2199 memset(data, 0, 3 * (32 - j));
2200 data += 3 * (32 - j);
2201 }
2202 } else {
2203 j = vc->vc_font.height * 4;
2204 for (i = 0; i < font->charcount; i++) {
2205 memcpy(data, fontdata, j);
2206 memset(data + j, 0, 128 - j);
2207 data += 128;
2208 fontdata += j;
2209 }
2210 }
2211 return 0;
2212 }
2213
2214 static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2215 const u8 * data, int userfont)
2216 {
2217 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2218 struct fbcon_ops *ops = info->fbcon_par;
2219 struct display *p = &fb_display[vc->vc_num];
2220 int resize;
2221 int cnt;
2222 char *old_data = NULL;
2223
2224 if (CON_IS_VISIBLE(vc) && softback_lines)
2225 fbcon_set_origin(vc);
2226
2227 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2228 if (p->userfont)
2229 old_data = vc->vc_font.data;
2230 if (userfont)
2231 cnt = FNTCHARCNT(data);
2232 else
2233 cnt = 256;
2234 vc->vc_font.data = (void *)(p->fontdata = data);
2235 if ((p->userfont = userfont))
2236 REFCOUNT(data)++;
2237 vc->vc_font.width = w;
2238 vc->vc_font.height = h;
2239 if (vc->vc_hi_font_mask && cnt == 256) {
2240 vc->vc_hi_font_mask = 0;
2241 if (vc->vc_can_do_color) {
2242 vc->vc_complement_mask >>= 1;
2243 vc->vc_s_complement_mask >>= 1;
2244 }
2245
2246 /* ++Edmund: reorder the attribute bits */
2247 if (vc->vc_can_do_color) {
2248 unsigned short *cp =
2249 (unsigned short *) vc->vc_origin;
2250 int count = vc->vc_screenbuf_size / 2;
2251 unsigned short c;
2252 for (; count > 0; count--, cp++) {
2253 c = scr_readw(cp);
2254 scr_writew(((c & 0xfe00) >> 1) |
2255 (c & 0xff), cp);
2256 }
2257 c = vc->vc_video_erase_char;
2258 vc->vc_video_erase_char =
2259 ((c & 0xfe00) >> 1) | (c & 0xff);
2260 vc->vc_attr >>= 1;
2261 }
2262 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2263 vc->vc_hi_font_mask = 0x100;
2264 if (vc->vc_can_do_color) {
2265 vc->vc_complement_mask <<= 1;
2266 vc->vc_s_complement_mask <<= 1;
2267 }
2268
2269 /* ++Edmund: reorder the attribute bits */
2270 {
2271 unsigned short *cp =
2272 (unsigned short *) vc->vc_origin;
2273 int count = vc->vc_screenbuf_size / 2;
2274 unsigned short c;
2275 for (; count > 0; count--, cp++) {
2276 unsigned short newc;
2277 c = scr_readw(cp);
2278 if (vc->vc_can_do_color)
2279 newc =
2280 ((c & 0xff00) << 1) | (c &
2281 0xff);
2282 else
2283 newc = c & ~0x100;
2284 scr_writew(newc, cp);
2285 }
2286 c = vc->vc_video_erase_char;
2287 if (vc->vc_can_do_color) {
2288 vc->vc_video_erase_char =
2289 ((c & 0xff00) << 1) | (c & 0xff);
2290 vc->vc_attr <<= 1;
2291 } else
2292 vc->vc_video_erase_char = c & ~0x100;
2293 }
2294
2295 }
2296
2297 if (resize) {
2298 int cols, rows;
2299
2300 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2301 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2302 cols /= w;
2303 rows /= h;
2304 vc_resize(vc, cols, rows);
2305 if (CON_IS_VISIBLE(vc) && softback_buf)
2306 fbcon_update_softback(vc);
2307 } else if (CON_IS_VISIBLE(vc)
2308 && vc->vc_mode == KD_TEXT) {
2309 fbcon_clear_margins(vc, 0);
2310 update_screen(vc);
2311 }
2312
2313 if (old_data && (--REFCOUNT(old_data) == 0))
2314 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2315 return 0;
2316 }
2317
2318 static int fbcon_copy_font(struct vc_data *vc, int con)
2319 {
2320 struct display *od = &fb_display[con];
2321 struct console_font *f = &vc->vc_font;
2322
2323 if (od->fontdata == f->data)
2324 return 0; /* already the same font... */
2325 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2326 }
2327
2328 /*
2329 * User asked to set font; we are guaranteed that
2330 * a) width and height are in range 1..32
2331 * b) charcount does not exceed 512
2332 * but lets not assume that, since someone might someday want to use larger
2333 * fonts. And charcount of 512 is small for unicode support.
2334 *
2335 * However, user space gives the font in 32 rows , regardless of
2336 * actual font height. So a new API is needed if support for larger fonts
2337 * is ever implemented.
2338 */
2339
2340 static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2341 {
2342 unsigned charcount = font->charcount;
2343 int w = font->width;
2344 int h = font->height;
2345 int size;
2346 int i, csum;
2347 u8 *new_data, *data = font->data;
2348 int pitch = (font->width+7) >> 3;
2349
2350 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2351 * If not this check should be changed to charcount < 256 */
2352 if (charcount != 256 && charcount != 512)
2353 return -EINVAL;
2354
2355 size = h * pitch * charcount;
2356
2357 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2358
2359 if (!new_data)
2360 return -ENOMEM;
2361
2362 new_data += FONT_EXTRA_WORDS * sizeof(int);
2363 FNTSIZE(new_data) = size;
2364 FNTCHARCNT(new_data) = charcount;
2365 REFCOUNT(new_data) = 0; /* usage counter */
2366 for (i=0; i< charcount; i++) {
2367 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2368 }
2369
2370 /* Since linux has a nice crc32 function use it for counting font
2371 * checksums. */
2372 csum = crc32(0, new_data, size);
2373
2374 FNTSUM(new_data) = csum;
2375 /* Check if the same font is on some other console already */
2376 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2377 struct vc_data *tmp = vc_cons[i].d;
2378
2379 if (fb_display[i].userfont &&
2380 fb_display[i].fontdata &&
2381 FNTSUM(fb_display[i].fontdata) == csum &&
2382 FNTSIZE(fb_display[i].fontdata) == size &&
2383 tmp->vc_font.width == w &&
2384 !memcmp(fb_display[i].fontdata, new_data, size)) {
2385 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2386 new_data = (u8 *)fb_display[i].fontdata;
2387 break;
2388 }
2389 }
2390 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2391 }
2392
2393 static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2394 {
2395 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2396 const struct font_desc *f;
2397
2398 if (!name)
2399 f = get_default_font(info->var.xres, info->var.yres);
2400 else if (!(f = find_font(name)))
2401 return -ENOENT;
2402
2403 font->width = f->width;
2404 font->height = f->height;
2405 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2406 }
2407
2408 static u16 palette_red[16];
2409 static u16 palette_green[16];
2410 static u16 palette_blue[16];
2411
2412 static struct fb_cmap palette_cmap = {
2413 0, 16, palette_red, palette_green, palette_blue, NULL
2414 };
2415
2416 static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2417 {
2418 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2419 int i, j, k, depth;
2420 u8 val;
2421
2422 if (fbcon_is_inactive(vc, info))
2423 return -EINVAL;
2424
2425 if (!CON_IS_VISIBLE(vc))
2426 return 0;
2427
2428 depth = fb_get_color_depth(&info->var, &info->fix);
2429 if (depth > 3) {
2430 for (i = j = 0; i < 16; i++) {
2431 k = table[i];
2432 val = vc->vc_palette[j++];
2433 palette_red[k] = (val << 8) | val;
2434 val = vc->vc_palette[j++];
2435 palette_green[k] = (val << 8) | val;
2436 val = vc->vc_palette[j++];
2437 palette_blue[k] = (val << 8) | val;
2438 }
2439 palette_cmap.len = 16;
2440 palette_cmap.start = 0;
2441 /*
2442 * If framebuffer is capable of less than 16 colors,
2443 * use default palette of fbcon.
2444 */
2445 } else
2446 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2447
2448 return fb_set_cmap(&palette_cmap, info);
2449 }
2450
2451 static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2452 {
2453 unsigned long p;
2454 int line;
2455
2456 if (vc->vc_num != fg_console || !softback_lines)
2457 return (u16 *) (vc->vc_origin + offset);
2458 line = offset / vc->vc_size_row;
2459 if (line >= softback_lines)
2460 return (u16 *) (vc->vc_origin + offset -
2461 softback_lines * vc->vc_size_row);
2462 p = softback_curr + offset;
2463 if (p >= softback_end)
2464 p += softback_buf - softback_end;
2465 return (u16 *) p;
2466 }
2467
2468 static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2469 int *px, int *py)
2470 {
2471 unsigned long ret;
2472 int x, y;
2473
2474 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2475 unsigned long offset = (pos - vc->vc_origin) / 2;
2476
2477 x = offset % vc->vc_cols;
2478 y = offset / vc->vc_cols;
2479 if (vc->vc_num == fg_console)
2480 y += softback_lines;
2481 ret = pos + (vc->vc_cols - x) * 2;
2482 } else if (vc->vc_num == fg_console && softback_lines) {
2483 unsigned long offset = pos - softback_curr;
2484
2485 if (pos < softback_curr)
2486 offset += softback_end - softback_buf;
2487 offset /= 2;
2488 x = offset % vc->vc_cols;
2489 y = offset / vc->vc_cols;
2490 ret = pos + (vc->vc_cols - x) * 2;
2491 if (ret == softback_end)
2492 ret = softback_buf;
2493 if (ret == softback_in)
2494 ret = vc->vc_origin;
2495 } else {
2496 /* Should not happen */
2497 x = y = 0;
2498 ret = vc->vc_origin;
2499 }
2500 if (px)
2501 *px = x;
2502 if (py)
2503 *py = y;
2504 return ret;
2505 }
2506
2507 /* As we might be inside of softback, we may work with non-contiguous buffer,
2508 that's why we have to use a separate routine. */
2509 static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2510 {
2511 while (cnt--) {
2512 u16 a = scr_readw(p);
2513 if (!vc->vc_can_do_color)
2514 a ^= 0x0800;
2515 else if (vc->vc_hi_font_mask == 0x100)
2516 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2517 (((a) & 0x0e00) << 4);
2518 else
2519 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2520 (((a) & 0x0700) << 4);
2521 scr_writew(a, p++);
2522 if (p == (u16 *) softback_end)
2523 p = (u16 *) softback_buf;
2524 if (p == (u16 *) softback_in)
2525 p = (u16 *) vc->vc_origin;
2526 }
2527 }
2528
2529 static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2530 {
2531 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
2532 struct fbcon_ops *ops = info->fbcon_par;
2533 struct display *p = &fb_display[fg_console];
2534 int offset, limit, scrollback_old;
2535
2536 if (softback_top) {
2537 if (vc->vc_num != fg_console)
2538 return 0;
2539 if (vc->vc_mode != KD_TEXT || !lines)
2540 return 0;
2541 if (logo_shown >= 0) {
2542 struct vc_data *conp2 = vc_cons[logo_shown].d;
2543
2544 if (conp2->vc_top == logo_lines
2545 && conp2->vc_bottom == conp2->vc_rows)
2546 conp2->vc_top = 0;
2547 if (logo_shown == vc->vc_num) {
2548 unsigned long p, q;
2549 int i;
2550
2551 p = softback_in;
2552 q = vc->vc_origin +
2553 logo_lines * vc->vc_size_row;
2554 for (i = 0; i < logo_lines; i++) {
2555 if (p == softback_top)
2556 break;
2557 if (p == softback_buf)
2558 p = softback_end;
2559 p -= vc->vc_size_row;
2560 q -= vc->vc_size_row;
2561 scr_memcpyw((u16 *) q, (u16 *) p,
2562 vc->vc_size_row);
2563 }
2564 softback_in = p;
2565 update_region(vc, vc->vc_origin,
2566 logo_lines * vc->vc_cols);
2567 }
2568 logo_shown = FBCON_LOGO_CANSHOW;
2569 }
2570 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2571 fbcon_redraw_softback(vc, p, lines);
2572 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2573 return 0;
2574 }
2575
2576 if (!scrollback_phys_max)
2577 return -ENOSYS;
2578
2579 scrollback_old = scrollback_current;
2580 scrollback_current -= lines;
2581 if (scrollback_current < 0)
2582 scrollback_current = 0;
2583 else if (scrollback_current > scrollback_max)
2584 scrollback_current = scrollback_max;
2585 if (scrollback_current == scrollback_old)
2586 return 0;
2587
2588 if (fbcon_is_inactive(vc, info))
2589 return 0;
2590
2591 fbcon_cursor(vc, CM_ERASE);
2592
2593 offset = p->yscroll - scrollback_current;
2594 limit = p->vrows;
2595 switch (p->scrollmode) {
2596 case SCROLL_WRAP_MOVE:
2597 info->var.vmode |= FB_VMODE_YWRAP;
2598 break;
2599 case SCROLL_PAN_MOVE:
2600 case SCROLL_PAN_REDRAW:
2601 limit -= vc->vc_rows;
2602 info->var.vmode &= ~FB_VMODE_YWRAP;
2603 break;
2604 }
2605 if (offset < 0)
2606 offset += limit;
2607 else if (offset >= limit)
2608 offset -= limit;
2609
2610 ops->var.xoffset = 0;
2611 ops->var.yoffset = offset * vc->vc_font.height;
2612 ops->update_start(info);
2613
2614 if (!scrollback_current)
2615 fbcon_cursor(vc, CM_DRAW);
2616 return 0;
2617 }
2618
2619 static int fbcon_set_origin(struct vc_data *vc)
2620 {
2621 if (softback_lines)
2622 fbcon_scrolldelta(vc, softback_lines);
2623 return 0;
2624 }
2625
2626 static void fbcon_suspended(struct fb_info *info)
2627 {
2628 struct vc_data *vc = NULL;
2629 struct fbcon_ops *ops = info->fbcon_par;
2630
2631 if (!ops || ops->currcon < 0)
2632 return;
2633 vc = vc_cons[ops->currcon].d;
2634
2635 /* Clear cursor, restore saved data */
2636 fbcon_cursor(vc, CM_ERASE);
2637 }
2638
2639 static void fbcon_resumed(struct fb_info *info)
2640 {
2641 struct vc_data *vc;
2642 struct fbcon_ops *ops = info->fbcon_par;
2643
2644 if (!ops || ops->currcon < 0)
2645 return;
2646 vc = vc_cons[ops->currcon].d;
2647
2648 update_screen(vc);
2649 }
2650
2651 static void fbcon_modechanged(struct fb_info *info)
2652 {
2653 struct fbcon_ops *ops = info->fbcon_par;
2654 struct vc_data *vc;
2655 struct display *p;
2656 int rows, cols;
2657
2658 if (!ops || ops->currcon < 0)
2659 return;
2660 vc = vc_cons[ops->currcon].d;
2661 if (vc->vc_mode != KD_TEXT ||
2662 registered_fb[con2fb_map[ops->currcon]] != info)
2663 return;
2664
2665 p = &fb_display[vc->vc_num];
2666 set_blitting_type(vc, info, p);
2667
2668 if (CON_IS_VISIBLE(vc)) {
2669 var_to_display(p, &info->var, info);
2670 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2671 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2672 cols /= vc->vc_font.width;
2673 rows /= vc->vc_font.height;
2674 vc_resize(vc, cols, rows);
2675 updatescrollmode(p, info, vc);
2676 scrollback_max = 0;
2677 scrollback_current = 0;
2678 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2679 ops->update_start(info);
2680 fbcon_set_palette(vc, color_table);
2681 update_screen(vc);
2682 if (softback_buf)
2683 fbcon_update_softback(vc);
2684 }
2685 }
2686
2687 static void fbcon_set_all_vcs(struct fb_info *info)
2688 {
2689 struct fbcon_ops *ops = info->fbcon_par;
2690 struct vc_data *vc;
2691 struct display *p;
2692 int i, rows, cols;
2693
2694 if (!ops || ops->currcon < 0)
2695 return;
2696
2697 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2698 vc = vc_cons[i].d;
2699 if (!vc || vc->vc_mode != KD_TEXT ||
2700 registered_fb[con2fb_map[i]] != info)
2701 continue;
2702
2703 p = &fb_display[vc->vc_num];
2704 set_blitting_type(vc, info, p);
2705 var_to_display(p, &info->var, info);
2706 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2707 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2708 cols /= vc->vc_font.width;
2709 rows /= vc->vc_font.height;
2710 vc_resize(vc, cols, rows);
2711
2712 if (CON_IS_VISIBLE(vc)) {
2713 updatescrollmode(p, info, vc);
2714 scrollback_max = 0;
2715 scrollback_current = 0;
2716 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2717 ops->update_start(info);
2718 fbcon_set_palette(vc, color_table);
2719 update_screen(vc);
2720 if (softback_buf)
2721 fbcon_update_softback(vc);
2722 }
2723 }
2724 }
2725
2726 static int fbcon_mode_deleted(struct fb_info *info,
2727 struct fb_videomode *mode)
2728 {
2729 struct fb_info *fb_info;
2730 struct display *p;
2731 int i, j, found = 0;
2732
2733 /* before deletion, ensure that mode is not in use */
2734 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2735 j = con2fb_map[i];
2736 if (j == -1)
2737 continue;
2738 fb_info = registered_fb[j];
2739 if (fb_info != info)
2740 continue;
2741 p = &fb_display[i];
2742 if (!p || !p->mode)
2743 continue;
2744 if (fb_mode_is_equal(p->mode, mode)) {
2745 found = 1;
2746 break;
2747 }
2748 }
2749 return found;
2750 }
2751
2752 static int fbcon_fb_registered(int idx)
2753 {
2754 int ret = 0, i;
2755
2756 if (info_idx == -1) {
2757 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2758 if (con2fb_map_boot[i] == idx) {
2759 info_idx = idx;
2760 break;
2761 }
2762 }
2763 if (info_idx != -1)
2764 ret = fbcon_takeover(1);
2765 } else {
2766 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2767 if (con2fb_map_boot[i] == idx)
2768 set_con2fb_map(i, idx, 0);
2769 }
2770 }
2771
2772 return ret;
2773 }
2774
2775 static void fbcon_fb_blanked(struct fb_info *info, int blank)
2776 {
2777 struct fbcon_ops *ops = info->fbcon_par;
2778 struct vc_data *vc;
2779
2780 if (!ops || ops->currcon < 0)
2781 return;
2782
2783 vc = vc_cons[ops->currcon].d;
2784 if (vc->vc_mode != KD_TEXT ||
2785 registered_fb[con2fb_map[ops->currcon]] != info)
2786 return;
2787
2788 if (CON_IS_VISIBLE(vc)) {
2789 if (blank)
2790 do_blank_screen(0);
2791 else
2792 do_unblank_screen(0);
2793 }
2794 ops->blank_state = blank;
2795 }
2796
2797 static void fbcon_new_modelist(struct fb_info *info)
2798 {
2799 int i;
2800 struct vc_data *vc;
2801 struct fb_var_screeninfo var;
2802 struct fb_videomode *mode;
2803
2804 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2805 if (registered_fb[con2fb_map[i]] != info)
2806 continue;
2807 if (!fb_display[i].mode)
2808 continue;
2809 vc = vc_cons[i].d;
2810 display_to_var(&var, &fb_display[i]);
2811 mode = fb_find_nearest_mode(fb_display[i].mode,
2812 &info->modelist);
2813 fb_videomode_to_var(&var, mode);
2814
2815 if (vc)
2816 fbcon_set_disp(info, &var, vc);
2817 else
2818 fbcon_preset_disp(info, &var, i);
2819
2820 }
2821 }
2822
2823 static int fbcon_event_notify(struct notifier_block *self,
2824 unsigned long action, void *data)
2825 {
2826 struct fb_event *event = data;
2827 struct fb_info *info = event->info;
2828 struct fb_videomode *mode;
2829 struct fb_con2fbmap *con2fb;
2830 int ret = 0;
2831
2832 switch(action) {
2833 case FB_EVENT_SUSPEND:
2834 fbcon_suspended(info);
2835 break;
2836 case FB_EVENT_RESUME:
2837 fbcon_resumed(info);
2838 break;
2839 case FB_EVENT_MODE_CHANGE:
2840 fbcon_modechanged(info);
2841 break;
2842 case FB_EVENT_MODE_CHANGE_ALL:
2843 fbcon_set_all_vcs(info);
2844 break;
2845 case FB_EVENT_MODE_DELETE:
2846 mode = event->data;
2847 ret = fbcon_mode_deleted(info, mode);
2848 break;
2849 case FB_EVENT_FB_REGISTERED:
2850 ret = fbcon_fb_registered(info->node);
2851 break;
2852 case FB_EVENT_SET_CONSOLE_MAP:
2853 con2fb = event->data;
2854 ret = set_con2fb_map(con2fb->console - 1,
2855 con2fb->framebuffer, 1);
2856 break;
2857 case FB_EVENT_GET_CONSOLE_MAP:
2858 con2fb = event->data;
2859 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2860 break;
2861 case FB_EVENT_BLANK:
2862 fbcon_fb_blanked(info, *(int *)event->data);
2863 break;
2864 case FB_EVENT_NEW_MODELIST:
2865 fbcon_new_modelist(info);
2866 break;
2867 }
2868
2869 return ret;
2870 }
2871
2872 /*
2873 * The console `switch' structure for the frame buffer based console
2874 */
2875
2876 static const struct consw fb_con = {
2877 .owner = THIS_MODULE,
2878 .con_startup = fbcon_startup,
2879 .con_init = fbcon_init,
2880 .con_deinit = fbcon_deinit,
2881 .con_clear = fbcon_clear,
2882 .con_putc = fbcon_putc,
2883 .con_putcs = fbcon_putcs,
2884 .con_cursor = fbcon_cursor,
2885 .con_scroll = fbcon_scroll,
2886 .con_bmove = fbcon_bmove,
2887 .con_switch = fbcon_switch,
2888 .con_blank = fbcon_blank,
2889 .con_font_set = fbcon_set_font,
2890 .con_font_get = fbcon_get_font,
2891 .con_font_default = fbcon_set_def_font,
2892 .con_font_copy = fbcon_copy_font,
2893 .con_set_palette = fbcon_set_palette,
2894 .con_scrolldelta = fbcon_scrolldelta,
2895 .con_set_origin = fbcon_set_origin,
2896 .con_invert_region = fbcon_invert_region,
2897 .con_screen_pos = fbcon_screen_pos,
2898 .con_getxy = fbcon_getxy,
2899 .con_resize = fbcon_resize,
2900 };
2901
2902 static struct notifier_block fbcon_event_notifier = {
2903 .notifier_call = fbcon_event_notify,
2904 };
2905
2906 static int __init fb_console_init(void)
2907 {
2908 int i;
2909
2910 acquire_console_sem();
2911 fb_register_client(&fbcon_event_notifier);
2912 release_console_sem();
2913
2914 for (i = 0; i < MAX_NR_CONSOLES; i++)
2915 con2fb_map[i] = -1;
2916
2917 if (num_registered_fb) {
2918 for (i = 0; i < FB_MAX; i++) {
2919 if (registered_fb[i] != NULL) {
2920 info_idx = i;
2921 break;
2922 }
2923 }
2924 fbcon_takeover(0);
2925 }
2926
2927 return 0;
2928 }
2929
2930 module_init(fb_console_init);
2931
2932 #ifdef MODULE
2933
2934 static void __exit fb_console_exit(void)
2935 {
2936 acquire_console_sem();
2937 fb_unregister_client(&fbcon_event_notifier);
2938 release_console_sem();
2939 give_up_console(&fb_con);
2940 }
2941
2942 module_exit(fb_console_exit);
2943
2944 #endif
2945
2946 MODULE_LICENSE("GPL");