]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/video/fbdev/core/fbcon.c
fbcon: Do not takeover the console from atomic context
[thirdparty/kernel/stable.git] / drivers / video / fbdev / core / fbcon.c
CommitLineData
1da177e4
LT
1/*
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
1da177e4
LT
61#include <linux/module.h>
62#include <linux/types.h>
1da177e4
LT
63#include <linux/fs.h>
64#include <linux/kernel.h>
65#include <linux/delay.h> /* MSch: for IRQ probe */
1da177e4
LT
66#include <linux/console.h>
67#include <linux/string.h>
68#include <linux/kd.h>
69#include <linux/slab.h>
70#include <linux/fb.h>
6104c370 71#include <linux/fbcon.h>
1da177e4
LT
72#include <linux/vt_kern.h>
73#include <linux/selection.h>
74#include <linux/font.h>
75#include <linux/smp.h>
76#include <linux/init.h>
77#include <linux/interrupt.h>
78#include <linux/crc32.h> /* For counting font checksums */
623e71b0 79#include <asm/fb.h>
1da177e4 80#include <asm/irq.h>
1da177e4
LT
81
82#include "fbcon.h"
83
84#ifdef FBCONDEBUG
5ae12170 85# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
1da177e4
LT
86#else
87# define DPRINTK(fmt, args...)
88#endif
89
90enum {
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
94};
95
ab767201 96static struct display fb_display[MAX_NR_CONSOLES];
e4fc2761 97
1da177e4
LT
98static signed char con2fb_map[MAX_NR_CONSOLES];
99static signed char con2fb_map_boot[MAX_NR_CONSOLES];
49a1d28f 100
1da177e4
LT
101static int logo_lines;
102/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
103 enums. */
104static int logo_shown = FBCON_LOGO_CANSHOW;
105/* Software scrollback */
106static int fbcon_softback_size = 32768;
107static unsigned long softback_buf, softback_curr;
108static unsigned long softback_in;
109static unsigned long softback_top, softback_end;
110static int softback_lines;
111/* console mappings */
112static int first_fb_vc;
113static int last_fb_vc = MAX_NR_CONSOLES - 1;
114static int fbcon_is_default = 1;
e614b18d 115static int fbcon_has_exited;
623e71b0 116static int primary_device = -1;
2ddce3fd 117static int fbcon_has_console_bind;
4769a9a5
AD
118
119#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
623e71b0 120static int map_override;
e614b18d 121
4769a9a5
AD
122static inline void fbcon_map_override(void)
123{
124 map_override = 1;
125}
126#else
127static inline void fbcon_map_override(void)
128{
129}
130#endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
131
83d83beb
HG
132#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
133static bool deferred_takeover = true;
134#else
135#define deferred_takeover false
136#endif
137
1da177e4
LT
138/* font data */
139static char fontname[40];
140
141/* current fb_info */
142static int info_idx = -1;
143
e4fc2761 144/* console rotation */
b0d8e409 145static int initial_rotation = -1;
0a727dea 146static int fbcon_has_sysfs;
74c1c8b3 147static int margin_color;
e4fc2761 148
1da177e4
LT
149static const struct consw fb_con;
150
151#define CM_SOFTBACK (8)
152
153#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
154
1da177e4
LT
155static int fbcon_set_origin(struct vc_data *);
156
acba9cd0 157static int fbcon_cursor_noblink;
1da177e4
LT
158
159#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
160
161/*
162 * Interface used by the world
163 */
164
165static const char *fbcon_startup(void);
166static void fbcon_init(struct vc_data *vc, int init);
167static void fbcon_deinit(struct vc_data *vc);
168static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
169 int width);
170static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
171static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
172 int count, int ypos, int xpos);
173static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
174static void fbcon_cursor(struct vc_data *vc, int mode);
1da177e4
LT
175static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
176 int height, int width);
177static int fbcon_switch(struct vc_data *vc);
178static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
709280da 179static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
1da177e4
LT
180
181/*
182 * Internal routines
183 */
1da177e4
LT
184static __inline__ void ywrap_up(struct vc_data *vc, int count);
185static __inline__ void ywrap_down(struct vc_data *vc, int count);
186static __inline__ void ypan_up(struct vc_data *vc, int count);
187static __inline__ void ypan_down(struct vc_data *vc, int count);
188static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
d1baa4ff 191 int unit);
1da177e4
LT
192static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
193 int line, int count, int dy);
a812c94b
AD
194static void fbcon_modechanged(struct fb_info *info);
195static void fbcon_set_all_vcs(struct fb_info *info);
5428b044
AD
196static void fbcon_start(void);
197static void fbcon_exit(void);
0c6c1ce0 198static struct device *fbcon_device;
9a179176 199
dbcbfe1e 200#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
b73deed3 201static inline void fbcon_set_rotation(struct fb_info *info)
dbcbfe1e
AD
202{
203 struct fbcon_ops *ops = info->fbcon_par;
204
205 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
b73deed3
AD
206 ops->p->con_rotate < 4)
207 ops->rotate = ops->p->con_rotate;
dbcbfe1e
AD
208 else
209 ops->rotate = 0;
210}
a812c94b
AD
211
212static void fbcon_rotate(struct fb_info *info, u32 rotate)
213{
214 struct fbcon_ops *ops= info->fbcon_par;
215 struct fb_info *fb_info;
216
217 if (!ops || ops->currcon == -1)
218 return;
219
220 fb_info = registered_fb[con2fb_map[ops->currcon]];
221
222 if (info == fb_info) {
223 struct display *p = &fb_display[ops->currcon];
224
225 if (rotate < 4)
226 p->con_rotate = rotate;
227 else
228 p->con_rotate = 0;
229
230 fbcon_modechanged(info);
231 }
232}
233
234static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
235{
236 struct fbcon_ops *ops = info->fbcon_par;
237 struct vc_data *vc;
238 struct display *p;
239 int i;
240
241 if (!ops || ops->currcon < 0 || rotate > 3)
242 return;
243
e614b18d 244 for (i = first_fb_vc; i <= last_fb_vc; i++) {
a812c94b
AD
245 vc = vc_cons[i].d;
246 if (!vc || vc->vc_mode != KD_TEXT ||
247 registered_fb[con2fb_map[i]] != info)
248 continue;
249
250 p = &fb_display[vc->vc_num];
251 p->con_rotate = rotate;
252 }
253
254 fbcon_set_all_vcs(info);
255}
dbcbfe1e 256#else
b73deed3 257static inline void fbcon_set_rotation(struct fb_info *info)
e4fc2761
AD
258{
259 struct fbcon_ops *ops = info->fbcon_par;
260
261 ops->rotate = FB_ROTATE_UR;
262}
a812c94b
AD
263
264static void fbcon_rotate(struct fb_info *info, u32 rotate)
265{
266 return;
267}
268
269static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
270{
271 return;
272}
dbcbfe1e 273#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
e4fc2761 274
a812c94b
AD
275static int fbcon_get_rotate(struct fb_info *info)
276{
277 struct fbcon_ops *ops = info->fbcon_par;
278
279 return (ops) ? ops->rotate : 0;
280}
281
1da177e4
LT
282static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
283{
284 struct fbcon_ops *ops = info->fbcon_par;
285
286 return (info->state != FBINFO_STATE_RUNNING ||
8fd4bd22
JB
287 vc->vc_mode != KD_TEXT || ops->graphics) &&
288 !vt_force_oops_output(vc);
1da177e4
LT
289}
290
da909ce4 291static int get_color(struct vc_data *vc, struct fb_info *info,
1da177e4
LT
292 u16 c, int is_fg)
293{
b8c90945 294 int depth = fb_get_color_depth(&info->var, &info->fix);
1da177e4
LT
295 int color = 0;
296
297 if (console_blanked) {
298 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
299
300 c = vc->vc_video_erase_char & charmask;
301 }
302
303 if (depth != 1)
304 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
305 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
306
307 switch (depth) {
308 case 1:
309 {
91c43132 310 int col = mono_col(info);
1da177e4 311 /* 0 or 1 */
b8c90945
AD
312 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
313 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
1da177e4
LT
314
315 if (console_blanked)
316 fg = bg;
317
318 color = (is_fg) ? fg : bg;
319 break;
320 }
321 case 2:
322 /*
323 * Scale down 16-colors to 4 colors. Default 4-color palette
2cc38ed1
AD
324 * is grayscale. However, simply dividing the values by 4
325 * will not work, as colors 1, 2 and 3 will be scaled-down
326 * to zero rendering them invisible. So empirically convert
327 * colors to a sane 4-level grayscale.
1da177e4 328 */
2cc38ed1
AD
329 switch (color) {
330 case 0:
331 color = 0; /* black */
332 break;
333 case 1 ... 6:
334 color = 2; /* white */
335 break;
336 case 7 ... 8:
337 color = 1; /* gray */
338 break;
339 default:
340 color = 3; /* intense white */
341 break;
342 }
343 break;
1da177e4
LT
344 case 3:
345 /*
346 * Last 8 entries of default 16-color palette is a more intense
347 * version of the first 8 (i.e., same chrominance, different
348 * luminance).
349 */
350 color &= 7;
351 break;
352 }
353
354
355 return color;
356}
357
4d9c5b6e
AD
358static void fbcon_update_softback(struct vc_data *vc)
359{
360 int l = fbcon_softback_size / vc->vc_size_row;
361
362 if (l > 5)
363 softback_end = softback_buf + l * vc->vc_size_row;
364 else
365 /* Smaller scrollback makes no sense, and 0 would screw
366 the operation totally */
367 softback_top = 0;
368}
369
c4028958 370static void fb_flashcursor(struct work_struct *work)
1da177e4 371{
c4028958 372 struct fb_info *info = container_of(work, struct fb_info, queue);
1da177e4 373 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
374 struct vc_data *vc = NULL;
375 int c;
376 int mode;
d8636a27
DA
377 int ret;
378
379 /* FIXME: we should sort out the unbind locking instead */
380 /* instead we just fail to flash the cursor if we can't get
381 * the lock instead of blocking fbcon deinit */
382 ret = console_trylock();
383 if (ret == 0)
384 return;
1da177e4 385
5428b044 386 if (ops && ops->currcon != -1)
1da177e4
LT
387 vc = vc_cons[ops->currcon].d;
388
6ca8dfd7 389 if (!vc || !con_is_visible(vc) ||
dbd4f128 390 registered_fb[con2fb_map[vc->vc_num]] != info ||
212f2639 391 vc->vc_deccm != 1) {
ac751efa 392 console_unlock();
1da177e4 393 return;
5428b044
AD
394 }
395
1da177e4
LT
396 c = scr_readw((u16 *) vc->vc_pos);
397 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
398 CM_ERASE : CM_DRAW;
b73deed3 399 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
1da177e4 400 get_color(vc, info, c, 0));
ac751efa 401 console_unlock();
1da177e4
LT
402}
403
6c789357 404static void cursor_timer_handler(struct timer_list *t)
1da177e4 405{
6c789357
KC
406 struct fbcon_ops *ops = from_timer(ops, t, cursor_timer);
407 struct fb_info *info = ops->info;
1da177e4 408
a85f1a41 409 queue_work(system_power_efficient_wq, &info->queue);
27a4c827 410 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
1da177e4
LT
411}
412
88fb2c6e
AD
413static void fbcon_add_cursor_timer(struct fb_info *info)
414{
415 struct fbcon_ops *ops = info->fbcon_par;
416
417 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
acba9cd0
AD
418 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
419 !fbcon_cursor_noblink) {
88fb2c6e 420 if (!info->queue.func)
c4028958 421 INIT_WORK(&info->queue, fb_flashcursor);
88fb2c6e 422
6c789357 423 timer_setup(&ops->cursor_timer, cursor_timer_handler, 0);
cd7b917c 424 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
88fb2c6e
AD
425 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
426 }
427}
428
429static void fbcon_del_cursor_timer(struct fb_info *info)
430{
431 struct fbcon_ops *ops = info->fbcon_par;
432
433 if (info->queue.func == fb_flashcursor &&
434 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
435 del_timer_sync(&ops->cursor_timer);
436 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
437 }
438}
439
1da177e4
LT
440#ifndef MODULE
441static int __init fb_console_setup(char *this_opt)
442{
443 char *options;
444 int i, j;
445
446 if (!this_opt || !*this_opt)
9b41046c 447 return 1;
1da177e4
LT
448
449 while ((options = strsep(&this_opt, ",")) != NULL) {
37773c4e 450 if (!strncmp(options, "font:", 5)) {
e432964a 451 strlcpy(fontname, options + 5, sizeof(fontname));
37773c4e
MH
452 continue;
453 }
1da177e4
LT
454
455 if (!strncmp(options, "scrollback:", 11)) {
456 options += 11;
457 if (*options) {
458 fbcon_softback_size = simple_strtoul(options, &options, 0);
459 if (*options == 'k' || *options == 'K') {
460 fbcon_softback_size *= 1024;
1da177e4 461 }
37773c4e
MH
462 }
463 continue;
1da177e4
LT
464 }
465
466 if (!strncmp(options, "map:", 4)) {
467 options += 4;
623e71b0 468 if (*options) {
1da177e4
LT
469 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
470 if (!options[j])
471 j = 0;
472 con2fb_map_boot[i] =
473 (options[j++]-'0') % FB_MAX;
474 }
623e71b0 475
4769a9a5 476 fbcon_map_override();
623e71b0 477 }
37773c4e 478 continue;
1da177e4
LT
479 }
480
481 if (!strncmp(options, "vc:", 3)) {
482 options += 3;
483 if (*options)
484 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
485 if (first_fb_vc < 0)
486 first_fb_vc = 0;
487 if (*options++ == '-')
488 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
489 fbcon_is_default = 0;
37773c4e
MH
490 continue;
491 }
e4fc2761
AD
492
493 if (!strncmp(options, "rotate:", 7)) {
494 options += 7;
495 if (*options)
2428e59b
MS
496 initial_rotation = simple_strtoul(options, &options, 0);
497 if (initial_rotation > 3)
498 initial_rotation = 0;
37773c4e 499 continue;
e4fc2761 500 }
74c1c8b3
DL
501
502 if (!strncmp(options, "margin:", 7)) {
503 options += 7;
504 if (*options)
505 margin_color = simple_strtoul(options, &options, 0);
74c1c8b3
DL
506 continue;
507 }
83d83beb
HG
508#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
509 if (!strcmp(options, "nodefer")) {
510 deferred_takeover = false;
511 continue;
512 }
513#endif
1da177e4 514 }
9b41046c 515 return 1;
1da177e4
LT
516}
517
518__setup("fbcon=", fb_console_setup);
519#endif
520
521static int search_fb_in_map(int idx)
522{
523 int i, retval = 0;
524
e614b18d 525 for (i = first_fb_vc; i <= last_fb_vc; i++) {
1da177e4
LT
526 if (con2fb_map[i] == idx)
527 retval = 1;
528 }
529 return retval;
530}
531
532static int search_for_mapped_con(void)
533{
534 int i, retval = 0;
535
e614b18d 536 for (i = first_fb_vc; i <= last_fb_vc; i++) {
1da177e4
LT
537 if (con2fb_map[i] != -1)
538 retval = 1;
539 }
540 return retval;
541}
542
50e244cc
AC
543static int do_fbcon_takeover(int show_logo)
544{
545 int err, i;
546
547 if (!num_registered_fb)
548 return -ENODEV;
549
550 if (!show_logo)
551 logo_shown = FBCON_LOGO_DONTSHOW;
552
553 for (i = first_fb_vc; i <= last_fb_vc; i++)
554 con2fb_map[i] = info_idx;
555
556 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
557 fbcon_is_default);
558
559 if (err) {
560 for (i = first_fb_vc; i <= last_fb_vc; i++)
561 con2fb_map[i] = -1;
562 info_idx = -1;
563 } else {
564 fbcon_has_console_bind = 1;
1da177e4
LT
565 }
566
567 return err;
568}
569
70802c60
AD
570#ifdef MODULE
571static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
572 int cols, int rows, int new_cols, int new_rows)
573{
574 logo_shown = FBCON_LOGO_DONTSHOW;
575}
576#else
1da177e4
LT
577static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
578 int cols, int rows, int new_cols, int new_rows)
579{
580 /* Need to make room for the logo */
9c44e5f6 581 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
582 int cnt, erase = vc->vc_video_erase_char, step;
583 unsigned short *save = NULL, *r, *q;
49a1d28f 584 int logo_height;
1da177e4 585
376b3ff5 586 if (info->fbops->owner) {
70802c60
AD
587 logo_shown = FBCON_LOGO_DONTSHOW;
588 return;
589 }
590
1da177e4
LT
591 /*
592 * remove underline attribute from erase character
593 * if black and white framebuffer.
594 */
b8c90945 595 if (fb_get_color_depth(&info->var, &info->fix) == 1)
1da177e4 596 erase &= ~0x400;
9c44e5f6 597 logo_height = fb_prepare_logo(info, ops->rotate);
416e74ea 598 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
1da177e4
LT
599 q = (unsigned short *) (vc->vc_origin +
600 vc->vc_size_row * rows);
601 step = logo_lines * cols;
602 for (r = q - logo_lines * cols; r < q; r++)
603 if (scr_readw(r) != vc->vc_video_erase_char)
604 break;
605 if (r != q && new_rows >= rows + logo_lines) {
6da2ec56
KC
606 save = kmalloc(array3_size(logo_lines, new_cols, 2),
607 GFP_KERNEL);
1da177e4
LT
608 if (save) {
609 int i = cols < new_cols ? cols : new_cols;
610 scr_memsetw(save, erase, logo_lines * new_cols * 2);
611 r = q - step;
612 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
613 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
614 r = q;
615 }
616 }
617 if (r == q) {
618 /* We can scroll screen down */
619 r = q - step - cols;
620 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
621 scr_memcpyw(r + step, r, vc->vc_size_row);
622 r -= cols;
623 }
624 if (!save) {
250038f5
GU
625 int lines;
626 if (vc->vc_y + logo_lines >= rows)
627 lines = rows - vc->vc_y - 1;
628 else
629 lines = logo_lines;
630 vc->vc_y += lines;
631 vc->vc_pos += lines * vc->vc_size_row;
1da177e4
LT
632 }
633 }
634 scr_memsetw((unsigned short *) vc->vc_origin,
635 erase,
636 vc->vc_size_row * logo_lines);
637
6ca8dfd7 638 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1da177e4
LT
639 fbcon_clear_margins(vc, 0);
640 update_screen(vc);
641 }
642
643 if (save) {
644 q = (unsigned short *) (vc->vc_origin +
645 vc->vc_size_row *
646 rows);
647 scr_memcpyw(q, save, logo_lines * new_cols * 2);
648 vc->vc_y += logo_lines;
649 vc->vc_pos += logo_lines * vc->vc_size_row;
650 kfree(save);
651 }
652
653 if (logo_lines > vc->vc_bottom) {
654 logo_shown = FBCON_LOGO_CANSHOW;
655 printk(KERN_INFO
656 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
657 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
658 logo_shown = FBCON_LOGO_DRAW;
659 vc->vc_top = logo_lines;
660 }
661}
70802c60 662#endif /* MODULE */
1da177e4
LT
663
664#ifdef CONFIG_FB_TILEBLITTING
b73deed3 665static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
1da177e4
LT
666{
667 struct fbcon_ops *ops = info->fbcon_par;
668
b73deed3 669 ops->p = &fb_display[vc->vc_num];
ab767201 670
1da177e4 671 if ((info->flags & FBINFO_MISC_TILEBLITTING))
b73deed3 672 fbcon_set_tileops(vc, info);
e4fc2761 673 else {
b73deed3 674 fbcon_set_rotation(info);
1da177e4 675 fbcon_set_bitops(ops);
e4fc2761 676 }
1da177e4 677}
38b4982c
AD
678
679static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
680{
681 int err = 0;
682
683 if (info->flags & FBINFO_MISC_TILEBLITTING &&
684 info->tileops->fb_get_tilemax(info) < charcount)
685 err = 1;
686
687 return err;
688}
1da177e4 689#else
b73deed3 690static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
1da177e4
LT
691{
692 struct fbcon_ops *ops = info->fbcon_par;
693
694 info->flags &= ~FBINFO_MISC_TILEBLITTING;
b73deed3
AD
695 ops->p = &fb_display[vc->vc_num];
696 fbcon_set_rotation(info);
1da177e4
LT
697 fbcon_set_bitops(ops);
698}
38b4982c
AD
699
700static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
701{
702 return 0;
703}
704
1da177e4
LT
705#endif /* CONFIG_MISC_TILEBLITTING */
706
707
708static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
709 int unit, int oldidx)
710{
711 struct fbcon_ops *ops = NULL;
712 int err = 0;
713
714 if (!try_module_get(info->fbops->owner))
715 err = -ENODEV;
716
717 if (!err && info->fbops->fb_open &&
718 info->fbops->fb_open(info, 0))
719 err = -ENODEV;
720
721 if (!err) {
a39bc34e 722 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
1da177e4
LT
723 if (!ops)
724 err = -ENOMEM;
725 }
726
727 if (!err) {
a1e533ec 728 ops->cur_blink_jiffies = HZ / 5;
6c789357 729 ops->info = info;
1da177e4 730 info->fbcon_par = ops;
d1baa4ff
AD
731
732 if (vc)
733 set_blitting_type(vc, info);
1da177e4
LT
734 }
735
736 if (err) {
737 con2fb_map[unit] = oldidx;
738 module_put(info->fbops->owner);
739 }
740
741 return err;
742}
743
744static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
745 struct fb_info *newinfo, int unit,
746 int oldidx, int found)
747{
748 struct fbcon_ops *ops = oldinfo->fbcon_par;
0fcf6ada 749 int err = 0, ret;
1da177e4
LT
750
751 if (oldinfo->fbops->fb_release &&
752 oldinfo->fbops->fb_release(oldinfo, 0)) {
753 con2fb_map[unit] = oldidx;
754 if (!found && newinfo->fbops->fb_release)
755 newinfo->fbops->fb_release(newinfo, 0);
756 if (!found)
757 module_put(newinfo->fbops->owner);
758 err = -ENODEV;
759 }
760
761 if (!err) {
88fb2c6e 762 fbcon_del_cursor_timer(oldinfo);
1da177e4
LT
763 kfree(ops->cursor_state.mask);
764 kfree(ops->cursor_data);
7a966fbd 765 kfree(ops->cursor_src);
e4fc2761 766 kfree(ops->fontbuffer);
1da177e4
LT
767 kfree(oldinfo->fbcon_par);
768 oldinfo->fbcon_par = NULL;
769 module_put(oldinfo->fbops->owner);
dd0314f7
AD
770 /*
771 If oldinfo and newinfo are driving the same hardware,
772 the fb_release() method of oldinfo may attempt to
773 restore the hardware state. This will leave the
774 newinfo in an undefined state. Thus, a call to
775 fb_set_par() may be needed for the newinfo.
776 */
5f4dc28b 777 if (newinfo && newinfo->fbops->fb_set_par) {
0fcf6ada
FTS
778 ret = newinfo->fbops->fb_set_par(newinfo);
779
780 if (ret)
781 printk(KERN_ERR "con2fb_release_oldinfo: "
782 "detected unhandled fb_set_par error, "
783 "error code %d\n", ret);
784 }
1da177e4
LT
785 }
786
787 return err;
788}
789
1da177e4
LT
790static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
791 int unit, int show_logo)
792{
793 struct fbcon_ops *ops = info->fbcon_par;
0fcf6ada 794 int ret;
1da177e4
LT
795
796 ops->currcon = fg_console;
797
0fcf6ada
FTS
798 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
799 ret = info->fbops->fb_set_par(info);
800
801 if (ret)
802 printk(KERN_ERR "con2fb_init_display: detected "
803 "unhandled fb_set_par error, "
804 "error code %d\n", ret);
805 }
1da177e4
LT
806
807 ops->flags |= FBCON_FLAGS_INIT;
808 ops->graphics = 0;
d1baa4ff 809 fbcon_set_disp(info, &info->var, unit);
1da177e4
LT
810
811 if (show_logo) {
812 struct vc_data *fg_vc = vc_cons[fg_console].d;
813 struct fb_info *fg_info =
814 registered_fb[con2fb_map[fg_console]];
815
816 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
817 fg_vc->vc_rows, fg_vc->vc_cols,
818 fg_vc->vc_rows);
819 }
820
821 update_screen(vc_cons[fg_console].d);
822}
823
824/**
825 * set_con2fb_map - map console to frame buffer device
826 * @unit: virtual console number to map
827 * @newidx: frame buffer index to map virtual console to
828 * @user: user request
829 *
830 * Maps a virtual console @unit to a frame buffer device
831 * @newidx.
054430e7
DA
832 *
833 * This should be called with the console lock held.
1da177e4
LT
834 */
835static int set_con2fb_map(int unit, int newidx, int user)
836{
837 struct vc_data *vc = vc_cons[unit].d;
838 int oldidx = con2fb_map[unit];
839 struct fb_info *info = registered_fb[newidx];
840 struct fb_info *oldinfo = NULL;
841 int found, err = 0;
842
3bd3a0e3
HG
843 WARN_CONSOLE_UNLOCKED();
844
1da177e4
LT
845 if (oldidx == newidx)
846 return 0;
847
32b98bf8 848 if (!info)
e614b18d 849 return -EINVAL;
1da177e4 850
32b98bf8 851 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
1da177e4 852 info_idx = newidx;
054430e7 853 return do_fbcon_takeover(0);
1da177e4
LT
854 }
855
856 if (oldidx != -1)
857 oldinfo = registered_fb[oldidx];
858
859 found = search_fb_in_map(newidx);
860
1da177e4
LT
861 con2fb_map[unit] = newidx;
862 if (!err && !found)
863 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
864
865
866 /*
867 * If old fb is not mapped to any of the consoles,
868 * fbcon should release it.
869 */
870 if (!err && oldinfo && !search_fb_in_map(oldidx))
871 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
872 found);
873
874 if (!err) {
875 int show_logo = (fg_console == 0 && !user &&
876 logo_shown != FBCON_LOGO_DONTSHOW);
877
878 if (!found)
88fb2c6e 879 fbcon_add_cursor_timer(info);
1da177e4
LT
880 con2fb_map_boot[unit] = newidx;
881 con2fb_init_display(vc, info, unit, show_logo);
882 }
883
e614b18d
AD
884 if (!search_fb_in_map(info_idx))
885 info_idx = newidx;
886
1da177e4
LT
887 return err;
888}
889
890/*
891 * Low Level Operations
892 */
155957f5 893/* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
1da177e4
LT
894static int var_to_display(struct display *disp,
895 struct fb_var_screeninfo *var,
896 struct fb_info *info)
897{
898 disp->xres_virtual = var->xres_virtual;
899 disp->yres_virtual = var->yres_virtual;
900 disp->bits_per_pixel = var->bits_per_pixel;
901 disp->grayscale = var->grayscale;
902 disp->nonstd = var->nonstd;
903 disp->accel_flags = var->accel_flags;
904 disp->height = var->height;
905 disp->width = var->width;
906 disp->red = var->red;
907 disp->green = var->green;
908 disp->blue = var->blue;
909 disp->transp = var->transp;
910 disp->rotate = var->rotate;
911 disp->mode = fb_match_mode(var, &info->modelist);
912 if (disp->mode == NULL)
913 /* This should not happen */
914 return -EINVAL;
915 return 0;
916}
917
918static void display_to_var(struct fb_var_screeninfo *var,
919 struct display *disp)
920{
921 fb_videomode_to_var(var, disp->mode);
922 var->xres_virtual = disp->xres_virtual;
923 var->yres_virtual = disp->yres_virtual;
924 var->bits_per_pixel = disp->bits_per_pixel;
925 var->grayscale = disp->grayscale;
926 var->nonstd = disp->nonstd;
927 var->accel_flags = disp->accel_flags;
928 var->height = disp->height;
929 var->width = disp->width;
930 var->red = disp->red;
931 var->green = disp->green;
932 var->blue = disp->blue;
933 var->transp = disp->transp;
934 var->rotate = disp->rotate;
935}
936
937static const char *fbcon_startup(void)
938{
939 const char *display_desc = "frame buffer device";
940 struct display *p = &fb_display[fg_console];
941 struct vc_data *vc = vc_cons[fg_console].d;
2f4516db 942 const struct font_desc *font = NULL;
1da177e4
LT
943 struct module *owner;
944 struct fb_info *info = NULL;
945 struct fbcon_ops *ops;
946 int rows, cols;
1da177e4 947
1da177e4
LT
948 /*
949 * If num_registered_fb is zero, this is a call for the dummy part.
950 * The frame buffer devices weren't initialized yet.
951 */
952 if (!num_registered_fb || info_idx == -1)
953 return display_desc;
954 /*
955 * Instead of blindly using registered_fb[0], we use info_idx, set by
956 * fb_console_init();
957 */
958 info = registered_fb[info_idx];
959 if (!info)
960 return NULL;
961
962 owner = info->fbops->owner;
963 if (!try_module_get(owner))
964 return NULL;
965 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
966 module_put(owner);
967 return NULL;
968 }
969
a39bc34e 970 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
1da177e4
LT
971 if (!ops) {
972 module_put(owner);
973 return NULL;
974 }
975
1da177e4
LT
976 ops->currcon = -1;
977 ops->graphics = 1;
e4fc2761 978 ops->cur_rotate = -1;
a1e533ec 979 ops->cur_blink_jiffies = HZ / 5;
d447ebf9 980 ops->info = info;
1da177e4 981 info->fbcon_par = ops;
c9e6a364
HG
982
983 p->con_rotate = initial_rotation;
984 if (p->con_rotate == -1)
985 p->con_rotate = info->fbcon_rotate_hint;
986 if (p->con_rotate == -1)
f2f4946b 987 p->con_rotate = FB_ROTATE_UR;
c9e6a364 988
b73deed3 989 set_blitting_type(vc, info);
1da177e4
LT
990
991 if (info->fix.type != FB_TYPE_TEXT) {
992 if (fbcon_softback_size) {
993 if (!softback_buf) {
994 softback_buf =
995 (unsigned long)
996 kmalloc(fbcon_softback_size,
997 GFP_KERNEL);
998 if (!softback_buf) {
999 fbcon_softback_size = 0;
1000 softback_top = 0;
1001 }
1002 }
1003 } else {
1004 if (softback_buf) {
1005 kfree((void *) softback_buf);
1006 softback_buf = 0;
1007 softback_top = 0;
1008 }
1009 }
1010 if (softback_buf)
1011 softback_in = softback_top = softback_curr =
1012 softback_buf;
1013 softback_lines = 0;
1014 }
1015
1016 /* Setup default font */
ae128786 1017 if (!p->fontdata && !vc->vc_font.data) {
1da177e4
LT
1018 if (!fontname[0] || !(font = find_font(fontname)))
1019 font = get_default_font(info->var.xres,
2d2699d9
AD
1020 info->var.yres,
1021 info->pixmap.blit_x,
1022 info->pixmap.blit_y);
1da177e4
LT
1023 vc->vc_font.width = font->width;
1024 vc->vc_font.height = font->height;
2f4516db 1025 vc->vc_font.data = (void *)(p->fontdata = font->data);
1da177e4 1026 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
ae128786
DA
1027 } else {
1028 p->fontdata = vc->vc_font.data;
1da177e4
LT
1029 }
1030
e4fc2761
AD
1031 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1032 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1033 cols /= vc->vc_font.width;
1034 rows /= vc->vc_font.height;
1da177e4
LT
1035 vc_resize(vc, cols, rows);
1036
1037 DPRINTK("mode: %s\n", info->fix.id);
1038 DPRINTK("visual: %d\n", info->fix.visual);
1039 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1040 info->var.yres,
1041 info->var.bits_per_pixel);
1042
88fb2c6e 1043 fbcon_add_cursor_timer(info);
e614b18d 1044 fbcon_has_exited = 0;
1da177e4
LT
1045 return display_desc;
1046}
1047
1048static void fbcon_init(struct vc_data *vc, int init)
1049{
1050 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1051 struct fbcon_ops *ops;
1052 struct vc_data **default_mode = vc->vc_display_fg;
1053 struct vc_data *svc = *default_mode;
1054 struct display *t, *p = &fb_display[vc->vc_num];
1055 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
0fcf6ada 1056 int cap, ret;
1da177e4
LT
1057
1058 if (info_idx == -1 || info == NULL)
1059 return;
306958e8
AB
1060
1061 cap = info->flags;
1062
1da177e4
LT
1063 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1064 (info->fix.type == FB_TYPE_TEXT))
1065 logo = 0;
1066
1da177e4
LT
1067 if (var_to_display(p, &info->var, info))
1068 return;
1069
d1baa4ff
AD
1070 if (!info->fbcon_par)
1071 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1072
1da177e4
LT
1073 /* If we are not the first console on this
1074 fb, copy the font from that console */
e614b18d
AD
1075 t = &fb_display[fg_console];
1076 if (!p->fontdata) {
1077 if (t->fontdata) {
1078 struct vc_data *fvc = vc_cons[fg_console].d;
1079
1080 vc->vc_font.data = (void *)(p->fontdata =
1081 fvc->vc_font.data);
1082 vc->vc_font.width = fvc->vc_font.width;
1083 vc->vc_font.height = fvc->vc_font.height;
1084 p->userfont = t->userfont;
1085
1086 if (p->userfont)
1087 REFCOUNT(p->fontdata)++;
1088 } else {
1089 const struct font_desc *font = NULL;
1090
1091 if (!fontname[0] || !(font = find_font(fontname)))
1092 font = get_default_font(info->var.xres,
2d2699d9
AD
1093 info->var.yres,
1094 info->pixmap.blit_x,
1095 info->pixmap.blit_y);
e614b18d
AD
1096 vc->vc_font.width = font->width;
1097 vc->vc_font.height = font->height;
1098 vc->vc_font.data = (void *)(p->fontdata = font->data);
1099 vc->vc_font.charcount = 256; /* FIXME Need to
1100 support more fonts */
1101 }
1da177e4 1102 }
e614b18d 1103
1da177e4
LT
1104 if (p->userfont)
1105 charcnt = FNTCHARCNT(p->fontdata);
e614b18d 1106
8fd4bd22 1107 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
b8c90945 1108 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1da177e4
LT
1109 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1110 if (charcnt == 256) {
1111 vc->vc_hi_font_mask = 0;
1112 } else {
1113 vc->vc_hi_font_mask = 0x100;
1114 if (vc->vc_can_do_color)
1115 vc->vc_complement_mask <<= 1;
1116 }
1117
1118 if (!*svc->vc_uni_pagedir_loc)
1119 con_set_default_unimap(svc);
1120 if (!*vc->vc_uni_pagedir_loc)
1121 con_copy_unimap(vc, svc);
1122
e4fc2761 1123 ops = info->fbcon_par;
f235f664 1124 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
c9e6a364
HG
1125
1126 p->con_rotate = initial_rotation;
1127 if (p->con_rotate == -1)
1128 p->con_rotate = info->fbcon_rotate_hint;
1129 if (p->con_rotate == -1)
f2f4946b 1130 p->con_rotate = FB_ROTATE_UR;
c9e6a364 1131
b73deed3 1132 set_blitting_type(vc, info);
e4fc2761 1133
1da177e4
LT
1134 cols = vc->vc_cols;
1135 rows = vc->vc_rows;
e4fc2761
AD
1136 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1137 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1138 new_cols /= vc->vc_font.width;
1139 new_rows /= vc->vc_font.height;
1da177e4 1140
1da177e4
LT
1141 /*
1142 * We must always set the mode. The mode of the previous console
1143 * driver could be in the same resolution but we are using different
1144 * hardware so we have to initialize the hardware.
1145 *
1146 * We need to do it in fbcon_init() to prevent screen corruption.
1147 */
6ca8dfd7 1148 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
1da177e4 1149 if (info->fbops->fb_set_par &&
0fcf6ada
FTS
1150 !(ops->flags & FBCON_FLAGS_INIT)) {
1151 ret = info->fbops->fb_set_par(info);
1152
1153 if (ret)
1154 printk(KERN_ERR "fbcon_init: detected "
1155 "unhandled fb_set_par error, "
1156 "error code %d\n", ret);
1157 }
1158
1da177e4
LT
1159 ops->flags |= FBCON_FLAGS_INIT;
1160 }
1161
1162 ops->graphics = 0;
1163
1164 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1165 !(cap & FBINFO_HWACCEL_DISABLED))
1166 p->scrollmode = SCROLL_MOVE;
1167 else /* default to something safe */
1168 p->scrollmode = SCROLL_REDRAW;
1169
1170 /*
1171 * ++guenther: console.c:vc_allocate() relies on initializing
1172 * vc_{cols,rows}, but we must not set those if we are only
1173 * resizing the console.
1174 */
0035fe00 1175 if (init) {
1da177e4
LT
1176 vc->vc_cols = new_cols;
1177 vc->vc_rows = new_rows;
0035fe00
JW
1178 } else
1179 vc_resize(vc, new_cols, new_rows);
1da177e4
LT
1180
1181 if (logo)
1182 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1183
4d9c5b6e
AD
1184 if (vc == svc && softback_buf)
1185 fbcon_update_softback(vc);
e4fc2761 1186
b73deed3 1187 if (ops->rotate_font && ops->rotate_font(info, vc)) {
e4fc2761 1188 ops->rotate = FB_ROTATE_UR;
b73deed3 1189 set_blitting_type(vc, info);
e4fc2761
AD
1190 }
1191
1a37d5f5 1192 ops->p = &fb_display[fg_console];
1da177e4
LT
1193}
1194
ae128786 1195static void fbcon_free_font(struct display *p, bool freefont)
e614b18d 1196{
ae128786 1197 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
e614b18d
AD
1198 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1199 p->fontdata = NULL;
1200 p->userfont = 0;
1201}
1202
8aac7f34
TI
1203static void set_vc_hi_font(struct vc_data *vc, bool set);
1204
1da177e4
LT
1205static void fbcon_deinit(struct vc_data *vc)
1206{
1207 struct display *p = &fb_display[vc->vc_num];
e614b18d
AD
1208 struct fb_info *info;
1209 struct fbcon_ops *ops;
1210 int idx;
ae128786 1211 bool free_font = true;
1da177e4 1212
e614b18d
AD
1213 idx = con2fb_map[vc->vc_num];
1214
1215 if (idx == -1)
1216 goto finished;
1217
1218 info = registered_fb[idx];
1219
1220 if (!info)
1221 goto finished;
1222
ae128786
DA
1223 if (info->flags & FBINFO_MISC_FIRMWARE)
1224 free_font = false;
e614b18d
AD
1225 ops = info->fbcon_par;
1226
1227 if (!ops)
1228 goto finished;
1229
6ca8dfd7 1230 if (con_is_visible(vc))
e614b18d
AD
1231 fbcon_del_cursor_timer(info);
1232
1233 ops->flags &= ~FBCON_FLAGS_INIT;
1234finished:
1235
ae128786 1236 fbcon_free_font(p, free_font);
e6637d54
MK
1237 if (free_font)
1238 vc->vc_font.data = NULL;
ae128786 1239
8aac7f34
TI
1240 if (vc->vc_hi_font_mask)
1241 set_vc_hi_font(vc, false);
1242
e614b18d
AD
1243 if (!con_is_bound(&fb_con))
1244 fbcon_exit();
1245
1246 return;
1da177e4
LT
1247}
1248
1249/* ====================================================================== */
1250
1251/* fbcon_XXX routines - interface used by the world
1252 *
1253 * This system is now divided into two levels because of complications
1254 * caused by hardware scrolling. Top level functions:
1255 *
1256 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1257 *
1258 * handles y values in range [0, scr_height-1] that correspond to real
1259 * screen positions. y_wrap shift means that first line of bitmap may be
1260 * anywhere on this display. These functions convert lineoffsets to
1261 * bitmap offsets and deal with the wrap-around case by splitting blits.
1262 *
1263 * fbcon_bmove_physical_8() -- These functions fast implementations
1264 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1265 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1266 *
1267 * WARNING:
1268 *
1269 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1270 * Implies should only really hardware scroll in rows. Only reason for
1271 * restriction is simplicity & efficiency at the moment.
1272 */
1273
1da177e4
LT
1274static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1275 int width)
1276{
1277 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1278 struct fbcon_ops *ops = info->fbcon_par;
1279
1280 struct display *p = &fb_display[vc->vc_num];
1281 u_int y_break;
1282
1283 if (fbcon_is_inactive(vc, info))
1284 return;
1285
1286 if (!height || !width)
1287 return;
1288
256fc0e5 1289 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
c213ddf3 1290 vc->vc_top = 0;
256fc0e5
KM
1291 /*
1292 * If the font dimensions are not an integral of the display
1293 * dimensions then the ops->clear below won't end up clearing
1294 * the margins. Call clear_margins here in case the logo
1295 * bitmap stretched into the margin area.
1296 */
1297 fbcon_clear_margins(vc, 0);
1298 }
c213ddf3 1299
1da177e4
LT
1300 /* Split blits that cross physical y_wrap boundary */
1301
1302 y_break = p->vrows - p->yscroll;
1303 if (sy < y_break && sy + height - 1 >= y_break) {
1304 u_int b = y_break - sy;
1305 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1306 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1307 width);
1308 } else
1309 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1310}
1311
1312static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1313 int count, int ypos, int xpos)
1314{
1315 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1316 struct display *p = &fb_display[vc->vc_num];
1317 struct fbcon_ops *ops = info->fbcon_par;
1318
1319 if (!fbcon_is_inactive(vc, info))
1320 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1321 get_color(vc, info, scr_readw(s), 1),
1322 get_color(vc, info, scr_readw(s), 0));
1323}
1324
1325static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1326{
1327 unsigned short chr;
1328
1329 scr_writew(c, &chr);
1330 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1331}
1332
1333static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1334{
1335 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1336 struct fbcon_ops *ops = info->fbcon_par;
1337
1338 if (!fbcon_is_inactive(vc, info))
74c1c8b3 1339 ops->clear_margins(vc, info, margin_color, bottom_only);
1da177e4
LT
1340}
1341
1342static void fbcon_cursor(struct vc_data *vc, int mode)
1343{
1344 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1345 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
1346 int y;
1347 int c = scr_readw((u16 *) vc->vc_pos);
1348
2a17d7e8
SD
1349 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1350
d1e23066 1351 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1da177e4
LT
1352 return;
1353
a5edce42
TR
1354 if (vc->vc_cursor_type & 0x10)
1355 fbcon_del_cursor_timer(info);
1356 else
acba9cd0
AD
1357 fbcon_add_cursor_timer(info);
1358
1da177e4
LT
1359 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1360 if (mode & CM_SOFTBACK) {
1361 mode &= ~CM_SOFTBACK;
1362 y = softback_lines;
1363 } else {
1364 if (softback_lines)
1365 fbcon_set_origin(vc);
1366 y = 0;
1367 }
1368
b73deed3 1369 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
1da177e4 1370 get_color(vc, info, c, 0));
1da177e4
LT
1371}
1372
1373static int scrollback_phys_max = 0;
1374static int scrollback_max = 0;
1375static int scrollback_current = 0;
1376
1da177e4 1377static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
d1baa4ff 1378 int unit)
1da177e4 1379{
d1baa4ff
AD
1380 struct display *p, *t;
1381 struct vc_data **default_mode, *vc;
1382 struct vc_data *svc;
e4fc2761 1383 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
1384 int rows, cols, charcnt = 256;
1385
d1baa4ff
AD
1386 p = &fb_display[unit];
1387
1da177e4
LT
1388 if (var_to_display(p, var, info))
1389 return;
d1baa4ff
AD
1390
1391 vc = vc_cons[unit].d;
1392
1393 if (!vc)
1394 return;
1395
1396 default_mode = vc->vc_display_fg;
1397 svc = *default_mode;
1da177e4 1398 t = &fb_display[svc->vc_num];
d1baa4ff 1399
1da177e4 1400 if (!vc->vc_font.data) {
2f4516db 1401 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
1da177e4
LT
1402 vc->vc_font.width = (*default_mode)->vc_font.width;
1403 vc->vc_font.height = (*default_mode)->vc_font.height;
1404 p->userfont = t->userfont;
1405 if (p->userfont)
1406 REFCOUNT(p->fontdata)++;
1407 }
1408 if (p->userfont)
1409 charcnt = FNTCHARCNT(p->fontdata);
1410
b8c90945
AD
1411 var->activate = FB_ACTIVATE_NOW;
1412 info->var.activate = var->activate;
e4fc2761
AD
1413 var->yoffset = info->var.yoffset;
1414 var->xoffset = info->var.xoffset;
b8c90945 1415 fb_set_var(info, var);
e4fc2761 1416 ops->var = info->var;
b8c90945 1417 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1da177e4
LT
1418 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1419 if (charcnt == 256) {
1420 vc->vc_hi_font_mask = 0;
1421 } else {
1422 vc->vc_hi_font_mask = 0x100;
1423 if (vc->vc_can_do_color)
1424 vc->vc_complement_mask <<= 1;
1425 }
1426
1427 if (!*svc->vc_uni_pagedir_loc)
1428 con_set_default_unimap(svc);
1429 if (!*vc->vc_uni_pagedir_loc)
1430 con_copy_unimap(vc, svc);
1431
e4fc2761
AD
1432 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1433 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1434 cols /= vc->vc_font.width;
1435 rows /= vc->vc_font.height;
1da177e4 1436 vc_resize(vc, cols, rows);
e4fc2761 1437
6ca8dfd7 1438 if (con_is_visible(vc)) {
1da177e4 1439 update_screen(vc);
4d9c5b6e
AD
1440 if (softback_buf)
1441 fbcon_update_softback(vc);
1da177e4
LT
1442 }
1443}
1444
1445static __inline__ void ywrap_up(struct vc_data *vc, int count)
1446{
1447 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
e4fc2761 1448 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
1449 struct display *p = &fb_display[vc->vc_num];
1450
1451 p->yscroll += count;
1452 if (p->yscroll >= p->vrows) /* Deal with wrap */
1453 p->yscroll -= p->vrows;
e4fc2761
AD
1454 ops->var.xoffset = 0;
1455 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1456 ops->var.vmode |= FB_VMODE_YWRAP;
1457 ops->update_start(info);
1da177e4
LT
1458 scrollback_max += count;
1459 if (scrollback_max > scrollback_phys_max)
1460 scrollback_max = scrollback_phys_max;
1461 scrollback_current = 0;
1462}
1463
1464static __inline__ void ywrap_down(struct vc_data *vc, int count)
1465{
1466 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
e4fc2761 1467 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
1468 struct display *p = &fb_display[vc->vc_num];
1469
1470 p->yscroll -= count;
1471 if (p->yscroll < 0) /* Deal with wrap */
1472 p->yscroll += p->vrows;
e4fc2761
AD
1473 ops->var.xoffset = 0;
1474 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1475 ops->var.vmode |= FB_VMODE_YWRAP;
1476 ops->update_start(info);
1da177e4
LT
1477 scrollback_max -= count;
1478 if (scrollback_max < 0)
1479 scrollback_max = 0;
1480 scrollback_current = 0;
1481}
1482
1483static __inline__ void ypan_up(struct vc_data *vc, int count)
1484{
1485 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1486 struct display *p = &fb_display[vc->vc_num];
1487 struct fbcon_ops *ops = info->fbcon_par;
1488
1489 p->yscroll += count;
1490 if (p->yscroll > p->vrows - vc->vc_rows) {
1491 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1492 0, 0, 0, vc->vc_rows, vc->vc_cols);
1493 p->yscroll -= p->vrows - vc->vc_rows;
1494 }
e4fc2761
AD
1495
1496 ops->var.xoffset = 0;
1497 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1498 ops->var.vmode &= ~FB_VMODE_YWRAP;
1499 ops->update_start(info);
1da177e4
LT
1500 fbcon_clear_margins(vc, 1);
1501 scrollback_max += count;
1502 if (scrollback_max > scrollback_phys_max)
1503 scrollback_max = scrollback_phys_max;
1504 scrollback_current = 0;
1505}
1506
1507static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1508{
1509 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
e4fc2761 1510 struct fbcon_ops *ops = info->fbcon_par;
1da177e4 1511 struct display *p = &fb_display[vc->vc_num];
1da177e4
LT
1512
1513 p->yscroll += count;
a39bc34e 1514
1da177e4
LT
1515 if (p->yscroll > p->vrows - vc->vc_rows) {
1516 p->yscroll -= p->vrows - vc->vc_rows;
1da177e4 1517 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
a39bc34e 1518 }
e4fc2761
AD
1519
1520 ops->var.xoffset = 0;
1521 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1522 ops->var.vmode &= ~FB_VMODE_YWRAP;
1523 ops->update_start(info);
1da177e4
LT
1524 fbcon_clear_margins(vc, 1);
1525 scrollback_max += count;
1526 if (scrollback_max > scrollback_phys_max)
1527 scrollback_max = scrollback_phys_max;
1528 scrollback_current = 0;
1529}
1530
1531static __inline__ void ypan_down(struct vc_data *vc, int count)
1532{
1533 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1534 struct display *p = &fb_display[vc->vc_num];
1535 struct fbcon_ops *ops = info->fbcon_par;
1536
1537 p->yscroll -= count;
1538 if (p->yscroll < 0) {
1539 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1540 0, vc->vc_rows, vc->vc_cols);
1541 p->yscroll += p->vrows - vc->vc_rows;
1542 }
e4fc2761
AD
1543
1544 ops->var.xoffset = 0;
1545 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1546 ops->var.vmode &= ~FB_VMODE_YWRAP;
1547 ops->update_start(info);
1da177e4
LT
1548 fbcon_clear_margins(vc, 1);
1549 scrollback_max -= count;
1550 if (scrollback_max < 0)
1551 scrollback_max = 0;
1552 scrollback_current = 0;
1553}
1554
1555static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1556{
1557 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
e4fc2761 1558 struct fbcon_ops *ops = info->fbcon_par;
1da177e4 1559 struct display *p = &fb_display[vc->vc_num];
1da177e4
LT
1560
1561 p->yscroll -= count;
a39bc34e 1562
1da177e4
LT
1563 if (p->yscroll < 0) {
1564 p->yscroll += p->vrows - vc->vc_rows;
1da177e4 1565 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
a39bc34e 1566 }
e4fc2761
AD
1567
1568 ops->var.xoffset = 0;
1569 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1570 ops->var.vmode &= ~FB_VMODE_YWRAP;
1571 ops->update_start(info);
1da177e4
LT
1572 fbcon_clear_margins(vc, 1);
1573 scrollback_max -= count;
1574 if (scrollback_max < 0)
1575 scrollback_max = 0;
1576 scrollback_current = 0;
1577}
1578
1579static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1580 long delta)
1581{
1582 int count = vc->vc_rows;
1583 unsigned short *d, *s;
1584 unsigned long n;
1585 int line = 0;
1586
1587 d = (u16 *) softback_curr;
1588 if (d == (u16 *) softback_in)
1589 d = (u16 *) vc->vc_origin;
1590 n = softback_curr + delta * vc->vc_size_row;
1591 softback_lines -= delta;
1592 if (delta < 0) {
1593 if (softback_curr < softback_top && n < softback_buf) {
1594 n += softback_end - softback_buf;
1595 if (n < softback_top) {
1596 softback_lines -=
1597 (softback_top - n) / vc->vc_size_row;
1598 n = softback_top;
1599 }
1600 } else if (softback_curr >= softback_top
1601 && n < softback_top) {
1602 softback_lines -=
1603 (softback_top - n) / vc->vc_size_row;
1604 n = softback_top;
1605 }
1606 } else {
1607 if (softback_curr > softback_in && n >= softback_end) {
1608 n += softback_buf - softback_end;
1609 if (n > softback_in) {
1610 n = softback_in;
1611 softback_lines = 0;
1612 }
1613 } else if (softback_curr <= softback_in && n > softback_in) {
1614 n = softback_in;
1615 softback_lines = 0;
1616 }
1617 }
1618 if (n == softback_curr)
1619 return;
1620 softback_curr = n;
1621 s = (u16 *) softback_curr;
1622 if (s == (u16 *) softback_in)
1623 s = (u16 *) vc->vc_origin;
1624 while (count--) {
1625 unsigned short *start;
1626 unsigned short *le;
1627 unsigned short c;
1628 int x = 0;
1629 unsigned short attr = 1;
1630
1631 start = s;
1632 le = advance_row(s, 1);
1633 do {
1634 c = scr_readw(s);
1635 if (attr != (c & 0xff00)) {
1636 attr = c & 0xff00;
1637 if (s > start) {
1638 fbcon_putcs(vc, start, s - start,
1639 line, x);
1640 x += s - start;
1641 start = s;
1642 }
1643 }
1644 if (c == scr_readw(d)) {
1645 if (s > start) {
1646 fbcon_putcs(vc, start, s - start,
1647 line, x);
1648 x += s - start + 1;
1649 start = s + 1;
1650 } else {
1651 x++;
1652 start++;
1653 }
1654 }
1655 s++;
1656 d++;
1657 } while (s < le);
1658 if (s > start)
1659 fbcon_putcs(vc, start, s - start, line, x);
1660 line++;
1661 if (d == (u16 *) softback_end)
1662 d = (u16 *) softback_buf;
1663 if (d == (u16 *) softback_in)
1664 d = (u16 *) vc->vc_origin;
1665 if (s == (u16 *) softback_end)
1666 s = (u16 *) softback_buf;
1667 if (s == (u16 *) softback_in)
1668 s = (u16 *) vc->vc_origin;
1669 }
1670}
1671
1672static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1673 int line, int count, int dy)
1674{
1675 unsigned short *s = (unsigned short *)
1676 (vc->vc_origin + vc->vc_size_row * line);
1677
1678 while (count--) {
1679 unsigned short *start = s;
1680 unsigned short *le = advance_row(s, 1);
1681 unsigned short c;
1682 int x = 0;
1683 unsigned short attr = 1;
1684
1685 do {
1686 c = scr_readw(s);
1687 if (attr != (c & 0xff00)) {
1688 attr = c & 0xff00;
1689 if (s > start) {
1690 fbcon_putcs(vc, start, s - start,
1691 dy, x);
1692 x += s - start;
1693 start = s;
1694 }
1695 }
1696 console_conditional_schedule();
1697 s++;
1698 } while (s < le);
1699 if (s > start)
1700 fbcon_putcs(vc, start, s - start, dy, x);
1701 console_conditional_schedule();
1702 dy++;
1703 }
1704}
1705
bad07ff7
KH
1706static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1707 struct display *p, int line, int count, int ycount)
1708{
1709 int offset = ycount * vc->vc_cols;
1710 unsigned short *d = (unsigned short *)
1711 (vc->vc_origin + vc->vc_size_row * line);
1712 unsigned short *s = d + offset;
1713 struct fbcon_ops *ops = info->fbcon_par;
1714
1715 while (count--) {
1716 unsigned short *start = s;
1717 unsigned short *le = advance_row(s, 1);
1718 unsigned short c;
1719 int x = 0;
1720
1721 do {
1722 c = scr_readw(s);
1723
1724 if (c == scr_readw(d)) {
1725 if (s > start) {
1726 ops->bmove(vc, info, line + ycount, x,
1727 line, x, 1, s-start);
1728 x += s - start + 1;
1729 start = s + 1;
1730 } else {
1731 x++;
1732 start++;
1733 }
1734 }
1735
1736 scr_writew(c, d);
1737 console_conditional_schedule();
1738 s++;
1739 d++;
1740 } while (s < le);
1741 if (s > start)
1742 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1743 s-start);
1744 console_conditional_schedule();
1745 if (ycount > 0)
1746 line++;
1747 else {
1748 line--;
1749 /* NOTE: We subtract two lines from these pointers */
1750 s -= vc->vc_size_row;
1751 d -= vc->vc_size_row;
1752 }
1753 }
1754}
1755
1da177e4
LT
1756static void fbcon_redraw(struct vc_data *vc, struct display *p,
1757 int line, int count, int offset)
1758{
1759 unsigned short *d = (unsigned short *)
1760 (vc->vc_origin + vc->vc_size_row * line);
1761 unsigned short *s = d + offset;
1762
1763 while (count--) {
1764 unsigned short *start = s;
1765 unsigned short *le = advance_row(s, 1);
1766 unsigned short c;
1767 int x = 0;
1768 unsigned short attr = 1;
1769
1770 do {
1771 c = scr_readw(s);
1772 if (attr != (c & 0xff00)) {
1773 attr = c & 0xff00;
1774 if (s > start) {
1775 fbcon_putcs(vc, start, s - start,
1776 line, x);
1777 x += s - start;
1778 start = s;
1779 }
1780 }
1781 if (c == scr_readw(d)) {
1782 if (s > start) {
1783 fbcon_putcs(vc, start, s - start,
1784 line, x);
1785 x += s - start + 1;
1786 start = s + 1;
1787 } else {
1788 x++;
1789 start++;
1790 }
1791 }
1792 scr_writew(c, d);
1793 console_conditional_schedule();
1794 s++;
1795 d++;
1796 } while (s < le);
1797 if (s > start)
1798 fbcon_putcs(vc, start, s - start, line, x);
1799 console_conditional_schedule();
1800 if (offset > 0)
1801 line++;
1802 else {
1803 line--;
1804 /* NOTE: We subtract two lines from these pointers */
1805 s -= vc->vc_size_row;
1806 d -= vc->vc_size_row;
1807 }
1808 }
1809}
1810
1811static inline void fbcon_softback_note(struct vc_data *vc, int t,
1812 int count)
1813{
1814 unsigned short *p;
1815
1816 if (vc->vc_num != fg_console)
1817 return;
1818 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1819
1820 while (count) {
1821 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1822 count--;
1823 p = advance_row(p, 1);
1824 softback_in += vc->vc_size_row;
1825 if (softback_in == softback_end)
1826 softback_in = softback_buf;
1827 if (softback_in == softback_top) {
1828 softback_top += vc->vc_size_row;
1829 if (softback_top == softback_end)
1830 softback_top = softback_buf;
1831 }
1832 }
1833 softback_curr = softback_in;
1834}
1835
d705ff38
JS
1836static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1837 enum con_scroll dir, unsigned int count)
1da177e4
LT
1838{
1839 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1840 struct display *p = &fb_display[vc->vc_num];
1da177e4
LT
1841 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1842
1843 if (fbcon_is_inactive(vc, info))
d705ff38 1844 return true;
1da177e4
LT
1845
1846 fbcon_cursor(vc, CM_ERASE);
1847
1848 /*
1849 * ++Geert: Only use ywrap/ypan if the console is in text mode
1850 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1851 * whole screen (prevents flicker).
1852 */
1853
1854 switch (dir) {
1855 case SM_UP:
1856 if (count > vc->vc_rows) /* Maximum realistic size */
1857 count = vc->vc_rows;
1858 if (softback_top)
1859 fbcon_softback_note(vc, t, count);
1860 if (logo_shown >= 0)
1861 goto redraw_up;
1862 switch (p->scrollmode) {
1863 case SCROLL_MOVE:
bad07ff7
KH
1864 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1865 count);
1866 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1867 scr_memsetw((unsigned short *) (vc->vc_origin +
1868 vc->vc_size_row *
1869 (b - count)),
93f78da4 1870 vc->vc_video_erase_char,
bad07ff7 1871 vc->vc_size_row * count);
d705ff38 1872 return true;
1da177e4
LT
1873 break;
1874
1875 case SCROLL_WRAP_MOVE:
1876 if (b - t - count > 3 * vc->vc_rows >> 2) {
1877 if (t > 0)
1878 fbcon_bmove(vc, 0, 0, count, 0, t,
1879 vc->vc_cols);
1880 ywrap_up(vc, count);
1881 if (vc->vc_rows - b > 0)
1882 fbcon_bmove(vc, b - count, 0, b, 0,
1883 vc->vc_rows - b,
1884 vc->vc_cols);
1885 } else if (info->flags & FBINFO_READS_FAST)
1886 fbcon_bmove(vc, t + count, 0, t, 0,
1887 b - t - count, vc->vc_cols);
1888 else
1889 goto redraw_up;
1890 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1891 break;
1892
1893 case SCROLL_PAN_REDRAW:
1894 if ((p->yscroll + count <=
1895 2 * (p->vrows - vc->vc_rows))
1896 && ((!scroll_partial && (b - t == vc->vc_rows))
1897 || (scroll_partial
1898 && (b - t - count >
1899 3 * vc->vc_rows >> 2)))) {
1900 if (t > 0)
1901 fbcon_redraw_move(vc, p, 0, t, count);
1902 ypan_up_redraw(vc, t, count);
1903 if (vc->vc_rows - b > 0)
26e780e8 1904 fbcon_redraw_move(vc, p, b,
1da177e4
LT
1905 vc->vc_rows - b, b);
1906 } else
1907 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1908 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1909 break;
1910
1911 case SCROLL_PAN_MOVE:
1912 if ((p->yscroll + count <=
1913 2 * (p->vrows - vc->vc_rows))
1914 && ((!scroll_partial && (b - t == vc->vc_rows))
1915 || (scroll_partial
1916 && (b - t - count >
1917 3 * vc->vc_rows >> 2)))) {
1918 if (t > 0)
1919 fbcon_bmove(vc, 0, 0, count, 0, t,
1920 vc->vc_cols);
1921 ypan_up(vc, count);
1922 if (vc->vc_rows - b > 0)
1923 fbcon_bmove(vc, b - count, 0, b, 0,
1924 vc->vc_rows - b,
1925 vc->vc_cols);
1926 } else if (info->flags & FBINFO_READS_FAST)
1927 fbcon_bmove(vc, t + count, 0, t, 0,
1928 b - t - count, vc->vc_cols);
1929 else
1930 goto redraw_up;
1931 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1932 break;
1933
1934 case SCROLL_REDRAW:
1935 redraw_up:
1936 fbcon_redraw(vc, p, t, b - t - count,
1937 count * vc->vc_cols);
1938 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1939 scr_memsetw((unsigned short *) (vc->vc_origin +
1940 vc->vc_size_row *
1941 (b - count)),
93f78da4 1942 vc->vc_video_erase_char,
1da177e4 1943 vc->vc_size_row * count);
d705ff38 1944 return true;
1da177e4
LT
1945 }
1946 break;
1947
1948 case SM_DOWN:
1949 if (count > vc->vc_rows) /* Maximum realistic size */
1950 count = vc->vc_rows;
e703ecc3
JB
1951 if (logo_shown >= 0)
1952 goto redraw_down;
1da177e4
LT
1953 switch (p->scrollmode) {
1954 case SCROLL_MOVE:
bad07ff7
KH
1955 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1956 -count);
1957 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1958 scr_memsetw((unsigned short *) (vc->vc_origin +
1959 vc->vc_size_row *
1960 t),
93f78da4 1961 vc->vc_video_erase_char,
bad07ff7 1962 vc->vc_size_row * count);
d705ff38 1963 return true;
1da177e4
LT
1964 break;
1965
1966 case SCROLL_WRAP_MOVE:
1967 if (b - t - count > 3 * vc->vc_rows >> 2) {
1968 if (vc->vc_rows - b > 0)
1969 fbcon_bmove(vc, b, 0, b - count, 0,
1970 vc->vc_rows - b,
1971 vc->vc_cols);
1972 ywrap_down(vc, count);
1973 if (t > 0)
1974 fbcon_bmove(vc, count, 0, 0, 0, t,
1975 vc->vc_cols);
1976 } else if (info->flags & FBINFO_READS_FAST)
1977 fbcon_bmove(vc, t, 0, t + count, 0,
1978 b - t - count, vc->vc_cols);
1979 else
1980 goto redraw_down;
1981 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1982 break;
1983
1984 case SCROLL_PAN_MOVE:
1985 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1986 && ((!scroll_partial && (b - t == vc->vc_rows))
1987 || (scroll_partial
1988 && (b - t - count >
1989 3 * vc->vc_rows >> 2)))) {
1990 if (vc->vc_rows - b > 0)
1991 fbcon_bmove(vc, b, 0, b - count, 0,
1992 vc->vc_rows - b,
1993 vc->vc_cols);
1994 ypan_down(vc, count);
1995 if (t > 0)
1996 fbcon_bmove(vc, count, 0, 0, 0, t,
1997 vc->vc_cols);
1998 } else if (info->flags & FBINFO_READS_FAST)
1999 fbcon_bmove(vc, t, 0, t + count, 0,
2000 b - t - count, vc->vc_cols);
2001 else
2002 goto redraw_down;
2003 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2004 break;
2005
2006 case SCROLL_PAN_REDRAW:
2007 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2008 && ((!scroll_partial && (b - t == vc->vc_rows))
2009 || (scroll_partial
2010 && (b - t - count >
2011 3 * vc->vc_rows >> 2)))) {
2012 if (vc->vc_rows - b > 0)
2013 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2014 b - count);
2015 ypan_down_redraw(vc, t, count);
2016 if (t > 0)
2017 fbcon_redraw_move(vc, p, count, t, 0);
2018 } else
2019 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2020 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2021 break;
2022
2023 case SCROLL_REDRAW:
2024 redraw_down:
2025 fbcon_redraw(vc, p, b - 1, b - t - count,
2026 -count * vc->vc_cols);
2027 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2028 scr_memsetw((unsigned short *) (vc->vc_origin +
2029 vc->vc_size_row *
2030 t),
93f78da4 2031 vc->vc_video_erase_char,
1da177e4 2032 vc->vc_size_row * count);
d705ff38 2033 return true;
1da177e4
LT
2034 }
2035 }
d705ff38 2036 return false;
1da177e4
LT
2037}
2038
2039
2040static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2041 int height, int width)
2042{
2043 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2044 struct display *p = &fb_display[vc->vc_num];
2045
2046 if (fbcon_is_inactive(vc, info))
2047 return;
2048
2049 if (!width || !height)
2050 return;
2051
2052 /* Split blits that cross physical y_wrap case.
2053 * Pathological case involves 4 blits, better to use recursive
2054 * code rather than unrolled case
2055 *
2056 * Recursive invocations don't need to erase the cursor over and
2057 * over again, so we use fbcon_bmove_rec()
2058 */
2059 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2060 p->vrows - p->yscroll);
2061}
2062
2063static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2064 int dy, int dx, int height, int width, u_int y_break)
2065{
2066 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2067 struct fbcon_ops *ops = info->fbcon_par;
2068 u_int b;
2069
2070 if (sy < y_break && sy + height > y_break) {
2071 b = y_break - sy;
2072 if (dy < sy) { /* Avoid trashing self */
2073 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2074 y_break);
2075 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2076 height - b, width, y_break);
2077 } else {
2078 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2079 height - b, width, y_break);
2080 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2081 y_break);
2082 }
2083 return;
2084 }
2085
2086 if (dy < y_break && dy + height > y_break) {
2087 b = y_break - dy;
2088 if (dy < sy) { /* Avoid trashing self */
2089 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2090 y_break);
2091 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2092 height - b, width, y_break);
2093 } else {
2094 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2095 height - b, width, y_break);
2096 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2097 y_break);
2098 }
2099 return;
2100 }
2101 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2102 height, width);
2103}
2104
def1be2d 2105static void updatescrollmode(struct display *p,
e4fc2761 2106 struct fb_info *info,
1da177e4
LT
2107 struct vc_data *vc)
2108{
e4fc2761 2109 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
2110 int fh = vc->vc_font.height;
2111 int cap = info->flags;
e4fc2761
AD
2112 u16 t = 0;
2113 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2114 info->fix.xpanstep);
2115 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2116 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2117 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2118 info->var.xres_virtual);
2119 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2120 divides(ypan, vc->vc_font.height) && vyres > yres;
2121 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2122 divides(ywrap, vc->vc_font.height) &&
244ab72d
KP
2123 divides(vc->vc_font.height, vyres) &&
2124 divides(vc->vc_font.height, yres);
1da177e4 2125 int reading_fast = cap & FBINFO_READS_FAST;
e4fc2761
AD
2126 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2127 !(cap & FBINFO_HWACCEL_DISABLED);
2128 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2129 !(cap & FBINFO_HWACCEL_DISABLED);
2130
2131 p->vrows = vyres/fh;
2132 if (yres > (fh * (vc->vc_rows + 1)))
2133 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2134 if ((yres % fh) && (vyres % fh < yres % fh))
1da177e4
LT
2135 p->vrows--;
2136
2137 if (good_wrap || good_pan) {
2138 if (reading_fast || fast_copyarea)
e4fc2761
AD
2139 p->scrollmode = good_wrap ?
2140 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
1da177e4
LT
2141 else
2142 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2143 SCROLL_PAN_REDRAW;
2144 } else {
2145 if (reading_fast || (fast_copyarea && !fast_imageblit))
2146 p->scrollmode = SCROLL_MOVE;
2147 else
2148 p->scrollmode = SCROLL_REDRAW;
2149 }
2150}
2151
2152static int fbcon_resize(struct vc_data *vc, unsigned int width,
e400b6ec 2153 unsigned int height, unsigned int user)
1da177e4
LT
2154{
2155 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
e4fc2761 2156 struct fbcon_ops *ops = info->fbcon_par;
1da177e4
LT
2157 struct display *p = &fb_display[vc->vc_num];
2158 struct fb_var_screeninfo var = info->var;
e4fc2761
AD
2159 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
2160
2161 virt_w = FBCON_SWAP(ops->rotate, width, height);
2162 virt_h = FBCON_SWAP(ops->rotate, height, width);
2163 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2164 vc->vc_font.height);
2165 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2166 vc->vc_font.width);
2167 var.xres = virt_w * virt_fw;
2168 var.yres = virt_h * virt_fh;
1da177e4
LT
2169 x_diff = info->var.xres - var.xres;
2170 y_diff = info->var.yres - var.yres;
e4fc2761
AD
2171 if (x_diff < 0 || x_diff > virt_fw ||
2172 y_diff < 0 || y_diff > virt_fh) {
9791d763 2173 const struct fb_videomode *mode;
1da177e4
LT
2174
2175 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2176 mode = fb_find_best_mode(&var, &info->modelist);
2177 if (mode == NULL)
2178 return -EINVAL;
3084a895 2179 display_to_var(&var, p);
1da177e4 2180 fb_videomode_to_var(&var, mode);
3084a895 2181
e4fc2761 2182 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
1da177e4 2183 return -EINVAL;
1da177e4
LT
2184
2185 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
6ca8dfd7 2186 if (con_is_visible(vc)) {
1da177e4
LT
2187 var.activate = FB_ACTIVATE_NOW |
2188 FB_ACTIVATE_FORCE;
2189 fb_set_var(info, &var);
2190 }
2191 var_to_display(p, &info->var, info);
e4fc2761 2192 ops->var = info->var;
1da177e4
LT
2193 }
2194 updatescrollmode(p, info, vc);
2195 return 0;
2196}
2197
2198static int fbcon_switch(struct vc_data *vc)
2199{
88fb2c6e 2200 struct fb_info *info, *old_info = NULL;
e4fc2761 2201 struct fbcon_ops *ops;
1da177e4
LT
2202 struct display *p = &fb_display[vc->vc_num];
2203 struct fb_var_screeninfo var;
0fcf6ada 2204 int i, ret, prev_console, charcnt = 256;
1da177e4
LT
2205
2206 info = registered_fb[con2fb_map[vc->vc_num]];
e4fc2761 2207 ops = info->fbcon_par;
1da177e4
LT
2208
2209 if (softback_top) {
1da177e4
LT
2210 if (softback_lines)
2211 fbcon_set_origin(vc);
2212 softback_top = softback_curr = softback_in = softback_buf;
2213 softback_lines = 0;
4d9c5b6e 2214 fbcon_update_softback(vc);
1da177e4
LT
2215 }
2216
2217 if (logo_shown >= 0) {
2218 struct vc_data *conp2 = vc_cons[logo_shown].d;
2219
2220 if (conp2->vc_top == logo_lines
2221 && conp2->vc_bottom == conp2->vc_rows)
2222 conp2->vc_top = 0;
2223 logo_shown = FBCON_LOGO_CANSHOW;
2224 }
2225
e4fc2761 2226 prev_console = ops->currcon;
88fb2c6e
AD
2227 if (prev_console != -1)
2228 old_info = registered_fb[con2fb_map[prev_console]];
1da177e4
LT
2229 /*
2230 * FIXME: If we have multiple fbdev's loaded, we need to
2231 * update all info->currcon. Perhaps, we can place this
2232 * in a centralized structure, but this might break some
2233 * drivers.
2234 *
2235 * info->currcon = vc->vc_num;
2236 */
10ac8688
YX
2237 for_each_registered_fb(i) {
2238 if (registered_fb[i]->fbcon_par) {
e4fc2761 2239 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
1da177e4 2240
e4fc2761 2241 o->currcon = vc->vc_num;
1da177e4
LT
2242 }
2243 }
2244 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2245 display_to_var(&var, p);
2246 var.activate = FB_ACTIVATE_NOW;
2247
2248 /*
2249 * make sure we don't unnecessarily trip the memcmp()
2250 * in fb_set_var()
2251 */
2252 info->var.activate = var.activate;
10732c35 2253 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
1da177e4 2254 fb_set_var(info, &var);
e4fc2761 2255 ops->var = info->var;
1da177e4 2256
39942fd8
KP
2257 if (old_info != NULL && (old_info != info ||
2258 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
0fcf6ada
FTS
2259 if (info->fbops->fb_set_par) {
2260 ret = info->fbops->fb_set_par(info);
2261
2262 if (ret)
2263 printk(KERN_ERR "fbcon_switch: detected "
2264 "unhandled fb_set_par error, "
2265 "error code %d\n", ret);
2266 }
a39bc34e 2267
5428b044 2268 if (old_info != info)
a39bc34e 2269 fbcon_del_cursor_timer(old_info);
88fb2c6e 2270 }
1da177e4 2271
212f2639
AD
2272 if (fbcon_is_inactive(vc, info) ||
2273 ops->blank_state != FB_BLANK_UNBLANK)
2274 fbcon_del_cursor_timer(info);
2275 else
2276 fbcon_add_cursor_timer(info);
2277
b73deed3 2278 set_blitting_type(vc, info);
e4fc2761
AD
2279 ops->cursor_reset = 1;
2280
b73deed3 2281 if (ops->rotate_font && ops->rotate_font(info, vc)) {
e4fc2761 2282 ops->rotate = FB_ROTATE_UR;
b73deed3 2283 set_blitting_type(vc, info);
e4fc2761 2284 }
1da177e4 2285
b8c90945 2286 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
1da177e4 2287 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
56f0d64d
AD
2288
2289 if (p->userfont)
2290 charcnt = FNTCHARCNT(vc->vc_font.data);
2291
2292 if (charcnt > 256)
2293 vc->vc_complement_mask <<= 1;
2294
1da177e4
LT
2295 updatescrollmode(p, info, vc);
2296
2297 switch (p->scrollmode) {
2298 case SCROLL_WRAP_MOVE:
2299 scrollback_phys_max = p->vrows - vc->vc_rows;
2300 break;
2301 case SCROLL_PAN_MOVE:
2302 case SCROLL_PAN_REDRAW:
2303 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2304 if (scrollback_phys_max < 0)
2305 scrollback_phys_max = 0;
2306 break;
2307 default:
2308 scrollback_phys_max = 0;
2309 break;
2310 }
e4fc2761 2311
1da177e4
LT
2312 scrollback_max = 0;
2313 scrollback_current = 0;
4e1567d3
AD
2314
2315 if (!fbcon_is_inactive(vc, info)) {
2316 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2317 ops->update_start(info);
2318 }
2319
1da177e4
LT
2320 fbcon_set_palette(vc, color_table);
2321 fbcon_clear_margins(vc, 0);
2322
2323 if (logo_shown == FBCON_LOGO_DRAW) {
2324
2325 logo_shown = fg_console;
2326 /* This is protected above by initmem_freed */
9c44e5f6 2327 fb_show_logo(info, ops->rotate);
1da177e4
LT
2328 update_region(vc,
2329 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2330 vc->vc_size_row * (vc->vc_bottom -
2331 vc->vc_top) / 2);
2332 return 0;
2333 }
2334 return 1;
2335}
2336
2337static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2338 int blank)
2339{
994efacd
RP
2340 struct fb_event event;
2341
1da177e4
LT
2342 if (blank) {
2343 unsigned short charmask = vc->vc_hi_font_mask ?
2344 0x1ff : 0xff;
2345 unsigned short oldc;
2346
2347 oldc = vc->vc_video_erase_char;
2348 vc->vc_video_erase_char &= charmask;
2349 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2350 vc->vc_video_erase_char = oldc;
2351 }
994efacd
RP
2352
2353
513adb58
AR
2354 if (!lock_fb_info(info))
2355 return;
994efacd
RP
2356 event.info = info;
2357 event.data = &blank;
2358 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
513adb58 2359 unlock_fb_info(info);
1da177e4
LT
2360}
2361
2362static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2363{
2364 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2365 struct fbcon_ops *ops = info->fbcon_par;
2366
2367 if (mode_switch) {
2368 struct fb_var_screeninfo var = info->var;
2369
2370 ops->graphics = 1;
2371
2372 if (!blank) {
2373 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2374 fb_set_var(info, &var);
2375 ops->graphics = 0;
e4fc2761 2376 ops->var = info->var;
f5c15d0b 2377 }
1da177e4
LT
2378 }
2379
2380 if (!fbcon_is_inactive(vc, info)) {
2381 if (ops->blank_state != blank) {
2382 ops->blank_state = blank;
2383 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2384 ops->cursor_flash = (!blank);
2385
bca404af
DB
2386 if (!(info->flags & FBINFO_MISC_USEREVENT))
2387 if (fb_blank(info, blank))
2388 fbcon_generic_blank(vc, info, blank);
1da177e4
LT
2389 }
2390
88fb2c6e
AD
2391 if (!blank)
2392 update_screen(vc);
2393 }
2394
4d8a2d98 2395 if (mode_switch || fbcon_is_inactive(vc, info) ||
212f2639 2396 ops->blank_state != FB_BLANK_UNBLANK)
88fb2c6e 2397 fbcon_del_cursor_timer(info);
212f2639
AD
2398 else
2399 fbcon_add_cursor_timer(info);
1da177e4 2400
88fb2c6e 2401 return 0;
1da177e4
LT
2402}
2403
d219adc1
JB
2404static int fbcon_debug_enter(struct vc_data *vc)
2405{
2406 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2407 struct fbcon_ops *ops = info->fbcon_par;
2408
2409 ops->save_graphics = ops->graphics;
2410 ops->graphics = 0;
2411 if (info->fbops->fb_debug_enter)
2412 info->fbops->fb_debug_enter(info);
2413 fbcon_set_palette(vc, color_table);
2414 return 0;
2415}
2416
2417static int fbcon_debug_leave(struct vc_data *vc)
2418{
2419 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2420 struct fbcon_ops *ops = info->fbcon_par;
2421
2422 ops->graphics = ops->save_graphics;
2423 if (info->fbops->fb_debug_leave)
2424 info->fbops->fb_debug_leave(info);
2425 return 0;
2426}
2427
1da177e4
LT
2428static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2429{
2430 u8 *fontdata = vc->vc_font.data;
2431 u8 *data = font->data;
2432 int i, j;
2433
2434 font->width = vc->vc_font.width;
2435 font->height = vc->vc_font.height;
2436 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2437 if (!font->data)
2438 return 0;
2439
2440 if (font->width <= 8) {
2441 j = vc->vc_font.height;
2442 for (i = 0; i < font->charcount; i++) {
2443 memcpy(data, fontdata, j);
2444 memset(data + j, 0, 32 - j);
2445 data += 32;
2446 fontdata += j;
2447 }
2448 } else if (font->width <= 16) {
2449 j = vc->vc_font.height * 2;
2450 for (i = 0; i < font->charcount; i++) {
2451 memcpy(data, fontdata, j);
2452 memset(data + j, 0, 64 - j);
2453 data += 64;
2454 fontdata += j;
2455 }
2456 } else if (font->width <= 24) {
2457 for (i = 0; i < font->charcount; i++) {
2458 for (j = 0; j < vc->vc_font.height; j++) {
2459 *data++ = fontdata[0];
2460 *data++ = fontdata[1];
2461 *data++ = fontdata[2];
2462 fontdata += sizeof(u32);
2463 }
2464 memset(data, 0, 3 * (32 - j));
2465 data += 3 * (32 - j);
2466 }
2467 } else {
2468 j = vc->vc_font.height * 4;
2469 for (i = 0; i < font->charcount; i++) {
2470 memcpy(data, fontdata, j);
2471 memset(data + j, 0, 128 - j);
2472 data += 128;
2473 fontdata += j;
2474 }
2475 }
2476 return 0;
2477}
2478
8aac7f34
TI
2479/* set/clear vc_hi_font_mask and update vc attrs accordingly */
2480static void set_vc_hi_font(struct vc_data *vc, bool set)
1da177e4 2481{
8aac7f34 2482 if (!set) {
1da177e4
LT
2483 vc->vc_hi_font_mask = 0;
2484 if (vc->vc_can_do_color) {
2485 vc->vc_complement_mask >>= 1;
2486 vc->vc_s_complement_mask >>= 1;
2487 }
2488
2489 /* ++Edmund: reorder the attribute bits */
2490 if (vc->vc_can_do_color) {
2491 unsigned short *cp =
2492 (unsigned short *) vc->vc_origin;
2493 int count = vc->vc_screenbuf_size / 2;
2494 unsigned short c;
2495 for (; count > 0; count--, cp++) {
2496 c = scr_readw(cp);
2497 scr_writew(((c & 0xfe00) >> 1) |
2498 (c & 0xff), cp);
2499 }
2500 c = vc->vc_video_erase_char;
2501 vc->vc_video_erase_char =
2502 ((c & 0xfe00) >> 1) | (c & 0xff);
2503 vc->vc_attr >>= 1;
2504 }
8aac7f34 2505 } else {
1da177e4
LT
2506 vc->vc_hi_font_mask = 0x100;
2507 if (vc->vc_can_do_color) {
2508 vc->vc_complement_mask <<= 1;
2509 vc->vc_s_complement_mask <<= 1;
2510 }
2511
2512 /* ++Edmund: reorder the attribute bits */
2513 {
2514 unsigned short *cp =
2515 (unsigned short *) vc->vc_origin;
2516 int count = vc->vc_screenbuf_size / 2;
2517 unsigned short c;
2518 for (; count > 0; count--, cp++) {
2519 unsigned short newc;
2520 c = scr_readw(cp);
2521 if (vc->vc_can_do_color)
2522 newc =
2523 ((c & 0xff00) << 1) | (c &
2524 0xff);
2525 else
2526 newc = c & ~0x100;
2527 scr_writew(newc, cp);
2528 }
2529 c = vc->vc_video_erase_char;
2530 if (vc->vc_can_do_color) {
2531 vc->vc_video_erase_char =
2532 ((c & 0xff00) << 1) | (c & 0xff);
2533 vc->vc_attr <<= 1;
93f78da4 2534 } else
1da177e4
LT
2535 vc->vc_video_erase_char = c & ~0x100;
2536 }
1da177e4 2537 }
8aac7f34
TI
2538}
2539
2540static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2541 const u8 * data, int userfont)
2542{
2543 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2544 struct fbcon_ops *ops = info->fbcon_par;
2545 struct display *p = &fb_display[vc->vc_num];
2546 int resize;
2547 int cnt;
2548 char *old_data = NULL;
2549
2550 if (con_is_visible(vc) && softback_lines)
2551 fbcon_set_origin(vc);
2552
2553 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2554 if (p->userfont)
2555 old_data = vc->vc_font.data;
2556 if (userfont)
2557 cnt = FNTCHARCNT(data);
2558 else
2559 cnt = 256;
2560 vc->vc_font.data = (void *)(p->fontdata = data);
2561 if ((p->userfont = userfont))
2562 REFCOUNT(data)++;
2563 vc->vc_font.width = w;
2564 vc->vc_font.height = h;
2565 if (vc->vc_hi_font_mask && cnt == 256)
2566 set_vc_hi_font(vc, false);
2567 else if (!vc->vc_hi_font_mask && cnt == 512)
2568 set_vc_hi_font(vc, true);
1da177e4
LT
2569
2570 if (resize) {
e4fc2761
AD
2571 int cols, rows;
2572
2573 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2574 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2575 cols /= w;
2576 rows /= h;
2577 vc_resize(vc, cols, rows);
6ca8dfd7 2578 if (con_is_visible(vc) && softback_buf)
4d9c5b6e 2579 fbcon_update_softback(vc);
6ca8dfd7 2580 } else if (con_is_visible(vc)
1da177e4
LT
2581 && vc->vc_mode == KD_TEXT) {
2582 fbcon_clear_margins(vc, 0);
2583 update_screen(vc);
2584 }
2585
2586 if (old_data && (--REFCOUNT(old_data) == 0))
2587 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2588 return 0;
2589}
2590
2591static int fbcon_copy_font(struct vc_data *vc, int con)
2592{
2593 struct display *od = &fb_display[con];
2594 struct console_font *f = &vc->vc_font;
2595
2596 if (od->fontdata == f->data)
2597 return 0; /* already the same font... */
2598 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2599}
2600
2601/*
2602 * User asked to set font; we are guaranteed that
2603 * a) width and height are in range 1..32
2604 * b) charcount does not exceed 512
2605 * but lets not assume that, since someone might someday want to use larger
2606 * fonts. And charcount of 512 is small for unicode support.
2607 *
2608 * However, user space gives the font in 32 rows , regardless of
2609 * actual font height. So a new API is needed if support for larger fonts
2610 * is ever implemented.
2611 */
2612
c396a5bf
KC
2613static int fbcon_set_font(struct vc_data *vc, struct console_font *font,
2614 unsigned int flags)
1da177e4 2615{
2d2699d9 2616 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1da177e4
LT
2617 unsigned charcount = font->charcount;
2618 int w = font->width;
2619 int h = font->height;
2620 int size;
2621 int i, csum;
2622 u8 *new_data, *data = font->data;
2623 int pitch = (font->width+7) >> 3;
2624
2625 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2626 * If not this check should be changed to charcount < 256 */
2627 if (charcount != 256 && charcount != 512)
2628 return -EINVAL;
2629
2d2699d9
AD
2630 /* Make sure drawing engine can handle the font */
2631 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2632 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2633 return -EINVAL;
38b4982c
AD
2634
2635 /* Make sure driver can handle the font length */
2636 if (fbcon_invalid_charcount(info, charcount))
2637 return -EINVAL;
2d2699d9 2638
1da177e4
LT
2639 size = h * pitch * charcount;
2640
2641 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2642
2643 if (!new_data)
2644 return -ENOMEM;
2645
2646 new_data += FONT_EXTRA_WORDS * sizeof(int);
2647 FNTSIZE(new_data) = size;
2648 FNTCHARCNT(new_data) = charcount;
2649 REFCOUNT(new_data) = 0; /* usage counter */
2650 for (i=0; i< charcount; i++) {
2651 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2652 }
2653
2654 /* Since linux has a nice crc32 function use it for counting font
2655 * checksums. */
2656 csum = crc32(0, new_data, size);
2657
2658 FNTSUM(new_data) = csum;
2659 /* Check if the same font is on some other console already */
e614b18d 2660 for (i = first_fb_vc; i <= last_fb_vc; i++) {
1da177e4
LT
2661 struct vc_data *tmp = vc_cons[i].d;
2662
2663 if (fb_display[i].userfont &&
2664 fb_display[i].fontdata &&
2665 FNTSUM(fb_display[i].fontdata) == csum &&
2666 FNTSIZE(fb_display[i].fontdata) == size &&
2667 tmp->vc_font.width == w &&
2668 !memcmp(fb_display[i].fontdata, new_data, size)) {
2669 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
2f4516db 2670 new_data = (u8 *)fb_display[i].fontdata;
1da177e4
LT
2671 break;
2672 }
2673 }
2674 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2675}
2676
2677static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2678{
2679 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2f4516db 2680 const struct font_desc *f;
1da177e4
LT
2681
2682 if (!name)
2d2699d9
AD
2683 f = get_default_font(info->var.xres, info->var.yres,
2684 info->pixmap.blit_x, info->pixmap.blit_y);
1da177e4
LT
2685 else if (!(f = find_font(name)))
2686 return -ENOENT;
2687
2688 font->width = f->width;
2689 font->height = f->height;
2690 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2691}
2692
2693static u16 palette_red[16];
2694static u16 palette_green[16];
2695static u16 palette_blue[16];
2696
2697static struct fb_cmap palette_cmap = {
2698 0, 16, palette_red, palette_green, palette_blue, NULL
2699};
2700
709280da 2701static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
1da177e4
LT
2702{
2703 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2704 int i, j, k, depth;
2705 u8 val;
2706
2707 if (fbcon_is_inactive(vc, info))
709280da 2708 return;
1da177e4 2709
6ca8dfd7 2710 if (!con_is_visible(vc))
709280da 2711 return;
1da177e4 2712
b8c90945 2713 depth = fb_get_color_depth(&info->var, &info->fix);
1da177e4
LT
2714 if (depth > 3) {
2715 for (i = j = 0; i < 16; i++) {
2716 k = table[i];
2717 val = vc->vc_palette[j++];
2718 palette_red[k] = (val << 8) | val;
2719 val = vc->vc_palette[j++];
2720 palette_green[k] = (val << 8) | val;
2721 val = vc->vc_palette[j++];
2722 palette_blue[k] = (val << 8) | val;
2723 }
2724 palette_cmap.len = 16;
2725 palette_cmap.start = 0;
2726 /*
2727 * If framebuffer is capable of less than 16 colors,
2728 * use default palette of fbcon.
2729 */
2730 } else
2731 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2732
709280da 2733 fb_set_cmap(&palette_cmap, info);
1da177e4
LT
2734}
2735
2736static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2737{
2738 unsigned long p;
2739 int line;
2740
2741 if (vc->vc_num != fg_console || !softback_lines)
2742 return (u16 *) (vc->vc_origin + offset);
2743 line = offset / vc->vc_size_row;
2744 if (line >= softback_lines)
2745 return (u16 *) (vc->vc_origin + offset -
2746 softback_lines * vc->vc_size_row);
2747 p = softback_curr + offset;
2748 if (p >= softback_end)
2749 p += softback_buf - softback_end;
2750 return (u16 *) p;
2751}
2752
2753static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2754 int *px, int *py)
2755{
2756 unsigned long ret;
2757 int x, y;
2758
2759 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2760 unsigned long offset = (pos - vc->vc_origin) / 2;
2761
2762 x = offset % vc->vc_cols;
2763 y = offset / vc->vc_cols;
2764 if (vc->vc_num == fg_console)
2765 y += softback_lines;
2766 ret = pos + (vc->vc_cols - x) * 2;
2767 } else if (vc->vc_num == fg_console && softback_lines) {
2768 unsigned long offset = pos - softback_curr;
2769
2770 if (pos < softback_curr)
2771 offset += softback_end - softback_buf;
2772 offset /= 2;
2773 x = offset % vc->vc_cols;
2774 y = offset / vc->vc_cols;
2775 ret = pos + (vc->vc_cols - x) * 2;
2776 if (ret == softback_end)
2777 ret = softback_buf;
2778 if (ret == softback_in)
2779 ret = vc->vc_origin;
2780 } else {
2781 /* Should not happen */
2782 x = y = 0;
2783 ret = vc->vc_origin;
2784 }
2785 if (px)
2786 *px = x;
2787 if (py)
2788 *py = y;
2789 return ret;
2790}
2791
2792/* As we might be inside of softback, we may work with non-contiguous buffer,
2793 that's why we have to use a separate routine. */
2794static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2795{
2796 while (cnt--) {
2797 u16 a = scr_readw(p);
2798 if (!vc->vc_can_do_color)
2799 a ^= 0x0800;
2800 else if (vc->vc_hi_font_mask == 0x100)
2801 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2802 (((a) & 0x0e00) << 4);
2803 else
2804 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2805 (((a) & 0x0700) << 4);
2806 scr_writew(a, p++);
2807 if (p == (u16 *) softback_end)
2808 p = (u16 *) softback_buf;
2809 if (p == (u16 *) softback_in)
2810 p = (u16 *) vc->vc_origin;
2811 }
2812}
2813
97293de9 2814static void fbcon_scrolldelta(struct vc_data *vc, int lines)
1da177e4
LT
2815{
2816 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
e4fc2761 2817 struct fbcon_ops *ops = info->fbcon_par;
2c6cc35c 2818 struct display *disp = &fb_display[fg_console];
1da177e4
LT
2819 int offset, limit, scrollback_old;
2820
2821 if (softback_top) {
2822 if (vc->vc_num != fg_console)
97293de9 2823 return;
1da177e4 2824 if (vc->vc_mode != KD_TEXT || !lines)
97293de9 2825 return;
1da177e4
LT
2826 if (logo_shown >= 0) {
2827 struct vc_data *conp2 = vc_cons[logo_shown].d;
2828
2829 if (conp2->vc_top == logo_lines
2830 && conp2->vc_bottom == conp2->vc_rows)
2831 conp2->vc_top = 0;
2832 if (logo_shown == vc->vc_num) {
2833 unsigned long p, q;
2834 int i;
2835
2836 p = softback_in;
2837 q = vc->vc_origin +
2838 logo_lines * vc->vc_size_row;
2839 for (i = 0; i < logo_lines; i++) {
2840 if (p == softback_top)
2841 break;
2842 if (p == softback_buf)
2843 p = softback_end;
2844 p -= vc->vc_size_row;
2845 q -= vc->vc_size_row;
2846 scr_memcpyw((u16 *) q, (u16 *) p,
2847 vc->vc_size_row);
2848 }
308af929 2849 softback_in = softback_curr = p;
1da177e4
LT
2850 update_region(vc, vc->vc_origin,
2851 logo_lines * vc->vc_cols);
2852 }
2853 logo_shown = FBCON_LOGO_CANSHOW;
2854 }
2855 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2c6cc35c 2856 fbcon_redraw_softback(vc, disp, lines);
1da177e4 2857 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
97293de9 2858 return;
1da177e4
LT
2859 }
2860
2861 if (!scrollback_phys_max)
97293de9 2862 return;
1da177e4
LT
2863
2864 scrollback_old = scrollback_current;
2865 scrollback_current -= lines;
2866 if (scrollback_current < 0)
2867 scrollback_current = 0;
2868 else if (scrollback_current > scrollback_max)
2869 scrollback_current = scrollback_max;
2870 if (scrollback_current == scrollback_old)
97293de9 2871 return;
1da177e4
LT
2872
2873 if (fbcon_is_inactive(vc, info))
97293de9 2874 return;
1da177e4
LT
2875
2876 fbcon_cursor(vc, CM_ERASE);
2877
2c6cc35c
MS
2878 offset = disp->yscroll - scrollback_current;
2879 limit = disp->vrows;
2880 switch (disp->scrollmode) {
1da177e4
LT
2881 case SCROLL_WRAP_MOVE:
2882 info->var.vmode |= FB_VMODE_YWRAP;
2883 break;
2884 case SCROLL_PAN_MOVE:
2885 case SCROLL_PAN_REDRAW:
2886 limit -= vc->vc_rows;
2887 info->var.vmode &= ~FB_VMODE_YWRAP;
2888 break;
2889 }
2890 if (offset < 0)
2891 offset += limit;
2892 else if (offset >= limit)
2893 offset -= limit;
e4fc2761
AD
2894
2895 ops->var.xoffset = 0;
2896 ops->var.yoffset = offset * vc->vc_font.height;
2897 ops->update_start(info);
2898
1da177e4
LT
2899 if (!scrollback_current)
2900 fbcon_cursor(vc, CM_DRAW);
1da177e4
LT
2901}
2902
2903static int fbcon_set_origin(struct vc_data *vc)
2904{
2905 if (softback_lines)
2906 fbcon_scrolldelta(vc, softback_lines);
2907 return 0;
2908}
2909
2910static void fbcon_suspended(struct fb_info *info)
2911{
2912 struct vc_data *vc = NULL;
2913 struct fbcon_ops *ops = info->fbcon_par;
2914
2915 if (!ops || ops->currcon < 0)
2916 return;
2917 vc = vc_cons[ops->currcon].d;
2918
2919 /* Clear cursor, restore saved data */
2920 fbcon_cursor(vc, CM_ERASE);
2921}
2922
2923static void fbcon_resumed(struct fb_info *info)
2924{
2925 struct vc_data *vc;
2926 struct fbcon_ops *ops = info->fbcon_par;
2927
2928 if (!ops || ops->currcon < 0)
2929 return;
2930 vc = vc_cons[ops->currcon].d;
2931
2932 update_screen(vc);
2933}
2934
2935static void fbcon_modechanged(struct fb_info *info)
2936{
2937 struct fbcon_ops *ops = info->fbcon_par;
2938 struct vc_data *vc;
2939 struct display *p;
2940 int rows, cols;
2941
2942 if (!ops || ops->currcon < 0)
2943 return;
2944 vc = vc_cons[ops->currcon].d;
e4fc2761
AD
2945 if (vc->vc_mode != KD_TEXT ||
2946 registered_fb[con2fb_map[ops->currcon]] != info)
1da177e4
LT
2947 return;
2948
2949 p = &fb_display[vc->vc_num];
b73deed3 2950 set_blitting_type(vc, info);
1da177e4 2951
6ca8dfd7 2952 if (con_is_visible(vc)) {
1da177e4 2953 var_to_display(p, &info->var, info);
e4fc2761
AD
2954 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2955 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2956 cols /= vc->vc_font.width;
2957 rows /= vc->vc_font.height;
1da177e4
LT
2958 vc_resize(vc, cols, rows);
2959 updatescrollmode(p, info, vc);
2960 scrollback_max = 0;
2961 scrollback_current = 0;
4e1567d3
AD
2962
2963 if (!fbcon_is_inactive(vc, info)) {
2964 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2965 ops->update_start(info);
2966 }
2967
1da177e4
LT
2968 fbcon_set_palette(vc, color_table);
2969 update_screen(vc);
4d9c5b6e
AD
2970 if (softback_buf)
2971 fbcon_update_softback(vc);
1da177e4
LT
2972 }
2973}
2974
7726e9e1
AD
2975static void fbcon_set_all_vcs(struct fb_info *info)
2976{
2977 struct fbcon_ops *ops = info->fbcon_par;
2978 struct vc_data *vc;
2979 struct display *p;
95d67bb1 2980 int i, rows, cols, fg = -1;
7726e9e1
AD
2981
2982 if (!ops || ops->currcon < 0)
2983 return;
2984
e614b18d 2985 for (i = first_fb_vc; i <= last_fb_vc; i++) {
7726e9e1
AD
2986 vc = vc_cons[i].d;
2987 if (!vc || vc->vc_mode != KD_TEXT ||
2988 registered_fb[con2fb_map[i]] != info)
2989 continue;
2990
6ca8dfd7 2991 if (con_is_visible(vc)) {
95d67bb1
AD
2992 fg = i;
2993 continue;
2994 }
2995
7726e9e1 2996 p = &fb_display[vc->vc_num];
b73deed3 2997 set_blitting_type(vc, info);
7726e9e1 2998 var_to_display(p, &info->var, info);
232fb69a
ON
2999 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3000 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
e4fc2761
AD
3001 cols /= vc->vc_font.width;
3002 rows /= vc->vc_font.height;
7726e9e1 3003 vc_resize(vc, cols, rows);
7726e9e1 3004 }
04a2fe57 3005
95d67bb1
AD
3006 if (fg != -1)
3007 fbcon_modechanged(info);
7726e9e1
AD
3008}
3009
1da177e4
LT
3010static int fbcon_mode_deleted(struct fb_info *info,
3011 struct fb_videomode *mode)
3012{
3013 struct fb_info *fb_info;
3014 struct display *p;
3015 int i, j, found = 0;
3016
3017 /* before deletion, ensure that mode is not in use */
3018 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3019 j = con2fb_map[i];
3020 if (j == -1)
3021 continue;
3022 fb_info = registered_fb[j];
3023 if (fb_info != info)
3024 continue;
3025 p = &fb_display[i];
3026 if (!p || !p->mode)
3027 continue;
3028 if (fb_mode_is_equal(p->mode, mode)) {
3029 found = 1;
3030 break;
3031 }
3032 }
3033 return found;
3034}
3035
cfafca80
JB
3036#ifdef CONFIG_VT_HW_CONSOLE_BINDING
3037static int fbcon_unbind(void)
3038{
3039 int ret;
3040
e93a9a86 3041 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
cfafca80 3042 fbcon_is_default);
2ddce3fd
IA
3043
3044 if (!ret)
3045 fbcon_has_console_bind = 0;
3046
cfafca80
JB
3047 return ret;
3048}
3049#else
3050static inline int fbcon_unbind(void)
3051{
3052 return -EINVAL;
3053}
3054#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3055
054430e7 3056/* called with console_lock held */
cfafca80
JB
3057static int fbcon_fb_unbind(int idx)
3058{
3059 int i, new_idx = -1, ret = 0;
3060
3bd3a0e3
HG
3061 WARN_CONSOLE_UNLOCKED();
3062
2ddce3fd
IA
3063 if (!fbcon_has_console_bind)
3064 return 0;
3065
cfafca80
JB
3066 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3067 if (con2fb_map[i] != idx &&
3068 con2fb_map[i] != -1) {
3069 new_idx = i;
3070 break;
3071 }
3072 }
3073
3074 if (new_idx != -1) {
3075 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3076 if (con2fb_map[i] == idx)
3077 set_con2fb_map(i, new_idx, 0);
3078 }
5f4dc28b
KP
3079 } else {
3080 struct fb_info *info = registered_fb[idx];
3081
3082 /* This is sort of like set_con2fb_map, except it maps
3083 * the consoles to no device and then releases the
3084 * oldinfo to free memory and cancel the cursor blink
3085 * timer. I can imagine this just becoming part of
3086 * set_con2fb_map where new_idx is -1
3087 */
3088 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3089 if (con2fb_map[i] == idx) {
3090 con2fb_map[i] = -1;
3091 if (!search_fb_in_map(idx)) {
3092 ret = con2fb_release_oldinfo(vc_cons[i].d,
3093 info, NULL, i,
3094 idx, 0);
3095 if (ret) {
3096 con2fb_map[i] = idx;
3097 return ret;
3098 }
3099 }
3100 }
3101 }
cfafca80 3102 ret = fbcon_unbind();
5f4dc28b 3103 }
cfafca80
JB
3104
3105 return ret;
3106}
3107
054430e7 3108/* called with console_lock held */
623e71b0 3109static int fbcon_fb_unregistered(struct fb_info *info)
e614b18d 3110{
66c1ca01 3111 int i, idx;
e614b18d 3112
3bd3a0e3
HG
3113 WARN_CONSOLE_UNLOCKED();
3114
83d83beb
HG
3115 if (deferred_takeover)
3116 return 0;
3117
66c1ca01 3118 idx = info->node;
e614b18d
AD
3119 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3120 if (con2fb_map[i] == idx)
3121 con2fb_map[i] = -1;
3122 }
3123
3124 if (idx == info_idx) {
3125 info_idx = -1;
3126
10ac8688
YX
3127 for_each_registered_fb(i) {
3128 info_idx = i;
3129 break;
e614b18d
AD
3130 }
3131 }
3132
3133 if (info_idx != -1) {
3134 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3135 if (con2fb_map[i] == -1)
3136 con2fb_map[i] = info_idx;
3137 }
3138 }
3139
623e71b0
AD
3140 if (primary_device == idx)
3141 primary_device = -1;
3142
66c1ca01 3143 if (!num_registered_fb)
e93a9a86 3144 do_unregister_con_driver(&fb_con);
66c1ca01 3145
623e71b0
AD
3146 return 0;
3147}
3148
054430e7 3149/* called with console_lock held */
6a9ee8af
DA
3150static void fbcon_remap_all(int idx)
3151{
3152 int i;
3bd3a0e3
HG
3153
3154 WARN_CONSOLE_UNLOCKED();
3155
83d83beb
HG
3156 if (deferred_takeover) {
3157 for (i = first_fb_vc; i <= last_fb_vc; i++)
3158 con2fb_map_boot[i] = idx;
3159 fbcon_map_override();
3160 return;
3161 }
3162
6a9ee8af
DA
3163 for (i = first_fb_vc; i <= last_fb_vc; i++)
3164 set_con2fb_map(i, idx, 0);
3165
3166 if (con_is_bound(&fb_con)) {
3167 printk(KERN_INFO "fbcon: Remapping primary device, "
3168 "fb%i, to tty %i-%i\n", idx,
3169 first_fb_vc + 1, last_fb_vc + 1);
3170 info_idx = idx;
3171 }
3172}
3173
623e71b0 3174#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
afd1db16 3175static void fbcon_select_primary(struct fb_info *info)
623e71b0 3176{
623e71b0
AD
3177 if (!map_override && primary_device == -1 &&
3178 fb_is_primary_device(info)) {
afd1db16 3179 int i;
623e71b0 3180
afd1db16
AD
3181 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3182 info->fix.id, info->node);
623e71b0
AD
3183 primary_device = info->node;
3184
afd1db16 3185 for (i = first_fb_vc; i <= last_fb_vc; i++)
623e71b0 3186 con2fb_map_boot[i] = primary_device;
623e71b0 3187
afd1db16
AD
3188 if (con_is_bound(&fb_con)) {
3189 printk(KERN_INFO "fbcon: Remapping primary device, "
3190 "fb%i, to tty %i-%i\n", info->node,
3191 first_fb_vc + 1, last_fb_vc + 1);
3192 info_idx = primary_device;
623e71b0 3193 }
623e71b0
AD
3194 }
3195
623e71b0
AD
3196}
3197#else
afd1db16 3198static inline void fbcon_select_primary(struct fb_info *info)
623e71b0 3199{
afd1db16 3200 return;
e614b18d 3201}
623e71b0 3202#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
e614b18d 3203
054430e7 3204/* called with console_lock held */
623e71b0 3205static int fbcon_fb_registered(struct fb_info *info)
1da177e4 3206{
66c1ca01 3207 int ret = 0, i, idx;
623e71b0 3208
3bd3a0e3
HG
3209 WARN_CONSOLE_UNLOCKED();
3210
66c1ca01 3211 idx = info->node;
afd1db16 3212 fbcon_select_primary(info);
1da177e4 3213
83d83beb
HG
3214 if (deferred_takeover) {
3215 pr_info("fbcon: Deferring console take-over\n");
3216 return 0;
3217 }
3218
1da177e4 3219 if (info_idx == -1) {
e614b18d 3220 for (i = first_fb_vc; i <= last_fb_vc; i++) {
1da177e4
LT
3221 if (con2fb_map_boot[i] == idx) {
3222 info_idx = idx;
3223 break;
3224 }
3225 }
e614b18d 3226
1da177e4 3227 if (info_idx != -1)
50e244cc 3228 ret = do_fbcon_takeover(1);
1da177e4 3229 } else {
e614b18d 3230 for (i = first_fb_vc; i <= last_fb_vc; i++) {
d1baa4ff 3231 if (con2fb_map_boot[i] == idx)
1da177e4
LT
3232 set_con2fb_map(i, idx, 0);
3233 }
3234 }
3235
3236 return ret;
3237}
3238
3239static void fbcon_fb_blanked(struct fb_info *info, int blank)
3240{
3241 struct fbcon_ops *ops = info->fbcon_par;
3242 struct vc_data *vc;
3243
3244 if (!ops || ops->currcon < 0)
3245 return;
3246
3247 vc = vc_cons[ops->currcon].d;
3248 if (vc->vc_mode != KD_TEXT ||
3249 registered_fb[con2fb_map[ops->currcon]] != info)
3250 return;
3251
6ca8dfd7 3252 if (con_is_visible(vc)) {
1da177e4
LT
3253 if (blank)
3254 do_blank_screen(0);
3255 else
3256 do_unblank_screen(0);
3257 }
3258 ops->blank_state = blank;
3259}
3260
3261static void fbcon_new_modelist(struct fb_info *info)
3262{
3263 int i;
3264 struct vc_data *vc;
3265 struct fb_var_screeninfo var;
9791d763 3266 const struct fb_videomode *mode;
1da177e4 3267
e614b18d 3268 for (i = first_fb_vc; i <= last_fb_vc; i++) {
1da177e4
LT
3269 if (registered_fb[con2fb_map[i]] != info)
3270 continue;
3271 if (!fb_display[i].mode)
3272 continue;
3273 vc = vc_cons[i].d;
3274 display_to_var(&var, &fb_display[i]);
8fb6567e
MJ
3275 mode = fb_find_nearest_mode(fb_display[i].mode,
3276 &info->modelist);
1da177e4 3277 fb_videomode_to_var(&var, mode);
d1baa4ff 3278 fbcon_set_disp(info, &var, vc->vc_num);
1da177e4
LT
3279 }
3280}
3281
38a3dc51
AD
3282static void fbcon_get_requirement(struct fb_info *info,
3283 struct fb_blit_caps *caps)
3284{
3285 struct vc_data *vc;
3286 struct display *p;
38a3dc51
AD
3287
3288 if (caps->flags) {
167f07f1 3289 int i, charcnt;
38a3dc51
AD
3290
3291 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3292 vc = vc_cons[i].d;
167f07f1
AD
3293 if (vc && vc->vc_mode == KD_TEXT &&
3294 info->node == con2fb_map[i]) {
38a3dc51
AD
3295 p = &fb_display[i];
3296 caps->x |= 1 << (vc->vc_font.width - 1);
3297 caps->y |= 1 << (vc->vc_font.height - 1);
3298 charcnt = (p->userfont) ?
3299 FNTCHARCNT(p->fontdata) : 256;
3300 if (caps->len < charcnt)
3301 caps->len = charcnt;
3302 }
3303 }
3304 } else {
3305 vc = vc_cons[fg_console].d;
3306
167f07f1
AD
3307 if (vc && vc->vc_mode == KD_TEXT &&
3308 info->node == con2fb_map[fg_console]) {
38a3dc51 3309 p = &fb_display[fg_console];
167f07f1
AD
3310 caps->x = 1 << (vc->vc_font.width - 1);
3311 caps->y = 1 << (vc->vc_font.height - 1);
3312 caps->len = (p->userfont) ?
38a3dc51 3313 FNTCHARCNT(p->fontdata) : 256;
38a3dc51
AD
3314 }
3315 }
3316}
3317
66c1ca01 3318static int fbcon_event_notify(struct notifier_block *self,
1da177e4
LT
3319 unsigned long action, void *data)
3320{
3321 struct fb_event *event = data;
3322 struct fb_info *info = event->info;
3323 struct fb_videomode *mode;
3324 struct fb_con2fbmap *con2fb;
38a3dc51 3325 struct fb_blit_caps *caps;
66c1ca01 3326 int idx, ret = 0;
1da177e4 3327
e614b18d
AD
3328 /*
3329 * ignore all events except driver registration and deregistration
3330 * if fbcon is not active
3331 */
3332 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3333 action == FB_EVENT_FB_UNREGISTERED))
3334 goto done;
3335
1da177e4
LT
3336 switch(action) {
3337 case FB_EVENT_SUSPEND:
3338 fbcon_suspended(info);
3339 break;
3340 case FB_EVENT_RESUME:
3341 fbcon_resumed(info);
3342 break;
3343 case FB_EVENT_MODE_CHANGE:
3344 fbcon_modechanged(info);
3345 break;
7726e9e1
AD
3346 case FB_EVENT_MODE_CHANGE_ALL:
3347 fbcon_set_all_vcs(info);
3348 break;
1da177e4
LT
3349 case FB_EVENT_MODE_DELETE:
3350 mode = event->data;
3351 ret = fbcon_mode_deleted(info, mode);
3352 break;
cfafca80 3353 case FB_EVENT_FB_UNBIND:
66c1ca01 3354 idx = info->node;
66c1ca01 3355 ret = fbcon_fb_unbind(idx);
cfafca80 3356 break;
1da177e4 3357 case FB_EVENT_FB_REGISTERED:
623e71b0 3358 ret = fbcon_fb_registered(info);
1da177e4 3359 break;
e614b18d 3360 case FB_EVENT_FB_UNREGISTERED:
623e71b0 3361 ret = fbcon_fb_unregistered(info);
e614b18d 3362 break;
1da177e4 3363 case FB_EVENT_SET_CONSOLE_MAP:
054430e7 3364 /* called with console lock held */
1da177e4
LT
3365 con2fb = event->data;
3366 ret = set_con2fb_map(con2fb->console - 1,
3367 con2fb->framebuffer, 1);
3368 break;
3369 case FB_EVENT_GET_CONSOLE_MAP:
3370 con2fb = event->data;
3371 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3372 break;
3373 case FB_EVENT_BLANK:
3374 fbcon_fb_blanked(info, *(int *)event->data);
3375 break;
3376 case FB_EVENT_NEW_MODELIST:
3377 fbcon_new_modelist(info);
3378 break;
38a3dc51
AD
3379 case FB_EVENT_GET_REQ:
3380 caps = event->data;
3381 fbcon_get_requirement(info, caps);
3382 break;
6a9ee8af
DA
3383 case FB_EVENT_REMAP_ALL_CONSOLE:
3384 idx = info->node;
3385 fbcon_remap_all(idx);
3386 break;
1da177e4 3387 }
e614b18d 3388done:
1da177e4
LT
3389 return ret;
3390}
3391
3392/*
3393 * The console `switch' structure for the frame buffer based console
3394 */
3395
3396static const struct consw fb_con = {
3397 .owner = THIS_MODULE,
3398 .con_startup = fbcon_startup,
3399 .con_init = fbcon_init,
3400 .con_deinit = fbcon_deinit,
3401 .con_clear = fbcon_clear,
3402 .con_putc = fbcon_putc,
3403 .con_putcs = fbcon_putcs,
3404 .con_cursor = fbcon_cursor,
3405 .con_scroll = fbcon_scroll,
1da177e4
LT
3406 .con_switch = fbcon_switch,
3407 .con_blank = fbcon_blank,
3408 .con_font_set = fbcon_set_font,
3409 .con_font_get = fbcon_get_font,
3410 .con_font_default = fbcon_set_def_font,
3411 .con_font_copy = fbcon_copy_font,
3412 .con_set_palette = fbcon_set_palette,
3413 .con_scrolldelta = fbcon_scrolldelta,
3414 .con_set_origin = fbcon_set_origin,
3415 .con_invert_region = fbcon_invert_region,
3416 .con_screen_pos = fbcon_screen_pos,
3417 .con_getxy = fbcon_getxy,
3418 .con_resize = fbcon_resize,
d219adc1
JB
3419 .con_debug_enter = fbcon_debug_enter,
3420 .con_debug_leave = fbcon_debug_leave,
1da177e4
LT
3421};
3422
3423static struct notifier_block fbcon_event_notifier = {
3424 .notifier_call = fbcon_event_notify,
3425};
3426
0c6c1ce0
AD
3427static ssize_t store_rotate(struct device *device,
3428 struct device_attribute *attr, const char *buf,
3429 size_t count)
9a179176
AD
3430{
3431 struct fb_info *info;
3432 int rotate, idx;
3433 char **last = NULL;
3434
e614b18d
AD
3435 if (fbcon_has_exited)
3436 return count;
3437
ac751efa 3438 console_lock();
9a179176
AD
3439 idx = con2fb_map[fg_console];
3440
3441 if (idx == -1 || registered_fb[idx] == NULL)
3442 goto err;
3443
3444 info = registered_fb[idx];
3445 rotate = simple_strtoul(buf, last, 0);
3446 fbcon_rotate(info, rotate);
3447err:
ac751efa 3448 console_unlock();
9a179176
AD
3449 return count;
3450}
3451
0c6c1ce0
AD
3452static ssize_t store_rotate_all(struct device *device,
3453 struct device_attribute *attr,const char *buf,
3454 size_t count)
9a179176
AD
3455{
3456 struct fb_info *info;
3457 int rotate, idx;
3458 char **last = NULL;
3459
e614b18d
AD
3460 if (fbcon_has_exited)
3461 return count;
3462
ac751efa 3463 console_lock();
9a179176
AD
3464 idx = con2fb_map[fg_console];
3465
3466 if (idx == -1 || registered_fb[idx] == NULL)
3467 goto err;
3468
3469 info = registered_fb[idx];
3470 rotate = simple_strtoul(buf, last, 0);
3471 fbcon_rotate_all(info, rotate);
3472err:
ac751efa 3473 console_unlock();
9a179176
AD
3474 return count;
3475}
3476
0c6c1ce0
AD
3477static ssize_t show_rotate(struct device *device,
3478 struct device_attribute *attr,char *buf)
9a179176
AD
3479{
3480 struct fb_info *info;
3481 int rotate = 0, idx;
3482
e614b18d
AD
3483 if (fbcon_has_exited)
3484 return 0;
3485
ac751efa 3486 console_lock();
9a179176
AD
3487 idx = con2fb_map[fg_console];
3488
3489 if (idx == -1 || registered_fb[idx] == NULL)
3490 goto err;
3491
3492 info = registered_fb[idx];
3493 rotate = fbcon_get_rotate(info);
3494err:
ac751efa 3495 console_unlock();
9a179176
AD
3496 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3497}
3498
0c6c1ce0
AD
3499static ssize_t show_cursor_blink(struct device *device,
3500 struct device_attribute *attr, char *buf)
acba9cd0
AD
3501{
3502 struct fb_info *info;
3503 struct fbcon_ops *ops;
3504 int idx, blink = -1;
3505
3506 if (fbcon_has_exited)
3507 return 0;
3508
ac751efa 3509 console_lock();
acba9cd0
AD
3510 idx = con2fb_map[fg_console];
3511
3512 if (idx == -1 || registered_fb[idx] == NULL)
3513 goto err;
3514
3515 info = registered_fb[idx];
3516 ops = info->fbcon_par;
3517
3518 if (!ops)
3519 goto err;
3520
3521 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3522err:
ac751efa 3523 console_unlock();
acba9cd0
AD
3524 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3525}
3526
0c6c1ce0
AD
3527static ssize_t store_cursor_blink(struct device *device,
3528 struct device_attribute *attr,
acba9cd0
AD
3529 const char *buf, size_t count)
3530{
3531 struct fb_info *info;
3532 int blink, idx;
3533 char **last = NULL;
3534
3535 if (fbcon_has_exited)
3536 return count;
3537
ac751efa 3538 console_lock();
acba9cd0
AD
3539 idx = con2fb_map[fg_console];
3540
3541 if (idx == -1 || registered_fb[idx] == NULL)
3542 goto err;
3543
3544 info = registered_fb[idx];
3545
3546 if (!info->fbcon_par)
3547 goto err;
3548
3549 blink = simple_strtoul(buf, last, 0);
3550
3551 if (blink) {
3552 fbcon_cursor_noblink = 0;
3553 fbcon_add_cursor_timer(info);
3554 } else {
3555 fbcon_cursor_noblink = 1;
3556 fbcon_del_cursor_timer(info);
3557 }
3558
3559err:
ac751efa 3560 console_unlock();
acba9cd0
AD
3561 return count;
3562}
3563
0c6c1ce0 3564static struct device_attribute device_attrs[] = {
9a179176
AD
3565 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3566 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
acba9cd0
AD
3567 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3568 store_cursor_blink),
9a179176
AD
3569};
3570
0c6c1ce0 3571static int fbcon_init_device(void)
9a179176 3572{
0a727dea
AD
3573 int i, error = 0;
3574
3575 fbcon_has_sysfs = 1;
3576
0c6c1ce0
AD
3577 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3578 error = device_create_file(fbcon_device, &device_attrs[i]);
0a727dea
AD
3579
3580 if (error)
3581 break;
3582 }
3583
3584 if (error) {
3585 while (--i >= 0)
0c6c1ce0 3586 device_remove_file(fbcon_device, &device_attrs[i]);
0a727dea
AD
3587
3588 fbcon_has_sysfs = 0;
3589 }
9a179176 3590
9a179176
AD
3591 return 0;
3592}
3593
83d83beb 3594#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
df37e225
HG
3595static void fbcon_register_existing_fbs(struct work_struct *work)
3596{
3597 int i;
3598
3599 console_lock();
3600
3601 for_each_registered_fb(i)
3602 fbcon_fb_registered(registered_fb[i]);
3603
3604 console_unlock();
3605}
3606
83d83beb 3607static struct notifier_block fbcon_output_nb;
df37e225 3608static DECLARE_WORK(fbcon_deferred_takeover_work, fbcon_register_existing_fbs);
83d83beb
HG
3609
3610static int fbcon_output_notifier(struct notifier_block *nb,
3611 unsigned long action, void *data)
3612{
83d83beb
HG
3613 WARN_CONSOLE_UNLOCKED();
3614
3615 pr_info("fbcon: Taking over console\n");
3616
3617 dummycon_unregister_output_notifier(&fbcon_output_nb);
3618 deferred_takeover = false;
3619 logo_shown = FBCON_LOGO_DONTSHOW;
3620
df37e225
HG
3621 /* We may get called in atomic context */
3622 schedule_work(&fbcon_deferred_takeover_work);
83d83beb
HG
3623
3624 return NOTIFY_OK;
3625}
83d83beb
HG
3626#endif
3627
5428b044 3628static void fbcon_start(void)
1da177e4 3629{
bedb38fc
HG
3630 WARN_CONSOLE_UNLOCKED();
3631
3632#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3633 if (conswitchp != &dummy_con)
3634 deferred_takeover = false;
3635
83d83beb 3636 if (deferred_takeover) {
bedb38fc
HG
3637 fbcon_output_nb.notifier_call = fbcon_output_notifier;
3638 dummycon_register_output_notifier(&fbcon_output_nb);
83d83beb
HG
3639 return;
3640 }
bedb38fc 3641#endif
83d83beb 3642
5428b044
AD
3643 if (num_registered_fb) {
3644 int i;
9a179176 3645
10ac8688
YX
3646 for_each_registered_fb(i) {
3647 info_idx = i;
3648 break;
1da177e4 3649 }
5428b044 3650
e57f35d4 3651 do_fbcon_takeover(0);
1da177e4 3652 }
9a179176
AD
3653}
3654
5428b044 3655static void fbcon_exit(void)
9a179176 3656{
e55186fe
AD
3657 struct fb_info *info;
3658 int i, j, mapped;
3659
e614b18d
AD
3660 if (fbcon_has_exited)
3661 return;
3662
83d83beb
HG
3663#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
3664 if (deferred_takeover) {
3665 dummycon_unregister_output_notifier(&fbcon_output_nb);
3666 deferred_takeover = false;
3667 }
3668#endif
3669
e55186fe 3670 kfree((void *)softback_buf);
5428b044 3671 softback_buf = 0UL;
e55186fe 3672
10ac8688 3673 for_each_registered_fb(i) {
142092e5 3674 int pending = 0;
beaa4867 3675
e55186fe
AD
3676 mapped = 0;
3677 info = registered_fb[i];
3678
142092e5
JP
3679 if (info->queue.func)
3680 pending = cancel_work_sync(&info->queue);
beaa4867
GL
3681 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3682 "no"));
3683
e614b18d 3684 for (j = first_fb_vc; j <= last_fb_vc; j++) {
5aa133d6 3685 if (con2fb_map[j] == i) {
e55186fe 3686 mapped = 1;
5aa133d6
WY
3687 break;
3688 }
e55186fe
AD
3689 }
3690
3691 if (mapped) {
3692 if (info->fbops->fb_release)
3693 info->fbops->fb_release(info, 0);
3694 module_put(info->fbops->owner);
5428b044
AD
3695
3696 if (info->fbcon_par) {
e299dd4d
DJ
3697 struct fbcon_ops *ops = info->fbcon_par;
3698
5428b044 3699 fbcon_del_cursor_timer(info);
e299dd4d 3700 kfree(ops->cursor_src);
46862145 3701 kfree(ops->cursor_state.mask);
5428b044
AD
3702 kfree(info->fbcon_par);
3703 info->fbcon_par = NULL;
3704 }
3705
3706 if (info->queue.func == fb_flashcursor)
3707 info->queue.func = NULL;
e55186fe
AD
3708 }
3709 }
3710
e614b18d 3711 fbcon_has_exited = 1;
5428b044
AD
3712}
3713
6104c370 3714void __init fb_console_init(void)
5428b044
AD
3715{
3716 int i;
3717
ac751efa 3718 console_lock();
5428b044 3719 fb_register_client(&fbcon_event_notifier);
77997aaa
GKH
3720 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3721 "fbcon");
5428b044 3722
0c6c1ce0
AD
3723 if (IS_ERR(fbcon_device)) {
3724 printk(KERN_WARNING "Unable to create device "
5428b044 3725 "for fbcon; errno = %ld\n",
0c6c1ce0
AD
3726 PTR_ERR(fbcon_device));
3727 fbcon_device = NULL;
5428b044 3728 } else
0c6c1ce0 3729 fbcon_init_device();
5428b044
AD
3730
3731 for (i = 0; i < MAX_NR_CONSOLES; i++)
3732 con2fb_map[i] = -1;
3733
5428b044 3734 fbcon_start();
bedb38fc 3735 console_unlock();
5428b044
AD
3736}
3737
5428b044
AD
3738#ifdef MODULE
3739
0c6c1ce0 3740static void __exit fbcon_deinit_device(void)
5428b044
AD
3741{
3742 int i;
3743
0a727dea 3744 if (fbcon_has_sysfs) {
0c6c1ce0
AD
3745 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3746 device_remove_file(fbcon_device, &device_attrs[i]);
0a727dea
AD
3747
3748 fbcon_has_sysfs = 0;
3749 }
9a179176
AD
3750}
3751
6104c370 3752void __exit fb_console_exit(void)
1da177e4 3753{
ac751efa 3754 console_lock();
1da177e4 3755 fb_unregister_client(&fbcon_event_notifier);
0c6c1ce0
AD
3756 fbcon_deinit_device();
3757 device_destroy(fb_class, MKDEV(0, 0));
e614b18d 3758 fbcon_exit();
70125e76 3759 do_unregister_con_driver(&fb_con);
ac751efa 3760 console_unlock();
1da177e4 3761}
1da177e4 3762#endif