blob: 4f6fc785e95f281976fa184264495ca95907cda6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Antonino A. Daplasab767202005-11-13 16:06:32 -0800109static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static 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
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800134/* console rotation */
135static int rotate;
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static __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);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800195static void fbcon_modechanged(struct fb_info *info);
196static void fbcon_set_all_vcs(struct fb_info *info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
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
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800211#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800212static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800213{
214 struct fbcon_ops *ops = info->fbcon_par;
215
216 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800217 ops->p->con_rotate < 4)
218 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800219 else
220 ops->rotate = 0;
221}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800222
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}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800267#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800268static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800269{
270 struct fbcon_ops *ops = info->fbcon_par;
271
272 ops->rotate = FB_ROTATE_UR;
273}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800274
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}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800284#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800285
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800286static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293static 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{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700304 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 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 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700320 int col = ~(0xfff << (max(info->var.green.length,
321 max(info->var.red.length,
322 info->var.blue.length)))) & 0xff;
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700325 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
326 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
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
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700337 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700342 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 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
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800371static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383static 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) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700397 registered_fb[con2fb_map[vc->vc_num]] != info ||
398 vc_cons[ops->currcon].d->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 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;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800405 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 get_color(vc, info, c, 0));
407 release_console_sem();
408}
409
Russell King41359dc2005-06-30 16:30:07 +0100410#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411static 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
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700433static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462#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 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800512
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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
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 */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800578 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 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 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700586 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800588 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 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
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800650static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651{
652 struct fbcon_ops *ops = info->fbcon_par;
653
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800654 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800657 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800658 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800659 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800664static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665{
666 struct fbcon_ops *ops = info->fbcon_par;
667
668 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800669 ops->p = &fb_display[vc->vc_num];
670 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 fbcon_set_bitops(ops);
672}
673#endif /* CONFIG_MISC_TILEBLITTING */
674
675
676static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
677 int unit, int oldidx)
678{
679 struct fbcon_ops *ops = NULL;
680 int err = 0;
681
682 if (!try_module_get(info->fbops->owner))
683 err = -ENODEV;
684
685 if (!err && info->fbops->fb_open &&
686 info->fbops->fb_open(info, 0))
687 err = -ENODEV;
688
689 if (!err) {
690 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
691 if (!ops)
692 err = -ENOMEM;
693 }
694
695 if (!err) {
696 memset(ops, 0, sizeof(struct fbcon_ops));
697 info->fbcon_par = ops;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800698 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 if (err) {
702 con2fb_map[unit] = oldidx;
703 module_put(info->fbops->owner);
704 }
705
706 return err;
707}
708
709static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
710 struct fb_info *newinfo, int unit,
711 int oldidx, int found)
712{
713 struct fbcon_ops *ops = oldinfo->fbcon_par;
714 int err = 0;
715
716 if (oldinfo->fbops->fb_release &&
717 oldinfo->fbops->fb_release(oldinfo, 0)) {
718 con2fb_map[unit] = oldidx;
719 if (!found && newinfo->fbops->fb_release)
720 newinfo->fbops->fb_release(newinfo, 0);
721 if (!found)
722 module_put(newinfo->fbops->owner);
723 err = -ENODEV;
724 }
725
726 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700727 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 kfree(ops->cursor_state.mask);
729 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800730 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 kfree(oldinfo->fbcon_par);
732 oldinfo->fbcon_par = NULL;
733 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800734 /*
735 If oldinfo and newinfo are driving the same hardware,
736 the fb_release() method of oldinfo may attempt to
737 restore the hardware state. This will leave the
738 newinfo in an undefined state. Thus, a call to
739 fb_set_par() may be needed for the newinfo.
740 */
741 if (newinfo->fbops->fb_set_par)
742 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744
745 return err;
746}
747
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
749 int unit, int show_logo)
750{
751 struct fbcon_ops *ops = info->fbcon_par;
752
753 ops->currcon = fg_console;
754
755 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
756 info->fbops->fb_set_par(info);
757
758 ops->flags |= FBCON_FLAGS_INIT;
759 ops->graphics = 0;
760
761 if (vc)
762 fbcon_set_disp(info, &info->var, vc);
763 else
764 fbcon_preset_disp(info, &info->var, unit);
765
766 if (show_logo) {
767 struct vc_data *fg_vc = vc_cons[fg_console].d;
768 struct fb_info *fg_info =
769 registered_fb[con2fb_map[fg_console]];
770
771 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
772 fg_vc->vc_rows, fg_vc->vc_cols,
773 fg_vc->vc_rows);
774 }
775
776 update_screen(vc_cons[fg_console].d);
777}
778
779/**
780 * set_con2fb_map - map console to frame buffer device
781 * @unit: virtual console number to map
782 * @newidx: frame buffer index to map virtual console to
783 * @user: user request
784 *
785 * Maps a virtual console @unit to a frame buffer device
786 * @newidx.
787 */
788static int set_con2fb_map(int unit, int newidx, int user)
789{
790 struct vc_data *vc = vc_cons[unit].d;
791 int oldidx = con2fb_map[unit];
792 struct fb_info *info = registered_fb[newidx];
793 struct fb_info *oldinfo = NULL;
794 int found, err = 0;
795
796 if (oldidx == newidx)
797 return 0;
798
799 if (!info)
800 err = -EINVAL;
801
802 if (!err && !search_for_mapped_con()) {
803 info_idx = newidx;
804 return fbcon_takeover(0);
805 }
806
807 if (oldidx != -1)
808 oldinfo = registered_fb[oldidx];
809
810 found = search_fb_in_map(newidx);
811
812 acquire_console_sem();
813 con2fb_map[unit] = newidx;
814 if (!err && !found)
815 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
816
817
818 /*
819 * If old fb is not mapped to any of the consoles,
820 * fbcon should release it.
821 */
822 if (!err && oldinfo && !search_fb_in_map(oldidx))
823 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
824 found);
825
826 if (!err) {
827 int show_logo = (fg_console == 0 && !user &&
828 logo_shown != FBCON_LOGO_DONTSHOW);
829
830 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700831 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 con2fb_map_boot[unit] = newidx;
833 con2fb_init_display(vc, info, unit, show_logo);
834 }
835
836 release_console_sem();
837 return err;
838}
839
840/*
841 * Low Level Operations
842 */
843/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
844static int var_to_display(struct display *disp,
845 struct fb_var_screeninfo *var,
846 struct fb_info *info)
847{
848 disp->xres_virtual = var->xres_virtual;
849 disp->yres_virtual = var->yres_virtual;
850 disp->bits_per_pixel = var->bits_per_pixel;
851 disp->grayscale = var->grayscale;
852 disp->nonstd = var->nonstd;
853 disp->accel_flags = var->accel_flags;
854 disp->height = var->height;
855 disp->width = var->width;
856 disp->red = var->red;
857 disp->green = var->green;
858 disp->blue = var->blue;
859 disp->transp = var->transp;
860 disp->rotate = var->rotate;
861 disp->mode = fb_match_mode(var, &info->modelist);
862 if (disp->mode == NULL)
863 /* This should not happen */
864 return -EINVAL;
865 return 0;
866}
867
868static void display_to_var(struct fb_var_screeninfo *var,
869 struct display *disp)
870{
871 fb_videomode_to_var(var, disp->mode);
872 var->xres_virtual = disp->xres_virtual;
873 var->yres_virtual = disp->yres_virtual;
874 var->bits_per_pixel = disp->bits_per_pixel;
875 var->grayscale = disp->grayscale;
876 var->nonstd = disp->nonstd;
877 var->accel_flags = disp->accel_flags;
878 var->height = disp->height;
879 var->width = disp->width;
880 var->red = disp->red;
881 var->green = disp->green;
882 var->blue = disp->blue;
883 var->transp = disp->transp;
884 var->rotate = disp->rotate;
885}
886
887static const char *fbcon_startup(void)
888{
889 const char *display_desc = "frame buffer device";
890 struct display *p = &fb_display[fg_console];
891 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700892 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 struct module *owner;
894 struct fb_info *info = NULL;
895 struct fbcon_ops *ops;
896 int rows, cols;
897 int irqres;
898
899 irqres = 1;
900 /*
901 * If num_registered_fb is zero, this is a call for the dummy part.
902 * The frame buffer devices weren't initialized yet.
903 */
904 if (!num_registered_fb || info_idx == -1)
905 return display_desc;
906 /*
907 * Instead of blindly using registered_fb[0], we use info_idx, set by
908 * fb_console_init();
909 */
910 info = registered_fb[info_idx];
911 if (!info)
912 return NULL;
913
914 owner = info->fbops->owner;
915 if (!try_module_get(owner))
916 return NULL;
917 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
918 module_put(owner);
919 return NULL;
920 }
921
922 ops = kmalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
923 if (!ops) {
924 module_put(owner);
925 return NULL;
926 }
927
928 memset(ops, 0, sizeof(struct fbcon_ops));
929 ops->currcon = -1;
930 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800931 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800933 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800934 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 if (info->fix.type != FB_TYPE_TEXT) {
937 if (fbcon_softback_size) {
938 if (!softback_buf) {
939 softback_buf =
940 (unsigned long)
941 kmalloc(fbcon_softback_size,
942 GFP_KERNEL);
943 if (!softback_buf) {
944 fbcon_softback_size = 0;
945 softback_top = 0;
946 }
947 }
948 } else {
949 if (softback_buf) {
950 kfree((void *) softback_buf);
951 softback_buf = 0;
952 softback_top = 0;
953 }
954 }
955 if (softback_buf)
956 softback_in = softback_top = softback_curr =
957 softback_buf;
958 softback_lines = 0;
959 }
960
961 /* Setup default font */
962 if (!p->fontdata) {
963 if (!fontname[0] || !(font = find_font(fontname)))
964 font = get_default_font(info->var.xres,
965 info->var.yres);
966 vc->vc_font.width = font->width;
967 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700968 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
970 }
971
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800972 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
973 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
974 cols /= vc->vc_font.width;
975 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 vc_resize(vc, cols, rows);
977
978 DPRINTK("mode: %s\n", info->fix.id);
979 DPRINTK("visual: %d\n", info->fix.visual);
980 DPRINTK("res: %dx%d-%d\n", info->var.xres,
981 info->var.yres,
982 info->var.bits_per_pixel);
983
984#ifdef CONFIG_ATARI
985 if (MACH_IS_ATARI) {
986 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
987 irqres =
988 request_irq(IRQ_AUTO_4, fb_vbl_handler,
989 IRQ_TYPE_PRIO, "framebuffer vbl",
990 info);
991 }
992#endif /* CONFIG_ATARI */
993
994#ifdef CONFIG_MAC
995 /*
996 * On a Macintoy, the VBL interrupt may or may not be active.
997 * As interrupt based cursor is more reliable and race free, we
998 * probe for VBL interrupts.
999 */
1000 if (MACH_IS_MAC) {
1001 int ct = 0;
1002 /*
1003 * Probe for VBL: set temp. handler ...
1004 */
1005 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1006 "framebuffer vbl", info);
1007 vbl_detected = 0;
1008
1009 /*
1010 * ... and spin for 20 ms ...
1011 */
1012 while (!vbl_detected && ++ct < 1000)
1013 udelay(20);
1014
1015 if (ct == 1000)
1016 printk
1017 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1018
1019 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1020
1021 if (vbl_detected) {
1022 /*
1023 * interrupt based cursor ok
1024 */
1025 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1026 irqres =
1027 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1028 "framebuffer vbl", info);
1029 } else {
1030 /*
1031 * VBL not detected: fall through, use timer based cursor
1032 */
1033 irqres = 1;
1034 }
1035 }
1036#endif /* CONFIG_MAC */
1037
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001038 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 return display_desc;
1040}
1041
1042static void fbcon_init(struct vc_data *vc, int init)
1043{
1044 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1045 struct fbcon_ops *ops;
1046 struct vc_data **default_mode = vc->vc_display_fg;
1047 struct vc_data *svc = *default_mode;
1048 struct display *t, *p = &fb_display[vc->vc_num];
1049 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001050 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 if (info_idx == -1 || info == NULL)
1053 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001054
1055 cap = info->flags;
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1058 (info->fix.type == FB_TYPE_TEXT))
1059 logo = 0;
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 if (var_to_display(p, &info->var, info))
1062 return;
1063
1064 /* If we are not the first console on this
1065 fb, copy the font from that console */
1066 t = &fb_display[svc->vc_num];
1067 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001068 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 vc->vc_font.width = (*default_mode)->vc_font.width;
1070 vc->vc_font.height = (*default_mode)->vc_font.height;
1071 p->userfont = t->userfont;
1072 if (p->userfont)
1073 REFCOUNT(p->fontdata)++;
1074 }
1075 if (p->userfont)
1076 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001077 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1079 if (charcnt == 256) {
1080 vc->vc_hi_font_mask = 0;
1081 } else {
1082 vc->vc_hi_font_mask = 0x100;
1083 if (vc->vc_can_do_color)
1084 vc->vc_complement_mask <<= 1;
1085 }
1086
1087 if (!*svc->vc_uni_pagedir_loc)
1088 con_set_default_unimap(svc);
1089 if (!*vc->vc_uni_pagedir_loc)
1090 con_copy_unimap(vc, svc);
1091
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001092 ops = info->fbcon_par;
1093 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001094 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 cols = vc->vc_cols;
1097 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001098 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1099 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1100 new_cols /= vc->vc_font.width;
1101 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 vc_resize(vc, new_cols, new_rows);
1103
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 /*
1105 * We must always set the mode. The mode of the previous console
1106 * driver could be in the same resolution but we are using different
1107 * hardware so we have to initialize the hardware.
1108 *
1109 * We need to do it in fbcon_init() to prevent screen corruption.
1110 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001111 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (info->fbops->fb_set_par &&
1113 !(ops->flags & FBCON_FLAGS_INIT))
1114 info->fbops->fb_set_par(info);
1115 ops->flags |= FBCON_FLAGS_INIT;
1116 }
1117
1118 ops->graphics = 0;
1119
1120 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1121 !(cap & FBINFO_HWACCEL_DISABLED))
1122 p->scrollmode = SCROLL_MOVE;
1123 else /* default to something safe */
1124 p->scrollmode = SCROLL_REDRAW;
1125
1126 /*
1127 * ++guenther: console.c:vc_allocate() relies on initializing
1128 * vc_{cols,rows}, but we must not set those if we are only
1129 * resizing the console.
1130 */
1131 if (!init) {
1132 vc->vc_cols = new_cols;
1133 vc->vc_rows = new_rows;
1134 }
1135
1136 if (logo)
1137 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1138
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001139 if (vc == svc && softback_buf)
1140 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001141
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001142 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001143 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001144 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001145 }
1146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
1149static void fbcon_deinit(struct vc_data *vc)
1150{
1151 struct display *p = &fb_display[vc->vc_num];
1152
1153 if (info_idx != -1)
1154 return;
1155 fbcon_free_font(p);
1156}
1157
1158/* ====================================================================== */
1159
1160/* fbcon_XXX routines - interface used by the world
1161 *
1162 * This system is now divided into two levels because of complications
1163 * caused by hardware scrolling. Top level functions:
1164 *
1165 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1166 *
1167 * handles y values in range [0, scr_height-1] that correspond to real
1168 * screen positions. y_wrap shift means that first line of bitmap may be
1169 * anywhere on this display. These functions convert lineoffsets to
1170 * bitmap offsets and deal with the wrap-around case by splitting blits.
1171 *
1172 * fbcon_bmove_physical_8() -- These functions fast implementations
1173 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1174 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1175 *
1176 * WARNING:
1177 *
1178 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1179 * Implies should only really hardware scroll in rows. Only reason for
1180 * restriction is simplicity & efficiency at the moment.
1181 */
1182
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1184 int width)
1185{
1186 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1187 struct fbcon_ops *ops = info->fbcon_par;
1188
1189 struct display *p = &fb_display[vc->vc_num];
1190 u_int y_break;
1191
1192 if (fbcon_is_inactive(vc, info))
1193 return;
1194
1195 if (!height || !width)
1196 return;
1197
1198 /* Split blits that cross physical y_wrap boundary */
1199
1200 y_break = p->vrows - p->yscroll;
1201 if (sy < y_break && sy + height - 1 >= y_break) {
1202 u_int b = y_break - sy;
1203 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1204 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1205 width);
1206 } else
1207 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1208}
1209
1210static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1211 int count, int ypos, int xpos)
1212{
1213 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1214 struct display *p = &fb_display[vc->vc_num];
1215 struct fbcon_ops *ops = info->fbcon_par;
1216
1217 if (!fbcon_is_inactive(vc, info))
1218 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1219 get_color(vc, info, scr_readw(s), 1),
1220 get_color(vc, info, scr_readw(s), 0));
1221}
1222
1223static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1224{
1225 unsigned short chr;
1226
1227 scr_writew(c, &chr);
1228 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1229}
1230
1231static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1232{
1233 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1234 struct fbcon_ops *ops = info->fbcon_par;
1235
1236 if (!fbcon_is_inactive(vc, info))
1237 ops->clear_margins(vc, info, bottom_only);
1238}
1239
1240static void fbcon_cursor(struct vc_data *vc, int mode)
1241{
1242 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1243 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 int y;
1245 int c = scr_readw((u16 *) vc->vc_pos);
1246
1247 if (fbcon_is_inactive(vc, info))
1248 return;
1249
1250 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1251 if (mode & CM_SOFTBACK) {
1252 mode &= ~CM_SOFTBACK;
1253 y = softback_lines;
1254 } else {
1255 if (softback_lines)
1256 fbcon_set_origin(vc);
1257 y = 0;
1258 }
1259
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001260 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 get_color(vc, info, c, 0));
1262 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1263}
1264
1265static int scrollback_phys_max = 0;
1266static int scrollback_max = 0;
1267static int scrollback_current = 0;
1268
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269/*
1270 * If no vc is existent yet, just set struct display
1271 */
1272static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1273 int unit)
1274{
1275 struct display *p = &fb_display[unit];
1276 struct display *t = &fb_display[fg_console];
1277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 if (var_to_display(p, var, info))
1279 return;
1280
1281 p->fontdata = t->fontdata;
1282 p->userfont = t->userfont;
1283 if (p->userfont)
1284 REFCOUNT(p->fontdata)++;
1285}
1286
1287static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1288 struct vc_data *vc)
1289{
1290 struct display *p = &fb_display[vc->vc_num], *t;
1291 struct vc_data **default_mode = vc->vc_display_fg;
1292 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001293 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 int rows, cols, charcnt = 256;
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 if (var_to_display(p, var, info))
1297 return;
1298 t = &fb_display[svc->vc_num];
1299 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001300 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 vc->vc_font.width = (*default_mode)->vc_font.width;
1302 vc->vc_font.height = (*default_mode)->vc_font.height;
1303 p->userfont = t->userfont;
1304 if (p->userfont)
1305 REFCOUNT(p->fontdata)++;
1306 }
1307 if (p->userfont)
1308 charcnt = FNTCHARCNT(p->fontdata);
1309
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001310 var->activate = FB_ACTIVATE_NOW;
1311 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001312 var->yoffset = info->var.yoffset;
1313 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001314 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001315 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001316 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1318 if (charcnt == 256) {
1319 vc->vc_hi_font_mask = 0;
1320 } else {
1321 vc->vc_hi_font_mask = 0x100;
1322 if (vc->vc_can_do_color)
1323 vc->vc_complement_mask <<= 1;
1324 }
1325
1326 if (!*svc->vc_uni_pagedir_loc)
1327 con_set_default_unimap(svc);
1328 if (!*vc->vc_uni_pagedir_loc)
1329 con_copy_unimap(vc, svc);
1330
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001331 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1332 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1333 cols /= vc->vc_font.width;
1334 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 if (CON_IS_VISIBLE(vc)) {
1338 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001339 if (softback_buf)
1340 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342}
1343
1344static __inline__ void ywrap_up(struct vc_data *vc, int count)
1345{
1346 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001347 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 struct display *p = &fb_display[vc->vc_num];
1349
1350 p->yscroll += count;
1351 if (p->yscroll >= p->vrows) /* Deal with wrap */
1352 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001353 ops->var.xoffset = 0;
1354 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1355 ops->var.vmode |= FB_VMODE_YWRAP;
1356 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 scrollback_max += count;
1358 if (scrollback_max > scrollback_phys_max)
1359 scrollback_max = scrollback_phys_max;
1360 scrollback_current = 0;
1361}
1362
1363static __inline__ void ywrap_down(struct vc_data *vc, int count)
1364{
1365 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001366 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 struct display *p = &fb_display[vc->vc_num];
1368
1369 p->yscroll -= count;
1370 if (p->yscroll < 0) /* Deal with wrap */
1371 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001372 ops->var.xoffset = 0;
1373 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1374 ops->var.vmode |= FB_VMODE_YWRAP;
1375 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 scrollback_max -= count;
1377 if (scrollback_max < 0)
1378 scrollback_max = 0;
1379 scrollback_current = 0;
1380}
1381
1382static __inline__ void ypan_up(struct vc_data *vc, int count)
1383{
1384 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1385 struct display *p = &fb_display[vc->vc_num];
1386 struct fbcon_ops *ops = info->fbcon_par;
1387
1388 p->yscroll += count;
1389 if (p->yscroll > p->vrows - vc->vc_rows) {
1390 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1391 0, 0, 0, vc->vc_rows, vc->vc_cols);
1392 p->yscroll -= p->vrows - vc->vc_rows;
1393 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001394
1395 ops->var.xoffset = 0;
1396 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1397 ops->var.vmode &= ~FB_VMODE_YWRAP;
1398 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 fbcon_clear_margins(vc, 1);
1400 scrollback_max += count;
1401 if (scrollback_max > scrollback_phys_max)
1402 scrollback_max = scrollback_phys_max;
1403 scrollback_current = 0;
1404}
1405
1406static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1407{
1408 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001409 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 struct display *p = &fb_display[vc->vc_num];
1411 int redraw = 0;
1412
1413 p->yscroll += count;
1414 if (p->yscroll > p->vrows - vc->vc_rows) {
1415 p->yscroll -= p->vrows - vc->vc_rows;
1416 redraw = 1;
1417 }
1418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 if (redraw)
1420 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001421
1422 ops->var.xoffset = 0;
1423 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1424 ops->var.vmode &= ~FB_VMODE_YWRAP;
1425 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 fbcon_clear_margins(vc, 1);
1427 scrollback_max += count;
1428 if (scrollback_max > scrollback_phys_max)
1429 scrollback_max = scrollback_phys_max;
1430 scrollback_current = 0;
1431}
1432
1433static __inline__ void ypan_down(struct vc_data *vc, int count)
1434{
1435 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1436 struct display *p = &fb_display[vc->vc_num];
1437 struct fbcon_ops *ops = info->fbcon_par;
1438
1439 p->yscroll -= count;
1440 if (p->yscroll < 0) {
1441 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1442 0, vc->vc_rows, vc->vc_cols);
1443 p->yscroll += p->vrows - vc->vc_rows;
1444 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001445
1446 ops->var.xoffset = 0;
1447 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1448 ops->var.vmode &= ~FB_VMODE_YWRAP;
1449 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 fbcon_clear_margins(vc, 1);
1451 scrollback_max -= count;
1452 if (scrollback_max < 0)
1453 scrollback_max = 0;
1454 scrollback_current = 0;
1455}
1456
1457static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1458{
1459 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001460 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 struct display *p = &fb_display[vc->vc_num];
1462 int redraw = 0;
1463
1464 p->yscroll -= count;
1465 if (p->yscroll < 0) {
1466 p->yscroll += p->vrows - vc->vc_rows;
1467 redraw = 1;
1468 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (redraw)
1471 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001472
1473 ops->var.xoffset = 0;
1474 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1475 ops->var.vmode &= ~FB_VMODE_YWRAP;
1476 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 fbcon_clear_margins(vc, 1);
1478 scrollback_max -= count;
1479 if (scrollback_max < 0)
1480 scrollback_max = 0;
1481 scrollback_current = 0;
1482}
1483
1484static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1485 long delta)
1486{
1487 int count = vc->vc_rows;
1488 unsigned short *d, *s;
1489 unsigned long n;
1490 int line = 0;
1491
1492 d = (u16 *) softback_curr;
1493 if (d == (u16 *) softback_in)
1494 d = (u16 *) vc->vc_origin;
1495 n = softback_curr + delta * vc->vc_size_row;
1496 softback_lines -= delta;
1497 if (delta < 0) {
1498 if (softback_curr < softback_top && n < softback_buf) {
1499 n += softback_end - softback_buf;
1500 if (n < softback_top) {
1501 softback_lines -=
1502 (softback_top - n) / vc->vc_size_row;
1503 n = softback_top;
1504 }
1505 } else if (softback_curr >= softback_top
1506 && n < softback_top) {
1507 softback_lines -=
1508 (softback_top - n) / vc->vc_size_row;
1509 n = softback_top;
1510 }
1511 } else {
1512 if (softback_curr > softback_in && n >= softback_end) {
1513 n += softback_buf - softback_end;
1514 if (n > softback_in) {
1515 n = softback_in;
1516 softback_lines = 0;
1517 }
1518 } else if (softback_curr <= softback_in && n > softback_in) {
1519 n = softback_in;
1520 softback_lines = 0;
1521 }
1522 }
1523 if (n == softback_curr)
1524 return;
1525 softback_curr = n;
1526 s = (u16 *) softback_curr;
1527 if (s == (u16 *) softback_in)
1528 s = (u16 *) vc->vc_origin;
1529 while (count--) {
1530 unsigned short *start;
1531 unsigned short *le;
1532 unsigned short c;
1533 int x = 0;
1534 unsigned short attr = 1;
1535
1536 start = s;
1537 le = advance_row(s, 1);
1538 do {
1539 c = scr_readw(s);
1540 if (attr != (c & 0xff00)) {
1541 attr = c & 0xff00;
1542 if (s > start) {
1543 fbcon_putcs(vc, start, s - start,
1544 line, x);
1545 x += s - start;
1546 start = s;
1547 }
1548 }
1549 if (c == scr_readw(d)) {
1550 if (s > start) {
1551 fbcon_putcs(vc, start, s - start,
1552 line, x);
1553 x += s - start + 1;
1554 start = s + 1;
1555 } else {
1556 x++;
1557 start++;
1558 }
1559 }
1560 s++;
1561 d++;
1562 } while (s < le);
1563 if (s > start)
1564 fbcon_putcs(vc, start, s - start, line, x);
1565 line++;
1566 if (d == (u16 *) softback_end)
1567 d = (u16 *) softback_buf;
1568 if (d == (u16 *) softback_in)
1569 d = (u16 *) vc->vc_origin;
1570 if (s == (u16 *) softback_end)
1571 s = (u16 *) softback_buf;
1572 if (s == (u16 *) softback_in)
1573 s = (u16 *) vc->vc_origin;
1574 }
1575}
1576
1577static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1578 int line, int count, int dy)
1579{
1580 unsigned short *s = (unsigned short *)
1581 (vc->vc_origin + vc->vc_size_row * line);
1582
1583 while (count--) {
1584 unsigned short *start = s;
1585 unsigned short *le = advance_row(s, 1);
1586 unsigned short c;
1587 int x = 0;
1588 unsigned short attr = 1;
1589
1590 do {
1591 c = scr_readw(s);
1592 if (attr != (c & 0xff00)) {
1593 attr = c & 0xff00;
1594 if (s > start) {
1595 fbcon_putcs(vc, start, s - start,
1596 dy, x);
1597 x += s - start;
1598 start = s;
1599 }
1600 }
1601 console_conditional_schedule();
1602 s++;
1603 } while (s < le);
1604 if (s > start)
1605 fbcon_putcs(vc, start, s - start, dy, x);
1606 console_conditional_schedule();
1607 dy++;
1608 }
1609}
1610
1611static void fbcon_redraw(struct vc_data *vc, struct display *p,
1612 int line, int count, int offset)
1613{
1614 unsigned short *d = (unsigned short *)
1615 (vc->vc_origin + vc->vc_size_row * line);
1616 unsigned short *s = d + offset;
1617
1618 while (count--) {
1619 unsigned short *start = s;
1620 unsigned short *le = advance_row(s, 1);
1621 unsigned short c;
1622 int x = 0;
1623 unsigned short attr = 1;
1624
1625 do {
1626 c = scr_readw(s);
1627 if (attr != (c & 0xff00)) {
1628 attr = c & 0xff00;
1629 if (s > start) {
1630 fbcon_putcs(vc, start, s - start,
1631 line, x);
1632 x += s - start;
1633 start = s;
1634 }
1635 }
1636 if (c == scr_readw(d)) {
1637 if (s > start) {
1638 fbcon_putcs(vc, start, s - start,
1639 line, x);
1640 x += s - start + 1;
1641 start = s + 1;
1642 } else {
1643 x++;
1644 start++;
1645 }
1646 }
1647 scr_writew(c, d);
1648 console_conditional_schedule();
1649 s++;
1650 d++;
1651 } while (s < le);
1652 if (s > start)
1653 fbcon_putcs(vc, start, s - start, line, x);
1654 console_conditional_schedule();
1655 if (offset > 0)
1656 line++;
1657 else {
1658 line--;
1659 /* NOTE: We subtract two lines from these pointers */
1660 s -= vc->vc_size_row;
1661 d -= vc->vc_size_row;
1662 }
1663 }
1664}
1665
1666static inline void fbcon_softback_note(struct vc_data *vc, int t,
1667 int count)
1668{
1669 unsigned short *p;
1670
1671 if (vc->vc_num != fg_console)
1672 return;
1673 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1674
1675 while (count) {
1676 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1677 count--;
1678 p = advance_row(p, 1);
1679 softback_in += vc->vc_size_row;
1680 if (softback_in == softback_end)
1681 softback_in = softback_buf;
1682 if (softback_in == softback_top) {
1683 softback_top += vc->vc_size_row;
1684 if (softback_top == softback_end)
1685 softback_top = softback_buf;
1686 }
1687 }
1688 softback_curr = softback_in;
1689}
1690
1691static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1692 int count)
1693{
1694 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1695 struct display *p = &fb_display[vc->vc_num];
1696 struct fbcon_ops *ops = info->fbcon_par;
1697 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1698
1699 if (fbcon_is_inactive(vc, info))
1700 return -EINVAL;
1701
1702 fbcon_cursor(vc, CM_ERASE);
1703
1704 /*
1705 * ++Geert: Only use ywrap/ypan if the console is in text mode
1706 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1707 * whole screen (prevents flicker).
1708 */
1709
1710 switch (dir) {
1711 case SM_UP:
1712 if (count > vc->vc_rows) /* Maximum realistic size */
1713 count = vc->vc_rows;
1714 if (softback_top)
1715 fbcon_softback_note(vc, t, count);
1716 if (logo_shown >= 0)
1717 goto redraw_up;
1718 switch (p->scrollmode) {
1719 case SCROLL_MOVE:
1720 ops->bmove(vc, info, t + count, 0, t, 0,
1721 b - t - count, vc->vc_cols);
1722 ops->clear(vc, info, b - count, 0, count,
1723 vc->vc_cols);
1724 break;
1725
1726 case SCROLL_WRAP_MOVE:
1727 if (b - t - count > 3 * vc->vc_rows >> 2) {
1728 if (t > 0)
1729 fbcon_bmove(vc, 0, 0, count, 0, t,
1730 vc->vc_cols);
1731 ywrap_up(vc, count);
1732 if (vc->vc_rows - b > 0)
1733 fbcon_bmove(vc, b - count, 0, b, 0,
1734 vc->vc_rows - b,
1735 vc->vc_cols);
1736 } else if (info->flags & FBINFO_READS_FAST)
1737 fbcon_bmove(vc, t + count, 0, t, 0,
1738 b - t - count, vc->vc_cols);
1739 else
1740 goto redraw_up;
1741 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1742 break;
1743
1744 case SCROLL_PAN_REDRAW:
1745 if ((p->yscroll + count <=
1746 2 * (p->vrows - vc->vc_rows))
1747 && ((!scroll_partial && (b - t == vc->vc_rows))
1748 || (scroll_partial
1749 && (b - t - count >
1750 3 * vc->vc_rows >> 2)))) {
1751 if (t > 0)
1752 fbcon_redraw_move(vc, p, 0, t, count);
1753 ypan_up_redraw(vc, t, count);
1754 if (vc->vc_rows - b > 0)
1755 fbcon_redraw_move(vc, p, b - count,
1756 vc->vc_rows - b, b);
1757 } else
1758 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1759 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1760 break;
1761
1762 case SCROLL_PAN_MOVE:
1763 if ((p->yscroll + count <=
1764 2 * (p->vrows - vc->vc_rows))
1765 && ((!scroll_partial && (b - t == vc->vc_rows))
1766 || (scroll_partial
1767 && (b - t - count >
1768 3 * vc->vc_rows >> 2)))) {
1769 if (t > 0)
1770 fbcon_bmove(vc, 0, 0, count, 0, t,
1771 vc->vc_cols);
1772 ypan_up(vc, count);
1773 if (vc->vc_rows - b > 0)
1774 fbcon_bmove(vc, b - count, 0, b, 0,
1775 vc->vc_rows - b,
1776 vc->vc_cols);
1777 } else if (info->flags & FBINFO_READS_FAST)
1778 fbcon_bmove(vc, t + count, 0, t, 0,
1779 b - t - count, vc->vc_cols);
1780 else
1781 goto redraw_up;
1782 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1783 break;
1784
1785 case SCROLL_REDRAW:
1786 redraw_up:
1787 fbcon_redraw(vc, p, t, b - t - count,
1788 count * vc->vc_cols);
1789 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1790 scr_memsetw((unsigned short *) (vc->vc_origin +
1791 vc->vc_size_row *
1792 (b - count)),
1793 vc->vc_video_erase_char,
1794 vc->vc_size_row * count);
1795 return 1;
1796 }
1797 break;
1798
1799 case SM_DOWN:
1800 if (count > vc->vc_rows) /* Maximum realistic size */
1801 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001802 if (logo_shown >= 0)
1803 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 switch (p->scrollmode) {
1805 case SCROLL_MOVE:
1806 ops->bmove(vc, info, t, 0, t + count, 0,
1807 b - t - count, vc->vc_cols);
1808 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1809 break;
1810
1811 case SCROLL_WRAP_MOVE:
1812 if (b - t - count > 3 * vc->vc_rows >> 2) {
1813 if (vc->vc_rows - b > 0)
1814 fbcon_bmove(vc, b, 0, b - count, 0,
1815 vc->vc_rows - b,
1816 vc->vc_cols);
1817 ywrap_down(vc, count);
1818 if (t > 0)
1819 fbcon_bmove(vc, count, 0, 0, 0, t,
1820 vc->vc_cols);
1821 } else if (info->flags & FBINFO_READS_FAST)
1822 fbcon_bmove(vc, t, 0, t + count, 0,
1823 b - t - count, vc->vc_cols);
1824 else
1825 goto redraw_down;
1826 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1827 break;
1828
1829 case SCROLL_PAN_MOVE:
1830 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1831 && ((!scroll_partial && (b - t == vc->vc_rows))
1832 || (scroll_partial
1833 && (b - t - count >
1834 3 * vc->vc_rows >> 2)))) {
1835 if (vc->vc_rows - b > 0)
1836 fbcon_bmove(vc, b, 0, b - count, 0,
1837 vc->vc_rows - b,
1838 vc->vc_cols);
1839 ypan_down(vc, count);
1840 if (t > 0)
1841 fbcon_bmove(vc, count, 0, 0, 0, t,
1842 vc->vc_cols);
1843 } else if (info->flags & FBINFO_READS_FAST)
1844 fbcon_bmove(vc, t, 0, t + count, 0,
1845 b - t - count, vc->vc_cols);
1846 else
1847 goto redraw_down;
1848 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1849 break;
1850
1851 case SCROLL_PAN_REDRAW:
1852 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1853 && ((!scroll_partial && (b - t == vc->vc_rows))
1854 || (scroll_partial
1855 && (b - t - count >
1856 3 * vc->vc_rows >> 2)))) {
1857 if (vc->vc_rows - b > 0)
1858 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1859 b - count);
1860 ypan_down_redraw(vc, t, count);
1861 if (t > 0)
1862 fbcon_redraw_move(vc, p, count, t, 0);
1863 } else
1864 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1865 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1866 break;
1867
1868 case SCROLL_REDRAW:
1869 redraw_down:
1870 fbcon_redraw(vc, p, b - 1, b - t - count,
1871 -count * vc->vc_cols);
1872 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1873 scr_memsetw((unsigned short *) (vc->vc_origin +
1874 vc->vc_size_row *
1875 t),
1876 vc->vc_video_erase_char,
1877 vc->vc_size_row * count);
1878 return 1;
1879 }
1880 }
1881 return 0;
1882}
1883
1884
1885static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1886 int height, int width)
1887{
1888 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1889 struct display *p = &fb_display[vc->vc_num];
1890
1891 if (fbcon_is_inactive(vc, info))
1892 return;
1893
1894 if (!width || !height)
1895 return;
1896
1897 /* Split blits that cross physical y_wrap case.
1898 * Pathological case involves 4 blits, better to use recursive
1899 * code rather than unrolled case
1900 *
1901 * Recursive invocations don't need to erase the cursor over and
1902 * over again, so we use fbcon_bmove_rec()
1903 */
1904 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1905 p->vrows - p->yscroll);
1906}
1907
1908static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1909 int dy, int dx, int height, int width, u_int y_break)
1910{
1911 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1912 struct fbcon_ops *ops = info->fbcon_par;
1913 u_int b;
1914
1915 if (sy < y_break && sy + height > y_break) {
1916 b = y_break - sy;
1917 if (dy < sy) { /* Avoid trashing self */
1918 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1919 y_break);
1920 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1921 height - b, width, y_break);
1922 } else {
1923 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1924 height - b, width, y_break);
1925 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1926 y_break);
1927 }
1928 return;
1929 }
1930
1931 if (dy < y_break && dy + height > y_break) {
1932 b = y_break - dy;
1933 if (dy < sy) { /* Avoid trashing self */
1934 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1935 y_break);
1936 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1937 height - b, width, y_break);
1938 } else {
1939 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1940 height - b, width, y_break);
1941 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1942 y_break);
1943 }
1944 return;
1945 }
1946 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
1947 height, width);
1948}
1949
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001950static __inline__ void updatescrollmode(struct display *p,
1951 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 struct vc_data *vc)
1953{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001954 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 int fh = vc->vc_font.height;
1956 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001957 u16 t = 0;
1958 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
1959 info->fix.xpanstep);
1960 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
1961 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1962 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
1963 info->var.xres_virtual);
1964 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
1965 divides(ypan, vc->vc_font.height) && vyres > yres;
1966 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
1967 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08001968 divides(vc->vc_font.height, vyres) &&
1969 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001971 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
1972 !(cap & FBINFO_HWACCEL_DISABLED);
1973 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
1974 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001976 p->vrows = vyres/fh;
1977 if (yres > (fh * (vc->vc_rows + 1)))
1978 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
1979 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 p->vrows--;
1981
1982 if (good_wrap || good_pan) {
1983 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001984 p->scrollmode = good_wrap ?
1985 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 else
1987 p->scrollmode = good_wrap ? SCROLL_REDRAW :
1988 SCROLL_PAN_REDRAW;
1989 } else {
1990 if (reading_fast || (fast_copyarea && !fast_imageblit))
1991 p->scrollmode = SCROLL_MOVE;
1992 else
1993 p->scrollmode = SCROLL_REDRAW;
1994 }
1995}
1996
1997static int fbcon_resize(struct vc_data *vc, unsigned int width,
1998 unsigned int height)
1999{
2000 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002001 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 struct display *p = &fb_display[vc->vc_num];
2003 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002004 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002006 virt_w = FBCON_SWAP(ops->rotate, width, height);
2007 virt_h = FBCON_SWAP(ops->rotate, height, width);
2008 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2009 vc->vc_font.height);
2010 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2011 vc->vc_font.width);
2012 var.xres = virt_w * virt_fw;
2013 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 x_diff = info->var.xres - var.xres;
2015 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002016 if (x_diff < 0 || x_diff > virt_fw ||
2017 y_diff < 0 || y_diff > virt_fh) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 struct fb_videomode *mode;
2019
2020 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2021 mode = fb_find_best_mode(&var, &info->modelist);
2022 if (mode == NULL)
2023 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002024 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002026
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002027 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2031 if (CON_IS_VISIBLE(vc)) {
2032 var.activate = FB_ACTIVATE_NOW |
2033 FB_ACTIVATE_FORCE;
2034 fb_set_var(info, &var);
2035 }
2036 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002037 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039 updatescrollmode(p, info, vc);
2040 return 0;
2041}
2042
2043static int fbcon_switch(struct vc_data *vc)
2044{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002045 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002046 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct display *p = &fb_display[vc->vc_num];
2048 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002049 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002052 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 if (softback_lines)
2056 fbcon_set_origin(vc);
2057 softback_top = softback_curr = softback_in = softback_buf;
2058 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002059 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 }
2061
2062 if (logo_shown >= 0) {
2063 struct vc_data *conp2 = vc_cons[logo_shown].d;
2064
2065 if (conp2->vc_top == logo_lines
2066 && conp2->vc_bottom == conp2->vc_rows)
2067 conp2->vc_top = 0;
2068 logo_shown = FBCON_LOGO_CANSHOW;
2069 }
2070
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002071 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002072 if (prev_console != -1)
2073 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 /*
2075 * FIXME: If we have multiple fbdev's loaded, we need to
2076 * update all info->currcon. Perhaps, we can place this
2077 * in a centralized structure, but this might break some
2078 * drivers.
2079 *
2080 * info->currcon = vc->vc_num;
2081 */
2082 for (i = 0; i < FB_MAX; i++) {
2083 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002084 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002086 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 }
2088 }
2089 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2090 display_to_var(&var, p);
2091 var.activate = FB_ACTIVATE_NOW;
2092
2093 /*
2094 * make sure we don't unnecessarily trip the memcmp()
2095 * in fb_set_var()
2096 */
2097 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002098 var.yoffset = info->var.yoffset;
2099 var.xoffset = info->var.xoffset;
2100 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002102 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Knut Petersen39942fd2005-12-12 22:17:19 -08002104 if (old_info != NULL && (old_info != info ||
2105 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002106 if (info->fbops->fb_set_par)
2107 info->fbops->fb_set_par(info);
2108 fbcon_del_cursor_timer(old_info);
2109 fbcon_add_cursor_timer(info);
2110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002112 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002113 ops->cursor_reset = 1;
2114
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002115 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002116 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002117 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002120 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002122
2123 if (p->userfont)
2124 charcnt = FNTCHARCNT(vc->vc_font.data);
2125
2126 if (charcnt > 256)
2127 vc->vc_complement_mask <<= 1;
2128
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 updatescrollmode(p, info, vc);
2130
2131 switch (p->scrollmode) {
2132 case SCROLL_WRAP_MOVE:
2133 scrollback_phys_max = p->vrows - vc->vc_rows;
2134 break;
2135 case SCROLL_PAN_MOVE:
2136 case SCROLL_PAN_REDRAW:
2137 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2138 if (scrollback_phys_max < 0)
2139 scrollback_phys_max = 0;
2140 break;
2141 default:
2142 scrollback_phys_max = 0;
2143 break;
2144 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002145
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 scrollback_max = 0;
2147 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002148
2149 if (!fbcon_is_inactive(vc, info)) {
2150 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2151 ops->update_start(info);
2152 }
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 fbcon_set_palette(vc, color_table);
2155 fbcon_clear_margins(vc, 0);
2156
2157 if (logo_shown == FBCON_LOGO_DRAW) {
2158
2159 logo_shown = fg_console;
2160 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002161 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 update_region(vc,
2163 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2164 vc->vc_size_row * (vc->vc_bottom -
2165 vc->vc_top) / 2);
2166 return 0;
2167 }
2168 return 1;
2169}
2170
2171static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2172 int blank)
2173{
2174 if (blank) {
2175 unsigned short charmask = vc->vc_hi_font_mask ?
2176 0x1ff : 0xff;
2177 unsigned short oldc;
2178
2179 oldc = vc->vc_video_erase_char;
2180 vc->vc_video_erase_char &= charmask;
2181 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2182 vc->vc_video_erase_char = oldc;
2183 }
2184}
2185
2186static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2187{
2188 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2189 struct fbcon_ops *ops = info->fbcon_par;
2190
2191 if (mode_switch) {
2192 struct fb_var_screeninfo var = info->var;
2193
2194 ops->graphics = 1;
2195
2196 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002197 if (info->fbops->fb_save_state)
2198 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2200 fb_set_var(info, &var);
2201 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002202 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002203 } else if (info->fbops->fb_restore_state)
2204 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 }
2206
2207 if (!fbcon_is_inactive(vc, info)) {
2208 if (ops->blank_state != blank) {
2209 ops->blank_state = blank;
2210 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2211 ops->cursor_flash = (!blank);
2212
2213 if (fb_blank(info, blank))
2214 fbcon_generic_blank(vc, info, blank);
2215 }
2216
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002217 if (!blank)
2218 update_screen(vc);
2219 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002221 if (!blank)
2222 fbcon_add_cursor_timer(info);
2223 else
2224 fbcon_del_cursor_timer(info);
2225
2226 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227}
2228
2229static void fbcon_free_font(struct display *p)
2230{
2231 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
2232 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
2233 p->fontdata = NULL;
2234 p->userfont = 0;
2235}
2236
2237static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2238{
2239 u8 *fontdata = vc->vc_font.data;
2240 u8 *data = font->data;
2241 int i, j;
2242
2243 font->width = vc->vc_font.width;
2244 font->height = vc->vc_font.height;
2245 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2246 if (!font->data)
2247 return 0;
2248
2249 if (font->width <= 8) {
2250 j = vc->vc_font.height;
2251 for (i = 0; i < font->charcount; i++) {
2252 memcpy(data, fontdata, j);
2253 memset(data + j, 0, 32 - j);
2254 data += 32;
2255 fontdata += j;
2256 }
2257 } else if (font->width <= 16) {
2258 j = vc->vc_font.height * 2;
2259 for (i = 0; i < font->charcount; i++) {
2260 memcpy(data, fontdata, j);
2261 memset(data + j, 0, 64 - j);
2262 data += 64;
2263 fontdata += j;
2264 }
2265 } else if (font->width <= 24) {
2266 for (i = 0; i < font->charcount; i++) {
2267 for (j = 0; j < vc->vc_font.height; j++) {
2268 *data++ = fontdata[0];
2269 *data++ = fontdata[1];
2270 *data++ = fontdata[2];
2271 fontdata += sizeof(u32);
2272 }
2273 memset(data, 0, 3 * (32 - j));
2274 data += 3 * (32 - j);
2275 }
2276 } else {
2277 j = vc->vc_font.height * 4;
2278 for (i = 0; i < font->charcount; i++) {
2279 memcpy(data, fontdata, j);
2280 memset(data + j, 0, 128 - j);
2281 data += 128;
2282 fontdata += j;
2283 }
2284 }
2285 return 0;
2286}
2287
2288static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002289 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290{
2291 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002292 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 struct display *p = &fb_display[vc->vc_num];
2294 int resize;
2295 int cnt;
2296 char *old_data = NULL;
2297
2298 if (CON_IS_VISIBLE(vc) && softback_lines)
2299 fbcon_set_origin(vc);
2300
2301 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2302 if (p->userfont)
2303 old_data = vc->vc_font.data;
2304 if (userfont)
2305 cnt = FNTCHARCNT(data);
2306 else
2307 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002308 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 if ((p->userfont = userfont))
2310 REFCOUNT(data)++;
2311 vc->vc_font.width = w;
2312 vc->vc_font.height = h;
2313 if (vc->vc_hi_font_mask && cnt == 256) {
2314 vc->vc_hi_font_mask = 0;
2315 if (vc->vc_can_do_color) {
2316 vc->vc_complement_mask >>= 1;
2317 vc->vc_s_complement_mask >>= 1;
2318 }
2319
2320 /* ++Edmund: reorder the attribute bits */
2321 if (vc->vc_can_do_color) {
2322 unsigned short *cp =
2323 (unsigned short *) vc->vc_origin;
2324 int count = vc->vc_screenbuf_size / 2;
2325 unsigned short c;
2326 for (; count > 0; count--, cp++) {
2327 c = scr_readw(cp);
2328 scr_writew(((c & 0xfe00) >> 1) |
2329 (c & 0xff), cp);
2330 }
2331 c = vc->vc_video_erase_char;
2332 vc->vc_video_erase_char =
2333 ((c & 0xfe00) >> 1) | (c & 0xff);
2334 vc->vc_attr >>= 1;
2335 }
2336 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2337 vc->vc_hi_font_mask = 0x100;
2338 if (vc->vc_can_do_color) {
2339 vc->vc_complement_mask <<= 1;
2340 vc->vc_s_complement_mask <<= 1;
2341 }
2342
2343 /* ++Edmund: reorder the attribute bits */
2344 {
2345 unsigned short *cp =
2346 (unsigned short *) vc->vc_origin;
2347 int count = vc->vc_screenbuf_size / 2;
2348 unsigned short c;
2349 for (; count > 0; count--, cp++) {
2350 unsigned short newc;
2351 c = scr_readw(cp);
2352 if (vc->vc_can_do_color)
2353 newc =
2354 ((c & 0xff00) << 1) | (c &
2355 0xff);
2356 else
2357 newc = c & ~0x100;
2358 scr_writew(newc, cp);
2359 }
2360 c = vc->vc_video_erase_char;
2361 if (vc->vc_can_do_color) {
2362 vc->vc_video_erase_char =
2363 ((c & 0xff00) << 1) | (c & 0xff);
2364 vc->vc_attr <<= 1;
2365 } else
2366 vc->vc_video_erase_char = c & ~0x100;
2367 }
2368
2369 }
2370
2371 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002372 int cols, rows;
2373
2374 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2375 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2376 cols /= w;
2377 rows /= h;
2378 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002379 if (CON_IS_VISIBLE(vc) && softback_buf)
2380 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 } else if (CON_IS_VISIBLE(vc)
2382 && vc->vc_mode == KD_TEXT) {
2383 fbcon_clear_margins(vc, 0);
2384 update_screen(vc);
2385 }
2386
2387 if (old_data && (--REFCOUNT(old_data) == 0))
2388 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2389 return 0;
2390}
2391
2392static int fbcon_copy_font(struct vc_data *vc, int con)
2393{
2394 struct display *od = &fb_display[con];
2395 struct console_font *f = &vc->vc_font;
2396
2397 if (od->fontdata == f->data)
2398 return 0; /* already the same font... */
2399 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2400}
2401
2402/*
2403 * User asked to set font; we are guaranteed that
2404 * a) width and height are in range 1..32
2405 * b) charcount does not exceed 512
2406 * but lets not assume that, since someone might someday want to use larger
2407 * fonts. And charcount of 512 is small for unicode support.
2408 *
2409 * However, user space gives the font in 32 rows , regardless of
2410 * actual font height. So a new API is needed if support for larger fonts
2411 * is ever implemented.
2412 */
2413
2414static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2415{
2416 unsigned charcount = font->charcount;
2417 int w = font->width;
2418 int h = font->height;
2419 int size;
2420 int i, csum;
2421 u8 *new_data, *data = font->data;
2422 int pitch = (font->width+7) >> 3;
2423
2424 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2425 * If not this check should be changed to charcount < 256 */
2426 if (charcount != 256 && charcount != 512)
2427 return -EINVAL;
2428
2429 size = h * pitch * charcount;
2430
2431 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2432
2433 if (!new_data)
2434 return -ENOMEM;
2435
2436 new_data += FONT_EXTRA_WORDS * sizeof(int);
2437 FNTSIZE(new_data) = size;
2438 FNTCHARCNT(new_data) = charcount;
2439 REFCOUNT(new_data) = 0; /* usage counter */
2440 for (i=0; i< charcount; i++) {
2441 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2442 }
2443
2444 /* Since linux has a nice crc32 function use it for counting font
2445 * checksums. */
2446 csum = crc32(0, new_data, size);
2447
2448 FNTSUM(new_data) = csum;
2449 /* Check if the same font is on some other console already */
2450 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2451 struct vc_data *tmp = vc_cons[i].d;
2452
2453 if (fb_display[i].userfont &&
2454 fb_display[i].fontdata &&
2455 FNTSUM(fb_display[i].fontdata) == csum &&
2456 FNTSIZE(fb_display[i].fontdata) == size &&
2457 tmp->vc_font.width == w &&
2458 !memcmp(fb_display[i].fontdata, new_data, size)) {
2459 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002460 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 break;
2462 }
2463 }
2464 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2465}
2466
2467static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2468{
2469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002470 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472 if (!name)
2473 f = get_default_font(info->var.xres, info->var.yres);
2474 else if (!(f = find_font(name)))
2475 return -ENOENT;
2476
2477 font->width = f->width;
2478 font->height = f->height;
2479 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2480}
2481
2482static u16 palette_red[16];
2483static u16 palette_green[16];
2484static u16 palette_blue[16];
2485
2486static struct fb_cmap palette_cmap = {
2487 0, 16, palette_red, palette_green, palette_blue, NULL
2488};
2489
2490static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2491{
2492 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2493 int i, j, k, depth;
2494 u8 val;
2495
2496 if (fbcon_is_inactive(vc, info))
2497 return -EINVAL;
2498
2499 if (!CON_IS_VISIBLE(vc))
2500 return 0;
2501
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002502 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if (depth > 3) {
2504 for (i = j = 0; i < 16; i++) {
2505 k = table[i];
2506 val = vc->vc_palette[j++];
2507 palette_red[k] = (val << 8) | val;
2508 val = vc->vc_palette[j++];
2509 palette_green[k] = (val << 8) | val;
2510 val = vc->vc_palette[j++];
2511 palette_blue[k] = (val << 8) | val;
2512 }
2513 palette_cmap.len = 16;
2514 palette_cmap.start = 0;
2515 /*
2516 * If framebuffer is capable of less than 16 colors,
2517 * use default palette of fbcon.
2518 */
2519 } else
2520 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2521
2522 return fb_set_cmap(&palette_cmap, info);
2523}
2524
2525static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2526{
2527 unsigned long p;
2528 int line;
2529
2530 if (vc->vc_num != fg_console || !softback_lines)
2531 return (u16 *) (vc->vc_origin + offset);
2532 line = offset / vc->vc_size_row;
2533 if (line >= softback_lines)
2534 return (u16 *) (vc->vc_origin + offset -
2535 softback_lines * vc->vc_size_row);
2536 p = softback_curr + offset;
2537 if (p >= softback_end)
2538 p += softback_buf - softback_end;
2539 return (u16 *) p;
2540}
2541
2542static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2543 int *px, int *py)
2544{
2545 unsigned long ret;
2546 int x, y;
2547
2548 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2549 unsigned long offset = (pos - vc->vc_origin) / 2;
2550
2551 x = offset % vc->vc_cols;
2552 y = offset / vc->vc_cols;
2553 if (vc->vc_num == fg_console)
2554 y += softback_lines;
2555 ret = pos + (vc->vc_cols - x) * 2;
2556 } else if (vc->vc_num == fg_console && softback_lines) {
2557 unsigned long offset = pos - softback_curr;
2558
2559 if (pos < softback_curr)
2560 offset += softback_end - softback_buf;
2561 offset /= 2;
2562 x = offset % vc->vc_cols;
2563 y = offset / vc->vc_cols;
2564 ret = pos + (vc->vc_cols - x) * 2;
2565 if (ret == softback_end)
2566 ret = softback_buf;
2567 if (ret == softback_in)
2568 ret = vc->vc_origin;
2569 } else {
2570 /* Should not happen */
2571 x = y = 0;
2572 ret = vc->vc_origin;
2573 }
2574 if (px)
2575 *px = x;
2576 if (py)
2577 *py = y;
2578 return ret;
2579}
2580
2581/* As we might be inside of softback, we may work with non-contiguous buffer,
2582 that's why we have to use a separate routine. */
2583static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2584{
2585 while (cnt--) {
2586 u16 a = scr_readw(p);
2587 if (!vc->vc_can_do_color)
2588 a ^= 0x0800;
2589 else if (vc->vc_hi_font_mask == 0x100)
2590 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2591 (((a) & 0x0e00) << 4);
2592 else
2593 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2594 (((a) & 0x0700) << 4);
2595 scr_writew(a, p++);
2596 if (p == (u16 *) softback_end)
2597 p = (u16 *) softback_buf;
2598 if (p == (u16 *) softback_in)
2599 p = (u16 *) vc->vc_origin;
2600 }
2601}
2602
2603static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2604{
2605 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002606 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 struct display *p = &fb_display[fg_console];
2608 int offset, limit, scrollback_old;
2609
2610 if (softback_top) {
2611 if (vc->vc_num != fg_console)
2612 return 0;
2613 if (vc->vc_mode != KD_TEXT || !lines)
2614 return 0;
2615 if (logo_shown >= 0) {
2616 struct vc_data *conp2 = vc_cons[logo_shown].d;
2617
2618 if (conp2->vc_top == logo_lines
2619 && conp2->vc_bottom == conp2->vc_rows)
2620 conp2->vc_top = 0;
2621 if (logo_shown == vc->vc_num) {
2622 unsigned long p, q;
2623 int i;
2624
2625 p = softback_in;
2626 q = vc->vc_origin +
2627 logo_lines * vc->vc_size_row;
2628 for (i = 0; i < logo_lines; i++) {
2629 if (p == softback_top)
2630 break;
2631 if (p == softback_buf)
2632 p = softback_end;
2633 p -= vc->vc_size_row;
2634 q -= vc->vc_size_row;
2635 scr_memcpyw((u16 *) q, (u16 *) p,
2636 vc->vc_size_row);
2637 }
2638 softback_in = p;
2639 update_region(vc, vc->vc_origin,
2640 logo_lines * vc->vc_cols);
2641 }
2642 logo_shown = FBCON_LOGO_CANSHOW;
2643 }
2644 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2645 fbcon_redraw_softback(vc, p, lines);
2646 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2647 return 0;
2648 }
2649
2650 if (!scrollback_phys_max)
2651 return -ENOSYS;
2652
2653 scrollback_old = scrollback_current;
2654 scrollback_current -= lines;
2655 if (scrollback_current < 0)
2656 scrollback_current = 0;
2657 else if (scrollback_current > scrollback_max)
2658 scrollback_current = scrollback_max;
2659 if (scrollback_current == scrollback_old)
2660 return 0;
2661
2662 if (fbcon_is_inactive(vc, info))
2663 return 0;
2664
2665 fbcon_cursor(vc, CM_ERASE);
2666
2667 offset = p->yscroll - scrollback_current;
2668 limit = p->vrows;
2669 switch (p->scrollmode) {
2670 case SCROLL_WRAP_MOVE:
2671 info->var.vmode |= FB_VMODE_YWRAP;
2672 break;
2673 case SCROLL_PAN_MOVE:
2674 case SCROLL_PAN_REDRAW:
2675 limit -= vc->vc_rows;
2676 info->var.vmode &= ~FB_VMODE_YWRAP;
2677 break;
2678 }
2679 if (offset < 0)
2680 offset += limit;
2681 else if (offset >= limit)
2682 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002683
2684 ops->var.xoffset = 0;
2685 ops->var.yoffset = offset * vc->vc_font.height;
2686 ops->update_start(info);
2687
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 if (!scrollback_current)
2689 fbcon_cursor(vc, CM_DRAW);
2690 return 0;
2691}
2692
2693static int fbcon_set_origin(struct vc_data *vc)
2694{
2695 if (softback_lines)
2696 fbcon_scrolldelta(vc, softback_lines);
2697 return 0;
2698}
2699
2700static void fbcon_suspended(struct fb_info *info)
2701{
2702 struct vc_data *vc = NULL;
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 /* Clear cursor, restore saved data */
2710 fbcon_cursor(vc, CM_ERASE);
2711}
2712
2713static void fbcon_resumed(struct fb_info *info)
2714{
2715 struct vc_data *vc;
2716 struct fbcon_ops *ops = info->fbcon_par;
2717
2718 if (!ops || ops->currcon < 0)
2719 return;
2720 vc = vc_cons[ops->currcon].d;
2721
2722 update_screen(vc);
2723}
2724
2725static void fbcon_modechanged(struct fb_info *info)
2726{
2727 struct fbcon_ops *ops = info->fbcon_par;
2728 struct vc_data *vc;
2729 struct display *p;
2730 int rows, cols;
2731
2732 if (!ops || ops->currcon < 0)
2733 return;
2734 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002735 if (vc->vc_mode != KD_TEXT ||
2736 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 return;
2738
2739 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002740 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
2742 if (CON_IS_VISIBLE(vc)) {
2743 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002744 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2745 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2746 cols /= vc->vc_font.width;
2747 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 vc_resize(vc, cols, rows);
2749 updatescrollmode(p, info, vc);
2750 scrollback_max = 0;
2751 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002752
2753 if (!fbcon_is_inactive(vc, info)) {
2754 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2755 ops->update_start(info);
2756 }
2757
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 fbcon_set_palette(vc, color_table);
2759 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002760 if (softback_buf)
2761 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
2763}
2764
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002765static void fbcon_set_all_vcs(struct fb_info *info)
2766{
2767 struct fbcon_ops *ops = info->fbcon_par;
2768 struct vc_data *vc;
2769 struct display *p;
2770 int i, rows, cols;
2771
2772 if (!ops || ops->currcon < 0)
2773 return;
2774
2775 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2776 vc = vc_cons[i].d;
2777 if (!vc || vc->vc_mode != KD_TEXT ||
2778 registered_fb[con2fb_map[i]] != info)
2779 continue;
2780
2781 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002782 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002783 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002784 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2785 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2786 cols /= vc->vc_font.width;
2787 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002788 vc_resize(vc, cols, rows);
2789
2790 if (CON_IS_VISIBLE(vc)) {
2791 updatescrollmode(p, info, vc);
2792 scrollback_max = 0;
2793 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002794
2795 if (!fbcon_is_inactive(vc, info)) {
2796 ops->var.xoffset = ops->var.yoffset =
2797 p->yscroll = 0;
2798 ops->update_start(info);
2799 }
2800
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002801 fbcon_set_palette(vc, color_table);
2802 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002803 if (softback_buf)
2804 fbcon_update_softback(vc);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002805 }
2806 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002807
2808 ops->p = &fb_display[ops->currcon];
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002809}
2810
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811static int fbcon_mode_deleted(struct fb_info *info,
2812 struct fb_videomode *mode)
2813{
2814 struct fb_info *fb_info;
2815 struct display *p;
2816 int i, j, found = 0;
2817
2818 /* before deletion, ensure that mode is not in use */
2819 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2820 j = con2fb_map[i];
2821 if (j == -1)
2822 continue;
2823 fb_info = registered_fb[j];
2824 if (fb_info != info)
2825 continue;
2826 p = &fb_display[i];
2827 if (!p || !p->mode)
2828 continue;
2829 if (fb_mode_is_equal(p->mode, mode)) {
2830 found = 1;
2831 break;
2832 }
2833 }
2834 return found;
2835}
2836
2837static int fbcon_fb_registered(int idx)
2838{
2839 int ret = 0, i;
2840
2841 if (info_idx == -1) {
2842 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2843 if (con2fb_map_boot[i] == idx) {
2844 info_idx = idx;
2845 break;
2846 }
2847 }
2848 if (info_idx != -1)
2849 ret = fbcon_takeover(1);
2850 } else {
2851 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2852 if (con2fb_map_boot[i] == idx)
2853 set_con2fb_map(i, idx, 0);
2854 }
2855 }
2856
2857 return ret;
2858}
2859
2860static void fbcon_fb_blanked(struct fb_info *info, int blank)
2861{
2862 struct fbcon_ops *ops = info->fbcon_par;
2863 struct vc_data *vc;
2864
2865 if (!ops || ops->currcon < 0)
2866 return;
2867
2868 vc = vc_cons[ops->currcon].d;
2869 if (vc->vc_mode != KD_TEXT ||
2870 registered_fb[con2fb_map[ops->currcon]] != info)
2871 return;
2872
2873 if (CON_IS_VISIBLE(vc)) {
2874 if (blank)
2875 do_blank_screen(0);
2876 else
2877 do_unblank_screen(0);
2878 }
2879 ops->blank_state = blank;
2880}
2881
2882static void fbcon_new_modelist(struct fb_info *info)
2883{
2884 int i;
2885 struct vc_data *vc;
2886 struct fb_var_screeninfo var;
2887 struct fb_videomode *mode;
2888
2889 for (i = 0; i < MAX_NR_CONSOLES; i++) {
2890 if (registered_fb[con2fb_map[i]] != info)
2891 continue;
2892 if (!fb_display[i].mode)
2893 continue;
2894 vc = vc_cons[i].d;
2895 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08002896 mode = fb_find_nearest_mode(fb_display[i].mode,
2897 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 fb_videomode_to_var(&var, mode);
2899
2900 if (vc)
2901 fbcon_set_disp(info, &var, vc);
2902 else
2903 fbcon_preset_disp(info, &var, i);
2904
2905 }
2906}
2907
2908static int fbcon_event_notify(struct notifier_block *self,
2909 unsigned long action, void *data)
2910{
2911 struct fb_event *event = data;
2912 struct fb_info *info = event->info;
2913 struct fb_videomode *mode;
2914 struct fb_con2fbmap *con2fb;
2915 int ret = 0;
2916
2917 switch(action) {
2918 case FB_EVENT_SUSPEND:
2919 fbcon_suspended(info);
2920 break;
2921 case FB_EVENT_RESUME:
2922 fbcon_resumed(info);
2923 break;
2924 case FB_EVENT_MODE_CHANGE:
2925 fbcon_modechanged(info);
2926 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002927 case FB_EVENT_MODE_CHANGE_ALL:
2928 fbcon_set_all_vcs(info);
2929 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 case FB_EVENT_MODE_DELETE:
2931 mode = event->data;
2932 ret = fbcon_mode_deleted(info, mode);
2933 break;
2934 case FB_EVENT_FB_REGISTERED:
2935 ret = fbcon_fb_registered(info->node);
2936 break;
2937 case FB_EVENT_SET_CONSOLE_MAP:
2938 con2fb = event->data;
2939 ret = set_con2fb_map(con2fb->console - 1,
2940 con2fb->framebuffer, 1);
2941 break;
2942 case FB_EVENT_GET_CONSOLE_MAP:
2943 con2fb = event->data;
2944 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
2945 break;
2946 case FB_EVENT_BLANK:
2947 fbcon_fb_blanked(info, *(int *)event->data);
2948 break;
2949 case FB_EVENT_NEW_MODELIST:
2950 fbcon_new_modelist(info);
2951 break;
Antonino A. Daplasa812c942005-11-08 21:39:15 -08002952 case FB_EVENT_SET_CON_ROTATE:
2953 fbcon_rotate(info, *(int *)event->data);
2954 break;
2955 case FB_EVENT_GET_CON_ROTATE:
2956 ret = fbcon_get_rotate(info);
2957 break;
2958 case FB_EVENT_SET_CON_ROTATE_ALL:
2959 fbcon_rotate_all(info, *(int *)event->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 }
2961
2962 return ret;
2963}
2964
2965/*
2966 * The console `switch' structure for the frame buffer based console
2967 */
2968
2969static const struct consw fb_con = {
2970 .owner = THIS_MODULE,
2971 .con_startup = fbcon_startup,
2972 .con_init = fbcon_init,
2973 .con_deinit = fbcon_deinit,
2974 .con_clear = fbcon_clear,
2975 .con_putc = fbcon_putc,
2976 .con_putcs = fbcon_putcs,
2977 .con_cursor = fbcon_cursor,
2978 .con_scroll = fbcon_scroll,
2979 .con_bmove = fbcon_bmove,
2980 .con_switch = fbcon_switch,
2981 .con_blank = fbcon_blank,
2982 .con_font_set = fbcon_set_font,
2983 .con_font_get = fbcon_get_font,
2984 .con_font_default = fbcon_set_def_font,
2985 .con_font_copy = fbcon_copy_font,
2986 .con_set_palette = fbcon_set_palette,
2987 .con_scrolldelta = fbcon_scrolldelta,
2988 .con_set_origin = fbcon_set_origin,
2989 .con_invert_region = fbcon_invert_region,
2990 .con_screen_pos = fbcon_screen_pos,
2991 .con_getxy = fbcon_getxy,
2992 .con_resize = fbcon_resize,
2993};
2994
2995static struct notifier_block fbcon_event_notifier = {
2996 .notifier_call = fbcon_event_notify,
2997};
2998
2999static int __init fb_console_init(void)
3000{
3001 int i;
3002
3003 acquire_console_sem();
3004 fb_register_client(&fbcon_event_notifier);
3005 release_console_sem();
3006
3007 for (i = 0; i < MAX_NR_CONSOLES; i++)
3008 con2fb_map[i] = -1;
3009
3010 if (num_registered_fb) {
3011 for (i = 0; i < FB_MAX; i++) {
3012 if (registered_fb[i] != NULL) {
3013 info_idx = i;
3014 break;
3015 }
3016 }
3017 fbcon_takeover(0);
3018 }
3019
3020 return 0;
3021}
3022
3023module_init(fb_console_init);
3024
3025#ifdef MODULE
3026
3027static void __exit fb_console_exit(void)
3028{
3029 acquire_console_sem();
3030 fb_unregister_client(&fbcon_event_notifier);
3031 release_console_sem();
3032 give_up_console(&fb_con);
3033}
3034
3035module_exit(fb_console_exit);
3036
3037#endif
3038
3039MODULE_LICENSE("GPL");