blob: 0f32f4a00b2df52844022b4bcdac074a1f48e98c [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/module.h>
62#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <linux/fs.h>
64#include <linux/kernel.h>
65#include <linux/delay.h> /* MSch: for IRQ probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <linux/console.h>
67#include <linux/string.h>
68#include <linux/kd.h>
69#include <linux/slab.h>
70#include <linux/fb.h>
71#include <linux/vt_kern.h>
72#include <linux/selection.h>
73#include <linux/font.h>
74#include <linux/smp.h>
75#include <linux/init.h>
76#include <linux/interrupt.h>
77#include <linux/crc32.h> /* For counting font checksums */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -070078#include <asm/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm/irq.h>
80#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#ifdef CONFIG_ATARI
82#include <asm/atariints.h>
83#endif
84#ifdef CONFIG_MAC
85#include <asm/macints.h>
86#endif
87#if defined(__mc68000__) || defined(CONFIG_APUS)
88#include <asm/machdep.h>
89#include <asm/setup.h>
90#endif
91
92#include "fbcon.h"
93
94#ifdef FBCONDEBUG
95# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
96#else
97# define DPRINTK(fmt, args...)
98#endif
99
100enum {
101 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
104};
105
Antonino A. Daplasab767202005-11-13 16:06:32 -0800106static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static signed char con2fb_map[MAX_NR_CONSOLES];
109static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700110#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int logo_height;
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static int logo_lines;
114/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
115 enums. */
116static int logo_shown = FBCON_LOGO_CANSHOW;
117/* Software scrollback */
118static int fbcon_softback_size = 32768;
119static unsigned long softback_buf, softback_curr;
120static unsigned long softback_in;
121static unsigned long softback_top, softback_end;
122static int softback_lines;
123/* console mappings */
124static int first_fb_vc;
125static int last_fb_vc = MAX_NR_CONSOLES - 1;
126static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700127static int fbcon_has_exited;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700128static int primary_device = -1;
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700129
130#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700131static int map_override;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700132
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700133static inline void fbcon_map_override(void)
134{
135 map_override = 1;
136}
137#else
138static inline void fbcon_map_override(void)
139{
140}
141#endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/* font data */
144static char fontname[40];
145
146/* current fb_info */
147static int info_idx = -1;
148
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800149/* console rotation */
150static int rotate;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700151static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153static const struct consw fb_con;
154
155#define CM_SOFTBACK (8)
156
157#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static int fbcon_set_origin(struct vc_data *);
160
161#define CURSOR_DRAW_DELAY (1)
162
163/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define ATARI_CURSOR_BLINK_RATE (42)
165#define MAC_CURSOR_BLINK_RATE (32)
166#define DEFAULT_CURSOR_BLINK_RATE (20)
167
168static int vbl_cursor_cnt;
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700169static int fbcon_cursor_noblink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
172
173/*
174 * Interface used by the world
175 */
176
177static const char *fbcon_startup(void);
178static void fbcon_init(struct vc_data *vc, int init);
179static void fbcon_deinit(struct vc_data *vc);
180static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
181 int width);
182static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
183static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
184 int count, int ypos, int xpos);
185static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
186static void fbcon_cursor(struct vc_data *vc, int mode);
187static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
188 int count);
189static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
190 int height, int width);
191static int fbcon_switch(struct vc_data *vc);
192static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
193static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
194static int fbcon_scrolldelta(struct vc_data *vc, int lines);
195
196/*
197 * Internal routines
198 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199static __inline__ void ywrap_up(struct vc_data *vc, int count);
200static __inline__ void ywrap_down(struct vc_data *vc, int count);
201static __inline__ void ypan_up(struct vc_data *vc, int count);
202static __inline__ void ypan_down(struct vc_data *vc, int count);
203static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
204 int dy, int dx, int height, int width, u_int y_break);
205static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700206 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
208 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800209static void fbcon_modechanged(struct fb_info *info);
210static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700211static void fbcon_start(void);
212static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700213static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215#ifdef CONFIG_MAC
216/*
217 * On the Macintoy, there may or may not be a working VBL int. We need to probe
218 */
219static int vbl_detected;
220
David Howells7d12e782006-10-05 14:55:46 +0100221static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 vbl_detected++;
224 return IRQ_HANDLED;
225}
226#endif
227
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800228#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800229static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800230{
231 struct fbcon_ops *ops = info->fbcon_par;
232
233 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800234 ops->p->con_rotate < 4)
235 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800236 else
237 ops->rotate = 0;
238}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800239
240static void fbcon_rotate(struct fb_info *info, u32 rotate)
241{
242 struct fbcon_ops *ops= info->fbcon_par;
243 struct fb_info *fb_info;
244
245 if (!ops || ops->currcon == -1)
246 return;
247
248 fb_info = registered_fb[con2fb_map[ops->currcon]];
249
250 if (info == fb_info) {
251 struct display *p = &fb_display[ops->currcon];
252
253 if (rotate < 4)
254 p->con_rotate = rotate;
255 else
256 p->con_rotate = 0;
257
258 fbcon_modechanged(info);
259 }
260}
261
262static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
263{
264 struct fbcon_ops *ops = info->fbcon_par;
265 struct vc_data *vc;
266 struct display *p;
267 int i;
268
269 if (!ops || ops->currcon < 0 || rotate > 3)
270 return;
271
Antonino A. Daplase614b182006-06-26 00:27:09 -0700272 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800273 vc = vc_cons[i].d;
274 if (!vc || vc->vc_mode != KD_TEXT ||
275 registered_fb[con2fb_map[i]] != info)
276 continue;
277
278 p = &fb_display[vc->vc_num];
279 p->con_rotate = rotate;
280 }
281
282 fbcon_set_all_vcs(info);
283}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800284#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800285static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800286{
287 struct fbcon_ops *ops = info->fbcon_par;
288
289 ops->rotate = FB_ROTATE_UR;
290}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800291
292static void fbcon_rotate(struct fb_info *info, u32 rotate)
293{
294 return;
295}
296
297static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
298{
299 return;
300}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800301#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800302
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800303static int fbcon_get_rotate(struct fb_info *info)
304{
305 struct fbcon_ops *ops = info->fbcon_par;
306
307 return (ops) ? ops->rotate : 0;
308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
311{
312 struct fbcon_ops *ops = info->fbcon_par;
313
314 return (info->state != FBINFO_STATE_RUNNING ||
315 vc->vc_mode != KD_TEXT || ops->graphics);
316}
317
318static inline int get_color(struct vc_data *vc, struct fb_info *info,
319 u16 c, int is_fg)
320{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700321 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 int color = 0;
323
324 if (console_blanked) {
325 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
326
327 c = vc->vc_video_erase_char & charmask;
328 }
329
330 if (depth != 1)
331 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
332 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
333
334 switch (depth) {
335 case 1:
336 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700337 int col = ~(0xfff << (max(info->var.green.length,
338 max(info->var.red.length,
339 info->var.blue.length)))) & 0xff;
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700342 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
343 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 if (console_blanked)
346 fg = bg;
347
348 color = (is_fg) ? fg : bg;
349 break;
350 }
351 case 2:
352 /*
353 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700354 * is grayscale. However, simply dividing the values by 4
355 * will not work, as colors 1, 2 and 3 will be scaled-down
356 * to zero rendering them invisible. So empirically convert
357 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700359 switch (color) {
360 case 0:
361 color = 0; /* black */
362 break;
363 case 1 ... 6:
364 color = 2; /* white */
365 break;
366 case 7 ... 8:
367 color = 1; /* gray */
368 break;
369 default:
370 color = 3; /* intense white */
371 break;
372 }
373 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 case 3:
375 /*
376 * Last 8 entries of default 16-color palette is a more intense
377 * version of the first 8 (i.e., same chrominance, different
378 * luminance).
379 */
380 color &= 7;
381 break;
382 }
383
384
385 return color;
386}
387
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800388static void fbcon_update_softback(struct vc_data *vc)
389{
390 int l = fbcon_softback_size / vc->vc_size_row;
391
392 if (l > 5)
393 softback_end = softback_buf + l * vc->vc_size_row;
394 else
395 /* Smaller scrollback makes no sense, and 0 would screw
396 the operation totally */
397 softback_top = 0;
398}
399
David Howellsc4028952006-11-22 14:57:56 +0000400static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
David Howellsc4028952006-11-22 14:57:56 +0000402 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 struct fbcon_ops *ops = info->fbcon_par;
404 struct display *p;
405 struct vc_data *vc = NULL;
406 int c;
407 int mode;
408
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700409 acquire_console_sem();
410 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 vc = vc_cons[ops->currcon].d;
412
413 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700414 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700415 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700416 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700418 }
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 p = &fb_display[vc->vc_num];
421 c = scr_readw((u16 *) vc->vc_pos);
422 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
423 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800424 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 get_color(vc, info, c, 0));
426 release_console_sem();
427}
428
Russell King41359dc2005-06-30 16:30:07 +0100429#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100431static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 struct fb_info *info = dev_id;
434
435 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
436 schedule_work(&info->queue);
437 vbl_cursor_cnt = cursor_blink_rate;
438 }
439 return IRQ_HANDLED;
440}
441#endif
442
443static void cursor_timer_handler(unsigned long dev_addr)
444{
445 struct fb_info *info = (struct fb_info *) dev_addr;
446 struct fbcon_ops *ops = info->fbcon_par;
447
448 schedule_work(&info->queue);
449 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
450}
451
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700452static void fbcon_add_cursor_timer(struct fb_info *info)
453{
454 struct fbcon_ops *ops = info->fbcon_par;
455
456 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700457 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
458 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700459 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000460 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700461
462 init_timer(&ops->cursor_timer);
463 ops->cursor_timer.function = cursor_timer_handler;
464 ops->cursor_timer.expires = jiffies + HZ / 5;
465 ops->cursor_timer.data = (unsigned long ) info;
466 add_timer(&ops->cursor_timer);
467 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
468 }
469}
470
471static void fbcon_del_cursor_timer(struct fb_info *info)
472{
473 struct fbcon_ops *ops = info->fbcon_par;
474
475 if (info->queue.func == fb_flashcursor &&
476 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
477 del_timer_sync(&ops->cursor_timer);
478 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
479 }
480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482#ifndef MODULE
483static int __init fb_console_setup(char *this_opt)
484{
485 char *options;
486 int i, j;
487
488 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800489 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491 while ((options = strsep(&this_opt, ",")) != NULL) {
492 if (!strncmp(options, "font:", 5))
493 strcpy(fontname, options + 5);
494
495 if (!strncmp(options, "scrollback:", 11)) {
496 options += 11;
497 if (*options) {
498 fbcon_softback_size = simple_strtoul(options, &options, 0);
499 if (*options == 'k' || *options == 'K') {
500 fbcon_softback_size *= 1024;
501 options++;
502 }
503 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800504 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 options++;
506 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800507 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509
510 if (!strncmp(options, "map:", 4)) {
511 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700512 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
514 if (!options[j])
515 j = 0;
516 con2fb_map_boot[i] =
517 (options[j++]-'0') % FB_MAX;
518 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700519
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700520 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700521 }
522
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800523 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
525
526 if (!strncmp(options, "vc:", 3)) {
527 options += 3;
528 if (*options)
529 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
530 if (first_fb_vc < 0)
531 first_fb_vc = 0;
532 if (*options++ == '-')
533 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
534 fbcon_is_default = 0;
535 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800536
537 if (!strncmp(options, "rotate:", 7)) {
538 options += 7;
539 if (*options)
540 rotate = simple_strtoul(options, &options, 0);
541 if (rotate > 3)
542 rotate = 0;
543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800545 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
548__setup("fbcon=", fb_console_setup);
549#endif
550
551static int search_fb_in_map(int idx)
552{
553 int i, retval = 0;
554
Antonino A. Daplase614b182006-06-26 00:27:09 -0700555 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 if (con2fb_map[i] == idx)
557 retval = 1;
558 }
559 return retval;
560}
561
562static int search_for_mapped_con(void)
563{
564 int i, retval = 0;
565
Antonino A. Daplase614b182006-06-26 00:27:09 -0700566 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 if (con2fb_map[i] != -1)
568 retval = 1;
569 }
570 return retval;
571}
572
573static int fbcon_takeover(int show_logo)
574{
575 int err, i;
576
577 if (!num_registered_fb)
578 return -ENODEV;
579
580 if (!show_logo)
581 logo_shown = FBCON_LOGO_DONTSHOW;
582
583 for (i = first_fb_vc; i <= last_fb_vc; i++)
584 con2fb_map[i] = info_idx;
585
586 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
587 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700588
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 if (err) {
590 for (i = first_fb_vc; i <= last_fb_vc; i++) {
591 con2fb_map[i] = -1;
592 }
593 info_idx = -1;
594 }
595
596 return err;
597}
598
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700599#ifdef MODULE
600static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
601 int cols, int rows, int new_cols, int new_rows)
602{
603 logo_shown = FBCON_LOGO_DONTSHOW;
604}
605#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
607 int cols, int rows, int new_cols, int new_rows)
608{
609 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800610 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 int cnt, erase = vc->vc_video_erase_char, step;
612 unsigned short *save = NULL, *r, *q;
613
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700614 if (info->flags & FBINFO_MODULE) {
615 logo_shown = FBCON_LOGO_DONTSHOW;
616 return;
617 }
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /*
620 * remove underline attribute from erase character
621 * if black and white framebuffer.
622 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700623 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800625 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 logo_lines = (logo_height + vc->vc_font.height - 1) /
627 vc->vc_font.height;
628 q = (unsigned short *) (vc->vc_origin +
629 vc->vc_size_row * rows);
630 step = logo_lines * cols;
631 for (r = q - logo_lines * cols; r < q; r++)
632 if (scr_readw(r) != vc->vc_video_erase_char)
633 break;
634 if (r != q && new_rows >= rows + logo_lines) {
635 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
636 if (save) {
637 int i = cols < new_cols ? cols : new_cols;
638 scr_memsetw(save, erase, logo_lines * new_cols * 2);
639 r = q - step;
640 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
641 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
642 r = q;
643 }
644 }
645 if (r == q) {
646 /* We can scroll screen down */
647 r = q - step - cols;
648 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
649 scr_memcpyw(r + step, r, vc->vc_size_row);
650 r -= cols;
651 }
652 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700653 int lines;
654 if (vc->vc_y + logo_lines >= rows)
655 lines = rows - vc->vc_y - 1;
656 else
657 lines = logo_lines;
658 vc->vc_y += lines;
659 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 }
661 }
662 scr_memsetw((unsigned short *) vc->vc_origin,
663 erase,
664 vc->vc_size_row * logo_lines);
665
666 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
667 fbcon_clear_margins(vc, 0);
668 update_screen(vc);
669 }
670
671 if (save) {
672 q = (unsigned short *) (vc->vc_origin +
673 vc->vc_size_row *
674 rows);
675 scr_memcpyw(q, save, logo_lines * new_cols * 2);
676 vc->vc_y += logo_lines;
677 vc->vc_pos += logo_lines * vc->vc_size_row;
678 kfree(save);
679 }
680
681 if (logo_lines > vc->vc_bottom) {
682 logo_shown = FBCON_LOGO_CANSHOW;
683 printk(KERN_INFO
684 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
685 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
686 logo_shown = FBCON_LOGO_DRAW;
687 vc->vc_top = logo_lines;
688 }
689}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700690#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800693static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694{
695 struct fbcon_ops *ops = info->fbcon_par;
696
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800697 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800700 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800701 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800702 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700706
707static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
708{
709 int err = 0;
710
711 if (info->flags & FBINFO_MISC_TILEBLITTING &&
712 info->tileops->fb_get_tilemax(info) < charcount)
713 err = 1;
714
715 return err;
716}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800718static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
720 struct fbcon_ops *ops = info->fbcon_par;
721
722 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800723 ops->p = &fb_display[vc->vc_num];
724 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 fbcon_set_bitops(ops);
726}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700727
728static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
729{
730 return 0;
731}
732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733#endif /* CONFIG_MISC_TILEBLITTING */
734
735
736static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
737 int unit, int oldidx)
738{
739 struct fbcon_ops *ops = NULL;
740 int err = 0;
741
742 if (!try_module_get(info->fbops->owner))
743 err = -ENODEV;
744
745 if (!err && info->fbops->fb_open &&
746 info->fbops->fb_open(info, 0))
747 err = -ENODEV;
748
749 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800750 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 if (!ops)
752 err = -ENOMEM;
753 }
754
755 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700757
758 if (vc)
759 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761
762 if (err) {
763 con2fb_map[unit] = oldidx;
764 module_put(info->fbops->owner);
765 }
766
767 return err;
768}
769
770static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
771 struct fb_info *newinfo, int unit,
772 int oldidx, int found)
773{
774 struct fbcon_ops *ops = oldinfo->fbcon_par;
775 int err = 0;
776
777 if (oldinfo->fbops->fb_release &&
778 oldinfo->fbops->fb_release(oldinfo, 0)) {
779 con2fb_map[unit] = oldidx;
780 if (!found && newinfo->fbops->fb_release)
781 newinfo->fbops->fb_release(newinfo, 0);
782 if (!found)
783 module_put(newinfo->fbops->owner);
784 err = -ENODEV;
785 }
786
787 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700788 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 kfree(ops->cursor_state.mask);
790 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800791 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 kfree(oldinfo->fbcon_par);
793 oldinfo->fbcon_par = NULL;
794 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800795 /*
796 If oldinfo and newinfo are driving the same hardware,
797 the fb_release() method of oldinfo may attempt to
798 restore the hardware state. This will leave the
799 newinfo in an undefined state. Thus, a call to
800 fb_set_par() may be needed for the newinfo.
801 */
802 if (newinfo->fbops->fb_set_par)
803 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
805
806 return err;
807}
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
810 int unit, int show_logo)
811{
812 struct fbcon_ops *ops = info->fbcon_par;
813
814 ops->currcon = fg_console;
815
816 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
817 info->fbops->fb_set_par(info);
818
819 ops->flags |= FBCON_FLAGS_INIT;
820 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700821 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 if (show_logo) {
824 struct vc_data *fg_vc = vc_cons[fg_console].d;
825 struct fb_info *fg_info =
826 registered_fb[con2fb_map[fg_console]];
827
828 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
829 fg_vc->vc_rows, fg_vc->vc_cols,
830 fg_vc->vc_rows);
831 }
832
833 update_screen(vc_cons[fg_console].d);
834}
835
836/**
837 * set_con2fb_map - map console to frame buffer device
838 * @unit: virtual console number to map
839 * @newidx: frame buffer index to map virtual console to
840 * @user: user request
841 *
842 * Maps a virtual console @unit to a frame buffer device
843 * @newidx.
844 */
845static int set_con2fb_map(int unit, int newidx, int user)
846{
847 struct vc_data *vc = vc_cons[unit].d;
848 int oldidx = con2fb_map[unit];
849 struct fb_info *info = registered_fb[newidx];
850 struct fb_info *oldinfo = NULL;
851 int found, err = 0;
852
853 if (oldidx == newidx)
854 return 0;
855
Antonino A. Daplase614b182006-06-26 00:27:09 -0700856 if (!info || fbcon_has_exited)
857 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 if (!err && !search_for_mapped_con()) {
860 info_idx = newidx;
861 return fbcon_takeover(0);
862 }
863
864 if (oldidx != -1)
865 oldinfo = registered_fb[oldidx];
866
867 found = search_fb_in_map(newidx);
868
869 acquire_console_sem();
870 con2fb_map[unit] = newidx;
871 if (!err && !found)
872 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
873
874
875 /*
876 * If old fb is not mapped to any of the consoles,
877 * fbcon should release it.
878 */
879 if (!err && oldinfo && !search_fb_in_map(oldidx))
880 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
881 found);
882
883 if (!err) {
884 int show_logo = (fg_console == 0 && !user &&
885 logo_shown != FBCON_LOGO_DONTSHOW);
886
887 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700888 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 con2fb_map_boot[unit] = newidx;
890 con2fb_init_display(vc, info, unit, show_logo);
891 }
892
Antonino A. Daplase614b182006-06-26 00:27:09 -0700893 if (!search_fb_in_map(info_idx))
894 info_idx = newidx;
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 release_console_sem();
897 return err;
898}
899
900/*
901 * Low Level Operations
902 */
903/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
904static int var_to_display(struct display *disp,
905 struct fb_var_screeninfo *var,
906 struct fb_info *info)
907{
908 disp->xres_virtual = var->xres_virtual;
909 disp->yres_virtual = var->yres_virtual;
910 disp->bits_per_pixel = var->bits_per_pixel;
911 disp->grayscale = var->grayscale;
912 disp->nonstd = var->nonstd;
913 disp->accel_flags = var->accel_flags;
914 disp->height = var->height;
915 disp->width = var->width;
916 disp->red = var->red;
917 disp->green = var->green;
918 disp->blue = var->blue;
919 disp->transp = var->transp;
920 disp->rotate = var->rotate;
921 disp->mode = fb_match_mode(var, &info->modelist);
922 if (disp->mode == NULL)
923 /* This should not happen */
924 return -EINVAL;
925 return 0;
926}
927
928static void display_to_var(struct fb_var_screeninfo *var,
929 struct display *disp)
930{
931 fb_videomode_to_var(var, disp->mode);
932 var->xres_virtual = disp->xres_virtual;
933 var->yres_virtual = disp->yres_virtual;
934 var->bits_per_pixel = disp->bits_per_pixel;
935 var->grayscale = disp->grayscale;
936 var->nonstd = disp->nonstd;
937 var->accel_flags = disp->accel_flags;
938 var->height = disp->height;
939 var->width = disp->width;
940 var->red = disp->red;
941 var->green = disp->green;
942 var->blue = disp->blue;
943 var->transp = disp->transp;
944 var->rotate = disp->rotate;
945}
946
947static const char *fbcon_startup(void)
948{
949 const char *display_desc = "frame buffer device";
950 struct display *p = &fb_display[fg_console];
951 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700952 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 struct module *owner;
954 struct fb_info *info = NULL;
955 struct fbcon_ops *ops;
956 int rows, cols;
957 int irqres;
958
959 irqres = 1;
960 /*
961 * If num_registered_fb is zero, this is a call for the dummy part.
962 * The frame buffer devices weren't initialized yet.
963 */
964 if (!num_registered_fb || info_idx == -1)
965 return display_desc;
966 /*
967 * Instead of blindly using registered_fb[0], we use info_idx, set by
968 * fb_console_init();
969 */
970 info = registered_fb[info_idx];
971 if (!info)
972 return NULL;
973
974 owner = info->fbops->owner;
975 if (!try_module_get(owner))
976 return NULL;
977 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
978 module_put(owner);
979 return NULL;
980 }
981
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800982 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (!ops) {
984 module_put(owner);
985 return NULL;
986 }
987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 ops->currcon = -1;
989 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800990 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800992 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800993 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 if (info->fix.type != FB_TYPE_TEXT) {
996 if (fbcon_softback_size) {
997 if (!softback_buf) {
998 softback_buf =
999 (unsigned long)
1000 kmalloc(fbcon_softback_size,
1001 GFP_KERNEL);
1002 if (!softback_buf) {
1003 fbcon_softback_size = 0;
1004 softback_top = 0;
1005 }
1006 }
1007 } else {
1008 if (softback_buf) {
1009 kfree((void *) softback_buf);
1010 softback_buf = 0;
1011 softback_top = 0;
1012 }
1013 }
1014 if (softback_buf)
1015 softback_in = softback_top = softback_curr =
1016 softback_buf;
1017 softback_lines = 0;
1018 }
1019
1020 /* Setup default font */
1021 if (!p->fontdata) {
1022 if (!fontname[0] || !(font = find_font(fontname)))
1023 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001024 info->var.yres,
1025 info->pixmap.blit_x,
1026 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 vc->vc_font.width = font->width;
1028 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001029 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1031 }
1032
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001033 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1034 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1035 cols /= vc->vc_font.width;
1036 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 vc_resize(vc, cols, rows);
1038
1039 DPRINTK("mode: %s\n", info->fix.id);
1040 DPRINTK("visual: %d\n", info->fix.visual);
1041 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1042 info->var.yres,
1043 info->var.bits_per_pixel);
1044
1045#ifdef CONFIG_ATARI
1046 if (MACH_IS_ATARI) {
1047 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1048 irqres =
1049 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1050 IRQ_TYPE_PRIO, "framebuffer vbl",
1051 info);
1052 }
1053#endif /* CONFIG_ATARI */
1054
1055#ifdef CONFIG_MAC
1056 /*
1057 * On a Macintoy, the VBL interrupt may or may not be active.
1058 * As interrupt based cursor is more reliable and race free, we
1059 * probe for VBL interrupts.
1060 */
1061 if (MACH_IS_MAC) {
1062 int ct = 0;
1063 /*
1064 * Probe for VBL: set temp. handler ...
1065 */
1066 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1067 "framebuffer vbl", info);
1068 vbl_detected = 0;
1069
1070 /*
1071 * ... and spin for 20 ms ...
1072 */
1073 while (!vbl_detected && ++ct < 1000)
1074 udelay(20);
1075
1076 if (ct == 1000)
1077 printk
1078 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1079
1080 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1081
1082 if (vbl_detected) {
1083 /*
1084 * interrupt based cursor ok
1085 */
1086 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1087 irqres =
1088 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1089 "framebuffer vbl", info);
1090 } else {
1091 /*
1092 * VBL not detected: fall through, use timer based cursor
1093 */
1094 irqres = 1;
1095 }
1096 }
1097#endif /* CONFIG_MAC */
1098
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001099 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001100 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 return display_desc;
1102}
1103
1104static void fbcon_init(struct vc_data *vc, int init)
1105{
1106 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1107 struct fbcon_ops *ops;
1108 struct vc_data **default_mode = vc->vc_display_fg;
1109 struct vc_data *svc = *default_mode;
1110 struct display *t, *p = &fb_display[vc->vc_num];
1111 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001112 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114 if (info_idx == -1 || info == NULL)
1115 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001116
1117 cap = info->flags;
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1120 (info->fix.type == FB_TYPE_TEXT))
1121 logo = 0;
1122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 if (var_to_display(p, &info->var, info))
1124 return;
1125
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001126 if (!info->fbcon_par)
1127 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 /* If we are not the first console on this
1130 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001131 t = &fb_display[fg_console];
1132 if (!p->fontdata) {
1133 if (t->fontdata) {
1134 struct vc_data *fvc = vc_cons[fg_console].d;
1135
1136 vc->vc_font.data = (void *)(p->fontdata =
1137 fvc->vc_font.data);
1138 vc->vc_font.width = fvc->vc_font.width;
1139 vc->vc_font.height = fvc->vc_font.height;
1140 p->userfont = t->userfont;
1141
1142 if (p->userfont)
1143 REFCOUNT(p->fontdata)++;
1144 } else {
1145 const struct font_desc *font = NULL;
1146
1147 if (!fontname[0] || !(font = find_font(fontname)))
1148 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001149 info->var.yres,
1150 info->pixmap.blit_x,
1151 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001152 vc->vc_font.width = font->width;
1153 vc->vc_font.height = font->height;
1154 vc->vc_font.data = (void *)(p->fontdata = font->data);
1155 vc->vc_font.charcount = 256; /* FIXME Need to
1156 support more fonts */
1157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001159
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (p->userfont)
1161 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001162
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001163 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1165 if (charcnt == 256) {
1166 vc->vc_hi_font_mask = 0;
1167 } else {
1168 vc->vc_hi_font_mask = 0x100;
1169 if (vc->vc_can_do_color)
1170 vc->vc_complement_mask <<= 1;
1171 }
1172
1173 if (!*svc->vc_uni_pagedir_loc)
1174 con_set_default_unimap(svc);
1175 if (!*vc->vc_uni_pagedir_loc)
1176 con_copy_unimap(vc, svc);
1177
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001178 ops = info->fbcon_par;
1179 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001180 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 cols = vc->vc_cols;
1183 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001184 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1185 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1186 new_cols /= vc->vc_font.width;
1187 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 vc_resize(vc, new_cols, new_rows);
1189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 /*
1191 * We must always set the mode. The mode of the previous console
1192 * driver could be in the same resolution but we are using different
1193 * hardware so we have to initialize the hardware.
1194 *
1195 * We need to do it in fbcon_init() to prevent screen corruption.
1196 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001197 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 if (info->fbops->fb_set_par &&
1199 !(ops->flags & FBCON_FLAGS_INIT))
1200 info->fbops->fb_set_par(info);
1201 ops->flags |= FBCON_FLAGS_INIT;
1202 }
1203
1204 ops->graphics = 0;
1205
1206 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1207 !(cap & FBINFO_HWACCEL_DISABLED))
1208 p->scrollmode = SCROLL_MOVE;
1209 else /* default to something safe */
1210 p->scrollmode = SCROLL_REDRAW;
1211
1212 /*
1213 * ++guenther: console.c:vc_allocate() relies on initializing
1214 * vc_{cols,rows}, but we must not set those if we are only
1215 * resizing the console.
1216 */
1217 if (!init) {
1218 vc->vc_cols = new_cols;
1219 vc->vc_rows = new_rows;
1220 }
1221
1222 if (logo)
1223 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1224
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001225 if (vc == svc && softback_buf)
1226 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001227
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001228 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001229 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001230 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001231 }
1232
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001233 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234}
1235
Antonino A. Daplase614b182006-06-26 00:27:09 -07001236static void fbcon_free_font(struct display *p)
1237{
1238 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1239 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1240 p->fontdata = NULL;
1241 p->userfont = 0;
1242}
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244static void fbcon_deinit(struct vc_data *vc)
1245{
1246 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001247 struct fb_info *info;
1248 struct fbcon_ops *ops;
1249 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001252 idx = con2fb_map[vc->vc_num];
1253
1254 if (idx == -1)
1255 goto finished;
1256
1257 info = registered_fb[idx];
1258
1259 if (!info)
1260 goto finished;
1261
1262 ops = info->fbcon_par;
1263
1264 if (!ops)
1265 goto finished;
1266
1267 if (CON_IS_VISIBLE(vc))
1268 fbcon_del_cursor_timer(info);
1269
1270 ops->flags &= ~FBCON_FLAGS_INIT;
1271finished:
1272
1273 if (!con_is_bound(&fb_con))
1274 fbcon_exit();
1275
1276 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
1279/* ====================================================================== */
1280
1281/* fbcon_XXX routines - interface used by the world
1282 *
1283 * This system is now divided into two levels because of complications
1284 * caused by hardware scrolling. Top level functions:
1285 *
1286 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1287 *
1288 * handles y values in range [0, scr_height-1] that correspond to real
1289 * screen positions. y_wrap shift means that first line of bitmap may be
1290 * anywhere on this display. These functions convert lineoffsets to
1291 * bitmap offsets and deal with the wrap-around case by splitting blits.
1292 *
1293 * fbcon_bmove_physical_8() -- These functions fast implementations
1294 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1295 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1296 *
1297 * WARNING:
1298 *
1299 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1300 * Implies should only really hardware scroll in rows. Only reason for
1301 * restriction is simplicity & efficiency at the moment.
1302 */
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1305 int width)
1306{
1307 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1308 struct fbcon_ops *ops = info->fbcon_par;
1309
1310 struct display *p = &fb_display[vc->vc_num];
1311 u_int y_break;
1312
1313 if (fbcon_is_inactive(vc, info))
1314 return;
1315
1316 if (!height || !width)
1317 return;
1318
1319 /* Split blits that cross physical y_wrap boundary */
1320
1321 y_break = p->vrows - p->yscroll;
1322 if (sy < y_break && sy + height - 1 >= y_break) {
1323 u_int b = y_break - sy;
1324 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1325 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1326 width);
1327 } else
1328 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1329}
1330
1331static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1332 int count, int ypos, int xpos)
1333{
1334 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1335 struct display *p = &fb_display[vc->vc_num];
1336 struct fbcon_ops *ops = info->fbcon_par;
1337
1338 if (!fbcon_is_inactive(vc, info))
1339 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1340 get_color(vc, info, scr_readw(s), 1),
1341 get_color(vc, info, scr_readw(s), 0));
1342}
1343
1344static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1345{
1346 unsigned short chr;
1347
1348 scr_writew(c, &chr);
1349 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1350}
1351
1352static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1353{
1354 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1355 struct fbcon_ops *ops = info->fbcon_par;
1356
1357 if (!fbcon_is_inactive(vc, info))
1358 ops->clear_margins(vc, info, bottom_only);
1359}
1360
1361static void fbcon_cursor(struct vc_data *vc, int mode)
1362{
1363 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1364 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 int y;
1366 int c = scr_readw((u16 *) vc->vc_pos);
1367
Michal Januszewskid1e23062007-05-08 00:38:07 -07001368 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 return;
1370
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001371 if (vc->vc_cursor_type & 0x10)
1372 fbcon_del_cursor_timer(info);
1373 else
1374 fbcon_add_cursor_timer(info);
1375
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1377 if (mode & CM_SOFTBACK) {
1378 mode &= ~CM_SOFTBACK;
1379 y = softback_lines;
1380 } else {
1381 if (softback_lines)
1382 fbcon_set_origin(vc);
1383 y = 0;
1384 }
1385
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001386 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 get_color(vc, info, c, 0));
1388 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1389}
1390
1391static int scrollback_phys_max = 0;
1392static int scrollback_max = 0;
1393static int scrollback_current = 0;
1394
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001396 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001398 struct display *p, *t;
1399 struct vc_data **default_mode, *vc;
1400 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001401 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 int rows, cols, charcnt = 256;
1403
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001404 p = &fb_display[unit];
1405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 if (var_to_display(p, var, info))
1407 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001408
1409 vc = vc_cons[unit].d;
1410
1411 if (!vc)
1412 return;
1413
1414 default_mode = vc->vc_display_fg;
1415 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001419 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 vc->vc_font.width = (*default_mode)->vc_font.width;
1421 vc->vc_font.height = (*default_mode)->vc_font.height;
1422 p->userfont = t->userfont;
1423 if (p->userfont)
1424 REFCOUNT(p->fontdata)++;
1425 }
1426 if (p->userfont)
1427 charcnt = FNTCHARCNT(p->fontdata);
1428
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001429 var->activate = FB_ACTIVATE_NOW;
1430 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001431 var->yoffset = info->var.yoffset;
1432 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001433 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001434 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001435 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1437 if (charcnt == 256) {
1438 vc->vc_hi_font_mask = 0;
1439 } else {
1440 vc->vc_hi_font_mask = 0x100;
1441 if (vc->vc_can_do_color)
1442 vc->vc_complement_mask <<= 1;
1443 }
1444
1445 if (!*svc->vc_uni_pagedir_loc)
1446 con_set_default_unimap(svc);
1447 if (!*vc->vc_uni_pagedir_loc)
1448 con_copy_unimap(vc, svc);
1449
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001450 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1451 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1452 cols /= vc->vc_font.width;
1453 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001455
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 if (CON_IS_VISIBLE(vc)) {
1457 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001458 if (softback_buf)
1459 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 }
1461}
1462
1463static __inline__ void ywrap_up(struct vc_data *vc, int count)
1464{
1465 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001466 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 struct display *p = &fb_display[vc->vc_num];
1468
1469 p->yscroll += count;
1470 if (p->yscroll >= p->vrows) /* Deal with wrap */
1471 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001472 ops->var.xoffset = 0;
1473 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1474 ops->var.vmode |= FB_VMODE_YWRAP;
1475 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 scrollback_max += count;
1477 if (scrollback_max > scrollback_phys_max)
1478 scrollback_max = scrollback_phys_max;
1479 scrollback_current = 0;
1480}
1481
1482static __inline__ void ywrap_down(struct vc_data *vc, int count)
1483{
1484 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001485 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 struct display *p = &fb_display[vc->vc_num];
1487
1488 p->yscroll -= count;
1489 if (p->yscroll < 0) /* Deal with wrap */
1490 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001491 ops->var.xoffset = 0;
1492 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1493 ops->var.vmode |= FB_VMODE_YWRAP;
1494 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 scrollback_max -= count;
1496 if (scrollback_max < 0)
1497 scrollback_max = 0;
1498 scrollback_current = 0;
1499}
1500
1501static __inline__ void ypan_up(struct vc_data *vc, int count)
1502{
1503 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1504 struct display *p = &fb_display[vc->vc_num];
1505 struct fbcon_ops *ops = info->fbcon_par;
1506
1507 p->yscroll += count;
1508 if (p->yscroll > p->vrows - vc->vc_rows) {
1509 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1510 0, 0, 0, vc->vc_rows, vc->vc_cols);
1511 p->yscroll -= p->vrows - vc->vc_rows;
1512 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001513
1514 ops->var.xoffset = 0;
1515 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1516 ops->var.vmode &= ~FB_VMODE_YWRAP;
1517 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 fbcon_clear_margins(vc, 1);
1519 scrollback_max += count;
1520 if (scrollback_max > scrollback_phys_max)
1521 scrollback_max = scrollback_phys_max;
1522 scrollback_current = 0;
1523}
1524
1525static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1526{
1527 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001528 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001532
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 if (p->yscroll > p->vrows - vc->vc_rows) {
1534 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001536 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001537
1538 ops->var.xoffset = 0;
1539 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1540 ops->var.vmode &= ~FB_VMODE_YWRAP;
1541 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 fbcon_clear_margins(vc, 1);
1543 scrollback_max += count;
1544 if (scrollback_max > scrollback_phys_max)
1545 scrollback_max = scrollback_phys_max;
1546 scrollback_current = 0;
1547}
1548
1549static __inline__ void ypan_down(struct vc_data *vc, int count)
1550{
1551 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1552 struct display *p = &fb_display[vc->vc_num];
1553 struct fbcon_ops *ops = info->fbcon_par;
1554
1555 p->yscroll -= count;
1556 if (p->yscroll < 0) {
1557 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1558 0, vc->vc_rows, vc->vc_cols);
1559 p->yscroll += p->vrows - vc->vc_rows;
1560 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001561
1562 ops->var.xoffset = 0;
1563 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1564 ops->var.vmode &= ~FB_VMODE_YWRAP;
1565 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 fbcon_clear_margins(vc, 1);
1567 scrollback_max -= count;
1568 if (scrollback_max < 0)
1569 scrollback_max = 0;
1570 scrollback_current = 0;
1571}
1572
1573static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1574{
1575 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001576 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001580
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 if (p->yscroll < 0) {
1582 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001584 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001585
1586 ops->var.xoffset = 0;
1587 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1588 ops->var.vmode &= ~FB_VMODE_YWRAP;
1589 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 fbcon_clear_margins(vc, 1);
1591 scrollback_max -= count;
1592 if (scrollback_max < 0)
1593 scrollback_max = 0;
1594 scrollback_current = 0;
1595}
1596
1597static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1598 long delta)
1599{
1600 int count = vc->vc_rows;
1601 unsigned short *d, *s;
1602 unsigned long n;
1603 int line = 0;
1604
1605 d = (u16 *) softback_curr;
1606 if (d == (u16 *) softback_in)
1607 d = (u16 *) vc->vc_origin;
1608 n = softback_curr + delta * vc->vc_size_row;
1609 softback_lines -= delta;
1610 if (delta < 0) {
1611 if (softback_curr < softback_top && n < softback_buf) {
1612 n += softback_end - softback_buf;
1613 if (n < softback_top) {
1614 softback_lines -=
1615 (softback_top - n) / vc->vc_size_row;
1616 n = softback_top;
1617 }
1618 } else if (softback_curr >= softback_top
1619 && n < softback_top) {
1620 softback_lines -=
1621 (softback_top - n) / vc->vc_size_row;
1622 n = softback_top;
1623 }
1624 } else {
1625 if (softback_curr > softback_in && n >= softback_end) {
1626 n += softback_buf - softback_end;
1627 if (n > softback_in) {
1628 n = softback_in;
1629 softback_lines = 0;
1630 }
1631 } else if (softback_curr <= softback_in && n > softback_in) {
1632 n = softback_in;
1633 softback_lines = 0;
1634 }
1635 }
1636 if (n == softback_curr)
1637 return;
1638 softback_curr = n;
1639 s = (u16 *) softback_curr;
1640 if (s == (u16 *) softback_in)
1641 s = (u16 *) vc->vc_origin;
1642 while (count--) {
1643 unsigned short *start;
1644 unsigned short *le;
1645 unsigned short c;
1646 int x = 0;
1647 unsigned short attr = 1;
1648
1649 start = s;
1650 le = advance_row(s, 1);
1651 do {
1652 c = scr_readw(s);
1653 if (attr != (c & 0xff00)) {
1654 attr = c & 0xff00;
1655 if (s > start) {
1656 fbcon_putcs(vc, start, s - start,
1657 line, x);
1658 x += s - start;
1659 start = s;
1660 }
1661 }
1662 if (c == scr_readw(d)) {
1663 if (s > start) {
1664 fbcon_putcs(vc, start, s - start,
1665 line, x);
1666 x += s - start + 1;
1667 start = s + 1;
1668 } else {
1669 x++;
1670 start++;
1671 }
1672 }
1673 s++;
1674 d++;
1675 } while (s < le);
1676 if (s > start)
1677 fbcon_putcs(vc, start, s - start, line, x);
1678 line++;
1679 if (d == (u16 *) softback_end)
1680 d = (u16 *) softback_buf;
1681 if (d == (u16 *) softback_in)
1682 d = (u16 *) vc->vc_origin;
1683 if (s == (u16 *) softback_end)
1684 s = (u16 *) softback_buf;
1685 if (s == (u16 *) softback_in)
1686 s = (u16 *) vc->vc_origin;
1687 }
1688}
1689
1690static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1691 int line, int count, int dy)
1692{
1693 unsigned short *s = (unsigned short *)
1694 (vc->vc_origin + vc->vc_size_row * line);
1695
1696 while (count--) {
1697 unsigned short *start = s;
1698 unsigned short *le = advance_row(s, 1);
1699 unsigned short c;
1700 int x = 0;
1701 unsigned short attr = 1;
1702
1703 do {
1704 c = scr_readw(s);
1705 if (attr != (c & 0xff00)) {
1706 attr = c & 0xff00;
1707 if (s > start) {
1708 fbcon_putcs(vc, start, s - start,
1709 dy, x);
1710 x += s - start;
1711 start = s;
1712 }
1713 }
1714 console_conditional_schedule();
1715 s++;
1716 } while (s < le);
1717 if (s > start)
1718 fbcon_putcs(vc, start, s - start, dy, x);
1719 console_conditional_schedule();
1720 dy++;
1721 }
1722}
1723
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001724static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1725 struct display *p, int line, int count, int ycount)
1726{
1727 int offset = ycount * vc->vc_cols;
1728 unsigned short *d = (unsigned short *)
1729 (vc->vc_origin + vc->vc_size_row * line);
1730 unsigned short *s = d + offset;
1731 struct fbcon_ops *ops = info->fbcon_par;
1732
1733 while (count--) {
1734 unsigned short *start = s;
1735 unsigned short *le = advance_row(s, 1);
1736 unsigned short c;
1737 int x = 0;
1738
1739 do {
1740 c = scr_readw(s);
1741
1742 if (c == scr_readw(d)) {
1743 if (s > start) {
1744 ops->bmove(vc, info, line + ycount, x,
1745 line, x, 1, s-start);
1746 x += s - start + 1;
1747 start = s + 1;
1748 } else {
1749 x++;
1750 start++;
1751 }
1752 }
1753
1754 scr_writew(c, d);
1755 console_conditional_schedule();
1756 s++;
1757 d++;
1758 } while (s < le);
1759 if (s > start)
1760 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1761 s-start);
1762 console_conditional_schedule();
1763 if (ycount > 0)
1764 line++;
1765 else {
1766 line--;
1767 /* NOTE: We subtract two lines from these pointers */
1768 s -= vc->vc_size_row;
1769 d -= vc->vc_size_row;
1770 }
1771 }
1772}
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774static void fbcon_redraw(struct vc_data *vc, struct display *p,
1775 int line, int count, int offset)
1776{
1777 unsigned short *d = (unsigned short *)
1778 (vc->vc_origin + vc->vc_size_row * line);
1779 unsigned short *s = d + offset;
1780
1781 while (count--) {
1782 unsigned short *start = s;
1783 unsigned short *le = advance_row(s, 1);
1784 unsigned short c;
1785 int x = 0;
1786 unsigned short attr = 1;
1787
1788 do {
1789 c = scr_readw(s);
1790 if (attr != (c & 0xff00)) {
1791 attr = c & 0xff00;
1792 if (s > start) {
1793 fbcon_putcs(vc, start, s - start,
1794 line, x);
1795 x += s - start;
1796 start = s;
1797 }
1798 }
1799 if (c == scr_readw(d)) {
1800 if (s > start) {
1801 fbcon_putcs(vc, start, s - start,
1802 line, x);
1803 x += s - start + 1;
1804 start = s + 1;
1805 } else {
1806 x++;
1807 start++;
1808 }
1809 }
1810 scr_writew(c, d);
1811 console_conditional_schedule();
1812 s++;
1813 d++;
1814 } while (s < le);
1815 if (s > start)
1816 fbcon_putcs(vc, start, s - start, line, x);
1817 console_conditional_schedule();
1818 if (offset > 0)
1819 line++;
1820 else {
1821 line--;
1822 /* NOTE: We subtract two lines from these pointers */
1823 s -= vc->vc_size_row;
1824 d -= vc->vc_size_row;
1825 }
1826 }
1827}
1828
1829static inline void fbcon_softback_note(struct vc_data *vc, int t,
1830 int count)
1831{
1832 unsigned short *p;
1833
1834 if (vc->vc_num != fg_console)
1835 return;
1836 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1837
1838 while (count) {
1839 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1840 count--;
1841 p = advance_row(p, 1);
1842 softback_in += vc->vc_size_row;
1843 if (softback_in == softback_end)
1844 softback_in = softback_buf;
1845 if (softback_in == softback_top) {
1846 softback_top += vc->vc_size_row;
1847 if (softback_top == softback_end)
1848 softback_top = softback_buf;
1849 }
1850 }
1851 softback_curr = softback_in;
1852}
1853
1854static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1855 int count)
1856{
1857 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1858 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1860
1861 if (fbcon_is_inactive(vc, info))
1862 return -EINVAL;
1863
1864 fbcon_cursor(vc, CM_ERASE);
1865
1866 /*
1867 * ++Geert: Only use ywrap/ypan if the console is in text mode
1868 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1869 * whole screen (prevents flicker).
1870 */
1871
1872 switch (dir) {
1873 case SM_UP:
1874 if (count > vc->vc_rows) /* Maximum realistic size */
1875 count = vc->vc_rows;
1876 if (softback_top)
1877 fbcon_softback_note(vc, t, count);
1878 if (logo_shown >= 0)
1879 goto redraw_up;
1880 switch (p->scrollmode) {
1881 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001882 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1883 count);
1884 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1885 scr_memsetw((unsigned short *) (vc->vc_origin +
1886 vc->vc_size_row *
1887 (b - count)),
1888 vc->vc_video_erase_char,
1889 vc->vc_size_row * count);
1890 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 break;
1892
1893 case SCROLL_WRAP_MOVE:
1894 if (b - t - count > 3 * vc->vc_rows >> 2) {
1895 if (t > 0)
1896 fbcon_bmove(vc, 0, 0, count, 0, t,
1897 vc->vc_cols);
1898 ywrap_up(vc, count);
1899 if (vc->vc_rows - b > 0)
1900 fbcon_bmove(vc, b - count, 0, b, 0,
1901 vc->vc_rows - b,
1902 vc->vc_cols);
1903 } else if (info->flags & FBINFO_READS_FAST)
1904 fbcon_bmove(vc, t + count, 0, t, 0,
1905 b - t - count, vc->vc_cols);
1906 else
1907 goto redraw_up;
1908 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1909 break;
1910
1911 case SCROLL_PAN_REDRAW:
1912 if ((p->yscroll + count <=
1913 2 * (p->vrows - vc->vc_rows))
1914 && ((!scroll_partial && (b - t == vc->vc_rows))
1915 || (scroll_partial
1916 && (b - t - count >
1917 3 * vc->vc_rows >> 2)))) {
1918 if (t > 0)
1919 fbcon_redraw_move(vc, p, 0, t, count);
1920 ypan_up_redraw(vc, t, count);
1921 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001922 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 vc->vc_rows - b, b);
1924 } else
1925 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1926 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1927 break;
1928
1929 case SCROLL_PAN_MOVE:
1930 if ((p->yscroll + count <=
1931 2 * (p->vrows - vc->vc_rows))
1932 && ((!scroll_partial && (b - t == vc->vc_rows))
1933 || (scroll_partial
1934 && (b - t - count >
1935 3 * vc->vc_rows >> 2)))) {
1936 if (t > 0)
1937 fbcon_bmove(vc, 0, 0, count, 0, t,
1938 vc->vc_cols);
1939 ypan_up(vc, count);
1940 if (vc->vc_rows - b > 0)
1941 fbcon_bmove(vc, b - count, 0, b, 0,
1942 vc->vc_rows - b,
1943 vc->vc_cols);
1944 } else if (info->flags & FBINFO_READS_FAST)
1945 fbcon_bmove(vc, t + count, 0, t, 0,
1946 b - t - count, vc->vc_cols);
1947 else
1948 goto redraw_up;
1949 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1950 break;
1951
1952 case SCROLL_REDRAW:
1953 redraw_up:
1954 fbcon_redraw(vc, p, t, b - t - count,
1955 count * vc->vc_cols);
1956 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1957 scr_memsetw((unsigned short *) (vc->vc_origin +
1958 vc->vc_size_row *
1959 (b - count)),
1960 vc->vc_video_erase_char,
1961 vc->vc_size_row * count);
1962 return 1;
1963 }
1964 break;
1965
1966 case SM_DOWN:
1967 if (count > vc->vc_rows) /* Maximum realistic size */
1968 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001969 if (logo_shown >= 0)
1970 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 switch (p->scrollmode) {
1972 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001973 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1974 -count);
1975 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1976 scr_memsetw((unsigned short *) (vc->vc_origin +
1977 vc->vc_size_row *
1978 t),
1979 vc->vc_video_erase_char,
1980 vc->vc_size_row * count);
1981 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 break;
1983
1984 case SCROLL_WRAP_MOVE:
1985 if (b - t - count > 3 * vc->vc_rows >> 2) {
1986 if (vc->vc_rows - b > 0)
1987 fbcon_bmove(vc, b, 0, b - count, 0,
1988 vc->vc_rows - b,
1989 vc->vc_cols);
1990 ywrap_down(vc, count);
1991 if (t > 0)
1992 fbcon_bmove(vc, count, 0, 0, 0, t,
1993 vc->vc_cols);
1994 } else if (info->flags & FBINFO_READS_FAST)
1995 fbcon_bmove(vc, t, 0, t + count, 0,
1996 b - t - count, vc->vc_cols);
1997 else
1998 goto redraw_down;
1999 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2000 break;
2001
2002 case SCROLL_PAN_MOVE:
2003 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2004 && ((!scroll_partial && (b - t == vc->vc_rows))
2005 || (scroll_partial
2006 && (b - t - count >
2007 3 * vc->vc_rows >> 2)))) {
2008 if (vc->vc_rows - b > 0)
2009 fbcon_bmove(vc, b, 0, b - count, 0,
2010 vc->vc_rows - b,
2011 vc->vc_cols);
2012 ypan_down(vc, count);
2013 if (t > 0)
2014 fbcon_bmove(vc, count, 0, 0, 0, t,
2015 vc->vc_cols);
2016 } else if (info->flags & FBINFO_READS_FAST)
2017 fbcon_bmove(vc, t, 0, t + count, 0,
2018 b - t - count, vc->vc_cols);
2019 else
2020 goto redraw_down;
2021 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2022 break;
2023
2024 case SCROLL_PAN_REDRAW:
2025 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2026 && ((!scroll_partial && (b - t == vc->vc_rows))
2027 || (scroll_partial
2028 && (b - t - count >
2029 3 * vc->vc_rows >> 2)))) {
2030 if (vc->vc_rows - b > 0)
2031 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2032 b - count);
2033 ypan_down_redraw(vc, t, count);
2034 if (t > 0)
2035 fbcon_redraw_move(vc, p, count, t, 0);
2036 } else
2037 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2038 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2039 break;
2040
2041 case SCROLL_REDRAW:
2042 redraw_down:
2043 fbcon_redraw(vc, p, b - 1, b - t - count,
2044 -count * vc->vc_cols);
2045 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2046 scr_memsetw((unsigned short *) (vc->vc_origin +
2047 vc->vc_size_row *
2048 t),
2049 vc->vc_video_erase_char,
2050 vc->vc_size_row * count);
2051 return 1;
2052 }
2053 }
2054 return 0;
2055}
2056
2057
2058static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2059 int height, int width)
2060{
2061 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2062 struct display *p = &fb_display[vc->vc_num];
2063
2064 if (fbcon_is_inactive(vc, info))
2065 return;
2066
2067 if (!width || !height)
2068 return;
2069
2070 /* Split blits that cross physical y_wrap case.
2071 * Pathological case involves 4 blits, better to use recursive
2072 * code rather than unrolled case
2073 *
2074 * Recursive invocations don't need to erase the cursor over and
2075 * over again, so we use fbcon_bmove_rec()
2076 */
2077 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2078 p->vrows - p->yscroll);
2079}
2080
2081static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2082 int dy, int dx, int height, int width, u_int y_break)
2083{
2084 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2085 struct fbcon_ops *ops = info->fbcon_par;
2086 u_int b;
2087
2088 if (sy < y_break && sy + height > y_break) {
2089 b = y_break - sy;
2090 if (dy < sy) { /* Avoid trashing self */
2091 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2092 y_break);
2093 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2094 height - b, width, y_break);
2095 } else {
2096 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2097 height - b, width, y_break);
2098 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2099 y_break);
2100 }
2101 return;
2102 }
2103
2104 if (dy < y_break && dy + height > y_break) {
2105 b = y_break - dy;
2106 if (dy < sy) { /* Avoid trashing self */
2107 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2108 y_break);
2109 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2110 height - b, width, y_break);
2111 } else {
2112 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2113 height - b, width, y_break);
2114 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2115 y_break);
2116 }
2117 return;
2118 }
2119 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2120 height, width);
2121}
2122
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002123static __inline__ void updatescrollmode(struct display *p,
2124 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct vc_data *vc)
2126{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002127 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 int fh = vc->vc_font.height;
2129 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002130 u16 t = 0;
2131 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2132 info->fix.xpanstep);
2133 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2134 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2135 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2136 info->var.xres_virtual);
2137 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2138 divides(ypan, vc->vc_font.height) && vyres > yres;
2139 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2140 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002141 divides(vc->vc_font.height, vyres) &&
2142 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002144 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2145 !(cap & FBINFO_HWACCEL_DISABLED);
2146 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2147 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002149 p->vrows = vyres/fh;
2150 if (yres > (fh * (vc->vc_rows + 1)))
2151 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2152 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 p->vrows--;
2154
2155 if (good_wrap || good_pan) {
2156 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002157 p->scrollmode = good_wrap ?
2158 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 else
2160 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2161 SCROLL_PAN_REDRAW;
2162 } else {
2163 if (reading_fast || (fast_copyarea && !fast_imageblit))
2164 p->scrollmode = SCROLL_MOVE;
2165 else
2166 p->scrollmode = SCROLL_REDRAW;
2167 }
2168}
2169
2170static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002171 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
2173 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002174 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 struct display *p = &fb_display[vc->vc_num];
2176 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002177 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002179 virt_w = FBCON_SWAP(ops->rotate, width, height);
2180 virt_h = FBCON_SWAP(ops->rotate, height, width);
2181 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2182 vc->vc_font.height);
2183 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2184 vc->vc_font.width);
2185 var.xres = virt_w * virt_fw;
2186 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 x_diff = info->var.xres - var.xres;
2188 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002189 if (x_diff < 0 || x_diff > virt_fw ||
2190 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002191 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
2193 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2194 mode = fb_find_best_mode(&var, &info->modelist);
2195 if (mode == NULL)
2196 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002197 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002199
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002200 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2204 if (CON_IS_VISIBLE(vc)) {
2205 var.activate = FB_ACTIVATE_NOW |
2206 FB_ACTIVATE_FORCE;
2207 fb_set_var(info, &var);
2208 }
2209 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002210 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 }
2212 updatescrollmode(p, info, vc);
2213 return 0;
2214}
2215
2216static int fbcon_switch(struct vc_data *vc)
2217{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002218 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002219 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 struct display *p = &fb_display[vc->vc_num];
2221 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002222 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002225 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
2227 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 if (softback_lines)
2229 fbcon_set_origin(vc);
2230 softback_top = softback_curr = softback_in = softback_buf;
2231 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002232 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 }
2234
2235 if (logo_shown >= 0) {
2236 struct vc_data *conp2 = vc_cons[logo_shown].d;
2237
2238 if (conp2->vc_top == logo_lines
2239 && conp2->vc_bottom == conp2->vc_rows)
2240 conp2->vc_top = 0;
2241 logo_shown = FBCON_LOGO_CANSHOW;
2242 }
2243
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002244 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002245 if (prev_console != -1)
2246 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 /*
2248 * FIXME: If we have multiple fbdev's loaded, we need to
2249 * update all info->currcon. Perhaps, we can place this
2250 * in a centralized structure, but this might break some
2251 * drivers.
2252 *
2253 * info->currcon = vc->vc_num;
2254 */
2255 for (i = 0; i < FB_MAX; i++) {
2256 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002257 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002259 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 }
2261 }
2262 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2263 display_to_var(&var, p);
2264 var.activate = FB_ACTIVATE_NOW;
2265
2266 /*
2267 * make sure we don't unnecessarily trip the memcmp()
2268 * in fb_set_var()
2269 */
2270 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002271 var.yoffset = info->var.yoffset;
2272 var.xoffset = info->var.xoffset;
2273 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002275 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Knut Petersen39942fd2005-12-12 22:17:19 -08002277 if (old_info != NULL && (old_info != info ||
2278 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002279 if (info->fbops->fb_set_par)
2280 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002281
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002282 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002283 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002286 if (fbcon_is_inactive(vc, info) ||
2287 ops->blank_state != FB_BLANK_UNBLANK)
2288 fbcon_del_cursor_timer(info);
2289 else
2290 fbcon_add_cursor_timer(info);
2291
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002292 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002293 ops->cursor_reset = 1;
2294
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002295 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002296 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002297 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002300 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002302
2303 if (p->userfont)
2304 charcnt = FNTCHARCNT(vc->vc_font.data);
2305
2306 if (charcnt > 256)
2307 vc->vc_complement_mask <<= 1;
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 updatescrollmode(p, info, vc);
2310
2311 switch (p->scrollmode) {
2312 case SCROLL_WRAP_MOVE:
2313 scrollback_phys_max = p->vrows - vc->vc_rows;
2314 break;
2315 case SCROLL_PAN_MOVE:
2316 case SCROLL_PAN_REDRAW:
2317 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2318 if (scrollback_phys_max < 0)
2319 scrollback_phys_max = 0;
2320 break;
2321 default:
2322 scrollback_phys_max = 0;
2323 break;
2324 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002325
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 scrollback_max = 0;
2327 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002328
2329 if (!fbcon_is_inactive(vc, info)) {
2330 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2331 ops->update_start(info);
2332 }
2333
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 fbcon_set_palette(vc, color_table);
2335 fbcon_clear_margins(vc, 0);
2336
2337 if (logo_shown == FBCON_LOGO_DRAW) {
2338
2339 logo_shown = fg_console;
2340 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002341 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 update_region(vc,
2343 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2344 vc->vc_size_row * (vc->vc_bottom -
2345 vc->vc_top) / 2);
2346 return 0;
2347 }
2348 return 1;
2349}
2350
2351static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2352 int blank)
2353{
Richard Purdie994efac2007-02-09 09:46:45 +00002354 struct fb_event event;
2355
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 if (blank) {
2357 unsigned short charmask = vc->vc_hi_font_mask ?
2358 0x1ff : 0xff;
2359 unsigned short oldc;
2360
2361 oldc = vc->vc_video_erase_char;
2362 vc->vc_video_erase_char &= charmask;
2363 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2364 vc->vc_video_erase_char = oldc;
2365 }
Richard Purdie994efac2007-02-09 09:46:45 +00002366
2367
2368 event.info = info;
2369 event.data = &blank;
2370 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371}
2372
2373static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2374{
2375 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2376 struct fbcon_ops *ops = info->fbcon_par;
2377
2378 if (mode_switch) {
2379 struct fb_var_screeninfo var = info->var;
2380
2381 ops->graphics = 1;
2382
2383 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002384 if (info->fbops->fb_save_state)
2385 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2387 fb_set_var(info, &var);
2388 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002389 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002390 } else if (info->fbops->fb_restore_state)
2391 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 }
2393
2394 if (!fbcon_is_inactive(vc, info)) {
2395 if (ops->blank_state != blank) {
2396 ops->blank_state = blank;
2397 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2398 ops->cursor_flash = (!blank);
2399
2400 if (fb_blank(info, blank))
2401 fbcon_generic_blank(vc, info, blank);
2402 }
2403
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002404 if (!blank)
2405 update_screen(vc);
2406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002408 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002409 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002410 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002411 else
2412 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002413
2414 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2418{
2419 u8 *fontdata = vc->vc_font.data;
2420 u8 *data = font->data;
2421 int i, j;
2422
2423 font->width = vc->vc_font.width;
2424 font->height = vc->vc_font.height;
2425 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2426 if (!font->data)
2427 return 0;
2428
2429 if (font->width <= 8) {
2430 j = vc->vc_font.height;
2431 for (i = 0; i < font->charcount; i++) {
2432 memcpy(data, fontdata, j);
2433 memset(data + j, 0, 32 - j);
2434 data += 32;
2435 fontdata += j;
2436 }
2437 } else if (font->width <= 16) {
2438 j = vc->vc_font.height * 2;
2439 for (i = 0; i < font->charcount; i++) {
2440 memcpy(data, fontdata, j);
2441 memset(data + j, 0, 64 - j);
2442 data += 64;
2443 fontdata += j;
2444 }
2445 } else if (font->width <= 24) {
2446 for (i = 0; i < font->charcount; i++) {
2447 for (j = 0; j < vc->vc_font.height; j++) {
2448 *data++ = fontdata[0];
2449 *data++ = fontdata[1];
2450 *data++ = fontdata[2];
2451 fontdata += sizeof(u32);
2452 }
2453 memset(data, 0, 3 * (32 - j));
2454 data += 3 * (32 - j);
2455 }
2456 } else {
2457 j = vc->vc_font.height * 4;
2458 for (i = 0; i < font->charcount; i++) {
2459 memcpy(data, fontdata, j);
2460 memset(data + j, 0, 128 - j);
2461 data += 128;
2462 fontdata += j;
2463 }
2464 }
2465 return 0;
2466}
2467
2468static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002469 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
2471 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002472 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 struct display *p = &fb_display[vc->vc_num];
2474 int resize;
2475 int cnt;
2476 char *old_data = NULL;
2477
2478 if (CON_IS_VISIBLE(vc) && softback_lines)
2479 fbcon_set_origin(vc);
2480
2481 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2482 if (p->userfont)
2483 old_data = vc->vc_font.data;
2484 if (userfont)
2485 cnt = FNTCHARCNT(data);
2486 else
2487 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002488 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 if ((p->userfont = userfont))
2490 REFCOUNT(data)++;
2491 vc->vc_font.width = w;
2492 vc->vc_font.height = h;
2493 if (vc->vc_hi_font_mask && cnt == 256) {
2494 vc->vc_hi_font_mask = 0;
2495 if (vc->vc_can_do_color) {
2496 vc->vc_complement_mask >>= 1;
2497 vc->vc_s_complement_mask >>= 1;
2498 }
2499
2500 /* ++Edmund: reorder the attribute bits */
2501 if (vc->vc_can_do_color) {
2502 unsigned short *cp =
2503 (unsigned short *) vc->vc_origin;
2504 int count = vc->vc_screenbuf_size / 2;
2505 unsigned short c;
2506 for (; count > 0; count--, cp++) {
2507 c = scr_readw(cp);
2508 scr_writew(((c & 0xfe00) >> 1) |
2509 (c & 0xff), cp);
2510 }
2511 c = vc->vc_video_erase_char;
2512 vc->vc_video_erase_char =
2513 ((c & 0xfe00) >> 1) | (c & 0xff);
2514 vc->vc_attr >>= 1;
2515 }
2516 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2517 vc->vc_hi_font_mask = 0x100;
2518 if (vc->vc_can_do_color) {
2519 vc->vc_complement_mask <<= 1;
2520 vc->vc_s_complement_mask <<= 1;
2521 }
2522
2523 /* ++Edmund: reorder the attribute bits */
2524 {
2525 unsigned short *cp =
2526 (unsigned short *) vc->vc_origin;
2527 int count = vc->vc_screenbuf_size / 2;
2528 unsigned short c;
2529 for (; count > 0; count--, cp++) {
2530 unsigned short newc;
2531 c = scr_readw(cp);
2532 if (vc->vc_can_do_color)
2533 newc =
2534 ((c & 0xff00) << 1) | (c &
2535 0xff);
2536 else
2537 newc = c & ~0x100;
2538 scr_writew(newc, cp);
2539 }
2540 c = vc->vc_video_erase_char;
2541 if (vc->vc_can_do_color) {
2542 vc->vc_video_erase_char =
2543 ((c & 0xff00) << 1) | (c & 0xff);
2544 vc->vc_attr <<= 1;
2545 } else
2546 vc->vc_video_erase_char = c & ~0x100;
2547 }
2548
2549 }
2550
2551 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002552 int cols, rows;
2553
2554 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2555 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2556 cols /= w;
2557 rows /= h;
2558 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002559 if (CON_IS_VISIBLE(vc) && softback_buf)
2560 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 } else if (CON_IS_VISIBLE(vc)
2562 && vc->vc_mode == KD_TEXT) {
2563 fbcon_clear_margins(vc, 0);
2564 update_screen(vc);
2565 }
2566
2567 if (old_data && (--REFCOUNT(old_data) == 0))
2568 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2569 return 0;
2570}
2571
2572static int fbcon_copy_font(struct vc_data *vc, int con)
2573{
2574 struct display *od = &fb_display[con];
2575 struct console_font *f = &vc->vc_font;
2576
2577 if (od->fontdata == f->data)
2578 return 0; /* already the same font... */
2579 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2580}
2581
2582/*
2583 * User asked to set font; we are guaranteed that
2584 * a) width and height are in range 1..32
2585 * b) charcount does not exceed 512
2586 * but lets not assume that, since someone might someday want to use larger
2587 * fonts. And charcount of 512 is small for unicode support.
2588 *
2589 * However, user space gives the font in 32 rows , regardless of
2590 * actual font height. So a new API is needed if support for larger fonts
2591 * is ever implemented.
2592 */
2593
2594static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2595{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002596 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 unsigned charcount = font->charcount;
2598 int w = font->width;
2599 int h = font->height;
2600 int size;
2601 int i, csum;
2602 u8 *new_data, *data = font->data;
2603 int pitch = (font->width+7) >> 3;
2604
2605 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2606 * If not this check should be changed to charcount < 256 */
2607 if (charcount != 256 && charcount != 512)
2608 return -EINVAL;
2609
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002610 /* Make sure drawing engine can handle the font */
2611 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2612 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2613 return -EINVAL;
2614
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002615 /* Make sure driver can handle the font length */
2616 if (fbcon_invalid_charcount(info, charcount))
2617 return -EINVAL;
2618
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 size = h * pitch * charcount;
2620
2621 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2622
2623 if (!new_data)
2624 return -ENOMEM;
2625
2626 new_data += FONT_EXTRA_WORDS * sizeof(int);
2627 FNTSIZE(new_data) = size;
2628 FNTCHARCNT(new_data) = charcount;
2629 REFCOUNT(new_data) = 0; /* usage counter */
2630 for (i=0; i< charcount; i++) {
2631 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2632 }
2633
2634 /* Since linux has a nice crc32 function use it for counting font
2635 * checksums. */
2636 csum = crc32(0, new_data, size);
2637
2638 FNTSUM(new_data) = csum;
2639 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002640 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 struct vc_data *tmp = vc_cons[i].d;
2642
2643 if (fb_display[i].userfont &&
2644 fb_display[i].fontdata &&
2645 FNTSUM(fb_display[i].fontdata) == csum &&
2646 FNTSIZE(fb_display[i].fontdata) == size &&
2647 tmp->vc_font.width == w &&
2648 !memcmp(fb_display[i].fontdata, new_data, size)) {
2649 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002650 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 break;
2652 }
2653 }
2654 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2655}
2656
2657static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2658{
2659 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002660 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
2662 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002663 f = get_default_font(info->var.xres, info->var.yres,
2664 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 else if (!(f = find_font(name)))
2666 return -ENOENT;
2667
2668 font->width = f->width;
2669 font->height = f->height;
2670 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2671}
2672
2673static u16 palette_red[16];
2674static u16 palette_green[16];
2675static u16 palette_blue[16];
2676
2677static struct fb_cmap palette_cmap = {
2678 0, 16, palette_red, palette_green, palette_blue, NULL
2679};
2680
2681static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2682{
2683 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2684 int i, j, k, depth;
2685 u8 val;
2686
2687 if (fbcon_is_inactive(vc, info))
2688 return -EINVAL;
2689
2690 if (!CON_IS_VISIBLE(vc))
2691 return 0;
2692
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002693 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 if (depth > 3) {
2695 for (i = j = 0; i < 16; i++) {
2696 k = table[i];
2697 val = vc->vc_palette[j++];
2698 palette_red[k] = (val << 8) | val;
2699 val = vc->vc_palette[j++];
2700 palette_green[k] = (val << 8) | val;
2701 val = vc->vc_palette[j++];
2702 palette_blue[k] = (val << 8) | val;
2703 }
2704 palette_cmap.len = 16;
2705 palette_cmap.start = 0;
2706 /*
2707 * If framebuffer is capable of less than 16 colors,
2708 * use default palette of fbcon.
2709 */
2710 } else
2711 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2712
2713 return fb_set_cmap(&palette_cmap, info);
2714}
2715
2716static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2717{
2718 unsigned long p;
2719 int line;
2720
2721 if (vc->vc_num != fg_console || !softback_lines)
2722 return (u16 *) (vc->vc_origin + offset);
2723 line = offset / vc->vc_size_row;
2724 if (line >= softback_lines)
2725 return (u16 *) (vc->vc_origin + offset -
2726 softback_lines * vc->vc_size_row);
2727 p = softback_curr + offset;
2728 if (p >= softback_end)
2729 p += softback_buf - softback_end;
2730 return (u16 *) p;
2731}
2732
2733static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2734 int *px, int *py)
2735{
2736 unsigned long ret;
2737 int x, y;
2738
2739 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2740 unsigned long offset = (pos - vc->vc_origin) / 2;
2741
2742 x = offset % vc->vc_cols;
2743 y = offset / vc->vc_cols;
2744 if (vc->vc_num == fg_console)
2745 y += softback_lines;
2746 ret = pos + (vc->vc_cols - x) * 2;
2747 } else if (vc->vc_num == fg_console && softback_lines) {
2748 unsigned long offset = pos - softback_curr;
2749
2750 if (pos < softback_curr)
2751 offset += softback_end - softback_buf;
2752 offset /= 2;
2753 x = offset % vc->vc_cols;
2754 y = offset / vc->vc_cols;
2755 ret = pos + (vc->vc_cols - x) * 2;
2756 if (ret == softback_end)
2757 ret = softback_buf;
2758 if (ret == softback_in)
2759 ret = vc->vc_origin;
2760 } else {
2761 /* Should not happen */
2762 x = y = 0;
2763 ret = vc->vc_origin;
2764 }
2765 if (px)
2766 *px = x;
2767 if (py)
2768 *py = y;
2769 return ret;
2770}
2771
2772/* As we might be inside of softback, we may work with non-contiguous buffer,
2773 that's why we have to use a separate routine. */
2774static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2775{
2776 while (cnt--) {
2777 u16 a = scr_readw(p);
2778 if (!vc->vc_can_do_color)
2779 a ^= 0x0800;
2780 else if (vc->vc_hi_font_mask == 0x100)
2781 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2782 (((a) & 0x0e00) << 4);
2783 else
2784 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2785 (((a) & 0x0700) << 4);
2786 scr_writew(a, p++);
2787 if (p == (u16 *) softback_end)
2788 p = (u16 *) softback_buf;
2789 if (p == (u16 *) softback_in)
2790 p = (u16 *) vc->vc_origin;
2791 }
2792}
2793
2794static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2795{
2796 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002797 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 struct display *p = &fb_display[fg_console];
2799 int offset, limit, scrollback_old;
2800
2801 if (softback_top) {
2802 if (vc->vc_num != fg_console)
2803 return 0;
2804 if (vc->vc_mode != KD_TEXT || !lines)
2805 return 0;
2806 if (logo_shown >= 0) {
2807 struct vc_data *conp2 = vc_cons[logo_shown].d;
2808
2809 if (conp2->vc_top == logo_lines
2810 && conp2->vc_bottom == conp2->vc_rows)
2811 conp2->vc_top = 0;
2812 if (logo_shown == vc->vc_num) {
2813 unsigned long p, q;
2814 int i;
2815
2816 p = softback_in;
2817 q = vc->vc_origin +
2818 logo_lines * vc->vc_size_row;
2819 for (i = 0; i < logo_lines; i++) {
2820 if (p == softback_top)
2821 break;
2822 if (p == softback_buf)
2823 p = softback_end;
2824 p -= vc->vc_size_row;
2825 q -= vc->vc_size_row;
2826 scr_memcpyw((u16 *) q, (u16 *) p,
2827 vc->vc_size_row);
2828 }
David Hollister308af922006-05-30 21:25:36 -07002829 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 update_region(vc, vc->vc_origin,
2831 logo_lines * vc->vc_cols);
2832 }
2833 logo_shown = FBCON_LOGO_CANSHOW;
2834 }
2835 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2836 fbcon_redraw_softback(vc, p, lines);
2837 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2838 return 0;
2839 }
2840
2841 if (!scrollback_phys_max)
2842 return -ENOSYS;
2843
2844 scrollback_old = scrollback_current;
2845 scrollback_current -= lines;
2846 if (scrollback_current < 0)
2847 scrollback_current = 0;
2848 else if (scrollback_current > scrollback_max)
2849 scrollback_current = scrollback_max;
2850 if (scrollback_current == scrollback_old)
2851 return 0;
2852
2853 if (fbcon_is_inactive(vc, info))
2854 return 0;
2855
2856 fbcon_cursor(vc, CM_ERASE);
2857
2858 offset = p->yscroll - scrollback_current;
2859 limit = p->vrows;
2860 switch (p->scrollmode) {
2861 case SCROLL_WRAP_MOVE:
2862 info->var.vmode |= FB_VMODE_YWRAP;
2863 break;
2864 case SCROLL_PAN_MOVE:
2865 case SCROLL_PAN_REDRAW:
2866 limit -= vc->vc_rows;
2867 info->var.vmode &= ~FB_VMODE_YWRAP;
2868 break;
2869 }
2870 if (offset < 0)
2871 offset += limit;
2872 else if (offset >= limit)
2873 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002874
2875 ops->var.xoffset = 0;
2876 ops->var.yoffset = offset * vc->vc_font.height;
2877 ops->update_start(info);
2878
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 if (!scrollback_current)
2880 fbcon_cursor(vc, CM_DRAW);
2881 return 0;
2882}
2883
2884static int fbcon_set_origin(struct vc_data *vc)
2885{
2886 if (softback_lines)
2887 fbcon_scrolldelta(vc, softback_lines);
2888 return 0;
2889}
2890
2891static void fbcon_suspended(struct fb_info *info)
2892{
2893 struct vc_data *vc = NULL;
2894 struct fbcon_ops *ops = info->fbcon_par;
2895
2896 if (!ops || ops->currcon < 0)
2897 return;
2898 vc = vc_cons[ops->currcon].d;
2899
2900 /* Clear cursor, restore saved data */
2901 fbcon_cursor(vc, CM_ERASE);
2902}
2903
2904static void fbcon_resumed(struct fb_info *info)
2905{
2906 struct vc_data *vc;
2907 struct fbcon_ops *ops = info->fbcon_par;
2908
2909 if (!ops || ops->currcon < 0)
2910 return;
2911 vc = vc_cons[ops->currcon].d;
2912
2913 update_screen(vc);
2914}
2915
2916static void fbcon_modechanged(struct fb_info *info)
2917{
2918 struct fbcon_ops *ops = info->fbcon_par;
2919 struct vc_data *vc;
2920 struct display *p;
2921 int rows, cols;
2922
2923 if (!ops || ops->currcon < 0)
2924 return;
2925 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002926 if (vc->vc_mode != KD_TEXT ||
2927 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 return;
2929
2930 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002931 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933 if (CON_IS_VISIBLE(vc)) {
2934 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002935 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2936 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2937 cols /= vc->vc_font.width;
2938 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 vc_resize(vc, cols, rows);
2940 updatescrollmode(p, info, vc);
2941 scrollback_max = 0;
2942 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002943
2944 if (!fbcon_is_inactive(vc, info)) {
2945 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2946 ops->update_start(info);
2947 }
2948
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 fbcon_set_palette(vc, color_table);
2950 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002951 if (softback_buf)
2952 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 }
2954}
2955
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002956static void fbcon_set_all_vcs(struct fb_info *info)
2957{
2958 struct fbcon_ops *ops = info->fbcon_par;
2959 struct vc_data *vc;
2960 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002961 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002962
2963 if (!ops || ops->currcon < 0)
2964 return;
2965
Antonino A. Daplase614b182006-06-26 00:27:09 -07002966 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002967 vc = vc_cons[i].d;
2968 if (!vc || vc->vc_mode != KD_TEXT ||
2969 registered_fb[con2fb_map[i]] != info)
2970 continue;
2971
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002972 if (CON_IS_VISIBLE(vc)) {
2973 fg = i;
2974 continue;
2975 }
2976
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002977 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002978 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002979 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002980 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2981 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002982 cols /= vc->vc_font.width;
2983 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002984 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002985 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002986
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002987 if (fg != -1)
2988 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002989}
2990
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991static int fbcon_mode_deleted(struct fb_info *info,
2992 struct fb_videomode *mode)
2993{
2994 struct fb_info *fb_info;
2995 struct display *p;
2996 int i, j, found = 0;
2997
2998 /* before deletion, ensure that mode is not in use */
2999 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3000 j = con2fb_map[i];
3001 if (j == -1)
3002 continue;
3003 fb_info = registered_fb[j];
3004 if (fb_info != info)
3005 continue;
3006 p = &fb_display[i];
3007 if (!p || !p->mode)
3008 continue;
3009 if (fb_mode_is_equal(p->mode, mode)) {
3010 found = 1;
3011 break;
3012 }
3013 }
3014 return found;
3015}
3016
Jesse Barnescfafca82007-07-17 04:05:33 -07003017#ifdef CONFIG_VT_HW_CONSOLE_BINDING
3018static int fbcon_unbind(void)
3019{
3020 int ret;
3021
3022 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3023 fbcon_is_default);
3024 return ret;
3025}
3026#else
3027static inline int fbcon_unbind(void)
3028{
3029 return -EINVAL;
3030}
3031#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3032
3033static int fbcon_fb_unbind(int idx)
3034{
3035 int i, new_idx = -1, ret = 0;
3036
3037 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3038 if (con2fb_map[i] != idx &&
3039 con2fb_map[i] != -1) {
3040 new_idx = i;
3041 break;
3042 }
3043 }
3044
3045 if (new_idx != -1) {
3046 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3047 if (con2fb_map[i] == idx)
3048 set_con2fb_map(i, new_idx, 0);
3049 }
3050 } else
3051 ret = fbcon_unbind();
3052
3053 return ret;
3054}
3055
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003056static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003057{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003058 int i, idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003059
3060 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3061 if (con2fb_map[i] == idx)
3062 con2fb_map[i] = -1;
3063 }
3064
3065 if (idx == info_idx) {
3066 info_idx = -1;
3067
3068 for (i = 0; i < FB_MAX; i++) {
3069 if (registered_fb[i] != NULL) {
3070 info_idx = i;
3071 break;
3072 }
3073 }
3074 }
3075
3076 if (info_idx != -1) {
3077 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3078 if (con2fb_map[i] == -1)
3079 con2fb_map[i] = info_idx;
3080 }
3081 }
3082
3083 if (!num_registered_fb)
3084 unregister_con_driver(&fb_con);
3085
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003086
3087 if (primary_device == idx)
3088 primary_device = -1;
3089
Antonino A. Daplase614b182006-06-26 00:27:09 -07003090 return 0;
3091}
3092
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003093#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003094static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003096 if (!map_override && primary_device == -1 &&
3097 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003098 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003099
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003100 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3101 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003102 primary_device = info->node;
3103
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003104 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003105 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003106
3107 if (con_is_bound(&fb_con)) {
3108 printk(KERN_INFO "fbcon: Remapping primary device, "
3109 "fb%i, to tty %i-%i\n", info->node,
3110 first_fb_vc + 1, last_fb_vc + 1);
3111 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003112 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003113 }
3114
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003115}
3116#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003117static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003118{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003119 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003120}
3121#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3122
3123static int fbcon_fb_registered(struct fb_info *info)
3124{
3125 int ret = 0, i, idx = info->node;
3126
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003127 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128
3129 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003130 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 if (con2fb_map_boot[i] == idx) {
3132 info_idx = idx;
3133 break;
3134 }
3135 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 if (info_idx != -1)
3138 ret = fbcon_takeover(1);
3139 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003140 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003141 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 set_con2fb_map(i, idx, 0);
3143 }
3144 }
3145
3146 return ret;
3147}
3148
3149static void fbcon_fb_blanked(struct fb_info *info, int blank)
3150{
3151 struct fbcon_ops *ops = info->fbcon_par;
3152 struct vc_data *vc;
3153
3154 if (!ops || ops->currcon < 0)
3155 return;
3156
3157 vc = vc_cons[ops->currcon].d;
3158 if (vc->vc_mode != KD_TEXT ||
3159 registered_fb[con2fb_map[ops->currcon]] != info)
3160 return;
3161
3162 if (CON_IS_VISIBLE(vc)) {
3163 if (blank)
3164 do_blank_screen(0);
3165 else
3166 do_unblank_screen(0);
3167 }
3168 ops->blank_state = blank;
3169}
3170
3171static void fbcon_new_modelist(struct fb_info *info)
3172{
3173 int i;
3174 struct vc_data *vc;
3175 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003176 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Antonino A. Daplase614b182006-06-26 00:27:09 -07003178 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 if (registered_fb[con2fb_map[i]] != info)
3180 continue;
3181 if (!fb_display[i].mode)
3182 continue;
3183 vc = vc_cons[i].d;
3184 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003185 mode = fb_find_nearest_mode(fb_display[i].mode,
3186 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003188 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 }
3190}
3191
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003192static void fbcon_get_requirement(struct fb_info *info,
3193 struct fb_blit_caps *caps)
3194{
3195 struct vc_data *vc;
3196 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003197
3198 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003199 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003200
3201 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3202 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003203 if (vc && vc->vc_mode == KD_TEXT &&
3204 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003205 p = &fb_display[i];
3206 caps->x |= 1 << (vc->vc_font.width - 1);
3207 caps->y |= 1 << (vc->vc_font.height - 1);
3208 charcnt = (p->userfont) ?
3209 FNTCHARCNT(p->fontdata) : 256;
3210 if (caps->len < charcnt)
3211 caps->len = charcnt;
3212 }
3213 }
3214 } else {
3215 vc = vc_cons[fg_console].d;
3216
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003217 if (vc && vc->vc_mode == KD_TEXT &&
3218 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003219 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003220 caps->x = 1 << (vc->vc_font.width - 1);
3221 caps->y = 1 << (vc->vc_font.height - 1);
3222 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003223 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003224 }
3225 }
3226}
3227
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228static int fbcon_event_notify(struct notifier_block *self,
3229 unsigned long action, void *data)
3230{
3231 struct fb_event *event = data;
3232 struct fb_info *info = event->info;
3233 struct fb_videomode *mode;
3234 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003235 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 int ret = 0;
3237
Antonino A. Daplase614b182006-06-26 00:27:09 -07003238 /*
3239 * ignore all events except driver registration and deregistration
3240 * if fbcon is not active
3241 */
3242 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3243 action == FB_EVENT_FB_UNREGISTERED))
3244 goto done;
3245
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 switch(action) {
3247 case FB_EVENT_SUSPEND:
3248 fbcon_suspended(info);
3249 break;
3250 case FB_EVENT_RESUME:
3251 fbcon_resumed(info);
3252 break;
3253 case FB_EVENT_MODE_CHANGE:
3254 fbcon_modechanged(info);
3255 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003256 case FB_EVENT_MODE_CHANGE_ALL:
3257 fbcon_set_all_vcs(info);
3258 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 case FB_EVENT_MODE_DELETE:
3260 mode = event->data;
3261 ret = fbcon_mode_deleted(info, mode);
3262 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003263 case FB_EVENT_FB_UNBIND:
3264 ret = fbcon_fb_unbind(info->node);
3265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003267 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003269 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003270 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003271 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 case FB_EVENT_SET_CONSOLE_MAP:
3273 con2fb = event->data;
3274 ret = set_con2fb_map(con2fb->console - 1,
3275 con2fb->framebuffer, 1);
3276 break;
3277 case FB_EVENT_GET_CONSOLE_MAP:
3278 con2fb = event->data;
3279 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3280 break;
3281 case FB_EVENT_BLANK:
3282 fbcon_fb_blanked(info, *(int *)event->data);
3283 break;
3284 case FB_EVENT_NEW_MODELIST:
3285 fbcon_new_modelist(info);
3286 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003287 case FB_EVENT_GET_REQ:
3288 caps = event->data;
3289 fbcon_get_requirement(info, caps);
3290 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 }
3292
Antonino A. Daplase614b182006-06-26 00:27:09 -07003293done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 return ret;
3295}
3296
3297/*
3298 * The console `switch' structure for the frame buffer based console
3299 */
3300
3301static const struct consw fb_con = {
3302 .owner = THIS_MODULE,
3303 .con_startup = fbcon_startup,
3304 .con_init = fbcon_init,
3305 .con_deinit = fbcon_deinit,
3306 .con_clear = fbcon_clear,
3307 .con_putc = fbcon_putc,
3308 .con_putcs = fbcon_putcs,
3309 .con_cursor = fbcon_cursor,
3310 .con_scroll = fbcon_scroll,
3311 .con_bmove = fbcon_bmove,
3312 .con_switch = fbcon_switch,
3313 .con_blank = fbcon_blank,
3314 .con_font_set = fbcon_set_font,
3315 .con_font_get = fbcon_get_font,
3316 .con_font_default = fbcon_set_def_font,
3317 .con_font_copy = fbcon_copy_font,
3318 .con_set_palette = fbcon_set_palette,
3319 .con_scrolldelta = fbcon_scrolldelta,
3320 .con_set_origin = fbcon_set_origin,
3321 .con_invert_region = fbcon_invert_region,
3322 .con_screen_pos = fbcon_screen_pos,
3323 .con_getxy = fbcon_getxy,
3324 .con_resize = fbcon_resize,
3325};
3326
3327static struct notifier_block fbcon_event_notifier = {
3328 .notifier_call = fbcon_event_notify,
3329};
3330
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003331static ssize_t store_rotate(struct device *device,
3332 struct device_attribute *attr, const char *buf,
3333 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003334{
3335 struct fb_info *info;
3336 int rotate, idx;
3337 char **last = NULL;
3338
Antonino A. Daplase614b182006-06-26 00:27:09 -07003339 if (fbcon_has_exited)
3340 return count;
3341
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003342 acquire_console_sem();
3343 idx = con2fb_map[fg_console];
3344
3345 if (idx == -1 || registered_fb[idx] == NULL)
3346 goto err;
3347
3348 info = registered_fb[idx];
3349 rotate = simple_strtoul(buf, last, 0);
3350 fbcon_rotate(info, rotate);
3351err:
3352 release_console_sem();
3353 return count;
3354}
3355
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003356static ssize_t store_rotate_all(struct device *device,
3357 struct device_attribute *attr,const char *buf,
3358 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003359{
3360 struct fb_info *info;
3361 int rotate, idx;
3362 char **last = NULL;
3363
Antonino A. Daplase614b182006-06-26 00:27:09 -07003364 if (fbcon_has_exited)
3365 return count;
3366
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003367 acquire_console_sem();
3368 idx = con2fb_map[fg_console];
3369
3370 if (idx == -1 || registered_fb[idx] == NULL)
3371 goto err;
3372
3373 info = registered_fb[idx];
3374 rotate = simple_strtoul(buf, last, 0);
3375 fbcon_rotate_all(info, rotate);
3376err:
3377 release_console_sem();
3378 return count;
3379}
3380
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003381static ssize_t show_rotate(struct device *device,
3382 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003383{
3384 struct fb_info *info;
3385 int rotate = 0, idx;
3386
Antonino A. Daplase614b182006-06-26 00:27:09 -07003387 if (fbcon_has_exited)
3388 return 0;
3389
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003390 acquire_console_sem();
3391 idx = con2fb_map[fg_console];
3392
3393 if (idx == -1 || registered_fb[idx] == NULL)
3394 goto err;
3395
3396 info = registered_fb[idx];
3397 rotate = fbcon_get_rotate(info);
3398err:
3399 release_console_sem();
3400 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3401}
3402
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003403static ssize_t show_cursor_blink(struct device *device,
3404 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003405{
3406 struct fb_info *info;
3407 struct fbcon_ops *ops;
3408 int idx, blink = -1;
3409
3410 if (fbcon_has_exited)
3411 return 0;
3412
3413 acquire_console_sem();
3414 idx = con2fb_map[fg_console];
3415
3416 if (idx == -1 || registered_fb[idx] == NULL)
3417 goto err;
3418
3419 info = registered_fb[idx];
3420 ops = info->fbcon_par;
3421
3422 if (!ops)
3423 goto err;
3424
3425 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3426err:
3427 release_console_sem();
3428 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3429}
3430
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003431static ssize_t store_cursor_blink(struct device *device,
3432 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003433 const char *buf, size_t count)
3434{
3435 struct fb_info *info;
3436 int blink, idx;
3437 char **last = NULL;
3438
3439 if (fbcon_has_exited)
3440 return count;
3441
3442 acquire_console_sem();
3443 idx = con2fb_map[fg_console];
3444
3445 if (idx == -1 || registered_fb[idx] == NULL)
3446 goto err;
3447
3448 info = registered_fb[idx];
3449
3450 if (!info->fbcon_par)
3451 goto err;
3452
3453 blink = simple_strtoul(buf, last, 0);
3454
3455 if (blink) {
3456 fbcon_cursor_noblink = 0;
3457 fbcon_add_cursor_timer(info);
3458 } else {
3459 fbcon_cursor_noblink = 1;
3460 fbcon_del_cursor_timer(info);
3461 }
3462
3463err:
3464 release_console_sem();
3465 return count;
3466}
3467
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003468static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003469 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3470 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003471 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3472 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003473};
3474
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003475static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003476{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003477 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003478
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003479 fbcon_has_sysfs = 1;
3480
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003481 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3482 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003483
3484 if (error)
3485 break;
3486 }
3487
3488 if (error) {
3489 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003490 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003491
3492 fbcon_has_sysfs = 0;
3493 }
3494
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003495 return 0;
3496}
3497
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003498static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003501 int i;
3502
3503 acquire_console_sem();
3504
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 for (i = 0; i < FB_MAX; i++) {
3506 if (registered_fb[i] != NULL) {
3507 info_idx = i;
3508 break;
3509 }
3510 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003511
3512 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 fbcon_takeover(0);
3514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515}
3516
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003517static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003518{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003519 struct fb_info *info;
3520 int i, j, mapped;
3521
Antonino A. Daplase614b182006-06-26 00:27:09 -07003522 if (fbcon_has_exited)
3523 return;
3524
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003525#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003526 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003527#endif
3528#ifdef CONFIG_MAC
3529 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003530 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003531#endif
3532
3533 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003534 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003535
3536 for (i = 0; i < FB_MAX; i++) {
3537 mapped = 0;
3538 info = registered_fb[i];
3539
3540 if (info == NULL)
3541 continue;
3542
Antonino A. Daplase614b182006-06-26 00:27:09 -07003543 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3544 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003545 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003546 }
3547
3548 if (mapped) {
3549 if (info->fbops->fb_release)
3550 info->fbops->fb_release(info, 0);
3551 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003552
3553 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003554 struct fbcon_ops *ops = info->fbcon_par;
3555
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003556 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003557 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003558 kfree(info->fbcon_par);
3559 info->fbcon_par = NULL;
3560 }
3561
3562 if (info->queue.func == fb_flashcursor)
3563 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003564 }
3565 }
3566
Antonino A. Daplase614b182006-06-26 00:27:09 -07003567 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003568}
3569
3570static int __init fb_console_init(void)
3571{
3572 int i;
3573
3574 acquire_console_sem();
3575 fb_register_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003576 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003577
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003578 if (IS_ERR(fbcon_device)) {
3579 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003580 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003581 PTR_ERR(fbcon_device));
3582 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003583 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003584 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003585
3586 for (i = 0; i < MAX_NR_CONSOLES; i++)
3587 con2fb_map[i] = -1;
3588
3589 release_console_sem();
3590 fbcon_start();
3591 return 0;
3592}
3593
3594module_init(fb_console_init);
3595
3596#ifdef MODULE
3597
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003598static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003599{
3600 int i;
3601
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003602 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003603 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3604 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003605
3606 fbcon_has_sysfs = 0;
3607 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003608}
3609
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610static void __exit fb_console_exit(void)
3611{
3612 acquire_console_sem();
3613 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003614 fbcon_deinit_device();
3615 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003616 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003618 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619}
3620
3621module_exit(fb_console_exit);
3622
3623#endif
3624
3625MODULE_LICENSE("GPL");