blob: 7ba21eb1676c43bc38a32b774ca196bbf0a57035 [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,
195 struct vc_data *vc);
196static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
197 int unit);
198static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
199 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800200static void fbcon_modechanged(struct fb_info *info);
201static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700202static void fbcon_start(void);
203static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700204static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#ifdef CONFIG_MAC
207/*
208 * On the Macintoy, there may or may not be a working VBL int. We need to probe
209 */
210static int vbl_detected;
211
David Howells7d12e782006-10-05 14:55:46 +0100212static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
214 vbl_detected++;
215 return IRQ_HANDLED;
216}
217#endif
218
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800219#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800220static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800221{
222 struct fbcon_ops *ops = info->fbcon_par;
223
224 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800225 ops->p->con_rotate < 4)
226 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800227 else
228 ops->rotate = 0;
229}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800230
231static void fbcon_rotate(struct fb_info *info, u32 rotate)
232{
233 struct fbcon_ops *ops= info->fbcon_par;
234 struct fb_info *fb_info;
235
236 if (!ops || ops->currcon == -1)
237 return;
238
239 fb_info = registered_fb[con2fb_map[ops->currcon]];
240
241 if (info == fb_info) {
242 struct display *p = &fb_display[ops->currcon];
243
244 if (rotate < 4)
245 p->con_rotate = rotate;
246 else
247 p->con_rotate = 0;
248
249 fbcon_modechanged(info);
250 }
251}
252
253static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
254{
255 struct fbcon_ops *ops = info->fbcon_par;
256 struct vc_data *vc;
257 struct display *p;
258 int i;
259
260 if (!ops || ops->currcon < 0 || rotate > 3)
261 return;
262
Antonino A. Daplase614b182006-06-26 00:27:09 -0700263 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800264 vc = vc_cons[i].d;
265 if (!vc || vc->vc_mode != KD_TEXT ||
266 registered_fb[con2fb_map[i]] != info)
267 continue;
268
269 p = &fb_display[vc->vc_num];
270 p->con_rotate = rotate;
271 }
272
273 fbcon_set_all_vcs(info);
274}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800275#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800276static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800277{
278 struct fbcon_ops *ops = info->fbcon_par;
279
280 ops->rotate = FB_ROTATE_UR;
281}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800282
283static void fbcon_rotate(struct fb_info *info, u32 rotate)
284{
285 return;
286}
287
288static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
289{
290 return;
291}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800292#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800293
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800294static int fbcon_get_rotate(struct fb_info *info)
295{
296 struct fbcon_ops *ops = info->fbcon_par;
297
298 return (ops) ? ops->rotate : 0;
299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
302{
303 struct fbcon_ops *ops = info->fbcon_par;
304
305 return (info->state != FBINFO_STATE_RUNNING ||
306 vc->vc_mode != KD_TEXT || ops->graphics);
307}
308
309static inline int get_color(struct vc_data *vc, struct fb_info *info,
310 u16 c, int is_fg)
311{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700312 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 int color = 0;
314
315 if (console_blanked) {
316 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
317
318 c = vc->vc_video_erase_char & charmask;
319 }
320
321 if (depth != 1)
322 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
323 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
324
325 switch (depth) {
326 case 1:
327 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700328 int col = ~(0xfff << (max(info->var.green.length,
329 max(info->var.red.length,
330 info->var.blue.length)))) & 0xff;
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700333 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
334 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 if (console_blanked)
337 fg = bg;
338
339 color = (is_fg) ? fg : bg;
340 break;
341 }
342 case 2:
343 /*
344 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700345 * is grayscale. However, simply dividing the values by 4
346 * will not work, as colors 1, 2 and 3 will be scaled-down
347 * to zero rendering them invisible. So empirically convert
348 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700350 switch (color) {
351 case 0:
352 color = 0; /* black */
353 break;
354 case 1 ... 6:
355 color = 2; /* white */
356 break;
357 case 7 ... 8:
358 color = 1; /* gray */
359 break;
360 default:
361 color = 3; /* intense white */
362 break;
363 }
364 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 case 3:
366 /*
367 * Last 8 entries of default 16-color palette is a more intense
368 * version of the first 8 (i.e., same chrominance, different
369 * luminance).
370 */
371 color &= 7;
372 break;
373 }
374
375
376 return color;
377}
378
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800379static void fbcon_update_softback(struct vc_data *vc)
380{
381 int l = fbcon_softback_size / vc->vc_size_row;
382
383 if (l > 5)
384 softback_end = softback_buf + l * vc->vc_size_row;
385 else
386 /* Smaller scrollback makes no sense, and 0 would screw
387 the operation totally */
388 softback_top = 0;
389}
390
David Howellsc4028952006-11-22 14:57:56 +0000391static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
David Howellsc4028952006-11-22 14:57:56 +0000393 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 struct fbcon_ops *ops = info->fbcon_par;
395 struct display *p;
396 struct vc_data *vc = NULL;
397 int c;
398 int mode;
399
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700400 acquire_console_sem();
401 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 vc = vc_cons[ops->currcon].d;
403
404 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700405 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700406 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700407 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700409 }
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 p = &fb_display[vc->vc_num];
412 c = scr_readw((u16 *) vc->vc_pos);
413 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
414 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800415 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 get_color(vc, info, c, 0));
417 release_console_sem();
418}
419
Russell King41359dc2005-06-30 16:30:07 +0100420#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100422static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 struct fb_info *info = dev_id;
425
426 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
427 schedule_work(&info->queue);
428 vbl_cursor_cnt = cursor_blink_rate;
429 }
430 return IRQ_HANDLED;
431}
432#endif
433
434static void cursor_timer_handler(unsigned long dev_addr)
435{
436 struct fb_info *info = (struct fb_info *) dev_addr;
437 struct fbcon_ops *ops = info->fbcon_par;
438
439 schedule_work(&info->queue);
440 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
441}
442
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700443static void fbcon_add_cursor_timer(struct fb_info *info)
444{
445 struct fbcon_ops *ops = info->fbcon_par;
446
447 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700448 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
449 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700450 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000451 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700452
453 init_timer(&ops->cursor_timer);
454 ops->cursor_timer.function = cursor_timer_handler;
455 ops->cursor_timer.expires = jiffies + HZ / 5;
456 ops->cursor_timer.data = (unsigned long ) info;
457 add_timer(&ops->cursor_timer);
458 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
459 }
460}
461
462static void fbcon_del_cursor_timer(struct fb_info *info)
463{
464 struct fbcon_ops *ops = info->fbcon_par;
465
466 if (info->queue.func == fb_flashcursor &&
467 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
468 del_timer_sync(&ops->cursor_timer);
469 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
470 }
471}
472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#ifndef MODULE
474static int __init fb_console_setup(char *this_opt)
475{
476 char *options;
477 int i, j;
478
479 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800480 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 while ((options = strsep(&this_opt, ",")) != NULL) {
483 if (!strncmp(options, "font:", 5))
484 strcpy(fontname, options + 5);
485
486 if (!strncmp(options, "scrollback:", 11)) {
487 options += 11;
488 if (*options) {
489 fbcon_softback_size = simple_strtoul(options, &options, 0);
490 if (*options == 'k' || *options == 'K') {
491 fbcon_softback_size *= 1024;
492 options++;
493 }
494 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800495 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 options++;
497 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800498 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500
501 if (!strncmp(options, "map:", 4)) {
502 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700503 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
505 if (!options[j])
506 j = 0;
507 con2fb_map_boot[i] =
508 (options[j++]-'0') % FB_MAX;
509 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700510
511 map_override = 1;
512 }
513
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800514 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 }
516
517 if (!strncmp(options, "vc:", 3)) {
518 options += 3;
519 if (*options)
520 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
521 if (first_fb_vc < 0)
522 first_fb_vc = 0;
523 if (*options++ == '-')
524 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
525 fbcon_is_default = 0;
526 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800527
528 if (!strncmp(options, "rotate:", 7)) {
529 options += 7;
530 if (*options)
531 rotate = simple_strtoul(options, &options, 0);
532 if (rotate > 3)
533 rotate = 0;
534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800536 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
539__setup("fbcon=", fb_console_setup);
540#endif
541
542static int search_fb_in_map(int idx)
543{
544 int i, retval = 0;
545
Antonino A. Daplase614b182006-06-26 00:27:09 -0700546 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (con2fb_map[i] == idx)
548 retval = 1;
549 }
550 return retval;
551}
552
553static int search_for_mapped_con(void)
554{
555 int i, retval = 0;
556
Antonino A. Daplase614b182006-06-26 00:27:09 -0700557 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (con2fb_map[i] != -1)
559 retval = 1;
560 }
561 return retval;
562}
563
564static int fbcon_takeover(int show_logo)
565{
566 int err, i;
567
568 if (!num_registered_fb)
569 return -ENODEV;
570
571 if (!show_logo)
572 logo_shown = FBCON_LOGO_DONTSHOW;
573
574 for (i = first_fb_vc; i <= last_fb_vc; i++)
575 con2fb_map[i] = info_idx;
576
577 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
578 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (err) {
581 for (i = first_fb_vc; i <= last_fb_vc; i++) {
582 con2fb_map[i] = -1;
583 }
584 info_idx = -1;
585 }
586
587 return err;
588}
589
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700590#ifdef MODULE
591static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
592 int cols, int rows, int new_cols, int new_rows)
593{
594 logo_shown = FBCON_LOGO_DONTSHOW;
595}
596#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
598 int cols, int rows, int new_cols, int new_rows)
599{
600 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800601 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 int cnt, erase = vc->vc_video_erase_char, step;
603 unsigned short *save = NULL, *r, *q;
604
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700605 if (info->flags & FBINFO_MODULE) {
606 logo_shown = FBCON_LOGO_DONTSHOW;
607 return;
608 }
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /*
611 * remove underline attribute from erase character
612 * if black and white framebuffer.
613 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700614 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800616 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 logo_lines = (logo_height + vc->vc_font.height - 1) /
618 vc->vc_font.height;
619 q = (unsigned short *) (vc->vc_origin +
620 vc->vc_size_row * rows);
621 step = logo_lines * cols;
622 for (r = q - logo_lines * cols; r < q; r++)
623 if (scr_readw(r) != vc->vc_video_erase_char)
624 break;
625 if (r != q && new_rows >= rows + logo_lines) {
626 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
627 if (save) {
628 int i = cols < new_cols ? cols : new_cols;
629 scr_memsetw(save, erase, logo_lines * new_cols * 2);
630 r = q - step;
631 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
632 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
633 r = q;
634 }
635 }
636 if (r == q) {
637 /* We can scroll screen down */
638 r = q - step - cols;
639 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
640 scr_memcpyw(r + step, r, vc->vc_size_row);
641 r -= cols;
642 }
643 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700644 int lines;
645 if (vc->vc_y + logo_lines >= rows)
646 lines = rows - vc->vc_y - 1;
647 else
648 lines = logo_lines;
649 vc->vc_y += lines;
650 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 }
652 }
653 scr_memsetw((unsigned short *) vc->vc_origin,
654 erase,
655 vc->vc_size_row * logo_lines);
656
657 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
658 fbcon_clear_margins(vc, 0);
659 update_screen(vc);
660 }
661
662 if (save) {
663 q = (unsigned short *) (vc->vc_origin +
664 vc->vc_size_row *
665 rows);
666 scr_memcpyw(q, save, logo_lines * new_cols * 2);
667 vc->vc_y += logo_lines;
668 vc->vc_pos += logo_lines * vc->vc_size_row;
669 kfree(save);
670 }
671
672 if (logo_lines > vc->vc_bottom) {
673 logo_shown = FBCON_LOGO_CANSHOW;
674 printk(KERN_INFO
675 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
676 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
677 logo_shown = FBCON_LOGO_DRAW;
678 vc->vc_top = logo_lines;
679 }
680}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700681#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800684static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
686 struct fbcon_ops *ops = info->fbcon_par;
687
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800688 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800691 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800692 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800693 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700697
698static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
699{
700 int err = 0;
701
702 if (info->flags & FBINFO_MISC_TILEBLITTING &&
703 info->tileops->fb_get_tilemax(info) < charcount)
704 err = 1;
705
706 return err;
707}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800709static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
711 struct fbcon_ops *ops = info->fbcon_par;
712
713 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800714 ops->p = &fb_display[vc->vc_num];
715 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 fbcon_set_bitops(ops);
717}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700718
719static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
720{
721 return 0;
722}
723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724#endif /* CONFIG_MISC_TILEBLITTING */
725
726
727static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
728 int unit, int oldidx)
729{
730 struct fbcon_ops *ops = NULL;
731 int err = 0;
732
733 if (!try_module_get(info->fbops->owner))
734 err = -ENODEV;
735
736 if (!err && info->fbops->fb_open &&
737 info->fbops->fb_open(info, 0))
738 err = -ENODEV;
739
740 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800741 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 if (!ops)
743 err = -ENOMEM;
744 }
745
746 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 info->fbcon_par = ops;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800748 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;
810
811 if (vc)
812 fbcon_set_disp(info, &info->var, vc);
813 else
814 fbcon_preset_disp(info, &info->var, unit);
815
816 if (show_logo) {
817 struct vc_data *fg_vc = vc_cons[fg_console].d;
818 struct fb_info *fg_info =
819 registered_fb[con2fb_map[fg_console]];
820
821 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
822 fg_vc->vc_rows, fg_vc->vc_cols,
823 fg_vc->vc_rows);
824 }
825
826 update_screen(vc_cons[fg_console].d);
827}
828
829/**
830 * set_con2fb_map - map console to frame buffer device
831 * @unit: virtual console number to map
832 * @newidx: frame buffer index to map virtual console to
833 * @user: user request
834 *
835 * Maps a virtual console @unit to a frame buffer device
836 * @newidx.
837 */
838static int set_con2fb_map(int unit, int newidx, int user)
839{
840 struct vc_data *vc = vc_cons[unit].d;
841 int oldidx = con2fb_map[unit];
842 struct fb_info *info = registered_fb[newidx];
843 struct fb_info *oldinfo = NULL;
844 int found, err = 0;
845
846 if (oldidx == newidx)
847 return 0;
848
Antonino A. Daplase614b182006-06-26 00:27:09 -0700849 if (!info || fbcon_has_exited)
850 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 if (!err && !search_for_mapped_con()) {
853 info_idx = newidx;
854 return fbcon_takeover(0);
855 }
856
857 if (oldidx != -1)
858 oldinfo = registered_fb[oldidx];
859
860 found = search_fb_in_map(newidx);
861
862 acquire_console_sem();
863 con2fb_map[unit] = newidx;
864 if (!err && !found)
865 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
866
867
868 /*
869 * If old fb is not mapped to any of the consoles,
870 * fbcon should release it.
871 */
872 if (!err && oldinfo && !search_fb_in_map(oldidx))
873 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
874 found);
875
876 if (!err) {
877 int show_logo = (fg_console == 0 && !user &&
878 logo_shown != FBCON_LOGO_DONTSHOW);
879
880 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700881 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 con2fb_map_boot[unit] = newidx;
883 con2fb_init_display(vc, info, unit, show_logo);
884 }
885
Antonino A. Daplase614b182006-06-26 00:27:09 -0700886 if (!search_fb_in_map(info_idx))
887 info_idx = newidx;
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 release_console_sem();
890 return err;
891}
892
893/*
894 * Low Level Operations
895 */
896/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
897static int var_to_display(struct display *disp,
898 struct fb_var_screeninfo *var,
899 struct fb_info *info)
900{
901 disp->xres_virtual = var->xres_virtual;
902 disp->yres_virtual = var->yres_virtual;
903 disp->bits_per_pixel = var->bits_per_pixel;
904 disp->grayscale = var->grayscale;
905 disp->nonstd = var->nonstd;
906 disp->accel_flags = var->accel_flags;
907 disp->height = var->height;
908 disp->width = var->width;
909 disp->red = var->red;
910 disp->green = var->green;
911 disp->blue = var->blue;
912 disp->transp = var->transp;
913 disp->rotate = var->rotate;
914 disp->mode = fb_match_mode(var, &info->modelist);
915 if (disp->mode == NULL)
916 /* This should not happen */
917 return -EINVAL;
918 return 0;
919}
920
921static void display_to_var(struct fb_var_screeninfo *var,
922 struct display *disp)
923{
924 fb_videomode_to_var(var, disp->mode);
925 var->xres_virtual = disp->xres_virtual;
926 var->yres_virtual = disp->yres_virtual;
927 var->bits_per_pixel = disp->bits_per_pixel;
928 var->grayscale = disp->grayscale;
929 var->nonstd = disp->nonstd;
930 var->accel_flags = disp->accel_flags;
931 var->height = disp->height;
932 var->width = disp->width;
933 var->red = disp->red;
934 var->green = disp->green;
935 var->blue = disp->blue;
936 var->transp = disp->transp;
937 var->rotate = disp->rotate;
938}
939
940static const char *fbcon_startup(void)
941{
942 const char *display_desc = "frame buffer device";
943 struct display *p = &fb_display[fg_console];
944 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700945 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 struct module *owner;
947 struct fb_info *info = NULL;
948 struct fbcon_ops *ops;
949 int rows, cols;
950 int irqres;
951
952 irqres = 1;
953 /*
954 * If num_registered_fb is zero, this is a call for the dummy part.
955 * The frame buffer devices weren't initialized yet.
956 */
957 if (!num_registered_fb || info_idx == -1)
958 return display_desc;
959 /*
960 * Instead of blindly using registered_fb[0], we use info_idx, set by
961 * fb_console_init();
962 */
963 info = registered_fb[info_idx];
964 if (!info)
965 return NULL;
966
967 owner = info->fbops->owner;
968 if (!try_module_get(owner))
969 return NULL;
970 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
971 module_put(owner);
972 return NULL;
973 }
974
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800975 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (!ops) {
977 module_put(owner);
978 return NULL;
979 }
980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 ops->currcon = -1;
982 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800983 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800985 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800986 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 if (info->fix.type != FB_TYPE_TEXT) {
989 if (fbcon_softback_size) {
990 if (!softback_buf) {
991 softback_buf =
992 (unsigned long)
993 kmalloc(fbcon_softback_size,
994 GFP_KERNEL);
995 if (!softback_buf) {
996 fbcon_softback_size = 0;
997 softback_top = 0;
998 }
999 }
1000 } else {
1001 if (softback_buf) {
1002 kfree((void *) softback_buf);
1003 softback_buf = 0;
1004 softback_top = 0;
1005 }
1006 }
1007 if (softback_buf)
1008 softback_in = softback_top = softback_curr =
1009 softback_buf;
1010 softback_lines = 0;
1011 }
1012
1013 /* Setup default font */
1014 if (!p->fontdata) {
1015 if (!fontname[0] || !(font = find_font(fontname)))
1016 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001017 info->var.yres,
1018 info->pixmap.blit_x,
1019 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 vc->vc_font.width = font->width;
1021 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001022 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1024 }
1025
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001026 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1027 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1028 cols /= vc->vc_font.width;
1029 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 vc_resize(vc, cols, rows);
1031
1032 DPRINTK("mode: %s\n", info->fix.id);
1033 DPRINTK("visual: %d\n", info->fix.visual);
1034 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1035 info->var.yres,
1036 info->var.bits_per_pixel);
1037
1038#ifdef CONFIG_ATARI
1039 if (MACH_IS_ATARI) {
1040 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1041 irqres =
1042 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1043 IRQ_TYPE_PRIO, "framebuffer vbl",
1044 info);
1045 }
1046#endif /* CONFIG_ATARI */
1047
1048#ifdef CONFIG_MAC
1049 /*
1050 * On a Macintoy, the VBL interrupt may or may not be active.
1051 * As interrupt based cursor is more reliable and race free, we
1052 * probe for VBL interrupts.
1053 */
1054 if (MACH_IS_MAC) {
1055 int ct = 0;
1056 /*
1057 * Probe for VBL: set temp. handler ...
1058 */
1059 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1060 "framebuffer vbl", info);
1061 vbl_detected = 0;
1062
1063 /*
1064 * ... and spin for 20 ms ...
1065 */
1066 while (!vbl_detected && ++ct < 1000)
1067 udelay(20);
1068
1069 if (ct == 1000)
1070 printk
1071 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1072
1073 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1074
1075 if (vbl_detected) {
1076 /*
1077 * interrupt based cursor ok
1078 */
1079 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1080 irqres =
1081 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1082 "framebuffer vbl", info);
1083 } else {
1084 /*
1085 * VBL not detected: fall through, use timer based cursor
1086 */
1087 irqres = 1;
1088 }
1089 }
1090#endif /* CONFIG_MAC */
1091
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001092 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001093 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 return display_desc;
1095}
1096
1097static void fbcon_init(struct vc_data *vc, int init)
1098{
1099 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1100 struct fbcon_ops *ops;
1101 struct vc_data **default_mode = vc->vc_display_fg;
1102 struct vc_data *svc = *default_mode;
1103 struct display *t, *p = &fb_display[vc->vc_num];
1104 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001105 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 if (info_idx == -1 || info == NULL)
1108 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001109
1110 cap = info->flags;
1111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1113 (info->fix.type == FB_TYPE_TEXT))
1114 logo = 0;
1115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 if (var_to_display(p, &info->var, info))
1117 return;
1118
1119 /* If we are not the first console on this
1120 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001121 t = &fb_display[fg_console];
1122 if (!p->fontdata) {
1123 if (t->fontdata) {
1124 struct vc_data *fvc = vc_cons[fg_console].d;
1125
1126 vc->vc_font.data = (void *)(p->fontdata =
1127 fvc->vc_font.data);
1128 vc->vc_font.width = fvc->vc_font.width;
1129 vc->vc_font.height = fvc->vc_font.height;
1130 p->userfont = t->userfont;
1131
1132 if (p->userfont)
1133 REFCOUNT(p->fontdata)++;
1134 } else {
1135 const struct font_desc *font = NULL;
1136
1137 if (!fontname[0] || !(font = find_font(fontname)))
1138 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001139 info->var.yres,
1140 info->pixmap.blit_x,
1141 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001142 vc->vc_font.width = font->width;
1143 vc->vc_font.height = font->height;
1144 vc->vc_font.data = (void *)(p->fontdata = font->data);
1145 vc->vc_font.charcount = 256; /* FIXME Need to
1146 support more fonts */
1147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 if (p->userfont)
1151 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001152
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001153 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1155 if (charcnt == 256) {
1156 vc->vc_hi_font_mask = 0;
1157 } else {
1158 vc->vc_hi_font_mask = 0x100;
1159 if (vc->vc_can_do_color)
1160 vc->vc_complement_mask <<= 1;
1161 }
1162
1163 if (!*svc->vc_uni_pagedir_loc)
1164 con_set_default_unimap(svc);
1165 if (!*vc->vc_uni_pagedir_loc)
1166 con_copy_unimap(vc, svc);
1167
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001168 ops = info->fbcon_par;
1169 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001170 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 cols = vc->vc_cols;
1173 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001174 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1175 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1176 new_cols /= vc->vc_font.width;
1177 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 vc_resize(vc, new_cols, new_rows);
1179
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 /*
1181 * We must always set the mode. The mode of the previous console
1182 * driver could be in the same resolution but we are using different
1183 * hardware so we have to initialize the hardware.
1184 *
1185 * We need to do it in fbcon_init() to prevent screen corruption.
1186 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001187 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 if (info->fbops->fb_set_par &&
1189 !(ops->flags & FBCON_FLAGS_INIT))
1190 info->fbops->fb_set_par(info);
1191 ops->flags |= FBCON_FLAGS_INIT;
1192 }
1193
1194 ops->graphics = 0;
1195
1196 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1197 !(cap & FBINFO_HWACCEL_DISABLED))
1198 p->scrollmode = SCROLL_MOVE;
1199 else /* default to something safe */
1200 p->scrollmode = SCROLL_REDRAW;
1201
1202 /*
1203 * ++guenther: console.c:vc_allocate() relies on initializing
1204 * vc_{cols,rows}, but we must not set those if we are only
1205 * resizing the console.
1206 */
1207 if (!init) {
1208 vc->vc_cols = new_cols;
1209 vc->vc_rows = new_rows;
1210 }
1211
1212 if (logo)
1213 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1214
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001215 if (vc == svc && softback_buf)
1216 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001217
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001218 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001219 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001220 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001221 }
1222
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001223 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224}
1225
Antonino A. Daplase614b182006-06-26 00:27:09 -07001226static void fbcon_free_font(struct display *p)
1227{
1228 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1229 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1230 p->fontdata = NULL;
1231 p->userfont = 0;
1232}
1233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234static void fbcon_deinit(struct vc_data *vc)
1235{
1236 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001237 struct fb_info *info;
1238 struct fbcon_ops *ops;
1239 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001242 idx = con2fb_map[vc->vc_num];
1243
1244 if (idx == -1)
1245 goto finished;
1246
1247 info = registered_fb[idx];
1248
1249 if (!info)
1250 goto finished;
1251
1252 ops = info->fbcon_par;
1253
1254 if (!ops)
1255 goto finished;
1256
1257 if (CON_IS_VISIBLE(vc))
1258 fbcon_del_cursor_timer(info);
1259
1260 ops->flags &= ~FBCON_FLAGS_INIT;
1261finished:
1262
1263 if (!con_is_bound(&fb_con))
1264 fbcon_exit();
1265
1266 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267}
1268
1269/* ====================================================================== */
1270
1271/* fbcon_XXX routines - interface used by the world
1272 *
1273 * This system is now divided into two levels because of complications
1274 * caused by hardware scrolling. Top level functions:
1275 *
1276 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1277 *
1278 * handles y values in range [0, scr_height-1] that correspond to real
1279 * screen positions. y_wrap shift means that first line of bitmap may be
1280 * anywhere on this display. These functions convert lineoffsets to
1281 * bitmap offsets and deal with the wrap-around case by splitting blits.
1282 *
1283 * fbcon_bmove_physical_8() -- These functions fast implementations
1284 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1285 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1286 *
1287 * WARNING:
1288 *
1289 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1290 * Implies should only really hardware scroll in rows. Only reason for
1291 * restriction is simplicity & efficiency at the moment.
1292 */
1293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1295 int width)
1296{
1297 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1298 struct fbcon_ops *ops = info->fbcon_par;
1299
1300 struct display *p = &fb_display[vc->vc_num];
1301 u_int y_break;
1302
1303 if (fbcon_is_inactive(vc, info))
1304 return;
1305
1306 if (!height || !width)
1307 return;
1308
1309 /* Split blits that cross physical y_wrap boundary */
1310
1311 y_break = p->vrows - p->yscroll;
1312 if (sy < y_break && sy + height - 1 >= y_break) {
1313 u_int b = y_break - sy;
1314 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1315 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1316 width);
1317 } else
1318 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1319}
1320
1321static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1322 int count, int ypos, int xpos)
1323{
1324 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1325 struct display *p = &fb_display[vc->vc_num];
1326 struct fbcon_ops *ops = info->fbcon_par;
1327
1328 if (!fbcon_is_inactive(vc, info))
1329 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1330 get_color(vc, info, scr_readw(s), 1),
1331 get_color(vc, info, scr_readw(s), 0));
1332}
1333
1334static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1335{
1336 unsigned short chr;
1337
1338 scr_writew(c, &chr);
1339 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1340}
1341
1342static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1343{
1344 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1345 struct fbcon_ops *ops = info->fbcon_par;
1346
1347 if (!fbcon_is_inactive(vc, info))
1348 ops->clear_margins(vc, info, bottom_only);
1349}
1350
1351static void fbcon_cursor(struct vc_data *vc, int mode)
1352{
1353 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1354 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 int y;
1356 int c = scr_readw((u16 *) vc->vc_pos);
1357
Michal Januszewskid1e23062007-05-08 00:38:07 -07001358 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 return;
1360
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001361 if (vc->vc_cursor_type & 0x10)
1362 fbcon_del_cursor_timer(info);
1363 else
1364 fbcon_add_cursor_timer(info);
1365
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1367 if (mode & CM_SOFTBACK) {
1368 mode &= ~CM_SOFTBACK;
1369 y = softback_lines;
1370 } else {
1371 if (softback_lines)
1372 fbcon_set_origin(vc);
1373 y = 0;
1374 }
1375
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001376 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 get_color(vc, info, c, 0));
1378 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1379}
1380
1381static int scrollback_phys_max = 0;
1382static int scrollback_max = 0;
1383static int scrollback_current = 0;
1384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385/*
1386 * If no vc is existent yet, just set struct display
1387 */
1388static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1389 int unit)
1390{
1391 struct display *p = &fb_display[unit];
1392 struct display *t = &fb_display[fg_console];
1393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 if (var_to_display(p, var, info))
1395 return;
1396
1397 p->fontdata = t->fontdata;
1398 p->userfont = t->userfont;
1399 if (p->userfont)
1400 REFCOUNT(p->fontdata)++;
1401}
1402
1403static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1404 struct vc_data *vc)
1405{
1406 struct display *p = &fb_display[vc->vc_num], *t;
1407 struct vc_data **default_mode = vc->vc_display_fg;
1408 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001409 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 int rows, cols, charcnt = 256;
1411
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 if (var_to_display(p, var, info))
1413 return;
1414 t = &fb_display[svc->vc_num];
1415 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001416 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 vc->vc_font.width = (*default_mode)->vc_font.width;
1418 vc->vc_font.height = (*default_mode)->vc_font.height;
1419 p->userfont = t->userfont;
1420 if (p->userfont)
1421 REFCOUNT(p->fontdata)++;
1422 }
1423 if (p->userfont)
1424 charcnt = FNTCHARCNT(p->fontdata);
1425
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001426 var->activate = FB_ACTIVATE_NOW;
1427 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001428 var->yoffset = info->var.yoffset;
1429 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001430 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001431 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001432 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1434 if (charcnt == 256) {
1435 vc->vc_hi_font_mask = 0;
1436 } else {
1437 vc->vc_hi_font_mask = 0x100;
1438 if (vc->vc_can_do_color)
1439 vc->vc_complement_mask <<= 1;
1440 }
1441
1442 if (!*svc->vc_uni_pagedir_loc)
1443 con_set_default_unimap(svc);
1444 if (!*vc->vc_uni_pagedir_loc)
1445 con_copy_unimap(vc, svc);
1446
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001447 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1448 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1449 cols /= vc->vc_font.width;
1450 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 if (CON_IS_VISIBLE(vc)) {
1454 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001455 if (softback_buf)
1456 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458}
1459
1460static __inline__ void ywrap_up(struct vc_data *vc, int count)
1461{
1462 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001463 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 struct display *p = &fb_display[vc->vc_num];
1465
1466 p->yscroll += count;
1467 if (p->yscroll >= p->vrows) /* Deal with wrap */
1468 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001469 ops->var.xoffset = 0;
1470 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1471 ops->var.vmode |= FB_VMODE_YWRAP;
1472 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 scrollback_max += count;
1474 if (scrollback_max > scrollback_phys_max)
1475 scrollback_max = scrollback_phys_max;
1476 scrollback_current = 0;
1477}
1478
1479static __inline__ void ywrap_down(struct vc_data *vc, int count)
1480{
1481 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001482 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 struct display *p = &fb_display[vc->vc_num];
1484
1485 p->yscroll -= count;
1486 if (p->yscroll < 0) /* Deal with wrap */
1487 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001488 ops->var.xoffset = 0;
1489 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1490 ops->var.vmode |= FB_VMODE_YWRAP;
1491 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 scrollback_max -= count;
1493 if (scrollback_max < 0)
1494 scrollback_max = 0;
1495 scrollback_current = 0;
1496}
1497
1498static __inline__ void ypan_up(struct vc_data *vc, int count)
1499{
1500 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1501 struct display *p = &fb_display[vc->vc_num];
1502 struct fbcon_ops *ops = info->fbcon_par;
1503
1504 p->yscroll += count;
1505 if (p->yscroll > p->vrows - vc->vc_rows) {
1506 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1507 0, 0, 0, vc->vc_rows, vc->vc_cols);
1508 p->yscroll -= p->vrows - vc->vc_rows;
1509 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001510
1511 ops->var.xoffset = 0;
1512 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1513 ops->var.vmode &= ~FB_VMODE_YWRAP;
1514 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 fbcon_clear_margins(vc, 1);
1516 scrollback_max += count;
1517 if (scrollback_max > scrollback_phys_max)
1518 scrollback_max = scrollback_phys_max;
1519 scrollback_current = 0;
1520}
1521
1522static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1523{
1524 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001525 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 if (p->yscroll > p->vrows - vc->vc_rows) {
1531 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001533 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001534
1535 ops->var.xoffset = 0;
1536 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1537 ops->var.vmode &= ~FB_VMODE_YWRAP;
1538 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 fbcon_clear_margins(vc, 1);
1540 scrollback_max += count;
1541 if (scrollback_max > scrollback_phys_max)
1542 scrollback_max = scrollback_phys_max;
1543 scrollback_current = 0;
1544}
1545
1546static __inline__ void ypan_down(struct vc_data *vc, int count)
1547{
1548 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1549 struct display *p = &fb_display[vc->vc_num];
1550 struct fbcon_ops *ops = info->fbcon_par;
1551
1552 p->yscroll -= count;
1553 if (p->yscroll < 0) {
1554 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1555 0, vc->vc_rows, vc->vc_cols);
1556 p->yscroll += p->vrows - vc->vc_rows;
1557 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001558
1559 ops->var.xoffset = 0;
1560 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1561 ops->var.vmode &= ~FB_VMODE_YWRAP;
1562 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 fbcon_clear_margins(vc, 1);
1564 scrollback_max -= count;
1565 if (scrollback_max < 0)
1566 scrollback_max = 0;
1567 scrollback_current = 0;
1568}
1569
1570static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1571{
1572 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001573 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
1576 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 if (p->yscroll < 0) {
1579 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001581 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001582
1583 ops->var.xoffset = 0;
1584 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1585 ops->var.vmode &= ~FB_VMODE_YWRAP;
1586 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 fbcon_clear_margins(vc, 1);
1588 scrollback_max -= count;
1589 if (scrollback_max < 0)
1590 scrollback_max = 0;
1591 scrollback_current = 0;
1592}
1593
1594static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1595 long delta)
1596{
1597 int count = vc->vc_rows;
1598 unsigned short *d, *s;
1599 unsigned long n;
1600 int line = 0;
1601
1602 d = (u16 *) softback_curr;
1603 if (d == (u16 *) softback_in)
1604 d = (u16 *) vc->vc_origin;
1605 n = softback_curr + delta * vc->vc_size_row;
1606 softback_lines -= delta;
1607 if (delta < 0) {
1608 if (softback_curr < softback_top && n < softback_buf) {
1609 n += softback_end - softback_buf;
1610 if (n < softback_top) {
1611 softback_lines -=
1612 (softback_top - n) / vc->vc_size_row;
1613 n = softback_top;
1614 }
1615 } else if (softback_curr >= softback_top
1616 && n < softback_top) {
1617 softback_lines -=
1618 (softback_top - n) / vc->vc_size_row;
1619 n = softback_top;
1620 }
1621 } else {
1622 if (softback_curr > softback_in && n >= softback_end) {
1623 n += softback_buf - softback_end;
1624 if (n > softback_in) {
1625 n = softback_in;
1626 softback_lines = 0;
1627 }
1628 } else if (softback_curr <= softback_in && n > softback_in) {
1629 n = softback_in;
1630 softback_lines = 0;
1631 }
1632 }
1633 if (n == softback_curr)
1634 return;
1635 softback_curr = n;
1636 s = (u16 *) softback_curr;
1637 if (s == (u16 *) softback_in)
1638 s = (u16 *) vc->vc_origin;
1639 while (count--) {
1640 unsigned short *start;
1641 unsigned short *le;
1642 unsigned short c;
1643 int x = 0;
1644 unsigned short attr = 1;
1645
1646 start = s;
1647 le = advance_row(s, 1);
1648 do {
1649 c = scr_readw(s);
1650 if (attr != (c & 0xff00)) {
1651 attr = c & 0xff00;
1652 if (s > start) {
1653 fbcon_putcs(vc, start, s - start,
1654 line, x);
1655 x += s - start;
1656 start = s;
1657 }
1658 }
1659 if (c == scr_readw(d)) {
1660 if (s > start) {
1661 fbcon_putcs(vc, start, s - start,
1662 line, x);
1663 x += s - start + 1;
1664 start = s + 1;
1665 } else {
1666 x++;
1667 start++;
1668 }
1669 }
1670 s++;
1671 d++;
1672 } while (s < le);
1673 if (s > start)
1674 fbcon_putcs(vc, start, s - start, line, x);
1675 line++;
1676 if (d == (u16 *) softback_end)
1677 d = (u16 *) softback_buf;
1678 if (d == (u16 *) softback_in)
1679 d = (u16 *) vc->vc_origin;
1680 if (s == (u16 *) softback_end)
1681 s = (u16 *) softback_buf;
1682 if (s == (u16 *) softback_in)
1683 s = (u16 *) vc->vc_origin;
1684 }
1685}
1686
1687static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1688 int line, int count, int dy)
1689{
1690 unsigned short *s = (unsigned short *)
1691 (vc->vc_origin + vc->vc_size_row * line);
1692
1693 while (count--) {
1694 unsigned short *start = s;
1695 unsigned short *le = advance_row(s, 1);
1696 unsigned short c;
1697 int x = 0;
1698 unsigned short attr = 1;
1699
1700 do {
1701 c = scr_readw(s);
1702 if (attr != (c & 0xff00)) {
1703 attr = c & 0xff00;
1704 if (s > start) {
1705 fbcon_putcs(vc, start, s - start,
1706 dy, x);
1707 x += s - start;
1708 start = s;
1709 }
1710 }
1711 console_conditional_schedule();
1712 s++;
1713 } while (s < le);
1714 if (s > start)
1715 fbcon_putcs(vc, start, s - start, dy, x);
1716 console_conditional_schedule();
1717 dy++;
1718 }
1719}
1720
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001721static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1722 struct display *p, int line, int count, int ycount)
1723{
1724 int offset = ycount * vc->vc_cols;
1725 unsigned short *d = (unsigned short *)
1726 (vc->vc_origin + vc->vc_size_row * line);
1727 unsigned short *s = d + offset;
1728 struct fbcon_ops *ops = info->fbcon_par;
1729
1730 while (count--) {
1731 unsigned short *start = s;
1732 unsigned short *le = advance_row(s, 1);
1733 unsigned short c;
1734 int x = 0;
1735
1736 do {
1737 c = scr_readw(s);
1738
1739 if (c == scr_readw(d)) {
1740 if (s > start) {
1741 ops->bmove(vc, info, line + ycount, x,
1742 line, x, 1, s-start);
1743 x += s - start + 1;
1744 start = s + 1;
1745 } else {
1746 x++;
1747 start++;
1748 }
1749 }
1750
1751 scr_writew(c, d);
1752 console_conditional_schedule();
1753 s++;
1754 d++;
1755 } while (s < le);
1756 if (s > start)
1757 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1758 s-start);
1759 console_conditional_schedule();
1760 if (ycount > 0)
1761 line++;
1762 else {
1763 line--;
1764 /* NOTE: We subtract two lines from these pointers */
1765 s -= vc->vc_size_row;
1766 d -= vc->vc_size_row;
1767 }
1768 }
1769}
1770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771static void fbcon_redraw(struct vc_data *vc, struct display *p,
1772 int line, int count, int offset)
1773{
1774 unsigned short *d = (unsigned short *)
1775 (vc->vc_origin + vc->vc_size_row * line);
1776 unsigned short *s = d + offset;
1777
1778 while (count--) {
1779 unsigned short *start = s;
1780 unsigned short *le = advance_row(s, 1);
1781 unsigned short c;
1782 int x = 0;
1783 unsigned short attr = 1;
1784
1785 do {
1786 c = scr_readw(s);
1787 if (attr != (c & 0xff00)) {
1788 attr = c & 0xff00;
1789 if (s > start) {
1790 fbcon_putcs(vc, start, s - start,
1791 line, x);
1792 x += s - start;
1793 start = s;
1794 }
1795 }
1796 if (c == scr_readw(d)) {
1797 if (s > start) {
1798 fbcon_putcs(vc, start, s - start,
1799 line, x);
1800 x += s - start + 1;
1801 start = s + 1;
1802 } else {
1803 x++;
1804 start++;
1805 }
1806 }
1807 scr_writew(c, d);
1808 console_conditional_schedule();
1809 s++;
1810 d++;
1811 } while (s < le);
1812 if (s > start)
1813 fbcon_putcs(vc, start, s - start, line, x);
1814 console_conditional_schedule();
1815 if (offset > 0)
1816 line++;
1817 else {
1818 line--;
1819 /* NOTE: We subtract two lines from these pointers */
1820 s -= vc->vc_size_row;
1821 d -= vc->vc_size_row;
1822 }
1823 }
1824}
1825
1826static inline void fbcon_softback_note(struct vc_data *vc, int t,
1827 int count)
1828{
1829 unsigned short *p;
1830
1831 if (vc->vc_num != fg_console)
1832 return;
1833 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1834
1835 while (count) {
1836 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1837 count--;
1838 p = advance_row(p, 1);
1839 softback_in += vc->vc_size_row;
1840 if (softback_in == softback_end)
1841 softback_in = softback_buf;
1842 if (softback_in == softback_top) {
1843 softback_top += vc->vc_size_row;
1844 if (softback_top == softback_end)
1845 softback_top = softback_buf;
1846 }
1847 }
1848 softback_curr = softback_in;
1849}
1850
1851static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1852 int count)
1853{
1854 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1855 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1857
1858 if (fbcon_is_inactive(vc, info))
1859 return -EINVAL;
1860
1861 fbcon_cursor(vc, CM_ERASE);
1862
1863 /*
1864 * ++Geert: Only use ywrap/ypan if the console is in text mode
1865 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1866 * whole screen (prevents flicker).
1867 */
1868
1869 switch (dir) {
1870 case SM_UP:
1871 if (count > vc->vc_rows) /* Maximum realistic size */
1872 count = vc->vc_rows;
1873 if (softback_top)
1874 fbcon_softback_note(vc, t, count);
1875 if (logo_shown >= 0)
1876 goto redraw_up;
1877 switch (p->scrollmode) {
1878 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001879 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1880 count);
1881 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1882 scr_memsetw((unsigned short *) (vc->vc_origin +
1883 vc->vc_size_row *
1884 (b - count)),
1885 vc->vc_video_erase_char,
1886 vc->vc_size_row * count);
1887 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 break;
1889
1890 case SCROLL_WRAP_MOVE:
1891 if (b - t - count > 3 * vc->vc_rows >> 2) {
1892 if (t > 0)
1893 fbcon_bmove(vc, 0, 0, count, 0, t,
1894 vc->vc_cols);
1895 ywrap_up(vc, count);
1896 if (vc->vc_rows - b > 0)
1897 fbcon_bmove(vc, b - count, 0, b, 0,
1898 vc->vc_rows - b,
1899 vc->vc_cols);
1900 } else if (info->flags & FBINFO_READS_FAST)
1901 fbcon_bmove(vc, t + count, 0, t, 0,
1902 b - t - count, vc->vc_cols);
1903 else
1904 goto redraw_up;
1905 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1906 break;
1907
1908 case SCROLL_PAN_REDRAW:
1909 if ((p->yscroll + count <=
1910 2 * (p->vrows - vc->vc_rows))
1911 && ((!scroll_partial && (b - t == vc->vc_rows))
1912 || (scroll_partial
1913 && (b - t - count >
1914 3 * vc->vc_rows >> 2)))) {
1915 if (t > 0)
1916 fbcon_redraw_move(vc, p, 0, t, count);
1917 ypan_up_redraw(vc, t, count);
1918 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001919 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 vc->vc_rows - b, b);
1921 } else
1922 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1923 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1924 break;
1925
1926 case SCROLL_PAN_MOVE:
1927 if ((p->yscroll + count <=
1928 2 * (p->vrows - vc->vc_rows))
1929 && ((!scroll_partial && (b - t == vc->vc_rows))
1930 || (scroll_partial
1931 && (b - t - count >
1932 3 * vc->vc_rows >> 2)))) {
1933 if (t > 0)
1934 fbcon_bmove(vc, 0, 0, count, 0, t,
1935 vc->vc_cols);
1936 ypan_up(vc, count);
1937 if (vc->vc_rows - b > 0)
1938 fbcon_bmove(vc, b - count, 0, b, 0,
1939 vc->vc_rows - b,
1940 vc->vc_cols);
1941 } else if (info->flags & FBINFO_READS_FAST)
1942 fbcon_bmove(vc, t + count, 0, t, 0,
1943 b - t - count, vc->vc_cols);
1944 else
1945 goto redraw_up;
1946 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1947 break;
1948
1949 case SCROLL_REDRAW:
1950 redraw_up:
1951 fbcon_redraw(vc, p, t, b - t - count,
1952 count * vc->vc_cols);
1953 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1954 scr_memsetw((unsigned short *) (vc->vc_origin +
1955 vc->vc_size_row *
1956 (b - count)),
1957 vc->vc_video_erase_char,
1958 vc->vc_size_row * count);
1959 return 1;
1960 }
1961 break;
1962
1963 case SM_DOWN:
1964 if (count > vc->vc_rows) /* Maximum realistic size */
1965 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001966 if (logo_shown >= 0)
1967 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 switch (p->scrollmode) {
1969 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001970 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1971 -count);
1972 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1973 scr_memsetw((unsigned short *) (vc->vc_origin +
1974 vc->vc_size_row *
1975 t),
1976 vc->vc_video_erase_char,
1977 vc->vc_size_row * count);
1978 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 break;
1980
1981 case SCROLL_WRAP_MOVE:
1982 if (b - t - count > 3 * vc->vc_rows >> 2) {
1983 if (vc->vc_rows - b > 0)
1984 fbcon_bmove(vc, b, 0, b - count, 0,
1985 vc->vc_rows - b,
1986 vc->vc_cols);
1987 ywrap_down(vc, count);
1988 if (t > 0)
1989 fbcon_bmove(vc, count, 0, 0, 0, t,
1990 vc->vc_cols);
1991 } else if (info->flags & FBINFO_READS_FAST)
1992 fbcon_bmove(vc, t, 0, t + count, 0,
1993 b - t - count, vc->vc_cols);
1994 else
1995 goto redraw_down;
1996 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1997 break;
1998
1999 case SCROLL_PAN_MOVE:
2000 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2001 && ((!scroll_partial && (b - t == vc->vc_rows))
2002 || (scroll_partial
2003 && (b - t - count >
2004 3 * vc->vc_rows >> 2)))) {
2005 if (vc->vc_rows - b > 0)
2006 fbcon_bmove(vc, b, 0, b - count, 0,
2007 vc->vc_rows - b,
2008 vc->vc_cols);
2009 ypan_down(vc, count);
2010 if (t > 0)
2011 fbcon_bmove(vc, count, 0, 0, 0, t,
2012 vc->vc_cols);
2013 } else if (info->flags & FBINFO_READS_FAST)
2014 fbcon_bmove(vc, t, 0, t + count, 0,
2015 b - t - count, vc->vc_cols);
2016 else
2017 goto redraw_down;
2018 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2019 break;
2020
2021 case SCROLL_PAN_REDRAW:
2022 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2023 && ((!scroll_partial && (b - t == vc->vc_rows))
2024 || (scroll_partial
2025 && (b - t - count >
2026 3 * vc->vc_rows >> 2)))) {
2027 if (vc->vc_rows - b > 0)
2028 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2029 b - count);
2030 ypan_down_redraw(vc, t, count);
2031 if (t > 0)
2032 fbcon_redraw_move(vc, p, count, t, 0);
2033 } else
2034 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2035 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2036 break;
2037
2038 case SCROLL_REDRAW:
2039 redraw_down:
2040 fbcon_redraw(vc, p, b - 1, b - t - count,
2041 -count * vc->vc_cols);
2042 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2043 scr_memsetw((unsigned short *) (vc->vc_origin +
2044 vc->vc_size_row *
2045 t),
2046 vc->vc_video_erase_char,
2047 vc->vc_size_row * count);
2048 return 1;
2049 }
2050 }
2051 return 0;
2052}
2053
2054
2055static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2056 int height, int width)
2057{
2058 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2059 struct display *p = &fb_display[vc->vc_num];
2060
2061 if (fbcon_is_inactive(vc, info))
2062 return;
2063
2064 if (!width || !height)
2065 return;
2066
2067 /* Split blits that cross physical y_wrap case.
2068 * Pathological case involves 4 blits, better to use recursive
2069 * code rather than unrolled case
2070 *
2071 * Recursive invocations don't need to erase the cursor over and
2072 * over again, so we use fbcon_bmove_rec()
2073 */
2074 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2075 p->vrows - p->yscroll);
2076}
2077
2078static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2079 int dy, int dx, int height, int width, u_int y_break)
2080{
2081 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2082 struct fbcon_ops *ops = info->fbcon_par;
2083 u_int b;
2084
2085 if (sy < y_break && sy + height > y_break) {
2086 b = y_break - sy;
2087 if (dy < sy) { /* Avoid trashing self */
2088 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2089 y_break);
2090 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2091 height - b, width, y_break);
2092 } else {
2093 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2094 height - b, width, y_break);
2095 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2096 y_break);
2097 }
2098 return;
2099 }
2100
2101 if (dy < y_break && dy + height > y_break) {
2102 b = y_break - dy;
2103 if (dy < sy) { /* Avoid trashing self */
2104 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2105 y_break);
2106 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2107 height - b, width, y_break);
2108 } else {
2109 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2110 height - b, width, y_break);
2111 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2112 y_break);
2113 }
2114 return;
2115 }
2116 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2117 height, width);
2118}
2119
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002120static __inline__ void updatescrollmode(struct display *p,
2121 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct vc_data *vc)
2123{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002124 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 int fh = vc->vc_font.height;
2126 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002127 u16 t = 0;
2128 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2129 info->fix.xpanstep);
2130 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2131 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2132 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2133 info->var.xres_virtual);
2134 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2135 divides(ypan, vc->vc_font.height) && vyres > yres;
2136 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2137 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002138 divides(vc->vc_font.height, vyres) &&
2139 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002141 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2142 !(cap & FBINFO_HWACCEL_DISABLED);
2143 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2144 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002146 p->vrows = vyres/fh;
2147 if (yres > (fh * (vc->vc_rows + 1)))
2148 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2149 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 p->vrows--;
2151
2152 if (good_wrap || good_pan) {
2153 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002154 p->scrollmode = good_wrap ?
2155 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 else
2157 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2158 SCROLL_PAN_REDRAW;
2159 } else {
2160 if (reading_fast || (fast_copyarea && !fast_imageblit))
2161 p->scrollmode = SCROLL_MOVE;
2162 else
2163 p->scrollmode = SCROLL_REDRAW;
2164 }
2165}
2166
2167static int fbcon_resize(struct vc_data *vc, unsigned int width,
2168 unsigned int height)
2169{
2170 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002171 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct display *p = &fb_display[vc->vc_num];
2173 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002174 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002176 virt_w = FBCON_SWAP(ops->rotate, width, height);
2177 virt_h = FBCON_SWAP(ops->rotate, height, width);
2178 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2179 vc->vc_font.height);
2180 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2181 vc->vc_font.width);
2182 var.xres = virt_w * virt_fw;
2183 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 x_diff = info->var.xres - var.xres;
2185 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002186 if (x_diff < 0 || x_diff > virt_fw ||
2187 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002188 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2191 mode = fb_find_best_mode(&var, &info->modelist);
2192 if (mode == NULL)
2193 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002194 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002196
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002197 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
2200 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2201 if (CON_IS_VISIBLE(vc)) {
2202 var.activate = FB_ACTIVATE_NOW |
2203 FB_ACTIVATE_FORCE;
2204 fb_set_var(info, &var);
2205 }
2206 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002207 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 }
2209 updatescrollmode(p, info, vc);
2210 return 0;
2211}
2212
2213static int fbcon_switch(struct vc_data *vc)
2214{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002215 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002216 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 struct display *p = &fb_display[vc->vc_num];
2218 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002219 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
2221 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002222 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 if (softback_lines)
2226 fbcon_set_origin(vc);
2227 softback_top = softback_curr = softback_in = softback_buf;
2228 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002229 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 }
2231
2232 if (logo_shown >= 0) {
2233 struct vc_data *conp2 = vc_cons[logo_shown].d;
2234
2235 if (conp2->vc_top == logo_lines
2236 && conp2->vc_bottom == conp2->vc_rows)
2237 conp2->vc_top = 0;
2238 logo_shown = FBCON_LOGO_CANSHOW;
2239 }
2240
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002241 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002242 if (prev_console != -1)
2243 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 /*
2245 * FIXME: If we have multiple fbdev's loaded, we need to
2246 * update all info->currcon. Perhaps, we can place this
2247 * in a centralized structure, but this might break some
2248 * drivers.
2249 *
2250 * info->currcon = vc->vc_num;
2251 */
2252 for (i = 0; i < FB_MAX; i++) {
2253 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002254 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002256 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 }
2258 }
2259 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2260 display_to_var(&var, p);
2261 var.activate = FB_ACTIVATE_NOW;
2262
2263 /*
2264 * make sure we don't unnecessarily trip the memcmp()
2265 * in fb_set_var()
2266 */
2267 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002268 var.yoffset = info->var.yoffset;
2269 var.xoffset = info->var.xoffset;
2270 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002272 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
Knut Petersen39942fd2005-12-12 22:17:19 -08002274 if (old_info != NULL && (old_info != info ||
2275 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002276 if (info->fbops->fb_set_par)
2277 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002278
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002279 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002280 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002283 if (fbcon_is_inactive(vc, info) ||
2284 ops->blank_state != FB_BLANK_UNBLANK)
2285 fbcon_del_cursor_timer(info);
2286 else
2287 fbcon_add_cursor_timer(info);
2288
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002289 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002290 ops->cursor_reset = 1;
2291
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002292 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002293 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002294 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002297 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002299
2300 if (p->userfont)
2301 charcnt = FNTCHARCNT(vc->vc_font.data);
2302
2303 if (charcnt > 256)
2304 vc->vc_complement_mask <<= 1;
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 updatescrollmode(p, info, vc);
2307
2308 switch (p->scrollmode) {
2309 case SCROLL_WRAP_MOVE:
2310 scrollback_phys_max = p->vrows - vc->vc_rows;
2311 break;
2312 case SCROLL_PAN_MOVE:
2313 case SCROLL_PAN_REDRAW:
2314 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2315 if (scrollback_phys_max < 0)
2316 scrollback_phys_max = 0;
2317 break;
2318 default:
2319 scrollback_phys_max = 0;
2320 break;
2321 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002322
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 scrollback_max = 0;
2324 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002325
2326 if (!fbcon_is_inactive(vc, info)) {
2327 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2328 ops->update_start(info);
2329 }
2330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 fbcon_set_palette(vc, color_table);
2332 fbcon_clear_margins(vc, 0);
2333
2334 if (logo_shown == FBCON_LOGO_DRAW) {
2335
2336 logo_shown = fg_console;
2337 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002338 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 update_region(vc,
2340 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2341 vc->vc_size_row * (vc->vc_bottom -
2342 vc->vc_top) / 2);
2343 return 0;
2344 }
2345 return 1;
2346}
2347
2348static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2349 int blank)
2350{
Richard Purdie994efac2007-02-09 09:46:45 +00002351 struct fb_event event;
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 if (blank) {
2354 unsigned short charmask = vc->vc_hi_font_mask ?
2355 0x1ff : 0xff;
2356 unsigned short oldc;
2357
2358 oldc = vc->vc_video_erase_char;
2359 vc->vc_video_erase_char &= charmask;
2360 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2361 vc->vc_video_erase_char = oldc;
2362 }
Richard Purdie994efac2007-02-09 09:46:45 +00002363
2364
2365 event.info = info;
2366 event.data = &blank;
2367 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368}
2369
2370static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2371{
2372 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2373 struct fbcon_ops *ops = info->fbcon_par;
2374
2375 if (mode_switch) {
2376 struct fb_var_screeninfo var = info->var;
2377
2378 ops->graphics = 1;
2379
2380 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002381 if (info->fbops->fb_save_state)
2382 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2384 fb_set_var(info, &var);
2385 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002386 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002387 } else if (info->fbops->fb_restore_state)
2388 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 }
2390
2391 if (!fbcon_is_inactive(vc, info)) {
2392 if (ops->blank_state != blank) {
2393 ops->blank_state = blank;
2394 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2395 ops->cursor_flash = (!blank);
2396
2397 if (fb_blank(info, blank))
2398 fbcon_generic_blank(vc, info, blank);
2399 }
2400
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002401 if (!blank)
2402 update_screen(vc);
2403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002405 if (fbcon_is_inactive(vc, info) ||
2406 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002407 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002408 else
2409 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002410
2411 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
2413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2415{
2416 u8 *fontdata = vc->vc_font.data;
2417 u8 *data = font->data;
2418 int i, j;
2419
2420 font->width = vc->vc_font.width;
2421 font->height = vc->vc_font.height;
2422 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2423 if (!font->data)
2424 return 0;
2425
2426 if (font->width <= 8) {
2427 j = vc->vc_font.height;
2428 for (i = 0; i < font->charcount; i++) {
2429 memcpy(data, fontdata, j);
2430 memset(data + j, 0, 32 - j);
2431 data += 32;
2432 fontdata += j;
2433 }
2434 } else if (font->width <= 16) {
2435 j = vc->vc_font.height * 2;
2436 for (i = 0; i < font->charcount; i++) {
2437 memcpy(data, fontdata, j);
2438 memset(data + j, 0, 64 - j);
2439 data += 64;
2440 fontdata += j;
2441 }
2442 } else if (font->width <= 24) {
2443 for (i = 0; i < font->charcount; i++) {
2444 for (j = 0; j < vc->vc_font.height; j++) {
2445 *data++ = fontdata[0];
2446 *data++ = fontdata[1];
2447 *data++ = fontdata[2];
2448 fontdata += sizeof(u32);
2449 }
2450 memset(data, 0, 3 * (32 - j));
2451 data += 3 * (32 - j);
2452 }
2453 } else {
2454 j = vc->vc_font.height * 4;
2455 for (i = 0; i < font->charcount; i++) {
2456 memcpy(data, fontdata, j);
2457 memset(data + j, 0, 128 - j);
2458 data += 128;
2459 fontdata += j;
2460 }
2461 }
2462 return 0;
2463}
2464
2465static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002466 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
2468 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002469 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 struct display *p = &fb_display[vc->vc_num];
2471 int resize;
2472 int cnt;
2473 char *old_data = NULL;
2474
2475 if (CON_IS_VISIBLE(vc) && softback_lines)
2476 fbcon_set_origin(vc);
2477
2478 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2479 if (p->userfont)
2480 old_data = vc->vc_font.data;
2481 if (userfont)
2482 cnt = FNTCHARCNT(data);
2483 else
2484 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002485 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 if ((p->userfont = userfont))
2487 REFCOUNT(data)++;
2488 vc->vc_font.width = w;
2489 vc->vc_font.height = h;
2490 if (vc->vc_hi_font_mask && cnt == 256) {
2491 vc->vc_hi_font_mask = 0;
2492 if (vc->vc_can_do_color) {
2493 vc->vc_complement_mask >>= 1;
2494 vc->vc_s_complement_mask >>= 1;
2495 }
2496
2497 /* ++Edmund: reorder the attribute bits */
2498 if (vc->vc_can_do_color) {
2499 unsigned short *cp =
2500 (unsigned short *) vc->vc_origin;
2501 int count = vc->vc_screenbuf_size / 2;
2502 unsigned short c;
2503 for (; count > 0; count--, cp++) {
2504 c = scr_readw(cp);
2505 scr_writew(((c & 0xfe00) >> 1) |
2506 (c & 0xff), cp);
2507 }
2508 c = vc->vc_video_erase_char;
2509 vc->vc_video_erase_char =
2510 ((c & 0xfe00) >> 1) | (c & 0xff);
2511 vc->vc_attr >>= 1;
2512 }
2513 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2514 vc->vc_hi_font_mask = 0x100;
2515 if (vc->vc_can_do_color) {
2516 vc->vc_complement_mask <<= 1;
2517 vc->vc_s_complement_mask <<= 1;
2518 }
2519
2520 /* ++Edmund: reorder the attribute bits */
2521 {
2522 unsigned short *cp =
2523 (unsigned short *) vc->vc_origin;
2524 int count = vc->vc_screenbuf_size / 2;
2525 unsigned short c;
2526 for (; count > 0; count--, cp++) {
2527 unsigned short newc;
2528 c = scr_readw(cp);
2529 if (vc->vc_can_do_color)
2530 newc =
2531 ((c & 0xff00) << 1) | (c &
2532 0xff);
2533 else
2534 newc = c & ~0x100;
2535 scr_writew(newc, cp);
2536 }
2537 c = vc->vc_video_erase_char;
2538 if (vc->vc_can_do_color) {
2539 vc->vc_video_erase_char =
2540 ((c & 0xff00) << 1) | (c & 0xff);
2541 vc->vc_attr <<= 1;
2542 } else
2543 vc->vc_video_erase_char = c & ~0x100;
2544 }
2545
2546 }
2547
2548 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002549 int cols, rows;
2550
2551 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2552 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2553 cols /= w;
2554 rows /= h;
2555 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002556 if (CON_IS_VISIBLE(vc) && softback_buf)
2557 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 } else if (CON_IS_VISIBLE(vc)
2559 && vc->vc_mode == KD_TEXT) {
2560 fbcon_clear_margins(vc, 0);
2561 update_screen(vc);
2562 }
2563
2564 if (old_data && (--REFCOUNT(old_data) == 0))
2565 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2566 return 0;
2567}
2568
2569static int fbcon_copy_font(struct vc_data *vc, int con)
2570{
2571 struct display *od = &fb_display[con];
2572 struct console_font *f = &vc->vc_font;
2573
2574 if (od->fontdata == f->data)
2575 return 0; /* already the same font... */
2576 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2577}
2578
2579/*
2580 * User asked to set font; we are guaranteed that
2581 * a) width and height are in range 1..32
2582 * b) charcount does not exceed 512
2583 * but lets not assume that, since someone might someday want to use larger
2584 * fonts. And charcount of 512 is small for unicode support.
2585 *
2586 * However, user space gives the font in 32 rows , regardless of
2587 * actual font height. So a new API is needed if support for larger fonts
2588 * is ever implemented.
2589 */
2590
2591static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2592{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002593 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 unsigned charcount = font->charcount;
2595 int w = font->width;
2596 int h = font->height;
2597 int size;
2598 int i, csum;
2599 u8 *new_data, *data = font->data;
2600 int pitch = (font->width+7) >> 3;
2601
2602 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2603 * If not this check should be changed to charcount < 256 */
2604 if (charcount != 256 && charcount != 512)
2605 return -EINVAL;
2606
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002607 /* Make sure drawing engine can handle the font */
2608 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2609 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2610 return -EINVAL;
2611
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002612 /* Make sure driver can handle the font length */
2613 if (fbcon_invalid_charcount(info, charcount))
2614 return -EINVAL;
2615
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 size = h * pitch * charcount;
2617
2618 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2619
2620 if (!new_data)
2621 return -ENOMEM;
2622
2623 new_data += FONT_EXTRA_WORDS * sizeof(int);
2624 FNTSIZE(new_data) = size;
2625 FNTCHARCNT(new_data) = charcount;
2626 REFCOUNT(new_data) = 0; /* usage counter */
2627 for (i=0; i< charcount; i++) {
2628 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2629 }
2630
2631 /* Since linux has a nice crc32 function use it for counting font
2632 * checksums. */
2633 csum = crc32(0, new_data, size);
2634
2635 FNTSUM(new_data) = csum;
2636 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002637 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 struct vc_data *tmp = vc_cons[i].d;
2639
2640 if (fb_display[i].userfont &&
2641 fb_display[i].fontdata &&
2642 FNTSUM(fb_display[i].fontdata) == csum &&
2643 FNTSIZE(fb_display[i].fontdata) == size &&
2644 tmp->vc_font.width == w &&
2645 !memcmp(fb_display[i].fontdata, new_data, size)) {
2646 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002647 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 break;
2649 }
2650 }
2651 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2652}
2653
2654static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2655{
2656 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002657 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
2659 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002660 f = get_default_font(info->var.xres, info->var.yres,
2661 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 else if (!(f = find_font(name)))
2663 return -ENOENT;
2664
2665 font->width = f->width;
2666 font->height = f->height;
2667 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2668}
2669
2670static u16 palette_red[16];
2671static u16 palette_green[16];
2672static u16 palette_blue[16];
2673
2674static struct fb_cmap palette_cmap = {
2675 0, 16, palette_red, palette_green, palette_blue, NULL
2676};
2677
2678static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2679{
2680 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2681 int i, j, k, depth;
2682 u8 val;
2683
2684 if (fbcon_is_inactive(vc, info))
2685 return -EINVAL;
2686
2687 if (!CON_IS_VISIBLE(vc))
2688 return 0;
2689
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002690 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 if (depth > 3) {
2692 for (i = j = 0; i < 16; i++) {
2693 k = table[i];
2694 val = vc->vc_palette[j++];
2695 palette_red[k] = (val << 8) | val;
2696 val = vc->vc_palette[j++];
2697 palette_green[k] = (val << 8) | val;
2698 val = vc->vc_palette[j++];
2699 palette_blue[k] = (val << 8) | val;
2700 }
2701 palette_cmap.len = 16;
2702 palette_cmap.start = 0;
2703 /*
2704 * If framebuffer is capable of less than 16 colors,
2705 * use default palette of fbcon.
2706 */
2707 } else
2708 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2709
2710 return fb_set_cmap(&palette_cmap, info);
2711}
2712
2713static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2714{
2715 unsigned long p;
2716 int line;
2717
2718 if (vc->vc_num != fg_console || !softback_lines)
2719 return (u16 *) (vc->vc_origin + offset);
2720 line = offset / vc->vc_size_row;
2721 if (line >= softback_lines)
2722 return (u16 *) (vc->vc_origin + offset -
2723 softback_lines * vc->vc_size_row);
2724 p = softback_curr + offset;
2725 if (p >= softback_end)
2726 p += softback_buf - softback_end;
2727 return (u16 *) p;
2728}
2729
2730static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2731 int *px, int *py)
2732{
2733 unsigned long ret;
2734 int x, y;
2735
2736 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2737 unsigned long offset = (pos - vc->vc_origin) / 2;
2738
2739 x = offset % vc->vc_cols;
2740 y = offset / vc->vc_cols;
2741 if (vc->vc_num == fg_console)
2742 y += softback_lines;
2743 ret = pos + (vc->vc_cols - x) * 2;
2744 } else if (vc->vc_num == fg_console && softback_lines) {
2745 unsigned long offset = pos - softback_curr;
2746
2747 if (pos < softback_curr)
2748 offset += softback_end - softback_buf;
2749 offset /= 2;
2750 x = offset % vc->vc_cols;
2751 y = offset / vc->vc_cols;
2752 ret = pos + (vc->vc_cols - x) * 2;
2753 if (ret == softback_end)
2754 ret = softback_buf;
2755 if (ret == softback_in)
2756 ret = vc->vc_origin;
2757 } else {
2758 /* Should not happen */
2759 x = y = 0;
2760 ret = vc->vc_origin;
2761 }
2762 if (px)
2763 *px = x;
2764 if (py)
2765 *py = y;
2766 return ret;
2767}
2768
2769/* As we might be inside of softback, we may work with non-contiguous buffer,
2770 that's why we have to use a separate routine. */
2771static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2772{
2773 while (cnt--) {
2774 u16 a = scr_readw(p);
2775 if (!vc->vc_can_do_color)
2776 a ^= 0x0800;
2777 else if (vc->vc_hi_font_mask == 0x100)
2778 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2779 (((a) & 0x0e00) << 4);
2780 else
2781 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2782 (((a) & 0x0700) << 4);
2783 scr_writew(a, p++);
2784 if (p == (u16 *) softback_end)
2785 p = (u16 *) softback_buf;
2786 if (p == (u16 *) softback_in)
2787 p = (u16 *) vc->vc_origin;
2788 }
2789}
2790
2791static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2792{
2793 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002794 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 struct display *p = &fb_display[fg_console];
2796 int offset, limit, scrollback_old;
2797
2798 if (softback_top) {
2799 if (vc->vc_num != fg_console)
2800 return 0;
2801 if (vc->vc_mode != KD_TEXT || !lines)
2802 return 0;
2803 if (logo_shown >= 0) {
2804 struct vc_data *conp2 = vc_cons[logo_shown].d;
2805
2806 if (conp2->vc_top == logo_lines
2807 && conp2->vc_bottom == conp2->vc_rows)
2808 conp2->vc_top = 0;
2809 if (logo_shown == vc->vc_num) {
2810 unsigned long p, q;
2811 int i;
2812
2813 p = softback_in;
2814 q = vc->vc_origin +
2815 logo_lines * vc->vc_size_row;
2816 for (i = 0; i < logo_lines; i++) {
2817 if (p == softback_top)
2818 break;
2819 if (p == softback_buf)
2820 p = softback_end;
2821 p -= vc->vc_size_row;
2822 q -= vc->vc_size_row;
2823 scr_memcpyw((u16 *) q, (u16 *) p,
2824 vc->vc_size_row);
2825 }
David Hollister308af922006-05-30 21:25:36 -07002826 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 update_region(vc, vc->vc_origin,
2828 logo_lines * vc->vc_cols);
2829 }
2830 logo_shown = FBCON_LOGO_CANSHOW;
2831 }
2832 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2833 fbcon_redraw_softback(vc, p, lines);
2834 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2835 return 0;
2836 }
2837
2838 if (!scrollback_phys_max)
2839 return -ENOSYS;
2840
2841 scrollback_old = scrollback_current;
2842 scrollback_current -= lines;
2843 if (scrollback_current < 0)
2844 scrollback_current = 0;
2845 else if (scrollback_current > scrollback_max)
2846 scrollback_current = scrollback_max;
2847 if (scrollback_current == scrollback_old)
2848 return 0;
2849
2850 if (fbcon_is_inactive(vc, info))
2851 return 0;
2852
2853 fbcon_cursor(vc, CM_ERASE);
2854
2855 offset = p->yscroll - scrollback_current;
2856 limit = p->vrows;
2857 switch (p->scrollmode) {
2858 case SCROLL_WRAP_MOVE:
2859 info->var.vmode |= FB_VMODE_YWRAP;
2860 break;
2861 case SCROLL_PAN_MOVE:
2862 case SCROLL_PAN_REDRAW:
2863 limit -= vc->vc_rows;
2864 info->var.vmode &= ~FB_VMODE_YWRAP;
2865 break;
2866 }
2867 if (offset < 0)
2868 offset += limit;
2869 else if (offset >= limit)
2870 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002871
2872 ops->var.xoffset = 0;
2873 ops->var.yoffset = offset * vc->vc_font.height;
2874 ops->update_start(info);
2875
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 if (!scrollback_current)
2877 fbcon_cursor(vc, CM_DRAW);
2878 return 0;
2879}
2880
2881static int fbcon_set_origin(struct vc_data *vc)
2882{
2883 if (softback_lines)
2884 fbcon_scrolldelta(vc, softback_lines);
2885 return 0;
2886}
2887
2888static void fbcon_suspended(struct fb_info *info)
2889{
2890 struct vc_data *vc = NULL;
2891 struct fbcon_ops *ops = info->fbcon_par;
2892
2893 if (!ops || ops->currcon < 0)
2894 return;
2895 vc = vc_cons[ops->currcon].d;
2896
2897 /* Clear cursor, restore saved data */
2898 fbcon_cursor(vc, CM_ERASE);
2899}
2900
2901static void fbcon_resumed(struct fb_info *info)
2902{
2903 struct vc_data *vc;
2904 struct fbcon_ops *ops = info->fbcon_par;
2905
2906 if (!ops || ops->currcon < 0)
2907 return;
2908 vc = vc_cons[ops->currcon].d;
2909
2910 update_screen(vc);
2911}
2912
2913static void fbcon_modechanged(struct fb_info *info)
2914{
2915 struct fbcon_ops *ops = info->fbcon_par;
2916 struct vc_data *vc;
2917 struct display *p;
2918 int rows, cols;
2919
2920 if (!ops || ops->currcon < 0)
2921 return;
2922 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002923 if (vc->vc_mode != KD_TEXT ||
2924 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 return;
2926
2927 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002928 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929
2930 if (CON_IS_VISIBLE(vc)) {
2931 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002932 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2933 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2934 cols /= vc->vc_font.width;
2935 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 vc_resize(vc, cols, rows);
2937 updatescrollmode(p, info, vc);
2938 scrollback_max = 0;
2939 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002940
2941 if (!fbcon_is_inactive(vc, info)) {
2942 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2943 ops->update_start(info);
2944 }
2945
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 fbcon_set_palette(vc, color_table);
2947 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002948 if (softback_buf)
2949 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 }
2951}
2952
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002953static void fbcon_set_all_vcs(struct fb_info *info)
2954{
2955 struct fbcon_ops *ops = info->fbcon_par;
2956 struct vc_data *vc;
2957 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002958 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002959
2960 if (!ops || ops->currcon < 0)
2961 return;
2962
Antonino A. Daplase614b182006-06-26 00:27:09 -07002963 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002964 vc = vc_cons[i].d;
2965 if (!vc || vc->vc_mode != KD_TEXT ||
2966 registered_fb[con2fb_map[i]] != info)
2967 continue;
2968
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002969 if (CON_IS_VISIBLE(vc)) {
2970 fg = i;
2971 continue;
2972 }
2973
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002974 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002975 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002976 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002977 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2978 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002979 cols /= vc->vc_font.width;
2980 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002981 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002982 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002983
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002984 if (fg != -1)
2985 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002986}
2987
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988static int fbcon_mode_deleted(struct fb_info *info,
2989 struct fb_videomode *mode)
2990{
2991 struct fb_info *fb_info;
2992 struct display *p;
2993 int i, j, found = 0;
2994
2995 /* before deletion, ensure that mode is not in use */
2996 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2997 j = con2fb_map[i];
2998 if (j == -1)
2999 continue;
3000 fb_info = registered_fb[j];
3001 if (fb_info != info)
3002 continue;
3003 p = &fb_display[i];
3004 if (!p || !p->mode)
3005 continue;
3006 if (fb_mode_is_equal(p->mode, mode)) {
3007 found = 1;
3008 break;
3009 }
3010 }
3011 return found;
3012}
3013
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003014static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003015{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003016 int i, idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003017
3018 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3019 if (con2fb_map[i] == idx)
3020 con2fb_map[i] = -1;
3021 }
3022
3023 if (idx == info_idx) {
3024 info_idx = -1;
3025
3026 for (i = 0; i < FB_MAX; i++) {
3027 if (registered_fb[i] != NULL) {
3028 info_idx = i;
3029 break;
3030 }
3031 }
3032 }
3033
3034 if (info_idx != -1) {
3035 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3036 if (con2fb_map[i] == -1)
3037 con2fb_map[i] = info_idx;
3038 }
3039 }
3040
3041 if (!num_registered_fb)
3042 unregister_con_driver(&fb_con);
3043
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003044
3045 if (primary_device == idx)
3046 primary_device = -1;
3047
Antonino A. Daplase614b182006-06-26 00:27:09 -07003048 return 0;
3049}
3050
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003051#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
3052static int fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003054 int ret = 0;
3055
3056 if (!map_override && primary_device == -1 &&
3057 fb_is_primary_device(info)) {
3058 int i, err;
3059
3060 printk(KERN_INFO "fbcon: %s is primary device\n",
3061 info->fix.id);
3062 primary_device = info->node;
3063
3064 if (!con_is_bound(&fb_con))
3065 goto done;
3066
3067 printk(KERN_INFO "fbcon: Unbinding old driver\n");
3068 unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3069 fbcon_is_default);
3070 info_idx = primary_device;
3071
3072 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3073 con2fb_map_boot[i] = primary_device;
3074 con2fb_map[i] = primary_device;
3075 }
3076
3077 printk(KERN_INFO "fbcon: Selecting new driver\n");
3078 err = bind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3079 fbcon_is_default);
3080
3081 if (err) {
3082 for (i = first_fb_vc; i <= last_fb_vc; i++)
3083 con2fb_map[i] = -1;
3084
3085 info_idx = -1;
3086 }
3087
3088 ret = 1;
3089 }
3090
3091done:
3092 return ret;
3093}
3094#else
3095static inline int fbcon_select_primary(struct fb_info *info)
3096{
3097 return 0;
3098}
3099#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3100
3101static int fbcon_fb_registered(struct fb_info *info)
3102{
3103 int ret = 0, i, idx = info->node;
3104
3105 if (fbcon_select_primary(info))
3106 goto done;
3107
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108
3109 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003110 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (con2fb_map_boot[i] == idx) {
3112 info_idx = idx;
3113 break;
3114 }
3115 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003116
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 if (info_idx != -1)
3118 ret = fbcon_takeover(1);
3119 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003120 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003121 if (con2fb_map_boot[i] == idx &&
3122 con2fb_map[i] == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 set_con2fb_map(i, idx, 0);
3124 }
3125 }
3126
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003127done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 return ret;
3129}
3130
3131static void fbcon_fb_blanked(struct fb_info *info, int blank)
3132{
3133 struct fbcon_ops *ops = info->fbcon_par;
3134 struct vc_data *vc;
3135
3136 if (!ops || ops->currcon < 0)
3137 return;
3138
3139 vc = vc_cons[ops->currcon].d;
3140 if (vc->vc_mode != KD_TEXT ||
3141 registered_fb[con2fb_map[ops->currcon]] != info)
3142 return;
3143
3144 if (CON_IS_VISIBLE(vc)) {
3145 if (blank)
3146 do_blank_screen(0);
3147 else
3148 do_unblank_screen(0);
3149 }
3150 ops->blank_state = blank;
3151}
3152
3153static void fbcon_new_modelist(struct fb_info *info)
3154{
3155 int i;
3156 struct vc_data *vc;
3157 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003158 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
Antonino A. Daplase614b182006-06-26 00:27:09 -07003160 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 if (registered_fb[con2fb_map[i]] != info)
3162 continue;
3163 if (!fb_display[i].mode)
3164 continue;
3165 vc = vc_cons[i].d;
3166 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003167 mode = fb_find_nearest_mode(fb_display[i].mode,
3168 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 fb_videomode_to_var(&var, mode);
3170
3171 if (vc)
3172 fbcon_set_disp(info, &var, vc);
3173 else
3174 fbcon_preset_disp(info, &var, i);
3175
3176 }
3177}
3178
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003179static void fbcon_get_requirement(struct fb_info *info,
3180 struct fb_blit_caps *caps)
3181{
3182 struct vc_data *vc;
3183 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003184
3185 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003186 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003187
3188 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3189 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003190 if (vc && vc->vc_mode == KD_TEXT &&
3191 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003192 p = &fb_display[i];
3193 caps->x |= 1 << (vc->vc_font.width - 1);
3194 caps->y |= 1 << (vc->vc_font.height - 1);
3195 charcnt = (p->userfont) ?
3196 FNTCHARCNT(p->fontdata) : 256;
3197 if (caps->len < charcnt)
3198 caps->len = charcnt;
3199 }
3200 }
3201 } else {
3202 vc = vc_cons[fg_console].d;
3203
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003204 if (vc && vc->vc_mode == KD_TEXT &&
3205 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003206 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003207 caps->x = 1 << (vc->vc_font.width - 1);
3208 caps->y = 1 << (vc->vc_font.height - 1);
3209 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003210 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003211 }
3212 }
3213}
3214
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215static int fbcon_event_notify(struct notifier_block *self,
3216 unsigned long action, void *data)
3217{
3218 struct fb_event *event = data;
3219 struct fb_info *info = event->info;
3220 struct fb_videomode *mode;
3221 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003222 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 int ret = 0;
3224
Antonino A. Daplase614b182006-06-26 00:27:09 -07003225 /*
3226 * ignore all events except driver registration and deregistration
3227 * if fbcon is not active
3228 */
3229 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3230 action == FB_EVENT_FB_UNREGISTERED))
3231 goto done;
3232
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 switch(action) {
3234 case FB_EVENT_SUSPEND:
3235 fbcon_suspended(info);
3236 break;
3237 case FB_EVENT_RESUME:
3238 fbcon_resumed(info);
3239 break;
3240 case FB_EVENT_MODE_CHANGE:
3241 fbcon_modechanged(info);
3242 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003243 case FB_EVENT_MODE_CHANGE_ALL:
3244 fbcon_set_all_vcs(info);
3245 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 case FB_EVENT_MODE_DELETE:
3247 mode = event->data;
3248 ret = fbcon_mode_deleted(info, mode);
3249 break;
3250 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003251 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003253 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003254 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003255 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 case FB_EVENT_SET_CONSOLE_MAP:
3257 con2fb = event->data;
3258 ret = set_con2fb_map(con2fb->console - 1,
3259 con2fb->framebuffer, 1);
3260 break;
3261 case FB_EVENT_GET_CONSOLE_MAP:
3262 con2fb = event->data;
3263 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3264 break;
3265 case FB_EVENT_BLANK:
3266 fbcon_fb_blanked(info, *(int *)event->data);
3267 break;
3268 case FB_EVENT_NEW_MODELIST:
3269 fbcon_new_modelist(info);
3270 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003271 case FB_EVENT_GET_REQ:
3272 caps = event->data;
3273 fbcon_get_requirement(info, caps);
3274 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 }
3276
Antonino A. Daplase614b182006-06-26 00:27:09 -07003277done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 return ret;
3279}
3280
3281/*
3282 * The console `switch' structure for the frame buffer based console
3283 */
3284
3285static const struct consw fb_con = {
3286 .owner = THIS_MODULE,
3287 .con_startup = fbcon_startup,
3288 .con_init = fbcon_init,
3289 .con_deinit = fbcon_deinit,
3290 .con_clear = fbcon_clear,
3291 .con_putc = fbcon_putc,
3292 .con_putcs = fbcon_putcs,
3293 .con_cursor = fbcon_cursor,
3294 .con_scroll = fbcon_scroll,
3295 .con_bmove = fbcon_bmove,
3296 .con_switch = fbcon_switch,
3297 .con_blank = fbcon_blank,
3298 .con_font_set = fbcon_set_font,
3299 .con_font_get = fbcon_get_font,
3300 .con_font_default = fbcon_set_def_font,
3301 .con_font_copy = fbcon_copy_font,
3302 .con_set_palette = fbcon_set_palette,
3303 .con_scrolldelta = fbcon_scrolldelta,
3304 .con_set_origin = fbcon_set_origin,
3305 .con_invert_region = fbcon_invert_region,
3306 .con_screen_pos = fbcon_screen_pos,
3307 .con_getxy = fbcon_getxy,
3308 .con_resize = fbcon_resize,
3309};
3310
3311static struct notifier_block fbcon_event_notifier = {
3312 .notifier_call = fbcon_event_notify,
3313};
3314
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003315static ssize_t store_rotate(struct device *device,
3316 struct device_attribute *attr, const char *buf,
3317 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003318{
3319 struct fb_info *info;
3320 int rotate, idx;
3321 char **last = NULL;
3322
Antonino A. Daplase614b182006-06-26 00:27:09 -07003323 if (fbcon_has_exited)
3324 return count;
3325
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003326 acquire_console_sem();
3327 idx = con2fb_map[fg_console];
3328
3329 if (idx == -1 || registered_fb[idx] == NULL)
3330 goto err;
3331
3332 info = registered_fb[idx];
3333 rotate = simple_strtoul(buf, last, 0);
3334 fbcon_rotate(info, rotate);
3335err:
3336 release_console_sem();
3337 return count;
3338}
3339
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003340static ssize_t store_rotate_all(struct device *device,
3341 struct device_attribute *attr,const char *buf,
3342 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003343{
3344 struct fb_info *info;
3345 int rotate, idx;
3346 char **last = NULL;
3347
Antonino A. Daplase614b182006-06-26 00:27:09 -07003348 if (fbcon_has_exited)
3349 return count;
3350
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003351 acquire_console_sem();
3352 idx = con2fb_map[fg_console];
3353
3354 if (idx == -1 || registered_fb[idx] == NULL)
3355 goto err;
3356
3357 info = registered_fb[idx];
3358 rotate = simple_strtoul(buf, last, 0);
3359 fbcon_rotate_all(info, rotate);
3360err:
3361 release_console_sem();
3362 return count;
3363}
3364
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003365static ssize_t show_rotate(struct device *device,
3366 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003367{
3368 struct fb_info *info;
3369 int rotate = 0, idx;
3370
Antonino A. Daplase614b182006-06-26 00:27:09 -07003371 if (fbcon_has_exited)
3372 return 0;
3373
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003374 acquire_console_sem();
3375 idx = con2fb_map[fg_console];
3376
3377 if (idx == -1 || registered_fb[idx] == NULL)
3378 goto err;
3379
3380 info = registered_fb[idx];
3381 rotate = fbcon_get_rotate(info);
3382err:
3383 release_console_sem();
3384 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3385}
3386
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003387static ssize_t show_cursor_blink(struct device *device,
3388 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003389{
3390 struct fb_info *info;
3391 struct fbcon_ops *ops;
3392 int idx, blink = -1;
3393
3394 if (fbcon_has_exited)
3395 return 0;
3396
3397 acquire_console_sem();
3398 idx = con2fb_map[fg_console];
3399
3400 if (idx == -1 || registered_fb[idx] == NULL)
3401 goto err;
3402
3403 info = registered_fb[idx];
3404 ops = info->fbcon_par;
3405
3406 if (!ops)
3407 goto err;
3408
3409 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3410err:
3411 release_console_sem();
3412 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3413}
3414
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003415static ssize_t store_cursor_blink(struct device *device,
3416 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003417 const char *buf, size_t count)
3418{
3419 struct fb_info *info;
3420 int blink, idx;
3421 char **last = NULL;
3422
3423 if (fbcon_has_exited)
3424 return count;
3425
3426 acquire_console_sem();
3427 idx = con2fb_map[fg_console];
3428
3429 if (idx == -1 || registered_fb[idx] == NULL)
3430 goto err;
3431
3432 info = registered_fb[idx];
3433
3434 if (!info->fbcon_par)
3435 goto err;
3436
3437 blink = simple_strtoul(buf, last, 0);
3438
3439 if (blink) {
3440 fbcon_cursor_noblink = 0;
3441 fbcon_add_cursor_timer(info);
3442 } else {
3443 fbcon_cursor_noblink = 1;
3444 fbcon_del_cursor_timer(info);
3445 }
3446
3447err:
3448 release_console_sem();
3449 return count;
3450}
3451
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003452static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003453 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3454 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003455 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3456 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003457};
3458
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003459static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003460{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003461 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003462
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003463 fbcon_has_sysfs = 1;
3464
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003465 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3466 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003467
3468 if (error)
3469 break;
3470 }
3471
3472 if (error) {
3473 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003474 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003475
3476 fbcon_has_sysfs = 0;
3477 }
3478
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003479 return 0;
3480}
3481
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003482static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003485 int i;
3486
3487 acquire_console_sem();
3488
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 for (i = 0; i < FB_MAX; i++) {
3490 if (registered_fb[i] != NULL) {
3491 info_idx = i;
3492 break;
3493 }
3494 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003495
3496 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 fbcon_takeover(0);
3498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499}
3500
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003501static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003502{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003503 struct fb_info *info;
3504 int i, j, mapped;
3505
Antonino A. Daplase614b182006-06-26 00:27:09 -07003506 if (fbcon_has_exited)
3507 return;
3508
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003509#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003510 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003511#endif
3512#ifdef CONFIG_MAC
3513 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003514 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003515#endif
3516
3517 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003518 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003519
3520 for (i = 0; i < FB_MAX; i++) {
3521 mapped = 0;
3522 info = registered_fb[i];
3523
3524 if (info == NULL)
3525 continue;
3526
Antonino A. Daplase614b182006-06-26 00:27:09 -07003527 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3528 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003529 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003530 }
3531
3532 if (mapped) {
3533 if (info->fbops->fb_release)
3534 info->fbops->fb_release(info, 0);
3535 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003536
3537 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003538 struct fbcon_ops *ops = info->fbcon_par;
3539
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003540 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003541 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003542 kfree(info->fbcon_par);
3543 info->fbcon_par = NULL;
3544 }
3545
3546 if (info->queue.func == fb_flashcursor)
3547 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003548 }
3549 }
3550
Antonino A. Daplase614b182006-06-26 00:27:09 -07003551 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003552}
3553
3554static int __init fb_console_init(void)
3555{
3556 int i;
3557
3558 acquire_console_sem();
3559 fb_register_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003560 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003561
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003562 if (IS_ERR(fbcon_device)) {
3563 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003564 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003565 PTR_ERR(fbcon_device));
3566 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003567 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003568 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003569
3570 for (i = 0; i < MAX_NR_CONSOLES; i++)
3571 con2fb_map[i] = -1;
3572
3573 release_console_sem();
3574 fbcon_start();
3575 return 0;
3576}
3577
3578module_init(fb_console_init);
3579
3580#ifdef MODULE
3581
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003582static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003583{
3584 int i;
3585
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003586 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003587 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3588 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003589
3590 fbcon_has_sysfs = 0;
3591 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003592}
3593
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594static void __exit fb_console_exit(void)
3595{
3596 acquire_console_sem();
3597 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003598 fbcon_deinit_device();
3599 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003600 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003602 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603}
3604
3605module_exit(fb_console_exit);
3606
3607#endif
3608
3609MODULE_LICENSE("GPL");