blob: 73813c60d03a9c010597c35a3960216005fe9ea2 [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 */
78#include <asm/irq.h>
79#include <asm/system.h>
80#include <asm/uaccess.h>
81#ifdef CONFIG_ATARI
82#include <asm/atariints.h>
83#endif
84#ifdef CONFIG_MAC
85#include <asm/macints.h>
86#endif
87#if defined(__mc68000__) || defined(CONFIG_APUS)
88#include <asm/machdep.h>
89#include <asm/setup.h>
90#endif
91
92#include "fbcon.h"
93
94#ifdef FBCONDEBUG
95# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
96#else
97# define DPRINTK(fmt, args...)
98#endif
99
100enum {
101 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
104};
105
Antonino A. Daplasab767202005-11-13 16:06:32 -0800106static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static signed char con2fb_map[MAX_NR_CONSOLES];
109static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700110#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int logo_height;
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static int logo_lines;
114/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
115 enums. */
116static int logo_shown = FBCON_LOGO_CANSHOW;
117/* Software scrollback */
118static int fbcon_softback_size = 32768;
119static unsigned long softback_buf, softback_curr;
120static unsigned long softback_in;
121static unsigned long softback_top, softback_end;
122static int softback_lines;
123/* console mappings */
124static int first_fb_vc;
125static int last_fb_vc = MAX_NR_CONSOLES - 1;
126static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700127static int fbcon_has_exited;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/* font data */
130static char fontname[40];
131
132/* current fb_info */
133static int info_idx = -1;
134
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800135/* console rotation */
136static int rotate;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700137static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139static const struct consw fb_con;
140
141#define CM_SOFTBACK (8)
142
143#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static int fbcon_set_origin(struct vc_data *);
146
147#define CURSOR_DRAW_DELAY (1)
148
149/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#define ATARI_CURSOR_BLINK_RATE (42)
151#define MAC_CURSOR_BLINK_RATE (32)
152#define DEFAULT_CURSOR_BLINK_RATE (20)
153
154static int vbl_cursor_cnt;
155
156#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
157
158/*
159 * Interface used by the world
160 */
161
162static const char *fbcon_startup(void);
163static void fbcon_init(struct vc_data *vc, int init);
164static void fbcon_deinit(struct vc_data *vc);
165static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
166 int width);
167static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
168static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
169 int count, int ypos, int xpos);
170static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
171static void fbcon_cursor(struct vc_data *vc, int mode);
172static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
173 int count);
174static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
175 int height, int width);
176static int fbcon_switch(struct vc_data *vc);
177static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
178static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
179static int fbcon_scrolldelta(struct vc_data *vc, int lines);
180
181/*
182 * Internal routines
183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static __inline__ void ywrap_up(struct vc_data *vc, int count);
185static __inline__ void ywrap_down(struct vc_data *vc, int count);
186static __inline__ void ypan_up(struct vc_data *vc, int count);
187static __inline__ void ypan_down(struct vc_data *vc, int count);
188static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 struct vc_data *vc);
192static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
193 int unit);
194static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
195 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800196static void fbcon_modechanged(struct fb_info *info);
197static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700198static void fbcon_start(void);
199static void fbcon_exit(void);
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700200static struct class_device *fbcon_class_device;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#ifdef CONFIG_MAC
203/*
204 * On the Macintoy, there may or may not be a working VBL int. We need to probe
205 */
206static int vbl_detected;
207
David Howells7d12e782006-10-05 14:55:46 +0100208static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 vbl_detected++;
211 return IRQ_HANDLED;
212}
213#endif
214
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800215#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800216static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800217{
218 struct fbcon_ops *ops = info->fbcon_par;
219
220 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800221 ops->p->con_rotate < 4)
222 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800223 else
224 ops->rotate = 0;
225}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800226
227static void fbcon_rotate(struct fb_info *info, u32 rotate)
228{
229 struct fbcon_ops *ops= info->fbcon_par;
230 struct fb_info *fb_info;
231
232 if (!ops || ops->currcon == -1)
233 return;
234
235 fb_info = registered_fb[con2fb_map[ops->currcon]];
236
237 if (info == fb_info) {
238 struct display *p = &fb_display[ops->currcon];
239
240 if (rotate < 4)
241 p->con_rotate = rotate;
242 else
243 p->con_rotate = 0;
244
245 fbcon_modechanged(info);
246 }
247}
248
249static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
250{
251 struct fbcon_ops *ops = info->fbcon_par;
252 struct vc_data *vc;
253 struct display *p;
254 int i;
255
256 if (!ops || ops->currcon < 0 || rotate > 3)
257 return;
258
Antonino A. Daplase614b182006-06-26 00:27:09 -0700259 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800260 vc = vc_cons[i].d;
261 if (!vc || vc->vc_mode != KD_TEXT ||
262 registered_fb[con2fb_map[i]] != info)
263 continue;
264
265 p = &fb_display[vc->vc_num];
266 p->con_rotate = rotate;
267 }
268
269 fbcon_set_all_vcs(info);
270}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800271#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800272static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800273{
274 struct fbcon_ops *ops = info->fbcon_par;
275
276 ops->rotate = FB_ROTATE_UR;
277}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800278
279static void fbcon_rotate(struct fb_info *info, u32 rotate)
280{
281 return;
282}
283
284static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
285{
286 return;
287}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800288#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800289
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800290static int fbcon_get_rotate(struct fb_info *info)
291{
292 struct fbcon_ops *ops = info->fbcon_par;
293
294 return (ops) ? ops->rotate : 0;
295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
298{
299 struct fbcon_ops *ops = info->fbcon_par;
300
301 return (info->state != FBINFO_STATE_RUNNING ||
302 vc->vc_mode != KD_TEXT || ops->graphics);
303}
304
305static inline int get_color(struct vc_data *vc, struct fb_info *info,
306 u16 c, int is_fg)
307{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700308 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 int color = 0;
310
311 if (console_blanked) {
312 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
313
314 c = vc->vc_video_erase_char & charmask;
315 }
316
317 if (depth != 1)
318 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
319 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
320
321 switch (depth) {
322 case 1:
323 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700324 int col = ~(0xfff << (max(info->var.green.length,
325 max(info->var.red.length,
326 info->var.blue.length)))) & 0xff;
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700329 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
330 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 if (console_blanked)
333 fg = bg;
334
335 color = (is_fg) ? fg : bg;
336 break;
337 }
338 case 2:
339 /*
340 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700341 * is grayscale. However, simply dividing the values by 4
342 * will not work, as colors 1, 2 and 3 will be scaled-down
343 * to zero rendering them invisible. So empirically convert
344 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700346 switch (color) {
347 case 0:
348 color = 0; /* black */
349 break;
350 case 1 ... 6:
351 color = 2; /* white */
352 break;
353 case 7 ... 8:
354 color = 1; /* gray */
355 break;
356 default:
357 color = 3; /* intense white */
358 break;
359 }
360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 case 3:
362 /*
363 * Last 8 entries of default 16-color palette is a more intense
364 * version of the first 8 (i.e., same chrominance, different
365 * luminance).
366 */
367 color &= 7;
368 break;
369 }
370
371
372 return color;
373}
374
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800375static void fbcon_update_softback(struct vc_data *vc)
376{
377 int l = fbcon_softback_size / vc->vc_size_row;
378
379 if (l > 5)
380 softback_end = softback_buf + l * vc->vc_size_row;
381 else
382 /* Smaller scrollback makes no sense, and 0 would screw
383 the operation totally */
384 softback_top = 0;
385}
386
David Howellsc4028952006-11-22 14:57:56 +0000387static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
David Howellsc4028952006-11-22 14:57:56 +0000389 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 struct fbcon_ops *ops = info->fbcon_par;
391 struct display *p;
392 struct vc_data *vc = NULL;
393 int c;
394 int mode;
395
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700396 acquire_console_sem();
397 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 vc = vc_cons[ops->currcon].d;
399
400 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700401 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700402 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700403 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700405 }
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 p = &fb_display[vc->vc_num];
408 c = scr_readw((u16 *) vc->vc_pos);
409 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
410 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800411 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 get_color(vc, info, c, 0));
413 release_console_sem();
414}
415
Russell King41359dc2005-06-30 16:30:07 +0100416#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100418static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 struct fb_info *info = dev_id;
421
422 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
423 schedule_work(&info->queue);
424 vbl_cursor_cnt = cursor_blink_rate;
425 }
426 return IRQ_HANDLED;
427}
428#endif
429
430static void cursor_timer_handler(unsigned long dev_addr)
431{
432 struct fb_info *info = (struct fb_info *) dev_addr;
433 struct fbcon_ops *ops = info->fbcon_par;
434
435 schedule_work(&info->queue);
436 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
437}
438
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700439static void fbcon_add_cursor_timer(struct fb_info *info)
440{
441 struct fbcon_ops *ops = info->fbcon_par;
442
443 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
444 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
445 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000446 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700447
448 init_timer(&ops->cursor_timer);
449 ops->cursor_timer.function = cursor_timer_handler;
450 ops->cursor_timer.expires = jiffies + HZ / 5;
451 ops->cursor_timer.data = (unsigned long ) info;
452 add_timer(&ops->cursor_timer);
453 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
454 }
455}
456
457static void fbcon_del_cursor_timer(struct fb_info *info)
458{
459 struct fbcon_ops *ops = info->fbcon_par;
460
461 if (info->queue.func == fb_flashcursor &&
462 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
463 del_timer_sync(&ops->cursor_timer);
464 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
465 }
466}
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#ifndef MODULE
469static int __init fb_console_setup(char *this_opt)
470{
471 char *options;
472 int i, j;
473
474 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800475 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 while ((options = strsep(&this_opt, ",")) != NULL) {
478 if (!strncmp(options, "font:", 5))
479 strcpy(fontname, options + 5);
480
481 if (!strncmp(options, "scrollback:", 11)) {
482 options += 11;
483 if (*options) {
484 fbcon_softback_size = simple_strtoul(options, &options, 0);
485 if (*options == 'k' || *options == 'K') {
486 fbcon_softback_size *= 1024;
487 options++;
488 }
489 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800490 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 options++;
492 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800493 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
496 if (!strncmp(options, "map:", 4)) {
497 options += 4;
498 if (*options)
499 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
500 if (!options[j])
501 j = 0;
502 con2fb_map_boot[i] =
503 (options[j++]-'0') % FB_MAX;
504 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800505 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
508 if (!strncmp(options, "vc:", 3)) {
509 options += 3;
510 if (*options)
511 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
512 if (first_fb_vc < 0)
513 first_fb_vc = 0;
514 if (*options++ == '-')
515 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
516 fbcon_is_default = 0;
517 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800518
519 if (!strncmp(options, "rotate:", 7)) {
520 options += 7;
521 if (*options)
522 rotate = simple_strtoul(options, &options, 0);
523 if (rotate > 3)
524 rotate = 0;
525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800527 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
530__setup("fbcon=", fb_console_setup);
531#endif
532
533static int search_fb_in_map(int idx)
534{
535 int i, retval = 0;
536
Antonino A. Daplase614b182006-06-26 00:27:09 -0700537 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (con2fb_map[i] == idx)
539 retval = 1;
540 }
541 return retval;
542}
543
544static int search_for_mapped_con(void)
545{
546 int i, retval = 0;
547
Antonino A. Daplase614b182006-06-26 00:27:09 -0700548 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (con2fb_map[i] != -1)
550 retval = 1;
551 }
552 return retval;
553}
554
555static int fbcon_takeover(int show_logo)
556{
557 int err, i;
558
559 if (!num_registered_fb)
560 return -ENODEV;
561
562 if (!show_logo)
563 logo_shown = FBCON_LOGO_DONTSHOW;
564
565 for (i = first_fb_vc; i <= last_fb_vc; i++)
566 con2fb_map[i] = info_idx;
567
568 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
569 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (err) {
572 for (i = first_fb_vc; i <= last_fb_vc; i++) {
573 con2fb_map[i] = -1;
574 }
575 info_idx = -1;
576 }
577
578 return err;
579}
580
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700581#ifdef MODULE
582static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
583 int cols, int rows, int new_cols, int new_rows)
584{
585 logo_shown = FBCON_LOGO_DONTSHOW;
586}
587#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
589 int cols, int rows, int new_cols, int new_rows)
590{
591 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800592 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 int cnt, erase = vc->vc_video_erase_char, step;
594 unsigned short *save = NULL, *r, *q;
595
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700596 if (info->flags & FBINFO_MODULE) {
597 logo_shown = FBCON_LOGO_DONTSHOW;
598 return;
599 }
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 /*
602 * remove underline attribute from erase character
603 * if black and white framebuffer.
604 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700605 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800607 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 logo_lines = (logo_height + vc->vc_font.height - 1) /
609 vc->vc_font.height;
610 q = (unsigned short *) (vc->vc_origin +
611 vc->vc_size_row * rows);
612 step = logo_lines * cols;
613 for (r = q - logo_lines * cols; r < q; r++)
614 if (scr_readw(r) != vc->vc_video_erase_char)
615 break;
616 if (r != q && new_rows >= rows + logo_lines) {
617 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
618 if (save) {
619 int i = cols < new_cols ? cols : new_cols;
620 scr_memsetw(save, erase, logo_lines * new_cols * 2);
621 r = q - step;
622 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
623 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
624 r = q;
625 }
626 }
627 if (r == q) {
628 /* We can scroll screen down */
629 r = q - step - cols;
630 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
631 scr_memcpyw(r + step, r, vc->vc_size_row);
632 r -= cols;
633 }
634 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700635 int lines;
636 if (vc->vc_y + logo_lines >= rows)
637 lines = rows - vc->vc_y - 1;
638 else
639 lines = logo_lines;
640 vc->vc_y += lines;
641 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 }
644 scr_memsetw((unsigned short *) vc->vc_origin,
645 erase,
646 vc->vc_size_row * logo_lines);
647
648 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
649 fbcon_clear_margins(vc, 0);
650 update_screen(vc);
651 }
652
653 if (save) {
654 q = (unsigned short *) (vc->vc_origin +
655 vc->vc_size_row *
656 rows);
657 scr_memcpyw(q, save, logo_lines * new_cols * 2);
658 vc->vc_y += logo_lines;
659 vc->vc_pos += logo_lines * vc->vc_size_row;
660 kfree(save);
661 }
662
663 if (logo_lines > vc->vc_bottom) {
664 logo_shown = FBCON_LOGO_CANSHOW;
665 printk(KERN_INFO
666 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
667 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
668 logo_shown = FBCON_LOGO_DRAW;
669 vc->vc_top = logo_lines;
670 }
671}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700672#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800675static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677 struct fbcon_ops *ops = info->fbcon_par;
678
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800679 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800682 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800683 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800684 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700688
689static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
690{
691 int err = 0;
692
693 if (info->flags & FBINFO_MISC_TILEBLITTING &&
694 info->tileops->fb_get_tilemax(info) < charcount)
695 err = 1;
696
697 return err;
698}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800700static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
702 struct fbcon_ops *ops = info->fbcon_par;
703
704 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800705 ops->p = &fb_display[vc->vc_num];
706 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 fbcon_set_bitops(ops);
708}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700709
710static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
711{
712 return 0;
713}
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#endif /* CONFIG_MISC_TILEBLITTING */
716
717
718static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
719 int unit, int oldidx)
720{
721 struct fbcon_ops *ops = NULL;
722 int err = 0;
723
724 if (!try_module_get(info->fbops->owner))
725 err = -ENODEV;
726
727 if (!err && info->fbops->fb_open &&
728 info->fbops->fb_open(info, 0))
729 err = -ENODEV;
730
731 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800732 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (!ops)
734 err = -ENOMEM;
735 }
736
737 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 info->fbcon_par = ops;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800739 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741
742 if (err) {
743 con2fb_map[unit] = oldidx;
744 module_put(info->fbops->owner);
745 }
746
747 return err;
748}
749
750static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
751 struct fb_info *newinfo, int unit,
752 int oldidx, int found)
753{
754 struct fbcon_ops *ops = oldinfo->fbcon_par;
755 int err = 0;
756
757 if (oldinfo->fbops->fb_release &&
758 oldinfo->fbops->fb_release(oldinfo, 0)) {
759 con2fb_map[unit] = oldidx;
760 if (!found && newinfo->fbops->fb_release)
761 newinfo->fbops->fb_release(newinfo, 0);
762 if (!found)
763 module_put(newinfo->fbops->owner);
764 err = -ENODEV;
765 }
766
767 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700768 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 kfree(ops->cursor_state.mask);
770 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800771 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 kfree(oldinfo->fbcon_par);
773 oldinfo->fbcon_par = NULL;
774 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800775 /*
776 If oldinfo and newinfo are driving the same hardware,
777 the fb_release() method of oldinfo may attempt to
778 restore the hardware state. This will leave the
779 newinfo in an undefined state. Thus, a call to
780 fb_set_par() may be needed for the newinfo.
781 */
782 if (newinfo->fbops->fb_set_par)
783 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
785
786 return err;
787}
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
790 int unit, int show_logo)
791{
792 struct fbcon_ops *ops = info->fbcon_par;
793
794 ops->currcon = fg_console;
795
796 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
797 info->fbops->fb_set_par(info);
798
799 ops->flags |= FBCON_FLAGS_INIT;
800 ops->graphics = 0;
801
802 if (vc)
803 fbcon_set_disp(info, &info->var, vc);
804 else
805 fbcon_preset_disp(info, &info->var, unit);
806
807 if (show_logo) {
808 struct vc_data *fg_vc = vc_cons[fg_console].d;
809 struct fb_info *fg_info =
810 registered_fb[con2fb_map[fg_console]];
811
812 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
813 fg_vc->vc_rows, fg_vc->vc_cols,
814 fg_vc->vc_rows);
815 }
816
817 update_screen(vc_cons[fg_console].d);
818}
819
820/**
821 * set_con2fb_map - map console to frame buffer device
822 * @unit: virtual console number to map
823 * @newidx: frame buffer index to map virtual console to
824 * @user: user request
825 *
826 * Maps a virtual console @unit to a frame buffer device
827 * @newidx.
828 */
829static int set_con2fb_map(int unit, int newidx, int user)
830{
831 struct vc_data *vc = vc_cons[unit].d;
832 int oldidx = con2fb_map[unit];
833 struct fb_info *info = registered_fb[newidx];
834 struct fb_info *oldinfo = NULL;
835 int found, err = 0;
836
837 if (oldidx == newidx)
838 return 0;
839
Antonino A. Daplase614b182006-06-26 00:27:09 -0700840 if (!info || fbcon_has_exited)
841 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 if (!err && !search_for_mapped_con()) {
844 info_idx = newidx;
845 return fbcon_takeover(0);
846 }
847
848 if (oldidx != -1)
849 oldinfo = registered_fb[oldidx];
850
851 found = search_fb_in_map(newidx);
852
853 acquire_console_sem();
854 con2fb_map[unit] = newidx;
855 if (!err && !found)
856 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
857
858
859 /*
860 * If old fb is not mapped to any of the consoles,
861 * fbcon should release it.
862 */
863 if (!err && oldinfo && !search_fb_in_map(oldidx))
864 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
865 found);
866
867 if (!err) {
868 int show_logo = (fg_console == 0 && !user &&
869 logo_shown != FBCON_LOGO_DONTSHOW);
870
871 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700872 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 con2fb_map_boot[unit] = newidx;
874 con2fb_init_display(vc, info, unit, show_logo);
875 }
876
Antonino A. Daplase614b182006-06-26 00:27:09 -0700877 if (!search_fb_in_map(info_idx))
878 info_idx = newidx;
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 release_console_sem();
881 return err;
882}
883
884/*
885 * Low Level Operations
886 */
887/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
888static int var_to_display(struct display *disp,
889 struct fb_var_screeninfo *var,
890 struct fb_info *info)
891{
892 disp->xres_virtual = var->xres_virtual;
893 disp->yres_virtual = var->yres_virtual;
894 disp->bits_per_pixel = var->bits_per_pixel;
895 disp->grayscale = var->grayscale;
896 disp->nonstd = var->nonstd;
897 disp->accel_flags = var->accel_flags;
898 disp->height = var->height;
899 disp->width = var->width;
900 disp->red = var->red;
901 disp->green = var->green;
902 disp->blue = var->blue;
903 disp->transp = var->transp;
904 disp->rotate = var->rotate;
905 disp->mode = fb_match_mode(var, &info->modelist);
906 if (disp->mode == NULL)
907 /* This should not happen */
908 return -EINVAL;
909 return 0;
910}
911
912static void display_to_var(struct fb_var_screeninfo *var,
913 struct display *disp)
914{
915 fb_videomode_to_var(var, disp->mode);
916 var->xres_virtual = disp->xres_virtual;
917 var->yres_virtual = disp->yres_virtual;
918 var->bits_per_pixel = disp->bits_per_pixel;
919 var->grayscale = disp->grayscale;
920 var->nonstd = disp->nonstd;
921 var->accel_flags = disp->accel_flags;
922 var->height = disp->height;
923 var->width = disp->width;
924 var->red = disp->red;
925 var->green = disp->green;
926 var->blue = disp->blue;
927 var->transp = disp->transp;
928 var->rotate = disp->rotate;
929}
930
931static const char *fbcon_startup(void)
932{
933 const char *display_desc = "frame buffer device";
934 struct display *p = &fb_display[fg_console];
935 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700936 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 struct module *owner;
938 struct fb_info *info = NULL;
939 struct fbcon_ops *ops;
940 int rows, cols;
941 int irqres;
942
943 irqres = 1;
944 /*
945 * If num_registered_fb is zero, this is a call for the dummy part.
946 * The frame buffer devices weren't initialized yet.
947 */
948 if (!num_registered_fb || info_idx == -1)
949 return display_desc;
950 /*
951 * Instead of blindly using registered_fb[0], we use info_idx, set by
952 * fb_console_init();
953 */
954 info = registered_fb[info_idx];
955 if (!info)
956 return NULL;
957
958 owner = info->fbops->owner;
959 if (!try_module_get(owner))
960 return NULL;
961 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
962 module_put(owner);
963 return NULL;
964 }
965
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800966 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (!ops) {
968 module_put(owner);
969 return NULL;
970 }
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 ops->currcon = -1;
973 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800974 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800976 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800977 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 if (info->fix.type != FB_TYPE_TEXT) {
980 if (fbcon_softback_size) {
981 if (!softback_buf) {
982 softback_buf =
983 (unsigned long)
984 kmalloc(fbcon_softback_size,
985 GFP_KERNEL);
986 if (!softback_buf) {
987 fbcon_softback_size = 0;
988 softback_top = 0;
989 }
990 }
991 } else {
992 if (softback_buf) {
993 kfree((void *) softback_buf);
994 softback_buf = 0;
995 softback_top = 0;
996 }
997 }
998 if (softback_buf)
999 softback_in = softback_top = softback_curr =
1000 softback_buf;
1001 softback_lines = 0;
1002 }
1003
1004 /* Setup default font */
1005 if (!p->fontdata) {
1006 if (!fontname[0] || !(font = find_font(fontname)))
1007 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001008 info->var.yres,
1009 info->pixmap.blit_x,
1010 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 vc->vc_font.width = font->width;
1012 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001013 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1015 }
1016
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001017 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1018 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1019 cols /= vc->vc_font.width;
1020 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 vc_resize(vc, cols, rows);
1022
1023 DPRINTK("mode: %s\n", info->fix.id);
1024 DPRINTK("visual: %d\n", info->fix.visual);
1025 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1026 info->var.yres,
1027 info->var.bits_per_pixel);
1028
1029#ifdef CONFIG_ATARI
1030 if (MACH_IS_ATARI) {
1031 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1032 irqres =
1033 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1034 IRQ_TYPE_PRIO, "framebuffer vbl",
1035 info);
1036 }
1037#endif /* CONFIG_ATARI */
1038
1039#ifdef CONFIG_MAC
1040 /*
1041 * On a Macintoy, the VBL interrupt may or may not be active.
1042 * As interrupt based cursor is more reliable and race free, we
1043 * probe for VBL interrupts.
1044 */
1045 if (MACH_IS_MAC) {
1046 int ct = 0;
1047 /*
1048 * Probe for VBL: set temp. handler ...
1049 */
1050 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1051 "framebuffer vbl", info);
1052 vbl_detected = 0;
1053
1054 /*
1055 * ... and spin for 20 ms ...
1056 */
1057 while (!vbl_detected && ++ct < 1000)
1058 udelay(20);
1059
1060 if (ct == 1000)
1061 printk
1062 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1063
1064 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1065
1066 if (vbl_detected) {
1067 /*
1068 * interrupt based cursor ok
1069 */
1070 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1071 irqres =
1072 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1073 "framebuffer vbl", info);
1074 } else {
1075 /*
1076 * VBL not detected: fall through, use timer based cursor
1077 */
1078 irqres = 1;
1079 }
1080 }
1081#endif /* CONFIG_MAC */
1082
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001083 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001084 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return display_desc;
1086}
1087
1088static void fbcon_init(struct vc_data *vc, int init)
1089{
1090 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1091 struct fbcon_ops *ops;
1092 struct vc_data **default_mode = vc->vc_display_fg;
1093 struct vc_data *svc = *default_mode;
1094 struct display *t, *p = &fb_display[vc->vc_num];
1095 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001096 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 if (info_idx == -1 || info == NULL)
1099 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001100
1101 cap = info->flags;
1102
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1104 (info->fix.type == FB_TYPE_TEXT))
1105 logo = 0;
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (var_to_display(p, &info->var, info))
1108 return;
1109
1110 /* If we are not the first console on this
1111 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001112 t = &fb_display[fg_console];
1113 if (!p->fontdata) {
1114 if (t->fontdata) {
1115 struct vc_data *fvc = vc_cons[fg_console].d;
1116
1117 vc->vc_font.data = (void *)(p->fontdata =
1118 fvc->vc_font.data);
1119 vc->vc_font.width = fvc->vc_font.width;
1120 vc->vc_font.height = fvc->vc_font.height;
1121 p->userfont = t->userfont;
1122
1123 if (p->userfont)
1124 REFCOUNT(p->fontdata)++;
1125 } else {
1126 const struct font_desc *font = NULL;
1127
1128 if (!fontname[0] || !(font = find_font(fontname)))
1129 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001130 info->var.yres,
1131 info->pixmap.blit_x,
1132 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001133 vc->vc_font.width = font->width;
1134 vc->vc_font.height = font->height;
1135 vc->vc_font.data = (void *)(p->fontdata = font->data);
1136 vc->vc_font.charcount = 256; /* FIXME Need to
1137 support more fonts */
1138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 if (p->userfont)
1142 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001143
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001144 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1146 if (charcnt == 256) {
1147 vc->vc_hi_font_mask = 0;
1148 } else {
1149 vc->vc_hi_font_mask = 0x100;
1150 if (vc->vc_can_do_color)
1151 vc->vc_complement_mask <<= 1;
1152 }
1153
1154 if (!*svc->vc_uni_pagedir_loc)
1155 con_set_default_unimap(svc);
1156 if (!*vc->vc_uni_pagedir_loc)
1157 con_copy_unimap(vc, svc);
1158
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001159 ops = info->fbcon_par;
1160 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001161 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 cols = vc->vc_cols;
1164 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001165 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1166 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1167 new_cols /= vc->vc_font.width;
1168 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 vc_resize(vc, new_cols, new_rows);
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /*
1172 * We must always set the mode. The mode of the previous console
1173 * driver could be in the same resolution but we are using different
1174 * hardware so we have to initialize the hardware.
1175 *
1176 * We need to do it in fbcon_init() to prevent screen corruption.
1177 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001178 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (info->fbops->fb_set_par &&
1180 !(ops->flags & FBCON_FLAGS_INIT))
1181 info->fbops->fb_set_par(info);
1182 ops->flags |= FBCON_FLAGS_INIT;
1183 }
1184
1185 ops->graphics = 0;
1186
1187 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1188 !(cap & FBINFO_HWACCEL_DISABLED))
1189 p->scrollmode = SCROLL_MOVE;
1190 else /* default to something safe */
1191 p->scrollmode = SCROLL_REDRAW;
1192
1193 /*
1194 * ++guenther: console.c:vc_allocate() relies on initializing
1195 * vc_{cols,rows}, but we must not set those if we are only
1196 * resizing the console.
1197 */
1198 if (!init) {
1199 vc->vc_cols = new_cols;
1200 vc->vc_rows = new_rows;
1201 }
1202
1203 if (logo)
1204 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1205
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001206 if (vc == svc && softback_buf)
1207 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001208
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001209 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001210 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001211 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001212 }
1213
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001214 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Antonino A. Daplase614b182006-06-26 00:27:09 -07001217static void fbcon_free_font(struct display *p)
1218{
1219 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1220 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1221 p->fontdata = NULL;
1222 p->userfont = 0;
1223}
1224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225static void fbcon_deinit(struct vc_data *vc)
1226{
1227 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001228 struct fb_info *info;
1229 struct fbcon_ops *ops;
1230 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001233 idx = con2fb_map[vc->vc_num];
1234
1235 if (idx == -1)
1236 goto finished;
1237
1238 info = registered_fb[idx];
1239
1240 if (!info)
1241 goto finished;
1242
1243 ops = info->fbcon_par;
1244
1245 if (!ops)
1246 goto finished;
1247
1248 if (CON_IS_VISIBLE(vc))
1249 fbcon_del_cursor_timer(info);
1250
1251 ops->flags &= ~FBCON_FLAGS_INIT;
1252finished:
1253
1254 if (!con_is_bound(&fb_con))
1255 fbcon_exit();
1256
1257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
1260/* ====================================================================== */
1261
1262/* fbcon_XXX routines - interface used by the world
1263 *
1264 * This system is now divided into two levels because of complications
1265 * caused by hardware scrolling. Top level functions:
1266 *
1267 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1268 *
1269 * handles y values in range [0, scr_height-1] that correspond to real
1270 * screen positions. y_wrap shift means that first line of bitmap may be
1271 * anywhere on this display. These functions convert lineoffsets to
1272 * bitmap offsets and deal with the wrap-around case by splitting blits.
1273 *
1274 * fbcon_bmove_physical_8() -- These functions fast implementations
1275 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1276 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1277 *
1278 * WARNING:
1279 *
1280 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1281 * Implies should only really hardware scroll in rows. Only reason for
1282 * restriction is simplicity & efficiency at the moment.
1283 */
1284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1286 int width)
1287{
1288 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1289 struct fbcon_ops *ops = info->fbcon_par;
1290
1291 struct display *p = &fb_display[vc->vc_num];
1292 u_int y_break;
1293
1294 if (fbcon_is_inactive(vc, info))
1295 return;
1296
1297 if (!height || !width)
1298 return;
1299
1300 /* Split blits that cross physical y_wrap boundary */
1301
1302 y_break = p->vrows - p->yscroll;
1303 if (sy < y_break && sy + height - 1 >= y_break) {
1304 u_int b = y_break - sy;
1305 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1306 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1307 width);
1308 } else
1309 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1310}
1311
1312static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1313 int count, int ypos, int xpos)
1314{
1315 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1316 struct display *p = &fb_display[vc->vc_num];
1317 struct fbcon_ops *ops = info->fbcon_par;
1318
1319 if (!fbcon_is_inactive(vc, info))
1320 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1321 get_color(vc, info, scr_readw(s), 1),
1322 get_color(vc, info, scr_readw(s), 0));
1323}
1324
1325static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1326{
1327 unsigned short chr;
1328
1329 scr_writew(c, &chr);
1330 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1331}
1332
1333static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1334{
1335 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1336 struct fbcon_ops *ops = info->fbcon_par;
1337
1338 if (!fbcon_is_inactive(vc, info))
1339 ops->clear_margins(vc, info, bottom_only);
1340}
1341
1342static void fbcon_cursor(struct vc_data *vc, int mode)
1343{
1344 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1345 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 int y;
1347 int c = scr_readw((u16 *) vc->vc_pos);
1348
Michal Januszewskid1e23062007-05-08 00:38:07 -07001349 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 return;
1351
1352 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1353 if (mode & CM_SOFTBACK) {
1354 mode &= ~CM_SOFTBACK;
1355 y = softback_lines;
1356 } else {
1357 if (softback_lines)
1358 fbcon_set_origin(vc);
1359 y = 0;
1360 }
1361
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001362 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 get_color(vc, info, c, 0));
1364 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1365}
1366
1367static int scrollback_phys_max = 0;
1368static int scrollback_max = 0;
1369static int scrollback_current = 0;
1370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371/*
1372 * If no vc is existent yet, just set struct display
1373 */
1374static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1375 int unit)
1376{
1377 struct display *p = &fb_display[unit];
1378 struct display *t = &fb_display[fg_console];
1379
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (var_to_display(p, var, info))
1381 return;
1382
1383 p->fontdata = t->fontdata;
1384 p->userfont = t->userfont;
1385 if (p->userfont)
1386 REFCOUNT(p->fontdata)++;
1387}
1388
1389static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1390 struct vc_data *vc)
1391{
1392 struct display *p = &fb_display[vc->vc_num], *t;
1393 struct vc_data **default_mode = vc->vc_display_fg;
1394 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001395 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 int rows, cols, charcnt = 256;
1397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 if (var_to_display(p, var, info))
1399 return;
1400 t = &fb_display[svc->vc_num];
1401 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001402 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 vc->vc_font.width = (*default_mode)->vc_font.width;
1404 vc->vc_font.height = (*default_mode)->vc_font.height;
1405 p->userfont = t->userfont;
1406 if (p->userfont)
1407 REFCOUNT(p->fontdata)++;
1408 }
1409 if (p->userfont)
1410 charcnt = FNTCHARCNT(p->fontdata);
1411
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001412 var->activate = FB_ACTIVATE_NOW;
1413 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001414 var->yoffset = info->var.yoffset;
1415 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001416 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001417 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001418 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1420 if (charcnt == 256) {
1421 vc->vc_hi_font_mask = 0;
1422 } else {
1423 vc->vc_hi_font_mask = 0x100;
1424 if (vc->vc_can_do_color)
1425 vc->vc_complement_mask <<= 1;
1426 }
1427
1428 if (!*svc->vc_uni_pagedir_loc)
1429 con_set_default_unimap(svc);
1430 if (!*vc->vc_uni_pagedir_loc)
1431 con_copy_unimap(vc, svc);
1432
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001433 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1434 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1435 cols /= vc->vc_font.width;
1436 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (CON_IS_VISIBLE(vc)) {
1440 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001441 if (softback_buf)
1442 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444}
1445
1446static __inline__ void ywrap_up(struct vc_data *vc, int count)
1447{
1448 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001449 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 struct display *p = &fb_display[vc->vc_num];
1451
1452 p->yscroll += count;
1453 if (p->yscroll >= p->vrows) /* Deal with wrap */
1454 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001455 ops->var.xoffset = 0;
1456 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1457 ops->var.vmode |= FB_VMODE_YWRAP;
1458 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 scrollback_max += count;
1460 if (scrollback_max > scrollback_phys_max)
1461 scrollback_max = scrollback_phys_max;
1462 scrollback_current = 0;
1463}
1464
1465static __inline__ void ywrap_down(struct vc_data *vc, int count)
1466{
1467 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001468 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 struct display *p = &fb_display[vc->vc_num];
1470
1471 p->yscroll -= count;
1472 if (p->yscroll < 0) /* Deal with wrap */
1473 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001474 ops->var.xoffset = 0;
1475 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1476 ops->var.vmode |= FB_VMODE_YWRAP;
1477 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 scrollback_max -= count;
1479 if (scrollback_max < 0)
1480 scrollback_max = 0;
1481 scrollback_current = 0;
1482}
1483
1484static __inline__ void ypan_up(struct vc_data *vc, int count)
1485{
1486 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1487 struct display *p = &fb_display[vc->vc_num];
1488 struct fbcon_ops *ops = info->fbcon_par;
1489
1490 p->yscroll += count;
1491 if (p->yscroll > p->vrows - vc->vc_rows) {
1492 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1493 0, 0, 0, vc->vc_rows, vc->vc_cols);
1494 p->yscroll -= p->vrows - vc->vc_rows;
1495 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001496
1497 ops->var.xoffset = 0;
1498 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1499 ops->var.vmode &= ~FB_VMODE_YWRAP;
1500 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 fbcon_clear_margins(vc, 1);
1502 scrollback_max += count;
1503 if (scrollback_max > scrollback_phys_max)
1504 scrollback_max = scrollback_phys_max;
1505 scrollback_current = 0;
1506}
1507
1508static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1509{
1510 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001511 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 if (p->yscroll > p->vrows - vc->vc_rows) {
1517 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001519 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001520
1521 ops->var.xoffset = 0;
1522 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1523 ops->var.vmode &= ~FB_VMODE_YWRAP;
1524 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 fbcon_clear_margins(vc, 1);
1526 scrollback_max += count;
1527 if (scrollback_max > scrollback_phys_max)
1528 scrollback_max = scrollback_phys_max;
1529 scrollback_current = 0;
1530}
1531
1532static __inline__ void ypan_down(struct vc_data *vc, int count)
1533{
1534 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1535 struct display *p = &fb_display[vc->vc_num];
1536 struct fbcon_ops *ops = info->fbcon_par;
1537
1538 p->yscroll -= count;
1539 if (p->yscroll < 0) {
1540 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1541 0, vc->vc_rows, vc->vc_cols);
1542 p->yscroll += p->vrows - vc->vc_rows;
1543 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001544
1545 ops->var.xoffset = 0;
1546 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1547 ops->var.vmode &= ~FB_VMODE_YWRAP;
1548 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 fbcon_clear_margins(vc, 1);
1550 scrollback_max -= count;
1551 if (scrollback_max < 0)
1552 scrollback_max = 0;
1553 scrollback_current = 0;
1554}
1555
1556static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1557{
1558 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001559 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001563
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 if (p->yscroll < 0) {
1565 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001567 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001568
1569 ops->var.xoffset = 0;
1570 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1571 ops->var.vmode &= ~FB_VMODE_YWRAP;
1572 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 fbcon_clear_margins(vc, 1);
1574 scrollback_max -= count;
1575 if (scrollback_max < 0)
1576 scrollback_max = 0;
1577 scrollback_current = 0;
1578}
1579
1580static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1581 long delta)
1582{
1583 int count = vc->vc_rows;
1584 unsigned short *d, *s;
1585 unsigned long n;
1586 int line = 0;
1587
1588 d = (u16 *) softback_curr;
1589 if (d == (u16 *) softback_in)
1590 d = (u16 *) vc->vc_origin;
1591 n = softback_curr + delta * vc->vc_size_row;
1592 softback_lines -= delta;
1593 if (delta < 0) {
1594 if (softback_curr < softback_top && n < softback_buf) {
1595 n += softback_end - softback_buf;
1596 if (n < softback_top) {
1597 softback_lines -=
1598 (softback_top - n) / vc->vc_size_row;
1599 n = softback_top;
1600 }
1601 } else if (softback_curr >= softback_top
1602 && n < softback_top) {
1603 softback_lines -=
1604 (softback_top - n) / vc->vc_size_row;
1605 n = softback_top;
1606 }
1607 } else {
1608 if (softback_curr > softback_in && n >= softback_end) {
1609 n += softback_buf - softback_end;
1610 if (n > softback_in) {
1611 n = softback_in;
1612 softback_lines = 0;
1613 }
1614 } else if (softback_curr <= softback_in && n > softback_in) {
1615 n = softback_in;
1616 softback_lines = 0;
1617 }
1618 }
1619 if (n == softback_curr)
1620 return;
1621 softback_curr = n;
1622 s = (u16 *) softback_curr;
1623 if (s == (u16 *) softback_in)
1624 s = (u16 *) vc->vc_origin;
1625 while (count--) {
1626 unsigned short *start;
1627 unsigned short *le;
1628 unsigned short c;
1629 int x = 0;
1630 unsigned short attr = 1;
1631
1632 start = s;
1633 le = advance_row(s, 1);
1634 do {
1635 c = scr_readw(s);
1636 if (attr != (c & 0xff00)) {
1637 attr = c & 0xff00;
1638 if (s > start) {
1639 fbcon_putcs(vc, start, s - start,
1640 line, x);
1641 x += s - start;
1642 start = s;
1643 }
1644 }
1645 if (c == scr_readw(d)) {
1646 if (s > start) {
1647 fbcon_putcs(vc, start, s - start,
1648 line, x);
1649 x += s - start + 1;
1650 start = s + 1;
1651 } else {
1652 x++;
1653 start++;
1654 }
1655 }
1656 s++;
1657 d++;
1658 } while (s < le);
1659 if (s > start)
1660 fbcon_putcs(vc, start, s - start, line, x);
1661 line++;
1662 if (d == (u16 *) softback_end)
1663 d = (u16 *) softback_buf;
1664 if (d == (u16 *) softback_in)
1665 d = (u16 *) vc->vc_origin;
1666 if (s == (u16 *) softback_end)
1667 s = (u16 *) softback_buf;
1668 if (s == (u16 *) softback_in)
1669 s = (u16 *) vc->vc_origin;
1670 }
1671}
1672
1673static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1674 int line, int count, int dy)
1675{
1676 unsigned short *s = (unsigned short *)
1677 (vc->vc_origin + vc->vc_size_row * line);
1678
1679 while (count--) {
1680 unsigned short *start = s;
1681 unsigned short *le = advance_row(s, 1);
1682 unsigned short c;
1683 int x = 0;
1684 unsigned short attr = 1;
1685
1686 do {
1687 c = scr_readw(s);
1688 if (attr != (c & 0xff00)) {
1689 attr = c & 0xff00;
1690 if (s > start) {
1691 fbcon_putcs(vc, start, s - start,
1692 dy, x);
1693 x += s - start;
1694 start = s;
1695 }
1696 }
1697 console_conditional_schedule();
1698 s++;
1699 } while (s < le);
1700 if (s > start)
1701 fbcon_putcs(vc, start, s - start, dy, x);
1702 console_conditional_schedule();
1703 dy++;
1704 }
1705}
1706
1707static 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];
1792 struct fbcon_ops *ops = info->fbcon_par;
1793 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1794
1795 if (fbcon_is_inactive(vc, info))
1796 return -EINVAL;
1797
1798 fbcon_cursor(vc, CM_ERASE);
1799
1800 /*
1801 * ++Geert: Only use ywrap/ypan if the console is in text mode
1802 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1803 * whole screen (prevents flicker).
1804 */
1805
1806 switch (dir) {
1807 case SM_UP:
1808 if (count > vc->vc_rows) /* Maximum realistic size */
1809 count = vc->vc_rows;
1810 if (softback_top)
1811 fbcon_softback_note(vc, t, count);
1812 if (logo_shown >= 0)
1813 goto redraw_up;
1814 switch (p->scrollmode) {
1815 case SCROLL_MOVE:
1816 ops->bmove(vc, info, t + count, 0, t, 0,
1817 b - t - count, vc->vc_cols);
1818 ops->clear(vc, info, b - count, 0, count,
1819 vc->vc_cols);
1820 break;
1821
1822 case SCROLL_WRAP_MOVE:
1823 if (b - t - count > 3 * vc->vc_rows >> 2) {
1824 if (t > 0)
1825 fbcon_bmove(vc, 0, 0, count, 0, t,
1826 vc->vc_cols);
1827 ywrap_up(vc, count);
1828 if (vc->vc_rows - b > 0)
1829 fbcon_bmove(vc, b - count, 0, b, 0,
1830 vc->vc_rows - b,
1831 vc->vc_cols);
1832 } else if (info->flags & FBINFO_READS_FAST)
1833 fbcon_bmove(vc, t + count, 0, t, 0,
1834 b - t - count, vc->vc_cols);
1835 else
1836 goto redraw_up;
1837 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1838 break;
1839
1840 case SCROLL_PAN_REDRAW:
1841 if ((p->yscroll + count <=
1842 2 * (p->vrows - vc->vc_rows))
1843 && ((!scroll_partial && (b - t == vc->vc_rows))
1844 || (scroll_partial
1845 && (b - t - count >
1846 3 * vc->vc_rows >> 2)))) {
1847 if (t > 0)
1848 fbcon_redraw_move(vc, p, 0, t, count);
1849 ypan_up_redraw(vc, t, count);
1850 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001851 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 vc->vc_rows - b, b);
1853 } else
1854 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1855 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1856 break;
1857
1858 case SCROLL_PAN_MOVE:
1859 if ((p->yscroll + count <=
1860 2 * (p->vrows - vc->vc_rows))
1861 && ((!scroll_partial && (b - t == vc->vc_rows))
1862 || (scroll_partial
1863 && (b - t - count >
1864 3 * vc->vc_rows >> 2)))) {
1865 if (t > 0)
1866 fbcon_bmove(vc, 0, 0, count, 0, t,
1867 vc->vc_cols);
1868 ypan_up(vc, count);
1869 if (vc->vc_rows - b > 0)
1870 fbcon_bmove(vc, b - count, 0, b, 0,
1871 vc->vc_rows - b,
1872 vc->vc_cols);
1873 } else if (info->flags & FBINFO_READS_FAST)
1874 fbcon_bmove(vc, t + count, 0, t, 0,
1875 b - t - count, vc->vc_cols);
1876 else
1877 goto redraw_up;
1878 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1879 break;
1880
1881 case SCROLL_REDRAW:
1882 redraw_up:
1883 fbcon_redraw(vc, p, t, b - t - count,
1884 count * vc->vc_cols);
1885 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1886 scr_memsetw((unsigned short *) (vc->vc_origin +
1887 vc->vc_size_row *
1888 (b - count)),
1889 vc->vc_video_erase_char,
1890 vc->vc_size_row * count);
1891 return 1;
1892 }
1893 break;
1894
1895 case SM_DOWN:
1896 if (count > vc->vc_rows) /* Maximum realistic size */
1897 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001898 if (logo_shown >= 0)
1899 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 switch (p->scrollmode) {
1901 case SCROLL_MOVE:
1902 ops->bmove(vc, info, t, 0, t + count, 0,
1903 b - t - count, vc->vc_cols);
1904 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1905 break;
1906
1907 case SCROLL_WRAP_MOVE:
1908 if (b - t - count > 3 * vc->vc_rows >> 2) {
1909 if (vc->vc_rows - b > 0)
1910 fbcon_bmove(vc, b, 0, b - count, 0,
1911 vc->vc_rows - b,
1912 vc->vc_cols);
1913 ywrap_down(vc, count);
1914 if (t > 0)
1915 fbcon_bmove(vc, count, 0, 0, 0, t,
1916 vc->vc_cols);
1917 } else if (info->flags & FBINFO_READS_FAST)
1918 fbcon_bmove(vc, t, 0, t + count, 0,
1919 b - t - count, vc->vc_cols);
1920 else
1921 goto redraw_down;
1922 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1923 break;
1924
1925 case SCROLL_PAN_MOVE:
1926 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1927 && ((!scroll_partial && (b - t == vc->vc_rows))
1928 || (scroll_partial
1929 && (b - t - count >
1930 3 * vc->vc_rows >> 2)))) {
1931 if (vc->vc_rows - b > 0)
1932 fbcon_bmove(vc, b, 0, b - count, 0,
1933 vc->vc_rows - b,
1934 vc->vc_cols);
1935 ypan_down(vc, count);
1936 if (t > 0)
1937 fbcon_bmove(vc, count, 0, 0, 0, t,
1938 vc->vc_cols);
1939 } else if (info->flags & FBINFO_READS_FAST)
1940 fbcon_bmove(vc, t, 0, t + count, 0,
1941 b - t - count, vc->vc_cols);
1942 else
1943 goto redraw_down;
1944 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1945 break;
1946
1947 case SCROLL_PAN_REDRAW:
1948 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1949 && ((!scroll_partial && (b - t == vc->vc_rows))
1950 || (scroll_partial
1951 && (b - t - count >
1952 3 * vc->vc_rows >> 2)))) {
1953 if (vc->vc_rows - b > 0)
1954 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1955 b - count);
1956 ypan_down_redraw(vc, t, count);
1957 if (t > 0)
1958 fbcon_redraw_move(vc, p, count, t, 0);
1959 } else
1960 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1961 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1962 break;
1963
1964 case SCROLL_REDRAW:
1965 redraw_down:
1966 fbcon_redraw(vc, p, b - 1, b - t - count,
1967 -count * vc->vc_cols);
1968 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1969 scr_memsetw((unsigned short *) (vc->vc_origin +
1970 vc->vc_size_row *
1971 t),
1972 vc->vc_video_erase_char,
1973 vc->vc_size_row * count);
1974 return 1;
1975 }
1976 }
1977 return 0;
1978}
1979
1980
1981static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1982 int height, int width)
1983{
1984 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1985 struct display *p = &fb_display[vc->vc_num];
1986
1987 if (fbcon_is_inactive(vc, info))
1988 return;
1989
1990 if (!width || !height)
1991 return;
1992
1993 /* Split blits that cross physical y_wrap case.
1994 * Pathological case involves 4 blits, better to use recursive
1995 * code rather than unrolled case
1996 *
1997 * Recursive invocations don't need to erase the cursor over and
1998 * over again, so we use fbcon_bmove_rec()
1999 */
2000 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2001 p->vrows - p->yscroll);
2002}
2003
2004static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2005 int dy, int dx, int height, int width, u_int y_break)
2006{
2007 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2008 struct fbcon_ops *ops = info->fbcon_par;
2009 u_int b;
2010
2011 if (sy < y_break && sy + height > y_break) {
2012 b = y_break - sy;
2013 if (dy < sy) { /* Avoid trashing self */
2014 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2015 y_break);
2016 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2017 height - b, width, y_break);
2018 } else {
2019 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2020 height - b, width, y_break);
2021 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2022 y_break);
2023 }
2024 return;
2025 }
2026
2027 if (dy < y_break && dy + height > y_break) {
2028 b = y_break - dy;
2029 if (dy < sy) { /* Avoid trashing self */
2030 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2031 y_break);
2032 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2033 height - b, width, y_break);
2034 } else {
2035 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2036 height - b, width, y_break);
2037 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2038 y_break);
2039 }
2040 return;
2041 }
2042 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2043 height, width);
2044}
2045
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002046static __inline__ void updatescrollmode(struct display *p,
2047 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 struct vc_data *vc)
2049{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002050 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 int fh = vc->vc_font.height;
2052 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002053 u16 t = 0;
2054 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2055 info->fix.xpanstep);
2056 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2057 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2058 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2059 info->var.xres_virtual);
2060 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2061 divides(ypan, vc->vc_font.height) && vyres > yres;
2062 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2063 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002064 divides(vc->vc_font.height, vyres) &&
2065 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002067 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2068 !(cap & FBINFO_HWACCEL_DISABLED);
2069 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2070 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002072 p->vrows = vyres/fh;
2073 if (yres > (fh * (vc->vc_rows + 1)))
2074 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2075 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 p->vrows--;
2077
2078 if (good_wrap || good_pan) {
2079 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002080 p->scrollmode = good_wrap ?
2081 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 else
2083 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2084 SCROLL_PAN_REDRAW;
2085 } else {
2086 if (reading_fast || (fast_copyarea && !fast_imageblit))
2087 p->scrollmode = SCROLL_MOVE;
2088 else
2089 p->scrollmode = SCROLL_REDRAW;
2090 }
2091}
2092
2093static int fbcon_resize(struct vc_data *vc, unsigned int width,
2094 unsigned int height)
2095{
2096 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002097 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct display *p = &fb_display[vc->vc_num];
2099 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002100 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002102 virt_w = FBCON_SWAP(ops->rotate, width, height);
2103 virt_h = FBCON_SWAP(ops->rotate, height, width);
2104 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2105 vc->vc_font.height);
2106 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2107 vc->vc_font.width);
2108 var.xres = virt_w * virt_fw;
2109 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 x_diff = info->var.xres - var.xres;
2111 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002112 if (x_diff < 0 || x_diff > virt_fw ||
2113 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002114 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2117 mode = fb_find_best_mode(&var, &info->modelist);
2118 if (mode == NULL)
2119 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002120 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002122
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002123 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
2126 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2127 if (CON_IS_VISIBLE(vc)) {
2128 var.activate = FB_ACTIVATE_NOW |
2129 FB_ACTIVATE_FORCE;
2130 fb_set_var(info, &var);
2131 }
2132 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002133 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 }
2135 updatescrollmode(p, info, vc);
2136 return 0;
2137}
2138
2139static int fbcon_switch(struct vc_data *vc)
2140{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002141 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002142 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct display *p = &fb_display[vc->vc_num];
2144 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002145 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002148 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149
2150 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 if (softback_lines)
2152 fbcon_set_origin(vc);
2153 softback_top = softback_curr = softback_in = softback_buf;
2154 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002155 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 }
2157
2158 if (logo_shown >= 0) {
2159 struct vc_data *conp2 = vc_cons[logo_shown].d;
2160
2161 if (conp2->vc_top == logo_lines
2162 && conp2->vc_bottom == conp2->vc_rows)
2163 conp2->vc_top = 0;
2164 logo_shown = FBCON_LOGO_CANSHOW;
2165 }
2166
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002167 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002168 if (prev_console != -1)
2169 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 /*
2171 * FIXME: If we have multiple fbdev's loaded, we need to
2172 * update all info->currcon. Perhaps, we can place this
2173 * in a centralized structure, but this might break some
2174 * drivers.
2175 *
2176 * info->currcon = vc->vc_num;
2177 */
2178 for (i = 0; i < FB_MAX; i++) {
2179 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002180 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002182 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 }
2184 }
2185 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2186 display_to_var(&var, p);
2187 var.activate = FB_ACTIVATE_NOW;
2188
2189 /*
2190 * make sure we don't unnecessarily trip the memcmp()
2191 * in fb_set_var()
2192 */
2193 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002194 var.yoffset = info->var.yoffset;
2195 var.xoffset = info->var.xoffset;
2196 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002198 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Knut Petersen39942fd2005-12-12 22:17:19 -08002200 if (old_info != NULL && (old_info != info ||
2201 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002202 if (info->fbops->fb_set_par)
2203 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002204
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002205 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002206 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002209 if (fbcon_is_inactive(vc, info) ||
2210 ops->blank_state != FB_BLANK_UNBLANK)
2211 fbcon_del_cursor_timer(info);
2212 else
2213 fbcon_add_cursor_timer(info);
2214
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002215 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002216 ops->cursor_reset = 1;
2217
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002218 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002219 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002220 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002223 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002225
2226 if (p->userfont)
2227 charcnt = FNTCHARCNT(vc->vc_font.data);
2228
2229 if (charcnt > 256)
2230 vc->vc_complement_mask <<= 1;
2231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 updatescrollmode(p, info, vc);
2233
2234 switch (p->scrollmode) {
2235 case SCROLL_WRAP_MOVE:
2236 scrollback_phys_max = p->vrows - vc->vc_rows;
2237 break;
2238 case SCROLL_PAN_MOVE:
2239 case SCROLL_PAN_REDRAW:
2240 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2241 if (scrollback_phys_max < 0)
2242 scrollback_phys_max = 0;
2243 break;
2244 default:
2245 scrollback_phys_max = 0;
2246 break;
2247 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002248
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 scrollback_max = 0;
2250 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002251
2252 if (!fbcon_is_inactive(vc, info)) {
2253 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2254 ops->update_start(info);
2255 }
2256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 fbcon_set_palette(vc, color_table);
2258 fbcon_clear_margins(vc, 0);
2259
2260 if (logo_shown == FBCON_LOGO_DRAW) {
2261
2262 logo_shown = fg_console;
2263 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002264 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 update_region(vc,
2266 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2267 vc->vc_size_row * (vc->vc_bottom -
2268 vc->vc_top) / 2);
2269 return 0;
2270 }
2271 return 1;
2272}
2273
2274static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2275 int blank)
2276{
Richard Purdie994efac2007-02-09 09:46:45 +00002277 struct fb_event event;
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 if (blank) {
2280 unsigned short charmask = vc->vc_hi_font_mask ?
2281 0x1ff : 0xff;
2282 unsigned short oldc;
2283
2284 oldc = vc->vc_video_erase_char;
2285 vc->vc_video_erase_char &= charmask;
2286 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2287 vc->vc_video_erase_char = oldc;
2288 }
Richard Purdie994efac2007-02-09 09:46:45 +00002289
2290
2291 event.info = info;
2292 event.data = &blank;
2293 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2297{
2298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2299 struct fbcon_ops *ops = info->fbcon_par;
2300
2301 if (mode_switch) {
2302 struct fb_var_screeninfo var = info->var;
2303
2304 ops->graphics = 1;
2305
2306 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002307 if (info->fbops->fb_save_state)
2308 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2310 fb_set_var(info, &var);
2311 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002312 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002313 } else if (info->fbops->fb_restore_state)
2314 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 }
2316
2317 if (!fbcon_is_inactive(vc, info)) {
2318 if (ops->blank_state != blank) {
2319 ops->blank_state = blank;
2320 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2321 ops->cursor_flash = (!blank);
2322
2323 if (fb_blank(info, blank))
2324 fbcon_generic_blank(vc, info, blank);
2325 }
2326
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002327 if (!blank)
2328 update_screen(vc);
2329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002331 if (fbcon_is_inactive(vc, info) ||
2332 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002333 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002334 else
2335 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002336
2337 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2341{
2342 u8 *fontdata = vc->vc_font.data;
2343 u8 *data = font->data;
2344 int i, j;
2345
2346 font->width = vc->vc_font.width;
2347 font->height = vc->vc_font.height;
2348 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2349 if (!font->data)
2350 return 0;
2351
2352 if (font->width <= 8) {
2353 j = vc->vc_font.height;
2354 for (i = 0; i < font->charcount; i++) {
2355 memcpy(data, fontdata, j);
2356 memset(data + j, 0, 32 - j);
2357 data += 32;
2358 fontdata += j;
2359 }
2360 } else if (font->width <= 16) {
2361 j = vc->vc_font.height * 2;
2362 for (i = 0; i < font->charcount; i++) {
2363 memcpy(data, fontdata, j);
2364 memset(data + j, 0, 64 - j);
2365 data += 64;
2366 fontdata += j;
2367 }
2368 } else if (font->width <= 24) {
2369 for (i = 0; i < font->charcount; i++) {
2370 for (j = 0; j < vc->vc_font.height; j++) {
2371 *data++ = fontdata[0];
2372 *data++ = fontdata[1];
2373 *data++ = fontdata[2];
2374 fontdata += sizeof(u32);
2375 }
2376 memset(data, 0, 3 * (32 - j));
2377 data += 3 * (32 - j);
2378 }
2379 } else {
2380 j = vc->vc_font.height * 4;
2381 for (i = 0; i < font->charcount; i++) {
2382 memcpy(data, fontdata, j);
2383 memset(data + j, 0, 128 - j);
2384 data += 128;
2385 fontdata += j;
2386 }
2387 }
2388 return 0;
2389}
2390
2391static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002392 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393{
2394 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002395 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 struct display *p = &fb_display[vc->vc_num];
2397 int resize;
2398 int cnt;
2399 char *old_data = NULL;
2400
2401 if (CON_IS_VISIBLE(vc) && softback_lines)
2402 fbcon_set_origin(vc);
2403
2404 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2405 if (p->userfont)
2406 old_data = vc->vc_font.data;
2407 if (userfont)
2408 cnt = FNTCHARCNT(data);
2409 else
2410 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002411 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 if ((p->userfont = userfont))
2413 REFCOUNT(data)++;
2414 vc->vc_font.width = w;
2415 vc->vc_font.height = h;
2416 if (vc->vc_hi_font_mask && cnt == 256) {
2417 vc->vc_hi_font_mask = 0;
2418 if (vc->vc_can_do_color) {
2419 vc->vc_complement_mask >>= 1;
2420 vc->vc_s_complement_mask >>= 1;
2421 }
2422
2423 /* ++Edmund: reorder the attribute bits */
2424 if (vc->vc_can_do_color) {
2425 unsigned short *cp =
2426 (unsigned short *) vc->vc_origin;
2427 int count = vc->vc_screenbuf_size / 2;
2428 unsigned short c;
2429 for (; count > 0; count--, cp++) {
2430 c = scr_readw(cp);
2431 scr_writew(((c & 0xfe00) >> 1) |
2432 (c & 0xff), cp);
2433 }
2434 c = vc->vc_video_erase_char;
2435 vc->vc_video_erase_char =
2436 ((c & 0xfe00) >> 1) | (c & 0xff);
2437 vc->vc_attr >>= 1;
2438 }
2439 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2440 vc->vc_hi_font_mask = 0x100;
2441 if (vc->vc_can_do_color) {
2442 vc->vc_complement_mask <<= 1;
2443 vc->vc_s_complement_mask <<= 1;
2444 }
2445
2446 /* ++Edmund: reorder the attribute bits */
2447 {
2448 unsigned short *cp =
2449 (unsigned short *) vc->vc_origin;
2450 int count = vc->vc_screenbuf_size / 2;
2451 unsigned short c;
2452 for (; count > 0; count--, cp++) {
2453 unsigned short newc;
2454 c = scr_readw(cp);
2455 if (vc->vc_can_do_color)
2456 newc =
2457 ((c & 0xff00) << 1) | (c &
2458 0xff);
2459 else
2460 newc = c & ~0x100;
2461 scr_writew(newc, cp);
2462 }
2463 c = vc->vc_video_erase_char;
2464 if (vc->vc_can_do_color) {
2465 vc->vc_video_erase_char =
2466 ((c & 0xff00) << 1) | (c & 0xff);
2467 vc->vc_attr <<= 1;
2468 } else
2469 vc->vc_video_erase_char = c & ~0x100;
2470 }
2471
2472 }
2473
2474 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002475 int cols, rows;
2476
2477 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2478 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2479 cols /= w;
2480 rows /= h;
2481 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002482 if (CON_IS_VISIBLE(vc) && softback_buf)
2483 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 } else if (CON_IS_VISIBLE(vc)
2485 && vc->vc_mode == KD_TEXT) {
2486 fbcon_clear_margins(vc, 0);
2487 update_screen(vc);
2488 }
2489
2490 if (old_data && (--REFCOUNT(old_data) == 0))
2491 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2492 return 0;
2493}
2494
2495static int fbcon_copy_font(struct vc_data *vc, int con)
2496{
2497 struct display *od = &fb_display[con];
2498 struct console_font *f = &vc->vc_font;
2499
2500 if (od->fontdata == f->data)
2501 return 0; /* already the same font... */
2502 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2503}
2504
2505/*
2506 * User asked to set font; we are guaranteed that
2507 * a) width and height are in range 1..32
2508 * b) charcount does not exceed 512
2509 * but lets not assume that, since someone might someday want to use larger
2510 * fonts. And charcount of 512 is small for unicode support.
2511 *
2512 * However, user space gives the font in 32 rows , regardless of
2513 * actual font height. So a new API is needed if support for larger fonts
2514 * is ever implemented.
2515 */
2516
2517static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2518{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002519 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 unsigned charcount = font->charcount;
2521 int w = font->width;
2522 int h = font->height;
2523 int size;
2524 int i, csum;
2525 u8 *new_data, *data = font->data;
2526 int pitch = (font->width+7) >> 3;
2527
2528 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2529 * If not this check should be changed to charcount < 256 */
2530 if (charcount != 256 && charcount != 512)
2531 return -EINVAL;
2532
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002533 /* Make sure drawing engine can handle the font */
2534 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2535 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2536 return -EINVAL;
2537
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002538 /* Make sure driver can handle the font length */
2539 if (fbcon_invalid_charcount(info, charcount))
2540 return -EINVAL;
2541
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 size = h * pitch * charcount;
2543
2544 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2545
2546 if (!new_data)
2547 return -ENOMEM;
2548
2549 new_data += FONT_EXTRA_WORDS * sizeof(int);
2550 FNTSIZE(new_data) = size;
2551 FNTCHARCNT(new_data) = charcount;
2552 REFCOUNT(new_data) = 0; /* usage counter */
2553 for (i=0; i< charcount; i++) {
2554 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2555 }
2556
2557 /* Since linux has a nice crc32 function use it for counting font
2558 * checksums. */
2559 csum = crc32(0, new_data, size);
2560
2561 FNTSUM(new_data) = csum;
2562 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002563 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 struct vc_data *tmp = vc_cons[i].d;
2565
2566 if (fb_display[i].userfont &&
2567 fb_display[i].fontdata &&
2568 FNTSUM(fb_display[i].fontdata) == csum &&
2569 FNTSIZE(fb_display[i].fontdata) == size &&
2570 tmp->vc_font.width == w &&
2571 !memcmp(fb_display[i].fontdata, new_data, size)) {
2572 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002573 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 break;
2575 }
2576 }
2577 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2578}
2579
2580static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2581{
2582 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002583 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
2585 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002586 f = get_default_font(info->var.xres, info->var.yres,
2587 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 else if (!(f = find_font(name)))
2589 return -ENOENT;
2590
2591 font->width = f->width;
2592 font->height = f->height;
2593 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2594}
2595
2596static u16 palette_red[16];
2597static u16 palette_green[16];
2598static u16 palette_blue[16];
2599
2600static struct fb_cmap palette_cmap = {
2601 0, 16, palette_red, palette_green, palette_blue, NULL
2602};
2603
2604static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2605{
2606 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2607 int i, j, k, depth;
2608 u8 val;
2609
2610 if (fbcon_is_inactive(vc, info))
2611 return -EINVAL;
2612
2613 if (!CON_IS_VISIBLE(vc))
2614 return 0;
2615
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002616 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 if (depth > 3) {
2618 for (i = j = 0; i < 16; i++) {
2619 k = table[i];
2620 val = vc->vc_palette[j++];
2621 palette_red[k] = (val << 8) | val;
2622 val = vc->vc_palette[j++];
2623 palette_green[k] = (val << 8) | val;
2624 val = vc->vc_palette[j++];
2625 palette_blue[k] = (val << 8) | val;
2626 }
2627 palette_cmap.len = 16;
2628 palette_cmap.start = 0;
2629 /*
2630 * If framebuffer is capable of less than 16 colors,
2631 * use default palette of fbcon.
2632 */
2633 } else
2634 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2635
2636 return fb_set_cmap(&palette_cmap, info);
2637}
2638
2639static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2640{
2641 unsigned long p;
2642 int line;
2643
2644 if (vc->vc_num != fg_console || !softback_lines)
2645 return (u16 *) (vc->vc_origin + offset);
2646 line = offset / vc->vc_size_row;
2647 if (line >= softback_lines)
2648 return (u16 *) (vc->vc_origin + offset -
2649 softback_lines * vc->vc_size_row);
2650 p = softback_curr + offset;
2651 if (p >= softback_end)
2652 p += softback_buf - softback_end;
2653 return (u16 *) p;
2654}
2655
2656static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2657 int *px, int *py)
2658{
2659 unsigned long ret;
2660 int x, y;
2661
2662 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2663 unsigned long offset = (pos - vc->vc_origin) / 2;
2664
2665 x = offset % vc->vc_cols;
2666 y = offset / vc->vc_cols;
2667 if (vc->vc_num == fg_console)
2668 y += softback_lines;
2669 ret = pos + (vc->vc_cols - x) * 2;
2670 } else if (vc->vc_num == fg_console && softback_lines) {
2671 unsigned long offset = pos - softback_curr;
2672
2673 if (pos < softback_curr)
2674 offset += softback_end - softback_buf;
2675 offset /= 2;
2676 x = offset % vc->vc_cols;
2677 y = offset / vc->vc_cols;
2678 ret = pos + (vc->vc_cols - x) * 2;
2679 if (ret == softback_end)
2680 ret = softback_buf;
2681 if (ret == softback_in)
2682 ret = vc->vc_origin;
2683 } else {
2684 /* Should not happen */
2685 x = y = 0;
2686 ret = vc->vc_origin;
2687 }
2688 if (px)
2689 *px = x;
2690 if (py)
2691 *py = y;
2692 return ret;
2693}
2694
2695/* As we might be inside of softback, we may work with non-contiguous buffer,
2696 that's why we have to use a separate routine. */
2697static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2698{
2699 while (cnt--) {
2700 u16 a = scr_readw(p);
2701 if (!vc->vc_can_do_color)
2702 a ^= 0x0800;
2703 else if (vc->vc_hi_font_mask == 0x100)
2704 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2705 (((a) & 0x0e00) << 4);
2706 else
2707 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2708 (((a) & 0x0700) << 4);
2709 scr_writew(a, p++);
2710 if (p == (u16 *) softback_end)
2711 p = (u16 *) softback_buf;
2712 if (p == (u16 *) softback_in)
2713 p = (u16 *) vc->vc_origin;
2714 }
2715}
2716
2717static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2718{
2719 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002720 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 struct display *p = &fb_display[fg_console];
2722 int offset, limit, scrollback_old;
2723
2724 if (softback_top) {
2725 if (vc->vc_num != fg_console)
2726 return 0;
2727 if (vc->vc_mode != KD_TEXT || !lines)
2728 return 0;
2729 if (logo_shown >= 0) {
2730 struct vc_data *conp2 = vc_cons[logo_shown].d;
2731
2732 if (conp2->vc_top == logo_lines
2733 && conp2->vc_bottom == conp2->vc_rows)
2734 conp2->vc_top = 0;
2735 if (logo_shown == vc->vc_num) {
2736 unsigned long p, q;
2737 int i;
2738
2739 p = softback_in;
2740 q = vc->vc_origin +
2741 logo_lines * vc->vc_size_row;
2742 for (i = 0; i < logo_lines; i++) {
2743 if (p == softback_top)
2744 break;
2745 if (p == softback_buf)
2746 p = softback_end;
2747 p -= vc->vc_size_row;
2748 q -= vc->vc_size_row;
2749 scr_memcpyw((u16 *) q, (u16 *) p,
2750 vc->vc_size_row);
2751 }
David Hollister308af922006-05-30 21:25:36 -07002752 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 update_region(vc, vc->vc_origin,
2754 logo_lines * vc->vc_cols);
2755 }
2756 logo_shown = FBCON_LOGO_CANSHOW;
2757 }
2758 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2759 fbcon_redraw_softback(vc, p, lines);
2760 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2761 return 0;
2762 }
2763
2764 if (!scrollback_phys_max)
2765 return -ENOSYS;
2766
2767 scrollback_old = scrollback_current;
2768 scrollback_current -= lines;
2769 if (scrollback_current < 0)
2770 scrollback_current = 0;
2771 else if (scrollback_current > scrollback_max)
2772 scrollback_current = scrollback_max;
2773 if (scrollback_current == scrollback_old)
2774 return 0;
2775
2776 if (fbcon_is_inactive(vc, info))
2777 return 0;
2778
2779 fbcon_cursor(vc, CM_ERASE);
2780
2781 offset = p->yscroll - scrollback_current;
2782 limit = p->vrows;
2783 switch (p->scrollmode) {
2784 case SCROLL_WRAP_MOVE:
2785 info->var.vmode |= FB_VMODE_YWRAP;
2786 break;
2787 case SCROLL_PAN_MOVE:
2788 case SCROLL_PAN_REDRAW:
2789 limit -= vc->vc_rows;
2790 info->var.vmode &= ~FB_VMODE_YWRAP;
2791 break;
2792 }
2793 if (offset < 0)
2794 offset += limit;
2795 else if (offset >= limit)
2796 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002797
2798 ops->var.xoffset = 0;
2799 ops->var.yoffset = offset * vc->vc_font.height;
2800 ops->update_start(info);
2801
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 if (!scrollback_current)
2803 fbcon_cursor(vc, CM_DRAW);
2804 return 0;
2805}
2806
2807static int fbcon_set_origin(struct vc_data *vc)
2808{
2809 if (softback_lines)
2810 fbcon_scrolldelta(vc, softback_lines);
2811 return 0;
2812}
2813
2814static void fbcon_suspended(struct fb_info *info)
2815{
2816 struct vc_data *vc = NULL;
2817 struct fbcon_ops *ops = info->fbcon_par;
2818
2819 if (!ops || ops->currcon < 0)
2820 return;
2821 vc = vc_cons[ops->currcon].d;
2822
2823 /* Clear cursor, restore saved data */
2824 fbcon_cursor(vc, CM_ERASE);
2825}
2826
2827static void fbcon_resumed(struct fb_info *info)
2828{
2829 struct vc_data *vc;
2830 struct fbcon_ops *ops = info->fbcon_par;
2831
2832 if (!ops || ops->currcon < 0)
2833 return;
2834 vc = vc_cons[ops->currcon].d;
2835
2836 update_screen(vc);
2837}
2838
2839static void fbcon_modechanged(struct fb_info *info)
2840{
2841 struct fbcon_ops *ops = info->fbcon_par;
2842 struct vc_data *vc;
2843 struct display *p;
2844 int rows, cols;
2845
2846 if (!ops || ops->currcon < 0)
2847 return;
2848 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002849 if (vc->vc_mode != KD_TEXT ||
2850 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 return;
2852
2853 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002854 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
2856 if (CON_IS_VISIBLE(vc)) {
2857 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002858 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2859 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2860 cols /= vc->vc_font.width;
2861 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 vc_resize(vc, cols, rows);
2863 updatescrollmode(p, info, vc);
2864 scrollback_max = 0;
2865 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002866
2867 if (!fbcon_is_inactive(vc, info)) {
2868 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2869 ops->update_start(info);
2870 }
2871
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 fbcon_set_palette(vc, color_table);
2873 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002874 if (softback_buf)
2875 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 }
2877}
2878
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002879static void fbcon_set_all_vcs(struct fb_info *info)
2880{
2881 struct fbcon_ops *ops = info->fbcon_par;
2882 struct vc_data *vc;
2883 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002884 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002885
2886 if (!ops || ops->currcon < 0)
2887 return;
2888
Antonino A. Daplase614b182006-06-26 00:27:09 -07002889 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002890 vc = vc_cons[i].d;
2891 if (!vc || vc->vc_mode != KD_TEXT ||
2892 registered_fb[con2fb_map[i]] != info)
2893 continue;
2894
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002895 if (CON_IS_VISIBLE(vc)) {
2896 fg = i;
2897 continue;
2898 }
2899
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002900 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002901 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002902 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002903 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2904 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002905 cols /= vc->vc_font.width;
2906 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002907 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002908 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002909
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002910 if (fg != -1)
2911 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002912}
2913
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914static int fbcon_mode_deleted(struct fb_info *info,
2915 struct fb_videomode *mode)
2916{
2917 struct fb_info *fb_info;
2918 struct display *p;
2919 int i, j, found = 0;
2920
2921 /* before deletion, ensure that mode is not in use */
2922 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2923 j = con2fb_map[i];
2924 if (j == -1)
2925 continue;
2926 fb_info = registered_fb[j];
2927 if (fb_info != info)
2928 continue;
2929 p = &fb_display[i];
2930 if (!p || !p->mode)
2931 continue;
2932 if (fb_mode_is_equal(p->mode, mode)) {
2933 found = 1;
2934 break;
2935 }
2936 }
2937 return found;
2938}
2939
Antonino A. Daplase614b182006-06-26 00:27:09 -07002940static int fbcon_fb_unregistered(int idx)
2941{
2942 int i;
2943
2944 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2945 if (con2fb_map[i] == idx)
2946 con2fb_map[i] = -1;
2947 }
2948
2949 if (idx == info_idx) {
2950 info_idx = -1;
2951
2952 for (i = 0; i < FB_MAX; i++) {
2953 if (registered_fb[i] != NULL) {
2954 info_idx = i;
2955 break;
2956 }
2957 }
2958 }
2959
2960 if (info_idx != -1) {
2961 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2962 if (con2fb_map[i] == -1)
2963 con2fb_map[i] = info_idx;
2964 }
2965 }
2966
2967 if (!num_registered_fb)
2968 unregister_con_driver(&fb_con);
2969
2970 return 0;
2971}
2972
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973static int fbcon_fb_registered(int idx)
2974{
2975 int ret = 0, i;
2976
2977 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002978 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if (con2fb_map_boot[i] == idx) {
2980 info_idx = idx;
2981 break;
2982 }
2983 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07002984
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 if (info_idx != -1)
2986 ret = fbcon_takeover(1);
2987 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002988 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002989 if (con2fb_map_boot[i] == idx &&
2990 con2fb_map[i] == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 set_con2fb_map(i, idx, 0);
2992 }
2993 }
2994
2995 return ret;
2996}
2997
2998static void fbcon_fb_blanked(struct fb_info *info, int blank)
2999{
3000 struct fbcon_ops *ops = info->fbcon_par;
3001 struct vc_data *vc;
3002
3003 if (!ops || ops->currcon < 0)
3004 return;
3005
3006 vc = vc_cons[ops->currcon].d;
3007 if (vc->vc_mode != KD_TEXT ||
3008 registered_fb[con2fb_map[ops->currcon]] != info)
3009 return;
3010
3011 if (CON_IS_VISIBLE(vc)) {
3012 if (blank)
3013 do_blank_screen(0);
3014 else
3015 do_unblank_screen(0);
3016 }
3017 ops->blank_state = blank;
3018}
3019
3020static void fbcon_new_modelist(struct fb_info *info)
3021{
3022 int i;
3023 struct vc_data *vc;
3024 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003025 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026
Antonino A. Daplase614b182006-06-26 00:27:09 -07003027 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 if (registered_fb[con2fb_map[i]] != info)
3029 continue;
3030 if (!fb_display[i].mode)
3031 continue;
3032 vc = vc_cons[i].d;
3033 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003034 mode = fb_find_nearest_mode(fb_display[i].mode,
3035 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 fb_videomode_to_var(&var, mode);
3037
3038 if (vc)
3039 fbcon_set_disp(info, &var, vc);
3040 else
3041 fbcon_preset_disp(info, &var, i);
3042
3043 }
3044}
3045
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003046static void fbcon_get_requirement(struct fb_info *info,
3047 struct fb_blit_caps *caps)
3048{
3049 struct vc_data *vc;
3050 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003051
3052 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003053 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003054
3055 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3056 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003057 if (vc && vc->vc_mode == KD_TEXT &&
3058 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003059 p = &fb_display[i];
3060 caps->x |= 1 << (vc->vc_font.width - 1);
3061 caps->y |= 1 << (vc->vc_font.height - 1);
3062 charcnt = (p->userfont) ?
3063 FNTCHARCNT(p->fontdata) : 256;
3064 if (caps->len < charcnt)
3065 caps->len = charcnt;
3066 }
3067 }
3068 } else {
3069 vc = vc_cons[fg_console].d;
3070
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003071 if (vc && vc->vc_mode == KD_TEXT &&
3072 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003073 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003074 caps->x = 1 << (vc->vc_font.width - 1);
3075 caps->y = 1 << (vc->vc_font.height - 1);
3076 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003077 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003078 }
3079 }
3080}
3081
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082static int fbcon_event_notify(struct notifier_block *self,
3083 unsigned long action, void *data)
3084{
3085 struct fb_event *event = data;
3086 struct fb_info *info = event->info;
3087 struct fb_videomode *mode;
3088 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003089 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 int ret = 0;
3091
Antonino A. Daplase614b182006-06-26 00:27:09 -07003092 /*
3093 * ignore all events except driver registration and deregistration
3094 * if fbcon is not active
3095 */
3096 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3097 action == FB_EVENT_FB_UNREGISTERED))
3098 goto done;
3099
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 switch(action) {
3101 case FB_EVENT_SUSPEND:
3102 fbcon_suspended(info);
3103 break;
3104 case FB_EVENT_RESUME:
3105 fbcon_resumed(info);
3106 break;
3107 case FB_EVENT_MODE_CHANGE:
3108 fbcon_modechanged(info);
3109 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003110 case FB_EVENT_MODE_CHANGE_ALL:
3111 fbcon_set_all_vcs(info);
3112 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 case FB_EVENT_MODE_DELETE:
3114 mode = event->data;
3115 ret = fbcon_mode_deleted(info, mode);
3116 break;
3117 case FB_EVENT_FB_REGISTERED:
3118 ret = fbcon_fb_registered(info->node);
3119 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003120 case FB_EVENT_FB_UNREGISTERED:
3121 ret = fbcon_fb_unregistered(info->node);
3122 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 case FB_EVENT_SET_CONSOLE_MAP:
3124 con2fb = event->data;
3125 ret = set_con2fb_map(con2fb->console - 1,
3126 con2fb->framebuffer, 1);
3127 break;
3128 case FB_EVENT_GET_CONSOLE_MAP:
3129 con2fb = event->data;
3130 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3131 break;
3132 case FB_EVENT_BLANK:
3133 fbcon_fb_blanked(info, *(int *)event->data);
3134 break;
3135 case FB_EVENT_NEW_MODELIST:
3136 fbcon_new_modelist(info);
3137 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003138 case FB_EVENT_GET_REQ:
3139 caps = event->data;
3140 fbcon_get_requirement(info, caps);
3141 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 }
3143
Antonino A. Daplase614b182006-06-26 00:27:09 -07003144done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145 return ret;
3146}
3147
3148/*
3149 * The console `switch' structure for the frame buffer based console
3150 */
3151
3152static const struct consw fb_con = {
3153 .owner = THIS_MODULE,
3154 .con_startup = fbcon_startup,
3155 .con_init = fbcon_init,
3156 .con_deinit = fbcon_deinit,
3157 .con_clear = fbcon_clear,
3158 .con_putc = fbcon_putc,
3159 .con_putcs = fbcon_putcs,
3160 .con_cursor = fbcon_cursor,
3161 .con_scroll = fbcon_scroll,
3162 .con_bmove = fbcon_bmove,
3163 .con_switch = fbcon_switch,
3164 .con_blank = fbcon_blank,
3165 .con_font_set = fbcon_set_font,
3166 .con_font_get = fbcon_get_font,
3167 .con_font_default = fbcon_set_def_font,
3168 .con_font_copy = fbcon_copy_font,
3169 .con_set_palette = fbcon_set_palette,
3170 .con_scrolldelta = fbcon_scrolldelta,
3171 .con_set_origin = fbcon_set_origin,
3172 .con_invert_region = fbcon_invert_region,
3173 .con_screen_pos = fbcon_screen_pos,
3174 .con_getxy = fbcon_getxy,
3175 .con_resize = fbcon_resize,
3176};
3177
3178static struct notifier_block fbcon_event_notifier = {
3179 .notifier_call = fbcon_event_notify,
3180};
3181
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003182static ssize_t store_rotate(struct class_device *class_device,
3183 const char *buf, size_t count)
3184{
3185 struct fb_info *info;
3186 int rotate, idx;
3187 char **last = NULL;
3188
Antonino A. Daplase614b182006-06-26 00:27:09 -07003189 if (fbcon_has_exited)
3190 return count;
3191
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003192 acquire_console_sem();
3193 idx = con2fb_map[fg_console];
3194
3195 if (idx == -1 || registered_fb[idx] == NULL)
3196 goto err;
3197
3198 info = registered_fb[idx];
3199 rotate = simple_strtoul(buf, last, 0);
3200 fbcon_rotate(info, rotate);
3201err:
3202 release_console_sem();
3203 return count;
3204}
3205
3206static ssize_t store_rotate_all(struct class_device *class_device,
3207 const char *buf, size_t count)
3208{
3209 struct fb_info *info;
3210 int rotate, idx;
3211 char **last = NULL;
3212
Antonino A. Daplase614b182006-06-26 00:27:09 -07003213 if (fbcon_has_exited)
3214 return count;
3215
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003216 acquire_console_sem();
3217 idx = con2fb_map[fg_console];
3218
3219 if (idx == -1 || registered_fb[idx] == NULL)
3220 goto err;
3221
3222 info = registered_fb[idx];
3223 rotate = simple_strtoul(buf, last, 0);
3224 fbcon_rotate_all(info, rotate);
3225err:
3226 release_console_sem();
3227 return count;
3228}
3229
3230static ssize_t show_rotate(struct class_device *class_device, char *buf)
3231{
3232 struct fb_info *info;
3233 int rotate = 0, idx;
3234
Antonino A. Daplase614b182006-06-26 00:27:09 -07003235 if (fbcon_has_exited)
3236 return 0;
3237
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003238 acquire_console_sem();
3239 idx = con2fb_map[fg_console];
3240
3241 if (idx == -1 || registered_fb[idx] == NULL)
3242 goto err;
3243
3244 info = registered_fb[idx];
3245 rotate = fbcon_get_rotate(info);
3246err:
3247 release_console_sem();
3248 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3249}
3250
3251static struct class_device_attribute class_device_attrs[] = {
3252 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3253 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3254};
3255
3256static int fbcon_init_class_device(void)
3257{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003258 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003259
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003260 fbcon_has_sysfs = 1;
3261
3262 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3263 error = class_device_create_file(fbcon_class_device,
3264 &class_device_attrs[i]);
3265
3266 if (error)
3267 break;
3268 }
3269
3270 if (error) {
3271 while (--i >= 0)
3272 class_device_remove_file(fbcon_class_device,
3273 &class_device_attrs[i]);
3274
3275 fbcon_has_sysfs = 0;
3276 }
3277
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003278 return 0;
3279}
3280
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003281static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003284 int i;
3285
3286 acquire_console_sem();
3287
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 for (i = 0; i < FB_MAX; i++) {
3289 if (registered_fb[i] != NULL) {
3290 info_idx = i;
3291 break;
3292 }
3293 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003294
3295 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 fbcon_takeover(0);
3297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298}
3299
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003300static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003301{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003302 struct fb_info *info;
3303 int i, j, mapped;
3304
Antonino A. Daplase614b182006-06-26 00:27:09 -07003305 if (fbcon_has_exited)
3306 return;
3307
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003308#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003309 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003310#endif
3311#ifdef CONFIG_MAC
3312 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003313 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003314#endif
3315
3316 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003317 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003318
3319 for (i = 0; i < FB_MAX; i++) {
3320 mapped = 0;
3321 info = registered_fb[i];
3322
3323 if (info == NULL)
3324 continue;
3325
Antonino A. Daplase614b182006-06-26 00:27:09 -07003326 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3327 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003328 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003329 }
3330
3331 if (mapped) {
3332 if (info->fbops->fb_release)
3333 info->fbops->fb_release(info, 0);
3334 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003335
3336 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003337 struct fbcon_ops *ops = info->fbcon_par;
3338
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003339 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003340 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003341 kfree(info->fbcon_par);
3342 info->fbcon_par = NULL;
3343 }
3344
3345 if (info->queue.func == fb_flashcursor)
3346 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003347 }
3348 }
3349
Antonino A. Daplase614b182006-06-26 00:27:09 -07003350 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003351}
3352
3353static int __init fb_console_init(void)
3354{
3355 int i;
3356
3357 acquire_console_sem();
3358 fb_register_client(&fbcon_event_notifier);
3359 fbcon_class_device =
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003360 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003361
3362 if (IS_ERR(fbcon_class_device)) {
3363 printk(KERN_WARNING "Unable to create class_device "
3364 "for fbcon; errno = %ld\n",
3365 PTR_ERR(fbcon_class_device));
3366 fbcon_class_device = NULL;
3367 } else
3368 fbcon_init_class_device();
3369
3370 for (i = 0; i < MAX_NR_CONSOLES; i++)
3371 con2fb_map[i] = -1;
3372
3373 release_console_sem();
3374 fbcon_start();
3375 return 0;
3376}
3377
3378module_init(fb_console_init);
3379
3380#ifdef MODULE
3381
Antonino A. Daplase614b182006-06-26 00:27:09 -07003382static void __exit fbcon_deinit_class_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003383{
3384 int i;
3385
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003386 if (fbcon_has_sysfs) {
3387 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3388 class_device_remove_file(fbcon_class_device,
3389 &class_device_attrs[i]);
3390
3391 fbcon_has_sysfs = 0;
3392 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003393}
3394
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395static void __exit fb_console_exit(void)
3396{
3397 acquire_console_sem();
3398 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003399 fbcon_deinit_class_device();
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003400 class_device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003401 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003403 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404}
3405
3406module_exit(fb_console_exit);
3407
3408#endif
3409
3410MODULE_LICENSE("GPL");