blob: 4bee7c2e6313925c2905d46cbca23de42012c478 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/module.h>
62#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#include <linux/fs.h>
64#include <linux/kernel.h>
65#include <linux/delay.h> /* MSch: for IRQ probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#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 */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -070078#include <asm/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <asm/irq.h>
80#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82#include "fbcon.h"
83
84#ifdef FBCONDEBUG
Harvey Harrison5ae12172008-04-28 02:15:47 -070085# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#else
87# define DPRINTK(fmt, args...)
88#endif
89
90enum {
91 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
92 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
93 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
94};
95
Antonino A. Daplasab767202005-11-13 16:06:32 -080096static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -080097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static signed char con2fb_map[MAX_NR_CONSOLES];
99static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static int logo_lines;
102/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
103 enums. */
104static int logo_shown = FBCON_LOGO_CANSHOW;
105/* Software scrollback */
106static int fbcon_softback_size = 32768;
107static unsigned long softback_buf, softback_curr;
108static unsigned long softback_in;
109static unsigned long softback_top, softback_end;
110static int softback_lines;
111/* console mappings */
112static int first_fb_vc;
113static int last_fb_vc = MAX_NR_CONSOLES - 1;
114static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700115static int fbcon_has_exited;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700116static int primary_device = -1;
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700117
118#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700119static int map_override;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700120
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700121static inline void fbcon_map_override(void)
122{
123 map_override = 1;
124}
125#else
126static inline void fbcon_map_override(void)
127{
128}
129#endif /* CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY */
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* font data */
132static char fontname[40];
133
134/* current fb_info */
135static int info_idx = -1;
136
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800137/* console rotation */
Marcin Slusarz2428e592008-02-06 01:39:14 -0800138static int initial_rotation;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700139static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141static const struct consw fb_con;
142
143#define CM_SOFTBACK (8)
144
145#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static int fbcon_set_origin(struct vc_data *);
148
149#define CURSOR_DRAW_DELAY (1)
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static int vbl_cursor_cnt;
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700152static int fbcon_cursor_noblink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
155
156/*
157 * Interface used by the world
158 */
159
160static const char *fbcon_startup(void);
161static void fbcon_init(struct vc_data *vc, int init);
162static void fbcon_deinit(struct vc_data *vc);
163static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
164 int width);
165static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
166static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
167 int count, int ypos, int xpos);
168static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
169static void fbcon_cursor(struct vc_data *vc, int mode);
170static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
171 int count);
172static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
173 int height, int width);
174static int fbcon_switch(struct vc_data *vc);
175static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
176static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
177static int fbcon_scrolldelta(struct vc_data *vc, int lines);
178
179/*
180 * Internal routines
181 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static __inline__ void ywrap_up(struct vc_data *vc, int count);
183static __inline__ void ywrap_down(struct vc_data *vc, int count);
184static __inline__ void ypan_up(struct vc_data *vc, int count);
185static __inline__ void ypan_down(struct vc_data *vc, int count);
186static 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);
188static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700189 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
191 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800192static void fbcon_modechanged(struct fb_info *info);
193static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700194static void fbcon_start(void);
195static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700196static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700197
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800198#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800199static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800200{
201 struct fbcon_ops *ops = info->fbcon_par;
202
203 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800204 ops->p->con_rotate < 4)
205 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800206 else
207 ops->rotate = 0;
208}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800209
210static void fbcon_rotate(struct fb_info *info, u32 rotate)
211{
212 struct fbcon_ops *ops= info->fbcon_par;
213 struct fb_info *fb_info;
214
215 if (!ops || ops->currcon == -1)
216 return;
217
218 fb_info = registered_fb[con2fb_map[ops->currcon]];
219
220 if (info == fb_info) {
221 struct display *p = &fb_display[ops->currcon];
222
223 if (rotate < 4)
224 p->con_rotate = rotate;
225 else
226 p->con_rotate = 0;
227
228 fbcon_modechanged(info);
229 }
230}
231
232static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
233{
234 struct fbcon_ops *ops = info->fbcon_par;
235 struct vc_data *vc;
236 struct display *p;
237 int i;
238
239 if (!ops || ops->currcon < 0 || rotate > 3)
240 return;
241
Antonino A. Daplase614b182006-06-26 00:27:09 -0700242 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800243 vc = vc_cons[i].d;
244 if (!vc || vc->vc_mode != KD_TEXT ||
245 registered_fb[con2fb_map[i]] != info)
246 continue;
247
248 p = &fb_display[vc->vc_num];
249 p->con_rotate = rotate;
250 }
251
252 fbcon_set_all_vcs(info);
253}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800254#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800255static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800256{
257 struct fbcon_ops *ops = info->fbcon_par;
258
259 ops->rotate = FB_ROTATE_UR;
260}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800261
262static void fbcon_rotate(struct fb_info *info, u32 rotate)
263{
264 return;
265}
266
267static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
268{
269 return;
270}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800271#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800272
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800273static int fbcon_get_rotate(struct fb_info *info)
274{
275 struct fbcon_ops *ops = info->fbcon_par;
276
277 return (ops) ? ops->rotate : 0;
278}
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
281{
282 struct fbcon_ops *ops = info->fbcon_par;
283
284 return (info->state != FBINFO_STATE_RUNNING ||
285 vc->vc_mode != KD_TEXT || ops->graphics);
286}
287
288static inline int get_color(struct vc_data *vc, struct fb_info *info,
289 u16 c, int is_fg)
290{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700291 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 int color = 0;
293
294 if (console_blanked) {
295 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
296
297 c = vc->vc_video_erase_char & charmask;
298 }
299
300 if (depth != 1)
301 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
302 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
303
304 switch (depth) {
305 case 1:
306 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800307 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700309 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
310 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312 if (console_blanked)
313 fg = bg;
314
315 color = (is_fg) ? fg : bg;
316 break;
317 }
318 case 2:
319 /*
320 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700321 * is grayscale. However, simply dividing the values by 4
322 * will not work, as colors 1, 2 and 3 will be scaled-down
323 * to zero rendering them invisible. So empirically convert
324 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700326 switch (color) {
327 case 0:
328 color = 0; /* black */
329 break;
330 case 1 ... 6:
331 color = 2; /* white */
332 break;
333 case 7 ... 8:
334 color = 1; /* gray */
335 break;
336 default:
337 color = 3; /* intense white */
338 break;
339 }
340 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 case 3:
342 /*
343 * Last 8 entries of default 16-color palette is a more intense
344 * version of the first 8 (i.e., same chrominance, different
345 * luminance).
346 */
347 color &= 7;
348 break;
349 }
350
351
352 return color;
353}
354
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800355static void fbcon_update_softback(struct vc_data *vc)
356{
357 int l = fbcon_softback_size / vc->vc_size_row;
358
359 if (l > 5)
360 softback_end = softback_buf + l * vc->vc_size_row;
361 else
362 /* Smaller scrollback makes no sense, and 0 would screw
363 the operation totally */
364 softback_top = 0;
365}
366
David Howellsc4028952006-11-22 14:57:56 +0000367static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
David Howellsc4028952006-11-22 14:57:56 +0000369 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 struct fbcon_ops *ops = info->fbcon_par;
371 struct display *p;
372 struct vc_data *vc = NULL;
373 int c;
374 int mode;
375
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700376 acquire_console_sem();
377 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 vc = vc_cons[ops->currcon].d;
379
380 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700381 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700382 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700383 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700385 }
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 p = &fb_display[vc->vc_num];
388 c = scr_readw((u16 *) vc->vc_pos);
389 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
390 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800391 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 get_color(vc, info, c, 0));
393 release_console_sem();
394}
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396static void cursor_timer_handler(unsigned long dev_addr)
397{
398 struct fb_info *info = (struct fb_info *) dev_addr;
399 struct fbcon_ops *ops = info->fbcon_par;
400
401 schedule_work(&info->queue);
402 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
403}
404
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700405static void fbcon_add_cursor_timer(struct fb_info *info)
406{
407 struct fbcon_ops *ops = info->fbcon_par;
408
409 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700410 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
411 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700412 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000413 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700414
415 init_timer(&ops->cursor_timer);
416 ops->cursor_timer.function = cursor_timer_handler;
417 ops->cursor_timer.expires = jiffies + HZ / 5;
418 ops->cursor_timer.data = (unsigned long ) info;
419 add_timer(&ops->cursor_timer);
420 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
421 }
422}
423
424static void fbcon_del_cursor_timer(struct fb_info *info)
425{
426 struct fbcon_ops *ops = info->fbcon_par;
427
428 if (info->queue.func == fb_flashcursor &&
429 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
430 del_timer_sync(&ops->cursor_timer);
431 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
432 }
433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#ifndef MODULE
436static int __init fb_console_setup(char *this_opt)
437{
438 char *options;
439 int i, j;
440
441 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800442 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 while ((options = strsep(&this_opt, ",")) != NULL) {
445 if (!strncmp(options, "font:", 5))
446 strcpy(fontname, options + 5);
447
448 if (!strncmp(options, "scrollback:", 11)) {
449 options += 11;
450 if (*options) {
451 fbcon_softback_size = simple_strtoul(options, &options, 0);
452 if (*options == 'k' || *options == 'K') {
453 fbcon_softback_size *= 1024;
454 options++;
455 }
456 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800457 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 options++;
459 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800460 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 if (!strncmp(options, "map:", 4)) {
464 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700465 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
467 if (!options[j])
468 j = 0;
469 con2fb_map_boot[i] =
470 (options[j++]-'0') % FB_MAX;
471 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700472
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700473 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700474 }
475
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800476 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478
479 if (!strncmp(options, "vc:", 3)) {
480 options += 3;
481 if (*options)
482 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
483 if (first_fb_vc < 0)
484 first_fb_vc = 0;
485 if (*options++ == '-')
486 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
487 fbcon_is_default = 0;
488 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800489
490 if (!strncmp(options, "rotate:", 7)) {
491 options += 7;
492 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800493 initial_rotation = simple_strtoul(options, &options, 0);
494 if (initial_rotation > 3)
495 initial_rotation = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800498 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499}
500
501__setup("fbcon=", fb_console_setup);
502#endif
503
504static int search_fb_in_map(int idx)
505{
506 int i, retval = 0;
507
Antonino A. Daplase614b182006-06-26 00:27:09 -0700508 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (con2fb_map[i] == idx)
510 retval = 1;
511 }
512 return retval;
513}
514
515static int search_for_mapped_con(void)
516{
517 int i, retval = 0;
518
Antonino A. Daplase614b182006-06-26 00:27:09 -0700519 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 if (con2fb_map[i] != -1)
521 retval = 1;
522 }
523 return retval;
524}
525
526static int fbcon_takeover(int show_logo)
527{
528 int err, i;
529
530 if (!num_registered_fb)
531 return -ENODEV;
532
533 if (!show_logo)
534 logo_shown = FBCON_LOGO_DONTSHOW;
535
536 for (i = first_fb_vc; i <= last_fb_vc; i++)
537 con2fb_map[i] = info_idx;
538
539 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
540 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (err) {
543 for (i = first_fb_vc; i <= last_fb_vc; i++) {
544 con2fb_map[i] = -1;
545 }
546 info_idx = -1;
547 }
548
549 return err;
550}
551
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700552#ifdef MODULE
553static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
554 int cols, int rows, int new_cols, int new_rows)
555{
556 logo_shown = FBCON_LOGO_DONTSHOW;
557}
558#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
560 int cols, int rows, int new_cols, int new_rows)
561{
562 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800563 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 int cnt, erase = vc->vc_video_erase_char, step;
565 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700566 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700568 if (info->flags & FBINFO_MODULE) {
569 logo_shown = FBCON_LOGO_DONTSHOW;
570 return;
571 }
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 /*
574 * remove underline attribute from erase character
575 * if black and white framebuffer.
576 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700577 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800579 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700580 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 q = (unsigned short *) (vc->vc_origin +
582 vc->vc_size_row * rows);
583 step = logo_lines * cols;
584 for (r = q - logo_lines * cols; r < q; r++)
585 if (scr_readw(r) != vc->vc_video_erase_char)
586 break;
587 if (r != q && new_rows >= rows + logo_lines) {
588 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
589 if (save) {
590 int i = cols < new_cols ? cols : new_cols;
591 scr_memsetw(save, erase, logo_lines * new_cols * 2);
592 r = q - step;
593 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
594 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
595 r = q;
596 }
597 }
598 if (r == q) {
599 /* We can scroll screen down */
600 r = q - step - cols;
601 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
602 scr_memcpyw(r + step, r, vc->vc_size_row);
603 r -= cols;
604 }
605 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700606 int lines;
607 if (vc->vc_y + logo_lines >= rows)
608 lines = rows - vc->vc_y - 1;
609 else
610 lines = logo_lines;
611 vc->vc_y += lines;
612 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614 }
615 scr_memsetw((unsigned short *) vc->vc_origin,
616 erase,
617 vc->vc_size_row * logo_lines);
618
619 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
620 fbcon_clear_margins(vc, 0);
621 update_screen(vc);
622 }
623
624 if (save) {
625 q = (unsigned short *) (vc->vc_origin +
626 vc->vc_size_row *
627 rows);
628 scr_memcpyw(q, save, logo_lines * new_cols * 2);
629 vc->vc_y += logo_lines;
630 vc->vc_pos += logo_lines * vc->vc_size_row;
631 kfree(save);
632 }
633
634 if (logo_lines > vc->vc_bottom) {
635 logo_shown = FBCON_LOGO_CANSHOW;
636 printk(KERN_INFO
637 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
638 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
639 logo_shown = FBCON_LOGO_DRAW;
640 vc->vc_top = logo_lines;
641 }
642}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700643#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800646static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
648 struct fbcon_ops *ops = info->fbcon_par;
649
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800650 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800653 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800654 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800655 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700659
660static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
661{
662 int err = 0;
663
664 if (info->flags & FBINFO_MISC_TILEBLITTING &&
665 info->tileops->fb_get_tilemax(info) < charcount)
666 err = 1;
667
668 return err;
669}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800671static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
673 struct fbcon_ops *ops = info->fbcon_par;
674
675 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800676 ops->p = &fb_display[vc->vc_num];
677 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 fbcon_set_bitops(ops);
679}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700680
681static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
682{
683 return 0;
684}
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#endif /* CONFIG_MISC_TILEBLITTING */
687
688
689static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
690 int unit, int oldidx)
691{
692 struct fbcon_ops *ops = NULL;
693 int err = 0;
694
695 if (!try_module_get(info->fbops->owner))
696 err = -ENODEV;
697
698 if (!err && info->fbops->fb_open &&
699 info->fbops->fb_open(info, 0))
700 err = -ENODEV;
701
702 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800703 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (!ops)
705 err = -ENOMEM;
706 }
707
708 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700710
711 if (vc)
712 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714
715 if (err) {
716 con2fb_map[unit] = oldidx;
717 module_put(info->fbops->owner);
718 }
719
720 return err;
721}
722
723static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
724 struct fb_info *newinfo, int unit,
725 int oldidx, int found)
726{
727 struct fbcon_ops *ops = oldinfo->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700728 int err = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 if (oldinfo->fbops->fb_release &&
731 oldinfo->fbops->fb_release(oldinfo, 0)) {
732 con2fb_map[unit] = oldidx;
733 if (!found && newinfo->fbops->fb_release)
734 newinfo->fbops->fb_release(newinfo, 0);
735 if (!found)
736 module_put(newinfo->fbops->owner);
737 err = -ENODEV;
738 }
739
740 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700741 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 kfree(ops->cursor_state.mask);
743 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800744 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 kfree(oldinfo->fbcon_par);
746 oldinfo->fbcon_par = NULL;
747 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800748 /*
749 If oldinfo and newinfo are driving the same hardware,
750 the fb_release() method of oldinfo may attempt to
751 restore the hardware state. This will leave the
752 newinfo in an undefined state. Thus, a call to
753 fb_set_par() may be needed for the newinfo.
754 */
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700755 if (newinfo->fbops->fb_set_par) {
756 ret = newinfo->fbops->fb_set_par(newinfo);
757
758 if (ret)
759 printk(KERN_ERR "con2fb_release_oldinfo: "
760 "detected unhandled fb_set_par error, "
761 "error code %d\n", ret);
762 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764
765 return err;
766}
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
769 int unit, int show_logo)
770{
771 struct fbcon_ops *ops = info->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700772 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 ops->currcon = fg_console;
775
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700776 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
777 ret = info->fbops->fb_set_par(info);
778
779 if (ret)
780 printk(KERN_ERR "con2fb_init_display: detected "
781 "unhandled fb_set_par error, "
782 "error code %d\n", ret);
783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 ops->flags |= FBCON_FLAGS_INIT;
786 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700787 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 if (show_logo) {
790 struct vc_data *fg_vc = vc_cons[fg_console].d;
791 struct fb_info *fg_info =
792 registered_fb[con2fb_map[fg_console]];
793
794 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
795 fg_vc->vc_rows, fg_vc->vc_cols,
796 fg_vc->vc_rows);
797 }
798
799 update_screen(vc_cons[fg_console].d);
800}
801
802/**
803 * set_con2fb_map - map console to frame buffer device
804 * @unit: virtual console number to map
805 * @newidx: frame buffer index to map virtual console to
806 * @user: user request
807 *
808 * Maps a virtual console @unit to a frame buffer device
809 * @newidx.
810 */
811static int set_con2fb_map(int unit, int newidx, int user)
812{
813 struct vc_data *vc = vc_cons[unit].d;
814 int oldidx = con2fb_map[unit];
815 struct fb_info *info = registered_fb[newidx];
816 struct fb_info *oldinfo = NULL;
817 int found, err = 0;
818
819 if (oldidx == newidx)
820 return 0;
821
Antonino A. Daplase614b182006-06-26 00:27:09 -0700822 if (!info || fbcon_has_exited)
823 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 if (!err && !search_for_mapped_con()) {
826 info_idx = newidx;
827 return fbcon_takeover(0);
828 }
829
830 if (oldidx != -1)
831 oldinfo = registered_fb[oldidx];
832
833 found = search_fb_in_map(newidx);
834
835 acquire_console_sem();
836 con2fb_map[unit] = newidx;
837 if (!err && !found)
838 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
839
840
841 /*
842 * If old fb is not mapped to any of the consoles,
843 * fbcon should release it.
844 */
845 if (!err && oldinfo && !search_fb_in_map(oldidx))
846 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
847 found);
848
849 if (!err) {
850 int show_logo = (fg_console == 0 && !user &&
851 logo_shown != FBCON_LOGO_DONTSHOW);
852
853 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700854 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 con2fb_map_boot[unit] = newidx;
856 con2fb_init_display(vc, info, unit, show_logo);
857 }
858
Antonino A. Daplase614b182006-06-26 00:27:09 -0700859 if (!search_fb_in_map(info_idx))
860 info_idx = newidx;
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 release_console_sem();
863 return err;
864}
865
866/*
867 * Low Level Operations
868 */
869/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
870static int var_to_display(struct display *disp,
871 struct fb_var_screeninfo *var,
872 struct fb_info *info)
873{
874 disp->xres_virtual = var->xres_virtual;
875 disp->yres_virtual = var->yres_virtual;
876 disp->bits_per_pixel = var->bits_per_pixel;
877 disp->grayscale = var->grayscale;
878 disp->nonstd = var->nonstd;
879 disp->accel_flags = var->accel_flags;
880 disp->height = var->height;
881 disp->width = var->width;
882 disp->red = var->red;
883 disp->green = var->green;
884 disp->blue = var->blue;
885 disp->transp = var->transp;
886 disp->rotate = var->rotate;
887 disp->mode = fb_match_mode(var, &info->modelist);
888 if (disp->mode == NULL)
889 /* This should not happen */
890 return -EINVAL;
891 return 0;
892}
893
894static void display_to_var(struct fb_var_screeninfo *var,
895 struct display *disp)
896{
897 fb_videomode_to_var(var, disp->mode);
898 var->xres_virtual = disp->xres_virtual;
899 var->yres_virtual = disp->yres_virtual;
900 var->bits_per_pixel = disp->bits_per_pixel;
901 var->grayscale = disp->grayscale;
902 var->nonstd = disp->nonstd;
903 var->accel_flags = disp->accel_flags;
904 var->height = disp->height;
905 var->width = disp->width;
906 var->red = disp->red;
907 var->green = disp->green;
908 var->blue = disp->blue;
909 var->transp = disp->transp;
910 var->rotate = disp->rotate;
911}
912
913static const char *fbcon_startup(void)
914{
915 const char *display_desc = "frame buffer device";
916 struct display *p = &fb_display[fg_console];
917 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700918 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 struct module *owner;
920 struct fb_info *info = NULL;
921 struct fbcon_ops *ops;
922 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 /*
925 * If num_registered_fb is zero, this is a call for the dummy part.
926 * The frame buffer devices weren't initialized yet.
927 */
928 if (!num_registered_fb || info_idx == -1)
929 return display_desc;
930 /*
931 * Instead of blindly using registered_fb[0], we use info_idx, set by
932 * fb_console_init();
933 */
934 info = registered_fb[info_idx];
935 if (!info)
936 return NULL;
937
938 owner = info->fbops->owner;
939 if (!try_module_get(owner))
940 return NULL;
941 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
942 module_put(owner);
943 return NULL;
944 }
945
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800946 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (!ops) {
948 module_put(owner);
949 return NULL;
950 }
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 ops->currcon = -1;
953 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800954 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800956 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800957 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959 if (info->fix.type != FB_TYPE_TEXT) {
960 if (fbcon_softback_size) {
961 if (!softback_buf) {
962 softback_buf =
963 (unsigned long)
964 kmalloc(fbcon_softback_size,
965 GFP_KERNEL);
966 if (!softback_buf) {
967 fbcon_softback_size = 0;
968 softback_top = 0;
969 }
970 }
971 } else {
972 if (softback_buf) {
973 kfree((void *) softback_buf);
974 softback_buf = 0;
975 softback_top = 0;
976 }
977 }
978 if (softback_buf)
979 softback_in = softback_top = softback_curr =
980 softback_buf;
981 softback_lines = 0;
982 }
983
984 /* Setup default font */
985 if (!p->fontdata) {
986 if (!fontname[0] || !(font = find_font(fontname)))
987 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700988 info->var.yres,
989 info->pixmap.blit_x,
990 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 vc->vc_font.width = font->width;
992 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700993 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
995 }
996
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800997 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
998 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
999 cols /= vc->vc_font.width;
1000 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 vc_resize(vc, cols, rows);
1002
1003 DPRINTK("mode: %s\n", info->fix.id);
1004 DPRINTK("visual: %d\n", info->fix.visual);
1005 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1006 info->var.yres,
1007 info->var.bits_per_pixel);
1008
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001009 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001010 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 return display_desc;
1012}
1013
1014static void fbcon_init(struct vc_data *vc, int init)
1015{
1016 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1017 struct fbcon_ops *ops;
1018 struct vc_data **default_mode = vc->vc_display_fg;
1019 struct vc_data *svc = *default_mode;
1020 struct display *t, *p = &fb_display[vc->vc_num];
1021 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001022 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
1024 if (info_idx == -1 || info == NULL)
1025 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001026
1027 cap = info->flags;
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1030 (info->fix.type == FB_TYPE_TEXT))
1031 logo = 0;
1032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 if (var_to_display(p, &info->var, info))
1034 return;
1035
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001036 if (!info->fbcon_par)
1037 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /* If we are not the first console on this
1040 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001041 t = &fb_display[fg_console];
1042 if (!p->fontdata) {
1043 if (t->fontdata) {
1044 struct vc_data *fvc = vc_cons[fg_console].d;
1045
1046 vc->vc_font.data = (void *)(p->fontdata =
1047 fvc->vc_font.data);
1048 vc->vc_font.width = fvc->vc_font.width;
1049 vc->vc_font.height = fvc->vc_font.height;
1050 p->userfont = t->userfont;
1051
1052 if (p->userfont)
1053 REFCOUNT(p->fontdata)++;
1054 } else {
1055 const struct font_desc *font = NULL;
1056
1057 if (!fontname[0] || !(font = find_font(fontname)))
1058 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001059 info->var.yres,
1060 info->pixmap.blit_x,
1061 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001062 vc->vc_font.width = font->width;
1063 vc->vc_font.height = font->height;
1064 vc->vc_font.data = (void *)(p->fontdata = font->data);
1065 vc->vc_font.charcount = 256; /* FIXME Need to
1066 support more fonts */
1067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (p->userfont)
1071 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001072
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001073 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1075 if (charcnt == 256) {
1076 vc->vc_hi_font_mask = 0;
1077 } else {
1078 vc->vc_hi_font_mask = 0x100;
1079 if (vc->vc_can_do_color)
1080 vc->vc_complement_mask <<= 1;
1081 }
1082
1083 if (!*svc->vc_uni_pagedir_loc)
1084 con_set_default_unimap(svc);
1085 if (!*vc->vc_uni_pagedir_loc)
1086 con_copy_unimap(vc, svc);
1087
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001088 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001089 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001090 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 cols = vc->vc_cols;
1093 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001094 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1095 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1096 new_cols /= vc->vc_font.width;
1097 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 /*
1100 * We must always set the mode. The mode of the previous console
1101 * driver could be in the same resolution but we are using different
1102 * hardware so we have to initialize the hardware.
1103 *
1104 * We need to do it in fbcon_init() to prevent screen corruption.
1105 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001106 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001108 !(ops->flags & FBCON_FLAGS_INIT)) {
1109 ret = info->fbops->fb_set_par(info);
1110
1111 if (ret)
1112 printk(KERN_ERR "fbcon_init: detected "
1113 "unhandled fb_set_par error, "
1114 "error code %d\n", ret);
1115 }
1116
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 ops->flags |= FBCON_FLAGS_INIT;
1118 }
1119
1120 ops->graphics = 0;
1121
1122 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1123 !(cap & FBINFO_HWACCEL_DISABLED))
1124 p->scrollmode = SCROLL_MOVE;
1125 else /* default to something safe */
1126 p->scrollmode = SCROLL_REDRAW;
1127
1128 /*
1129 * ++guenther: console.c:vc_allocate() relies on initializing
1130 * vc_{cols,rows}, but we must not set those if we are only
1131 * resizing the console.
1132 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001133 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 vc->vc_cols = new_cols;
1135 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001136 } else
1137 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
1139 if (logo)
1140 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1141
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001142 if (vc == svc && softback_buf)
1143 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001144
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001145 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001146 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001147 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001148 }
1149
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001150 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151}
1152
Antonino A. Daplase614b182006-06-26 00:27:09 -07001153static void fbcon_free_font(struct display *p)
1154{
1155 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1156 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1157 p->fontdata = NULL;
1158 p->userfont = 0;
1159}
1160
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161static void fbcon_deinit(struct vc_data *vc)
1162{
1163 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001164 struct fb_info *info;
1165 struct fbcon_ops *ops;
1166 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001169 idx = con2fb_map[vc->vc_num];
1170
1171 if (idx == -1)
1172 goto finished;
1173
1174 info = registered_fb[idx];
1175
1176 if (!info)
1177 goto finished;
1178
1179 ops = info->fbcon_par;
1180
1181 if (!ops)
1182 goto finished;
1183
1184 if (CON_IS_VISIBLE(vc))
1185 fbcon_del_cursor_timer(info);
1186
1187 ops->flags &= ~FBCON_FLAGS_INIT;
1188finished:
1189
1190 if (!con_is_bound(&fb_con))
1191 fbcon_exit();
1192
1193 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194}
1195
1196/* ====================================================================== */
1197
1198/* fbcon_XXX routines - interface used by the world
1199 *
1200 * This system is now divided into two levels because of complications
1201 * caused by hardware scrolling. Top level functions:
1202 *
1203 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1204 *
1205 * handles y values in range [0, scr_height-1] that correspond to real
1206 * screen positions. y_wrap shift means that first line of bitmap may be
1207 * anywhere on this display. These functions convert lineoffsets to
1208 * bitmap offsets and deal with the wrap-around case by splitting blits.
1209 *
1210 * fbcon_bmove_physical_8() -- These functions fast implementations
1211 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1212 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1213 *
1214 * WARNING:
1215 *
1216 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1217 * Implies should only really hardware scroll in rows. Only reason for
1218 * restriction is simplicity & efficiency at the moment.
1219 */
1220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1222 int width)
1223{
1224 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1225 struct fbcon_ops *ops = info->fbcon_par;
1226
1227 struct display *p = &fb_display[vc->vc_num];
1228 u_int y_break;
1229
1230 if (fbcon_is_inactive(vc, info))
1231 return;
1232
1233 if (!height || !width)
1234 return;
1235
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001236 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1237 vc->vc_top = 0;
1238
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 /* Split blits that cross physical y_wrap boundary */
1240
1241 y_break = p->vrows - p->yscroll;
1242 if (sy < y_break && sy + height - 1 >= y_break) {
1243 u_int b = y_break - sy;
1244 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1245 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1246 width);
1247 } else
1248 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1249}
1250
1251static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1252 int count, int ypos, int xpos)
1253{
1254 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1255 struct display *p = &fb_display[vc->vc_num];
1256 struct fbcon_ops *ops = info->fbcon_par;
1257
1258 if (!fbcon_is_inactive(vc, info))
1259 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1260 get_color(vc, info, scr_readw(s), 1),
1261 get_color(vc, info, scr_readw(s), 0));
1262}
1263
1264static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1265{
1266 unsigned short chr;
1267
1268 scr_writew(c, &chr);
1269 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1270}
1271
1272static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1273{
1274 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1275 struct fbcon_ops *ops = info->fbcon_par;
1276
1277 if (!fbcon_is_inactive(vc, info))
1278 ops->clear_margins(vc, info, bottom_only);
1279}
1280
1281static void fbcon_cursor(struct vc_data *vc, int mode)
1282{
1283 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1284 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 int y;
1286 int c = scr_readw((u16 *) vc->vc_pos);
1287
Michal Januszewskid1e23062007-05-08 00:38:07 -07001288 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 return;
1290
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001291 if (vc->vc_cursor_type & 0x10)
1292 fbcon_del_cursor_timer(info);
1293 else
1294 fbcon_add_cursor_timer(info);
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1297 if (mode & CM_SOFTBACK) {
1298 mode &= ~CM_SOFTBACK;
1299 y = softback_lines;
1300 } else {
1301 if (softback_lines)
1302 fbcon_set_origin(vc);
1303 y = 0;
1304 }
1305
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001306 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 get_color(vc, info, c, 0));
1308 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1309}
1310
1311static int scrollback_phys_max = 0;
1312static int scrollback_max = 0;
1313static int scrollback_current = 0;
1314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001316 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001318 struct display *p, *t;
1319 struct vc_data **default_mode, *vc;
1320 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001321 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 int rows, cols, charcnt = 256;
1323
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001324 p = &fb_display[unit];
1325
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if (var_to_display(p, var, info))
1327 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001328
1329 vc = vc_cons[unit].d;
1330
1331 if (!vc)
1332 return;
1333
1334 default_mode = vc->vc_display_fg;
1335 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001339 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 vc->vc_font.width = (*default_mode)->vc_font.width;
1341 vc->vc_font.height = (*default_mode)->vc_font.height;
1342 p->userfont = t->userfont;
1343 if (p->userfont)
1344 REFCOUNT(p->fontdata)++;
1345 }
1346 if (p->userfont)
1347 charcnt = FNTCHARCNT(p->fontdata);
1348
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001349 var->activate = FB_ACTIVATE_NOW;
1350 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001351 var->yoffset = info->var.yoffset;
1352 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001353 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001354 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001355 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1357 if (charcnt == 256) {
1358 vc->vc_hi_font_mask = 0;
1359 } else {
1360 vc->vc_hi_font_mask = 0x100;
1361 if (vc->vc_can_do_color)
1362 vc->vc_complement_mask <<= 1;
1363 }
1364
1365 if (!*svc->vc_uni_pagedir_loc)
1366 con_set_default_unimap(svc);
1367 if (!*vc->vc_uni_pagedir_loc)
1368 con_copy_unimap(vc, svc);
1369
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001370 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1371 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1372 cols /= vc->vc_font.width;
1373 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001375
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 if (CON_IS_VISIBLE(vc)) {
1377 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001378 if (softback_buf)
1379 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 }
1381}
1382
1383static __inline__ void ywrap_up(struct vc_data *vc, int count)
1384{
1385 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001386 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 struct display *p = &fb_display[vc->vc_num];
1388
1389 p->yscroll += count;
1390 if (p->yscroll >= p->vrows) /* Deal with wrap */
1391 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001392 ops->var.xoffset = 0;
1393 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1394 ops->var.vmode |= FB_VMODE_YWRAP;
1395 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 scrollback_max += count;
1397 if (scrollback_max > scrollback_phys_max)
1398 scrollback_max = scrollback_phys_max;
1399 scrollback_current = 0;
1400}
1401
1402static __inline__ void ywrap_down(struct vc_data *vc, int count)
1403{
1404 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001405 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 struct display *p = &fb_display[vc->vc_num];
1407
1408 p->yscroll -= count;
1409 if (p->yscroll < 0) /* Deal with wrap */
1410 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001411 ops->var.xoffset = 0;
1412 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1413 ops->var.vmode |= FB_VMODE_YWRAP;
1414 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 scrollback_max -= count;
1416 if (scrollback_max < 0)
1417 scrollback_max = 0;
1418 scrollback_current = 0;
1419}
1420
1421static __inline__ void ypan_up(struct vc_data *vc, int count)
1422{
1423 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1424 struct display *p = &fb_display[vc->vc_num];
1425 struct fbcon_ops *ops = info->fbcon_par;
1426
1427 p->yscroll += count;
1428 if (p->yscroll > p->vrows - vc->vc_rows) {
1429 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1430 0, 0, 0, vc->vc_rows, vc->vc_cols);
1431 p->yscroll -= p->vrows - vc->vc_rows;
1432 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001433
1434 ops->var.xoffset = 0;
1435 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1436 ops->var.vmode &= ~FB_VMODE_YWRAP;
1437 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 fbcon_clear_margins(vc, 1);
1439 scrollback_max += count;
1440 if (scrollback_max > scrollback_phys_max)
1441 scrollback_max = scrollback_phys_max;
1442 scrollback_current = 0;
1443}
1444
1445static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1446{
1447 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001448 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 if (p->yscroll > p->vrows - vc->vc_rows) {
1454 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001456 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001457
1458 ops->var.xoffset = 0;
1459 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1460 ops->var.vmode &= ~FB_VMODE_YWRAP;
1461 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 fbcon_clear_margins(vc, 1);
1463 scrollback_max += count;
1464 if (scrollback_max > scrollback_phys_max)
1465 scrollback_max = scrollback_phys_max;
1466 scrollback_current = 0;
1467}
1468
1469static __inline__ void ypan_down(struct vc_data *vc, int count)
1470{
1471 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1472 struct display *p = &fb_display[vc->vc_num];
1473 struct fbcon_ops *ops = info->fbcon_par;
1474
1475 p->yscroll -= count;
1476 if (p->yscroll < 0) {
1477 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1478 0, vc->vc_rows, vc->vc_cols);
1479 p->yscroll += p->vrows - vc->vc_rows;
1480 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001481
1482 ops->var.xoffset = 0;
1483 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1484 ops->var.vmode &= ~FB_VMODE_YWRAP;
1485 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 fbcon_clear_margins(vc, 1);
1487 scrollback_max -= count;
1488 if (scrollback_max < 0)
1489 scrollback_max = 0;
1490 scrollback_current = 0;
1491}
1492
1493static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1494{
1495 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001496 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001500
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 if (p->yscroll < 0) {
1502 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001504 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001505
1506 ops->var.xoffset = 0;
1507 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1508 ops->var.vmode &= ~FB_VMODE_YWRAP;
1509 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 fbcon_clear_margins(vc, 1);
1511 scrollback_max -= count;
1512 if (scrollback_max < 0)
1513 scrollback_max = 0;
1514 scrollback_current = 0;
1515}
1516
1517static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1518 long delta)
1519{
1520 int count = vc->vc_rows;
1521 unsigned short *d, *s;
1522 unsigned long n;
1523 int line = 0;
1524
1525 d = (u16 *) softback_curr;
1526 if (d == (u16 *) softback_in)
1527 d = (u16 *) vc->vc_origin;
1528 n = softback_curr + delta * vc->vc_size_row;
1529 softback_lines -= delta;
1530 if (delta < 0) {
1531 if (softback_curr < softback_top && n < softback_buf) {
1532 n += softback_end - softback_buf;
1533 if (n < softback_top) {
1534 softback_lines -=
1535 (softback_top - n) / vc->vc_size_row;
1536 n = softback_top;
1537 }
1538 } else if (softback_curr >= softback_top
1539 && n < softback_top) {
1540 softback_lines -=
1541 (softback_top - n) / vc->vc_size_row;
1542 n = softback_top;
1543 }
1544 } else {
1545 if (softback_curr > softback_in && n >= softback_end) {
1546 n += softback_buf - softback_end;
1547 if (n > softback_in) {
1548 n = softback_in;
1549 softback_lines = 0;
1550 }
1551 } else if (softback_curr <= softback_in && n > softback_in) {
1552 n = softback_in;
1553 softback_lines = 0;
1554 }
1555 }
1556 if (n == softback_curr)
1557 return;
1558 softback_curr = n;
1559 s = (u16 *) softback_curr;
1560 if (s == (u16 *) softback_in)
1561 s = (u16 *) vc->vc_origin;
1562 while (count--) {
1563 unsigned short *start;
1564 unsigned short *le;
1565 unsigned short c;
1566 int x = 0;
1567 unsigned short attr = 1;
1568
1569 start = s;
1570 le = advance_row(s, 1);
1571 do {
1572 c = scr_readw(s);
1573 if (attr != (c & 0xff00)) {
1574 attr = c & 0xff00;
1575 if (s > start) {
1576 fbcon_putcs(vc, start, s - start,
1577 line, x);
1578 x += s - start;
1579 start = s;
1580 }
1581 }
1582 if (c == scr_readw(d)) {
1583 if (s > start) {
1584 fbcon_putcs(vc, start, s - start,
1585 line, x);
1586 x += s - start + 1;
1587 start = s + 1;
1588 } else {
1589 x++;
1590 start++;
1591 }
1592 }
1593 s++;
1594 d++;
1595 } while (s < le);
1596 if (s > start)
1597 fbcon_putcs(vc, start, s - start, line, x);
1598 line++;
1599 if (d == (u16 *) softback_end)
1600 d = (u16 *) softback_buf;
1601 if (d == (u16 *) softback_in)
1602 d = (u16 *) vc->vc_origin;
1603 if (s == (u16 *) softback_end)
1604 s = (u16 *) softback_buf;
1605 if (s == (u16 *) softback_in)
1606 s = (u16 *) vc->vc_origin;
1607 }
1608}
1609
1610static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1611 int line, int count, int dy)
1612{
1613 unsigned short *s = (unsigned short *)
1614 (vc->vc_origin + vc->vc_size_row * line);
1615
1616 while (count--) {
1617 unsigned short *start = s;
1618 unsigned short *le = advance_row(s, 1);
1619 unsigned short c;
1620 int x = 0;
1621 unsigned short attr = 1;
1622
1623 do {
1624 c = scr_readw(s);
1625 if (attr != (c & 0xff00)) {
1626 attr = c & 0xff00;
1627 if (s > start) {
1628 fbcon_putcs(vc, start, s - start,
1629 dy, x);
1630 x += s - start;
1631 start = s;
1632 }
1633 }
1634 console_conditional_schedule();
1635 s++;
1636 } while (s < le);
1637 if (s > start)
1638 fbcon_putcs(vc, start, s - start, dy, x);
1639 console_conditional_schedule();
1640 dy++;
1641 }
1642}
1643
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001644static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1645 struct display *p, int line, int count, int ycount)
1646{
1647 int offset = ycount * vc->vc_cols;
1648 unsigned short *d = (unsigned short *)
1649 (vc->vc_origin + vc->vc_size_row * line);
1650 unsigned short *s = d + offset;
1651 struct fbcon_ops *ops = info->fbcon_par;
1652
1653 while (count--) {
1654 unsigned short *start = s;
1655 unsigned short *le = advance_row(s, 1);
1656 unsigned short c;
1657 int x = 0;
1658
1659 do {
1660 c = scr_readw(s);
1661
1662 if (c == scr_readw(d)) {
1663 if (s > start) {
1664 ops->bmove(vc, info, line + ycount, x,
1665 line, x, 1, s-start);
1666 x += s - start + 1;
1667 start = s + 1;
1668 } else {
1669 x++;
1670 start++;
1671 }
1672 }
1673
1674 scr_writew(c, d);
1675 console_conditional_schedule();
1676 s++;
1677 d++;
1678 } while (s < le);
1679 if (s > start)
1680 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1681 s-start);
1682 console_conditional_schedule();
1683 if (ycount > 0)
1684 line++;
1685 else {
1686 line--;
1687 /* NOTE: We subtract two lines from these pointers */
1688 s -= vc->vc_size_row;
1689 d -= vc->vc_size_row;
1690 }
1691 }
1692}
1693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694static void fbcon_redraw(struct vc_data *vc, struct display *p,
1695 int line, int count, int offset)
1696{
1697 unsigned short *d = (unsigned short *)
1698 (vc->vc_origin + vc->vc_size_row * line);
1699 unsigned short *s = d + offset;
1700
1701 while (count--) {
1702 unsigned short *start = s;
1703 unsigned short *le = advance_row(s, 1);
1704 unsigned short c;
1705 int x = 0;
1706 unsigned short attr = 1;
1707
1708 do {
1709 c = scr_readw(s);
1710 if (attr != (c & 0xff00)) {
1711 attr = c & 0xff00;
1712 if (s > start) {
1713 fbcon_putcs(vc, start, s - start,
1714 line, x);
1715 x += s - start;
1716 start = s;
1717 }
1718 }
1719 if (c == scr_readw(d)) {
1720 if (s > start) {
1721 fbcon_putcs(vc, start, s - start,
1722 line, x);
1723 x += s - start + 1;
1724 start = s + 1;
1725 } else {
1726 x++;
1727 start++;
1728 }
1729 }
1730 scr_writew(c, d);
1731 console_conditional_schedule();
1732 s++;
1733 d++;
1734 } while (s < le);
1735 if (s > start)
1736 fbcon_putcs(vc, start, s - start, line, x);
1737 console_conditional_schedule();
1738 if (offset > 0)
1739 line++;
1740 else {
1741 line--;
1742 /* NOTE: We subtract two lines from these pointers */
1743 s -= vc->vc_size_row;
1744 d -= vc->vc_size_row;
1745 }
1746 }
1747}
1748
1749static inline void fbcon_softback_note(struct vc_data *vc, int t,
1750 int count)
1751{
1752 unsigned short *p;
1753
1754 if (vc->vc_num != fg_console)
1755 return;
1756 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1757
1758 while (count) {
1759 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1760 count--;
1761 p = advance_row(p, 1);
1762 softback_in += vc->vc_size_row;
1763 if (softback_in == softback_end)
1764 softback_in = softback_buf;
1765 if (softback_in == softback_top) {
1766 softback_top += vc->vc_size_row;
1767 if (softback_top == softback_end)
1768 softback_top = softback_buf;
1769 }
1770 }
1771 softback_curr = softback_in;
1772}
1773
1774static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1775 int count)
1776{
1777 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1778 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1780
1781 if (fbcon_is_inactive(vc, info))
1782 return -EINVAL;
1783
1784 fbcon_cursor(vc, CM_ERASE);
1785
1786 /*
1787 * ++Geert: Only use ywrap/ypan if the console is in text mode
1788 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1789 * whole screen (prevents flicker).
1790 */
1791
1792 switch (dir) {
1793 case SM_UP:
1794 if (count > vc->vc_rows) /* Maximum realistic size */
1795 count = vc->vc_rows;
1796 if (softback_top)
1797 fbcon_softback_note(vc, t, count);
1798 if (logo_shown >= 0)
1799 goto redraw_up;
1800 switch (p->scrollmode) {
1801 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001802 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1803 count);
1804 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1805 scr_memsetw((unsigned short *) (vc->vc_origin +
1806 vc->vc_size_row *
1807 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001808 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001809 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001810 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 break;
1812
1813 case SCROLL_WRAP_MOVE:
1814 if (b - t - count > 3 * vc->vc_rows >> 2) {
1815 if (t > 0)
1816 fbcon_bmove(vc, 0, 0, count, 0, t,
1817 vc->vc_cols);
1818 ywrap_up(vc, count);
1819 if (vc->vc_rows - b > 0)
1820 fbcon_bmove(vc, b - count, 0, b, 0,
1821 vc->vc_rows - b,
1822 vc->vc_cols);
1823 } else if (info->flags & FBINFO_READS_FAST)
1824 fbcon_bmove(vc, t + count, 0, t, 0,
1825 b - t - count, vc->vc_cols);
1826 else
1827 goto redraw_up;
1828 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1829 break;
1830
1831 case SCROLL_PAN_REDRAW:
1832 if ((p->yscroll + count <=
1833 2 * (p->vrows - vc->vc_rows))
1834 && ((!scroll_partial && (b - t == vc->vc_rows))
1835 || (scroll_partial
1836 && (b - t - count >
1837 3 * vc->vc_rows >> 2)))) {
1838 if (t > 0)
1839 fbcon_redraw_move(vc, p, 0, t, count);
1840 ypan_up_redraw(vc, t, count);
1841 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001842 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 vc->vc_rows - b, b);
1844 } else
1845 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1846 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1847 break;
1848
1849 case SCROLL_PAN_MOVE:
1850 if ((p->yscroll + count <=
1851 2 * (p->vrows - vc->vc_rows))
1852 && ((!scroll_partial && (b - t == vc->vc_rows))
1853 || (scroll_partial
1854 && (b - t - count >
1855 3 * vc->vc_rows >> 2)))) {
1856 if (t > 0)
1857 fbcon_bmove(vc, 0, 0, count, 0, t,
1858 vc->vc_cols);
1859 ypan_up(vc, count);
1860 if (vc->vc_rows - b > 0)
1861 fbcon_bmove(vc, b - count, 0, b, 0,
1862 vc->vc_rows - b,
1863 vc->vc_cols);
1864 } else if (info->flags & FBINFO_READS_FAST)
1865 fbcon_bmove(vc, t + count, 0, t, 0,
1866 b - t - count, vc->vc_cols);
1867 else
1868 goto redraw_up;
1869 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1870 break;
1871
1872 case SCROLL_REDRAW:
1873 redraw_up:
1874 fbcon_redraw(vc, p, t, b - t - count,
1875 count * vc->vc_cols);
1876 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1877 scr_memsetw((unsigned short *) (vc->vc_origin +
1878 vc->vc_size_row *
1879 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001880 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001882 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 }
1884 break;
1885
1886 case SM_DOWN:
1887 if (count > vc->vc_rows) /* Maximum realistic size */
1888 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001889 if (logo_shown >= 0)
1890 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 switch (p->scrollmode) {
1892 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001893 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1894 -count);
1895 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1896 scr_memsetw((unsigned short *) (vc->vc_origin +
1897 vc->vc_size_row *
1898 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001899 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001900 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001901 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 break;
1903
1904 case SCROLL_WRAP_MOVE:
1905 if (b - t - count > 3 * vc->vc_rows >> 2) {
1906 if (vc->vc_rows - b > 0)
1907 fbcon_bmove(vc, b, 0, b - count, 0,
1908 vc->vc_rows - b,
1909 vc->vc_cols);
1910 ywrap_down(vc, count);
1911 if (t > 0)
1912 fbcon_bmove(vc, count, 0, 0, 0, t,
1913 vc->vc_cols);
1914 } else if (info->flags & FBINFO_READS_FAST)
1915 fbcon_bmove(vc, t, 0, t + count, 0,
1916 b - t - count, vc->vc_cols);
1917 else
1918 goto redraw_down;
1919 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1920 break;
1921
1922 case SCROLL_PAN_MOVE:
1923 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1924 && ((!scroll_partial && (b - t == vc->vc_rows))
1925 || (scroll_partial
1926 && (b - t - count >
1927 3 * vc->vc_rows >> 2)))) {
1928 if (vc->vc_rows - b > 0)
1929 fbcon_bmove(vc, b, 0, b - count, 0,
1930 vc->vc_rows - b,
1931 vc->vc_cols);
1932 ypan_down(vc, count);
1933 if (t > 0)
1934 fbcon_bmove(vc, count, 0, 0, 0, t,
1935 vc->vc_cols);
1936 } else if (info->flags & FBINFO_READS_FAST)
1937 fbcon_bmove(vc, t, 0, t + count, 0,
1938 b - t - count, vc->vc_cols);
1939 else
1940 goto redraw_down;
1941 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1942 break;
1943
1944 case SCROLL_PAN_REDRAW:
1945 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1946 && ((!scroll_partial && (b - t == vc->vc_rows))
1947 || (scroll_partial
1948 && (b - t - count >
1949 3 * vc->vc_rows >> 2)))) {
1950 if (vc->vc_rows - b > 0)
1951 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1952 b - count);
1953 ypan_down_redraw(vc, t, count);
1954 if (t > 0)
1955 fbcon_redraw_move(vc, p, count, t, 0);
1956 } else
1957 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1958 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1959 break;
1960
1961 case SCROLL_REDRAW:
1962 redraw_down:
1963 fbcon_redraw(vc, p, b - 1, b - t - count,
1964 -count * vc->vc_cols);
1965 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1966 scr_memsetw((unsigned short *) (vc->vc_origin +
1967 vc->vc_size_row *
1968 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001969 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001971 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 }
1973 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07001974 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975}
1976
1977
1978static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1979 int height, int width)
1980{
1981 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1982 struct display *p = &fb_display[vc->vc_num];
1983
1984 if (fbcon_is_inactive(vc, info))
1985 return;
1986
1987 if (!width || !height)
1988 return;
1989
1990 /* Split blits that cross physical y_wrap case.
1991 * Pathological case involves 4 blits, better to use recursive
1992 * code rather than unrolled case
1993 *
1994 * Recursive invocations don't need to erase the cursor over and
1995 * over again, so we use fbcon_bmove_rec()
1996 */
1997 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1998 p->vrows - p->yscroll);
1999}
2000
2001static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2002 int dy, int dx, int height, int width, u_int y_break)
2003{
2004 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2005 struct fbcon_ops *ops = info->fbcon_par;
2006 u_int b;
2007
2008 if (sy < y_break && sy + height > y_break) {
2009 b = y_break - sy;
2010 if (dy < sy) { /* Avoid trashing self */
2011 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2012 y_break);
2013 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2014 height - b, width, y_break);
2015 } else {
2016 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2017 height - b, width, y_break);
2018 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2019 y_break);
2020 }
2021 return;
2022 }
2023
2024 if (dy < y_break && dy + height > y_break) {
2025 b = y_break - dy;
2026 if (dy < sy) { /* Avoid trashing self */
2027 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2028 y_break);
2029 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2030 height - b, width, y_break);
2031 } else {
2032 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2033 height - b, width, y_break);
2034 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2035 y_break);
2036 }
2037 return;
2038 }
2039 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2040 height, width);
2041}
2042
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002043static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002044 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 struct vc_data *vc)
2046{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002047 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 int fh = vc->vc_font.height;
2049 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002050 u16 t = 0;
2051 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2052 info->fix.xpanstep);
2053 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2054 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2055 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2056 info->var.xres_virtual);
2057 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2058 divides(ypan, vc->vc_font.height) && vyres > yres;
2059 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2060 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002061 divides(vc->vc_font.height, vyres) &&
2062 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002064 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2065 !(cap & FBINFO_HWACCEL_DISABLED);
2066 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2067 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002069 p->vrows = vyres/fh;
2070 if (yres > (fh * (vc->vc_rows + 1)))
2071 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2072 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 p->vrows--;
2074
2075 if (good_wrap || good_pan) {
2076 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002077 p->scrollmode = good_wrap ?
2078 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 else
2080 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2081 SCROLL_PAN_REDRAW;
2082 } else {
2083 if (reading_fast || (fast_copyarea && !fast_imageblit))
2084 p->scrollmode = SCROLL_MOVE;
2085 else
2086 p->scrollmode = SCROLL_REDRAW;
2087 }
2088}
2089
2090static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002091 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
2093 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002094 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 struct display *p = &fb_display[vc->vc_num];
2096 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002097 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002099 virt_w = FBCON_SWAP(ops->rotate, width, height);
2100 virt_h = FBCON_SWAP(ops->rotate, height, width);
2101 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2102 vc->vc_font.height);
2103 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2104 vc->vc_font.width);
2105 var.xres = virt_w * virt_fw;
2106 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 x_diff = info->var.xres - var.xres;
2108 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002109 if (x_diff < 0 || x_diff > virt_fw ||
2110 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002111 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
2113 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2114 mode = fb_find_best_mode(&var, &info->modelist);
2115 if (mode == NULL)
2116 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002117 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002119
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002120 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
2123 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2124 if (CON_IS_VISIBLE(vc)) {
2125 var.activate = FB_ACTIVATE_NOW |
2126 FB_ACTIVATE_FORCE;
2127 fb_set_var(info, &var);
2128 }
2129 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002130 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 }
2132 updatescrollmode(p, info, vc);
2133 return 0;
2134}
2135
2136static int fbcon_switch(struct vc_data *vc)
2137{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002138 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002139 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 struct display *p = &fb_display[vc->vc_num];
2141 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002142 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002145 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
2147 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 if (softback_lines)
2149 fbcon_set_origin(vc);
2150 softback_top = softback_curr = softback_in = softback_buf;
2151 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002152 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 }
2154
2155 if (logo_shown >= 0) {
2156 struct vc_data *conp2 = vc_cons[logo_shown].d;
2157
2158 if (conp2->vc_top == logo_lines
2159 && conp2->vc_bottom == conp2->vc_rows)
2160 conp2->vc_top = 0;
2161 logo_shown = FBCON_LOGO_CANSHOW;
2162 }
2163
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002164 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002165 if (prev_console != -1)
2166 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 /*
2168 * FIXME: If we have multiple fbdev's loaded, we need to
2169 * update all info->currcon. Perhaps, we can place this
2170 * in a centralized structure, but this might break some
2171 * drivers.
2172 *
2173 * info->currcon = vc->vc_num;
2174 */
2175 for (i = 0; i < FB_MAX; i++) {
2176 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002177 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002179 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 }
2181 }
2182 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2183 display_to_var(&var, p);
2184 var.activate = FB_ACTIVATE_NOW;
2185
2186 /*
2187 * make sure we don't unnecessarily trip the memcmp()
2188 * in fb_set_var()
2189 */
2190 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002191 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002193 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Knut Petersen39942fd2005-12-12 22:17:19 -08002195 if (old_info != NULL && (old_info != info ||
2196 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002197 if (info->fbops->fb_set_par) {
2198 ret = info->fbops->fb_set_par(info);
2199
2200 if (ret)
2201 printk(KERN_ERR "fbcon_switch: detected "
2202 "unhandled fb_set_par error, "
2203 "error code %d\n", ret);
2204 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002205
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002206 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002207 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002210 if (fbcon_is_inactive(vc, info) ||
2211 ops->blank_state != FB_BLANK_UNBLANK)
2212 fbcon_del_cursor_timer(info);
2213 else
2214 fbcon_add_cursor_timer(info);
2215
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002216 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002217 ops->cursor_reset = 1;
2218
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002219 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002220 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002221 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002224 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002226
2227 if (p->userfont)
2228 charcnt = FNTCHARCNT(vc->vc_font.data);
2229
2230 if (charcnt > 256)
2231 vc->vc_complement_mask <<= 1;
2232
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 updatescrollmode(p, info, vc);
2234
2235 switch (p->scrollmode) {
2236 case SCROLL_WRAP_MOVE:
2237 scrollback_phys_max = p->vrows - vc->vc_rows;
2238 break;
2239 case SCROLL_PAN_MOVE:
2240 case SCROLL_PAN_REDRAW:
2241 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2242 if (scrollback_phys_max < 0)
2243 scrollback_phys_max = 0;
2244 break;
2245 default:
2246 scrollback_phys_max = 0;
2247 break;
2248 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 scrollback_max = 0;
2251 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002252
2253 if (!fbcon_is_inactive(vc, info)) {
2254 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2255 ops->update_start(info);
2256 }
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 fbcon_set_palette(vc, color_table);
2259 fbcon_clear_margins(vc, 0);
2260
2261 if (logo_shown == FBCON_LOGO_DRAW) {
2262
2263 logo_shown = fg_console;
2264 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002265 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 update_region(vc,
2267 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2268 vc->vc_size_row * (vc->vc_bottom -
2269 vc->vc_top) / 2);
2270 return 0;
2271 }
2272 return 1;
2273}
2274
2275static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2276 int blank)
2277{
Richard Purdie994efac2007-02-09 09:46:45 +00002278 struct fb_event event;
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 if (blank) {
2281 unsigned short charmask = vc->vc_hi_font_mask ?
2282 0x1ff : 0xff;
2283 unsigned short oldc;
2284
2285 oldc = vc->vc_video_erase_char;
2286 vc->vc_video_erase_char &= charmask;
2287 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2288 vc->vc_video_erase_char = oldc;
2289 }
Richard Purdie994efac2007-02-09 09:46:45 +00002290
2291
Andrea Righi513adb52009-04-13 14:39:39 -07002292 if (!lock_fb_info(info))
2293 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002294 event.info = info;
2295 event.data = &blank;
2296 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002297 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298}
2299
2300static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2301{
2302 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2303 struct fbcon_ops *ops = info->fbcon_par;
2304
2305 if (mode_switch) {
2306 struct fb_var_screeninfo var = info->var;
2307
2308 ops->graphics = 1;
2309
2310 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002311 if (info->fbops->fb_save_state)
2312 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2314 fb_set_var(info, &var);
2315 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002316 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002317 } else if (info->fbops->fb_restore_state)
2318 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320
2321 if (!fbcon_is_inactive(vc, info)) {
2322 if (ops->blank_state != blank) {
2323 ops->blank_state = blank;
2324 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2325 ops->cursor_flash = (!blank);
2326
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002327 if (!(info->flags & FBINFO_MISC_USEREVENT))
2328 if (fb_blank(info, blank))
2329 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 }
2331
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002332 if (!blank)
2333 update_screen(vc);
2334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002336 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002337 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002338 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002339 else
2340 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002341
2342 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343}
2344
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2346{
2347 u8 *fontdata = vc->vc_font.data;
2348 u8 *data = font->data;
2349 int i, j;
2350
2351 font->width = vc->vc_font.width;
2352 font->height = vc->vc_font.height;
2353 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2354 if (!font->data)
2355 return 0;
2356
2357 if (font->width <= 8) {
2358 j = vc->vc_font.height;
2359 for (i = 0; i < font->charcount; i++) {
2360 memcpy(data, fontdata, j);
2361 memset(data + j, 0, 32 - j);
2362 data += 32;
2363 fontdata += j;
2364 }
2365 } else if (font->width <= 16) {
2366 j = vc->vc_font.height * 2;
2367 for (i = 0; i < font->charcount; i++) {
2368 memcpy(data, fontdata, j);
2369 memset(data + j, 0, 64 - j);
2370 data += 64;
2371 fontdata += j;
2372 }
2373 } else if (font->width <= 24) {
2374 for (i = 0; i < font->charcount; i++) {
2375 for (j = 0; j < vc->vc_font.height; j++) {
2376 *data++ = fontdata[0];
2377 *data++ = fontdata[1];
2378 *data++ = fontdata[2];
2379 fontdata += sizeof(u32);
2380 }
2381 memset(data, 0, 3 * (32 - j));
2382 data += 3 * (32 - j);
2383 }
2384 } else {
2385 j = vc->vc_font.height * 4;
2386 for (i = 0; i < font->charcount; i++) {
2387 memcpy(data, fontdata, j);
2388 memset(data + j, 0, 128 - j);
2389 data += 128;
2390 fontdata += j;
2391 }
2392 }
2393 return 0;
2394}
2395
2396static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002397 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
2399 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002400 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 struct display *p = &fb_display[vc->vc_num];
2402 int resize;
2403 int cnt;
2404 char *old_data = NULL;
2405
2406 if (CON_IS_VISIBLE(vc) && softback_lines)
2407 fbcon_set_origin(vc);
2408
2409 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2410 if (p->userfont)
2411 old_data = vc->vc_font.data;
2412 if (userfont)
2413 cnt = FNTCHARCNT(data);
2414 else
2415 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002416 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 if ((p->userfont = userfont))
2418 REFCOUNT(data)++;
2419 vc->vc_font.width = w;
2420 vc->vc_font.height = h;
2421 if (vc->vc_hi_font_mask && cnt == 256) {
2422 vc->vc_hi_font_mask = 0;
2423 if (vc->vc_can_do_color) {
2424 vc->vc_complement_mask >>= 1;
2425 vc->vc_s_complement_mask >>= 1;
2426 }
2427
2428 /* ++Edmund: reorder the attribute bits */
2429 if (vc->vc_can_do_color) {
2430 unsigned short *cp =
2431 (unsigned short *) vc->vc_origin;
2432 int count = vc->vc_screenbuf_size / 2;
2433 unsigned short c;
2434 for (; count > 0; count--, cp++) {
2435 c = scr_readw(cp);
2436 scr_writew(((c & 0xfe00) >> 1) |
2437 (c & 0xff), cp);
2438 }
2439 c = vc->vc_video_erase_char;
2440 vc->vc_video_erase_char =
2441 ((c & 0xfe00) >> 1) | (c & 0xff);
2442 vc->vc_attr >>= 1;
2443 }
2444 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2445 vc->vc_hi_font_mask = 0x100;
2446 if (vc->vc_can_do_color) {
2447 vc->vc_complement_mask <<= 1;
2448 vc->vc_s_complement_mask <<= 1;
2449 }
2450
2451 /* ++Edmund: reorder the attribute bits */
2452 {
2453 unsigned short *cp =
2454 (unsigned short *) vc->vc_origin;
2455 int count = vc->vc_screenbuf_size / 2;
2456 unsigned short c;
2457 for (; count > 0; count--, cp++) {
2458 unsigned short newc;
2459 c = scr_readw(cp);
2460 if (vc->vc_can_do_color)
2461 newc =
2462 ((c & 0xff00) << 1) | (c &
2463 0xff);
2464 else
2465 newc = c & ~0x100;
2466 scr_writew(newc, cp);
2467 }
2468 c = vc->vc_video_erase_char;
2469 if (vc->vc_can_do_color) {
2470 vc->vc_video_erase_char =
2471 ((c & 0xff00) << 1) | (c & 0xff);
2472 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002473 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 vc->vc_video_erase_char = c & ~0x100;
2475 }
2476
2477 }
2478
2479 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002480 int cols, rows;
2481
2482 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2483 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2484 cols /= w;
2485 rows /= h;
2486 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002487 if (CON_IS_VISIBLE(vc) && softback_buf)
2488 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 } else if (CON_IS_VISIBLE(vc)
2490 && vc->vc_mode == KD_TEXT) {
2491 fbcon_clear_margins(vc, 0);
2492 update_screen(vc);
2493 }
2494
2495 if (old_data && (--REFCOUNT(old_data) == 0))
2496 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2497 return 0;
2498}
2499
2500static int fbcon_copy_font(struct vc_data *vc, int con)
2501{
2502 struct display *od = &fb_display[con];
2503 struct console_font *f = &vc->vc_font;
2504
2505 if (od->fontdata == f->data)
2506 return 0; /* already the same font... */
2507 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2508}
2509
2510/*
2511 * User asked to set font; we are guaranteed that
2512 * a) width and height are in range 1..32
2513 * b) charcount does not exceed 512
2514 * but lets not assume that, since someone might someday want to use larger
2515 * fonts. And charcount of 512 is small for unicode support.
2516 *
2517 * However, user space gives the font in 32 rows , regardless of
2518 * actual font height. So a new API is needed if support for larger fonts
2519 * is ever implemented.
2520 */
2521
2522static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2523{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002524 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 unsigned charcount = font->charcount;
2526 int w = font->width;
2527 int h = font->height;
2528 int size;
2529 int i, csum;
2530 u8 *new_data, *data = font->data;
2531 int pitch = (font->width+7) >> 3;
2532
2533 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2534 * If not this check should be changed to charcount < 256 */
2535 if (charcount != 256 && charcount != 512)
2536 return -EINVAL;
2537
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002538 /* Make sure drawing engine can handle the font */
2539 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2540 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2541 return -EINVAL;
2542
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002543 /* Make sure driver can handle the font length */
2544 if (fbcon_invalid_charcount(info, charcount))
2545 return -EINVAL;
2546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 size = h * pitch * charcount;
2548
2549 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2550
2551 if (!new_data)
2552 return -ENOMEM;
2553
2554 new_data += FONT_EXTRA_WORDS * sizeof(int);
2555 FNTSIZE(new_data) = size;
2556 FNTCHARCNT(new_data) = charcount;
2557 REFCOUNT(new_data) = 0; /* usage counter */
2558 for (i=0; i< charcount; i++) {
2559 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2560 }
2561
2562 /* Since linux has a nice crc32 function use it for counting font
2563 * checksums. */
2564 csum = crc32(0, new_data, size);
2565
2566 FNTSUM(new_data) = csum;
2567 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002568 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 struct vc_data *tmp = vc_cons[i].d;
2570
2571 if (fb_display[i].userfont &&
2572 fb_display[i].fontdata &&
2573 FNTSUM(fb_display[i].fontdata) == csum &&
2574 FNTSIZE(fb_display[i].fontdata) == size &&
2575 tmp->vc_font.width == w &&
2576 !memcmp(fb_display[i].fontdata, new_data, size)) {
2577 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002578 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 break;
2580 }
2581 }
2582 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2583}
2584
2585static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2586{
2587 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002588 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
2590 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002591 f = get_default_font(info->var.xres, info->var.yres,
2592 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 else if (!(f = find_font(name)))
2594 return -ENOENT;
2595
2596 font->width = f->width;
2597 font->height = f->height;
2598 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2599}
2600
2601static u16 palette_red[16];
2602static u16 palette_green[16];
2603static u16 palette_blue[16];
2604
2605static struct fb_cmap palette_cmap = {
2606 0, 16, palette_red, palette_green, palette_blue, NULL
2607};
2608
2609static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2610{
2611 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2612 int i, j, k, depth;
2613 u8 val;
2614
2615 if (fbcon_is_inactive(vc, info))
2616 return -EINVAL;
2617
2618 if (!CON_IS_VISIBLE(vc))
2619 return 0;
2620
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002621 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 if (depth > 3) {
2623 for (i = j = 0; i < 16; i++) {
2624 k = table[i];
2625 val = vc->vc_palette[j++];
2626 palette_red[k] = (val << 8) | val;
2627 val = vc->vc_palette[j++];
2628 palette_green[k] = (val << 8) | val;
2629 val = vc->vc_palette[j++];
2630 palette_blue[k] = (val << 8) | val;
2631 }
2632 palette_cmap.len = 16;
2633 palette_cmap.start = 0;
2634 /*
2635 * If framebuffer is capable of less than 16 colors,
2636 * use default palette of fbcon.
2637 */
2638 } else
2639 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2640
2641 return fb_set_cmap(&palette_cmap, info);
2642}
2643
2644static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2645{
2646 unsigned long p;
2647 int line;
2648
2649 if (vc->vc_num != fg_console || !softback_lines)
2650 return (u16 *) (vc->vc_origin + offset);
2651 line = offset / vc->vc_size_row;
2652 if (line >= softback_lines)
2653 return (u16 *) (vc->vc_origin + offset -
2654 softback_lines * vc->vc_size_row);
2655 p = softback_curr + offset;
2656 if (p >= softback_end)
2657 p += softback_buf - softback_end;
2658 return (u16 *) p;
2659}
2660
2661static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2662 int *px, int *py)
2663{
2664 unsigned long ret;
2665 int x, y;
2666
2667 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2668 unsigned long offset = (pos - vc->vc_origin) / 2;
2669
2670 x = offset % vc->vc_cols;
2671 y = offset / vc->vc_cols;
2672 if (vc->vc_num == fg_console)
2673 y += softback_lines;
2674 ret = pos + (vc->vc_cols - x) * 2;
2675 } else if (vc->vc_num == fg_console && softback_lines) {
2676 unsigned long offset = pos - softback_curr;
2677
2678 if (pos < softback_curr)
2679 offset += softback_end - softback_buf;
2680 offset /= 2;
2681 x = offset % vc->vc_cols;
2682 y = offset / vc->vc_cols;
2683 ret = pos + (vc->vc_cols - x) * 2;
2684 if (ret == softback_end)
2685 ret = softback_buf;
2686 if (ret == softback_in)
2687 ret = vc->vc_origin;
2688 } else {
2689 /* Should not happen */
2690 x = y = 0;
2691 ret = vc->vc_origin;
2692 }
2693 if (px)
2694 *px = x;
2695 if (py)
2696 *py = y;
2697 return ret;
2698}
2699
2700/* As we might be inside of softback, we may work with non-contiguous buffer,
2701 that's why we have to use a separate routine. */
2702static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2703{
2704 while (cnt--) {
2705 u16 a = scr_readw(p);
2706 if (!vc->vc_can_do_color)
2707 a ^= 0x0800;
2708 else if (vc->vc_hi_font_mask == 0x100)
2709 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2710 (((a) & 0x0e00) << 4);
2711 else
2712 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2713 (((a) & 0x0700) << 4);
2714 scr_writew(a, p++);
2715 if (p == (u16 *) softback_end)
2716 p = (u16 *) softback_buf;
2717 if (p == (u16 *) softback_in)
2718 p = (u16 *) vc->vc_origin;
2719 }
2720}
2721
2722static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2723{
2724 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002725 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002726 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 int offset, limit, scrollback_old;
2728
2729 if (softback_top) {
2730 if (vc->vc_num != fg_console)
2731 return 0;
2732 if (vc->vc_mode != KD_TEXT || !lines)
2733 return 0;
2734 if (logo_shown >= 0) {
2735 struct vc_data *conp2 = vc_cons[logo_shown].d;
2736
2737 if (conp2->vc_top == logo_lines
2738 && conp2->vc_bottom == conp2->vc_rows)
2739 conp2->vc_top = 0;
2740 if (logo_shown == vc->vc_num) {
2741 unsigned long p, q;
2742 int i;
2743
2744 p = softback_in;
2745 q = vc->vc_origin +
2746 logo_lines * vc->vc_size_row;
2747 for (i = 0; i < logo_lines; i++) {
2748 if (p == softback_top)
2749 break;
2750 if (p == softback_buf)
2751 p = softback_end;
2752 p -= vc->vc_size_row;
2753 q -= vc->vc_size_row;
2754 scr_memcpyw((u16 *) q, (u16 *) p,
2755 vc->vc_size_row);
2756 }
David Hollister308af922006-05-30 21:25:36 -07002757 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 update_region(vc, vc->vc_origin,
2759 logo_lines * vc->vc_cols);
2760 }
2761 logo_shown = FBCON_LOGO_CANSHOW;
2762 }
2763 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002764 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2766 return 0;
2767 }
2768
2769 if (!scrollback_phys_max)
2770 return -ENOSYS;
2771
2772 scrollback_old = scrollback_current;
2773 scrollback_current -= lines;
2774 if (scrollback_current < 0)
2775 scrollback_current = 0;
2776 else if (scrollback_current > scrollback_max)
2777 scrollback_current = scrollback_max;
2778 if (scrollback_current == scrollback_old)
2779 return 0;
2780
2781 if (fbcon_is_inactive(vc, info))
2782 return 0;
2783
2784 fbcon_cursor(vc, CM_ERASE);
2785
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002786 offset = disp->yscroll - scrollback_current;
2787 limit = disp->vrows;
2788 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 case SCROLL_WRAP_MOVE:
2790 info->var.vmode |= FB_VMODE_YWRAP;
2791 break;
2792 case SCROLL_PAN_MOVE:
2793 case SCROLL_PAN_REDRAW:
2794 limit -= vc->vc_rows;
2795 info->var.vmode &= ~FB_VMODE_YWRAP;
2796 break;
2797 }
2798 if (offset < 0)
2799 offset += limit;
2800 else if (offset >= limit)
2801 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002802
2803 ops->var.xoffset = 0;
2804 ops->var.yoffset = offset * vc->vc_font.height;
2805 ops->update_start(info);
2806
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 if (!scrollback_current)
2808 fbcon_cursor(vc, CM_DRAW);
2809 return 0;
2810}
2811
2812static int fbcon_set_origin(struct vc_data *vc)
2813{
2814 if (softback_lines)
2815 fbcon_scrolldelta(vc, softback_lines);
2816 return 0;
2817}
2818
2819static void fbcon_suspended(struct fb_info *info)
2820{
2821 struct vc_data *vc = NULL;
2822 struct fbcon_ops *ops = info->fbcon_par;
2823
2824 if (!ops || ops->currcon < 0)
2825 return;
2826 vc = vc_cons[ops->currcon].d;
2827
2828 /* Clear cursor, restore saved data */
2829 fbcon_cursor(vc, CM_ERASE);
2830}
2831
2832static void fbcon_resumed(struct fb_info *info)
2833{
2834 struct vc_data *vc;
2835 struct fbcon_ops *ops = info->fbcon_par;
2836
2837 if (!ops || ops->currcon < 0)
2838 return;
2839 vc = vc_cons[ops->currcon].d;
2840
2841 update_screen(vc);
2842}
2843
2844static void fbcon_modechanged(struct fb_info *info)
2845{
2846 struct fbcon_ops *ops = info->fbcon_par;
2847 struct vc_data *vc;
2848 struct display *p;
2849 int rows, cols;
2850
2851 if (!ops || ops->currcon < 0)
2852 return;
2853 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002854 if (vc->vc_mode != KD_TEXT ||
2855 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 return;
2857
2858 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002859 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860
2861 if (CON_IS_VISIBLE(vc)) {
2862 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002863 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2864 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2865 cols /= vc->vc_font.width;
2866 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 vc_resize(vc, cols, rows);
2868 updatescrollmode(p, info, vc);
2869 scrollback_max = 0;
2870 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002871
2872 if (!fbcon_is_inactive(vc, info)) {
2873 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2874 ops->update_start(info);
2875 }
2876
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 fbcon_set_palette(vc, color_table);
2878 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002879 if (softback_buf)
2880 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
2882}
2883
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002884static void fbcon_set_all_vcs(struct fb_info *info)
2885{
2886 struct fbcon_ops *ops = info->fbcon_par;
2887 struct vc_data *vc;
2888 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002889 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002890
2891 if (!ops || ops->currcon < 0)
2892 return;
2893
Antonino A. Daplase614b182006-06-26 00:27:09 -07002894 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002895 vc = vc_cons[i].d;
2896 if (!vc || vc->vc_mode != KD_TEXT ||
2897 registered_fb[con2fb_map[i]] != info)
2898 continue;
2899
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002900 if (CON_IS_VISIBLE(vc)) {
2901 fg = i;
2902 continue;
2903 }
2904
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002905 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002906 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002907 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002908 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2909 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002910 cols /= vc->vc_font.width;
2911 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002912 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002913 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002914
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002915 if (fg != -1)
2916 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002917}
2918
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919static int fbcon_mode_deleted(struct fb_info *info,
2920 struct fb_videomode *mode)
2921{
2922 struct fb_info *fb_info;
2923 struct display *p;
2924 int i, j, found = 0;
2925
2926 /* before deletion, ensure that mode is not in use */
2927 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2928 j = con2fb_map[i];
2929 if (j == -1)
2930 continue;
2931 fb_info = registered_fb[j];
2932 if (fb_info != info)
2933 continue;
2934 p = &fb_display[i];
2935 if (!p || !p->mode)
2936 continue;
2937 if (fb_mode_is_equal(p->mode, mode)) {
2938 found = 1;
2939 break;
2940 }
2941 }
2942 return found;
2943}
2944
Jesse Barnescfafca82007-07-17 04:05:33 -07002945#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2946static int fbcon_unbind(void)
2947{
2948 int ret;
2949
2950 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2951 fbcon_is_default);
2952 return ret;
2953}
2954#else
2955static inline int fbcon_unbind(void)
2956{
2957 return -EINVAL;
2958}
2959#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2960
2961static int fbcon_fb_unbind(int idx)
2962{
2963 int i, new_idx = -1, ret = 0;
2964
2965 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2966 if (con2fb_map[i] != idx &&
2967 con2fb_map[i] != -1) {
2968 new_idx = i;
2969 break;
2970 }
2971 }
2972
2973 if (new_idx != -1) {
2974 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2975 if (con2fb_map[i] == idx)
2976 set_con2fb_map(i, new_idx, 0);
2977 }
2978 } else
2979 ret = fbcon_unbind();
2980
2981 return ret;
2982}
2983
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002984static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07002985{
Andrea Righi66c1ca02009-03-31 15:25:18 -07002986 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07002987
Andrea Righi66c1ca02009-03-31 15:25:18 -07002988 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07002989 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2990 if (con2fb_map[i] == idx)
2991 con2fb_map[i] = -1;
2992 }
2993
2994 if (idx == info_idx) {
2995 info_idx = -1;
2996
2997 for (i = 0; i < FB_MAX; i++) {
2998 if (registered_fb[i] != NULL) {
2999 info_idx = i;
3000 break;
3001 }
3002 }
3003 }
3004
3005 if (info_idx != -1) {
3006 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3007 if (con2fb_map[i] == -1)
3008 con2fb_map[i] = info_idx;
3009 }
3010 }
3011
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003012 if (primary_device == idx)
3013 primary_device = -1;
3014
Andrea Righi66c1ca02009-03-31 15:25:18 -07003015 if (!num_registered_fb)
3016 unregister_con_driver(&fb_con);
3017
Antonino A. Daplase614b182006-06-26 00:27:09 -07003018 return 0;
3019}
3020
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003021#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003022static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003024 if (!map_override && primary_device == -1 &&
3025 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003026 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003027
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003028 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3029 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003030 primary_device = info->node;
3031
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003032 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003033 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003034
3035 if (con_is_bound(&fb_con)) {
3036 printk(KERN_INFO "fbcon: Remapping primary device, "
3037 "fb%i, to tty %i-%i\n", info->node,
3038 first_fb_vc + 1, last_fb_vc + 1);
3039 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003040 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003041 }
3042
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003043}
3044#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003045static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003046{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003047 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003048}
3049#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3050
3051static int fbcon_fb_registered(struct fb_info *info)
3052{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003053 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003054
Andrea Righi66c1ca02009-03-31 15:25:18 -07003055 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003056 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003059 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 if (con2fb_map_boot[i] == idx) {
3061 info_idx = idx;
3062 break;
3063 }
3064 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003065
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 if (info_idx != -1)
3067 ret = fbcon_takeover(1);
3068 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003069 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003070 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 set_con2fb_map(i, idx, 0);
3072 }
3073 }
3074
3075 return ret;
3076}
3077
3078static void fbcon_fb_blanked(struct fb_info *info, int blank)
3079{
3080 struct fbcon_ops *ops = info->fbcon_par;
3081 struct vc_data *vc;
3082
3083 if (!ops || ops->currcon < 0)
3084 return;
3085
3086 vc = vc_cons[ops->currcon].d;
3087 if (vc->vc_mode != KD_TEXT ||
3088 registered_fb[con2fb_map[ops->currcon]] != info)
3089 return;
3090
3091 if (CON_IS_VISIBLE(vc)) {
3092 if (blank)
3093 do_blank_screen(0);
3094 else
3095 do_unblank_screen(0);
3096 }
3097 ops->blank_state = blank;
3098}
3099
3100static void fbcon_new_modelist(struct fb_info *info)
3101{
3102 int i;
3103 struct vc_data *vc;
3104 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003105 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106
Antonino A. Daplase614b182006-06-26 00:27:09 -07003107 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 if (registered_fb[con2fb_map[i]] != info)
3109 continue;
3110 if (!fb_display[i].mode)
3111 continue;
3112 vc = vc_cons[i].d;
3113 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003114 mode = fb_find_nearest_mode(fb_display[i].mode,
3115 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003117 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 }
3119}
3120
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003121static void fbcon_get_requirement(struct fb_info *info,
3122 struct fb_blit_caps *caps)
3123{
3124 struct vc_data *vc;
3125 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003126
3127 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003128 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003129
3130 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3131 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003132 if (vc && vc->vc_mode == KD_TEXT &&
3133 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003134 p = &fb_display[i];
3135 caps->x |= 1 << (vc->vc_font.width - 1);
3136 caps->y |= 1 << (vc->vc_font.height - 1);
3137 charcnt = (p->userfont) ?
3138 FNTCHARCNT(p->fontdata) : 256;
3139 if (caps->len < charcnt)
3140 caps->len = charcnt;
3141 }
3142 }
3143 } else {
3144 vc = vc_cons[fg_console].d;
3145
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003146 if (vc && vc->vc_mode == KD_TEXT &&
3147 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003148 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003149 caps->x = 1 << (vc->vc_font.width - 1);
3150 caps->y = 1 << (vc->vc_font.height - 1);
3151 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003152 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003153 }
3154 }
3155}
3156
Andrea Righi66c1ca02009-03-31 15:25:18 -07003157static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 unsigned long action, void *data)
3159{
3160 struct fb_event *event = data;
3161 struct fb_info *info = event->info;
3162 struct fb_videomode *mode;
3163 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003164 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003165 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166
Antonino A. Daplase614b182006-06-26 00:27:09 -07003167 /*
3168 * ignore all events except driver registration and deregistration
3169 * if fbcon is not active
3170 */
3171 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3172 action == FB_EVENT_FB_UNREGISTERED))
3173 goto done;
3174
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 switch(action) {
3176 case FB_EVENT_SUSPEND:
3177 fbcon_suspended(info);
3178 break;
3179 case FB_EVENT_RESUME:
3180 fbcon_resumed(info);
3181 break;
3182 case FB_EVENT_MODE_CHANGE:
3183 fbcon_modechanged(info);
3184 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003185 case FB_EVENT_MODE_CHANGE_ALL:
3186 fbcon_set_all_vcs(info);
3187 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 case FB_EVENT_MODE_DELETE:
3189 mode = event->data;
3190 ret = fbcon_mode_deleted(info, mode);
3191 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003192 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003193 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003194 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003195 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003197 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003199 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003200 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003201 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 case FB_EVENT_SET_CONSOLE_MAP:
3203 con2fb = event->data;
3204 ret = set_con2fb_map(con2fb->console - 1,
3205 con2fb->framebuffer, 1);
3206 break;
3207 case FB_EVENT_GET_CONSOLE_MAP:
3208 con2fb = event->data;
3209 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3210 break;
3211 case FB_EVENT_BLANK:
3212 fbcon_fb_blanked(info, *(int *)event->data);
3213 break;
3214 case FB_EVENT_NEW_MODELIST:
3215 fbcon_new_modelist(info);
3216 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003217 case FB_EVENT_GET_REQ:
3218 caps = event->data;
3219 fbcon_get_requirement(info, caps);
3220 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003222done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 return ret;
3224}
3225
3226/*
3227 * The console `switch' structure for the frame buffer based console
3228 */
3229
3230static const struct consw fb_con = {
3231 .owner = THIS_MODULE,
3232 .con_startup = fbcon_startup,
3233 .con_init = fbcon_init,
3234 .con_deinit = fbcon_deinit,
3235 .con_clear = fbcon_clear,
3236 .con_putc = fbcon_putc,
3237 .con_putcs = fbcon_putcs,
3238 .con_cursor = fbcon_cursor,
3239 .con_scroll = fbcon_scroll,
3240 .con_bmove = fbcon_bmove,
3241 .con_switch = fbcon_switch,
3242 .con_blank = fbcon_blank,
3243 .con_font_set = fbcon_set_font,
3244 .con_font_get = fbcon_get_font,
3245 .con_font_default = fbcon_set_def_font,
3246 .con_font_copy = fbcon_copy_font,
3247 .con_set_palette = fbcon_set_palette,
3248 .con_scrolldelta = fbcon_scrolldelta,
3249 .con_set_origin = fbcon_set_origin,
3250 .con_invert_region = fbcon_invert_region,
3251 .con_screen_pos = fbcon_screen_pos,
3252 .con_getxy = fbcon_getxy,
3253 .con_resize = fbcon_resize,
3254};
3255
3256static struct notifier_block fbcon_event_notifier = {
3257 .notifier_call = fbcon_event_notify,
3258};
3259
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003260static ssize_t store_rotate(struct device *device,
3261 struct device_attribute *attr, const char *buf,
3262 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003263{
3264 struct fb_info *info;
3265 int rotate, idx;
3266 char **last = NULL;
3267
Antonino A. Daplase614b182006-06-26 00:27:09 -07003268 if (fbcon_has_exited)
3269 return count;
3270
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003271 acquire_console_sem();
3272 idx = con2fb_map[fg_console];
3273
3274 if (idx == -1 || registered_fb[idx] == NULL)
3275 goto err;
3276
3277 info = registered_fb[idx];
3278 rotate = simple_strtoul(buf, last, 0);
3279 fbcon_rotate(info, rotate);
3280err:
3281 release_console_sem();
3282 return count;
3283}
3284
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003285static ssize_t store_rotate_all(struct device *device,
3286 struct device_attribute *attr,const char *buf,
3287 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003288{
3289 struct fb_info *info;
3290 int rotate, idx;
3291 char **last = NULL;
3292
Antonino A. Daplase614b182006-06-26 00:27:09 -07003293 if (fbcon_has_exited)
3294 return count;
3295
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003296 acquire_console_sem();
3297 idx = con2fb_map[fg_console];
3298
3299 if (idx == -1 || registered_fb[idx] == NULL)
3300 goto err;
3301
3302 info = registered_fb[idx];
3303 rotate = simple_strtoul(buf, last, 0);
3304 fbcon_rotate_all(info, rotate);
3305err:
3306 release_console_sem();
3307 return count;
3308}
3309
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003310static ssize_t show_rotate(struct device *device,
3311 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003312{
3313 struct fb_info *info;
3314 int rotate = 0, idx;
3315
Antonino A. Daplase614b182006-06-26 00:27:09 -07003316 if (fbcon_has_exited)
3317 return 0;
3318
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003319 acquire_console_sem();
3320 idx = con2fb_map[fg_console];
3321
3322 if (idx == -1 || registered_fb[idx] == NULL)
3323 goto err;
3324
3325 info = registered_fb[idx];
3326 rotate = fbcon_get_rotate(info);
3327err:
3328 release_console_sem();
3329 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3330}
3331
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003332static ssize_t show_cursor_blink(struct device *device,
3333 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003334{
3335 struct fb_info *info;
3336 struct fbcon_ops *ops;
3337 int idx, blink = -1;
3338
3339 if (fbcon_has_exited)
3340 return 0;
3341
3342 acquire_console_sem();
3343 idx = con2fb_map[fg_console];
3344
3345 if (idx == -1 || registered_fb[idx] == NULL)
3346 goto err;
3347
3348 info = registered_fb[idx];
3349 ops = info->fbcon_par;
3350
3351 if (!ops)
3352 goto err;
3353
3354 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3355err:
3356 release_console_sem();
3357 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3358}
3359
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003360static ssize_t store_cursor_blink(struct device *device,
3361 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003362 const char *buf, size_t count)
3363{
3364 struct fb_info *info;
3365 int blink, idx;
3366 char **last = NULL;
3367
3368 if (fbcon_has_exited)
3369 return count;
3370
3371 acquire_console_sem();
3372 idx = con2fb_map[fg_console];
3373
3374 if (idx == -1 || registered_fb[idx] == NULL)
3375 goto err;
3376
3377 info = registered_fb[idx];
3378
3379 if (!info->fbcon_par)
3380 goto err;
3381
3382 blink = simple_strtoul(buf, last, 0);
3383
3384 if (blink) {
3385 fbcon_cursor_noblink = 0;
3386 fbcon_add_cursor_timer(info);
3387 } else {
3388 fbcon_cursor_noblink = 1;
3389 fbcon_del_cursor_timer(info);
3390 }
3391
3392err:
3393 release_console_sem();
3394 return count;
3395}
3396
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003397static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003398 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3399 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003400 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3401 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003402};
3403
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003404static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003405{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003406 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003407
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003408 fbcon_has_sysfs = 1;
3409
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003410 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3411 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003412
3413 if (error)
3414 break;
3415 }
3416
3417 if (error) {
3418 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003419 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003420
3421 fbcon_has_sysfs = 0;
3422 }
3423
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003424 return 0;
3425}
3426
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003427static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003430 int i;
3431
3432 acquire_console_sem();
3433
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 for (i = 0; i < FB_MAX; i++) {
3435 if (registered_fb[i] != NULL) {
3436 info_idx = i;
3437 break;
3438 }
3439 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003440
3441 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 fbcon_takeover(0);
3443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444}
3445
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003446static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003447{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003448 struct fb_info *info;
3449 int i, j, mapped;
3450
Antonino A. Daplase614b182006-06-26 00:27:09 -07003451 if (fbcon_has_exited)
3452 return;
3453
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003454 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003455 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003456
3457 for (i = 0; i < FB_MAX; i++) {
Geoff Levandbeaa4862008-12-09 13:14:17 -08003458 int pending;
3459
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003460 mapped = 0;
3461 info = registered_fb[i];
3462
3463 if (info == NULL)
3464 continue;
3465
Geoff Levandbeaa4862008-12-09 13:14:17 -08003466 pending = cancel_work_sync(&info->queue);
3467 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3468 "no"));
3469
Antonino A. Daplase614b182006-06-26 00:27:09 -07003470 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3471 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003472 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003473 }
3474
3475 if (mapped) {
3476 if (info->fbops->fb_release)
3477 info->fbops->fb_release(info, 0);
3478 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003479
3480 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003481 struct fbcon_ops *ops = info->fbcon_par;
3482
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003483 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003484 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003485 kfree(info->fbcon_par);
3486 info->fbcon_par = NULL;
3487 }
3488
3489 if (info->queue.func == fb_flashcursor)
3490 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003491 }
3492 }
3493
Antonino A. Daplase614b182006-06-26 00:27:09 -07003494 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003495}
3496
3497static int __init fb_console_init(void)
3498{
3499 int i;
3500
3501 acquire_console_sem();
3502 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003503 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3504 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003505
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003506 if (IS_ERR(fbcon_device)) {
3507 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003508 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003509 PTR_ERR(fbcon_device));
3510 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003511 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003512 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003513
3514 for (i = 0; i < MAX_NR_CONSOLES; i++)
3515 con2fb_map[i] = -1;
3516
3517 release_console_sem();
3518 fbcon_start();
3519 return 0;
3520}
3521
3522module_init(fb_console_init);
3523
3524#ifdef MODULE
3525
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003526static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003527{
3528 int i;
3529
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003530 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003531 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3532 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003533
3534 fbcon_has_sysfs = 0;
3535 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003536}
3537
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538static void __exit fb_console_exit(void)
3539{
3540 acquire_console_sem();
3541 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003542 fbcon_deinit_device();
3543 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003544 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003546 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547}
3548
3549module_exit(fb_console_exit);
3550
3551#endif
3552
3553MODULE_LICENSE("GPL");