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