blob: f8dbe76a1b6f56649e5109e6e74c000aed00176b [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 */
Dave Airlieae128782013-01-24 16:12:41 +1000993 if (!p->fontdata && !vc->vc_font.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 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 */
Dave Airlieae128782013-01-24 16:12:41 +10001003 } else {
1004 p->fontdata = vc->vc_font.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 }
1006
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001007 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1008 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1009 cols /= vc->vc_font.width;
1010 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 vc_resize(vc, cols, rows);
1012
1013 DPRINTK("mode: %s\n", info->fix.id);
1014 DPRINTK("visual: %d\n", info->fix.visual);
1015 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1016 info->var.yres,
1017 info->var.bits_per_pixel);
1018
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001019 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001020 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 return display_desc;
1022}
1023
1024static void fbcon_init(struct vc_data *vc, int init)
1025{
1026 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1027 struct fbcon_ops *ops;
1028 struct vc_data **default_mode = vc->vc_display_fg;
1029 struct vc_data *svc = *default_mode;
1030 struct display *t, *p = &fb_display[vc->vc_num];
1031 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001032 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 if (info_idx == -1 || info == NULL)
1035 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001036
1037 cap = info->flags;
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1040 (info->fix.type == FB_TYPE_TEXT))
1041 logo = 0;
1042
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if (var_to_display(p, &info->var, info))
1044 return;
1045
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001046 if (!info->fbcon_par)
1047 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 /* If we are not the first console on this
1050 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001051 t = &fb_display[fg_console];
1052 if (!p->fontdata) {
1053 if (t->fontdata) {
1054 struct vc_data *fvc = vc_cons[fg_console].d;
1055
1056 vc->vc_font.data = (void *)(p->fontdata =
1057 fvc->vc_font.data);
1058 vc->vc_font.width = fvc->vc_font.width;
1059 vc->vc_font.height = fvc->vc_font.height;
1060 p->userfont = t->userfont;
1061
1062 if (p->userfont)
1063 REFCOUNT(p->fontdata)++;
1064 } else {
1065 const struct font_desc *font = NULL;
1066
1067 if (!fontname[0] || !(font = find_font(fontname)))
1068 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001069 info->var.yres,
1070 info->pixmap.blit_x,
1071 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001072 vc->vc_font.width = font->width;
1073 vc->vc_font.height = font->height;
1074 vc->vc_font.data = (void *)(p->fontdata = font->data);
1075 vc->vc_font.charcount = 256; /* FIXME Need to
1076 support more fonts */
1077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001079
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 if (p->userfont)
1081 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001082
Jesse Barnes8fd4bd22010-06-23 12:56:12 -07001083 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001084 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1086 if (charcnt == 256) {
1087 vc->vc_hi_font_mask = 0;
1088 } else {
1089 vc->vc_hi_font_mask = 0x100;
1090 if (vc->vc_can_do_color)
1091 vc->vc_complement_mask <<= 1;
1092 }
1093
1094 if (!*svc->vc_uni_pagedir_loc)
1095 con_set_default_unimap(svc);
1096 if (!*vc->vc_uni_pagedir_loc)
1097 con_copy_unimap(vc, svc);
1098
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001099 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001100 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001101 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001102
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 cols = vc->vc_cols;
1104 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001105 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1106 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1107 new_cols /= vc->vc_font.width;
1108 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 /*
1111 * We must always set the mode. The mode of the previous console
1112 * driver could be in the same resolution but we are using different
1113 * hardware so we have to initialize the hardware.
1114 *
1115 * We need to do it in fbcon_init() to prevent screen corruption.
1116 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001117 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001119 !(ops->flags & FBCON_FLAGS_INIT)) {
1120 ret = info->fbops->fb_set_par(info);
1121
1122 if (ret)
1123 printk(KERN_ERR "fbcon_init: detected "
1124 "unhandled fb_set_par error, "
1125 "error code %d\n", ret);
1126 }
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 ops->flags |= FBCON_FLAGS_INIT;
1129 }
1130
1131 ops->graphics = 0;
1132
1133 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1134 !(cap & FBINFO_HWACCEL_DISABLED))
1135 p->scrollmode = SCROLL_MOVE;
1136 else /* default to something safe */
1137 p->scrollmode = SCROLL_REDRAW;
1138
1139 /*
1140 * ++guenther: console.c:vc_allocate() relies on initializing
1141 * vc_{cols,rows}, but we must not set those if we are only
1142 * resizing the console.
1143 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001144 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 vc->vc_cols = new_cols;
1146 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001147 } else
1148 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 if (logo)
1151 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1152
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001153 if (vc == svc && softback_buf)
1154 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001155
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001156 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001157 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001158 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001159 }
1160
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001161 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Dave Airlieae128782013-01-24 16:12:41 +10001164static void fbcon_free_font(struct display *p, bool freefont)
Antonino A. Daplase614b182006-06-26 00:27:09 -07001165{
Dave Airlieae128782013-01-24 16:12:41 +10001166 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001167 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1168 p->fontdata = NULL;
1169 p->userfont = 0;
1170}
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172static void fbcon_deinit(struct vc_data *vc)
1173{
1174 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001175 struct fb_info *info;
1176 struct fbcon_ops *ops;
1177 int idx;
Dave Airlieae128782013-01-24 16:12:41 +10001178 bool free_font = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Antonino A. Daplase614b182006-06-26 00:27:09 -07001180 idx = con2fb_map[vc->vc_num];
1181
1182 if (idx == -1)
1183 goto finished;
1184
1185 info = registered_fb[idx];
1186
1187 if (!info)
1188 goto finished;
1189
Dave Airlieae128782013-01-24 16:12:41 +10001190 if (info->flags & FBINFO_MISC_FIRMWARE)
1191 free_font = false;
Antonino A. Daplase614b182006-06-26 00:27:09 -07001192 ops = info->fbcon_par;
1193
1194 if (!ops)
1195 goto finished;
1196
1197 if (CON_IS_VISIBLE(vc))
1198 fbcon_del_cursor_timer(info);
1199
1200 ops->flags &= ~FBCON_FLAGS_INIT;
1201finished:
1202
Dave Airlieae128782013-01-24 16:12:41 +10001203 fbcon_free_font(p, free_font);
1204
Antonino A. Daplase614b182006-06-26 00:27:09 -07001205 if (!con_is_bound(&fb_con))
1206 fbcon_exit();
1207
1208 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
1211/* ====================================================================== */
1212
1213/* fbcon_XXX routines - interface used by the world
1214 *
1215 * This system is now divided into two levels because of complications
1216 * caused by hardware scrolling. Top level functions:
1217 *
1218 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1219 *
1220 * handles y values in range [0, scr_height-1] that correspond to real
1221 * screen positions. y_wrap shift means that first line of bitmap may be
1222 * anywhere on this display. These functions convert lineoffsets to
1223 * bitmap offsets and deal with the wrap-around case by splitting blits.
1224 *
1225 * fbcon_bmove_physical_8() -- These functions fast implementations
1226 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1227 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1228 *
1229 * WARNING:
1230 *
1231 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1232 * Implies should only really hardware scroll in rows. Only reason for
1233 * restriction is simplicity & efficiency at the moment.
1234 */
1235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1237 int width)
1238{
1239 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1240 struct fbcon_ops *ops = info->fbcon_par;
1241
1242 struct display *p = &fb_display[vc->vc_num];
1243 u_int y_break;
1244
1245 if (fbcon_is_inactive(vc, info))
1246 return;
1247
1248 if (!height || !width)
1249 return;
1250
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001251 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1252 vc->vc_top = 0;
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 /* Split blits that cross physical y_wrap boundary */
1255
1256 y_break = p->vrows - p->yscroll;
1257 if (sy < y_break && sy + height - 1 >= y_break) {
1258 u_int b = y_break - sy;
1259 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1260 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1261 width);
1262 } else
1263 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1264}
1265
1266static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1267 int count, int ypos, int xpos)
1268{
1269 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1270 struct display *p = &fb_display[vc->vc_num];
1271 struct fbcon_ops *ops = info->fbcon_par;
1272
1273 if (!fbcon_is_inactive(vc, info))
1274 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1275 get_color(vc, info, scr_readw(s), 1),
1276 get_color(vc, info, scr_readw(s), 0));
1277}
1278
1279static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1280{
1281 unsigned short chr;
1282
1283 scr_writew(c, &chr);
1284 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1285}
1286
1287static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1288{
1289 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1290 struct fbcon_ops *ops = info->fbcon_par;
1291
1292 if (!fbcon_is_inactive(vc, info))
1293 ops->clear_margins(vc, info, bottom_only);
1294}
1295
1296static void fbcon_cursor(struct vc_data *vc, int mode)
1297{
1298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1299 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 int y;
1301 int c = scr_readw((u16 *) vc->vc_pos);
1302
Michal Januszewskid1e23062007-05-08 00:38:07 -07001303 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 return;
1305
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001306 if (vc->vc_cursor_type & 0x10)
1307 fbcon_del_cursor_timer(info);
1308 else
1309 fbcon_add_cursor_timer(info);
1310
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1312 if (mode & CM_SOFTBACK) {
1313 mode &= ~CM_SOFTBACK;
1314 y = softback_lines;
1315 } else {
1316 if (softback_lines)
1317 fbcon_set_origin(vc);
1318 y = 0;
1319 }
1320
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001321 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 get_color(vc, info, c, 0));
1323 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1324}
1325
1326static int scrollback_phys_max = 0;
1327static int scrollback_max = 0;
1328static int scrollback_current = 0;
1329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001331 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001333 struct display *p, *t;
1334 struct vc_data **default_mode, *vc;
1335 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001336 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 int rows, cols, charcnt = 256;
1338
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001339 p = &fb_display[unit];
1340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 if (var_to_display(p, var, info))
1342 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001343
1344 vc = vc_cons[unit].d;
1345
1346 if (!vc)
1347 return;
1348
1349 default_mode = vc->vc_display_fg;
1350 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001354 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 vc->vc_font.width = (*default_mode)->vc_font.width;
1356 vc->vc_font.height = (*default_mode)->vc_font.height;
1357 p->userfont = t->userfont;
1358 if (p->userfont)
1359 REFCOUNT(p->fontdata)++;
1360 }
1361 if (p->userfont)
1362 charcnt = FNTCHARCNT(p->fontdata);
1363
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001364 var->activate = FB_ACTIVATE_NOW;
1365 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001366 var->yoffset = info->var.yoffset;
1367 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001368 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001369 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001370 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1372 if (charcnt == 256) {
1373 vc->vc_hi_font_mask = 0;
1374 } else {
1375 vc->vc_hi_font_mask = 0x100;
1376 if (vc->vc_can_do_color)
1377 vc->vc_complement_mask <<= 1;
1378 }
1379
1380 if (!*svc->vc_uni_pagedir_loc)
1381 con_set_default_unimap(svc);
1382 if (!*vc->vc_uni_pagedir_loc)
1383 con_copy_unimap(vc, svc);
1384
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001385 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1386 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1387 cols /= vc->vc_font.width;
1388 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001390
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 if (CON_IS_VISIBLE(vc)) {
1392 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001393 if (softback_buf)
1394 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 }
1396}
1397
1398static __inline__ void ywrap_up(struct vc_data *vc, int count)
1399{
1400 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001401 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 struct display *p = &fb_display[vc->vc_num];
1403
1404 p->yscroll += count;
1405 if (p->yscroll >= p->vrows) /* Deal with wrap */
1406 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001407 ops->var.xoffset = 0;
1408 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1409 ops->var.vmode |= FB_VMODE_YWRAP;
1410 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 scrollback_max += count;
1412 if (scrollback_max > scrollback_phys_max)
1413 scrollback_max = scrollback_phys_max;
1414 scrollback_current = 0;
1415}
1416
1417static __inline__ void ywrap_down(struct vc_data *vc, int count)
1418{
1419 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001420 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 struct display *p = &fb_display[vc->vc_num];
1422
1423 p->yscroll -= count;
1424 if (p->yscroll < 0) /* Deal with wrap */
1425 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001426 ops->var.xoffset = 0;
1427 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1428 ops->var.vmode |= FB_VMODE_YWRAP;
1429 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 scrollback_max -= count;
1431 if (scrollback_max < 0)
1432 scrollback_max = 0;
1433 scrollback_current = 0;
1434}
1435
1436static __inline__ void ypan_up(struct vc_data *vc, int count)
1437{
1438 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1439 struct display *p = &fb_display[vc->vc_num];
1440 struct fbcon_ops *ops = info->fbcon_par;
1441
1442 p->yscroll += count;
1443 if (p->yscroll > p->vrows - vc->vc_rows) {
1444 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1445 0, 0, 0, vc->vc_rows, vc->vc_cols);
1446 p->yscroll -= p->vrows - vc->vc_rows;
1447 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001448
1449 ops->var.xoffset = 0;
1450 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1451 ops->var.vmode &= ~FB_VMODE_YWRAP;
1452 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 fbcon_clear_margins(vc, 1);
1454 scrollback_max += count;
1455 if (scrollback_max > scrollback_phys_max)
1456 scrollback_max = scrollback_phys_max;
1457 scrollback_current = 0;
1458}
1459
1460static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1461{
1462 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001463 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
1466 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 if (p->yscroll > p->vrows - vc->vc_rows) {
1469 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001471 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001472
1473 ops->var.xoffset = 0;
1474 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1475 ops->var.vmode &= ~FB_VMODE_YWRAP;
1476 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 fbcon_clear_margins(vc, 1);
1478 scrollback_max += count;
1479 if (scrollback_max > scrollback_phys_max)
1480 scrollback_max = scrollback_phys_max;
1481 scrollback_current = 0;
1482}
1483
1484static __inline__ void ypan_down(struct vc_data *vc, int count)
1485{
1486 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1487 struct display *p = &fb_display[vc->vc_num];
1488 struct fbcon_ops *ops = info->fbcon_par;
1489
1490 p->yscroll -= count;
1491 if (p->yscroll < 0) {
1492 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1493 0, vc->vc_rows, vc->vc_cols);
1494 p->yscroll += p->vrows - vc->vc_rows;
1495 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001496
1497 ops->var.xoffset = 0;
1498 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1499 ops->var.vmode &= ~FB_VMODE_YWRAP;
1500 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 fbcon_clear_margins(vc, 1);
1502 scrollback_max -= count;
1503 if (scrollback_max < 0)
1504 scrollback_max = 0;
1505 scrollback_current = 0;
1506}
1507
1508static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1509{
1510 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001511 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 if (p->yscroll < 0) {
1517 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001519 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001520
1521 ops->var.xoffset = 0;
1522 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1523 ops->var.vmode &= ~FB_VMODE_YWRAP;
1524 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 fbcon_clear_margins(vc, 1);
1526 scrollback_max -= count;
1527 if (scrollback_max < 0)
1528 scrollback_max = 0;
1529 scrollback_current = 0;
1530}
1531
1532static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1533 long delta)
1534{
1535 int count = vc->vc_rows;
1536 unsigned short *d, *s;
1537 unsigned long n;
1538 int line = 0;
1539
1540 d = (u16 *) softback_curr;
1541 if (d == (u16 *) softback_in)
1542 d = (u16 *) vc->vc_origin;
1543 n = softback_curr + delta * vc->vc_size_row;
1544 softback_lines -= delta;
1545 if (delta < 0) {
1546 if (softback_curr < softback_top && n < softback_buf) {
1547 n += softback_end - softback_buf;
1548 if (n < softback_top) {
1549 softback_lines -=
1550 (softback_top - n) / vc->vc_size_row;
1551 n = softback_top;
1552 }
1553 } else if (softback_curr >= softback_top
1554 && n < softback_top) {
1555 softback_lines -=
1556 (softback_top - n) / vc->vc_size_row;
1557 n = softback_top;
1558 }
1559 } else {
1560 if (softback_curr > softback_in && n >= softback_end) {
1561 n += softback_buf - softback_end;
1562 if (n > softback_in) {
1563 n = softback_in;
1564 softback_lines = 0;
1565 }
1566 } else if (softback_curr <= softback_in && n > softback_in) {
1567 n = softback_in;
1568 softback_lines = 0;
1569 }
1570 }
1571 if (n == softback_curr)
1572 return;
1573 softback_curr = n;
1574 s = (u16 *) softback_curr;
1575 if (s == (u16 *) softback_in)
1576 s = (u16 *) vc->vc_origin;
1577 while (count--) {
1578 unsigned short *start;
1579 unsigned short *le;
1580 unsigned short c;
1581 int x = 0;
1582 unsigned short attr = 1;
1583
1584 start = s;
1585 le = advance_row(s, 1);
1586 do {
1587 c = scr_readw(s);
1588 if (attr != (c & 0xff00)) {
1589 attr = c & 0xff00;
1590 if (s > start) {
1591 fbcon_putcs(vc, start, s - start,
1592 line, x);
1593 x += s - start;
1594 start = s;
1595 }
1596 }
1597 if (c == scr_readw(d)) {
1598 if (s > start) {
1599 fbcon_putcs(vc, start, s - start,
1600 line, x);
1601 x += s - start + 1;
1602 start = s + 1;
1603 } else {
1604 x++;
1605 start++;
1606 }
1607 }
1608 s++;
1609 d++;
1610 } while (s < le);
1611 if (s > start)
1612 fbcon_putcs(vc, start, s - start, line, x);
1613 line++;
1614 if (d == (u16 *) softback_end)
1615 d = (u16 *) softback_buf;
1616 if (d == (u16 *) softback_in)
1617 d = (u16 *) vc->vc_origin;
1618 if (s == (u16 *) softback_end)
1619 s = (u16 *) softback_buf;
1620 if (s == (u16 *) softback_in)
1621 s = (u16 *) vc->vc_origin;
1622 }
1623}
1624
1625static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1626 int line, int count, int dy)
1627{
1628 unsigned short *s = (unsigned short *)
1629 (vc->vc_origin + vc->vc_size_row * line);
1630
1631 while (count--) {
1632 unsigned short *start = s;
1633 unsigned short *le = advance_row(s, 1);
1634 unsigned short c;
1635 int x = 0;
1636 unsigned short attr = 1;
1637
1638 do {
1639 c = scr_readw(s);
1640 if (attr != (c & 0xff00)) {
1641 attr = c & 0xff00;
1642 if (s > start) {
1643 fbcon_putcs(vc, start, s - start,
1644 dy, x);
1645 x += s - start;
1646 start = s;
1647 }
1648 }
1649 console_conditional_schedule();
1650 s++;
1651 } while (s < le);
1652 if (s > start)
1653 fbcon_putcs(vc, start, s - start, dy, x);
1654 console_conditional_schedule();
1655 dy++;
1656 }
1657}
1658
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001659static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1660 struct display *p, int line, int count, int ycount)
1661{
1662 int offset = ycount * vc->vc_cols;
1663 unsigned short *d = (unsigned short *)
1664 (vc->vc_origin + vc->vc_size_row * line);
1665 unsigned short *s = d + offset;
1666 struct fbcon_ops *ops = info->fbcon_par;
1667
1668 while (count--) {
1669 unsigned short *start = s;
1670 unsigned short *le = advance_row(s, 1);
1671 unsigned short c;
1672 int x = 0;
1673
1674 do {
1675 c = scr_readw(s);
1676
1677 if (c == scr_readw(d)) {
1678 if (s > start) {
1679 ops->bmove(vc, info, line + ycount, x,
1680 line, x, 1, s-start);
1681 x += s - start + 1;
1682 start = s + 1;
1683 } else {
1684 x++;
1685 start++;
1686 }
1687 }
1688
1689 scr_writew(c, d);
1690 console_conditional_schedule();
1691 s++;
1692 d++;
1693 } while (s < le);
1694 if (s > start)
1695 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1696 s-start);
1697 console_conditional_schedule();
1698 if (ycount > 0)
1699 line++;
1700 else {
1701 line--;
1702 /* NOTE: We subtract two lines from these pointers */
1703 s -= vc->vc_size_row;
1704 d -= vc->vc_size_row;
1705 }
1706 }
1707}
1708
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709static void fbcon_redraw(struct vc_data *vc, struct display *p,
1710 int line, int count, int offset)
1711{
1712 unsigned short *d = (unsigned short *)
1713 (vc->vc_origin + vc->vc_size_row * line);
1714 unsigned short *s = d + offset;
1715
1716 while (count--) {
1717 unsigned short *start = s;
1718 unsigned short *le = advance_row(s, 1);
1719 unsigned short c;
1720 int x = 0;
1721 unsigned short attr = 1;
1722
1723 do {
1724 c = scr_readw(s);
1725 if (attr != (c & 0xff00)) {
1726 attr = c & 0xff00;
1727 if (s > start) {
1728 fbcon_putcs(vc, start, s - start,
1729 line, x);
1730 x += s - start;
1731 start = s;
1732 }
1733 }
1734 if (c == scr_readw(d)) {
1735 if (s > start) {
1736 fbcon_putcs(vc, start, s - start,
1737 line, x);
1738 x += s - start + 1;
1739 start = s + 1;
1740 } else {
1741 x++;
1742 start++;
1743 }
1744 }
1745 scr_writew(c, d);
1746 console_conditional_schedule();
1747 s++;
1748 d++;
1749 } while (s < le);
1750 if (s > start)
1751 fbcon_putcs(vc, start, s - start, line, x);
1752 console_conditional_schedule();
1753 if (offset > 0)
1754 line++;
1755 else {
1756 line--;
1757 /* NOTE: We subtract two lines from these pointers */
1758 s -= vc->vc_size_row;
1759 d -= vc->vc_size_row;
1760 }
1761 }
1762}
1763
1764static inline void fbcon_softback_note(struct vc_data *vc, int t,
1765 int count)
1766{
1767 unsigned short *p;
1768
1769 if (vc->vc_num != fg_console)
1770 return;
1771 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1772
1773 while (count) {
1774 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1775 count--;
1776 p = advance_row(p, 1);
1777 softback_in += vc->vc_size_row;
1778 if (softback_in == softback_end)
1779 softback_in = softback_buf;
1780 if (softback_in == softback_top) {
1781 softback_top += vc->vc_size_row;
1782 if (softback_top == softback_end)
1783 softback_top = softback_buf;
1784 }
1785 }
1786 softback_curr = softback_in;
1787}
1788
1789static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1790 int count)
1791{
1792 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1793 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1795
1796 if (fbcon_is_inactive(vc, info))
1797 return -EINVAL;
1798
1799 fbcon_cursor(vc, CM_ERASE);
1800
1801 /*
1802 * ++Geert: Only use ywrap/ypan if the console is in text mode
1803 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1804 * whole screen (prevents flicker).
1805 */
1806
1807 switch (dir) {
1808 case SM_UP:
1809 if (count > vc->vc_rows) /* Maximum realistic size */
1810 count = vc->vc_rows;
1811 if (softback_top)
1812 fbcon_softback_note(vc, t, count);
1813 if (logo_shown >= 0)
1814 goto redraw_up;
1815 switch (p->scrollmode) {
1816 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001817 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1818 count);
1819 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1820 scr_memsetw((unsigned short *) (vc->vc_origin +
1821 vc->vc_size_row *
1822 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001823 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001824 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001825 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 break;
1827
1828 case SCROLL_WRAP_MOVE:
1829 if (b - t - count > 3 * vc->vc_rows >> 2) {
1830 if (t > 0)
1831 fbcon_bmove(vc, 0, 0, count, 0, t,
1832 vc->vc_cols);
1833 ywrap_up(vc, count);
1834 if (vc->vc_rows - b > 0)
1835 fbcon_bmove(vc, b - count, 0, b, 0,
1836 vc->vc_rows - b,
1837 vc->vc_cols);
1838 } else if (info->flags & FBINFO_READS_FAST)
1839 fbcon_bmove(vc, t + count, 0, t, 0,
1840 b - t - count, vc->vc_cols);
1841 else
1842 goto redraw_up;
1843 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1844 break;
1845
1846 case SCROLL_PAN_REDRAW:
1847 if ((p->yscroll + count <=
1848 2 * (p->vrows - vc->vc_rows))
1849 && ((!scroll_partial && (b - t == vc->vc_rows))
1850 || (scroll_partial
1851 && (b - t - count >
1852 3 * vc->vc_rows >> 2)))) {
1853 if (t > 0)
1854 fbcon_redraw_move(vc, p, 0, t, count);
1855 ypan_up_redraw(vc, t, count);
1856 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001857 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 vc->vc_rows - b, b);
1859 } else
1860 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1861 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1862 break;
1863
1864 case SCROLL_PAN_MOVE:
1865 if ((p->yscroll + count <=
1866 2 * (p->vrows - vc->vc_rows))
1867 && ((!scroll_partial && (b - t == vc->vc_rows))
1868 || (scroll_partial
1869 && (b - t - count >
1870 3 * vc->vc_rows >> 2)))) {
1871 if (t > 0)
1872 fbcon_bmove(vc, 0, 0, count, 0, t,
1873 vc->vc_cols);
1874 ypan_up(vc, count);
1875 if (vc->vc_rows - b > 0)
1876 fbcon_bmove(vc, b - count, 0, b, 0,
1877 vc->vc_rows - b,
1878 vc->vc_cols);
1879 } else if (info->flags & FBINFO_READS_FAST)
1880 fbcon_bmove(vc, t + count, 0, t, 0,
1881 b - t - count, vc->vc_cols);
1882 else
1883 goto redraw_up;
1884 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1885 break;
1886
1887 case SCROLL_REDRAW:
1888 redraw_up:
1889 fbcon_redraw(vc, p, t, b - t - count,
1890 count * vc->vc_cols);
1891 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1892 scr_memsetw((unsigned short *) (vc->vc_origin +
1893 vc->vc_size_row *
1894 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001895 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001897 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 }
1899 break;
1900
1901 case SM_DOWN:
1902 if (count > vc->vc_rows) /* Maximum realistic size */
1903 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001904 if (logo_shown >= 0)
1905 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 switch (p->scrollmode) {
1907 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001908 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1909 -count);
1910 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1911 scr_memsetw((unsigned short *) (vc->vc_origin +
1912 vc->vc_size_row *
1913 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001914 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001915 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001916 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 break;
1918
1919 case SCROLL_WRAP_MOVE:
1920 if (b - t - count > 3 * vc->vc_rows >> 2) {
1921 if (vc->vc_rows - b > 0)
1922 fbcon_bmove(vc, b, 0, b - count, 0,
1923 vc->vc_rows - b,
1924 vc->vc_cols);
1925 ywrap_down(vc, count);
1926 if (t > 0)
1927 fbcon_bmove(vc, count, 0, 0, 0, t,
1928 vc->vc_cols);
1929 } else if (info->flags & FBINFO_READS_FAST)
1930 fbcon_bmove(vc, t, 0, t + count, 0,
1931 b - t - count, vc->vc_cols);
1932 else
1933 goto redraw_down;
1934 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1935 break;
1936
1937 case SCROLL_PAN_MOVE:
1938 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1939 && ((!scroll_partial && (b - t == vc->vc_rows))
1940 || (scroll_partial
1941 && (b - t - count >
1942 3 * vc->vc_rows >> 2)))) {
1943 if (vc->vc_rows - b > 0)
1944 fbcon_bmove(vc, b, 0, b - count, 0,
1945 vc->vc_rows - b,
1946 vc->vc_cols);
1947 ypan_down(vc, count);
1948 if (t > 0)
1949 fbcon_bmove(vc, count, 0, 0, 0, t,
1950 vc->vc_cols);
1951 } else if (info->flags & FBINFO_READS_FAST)
1952 fbcon_bmove(vc, t, 0, t + count, 0,
1953 b - t - count, vc->vc_cols);
1954 else
1955 goto redraw_down;
1956 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1957 break;
1958
1959 case SCROLL_PAN_REDRAW:
1960 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1961 && ((!scroll_partial && (b - t == vc->vc_rows))
1962 || (scroll_partial
1963 && (b - t - count >
1964 3 * vc->vc_rows >> 2)))) {
1965 if (vc->vc_rows - b > 0)
1966 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1967 b - count);
1968 ypan_down_redraw(vc, t, count);
1969 if (t > 0)
1970 fbcon_redraw_move(vc, p, count, t, 0);
1971 } else
1972 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1973 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1974 break;
1975
1976 case SCROLL_REDRAW:
1977 redraw_down:
1978 fbcon_redraw(vc, p, b - 1, b - t - count,
1979 -count * vc->vc_cols);
1980 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1981 scr_memsetw((unsigned short *) (vc->vc_origin +
1982 vc->vc_size_row *
1983 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001984 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001986 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 }
1988 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07001989 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990}
1991
1992
1993static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
1994 int height, int width)
1995{
1996 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1997 struct display *p = &fb_display[vc->vc_num];
1998
1999 if (fbcon_is_inactive(vc, info))
2000 return;
2001
2002 if (!width || !height)
2003 return;
2004
2005 /* Split blits that cross physical y_wrap case.
2006 * Pathological case involves 4 blits, better to use recursive
2007 * code rather than unrolled case
2008 *
2009 * Recursive invocations don't need to erase the cursor over and
2010 * over again, so we use fbcon_bmove_rec()
2011 */
2012 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2013 p->vrows - p->yscroll);
2014}
2015
2016static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2017 int dy, int dx, int height, int width, u_int y_break)
2018{
2019 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2020 struct fbcon_ops *ops = info->fbcon_par;
2021 u_int b;
2022
2023 if (sy < y_break && sy + height > y_break) {
2024 b = y_break - sy;
2025 if (dy < sy) { /* Avoid trashing self */
2026 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2027 y_break);
2028 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2029 height - b, width, y_break);
2030 } else {
2031 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2032 height - b, width, y_break);
2033 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2034 y_break);
2035 }
2036 return;
2037 }
2038
2039 if (dy < y_break && dy + height > y_break) {
2040 b = y_break - dy;
2041 if (dy < sy) { /* Avoid trashing self */
2042 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2043 y_break);
2044 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2045 height - b, width, y_break);
2046 } else {
2047 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2048 height - b, width, y_break);
2049 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2050 y_break);
2051 }
2052 return;
2053 }
2054 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2055 height, width);
2056}
2057
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002058static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002059 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 struct vc_data *vc)
2061{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002062 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 int fh = vc->vc_font.height;
2064 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002065 u16 t = 0;
2066 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2067 info->fix.xpanstep);
2068 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2069 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2070 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2071 info->var.xres_virtual);
2072 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2073 divides(ypan, vc->vc_font.height) && vyres > yres;
2074 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2075 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002076 divides(vc->vc_font.height, vyres) &&
2077 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002079 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2080 !(cap & FBINFO_HWACCEL_DISABLED);
2081 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2082 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002084 p->vrows = vyres/fh;
2085 if (yres > (fh * (vc->vc_rows + 1)))
2086 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2087 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 p->vrows--;
2089
2090 if (good_wrap || good_pan) {
2091 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002092 p->scrollmode = good_wrap ?
2093 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 else
2095 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2096 SCROLL_PAN_REDRAW;
2097 } else {
2098 if (reading_fast || (fast_copyarea && !fast_imageblit))
2099 p->scrollmode = SCROLL_MOVE;
2100 else
2101 p->scrollmode = SCROLL_REDRAW;
2102 }
2103}
2104
2105static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002106 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002109 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 struct display *p = &fb_display[vc->vc_num];
2111 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002112 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002114 virt_w = FBCON_SWAP(ops->rotate, width, height);
2115 virt_h = FBCON_SWAP(ops->rotate, height, width);
2116 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2117 vc->vc_font.height);
2118 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2119 vc->vc_font.width);
2120 var.xres = virt_w * virt_fw;
2121 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 x_diff = info->var.xres - var.xres;
2123 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002124 if (x_diff < 0 || x_diff > virt_fw ||
2125 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002126 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
2128 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2129 mode = fb_find_best_mode(&var, &info->modelist);
2130 if (mode == NULL)
2131 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002132 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002134
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002135 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2139 if (CON_IS_VISIBLE(vc)) {
2140 var.activate = FB_ACTIVATE_NOW |
2141 FB_ACTIVATE_FORCE;
2142 fb_set_var(info, &var);
2143 }
2144 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002145 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 }
2147 updatescrollmode(p, info, vc);
2148 return 0;
2149}
2150
2151static int fbcon_switch(struct vc_data *vc)
2152{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002153 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002154 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 struct display *p = &fb_display[vc->vc_num];
2156 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002157 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002160 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
2162 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 if (softback_lines)
2164 fbcon_set_origin(vc);
2165 softback_top = softback_curr = softback_in = softback_buf;
2166 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002167 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 }
2169
2170 if (logo_shown >= 0) {
2171 struct vc_data *conp2 = vc_cons[logo_shown].d;
2172
2173 if (conp2->vc_top == logo_lines
2174 && conp2->vc_bottom == conp2->vc_rows)
2175 conp2->vc_top = 0;
2176 logo_shown = FBCON_LOGO_CANSHOW;
2177 }
2178
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002179 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002180 if (prev_console != -1)
2181 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 /*
2183 * FIXME: If we have multiple fbdev's loaded, we need to
2184 * update all info->currcon. Perhaps, we can place this
2185 * in a centralized structure, but this might break some
2186 * drivers.
2187 *
2188 * info->currcon = vc->vc_num;
2189 */
2190 for (i = 0; i < FB_MAX; i++) {
2191 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002192 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002194 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 }
2196 }
2197 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2198 display_to_var(&var, p);
2199 var.activate = FB_ACTIVATE_NOW;
2200
2201 /*
2202 * make sure we don't unnecessarily trip the memcmp()
2203 * in fb_set_var()
2204 */
2205 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002206 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002208 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
Knut Petersen39942fd2005-12-12 22:17:19 -08002210 if (old_info != NULL && (old_info != info ||
2211 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002212 if (info->fbops->fb_set_par) {
2213 ret = info->fbops->fb_set_par(info);
2214
2215 if (ret)
2216 printk(KERN_ERR "fbcon_switch: detected "
2217 "unhandled fb_set_par error, "
2218 "error code %d\n", ret);
2219 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002220
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002221 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002222 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002225 if (fbcon_is_inactive(vc, info) ||
2226 ops->blank_state != FB_BLANK_UNBLANK)
2227 fbcon_del_cursor_timer(info);
2228 else
2229 fbcon_add_cursor_timer(info);
2230
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002231 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002232 ops->cursor_reset = 1;
2233
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002234 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002235 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002236 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002239 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002241
2242 if (p->userfont)
2243 charcnt = FNTCHARCNT(vc->vc_font.data);
2244
2245 if (charcnt > 256)
2246 vc->vc_complement_mask <<= 1;
2247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 updatescrollmode(p, info, vc);
2249
2250 switch (p->scrollmode) {
2251 case SCROLL_WRAP_MOVE:
2252 scrollback_phys_max = p->vrows - vc->vc_rows;
2253 break;
2254 case SCROLL_PAN_MOVE:
2255 case SCROLL_PAN_REDRAW:
2256 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2257 if (scrollback_phys_max < 0)
2258 scrollback_phys_max = 0;
2259 break;
2260 default:
2261 scrollback_phys_max = 0;
2262 break;
2263 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 scrollback_max = 0;
2266 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002267
2268 if (!fbcon_is_inactive(vc, info)) {
2269 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2270 ops->update_start(info);
2271 }
2272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 fbcon_set_palette(vc, color_table);
2274 fbcon_clear_margins(vc, 0);
2275
2276 if (logo_shown == FBCON_LOGO_DRAW) {
2277
2278 logo_shown = fg_console;
2279 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002280 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 update_region(vc,
2282 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2283 vc->vc_size_row * (vc->vc_bottom -
2284 vc->vc_top) / 2);
2285 return 0;
2286 }
2287 return 1;
2288}
2289
2290static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2291 int blank)
2292{
Richard Purdie994efac2007-02-09 09:46:45 +00002293 struct fb_event event;
2294
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (blank) {
2296 unsigned short charmask = vc->vc_hi_font_mask ?
2297 0x1ff : 0xff;
2298 unsigned short oldc;
2299
2300 oldc = vc->vc_video_erase_char;
2301 vc->vc_video_erase_char &= charmask;
2302 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2303 vc->vc_video_erase_char = oldc;
2304 }
Richard Purdie994efac2007-02-09 09:46:45 +00002305
2306
Andrea Righi513adb52009-04-13 14:39:39 -07002307 if (!lock_fb_info(info))
2308 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002309 event.info = info;
2310 event.data = &blank;
2311 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002312 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
2315static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2316{
2317 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2318 struct fbcon_ops *ops = info->fbcon_par;
2319
2320 if (mode_switch) {
2321 struct fb_var_screeninfo var = info->var;
2322
2323 ops->graphics = 1;
2324
2325 if (!blank) {
2326 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2327 fb_set_var(info, &var);
2328 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002329 ops->var = info->var;
Krzysztof Heltf5c15d02009-11-11 14:26:22 -08002330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332
2333 if (!fbcon_is_inactive(vc, info)) {
2334 if (ops->blank_state != blank) {
2335 ops->blank_state = blank;
2336 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2337 ops->cursor_flash = (!blank);
2338
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002339 if (!(info->flags & FBINFO_MISC_USEREVENT))
2340 if (fb_blank(info, blank))
2341 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
2343
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002344 if (!blank)
2345 update_screen(vc);
2346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002348 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002349 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002350 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002351 else
2352 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002353
2354 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355}
2356
Jesse Barnesd219adc2010-08-02 12:05:41 -07002357static int fbcon_debug_enter(struct vc_data *vc)
2358{
2359 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2360 struct fbcon_ops *ops = info->fbcon_par;
2361
2362 ops->save_graphics = ops->graphics;
2363 ops->graphics = 0;
2364 if (info->fbops->fb_debug_enter)
2365 info->fbops->fb_debug_enter(info);
2366 fbcon_set_palette(vc, color_table);
2367 return 0;
2368}
2369
2370static int fbcon_debug_leave(struct vc_data *vc)
2371{
2372 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2373 struct fbcon_ops *ops = info->fbcon_par;
2374
2375 ops->graphics = ops->save_graphics;
2376 if (info->fbops->fb_debug_leave)
2377 info->fbops->fb_debug_leave(info);
2378 return 0;
2379}
2380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2382{
2383 u8 *fontdata = vc->vc_font.data;
2384 u8 *data = font->data;
2385 int i, j;
2386
2387 font->width = vc->vc_font.width;
2388 font->height = vc->vc_font.height;
2389 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2390 if (!font->data)
2391 return 0;
2392
2393 if (font->width <= 8) {
2394 j = vc->vc_font.height;
2395 for (i = 0; i < font->charcount; i++) {
2396 memcpy(data, fontdata, j);
2397 memset(data + j, 0, 32 - j);
2398 data += 32;
2399 fontdata += j;
2400 }
2401 } else if (font->width <= 16) {
2402 j = vc->vc_font.height * 2;
2403 for (i = 0; i < font->charcount; i++) {
2404 memcpy(data, fontdata, j);
2405 memset(data + j, 0, 64 - j);
2406 data += 64;
2407 fontdata += j;
2408 }
2409 } else if (font->width <= 24) {
2410 for (i = 0; i < font->charcount; i++) {
2411 for (j = 0; j < vc->vc_font.height; j++) {
2412 *data++ = fontdata[0];
2413 *data++ = fontdata[1];
2414 *data++ = fontdata[2];
2415 fontdata += sizeof(u32);
2416 }
2417 memset(data, 0, 3 * (32 - j));
2418 data += 3 * (32 - j);
2419 }
2420 } else {
2421 j = vc->vc_font.height * 4;
2422 for (i = 0; i < font->charcount; i++) {
2423 memcpy(data, fontdata, j);
2424 memset(data + j, 0, 128 - j);
2425 data += 128;
2426 fontdata += j;
2427 }
2428 }
2429 return 0;
2430}
2431
2432static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002433 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
2435 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002436 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 struct display *p = &fb_display[vc->vc_num];
2438 int resize;
2439 int cnt;
2440 char *old_data = NULL;
2441
2442 if (CON_IS_VISIBLE(vc) && softback_lines)
2443 fbcon_set_origin(vc);
2444
2445 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2446 if (p->userfont)
2447 old_data = vc->vc_font.data;
2448 if (userfont)
2449 cnt = FNTCHARCNT(data);
2450 else
2451 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002452 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 if ((p->userfont = userfont))
2454 REFCOUNT(data)++;
2455 vc->vc_font.width = w;
2456 vc->vc_font.height = h;
2457 if (vc->vc_hi_font_mask && cnt == 256) {
2458 vc->vc_hi_font_mask = 0;
2459 if (vc->vc_can_do_color) {
2460 vc->vc_complement_mask >>= 1;
2461 vc->vc_s_complement_mask >>= 1;
2462 }
2463
2464 /* ++Edmund: reorder the attribute bits */
2465 if (vc->vc_can_do_color) {
2466 unsigned short *cp =
2467 (unsigned short *) vc->vc_origin;
2468 int count = vc->vc_screenbuf_size / 2;
2469 unsigned short c;
2470 for (; count > 0; count--, cp++) {
2471 c = scr_readw(cp);
2472 scr_writew(((c & 0xfe00) >> 1) |
2473 (c & 0xff), cp);
2474 }
2475 c = vc->vc_video_erase_char;
2476 vc->vc_video_erase_char =
2477 ((c & 0xfe00) >> 1) | (c & 0xff);
2478 vc->vc_attr >>= 1;
2479 }
2480 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2481 vc->vc_hi_font_mask = 0x100;
2482 if (vc->vc_can_do_color) {
2483 vc->vc_complement_mask <<= 1;
2484 vc->vc_s_complement_mask <<= 1;
2485 }
2486
2487 /* ++Edmund: reorder the attribute bits */
2488 {
2489 unsigned short *cp =
2490 (unsigned short *) vc->vc_origin;
2491 int count = vc->vc_screenbuf_size / 2;
2492 unsigned short c;
2493 for (; count > 0; count--, cp++) {
2494 unsigned short newc;
2495 c = scr_readw(cp);
2496 if (vc->vc_can_do_color)
2497 newc =
2498 ((c & 0xff00) << 1) | (c &
2499 0xff);
2500 else
2501 newc = c & ~0x100;
2502 scr_writew(newc, cp);
2503 }
2504 c = vc->vc_video_erase_char;
2505 if (vc->vc_can_do_color) {
2506 vc->vc_video_erase_char =
2507 ((c & 0xff00) << 1) | (c & 0xff);
2508 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002509 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 vc->vc_video_erase_char = c & ~0x100;
2511 }
2512
2513 }
2514
2515 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002516 int cols, rows;
2517
2518 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2519 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2520 cols /= w;
2521 rows /= h;
2522 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002523 if (CON_IS_VISIBLE(vc) && softback_buf)
2524 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 } else if (CON_IS_VISIBLE(vc)
2526 && vc->vc_mode == KD_TEXT) {
2527 fbcon_clear_margins(vc, 0);
2528 update_screen(vc);
2529 }
2530
2531 if (old_data && (--REFCOUNT(old_data) == 0))
2532 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2533 return 0;
2534}
2535
2536static int fbcon_copy_font(struct vc_data *vc, int con)
2537{
2538 struct display *od = &fb_display[con];
2539 struct console_font *f = &vc->vc_font;
2540
2541 if (od->fontdata == f->data)
2542 return 0; /* already the same font... */
2543 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2544}
2545
2546/*
2547 * User asked to set font; we are guaranteed that
2548 * a) width and height are in range 1..32
2549 * b) charcount does not exceed 512
2550 * but lets not assume that, since someone might someday want to use larger
2551 * fonts. And charcount of 512 is small for unicode support.
2552 *
2553 * However, user space gives the font in 32 rows , regardless of
2554 * actual font height. So a new API is needed if support for larger fonts
2555 * is ever implemented.
2556 */
2557
2558static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2559{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002560 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 unsigned charcount = font->charcount;
2562 int w = font->width;
2563 int h = font->height;
2564 int size;
2565 int i, csum;
2566 u8 *new_data, *data = font->data;
2567 int pitch = (font->width+7) >> 3;
2568
2569 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2570 * If not this check should be changed to charcount < 256 */
2571 if (charcount != 256 && charcount != 512)
2572 return -EINVAL;
2573
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002574 /* Make sure drawing engine can handle the font */
2575 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2576 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2577 return -EINVAL;
2578
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002579 /* Make sure driver can handle the font length */
2580 if (fbcon_invalid_charcount(info, charcount))
2581 return -EINVAL;
2582
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 size = h * pitch * charcount;
2584
2585 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2586
2587 if (!new_data)
2588 return -ENOMEM;
2589
2590 new_data += FONT_EXTRA_WORDS * sizeof(int);
2591 FNTSIZE(new_data) = size;
2592 FNTCHARCNT(new_data) = charcount;
2593 REFCOUNT(new_data) = 0; /* usage counter */
2594 for (i=0; i< charcount; i++) {
2595 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2596 }
2597
2598 /* Since linux has a nice crc32 function use it for counting font
2599 * checksums. */
2600 csum = crc32(0, new_data, size);
2601
2602 FNTSUM(new_data) = csum;
2603 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002604 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 struct vc_data *tmp = vc_cons[i].d;
2606
2607 if (fb_display[i].userfont &&
2608 fb_display[i].fontdata &&
2609 FNTSUM(fb_display[i].fontdata) == csum &&
2610 FNTSIZE(fb_display[i].fontdata) == size &&
2611 tmp->vc_font.width == w &&
2612 !memcmp(fb_display[i].fontdata, new_data, size)) {
2613 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002614 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 break;
2616 }
2617 }
2618 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2619}
2620
2621static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2622{
2623 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002624 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
2626 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002627 f = get_default_font(info->var.xres, info->var.yres,
2628 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 else if (!(f = find_font(name)))
2630 return -ENOENT;
2631
2632 font->width = f->width;
2633 font->height = f->height;
2634 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2635}
2636
2637static u16 palette_red[16];
2638static u16 palette_green[16];
2639static u16 palette_blue[16];
2640
2641static struct fb_cmap palette_cmap = {
2642 0, 16, palette_red, palette_green, palette_blue, NULL
2643};
2644
2645static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2646{
2647 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2648 int i, j, k, depth;
2649 u8 val;
2650
2651 if (fbcon_is_inactive(vc, info))
2652 return -EINVAL;
2653
2654 if (!CON_IS_VISIBLE(vc))
2655 return 0;
2656
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002657 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 if (depth > 3) {
2659 for (i = j = 0; i < 16; i++) {
2660 k = table[i];
2661 val = vc->vc_palette[j++];
2662 palette_red[k] = (val << 8) | val;
2663 val = vc->vc_palette[j++];
2664 palette_green[k] = (val << 8) | val;
2665 val = vc->vc_palette[j++];
2666 palette_blue[k] = (val << 8) | val;
2667 }
2668 palette_cmap.len = 16;
2669 palette_cmap.start = 0;
2670 /*
2671 * If framebuffer is capable of less than 16 colors,
2672 * use default palette of fbcon.
2673 */
2674 } else
2675 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2676
2677 return fb_set_cmap(&palette_cmap, info);
2678}
2679
2680static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2681{
2682 unsigned long p;
2683 int line;
2684
2685 if (vc->vc_num != fg_console || !softback_lines)
2686 return (u16 *) (vc->vc_origin + offset);
2687 line = offset / vc->vc_size_row;
2688 if (line >= softback_lines)
2689 return (u16 *) (vc->vc_origin + offset -
2690 softback_lines * vc->vc_size_row);
2691 p = softback_curr + offset;
2692 if (p >= softback_end)
2693 p += softback_buf - softback_end;
2694 return (u16 *) p;
2695}
2696
2697static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2698 int *px, int *py)
2699{
2700 unsigned long ret;
2701 int x, y;
2702
2703 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2704 unsigned long offset = (pos - vc->vc_origin) / 2;
2705
2706 x = offset % vc->vc_cols;
2707 y = offset / vc->vc_cols;
2708 if (vc->vc_num == fg_console)
2709 y += softback_lines;
2710 ret = pos + (vc->vc_cols - x) * 2;
2711 } else if (vc->vc_num == fg_console && softback_lines) {
2712 unsigned long offset = pos - softback_curr;
2713
2714 if (pos < softback_curr)
2715 offset += softback_end - softback_buf;
2716 offset /= 2;
2717 x = offset % vc->vc_cols;
2718 y = offset / vc->vc_cols;
2719 ret = pos + (vc->vc_cols - x) * 2;
2720 if (ret == softback_end)
2721 ret = softback_buf;
2722 if (ret == softback_in)
2723 ret = vc->vc_origin;
2724 } else {
2725 /* Should not happen */
2726 x = y = 0;
2727 ret = vc->vc_origin;
2728 }
2729 if (px)
2730 *px = x;
2731 if (py)
2732 *py = y;
2733 return ret;
2734}
2735
2736/* As we might be inside of softback, we may work with non-contiguous buffer,
2737 that's why we have to use a separate routine. */
2738static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2739{
2740 while (cnt--) {
2741 u16 a = scr_readw(p);
2742 if (!vc->vc_can_do_color)
2743 a ^= 0x0800;
2744 else if (vc->vc_hi_font_mask == 0x100)
2745 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2746 (((a) & 0x0e00) << 4);
2747 else
2748 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2749 (((a) & 0x0700) << 4);
2750 scr_writew(a, p++);
2751 if (p == (u16 *) softback_end)
2752 p = (u16 *) softback_buf;
2753 if (p == (u16 *) softback_in)
2754 p = (u16 *) vc->vc_origin;
2755 }
2756}
2757
2758static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2759{
2760 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002761 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002762 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 int offset, limit, scrollback_old;
2764
2765 if (softback_top) {
2766 if (vc->vc_num != fg_console)
2767 return 0;
2768 if (vc->vc_mode != KD_TEXT || !lines)
2769 return 0;
2770 if (logo_shown >= 0) {
2771 struct vc_data *conp2 = vc_cons[logo_shown].d;
2772
2773 if (conp2->vc_top == logo_lines
2774 && conp2->vc_bottom == conp2->vc_rows)
2775 conp2->vc_top = 0;
2776 if (logo_shown == vc->vc_num) {
2777 unsigned long p, q;
2778 int i;
2779
2780 p = softback_in;
2781 q = vc->vc_origin +
2782 logo_lines * vc->vc_size_row;
2783 for (i = 0; i < logo_lines; i++) {
2784 if (p == softback_top)
2785 break;
2786 if (p == softback_buf)
2787 p = softback_end;
2788 p -= vc->vc_size_row;
2789 q -= vc->vc_size_row;
2790 scr_memcpyw((u16 *) q, (u16 *) p,
2791 vc->vc_size_row);
2792 }
David Hollister308af922006-05-30 21:25:36 -07002793 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 update_region(vc, vc->vc_origin,
2795 logo_lines * vc->vc_cols);
2796 }
2797 logo_shown = FBCON_LOGO_CANSHOW;
2798 }
2799 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002800 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2802 return 0;
2803 }
2804
2805 if (!scrollback_phys_max)
2806 return -ENOSYS;
2807
2808 scrollback_old = scrollback_current;
2809 scrollback_current -= lines;
2810 if (scrollback_current < 0)
2811 scrollback_current = 0;
2812 else if (scrollback_current > scrollback_max)
2813 scrollback_current = scrollback_max;
2814 if (scrollback_current == scrollback_old)
2815 return 0;
2816
2817 if (fbcon_is_inactive(vc, info))
2818 return 0;
2819
2820 fbcon_cursor(vc, CM_ERASE);
2821
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002822 offset = disp->yscroll - scrollback_current;
2823 limit = disp->vrows;
2824 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 case SCROLL_WRAP_MOVE:
2826 info->var.vmode |= FB_VMODE_YWRAP;
2827 break;
2828 case SCROLL_PAN_MOVE:
2829 case SCROLL_PAN_REDRAW:
2830 limit -= vc->vc_rows;
2831 info->var.vmode &= ~FB_VMODE_YWRAP;
2832 break;
2833 }
2834 if (offset < 0)
2835 offset += limit;
2836 else if (offset >= limit)
2837 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002838
2839 ops->var.xoffset = 0;
2840 ops->var.yoffset = offset * vc->vc_font.height;
2841 ops->update_start(info);
2842
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 if (!scrollback_current)
2844 fbcon_cursor(vc, CM_DRAW);
2845 return 0;
2846}
2847
2848static int fbcon_set_origin(struct vc_data *vc)
2849{
2850 if (softback_lines)
2851 fbcon_scrolldelta(vc, softback_lines);
2852 return 0;
2853}
2854
2855static void fbcon_suspended(struct fb_info *info)
2856{
2857 struct vc_data *vc = NULL;
2858 struct fbcon_ops *ops = info->fbcon_par;
2859
2860 if (!ops || ops->currcon < 0)
2861 return;
2862 vc = vc_cons[ops->currcon].d;
2863
2864 /* Clear cursor, restore saved data */
2865 fbcon_cursor(vc, CM_ERASE);
2866}
2867
2868static void fbcon_resumed(struct fb_info *info)
2869{
2870 struct vc_data *vc;
2871 struct fbcon_ops *ops = info->fbcon_par;
2872
2873 if (!ops || ops->currcon < 0)
2874 return;
2875 vc = vc_cons[ops->currcon].d;
2876
2877 update_screen(vc);
2878}
2879
2880static void fbcon_modechanged(struct fb_info *info)
2881{
2882 struct fbcon_ops *ops = info->fbcon_par;
2883 struct vc_data *vc;
2884 struct display *p;
2885 int rows, cols;
2886
2887 if (!ops || ops->currcon < 0)
2888 return;
2889 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002890 if (vc->vc_mode != KD_TEXT ||
2891 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 return;
2893
2894 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002895 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897 if (CON_IS_VISIBLE(vc)) {
2898 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002899 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2900 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2901 cols /= vc->vc_font.width;
2902 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 vc_resize(vc, cols, rows);
2904 updatescrollmode(p, info, vc);
2905 scrollback_max = 0;
2906 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002907
2908 if (!fbcon_is_inactive(vc, info)) {
2909 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2910 ops->update_start(info);
2911 }
2912
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 fbcon_set_palette(vc, color_table);
2914 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002915 if (softback_buf)
2916 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 }
2918}
2919
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002920static void fbcon_set_all_vcs(struct fb_info *info)
2921{
2922 struct fbcon_ops *ops = info->fbcon_par;
2923 struct vc_data *vc;
2924 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002925 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002926
2927 if (!ops || ops->currcon < 0)
2928 return;
2929
Antonino A. Daplase614b182006-06-26 00:27:09 -07002930 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002931 vc = vc_cons[i].d;
2932 if (!vc || vc->vc_mode != KD_TEXT ||
2933 registered_fb[con2fb_map[i]] != info)
2934 continue;
2935
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002936 if (CON_IS_VISIBLE(vc)) {
2937 fg = i;
2938 continue;
2939 }
2940
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002941 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002942 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002943 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002944 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2945 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002946 cols /= vc->vc_font.width;
2947 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002948 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002949 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002950
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002951 if (fg != -1)
2952 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002953}
2954
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955static int fbcon_mode_deleted(struct fb_info *info,
2956 struct fb_videomode *mode)
2957{
2958 struct fb_info *fb_info;
2959 struct display *p;
2960 int i, j, found = 0;
2961
2962 /* before deletion, ensure that mode is not in use */
2963 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2964 j = con2fb_map[i];
2965 if (j == -1)
2966 continue;
2967 fb_info = registered_fb[j];
2968 if (fb_info != info)
2969 continue;
2970 p = &fb_display[i];
2971 if (!p || !p->mode)
2972 continue;
2973 if (fb_mode_is_equal(p->mode, mode)) {
2974 found = 1;
2975 break;
2976 }
2977 }
2978 return found;
2979}
2980
Jesse Barnescfafca82007-07-17 04:05:33 -07002981#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2982static int fbcon_unbind(void)
2983{
2984 int ret;
2985
2986 ret = unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
2987 fbcon_is_default);
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07002988
2989 if (!ret)
2990 fbcon_has_console_bind = 0;
2991
Jesse Barnescfafca82007-07-17 04:05:33 -07002992 return ret;
2993}
2994#else
2995static inline int fbcon_unbind(void)
2996{
2997 return -EINVAL;
2998}
2999#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3000
3001static int fbcon_fb_unbind(int idx)
3002{
3003 int i, new_idx = -1, ret = 0;
3004
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003005 if (!fbcon_has_console_bind)
3006 return 0;
3007
Jesse Barnescfafca82007-07-17 04:05:33 -07003008 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3009 if (con2fb_map[i] != idx &&
3010 con2fb_map[i] != -1) {
3011 new_idx = i;
3012 break;
3013 }
3014 }
3015
3016 if (new_idx != -1) {
3017 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3018 if (con2fb_map[i] == idx)
3019 set_con2fb_map(i, new_idx, 0);
3020 }
3021 } else
3022 ret = fbcon_unbind();
3023
3024 return ret;
3025}
3026
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003027static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003028{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003029 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003030
Andrea Righi66c1ca02009-03-31 15:25:18 -07003031 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003032 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3033 if (con2fb_map[i] == idx)
3034 con2fb_map[i] = -1;
3035 }
3036
3037 if (idx == info_idx) {
3038 info_idx = -1;
3039
3040 for (i = 0; i < FB_MAX; i++) {
3041 if (registered_fb[i] != NULL) {
3042 info_idx = i;
3043 break;
3044 }
3045 }
3046 }
3047
3048 if (info_idx != -1) {
3049 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3050 if (con2fb_map[i] == -1)
3051 con2fb_map[i] = info_idx;
3052 }
3053 }
3054
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003055 if (primary_device == idx)
3056 primary_device = -1;
3057
Andrea Righi66c1ca02009-03-31 15:25:18 -07003058 if (!num_registered_fb)
3059 unregister_con_driver(&fb_con);
3060
Antonino A. Daplase614b182006-06-26 00:27:09 -07003061 return 0;
3062}
3063
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003064static void fbcon_remap_all(int idx)
3065{
3066 int i;
3067 for (i = first_fb_vc; i <= last_fb_vc; i++)
3068 set_con2fb_map(i, idx, 0);
3069
3070 if (con_is_bound(&fb_con)) {
3071 printk(KERN_INFO "fbcon: Remapping primary device, "
3072 "fb%i, to tty %i-%i\n", idx,
3073 first_fb_vc + 1, last_fb_vc + 1);
3074 info_idx = idx;
3075 }
3076}
3077
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003078#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003079static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003081 if (!map_override && primary_device == -1 &&
3082 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003083 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003084
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003085 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3086 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003087 primary_device = info->node;
3088
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003089 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003090 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003091
3092 if (con_is_bound(&fb_con)) {
3093 printk(KERN_INFO "fbcon: Remapping primary device, "
3094 "fb%i, to tty %i-%i\n", info->node,
3095 first_fb_vc + 1, last_fb_vc + 1);
3096 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003097 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003098 }
3099
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003100}
3101#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003102static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003103{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003104 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003105}
3106#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3107
3108static int fbcon_fb_registered(struct fb_info *info)
3109{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003110 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003111
Andrea Righi66c1ca02009-03-31 15:25:18 -07003112 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003113 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003116 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 if (con2fb_map_boot[i] == idx) {
3118 info_idx = idx;
3119 break;
3120 }
3121 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003122
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 if (info_idx != -1)
3124 ret = fbcon_takeover(1);
3125 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003126 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003127 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 set_con2fb_map(i, idx, 0);
3129 }
3130 }
3131
3132 return ret;
3133}
3134
3135static void fbcon_fb_blanked(struct fb_info *info, int blank)
3136{
3137 struct fbcon_ops *ops = info->fbcon_par;
3138 struct vc_data *vc;
3139
3140 if (!ops || ops->currcon < 0)
3141 return;
3142
3143 vc = vc_cons[ops->currcon].d;
3144 if (vc->vc_mode != KD_TEXT ||
3145 registered_fb[con2fb_map[ops->currcon]] != info)
3146 return;
3147
3148 if (CON_IS_VISIBLE(vc)) {
3149 if (blank)
3150 do_blank_screen(0);
3151 else
3152 do_unblank_screen(0);
3153 }
3154 ops->blank_state = blank;
3155}
3156
3157static void fbcon_new_modelist(struct fb_info *info)
3158{
3159 int i;
3160 struct vc_data *vc;
3161 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003162 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
Antonino A. Daplase614b182006-06-26 00:27:09 -07003164 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 if (registered_fb[con2fb_map[i]] != info)
3166 continue;
3167 if (!fb_display[i].mode)
3168 continue;
3169 vc = vc_cons[i].d;
3170 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003171 mode = fb_find_nearest_mode(fb_display[i].mode,
3172 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003174 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 }
3176}
3177
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003178static void fbcon_get_requirement(struct fb_info *info,
3179 struct fb_blit_caps *caps)
3180{
3181 struct vc_data *vc;
3182 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003183
3184 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003185 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003186
3187 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3188 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003189 if (vc && vc->vc_mode == KD_TEXT &&
3190 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003191 p = &fb_display[i];
3192 caps->x |= 1 << (vc->vc_font.width - 1);
3193 caps->y |= 1 << (vc->vc_font.height - 1);
3194 charcnt = (p->userfont) ?
3195 FNTCHARCNT(p->fontdata) : 256;
3196 if (caps->len < charcnt)
3197 caps->len = charcnt;
3198 }
3199 }
3200 } else {
3201 vc = vc_cons[fg_console].d;
3202
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003203 if (vc && vc->vc_mode == KD_TEXT &&
3204 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003205 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003206 caps->x = 1 << (vc->vc_font.width - 1);
3207 caps->y = 1 << (vc->vc_font.height - 1);
3208 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003209 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003210 }
3211 }
3212}
3213
Andrea Righi66c1ca02009-03-31 15:25:18 -07003214static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 unsigned long action, void *data)
3216{
3217 struct fb_event *event = data;
3218 struct fb_info *info = event->info;
3219 struct fb_videomode *mode;
3220 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003221 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003222 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
Antonino A. Daplase614b182006-06-26 00:27:09 -07003224 /*
3225 * ignore all events except driver registration and deregistration
3226 * if fbcon is not active
3227 */
3228 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3229 action == FB_EVENT_FB_UNREGISTERED))
3230 goto done;
3231
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 switch(action) {
3233 case FB_EVENT_SUSPEND:
3234 fbcon_suspended(info);
3235 break;
3236 case FB_EVENT_RESUME:
3237 fbcon_resumed(info);
3238 break;
3239 case FB_EVENT_MODE_CHANGE:
3240 fbcon_modechanged(info);
3241 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003242 case FB_EVENT_MODE_CHANGE_ALL:
3243 fbcon_set_all_vcs(info);
3244 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 case FB_EVENT_MODE_DELETE:
3246 mode = event->data;
3247 ret = fbcon_mode_deleted(info, mode);
3248 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003249 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003250 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003251 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003252 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003254 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003256 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003257 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003258 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 case FB_EVENT_SET_CONSOLE_MAP:
3260 con2fb = event->data;
3261 ret = set_con2fb_map(con2fb->console - 1,
3262 con2fb->framebuffer, 1);
3263 break;
3264 case FB_EVENT_GET_CONSOLE_MAP:
3265 con2fb = event->data;
3266 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3267 break;
3268 case FB_EVENT_BLANK:
3269 fbcon_fb_blanked(info, *(int *)event->data);
3270 break;
3271 case FB_EVENT_NEW_MODELIST:
3272 fbcon_new_modelist(info);
3273 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003274 case FB_EVENT_GET_REQ:
3275 caps = event->data;
3276 fbcon_get_requirement(info, caps);
3277 break;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003278 case FB_EVENT_REMAP_ALL_CONSOLE:
3279 idx = info->node;
3280 fbcon_remap_all(idx);
3281 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003283done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 return ret;
3285}
3286
3287/*
3288 * The console `switch' structure for the frame buffer based console
3289 */
3290
3291static const struct consw fb_con = {
3292 .owner = THIS_MODULE,
3293 .con_startup = fbcon_startup,
3294 .con_init = fbcon_init,
3295 .con_deinit = fbcon_deinit,
3296 .con_clear = fbcon_clear,
3297 .con_putc = fbcon_putc,
3298 .con_putcs = fbcon_putcs,
3299 .con_cursor = fbcon_cursor,
3300 .con_scroll = fbcon_scroll,
3301 .con_bmove = fbcon_bmove,
3302 .con_switch = fbcon_switch,
3303 .con_blank = fbcon_blank,
3304 .con_font_set = fbcon_set_font,
3305 .con_font_get = fbcon_get_font,
3306 .con_font_default = fbcon_set_def_font,
3307 .con_font_copy = fbcon_copy_font,
3308 .con_set_palette = fbcon_set_palette,
3309 .con_scrolldelta = fbcon_scrolldelta,
3310 .con_set_origin = fbcon_set_origin,
3311 .con_invert_region = fbcon_invert_region,
3312 .con_screen_pos = fbcon_screen_pos,
3313 .con_getxy = fbcon_getxy,
3314 .con_resize = fbcon_resize,
Jesse Barnesd219adc2010-08-02 12:05:41 -07003315 .con_debug_enter = fbcon_debug_enter,
3316 .con_debug_leave = fbcon_debug_leave,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317};
3318
3319static struct notifier_block fbcon_event_notifier = {
3320 .notifier_call = fbcon_event_notify,
3321};
3322
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003323static ssize_t store_rotate(struct device *device,
3324 struct device_attribute *attr, const char *buf,
3325 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003326{
3327 struct fb_info *info;
3328 int rotate, idx;
3329 char **last = NULL;
3330
Antonino A. Daplase614b182006-06-26 00:27:09 -07003331 if (fbcon_has_exited)
3332 return count;
3333
Torben Hohnac751ef2011-01-25 15:07:35 -08003334 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003335 idx = con2fb_map[fg_console];
3336
3337 if (idx == -1 || registered_fb[idx] == NULL)
3338 goto err;
3339
3340 info = registered_fb[idx];
3341 rotate = simple_strtoul(buf, last, 0);
3342 fbcon_rotate(info, rotate);
3343err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003344 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003345 return count;
3346}
3347
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003348static ssize_t store_rotate_all(struct device *device,
3349 struct device_attribute *attr,const char *buf,
3350 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003351{
3352 struct fb_info *info;
3353 int rotate, idx;
3354 char **last = NULL;
3355
Antonino A. Daplase614b182006-06-26 00:27:09 -07003356 if (fbcon_has_exited)
3357 return count;
3358
Torben Hohnac751ef2011-01-25 15:07:35 -08003359 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003360 idx = con2fb_map[fg_console];
3361
3362 if (idx == -1 || registered_fb[idx] == NULL)
3363 goto err;
3364
3365 info = registered_fb[idx];
3366 rotate = simple_strtoul(buf, last, 0);
3367 fbcon_rotate_all(info, rotate);
3368err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003369 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003370 return count;
3371}
3372
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003373static ssize_t show_rotate(struct device *device,
3374 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003375{
3376 struct fb_info *info;
3377 int rotate = 0, idx;
3378
Antonino A. Daplase614b182006-06-26 00:27:09 -07003379 if (fbcon_has_exited)
3380 return 0;
3381
Torben Hohnac751ef2011-01-25 15:07:35 -08003382 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003383 idx = con2fb_map[fg_console];
3384
3385 if (idx == -1 || registered_fb[idx] == NULL)
3386 goto err;
3387
3388 info = registered_fb[idx];
3389 rotate = fbcon_get_rotate(info);
3390err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003391 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003392 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3393}
3394
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003395static ssize_t show_cursor_blink(struct device *device,
3396 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003397{
3398 struct fb_info *info;
3399 struct fbcon_ops *ops;
3400 int idx, blink = -1;
3401
3402 if (fbcon_has_exited)
3403 return 0;
3404
Torben Hohnac751ef2011-01-25 15:07:35 -08003405 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003406 idx = con2fb_map[fg_console];
3407
3408 if (idx == -1 || registered_fb[idx] == NULL)
3409 goto err;
3410
3411 info = registered_fb[idx];
3412 ops = info->fbcon_par;
3413
3414 if (!ops)
3415 goto err;
3416
3417 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3418err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003419 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003420 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3421}
3422
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003423static ssize_t store_cursor_blink(struct device *device,
3424 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003425 const char *buf, size_t count)
3426{
3427 struct fb_info *info;
3428 int blink, idx;
3429 char **last = NULL;
3430
3431 if (fbcon_has_exited)
3432 return count;
3433
Torben Hohnac751ef2011-01-25 15:07:35 -08003434 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003435 idx = con2fb_map[fg_console];
3436
3437 if (idx == -1 || registered_fb[idx] == NULL)
3438 goto err;
3439
3440 info = registered_fb[idx];
3441
3442 if (!info->fbcon_par)
3443 goto err;
3444
3445 blink = simple_strtoul(buf, last, 0);
3446
3447 if (blink) {
3448 fbcon_cursor_noblink = 0;
3449 fbcon_add_cursor_timer(info);
3450 } else {
3451 fbcon_cursor_noblink = 1;
3452 fbcon_del_cursor_timer(info);
3453 }
3454
3455err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003456 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003457 return count;
3458}
3459
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003460static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003461 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3462 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003463 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3464 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003465};
3466
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003467static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003468{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003469 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003470
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003471 fbcon_has_sysfs = 1;
3472
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003473 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3474 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003475
3476 if (error)
3477 break;
3478 }
3479
3480 if (error) {
3481 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003482 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003483
3484 fbcon_has_sysfs = 0;
3485 }
3486
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003487 return 0;
3488}
3489
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003490static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003493 int i;
3494
Torben Hohnac751ef2011-01-25 15:07:35 -08003495 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003496
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 for (i = 0; i < FB_MAX; i++) {
3498 if (registered_fb[i] != NULL) {
3499 info_idx = i;
3500 break;
3501 }
3502 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003503
Torben Hohnac751ef2011-01-25 15:07:35 -08003504 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 fbcon_takeover(0);
3506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507}
3508
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003509static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003510{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003511 struct fb_info *info;
3512 int i, j, mapped;
3513
Antonino A. Daplase614b182006-06-26 00:27:09 -07003514 if (fbcon_has_exited)
3515 return;
3516
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003517 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003518 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003519
3520 for (i = 0; i < FB_MAX; i++) {
Jarek Poplawski142092e2010-09-22 13:05:05 -07003521 int pending = 0;
Geoff Levandbeaa4862008-12-09 13:14:17 -08003522
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003523 mapped = 0;
3524 info = registered_fb[i];
3525
3526 if (info == NULL)
3527 continue;
3528
Jarek Poplawski142092e2010-09-22 13:05:05 -07003529 if (info->queue.func)
3530 pending = cancel_work_sync(&info->queue);
Geoff Levandbeaa4862008-12-09 13:14:17 -08003531 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3532 "no"));
3533
Antonino A. Daplase614b182006-06-26 00:27:09 -07003534 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3535 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003536 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003537 }
3538
3539 if (mapped) {
3540 if (info->fbops->fb_release)
3541 info->fbops->fb_release(info, 0);
3542 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003543
3544 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003545 struct fbcon_ops *ops = info->fbcon_par;
3546
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003547 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003548 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003549 kfree(info->fbcon_par);
3550 info->fbcon_par = NULL;
3551 }
3552
3553 if (info->queue.func == fb_flashcursor)
3554 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003555 }
3556 }
3557
Antonino A. Daplase614b182006-06-26 00:27:09 -07003558 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003559}
3560
3561static int __init fb_console_init(void)
3562{
3563 int i;
3564
Torben Hohnac751ef2011-01-25 15:07:35 -08003565 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003566 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003567 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3568 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003569
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003570 if (IS_ERR(fbcon_device)) {
3571 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003572 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003573 PTR_ERR(fbcon_device));
3574 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003575 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003576 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003577
3578 for (i = 0; i < MAX_NR_CONSOLES; i++)
3579 con2fb_map[i] = -1;
3580
Torben Hohnac751ef2011-01-25 15:07:35 -08003581 console_unlock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003582 fbcon_start();
3583 return 0;
3584}
3585
3586module_init(fb_console_init);
3587
3588#ifdef MODULE
3589
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003590static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003591{
3592 int i;
3593
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003594 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003595 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3596 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003597
3598 fbcon_has_sysfs = 0;
3599 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003600}
3601
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602static void __exit fb_console_exit(void)
3603{
Torben Hohnac751ef2011-01-25 15:07:35 -08003604 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003606 fbcon_deinit_device();
3607 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003608 fbcon_exit();
Torben Hohnac751ef2011-01-25 15:07:35 -08003609 console_unlock();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003610 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611}
3612
3613module_exit(fb_console_exit);
3614
3615#endif
3616
3617MODULE_LICENSE("GPL");