blob: f8a61e210d2e63469d3196a97aee5cb704e9f940 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81#include "fbcon.h"
82
83#ifdef FBCONDEBUG
Harvey Harrison5ae12172008-04-28 02:15:47 -070084# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __func__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#else
86# define DPRINTK(fmt, args...)
87#endif
88
89enum {
90 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
91 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
92 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
93};
94
Antonino A. Daplasab767202005-11-13 16:06:32 -080095static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -080096
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static signed char con2fb_map[MAX_NR_CONSOLES];
98static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Krzysztof Helt49a1d282008-07-23 21:31:21 -070099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100static int logo_lines;
101/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
102 enums. */
103static int logo_shown = FBCON_LOGO_CANSHOW;
104/* Software scrollback */
105static int fbcon_softback_size = 32768;
106static unsigned long softback_buf, softback_curr;
107static unsigned long softback_in;
108static unsigned long softback_top, softback_end;
109static int softback_lines;
110/* console mappings */
111static int first_fb_vc;
112static int last_fb_vc = MAX_NR_CONSOLES - 1;
113static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700114static int fbcon_has_exited;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700115static int primary_device = -1;
Ian Armstrong2ddce3f2009-09-22 16:47:52 -0700116static int fbcon_has_console_bind;
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 ||
Jesse Barnes8fd4bd22010-06-23 12:56:12 -0700285 vc->vc_mode != KD_TEXT || ops->graphics) &&
286 !vt_force_oops_output(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}
288
Denys Vlasenkoda909ce2010-08-10 18:02:29 -0700289static int get_color(struct vc_data *vc, struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 u16 c, int is_fg)
291{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700292 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 int color = 0;
294
295 if (console_blanked) {
296 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
297
298 c = vc->vc_video_erase_char & charmask;
299 }
300
301 if (depth != 1)
302 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
303 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
304
305 switch (depth) {
306 case 1:
307 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800308 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700310 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
311 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 if (console_blanked)
314 fg = bg;
315
316 color = (is_fg) ? fg : bg;
317 break;
318 }
319 case 2:
320 /*
321 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700322 * is grayscale. However, simply dividing the values by 4
323 * will not work, as colors 1, 2 and 3 will be scaled-down
324 * to zero rendering them invisible. So empirically convert
325 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700327 switch (color) {
328 case 0:
329 color = 0; /* black */
330 break;
331 case 1 ... 6:
332 color = 2; /* white */
333 break;
334 case 7 ... 8:
335 color = 1; /* gray */
336 break;
337 default:
338 color = 3; /* intense white */
339 break;
340 }
341 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 case 3:
343 /*
344 * Last 8 entries of default 16-color palette is a more intense
345 * version of the first 8 (i.e., same chrominance, different
346 * luminance).
347 */
348 color &= 7;
349 break;
350 }
351
352
353 return color;
354}
355
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800356static void fbcon_update_softback(struct vc_data *vc)
357{
358 int l = fbcon_softback_size / vc->vc_size_row;
359
360 if (l > 5)
361 softback_end = softback_buf + l * vc->vc_size_row;
362 else
363 /* Smaller scrollback makes no sense, and 0 would screw
364 the operation totally */
365 softback_top = 0;
366}
367
David Howellsc4028952006-11-22 14:57:56 +0000368static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
David Howellsc4028952006-11-22 14:57:56 +0000370 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 struct vc_data *vc = NULL;
373 int c;
374 int mode;
Dave Airlied8636a22012-08-21 16:29:47 +1000375 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Dave Airlied8636a22012-08-21 16:29:47 +1000377 /* FIXME: we should sort out the unbind locking instead */
378 /* instead we just fail to flash the cursor if we can't get
379 * the lock instead of blocking fbcon deinit */
380 ret = console_trylock();
381 if (ret == 0)
382 return;
383
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700384 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 vc = vc_cons[ops->currcon].d;
386
387 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700388 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700389 vc->vc_deccm != 1) {
Torben Hohnac751ef2011-01-25 15:07:35 -0800390 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700392 }
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 c = scr_readw((u16 *) vc->vc_pos);
395 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
396 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800397 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 get_color(vc, info, c, 0));
Torben Hohnac751ef2011-01-25 15:07:35 -0800399 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402static void cursor_timer_handler(unsigned long dev_addr)
403{
404 struct fb_info *info = (struct fb_info *) dev_addr;
405 struct fbcon_ops *ops = info->fbcon_par;
406
407 schedule_work(&info->queue);
408 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
409}
410
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700411static void fbcon_add_cursor_timer(struct fb_info *info)
412{
413 struct fbcon_ops *ops = info->fbcon_par;
414
415 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700416 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
417 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700418 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000419 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700420
421 init_timer(&ops->cursor_timer);
422 ops->cursor_timer.function = cursor_timer_handler;
423 ops->cursor_timer.expires = jiffies + HZ / 5;
424 ops->cursor_timer.data = (unsigned long ) info;
425 add_timer(&ops->cursor_timer);
426 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
427 }
428}
429
430static void fbcon_del_cursor_timer(struct fb_info *info)
431{
432 struct fbcon_ops *ops = info->fbcon_par;
433
434 if (info->queue.func == fb_flashcursor &&
435 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
436 del_timer_sync(&ops->cursor_timer);
437 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
438 }
439}
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#ifndef MODULE
442static int __init fb_console_setup(char *this_opt)
443{
444 char *options;
445 int i, j;
446
447 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800448 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 while ((options = strsep(&this_opt, ",")) != NULL) {
451 if (!strncmp(options, "font:", 5))
Paul Cercueile4329642012-07-24 03:00:24 +0200452 strlcpy(fontname, options + 5, sizeof(fontname));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 if (!strncmp(options, "scrollback:", 11)) {
455 options += 11;
456 if (*options) {
457 fbcon_softback_size = simple_strtoul(options, &options, 0);
458 if (*options == 'k' || *options == 'K') {
459 fbcon_softback_size *= 1024;
460 options++;
461 }
462 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800463 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 options++;
465 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800466 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
469 if (!strncmp(options, "map:", 4)) {
470 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700471 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
473 if (!options[j])
474 j = 0;
475 con2fb_map_boot[i] =
476 (options[j++]-'0') % FB_MAX;
477 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700478
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700479 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700480 }
481
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800482 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
484
485 if (!strncmp(options, "vc:", 3)) {
486 options += 3;
487 if (*options)
488 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
489 if (first_fb_vc < 0)
490 first_fb_vc = 0;
491 if (*options++ == '-')
492 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
493 fbcon_is_default = 0;
494 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800495
496 if (!strncmp(options, "rotate:", 7)) {
497 options += 7;
498 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800499 initial_rotation = simple_strtoul(options, &options, 0);
500 if (initial_rotation > 3)
501 initial_rotation = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800504 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
507__setup("fbcon=", fb_console_setup);
508#endif
509
510static int search_fb_in_map(int idx)
511{
512 int i, retval = 0;
513
Antonino A. Daplase614b182006-06-26 00:27:09 -0700514 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (con2fb_map[i] == idx)
516 retval = 1;
517 }
518 return retval;
519}
520
521static int search_for_mapped_con(void)
522{
523 int i, retval = 0;
524
Antonino A. Daplase614b182006-06-26 00:27:09 -0700525 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (con2fb_map[i] != -1)
527 retval = 1;
528 }
529 return retval;
530}
531
532static int fbcon_takeover(int show_logo)
533{
534 int err, i;
535
536 if (!num_registered_fb)
537 return -ENODEV;
538
539 if (!show_logo)
540 logo_shown = FBCON_LOGO_DONTSHOW;
541
542 for (i = first_fb_vc; i <= last_fb_vc; i++)
543 con2fb_map[i] = info_idx;
544
545 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
546 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 if (err) {
549 for (i = first_fb_vc; i <= last_fb_vc; i++) {
550 con2fb_map[i] = -1;
551 }
552 info_idx = -1;
Ian Armstrong2ddce3f2009-09-22 16:47:52 -0700553 } else {
554 fbcon_has_console_bind = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556
557 return err;
558}
559
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700560#ifdef MODULE
561static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
562 int cols, int rows, int new_cols, int new_rows)
563{
564 logo_shown = FBCON_LOGO_DONTSHOW;
565}
566#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
568 int cols, int rows, int new_cols, int new_rows)
569{
570 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800571 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 int cnt, erase = vc->vc_video_erase_char, step;
573 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700574 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700576 if (info->flags & FBINFO_MODULE) {
577 logo_shown = FBCON_LOGO_DONTSHOW;
578 return;
579 }
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 /*
582 * remove underline attribute from erase character
583 * if black and white framebuffer.
584 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700585 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800587 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700588 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 q = (unsigned short *) (vc->vc_origin +
590 vc->vc_size_row * rows);
591 step = logo_lines * cols;
592 for (r = q - logo_lines * cols; r < q; r++)
593 if (scr_readw(r) != vc->vc_video_erase_char)
594 break;
595 if (r != q && new_rows >= rows + logo_lines) {
596 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
597 if (save) {
598 int i = cols < new_cols ? cols : new_cols;
599 scr_memsetw(save, erase, logo_lines * new_cols * 2);
600 r = q - step;
601 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
602 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
603 r = q;
604 }
605 }
606 if (r == q) {
607 /* We can scroll screen down */
608 r = q - step - cols;
609 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
610 scr_memcpyw(r + step, r, vc->vc_size_row);
611 r -= cols;
612 }
613 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700614 int lines;
615 if (vc->vc_y + logo_lines >= rows)
616 lines = rows - vc->vc_y - 1;
617 else
618 lines = logo_lines;
619 vc->vc_y += lines;
620 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622 }
623 scr_memsetw((unsigned short *) vc->vc_origin,
624 erase,
625 vc->vc_size_row * logo_lines);
626
627 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
628 fbcon_clear_margins(vc, 0);
629 update_screen(vc);
630 }
631
632 if (save) {
633 q = (unsigned short *) (vc->vc_origin +
634 vc->vc_size_row *
635 rows);
636 scr_memcpyw(q, save, logo_lines * new_cols * 2);
637 vc->vc_y += logo_lines;
638 vc->vc_pos += logo_lines * vc->vc_size_row;
639 kfree(save);
640 }
641
642 if (logo_lines > vc->vc_bottom) {
643 logo_shown = FBCON_LOGO_CANSHOW;
644 printk(KERN_INFO
645 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
646 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
647 logo_shown = FBCON_LOGO_DRAW;
648 vc->vc_top = logo_lines;
649 }
650}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700651#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800654static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
656 struct fbcon_ops *ops = info->fbcon_par;
657
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800658 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800659
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800661 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800662 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800663 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700667
668static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
669{
670 int err = 0;
671
672 if (info->flags & FBINFO_MISC_TILEBLITTING &&
673 info->tileops->fb_get_tilemax(info) < charcount)
674 err = 1;
675
676 return err;
677}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800679static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
681 struct fbcon_ops *ops = info->fbcon_par;
682
683 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800684 ops->p = &fb_display[vc->vc_num];
685 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 fbcon_set_bitops(ops);
687}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700688
689static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
690{
691 return 0;
692}
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#endif /* CONFIG_MISC_TILEBLITTING */
695
696
697static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
698 int unit, int oldidx)
699{
700 struct fbcon_ops *ops = NULL;
701 int err = 0;
702
703 if (!try_module_get(info->fbops->owner))
704 err = -ENODEV;
705
706 if (!err && info->fbops->fb_open &&
707 info->fbops->fb_open(info, 0))
708 err = -ENODEV;
709
710 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800711 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 if (!ops)
713 err = -ENOMEM;
714 }
715
716 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700718
719 if (vc)
720 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722
723 if (err) {
724 con2fb_map[unit] = oldidx;
725 module_put(info->fbops->owner);
726 }
727
728 return err;
729}
730
731static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
732 struct fb_info *newinfo, int unit,
733 int oldidx, int found)
734{
735 struct fbcon_ops *ops = oldinfo->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700736 int err = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 if (oldinfo->fbops->fb_release &&
739 oldinfo->fbops->fb_release(oldinfo, 0)) {
740 con2fb_map[unit] = oldidx;
741 if (!found && newinfo->fbops->fb_release)
742 newinfo->fbops->fb_release(newinfo, 0);
743 if (!found)
744 module_put(newinfo->fbops->owner);
745 err = -ENODEV;
746 }
747
748 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700749 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 kfree(ops->cursor_state.mask);
751 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800752 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 kfree(oldinfo->fbcon_par);
754 oldinfo->fbcon_par = NULL;
755 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800756 /*
757 If oldinfo and newinfo are driving the same hardware,
758 the fb_release() method of oldinfo may attempt to
759 restore the hardware state. This will leave the
760 newinfo in an undefined state. Thus, a call to
761 fb_set_par() may be needed for the newinfo.
762 */
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700763 if (newinfo->fbops->fb_set_par) {
764 ret = newinfo->fbops->fb_set_par(newinfo);
765
766 if (ret)
767 printk(KERN_ERR "con2fb_release_oldinfo: "
768 "detected unhandled fb_set_par error, "
769 "error code %d\n", ret);
770 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772
773 return err;
774}
775
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
777 int unit, int show_logo)
778{
779 struct fbcon_ops *ops = info->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700780 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
782 ops->currcon = fg_console;
783
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700784 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
785 ret = info->fbops->fb_set_par(info);
786
787 if (ret)
788 printk(KERN_ERR "con2fb_init_display: detected "
789 "unhandled fb_set_par error, "
790 "error code %d\n", ret);
791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 ops->flags |= FBCON_FLAGS_INIT;
794 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700795 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 if (show_logo) {
798 struct vc_data *fg_vc = vc_cons[fg_console].d;
799 struct fb_info *fg_info =
800 registered_fb[con2fb_map[fg_console]];
801
802 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
803 fg_vc->vc_rows, fg_vc->vc_cols,
804 fg_vc->vc_rows);
805 }
806
807 update_screen(vc_cons[fg_console].d);
808}
809
810/**
811 * set_con2fb_map - map console to frame buffer device
812 * @unit: virtual console number to map
813 * @newidx: frame buffer index to map virtual console to
814 * @user: user request
815 *
816 * Maps a virtual console @unit to a frame buffer device
817 * @newidx.
818 */
819static int set_con2fb_map(int unit, int newidx, int user)
820{
821 struct vc_data *vc = vc_cons[unit].d;
822 int oldidx = con2fb_map[unit];
823 struct fb_info *info = registered_fb[newidx];
824 struct fb_info *oldinfo = NULL;
825 int found, err = 0;
826
827 if (oldidx == newidx)
828 return 0;
829
Dave Airlie32b98bf2010-12-21 01:41:17 +0000830 if (!info)
Antonino A. Daplase614b182006-06-26 00:27:09 -0700831 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
Dave Airlie32b98bf2010-12-21 01:41:17 +0000833 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 info_idx = newidx;
835 return fbcon_takeover(0);
836 }
837
838 if (oldidx != -1)
839 oldinfo = registered_fb[oldidx];
840
841 found = search_fb_in_map(newidx);
842
Torben Hohnac751ef2011-01-25 15:07:35 -0800843 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 con2fb_map[unit] = newidx;
845 if (!err && !found)
846 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
847
848
849 /*
850 * If old fb is not mapped to any of the consoles,
851 * fbcon should release it.
852 */
853 if (!err && oldinfo && !search_fb_in_map(oldidx))
854 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
855 found);
856
857 if (!err) {
858 int show_logo = (fg_console == 0 && !user &&
859 logo_shown != FBCON_LOGO_DONTSHOW);
860
861 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700862 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 con2fb_map_boot[unit] = newidx;
864 con2fb_init_display(vc, info, unit, show_logo);
865 }
866
Antonino A. Daplase614b182006-06-26 00:27:09 -0700867 if (!search_fb_in_map(info_idx))
868 info_idx = newidx;
869
Torben Hohnac751ef2011-01-25 15:07:35 -0800870 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 return err;
872}
873
874/*
875 * Low Level Operations
876 */
877/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
878static int var_to_display(struct display *disp,
879 struct fb_var_screeninfo *var,
880 struct fb_info *info)
881{
882 disp->xres_virtual = var->xres_virtual;
883 disp->yres_virtual = var->yres_virtual;
884 disp->bits_per_pixel = var->bits_per_pixel;
885 disp->grayscale = var->grayscale;
886 disp->nonstd = var->nonstd;
887 disp->accel_flags = var->accel_flags;
888 disp->height = var->height;
889 disp->width = var->width;
890 disp->red = var->red;
891 disp->green = var->green;
892 disp->blue = var->blue;
893 disp->transp = var->transp;
894 disp->rotate = var->rotate;
895 disp->mode = fb_match_mode(var, &info->modelist);
896 if (disp->mode == NULL)
897 /* This should not happen */
898 return -EINVAL;
899 return 0;
900}
901
902static void display_to_var(struct fb_var_screeninfo *var,
903 struct display *disp)
904{
905 fb_videomode_to_var(var, disp->mode);
906 var->xres_virtual = disp->xres_virtual;
907 var->yres_virtual = disp->yres_virtual;
908 var->bits_per_pixel = disp->bits_per_pixel;
909 var->grayscale = disp->grayscale;
910 var->nonstd = disp->nonstd;
911 var->accel_flags = disp->accel_flags;
912 var->height = disp->height;
913 var->width = disp->width;
914 var->red = disp->red;
915 var->green = disp->green;
916 var->blue = disp->blue;
917 var->transp = disp->transp;
918 var->rotate = disp->rotate;
919}
920
921static const char *fbcon_startup(void)
922{
923 const char *display_desc = "frame buffer device";
924 struct display *p = &fb_display[fg_console];
925 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700926 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 struct module *owner;
928 struct fb_info *info = NULL;
929 struct fbcon_ops *ops;
930 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 /*
933 * If num_registered_fb is zero, this is a call for the dummy part.
934 * The frame buffer devices weren't initialized yet.
935 */
936 if (!num_registered_fb || info_idx == -1)
937 return display_desc;
938 /*
939 * Instead of blindly using registered_fb[0], we use info_idx, set by
940 * fb_console_init();
941 */
942 info = registered_fb[info_idx];
943 if (!info)
944 return NULL;
945
946 owner = info->fbops->owner;
947 if (!try_module_get(owner))
948 return NULL;
949 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
950 module_put(owner);
951 return NULL;
952 }
953
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800954 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 if (!ops) {
956 module_put(owner);
957 return NULL;
958 }
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 ops->currcon = -1;
961 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800962 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800964 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800965 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 if (info->fix.type != FB_TYPE_TEXT) {
968 if (fbcon_softback_size) {
969 if (!softback_buf) {
970 softback_buf =
971 (unsigned long)
972 kmalloc(fbcon_softback_size,
973 GFP_KERNEL);
974 if (!softback_buf) {
975 fbcon_softback_size = 0;
976 softback_top = 0;
977 }
978 }
979 } else {
980 if (softback_buf) {
981 kfree((void *) softback_buf);
982 softback_buf = 0;
983 softback_top = 0;
984 }
985 }
986 if (softback_buf)
987 softback_in = softback_top = softback_curr =
988 softback_buf;
989 softback_lines = 0;
990 }
991
992 /* Setup default font */
993 if (!p->fontdata) {
994 if (!fontname[0] || !(font = find_font(fontname)))
995 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700996 info->var.yres,
997 info->pixmap.blit_x,
998 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 vc->vc_font.width = font->width;
1000 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001001 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1003 }
1004
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001005 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1006 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1007 cols /= vc->vc_font.width;
1008 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 vc_resize(vc, cols, rows);
1010
1011 DPRINTK("mode: %s\n", info->fix.id);
1012 DPRINTK("visual: %d\n", info->fix.visual);
1013 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1014 info->var.yres,
1015 info->var.bits_per_pixel);
1016
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001017 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001018 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 return display_desc;
1020}
1021
1022static void fbcon_init(struct vc_data *vc, int init)
1023{
1024 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1025 struct fbcon_ops *ops;
1026 struct vc_data **default_mode = vc->vc_display_fg;
1027 struct vc_data *svc = *default_mode;
1028 struct display *t, *p = &fb_display[vc->vc_num];
1029 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001030 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 if (info_idx == -1 || info == NULL)
1033 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001034
1035 cap = info->flags;
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1038 (info->fix.type == FB_TYPE_TEXT))
1039 logo = 0;
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (var_to_display(p, &info->var, info))
1042 return;
1043
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001044 if (!info->fbcon_par)
1045 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 /* If we are not the first console on this
1048 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001049 t = &fb_display[fg_console];
1050 if (!p->fontdata) {
1051 if (t->fontdata) {
1052 struct vc_data *fvc = vc_cons[fg_console].d;
1053
1054 vc->vc_font.data = (void *)(p->fontdata =
1055 fvc->vc_font.data);
1056 vc->vc_font.width = fvc->vc_font.width;
1057 vc->vc_font.height = fvc->vc_font.height;
1058 p->userfont = t->userfont;
1059
1060 if (p->userfont)
1061 REFCOUNT(p->fontdata)++;
1062 } else {
1063 const struct font_desc *font = NULL;
1064
1065 if (!fontname[0] || !(font = find_font(fontname)))
1066 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001067 info->var.yres,
1068 info->pixmap.blit_x,
1069 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001070 vc->vc_font.width = font->width;
1071 vc->vc_font.height = font->height;
1072 vc->vc_font.data = (void *)(p->fontdata = font->data);
1073 vc->vc_font.charcount = 256; /* FIXME Need to
1074 support more fonts */
1075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (p->userfont)
1079 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001080
Jesse Barnes8fd4bd22010-06-23 12:56:12 -07001081 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001082 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1084 if (charcnt == 256) {
1085 vc->vc_hi_font_mask = 0;
1086 } else {
1087 vc->vc_hi_font_mask = 0x100;
1088 if (vc->vc_can_do_color)
1089 vc->vc_complement_mask <<= 1;
1090 }
1091
1092 if (!*svc->vc_uni_pagedir_loc)
1093 con_set_default_unimap(svc);
1094 if (!*vc->vc_uni_pagedir_loc)
1095 con_copy_unimap(vc, svc);
1096
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001097 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001098 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001099 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 cols = vc->vc_cols;
1102 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001103 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1104 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1105 new_cols /= vc->vc_font.width;
1106 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 /*
1109 * We must always set the mode. The mode of the previous console
1110 * driver could be in the same resolution but we are using different
1111 * hardware so we have to initialize the hardware.
1112 *
1113 * We need to do it in fbcon_init() to prevent screen corruption.
1114 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001115 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001117 !(ops->flags & FBCON_FLAGS_INIT)) {
1118 ret = info->fbops->fb_set_par(info);
1119
1120 if (ret)
1121 printk(KERN_ERR "fbcon_init: detected "
1122 "unhandled fb_set_par error, "
1123 "error code %d\n", ret);
1124 }
1125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 ops->flags |= FBCON_FLAGS_INIT;
1127 }
1128
1129 ops->graphics = 0;
1130
1131 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1132 !(cap & FBINFO_HWACCEL_DISABLED))
1133 p->scrollmode = SCROLL_MOVE;
1134 else /* default to something safe */
1135 p->scrollmode = SCROLL_REDRAW;
1136
1137 /*
1138 * ++guenther: console.c:vc_allocate() relies on initializing
1139 * vc_{cols,rows}, but we must not set those if we are only
1140 * resizing the console.
1141 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001142 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 vc->vc_cols = new_cols;
1144 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001145 } else
1146 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 if (logo)
1149 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1150
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001151 if (vc == svc && softback_buf)
1152 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001153
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001154 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001155 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001156 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001157 }
1158
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001159 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Antonino A. Daplase614b182006-06-26 00:27:09 -07001162static void fbcon_free_font(struct display *p)
1163{
1164 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1165 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1166 p->fontdata = NULL;
1167 p->userfont = 0;
1168}
1169
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170static void fbcon_deinit(struct vc_data *vc)
1171{
1172 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001173 struct fb_info *info;
1174 struct fbcon_ops *ops;
1175 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001178 idx = con2fb_map[vc->vc_num];
1179
1180 if (idx == -1)
1181 goto finished;
1182
1183 info = registered_fb[idx];
1184
1185 if (!info)
1186 goto finished;
1187
1188 ops = info->fbcon_par;
1189
1190 if (!ops)
1191 goto finished;
1192
1193 if (CON_IS_VISIBLE(vc))
1194 fbcon_del_cursor_timer(info);
1195
1196 ops->flags &= ~FBCON_FLAGS_INIT;
1197finished:
1198
1199 if (!con_is_bound(&fb_con))
1200 fbcon_exit();
1201
1202 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
1205/* ====================================================================== */
1206
1207/* fbcon_XXX routines - interface used by the world
1208 *
1209 * This system is now divided into two levels because of complications
1210 * caused by hardware scrolling. Top level functions:
1211 *
1212 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1213 *
1214 * handles y values in range [0, scr_height-1] that correspond to real
1215 * screen positions. y_wrap shift means that first line of bitmap may be
1216 * anywhere on this display. These functions convert lineoffsets to
1217 * bitmap offsets and deal with the wrap-around case by splitting blits.
1218 *
1219 * fbcon_bmove_physical_8() -- These functions fast implementations
1220 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1221 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1222 *
1223 * WARNING:
1224 *
1225 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1226 * Implies should only really hardware scroll in rows. Only reason for
1227 * restriction is simplicity & efficiency at the moment.
1228 */
1229
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1231 int width)
1232{
1233 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1234 struct fbcon_ops *ops = info->fbcon_par;
1235
1236 struct display *p = &fb_display[vc->vc_num];
1237 u_int y_break;
1238
1239 if (fbcon_is_inactive(vc, info))
1240 return;
1241
1242 if (!height || !width)
1243 return;
1244
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001245 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001246 vc->vc_top = 0;
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001247 /*
1248 * If the font dimensions are not an integral of the display
1249 * dimensions then the ops->clear below won't end up clearing
1250 * the margins. Call clear_margins here in case the logo
1251 * bitmap stretched into the margin area.
1252 */
1253 fbcon_clear_margins(vc, 0);
1254 }
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 /* Split blits that cross physical y_wrap boundary */
1257
1258 y_break = p->vrows - p->yscroll;
1259 if (sy < y_break && sy + height - 1 >= y_break) {
1260 u_int b = y_break - sy;
1261 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1262 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1263 width);
1264 } else
1265 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1266}
1267
1268static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1269 int count, int ypos, int xpos)
1270{
1271 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1272 struct display *p = &fb_display[vc->vc_num];
1273 struct fbcon_ops *ops = info->fbcon_par;
1274
1275 if (!fbcon_is_inactive(vc, info))
1276 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1277 get_color(vc, info, scr_readw(s), 1),
1278 get_color(vc, info, scr_readw(s), 0));
1279}
1280
1281static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1282{
1283 unsigned short chr;
1284
1285 scr_writew(c, &chr);
1286 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1287}
1288
1289static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1290{
1291 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1292 struct fbcon_ops *ops = info->fbcon_par;
1293
1294 if (!fbcon_is_inactive(vc, info))
1295 ops->clear_margins(vc, info, bottom_only);
1296}
1297
1298static void fbcon_cursor(struct vc_data *vc, int mode)
1299{
1300 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1301 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 int y;
1303 int c = scr_readw((u16 *) vc->vc_pos);
1304
Michal Januszewskid1e23062007-05-08 00:38:07 -07001305 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 return;
1307
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001308 if (vc->vc_cursor_type & 0x10)
1309 fbcon_del_cursor_timer(info);
1310 else
1311 fbcon_add_cursor_timer(info);
1312
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1314 if (mode & CM_SOFTBACK) {
1315 mode &= ~CM_SOFTBACK;
1316 y = softback_lines;
1317 } else {
1318 if (softback_lines)
1319 fbcon_set_origin(vc);
1320 y = 0;
1321 }
1322
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001323 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 get_color(vc, info, c, 0));
1325 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1326}
1327
1328static int scrollback_phys_max = 0;
1329static int scrollback_max = 0;
1330static int scrollback_current = 0;
1331
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001333 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001335 struct display *p, *t;
1336 struct vc_data **default_mode, *vc;
1337 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001338 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 int rows, cols, charcnt = 256;
1340
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001341 p = &fb_display[unit];
1342
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 if (var_to_display(p, var, info))
1344 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001345
1346 vc = vc_cons[unit].d;
1347
1348 if (!vc)
1349 return;
1350
1351 default_mode = vc->vc_display_fg;
1352 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001354
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001356 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 vc->vc_font.width = (*default_mode)->vc_font.width;
1358 vc->vc_font.height = (*default_mode)->vc_font.height;
1359 p->userfont = t->userfont;
1360 if (p->userfont)
1361 REFCOUNT(p->fontdata)++;
1362 }
1363 if (p->userfont)
1364 charcnt = FNTCHARCNT(p->fontdata);
1365
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001366 var->activate = FB_ACTIVATE_NOW;
1367 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001368 var->yoffset = info->var.yoffset;
1369 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001370 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001371 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001372 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1374 if (charcnt == 256) {
1375 vc->vc_hi_font_mask = 0;
1376 } else {
1377 vc->vc_hi_font_mask = 0x100;
1378 if (vc->vc_can_do_color)
1379 vc->vc_complement_mask <<= 1;
1380 }
1381
1382 if (!*svc->vc_uni_pagedir_loc)
1383 con_set_default_unimap(svc);
1384 if (!*vc->vc_uni_pagedir_loc)
1385 con_copy_unimap(vc, svc);
1386
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001387 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1388 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1389 cols /= vc->vc_font.width;
1390 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 if (CON_IS_VISIBLE(vc)) {
1394 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001395 if (softback_buf)
1396 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
1398}
1399
1400static __inline__ void ywrap_up(struct vc_data *vc, int count)
1401{
1402 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001403 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 struct display *p = &fb_display[vc->vc_num];
1405
1406 p->yscroll += count;
1407 if (p->yscroll >= p->vrows) /* Deal with wrap */
1408 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001409 ops->var.xoffset = 0;
1410 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1411 ops->var.vmode |= FB_VMODE_YWRAP;
1412 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 scrollback_max += count;
1414 if (scrollback_max > scrollback_phys_max)
1415 scrollback_max = scrollback_phys_max;
1416 scrollback_current = 0;
1417}
1418
1419static __inline__ void ywrap_down(struct vc_data *vc, int count)
1420{
1421 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001422 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 struct display *p = &fb_display[vc->vc_num];
1424
1425 p->yscroll -= count;
1426 if (p->yscroll < 0) /* Deal with wrap */
1427 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001428 ops->var.xoffset = 0;
1429 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1430 ops->var.vmode |= FB_VMODE_YWRAP;
1431 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 scrollback_max -= count;
1433 if (scrollback_max < 0)
1434 scrollback_max = 0;
1435 scrollback_current = 0;
1436}
1437
1438static __inline__ void ypan_up(struct vc_data *vc, int count)
1439{
1440 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1441 struct display *p = &fb_display[vc->vc_num];
1442 struct fbcon_ops *ops = info->fbcon_par;
1443
1444 p->yscroll += count;
1445 if (p->yscroll > p->vrows - vc->vc_rows) {
1446 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1447 0, 0, 0, vc->vc_rows, vc->vc_cols);
1448 p->yscroll -= p->vrows - vc->vc_rows;
1449 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001450
1451 ops->var.xoffset = 0;
1452 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1453 ops->var.vmode &= ~FB_VMODE_YWRAP;
1454 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 fbcon_clear_margins(vc, 1);
1456 scrollback_max += count;
1457 if (scrollback_max > scrollback_phys_max)
1458 scrollback_max = scrollback_phys_max;
1459 scrollback_current = 0;
1460}
1461
1462static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1463{
1464 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001465 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (p->yscroll > p->vrows - vc->vc_rows) {
1471 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001473 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001474
1475 ops->var.xoffset = 0;
1476 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1477 ops->var.vmode &= ~FB_VMODE_YWRAP;
1478 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 fbcon_clear_margins(vc, 1);
1480 scrollback_max += count;
1481 if (scrollback_max > scrollback_phys_max)
1482 scrollback_max = scrollback_phys_max;
1483 scrollback_current = 0;
1484}
1485
1486static __inline__ void ypan_down(struct vc_data *vc, int count)
1487{
1488 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1489 struct display *p = &fb_display[vc->vc_num];
1490 struct fbcon_ops *ops = info->fbcon_par;
1491
1492 p->yscroll -= count;
1493 if (p->yscroll < 0) {
1494 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1495 0, vc->vc_rows, vc->vc_cols);
1496 p->yscroll += p->vrows - vc->vc_rows;
1497 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001498
1499 ops->var.xoffset = 0;
1500 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1501 ops->var.vmode &= ~FB_VMODE_YWRAP;
1502 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 fbcon_clear_margins(vc, 1);
1504 scrollback_max -= count;
1505 if (scrollback_max < 0)
1506 scrollback_max = 0;
1507 scrollback_current = 0;
1508}
1509
1510static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1511{
1512 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001513 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001517
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 if (p->yscroll < 0) {
1519 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001521 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001522
1523 ops->var.xoffset = 0;
1524 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1525 ops->var.vmode &= ~FB_VMODE_YWRAP;
1526 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 fbcon_clear_margins(vc, 1);
1528 scrollback_max -= count;
1529 if (scrollback_max < 0)
1530 scrollback_max = 0;
1531 scrollback_current = 0;
1532}
1533
1534static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1535 long delta)
1536{
1537 int count = vc->vc_rows;
1538 unsigned short *d, *s;
1539 unsigned long n;
1540 int line = 0;
1541
1542 d = (u16 *) softback_curr;
1543 if (d == (u16 *) softback_in)
1544 d = (u16 *) vc->vc_origin;
1545 n = softback_curr + delta * vc->vc_size_row;
1546 softback_lines -= delta;
1547 if (delta < 0) {
1548 if (softback_curr < softback_top && n < softback_buf) {
1549 n += softback_end - softback_buf;
1550 if (n < softback_top) {
1551 softback_lines -=
1552 (softback_top - n) / vc->vc_size_row;
1553 n = softback_top;
1554 }
1555 } else if (softback_curr >= softback_top
1556 && n < softback_top) {
1557 softback_lines -=
1558 (softback_top - n) / vc->vc_size_row;
1559 n = softback_top;
1560 }
1561 } else {
1562 if (softback_curr > softback_in && n >= softback_end) {
1563 n += softback_buf - softback_end;
1564 if (n > softback_in) {
1565 n = softback_in;
1566 softback_lines = 0;
1567 }
1568 } else if (softback_curr <= softback_in && n > softback_in) {
1569 n = softback_in;
1570 softback_lines = 0;
1571 }
1572 }
1573 if (n == softback_curr)
1574 return;
1575 softback_curr = n;
1576 s = (u16 *) softback_curr;
1577 if (s == (u16 *) softback_in)
1578 s = (u16 *) vc->vc_origin;
1579 while (count--) {
1580 unsigned short *start;
1581 unsigned short *le;
1582 unsigned short c;
1583 int x = 0;
1584 unsigned short attr = 1;
1585
1586 start = s;
1587 le = advance_row(s, 1);
1588 do {
1589 c = scr_readw(s);
1590 if (attr != (c & 0xff00)) {
1591 attr = c & 0xff00;
1592 if (s > start) {
1593 fbcon_putcs(vc, start, s - start,
1594 line, x);
1595 x += s - start;
1596 start = s;
1597 }
1598 }
1599 if (c == scr_readw(d)) {
1600 if (s > start) {
1601 fbcon_putcs(vc, start, s - start,
1602 line, x);
1603 x += s - start + 1;
1604 start = s + 1;
1605 } else {
1606 x++;
1607 start++;
1608 }
1609 }
1610 s++;
1611 d++;
1612 } while (s < le);
1613 if (s > start)
1614 fbcon_putcs(vc, start, s - start, line, x);
1615 line++;
1616 if (d == (u16 *) softback_end)
1617 d = (u16 *) softback_buf;
1618 if (d == (u16 *) softback_in)
1619 d = (u16 *) vc->vc_origin;
1620 if (s == (u16 *) softback_end)
1621 s = (u16 *) softback_buf;
1622 if (s == (u16 *) softback_in)
1623 s = (u16 *) vc->vc_origin;
1624 }
1625}
1626
1627static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1628 int line, int count, int dy)
1629{
1630 unsigned short *s = (unsigned short *)
1631 (vc->vc_origin + vc->vc_size_row * line);
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 unsigned short attr = 1;
1639
1640 do {
1641 c = scr_readw(s);
1642 if (attr != (c & 0xff00)) {
1643 attr = c & 0xff00;
1644 if (s > start) {
1645 fbcon_putcs(vc, start, s - start,
1646 dy, x);
1647 x += s - start;
1648 start = s;
1649 }
1650 }
1651 console_conditional_schedule();
1652 s++;
1653 } while (s < le);
1654 if (s > start)
1655 fbcon_putcs(vc, start, s - start, dy, x);
1656 console_conditional_schedule();
1657 dy++;
1658 }
1659}
1660
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001661static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1662 struct display *p, int line, int count, int ycount)
1663{
1664 int offset = ycount * vc->vc_cols;
1665 unsigned short *d = (unsigned short *)
1666 (vc->vc_origin + vc->vc_size_row * line);
1667 unsigned short *s = d + offset;
1668 struct fbcon_ops *ops = info->fbcon_par;
1669
1670 while (count--) {
1671 unsigned short *start = s;
1672 unsigned short *le = advance_row(s, 1);
1673 unsigned short c;
1674 int x = 0;
1675
1676 do {
1677 c = scr_readw(s);
1678
1679 if (c == scr_readw(d)) {
1680 if (s > start) {
1681 ops->bmove(vc, info, line + ycount, x,
1682 line, x, 1, s-start);
1683 x += s - start + 1;
1684 start = s + 1;
1685 } else {
1686 x++;
1687 start++;
1688 }
1689 }
1690
1691 scr_writew(c, d);
1692 console_conditional_schedule();
1693 s++;
1694 d++;
1695 } while (s < le);
1696 if (s > start)
1697 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1698 s-start);
1699 console_conditional_schedule();
1700 if (ycount > 0)
1701 line++;
1702 else {
1703 line--;
1704 /* NOTE: We subtract two lines from these pointers */
1705 s -= vc->vc_size_row;
1706 d -= vc->vc_size_row;
1707 }
1708 }
1709}
1710
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711static void fbcon_redraw(struct vc_data *vc, struct display *p,
1712 int line, int count, int offset)
1713{
1714 unsigned short *d = (unsigned short *)
1715 (vc->vc_origin + vc->vc_size_row * line);
1716 unsigned short *s = d + offset;
1717
1718 while (count--) {
1719 unsigned short *start = s;
1720 unsigned short *le = advance_row(s, 1);
1721 unsigned short c;
1722 int x = 0;
1723 unsigned short attr = 1;
1724
1725 do {
1726 c = scr_readw(s);
1727 if (attr != (c & 0xff00)) {
1728 attr = c & 0xff00;
1729 if (s > start) {
1730 fbcon_putcs(vc, start, s - start,
1731 line, x);
1732 x += s - start;
1733 start = s;
1734 }
1735 }
1736 if (c == scr_readw(d)) {
1737 if (s > start) {
1738 fbcon_putcs(vc, start, s - start,
1739 line, x);
1740 x += s - start + 1;
1741 start = s + 1;
1742 } else {
1743 x++;
1744 start++;
1745 }
1746 }
1747 scr_writew(c, d);
1748 console_conditional_schedule();
1749 s++;
1750 d++;
1751 } while (s < le);
1752 if (s > start)
1753 fbcon_putcs(vc, start, s - start, line, x);
1754 console_conditional_schedule();
1755 if (offset > 0)
1756 line++;
1757 else {
1758 line--;
1759 /* NOTE: We subtract two lines from these pointers */
1760 s -= vc->vc_size_row;
1761 d -= vc->vc_size_row;
1762 }
1763 }
1764}
1765
1766static inline void fbcon_softback_note(struct vc_data *vc, int t,
1767 int count)
1768{
1769 unsigned short *p;
1770
1771 if (vc->vc_num != fg_console)
1772 return;
1773 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1774
1775 while (count) {
1776 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1777 count--;
1778 p = advance_row(p, 1);
1779 softback_in += vc->vc_size_row;
1780 if (softback_in == softback_end)
1781 softback_in = softback_buf;
1782 if (softback_in == softback_top) {
1783 softback_top += vc->vc_size_row;
1784 if (softback_top == softback_end)
1785 softback_top = softback_buf;
1786 }
1787 }
1788 softback_curr = softback_in;
1789}
1790
1791static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1792 int count)
1793{
1794 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1795 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1797
1798 if (fbcon_is_inactive(vc, info))
1799 return -EINVAL;
1800
1801 fbcon_cursor(vc, CM_ERASE);
1802
1803 /*
1804 * ++Geert: Only use ywrap/ypan if the console is in text mode
1805 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1806 * whole screen (prevents flicker).
1807 */
1808
1809 switch (dir) {
1810 case SM_UP:
1811 if (count > vc->vc_rows) /* Maximum realistic size */
1812 count = vc->vc_rows;
1813 if (softback_top)
1814 fbcon_softback_note(vc, t, count);
1815 if (logo_shown >= 0)
1816 goto redraw_up;
1817 switch (p->scrollmode) {
1818 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001819 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1820 count);
1821 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1822 scr_memsetw((unsigned short *) (vc->vc_origin +
1823 vc->vc_size_row *
1824 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001825 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001826 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001827 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 break;
1829
1830 case SCROLL_WRAP_MOVE:
1831 if (b - t - count > 3 * vc->vc_rows >> 2) {
1832 if (t > 0)
1833 fbcon_bmove(vc, 0, 0, count, 0, t,
1834 vc->vc_cols);
1835 ywrap_up(vc, count);
1836 if (vc->vc_rows - b > 0)
1837 fbcon_bmove(vc, b - count, 0, b, 0,
1838 vc->vc_rows - b,
1839 vc->vc_cols);
1840 } else if (info->flags & FBINFO_READS_FAST)
1841 fbcon_bmove(vc, t + count, 0, t, 0,
1842 b - t - count, vc->vc_cols);
1843 else
1844 goto redraw_up;
1845 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1846 break;
1847
1848 case SCROLL_PAN_REDRAW:
1849 if ((p->yscroll + count <=
1850 2 * (p->vrows - vc->vc_rows))
1851 && ((!scroll_partial && (b - t == vc->vc_rows))
1852 || (scroll_partial
1853 && (b - t - count >
1854 3 * vc->vc_rows >> 2)))) {
1855 if (t > 0)
1856 fbcon_redraw_move(vc, p, 0, t, count);
1857 ypan_up_redraw(vc, t, count);
1858 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001859 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 vc->vc_rows - b, b);
1861 } else
1862 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1863 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1864 break;
1865
1866 case SCROLL_PAN_MOVE:
1867 if ((p->yscroll + count <=
1868 2 * (p->vrows - vc->vc_rows))
1869 && ((!scroll_partial && (b - t == vc->vc_rows))
1870 || (scroll_partial
1871 && (b - t - count >
1872 3 * vc->vc_rows >> 2)))) {
1873 if (t > 0)
1874 fbcon_bmove(vc, 0, 0, count, 0, t,
1875 vc->vc_cols);
1876 ypan_up(vc, count);
1877 if (vc->vc_rows - b > 0)
1878 fbcon_bmove(vc, b - count, 0, b, 0,
1879 vc->vc_rows - b,
1880 vc->vc_cols);
1881 } else if (info->flags & FBINFO_READS_FAST)
1882 fbcon_bmove(vc, t + count, 0, t, 0,
1883 b - t - count, vc->vc_cols);
1884 else
1885 goto redraw_up;
1886 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1887 break;
1888
1889 case SCROLL_REDRAW:
1890 redraw_up:
1891 fbcon_redraw(vc, p, t, b - t - count,
1892 count * vc->vc_cols);
1893 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1894 scr_memsetw((unsigned short *) (vc->vc_origin +
1895 vc->vc_size_row *
1896 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001897 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001899 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 }
1901 break;
1902
1903 case SM_DOWN:
1904 if (count > vc->vc_rows) /* Maximum realistic size */
1905 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001906 if (logo_shown >= 0)
1907 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 switch (p->scrollmode) {
1909 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001910 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1911 -count);
1912 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1913 scr_memsetw((unsigned short *) (vc->vc_origin +
1914 vc->vc_size_row *
1915 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001916 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001917 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001918 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 break;
1920
1921 case SCROLL_WRAP_MOVE:
1922 if (b - t - count > 3 * vc->vc_rows >> 2) {
1923 if (vc->vc_rows - b > 0)
1924 fbcon_bmove(vc, b, 0, b - count, 0,
1925 vc->vc_rows - b,
1926 vc->vc_cols);
1927 ywrap_down(vc, count);
1928 if (t > 0)
1929 fbcon_bmove(vc, count, 0, 0, 0, t,
1930 vc->vc_cols);
1931 } else if (info->flags & FBINFO_READS_FAST)
1932 fbcon_bmove(vc, t, 0, t + count, 0,
1933 b - t - count, vc->vc_cols);
1934 else
1935 goto redraw_down;
1936 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1937 break;
1938
1939 case SCROLL_PAN_MOVE:
1940 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1941 && ((!scroll_partial && (b - t == vc->vc_rows))
1942 || (scroll_partial
1943 && (b - t - count >
1944 3 * vc->vc_rows >> 2)))) {
1945 if (vc->vc_rows - b > 0)
1946 fbcon_bmove(vc, b, 0, b - count, 0,
1947 vc->vc_rows - b,
1948 vc->vc_cols);
1949 ypan_down(vc, count);
1950 if (t > 0)
1951 fbcon_bmove(vc, count, 0, 0, 0, t,
1952 vc->vc_cols);
1953 } else if (info->flags & FBINFO_READS_FAST)
1954 fbcon_bmove(vc, t, 0, t + count, 0,
1955 b - t - count, vc->vc_cols);
1956 else
1957 goto redraw_down;
1958 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1959 break;
1960
1961 case SCROLL_PAN_REDRAW:
1962 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1963 && ((!scroll_partial && (b - t == vc->vc_rows))
1964 || (scroll_partial
1965 && (b - t - count >
1966 3 * vc->vc_rows >> 2)))) {
1967 if (vc->vc_rows - b > 0)
1968 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1969 b - count);
1970 ypan_down_redraw(vc, t, count);
1971 if (t > 0)
1972 fbcon_redraw_move(vc, p, count, t, 0);
1973 } else
1974 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1975 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1976 break;
1977
1978 case SCROLL_REDRAW:
1979 redraw_down:
1980 fbcon_redraw(vc, p, b - 1, b - t - count,
1981 -count * vc->vc_cols);
1982 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1983 scr_memsetw((unsigned short *) (vc->vc_origin +
1984 vc->vc_size_row *
1985 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001986 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001988 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 }
1990 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07001991 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
1994
1995static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1996 int height, int width)
1997{
1998 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1999 struct display *p = &fb_display[vc->vc_num];
2000
2001 if (fbcon_is_inactive(vc, info))
2002 return;
2003
2004 if (!width || !height)
2005 return;
2006
2007 /* Split blits that cross physical y_wrap case.
2008 * Pathological case involves 4 blits, better to use recursive
2009 * code rather than unrolled case
2010 *
2011 * Recursive invocations don't need to erase the cursor over and
2012 * over again, so we use fbcon_bmove_rec()
2013 */
2014 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2015 p->vrows - p->yscroll);
2016}
2017
2018static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2019 int dy, int dx, int height, int width, u_int y_break)
2020{
2021 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2022 struct fbcon_ops *ops = info->fbcon_par;
2023 u_int b;
2024
2025 if (sy < y_break && sy + height > y_break) {
2026 b = y_break - sy;
2027 if (dy < sy) { /* Avoid trashing self */
2028 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2029 y_break);
2030 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2031 height - b, width, y_break);
2032 } else {
2033 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2034 height - b, width, y_break);
2035 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2036 y_break);
2037 }
2038 return;
2039 }
2040
2041 if (dy < y_break && dy + height > y_break) {
2042 b = y_break - dy;
2043 if (dy < sy) { /* Avoid trashing self */
2044 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2045 y_break);
2046 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2047 height - b, width, y_break);
2048 } else {
2049 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2050 height - b, width, y_break);
2051 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2052 y_break);
2053 }
2054 return;
2055 }
2056 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2057 height, width);
2058}
2059
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002060static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002061 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 struct vc_data *vc)
2063{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002064 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 int fh = vc->vc_font.height;
2066 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002067 u16 t = 0;
2068 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2069 info->fix.xpanstep);
2070 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2071 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2072 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2073 info->var.xres_virtual);
2074 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2075 divides(ypan, vc->vc_font.height) && vyres > yres;
2076 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2077 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002078 divides(vc->vc_font.height, vyres) &&
2079 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002081 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2082 !(cap & FBINFO_HWACCEL_DISABLED);
2083 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2084 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002086 p->vrows = vyres/fh;
2087 if (yres > (fh * (vc->vc_rows + 1)))
2088 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2089 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 p->vrows--;
2091
2092 if (good_wrap || good_pan) {
2093 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002094 p->scrollmode = good_wrap ?
2095 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 else
2097 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2098 SCROLL_PAN_REDRAW;
2099 } else {
2100 if (reading_fast || (fast_copyarea && !fast_imageblit))
2101 p->scrollmode = SCROLL_MOVE;
2102 else
2103 p->scrollmode = SCROLL_REDRAW;
2104 }
2105}
2106
2107static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002108 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
2110 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002111 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct display *p = &fb_display[vc->vc_num];
2113 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002114 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002116 virt_w = FBCON_SWAP(ops->rotate, width, height);
2117 virt_h = FBCON_SWAP(ops->rotate, height, width);
2118 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2119 vc->vc_font.height);
2120 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2121 vc->vc_font.width);
2122 var.xres = virt_w * virt_fw;
2123 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 x_diff = info->var.xres - var.xres;
2125 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002126 if (x_diff < 0 || x_diff > virt_fw ||
2127 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002128 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2131 mode = fb_find_best_mode(&var, &info->modelist);
2132 if (mode == NULL)
2133 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002134 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002136
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002137 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2141 if (CON_IS_VISIBLE(vc)) {
2142 var.activate = FB_ACTIVATE_NOW |
2143 FB_ACTIVATE_FORCE;
2144 fb_set_var(info, &var);
2145 }
2146 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002147 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
2149 updatescrollmode(p, info, vc);
2150 return 0;
2151}
2152
2153static int fbcon_switch(struct vc_data *vc)
2154{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002155 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002156 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 struct display *p = &fb_display[vc->vc_num];
2158 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002159 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
2161 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002162 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 if (softback_lines)
2166 fbcon_set_origin(vc);
2167 softback_top = softback_curr = softback_in = softback_buf;
2168 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002169 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 }
2171
2172 if (logo_shown >= 0) {
2173 struct vc_data *conp2 = vc_cons[logo_shown].d;
2174
2175 if (conp2->vc_top == logo_lines
2176 && conp2->vc_bottom == conp2->vc_rows)
2177 conp2->vc_top = 0;
2178 logo_shown = FBCON_LOGO_CANSHOW;
2179 }
2180
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002181 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002182 if (prev_console != -1)
2183 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 /*
2185 * FIXME: If we have multiple fbdev's loaded, we need to
2186 * update all info->currcon. Perhaps, we can place this
2187 * in a centralized structure, but this might break some
2188 * drivers.
2189 *
2190 * info->currcon = vc->vc_num;
2191 */
2192 for (i = 0; i < FB_MAX; i++) {
2193 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002194 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002196 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 }
2198 }
2199 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2200 display_to_var(&var, p);
2201 var.activate = FB_ACTIVATE_NOW;
2202
2203 /*
2204 * make sure we don't unnecessarily trip the memcmp()
2205 * in fb_set_var()
2206 */
2207 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002208 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002210 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Knut Petersen39942fd2005-12-12 22:17:19 -08002212 if (old_info != NULL && (old_info != info ||
2213 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002214 if (info->fbops->fb_set_par) {
2215 ret = info->fbops->fb_set_par(info);
2216
2217 if (ret)
2218 printk(KERN_ERR "fbcon_switch: detected "
2219 "unhandled fb_set_par error, "
2220 "error code %d\n", ret);
2221 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002222
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002223 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002224 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002227 if (fbcon_is_inactive(vc, info) ||
2228 ops->blank_state != FB_BLANK_UNBLANK)
2229 fbcon_del_cursor_timer(info);
2230 else
2231 fbcon_add_cursor_timer(info);
2232
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002233 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002234 ops->cursor_reset = 1;
2235
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002236 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002237 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002238 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002241 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002243
2244 if (p->userfont)
2245 charcnt = FNTCHARCNT(vc->vc_font.data);
2246
2247 if (charcnt > 256)
2248 vc->vc_complement_mask <<= 1;
2249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 updatescrollmode(p, info, vc);
2251
2252 switch (p->scrollmode) {
2253 case SCROLL_WRAP_MOVE:
2254 scrollback_phys_max = p->vrows - vc->vc_rows;
2255 break;
2256 case SCROLL_PAN_MOVE:
2257 case SCROLL_PAN_REDRAW:
2258 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2259 if (scrollback_phys_max < 0)
2260 scrollback_phys_max = 0;
2261 break;
2262 default:
2263 scrollback_phys_max = 0;
2264 break;
2265 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002266
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 scrollback_max = 0;
2268 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002269
2270 if (!fbcon_is_inactive(vc, info)) {
2271 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2272 ops->update_start(info);
2273 }
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 fbcon_set_palette(vc, color_table);
2276 fbcon_clear_margins(vc, 0);
2277
2278 if (logo_shown == FBCON_LOGO_DRAW) {
2279
2280 logo_shown = fg_console;
2281 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002282 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 update_region(vc,
2284 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2285 vc->vc_size_row * (vc->vc_bottom -
2286 vc->vc_top) / 2);
2287 return 0;
2288 }
2289 return 1;
2290}
2291
2292static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2293 int blank)
2294{
Richard Purdie994efac2007-02-09 09:46:45 +00002295 struct fb_event event;
2296
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 if (blank) {
2298 unsigned short charmask = vc->vc_hi_font_mask ?
2299 0x1ff : 0xff;
2300 unsigned short oldc;
2301
2302 oldc = vc->vc_video_erase_char;
2303 vc->vc_video_erase_char &= charmask;
2304 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2305 vc->vc_video_erase_char = oldc;
2306 }
Richard Purdie994efac2007-02-09 09:46:45 +00002307
2308
Andrea Righi513adb52009-04-13 14:39:39 -07002309 if (!lock_fb_info(info))
2310 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002311 event.info = info;
2312 event.data = &blank;
2313 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002314 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315}
2316
2317static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2318{
2319 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2320 struct fbcon_ops *ops = info->fbcon_par;
2321
2322 if (mode_switch) {
2323 struct fb_var_screeninfo var = info->var;
2324
2325 ops->graphics = 1;
2326
2327 if (!blank) {
2328 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2329 fb_set_var(info, &var);
2330 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002331 ops->var = info->var;
Krzysztof Heltf5c15d02009-11-11 14:26:22 -08002332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 }
2334
2335 if (!fbcon_is_inactive(vc, info)) {
2336 if (ops->blank_state != blank) {
2337 ops->blank_state = blank;
2338 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2339 ops->cursor_flash = (!blank);
2340
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002341 if (!(info->flags & FBINFO_MISC_USEREVENT))
2342 if (fb_blank(info, blank))
2343 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 }
2345
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002346 if (!blank)
2347 update_screen(vc);
2348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002350 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002351 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002352 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002353 else
2354 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002355
2356 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
Jesse Barnesd219adc2010-08-02 12:05:41 -07002359static int fbcon_debug_enter(struct vc_data *vc)
2360{
2361 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2362 struct fbcon_ops *ops = info->fbcon_par;
2363
2364 ops->save_graphics = ops->graphics;
2365 ops->graphics = 0;
2366 if (info->fbops->fb_debug_enter)
2367 info->fbops->fb_debug_enter(info);
2368 fbcon_set_palette(vc, color_table);
2369 return 0;
2370}
2371
2372static int fbcon_debug_leave(struct vc_data *vc)
2373{
2374 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2375 struct fbcon_ops *ops = info->fbcon_par;
2376
2377 ops->graphics = ops->save_graphics;
2378 if (info->fbops->fb_debug_leave)
2379 info->fbops->fb_debug_leave(info);
2380 return 0;
2381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2384{
2385 u8 *fontdata = vc->vc_font.data;
2386 u8 *data = font->data;
2387 int i, j;
2388
2389 font->width = vc->vc_font.width;
2390 font->height = vc->vc_font.height;
2391 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2392 if (!font->data)
2393 return 0;
2394
2395 if (font->width <= 8) {
2396 j = vc->vc_font.height;
2397 for (i = 0; i < font->charcount; i++) {
2398 memcpy(data, fontdata, j);
2399 memset(data + j, 0, 32 - j);
2400 data += 32;
2401 fontdata += j;
2402 }
2403 } else if (font->width <= 16) {
2404 j = vc->vc_font.height * 2;
2405 for (i = 0; i < font->charcount; i++) {
2406 memcpy(data, fontdata, j);
2407 memset(data + j, 0, 64 - j);
2408 data += 64;
2409 fontdata += j;
2410 }
2411 } else if (font->width <= 24) {
2412 for (i = 0; i < font->charcount; i++) {
2413 for (j = 0; j < vc->vc_font.height; j++) {
2414 *data++ = fontdata[0];
2415 *data++ = fontdata[1];
2416 *data++ = fontdata[2];
2417 fontdata += sizeof(u32);
2418 }
2419 memset(data, 0, 3 * (32 - j));
2420 data += 3 * (32 - j);
2421 }
2422 } else {
2423 j = vc->vc_font.height * 4;
2424 for (i = 0; i < font->charcount; i++) {
2425 memcpy(data, fontdata, j);
2426 memset(data + j, 0, 128 - j);
2427 data += 128;
2428 fontdata += j;
2429 }
2430 }
2431 return 0;
2432}
2433
2434static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002435 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
2437 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002438 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct display *p = &fb_display[vc->vc_num];
2440 int resize;
2441 int cnt;
2442 char *old_data = NULL;
2443
2444 if (CON_IS_VISIBLE(vc) && softback_lines)
2445 fbcon_set_origin(vc);
2446
2447 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2448 if (p->userfont)
2449 old_data = vc->vc_font.data;
2450 if (userfont)
2451 cnt = FNTCHARCNT(data);
2452 else
2453 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002454 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 if ((p->userfont = userfont))
2456 REFCOUNT(data)++;
2457 vc->vc_font.width = w;
2458 vc->vc_font.height = h;
2459 if (vc->vc_hi_font_mask && cnt == 256) {
2460 vc->vc_hi_font_mask = 0;
2461 if (vc->vc_can_do_color) {
2462 vc->vc_complement_mask >>= 1;
2463 vc->vc_s_complement_mask >>= 1;
2464 }
2465
2466 /* ++Edmund: reorder the attribute bits */
2467 if (vc->vc_can_do_color) {
2468 unsigned short *cp =
2469 (unsigned short *) vc->vc_origin;
2470 int count = vc->vc_screenbuf_size / 2;
2471 unsigned short c;
2472 for (; count > 0; count--, cp++) {
2473 c = scr_readw(cp);
2474 scr_writew(((c & 0xfe00) >> 1) |
2475 (c & 0xff), cp);
2476 }
2477 c = vc->vc_video_erase_char;
2478 vc->vc_video_erase_char =
2479 ((c & 0xfe00) >> 1) | (c & 0xff);
2480 vc->vc_attr >>= 1;
2481 }
2482 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2483 vc->vc_hi_font_mask = 0x100;
2484 if (vc->vc_can_do_color) {
2485 vc->vc_complement_mask <<= 1;
2486 vc->vc_s_complement_mask <<= 1;
2487 }
2488
2489 /* ++Edmund: reorder the attribute bits */
2490 {
2491 unsigned short *cp =
2492 (unsigned short *) vc->vc_origin;
2493 int count = vc->vc_screenbuf_size / 2;
2494 unsigned short c;
2495 for (; count > 0; count--, cp++) {
2496 unsigned short newc;
2497 c = scr_readw(cp);
2498 if (vc->vc_can_do_color)
2499 newc =
2500 ((c & 0xff00) << 1) | (c &
2501 0xff);
2502 else
2503 newc = c & ~0x100;
2504 scr_writew(newc, cp);
2505 }
2506 c = vc->vc_video_erase_char;
2507 if (vc->vc_can_do_color) {
2508 vc->vc_video_erase_char =
2509 ((c & 0xff00) << 1) | (c & 0xff);
2510 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002511 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 vc->vc_video_erase_char = c & ~0x100;
2513 }
2514
2515 }
2516
2517 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002518 int cols, rows;
2519
2520 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2521 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2522 cols /= w;
2523 rows /= h;
2524 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002525 if (CON_IS_VISIBLE(vc) && softback_buf)
2526 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 } else if (CON_IS_VISIBLE(vc)
2528 && vc->vc_mode == KD_TEXT) {
2529 fbcon_clear_margins(vc, 0);
2530 update_screen(vc);
2531 }
2532
2533 if (old_data && (--REFCOUNT(old_data) == 0))
2534 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2535 return 0;
2536}
2537
2538static int fbcon_copy_font(struct vc_data *vc, int con)
2539{
2540 struct display *od = &fb_display[con];
2541 struct console_font *f = &vc->vc_font;
2542
2543 if (od->fontdata == f->data)
2544 return 0; /* already the same font... */
2545 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2546}
2547
2548/*
2549 * User asked to set font; we are guaranteed that
2550 * a) width and height are in range 1..32
2551 * b) charcount does not exceed 512
2552 * but lets not assume that, since someone might someday want to use larger
2553 * fonts. And charcount of 512 is small for unicode support.
2554 *
2555 * However, user space gives the font in 32 rows , regardless of
2556 * actual font height. So a new API is needed if support for larger fonts
2557 * is ever implemented.
2558 */
2559
2560static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2561{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002562 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 unsigned charcount = font->charcount;
2564 int w = font->width;
2565 int h = font->height;
2566 int size;
2567 int i, csum;
2568 u8 *new_data, *data = font->data;
2569 int pitch = (font->width+7) >> 3;
2570
2571 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2572 * If not this check should be changed to charcount < 256 */
2573 if (charcount != 256 && charcount != 512)
2574 return -EINVAL;
2575
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002576 /* Make sure drawing engine can handle the font */
2577 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2578 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2579 return -EINVAL;
2580
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002581 /* Make sure driver can handle the font length */
2582 if (fbcon_invalid_charcount(info, charcount))
2583 return -EINVAL;
2584
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 size = h * pitch * charcount;
2586
2587 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2588
2589 if (!new_data)
2590 return -ENOMEM;
2591
2592 new_data += FONT_EXTRA_WORDS * sizeof(int);
2593 FNTSIZE(new_data) = size;
2594 FNTCHARCNT(new_data) = charcount;
2595 REFCOUNT(new_data) = 0; /* usage counter */
2596 for (i=0; i< charcount; i++) {
2597 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2598 }
2599
2600 /* Since linux has a nice crc32 function use it for counting font
2601 * checksums. */
2602 csum = crc32(0, new_data, size);
2603
2604 FNTSUM(new_data) = csum;
2605 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002606 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 struct vc_data *tmp = vc_cons[i].d;
2608
2609 if (fb_display[i].userfont &&
2610 fb_display[i].fontdata &&
2611 FNTSUM(fb_display[i].fontdata) == csum &&
2612 FNTSIZE(fb_display[i].fontdata) == size &&
2613 tmp->vc_font.width == w &&
2614 !memcmp(fb_display[i].fontdata, new_data, size)) {
2615 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002616 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 break;
2618 }
2619 }
2620 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2621}
2622
2623static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2624{
2625 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002626 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
2628 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002629 f = get_default_font(info->var.xres, info->var.yres,
2630 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 else if (!(f = find_font(name)))
2632 return -ENOENT;
2633
2634 font->width = f->width;
2635 font->height = f->height;
2636 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2637}
2638
2639static u16 palette_red[16];
2640static u16 palette_green[16];
2641static u16 palette_blue[16];
2642
2643static struct fb_cmap palette_cmap = {
2644 0, 16, palette_red, palette_green, palette_blue, NULL
2645};
2646
2647static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2648{
2649 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2650 int i, j, k, depth;
2651 u8 val;
2652
2653 if (fbcon_is_inactive(vc, info))
2654 return -EINVAL;
2655
2656 if (!CON_IS_VISIBLE(vc))
2657 return 0;
2658
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002659 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 if (depth > 3) {
2661 for (i = j = 0; i < 16; i++) {
2662 k = table[i];
2663 val = vc->vc_palette[j++];
2664 palette_red[k] = (val << 8) | val;
2665 val = vc->vc_palette[j++];
2666 palette_green[k] = (val << 8) | val;
2667 val = vc->vc_palette[j++];
2668 palette_blue[k] = (val << 8) | val;
2669 }
2670 palette_cmap.len = 16;
2671 palette_cmap.start = 0;
2672 /*
2673 * If framebuffer is capable of less than 16 colors,
2674 * use default palette of fbcon.
2675 */
2676 } else
2677 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2678
2679 return fb_set_cmap(&palette_cmap, info);
2680}
2681
2682static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2683{
2684 unsigned long p;
2685 int line;
2686
2687 if (vc->vc_num != fg_console || !softback_lines)
2688 return (u16 *) (vc->vc_origin + offset);
2689 line = offset / vc->vc_size_row;
2690 if (line >= softback_lines)
2691 return (u16 *) (vc->vc_origin + offset -
2692 softback_lines * vc->vc_size_row);
2693 p = softback_curr + offset;
2694 if (p >= softback_end)
2695 p += softback_buf - softback_end;
2696 return (u16 *) p;
2697}
2698
2699static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2700 int *px, int *py)
2701{
2702 unsigned long ret;
2703 int x, y;
2704
2705 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2706 unsigned long offset = (pos - vc->vc_origin) / 2;
2707
2708 x = offset % vc->vc_cols;
2709 y = offset / vc->vc_cols;
2710 if (vc->vc_num == fg_console)
2711 y += softback_lines;
2712 ret = pos + (vc->vc_cols - x) * 2;
2713 } else if (vc->vc_num == fg_console && softback_lines) {
2714 unsigned long offset = pos - softback_curr;
2715
2716 if (pos < softback_curr)
2717 offset += softback_end - softback_buf;
2718 offset /= 2;
2719 x = offset % vc->vc_cols;
2720 y = offset / vc->vc_cols;
2721 ret = pos + (vc->vc_cols - x) * 2;
2722 if (ret == softback_end)
2723 ret = softback_buf;
2724 if (ret == softback_in)
2725 ret = vc->vc_origin;
2726 } else {
2727 /* Should not happen */
2728 x = y = 0;
2729 ret = vc->vc_origin;
2730 }
2731 if (px)
2732 *px = x;
2733 if (py)
2734 *py = y;
2735 return ret;
2736}
2737
2738/* As we might be inside of softback, we may work with non-contiguous buffer,
2739 that's why we have to use a separate routine. */
2740static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2741{
2742 while (cnt--) {
2743 u16 a = scr_readw(p);
2744 if (!vc->vc_can_do_color)
2745 a ^= 0x0800;
2746 else if (vc->vc_hi_font_mask == 0x100)
2747 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2748 (((a) & 0x0e00) << 4);
2749 else
2750 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2751 (((a) & 0x0700) << 4);
2752 scr_writew(a, p++);
2753 if (p == (u16 *) softback_end)
2754 p = (u16 *) softback_buf;
2755 if (p == (u16 *) softback_in)
2756 p = (u16 *) vc->vc_origin;
2757 }
2758}
2759
2760static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2761{
2762 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002763 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002764 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 int offset, limit, scrollback_old;
2766
2767 if (softback_top) {
2768 if (vc->vc_num != fg_console)
2769 return 0;
2770 if (vc->vc_mode != KD_TEXT || !lines)
2771 return 0;
2772 if (logo_shown >= 0) {
2773 struct vc_data *conp2 = vc_cons[logo_shown].d;
2774
2775 if (conp2->vc_top == logo_lines
2776 && conp2->vc_bottom == conp2->vc_rows)
2777 conp2->vc_top = 0;
2778 if (logo_shown == vc->vc_num) {
2779 unsigned long p, q;
2780 int i;
2781
2782 p = softback_in;
2783 q = vc->vc_origin +
2784 logo_lines * vc->vc_size_row;
2785 for (i = 0; i < logo_lines; i++) {
2786 if (p == softback_top)
2787 break;
2788 if (p == softback_buf)
2789 p = softback_end;
2790 p -= vc->vc_size_row;
2791 q -= vc->vc_size_row;
2792 scr_memcpyw((u16 *) q, (u16 *) p,
2793 vc->vc_size_row);
2794 }
David Hollister308af922006-05-30 21:25:36 -07002795 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 update_region(vc, vc->vc_origin,
2797 logo_lines * vc->vc_cols);
2798 }
2799 logo_shown = FBCON_LOGO_CANSHOW;
2800 }
2801 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002802 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2804 return 0;
2805 }
2806
2807 if (!scrollback_phys_max)
2808 return -ENOSYS;
2809
2810 scrollback_old = scrollback_current;
2811 scrollback_current -= lines;
2812 if (scrollback_current < 0)
2813 scrollback_current = 0;
2814 else if (scrollback_current > scrollback_max)
2815 scrollback_current = scrollback_max;
2816 if (scrollback_current == scrollback_old)
2817 return 0;
2818
2819 if (fbcon_is_inactive(vc, info))
2820 return 0;
2821
2822 fbcon_cursor(vc, CM_ERASE);
2823
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002824 offset = disp->yscroll - scrollback_current;
2825 limit = disp->vrows;
2826 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 case SCROLL_WRAP_MOVE:
2828 info->var.vmode |= FB_VMODE_YWRAP;
2829 break;
2830 case SCROLL_PAN_MOVE:
2831 case SCROLL_PAN_REDRAW:
2832 limit -= vc->vc_rows;
2833 info->var.vmode &= ~FB_VMODE_YWRAP;
2834 break;
2835 }
2836 if (offset < 0)
2837 offset += limit;
2838 else if (offset >= limit)
2839 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002840
2841 ops->var.xoffset = 0;
2842 ops->var.yoffset = offset * vc->vc_font.height;
2843 ops->update_start(info);
2844
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 if (!scrollback_current)
2846 fbcon_cursor(vc, CM_DRAW);
2847 return 0;
2848}
2849
2850static int fbcon_set_origin(struct vc_data *vc)
2851{
2852 if (softback_lines)
2853 fbcon_scrolldelta(vc, softback_lines);
2854 return 0;
2855}
2856
2857static void fbcon_suspended(struct fb_info *info)
2858{
2859 struct vc_data *vc = NULL;
2860 struct fbcon_ops *ops = info->fbcon_par;
2861
2862 if (!ops || ops->currcon < 0)
2863 return;
2864 vc = vc_cons[ops->currcon].d;
2865
2866 /* Clear cursor, restore saved data */
2867 fbcon_cursor(vc, CM_ERASE);
2868}
2869
2870static void fbcon_resumed(struct fb_info *info)
2871{
2872 struct vc_data *vc;
2873 struct fbcon_ops *ops = info->fbcon_par;
2874
2875 if (!ops || ops->currcon < 0)
2876 return;
2877 vc = vc_cons[ops->currcon].d;
2878
2879 update_screen(vc);
2880}
2881
2882static void fbcon_modechanged(struct fb_info *info)
2883{
2884 struct fbcon_ops *ops = info->fbcon_par;
2885 struct vc_data *vc;
2886 struct display *p;
2887 int rows, cols;
2888
2889 if (!ops || ops->currcon < 0)
2890 return;
2891 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002892 if (vc->vc_mode != KD_TEXT ||
2893 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 return;
2895
2896 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002897 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
2899 if (CON_IS_VISIBLE(vc)) {
2900 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002901 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2902 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2903 cols /= vc->vc_font.width;
2904 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 vc_resize(vc, cols, rows);
2906 updatescrollmode(p, info, vc);
2907 scrollback_max = 0;
2908 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002909
2910 if (!fbcon_is_inactive(vc, info)) {
2911 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2912 ops->update_start(info);
2913 }
2914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 fbcon_set_palette(vc, color_table);
2916 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002917 if (softback_buf)
2918 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 }
2920}
2921
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002922static void fbcon_set_all_vcs(struct fb_info *info)
2923{
2924 struct fbcon_ops *ops = info->fbcon_par;
2925 struct vc_data *vc;
2926 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002927 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002928
2929 if (!ops || ops->currcon < 0)
2930 return;
2931
Antonino A. Daplase614b182006-06-26 00:27:09 -07002932 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002933 vc = vc_cons[i].d;
2934 if (!vc || vc->vc_mode != KD_TEXT ||
2935 registered_fb[con2fb_map[i]] != info)
2936 continue;
2937
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002938 if (CON_IS_VISIBLE(vc)) {
2939 fg = i;
2940 continue;
2941 }
2942
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002943 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002944 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002945 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002946 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2947 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002948 cols /= vc->vc_font.width;
2949 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002950 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002951 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002952
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002953 if (fg != -1)
2954 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002955}
2956
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957static int fbcon_mode_deleted(struct fb_info *info,
2958 struct fb_videomode *mode)
2959{
2960 struct fb_info *fb_info;
2961 struct display *p;
2962 int i, j, found = 0;
2963
2964 /* before deletion, ensure that mode is not in use */
2965 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2966 j = con2fb_map[i];
2967 if (j == -1)
2968 continue;
2969 fb_info = registered_fb[j];
2970 if (fb_info != info)
2971 continue;
2972 p = &fb_display[i];
2973 if (!p || !p->mode)
2974 continue;
2975 if (fb_mode_is_equal(p->mode, mode)) {
2976 found = 1;
2977 break;
2978 }
2979 }
2980 return found;
2981}
2982
Jesse Barnescfafca82007-07-17 04:05:33 -07002983#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2984static int fbcon_unbind(void)
2985{
2986 int ret;
2987
2988 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2989 fbcon_is_default);
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07002990
2991 if (!ret)
2992 fbcon_has_console_bind = 0;
2993
Jesse Barnescfafca82007-07-17 04:05:33 -07002994 return ret;
2995}
2996#else
2997static inline int fbcon_unbind(void)
2998{
2999 return -EINVAL;
3000}
3001#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3002
3003static int fbcon_fb_unbind(int idx)
3004{
3005 int i, new_idx = -1, ret = 0;
3006
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003007 if (!fbcon_has_console_bind)
3008 return 0;
3009
Jesse Barnescfafca82007-07-17 04:05:33 -07003010 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3011 if (con2fb_map[i] != idx &&
3012 con2fb_map[i] != -1) {
3013 new_idx = i;
3014 break;
3015 }
3016 }
3017
3018 if (new_idx != -1) {
3019 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3020 if (con2fb_map[i] == idx)
3021 set_con2fb_map(i, new_idx, 0);
3022 }
3023 } else
3024 ret = fbcon_unbind();
3025
3026 return ret;
3027}
3028
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003029static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003030{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003031 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003032
Andrea Righi66c1ca02009-03-31 15:25:18 -07003033 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003034 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3035 if (con2fb_map[i] == idx)
3036 con2fb_map[i] = -1;
3037 }
3038
3039 if (idx == info_idx) {
3040 info_idx = -1;
3041
3042 for (i = 0; i < FB_MAX; i++) {
3043 if (registered_fb[i] != NULL) {
3044 info_idx = i;
3045 break;
3046 }
3047 }
3048 }
3049
3050 if (info_idx != -1) {
3051 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3052 if (con2fb_map[i] == -1)
3053 con2fb_map[i] = info_idx;
3054 }
3055 }
3056
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003057 if (primary_device == idx)
3058 primary_device = -1;
3059
Andrea Righi66c1ca02009-03-31 15:25:18 -07003060 if (!num_registered_fb)
3061 unregister_con_driver(&fb_con);
3062
Antonino A. Daplase614b182006-06-26 00:27:09 -07003063 return 0;
3064}
3065
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003066static void fbcon_remap_all(int idx)
3067{
3068 int i;
3069 for (i = first_fb_vc; i <= last_fb_vc; i++)
3070 set_con2fb_map(i, idx, 0);
3071
3072 if (con_is_bound(&fb_con)) {
3073 printk(KERN_INFO "fbcon: Remapping primary device, "
3074 "fb%i, to tty %i-%i\n", idx,
3075 first_fb_vc + 1, last_fb_vc + 1);
3076 info_idx = idx;
3077 }
3078}
3079
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003080#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003081static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003083 if (!map_override && primary_device == -1 &&
3084 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003085 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003086
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003087 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3088 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003089 primary_device = info->node;
3090
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003091 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003092 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003093
3094 if (con_is_bound(&fb_con)) {
3095 printk(KERN_INFO "fbcon: Remapping primary device, "
3096 "fb%i, to tty %i-%i\n", info->node,
3097 first_fb_vc + 1, last_fb_vc + 1);
3098 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003099 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003100 }
3101
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003102}
3103#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003104static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003105{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003106 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003107}
3108#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3109
3110static int fbcon_fb_registered(struct fb_info *info)
3111{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003112 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003113
Andrea Righi66c1ca02009-03-31 15:25:18 -07003114 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003115 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
3117 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003118 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 if (con2fb_map_boot[i] == idx) {
3120 info_idx = idx;
3121 break;
3122 }
3123 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003124
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 if (info_idx != -1)
3126 ret = fbcon_takeover(1);
3127 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003128 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003129 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 set_con2fb_map(i, idx, 0);
3131 }
3132 }
3133
3134 return ret;
3135}
3136
3137static void fbcon_fb_blanked(struct fb_info *info, int blank)
3138{
3139 struct fbcon_ops *ops = info->fbcon_par;
3140 struct vc_data *vc;
3141
3142 if (!ops || ops->currcon < 0)
3143 return;
3144
3145 vc = vc_cons[ops->currcon].d;
3146 if (vc->vc_mode != KD_TEXT ||
3147 registered_fb[con2fb_map[ops->currcon]] != info)
3148 return;
3149
3150 if (CON_IS_VISIBLE(vc)) {
3151 if (blank)
3152 do_blank_screen(0);
3153 else
3154 do_unblank_screen(0);
3155 }
3156 ops->blank_state = blank;
3157}
3158
3159static void fbcon_new_modelist(struct fb_info *info)
3160{
3161 int i;
3162 struct vc_data *vc;
3163 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003164 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
Antonino A. Daplase614b182006-06-26 00:27:09 -07003166 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 if (registered_fb[con2fb_map[i]] != info)
3168 continue;
3169 if (!fb_display[i].mode)
3170 continue;
3171 vc = vc_cons[i].d;
3172 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003173 mode = fb_find_nearest_mode(fb_display[i].mode,
3174 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003176 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 }
3178}
3179
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003180static void fbcon_get_requirement(struct fb_info *info,
3181 struct fb_blit_caps *caps)
3182{
3183 struct vc_data *vc;
3184 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003185
3186 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003187 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003188
3189 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3190 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003191 if (vc && vc->vc_mode == KD_TEXT &&
3192 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003193 p = &fb_display[i];
3194 caps->x |= 1 << (vc->vc_font.width - 1);
3195 caps->y |= 1 << (vc->vc_font.height - 1);
3196 charcnt = (p->userfont) ?
3197 FNTCHARCNT(p->fontdata) : 256;
3198 if (caps->len < charcnt)
3199 caps->len = charcnt;
3200 }
3201 }
3202 } else {
3203 vc = vc_cons[fg_console].d;
3204
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003205 if (vc && vc->vc_mode == KD_TEXT &&
3206 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003207 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003208 caps->x = 1 << (vc->vc_font.width - 1);
3209 caps->y = 1 << (vc->vc_font.height - 1);
3210 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003211 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003212 }
3213 }
3214}
3215
Andrea Righi66c1ca02009-03-31 15:25:18 -07003216static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 unsigned long action, void *data)
3218{
3219 struct fb_event *event = data;
3220 struct fb_info *info = event->info;
3221 struct fb_videomode *mode;
3222 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003223 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003224 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
Antonino A. Daplase614b182006-06-26 00:27:09 -07003226 /*
3227 * ignore all events except driver registration and deregistration
3228 * if fbcon is not active
3229 */
3230 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3231 action == FB_EVENT_FB_UNREGISTERED))
3232 goto done;
3233
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 switch(action) {
3235 case FB_EVENT_SUSPEND:
3236 fbcon_suspended(info);
3237 break;
3238 case FB_EVENT_RESUME:
3239 fbcon_resumed(info);
3240 break;
3241 case FB_EVENT_MODE_CHANGE:
3242 fbcon_modechanged(info);
3243 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003244 case FB_EVENT_MODE_CHANGE_ALL:
3245 fbcon_set_all_vcs(info);
3246 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 case FB_EVENT_MODE_DELETE:
3248 mode = event->data;
3249 ret = fbcon_mode_deleted(info, mode);
3250 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003251 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003252 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003253 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003254 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003256 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003258 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003259 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003260 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 case FB_EVENT_SET_CONSOLE_MAP:
3262 con2fb = event->data;
3263 ret = set_con2fb_map(con2fb->console - 1,
3264 con2fb->framebuffer, 1);
3265 break;
3266 case FB_EVENT_GET_CONSOLE_MAP:
3267 con2fb = event->data;
3268 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3269 break;
3270 case FB_EVENT_BLANK:
3271 fbcon_fb_blanked(info, *(int *)event->data);
3272 break;
3273 case FB_EVENT_NEW_MODELIST:
3274 fbcon_new_modelist(info);
3275 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003276 case FB_EVENT_GET_REQ:
3277 caps = event->data;
3278 fbcon_get_requirement(info, caps);
3279 break;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003280 case FB_EVENT_REMAP_ALL_CONSOLE:
3281 idx = info->node;
3282 fbcon_remap_all(idx);
3283 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003285done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 return ret;
3287}
3288
3289/*
3290 * The console `switch' structure for the frame buffer based console
3291 */
3292
3293static const struct consw fb_con = {
3294 .owner = THIS_MODULE,
3295 .con_startup = fbcon_startup,
3296 .con_init = fbcon_init,
3297 .con_deinit = fbcon_deinit,
3298 .con_clear = fbcon_clear,
3299 .con_putc = fbcon_putc,
3300 .con_putcs = fbcon_putcs,
3301 .con_cursor = fbcon_cursor,
3302 .con_scroll = fbcon_scroll,
3303 .con_bmove = fbcon_bmove,
3304 .con_switch = fbcon_switch,
3305 .con_blank = fbcon_blank,
3306 .con_font_set = fbcon_set_font,
3307 .con_font_get = fbcon_get_font,
3308 .con_font_default = fbcon_set_def_font,
3309 .con_font_copy = fbcon_copy_font,
3310 .con_set_palette = fbcon_set_palette,
3311 .con_scrolldelta = fbcon_scrolldelta,
3312 .con_set_origin = fbcon_set_origin,
3313 .con_invert_region = fbcon_invert_region,
3314 .con_screen_pos = fbcon_screen_pos,
3315 .con_getxy = fbcon_getxy,
3316 .con_resize = fbcon_resize,
Jesse Barnesd219adc2010-08-02 12:05:41 -07003317 .con_debug_enter = fbcon_debug_enter,
3318 .con_debug_leave = fbcon_debug_leave,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319};
3320
3321static struct notifier_block fbcon_event_notifier = {
3322 .notifier_call = fbcon_event_notify,
3323};
3324
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003325static ssize_t store_rotate(struct device *device,
3326 struct device_attribute *attr, const char *buf,
3327 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003328{
3329 struct fb_info *info;
3330 int rotate, idx;
3331 char **last = NULL;
3332
Antonino A. Daplase614b182006-06-26 00:27:09 -07003333 if (fbcon_has_exited)
3334 return count;
3335
Torben Hohnac751ef2011-01-25 15:07:35 -08003336 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003337 idx = con2fb_map[fg_console];
3338
3339 if (idx == -1 || registered_fb[idx] == NULL)
3340 goto err;
3341
3342 info = registered_fb[idx];
3343 rotate = simple_strtoul(buf, last, 0);
3344 fbcon_rotate(info, rotate);
3345err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003346 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003347 return count;
3348}
3349
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003350static ssize_t store_rotate_all(struct device *device,
3351 struct device_attribute *attr,const char *buf,
3352 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003353{
3354 struct fb_info *info;
3355 int rotate, idx;
3356 char **last = NULL;
3357
Antonino A. Daplase614b182006-06-26 00:27:09 -07003358 if (fbcon_has_exited)
3359 return count;
3360
Torben Hohnac751ef2011-01-25 15:07:35 -08003361 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003362 idx = con2fb_map[fg_console];
3363
3364 if (idx == -1 || registered_fb[idx] == NULL)
3365 goto err;
3366
3367 info = registered_fb[idx];
3368 rotate = simple_strtoul(buf, last, 0);
3369 fbcon_rotate_all(info, rotate);
3370err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003371 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003372 return count;
3373}
3374
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003375static ssize_t show_rotate(struct device *device,
3376 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003377{
3378 struct fb_info *info;
3379 int rotate = 0, idx;
3380
Antonino A. Daplase614b182006-06-26 00:27:09 -07003381 if (fbcon_has_exited)
3382 return 0;
3383
Torben Hohnac751ef2011-01-25 15:07:35 -08003384 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003385 idx = con2fb_map[fg_console];
3386
3387 if (idx == -1 || registered_fb[idx] == NULL)
3388 goto err;
3389
3390 info = registered_fb[idx];
3391 rotate = fbcon_get_rotate(info);
3392err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003393 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003394 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3395}
3396
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003397static ssize_t show_cursor_blink(struct device *device,
3398 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003399{
3400 struct fb_info *info;
3401 struct fbcon_ops *ops;
3402 int idx, blink = -1;
3403
3404 if (fbcon_has_exited)
3405 return 0;
3406
Torben Hohnac751ef2011-01-25 15:07:35 -08003407 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003408 idx = con2fb_map[fg_console];
3409
3410 if (idx == -1 || registered_fb[idx] == NULL)
3411 goto err;
3412
3413 info = registered_fb[idx];
3414 ops = info->fbcon_par;
3415
3416 if (!ops)
3417 goto err;
3418
3419 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3420err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003421 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003422 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3423}
3424
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003425static ssize_t store_cursor_blink(struct device *device,
3426 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003427 const char *buf, size_t count)
3428{
3429 struct fb_info *info;
3430 int blink, idx;
3431 char **last = NULL;
3432
3433 if (fbcon_has_exited)
3434 return count;
3435
Torben Hohnac751ef2011-01-25 15:07:35 -08003436 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003437 idx = con2fb_map[fg_console];
3438
3439 if (idx == -1 || registered_fb[idx] == NULL)
3440 goto err;
3441
3442 info = registered_fb[idx];
3443
3444 if (!info->fbcon_par)
3445 goto err;
3446
3447 blink = simple_strtoul(buf, last, 0);
3448
3449 if (blink) {
3450 fbcon_cursor_noblink = 0;
3451 fbcon_add_cursor_timer(info);
3452 } else {
3453 fbcon_cursor_noblink = 1;
3454 fbcon_del_cursor_timer(info);
3455 }
3456
3457err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003458 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003459 return count;
3460}
3461
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003462static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003463 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3464 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003465 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3466 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003467};
3468
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003469static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003470{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003471 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003472
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003473 fbcon_has_sysfs = 1;
3474
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003475 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3476 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003477
3478 if (error)
3479 break;
3480 }
3481
3482 if (error) {
3483 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003484 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003485
3486 fbcon_has_sysfs = 0;
3487 }
3488
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003489 return 0;
3490}
3491
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003492static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003495 int i;
3496
Torben Hohnac751ef2011-01-25 15:07:35 -08003497 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003498
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 for (i = 0; i < FB_MAX; i++) {
3500 if (registered_fb[i] != NULL) {
3501 info_idx = i;
3502 break;
3503 }
3504 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003505
Torben Hohnac751ef2011-01-25 15:07:35 -08003506 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 fbcon_takeover(0);
3508 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509}
3510
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003511static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003512{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003513 struct fb_info *info;
3514 int i, j, mapped;
3515
Antonino A. Daplase614b182006-06-26 00:27:09 -07003516 if (fbcon_has_exited)
3517 return;
3518
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003519 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003520 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003521
3522 for (i = 0; i < FB_MAX; i++) {
Jarek Poplawski142092e2010-09-22 13:05:05 -07003523 int pending = 0;
Geoff Levandbeaa4862008-12-09 13:14:17 -08003524
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003525 mapped = 0;
3526 info = registered_fb[i];
3527
3528 if (info == NULL)
3529 continue;
3530
Jarek Poplawski142092e2010-09-22 13:05:05 -07003531 if (info->queue.func)
3532 pending = cancel_work_sync(&info->queue);
Geoff Levandbeaa4862008-12-09 13:14:17 -08003533 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3534 "no"));
3535
Antonino A. Daplase614b182006-06-26 00:27:09 -07003536 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3537 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003538 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003539 }
3540
3541 if (mapped) {
3542 if (info->fbops->fb_release)
3543 info->fbops->fb_release(info, 0);
3544 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003545
3546 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003547 struct fbcon_ops *ops = info->fbcon_par;
3548
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003549 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003550 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003551 kfree(info->fbcon_par);
3552 info->fbcon_par = NULL;
3553 }
3554
3555 if (info->queue.func == fb_flashcursor)
3556 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003557 }
3558 }
3559
Antonino A. Daplase614b182006-06-26 00:27:09 -07003560 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003561}
3562
3563static int __init fb_console_init(void)
3564{
3565 int i;
3566
Torben Hohnac751ef2011-01-25 15:07:35 -08003567 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003568 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003569 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3570 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003571
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003572 if (IS_ERR(fbcon_device)) {
3573 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003574 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003575 PTR_ERR(fbcon_device));
3576 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003577 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003578 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003579
3580 for (i = 0; i < MAX_NR_CONSOLES; i++)
3581 con2fb_map[i] = -1;
3582
Torben Hohnac751ef2011-01-25 15:07:35 -08003583 console_unlock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003584 fbcon_start();
3585 return 0;
3586}
3587
3588module_init(fb_console_init);
3589
3590#ifdef MODULE
3591
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003592static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003593{
3594 int i;
3595
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003596 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003597 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3598 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003599
3600 fbcon_has_sysfs = 0;
3601 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003602}
3603
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604static void __exit fb_console_exit(void)
3605{
Torben Hohnac751ef2011-01-25 15:07:35 -08003606 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003608 fbcon_deinit_device();
3609 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003610 fbcon_exit();
Torben Hohnac751ef2011-01-25 15:07:35 -08003611 console_unlock();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003612 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613}
3614
3615module_exit(fb_console_exit);
3616
3617#endif
3618
3619MODULE_LICENSE("GPL");