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