blob: 2cd500a304f234456c083baf920255a657c650f9 [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;
728 int err = 0;
729
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 */
755 if (newinfo->fbops->fb_set_par)
756 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758
759 return err;
760}
761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
763 int unit, int show_logo)
764{
765 struct fbcon_ops *ops = info->fbcon_par;
766
767 ops->currcon = fg_console;
768
769 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
770 info->fbops->fb_set_par(info);
771
772 ops->flags |= FBCON_FLAGS_INIT;
773 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700774 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 if (show_logo) {
777 struct vc_data *fg_vc = vc_cons[fg_console].d;
778 struct fb_info *fg_info =
779 registered_fb[con2fb_map[fg_console]];
780
781 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
782 fg_vc->vc_rows, fg_vc->vc_cols,
783 fg_vc->vc_rows);
784 }
785
786 update_screen(vc_cons[fg_console].d);
787}
788
789/**
790 * set_con2fb_map - map console to frame buffer device
791 * @unit: virtual console number to map
792 * @newidx: frame buffer index to map virtual console to
793 * @user: user request
794 *
795 * Maps a virtual console @unit to a frame buffer device
796 * @newidx.
797 */
798static int set_con2fb_map(int unit, int newidx, int user)
799{
800 struct vc_data *vc = vc_cons[unit].d;
801 int oldidx = con2fb_map[unit];
802 struct fb_info *info = registered_fb[newidx];
803 struct fb_info *oldinfo = NULL;
804 int found, err = 0;
805
806 if (oldidx == newidx)
807 return 0;
808
Antonino A. Daplase614b182006-06-26 00:27:09 -0700809 if (!info || fbcon_has_exited)
810 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
812 if (!err && !search_for_mapped_con()) {
813 info_idx = newidx;
814 return fbcon_takeover(0);
815 }
816
817 if (oldidx != -1)
818 oldinfo = registered_fb[oldidx];
819
820 found = search_fb_in_map(newidx);
821
822 acquire_console_sem();
823 con2fb_map[unit] = newidx;
824 if (!err && !found)
825 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
826
827
828 /*
829 * If old fb is not mapped to any of the consoles,
830 * fbcon should release it.
831 */
832 if (!err && oldinfo && !search_fb_in_map(oldidx))
833 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
834 found);
835
836 if (!err) {
837 int show_logo = (fg_console == 0 && !user &&
838 logo_shown != FBCON_LOGO_DONTSHOW);
839
840 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700841 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 con2fb_map_boot[unit] = newidx;
843 con2fb_init_display(vc, info, unit, show_logo);
844 }
845
Antonino A. Daplase614b182006-06-26 00:27:09 -0700846 if (!search_fb_in_map(info_idx))
847 info_idx = newidx;
848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 release_console_sem();
850 return err;
851}
852
853/*
854 * Low Level Operations
855 */
856/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
857static int var_to_display(struct display *disp,
858 struct fb_var_screeninfo *var,
859 struct fb_info *info)
860{
861 disp->xres_virtual = var->xres_virtual;
862 disp->yres_virtual = var->yres_virtual;
863 disp->bits_per_pixel = var->bits_per_pixel;
864 disp->grayscale = var->grayscale;
865 disp->nonstd = var->nonstd;
866 disp->accel_flags = var->accel_flags;
867 disp->height = var->height;
868 disp->width = var->width;
869 disp->red = var->red;
870 disp->green = var->green;
871 disp->blue = var->blue;
872 disp->transp = var->transp;
873 disp->rotate = var->rotate;
874 disp->mode = fb_match_mode(var, &info->modelist);
875 if (disp->mode == NULL)
876 /* This should not happen */
877 return -EINVAL;
878 return 0;
879}
880
881static void display_to_var(struct fb_var_screeninfo *var,
882 struct display *disp)
883{
884 fb_videomode_to_var(var, disp->mode);
885 var->xres_virtual = disp->xres_virtual;
886 var->yres_virtual = disp->yres_virtual;
887 var->bits_per_pixel = disp->bits_per_pixel;
888 var->grayscale = disp->grayscale;
889 var->nonstd = disp->nonstd;
890 var->accel_flags = disp->accel_flags;
891 var->height = disp->height;
892 var->width = disp->width;
893 var->red = disp->red;
894 var->green = disp->green;
895 var->blue = disp->blue;
896 var->transp = disp->transp;
897 var->rotate = disp->rotate;
898}
899
900static const char *fbcon_startup(void)
901{
902 const char *display_desc = "frame buffer device";
903 struct display *p = &fb_display[fg_console];
904 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700905 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 struct module *owner;
907 struct fb_info *info = NULL;
908 struct fbcon_ops *ops;
909 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 /*
912 * If num_registered_fb is zero, this is a call for the dummy part.
913 * The frame buffer devices weren't initialized yet.
914 */
915 if (!num_registered_fb || info_idx == -1)
916 return display_desc;
917 /*
918 * Instead of blindly using registered_fb[0], we use info_idx, set by
919 * fb_console_init();
920 */
921 info = registered_fb[info_idx];
922 if (!info)
923 return NULL;
924
925 owner = info->fbops->owner;
926 if (!try_module_get(owner))
927 return NULL;
928 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
929 module_put(owner);
930 return NULL;
931 }
932
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800933 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if (!ops) {
935 module_put(owner);
936 return NULL;
937 }
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 ops->currcon = -1;
940 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800941 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800943 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800944 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 if (info->fix.type != FB_TYPE_TEXT) {
947 if (fbcon_softback_size) {
948 if (!softback_buf) {
949 softback_buf =
950 (unsigned long)
951 kmalloc(fbcon_softback_size,
952 GFP_KERNEL);
953 if (!softback_buf) {
954 fbcon_softback_size = 0;
955 softback_top = 0;
956 }
957 }
958 } else {
959 if (softback_buf) {
960 kfree((void *) softback_buf);
961 softback_buf = 0;
962 softback_top = 0;
963 }
964 }
965 if (softback_buf)
966 softback_in = softback_top = softback_curr =
967 softback_buf;
968 softback_lines = 0;
969 }
970
971 /* Setup default font */
972 if (!p->fontdata) {
973 if (!fontname[0] || !(font = find_font(fontname)))
974 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700975 info->var.yres,
976 info->pixmap.blit_x,
977 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 vc->vc_font.width = font->width;
979 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700980 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
982 }
983
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800984 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
985 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
986 cols /= vc->vc_font.width;
987 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 vc_resize(vc, cols, rows);
989
990 DPRINTK("mode: %s\n", info->fix.id);
991 DPRINTK("visual: %d\n", info->fix.visual);
992 DPRINTK("res: %dx%d-%d\n", info->var.xres,
993 info->var.yres,
994 info->var.bits_per_pixel);
995
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700996 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700997 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 return display_desc;
999}
1000
1001static void fbcon_init(struct vc_data *vc, int init)
1002{
1003 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1004 struct fbcon_ops *ops;
1005 struct vc_data **default_mode = vc->vc_display_fg;
1006 struct vc_data *svc = *default_mode;
1007 struct display *t, *p = &fb_display[vc->vc_num];
1008 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001009 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 if (info_idx == -1 || info == NULL)
1012 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001013
1014 cap = info->flags;
1015
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1017 (info->fix.type == FB_TYPE_TEXT))
1018 logo = 0;
1019
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 if (var_to_display(p, &info->var, info))
1021 return;
1022
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001023 if (!info->fbcon_par)
1024 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1025
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 /* If we are not the first console on this
1027 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001028 t = &fb_display[fg_console];
1029 if (!p->fontdata) {
1030 if (t->fontdata) {
1031 struct vc_data *fvc = vc_cons[fg_console].d;
1032
1033 vc->vc_font.data = (void *)(p->fontdata =
1034 fvc->vc_font.data);
1035 vc->vc_font.width = fvc->vc_font.width;
1036 vc->vc_font.height = fvc->vc_font.height;
1037 p->userfont = t->userfont;
1038
1039 if (p->userfont)
1040 REFCOUNT(p->fontdata)++;
1041 } else {
1042 const struct font_desc *font = NULL;
1043
1044 if (!fontname[0] || !(font = find_font(fontname)))
1045 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001046 info->var.yres,
1047 info->pixmap.blit_x,
1048 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001049 vc->vc_font.width = font->width;
1050 vc->vc_font.height = font->height;
1051 vc->vc_font.data = (void *)(p->fontdata = font->data);
1052 vc->vc_font.charcount = 256; /* FIXME Need to
1053 support more fonts */
1054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (p->userfont)
1058 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001059
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001060 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1062 if (charcnt == 256) {
1063 vc->vc_hi_font_mask = 0;
1064 } else {
1065 vc->vc_hi_font_mask = 0x100;
1066 if (vc->vc_can_do_color)
1067 vc->vc_complement_mask <<= 1;
1068 }
1069
1070 if (!*svc->vc_uni_pagedir_loc)
1071 con_set_default_unimap(svc);
1072 if (!*vc->vc_uni_pagedir_loc)
1073 con_copy_unimap(vc, svc);
1074
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001075 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001076 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001077 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001078
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 cols = vc->vc_cols;
1080 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001081 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1082 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1083 new_cols /= vc->vc_font.width;
1084 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 vc_resize(vc, new_cols, new_rows);
1086
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 /*
1088 * We must always set the mode. The mode of the previous console
1089 * driver could be in the same resolution but we are using different
1090 * hardware so we have to initialize the hardware.
1091 *
1092 * We need to do it in fbcon_init() to prevent screen corruption.
1093 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001094 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 if (info->fbops->fb_set_par &&
1096 !(ops->flags & FBCON_FLAGS_INIT))
1097 info->fbops->fb_set_par(info);
1098 ops->flags |= FBCON_FLAGS_INIT;
1099 }
1100
1101 ops->graphics = 0;
1102
1103 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1104 !(cap & FBINFO_HWACCEL_DISABLED))
1105 p->scrollmode = SCROLL_MOVE;
1106 else /* default to something safe */
1107 p->scrollmode = SCROLL_REDRAW;
1108
1109 /*
1110 * ++guenther: console.c:vc_allocate() relies on initializing
1111 * vc_{cols,rows}, but we must not set those if we are only
1112 * resizing the console.
1113 */
1114 if (!init) {
1115 vc->vc_cols = new_cols;
1116 vc->vc_rows = new_rows;
1117 }
1118
1119 if (logo)
1120 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1121
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001122 if (vc == svc && softback_buf)
1123 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001124
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001125 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001126 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001127 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001128 }
1129
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001130 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131}
1132
Antonino A. Daplase614b182006-06-26 00:27:09 -07001133static void fbcon_free_font(struct display *p)
1134{
1135 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1136 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1137 p->fontdata = NULL;
1138 p->userfont = 0;
1139}
1140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141static void fbcon_deinit(struct vc_data *vc)
1142{
1143 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001144 struct fb_info *info;
1145 struct fbcon_ops *ops;
1146 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001149 idx = con2fb_map[vc->vc_num];
1150
1151 if (idx == -1)
1152 goto finished;
1153
1154 info = registered_fb[idx];
1155
1156 if (!info)
1157 goto finished;
1158
1159 ops = info->fbcon_par;
1160
1161 if (!ops)
1162 goto finished;
1163
1164 if (CON_IS_VISIBLE(vc))
1165 fbcon_del_cursor_timer(info);
1166
1167 ops->flags &= ~FBCON_FLAGS_INIT;
1168finished:
1169
1170 if (!con_is_bound(&fb_con))
1171 fbcon_exit();
1172
1173 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
1176/* ====================================================================== */
1177
1178/* fbcon_XXX routines - interface used by the world
1179 *
1180 * This system is now divided into two levels because of complications
1181 * caused by hardware scrolling. Top level functions:
1182 *
1183 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1184 *
1185 * handles y values in range [0, scr_height-1] that correspond to real
1186 * screen positions. y_wrap shift means that first line of bitmap may be
1187 * anywhere on this display. These functions convert lineoffsets to
1188 * bitmap offsets and deal with the wrap-around case by splitting blits.
1189 *
1190 * fbcon_bmove_physical_8() -- These functions fast implementations
1191 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1192 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1193 *
1194 * WARNING:
1195 *
1196 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1197 * Implies should only really hardware scroll in rows. Only reason for
1198 * restriction is simplicity & efficiency at the moment.
1199 */
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1202 int width)
1203{
1204 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1205 struct fbcon_ops *ops = info->fbcon_par;
1206
1207 struct display *p = &fb_display[vc->vc_num];
1208 u_int y_break;
1209
1210 if (fbcon_is_inactive(vc, info))
1211 return;
1212
1213 if (!height || !width)
1214 return;
1215
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001216 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1217 vc->vc_top = 0;
1218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 /* Split blits that cross physical y_wrap boundary */
1220
1221 y_break = p->vrows - p->yscroll;
1222 if (sy < y_break && sy + height - 1 >= y_break) {
1223 u_int b = y_break - sy;
1224 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1225 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1226 width);
1227 } else
1228 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1229}
1230
1231static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1232 int count, int ypos, int xpos)
1233{
1234 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1235 struct display *p = &fb_display[vc->vc_num];
1236 struct fbcon_ops *ops = info->fbcon_par;
1237
1238 if (!fbcon_is_inactive(vc, info))
1239 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1240 get_color(vc, info, scr_readw(s), 1),
1241 get_color(vc, info, scr_readw(s), 0));
1242}
1243
1244static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1245{
1246 unsigned short chr;
1247
1248 scr_writew(c, &chr);
1249 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1250}
1251
1252static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1253{
1254 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1255 struct fbcon_ops *ops = info->fbcon_par;
1256
1257 if (!fbcon_is_inactive(vc, info))
1258 ops->clear_margins(vc, info, bottom_only);
1259}
1260
1261static void fbcon_cursor(struct vc_data *vc, int mode)
1262{
1263 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1264 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 int y;
1266 int c = scr_readw((u16 *) vc->vc_pos);
1267
Michal Januszewskid1e23062007-05-08 00:38:07 -07001268 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 return;
1270
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001271 if (vc->vc_cursor_type & 0x10)
1272 fbcon_del_cursor_timer(info);
1273 else
1274 fbcon_add_cursor_timer(info);
1275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1277 if (mode & CM_SOFTBACK) {
1278 mode &= ~CM_SOFTBACK;
1279 y = softback_lines;
1280 } else {
1281 if (softback_lines)
1282 fbcon_set_origin(vc);
1283 y = 0;
1284 }
1285
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001286 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 get_color(vc, info, c, 0));
1288 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1289}
1290
1291static int scrollback_phys_max = 0;
1292static int scrollback_max = 0;
1293static int scrollback_current = 0;
1294
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001296 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001298 struct display *p, *t;
1299 struct vc_data **default_mode, *vc;
1300 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001301 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 int rows, cols, charcnt = 256;
1303
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001304 p = &fb_display[unit];
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if (var_to_display(p, var, info))
1307 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001308
1309 vc = vc_cons[unit].d;
1310
1311 if (!vc)
1312 return;
1313
1314 default_mode = vc->vc_display_fg;
1315 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001317
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001319 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 vc->vc_font.width = (*default_mode)->vc_font.width;
1321 vc->vc_font.height = (*default_mode)->vc_font.height;
1322 p->userfont = t->userfont;
1323 if (p->userfont)
1324 REFCOUNT(p->fontdata)++;
1325 }
1326 if (p->userfont)
1327 charcnt = FNTCHARCNT(p->fontdata);
1328
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001329 var->activate = FB_ACTIVATE_NOW;
1330 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001331 var->yoffset = info->var.yoffset;
1332 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001333 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001334 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001335 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1337 if (charcnt == 256) {
1338 vc->vc_hi_font_mask = 0;
1339 } else {
1340 vc->vc_hi_font_mask = 0x100;
1341 if (vc->vc_can_do_color)
1342 vc->vc_complement_mask <<= 1;
1343 }
1344
1345 if (!*svc->vc_uni_pagedir_loc)
1346 con_set_default_unimap(svc);
1347 if (!*vc->vc_uni_pagedir_loc)
1348 con_copy_unimap(vc, svc);
1349
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001350 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1351 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1352 cols /= vc->vc_font.width;
1353 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001355
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 if (CON_IS_VISIBLE(vc)) {
1357 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001358 if (softback_buf)
1359 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 }
1361}
1362
1363static __inline__ void ywrap_up(struct vc_data *vc, int count)
1364{
1365 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001366 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 struct display *p = &fb_display[vc->vc_num];
1368
1369 p->yscroll += count;
1370 if (p->yscroll >= p->vrows) /* Deal with wrap */
1371 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001372 ops->var.xoffset = 0;
1373 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1374 ops->var.vmode |= FB_VMODE_YWRAP;
1375 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 scrollback_max += count;
1377 if (scrollback_max > scrollback_phys_max)
1378 scrollback_max = scrollback_phys_max;
1379 scrollback_current = 0;
1380}
1381
1382static __inline__ void ywrap_down(struct vc_data *vc, int count)
1383{
1384 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001385 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 struct display *p = &fb_display[vc->vc_num];
1387
1388 p->yscroll -= count;
1389 if (p->yscroll < 0) /* Deal with wrap */
1390 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001391 ops->var.xoffset = 0;
1392 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1393 ops->var.vmode |= FB_VMODE_YWRAP;
1394 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 scrollback_max -= count;
1396 if (scrollback_max < 0)
1397 scrollback_max = 0;
1398 scrollback_current = 0;
1399}
1400
1401static __inline__ void ypan_up(struct vc_data *vc, int count)
1402{
1403 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1404 struct display *p = &fb_display[vc->vc_num];
1405 struct fbcon_ops *ops = info->fbcon_par;
1406
1407 p->yscroll += count;
1408 if (p->yscroll > p->vrows - vc->vc_rows) {
1409 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1410 0, 0, 0, vc->vc_rows, vc->vc_cols);
1411 p->yscroll -= p->vrows - vc->vc_rows;
1412 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001413
1414 ops->var.xoffset = 0;
1415 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1416 ops->var.vmode &= ~FB_VMODE_YWRAP;
1417 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 fbcon_clear_margins(vc, 1);
1419 scrollback_max += count;
1420 if (scrollback_max > scrollback_phys_max)
1421 scrollback_max = scrollback_phys_max;
1422 scrollback_current = 0;
1423}
1424
1425static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1426{
1427 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001428 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 if (p->yscroll > p->vrows - vc->vc_rows) {
1434 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001436 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001437
1438 ops->var.xoffset = 0;
1439 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1440 ops->var.vmode &= ~FB_VMODE_YWRAP;
1441 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 fbcon_clear_margins(vc, 1);
1443 scrollback_max += count;
1444 if (scrollback_max > scrollback_phys_max)
1445 scrollback_max = scrollback_phys_max;
1446 scrollback_current = 0;
1447}
1448
1449static __inline__ void ypan_down(struct vc_data *vc, int count)
1450{
1451 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1452 struct display *p = &fb_display[vc->vc_num];
1453 struct fbcon_ops *ops = info->fbcon_par;
1454
1455 p->yscroll -= count;
1456 if (p->yscroll < 0) {
1457 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1458 0, vc->vc_rows, vc->vc_cols);
1459 p->yscroll += p->vrows - vc->vc_rows;
1460 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001461
1462 ops->var.xoffset = 0;
1463 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1464 ops->var.vmode &= ~FB_VMODE_YWRAP;
1465 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 fbcon_clear_margins(vc, 1);
1467 scrollback_max -= count;
1468 if (scrollback_max < 0)
1469 scrollback_max = 0;
1470 scrollback_current = 0;
1471}
1472
1473static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1474{
1475 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001476 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
1479 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 if (p->yscroll < 0) {
1482 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001484 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001485
1486 ops->var.xoffset = 0;
1487 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1488 ops->var.vmode &= ~FB_VMODE_YWRAP;
1489 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 fbcon_clear_margins(vc, 1);
1491 scrollback_max -= count;
1492 if (scrollback_max < 0)
1493 scrollback_max = 0;
1494 scrollback_current = 0;
1495}
1496
1497static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1498 long delta)
1499{
1500 int count = vc->vc_rows;
1501 unsigned short *d, *s;
1502 unsigned long n;
1503 int line = 0;
1504
1505 d = (u16 *) softback_curr;
1506 if (d == (u16 *) softback_in)
1507 d = (u16 *) vc->vc_origin;
1508 n = softback_curr + delta * vc->vc_size_row;
1509 softback_lines -= delta;
1510 if (delta < 0) {
1511 if (softback_curr < softback_top && n < softback_buf) {
1512 n += softback_end - softback_buf;
1513 if (n < softback_top) {
1514 softback_lines -=
1515 (softback_top - n) / vc->vc_size_row;
1516 n = softback_top;
1517 }
1518 } else if (softback_curr >= softback_top
1519 && n < softback_top) {
1520 softback_lines -=
1521 (softback_top - n) / vc->vc_size_row;
1522 n = softback_top;
1523 }
1524 } else {
1525 if (softback_curr > softback_in && n >= softback_end) {
1526 n += softback_buf - softback_end;
1527 if (n > softback_in) {
1528 n = softback_in;
1529 softback_lines = 0;
1530 }
1531 } else if (softback_curr <= softback_in && n > softback_in) {
1532 n = softback_in;
1533 softback_lines = 0;
1534 }
1535 }
1536 if (n == softback_curr)
1537 return;
1538 softback_curr = n;
1539 s = (u16 *) softback_curr;
1540 if (s == (u16 *) softback_in)
1541 s = (u16 *) vc->vc_origin;
1542 while (count--) {
1543 unsigned short *start;
1544 unsigned short *le;
1545 unsigned short c;
1546 int x = 0;
1547 unsigned short attr = 1;
1548
1549 start = s;
1550 le = advance_row(s, 1);
1551 do {
1552 c = scr_readw(s);
1553 if (attr != (c & 0xff00)) {
1554 attr = c & 0xff00;
1555 if (s > start) {
1556 fbcon_putcs(vc, start, s - start,
1557 line, x);
1558 x += s - start;
1559 start = s;
1560 }
1561 }
1562 if (c == scr_readw(d)) {
1563 if (s > start) {
1564 fbcon_putcs(vc, start, s - start,
1565 line, x);
1566 x += s - start + 1;
1567 start = s + 1;
1568 } else {
1569 x++;
1570 start++;
1571 }
1572 }
1573 s++;
1574 d++;
1575 } while (s < le);
1576 if (s > start)
1577 fbcon_putcs(vc, start, s - start, line, x);
1578 line++;
1579 if (d == (u16 *) softback_end)
1580 d = (u16 *) softback_buf;
1581 if (d == (u16 *) softback_in)
1582 d = (u16 *) vc->vc_origin;
1583 if (s == (u16 *) softback_end)
1584 s = (u16 *) softback_buf;
1585 if (s == (u16 *) softback_in)
1586 s = (u16 *) vc->vc_origin;
1587 }
1588}
1589
1590static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1591 int line, int count, int dy)
1592{
1593 unsigned short *s = (unsigned short *)
1594 (vc->vc_origin + vc->vc_size_row * line);
1595
1596 while (count--) {
1597 unsigned short *start = s;
1598 unsigned short *le = advance_row(s, 1);
1599 unsigned short c;
1600 int x = 0;
1601 unsigned short attr = 1;
1602
1603 do {
1604 c = scr_readw(s);
1605 if (attr != (c & 0xff00)) {
1606 attr = c & 0xff00;
1607 if (s > start) {
1608 fbcon_putcs(vc, start, s - start,
1609 dy, x);
1610 x += s - start;
1611 start = s;
1612 }
1613 }
1614 console_conditional_schedule();
1615 s++;
1616 } while (s < le);
1617 if (s > start)
1618 fbcon_putcs(vc, start, s - start, dy, x);
1619 console_conditional_schedule();
1620 dy++;
1621 }
1622}
1623
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001624static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1625 struct display *p, int line, int count, int ycount)
1626{
1627 int offset = ycount * vc->vc_cols;
1628 unsigned short *d = (unsigned short *)
1629 (vc->vc_origin + vc->vc_size_row * line);
1630 unsigned short *s = d + offset;
1631 struct fbcon_ops *ops = info->fbcon_par;
1632
1633 while (count--) {
1634 unsigned short *start = s;
1635 unsigned short *le = advance_row(s, 1);
1636 unsigned short c;
1637 int x = 0;
1638
1639 do {
1640 c = scr_readw(s);
1641
1642 if (c == scr_readw(d)) {
1643 if (s > start) {
1644 ops->bmove(vc, info, line + ycount, x,
1645 line, x, 1, s-start);
1646 x += s - start + 1;
1647 start = s + 1;
1648 } else {
1649 x++;
1650 start++;
1651 }
1652 }
1653
1654 scr_writew(c, d);
1655 console_conditional_schedule();
1656 s++;
1657 d++;
1658 } while (s < le);
1659 if (s > start)
1660 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1661 s-start);
1662 console_conditional_schedule();
1663 if (ycount > 0)
1664 line++;
1665 else {
1666 line--;
1667 /* NOTE: We subtract two lines from these pointers */
1668 s -= vc->vc_size_row;
1669 d -= vc->vc_size_row;
1670 }
1671 }
1672}
1673
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674static void fbcon_redraw(struct vc_data *vc, struct display *p,
1675 int line, int count, int offset)
1676{
1677 unsigned short *d = (unsigned short *)
1678 (vc->vc_origin + vc->vc_size_row * line);
1679 unsigned short *s = d + offset;
1680
1681 while (count--) {
1682 unsigned short *start = s;
1683 unsigned short *le = advance_row(s, 1);
1684 unsigned short c;
1685 int x = 0;
1686 unsigned short attr = 1;
1687
1688 do {
1689 c = scr_readw(s);
1690 if (attr != (c & 0xff00)) {
1691 attr = c & 0xff00;
1692 if (s > start) {
1693 fbcon_putcs(vc, start, s - start,
1694 line, x);
1695 x += s - start;
1696 start = s;
1697 }
1698 }
1699 if (c == scr_readw(d)) {
1700 if (s > start) {
1701 fbcon_putcs(vc, start, s - start,
1702 line, x);
1703 x += s - start + 1;
1704 start = s + 1;
1705 } else {
1706 x++;
1707 start++;
1708 }
1709 }
1710 scr_writew(c, d);
1711 console_conditional_schedule();
1712 s++;
1713 d++;
1714 } while (s < le);
1715 if (s > start)
1716 fbcon_putcs(vc, start, s - start, line, x);
1717 console_conditional_schedule();
1718 if (offset > 0)
1719 line++;
1720 else {
1721 line--;
1722 /* NOTE: We subtract two lines from these pointers */
1723 s -= vc->vc_size_row;
1724 d -= vc->vc_size_row;
1725 }
1726 }
1727}
1728
1729static inline void fbcon_softback_note(struct vc_data *vc, int t,
1730 int count)
1731{
1732 unsigned short *p;
1733
1734 if (vc->vc_num != fg_console)
1735 return;
1736 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1737
1738 while (count) {
1739 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1740 count--;
1741 p = advance_row(p, 1);
1742 softback_in += vc->vc_size_row;
1743 if (softback_in == softback_end)
1744 softback_in = softback_buf;
1745 if (softback_in == softback_top) {
1746 softback_top += vc->vc_size_row;
1747 if (softback_top == softback_end)
1748 softback_top = softback_buf;
1749 }
1750 }
1751 softback_curr = softback_in;
1752}
1753
1754static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1755 int count)
1756{
1757 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1758 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1760
1761 if (fbcon_is_inactive(vc, info))
1762 return -EINVAL;
1763
1764 fbcon_cursor(vc, CM_ERASE);
1765
1766 /*
1767 * ++Geert: Only use ywrap/ypan if the console is in text mode
1768 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1769 * whole screen (prevents flicker).
1770 */
1771
1772 switch (dir) {
1773 case SM_UP:
1774 if (count > vc->vc_rows) /* Maximum realistic size */
1775 count = vc->vc_rows;
1776 if (softback_top)
1777 fbcon_softback_note(vc, t, count);
1778 if (logo_shown >= 0)
1779 goto redraw_up;
1780 switch (p->scrollmode) {
1781 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001782 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1783 count);
1784 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1785 scr_memsetw((unsigned short *) (vc->vc_origin +
1786 vc->vc_size_row *
1787 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001788 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001789 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001790 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 break;
1792
1793 case SCROLL_WRAP_MOVE:
1794 if (b - t - count > 3 * vc->vc_rows >> 2) {
1795 if (t > 0)
1796 fbcon_bmove(vc, 0, 0, count, 0, t,
1797 vc->vc_cols);
1798 ywrap_up(vc, count);
1799 if (vc->vc_rows - b > 0)
1800 fbcon_bmove(vc, b - count, 0, b, 0,
1801 vc->vc_rows - b,
1802 vc->vc_cols);
1803 } else if (info->flags & FBINFO_READS_FAST)
1804 fbcon_bmove(vc, t + count, 0, t, 0,
1805 b - t - count, vc->vc_cols);
1806 else
1807 goto redraw_up;
1808 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1809 break;
1810
1811 case SCROLL_PAN_REDRAW:
1812 if ((p->yscroll + count <=
1813 2 * (p->vrows - vc->vc_rows))
1814 && ((!scroll_partial && (b - t == vc->vc_rows))
1815 || (scroll_partial
1816 && (b - t - count >
1817 3 * vc->vc_rows >> 2)))) {
1818 if (t > 0)
1819 fbcon_redraw_move(vc, p, 0, t, count);
1820 ypan_up_redraw(vc, t, count);
1821 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001822 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 vc->vc_rows - b, b);
1824 } else
1825 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1826 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1827 break;
1828
1829 case SCROLL_PAN_MOVE:
1830 if ((p->yscroll + count <=
1831 2 * (p->vrows - vc->vc_rows))
1832 && ((!scroll_partial && (b - t == vc->vc_rows))
1833 || (scroll_partial
1834 && (b - t - count >
1835 3 * vc->vc_rows >> 2)))) {
1836 if (t > 0)
1837 fbcon_bmove(vc, 0, 0, count, 0, t,
1838 vc->vc_cols);
1839 ypan_up(vc, count);
1840 if (vc->vc_rows - b > 0)
1841 fbcon_bmove(vc, b - count, 0, b, 0,
1842 vc->vc_rows - b,
1843 vc->vc_cols);
1844 } else if (info->flags & FBINFO_READS_FAST)
1845 fbcon_bmove(vc, t + count, 0, t, 0,
1846 b - t - count, vc->vc_cols);
1847 else
1848 goto redraw_up;
1849 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1850 break;
1851
1852 case SCROLL_REDRAW:
1853 redraw_up:
1854 fbcon_redraw(vc, p, t, b - t - count,
1855 count * vc->vc_cols);
1856 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1857 scr_memsetw((unsigned short *) (vc->vc_origin +
1858 vc->vc_size_row *
1859 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001860 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001862 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 }
1864 break;
1865
1866 case SM_DOWN:
1867 if (count > vc->vc_rows) /* Maximum realistic size */
1868 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001869 if (logo_shown >= 0)
1870 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 switch (p->scrollmode) {
1872 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001873 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1874 -count);
1875 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1876 scr_memsetw((unsigned short *) (vc->vc_origin +
1877 vc->vc_size_row *
1878 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001879 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001880 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001881 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 break;
1883
1884 case SCROLL_WRAP_MOVE:
1885 if (b - t - count > 3 * vc->vc_rows >> 2) {
1886 if (vc->vc_rows - b > 0)
1887 fbcon_bmove(vc, b, 0, b - count, 0,
1888 vc->vc_rows - b,
1889 vc->vc_cols);
1890 ywrap_down(vc, count);
1891 if (t > 0)
1892 fbcon_bmove(vc, count, 0, 0, 0, t,
1893 vc->vc_cols);
1894 } else if (info->flags & FBINFO_READS_FAST)
1895 fbcon_bmove(vc, t, 0, t + count, 0,
1896 b - t - count, vc->vc_cols);
1897 else
1898 goto redraw_down;
1899 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1900 break;
1901
1902 case SCROLL_PAN_MOVE:
1903 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1904 && ((!scroll_partial && (b - t == vc->vc_rows))
1905 || (scroll_partial
1906 && (b - t - count >
1907 3 * vc->vc_rows >> 2)))) {
1908 if (vc->vc_rows - b > 0)
1909 fbcon_bmove(vc, b, 0, b - count, 0,
1910 vc->vc_rows - b,
1911 vc->vc_cols);
1912 ypan_down(vc, count);
1913 if (t > 0)
1914 fbcon_bmove(vc, count, 0, 0, 0, t,
1915 vc->vc_cols);
1916 } else if (info->flags & FBINFO_READS_FAST)
1917 fbcon_bmove(vc, t, 0, t + count, 0,
1918 b - t - count, vc->vc_cols);
1919 else
1920 goto redraw_down;
1921 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1922 break;
1923
1924 case SCROLL_PAN_REDRAW:
1925 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1926 && ((!scroll_partial && (b - t == vc->vc_rows))
1927 || (scroll_partial
1928 && (b - t - count >
1929 3 * vc->vc_rows >> 2)))) {
1930 if (vc->vc_rows - b > 0)
1931 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1932 b - count);
1933 ypan_down_redraw(vc, t, count);
1934 if (t > 0)
1935 fbcon_redraw_move(vc, p, count, t, 0);
1936 } else
1937 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1938 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1939 break;
1940
1941 case SCROLL_REDRAW:
1942 redraw_down:
1943 fbcon_redraw(vc, p, b - 1, b - t - count,
1944 -count * vc->vc_cols);
1945 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1946 scr_memsetw((unsigned short *) (vc->vc_origin +
1947 vc->vc_size_row *
1948 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001949 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001951 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 }
1953 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07001954 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}
1956
1957
1958static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1959 int height, int width)
1960{
1961 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1962 struct display *p = &fb_display[vc->vc_num];
1963
1964 if (fbcon_is_inactive(vc, info))
1965 return;
1966
1967 if (!width || !height)
1968 return;
1969
1970 /* Split blits that cross physical y_wrap case.
1971 * Pathological case involves 4 blits, better to use recursive
1972 * code rather than unrolled case
1973 *
1974 * Recursive invocations don't need to erase the cursor over and
1975 * over again, so we use fbcon_bmove_rec()
1976 */
1977 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
1978 p->vrows - p->yscroll);
1979}
1980
1981static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
1982 int dy, int dx, int height, int width, u_int y_break)
1983{
1984 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1985 struct fbcon_ops *ops = info->fbcon_par;
1986 u_int b;
1987
1988 if (sy < y_break && sy + height > y_break) {
1989 b = y_break - sy;
1990 if (dy < sy) { /* Avoid trashing self */
1991 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1992 y_break);
1993 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1994 height - b, width, y_break);
1995 } else {
1996 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
1997 height - b, width, y_break);
1998 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
1999 y_break);
2000 }
2001 return;
2002 }
2003
2004 if (dy < y_break && dy + height > y_break) {
2005 b = y_break - dy;
2006 if (dy < sy) { /* Avoid trashing self */
2007 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2008 y_break);
2009 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2010 height - b, width, y_break);
2011 } else {
2012 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2013 height - b, width, y_break);
2014 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2015 y_break);
2016 }
2017 return;
2018 }
2019 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2020 height, width);
2021}
2022
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002023static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002024 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 struct vc_data *vc)
2026{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002027 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 int fh = vc->vc_font.height;
2029 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002030 u16 t = 0;
2031 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2032 info->fix.xpanstep);
2033 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2034 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2035 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2036 info->var.xres_virtual);
2037 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2038 divides(ypan, vc->vc_font.height) && vyres > yres;
2039 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2040 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002041 divides(vc->vc_font.height, vyres) &&
2042 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002044 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2045 !(cap & FBINFO_HWACCEL_DISABLED);
2046 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2047 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002049 p->vrows = vyres/fh;
2050 if (yres > (fh * (vc->vc_rows + 1)))
2051 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2052 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 p->vrows--;
2054
2055 if (good_wrap || good_pan) {
2056 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002057 p->scrollmode = good_wrap ?
2058 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 else
2060 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2061 SCROLL_PAN_REDRAW;
2062 } else {
2063 if (reading_fast || (fast_copyarea && !fast_imageblit))
2064 p->scrollmode = SCROLL_MOVE;
2065 else
2066 p->scrollmode = SCROLL_REDRAW;
2067 }
2068}
2069
2070static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002071 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072{
2073 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002074 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 struct display *p = &fb_display[vc->vc_num];
2076 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002077 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002079 virt_w = FBCON_SWAP(ops->rotate, width, height);
2080 virt_h = FBCON_SWAP(ops->rotate, height, width);
2081 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2082 vc->vc_font.height);
2083 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2084 vc->vc_font.width);
2085 var.xres = virt_w * virt_fw;
2086 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 x_diff = info->var.xres - var.xres;
2088 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002089 if (x_diff < 0 || x_diff > virt_fw ||
2090 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002091 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2094 mode = fb_find_best_mode(&var, &info->modelist);
2095 if (mode == NULL)
2096 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002097 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002099
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002100 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
2103 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2104 if (CON_IS_VISIBLE(vc)) {
2105 var.activate = FB_ACTIVATE_NOW |
2106 FB_ACTIVATE_FORCE;
2107 fb_set_var(info, &var);
2108 }
2109 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002110 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 }
2112 updatescrollmode(p, info, vc);
2113 return 0;
2114}
2115
2116static int fbcon_switch(struct vc_data *vc)
2117{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002118 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002119 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct display *p = &fb_display[vc->vc_num];
2121 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002122 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
2124 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002125 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126
2127 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 if (softback_lines)
2129 fbcon_set_origin(vc);
2130 softback_top = softback_curr = softback_in = softback_buf;
2131 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002132 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 }
2134
2135 if (logo_shown >= 0) {
2136 struct vc_data *conp2 = vc_cons[logo_shown].d;
2137
2138 if (conp2->vc_top == logo_lines
2139 && conp2->vc_bottom == conp2->vc_rows)
2140 conp2->vc_top = 0;
2141 logo_shown = FBCON_LOGO_CANSHOW;
2142 }
2143
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002144 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002145 if (prev_console != -1)
2146 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 /*
2148 * FIXME: If we have multiple fbdev's loaded, we need to
2149 * update all info->currcon. Perhaps, we can place this
2150 * in a centralized structure, but this might break some
2151 * drivers.
2152 *
2153 * info->currcon = vc->vc_num;
2154 */
2155 for (i = 0; i < FB_MAX; i++) {
2156 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002157 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002159 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 }
2161 }
2162 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2163 display_to_var(&var, p);
2164 var.activate = FB_ACTIVATE_NOW;
2165
2166 /*
2167 * make sure we don't unnecessarily trip the memcmp()
2168 * in fb_set_var()
2169 */
2170 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002171 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002173 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Knut Petersen39942fd2005-12-12 22:17:19 -08002175 if (old_info != NULL && (old_info != info ||
2176 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002177 if (info->fbops->fb_set_par)
2178 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002179
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002180 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002181 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002182 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002184 if (fbcon_is_inactive(vc, info) ||
2185 ops->blank_state != FB_BLANK_UNBLANK)
2186 fbcon_del_cursor_timer(info);
2187 else
2188 fbcon_add_cursor_timer(info);
2189
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002190 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002191 ops->cursor_reset = 1;
2192
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002193 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002194 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002195 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002198 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002200
2201 if (p->userfont)
2202 charcnt = FNTCHARCNT(vc->vc_font.data);
2203
2204 if (charcnt > 256)
2205 vc->vc_complement_mask <<= 1;
2206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 updatescrollmode(p, info, vc);
2208
2209 switch (p->scrollmode) {
2210 case SCROLL_WRAP_MOVE:
2211 scrollback_phys_max = p->vrows - vc->vc_rows;
2212 break;
2213 case SCROLL_PAN_MOVE:
2214 case SCROLL_PAN_REDRAW:
2215 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2216 if (scrollback_phys_max < 0)
2217 scrollback_phys_max = 0;
2218 break;
2219 default:
2220 scrollback_phys_max = 0;
2221 break;
2222 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002223
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 scrollback_max = 0;
2225 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002226
2227 if (!fbcon_is_inactive(vc, info)) {
2228 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2229 ops->update_start(info);
2230 }
2231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 fbcon_set_palette(vc, color_table);
2233 fbcon_clear_margins(vc, 0);
2234
2235 if (logo_shown == FBCON_LOGO_DRAW) {
2236
2237 logo_shown = fg_console;
2238 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002239 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 update_region(vc,
2241 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2242 vc->vc_size_row * (vc->vc_bottom -
2243 vc->vc_top) / 2);
2244 return 0;
2245 }
2246 return 1;
2247}
2248
2249static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2250 int blank)
2251{
Richard Purdie994efac2007-02-09 09:46:45 +00002252 struct fb_event event;
2253
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 if (blank) {
2255 unsigned short charmask = vc->vc_hi_font_mask ?
2256 0x1ff : 0xff;
2257 unsigned short oldc;
2258
2259 oldc = vc->vc_video_erase_char;
2260 vc->vc_video_erase_char &= charmask;
2261 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2262 vc->vc_video_erase_char = oldc;
2263 }
Richard Purdie994efac2007-02-09 09:46:45 +00002264
2265
2266 event.info = info;
2267 event.data = &blank;
2268 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
2271static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2272{
2273 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2274 struct fbcon_ops *ops = info->fbcon_par;
2275
2276 if (mode_switch) {
2277 struct fb_var_screeninfo var = info->var;
2278
2279 ops->graphics = 1;
2280
2281 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002282 if (info->fbops->fb_save_state)
2283 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2285 fb_set_var(info, &var);
2286 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002287 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002288 } else if (info->fbops->fb_restore_state)
2289 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 }
2291
2292 if (!fbcon_is_inactive(vc, info)) {
2293 if (ops->blank_state != blank) {
2294 ops->blank_state = blank;
2295 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2296 ops->cursor_flash = (!blank);
2297
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002298 if (!(info->flags & FBINFO_MISC_USEREVENT))
2299 if (fb_blank(info, blank))
2300 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 }
2302
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002303 if (!blank)
2304 update_screen(vc);
2305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002307 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002308 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002309 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002310 else
2311 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002312
2313 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314}
2315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2317{
2318 u8 *fontdata = vc->vc_font.data;
2319 u8 *data = font->data;
2320 int i, j;
2321
2322 font->width = vc->vc_font.width;
2323 font->height = vc->vc_font.height;
2324 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2325 if (!font->data)
2326 return 0;
2327
2328 if (font->width <= 8) {
2329 j = vc->vc_font.height;
2330 for (i = 0; i < font->charcount; i++) {
2331 memcpy(data, fontdata, j);
2332 memset(data + j, 0, 32 - j);
2333 data += 32;
2334 fontdata += j;
2335 }
2336 } else if (font->width <= 16) {
2337 j = vc->vc_font.height * 2;
2338 for (i = 0; i < font->charcount; i++) {
2339 memcpy(data, fontdata, j);
2340 memset(data + j, 0, 64 - j);
2341 data += 64;
2342 fontdata += j;
2343 }
2344 } else if (font->width <= 24) {
2345 for (i = 0; i < font->charcount; i++) {
2346 for (j = 0; j < vc->vc_font.height; j++) {
2347 *data++ = fontdata[0];
2348 *data++ = fontdata[1];
2349 *data++ = fontdata[2];
2350 fontdata += sizeof(u32);
2351 }
2352 memset(data, 0, 3 * (32 - j));
2353 data += 3 * (32 - j);
2354 }
2355 } else {
2356 j = vc->vc_font.height * 4;
2357 for (i = 0; i < font->charcount; i++) {
2358 memcpy(data, fontdata, j);
2359 memset(data + j, 0, 128 - j);
2360 data += 128;
2361 fontdata += j;
2362 }
2363 }
2364 return 0;
2365}
2366
2367static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002368 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
2370 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002371 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 struct display *p = &fb_display[vc->vc_num];
2373 int resize;
2374 int cnt;
2375 char *old_data = NULL;
2376
2377 if (CON_IS_VISIBLE(vc) && softback_lines)
2378 fbcon_set_origin(vc);
2379
2380 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2381 if (p->userfont)
2382 old_data = vc->vc_font.data;
2383 if (userfont)
2384 cnt = FNTCHARCNT(data);
2385 else
2386 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002387 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if ((p->userfont = userfont))
2389 REFCOUNT(data)++;
2390 vc->vc_font.width = w;
2391 vc->vc_font.height = h;
2392 if (vc->vc_hi_font_mask && cnt == 256) {
2393 vc->vc_hi_font_mask = 0;
2394 if (vc->vc_can_do_color) {
2395 vc->vc_complement_mask >>= 1;
2396 vc->vc_s_complement_mask >>= 1;
2397 }
2398
2399 /* ++Edmund: reorder the attribute bits */
2400 if (vc->vc_can_do_color) {
2401 unsigned short *cp =
2402 (unsigned short *) vc->vc_origin;
2403 int count = vc->vc_screenbuf_size / 2;
2404 unsigned short c;
2405 for (; count > 0; count--, cp++) {
2406 c = scr_readw(cp);
2407 scr_writew(((c & 0xfe00) >> 1) |
2408 (c & 0xff), cp);
2409 }
2410 c = vc->vc_video_erase_char;
2411 vc->vc_video_erase_char =
2412 ((c & 0xfe00) >> 1) | (c & 0xff);
2413 vc->vc_attr >>= 1;
2414 }
2415 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2416 vc->vc_hi_font_mask = 0x100;
2417 if (vc->vc_can_do_color) {
2418 vc->vc_complement_mask <<= 1;
2419 vc->vc_s_complement_mask <<= 1;
2420 }
2421
2422 /* ++Edmund: reorder the attribute bits */
2423 {
2424 unsigned short *cp =
2425 (unsigned short *) vc->vc_origin;
2426 int count = vc->vc_screenbuf_size / 2;
2427 unsigned short c;
2428 for (; count > 0; count--, cp++) {
2429 unsigned short newc;
2430 c = scr_readw(cp);
2431 if (vc->vc_can_do_color)
2432 newc =
2433 ((c & 0xff00) << 1) | (c &
2434 0xff);
2435 else
2436 newc = c & ~0x100;
2437 scr_writew(newc, cp);
2438 }
2439 c = vc->vc_video_erase_char;
2440 if (vc->vc_can_do_color) {
2441 vc->vc_video_erase_char =
2442 ((c & 0xff00) << 1) | (c & 0xff);
2443 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002444 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 vc->vc_video_erase_char = c & ~0x100;
2446 }
2447
2448 }
2449
2450 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002451 int cols, rows;
2452
2453 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2454 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2455 cols /= w;
2456 rows /= h;
2457 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002458 if (CON_IS_VISIBLE(vc) && softback_buf)
2459 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 } else if (CON_IS_VISIBLE(vc)
2461 && vc->vc_mode == KD_TEXT) {
2462 fbcon_clear_margins(vc, 0);
2463 update_screen(vc);
2464 }
2465
2466 if (old_data && (--REFCOUNT(old_data) == 0))
2467 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2468 return 0;
2469}
2470
2471static int fbcon_copy_font(struct vc_data *vc, int con)
2472{
2473 struct display *od = &fb_display[con];
2474 struct console_font *f = &vc->vc_font;
2475
2476 if (od->fontdata == f->data)
2477 return 0; /* already the same font... */
2478 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2479}
2480
2481/*
2482 * User asked to set font; we are guaranteed that
2483 * a) width and height are in range 1..32
2484 * b) charcount does not exceed 512
2485 * but lets not assume that, since someone might someday want to use larger
2486 * fonts. And charcount of 512 is small for unicode support.
2487 *
2488 * However, user space gives the font in 32 rows , regardless of
2489 * actual font height. So a new API is needed if support for larger fonts
2490 * is ever implemented.
2491 */
2492
2493static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2494{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002495 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 unsigned charcount = font->charcount;
2497 int w = font->width;
2498 int h = font->height;
2499 int size;
2500 int i, csum;
2501 u8 *new_data, *data = font->data;
2502 int pitch = (font->width+7) >> 3;
2503
2504 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2505 * If not this check should be changed to charcount < 256 */
2506 if (charcount != 256 && charcount != 512)
2507 return -EINVAL;
2508
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002509 /* Make sure drawing engine can handle the font */
2510 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2511 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2512 return -EINVAL;
2513
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002514 /* Make sure driver can handle the font length */
2515 if (fbcon_invalid_charcount(info, charcount))
2516 return -EINVAL;
2517
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 size = h * pitch * charcount;
2519
2520 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2521
2522 if (!new_data)
2523 return -ENOMEM;
2524
2525 new_data += FONT_EXTRA_WORDS * sizeof(int);
2526 FNTSIZE(new_data) = size;
2527 FNTCHARCNT(new_data) = charcount;
2528 REFCOUNT(new_data) = 0; /* usage counter */
2529 for (i=0; i< charcount; i++) {
2530 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2531 }
2532
2533 /* Since linux has a nice crc32 function use it for counting font
2534 * checksums. */
2535 csum = crc32(0, new_data, size);
2536
2537 FNTSUM(new_data) = csum;
2538 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002539 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 struct vc_data *tmp = vc_cons[i].d;
2541
2542 if (fb_display[i].userfont &&
2543 fb_display[i].fontdata &&
2544 FNTSUM(fb_display[i].fontdata) == csum &&
2545 FNTSIZE(fb_display[i].fontdata) == size &&
2546 tmp->vc_font.width == w &&
2547 !memcmp(fb_display[i].fontdata, new_data, size)) {
2548 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002549 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 break;
2551 }
2552 }
2553 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2554}
2555
2556static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2557{
2558 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002559 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002562 f = get_default_font(info->var.xres, info->var.yres,
2563 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 else if (!(f = find_font(name)))
2565 return -ENOENT;
2566
2567 font->width = f->width;
2568 font->height = f->height;
2569 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2570}
2571
2572static u16 palette_red[16];
2573static u16 palette_green[16];
2574static u16 palette_blue[16];
2575
2576static struct fb_cmap palette_cmap = {
2577 0, 16, palette_red, palette_green, palette_blue, NULL
2578};
2579
2580static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2581{
2582 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2583 int i, j, k, depth;
2584 u8 val;
2585
2586 if (fbcon_is_inactive(vc, info))
2587 return -EINVAL;
2588
2589 if (!CON_IS_VISIBLE(vc))
2590 return 0;
2591
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002592 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 if (depth > 3) {
2594 for (i = j = 0; i < 16; i++) {
2595 k = table[i];
2596 val = vc->vc_palette[j++];
2597 palette_red[k] = (val << 8) | val;
2598 val = vc->vc_palette[j++];
2599 palette_green[k] = (val << 8) | val;
2600 val = vc->vc_palette[j++];
2601 palette_blue[k] = (val << 8) | val;
2602 }
2603 palette_cmap.len = 16;
2604 palette_cmap.start = 0;
2605 /*
2606 * If framebuffer is capable of less than 16 colors,
2607 * use default palette of fbcon.
2608 */
2609 } else
2610 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2611
2612 return fb_set_cmap(&palette_cmap, info);
2613}
2614
2615static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2616{
2617 unsigned long p;
2618 int line;
2619
2620 if (vc->vc_num != fg_console || !softback_lines)
2621 return (u16 *) (vc->vc_origin + offset);
2622 line = offset / vc->vc_size_row;
2623 if (line >= softback_lines)
2624 return (u16 *) (vc->vc_origin + offset -
2625 softback_lines * vc->vc_size_row);
2626 p = softback_curr + offset;
2627 if (p >= softback_end)
2628 p += softback_buf - softback_end;
2629 return (u16 *) p;
2630}
2631
2632static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2633 int *px, int *py)
2634{
2635 unsigned long ret;
2636 int x, y;
2637
2638 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2639 unsigned long offset = (pos - vc->vc_origin) / 2;
2640
2641 x = offset % vc->vc_cols;
2642 y = offset / vc->vc_cols;
2643 if (vc->vc_num == fg_console)
2644 y += softback_lines;
2645 ret = pos + (vc->vc_cols - x) * 2;
2646 } else if (vc->vc_num == fg_console && softback_lines) {
2647 unsigned long offset = pos - softback_curr;
2648
2649 if (pos < softback_curr)
2650 offset += softback_end - softback_buf;
2651 offset /= 2;
2652 x = offset % vc->vc_cols;
2653 y = offset / vc->vc_cols;
2654 ret = pos + (vc->vc_cols - x) * 2;
2655 if (ret == softback_end)
2656 ret = softback_buf;
2657 if (ret == softback_in)
2658 ret = vc->vc_origin;
2659 } else {
2660 /* Should not happen */
2661 x = y = 0;
2662 ret = vc->vc_origin;
2663 }
2664 if (px)
2665 *px = x;
2666 if (py)
2667 *py = y;
2668 return ret;
2669}
2670
2671/* As we might be inside of softback, we may work with non-contiguous buffer,
2672 that's why we have to use a separate routine. */
2673static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2674{
2675 while (cnt--) {
2676 u16 a = scr_readw(p);
2677 if (!vc->vc_can_do_color)
2678 a ^= 0x0800;
2679 else if (vc->vc_hi_font_mask == 0x100)
2680 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2681 (((a) & 0x0e00) << 4);
2682 else
2683 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2684 (((a) & 0x0700) << 4);
2685 scr_writew(a, p++);
2686 if (p == (u16 *) softback_end)
2687 p = (u16 *) softback_buf;
2688 if (p == (u16 *) softback_in)
2689 p = (u16 *) vc->vc_origin;
2690 }
2691}
2692
2693static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2694{
2695 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002696 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002697 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 int offset, limit, scrollback_old;
2699
2700 if (softback_top) {
2701 if (vc->vc_num != fg_console)
2702 return 0;
2703 if (vc->vc_mode != KD_TEXT || !lines)
2704 return 0;
2705 if (logo_shown >= 0) {
2706 struct vc_data *conp2 = vc_cons[logo_shown].d;
2707
2708 if (conp2->vc_top == logo_lines
2709 && conp2->vc_bottom == conp2->vc_rows)
2710 conp2->vc_top = 0;
2711 if (logo_shown == vc->vc_num) {
2712 unsigned long p, q;
2713 int i;
2714
2715 p = softback_in;
2716 q = vc->vc_origin +
2717 logo_lines * vc->vc_size_row;
2718 for (i = 0; i < logo_lines; i++) {
2719 if (p == softback_top)
2720 break;
2721 if (p == softback_buf)
2722 p = softback_end;
2723 p -= vc->vc_size_row;
2724 q -= vc->vc_size_row;
2725 scr_memcpyw((u16 *) q, (u16 *) p,
2726 vc->vc_size_row);
2727 }
David Hollister308af922006-05-30 21:25:36 -07002728 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 update_region(vc, vc->vc_origin,
2730 logo_lines * vc->vc_cols);
2731 }
2732 logo_shown = FBCON_LOGO_CANSHOW;
2733 }
2734 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002735 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2737 return 0;
2738 }
2739
2740 if (!scrollback_phys_max)
2741 return -ENOSYS;
2742
2743 scrollback_old = scrollback_current;
2744 scrollback_current -= lines;
2745 if (scrollback_current < 0)
2746 scrollback_current = 0;
2747 else if (scrollback_current > scrollback_max)
2748 scrollback_current = scrollback_max;
2749 if (scrollback_current == scrollback_old)
2750 return 0;
2751
2752 if (fbcon_is_inactive(vc, info))
2753 return 0;
2754
2755 fbcon_cursor(vc, CM_ERASE);
2756
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002757 offset = disp->yscroll - scrollback_current;
2758 limit = disp->vrows;
2759 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 case SCROLL_WRAP_MOVE:
2761 info->var.vmode |= FB_VMODE_YWRAP;
2762 break;
2763 case SCROLL_PAN_MOVE:
2764 case SCROLL_PAN_REDRAW:
2765 limit -= vc->vc_rows;
2766 info->var.vmode &= ~FB_VMODE_YWRAP;
2767 break;
2768 }
2769 if (offset < 0)
2770 offset += limit;
2771 else if (offset >= limit)
2772 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002773
2774 ops->var.xoffset = 0;
2775 ops->var.yoffset = offset * vc->vc_font.height;
2776 ops->update_start(info);
2777
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 if (!scrollback_current)
2779 fbcon_cursor(vc, CM_DRAW);
2780 return 0;
2781}
2782
2783static int fbcon_set_origin(struct vc_data *vc)
2784{
2785 if (softback_lines)
2786 fbcon_scrolldelta(vc, softback_lines);
2787 return 0;
2788}
2789
2790static void fbcon_suspended(struct fb_info *info)
2791{
2792 struct vc_data *vc = NULL;
2793 struct fbcon_ops *ops = info->fbcon_par;
2794
2795 if (!ops || ops->currcon < 0)
2796 return;
2797 vc = vc_cons[ops->currcon].d;
2798
2799 /* Clear cursor, restore saved data */
2800 fbcon_cursor(vc, CM_ERASE);
2801}
2802
2803static void fbcon_resumed(struct fb_info *info)
2804{
2805 struct vc_data *vc;
2806 struct fbcon_ops *ops = info->fbcon_par;
2807
2808 if (!ops || ops->currcon < 0)
2809 return;
2810 vc = vc_cons[ops->currcon].d;
2811
2812 update_screen(vc);
2813}
2814
2815static void fbcon_modechanged(struct fb_info *info)
2816{
2817 struct fbcon_ops *ops = info->fbcon_par;
2818 struct vc_data *vc;
2819 struct display *p;
2820 int rows, cols;
2821
2822 if (!ops || ops->currcon < 0)
2823 return;
2824 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002825 if (vc->vc_mode != KD_TEXT ||
2826 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 return;
2828
2829 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002830 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831
2832 if (CON_IS_VISIBLE(vc)) {
2833 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002834 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2835 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2836 cols /= vc->vc_font.width;
2837 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 vc_resize(vc, cols, rows);
2839 updatescrollmode(p, info, vc);
2840 scrollback_max = 0;
2841 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002842
2843 if (!fbcon_is_inactive(vc, info)) {
2844 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2845 ops->update_start(info);
2846 }
2847
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 fbcon_set_palette(vc, color_table);
2849 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002850 if (softback_buf)
2851 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 }
2853}
2854
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002855static void fbcon_set_all_vcs(struct fb_info *info)
2856{
2857 struct fbcon_ops *ops = info->fbcon_par;
2858 struct vc_data *vc;
2859 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002860 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002861
2862 if (!ops || ops->currcon < 0)
2863 return;
2864
Antonino A. Daplase614b182006-06-26 00:27:09 -07002865 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002866 vc = vc_cons[i].d;
2867 if (!vc || vc->vc_mode != KD_TEXT ||
2868 registered_fb[con2fb_map[i]] != info)
2869 continue;
2870
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002871 if (CON_IS_VISIBLE(vc)) {
2872 fg = i;
2873 continue;
2874 }
2875
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002876 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002877 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002878 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002879 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2880 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002881 cols /= vc->vc_font.width;
2882 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002883 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002884 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002885
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002886 if (fg != -1)
2887 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002888}
2889
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890static int fbcon_mode_deleted(struct fb_info *info,
2891 struct fb_videomode *mode)
2892{
2893 struct fb_info *fb_info;
2894 struct display *p;
2895 int i, j, found = 0;
2896
2897 /* before deletion, ensure that mode is not in use */
2898 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2899 j = con2fb_map[i];
2900 if (j == -1)
2901 continue;
2902 fb_info = registered_fb[j];
2903 if (fb_info != info)
2904 continue;
2905 p = &fb_display[i];
2906 if (!p || !p->mode)
2907 continue;
2908 if (fb_mode_is_equal(p->mode, mode)) {
2909 found = 1;
2910 break;
2911 }
2912 }
2913 return found;
2914}
2915
Jesse Barnescfafca82007-07-17 04:05:33 -07002916#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2917static int fbcon_unbind(void)
2918{
2919 int ret;
2920
2921 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2922 fbcon_is_default);
2923 return ret;
2924}
2925#else
2926static inline int fbcon_unbind(void)
2927{
2928 return -EINVAL;
2929}
2930#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
2931
2932static int fbcon_fb_unbind(int idx)
2933{
2934 int i, new_idx = -1, ret = 0;
2935
2936 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2937 if (con2fb_map[i] != idx &&
2938 con2fb_map[i] != -1) {
2939 new_idx = i;
2940 break;
2941 }
2942 }
2943
2944 if (new_idx != -1) {
2945 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2946 if (con2fb_map[i] == idx)
2947 set_con2fb_map(i, new_idx, 0);
2948 }
2949 } else
2950 ret = fbcon_unbind();
2951
2952 return ret;
2953}
2954
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002955static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07002956{
Andrea Righi66c1ca02009-03-31 15:25:18 -07002957 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07002958
Andrea Righi66c1ca02009-03-31 15:25:18 -07002959 if (!lock_fb_info(info))
2960 return -ENODEV;
2961 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07002962 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2963 if (con2fb_map[i] == idx)
2964 con2fb_map[i] = -1;
2965 }
2966
2967 if (idx == info_idx) {
2968 info_idx = -1;
2969
2970 for (i = 0; i < FB_MAX; i++) {
2971 if (registered_fb[i] != NULL) {
2972 info_idx = i;
2973 break;
2974 }
2975 }
2976 }
2977
2978 if (info_idx != -1) {
2979 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2980 if (con2fb_map[i] == -1)
2981 con2fb_map[i] = info_idx;
2982 }
2983 }
2984
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002985 if (primary_device == idx)
2986 primary_device = -1;
2987
Andrea Righi66c1ca02009-03-31 15:25:18 -07002988 unlock_fb_info(info);
2989
2990 if (!num_registered_fb)
2991 unregister_con_driver(&fb_con);
2992
Antonino A. Daplase614b182006-06-26 00:27:09 -07002993 return 0;
2994}
2995
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002996#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07002997static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07002999 if (!map_override && primary_device == -1 &&
3000 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003001 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003002
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003003 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3004 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003005 primary_device = info->node;
3006
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003007 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003008 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003009
3010 if (con_is_bound(&fb_con)) {
3011 printk(KERN_INFO "fbcon: Remapping primary device, "
3012 "fb%i, to tty %i-%i\n", info->node,
3013 first_fb_vc + 1, last_fb_vc + 1);
3014 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003015 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003016 }
3017
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003018}
3019#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003020static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003021{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003022 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003023}
3024#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3025
3026static int fbcon_fb_registered(struct fb_info *info)
3027{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003028 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003029
Andrea Righi66c1ca02009-03-31 15:25:18 -07003030 if (!lock_fb_info(info))
3031 return -ENODEV;
3032 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003033 fbcon_select_primary(info);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003034 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
3036 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003037 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 if (con2fb_map_boot[i] == idx) {
3039 info_idx = idx;
3040 break;
3041 }
3042 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003043
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 if (info_idx != -1)
3045 ret = fbcon_takeover(1);
3046 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003047 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003048 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 set_con2fb_map(i, idx, 0);
3050 }
3051 }
3052
3053 return ret;
3054}
3055
3056static void fbcon_fb_blanked(struct fb_info *info, int blank)
3057{
3058 struct fbcon_ops *ops = info->fbcon_par;
3059 struct vc_data *vc;
3060
3061 if (!ops || ops->currcon < 0)
3062 return;
3063
3064 vc = vc_cons[ops->currcon].d;
3065 if (vc->vc_mode != KD_TEXT ||
3066 registered_fb[con2fb_map[ops->currcon]] != info)
3067 return;
3068
3069 if (CON_IS_VISIBLE(vc)) {
3070 if (blank)
3071 do_blank_screen(0);
3072 else
3073 do_unblank_screen(0);
3074 }
3075 ops->blank_state = blank;
3076}
3077
3078static void fbcon_new_modelist(struct fb_info *info)
3079{
3080 int i;
3081 struct vc_data *vc;
3082 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003083 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
Antonino A. Daplase614b182006-06-26 00:27:09 -07003085 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 if (registered_fb[con2fb_map[i]] != info)
3087 continue;
3088 if (!fb_display[i].mode)
3089 continue;
3090 vc = vc_cons[i].d;
3091 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003092 mode = fb_find_nearest_mode(fb_display[i].mode,
3093 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003095 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 }
3097}
3098
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003099static void fbcon_get_requirement(struct fb_info *info,
3100 struct fb_blit_caps *caps)
3101{
3102 struct vc_data *vc;
3103 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003104
3105 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003106 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003107
3108 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3109 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003110 if (vc && vc->vc_mode == KD_TEXT &&
3111 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003112 p = &fb_display[i];
3113 caps->x |= 1 << (vc->vc_font.width - 1);
3114 caps->y |= 1 << (vc->vc_font.height - 1);
3115 charcnt = (p->userfont) ?
3116 FNTCHARCNT(p->fontdata) : 256;
3117 if (caps->len < charcnt)
3118 caps->len = charcnt;
3119 }
3120 }
3121 } else {
3122 vc = vc_cons[fg_console].d;
3123
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003124 if (vc && vc->vc_mode == KD_TEXT &&
3125 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003126 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003127 caps->x = 1 << (vc->vc_font.width - 1);
3128 caps->y = 1 << (vc->vc_font.height - 1);
3129 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003130 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003131 }
3132 }
3133}
3134
Andrea Righi66c1ca02009-03-31 15:25:18 -07003135static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 unsigned long action, void *data)
3137{
3138 struct fb_event *event = data;
3139 struct fb_info *info = event->info;
3140 struct fb_videomode *mode;
3141 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003142 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003143 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144
Antonino A. Daplase614b182006-06-26 00:27:09 -07003145 /*
3146 * ignore all events except driver registration and deregistration
3147 * if fbcon is not active
3148 */
3149 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3150 action == FB_EVENT_FB_UNREGISTERED))
3151 goto done;
3152
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 switch(action) {
3154 case FB_EVENT_SUSPEND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003155 if (!lock_fb_info(info)) {
3156 ret = -ENODEV;
3157 goto done;
3158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 fbcon_suspended(info);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003160 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 break;
3162 case FB_EVENT_RESUME:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003163 if (!lock_fb_info(info)) {
3164 ret = -ENODEV;
3165 goto done;
3166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 fbcon_resumed(info);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003168 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 break;
3170 case FB_EVENT_MODE_CHANGE:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003171 if (!lock_fb_info(info)) {
3172 ret = -ENODEV;
3173 goto done;
3174 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 fbcon_modechanged(info);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003176 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003178 case FB_EVENT_MODE_CHANGE_ALL:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003179 if (!lock_fb_info(info)) {
3180 ret = -ENODEV;
3181 goto done;
3182 }
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003183 fbcon_set_all_vcs(info);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003184 unlock_fb_info(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003185 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 case FB_EVENT_MODE_DELETE:
3187 mode = event->data;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003188 if (!lock_fb_info(info)) {
3189 ret = -ENODEV;
3190 goto done;
3191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 ret = fbcon_mode_deleted(info, mode);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003193 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003195 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003196 if (!lock_fb_info(info)) {
3197 ret = -ENODEV;
3198 goto done;
3199 }
3200 idx = info->node;
3201 unlock_fb_info(info);
3202 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003205 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003207 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003208 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003209 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 case FB_EVENT_SET_CONSOLE_MAP:
3211 con2fb = event->data;
3212 ret = set_con2fb_map(con2fb->console - 1,
3213 con2fb->framebuffer, 1);
3214 break;
3215 case FB_EVENT_GET_CONSOLE_MAP:
3216 con2fb = event->data;
3217 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3218 break;
3219 case FB_EVENT_BLANK:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003220 if (!lock_fb_info(info)) {
3221 ret = -ENODEV;
3222 goto done;
3223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 fbcon_fb_blanked(info, *(int *)event->data);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003225 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 break;
3227 case FB_EVENT_NEW_MODELIST:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003228 if (!lock_fb_info(info)) {
3229 ret = -ENODEV;
3230 goto done;
3231 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 fbcon_new_modelist(info);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003233 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003235 case FB_EVENT_GET_REQ:
3236 caps = event->data;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003237 if (!lock_fb_info(info)) {
3238 ret = -ENODEV;
3239 goto done;
3240 }
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003241 fbcon_get_requirement(info, caps);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003242 unlock_fb_info(info);
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003243 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003245done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 return ret;
3247}
3248
3249/*
3250 * The console `switch' structure for the frame buffer based console
3251 */
3252
3253static const struct consw fb_con = {
3254 .owner = THIS_MODULE,
3255 .con_startup = fbcon_startup,
3256 .con_init = fbcon_init,
3257 .con_deinit = fbcon_deinit,
3258 .con_clear = fbcon_clear,
3259 .con_putc = fbcon_putc,
3260 .con_putcs = fbcon_putcs,
3261 .con_cursor = fbcon_cursor,
3262 .con_scroll = fbcon_scroll,
3263 .con_bmove = fbcon_bmove,
3264 .con_switch = fbcon_switch,
3265 .con_blank = fbcon_blank,
3266 .con_font_set = fbcon_set_font,
3267 .con_font_get = fbcon_get_font,
3268 .con_font_default = fbcon_set_def_font,
3269 .con_font_copy = fbcon_copy_font,
3270 .con_set_palette = fbcon_set_palette,
3271 .con_scrolldelta = fbcon_scrolldelta,
3272 .con_set_origin = fbcon_set_origin,
3273 .con_invert_region = fbcon_invert_region,
3274 .con_screen_pos = fbcon_screen_pos,
3275 .con_getxy = fbcon_getxy,
3276 .con_resize = fbcon_resize,
3277};
3278
3279static struct notifier_block fbcon_event_notifier = {
3280 .notifier_call = fbcon_event_notify,
3281};
3282
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003283static ssize_t store_rotate(struct device *device,
3284 struct device_attribute *attr, const char *buf,
3285 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003286{
3287 struct fb_info *info;
3288 int rotate, idx;
3289 char **last = NULL;
3290
Antonino A. Daplase614b182006-06-26 00:27:09 -07003291 if (fbcon_has_exited)
3292 return count;
3293
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003294 acquire_console_sem();
3295 idx = con2fb_map[fg_console];
3296
3297 if (idx == -1 || registered_fb[idx] == NULL)
3298 goto err;
3299
3300 info = registered_fb[idx];
3301 rotate = simple_strtoul(buf, last, 0);
3302 fbcon_rotate(info, rotate);
3303err:
3304 release_console_sem();
3305 return count;
3306}
3307
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003308static ssize_t store_rotate_all(struct device *device,
3309 struct device_attribute *attr,const char *buf,
3310 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003311{
3312 struct fb_info *info;
3313 int rotate, idx;
3314 char **last = NULL;
3315
Antonino A. Daplase614b182006-06-26 00:27:09 -07003316 if (fbcon_has_exited)
3317 return count;
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 = simple_strtoul(buf, last, 0);
3327 fbcon_rotate_all(info, rotate);
3328err:
3329 release_console_sem();
3330 return count;
3331}
3332
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003333static ssize_t show_rotate(struct device *device,
3334 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003335{
3336 struct fb_info *info;
3337 int rotate = 0, idx;
3338
Antonino A. Daplase614b182006-06-26 00:27:09 -07003339 if (fbcon_has_exited)
3340 return 0;
3341
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003342 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 rotate = fbcon_get_rotate(info);
3350err:
3351 release_console_sem();
3352 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3353}
3354
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003355static ssize_t show_cursor_blink(struct device *device,
3356 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003357{
3358 struct fb_info *info;
3359 struct fbcon_ops *ops;
3360 int idx, blink = -1;
3361
3362 if (fbcon_has_exited)
3363 return 0;
3364
3365 acquire_console_sem();
3366 idx = con2fb_map[fg_console];
3367
3368 if (idx == -1 || registered_fb[idx] == NULL)
3369 goto err;
3370
3371 info = registered_fb[idx];
3372 ops = info->fbcon_par;
3373
3374 if (!ops)
3375 goto err;
3376
3377 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3378err:
3379 release_console_sem();
3380 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3381}
3382
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003383static ssize_t store_cursor_blink(struct device *device,
3384 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003385 const char *buf, size_t count)
3386{
3387 struct fb_info *info;
3388 int blink, idx;
3389 char **last = NULL;
3390
3391 if (fbcon_has_exited)
3392 return count;
3393
3394 acquire_console_sem();
3395 idx = con2fb_map[fg_console];
3396
3397 if (idx == -1 || registered_fb[idx] == NULL)
3398 goto err;
3399
3400 info = registered_fb[idx];
3401
3402 if (!info->fbcon_par)
3403 goto err;
3404
3405 blink = simple_strtoul(buf, last, 0);
3406
3407 if (blink) {
3408 fbcon_cursor_noblink = 0;
3409 fbcon_add_cursor_timer(info);
3410 } else {
3411 fbcon_cursor_noblink = 1;
3412 fbcon_del_cursor_timer(info);
3413 }
3414
3415err:
3416 release_console_sem();
3417 return count;
3418}
3419
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003420static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003421 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3422 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003423 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3424 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003425};
3426
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003427static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003428{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003429 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003430
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003431 fbcon_has_sysfs = 1;
3432
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003433 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3434 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003435
3436 if (error)
3437 break;
3438 }
3439
3440 if (error) {
3441 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003442 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003443
3444 fbcon_has_sysfs = 0;
3445 }
3446
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003447 return 0;
3448}
3449
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003450static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003453 int i;
3454
3455 acquire_console_sem();
3456
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 for (i = 0; i < FB_MAX; i++) {
3458 if (registered_fb[i] != NULL) {
3459 info_idx = i;
3460 break;
3461 }
3462 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003463
3464 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 fbcon_takeover(0);
3466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467}
3468
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003469static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003470{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003471 struct fb_info *info;
3472 int i, j, mapped;
3473
Antonino A. Daplase614b182006-06-26 00:27:09 -07003474 if (fbcon_has_exited)
3475 return;
3476
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003477 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003478 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003479
3480 for (i = 0; i < FB_MAX; i++) {
Geoff Levandbeaa4862008-12-09 13:14:17 -08003481 int pending;
3482
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003483 mapped = 0;
3484 info = registered_fb[i];
3485
3486 if (info == NULL)
3487 continue;
3488
Geoff Levandbeaa4862008-12-09 13:14:17 -08003489 pending = cancel_work_sync(&info->queue);
3490 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3491 "no"));
3492
Antonino A. Daplase614b182006-06-26 00:27:09 -07003493 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3494 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003495 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003496 }
3497
3498 if (mapped) {
3499 if (info->fbops->fb_release)
3500 info->fbops->fb_release(info, 0);
3501 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003502
3503 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003504 struct fbcon_ops *ops = info->fbcon_par;
3505
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003506 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003507 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003508 kfree(info->fbcon_par);
3509 info->fbcon_par = NULL;
3510 }
3511
3512 if (info->queue.func == fb_flashcursor)
3513 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003514 }
3515 }
3516
Antonino A. Daplase614b182006-06-26 00:27:09 -07003517 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003518}
3519
3520static int __init fb_console_init(void)
3521{
3522 int i;
3523
3524 acquire_console_sem();
3525 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003526 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3527 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003528
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003529 if (IS_ERR(fbcon_device)) {
3530 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003531 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003532 PTR_ERR(fbcon_device));
3533 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003534 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003535 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003536
3537 for (i = 0; i < MAX_NR_CONSOLES; i++)
3538 con2fb_map[i] = -1;
3539
3540 release_console_sem();
3541 fbcon_start();
3542 return 0;
3543}
3544
3545module_init(fb_console_init);
3546
3547#ifdef MODULE
3548
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003549static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003550{
3551 int i;
3552
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003553 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003554 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3555 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003556
3557 fbcon_has_sysfs = 0;
3558 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003559}
3560
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561static void __exit fb_console_exit(void)
3562{
3563 acquire_console_sem();
3564 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003565 fbcon_deinit_device();
3566 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003567 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003569 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570}
3571
3572module_exit(fb_console_exit);
3573
3574#endif
3575
3576MODULE_LICENSE("GPL");