blob: c71a88d531cd6eb3cda61d9106376c69b63d418d [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}
688#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800689static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 struct fbcon_ops *ops = info->fbcon_par;
692
693 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800694 ops->p = &fb_display[vc->vc_num];
695 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 fbcon_set_bitops(ops);
697}
698#endif /* CONFIG_MISC_TILEBLITTING */
699
700
701static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
702 int unit, int oldidx)
703{
704 struct fbcon_ops *ops = NULL;
705 int err = 0;
706
707 if (!try_module_get(info->fbops->owner))
708 err = -ENODEV;
709
710 if (!err && info->fbops->fb_open &&
711 info->fbops->fb_open(info, 0))
712 err = -ENODEV;
713
714 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800715 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (!ops)
717 err = -ENOMEM;
718 }
719
720 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 info->fbcon_par = ops;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800722 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724
725 if (err) {
726 con2fb_map[unit] = oldidx;
727 module_put(info->fbops->owner);
728 }
729
730 return err;
731}
732
733static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
734 struct fb_info *newinfo, int unit,
735 int oldidx, int found)
736{
737 struct fbcon_ops *ops = oldinfo->fbcon_par;
738 int err = 0;
739
740 if (oldinfo->fbops->fb_release &&
741 oldinfo->fbops->fb_release(oldinfo, 0)) {
742 con2fb_map[unit] = oldidx;
743 if (!found && newinfo->fbops->fb_release)
744 newinfo->fbops->fb_release(newinfo, 0);
745 if (!found)
746 module_put(newinfo->fbops->owner);
747 err = -ENODEV;
748 }
749
750 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700751 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 kfree(ops->cursor_state.mask);
753 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800754 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 kfree(oldinfo->fbcon_par);
756 oldinfo->fbcon_par = NULL;
757 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800758 /*
759 If oldinfo and newinfo are driving the same hardware,
760 the fb_release() method of oldinfo may attempt to
761 restore the hardware state. This will leave the
762 newinfo in an undefined state. Thus, a call to
763 fb_set_par() may be needed for the newinfo.
764 */
765 if (newinfo->fbops->fb_set_par)
766 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
769 return err;
770}
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
773 int unit, int show_logo)
774{
775 struct fbcon_ops *ops = info->fbcon_par;
776
777 ops->currcon = fg_console;
778
779 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
780 info->fbops->fb_set_par(info);
781
782 ops->flags |= FBCON_FLAGS_INIT;
783 ops->graphics = 0;
784
785 if (vc)
786 fbcon_set_disp(info, &info->var, vc);
787 else
788 fbcon_preset_disp(info, &info->var, unit);
789
790 if (show_logo) {
791 struct vc_data *fg_vc = vc_cons[fg_console].d;
792 struct fb_info *fg_info =
793 registered_fb[con2fb_map[fg_console]];
794
795 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
796 fg_vc->vc_rows, fg_vc->vc_cols,
797 fg_vc->vc_rows);
798 }
799
800 update_screen(vc_cons[fg_console].d);
801}
802
803/**
804 * set_con2fb_map - map console to frame buffer device
805 * @unit: virtual console number to map
806 * @newidx: frame buffer index to map virtual console to
807 * @user: user request
808 *
809 * Maps a virtual console @unit to a frame buffer device
810 * @newidx.
811 */
812static int set_con2fb_map(int unit, int newidx, int user)
813{
814 struct vc_data *vc = vc_cons[unit].d;
815 int oldidx = con2fb_map[unit];
816 struct fb_info *info = registered_fb[newidx];
817 struct fb_info *oldinfo = NULL;
818 int found, err = 0;
819
820 if (oldidx == newidx)
821 return 0;
822
Antonino A. Daplase614b182006-06-26 00:27:09 -0700823 if (!info || fbcon_has_exited)
824 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 if (!err && !search_for_mapped_con()) {
827 info_idx = newidx;
828 return fbcon_takeover(0);
829 }
830
831 if (oldidx != -1)
832 oldinfo = registered_fb[oldidx];
833
834 found = search_fb_in_map(newidx);
835
836 acquire_console_sem();
837 con2fb_map[unit] = newidx;
838 if (!err && !found)
839 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
840
841
842 /*
843 * If old fb is not mapped to any of the consoles,
844 * fbcon should release it.
845 */
846 if (!err && oldinfo && !search_fb_in_map(oldidx))
847 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
848 found);
849
850 if (!err) {
851 int show_logo = (fg_console == 0 && !user &&
852 logo_shown != FBCON_LOGO_DONTSHOW);
853
854 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700855 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 con2fb_map_boot[unit] = newidx;
857 con2fb_init_display(vc, info, unit, show_logo);
858 }
859
Antonino A. Daplase614b182006-06-26 00:27:09 -0700860 if (!search_fb_in_map(info_idx))
861 info_idx = newidx;
862
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 release_console_sem();
864 return err;
865}
866
867/*
868 * Low Level Operations
869 */
870/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
871static int var_to_display(struct display *disp,
872 struct fb_var_screeninfo *var,
873 struct fb_info *info)
874{
875 disp->xres_virtual = var->xres_virtual;
876 disp->yres_virtual = var->yres_virtual;
877 disp->bits_per_pixel = var->bits_per_pixel;
878 disp->grayscale = var->grayscale;
879 disp->nonstd = var->nonstd;
880 disp->accel_flags = var->accel_flags;
881 disp->height = var->height;
882 disp->width = var->width;
883 disp->red = var->red;
884 disp->green = var->green;
885 disp->blue = var->blue;
886 disp->transp = var->transp;
887 disp->rotate = var->rotate;
888 disp->mode = fb_match_mode(var, &info->modelist);
889 if (disp->mode == NULL)
890 /* This should not happen */
891 return -EINVAL;
892 return 0;
893}
894
895static void display_to_var(struct fb_var_screeninfo *var,
896 struct display *disp)
897{
898 fb_videomode_to_var(var, disp->mode);
899 var->xres_virtual = disp->xres_virtual;
900 var->yres_virtual = disp->yres_virtual;
901 var->bits_per_pixel = disp->bits_per_pixel;
902 var->grayscale = disp->grayscale;
903 var->nonstd = disp->nonstd;
904 var->accel_flags = disp->accel_flags;
905 var->height = disp->height;
906 var->width = disp->width;
907 var->red = disp->red;
908 var->green = disp->green;
909 var->blue = disp->blue;
910 var->transp = disp->transp;
911 var->rotate = disp->rotate;
912}
913
914static const char *fbcon_startup(void)
915{
916 const char *display_desc = "frame buffer device";
917 struct display *p = &fb_display[fg_console];
918 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700919 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 struct module *owner;
921 struct fb_info *info = NULL;
922 struct fbcon_ops *ops;
923 int rows, cols;
924 int irqres;
925
926 irqres = 1;
927 /*
928 * If num_registered_fb is zero, this is a call for the dummy part.
929 * The frame buffer devices weren't initialized yet.
930 */
931 if (!num_registered_fb || info_idx == -1)
932 return display_desc;
933 /*
934 * Instead of blindly using registered_fb[0], we use info_idx, set by
935 * fb_console_init();
936 */
937 info = registered_fb[info_idx];
938 if (!info)
939 return NULL;
940
941 owner = info->fbops->owner;
942 if (!try_module_get(owner))
943 return NULL;
944 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
945 module_put(owner);
946 return NULL;
947 }
948
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800949 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 if (!ops) {
951 module_put(owner);
952 return NULL;
953 }
954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 ops->currcon = -1;
956 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800957 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800959 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800960 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 if (info->fix.type != FB_TYPE_TEXT) {
963 if (fbcon_softback_size) {
964 if (!softback_buf) {
965 softback_buf =
966 (unsigned long)
967 kmalloc(fbcon_softback_size,
968 GFP_KERNEL);
969 if (!softback_buf) {
970 fbcon_softback_size = 0;
971 softback_top = 0;
972 }
973 }
974 } else {
975 if (softback_buf) {
976 kfree((void *) softback_buf);
977 softback_buf = 0;
978 softback_top = 0;
979 }
980 }
981 if (softback_buf)
982 softback_in = softback_top = softback_curr =
983 softback_buf;
984 softback_lines = 0;
985 }
986
987 /* Setup default font */
988 if (!p->fontdata) {
989 if (!fontname[0] || !(font = find_font(fontname)))
990 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700991 info->var.yres,
992 info->pixmap.blit_x,
993 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 vc->vc_font.width = font->width;
995 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700996 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
998 }
999
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001000 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1001 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1002 cols /= vc->vc_font.width;
1003 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 vc_resize(vc, cols, rows);
1005
1006 DPRINTK("mode: %s\n", info->fix.id);
1007 DPRINTK("visual: %d\n", info->fix.visual);
1008 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1009 info->var.yres,
1010 info->var.bits_per_pixel);
1011
1012#ifdef CONFIG_ATARI
1013 if (MACH_IS_ATARI) {
1014 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1015 irqres =
1016 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1017 IRQ_TYPE_PRIO, "framebuffer vbl",
1018 info);
1019 }
1020#endif /* CONFIG_ATARI */
1021
1022#ifdef CONFIG_MAC
1023 /*
1024 * On a Macintoy, the VBL interrupt may or may not be active.
1025 * As interrupt based cursor is more reliable and race free, we
1026 * probe for VBL interrupts.
1027 */
1028 if (MACH_IS_MAC) {
1029 int ct = 0;
1030 /*
1031 * Probe for VBL: set temp. handler ...
1032 */
1033 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1034 "framebuffer vbl", info);
1035 vbl_detected = 0;
1036
1037 /*
1038 * ... and spin for 20 ms ...
1039 */
1040 while (!vbl_detected && ++ct < 1000)
1041 udelay(20);
1042
1043 if (ct == 1000)
1044 printk
1045 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1046
1047 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1048
1049 if (vbl_detected) {
1050 /*
1051 * interrupt based cursor ok
1052 */
1053 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1054 irqres =
1055 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1056 "framebuffer vbl", info);
1057 } else {
1058 /*
1059 * VBL not detected: fall through, use timer based cursor
1060 */
1061 irqres = 1;
1062 }
1063 }
1064#endif /* CONFIG_MAC */
1065
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001066 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001067 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 return display_desc;
1069}
1070
1071static void fbcon_init(struct vc_data *vc, int init)
1072{
1073 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1074 struct fbcon_ops *ops;
1075 struct vc_data **default_mode = vc->vc_display_fg;
1076 struct vc_data *svc = *default_mode;
1077 struct display *t, *p = &fb_display[vc->vc_num];
1078 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001079 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 if (info_idx == -1 || info == NULL)
1082 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001083
1084 cap = info->flags;
1085
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1087 (info->fix.type == FB_TYPE_TEXT))
1088 logo = 0;
1089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (var_to_display(p, &info->var, info))
1091 return;
1092
1093 /* If we are not the first console on this
1094 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001095 t = &fb_display[fg_console];
1096 if (!p->fontdata) {
1097 if (t->fontdata) {
1098 struct vc_data *fvc = vc_cons[fg_console].d;
1099
1100 vc->vc_font.data = (void *)(p->fontdata =
1101 fvc->vc_font.data);
1102 vc->vc_font.width = fvc->vc_font.width;
1103 vc->vc_font.height = fvc->vc_font.height;
1104 p->userfont = t->userfont;
1105
1106 if (p->userfont)
1107 REFCOUNT(p->fontdata)++;
1108 } else {
1109 const struct font_desc *font = NULL;
1110
1111 if (!fontname[0] || !(font = find_font(fontname)))
1112 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001113 info->var.yres,
1114 info->pixmap.blit_x,
1115 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001116 vc->vc_font.width = font->width;
1117 vc->vc_font.height = font->height;
1118 vc->vc_font.data = (void *)(p->fontdata = font->data);
1119 vc->vc_font.charcount = 256; /* FIXME Need to
1120 support more fonts */
1121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 if (p->userfont)
1125 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001126
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001127 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1129 if (charcnt == 256) {
1130 vc->vc_hi_font_mask = 0;
1131 } else {
1132 vc->vc_hi_font_mask = 0x100;
1133 if (vc->vc_can_do_color)
1134 vc->vc_complement_mask <<= 1;
1135 }
1136
1137 if (!*svc->vc_uni_pagedir_loc)
1138 con_set_default_unimap(svc);
1139 if (!*vc->vc_uni_pagedir_loc)
1140 con_copy_unimap(vc, svc);
1141
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001142 ops = info->fbcon_par;
1143 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001144 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 cols = vc->vc_cols;
1147 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001148 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1149 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1150 new_cols /= vc->vc_font.width;
1151 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 vc_resize(vc, new_cols, new_rows);
1153
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 /*
1155 * We must always set the mode. The mode of the previous console
1156 * driver could be in the same resolution but we are using different
1157 * hardware so we have to initialize the hardware.
1158 *
1159 * We need to do it in fbcon_init() to prevent screen corruption.
1160 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001161 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 if (info->fbops->fb_set_par &&
1163 !(ops->flags & FBCON_FLAGS_INIT))
1164 info->fbops->fb_set_par(info);
1165 ops->flags |= FBCON_FLAGS_INIT;
1166 }
1167
1168 ops->graphics = 0;
1169
1170 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1171 !(cap & FBINFO_HWACCEL_DISABLED))
1172 p->scrollmode = SCROLL_MOVE;
1173 else /* default to something safe */
1174 p->scrollmode = SCROLL_REDRAW;
1175
1176 /*
1177 * ++guenther: console.c:vc_allocate() relies on initializing
1178 * vc_{cols,rows}, but we must not set those if we are only
1179 * resizing the console.
1180 */
1181 if (!init) {
1182 vc->vc_cols = new_cols;
1183 vc->vc_rows = new_rows;
1184 }
1185
1186 if (logo)
1187 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1188
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001189 if (vc == svc && softback_buf)
1190 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001191
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001192 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001193 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001194 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001195 }
1196
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001197 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Antonino A. Daplase614b182006-06-26 00:27:09 -07001200static void fbcon_free_font(struct display *p)
1201{
1202 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1203 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1204 p->fontdata = NULL;
1205 p->userfont = 0;
1206}
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208static void fbcon_deinit(struct vc_data *vc)
1209{
1210 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001211 struct fb_info *info;
1212 struct fbcon_ops *ops;
1213 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001216 idx = con2fb_map[vc->vc_num];
1217
1218 if (idx == -1)
1219 goto finished;
1220
1221 info = registered_fb[idx];
1222
1223 if (!info)
1224 goto finished;
1225
1226 ops = info->fbcon_par;
1227
1228 if (!ops)
1229 goto finished;
1230
1231 if (CON_IS_VISIBLE(vc))
1232 fbcon_del_cursor_timer(info);
1233
1234 ops->flags &= ~FBCON_FLAGS_INIT;
1235finished:
1236
1237 if (!con_is_bound(&fb_con))
1238 fbcon_exit();
1239
1240 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
1243/* ====================================================================== */
1244
1245/* fbcon_XXX routines - interface used by the world
1246 *
1247 * This system is now divided into two levels because of complications
1248 * caused by hardware scrolling. Top level functions:
1249 *
1250 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1251 *
1252 * handles y values in range [0, scr_height-1] that correspond to real
1253 * screen positions. y_wrap shift means that first line of bitmap may be
1254 * anywhere on this display. These functions convert lineoffsets to
1255 * bitmap offsets and deal with the wrap-around case by splitting blits.
1256 *
1257 * fbcon_bmove_physical_8() -- These functions fast implementations
1258 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1259 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1260 *
1261 * WARNING:
1262 *
1263 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1264 * Implies should only really hardware scroll in rows. Only reason for
1265 * restriction is simplicity & efficiency at the moment.
1266 */
1267
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1269 int width)
1270{
1271 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1272 struct fbcon_ops *ops = info->fbcon_par;
1273
1274 struct display *p = &fb_display[vc->vc_num];
1275 u_int y_break;
1276
1277 if (fbcon_is_inactive(vc, info))
1278 return;
1279
1280 if (!height || !width)
1281 return;
1282
1283 /* Split blits that cross physical y_wrap boundary */
1284
1285 y_break = p->vrows - p->yscroll;
1286 if (sy < y_break && sy + height - 1 >= y_break) {
1287 u_int b = y_break - sy;
1288 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1289 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1290 width);
1291 } else
1292 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1293}
1294
1295static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1296 int count, int ypos, int xpos)
1297{
1298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1299 struct display *p = &fb_display[vc->vc_num];
1300 struct fbcon_ops *ops = info->fbcon_par;
1301
1302 if (!fbcon_is_inactive(vc, info))
1303 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1304 get_color(vc, info, scr_readw(s), 1),
1305 get_color(vc, info, scr_readw(s), 0));
1306}
1307
1308static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1309{
1310 unsigned short chr;
1311
1312 scr_writew(c, &chr);
1313 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1314}
1315
1316static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1317{
1318 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1319 struct fbcon_ops *ops = info->fbcon_par;
1320
1321 if (!fbcon_is_inactive(vc, info))
1322 ops->clear_margins(vc, info, bottom_only);
1323}
1324
1325static void fbcon_cursor(struct vc_data *vc, int mode)
1326{
1327 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1328 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 int y;
1330 int c = scr_readw((u16 *) vc->vc_pos);
1331
Michal Januszewskid1e23062007-05-08 00:38:07 -07001332 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 return;
1334
1335 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1336 if (mode & CM_SOFTBACK) {
1337 mode &= ~CM_SOFTBACK;
1338 y = softback_lines;
1339 } else {
1340 if (softback_lines)
1341 fbcon_set_origin(vc);
1342 y = 0;
1343 }
1344
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001345 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 get_color(vc, info, c, 0));
1347 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1348}
1349
1350static int scrollback_phys_max = 0;
1351static int scrollback_max = 0;
1352static int scrollback_current = 0;
1353
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354/*
1355 * If no vc is existent yet, just set struct display
1356 */
1357static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1358 int unit)
1359{
1360 struct display *p = &fb_display[unit];
1361 struct display *t = &fb_display[fg_console];
1362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if (var_to_display(p, var, info))
1364 return;
1365
1366 p->fontdata = t->fontdata;
1367 p->userfont = t->userfont;
1368 if (p->userfont)
1369 REFCOUNT(p->fontdata)++;
1370}
1371
1372static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1373 struct vc_data *vc)
1374{
1375 struct display *p = &fb_display[vc->vc_num], *t;
1376 struct vc_data **default_mode = vc->vc_display_fg;
1377 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001378 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 int rows, cols, charcnt = 256;
1380
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (var_to_display(p, var, info))
1382 return;
1383 t = &fb_display[svc->vc_num];
1384 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001385 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 vc->vc_font.width = (*default_mode)->vc_font.width;
1387 vc->vc_font.height = (*default_mode)->vc_font.height;
1388 p->userfont = t->userfont;
1389 if (p->userfont)
1390 REFCOUNT(p->fontdata)++;
1391 }
1392 if (p->userfont)
1393 charcnt = FNTCHARCNT(p->fontdata);
1394
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001395 var->activate = FB_ACTIVATE_NOW;
1396 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001397 var->yoffset = info->var.yoffset;
1398 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001399 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001400 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001401 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1403 if (charcnt == 256) {
1404 vc->vc_hi_font_mask = 0;
1405 } else {
1406 vc->vc_hi_font_mask = 0x100;
1407 if (vc->vc_can_do_color)
1408 vc->vc_complement_mask <<= 1;
1409 }
1410
1411 if (!*svc->vc_uni_pagedir_loc)
1412 con_set_default_unimap(svc);
1413 if (!*vc->vc_uni_pagedir_loc)
1414 con_copy_unimap(vc, svc);
1415
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001416 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1417 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1418 cols /= vc->vc_font.width;
1419 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001421
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (CON_IS_VISIBLE(vc)) {
1423 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001424 if (softback_buf)
1425 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
1427}
1428
1429static __inline__ void ywrap_up(struct vc_data *vc, int count)
1430{
1431 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001432 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 struct display *p = &fb_display[vc->vc_num];
1434
1435 p->yscroll += count;
1436 if (p->yscroll >= p->vrows) /* Deal with wrap */
1437 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001438 ops->var.xoffset = 0;
1439 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1440 ops->var.vmode |= FB_VMODE_YWRAP;
1441 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 scrollback_max += count;
1443 if (scrollback_max > scrollback_phys_max)
1444 scrollback_max = scrollback_phys_max;
1445 scrollback_current = 0;
1446}
1447
1448static __inline__ void ywrap_down(struct vc_data *vc, int count)
1449{
1450 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001451 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 struct display *p = &fb_display[vc->vc_num];
1453
1454 p->yscroll -= count;
1455 if (p->yscroll < 0) /* Deal with wrap */
1456 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001457 ops->var.xoffset = 0;
1458 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1459 ops->var.vmode |= FB_VMODE_YWRAP;
1460 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 scrollback_max -= count;
1462 if (scrollback_max < 0)
1463 scrollback_max = 0;
1464 scrollback_current = 0;
1465}
1466
1467static __inline__ void ypan_up(struct vc_data *vc, int count)
1468{
1469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1470 struct display *p = &fb_display[vc->vc_num];
1471 struct fbcon_ops *ops = info->fbcon_par;
1472
1473 p->yscroll += count;
1474 if (p->yscroll > p->vrows - vc->vc_rows) {
1475 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1476 0, 0, 0, vc->vc_rows, vc->vc_cols);
1477 p->yscroll -= p->vrows - vc->vc_rows;
1478 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001479
1480 ops->var.xoffset = 0;
1481 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1482 ops->var.vmode &= ~FB_VMODE_YWRAP;
1483 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 fbcon_clear_margins(vc, 1);
1485 scrollback_max += count;
1486 if (scrollback_max > scrollback_phys_max)
1487 scrollback_max = scrollback_phys_max;
1488 scrollback_current = 0;
1489}
1490
1491static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1492{
1493 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001494 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001498
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 if (p->yscroll > p->vrows - vc->vc_rows) {
1500 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001502 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001503
1504 ops->var.xoffset = 0;
1505 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1506 ops->var.vmode &= ~FB_VMODE_YWRAP;
1507 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 fbcon_clear_margins(vc, 1);
1509 scrollback_max += count;
1510 if (scrollback_max > scrollback_phys_max)
1511 scrollback_max = scrollback_phys_max;
1512 scrollback_current = 0;
1513}
1514
1515static __inline__ void ypan_down(struct vc_data *vc, int count)
1516{
1517 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1518 struct display *p = &fb_display[vc->vc_num];
1519 struct fbcon_ops *ops = info->fbcon_par;
1520
1521 p->yscroll -= count;
1522 if (p->yscroll < 0) {
1523 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1524 0, vc->vc_rows, vc->vc_cols);
1525 p->yscroll += p->vrows - vc->vc_rows;
1526 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001527
1528 ops->var.xoffset = 0;
1529 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1530 ops->var.vmode &= ~FB_VMODE_YWRAP;
1531 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 fbcon_clear_margins(vc, 1);
1533 scrollback_max -= count;
1534 if (scrollback_max < 0)
1535 scrollback_max = 0;
1536 scrollback_current = 0;
1537}
1538
1539static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1540{
1541 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001542 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544
1545 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001546
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 if (p->yscroll < 0) {
1548 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001550 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001551
1552 ops->var.xoffset = 0;
1553 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1554 ops->var.vmode &= ~FB_VMODE_YWRAP;
1555 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 fbcon_clear_margins(vc, 1);
1557 scrollback_max -= count;
1558 if (scrollback_max < 0)
1559 scrollback_max = 0;
1560 scrollback_current = 0;
1561}
1562
1563static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1564 long delta)
1565{
1566 int count = vc->vc_rows;
1567 unsigned short *d, *s;
1568 unsigned long n;
1569 int line = 0;
1570
1571 d = (u16 *) softback_curr;
1572 if (d == (u16 *) softback_in)
1573 d = (u16 *) vc->vc_origin;
1574 n = softback_curr + delta * vc->vc_size_row;
1575 softback_lines -= delta;
1576 if (delta < 0) {
1577 if (softback_curr < softback_top && n < softback_buf) {
1578 n += softback_end - softback_buf;
1579 if (n < softback_top) {
1580 softback_lines -=
1581 (softback_top - n) / vc->vc_size_row;
1582 n = softback_top;
1583 }
1584 } else if (softback_curr >= softback_top
1585 && n < softback_top) {
1586 softback_lines -=
1587 (softback_top - n) / vc->vc_size_row;
1588 n = softback_top;
1589 }
1590 } else {
1591 if (softback_curr > softback_in && n >= softback_end) {
1592 n += softback_buf - softback_end;
1593 if (n > softback_in) {
1594 n = softback_in;
1595 softback_lines = 0;
1596 }
1597 } else if (softback_curr <= softback_in && n > softback_in) {
1598 n = softback_in;
1599 softback_lines = 0;
1600 }
1601 }
1602 if (n == softback_curr)
1603 return;
1604 softback_curr = n;
1605 s = (u16 *) softback_curr;
1606 if (s == (u16 *) softback_in)
1607 s = (u16 *) vc->vc_origin;
1608 while (count--) {
1609 unsigned short *start;
1610 unsigned short *le;
1611 unsigned short c;
1612 int x = 0;
1613 unsigned short attr = 1;
1614
1615 start = s;
1616 le = advance_row(s, 1);
1617 do {
1618 c = scr_readw(s);
1619 if (attr != (c & 0xff00)) {
1620 attr = c & 0xff00;
1621 if (s > start) {
1622 fbcon_putcs(vc, start, s - start,
1623 line, x);
1624 x += s - start;
1625 start = s;
1626 }
1627 }
1628 if (c == scr_readw(d)) {
1629 if (s > start) {
1630 fbcon_putcs(vc, start, s - start,
1631 line, x);
1632 x += s - start + 1;
1633 start = s + 1;
1634 } else {
1635 x++;
1636 start++;
1637 }
1638 }
1639 s++;
1640 d++;
1641 } while (s < le);
1642 if (s > start)
1643 fbcon_putcs(vc, start, s - start, line, x);
1644 line++;
1645 if (d == (u16 *) softback_end)
1646 d = (u16 *) softback_buf;
1647 if (d == (u16 *) softback_in)
1648 d = (u16 *) vc->vc_origin;
1649 if (s == (u16 *) softback_end)
1650 s = (u16 *) softback_buf;
1651 if (s == (u16 *) softback_in)
1652 s = (u16 *) vc->vc_origin;
1653 }
1654}
1655
1656static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1657 int line, int count, int dy)
1658{
1659 unsigned short *s = (unsigned short *)
1660 (vc->vc_origin + vc->vc_size_row * line);
1661
1662 while (count--) {
1663 unsigned short *start = s;
1664 unsigned short *le = advance_row(s, 1);
1665 unsigned short c;
1666 int x = 0;
1667 unsigned short attr = 1;
1668
1669 do {
1670 c = scr_readw(s);
1671 if (attr != (c & 0xff00)) {
1672 attr = c & 0xff00;
1673 if (s > start) {
1674 fbcon_putcs(vc, start, s - start,
1675 dy, x);
1676 x += s - start;
1677 start = s;
1678 }
1679 }
1680 console_conditional_schedule();
1681 s++;
1682 } while (s < le);
1683 if (s > start)
1684 fbcon_putcs(vc, start, s - start, dy, x);
1685 console_conditional_schedule();
1686 dy++;
1687 }
1688}
1689
1690static void fbcon_redraw(struct vc_data *vc, struct display *p,
1691 int line, int count, int offset)
1692{
1693 unsigned short *d = (unsigned short *)
1694 (vc->vc_origin + vc->vc_size_row * line);
1695 unsigned short *s = d + offset;
1696
1697 while (count--) {
1698 unsigned short *start = s;
1699 unsigned short *le = advance_row(s, 1);
1700 unsigned short c;
1701 int x = 0;
1702 unsigned short attr = 1;
1703
1704 do {
1705 c = scr_readw(s);
1706 if (attr != (c & 0xff00)) {
1707 attr = c & 0xff00;
1708 if (s > start) {
1709 fbcon_putcs(vc, start, s - start,
1710 line, x);
1711 x += s - start;
1712 start = s;
1713 }
1714 }
1715 if (c == scr_readw(d)) {
1716 if (s > start) {
1717 fbcon_putcs(vc, start, s - start,
1718 line, x);
1719 x += s - start + 1;
1720 start = s + 1;
1721 } else {
1722 x++;
1723 start++;
1724 }
1725 }
1726 scr_writew(c, d);
1727 console_conditional_schedule();
1728 s++;
1729 d++;
1730 } while (s < le);
1731 if (s > start)
1732 fbcon_putcs(vc, start, s - start, line, x);
1733 console_conditional_schedule();
1734 if (offset > 0)
1735 line++;
1736 else {
1737 line--;
1738 /* NOTE: We subtract two lines from these pointers */
1739 s -= vc->vc_size_row;
1740 d -= vc->vc_size_row;
1741 }
1742 }
1743}
1744
1745static inline void fbcon_softback_note(struct vc_data *vc, int t,
1746 int count)
1747{
1748 unsigned short *p;
1749
1750 if (vc->vc_num != fg_console)
1751 return;
1752 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1753
1754 while (count) {
1755 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1756 count--;
1757 p = advance_row(p, 1);
1758 softback_in += vc->vc_size_row;
1759 if (softback_in == softback_end)
1760 softback_in = softback_buf;
1761 if (softback_in == softback_top) {
1762 softback_top += vc->vc_size_row;
1763 if (softback_top == softback_end)
1764 softback_top = softback_buf;
1765 }
1766 }
1767 softback_curr = softback_in;
1768}
1769
1770static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1771 int count)
1772{
1773 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1774 struct display *p = &fb_display[vc->vc_num];
1775 struct fbcon_ops *ops = info->fbcon_par;
1776 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1777
1778 if (fbcon_is_inactive(vc, info))
1779 return -EINVAL;
1780
1781 fbcon_cursor(vc, CM_ERASE);
1782
1783 /*
1784 * ++Geert: Only use ywrap/ypan if the console is in text mode
1785 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1786 * whole screen (prevents flicker).
1787 */
1788
1789 switch (dir) {
1790 case SM_UP:
1791 if (count > vc->vc_rows) /* Maximum realistic size */
1792 count = vc->vc_rows;
1793 if (softback_top)
1794 fbcon_softback_note(vc, t, count);
1795 if (logo_shown >= 0)
1796 goto redraw_up;
1797 switch (p->scrollmode) {
1798 case SCROLL_MOVE:
1799 ops->bmove(vc, info, t + count, 0, t, 0,
1800 b - t - count, vc->vc_cols);
1801 ops->clear(vc, info, b - count, 0, count,
1802 vc->vc_cols);
1803 break;
1804
1805 case SCROLL_WRAP_MOVE:
1806 if (b - t - count > 3 * vc->vc_rows >> 2) {
1807 if (t > 0)
1808 fbcon_bmove(vc, 0, 0, count, 0, t,
1809 vc->vc_cols);
1810 ywrap_up(vc, count);
1811 if (vc->vc_rows - b > 0)
1812 fbcon_bmove(vc, b - count, 0, b, 0,
1813 vc->vc_rows - b,
1814 vc->vc_cols);
1815 } else if (info->flags & FBINFO_READS_FAST)
1816 fbcon_bmove(vc, t + count, 0, t, 0,
1817 b - t - count, vc->vc_cols);
1818 else
1819 goto redraw_up;
1820 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1821 break;
1822
1823 case SCROLL_PAN_REDRAW:
1824 if ((p->yscroll + count <=
1825 2 * (p->vrows - vc->vc_rows))
1826 && ((!scroll_partial && (b - t == vc->vc_rows))
1827 || (scroll_partial
1828 && (b - t - count >
1829 3 * vc->vc_rows >> 2)))) {
1830 if (t > 0)
1831 fbcon_redraw_move(vc, p, 0, t, count);
1832 ypan_up_redraw(vc, t, count);
1833 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001834 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 vc->vc_rows - b, b);
1836 } else
1837 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1838 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1839 break;
1840
1841 case SCROLL_PAN_MOVE:
1842 if ((p->yscroll + count <=
1843 2 * (p->vrows - vc->vc_rows))
1844 && ((!scroll_partial && (b - t == vc->vc_rows))
1845 || (scroll_partial
1846 && (b - t - count >
1847 3 * vc->vc_rows >> 2)))) {
1848 if (t > 0)
1849 fbcon_bmove(vc, 0, 0, count, 0, t,
1850 vc->vc_cols);
1851 ypan_up(vc, count);
1852 if (vc->vc_rows - b > 0)
1853 fbcon_bmove(vc, b - count, 0, b, 0,
1854 vc->vc_rows - b,
1855 vc->vc_cols);
1856 } else if (info->flags & FBINFO_READS_FAST)
1857 fbcon_bmove(vc, t + count, 0, t, 0,
1858 b - t - count, vc->vc_cols);
1859 else
1860 goto redraw_up;
1861 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1862 break;
1863
1864 case SCROLL_REDRAW:
1865 redraw_up:
1866 fbcon_redraw(vc, p, t, b - t - count,
1867 count * vc->vc_cols);
1868 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1869 scr_memsetw((unsigned short *) (vc->vc_origin +
1870 vc->vc_size_row *
1871 (b - count)),
1872 vc->vc_video_erase_char,
1873 vc->vc_size_row * count);
1874 return 1;
1875 }
1876 break;
1877
1878 case SM_DOWN:
1879 if (count > vc->vc_rows) /* Maximum realistic size */
1880 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001881 if (logo_shown >= 0)
1882 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 switch (p->scrollmode) {
1884 case SCROLL_MOVE:
1885 ops->bmove(vc, info, t, 0, t + count, 0,
1886 b - t - count, vc->vc_cols);
1887 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1888 break;
1889
1890 case SCROLL_WRAP_MOVE:
1891 if (b - t - count > 3 * vc->vc_rows >> 2) {
1892 if (vc->vc_rows - b > 0)
1893 fbcon_bmove(vc, b, 0, b - count, 0,
1894 vc->vc_rows - b,
1895 vc->vc_cols);
1896 ywrap_down(vc, count);
1897 if (t > 0)
1898 fbcon_bmove(vc, count, 0, 0, 0, t,
1899 vc->vc_cols);
1900 } else if (info->flags & FBINFO_READS_FAST)
1901 fbcon_bmove(vc, t, 0, t + count, 0,
1902 b - t - count, vc->vc_cols);
1903 else
1904 goto redraw_down;
1905 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1906 break;
1907
1908 case SCROLL_PAN_MOVE:
1909 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1910 && ((!scroll_partial && (b - t == vc->vc_rows))
1911 || (scroll_partial
1912 && (b - t - count >
1913 3 * vc->vc_rows >> 2)))) {
1914 if (vc->vc_rows - b > 0)
1915 fbcon_bmove(vc, b, 0, b - count, 0,
1916 vc->vc_rows - b,
1917 vc->vc_cols);
1918 ypan_down(vc, count);
1919 if (t > 0)
1920 fbcon_bmove(vc, count, 0, 0, 0, t,
1921 vc->vc_cols);
1922 } else if (info->flags & FBINFO_READS_FAST)
1923 fbcon_bmove(vc, t, 0, t + count, 0,
1924 b - t - count, vc->vc_cols);
1925 else
1926 goto redraw_down;
1927 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1928 break;
1929
1930 case SCROLL_PAN_REDRAW:
1931 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1932 && ((!scroll_partial && (b - t == vc->vc_rows))
1933 || (scroll_partial
1934 && (b - t - count >
1935 3 * vc->vc_rows >> 2)))) {
1936 if (vc->vc_rows - b > 0)
1937 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1938 b - count);
1939 ypan_down_redraw(vc, t, count);
1940 if (t > 0)
1941 fbcon_redraw_move(vc, p, count, t, 0);
1942 } else
1943 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1944 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1945 break;
1946
1947 case SCROLL_REDRAW:
1948 redraw_down:
1949 fbcon_redraw(vc, p, b - 1, b - t - count,
1950 -count * vc->vc_cols);
1951 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1952 scr_memsetw((unsigned short *) (vc->vc_origin +
1953 vc->vc_size_row *
1954 t),
1955 vc->vc_video_erase_char,
1956 vc->vc_size_row * count);
1957 return 1;
1958 }
1959 }
1960 return 0;
1961}
1962
1963
1964static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1965 int height, int width)
1966{
1967 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1968 struct display *p = &fb_display[vc->vc_num];
1969
1970 if (fbcon_is_inactive(vc, info))
1971 return;
1972
1973 if (!width || !height)
1974 return;
1975
1976 /* Split blits that cross physical y_wrap case.
1977 * Pathological case involves 4 blits, better to use recursive
1978 * code rather than unrolled case
1979 *
1980 * Recursive invocations don't need to erase the cursor over and
1981 * over again, so we use fbcon_bmove_rec()
1982 */
1983 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1984 p->vrows - p->yscroll);
1985}
1986
1987static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1988 int dy, int dx, int height, int width, u_int y_break)
1989{
1990 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1991 struct fbcon_ops *ops = info->fbcon_par;
1992 u_int b;
1993
1994 if (sy < y_break && sy + height > y_break) {
1995 b = y_break - sy;
1996 if (dy < sy) { /* Avoid trashing self */
1997 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1998 y_break);
1999 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2000 height - b, width, y_break);
2001 } else {
2002 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2003 height - b, width, y_break);
2004 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2005 y_break);
2006 }
2007 return;
2008 }
2009
2010 if (dy < y_break && dy + height > y_break) {
2011 b = y_break - dy;
2012 if (dy < sy) { /* Avoid trashing self */
2013 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2014 y_break);
2015 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2016 height - b, width, y_break);
2017 } else {
2018 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2019 height - b, width, y_break);
2020 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2021 y_break);
2022 }
2023 return;
2024 }
2025 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2026 height, width);
2027}
2028
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002029static __inline__ void updatescrollmode(struct display *p,
2030 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 struct vc_data *vc)
2032{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002033 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 int fh = vc->vc_font.height;
2035 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002036 u16 t = 0;
2037 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2038 info->fix.xpanstep);
2039 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2040 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2041 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2042 info->var.xres_virtual);
2043 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2044 divides(ypan, vc->vc_font.height) && vyres > yres;
2045 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2046 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002047 divides(vc->vc_font.height, vyres) &&
2048 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002050 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2051 !(cap & FBINFO_HWACCEL_DISABLED);
2052 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2053 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002055 p->vrows = vyres/fh;
2056 if (yres > (fh * (vc->vc_rows + 1)))
2057 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2058 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 p->vrows--;
2060
2061 if (good_wrap || good_pan) {
2062 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002063 p->scrollmode = good_wrap ?
2064 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 else
2066 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2067 SCROLL_PAN_REDRAW;
2068 } else {
2069 if (reading_fast || (fast_copyarea && !fast_imageblit))
2070 p->scrollmode = SCROLL_MOVE;
2071 else
2072 p->scrollmode = SCROLL_REDRAW;
2073 }
2074}
2075
2076static int fbcon_resize(struct vc_data *vc, unsigned int width,
2077 unsigned int height)
2078{
2079 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002080 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct display *p = &fb_display[vc->vc_num];
2082 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002083 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002085 virt_w = FBCON_SWAP(ops->rotate, width, height);
2086 virt_h = FBCON_SWAP(ops->rotate, height, width);
2087 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2088 vc->vc_font.height);
2089 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2090 vc->vc_font.width);
2091 var.xres = virt_w * virt_fw;
2092 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 x_diff = info->var.xres - var.xres;
2094 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002095 if (x_diff < 0 || x_diff > virt_fw ||
2096 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002097 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2100 mode = fb_find_best_mode(&var, &info->modelist);
2101 if (mode == NULL)
2102 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002103 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002105
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002106 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2110 if (CON_IS_VISIBLE(vc)) {
2111 var.activate = FB_ACTIVATE_NOW |
2112 FB_ACTIVATE_FORCE;
2113 fb_set_var(info, &var);
2114 }
2115 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002116 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
2118 updatescrollmode(p, info, vc);
2119 return 0;
2120}
2121
2122static int fbcon_switch(struct vc_data *vc)
2123{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002124 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002125 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 struct display *p = &fb_display[vc->vc_num];
2127 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002128 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002131 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132
2133 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 if (softback_lines)
2135 fbcon_set_origin(vc);
2136 softback_top = softback_curr = softback_in = softback_buf;
2137 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002138 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 }
2140
2141 if (logo_shown >= 0) {
2142 struct vc_data *conp2 = vc_cons[logo_shown].d;
2143
2144 if (conp2->vc_top == logo_lines
2145 && conp2->vc_bottom == conp2->vc_rows)
2146 conp2->vc_top = 0;
2147 logo_shown = FBCON_LOGO_CANSHOW;
2148 }
2149
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002150 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002151 if (prev_console != -1)
2152 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 /*
2154 * FIXME: If we have multiple fbdev's loaded, we need to
2155 * update all info->currcon. Perhaps, we can place this
2156 * in a centralized structure, but this might break some
2157 * drivers.
2158 *
2159 * info->currcon = vc->vc_num;
2160 */
2161 for (i = 0; i < FB_MAX; i++) {
2162 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002163 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002165 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 }
2167 }
2168 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2169 display_to_var(&var, p);
2170 var.activate = FB_ACTIVATE_NOW;
2171
2172 /*
2173 * make sure we don't unnecessarily trip the memcmp()
2174 * in fb_set_var()
2175 */
2176 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002177 var.yoffset = info->var.yoffset;
2178 var.xoffset = info->var.xoffset;
2179 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002181 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
Knut Petersen39942fd2005-12-12 22:17:19 -08002183 if (old_info != NULL && (old_info != info ||
2184 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002185 if (info->fbops->fb_set_par)
2186 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002187
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002188 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002189 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002192 if (fbcon_is_inactive(vc, info) ||
2193 ops->blank_state != FB_BLANK_UNBLANK)
2194 fbcon_del_cursor_timer(info);
2195 else
2196 fbcon_add_cursor_timer(info);
2197
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002198 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002199 ops->cursor_reset = 1;
2200
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002201 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002202 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002203 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002206 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002208
2209 if (p->userfont)
2210 charcnt = FNTCHARCNT(vc->vc_font.data);
2211
2212 if (charcnt > 256)
2213 vc->vc_complement_mask <<= 1;
2214
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 updatescrollmode(p, info, vc);
2216
2217 switch (p->scrollmode) {
2218 case SCROLL_WRAP_MOVE:
2219 scrollback_phys_max = p->vrows - vc->vc_rows;
2220 break;
2221 case SCROLL_PAN_MOVE:
2222 case SCROLL_PAN_REDRAW:
2223 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2224 if (scrollback_phys_max < 0)
2225 scrollback_phys_max = 0;
2226 break;
2227 default:
2228 scrollback_phys_max = 0;
2229 break;
2230 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 scrollback_max = 0;
2233 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002234
2235 if (!fbcon_is_inactive(vc, info)) {
2236 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2237 ops->update_start(info);
2238 }
2239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 fbcon_set_palette(vc, color_table);
2241 fbcon_clear_margins(vc, 0);
2242
2243 if (logo_shown == FBCON_LOGO_DRAW) {
2244
2245 logo_shown = fg_console;
2246 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002247 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 update_region(vc,
2249 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2250 vc->vc_size_row * (vc->vc_bottom -
2251 vc->vc_top) / 2);
2252 return 0;
2253 }
2254 return 1;
2255}
2256
2257static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2258 int blank)
2259{
Richard Purdie994efac2007-02-09 09:46:45 +00002260 struct fb_event event;
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 if (blank) {
2263 unsigned short charmask = vc->vc_hi_font_mask ?
2264 0x1ff : 0xff;
2265 unsigned short oldc;
2266
2267 oldc = vc->vc_video_erase_char;
2268 vc->vc_video_erase_char &= charmask;
2269 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2270 vc->vc_video_erase_char = oldc;
2271 }
Richard Purdie994efac2007-02-09 09:46:45 +00002272
2273
2274 event.info = info;
2275 event.data = &blank;
2276 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
2279static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2280{
2281 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2282 struct fbcon_ops *ops = info->fbcon_par;
2283
2284 if (mode_switch) {
2285 struct fb_var_screeninfo var = info->var;
2286
2287 ops->graphics = 1;
2288
2289 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002290 if (info->fbops->fb_save_state)
2291 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2293 fb_set_var(info, &var);
2294 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002295 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002296 } else if (info->fbops->fb_restore_state)
2297 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 }
2299
2300 if (!fbcon_is_inactive(vc, info)) {
2301 if (ops->blank_state != blank) {
2302 ops->blank_state = blank;
2303 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2304 ops->cursor_flash = (!blank);
2305
2306 if (fb_blank(info, blank))
2307 fbcon_generic_blank(vc, info, blank);
2308 }
2309
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002310 if (!blank)
2311 update_screen(vc);
2312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002314 if (fbcon_is_inactive(vc, info) ||
2315 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002316 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002317 else
2318 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002319
2320 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321}
2322
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2324{
2325 u8 *fontdata = vc->vc_font.data;
2326 u8 *data = font->data;
2327 int i, j;
2328
2329 font->width = vc->vc_font.width;
2330 font->height = vc->vc_font.height;
2331 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2332 if (!font->data)
2333 return 0;
2334
2335 if (font->width <= 8) {
2336 j = vc->vc_font.height;
2337 for (i = 0; i < font->charcount; i++) {
2338 memcpy(data, fontdata, j);
2339 memset(data + j, 0, 32 - j);
2340 data += 32;
2341 fontdata += j;
2342 }
2343 } else if (font->width <= 16) {
2344 j = vc->vc_font.height * 2;
2345 for (i = 0; i < font->charcount; i++) {
2346 memcpy(data, fontdata, j);
2347 memset(data + j, 0, 64 - j);
2348 data += 64;
2349 fontdata += j;
2350 }
2351 } else if (font->width <= 24) {
2352 for (i = 0; i < font->charcount; i++) {
2353 for (j = 0; j < vc->vc_font.height; j++) {
2354 *data++ = fontdata[0];
2355 *data++ = fontdata[1];
2356 *data++ = fontdata[2];
2357 fontdata += sizeof(u32);
2358 }
2359 memset(data, 0, 3 * (32 - j));
2360 data += 3 * (32 - j);
2361 }
2362 } else {
2363 j = vc->vc_font.height * 4;
2364 for (i = 0; i < font->charcount; i++) {
2365 memcpy(data, fontdata, j);
2366 memset(data + j, 0, 128 - j);
2367 data += 128;
2368 fontdata += j;
2369 }
2370 }
2371 return 0;
2372}
2373
2374static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002375 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376{
2377 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002378 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 struct display *p = &fb_display[vc->vc_num];
2380 int resize;
2381 int cnt;
2382 char *old_data = NULL;
2383
2384 if (CON_IS_VISIBLE(vc) && softback_lines)
2385 fbcon_set_origin(vc);
2386
2387 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2388 if (p->userfont)
2389 old_data = vc->vc_font.data;
2390 if (userfont)
2391 cnt = FNTCHARCNT(data);
2392 else
2393 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002394 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 if ((p->userfont = userfont))
2396 REFCOUNT(data)++;
2397 vc->vc_font.width = w;
2398 vc->vc_font.height = h;
2399 if (vc->vc_hi_font_mask && cnt == 256) {
2400 vc->vc_hi_font_mask = 0;
2401 if (vc->vc_can_do_color) {
2402 vc->vc_complement_mask >>= 1;
2403 vc->vc_s_complement_mask >>= 1;
2404 }
2405
2406 /* ++Edmund: reorder the attribute bits */
2407 if (vc->vc_can_do_color) {
2408 unsigned short *cp =
2409 (unsigned short *) vc->vc_origin;
2410 int count = vc->vc_screenbuf_size / 2;
2411 unsigned short c;
2412 for (; count > 0; count--, cp++) {
2413 c = scr_readw(cp);
2414 scr_writew(((c & 0xfe00) >> 1) |
2415 (c & 0xff), cp);
2416 }
2417 c = vc->vc_video_erase_char;
2418 vc->vc_video_erase_char =
2419 ((c & 0xfe00) >> 1) | (c & 0xff);
2420 vc->vc_attr >>= 1;
2421 }
2422 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2423 vc->vc_hi_font_mask = 0x100;
2424 if (vc->vc_can_do_color) {
2425 vc->vc_complement_mask <<= 1;
2426 vc->vc_s_complement_mask <<= 1;
2427 }
2428
2429 /* ++Edmund: reorder the attribute bits */
2430 {
2431 unsigned short *cp =
2432 (unsigned short *) vc->vc_origin;
2433 int count = vc->vc_screenbuf_size / 2;
2434 unsigned short c;
2435 for (; count > 0; count--, cp++) {
2436 unsigned short newc;
2437 c = scr_readw(cp);
2438 if (vc->vc_can_do_color)
2439 newc =
2440 ((c & 0xff00) << 1) | (c &
2441 0xff);
2442 else
2443 newc = c & ~0x100;
2444 scr_writew(newc, cp);
2445 }
2446 c = vc->vc_video_erase_char;
2447 if (vc->vc_can_do_color) {
2448 vc->vc_video_erase_char =
2449 ((c & 0xff00) << 1) | (c & 0xff);
2450 vc->vc_attr <<= 1;
2451 } else
2452 vc->vc_video_erase_char = c & ~0x100;
2453 }
2454
2455 }
2456
2457 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002458 int cols, rows;
2459
2460 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2461 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2462 cols /= w;
2463 rows /= h;
2464 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002465 if (CON_IS_VISIBLE(vc) && softback_buf)
2466 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 } else if (CON_IS_VISIBLE(vc)
2468 && vc->vc_mode == KD_TEXT) {
2469 fbcon_clear_margins(vc, 0);
2470 update_screen(vc);
2471 }
2472
2473 if (old_data && (--REFCOUNT(old_data) == 0))
2474 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2475 return 0;
2476}
2477
2478static int fbcon_copy_font(struct vc_data *vc, int con)
2479{
2480 struct display *od = &fb_display[con];
2481 struct console_font *f = &vc->vc_font;
2482
2483 if (od->fontdata == f->data)
2484 return 0; /* already the same font... */
2485 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2486}
2487
2488/*
2489 * User asked to set font; we are guaranteed that
2490 * a) width and height are in range 1..32
2491 * b) charcount does not exceed 512
2492 * but lets not assume that, since someone might someday want to use larger
2493 * fonts. And charcount of 512 is small for unicode support.
2494 *
2495 * However, user space gives the font in 32 rows , regardless of
2496 * actual font height. So a new API is needed if support for larger fonts
2497 * is ever implemented.
2498 */
2499
2500static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2501{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002502 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 unsigned charcount = font->charcount;
2504 int w = font->width;
2505 int h = font->height;
2506 int size;
2507 int i, csum;
2508 u8 *new_data, *data = font->data;
2509 int pitch = (font->width+7) >> 3;
2510
2511 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2512 * If not this check should be changed to charcount < 256 */
2513 if (charcount != 256 && charcount != 512)
2514 return -EINVAL;
2515
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002516 /* Make sure drawing engine can handle the font */
2517 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2518 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2519 return -EINVAL;
2520
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 size = h * pitch * charcount;
2522
2523 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2524
2525 if (!new_data)
2526 return -ENOMEM;
2527
2528 new_data += FONT_EXTRA_WORDS * sizeof(int);
2529 FNTSIZE(new_data) = size;
2530 FNTCHARCNT(new_data) = charcount;
2531 REFCOUNT(new_data) = 0; /* usage counter */
2532 for (i=0; i< charcount; i++) {
2533 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2534 }
2535
2536 /* Since linux has a nice crc32 function use it for counting font
2537 * checksums. */
2538 csum = crc32(0, new_data, size);
2539
2540 FNTSUM(new_data) = csum;
2541 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002542 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 struct vc_data *tmp = vc_cons[i].d;
2544
2545 if (fb_display[i].userfont &&
2546 fb_display[i].fontdata &&
2547 FNTSUM(fb_display[i].fontdata) == csum &&
2548 FNTSIZE(fb_display[i].fontdata) == size &&
2549 tmp->vc_font.width == w &&
2550 !memcmp(fb_display[i].fontdata, new_data, size)) {
2551 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002552 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 break;
2554 }
2555 }
2556 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2557}
2558
2559static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2560{
2561 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002562 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002565 f = get_default_font(info->var.xres, info->var.yres,
2566 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 else if (!(f = find_font(name)))
2568 return -ENOENT;
2569
2570 font->width = f->width;
2571 font->height = f->height;
2572 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2573}
2574
2575static u16 palette_red[16];
2576static u16 palette_green[16];
2577static u16 palette_blue[16];
2578
2579static struct fb_cmap palette_cmap = {
2580 0, 16, palette_red, palette_green, palette_blue, NULL
2581};
2582
2583static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2584{
2585 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2586 int i, j, k, depth;
2587 u8 val;
2588
2589 if (fbcon_is_inactive(vc, info))
2590 return -EINVAL;
2591
2592 if (!CON_IS_VISIBLE(vc))
2593 return 0;
2594
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002595 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 if (depth > 3) {
2597 for (i = j = 0; i < 16; i++) {
2598 k = table[i];
2599 val = vc->vc_palette[j++];
2600 palette_red[k] = (val << 8) | val;
2601 val = vc->vc_palette[j++];
2602 palette_green[k] = (val << 8) | val;
2603 val = vc->vc_palette[j++];
2604 palette_blue[k] = (val << 8) | val;
2605 }
2606 palette_cmap.len = 16;
2607 palette_cmap.start = 0;
2608 /*
2609 * If framebuffer is capable of less than 16 colors,
2610 * use default palette of fbcon.
2611 */
2612 } else
2613 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2614
2615 return fb_set_cmap(&palette_cmap, info);
2616}
2617
2618static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2619{
2620 unsigned long p;
2621 int line;
2622
2623 if (vc->vc_num != fg_console || !softback_lines)
2624 return (u16 *) (vc->vc_origin + offset);
2625 line = offset / vc->vc_size_row;
2626 if (line >= softback_lines)
2627 return (u16 *) (vc->vc_origin + offset -
2628 softback_lines * vc->vc_size_row);
2629 p = softback_curr + offset;
2630 if (p >= softback_end)
2631 p += softback_buf - softback_end;
2632 return (u16 *) p;
2633}
2634
2635static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2636 int *px, int *py)
2637{
2638 unsigned long ret;
2639 int x, y;
2640
2641 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2642 unsigned long offset = (pos - vc->vc_origin) / 2;
2643
2644 x = offset % vc->vc_cols;
2645 y = offset / vc->vc_cols;
2646 if (vc->vc_num == fg_console)
2647 y += softback_lines;
2648 ret = pos + (vc->vc_cols - x) * 2;
2649 } else if (vc->vc_num == fg_console && softback_lines) {
2650 unsigned long offset = pos - softback_curr;
2651
2652 if (pos < softback_curr)
2653 offset += softback_end - softback_buf;
2654 offset /= 2;
2655 x = offset % vc->vc_cols;
2656 y = offset / vc->vc_cols;
2657 ret = pos + (vc->vc_cols - x) * 2;
2658 if (ret == softback_end)
2659 ret = softback_buf;
2660 if (ret == softback_in)
2661 ret = vc->vc_origin;
2662 } else {
2663 /* Should not happen */
2664 x = y = 0;
2665 ret = vc->vc_origin;
2666 }
2667 if (px)
2668 *px = x;
2669 if (py)
2670 *py = y;
2671 return ret;
2672}
2673
2674/* As we might be inside of softback, we may work with non-contiguous buffer,
2675 that's why we have to use a separate routine. */
2676static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2677{
2678 while (cnt--) {
2679 u16 a = scr_readw(p);
2680 if (!vc->vc_can_do_color)
2681 a ^= 0x0800;
2682 else if (vc->vc_hi_font_mask == 0x100)
2683 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2684 (((a) & 0x0e00) << 4);
2685 else
2686 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2687 (((a) & 0x0700) << 4);
2688 scr_writew(a, p++);
2689 if (p == (u16 *) softback_end)
2690 p = (u16 *) softback_buf;
2691 if (p == (u16 *) softback_in)
2692 p = (u16 *) vc->vc_origin;
2693 }
2694}
2695
2696static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2697{
2698 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002699 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 struct display *p = &fb_display[fg_console];
2701 int offset, limit, scrollback_old;
2702
2703 if (softback_top) {
2704 if (vc->vc_num != fg_console)
2705 return 0;
2706 if (vc->vc_mode != KD_TEXT || !lines)
2707 return 0;
2708 if (logo_shown >= 0) {
2709 struct vc_data *conp2 = vc_cons[logo_shown].d;
2710
2711 if (conp2->vc_top == logo_lines
2712 && conp2->vc_bottom == conp2->vc_rows)
2713 conp2->vc_top = 0;
2714 if (logo_shown == vc->vc_num) {
2715 unsigned long p, q;
2716 int i;
2717
2718 p = softback_in;
2719 q = vc->vc_origin +
2720 logo_lines * vc->vc_size_row;
2721 for (i = 0; i < logo_lines; i++) {
2722 if (p == softback_top)
2723 break;
2724 if (p == softback_buf)
2725 p = softback_end;
2726 p -= vc->vc_size_row;
2727 q -= vc->vc_size_row;
2728 scr_memcpyw((u16 *) q, (u16 *) p,
2729 vc->vc_size_row);
2730 }
David Hollister308af922006-05-30 21:25:36 -07002731 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 update_region(vc, vc->vc_origin,
2733 logo_lines * vc->vc_cols);
2734 }
2735 logo_shown = FBCON_LOGO_CANSHOW;
2736 }
2737 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2738 fbcon_redraw_softback(vc, p, lines);
2739 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2740 return 0;
2741 }
2742
2743 if (!scrollback_phys_max)
2744 return -ENOSYS;
2745
2746 scrollback_old = scrollback_current;
2747 scrollback_current -= lines;
2748 if (scrollback_current < 0)
2749 scrollback_current = 0;
2750 else if (scrollback_current > scrollback_max)
2751 scrollback_current = scrollback_max;
2752 if (scrollback_current == scrollback_old)
2753 return 0;
2754
2755 if (fbcon_is_inactive(vc, info))
2756 return 0;
2757
2758 fbcon_cursor(vc, CM_ERASE);
2759
2760 offset = p->yscroll - scrollback_current;
2761 limit = p->vrows;
2762 switch (p->scrollmode) {
2763 case SCROLL_WRAP_MOVE:
2764 info->var.vmode |= FB_VMODE_YWRAP;
2765 break;
2766 case SCROLL_PAN_MOVE:
2767 case SCROLL_PAN_REDRAW:
2768 limit -= vc->vc_rows;
2769 info->var.vmode &= ~FB_VMODE_YWRAP;
2770 break;
2771 }
2772 if (offset < 0)
2773 offset += limit;
2774 else if (offset >= limit)
2775 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002776
2777 ops->var.xoffset = 0;
2778 ops->var.yoffset = offset * vc->vc_font.height;
2779 ops->update_start(info);
2780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 if (!scrollback_current)
2782 fbcon_cursor(vc, CM_DRAW);
2783 return 0;
2784}
2785
2786static int fbcon_set_origin(struct vc_data *vc)
2787{
2788 if (softback_lines)
2789 fbcon_scrolldelta(vc, softback_lines);
2790 return 0;
2791}
2792
2793static void fbcon_suspended(struct fb_info *info)
2794{
2795 struct vc_data *vc = NULL;
2796 struct fbcon_ops *ops = info->fbcon_par;
2797
2798 if (!ops || ops->currcon < 0)
2799 return;
2800 vc = vc_cons[ops->currcon].d;
2801
2802 /* Clear cursor, restore saved data */
2803 fbcon_cursor(vc, CM_ERASE);
2804}
2805
2806static void fbcon_resumed(struct fb_info *info)
2807{
2808 struct vc_data *vc;
2809 struct fbcon_ops *ops = info->fbcon_par;
2810
2811 if (!ops || ops->currcon < 0)
2812 return;
2813 vc = vc_cons[ops->currcon].d;
2814
2815 update_screen(vc);
2816}
2817
2818static void fbcon_modechanged(struct fb_info *info)
2819{
2820 struct fbcon_ops *ops = info->fbcon_par;
2821 struct vc_data *vc;
2822 struct display *p;
2823 int rows, cols;
2824
2825 if (!ops || ops->currcon < 0)
2826 return;
2827 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002828 if (vc->vc_mode != KD_TEXT ||
2829 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 return;
2831
2832 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002833 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
2835 if (CON_IS_VISIBLE(vc)) {
2836 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002837 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2838 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2839 cols /= vc->vc_font.width;
2840 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 vc_resize(vc, cols, rows);
2842 updatescrollmode(p, info, vc);
2843 scrollback_max = 0;
2844 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002845
2846 if (!fbcon_is_inactive(vc, info)) {
2847 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2848 ops->update_start(info);
2849 }
2850
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 fbcon_set_palette(vc, color_table);
2852 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002853 if (softback_buf)
2854 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 }
2856}
2857
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002858static void fbcon_set_all_vcs(struct fb_info *info)
2859{
2860 struct fbcon_ops *ops = info->fbcon_par;
2861 struct vc_data *vc;
2862 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002863 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002864
2865 if (!ops || ops->currcon < 0)
2866 return;
2867
Antonino A. Daplase614b182006-06-26 00:27:09 -07002868 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002869 vc = vc_cons[i].d;
2870 if (!vc || vc->vc_mode != KD_TEXT ||
2871 registered_fb[con2fb_map[i]] != info)
2872 continue;
2873
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002874 if (CON_IS_VISIBLE(vc)) {
2875 fg = i;
2876 continue;
2877 }
2878
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002879 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002880 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002881 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002882 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2883 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002884 cols /= vc->vc_font.width;
2885 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002886 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002887 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002888
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002889 if (fg != -1)
2890 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002891}
2892
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893static int fbcon_mode_deleted(struct fb_info *info,
2894 struct fb_videomode *mode)
2895{
2896 struct fb_info *fb_info;
2897 struct display *p;
2898 int i, j, found = 0;
2899
2900 /* before deletion, ensure that mode is not in use */
2901 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2902 j = con2fb_map[i];
2903 if (j == -1)
2904 continue;
2905 fb_info = registered_fb[j];
2906 if (fb_info != info)
2907 continue;
2908 p = &fb_display[i];
2909 if (!p || !p->mode)
2910 continue;
2911 if (fb_mode_is_equal(p->mode, mode)) {
2912 found = 1;
2913 break;
2914 }
2915 }
2916 return found;
2917}
2918
Antonino A. Daplase614b182006-06-26 00:27:09 -07002919static int fbcon_fb_unregistered(int idx)
2920{
2921 int i;
2922
2923 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2924 if (con2fb_map[i] == idx)
2925 con2fb_map[i] = -1;
2926 }
2927
2928 if (idx == info_idx) {
2929 info_idx = -1;
2930
2931 for (i = 0; i < FB_MAX; i++) {
2932 if (registered_fb[i] != NULL) {
2933 info_idx = i;
2934 break;
2935 }
2936 }
2937 }
2938
2939 if (info_idx != -1) {
2940 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2941 if (con2fb_map[i] == -1)
2942 con2fb_map[i] = info_idx;
2943 }
2944 }
2945
2946 if (!num_registered_fb)
2947 unregister_con_driver(&fb_con);
2948
2949 return 0;
2950}
2951
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952static int fbcon_fb_registered(int idx)
2953{
2954 int ret = 0, i;
2955
2956 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002957 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 if (con2fb_map_boot[i] == idx) {
2959 info_idx = idx;
2960 break;
2961 }
2962 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07002963
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 if (info_idx != -1)
2965 ret = fbcon_takeover(1);
2966 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002967 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002968 if (con2fb_map_boot[i] == idx &&
2969 con2fb_map[i] == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 set_con2fb_map(i, idx, 0);
2971 }
2972 }
2973
2974 return ret;
2975}
2976
2977static void fbcon_fb_blanked(struct fb_info *info, int blank)
2978{
2979 struct fbcon_ops *ops = info->fbcon_par;
2980 struct vc_data *vc;
2981
2982 if (!ops || ops->currcon < 0)
2983 return;
2984
2985 vc = vc_cons[ops->currcon].d;
2986 if (vc->vc_mode != KD_TEXT ||
2987 registered_fb[con2fb_map[ops->currcon]] != info)
2988 return;
2989
2990 if (CON_IS_VISIBLE(vc)) {
2991 if (blank)
2992 do_blank_screen(0);
2993 else
2994 do_unblank_screen(0);
2995 }
2996 ops->blank_state = blank;
2997}
2998
2999static void fbcon_new_modelist(struct fb_info *info)
3000{
3001 int i;
3002 struct vc_data *vc;
3003 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003004 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005
Antonino A. Daplase614b182006-06-26 00:27:09 -07003006 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 if (registered_fb[con2fb_map[i]] != info)
3008 continue;
3009 if (!fb_display[i].mode)
3010 continue;
3011 vc = vc_cons[i].d;
3012 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003013 mode = fb_find_nearest_mode(fb_display[i].mode,
3014 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 fb_videomode_to_var(&var, mode);
3016
3017 if (vc)
3018 fbcon_set_disp(info, &var, vc);
3019 else
3020 fbcon_preset_disp(info, &var, i);
3021
3022 }
3023}
3024
3025static int fbcon_event_notify(struct notifier_block *self,
3026 unsigned long action, void *data)
3027{
3028 struct fb_event *event = data;
3029 struct fb_info *info = event->info;
3030 struct fb_videomode *mode;
3031 struct fb_con2fbmap *con2fb;
3032 int ret = 0;
3033
Antonino A. Daplase614b182006-06-26 00:27:09 -07003034 /*
3035 * ignore all events except driver registration and deregistration
3036 * if fbcon is not active
3037 */
3038 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3039 action == FB_EVENT_FB_UNREGISTERED))
3040 goto done;
3041
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 switch(action) {
3043 case FB_EVENT_SUSPEND:
3044 fbcon_suspended(info);
3045 break;
3046 case FB_EVENT_RESUME:
3047 fbcon_resumed(info);
3048 break;
3049 case FB_EVENT_MODE_CHANGE:
3050 fbcon_modechanged(info);
3051 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003052 case FB_EVENT_MODE_CHANGE_ALL:
3053 fbcon_set_all_vcs(info);
3054 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 case FB_EVENT_MODE_DELETE:
3056 mode = event->data;
3057 ret = fbcon_mode_deleted(info, mode);
3058 break;
3059 case FB_EVENT_FB_REGISTERED:
3060 ret = fbcon_fb_registered(info->node);
3061 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003062 case FB_EVENT_FB_UNREGISTERED:
3063 ret = fbcon_fb_unregistered(info->node);
3064 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 case FB_EVENT_SET_CONSOLE_MAP:
3066 con2fb = event->data;
3067 ret = set_con2fb_map(con2fb->console - 1,
3068 con2fb->framebuffer, 1);
3069 break;
3070 case FB_EVENT_GET_CONSOLE_MAP:
3071 con2fb = event->data;
3072 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3073 break;
3074 case FB_EVENT_BLANK:
3075 fbcon_fb_blanked(info, *(int *)event->data);
3076 break;
3077 case FB_EVENT_NEW_MODELIST:
3078 fbcon_new_modelist(info);
3079 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 }
3081
Antonino A. Daplase614b182006-06-26 00:27:09 -07003082done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 return ret;
3084}
3085
3086/*
3087 * The console `switch' structure for the frame buffer based console
3088 */
3089
3090static const struct consw fb_con = {
3091 .owner = THIS_MODULE,
3092 .con_startup = fbcon_startup,
3093 .con_init = fbcon_init,
3094 .con_deinit = fbcon_deinit,
3095 .con_clear = fbcon_clear,
3096 .con_putc = fbcon_putc,
3097 .con_putcs = fbcon_putcs,
3098 .con_cursor = fbcon_cursor,
3099 .con_scroll = fbcon_scroll,
3100 .con_bmove = fbcon_bmove,
3101 .con_switch = fbcon_switch,
3102 .con_blank = fbcon_blank,
3103 .con_font_set = fbcon_set_font,
3104 .con_font_get = fbcon_get_font,
3105 .con_font_default = fbcon_set_def_font,
3106 .con_font_copy = fbcon_copy_font,
3107 .con_set_palette = fbcon_set_palette,
3108 .con_scrolldelta = fbcon_scrolldelta,
3109 .con_set_origin = fbcon_set_origin,
3110 .con_invert_region = fbcon_invert_region,
3111 .con_screen_pos = fbcon_screen_pos,
3112 .con_getxy = fbcon_getxy,
3113 .con_resize = fbcon_resize,
3114};
3115
3116static struct notifier_block fbcon_event_notifier = {
3117 .notifier_call = fbcon_event_notify,
3118};
3119
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003120static ssize_t store_rotate(struct class_device *class_device,
3121 const char *buf, size_t count)
3122{
3123 struct fb_info *info;
3124 int rotate, idx;
3125 char **last = NULL;
3126
Antonino A. Daplase614b182006-06-26 00:27:09 -07003127 if (fbcon_has_exited)
3128 return count;
3129
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003130 acquire_console_sem();
3131 idx = con2fb_map[fg_console];
3132
3133 if (idx == -1 || registered_fb[idx] == NULL)
3134 goto err;
3135
3136 info = registered_fb[idx];
3137 rotate = simple_strtoul(buf, last, 0);
3138 fbcon_rotate(info, rotate);
3139err:
3140 release_console_sem();
3141 return count;
3142}
3143
3144static ssize_t store_rotate_all(struct class_device *class_device,
3145 const char *buf, size_t count)
3146{
3147 struct fb_info *info;
3148 int rotate, idx;
3149 char **last = NULL;
3150
Antonino A. Daplase614b182006-06-26 00:27:09 -07003151 if (fbcon_has_exited)
3152 return count;
3153
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003154 acquire_console_sem();
3155 idx = con2fb_map[fg_console];
3156
3157 if (idx == -1 || registered_fb[idx] == NULL)
3158 goto err;
3159
3160 info = registered_fb[idx];
3161 rotate = simple_strtoul(buf, last, 0);
3162 fbcon_rotate_all(info, rotate);
3163err:
3164 release_console_sem();
3165 return count;
3166}
3167
3168static ssize_t show_rotate(struct class_device *class_device, char *buf)
3169{
3170 struct fb_info *info;
3171 int rotate = 0, idx;
3172
Antonino A. Daplase614b182006-06-26 00:27:09 -07003173 if (fbcon_has_exited)
3174 return 0;
3175
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003176 acquire_console_sem();
3177 idx = con2fb_map[fg_console];
3178
3179 if (idx == -1 || registered_fb[idx] == NULL)
3180 goto err;
3181
3182 info = registered_fb[idx];
3183 rotate = fbcon_get_rotate(info);
3184err:
3185 release_console_sem();
3186 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3187}
3188
3189static struct class_device_attribute class_device_attrs[] = {
3190 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3191 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3192};
3193
3194static int fbcon_init_class_device(void)
3195{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003196 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003197
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003198 fbcon_has_sysfs = 1;
3199
3200 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3201 error = class_device_create_file(fbcon_class_device,
3202 &class_device_attrs[i]);
3203
3204 if (error)
3205 break;
3206 }
3207
3208 if (error) {
3209 while (--i >= 0)
3210 class_device_remove_file(fbcon_class_device,
3211 &class_device_attrs[i]);
3212
3213 fbcon_has_sysfs = 0;
3214 }
3215
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003216 return 0;
3217}
3218
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003219static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003222 int i;
3223
3224 acquire_console_sem();
3225
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 for (i = 0; i < FB_MAX; i++) {
3227 if (registered_fb[i] != NULL) {
3228 info_idx = i;
3229 break;
3230 }
3231 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003232
3233 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 fbcon_takeover(0);
3235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236}
3237
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003238static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003239{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003240 struct fb_info *info;
3241 int i, j, mapped;
3242
Antonino A. Daplase614b182006-06-26 00:27:09 -07003243 if (fbcon_has_exited)
3244 return;
3245
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003246#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003247 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003248#endif
3249#ifdef CONFIG_MAC
3250 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003251 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003252#endif
3253
3254 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003255 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003256
3257 for (i = 0; i < FB_MAX; i++) {
3258 mapped = 0;
3259 info = registered_fb[i];
3260
3261 if (info == NULL)
3262 continue;
3263
Antonino A. Daplase614b182006-06-26 00:27:09 -07003264 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3265 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003266 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003267 }
3268
3269 if (mapped) {
3270 if (info->fbops->fb_release)
3271 info->fbops->fb_release(info, 0);
3272 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003273
3274 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003275 struct fbcon_ops *ops = info->fbcon_par;
3276
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003277 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003278 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003279 kfree(info->fbcon_par);
3280 info->fbcon_par = NULL;
3281 }
3282
3283 if (info->queue.func == fb_flashcursor)
3284 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003285 }
3286 }
3287
Antonino A. Daplase614b182006-06-26 00:27:09 -07003288 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003289}
3290
3291static int __init fb_console_init(void)
3292{
3293 int i;
3294
3295 acquire_console_sem();
3296 fb_register_client(&fbcon_event_notifier);
3297 fbcon_class_device =
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003298 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003299
3300 if (IS_ERR(fbcon_class_device)) {
3301 printk(KERN_WARNING "Unable to create class_device "
3302 "for fbcon; errno = %ld\n",
3303 PTR_ERR(fbcon_class_device));
3304 fbcon_class_device = NULL;
3305 } else
3306 fbcon_init_class_device();
3307
3308 for (i = 0; i < MAX_NR_CONSOLES; i++)
3309 con2fb_map[i] = -1;
3310
3311 release_console_sem();
3312 fbcon_start();
3313 return 0;
3314}
3315
3316module_init(fb_console_init);
3317
3318#ifdef MODULE
3319
Antonino A. Daplase614b182006-06-26 00:27:09 -07003320static void __exit fbcon_deinit_class_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003321{
3322 int i;
3323
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003324 if (fbcon_has_sysfs) {
3325 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3326 class_device_remove_file(fbcon_class_device,
3327 &class_device_attrs[i]);
3328
3329 fbcon_has_sysfs = 0;
3330 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003331}
3332
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333static void __exit fb_console_exit(void)
3334{
3335 acquire_console_sem();
3336 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003337 fbcon_deinit_class_device();
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003338 class_device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003339 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003341 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342}
3343
3344module_exit(fb_console_exit);
3345
3346#endif
3347
3348MODULE_LICENSE("GPL");