blob: 64b3d30027b825395ee2320f70c2e33f7665a0cf [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
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001314 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1315 vc->vc_top = 0;
1316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 /* Split blits that cross physical y_wrap boundary */
1318
1319 y_break = p->vrows - p->yscroll;
1320 if (sy < y_break && sy + height - 1 >= y_break) {
1321 u_int b = y_break - sy;
1322 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1323 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1324 width);
1325 } else
1326 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1327}
1328
1329static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1330 int count, int ypos, int xpos)
1331{
1332 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1333 struct display *p = &fb_display[vc->vc_num];
1334 struct fbcon_ops *ops = info->fbcon_par;
1335
1336 if (!fbcon_is_inactive(vc, info))
1337 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1338 get_color(vc, info, scr_readw(s), 1),
1339 get_color(vc, info, scr_readw(s), 0));
1340}
1341
1342static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1343{
1344 unsigned short chr;
1345
1346 scr_writew(c, &chr);
1347 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1348}
1349
1350static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1351{
1352 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1353 struct fbcon_ops *ops = info->fbcon_par;
1354
1355 if (!fbcon_is_inactive(vc, info))
1356 ops->clear_margins(vc, info, bottom_only);
1357}
1358
1359static void fbcon_cursor(struct vc_data *vc, int mode)
1360{
1361 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1362 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 int y;
1364 int c = scr_readw((u16 *) vc->vc_pos);
1365
Michal Januszewskid1e23062007-05-08 00:38:07 -07001366 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 return;
1368
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001369 if (vc->vc_cursor_type & 0x10)
1370 fbcon_del_cursor_timer(info);
1371 else
1372 fbcon_add_cursor_timer(info);
1373
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1375 if (mode & CM_SOFTBACK) {
1376 mode &= ~CM_SOFTBACK;
1377 y = softback_lines;
1378 } else {
1379 if (softback_lines)
1380 fbcon_set_origin(vc);
1381 y = 0;
1382 }
1383
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001384 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 get_color(vc, info, c, 0));
1386 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1387}
1388
1389static int scrollback_phys_max = 0;
1390static int scrollback_max = 0;
1391static int scrollback_current = 0;
1392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001394 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001396 struct display *p, *t;
1397 struct vc_data **default_mode, *vc;
1398 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001399 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 int rows, cols, charcnt = 256;
1401
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001402 p = &fb_display[unit];
1403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 if (var_to_display(p, var, info))
1405 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001406
1407 vc = vc_cons[unit].d;
1408
1409 if (!vc)
1410 return;
1411
1412 default_mode = vc->vc_display_fg;
1413 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001415
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001417 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 vc->vc_font.width = (*default_mode)->vc_font.width;
1419 vc->vc_font.height = (*default_mode)->vc_font.height;
1420 p->userfont = t->userfont;
1421 if (p->userfont)
1422 REFCOUNT(p->fontdata)++;
1423 }
1424 if (p->userfont)
1425 charcnt = FNTCHARCNT(p->fontdata);
1426
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001427 var->activate = FB_ACTIVATE_NOW;
1428 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001429 var->yoffset = info->var.yoffset;
1430 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001431 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001432 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001433 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1435 if (charcnt == 256) {
1436 vc->vc_hi_font_mask = 0;
1437 } else {
1438 vc->vc_hi_font_mask = 0x100;
1439 if (vc->vc_can_do_color)
1440 vc->vc_complement_mask <<= 1;
1441 }
1442
1443 if (!*svc->vc_uni_pagedir_loc)
1444 con_set_default_unimap(svc);
1445 if (!*vc->vc_uni_pagedir_loc)
1446 con_copy_unimap(vc, svc);
1447
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001448 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1449 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1450 cols /= vc->vc_font.width;
1451 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001453
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 if (CON_IS_VISIBLE(vc)) {
1455 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001456 if (softback_buf)
1457 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459}
1460
1461static __inline__ void ywrap_up(struct vc_data *vc, int count)
1462{
1463 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001464 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 struct display *p = &fb_display[vc->vc_num];
1466
1467 p->yscroll += count;
1468 if (p->yscroll >= p->vrows) /* Deal with wrap */
1469 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001470 ops->var.xoffset = 0;
1471 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1472 ops->var.vmode |= FB_VMODE_YWRAP;
1473 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 scrollback_max += count;
1475 if (scrollback_max > scrollback_phys_max)
1476 scrollback_max = scrollback_phys_max;
1477 scrollback_current = 0;
1478}
1479
1480static __inline__ void ywrap_down(struct vc_data *vc, int count)
1481{
1482 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001483 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 struct display *p = &fb_display[vc->vc_num];
1485
1486 p->yscroll -= count;
1487 if (p->yscroll < 0) /* Deal with wrap */
1488 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001489 ops->var.xoffset = 0;
1490 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1491 ops->var.vmode |= FB_VMODE_YWRAP;
1492 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 scrollback_max -= count;
1494 if (scrollback_max < 0)
1495 scrollback_max = 0;
1496 scrollback_current = 0;
1497}
1498
1499static __inline__ void ypan_up(struct vc_data *vc, int count)
1500{
1501 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1502 struct display *p = &fb_display[vc->vc_num];
1503 struct fbcon_ops *ops = info->fbcon_par;
1504
1505 p->yscroll += count;
1506 if (p->yscroll > p->vrows - vc->vc_rows) {
1507 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1508 0, 0, 0, vc->vc_rows, vc->vc_cols);
1509 p->yscroll -= p->vrows - vc->vc_rows;
1510 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001511
1512 ops->var.xoffset = 0;
1513 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1514 ops->var.vmode &= ~FB_VMODE_YWRAP;
1515 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 fbcon_clear_margins(vc, 1);
1517 scrollback_max += count;
1518 if (scrollback_max > scrollback_phys_max)
1519 scrollback_max = scrollback_phys_max;
1520 scrollback_current = 0;
1521}
1522
1523static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1524{
1525 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001526 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001530
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 if (p->yscroll > p->vrows - vc->vc_rows) {
1532 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001534 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001535
1536 ops->var.xoffset = 0;
1537 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1538 ops->var.vmode &= ~FB_VMODE_YWRAP;
1539 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 fbcon_clear_margins(vc, 1);
1541 scrollback_max += count;
1542 if (scrollback_max > scrollback_phys_max)
1543 scrollback_max = scrollback_phys_max;
1544 scrollback_current = 0;
1545}
1546
1547static __inline__ void ypan_down(struct vc_data *vc, int count)
1548{
1549 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1550 struct display *p = &fb_display[vc->vc_num];
1551 struct fbcon_ops *ops = info->fbcon_par;
1552
1553 p->yscroll -= count;
1554 if (p->yscroll < 0) {
1555 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1556 0, vc->vc_rows, vc->vc_cols);
1557 p->yscroll += p->vrows - vc->vc_rows;
1558 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001559
1560 ops->var.xoffset = 0;
1561 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1562 ops->var.vmode &= ~FB_VMODE_YWRAP;
1563 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 fbcon_clear_margins(vc, 1);
1565 scrollback_max -= count;
1566 if (scrollback_max < 0)
1567 scrollback_max = 0;
1568 scrollback_current = 0;
1569}
1570
1571static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1572{
1573 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001574 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
1577 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 if (p->yscroll < 0) {
1580 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001582 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001583
1584 ops->var.xoffset = 0;
1585 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1586 ops->var.vmode &= ~FB_VMODE_YWRAP;
1587 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 fbcon_clear_margins(vc, 1);
1589 scrollback_max -= count;
1590 if (scrollback_max < 0)
1591 scrollback_max = 0;
1592 scrollback_current = 0;
1593}
1594
1595static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1596 long delta)
1597{
1598 int count = vc->vc_rows;
1599 unsigned short *d, *s;
1600 unsigned long n;
1601 int line = 0;
1602
1603 d = (u16 *) softback_curr;
1604 if (d == (u16 *) softback_in)
1605 d = (u16 *) vc->vc_origin;
1606 n = softback_curr + delta * vc->vc_size_row;
1607 softback_lines -= delta;
1608 if (delta < 0) {
1609 if (softback_curr < softback_top && n < softback_buf) {
1610 n += softback_end - softback_buf;
1611 if (n < softback_top) {
1612 softback_lines -=
1613 (softback_top - n) / vc->vc_size_row;
1614 n = softback_top;
1615 }
1616 } else if (softback_curr >= softback_top
1617 && n < softback_top) {
1618 softback_lines -=
1619 (softback_top - n) / vc->vc_size_row;
1620 n = softback_top;
1621 }
1622 } else {
1623 if (softback_curr > softback_in && n >= softback_end) {
1624 n += softback_buf - softback_end;
1625 if (n > softback_in) {
1626 n = softback_in;
1627 softback_lines = 0;
1628 }
1629 } else if (softback_curr <= softback_in && n > softback_in) {
1630 n = softback_in;
1631 softback_lines = 0;
1632 }
1633 }
1634 if (n == softback_curr)
1635 return;
1636 softback_curr = n;
1637 s = (u16 *) softback_curr;
1638 if (s == (u16 *) softback_in)
1639 s = (u16 *) vc->vc_origin;
1640 while (count--) {
1641 unsigned short *start;
1642 unsigned short *le;
1643 unsigned short c;
1644 int x = 0;
1645 unsigned short attr = 1;
1646
1647 start = s;
1648 le = advance_row(s, 1);
1649 do {
1650 c = scr_readw(s);
1651 if (attr != (c & 0xff00)) {
1652 attr = c & 0xff00;
1653 if (s > start) {
1654 fbcon_putcs(vc, start, s - start,
1655 line, x);
1656 x += s - start;
1657 start = s;
1658 }
1659 }
1660 if (c == scr_readw(d)) {
1661 if (s > start) {
1662 fbcon_putcs(vc, start, s - start,
1663 line, x);
1664 x += s - start + 1;
1665 start = s + 1;
1666 } else {
1667 x++;
1668 start++;
1669 }
1670 }
1671 s++;
1672 d++;
1673 } while (s < le);
1674 if (s > start)
1675 fbcon_putcs(vc, start, s - start, line, x);
1676 line++;
1677 if (d == (u16 *) softback_end)
1678 d = (u16 *) softback_buf;
1679 if (d == (u16 *) softback_in)
1680 d = (u16 *) vc->vc_origin;
1681 if (s == (u16 *) softback_end)
1682 s = (u16 *) softback_buf;
1683 if (s == (u16 *) softback_in)
1684 s = (u16 *) vc->vc_origin;
1685 }
1686}
1687
1688static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1689 int line, int count, int dy)
1690{
1691 unsigned short *s = (unsigned short *)
1692 (vc->vc_origin + vc->vc_size_row * line);
1693
1694 while (count--) {
1695 unsigned short *start = s;
1696 unsigned short *le = advance_row(s, 1);
1697 unsigned short c;
1698 int x = 0;
1699 unsigned short attr = 1;
1700
1701 do {
1702 c = scr_readw(s);
1703 if (attr != (c & 0xff00)) {
1704 attr = c & 0xff00;
1705 if (s > start) {
1706 fbcon_putcs(vc, start, s - start,
1707 dy, x);
1708 x += s - start;
1709 start = s;
1710 }
1711 }
1712 console_conditional_schedule();
1713 s++;
1714 } while (s < le);
1715 if (s > start)
1716 fbcon_putcs(vc, start, s - start, dy, x);
1717 console_conditional_schedule();
1718 dy++;
1719 }
1720}
1721
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001722static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1723 struct display *p, int line, int count, int ycount)
1724{
1725 int offset = ycount * vc->vc_cols;
1726 unsigned short *d = (unsigned short *)
1727 (vc->vc_origin + vc->vc_size_row * line);
1728 unsigned short *s = d + offset;
1729 struct fbcon_ops *ops = info->fbcon_par;
1730
1731 while (count--) {
1732 unsigned short *start = s;
1733 unsigned short *le = advance_row(s, 1);
1734 unsigned short c;
1735 int x = 0;
1736
1737 do {
1738 c = scr_readw(s);
1739
1740 if (c == scr_readw(d)) {
1741 if (s > start) {
1742 ops->bmove(vc, info, line + ycount, x,
1743 line, x, 1, s-start);
1744 x += s - start + 1;
1745 start = s + 1;
1746 } else {
1747 x++;
1748 start++;
1749 }
1750 }
1751
1752 scr_writew(c, d);
1753 console_conditional_schedule();
1754 s++;
1755 d++;
1756 } while (s < le);
1757 if (s > start)
1758 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1759 s-start);
1760 console_conditional_schedule();
1761 if (ycount > 0)
1762 line++;
1763 else {
1764 line--;
1765 /* NOTE: We subtract two lines from these pointers */
1766 s -= vc->vc_size_row;
1767 d -= vc->vc_size_row;
1768 }
1769 }
1770}
1771
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772static void fbcon_redraw(struct vc_data *vc, struct display *p,
1773 int line, int count, int offset)
1774{
1775 unsigned short *d = (unsigned short *)
1776 (vc->vc_origin + vc->vc_size_row * line);
1777 unsigned short *s = d + offset;
1778
1779 while (count--) {
1780 unsigned short *start = s;
1781 unsigned short *le = advance_row(s, 1);
1782 unsigned short c;
1783 int x = 0;
1784 unsigned short attr = 1;
1785
1786 do {
1787 c = scr_readw(s);
1788 if (attr != (c & 0xff00)) {
1789 attr = c & 0xff00;
1790 if (s > start) {
1791 fbcon_putcs(vc, start, s - start,
1792 line, x);
1793 x += s - start;
1794 start = s;
1795 }
1796 }
1797 if (c == scr_readw(d)) {
1798 if (s > start) {
1799 fbcon_putcs(vc, start, s - start,
1800 line, x);
1801 x += s - start + 1;
1802 start = s + 1;
1803 } else {
1804 x++;
1805 start++;
1806 }
1807 }
1808 scr_writew(c, d);
1809 console_conditional_schedule();
1810 s++;
1811 d++;
1812 } while (s < le);
1813 if (s > start)
1814 fbcon_putcs(vc, start, s - start, line, x);
1815 console_conditional_schedule();
1816 if (offset > 0)
1817 line++;
1818 else {
1819 line--;
1820 /* NOTE: We subtract two lines from these pointers */
1821 s -= vc->vc_size_row;
1822 d -= vc->vc_size_row;
1823 }
1824 }
1825}
1826
1827static inline void fbcon_softback_note(struct vc_data *vc, int t,
1828 int count)
1829{
1830 unsigned short *p;
1831
1832 if (vc->vc_num != fg_console)
1833 return;
1834 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1835
1836 while (count) {
1837 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1838 count--;
1839 p = advance_row(p, 1);
1840 softback_in += vc->vc_size_row;
1841 if (softback_in == softback_end)
1842 softback_in = softback_buf;
1843 if (softback_in == softback_top) {
1844 softback_top += vc->vc_size_row;
1845 if (softback_top == softback_end)
1846 softback_top = softback_buf;
1847 }
1848 }
1849 softback_curr = softback_in;
1850}
1851
1852static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1853 int count)
1854{
1855 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1856 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1858
1859 if (fbcon_is_inactive(vc, info))
1860 return -EINVAL;
1861
1862 fbcon_cursor(vc, CM_ERASE);
1863
1864 /*
1865 * ++Geert: Only use ywrap/ypan if the console is in text mode
1866 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1867 * whole screen (prevents flicker).
1868 */
1869
1870 switch (dir) {
1871 case SM_UP:
1872 if (count > vc->vc_rows) /* Maximum realistic size */
1873 count = vc->vc_rows;
1874 if (softback_top)
1875 fbcon_softback_note(vc, t, count);
1876 if (logo_shown >= 0)
1877 goto redraw_up;
1878 switch (p->scrollmode) {
1879 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001880 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1881 count);
1882 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1883 scr_memsetw((unsigned short *) (vc->vc_origin +
1884 vc->vc_size_row *
1885 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001886 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001887 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001888 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 break;
1890
1891 case SCROLL_WRAP_MOVE:
1892 if (b - t - count > 3 * vc->vc_rows >> 2) {
1893 if (t > 0)
1894 fbcon_bmove(vc, 0, 0, count, 0, t,
1895 vc->vc_cols);
1896 ywrap_up(vc, count);
1897 if (vc->vc_rows - b > 0)
1898 fbcon_bmove(vc, b - count, 0, b, 0,
1899 vc->vc_rows - b,
1900 vc->vc_cols);
1901 } else if (info->flags & FBINFO_READS_FAST)
1902 fbcon_bmove(vc, t + count, 0, t, 0,
1903 b - t - count, vc->vc_cols);
1904 else
1905 goto redraw_up;
1906 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1907 break;
1908
1909 case SCROLL_PAN_REDRAW:
1910 if ((p->yscroll + count <=
1911 2 * (p->vrows - vc->vc_rows))
1912 && ((!scroll_partial && (b - t == vc->vc_rows))
1913 || (scroll_partial
1914 && (b - t - count >
1915 3 * vc->vc_rows >> 2)))) {
1916 if (t > 0)
1917 fbcon_redraw_move(vc, p, 0, t, count);
1918 ypan_up_redraw(vc, t, count);
1919 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001920 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 vc->vc_rows - b, b);
1922 } else
1923 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1924 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1925 break;
1926
1927 case SCROLL_PAN_MOVE:
1928 if ((p->yscroll + count <=
1929 2 * (p->vrows - vc->vc_rows))
1930 && ((!scroll_partial && (b - t == vc->vc_rows))
1931 || (scroll_partial
1932 && (b - t - count >
1933 3 * vc->vc_rows >> 2)))) {
1934 if (t > 0)
1935 fbcon_bmove(vc, 0, 0, count, 0, t,
1936 vc->vc_cols);
1937 ypan_up(vc, count);
1938 if (vc->vc_rows - b > 0)
1939 fbcon_bmove(vc, b - count, 0, b, 0,
1940 vc->vc_rows - b,
1941 vc->vc_cols);
1942 } else if (info->flags & FBINFO_READS_FAST)
1943 fbcon_bmove(vc, t + count, 0, t, 0,
1944 b - t - count, vc->vc_cols);
1945 else
1946 goto redraw_up;
1947 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1948 break;
1949
1950 case SCROLL_REDRAW:
1951 redraw_up:
1952 fbcon_redraw(vc, p, t, b - t - count,
1953 count * vc->vc_cols);
1954 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1955 scr_memsetw((unsigned short *) (vc->vc_origin +
1956 vc->vc_size_row *
1957 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001958 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001960 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 }
1962 break;
1963
1964 case SM_DOWN:
1965 if (count > vc->vc_rows) /* Maximum realistic size */
1966 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001967 if (logo_shown >= 0)
1968 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 switch (p->scrollmode) {
1970 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001971 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1972 -count);
1973 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1974 scr_memsetw((unsigned short *) (vc->vc_origin +
1975 vc->vc_size_row *
1976 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001977 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001978 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001979 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 break;
1981
1982 case SCROLL_WRAP_MOVE:
1983 if (b - t - count > 3 * vc->vc_rows >> 2) {
1984 if (vc->vc_rows - b > 0)
1985 fbcon_bmove(vc, b, 0, b - count, 0,
1986 vc->vc_rows - b,
1987 vc->vc_cols);
1988 ywrap_down(vc, count);
1989 if (t > 0)
1990 fbcon_bmove(vc, count, 0, 0, 0, t,
1991 vc->vc_cols);
1992 } else if (info->flags & FBINFO_READS_FAST)
1993 fbcon_bmove(vc, t, 0, t + count, 0,
1994 b - t - count, vc->vc_cols);
1995 else
1996 goto redraw_down;
1997 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1998 break;
1999
2000 case SCROLL_PAN_MOVE:
2001 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2002 && ((!scroll_partial && (b - t == vc->vc_rows))
2003 || (scroll_partial
2004 && (b - t - count >
2005 3 * vc->vc_rows >> 2)))) {
2006 if (vc->vc_rows - b > 0)
2007 fbcon_bmove(vc, b, 0, b - count, 0,
2008 vc->vc_rows - b,
2009 vc->vc_cols);
2010 ypan_down(vc, count);
2011 if (t > 0)
2012 fbcon_bmove(vc, count, 0, 0, 0, t,
2013 vc->vc_cols);
2014 } else if (info->flags & FBINFO_READS_FAST)
2015 fbcon_bmove(vc, t, 0, t + count, 0,
2016 b - t - count, vc->vc_cols);
2017 else
2018 goto redraw_down;
2019 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2020 break;
2021
2022 case SCROLL_PAN_REDRAW:
2023 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2024 && ((!scroll_partial && (b - t == vc->vc_rows))
2025 || (scroll_partial
2026 && (b - t - count >
2027 3 * vc->vc_rows >> 2)))) {
2028 if (vc->vc_rows - b > 0)
2029 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2030 b - count);
2031 ypan_down_redraw(vc, t, count);
2032 if (t > 0)
2033 fbcon_redraw_move(vc, p, count, t, 0);
2034 } else
2035 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2036 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2037 break;
2038
2039 case SCROLL_REDRAW:
2040 redraw_down:
2041 fbcon_redraw(vc, p, b - 1, b - t - count,
2042 -count * vc->vc_cols);
2043 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2044 scr_memsetw((unsigned short *) (vc->vc_origin +
2045 vc->vc_size_row *
2046 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07002047 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07002049 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 }
2051 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07002052 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053}
2054
2055
2056static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2057 int height, int width)
2058{
2059 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2060 struct display *p = &fb_display[vc->vc_num];
2061
2062 if (fbcon_is_inactive(vc, info))
2063 return;
2064
2065 if (!width || !height)
2066 return;
2067
2068 /* Split blits that cross physical y_wrap case.
2069 * Pathological case involves 4 blits, better to use recursive
2070 * code rather than unrolled case
2071 *
2072 * Recursive invocations don't need to erase the cursor over and
2073 * over again, so we use fbcon_bmove_rec()
2074 */
2075 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2076 p->vrows - p->yscroll);
2077}
2078
2079static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2080 int dy, int dx, int height, int width, u_int y_break)
2081{
2082 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2083 struct fbcon_ops *ops = info->fbcon_par;
2084 u_int b;
2085
2086 if (sy < y_break && sy + height > y_break) {
2087 b = y_break - sy;
2088 if (dy < sy) { /* Avoid trashing self */
2089 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2090 y_break);
2091 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2092 height - b, width, y_break);
2093 } else {
2094 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2095 height - b, width, y_break);
2096 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2097 y_break);
2098 }
2099 return;
2100 }
2101
2102 if (dy < y_break && dy + height > y_break) {
2103 b = y_break - dy;
2104 if (dy < sy) { /* Avoid trashing self */
2105 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2106 y_break);
2107 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2108 height - b, width, y_break);
2109 } else {
2110 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2111 height - b, width, y_break);
2112 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2113 y_break);
2114 }
2115 return;
2116 }
2117 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2118 height, width);
2119}
2120
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002121static __inline__ void updatescrollmode(struct display *p,
2122 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 struct vc_data *vc)
2124{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002125 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 int fh = vc->vc_font.height;
2127 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002128 u16 t = 0;
2129 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2130 info->fix.xpanstep);
2131 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2132 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2133 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2134 info->var.xres_virtual);
2135 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2136 divides(ypan, vc->vc_font.height) && vyres > yres;
2137 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2138 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002139 divides(vc->vc_font.height, vyres) &&
2140 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002142 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2143 !(cap & FBINFO_HWACCEL_DISABLED);
2144 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2145 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002147 p->vrows = vyres/fh;
2148 if (yres > (fh * (vc->vc_rows + 1)))
2149 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2150 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 p->vrows--;
2152
2153 if (good_wrap || good_pan) {
2154 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002155 p->scrollmode = good_wrap ?
2156 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 else
2158 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2159 SCROLL_PAN_REDRAW;
2160 } else {
2161 if (reading_fast || (fast_copyarea && !fast_imageblit))
2162 p->scrollmode = SCROLL_MOVE;
2163 else
2164 p->scrollmode = SCROLL_REDRAW;
2165 }
2166}
2167
2168static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002169 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
2171 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002172 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct display *p = &fb_display[vc->vc_num];
2174 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002175 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002177 virt_w = FBCON_SWAP(ops->rotate, width, height);
2178 virt_h = FBCON_SWAP(ops->rotate, height, width);
2179 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2180 vc->vc_font.height);
2181 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2182 vc->vc_font.width);
2183 var.xres = virt_w * virt_fw;
2184 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 x_diff = info->var.xres - var.xres;
2186 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002187 if (x_diff < 0 || x_diff > virt_fw ||
2188 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002189 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
2191 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2192 mode = fb_find_best_mode(&var, &info->modelist);
2193 if (mode == NULL)
2194 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002195 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002197
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002198 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
2201 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2202 if (CON_IS_VISIBLE(vc)) {
2203 var.activate = FB_ACTIVATE_NOW |
2204 FB_ACTIVATE_FORCE;
2205 fb_set_var(info, &var);
2206 }
2207 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002208 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 }
2210 updatescrollmode(p, info, vc);
2211 return 0;
2212}
2213
2214static int fbcon_switch(struct vc_data *vc)
2215{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002216 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002217 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct display *p = &fb_display[vc->vc_num];
2219 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002220 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
2222 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002223 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 if (softback_lines)
2227 fbcon_set_origin(vc);
2228 softback_top = softback_curr = softback_in = softback_buf;
2229 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002230 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 }
2232
2233 if (logo_shown >= 0) {
2234 struct vc_data *conp2 = vc_cons[logo_shown].d;
2235
2236 if (conp2->vc_top == logo_lines
2237 && conp2->vc_bottom == conp2->vc_rows)
2238 conp2->vc_top = 0;
2239 logo_shown = FBCON_LOGO_CANSHOW;
2240 }
2241
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002242 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002243 if (prev_console != -1)
2244 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 /*
2246 * FIXME: If we have multiple fbdev's loaded, we need to
2247 * update all info->currcon. Perhaps, we can place this
2248 * in a centralized structure, but this might break some
2249 * drivers.
2250 *
2251 * info->currcon = vc->vc_num;
2252 */
2253 for (i = 0; i < FB_MAX; i++) {
2254 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002255 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002257 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 }
2259 }
2260 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2261 display_to_var(&var, p);
2262 var.activate = FB_ACTIVATE_NOW;
2263
2264 /*
2265 * make sure we don't unnecessarily trip the memcmp()
2266 * in fb_set_var()
2267 */
2268 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002269 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002271 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Knut Petersen39942fd2005-12-12 22:17:19 -08002273 if (old_info != NULL && (old_info != info ||
2274 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002275 if (info->fbops->fb_set_par)
2276 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002277
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002278 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002279 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002282 if (fbcon_is_inactive(vc, info) ||
2283 ops->blank_state != FB_BLANK_UNBLANK)
2284 fbcon_del_cursor_timer(info);
2285 else
2286 fbcon_add_cursor_timer(info);
2287
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002288 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002289 ops->cursor_reset = 1;
2290
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002291 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002292 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002293 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002296 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002298
2299 if (p->userfont)
2300 charcnt = FNTCHARCNT(vc->vc_font.data);
2301
2302 if (charcnt > 256)
2303 vc->vc_complement_mask <<= 1;
2304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 updatescrollmode(p, info, vc);
2306
2307 switch (p->scrollmode) {
2308 case SCROLL_WRAP_MOVE:
2309 scrollback_phys_max = p->vrows - vc->vc_rows;
2310 break;
2311 case SCROLL_PAN_MOVE:
2312 case SCROLL_PAN_REDRAW:
2313 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2314 if (scrollback_phys_max < 0)
2315 scrollback_phys_max = 0;
2316 break;
2317 default:
2318 scrollback_phys_max = 0;
2319 break;
2320 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002321
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 scrollback_max = 0;
2323 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002324
2325 if (!fbcon_is_inactive(vc, info)) {
2326 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2327 ops->update_start(info);
2328 }
2329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 fbcon_set_palette(vc, color_table);
2331 fbcon_clear_margins(vc, 0);
2332
2333 if (logo_shown == FBCON_LOGO_DRAW) {
2334
2335 logo_shown = fg_console;
2336 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002337 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 update_region(vc,
2339 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2340 vc->vc_size_row * (vc->vc_bottom -
2341 vc->vc_top) / 2);
2342 return 0;
2343 }
2344 return 1;
2345}
2346
2347static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2348 int blank)
2349{
Richard Purdie994efac2007-02-09 09:46:45 +00002350 struct fb_event event;
2351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 if (blank) {
2353 unsigned short charmask = vc->vc_hi_font_mask ?
2354 0x1ff : 0xff;
2355 unsigned short oldc;
2356
2357 oldc = vc->vc_video_erase_char;
2358 vc->vc_video_erase_char &= charmask;
2359 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2360 vc->vc_video_erase_char = oldc;
2361 }
Richard Purdie994efac2007-02-09 09:46:45 +00002362
2363
2364 event.info = info;
2365 event.data = &blank;
2366 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367}
2368
2369static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2370{
2371 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2372 struct fbcon_ops *ops = info->fbcon_par;
2373
2374 if (mode_switch) {
2375 struct fb_var_screeninfo var = info->var;
2376
2377 ops->graphics = 1;
2378
2379 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002380 if (info->fbops->fb_save_state)
2381 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2383 fb_set_var(info, &var);
2384 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002385 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002386 } else if (info->fbops->fb_restore_state)
2387 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 }
2389
2390 if (!fbcon_is_inactive(vc, info)) {
2391 if (ops->blank_state != blank) {
Krzysztof Heltaef7db42008-10-03 15:23:38 -07002392 int ret = 1;
2393
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 ops->blank_state = blank;
2395 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2396 ops->cursor_flash = (!blank);
2397
Krzysztof Heltaef7db42008-10-03 15:23:38 -07002398 if (info->fbops->fb_blank)
2399 ret = info->fbops->fb_blank(blank, info);
2400 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 fbcon_generic_blank(vc, info, blank);
2402 }
2403
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002404 if (!blank)
2405 update_screen(vc);
2406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002408 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002409 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002410 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002411 else
2412 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002413
2414 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2418{
2419 u8 *fontdata = vc->vc_font.data;
2420 u8 *data = font->data;
2421 int i, j;
2422
2423 font->width = vc->vc_font.width;
2424 font->height = vc->vc_font.height;
2425 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2426 if (!font->data)
2427 return 0;
2428
2429 if (font->width <= 8) {
2430 j = vc->vc_font.height;
2431 for (i = 0; i < font->charcount; i++) {
2432 memcpy(data, fontdata, j);
2433 memset(data + j, 0, 32 - j);
2434 data += 32;
2435 fontdata += j;
2436 }
2437 } else if (font->width <= 16) {
2438 j = vc->vc_font.height * 2;
2439 for (i = 0; i < font->charcount; i++) {
2440 memcpy(data, fontdata, j);
2441 memset(data + j, 0, 64 - j);
2442 data += 64;
2443 fontdata += j;
2444 }
2445 } else if (font->width <= 24) {
2446 for (i = 0; i < font->charcount; i++) {
2447 for (j = 0; j < vc->vc_font.height; j++) {
2448 *data++ = fontdata[0];
2449 *data++ = fontdata[1];
2450 *data++ = fontdata[2];
2451 fontdata += sizeof(u32);
2452 }
2453 memset(data, 0, 3 * (32 - j));
2454 data += 3 * (32 - j);
2455 }
2456 } else {
2457 j = vc->vc_font.height * 4;
2458 for (i = 0; i < font->charcount; i++) {
2459 memcpy(data, fontdata, j);
2460 memset(data + j, 0, 128 - j);
2461 data += 128;
2462 fontdata += j;
2463 }
2464 }
2465 return 0;
2466}
2467
2468static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002469 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
2471 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002472 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 struct display *p = &fb_display[vc->vc_num];
2474 int resize;
2475 int cnt;
2476 char *old_data = NULL;
2477
2478 if (CON_IS_VISIBLE(vc) && softback_lines)
2479 fbcon_set_origin(vc);
2480
2481 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2482 if (p->userfont)
2483 old_data = vc->vc_font.data;
2484 if (userfont)
2485 cnt = FNTCHARCNT(data);
2486 else
2487 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002488 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 if ((p->userfont = userfont))
2490 REFCOUNT(data)++;
2491 vc->vc_font.width = w;
2492 vc->vc_font.height = h;
2493 if (vc->vc_hi_font_mask && cnt == 256) {
2494 vc->vc_hi_font_mask = 0;
2495 if (vc->vc_can_do_color) {
2496 vc->vc_complement_mask >>= 1;
2497 vc->vc_s_complement_mask >>= 1;
2498 }
2499
2500 /* ++Edmund: reorder the attribute bits */
2501 if (vc->vc_can_do_color) {
2502 unsigned short *cp =
2503 (unsigned short *) vc->vc_origin;
2504 int count = vc->vc_screenbuf_size / 2;
2505 unsigned short c;
2506 for (; count > 0; count--, cp++) {
2507 c = scr_readw(cp);
2508 scr_writew(((c & 0xfe00) >> 1) |
2509 (c & 0xff), cp);
2510 }
2511 c = vc->vc_video_erase_char;
2512 vc->vc_video_erase_char =
2513 ((c & 0xfe00) >> 1) | (c & 0xff);
2514 vc->vc_attr >>= 1;
2515 }
2516 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2517 vc->vc_hi_font_mask = 0x100;
2518 if (vc->vc_can_do_color) {
2519 vc->vc_complement_mask <<= 1;
2520 vc->vc_s_complement_mask <<= 1;
2521 }
2522
2523 /* ++Edmund: reorder the attribute bits */
2524 {
2525 unsigned short *cp =
2526 (unsigned short *) vc->vc_origin;
2527 int count = vc->vc_screenbuf_size / 2;
2528 unsigned short c;
2529 for (; count > 0; count--, cp++) {
2530 unsigned short newc;
2531 c = scr_readw(cp);
2532 if (vc->vc_can_do_color)
2533 newc =
2534 ((c & 0xff00) << 1) | (c &
2535 0xff);
2536 else
2537 newc = c & ~0x100;
2538 scr_writew(newc, cp);
2539 }
2540 c = vc->vc_video_erase_char;
2541 if (vc->vc_can_do_color) {
2542 vc->vc_video_erase_char =
2543 ((c & 0xff00) << 1) | (c & 0xff);
2544 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002545 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 vc->vc_video_erase_char = c & ~0x100;
2547 }
2548
2549 }
2550
2551 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002552 int cols, rows;
2553
2554 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2555 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2556 cols /= w;
2557 rows /= h;
2558 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002559 if (CON_IS_VISIBLE(vc) && softback_buf)
2560 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 } else if (CON_IS_VISIBLE(vc)
2562 && vc->vc_mode == KD_TEXT) {
2563 fbcon_clear_margins(vc, 0);
2564 update_screen(vc);
2565 }
2566
2567 if (old_data && (--REFCOUNT(old_data) == 0))
2568 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2569 return 0;
2570}
2571
2572static int fbcon_copy_font(struct vc_data *vc, int con)
2573{
2574 struct display *od = &fb_display[con];
2575 struct console_font *f = &vc->vc_font;
2576
2577 if (od->fontdata == f->data)
2578 return 0; /* already the same font... */
2579 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2580}
2581
2582/*
2583 * User asked to set font; we are guaranteed that
2584 * a) width and height are in range 1..32
2585 * b) charcount does not exceed 512
2586 * but lets not assume that, since someone might someday want to use larger
2587 * fonts. And charcount of 512 is small for unicode support.
2588 *
2589 * However, user space gives the font in 32 rows , regardless of
2590 * actual font height. So a new API is needed if support for larger fonts
2591 * is ever implemented.
2592 */
2593
2594static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2595{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002596 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 unsigned charcount = font->charcount;
2598 int w = font->width;
2599 int h = font->height;
2600 int size;
2601 int i, csum;
2602 u8 *new_data, *data = font->data;
2603 int pitch = (font->width+7) >> 3;
2604
2605 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2606 * If not this check should be changed to charcount < 256 */
2607 if (charcount != 256 && charcount != 512)
2608 return -EINVAL;
2609
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002610 /* Make sure drawing engine can handle the font */
2611 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2612 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2613 return -EINVAL;
2614
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002615 /* Make sure driver can handle the font length */
2616 if (fbcon_invalid_charcount(info, charcount))
2617 return -EINVAL;
2618
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 size = h * pitch * charcount;
2620
2621 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2622
2623 if (!new_data)
2624 return -ENOMEM;
2625
2626 new_data += FONT_EXTRA_WORDS * sizeof(int);
2627 FNTSIZE(new_data) = size;
2628 FNTCHARCNT(new_data) = charcount;
2629 REFCOUNT(new_data) = 0; /* usage counter */
2630 for (i=0; i< charcount; i++) {
2631 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2632 }
2633
2634 /* Since linux has a nice crc32 function use it for counting font
2635 * checksums. */
2636 csum = crc32(0, new_data, size);
2637
2638 FNTSUM(new_data) = csum;
2639 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002640 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 struct vc_data *tmp = vc_cons[i].d;
2642
2643 if (fb_display[i].userfont &&
2644 fb_display[i].fontdata &&
2645 FNTSUM(fb_display[i].fontdata) == csum &&
2646 FNTSIZE(fb_display[i].fontdata) == size &&
2647 tmp->vc_font.width == w &&
2648 !memcmp(fb_display[i].fontdata, new_data, size)) {
2649 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002650 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 break;
2652 }
2653 }
2654 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2655}
2656
2657static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2658{
2659 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002660 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
2662 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002663 f = get_default_font(info->var.xres, info->var.yres,
2664 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 else if (!(f = find_font(name)))
2666 return -ENOENT;
2667
2668 font->width = f->width;
2669 font->height = f->height;
2670 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2671}
2672
2673static u16 palette_red[16];
2674static u16 palette_green[16];
2675static u16 palette_blue[16];
2676
2677static struct fb_cmap palette_cmap = {
2678 0, 16, palette_red, palette_green, palette_blue, NULL
2679};
2680
2681static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2682{
2683 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2684 int i, j, k, depth;
2685 u8 val;
2686
2687 if (fbcon_is_inactive(vc, info))
2688 return -EINVAL;
2689
2690 if (!CON_IS_VISIBLE(vc))
2691 return 0;
2692
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002693 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 if (depth > 3) {
2695 for (i = j = 0; i < 16; i++) {
2696 k = table[i];
2697 val = vc->vc_palette[j++];
2698 palette_red[k] = (val << 8) | val;
2699 val = vc->vc_palette[j++];
2700 palette_green[k] = (val << 8) | val;
2701 val = vc->vc_palette[j++];
2702 palette_blue[k] = (val << 8) | val;
2703 }
2704 palette_cmap.len = 16;
2705 palette_cmap.start = 0;
2706 /*
2707 * If framebuffer is capable of less than 16 colors,
2708 * use default palette of fbcon.
2709 */
2710 } else
2711 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2712
2713 return fb_set_cmap(&palette_cmap, info);
2714}
2715
2716static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2717{
2718 unsigned long p;
2719 int line;
2720
2721 if (vc->vc_num != fg_console || !softback_lines)
2722 return (u16 *) (vc->vc_origin + offset);
2723 line = offset / vc->vc_size_row;
2724 if (line >= softback_lines)
2725 return (u16 *) (vc->vc_origin + offset -
2726 softback_lines * vc->vc_size_row);
2727 p = softback_curr + offset;
2728 if (p >= softback_end)
2729 p += softback_buf - softback_end;
2730 return (u16 *) p;
2731}
2732
2733static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2734 int *px, int *py)
2735{
2736 unsigned long ret;
2737 int x, y;
2738
2739 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2740 unsigned long offset = (pos - vc->vc_origin) / 2;
2741
2742 x = offset % vc->vc_cols;
2743 y = offset / vc->vc_cols;
2744 if (vc->vc_num == fg_console)
2745 y += softback_lines;
2746 ret = pos + (vc->vc_cols - x) * 2;
2747 } else if (vc->vc_num == fg_console && softback_lines) {
2748 unsigned long offset = pos - softback_curr;
2749
2750 if (pos < softback_curr)
2751 offset += softback_end - softback_buf;
2752 offset /= 2;
2753 x = offset % vc->vc_cols;
2754 y = offset / vc->vc_cols;
2755 ret = pos + (vc->vc_cols - x) * 2;
2756 if (ret == softback_end)
2757 ret = softback_buf;
2758 if (ret == softback_in)
2759 ret = vc->vc_origin;
2760 } else {
2761 /* Should not happen */
2762 x = y = 0;
2763 ret = vc->vc_origin;
2764 }
2765 if (px)
2766 *px = x;
2767 if (py)
2768 *py = y;
2769 return ret;
2770}
2771
2772/* As we might be inside of softback, we may work with non-contiguous buffer,
2773 that's why we have to use a separate routine. */
2774static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2775{
2776 while (cnt--) {
2777 u16 a = scr_readw(p);
2778 if (!vc->vc_can_do_color)
2779 a ^= 0x0800;
2780 else if (vc->vc_hi_font_mask == 0x100)
2781 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2782 (((a) & 0x0e00) << 4);
2783 else
2784 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2785 (((a) & 0x0700) << 4);
2786 scr_writew(a, p++);
2787 if (p == (u16 *) softback_end)
2788 p = (u16 *) softback_buf;
2789 if (p == (u16 *) softback_in)
2790 p = (u16 *) vc->vc_origin;
2791 }
2792}
2793
2794static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2795{
2796 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002797 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002798 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 int offset, limit, scrollback_old;
2800
2801 if (softback_top) {
2802 if (vc->vc_num != fg_console)
2803 return 0;
2804 if (vc->vc_mode != KD_TEXT || !lines)
2805 return 0;
2806 if (logo_shown >= 0) {
2807 struct vc_data *conp2 = vc_cons[logo_shown].d;
2808
2809 if (conp2->vc_top == logo_lines
2810 && conp2->vc_bottom == conp2->vc_rows)
2811 conp2->vc_top = 0;
2812 if (logo_shown == vc->vc_num) {
2813 unsigned long p, q;
2814 int i;
2815
2816 p = softback_in;
2817 q = vc->vc_origin +
2818 logo_lines * vc->vc_size_row;
2819 for (i = 0; i < logo_lines; i++) {
2820 if (p == softback_top)
2821 break;
2822 if (p == softback_buf)
2823 p = softback_end;
2824 p -= vc->vc_size_row;
2825 q -= vc->vc_size_row;
2826 scr_memcpyw((u16 *) q, (u16 *) p,
2827 vc->vc_size_row);
2828 }
David Hollister308af922006-05-30 21:25:36 -07002829 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 update_region(vc, vc->vc_origin,
2831 logo_lines * vc->vc_cols);
2832 }
2833 logo_shown = FBCON_LOGO_CANSHOW;
2834 }
2835 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002836 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2838 return 0;
2839 }
2840
2841 if (!scrollback_phys_max)
2842 return -ENOSYS;
2843
2844 scrollback_old = scrollback_current;
2845 scrollback_current -= lines;
2846 if (scrollback_current < 0)
2847 scrollback_current = 0;
2848 else if (scrollback_current > scrollback_max)
2849 scrollback_current = scrollback_max;
2850 if (scrollback_current == scrollback_old)
2851 return 0;
2852
2853 if (fbcon_is_inactive(vc, info))
2854 return 0;
2855
2856 fbcon_cursor(vc, CM_ERASE);
2857
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002858 offset = disp->yscroll - scrollback_current;
2859 limit = disp->vrows;
2860 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 case SCROLL_WRAP_MOVE:
2862 info->var.vmode |= FB_VMODE_YWRAP;
2863 break;
2864 case SCROLL_PAN_MOVE:
2865 case SCROLL_PAN_REDRAW:
2866 limit -= vc->vc_rows;
2867 info->var.vmode &= ~FB_VMODE_YWRAP;
2868 break;
2869 }
2870 if (offset < 0)
2871 offset += limit;
2872 else if (offset >= limit)
2873 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002874
2875 ops->var.xoffset = 0;
2876 ops->var.yoffset = offset * vc->vc_font.height;
2877 ops->update_start(info);
2878
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 if (!scrollback_current)
2880 fbcon_cursor(vc, CM_DRAW);
2881 return 0;
2882}
2883
2884static int fbcon_set_origin(struct vc_data *vc)
2885{
2886 if (softback_lines)
2887 fbcon_scrolldelta(vc, softback_lines);
2888 return 0;
2889}
2890
2891static void fbcon_suspended(struct fb_info *info)
2892{
2893 struct vc_data *vc = NULL;
2894 struct fbcon_ops *ops = info->fbcon_par;
2895
2896 if (!ops || ops->currcon < 0)
2897 return;
2898 vc = vc_cons[ops->currcon].d;
2899
2900 /* Clear cursor, restore saved data */
2901 fbcon_cursor(vc, CM_ERASE);
2902}
2903
2904static void fbcon_resumed(struct fb_info *info)
2905{
2906 struct vc_data *vc;
2907 struct fbcon_ops *ops = info->fbcon_par;
2908
2909 if (!ops || ops->currcon < 0)
2910 return;
2911 vc = vc_cons[ops->currcon].d;
2912
2913 update_screen(vc);
2914}
2915
2916static void fbcon_modechanged(struct fb_info *info)
2917{
2918 struct fbcon_ops *ops = info->fbcon_par;
2919 struct vc_data *vc;
2920 struct display *p;
2921 int rows, cols;
2922
2923 if (!ops || ops->currcon < 0)
2924 return;
2925 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002926 if (vc->vc_mode != KD_TEXT ||
2927 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 return;
2929
2930 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002931 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933 if (CON_IS_VISIBLE(vc)) {
2934 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002935 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2936 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2937 cols /= vc->vc_font.width;
2938 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 vc_resize(vc, cols, rows);
2940 updatescrollmode(p, info, vc);
2941 scrollback_max = 0;
2942 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002943
2944 if (!fbcon_is_inactive(vc, info)) {
2945 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2946 ops->update_start(info);
2947 }
2948
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 fbcon_set_palette(vc, color_table);
2950 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002951 if (softback_buf)
2952 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 }
2954}
2955
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002956static void fbcon_set_all_vcs(struct fb_info *info)
2957{
2958 struct fbcon_ops *ops = info->fbcon_par;
2959 struct vc_data *vc;
2960 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002961 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002962
2963 if (!ops || ops->currcon < 0)
2964 return;
2965
Antonino A. Daplase614b182006-06-26 00:27:09 -07002966 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002967 vc = vc_cons[i].d;
2968 if (!vc || vc->vc_mode != KD_TEXT ||
2969 registered_fb[con2fb_map[i]] != info)
2970 continue;
2971
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002972 if (CON_IS_VISIBLE(vc)) {
2973 fg = i;
2974 continue;
2975 }
2976
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002977 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002978 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002979 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002980 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2981 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002982 cols /= vc->vc_font.width;
2983 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002984 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002985 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002986
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002987 if (fg != -1)
2988 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002989}
2990
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991static int fbcon_mode_deleted(struct fb_info *info,
2992 struct fb_videomode *mode)
2993{
2994 struct fb_info *fb_info;
2995 struct display *p;
2996 int i, j, found = 0;
2997
2998 /* before deletion, ensure that mode is not in use */
2999 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3000 j = con2fb_map[i];
3001 if (j == -1)
3002 continue;
3003 fb_info = registered_fb[j];
3004 if (fb_info != info)
3005 continue;
3006 p = &fb_display[i];
3007 if (!p || !p->mode)
3008 continue;
3009 if (fb_mode_is_equal(p->mode, mode)) {
3010 found = 1;
3011 break;
3012 }
3013 }
3014 return found;
3015}
3016
Jesse Barnescfafca82007-07-17 04:05:33 -07003017#ifdef CONFIG_VT_HW_CONSOLE_BINDING
3018static int fbcon_unbind(void)
3019{
3020 int ret;
3021
3022 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
3023 fbcon_is_default);
3024 return ret;
3025}
3026#else
3027static inline int fbcon_unbind(void)
3028{
3029 return -EINVAL;
3030}
3031#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3032
3033static int fbcon_fb_unbind(int idx)
3034{
3035 int i, new_idx = -1, ret = 0;
3036
3037 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3038 if (con2fb_map[i] != idx &&
3039 con2fb_map[i] != -1) {
3040 new_idx = i;
3041 break;
3042 }
3043 }
3044
3045 if (new_idx != -1) {
3046 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3047 if (con2fb_map[i] == idx)
3048 set_con2fb_map(i, new_idx, 0);
3049 }
3050 } else
3051 ret = fbcon_unbind();
3052
3053 return ret;
3054}
3055
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003056static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003057{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003058 int i, idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003059
3060 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3061 if (con2fb_map[i] == idx)
3062 con2fb_map[i] = -1;
3063 }
3064
3065 if (idx == info_idx) {
3066 info_idx = -1;
3067
3068 for (i = 0; i < FB_MAX; i++) {
3069 if (registered_fb[i] != NULL) {
3070 info_idx = i;
3071 break;
3072 }
3073 }
3074 }
3075
3076 if (info_idx != -1) {
3077 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3078 if (con2fb_map[i] == -1)
3079 con2fb_map[i] = info_idx;
3080 }
3081 }
3082
3083 if (!num_registered_fb)
3084 unregister_con_driver(&fb_con);
3085
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003086
3087 if (primary_device == idx)
3088 primary_device = -1;
3089
Antonino A. Daplase614b182006-06-26 00:27:09 -07003090 return 0;
3091}
3092
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003093#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003094static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003096 if (!map_override && primary_device == -1 &&
3097 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003098 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003099
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003100 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3101 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003102 primary_device = info->node;
3103
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003104 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003105 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003106
3107 if (con_is_bound(&fb_con)) {
3108 printk(KERN_INFO "fbcon: Remapping primary device, "
3109 "fb%i, to tty %i-%i\n", info->node,
3110 first_fb_vc + 1, last_fb_vc + 1);
3111 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003112 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003113 }
3114
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003115}
3116#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003117static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003118{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003119 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003120}
3121#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3122
3123static int fbcon_fb_registered(struct fb_info *info)
3124{
3125 int ret = 0, i, idx = info->node;
3126
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003127 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128
3129 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003130 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 if (con2fb_map_boot[i] == idx) {
3132 info_idx = idx;
3133 break;
3134 }
3135 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 if (info_idx != -1)
3138 ret = fbcon_takeover(1);
3139 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003140 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003141 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 set_con2fb_map(i, idx, 0);
3143 }
3144 }
3145
3146 return ret;
3147}
3148
3149static void fbcon_fb_blanked(struct fb_info *info, int blank)
3150{
3151 struct fbcon_ops *ops = info->fbcon_par;
3152 struct vc_data *vc;
3153
3154 if (!ops || ops->currcon < 0)
3155 return;
3156
3157 vc = vc_cons[ops->currcon].d;
3158 if (vc->vc_mode != KD_TEXT ||
3159 registered_fb[con2fb_map[ops->currcon]] != info)
3160 return;
3161
3162 if (CON_IS_VISIBLE(vc)) {
3163 if (blank)
3164 do_blank_screen(0);
3165 else
3166 do_unblank_screen(0);
3167 }
3168 ops->blank_state = blank;
3169}
3170
3171static void fbcon_new_modelist(struct fb_info *info)
3172{
3173 int i;
3174 struct vc_data *vc;
3175 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003176 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177
Antonino A. Daplase614b182006-06-26 00:27:09 -07003178 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 if (registered_fb[con2fb_map[i]] != info)
3180 continue;
3181 if (!fb_display[i].mode)
3182 continue;
3183 vc = vc_cons[i].d;
3184 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003185 mode = fb_find_nearest_mode(fb_display[i].mode,
3186 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003188 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 }
3190}
3191
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003192static void fbcon_get_requirement(struct fb_info *info,
3193 struct fb_blit_caps *caps)
3194{
3195 struct vc_data *vc;
3196 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003197
3198 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003199 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003200
3201 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3202 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003203 if (vc && vc->vc_mode == KD_TEXT &&
3204 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003205 p = &fb_display[i];
3206 caps->x |= 1 << (vc->vc_font.width - 1);
3207 caps->y |= 1 << (vc->vc_font.height - 1);
3208 charcnt = (p->userfont) ?
3209 FNTCHARCNT(p->fontdata) : 256;
3210 if (caps->len < charcnt)
3211 caps->len = charcnt;
3212 }
3213 }
3214 } else {
3215 vc = vc_cons[fg_console].d;
3216
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003217 if (vc && vc->vc_mode == KD_TEXT &&
3218 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003219 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003220 caps->x = 1 << (vc->vc_font.width - 1);
3221 caps->y = 1 << (vc->vc_font.height - 1);
3222 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003223 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003224 }
3225 }
3226}
3227
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228static int fbcon_event_notify(struct notifier_block *self,
3229 unsigned long action, void *data)
3230{
3231 struct fb_event *event = data;
3232 struct fb_info *info = event->info;
3233 struct fb_videomode *mode;
3234 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003235 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 int ret = 0;
3237
Antonino A. Daplase614b182006-06-26 00:27:09 -07003238 /*
3239 * ignore all events except driver registration and deregistration
3240 * if fbcon is not active
3241 */
3242 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3243 action == FB_EVENT_FB_UNREGISTERED))
3244 goto done;
3245
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 switch(action) {
3247 case FB_EVENT_SUSPEND:
3248 fbcon_suspended(info);
3249 break;
3250 case FB_EVENT_RESUME:
3251 fbcon_resumed(info);
3252 break;
3253 case FB_EVENT_MODE_CHANGE:
3254 fbcon_modechanged(info);
3255 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003256 case FB_EVENT_MODE_CHANGE_ALL:
3257 fbcon_set_all_vcs(info);
3258 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 case FB_EVENT_MODE_DELETE:
3260 mode = event->data;
3261 ret = fbcon_mode_deleted(info, mode);
3262 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003263 case FB_EVENT_FB_UNBIND:
3264 ret = fbcon_fb_unbind(info->node);
3265 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003267 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003269 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003270 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003271 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 case FB_EVENT_SET_CONSOLE_MAP:
3273 con2fb = event->data;
3274 ret = set_con2fb_map(con2fb->console - 1,
3275 con2fb->framebuffer, 1);
3276 break;
3277 case FB_EVENT_GET_CONSOLE_MAP:
3278 con2fb = event->data;
3279 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3280 break;
3281 case FB_EVENT_BLANK:
3282 fbcon_fb_blanked(info, *(int *)event->data);
3283 break;
3284 case FB_EVENT_NEW_MODELIST:
3285 fbcon_new_modelist(info);
3286 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003287 case FB_EVENT_GET_REQ:
3288 caps = event->data;
3289 fbcon_get_requirement(info, caps);
3290 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 }
3292
Antonino A. Daplase614b182006-06-26 00:27:09 -07003293done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 return ret;
3295}
3296
3297/*
3298 * The console `switch' structure for the frame buffer based console
3299 */
3300
3301static const struct consw fb_con = {
3302 .owner = THIS_MODULE,
3303 .con_startup = fbcon_startup,
3304 .con_init = fbcon_init,
3305 .con_deinit = fbcon_deinit,
3306 .con_clear = fbcon_clear,
3307 .con_putc = fbcon_putc,
3308 .con_putcs = fbcon_putcs,
3309 .con_cursor = fbcon_cursor,
3310 .con_scroll = fbcon_scroll,
3311 .con_bmove = fbcon_bmove,
3312 .con_switch = fbcon_switch,
3313 .con_blank = fbcon_blank,
3314 .con_font_set = fbcon_set_font,
3315 .con_font_get = fbcon_get_font,
3316 .con_font_default = fbcon_set_def_font,
3317 .con_font_copy = fbcon_copy_font,
3318 .con_set_palette = fbcon_set_palette,
3319 .con_scrolldelta = fbcon_scrolldelta,
3320 .con_set_origin = fbcon_set_origin,
3321 .con_invert_region = fbcon_invert_region,
3322 .con_screen_pos = fbcon_screen_pos,
3323 .con_getxy = fbcon_getxy,
3324 .con_resize = fbcon_resize,
3325};
3326
3327static struct notifier_block fbcon_event_notifier = {
3328 .notifier_call = fbcon_event_notify,
3329};
3330
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003331static ssize_t store_rotate(struct device *device,
3332 struct device_attribute *attr, const char *buf,
3333 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003334{
3335 struct fb_info *info;
3336 int rotate, idx;
3337 char **last = NULL;
3338
Antonino A. Daplase614b182006-06-26 00:27:09 -07003339 if (fbcon_has_exited)
3340 return count;
3341
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003342 acquire_console_sem();
3343 idx = con2fb_map[fg_console];
3344
3345 if (idx == -1 || registered_fb[idx] == NULL)
3346 goto err;
3347
3348 info = registered_fb[idx];
3349 rotate = simple_strtoul(buf, last, 0);
3350 fbcon_rotate(info, rotate);
3351err:
3352 release_console_sem();
3353 return count;
3354}
3355
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003356static ssize_t store_rotate_all(struct device *device,
3357 struct device_attribute *attr,const char *buf,
3358 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003359{
3360 struct fb_info *info;
3361 int rotate, idx;
3362 char **last = NULL;
3363
Antonino A. Daplase614b182006-06-26 00:27:09 -07003364 if (fbcon_has_exited)
3365 return count;
3366
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003367 acquire_console_sem();
3368 idx = con2fb_map[fg_console];
3369
3370 if (idx == -1 || registered_fb[idx] == NULL)
3371 goto err;
3372
3373 info = registered_fb[idx];
3374 rotate = simple_strtoul(buf, last, 0);
3375 fbcon_rotate_all(info, rotate);
3376err:
3377 release_console_sem();
3378 return count;
3379}
3380
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003381static ssize_t show_rotate(struct device *device,
3382 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003383{
3384 struct fb_info *info;
3385 int rotate = 0, idx;
3386
Antonino A. Daplase614b182006-06-26 00:27:09 -07003387 if (fbcon_has_exited)
3388 return 0;
3389
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003390 acquire_console_sem();
3391 idx = con2fb_map[fg_console];
3392
3393 if (idx == -1 || registered_fb[idx] == NULL)
3394 goto err;
3395
3396 info = registered_fb[idx];
3397 rotate = fbcon_get_rotate(info);
3398err:
3399 release_console_sem();
3400 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3401}
3402
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003403static ssize_t show_cursor_blink(struct device *device,
3404 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003405{
3406 struct fb_info *info;
3407 struct fbcon_ops *ops;
3408 int idx, blink = -1;
3409
3410 if (fbcon_has_exited)
3411 return 0;
3412
3413 acquire_console_sem();
3414 idx = con2fb_map[fg_console];
3415
3416 if (idx == -1 || registered_fb[idx] == NULL)
3417 goto err;
3418
3419 info = registered_fb[idx];
3420 ops = info->fbcon_par;
3421
3422 if (!ops)
3423 goto err;
3424
3425 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3426err:
3427 release_console_sem();
3428 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3429}
3430
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003431static ssize_t store_cursor_blink(struct device *device,
3432 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003433 const char *buf, size_t count)
3434{
3435 struct fb_info *info;
3436 int blink, idx;
3437 char **last = NULL;
3438
3439 if (fbcon_has_exited)
3440 return count;
3441
3442 acquire_console_sem();
3443 idx = con2fb_map[fg_console];
3444
3445 if (idx == -1 || registered_fb[idx] == NULL)
3446 goto err;
3447
3448 info = registered_fb[idx];
3449
3450 if (!info->fbcon_par)
3451 goto err;
3452
3453 blink = simple_strtoul(buf, last, 0);
3454
3455 if (blink) {
3456 fbcon_cursor_noblink = 0;
3457 fbcon_add_cursor_timer(info);
3458 } else {
3459 fbcon_cursor_noblink = 1;
3460 fbcon_del_cursor_timer(info);
3461 }
3462
3463err:
3464 release_console_sem();
3465 return count;
3466}
3467
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003468static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003469 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3470 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003471 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3472 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003473};
3474
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003475static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003476{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003477 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003478
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003479 fbcon_has_sysfs = 1;
3480
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003481 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3482 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003483
3484 if (error)
3485 break;
3486 }
3487
3488 if (error) {
3489 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003490 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003491
3492 fbcon_has_sysfs = 0;
3493 }
3494
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003495 return 0;
3496}
3497
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003498static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003501 int i;
3502
3503 acquire_console_sem();
3504
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 for (i = 0; i < FB_MAX; i++) {
3506 if (registered_fb[i] != NULL) {
3507 info_idx = i;
3508 break;
3509 }
3510 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003511
3512 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 fbcon_takeover(0);
3514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515}
3516
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003517static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003518{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003519 struct fb_info *info;
3520 int i, j, mapped;
3521
Antonino A. Daplase614b182006-06-26 00:27:09 -07003522 if (fbcon_has_exited)
3523 return;
3524
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003525#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003526 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003527#endif
3528#ifdef CONFIG_MAC
3529 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003530 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003531#endif
3532
3533 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003534 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003535
3536 for (i = 0; i < FB_MAX; i++) {
3537 mapped = 0;
3538 info = registered_fb[i];
3539
3540 if (info == NULL)
3541 continue;
3542
Antonino A. Daplase614b182006-06-26 00:27:09 -07003543 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3544 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003545 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003546 }
3547
3548 if (mapped) {
3549 if (info->fbops->fb_release)
3550 info->fbops->fb_release(info, 0);
3551 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003552
3553 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003554 struct fbcon_ops *ops = info->fbcon_par;
3555
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003556 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003557 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003558 kfree(info->fbcon_par);
3559 info->fbcon_par = NULL;
3560 }
3561
3562 if (info->queue.func == fb_flashcursor)
3563 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003564 }
3565 }
3566
Antonino A. Daplase614b182006-06-26 00:27:09 -07003567 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003568}
3569
3570static int __init fb_console_init(void)
3571{
3572 int i;
3573
3574 acquire_console_sem();
3575 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003576 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3577 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003578
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003579 if (IS_ERR(fbcon_device)) {
3580 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003581 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003582 PTR_ERR(fbcon_device));
3583 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003584 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003585 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003586
3587 for (i = 0; i < MAX_NR_CONSOLES; i++)
3588 con2fb_map[i] = -1;
3589
3590 release_console_sem();
3591 fbcon_start();
3592 return 0;
3593}
3594
3595module_init(fb_console_init);
3596
3597#ifdef MODULE
3598
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003599static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003600{
3601 int i;
3602
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003603 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003604 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3605 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003606
3607 fbcon_has_sysfs = 0;
3608 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003609}
3610
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611static void __exit fb_console_exit(void)
3612{
3613 acquire_console_sem();
3614 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003615 fbcon_deinit_device();
3616 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003617 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003619 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620}
3621
3622module_exit(fb_console_exit);
3623
3624#endif
3625
3626MODULE_LICENSE("GPL");