blob: 3ccfa76d9b2a0c7f523dcb6e37dc10ad3fac59ea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/video/fbcon.c -- Low level frame buffer based console driver
3 *
4 * Copyright (C) 1995 Geert Uytterhoeven
5 *
6 *
7 * This file is based on the original Amiga console driver (amicon.c):
8 *
9 * Copyright (C) 1993 Hamish Macdonald
10 * Greg Harp
11 * Copyright (C) 1994 David Carter [carter@compsci.bristol.ac.uk]
12 *
13 * with work by William Rucklidge (wjr@cs.cornell.edu)
14 * Geert Uytterhoeven
15 * Jes Sorensen (jds@kom.auc.dk)
16 * Martin Apel
17 *
18 * and on the original Atari console driver (atacon.c):
19 *
20 * Copyright (C) 1993 Bjoern Brauel
21 * Roman Hodek
22 *
23 * with work by Guenther Kelleter
24 * Martin Schaller
25 * Andreas Schwab
26 *
27 * Hardware cursor support added by Emmanuel Marty (core@ggi-project.org)
28 * Smart redraw scrolling, arbitrary font width support, 512char font support
29 * and software scrollback added by
30 * Jakub Jelinek (jj@ultra.linux.cz)
31 *
32 * Random hacking by Martin Mares <mj@ucw.cz>
33 *
34 * 2001 - Documented with DocBook
35 * - Brad Douglas <brad@neruo.com>
36 *
37 * The low level operations for the various display memory organizations are
38 * now in separate source files.
39 *
40 * Currently the following organizations are supported:
41 *
42 * o afb Amiga bitplanes
43 * o cfb{2,4,8,16,24,32} Packed pixels
44 * o ilbm Amiga interleaved bitplanes
45 * o iplan2p[248] Atari interleaved bitplanes
46 * o mfb Monochrome
47 * o vga VGA characters/attributes
48 *
49 * To do:
50 *
51 * - Implement 16 plane mode (iplan2p16)
52 *
53 *
54 * This file is subject to the terms and conditions of the GNU General Public
55 * License. See the file COPYING in the main directory of this archive for
56 * more details.
57 */
58
59#undef FBCONDEBUG
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/module.h>
62#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <linux/fs.h>
64#include <linux/kernel.h>
65#include <linux/delay.h> /* MSch: for IRQ probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <linux/console.h>
67#include <linux/string.h>
68#include <linux/kd.h>
69#include <linux/slab.h>
70#include <linux/fb.h>
71#include <linux/vt_kern.h>
72#include <linux/selection.h>
73#include <linux/font.h>
74#include <linux/smp.h>
75#include <linux/init.h>
76#include <linux/interrupt.h>
77#include <linux/crc32.h> /* For counting font checksums */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -070078#include <asm/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm/irq.h>
80#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#ifdef CONFIG_ATARI
82#include <asm/atariints.h>
83#endif
84#ifdef CONFIG_MAC
85#include <asm/macints.h>
86#endif
Adrian Bunk7b892802008-02-06 01:36:29 -080087#if defined(__mc68000__)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#include <asm/machdep.h>
89#include <asm/setup.h>
90#endif
91
92#include "fbcon.h"
93
94#ifdef FBCONDEBUG
Harvey Harrison5ae12172008-04-28 02:15:47 -070095# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#else
97# define DPRINTK(fmt, args...)
98#endif
99
100enum {
101 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
104};
105
Antonino A. Daplasab767202005-11-13 16:06:32 -0800106static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static signed char con2fb_map[MAX_NR_CONSOLES];
109static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int logo_lines;
112/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
113 enums. */
114static int logo_shown = FBCON_LOGO_CANSHOW;
115/* Software scrollback */
116static int fbcon_softback_size = 32768;
117static unsigned long softback_buf, softback_curr;
118static unsigned long softback_in;
119static unsigned long softback_top, softback_end;
120static int softback_lines;
121/* console mappings */
122static int first_fb_vc;
123static int last_fb_vc = MAX_NR_CONSOLES - 1;
124static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700125static int fbcon_has_exited;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700126static int primary_device = -1;
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700127
128#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700129static int map_override;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700130
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700131static inline void fbcon_map_override(void)
132{
133 map_override = 1;
134}
135#else
136static inline void fbcon_map_override(void)
137{
138}
139#endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/* font data */
142static char fontname[40];
143
144/* current fb_info */
145static int info_idx = -1;
146
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800147/* console rotation */
Marcin Slusarz2428e592008-02-06 01:39:14 -0800148static int initial_rotation;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700149static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static const struct consw fb_con;
152
153#define CM_SOFTBACK (8)
154
155#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static int fbcon_set_origin(struct vc_data *);
158
159#define CURSOR_DRAW_DELAY (1)
160
161/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#define ATARI_CURSOR_BLINK_RATE (42)
163#define MAC_CURSOR_BLINK_RATE (32)
164#define DEFAULT_CURSOR_BLINK_RATE (20)
165
166static int vbl_cursor_cnt;
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700167static int fbcon_cursor_noblink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
170
171/*
172 * Interface used by the world
173 */
174
175static const char *fbcon_startup(void);
176static void fbcon_init(struct vc_data *vc, int init);
177static void fbcon_deinit(struct vc_data *vc);
178static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
179 int width);
180static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
181static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
182 int count, int ypos, int xpos);
183static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
184static void fbcon_cursor(struct vc_data *vc, int mode);
185static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
186 int count);
187static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
188 int height, int width);
189static int fbcon_switch(struct vc_data *vc);
190static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
191static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
192static int fbcon_scrolldelta(struct vc_data *vc, int lines);
193
194/*
195 * Internal routines
196 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197static __inline__ void ywrap_up(struct vc_data *vc, int count);
198static __inline__ void ywrap_down(struct vc_data *vc, int count);
199static __inline__ void ypan_up(struct vc_data *vc, int count);
200static __inline__ void ypan_down(struct vc_data *vc, int count);
201static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
202 int dy, int dx, int height, int width, u_int y_break);
203static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700204 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
206 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800207static void fbcon_modechanged(struct fb_info *info);
208static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700209static void fbcon_start(void);
210static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700211static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#ifdef CONFIG_MAC
214/*
215 * On the Macintoy, there may or may not be a working VBL int. We need to probe
216 */
217static int vbl_detected;
218
David Howells7d12e782006-10-05 14:55:46 +0100219static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 vbl_detected++;
222 return IRQ_HANDLED;
223}
224#endif
225
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800226#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800227static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800228{
229 struct fbcon_ops *ops = info->fbcon_par;
230
231 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800232 ops->p->con_rotate < 4)
233 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800234 else
235 ops->rotate = 0;
236}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800237
238static void fbcon_rotate(struct fb_info *info, u32 rotate)
239{
240 struct fbcon_ops *ops= info->fbcon_par;
241 struct fb_info *fb_info;
242
243 if (!ops || ops->currcon == -1)
244 return;
245
246 fb_info = registered_fb[con2fb_map[ops->currcon]];
247
248 if (info == fb_info) {
249 struct display *p = &fb_display[ops->currcon];
250
251 if (rotate < 4)
252 p->con_rotate = rotate;
253 else
254 p->con_rotate = 0;
255
256 fbcon_modechanged(info);
257 }
258}
259
260static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
261{
262 struct fbcon_ops *ops = info->fbcon_par;
263 struct vc_data *vc;
264 struct display *p;
265 int i;
266
267 if (!ops || ops->currcon < 0 || rotate > 3)
268 return;
269
Antonino A. Daplase614b182006-06-26 00:27:09 -0700270 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800271 vc = vc_cons[i].d;
272 if (!vc || vc->vc_mode != KD_TEXT ||
273 registered_fb[con2fb_map[i]] != info)
274 continue;
275
276 p = &fb_display[vc->vc_num];
277 p->con_rotate = rotate;
278 }
279
280 fbcon_set_all_vcs(info);
281}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800282#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800283static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800284{
285 struct fbcon_ops *ops = info->fbcon_par;
286
287 ops->rotate = FB_ROTATE_UR;
288}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800289
290static void fbcon_rotate(struct fb_info *info, u32 rotate)
291{
292 return;
293}
294
295static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
296{
297 return;
298}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800299#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800300
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800301static int fbcon_get_rotate(struct fb_info *info)
302{
303 struct fbcon_ops *ops = info->fbcon_par;
304
305 return (ops) ? ops->rotate : 0;
306}
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
309{
310 struct fbcon_ops *ops = info->fbcon_par;
311
312 return (info->state != FBINFO_STATE_RUNNING ||
313 vc->vc_mode != KD_TEXT || ops->graphics);
314}
315
316static inline int get_color(struct vc_data *vc, struct fb_info *info,
317 u16 c, int is_fg)
318{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700319 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 int color = 0;
321
322 if (console_blanked) {
323 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
324
325 c = vc->vc_video_erase_char & charmask;
326 }
327
328 if (depth != 1)
329 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
330 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
331
332 switch (depth) {
333 case 1:
334 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800335 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700337 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
338 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 if (console_blanked)
341 fg = bg;
342
343 color = (is_fg) ? fg : bg;
344 break;
345 }
346 case 2:
347 /*
348 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700349 * is grayscale. However, simply dividing the values by 4
350 * will not work, as colors 1, 2 and 3 will be scaled-down
351 * to zero rendering them invisible. So empirically convert
352 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700354 switch (color) {
355 case 0:
356 color = 0; /* black */
357 break;
358 case 1 ... 6:
359 color = 2; /* white */
360 break;
361 case 7 ... 8:
362 color = 1; /* gray */
363 break;
364 default:
365 color = 3; /* intense white */
366 break;
367 }
368 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 case 3:
370 /*
371 * Last 8 entries of default 16-color palette is a more intense
372 * version of the first 8 (i.e., same chrominance, different
373 * luminance).
374 */
375 color &= 7;
376 break;
377 }
378
379
380 return color;
381}
382
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800383static void fbcon_update_softback(struct vc_data *vc)
384{
385 int l = fbcon_softback_size / vc->vc_size_row;
386
387 if (l > 5)
388 softback_end = softback_buf + l * vc->vc_size_row;
389 else
390 /* Smaller scrollback makes no sense, and 0 would screw
391 the operation totally */
392 softback_top = 0;
393}
394
David Howellsc4028952006-11-22 14:57:56 +0000395static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
David Howellsc4028952006-11-22 14:57:56 +0000397 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 struct fbcon_ops *ops = info->fbcon_par;
399 struct display *p;
400 struct vc_data *vc = NULL;
401 int c;
402 int mode;
403
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700404 acquire_console_sem();
405 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 vc = vc_cons[ops->currcon].d;
407
408 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700409 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700410 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700411 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700413 }
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 p = &fb_display[vc->vc_num];
416 c = scr_readw((u16 *) vc->vc_pos);
417 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
418 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800419 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 get_color(vc, info, c, 0));
421 release_console_sem();
422}
423
Russell King41359dc2005-06-30 16:30:07 +0100424#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100426static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
428 struct fb_info *info = dev_id;
429
430 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
431 schedule_work(&info->queue);
432 vbl_cursor_cnt = cursor_blink_rate;
433 }
434 return IRQ_HANDLED;
435}
436#endif
437
438static void cursor_timer_handler(unsigned long dev_addr)
439{
440 struct fb_info *info = (struct fb_info *) dev_addr;
441 struct fbcon_ops *ops = info->fbcon_par;
442
443 schedule_work(&info->queue);
444 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
445}
446
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700447static void fbcon_add_cursor_timer(struct fb_info *info)
448{
449 struct fbcon_ops *ops = info->fbcon_par;
450
451 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700452 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
453 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700454 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000455 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700456
457 init_timer(&ops->cursor_timer);
458 ops->cursor_timer.function = cursor_timer_handler;
459 ops->cursor_timer.expires = jiffies + HZ / 5;
460 ops->cursor_timer.data = (unsigned long ) info;
461 add_timer(&ops->cursor_timer);
462 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
463 }
464}
465
466static void fbcon_del_cursor_timer(struct fb_info *info)
467{
468 struct fbcon_ops *ops = info->fbcon_par;
469
470 if (info->queue.func == fb_flashcursor &&
471 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
472 del_timer_sync(&ops->cursor_timer);
473 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
474 }
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#ifndef MODULE
478static int __init fb_console_setup(char *this_opt)
479{
480 char *options;
481 int i, j;
482
483 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800484 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 while ((options = strsep(&this_opt, ",")) != NULL) {
487 if (!strncmp(options, "font:", 5))
488 strcpy(fontname, options + 5);
489
490 if (!strncmp(options, "scrollback:", 11)) {
491 options += 11;
492 if (*options) {
493 fbcon_softback_size = simple_strtoul(options, &options, 0);
494 if (*options == 'k' || *options == 'K') {
495 fbcon_softback_size *= 1024;
496 options++;
497 }
498 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800499 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 options++;
501 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800502 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
504
505 if (!strncmp(options, "map:", 4)) {
506 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700507 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
509 if (!options[j])
510 j = 0;
511 con2fb_map_boot[i] =
512 (options[j++]-'0') % FB_MAX;
513 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700514
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700515 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700516 }
517
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800518 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 }
520
521 if (!strncmp(options, "vc:", 3)) {
522 options += 3;
523 if (*options)
524 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
525 if (first_fb_vc < 0)
526 first_fb_vc = 0;
527 if (*options++ == '-')
528 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
529 fbcon_is_default = 0;
530 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800531
532 if (!strncmp(options, "rotate:", 7)) {
533 options += 7;
534 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800535 initial_rotation = simple_strtoul(options, &options, 0);
536 if (initial_rotation > 3)
537 initial_rotation = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800540 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
543__setup("fbcon=", fb_console_setup);
544#endif
545
546static int search_fb_in_map(int idx)
547{
548 int i, retval = 0;
549
Antonino A. Daplase614b182006-06-26 00:27:09 -0700550 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (con2fb_map[i] == idx)
552 retval = 1;
553 }
554 return retval;
555}
556
557static int search_for_mapped_con(void)
558{
559 int i, retval = 0;
560
Antonino A. Daplase614b182006-06-26 00:27:09 -0700561 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (con2fb_map[i] != -1)
563 retval = 1;
564 }
565 return retval;
566}
567
568static int fbcon_takeover(int show_logo)
569{
570 int err, i;
571
572 if (!num_registered_fb)
573 return -ENODEV;
574
575 if (!show_logo)
576 logo_shown = FBCON_LOGO_DONTSHOW;
577
578 for (i = first_fb_vc; i <= last_fb_vc; i++)
579 con2fb_map[i] = info_idx;
580
581 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
582 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 if (err) {
585 for (i = first_fb_vc; i <= last_fb_vc; i++) {
586 con2fb_map[i] = -1;
587 }
588 info_idx = -1;
589 }
590
591 return err;
592}
593
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700594#ifdef MODULE
595static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
596 int cols, int rows, int new_cols, int new_rows)
597{
598 logo_shown = FBCON_LOGO_DONTSHOW;
599}
600#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
602 int cols, int rows, int new_cols, int new_rows)
603{
604 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800605 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 int cnt, erase = vc->vc_video_erase_char, step;
607 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700608 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700610 if (info->flags & FBINFO_MODULE) {
611 logo_shown = FBCON_LOGO_DONTSHOW;
612 return;
613 }
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 /*
616 * remove underline attribute from erase character
617 * if black and white framebuffer.
618 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700619 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800621 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700622 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 q = (unsigned short *) (vc->vc_origin +
624 vc->vc_size_row * rows);
625 step = logo_lines * cols;
626 for (r = q - logo_lines * cols; r < q; r++)
627 if (scr_readw(r) != vc->vc_video_erase_char)
628 break;
629 if (r != q && new_rows >= rows + logo_lines) {
630 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
631 if (save) {
632 int i = cols < new_cols ? cols : new_cols;
633 scr_memsetw(save, erase, logo_lines * new_cols * 2);
634 r = q - step;
635 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
636 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
637 r = q;
638 }
639 }
640 if (r == q) {
641 /* We can scroll screen down */
642 r = q - step - cols;
643 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
644 scr_memcpyw(r + step, r, vc->vc_size_row);
645 r -= cols;
646 }
647 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700648 int lines;
649 if (vc->vc_y + logo_lines >= rows)
650 lines = rows - vc->vc_y - 1;
651 else
652 lines = logo_lines;
653 vc->vc_y += lines;
654 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 }
656 }
657 scr_memsetw((unsigned short *) vc->vc_origin,
658 erase,
659 vc->vc_size_row * logo_lines);
660
661 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
662 fbcon_clear_margins(vc, 0);
663 update_screen(vc);
664 }
665
666 if (save) {
667 q = (unsigned short *) (vc->vc_origin +
668 vc->vc_size_row *
669 rows);
670 scr_memcpyw(q, save, logo_lines * new_cols * 2);
671 vc->vc_y += logo_lines;
672 vc->vc_pos += logo_lines * vc->vc_size_row;
673 kfree(save);
674 }
675
676 if (logo_lines > vc->vc_bottom) {
677 logo_shown = FBCON_LOGO_CANSHOW;
678 printk(KERN_INFO
679 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
680 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
681 logo_shown = FBCON_LOGO_DRAW;
682 vc->vc_top = logo_lines;
683 }
684}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700685#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800688static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689{
690 struct fbcon_ops *ops = info->fbcon_par;
691
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800692 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800695 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800696 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800697 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700701
702static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
703{
704 int err = 0;
705
706 if (info->flags & FBINFO_MISC_TILEBLITTING &&
707 info->tileops->fb_get_tilemax(info) < charcount)
708 err = 1;
709
710 return err;
711}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800713static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714{
715 struct fbcon_ops *ops = info->fbcon_par;
716
717 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800718 ops->p = &fb_display[vc->vc_num];
719 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 fbcon_set_bitops(ops);
721}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700722
723static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
724{
725 return 0;
726}
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#endif /* CONFIG_MISC_TILEBLITTING */
729
730
731static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
732 int unit, int oldidx)
733{
734 struct fbcon_ops *ops = NULL;
735 int err = 0;
736
737 if (!try_module_get(info->fbops->owner))
738 err = -ENODEV;
739
740 if (!err && info->fbops->fb_open &&
741 info->fbops->fb_open(info, 0))
742 err = -ENODEV;
743
744 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800745 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 if (!ops)
747 err = -ENOMEM;
748 }
749
750 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700752
753 if (vc)
754 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
757 if (err) {
758 con2fb_map[unit] = oldidx;
759 module_put(info->fbops->owner);
760 }
761
762 return err;
763}
764
765static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
766 struct fb_info *newinfo, int unit,
767 int oldidx, int found)
768{
769 struct fbcon_ops *ops = oldinfo->fbcon_par;
770 int err = 0;
771
772 if (oldinfo->fbops->fb_release &&
773 oldinfo->fbops->fb_release(oldinfo, 0)) {
774 con2fb_map[unit] = oldidx;
775 if (!found && newinfo->fbops->fb_release)
776 newinfo->fbops->fb_release(newinfo, 0);
777 if (!found)
778 module_put(newinfo->fbops->owner);
779 err = -ENODEV;
780 }
781
782 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700783 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 kfree(ops->cursor_state.mask);
785 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800786 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 kfree(oldinfo->fbcon_par);
788 oldinfo->fbcon_par = NULL;
789 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800790 /*
791 If oldinfo and newinfo are driving the same hardware,
792 the fb_release() method of oldinfo may attempt to
793 restore the hardware state. This will leave the
794 newinfo in an undefined state. Thus, a call to
795 fb_set_par() may be needed for the newinfo.
796 */
797 if (newinfo->fbops->fb_set_par)
798 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 }
800
801 return err;
802}
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
805 int unit, int show_logo)
806{
807 struct fbcon_ops *ops = info->fbcon_par;
808
809 ops->currcon = fg_console;
810
811 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
812 info->fbops->fb_set_par(info);
813
814 ops->flags |= FBCON_FLAGS_INIT;
815 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700816 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
818 if (show_logo) {
819 struct vc_data *fg_vc = vc_cons[fg_console].d;
820 struct fb_info *fg_info =
821 registered_fb[con2fb_map[fg_console]];
822
823 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
824 fg_vc->vc_rows, fg_vc->vc_cols,
825 fg_vc->vc_rows);
826 }
827
828 update_screen(vc_cons[fg_console].d);
829}
830
831/**
832 * set_con2fb_map - map console to frame buffer device
833 * @unit: virtual console number to map
834 * @newidx: frame buffer index to map virtual console to
835 * @user: user request
836 *
837 * Maps a virtual console @unit to a frame buffer device
838 * @newidx.
839 */
840static int set_con2fb_map(int unit, int newidx, int user)
841{
842 struct vc_data *vc = vc_cons[unit].d;
843 int oldidx = con2fb_map[unit];
844 struct fb_info *info = registered_fb[newidx];
845 struct fb_info *oldinfo = NULL;
846 int found, err = 0;
847
848 if (oldidx == newidx)
849 return 0;
850
Antonino A. Daplase614b182006-06-26 00:27:09 -0700851 if (!info || fbcon_has_exited)
852 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 if (!err && !search_for_mapped_con()) {
855 info_idx = newidx;
856 return fbcon_takeover(0);
857 }
858
859 if (oldidx != -1)
860 oldinfo = registered_fb[oldidx];
861
862 found = search_fb_in_map(newidx);
863
864 acquire_console_sem();
865 con2fb_map[unit] = newidx;
866 if (!err && !found)
867 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
868
869
870 /*
871 * If old fb is not mapped to any of the consoles,
872 * fbcon should release it.
873 */
874 if (!err && oldinfo && !search_fb_in_map(oldidx))
875 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
876 found);
877
878 if (!err) {
879 int show_logo = (fg_console == 0 && !user &&
880 logo_shown != FBCON_LOGO_DONTSHOW);
881
882 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700883 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 con2fb_map_boot[unit] = newidx;
885 con2fb_init_display(vc, info, unit, show_logo);
886 }
887
Antonino A. Daplase614b182006-06-26 00:27:09 -0700888 if (!search_fb_in_map(info_idx))
889 info_idx = newidx;
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 release_console_sem();
892 return err;
893}
894
895/*
896 * Low Level Operations
897 */
898/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
899static int var_to_display(struct display *disp,
900 struct fb_var_screeninfo *var,
901 struct fb_info *info)
902{
903 disp->xres_virtual = var->xres_virtual;
904 disp->yres_virtual = var->yres_virtual;
905 disp->bits_per_pixel = var->bits_per_pixel;
906 disp->grayscale = var->grayscale;
907 disp->nonstd = var->nonstd;
908 disp->accel_flags = var->accel_flags;
909 disp->height = var->height;
910 disp->width = var->width;
911 disp->red = var->red;
912 disp->green = var->green;
913 disp->blue = var->blue;
914 disp->transp = var->transp;
915 disp->rotate = var->rotate;
916 disp->mode = fb_match_mode(var, &info->modelist);
917 if (disp->mode == NULL)
918 /* This should not happen */
919 return -EINVAL;
920 return 0;
921}
922
923static void display_to_var(struct fb_var_screeninfo *var,
924 struct display *disp)
925{
926 fb_videomode_to_var(var, disp->mode);
927 var->xres_virtual = disp->xres_virtual;
928 var->yres_virtual = disp->yres_virtual;
929 var->bits_per_pixel = disp->bits_per_pixel;
930 var->grayscale = disp->grayscale;
931 var->nonstd = disp->nonstd;
932 var->accel_flags = disp->accel_flags;
933 var->height = disp->height;
934 var->width = disp->width;
935 var->red = disp->red;
936 var->green = disp->green;
937 var->blue = disp->blue;
938 var->transp = disp->transp;
939 var->rotate = disp->rotate;
940}
941
942static const char *fbcon_startup(void)
943{
944 const char *display_desc = "frame buffer device";
945 struct display *p = &fb_display[fg_console];
946 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700947 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 struct module *owner;
949 struct fb_info *info = NULL;
950 struct fbcon_ops *ops;
951 int rows, cols;
952 int irqres;
953
954 irqres = 1;
955 /*
956 * If num_registered_fb is zero, this is a call for the dummy part.
957 * The frame buffer devices weren't initialized yet.
958 */
959 if (!num_registered_fb || info_idx == -1)
960 return display_desc;
961 /*
962 * Instead of blindly using registered_fb[0], we use info_idx, set by
963 * fb_console_init();
964 */
965 info = registered_fb[info_idx];
966 if (!info)
967 return NULL;
968
969 owner = info->fbops->owner;
970 if (!try_module_get(owner))
971 return NULL;
972 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
973 module_put(owner);
974 return NULL;
975 }
976
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800977 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 if (!ops) {
979 module_put(owner);
980 return NULL;
981 }
982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 ops->currcon = -1;
984 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800985 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800987 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800988 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 if (info->fix.type != FB_TYPE_TEXT) {
991 if (fbcon_softback_size) {
992 if (!softback_buf) {
993 softback_buf =
994 (unsigned long)
995 kmalloc(fbcon_softback_size,
996 GFP_KERNEL);
997 if (!softback_buf) {
998 fbcon_softback_size = 0;
999 softback_top = 0;
1000 }
1001 }
1002 } else {
1003 if (softback_buf) {
1004 kfree((void *) softback_buf);
1005 softback_buf = 0;
1006 softback_top = 0;
1007 }
1008 }
1009 if (softback_buf)
1010 softback_in = softback_top = softback_curr =
1011 softback_buf;
1012 softback_lines = 0;
1013 }
1014
1015 /* Setup default font */
1016 if (!p->fontdata) {
1017 if (!fontname[0] || !(font = find_font(fontname)))
1018 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001019 info->var.yres,
1020 info->pixmap.blit_x,
1021 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 vc->vc_font.width = font->width;
1023 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001024 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1026 }
1027
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001028 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1029 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1030 cols /= vc->vc_font.width;
1031 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 vc_resize(vc, cols, rows);
1033
1034 DPRINTK("mode: %s\n", info->fix.id);
1035 DPRINTK("visual: %d\n", info->fix.visual);
1036 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1037 info->var.yres,
1038 info->var.bits_per_pixel);
1039
1040#ifdef CONFIG_ATARI
1041 if (MACH_IS_ATARI) {
1042 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1043 irqres =
1044 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1045 IRQ_TYPE_PRIO, "framebuffer vbl",
1046 info);
1047 }
1048#endif /* CONFIG_ATARI */
1049
1050#ifdef CONFIG_MAC
1051 /*
1052 * On a Macintoy, the VBL interrupt may or may not be active.
1053 * As interrupt based cursor is more reliable and race free, we
1054 * probe for VBL interrupts.
1055 */
1056 if (MACH_IS_MAC) {
1057 int ct = 0;
1058 /*
1059 * Probe for VBL: set temp. handler ...
1060 */
1061 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1062 "framebuffer vbl", info);
1063 vbl_detected = 0;
1064
1065 /*
1066 * ... and spin for 20 ms ...
1067 */
1068 while (!vbl_detected && ++ct < 1000)
1069 udelay(20);
1070
1071 if (ct == 1000)
1072 printk
1073 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1074
1075 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1076
1077 if (vbl_detected) {
1078 /*
1079 * interrupt based cursor ok
1080 */
1081 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1082 irqres =
1083 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1084 "framebuffer vbl", info);
1085 } else {
1086 /*
1087 * VBL not detected: fall through, use timer based cursor
1088 */
1089 irqres = 1;
1090 }
1091 }
1092#endif /* CONFIG_MAC */
1093
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001094 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001095 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 return display_desc;
1097}
1098
1099static void fbcon_init(struct vc_data *vc, int init)
1100{
1101 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1102 struct fbcon_ops *ops;
1103 struct vc_data **default_mode = vc->vc_display_fg;
1104 struct vc_data *svc = *default_mode;
1105 struct display *t, *p = &fb_display[vc->vc_num];
1106 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001107 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
1109 if (info_idx == -1 || info == NULL)
1110 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001111
1112 cap = info->flags;
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1115 (info->fix.type == FB_TYPE_TEXT))
1116 logo = 0;
1117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 if (var_to_display(p, &info->var, info))
1119 return;
1120
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001121 if (!info->fbcon_par)
1122 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 /* If we are not the first console on this
1125 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001126 t = &fb_display[fg_console];
1127 if (!p->fontdata) {
1128 if (t->fontdata) {
1129 struct vc_data *fvc = vc_cons[fg_console].d;
1130
1131 vc->vc_font.data = (void *)(p->fontdata =
1132 fvc->vc_font.data);
1133 vc->vc_font.width = fvc->vc_font.width;
1134 vc->vc_font.height = fvc->vc_font.height;
1135 p->userfont = t->userfont;
1136
1137 if (p->userfont)
1138 REFCOUNT(p->fontdata)++;
1139 } else {
1140 const struct font_desc *font = NULL;
1141
1142 if (!fontname[0] || !(font = find_font(fontname)))
1143 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001144 info->var.yres,
1145 info->pixmap.blit_x,
1146 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001147 vc->vc_font.width = font->width;
1148 vc->vc_font.height = font->height;
1149 vc->vc_font.data = (void *)(p->fontdata = font->data);
1150 vc->vc_font.charcount = 256; /* FIXME Need to
1151 support more fonts */
1152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (p->userfont)
1156 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001157
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001158 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1160 if (charcnt == 256) {
1161 vc->vc_hi_font_mask = 0;
1162 } else {
1163 vc->vc_hi_font_mask = 0x100;
1164 if (vc->vc_can_do_color)
1165 vc->vc_complement_mask <<= 1;
1166 }
1167
1168 if (!*svc->vc_uni_pagedir_loc)
1169 con_set_default_unimap(svc);
1170 if (!*vc->vc_uni_pagedir_loc)
1171 con_copy_unimap(vc, svc);
1172
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001173 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001174 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001175 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 cols = vc->vc_cols;
1178 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001179 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1180 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1181 new_cols /= vc->vc_font.width;
1182 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 vc_resize(vc, new_cols, new_rows);
1184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 /*
1186 * We must always set the mode. The mode of the previous console
1187 * driver could be in the same resolution but we are using different
1188 * hardware so we have to initialize the hardware.
1189 *
1190 * We need to do it in fbcon_init() to prevent screen corruption.
1191 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001192 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (info->fbops->fb_set_par &&
1194 !(ops->flags & FBCON_FLAGS_INIT))
1195 info->fbops->fb_set_par(info);
1196 ops->flags |= FBCON_FLAGS_INIT;
1197 }
1198
1199 ops->graphics = 0;
1200
1201 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1202 !(cap & FBINFO_HWACCEL_DISABLED))
1203 p->scrollmode = SCROLL_MOVE;
1204 else /* default to something safe */
1205 p->scrollmode = SCROLL_REDRAW;
1206
1207 /*
1208 * ++guenther: console.c:vc_allocate() relies on initializing
1209 * vc_{cols,rows}, but we must not set those if we are only
1210 * resizing the console.
1211 */
1212 if (!init) {
1213 vc->vc_cols = new_cols;
1214 vc->vc_rows = new_rows;
1215 }
1216
1217 if (logo)
1218 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1219
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001220 if (vc == svc && softback_buf)
1221 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001222
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001223 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001224 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001225 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001226 }
1227
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001228 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229}
1230
Antonino A. Daplase614b182006-06-26 00:27:09 -07001231static void fbcon_free_font(struct display *p)
1232{
1233 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1234 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1235 p->fontdata = NULL;
1236 p->userfont = 0;
1237}
1238
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239static void fbcon_deinit(struct vc_data *vc)
1240{
1241 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001242 struct fb_info *info;
1243 struct fbcon_ops *ops;
1244 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001247 idx = con2fb_map[vc->vc_num];
1248
1249 if (idx == -1)
1250 goto finished;
1251
1252 info = registered_fb[idx];
1253
1254 if (!info)
1255 goto finished;
1256
1257 ops = info->fbcon_par;
1258
1259 if (!ops)
1260 goto finished;
1261
1262 if (CON_IS_VISIBLE(vc))
1263 fbcon_del_cursor_timer(info);
1264
1265 ops->flags &= ~FBCON_FLAGS_INIT;
1266finished:
1267
1268 if (!con_is_bound(&fb_con))
1269 fbcon_exit();
1270
1271 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
1274/* ====================================================================== */
1275
1276/* fbcon_XXX routines - interface used by the world
1277 *
1278 * This system is now divided into two levels because of complications
1279 * caused by hardware scrolling. Top level functions:
1280 *
1281 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1282 *
1283 * handles y values in range [0, scr_height-1] that correspond to real
1284 * screen positions. y_wrap shift means that first line of bitmap may be
1285 * anywhere on this display. These functions convert lineoffsets to
1286 * bitmap offsets and deal with the wrap-around case by splitting blits.
1287 *
1288 * fbcon_bmove_physical_8() -- These functions fast implementations
1289 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1290 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1291 *
1292 * WARNING:
1293 *
1294 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1295 * Implies should only really hardware scroll in rows. Only reason for
1296 * restriction is simplicity & efficiency at the moment.
1297 */
1298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1300 int width)
1301{
1302 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1303 struct fbcon_ops *ops = info->fbcon_par;
1304
1305 struct display *p = &fb_display[vc->vc_num];
1306 u_int y_break;
1307
1308 if (fbcon_is_inactive(vc, info))
1309 return;
1310
1311 if (!height || !width)
1312 return;
1313
1314 /* Split blits that cross physical y_wrap boundary */
1315
1316 y_break = p->vrows - p->yscroll;
1317 if (sy < y_break && sy + height - 1 >= y_break) {
1318 u_int b = y_break - sy;
1319 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1320 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1321 width);
1322 } else
1323 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1324}
1325
1326static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1327 int count, int ypos, int xpos)
1328{
1329 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1330 struct display *p = &fb_display[vc->vc_num];
1331 struct fbcon_ops *ops = info->fbcon_par;
1332
1333 if (!fbcon_is_inactive(vc, info))
1334 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1335 get_color(vc, info, scr_readw(s), 1),
1336 get_color(vc, info, scr_readw(s), 0));
1337}
1338
1339static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1340{
1341 unsigned short chr;
1342
1343 scr_writew(c, &chr);
1344 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1345}
1346
1347static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1348{
1349 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1350 struct fbcon_ops *ops = info->fbcon_par;
1351
1352 if (!fbcon_is_inactive(vc, info))
1353 ops->clear_margins(vc, info, bottom_only);
1354}
1355
1356static void fbcon_cursor(struct vc_data *vc, int mode)
1357{
1358 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1359 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 int y;
1361 int c = scr_readw((u16 *) vc->vc_pos);
1362
Michal Januszewskid1e23062007-05-08 00:38:07 -07001363 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 return;
1365
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001366 if (vc->vc_cursor_type & 0x10)
1367 fbcon_del_cursor_timer(info);
1368 else
1369 fbcon_add_cursor_timer(info);
1370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1372 if (mode & CM_SOFTBACK) {
1373 mode &= ~CM_SOFTBACK;
1374 y = softback_lines;
1375 } else {
1376 if (softback_lines)
1377 fbcon_set_origin(vc);
1378 y = 0;
1379 }
1380
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001381 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 get_color(vc, info, c, 0));
1383 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1384}
1385
1386static int scrollback_phys_max = 0;
1387static int scrollback_max = 0;
1388static int scrollback_current = 0;
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001391 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001393 struct display *p, *t;
1394 struct vc_data **default_mode, *vc;
1395 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001396 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 int rows, cols, charcnt = 256;
1398
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001399 p = &fb_display[unit];
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 if (var_to_display(p, var, info))
1402 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001403
1404 vc = vc_cons[unit].d;
1405
1406 if (!vc)
1407 return;
1408
1409 default_mode = vc->vc_display_fg;
1410 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001412
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001414 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 vc->vc_font.width = (*default_mode)->vc_font.width;
1416 vc->vc_font.height = (*default_mode)->vc_font.height;
1417 p->userfont = t->userfont;
1418 if (p->userfont)
1419 REFCOUNT(p->fontdata)++;
1420 }
1421 if (p->userfont)
1422 charcnt = FNTCHARCNT(p->fontdata);
1423
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001424 var->activate = FB_ACTIVATE_NOW;
1425 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001426 var->yoffset = info->var.yoffset;
1427 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001428 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001429 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001430 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1432 if (charcnt == 256) {
1433 vc->vc_hi_font_mask = 0;
1434 } else {
1435 vc->vc_hi_font_mask = 0x100;
1436 if (vc->vc_can_do_color)
1437 vc->vc_complement_mask <<= 1;
1438 }
1439
1440 if (!*svc->vc_uni_pagedir_loc)
1441 con_set_default_unimap(svc);
1442 if (!*vc->vc_uni_pagedir_loc)
1443 con_copy_unimap(vc, svc);
1444
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001445 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1446 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1447 cols /= vc->vc_font.width;
1448 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001450
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 if (CON_IS_VISIBLE(vc)) {
1452 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001453 if (softback_buf)
1454 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 }
1456}
1457
1458static __inline__ void ywrap_up(struct vc_data *vc, int count)
1459{
1460 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001461 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 struct display *p = &fb_display[vc->vc_num];
1463
1464 p->yscroll += count;
1465 if (p->yscroll >= p->vrows) /* Deal with wrap */
1466 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001467 ops->var.xoffset = 0;
1468 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1469 ops->var.vmode |= FB_VMODE_YWRAP;
1470 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 scrollback_max += count;
1472 if (scrollback_max > scrollback_phys_max)
1473 scrollback_max = scrollback_phys_max;
1474 scrollback_current = 0;
1475}
1476
1477static __inline__ void ywrap_down(struct vc_data *vc, int count)
1478{
1479 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001480 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 struct display *p = &fb_display[vc->vc_num];
1482
1483 p->yscroll -= count;
1484 if (p->yscroll < 0) /* Deal with wrap */
1485 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001486 ops->var.xoffset = 0;
1487 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1488 ops->var.vmode |= FB_VMODE_YWRAP;
1489 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 scrollback_max -= count;
1491 if (scrollback_max < 0)
1492 scrollback_max = 0;
1493 scrollback_current = 0;
1494}
1495
1496static __inline__ void ypan_up(struct vc_data *vc, int count)
1497{
1498 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1499 struct display *p = &fb_display[vc->vc_num];
1500 struct fbcon_ops *ops = info->fbcon_par;
1501
1502 p->yscroll += count;
1503 if (p->yscroll > p->vrows - vc->vc_rows) {
1504 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1505 0, 0, 0, vc->vc_rows, vc->vc_cols);
1506 p->yscroll -= p->vrows - vc->vc_rows;
1507 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001508
1509 ops->var.xoffset = 0;
1510 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1511 ops->var.vmode &= ~FB_VMODE_YWRAP;
1512 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 fbcon_clear_margins(vc, 1);
1514 scrollback_max += count;
1515 if (scrollback_max > scrollback_phys_max)
1516 scrollback_max = scrollback_phys_max;
1517 scrollback_current = 0;
1518}
1519
1520static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1521{
1522 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001523 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001527
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 if (p->yscroll > p->vrows - vc->vc_rows) {
1529 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001531 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001532
1533 ops->var.xoffset = 0;
1534 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1535 ops->var.vmode &= ~FB_VMODE_YWRAP;
1536 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 fbcon_clear_margins(vc, 1);
1538 scrollback_max += count;
1539 if (scrollback_max > scrollback_phys_max)
1540 scrollback_max = scrollback_phys_max;
1541 scrollback_current = 0;
1542}
1543
1544static __inline__ void ypan_down(struct vc_data *vc, int count)
1545{
1546 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1547 struct display *p = &fb_display[vc->vc_num];
1548 struct fbcon_ops *ops = info->fbcon_par;
1549
1550 p->yscroll -= count;
1551 if (p->yscroll < 0) {
1552 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1553 0, vc->vc_rows, vc->vc_cols);
1554 p->yscroll += p->vrows - vc->vc_rows;
1555 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001556
1557 ops->var.xoffset = 0;
1558 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1559 ops->var.vmode &= ~FB_VMODE_YWRAP;
1560 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 fbcon_clear_margins(vc, 1);
1562 scrollback_max -= count;
1563 if (scrollback_max < 0)
1564 scrollback_max = 0;
1565 scrollback_current = 0;
1566}
1567
1568static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1569{
1570 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001571 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
1574 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 if (p->yscroll < 0) {
1577 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001579 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001580
1581 ops->var.xoffset = 0;
1582 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1583 ops->var.vmode &= ~FB_VMODE_YWRAP;
1584 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 fbcon_clear_margins(vc, 1);
1586 scrollback_max -= count;
1587 if (scrollback_max < 0)
1588 scrollback_max = 0;
1589 scrollback_current = 0;
1590}
1591
1592static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1593 long delta)
1594{
1595 int count = vc->vc_rows;
1596 unsigned short *d, *s;
1597 unsigned long n;
1598 int line = 0;
1599
1600 d = (u16 *) softback_curr;
1601 if (d == (u16 *) softback_in)
1602 d = (u16 *) vc->vc_origin;
1603 n = softback_curr + delta * vc->vc_size_row;
1604 softback_lines -= delta;
1605 if (delta < 0) {
1606 if (softback_curr < softback_top && n < softback_buf) {
1607 n += softback_end - softback_buf;
1608 if (n < softback_top) {
1609 softback_lines -=
1610 (softback_top - n) / vc->vc_size_row;
1611 n = softback_top;
1612 }
1613 } else if (softback_curr >= softback_top
1614 && n < softback_top) {
1615 softback_lines -=
1616 (softback_top - n) / vc->vc_size_row;
1617 n = softback_top;
1618 }
1619 } else {
1620 if (softback_curr > softback_in && n >= softback_end) {
1621 n += softback_buf - softback_end;
1622 if (n > softback_in) {
1623 n = softback_in;
1624 softback_lines = 0;
1625 }
1626 } else if (softback_curr <= softback_in && n > softback_in) {
1627 n = softback_in;
1628 softback_lines = 0;
1629 }
1630 }
1631 if (n == softback_curr)
1632 return;
1633 softback_curr = n;
1634 s = (u16 *) softback_curr;
1635 if (s == (u16 *) softback_in)
1636 s = (u16 *) vc->vc_origin;
1637 while (count--) {
1638 unsigned short *start;
1639 unsigned short *le;
1640 unsigned short c;
1641 int x = 0;
1642 unsigned short attr = 1;
1643
1644 start = s;
1645 le = advance_row(s, 1);
1646 do {
1647 c = scr_readw(s);
1648 if (attr != (c & 0xff00)) {
1649 attr = c & 0xff00;
1650 if (s > start) {
1651 fbcon_putcs(vc, start, s - start,
1652 line, x);
1653 x += s - start;
1654 start = s;
1655 }
1656 }
1657 if (c == scr_readw(d)) {
1658 if (s > start) {
1659 fbcon_putcs(vc, start, s - start,
1660 line, x);
1661 x += s - start + 1;
1662 start = s + 1;
1663 } else {
1664 x++;
1665 start++;
1666 }
1667 }
1668 s++;
1669 d++;
1670 } while (s < le);
1671 if (s > start)
1672 fbcon_putcs(vc, start, s - start, line, x);
1673 line++;
1674 if (d == (u16 *) softback_end)
1675 d = (u16 *) softback_buf;
1676 if (d == (u16 *) softback_in)
1677 d = (u16 *) vc->vc_origin;
1678 if (s == (u16 *) softback_end)
1679 s = (u16 *) softback_buf;
1680 if (s == (u16 *) softback_in)
1681 s = (u16 *) vc->vc_origin;
1682 }
1683}
1684
1685static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1686 int line, int count, int dy)
1687{
1688 unsigned short *s = (unsigned short *)
1689 (vc->vc_origin + vc->vc_size_row * line);
1690
1691 while (count--) {
1692 unsigned short *start = s;
1693 unsigned short *le = advance_row(s, 1);
1694 unsigned short c;
1695 int x = 0;
1696 unsigned short attr = 1;
1697
1698 do {
1699 c = scr_readw(s);
1700 if (attr != (c & 0xff00)) {
1701 attr = c & 0xff00;
1702 if (s > start) {
1703 fbcon_putcs(vc, start, s - start,
1704 dy, x);
1705 x += s - start;
1706 start = s;
1707 }
1708 }
1709 console_conditional_schedule();
1710 s++;
1711 } while (s < le);
1712 if (s > start)
1713 fbcon_putcs(vc, start, s - start, dy, x);
1714 console_conditional_schedule();
1715 dy++;
1716 }
1717}
1718
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001719static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1720 struct display *p, int line, int count, int ycount)
1721{
1722 int offset = ycount * vc->vc_cols;
1723 unsigned short *d = (unsigned short *)
1724 (vc->vc_origin + vc->vc_size_row * line);
1725 unsigned short *s = d + offset;
1726 struct fbcon_ops *ops = info->fbcon_par;
1727
1728 while (count--) {
1729 unsigned short *start = s;
1730 unsigned short *le = advance_row(s, 1);
1731 unsigned short c;
1732 int x = 0;
1733
1734 do {
1735 c = scr_readw(s);
1736
1737 if (c == scr_readw(d)) {
1738 if (s > start) {
1739 ops->bmove(vc, info, line + ycount, x,
1740 line, x, 1, s-start);
1741 x += s - start + 1;
1742 start = s + 1;
1743 } else {
1744 x++;
1745 start++;
1746 }
1747 }
1748
1749 scr_writew(c, d);
1750 console_conditional_schedule();
1751 s++;
1752 d++;
1753 } while (s < le);
1754 if (s > start)
1755 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1756 s-start);
1757 console_conditional_schedule();
1758 if (ycount > 0)
1759 line++;
1760 else {
1761 line--;
1762 /* NOTE: We subtract two lines from these pointers */
1763 s -= vc->vc_size_row;
1764 d -= vc->vc_size_row;
1765 }
1766 }
1767}
1768
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769static void fbcon_redraw(struct vc_data *vc, struct display *p,
1770 int line, int count, int offset)
1771{
1772 unsigned short *d = (unsigned short *)
1773 (vc->vc_origin + vc->vc_size_row * line);
1774 unsigned short *s = d + offset;
1775
1776 while (count--) {
1777 unsigned short *start = s;
1778 unsigned short *le = advance_row(s, 1);
1779 unsigned short c;
1780 int x = 0;
1781 unsigned short attr = 1;
1782
1783 do {
1784 c = scr_readw(s);
1785 if (attr != (c & 0xff00)) {
1786 attr = c & 0xff00;
1787 if (s > start) {
1788 fbcon_putcs(vc, start, s - start,
1789 line, x);
1790 x += s - start;
1791 start = s;
1792 }
1793 }
1794 if (c == scr_readw(d)) {
1795 if (s > start) {
1796 fbcon_putcs(vc, start, s - start,
1797 line, x);
1798 x += s - start + 1;
1799 start = s + 1;
1800 } else {
1801 x++;
1802 start++;
1803 }
1804 }
1805 scr_writew(c, d);
1806 console_conditional_schedule();
1807 s++;
1808 d++;
1809 } while (s < le);
1810 if (s > start)
1811 fbcon_putcs(vc, start, s - start, line, x);
1812 console_conditional_schedule();
1813 if (offset > 0)
1814 line++;
1815 else {
1816 line--;
1817 /* NOTE: We subtract two lines from these pointers */
1818 s -= vc->vc_size_row;
1819 d -= vc->vc_size_row;
1820 }
1821 }
1822}
1823
1824static inline void fbcon_softback_note(struct vc_data *vc, int t,
1825 int count)
1826{
1827 unsigned short *p;
1828
1829 if (vc->vc_num != fg_console)
1830 return;
1831 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1832
1833 while (count) {
1834 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1835 count--;
1836 p = advance_row(p, 1);
1837 softback_in += vc->vc_size_row;
1838 if (softback_in == softback_end)
1839 softback_in = softback_buf;
1840 if (softback_in == softback_top) {
1841 softback_top += vc->vc_size_row;
1842 if (softback_top == softback_end)
1843 softback_top = softback_buf;
1844 }
1845 }
1846 softback_curr = softback_in;
1847}
1848
1849static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1850 int count)
1851{
1852 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1853 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07001855 unsigned short saved_ec;
1856 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
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
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07001869 saved_ec = vc->vc_video_erase_char;
1870 vc->vc_video_erase_char = vc->vc_scrl_erase_char;
1871
1872 ret = 0;
1873
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 switch (dir) {
1875 case SM_UP:
1876 if (count > vc->vc_rows) /* Maximum realistic size */
1877 count = vc->vc_rows;
1878 if (softback_top)
1879 fbcon_softback_note(vc, t, count);
1880 if (logo_shown >= 0)
1881 goto redraw_up;
1882 switch (p->scrollmode) {
1883 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001884 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1885 count);
1886 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1887 scr_memsetw((unsigned short *) (vc->vc_origin +
1888 vc->vc_size_row *
1889 (b - count)),
Jan Engelhardtc9e587a2008-04-29 00:59:46 -07001890 vc->vc_scrl_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001891 vc->vc_size_row * count);
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07001892 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 break;
1894
1895 case SCROLL_WRAP_MOVE:
1896 if (b - t - count > 3 * vc->vc_rows >> 2) {
1897 if (t > 0)
1898 fbcon_bmove(vc, 0, 0, count, 0, t,
1899 vc->vc_cols);
1900 ywrap_up(vc, count);
1901 if (vc->vc_rows - b > 0)
1902 fbcon_bmove(vc, b - count, 0, b, 0,
1903 vc->vc_rows - b,
1904 vc->vc_cols);
1905 } else if (info->flags & FBINFO_READS_FAST)
1906 fbcon_bmove(vc, t + count, 0, t, 0,
1907 b - t - count, vc->vc_cols);
1908 else
1909 goto redraw_up;
1910 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1911 break;
1912
1913 case SCROLL_PAN_REDRAW:
1914 if ((p->yscroll + count <=
1915 2 * (p->vrows - vc->vc_rows))
1916 && ((!scroll_partial && (b - t == vc->vc_rows))
1917 || (scroll_partial
1918 && (b - t - count >
1919 3 * vc->vc_rows >> 2)))) {
1920 if (t > 0)
1921 fbcon_redraw_move(vc, p, 0, t, count);
1922 ypan_up_redraw(vc, t, count);
1923 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001924 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 vc->vc_rows - b, b);
1926 } else
1927 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1928 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1929 break;
1930
1931 case SCROLL_PAN_MOVE:
1932 if ((p->yscroll + count <=
1933 2 * (p->vrows - vc->vc_rows))
1934 && ((!scroll_partial && (b - t == vc->vc_rows))
1935 || (scroll_partial
1936 && (b - t - count >
1937 3 * vc->vc_rows >> 2)))) {
1938 if (t > 0)
1939 fbcon_bmove(vc, 0, 0, count, 0, t,
1940 vc->vc_cols);
1941 ypan_up(vc, count);
1942 if (vc->vc_rows - b > 0)
1943 fbcon_bmove(vc, b - count, 0, b, 0,
1944 vc->vc_rows - b,
1945 vc->vc_cols);
1946 } else if (info->flags & FBINFO_READS_FAST)
1947 fbcon_bmove(vc, t + count, 0, t, 0,
1948 b - t - count, vc->vc_cols);
1949 else
1950 goto redraw_up;
1951 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1952 break;
1953
1954 case SCROLL_REDRAW:
1955 redraw_up:
1956 fbcon_redraw(vc, p, t, b - t - count,
1957 count * vc->vc_cols);
1958 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1959 scr_memsetw((unsigned short *) (vc->vc_origin +
1960 vc->vc_size_row *
1961 (b - count)),
Jan Engelhardtc9e587a2008-04-29 00:59:46 -07001962 vc->vc_scrl_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 vc->vc_size_row * count);
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07001964 ret = 1;
1965 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 }
1967 break;
1968
1969 case SM_DOWN:
1970 if (count > vc->vc_rows) /* Maximum realistic size */
1971 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001972 if (logo_shown >= 0)
1973 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 switch (p->scrollmode) {
1975 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001976 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1977 -count);
1978 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1979 scr_memsetw((unsigned short *) (vc->vc_origin +
1980 vc->vc_size_row *
1981 t),
Jan Engelhardtc9e587a2008-04-29 00:59:46 -07001982 vc->vc_scrl_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001983 vc->vc_size_row * count);
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07001984 ret = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 break;
1986
1987 case SCROLL_WRAP_MOVE:
1988 if (b - t - count > 3 * vc->vc_rows >> 2) {
1989 if (vc->vc_rows - b > 0)
1990 fbcon_bmove(vc, b, 0, b - count, 0,
1991 vc->vc_rows - b,
1992 vc->vc_cols);
1993 ywrap_down(vc, count);
1994 if (t > 0)
1995 fbcon_bmove(vc, count, 0, 0, 0, t,
1996 vc->vc_cols);
1997 } else if (info->flags & FBINFO_READS_FAST)
1998 fbcon_bmove(vc, t, 0, t + count, 0,
1999 b - t - count, vc->vc_cols);
2000 else
2001 goto redraw_down;
2002 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2003 break;
2004
2005 case SCROLL_PAN_MOVE:
2006 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2007 && ((!scroll_partial && (b - t == vc->vc_rows))
2008 || (scroll_partial
2009 && (b - t - count >
2010 3 * vc->vc_rows >> 2)))) {
2011 if (vc->vc_rows - b > 0)
2012 fbcon_bmove(vc, b, 0, b - count, 0,
2013 vc->vc_rows - b,
2014 vc->vc_cols);
2015 ypan_down(vc, count);
2016 if (t > 0)
2017 fbcon_bmove(vc, count, 0, 0, 0, t,
2018 vc->vc_cols);
2019 } else if (info->flags & FBINFO_READS_FAST)
2020 fbcon_bmove(vc, t, 0, t + count, 0,
2021 b - t - count, vc->vc_cols);
2022 else
2023 goto redraw_down;
2024 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2025 break;
2026
2027 case SCROLL_PAN_REDRAW:
2028 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2029 && ((!scroll_partial && (b - t == vc->vc_rows))
2030 || (scroll_partial
2031 && (b - t - count >
2032 3 * vc->vc_rows >> 2)))) {
2033 if (vc->vc_rows - b > 0)
2034 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2035 b - count);
2036 ypan_down_redraw(vc, t, count);
2037 if (t > 0)
2038 fbcon_redraw_move(vc, p, count, t, 0);
2039 } else
2040 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2041 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2042 break;
2043
2044 case SCROLL_REDRAW:
2045 redraw_down:
2046 fbcon_redraw(vc, p, b - 1, b - t - count,
2047 -count * vc->vc_cols);
2048 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2049 scr_memsetw((unsigned short *) (vc->vc_origin +
2050 vc->vc_size_row *
2051 t),
Jan Engelhardtc9e587a2008-04-29 00:59:46 -07002052 vc->vc_scrl_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 vc->vc_size_row * count);
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07002054 ret = 1;
2055 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 }
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07002057 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 }
Jan Engelhardtd850a2f2008-05-12 14:02:39 -07002059 vc->vc_video_erase_char = saved_ec;
2060 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061}
2062
2063
2064static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2065 int height, int width)
2066{
2067 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2068 struct display *p = &fb_display[vc->vc_num];
2069
2070 if (fbcon_is_inactive(vc, info))
2071 return;
2072
2073 if (!width || !height)
2074 return;
2075
2076 /* Split blits that cross physical y_wrap case.
2077 * Pathological case involves 4 blits, better to use recursive
2078 * code rather than unrolled case
2079 *
2080 * Recursive invocations don't need to erase the cursor over and
2081 * over again, so we use fbcon_bmove_rec()
2082 */
2083 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2084 p->vrows - p->yscroll);
2085}
2086
2087static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2088 int dy, int dx, int height, int width, u_int y_break)
2089{
2090 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2091 struct fbcon_ops *ops = info->fbcon_par;
2092 u_int b;
2093
2094 if (sy < y_break && sy + height > y_break) {
2095 b = y_break - sy;
2096 if (dy < sy) { /* Avoid trashing self */
2097 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2098 y_break);
2099 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2100 height - b, width, y_break);
2101 } else {
2102 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2103 height - b, width, y_break);
2104 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2105 y_break);
2106 }
2107 return;
2108 }
2109
2110 if (dy < y_break && dy + height > y_break) {
2111 b = y_break - dy;
2112 if (dy < sy) { /* Avoid trashing self */
2113 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2114 y_break);
2115 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2116 height - b, width, y_break);
2117 } else {
2118 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2119 height - b, width, y_break);
2120 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2121 y_break);
2122 }
2123 return;
2124 }
2125 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2126 height, width);
2127}
2128
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002129static __inline__ void updatescrollmode(struct display *p,
2130 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct vc_data *vc)
2132{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002133 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 int fh = vc->vc_font.height;
2135 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002136 u16 t = 0;
2137 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2138 info->fix.xpanstep);
2139 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2140 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2141 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2142 info->var.xres_virtual);
2143 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2144 divides(ypan, vc->vc_font.height) && vyres > yres;
2145 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2146 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002147 divides(vc->vc_font.height, vyres) &&
2148 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002150 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2151 !(cap & FBINFO_HWACCEL_DISABLED);
2152 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2153 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002155 p->vrows = vyres/fh;
2156 if (yres > (fh * (vc->vc_rows + 1)))
2157 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2158 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 p->vrows--;
2160
2161 if (good_wrap || good_pan) {
2162 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002163 p->scrollmode = good_wrap ?
2164 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 else
2166 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2167 SCROLL_PAN_REDRAW;
2168 } else {
2169 if (reading_fast || (fast_copyarea && !fast_imageblit))
2170 p->scrollmode = SCROLL_MOVE;
2171 else
2172 p->scrollmode = SCROLL_REDRAW;
2173 }
2174}
2175
2176static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002177 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002180 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct display *p = &fb_display[vc->vc_num];
2182 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002183 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002185 virt_w = FBCON_SWAP(ops->rotate, width, height);
2186 virt_h = FBCON_SWAP(ops->rotate, height, width);
2187 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2188 vc->vc_font.height);
2189 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2190 vc->vc_font.width);
2191 var.xres = virt_w * virt_fw;
2192 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 x_diff = info->var.xres - var.xres;
2194 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002195 if (x_diff < 0 || x_diff > virt_fw ||
2196 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002197 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
2199 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2200 mode = fb_find_best_mode(&var, &info->modelist);
2201 if (mode == NULL)
2202 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002203 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002205
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002206 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
2209 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2210 if (CON_IS_VISIBLE(vc)) {
2211 var.activate = FB_ACTIVATE_NOW |
2212 FB_ACTIVATE_FORCE;
2213 fb_set_var(info, &var);
2214 }
2215 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002216 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 }
2218 updatescrollmode(p, info, vc);
2219 return 0;
2220}
2221
2222static int fbcon_switch(struct vc_data *vc)
2223{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002224 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002225 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 struct display *p = &fb_display[vc->vc_num];
2227 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002228 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
2230 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002231 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 if (softback_lines)
2235 fbcon_set_origin(vc);
2236 softback_top = softback_curr = softback_in = softback_buf;
2237 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002238 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 }
2240
2241 if (logo_shown >= 0) {
2242 struct vc_data *conp2 = vc_cons[logo_shown].d;
2243
2244 if (conp2->vc_top == logo_lines
2245 && conp2->vc_bottom == conp2->vc_rows)
2246 conp2->vc_top = 0;
2247 logo_shown = FBCON_LOGO_CANSHOW;
2248 }
2249
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002250 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002251 if (prev_console != -1)
2252 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 /*
2254 * FIXME: If we have multiple fbdev's loaded, we need to
2255 * update all info->currcon. Perhaps, we can place this
2256 * in a centralized structure, but this might break some
2257 * drivers.
2258 *
2259 * info->currcon = vc->vc_num;
2260 */
2261 for (i = 0; i < FB_MAX; i++) {
2262 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002263 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002265 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 }
2267 }
2268 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2269 display_to_var(&var, p);
2270 var.activate = FB_ACTIVATE_NOW;
2271
2272 /*
2273 * make sure we don't unnecessarily trip the memcmp()
2274 * in fb_set_var()
2275 */
2276 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002277 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002279 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Knut Petersen39942fd2005-12-12 22:17:19 -08002281 if (old_info != NULL && (old_info != info ||
2282 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002283 if (info->fbops->fb_set_par)
2284 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002285
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002286 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002287 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002290 if (fbcon_is_inactive(vc, info) ||
2291 ops->blank_state != FB_BLANK_UNBLANK)
2292 fbcon_del_cursor_timer(info);
2293 else
2294 fbcon_add_cursor_timer(info);
2295
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002296 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002297 ops->cursor_reset = 1;
2298
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002299 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002300 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002301 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002304 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002306
2307 if (p->userfont)
2308 charcnt = FNTCHARCNT(vc->vc_font.data);
2309
2310 if (charcnt > 256)
2311 vc->vc_complement_mask <<= 1;
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 updatescrollmode(p, info, vc);
2314
2315 switch (p->scrollmode) {
2316 case SCROLL_WRAP_MOVE:
2317 scrollback_phys_max = p->vrows - vc->vc_rows;
2318 break;
2319 case SCROLL_PAN_MOVE:
2320 case SCROLL_PAN_REDRAW:
2321 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2322 if (scrollback_phys_max < 0)
2323 scrollback_phys_max = 0;
2324 break;
2325 default:
2326 scrollback_phys_max = 0;
2327 break;
2328 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 scrollback_max = 0;
2331 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002332
2333 if (!fbcon_is_inactive(vc, info)) {
2334 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2335 ops->update_start(info);
2336 }
2337
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 fbcon_set_palette(vc, color_table);
2339 fbcon_clear_margins(vc, 0);
2340
2341 if (logo_shown == FBCON_LOGO_DRAW) {
2342
2343 logo_shown = fg_console;
2344 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002345 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 update_region(vc,
2347 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2348 vc->vc_size_row * (vc->vc_bottom -
2349 vc->vc_top) / 2);
2350 return 0;
2351 }
2352 return 1;
2353}
2354
2355static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2356 int blank)
2357{
Richard Purdie994efac2007-02-09 09:46:45 +00002358 struct fb_event event;
2359
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 if (blank) {
2361 unsigned short charmask = vc->vc_hi_font_mask ?
2362 0x1ff : 0xff;
2363 unsigned short oldc;
2364
2365 oldc = vc->vc_video_erase_char;
2366 vc->vc_video_erase_char &= charmask;
2367 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2368 vc->vc_video_erase_char = oldc;
2369 }
Richard Purdie994efac2007-02-09 09:46:45 +00002370
2371
2372 event.info = info;
2373 event.data = &blank;
2374 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
2377static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2378{
2379 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2380 struct fbcon_ops *ops = info->fbcon_par;
2381
2382 if (mode_switch) {
2383 struct fb_var_screeninfo var = info->var;
2384
2385 ops->graphics = 1;
2386
2387 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002388 if (info->fbops->fb_save_state)
2389 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2391 fb_set_var(info, &var);
2392 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002393 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002394 } else if (info->fbops->fb_restore_state)
2395 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 }
2397
2398 if (!fbcon_is_inactive(vc, info)) {
2399 if (ops->blank_state != blank) {
2400 ops->blank_state = blank;
2401 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2402 ops->cursor_flash = (!blank);
2403
2404 if (fb_blank(info, blank))
2405 fbcon_generic_blank(vc, info, blank);
2406 }
2407
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002408 if (!blank)
2409 update_screen(vc);
2410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002412 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002413 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002414 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002415 else
2416 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002417
2418 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419}
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2422{
2423 u8 *fontdata = vc->vc_font.data;
2424 u8 *data = font->data;
2425 int i, j;
2426
2427 font->width = vc->vc_font.width;
2428 font->height = vc->vc_font.height;
2429 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2430 if (!font->data)
2431 return 0;
2432
2433 if (font->width <= 8) {
2434 j = vc->vc_font.height;
2435 for (i = 0; i < font->charcount; i++) {
2436 memcpy(data, fontdata, j);
2437 memset(data + j, 0, 32 - j);
2438 data += 32;
2439 fontdata += j;
2440 }
2441 } else if (font->width <= 16) {
2442 j = vc->vc_font.height * 2;
2443 for (i = 0; i < font->charcount; i++) {
2444 memcpy(data, fontdata, j);
2445 memset(data + j, 0, 64 - j);
2446 data += 64;
2447 fontdata += j;
2448 }
2449 } else if (font->width <= 24) {
2450 for (i = 0; i < font->charcount; i++) {
2451 for (j = 0; j < vc->vc_font.height; j++) {
2452 *data++ = fontdata[0];
2453 *data++ = fontdata[1];
2454 *data++ = fontdata[2];
2455 fontdata += sizeof(u32);
2456 }
2457 memset(data, 0, 3 * (32 - j));
2458 data += 3 * (32 - j);
2459 }
2460 } else {
2461 j = vc->vc_font.height * 4;
2462 for (i = 0; i < font->charcount; i++) {
2463 memcpy(data, fontdata, j);
2464 memset(data + j, 0, 128 - j);
2465 data += 128;
2466 fontdata += j;
2467 }
2468 }
2469 return 0;
2470}
2471
2472static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002473 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474{
2475 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002476 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 struct display *p = &fb_display[vc->vc_num];
2478 int resize;
2479 int cnt;
2480 char *old_data = NULL;
2481
2482 if (CON_IS_VISIBLE(vc) && softback_lines)
2483 fbcon_set_origin(vc);
2484
2485 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2486 if (p->userfont)
2487 old_data = vc->vc_font.data;
2488 if (userfont)
2489 cnt = FNTCHARCNT(data);
2490 else
2491 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002492 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 if ((p->userfont = userfont))
2494 REFCOUNT(data)++;
2495 vc->vc_font.width = w;
2496 vc->vc_font.height = h;
2497 if (vc->vc_hi_font_mask && cnt == 256) {
2498 vc->vc_hi_font_mask = 0;
2499 if (vc->vc_can_do_color) {
2500 vc->vc_complement_mask >>= 1;
2501 vc->vc_s_complement_mask >>= 1;
2502 }
2503
2504 /* ++Edmund: reorder the attribute bits */
2505 if (vc->vc_can_do_color) {
2506 unsigned short *cp =
2507 (unsigned short *) vc->vc_origin;
2508 int count = vc->vc_screenbuf_size / 2;
2509 unsigned short c;
2510 for (; count > 0; count--, cp++) {
2511 c = scr_readw(cp);
2512 scr_writew(((c & 0xfe00) >> 1) |
2513 (c & 0xff), cp);
2514 }
2515 c = vc->vc_video_erase_char;
2516 vc->vc_video_erase_char =
2517 ((c & 0xfe00) >> 1) | (c & 0xff);
Jan Engelhardt7fe39152008-05-12 14:02:38 -07002518 c = vc->vc_def_color;
2519 vc->vc_scrl_erase_char =
2520 ((c & 0xFE00) >> 1) | (c & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 vc->vc_attr >>= 1;
2522 }
2523 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2524 vc->vc_hi_font_mask = 0x100;
2525 if (vc->vc_can_do_color) {
2526 vc->vc_complement_mask <<= 1;
2527 vc->vc_s_complement_mask <<= 1;
2528 }
2529
2530 /* ++Edmund: reorder the attribute bits */
2531 {
2532 unsigned short *cp =
2533 (unsigned short *) vc->vc_origin;
2534 int count = vc->vc_screenbuf_size / 2;
2535 unsigned short c;
2536 for (; count > 0; count--, cp++) {
2537 unsigned short newc;
2538 c = scr_readw(cp);
2539 if (vc->vc_can_do_color)
2540 newc =
2541 ((c & 0xff00) << 1) | (c &
2542 0xff);
2543 else
2544 newc = c & ~0x100;
2545 scr_writew(newc, cp);
2546 }
2547 c = vc->vc_video_erase_char;
2548 if (vc->vc_can_do_color) {
2549 vc->vc_video_erase_char =
2550 ((c & 0xff00) << 1) | (c & 0xff);
Jan Engelhardt7fe39152008-05-12 14:02:38 -07002551 c = vc->vc_def_color;
2552 vc->vc_scrl_erase_char =
2553 ((c & 0xFF00) << 1) | (c & 0xFF);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 vc->vc_attr <<= 1;
Jan Engelhardt7fe39152008-05-12 14:02:38 -07002555 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 vc->vc_video_erase_char = c & ~0x100;
Jan Engelhardt7fe39152008-05-12 14:02:38 -07002557 vc->vc_scrl_erase_char = c & ~0x100;
2558 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 }
2560
2561 }
2562
2563 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002564 int cols, rows;
2565
2566 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2567 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2568 cols /= w;
2569 rows /= h;
2570 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002571 if (CON_IS_VISIBLE(vc) && softback_buf)
2572 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 } else if (CON_IS_VISIBLE(vc)
2574 && vc->vc_mode == KD_TEXT) {
2575 fbcon_clear_margins(vc, 0);
2576 update_screen(vc);
2577 }
2578
2579 if (old_data && (--REFCOUNT(old_data) == 0))
2580 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2581 return 0;
2582}
2583
2584static int fbcon_copy_font(struct vc_data *vc, int con)
2585{
2586 struct display *od = &fb_display[con];
2587 struct console_font *f = &vc->vc_font;
2588
2589 if (od->fontdata == f->data)
2590 return 0; /* already the same font... */
2591 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2592}
2593
2594/*
2595 * User asked to set font; we are guaranteed that
2596 * a) width and height are in range 1..32
2597 * b) charcount does not exceed 512
2598 * but lets not assume that, since someone might someday want to use larger
2599 * fonts. And charcount of 512 is small for unicode support.
2600 *
2601 * However, user space gives the font in 32 rows , regardless of
2602 * actual font height. So a new API is needed if support for larger fonts
2603 * is ever implemented.
2604 */
2605
2606static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2607{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002608 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 unsigned charcount = font->charcount;
2610 int w = font->width;
2611 int h = font->height;
2612 int size;
2613 int i, csum;
2614 u8 *new_data, *data = font->data;
2615 int pitch = (font->width+7) >> 3;
2616
2617 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2618 * If not this check should be changed to charcount < 256 */
2619 if (charcount != 256 && charcount != 512)
2620 return -EINVAL;
2621
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002622 /* Make sure drawing engine can handle the font */
2623 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2624 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2625 return -EINVAL;
2626
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002627 /* Make sure driver can handle the font length */
2628 if (fbcon_invalid_charcount(info, charcount))
2629 return -EINVAL;
2630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 size = h * pitch * charcount;
2632
2633 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2634
2635 if (!new_data)
2636 return -ENOMEM;
2637
2638 new_data += FONT_EXTRA_WORDS * sizeof(int);
2639 FNTSIZE(new_data) = size;
2640 FNTCHARCNT(new_data) = charcount;
2641 REFCOUNT(new_data) = 0; /* usage counter */
2642 for (i=0; i< charcount; i++) {
2643 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2644 }
2645
2646 /* Since linux has a nice crc32 function use it for counting font
2647 * checksums. */
2648 csum = crc32(0, new_data, size);
2649
2650 FNTSUM(new_data) = csum;
2651 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002652 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 struct vc_data *tmp = vc_cons[i].d;
2654
2655 if (fb_display[i].userfont &&
2656 fb_display[i].fontdata &&
2657 FNTSUM(fb_display[i].fontdata) == csum &&
2658 FNTSIZE(fb_display[i].fontdata) == size &&
2659 tmp->vc_font.width == w &&
2660 !memcmp(fb_display[i].fontdata, new_data, size)) {
2661 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002662 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 break;
2664 }
2665 }
2666 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2667}
2668
2669static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2670{
2671 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002672 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
2674 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002675 f = get_default_font(info->var.xres, info->var.yres,
2676 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 else if (!(f = find_font(name)))
2678 return -ENOENT;
2679
2680 font->width = f->width;
2681 font->height = f->height;
2682 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2683}
2684
2685static u16 palette_red[16];
2686static u16 palette_green[16];
2687static u16 palette_blue[16];
2688
2689static struct fb_cmap palette_cmap = {
2690 0, 16, palette_red, palette_green, palette_blue, NULL
2691};
2692
2693static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2694{
2695 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2696 int i, j, k, depth;
2697 u8 val;
2698
2699 if (fbcon_is_inactive(vc, info))
2700 return -EINVAL;
2701
2702 if (!CON_IS_VISIBLE(vc))
2703 return 0;
2704
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002705 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 if (depth > 3) {
2707 for (i = j = 0; i < 16; i++) {
2708 k = table[i];
2709 val = vc->vc_palette[j++];
2710 palette_red[k] = (val << 8) | val;
2711 val = vc->vc_palette[j++];
2712 palette_green[k] = (val << 8) | val;
2713 val = vc->vc_palette[j++];
2714 palette_blue[k] = (val << 8) | val;
2715 }
2716 palette_cmap.len = 16;
2717 palette_cmap.start = 0;
2718 /*
2719 * If framebuffer is capable of less than 16 colors,
2720 * use default palette of fbcon.
2721 */
2722 } else
2723 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2724
2725 return fb_set_cmap(&palette_cmap, info);
2726}
2727
2728static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2729{
2730 unsigned long p;
2731 int line;
2732
2733 if (vc->vc_num != fg_console || !softback_lines)
2734 return (u16 *) (vc->vc_origin + offset);
2735 line = offset / vc->vc_size_row;
2736 if (line >= softback_lines)
2737 return (u16 *) (vc->vc_origin + offset -
2738 softback_lines * vc->vc_size_row);
2739 p = softback_curr + offset;
2740 if (p >= softback_end)
2741 p += softback_buf - softback_end;
2742 return (u16 *) p;
2743}
2744
2745static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2746 int *px, int *py)
2747{
2748 unsigned long ret;
2749 int x, y;
2750
2751 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2752 unsigned long offset = (pos - vc->vc_origin) / 2;
2753
2754 x = offset % vc->vc_cols;
2755 y = offset / vc->vc_cols;
2756 if (vc->vc_num == fg_console)
2757 y += softback_lines;
2758 ret = pos + (vc->vc_cols - x) * 2;
2759 } else if (vc->vc_num == fg_console && softback_lines) {
2760 unsigned long offset = pos - softback_curr;
2761
2762 if (pos < softback_curr)
2763 offset += softback_end - softback_buf;
2764 offset /= 2;
2765 x = offset % vc->vc_cols;
2766 y = offset / vc->vc_cols;
2767 ret = pos + (vc->vc_cols - x) * 2;
2768 if (ret == softback_end)
2769 ret = softback_buf;
2770 if (ret == softback_in)
2771 ret = vc->vc_origin;
2772 } else {
2773 /* Should not happen */
2774 x = y = 0;
2775 ret = vc->vc_origin;
2776 }
2777 if (px)
2778 *px = x;
2779 if (py)
2780 *py = y;
2781 return ret;
2782}
2783
2784/* As we might be inside of softback, we may work with non-contiguous buffer,
2785 that's why we have to use a separate routine. */
2786static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2787{
2788 while (cnt--) {
2789 u16 a = scr_readw(p);
2790 if (!vc->vc_can_do_color)
2791 a ^= 0x0800;
2792 else if (vc->vc_hi_font_mask == 0x100)
2793 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2794 (((a) & 0x0e00) << 4);
2795 else
2796 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2797 (((a) & 0x0700) << 4);
2798 scr_writew(a, p++);
2799 if (p == (u16 *) softback_end)
2800 p = (u16 *) softback_buf;
2801 if (p == (u16 *) softback_in)
2802 p = (u16 *) vc->vc_origin;
2803 }
2804}
2805
2806static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2807{
2808 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002809 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002810 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 int offset, limit, scrollback_old;
2812
2813 if (softback_top) {
2814 if (vc->vc_num != fg_console)
2815 return 0;
2816 if (vc->vc_mode != KD_TEXT || !lines)
2817 return 0;
2818 if (logo_shown >= 0) {
2819 struct vc_data *conp2 = vc_cons[logo_shown].d;
2820
2821 if (conp2->vc_top == logo_lines
2822 && conp2->vc_bottom == conp2->vc_rows)
2823 conp2->vc_top = 0;
2824 if (logo_shown == vc->vc_num) {
2825 unsigned long p, q;
2826 int i;
2827
2828 p = softback_in;
2829 q = vc->vc_origin +
2830 logo_lines * vc->vc_size_row;
2831 for (i = 0; i < logo_lines; i++) {
2832 if (p == softback_top)
2833 break;
2834 if (p == softback_buf)
2835 p = softback_end;
2836 p -= vc->vc_size_row;
2837 q -= vc->vc_size_row;
2838 scr_memcpyw((u16 *) q, (u16 *) p,
2839 vc->vc_size_row);
2840 }
David Hollister308af922006-05-30 21:25:36 -07002841 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 update_region(vc, vc->vc_origin,
2843 logo_lines * vc->vc_cols);
2844 }
2845 logo_shown = FBCON_LOGO_CANSHOW;
2846 }
2847 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002848 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2850 return 0;
2851 }
2852
2853 if (!scrollback_phys_max)
2854 return -ENOSYS;
2855
2856 scrollback_old = scrollback_current;
2857 scrollback_current -= lines;
2858 if (scrollback_current < 0)
2859 scrollback_current = 0;
2860 else if (scrollback_current > scrollback_max)
2861 scrollback_current = scrollback_max;
2862 if (scrollback_current == scrollback_old)
2863 return 0;
2864
2865 if (fbcon_is_inactive(vc, info))
2866 return 0;
2867
2868 fbcon_cursor(vc, CM_ERASE);
2869
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002870 offset = disp->yscroll - scrollback_current;
2871 limit = disp->vrows;
2872 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 case SCROLL_WRAP_MOVE:
2874 info->var.vmode |= FB_VMODE_YWRAP;
2875 break;
2876 case SCROLL_PAN_MOVE:
2877 case SCROLL_PAN_REDRAW:
2878 limit -= vc->vc_rows;
2879 info->var.vmode &= ~FB_VMODE_YWRAP;
2880 break;
2881 }
2882 if (offset < 0)
2883 offset += limit;
2884 else if (offset >= limit)
2885 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002886
2887 ops->var.xoffset = 0;
2888 ops->var.yoffset = offset * vc->vc_font.height;
2889 ops->update_start(info);
2890
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 if (!scrollback_current)
2892 fbcon_cursor(vc, CM_DRAW);
2893 return 0;
2894}
2895
2896static int fbcon_set_origin(struct vc_data *vc)
2897{
2898 if (softback_lines)
2899 fbcon_scrolldelta(vc, softback_lines);
2900 return 0;
2901}
2902
2903static void fbcon_suspended(struct fb_info *info)
2904{
2905 struct vc_data *vc = NULL;
2906 struct fbcon_ops *ops = info->fbcon_par;
2907
2908 if (!ops || ops->currcon < 0)
2909 return;
2910 vc = vc_cons[ops->currcon].d;
2911
2912 /* Clear cursor, restore saved data */
2913 fbcon_cursor(vc, CM_ERASE);
2914}
2915
2916static void fbcon_resumed(struct fb_info *info)
2917{
2918 struct vc_data *vc;
2919 struct fbcon_ops *ops = info->fbcon_par;
2920
2921 if (!ops || ops->currcon < 0)
2922 return;
2923 vc = vc_cons[ops->currcon].d;
2924
2925 update_screen(vc);
2926}
2927
2928static void fbcon_modechanged(struct fb_info *info)
2929{
2930 struct fbcon_ops *ops = info->fbcon_par;
2931 struct vc_data *vc;
2932 struct display *p;
2933 int rows, cols;
2934
2935 if (!ops || ops->currcon < 0)
2936 return;
2937 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002938 if (vc->vc_mode != KD_TEXT ||
2939 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return;
2941
2942 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002943 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944
2945 if (CON_IS_VISIBLE(vc)) {
2946 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002947 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2948 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2949 cols /= vc->vc_font.width;
2950 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 vc_resize(vc, cols, rows);
2952 updatescrollmode(p, info, vc);
2953 scrollback_max = 0;
2954 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002955
2956 if (!fbcon_is_inactive(vc, info)) {
2957 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2958 ops->update_start(info);
2959 }
2960
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 fbcon_set_palette(vc, color_table);
2962 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002963 if (softback_buf)
2964 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966}
2967
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002968static void fbcon_set_all_vcs(struct fb_info *info)
2969{
2970 struct fbcon_ops *ops = info->fbcon_par;
2971 struct vc_data *vc;
2972 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002973 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002974
2975 if (!ops || ops->currcon < 0)
2976 return;
2977
Antonino A. Daplase614b182006-06-26 00:27:09 -07002978 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002979 vc = vc_cons[i].d;
2980 if (!vc || vc->vc_mode != KD_TEXT ||
2981 registered_fb[con2fb_map[i]] != info)
2982 continue;
2983
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002984 if (CON_IS_VISIBLE(vc)) {
2985 fg = i;
2986 continue;
2987 }
2988
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002989 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002990 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002991 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002992 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2993 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002994 cols /= vc->vc_font.width;
2995 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002996 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002997 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002998
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002999 if (fg != -1)
3000 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003001}
3002
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003static int fbcon_mode_deleted(struct fb_info *info,
3004 struct fb_videomode *mode)
3005{
3006 struct fb_info *fb_info;
3007 struct display *p;
3008 int i, j, found = 0;
3009
3010 /* before deletion, ensure that mode is not in use */
3011 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3012 j = con2fb_map[i];
3013 if (j == -1)
3014 continue;
3015 fb_info = registered_fb[j];
3016 if (fb_info != info)
3017 continue;
3018 p = &fb_display[i];
3019 if (!p || !p->mode)
3020 continue;
3021 if (fb_mode_is_equal(p->mode, mode)) {
3022 found = 1;
3023 break;
3024 }
3025 }
3026 return found;
3027}
3028
Jesse Barnescfafca82007-07-17 04:05:33 -07003029#ifdef CONFIG_VT_HW_CONSOLE_BINDING
3030static int fbcon_unbind(void)
3031{
3032 int ret;
3033
3034 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3035 fbcon_is_default);
3036 return ret;
3037}
3038#else
3039static inline int fbcon_unbind(void)
3040{
3041 return -EINVAL;
3042}
3043#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3044
3045static int fbcon_fb_unbind(int idx)
3046{
3047 int i, new_idx = -1, ret = 0;
3048
3049 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3050 if (con2fb_map[i] != idx &&
3051 con2fb_map[i] != -1) {
3052 new_idx = i;
3053 break;
3054 }
3055 }
3056
3057 if (new_idx != -1) {
3058 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3059 if (con2fb_map[i] == idx)
3060 set_con2fb_map(i, new_idx, 0);
3061 }
3062 } else
3063 ret = fbcon_unbind();
3064
3065 return ret;
3066}
3067
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003068static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003069{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003070 int i, idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003071
3072 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3073 if (con2fb_map[i] == idx)
3074 con2fb_map[i] = -1;
3075 }
3076
3077 if (idx == info_idx) {
3078 info_idx = -1;
3079
3080 for (i = 0; i < FB_MAX; i++) {
3081 if (registered_fb[i] != NULL) {
3082 info_idx = i;
3083 break;
3084 }
3085 }
3086 }
3087
3088 if (info_idx != -1) {
3089 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3090 if (con2fb_map[i] == -1)
3091 con2fb_map[i] = info_idx;
3092 }
3093 }
3094
3095 if (!num_registered_fb)
3096 unregister_con_driver(&fb_con);
3097
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003098
3099 if (primary_device == idx)
3100 primary_device = -1;
3101
Antonino A. Daplase614b182006-06-26 00:27:09 -07003102 return 0;
3103}
3104
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003105#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003106static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003108 if (!map_override && primary_device == -1 &&
3109 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003110 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003111
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003112 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3113 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003114 primary_device = info->node;
3115
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003116 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003117 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003118
3119 if (con_is_bound(&fb_con)) {
3120 printk(KERN_INFO "fbcon: Remapping primary device, "
3121 "fb%i, to tty %i-%i\n", info->node,
3122 first_fb_vc + 1, last_fb_vc + 1);
3123 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003124 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003125 }
3126
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003127}
3128#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003129static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003130{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003131 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003132}
3133#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3134
3135static int fbcon_fb_registered(struct fb_info *info)
3136{
3137 int ret = 0, i, idx = info->node;
3138
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003139 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
3141 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003142 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 if (con2fb_map_boot[i] == idx) {
3144 info_idx = idx;
3145 break;
3146 }
3147 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003148
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 if (info_idx != -1)
3150 ret = fbcon_takeover(1);
3151 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003152 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003153 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 set_con2fb_map(i, idx, 0);
3155 }
3156 }
3157
3158 return ret;
3159}
3160
3161static void fbcon_fb_blanked(struct fb_info *info, int blank)
3162{
3163 struct fbcon_ops *ops = info->fbcon_par;
3164 struct vc_data *vc;
3165
3166 if (!ops || ops->currcon < 0)
3167 return;
3168
3169 vc = vc_cons[ops->currcon].d;
3170 if (vc->vc_mode != KD_TEXT ||
3171 registered_fb[con2fb_map[ops->currcon]] != info)
3172 return;
3173
3174 if (CON_IS_VISIBLE(vc)) {
3175 if (blank)
3176 do_blank_screen(0);
3177 else
3178 do_unblank_screen(0);
3179 }
3180 ops->blank_state = blank;
3181}
3182
3183static void fbcon_new_modelist(struct fb_info *info)
3184{
3185 int i;
3186 struct vc_data *vc;
3187 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003188 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
Antonino A. Daplase614b182006-06-26 00:27:09 -07003190 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 if (registered_fb[con2fb_map[i]] != info)
3192 continue;
3193 if (!fb_display[i].mode)
3194 continue;
3195 vc = vc_cons[i].d;
3196 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003197 mode = fb_find_nearest_mode(fb_display[i].mode,
3198 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003200 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 }
3202}
3203
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003204static void fbcon_get_requirement(struct fb_info *info,
3205 struct fb_blit_caps *caps)
3206{
3207 struct vc_data *vc;
3208 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003209
3210 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003211 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003212
3213 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3214 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003215 if (vc && vc->vc_mode == KD_TEXT &&
3216 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003217 p = &fb_display[i];
3218 caps->x |= 1 << (vc->vc_font.width - 1);
3219 caps->y |= 1 << (vc->vc_font.height - 1);
3220 charcnt = (p->userfont) ?
3221 FNTCHARCNT(p->fontdata) : 256;
3222 if (caps->len < charcnt)
3223 caps->len = charcnt;
3224 }
3225 }
3226 } else {
3227 vc = vc_cons[fg_console].d;
3228
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003229 if (vc && vc->vc_mode == KD_TEXT &&
3230 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003231 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003232 caps->x = 1 << (vc->vc_font.width - 1);
3233 caps->y = 1 << (vc->vc_font.height - 1);
3234 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003235 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003236 }
3237 }
3238}
3239
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240static int fbcon_event_notify(struct notifier_block *self,
3241 unsigned long action, void *data)
3242{
3243 struct fb_event *event = data;
3244 struct fb_info *info = event->info;
3245 struct fb_videomode *mode;
3246 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003247 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 int ret = 0;
3249
Antonino A. Daplase614b182006-06-26 00:27:09 -07003250 /*
3251 * ignore all events except driver registration and deregistration
3252 * if fbcon is not active
3253 */
3254 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3255 action == FB_EVENT_FB_UNREGISTERED))
3256 goto done;
3257
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 switch(action) {
3259 case FB_EVENT_SUSPEND:
3260 fbcon_suspended(info);
3261 break;
3262 case FB_EVENT_RESUME:
3263 fbcon_resumed(info);
3264 break;
3265 case FB_EVENT_MODE_CHANGE:
3266 fbcon_modechanged(info);
3267 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003268 case FB_EVENT_MODE_CHANGE_ALL:
3269 fbcon_set_all_vcs(info);
3270 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 case FB_EVENT_MODE_DELETE:
3272 mode = event->data;
3273 ret = fbcon_mode_deleted(info, mode);
3274 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003275 case FB_EVENT_FB_UNBIND:
3276 ret = fbcon_fb_unbind(info->node);
3277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003279 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003281 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003282 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003283 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 case FB_EVENT_SET_CONSOLE_MAP:
3285 con2fb = event->data;
3286 ret = set_con2fb_map(con2fb->console - 1,
3287 con2fb->framebuffer, 1);
3288 break;
3289 case FB_EVENT_GET_CONSOLE_MAP:
3290 con2fb = event->data;
3291 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3292 break;
3293 case FB_EVENT_BLANK:
3294 fbcon_fb_blanked(info, *(int *)event->data);
3295 break;
3296 case FB_EVENT_NEW_MODELIST:
3297 fbcon_new_modelist(info);
3298 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003299 case FB_EVENT_GET_REQ:
3300 caps = event->data;
3301 fbcon_get_requirement(info, caps);
3302 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 }
3304
Antonino A. Daplase614b182006-06-26 00:27:09 -07003305done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 return ret;
3307}
3308
3309/*
3310 * The console `switch' structure for the frame buffer based console
3311 */
3312
3313static const struct consw fb_con = {
3314 .owner = THIS_MODULE,
3315 .con_startup = fbcon_startup,
3316 .con_init = fbcon_init,
3317 .con_deinit = fbcon_deinit,
3318 .con_clear = fbcon_clear,
3319 .con_putc = fbcon_putc,
3320 .con_putcs = fbcon_putcs,
3321 .con_cursor = fbcon_cursor,
3322 .con_scroll = fbcon_scroll,
3323 .con_bmove = fbcon_bmove,
3324 .con_switch = fbcon_switch,
3325 .con_blank = fbcon_blank,
3326 .con_font_set = fbcon_set_font,
3327 .con_font_get = fbcon_get_font,
3328 .con_font_default = fbcon_set_def_font,
3329 .con_font_copy = fbcon_copy_font,
3330 .con_set_palette = fbcon_set_palette,
3331 .con_scrolldelta = fbcon_scrolldelta,
3332 .con_set_origin = fbcon_set_origin,
3333 .con_invert_region = fbcon_invert_region,
3334 .con_screen_pos = fbcon_screen_pos,
3335 .con_getxy = fbcon_getxy,
3336 .con_resize = fbcon_resize,
3337};
3338
3339static struct notifier_block fbcon_event_notifier = {
3340 .notifier_call = fbcon_event_notify,
3341};
3342
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003343static ssize_t store_rotate(struct device *device,
3344 struct device_attribute *attr, const char *buf,
3345 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003346{
3347 struct fb_info *info;
3348 int rotate, idx;
3349 char **last = NULL;
3350
Antonino A. Daplase614b182006-06-26 00:27:09 -07003351 if (fbcon_has_exited)
3352 return count;
3353
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003354 acquire_console_sem();
3355 idx = con2fb_map[fg_console];
3356
3357 if (idx == -1 || registered_fb[idx] == NULL)
3358 goto err;
3359
3360 info = registered_fb[idx];
3361 rotate = simple_strtoul(buf, last, 0);
3362 fbcon_rotate(info, rotate);
3363err:
3364 release_console_sem();
3365 return count;
3366}
3367
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003368static ssize_t store_rotate_all(struct device *device,
3369 struct device_attribute *attr,const char *buf,
3370 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003371{
3372 struct fb_info *info;
3373 int rotate, idx;
3374 char **last = NULL;
3375
Antonino A. Daplase614b182006-06-26 00:27:09 -07003376 if (fbcon_has_exited)
3377 return count;
3378
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003379 acquire_console_sem();
3380 idx = con2fb_map[fg_console];
3381
3382 if (idx == -1 || registered_fb[idx] == NULL)
3383 goto err;
3384
3385 info = registered_fb[idx];
3386 rotate = simple_strtoul(buf, last, 0);
3387 fbcon_rotate_all(info, rotate);
3388err:
3389 release_console_sem();
3390 return count;
3391}
3392
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003393static ssize_t show_rotate(struct device *device,
3394 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003395{
3396 struct fb_info *info;
3397 int rotate = 0, idx;
3398
Antonino A. Daplase614b182006-06-26 00:27:09 -07003399 if (fbcon_has_exited)
3400 return 0;
3401
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003402 acquire_console_sem();
3403 idx = con2fb_map[fg_console];
3404
3405 if (idx == -1 || registered_fb[idx] == NULL)
3406 goto err;
3407
3408 info = registered_fb[idx];
3409 rotate = fbcon_get_rotate(info);
3410err:
3411 release_console_sem();
3412 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3413}
3414
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003415static ssize_t show_cursor_blink(struct device *device,
3416 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003417{
3418 struct fb_info *info;
3419 struct fbcon_ops *ops;
3420 int idx, blink = -1;
3421
3422 if (fbcon_has_exited)
3423 return 0;
3424
3425 acquire_console_sem();
3426 idx = con2fb_map[fg_console];
3427
3428 if (idx == -1 || registered_fb[idx] == NULL)
3429 goto err;
3430
3431 info = registered_fb[idx];
3432 ops = info->fbcon_par;
3433
3434 if (!ops)
3435 goto err;
3436
3437 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3438err:
3439 release_console_sem();
3440 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3441}
3442
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003443static ssize_t store_cursor_blink(struct device *device,
3444 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003445 const char *buf, size_t count)
3446{
3447 struct fb_info *info;
3448 int blink, idx;
3449 char **last = NULL;
3450
3451 if (fbcon_has_exited)
3452 return count;
3453
3454 acquire_console_sem();
3455 idx = con2fb_map[fg_console];
3456
3457 if (idx == -1 || registered_fb[idx] == NULL)
3458 goto err;
3459
3460 info = registered_fb[idx];
3461
3462 if (!info->fbcon_par)
3463 goto err;
3464
3465 blink = simple_strtoul(buf, last, 0);
3466
3467 if (blink) {
3468 fbcon_cursor_noblink = 0;
3469 fbcon_add_cursor_timer(info);
3470 } else {
3471 fbcon_cursor_noblink = 1;
3472 fbcon_del_cursor_timer(info);
3473 }
3474
3475err:
3476 release_console_sem();
3477 return count;
3478}
3479
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003480static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003481 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3482 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003483 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3484 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003485};
3486
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003487static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003488{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003489 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003490
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003491 fbcon_has_sysfs = 1;
3492
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003493 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3494 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003495
3496 if (error)
3497 break;
3498 }
3499
3500 if (error) {
3501 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003502 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003503
3504 fbcon_has_sysfs = 0;
3505 }
3506
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003507 return 0;
3508}
3509
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003510static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003513 int i;
3514
3515 acquire_console_sem();
3516
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 for (i = 0; i < FB_MAX; i++) {
3518 if (registered_fb[i] != NULL) {
3519 info_idx = i;
3520 break;
3521 }
3522 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003523
3524 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 fbcon_takeover(0);
3526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527}
3528
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003529static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003530{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003531 struct fb_info *info;
3532 int i, j, mapped;
3533
Antonino A. Daplase614b182006-06-26 00:27:09 -07003534 if (fbcon_has_exited)
3535 return;
3536
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003537#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003538 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003539#endif
3540#ifdef CONFIG_MAC
3541 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003542 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003543#endif
3544
3545 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003546 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003547
3548 for (i = 0; i < FB_MAX; i++) {
3549 mapped = 0;
3550 info = registered_fb[i];
3551
3552 if (info == NULL)
3553 continue;
3554
Antonino A. Daplase614b182006-06-26 00:27:09 -07003555 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3556 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003557 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003558 }
3559
3560 if (mapped) {
3561 if (info->fbops->fb_release)
3562 info->fbops->fb_release(info, 0);
3563 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003564
3565 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003566 struct fbcon_ops *ops = info->fbcon_par;
3567
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003568 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003569 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003570 kfree(info->fbcon_par);
3571 info->fbcon_par = NULL;
3572 }
3573
3574 if (info->queue.func == fb_flashcursor)
3575 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003576 }
3577 }
3578
Antonino A. Daplase614b182006-06-26 00:27:09 -07003579 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003580}
3581
3582static int __init fb_console_init(void)
3583{
3584 int i;
3585
3586 acquire_console_sem();
3587 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman1e274402008-05-21 12:52:33 -07003588 fbcon_device = device_create_drvdata(fb_class, NULL, MKDEV(0, 0),
3589 NULL, "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003590
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003591 if (IS_ERR(fbcon_device)) {
3592 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003593 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003594 PTR_ERR(fbcon_device));
3595 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003596 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003597 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003598
3599 for (i = 0; i < MAX_NR_CONSOLES; i++)
3600 con2fb_map[i] = -1;
3601
3602 release_console_sem();
3603 fbcon_start();
3604 return 0;
3605}
3606
3607module_init(fb_console_init);
3608
3609#ifdef MODULE
3610
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003611static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003612{
3613 int i;
3614
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003615 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003616 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3617 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003618
3619 fbcon_has_sysfs = 0;
3620 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003621}
3622
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623static void __exit fb_console_exit(void)
3624{
3625 acquire_console_sem();
3626 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003627 fbcon_deinit_device();
3628 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003629 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003631 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632}
3633
3634module_exit(fb_console_exit);
3635
3636#endif
3637
3638MODULE_LICENSE("GPL");