blob: 6e92917ba77a97477f32a0426ee914c351867a6b [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
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700149static int fbcon_cursor_noblink;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
152
153/*
154 * Interface used by the world
155 */
156
157static const char *fbcon_startup(void);
158static void fbcon_init(struct vc_data *vc, int init);
159static void fbcon_deinit(struct vc_data *vc);
160static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
161 int width);
162static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
163static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
164 int count, int ypos, int xpos);
165static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
166static void fbcon_cursor(struct vc_data *vc, int mode);
167static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
168 int count);
169static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
170 int height, int width);
171static int fbcon_switch(struct vc_data *vc);
172static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
173static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
174static int fbcon_scrolldelta(struct vc_data *vc, int lines);
175
176/*
177 * Internal routines
178 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179static __inline__ void ywrap_up(struct vc_data *vc, int count);
180static __inline__ void ywrap_down(struct vc_data *vc, int count);
181static __inline__ void ypan_up(struct vc_data *vc, int count);
182static __inline__ void ypan_down(struct vc_data *vc, int count);
183static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
184 int dy, int dx, int height, int width, u_int y_break);
185static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700186 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
188 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800189static void fbcon_modechanged(struct fb_info *info);
190static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700191static void fbcon_start(void);
192static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700193static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700194
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800195#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800196static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800197{
198 struct fbcon_ops *ops = info->fbcon_par;
199
200 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800201 ops->p->con_rotate < 4)
202 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800203 else
204 ops->rotate = 0;
205}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800206
207static void fbcon_rotate(struct fb_info *info, u32 rotate)
208{
209 struct fbcon_ops *ops= info->fbcon_par;
210 struct fb_info *fb_info;
211
212 if (!ops || ops->currcon == -1)
213 return;
214
215 fb_info = registered_fb[con2fb_map[ops->currcon]];
216
217 if (info == fb_info) {
218 struct display *p = &fb_display[ops->currcon];
219
220 if (rotate < 4)
221 p->con_rotate = rotate;
222 else
223 p->con_rotate = 0;
224
225 fbcon_modechanged(info);
226 }
227}
228
229static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
230{
231 struct fbcon_ops *ops = info->fbcon_par;
232 struct vc_data *vc;
233 struct display *p;
234 int i;
235
236 if (!ops || ops->currcon < 0 || rotate > 3)
237 return;
238
Antonino A. Daplase614b182006-06-26 00:27:09 -0700239 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800240 vc = vc_cons[i].d;
241 if (!vc || vc->vc_mode != KD_TEXT ||
242 registered_fb[con2fb_map[i]] != info)
243 continue;
244
245 p = &fb_display[vc->vc_num];
246 p->con_rotate = rotate;
247 }
248
249 fbcon_set_all_vcs(info);
250}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800251#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800252static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800253{
254 struct fbcon_ops *ops = info->fbcon_par;
255
256 ops->rotate = FB_ROTATE_UR;
257}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800258
259static void fbcon_rotate(struct fb_info *info, u32 rotate)
260{
261 return;
262}
263
264static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
265{
266 return;
267}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800268#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800269
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800270static int fbcon_get_rotate(struct fb_info *info)
271{
272 struct fbcon_ops *ops = info->fbcon_par;
273
274 return (ops) ? ops->rotate : 0;
275}
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
278{
279 struct fbcon_ops *ops = info->fbcon_par;
280
281 return (info->state != FBINFO_STATE_RUNNING ||
Jesse Barnes8fd4bd22010-06-23 12:56:12 -0700282 vc->vc_mode != KD_TEXT || ops->graphics) &&
283 !vt_force_oops_output(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
Denys Vlasenkoda909ce2010-08-10 18:02:29 -0700286static int get_color(struct vc_data *vc, struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 u16 c, int is_fg)
288{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700289 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 int color = 0;
291
292 if (console_blanked) {
293 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
294
295 c = vc->vc_video_erase_char & charmask;
296 }
297
298 if (depth != 1)
299 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
300 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
301
302 switch (depth) {
303 case 1:
304 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800305 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700307 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
308 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 if (console_blanked)
311 fg = bg;
312
313 color = (is_fg) ? fg : bg;
314 break;
315 }
316 case 2:
317 /*
318 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700319 * is grayscale. However, simply dividing the values by 4
320 * will not work, as colors 1, 2 and 3 will be scaled-down
321 * to zero rendering them invisible. So empirically convert
322 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700324 switch (color) {
325 case 0:
326 color = 0; /* black */
327 break;
328 case 1 ... 6:
329 color = 2; /* white */
330 break;
331 case 7 ... 8:
332 color = 1; /* gray */
333 break;
334 default:
335 color = 3; /* intense white */
336 break;
337 }
338 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 case 3:
340 /*
341 * Last 8 entries of default 16-color palette is a more intense
342 * version of the first 8 (i.e., same chrominance, different
343 * luminance).
344 */
345 color &= 7;
346 break;
347 }
348
349
350 return color;
351}
352
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800353static void fbcon_update_softback(struct vc_data *vc)
354{
355 int l = fbcon_softback_size / vc->vc_size_row;
356
357 if (l > 5)
358 softback_end = softback_buf + l * vc->vc_size_row;
359 else
360 /* Smaller scrollback makes no sense, and 0 would screw
361 the operation totally */
362 softback_top = 0;
363}
364
David Howellsc4028952006-11-22 14:57:56 +0000365static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
David Howellsc4028952006-11-22 14:57:56 +0000367 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 struct vc_data *vc = NULL;
370 int c;
371 int mode;
Dave Airlied8636a22012-08-21 16:29:47 +1000372 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Dave Airlied8636a22012-08-21 16:29:47 +1000374 /* FIXME: we should sort out the unbind locking instead */
375 /* instead we just fail to flash the cursor if we can't get
376 * the lock instead of blocking fbcon deinit */
377 ret = console_trylock();
378 if (ret == 0)
379 return;
380
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700381 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 vc = vc_cons[ops->currcon].d;
383
384 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700385 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700386 vc->vc_deccm != 1) {
Torben Hohnac751ef2011-01-25 15:07:35 -0800387 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700389 }
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 c = scr_readw((u16 *) vc->vc_pos);
392 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
393 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800394 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 get_color(vc, info, c, 0));
Torben Hohnac751ef2011-01-25 15:07:35 -0800396 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399static void cursor_timer_handler(unsigned long dev_addr)
400{
401 struct fb_info *info = (struct fb_info *) dev_addr;
402 struct fbcon_ops *ops = info->fbcon_par;
403
Viresh Kumara85f1a42013-04-24 17:12:57 +0530404 queue_work(system_power_efficient_wq, &info->queue);
Scot Doyle27a4c822015-03-26 13:56:38 +0000405 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
407
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700408static void fbcon_add_cursor_timer(struct fb_info *info)
409{
410 struct fbcon_ops *ops = info->fbcon_par;
411
412 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700413 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
414 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700415 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000416 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700417
418 init_timer(&ops->cursor_timer);
419 ops->cursor_timer.function = cursor_timer_handler;
Scot Doyle27a4c822015-03-26 13:56:38 +0000420 ops->cursor_timer.expires = jiffies + ops->cur_blink_jiffies;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700421 ops->cursor_timer.data = (unsigned long ) info;
422 add_timer(&ops->cursor_timer);
423 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
424 }
425}
426
427static void fbcon_del_cursor_timer(struct fb_info *info)
428{
429 struct fbcon_ops *ops = info->fbcon_par;
430
431 if (info->queue.func == fb_flashcursor &&
432 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
433 del_timer_sync(&ops->cursor_timer);
434 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
435 }
436}
437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#ifndef MODULE
439static int __init fb_console_setup(char *this_opt)
440{
441 char *options;
442 int i, j;
443
444 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800445 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 while ((options = strsep(&this_opt, ",")) != NULL) {
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200448 if (!strncmp(options, "font:", 5)) {
Paul Cercueile4329642012-07-24 03:00:24 +0200449 strlcpy(fontname, options + 5, sizeof(fontname));
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200450 continue;
451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 if (!strncmp(options, "scrollback:", 11)) {
454 options += 11;
455 if (*options) {
456 fbcon_softback_size = simple_strtoul(options, &options, 0);
457 if (*options == 'k' || *options == 'K') {
458 fbcon_softback_size *= 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200460 }
461 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463
464 if (!strncmp(options, "map:", 4)) {
465 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700466 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
468 if (!options[j])
469 j = 0;
470 con2fb_map_boot[i] =
471 (options[j++]-'0') % FB_MAX;
472 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700473
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700474 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700475 }
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200476 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478
479 if (!strncmp(options, "vc:", 3)) {
480 options += 3;
481 if (*options)
482 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
483 if (first_fb_vc < 0)
484 first_fb_vc = 0;
485 if (*options++ == '-')
486 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
487 fbcon_is_default = 0;
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200488 continue;
489 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800490
491 if (!strncmp(options, "rotate:", 7)) {
492 options += 7;
493 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800494 initial_rotation = simple_strtoul(options, &options, 0);
495 if (initial_rotation > 3)
496 initial_rotation = 0;
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200497 continue;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800500 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
503__setup("fbcon=", fb_console_setup);
504#endif
505
506static int search_fb_in_map(int idx)
507{
508 int i, retval = 0;
509
Antonino A. Daplase614b182006-06-26 00:27:09 -0700510 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (con2fb_map[i] == idx)
512 retval = 1;
513 }
514 return retval;
515}
516
517static int search_for_mapped_con(void)
518{
519 int i, retval = 0;
520
Antonino A. Daplase614b182006-06-26 00:27:09 -0700521 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (con2fb_map[i] != -1)
523 retval = 1;
524 }
525 return retval;
526}
527
Alan Cox50e244c2013-01-25 10:28:15 +1000528static int do_fbcon_takeover(int show_logo)
529{
530 int err, i;
531
532 if (!num_registered_fb)
533 return -ENODEV;
534
535 if (!show_logo)
536 logo_shown = FBCON_LOGO_DONTSHOW;
537
538 for (i = first_fb_vc; i <= last_fb_vc; i++)
539 con2fb_map[i] = info_idx;
540
541 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
542 fbcon_is_default);
543
544 if (err) {
545 for (i = first_fb_vc; i <= last_fb_vc; i++)
546 con2fb_map[i] = -1;
547 info_idx = -1;
548 } else {
549 fbcon_has_console_bind = 1;
550 }
551
552 return err;
553}
554
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700555#ifdef MODULE
556static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
557 int cols, int rows, int new_cols, int new_rows)
558{
559 logo_shown = FBCON_LOGO_DONTSHOW;
560}
561#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
563 int cols, int rows, int new_cols, int new_rows)
564{
565 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800566 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 int cnt, erase = vc->vc_video_erase_char, step;
568 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700569 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700571 if (info->flags & FBINFO_MODULE) {
572 logo_shown = FBCON_LOGO_DONTSHOW;
573 return;
574 }
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 /*
577 * remove underline attribute from erase character
578 * if black and white framebuffer.
579 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700580 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800582 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700583 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 q = (unsigned short *) (vc->vc_origin +
585 vc->vc_size_row * rows);
586 step = logo_lines * cols;
587 for (r = q - logo_lines * cols; r < q; r++)
588 if (scr_readw(r) != vc->vc_video_erase_char)
589 break;
590 if (r != q && new_rows >= rows + logo_lines) {
591 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
592 if (save) {
593 int i = cols < new_cols ? cols : new_cols;
594 scr_memsetw(save, erase, logo_lines * new_cols * 2);
595 r = q - step;
596 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
597 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
598 r = q;
599 }
600 }
601 if (r == q) {
602 /* We can scroll screen down */
603 r = q - step - cols;
604 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
605 scr_memcpyw(r + step, r, vc->vc_size_row);
606 r -= cols;
607 }
608 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700609 int lines;
610 if (vc->vc_y + logo_lines >= rows)
611 lines = rows - vc->vc_y - 1;
612 else
613 lines = logo_lines;
614 vc->vc_y += lines;
615 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 }
617 }
618 scr_memsetw((unsigned short *) vc->vc_origin,
619 erase,
620 vc->vc_size_row * logo_lines);
621
622 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
623 fbcon_clear_margins(vc, 0);
624 update_screen(vc);
625 }
626
627 if (save) {
628 q = (unsigned short *) (vc->vc_origin +
629 vc->vc_size_row *
630 rows);
631 scr_memcpyw(q, save, logo_lines * new_cols * 2);
632 vc->vc_y += logo_lines;
633 vc->vc_pos += logo_lines * vc->vc_size_row;
634 kfree(save);
635 }
636
637 if (logo_lines > vc->vc_bottom) {
638 logo_shown = FBCON_LOGO_CANSHOW;
639 printk(KERN_INFO
640 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
641 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
642 logo_shown = FBCON_LOGO_DRAW;
643 vc->vc_top = logo_lines;
644 }
645}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700646#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800649static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 struct fbcon_ops *ops = info->fbcon_par;
652
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800653 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800654
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800656 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800657 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800658 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800660 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700662
663static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
664{
665 int err = 0;
666
667 if (info->flags & FBINFO_MISC_TILEBLITTING &&
668 info->tileops->fb_get_tilemax(info) < charcount)
669 err = 1;
670
671 return err;
672}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800674static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
676 struct fbcon_ops *ops = info->fbcon_par;
677
678 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800679 ops->p = &fb_display[vc->vc_num];
680 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 fbcon_set_bitops(ops);
682}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700683
684static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
685{
686 return 0;
687}
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#endif /* CONFIG_MISC_TILEBLITTING */
690
691
692static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
693 int unit, int oldidx)
694{
695 struct fbcon_ops *ops = NULL;
696 int err = 0;
697
698 if (!try_module_get(info->fbops->owner))
699 err = -ENODEV;
700
701 if (!err && info->fbops->fb_open &&
702 info->fbops->fb_open(info, 0))
703 err = -ENODEV;
704
705 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800706 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if (!ops)
708 err = -ENOMEM;
709 }
710
711 if (!err) {
Jean-Philippe Bruckera1e533e2016-02-15 18:41:33 +0000712 ops->cur_blink_jiffies = HZ / 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700714
715 if (vc)
716 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
719 if (err) {
720 con2fb_map[unit] = oldidx;
721 module_put(info->fbops->owner);
722 }
723
724 return err;
725}
726
727static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
728 struct fb_info *newinfo, int unit,
729 int oldidx, int found)
730{
731 struct fbcon_ops *ops = oldinfo->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700732 int err = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 if (oldinfo->fbops->fb_release &&
735 oldinfo->fbops->fb_release(oldinfo, 0)) {
736 con2fb_map[unit] = oldidx;
737 if (!found && newinfo->fbops->fb_release)
738 newinfo->fbops->fb_release(newinfo, 0);
739 if (!found)
740 module_put(newinfo->fbops->owner);
741 err = -ENODEV;
742 }
743
744 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700745 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 kfree(ops->cursor_state.mask);
747 kfree(ops->cursor_data);
Masami Ichikawa7a966fb2014-04-23 23:35:22 +0900748 kfree(ops->cursor_src);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800749 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 kfree(oldinfo->fbcon_par);
751 oldinfo->fbcon_par = NULL;
752 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800753 /*
754 If oldinfo and newinfo are driving the same hardware,
755 the fb_release() method of oldinfo may attempt to
756 restore the hardware state. This will leave the
757 newinfo in an undefined state. Thus, a call to
758 fb_set_par() may be needed for the newinfo.
759 */
Keith Packard5f4dc282014-01-20 13:31:10 -0800760 if (newinfo && newinfo->fbops->fb_set_par) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700761 ret = newinfo->fbops->fb_set_par(newinfo);
762
763 if (ret)
764 printk(KERN_ERR "con2fb_release_oldinfo: "
765 "detected unhandled fb_set_par error, "
766 "error code %d\n", ret);
767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 }
769
770 return err;
771}
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
774 int unit, int show_logo)
775{
776 struct fbcon_ops *ops = info->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700777 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 ops->currcon = fg_console;
780
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700781 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
782 ret = info->fbops->fb_set_par(info);
783
784 if (ret)
785 printk(KERN_ERR "con2fb_init_display: detected "
786 "unhandled fb_set_par error, "
787 "error code %d\n", ret);
788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 ops->flags |= FBCON_FLAGS_INIT;
791 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700792 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (show_logo) {
795 struct vc_data *fg_vc = vc_cons[fg_console].d;
796 struct fb_info *fg_info =
797 registered_fb[con2fb_map[fg_console]];
798
799 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
800 fg_vc->vc_rows, fg_vc->vc_cols,
801 fg_vc->vc_rows);
802 }
803
804 update_screen(vc_cons[fg_console].d);
805}
806
807/**
808 * set_con2fb_map - map console to frame buffer device
809 * @unit: virtual console number to map
810 * @newidx: frame buffer index to map virtual console to
811 * @user: user request
812 *
813 * Maps a virtual console @unit to a frame buffer device
814 * @newidx.
Dave Airlie054430e2013-01-25 11:38:56 +1000815 *
816 * This should be called with the console lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 */
818static int set_con2fb_map(int unit, int newidx, int user)
819{
820 struct vc_data *vc = vc_cons[unit].d;
821 int oldidx = con2fb_map[unit];
822 struct fb_info *info = registered_fb[newidx];
823 struct fb_info *oldinfo = NULL;
824 int found, err = 0;
825
826 if (oldidx == newidx)
827 return 0;
828
Dave Airlie32b98bf2010-12-21 01:41:17 +0000829 if (!info)
Antonino A. Daplase614b182006-06-26 00:27:09 -0700830 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Dave Airlie32b98bf2010-12-21 01:41:17 +0000832 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 info_idx = newidx;
Dave Airlie054430e2013-01-25 11:38:56 +1000834 return do_fbcon_takeover(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 }
836
837 if (oldidx != -1)
838 oldinfo = registered_fb[oldidx];
839
840 found = search_fb_in_map(newidx);
841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 con2fb_map[unit] = newidx;
843 if (!err && !found)
844 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
845
846
847 /*
848 * If old fb is not mapped to any of the consoles,
849 * fbcon should release it.
850 */
851 if (!err && oldinfo && !search_fb_in_map(oldidx))
852 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
853 found);
854
855 if (!err) {
856 int show_logo = (fg_console == 0 && !user &&
857 logo_shown != FBCON_LOGO_DONTSHOW);
858
859 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700860 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 con2fb_map_boot[unit] = newidx;
862 con2fb_init_display(vc, info, unit, show_logo);
863 }
864
Antonino A. Daplase614b182006-06-26 00:27:09 -0700865 if (!search_fb_in_map(info_idx))
866 info_idx = newidx;
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 return err;
869}
870
871/*
872 * Low Level Operations
873 */
Wang YanQing155957f2013-05-21 13:15:12 +0800874/* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875static int var_to_display(struct display *disp,
876 struct fb_var_screeninfo *var,
877 struct fb_info *info)
878{
879 disp->xres_virtual = var->xres_virtual;
880 disp->yres_virtual = var->yres_virtual;
881 disp->bits_per_pixel = var->bits_per_pixel;
882 disp->grayscale = var->grayscale;
883 disp->nonstd = var->nonstd;
884 disp->accel_flags = var->accel_flags;
885 disp->height = var->height;
886 disp->width = var->width;
887 disp->red = var->red;
888 disp->green = var->green;
889 disp->blue = var->blue;
890 disp->transp = var->transp;
891 disp->rotate = var->rotate;
892 disp->mode = fb_match_mode(var, &info->modelist);
893 if (disp->mode == NULL)
894 /* This should not happen */
895 return -EINVAL;
896 return 0;
897}
898
899static void display_to_var(struct fb_var_screeninfo *var,
900 struct display *disp)
901{
902 fb_videomode_to_var(var, disp->mode);
903 var->xres_virtual = disp->xres_virtual;
904 var->yres_virtual = disp->yres_virtual;
905 var->bits_per_pixel = disp->bits_per_pixel;
906 var->grayscale = disp->grayscale;
907 var->nonstd = disp->nonstd;
908 var->accel_flags = disp->accel_flags;
909 var->height = disp->height;
910 var->width = disp->width;
911 var->red = disp->red;
912 var->green = disp->green;
913 var->blue = disp->blue;
914 var->transp = disp->transp;
915 var->rotate = disp->rotate;
916}
917
918static const char *fbcon_startup(void)
919{
920 const char *display_desc = "frame buffer device";
921 struct display *p = &fb_display[fg_console];
922 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700923 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 struct module *owner;
925 struct fb_info *info = NULL;
926 struct fbcon_ops *ops;
927 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 /*
930 * If num_registered_fb is zero, this is a call for the dummy part.
931 * The frame buffer devices weren't initialized yet.
932 */
933 if (!num_registered_fb || info_idx == -1)
934 return display_desc;
935 /*
936 * Instead of blindly using registered_fb[0], we use info_idx, set by
937 * fb_console_init();
938 */
939 info = registered_fb[info_idx];
940 if (!info)
941 return NULL;
942
943 owner = info->fbops->owner;
944 if (!try_module_get(owner))
945 return NULL;
946 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
947 module_put(owner);
948 return NULL;
949 }
950
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800951 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 if (!ops) {
953 module_put(owner);
954 return NULL;
955 }
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 ops->currcon = -1;
958 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800959 ops->cur_rotate = -1;
Jean-Philippe Bruckera1e533e2016-02-15 18:41:33 +0000960 ops->cur_blink_jiffies = HZ / 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800962 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800963 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 if (info->fix.type != FB_TYPE_TEXT) {
966 if (fbcon_softback_size) {
967 if (!softback_buf) {
968 softback_buf =
969 (unsigned long)
970 kmalloc(fbcon_softback_size,
971 GFP_KERNEL);
972 if (!softback_buf) {
973 fbcon_softback_size = 0;
974 softback_top = 0;
975 }
976 }
977 } else {
978 if (softback_buf) {
979 kfree((void *) softback_buf);
980 softback_buf = 0;
981 softback_top = 0;
982 }
983 }
984 if (softback_buf)
985 softback_in = softback_top = softback_curr =
986 softback_buf;
987 softback_lines = 0;
988 }
989
990 /* Setup default font */
Dave Airlieae128782013-01-24 16:12:41 +1000991 if (!p->fontdata && !vc->vc_font.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 if (!fontname[0] || !(font = find_font(fontname)))
993 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700994 info->var.yres,
995 info->pixmap.blit_x,
996 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 vc->vc_font.width = font->width;
998 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700999 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
Dave Airlieae128782013-01-24 16:12:41 +10001001 } else {
1002 p->fontdata = vc->vc_font.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
1004
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001005 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1006 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1007 cols /= vc->vc_font.width;
1008 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 vc_resize(vc, cols, rows);
1010
1011 DPRINTK("mode: %s\n", info->fix.id);
1012 DPRINTK("visual: %d\n", info->fix.visual);
1013 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1014 info->var.yres,
1015 info->var.bits_per_pixel);
1016
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001017 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001018 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 return display_desc;
1020}
1021
1022static void fbcon_init(struct vc_data *vc, int init)
1023{
1024 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1025 struct fbcon_ops *ops;
1026 struct vc_data **default_mode = vc->vc_display_fg;
1027 struct vc_data *svc = *default_mode;
1028 struct display *t, *p = &fb_display[vc->vc_num];
1029 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001030 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032 if (info_idx == -1 || info == NULL)
1033 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001034
1035 cap = info->flags;
1036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1038 (info->fix.type == FB_TYPE_TEXT))
1039 logo = 0;
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (var_to_display(p, &info->var, info))
1042 return;
1043
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001044 if (!info->fbcon_par)
1045 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 /* If we are not the first console on this
1048 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001049 t = &fb_display[fg_console];
1050 if (!p->fontdata) {
1051 if (t->fontdata) {
1052 struct vc_data *fvc = vc_cons[fg_console].d;
1053
1054 vc->vc_font.data = (void *)(p->fontdata =
1055 fvc->vc_font.data);
1056 vc->vc_font.width = fvc->vc_font.width;
1057 vc->vc_font.height = fvc->vc_font.height;
1058 p->userfont = t->userfont;
1059
1060 if (p->userfont)
1061 REFCOUNT(p->fontdata)++;
1062 } else {
1063 const struct font_desc *font = NULL;
1064
1065 if (!fontname[0] || !(font = find_font(fontname)))
1066 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001067 info->var.yres,
1068 info->pixmap.blit_x,
1069 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001070 vc->vc_font.width = font->width;
1071 vc->vc_font.height = font->height;
1072 vc->vc_font.data = (void *)(p->fontdata = font->data);
1073 vc->vc_font.charcount = 256; /* FIXME Need to
1074 support more fonts */
1075 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (p->userfont)
1079 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001080
Jesse Barnes8fd4bd22010-06-23 12:56:12 -07001081 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001082 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1084 if (charcnt == 256) {
1085 vc->vc_hi_font_mask = 0;
1086 } else {
1087 vc->vc_hi_font_mask = 0x100;
1088 if (vc->vc_can_do_color)
1089 vc->vc_complement_mask <<= 1;
1090 }
1091
1092 if (!*svc->vc_uni_pagedir_loc)
1093 con_set_default_unimap(svc);
1094 if (!*vc->vc_uni_pagedir_loc)
1095 con_copy_unimap(vc, svc);
1096
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001097 ops = info->fbcon_par;
Scot Doylef235f662015-10-09 15:08:10 +00001098 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
Marcin Slusarz2428e592008-02-06 01:39:14 -08001099 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001100 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 cols = vc->vc_cols;
1103 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001104 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1105 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1106 new_cols /= vc->vc_font.width;
1107 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 /*
1110 * We must always set the mode. The mode of the previous console
1111 * driver could be in the same resolution but we are using different
1112 * hardware so we have to initialize the hardware.
1113 *
1114 * We need to do it in fbcon_init() to prevent screen corruption.
1115 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001116 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001118 !(ops->flags & FBCON_FLAGS_INIT)) {
1119 ret = info->fbops->fb_set_par(info);
1120
1121 if (ret)
1122 printk(KERN_ERR "fbcon_init: detected "
1123 "unhandled fb_set_par error, "
1124 "error code %d\n", ret);
1125 }
1126
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 ops->flags |= FBCON_FLAGS_INIT;
1128 }
1129
1130 ops->graphics = 0;
1131
1132 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1133 !(cap & FBINFO_HWACCEL_DISABLED))
1134 p->scrollmode = SCROLL_MOVE;
1135 else /* default to something safe */
1136 p->scrollmode = SCROLL_REDRAW;
1137
1138 /*
1139 * ++guenther: console.c:vc_allocate() relies on initializing
1140 * vc_{cols,rows}, but we must not set those if we are only
1141 * resizing the console.
1142 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001143 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 vc->vc_cols = new_cols;
1145 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001146 } else
1147 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 if (logo)
1150 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1151
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001152 if (vc == svc && softback_buf)
1153 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001154
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001155 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001156 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001157 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001158 }
1159
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001160 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161}
1162
Dave Airlieae128782013-01-24 16:12:41 +10001163static void fbcon_free_font(struct display *p, bool freefont)
Antonino A. Daplase614b182006-06-26 00:27:09 -07001164{
Dave Airlieae128782013-01-24 16:12:41 +10001165 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001166 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1167 p->fontdata = NULL;
1168 p->userfont = 0;
1169}
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171static void fbcon_deinit(struct vc_data *vc)
1172{
1173 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001174 struct fb_info *info;
1175 struct fbcon_ops *ops;
1176 int idx;
Dave Airlieae128782013-01-24 16:12:41 +10001177 bool free_font = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Antonino A. Daplase614b182006-06-26 00:27:09 -07001179 idx = con2fb_map[vc->vc_num];
1180
1181 if (idx == -1)
1182 goto finished;
1183
1184 info = registered_fb[idx];
1185
1186 if (!info)
1187 goto finished;
1188
Dave Airlieae128782013-01-24 16:12:41 +10001189 if (info->flags & FBINFO_MISC_FIRMWARE)
1190 free_font = false;
Antonino A. Daplase614b182006-06-26 00:27:09 -07001191 ops = info->fbcon_par;
1192
1193 if (!ops)
1194 goto finished;
1195
1196 if (CON_IS_VISIBLE(vc))
1197 fbcon_del_cursor_timer(info);
1198
1199 ops->flags &= ~FBCON_FLAGS_INIT;
1200finished:
1201
Dave Airlieae128782013-01-24 16:12:41 +10001202 fbcon_free_font(p, free_font);
Mika Kuoppalae6637d52013-04-22 14:19:26 +03001203 if (free_font)
1204 vc->vc_font.data = NULL;
Dave Airlieae128782013-01-24 16:12:41 +10001205
Antonino A. Daplase614b182006-06-26 00:27:09 -07001206 if (!con_is_bound(&fb_con))
1207 fbcon_exit();
1208
1209 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210}
1211
1212/* ====================================================================== */
1213
1214/* fbcon_XXX routines - interface used by the world
1215 *
1216 * This system is now divided into two levels because of complications
1217 * caused by hardware scrolling. Top level functions:
1218 *
1219 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1220 *
1221 * handles y values in range [0, scr_height-1] that correspond to real
1222 * screen positions. y_wrap shift means that first line of bitmap may be
1223 * anywhere on this display. These functions convert lineoffsets to
1224 * bitmap offsets and deal with the wrap-around case by splitting blits.
1225 *
1226 * fbcon_bmove_physical_8() -- These functions fast implementations
1227 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1228 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1229 *
1230 * WARNING:
1231 *
1232 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1233 * Implies should only really hardware scroll in rows. Only reason for
1234 * restriction is simplicity & efficiency at the moment.
1235 */
1236
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1238 int width)
1239{
1240 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1241 struct fbcon_ops *ops = info->fbcon_par;
1242
1243 struct display *p = &fb_display[vc->vc_num];
1244 u_int y_break;
1245
1246 if (fbcon_is_inactive(vc, info))
1247 return;
1248
1249 if (!height || !width)
1250 return;
1251
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001252 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001253 vc->vc_top = 0;
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001254 /*
1255 * If the font dimensions are not an integral of the display
1256 * dimensions then the ops->clear below won't end up clearing
1257 * the margins. Call clear_margins here in case the logo
1258 * bitmap stretched into the margin area.
1259 */
1260 fbcon_clear_margins(vc, 0);
1261 }
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 /* Split blits that cross physical y_wrap boundary */
1264
1265 y_break = p->vrows - p->yscroll;
1266 if (sy < y_break && sy + height - 1 >= y_break) {
1267 u_int b = y_break - sy;
1268 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1269 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1270 width);
1271 } else
1272 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1273}
1274
1275static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1276 int count, int ypos, int xpos)
1277{
1278 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1279 struct display *p = &fb_display[vc->vc_num];
1280 struct fbcon_ops *ops = info->fbcon_par;
1281
1282 if (!fbcon_is_inactive(vc, info))
1283 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1284 get_color(vc, info, scr_readw(s), 1),
1285 get_color(vc, info, scr_readw(s), 0));
1286}
1287
1288static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1289{
1290 unsigned short chr;
1291
1292 scr_writew(c, &chr);
1293 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1294}
1295
1296static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1297{
1298 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1299 struct fbcon_ops *ops = info->fbcon_par;
1300
1301 if (!fbcon_is_inactive(vc, info))
1302 ops->clear_margins(vc, info, bottom_only);
1303}
1304
1305static void fbcon_cursor(struct vc_data *vc, int mode)
1306{
1307 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1308 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 int y;
1310 int c = scr_readw((u16 *) vc->vc_pos);
1311
Scot Doyle2a17d7e2015-08-04 12:33:32 +00001312 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1313
Michal Januszewskid1e23062007-05-08 00:38:07 -07001314 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 return;
1316
Thierry Redinga5edce42015-05-21 09:58:03 +02001317 if (vc->vc_cursor_type & 0x10)
1318 fbcon_del_cursor_timer(info);
1319 else
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001320 fbcon_add_cursor_timer(info);
1321
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1323 if (mode & CM_SOFTBACK) {
1324 mode &= ~CM_SOFTBACK;
1325 y = softback_lines;
1326 } else {
1327 if (softback_lines)
1328 fbcon_set_origin(vc);
1329 y = 0;
1330 }
1331
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001332 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 get_color(vc, info, c, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
1336static int scrollback_phys_max = 0;
1337static int scrollback_max = 0;
1338static int scrollback_current = 0;
1339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001341 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001343 struct display *p, *t;
1344 struct vc_data **default_mode, *vc;
1345 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001346 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 int rows, cols, charcnt = 256;
1348
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001349 p = &fb_display[unit];
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 if (var_to_display(p, var, info))
1352 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001353
1354 vc = vc_cons[unit].d;
1355
1356 if (!vc)
1357 return;
1358
1359 default_mode = vc->vc_display_fg;
1360 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001364 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 vc->vc_font.width = (*default_mode)->vc_font.width;
1366 vc->vc_font.height = (*default_mode)->vc_font.height;
1367 p->userfont = t->userfont;
1368 if (p->userfont)
1369 REFCOUNT(p->fontdata)++;
1370 }
1371 if (p->userfont)
1372 charcnt = FNTCHARCNT(p->fontdata);
1373
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001374 var->activate = FB_ACTIVATE_NOW;
1375 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001376 var->yoffset = info->var.yoffset;
1377 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001378 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001379 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001380 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1382 if (charcnt == 256) {
1383 vc->vc_hi_font_mask = 0;
1384 } else {
1385 vc->vc_hi_font_mask = 0x100;
1386 if (vc->vc_can_do_color)
1387 vc->vc_complement_mask <<= 1;
1388 }
1389
1390 if (!*svc->vc_uni_pagedir_loc)
1391 con_set_default_unimap(svc);
1392 if (!*vc->vc_uni_pagedir_loc)
1393 con_copy_unimap(vc, svc);
1394
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001395 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1396 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1397 cols /= vc->vc_font.width;
1398 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 if (CON_IS_VISIBLE(vc)) {
1402 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001403 if (softback_buf)
1404 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 }
1406}
1407
1408static __inline__ void ywrap_up(struct vc_data *vc, int count)
1409{
1410 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001411 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 struct display *p = &fb_display[vc->vc_num];
1413
1414 p->yscroll += count;
1415 if (p->yscroll >= p->vrows) /* Deal with wrap */
1416 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001417 ops->var.xoffset = 0;
1418 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1419 ops->var.vmode |= FB_VMODE_YWRAP;
1420 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 scrollback_max += count;
1422 if (scrollback_max > scrollback_phys_max)
1423 scrollback_max = scrollback_phys_max;
1424 scrollback_current = 0;
1425}
1426
1427static __inline__ void ywrap_down(struct vc_data *vc, int count)
1428{
1429 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001430 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 struct display *p = &fb_display[vc->vc_num];
1432
1433 p->yscroll -= count;
1434 if (p->yscroll < 0) /* Deal with wrap */
1435 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001436 ops->var.xoffset = 0;
1437 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1438 ops->var.vmode |= FB_VMODE_YWRAP;
1439 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 scrollback_max -= count;
1441 if (scrollback_max < 0)
1442 scrollback_max = 0;
1443 scrollback_current = 0;
1444}
1445
1446static __inline__ void ypan_up(struct vc_data *vc, int count)
1447{
1448 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1449 struct display *p = &fb_display[vc->vc_num];
1450 struct fbcon_ops *ops = info->fbcon_par;
1451
1452 p->yscroll += count;
1453 if (p->yscroll > p->vrows - vc->vc_rows) {
1454 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1455 0, 0, 0, vc->vc_rows, vc->vc_cols);
1456 p->yscroll -= p->vrows - vc->vc_rows;
1457 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001458
1459 ops->var.xoffset = 0;
1460 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1461 ops->var.vmode &= ~FB_VMODE_YWRAP;
1462 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 fbcon_clear_margins(vc, 1);
1464 scrollback_max += count;
1465 if (scrollback_max > scrollback_phys_max)
1466 scrollback_max = scrollback_phys_max;
1467 scrollback_current = 0;
1468}
1469
1470static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1471{
1472 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001473 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 if (p->yscroll > p->vrows - vc->vc_rows) {
1479 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001481 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001482
1483 ops->var.xoffset = 0;
1484 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1485 ops->var.vmode &= ~FB_VMODE_YWRAP;
1486 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 fbcon_clear_margins(vc, 1);
1488 scrollback_max += count;
1489 if (scrollback_max > scrollback_phys_max)
1490 scrollback_max = scrollback_phys_max;
1491 scrollback_current = 0;
1492}
1493
1494static __inline__ void ypan_down(struct vc_data *vc, int count)
1495{
1496 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1497 struct display *p = &fb_display[vc->vc_num];
1498 struct fbcon_ops *ops = info->fbcon_par;
1499
1500 p->yscroll -= count;
1501 if (p->yscroll < 0) {
1502 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1503 0, vc->vc_rows, vc->vc_cols);
1504 p->yscroll += p->vrows - vc->vc_rows;
1505 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001506
1507 ops->var.xoffset = 0;
1508 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1509 ops->var.vmode &= ~FB_VMODE_YWRAP;
1510 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 fbcon_clear_margins(vc, 1);
1512 scrollback_max -= count;
1513 if (scrollback_max < 0)
1514 scrollback_max = 0;
1515 scrollback_current = 0;
1516}
1517
1518static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1519{
1520 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001521 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (p->yscroll < 0) {
1527 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001529 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001530
1531 ops->var.xoffset = 0;
1532 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1533 ops->var.vmode &= ~FB_VMODE_YWRAP;
1534 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 fbcon_clear_margins(vc, 1);
1536 scrollback_max -= count;
1537 if (scrollback_max < 0)
1538 scrollback_max = 0;
1539 scrollback_current = 0;
1540}
1541
1542static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1543 long delta)
1544{
1545 int count = vc->vc_rows;
1546 unsigned short *d, *s;
1547 unsigned long n;
1548 int line = 0;
1549
1550 d = (u16 *) softback_curr;
1551 if (d == (u16 *) softback_in)
1552 d = (u16 *) vc->vc_origin;
1553 n = softback_curr + delta * vc->vc_size_row;
1554 softback_lines -= delta;
1555 if (delta < 0) {
1556 if (softback_curr < softback_top && n < softback_buf) {
1557 n += softback_end - softback_buf;
1558 if (n < softback_top) {
1559 softback_lines -=
1560 (softback_top - n) / vc->vc_size_row;
1561 n = softback_top;
1562 }
1563 } else if (softback_curr >= softback_top
1564 && n < softback_top) {
1565 softback_lines -=
1566 (softback_top - n) / vc->vc_size_row;
1567 n = softback_top;
1568 }
1569 } else {
1570 if (softback_curr > softback_in && n >= softback_end) {
1571 n += softback_buf - softback_end;
1572 if (n > softback_in) {
1573 n = softback_in;
1574 softback_lines = 0;
1575 }
1576 } else if (softback_curr <= softback_in && n > softback_in) {
1577 n = softback_in;
1578 softback_lines = 0;
1579 }
1580 }
1581 if (n == softback_curr)
1582 return;
1583 softback_curr = n;
1584 s = (u16 *) softback_curr;
1585 if (s == (u16 *) softback_in)
1586 s = (u16 *) vc->vc_origin;
1587 while (count--) {
1588 unsigned short *start;
1589 unsigned short *le;
1590 unsigned short c;
1591 int x = 0;
1592 unsigned short attr = 1;
1593
1594 start = s;
1595 le = advance_row(s, 1);
1596 do {
1597 c = scr_readw(s);
1598 if (attr != (c & 0xff00)) {
1599 attr = c & 0xff00;
1600 if (s > start) {
1601 fbcon_putcs(vc, start, s - start,
1602 line, x);
1603 x += s - start;
1604 start = s;
1605 }
1606 }
1607 if (c == scr_readw(d)) {
1608 if (s > start) {
1609 fbcon_putcs(vc, start, s - start,
1610 line, x);
1611 x += s - start + 1;
1612 start = s + 1;
1613 } else {
1614 x++;
1615 start++;
1616 }
1617 }
1618 s++;
1619 d++;
1620 } while (s < le);
1621 if (s > start)
1622 fbcon_putcs(vc, start, s - start, line, x);
1623 line++;
1624 if (d == (u16 *) softback_end)
1625 d = (u16 *) softback_buf;
1626 if (d == (u16 *) softback_in)
1627 d = (u16 *) vc->vc_origin;
1628 if (s == (u16 *) softback_end)
1629 s = (u16 *) softback_buf;
1630 if (s == (u16 *) softback_in)
1631 s = (u16 *) vc->vc_origin;
1632 }
1633}
1634
1635static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1636 int line, int count, int dy)
1637{
1638 unsigned short *s = (unsigned short *)
1639 (vc->vc_origin + vc->vc_size_row * line);
1640
1641 while (count--) {
1642 unsigned short *start = s;
1643 unsigned short *le = advance_row(s, 1);
1644 unsigned short c;
1645 int x = 0;
1646 unsigned short attr = 1;
1647
1648 do {
1649 c = scr_readw(s);
1650 if (attr != (c & 0xff00)) {
1651 attr = c & 0xff00;
1652 if (s > start) {
1653 fbcon_putcs(vc, start, s - start,
1654 dy, x);
1655 x += s - start;
1656 start = s;
1657 }
1658 }
1659 console_conditional_schedule();
1660 s++;
1661 } while (s < le);
1662 if (s > start)
1663 fbcon_putcs(vc, start, s - start, dy, x);
1664 console_conditional_schedule();
1665 dy++;
1666 }
1667}
1668
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001669static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1670 struct display *p, int line, int count, int ycount)
1671{
1672 int offset = ycount * vc->vc_cols;
1673 unsigned short *d = (unsigned short *)
1674 (vc->vc_origin + vc->vc_size_row * line);
1675 unsigned short *s = d + offset;
1676 struct fbcon_ops *ops = info->fbcon_par;
1677
1678 while (count--) {
1679 unsigned short *start = s;
1680 unsigned short *le = advance_row(s, 1);
1681 unsigned short c;
1682 int x = 0;
1683
1684 do {
1685 c = scr_readw(s);
1686
1687 if (c == scr_readw(d)) {
1688 if (s > start) {
1689 ops->bmove(vc, info, line + ycount, x,
1690 line, x, 1, s-start);
1691 x += s - start + 1;
1692 start = s + 1;
1693 } else {
1694 x++;
1695 start++;
1696 }
1697 }
1698
1699 scr_writew(c, d);
1700 console_conditional_schedule();
1701 s++;
1702 d++;
1703 } while (s < le);
1704 if (s > start)
1705 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1706 s-start);
1707 console_conditional_schedule();
1708 if (ycount > 0)
1709 line++;
1710 else {
1711 line--;
1712 /* NOTE: We subtract two lines from these pointers */
1713 s -= vc->vc_size_row;
1714 d -= vc->vc_size_row;
1715 }
1716 }
1717}
1718
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719static void fbcon_redraw(struct vc_data *vc, struct display *p,
1720 int line, int count, int offset)
1721{
1722 unsigned short *d = (unsigned short *)
1723 (vc->vc_origin + vc->vc_size_row * line);
1724 unsigned short *s = d + offset;
1725
1726 while (count--) {
1727 unsigned short *start = s;
1728 unsigned short *le = advance_row(s, 1);
1729 unsigned short c;
1730 int x = 0;
1731 unsigned short attr = 1;
1732
1733 do {
1734 c = scr_readw(s);
1735 if (attr != (c & 0xff00)) {
1736 attr = c & 0xff00;
1737 if (s > start) {
1738 fbcon_putcs(vc, start, s - start,
1739 line, x);
1740 x += s - start;
1741 start = s;
1742 }
1743 }
1744 if (c == scr_readw(d)) {
1745 if (s > start) {
1746 fbcon_putcs(vc, start, s - start,
1747 line, x);
1748 x += s - start + 1;
1749 start = s + 1;
1750 } else {
1751 x++;
1752 start++;
1753 }
1754 }
1755 scr_writew(c, d);
1756 console_conditional_schedule();
1757 s++;
1758 d++;
1759 } while (s < le);
1760 if (s > start)
1761 fbcon_putcs(vc, start, s - start, line, x);
1762 console_conditional_schedule();
1763 if (offset > 0)
1764 line++;
1765 else {
1766 line--;
1767 /* NOTE: We subtract two lines from these pointers */
1768 s -= vc->vc_size_row;
1769 d -= vc->vc_size_row;
1770 }
1771 }
1772}
1773
1774static inline void fbcon_softback_note(struct vc_data *vc, int t,
1775 int count)
1776{
1777 unsigned short *p;
1778
1779 if (vc->vc_num != fg_console)
1780 return;
1781 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1782
1783 while (count) {
1784 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1785 count--;
1786 p = advance_row(p, 1);
1787 softback_in += vc->vc_size_row;
1788 if (softback_in == softback_end)
1789 softback_in = softback_buf;
1790 if (softback_in == softback_top) {
1791 softback_top += vc->vc_size_row;
1792 if (softback_top == softback_end)
1793 softback_top = softback_buf;
1794 }
1795 }
1796 softback_curr = softback_in;
1797}
1798
1799static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1800 int count)
1801{
1802 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1803 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1805
1806 if (fbcon_is_inactive(vc, info))
1807 return -EINVAL;
1808
1809 fbcon_cursor(vc, CM_ERASE);
1810
1811 /*
1812 * ++Geert: Only use ywrap/ypan if the console is in text mode
1813 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1814 * whole screen (prevents flicker).
1815 */
1816
1817 switch (dir) {
1818 case SM_UP:
1819 if (count > vc->vc_rows) /* Maximum realistic size */
1820 count = vc->vc_rows;
1821 if (softback_top)
1822 fbcon_softback_note(vc, t, count);
1823 if (logo_shown >= 0)
1824 goto redraw_up;
1825 switch (p->scrollmode) {
1826 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001827 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1828 count);
1829 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1830 scr_memsetw((unsigned short *) (vc->vc_origin +
1831 vc->vc_size_row *
1832 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001833 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001834 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001835 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 break;
1837
1838 case SCROLL_WRAP_MOVE:
1839 if (b - t - count > 3 * vc->vc_rows >> 2) {
1840 if (t > 0)
1841 fbcon_bmove(vc, 0, 0, count, 0, t,
1842 vc->vc_cols);
1843 ywrap_up(vc, count);
1844 if (vc->vc_rows - b > 0)
1845 fbcon_bmove(vc, b - count, 0, b, 0,
1846 vc->vc_rows - b,
1847 vc->vc_cols);
1848 } else if (info->flags & FBINFO_READS_FAST)
1849 fbcon_bmove(vc, t + count, 0, t, 0,
1850 b - t - count, vc->vc_cols);
1851 else
1852 goto redraw_up;
1853 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1854 break;
1855
1856 case SCROLL_PAN_REDRAW:
1857 if ((p->yscroll + count <=
1858 2 * (p->vrows - vc->vc_rows))
1859 && ((!scroll_partial && (b - t == vc->vc_rows))
1860 || (scroll_partial
1861 && (b - t - count >
1862 3 * vc->vc_rows >> 2)))) {
1863 if (t > 0)
1864 fbcon_redraw_move(vc, p, 0, t, count);
1865 ypan_up_redraw(vc, t, count);
1866 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001867 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 vc->vc_rows - b, b);
1869 } else
1870 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1871 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1872 break;
1873
1874 case SCROLL_PAN_MOVE:
1875 if ((p->yscroll + count <=
1876 2 * (p->vrows - vc->vc_rows))
1877 && ((!scroll_partial && (b - t == vc->vc_rows))
1878 || (scroll_partial
1879 && (b - t - count >
1880 3 * vc->vc_rows >> 2)))) {
1881 if (t > 0)
1882 fbcon_bmove(vc, 0, 0, count, 0, t,
1883 vc->vc_cols);
1884 ypan_up(vc, count);
1885 if (vc->vc_rows - b > 0)
1886 fbcon_bmove(vc, b - count, 0, b, 0,
1887 vc->vc_rows - b,
1888 vc->vc_cols);
1889 } else if (info->flags & FBINFO_READS_FAST)
1890 fbcon_bmove(vc, t + count, 0, t, 0,
1891 b - t - count, vc->vc_cols);
1892 else
1893 goto redraw_up;
1894 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1895 break;
1896
1897 case SCROLL_REDRAW:
1898 redraw_up:
1899 fbcon_redraw(vc, p, t, b - t - count,
1900 count * vc->vc_cols);
1901 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1902 scr_memsetw((unsigned short *) (vc->vc_origin +
1903 vc->vc_size_row *
1904 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001905 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001907 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
1909 break;
1910
1911 case SM_DOWN:
1912 if (count > vc->vc_rows) /* Maximum realistic size */
1913 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001914 if (logo_shown >= 0)
1915 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 switch (p->scrollmode) {
1917 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001918 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1919 -count);
1920 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1921 scr_memsetw((unsigned short *) (vc->vc_origin +
1922 vc->vc_size_row *
1923 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001924 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001925 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001926 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 break;
1928
1929 case SCROLL_WRAP_MOVE:
1930 if (b - t - count > 3 * vc->vc_rows >> 2) {
1931 if (vc->vc_rows - b > 0)
1932 fbcon_bmove(vc, b, 0, b - count, 0,
1933 vc->vc_rows - b,
1934 vc->vc_cols);
1935 ywrap_down(vc, count);
1936 if (t > 0)
1937 fbcon_bmove(vc, count, 0, 0, 0, t,
1938 vc->vc_cols);
1939 } else if (info->flags & FBINFO_READS_FAST)
1940 fbcon_bmove(vc, t, 0, t + count, 0,
1941 b - t - count, vc->vc_cols);
1942 else
1943 goto redraw_down;
1944 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1945 break;
1946
1947 case SCROLL_PAN_MOVE:
1948 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1949 && ((!scroll_partial && (b - t == vc->vc_rows))
1950 || (scroll_partial
1951 && (b - t - count >
1952 3 * vc->vc_rows >> 2)))) {
1953 if (vc->vc_rows - b > 0)
1954 fbcon_bmove(vc, b, 0, b - count, 0,
1955 vc->vc_rows - b,
1956 vc->vc_cols);
1957 ypan_down(vc, count);
1958 if (t > 0)
1959 fbcon_bmove(vc, count, 0, 0, 0, t,
1960 vc->vc_cols);
1961 } else if (info->flags & FBINFO_READS_FAST)
1962 fbcon_bmove(vc, t, 0, t + count, 0,
1963 b - t - count, vc->vc_cols);
1964 else
1965 goto redraw_down;
1966 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1967 break;
1968
1969 case SCROLL_PAN_REDRAW:
1970 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1971 && ((!scroll_partial && (b - t == vc->vc_rows))
1972 || (scroll_partial
1973 && (b - t - count >
1974 3 * vc->vc_rows >> 2)))) {
1975 if (vc->vc_rows - b > 0)
1976 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1977 b - count);
1978 ypan_down_redraw(vc, t, count);
1979 if (t > 0)
1980 fbcon_redraw_move(vc, p, count, t, 0);
1981 } else
1982 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1983 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1984 break;
1985
1986 case SCROLL_REDRAW:
1987 redraw_down:
1988 fbcon_redraw(vc, p, b - 1, b - t - count,
1989 -count * vc->vc_cols);
1990 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1991 scr_memsetw((unsigned short *) (vc->vc_origin +
1992 vc->vc_size_row *
1993 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001994 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001996 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 }
1998 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07001999 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000}
2001
2002
2003static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2004 int height, int width)
2005{
2006 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2007 struct display *p = &fb_display[vc->vc_num];
2008
2009 if (fbcon_is_inactive(vc, info))
2010 return;
2011
2012 if (!width || !height)
2013 return;
2014
2015 /* Split blits that cross physical y_wrap case.
2016 * Pathological case involves 4 blits, better to use recursive
2017 * code rather than unrolled case
2018 *
2019 * Recursive invocations don't need to erase the cursor over and
2020 * over again, so we use fbcon_bmove_rec()
2021 */
2022 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2023 p->vrows - p->yscroll);
2024}
2025
2026static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2027 int dy, int dx, int height, int width, u_int y_break)
2028{
2029 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2030 struct fbcon_ops *ops = info->fbcon_par;
2031 u_int b;
2032
2033 if (sy < y_break && sy + height > y_break) {
2034 b = y_break - sy;
2035 if (dy < sy) { /* Avoid trashing self */
2036 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2037 y_break);
2038 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2039 height - b, width, y_break);
2040 } else {
2041 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2042 height - b, width, y_break);
2043 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2044 y_break);
2045 }
2046 return;
2047 }
2048
2049 if (dy < y_break && dy + height > y_break) {
2050 b = y_break - dy;
2051 if (dy < sy) { /* Avoid trashing self */
2052 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2053 y_break);
2054 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2055 height - b, width, y_break);
2056 } else {
2057 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2058 height - b, width, y_break);
2059 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2060 y_break);
2061 }
2062 return;
2063 }
2064 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2065 height, width);
2066}
2067
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002068static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002069 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 struct vc_data *vc)
2071{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002072 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 int fh = vc->vc_font.height;
2074 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002075 u16 t = 0;
2076 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2077 info->fix.xpanstep);
2078 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2079 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2080 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2081 info->var.xres_virtual);
2082 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2083 divides(ypan, vc->vc_font.height) && vyres > yres;
2084 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2085 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002086 divides(vc->vc_font.height, vyres) &&
2087 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002089 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2090 !(cap & FBINFO_HWACCEL_DISABLED);
2091 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2092 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002094 p->vrows = vyres/fh;
2095 if (yres > (fh * (vc->vc_rows + 1)))
2096 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2097 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 p->vrows--;
2099
2100 if (good_wrap || good_pan) {
2101 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002102 p->scrollmode = good_wrap ?
2103 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 else
2105 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2106 SCROLL_PAN_REDRAW;
2107 } else {
2108 if (reading_fast || (fast_copyarea && !fast_imageblit))
2109 p->scrollmode = SCROLL_MOVE;
2110 else
2111 p->scrollmode = SCROLL_REDRAW;
2112 }
2113}
2114
2115static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002116 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
2118 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002119 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct display *p = &fb_display[vc->vc_num];
2121 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002122 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002124 virt_w = FBCON_SWAP(ops->rotate, width, height);
2125 virt_h = FBCON_SWAP(ops->rotate, height, width);
2126 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2127 vc->vc_font.height);
2128 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2129 vc->vc_font.width);
2130 var.xres = virt_w * virt_fw;
2131 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 x_diff = info->var.xres - var.xres;
2133 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002134 if (x_diff < 0 || x_diff > virt_fw ||
2135 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002136 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2139 mode = fb_find_best_mode(&var, &info->modelist);
2140 if (mode == NULL)
2141 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002142 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002144
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002145 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
2148 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2149 if (CON_IS_VISIBLE(vc)) {
2150 var.activate = FB_ACTIVATE_NOW |
2151 FB_ACTIVATE_FORCE;
2152 fb_set_var(info, &var);
2153 }
2154 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002155 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 }
2157 updatescrollmode(p, info, vc);
2158 return 0;
2159}
2160
2161static int fbcon_switch(struct vc_data *vc)
2162{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002163 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002164 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct display *p = &fb_display[vc->vc_num];
2166 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002167 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002170 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
2172 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 if (softback_lines)
2174 fbcon_set_origin(vc);
2175 softback_top = softback_curr = softback_in = softback_buf;
2176 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002177 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 }
2179
2180 if (logo_shown >= 0) {
2181 struct vc_data *conp2 = vc_cons[logo_shown].d;
2182
2183 if (conp2->vc_top == logo_lines
2184 && conp2->vc_bottom == conp2->vc_rows)
2185 conp2->vc_top = 0;
2186 logo_shown = FBCON_LOGO_CANSHOW;
2187 }
2188
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002189 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002190 if (prev_console != -1)
2191 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 /*
2193 * FIXME: If we have multiple fbdev's loaded, we need to
2194 * update all info->currcon. Perhaps, we can place this
2195 * in a centralized structure, but this might break some
2196 * drivers.
2197 *
2198 * info->currcon = vc->vc_num;
2199 */
2200 for (i = 0; i < FB_MAX; i++) {
2201 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002202 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002204 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 }
2206 }
2207 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2208 display_to_var(&var, p);
2209 var.activate = FB_ACTIVATE_NOW;
2210
2211 /*
2212 * make sure we don't unnecessarily trip the memcmp()
2213 * in fb_set_var()
2214 */
2215 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002216 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002218 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219
Knut Petersen39942fd2005-12-12 22:17:19 -08002220 if (old_info != NULL && (old_info != info ||
2221 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002222 if (info->fbops->fb_set_par) {
2223 ret = info->fbops->fb_set_par(info);
2224
2225 if (ret)
2226 printk(KERN_ERR "fbcon_switch: detected "
2227 "unhandled fb_set_par error, "
2228 "error code %d\n", ret);
2229 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002230
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002231 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002232 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002235 if (fbcon_is_inactive(vc, info) ||
2236 ops->blank_state != FB_BLANK_UNBLANK)
2237 fbcon_del_cursor_timer(info);
2238 else
2239 fbcon_add_cursor_timer(info);
2240
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002241 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002242 ops->cursor_reset = 1;
2243
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002244 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002245 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002246 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002249 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002251
2252 if (p->userfont)
2253 charcnt = FNTCHARCNT(vc->vc_font.data);
2254
2255 if (charcnt > 256)
2256 vc->vc_complement_mask <<= 1;
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 updatescrollmode(p, info, vc);
2259
2260 switch (p->scrollmode) {
2261 case SCROLL_WRAP_MOVE:
2262 scrollback_phys_max = p->vrows - vc->vc_rows;
2263 break;
2264 case SCROLL_PAN_MOVE:
2265 case SCROLL_PAN_REDRAW:
2266 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2267 if (scrollback_phys_max < 0)
2268 scrollback_phys_max = 0;
2269 break;
2270 default:
2271 scrollback_phys_max = 0;
2272 break;
2273 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 scrollback_max = 0;
2276 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002277
2278 if (!fbcon_is_inactive(vc, info)) {
2279 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2280 ops->update_start(info);
2281 }
2282
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 fbcon_set_palette(vc, color_table);
2284 fbcon_clear_margins(vc, 0);
2285
2286 if (logo_shown == FBCON_LOGO_DRAW) {
2287
2288 logo_shown = fg_console;
2289 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002290 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 update_region(vc,
2292 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2293 vc->vc_size_row * (vc->vc_bottom -
2294 vc->vc_top) / 2);
2295 return 0;
2296 }
2297 return 1;
2298}
2299
2300static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2301 int blank)
2302{
Richard Purdie994efac2007-02-09 09:46:45 +00002303 struct fb_event event;
2304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 if (blank) {
2306 unsigned short charmask = vc->vc_hi_font_mask ?
2307 0x1ff : 0xff;
2308 unsigned short oldc;
2309
2310 oldc = vc->vc_video_erase_char;
2311 vc->vc_video_erase_char &= charmask;
2312 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2313 vc->vc_video_erase_char = oldc;
2314 }
Richard Purdie994efac2007-02-09 09:46:45 +00002315
2316
Andrea Righi513adb52009-04-13 14:39:39 -07002317 if (!lock_fb_info(info))
2318 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002319 event.info = info;
2320 event.data = &blank;
2321 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002322 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
2325static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2326{
2327 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2328 struct fbcon_ops *ops = info->fbcon_par;
2329
2330 if (mode_switch) {
2331 struct fb_var_screeninfo var = info->var;
2332
2333 ops->graphics = 1;
2334
2335 if (!blank) {
2336 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2337 fb_set_var(info, &var);
2338 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002339 ops->var = info->var;
Krzysztof Heltf5c15d02009-11-11 14:26:22 -08002340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 }
2342
2343 if (!fbcon_is_inactive(vc, info)) {
2344 if (ops->blank_state != blank) {
2345 ops->blank_state = blank;
2346 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2347 ops->cursor_flash = (!blank);
2348
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002349 if (!(info->flags & FBINFO_MISC_USEREVENT))
2350 if (fb_blank(info, blank))
2351 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002354 if (!blank)
2355 update_screen(vc);
2356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002358 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002359 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002360 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002361 else
2362 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002363
2364 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365}
2366
Jesse Barnesd219adc2010-08-02 12:05:41 -07002367static int fbcon_debug_enter(struct vc_data *vc)
2368{
2369 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2370 struct fbcon_ops *ops = info->fbcon_par;
2371
2372 ops->save_graphics = ops->graphics;
2373 ops->graphics = 0;
2374 if (info->fbops->fb_debug_enter)
2375 info->fbops->fb_debug_enter(info);
2376 fbcon_set_palette(vc, color_table);
2377 return 0;
2378}
2379
2380static int fbcon_debug_leave(struct vc_data *vc)
2381{
2382 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2383 struct fbcon_ops *ops = info->fbcon_par;
2384
2385 ops->graphics = ops->save_graphics;
2386 if (info->fbops->fb_debug_leave)
2387 info->fbops->fb_debug_leave(info);
2388 return 0;
2389}
2390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2392{
2393 u8 *fontdata = vc->vc_font.data;
2394 u8 *data = font->data;
2395 int i, j;
2396
2397 font->width = vc->vc_font.width;
2398 font->height = vc->vc_font.height;
2399 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2400 if (!font->data)
2401 return 0;
2402
2403 if (font->width <= 8) {
2404 j = vc->vc_font.height;
2405 for (i = 0; i < font->charcount; i++) {
2406 memcpy(data, fontdata, j);
2407 memset(data + j, 0, 32 - j);
2408 data += 32;
2409 fontdata += j;
2410 }
2411 } else if (font->width <= 16) {
2412 j = vc->vc_font.height * 2;
2413 for (i = 0; i < font->charcount; i++) {
2414 memcpy(data, fontdata, j);
2415 memset(data + j, 0, 64 - j);
2416 data += 64;
2417 fontdata += j;
2418 }
2419 } else if (font->width <= 24) {
2420 for (i = 0; i < font->charcount; i++) {
2421 for (j = 0; j < vc->vc_font.height; j++) {
2422 *data++ = fontdata[0];
2423 *data++ = fontdata[1];
2424 *data++ = fontdata[2];
2425 fontdata += sizeof(u32);
2426 }
2427 memset(data, 0, 3 * (32 - j));
2428 data += 3 * (32 - j);
2429 }
2430 } else {
2431 j = vc->vc_font.height * 4;
2432 for (i = 0; i < font->charcount; i++) {
2433 memcpy(data, fontdata, j);
2434 memset(data + j, 0, 128 - j);
2435 data += 128;
2436 fontdata += j;
2437 }
2438 }
2439 return 0;
2440}
2441
2442static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002443 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444{
2445 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002446 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 struct display *p = &fb_display[vc->vc_num];
2448 int resize;
2449 int cnt;
2450 char *old_data = NULL;
2451
2452 if (CON_IS_VISIBLE(vc) && softback_lines)
2453 fbcon_set_origin(vc);
2454
2455 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2456 if (p->userfont)
2457 old_data = vc->vc_font.data;
2458 if (userfont)
2459 cnt = FNTCHARCNT(data);
2460 else
2461 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002462 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 if ((p->userfont = userfont))
2464 REFCOUNT(data)++;
2465 vc->vc_font.width = w;
2466 vc->vc_font.height = h;
2467 if (vc->vc_hi_font_mask && cnt == 256) {
2468 vc->vc_hi_font_mask = 0;
2469 if (vc->vc_can_do_color) {
2470 vc->vc_complement_mask >>= 1;
2471 vc->vc_s_complement_mask >>= 1;
2472 }
2473
2474 /* ++Edmund: reorder the attribute bits */
2475 if (vc->vc_can_do_color) {
2476 unsigned short *cp =
2477 (unsigned short *) vc->vc_origin;
2478 int count = vc->vc_screenbuf_size / 2;
2479 unsigned short c;
2480 for (; count > 0; count--, cp++) {
2481 c = scr_readw(cp);
2482 scr_writew(((c & 0xfe00) >> 1) |
2483 (c & 0xff), cp);
2484 }
2485 c = vc->vc_video_erase_char;
2486 vc->vc_video_erase_char =
2487 ((c & 0xfe00) >> 1) | (c & 0xff);
2488 vc->vc_attr >>= 1;
2489 }
2490 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2491 vc->vc_hi_font_mask = 0x100;
2492 if (vc->vc_can_do_color) {
2493 vc->vc_complement_mask <<= 1;
2494 vc->vc_s_complement_mask <<= 1;
2495 }
2496
2497 /* ++Edmund: reorder the attribute bits */
2498 {
2499 unsigned short *cp =
2500 (unsigned short *) vc->vc_origin;
2501 int count = vc->vc_screenbuf_size / 2;
2502 unsigned short c;
2503 for (; count > 0; count--, cp++) {
2504 unsigned short newc;
2505 c = scr_readw(cp);
2506 if (vc->vc_can_do_color)
2507 newc =
2508 ((c & 0xff00) << 1) | (c &
2509 0xff);
2510 else
2511 newc = c & ~0x100;
2512 scr_writew(newc, cp);
2513 }
2514 c = vc->vc_video_erase_char;
2515 if (vc->vc_can_do_color) {
2516 vc->vc_video_erase_char =
2517 ((c & 0xff00) << 1) | (c & 0xff);
2518 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002519 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 vc->vc_video_erase_char = c & ~0x100;
2521 }
2522
2523 }
2524
2525 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002526 int cols, rows;
2527
2528 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2529 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2530 cols /= w;
2531 rows /= h;
2532 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002533 if (CON_IS_VISIBLE(vc) && softback_buf)
2534 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 } else if (CON_IS_VISIBLE(vc)
2536 && vc->vc_mode == KD_TEXT) {
2537 fbcon_clear_margins(vc, 0);
2538 update_screen(vc);
2539 }
2540
2541 if (old_data && (--REFCOUNT(old_data) == 0))
2542 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2543 return 0;
2544}
2545
2546static int fbcon_copy_font(struct vc_data *vc, int con)
2547{
2548 struct display *od = &fb_display[con];
2549 struct console_font *f = &vc->vc_font;
2550
2551 if (od->fontdata == f->data)
2552 return 0; /* already the same font... */
2553 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2554}
2555
2556/*
2557 * User asked to set font; we are guaranteed that
2558 * a) width and height are in range 1..32
2559 * b) charcount does not exceed 512
2560 * but lets not assume that, since someone might someday want to use larger
2561 * fonts. And charcount of 512 is small for unicode support.
2562 *
2563 * However, user space gives the font in 32 rows , regardless of
2564 * actual font height. So a new API is needed if support for larger fonts
2565 * is ever implemented.
2566 */
2567
2568static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2569{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002570 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 unsigned charcount = font->charcount;
2572 int w = font->width;
2573 int h = font->height;
2574 int size;
2575 int i, csum;
2576 u8 *new_data, *data = font->data;
2577 int pitch = (font->width+7) >> 3;
2578
2579 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2580 * If not this check should be changed to charcount < 256 */
2581 if (charcount != 256 && charcount != 512)
2582 return -EINVAL;
2583
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002584 /* Make sure drawing engine can handle the font */
2585 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2586 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2587 return -EINVAL;
2588
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002589 /* Make sure driver can handle the font length */
2590 if (fbcon_invalid_charcount(info, charcount))
2591 return -EINVAL;
2592
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 size = h * pitch * charcount;
2594
2595 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2596
2597 if (!new_data)
2598 return -ENOMEM;
2599
2600 new_data += FONT_EXTRA_WORDS * sizeof(int);
2601 FNTSIZE(new_data) = size;
2602 FNTCHARCNT(new_data) = charcount;
2603 REFCOUNT(new_data) = 0; /* usage counter */
2604 for (i=0; i< charcount; i++) {
2605 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2606 }
2607
2608 /* Since linux has a nice crc32 function use it for counting font
2609 * checksums. */
2610 csum = crc32(0, new_data, size);
2611
2612 FNTSUM(new_data) = csum;
2613 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002614 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 struct vc_data *tmp = vc_cons[i].d;
2616
2617 if (fb_display[i].userfont &&
2618 fb_display[i].fontdata &&
2619 FNTSUM(fb_display[i].fontdata) == csum &&
2620 FNTSIZE(fb_display[i].fontdata) == size &&
2621 tmp->vc_font.width == w &&
2622 !memcmp(fb_display[i].fontdata, new_data, size)) {
2623 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002624 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 break;
2626 }
2627 }
2628 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2629}
2630
2631static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2632{
2633 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002634 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002637 f = get_default_font(info->var.xres, info->var.yres,
2638 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 else if (!(f = find_font(name)))
2640 return -ENOENT;
2641
2642 font->width = f->width;
2643 font->height = f->height;
2644 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2645}
2646
2647static u16 palette_red[16];
2648static u16 palette_green[16];
2649static u16 palette_blue[16];
2650
2651static struct fb_cmap palette_cmap = {
2652 0, 16, palette_red, palette_green, palette_blue, NULL
2653};
2654
2655static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2656{
2657 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2658 int i, j, k, depth;
2659 u8 val;
2660
2661 if (fbcon_is_inactive(vc, info))
2662 return -EINVAL;
2663
2664 if (!CON_IS_VISIBLE(vc))
2665 return 0;
2666
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002667 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 if (depth > 3) {
2669 for (i = j = 0; i < 16; i++) {
2670 k = table[i];
2671 val = vc->vc_palette[j++];
2672 palette_red[k] = (val << 8) | val;
2673 val = vc->vc_palette[j++];
2674 palette_green[k] = (val << 8) | val;
2675 val = vc->vc_palette[j++];
2676 palette_blue[k] = (val << 8) | val;
2677 }
2678 palette_cmap.len = 16;
2679 palette_cmap.start = 0;
2680 /*
2681 * If framebuffer is capable of less than 16 colors,
2682 * use default palette of fbcon.
2683 */
2684 } else
2685 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2686
2687 return fb_set_cmap(&palette_cmap, info);
2688}
2689
2690static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2691{
2692 unsigned long p;
2693 int line;
2694
2695 if (vc->vc_num != fg_console || !softback_lines)
2696 return (u16 *) (vc->vc_origin + offset);
2697 line = offset / vc->vc_size_row;
2698 if (line >= softback_lines)
2699 return (u16 *) (vc->vc_origin + offset -
2700 softback_lines * vc->vc_size_row);
2701 p = softback_curr + offset;
2702 if (p >= softback_end)
2703 p += softback_buf - softback_end;
2704 return (u16 *) p;
2705}
2706
2707static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2708 int *px, int *py)
2709{
2710 unsigned long ret;
2711 int x, y;
2712
2713 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2714 unsigned long offset = (pos - vc->vc_origin) / 2;
2715
2716 x = offset % vc->vc_cols;
2717 y = offset / vc->vc_cols;
2718 if (vc->vc_num == fg_console)
2719 y += softback_lines;
2720 ret = pos + (vc->vc_cols - x) * 2;
2721 } else if (vc->vc_num == fg_console && softback_lines) {
2722 unsigned long offset = pos - softback_curr;
2723
2724 if (pos < softback_curr)
2725 offset += softback_end - softback_buf;
2726 offset /= 2;
2727 x = offset % vc->vc_cols;
2728 y = offset / vc->vc_cols;
2729 ret = pos + (vc->vc_cols - x) * 2;
2730 if (ret == softback_end)
2731 ret = softback_buf;
2732 if (ret == softback_in)
2733 ret = vc->vc_origin;
2734 } else {
2735 /* Should not happen */
2736 x = y = 0;
2737 ret = vc->vc_origin;
2738 }
2739 if (px)
2740 *px = x;
2741 if (py)
2742 *py = y;
2743 return ret;
2744}
2745
2746/* As we might be inside of softback, we may work with non-contiguous buffer,
2747 that's why we have to use a separate routine. */
2748static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2749{
2750 while (cnt--) {
2751 u16 a = scr_readw(p);
2752 if (!vc->vc_can_do_color)
2753 a ^= 0x0800;
2754 else if (vc->vc_hi_font_mask == 0x100)
2755 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2756 (((a) & 0x0e00) << 4);
2757 else
2758 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2759 (((a) & 0x0700) << 4);
2760 scr_writew(a, p++);
2761 if (p == (u16 *) softback_end)
2762 p = (u16 *) softback_buf;
2763 if (p == (u16 *) softback_in)
2764 p = (u16 *) vc->vc_origin;
2765 }
2766}
2767
2768static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2769{
2770 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002771 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002772 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 int offset, limit, scrollback_old;
2774
2775 if (softback_top) {
2776 if (vc->vc_num != fg_console)
2777 return 0;
2778 if (vc->vc_mode != KD_TEXT || !lines)
2779 return 0;
2780 if (logo_shown >= 0) {
2781 struct vc_data *conp2 = vc_cons[logo_shown].d;
2782
2783 if (conp2->vc_top == logo_lines
2784 && conp2->vc_bottom == conp2->vc_rows)
2785 conp2->vc_top = 0;
2786 if (logo_shown == vc->vc_num) {
2787 unsigned long p, q;
2788 int i;
2789
2790 p = softback_in;
2791 q = vc->vc_origin +
2792 logo_lines * vc->vc_size_row;
2793 for (i = 0; i < logo_lines; i++) {
2794 if (p == softback_top)
2795 break;
2796 if (p == softback_buf)
2797 p = softback_end;
2798 p -= vc->vc_size_row;
2799 q -= vc->vc_size_row;
2800 scr_memcpyw((u16 *) q, (u16 *) p,
2801 vc->vc_size_row);
2802 }
David Hollister308af922006-05-30 21:25:36 -07002803 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 update_region(vc, vc->vc_origin,
2805 logo_lines * vc->vc_cols);
2806 }
2807 logo_shown = FBCON_LOGO_CANSHOW;
2808 }
2809 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002810 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2812 return 0;
2813 }
2814
2815 if (!scrollback_phys_max)
2816 return -ENOSYS;
2817
2818 scrollback_old = scrollback_current;
2819 scrollback_current -= lines;
2820 if (scrollback_current < 0)
2821 scrollback_current = 0;
2822 else if (scrollback_current > scrollback_max)
2823 scrollback_current = scrollback_max;
2824 if (scrollback_current == scrollback_old)
2825 return 0;
2826
2827 if (fbcon_is_inactive(vc, info))
2828 return 0;
2829
2830 fbcon_cursor(vc, CM_ERASE);
2831
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002832 offset = disp->yscroll - scrollback_current;
2833 limit = disp->vrows;
2834 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 case SCROLL_WRAP_MOVE:
2836 info->var.vmode |= FB_VMODE_YWRAP;
2837 break;
2838 case SCROLL_PAN_MOVE:
2839 case SCROLL_PAN_REDRAW:
2840 limit -= vc->vc_rows;
2841 info->var.vmode &= ~FB_VMODE_YWRAP;
2842 break;
2843 }
2844 if (offset < 0)
2845 offset += limit;
2846 else if (offset >= limit)
2847 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002848
2849 ops->var.xoffset = 0;
2850 ops->var.yoffset = offset * vc->vc_font.height;
2851 ops->update_start(info);
2852
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 if (!scrollback_current)
2854 fbcon_cursor(vc, CM_DRAW);
2855 return 0;
2856}
2857
2858static int fbcon_set_origin(struct vc_data *vc)
2859{
2860 if (softback_lines)
2861 fbcon_scrolldelta(vc, softback_lines);
2862 return 0;
2863}
2864
2865static void fbcon_suspended(struct fb_info *info)
2866{
2867 struct vc_data *vc = NULL;
2868 struct fbcon_ops *ops = info->fbcon_par;
2869
2870 if (!ops || ops->currcon < 0)
2871 return;
2872 vc = vc_cons[ops->currcon].d;
2873
2874 /* Clear cursor, restore saved data */
2875 fbcon_cursor(vc, CM_ERASE);
2876}
2877
2878static void fbcon_resumed(struct fb_info *info)
2879{
2880 struct vc_data *vc;
2881 struct fbcon_ops *ops = info->fbcon_par;
2882
2883 if (!ops || ops->currcon < 0)
2884 return;
2885 vc = vc_cons[ops->currcon].d;
2886
2887 update_screen(vc);
2888}
2889
2890static void fbcon_modechanged(struct fb_info *info)
2891{
2892 struct fbcon_ops *ops = info->fbcon_par;
2893 struct vc_data *vc;
2894 struct display *p;
2895 int rows, cols;
2896
2897 if (!ops || ops->currcon < 0)
2898 return;
2899 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002900 if (vc->vc_mode != KD_TEXT ||
2901 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 return;
2903
2904 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002905 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
2907 if (CON_IS_VISIBLE(vc)) {
2908 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002909 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2910 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2911 cols /= vc->vc_font.width;
2912 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 vc_resize(vc, cols, rows);
2914 updatescrollmode(p, info, vc);
2915 scrollback_max = 0;
2916 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002917
2918 if (!fbcon_is_inactive(vc, info)) {
2919 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2920 ops->update_start(info);
2921 }
2922
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 fbcon_set_palette(vc, color_table);
2924 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002925 if (softback_buf)
2926 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 }
2928}
2929
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002930static void fbcon_set_all_vcs(struct fb_info *info)
2931{
2932 struct fbcon_ops *ops = info->fbcon_par;
2933 struct vc_data *vc;
2934 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002935 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002936
2937 if (!ops || ops->currcon < 0)
2938 return;
2939
Antonino A. Daplase614b182006-06-26 00:27:09 -07002940 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002941 vc = vc_cons[i].d;
2942 if (!vc || vc->vc_mode != KD_TEXT ||
2943 registered_fb[con2fb_map[i]] != info)
2944 continue;
2945
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002946 if (CON_IS_VISIBLE(vc)) {
2947 fg = i;
2948 continue;
2949 }
2950
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002951 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002952 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002953 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002954 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2955 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002956 cols /= vc->vc_font.width;
2957 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002958 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002959 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002960
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002961 if (fg != -1)
2962 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002963}
2964
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965static int fbcon_mode_deleted(struct fb_info *info,
2966 struct fb_videomode *mode)
2967{
2968 struct fb_info *fb_info;
2969 struct display *p;
2970 int i, j, found = 0;
2971
2972 /* before deletion, ensure that mode is not in use */
2973 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2974 j = con2fb_map[i];
2975 if (j == -1)
2976 continue;
2977 fb_info = registered_fb[j];
2978 if (fb_info != info)
2979 continue;
2980 p = &fb_display[i];
2981 if (!p || !p->mode)
2982 continue;
2983 if (fb_mode_is_equal(p->mode, mode)) {
2984 found = 1;
2985 break;
2986 }
2987 }
2988 return found;
2989}
2990
Jesse Barnescfafca82007-07-17 04:05:33 -07002991#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2992static int fbcon_unbind(void)
2993{
2994 int ret;
2995
Takashi Iwaie93a9a82013-01-25 10:28:18 +10002996 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
Jesse Barnescfafca82007-07-17 04:05:33 -07002997 fbcon_is_default);
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07002998
2999 if (!ret)
3000 fbcon_has_console_bind = 0;
3001
Jesse Barnescfafca82007-07-17 04:05:33 -07003002 return ret;
3003}
3004#else
3005static inline int fbcon_unbind(void)
3006{
3007 return -EINVAL;
3008}
3009#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3010
Dave Airlie054430e2013-01-25 11:38:56 +10003011/* called with console_lock held */
Jesse Barnescfafca82007-07-17 04:05:33 -07003012static int fbcon_fb_unbind(int idx)
3013{
3014 int i, new_idx = -1, ret = 0;
3015
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003016 if (!fbcon_has_console_bind)
3017 return 0;
3018
Jesse Barnescfafca82007-07-17 04:05:33 -07003019 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3020 if (con2fb_map[i] != idx &&
3021 con2fb_map[i] != -1) {
3022 new_idx = i;
3023 break;
3024 }
3025 }
3026
3027 if (new_idx != -1) {
3028 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3029 if (con2fb_map[i] == idx)
3030 set_con2fb_map(i, new_idx, 0);
3031 }
Keith Packard5f4dc282014-01-20 13:31:10 -08003032 } else {
3033 struct fb_info *info = registered_fb[idx];
3034
3035 /* This is sort of like set_con2fb_map, except it maps
3036 * the consoles to no device and then releases the
3037 * oldinfo to free memory and cancel the cursor blink
3038 * timer. I can imagine this just becoming part of
3039 * set_con2fb_map where new_idx is -1
3040 */
3041 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3042 if (con2fb_map[i] == idx) {
3043 con2fb_map[i] = -1;
3044 if (!search_fb_in_map(idx)) {
3045 ret = con2fb_release_oldinfo(vc_cons[i].d,
3046 info, NULL, i,
3047 idx, 0);
3048 if (ret) {
3049 con2fb_map[i] = idx;
3050 return ret;
3051 }
3052 }
3053 }
3054 }
Jesse Barnescfafca82007-07-17 04:05:33 -07003055 ret = fbcon_unbind();
Keith Packard5f4dc282014-01-20 13:31:10 -08003056 }
Jesse Barnescfafca82007-07-17 04:05:33 -07003057
3058 return ret;
3059}
3060
Dave Airlie054430e2013-01-25 11:38:56 +10003061/* called with console_lock held */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003062static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003063{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003064 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003065
Andrea Righi66c1ca02009-03-31 15:25:18 -07003066 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003067 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3068 if (con2fb_map[i] == idx)
3069 con2fb_map[i] = -1;
3070 }
3071
3072 if (idx == info_idx) {
3073 info_idx = -1;
3074
3075 for (i = 0; i < FB_MAX; i++) {
3076 if (registered_fb[i] != NULL) {
3077 info_idx = i;
3078 break;
3079 }
3080 }
3081 }
3082
3083 if (info_idx != -1) {
3084 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3085 if (con2fb_map[i] == -1)
3086 con2fb_map[i] = info_idx;
3087 }
3088 }
3089
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003090 if (primary_device == idx)
3091 primary_device = -1;
3092
Andrea Righi66c1ca02009-03-31 15:25:18 -07003093 if (!num_registered_fb)
Takashi Iwaie93a9a82013-01-25 10:28:18 +10003094 do_unregister_con_driver(&fb_con);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003095
Antonino A. Daplase614b182006-06-26 00:27:09 -07003096 return 0;
3097}
3098
Dave Airlie054430e2013-01-25 11:38:56 +10003099/* called with console_lock held */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003100static void fbcon_remap_all(int idx)
3101{
3102 int i;
3103 for (i = first_fb_vc; i <= last_fb_vc; i++)
3104 set_con2fb_map(i, idx, 0);
3105
3106 if (con_is_bound(&fb_con)) {
3107 printk(KERN_INFO "fbcon: Remapping primary device, "
3108 "fb%i, to tty %i-%i\n", idx,
3109 first_fb_vc + 1, last_fb_vc + 1);
3110 info_idx = idx;
3111 }
3112}
3113
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003114#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003115static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003117 if (!map_override && primary_device == -1 &&
3118 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003119 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003120
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003121 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3122 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003123 primary_device = info->node;
3124
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003125 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003126 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003127
3128 if (con_is_bound(&fb_con)) {
3129 printk(KERN_INFO "fbcon: Remapping primary device, "
3130 "fb%i, to tty %i-%i\n", info->node,
3131 first_fb_vc + 1, last_fb_vc + 1);
3132 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003133 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003134 }
3135
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003136}
3137#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003138static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003139{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003140 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003141}
3142#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3143
Dave Airlie054430e2013-01-25 11:38:56 +10003144/* called with console_lock held */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003145static int fbcon_fb_registered(struct fb_info *info)
3146{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003147 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003148
Andrea Righi66c1ca02009-03-31 15:25:18 -07003149 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003150 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003153 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 if (con2fb_map_boot[i] == idx) {
3155 info_idx = idx;
3156 break;
3157 }
3158 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003159
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 if (info_idx != -1)
Alan Cox50e244c2013-01-25 10:28:15 +10003161 ret = do_fbcon_takeover(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003163 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003164 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 set_con2fb_map(i, idx, 0);
3166 }
3167 }
3168
3169 return ret;
3170}
3171
3172static void fbcon_fb_blanked(struct fb_info *info, int blank)
3173{
3174 struct fbcon_ops *ops = info->fbcon_par;
3175 struct vc_data *vc;
3176
3177 if (!ops || ops->currcon < 0)
3178 return;
3179
3180 vc = vc_cons[ops->currcon].d;
3181 if (vc->vc_mode != KD_TEXT ||
3182 registered_fb[con2fb_map[ops->currcon]] != info)
3183 return;
3184
3185 if (CON_IS_VISIBLE(vc)) {
3186 if (blank)
3187 do_blank_screen(0);
3188 else
3189 do_unblank_screen(0);
3190 }
3191 ops->blank_state = blank;
3192}
3193
3194static void fbcon_new_modelist(struct fb_info *info)
3195{
3196 int i;
3197 struct vc_data *vc;
3198 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003199 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
Antonino A. Daplase614b182006-06-26 00:27:09 -07003201 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 if (registered_fb[con2fb_map[i]] != info)
3203 continue;
3204 if (!fb_display[i].mode)
3205 continue;
3206 vc = vc_cons[i].d;
3207 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003208 mode = fb_find_nearest_mode(fb_display[i].mode,
3209 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003211 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 }
3213}
3214
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003215static void fbcon_get_requirement(struct fb_info *info,
3216 struct fb_blit_caps *caps)
3217{
3218 struct vc_data *vc;
3219 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003220
3221 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003222 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003223
3224 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3225 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003226 if (vc && vc->vc_mode == KD_TEXT &&
3227 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003228 p = &fb_display[i];
3229 caps->x |= 1 << (vc->vc_font.width - 1);
3230 caps->y |= 1 << (vc->vc_font.height - 1);
3231 charcnt = (p->userfont) ?
3232 FNTCHARCNT(p->fontdata) : 256;
3233 if (caps->len < charcnt)
3234 caps->len = charcnt;
3235 }
3236 }
3237 } else {
3238 vc = vc_cons[fg_console].d;
3239
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003240 if (vc && vc->vc_mode == KD_TEXT &&
3241 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003242 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003243 caps->x = 1 << (vc->vc_font.width - 1);
3244 caps->y = 1 << (vc->vc_font.height - 1);
3245 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003246 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003247 }
3248 }
3249}
3250
Andrea Righi66c1ca02009-03-31 15:25:18 -07003251static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 unsigned long action, void *data)
3253{
3254 struct fb_event *event = data;
3255 struct fb_info *info = event->info;
3256 struct fb_videomode *mode;
3257 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003258 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003259 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
Antonino A. Daplase614b182006-06-26 00:27:09 -07003261 /*
3262 * ignore all events except driver registration and deregistration
3263 * if fbcon is not active
3264 */
3265 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3266 action == FB_EVENT_FB_UNREGISTERED))
3267 goto done;
3268
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 switch(action) {
3270 case FB_EVENT_SUSPEND:
3271 fbcon_suspended(info);
3272 break;
3273 case FB_EVENT_RESUME:
3274 fbcon_resumed(info);
3275 break;
3276 case FB_EVENT_MODE_CHANGE:
3277 fbcon_modechanged(info);
3278 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003279 case FB_EVENT_MODE_CHANGE_ALL:
3280 fbcon_set_all_vcs(info);
3281 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 case FB_EVENT_MODE_DELETE:
3283 mode = event->data;
3284 ret = fbcon_mode_deleted(info, mode);
3285 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003286 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003287 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003288 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003289 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003291 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003293 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003294 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 case FB_EVENT_SET_CONSOLE_MAP:
Dave Airlie054430e2013-01-25 11:38:56 +10003297 /* called with console lock held */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 con2fb = event->data;
3299 ret = set_con2fb_map(con2fb->console - 1,
3300 con2fb->framebuffer, 1);
3301 break;
3302 case FB_EVENT_GET_CONSOLE_MAP:
3303 con2fb = event->data;
3304 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3305 break;
3306 case FB_EVENT_BLANK:
3307 fbcon_fb_blanked(info, *(int *)event->data);
3308 break;
3309 case FB_EVENT_NEW_MODELIST:
3310 fbcon_new_modelist(info);
3311 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003312 case FB_EVENT_GET_REQ:
3313 caps = event->data;
3314 fbcon_get_requirement(info, caps);
3315 break;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003316 case FB_EVENT_REMAP_ALL_CONSOLE:
3317 idx = info->node;
3318 fbcon_remap_all(idx);
3319 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003321done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 return ret;
3323}
3324
3325/*
3326 * The console `switch' structure for the frame buffer based console
3327 */
3328
3329static const struct consw fb_con = {
3330 .owner = THIS_MODULE,
3331 .con_startup = fbcon_startup,
3332 .con_init = fbcon_init,
3333 .con_deinit = fbcon_deinit,
3334 .con_clear = fbcon_clear,
3335 .con_putc = fbcon_putc,
3336 .con_putcs = fbcon_putcs,
3337 .con_cursor = fbcon_cursor,
3338 .con_scroll = fbcon_scroll,
3339 .con_bmove = fbcon_bmove,
3340 .con_switch = fbcon_switch,
3341 .con_blank = fbcon_blank,
3342 .con_font_set = fbcon_set_font,
3343 .con_font_get = fbcon_get_font,
3344 .con_font_default = fbcon_set_def_font,
3345 .con_font_copy = fbcon_copy_font,
3346 .con_set_palette = fbcon_set_palette,
3347 .con_scrolldelta = fbcon_scrolldelta,
3348 .con_set_origin = fbcon_set_origin,
3349 .con_invert_region = fbcon_invert_region,
3350 .con_screen_pos = fbcon_screen_pos,
3351 .con_getxy = fbcon_getxy,
3352 .con_resize = fbcon_resize,
Jesse Barnesd219adc2010-08-02 12:05:41 -07003353 .con_debug_enter = fbcon_debug_enter,
3354 .con_debug_leave = fbcon_debug_leave,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355};
3356
3357static struct notifier_block fbcon_event_notifier = {
3358 .notifier_call = fbcon_event_notify,
3359};
3360
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003361static ssize_t store_rotate(struct device *device,
3362 struct device_attribute *attr, const char *buf,
3363 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003364{
3365 struct fb_info *info;
3366 int rotate, idx;
3367 char **last = NULL;
3368
Antonino A. Daplase614b182006-06-26 00:27:09 -07003369 if (fbcon_has_exited)
3370 return count;
3371
Torben Hohnac751ef2011-01-25 15:07:35 -08003372 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003373 idx = con2fb_map[fg_console];
3374
3375 if (idx == -1 || registered_fb[idx] == NULL)
3376 goto err;
3377
3378 info = registered_fb[idx];
3379 rotate = simple_strtoul(buf, last, 0);
3380 fbcon_rotate(info, rotate);
3381err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003382 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003383 return count;
3384}
3385
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003386static ssize_t store_rotate_all(struct device *device,
3387 struct device_attribute *attr,const char *buf,
3388 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003389{
3390 struct fb_info *info;
3391 int rotate, idx;
3392 char **last = NULL;
3393
Antonino A. Daplase614b182006-06-26 00:27:09 -07003394 if (fbcon_has_exited)
3395 return count;
3396
Torben Hohnac751ef2011-01-25 15:07:35 -08003397 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003398 idx = con2fb_map[fg_console];
3399
3400 if (idx == -1 || registered_fb[idx] == NULL)
3401 goto err;
3402
3403 info = registered_fb[idx];
3404 rotate = simple_strtoul(buf, last, 0);
3405 fbcon_rotate_all(info, rotate);
3406err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003407 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003408 return count;
3409}
3410
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003411static ssize_t show_rotate(struct device *device,
3412 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003413{
3414 struct fb_info *info;
3415 int rotate = 0, idx;
3416
Antonino A. Daplase614b182006-06-26 00:27:09 -07003417 if (fbcon_has_exited)
3418 return 0;
3419
Torben Hohnac751ef2011-01-25 15:07:35 -08003420 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003421 idx = con2fb_map[fg_console];
3422
3423 if (idx == -1 || registered_fb[idx] == NULL)
3424 goto err;
3425
3426 info = registered_fb[idx];
3427 rotate = fbcon_get_rotate(info);
3428err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003429 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003430 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3431}
3432
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003433static ssize_t show_cursor_blink(struct device *device,
3434 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003435{
3436 struct fb_info *info;
3437 struct fbcon_ops *ops;
3438 int idx, blink = -1;
3439
3440 if (fbcon_has_exited)
3441 return 0;
3442
Torben Hohnac751ef2011-01-25 15:07:35 -08003443 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003444 idx = con2fb_map[fg_console];
3445
3446 if (idx == -1 || registered_fb[idx] == NULL)
3447 goto err;
3448
3449 info = registered_fb[idx];
3450 ops = info->fbcon_par;
3451
3452 if (!ops)
3453 goto err;
3454
3455 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3456err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003457 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003458 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3459}
3460
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003461static ssize_t store_cursor_blink(struct device *device,
3462 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003463 const char *buf, size_t count)
3464{
3465 struct fb_info *info;
3466 int blink, idx;
3467 char **last = NULL;
3468
3469 if (fbcon_has_exited)
3470 return count;
3471
Torben Hohnac751ef2011-01-25 15:07:35 -08003472 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003473 idx = con2fb_map[fg_console];
3474
3475 if (idx == -1 || registered_fb[idx] == NULL)
3476 goto err;
3477
3478 info = registered_fb[idx];
3479
3480 if (!info->fbcon_par)
3481 goto err;
3482
3483 blink = simple_strtoul(buf, last, 0);
3484
3485 if (blink) {
3486 fbcon_cursor_noblink = 0;
3487 fbcon_add_cursor_timer(info);
3488 } else {
3489 fbcon_cursor_noblink = 1;
3490 fbcon_del_cursor_timer(info);
3491 }
3492
3493err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003494 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003495 return count;
3496}
3497
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003498static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003499 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3500 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003501 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3502 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003503};
3504
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003505static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003506{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003507 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003508
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003509 fbcon_has_sysfs = 1;
3510
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003511 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3512 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003513
3514 if (error)
3515 break;
3516 }
3517
3518 if (error) {
3519 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003520 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003521
3522 fbcon_has_sysfs = 0;
3523 }
3524
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003525 return 0;
3526}
3527
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003528static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003531 int i;
3532
Torben Hohnac751ef2011-01-25 15:07:35 -08003533 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003534
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 for (i = 0; i < FB_MAX; i++) {
3536 if (registered_fb[i] != NULL) {
3537 info_idx = i;
3538 break;
3539 }
3540 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003541
Wang YanQinge57f35d2013-05-09 02:13:30 +08003542 do_fbcon_takeover(0);
Torben Hohnac751ef2011-01-25 15:07:35 -08003543 console_unlock();
Wang YanQinge57f35d2013-05-09 02:13:30 +08003544
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546}
3547
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003548static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003549{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003550 struct fb_info *info;
3551 int i, j, mapped;
3552
Antonino A. Daplase614b182006-06-26 00:27:09 -07003553 if (fbcon_has_exited)
3554 return;
3555
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003556 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003557 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003558
3559 for (i = 0; i < FB_MAX; i++) {
Jarek Poplawski142092e2010-09-22 13:05:05 -07003560 int pending = 0;
Geoff Levandbeaa4862008-12-09 13:14:17 -08003561
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003562 mapped = 0;
3563 info = registered_fb[i];
3564
3565 if (info == NULL)
3566 continue;
3567
Jarek Poplawski142092e2010-09-22 13:05:05 -07003568 if (info->queue.func)
3569 pending = cancel_work_sync(&info->queue);
Geoff Levandbeaa4862008-12-09 13:14:17 -08003570 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3571 "no"));
3572
Antonino A. Daplase614b182006-06-26 00:27:09 -07003573 for (j = first_fb_vc; j <= last_fb_vc; j++) {
Wang YanQing5aa133d2013-12-27 10:39:18 +08003574 if (con2fb_map[j] == i) {
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003575 mapped = 1;
Wang YanQing5aa133d2013-12-27 10:39:18 +08003576 break;
3577 }
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003578 }
3579
3580 if (mapped) {
3581 if (info->fbops->fb_release)
3582 info->fbops->fb_release(info, 0);
3583 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003584
3585 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003586 struct fbcon_ops *ops = info->fbcon_par;
3587
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003588 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003589 kfree(ops->cursor_src);
Masami Ichikawa46862142013-12-25 23:47:37 +09003590 kfree(ops->cursor_state.mask);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003591 kfree(info->fbcon_par);
3592 info->fbcon_par = NULL;
3593 }
3594
3595 if (info->queue.func == fb_flashcursor)
3596 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003597 }
3598 }
3599
Antonino A. Daplase614b182006-06-26 00:27:09 -07003600 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003601}
3602
3603static int __init fb_console_init(void)
3604{
3605 int i;
3606
Torben Hohnac751ef2011-01-25 15:07:35 -08003607 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003608 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003609 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3610 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003611
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003612 if (IS_ERR(fbcon_device)) {
3613 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003614 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003615 PTR_ERR(fbcon_device));
3616 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003617 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003618 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003619
3620 for (i = 0; i < MAX_NR_CONSOLES; i++)
3621 con2fb_map[i] = -1;
3622
Torben Hohnac751ef2011-01-25 15:07:35 -08003623 console_unlock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003624 fbcon_start();
3625 return 0;
3626}
3627
Hans de Goedeba168a32014-11-14 13:26:54 +01003628fs_initcall(fb_console_init);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003629
3630#ifdef MODULE
3631
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003632static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003633{
3634 int i;
3635
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003636 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003637 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3638 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003639
3640 fbcon_has_sysfs = 0;
3641 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003642}
3643
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644static void __exit fb_console_exit(void)
3645{
Torben Hohnac751ef2011-01-25 15:07:35 -08003646 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003648 fbcon_deinit_device();
3649 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003650 fbcon_exit();
Wang YanQing70125e72013-05-09 02:14:39 +08003651 do_unregister_con_driver(&fb_con);
Torben Hohnac751ef2011-01-25 15:07:35 -08003652 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003653}
3654
3655module_exit(fb_console_exit);
3656
3657#endif
3658
3659MODULE_LICENSE("GPL");