blob: 0429fd2cece09cff24a3e3f849a9894bac3056cb [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];
110static int logo_height;
111static int logo_lines;
112/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
113 enums. */
114static int logo_shown = FBCON_LOGO_CANSHOW;
115/* Software scrollback */
116static int fbcon_softback_size = 32768;
117static unsigned long softback_buf, softback_curr;
118static unsigned long softback_in;
119static unsigned long softback_top, softback_end;
120static int softback_lines;
121/* console mappings */
122static int first_fb_vc;
123static int last_fb_vc = MAX_NR_CONSOLES - 1;
124static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700125static int fbcon_has_exited;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/* font data */
128static char fontname[40];
129
130/* current fb_info */
131static int info_idx = -1;
132
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800133/* console rotation */
134static int rotate;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700135static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static const struct consw fb_con;
138
139#define CM_SOFTBACK (8)
140
141#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static int fbcon_set_origin(struct vc_data *);
144
145#define CURSOR_DRAW_DELAY (1)
146
147/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define ATARI_CURSOR_BLINK_RATE (42)
149#define MAC_CURSOR_BLINK_RATE (32)
150#define DEFAULT_CURSOR_BLINK_RATE (20)
151
152static int vbl_cursor_cnt;
153
154#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
155
156/*
157 * Interface used by the world
158 */
159
160static const char *fbcon_startup(void);
161static void fbcon_init(struct vc_data *vc, int init);
162static void fbcon_deinit(struct vc_data *vc);
163static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
164 int width);
165static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
166static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
167 int count, int ypos, int xpos);
168static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
169static void fbcon_cursor(struct vc_data *vc, int mode);
170static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
171 int count);
172static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
173 int height, int width);
174static int fbcon_switch(struct vc_data *vc);
175static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
176static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
177static int fbcon_scrolldelta(struct vc_data *vc, int lines);
178
179/*
180 * Internal routines
181 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static __inline__ void ywrap_up(struct vc_data *vc, int count);
183static __inline__ void ywrap_down(struct vc_data *vc, int count);
184static __inline__ void ypan_up(struct vc_data *vc, int count);
185static __inline__ void ypan_down(struct vc_data *vc, int count);
186static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
187 int dy, int dx, int height, int width, u_int y_break);
188static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
189 struct vc_data *vc);
190static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 int unit);
192static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
193 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800194static void fbcon_modechanged(struct fb_info *info);
195static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700196static void fbcon_start(void);
197static void fbcon_exit(void);
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700198static struct class_device *fbcon_class_device;
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#ifdef CONFIG_MAC
201/*
202 * On the Macintoy, there may or may not be a working VBL int. We need to probe
203 */
204static int vbl_detected;
205
David Howells7d12e782006-10-05 14:55:46 +0100206static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207{
208 vbl_detected++;
209 return IRQ_HANDLED;
210}
211#endif
212
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800213#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800214static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800215{
216 struct fbcon_ops *ops = info->fbcon_par;
217
218 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800219 ops->p->con_rotate < 4)
220 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800221 else
222 ops->rotate = 0;
223}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800224
225static void fbcon_rotate(struct fb_info *info, u32 rotate)
226{
227 struct fbcon_ops *ops= info->fbcon_par;
228 struct fb_info *fb_info;
229
230 if (!ops || ops->currcon == -1)
231 return;
232
233 fb_info = registered_fb[con2fb_map[ops->currcon]];
234
235 if (info == fb_info) {
236 struct display *p = &fb_display[ops->currcon];
237
238 if (rotate < 4)
239 p->con_rotate = rotate;
240 else
241 p->con_rotate = 0;
242
243 fbcon_modechanged(info);
244 }
245}
246
247static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
248{
249 struct fbcon_ops *ops = info->fbcon_par;
250 struct vc_data *vc;
251 struct display *p;
252 int i;
253
254 if (!ops || ops->currcon < 0 || rotate > 3)
255 return;
256
Antonino A. Daplase614b182006-06-26 00:27:09 -0700257 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800258 vc = vc_cons[i].d;
259 if (!vc || vc->vc_mode != KD_TEXT ||
260 registered_fb[con2fb_map[i]] != info)
261 continue;
262
263 p = &fb_display[vc->vc_num];
264 p->con_rotate = rotate;
265 }
266
267 fbcon_set_all_vcs(info);
268}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800269#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800270static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800271{
272 struct fbcon_ops *ops = info->fbcon_par;
273
274 ops->rotate = FB_ROTATE_UR;
275}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800276
277static void fbcon_rotate(struct fb_info *info, u32 rotate)
278{
279 return;
280}
281
282static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
283{
284 return;
285}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800286#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800287
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800288static int fbcon_get_rotate(struct fb_info *info)
289{
290 struct fbcon_ops *ops = info->fbcon_par;
291
292 return (ops) ? ops->rotate : 0;
293}
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
296{
297 struct fbcon_ops *ops = info->fbcon_par;
298
299 return (info->state != FBINFO_STATE_RUNNING ||
300 vc->vc_mode != KD_TEXT || ops->graphics);
301}
302
303static inline int get_color(struct vc_data *vc, struct fb_info *info,
304 u16 c, int is_fg)
305{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700306 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 int color = 0;
308
309 if (console_blanked) {
310 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
311
312 c = vc->vc_video_erase_char & charmask;
313 }
314
315 if (depth != 1)
316 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
317 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
318
319 switch (depth) {
320 case 1:
321 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700322 int col = ~(0xfff << (max(info->var.green.length,
323 max(info->var.red.length,
324 info->var.blue.length)))) & 0xff;
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700327 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
328 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 if (console_blanked)
331 fg = bg;
332
333 color = (is_fg) ? fg : bg;
334 break;
335 }
336 case 2:
337 /*
338 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700339 * is grayscale. However, simply dividing the values by 4
340 * will not work, as colors 1, 2 and 3 will be scaled-down
341 * to zero rendering them invisible. So empirically convert
342 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700344 switch (color) {
345 case 0:
346 color = 0; /* black */
347 break;
348 case 1 ... 6:
349 color = 2; /* white */
350 break;
351 case 7 ... 8:
352 color = 1; /* gray */
353 break;
354 default:
355 color = 3; /* intense white */
356 break;
357 }
358 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 case 3:
360 /*
361 * Last 8 entries of default 16-color palette is a more intense
362 * version of the first 8 (i.e., same chrominance, different
363 * luminance).
364 */
365 color &= 7;
366 break;
367 }
368
369
370 return color;
371}
372
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800373static void fbcon_update_softback(struct vc_data *vc)
374{
375 int l = fbcon_softback_size / vc->vc_size_row;
376
377 if (l > 5)
378 softback_end = softback_buf + l * vc->vc_size_row;
379 else
380 /* Smaller scrollback makes no sense, and 0 would screw
381 the operation totally */
382 softback_top = 0;
383}
384
David Howellsc4028952006-11-22 14:57:56 +0000385static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
David Howellsc4028952006-11-22 14:57:56 +0000387 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 struct fbcon_ops *ops = info->fbcon_par;
389 struct display *p;
390 struct vc_data *vc = NULL;
391 int c;
392 int mode;
393
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700394 acquire_console_sem();
395 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 vc = vc_cons[ops->currcon].d;
397
398 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700399 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700400 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700401 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700403 }
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 p = &fb_display[vc->vc_num];
406 c = scr_readw((u16 *) vc->vc_pos);
407 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
408 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800409 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 get_color(vc, info, c, 0));
411 release_console_sem();
412}
413
Russell King41359dc2005-06-30 16:30:07 +0100414#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100416static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
418 struct fb_info *info = dev_id;
419
420 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
421 schedule_work(&info->queue);
422 vbl_cursor_cnt = cursor_blink_rate;
423 }
424 return IRQ_HANDLED;
425}
426#endif
427
428static void cursor_timer_handler(unsigned long dev_addr)
429{
430 struct fb_info *info = (struct fb_info *) dev_addr;
431 struct fbcon_ops *ops = info->fbcon_par;
432
433 schedule_work(&info->queue);
434 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
435}
436
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700437static void fbcon_add_cursor_timer(struct fb_info *info)
438{
439 struct fbcon_ops *ops = info->fbcon_par;
440
441 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
442 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
443 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000444 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700445
446 init_timer(&ops->cursor_timer);
447 ops->cursor_timer.function = cursor_timer_handler;
448 ops->cursor_timer.expires = jiffies + HZ / 5;
449 ops->cursor_timer.data = (unsigned long ) info;
450 add_timer(&ops->cursor_timer);
451 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
452 }
453}
454
455static void fbcon_del_cursor_timer(struct fb_info *info)
456{
457 struct fbcon_ops *ops = info->fbcon_par;
458
459 if (info->queue.func == fb_flashcursor &&
460 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
461 del_timer_sync(&ops->cursor_timer);
462 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
463 }
464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466#ifndef MODULE
467static int __init fb_console_setup(char *this_opt)
468{
469 char *options;
470 int i, j;
471
472 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800473 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 while ((options = strsep(&this_opt, ",")) != NULL) {
476 if (!strncmp(options, "font:", 5))
477 strcpy(fontname, options + 5);
478
479 if (!strncmp(options, "scrollback:", 11)) {
480 options += 11;
481 if (*options) {
482 fbcon_softback_size = simple_strtoul(options, &options, 0);
483 if (*options == 'k' || *options == 'K') {
484 fbcon_softback_size *= 1024;
485 options++;
486 }
487 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800488 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 options++;
490 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800491 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
493
494 if (!strncmp(options, "map:", 4)) {
495 options += 4;
496 if (*options)
497 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
498 if (!options[j])
499 j = 0;
500 con2fb_map_boot[i] =
501 (options[j++]-'0') % FB_MAX;
502 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800503 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
506 if (!strncmp(options, "vc:", 3)) {
507 options += 3;
508 if (*options)
509 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
510 if (first_fb_vc < 0)
511 first_fb_vc = 0;
512 if (*options++ == '-')
513 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
514 fbcon_is_default = 0;
515 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800516
517 if (!strncmp(options, "rotate:", 7)) {
518 options += 7;
519 if (*options)
520 rotate = simple_strtoul(options, &options, 0);
521 if (rotate > 3)
522 rotate = 0;
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800525 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
528__setup("fbcon=", fb_console_setup);
529#endif
530
531static int search_fb_in_map(int idx)
532{
533 int i, retval = 0;
534
Antonino A. Daplase614b182006-06-26 00:27:09 -0700535 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (con2fb_map[i] == idx)
537 retval = 1;
538 }
539 return retval;
540}
541
542static int search_for_mapped_con(void)
543{
544 int i, retval = 0;
545
Antonino A. Daplase614b182006-06-26 00:27:09 -0700546 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (con2fb_map[i] != -1)
548 retval = 1;
549 }
550 return retval;
551}
552
553static int fbcon_takeover(int show_logo)
554{
555 int err, i;
556
557 if (!num_registered_fb)
558 return -ENODEV;
559
560 if (!show_logo)
561 logo_shown = FBCON_LOGO_DONTSHOW;
562
563 for (i = first_fb_vc; i <= last_fb_vc; i++)
564 con2fb_map[i] = info_idx;
565
566 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
567 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (err) {
570 for (i = first_fb_vc; i <= last_fb_vc; i++) {
571 con2fb_map[i] = -1;
572 }
573 info_idx = -1;
574 }
575
576 return err;
577}
578
579static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
580 int cols, int rows, int new_cols, int new_rows)
581{
582 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800583 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 int cnt, erase = vc->vc_video_erase_char, step;
585 unsigned short *save = NULL, *r, *q;
586
587 /*
588 * remove underline attribute from erase character
589 * if black and white framebuffer.
590 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700591 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800593 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 logo_lines = (logo_height + vc->vc_font.height - 1) /
595 vc->vc_font.height;
596 q = (unsigned short *) (vc->vc_origin +
597 vc->vc_size_row * rows);
598 step = logo_lines * cols;
599 for (r = q - logo_lines * cols; r < q; r++)
600 if (scr_readw(r) != vc->vc_video_erase_char)
601 break;
602 if (r != q && new_rows >= rows + logo_lines) {
603 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
604 if (save) {
605 int i = cols < new_cols ? cols : new_cols;
606 scr_memsetw(save, erase, logo_lines * new_cols * 2);
607 r = q - step;
608 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
609 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
610 r = q;
611 }
612 }
613 if (r == q) {
614 /* We can scroll screen down */
615 r = q - step - cols;
616 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
617 scr_memcpyw(r + step, r, vc->vc_size_row);
618 r -= cols;
619 }
620 if (!save) {
621 vc->vc_y += logo_lines;
622 vc->vc_pos += logo_lines * vc->vc_size_row;
623 }
624 }
625 scr_memsetw((unsigned short *) vc->vc_origin,
626 erase,
627 vc->vc_size_row * logo_lines);
628
629 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
630 fbcon_clear_margins(vc, 0);
631 update_screen(vc);
632 }
633
634 if (save) {
635 q = (unsigned short *) (vc->vc_origin +
636 vc->vc_size_row *
637 rows);
638 scr_memcpyw(q, save, logo_lines * new_cols * 2);
639 vc->vc_y += logo_lines;
640 vc->vc_pos += logo_lines * vc->vc_size_row;
641 kfree(save);
642 }
643
644 if (logo_lines > vc->vc_bottom) {
645 logo_shown = FBCON_LOGO_CANSHOW;
646 printk(KERN_INFO
647 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
648 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
649 logo_shown = FBCON_LOGO_DRAW;
650 vc->vc_top = logo_lines;
651 }
652}
653
654#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800655static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
657 struct fbcon_ops *ops = info->fbcon_par;
658
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800659 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800662 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800663 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800664 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800669static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
671 struct fbcon_ops *ops = info->fbcon_par;
672
673 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800674 ops->p = &fb_display[vc->vc_num];
675 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 fbcon_set_bitops(ops);
677}
678#endif /* CONFIG_MISC_TILEBLITTING */
679
680
681static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
682 int unit, int oldidx)
683{
684 struct fbcon_ops *ops = NULL;
685 int err = 0;
686
687 if (!try_module_get(info->fbops->owner))
688 err = -ENODEV;
689
690 if (!err && info->fbops->fb_open &&
691 info->fbops->fb_open(info, 0))
692 err = -ENODEV;
693
694 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800695 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 if (!ops)
697 err = -ENOMEM;
698 }
699
700 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 info->fbcon_par = ops;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800702 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704
705 if (err) {
706 con2fb_map[unit] = oldidx;
707 module_put(info->fbops->owner);
708 }
709
710 return err;
711}
712
713static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
714 struct fb_info *newinfo, int unit,
715 int oldidx, int found)
716{
717 struct fbcon_ops *ops = oldinfo->fbcon_par;
718 int err = 0;
719
720 if (oldinfo->fbops->fb_release &&
721 oldinfo->fbops->fb_release(oldinfo, 0)) {
722 con2fb_map[unit] = oldidx;
723 if (!found && newinfo->fbops->fb_release)
724 newinfo->fbops->fb_release(newinfo, 0);
725 if (!found)
726 module_put(newinfo->fbops->owner);
727 err = -ENODEV;
728 }
729
730 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700731 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 kfree(ops->cursor_state.mask);
733 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800734 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 kfree(oldinfo->fbcon_par);
736 oldinfo->fbcon_par = NULL;
737 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800738 /*
739 If oldinfo and newinfo are driving the same hardware,
740 the fb_release() method of oldinfo may attempt to
741 restore the hardware state. This will leave the
742 newinfo in an undefined state. Thus, a call to
743 fb_set_par() may be needed for the newinfo.
744 */
745 if (newinfo->fbops->fb_set_par)
746 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748
749 return err;
750}
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
753 int unit, int show_logo)
754{
755 struct fbcon_ops *ops = info->fbcon_par;
756
757 ops->currcon = fg_console;
758
759 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
760 info->fbops->fb_set_par(info);
761
762 ops->flags |= FBCON_FLAGS_INIT;
763 ops->graphics = 0;
764
765 if (vc)
766 fbcon_set_disp(info, &info->var, vc);
767 else
768 fbcon_preset_disp(info, &info->var, unit);
769
770 if (show_logo) {
771 struct vc_data *fg_vc = vc_cons[fg_console].d;
772 struct fb_info *fg_info =
773 registered_fb[con2fb_map[fg_console]];
774
775 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
776 fg_vc->vc_rows, fg_vc->vc_cols,
777 fg_vc->vc_rows);
778 }
779
780 update_screen(vc_cons[fg_console].d);
781}
782
783/**
784 * set_con2fb_map - map console to frame buffer device
785 * @unit: virtual console number to map
786 * @newidx: frame buffer index to map virtual console to
787 * @user: user request
788 *
789 * Maps a virtual console @unit to a frame buffer device
790 * @newidx.
791 */
792static int set_con2fb_map(int unit, int newidx, int user)
793{
794 struct vc_data *vc = vc_cons[unit].d;
795 int oldidx = con2fb_map[unit];
796 struct fb_info *info = registered_fb[newidx];
797 struct fb_info *oldinfo = NULL;
798 int found, err = 0;
799
800 if (oldidx == newidx)
801 return 0;
802
Antonino A. Daplase614b182006-06-26 00:27:09 -0700803 if (!info || fbcon_has_exited)
804 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 if (!err && !search_for_mapped_con()) {
807 info_idx = newidx;
808 return fbcon_takeover(0);
809 }
810
811 if (oldidx != -1)
812 oldinfo = registered_fb[oldidx];
813
814 found = search_fb_in_map(newidx);
815
816 acquire_console_sem();
817 con2fb_map[unit] = newidx;
818 if (!err && !found)
819 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
820
821
822 /*
823 * If old fb is not mapped to any of the consoles,
824 * fbcon should release it.
825 */
826 if (!err && oldinfo && !search_fb_in_map(oldidx))
827 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
828 found);
829
830 if (!err) {
831 int show_logo = (fg_console == 0 && !user &&
832 logo_shown != FBCON_LOGO_DONTSHOW);
833
834 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700835 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 con2fb_map_boot[unit] = newidx;
837 con2fb_init_display(vc, info, unit, show_logo);
838 }
839
Antonino A. Daplase614b182006-06-26 00:27:09 -0700840 if (!search_fb_in_map(info_idx))
841 info_idx = newidx;
842
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 release_console_sem();
844 return err;
845}
846
847/*
848 * Low Level Operations
849 */
850/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
851static int var_to_display(struct display *disp,
852 struct fb_var_screeninfo *var,
853 struct fb_info *info)
854{
855 disp->xres_virtual = var->xres_virtual;
856 disp->yres_virtual = var->yres_virtual;
857 disp->bits_per_pixel = var->bits_per_pixel;
858 disp->grayscale = var->grayscale;
859 disp->nonstd = var->nonstd;
860 disp->accel_flags = var->accel_flags;
861 disp->height = var->height;
862 disp->width = var->width;
863 disp->red = var->red;
864 disp->green = var->green;
865 disp->blue = var->blue;
866 disp->transp = var->transp;
867 disp->rotate = var->rotate;
868 disp->mode = fb_match_mode(var, &info->modelist);
869 if (disp->mode == NULL)
870 /* This should not happen */
871 return -EINVAL;
872 return 0;
873}
874
875static void display_to_var(struct fb_var_screeninfo *var,
876 struct display *disp)
877{
878 fb_videomode_to_var(var, disp->mode);
879 var->xres_virtual = disp->xres_virtual;
880 var->yres_virtual = disp->yres_virtual;
881 var->bits_per_pixel = disp->bits_per_pixel;
882 var->grayscale = disp->grayscale;
883 var->nonstd = disp->nonstd;
884 var->accel_flags = disp->accel_flags;
885 var->height = disp->height;
886 var->width = disp->width;
887 var->red = disp->red;
888 var->green = disp->green;
889 var->blue = disp->blue;
890 var->transp = disp->transp;
891 var->rotate = disp->rotate;
892}
893
894static const char *fbcon_startup(void)
895{
896 const char *display_desc = "frame buffer device";
897 struct display *p = &fb_display[fg_console];
898 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700899 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 struct module *owner;
901 struct fb_info *info = NULL;
902 struct fbcon_ops *ops;
903 int rows, cols;
904 int irqres;
905
906 irqres = 1;
907 /*
908 * If num_registered_fb is zero, this is a call for the dummy part.
909 * The frame buffer devices weren't initialized yet.
910 */
911 if (!num_registered_fb || info_idx == -1)
912 return display_desc;
913 /*
914 * Instead of blindly using registered_fb[0], we use info_idx, set by
915 * fb_console_init();
916 */
917 info = registered_fb[info_idx];
918 if (!info)
919 return NULL;
920
921 owner = info->fbops->owner;
922 if (!try_module_get(owner))
923 return NULL;
924 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
925 module_put(owner);
926 return NULL;
927 }
928
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800929 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 if (!ops) {
931 module_put(owner);
932 return NULL;
933 }
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 ops->currcon = -1;
936 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800937 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800939 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800940 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 if (info->fix.type != FB_TYPE_TEXT) {
943 if (fbcon_softback_size) {
944 if (!softback_buf) {
945 softback_buf =
946 (unsigned long)
947 kmalloc(fbcon_softback_size,
948 GFP_KERNEL);
949 if (!softback_buf) {
950 fbcon_softback_size = 0;
951 softback_top = 0;
952 }
953 }
954 } else {
955 if (softback_buf) {
956 kfree((void *) softback_buf);
957 softback_buf = 0;
958 softback_top = 0;
959 }
960 }
961 if (softback_buf)
962 softback_in = softback_top = softback_curr =
963 softback_buf;
964 softback_lines = 0;
965 }
966
967 /* Setup default font */
968 if (!p->fontdata) {
969 if (!fontname[0] || !(font = find_font(fontname)))
970 font = get_default_font(info->var.xres,
971 info->var.yres);
972 vc->vc_font.width = font->width;
973 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700974 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
976 }
977
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800978 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
979 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
980 cols /= vc->vc_font.width;
981 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 vc_resize(vc, cols, rows);
983
984 DPRINTK("mode: %s\n", info->fix.id);
985 DPRINTK("visual: %d\n", info->fix.visual);
986 DPRINTK("res: %dx%d-%d\n", info->var.xres,
987 info->var.yres,
988 info->var.bits_per_pixel);
989
990#ifdef CONFIG_ATARI
991 if (MACH_IS_ATARI) {
992 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
993 irqres =
994 request_irq(IRQ_AUTO_4, fb_vbl_handler,
995 IRQ_TYPE_PRIO, "framebuffer vbl",
996 info);
997 }
998#endif /* CONFIG_ATARI */
999
1000#ifdef CONFIG_MAC
1001 /*
1002 * On a Macintoy, the VBL interrupt may or may not be active.
1003 * As interrupt based cursor is more reliable and race free, we
1004 * probe for VBL interrupts.
1005 */
1006 if (MACH_IS_MAC) {
1007 int ct = 0;
1008 /*
1009 * Probe for VBL: set temp. handler ...
1010 */
1011 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1012 "framebuffer vbl", info);
1013 vbl_detected = 0;
1014
1015 /*
1016 * ... and spin for 20 ms ...
1017 */
1018 while (!vbl_detected && ++ct < 1000)
1019 udelay(20);
1020
1021 if (ct == 1000)
1022 printk
1023 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1024
1025 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1026
1027 if (vbl_detected) {
1028 /*
1029 * interrupt based cursor ok
1030 */
1031 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1032 irqres =
1033 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1034 "framebuffer vbl", info);
1035 } else {
1036 /*
1037 * VBL not detected: fall through, use timer based cursor
1038 */
1039 irqres = 1;
1040 }
1041 }
1042#endif /* CONFIG_MAC */
1043
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001044 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001045 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 return display_desc;
1047}
1048
1049static void fbcon_init(struct vc_data *vc, int init)
1050{
1051 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1052 struct fbcon_ops *ops;
1053 struct vc_data **default_mode = vc->vc_display_fg;
1054 struct vc_data *svc = *default_mode;
1055 struct display *t, *p = &fb_display[vc->vc_num];
1056 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001057 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 if (info_idx == -1 || info == NULL)
1060 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001061
1062 cap = info->flags;
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1065 (info->fix.type == FB_TYPE_TEXT))
1066 logo = 0;
1067
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 if (var_to_display(p, &info->var, info))
1069 return;
1070
1071 /* If we are not the first console on this
1072 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001073 t = &fb_display[fg_console];
1074 if (!p->fontdata) {
1075 if (t->fontdata) {
1076 struct vc_data *fvc = vc_cons[fg_console].d;
1077
1078 vc->vc_font.data = (void *)(p->fontdata =
1079 fvc->vc_font.data);
1080 vc->vc_font.width = fvc->vc_font.width;
1081 vc->vc_font.height = fvc->vc_font.height;
1082 p->userfont = t->userfont;
1083
1084 if (p->userfont)
1085 REFCOUNT(p->fontdata)++;
1086 } else {
1087 const struct font_desc *font = NULL;
1088
1089 if (!fontname[0] || !(font = find_font(fontname)))
1090 font = get_default_font(info->var.xres,
1091 info->var.yres);
1092 vc->vc_font.width = font->width;
1093 vc->vc_font.height = font->height;
1094 vc->vc_font.data = (void *)(p->fontdata = font->data);
1095 vc->vc_font.charcount = 256; /* FIXME Need to
1096 support more fonts */
1097 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001099
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 if (p->userfont)
1101 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001102
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001103 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1105 if (charcnt == 256) {
1106 vc->vc_hi_font_mask = 0;
1107 } else {
1108 vc->vc_hi_font_mask = 0x100;
1109 if (vc->vc_can_do_color)
1110 vc->vc_complement_mask <<= 1;
1111 }
1112
1113 if (!*svc->vc_uni_pagedir_loc)
1114 con_set_default_unimap(svc);
1115 if (!*vc->vc_uni_pagedir_loc)
1116 con_copy_unimap(vc, svc);
1117
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001118 ops = info->fbcon_par;
1119 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001120 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 cols = vc->vc_cols;
1123 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001124 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1125 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1126 new_cols /= vc->vc_font.width;
1127 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 vc_resize(vc, new_cols, new_rows);
1129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 /*
1131 * We must always set the mode. The mode of the previous console
1132 * driver could be in the same resolution but we are using different
1133 * hardware so we have to initialize the hardware.
1134 *
1135 * We need to do it in fbcon_init() to prevent screen corruption.
1136 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001137 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 if (info->fbops->fb_set_par &&
1139 !(ops->flags & FBCON_FLAGS_INIT))
1140 info->fbops->fb_set_par(info);
1141 ops->flags |= FBCON_FLAGS_INIT;
1142 }
1143
1144 ops->graphics = 0;
1145
1146 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1147 !(cap & FBINFO_HWACCEL_DISABLED))
1148 p->scrollmode = SCROLL_MOVE;
1149 else /* default to something safe */
1150 p->scrollmode = SCROLL_REDRAW;
1151
1152 /*
1153 * ++guenther: console.c:vc_allocate() relies on initializing
1154 * vc_{cols,rows}, but we must not set those if we are only
1155 * resizing the console.
1156 */
1157 if (!init) {
1158 vc->vc_cols = new_cols;
1159 vc->vc_rows = new_rows;
1160 }
1161
1162 if (logo)
1163 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1164
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001165 if (vc == svc && softback_buf)
1166 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001167
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001168 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001169 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001170 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001171 }
1172
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001173 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Antonino A. Daplase614b182006-06-26 00:27:09 -07001176static void fbcon_free_font(struct display *p)
1177{
1178 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1179 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1180 p->fontdata = NULL;
1181 p->userfont = 0;
1182}
1183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184static void fbcon_deinit(struct vc_data *vc)
1185{
1186 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001187 struct fb_info *info;
1188 struct fbcon_ops *ops;
1189 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001192 idx = con2fb_map[vc->vc_num];
1193
1194 if (idx == -1)
1195 goto finished;
1196
1197 info = registered_fb[idx];
1198
1199 if (!info)
1200 goto finished;
1201
1202 ops = info->fbcon_par;
1203
1204 if (!ops)
1205 goto finished;
1206
1207 if (CON_IS_VISIBLE(vc))
1208 fbcon_del_cursor_timer(info);
1209
1210 ops->flags &= ~FBCON_FLAGS_INIT;
1211finished:
1212
1213 if (!con_is_bound(&fb_con))
1214 fbcon_exit();
1215
1216 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217}
1218
1219/* ====================================================================== */
1220
1221/* fbcon_XXX routines - interface used by the world
1222 *
1223 * This system is now divided into two levels because of complications
1224 * caused by hardware scrolling. Top level functions:
1225 *
1226 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1227 *
1228 * handles y values in range [0, scr_height-1] that correspond to real
1229 * screen positions. y_wrap shift means that first line of bitmap may be
1230 * anywhere on this display. These functions convert lineoffsets to
1231 * bitmap offsets and deal with the wrap-around case by splitting blits.
1232 *
1233 * fbcon_bmove_physical_8() -- These functions fast implementations
1234 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1235 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1236 *
1237 * WARNING:
1238 *
1239 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1240 * Implies should only really hardware scroll in rows. Only reason for
1241 * restriction is simplicity & efficiency at the moment.
1242 */
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1245 int width)
1246{
1247 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1248 struct fbcon_ops *ops = info->fbcon_par;
1249
1250 struct display *p = &fb_display[vc->vc_num];
1251 u_int y_break;
1252
1253 if (fbcon_is_inactive(vc, info))
1254 return;
1255
1256 if (!height || !width)
1257 return;
1258
1259 /* Split blits that cross physical y_wrap boundary */
1260
1261 y_break = p->vrows - p->yscroll;
1262 if (sy < y_break && sy + height - 1 >= y_break) {
1263 u_int b = y_break - sy;
1264 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1265 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1266 width);
1267 } else
1268 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1269}
1270
1271static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1272 int count, int ypos, int xpos)
1273{
1274 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1275 struct display *p = &fb_display[vc->vc_num];
1276 struct fbcon_ops *ops = info->fbcon_par;
1277
1278 if (!fbcon_is_inactive(vc, info))
1279 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1280 get_color(vc, info, scr_readw(s), 1),
1281 get_color(vc, info, scr_readw(s), 0));
1282}
1283
1284static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1285{
1286 unsigned short chr;
1287
1288 scr_writew(c, &chr);
1289 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1290}
1291
1292static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1293{
1294 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1295 struct fbcon_ops *ops = info->fbcon_par;
1296
1297 if (!fbcon_is_inactive(vc, info))
1298 ops->clear_margins(vc, info, bottom_only);
1299}
1300
1301static void fbcon_cursor(struct vc_data *vc, int mode)
1302{
1303 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1304 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 int y;
1306 int c = scr_readw((u16 *) vc->vc_pos);
1307
1308 if (fbcon_is_inactive(vc, info))
1309 return;
1310
1311 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1312 if (mode & CM_SOFTBACK) {
1313 mode &= ~CM_SOFTBACK;
1314 y = softback_lines;
1315 } else {
1316 if (softback_lines)
1317 fbcon_set_origin(vc);
1318 y = 0;
1319 }
1320
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001321 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 get_color(vc, info, c, 0));
1323 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1324}
1325
1326static int scrollback_phys_max = 0;
1327static int scrollback_max = 0;
1328static int scrollback_current = 0;
1329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330/*
1331 * If no vc is existent yet, just set struct display
1332 */
1333static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1334 int unit)
1335{
1336 struct display *p = &fb_display[unit];
1337 struct display *t = &fb_display[fg_console];
1338
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 if (var_to_display(p, var, info))
1340 return;
1341
1342 p->fontdata = t->fontdata;
1343 p->userfont = t->userfont;
1344 if (p->userfont)
1345 REFCOUNT(p->fontdata)++;
1346}
1347
1348static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1349 struct vc_data *vc)
1350{
1351 struct display *p = &fb_display[vc->vc_num], *t;
1352 struct vc_data **default_mode = vc->vc_display_fg;
1353 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001354 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 int rows, cols, charcnt = 256;
1356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if (var_to_display(p, var, info))
1358 return;
1359 t = &fb_display[svc->vc_num];
1360 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001361 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 vc->vc_font.width = (*default_mode)->vc_font.width;
1363 vc->vc_font.height = (*default_mode)->vc_font.height;
1364 p->userfont = t->userfont;
1365 if (p->userfont)
1366 REFCOUNT(p->fontdata)++;
1367 }
1368 if (p->userfont)
1369 charcnt = FNTCHARCNT(p->fontdata);
1370
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001371 var->activate = FB_ACTIVATE_NOW;
1372 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001373 var->yoffset = info->var.yoffset;
1374 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001375 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001376 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001377 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1379 if (charcnt == 256) {
1380 vc->vc_hi_font_mask = 0;
1381 } else {
1382 vc->vc_hi_font_mask = 0x100;
1383 if (vc->vc_can_do_color)
1384 vc->vc_complement_mask <<= 1;
1385 }
1386
1387 if (!*svc->vc_uni_pagedir_loc)
1388 con_set_default_unimap(svc);
1389 if (!*vc->vc_uni_pagedir_loc)
1390 con_copy_unimap(vc, svc);
1391
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001392 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1393 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1394 cols /= vc->vc_font.width;
1395 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 if (CON_IS_VISIBLE(vc)) {
1399 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001400 if (softback_buf)
1401 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 }
1403}
1404
1405static __inline__ void ywrap_up(struct vc_data *vc, int count)
1406{
1407 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001408 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 struct display *p = &fb_display[vc->vc_num];
1410
1411 p->yscroll += count;
1412 if (p->yscroll >= p->vrows) /* Deal with wrap */
1413 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001414 ops->var.xoffset = 0;
1415 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1416 ops->var.vmode |= FB_VMODE_YWRAP;
1417 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 scrollback_max += count;
1419 if (scrollback_max > scrollback_phys_max)
1420 scrollback_max = scrollback_phys_max;
1421 scrollback_current = 0;
1422}
1423
1424static __inline__ void ywrap_down(struct vc_data *vc, int count)
1425{
1426 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001427 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 struct display *p = &fb_display[vc->vc_num];
1429
1430 p->yscroll -= count;
1431 if (p->yscroll < 0) /* Deal with wrap */
1432 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001433 ops->var.xoffset = 0;
1434 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1435 ops->var.vmode |= FB_VMODE_YWRAP;
1436 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 scrollback_max -= count;
1438 if (scrollback_max < 0)
1439 scrollback_max = 0;
1440 scrollback_current = 0;
1441}
1442
1443static __inline__ void ypan_up(struct vc_data *vc, int count)
1444{
1445 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1446 struct display *p = &fb_display[vc->vc_num];
1447 struct fbcon_ops *ops = info->fbcon_par;
1448
1449 p->yscroll += count;
1450 if (p->yscroll > p->vrows - vc->vc_rows) {
1451 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1452 0, 0, 0, vc->vc_rows, vc->vc_cols);
1453 p->yscroll -= p->vrows - vc->vc_rows;
1454 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001455
1456 ops->var.xoffset = 0;
1457 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1458 ops->var.vmode &= ~FB_VMODE_YWRAP;
1459 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 fbcon_clear_margins(vc, 1);
1461 scrollback_max += count;
1462 if (scrollback_max > scrollback_phys_max)
1463 scrollback_max = scrollback_phys_max;
1464 scrollback_current = 0;
1465}
1466
1467static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1468{
1469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001470 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 if (p->yscroll > p->vrows - vc->vc_rows) {
1476 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001478 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001479
1480 ops->var.xoffset = 0;
1481 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1482 ops->var.vmode &= ~FB_VMODE_YWRAP;
1483 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 fbcon_clear_margins(vc, 1);
1485 scrollback_max += count;
1486 if (scrollback_max > scrollback_phys_max)
1487 scrollback_max = scrollback_phys_max;
1488 scrollback_current = 0;
1489}
1490
1491static __inline__ void ypan_down(struct vc_data *vc, int count)
1492{
1493 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1494 struct display *p = &fb_display[vc->vc_num];
1495 struct fbcon_ops *ops = info->fbcon_par;
1496
1497 p->yscroll -= count;
1498 if (p->yscroll < 0) {
1499 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1500 0, vc->vc_rows, vc->vc_cols);
1501 p->yscroll += p->vrows - vc->vc_rows;
1502 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001503
1504 ops->var.xoffset = 0;
1505 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1506 ops->var.vmode &= ~FB_VMODE_YWRAP;
1507 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 fbcon_clear_margins(vc, 1);
1509 scrollback_max -= count;
1510 if (scrollback_max < 0)
1511 scrollback_max = 0;
1512 scrollback_current = 0;
1513}
1514
1515static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1516{
1517 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001518 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 if (p->yscroll < 0) {
1524 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001526 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001527
1528 ops->var.xoffset = 0;
1529 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1530 ops->var.vmode &= ~FB_VMODE_YWRAP;
1531 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 fbcon_clear_margins(vc, 1);
1533 scrollback_max -= count;
1534 if (scrollback_max < 0)
1535 scrollback_max = 0;
1536 scrollback_current = 0;
1537}
1538
1539static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1540 long delta)
1541{
1542 int count = vc->vc_rows;
1543 unsigned short *d, *s;
1544 unsigned long n;
1545 int line = 0;
1546
1547 d = (u16 *) softback_curr;
1548 if (d == (u16 *) softback_in)
1549 d = (u16 *) vc->vc_origin;
1550 n = softback_curr + delta * vc->vc_size_row;
1551 softback_lines -= delta;
1552 if (delta < 0) {
1553 if (softback_curr < softback_top && n < softback_buf) {
1554 n += softback_end - softback_buf;
1555 if (n < softback_top) {
1556 softback_lines -=
1557 (softback_top - n) / vc->vc_size_row;
1558 n = softback_top;
1559 }
1560 } else if (softback_curr >= softback_top
1561 && n < softback_top) {
1562 softback_lines -=
1563 (softback_top - n) / vc->vc_size_row;
1564 n = softback_top;
1565 }
1566 } else {
1567 if (softback_curr > softback_in && n >= softback_end) {
1568 n += softback_buf - softback_end;
1569 if (n > softback_in) {
1570 n = softback_in;
1571 softback_lines = 0;
1572 }
1573 } else if (softback_curr <= softback_in && n > softback_in) {
1574 n = softback_in;
1575 softback_lines = 0;
1576 }
1577 }
1578 if (n == softback_curr)
1579 return;
1580 softback_curr = n;
1581 s = (u16 *) softback_curr;
1582 if (s == (u16 *) softback_in)
1583 s = (u16 *) vc->vc_origin;
1584 while (count--) {
1585 unsigned short *start;
1586 unsigned short *le;
1587 unsigned short c;
1588 int x = 0;
1589 unsigned short attr = 1;
1590
1591 start = s;
1592 le = advance_row(s, 1);
1593 do {
1594 c = scr_readw(s);
1595 if (attr != (c & 0xff00)) {
1596 attr = c & 0xff00;
1597 if (s > start) {
1598 fbcon_putcs(vc, start, s - start,
1599 line, x);
1600 x += s - start;
1601 start = s;
1602 }
1603 }
1604 if (c == scr_readw(d)) {
1605 if (s > start) {
1606 fbcon_putcs(vc, start, s - start,
1607 line, x);
1608 x += s - start + 1;
1609 start = s + 1;
1610 } else {
1611 x++;
1612 start++;
1613 }
1614 }
1615 s++;
1616 d++;
1617 } while (s < le);
1618 if (s > start)
1619 fbcon_putcs(vc, start, s - start, line, x);
1620 line++;
1621 if (d == (u16 *) softback_end)
1622 d = (u16 *) softback_buf;
1623 if (d == (u16 *) softback_in)
1624 d = (u16 *) vc->vc_origin;
1625 if (s == (u16 *) softback_end)
1626 s = (u16 *) softback_buf;
1627 if (s == (u16 *) softback_in)
1628 s = (u16 *) vc->vc_origin;
1629 }
1630}
1631
1632static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1633 int line, int count, int dy)
1634{
1635 unsigned short *s = (unsigned short *)
1636 (vc->vc_origin + vc->vc_size_row * line);
1637
1638 while (count--) {
1639 unsigned short *start = s;
1640 unsigned short *le = advance_row(s, 1);
1641 unsigned short c;
1642 int x = 0;
1643 unsigned short attr = 1;
1644
1645 do {
1646 c = scr_readw(s);
1647 if (attr != (c & 0xff00)) {
1648 attr = c & 0xff00;
1649 if (s > start) {
1650 fbcon_putcs(vc, start, s - start,
1651 dy, x);
1652 x += s - start;
1653 start = s;
1654 }
1655 }
1656 console_conditional_schedule();
1657 s++;
1658 } while (s < le);
1659 if (s > start)
1660 fbcon_putcs(vc, start, s - start, dy, x);
1661 console_conditional_schedule();
1662 dy++;
1663 }
1664}
1665
1666static void fbcon_redraw(struct vc_data *vc, struct display *p,
1667 int line, int count, int offset)
1668{
1669 unsigned short *d = (unsigned short *)
1670 (vc->vc_origin + vc->vc_size_row * line);
1671 unsigned short *s = d + offset;
1672
1673 while (count--) {
1674 unsigned short *start = s;
1675 unsigned short *le = advance_row(s, 1);
1676 unsigned short c;
1677 int x = 0;
1678 unsigned short attr = 1;
1679
1680 do {
1681 c = scr_readw(s);
1682 if (attr != (c & 0xff00)) {
1683 attr = c & 0xff00;
1684 if (s > start) {
1685 fbcon_putcs(vc, start, s - start,
1686 line, x);
1687 x += s - start;
1688 start = s;
1689 }
1690 }
1691 if (c == scr_readw(d)) {
1692 if (s > start) {
1693 fbcon_putcs(vc, start, s - start,
1694 line, x);
1695 x += s - start + 1;
1696 start = s + 1;
1697 } else {
1698 x++;
1699 start++;
1700 }
1701 }
1702 scr_writew(c, d);
1703 console_conditional_schedule();
1704 s++;
1705 d++;
1706 } while (s < le);
1707 if (s > start)
1708 fbcon_putcs(vc, start, s - start, line, x);
1709 console_conditional_schedule();
1710 if (offset > 0)
1711 line++;
1712 else {
1713 line--;
1714 /* NOTE: We subtract two lines from these pointers */
1715 s -= vc->vc_size_row;
1716 d -= vc->vc_size_row;
1717 }
1718 }
1719}
1720
1721static inline void fbcon_softback_note(struct vc_data *vc, int t,
1722 int count)
1723{
1724 unsigned short *p;
1725
1726 if (vc->vc_num != fg_console)
1727 return;
1728 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1729
1730 while (count) {
1731 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1732 count--;
1733 p = advance_row(p, 1);
1734 softback_in += vc->vc_size_row;
1735 if (softback_in == softback_end)
1736 softback_in = softback_buf;
1737 if (softback_in == softback_top) {
1738 softback_top += vc->vc_size_row;
1739 if (softback_top == softback_end)
1740 softback_top = softback_buf;
1741 }
1742 }
1743 softback_curr = softback_in;
1744}
1745
1746static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1747 int count)
1748{
1749 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1750 struct display *p = &fb_display[vc->vc_num];
1751 struct fbcon_ops *ops = info->fbcon_par;
1752 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1753
1754 if (fbcon_is_inactive(vc, info))
1755 return -EINVAL;
1756
1757 fbcon_cursor(vc, CM_ERASE);
1758
1759 /*
1760 * ++Geert: Only use ywrap/ypan if the console is in text mode
1761 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1762 * whole screen (prevents flicker).
1763 */
1764
1765 switch (dir) {
1766 case SM_UP:
1767 if (count > vc->vc_rows) /* Maximum realistic size */
1768 count = vc->vc_rows;
1769 if (softback_top)
1770 fbcon_softback_note(vc, t, count);
1771 if (logo_shown >= 0)
1772 goto redraw_up;
1773 switch (p->scrollmode) {
1774 case SCROLL_MOVE:
1775 ops->bmove(vc, info, t + count, 0, t, 0,
1776 b - t - count, vc->vc_cols);
1777 ops->clear(vc, info, b - count, 0, count,
1778 vc->vc_cols);
1779 break;
1780
1781 case SCROLL_WRAP_MOVE:
1782 if (b - t - count > 3 * vc->vc_rows >> 2) {
1783 if (t > 0)
1784 fbcon_bmove(vc, 0, 0, count, 0, t,
1785 vc->vc_cols);
1786 ywrap_up(vc, count);
1787 if (vc->vc_rows - b > 0)
1788 fbcon_bmove(vc, b - count, 0, b, 0,
1789 vc->vc_rows - b,
1790 vc->vc_cols);
1791 } else if (info->flags & FBINFO_READS_FAST)
1792 fbcon_bmove(vc, t + count, 0, t, 0,
1793 b - t - count, vc->vc_cols);
1794 else
1795 goto redraw_up;
1796 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1797 break;
1798
1799 case SCROLL_PAN_REDRAW:
1800 if ((p->yscroll + count <=
1801 2 * (p->vrows - vc->vc_rows))
1802 && ((!scroll_partial && (b - t == vc->vc_rows))
1803 || (scroll_partial
1804 && (b - t - count >
1805 3 * vc->vc_rows >> 2)))) {
1806 if (t > 0)
1807 fbcon_redraw_move(vc, p, 0, t, count);
1808 ypan_up_redraw(vc, t, count);
1809 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001810 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 vc->vc_rows - b, b);
1812 } else
1813 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1814 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1815 break;
1816
1817 case SCROLL_PAN_MOVE:
1818 if ((p->yscroll + count <=
1819 2 * (p->vrows - vc->vc_rows))
1820 && ((!scroll_partial && (b - t == vc->vc_rows))
1821 || (scroll_partial
1822 && (b - t - count >
1823 3 * vc->vc_rows >> 2)))) {
1824 if (t > 0)
1825 fbcon_bmove(vc, 0, 0, count, 0, t,
1826 vc->vc_cols);
1827 ypan_up(vc, count);
1828 if (vc->vc_rows - b > 0)
1829 fbcon_bmove(vc, b - count, 0, b, 0,
1830 vc->vc_rows - b,
1831 vc->vc_cols);
1832 } else if (info->flags & FBINFO_READS_FAST)
1833 fbcon_bmove(vc, t + count, 0, t, 0,
1834 b - t - count, vc->vc_cols);
1835 else
1836 goto redraw_up;
1837 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1838 break;
1839
1840 case SCROLL_REDRAW:
1841 redraw_up:
1842 fbcon_redraw(vc, p, t, b - t - count,
1843 count * vc->vc_cols);
1844 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1845 scr_memsetw((unsigned short *) (vc->vc_origin +
1846 vc->vc_size_row *
1847 (b - count)),
1848 vc->vc_video_erase_char,
1849 vc->vc_size_row * count);
1850 return 1;
1851 }
1852 break;
1853
1854 case SM_DOWN:
1855 if (count > vc->vc_rows) /* Maximum realistic size */
1856 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001857 if (logo_shown >= 0)
1858 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 switch (p->scrollmode) {
1860 case SCROLL_MOVE:
1861 ops->bmove(vc, info, t, 0, t + count, 0,
1862 b - t - count, vc->vc_cols);
1863 ops->clear(vc, info, t, 0, count, vc->vc_cols);
1864 break;
1865
1866 case SCROLL_WRAP_MOVE:
1867 if (b - t - count > 3 * vc->vc_rows >> 2) {
1868 if (vc->vc_rows - b > 0)
1869 fbcon_bmove(vc, b, 0, b - count, 0,
1870 vc->vc_rows - b,
1871 vc->vc_cols);
1872 ywrap_down(vc, count);
1873 if (t > 0)
1874 fbcon_bmove(vc, count, 0, 0, 0, t,
1875 vc->vc_cols);
1876 } else if (info->flags & FBINFO_READS_FAST)
1877 fbcon_bmove(vc, t, 0, t + count, 0,
1878 b - t - count, vc->vc_cols);
1879 else
1880 goto redraw_down;
1881 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1882 break;
1883
1884 case SCROLL_PAN_MOVE:
1885 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1886 && ((!scroll_partial && (b - t == vc->vc_rows))
1887 || (scroll_partial
1888 && (b - t - count >
1889 3 * vc->vc_rows >> 2)))) {
1890 if (vc->vc_rows - b > 0)
1891 fbcon_bmove(vc, b, 0, b - count, 0,
1892 vc->vc_rows - b,
1893 vc->vc_cols);
1894 ypan_down(vc, count);
1895 if (t > 0)
1896 fbcon_bmove(vc, count, 0, 0, 0, t,
1897 vc->vc_cols);
1898 } else if (info->flags & FBINFO_READS_FAST)
1899 fbcon_bmove(vc, t, 0, t + count, 0,
1900 b - t - count, vc->vc_cols);
1901 else
1902 goto redraw_down;
1903 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1904 break;
1905
1906 case SCROLL_PAN_REDRAW:
1907 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1908 && ((!scroll_partial && (b - t == vc->vc_rows))
1909 || (scroll_partial
1910 && (b - t - count >
1911 3 * vc->vc_rows >> 2)))) {
1912 if (vc->vc_rows - b > 0)
1913 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1914 b - count);
1915 ypan_down_redraw(vc, t, count);
1916 if (t > 0)
1917 fbcon_redraw_move(vc, p, count, t, 0);
1918 } else
1919 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1920 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1921 break;
1922
1923 case SCROLL_REDRAW:
1924 redraw_down:
1925 fbcon_redraw(vc, p, b - 1, b - t - count,
1926 -count * vc->vc_cols);
1927 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1928 scr_memsetw((unsigned short *) (vc->vc_origin +
1929 vc->vc_size_row *
1930 t),
1931 vc->vc_video_erase_char,
1932 vc->vc_size_row * count);
1933 return 1;
1934 }
1935 }
1936 return 0;
1937}
1938
1939
1940static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1941 int height, int width)
1942{
1943 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1944 struct display *p = &fb_display[vc->vc_num];
1945
1946 if (fbcon_is_inactive(vc, info))
1947 return;
1948
1949 if (!width || !height)
1950 return;
1951
1952 /* Split blits that cross physical y_wrap case.
1953 * Pathological case involves 4 blits, better to use recursive
1954 * code rather than unrolled case
1955 *
1956 * Recursive invocations don't need to erase the cursor over and
1957 * over again, so we use fbcon_bmove_rec()
1958 */
1959 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1960 p->vrows - p->yscroll);
1961}
1962
1963static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1964 int dy, int dx, int height, int width, u_int y_break)
1965{
1966 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1967 struct fbcon_ops *ops = info->fbcon_par;
1968 u_int b;
1969
1970 if (sy < y_break && sy + height > y_break) {
1971 b = y_break - sy;
1972 if (dy < sy) { /* Avoid trashing self */
1973 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1974 y_break);
1975 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1976 height - b, width, y_break);
1977 } else {
1978 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1979 height - b, width, y_break);
1980 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1981 y_break);
1982 }
1983 return;
1984 }
1985
1986 if (dy < y_break && dy + height > y_break) {
1987 b = y_break - dy;
1988 if (dy < sy) { /* Avoid trashing self */
1989 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1990 y_break);
1991 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1992 height - b, width, y_break);
1993 } else {
1994 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1995 height - b, width, y_break);
1996 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1997 y_break);
1998 }
1999 return;
2000 }
2001 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2002 height, width);
2003}
2004
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002005static __inline__ void updatescrollmode(struct display *p,
2006 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 struct vc_data *vc)
2008{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002009 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 int fh = vc->vc_font.height;
2011 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002012 u16 t = 0;
2013 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2014 info->fix.xpanstep);
2015 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2016 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2017 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2018 info->var.xres_virtual);
2019 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2020 divides(ypan, vc->vc_font.height) && vyres > yres;
2021 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2022 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002023 divides(vc->vc_font.height, vyres) &&
2024 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002026 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2027 !(cap & FBINFO_HWACCEL_DISABLED);
2028 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2029 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002031 p->vrows = vyres/fh;
2032 if (yres > (fh * (vc->vc_rows + 1)))
2033 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2034 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 p->vrows--;
2036
2037 if (good_wrap || good_pan) {
2038 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002039 p->scrollmode = good_wrap ?
2040 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 else
2042 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2043 SCROLL_PAN_REDRAW;
2044 } else {
2045 if (reading_fast || (fast_copyarea && !fast_imageblit))
2046 p->scrollmode = SCROLL_MOVE;
2047 else
2048 p->scrollmode = SCROLL_REDRAW;
2049 }
2050}
2051
2052static int fbcon_resize(struct vc_data *vc, unsigned int width,
2053 unsigned int height)
2054{
2055 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002056 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 struct display *p = &fb_display[vc->vc_num];
2058 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002059 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002061 virt_w = FBCON_SWAP(ops->rotate, width, height);
2062 virt_h = FBCON_SWAP(ops->rotate, height, width);
2063 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2064 vc->vc_font.height);
2065 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2066 vc->vc_font.width);
2067 var.xres = virt_w * virt_fw;
2068 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 x_diff = info->var.xres - var.xres;
2070 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002071 if (x_diff < 0 || x_diff > virt_fw ||
2072 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002073 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2076 mode = fb_find_best_mode(&var, &info->modelist);
2077 if (mode == NULL)
2078 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002079 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002081
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002082 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2086 if (CON_IS_VISIBLE(vc)) {
2087 var.activate = FB_ACTIVATE_NOW |
2088 FB_ACTIVATE_FORCE;
2089 fb_set_var(info, &var);
2090 }
2091 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002092 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 }
2094 updatescrollmode(p, info, vc);
2095 return 0;
2096}
2097
2098static int fbcon_switch(struct vc_data *vc)
2099{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002100 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002101 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 struct display *p = &fb_display[vc->vc_num];
2103 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002104 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002107 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 if (softback_lines)
2111 fbcon_set_origin(vc);
2112 softback_top = softback_curr = softback_in = softback_buf;
2113 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002114 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 }
2116
2117 if (logo_shown >= 0) {
2118 struct vc_data *conp2 = vc_cons[logo_shown].d;
2119
2120 if (conp2->vc_top == logo_lines
2121 && conp2->vc_bottom == conp2->vc_rows)
2122 conp2->vc_top = 0;
2123 logo_shown = FBCON_LOGO_CANSHOW;
2124 }
2125
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002126 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002127 if (prev_console != -1)
2128 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 /*
2130 * FIXME: If we have multiple fbdev's loaded, we need to
2131 * update all info->currcon. Perhaps, we can place this
2132 * in a centralized structure, but this might break some
2133 * drivers.
2134 *
2135 * info->currcon = vc->vc_num;
2136 */
2137 for (i = 0; i < FB_MAX; i++) {
2138 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002139 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002141 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 }
2143 }
2144 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2145 display_to_var(&var, p);
2146 var.activate = FB_ACTIVATE_NOW;
2147
2148 /*
2149 * make sure we don't unnecessarily trip the memcmp()
2150 * in fb_set_var()
2151 */
2152 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002153 var.yoffset = info->var.yoffset;
2154 var.xoffset = info->var.xoffset;
2155 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002157 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Knut Petersen39942fd2005-12-12 22:17:19 -08002159 if (old_info != NULL && (old_info != info ||
2160 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002161 if (info->fbops->fb_set_par)
2162 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002163
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002164 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002165 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002168 if (fbcon_is_inactive(vc, info) ||
2169 ops->blank_state != FB_BLANK_UNBLANK)
2170 fbcon_del_cursor_timer(info);
2171 else
2172 fbcon_add_cursor_timer(info);
2173
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002174 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002175 ops->cursor_reset = 1;
2176
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002177 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002178 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002179 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002182 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002184
2185 if (p->userfont)
2186 charcnt = FNTCHARCNT(vc->vc_font.data);
2187
2188 if (charcnt > 256)
2189 vc->vc_complement_mask <<= 1;
2190
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 updatescrollmode(p, info, vc);
2192
2193 switch (p->scrollmode) {
2194 case SCROLL_WRAP_MOVE:
2195 scrollback_phys_max = p->vrows - vc->vc_rows;
2196 break;
2197 case SCROLL_PAN_MOVE:
2198 case SCROLL_PAN_REDRAW:
2199 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2200 if (scrollback_phys_max < 0)
2201 scrollback_phys_max = 0;
2202 break;
2203 default:
2204 scrollback_phys_max = 0;
2205 break;
2206 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 scrollback_max = 0;
2209 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002210
2211 if (!fbcon_is_inactive(vc, info)) {
2212 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2213 ops->update_start(info);
2214 }
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 fbcon_set_palette(vc, color_table);
2217 fbcon_clear_margins(vc, 0);
2218
2219 if (logo_shown == FBCON_LOGO_DRAW) {
2220
2221 logo_shown = fg_console;
2222 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002223 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 update_region(vc,
2225 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2226 vc->vc_size_row * (vc->vc_bottom -
2227 vc->vc_top) / 2);
2228 return 0;
2229 }
2230 return 1;
2231}
2232
2233static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2234 int blank)
2235{
Richard Purdie994efac2007-02-09 09:46:45 +00002236 struct fb_event event;
2237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 if (blank) {
2239 unsigned short charmask = vc->vc_hi_font_mask ?
2240 0x1ff : 0xff;
2241 unsigned short oldc;
2242
2243 oldc = vc->vc_video_erase_char;
2244 vc->vc_video_erase_char &= charmask;
2245 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2246 vc->vc_video_erase_char = oldc;
2247 }
Richard Purdie994efac2007-02-09 09:46:45 +00002248
2249
2250 event.info = info;
2251 event.data = &blank;
2252 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253}
2254
2255static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2256{
2257 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2258 struct fbcon_ops *ops = info->fbcon_par;
2259
2260 if (mode_switch) {
2261 struct fb_var_screeninfo var = info->var;
2262
2263 ops->graphics = 1;
2264
2265 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002266 if (info->fbops->fb_save_state)
2267 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2269 fb_set_var(info, &var);
2270 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002271 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002272 } else if (info->fbops->fb_restore_state)
2273 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 }
2275
2276 if (!fbcon_is_inactive(vc, info)) {
2277 if (ops->blank_state != blank) {
2278 ops->blank_state = blank;
2279 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2280 ops->cursor_flash = (!blank);
2281
2282 if (fb_blank(info, blank))
2283 fbcon_generic_blank(vc, info, blank);
2284 }
2285
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002286 if (!blank)
2287 update_screen(vc);
2288 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002290 if (fbcon_is_inactive(vc, info) ||
2291 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002292 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002293 else
2294 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002295
2296 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297}
2298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2300{
2301 u8 *fontdata = vc->vc_font.data;
2302 u8 *data = font->data;
2303 int i, j;
2304
2305 font->width = vc->vc_font.width;
2306 font->height = vc->vc_font.height;
2307 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2308 if (!font->data)
2309 return 0;
2310
2311 if (font->width <= 8) {
2312 j = vc->vc_font.height;
2313 for (i = 0; i < font->charcount; i++) {
2314 memcpy(data, fontdata, j);
2315 memset(data + j, 0, 32 - j);
2316 data += 32;
2317 fontdata += j;
2318 }
2319 } else if (font->width <= 16) {
2320 j = vc->vc_font.height * 2;
2321 for (i = 0; i < font->charcount; i++) {
2322 memcpy(data, fontdata, j);
2323 memset(data + j, 0, 64 - j);
2324 data += 64;
2325 fontdata += j;
2326 }
2327 } else if (font->width <= 24) {
2328 for (i = 0; i < font->charcount; i++) {
2329 for (j = 0; j < vc->vc_font.height; j++) {
2330 *data++ = fontdata[0];
2331 *data++ = fontdata[1];
2332 *data++ = fontdata[2];
2333 fontdata += sizeof(u32);
2334 }
2335 memset(data, 0, 3 * (32 - j));
2336 data += 3 * (32 - j);
2337 }
2338 } else {
2339 j = vc->vc_font.height * 4;
2340 for (i = 0; i < font->charcount; i++) {
2341 memcpy(data, fontdata, j);
2342 memset(data + j, 0, 128 - j);
2343 data += 128;
2344 fontdata += j;
2345 }
2346 }
2347 return 0;
2348}
2349
2350static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002351 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352{
2353 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002354 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct display *p = &fb_display[vc->vc_num];
2356 int resize;
2357 int cnt;
2358 char *old_data = NULL;
2359
2360 if (CON_IS_VISIBLE(vc) && softback_lines)
2361 fbcon_set_origin(vc);
2362
2363 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2364 if (p->userfont)
2365 old_data = vc->vc_font.data;
2366 if (userfont)
2367 cnt = FNTCHARCNT(data);
2368 else
2369 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002370 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 if ((p->userfont = userfont))
2372 REFCOUNT(data)++;
2373 vc->vc_font.width = w;
2374 vc->vc_font.height = h;
2375 if (vc->vc_hi_font_mask && cnt == 256) {
2376 vc->vc_hi_font_mask = 0;
2377 if (vc->vc_can_do_color) {
2378 vc->vc_complement_mask >>= 1;
2379 vc->vc_s_complement_mask >>= 1;
2380 }
2381
2382 /* ++Edmund: reorder the attribute bits */
2383 if (vc->vc_can_do_color) {
2384 unsigned short *cp =
2385 (unsigned short *) vc->vc_origin;
2386 int count = vc->vc_screenbuf_size / 2;
2387 unsigned short c;
2388 for (; count > 0; count--, cp++) {
2389 c = scr_readw(cp);
2390 scr_writew(((c & 0xfe00) >> 1) |
2391 (c & 0xff), cp);
2392 }
2393 c = vc->vc_video_erase_char;
2394 vc->vc_video_erase_char =
2395 ((c & 0xfe00) >> 1) | (c & 0xff);
2396 vc->vc_attr >>= 1;
2397 }
2398 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2399 vc->vc_hi_font_mask = 0x100;
2400 if (vc->vc_can_do_color) {
2401 vc->vc_complement_mask <<= 1;
2402 vc->vc_s_complement_mask <<= 1;
2403 }
2404
2405 /* ++Edmund: reorder the attribute bits */
2406 {
2407 unsigned short *cp =
2408 (unsigned short *) vc->vc_origin;
2409 int count = vc->vc_screenbuf_size / 2;
2410 unsigned short c;
2411 for (; count > 0; count--, cp++) {
2412 unsigned short newc;
2413 c = scr_readw(cp);
2414 if (vc->vc_can_do_color)
2415 newc =
2416 ((c & 0xff00) << 1) | (c &
2417 0xff);
2418 else
2419 newc = c & ~0x100;
2420 scr_writew(newc, cp);
2421 }
2422 c = vc->vc_video_erase_char;
2423 if (vc->vc_can_do_color) {
2424 vc->vc_video_erase_char =
2425 ((c & 0xff00) << 1) | (c & 0xff);
2426 vc->vc_attr <<= 1;
2427 } else
2428 vc->vc_video_erase_char = c & ~0x100;
2429 }
2430
2431 }
2432
2433 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002434 int cols, rows;
2435
2436 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2437 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2438 cols /= w;
2439 rows /= h;
2440 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002441 if (CON_IS_VISIBLE(vc) && softback_buf)
2442 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 } else if (CON_IS_VISIBLE(vc)
2444 && vc->vc_mode == KD_TEXT) {
2445 fbcon_clear_margins(vc, 0);
2446 update_screen(vc);
2447 }
2448
2449 if (old_data && (--REFCOUNT(old_data) == 0))
2450 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2451 return 0;
2452}
2453
2454static int fbcon_copy_font(struct vc_data *vc, int con)
2455{
2456 struct display *od = &fb_display[con];
2457 struct console_font *f = &vc->vc_font;
2458
2459 if (od->fontdata == f->data)
2460 return 0; /* already the same font... */
2461 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2462}
2463
2464/*
2465 * User asked to set font; we are guaranteed that
2466 * a) width and height are in range 1..32
2467 * b) charcount does not exceed 512
2468 * but lets not assume that, since someone might someday want to use larger
2469 * fonts. And charcount of 512 is small for unicode support.
2470 *
2471 * However, user space gives the font in 32 rows , regardless of
2472 * actual font height. So a new API is needed if support for larger fonts
2473 * is ever implemented.
2474 */
2475
2476static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2477{
2478 unsigned charcount = font->charcount;
2479 int w = font->width;
2480 int h = font->height;
2481 int size;
2482 int i, csum;
2483 u8 *new_data, *data = font->data;
2484 int pitch = (font->width+7) >> 3;
2485
2486 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2487 * If not this check should be changed to charcount < 256 */
2488 if (charcount != 256 && charcount != 512)
2489 return -EINVAL;
2490
2491 size = h * pitch * charcount;
2492
2493 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2494
2495 if (!new_data)
2496 return -ENOMEM;
2497
2498 new_data += FONT_EXTRA_WORDS * sizeof(int);
2499 FNTSIZE(new_data) = size;
2500 FNTCHARCNT(new_data) = charcount;
2501 REFCOUNT(new_data) = 0; /* usage counter */
2502 for (i=0; i< charcount; i++) {
2503 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2504 }
2505
2506 /* Since linux has a nice crc32 function use it for counting font
2507 * checksums. */
2508 csum = crc32(0, new_data, size);
2509
2510 FNTSUM(new_data) = csum;
2511 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002512 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 struct vc_data *tmp = vc_cons[i].d;
2514
2515 if (fb_display[i].userfont &&
2516 fb_display[i].fontdata &&
2517 FNTSUM(fb_display[i].fontdata) == csum &&
2518 FNTSIZE(fb_display[i].fontdata) == size &&
2519 tmp->vc_font.width == w &&
2520 !memcmp(fb_display[i].fontdata, new_data, size)) {
2521 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002522 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 break;
2524 }
2525 }
2526 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2527}
2528
2529static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2530{
2531 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002532 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534 if (!name)
2535 f = get_default_font(info->var.xres, info->var.yres);
2536 else if (!(f = find_font(name)))
2537 return -ENOENT;
2538
2539 font->width = f->width;
2540 font->height = f->height;
2541 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2542}
2543
2544static u16 palette_red[16];
2545static u16 palette_green[16];
2546static u16 palette_blue[16];
2547
2548static struct fb_cmap palette_cmap = {
2549 0, 16, palette_red, palette_green, palette_blue, NULL
2550};
2551
2552static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2553{
2554 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2555 int i, j, k, depth;
2556 u8 val;
2557
2558 if (fbcon_is_inactive(vc, info))
2559 return -EINVAL;
2560
2561 if (!CON_IS_VISIBLE(vc))
2562 return 0;
2563
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002564 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 if (depth > 3) {
2566 for (i = j = 0; i < 16; i++) {
2567 k = table[i];
2568 val = vc->vc_palette[j++];
2569 palette_red[k] = (val << 8) | val;
2570 val = vc->vc_palette[j++];
2571 palette_green[k] = (val << 8) | val;
2572 val = vc->vc_palette[j++];
2573 palette_blue[k] = (val << 8) | val;
2574 }
2575 palette_cmap.len = 16;
2576 palette_cmap.start = 0;
2577 /*
2578 * If framebuffer is capable of less than 16 colors,
2579 * use default palette of fbcon.
2580 */
2581 } else
2582 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2583
2584 return fb_set_cmap(&palette_cmap, info);
2585}
2586
2587static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2588{
2589 unsigned long p;
2590 int line;
2591
2592 if (vc->vc_num != fg_console || !softback_lines)
2593 return (u16 *) (vc->vc_origin + offset);
2594 line = offset / vc->vc_size_row;
2595 if (line >= softback_lines)
2596 return (u16 *) (vc->vc_origin + offset -
2597 softback_lines * vc->vc_size_row);
2598 p = softback_curr + offset;
2599 if (p >= softback_end)
2600 p += softback_buf - softback_end;
2601 return (u16 *) p;
2602}
2603
2604static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2605 int *px, int *py)
2606{
2607 unsigned long ret;
2608 int x, y;
2609
2610 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2611 unsigned long offset = (pos - vc->vc_origin) / 2;
2612
2613 x = offset % vc->vc_cols;
2614 y = offset / vc->vc_cols;
2615 if (vc->vc_num == fg_console)
2616 y += softback_lines;
2617 ret = pos + (vc->vc_cols - x) * 2;
2618 } else if (vc->vc_num == fg_console && softback_lines) {
2619 unsigned long offset = pos - softback_curr;
2620
2621 if (pos < softback_curr)
2622 offset += softback_end - softback_buf;
2623 offset /= 2;
2624 x = offset % vc->vc_cols;
2625 y = offset / vc->vc_cols;
2626 ret = pos + (vc->vc_cols - x) * 2;
2627 if (ret == softback_end)
2628 ret = softback_buf;
2629 if (ret == softback_in)
2630 ret = vc->vc_origin;
2631 } else {
2632 /* Should not happen */
2633 x = y = 0;
2634 ret = vc->vc_origin;
2635 }
2636 if (px)
2637 *px = x;
2638 if (py)
2639 *py = y;
2640 return ret;
2641}
2642
2643/* As we might be inside of softback, we may work with non-contiguous buffer,
2644 that's why we have to use a separate routine. */
2645static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2646{
2647 while (cnt--) {
2648 u16 a = scr_readw(p);
2649 if (!vc->vc_can_do_color)
2650 a ^= 0x0800;
2651 else if (vc->vc_hi_font_mask == 0x100)
2652 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2653 (((a) & 0x0e00) << 4);
2654 else
2655 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2656 (((a) & 0x0700) << 4);
2657 scr_writew(a, p++);
2658 if (p == (u16 *) softback_end)
2659 p = (u16 *) softback_buf;
2660 if (p == (u16 *) softback_in)
2661 p = (u16 *) vc->vc_origin;
2662 }
2663}
2664
2665static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2666{
2667 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002668 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 struct display *p = &fb_display[fg_console];
2670 int offset, limit, scrollback_old;
2671
2672 if (softback_top) {
2673 if (vc->vc_num != fg_console)
2674 return 0;
2675 if (vc->vc_mode != KD_TEXT || !lines)
2676 return 0;
2677 if (logo_shown >= 0) {
2678 struct vc_data *conp2 = vc_cons[logo_shown].d;
2679
2680 if (conp2->vc_top == logo_lines
2681 && conp2->vc_bottom == conp2->vc_rows)
2682 conp2->vc_top = 0;
2683 if (logo_shown == vc->vc_num) {
2684 unsigned long p, q;
2685 int i;
2686
2687 p = softback_in;
2688 q = vc->vc_origin +
2689 logo_lines * vc->vc_size_row;
2690 for (i = 0; i < logo_lines; i++) {
2691 if (p == softback_top)
2692 break;
2693 if (p == softback_buf)
2694 p = softback_end;
2695 p -= vc->vc_size_row;
2696 q -= vc->vc_size_row;
2697 scr_memcpyw((u16 *) q, (u16 *) p,
2698 vc->vc_size_row);
2699 }
David Hollister308af922006-05-30 21:25:36 -07002700 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 update_region(vc, vc->vc_origin,
2702 logo_lines * vc->vc_cols);
2703 }
2704 logo_shown = FBCON_LOGO_CANSHOW;
2705 }
2706 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2707 fbcon_redraw_softback(vc, p, lines);
2708 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2709 return 0;
2710 }
2711
2712 if (!scrollback_phys_max)
2713 return -ENOSYS;
2714
2715 scrollback_old = scrollback_current;
2716 scrollback_current -= lines;
2717 if (scrollback_current < 0)
2718 scrollback_current = 0;
2719 else if (scrollback_current > scrollback_max)
2720 scrollback_current = scrollback_max;
2721 if (scrollback_current == scrollback_old)
2722 return 0;
2723
2724 if (fbcon_is_inactive(vc, info))
2725 return 0;
2726
2727 fbcon_cursor(vc, CM_ERASE);
2728
2729 offset = p->yscroll - scrollback_current;
2730 limit = p->vrows;
2731 switch (p->scrollmode) {
2732 case SCROLL_WRAP_MOVE:
2733 info->var.vmode |= FB_VMODE_YWRAP;
2734 break;
2735 case SCROLL_PAN_MOVE:
2736 case SCROLL_PAN_REDRAW:
2737 limit -= vc->vc_rows;
2738 info->var.vmode &= ~FB_VMODE_YWRAP;
2739 break;
2740 }
2741 if (offset < 0)
2742 offset += limit;
2743 else if (offset >= limit)
2744 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002745
2746 ops->var.xoffset = 0;
2747 ops->var.yoffset = offset * vc->vc_font.height;
2748 ops->update_start(info);
2749
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if (!scrollback_current)
2751 fbcon_cursor(vc, CM_DRAW);
2752 return 0;
2753}
2754
2755static int fbcon_set_origin(struct vc_data *vc)
2756{
2757 if (softback_lines)
2758 fbcon_scrolldelta(vc, softback_lines);
2759 return 0;
2760}
2761
2762static void fbcon_suspended(struct fb_info *info)
2763{
2764 struct vc_data *vc = NULL;
2765 struct fbcon_ops *ops = info->fbcon_par;
2766
2767 if (!ops || ops->currcon < 0)
2768 return;
2769 vc = vc_cons[ops->currcon].d;
2770
2771 /* Clear cursor, restore saved data */
2772 fbcon_cursor(vc, CM_ERASE);
2773}
2774
2775static void fbcon_resumed(struct fb_info *info)
2776{
2777 struct vc_data *vc;
2778 struct fbcon_ops *ops = info->fbcon_par;
2779
2780 if (!ops || ops->currcon < 0)
2781 return;
2782 vc = vc_cons[ops->currcon].d;
2783
2784 update_screen(vc);
2785}
2786
2787static void fbcon_modechanged(struct fb_info *info)
2788{
2789 struct fbcon_ops *ops = info->fbcon_par;
2790 struct vc_data *vc;
2791 struct display *p;
2792 int rows, cols;
2793
2794 if (!ops || ops->currcon < 0)
2795 return;
2796 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002797 if (vc->vc_mode != KD_TEXT ||
2798 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 return;
2800
2801 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002802 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
2804 if (CON_IS_VISIBLE(vc)) {
2805 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002806 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2807 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2808 cols /= vc->vc_font.width;
2809 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 vc_resize(vc, cols, rows);
2811 updatescrollmode(p, info, vc);
2812 scrollback_max = 0;
2813 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002814
2815 if (!fbcon_is_inactive(vc, info)) {
2816 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2817 ops->update_start(info);
2818 }
2819
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 fbcon_set_palette(vc, color_table);
2821 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002822 if (softback_buf)
2823 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 }
2825}
2826
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002827static void fbcon_set_all_vcs(struct fb_info *info)
2828{
2829 struct fbcon_ops *ops = info->fbcon_par;
2830 struct vc_data *vc;
2831 struct display *p;
2832 int i, rows, cols;
2833
2834 if (!ops || ops->currcon < 0)
2835 return;
2836
Antonino A. Daplase614b182006-06-26 00:27:09 -07002837 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002838 vc = vc_cons[i].d;
2839 if (!vc || vc->vc_mode != KD_TEXT ||
2840 registered_fb[con2fb_map[i]] != info)
2841 continue;
2842
2843 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002844 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002845 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002846 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2847 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2848 cols /= vc->vc_font.width;
2849 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002850 vc_resize(vc, cols, rows);
2851
2852 if (CON_IS_VISIBLE(vc)) {
2853 updatescrollmode(p, info, vc);
2854 scrollback_max = 0;
2855 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002856
2857 if (!fbcon_is_inactive(vc, info)) {
2858 ops->var.xoffset = ops->var.yoffset =
2859 p->yscroll = 0;
2860 ops->update_start(info);
2861 }
2862
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002863 fbcon_set_palette(vc, color_table);
2864 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002865 if (softback_buf)
2866 fbcon_update_softback(vc);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002867 }
2868 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002869
2870 ops->p = &fb_display[ops->currcon];
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002871}
2872
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873static int fbcon_mode_deleted(struct fb_info *info,
2874 struct fb_videomode *mode)
2875{
2876 struct fb_info *fb_info;
2877 struct display *p;
2878 int i, j, found = 0;
2879
2880 /* before deletion, ensure that mode is not in use */
2881 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2882 j = con2fb_map[i];
2883 if (j == -1)
2884 continue;
2885 fb_info = registered_fb[j];
2886 if (fb_info != info)
2887 continue;
2888 p = &fb_display[i];
2889 if (!p || !p->mode)
2890 continue;
2891 if (fb_mode_is_equal(p->mode, mode)) {
2892 found = 1;
2893 break;
2894 }
2895 }
2896 return found;
2897}
2898
Antonino A. Daplase614b182006-06-26 00:27:09 -07002899static int fbcon_fb_unregistered(int idx)
2900{
2901 int i;
2902
2903 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2904 if (con2fb_map[i] == idx)
2905 con2fb_map[i] = -1;
2906 }
2907
2908 if (idx == info_idx) {
2909 info_idx = -1;
2910
2911 for (i = 0; i < FB_MAX; i++) {
2912 if (registered_fb[i] != NULL) {
2913 info_idx = i;
2914 break;
2915 }
2916 }
2917 }
2918
2919 if (info_idx != -1) {
2920 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2921 if (con2fb_map[i] == -1)
2922 con2fb_map[i] = info_idx;
2923 }
2924 }
2925
2926 if (!num_registered_fb)
2927 unregister_con_driver(&fb_con);
2928
2929 return 0;
2930}
2931
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932static int fbcon_fb_registered(int idx)
2933{
2934 int ret = 0, i;
2935
2936 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002937 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 if (con2fb_map_boot[i] == idx) {
2939 info_idx = idx;
2940 break;
2941 }
2942 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07002943
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 if (info_idx != -1)
2945 ret = fbcon_takeover(1);
2946 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07002947 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002948 if (con2fb_map_boot[i] == idx &&
2949 con2fb_map[i] == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 set_con2fb_map(i, idx, 0);
2951 }
2952 }
2953
2954 return ret;
2955}
2956
2957static void fbcon_fb_blanked(struct fb_info *info, int blank)
2958{
2959 struct fbcon_ops *ops = info->fbcon_par;
2960 struct vc_data *vc;
2961
2962 if (!ops || ops->currcon < 0)
2963 return;
2964
2965 vc = vc_cons[ops->currcon].d;
2966 if (vc->vc_mode != KD_TEXT ||
2967 registered_fb[con2fb_map[ops->currcon]] != info)
2968 return;
2969
2970 if (CON_IS_VISIBLE(vc)) {
2971 if (blank)
2972 do_blank_screen(0);
2973 else
2974 do_unblank_screen(0);
2975 }
2976 ops->blank_state = blank;
2977}
2978
2979static void fbcon_new_modelist(struct fb_info *info)
2980{
2981 int i;
2982 struct vc_data *vc;
2983 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002984 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
Antonino A. Daplase614b182006-06-26 00:27:09 -07002986 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 if (registered_fb[con2fb_map[i]] != info)
2988 continue;
2989 if (!fb_display[i].mode)
2990 continue;
2991 vc = vc_cons[i].d;
2992 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08002993 mode = fb_find_nearest_mode(fb_display[i].mode,
2994 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 fb_videomode_to_var(&var, mode);
2996
2997 if (vc)
2998 fbcon_set_disp(info, &var, vc);
2999 else
3000 fbcon_preset_disp(info, &var, i);
3001
3002 }
3003}
3004
3005static int fbcon_event_notify(struct notifier_block *self,
3006 unsigned long action, void *data)
3007{
3008 struct fb_event *event = data;
3009 struct fb_info *info = event->info;
3010 struct fb_videomode *mode;
3011 struct fb_con2fbmap *con2fb;
3012 int ret = 0;
3013
Antonino A. Daplase614b182006-06-26 00:27:09 -07003014 /*
3015 * ignore all events except driver registration and deregistration
3016 * if fbcon is not active
3017 */
3018 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3019 action == FB_EVENT_FB_UNREGISTERED))
3020 goto done;
3021
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 switch(action) {
3023 case FB_EVENT_SUSPEND:
3024 fbcon_suspended(info);
3025 break;
3026 case FB_EVENT_RESUME:
3027 fbcon_resumed(info);
3028 break;
3029 case FB_EVENT_MODE_CHANGE:
3030 fbcon_modechanged(info);
3031 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003032 case FB_EVENT_MODE_CHANGE_ALL:
3033 fbcon_set_all_vcs(info);
3034 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 case FB_EVENT_MODE_DELETE:
3036 mode = event->data;
3037 ret = fbcon_mode_deleted(info, mode);
3038 break;
3039 case FB_EVENT_FB_REGISTERED:
3040 ret = fbcon_fb_registered(info->node);
3041 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003042 case FB_EVENT_FB_UNREGISTERED:
3043 ret = fbcon_fb_unregistered(info->node);
3044 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 case FB_EVENT_SET_CONSOLE_MAP:
3046 con2fb = event->data;
3047 ret = set_con2fb_map(con2fb->console - 1,
3048 con2fb->framebuffer, 1);
3049 break;
3050 case FB_EVENT_GET_CONSOLE_MAP:
3051 con2fb = event->data;
3052 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3053 break;
3054 case FB_EVENT_BLANK:
3055 fbcon_fb_blanked(info, *(int *)event->data);
3056 break;
3057 case FB_EVENT_NEW_MODELIST:
3058 fbcon_new_modelist(info);
3059 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
3061
Antonino A. Daplase614b182006-06-26 00:27:09 -07003062done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 return ret;
3064}
3065
3066/*
3067 * The console `switch' structure for the frame buffer based console
3068 */
3069
3070static const struct consw fb_con = {
3071 .owner = THIS_MODULE,
3072 .con_startup = fbcon_startup,
3073 .con_init = fbcon_init,
3074 .con_deinit = fbcon_deinit,
3075 .con_clear = fbcon_clear,
3076 .con_putc = fbcon_putc,
3077 .con_putcs = fbcon_putcs,
3078 .con_cursor = fbcon_cursor,
3079 .con_scroll = fbcon_scroll,
3080 .con_bmove = fbcon_bmove,
3081 .con_switch = fbcon_switch,
3082 .con_blank = fbcon_blank,
3083 .con_font_set = fbcon_set_font,
3084 .con_font_get = fbcon_get_font,
3085 .con_font_default = fbcon_set_def_font,
3086 .con_font_copy = fbcon_copy_font,
3087 .con_set_palette = fbcon_set_palette,
3088 .con_scrolldelta = fbcon_scrolldelta,
3089 .con_set_origin = fbcon_set_origin,
3090 .con_invert_region = fbcon_invert_region,
3091 .con_screen_pos = fbcon_screen_pos,
3092 .con_getxy = fbcon_getxy,
3093 .con_resize = fbcon_resize,
3094};
3095
3096static struct notifier_block fbcon_event_notifier = {
3097 .notifier_call = fbcon_event_notify,
3098};
3099
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003100static ssize_t store_rotate(struct class_device *class_device,
3101 const char *buf, size_t count)
3102{
3103 struct fb_info *info;
3104 int rotate, idx;
3105 char **last = NULL;
3106
Antonino A. Daplase614b182006-06-26 00:27:09 -07003107 if (fbcon_has_exited)
3108 return count;
3109
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003110 acquire_console_sem();
3111 idx = con2fb_map[fg_console];
3112
3113 if (idx == -1 || registered_fb[idx] == NULL)
3114 goto err;
3115
3116 info = registered_fb[idx];
3117 rotate = simple_strtoul(buf, last, 0);
3118 fbcon_rotate(info, rotate);
3119err:
3120 release_console_sem();
3121 return count;
3122}
3123
3124static ssize_t store_rotate_all(struct class_device *class_device,
3125 const char *buf, size_t count)
3126{
3127 struct fb_info *info;
3128 int rotate, idx;
3129 char **last = NULL;
3130
Antonino A. Daplase614b182006-06-26 00:27:09 -07003131 if (fbcon_has_exited)
3132 return count;
3133
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003134 acquire_console_sem();
3135 idx = con2fb_map[fg_console];
3136
3137 if (idx == -1 || registered_fb[idx] == NULL)
3138 goto err;
3139
3140 info = registered_fb[idx];
3141 rotate = simple_strtoul(buf, last, 0);
3142 fbcon_rotate_all(info, rotate);
3143err:
3144 release_console_sem();
3145 return count;
3146}
3147
3148static ssize_t show_rotate(struct class_device *class_device, char *buf)
3149{
3150 struct fb_info *info;
3151 int rotate = 0, idx;
3152
Antonino A. Daplase614b182006-06-26 00:27:09 -07003153 if (fbcon_has_exited)
3154 return 0;
3155
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003156 acquire_console_sem();
3157 idx = con2fb_map[fg_console];
3158
3159 if (idx == -1 || registered_fb[idx] == NULL)
3160 goto err;
3161
3162 info = registered_fb[idx];
3163 rotate = fbcon_get_rotate(info);
3164err:
3165 release_console_sem();
3166 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3167}
3168
3169static struct class_device_attribute class_device_attrs[] = {
3170 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3171 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3172};
3173
3174static int fbcon_init_class_device(void)
3175{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003176 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003177
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003178 fbcon_has_sysfs = 1;
3179
3180 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3181 error = class_device_create_file(fbcon_class_device,
3182 &class_device_attrs[i]);
3183
3184 if (error)
3185 break;
3186 }
3187
3188 if (error) {
3189 while (--i >= 0)
3190 class_device_remove_file(fbcon_class_device,
3191 &class_device_attrs[i]);
3192
3193 fbcon_has_sysfs = 0;
3194 }
3195
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003196 return 0;
3197}
3198
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003199static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003202 int i;
3203
3204 acquire_console_sem();
3205
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 for (i = 0; i < FB_MAX; i++) {
3207 if (registered_fb[i] != NULL) {
3208 info_idx = i;
3209 break;
3210 }
3211 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003212
3213 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 fbcon_takeover(0);
3215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216}
3217
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003218static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003219{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003220 struct fb_info *info;
3221 int i, j, mapped;
3222
Antonino A. Daplase614b182006-06-26 00:27:09 -07003223 if (fbcon_has_exited)
3224 return;
3225
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003226#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003227 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003228#endif
3229#ifdef CONFIG_MAC
3230 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003231 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003232#endif
3233
3234 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003235 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003236
3237 for (i = 0; i < FB_MAX; i++) {
3238 mapped = 0;
3239 info = registered_fb[i];
3240
3241 if (info == NULL)
3242 continue;
3243
Antonino A. Daplase614b182006-06-26 00:27:09 -07003244 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3245 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003246 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003247 }
3248
3249 if (mapped) {
3250 if (info->fbops->fb_release)
3251 info->fbops->fb_release(info, 0);
3252 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003253
3254 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003255 struct fbcon_ops *ops = info->fbcon_par;
3256
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003257 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003258 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003259 kfree(info->fbcon_par);
3260 info->fbcon_par = NULL;
3261 }
3262
3263 if (info->queue.func == fb_flashcursor)
3264 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003265 }
3266 }
3267
Antonino A. Daplase614b182006-06-26 00:27:09 -07003268 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003269}
3270
3271static int __init fb_console_init(void)
3272{
3273 int i;
3274
3275 acquire_console_sem();
3276 fb_register_client(&fbcon_event_notifier);
3277 fbcon_class_device =
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003278 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003279
3280 if (IS_ERR(fbcon_class_device)) {
3281 printk(KERN_WARNING "Unable to create class_device "
3282 "for fbcon; errno = %ld\n",
3283 PTR_ERR(fbcon_class_device));
3284 fbcon_class_device = NULL;
3285 } else
3286 fbcon_init_class_device();
3287
3288 for (i = 0; i < MAX_NR_CONSOLES; i++)
3289 con2fb_map[i] = -1;
3290
3291 release_console_sem();
3292 fbcon_start();
3293 return 0;
3294}
3295
3296module_init(fb_console_init);
3297
3298#ifdef MODULE
3299
Antonino A. Daplase614b182006-06-26 00:27:09 -07003300static void __exit fbcon_deinit_class_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003301{
3302 int i;
3303
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003304 if (fbcon_has_sysfs) {
3305 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3306 class_device_remove_file(fbcon_class_device,
3307 &class_device_attrs[i]);
3308
3309 fbcon_has_sysfs = 0;
3310 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003311}
3312
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313static void __exit fb_console_exit(void)
3314{
3315 acquire_console_sem();
3316 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003317 fbcon_deinit_class_device();
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003318 class_device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003319 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003321 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322}
3323
3324module_exit(fb_console_exit);
3325
3326#endif
3327
3328MODULE_LICENSE("GPL");