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