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