blob: 13b67ee8b3c0eb1320c90aa585ac71e3d7bdfee5 [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>
81#include <asm/uaccess.h>
82#ifdef CONFIG_ATARI
83#include <asm/atariints.h>
84#endif
85#ifdef CONFIG_MAC
86#include <asm/macints.h>
87#endif
88#if defined(__mc68000__) || defined(CONFIG_APUS)
89#include <asm/machdep.h>
90#include <asm/setup.h>
91#endif
92
93#include "fbcon.h"
94
95#ifdef FBCONDEBUG
96# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
97#else
98# define DPRINTK(fmt, args...)
99#endif
100
101enum {
102 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
103 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
104 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
105};
106
Antonino A. Daplasab767202005-11-13 16:06:32 -0800107static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static signed char con2fb_map[MAX_NR_CONSOLES];
110static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700111#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int logo_height;
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114static int logo_lines;
115/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
116 enums. */
117static int logo_shown = FBCON_LOGO_CANSHOW;
118/* Software scrollback */
119static int fbcon_softback_size = 32768;
120static unsigned long softback_buf, softback_curr;
121static unsigned long softback_in;
122static unsigned long softback_top, softback_end;
123static int softback_lines;
124/* console mappings */
125static int first_fb_vc;
126static int last_fb_vc = MAX_NR_CONSOLES - 1;
127static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700128static int fbcon_has_exited;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700129static int primary_device = -1;
130static int map_override;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* font data */
133static char fontname[40];
134
135/* current fb_info */
136static int info_idx = -1;
137
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800138/* console rotation */
139static int rotate;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700140static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142static const struct consw fb_con;
143
144#define CM_SOFTBACK (8)
145
146#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static int fbcon_set_origin(struct vc_data *);
149
150#define CURSOR_DRAW_DELAY (1)
151
152/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#define ATARI_CURSOR_BLINK_RATE (42)
154#define MAC_CURSOR_BLINK_RATE (32)
155#define DEFAULT_CURSOR_BLINK_RATE (20)
156
157static int vbl_cursor_cnt;
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700158static int fbcon_cursor_noblink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
161
162/*
163 * Interface used by the world
164 */
165
166static const char *fbcon_startup(void);
167static void fbcon_init(struct vc_data *vc, int init);
168static void fbcon_deinit(struct vc_data *vc);
169static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
170 int width);
171static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
172static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
173 int count, int ypos, int xpos);
174static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
175static void fbcon_cursor(struct vc_data *vc, int mode);
176static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
177 int count);
178static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
179 int height, int width);
180static int fbcon_switch(struct vc_data *vc);
181static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
182static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
183static int fbcon_scrolldelta(struct vc_data *vc, int lines);
184
185/*
186 * Internal routines
187 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static __inline__ void ywrap_up(struct vc_data *vc, int count);
189static __inline__ void ywrap_down(struct vc_data *vc, int count);
190static __inline__ void ypan_up(struct vc_data *vc, int count);
191static __inline__ void ypan_down(struct vc_data *vc, int count);
192static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
193 int dy, int dx, int height, int width, u_int y_break);
194static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700195 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
197 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800198static void fbcon_modechanged(struct fb_info *info);
199static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700200static void fbcon_start(void);
201static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700202static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204#ifdef CONFIG_MAC
205/*
206 * On the Macintoy, there may or may not be a working VBL int. We need to probe
207 */
208static int vbl_detected;
209
David Howells7d12e782006-10-05 14:55:46 +0100210static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 vbl_detected++;
213 return IRQ_HANDLED;
214}
215#endif
216
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800217#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800218static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800219{
220 struct fbcon_ops *ops = info->fbcon_par;
221
222 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800223 ops->p->con_rotate < 4)
224 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800225 else
226 ops->rotate = 0;
227}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800228
229static void fbcon_rotate(struct fb_info *info, u32 rotate)
230{
231 struct fbcon_ops *ops= info->fbcon_par;
232 struct fb_info *fb_info;
233
234 if (!ops || ops->currcon == -1)
235 return;
236
237 fb_info = registered_fb[con2fb_map[ops->currcon]];
238
239 if (info == fb_info) {
240 struct display *p = &fb_display[ops->currcon];
241
242 if (rotate < 4)
243 p->con_rotate = rotate;
244 else
245 p->con_rotate = 0;
246
247 fbcon_modechanged(info);
248 }
249}
250
251static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
252{
253 struct fbcon_ops *ops = info->fbcon_par;
254 struct vc_data *vc;
255 struct display *p;
256 int i;
257
258 if (!ops || ops->currcon < 0 || rotate > 3)
259 return;
260
Antonino A. Daplase614b182006-06-26 00:27:09 -0700261 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800262 vc = vc_cons[i].d;
263 if (!vc || vc->vc_mode != KD_TEXT ||
264 registered_fb[con2fb_map[i]] != info)
265 continue;
266
267 p = &fb_display[vc->vc_num];
268 p->con_rotate = rotate;
269 }
270
271 fbcon_set_all_vcs(info);
272}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800273#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800274static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800275{
276 struct fbcon_ops *ops = info->fbcon_par;
277
278 ops->rotate = FB_ROTATE_UR;
279}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800280
281static void fbcon_rotate(struct fb_info *info, u32 rotate)
282{
283 return;
284}
285
286static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
287{
288 return;
289}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800290#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800291
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800292static int fbcon_get_rotate(struct fb_info *info)
293{
294 struct fbcon_ops *ops = info->fbcon_par;
295
296 return (ops) ? ops->rotate : 0;
297}
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
300{
301 struct fbcon_ops *ops = info->fbcon_par;
302
303 return (info->state != FBINFO_STATE_RUNNING ||
304 vc->vc_mode != KD_TEXT || ops->graphics);
305}
306
307static inline int get_color(struct vc_data *vc, struct fb_info *info,
308 u16 c, int is_fg)
309{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700310 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 int color = 0;
312
313 if (console_blanked) {
314 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
315
316 c = vc->vc_video_erase_char & charmask;
317 }
318
319 if (depth != 1)
320 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
321 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
322
323 switch (depth) {
324 case 1:
325 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700326 int col = ~(0xfff << (max(info->var.green.length,
327 max(info->var.red.length,
328 info->var.blue.length)))) & 0xff;
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700331 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
332 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 if (console_blanked)
335 fg = bg;
336
337 color = (is_fg) ? fg : bg;
338 break;
339 }
340 case 2:
341 /*
342 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700343 * is grayscale. However, simply dividing the values by 4
344 * will not work, as colors 1, 2 and 3 will be scaled-down
345 * to zero rendering them invisible. So empirically convert
346 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700348 switch (color) {
349 case 0:
350 color = 0; /* black */
351 break;
352 case 1 ... 6:
353 color = 2; /* white */
354 break;
355 case 7 ... 8:
356 color = 1; /* gray */
357 break;
358 default:
359 color = 3; /* intense white */
360 break;
361 }
362 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 case 3:
364 /*
365 * Last 8 entries of default 16-color palette is a more intense
366 * version of the first 8 (i.e., same chrominance, different
367 * luminance).
368 */
369 color &= 7;
370 break;
371 }
372
373
374 return color;
375}
376
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800377static void fbcon_update_softback(struct vc_data *vc)
378{
379 int l = fbcon_softback_size / vc->vc_size_row;
380
381 if (l > 5)
382 softback_end = softback_buf + l * vc->vc_size_row;
383 else
384 /* Smaller scrollback makes no sense, and 0 would screw
385 the operation totally */
386 softback_top = 0;
387}
388
David Howellsc4028952006-11-22 14:57:56 +0000389static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
David Howellsc4028952006-11-22 14:57:56 +0000391 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 struct fbcon_ops *ops = info->fbcon_par;
393 struct display *p;
394 struct vc_data *vc = NULL;
395 int c;
396 int mode;
397
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700398 acquire_console_sem();
399 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 vc = vc_cons[ops->currcon].d;
401
402 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700403 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700404 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700405 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700407 }
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 p = &fb_display[vc->vc_num];
410 c = scr_readw((u16 *) vc->vc_pos);
411 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
412 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800413 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 get_color(vc, info, c, 0));
415 release_console_sem();
416}
417
Russell King41359dc2005-06-30 16:30:07 +0100418#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100420static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
422 struct fb_info *info = dev_id;
423
424 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
425 schedule_work(&info->queue);
426 vbl_cursor_cnt = cursor_blink_rate;
427 }
428 return IRQ_HANDLED;
429}
430#endif
431
432static void cursor_timer_handler(unsigned long dev_addr)
433{
434 struct fb_info *info = (struct fb_info *) dev_addr;
435 struct fbcon_ops *ops = info->fbcon_par;
436
437 schedule_work(&info->queue);
438 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
439}
440
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700441static void fbcon_add_cursor_timer(struct fb_info *info)
442{
443 struct fbcon_ops *ops = info->fbcon_par;
444
445 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700446 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
447 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700448 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000449 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700450
451 init_timer(&ops->cursor_timer);
452 ops->cursor_timer.function = cursor_timer_handler;
453 ops->cursor_timer.expires = jiffies + HZ / 5;
454 ops->cursor_timer.data = (unsigned long ) info;
455 add_timer(&ops->cursor_timer);
456 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
457 }
458}
459
460static void fbcon_del_cursor_timer(struct fb_info *info)
461{
462 struct fbcon_ops *ops = info->fbcon_par;
463
464 if (info->queue.func == fb_flashcursor &&
465 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
466 del_timer_sync(&ops->cursor_timer);
467 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
468 }
469}
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#ifndef MODULE
472static int __init fb_console_setup(char *this_opt)
473{
474 char *options;
475 int i, j;
476
477 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800478 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 while ((options = strsep(&this_opt, ",")) != NULL) {
481 if (!strncmp(options, "font:", 5))
482 strcpy(fontname, options + 5);
483
484 if (!strncmp(options, "scrollback:", 11)) {
485 options += 11;
486 if (*options) {
487 fbcon_softback_size = simple_strtoul(options, &options, 0);
488 if (*options == 'k' || *options == 'K') {
489 fbcon_softback_size *= 1024;
490 options++;
491 }
492 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800493 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 options++;
495 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800496 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498
499 if (!strncmp(options, "map:", 4)) {
500 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700501 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
503 if (!options[j])
504 j = 0;
505 con2fb_map_boot[i] =
506 (options[j++]-'0') % FB_MAX;
507 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700508
509 map_override = 1;
510 }
511
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800512 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514
515 if (!strncmp(options, "vc:", 3)) {
516 options += 3;
517 if (*options)
518 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
519 if (first_fb_vc < 0)
520 first_fb_vc = 0;
521 if (*options++ == '-')
522 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
523 fbcon_is_default = 0;
524 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800525
526 if (!strncmp(options, "rotate:", 7)) {
527 options += 7;
528 if (*options)
529 rotate = simple_strtoul(options, &options, 0);
530 if (rotate > 3)
531 rotate = 0;
532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800534 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
537__setup("fbcon=", fb_console_setup);
538#endif
539
540static int search_fb_in_map(int idx)
541{
542 int i, retval = 0;
543
Antonino A. Daplase614b182006-06-26 00:27:09 -0700544 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 if (con2fb_map[i] == idx)
546 retval = 1;
547 }
548 return retval;
549}
550
551static int search_for_mapped_con(void)
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] != -1)
557 retval = 1;
558 }
559 return retval;
560}
561
562static int fbcon_takeover(int show_logo)
563{
564 int err, i;
565
566 if (!num_registered_fb)
567 return -ENODEV;
568
569 if (!show_logo)
570 logo_shown = FBCON_LOGO_DONTSHOW;
571
572 for (i = first_fb_vc; i <= last_fb_vc; i++)
573 con2fb_map[i] = info_idx;
574
575 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
576 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 if (err) {
579 for (i = first_fb_vc; i <= last_fb_vc; i++) {
580 con2fb_map[i] = -1;
581 }
582 info_idx = -1;
583 }
584
585 return err;
586}
587
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700588#ifdef MODULE
589static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
590 int cols, int rows, int new_cols, int new_rows)
591{
592 logo_shown = FBCON_LOGO_DONTSHOW;
593}
594#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
596 int cols, int rows, int new_cols, int new_rows)
597{
598 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800599 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 int cnt, erase = vc->vc_video_erase_char, step;
601 unsigned short *save = NULL, *r, *q;
602
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700603 if (info->flags & FBINFO_MODULE) {
604 logo_shown = FBCON_LOGO_DONTSHOW;
605 return;
606 }
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /*
609 * remove underline attribute from erase character
610 * if black and white framebuffer.
611 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700612 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800614 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 logo_lines = (logo_height + vc->vc_font.height - 1) /
616 vc->vc_font.height;
617 q = (unsigned short *) (vc->vc_origin +
618 vc->vc_size_row * rows);
619 step = logo_lines * cols;
620 for (r = q - logo_lines * cols; r < q; r++)
621 if (scr_readw(r) != vc->vc_video_erase_char)
622 break;
623 if (r != q && new_rows >= rows + logo_lines) {
624 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
625 if (save) {
626 int i = cols < new_cols ? cols : new_cols;
627 scr_memsetw(save, erase, logo_lines * new_cols * 2);
628 r = q - step;
629 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
630 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
631 r = q;
632 }
633 }
634 if (r == q) {
635 /* We can scroll screen down */
636 r = q - step - cols;
637 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
638 scr_memcpyw(r + step, r, vc->vc_size_row);
639 r -= cols;
640 }
641 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700642 int lines;
643 if (vc->vc_y + logo_lines >= rows)
644 lines = rows - vc->vc_y - 1;
645 else
646 lines = logo_lines;
647 vc->vc_y += lines;
648 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 }
651 scr_memsetw((unsigned short *) vc->vc_origin,
652 erase,
653 vc->vc_size_row * logo_lines);
654
655 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
656 fbcon_clear_margins(vc, 0);
657 update_screen(vc);
658 }
659
660 if (save) {
661 q = (unsigned short *) (vc->vc_origin +
662 vc->vc_size_row *
663 rows);
664 scr_memcpyw(q, save, logo_lines * new_cols * 2);
665 vc->vc_y += logo_lines;
666 vc->vc_pos += logo_lines * vc->vc_size_row;
667 kfree(save);
668 }
669
670 if (logo_lines > vc->vc_bottom) {
671 logo_shown = FBCON_LOGO_CANSHOW;
672 printk(KERN_INFO
673 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
674 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
675 logo_shown = FBCON_LOGO_DRAW;
676 vc->vc_top = logo_lines;
677 }
678}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700679#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800682static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683{
684 struct fbcon_ops *ops = info->fbcon_par;
685
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800686 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800689 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800690 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800691 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700695
696static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
697{
698 int err = 0;
699
700 if (info->flags & FBINFO_MISC_TILEBLITTING &&
701 info->tileops->fb_get_tilemax(info) < charcount)
702 err = 1;
703
704 return err;
705}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800707static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
709 struct fbcon_ops *ops = info->fbcon_par;
710
711 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800712 ops->p = &fb_display[vc->vc_num];
713 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 fbcon_set_bitops(ops);
715}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700716
717static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
718{
719 return 0;
720}
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif /* CONFIG_MISC_TILEBLITTING */
723
724
725static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
726 int unit, int oldidx)
727{
728 struct fbcon_ops *ops = NULL;
729 int err = 0;
730
731 if (!try_module_get(info->fbops->owner))
732 err = -ENODEV;
733
734 if (!err && info->fbops->fb_open &&
735 info->fbops->fb_open(info, 0))
736 err = -ENODEV;
737
738 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800739 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 if (!ops)
741 err = -ENOMEM;
742 }
743
744 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700746
747 if (vc)
748 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
750
751 if (err) {
752 con2fb_map[unit] = oldidx;
753 module_put(info->fbops->owner);
754 }
755
756 return err;
757}
758
759static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
760 struct fb_info *newinfo, int unit,
761 int oldidx, int found)
762{
763 struct fbcon_ops *ops = oldinfo->fbcon_par;
764 int err = 0;
765
766 if (oldinfo->fbops->fb_release &&
767 oldinfo->fbops->fb_release(oldinfo, 0)) {
768 con2fb_map[unit] = oldidx;
769 if (!found && newinfo->fbops->fb_release)
770 newinfo->fbops->fb_release(newinfo, 0);
771 if (!found)
772 module_put(newinfo->fbops->owner);
773 err = -ENODEV;
774 }
775
776 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700777 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 kfree(ops->cursor_state.mask);
779 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800780 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 kfree(oldinfo->fbcon_par);
782 oldinfo->fbcon_par = NULL;
783 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800784 /*
785 If oldinfo and newinfo are driving the same hardware,
786 the fb_release() method of oldinfo may attempt to
787 restore the hardware state. This will leave the
788 newinfo in an undefined state. Thus, a call to
789 fb_set_par() may be needed for the newinfo.
790 */
791 if (newinfo->fbops->fb_set_par)
792 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 }
794
795 return err;
796}
797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
799 int unit, int show_logo)
800{
801 struct fbcon_ops *ops = info->fbcon_par;
802
803 ops->currcon = fg_console;
804
805 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
806 info->fbops->fb_set_par(info);
807
808 ops->flags |= FBCON_FLAGS_INIT;
809 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700810 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (show_logo) {
813 struct vc_data *fg_vc = vc_cons[fg_console].d;
814 struct fb_info *fg_info =
815 registered_fb[con2fb_map[fg_console]];
816
817 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
818 fg_vc->vc_rows, fg_vc->vc_cols,
819 fg_vc->vc_rows);
820 }
821
822 update_screen(vc_cons[fg_console].d);
823}
824
825/**
826 * set_con2fb_map - map console to frame buffer device
827 * @unit: virtual console number to map
828 * @newidx: frame buffer index to map virtual console to
829 * @user: user request
830 *
831 * Maps a virtual console @unit to a frame buffer device
832 * @newidx.
833 */
834static int set_con2fb_map(int unit, int newidx, int user)
835{
836 struct vc_data *vc = vc_cons[unit].d;
837 int oldidx = con2fb_map[unit];
838 struct fb_info *info = registered_fb[newidx];
839 struct fb_info *oldinfo = NULL;
840 int found, err = 0;
841
842 if (oldidx == newidx)
843 return 0;
844
Antonino A. Daplase614b182006-06-26 00:27:09 -0700845 if (!info || fbcon_has_exited)
846 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 if (!err && !search_for_mapped_con()) {
849 info_idx = newidx;
850 return fbcon_takeover(0);
851 }
852
853 if (oldidx != -1)
854 oldinfo = registered_fb[oldidx];
855
856 found = search_fb_in_map(newidx);
857
858 acquire_console_sem();
859 con2fb_map[unit] = newidx;
860 if (!err && !found)
861 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
862
863
864 /*
865 * If old fb is not mapped to any of the consoles,
866 * fbcon should release it.
867 */
868 if (!err && oldinfo && !search_fb_in_map(oldidx))
869 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
870 found);
871
872 if (!err) {
873 int show_logo = (fg_console == 0 && !user &&
874 logo_shown != FBCON_LOGO_DONTSHOW);
875
876 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700877 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 con2fb_map_boot[unit] = newidx;
879 con2fb_init_display(vc, info, unit, show_logo);
880 }
881
Antonino A. Daplase614b182006-06-26 00:27:09 -0700882 if (!search_fb_in_map(info_idx))
883 info_idx = newidx;
884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 release_console_sem();
886 return err;
887}
888
889/*
890 * Low Level Operations
891 */
892/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
893static int var_to_display(struct display *disp,
894 struct fb_var_screeninfo *var,
895 struct fb_info *info)
896{
897 disp->xres_virtual = var->xres_virtual;
898 disp->yres_virtual = var->yres_virtual;
899 disp->bits_per_pixel = var->bits_per_pixel;
900 disp->grayscale = var->grayscale;
901 disp->nonstd = var->nonstd;
902 disp->accel_flags = var->accel_flags;
903 disp->height = var->height;
904 disp->width = var->width;
905 disp->red = var->red;
906 disp->green = var->green;
907 disp->blue = var->blue;
908 disp->transp = var->transp;
909 disp->rotate = var->rotate;
910 disp->mode = fb_match_mode(var, &info->modelist);
911 if (disp->mode == NULL)
912 /* This should not happen */
913 return -EINVAL;
914 return 0;
915}
916
917static void display_to_var(struct fb_var_screeninfo *var,
918 struct display *disp)
919{
920 fb_videomode_to_var(var, disp->mode);
921 var->xres_virtual = disp->xres_virtual;
922 var->yres_virtual = disp->yres_virtual;
923 var->bits_per_pixel = disp->bits_per_pixel;
924 var->grayscale = disp->grayscale;
925 var->nonstd = disp->nonstd;
926 var->accel_flags = disp->accel_flags;
927 var->height = disp->height;
928 var->width = disp->width;
929 var->red = disp->red;
930 var->green = disp->green;
931 var->blue = disp->blue;
932 var->transp = disp->transp;
933 var->rotate = disp->rotate;
934}
935
936static const char *fbcon_startup(void)
937{
938 const char *display_desc = "frame buffer device";
939 struct display *p = &fb_display[fg_console];
940 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700941 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 struct module *owner;
943 struct fb_info *info = NULL;
944 struct fbcon_ops *ops;
945 int rows, cols;
946 int irqres;
947
948 irqres = 1;
949 /*
950 * If num_registered_fb is zero, this is a call for the dummy part.
951 * The frame buffer devices weren't initialized yet.
952 */
953 if (!num_registered_fb || info_idx == -1)
954 return display_desc;
955 /*
956 * Instead of blindly using registered_fb[0], we use info_idx, set by
957 * fb_console_init();
958 */
959 info = registered_fb[info_idx];
960 if (!info)
961 return NULL;
962
963 owner = info->fbops->owner;
964 if (!try_module_get(owner))
965 return NULL;
966 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
967 module_put(owner);
968 return NULL;
969 }
970
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800971 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (!ops) {
973 module_put(owner);
974 return NULL;
975 }
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 ops->currcon = -1;
978 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800979 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800981 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800982 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984 if (info->fix.type != FB_TYPE_TEXT) {
985 if (fbcon_softback_size) {
986 if (!softback_buf) {
987 softback_buf =
988 (unsigned long)
989 kmalloc(fbcon_softback_size,
990 GFP_KERNEL);
991 if (!softback_buf) {
992 fbcon_softback_size = 0;
993 softback_top = 0;
994 }
995 }
996 } else {
997 if (softback_buf) {
998 kfree((void *) softback_buf);
999 softback_buf = 0;
1000 softback_top = 0;
1001 }
1002 }
1003 if (softback_buf)
1004 softback_in = softback_top = softback_curr =
1005 softback_buf;
1006 softback_lines = 0;
1007 }
1008
1009 /* Setup default font */
1010 if (!p->fontdata) {
1011 if (!fontname[0] || !(font = find_font(fontname)))
1012 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001013 info->var.yres,
1014 info->pixmap.blit_x,
1015 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 vc->vc_font.width = font->width;
1017 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001018 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1020 }
1021
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001022 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1023 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1024 cols /= vc->vc_font.width;
1025 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 vc_resize(vc, cols, rows);
1027
1028 DPRINTK("mode: %s\n", info->fix.id);
1029 DPRINTK("visual: %d\n", info->fix.visual);
1030 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1031 info->var.yres,
1032 info->var.bits_per_pixel);
1033
1034#ifdef CONFIG_ATARI
1035 if (MACH_IS_ATARI) {
1036 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1037 irqres =
1038 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1039 IRQ_TYPE_PRIO, "framebuffer vbl",
1040 info);
1041 }
1042#endif /* CONFIG_ATARI */
1043
1044#ifdef CONFIG_MAC
1045 /*
1046 * On a Macintoy, the VBL interrupt may or may not be active.
1047 * As interrupt based cursor is more reliable and race free, we
1048 * probe for VBL interrupts.
1049 */
1050 if (MACH_IS_MAC) {
1051 int ct = 0;
1052 /*
1053 * Probe for VBL: set temp. handler ...
1054 */
1055 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1056 "framebuffer vbl", info);
1057 vbl_detected = 0;
1058
1059 /*
1060 * ... and spin for 20 ms ...
1061 */
1062 while (!vbl_detected && ++ct < 1000)
1063 udelay(20);
1064
1065 if (ct == 1000)
1066 printk
1067 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1068
1069 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1070
1071 if (vbl_detected) {
1072 /*
1073 * interrupt based cursor ok
1074 */
1075 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1076 irqres =
1077 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1078 "framebuffer vbl", info);
1079 } else {
1080 /*
1081 * VBL not detected: fall through, use timer based cursor
1082 */
1083 irqres = 1;
1084 }
1085 }
1086#endif /* CONFIG_MAC */
1087
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001088 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001089 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 return display_desc;
1091}
1092
1093static void fbcon_init(struct vc_data *vc, int init)
1094{
1095 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1096 struct fbcon_ops *ops;
1097 struct vc_data **default_mode = vc->vc_display_fg;
1098 struct vc_data *svc = *default_mode;
1099 struct display *t, *p = &fb_display[vc->vc_num];
1100 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001101 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 if (info_idx == -1 || info == NULL)
1104 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001105
1106 cap = info->flags;
1107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1109 (info->fix.type == FB_TYPE_TEXT))
1110 logo = 0;
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (var_to_display(p, &info->var, info))
1113 return;
1114
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001115 if (!info->fbcon_par)
1116 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 /* If we are not the first console on this
1119 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001120 t = &fb_display[fg_console];
1121 if (!p->fontdata) {
1122 if (t->fontdata) {
1123 struct vc_data *fvc = vc_cons[fg_console].d;
1124
1125 vc->vc_font.data = (void *)(p->fontdata =
1126 fvc->vc_font.data);
1127 vc->vc_font.width = fvc->vc_font.width;
1128 vc->vc_font.height = fvc->vc_font.height;
1129 p->userfont = t->userfont;
1130
1131 if (p->userfont)
1132 REFCOUNT(p->fontdata)++;
1133 } else {
1134 const struct font_desc *font = NULL;
1135
1136 if (!fontname[0] || !(font = find_font(fontname)))
1137 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001138 info->var.yres,
1139 info->pixmap.blit_x,
1140 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001141 vc->vc_font.width = font->width;
1142 vc->vc_font.height = font->height;
1143 vc->vc_font.data = (void *)(p->fontdata = font->data);
1144 vc->vc_font.charcount = 256; /* FIXME Need to
1145 support more fonts */
1146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (p->userfont)
1150 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001151
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001152 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1154 if (charcnt == 256) {
1155 vc->vc_hi_font_mask = 0;
1156 } else {
1157 vc->vc_hi_font_mask = 0x100;
1158 if (vc->vc_can_do_color)
1159 vc->vc_complement_mask <<= 1;
1160 }
1161
1162 if (!*svc->vc_uni_pagedir_loc)
1163 con_set_default_unimap(svc);
1164 if (!*vc->vc_uni_pagedir_loc)
1165 con_copy_unimap(vc, svc);
1166
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001167 ops = info->fbcon_par;
1168 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001169 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 cols = vc->vc_cols;
1172 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001173 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1174 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1175 new_cols /= vc->vc_font.width;
1176 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 vc_resize(vc, new_cols, new_rows);
1178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 /*
1180 * We must always set the mode. The mode of the previous console
1181 * driver could be in the same resolution but we are using different
1182 * hardware so we have to initialize the hardware.
1183 *
1184 * We need to do it in fbcon_init() to prevent screen corruption.
1185 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001186 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if (info->fbops->fb_set_par &&
1188 !(ops->flags & FBCON_FLAGS_INIT))
1189 info->fbops->fb_set_par(info);
1190 ops->flags |= FBCON_FLAGS_INIT;
1191 }
1192
1193 ops->graphics = 0;
1194
1195 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1196 !(cap & FBINFO_HWACCEL_DISABLED))
1197 p->scrollmode = SCROLL_MOVE;
1198 else /* default to something safe */
1199 p->scrollmode = SCROLL_REDRAW;
1200
1201 /*
1202 * ++guenther: console.c:vc_allocate() relies on initializing
1203 * vc_{cols,rows}, but we must not set those if we are only
1204 * resizing the console.
1205 */
1206 if (!init) {
1207 vc->vc_cols = new_cols;
1208 vc->vc_rows = new_rows;
1209 }
1210
1211 if (logo)
1212 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1213
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001214 if (vc == svc && softback_buf)
1215 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001216
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001217 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001218 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001219 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001220 }
1221
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001222 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Antonino A. Daplase614b182006-06-26 00:27:09 -07001225static void fbcon_free_font(struct display *p)
1226{
1227 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1228 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1229 p->fontdata = NULL;
1230 p->userfont = 0;
1231}
1232
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233static void fbcon_deinit(struct vc_data *vc)
1234{
1235 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001236 struct fb_info *info;
1237 struct fbcon_ops *ops;
1238 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001241 idx = con2fb_map[vc->vc_num];
1242
1243 if (idx == -1)
1244 goto finished;
1245
1246 info = registered_fb[idx];
1247
1248 if (!info)
1249 goto finished;
1250
1251 ops = info->fbcon_par;
1252
1253 if (!ops)
1254 goto finished;
1255
1256 if (CON_IS_VISIBLE(vc))
1257 fbcon_del_cursor_timer(info);
1258
1259 ops->flags &= ~FBCON_FLAGS_INIT;
1260finished:
1261
1262 if (!con_is_bound(&fb_con))
1263 fbcon_exit();
1264
1265 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
1268/* ====================================================================== */
1269
1270/* fbcon_XXX routines - interface used by the world
1271 *
1272 * This system is now divided into two levels because of complications
1273 * caused by hardware scrolling. Top level functions:
1274 *
1275 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1276 *
1277 * handles y values in range [0, scr_height-1] that correspond to real
1278 * screen positions. y_wrap shift means that first line of bitmap may be
1279 * anywhere on this display. These functions convert lineoffsets to
1280 * bitmap offsets and deal with the wrap-around case by splitting blits.
1281 *
1282 * fbcon_bmove_physical_8() -- These functions fast implementations
1283 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1284 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1285 *
1286 * WARNING:
1287 *
1288 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1289 * Implies should only really hardware scroll in rows. Only reason for
1290 * restriction is simplicity & efficiency at the moment.
1291 */
1292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1294 int width)
1295{
1296 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1297 struct fbcon_ops *ops = info->fbcon_par;
1298
1299 struct display *p = &fb_display[vc->vc_num];
1300 u_int y_break;
1301
1302 if (fbcon_is_inactive(vc, info))
1303 return;
1304
1305 if (!height || !width)
1306 return;
1307
1308 /* Split blits that cross physical y_wrap boundary */
1309
1310 y_break = p->vrows - p->yscroll;
1311 if (sy < y_break && sy + height - 1 >= y_break) {
1312 u_int b = y_break - sy;
1313 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1314 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1315 width);
1316 } else
1317 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1318}
1319
1320static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1321 int count, int ypos, int xpos)
1322{
1323 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1324 struct display *p = &fb_display[vc->vc_num];
1325 struct fbcon_ops *ops = info->fbcon_par;
1326
1327 if (!fbcon_is_inactive(vc, info))
1328 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1329 get_color(vc, info, scr_readw(s), 1),
1330 get_color(vc, info, scr_readw(s), 0));
1331}
1332
1333static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1334{
1335 unsigned short chr;
1336
1337 scr_writew(c, &chr);
1338 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1339}
1340
1341static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1342{
1343 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1344 struct fbcon_ops *ops = info->fbcon_par;
1345
1346 if (!fbcon_is_inactive(vc, info))
1347 ops->clear_margins(vc, info, bottom_only);
1348}
1349
1350static void fbcon_cursor(struct vc_data *vc, int mode)
1351{
1352 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1353 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 int y;
1355 int c = scr_readw((u16 *) vc->vc_pos);
1356
Michal Januszewskid1e23062007-05-08 00:38:07 -07001357 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 return;
1359
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001360 if (vc->vc_cursor_type & 0x10)
1361 fbcon_del_cursor_timer(info);
1362 else
1363 fbcon_add_cursor_timer(info);
1364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1366 if (mode & CM_SOFTBACK) {
1367 mode &= ~CM_SOFTBACK;
1368 y = softback_lines;
1369 } else {
1370 if (softback_lines)
1371 fbcon_set_origin(vc);
1372 y = 0;
1373 }
1374
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001375 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 get_color(vc, info, c, 0));
1377 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1378}
1379
1380static int scrollback_phys_max = 0;
1381static int scrollback_max = 0;
1382static int scrollback_current = 0;
1383
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001385 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001387 struct display *p, *t;
1388 struct vc_data **default_mode, *vc;
1389 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001390 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 int rows, cols, charcnt = 256;
1392
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001393 p = &fb_display[unit];
1394
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 if (var_to_display(p, var, info))
1396 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001397
1398 vc = vc_cons[unit].d;
1399
1400 if (!vc)
1401 return;
1402
1403 default_mode = vc->vc_display_fg;
1404 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001406
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001408 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 vc->vc_font.width = (*default_mode)->vc_font.width;
1410 vc->vc_font.height = (*default_mode)->vc_font.height;
1411 p->userfont = t->userfont;
1412 if (p->userfont)
1413 REFCOUNT(p->fontdata)++;
1414 }
1415 if (p->userfont)
1416 charcnt = FNTCHARCNT(p->fontdata);
1417
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001418 var->activate = FB_ACTIVATE_NOW;
1419 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001420 var->yoffset = info->var.yoffset;
1421 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001422 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001423 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001424 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1426 if (charcnt == 256) {
1427 vc->vc_hi_font_mask = 0;
1428 } else {
1429 vc->vc_hi_font_mask = 0x100;
1430 if (vc->vc_can_do_color)
1431 vc->vc_complement_mask <<= 1;
1432 }
1433
1434 if (!*svc->vc_uni_pagedir_loc)
1435 con_set_default_unimap(svc);
1436 if (!*vc->vc_uni_pagedir_loc)
1437 con_copy_unimap(vc, svc);
1438
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001439 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1440 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1441 cols /= vc->vc_font.width;
1442 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001444
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 if (CON_IS_VISIBLE(vc)) {
1446 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001447 if (softback_buf)
1448 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 }
1450}
1451
1452static __inline__ void ywrap_up(struct vc_data *vc, int count)
1453{
1454 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001455 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 struct display *p = &fb_display[vc->vc_num];
1457
1458 p->yscroll += count;
1459 if (p->yscroll >= p->vrows) /* Deal with wrap */
1460 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001461 ops->var.xoffset = 0;
1462 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1463 ops->var.vmode |= FB_VMODE_YWRAP;
1464 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 scrollback_max += count;
1466 if (scrollback_max > scrollback_phys_max)
1467 scrollback_max = scrollback_phys_max;
1468 scrollback_current = 0;
1469}
1470
1471static __inline__ void ywrap_down(struct vc_data *vc, int count)
1472{
1473 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001474 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 struct display *p = &fb_display[vc->vc_num];
1476
1477 p->yscroll -= count;
1478 if (p->yscroll < 0) /* Deal with wrap */
1479 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001480 ops->var.xoffset = 0;
1481 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1482 ops->var.vmode |= FB_VMODE_YWRAP;
1483 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 scrollback_max -= count;
1485 if (scrollback_max < 0)
1486 scrollback_max = 0;
1487 scrollback_current = 0;
1488}
1489
1490static __inline__ void ypan_up(struct vc_data *vc, int count)
1491{
1492 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1493 struct display *p = &fb_display[vc->vc_num];
1494 struct fbcon_ops *ops = info->fbcon_par;
1495
1496 p->yscroll += count;
1497 if (p->yscroll > p->vrows - vc->vc_rows) {
1498 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1499 0, 0, 0, vc->vc_rows, vc->vc_cols);
1500 p->yscroll -= p->vrows - vc->vc_rows;
1501 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001502
1503 ops->var.xoffset = 0;
1504 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1505 ops->var.vmode &= ~FB_VMODE_YWRAP;
1506 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 fbcon_clear_margins(vc, 1);
1508 scrollback_max += count;
1509 if (scrollback_max > scrollback_phys_max)
1510 scrollback_max = scrollback_phys_max;
1511 scrollback_current = 0;
1512}
1513
1514static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1515{
1516 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001517 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 if (p->yscroll > p->vrows - vc->vc_rows) {
1523 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001525 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001526
1527 ops->var.xoffset = 0;
1528 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1529 ops->var.vmode &= ~FB_VMODE_YWRAP;
1530 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 fbcon_clear_margins(vc, 1);
1532 scrollback_max += count;
1533 if (scrollback_max > scrollback_phys_max)
1534 scrollback_max = scrollback_phys_max;
1535 scrollback_current = 0;
1536}
1537
1538static __inline__ void ypan_down(struct vc_data *vc, int count)
1539{
1540 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1541 struct display *p = &fb_display[vc->vc_num];
1542 struct fbcon_ops *ops = info->fbcon_par;
1543
1544 p->yscroll -= count;
1545 if (p->yscroll < 0) {
1546 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1547 0, vc->vc_rows, vc->vc_cols);
1548 p->yscroll += p->vrows - vc->vc_rows;
1549 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001550
1551 ops->var.xoffset = 0;
1552 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1553 ops->var.vmode &= ~FB_VMODE_YWRAP;
1554 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 fbcon_clear_margins(vc, 1);
1556 scrollback_max -= count;
1557 if (scrollback_max < 0)
1558 scrollback_max = 0;
1559 scrollback_current = 0;
1560}
1561
1562static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1563{
1564 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001565 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (p->yscroll < 0) {
1571 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001573 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001574
1575 ops->var.xoffset = 0;
1576 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1577 ops->var.vmode &= ~FB_VMODE_YWRAP;
1578 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 fbcon_clear_margins(vc, 1);
1580 scrollback_max -= count;
1581 if (scrollback_max < 0)
1582 scrollback_max = 0;
1583 scrollback_current = 0;
1584}
1585
1586static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1587 long delta)
1588{
1589 int count = vc->vc_rows;
1590 unsigned short *d, *s;
1591 unsigned long n;
1592 int line = 0;
1593
1594 d = (u16 *) softback_curr;
1595 if (d == (u16 *) softback_in)
1596 d = (u16 *) vc->vc_origin;
1597 n = softback_curr + delta * vc->vc_size_row;
1598 softback_lines -= delta;
1599 if (delta < 0) {
1600 if (softback_curr < softback_top && n < softback_buf) {
1601 n += softback_end - softback_buf;
1602 if (n < softback_top) {
1603 softback_lines -=
1604 (softback_top - n) / vc->vc_size_row;
1605 n = softback_top;
1606 }
1607 } else if (softback_curr >= softback_top
1608 && n < softback_top) {
1609 softback_lines -=
1610 (softback_top - n) / vc->vc_size_row;
1611 n = softback_top;
1612 }
1613 } else {
1614 if (softback_curr > softback_in && n >= softback_end) {
1615 n += softback_buf - softback_end;
1616 if (n > softback_in) {
1617 n = softback_in;
1618 softback_lines = 0;
1619 }
1620 } else if (softback_curr <= softback_in && n > softback_in) {
1621 n = softback_in;
1622 softback_lines = 0;
1623 }
1624 }
1625 if (n == softback_curr)
1626 return;
1627 softback_curr = n;
1628 s = (u16 *) softback_curr;
1629 if (s == (u16 *) softback_in)
1630 s = (u16 *) vc->vc_origin;
1631 while (count--) {
1632 unsigned short *start;
1633 unsigned short *le;
1634 unsigned short c;
1635 int x = 0;
1636 unsigned short attr = 1;
1637
1638 start = s;
1639 le = advance_row(s, 1);
1640 do {
1641 c = scr_readw(s);
1642 if (attr != (c & 0xff00)) {
1643 attr = c & 0xff00;
1644 if (s > start) {
1645 fbcon_putcs(vc, start, s - start,
1646 line, x);
1647 x += s - start;
1648 start = s;
1649 }
1650 }
1651 if (c == scr_readw(d)) {
1652 if (s > start) {
1653 fbcon_putcs(vc, start, s - start,
1654 line, x);
1655 x += s - start + 1;
1656 start = s + 1;
1657 } else {
1658 x++;
1659 start++;
1660 }
1661 }
1662 s++;
1663 d++;
1664 } while (s < le);
1665 if (s > start)
1666 fbcon_putcs(vc, start, s - start, line, x);
1667 line++;
1668 if (d == (u16 *) softback_end)
1669 d = (u16 *) softback_buf;
1670 if (d == (u16 *) softback_in)
1671 d = (u16 *) vc->vc_origin;
1672 if (s == (u16 *) softback_end)
1673 s = (u16 *) softback_buf;
1674 if (s == (u16 *) softback_in)
1675 s = (u16 *) vc->vc_origin;
1676 }
1677}
1678
1679static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1680 int line, int count, int dy)
1681{
1682 unsigned short *s = (unsigned short *)
1683 (vc->vc_origin + vc->vc_size_row * line);
1684
1685 while (count--) {
1686 unsigned short *start = s;
1687 unsigned short *le = advance_row(s, 1);
1688 unsigned short c;
1689 int x = 0;
1690 unsigned short attr = 1;
1691
1692 do {
1693 c = scr_readw(s);
1694 if (attr != (c & 0xff00)) {
1695 attr = c & 0xff00;
1696 if (s > start) {
1697 fbcon_putcs(vc, start, s - start,
1698 dy, x);
1699 x += s - start;
1700 start = s;
1701 }
1702 }
1703 console_conditional_schedule();
1704 s++;
1705 } while (s < le);
1706 if (s > start)
1707 fbcon_putcs(vc, start, s - start, dy, x);
1708 console_conditional_schedule();
1709 dy++;
1710 }
1711}
1712
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001713static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1714 struct display *p, int line, int count, int ycount)
1715{
1716 int offset = ycount * vc->vc_cols;
1717 unsigned short *d = (unsigned short *)
1718 (vc->vc_origin + vc->vc_size_row * line);
1719 unsigned short *s = d + offset;
1720 struct fbcon_ops *ops = info->fbcon_par;
1721
1722 while (count--) {
1723 unsigned short *start = s;
1724 unsigned short *le = advance_row(s, 1);
1725 unsigned short c;
1726 int x = 0;
1727
1728 do {
1729 c = scr_readw(s);
1730
1731 if (c == scr_readw(d)) {
1732 if (s > start) {
1733 ops->bmove(vc, info, line + ycount, x,
1734 line, x, 1, s-start);
1735 x += s - start + 1;
1736 start = s + 1;
1737 } else {
1738 x++;
1739 start++;
1740 }
1741 }
1742
1743 scr_writew(c, d);
1744 console_conditional_schedule();
1745 s++;
1746 d++;
1747 } while (s < le);
1748 if (s > start)
1749 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1750 s-start);
1751 console_conditional_schedule();
1752 if (ycount > 0)
1753 line++;
1754 else {
1755 line--;
1756 /* NOTE: We subtract two lines from these pointers */
1757 s -= vc->vc_size_row;
1758 d -= vc->vc_size_row;
1759 }
1760 }
1761}
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763static void fbcon_redraw(struct vc_data *vc, struct display *p,
1764 int line, int count, int offset)
1765{
1766 unsigned short *d = (unsigned short *)
1767 (vc->vc_origin + vc->vc_size_row * line);
1768 unsigned short *s = d + offset;
1769
1770 while (count--) {
1771 unsigned short *start = s;
1772 unsigned short *le = advance_row(s, 1);
1773 unsigned short c;
1774 int x = 0;
1775 unsigned short attr = 1;
1776
1777 do {
1778 c = scr_readw(s);
1779 if (attr != (c & 0xff00)) {
1780 attr = c & 0xff00;
1781 if (s > start) {
1782 fbcon_putcs(vc, start, s - start,
1783 line, x);
1784 x += s - start;
1785 start = s;
1786 }
1787 }
1788 if (c == scr_readw(d)) {
1789 if (s > start) {
1790 fbcon_putcs(vc, start, s - start,
1791 line, x);
1792 x += s - start + 1;
1793 start = s + 1;
1794 } else {
1795 x++;
1796 start++;
1797 }
1798 }
1799 scr_writew(c, d);
1800 console_conditional_schedule();
1801 s++;
1802 d++;
1803 } while (s < le);
1804 if (s > start)
1805 fbcon_putcs(vc, start, s - start, line, x);
1806 console_conditional_schedule();
1807 if (offset > 0)
1808 line++;
1809 else {
1810 line--;
1811 /* NOTE: We subtract two lines from these pointers */
1812 s -= vc->vc_size_row;
1813 d -= vc->vc_size_row;
1814 }
1815 }
1816}
1817
1818static inline void fbcon_softback_note(struct vc_data *vc, int t,
1819 int count)
1820{
1821 unsigned short *p;
1822
1823 if (vc->vc_num != fg_console)
1824 return;
1825 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1826
1827 while (count) {
1828 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1829 count--;
1830 p = advance_row(p, 1);
1831 softback_in += vc->vc_size_row;
1832 if (softback_in == softback_end)
1833 softback_in = softback_buf;
1834 if (softback_in == softback_top) {
1835 softback_top += vc->vc_size_row;
1836 if (softback_top == softback_end)
1837 softback_top = softback_buf;
1838 }
1839 }
1840 softback_curr = softback_in;
1841}
1842
1843static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1844 int count)
1845{
1846 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1847 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1849
1850 if (fbcon_is_inactive(vc, info))
1851 return -EINVAL;
1852
1853 fbcon_cursor(vc, CM_ERASE);
1854
1855 /*
1856 * ++Geert: Only use ywrap/ypan if the console is in text mode
1857 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1858 * whole screen (prevents flicker).
1859 */
1860
1861 switch (dir) {
1862 case SM_UP:
1863 if (count > vc->vc_rows) /* Maximum realistic size */
1864 count = vc->vc_rows;
1865 if (softback_top)
1866 fbcon_softback_note(vc, t, count);
1867 if (logo_shown >= 0)
1868 goto redraw_up;
1869 switch (p->scrollmode) {
1870 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001871 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1872 count);
1873 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1874 scr_memsetw((unsigned short *) (vc->vc_origin +
1875 vc->vc_size_row *
1876 (b - count)),
1877 vc->vc_video_erase_char,
1878 vc->vc_size_row * count);
1879 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 break;
1881
1882 case SCROLL_WRAP_MOVE:
1883 if (b - t - count > 3 * vc->vc_rows >> 2) {
1884 if (t > 0)
1885 fbcon_bmove(vc, 0, 0, count, 0, t,
1886 vc->vc_cols);
1887 ywrap_up(vc, count);
1888 if (vc->vc_rows - b > 0)
1889 fbcon_bmove(vc, b - count, 0, b, 0,
1890 vc->vc_rows - b,
1891 vc->vc_cols);
1892 } else if (info->flags & FBINFO_READS_FAST)
1893 fbcon_bmove(vc, t + count, 0, t, 0,
1894 b - t - count, vc->vc_cols);
1895 else
1896 goto redraw_up;
1897 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1898 break;
1899
1900 case SCROLL_PAN_REDRAW:
1901 if ((p->yscroll + count <=
1902 2 * (p->vrows - vc->vc_rows))
1903 && ((!scroll_partial && (b - t == vc->vc_rows))
1904 || (scroll_partial
1905 && (b - t - count >
1906 3 * vc->vc_rows >> 2)))) {
1907 if (t > 0)
1908 fbcon_redraw_move(vc, p, 0, t, count);
1909 ypan_up_redraw(vc, t, count);
1910 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001911 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 vc->vc_rows - b, b);
1913 } else
1914 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1915 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1916 break;
1917
1918 case SCROLL_PAN_MOVE:
1919 if ((p->yscroll + count <=
1920 2 * (p->vrows - vc->vc_rows))
1921 && ((!scroll_partial && (b - t == vc->vc_rows))
1922 || (scroll_partial
1923 && (b - t - count >
1924 3 * vc->vc_rows >> 2)))) {
1925 if (t > 0)
1926 fbcon_bmove(vc, 0, 0, count, 0, t,
1927 vc->vc_cols);
1928 ypan_up(vc, count);
1929 if (vc->vc_rows - b > 0)
1930 fbcon_bmove(vc, b - count, 0, b, 0,
1931 vc->vc_rows - b,
1932 vc->vc_cols);
1933 } else if (info->flags & FBINFO_READS_FAST)
1934 fbcon_bmove(vc, t + count, 0, t, 0,
1935 b - t - count, vc->vc_cols);
1936 else
1937 goto redraw_up;
1938 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1939 break;
1940
1941 case SCROLL_REDRAW:
1942 redraw_up:
1943 fbcon_redraw(vc, p, t, b - t - count,
1944 count * vc->vc_cols);
1945 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1946 scr_memsetw((unsigned short *) (vc->vc_origin +
1947 vc->vc_size_row *
1948 (b - count)),
1949 vc->vc_video_erase_char,
1950 vc->vc_size_row * count);
1951 return 1;
1952 }
1953 break;
1954
1955 case SM_DOWN:
1956 if (count > vc->vc_rows) /* Maximum realistic size */
1957 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001958 if (logo_shown >= 0)
1959 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 switch (p->scrollmode) {
1961 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001962 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1963 -count);
1964 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1965 scr_memsetw((unsigned short *) (vc->vc_origin +
1966 vc->vc_size_row *
1967 t),
1968 vc->vc_video_erase_char,
1969 vc->vc_size_row * count);
1970 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 break;
1972
1973 case SCROLL_WRAP_MOVE:
1974 if (b - t - count > 3 * vc->vc_rows >> 2) {
1975 if (vc->vc_rows - b > 0)
1976 fbcon_bmove(vc, b, 0, b - count, 0,
1977 vc->vc_rows - b,
1978 vc->vc_cols);
1979 ywrap_down(vc, count);
1980 if (t > 0)
1981 fbcon_bmove(vc, count, 0, 0, 0, t,
1982 vc->vc_cols);
1983 } else if (info->flags & FBINFO_READS_FAST)
1984 fbcon_bmove(vc, t, 0, t + count, 0,
1985 b - t - count, vc->vc_cols);
1986 else
1987 goto redraw_down;
1988 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1989 break;
1990
1991 case SCROLL_PAN_MOVE:
1992 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1993 && ((!scroll_partial && (b - t == vc->vc_rows))
1994 || (scroll_partial
1995 && (b - t - count >
1996 3 * vc->vc_rows >> 2)))) {
1997 if (vc->vc_rows - b > 0)
1998 fbcon_bmove(vc, b, 0, b - count, 0,
1999 vc->vc_rows - b,
2000 vc->vc_cols);
2001 ypan_down(vc, count);
2002 if (t > 0)
2003 fbcon_bmove(vc, count, 0, 0, 0, t,
2004 vc->vc_cols);
2005 } else if (info->flags & FBINFO_READS_FAST)
2006 fbcon_bmove(vc, t, 0, t + count, 0,
2007 b - t - count, vc->vc_cols);
2008 else
2009 goto redraw_down;
2010 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2011 break;
2012
2013 case SCROLL_PAN_REDRAW:
2014 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2015 && ((!scroll_partial && (b - t == vc->vc_rows))
2016 || (scroll_partial
2017 && (b - t - count >
2018 3 * vc->vc_rows >> 2)))) {
2019 if (vc->vc_rows - b > 0)
2020 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2021 b - count);
2022 ypan_down_redraw(vc, t, count);
2023 if (t > 0)
2024 fbcon_redraw_move(vc, p, count, t, 0);
2025 } else
2026 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2027 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2028 break;
2029
2030 case SCROLL_REDRAW:
2031 redraw_down:
2032 fbcon_redraw(vc, p, b - 1, b - t - count,
2033 -count * vc->vc_cols);
2034 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2035 scr_memsetw((unsigned short *) (vc->vc_origin +
2036 vc->vc_size_row *
2037 t),
2038 vc->vc_video_erase_char,
2039 vc->vc_size_row * count);
2040 return 1;
2041 }
2042 }
2043 return 0;
2044}
2045
2046
2047static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2048 int height, int width)
2049{
2050 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2051 struct display *p = &fb_display[vc->vc_num];
2052
2053 if (fbcon_is_inactive(vc, info))
2054 return;
2055
2056 if (!width || !height)
2057 return;
2058
2059 /* Split blits that cross physical y_wrap case.
2060 * Pathological case involves 4 blits, better to use recursive
2061 * code rather than unrolled case
2062 *
2063 * Recursive invocations don't need to erase the cursor over and
2064 * over again, so we use fbcon_bmove_rec()
2065 */
2066 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2067 p->vrows - p->yscroll);
2068}
2069
2070static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2071 int dy, int dx, int height, int width, u_int y_break)
2072{
2073 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2074 struct fbcon_ops *ops = info->fbcon_par;
2075 u_int b;
2076
2077 if (sy < y_break && sy + height > y_break) {
2078 b = y_break - sy;
2079 if (dy < sy) { /* Avoid trashing self */
2080 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2081 y_break);
2082 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2083 height - b, width, y_break);
2084 } else {
2085 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2086 height - b, width, y_break);
2087 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2088 y_break);
2089 }
2090 return;
2091 }
2092
2093 if (dy < y_break && dy + height > y_break) {
2094 b = y_break - dy;
2095 if (dy < sy) { /* Avoid trashing self */
2096 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2097 y_break);
2098 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2099 height - b, width, y_break);
2100 } else {
2101 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2102 height - b, width, y_break);
2103 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2104 y_break);
2105 }
2106 return;
2107 }
2108 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2109 height, width);
2110}
2111
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002112static __inline__ void updatescrollmode(struct display *p,
2113 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct vc_data *vc)
2115{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002116 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 int fh = vc->vc_font.height;
2118 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002119 u16 t = 0;
2120 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2121 info->fix.xpanstep);
2122 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2123 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2124 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2125 info->var.xres_virtual);
2126 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2127 divides(ypan, vc->vc_font.height) && vyres > yres;
2128 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2129 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002130 divides(vc->vc_font.height, vyres) &&
2131 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002133 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2134 !(cap & FBINFO_HWACCEL_DISABLED);
2135 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2136 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002138 p->vrows = vyres/fh;
2139 if (yres > (fh * (vc->vc_rows + 1)))
2140 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2141 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 p->vrows--;
2143
2144 if (good_wrap || good_pan) {
2145 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002146 p->scrollmode = good_wrap ?
2147 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 else
2149 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2150 SCROLL_PAN_REDRAW;
2151 } else {
2152 if (reading_fast || (fast_copyarea && !fast_imageblit))
2153 p->scrollmode = SCROLL_MOVE;
2154 else
2155 p->scrollmode = SCROLL_REDRAW;
2156 }
2157}
2158
2159static int fbcon_resize(struct vc_data *vc, unsigned int width,
2160 unsigned int height)
2161{
2162 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002163 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 struct display *p = &fb_display[vc->vc_num];
2165 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002166 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002168 virt_w = FBCON_SWAP(ops->rotate, width, height);
2169 virt_h = FBCON_SWAP(ops->rotate, height, width);
2170 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2171 vc->vc_font.height);
2172 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2173 vc->vc_font.width);
2174 var.xres = virt_w * virt_fw;
2175 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 x_diff = info->var.xres - var.xres;
2177 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002178 if (x_diff < 0 || x_diff > virt_fw ||
2179 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002180 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
2182 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2183 mode = fb_find_best_mode(&var, &info->modelist);
2184 if (mode == NULL)
2185 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002186 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002188
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002189 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
2192 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2193 if (CON_IS_VISIBLE(vc)) {
2194 var.activate = FB_ACTIVATE_NOW |
2195 FB_ACTIVATE_FORCE;
2196 fb_set_var(info, &var);
2197 }
2198 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002199 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 }
2201 updatescrollmode(p, info, vc);
2202 return 0;
2203}
2204
2205static int fbcon_switch(struct vc_data *vc)
2206{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002207 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002208 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct display *p = &fb_display[vc->vc_num];
2210 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002211 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
2213 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002214 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 if (softback_lines)
2218 fbcon_set_origin(vc);
2219 softback_top = softback_curr = softback_in = softback_buf;
2220 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002221 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 }
2223
2224 if (logo_shown >= 0) {
2225 struct vc_data *conp2 = vc_cons[logo_shown].d;
2226
2227 if (conp2->vc_top == logo_lines
2228 && conp2->vc_bottom == conp2->vc_rows)
2229 conp2->vc_top = 0;
2230 logo_shown = FBCON_LOGO_CANSHOW;
2231 }
2232
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002233 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002234 if (prev_console != -1)
2235 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 /*
2237 * FIXME: If we have multiple fbdev's loaded, we need to
2238 * update all info->currcon. Perhaps, we can place this
2239 * in a centralized structure, but this might break some
2240 * drivers.
2241 *
2242 * info->currcon = vc->vc_num;
2243 */
2244 for (i = 0; i < FB_MAX; i++) {
2245 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002246 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002248 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 }
2250 }
2251 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2252 display_to_var(&var, p);
2253 var.activate = FB_ACTIVATE_NOW;
2254
2255 /*
2256 * make sure we don't unnecessarily trip the memcmp()
2257 * in fb_set_var()
2258 */
2259 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002260 var.yoffset = info->var.yoffset;
2261 var.xoffset = info->var.xoffset;
2262 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002264 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
Knut Petersen39942fd2005-12-12 22:17:19 -08002266 if (old_info != NULL && (old_info != info ||
2267 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002268 if (info->fbops->fb_set_par)
2269 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002270
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002271 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002272 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002275 if (fbcon_is_inactive(vc, info) ||
2276 ops->blank_state != FB_BLANK_UNBLANK)
2277 fbcon_del_cursor_timer(info);
2278 else
2279 fbcon_add_cursor_timer(info);
2280
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002281 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002282 ops->cursor_reset = 1;
2283
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002284 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002285 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002286 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002289 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002291
2292 if (p->userfont)
2293 charcnt = FNTCHARCNT(vc->vc_font.data);
2294
2295 if (charcnt > 256)
2296 vc->vc_complement_mask <<= 1;
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 updatescrollmode(p, info, vc);
2299
2300 switch (p->scrollmode) {
2301 case SCROLL_WRAP_MOVE:
2302 scrollback_phys_max = p->vrows - vc->vc_rows;
2303 break;
2304 case SCROLL_PAN_MOVE:
2305 case SCROLL_PAN_REDRAW:
2306 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2307 if (scrollback_phys_max < 0)
2308 scrollback_phys_max = 0;
2309 break;
2310 default:
2311 scrollback_phys_max = 0;
2312 break;
2313 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002314
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 scrollback_max = 0;
2316 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002317
2318 if (!fbcon_is_inactive(vc, info)) {
2319 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2320 ops->update_start(info);
2321 }
2322
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 fbcon_set_palette(vc, color_table);
2324 fbcon_clear_margins(vc, 0);
2325
2326 if (logo_shown == FBCON_LOGO_DRAW) {
2327
2328 logo_shown = fg_console;
2329 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002330 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 update_region(vc,
2332 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2333 vc->vc_size_row * (vc->vc_bottom -
2334 vc->vc_top) / 2);
2335 return 0;
2336 }
2337 return 1;
2338}
2339
2340static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2341 int blank)
2342{
Richard Purdie994efac2007-02-09 09:46:45 +00002343 struct fb_event event;
2344
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 if (blank) {
2346 unsigned short charmask = vc->vc_hi_font_mask ?
2347 0x1ff : 0xff;
2348 unsigned short oldc;
2349
2350 oldc = vc->vc_video_erase_char;
2351 vc->vc_video_erase_char &= charmask;
2352 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2353 vc->vc_video_erase_char = oldc;
2354 }
Richard Purdie994efac2007-02-09 09:46:45 +00002355
2356
2357 event.info = info;
2358 event.data = &blank;
2359 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360}
2361
2362static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2363{
2364 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2365 struct fbcon_ops *ops = info->fbcon_par;
2366
2367 if (mode_switch) {
2368 struct fb_var_screeninfo var = info->var;
2369
2370 ops->graphics = 1;
2371
2372 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002373 if (info->fbops->fb_save_state)
2374 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2376 fb_set_var(info, &var);
2377 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002378 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002379 } else if (info->fbops->fb_restore_state)
2380 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 }
2382
2383 if (!fbcon_is_inactive(vc, info)) {
2384 if (ops->blank_state != blank) {
2385 ops->blank_state = blank;
2386 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2387 ops->cursor_flash = (!blank);
2388
2389 if (fb_blank(info, blank))
2390 fbcon_generic_blank(vc, info, blank);
2391 }
2392
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002393 if (!blank)
2394 update_screen(vc);
2395 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002397 if (fbcon_is_inactive(vc, info) ||
2398 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002399 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002400 else
2401 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002402
2403 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404}
2405
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2407{
2408 u8 *fontdata = vc->vc_font.data;
2409 u8 *data = font->data;
2410 int i, j;
2411
2412 font->width = vc->vc_font.width;
2413 font->height = vc->vc_font.height;
2414 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2415 if (!font->data)
2416 return 0;
2417
2418 if (font->width <= 8) {
2419 j = vc->vc_font.height;
2420 for (i = 0; i < font->charcount; i++) {
2421 memcpy(data, fontdata, j);
2422 memset(data + j, 0, 32 - j);
2423 data += 32;
2424 fontdata += j;
2425 }
2426 } else if (font->width <= 16) {
2427 j = vc->vc_font.height * 2;
2428 for (i = 0; i < font->charcount; i++) {
2429 memcpy(data, fontdata, j);
2430 memset(data + j, 0, 64 - j);
2431 data += 64;
2432 fontdata += j;
2433 }
2434 } else if (font->width <= 24) {
2435 for (i = 0; i < font->charcount; i++) {
2436 for (j = 0; j < vc->vc_font.height; j++) {
2437 *data++ = fontdata[0];
2438 *data++ = fontdata[1];
2439 *data++ = fontdata[2];
2440 fontdata += sizeof(u32);
2441 }
2442 memset(data, 0, 3 * (32 - j));
2443 data += 3 * (32 - j);
2444 }
2445 } else {
2446 j = vc->vc_font.height * 4;
2447 for (i = 0; i < font->charcount; i++) {
2448 memcpy(data, fontdata, j);
2449 memset(data + j, 0, 128 - j);
2450 data += 128;
2451 fontdata += j;
2452 }
2453 }
2454 return 0;
2455}
2456
2457static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002458 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459{
2460 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002461 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 struct display *p = &fb_display[vc->vc_num];
2463 int resize;
2464 int cnt;
2465 char *old_data = NULL;
2466
2467 if (CON_IS_VISIBLE(vc) && softback_lines)
2468 fbcon_set_origin(vc);
2469
2470 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2471 if (p->userfont)
2472 old_data = vc->vc_font.data;
2473 if (userfont)
2474 cnt = FNTCHARCNT(data);
2475 else
2476 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002477 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 if ((p->userfont = userfont))
2479 REFCOUNT(data)++;
2480 vc->vc_font.width = w;
2481 vc->vc_font.height = h;
2482 if (vc->vc_hi_font_mask && cnt == 256) {
2483 vc->vc_hi_font_mask = 0;
2484 if (vc->vc_can_do_color) {
2485 vc->vc_complement_mask >>= 1;
2486 vc->vc_s_complement_mask >>= 1;
2487 }
2488
2489 /* ++Edmund: reorder the attribute bits */
2490 if (vc->vc_can_do_color) {
2491 unsigned short *cp =
2492 (unsigned short *) vc->vc_origin;
2493 int count = vc->vc_screenbuf_size / 2;
2494 unsigned short c;
2495 for (; count > 0; count--, cp++) {
2496 c = scr_readw(cp);
2497 scr_writew(((c & 0xfe00) >> 1) |
2498 (c & 0xff), cp);
2499 }
2500 c = vc->vc_video_erase_char;
2501 vc->vc_video_erase_char =
2502 ((c & 0xfe00) >> 1) | (c & 0xff);
2503 vc->vc_attr >>= 1;
2504 }
2505 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2506 vc->vc_hi_font_mask = 0x100;
2507 if (vc->vc_can_do_color) {
2508 vc->vc_complement_mask <<= 1;
2509 vc->vc_s_complement_mask <<= 1;
2510 }
2511
2512 /* ++Edmund: reorder the attribute bits */
2513 {
2514 unsigned short *cp =
2515 (unsigned short *) vc->vc_origin;
2516 int count = vc->vc_screenbuf_size / 2;
2517 unsigned short c;
2518 for (; count > 0; count--, cp++) {
2519 unsigned short newc;
2520 c = scr_readw(cp);
2521 if (vc->vc_can_do_color)
2522 newc =
2523 ((c & 0xff00) << 1) | (c &
2524 0xff);
2525 else
2526 newc = c & ~0x100;
2527 scr_writew(newc, cp);
2528 }
2529 c = vc->vc_video_erase_char;
2530 if (vc->vc_can_do_color) {
2531 vc->vc_video_erase_char =
2532 ((c & 0xff00) << 1) | (c & 0xff);
2533 vc->vc_attr <<= 1;
2534 } else
2535 vc->vc_video_erase_char = c & ~0x100;
2536 }
2537
2538 }
2539
2540 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002541 int cols, rows;
2542
2543 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2544 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2545 cols /= w;
2546 rows /= h;
2547 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002548 if (CON_IS_VISIBLE(vc) && softback_buf)
2549 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 } else if (CON_IS_VISIBLE(vc)
2551 && vc->vc_mode == KD_TEXT) {
2552 fbcon_clear_margins(vc, 0);
2553 update_screen(vc);
2554 }
2555
2556 if (old_data && (--REFCOUNT(old_data) == 0))
2557 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2558 return 0;
2559}
2560
2561static int fbcon_copy_font(struct vc_data *vc, int con)
2562{
2563 struct display *od = &fb_display[con];
2564 struct console_font *f = &vc->vc_font;
2565
2566 if (od->fontdata == f->data)
2567 return 0; /* already the same font... */
2568 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2569}
2570
2571/*
2572 * User asked to set font; we are guaranteed that
2573 * a) width and height are in range 1..32
2574 * b) charcount does not exceed 512
2575 * but lets not assume that, since someone might someday want to use larger
2576 * fonts. And charcount of 512 is small for unicode support.
2577 *
2578 * However, user space gives the font in 32 rows , regardless of
2579 * actual font height. So a new API is needed if support for larger fonts
2580 * is ever implemented.
2581 */
2582
2583static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2584{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002585 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 unsigned charcount = font->charcount;
2587 int w = font->width;
2588 int h = font->height;
2589 int size;
2590 int i, csum;
2591 u8 *new_data, *data = font->data;
2592 int pitch = (font->width+7) >> 3;
2593
2594 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2595 * If not this check should be changed to charcount < 256 */
2596 if (charcount != 256 && charcount != 512)
2597 return -EINVAL;
2598
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002599 /* Make sure drawing engine can handle the font */
2600 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2601 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2602 return -EINVAL;
2603
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002604 /* Make sure driver can handle the font length */
2605 if (fbcon_invalid_charcount(info, charcount))
2606 return -EINVAL;
2607
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 size = h * pitch * charcount;
2609
2610 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2611
2612 if (!new_data)
2613 return -ENOMEM;
2614
2615 new_data += FONT_EXTRA_WORDS * sizeof(int);
2616 FNTSIZE(new_data) = size;
2617 FNTCHARCNT(new_data) = charcount;
2618 REFCOUNT(new_data) = 0; /* usage counter */
2619 for (i=0; i< charcount; i++) {
2620 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2621 }
2622
2623 /* Since linux has a nice crc32 function use it for counting font
2624 * checksums. */
2625 csum = crc32(0, new_data, size);
2626
2627 FNTSUM(new_data) = csum;
2628 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002629 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 struct vc_data *tmp = vc_cons[i].d;
2631
2632 if (fb_display[i].userfont &&
2633 fb_display[i].fontdata &&
2634 FNTSUM(fb_display[i].fontdata) == csum &&
2635 FNTSIZE(fb_display[i].fontdata) == size &&
2636 tmp->vc_font.width == w &&
2637 !memcmp(fb_display[i].fontdata, new_data, size)) {
2638 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002639 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 break;
2641 }
2642 }
2643 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2644}
2645
2646static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2647{
2648 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002649 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002652 f = get_default_font(info->var.xres, info->var.yres,
2653 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 else if (!(f = find_font(name)))
2655 return -ENOENT;
2656
2657 font->width = f->width;
2658 font->height = f->height;
2659 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2660}
2661
2662static u16 palette_red[16];
2663static u16 palette_green[16];
2664static u16 palette_blue[16];
2665
2666static struct fb_cmap palette_cmap = {
2667 0, 16, palette_red, palette_green, palette_blue, NULL
2668};
2669
2670static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2671{
2672 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2673 int i, j, k, depth;
2674 u8 val;
2675
2676 if (fbcon_is_inactive(vc, info))
2677 return -EINVAL;
2678
2679 if (!CON_IS_VISIBLE(vc))
2680 return 0;
2681
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002682 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 if (depth > 3) {
2684 for (i = j = 0; i < 16; i++) {
2685 k = table[i];
2686 val = vc->vc_palette[j++];
2687 palette_red[k] = (val << 8) | val;
2688 val = vc->vc_palette[j++];
2689 palette_green[k] = (val << 8) | val;
2690 val = vc->vc_palette[j++];
2691 palette_blue[k] = (val << 8) | val;
2692 }
2693 palette_cmap.len = 16;
2694 palette_cmap.start = 0;
2695 /*
2696 * If framebuffer is capable of less than 16 colors,
2697 * use default palette of fbcon.
2698 */
2699 } else
2700 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2701
2702 return fb_set_cmap(&palette_cmap, info);
2703}
2704
2705static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2706{
2707 unsigned long p;
2708 int line;
2709
2710 if (vc->vc_num != fg_console || !softback_lines)
2711 return (u16 *) (vc->vc_origin + offset);
2712 line = offset / vc->vc_size_row;
2713 if (line >= softback_lines)
2714 return (u16 *) (vc->vc_origin + offset -
2715 softback_lines * vc->vc_size_row);
2716 p = softback_curr + offset;
2717 if (p >= softback_end)
2718 p += softback_buf - softback_end;
2719 return (u16 *) p;
2720}
2721
2722static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2723 int *px, int *py)
2724{
2725 unsigned long ret;
2726 int x, y;
2727
2728 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2729 unsigned long offset = (pos - vc->vc_origin) / 2;
2730
2731 x = offset % vc->vc_cols;
2732 y = offset / vc->vc_cols;
2733 if (vc->vc_num == fg_console)
2734 y += softback_lines;
2735 ret = pos + (vc->vc_cols - x) * 2;
2736 } else if (vc->vc_num == fg_console && softback_lines) {
2737 unsigned long offset = pos - softback_curr;
2738
2739 if (pos < softback_curr)
2740 offset += softback_end - softback_buf;
2741 offset /= 2;
2742 x = offset % vc->vc_cols;
2743 y = offset / vc->vc_cols;
2744 ret = pos + (vc->vc_cols - x) * 2;
2745 if (ret == softback_end)
2746 ret = softback_buf;
2747 if (ret == softback_in)
2748 ret = vc->vc_origin;
2749 } else {
2750 /* Should not happen */
2751 x = y = 0;
2752 ret = vc->vc_origin;
2753 }
2754 if (px)
2755 *px = x;
2756 if (py)
2757 *py = y;
2758 return ret;
2759}
2760
2761/* As we might be inside of softback, we may work with non-contiguous buffer,
2762 that's why we have to use a separate routine. */
2763static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2764{
2765 while (cnt--) {
2766 u16 a = scr_readw(p);
2767 if (!vc->vc_can_do_color)
2768 a ^= 0x0800;
2769 else if (vc->vc_hi_font_mask == 0x100)
2770 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2771 (((a) & 0x0e00) << 4);
2772 else
2773 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2774 (((a) & 0x0700) << 4);
2775 scr_writew(a, p++);
2776 if (p == (u16 *) softback_end)
2777 p = (u16 *) softback_buf;
2778 if (p == (u16 *) softback_in)
2779 p = (u16 *) vc->vc_origin;
2780 }
2781}
2782
2783static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2784{
2785 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002786 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 struct display *p = &fb_display[fg_console];
2788 int offset, limit, scrollback_old;
2789
2790 if (softback_top) {
2791 if (vc->vc_num != fg_console)
2792 return 0;
2793 if (vc->vc_mode != KD_TEXT || !lines)
2794 return 0;
2795 if (logo_shown >= 0) {
2796 struct vc_data *conp2 = vc_cons[logo_shown].d;
2797
2798 if (conp2->vc_top == logo_lines
2799 && conp2->vc_bottom == conp2->vc_rows)
2800 conp2->vc_top = 0;
2801 if (logo_shown == vc->vc_num) {
2802 unsigned long p, q;
2803 int i;
2804
2805 p = softback_in;
2806 q = vc->vc_origin +
2807 logo_lines * vc->vc_size_row;
2808 for (i = 0; i < logo_lines; i++) {
2809 if (p == softback_top)
2810 break;
2811 if (p == softback_buf)
2812 p = softback_end;
2813 p -= vc->vc_size_row;
2814 q -= vc->vc_size_row;
2815 scr_memcpyw((u16 *) q, (u16 *) p,
2816 vc->vc_size_row);
2817 }
David Hollister308af922006-05-30 21:25:36 -07002818 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 update_region(vc, vc->vc_origin,
2820 logo_lines * vc->vc_cols);
2821 }
2822 logo_shown = FBCON_LOGO_CANSHOW;
2823 }
2824 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2825 fbcon_redraw_softback(vc, p, lines);
2826 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2827 return 0;
2828 }
2829
2830 if (!scrollback_phys_max)
2831 return -ENOSYS;
2832
2833 scrollback_old = scrollback_current;
2834 scrollback_current -= lines;
2835 if (scrollback_current < 0)
2836 scrollback_current = 0;
2837 else if (scrollback_current > scrollback_max)
2838 scrollback_current = scrollback_max;
2839 if (scrollback_current == scrollback_old)
2840 return 0;
2841
2842 if (fbcon_is_inactive(vc, info))
2843 return 0;
2844
2845 fbcon_cursor(vc, CM_ERASE);
2846
2847 offset = p->yscroll - scrollback_current;
2848 limit = p->vrows;
2849 switch (p->scrollmode) {
2850 case SCROLL_WRAP_MOVE:
2851 info->var.vmode |= FB_VMODE_YWRAP;
2852 break;
2853 case SCROLL_PAN_MOVE:
2854 case SCROLL_PAN_REDRAW:
2855 limit -= vc->vc_rows;
2856 info->var.vmode &= ~FB_VMODE_YWRAP;
2857 break;
2858 }
2859 if (offset < 0)
2860 offset += limit;
2861 else if (offset >= limit)
2862 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002863
2864 ops->var.xoffset = 0;
2865 ops->var.yoffset = offset * vc->vc_font.height;
2866 ops->update_start(info);
2867
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 if (!scrollback_current)
2869 fbcon_cursor(vc, CM_DRAW);
2870 return 0;
2871}
2872
2873static int fbcon_set_origin(struct vc_data *vc)
2874{
2875 if (softback_lines)
2876 fbcon_scrolldelta(vc, softback_lines);
2877 return 0;
2878}
2879
2880static void fbcon_suspended(struct fb_info *info)
2881{
2882 struct vc_data *vc = NULL;
2883 struct fbcon_ops *ops = info->fbcon_par;
2884
2885 if (!ops || ops->currcon < 0)
2886 return;
2887 vc = vc_cons[ops->currcon].d;
2888
2889 /* Clear cursor, restore saved data */
2890 fbcon_cursor(vc, CM_ERASE);
2891}
2892
2893static void fbcon_resumed(struct fb_info *info)
2894{
2895 struct vc_data *vc;
2896 struct fbcon_ops *ops = info->fbcon_par;
2897
2898 if (!ops || ops->currcon < 0)
2899 return;
2900 vc = vc_cons[ops->currcon].d;
2901
2902 update_screen(vc);
2903}
2904
2905static void fbcon_modechanged(struct fb_info *info)
2906{
2907 struct fbcon_ops *ops = info->fbcon_par;
2908 struct vc_data *vc;
2909 struct display *p;
2910 int rows, cols;
2911
2912 if (!ops || ops->currcon < 0)
2913 return;
2914 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002915 if (vc->vc_mode != KD_TEXT ||
2916 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 return;
2918
2919 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002920 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922 if (CON_IS_VISIBLE(vc)) {
2923 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002924 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2925 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2926 cols /= vc->vc_font.width;
2927 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 vc_resize(vc, cols, rows);
2929 updatescrollmode(p, info, vc);
2930 scrollback_max = 0;
2931 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002932
2933 if (!fbcon_is_inactive(vc, info)) {
2934 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2935 ops->update_start(info);
2936 }
2937
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 fbcon_set_palette(vc, color_table);
2939 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002940 if (softback_buf)
2941 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 }
2943}
2944
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002945static void fbcon_set_all_vcs(struct fb_info *info)
2946{
2947 struct fbcon_ops *ops = info->fbcon_par;
2948 struct vc_data *vc;
2949 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002950 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002951
2952 if (!ops || ops->currcon < 0)
2953 return;
2954
Antonino A. Daplase614b182006-06-26 00:27:09 -07002955 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002956 vc = vc_cons[i].d;
2957 if (!vc || vc->vc_mode != KD_TEXT ||
2958 registered_fb[con2fb_map[i]] != info)
2959 continue;
2960
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002961 if (CON_IS_VISIBLE(vc)) {
2962 fg = i;
2963 continue;
2964 }
2965
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002966 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002967 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002968 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002969 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2970 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002971 cols /= vc->vc_font.width;
2972 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002973 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002974 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002975
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002976 if (fg != -1)
2977 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002978}
2979
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980static int fbcon_mode_deleted(struct fb_info *info,
2981 struct fb_videomode *mode)
2982{
2983 struct fb_info *fb_info;
2984 struct display *p;
2985 int i, j, found = 0;
2986
2987 /* before deletion, ensure that mode is not in use */
2988 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2989 j = con2fb_map[i];
2990 if (j == -1)
2991 continue;
2992 fb_info = registered_fb[j];
2993 if (fb_info != info)
2994 continue;
2995 p = &fb_display[i];
2996 if (!p || !p->mode)
2997 continue;
2998 if (fb_mode_is_equal(p->mode, mode)) {
2999 found = 1;
3000 break;
3001 }
3002 }
3003 return found;
3004}
3005
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003006static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003007{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003008 int i, idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003009
3010 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3011 if (con2fb_map[i] == idx)
3012 con2fb_map[i] = -1;
3013 }
3014
3015 if (idx == info_idx) {
3016 info_idx = -1;
3017
3018 for (i = 0; i < FB_MAX; i++) {
3019 if (registered_fb[i] != NULL) {
3020 info_idx = i;
3021 break;
3022 }
3023 }
3024 }
3025
3026 if (info_idx != -1) {
3027 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3028 if (con2fb_map[i] == -1)
3029 con2fb_map[i] = info_idx;
3030 }
3031 }
3032
3033 if (!num_registered_fb)
3034 unregister_con_driver(&fb_con);
3035
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003036
3037 if (primary_device == idx)
3038 primary_device = -1;
3039
Antonino A. Daplase614b182006-06-26 00:27:09 -07003040 return 0;
3041}
3042
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003043#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3044static int fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003046 int ret = 0;
3047
3048 if (!map_override && primary_device == -1 &&
3049 fb_is_primary_device(info)) {
3050 int i, err;
3051
3052 printk(KERN_INFO "fbcon: %s is primary device\n",
3053 info->fix.id);
3054 primary_device = info->node;
3055
3056 if (!con_is_bound(&fb_con))
3057 goto done;
3058
3059 printk(KERN_INFO "fbcon: Unbinding old driver\n");
3060 unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3061 fbcon_is_default);
3062 info_idx = primary_device;
3063
3064 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3065 con2fb_map_boot[i] = primary_device;
3066 con2fb_map[i] = primary_device;
3067 }
3068
3069 printk(KERN_INFO "fbcon: Selecting new driver\n");
3070 err = bind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3071 fbcon_is_default);
3072
3073 if (err) {
3074 for (i = first_fb_vc; i <= last_fb_vc; i++)
3075 con2fb_map[i] = -1;
3076
3077 info_idx = -1;
3078 }
3079
3080 ret = 1;
3081 }
3082
3083done:
3084 return ret;
3085}
3086#else
3087static inline int fbcon_select_primary(struct fb_info *info)
3088{
3089 return 0;
3090}
3091#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3092
3093static int fbcon_fb_registered(struct fb_info *info)
3094{
3095 int ret = 0, i, idx = info->node;
3096
3097 if (fbcon_select_primary(info))
3098 goto done;
3099
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100
3101 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003102 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 if (con2fb_map_boot[i] == idx) {
3104 info_idx = idx;
3105 break;
3106 }
3107 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003108
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 if (info_idx != -1)
3110 ret = fbcon_takeover(1);
3111 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003112 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003113 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 set_con2fb_map(i, idx, 0);
3115 }
3116 }
3117
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003118done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 return ret;
3120}
3121
3122static void fbcon_fb_blanked(struct fb_info *info, int blank)
3123{
3124 struct fbcon_ops *ops = info->fbcon_par;
3125 struct vc_data *vc;
3126
3127 if (!ops || ops->currcon < 0)
3128 return;
3129
3130 vc = vc_cons[ops->currcon].d;
3131 if (vc->vc_mode != KD_TEXT ||
3132 registered_fb[con2fb_map[ops->currcon]] != info)
3133 return;
3134
3135 if (CON_IS_VISIBLE(vc)) {
3136 if (blank)
3137 do_blank_screen(0);
3138 else
3139 do_unblank_screen(0);
3140 }
3141 ops->blank_state = blank;
3142}
3143
3144static void fbcon_new_modelist(struct fb_info *info)
3145{
3146 int i;
3147 struct vc_data *vc;
3148 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003149 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Antonino A. Daplase614b182006-06-26 00:27:09 -07003151 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 if (registered_fb[con2fb_map[i]] != info)
3153 continue;
3154 if (!fb_display[i].mode)
3155 continue;
3156 vc = vc_cons[i].d;
3157 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003158 mode = fb_find_nearest_mode(fb_display[i].mode,
3159 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003161 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 }
3163}
3164
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003165static void fbcon_get_requirement(struct fb_info *info,
3166 struct fb_blit_caps *caps)
3167{
3168 struct vc_data *vc;
3169 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003170
3171 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003172 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003173
3174 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3175 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003176 if (vc && vc->vc_mode == KD_TEXT &&
3177 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003178 p = &fb_display[i];
3179 caps->x |= 1 << (vc->vc_font.width - 1);
3180 caps->y |= 1 << (vc->vc_font.height - 1);
3181 charcnt = (p->userfont) ?
3182 FNTCHARCNT(p->fontdata) : 256;
3183 if (caps->len < charcnt)
3184 caps->len = charcnt;
3185 }
3186 }
3187 } else {
3188 vc = vc_cons[fg_console].d;
3189
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003190 if (vc && vc->vc_mode == KD_TEXT &&
3191 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003192 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003193 caps->x = 1 << (vc->vc_font.width - 1);
3194 caps->y = 1 << (vc->vc_font.height - 1);
3195 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003196 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003197 }
3198 }
3199}
3200
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201static int fbcon_event_notify(struct notifier_block *self,
3202 unsigned long action, void *data)
3203{
3204 struct fb_event *event = data;
3205 struct fb_info *info = event->info;
3206 struct fb_videomode *mode;
3207 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003208 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 int ret = 0;
3210
Antonino A. Daplase614b182006-06-26 00:27:09 -07003211 /*
3212 * ignore all events except driver registration and deregistration
3213 * if fbcon is not active
3214 */
3215 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3216 action == FB_EVENT_FB_UNREGISTERED))
3217 goto done;
3218
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 switch(action) {
3220 case FB_EVENT_SUSPEND:
3221 fbcon_suspended(info);
3222 break;
3223 case FB_EVENT_RESUME:
3224 fbcon_resumed(info);
3225 break;
3226 case FB_EVENT_MODE_CHANGE:
3227 fbcon_modechanged(info);
3228 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003229 case FB_EVENT_MODE_CHANGE_ALL:
3230 fbcon_set_all_vcs(info);
3231 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 case FB_EVENT_MODE_DELETE:
3233 mode = event->data;
3234 ret = fbcon_mode_deleted(info, mode);
3235 break;
3236 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003237 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003239 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003240 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003241 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 case FB_EVENT_SET_CONSOLE_MAP:
3243 con2fb = event->data;
3244 ret = set_con2fb_map(con2fb->console - 1,
3245 con2fb->framebuffer, 1);
3246 break;
3247 case FB_EVENT_GET_CONSOLE_MAP:
3248 con2fb = event->data;
3249 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3250 break;
3251 case FB_EVENT_BLANK:
3252 fbcon_fb_blanked(info, *(int *)event->data);
3253 break;
3254 case FB_EVENT_NEW_MODELIST:
3255 fbcon_new_modelist(info);
3256 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003257 case FB_EVENT_GET_REQ:
3258 caps = event->data;
3259 fbcon_get_requirement(info, caps);
3260 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 }
3262
Antonino A. Daplase614b182006-06-26 00:27:09 -07003263done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 return ret;
3265}
3266
3267/*
3268 * The console `switch' structure for the frame buffer based console
3269 */
3270
3271static const struct consw fb_con = {
3272 .owner = THIS_MODULE,
3273 .con_startup = fbcon_startup,
3274 .con_init = fbcon_init,
3275 .con_deinit = fbcon_deinit,
3276 .con_clear = fbcon_clear,
3277 .con_putc = fbcon_putc,
3278 .con_putcs = fbcon_putcs,
3279 .con_cursor = fbcon_cursor,
3280 .con_scroll = fbcon_scroll,
3281 .con_bmove = fbcon_bmove,
3282 .con_switch = fbcon_switch,
3283 .con_blank = fbcon_blank,
3284 .con_font_set = fbcon_set_font,
3285 .con_font_get = fbcon_get_font,
3286 .con_font_default = fbcon_set_def_font,
3287 .con_font_copy = fbcon_copy_font,
3288 .con_set_palette = fbcon_set_palette,
3289 .con_scrolldelta = fbcon_scrolldelta,
3290 .con_set_origin = fbcon_set_origin,
3291 .con_invert_region = fbcon_invert_region,
3292 .con_screen_pos = fbcon_screen_pos,
3293 .con_getxy = fbcon_getxy,
3294 .con_resize = fbcon_resize,
3295};
3296
3297static struct notifier_block fbcon_event_notifier = {
3298 .notifier_call = fbcon_event_notify,
3299};
3300
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003301static ssize_t store_rotate(struct device *device,
3302 struct device_attribute *attr, const char *buf,
3303 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003304{
3305 struct fb_info *info;
3306 int rotate, idx;
3307 char **last = NULL;
3308
Antonino A. Daplase614b182006-06-26 00:27:09 -07003309 if (fbcon_has_exited)
3310 return count;
3311
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003312 acquire_console_sem();
3313 idx = con2fb_map[fg_console];
3314
3315 if (idx == -1 || registered_fb[idx] == NULL)
3316 goto err;
3317
3318 info = registered_fb[idx];
3319 rotate = simple_strtoul(buf, last, 0);
3320 fbcon_rotate(info, rotate);
3321err:
3322 release_console_sem();
3323 return count;
3324}
3325
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003326static ssize_t store_rotate_all(struct device *device,
3327 struct device_attribute *attr,const char *buf,
3328 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003329{
3330 struct fb_info *info;
3331 int rotate, idx;
3332 char **last = NULL;
3333
Antonino A. Daplase614b182006-06-26 00:27:09 -07003334 if (fbcon_has_exited)
3335 return count;
3336
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003337 acquire_console_sem();
3338 idx = con2fb_map[fg_console];
3339
3340 if (idx == -1 || registered_fb[idx] == NULL)
3341 goto err;
3342
3343 info = registered_fb[idx];
3344 rotate = simple_strtoul(buf, last, 0);
3345 fbcon_rotate_all(info, rotate);
3346err:
3347 release_console_sem();
3348 return count;
3349}
3350
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003351static ssize_t show_rotate(struct device *device,
3352 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003353{
3354 struct fb_info *info;
3355 int rotate = 0, idx;
3356
Antonino A. Daplase614b182006-06-26 00:27:09 -07003357 if (fbcon_has_exited)
3358 return 0;
3359
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003360 acquire_console_sem();
3361 idx = con2fb_map[fg_console];
3362
3363 if (idx == -1 || registered_fb[idx] == NULL)
3364 goto err;
3365
3366 info = registered_fb[idx];
3367 rotate = fbcon_get_rotate(info);
3368err:
3369 release_console_sem();
3370 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3371}
3372
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003373static ssize_t show_cursor_blink(struct device *device,
3374 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003375{
3376 struct fb_info *info;
3377 struct fbcon_ops *ops;
3378 int idx, blink = -1;
3379
3380 if (fbcon_has_exited)
3381 return 0;
3382
3383 acquire_console_sem();
3384 idx = con2fb_map[fg_console];
3385
3386 if (idx == -1 || registered_fb[idx] == NULL)
3387 goto err;
3388
3389 info = registered_fb[idx];
3390 ops = info->fbcon_par;
3391
3392 if (!ops)
3393 goto err;
3394
3395 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3396err:
3397 release_console_sem();
3398 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3399}
3400
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003401static ssize_t store_cursor_blink(struct device *device,
3402 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003403 const char *buf, size_t count)
3404{
3405 struct fb_info *info;
3406 int blink, idx;
3407 char **last = NULL;
3408
3409 if (fbcon_has_exited)
3410 return count;
3411
3412 acquire_console_sem();
3413 idx = con2fb_map[fg_console];
3414
3415 if (idx == -1 || registered_fb[idx] == NULL)
3416 goto err;
3417
3418 info = registered_fb[idx];
3419
3420 if (!info->fbcon_par)
3421 goto err;
3422
3423 blink = simple_strtoul(buf, last, 0);
3424
3425 if (blink) {
3426 fbcon_cursor_noblink = 0;
3427 fbcon_add_cursor_timer(info);
3428 } else {
3429 fbcon_cursor_noblink = 1;
3430 fbcon_del_cursor_timer(info);
3431 }
3432
3433err:
3434 release_console_sem();
3435 return count;
3436}
3437
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003438static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003439 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3440 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003441 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3442 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003443};
3444
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003445static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003446{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003447 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003448
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003449 fbcon_has_sysfs = 1;
3450
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003451 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3452 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003453
3454 if (error)
3455 break;
3456 }
3457
3458 if (error) {
3459 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003460 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003461
3462 fbcon_has_sysfs = 0;
3463 }
3464
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003465 return 0;
3466}
3467
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003468static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003471 int i;
3472
3473 acquire_console_sem();
3474
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 for (i = 0; i < FB_MAX; i++) {
3476 if (registered_fb[i] != NULL) {
3477 info_idx = i;
3478 break;
3479 }
3480 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003481
3482 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 fbcon_takeover(0);
3484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485}
3486
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003487static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003488{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003489 struct fb_info *info;
3490 int i, j, mapped;
3491
Antonino A. Daplase614b182006-06-26 00:27:09 -07003492 if (fbcon_has_exited)
3493 return;
3494
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003495#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003496 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003497#endif
3498#ifdef CONFIG_MAC
3499 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003500 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003501#endif
3502
3503 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003504 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003505
3506 for (i = 0; i < FB_MAX; i++) {
3507 mapped = 0;
3508 info = registered_fb[i];
3509
3510 if (info == NULL)
3511 continue;
3512
Antonino A. Daplase614b182006-06-26 00:27:09 -07003513 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3514 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003515 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003516 }
3517
3518 if (mapped) {
3519 if (info->fbops->fb_release)
3520 info->fbops->fb_release(info, 0);
3521 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003522
3523 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003524 struct fbcon_ops *ops = info->fbcon_par;
3525
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003526 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003527 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003528 kfree(info->fbcon_par);
3529 info->fbcon_par = NULL;
3530 }
3531
3532 if (info->queue.func == fb_flashcursor)
3533 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003534 }
3535 }
3536
Antonino A. Daplase614b182006-06-26 00:27:09 -07003537 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003538}
3539
3540static int __init fb_console_init(void)
3541{
3542 int i;
3543
3544 acquire_console_sem();
3545 fb_register_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003546 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003547
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003548 if (IS_ERR(fbcon_device)) {
3549 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003550 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003551 PTR_ERR(fbcon_device));
3552 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003553 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003554 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003555
3556 for (i = 0; i < MAX_NR_CONSOLES; i++)
3557 con2fb_map[i] = -1;
3558
3559 release_console_sem();
3560 fbcon_start();
3561 return 0;
3562}
3563
3564module_init(fb_console_init);
3565
3566#ifdef MODULE
3567
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003568static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003569{
3570 int i;
3571
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003572 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003573 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3574 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003575
3576 fbcon_has_sysfs = 0;
3577 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003578}
3579
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580static void __exit fb_console_exit(void)
3581{
3582 acquire_console_sem();
3583 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003584 fbcon_deinit_device();
3585 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003586 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003588 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589}
3590
3591module_exit(fb_console_exit);
3592
3593#endif
3594
3595MODULE_LICENSE("GPL");