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