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