blob: 5bf163e038409cd6568a0ab0ef4be07fb1802928 [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 Airlie13e902a2012-08-21 16:29:47 +1000375 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Dave Airlie13e902a2012-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))
452 strcpy(fontname, options + 5);
453
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
Alan Coxc30b55c2013-01-25 10:28:15 +1000532static int do_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 = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
546 fbcon_is_default);
547
548 if (err) {
549 for (i = first_fb_vc; i <= last_fb_vc; i++)
550 con2fb_map[i] = -1;
551 info_idx = -1;
552 } else {
553 fbcon_has_console_bind = 1;
554 }
555
556 return err;
557}
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559static int fbcon_takeover(int show_logo)
560{
561 int err, i;
562
563 if (!num_registered_fb)
564 return -ENODEV;
565
566 if (!show_logo)
567 logo_shown = FBCON_LOGO_DONTSHOW;
568
569 for (i = first_fb_vc; i <= last_fb_vc; i++)
570 con2fb_map[i] = info_idx;
571
572 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
573 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (err) {
576 for (i = first_fb_vc; i <= last_fb_vc; i++) {
577 con2fb_map[i] = -1;
578 }
579 info_idx = -1;
Ian Armstrong2ddce3f2009-09-22 16:47:52 -0700580 } else {
581 fbcon_has_console_bind = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583
584 return err;
585}
586
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700587#ifdef MODULE
588static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
589 int cols, int rows, int new_cols, int new_rows)
590{
591 logo_shown = FBCON_LOGO_DONTSHOW;
592}
593#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
595 int cols, int rows, int new_cols, int new_rows)
596{
597 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800598 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 int cnt, erase = vc->vc_video_erase_char, step;
600 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700601 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700603 if (info->flags & FBINFO_MODULE) {
604 logo_shown = FBCON_LOGO_DONTSHOW;
605 return;
606 }
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /*
609 * remove underline attribute from erase character
610 * if black and white framebuffer.
611 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700612 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800614 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700615 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 q = (unsigned short *) (vc->vc_origin +
617 vc->vc_size_row * rows);
618 step = logo_lines * cols;
619 for (r = q - logo_lines * cols; r < q; r++)
620 if (scr_readw(r) != vc->vc_video_erase_char)
621 break;
622 if (r != q && new_rows >= rows + logo_lines) {
623 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
624 if (save) {
625 int i = cols < new_cols ? cols : new_cols;
626 scr_memsetw(save, erase, logo_lines * new_cols * 2);
627 r = q - step;
628 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
629 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
630 r = q;
631 }
632 }
633 if (r == q) {
634 /* We can scroll screen down */
635 r = q - step - cols;
636 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
637 scr_memcpyw(r + step, r, vc->vc_size_row);
638 r -= cols;
639 }
640 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700641 int lines;
642 if (vc->vc_y + logo_lines >= rows)
643 lines = rows - vc->vc_y - 1;
644 else
645 lines = logo_lines;
646 vc->vc_y += lines;
647 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649 }
650 scr_memsetw((unsigned short *) vc->vc_origin,
651 erase,
652 vc->vc_size_row * logo_lines);
653
654 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
655 fbcon_clear_margins(vc, 0);
656 update_screen(vc);
657 }
658
659 if (save) {
660 q = (unsigned short *) (vc->vc_origin +
661 vc->vc_size_row *
662 rows);
663 scr_memcpyw(q, save, logo_lines * new_cols * 2);
664 vc->vc_y += logo_lines;
665 vc->vc_pos += logo_lines * vc->vc_size_row;
666 kfree(save);
667 }
668
669 if (logo_lines > vc->vc_bottom) {
670 logo_shown = FBCON_LOGO_CANSHOW;
671 printk(KERN_INFO
672 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
673 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
674 logo_shown = FBCON_LOGO_DRAW;
675 vc->vc_top = logo_lines;
676 }
677}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700678#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800681static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682{
683 struct fbcon_ops *ops = info->fbcon_par;
684
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800685 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800688 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800689 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800690 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700694
695static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
696{
697 int err = 0;
698
699 if (info->flags & FBINFO_MISC_TILEBLITTING &&
700 info->tileops->fb_get_tilemax(info) < charcount)
701 err = 1;
702
703 return err;
704}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800706static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707{
708 struct fbcon_ops *ops = info->fbcon_par;
709
710 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800711 ops->p = &fb_display[vc->vc_num];
712 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 fbcon_set_bitops(ops);
714}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700715
716static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
717{
718 return 0;
719}
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#endif /* CONFIG_MISC_TILEBLITTING */
722
723
724static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
725 int unit, int oldidx)
726{
727 struct fbcon_ops *ops = NULL;
728 int err = 0;
729
730 if (!try_module_get(info->fbops->owner))
731 err = -ENODEV;
732
733 if (!err && info->fbops->fb_open &&
734 info->fbops->fb_open(info, 0))
735 err = -ENODEV;
736
737 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800738 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 if (!ops)
740 err = -ENOMEM;
741 }
742
743 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700745
746 if (vc)
747 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
749
750 if (err) {
751 con2fb_map[unit] = oldidx;
752 module_put(info->fbops->owner);
753 }
754
755 return err;
756}
757
758static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
759 struct fb_info *newinfo, int unit,
760 int oldidx, int found)
761{
762 struct fbcon_ops *ops = oldinfo->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700763 int err = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (oldinfo->fbops->fb_release &&
766 oldinfo->fbops->fb_release(oldinfo, 0)) {
767 con2fb_map[unit] = oldidx;
768 if (!found && newinfo->fbops->fb_release)
769 newinfo->fbops->fb_release(newinfo, 0);
770 if (!found)
771 module_put(newinfo->fbops->owner);
772 err = -ENODEV;
773 }
774
775 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700776 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 kfree(ops->cursor_state.mask);
778 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800779 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 kfree(oldinfo->fbcon_par);
781 oldinfo->fbcon_par = NULL;
782 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800783 /*
784 If oldinfo and newinfo are driving the same hardware,
785 the fb_release() method of oldinfo may attempt to
786 restore the hardware state. This will leave the
787 newinfo in an undefined state. Thus, a call to
788 fb_set_par() may be needed for the newinfo.
789 */
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700790 if (newinfo->fbops->fb_set_par) {
791 ret = newinfo->fbops->fb_set_par(newinfo);
792
793 if (ret)
794 printk(KERN_ERR "con2fb_release_oldinfo: "
795 "detected unhandled fb_set_par error, "
796 "error code %d\n", ret);
797 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799
800 return err;
801}
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
804 int unit, int show_logo)
805{
806 struct fbcon_ops *ops = info->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700807 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 ops->currcon = fg_console;
810
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700811 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
812 ret = info->fbops->fb_set_par(info);
813
814 if (ret)
815 printk(KERN_ERR "con2fb_init_display: detected "
816 "unhandled fb_set_par error, "
817 "error code %d\n", ret);
818 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 ops->flags |= FBCON_FLAGS_INIT;
821 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700822 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 if (show_logo) {
825 struct vc_data *fg_vc = vc_cons[fg_console].d;
826 struct fb_info *fg_info =
827 registered_fb[con2fb_map[fg_console]];
828
829 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
830 fg_vc->vc_rows, fg_vc->vc_cols,
831 fg_vc->vc_rows);
832 }
833
834 update_screen(vc_cons[fg_console].d);
835}
836
837/**
838 * set_con2fb_map - map console to frame buffer device
839 * @unit: virtual console number to map
840 * @newidx: frame buffer index to map virtual console to
841 * @user: user request
842 *
843 * Maps a virtual console @unit to a frame buffer device
844 * @newidx.
845 */
846static int set_con2fb_map(int unit, int newidx, int user)
847{
848 struct vc_data *vc = vc_cons[unit].d;
849 int oldidx = con2fb_map[unit];
850 struct fb_info *info = registered_fb[newidx];
851 struct fb_info *oldinfo = NULL;
852 int found, err = 0;
853
854 if (oldidx == newidx)
855 return 0;
856
Dave Airlie32b98bf2010-12-21 01:41:17 +0000857 if (!info)
Antonino A. Daplase614b182006-06-26 00:27:09 -0700858 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Dave Airlie32b98bf2010-12-21 01:41:17 +0000860 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 info_idx = newidx;
862 return fbcon_takeover(0);
863 }
864
865 if (oldidx != -1)
866 oldinfo = registered_fb[oldidx];
867
868 found = search_fb_in_map(newidx);
869
Torben Hohnac751ef2011-01-25 15:07:35 -0800870 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 con2fb_map[unit] = newidx;
872 if (!err && !found)
873 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
874
875
876 /*
877 * If old fb is not mapped to any of the consoles,
878 * fbcon should release it.
879 */
880 if (!err && oldinfo && !search_fb_in_map(oldidx))
881 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
882 found);
883
884 if (!err) {
885 int show_logo = (fg_console == 0 && !user &&
886 logo_shown != FBCON_LOGO_DONTSHOW);
887
888 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700889 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 con2fb_map_boot[unit] = newidx;
891 con2fb_init_display(vc, info, unit, show_logo);
892 }
893
Antonino A. Daplase614b182006-06-26 00:27:09 -0700894 if (!search_fb_in_map(info_idx))
895 info_idx = newidx;
896
Torben Hohnac751ef2011-01-25 15:07:35 -0800897 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return err;
899}
900
901/*
902 * Low Level Operations
903 */
904/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
905static int var_to_display(struct display *disp,
906 struct fb_var_screeninfo *var,
907 struct fb_info *info)
908{
909 disp->xres_virtual = var->xres_virtual;
910 disp->yres_virtual = var->yres_virtual;
911 disp->bits_per_pixel = var->bits_per_pixel;
912 disp->grayscale = var->grayscale;
913 disp->nonstd = var->nonstd;
914 disp->accel_flags = var->accel_flags;
915 disp->height = var->height;
916 disp->width = var->width;
917 disp->red = var->red;
918 disp->green = var->green;
919 disp->blue = var->blue;
920 disp->transp = var->transp;
921 disp->rotate = var->rotate;
922 disp->mode = fb_match_mode(var, &info->modelist);
923 if (disp->mode == NULL)
924 /* This should not happen */
925 return -EINVAL;
926 return 0;
927}
928
929static void display_to_var(struct fb_var_screeninfo *var,
930 struct display *disp)
931{
932 fb_videomode_to_var(var, disp->mode);
933 var->xres_virtual = disp->xres_virtual;
934 var->yres_virtual = disp->yres_virtual;
935 var->bits_per_pixel = disp->bits_per_pixel;
936 var->grayscale = disp->grayscale;
937 var->nonstd = disp->nonstd;
938 var->accel_flags = disp->accel_flags;
939 var->height = disp->height;
940 var->width = disp->width;
941 var->red = disp->red;
942 var->green = disp->green;
943 var->blue = disp->blue;
944 var->transp = disp->transp;
945 var->rotate = disp->rotate;
946}
947
948static const char *fbcon_startup(void)
949{
950 const char *display_desc = "frame buffer device";
951 struct display *p = &fb_display[fg_console];
952 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700953 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 struct module *owner;
955 struct fb_info *info = NULL;
956 struct fbcon_ops *ops;
957 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /*
960 * If num_registered_fb is zero, this is a call for the dummy part.
961 * The frame buffer devices weren't initialized yet.
962 */
963 if (!num_registered_fb || info_idx == -1)
964 return display_desc;
965 /*
966 * Instead of blindly using registered_fb[0], we use info_idx, set by
967 * fb_console_init();
968 */
969 info = registered_fb[info_idx];
970 if (!info)
971 return NULL;
972
973 owner = info->fbops->owner;
974 if (!try_module_get(owner))
975 return NULL;
976 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
977 module_put(owner);
978 return NULL;
979 }
980
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800981 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (!ops) {
983 module_put(owner);
984 return NULL;
985 }
986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 ops->currcon = -1;
988 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800989 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800991 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800992 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993
994 if (info->fix.type != FB_TYPE_TEXT) {
995 if (fbcon_softback_size) {
996 if (!softback_buf) {
997 softback_buf =
998 (unsigned long)
999 kmalloc(fbcon_softback_size,
1000 GFP_KERNEL);
1001 if (!softback_buf) {
1002 fbcon_softback_size = 0;
1003 softback_top = 0;
1004 }
1005 }
1006 } else {
1007 if (softback_buf) {
1008 kfree((void *) softback_buf);
1009 softback_buf = 0;
1010 softback_top = 0;
1011 }
1012 }
1013 if (softback_buf)
1014 softback_in = softback_top = softback_curr =
1015 softback_buf;
1016 softback_lines = 0;
1017 }
1018
1019 /* Setup default font */
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001020 if (!p->fontdata && !vc->vc_font.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (!fontname[0] || !(font = find_font(fontname)))
1022 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001023 info->var.yres,
1024 info->pixmap.blit_x,
1025 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 vc->vc_font.width = font->width;
1027 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001028 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001030 } else {
1031 p->fontdata = vc->vc_font.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
1033
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001034 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1035 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1036 cols /= vc->vc_font.width;
1037 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 vc_resize(vc, cols, rows);
1039
1040 DPRINTK("mode: %s\n", info->fix.id);
1041 DPRINTK("visual: %d\n", info->fix.visual);
1042 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1043 info->var.yres,
1044 info->var.bits_per_pixel);
1045
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001046 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001047 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 return display_desc;
1049}
1050
1051static void fbcon_init(struct vc_data *vc, int init)
1052{
1053 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1054 struct fbcon_ops *ops;
1055 struct vc_data **default_mode = vc->vc_display_fg;
1056 struct vc_data *svc = *default_mode;
1057 struct display *t, *p = &fb_display[vc->vc_num];
1058 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001059 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061 if (info_idx == -1 || info == NULL)
1062 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001063
1064 cap = info->flags;
1065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1067 (info->fix.type == FB_TYPE_TEXT))
1068 logo = 0;
1069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (var_to_display(p, &info->var, info))
1071 return;
1072
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001073 if (!info->fbcon_par)
1074 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 /* If we are not the first console on this
1077 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001078 t = &fb_display[fg_console];
1079 if (!p->fontdata) {
1080 if (t->fontdata) {
1081 struct vc_data *fvc = vc_cons[fg_console].d;
1082
1083 vc->vc_font.data = (void *)(p->fontdata =
1084 fvc->vc_font.data);
1085 vc->vc_font.width = fvc->vc_font.width;
1086 vc->vc_font.height = fvc->vc_font.height;
1087 p->userfont = t->userfont;
1088
1089 if (p->userfont)
1090 REFCOUNT(p->fontdata)++;
1091 } else {
1092 const struct font_desc *font = NULL;
1093
1094 if (!fontname[0] || !(font = find_font(fontname)))
1095 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001096 info->var.yres,
1097 info->pixmap.blit_x,
1098 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001099 vc->vc_font.width = font->width;
1100 vc->vc_font.height = font->height;
1101 vc->vc_font.data = (void *)(p->fontdata = font->data);
1102 vc->vc_font.charcount = 256; /* FIXME Need to
1103 support more fonts */
1104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (p->userfont)
1108 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001109
Jesse Barnes8fd4bd22010-06-23 12:56:12 -07001110 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001111 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1113 if (charcnt == 256) {
1114 vc->vc_hi_font_mask = 0;
1115 } else {
1116 vc->vc_hi_font_mask = 0x100;
1117 if (vc->vc_can_do_color)
1118 vc->vc_complement_mask <<= 1;
1119 }
1120
1121 if (!*svc->vc_uni_pagedir_loc)
1122 con_set_default_unimap(svc);
1123 if (!*vc->vc_uni_pagedir_loc)
1124 con_copy_unimap(vc, svc);
1125
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001126 ops = info->fbcon_par;
Marcin Slusarz2428e592008-02-06 01:39:14 -08001127 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001128 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 cols = vc->vc_cols;
1131 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001132 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1133 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1134 new_cols /= vc->vc_font.width;
1135 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 /*
1138 * We must always set the mode. The mode of the previous console
1139 * driver could be in the same resolution but we are using different
1140 * hardware so we have to initialize the hardware.
1141 *
1142 * We need to do it in fbcon_init() to prevent screen corruption.
1143 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001144 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001146 !(ops->flags & FBCON_FLAGS_INIT)) {
1147 ret = info->fbops->fb_set_par(info);
1148
1149 if (ret)
1150 printk(KERN_ERR "fbcon_init: detected "
1151 "unhandled fb_set_par error, "
1152 "error code %d\n", ret);
1153 }
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 ops->flags |= FBCON_FLAGS_INIT;
1156 }
1157
1158 ops->graphics = 0;
1159
1160 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1161 !(cap & FBINFO_HWACCEL_DISABLED))
1162 p->scrollmode = SCROLL_MOVE;
1163 else /* default to something safe */
1164 p->scrollmode = SCROLL_REDRAW;
1165
1166 /*
1167 * ++guenther: console.c:vc_allocate() relies on initializing
1168 * vc_{cols,rows}, but we must not set those if we are only
1169 * resizing the console.
1170 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001171 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 vc->vc_cols = new_cols;
1173 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001174 } else
1175 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 if (logo)
1178 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1179
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001180 if (vc == svc && softback_buf)
1181 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001182
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001183 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001184 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001185 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001186 }
1187
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001188 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001191static void fbcon_free_font(struct display *p, bool freefont)
Antonino A. Daplase614b182006-06-26 00:27:09 -07001192{
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001193 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001194 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1195 p->fontdata = NULL;
1196 p->userfont = 0;
1197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199static void fbcon_deinit(struct vc_data *vc)
1200{
1201 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001202 struct fb_info *info;
1203 struct fbcon_ops *ops;
1204 int idx;
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001205 bool free_font = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Antonino A. Daplase614b182006-06-26 00:27:09 -07001207 idx = con2fb_map[vc->vc_num];
1208
1209 if (idx == -1)
1210 goto finished;
1211
1212 info = registered_fb[idx];
1213
1214 if (!info)
1215 goto finished;
1216
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001217 if (info->flags & FBINFO_MISC_FIRMWARE)
1218 free_font = false;
Antonino A. Daplase614b182006-06-26 00:27:09 -07001219 ops = info->fbcon_par;
1220
1221 if (!ops)
1222 goto finished;
1223
1224 if (CON_IS_VISIBLE(vc))
1225 fbcon_del_cursor_timer(info);
1226
1227 ops->flags &= ~FBCON_FLAGS_INIT;
1228finished:
1229
Dave Airlie62a3dcc2013-01-24 16:12:41 +10001230 fbcon_free_font(p, free_font);
1231
Antonino A. Daplase614b182006-06-26 00:27:09 -07001232 if (!con_is_bound(&fb_con))
1233 fbcon_exit();
1234
1235 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236}
1237
1238/* ====================================================================== */
1239
1240/* fbcon_XXX routines - interface used by the world
1241 *
1242 * This system is now divided into two levels because of complications
1243 * caused by hardware scrolling. Top level functions:
1244 *
1245 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1246 *
1247 * handles y values in range [0, scr_height-1] that correspond to real
1248 * screen positions. y_wrap shift means that first line of bitmap may be
1249 * anywhere on this display. These functions convert lineoffsets to
1250 * bitmap offsets and deal with the wrap-around case by splitting blits.
1251 *
1252 * fbcon_bmove_physical_8() -- These functions fast implementations
1253 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1254 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1255 *
1256 * WARNING:
1257 *
1258 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1259 * Implies should only really hardware scroll in rows. Only reason for
1260 * restriction is simplicity & efficiency at the moment.
1261 */
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1264 int width)
1265{
1266 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1267 struct fbcon_ops *ops = info->fbcon_par;
1268
1269 struct display *p = &fb_display[vc->vc_num];
1270 u_int y_break;
1271
1272 if (fbcon_is_inactive(vc, info))
1273 return;
1274
1275 if (!height || !width)
1276 return;
1277
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001278 if (sy < vc->vc_top && vc->vc_top == logo_lines)
1279 vc->vc_top = 0;
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 /* Split blits that cross physical y_wrap boundary */
1282
1283 y_break = p->vrows - p->yscroll;
1284 if (sy < y_break && sy + height - 1 >= y_break) {
1285 u_int b = y_break - sy;
1286 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1287 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1288 width);
1289 } else
1290 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1291}
1292
1293static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1294 int count, int ypos, int xpos)
1295{
1296 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1297 struct display *p = &fb_display[vc->vc_num];
1298 struct fbcon_ops *ops = info->fbcon_par;
1299
1300 if (!fbcon_is_inactive(vc, info))
1301 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1302 get_color(vc, info, scr_readw(s), 1),
1303 get_color(vc, info, scr_readw(s), 0));
1304}
1305
1306static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1307{
1308 unsigned short chr;
1309
1310 scr_writew(c, &chr);
1311 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1312}
1313
1314static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1315{
1316 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1317 struct fbcon_ops *ops = info->fbcon_par;
1318
1319 if (!fbcon_is_inactive(vc, info))
1320 ops->clear_margins(vc, info, bottom_only);
1321}
1322
1323static void fbcon_cursor(struct vc_data *vc, int mode)
1324{
1325 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1326 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 int y;
1328 int c = scr_readw((u16 *) vc->vc_pos);
1329
Michal Januszewskid1e23062007-05-08 00:38:07 -07001330 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 return;
1332
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001333 if (vc->vc_cursor_type & 0x10)
1334 fbcon_del_cursor_timer(info);
1335 else
1336 fbcon_add_cursor_timer(info);
1337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1339 if (mode & CM_SOFTBACK) {
1340 mode &= ~CM_SOFTBACK;
1341 y = softback_lines;
1342 } else {
1343 if (softback_lines)
1344 fbcon_set_origin(vc);
1345 y = 0;
1346 }
1347
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001348 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 get_color(vc, info, c, 0));
1350 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1351}
1352
1353static int scrollback_phys_max = 0;
1354static int scrollback_max = 0;
1355static int scrollback_current = 0;
1356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001358 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001360 struct display *p, *t;
1361 struct vc_data **default_mode, *vc;
1362 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001363 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 int rows, cols, charcnt = 256;
1365
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001366 p = &fb_display[unit];
1367
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if (var_to_display(p, var, info))
1369 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001370
1371 vc = vc_cons[unit].d;
1372
1373 if (!vc)
1374 return;
1375
1376 default_mode = vc->vc_display_fg;
1377 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001379
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001381 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 vc->vc_font.width = (*default_mode)->vc_font.width;
1383 vc->vc_font.height = (*default_mode)->vc_font.height;
1384 p->userfont = t->userfont;
1385 if (p->userfont)
1386 REFCOUNT(p->fontdata)++;
1387 }
1388 if (p->userfont)
1389 charcnt = FNTCHARCNT(p->fontdata);
1390
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001391 var->activate = FB_ACTIVATE_NOW;
1392 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001393 var->yoffset = info->var.yoffset;
1394 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001395 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001396 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001397 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1399 if (charcnt == 256) {
1400 vc->vc_hi_font_mask = 0;
1401 } else {
1402 vc->vc_hi_font_mask = 0x100;
1403 if (vc->vc_can_do_color)
1404 vc->vc_complement_mask <<= 1;
1405 }
1406
1407 if (!*svc->vc_uni_pagedir_loc)
1408 con_set_default_unimap(svc);
1409 if (!*vc->vc_uni_pagedir_loc)
1410 con_copy_unimap(vc, svc);
1411
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001412 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1413 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1414 cols /= vc->vc_font.width;
1415 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001417
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 if (CON_IS_VISIBLE(vc)) {
1419 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001420 if (softback_buf)
1421 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423}
1424
1425static __inline__ void ywrap_up(struct vc_data *vc, int count)
1426{
1427 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001428 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 struct display *p = &fb_display[vc->vc_num];
1430
1431 p->yscroll += count;
1432 if (p->yscroll >= p->vrows) /* Deal with wrap */
1433 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001434 ops->var.xoffset = 0;
1435 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1436 ops->var.vmode |= FB_VMODE_YWRAP;
1437 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 scrollback_max += count;
1439 if (scrollback_max > scrollback_phys_max)
1440 scrollback_max = scrollback_phys_max;
1441 scrollback_current = 0;
1442}
1443
1444static __inline__ void ywrap_down(struct vc_data *vc, int count)
1445{
1446 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001447 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 struct display *p = &fb_display[vc->vc_num];
1449
1450 p->yscroll -= count;
1451 if (p->yscroll < 0) /* Deal with wrap */
1452 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001453 ops->var.xoffset = 0;
1454 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1455 ops->var.vmode |= FB_VMODE_YWRAP;
1456 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 scrollback_max -= count;
1458 if (scrollback_max < 0)
1459 scrollback_max = 0;
1460 scrollback_current = 0;
1461}
1462
1463static __inline__ void ypan_up(struct vc_data *vc, int count)
1464{
1465 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1466 struct display *p = &fb_display[vc->vc_num];
1467 struct fbcon_ops *ops = info->fbcon_par;
1468
1469 p->yscroll += count;
1470 if (p->yscroll > p->vrows - vc->vc_rows) {
1471 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1472 0, 0, 0, vc->vc_rows, vc->vc_cols);
1473 p->yscroll -= p->vrows - vc->vc_rows;
1474 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001475
1476 ops->var.xoffset = 0;
1477 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1478 ops->var.vmode &= ~FB_VMODE_YWRAP;
1479 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 fbcon_clear_margins(vc, 1);
1481 scrollback_max += count;
1482 if (scrollback_max > scrollback_phys_max)
1483 scrollback_max = scrollback_phys_max;
1484 scrollback_current = 0;
1485}
1486
1487static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1488{
1489 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001490 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if (p->yscroll > p->vrows - vc->vc_rows) {
1496 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001498 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001499
1500 ops->var.xoffset = 0;
1501 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1502 ops->var.vmode &= ~FB_VMODE_YWRAP;
1503 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 fbcon_clear_margins(vc, 1);
1505 scrollback_max += count;
1506 if (scrollback_max > scrollback_phys_max)
1507 scrollback_max = scrollback_phys_max;
1508 scrollback_current = 0;
1509}
1510
1511static __inline__ void ypan_down(struct vc_data *vc, int count)
1512{
1513 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1514 struct display *p = &fb_display[vc->vc_num];
1515 struct fbcon_ops *ops = info->fbcon_par;
1516
1517 p->yscroll -= count;
1518 if (p->yscroll < 0) {
1519 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1520 0, vc->vc_rows, vc->vc_cols);
1521 p->yscroll += p->vrows - vc->vc_rows;
1522 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001523
1524 ops->var.xoffset = 0;
1525 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1526 ops->var.vmode &= ~FB_VMODE_YWRAP;
1527 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 fbcon_clear_margins(vc, 1);
1529 scrollback_max -= count;
1530 if (scrollback_max < 0)
1531 scrollback_max = 0;
1532 scrollback_current = 0;
1533}
1534
1535static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1536{
1537 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001538 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001542
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 if (p->yscroll < 0) {
1544 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001546 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001547
1548 ops->var.xoffset = 0;
1549 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1550 ops->var.vmode &= ~FB_VMODE_YWRAP;
1551 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 fbcon_clear_margins(vc, 1);
1553 scrollback_max -= count;
1554 if (scrollback_max < 0)
1555 scrollback_max = 0;
1556 scrollback_current = 0;
1557}
1558
1559static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1560 long delta)
1561{
1562 int count = vc->vc_rows;
1563 unsigned short *d, *s;
1564 unsigned long n;
1565 int line = 0;
1566
1567 d = (u16 *) softback_curr;
1568 if (d == (u16 *) softback_in)
1569 d = (u16 *) vc->vc_origin;
1570 n = softback_curr + delta * vc->vc_size_row;
1571 softback_lines -= delta;
1572 if (delta < 0) {
1573 if (softback_curr < softback_top && n < softback_buf) {
1574 n += softback_end - softback_buf;
1575 if (n < softback_top) {
1576 softback_lines -=
1577 (softback_top - n) / vc->vc_size_row;
1578 n = softback_top;
1579 }
1580 } else if (softback_curr >= softback_top
1581 && n < softback_top) {
1582 softback_lines -=
1583 (softback_top - n) / vc->vc_size_row;
1584 n = softback_top;
1585 }
1586 } else {
1587 if (softback_curr > softback_in && n >= softback_end) {
1588 n += softback_buf - softback_end;
1589 if (n > softback_in) {
1590 n = softback_in;
1591 softback_lines = 0;
1592 }
1593 } else if (softback_curr <= softback_in && n > softback_in) {
1594 n = softback_in;
1595 softback_lines = 0;
1596 }
1597 }
1598 if (n == softback_curr)
1599 return;
1600 softback_curr = n;
1601 s = (u16 *) softback_curr;
1602 if (s == (u16 *) softback_in)
1603 s = (u16 *) vc->vc_origin;
1604 while (count--) {
1605 unsigned short *start;
1606 unsigned short *le;
1607 unsigned short c;
1608 int x = 0;
1609 unsigned short attr = 1;
1610
1611 start = s;
1612 le = advance_row(s, 1);
1613 do {
1614 c = scr_readw(s);
1615 if (attr != (c & 0xff00)) {
1616 attr = c & 0xff00;
1617 if (s > start) {
1618 fbcon_putcs(vc, start, s - start,
1619 line, x);
1620 x += s - start;
1621 start = s;
1622 }
1623 }
1624 if (c == scr_readw(d)) {
1625 if (s > start) {
1626 fbcon_putcs(vc, start, s - start,
1627 line, x);
1628 x += s - start + 1;
1629 start = s + 1;
1630 } else {
1631 x++;
1632 start++;
1633 }
1634 }
1635 s++;
1636 d++;
1637 } while (s < le);
1638 if (s > start)
1639 fbcon_putcs(vc, start, s - start, line, x);
1640 line++;
1641 if (d == (u16 *) softback_end)
1642 d = (u16 *) softback_buf;
1643 if (d == (u16 *) softback_in)
1644 d = (u16 *) vc->vc_origin;
1645 if (s == (u16 *) softback_end)
1646 s = (u16 *) softback_buf;
1647 if (s == (u16 *) softback_in)
1648 s = (u16 *) vc->vc_origin;
1649 }
1650}
1651
1652static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1653 int line, int count, int dy)
1654{
1655 unsigned short *s = (unsigned short *)
1656 (vc->vc_origin + vc->vc_size_row * line);
1657
1658 while (count--) {
1659 unsigned short *start = s;
1660 unsigned short *le = advance_row(s, 1);
1661 unsigned short c;
1662 int x = 0;
1663 unsigned short attr = 1;
1664
1665 do {
1666 c = scr_readw(s);
1667 if (attr != (c & 0xff00)) {
1668 attr = c & 0xff00;
1669 if (s > start) {
1670 fbcon_putcs(vc, start, s - start,
1671 dy, x);
1672 x += s - start;
1673 start = s;
1674 }
1675 }
1676 console_conditional_schedule();
1677 s++;
1678 } while (s < le);
1679 if (s > start)
1680 fbcon_putcs(vc, start, s - start, dy, x);
1681 console_conditional_schedule();
1682 dy++;
1683 }
1684}
1685
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001686static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1687 struct display *p, int line, int count, int ycount)
1688{
1689 int offset = ycount * vc->vc_cols;
1690 unsigned short *d = (unsigned short *)
1691 (vc->vc_origin + vc->vc_size_row * line);
1692 unsigned short *s = d + offset;
1693 struct fbcon_ops *ops = info->fbcon_par;
1694
1695 while (count--) {
1696 unsigned short *start = s;
1697 unsigned short *le = advance_row(s, 1);
1698 unsigned short c;
1699 int x = 0;
1700
1701 do {
1702 c = scr_readw(s);
1703
1704 if (c == scr_readw(d)) {
1705 if (s > start) {
1706 ops->bmove(vc, info, line + ycount, x,
1707 line, x, 1, s-start);
1708 x += s - start + 1;
1709 start = s + 1;
1710 } else {
1711 x++;
1712 start++;
1713 }
1714 }
1715
1716 scr_writew(c, d);
1717 console_conditional_schedule();
1718 s++;
1719 d++;
1720 } while (s < le);
1721 if (s > start)
1722 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1723 s-start);
1724 console_conditional_schedule();
1725 if (ycount > 0)
1726 line++;
1727 else {
1728 line--;
1729 /* NOTE: We subtract two lines from these pointers */
1730 s -= vc->vc_size_row;
1731 d -= vc->vc_size_row;
1732 }
1733 }
1734}
1735
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736static void fbcon_redraw(struct vc_data *vc, struct display *p,
1737 int line, int count, int offset)
1738{
1739 unsigned short *d = (unsigned short *)
1740 (vc->vc_origin + vc->vc_size_row * line);
1741 unsigned short *s = d + offset;
1742
1743 while (count--) {
1744 unsigned short *start = s;
1745 unsigned short *le = advance_row(s, 1);
1746 unsigned short c;
1747 int x = 0;
1748 unsigned short attr = 1;
1749
1750 do {
1751 c = scr_readw(s);
1752 if (attr != (c & 0xff00)) {
1753 attr = c & 0xff00;
1754 if (s > start) {
1755 fbcon_putcs(vc, start, s - start,
1756 line, x);
1757 x += s - start;
1758 start = s;
1759 }
1760 }
1761 if (c == scr_readw(d)) {
1762 if (s > start) {
1763 fbcon_putcs(vc, start, s - start,
1764 line, x);
1765 x += s - start + 1;
1766 start = s + 1;
1767 } else {
1768 x++;
1769 start++;
1770 }
1771 }
1772 scr_writew(c, d);
1773 console_conditional_schedule();
1774 s++;
1775 d++;
1776 } while (s < le);
1777 if (s > start)
1778 fbcon_putcs(vc, start, s - start, line, x);
1779 console_conditional_schedule();
1780 if (offset > 0)
1781 line++;
1782 else {
1783 line--;
1784 /* NOTE: We subtract two lines from these pointers */
1785 s -= vc->vc_size_row;
1786 d -= vc->vc_size_row;
1787 }
1788 }
1789}
1790
1791static inline void fbcon_softback_note(struct vc_data *vc, int t,
1792 int count)
1793{
1794 unsigned short *p;
1795
1796 if (vc->vc_num != fg_console)
1797 return;
1798 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1799
1800 while (count) {
1801 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1802 count--;
1803 p = advance_row(p, 1);
1804 softback_in += vc->vc_size_row;
1805 if (softback_in == softback_end)
1806 softback_in = softback_buf;
1807 if (softback_in == softback_top) {
1808 softback_top += vc->vc_size_row;
1809 if (softback_top == softback_end)
1810 softback_top = softback_buf;
1811 }
1812 }
1813 softback_curr = softback_in;
1814}
1815
1816static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1817 int count)
1818{
1819 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1820 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1822
1823 if (fbcon_is_inactive(vc, info))
1824 return -EINVAL;
1825
1826 fbcon_cursor(vc, CM_ERASE);
1827
1828 /*
1829 * ++Geert: Only use ywrap/ypan if the console is in text mode
1830 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1831 * whole screen (prevents flicker).
1832 */
1833
1834 switch (dir) {
1835 case SM_UP:
1836 if (count > vc->vc_rows) /* Maximum realistic size */
1837 count = vc->vc_rows;
1838 if (softback_top)
1839 fbcon_softback_note(vc, t, count);
1840 if (logo_shown >= 0)
1841 goto redraw_up;
1842 switch (p->scrollmode) {
1843 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001844 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1845 count);
1846 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1847 scr_memsetw((unsigned short *) (vc->vc_origin +
1848 vc->vc_size_row *
1849 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001850 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001851 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001852 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 break;
1854
1855 case SCROLL_WRAP_MOVE:
1856 if (b - t - count > 3 * vc->vc_rows >> 2) {
1857 if (t > 0)
1858 fbcon_bmove(vc, 0, 0, count, 0, t,
1859 vc->vc_cols);
1860 ywrap_up(vc, count);
1861 if (vc->vc_rows - b > 0)
1862 fbcon_bmove(vc, b - count, 0, b, 0,
1863 vc->vc_rows - b,
1864 vc->vc_cols);
1865 } else if (info->flags & FBINFO_READS_FAST)
1866 fbcon_bmove(vc, t + count, 0, t, 0,
1867 b - t - count, vc->vc_cols);
1868 else
1869 goto redraw_up;
1870 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1871 break;
1872
1873 case SCROLL_PAN_REDRAW:
1874 if ((p->yscroll + count <=
1875 2 * (p->vrows - vc->vc_rows))
1876 && ((!scroll_partial && (b - t == vc->vc_rows))
1877 || (scroll_partial
1878 && (b - t - count >
1879 3 * vc->vc_rows >> 2)))) {
1880 if (t > 0)
1881 fbcon_redraw_move(vc, p, 0, t, count);
1882 ypan_up_redraw(vc, t, count);
1883 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001884 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 vc->vc_rows - b, b);
1886 } else
1887 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1888 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1889 break;
1890
1891 case SCROLL_PAN_MOVE:
1892 if ((p->yscroll + count <=
1893 2 * (p->vrows - vc->vc_rows))
1894 && ((!scroll_partial && (b - t == vc->vc_rows))
1895 || (scroll_partial
1896 && (b - t - count >
1897 3 * vc->vc_rows >> 2)))) {
1898 if (t > 0)
1899 fbcon_bmove(vc, 0, 0, count, 0, t,
1900 vc->vc_cols);
1901 ypan_up(vc, count);
1902 if (vc->vc_rows - b > 0)
1903 fbcon_bmove(vc, b - count, 0, b, 0,
1904 vc->vc_rows - b,
1905 vc->vc_cols);
1906 } else if (info->flags & FBINFO_READS_FAST)
1907 fbcon_bmove(vc, t + count, 0, t, 0,
1908 b - t - count, vc->vc_cols);
1909 else
1910 goto redraw_up;
1911 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1912 break;
1913
1914 case SCROLL_REDRAW:
1915 redraw_up:
1916 fbcon_redraw(vc, p, t, b - t - count,
1917 count * vc->vc_cols);
1918 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1919 scr_memsetw((unsigned short *) (vc->vc_origin +
1920 vc->vc_size_row *
1921 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001922 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001924 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 }
1926 break;
1927
1928 case SM_DOWN:
1929 if (count > vc->vc_rows) /* Maximum realistic size */
1930 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001931 if (logo_shown >= 0)
1932 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 switch (p->scrollmode) {
1934 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001935 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1936 -count);
1937 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1938 scr_memsetw((unsigned short *) (vc->vc_origin +
1939 vc->vc_size_row *
1940 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001941 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001942 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001943 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 break;
1945
1946 case SCROLL_WRAP_MOVE:
1947 if (b - t - count > 3 * vc->vc_rows >> 2) {
1948 if (vc->vc_rows - b > 0)
1949 fbcon_bmove(vc, b, 0, b - count, 0,
1950 vc->vc_rows - b,
1951 vc->vc_cols);
1952 ywrap_down(vc, count);
1953 if (t > 0)
1954 fbcon_bmove(vc, count, 0, 0, 0, t,
1955 vc->vc_cols);
1956 } else if (info->flags & FBINFO_READS_FAST)
1957 fbcon_bmove(vc, t, 0, t + count, 0,
1958 b - t - count, vc->vc_cols);
1959 else
1960 goto redraw_down;
1961 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1962 break;
1963
1964 case SCROLL_PAN_MOVE:
1965 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1966 && ((!scroll_partial && (b - t == vc->vc_rows))
1967 || (scroll_partial
1968 && (b - t - count >
1969 3 * vc->vc_rows >> 2)))) {
1970 if (vc->vc_rows - b > 0)
1971 fbcon_bmove(vc, b, 0, b - count, 0,
1972 vc->vc_rows - b,
1973 vc->vc_cols);
1974 ypan_down(vc, count);
1975 if (t > 0)
1976 fbcon_bmove(vc, count, 0, 0, 0, t,
1977 vc->vc_cols);
1978 } else if (info->flags & FBINFO_READS_FAST)
1979 fbcon_bmove(vc, t, 0, t + count, 0,
1980 b - t - count, vc->vc_cols);
1981 else
1982 goto redraw_down;
1983 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1984 break;
1985
1986 case SCROLL_PAN_REDRAW:
1987 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1988 && ((!scroll_partial && (b - t == vc->vc_rows))
1989 || (scroll_partial
1990 && (b - t - count >
1991 3 * vc->vc_rows >> 2)))) {
1992 if (vc->vc_rows - b > 0)
1993 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1994 b - count);
1995 ypan_down_redraw(vc, t, count);
1996 if (t > 0)
1997 fbcon_redraw_move(vc, p, count, t, 0);
1998 } else
1999 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2000 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2001 break;
2002
2003 case SCROLL_REDRAW:
2004 redraw_down:
2005 fbcon_redraw(vc, p, b - 1, b - t - count,
2006 -count * vc->vc_cols);
2007 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2008 scr_memsetw((unsigned short *) (vc->vc_origin +
2009 vc->vc_size_row *
2010 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07002011 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07002013 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 }
2015 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07002016 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017}
2018
2019
2020static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2021 int height, int width)
2022{
2023 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2024 struct display *p = &fb_display[vc->vc_num];
2025
2026 if (fbcon_is_inactive(vc, info))
2027 return;
2028
2029 if (!width || !height)
2030 return;
2031
2032 /* Split blits that cross physical y_wrap case.
2033 * Pathological case involves 4 blits, better to use recursive
2034 * code rather than unrolled case
2035 *
2036 * Recursive invocations don't need to erase the cursor over and
2037 * over again, so we use fbcon_bmove_rec()
2038 */
2039 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2040 p->vrows - p->yscroll);
2041}
2042
2043static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2044 int dy, int dx, int height, int width, u_int y_break)
2045{
2046 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2047 struct fbcon_ops *ops = info->fbcon_par;
2048 u_int b;
2049
2050 if (sy < y_break && sy + height > y_break) {
2051 b = y_break - sy;
2052 if (dy < sy) { /* Avoid trashing self */
2053 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2054 y_break);
2055 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2056 height - b, width, y_break);
2057 } else {
2058 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2059 height - b, width, y_break);
2060 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2061 y_break);
2062 }
2063 return;
2064 }
2065
2066 if (dy < y_break && dy + height > y_break) {
2067 b = y_break - dy;
2068 if (dy < sy) { /* Avoid trashing self */
2069 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2070 y_break);
2071 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2072 height - b, width, y_break);
2073 } else {
2074 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2075 height - b, width, y_break);
2076 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2077 y_break);
2078 }
2079 return;
2080 }
2081 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2082 height, width);
2083}
2084
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002085static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002086 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 struct vc_data *vc)
2088{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002089 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 int fh = vc->vc_font.height;
2091 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002092 u16 t = 0;
2093 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2094 info->fix.xpanstep);
2095 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2096 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2097 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2098 info->var.xres_virtual);
2099 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2100 divides(ypan, vc->vc_font.height) && vyres > yres;
2101 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2102 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002103 divides(vc->vc_font.height, vyres) &&
2104 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002106 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2107 !(cap & FBINFO_HWACCEL_DISABLED);
2108 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2109 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002111 p->vrows = vyres/fh;
2112 if (yres > (fh * (vc->vc_rows + 1)))
2113 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2114 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 p->vrows--;
2116
2117 if (good_wrap || good_pan) {
2118 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002119 p->scrollmode = good_wrap ?
2120 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 else
2122 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2123 SCROLL_PAN_REDRAW;
2124 } else {
2125 if (reading_fast || (fast_copyarea && !fast_imageblit))
2126 p->scrollmode = SCROLL_MOVE;
2127 else
2128 p->scrollmode = SCROLL_REDRAW;
2129 }
2130}
2131
2132static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002133 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
2135 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002136 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct display *p = &fb_display[vc->vc_num];
2138 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002139 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002141 virt_w = FBCON_SWAP(ops->rotate, width, height);
2142 virt_h = FBCON_SWAP(ops->rotate, height, width);
2143 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2144 vc->vc_font.height);
2145 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2146 vc->vc_font.width);
2147 var.xres = virt_w * virt_fw;
2148 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 x_diff = info->var.xres - var.xres;
2150 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002151 if (x_diff < 0 || x_diff > virt_fw ||
2152 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002153 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
2155 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2156 mode = fb_find_best_mode(&var, &info->modelist);
2157 if (mode == NULL)
2158 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002159 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002161
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002162 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
2165 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2166 if (CON_IS_VISIBLE(vc)) {
2167 var.activate = FB_ACTIVATE_NOW |
2168 FB_ACTIVATE_FORCE;
2169 fb_set_var(info, &var);
2170 }
2171 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002172 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 }
2174 updatescrollmode(p, info, vc);
2175 return 0;
2176}
2177
2178static int fbcon_switch(struct vc_data *vc)
2179{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002180 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002181 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 struct display *p = &fb_display[vc->vc_num];
2183 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002184 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
2186 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002187 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 if (softback_lines)
2191 fbcon_set_origin(vc);
2192 softback_top = softback_curr = softback_in = softback_buf;
2193 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002194 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 }
2196
2197 if (logo_shown >= 0) {
2198 struct vc_data *conp2 = vc_cons[logo_shown].d;
2199
2200 if (conp2->vc_top == logo_lines
2201 && conp2->vc_bottom == conp2->vc_rows)
2202 conp2->vc_top = 0;
2203 logo_shown = FBCON_LOGO_CANSHOW;
2204 }
2205
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002206 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002207 if (prev_console != -1)
2208 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 /*
2210 * FIXME: If we have multiple fbdev's loaded, we need to
2211 * update all info->currcon. Perhaps, we can place this
2212 * in a centralized structure, but this might break some
2213 * drivers.
2214 *
2215 * info->currcon = vc->vc_num;
2216 */
2217 for (i = 0; i < FB_MAX; i++) {
2218 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002219 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002221 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 }
2223 }
2224 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2225 display_to_var(&var, p);
2226 var.activate = FB_ACTIVATE_NOW;
2227
2228 /*
2229 * make sure we don't unnecessarily trip the memcmp()
2230 * in fb_set_var()
2231 */
2232 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002233 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002235 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Knut Petersen39942fd2005-12-12 22:17:19 -08002237 if (old_info != NULL && (old_info != info ||
2238 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002239 if (info->fbops->fb_set_par) {
2240 ret = info->fbops->fb_set_par(info);
2241
2242 if (ret)
2243 printk(KERN_ERR "fbcon_switch: detected "
2244 "unhandled fb_set_par error, "
2245 "error code %d\n", ret);
2246 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002247
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002248 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002249 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002252 if (fbcon_is_inactive(vc, info) ||
2253 ops->blank_state != FB_BLANK_UNBLANK)
2254 fbcon_del_cursor_timer(info);
2255 else
2256 fbcon_add_cursor_timer(info);
2257
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002258 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002259 ops->cursor_reset = 1;
2260
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002261 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002262 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002263 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002266 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002268
2269 if (p->userfont)
2270 charcnt = FNTCHARCNT(vc->vc_font.data);
2271
2272 if (charcnt > 256)
2273 vc->vc_complement_mask <<= 1;
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 updatescrollmode(p, info, vc);
2276
2277 switch (p->scrollmode) {
2278 case SCROLL_WRAP_MOVE:
2279 scrollback_phys_max = p->vrows - vc->vc_rows;
2280 break;
2281 case SCROLL_PAN_MOVE:
2282 case SCROLL_PAN_REDRAW:
2283 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2284 if (scrollback_phys_max < 0)
2285 scrollback_phys_max = 0;
2286 break;
2287 default:
2288 scrollback_phys_max = 0;
2289 break;
2290 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002291
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 scrollback_max = 0;
2293 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002294
2295 if (!fbcon_is_inactive(vc, info)) {
2296 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2297 ops->update_start(info);
2298 }
2299
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 fbcon_set_palette(vc, color_table);
2301 fbcon_clear_margins(vc, 0);
2302
2303 if (logo_shown == FBCON_LOGO_DRAW) {
2304
2305 logo_shown = fg_console;
2306 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002307 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 update_region(vc,
2309 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2310 vc->vc_size_row * (vc->vc_bottom -
2311 vc->vc_top) / 2);
2312 return 0;
2313 }
2314 return 1;
2315}
2316
2317static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2318 int blank)
2319{
Richard Purdie994efac2007-02-09 09:46:45 +00002320 struct fb_event event;
2321
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 if (blank) {
2323 unsigned short charmask = vc->vc_hi_font_mask ?
2324 0x1ff : 0xff;
2325 unsigned short oldc;
2326
2327 oldc = vc->vc_video_erase_char;
2328 vc->vc_video_erase_char &= charmask;
2329 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2330 vc->vc_video_erase_char = oldc;
2331 }
Richard Purdie994efac2007-02-09 09:46:45 +00002332
2333
Andrea Righi513adb52009-04-13 14:39:39 -07002334 if (!lock_fb_info(info))
2335 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002336 event.info = info;
2337 event.data = &blank;
2338 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002339 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340}
2341
2342static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2343{
2344 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2345 struct fbcon_ops *ops = info->fbcon_par;
2346
2347 if (mode_switch) {
2348 struct fb_var_screeninfo var = info->var;
2349
2350 ops->graphics = 1;
2351
2352 if (!blank) {
2353 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2354 fb_set_var(info, &var);
2355 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002356 ops->var = info->var;
Krzysztof Heltf5c15d02009-11-11 14:26:22 -08002357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 }
2359
2360 if (!fbcon_is_inactive(vc, info)) {
2361 if (ops->blank_state != blank) {
2362 ops->blank_state = blank;
2363 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2364 ops->cursor_flash = (!blank);
2365
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002366 if (!(info->flags & FBINFO_MISC_USEREVENT))
2367 if (fb_blank(info, blank))
2368 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 }
2370
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002371 if (!blank)
2372 update_screen(vc);
2373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002375 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002376 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002377 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002378 else
2379 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002380
2381 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382}
2383
Jesse Barnesd219adc2010-08-02 12:05:41 -07002384static int fbcon_debug_enter(struct vc_data *vc)
2385{
2386 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2387 struct fbcon_ops *ops = info->fbcon_par;
2388
2389 ops->save_graphics = ops->graphics;
2390 ops->graphics = 0;
2391 if (info->fbops->fb_debug_enter)
2392 info->fbops->fb_debug_enter(info);
2393 fbcon_set_palette(vc, color_table);
2394 return 0;
2395}
2396
2397static int fbcon_debug_leave(struct vc_data *vc)
2398{
2399 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2400 struct fbcon_ops *ops = info->fbcon_par;
2401
2402 ops->graphics = ops->save_graphics;
2403 if (info->fbops->fb_debug_leave)
2404 info->fbops->fb_debug_leave(info);
2405 return 0;
2406}
2407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2409{
2410 u8 *fontdata = vc->vc_font.data;
2411 u8 *data = font->data;
2412 int i, j;
2413
2414 font->width = vc->vc_font.width;
2415 font->height = vc->vc_font.height;
2416 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2417 if (!font->data)
2418 return 0;
2419
2420 if (font->width <= 8) {
2421 j = vc->vc_font.height;
2422 for (i = 0; i < font->charcount; i++) {
2423 memcpy(data, fontdata, j);
2424 memset(data + j, 0, 32 - j);
2425 data += 32;
2426 fontdata += j;
2427 }
2428 } else if (font->width <= 16) {
2429 j = vc->vc_font.height * 2;
2430 for (i = 0; i < font->charcount; i++) {
2431 memcpy(data, fontdata, j);
2432 memset(data + j, 0, 64 - j);
2433 data += 64;
2434 fontdata += j;
2435 }
2436 } else if (font->width <= 24) {
2437 for (i = 0; i < font->charcount; i++) {
2438 for (j = 0; j < vc->vc_font.height; j++) {
2439 *data++ = fontdata[0];
2440 *data++ = fontdata[1];
2441 *data++ = fontdata[2];
2442 fontdata += sizeof(u32);
2443 }
2444 memset(data, 0, 3 * (32 - j));
2445 data += 3 * (32 - j);
2446 }
2447 } else {
2448 j = vc->vc_font.height * 4;
2449 for (i = 0; i < font->charcount; i++) {
2450 memcpy(data, fontdata, j);
2451 memset(data + j, 0, 128 - j);
2452 data += 128;
2453 fontdata += j;
2454 }
2455 }
2456 return 0;
2457}
2458
2459static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002460 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461{
2462 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002463 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 struct display *p = &fb_display[vc->vc_num];
2465 int resize;
2466 int cnt;
2467 char *old_data = NULL;
2468
2469 if (CON_IS_VISIBLE(vc) && softback_lines)
2470 fbcon_set_origin(vc);
2471
2472 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2473 if (p->userfont)
2474 old_data = vc->vc_font.data;
2475 if (userfont)
2476 cnt = FNTCHARCNT(data);
2477 else
2478 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002479 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 if ((p->userfont = userfont))
2481 REFCOUNT(data)++;
2482 vc->vc_font.width = w;
2483 vc->vc_font.height = h;
2484 if (vc->vc_hi_font_mask && cnt == 256) {
2485 vc->vc_hi_font_mask = 0;
2486 if (vc->vc_can_do_color) {
2487 vc->vc_complement_mask >>= 1;
2488 vc->vc_s_complement_mask >>= 1;
2489 }
2490
2491 /* ++Edmund: reorder the attribute bits */
2492 if (vc->vc_can_do_color) {
2493 unsigned short *cp =
2494 (unsigned short *) vc->vc_origin;
2495 int count = vc->vc_screenbuf_size / 2;
2496 unsigned short c;
2497 for (; count > 0; count--, cp++) {
2498 c = scr_readw(cp);
2499 scr_writew(((c & 0xfe00) >> 1) |
2500 (c & 0xff), cp);
2501 }
2502 c = vc->vc_video_erase_char;
2503 vc->vc_video_erase_char =
2504 ((c & 0xfe00) >> 1) | (c & 0xff);
2505 vc->vc_attr >>= 1;
2506 }
2507 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2508 vc->vc_hi_font_mask = 0x100;
2509 if (vc->vc_can_do_color) {
2510 vc->vc_complement_mask <<= 1;
2511 vc->vc_s_complement_mask <<= 1;
2512 }
2513
2514 /* ++Edmund: reorder the attribute bits */
2515 {
2516 unsigned short *cp =
2517 (unsigned short *) vc->vc_origin;
2518 int count = vc->vc_screenbuf_size / 2;
2519 unsigned short c;
2520 for (; count > 0; count--, cp++) {
2521 unsigned short newc;
2522 c = scr_readw(cp);
2523 if (vc->vc_can_do_color)
2524 newc =
2525 ((c & 0xff00) << 1) | (c &
2526 0xff);
2527 else
2528 newc = c & ~0x100;
2529 scr_writew(newc, cp);
2530 }
2531 c = vc->vc_video_erase_char;
2532 if (vc->vc_can_do_color) {
2533 vc->vc_video_erase_char =
2534 ((c & 0xff00) << 1) | (c & 0xff);
2535 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002536 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 vc->vc_video_erase_char = c & ~0x100;
2538 }
2539
2540 }
2541
2542 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002543 int cols, rows;
2544
2545 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2546 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2547 cols /= w;
2548 rows /= h;
2549 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002550 if (CON_IS_VISIBLE(vc) && softback_buf)
2551 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 } else if (CON_IS_VISIBLE(vc)
2553 && vc->vc_mode == KD_TEXT) {
2554 fbcon_clear_margins(vc, 0);
2555 update_screen(vc);
2556 }
2557
2558 if (old_data && (--REFCOUNT(old_data) == 0))
2559 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2560 return 0;
2561}
2562
2563static int fbcon_copy_font(struct vc_data *vc, int con)
2564{
2565 struct display *od = &fb_display[con];
2566 struct console_font *f = &vc->vc_font;
2567
2568 if (od->fontdata == f->data)
2569 return 0; /* already the same font... */
2570 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2571}
2572
2573/*
2574 * User asked to set font; we are guaranteed that
2575 * a) width and height are in range 1..32
2576 * b) charcount does not exceed 512
2577 * but lets not assume that, since someone might someday want to use larger
2578 * fonts. And charcount of 512 is small for unicode support.
2579 *
2580 * However, user space gives the font in 32 rows , regardless of
2581 * actual font height. So a new API is needed if support for larger fonts
2582 * is ever implemented.
2583 */
2584
2585static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2586{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002587 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 unsigned charcount = font->charcount;
2589 int w = font->width;
2590 int h = font->height;
2591 int size;
2592 int i, csum;
2593 u8 *new_data, *data = font->data;
2594 int pitch = (font->width+7) >> 3;
2595
2596 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2597 * If not this check should be changed to charcount < 256 */
2598 if (charcount != 256 && charcount != 512)
2599 return -EINVAL;
2600
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002601 /* Make sure drawing engine can handle the font */
2602 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2603 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2604 return -EINVAL;
2605
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002606 /* Make sure driver can handle the font length */
2607 if (fbcon_invalid_charcount(info, charcount))
2608 return -EINVAL;
2609
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 size = h * pitch * charcount;
2611
2612 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2613
2614 if (!new_data)
2615 return -ENOMEM;
2616
2617 new_data += FONT_EXTRA_WORDS * sizeof(int);
2618 FNTSIZE(new_data) = size;
2619 FNTCHARCNT(new_data) = charcount;
2620 REFCOUNT(new_data) = 0; /* usage counter */
2621 for (i=0; i< charcount; i++) {
2622 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2623 }
2624
2625 /* Since linux has a nice crc32 function use it for counting font
2626 * checksums. */
2627 csum = crc32(0, new_data, size);
2628
2629 FNTSUM(new_data) = csum;
2630 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002631 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct vc_data *tmp = vc_cons[i].d;
2633
2634 if (fb_display[i].userfont &&
2635 fb_display[i].fontdata &&
2636 FNTSUM(fb_display[i].fontdata) == csum &&
2637 FNTSIZE(fb_display[i].fontdata) == size &&
2638 tmp->vc_font.width == w &&
2639 !memcmp(fb_display[i].fontdata, new_data, size)) {
2640 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002641 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 break;
2643 }
2644 }
2645 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2646}
2647
2648static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2649{
2650 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002651 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652
2653 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002654 f = get_default_font(info->var.xres, info->var.yres,
2655 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 else if (!(f = find_font(name)))
2657 return -ENOENT;
2658
2659 font->width = f->width;
2660 font->height = f->height;
2661 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2662}
2663
2664static u16 palette_red[16];
2665static u16 palette_green[16];
2666static u16 palette_blue[16];
2667
2668static struct fb_cmap palette_cmap = {
2669 0, 16, palette_red, palette_green, palette_blue, NULL
2670};
2671
2672static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2673{
2674 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2675 int i, j, k, depth;
2676 u8 val;
2677
2678 if (fbcon_is_inactive(vc, info))
2679 return -EINVAL;
2680
2681 if (!CON_IS_VISIBLE(vc))
2682 return 0;
2683
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002684 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 if (depth > 3) {
2686 for (i = j = 0; i < 16; i++) {
2687 k = table[i];
2688 val = vc->vc_palette[j++];
2689 palette_red[k] = (val << 8) | val;
2690 val = vc->vc_palette[j++];
2691 palette_green[k] = (val << 8) | val;
2692 val = vc->vc_palette[j++];
2693 palette_blue[k] = (val << 8) | val;
2694 }
2695 palette_cmap.len = 16;
2696 palette_cmap.start = 0;
2697 /*
2698 * If framebuffer is capable of less than 16 colors,
2699 * use default palette of fbcon.
2700 */
2701 } else
2702 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2703
2704 return fb_set_cmap(&palette_cmap, info);
2705}
2706
2707static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2708{
2709 unsigned long p;
2710 int line;
2711
2712 if (vc->vc_num != fg_console || !softback_lines)
2713 return (u16 *) (vc->vc_origin + offset);
2714 line = offset / vc->vc_size_row;
2715 if (line >= softback_lines)
2716 return (u16 *) (vc->vc_origin + offset -
2717 softback_lines * vc->vc_size_row);
2718 p = softback_curr + offset;
2719 if (p >= softback_end)
2720 p += softback_buf - softback_end;
2721 return (u16 *) p;
2722}
2723
2724static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2725 int *px, int *py)
2726{
2727 unsigned long ret;
2728 int x, y;
2729
2730 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2731 unsigned long offset = (pos - vc->vc_origin) / 2;
2732
2733 x = offset % vc->vc_cols;
2734 y = offset / vc->vc_cols;
2735 if (vc->vc_num == fg_console)
2736 y += softback_lines;
2737 ret = pos + (vc->vc_cols - x) * 2;
2738 } else if (vc->vc_num == fg_console && softback_lines) {
2739 unsigned long offset = pos - softback_curr;
2740
2741 if (pos < softback_curr)
2742 offset += softback_end - softback_buf;
2743 offset /= 2;
2744 x = offset % vc->vc_cols;
2745 y = offset / vc->vc_cols;
2746 ret = pos + (vc->vc_cols - x) * 2;
2747 if (ret == softback_end)
2748 ret = softback_buf;
2749 if (ret == softback_in)
2750 ret = vc->vc_origin;
2751 } else {
2752 /* Should not happen */
2753 x = y = 0;
2754 ret = vc->vc_origin;
2755 }
2756 if (px)
2757 *px = x;
2758 if (py)
2759 *py = y;
2760 return ret;
2761}
2762
2763/* As we might be inside of softback, we may work with non-contiguous buffer,
2764 that's why we have to use a separate routine. */
2765static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2766{
2767 while (cnt--) {
2768 u16 a = scr_readw(p);
2769 if (!vc->vc_can_do_color)
2770 a ^= 0x0800;
2771 else if (vc->vc_hi_font_mask == 0x100)
2772 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2773 (((a) & 0x0e00) << 4);
2774 else
2775 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2776 (((a) & 0x0700) << 4);
2777 scr_writew(a, p++);
2778 if (p == (u16 *) softback_end)
2779 p = (u16 *) softback_buf;
2780 if (p == (u16 *) softback_in)
2781 p = (u16 *) vc->vc_origin;
2782 }
2783}
2784
2785static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2786{
2787 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002788 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002789 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 int offset, limit, scrollback_old;
2791
2792 if (softback_top) {
2793 if (vc->vc_num != fg_console)
2794 return 0;
2795 if (vc->vc_mode != KD_TEXT || !lines)
2796 return 0;
2797 if (logo_shown >= 0) {
2798 struct vc_data *conp2 = vc_cons[logo_shown].d;
2799
2800 if (conp2->vc_top == logo_lines
2801 && conp2->vc_bottom == conp2->vc_rows)
2802 conp2->vc_top = 0;
2803 if (logo_shown == vc->vc_num) {
2804 unsigned long p, q;
2805 int i;
2806
2807 p = softback_in;
2808 q = vc->vc_origin +
2809 logo_lines * vc->vc_size_row;
2810 for (i = 0; i < logo_lines; i++) {
2811 if (p == softback_top)
2812 break;
2813 if (p == softback_buf)
2814 p = softback_end;
2815 p -= vc->vc_size_row;
2816 q -= vc->vc_size_row;
2817 scr_memcpyw((u16 *) q, (u16 *) p,
2818 vc->vc_size_row);
2819 }
David Hollister308af922006-05-30 21:25:36 -07002820 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 update_region(vc, vc->vc_origin,
2822 logo_lines * vc->vc_cols);
2823 }
2824 logo_shown = FBCON_LOGO_CANSHOW;
2825 }
2826 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002827 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2829 return 0;
2830 }
2831
2832 if (!scrollback_phys_max)
2833 return -ENOSYS;
2834
2835 scrollback_old = scrollback_current;
2836 scrollback_current -= lines;
2837 if (scrollback_current < 0)
2838 scrollback_current = 0;
2839 else if (scrollback_current > scrollback_max)
2840 scrollback_current = scrollback_max;
2841 if (scrollback_current == scrollback_old)
2842 return 0;
2843
2844 if (fbcon_is_inactive(vc, info))
2845 return 0;
2846
2847 fbcon_cursor(vc, CM_ERASE);
2848
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002849 offset = disp->yscroll - scrollback_current;
2850 limit = disp->vrows;
2851 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 case SCROLL_WRAP_MOVE:
2853 info->var.vmode |= FB_VMODE_YWRAP;
2854 break;
2855 case SCROLL_PAN_MOVE:
2856 case SCROLL_PAN_REDRAW:
2857 limit -= vc->vc_rows;
2858 info->var.vmode &= ~FB_VMODE_YWRAP;
2859 break;
2860 }
2861 if (offset < 0)
2862 offset += limit;
2863 else if (offset >= limit)
2864 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002865
2866 ops->var.xoffset = 0;
2867 ops->var.yoffset = offset * vc->vc_font.height;
2868 ops->update_start(info);
2869
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 if (!scrollback_current)
2871 fbcon_cursor(vc, CM_DRAW);
2872 return 0;
2873}
2874
2875static int fbcon_set_origin(struct vc_data *vc)
2876{
2877 if (softback_lines)
2878 fbcon_scrolldelta(vc, softback_lines);
2879 return 0;
2880}
2881
2882static void fbcon_suspended(struct fb_info *info)
2883{
2884 struct vc_data *vc = NULL;
2885 struct fbcon_ops *ops = info->fbcon_par;
2886
2887 if (!ops || ops->currcon < 0)
2888 return;
2889 vc = vc_cons[ops->currcon].d;
2890
2891 /* Clear cursor, restore saved data */
2892 fbcon_cursor(vc, CM_ERASE);
2893}
2894
2895static void fbcon_resumed(struct fb_info *info)
2896{
2897 struct vc_data *vc;
2898 struct fbcon_ops *ops = info->fbcon_par;
2899
2900 if (!ops || ops->currcon < 0)
2901 return;
2902 vc = vc_cons[ops->currcon].d;
2903
2904 update_screen(vc);
2905}
2906
2907static void fbcon_modechanged(struct fb_info *info)
2908{
2909 struct fbcon_ops *ops = info->fbcon_par;
2910 struct vc_data *vc;
2911 struct display *p;
2912 int rows, cols;
2913
2914 if (!ops || ops->currcon < 0)
2915 return;
2916 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002917 if (vc->vc_mode != KD_TEXT ||
2918 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 return;
2920
2921 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002922 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923
2924 if (CON_IS_VISIBLE(vc)) {
2925 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002926 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2927 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2928 cols /= vc->vc_font.width;
2929 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 vc_resize(vc, cols, rows);
2931 updatescrollmode(p, info, vc);
2932 scrollback_max = 0;
2933 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002934
2935 if (!fbcon_is_inactive(vc, info)) {
2936 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2937 ops->update_start(info);
2938 }
2939
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 fbcon_set_palette(vc, color_table);
2941 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002942 if (softback_buf)
2943 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 }
2945}
2946
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002947static void fbcon_set_all_vcs(struct fb_info *info)
2948{
2949 struct fbcon_ops *ops = info->fbcon_par;
2950 struct vc_data *vc;
2951 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002952 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002953
2954 if (!ops || ops->currcon < 0)
2955 return;
2956
Antonino A. Daplase614b182006-06-26 00:27:09 -07002957 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002958 vc = vc_cons[i].d;
2959 if (!vc || vc->vc_mode != KD_TEXT ||
2960 registered_fb[con2fb_map[i]] != info)
2961 continue;
2962
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002963 if (CON_IS_VISIBLE(vc)) {
2964 fg = i;
2965 continue;
2966 }
2967
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002968 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002969 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002970 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002971 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2972 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002973 cols /= vc->vc_font.width;
2974 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002975 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002976 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002977
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002978 if (fg != -1)
2979 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002980}
2981
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982static int fbcon_mode_deleted(struct fb_info *info,
2983 struct fb_videomode *mode)
2984{
2985 struct fb_info *fb_info;
2986 struct display *p;
2987 int i, j, found = 0;
2988
2989 /* before deletion, ensure that mode is not in use */
2990 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2991 j = con2fb_map[i];
2992 if (j == -1)
2993 continue;
2994 fb_info = registered_fb[j];
2995 if (fb_info != info)
2996 continue;
2997 p = &fb_display[i];
2998 if (!p || !p->mode)
2999 continue;
3000 if (fb_mode_is_equal(p->mode, mode)) {
3001 found = 1;
3002 break;
3003 }
3004 }
3005 return found;
3006}
3007
Jesse Barnescfafca82007-07-17 04:05:33 -07003008#ifdef CONFIG_VT_HW_CONSOLE_BINDING
3009static int fbcon_unbind(void)
3010{
3011 int ret;
3012
Takashi Iwaif515e1d2013-01-25 10:28:18 +10003013 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
Jesse Barnescfafca82007-07-17 04:05:33 -07003014 fbcon_is_default);
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003015
3016 if (!ret)
3017 fbcon_has_console_bind = 0;
3018
Jesse Barnescfafca82007-07-17 04:05:33 -07003019 return ret;
3020}
3021#else
3022static inline int fbcon_unbind(void)
3023{
3024 return -EINVAL;
3025}
3026#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3027
3028static int fbcon_fb_unbind(int idx)
3029{
3030 int i, new_idx = -1, ret = 0;
3031
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003032 if (!fbcon_has_console_bind)
3033 return 0;
3034
Jesse Barnescfafca82007-07-17 04:05:33 -07003035 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3036 if (con2fb_map[i] != idx &&
3037 con2fb_map[i] != -1) {
3038 new_idx = i;
3039 break;
3040 }
3041 }
3042
3043 if (new_idx != -1) {
3044 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3045 if (con2fb_map[i] == idx)
3046 set_con2fb_map(i, new_idx, 0);
3047 }
3048 } else
3049 ret = fbcon_unbind();
3050
3051 return ret;
3052}
3053
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003054static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003055{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003056 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003057
Andrea Righi66c1ca02009-03-31 15:25:18 -07003058 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003059 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3060 if (con2fb_map[i] == idx)
3061 con2fb_map[i] = -1;
3062 }
3063
3064 if (idx == info_idx) {
3065 info_idx = -1;
3066
3067 for (i = 0; i < FB_MAX; i++) {
3068 if (registered_fb[i] != NULL) {
3069 info_idx = i;
3070 break;
3071 }
3072 }
3073 }
3074
3075 if (info_idx != -1) {
3076 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3077 if (con2fb_map[i] == -1)
3078 con2fb_map[i] = info_idx;
3079 }
3080 }
3081
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003082 if (primary_device == idx)
3083 primary_device = -1;
3084
Andrea Righi66c1ca02009-03-31 15:25:18 -07003085 if (!num_registered_fb)
Takashi Iwaif515e1d2013-01-25 10:28:18 +10003086 do_unregister_con_driver(&fb_con);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003087
Antonino A. Daplase614b182006-06-26 00:27:09 -07003088 return 0;
3089}
3090
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003091static void fbcon_remap_all(int idx)
3092{
3093 int i;
3094 for (i = first_fb_vc; i <= last_fb_vc; i++)
3095 set_con2fb_map(i, idx, 0);
3096
3097 if (con_is_bound(&fb_con)) {
3098 printk(KERN_INFO "fbcon: Remapping primary device, "
3099 "fb%i, to tty %i-%i\n", idx,
3100 first_fb_vc + 1, last_fb_vc + 1);
3101 info_idx = idx;
3102 }
3103}
3104
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003105#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003106static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003108 if (!map_override && primary_device == -1 &&
3109 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003110 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003111
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003112 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3113 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003114 primary_device = info->node;
3115
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003116 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003117 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003118
3119 if (con_is_bound(&fb_con)) {
3120 printk(KERN_INFO "fbcon: Remapping primary device, "
3121 "fb%i, to tty %i-%i\n", info->node,
3122 first_fb_vc + 1, last_fb_vc + 1);
3123 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003124 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003125 }
3126
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003127}
3128#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003129static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003130{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003131 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003132}
3133#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3134
3135static int fbcon_fb_registered(struct fb_info *info)
3136{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003137 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003138
Andrea Righi66c1ca02009-03-31 15:25:18 -07003139 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003140 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141
3142 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003143 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 if (con2fb_map_boot[i] == idx) {
3145 info_idx = idx;
3146 break;
3147 }
3148 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003149
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 if (info_idx != -1)
Alan Coxc30b55c2013-01-25 10:28:15 +10003151 ret = do_fbcon_takeover(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003153 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003154 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 set_con2fb_map(i, idx, 0);
3156 }
3157 }
3158
3159 return ret;
3160}
3161
3162static void fbcon_fb_blanked(struct fb_info *info, int blank)
3163{
3164 struct fbcon_ops *ops = info->fbcon_par;
3165 struct vc_data *vc;
3166
3167 if (!ops || ops->currcon < 0)
3168 return;
3169
3170 vc = vc_cons[ops->currcon].d;
3171 if (vc->vc_mode != KD_TEXT ||
3172 registered_fb[con2fb_map[ops->currcon]] != info)
3173 return;
3174
3175 if (CON_IS_VISIBLE(vc)) {
3176 if (blank)
3177 do_blank_screen(0);
3178 else
3179 do_unblank_screen(0);
3180 }
3181 ops->blank_state = blank;
3182}
3183
3184static void fbcon_new_modelist(struct fb_info *info)
3185{
3186 int i;
3187 struct vc_data *vc;
3188 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003189 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
Antonino A. Daplase614b182006-06-26 00:27:09 -07003191 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 if (registered_fb[con2fb_map[i]] != info)
3193 continue;
3194 if (!fb_display[i].mode)
3195 continue;
3196 vc = vc_cons[i].d;
3197 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003198 mode = fb_find_nearest_mode(fb_display[i].mode,
3199 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003201 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 }
3203}
3204
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003205static void fbcon_get_requirement(struct fb_info *info,
3206 struct fb_blit_caps *caps)
3207{
3208 struct vc_data *vc;
3209 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003210
3211 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003212 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003213
3214 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3215 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003216 if (vc && vc->vc_mode == KD_TEXT &&
3217 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003218 p = &fb_display[i];
3219 caps->x |= 1 << (vc->vc_font.width - 1);
3220 caps->y |= 1 << (vc->vc_font.height - 1);
3221 charcnt = (p->userfont) ?
3222 FNTCHARCNT(p->fontdata) : 256;
3223 if (caps->len < charcnt)
3224 caps->len = charcnt;
3225 }
3226 }
3227 } else {
3228 vc = vc_cons[fg_console].d;
3229
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003230 if (vc && vc->vc_mode == KD_TEXT &&
3231 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003232 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003233 caps->x = 1 << (vc->vc_font.width - 1);
3234 caps->y = 1 << (vc->vc_font.height - 1);
3235 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003236 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003237 }
3238 }
3239}
3240
Andrea Righi66c1ca02009-03-31 15:25:18 -07003241static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 unsigned long action, void *data)
3243{
3244 struct fb_event *event = data;
3245 struct fb_info *info = event->info;
3246 struct fb_videomode *mode;
3247 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003248 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003249 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250
Antonino A. Daplase614b182006-06-26 00:27:09 -07003251 /*
3252 * ignore all events except driver registration and deregistration
3253 * if fbcon is not active
3254 */
3255 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3256 action == FB_EVENT_FB_UNREGISTERED))
3257 goto done;
3258
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 switch(action) {
3260 case FB_EVENT_SUSPEND:
3261 fbcon_suspended(info);
3262 break;
3263 case FB_EVENT_RESUME:
3264 fbcon_resumed(info);
3265 break;
3266 case FB_EVENT_MODE_CHANGE:
3267 fbcon_modechanged(info);
3268 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003269 case FB_EVENT_MODE_CHANGE_ALL:
3270 fbcon_set_all_vcs(info);
3271 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 case FB_EVENT_MODE_DELETE:
3273 mode = event->data;
3274 ret = fbcon_mode_deleted(info, mode);
3275 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003276 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003277 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003278 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003279 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003281 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003283 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003284 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003285 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 case FB_EVENT_SET_CONSOLE_MAP:
3287 con2fb = event->data;
3288 ret = set_con2fb_map(con2fb->console - 1,
3289 con2fb->framebuffer, 1);
3290 break;
3291 case FB_EVENT_GET_CONSOLE_MAP:
3292 con2fb = event->data;
3293 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3294 break;
3295 case FB_EVENT_BLANK:
3296 fbcon_fb_blanked(info, *(int *)event->data);
3297 break;
3298 case FB_EVENT_NEW_MODELIST:
3299 fbcon_new_modelist(info);
3300 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003301 case FB_EVENT_GET_REQ:
3302 caps = event->data;
3303 fbcon_get_requirement(info, caps);
3304 break;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003305 case FB_EVENT_REMAP_ALL_CONSOLE:
3306 idx = info->node;
3307 fbcon_remap_all(idx);
3308 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003310done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 return ret;
3312}
3313
3314/*
3315 * The console `switch' structure for the frame buffer based console
3316 */
3317
3318static const struct consw fb_con = {
3319 .owner = THIS_MODULE,
3320 .con_startup = fbcon_startup,
3321 .con_init = fbcon_init,
3322 .con_deinit = fbcon_deinit,
3323 .con_clear = fbcon_clear,
3324 .con_putc = fbcon_putc,
3325 .con_putcs = fbcon_putcs,
3326 .con_cursor = fbcon_cursor,
3327 .con_scroll = fbcon_scroll,
3328 .con_bmove = fbcon_bmove,
3329 .con_switch = fbcon_switch,
3330 .con_blank = fbcon_blank,
3331 .con_font_set = fbcon_set_font,
3332 .con_font_get = fbcon_get_font,
3333 .con_font_default = fbcon_set_def_font,
3334 .con_font_copy = fbcon_copy_font,
3335 .con_set_palette = fbcon_set_palette,
3336 .con_scrolldelta = fbcon_scrolldelta,
3337 .con_set_origin = fbcon_set_origin,
3338 .con_invert_region = fbcon_invert_region,
3339 .con_screen_pos = fbcon_screen_pos,
3340 .con_getxy = fbcon_getxy,
3341 .con_resize = fbcon_resize,
Jesse Barnesd219adc2010-08-02 12:05:41 -07003342 .con_debug_enter = fbcon_debug_enter,
3343 .con_debug_leave = fbcon_debug_leave,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344};
3345
3346static struct notifier_block fbcon_event_notifier = {
3347 .notifier_call = fbcon_event_notify,
3348};
3349
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003350static ssize_t store_rotate(struct device *device,
3351 struct device_attribute *attr, const char *buf,
3352 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003353{
3354 struct fb_info *info;
3355 int rotate, idx;
3356 char **last = NULL;
3357
Antonino A. Daplase614b182006-06-26 00:27:09 -07003358 if (fbcon_has_exited)
3359 return count;
3360
Torben Hohnac751ef2011-01-25 15:07:35 -08003361 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003362 idx = con2fb_map[fg_console];
3363
3364 if (idx == -1 || registered_fb[idx] == NULL)
3365 goto err;
3366
3367 info = registered_fb[idx];
3368 rotate = simple_strtoul(buf, last, 0);
3369 fbcon_rotate(info, rotate);
3370err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003371 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003372 return count;
3373}
3374
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003375static ssize_t store_rotate_all(struct device *device,
3376 struct device_attribute *attr,const char *buf,
3377 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003378{
3379 struct fb_info *info;
3380 int rotate, idx;
3381 char **last = NULL;
3382
Antonino A. Daplase614b182006-06-26 00:27:09 -07003383 if (fbcon_has_exited)
3384 return count;
3385
Torben Hohnac751ef2011-01-25 15:07:35 -08003386 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003387 idx = con2fb_map[fg_console];
3388
3389 if (idx == -1 || registered_fb[idx] == NULL)
3390 goto err;
3391
3392 info = registered_fb[idx];
3393 rotate = simple_strtoul(buf, last, 0);
3394 fbcon_rotate_all(info, rotate);
3395err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003396 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003397 return count;
3398}
3399
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003400static ssize_t show_rotate(struct device *device,
3401 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003402{
3403 struct fb_info *info;
3404 int rotate = 0, idx;
3405
Antonino A. Daplase614b182006-06-26 00:27:09 -07003406 if (fbcon_has_exited)
3407 return 0;
3408
Torben Hohnac751ef2011-01-25 15:07:35 -08003409 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003410 idx = con2fb_map[fg_console];
3411
3412 if (idx == -1 || registered_fb[idx] == NULL)
3413 goto err;
3414
3415 info = registered_fb[idx];
3416 rotate = fbcon_get_rotate(info);
3417err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003418 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003419 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3420}
3421
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003422static ssize_t show_cursor_blink(struct device *device,
3423 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003424{
3425 struct fb_info *info;
3426 struct fbcon_ops *ops;
3427 int idx, blink = -1;
3428
3429 if (fbcon_has_exited)
3430 return 0;
3431
Torben Hohnac751ef2011-01-25 15:07:35 -08003432 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003433 idx = con2fb_map[fg_console];
3434
3435 if (idx == -1 || registered_fb[idx] == NULL)
3436 goto err;
3437
3438 info = registered_fb[idx];
3439 ops = info->fbcon_par;
3440
3441 if (!ops)
3442 goto err;
3443
3444 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3445err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003446 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003447 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3448}
3449
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003450static ssize_t store_cursor_blink(struct device *device,
3451 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003452 const char *buf, size_t count)
3453{
3454 struct fb_info *info;
3455 int blink, idx;
3456 char **last = NULL;
3457
3458 if (fbcon_has_exited)
3459 return count;
3460
Torben Hohnac751ef2011-01-25 15:07:35 -08003461 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003462 idx = con2fb_map[fg_console];
3463
3464 if (idx == -1 || registered_fb[idx] == NULL)
3465 goto err;
3466
3467 info = registered_fb[idx];
3468
3469 if (!info->fbcon_par)
3470 goto err;
3471
3472 blink = simple_strtoul(buf, last, 0);
3473
3474 if (blink) {
3475 fbcon_cursor_noblink = 0;
3476 fbcon_add_cursor_timer(info);
3477 } else {
3478 fbcon_cursor_noblink = 1;
3479 fbcon_del_cursor_timer(info);
3480 }
3481
3482err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003483 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003484 return count;
3485}
3486
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003487static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003488 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3489 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003490 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3491 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003492};
3493
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003494static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003495{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003496 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003497
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003498 fbcon_has_sysfs = 1;
3499
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003500 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3501 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003502
3503 if (error)
3504 break;
3505 }
3506
3507 if (error) {
3508 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003509 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003510
3511 fbcon_has_sysfs = 0;
3512 }
3513
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003514 return 0;
3515}
3516
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003517static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003520 int i;
3521
Torben Hohnac751ef2011-01-25 15:07:35 -08003522 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003523
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 for (i = 0; i < FB_MAX; i++) {
3525 if (registered_fb[i] != NULL) {
3526 info_idx = i;
3527 break;
3528 }
3529 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003530
Torben Hohnac751ef2011-01-25 15:07:35 -08003531 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 fbcon_takeover(0);
3533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534}
3535
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003536static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003537{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003538 struct fb_info *info;
3539 int i, j, mapped;
3540
Antonino A. Daplase614b182006-06-26 00:27:09 -07003541 if (fbcon_has_exited)
3542 return;
3543
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003544 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003545 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003546
3547 for (i = 0; i < FB_MAX; i++) {
Jarek Poplawski142092e2010-09-22 13:05:05 -07003548 int pending = 0;
Geoff Levandbeaa4862008-12-09 13:14:17 -08003549
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003550 mapped = 0;
3551 info = registered_fb[i];
3552
3553 if (info == NULL)
3554 continue;
3555
Jarek Poplawski142092e2010-09-22 13:05:05 -07003556 if (info->queue.func)
3557 pending = cancel_work_sync(&info->queue);
Geoff Levandbeaa4862008-12-09 13:14:17 -08003558 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3559 "no"));
3560
Antonino A. Daplase614b182006-06-26 00:27:09 -07003561 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3562 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003563 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003564 }
3565
3566 if (mapped) {
3567 if (info->fbops->fb_release)
3568 info->fbops->fb_release(info, 0);
3569 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003570
3571 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003572 struct fbcon_ops *ops = info->fbcon_par;
3573
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003574 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003575 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003576 kfree(info->fbcon_par);
3577 info->fbcon_par = NULL;
3578 }
3579
3580 if (info->queue.func == fb_flashcursor)
3581 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003582 }
3583 }
3584
Antonino A. Daplase614b182006-06-26 00:27:09 -07003585 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003586}
3587
3588static int __init fb_console_init(void)
3589{
3590 int i;
3591
Torben Hohnac751ef2011-01-25 15:07:35 -08003592 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003593 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003594 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3595 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003596
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003597 if (IS_ERR(fbcon_device)) {
3598 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003599 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003600 PTR_ERR(fbcon_device));
3601 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003602 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003603 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003604
3605 for (i = 0; i < MAX_NR_CONSOLES; i++)
3606 con2fb_map[i] = -1;
3607
Torben Hohnac751ef2011-01-25 15:07:35 -08003608 console_unlock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003609 fbcon_start();
3610 return 0;
3611}
3612
3613module_init(fb_console_init);
3614
3615#ifdef MODULE
3616
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003617static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003618{
3619 int i;
3620
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003621 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003622 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3623 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003624
3625 fbcon_has_sysfs = 0;
3626 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003627}
3628
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629static void __exit fb_console_exit(void)
3630{
Torben Hohnac751ef2011-01-25 15:07:35 -08003631 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003633 fbcon_deinit_device();
3634 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003635 fbcon_exit();
Torben Hohnac751ef2011-01-25 15:07:35 -08003636 console_unlock();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003637 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003638}
3639
3640module_exit(fb_console_exit);
3641
3642#endif
3643
3644MODULE_LICENSE("GPL");