blob: 19dfdfbd434149543fbbf9889042ed969ae3731a [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,
991 info->var.yres);
992 vc->vc_font.width = font->width;
993 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700994 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
996 }
997
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800998 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
999 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1000 cols /= vc->vc_font.width;
1001 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 vc_resize(vc, cols, rows);
1003
1004 DPRINTK("mode: %s\n", info->fix.id);
1005 DPRINTK("visual: %d\n", info->fix.visual);
1006 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1007 info->var.yres,
1008 info->var.bits_per_pixel);
1009
1010#ifdef CONFIG_ATARI
1011 if (MACH_IS_ATARI) {
1012 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1013 irqres =
1014 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1015 IRQ_TYPE_PRIO, "framebuffer vbl",
1016 info);
1017 }
1018#endif /* CONFIG_ATARI */
1019
1020#ifdef CONFIG_MAC
1021 /*
1022 * On a Macintoy, the VBL interrupt may or may not be active.
1023 * As interrupt based cursor is more reliable and race free, we
1024 * probe for VBL interrupts.
1025 */
1026 if (MACH_IS_MAC) {
1027 int ct = 0;
1028 /*
1029 * Probe for VBL: set temp. handler ...
1030 */
1031 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1032 "framebuffer vbl", info);
1033 vbl_detected = 0;
1034
1035 /*
1036 * ... and spin for 20 ms ...
1037 */
1038 while (!vbl_detected && ++ct < 1000)
1039 udelay(20);
1040
1041 if (ct == 1000)
1042 printk
1043 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1044
1045 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1046
1047 if (vbl_detected) {
1048 /*
1049 * interrupt based cursor ok
1050 */
1051 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1052 irqres =
1053 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1054 "framebuffer vbl", info);
1055 } else {
1056 /*
1057 * VBL not detected: fall through, use timer based cursor
1058 */
1059 irqres = 1;
1060 }
1061 }
1062#endif /* CONFIG_MAC */
1063
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001064 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001065 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 return display_desc;
1067}
1068
1069static void fbcon_init(struct vc_data *vc, int init)
1070{
1071 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1072 struct fbcon_ops *ops;
1073 struct vc_data **default_mode = vc->vc_display_fg;
1074 struct vc_data *svc = *default_mode;
1075 struct display *t, *p = &fb_display[vc->vc_num];
1076 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001077 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
1079 if (info_idx == -1 || info == NULL)
1080 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001081
1082 cap = info->flags;
1083
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1085 (info->fix.type == FB_TYPE_TEXT))
1086 logo = 0;
1087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (var_to_display(p, &info->var, info))
1089 return;
1090
1091 /* If we are not the first console on this
1092 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001093 t = &fb_display[fg_console];
1094 if (!p->fontdata) {
1095 if (t->fontdata) {
1096 struct vc_data *fvc = vc_cons[fg_console].d;
1097
1098 vc->vc_font.data = (void *)(p->fontdata =
1099 fvc->vc_font.data);
1100 vc->vc_font.width = fvc->vc_font.width;
1101 vc->vc_font.height = fvc->vc_font.height;
1102 p->userfont = t->userfont;
1103
1104 if (p->userfont)
1105 REFCOUNT(p->fontdata)++;
1106 } else {
1107 const struct font_desc *font = NULL;
1108
1109 if (!fontname[0] || !(font = find_font(fontname)))
1110 font = get_default_font(info->var.xres,
1111 info->var.yres);
1112 vc->vc_font.width = font->width;
1113 vc->vc_font.height = font->height;
1114 vc->vc_font.data = (void *)(p->fontdata = font->data);
1115 vc->vc_font.charcount = 256; /* FIXME Need to
1116 support more fonts */
1117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 if (p->userfont)
1121 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001122
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001123 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1125 if (charcnt == 256) {
1126 vc->vc_hi_font_mask = 0;
1127 } else {
1128 vc->vc_hi_font_mask = 0x100;
1129 if (vc->vc_can_do_color)
1130 vc->vc_complement_mask <<= 1;
1131 }
1132
1133 if (!*svc->vc_uni_pagedir_loc)
1134 con_set_default_unimap(svc);
1135 if (!*vc->vc_uni_pagedir_loc)
1136 con_copy_unimap(vc, svc);
1137
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001138 ops = info->fbcon_par;
1139 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001140 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 cols = vc->vc_cols;
1143 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001144 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1145 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1146 new_cols /= vc->vc_font.width;
1147 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 vc_resize(vc, new_cols, new_rows);
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 /*
1151 * We must always set the mode. The mode of the previous console
1152 * driver could be in the same resolution but we are using different
1153 * hardware so we have to initialize the hardware.
1154 *
1155 * We need to do it in fbcon_init() to prevent screen corruption.
1156 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001157 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 if (info->fbops->fb_set_par &&
1159 !(ops->flags & FBCON_FLAGS_INIT))
1160 info->fbops->fb_set_par(info);
1161 ops->flags |= FBCON_FLAGS_INIT;
1162 }
1163
1164 ops->graphics = 0;
1165
1166 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1167 !(cap & FBINFO_HWACCEL_DISABLED))
1168 p->scrollmode = SCROLL_MOVE;
1169 else /* default to something safe */
1170 p->scrollmode = SCROLL_REDRAW;
1171
1172 /*
1173 * ++guenther: console.c:vc_allocate() relies on initializing
1174 * vc_{cols,rows}, but we must not set those if we are only
1175 * resizing the console.
1176 */
1177 if (!init) {
1178 vc->vc_cols = new_cols;
1179 vc->vc_rows = new_rows;
1180 }
1181
1182 if (logo)
1183 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1184
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001185 if (vc == svc && softback_buf)
1186 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001187
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001188 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001189 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001190 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001191 }
1192
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001193 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
Antonino A. Daplase614b182006-06-26 00:27:09 -07001196static void fbcon_free_font(struct display *p)
1197{
1198 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1199 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1200 p->fontdata = NULL;
1201 p->userfont = 0;
1202}
1203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204static void fbcon_deinit(struct vc_data *vc)
1205{
1206 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001207 struct fb_info *info;
1208 struct fbcon_ops *ops;
1209 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001212 idx = con2fb_map[vc->vc_num];
1213
1214 if (idx == -1)
1215 goto finished;
1216
1217 info = registered_fb[idx];
1218
1219 if (!info)
1220 goto finished;
1221
1222 ops = info->fbcon_par;
1223
1224 if (!ops)
1225 goto finished;
1226
1227 if (CON_IS_VISIBLE(vc))
1228 fbcon_del_cursor_timer(info);
1229
1230 ops->flags &= ~FBCON_FLAGS_INIT;
1231finished:
1232
1233 if (!con_is_bound(&fb_con))
1234 fbcon_exit();
1235
1236 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
1239/* ====================================================================== */
1240
1241/* fbcon_XXX routines - interface used by the world
1242 *
1243 * This system is now divided into two levels because of complications
1244 * caused by hardware scrolling. Top level functions:
1245 *
1246 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1247 *
1248 * handles y values in range [0, scr_height-1] that correspond to real
1249 * screen positions. y_wrap shift means that first line of bitmap may be
1250 * anywhere on this display. These functions convert lineoffsets to
1251 * bitmap offsets and deal with the wrap-around case by splitting blits.
1252 *
1253 * fbcon_bmove_physical_8() -- These functions fast implementations
1254 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1255 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1256 *
1257 * WARNING:
1258 *
1259 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1260 * Implies should only really hardware scroll in rows. Only reason for
1261 * restriction is simplicity & efficiency at the moment.
1262 */
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1265 int width)
1266{
1267 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1268 struct fbcon_ops *ops = info->fbcon_par;
1269
1270 struct display *p = &fb_display[vc->vc_num];
1271 u_int y_break;
1272
1273 if (fbcon_is_inactive(vc, info))
1274 return;
1275
1276 if (!height || !width)
1277 return;
1278
1279 /* Split blits that cross physical y_wrap boundary */
1280
1281 y_break = p->vrows - p->yscroll;
1282 if (sy < y_break && sy + height - 1 >= y_break) {
1283 u_int b = y_break - sy;
1284 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1285 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1286 width);
1287 } else
1288 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1289}
1290
1291static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1292 int count, int ypos, int xpos)
1293{
1294 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1295 struct display *p = &fb_display[vc->vc_num];
1296 struct fbcon_ops *ops = info->fbcon_par;
1297
1298 if (!fbcon_is_inactive(vc, info))
1299 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1300 get_color(vc, info, scr_readw(s), 1),
1301 get_color(vc, info, scr_readw(s), 0));
1302}
1303
1304static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1305{
1306 unsigned short chr;
1307
1308 scr_writew(c, &chr);
1309 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1310}
1311
1312static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1313{
1314 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1315 struct fbcon_ops *ops = info->fbcon_par;
1316
1317 if (!fbcon_is_inactive(vc, info))
1318 ops->clear_margins(vc, info, bottom_only);
1319}
1320
1321static void fbcon_cursor(struct vc_data *vc, int mode)
1322{
1323 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1324 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 int y;
1326 int c = scr_readw((u16 *) vc->vc_pos);
1327
Michal Januszewskid1e23062007-05-08 00:38:07 -07001328 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 return;
1330
1331 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1332 if (mode & CM_SOFTBACK) {
1333 mode &= ~CM_SOFTBACK;
1334 y = softback_lines;
1335 } else {
1336 if (softback_lines)
1337 fbcon_set_origin(vc);
1338 y = 0;
1339 }
1340
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001341 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 get_color(vc, info, c, 0));
1343 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1344}
1345
1346static int scrollback_phys_max = 0;
1347static int scrollback_max = 0;
1348static int scrollback_current = 0;
1349
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350/*
1351 * If no vc is existent yet, just set struct display
1352 */
1353static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1354 int unit)
1355{
1356 struct display *p = &fb_display[unit];
1357 struct display *t = &fb_display[fg_console];
1358
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 if (var_to_display(p, var, info))
1360 return;
1361
1362 p->fontdata = t->fontdata;
1363 p->userfont = t->userfont;
1364 if (p->userfont)
1365 REFCOUNT(p->fontdata)++;
1366}
1367
1368static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1369 struct vc_data *vc)
1370{
1371 struct display *p = &fb_display[vc->vc_num], *t;
1372 struct vc_data **default_mode = vc->vc_display_fg;
1373 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001374 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 int rows, cols, charcnt = 256;
1376
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 if (var_to_display(p, var, info))
1378 return;
1379 t = &fb_display[svc->vc_num];
1380 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001381 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 vc->vc_font.width = (*default_mode)->vc_font.width;
1383 vc->vc_font.height = (*default_mode)->vc_font.height;
1384 p->userfont = t->userfont;
1385 if (p->userfont)
1386 REFCOUNT(p->fontdata)++;
1387 }
1388 if (p->userfont)
1389 charcnt = FNTCHARCNT(p->fontdata);
1390
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001391 var->activate = FB_ACTIVATE_NOW;
1392 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001393 var->yoffset = info->var.yoffset;
1394 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001395 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001396 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001397 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1399 if (charcnt == 256) {
1400 vc->vc_hi_font_mask = 0;
1401 } else {
1402 vc->vc_hi_font_mask = 0x100;
1403 if (vc->vc_can_do_color)
1404 vc->vc_complement_mask <<= 1;
1405 }
1406
1407 if (!*svc->vc_uni_pagedir_loc)
1408 con_set_default_unimap(svc);
1409 if (!*vc->vc_uni_pagedir_loc)
1410 con_copy_unimap(vc, svc);
1411
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001412 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1413 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1414 cols /= vc->vc_font.width;
1415 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 if (CON_IS_VISIBLE(vc)) {
1419 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001420 if (softback_buf)
1421 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423}
1424
1425static __inline__ void ywrap_up(struct vc_data *vc, int count)
1426{
1427 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001428 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 struct display *p = &fb_display[vc->vc_num];
1430
1431 p->yscroll += count;
1432 if (p->yscroll >= p->vrows) /* Deal with wrap */
1433 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001434 ops->var.xoffset = 0;
1435 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1436 ops->var.vmode |= FB_VMODE_YWRAP;
1437 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 scrollback_max += count;
1439 if (scrollback_max > scrollback_phys_max)
1440 scrollback_max = scrollback_phys_max;
1441 scrollback_current = 0;
1442}
1443
1444static __inline__ void ywrap_down(struct vc_data *vc, int count)
1445{
1446 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001447 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 struct display *p = &fb_display[vc->vc_num];
1449
1450 p->yscroll -= count;
1451 if (p->yscroll < 0) /* Deal with wrap */
1452 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001453 ops->var.xoffset = 0;
1454 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1455 ops->var.vmode |= FB_VMODE_YWRAP;
1456 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 scrollback_max -= count;
1458 if (scrollback_max < 0)
1459 scrollback_max = 0;
1460 scrollback_current = 0;
1461}
1462
1463static __inline__ void ypan_up(struct vc_data *vc, int count)
1464{
1465 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1466 struct display *p = &fb_display[vc->vc_num];
1467 struct fbcon_ops *ops = info->fbcon_par;
1468
1469 p->yscroll += count;
1470 if (p->yscroll > p->vrows - vc->vc_rows) {
1471 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1472 0, 0, 0, vc->vc_rows, vc->vc_cols);
1473 p->yscroll -= p->vrows - vc->vc_rows;
1474 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001475
1476 ops->var.xoffset = 0;
1477 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1478 ops->var.vmode &= ~FB_VMODE_YWRAP;
1479 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 fbcon_clear_margins(vc, 1);
1481 scrollback_max += count;
1482 if (scrollback_max > scrollback_phys_max)
1483 scrollback_max = scrollback_phys_max;
1484 scrollback_current = 0;
1485}
1486
1487static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1488{
1489 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001490 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if (p->yscroll > p->vrows - vc->vc_rows) {
1496 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001498 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001499
1500 ops->var.xoffset = 0;
1501 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1502 ops->var.vmode &= ~FB_VMODE_YWRAP;
1503 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 fbcon_clear_margins(vc, 1);
1505 scrollback_max += count;
1506 if (scrollback_max > scrollback_phys_max)
1507 scrollback_max = scrollback_phys_max;
1508 scrollback_current = 0;
1509}
1510
1511static __inline__ void ypan_down(struct vc_data *vc, int count)
1512{
1513 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1514 struct display *p = &fb_display[vc->vc_num];
1515 struct fbcon_ops *ops = info->fbcon_par;
1516
1517 p->yscroll -= count;
1518 if (p->yscroll < 0) {
1519 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1520 0, vc->vc_rows, vc->vc_cols);
1521 p->yscroll += p->vrows - vc->vc_rows;
1522 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001523
1524 ops->var.xoffset = 0;
1525 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1526 ops->var.vmode &= ~FB_VMODE_YWRAP;
1527 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 fbcon_clear_margins(vc, 1);
1529 scrollback_max -= count;
1530 if (scrollback_max < 0)
1531 scrollback_max = 0;
1532 scrollback_current = 0;
1533}
1534
1535static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1536{
1537 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001538 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001542
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 if (p->yscroll < 0) {
1544 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001546 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001547
1548 ops->var.xoffset = 0;
1549 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1550 ops->var.vmode &= ~FB_VMODE_YWRAP;
1551 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 fbcon_clear_margins(vc, 1);
1553 scrollback_max -= count;
1554 if (scrollback_max < 0)
1555 scrollback_max = 0;
1556 scrollback_current = 0;
1557}
1558
1559static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1560 long delta)
1561{
1562 int count = vc->vc_rows;
1563 unsigned short *d, *s;
1564 unsigned long n;
1565 int line = 0;
1566
1567 d = (u16 *) softback_curr;
1568 if (d == (u16 *) softback_in)
1569 d = (u16 *) vc->vc_origin;
1570 n = softback_curr + delta * vc->vc_size_row;
1571 softback_lines -= delta;
1572 if (delta < 0) {
1573 if (softback_curr < softback_top && n < softback_buf) {
1574 n += softback_end - softback_buf;
1575 if (n < softback_top) {
1576 softback_lines -=
1577 (softback_top - n) / vc->vc_size_row;
1578 n = softback_top;
1579 }
1580 } else if (softback_curr >= softback_top
1581 && n < softback_top) {
1582 softback_lines -=
1583 (softback_top - n) / vc->vc_size_row;
1584 n = softback_top;
1585 }
1586 } else {
1587 if (softback_curr > softback_in && n >= softback_end) {
1588 n += softback_buf - softback_end;
1589 if (n > softback_in) {
1590 n = softback_in;
1591 softback_lines = 0;
1592 }
1593 } else if (softback_curr <= softback_in && n > softback_in) {
1594 n = softback_in;
1595 softback_lines = 0;
1596 }
1597 }
1598 if (n == softback_curr)
1599 return;
1600 softback_curr = n;
1601 s = (u16 *) softback_curr;
1602 if (s == (u16 *) softback_in)
1603 s = (u16 *) vc->vc_origin;
1604 while (count--) {
1605 unsigned short *start;
1606 unsigned short *le;
1607 unsigned short c;
1608 int x = 0;
1609 unsigned short attr = 1;
1610
1611 start = s;
1612 le = advance_row(s, 1);
1613 do {
1614 c = scr_readw(s);
1615 if (attr != (c & 0xff00)) {
1616 attr = c & 0xff00;
1617 if (s > start) {
1618 fbcon_putcs(vc, start, s - start,
1619 line, x);
1620 x += s - start;
1621 start = s;
1622 }
1623 }
1624 if (c == scr_readw(d)) {
1625 if (s > start) {
1626 fbcon_putcs(vc, start, s - start,
1627 line, x);
1628 x += s - start + 1;
1629 start = s + 1;
1630 } else {
1631 x++;
1632 start++;
1633 }
1634 }
1635 s++;
1636 d++;
1637 } while (s < le);
1638 if (s > start)
1639 fbcon_putcs(vc, start, s - start, line, x);
1640 line++;
1641 if (d == (u16 *) softback_end)
1642 d = (u16 *) softback_buf;
1643 if (d == (u16 *) softback_in)
1644 d = (u16 *) vc->vc_origin;
1645 if (s == (u16 *) softback_end)
1646 s = (u16 *) softback_buf;
1647 if (s == (u16 *) softback_in)
1648 s = (u16 *) vc->vc_origin;
1649 }
1650}
1651
1652static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1653 int line, int count, int dy)
1654{
1655 unsigned short *s = (unsigned short *)
1656 (vc->vc_origin + vc->vc_size_row * line);
1657
1658 while (count--) {
1659 unsigned short *start = s;
1660 unsigned short *le = advance_row(s, 1);
1661 unsigned short c;
1662 int x = 0;
1663 unsigned short attr = 1;
1664
1665 do {
1666 c = scr_readw(s);
1667 if (attr != (c & 0xff00)) {
1668 attr = c & 0xff00;
1669 if (s > start) {
1670 fbcon_putcs(vc, start, s - start,
1671 dy, x);
1672 x += s - start;
1673 start = s;
1674 }
1675 }
1676 console_conditional_schedule();
1677 s++;
1678 } while (s < le);
1679 if (s > start)
1680 fbcon_putcs(vc, start, s - start, dy, x);
1681 console_conditional_schedule();
1682 dy++;
1683 }
1684}
1685
1686static void fbcon_redraw(struct vc_data *vc, struct display *p,
1687 int line, int count, int offset)
1688{
1689 unsigned short *d = (unsigned short *)
1690 (vc->vc_origin + vc->vc_size_row * line);
1691 unsigned short *s = d + offset;
1692
1693 while (count--) {
1694 unsigned short *start = s;
1695 unsigned short *le = advance_row(s, 1);
1696 unsigned short c;
1697 int x = 0;
1698 unsigned short attr = 1;
1699
1700 do {
1701 c = scr_readw(s);
1702 if (attr != (c & 0xff00)) {
1703 attr = c & 0xff00;
1704 if (s > start) {
1705 fbcon_putcs(vc, start, s - start,
1706 line, x);
1707 x += s - start;
1708 start = s;
1709 }
1710 }
1711 if (c == scr_readw(d)) {
1712 if (s > start) {
1713 fbcon_putcs(vc, start, s - start,
1714 line, x);
1715 x += s - start + 1;
1716 start = s + 1;
1717 } else {
1718 x++;
1719 start++;
1720 }
1721 }
1722 scr_writew(c, d);
1723 console_conditional_schedule();
1724 s++;
1725 d++;
1726 } while (s < le);
1727 if (s > start)
1728 fbcon_putcs(vc, start, s - start, line, x);
1729 console_conditional_schedule();
1730 if (offset > 0)
1731 line++;
1732 else {
1733 line--;
1734 /* NOTE: We subtract two lines from these pointers */
1735 s -= vc->vc_size_row;
1736 d -= vc->vc_size_row;
1737 }
1738 }
1739}
1740
1741static inline void fbcon_softback_note(struct vc_data *vc, int t,
1742 int count)
1743{
1744 unsigned short *p;
1745
1746 if (vc->vc_num != fg_console)
1747 return;
1748 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1749
1750 while (count) {
1751 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1752 count--;
1753 p = advance_row(p, 1);
1754 softback_in += vc->vc_size_row;
1755 if (softback_in == softback_end)
1756 softback_in = softback_buf;
1757 if (softback_in == softback_top) {
1758 softback_top += vc->vc_size_row;
1759 if (softback_top == softback_end)
1760 softback_top = softback_buf;
1761 }
1762 }
1763 softback_curr = softback_in;
1764}
1765
1766static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1767 int count)
1768{
1769 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1770 struct display *p = &fb_display[vc->vc_num];
1771 struct fbcon_ops *ops = info->fbcon_par;
1772 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1773
1774 if (fbcon_is_inactive(vc, info))
1775 return -EINVAL;
1776
1777 fbcon_cursor(vc, CM_ERASE);
1778
1779 /*
1780 * ++Geert: Only use ywrap/ypan if the console is in text mode
1781 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1782 * whole screen (prevents flicker).
1783 */
1784
1785 switch (dir) {
1786 case SM_UP:
1787 if (count > vc->vc_rows) /* Maximum realistic size */
1788 count = vc->vc_rows;
1789 if (softback_top)
1790 fbcon_softback_note(vc, t, count);
1791 if (logo_shown >= 0)
1792 goto redraw_up;
1793 switch (p->scrollmode) {
1794 case SCROLL_MOVE:
1795 ops->bmove(vc, info, t + count, 0, t, 0,
1796 b - t - count, vc->vc_cols);
1797 ops->clear(vc, info, b - count, 0, count,
1798 vc->vc_cols);
1799 break;
1800
1801 case SCROLL_WRAP_MOVE:
1802 if (b - t - count > 3 * vc->vc_rows >> 2) {
1803 if (t > 0)
1804 fbcon_bmove(vc, 0, 0, count, 0, t,
1805 vc->vc_cols);
1806 ywrap_up(vc, count);
1807 if (vc->vc_rows - b > 0)
1808 fbcon_bmove(vc, b - count, 0, b, 0,
1809 vc->vc_rows - b,
1810 vc->vc_cols);
1811 } else if (info->flags & FBINFO_READS_FAST)
1812 fbcon_bmove(vc, t + count, 0, t, 0,
1813 b - t - count, vc->vc_cols);
1814 else
1815 goto redraw_up;
1816 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1817 break;
1818
1819 case SCROLL_PAN_REDRAW:
1820 if ((p->yscroll + count <=
1821 2 * (p->vrows - vc->vc_rows))
1822 && ((!scroll_partial && (b - t == vc->vc_rows))
1823 || (scroll_partial
1824 && (b - t - count >
1825 3 * vc->vc_rows >> 2)))) {
1826 if (t > 0)
1827 fbcon_redraw_move(vc, p, 0, t, count);
1828 ypan_up_redraw(vc, t, count);
1829 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001830 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 vc->vc_rows - b, b);
1832 } else
1833 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1834 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1835 break;
1836
1837 case SCROLL_PAN_MOVE:
1838 if ((p->yscroll + count <=
1839 2 * (p->vrows - vc->vc_rows))
1840 && ((!scroll_partial && (b - t == vc->vc_rows))
1841 || (scroll_partial
1842 && (b - t - count >
1843 3 * vc->vc_rows >> 2)))) {
1844 if (t > 0)
1845 fbcon_bmove(vc, 0, 0, count, 0, t,
1846 vc->vc_cols);
1847 ypan_up(vc, count);
1848 if (vc->vc_rows - b > 0)
1849 fbcon_bmove(vc, b - count, 0, b, 0,
1850 vc->vc_rows - b,
1851 vc->vc_cols);
1852 } else if (info->flags & FBINFO_READS_FAST)
1853 fbcon_bmove(vc, t + count, 0, t, 0,
1854 b - t - count, vc->vc_cols);
1855 else
1856 goto redraw_up;
1857 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1858 break;
1859
1860 case SCROLL_REDRAW:
1861 redraw_up:
1862 fbcon_redraw(vc, p, t, b - t - count,
1863 count * vc->vc_cols);
1864 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1865 scr_memsetw((unsigned short *) (vc->vc_origin +
1866 vc->vc_size_row *
1867 (b - count)),
1868 vc->vc_video_erase_char,
1869 vc->vc_size_row * count);
1870 return 1;
1871 }
1872 break;
1873
1874 case SM_DOWN:
1875 if (count > vc->vc_rows) /* Maximum realistic size */
1876 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001877 if (logo_shown >= 0)
1878 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 switch (p->scrollmode) {
1880 case SCROLL_MOVE:
1881 ops->bmove(vc, info, t, 0, t + count, 0,
1882 b - t - count, vc->vc_cols);
1883 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1884 break;
1885
1886 case SCROLL_WRAP_MOVE:
1887 if (b - t - count > 3 * vc->vc_rows >> 2) {
1888 if (vc->vc_rows - b > 0)
1889 fbcon_bmove(vc, b, 0, b - count, 0,
1890 vc->vc_rows - b,
1891 vc->vc_cols);
1892 ywrap_down(vc, count);
1893 if (t > 0)
1894 fbcon_bmove(vc, count, 0, 0, 0, t,
1895 vc->vc_cols);
1896 } else if (info->flags & FBINFO_READS_FAST)
1897 fbcon_bmove(vc, t, 0, t + count, 0,
1898 b - t - count, vc->vc_cols);
1899 else
1900 goto redraw_down;
1901 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1902 break;
1903
1904 case SCROLL_PAN_MOVE:
1905 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1906 && ((!scroll_partial && (b - t == vc->vc_rows))
1907 || (scroll_partial
1908 && (b - t - count >
1909 3 * vc->vc_rows >> 2)))) {
1910 if (vc->vc_rows - b > 0)
1911 fbcon_bmove(vc, b, 0, b - count, 0,
1912 vc->vc_rows - b,
1913 vc->vc_cols);
1914 ypan_down(vc, count);
1915 if (t > 0)
1916 fbcon_bmove(vc, count, 0, 0, 0, t,
1917 vc->vc_cols);
1918 } else if (info->flags & FBINFO_READS_FAST)
1919 fbcon_bmove(vc, t, 0, t + count, 0,
1920 b - t - count, vc->vc_cols);
1921 else
1922 goto redraw_down;
1923 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1924 break;
1925
1926 case SCROLL_PAN_REDRAW:
1927 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1928 && ((!scroll_partial && (b - t == vc->vc_rows))
1929 || (scroll_partial
1930 && (b - t - count >
1931 3 * vc->vc_rows >> 2)))) {
1932 if (vc->vc_rows - b > 0)
1933 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1934 b - count);
1935 ypan_down_redraw(vc, t, count);
1936 if (t > 0)
1937 fbcon_redraw_move(vc, p, count, t, 0);
1938 } else
1939 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1940 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1941 break;
1942
1943 case SCROLL_REDRAW:
1944 redraw_down:
1945 fbcon_redraw(vc, p, b - 1, b - t - count,
1946 -count * vc->vc_cols);
1947 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1948 scr_memsetw((unsigned short *) (vc->vc_origin +
1949 vc->vc_size_row *
1950 t),
1951 vc->vc_video_erase_char,
1952 vc->vc_size_row * count);
1953 return 1;
1954 }
1955 }
1956 return 0;
1957}
1958
1959
1960static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1961 int height, int width)
1962{
1963 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1964 struct display *p = &fb_display[vc->vc_num];
1965
1966 if (fbcon_is_inactive(vc, info))
1967 return;
1968
1969 if (!width || !height)
1970 return;
1971
1972 /* Split blits that cross physical y_wrap case.
1973 * Pathological case involves 4 blits, better to use recursive
1974 * code rather than unrolled case
1975 *
1976 * Recursive invocations don't need to erase the cursor over and
1977 * over again, so we use fbcon_bmove_rec()
1978 */
1979 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1980 p->vrows - p->yscroll);
1981}
1982
1983static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1984 int dy, int dx, int height, int width, u_int y_break)
1985{
1986 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1987 struct fbcon_ops *ops = info->fbcon_par;
1988 u_int b;
1989
1990 if (sy < y_break && sy + height > y_break) {
1991 b = y_break - sy;
1992 if (dy < sy) { /* Avoid trashing self */
1993 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1994 y_break);
1995 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1996 height - b, width, y_break);
1997 } else {
1998 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1999 height - b, width, y_break);
2000 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2001 y_break);
2002 }
2003 return;
2004 }
2005
2006 if (dy < y_break && dy + height > y_break) {
2007 b = y_break - dy;
2008 if (dy < sy) { /* Avoid trashing self */
2009 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2010 y_break);
2011 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2012 height - b, width, y_break);
2013 } else {
2014 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2015 height - b, width, y_break);
2016 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2017 y_break);
2018 }
2019 return;
2020 }
2021 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2022 height, width);
2023}
2024
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002025static __inline__ void updatescrollmode(struct display *p,
2026 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 struct vc_data *vc)
2028{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002029 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 int fh = vc->vc_font.height;
2031 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002032 u16 t = 0;
2033 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2034 info->fix.xpanstep);
2035 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2036 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2037 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2038 info->var.xres_virtual);
2039 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2040 divides(ypan, vc->vc_font.height) && vyres > yres;
2041 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2042 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002043 divides(vc->vc_font.height, vyres) &&
2044 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002046 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2047 !(cap & FBINFO_HWACCEL_DISABLED);
2048 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2049 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002051 p->vrows = vyres/fh;
2052 if (yres > (fh * (vc->vc_rows + 1)))
2053 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2054 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 p->vrows--;
2056
2057 if (good_wrap || good_pan) {
2058 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002059 p->scrollmode = good_wrap ?
2060 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 else
2062 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2063 SCROLL_PAN_REDRAW;
2064 } else {
2065 if (reading_fast || (fast_copyarea && !fast_imageblit))
2066 p->scrollmode = SCROLL_MOVE;
2067 else
2068 p->scrollmode = SCROLL_REDRAW;
2069 }
2070}
2071
2072static int fbcon_resize(struct vc_data *vc, unsigned int width,
2073 unsigned int height)
2074{
2075 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002076 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 struct display *p = &fb_display[vc->vc_num];
2078 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002079 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002081 virt_w = FBCON_SWAP(ops->rotate, width, height);
2082 virt_h = FBCON_SWAP(ops->rotate, height, width);
2083 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2084 vc->vc_font.height);
2085 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2086 vc->vc_font.width);
2087 var.xres = virt_w * virt_fw;
2088 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 x_diff = info->var.xres - var.xres;
2090 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002091 if (x_diff < 0 || x_diff > virt_fw ||
2092 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002093 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2096 mode = fb_find_best_mode(&var, &info->modelist);
2097 if (mode == NULL)
2098 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002099 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002101
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002102 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2106 if (CON_IS_VISIBLE(vc)) {
2107 var.activate = FB_ACTIVATE_NOW |
2108 FB_ACTIVATE_FORCE;
2109 fb_set_var(info, &var);
2110 }
2111 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002112 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 }
2114 updatescrollmode(p, info, vc);
2115 return 0;
2116}
2117
2118static int fbcon_switch(struct vc_data *vc)
2119{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002120 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002121 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 struct display *p = &fb_display[vc->vc_num];
2123 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002124 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
2126 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002127 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
2129 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 if (softback_lines)
2131 fbcon_set_origin(vc);
2132 softback_top = softback_curr = softback_in = softback_buf;
2133 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002134 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 }
2136
2137 if (logo_shown >= 0) {
2138 struct vc_data *conp2 = vc_cons[logo_shown].d;
2139
2140 if (conp2->vc_top == logo_lines
2141 && conp2->vc_bottom == conp2->vc_rows)
2142 conp2->vc_top = 0;
2143 logo_shown = FBCON_LOGO_CANSHOW;
2144 }
2145
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002146 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002147 if (prev_console != -1)
2148 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 /*
2150 * FIXME: If we have multiple fbdev's loaded, we need to
2151 * update all info->currcon. Perhaps, we can place this
2152 * in a centralized structure, but this might break some
2153 * drivers.
2154 *
2155 * info->currcon = vc->vc_num;
2156 */
2157 for (i = 0; i < FB_MAX; i++) {
2158 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002159 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002161 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 }
2163 }
2164 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2165 display_to_var(&var, p);
2166 var.activate = FB_ACTIVATE_NOW;
2167
2168 /*
2169 * make sure we don't unnecessarily trip the memcmp()
2170 * in fb_set_var()
2171 */
2172 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002173 var.yoffset = info->var.yoffset;
2174 var.xoffset = info->var.xoffset;
2175 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002177 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Knut Petersen39942fd2005-12-12 22:17:19 -08002179 if (old_info != NULL && (old_info != info ||
2180 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002181 if (info->fbops->fb_set_par)
2182 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002183
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002184 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002185 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002188 if (fbcon_is_inactive(vc, info) ||
2189 ops->blank_state != FB_BLANK_UNBLANK)
2190 fbcon_del_cursor_timer(info);
2191 else
2192 fbcon_add_cursor_timer(info);
2193
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002194 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002195 ops->cursor_reset = 1;
2196
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002197 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002198 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002199 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002202 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002204
2205 if (p->userfont)
2206 charcnt = FNTCHARCNT(vc->vc_font.data);
2207
2208 if (charcnt > 256)
2209 vc->vc_complement_mask <<= 1;
2210
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 updatescrollmode(p, info, vc);
2212
2213 switch (p->scrollmode) {
2214 case SCROLL_WRAP_MOVE:
2215 scrollback_phys_max = p->vrows - vc->vc_rows;
2216 break;
2217 case SCROLL_PAN_MOVE:
2218 case SCROLL_PAN_REDRAW:
2219 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2220 if (scrollback_phys_max < 0)
2221 scrollback_phys_max = 0;
2222 break;
2223 default:
2224 scrollback_phys_max = 0;
2225 break;
2226 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002227
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 scrollback_max = 0;
2229 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002230
2231 if (!fbcon_is_inactive(vc, info)) {
2232 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2233 ops->update_start(info);
2234 }
2235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 fbcon_set_palette(vc, color_table);
2237 fbcon_clear_margins(vc, 0);
2238
2239 if (logo_shown == FBCON_LOGO_DRAW) {
2240
2241 logo_shown = fg_console;
2242 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002243 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 update_region(vc,
2245 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2246 vc->vc_size_row * (vc->vc_bottom -
2247 vc->vc_top) / 2);
2248 return 0;
2249 }
2250 return 1;
2251}
2252
2253static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2254 int blank)
2255{
Richard Purdie994efac2007-02-09 09:46:45 +00002256 struct fb_event event;
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 if (blank) {
2259 unsigned short charmask = vc->vc_hi_font_mask ?
2260 0x1ff : 0xff;
2261 unsigned short oldc;
2262
2263 oldc = vc->vc_video_erase_char;
2264 vc->vc_video_erase_char &= charmask;
2265 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2266 vc->vc_video_erase_char = oldc;
2267 }
Richard Purdie994efac2007-02-09 09:46:45 +00002268
2269
2270 event.info = info;
2271 event.data = &blank;
2272 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2276{
2277 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2278 struct fbcon_ops *ops = info->fbcon_par;
2279
2280 if (mode_switch) {
2281 struct fb_var_screeninfo var = info->var;
2282
2283 ops->graphics = 1;
2284
2285 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002286 if (info->fbops->fb_save_state)
2287 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2289 fb_set_var(info, &var);
2290 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002291 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002292 } else if (info->fbops->fb_restore_state)
2293 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 }
2295
2296 if (!fbcon_is_inactive(vc, info)) {
2297 if (ops->blank_state != blank) {
2298 ops->blank_state = blank;
2299 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2300 ops->cursor_flash = (!blank);
2301
2302 if (fb_blank(info, blank))
2303 fbcon_generic_blank(vc, info, blank);
2304 }
2305
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002306 if (!blank)
2307 update_screen(vc);
2308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002310 if (fbcon_is_inactive(vc, info) ||
2311 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002312 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002313 else
2314 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002315
2316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2320{
2321 u8 *fontdata = vc->vc_font.data;
2322 u8 *data = font->data;
2323 int i, j;
2324
2325 font->width = vc->vc_font.width;
2326 font->height = vc->vc_font.height;
2327 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2328 if (!font->data)
2329 return 0;
2330
2331 if (font->width <= 8) {
2332 j = vc->vc_font.height;
2333 for (i = 0; i < font->charcount; i++) {
2334 memcpy(data, fontdata, j);
2335 memset(data + j, 0, 32 - j);
2336 data += 32;
2337 fontdata += j;
2338 }
2339 } else if (font->width <= 16) {
2340 j = vc->vc_font.height * 2;
2341 for (i = 0; i < font->charcount; i++) {
2342 memcpy(data, fontdata, j);
2343 memset(data + j, 0, 64 - j);
2344 data += 64;
2345 fontdata += j;
2346 }
2347 } else if (font->width <= 24) {
2348 for (i = 0; i < font->charcount; i++) {
2349 for (j = 0; j < vc->vc_font.height; j++) {
2350 *data++ = fontdata[0];
2351 *data++ = fontdata[1];
2352 *data++ = fontdata[2];
2353 fontdata += sizeof(u32);
2354 }
2355 memset(data, 0, 3 * (32 - j));
2356 data += 3 * (32 - j);
2357 }
2358 } else {
2359 j = vc->vc_font.height * 4;
2360 for (i = 0; i < font->charcount; i++) {
2361 memcpy(data, fontdata, j);
2362 memset(data + j, 0, 128 - j);
2363 data += 128;
2364 fontdata += j;
2365 }
2366 }
2367 return 0;
2368}
2369
2370static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002371 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
2373 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002374 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 struct display *p = &fb_display[vc->vc_num];
2376 int resize;
2377 int cnt;
2378 char *old_data = NULL;
2379
2380 if (CON_IS_VISIBLE(vc) && softback_lines)
2381 fbcon_set_origin(vc);
2382
2383 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2384 if (p->userfont)
2385 old_data = vc->vc_font.data;
2386 if (userfont)
2387 cnt = FNTCHARCNT(data);
2388 else
2389 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002390 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 if ((p->userfont = userfont))
2392 REFCOUNT(data)++;
2393 vc->vc_font.width = w;
2394 vc->vc_font.height = h;
2395 if (vc->vc_hi_font_mask && cnt == 256) {
2396 vc->vc_hi_font_mask = 0;
2397 if (vc->vc_can_do_color) {
2398 vc->vc_complement_mask >>= 1;
2399 vc->vc_s_complement_mask >>= 1;
2400 }
2401
2402 /* ++Edmund: reorder the attribute bits */
2403 if (vc->vc_can_do_color) {
2404 unsigned short *cp =
2405 (unsigned short *) vc->vc_origin;
2406 int count = vc->vc_screenbuf_size / 2;
2407 unsigned short c;
2408 for (; count > 0; count--, cp++) {
2409 c = scr_readw(cp);
2410 scr_writew(((c & 0xfe00) >> 1) |
2411 (c & 0xff), cp);
2412 }
2413 c = vc->vc_video_erase_char;
2414 vc->vc_video_erase_char =
2415 ((c & 0xfe00) >> 1) | (c & 0xff);
2416 vc->vc_attr >>= 1;
2417 }
2418 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2419 vc->vc_hi_font_mask = 0x100;
2420 if (vc->vc_can_do_color) {
2421 vc->vc_complement_mask <<= 1;
2422 vc->vc_s_complement_mask <<= 1;
2423 }
2424
2425 /* ++Edmund: reorder the attribute bits */
2426 {
2427 unsigned short *cp =
2428 (unsigned short *) vc->vc_origin;
2429 int count = vc->vc_screenbuf_size / 2;
2430 unsigned short c;
2431 for (; count > 0; count--, cp++) {
2432 unsigned short newc;
2433 c = scr_readw(cp);
2434 if (vc->vc_can_do_color)
2435 newc =
2436 ((c & 0xff00) << 1) | (c &
2437 0xff);
2438 else
2439 newc = c & ~0x100;
2440 scr_writew(newc, cp);
2441 }
2442 c = vc->vc_video_erase_char;
2443 if (vc->vc_can_do_color) {
2444 vc->vc_video_erase_char =
2445 ((c & 0xff00) << 1) | (c & 0xff);
2446 vc->vc_attr <<= 1;
2447 } else
2448 vc->vc_video_erase_char = c & ~0x100;
2449 }
2450
2451 }
2452
2453 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002454 int cols, rows;
2455
2456 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2457 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2458 cols /= w;
2459 rows /= h;
2460 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002461 if (CON_IS_VISIBLE(vc) && softback_buf)
2462 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 } else if (CON_IS_VISIBLE(vc)
2464 && vc->vc_mode == KD_TEXT) {
2465 fbcon_clear_margins(vc, 0);
2466 update_screen(vc);
2467 }
2468
2469 if (old_data && (--REFCOUNT(old_data) == 0))
2470 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2471 return 0;
2472}
2473
2474static int fbcon_copy_font(struct vc_data *vc, int con)
2475{
2476 struct display *od = &fb_display[con];
2477 struct console_font *f = &vc->vc_font;
2478
2479 if (od->fontdata == f->data)
2480 return 0; /* already the same font... */
2481 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2482}
2483
2484/*
2485 * User asked to set font; we are guaranteed that
2486 * a) width and height are in range 1..32
2487 * b) charcount does not exceed 512
2488 * but lets not assume that, since someone might someday want to use larger
2489 * fonts. And charcount of 512 is small for unicode support.
2490 *
2491 * However, user space gives the font in 32 rows , regardless of
2492 * actual font height. So a new API is needed if support for larger fonts
2493 * is ever implemented.
2494 */
2495
2496static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2497{
2498 unsigned charcount = font->charcount;
2499 int w = font->width;
2500 int h = font->height;
2501 int size;
2502 int i, csum;
2503 u8 *new_data, *data = font->data;
2504 int pitch = (font->width+7) >> 3;
2505
2506 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2507 * If not this check should be changed to charcount < 256 */
2508 if (charcount != 256 && charcount != 512)
2509 return -EINVAL;
2510
2511 size = h * pitch * charcount;
2512
2513 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2514
2515 if (!new_data)
2516 return -ENOMEM;
2517
2518 new_data += FONT_EXTRA_WORDS * sizeof(int);
2519 FNTSIZE(new_data) = size;
2520 FNTCHARCNT(new_data) = charcount;
2521 REFCOUNT(new_data) = 0; /* usage counter */
2522 for (i=0; i< charcount; i++) {
2523 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2524 }
2525
2526 /* Since linux has a nice crc32 function use it for counting font
2527 * checksums. */
2528 csum = crc32(0, new_data, size);
2529
2530 FNTSUM(new_data) = csum;
2531 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002532 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 struct vc_data *tmp = vc_cons[i].d;
2534
2535 if (fb_display[i].userfont &&
2536 fb_display[i].fontdata &&
2537 FNTSUM(fb_display[i].fontdata) == csum &&
2538 FNTSIZE(fb_display[i].fontdata) == size &&
2539 tmp->vc_font.width == w &&
2540 !memcmp(fb_display[i].fontdata, new_data, size)) {
2541 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002542 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 break;
2544 }
2545 }
2546 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2547}
2548
2549static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2550{
2551 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002552 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 if (!name)
2555 f = get_default_font(info->var.xres, info->var.yres);
2556 else if (!(f = find_font(name)))
2557 return -ENOENT;
2558
2559 font->width = f->width;
2560 font->height = f->height;
2561 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2562}
2563
2564static u16 palette_red[16];
2565static u16 palette_green[16];
2566static u16 palette_blue[16];
2567
2568static struct fb_cmap palette_cmap = {
2569 0, 16, palette_red, palette_green, palette_blue, NULL
2570};
2571
2572static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2573{
2574 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2575 int i, j, k, depth;
2576 u8 val;
2577
2578 if (fbcon_is_inactive(vc, info))
2579 return -EINVAL;
2580
2581 if (!CON_IS_VISIBLE(vc))
2582 return 0;
2583
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002584 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 if (depth > 3) {
2586 for (i = j = 0; i < 16; i++) {
2587 k = table[i];
2588 val = vc->vc_palette[j++];
2589 palette_red[k] = (val << 8) | val;
2590 val = vc->vc_palette[j++];
2591 palette_green[k] = (val << 8) | val;
2592 val = vc->vc_palette[j++];
2593 palette_blue[k] = (val << 8) | val;
2594 }
2595 palette_cmap.len = 16;
2596 palette_cmap.start = 0;
2597 /*
2598 * If framebuffer is capable of less than 16 colors,
2599 * use default palette of fbcon.
2600 */
2601 } else
2602 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2603
2604 return fb_set_cmap(&palette_cmap, info);
2605}
2606
2607static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2608{
2609 unsigned long p;
2610 int line;
2611
2612 if (vc->vc_num != fg_console || !softback_lines)
2613 return (u16 *) (vc->vc_origin + offset);
2614 line = offset / vc->vc_size_row;
2615 if (line >= softback_lines)
2616 return (u16 *) (vc->vc_origin + offset -
2617 softback_lines * vc->vc_size_row);
2618 p = softback_curr + offset;
2619 if (p >= softback_end)
2620 p += softback_buf - softback_end;
2621 return (u16 *) p;
2622}
2623
2624static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2625 int *px, int *py)
2626{
2627 unsigned long ret;
2628 int x, y;
2629
2630 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2631 unsigned long offset = (pos - vc->vc_origin) / 2;
2632
2633 x = offset % vc->vc_cols;
2634 y = offset / vc->vc_cols;
2635 if (vc->vc_num == fg_console)
2636 y += softback_lines;
2637 ret = pos + (vc->vc_cols - x) * 2;
2638 } else if (vc->vc_num == fg_console && softback_lines) {
2639 unsigned long offset = pos - softback_curr;
2640
2641 if (pos < softback_curr)
2642 offset += softback_end - softback_buf;
2643 offset /= 2;
2644 x = offset % vc->vc_cols;
2645 y = offset / vc->vc_cols;
2646 ret = pos + (vc->vc_cols - x) * 2;
2647 if (ret == softback_end)
2648 ret = softback_buf;
2649 if (ret == softback_in)
2650 ret = vc->vc_origin;
2651 } else {
2652 /* Should not happen */
2653 x = y = 0;
2654 ret = vc->vc_origin;
2655 }
2656 if (px)
2657 *px = x;
2658 if (py)
2659 *py = y;
2660 return ret;
2661}
2662
2663/* As we might be inside of softback, we may work with non-contiguous buffer,
2664 that's why we have to use a separate routine. */
2665static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2666{
2667 while (cnt--) {
2668 u16 a = scr_readw(p);
2669 if (!vc->vc_can_do_color)
2670 a ^= 0x0800;
2671 else if (vc->vc_hi_font_mask == 0x100)
2672 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2673 (((a) & 0x0e00) << 4);
2674 else
2675 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2676 (((a) & 0x0700) << 4);
2677 scr_writew(a, p++);
2678 if (p == (u16 *) softback_end)
2679 p = (u16 *) softback_buf;
2680 if (p == (u16 *) softback_in)
2681 p = (u16 *) vc->vc_origin;
2682 }
2683}
2684
2685static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2686{
2687 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002688 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 struct display *p = &fb_display[fg_console];
2690 int offset, limit, scrollback_old;
2691
2692 if (softback_top) {
2693 if (vc->vc_num != fg_console)
2694 return 0;
2695 if (vc->vc_mode != KD_TEXT || !lines)
2696 return 0;
2697 if (logo_shown >= 0) {
2698 struct vc_data *conp2 = vc_cons[logo_shown].d;
2699
2700 if (conp2->vc_top == logo_lines
2701 && conp2->vc_bottom == conp2->vc_rows)
2702 conp2->vc_top = 0;
2703 if (logo_shown == vc->vc_num) {
2704 unsigned long p, q;
2705 int i;
2706
2707 p = softback_in;
2708 q = vc->vc_origin +
2709 logo_lines * vc->vc_size_row;
2710 for (i = 0; i < logo_lines; i++) {
2711 if (p == softback_top)
2712 break;
2713 if (p == softback_buf)
2714 p = softback_end;
2715 p -= vc->vc_size_row;
2716 q -= vc->vc_size_row;
2717 scr_memcpyw((u16 *) q, (u16 *) p,
2718 vc->vc_size_row);
2719 }
David Hollister308af922006-05-30 21:25:36 -07002720 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 update_region(vc, vc->vc_origin,
2722 logo_lines * vc->vc_cols);
2723 }
2724 logo_shown = FBCON_LOGO_CANSHOW;
2725 }
2726 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2727 fbcon_redraw_softback(vc, p, lines);
2728 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2729 return 0;
2730 }
2731
2732 if (!scrollback_phys_max)
2733 return -ENOSYS;
2734
2735 scrollback_old = scrollback_current;
2736 scrollback_current -= lines;
2737 if (scrollback_current < 0)
2738 scrollback_current = 0;
2739 else if (scrollback_current > scrollback_max)
2740 scrollback_current = scrollback_max;
2741 if (scrollback_current == scrollback_old)
2742 return 0;
2743
2744 if (fbcon_is_inactive(vc, info))
2745 return 0;
2746
2747 fbcon_cursor(vc, CM_ERASE);
2748
2749 offset = p->yscroll - scrollback_current;
2750 limit = p->vrows;
2751 switch (p->scrollmode) {
2752 case SCROLL_WRAP_MOVE:
2753 info->var.vmode |= FB_VMODE_YWRAP;
2754 break;
2755 case SCROLL_PAN_MOVE:
2756 case SCROLL_PAN_REDRAW:
2757 limit -= vc->vc_rows;
2758 info->var.vmode &= ~FB_VMODE_YWRAP;
2759 break;
2760 }
2761 if (offset < 0)
2762 offset += limit;
2763 else if (offset >= limit)
2764 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002765
2766 ops->var.xoffset = 0;
2767 ops->var.yoffset = offset * vc->vc_font.height;
2768 ops->update_start(info);
2769
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 if (!scrollback_current)
2771 fbcon_cursor(vc, CM_DRAW);
2772 return 0;
2773}
2774
2775static int fbcon_set_origin(struct vc_data *vc)
2776{
2777 if (softback_lines)
2778 fbcon_scrolldelta(vc, softback_lines);
2779 return 0;
2780}
2781
2782static void fbcon_suspended(struct fb_info *info)
2783{
2784 struct vc_data *vc = NULL;
2785 struct fbcon_ops *ops = info->fbcon_par;
2786
2787 if (!ops || ops->currcon < 0)
2788 return;
2789 vc = vc_cons[ops->currcon].d;
2790
2791 /* Clear cursor, restore saved data */
2792 fbcon_cursor(vc, CM_ERASE);
2793}
2794
2795static void fbcon_resumed(struct fb_info *info)
2796{
2797 struct vc_data *vc;
2798 struct fbcon_ops *ops = info->fbcon_par;
2799
2800 if (!ops || ops->currcon < 0)
2801 return;
2802 vc = vc_cons[ops->currcon].d;
2803
2804 update_screen(vc);
2805}
2806
2807static void fbcon_modechanged(struct fb_info *info)
2808{
2809 struct fbcon_ops *ops = info->fbcon_par;
2810 struct vc_data *vc;
2811 struct display *p;
2812 int rows, cols;
2813
2814 if (!ops || ops->currcon < 0)
2815 return;
2816 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002817 if (vc->vc_mode != KD_TEXT ||
2818 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 return;
2820
2821 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002822 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
2824 if (CON_IS_VISIBLE(vc)) {
2825 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002826 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2827 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2828 cols /= vc->vc_font.width;
2829 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 vc_resize(vc, cols, rows);
2831 updatescrollmode(p, info, vc);
2832 scrollback_max = 0;
2833 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002834
2835 if (!fbcon_is_inactive(vc, info)) {
2836 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2837 ops->update_start(info);
2838 }
2839
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 fbcon_set_palette(vc, color_table);
2841 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002842 if (softback_buf)
2843 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 }
2845}
2846
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002847static void fbcon_set_all_vcs(struct fb_info *info)
2848{
2849 struct fbcon_ops *ops = info->fbcon_par;
2850 struct vc_data *vc;
2851 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002852 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002853
2854 if (!ops || ops->currcon < 0)
2855 return;
2856
Antonino A. Daplase614b182006-06-26 00:27:09 -07002857 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002858 vc = vc_cons[i].d;
2859 if (!vc || vc->vc_mode != KD_TEXT ||
2860 registered_fb[con2fb_map[i]] != info)
2861 continue;
2862
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002863 if (CON_IS_VISIBLE(vc)) {
2864 fg = i;
2865 continue;
2866 }
2867
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002868 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002869 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002870 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002871 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2872 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002873 cols /= vc->vc_font.width;
2874 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002875 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002876 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002877
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002878 if (fg != -1)
2879 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002880}
2881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882static int fbcon_mode_deleted(struct fb_info *info,
2883 struct fb_videomode *mode)
2884{
2885 struct fb_info *fb_info;
2886 struct display *p;
2887 int i, j, found = 0;
2888
2889 /* before deletion, ensure that mode is not in use */
2890 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2891 j = con2fb_map[i];
2892 if (j == -1)
2893 continue;
2894 fb_info = registered_fb[j];
2895 if (fb_info != info)
2896 continue;
2897 p = &fb_display[i];
2898 if (!p || !p->mode)
2899 continue;
2900 if (fb_mode_is_equal(p->mode, mode)) {
2901 found = 1;
2902 break;
2903 }
2904 }
2905 return found;
2906}
2907
Antonino A. Daplase614b182006-06-26 00:27:09 -07002908static int fbcon_fb_unregistered(int idx)
2909{
2910 int i;
2911
2912 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2913 if (con2fb_map[i] == idx)
2914 con2fb_map[i] = -1;
2915 }
2916
2917 if (idx == info_idx) {
2918 info_idx = -1;
2919
2920 for (i = 0; i < FB_MAX; i++) {
2921 if (registered_fb[i] != NULL) {
2922 info_idx = i;
2923 break;
2924 }
2925 }
2926 }
2927
2928 if (info_idx != -1) {
2929 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2930 if (con2fb_map[i] == -1)
2931 con2fb_map[i] = info_idx;
2932 }
2933 }
2934
2935 if (!num_registered_fb)
2936 unregister_con_driver(&fb_con);
2937
2938 return 0;
2939}
2940
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941static int fbcon_fb_registered(int idx)
2942{
2943 int ret = 0, i;
2944
2945 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002946 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 if (con2fb_map_boot[i] == idx) {
2948 info_idx = idx;
2949 break;
2950 }
2951 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07002952
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 if (info_idx != -1)
2954 ret = fbcon_takeover(1);
2955 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002956 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002957 if (con2fb_map_boot[i] == idx &&
2958 con2fb_map[i] == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 set_con2fb_map(i, idx, 0);
2960 }
2961 }
2962
2963 return ret;
2964}
2965
2966static void fbcon_fb_blanked(struct fb_info *info, int blank)
2967{
2968 struct fbcon_ops *ops = info->fbcon_par;
2969 struct vc_data *vc;
2970
2971 if (!ops || ops->currcon < 0)
2972 return;
2973
2974 vc = vc_cons[ops->currcon].d;
2975 if (vc->vc_mode != KD_TEXT ||
2976 registered_fb[con2fb_map[ops->currcon]] != info)
2977 return;
2978
2979 if (CON_IS_VISIBLE(vc)) {
2980 if (blank)
2981 do_blank_screen(0);
2982 else
2983 do_unblank_screen(0);
2984 }
2985 ops->blank_state = blank;
2986}
2987
2988static void fbcon_new_modelist(struct fb_info *info)
2989{
2990 int i;
2991 struct vc_data *vc;
2992 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002993 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Antonino A. Daplase614b182006-06-26 00:27:09 -07002995 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 if (registered_fb[con2fb_map[i]] != info)
2997 continue;
2998 if (!fb_display[i].mode)
2999 continue;
3000 vc = vc_cons[i].d;
3001 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003002 mode = fb_find_nearest_mode(fb_display[i].mode,
3003 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 fb_videomode_to_var(&var, mode);
3005
3006 if (vc)
3007 fbcon_set_disp(info, &var, vc);
3008 else
3009 fbcon_preset_disp(info, &var, i);
3010
3011 }
3012}
3013
3014static int fbcon_event_notify(struct notifier_block *self,
3015 unsigned long action, void *data)
3016{
3017 struct fb_event *event = data;
3018 struct fb_info *info = event->info;
3019 struct fb_videomode *mode;
3020 struct fb_con2fbmap *con2fb;
3021 int ret = 0;
3022
Antonino A. Daplase614b182006-06-26 00:27:09 -07003023 /*
3024 * ignore all events except driver registration and deregistration
3025 * if fbcon is not active
3026 */
3027 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3028 action == FB_EVENT_FB_UNREGISTERED))
3029 goto done;
3030
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 switch(action) {
3032 case FB_EVENT_SUSPEND:
3033 fbcon_suspended(info);
3034 break;
3035 case FB_EVENT_RESUME:
3036 fbcon_resumed(info);
3037 break;
3038 case FB_EVENT_MODE_CHANGE:
3039 fbcon_modechanged(info);
3040 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003041 case FB_EVENT_MODE_CHANGE_ALL:
3042 fbcon_set_all_vcs(info);
3043 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 case FB_EVENT_MODE_DELETE:
3045 mode = event->data;
3046 ret = fbcon_mode_deleted(info, mode);
3047 break;
3048 case FB_EVENT_FB_REGISTERED:
3049 ret = fbcon_fb_registered(info->node);
3050 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003051 case FB_EVENT_FB_UNREGISTERED:
3052 ret = fbcon_fb_unregistered(info->node);
3053 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 case FB_EVENT_SET_CONSOLE_MAP:
3055 con2fb = event->data;
3056 ret = set_con2fb_map(con2fb->console - 1,
3057 con2fb->framebuffer, 1);
3058 break;
3059 case FB_EVENT_GET_CONSOLE_MAP:
3060 con2fb = event->data;
3061 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3062 break;
3063 case FB_EVENT_BLANK:
3064 fbcon_fb_blanked(info, *(int *)event->data);
3065 break;
3066 case FB_EVENT_NEW_MODELIST:
3067 fbcon_new_modelist(info);
3068 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 }
3070
Antonino A. Daplase614b182006-06-26 00:27:09 -07003071done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 return ret;
3073}
3074
3075/*
3076 * The console `switch' structure for the frame buffer based console
3077 */
3078
3079static const struct consw fb_con = {
3080 .owner = THIS_MODULE,
3081 .con_startup = fbcon_startup,
3082 .con_init = fbcon_init,
3083 .con_deinit = fbcon_deinit,
3084 .con_clear = fbcon_clear,
3085 .con_putc = fbcon_putc,
3086 .con_putcs = fbcon_putcs,
3087 .con_cursor = fbcon_cursor,
3088 .con_scroll = fbcon_scroll,
3089 .con_bmove = fbcon_bmove,
3090 .con_switch = fbcon_switch,
3091 .con_blank = fbcon_blank,
3092 .con_font_set = fbcon_set_font,
3093 .con_font_get = fbcon_get_font,
3094 .con_font_default = fbcon_set_def_font,
3095 .con_font_copy = fbcon_copy_font,
3096 .con_set_palette = fbcon_set_palette,
3097 .con_scrolldelta = fbcon_scrolldelta,
3098 .con_set_origin = fbcon_set_origin,
3099 .con_invert_region = fbcon_invert_region,
3100 .con_screen_pos = fbcon_screen_pos,
3101 .con_getxy = fbcon_getxy,
3102 .con_resize = fbcon_resize,
3103};
3104
3105static struct notifier_block fbcon_event_notifier = {
3106 .notifier_call = fbcon_event_notify,
3107};
3108
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003109static ssize_t store_rotate(struct class_device *class_device,
3110 const char *buf, size_t count)
3111{
3112 struct fb_info *info;
3113 int rotate, idx;
3114 char **last = NULL;
3115
Antonino A. Daplase614b182006-06-26 00:27:09 -07003116 if (fbcon_has_exited)
3117 return count;
3118
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003119 acquire_console_sem();
3120 idx = con2fb_map[fg_console];
3121
3122 if (idx == -1 || registered_fb[idx] == NULL)
3123 goto err;
3124
3125 info = registered_fb[idx];
3126 rotate = simple_strtoul(buf, last, 0);
3127 fbcon_rotate(info, rotate);
3128err:
3129 release_console_sem();
3130 return count;
3131}
3132
3133static ssize_t store_rotate_all(struct class_device *class_device,
3134 const char *buf, size_t count)
3135{
3136 struct fb_info *info;
3137 int rotate, idx;
3138 char **last = NULL;
3139
Antonino A. Daplase614b182006-06-26 00:27:09 -07003140 if (fbcon_has_exited)
3141 return count;
3142
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003143 acquire_console_sem();
3144 idx = con2fb_map[fg_console];
3145
3146 if (idx == -1 || registered_fb[idx] == NULL)
3147 goto err;
3148
3149 info = registered_fb[idx];
3150 rotate = simple_strtoul(buf, last, 0);
3151 fbcon_rotate_all(info, rotate);
3152err:
3153 release_console_sem();
3154 return count;
3155}
3156
3157static ssize_t show_rotate(struct class_device *class_device, char *buf)
3158{
3159 struct fb_info *info;
3160 int rotate = 0, idx;
3161
Antonino A. Daplase614b182006-06-26 00:27:09 -07003162 if (fbcon_has_exited)
3163 return 0;
3164
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003165 acquire_console_sem();
3166 idx = con2fb_map[fg_console];
3167
3168 if (idx == -1 || registered_fb[idx] == NULL)
3169 goto err;
3170
3171 info = registered_fb[idx];
3172 rotate = fbcon_get_rotate(info);
3173err:
3174 release_console_sem();
3175 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3176}
3177
3178static struct class_device_attribute class_device_attrs[] = {
3179 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3180 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3181};
3182
3183static int fbcon_init_class_device(void)
3184{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003185 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003186
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003187 fbcon_has_sysfs = 1;
3188
3189 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3190 error = class_device_create_file(fbcon_class_device,
3191 &class_device_attrs[i]);
3192
3193 if (error)
3194 break;
3195 }
3196
3197 if (error) {
3198 while (--i >= 0)
3199 class_device_remove_file(fbcon_class_device,
3200 &class_device_attrs[i]);
3201
3202 fbcon_has_sysfs = 0;
3203 }
3204
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003205 return 0;
3206}
3207
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003208static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003211 int i;
3212
3213 acquire_console_sem();
3214
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 for (i = 0; i < FB_MAX; i++) {
3216 if (registered_fb[i] != NULL) {
3217 info_idx = i;
3218 break;
3219 }
3220 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003221
3222 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 fbcon_takeover(0);
3224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003227static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003228{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003229 struct fb_info *info;
3230 int i, j, mapped;
3231
Antonino A. Daplase614b182006-06-26 00:27:09 -07003232 if (fbcon_has_exited)
3233 return;
3234
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003235#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003236 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003237#endif
3238#ifdef CONFIG_MAC
3239 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003240 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003241#endif
3242
3243 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003244 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003245
3246 for (i = 0; i < FB_MAX; i++) {
3247 mapped = 0;
3248 info = registered_fb[i];
3249
3250 if (info == NULL)
3251 continue;
3252
Antonino A. Daplase614b182006-06-26 00:27:09 -07003253 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3254 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003255 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003256 }
3257
3258 if (mapped) {
3259 if (info->fbops->fb_release)
3260 info->fbops->fb_release(info, 0);
3261 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003262
3263 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003264 struct fbcon_ops *ops = info->fbcon_par;
3265
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003266 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003267 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003268 kfree(info->fbcon_par);
3269 info->fbcon_par = NULL;
3270 }
3271
3272 if (info->queue.func == fb_flashcursor)
3273 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003274 }
3275 }
3276
Antonino A. Daplase614b182006-06-26 00:27:09 -07003277 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003278}
3279
3280static int __init fb_console_init(void)
3281{
3282 int i;
3283
3284 acquire_console_sem();
3285 fb_register_client(&fbcon_event_notifier);
3286 fbcon_class_device =
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003287 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003288
3289 if (IS_ERR(fbcon_class_device)) {
3290 printk(KERN_WARNING "Unable to create class_device "
3291 "for fbcon; errno = %ld\n",
3292 PTR_ERR(fbcon_class_device));
3293 fbcon_class_device = NULL;
3294 } else
3295 fbcon_init_class_device();
3296
3297 for (i = 0; i < MAX_NR_CONSOLES; i++)
3298 con2fb_map[i] = -1;
3299
3300 release_console_sem();
3301 fbcon_start();
3302 return 0;
3303}
3304
3305module_init(fb_console_init);
3306
3307#ifdef MODULE
3308
Antonino A. Daplase614b182006-06-26 00:27:09 -07003309static void __exit fbcon_deinit_class_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003310{
3311 int i;
3312
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003313 if (fbcon_has_sysfs) {
3314 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3315 class_device_remove_file(fbcon_class_device,
3316 &class_device_attrs[i]);
3317
3318 fbcon_has_sysfs = 0;
3319 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003320}
3321
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322static void __exit fb_console_exit(void)
3323{
3324 acquire_console_sem();
3325 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003326 fbcon_deinit_class_device();
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003327 class_device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003328 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003330 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331}
3332
3333module_exit(fb_console_exit);
3334
3335#endif
3336
3337MODULE_LICENSE("GPL");