blob: 4bcff81b50e03afa91f6dbf8eeef0784a2f12f12 [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
Adrian Bunk7b892802008-02-06 01:36:29 -080084#if defined(__mc68000__)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#include <asm/machdep.h>
86#include <asm/setup.h>
87#endif
88
89#include "fbcon.h"
90
91#ifdef FBCONDEBUG
Harvey Harrison5ae12172008-04-28 02:15:47 -070092# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#else
94# define DPRINTK(fmt, args...)
95#endif
96
97enum {
98 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
99 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
100 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
101};
102
Antonino A. Daplasab767202005-11-13 16:06:32 -0800103static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105static signed char con2fb_map[MAX_NR_CONSOLES];
106static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int logo_lines;
109/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
110 enums. */
111static int logo_shown = FBCON_LOGO_CANSHOW;
112/* Software scrollback */
113static int fbcon_softback_size = 32768;
114static unsigned long softback_buf, softback_curr;
115static unsigned long softback_in;
116static unsigned long softback_top, softback_end;
117static int softback_lines;
118/* console mappings */
119static int first_fb_vc;
120static int last_fb_vc = MAX_NR_CONSOLES - 1;
121static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700122static int fbcon_has_exited;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700123static int primary_device = -1;
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700124
125#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700126static int map_override;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700127
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700128static inline void fbcon_map_override(void)
129{
130 map_override = 1;
131}
132#else
133static inline void fbcon_map_override(void)
134{
135}
136#endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* font data */
139static char fontname[40];
140
141/* current fb_info */
142static int info_idx = -1;
143
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800144/* console rotation */
Marcin Slusarz2428e592008-02-06 01:39:14 -0800145static int initial_rotation;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700146static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static const struct consw fb_con;
149
150#define CM_SOFTBACK (8)
151
152#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154static int fbcon_set_origin(struct vc_data *);
155
156#define CURSOR_DRAW_DELAY (1)
157
158/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#define ATARI_CURSOR_BLINK_RATE (42)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161static int vbl_cursor_cnt;
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700162static int fbcon_cursor_noblink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
165
166/*
167 * Interface used by the world
168 */
169
170static const char *fbcon_startup(void);
171static void fbcon_init(struct vc_data *vc, int init);
172static void fbcon_deinit(struct vc_data *vc);
173static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
174 int width);
175static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
176static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
177 int count, int ypos, int xpos);
178static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
179static void fbcon_cursor(struct vc_data *vc, int mode);
180static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
181 int count);
182static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
183 int height, int width);
184static int fbcon_switch(struct vc_data *vc);
185static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
186static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
187static int fbcon_scrolldelta(struct vc_data *vc, int lines);
188
189/*
190 * Internal routines
191 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static __inline__ void ywrap_up(struct vc_data *vc, int count);
193static __inline__ void ywrap_down(struct vc_data *vc, int count);
194static __inline__ void ypan_up(struct vc_data *vc, int count);
195static __inline__ void ypan_down(struct vc_data *vc, int count);
196static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
197 int dy, int dx, int height, int width, u_int y_break);
198static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700199 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
201 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800202static void fbcon_modechanged(struct fb_info *info);
203static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700204static void fbcon_start(void);
205static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700206static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700207
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800208#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800209static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800210{
211 struct fbcon_ops *ops = info->fbcon_par;
212
213 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800214 ops->p->con_rotate < 4)
215 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800216 else
217 ops->rotate = 0;
218}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800219
220static void fbcon_rotate(struct fb_info *info, u32 rotate)
221{
222 struct fbcon_ops *ops= info->fbcon_par;
223 struct fb_info *fb_info;
224
225 if (!ops || ops->currcon == -1)
226 return;
227
228 fb_info = registered_fb[con2fb_map[ops->currcon]];
229
230 if (info == fb_info) {
231 struct display *p = &fb_display[ops->currcon];
232
233 if (rotate < 4)
234 p->con_rotate = rotate;
235 else
236 p->con_rotate = 0;
237
238 fbcon_modechanged(info);
239 }
240}
241
242static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
243{
244 struct fbcon_ops *ops = info->fbcon_par;
245 struct vc_data *vc;
246 struct display *p;
247 int i;
248
249 if (!ops || ops->currcon < 0 || rotate > 3)
250 return;
251
Antonino A. Daplase614b182006-06-26 00:27:09 -0700252 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800253 vc = vc_cons[i].d;
254 if (!vc || vc->vc_mode != KD_TEXT ||
255 registered_fb[con2fb_map[i]] != info)
256 continue;
257
258 p = &fb_display[vc->vc_num];
259 p->con_rotate = rotate;
260 }
261
262 fbcon_set_all_vcs(info);
263}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800264#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800265static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800266{
267 struct fbcon_ops *ops = info->fbcon_par;
268
269 ops->rotate = FB_ROTATE_UR;
270}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800271
272static void fbcon_rotate(struct fb_info *info, u32 rotate)
273{
274 return;
275}
276
277static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
278{
279 return;
280}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800281#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800282
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800283static int fbcon_get_rotate(struct fb_info *info)
284{
285 struct fbcon_ops *ops = info->fbcon_par;
286
287 return (ops) ? ops->rotate : 0;
288}
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
291{
292 struct fbcon_ops *ops = info->fbcon_par;
293
294 return (info->state != FBINFO_STATE_RUNNING ||
295 vc->vc_mode != KD_TEXT || ops->graphics);
296}
297
298static inline int get_color(struct vc_data *vc, struct fb_info *info,
299 u16 c, int is_fg)
300{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700301 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 int color = 0;
303
304 if (console_blanked) {
305 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
306
307 c = vc->vc_video_erase_char & charmask;
308 }
309
310 if (depth != 1)
311 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
312 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
313
314 switch (depth) {
315 case 1:
316 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800317 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700319 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
320 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 if (console_blanked)
323 fg = bg;
324
325 color = (is_fg) ? fg : bg;
326 break;
327 }
328 case 2:
329 /*
330 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700331 * is grayscale. However, simply dividing the values by 4
332 * will not work, as colors 1, 2 and 3 will be scaled-down
333 * to zero rendering them invisible. So empirically convert
334 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700336 switch (color) {
337 case 0:
338 color = 0; /* black */
339 break;
340 case 1 ... 6:
341 color = 2; /* white */
342 break;
343 case 7 ... 8:
344 color = 1; /* gray */
345 break;
346 default:
347 color = 3; /* intense white */
348 break;
349 }
350 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 case 3:
352 /*
353 * Last 8 entries of default 16-color palette is a more intense
354 * version of the first 8 (i.e., same chrominance, different
355 * luminance).
356 */
357 color &= 7;
358 break;
359 }
360
361
362 return color;
363}
364
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800365static void fbcon_update_softback(struct vc_data *vc)
366{
367 int l = fbcon_softback_size / vc->vc_size_row;
368
369 if (l > 5)
370 softback_end = softback_buf + l * vc->vc_size_row;
371 else
372 /* Smaller scrollback makes no sense, and 0 would screw
373 the operation totally */
374 softback_top = 0;
375}
376
David Howellsc4028952006-11-22 14:57:56 +0000377static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
David Howellsc4028952006-11-22 14:57:56 +0000379 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 struct fbcon_ops *ops = info->fbcon_par;
381 struct display *p;
382 struct vc_data *vc = NULL;
383 int c;
384 int mode;
385
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700386 acquire_console_sem();
387 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 vc = vc_cons[ops->currcon].d;
389
390 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700391 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700392 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700393 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700395 }
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 p = &fb_display[vc->vc_num];
398 c = scr_readw((u16 *) vc->vc_pos);
399 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
400 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800401 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 get_color(vc, info, c, 0));
403 release_console_sem();
404}
405
Finn Thain79f0c9a2008-11-18 20:45:23 +0100406#ifdef CONFIG_ATARI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100408static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
410 struct fb_info *info = dev_id;
411
412 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
413 schedule_work(&info->queue);
414 vbl_cursor_cnt = cursor_blink_rate;
415 }
416 return IRQ_HANDLED;
417}
418#endif
419
420static void cursor_timer_handler(unsigned long dev_addr)
421{
422 struct fb_info *info = (struct fb_info *) dev_addr;
423 struct fbcon_ops *ops = info->fbcon_par;
424
425 schedule_work(&info->queue);
426 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
427}
428
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700429static void fbcon_add_cursor_timer(struct fb_info *info)
430{
431 struct fbcon_ops *ops = info->fbcon_par;
432
433 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700434 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
435 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700436 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000437 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700438
439 init_timer(&ops->cursor_timer);
440 ops->cursor_timer.function = cursor_timer_handler;
441 ops->cursor_timer.expires = jiffies + HZ / 5;
442 ops->cursor_timer.data = (unsigned long ) info;
443 add_timer(&ops->cursor_timer);
444 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
445 }
446}
447
448static void fbcon_del_cursor_timer(struct fb_info *info)
449{
450 struct fbcon_ops *ops = info->fbcon_par;
451
452 if (info->queue.func == fb_flashcursor &&
453 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
454 del_timer_sync(&ops->cursor_timer);
455 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
456 }
457}
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#ifndef MODULE
460static int __init fb_console_setup(char *this_opt)
461{
462 char *options;
463 int i, j;
464
465 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800466 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 while ((options = strsep(&this_opt, ",")) != NULL) {
469 if (!strncmp(options, "font:", 5))
470 strcpy(fontname, options + 5);
471
472 if (!strncmp(options, "scrollback:", 11)) {
473 options += 11;
474 if (*options) {
475 fbcon_softback_size = simple_strtoul(options, &options, 0);
476 if (*options == 'k' || *options == 'K') {
477 fbcon_softback_size *= 1024;
478 options++;
479 }
480 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800481 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 options++;
483 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800484 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486
487 if (!strncmp(options, "map:", 4)) {
488 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700489 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
491 if (!options[j])
492 j = 0;
493 con2fb_map_boot[i] =
494 (options[j++]-'0') % FB_MAX;
495 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700496
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700497 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700498 }
499
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800500 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
503 if (!strncmp(options, "vc:", 3)) {
504 options += 3;
505 if (*options)
506 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
507 if (first_fb_vc < 0)
508 first_fb_vc = 0;
509 if (*options++ == '-')
510 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
511 fbcon_is_default = 0;
512 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800513
514 if (!strncmp(options, "rotate:", 7)) {
515 options += 7;
516 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800517 initial_rotation = simple_strtoul(options, &options, 0);
518 if (initial_rotation > 3)
519 initial_rotation = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800522 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
525__setup("fbcon=", fb_console_setup);
526#endif
527
528static int search_fb_in_map(int idx)
529{
530 int i, retval = 0;
531
Antonino A. Daplase614b182006-06-26 00:27:09 -0700532 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (con2fb_map[i] == idx)
534 retval = 1;
535 }
536 return retval;
537}
538
539static int search_for_mapped_con(void)
540{
541 int i, retval = 0;
542
Antonino A. Daplase614b182006-06-26 00:27:09 -0700543 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 if (con2fb_map[i] != -1)
545 retval = 1;
546 }
547 return retval;
548}
549
550static int fbcon_takeover(int show_logo)
551{
552 int err, i;
553
554 if (!num_registered_fb)
555 return -ENODEV;
556
557 if (!show_logo)
558 logo_shown = FBCON_LOGO_DONTSHOW;
559
560 for (i = first_fb_vc; i <= last_fb_vc; i++)
561 con2fb_map[i] = info_idx;
562
563 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
564 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if (err) {
567 for (i = first_fb_vc; i <= last_fb_vc; i++) {
568 con2fb_map[i] = -1;
569 }
570 info_idx = -1;
571 }
572
573 return err;
574}
575
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700576#ifdef MODULE
577static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
578 int cols, int rows, int new_cols, int new_rows)
579{
580 logo_shown = FBCON_LOGO_DONTSHOW;
581}
582#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
584 int cols, int rows, int new_cols, int new_rows)
585{
586 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800587 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 int cnt, erase = vc->vc_video_erase_char, step;
589 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700590 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700592 if (info->flags & FBINFO_MODULE) {
593 logo_shown = FBCON_LOGO_DONTSHOW;
594 return;
595 }
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 /*
598 * remove underline attribute from erase character
599 * if black and white framebuffer.
600 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700601 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800603 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700604 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 q = (unsigned short *) (vc->vc_origin +
606 vc->vc_size_row * rows);
607 step = logo_lines * cols;
608 for (r = q - logo_lines * cols; r < q; r++)
609 if (scr_readw(r) != vc->vc_video_erase_char)
610 break;
611 if (r != q && new_rows >= rows + logo_lines) {
612 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
613 if (save) {
614 int i = cols < new_cols ? cols : new_cols;
615 scr_memsetw(save, erase, logo_lines * new_cols * 2);
616 r = q - step;
617 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
618 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
619 r = q;
620 }
621 }
622 if (r == q) {
623 /* We can scroll screen down */
624 r = q - step - cols;
625 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
626 scr_memcpyw(r + step, r, vc->vc_size_row);
627 r -= cols;
628 }
629 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700630 int lines;
631 if (vc->vc_y + logo_lines >= rows)
632 lines = rows - vc->vc_y - 1;
633 else
634 lines = logo_lines;
635 vc->vc_y += lines;
636 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638 }
639 scr_memsetw((unsigned short *) vc->vc_origin,
640 erase,
641 vc->vc_size_row * logo_lines);
642
643 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
644 fbcon_clear_margins(vc, 0);
645 update_screen(vc);
646 }
647
648 if (save) {
649 q = (unsigned short *) (vc->vc_origin +
650 vc->vc_size_row *
651 rows);
652 scr_memcpyw(q, save, logo_lines * new_cols * 2);
653 vc->vc_y += logo_lines;
654 vc->vc_pos += logo_lines * vc->vc_size_row;
655 kfree(save);
656 }
657
658 if (logo_lines > vc->vc_bottom) {
659 logo_shown = FBCON_LOGO_CANSHOW;
660 printk(KERN_INFO
661 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
662 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
663 logo_shown = FBCON_LOGO_DRAW;
664 vc->vc_top = logo_lines;
665 }
666}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700667#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800670static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671{
672 struct fbcon_ops *ops = info->fbcon_par;
673
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800674 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800677 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800678 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800679 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700683
684static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
685{
686 int err = 0;
687
688 if (info->flags & FBINFO_MISC_TILEBLITTING &&
689 info->tileops->fb_get_tilemax(info) < charcount)
690 err = 1;
691
692 return err;
693}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800695static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 struct fbcon_ops *ops = info->fbcon_par;
698
699 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800700 ops->p = &fb_display[vc->vc_num];
701 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 fbcon_set_bitops(ops);
703}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700704
705static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
706{
707 return 0;
708}
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#endif /* CONFIG_MISC_TILEBLITTING */
711
712
713static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
714 int unit, int oldidx)
715{
716 struct fbcon_ops *ops = NULL;
717 int err = 0;
718
719 if (!try_module_get(info->fbops->owner))
720 err = -ENODEV;
721
722 if (!err && info->fbops->fb_open &&
723 info->fbops->fb_open(info, 0))
724 err = -ENODEV;
725
726 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800727 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if (!ops)
729 err = -ENOMEM;
730 }
731
732 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700734
735 if (vc)
736 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 }
738
739 if (err) {
740 con2fb_map[unit] = oldidx;
741 module_put(info->fbops->owner);
742 }
743
744 return err;
745}
746
747static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
748 struct fb_info *newinfo, int unit,
749 int oldidx, int found)
750{
751 struct fbcon_ops *ops = oldinfo->fbcon_par;
752 int err = 0;
753
754 if (oldinfo->fbops->fb_release &&
755 oldinfo->fbops->fb_release(oldinfo, 0)) {
756 con2fb_map[unit] = oldidx;
757 if (!found && newinfo->fbops->fb_release)
758 newinfo->fbops->fb_release(newinfo, 0);
759 if (!found)
760 module_put(newinfo->fbops->owner);
761 err = -ENODEV;
762 }
763
764 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700765 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 kfree(ops->cursor_state.mask);
767 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800768 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 kfree(oldinfo->fbcon_par);
770 oldinfo->fbcon_par = NULL;
771 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800772 /*
773 If oldinfo and newinfo are driving the same hardware,
774 the fb_release() method of oldinfo may attempt to
775 restore the hardware state. This will leave the
776 newinfo in an undefined state. Thus, a call to
777 fb_set_par() may be needed for the newinfo.
778 */
779 if (newinfo->fbops->fb_set_par)
780 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 }
782
783 return err;
784}
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
787 int unit, int show_logo)
788{
789 struct fbcon_ops *ops = info->fbcon_par;
790
791 ops->currcon = fg_console;
792
793 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
794 info->fbops->fb_set_par(info);
795
796 ops->flags |= FBCON_FLAGS_INIT;
797 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700798 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 if (show_logo) {
801 struct vc_data *fg_vc = vc_cons[fg_console].d;
802 struct fb_info *fg_info =
803 registered_fb[con2fb_map[fg_console]];
804
805 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
806 fg_vc->vc_rows, fg_vc->vc_cols,
807 fg_vc->vc_rows);
808 }
809
810 update_screen(vc_cons[fg_console].d);
811}
812
813/**
814 * set_con2fb_map - map console to frame buffer device
815 * @unit: virtual console number to map
816 * @newidx: frame buffer index to map virtual console to
817 * @user: user request
818 *
819 * Maps a virtual console @unit to a frame buffer device
820 * @newidx.
821 */
822static int set_con2fb_map(int unit, int newidx, int user)
823{
824 struct vc_data *vc = vc_cons[unit].d;
825 int oldidx = con2fb_map[unit];
826 struct fb_info *info = registered_fb[newidx];
827 struct fb_info *oldinfo = NULL;
828 int found, err = 0;
829
830 if (oldidx == newidx)
831 return 0;
832
Antonino A. Daplase614b182006-06-26 00:27:09 -0700833 if (!info || fbcon_has_exited)
834 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836 if (!err && !search_for_mapped_con()) {
837 info_idx = newidx;
838 return fbcon_takeover(0);
839 }
840
841 if (oldidx != -1)
842 oldinfo = registered_fb[oldidx];
843
844 found = search_fb_in_map(newidx);
845
846 acquire_console_sem();
847 con2fb_map[unit] = newidx;
848 if (!err && !found)
849 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
850
851
852 /*
853 * If old fb is not mapped to any of the consoles,
854 * fbcon should release it.
855 */
856 if (!err && oldinfo && !search_fb_in_map(oldidx))
857 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
858 found);
859
860 if (!err) {
861 int show_logo = (fg_console == 0 && !user &&
862 logo_shown != FBCON_LOGO_DONTSHOW);
863
864 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700865 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 con2fb_map_boot[unit] = newidx;
867 con2fb_init_display(vc, info, unit, show_logo);
868 }
869
Antonino A. Daplase614b182006-06-26 00:27:09 -0700870 if (!search_fb_in_map(info_idx))
871 info_idx = newidx;
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 release_console_sem();
874 return err;
875}
876
877/*
878 * Low Level Operations
879 */
880/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
881static int var_to_display(struct display *disp,
882 struct fb_var_screeninfo *var,
883 struct fb_info *info)
884{
885 disp->xres_virtual = var->xres_virtual;
886 disp->yres_virtual = var->yres_virtual;
887 disp->bits_per_pixel = var->bits_per_pixel;
888 disp->grayscale = var->grayscale;
889 disp->nonstd = var->nonstd;
890 disp->accel_flags = var->accel_flags;
891 disp->height = var->height;
892 disp->width = var->width;
893 disp->red = var->red;
894 disp->green = var->green;
895 disp->blue = var->blue;
896 disp->transp = var->transp;
897 disp->rotate = var->rotate;
898 disp->mode = fb_match_mode(var, &info->modelist);
899 if (disp->mode == NULL)
900 /* This should not happen */
901 return -EINVAL;
902 return 0;
903}
904
905static void display_to_var(struct fb_var_screeninfo *var,
906 struct display *disp)
907{
908 fb_videomode_to_var(var, disp->mode);
909 var->xres_virtual = disp->xres_virtual;
910 var->yres_virtual = disp->yres_virtual;
911 var->bits_per_pixel = disp->bits_per_pixel;
912 var->grayscale = disp->grayscale;
913 var->nonstd = disp->nonstd;
914 var->accel_flags = disp->accel_flags;
915 var->height = disp->height;
916 var->width = disp->width;
917 var->red = disp->red;
918 var->green = disp->green;
919 var->blue = disp->blue;
920 var->transp = disp->transp;
921 var->rotate = disp->rotate;
922}
923
924static const char *fbcon_startup(void)
925{
926 const char *display_desc = "frame buffer device";
927 struct display *p = &fb_display[fg_console];
928 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700929 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 struct module *owner;
931 struct fb_info *info = NULL;
932 struct fbcon_ops *ops;
933 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 /*
936 * If num_registered_fb is zero, this is a call for the dummy part.
937 * The frame buffer devices weren't initialized yet.
938 */
939 if (!num_registered_fb || info_idx == -1)
940 return display_desc;
941 /*
942 * Instead of blindly using registered_fb[0], we use info_idx, set by
943 * fb_console_init();
944 */
945 info = registered_fb[info_idx];
946 if (!info)
947 return NULL;
948
949 owner = info->fbops->owner;
950 if (!try_module_get(owner))
951 return NULL;
952 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
953 module_put(owner);
954 return NULL;
955 }
956
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800957 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (!ops) {
959 module_put(owner);
960 return NULL;
961 }
962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 ops->currcon = -1;
964 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800965 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800967 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800968 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 if (info->fix.type != FB_TYPE_TEXT) {
971 if (fbcon_softback_size) {
972 if (!softback_buf) {
973 softback_buf =
974 (unsigned long)
975 kmalloc(fbcon_softback_size,
976 GFP_KERNEL);
977 if (!softback_buf) {
978 fbcon_softback_size = 0;
979 softback_top = 0;
980 }
981 }
982 } else {
983 if (softback_buf) {
984 kfree((void *) softback_buf);
985 softback_buf = 0;
986 softback_top = 0;
987 }
988 }
989 if (softback_buf)
990 softback_in = softback_top = softback_curr =
991 softback_buf;
992 softback_lines = 0;
993 }
994
995 /* Setup default font */
996 if (!p->fontdata) {
997 if (!fontname[0] || !(font = find_font(fontname)))
998 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700999 info->var.yres,
1000 info->pixmap.blit_x,
1001 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 vc->vc_font.width = font->width;
1003 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001004 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1006 }
1007
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001008 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1009 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1010 cols /= vc->vc_font.width;
1011 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 vc_resize(vc, cols, rows);
1013
1014 DPRINTK("mode: %s\n", info->fix.id);
1015 DPRINTK("visual: %d\n", info->fix.visual);
1016 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1017 info->var.yres,
1018 info->var.bits_per_pixel);
1019
1020#ifdef CONFIG_ATARI
1021 if (MACH_IS_ATARI) {
1022 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
Finn Thain79f0c9a2008-11-18 20:45:23 +01001023 (void)request_irq(IRQ_AUTO_4, fb_vbl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 IRQ_TYPE_PRIO, "framebuffer vbl",
1025 info);
1026 }
Finn Thain79f0c9a2008-11-18 20:45:23 +01001027#endif /* CONFIG_ATARI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001029 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001030 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return display_desc;
1032}
1033
1034static void fbcon_init(struct vc_data *vc, int init)
1035{
1036 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1037 struct fbcon_ops *ops;
1038 struct vc_data **default_mode = vc->vc_display_fg;
1039 struct vc_data *svc = *default_mode;
1040 struct display *t, *p = &fb_display[vc->vc_num];
1041 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001042 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 if (info_idx == -1 || info == NULL)
1045 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001046
1047 cap = info->flags;
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1050 (info->fix.type == FB_TYPE_TEXT))
1051 logo = 0;
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 if (var_to_display(p, &info->var, info))
1054 return;
1055
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001056 if (!info->fbcon_par)
1057 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 /* If we are not the first console on this
1060 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001061 t = &fb_display[fg_console];
1062 if (!p->fontdata) {
1063 if (t->fontdata) {
1064 struct vc_data *fvc = vc_cons[fg_console].d;
1065
1066 vc->vc_font.data = (void *)(p->fontdata =
1067 fvc->vc_font.data);
1068 vc->vc_font.width = fvc->vc_font.width;
1069 vc->vc_font.height = fvc->vc_font.height;
1070 p->userfont = t->userfont;
1071
1072 if (p->userfont)
1073 REFCOUNT(p->fontdata)++;
1074 } else {
1075 const struct font_desc *font = NULL;
1076
1077 if (!fontname[0] || !(font = find_font(fontname)))
1078 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001079 info->var.yres,
1080 info->pixmap.blit_x,
1081 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001082 vc->vc_font.width = font->width;
1083 vc->vc_font.height = font->height;
1084 vc->vc_font.data = (void *)(p->fontdata = font->data);
1085 vc->vc_font.charcount = 256; /* FIXME Need to
1086 support more fonts */
1087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (p->userfont)
1091 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001092
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001093 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1095 if (charcnt == 256) {
1096 vc->vc_hi_font_mask = 0;
1097 } else {
1098 vc->vc_hi_font_mask = 0x100;
1099 if (vc->vc_can_do_color)
1100 vc->vc_complement_mask <<= 1;
1101 }
1102
1103 if (!*svc->vc_uni_pagedir_loc)
1104 con_set_default_unimap(svc);
1105 if (!*vc->vc_uni_pagedir_loc)
1106 con_copy_unimap(vc, svc);
1107
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001108 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001109 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001110 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 cols = vc->vc_cols;
1113 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001114 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1115 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1116 new_cols /= vc->vc_font.width;
1117 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 vc_resize(vc, new_cols, new_rows);
1119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 /*
1121 * We must always set the mode. The mode of the previous console
1122 * driver could be in the same resolution but we are using different
1123 * hardware so we have to initialize the hardware.
1124 *
1125 * We need to do it in fbcon_init() to prevent screen corruption.
1126 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001127 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 if (info->fbops->fb_set_par &&
1129 !(ops->flags & FBCON_FLAGS_INIT))
1130 info->fbops->fb_set_par(info);
1131 ops->flags |= FBCON_FLAGS_INIT;
1132 }
1133
1134 ops->graphics = 0;
1135
1136 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1137 !(cap & FBINFO_HWACCEL_DISABLED))
1138 p->scrollmode = SCROLL_MOVE;
1139 else /* default to something safe */
1140 p->scrollmode = SCROLL_REDRAW;
1141
1142 /*
1143 * ++guenther: console.c:vc_allocate() relies on initializing
1144 * vc_{cols,rows}, but we must not set those if we are only
1145 * resizing the console.
1146 */
1147 if (!init) {
1148 vc->vc_cols = new_cols;
1149 vc->vc_rows = new_rows;
1150 }
1151
1152 if (logo)
1153 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1154
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001155 if (vc == svc && softback_buf)
1156 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001157
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001158 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001159 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001160 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001161 }
1162
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001163 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
Antonino A. Daplase614b182006-06-26 00:27:09 -07001166static void fbcon_free_font(struct display *p)
1167{
1168 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1169 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1170 p->fontdata = NULL;
1171 p->userfont = 0;
1172}
1173
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174static void fbcon_deinit(struct vc_data *vc)
1175{
1176 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001177 struct fb_info *info;
1178 struct fbcon_ops *ops;
1179 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001182 idx = con2fb_map[vc->vc_num];
1183
1184 if (idx == -1)
1185 goto finished;
1186
1187 info = registered_fb[idx];
1188
1189 if (!info)
1190 goto finished;
1191
1192 ops = info->fbcon_par;
1193
1194 if (!ops)
1195 goto finished;
1196
1197 if (CON_IS_VISIBLE(vc))
1198 fbcon_del_cursor_timer(info);
1199
1200 ops->flags &= ~FBCON_FLAGS_INIT;
1201finished:
1202
1203 if (!con_is_bound(&fb_con))
1204 fbcon_exit();
1205
1206 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
1209/* ====================================================================== */
1210
1211/* fbcon_XXX routines - interface used by the world
1212 *
1213 * This system is now divided into two levels because of complications
1214 * caused by hardware scrolling. Top level functions:
1215 *
1216 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1217 *
1218 * handles y values in range [0, scr_height-1] that correspond to real
1219 * screen positions. y_wrap shift means that first line of bitmap may be
1220 * anywhere on this display. These functions convert lineoffsets to
1221 * bitmap offsets and deal with the wrap-around case by splitting blits.
1222 *
1223 * fbcon_bmove_physical_8() -- These functions fast implementations
1224 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1225 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1226 *
1227 * WARNING:
1228 *
1229 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1230 * Implies should only really hardware scroll in rows. Only reason for
1231 * restriction is simplicity & efficiency at the moment.
1232 */
1233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1235 int width)
1236{
1237 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1238 struct fbcon_ops *ops = info->fbcon_par;
1239
1240 struct display *p = &fb_display[vc->vc_num];
1241 u_int y_break;
1242
1243 if (fbcon_is_inactive(vc, info))
1244 return;
1245
1246 if (!height || !width)
1247 return;
1248
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001249 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1250 vc->vc_top = 0;
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 /* Split blits that cross physical y_wrap boundary */
1253
1254 y_break = p->vrows - p->yscroll;
1255 if (sy < y_break && sy + height - 1 >= y_break) {
1256 u_int b = y_break - sy;
1257 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1258 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1259 width);
1260 } else
1261 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1262}
1263
1264static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1265 int count, int ypos, int xpos)
1266{
1267 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1268 struct display *p = &fb_display[vc->vc_num];
1269 struct fbcon_ops *ops = info->fbcon_par;
1270
1271 if (!fbcon_is_inactive(vc, info))
1272 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1273 get_color(vc, info, scr_readw(s), 1),
1274 get_color(vc, info, scr_readw(s), 0));
1275}
1276
1277static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1278{
1279 unsigned short chr;
1280
1281 scr_writew(c, &chr);
1282 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1283}
1284
1285static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1286{
1287 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1288 struct fbcon_ops *ops = info->fbcon_par;
1289
1290 if (!fbcon_is_inactive(vc, info))
1291 ops->clear_margins(vc, info, bottom_only);
1292}
1293
1294static void fbcon_cursor(struct vc_data *vc, int mode)
1295{
1296 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1297 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 int y;
1299 int c = scr_readw((u16 *) vc->vc_pos);
1300
Michal Januszewskid1e23062007-05-08 00:38:07 -07001301 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 return;
1303
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001304 if (vc->vc_cursor_type & 0x10)
1305 fbcon_del_cursor_timer(info);
1306 else
1307 fbcon_add_cursor_timer(info);
1308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1310 if (mode & CM_SOFTBACK) {
1311 mode &= ~CM_SOFTBACK;
1312 y = softback_lines;
1313 } else {
1314 if (softback_lines)
1315 fbcon_set_origin(vc);
1316 y = 0;
1317 }
1318
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001319 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 get_color(vc, info, c, 0));
1321 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1322}
1323
1324static int scrollback_phys_max = 0;
1325static int scrollback_max = 0;
1326static int scrollback_current = 0;
1327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001329 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001331 struct display *p, *t;
1332 struct vc_data **default_mode, *vc;
1333 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001334 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 int rows, cols, charcnt = 256;
1336
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001337 p = &fb_display[unit];
1338
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 if (var_to_display(p, var, info))
1340 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001341
1342 vc = vc_cons[unit].d;
1343
1344 if (!vc)
1345 return;
1346
1347 default_mode = vc->vc_display_fg;
1348 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001352 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 vc->vc_font.width = (*default_mode)->vc_font.width;
1354 vc->vc_font.height = (*default_mode)->vc_font.height;
1355 p->userfont = t->userfont;
1356 if (p->userfont)
1357 REFCOUNT(p->fontdata)++;
1358 }
1359 if (p->userfont)
1360 charcnt = FNTCHARCNT(p->fontdata);
1361
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001362 var->activate = FB_ACTIVATE_NOW;
1363 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001364 var->yoffset = info->var.yoffset;
1365 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001366 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001367 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001368 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1370 if (charcnt == 256) {
1371 vc->vc_hi_font_mask = 0;
1372 } else {
1373 vc->vc_hi_font_mask = 0x100;
1374 if (vc->vc_can_do_color)
1375 vc->vc_complement_mask <<= 1;
1376 }
1377
1378 if (!*svc->vc_uni_pagedir_loc)
1379 con_set_default_unimap(svc);
1380 if (!*vc->vc_uni_pagedir_loc)
1381 con_copy_unimap(vc, svc);
1382
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001383 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1384 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1385 cols /= vc->vc_font.width;
1386 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 if (CON_IS_VISIBLE(vc)) {
1390 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001391 if (softback_buf)
1392 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
1394}
1395
1396static __inline__ void ywrap_up(struct vc_data *vc, int count)
1397{
1398 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001399 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 struct display *p = &fb_display[vc->vc_num];
1401
1402 p->yscroll += count;
1403 if (p->yscroll >= p->vrows) /* Deal with wrap */
1404 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001405 ops->var.xoffset = 0;
1406 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1407 ops->var.vmode |= FB_VMODE_YWRAP;
1408 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 scrollback_max += count;
1410 if (scrollback_max > scrollback_phys_max)
1411 scrollback_max = scrollback_phys_max;
1412 scrollback_current = 0;
1413}
1414
1415static __inline__ void ywrap_down(struct vc_data *vc, int count)
1416{
1417 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001418 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 struct display *p = &fb_display[vc->vc_num];
1420
1421 p->yscroll -= count;
1422 if (p->yscroll < 0) /* Deal with wrap */
1423 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001424 ops->var.xoffset = 0;
1425 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1426 ops->var.vmode |= FB_VMODE_YWRAP;
1427 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 scrollback_max -= count;
1429 if (scrollback_max < 0)
1430 scrollback_max = 0;
1431 scrollback_current = 0;
1432}
1433
1434static __inline__ void ypan_up(struct vc_data *vc, int count)
1435{
1436 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1437 struct display *p = &fb_display[vc->vc_num];
1438 struct fbcon_ops *ops = info->fbcon_par;
1439
1440 p->yscroll += count;
1441 if (p->yscroll > p->vrows - vc->vc_rows) {
1442 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1443 0, 0, 0, vc->vc_rows, vc->vc_cols);
1444 p->yscroll -= p->vrows - vc->vc_rows;
1445 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001446
1447 ops->var.xoffset = 0;
1448 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1449 ops->var.vmode &= ~FB_VMODE_YWRAP;
1450 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 fbcon_clear_margins(vc, 1);
1452 scrollback_max += count;
1453 if (scrollback_max > scrollback_phys_max)
1454 scrollback_max = scrollback_phys_max;
1455 scrollback_current = 0;
1456}
1457
1458static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1459{
1460 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001461 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001465
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 if (p->yscroll > p->vrows - vc->vc_rows) {
1467 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001469 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001470
1471 ops->var.xoffset = 0;
1472 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1473 ops->var.vmode &= ~FB_VMODE_YWRAP;
1474 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 fbcon_clear_margins(vc, 1);
1476 scrollback_max += count;
1477 if (scrollback_max > scrollback_phys_max)
1478 scrollback_max = scrollback_phys_max;
1479 scrollback_current = 0;
1480}
1481
1482static __inline__ void ypan_down(struct vc_data *vc, int count)
1483{
1484 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1485 struct display *p = &fb_display[vc->vc_num];
1486 struct fbcon_ops *ops = info->fbcon_par;
1487
1488 p->yscroll -= count;
1489 if (p->yscroll < 0) {
1490 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1491 0, vc->vc_rows, vc->vc_cols);
1492 p->yscroll += p->vrows - vc->vc_rows;
1493 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001494
1495 ops->var.xoffset = 0;
1496 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1497 ops->var.vmode &= ~FB_VMODE_YWRAP;
1498 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 fbcon_clear_margins(vc, 1);
1500 scrollback_max -= count;
1501 if (scrollback_max < 0)
1502 scrollback_max = 0;
1503 scrollback_current = 0;
1504}
1505
1506static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1507{
1508 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001509 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001513
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 if (p->yscroll < 0) {
1515 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001517 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001518
1519 ops->var.xoffset = 0;
1520 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1521 ops->var.vmode &= ~FB_VMODE_YWRAP;
1522 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 fbcon_clear_margins(vc, 1);
1524 scrollback_max -= count;
1525 if (scrollback_max < 0)
1526 scrollback_max = 0;
1527 scrollback_current = 0;
1528}
1529
1530static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1531 long delta)
1532{
1533 int count = vc->vc_rows;
1534 unsigned short *d, *s;
1535 unsigned long n;
1536 int line = 0;
1537
1538 d = (u16 *) softback_curr;
1539 if (d == (u16 *) softback_in)
1540 d = (u16 *) vc->vc_origin;
1541 n = softback_curr + delta * vc->vc_size_row;
1542 softback_lines -= delta;
1543 if (delta < 0) {
1544 if (softback_curr < softback_top && n < softback_buf) {
1545 n += softback_end - softback_buf;
1546 if (n < softback_top) {
1547 softback_lines -=
1548 (softback_top - n) / vc->vc_size_row;
1549 n = softback_top;
1550 }
1551 } else if (softback_curr >= softback_top
1552 && n < softback_top) {
1553 softback_lines -=
1554 (softback_top - n) / vc->vc_size_row;
1555 n = softback_top;
1556 }
1557 } else {
1558 if (softback_curr > softback_in && n >= softback_end) {
1559 n += softback_buf - softback_end;
1560 if (n > softback_in) {
1561 n = softback_in;
1562 softback_lines = 0;
1563 }
1564 } else if (softback_curr <= softback_in && n > softback_in) {
1565 n = softback_in;
1566 softback_lines = 0;
1567 }
1568 }
1569 if (n == softback_curr)
1570 return;
1571 softback_curr = n;
1572 s = (u16 *) softback_curr;
1573 if (s == (u16 *) softback_in)
1574 s = (u16 *) vc->vc_origin;
1575 while (count--) {
1576 unsigned short *start;
1577 unsigned short *le;
1578 unsigned short c;
1579 int x = 0;
1580 unsigned short attr = 1;
1581
1582 start = s;
1583 le = advance_row(s, 1);
1584 do {
1585 c = scr_readw(s);
1586 if (attr != (c & 0xff00)) {
1587 attr = c & 0xff00;
1588 if (s > start) {
1589 fbcon_putcs(vc, start, s - start,
1590 line, x);
1591 x += s - start;
1592 start = s;
1593 }
1594 }
1595 if (c == scr_readw(d)) {
1596 if (s > start) {
1597 fbcon_putcs(vc, start, s - start,
1598 line, x);
1599 x += s - start + 1;
1600 start = s + 1;
1601 } else {
1602 x++;
1603 start++;
1604 }
1605 }
1606 s++;
1607 d++;
1608 } while (s < le);
1609 if (s > start)
1610 fbcon_putcs(vc, start, s - start, line, x);
1611 line++;
1612 if (d == (u16 *) softback_end)
1613 d = (u16 *) softback_buf;
1614 if (d == (u16 *) softback_in)
1615 d = (u16 *) vc->vc_origin;
1616 if (s == (u16 *) softback_end)
1617 s = (u16 *) softback_buf;
1618 if (s == (u16 *) softback_in)
1619 s = (u16 *) vc->vc_origin;
1620 }
1621}
1622
1623static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1624 int line, int count, int dy)
1625{
1626 unsigned short *s = (unsigned short *)
1627 (vc->vc_origin + vc->vc_size_row * line);
1628
1629 while (count--) {
1630 unsigned short *start = s;
1631 unsigned short *le = advance_row(s, 1);
1632 unsigned short c;
1633 int x = 0;
1634 unsigned short attr = 1;
1635
1636 do {
1637 c = scr_readw(s);
1638 if (attr != (c & 0xff00)) {
1639 attr = c & 0xff00;
1640 if (s > start) {
1641 fbcon_putcs(vc, start, s - start,
1642 dy, x);
1643 x += s - start;
1644 start = s;
1645 }
1646 }
1647 console_conditional_schedule();
1648 s++;
1649 } while (s < le);
1650 if (s > start)
1651 fbcon_putcs(vc, start, s - start, dy, x);
1652 console_conditional_schedule();
1653 dy++;
1654 }
1655}
1656
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001657static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1658 struct display *p, int line, int count, int ycount)
1659{
1660 int offset = ycount * vc->vc_cols;
1661 unsigned short *d = (unsigned short *)
1662 (vc->vc_origin + vc->vc_size_row * line);
1663 unsigned short *s = d + offset;
1664 struct fbcon_ops *ops = info->fbcon_par;
1665
1666 while (count--) {
1667 unsigned short *start = s;
1668 unsigned short *le = advance_row(s, 1);
1669 unsigned short c;
1670 int x = 0;
1671
1672 do {
1673 c = scr_readw(s);
1674
1675 if (c == scr_readw(d)) {
1676 if (s > start) {
1677 ops->bmove(vc, info, line + ycount, x,
1678 line, x, 1, s-start);
1679 x += s - start + 1;
1680 start = s + 1;
1681 } else {
1682 x++;
1683 start++;
1684 }
1685 }
1686
1687 scr_writew(c, d);
1688 console_conditional_schedule();
1689 s++;
1690 d++;
1691 } while (s < le);
1692 if (s > start)
1693 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1694 s-start);
1695 console_conditional_schedule();
1696 if (ycount > 0)
1697 line++;
1698 else {
1699 line--;
1700 /* NOTE: We subtract two lines from these pointers */
1701 s -= vc->vc_size_row;
1702 d -= vc->vc_size_row;
1703 }
1704 }
1705}
1706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707static void fbcon_redraw(struct vc_data *vc, struct display *p,
1708 int line, int count, int offset)
1709{
1710 unsigned short *d = (unsigned short *)
1711 (vc->vc_origin + vc->vc_size_row * line);
1712 unsigned short *s = d + offset;
1713
1714 while (count--) {
1715 unsigned short *start = s;
1716 unsigned short *le = advance_row(s, 1);
1717 unsigned short c;
1718 int x = 0;
1719 unsigned short attr = 1;
1720
1721 do {
1722 c = scr_readw(s);
1723 if (attr != (c & 0xff00)) {
1724 attr = c & 0xff00;
1725 if (s > start) {
1726 fbcon_putcs(vc, start, s - start,
1727 line, x);
1728 x += s - start;
1729 start = s;
1730 }
1731 }
1732 if (c == scr_readw(d)) {
1733 if (s > start) {
1734 fbcon_putcs(vc, start, s - start,
1735 line, x);
1736 x += s - start + 1;
1737 start = s + 1;
1738 } else {
1739 x++;
1740 start++;
1741 }
1742 }
1743 scr_writew(c, d);
1744 console_conditional_schedule();
1745 s++;
1746 d++;
1747 } while (s < le);
1748 if (s > start)
1749 fbcon_putcs(vc, start, s - start, line, x);
1750 console_conditional_schedule();
1751 if (offset > 0)
1752 line++;
1753 else {
1754 line--;
1755 /* NOTE: We subtract two lines from these pointers */
1756 s -= vc->vc_size_row;
1757 d -= vc->vc_size_row;
1758 }
1759 }
1760}
1761
1762static inline void fbcon_softback_note(struct vc_data *vc, int t,
1763 int count)
1764{
1765 unsigned short *p;
1766
1767 if (vc->vc_num != fg_console)
1768 return;
1769 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1770
1771 while (count) {
1772 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1773 count--;
1774 p = advance_row(p, 1);
1775 softback_in += vc->vc_size_row;
1776 if (softback_in == softback_end)
1777 softback_in = softback_buf;
1778 if (softback_in == softback_top) {
1779 softback_top += vc->vc_size_row;
1780 if (softback_top == softback_end)
1781 softback_top = softback_buf;
1782 }
1783 }
1784 softback_curr = softback_in;
1785}
1786
1787static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1788 int count)
1789{
1790 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1791 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1793
1794 if (fbcon_is_inactive(vc, info))
1795 return -EINVAL;
1796
1797 fbcon_cursor(vc, CM_ERASE);
1798
1799 /*
1800 * ++Geert: Only use ywrap/ypan if the console is in text mode
1801 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1802 * whole screen (prevents flicker).
1803 */
1804
1805 switch (dir) {
1806 case SM_UP:
1807 if (count > vc->vc_rows) /* Maximum realistic size */
1808 count = vc->vc_rows;
1809 if (softback_top)
1810 fbcon_softback_note(vc, t, count);
1811 if (logo_shown >= 0)
1812 goto redraw_up;
1813 switch (p->scrollmode) {
1814 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001815 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1816 count);
1817 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1818 scr_memsetw((unsigned short *) (vc->vc_origin +
1819 vc->vc_size_row *
1820 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001821 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001822 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001823 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 break;
1825
1826 case SCROLL_WRAP_MOVE:
1827 if (b - t - count > 3 * vc->vc_rows >> 2) {
1828 if (t > 0)
1829 fbcon_bmove(vc, 0, 0, count, 0, t,
1830 vc->vc_cols);
1831 ywrap_up(vc, count);
1832 if (vc->vc_rows - b > 0)
1833 fbcon_bmove(vc, b - count, 0, b, 0,
1834 vc->vc_rows - b,
1835 vc->vc_cols);
1836 } else if (info->flags & FBINFO_READS_FAST)
1837 fbcon_bmove(vc, t + count, 0, t, 0,
1838 b - t - count, vc->vc_cols);
1839 else
1840 goto redraw_up;
1841 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1842 break;
1843
1844 case SCROLL_PAN_REDRAW:
1845 if ((p->yscroll + count <=
1846 2 * (p->vrows - vc->vc_rows))
1847 && ((!scroll_partial && (b - t == vc->vc_rows))
1848 || (scroll_partial
1849 && (b - t - count >
1850 3 * vc->vc_rows >> 2)))) {
1851 if (t > 0)
1852 fbcon_redraw_move(vc, p, 0, t, count);
1853 ypan_up_redraw(vc, t, count);
1854 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001855 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 vc->vc_rows - b, b);
1857 } else
1858 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1859 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1860 break;
1861
1862 case SCROLL_PAN_MOVE:
1863 if ((p->yscroll + count <=
1864 2 * (p->vrows - vc->vc_rows))
1865 && ((!scroll_partial && (b - t == vc->vc_rows))
1866 || (scroll_partial
1867 && (b - t - count >
1868 3 * vc->vc_rows >> 2)))) {
1869 if (t > 0)
1870 fbcon_bmove(vc, 0, 0, count, 0, t,
1871 vc->vc_cols);
1872 ypan_up(vc, count);
1873 if (vc->vc_rows - b > 0)
1874 fbcon_bmove(vc, b - count, 0, b, 0,
1875 vc->vc_rows - b,
1876 vc->vc_cols);
1877 } else if (info->flags & FBINFO_READS_FAST)
1878 fbcon_bmove(vc, t + count, 0, t, 0,
1879 b - t - count, vc->vc_cols);
1880 else
1881 goto redraw_up;
1882 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1883 break;
1884
1885 case SCROLL_REDRAW:
1886 redraw_up:
1887 fbcon_redraw(vc, p, t, b - t - count,
1888 count * vc->vc_cols);
1889 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1890 scr_memsetw((unsigned short *) (vc->vc_origin +
1891 vc->vc_size_row *
1892 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001893 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001895 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
1897 break;
1898
1899 case SM_DOWN:
1900 if (count > vc->vc_rows) /* Maximum realistic size */
1901 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001902 if (logo_shown >= 0)
1903 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 switch (p->scrollmode) {
1905 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001906 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1907 -count);
1908 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1909 scr_memsetw((unsigned short *) (vc->vc_origin +
1910 vc->vc_size_row *
1911 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001912 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001913 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001914 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 break;
1916
1917 case SCROLL_WRAP_MOVE:
1918 if (b - t - count > 3 * vc->vc_rows >> 2) {
1919 if (vc->vc_rows - b > 0)
1920 fbcon_bmove(vc, b, 0, b - count, 0,
1921 vc->vc_rows - b,
1922 vc->vc_cols);
1923 ywrap_down(vc, count);
1924 if (t > 0)
1925 fbcon_bmove(vc, count, 0, 0, 0, t,
1926 vc->vc_cols);
1927 } else if (info->flags & FBINFO_READS_FAST)
1928 fbcon_bmove(vc, t, 0, t + count, 0,
1929 b - t - count, vc->vc_cols);
1930 else
1931 goto redraw_down;
1932 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1933 break;
1934
1935 case SCROLL_PAN_MOVE:
1936 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1937 && ((!scroll_partial && (b - t == vc->vc_rows))
1938 || (scroll_partial
1939 && (b - t - count >
1940 3 * vc->vc_rows >> 2)))) {
1941 if (vc->vc_rows - b > 0)
1942 fbcon_bmove(vc, b, 0, b - count, 0,
1943 vc->vc_rows - b,
1944 vc->vc_cols);
1945 ypan_down(vc, count);
1946 if (t > 0)
1947 fbcon_bmove(vc, count, 0, 0, 0, t,
1948 vc->vc_cols);
1949 } else if (info->flags & FBINFO_READS_FAST)
1950 fbcon_bmove(vc, t, 0, t + count, 0,
1951 b - t - count, vc->vc_cols);
1952 else
1953 goto redraw_down;
1954 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1955 break;
1956
1957 case SCROLL_PAN_REDRAW:
1958 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1959 && ((!scroll_partial && (b - t == vc->vc_rows))
1960 || (scroll_partial
1961 && (b - t - count >
1962 3 * vc->vc_rows >> 2)))) {
1963 if (vc->vc_rows - b > 0)
1964 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1965 b - count);
1966 ypan_down_redraw(vc, t, count);
1967 if (t > 0)
1968 fbcon_redraw_move(vc, p, count, t, 0);
1969 } else
1970 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1971 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1972 break;
1973
1974 case SCROLL_REDRAW:
1975 redraw_down:
1976 fbcon_redraw(vc, p, b - 1, b - t - count,
1977 -count * vc->vc_cols);
1978 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1979 scr_memsetw((unsigned short *) (vc->vc_origin +
1980 vc->vc_size_row *
1981 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001982 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001984 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 }
1986 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07001987 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988}
1989
1990
1991static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1992 int height, int width)
1993{
1994 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1995 struct display *p = &fb_display[vc->vc_num];
1996
1997 if (fbcon_is_inactive(vc, info))
1998 return;
1999
2000 if (!width || !height)
2001 return;
2002
2003 /* Split blits that cross physical y_wrap case.
2004 * Pathological case involves 4 blits, better to use recursive
2005 * code rather than unrolled case
2006 *
2007 * Recursive invocations don't need to erase the cursor over and
2008 * over again, so we use fbcon_bmove_rec()
2009 */
2010 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2011 p->vrows - p->yscroll);
2012}
2013
2014static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2015 int dy, int dx, int height, int width, u_int y_break)
2016{
2017 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2018 struct fbcon_ops *ops = info->fbcon_par;
2019 u_int b;
2020
2021 if (sy < y_break && sy + height > y_break) {
2022 b = y_break - sy;
2023 if (dy < sy) { /* Avoid trashing self */
2024 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2025 y_break);
2026 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2027 height - b, width, y_break);
2028 } else {
2029 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2030 height - b, width, y_break);
2031 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2032 y_break);
2033 }
2034 return;
2035 }
2036
2037 if (dy < y_break && dy + height > y_break) {
2038 b = y_break - dy;
2039 if (dy < sy) { /* Avoid trashing self */
2040 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2041 y_break);
2042 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2043 height - b, width, y_break);
2044 } else {
2045 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2046 height - b, width, y_break);
2047 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2048 y_break);
2049 }
2050 return;
2051 }
2052 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2053 height, width);
2054}
2055
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002056static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002057 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 struct vc_data *vc)
2059{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002060 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 int fh = vc->vc_font.height;
2062 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002063 u16 t = 0;
2064 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2065 info->fix.xpanstep);
2066 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2067 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2068 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2069 info->var.xres_virtual);
2070 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2071 divides(ypan, vc->vc_font.height) && vyres > yres;
2072 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2073 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002074 divides(vc->vc_font.height, vyres) &&
2075 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002077 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2078 !(cap & FBINFO_HWACCEL_DISABLED);
2079 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2080 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002082 p->vrows = vyres/fh;
2083 if (yres > (fh * (vc->vc_rows + 1)))
2084 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2085 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 p->vrows--;
2087
2088 if (good_wrap || good_pan) {
2089 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002090 p->scrollmode = good_wrap ?
2091 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 else
2093 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2094 SCROLL_PAN_REDRAW;
2095 } else {
2096 if (reading_fast || (fast_copyarea && !fast_imageblit))
2097 p->scrollmode = SCROLL_MOVE;
2098 else
2099 p->scrollmode = SCROLL_REDRAW;
2100 }
2101}
2102
2103static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002104 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
2106 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002107 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 struct display *p = &fb_display[vc->vc_num];
2109 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002110 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002112 virt_w = FBCON_SWAP(ops->rotate, width, height);
2113 virt_h = FBCON_SWAP(ops->rotate, height, width);
2114 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2115 vc->vc_font.height);
2116 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2117 vc->vc_font.width);
2118 var.xres = virt_w * virt_fw;
2119 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 x_diff = info->var.xres - var.xres;
2121 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002122 if (x_diff < 0 || x_diff > virt_fw ||
2123 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002124 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
2126 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2127 mode = fb_find_best_mode(&var, &info->modelist);
2128 if (mode == NULL)
2129 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002130 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002132
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002133 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
2136 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2137 if (CON_IS_VISIBLE(vc)) {
2138 var.activate = FB_ACTIVATE_NOW |
2139 FB_ACTIVATE_FORCE;
2140 fb_set_var(info, &var);
2141 }
2142 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002143 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 }
2145 updatescrollmode(p, info, vc);
2146 return 0;
2147}
2148
2149static int fbcon_switch(struct vc_data *vc)
2150{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002151 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002152 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 struct display *p = &fb_display[vc->vc_num];
2154 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002155 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
2157 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002158 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
2160 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 if (softback_lines)
2162 fbcon_set_origin(vc);
2163 softback_top = softback_curr = softback_in = softback_buf;
2164 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002165 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 }
2167
2168 if (logo_shown >= 0) {
2169 struct vc_data *conp2 = vc_cons[logo_shown].d;
2170
2171 if (conp2->vc_top == logo_lines
2172 && conp2->vc_bottom == conp2->vc_rows)
2173 conp2->vc_top = 0;
2174 logo_shown = FBCON_LOGO_CANSHOW;
2175 }
2176
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002177 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002178 if (prev_console != -1)
2179 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 /*
2181 * FIXME: If we have multiple fbdev's loaded, we need to
2182 * update all info->currcon. Perhaps, we can place this
2183 * in a centralized structure, but this might break some
2184 * drivers.
2185 *
2186 * info->currcon = vc->vc_num;
2187 */
2188 for (i = 0; i < FB_MAX; i++) {
2189 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002190 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002192 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 }
2194 }
2195 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2196 display_to_var(&var, p);
2197 var.activate = FB_ACTIVATE_NOW;
2198
2199 /*
2200 * make sure we don't unnecessarily trip the memcmp()
2201 * in fb_set_var()
2202 */
2203 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002204 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002206 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Knut Petersen39942fd2005-12-12 22:17:19 -08002208 if (old_info != NULL && (old_info != info ||
2209 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002210 if (info->fbops->fb_set_par)
2211 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002212
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002213 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002214 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002217 if (fbcon_is_inactive(vc, info) ||
2218 ops->blank_state != FB_BLANK_UNBLANK)
2219 fbcon_del_cursor_timer(info);
2220 else
2221 fbcon_add_cursor_timer(info);
2222
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002223 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002224 ops->cursor_reset = 1;
2225
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002226 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002227 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002228 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002231 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002233
2234 if (p->userfont)
2235 charcnt = FNTCHARCNT(vc->vc_font.data);
2236
2237 if (charcnt > 256)
2238 vc->vc_complement_mask <<= 1;
2239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 updatescrollmode(p, info, vc);
2241
2242 switch (p->scrollmode) {
2243 case SCROLL_WRAP_MOVE:
2244 scrollback_phys_max = p->vrows - vc->vc_rows;
2245 break;
2246 case SCROLL_PAN_MOVE:
2247 case SCROLL_PAN_REDRAW:
2248 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2249 if (scrollback_phys_max < 0)
2250 scrollback_phys_max = 0;
2251 break;
2252 default:
2253 scrollback_phys_max = 0;
2254 break;
2255 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 scrollback_max = 0;
2258 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002259
2260 if (!fbcon_is_inactive(vc, info)) {
2261 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2262 ops->update_start(info);
2263 }
2264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 fbcon_set_palette(vc, color_table);
2266 fbcon_clear_margins(vc, 0);
2267
2268 if (logo_shown == FBCON_LOGO_DRAW) {
2269
2270 logo_shown = fg_console;
2271 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002272 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 update_region(vc,
2274 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2275 vc->vc_size_row * (vc->vc_bottom -
2276 vc->vc_top) / 2);
2277 return 0;
2278 }
2279 return 1;
2280}
2281
2282static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2283 int blank)
2284{
Richard Purdie994efac2007-02-09 09:46:45 +00002285 struct fb_event event;
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 if (blank) {
2288 unsigned short charmask = vc->vc_hi_font_mask ?
2289 0x1ff : 0xff;
2290 unsigned short oldc;
2291
2292 oldc = vc->vc_video_erase_char;
2293 vc->vc_video_erase_char &= charmask;
2294 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2295 vc->vc_video_erase_char = oldc;
2296 }
Richard Purdie994efac2007-02-09 09:46:45 +00002297
2298
2299 event.info = info;
2300 event.data = &blank;
2301 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302}
2303
2304static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2305{
2306 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2307 struct fbcon_ops *ops = info->fbcon_par;
2308
2309 if (mode_switch) {
2310 struct fb_var_screeninfo var = info->var;
2311
2312 ops->graphics = 1;
2313
2314 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002315 if (info->fbops->fb_save_state)
2316 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2318 fb_set_var(info, &var);
2319 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002320 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002321 } else if (info->fbops->fb_restore_state)
2322 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
2324
2325 if (!fbcon_is_inactive(vc, info)) {
2326 if (ops->blank_state != blank) {
2327 ops->blank_state = blank;
2328 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2329 ops->cursor_flash = (!blank);
2330
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002331 if (!(info->flags & FBINFO_MISC_USEREVENT))
2332 if (fb_blank(info, blank))
2333 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 }
2335
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002336 if (!blank)
2337 update_screen(vc);
2338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002340 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002341 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002342 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002343 else
2344 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002345
2346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347}
2348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2350{
2351 u8 *fontdata = vc->vc_font.data;
2352 u8 *data = font->data;
2353 int i, j;
2354
2355 font->width = vc->vc_font.width;
2356 font->height = vc->vc_font.height;
2357 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2358 if (!font->data)
2359 return 0;
2360
2361 if (font->width <= 8) {
2362 j = vc->vc_font.height;
2363 for (i = 0; i < font->charcount; i++) {
2364 memcpy(data, fontdata, j);
2365 memset(data + j, 0, 32 - j);
2366 data += 32;
2367 fontdata += j;
2368 }
2369 } else if (font->width <= 16) {
2370 j = vc->vc_font.height * 2;
2371 for (i = 0; i < font->charcount; i++) {
2372 memcpy(data, fontdata, j);
2373 memset(data + j, 0, 64 - j);
2374 data += 64;
2375 fontdata += j;
2376 }
2377 } else if (font->width <= 24) {
2378 for (i = 0; i < font->charcount; i++) {
2379 for (j = 0; j < vc->vc_font.height; j++) {
2380 *data++ = fontdata[0];
2381 *data++ = fontdata[1];
2382 *data++ = fontdata[2];
2383 fontdata += sizeof(u32);
2384 }
2385 memset(data, 0, 3 * (32 - j));
2386 data += 3 * (32 - j);
2387 }
2388 } else {
2389 j = vc->vc_font.height * 4;
2390 for (i = 0; i < font->charcount; i++) {
2391 memcpy(data, fontdata, j);
2392 memset(data + j, 0, 128 - j);
2393 data += 128;
2394 fontdata += j;
2395 }
2396 }
2397 return 0;
2398}
2399
2400static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002401 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
2403 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002404 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 struct display *p = &fb_display[vc->vc_num];
2406 int resize;
2407 int cnt;
2408 char *old_data = NULL;
2409
2410 if (CON_IS_VISIBLE(vc) && softback_lines)
2411 fbcon_set_origin(vc);
2412
2413 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2414 if (p->userfont)
2415 old_data = vc->vc_font.data;
2416 if (userfont)
2417 cnt = FNTCHARCNT(data);
2418 else
2419 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002420 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 if ((p->userfont = userfont))
2422 REFCOUNT(data)++;
2423 vc->vc_font.width = w;
2424 vc->vc_font.height = h;
2425 if (vc->vc_hi_font_mask && cnt == 256) {
2426 vc->vc_hi_font_mask = 0;
2427 if (vc->vc_can_do_color) {
2428 vc->vc_complement_mask >>= 1;
2429 vc->vc_s_complement_mask >>= 1;
2430 }
2431
2432 /* ++Edmund: reorder the attribute bits */
2433 if (vc->vc_can_do_color) {
2434 unsigned short *cp =
2435 (unsigned short *) vc->vc_origin;
2436 int count = vc->vc_screenbuf_size / 2;
2437 unsigned short c;
2438 for (; count > 0; count--, cp++) {
2439 c = scr_readw(cp);
2440 scr_writew(((c & 0xfe00) >> 1) |
2441 (c & 0xff), cp);
2442 }
2443 c = vc->vc_video_erase_char;
2444 vc->vc_video_erase_char =
2445 ((c & 0xfe00) >> 1) | (c & 0xff);
2446 vc->vc_attr >>= 1;
2447 }
2448 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2449 vc->vc_hi_font_mask = 0x100;
2450 if (vc->vc_can_do_color) {
2451 vc->vc_complement_mask <<= 1;
2452 vc->vc_s_complement_mask <<= 1;
2453 }
2454
2455 /* ++Edmund: reorder the attribute bits */
2456 {
2457 unsigned short *cp =
2458 (unsigned short *) vc->vc_origin;
2459 int count = vc->vc_screenbuf_size / 2;
2460 unsigned short c;
2461 for (; count > 0; count--, cp++) {
2462 unsigned short newc;
2463 c = scr_readw(cp);
2464 if (vc->vc_can_do_color)
2465 newc =
2466 ((c & 0xff00) << 1) | (c &
2467 0xff);
2468 else
2469 newc = c & ~0x100;
2470 scr_writew(newc, cp);
2471 }
2472 c = vc->vc_video_erase_char;
2473 if (vc->vc_can_do_color) {
2474 vc->vc_video_erase_char =
2475 ((c & 0xff00) << 1) | (c & 0xff);
2476 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002477 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 vc->vc_video_erase_char = c & ~0x100;
2479 }
2480
2481 }
2482
2483 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002484 int cols, rows;
2485
2486 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2487 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2488 cols /= w;
2489 rows /= h;
2490 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002491 if (CON_IS_VISIBLE(vc) && softback_buf)
2492 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 } else if (CON_IS_VISIBLE(vc)
2494 && vc->vc_mode == KD_TEXT) {
2495 fbcon_clear_margins(vc, 0);
2496 update_screen(vc);
2497 }
2498
2499 if (old_data && (--REFCOUNT(old_data) == 0))
2500 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2501 return 0;
2502}
2503
2504static int fbcon_copy_font(struct vc_data *vc, int con)
2505{
2506 struct display *od = &fb_display[con];
2507 struct console_font *f = &vc->vc_font;
2508
2509 if (od->fontdata == f->data)
2510 return 0; /* already the same font... */
2511 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2512}
2513
2514/*
2515 * User asked to set font; we are guaranteed that
2516 * a) width and height are in range 1..32
2517 * b) charcount does not exceed 512
2518 * but lets not assume that, since someone might someday want to use larger
2519 * fonts. And charcount of 512 is small for unicode support.
2520 *
2521 * However, user space gives the font in 32 rows , regardless of
2522 * actual font height. So a new API is needed if support for larger fonts
2523 * is ever implemented.
2524 */
2525
2526static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2527{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002528 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 unsigned charcount = font->charcount;
2530 int w = font->width;
2531 int h = font->height;
2532 int size;
2533 int i, csum;
2534 u8 *new_data, *data = font->data;
2535 int pitch = (font->width+7) >> 3;
2536
2537 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2538 * If not this check should be changed to charcount < 256 */
2539 if (charcount != 256 && charcount != 512)
2540 return -EINVAL;
2541
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002542 /* Make sure drawing engine can handle the font */
2543 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2544 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2545 return -EINVAL;
2546
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002547 /* Make sure driver can handle the font length */
2548 if (fbcon_invalid_charcount(info, charcount))
2549 return -EINVAL;
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 size = h * pitch * charcount;
2552
2553 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2554
2555 if (!new_data)
2556 return -ENOMEM;
2557
2558 new_data += FONT_EXTRA_WORDS * sizeof(int);
2559 FNTSIZE(new_data) = size;
2560 FNTCHARCNT(new_data) = charcount;
2561 REFCOUNT(new_data) = 0; /* usage counter */
2562 for (i=0; i< charcount; i++) {
2563 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2564 }
2565
2566 /* Since linux has a nice crc32 function use it for counting font
2567 * checksums. */
2568 csum = crc32(0, new_data, size);
2569
2570 FNTSUM(new_data) = csum;
2571 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002572 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 struct vc_data *tmp = vc_cons[i].d;
2574
2575 if (fb_display[i].userfont &&
2576 fb_display[i].fontdata &&
2577 FNTSUM(fb_display[i].fontdata) == csum &&
2578 FNTSIZE(fb_display[i].fontdata) == size &&
2579 tmp->vc_font.width == w &&
2580 !memcmp(fb_display[i].fontdata, new_data, size)) {
2581 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002582 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 break;
2584 }
2585 }
2586 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2587}
2588
2589static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2590{
2591 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002592 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
2594 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002595 f = get_default_font(info->var.xres, info->var.yres,
2596 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 else if (!(f = find_font(name)))
2598 return -ENOENT;
2599
2600 font->width = f->width;
2601 font->height = f->height;
2602 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2603}
2604
2605static u16 palette_red[16];
2606static u16 palette_green[16];
2607static u16 palette_blue[16];
2608
2609static struct fb_cmap palette_cmap = {
2610 0, 16, palette_red, palette_green, palette_blue, NULL
2611};
2612
2613static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2614{
2615 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2616 int i, j, k, depth;
2617 u8 val;
2618
2619 if (fbcon_is_inactive(vc, info))
2620 return -EINVAL;
2621
2622 if (!CON_IS_VISIBLE(vc))
2623 return 0;
2624
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002625 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 if (depth > 3) {
2627 for (i = j = 0; i < 16; i++) {
2628 k = table[i];
2629 val = vc->vc_palette[j++];
2630 palette_red[k] = (val << 8) | val;
2631 val = vc->vc_palette[j++];
2632 palette_green[k] = (val << 8) | val;
2633 val = vc->vc_palette[j++];
2634 palette_blue[k] = (val << 8) | val;
2635 }
2636 palette_cmap.len = 16;
2637 palette_cmap.start = 0;
2638 /*
2639 * If framebuffer is capable of less than 16 colors,
2640 * use default palette of fbcon.
2641 */
2642 } else
2643 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2644
2645 return fb_set_cmap(&palette_cmap, info);
2646}
2647
2648static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2649{
2650 unsigned long p;
2651 int line;
2652
2653 if (vc->vc_num != fg_console || !softback_lines)
2654 return (u16 *) (vc->vc_origin + offset);
2655 line = offset / vc->vc_size_row;
2656 if (line >= softback_lines)
2657 return (u16 *) (vc->vc_origin + offset -
2658 softback_lines * vc->vc_size_row);
2659 p = softback_curr + offset;
2660 if (p >= softback_end)
2661 p += softback_buf - softback_end;
2662 return (u16 *) p;
2663}
2664
2665static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2666 int *px, int *py)
2667{
2668 unsigned long ret;
2669 int x, y;
2670
2671 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2672 unsigned long offset = (pos - vc->vc_origin) / 2;
2673
2674 x = offset % vc->vc_cols;
2675 y = offset / vc->vc_cols;
2676 if (vc->vc_num == fg_console)
2677 y += softback_lines;
2678 ret = pos + (vc->vc_cols - x) * 2;
2679 } else if (vc->vc_num == fg_console && softback_lines) {
2680 unsigned long offset = pos - softback_curr;
2681
2682 if (pos < softback_curr)
2683 offset += softback_end - softback_buf;
2684 offset /= 2;
2685 x = offset % vc->vc_cols;
2686 y = offset / vc->vc_cols;
2687 ret = pos + (vc->vc_cols - x) * 2;
2688 if (ret == softback_end)
2689 ret = softback_buf;
2690 if (ret == softback_in)
2691 ret = vc->vc_origin;
2692 } else {
2693 /* Should not happen */
2694 x = y = 0;
2695 ret = vc->vc_origin;
2696 }
2697 if (px)
2698 *px = x;
2699 if (py)
2700 *py = y;
2701 return ret;
2702}
2703
2704/* As we might be inside of softback, we may work with non-contiguous buffer,
2705 that's why we have to use a separate routine. */
2706static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2707{
2708 while (cnt--) {
2709 u16 a = scr_readw(p);
2710 if (!vc->vc_can_do_color)
2711 a ^= 0x0800;
2712 else if (vc->vc_hi_font_mask == 0x100)
2713 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2714 (((a) & 0x0e00) << 4);
2715 else
2716 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2717 (((a) & 0x0700) << 4);
2718 scr_writew(a, p++);
2719 if (p == (u16 *) softback_end)
2720 p = (u16 *) softback_buf;
2721 if (p == (u16 *) softback_in)
2722 p = (u16 *) vc->vc_origin;
2723 }
2724}
2725
2726static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2727{
2728 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002729 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002730 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 int offset, limit, scrollback_old;
2732
2733 if (softback_top) {
2734 if (vc->vc_num != fg_console)
2735 return 0;
2736 if (vc->vc_mode != KD_TEXT || !lines)
2737 return 0;
2738 if (logo_shown >= 0) {
2739 struct vc_data *conp2 = vc_cons[logo_shown].d;
2740
2741 if (conp2->vc_top == logo_lines
2742 && conp2->vc_bottom == conp2->vc_rows)
2743 conp2->vc_top = 0;
2744 if (logo_shown == vc->vc_num) {
2745 unsigned long p, q;
2746 int i;
2747
2748 p = softback_in;
2749 q = vc->vc_origin +
2750 logo_lines * vc->vc_size_row;
2751 for (i = 0; i < logo_lines; i++) {
2752 if (p == softback_top)
2753 break;
2754 if (p == softback_buf)
2755 p = softback_end;
2756 p -= vc->vc_size_row;
2757 q -= vc->vc_size_row;
2758 scr_memcpyw((u16 *) q, (u16 *) p,
2759 vc->vc_size_row);
2760 }
David Hollister308af922006-05-30 21:25:36 -07002761 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 update_region(vc, vc->vc_origin,
2763 logo_lines * vc->vc_cols);
2764 }
2765 logo_shown = FBCON_LOGO_CANSHOW;
2766 }
2767 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002768 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2770 return 0;
2771 }
2772
2773 if (!scrollback_phys_max)
2774 return -ENOSYS;
2775
2776 scrollback_old = scrollback_current;
2777 scrollback_current -= lines;
2778 if (scrollback_current < 0)
2779 scrollback_current = 0;
2780 else if (scrollback_current > scrollback_max)
2781 scrollback_current = scrollback_max;
2782 if (scrollback_current == scrollback_old)
2783 return 0;
2784
2785 if (fbcon_is_inactive(vc, info))
2786 return 0;
2787
2788 fbcon_cursor(vc, CM_ERASE);
2789
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002790 offset = disp->yscroll - scrollback_current;
2791 limit = disp->vrows;
2792 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 case SCROLL_WRAP_MOVE:
2794 info->var.vmode |= FB_VMODE_YWRAP;
2795 break;
2796 case SCROLL_PAN_MOVE:
2797 case SCROLL_PAN_REDRAW:
2798 limit -= vc->vc_rows;
2799 info->var.vmode &= ~FB_VMODE_YWRAP;
2800 break;
2801 }
2802 if (offset < 0)
2803 offset += limit;
2804 else if (offset >= limit)
2805 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002806
2807 ops->var.xoffset = 0;
2808 ops->var.yoffset = offset * vc->vc_font.height;
2809 ops->update_start(info);
2810
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 if (!scrollback_current)
2812 fbcon_cursor(vc, CM_DRAW);
2813 return 0;
2814}
2815
2816static int fbcon_set_origin(struct vc_data *vc)
2817{
2818 if (softback_lines)
2819 fbcon_scrolldelta(vc, softback_lines);
2820 return 0;
2821}
2822
2823static void fbcon_suspended(struct fb_info *info)
2824{
2825 struct vc_data *vc = NULL;
2826 struct fbcon_ops *ops = info->fbcon_par;
2827
2828 if (!ops || ops->currcon < 0)
2829 return;
2830 vc = vc_cons[ops->currcon].d;
2831
2832 /* Clear cursor, restore saved data */
2833 fbcon_cursor(vc, CM_ERASE);
2834}
2835
2836static void fbcon_resumed(struct fb_info *info)
2837{
2838 struct vc_data *vc;
2839 struct fbcon_ops *ops = info->fbcon_par;
2840
2841 if (!ops || ops->currcon < 0)
2842 return;
2843 vc = vc_cons[ops->currcon].d;
2844
2845 update_screen(vc);
2846}
2847
2848static void fbcon_modechanged(struct fb_info *info)
2849{
2850 struct fbcon_ops *ops = info->fbcon_par;
2851 struct vc_data *vc;
2852 struct display *p;
2853 int rows, cols;
2854
2855 if (!ops || ops->currcon < 0)
2856 return;
2857 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002858 if (vc->vc_mode != KD_TEXT ||
2859 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 return;
2861
2862 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002863 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865 if (CON_IS_VISIBLE(vc)) {
2866 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002867 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2868 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2869 cols /= vc->vc_font.width;
2870 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 vc_resize(vc, cols, rows);
2872 updatescrollmode(p, info, vc);
2873 scrollback_max = 0;
2874 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002875
2876 if (!fbcon_is_inactive(vc, info)) {
2877 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2878 ops->update_start(info);
2879 }
2880
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 fbcon_set_palette(vc, color_table);
2882 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002883 if (softback_buf)
2884 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 }
2886}
2887
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002888static void fbcon_set_all_vcs(struct fb_info *info)
2889{
2890 struct fbcon_ops *ops = info->fbcon_par;
2891 struct vc_data *vc;
2892 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002893 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002894
2895 if (!ops || ops->currcon < 0)
2896 return;
2897
Antonino A. Daplase614b182006-06-26 00:27:09 -07002898 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002899 vc = vc_cons[i].d;
2900 if (!vc || vc->vc_mode != KD_TEXT ||
2901 registered_fb[con2fb_map[i]] != info)
2902 continue;
2903
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002904 if (CON_IS_VISIBLE(vc)) {
2905 fg = i;
2906 continue;
2907 }
2908
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002909 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002910 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002911 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002912 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2913 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002914 cols /= vc->vc_font.width;
2915 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002916 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002917 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002918
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002919 if (fg != -1)
2920 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002921}
2922
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923static int fbcon_mode_deleted(struct fb_info *info,
2924 struct fb_videomode *mode)
2925{
2926 struct fb_info *fb_info;
2927 struct display *p;
2928 int i, j, found = 0;
2929
2930 /* before deletion, ensure that mode is not in use */
2931 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2932 j = con2fb_map[i];
2933 if (j == -1)
2934 continue;
2935 fb_info = registered_fb[j];
2936 if (fb_info != info)
2937 continue;
2938 p = &fb_display[i];
2939 if (!p || !p->mode)
2940 continue;
2941 if (fb_mode_is_equal(p->mode, mode)) {
2942 found = 1;
2943 break;
2944 }
2945 }
2946 return found;
2947}
2948
Jesse Barnescfafca82007-07-17 04:05:33 -07002949#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2950static int fbcon_unbind(void)
2951{
2952 int ret;
2953
2954 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2955 fbcon_is_default);
2956 return ret;
2957}
2958#else
2959static inline int fbcon_unbind(void)
2960{
2961 return -EINVAL;
2962}
2963#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2964
2965static int fbcon_fb_unbind(int idx)
2966{
2967 int i, new_idx = -1, ret = 0;
2968
2969 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2970 if (con2fb_map[i] != idx &&
2971 con2fb_map[i] != -1) {
2972 new_idx = i;
2973 break;
2974 }
2975 }
2976
2977 if (new_idx != -1) {
2978 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2979 if (con2fb_map[i] == idx)
2980 set_con2fb_map(i, new_idx, 0);
2981 }
2982 } else
2983 ret = fbcon_unbind();
2984
2985 return ret;
2986}
2987
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002988static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07002989{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002990 int i, idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07002991
2992 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2993 if (con2fb_map[i] == idx)
2994 con2fb_map[i] = -1;
2995 }
2996
2997 if (idx == info_idx) {
2998 info_idx = -1;
2999
3000 for (i = 0; i < FB_MAX; i++) {
3001 if (registered_fb[i] != NULL) {
3002 info_idx = i;
3003 break;
3004 }
3005 }
3006 }
3007
3008 if (info_idx != -1) {
3009 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3010 if (con2fb_map[i] == -1)
3011 con2fb_map[i] = info_idx;
3012 }
3013 }
3014
3015 if (!num_registered_fb)
3016 unregister_con_driver(&fb_con);
3017
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003018
3019 if (primary_device == idx)
3020 primary_device = -1;
3021
Antonino A. Daplase614b182006-06-26 00:27:09 -07003022 return 0;
3023}
3024
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003025#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003026static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003028 if (!map_override && primary_device == -1 &&
3029 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003030 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003031
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003032 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3033 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003034 primary_device = info->node;
3035
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003036 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003037 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003038
3039 if (con_is_bound(&fb_con)) {
3040 printk(KERN_INFO "fbcon: Remapping primary device, "
3041 "fb%i, to tty %i-%i\n", info->node,
3042 first_fb_vc + 1, last_fb_vc + 1);
3043 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003044 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003045 }
3046
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003047}
3048#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003049static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003050{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003051 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003052}
3053#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3054
3055static int fbcon_fb_registered(struct fb_info *info)
3056{
3057 int ret = 0, i, idx = info->node;
3058
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003059 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
3061 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003062 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 if (con2fb_map_boot[i] == idx) {
3064 info_idx = idx;
3065 break;
3066 }
3067 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003068
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 if (info_idx != -1)
3070 ret = fbcon_takeover(1);
3071 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003072 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003073 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 set_con2fb_map(i, idx, 0);
3075 }
3076 }
3077
3078 return ret;
3079}
3080
3081static void fbcon_fb_blanked(struct fb_info *info, int blank)
3082{
3083 struct fbcon_ops *ops = info->fbcon_par;
3084 struct vc_data *vc;
3085
3086 if (!ops || ops->currcon < 0)
3087 return;
3088
3089 vc = vc_cons[ops->currcon].d;
3090 if (vc->vc_mode != KD_TEXT ||
3091 registered_fb[con2fb_map[ops->currcon]] != info)
3092 return;
3093
3094 if (CON_IS_VISIBLE(vc)) {
3095 if (blank)
3096 do_blank_screen(0);
3097 else
3098 do_unblank_screen(0);
3099 }
3100 ops->blank_state = blank;
3101}
3102
3103static void fbcon_new_modelist(struct fb_info *info)
3104{
3105 int i;
3106 struct vc_data *vc;
3107 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003108 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109
Antonino A. Daplase614b182006-06-26 00:27:09 -07003110 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 if (registered_fb[con2fb_map[i]] != info)
3112 continue;
3113 if (!fb_display[i].mode)
3114 continue;
3115 vc = vc_cons[i].d;
3116 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003117 mode = fb_find_nearest_mode(fb_display[i].mode,
3118 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003120 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 }
3122}
3123
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003124static void fbcon_get_requirement(struct fb_info *info,
3125 struct fb_blit_caps *caps)
3126{
3127 struct vc_data *vc;
3128 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003129
3130 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003131 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003132
3133 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3134 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003135 if (vc && vc->vc_mode == KD_TEXT &&
3136 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003137 p = &fb_display[i];
3138 caps->x |= 1 << (vc->vc_font.width - 1);
3139 caps->y |= 1 << (vc->vc_font.height - 1);
3140 charcnt = (p->userfont) ?
3141 FNTCHARCNT(p->fontdata) : 256;
3142 if (caps->len < charcnt)
3143 caps->len = charcnt;
3144 }
3145 }
3146 } else {
3147 vc = vc_cons[fg_console].d;
3148
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003149 if (vc && vc->vc_mode == KD_TEXT &&
3150 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003151 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003152 caps->x = 1 << (vc->vc_font.width - 1);
3153 caps->y = 1 << (vc->vc_font.height - 1);
3154 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003155 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003156 }
3157 }
3158}
3159
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160static int fbcon_event_notify(struct notifier_block *self,
3161 unsigned long action, void *data)
3162{
3163 struct fb_event *event = data;
3164 struct fb_info *info = event->info;
3165 struct fb_videomode *mode;
3166 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003167 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 int ret = 0;
3169
Antonino A. Daplase614b182006-06-26 00:27:09 -07003170 /*
3171 * ignore all events except driver registration and deregistration
3172 * if fbcon is not active
3173 */
3174 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3175 action == FB_EVENT_FB_UNREGISTERED))
3176 goto done;
3177
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 switch(action) {
3179 case FB_EVENT_SUSPEND:
3180 fbcon_suspended(info);
3181 break;
3182 case FB_EVENT_RESUME:
3183 fbcon_resumed(info);
3184 break;
3185 case FB_EVENT_MODE_CHANGE:
3186 fbcon_modechanged(info);
3187 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003188 case FB_EVENT_MODE_CHANGE_ALL:
3189 fbcon_set_all_vcs(info);
3190 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 case FB_EVENT_MODE_DELETE:
3192 mode = event->data;
3193 ret = fbcon_mode_deleted(info, mode);
3194 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003195 case FB_EVENT_FB_UNBIND:
3196 ret = fbcon_fb_unbind(info->node);
3197 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003199 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003201 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003202 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 case FB_EVENT_SET_CONSOLE_MAP:
3205 con2fb = event->data;
3206 ret = set_con2fb_map(con2fb->console - 1,
3207 con2fb->framebuffer, 1);
3208 break;
3209 case FB_EVENT_GET_CONSOLE_MAP:
3210 con2fb = event->data;
3211 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3212 break;
3213 case FB_EVENT_BLANK:
3214 fbcon_fb_blanked(info, *(int *)event->data);
3215 break;
3216 case FB_EVENT_NEW_MODELIST:
3217 fbcon_new_modelist(info);
3218 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003219 case FB_EVENT_GET_REQ:
3220 caps = event->data;
3221 fbcon_get_requirement(info, caps);
3222 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 }
3224
Antonino A. Daplase614b182006-06-26 00:27:09 -07003225done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 return ret;
3227}
3228
3229/*
3230 * The console `switch' structure for the frame buffer based console
3231 */
3232
3233static const struct consw fb_con = {
3234 .owner = THIS_MODULE,
3235 .con_startup = fbcon_startup,
3236 .con_init = fbcon_init,
3237 .con_deinit = fbcon_deinit,
3238 .con_clear = fbcon_clear,
3239 .con_putc = fbcon_putc,
3240 .con_putcs = fbcon_putcs,
3241 .con_cursor = fbcon_cursor,
3242 .con_scroll = fbcon_scroll,
3243 .con_bmove = fbcon_bmove,
3244 .con_switch = fbcon_switch,
3245 .con_blank = fbcon_blank,
3246 .con_font_set = fbcon_set_font,
3247 .con_font_get = fbcon_get_font,
3248 .con_font_default = fbcon_set_def_font,
3249 .con_font_copy = fbcon_copy_font,
3250 .con_set_palette = fbcon_set_palette,
3251 .con_scrolldelta = fbcon_scrolldelta,
3252 .con_set_origin = fbcon_set_origin,
3253 .con_invert_region = fbcon_invert_region,
3254 .con_screen_pos = fbcon_screen_pos,
3255 .con_getxy = fbcon_getxy,
3256 .con_resize = fbcon_resize,
3257};
3258
3259static struct notifier_block fbcon_event_notifier = {
3260 .notifier_call = fbcon_event_notify,
3261};
3262
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003263static ssize_t store_rotate(struct device *device,
3264 struct device_attribute *attr, const char *buf,
3265 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003266{
3267 struct fb_info *info;
3268 int rotate, idx;
3269 char **last = NULL;
3270
Antonino A. Daplase614b182006-06-26 00:27:09 -07003271 if (fbcon_has_exited)
3272 return count;
3273
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003274 acquire_console_sem();
3275 idx = con2fb_map[fg_console];
3276
3277 if (idx == -1 || registered_fb[idx] == NULL)
3278 goto err;
3279
3280 info = registered_fb[idx];
3281 rotate = simple_strtoul(buf, last, 0);
3282 fbcon_rotate(info, rotate);
3283err:
3284 release_console_sem();
3285 return count;
3286}
3287
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003288static ssize_t store_rotate_all(struct device *device,
3289 struct device_attribute *attr,const char *buf,
3290 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003291{
3292 struct fb_info *info;
3293 int rotate, idx;
3294 char **last = NULL;
3295
Antonino A. Daplase614b182006-06-26 00:27:09 -07003296 if (fbcon_has_exited)
3297 return count;
3298
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003299 acquire_console_sem();
3300 idx = con2fb_map[fg_console];
3301
3302 if (idx == -1 || registered_fb[idx] == NULL)
3303 goto err;
3304
3305 info = registered_fb[idx];
3306 rotate = simple_strtoul(buf, last, 0);
3307 fbcon_rotate_all(info, rotate);
3308err:
3309 release_console_sem();
3310 return count;
3311}
3312
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003313static ssize_t show_rotate(struct device *device,
3314 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003315{
3316 struct fb_info *info;
3317 int rotate = 0, idx;
3318
Antonino A. Daplase614b182006-06-26 00:27:09 -07003319 if (fbcon_has_exited)
3320 return 0;
3321
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003322 acquire_console_sem();
3323 idx = con2fb_map[fg_console];
3324
3325 if (idx == -1 || registered_fb[idx] == NULL)
3326 goto err;
3327
3328 info = registered_fb[idx];
3329 rotate = fbcon_get_rotate(info);
3330err:
3331 release_console_sem();
3332 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3333}
3334
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003335static ssize_t show_cursor_blink(struct device *device,
3336 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003337{
3338 struct fb_info *info;
3339 struct fbcon_ops *ops;
3340 int idx, blink = -1;
3341
3342 if (fbcon_has_exited)
3343 return 0;
3344
3345 acquire_console_sem();
3346 idx = con2fb_map[fg_console];
3347
3348 if (idx == -1 || registered_fb[idx] == NULL)
3349 goto err;
3350
3351 info = registered_fb[idx];
3352 ops = info->fbcon_par;
3353
3354 if (!ops)
3355 goto err;
3356
3357 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3358err:
3359 release_console_sem();
3360 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3361}
3362
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003363static ssize_t store_cursor_blink(struct device *device,
3364 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003365 const char *buf, size_t count)
3366{
3367 struct fb_info *info;
3368 int blink, idx;
3369 char **last = NULL;
3370
3371 if (fbcon_has_exited)
3372 return count;
3373
3374 acquire_console_sem();
3375 idx = con2fb_map[fg_console];
3376
3377 if (idx == -1 || registered_fb[idx] == NULL)
3378 goto err;
3379
3380 info = registered_fb[idx];
3381
3382 if (!info->fbcon_par)
3383 goto err;
3384
3385 blink = simple_strtoul(buf, last, 0);
3386
3387 if (blink) {
3388 fbcon_cursor_noblink = 0;
3389 fbcon_add_cursor_timer(info);
3390 } else {
3391 fbcon_cursor_noblink = 1;
3392 fbcon_del_cursor_timer(info);
3393 }
3394
3395err:
3396 release_console_sem();
3397 return count;
3398}
3399
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003400static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003401 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3402 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003403 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3404 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003405};
3406
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003407static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003408{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003409 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003410
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003411 fbcon_has_sysfs = 1;
3412
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003413 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3414 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003415
3416 if (error)
3417 break;
3418 }
3419
3420 if (error) {
3421 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003422 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003423
3424 fbcon_has_sysfs = 0;
3425 }
3426
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003427 return 0;
3428}
3429
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003430static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003433 int i;
3434
3435 acquire_console_sem();
3436
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 for (i = 0; i < FB_MAX; i++) {
3438 if (registered_fb[i] != NULL) {
3439 info_idx = i;
3440 break;
3441 }
3442 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003443
3444 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 fbcon_takeover(0);
3446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447}
3448
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003449static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003450{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003451 struct fb_info *info;
3452 int i, j, mapped;
3453
Antonino A. Daplase614b182006-06-26 00:27:09 -07003454 if (fbcon_has_exited)
3455 return;
3456
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003457#ifdef CONFIG_ATARI
Geert Uytterhoeven7f877eb2008-11-18 20:45:23 +01003458 if (MACH_IS_ATARI)
3459 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003460#endif
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003461
3462 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003463 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003464
3465 for (i = 0; i < FB_MAX; i++) {
Geoff Levandbeaa4862008-12-09 13:14:17 -08003466 int pending;
3467
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003468 mapped = 0;
3469 info = registered_fb[i];
3470
3471 if (info == NULL)
3472 continue;
3473
Geoff Levandbeaa4862008-12-09 13:14:17 -08003474 pending = cancel_work_sync(&info->queue);
3475 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3476 "no"));
3477
Antonino A. Daplase614b182006-06-26 00:27:09 -07003478 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3479 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003480 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003481 }
3482
3483 if (mapped) {
3484 if (info->fbops->fb_release)
3485 info->fbops->fb_release(info, 0);
3486 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003487
3488 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003489 struct fbcon_ops *ops = info->fbcon_par;
3490
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003491 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003492 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003493 kfree(info->fbcon_par);
3494 info->fbcon_par = NULL;
3495 }
3496
3497 if (info->queue.func == fb_flashcursor)
3498 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003499 }
3500 }
3501
Antonino A. Daplase614b182006-06-26 00:27:09 -07003502 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003503}
3504
3505static int __init fb_console_init(void)
3506{
3507 int i;
3508
3509 acquire_console_sem();
3510 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003511 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3512 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003513
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003514 if (IS_ERR(fbcon_device)) {
3515 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003516 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003517 PTR_ERR(fbcon_device));
3518 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003519 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003520 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003521
3522 for (i = 0; i < MAX_NR_CONSOLES; i++)
3523 con2fb_map[i] = -1;
3524
3525 release_console_sem();
3526 fbcon_start();
3527 return 0;
3528}
3529
3530module_init(fb_console_init);
3531
3532#ifdef MODULE
3533
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003534static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003535{
3536 int i;
3537
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003538 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003539 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3540 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003541
3542 fbcon_has_sysfs = 0;
3543 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003544}
3545
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546static void __exit fb_console_exit(void)
3547{
3548 acquire_console_sem();
3549 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003550 fbcon_deinit_device();
3551 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003552 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003554 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555}
3556
3557module_exit(fb_console_exit);
3558
3559#endif
3560
3561MODULE_LICENSE("GPL");