blob: 4db10d7990c98554acf3d15f8b52e1a0c3026d01 [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);
Jiri Slaby709280d2016-06-23 13:34:27 +0200173static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175/*
176 * Internal routines
177 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static __inline__ void ywrap_up(struct vc_data *vc, int count);
179static __inline__ void ywrap_down(struct vc_data *vc, int count);
180static __inline__ void ypan_up(struct vc_data *vc, int count);
181static __inline__ void ypan_down(struct vc_data *vc, int count);
182static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
183 int dy, int dx, int height, int width, u_int y_break);
184static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700185 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
187 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800188static void fbcon_modechanged(struct fb_info *info);
189static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700190static void fbcon_start(void);
191static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700192static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700193
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800194#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800195static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800196{
197 struct fbcon_ops *ops = info->fbcon_par;
198
199 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800200 ops->p->con_rotate < 4)
201 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800202 else
203 ops->rotate = 0;
204}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800205
206static void fbcon_rotate(struct fb_info *info, u32 rotate)
207{
208 struct fbcon_ops *ops= info->fbcon_par;
209 struct fb_info *fb_info;
210
211 if (!ops || ops->currcon == -1)
212 return;
213
214 fb_info = registered_fb[con2fb_map[ops->currcon]];
215
216 if (info == fb_info) {
217 struct display *p = &fb_display[ops->currcon];
218
219 if (rotate < 4)
220 p->con_rotate = rotate;
221 else
222 p->con_rotate = 0;
223
224 fbcon_modechanged(info);
225 }
226}
227
228static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
229{
230 struct fbcon_ops *ops = info->fbcon_par;
231 struct vc_data *vc;
232 struct display *p;
233 int i;
234
235 if (!ops || ops->currcon < 0 || rotate > 3)
236 return;
237
Antonino A. Daplase614b182006-06-26 00:27:09 -0700238 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800239 vc = vc_cons[i].d;
240 if (!vc || vc->vc_mode != KD_TEXT ||
241 registered_fb[con2fb_map[i]] != info)
242 continue;
243
244 p = &fb_display[vc->vc_num];
245 p->con_rotate = rotate;
246 }
247
248 fbcon_set_all_vcs(info);
249}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800250#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800251static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800252{
253 struct fbcon_ops *ops = info->fbcon_par;
254
255 ops->rotate = FB_ROTATE_UR;
256}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800257
258static void fbcon_rotate(struct fb_info *info, u32 rotate)
259{
260 return;
261}
262
263static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
264{
265 return;
266}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800267#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800268
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800269static int fbcon_get_rotate(struct fb_info *info)
270{
271 struct fbcon_ops *ops = info->fbcon_par;
272
273 return (ops) ? ops->rotate : 0;
274}
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
277{
278 struct fbcon_ops *ops = info->fbcon_par;
279
280 return (info->state != FBINFO_STATE_RUNNING ||
Jesse Barnes8fd4bd22010-06-23 12:56:12 -0700281 vc->vc_mode != KD_TEXT || ops->graphics) &&
282 !vt_force_oops_output(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Denys Vlasenkoda909ce2010-08-10 18:02:29 -0700285static int get_color(struct vc_data *vc, struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 u16 c, int is_fg)
287{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700288 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 int color = 0;
290
291 if (console_blanked) {
292 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
293
294 c = vc->vc_video_erase_char & charmask;
295 }
296
297 if (depth != 1)
298 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
299 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
300
301 switch (depth) {
302 case 1:
303 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800304 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700306 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
307 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 if (console_blanked)
310 fg = bg;
311
312 color = (is_fg) ? fg : bg;
313 break;
314 }
315 case 2:
316 /*
317 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700318 * is grayscale. However, simply dividing the values by 4
319 * will not work, as colors 1, 2 and 3 will be scaled-down
320 * to zero rendering them invisible. So empirically convert
321 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700323 switch (color) {
324 case 0:
325 color = 0; /* black */
326 break;
327 case 1 ... 6:
328 color = 2; /* white */
329 break;
330 case 7 ... 8:
331 color = 1; /* gray */
332 break;
333 default:
334 color = 3; /* intense white */
335 break;
336 }
337 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 case 3:
339 /*
340 * Last 8 entries of default 16-color palette is a more intense
341 * version of the first 8 (i.e., same chrominance, different
342 * luminance).
343 */
344 color &= 7;
345 break;
346 }
347
348
349 return color;
350}
351
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800352static void fbcon_update_softback(struct vc_data *vc)
353{
354 int l = fbcon_softback_size / vc->vc_size_row;
355
356 if (l > 5)
357 softback_end = softback_buf + l * vc->vc_size_row;
358 else
359 /* Smaller scrollback makes no sense, and 0 would screw
360 the operation totally */
361 softback_top = 0;
362}
363
David Howellsc4028952006-11-22 14:57:56 +0000364static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365{
David Howellsc4028952006-11-22 14:57:56 +0000366 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 struct vc_data *vc = NULL;
369 int c;
370 int mode;
Dave Airlied8636a22012-08-21 16:29:47 +1000371 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Dave Airlied8636a22012-08-21 16:29:47 +1000373 /* FIXME: we should sort out the unbind locking instead */
374 /* instead we just fail to flash the cursor if we can't get
375 * the lock instead of blocking fbcon deinit */
376 ret = console_trylock();
377 if (ret == 0)
378 return;
379
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700380 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 vc = vc_cons[ops->currcon].d;
382
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +0200383 if (!vc || !con_is_visible(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700384 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700385 vc->vc_deccm != 1) {
Torben Hohnac751ef2011-01-25 15:07:35 -0800386 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700388 }
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 c = scr_readw((u16 *) vc->vc_pos);
391 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
392 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800393 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 get_color(vc, info, c, 0));
Torben Hohnac751ef2011-01-25 15:07:35 -0800395 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398static void cursor_timer_handler(unsigned long dev_addr)
399{
400 struct fb_info *info = (struct fb_info *) dev_addr;
401 struct fbcon_ops *ops = info->fbcon_par;
402
Viresh Kumara85f1a42013-04-24 17:12:57 +0530403 queue_work(system_power_efficient_wq, &info->queue);
Scot Doyle27a4c822015-03-26 13:56:38 +0000404 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700407static void fbcon_add_cursor_timer(struct fb_info *info)
408{
409 struct fbcon_ops *ops = info->fbcon_par;
410
411 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700412 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
413 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700414 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000415 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700416
417 init_timer(&ops->cursor_timer);
418 ops->cursor_timer.function = cursor_timer_handler;
Scot Doyle27a4c822015-03-26 13:56:38 +0000419 ops->cursor_timer.expires = jiffies + ops->cur_blink_jiffies;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700420 ops->cursor_timer.data = (unsigned long ) info;
421 add_timer(&ops->cursor_timer);
422 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
423 }
424}
425
426static void fbcon_del_cursor_timer(struct fb_info *info)
427{
428 struct fbcon_ops *ops = info->fbcon_par;
429
430 if (info->queue.func == fb_flashcursor &&
431 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
432 del_timer_sync(&ops->cursor_timer);
433 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
434 }
435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#ifndef MODULE
438static int __init fb_console_setup(char *this_opt)
439{
440 char *options;
441 int i, j;
442
443 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800444 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 while ((options = strsep(&this_opt, ",")) != NULL) {
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200447 if (!strncmp(options, "font:", 5)) {
Paul Cercueile4329642012-07-24 03:00:24 +0200448 strlcpy(fontname, options + 5, sizeof(fontname));
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200449 continue;
450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 if (!strncmp(options, "scrollback:", 11)) {
453 options += 11;
454 if (*options) {
455 fbcon_softback_size = simple_strtoul(options, &options, 0);
456 if (*options == 'k' || *options == 'K') {
457 fbcon_softback_size *= 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200459 }
460 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 if (!strncmp(options, "map:", 4)) {
464 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700465 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
467 if (!options[j])
468 j = 0;
469 con2fb_map_boot[i] =
470 (options[j++]-'0') % FB_MAX;
471 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700472
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700473 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700474 }
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200475 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477
478 if (!strncmp(options, "vc:", 3)) {
479 options += 3;
480 if (*options)
481 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
482 if (first_fb_vc < 0)
483 first_fb_vc = 0;
484 if (*options++ == '-')
485 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
486 fbcon_is_default = 0;
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200487 continue;
488 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800489
490 if (!strncmp(options, "rotate:", 7)) {
491 options += 7;
492 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800493 initial_rotation = simple_strtoul(options, &options, 0);
494 if (initial_rotation > 3)
495 initial_rotation = 0;
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200496 continue;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800499 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500}
501
502__setup("fbcon=", fb_console_setup);
503#endif
504
505static int search_fb_in_map(int idx)
506{
507 int i, retval = 0;
508
Antonino A. Daplase614b182006-06-26 00:27:09 -0700509 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if (con2fb_map[i] == idx)
511 retval = 1;
512 }
513 return retval;
514}
515
516static int search_for_mapped_con(void)
517{
518 int i, retval = 0;
519
Antonino A. Daplase614b182006-06-26 00:27:09 -0700520 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (con2fb_map[i] != -1)
522 retval = 1;
523 }
524 return retval;
525}
526
Alan Cox50e244c2013-01-25 10:28:15 +1000527static int do_fbcon_takeover(int show_logo)
528{
529 int err, i;
530
531 if (!num_registered_fb)
532 return -ENODEV;
533
534 if (!show_logo)
535 logo_shown = FBCON_LOGO_DONTSHOW;
536
537 for (i = first_fb_vc; i <= last_fb_vc; i++)
538 con2fb_map[i] = info_idx;
539
540 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
541 fbcon_is_default);
542
543 if (err) {
544 for (i = first_fb_vc; i <= last_fb_vc; i++)
545 con2fb_map[i] = -1;
546 info_idx = -1;
547 } else {
548 fbcon_has_console_bind = 1;
549 }
550
551 return err;
552}
553
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700554#ifdef MODULE
555static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
556 int cols, int rows, int new_cols, int new_rows)
557{
558 logo_shown = FBCON_LOGO_DONTSHOW;
559}
560#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
562 int cols, int rows, int new_cols, int new_rows)
563{
564 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800565 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 int cnt, erase = vc->vc_video_erase_char, step;
567 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700568 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700570 if (info->flags & FBINFO_MODULE) {
571 logo_shown = FBCON_LOGO_DONTSHOW;
572 return;
573 }
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /*
576 * remove underline attribute from erase character
577 * if black and white framebuffer.
578 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700579 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800581 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700582 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 q = (unsigned short *) (vc->vc_origin +
584 vc->vc_size_row * rows);
585 step = logo_lines * cols;
586 for (r = q - logo_lines * cols; r < q; r++)
587 if (scr_readw(r) != vc->vc_video_erase_char)
588 break;
589 if (r != q && new_rows >= rows + logo_lines) {
590 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
591 if (save) {
592 int i = cols < new_cols ? cols : new_cols;
593 scr_memsetw(save, erase, logo_lines * new_cols * 2);
594 r = q - step;
595 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
596 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
597 r = q;
598 }
599 }
600 if (r == q) {
601 /* We can scroll screen down */
602 r = q - step - cols;
603 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
604 scr_memcpyw(r + step, r, vc->vc_size_row);
605 r -= cols;
606 }
607 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700608 int lines;
609 if (vc->vc_y + logo_lines >= rows)
610 lines = rows - vc->vc_y - 1;
611 else
612 lines = logo_lines;
613 vc->vc_y += lines;
614 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616 }
617 scr_memsetw((unsigned short *) vc->vc_origin,
618 erase,
619 vc->vc_size_row * logo_lines);
620
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +0200621 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 fbcon_clear_margins(vc, 0);
623 update_screen(vc);
624 }
625
626 if (save) {
627 q = (unsigned short *) (vc->vc_origin +
628 vc->vc_size_row *
629 rows);
630 scr_memcpyw(q, save, logo_lines * new_cols * 2);
631 vc->vc_y += logo_lines;
632 vc->vc_pos += logo_lines * vc->vc_size_row;
633 kfree(save);
634 }
635
636 if (logo_lines > vc->vc_bottom) {
637 logo_shown = FBCON_LOGO_CANSHOW;
638 printk(KERN_INFO
639 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
640 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
641 logo_shown = FBCON_LOGO_DRAW;
642 vc->vc_top = logo_lines;
643 }
644}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700645#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
647#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800648static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
650 struct fbcon_ops *ops = info->fbcon_par;
651
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800652 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800655 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800656 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800657 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700661
662static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
663{
664 int err = 0;
665
666 if (info->flags & FBINFO_MISC_TILEBLITTING &&
667 info->tileops->fb_get_tilemax(info) < charcount)
668 err = 1;
669
670 return err;
671}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800673static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
675 struct fbcon_ops *ops = info->fbcon_par;
676
677 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800678 ops->p = &fb_display[vc->vc_num];
679 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 fbcon_set_bitops(ops);
681}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700682
683static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
684{
685 return 0;
686}
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688#endif /* CONFIG_MISC_TILEBLITTING */
689
690
691static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
692 int unit, int oldidx)
693{
694 struct fbcon_ops *ops = NULL;
695 int err = 0;
696
697 if (!try_module_get(info->fbops->owner))
698 err = -ENODEV;
699
700 if (!err && info->fbops->fb_open &&
701 info->fbops->fb_open(info, 0))
702 err = -ENODEV;
703
704 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800705 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 if (!ops)
707 err = -ENOMEM;
708 }
709
710 if (!err) {
Jean-Philippe Bruckera1e533e2016-02-15 18:41:33 +0000711 ops->cur_blink_jiffies = HZ / 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700713
714 if (vc)
715 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
718 if (err) {
719 con2fb_map[unit] = oldidx;
720 module_put(info->fbops->owner);
721 }
722
723 return err;
724}
725
726static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
727 struct fb_info *newinfo, int unit,
728 int oldidx, int found)
729{
730 struct fbcon_ops *ops = oldinfo->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700731 int err = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 if (oldinfo->fbops->fb_release &&
734 oldinfo->fbops->fb_release(oldinfo, 0)) {
735 con2fb_map[unit] = oldidx;
736 if (!found && newinfo->fbops->fb_release)
737 newinfo->fbops->fb_release(newinfo, 0);
738 if (!found)
739 module_put(newinfo->fbops->owner);
740 err = -ENODEV;
741 }
742
743 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700744 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 kfree(ops->cursor_state.mask);
746 kfree(ops->cursor_data);
Masami Ichikawa7a966fb2014-04-23 23:35:22 +0900747 kfree(ops->cursor_src);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800748 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 kfree(oldinfo->fbcon_par);
750 oldinfo->fbcon_par = NULL;
751 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800752 /*
753 If oldinfo and newinfo are driving the same hardware,
754 the fb_release() method of oldinfo may attempt to
755 restore the hardware state. This will leave the
756 newinfo in an undefined state. Thus, a call to
757 fb_set_par() may be needed for the newinfo.
758 */
Keith Packard5f4dc282014-01-20 13:31:10 -0800759 if (newinfo && newinfo->fbops->fb_set_par) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700760 ret = newinfo->fbops->fb_set_par(newinfo);
761
762 if (ret)
763 printk(KERN_ERR "con2fb_release_oldinfo: "
764 "detected unhandled fb_set_par error, "
765 "error code %d\n", ret);
766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
769 return err;
770}
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
773 int unit, int show_logo)
774{
775 struct fbcon_ops *ops = info->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700776 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 ops->currcon = fg_console;
779
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700780 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
781 ret = info->fbops->fb_set_par(info);
782
783 if (ret)
784 printk(KERN_ERR "con2fb_init_display: detected "
785 "unhandled fb_set_par error, "
786 "error code %d\n", ret);
787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 ops->flags |= FBCON_FLAGS_INIT;
790 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700791 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 if (show_logo) {
794 struct vc_data *fg_vc = vc_cons[fg_console].d;
795 struct fb_info *fg_info =
796 registered_fb[con2fb_map[fg_console]];
797
798 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
799 fg_vc->vc_rows, fg_vc->vc_cols,
800 fg_vc->vc_rows);
801 }
802
803 update_screen(vc_cons[fg_console].d);
804}
805
806/**
807 * set_con2fb_map - map console to frame buffer device
808 * @unit: virtual console number to map
809 * @newidx: frame buffer index to map virtual console to
810 * @user: user request
811 *
812 * Maps a virtual console @unit to a frame buffer device
813 * @newidx.
Dave Airlie054430e2013-01-25 11:38:56 +1000814 *
815 * This should be called with the console lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 */
817static int set_con2fb_map(int unit, int newidx, int user)
818{
819 struct vc_data *vc = vc_cons[unit].d;
820 int oldidx = con2fb_map[unit];
821 struct fb_info *info = registered_fb[newidx];
822 struct fb_info *oldinfo = NULL;
823 int found, err = 0;
824
825 if (oldidx == newidx)
826 return 0;
827
Dave Airlie32b98bf2010-12-21 01:41:17 +0000828 if (!info)
Antonino A. Daplase614b182006-06-26 00:27:09 -0700829 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
Dave Airlie32b98bf2010-12-21 01:41:17 +0000831 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 info_idx = newidx;
Dave Airlie054430e2013-01-25 11:38:56 +1000833 return do_fbcon_takeover(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835
836 if (oldidx != -1)
837 oldinfo = registered_fb[oldidx];
838
839 found = search_fb_in_map(newidx);
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 con2fb_map[unit] = newidx;
842 if (!err && !found)
843 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
844
845
846 /*
847 * If old fb is not mapped to any of the consoles,
848 * fbcon should release it.
849 */
850 if (!err && oldinfo && !search_fb_in_map(oldidx))
851 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
852 found);
853
854 if (!err) {
855 int show_logo = (fg_console == 0 && !user &&
856 logo_shown != FBCON_LOGO_DONTSHOW);
857
858 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700859 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 con2fb_map_boot[unit] = newidx;
861 con2fb_init_display(vc, info, unit, show_logo);
862 }
863
Antonino A. Daplase614b182006-06-26 00:27:09 -0700864 if (!search_fb_in_map(info_idx))
865 info_idx = newidx;
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 return err;
868}
869
870/*
871 * Low Level Operations
872 */
Wang YanQing155957f2013-05-21 13:15:12 +0800873/* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874static int var_to_display(struct display *disp,
875 struct fb_var_screeninfo *var,
876 struct fb_info *info)
877{
878 disp->xres_virtual = var->xres_virtual;
879 disp->yres_virtual = var->yres_virtual;
880 disp->bits_per_pixel = var->bits_per_pixel;
881 disp->grayscale = var->grayscale;
882 disp->nonstd = var->nonstd;
883 disp->accel_flags = var->accel_flags;
884 disp->height = var->height;
885 disp->width = var->width;
886 disp->red = var->red;
887 disp->green = var->green;
888 disp->blue = var->blue;
889 disp->transp = var->transp;
890 disp->rotate = var->rotate;
891 disp->mode = fb_match_mode(var, &info->modelist);
892 if (disp->mode == NULL)
893 /* This should not happen */
894 return -EINVAL;
895 return 0;
896}
897
898static void display_to_var(struct fb_var_screeninfo *var,
899 struct display *disp)
900{
901 fb_videomode_to_var(var, disp->mode);
902 var->xres_virtual = disp->xres_virtual;
903 var->yres_virtual = disp->yres_virtual;
904 var->bits_per_pixel = disp->bits_per_pixel;
905 var->grayscale = disp->grayscale;
906 var->nonstd = disp->nonstd;
907 var->accel_flags = disp->accel_flags;
908 var->height = disp->height;
909 var->width = disp->width;
910 var->red = disp->red;
911 var->green = disp->green;
912 var->blue = disp->blue;
913 var->transp = disp->transp;
914 var->rotate = disp->rotate;
915}
916
917static const char *fbcon_startup(void)
918{
919 const char *display_desc = "frame buffer device";
920 struct display *p = &fb_display[fg_console];
921 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700922 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 struct module *owner;
924 struct fb_info *info = NULL;
925 struct fbcon_ops *ops;
926 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 /*
929 * If num_registered_fb is zero, this is a call for the dummy part.
930 * The frame buffer devices weren't initialized yet.
931 */
932 if (!num_registered_fb || info_idx == -1)
933 return display_desc;
934 /*
935 * Instead of blindly using registered_fb[0], we use info_idx, set by
936 * fb_console_init();
937 */
938 info = registered_fb[info_idx];
939 if (!info)
940 return NULL;
941
942 owner = info->fbops->owner;
943 if (!try_module_get(owner))
944 return NULL;
945 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
946 module_put(owner);
947 return NULL;
948 }
949
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800950 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 if (!ops) {
952 module_put(owner);
953 return NULL;
954 }
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 ops->currcon = -1;
957 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800958 ops->cur_rotate = -1;
Jean-Philippe Bruckera1e533e2016-02-15 18:41:33 +0000959 ops->cur_blink_jiffies = HZ / 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800961 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800962 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 if (info->fix.type != FB_TYPE_TEXT) {
965 if (fbcon_softback_size) {
966 if (!softback_buf) {
967 softback_buf =
968 (unsigned long)
969 kmalloc(fbcon_softback_size,
970 GFP_KERNEL);
971 if (!softback_buf) {
972 fbcon_softback_size = 0;
973 softback_top = 0;
974 }
975 }
976 } else {
977 if (softback_buf) {
978 kfree((void *) softback_buf);
979 softback_buf = 0;
980 softback_top = 0;
981 }
982 }
983 if (softback_buf)
984 softback_in = softback_top = softback_curr =
985 softback_buf;
986 softback_lines = 0;
987 }
988
989 /* Setup default font */
Dave Airlieae128782013-01-24 16:12:41 +1000990 if (!p->fontdata && !vc->vc_font.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (!fontname[0] || !(font = find_font(fontname)))
992 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700993 info->var.yres,
994 info->pixmap.blit_x,
995 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 vc->vc_font.width = font->width;
997 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700998 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
Dave Airlieae128782013-01-24 16:12:41 +10001000 } else {
1001 p->fontdata = vc->vc_font.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 }
1003
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001004 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1005 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1006 cols /= vc->vc_font.width;
1007 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 vc_resize(vc, cols, rows);
1009
1010 DPRINTK("mode: %s\n", info->fix.id);
1011 DPRINTK("visual: %d\n", info->fix.visual);
1012 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1013 info->var.yres,
1014 info->var.bits_per_pixel);
1015
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001016 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001017 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 return display_desc;
1019}
1020
1021static void fbcon_init(struct vc_data *vc, int init)
1022{
1023 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1024 struct fbcon_ops *ops;
1025 struct vc_data **default_mode = vc->vc_display_fg;
1026 struct vc_data *svc = *default_mode;
1027 struct display *t, *p = &fb_display[vc->vc_num];
1028 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001029 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 if (info_idx == -1 || info == NULL)
1032 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001033
1034 cap = info->flags;
1035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1037 (info->fix.type == FB_TYPE_TEXT))
1038 logo = 0;
1039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 if (var_to_display(p, &info->var, info))
1041 return;
1042
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001043 if (!info->fbcon_par)
1044 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 /* If we are not the first console on this
1047 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001048 t = &fb_display[fg_console];
1049 if (!p->fontdata) {
1050 if (t->fontdata) {
1051 struct vc_data *fvc = vc_cons[fg_console].d;
1052
1053 vc->vc_font.data = (void *)(p->fontdata =
1054 fvc->vc_font.data);
1055 vc->vc_font.width = fvc->vc_font.width;
1056 vc->vc_font.height = fvc->vc_font.height;
1057 p->userfont = t->userfont;
1058
1059 if (p->userfont)
1060 REFCOUNT(p->fontdata)++;
1061 } else {
1062 const struct font_desc *font = NULL;
1063
1064 if (!fontname[0] || !(font = find_font(fontname)))
1065 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001066 info->var.yres,
1067 info->pixmap.blit_x,
1068 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001069 vc->vc_font.width = font->width;
1070 vc->vc_font.height = font->height;
1071 vc->vc_font.data = (void *)(p->fontdata = font->data);
1072 vc->vc_font.charcount = 256; /* FIXME Need to
1073 support more fonts */
1074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001076
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 if (p->userfont)
1078 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001079
Jesse Barnes8fd4bd22010-06-23 12:56:12 -07001080 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001081 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1083 if (charcnt == 256) {
1084 vc->vc_hi_font_mask = 0;
1085 } else {
1086 vc->vc_hi_font_mask = 0x100;
1087 if (vc->vc_can_do_color)
1088 vc->vc_complement_mask <<= 1;
1089 }
1090
1091 if (!*svc->vc_uni_pagedir_loc)
1092 con_set_default_unimap(svc);
1093 if (!*vc->vc_uni_pagedir_loc)
1094 con_copy_unimap(vc, svc);
1095
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001096 ops = info->fbcon_par;
Scot Doylef235f662015-10-09 15:08:10 +00001097 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
Marcin Slusarz2428e592008-02-06 01:39:14 -08001098 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001099 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 cols = vc->vc_cols;
1102 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001103 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1104 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1105 new_cols /= vc->vc_font.width;
1106 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 /*
1109 * We must always set the mode. The mode of the previous console
1110 * driver could be in the same resolution but we are using different
1111 * hardware so we have to initialize the hardware.
1112 *
1113 * We need to do it in fbcon_init() to prevent screen corruption.
1114 */
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02001115 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001117 !(ops->flags & FBCON_FLAGS_INIT)) {
1118 ret = info->fbops->fb_set_par(info);
1119
1120 if (ret)
1121 printk(KERN_ERR "fbcon_init: detected "
1122 "unhandled fb_set_par error, "
1123 "error code %d\n", ret);
1124 }
1125
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 ops->flags |= FBCON_FLAGS_INIT;
1127 }
1128
1129 ops->graphics = 0;
1130
1131 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1132 !(cap & FBINFO_HWACCEL_DISABLED))
1133 p->scrollmode = SCROLL_MOVE;
1134 else /* default to something safe */
1135 p->scrollmode = SCROLL_REDRAW;
1136
1137 /*
1138 * ++guenther: console.c:vc_allocate() relies on initializing
1139 * vc_{cols,rows}, but we must not set those if we are only
1140 * resizing the console.
1141 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001142 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 vc->vc_cols = new_cols;
1144 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001145 } else
1146 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 if (logo)
1149 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1150
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001151 if (vc == svc && softback_buf)
1152 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001153
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001154 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001155 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001156 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001157 }
1158
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001159 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Dave Airlieae128782013-01-24 16:12:41 +10001162static void fbcon_free_font(struct display *p, bool freefont)
Antonino A. Daplase614b182006-06-26 00:27:09 -07001163{
Dave Airlieae128782013-01-24 16:12:41 +10001164 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001165 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1166 p->fontdata = NULL;
1167 p->userfont = 0;
1168}
1169
Takashi Iwai3fd37722017-01-11 17:09:50 +01001170static void set_vc_hi_font(struct vc_data *vc, bool set);
1171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172static void fbcon_deinit(struct vc_data *vc)
1173{
1174 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001175 struct fb_info *info;
1176 struct fbcon_ops *ops;
1177 int idx;
Dave Airlieae128782013-01-24 16:12:41 +10001178 bool free_font = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Antonino A. Daplase614b182006-06-26 00:27:09 -07001180 idx = con2fb_map[vc->vc_num];
1181
1182 if (idx == -1)
1183 goto finished;
1184
1185 info = registered_fb[idx];
1186
1187 if (!info)
1188 goto finished;
1189
Dave Airlieae128782013-01-24 16:12:41 +10001190 if (info->flags & FBINFO_MISC_FIRMWARE)
1191 free_font = false;
Antonino A. Daplase614b182006-06-26 00:27:09 -07001192 ops = info->fbcon_par;
1193
1194 if (!ops)
1195 goto finished;
1196
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02001197 if (con_is_visible(vc))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001198 fbcon_del_cursor_timer(info);
1199
1200 ops->flags &= ~FBCON_FLAGS_INIT;
1201finished:
1202
Dave Airlieae128782013-01-24 16:12:41 +10001203 fbcon_free_font(p, free_font);
Mika Kuoppalae6637d52013-04-22 14:19:26 +03001204 if (free_font)
1205 vc->vc_font.data = NULL;
Dave Airlieae128782013-01-24 16:12:41 +10001206
Takashi Iwai3fd37722017-01-11 17:09:50 +01001207 if (vc->vc_hi_font_mask)
1208 set_vc_hi_font(vc, false);
1209
Antonino A. Daplase614b182006-06-26 00:27:09 -07001210 if (!con_is_bound(&fb_con))
1211 fbcon_exit();
1212
1213 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
1216/* ====================================================================== */
1217
1218/* fbcon_XXX routines - interface used by the world
1219 *
1220 * This system is now divided into two levels because of complications
1221 * caused by hardware scrolling. Top level functions:
1222 *
1223 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1224 *
1225 * handles y values in range [0, scr_height-1] that correspond to real
1226 * screen positions. y_wrap shift means that first line of bitmap may be
1227 * anywhere on this display. These functions convert lineoffsets to
1228 * bitmap offsets and deal with the wrap-around case by splitting blits.
1229 *
1230 * fbcon_bmove_physical_8() -- These functions fast implementations
1231 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1232 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1233 *
1234 * WARNING:
1235 *
1236 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1237 * Implies should only really hardware scroll in rows. Only reason for
1238 * restriction is simplicity & efficiency at the moment.
1239 */
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1242 int width)
1243{
1244 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1245 struct fbcon_ops *ops = info->fbcon_par;
1246
1247 struct display *p = &fb_display[vc->vc_num];
1248 u_int y_break;
1249
1250 if (fbcon_is_inactive(vc, info))
1251 return;
1252
1253 if (!height || !width)
1254 return;
1255
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001256 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001257 vc->vc_top = 0;
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001258 /*
1259 * If the font dimensions are not an integral of the display
1260 * dimensions then the ops->clear below won't end up clearing
1261 * the margins. Call clear_margins here in case the logo
1262 * bitmap stretched into the margin area.
1263 */
1264 fbcon_clear_margins(vc, 0);
1265 }
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 /* Split blits that cross physical y_wrap boundary */
1268
1269 y_break = p->vrows - p->yscroll;
1270 if (sy < y_break && sy + height - 1 >= y_break) {
1271 u_int b = y_break - sy;
1272 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1273 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1274 width);
1275 } else
1276 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1277}
1278
1279static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1280 int count, int ypos, int xpos)
1281{
1282 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1283 struct display *p = &fb_display[vc->vc_num];
1284 struct fbcon_ops *ops = info->fbcon_par;
1285
1286 if (!fbcon_is_inactive(vc, info))
1287 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1288 get_color(vc, info, scr_readw(s), 1),
1289 get_color(vc, info, scr_readw(s), 0));
1290}
1291
1292static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1293{
1294 unsigned short chr;
1295
1296 scr_writew(c, &chr);
1297 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1298}
1299
1300static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1301{
1302 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1303 struct fbcon_ops *ops = info->fbcon_par;
1304
1305 if (!fbcon_is_inactive(vc, info))
1306 ops->clear_margins(vc, info, bottom_only);
1307}
1308
1309static void fbcon_cursor(struct vc_data *vc, int mode)
1310{
1311 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1312 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 int y;
1314 int c = scr_readw((u16 *) vc->vc_pos);
1315
Scot Doyle2a17d7e2015-08-04 12:33:32 +00001316 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1317
Michal Januszewskid1e23062007-05-08 00:38:07 -07001318 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 return;
1320
Thierry Redinga5edce42015-05-21 09:58:03 +02001321 if (vc->vc_cursor_type & 0x10)
1322 fbcon_del_cursor_timer(info);
1323 else
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001324 fbcon_add_cursor_timer(info);
1325
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1327 if (mode & CM_SOFTBACK) {
1328 mode &= ~CM_SOFTBACK;
1329 y = softback_lines;
1330 } else {
1331 if (softback_lines)
1332 fbcon_set_origin(vc);
1333 y = 0;
1334 }
1335
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001336 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 get_color(vc, info, c, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
1340static int scrollback_phys_max = 0;
1341static int scrollback_max = 0;
1342static int scrollback_current = 0;
1343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001345 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001347 struct display *p, *t;
1348 struct vc_data **default_mode, *vc;
1349 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001350 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 int rows, cols, charcnt = 256;
1352
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001353 p = &fb_display[unit];
1354
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 if (var_to_display(p, var, info))
1356 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001357
1358 vc = vc_cons[unit].d;
1359
1360 if (!vc)
1361 return;
1362
1363 default_mode = vc->vc_display_fg;
1364 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001368 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 vc->vc_font.width = (*default_mode)->vc_font.width;
1370 vc->vc_font.height = (*default_mode)->vc_font.height;
1371 p->userfont = t->userfont;
1372 if (p->userfont)
1373 REFCOUNT(p->fontdata)++;
1374 }
1375 if (p->userfont)
1376 charcnt = FNTCHARCNT(p->fontdata);
1377
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001378 var->activate = FB_ACTIVATE_NOW;
1379 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001380 var->yoffset = info->var.yoffset;
1381 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001382 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001383 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001384 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1386 if (charcnt == 256) {
1387 vc->vc_hi_font_mask = 0;
1388 } else {
1389 vc->vc_hi_font_mask = 0x100;
1390 if (vc->vc_can_do_color)
1391 vc->vc_complement_mask <<= 1;
1392 }
1393
1394 if (!*svc->vc_uni_pagedir_loc)
1395 con_set_default_unimap(svc);
1396 if (!*vc->vc_uni_pagedir_loc)
1397 con_copy_unimap(vc, svc);
1398
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001399 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1400 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1401 cols /= vc->vc_font.width;
1402 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001404
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02001405 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001407 if (softback_buf)
1408 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 }
1410}
1411
1412static __inline__ void ywrap_up(struct vc_data *vc, int count)
1413{
1414 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001415 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 struct display *p = &fb_display[vc->vc_num];
1417
1418 p->yscroll += count;
1419 if (p->yscroll >= p->vrows) /* Deal with wrap */
1420 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001421 ops->var.xoffset = 0;
1422 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1423 ops->var.vmode |= FB_VMODE_YWRAP;
1424 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 scrollback_max += count;
1426 if (scrollback_max > scrollback_phys_max)
1427 scrollback_max = scrollback_phys_max;
1428 scrollback_current = 0;
1429}
1430
1431static __inline__ void ywrap_down(struct vc_data *vc, int count)
1432{
1433 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001434 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 struct display *p = &fb_display[vc->vc_num];
1436
1437 p->yscroll -= count;
1438 if (p->yscroll < 0) /* Deal with wrap */
1439 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001440 ops->var.xoffset = 0;
1441 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1442 ops->var.vmode |= FB_VMODE_YWRAP;
1443 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 scrollback_max -= count;
1445 if (scrollback_max < 0)
1446 scrollback_max = 0;
1447 scrollback_current = 0;
1448}
1449
1450static __inline__ void ypan_up(struct vc_data *vc, int count)
1451{
1452 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1453 struct display *p = &fb_display[vc->vc_num];
1454 struct fbcon_ops *ops = info->fbcon_par;
1455
1456 p->yscroll += count;
1457 if (p->yscroll > p->vrows - vc->vc_rows) {
1458 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1459 0, 0, 0, vc->vc_rows, vc->vc_cols);
1460 p->yscroll -= p->vrows - vc->vc_rows;
1461 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001462
1463 ops->var.xoffset = 0;
1464 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1465 ops->var.vmode &= ~FB_VMODE_YWRAP;
1466 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 fbcon_clear_margins(vc, 1);
1468 scrollback_max += count;
1469 if (scrollback_max > scrollback_phys_max)
1470 scrollback_max = scrollback_phys_max;
1471 scrollback_current = 0;
1472}
1473
1474static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1475{
1476 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001477 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 if (p->yscroll > p->vrows - vc->vc_rows) {
1483 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001485 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001486
1487 ops->var.xoffset = 0;
1488 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1489 ops->var.vmode &= ~FB_VMODE_YWRAP;
1490 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 fbcon_clear_margins(vc, 1);
1492 scrollback_max += count;
1493 if (scrollback_max > scrollback_phys_max)
1494 scrollback_max = scrollback_phys_max;
1495 scrollback_current = 0;
1496}
1497
1498static __inline__ void ypan_down(struct vc_data *vc, int count)
1499{
1500 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1501 struct display *p = &fb_display[vc->vc_num];
1502 struct fbcon_ops *ops = info->fbcon_par;
1503
1504 p->yscroll -= count;
1505 if (p->yscroll < 0) {
1506 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1507 0, vc->vc_rows, vc->vc_cols);
1508 p->yscroll += p->vrows - vc->vc_rows;
1509 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001510
1511 ops->var.xoffset = 0;
1512 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1513 ops->var.vmode &= ~FB_VMODE_YWRAP;
1514 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 fbcon_clear_margins(vc, 1);
1516 scrollback_max -= count;
1517 if (scrollback_max < 0)
1518 scrollback_max = 0;
1519 scrollback_current = 0;
1520}
1521
1522static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1523{
1524 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001525 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 if (p->yscroll < 0) {
1531 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001533 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001534
1535 ops->var.xoffset = 0;
1536 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1537 ops->var.vmode &= ~FB_VMODE_YWRAP;
1538 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 fbcon_clear_margins(vc, 1);
1540 scrollback_max -= count;
1541 if (scrollback_max < 0)
1542 scrollback_max = 0;
1543 scrollback_current = 0;
1544}
1545
1546static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1547 long delta)
1548{
1549 int count = vc->vc_rows;
1550 unsigned short *d, *s;
1551 unsigned long n;
1552 int line = 0;
1553
1554 d = (u16 *) softback_curr;
1555 if (d == (u16 *) softback_in)
1556 d = (u16 *) vc->vc_origin;
1557 n = softback_curr + delta * vc->vc_size_row;
1558 softback_lines -= delta;
1559 if (delta < 0) {
1560 if (softback_curr < softback_top && n < softback_buf) {
1561 n += softback_end - softback_buf;
1562 if (n < softback_top) {
1563 softback_lines -=
1564 (softback_top - n) / vc->vc_size_row;
1565 n = softback_top;
1566 }
1567 } else if (softback_curr >= softback_top
1568 && n < softback_top) {
1569 softback_lines -=
1570 (softback_top - n) / vc->vc_size_row;
1571 n = softback_top;
1572 }
1573 } else {
1574 if (softback_curr > softback_in && n >= softback_end) {
1575 n += softback_buf - softback_end;
1576 if (n > softback_in) {
1577 n = softback_in;
1578 softback_lines = 0;
1579 }
1580 } else if (softback_curr <= softback_in && n > softback_in) {
1581 n = softback_in;
1582 softback_lines = 0;
1583 }
1584 }
1585 if (n == softback_curr)
1586 return;
1587 softback_curr = n;
1588 s = (u16 *) softback_curr;
1589 if (s == (u16 *) softback_in)
1590 s = (u16 *) vc->vc_origin;
1591 while (count--) {
1592 unsigned short *start;
1593 unsigned short *le;
1594 unsigned short c;
1595 int x = 0;
1596 unsigned short attr = 1;
1597
1598 start = s;
1599 le = advance_row(s, 1);
1600 do {
1601 c = scr_readw(s);
1602 if (attr != (c & 0xff00)) {
1603 attr = c & 0xff00;
1604 if (s > start) {
1605 fbcon_putcs(vc, start, s - start,
1606 line, x);
1607 x += s - start;
1608 start = s;
1609 }
1610 }
1611 if (c == scr_readw(d)) {
1612 if (s > start) {
1613 fbcon_putcs(vc, start, s - start,
1614 line, x);
1615 x += s - start + 1;
1616 start = s + 1;
1617 } else {
1618 x++;
1619 start++;
1620 }
1621 }
1622 s++;
1623 d++;
1624 } while (s < le);
1625 if (s > start)
1626 fbcon_putcs(vc, start, s - start, line, x);
1627 line++;
1628 if (d == (u16 *) softback_end)
1629 d = (u16 *) softback_buf;
1630 if (d == (u16 *) softback_in)
1631 d = (u16 *) vc->vc_origin;
1632 if (s == (u16 *) softback_end)
1633 s = (u16 *) softback_buf;
1634 if (s == (u16 *) softback_in)
1635 s = (u16 *) vc->vc_origin;
1636 }
1637}
1638
1639static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1640 int line, int count, int dy)
1641{
1642 unsigned short *s = (unsigned short *)
1643 (vc->vc_origin + vc->vc_size_row * line);
1644
1645 while (count--) {
1646 unsigned short *start = s;
1647 unsigned short *le = advance_row(s, 1);
1648 unsigned short c;
1649 int x = 0;
1650 unsigned short attr = 1;
1651
1652 do {
1653 c = scr_readw(s);
1654 if (attr != (c & 0xff00)) {
1655 attr = c & 0xff00;
1656 if (s > start) {
1657 fbcon_putcs(vc, start, s - start,
1658 dy, x);
1659 x += s - start;
1660 start = s;
1661 }
1662 }
1663 console_conditional_schedule();
1664 s++;
1665 } while (s < le);
1666 if (s > start)
1667 fbcon_putcs(vc, start, s - start, dy, x);
1668 console_conditional_schedule();
1669 dy++;
1670 }
1671}
1672
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001673static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1674 struct display *p, int line, int count, int ycount)
1675{
1676 int offset = ycount * vc->vc_cols;
1677 unsigned short *d = (unsigned short *)
1678 (vc->vc_origin + vc->vc_size_row * line);
1679 unsigned short *s = d + offset;
1680 struct fbcon_ops *ops = info->fbcon_par;
1681
1682 while (count--) {
1683 unsigned short *start = s;
1684 unsigned short *le = advance_row(s, 1);
1685 unsigned short c;
1686 int x = 0;
1687
1688 do {
1689 c = scr_readw(s);
1690
1691 if (c == scr_readw(d)) {
1692 if (s > start) {
1693 ops->bmove(vc, info, line + ycount, x,
1694 line, x, 1, s-start);
1695 x += s - start + 1;
1696 start = s + 1;
1697 } else {
1698 x++;
1699 start++;
1700 }
1701 }
1702
1703 scr_writew(c, d);
1704 console_conditional_schedule();
1705 s++;
1706 d++;
1707 } while (s < le);
1708 if (s > start)
1709 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1710 s-start);
1711 console_conditional_schedule();
1712 if (ycount > 0)
1713 line++;
1714 else {
1715 line--;
1716 /* NOTE: We subtract two lines from these pointers */
1717 s -= vc->vc_size_row;
1718 d -= vc->vc_size_row;
1719 }
1720 }
1721}
1722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723static void fbcon_redraw(struct vc_data *vc, struct display *p,
1724 int line, int count, int offset)
1725{
1726 unsigned short *d = (unsigned short *)
1727 (vc->vc_origin + vc->vc_size_row * line);
1728 unsigned short *s = d + offset;
1729
1730 while (count--) {
1731 unsigned short *start = s;
1732 unsigned short *le = advance_row(s, 1);
1733 unsigned short c;
1734 int x = 0;
1735 unsigned short attr = 1;
1736
1737 do {
1738 c = scr_readw(s);
1739 if (attr != (c & 0xff00)) {
1740 attr = c & 0xff00;
1741 if (s > start) {
1742 fbcon_putcs(vc, start, s - start,
1743 line, x);
1744 x += s - start;
1745 start = s;
1746 }
1747 }
1748 if (c == scr_readw(d)) {
1749 if (s > start) {
1750 fbcon_putcs(vc, start, s - start,
1751 line, x);
1752 x += s - start + 1;
1753 start = s + 1;
1754 } else {
1755 x++;
1756 start++;
1757 }
1758 }
1759 scr_writew(c, d);
1760 console_conditional_schedule();
1761 s++;
1762 d++;
1763 } while (s < le);
1764 if (s > start)
1765 fbcon_putcs(vc, start, s - start, line, x);
1766 console_conditional_schedule();
1767 if (offset > 0)
1768 line++;
1769 else {
1770 line--;
1771 /* NOTE: We subtract two lines from these pointers */
1772 s -= vc->vc_size_row;
1773 d -= vc->vc_size_row;
1774 }
1775 }
1776}
1777
1778static inline void fbcon_softback_note(struct vc_data *vc, int t,
1779 int count)
1780{
1781 unsigned short *p;
1782
1783 if (vc->vc_num != fg_console)
1784 return;
1785 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1786
1787 while (count) {
1788 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1789 count--;
1790 p = advance_row(p, 1);
1791 softback_in += vc->vc_size_row;
1792 if (softback_in == softback_end)
1793 softback_in = softback_buf;
1794 if (softback_in == softback_top) {
1795 softback_top += vc->vc_size_row;
1796 if (softback_top == softback_end)
1797 softback_top = softback_buf;
1798 }
1799 }
1800 softback_curr = softback_in;
1801}
1802
1803static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1804 int count)
1805{
1806 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1807 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1809
1810 if (fbcon_is_inactive(vc, info))
1811 return -EINVAL;
1812
1813 fbcon_cursor(vc, CM_ERASE);
1814
1815 /*
1816 * ++Geert: Only use ywrap/ypan if the console is in text mode
1817 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1818 * whole screen (prevents flicker).
1819 */
1820
1821 switch (dir) {
1822 case SM_UP:
1823 if (count > vc->vc_rows) /* Maximum realistic size */
1824 count = vc->vc_rows;
1825 if (softback_top)
1826 fbcon_softback_note(vc, t, count);
1827 if (logo_shown >= 0)
1828 goto redraw_up;
1829 switch (p->scrollmode) {
1830 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001831 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1832 count);
1833 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1834 scr_memsetw((unsigned short *) (vc->vc_origin +
1835 vc->vc_size_row *
1836 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001837 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001838 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001839 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 break;
1841
1842 case SCROLL_WRAP_MOVE:
1843 if (b - t - count > 3 * vc->vc_rows >> 2) {
1844 if (t > 0)
1845 fbcon_bmove(vc, 0, 0, count, 0, t,
1846 vc->vc_cols);
1847 ywrap_up(vc, count);
1848 if (vc->vc_rows - b > 0)
1849 fbcon_bmove(vc, b - count, 0, b, 0,
1850 vc->vc_rows - b,
1851 vc->vc_cols);
1852 } else if (info->flags & FBINFO_READS_FAST)
1853 fbcon_bmove(vc, t + count, 0, t, 0,
1854 b - t - count, vc->vc_cols);
1855 else
1856 goto redraw_up;
1857 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1858 break;
1859
1860 case SCROLL_PAN_REDRAW:
1861 if ((p->yscroll + count <=
1862 2 * (p->vrows - vc->vc_rows))
1863 && ((!scroll_partial && (b - t == vc->vc_rows))
1864 || (scroll_partial
1865 && (b - t - count >
1866 3 * vc->vc_rows >> 2)))) {
1867 if (t > 0)
1868 fbcon_redraw_move(vc, p, 0, t, count);
1869 ypan_up_redraw(vc, t, count);
1870 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001871 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 vc->vc_rows - b, b);
1873 } else
1874 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1875 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1876 break;
1877
1878 case SCROLL_PAN_MOVE:
1879 if ((p->yscroll + count <=
1880 2 * (p->vrows - vc->vc_rows))
1881 && ((!scroll_partial && (b - t == vc->vc_rows))
1882 || (scroll_partial
1883 && (b - t - count >
1884 3 * vc->vc_rows >> 2)))) {
1885 if (t > 0)
1886 fbcon_bmove(vc, 0, 0, count, 0, t,
1887 vc->vc_cols);
1888 ypan_up(vc, count);
1889 if (vc->vc_rows - b > 0)
1890 fbcon_bmove(vc, b - count, 0, b, 0,
1891 vc->vc_rows - b,
1892 vc->vc_cols);
1893 } else if (info->flags & FBINFO_READS_FAST)
1894 fbcon_bmove(vc, t + count, 0, t, 0,
1895 b - t - count, vc->vc_cols);
1896 else
1897 goto redraw_up;
1898 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1899 break;
1900
1901 case SCROLL_REDRAW:
1902 redraw_up:
1903 fbcon_redraw(vc, p, t, b - t - count,
1904 count * vc->vc_cols);
1905 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1906 scr_memsetw((unsigned short *) (vc->vc_origin +
1907 vc->vc_size_row *
1908 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001909 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001911 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 }
1913 break;
1914
1915 case SM_DOWN:
1916 if (count > vc->vc_rows) /* Maximum realistic size */
1917 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001918 if (logo_shown >= 0)
1919 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 switch (p->scrollmode) {
1921 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001922 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1923 -count);
1924 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1925 scr_memsetw((unsigned short *) (vc->vc_origin +
1926 vc->vc_size_row *
1927 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001928 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001929 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07001930 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 break;
1932
1933 case SCROLL_WRAP_MOVE:
1934 if (b - t - count > 3 * vc->vc_rows >> 2) {
1935 if (vc->vc_rows - b > 0)
1936 fbcon_bmove(vc, b, 0, b - count, 0,
1937 vc->vc_rows - b,
1938 vc->vc_cols);
1939 ywrap_down(vc, count);
1940 if (t > 0)
1941 fbcon_bmove(vc, count, 0, 0, 0, t,
1942 vc->vc_cols);
1943 } else if (info->flags & FBINFO_READS_FAST)
1944 fbcon_bmove(vc, t, 0, t + count, 0,
1945 b - t - count, vc->vc_cols);
1946 else
1947 goto redraw_down;
1948 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1949 break;
1950
1951 case SCROLL_PAN_MOVE:
1952 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1953 && ((!scroll_partial && (b - t == vc->vc_rows))
1954 || (scroll_partial
1955 && (b - t - count >
1956 3 * vc->vc_rows >> 2)))) {
1957 if (vc->vc_rows - b > 0)
1958 fbcon_bmove(vc, b, 0, b - count, 0,
1959 vc->vc_rows - b,
1960 vc->vc_cols);
1961 ypan_down(vc, count);
1962 if (t > 0)
1963 fbcon_bmove(vc, count, 0, 0, 0, t,
1964 vc->vc_cols);
1965 } else if (info->flags & FBINFO_READS_FAST)
1966 fbcon_bmove(vc, t, 0, t + count, 0,
1967 b - t - count, vc->vc_cols);
1968 else
1969 goto redraw_down;
1970 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1971 break;
1972
1973 case SCROLL_PAN_REDRAW:
1974 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1975 && ((!scroll_partial && (b - t == vc->vc_rows))
1976 || (scroll_partial
1977 && (b - t - count >
1978 3 * vc->vc_rows >> 2)))) {
1979 if (vc->vc_rows - b > 0)
1980 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1981 b - count);
1982 ypan_down_redraw(vc, t, count);
1983 if (t > 0)
1984 fbcon_redraw_move(vc, p, count, t, 0);
1985 } else
1986 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1987 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1988 break;
1989
1990 case SCROLL_REDRAW:
1991 redraw_down:
1992 fbcon_redraw(vc, p, b - 1, b - t - count,
1993 -count * vc->vc_cols);
1994 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1995 scr_memsetw((unsigned short *) (vc->vc_origin +
1996 vc->vc_size_row *
1997 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001998 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 vc->vc_size_row * count);
Linus Torvalds93f78da2008-10-14 12:12:02 -07002000 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 }
2002 }
Linus Torvalds93f78da2008-10-14 12:12:02 -07002003 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004}
2005
2006
2007static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2008 int height, int width)
2009{
2010 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2011 struct display *p = &fb_display[vc->vc_num];
2012
2013 if (fbcon_is_inactive(vc, info))
2014 return;
2015
2016 if (!width || !height)
2017 return;
2018
2019 /* Split blits that cross physical y_wrap case.
2020 * Pathological case involves 4 blits, better to use recursive
2021 * code rather than unrolled case
2022 *
2023 * Recursive invocations don't need to erase the cursor over and
2024 * over again, so we use fbcon_bmove_rec()
2025 */
2026 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2027 p->vrows - p->yscroll);
2028}
2029
2030static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2031 int dy, int dx, int height, int width, u_int y_break)
2032{
2033 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2034 struct fbcon_ops *ops = info->fbcon_par;
2035 u_int b;
2036
2037 if (sy < y_break && sy + height > y_break) {
2038 b = y_break - sy;
2039 if (dy < sy) { /* Avoid trashing self */
2040 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2041 y_break);
2042 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2043 height - b, width, y_break);
2044 } else {
2045 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2046 height - b, width, y_break);
2047 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2048 y_break);
2049 }
2050 return;
2051 }
2052
2053 if (dy < y_break && dy + height > y_break) {
2054 b = y_break - dy;
2055 if (dy < sy) { /* Avoid trashing self */
2056 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2057 y_break);
2058 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2059 height - b, width, y_break);
2060 } else {
2061 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2062 height - b, width, y_break);
2063 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2064 y_break);
2065 }
2066 return;
2067 }
2068 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2069 height, width);
2070}
2071
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002072static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002073 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct vc_data *vc)
2075{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002076 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 int fh = vc->vc_font.height;
2078 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002079 u16 t = 0;
2080 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2081 info->fix.xpanstep);
2082 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2083 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2084 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2085 info->var.xres_virtual);
2086 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2087 divides(ypan, vc->vc_font.height) && vyres > yres;
2088 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2089 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002090 divides(vc->vc_font.height, vyres) &&
2091 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002093 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2094 !(cap & FBINFO_HWACCEL_DISABLED);
2095 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2096 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002098 p->vrows = vyres/fh;
2099 if (yres > (fh * (vc->vc_rows + 1)))
2100 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2101 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 p->vrows--;
2103
2104 if (good_wrap || good_pan) {
2105 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002106 p->scrollmode = good_wrap ?
2107 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 else
2109 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2110 SCROLL_PAN_REDRAW;
2111 } else {
2112 if (reading_fast || (fast_copyarea && !fast_imageblit))
2113 p->scrollmode = SCROLL_MOVE;
2114 else
2115 p->scrollmode = SCROLL_REDRAW;
2116 }
2117}
2118
2119static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002120 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
2122 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002123 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct display *p = &fb_display[vc->vc_num];
2125 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002126 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002128 virt_w = FBCON_SWAP(ops->rotate, width, height);
2129 virt_h = FBCON_SWAP(ops->rotate, height, width);
2130 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2131 vc->vc_font.height);
2132 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2133 vc->vc_font.width);
2134 var.xres = virt_w * virt_fw;
2135 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 x_diff = info->var.xres - var.xres;
2137 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002138 if (x_diff < 0 || x_diff > virt_fw ||
2139 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002140 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2143 mode = fb_find_best_mode(&var, &info->modelist);
2144 if (mode == NULL)
2145 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002146 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002148
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002149 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002153 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 var.activate = FB_ACTIVATE_NOW |
2155 FB_ACTIVATE_FORCE;
2156 fb_set_var(info, &var);
2157 }
2158 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002159 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 }
2161 updatescrollmode(p, info, vc);
2162 return 0;
2163}
2164
2165static int fbcon_switch(struct vc_data *vc)
2166{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002167 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002168 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct display *p = &fb_display[vc->vc_num];
2170 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002171 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002174 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 if (softback_lines)
2178 fbcon_set_origin(vc);
2179 softback_top = softback_curr = softback_in = softback_buf;
2180 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002181 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 }
2183
2184 if (logo_shown >= 0) {
2185 struct vc_data *conp2 = vc_cons[logo_shown].d;
2186
2187 if (conp2->vc_top == logo_lines
2188 && conp2->vc_bottom == conp2->vc_rows)
2189 conp2->vc_top = 0;
2190 logo_shown = FBCON_LOGO_CANSHOW;
2191 }
2192
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002193 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002194 if (prev_console != -1)
2195 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 /*
2197 * FIXME: If we have multiple fbdev's loaded, we need to
2198 * update all info->currcon. Perhaps, we can place this
2199 * in a centralized structure, but this might break some
2200 * drivers.
2201 *
2202 * info->currcon = vc->vc_num;
2203 */
2204 for (i = 0; i < FB_MAX; i++) {
2205 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002206 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002208 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 }
2210 }
2211 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2212 display_to_var(&var, p);
2213 var.activate = FB_ACTIVATE_NOW;
2214
2215 /*
2216 * make sure we don't unnecessarily trip the memcmp()
2217 * in fb_set_var()
2218 */
2219 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002220 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002222 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Knut Petersen39942fd2005-12-12 22:17:19 -08002224 if (old_info != NULL && (old_info != info ||
2225 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002226 if (info->fbops->fb_set_par) {
2227 ret = info->fbops->fb_set_par(info);
2228
2229 if (ret)
2230 printk(KERN_ERR "fbcon_switch: detected "
2231 "unhandled fb_set_par error, "
2232 "error code %d\n", ret);
2233 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002234
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002235 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002236 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002239 if (fbcon_is_inactive(vc, info) ||
2240 ops->blank_state != FB_BLANK_UNBLANK)
2241 fbcon_del_cursor_timer(info);
2242 else
2243 fbcon_add_cursor_timer(info);
2244
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002245 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002246 ops->cursor_reset = 1;
2247
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002248 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002249 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002250 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002251 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002253 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002255
2256 if (p->userfont)
2257 charcnt = FNTCHARCNT(vc->vc_font.data);
2258
2259 if (charcnt > 256)
2260 vc->vc_complement_mask <<= 1;
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 updatescrollmode(p, info, vc);
2263
2264 switch (p->scrollmode) {
2265 case SCROLL_WRAP_MOVE:
2266 scrollback_phys_max = p->vrows - vc->vc_rows;
2267 break;
2268 case SCROLL_PAN_MOVE:
2269 case SCROLL_PAN_REDRAW:
2270 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2271 if (scrollback_phys_max < 0)
2272 scrollback_phys_max = 0;
2273 break;
2274 default:
2275 scrollback_phys_max = 0;
2276 break;
2277 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 scrollback_max = 0;
2280 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002281
2282 if (!fbcon_is_inactive(vc, info)) {
2283 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2284 ops->update_start(info);
2285 }
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 fbcon_set_palette(vc, color_table);
2288 fbcon_clear_margins(vc, 0);
2289
2290 if (logo_shown == FBCON_LOGO_DRAW) {
2291
2292 logo_shown = fg_console;
2293 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002294 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 update_region(vc,
2296 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2297 vc->vc_size_row * (vc->vc_bottom -
2298 vc->vc_top) / 2);
2299 return 0;
2300 }
2301 return 1;
2302}
2303
2304static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2305 int blank)
2306{
Richard Purdie994efac2007-02-09 09:46:45 +00002307 struct fb_event event;
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 if (blank) {
2310 unsigned short charmask = vc->vc_hi_font_mask ?
2311 0x1ff : 0xff;
2312 unsigned short oldc;
2313
2314 oldc = vc->vc_video_erase_char;
2315 vc->vc_video_erase_char &= charmask;
2316 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2317 vc->vc_video_erase_char = oldc;
2318 }
Richard Purdie994efac2007-02-09 09:46:45 +00002319
2320
Andrea Righi513adb52009-04-13 14:39:39 -07002321 if (!lock_fb_info(info))
2322 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002323 event.info = info;
2324 event.data = &blank;
2325 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002326 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
2329static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2330{
2331 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2332 struct fbcon_ops *ops = info->fbcon_par;
2333
2334 if (mode_switch) {
2335 struct fb_var_screeninfo var = info->var;
2336
2337 ops->graphics = 1;
2338
2339 if (!blank) {
2340 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2341 fb_set_var(info, &var);
2342 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002343 ops->var = info->var;
Krzysztof Heltf5c15d02009-11-11 14:26:22 -08002344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 }
2346
2347 if (!fbcon_is_inactive(vc, info)) {
2348 if (ops->blank_state != blank) {
2349 ops->blank_state = blank;
2350 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2351 ops->cursor_flash = (!blank);
2352
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002353 if (!(info->flags & FBINFO_MISC_USEREVENT))
2354 if (fb_blank(info, blank))
2355 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 }
2357
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002358 if (!blank)
2359 update_screen(vc);
2360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002362 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002363 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002364 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002365 else
2366 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002367
2368 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369}
2370
Jesse Barnesd219adc2010-08-02 12:05:41 -07002371static int fbcon_debug_enter(struct vc_data *vc)
2372{
2373 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2374 struct fbcon_ops *ops = info->fbcon_par;
2375
2376 ops->save_graphics = ops->graphics;
2377 ops->graphics = 0;
2378 if (info->fbops->fb_debug_enter)
2379 info->fbops->fb_debug_enter(info);
2380 fbcon_set_palette(vc, color_table);
2381 return 0;
2382}
2383
2384static int fbcon_debug_leave(struct vc_data *vc)
2385{
2386 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2387 struct fbcon_ops *ops = info->fbcon_par;
2388
2389 ops->graphics = ops->save_graphics;
2390 if (info->fbops->fb_debug_leave)
2391 info->fbops->fb_debug_leave(info);
2392 return 0;
2393}
2394
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2396{
2397 u8 *fontdata = vc->vc_font.data;
2398 u8 *data = font->data;
2399 int i, j;
2400
2401 font->width = vc->vc_font.width;
2402 font->height = vc->vc_font.height;
2403 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2404 if (!font->data)
2405 return 0;
2406
2407 if (font->width <= 8) {
2408 j = vc->vc_font.height;
2409 for (i = 0; i < font->charcount; i++) {
2410 memcpy(data, fontdata, j);
2411 memset(data + j, 0, 32 - j);
2412 data += 32;
2413 fontdata += j;
2414 }
2415 } else if (font->width <= 16) {
2416 j = vc->vc_font.height * 2;
2417 for (i = 0; i < font->charcount; i++) {
2418 memcpy(data, fontdata, j);
2419 memset(data + j, 0, 64 - j);
2420 data += 64;
2421 fontdata += j;
2422 }
2423 } else if (font->width <= 24) {
2424 for (i = 0; i < font->charcount; i++) {
2425 for (j = 0; j < vc->vc_font.height; j++) {
2426 *data++ = fontdata[0];
2427 *data++ = fontdata[1];
2428 *data++ = fontdata[2];
2429 fontdata += sizeof(u32);
2430 }
2431 memset(data, 0, 3 * (32 - j));
2432 data += 3 * (32 - j);
2433 }
2434 } else {
2435 j = vc->vc_font.height * 4;
2436 for (i = 0; i < font->charcount; i++) {
2437 memcpy(data, fontdata, j);
2438 memset(data + j, 0, 128 - j);
2439 data += 128;
2440 fontdata += j;
2441 }
2442 }
2443 return 0;
2444}
2445
Takashi Iwai3fd37722017-01-11 17:09:50 +01002446/* set/clear vc_hi_font_mask and update vc attrs accordingly */
2447static void set_vc_hi_font(struct vc_data *vc, bool set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448{
Takashi Iwai3fd37722017-01-11 17:09:50 +01002449 if (!set) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 vc->vc_hi_font_mask = 0;
2451 if (vc->vc_can_do_color) {
2452 vc->vc_complement_mask >>= 1;
2453 vc->vc_s_complement_mask >>= 1;
2454 }
2455
2456 /* ++Edmund: reorder the attribute bits */
2457 if (vc->vc_can_do_color) {
2458 unsigned short *cp =
2459 (unsigned short *) vc->vc_origin;
2460 int count = vc->vc_screenbuf_size / 2;
2461 unsigned short c;
2462 for (; count > 0; count--, cp++) {
2463 c = scr_readw(cp);
2464 scr_writew(((c & 0xfe00) >> 1) |
2465 (c & 0xff), cp);
2466 }
2467 c = vc->vc_video_erase_char;
2468 vc->vc_video_erase_char =
2469 ((c & 0xfe00) >> 1) | (c & 0xff);
2470 vc->vc_attr >>= 1;
2471 }
Takashi Iwai3fd37722017-01-11 17:09:50 +01002472 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 vc->vc_hi_font_mask = 0x100;
2474 if (vc->vc_can_do_color) {
2475 vc->vc_complement_mask <<= 1;
2476 vc->vc_s_complement_mask <<= 1;
2477 }
2478
2479 /* ++Edmund: reorder the attribute bits */
2480 {
2481 unsigned short *cp =
2482 (unsigned short *) vc->vc_origin;
2483 int count = vc->vc_screenbuf_size / 2;
2484 unsigned short c;
2485 for (; count > 0; count--, cp++) {
2486 unsigned short newc;
2487 c = scr_readw(cp);
2488 if (vc->vc_can_do_color)
2489 newc =
2490 ((c & 0xff00) << 1) | (c &
2491 0xff);
2492 else
2493 newc = c & ~0x100;
2494 scr_writew(newc, cp);
2495 }
2496 c = vc->vc_video_erase_char;
2497 if (vc->vc_can_do_color) {
2498 vc->vc_video_erase_char =
2499 ((c & 0xff00) << 1) | (c & 0xff);
2500 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002501 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 vc->vc_video_erase_char = c & ~0x100;
2503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
Takashi Iwai3fd37722017-01-11 17:09:50 +01002505}
2506
2507static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2508 const u8 * data, int userfont)
2509{
2510 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2511 struct fbcon_ops *ops = info->fbcon_par;
2512 struct display *p = &fb_display[vc->vc_num];
2513 int resize;
2514 int cnt;
2515 char *old_data = NULL;
2516
2517 if (con_is_visible(vc) && softback_lines)
2518 fbcon_set_origin(vc);
2519
2520 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2521 if (p->userfont)
2522 old_data = vc->vc_font.data;
2523 if (userfont)
2524 cnt = FNTCHARCNT(data);
2525 else
2526 cnt = 256;
2527 vc->vc_font.data = (void *)(p->fontdata = data);
2528 if ((p->userfont = userfont))
2529 REFCOUNT(data)++;
2530 vc->vc_font.width = w;
2531 vc->vc_font.height = h;
2532 if (vc->vc_hi_font_mask && cnt == 256)
2533 set_vc_hi_font(vc, false);
2534 else if (!vc->vc_hi_font_mask && cnt == 512)
2535 set_vc_hi_font(vc, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002538 int cols, rows;
2539
2540 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2541 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2542 cols /= w;
2543 rows /= h;
2544 vc_resize(vc, cols, rows);
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002545 if (con_is_visible(vc) && softback_buf)
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002546 fbcon_update_softback(vc);
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002547 } else if (con_is_visible(vc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 && vc->vc_mode == KD_TEXT) {
2549 fbcon_clear_margins(vc, 0);
2550 update_screen(vc);
2551 }
2552
2553 if (old_data && (--REFCOUNT(old_data) == 0))
2554 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2555 return 0;
2556}
2557
2558static int fbcon_copy_font(struct vc_data *vc, int con)
2559{
2560 struct display *od = &fb_display[con];
2561 struct console_font *f = &vc->vc_font;
2562
2563 if (od->fontdata == f->data)
2564 return 0; /* already the same font... */
2565 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2566}
2567
2568/*
2569 * User asked to set font; we are guaranteed that
2570 * a) width and height are in range 1..32
2571 * b) charcount does not exceed 512
2572 * but lets not assume that, since someone might someday want to use larger
2573 * fonts. And charcount of 512 is small for unicode support.
2574 *
2575 * However, user space gives the font in 32 rows , regardless of
2576 * actual font height. So a new API is needed if support for larger fonts
2577 * is ever implemented.
2578 */
2579
2580static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2581{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002582 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 unsigned charcount = font->charcount;
2584 int w = font->width;
2585 int h = font->height;
2586 int size;
2587 int i, csum;
2588 u8 *new_data, *data = font->data;
2589 int pitch = (font->width+7) >> 3;
2590
2591 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2592 * If not this check should be changed to charcount < 256 */
2593 if (charcount != 256 && charcount != 512)
2594 return -EINVAL;
2595
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002596 /* Make sure drawing engine can handle the font */
2597 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2598 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2599 return -EINVAL;
2600
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002601 /* Make sure driver can handle the font length */
2602 if (fbcon_invalid_charcount(info, charcount))
2603 return -EINVAL;
2604
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 size = h * pitch * charcount;
2606
2607 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2608
2609 if (!new_data)
2610 return -ENOMEM;
2611
2612 new_data += FONT_EXTRA_WORDS * sizeof(int);
2613 FNTSIZE(new_data) = size;
2614 FNTCHARCNT(new_data) = charcount;
2615 REFCOUNT(new_data) = 0; /* usage counter */
2616 for (i=0; i< charcount; i++) {
2617 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2618 }
2619
2620 /* Since linux has a nice crc32 function use it for counting font
2621 * checksums. */
2622 csum = crc32(0, new_data, size);
2623
2624 FNTSUM(new_data) = csum;
2625 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002626 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 struct vc_data *tmp = vc_cons[i].d;
2628
2629 if (fb_display[i].userfont &&
2630 fb_display[i].fontdata &&
2631 FNTSUM(fb_display[i].fontdata) == csum &&
2632 FNTSIZE(fb_display[i].fontdata) == size &&
2633 tmp->vc_font.width == w &&
2634 !memcmp(fb_display[i].fontdata, new_data, size)) {
2635 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002636 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 break;
2638 }
2639 }
2640 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2641}
2642
2643static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2644{
2645 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002646 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
2648 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002649 f = get_default_font(info->var.xres, info->var.yres,
2650 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 else if (!(f = find_font(name)))
2652 return -ENOENT;
2653
2654 font->width = f->width;
2655 font->height = f->height;
2656 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2657}
2658
2659static u16 palette_red[16];
2660static u16 palette_green[16];
2661static u16 palette_blue[16];
2662
2663static struct fb_cmap palette_cmap = {
2664 0, 16, palette_red, palette_green, palette_blue, NULL
2665};
2666
Jiri Slaby709280d2016-06-23 13:34:27 +02002667static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668{
2669 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2670 int i, j, k, depth;
2671 u8 val;
2672
2673 if (fbcon_is_inactive(vc, info))
Jiri Slaby709280d2016-06-23 13:34:27 +02002674 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002676 if (!con_is_visible(vc))
Jiri Slaby709280d2016-06-23 13:34:27 +02002677 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002679 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 if (depth > 3) {
2681 for (i = j = 0; i < 16; i++) {
2682 k = table[i];
2683 val = vc->vc_palette[j++];
2684 palette_red[k] = (val << 8) | val;
2685 val = vc->vc_palette[j++];
2686 palette_green[k] = (val << 8) | val;
2687 val = vc->vc_palette[j++];
2688 palette_blue[k] = (val << 8) | val;
2689 }
2690 palette_cmap.len = 16;
2691 palette_cmap.start = 0;
2692 /*
2693 * If framebuffer is capable of less than 16 colors,
2694 * use default palette of fbcon.
2695 */
2696 } else
2697 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2698
Jiri Slaby709280d2016-06-23 13:34:27 +02002699 fb_set_cmap(&palette_cmap, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700}
2701
2702static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2703{
2704 unsigned long p;
2705 int line;
2706
2707 if (vc->vc_num != fg_console || !softback_lines)
2708 return (u16 *) (vc->vc_origin + offset);
2709 line = offset / vc->vc_size_row;
2710 if (line >= softback_lines)
2711 return (u16 *) (vc->vc_origin + offset -
2712 softback_lines * vc->vc_size_row);
2713 p = softback_curr + offset;
2714 if (p >= softback_end)
2715 p += softback_buf - softback_end;
2716 return (u16 *) p;
2717}
2718
2719static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2720 int *px, int *py)
2721{
2722 unsigned long ret;
2723 int x, y;
2724
2725 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2726 unsigned long offset = (pos - vc->vc_origin) / 2;
2727
2728 x = offset % vc->vc_cols;
2729 y = offset / vc->vc_cols;
2730 if (vc->vc_num == fg_console)
2731 y += softback_lines;
2732 ret = pos + (vc->vc_cols - x) * 2;
2733 } else if (vc->vc_num == fg_console && softback_lines) {
2734 unsigned long offset = pos - softback_curr;
2735
2736 if (pos < softback_curr)
2737 offset += softback_end - softback_buf;
2738 offset /= 2;
2739 x = offset % vc->vc_cols;
2740 y = offset / vc->vc_cols;
2741 ret = pos + (vc->vc_cols - x) * 2;
2742 if (ret == softback_end)
2743 ret = softback_buf;
2744 if (ret == softback_in)
2745 ret = vc->vc_origin;
2746 } else {
2747 /* Should not happen */
2748 x = y = 0;
2749 ret = vc->vc_origin;
2750 }
2751 if (px)
2752 *px = x;
2753 if (py)
2754 *py = y;
2755 return ret;
2756}
2757
2758/* As we might be inside of softback, we may work with non-contiguous buffer,
2759 that's why we have to use a separate routine. */
2760static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2761{
2762 while (cnt--) {
2763 u16 a = scr_readw(p);
2764 if (!vc->vc_can_do_color)
2765 a ^= 0x0800;
2766 else if (vc->vc_hi_font_mask == 0x100)
2767 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2768 (((a) & 0x0e00) << 4);
2769 else
2770 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2771 (((a) & 0x0700) << 4);
2772 scr_writew(a, p++);
2773 if (p == (u16 *) softback_end)
2774 p = (u16 *) softback_buf;
2775 if (p == (u16 *) softback_in)
2776 p = (u16 *) vc->vc_origin;
2777 }
2778}
2779
Jiri Slaby97293de2016-06-23 13:34:26 +02002780static void fbcon_scrolldelta(struct vc_data *vc, int lines)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781{
2782 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002783 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002784 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 int offset, limit, scrollback_old;
2786
2787 if (softback_top) {
2788 if (vc->vc_num != fg_console)
Jiri Slaby97293de2016-06-23 13:34:26 +02002789 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 if (vc->vc_mode != KD_TEXT || !lines)
Jiri Slaby97293de2016-06-23 13:34:26 +02002791 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 if (logo_shown >= 0) {
2793 struct vc_data *conp2 = vc_cons[logo_shown].d;
2794
2795 if (conp2->vc_top == logo_lines
2796 && conp2->vc_bottom == conp2->vc_rows)
2797 conp2->vc_top = 0;
2798 if (logo_shown == vc->vc_num) {
2799 unsigned long p, q;
2800 int i;
2801
2802 p = softback_in;
2803 q = vc->vc_origin +
2804 logo_lines * vc->vc_size_row;
2805 for (i = 0; i < logo_lines; i++) {
2806 if (p == softback_top)
2807 break;
2808 if (p == softback_buf)
2809 p = softback_end;
2810 p -= vc->vc_size_row;
2811 q -= vc->vc_size_row;
2812 scr_memcpyw((u16 *) q, (u16 *) p,
2813 vc->vc_size_row);
2814 }
David Hollister308af922006-05-30 21:25:36 -07002815 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 update_region(vc, vc->vc_origin,
2817 logo_lines * vc->vc_cols);
2818 }
2819 logo_shown = FBCON_LOGO_CANSHOW;
2820 }
2821 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002822 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
Jiri Slaby97293de2016-06-23 13:34:26 +02002824 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 }
2826
2827 if (!scrollback_phys_max)
Jiri Slaby97293de2016-06-23 13:34:26 +02002828 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830 scrollback_old = scrollback_current;
2831 scrollback_current -= lines;
2832 if (scrollback_current < 0)
2833 scrollback_current = 0;
2834 else if (scrollback_current > scrollback_max)
2835 scrollback_current = scrollback_max;
2836 if (scrollback_current == scrollback_old)
Jiri Slaby97293de2016-06-23 13:34:26 +02002837 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838
2839 if (fbcon_is_inactive(vc, info))
Jiri Slaby97293de2016-06-23 13:34:26 +02002840 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841
2842 fbcon_cursor(vc, CM_ERASE);
2843
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002844 offset = disp->yscroll - scrollback_current;
2845 limit = disp->vrows;
2846 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 case SCROLL_WRAP_MOVE:
2848 info->var.vmode |= FB_VMODE_YWRAP;
2849 break;
2850 case SCROLL_PAN_MOVE:
2851 case SCROLL_PAN_REDRAW:
2852 limit -= vc->vc_rows;
2853 info->var.vmode &= ~FB_VMODE_YWRAP;
2854 break;
2855 }
2856 if (offset < 0)
2857 offset += limit;
2858 else if (offset >= limit)
2859 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002860
2861 ops->var.xoffset = 0;
2862 ops->var.yoffset = offset * vc->vc_font.height;
2863 ops->update_start(info);
2864
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 if (!scrollback_current)
2866 fbcon_cursor(vc, CM_DRAW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867}
2868
2869static int fbcon_set_origin(struct vc_data *vc)
2870{
2871 if (softback_lines)
2872 fbcon_scrolldelta(vc, softback_lines);
2873 return 0;
2874}
2875
2876static void fbcon_suspended(struct fb_info *info)
2877{
2878 struct vc_data *vc = NULL;
2879 struct fbcon_ops *ops = info->fbcon_par;
2880
2881 if (!ops || ops->currcon < 0)
2882 return;
2883 vc = vc_cons[ops->currcon].d;
2884
2885 /* Clear cursor, restore saved data */
2886 fbcon_cursor(vc, CM_ERASE);
2887}
2888
2889static void fbcon_resumed(struct fb_info *info)
2890{
2891 struct vc_data *vc;
2892 struct fbcon_ops *ops = info->fbcon_par;
2893
2894 if (!ops || ops->currcon < 0)
2895 return;
2896 vc = vc_cons[ops->currcon].d;
2897
2898 update_screen(vc);
2899}
2900
2901static void fbcon_modechanged(struct fb_info *info)
2902{
2903 struct fbcon_ops *ops = info->fbcon_par;
2904 struct vc_data *vc;
2905 struct display *p;
2906 int rows, cols;
2907
2908 if (!ops || ops->currcon < 0)
2909 return;
2910 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002911 if (vc->vc_mode != KD_TEXT ||
2912 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return;
2914
2915 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002916 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002918 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002920 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2921 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2922 cols /= vc->vc_font.width;
2923 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 vc_resize(vc, cols, rows);
2925 updatescrollmode(p, info, vc);
2926 scrollback_max = 0;
2927 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002928
2929 if (!fbcon_is_inactive(vc, info)) {
2930 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2931 ops->update_start(info);
2932 }
2933
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 fbcon_set_palette(vc, color_table);
2935 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002936 if (softback_buf)
2937 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939}
2940
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002941static void fbcon_set_all_vcs(struct fb_info *info)
2942{
2943 struct fbcon_ops *ops = info->fbcon_par;
2944 struct vc_data *vc;
2945 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002946 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002947
2948 if (!ops || ops->currcon < 0)
2949 return;
2950
Antonino A. Daplase614b182006-06-26 00:27:09 -07002951 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002952 vc = vc_cons[i].d;
2953 if (!vc || vc->vc_mode != KD_TEXT ||
2954 registered_fb[con2fb_map[i]] != info)
2955 continue;
2956
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002957 if (con_is_visible(vc)) {
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002958 fg = i;
2959 continue;
2960 }
2961
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002962 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002963 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002964 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002965 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2966 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002967 cols /= vc->vc_font.width;
2968 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002969 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002970 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002971
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002972 if (fg != -1)
2973 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002974}
2975
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976static int fbcon_mode_deleted(struct fb_info *info,
2977 struct fb_videomode *mode)
2978{
2979 struct fb_info *fb_info;
2980 struct display *p;
2981 int i, j, found = 0;
2982
2983 /* before deletion, ensure that mode is not in use */
2984 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2985 j = con2fb_map[i];
2986 if (j == -1)
2987 continue;
2988 fb_info = registered_fb[j];
2989 if (fb_info != info)
2990 continue;
2991 p = &fb_display[i];
2992 if (!p || !p->mode)
2993 continue;
2994 if (fb_mode_is_equal(p->mode, mode)) {
2995 found = 1;
2996 break;
2997 }
2998 }
2999 return found;
3000}
3001
Jesse Barnescfafca82007-07-17 04:05:33 -07003002#ifdef CONFIG_VT_HW_CONSOLE_BINDING
3003static int fbcon_unbind(void)
3004{
3005 int ret;
3006
Takashi Iwaie93a9a82013-01-25 10:28:18 +10003007 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
Jesse Barnescfafca82007-07-17 04:05:33 -07003008 fbcon_is_default);
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003009
3010 if (!ret)
3011 fbcon_has_console_bind = 0;
3012
Jesse Barnescfafca82007-07-17 04:05:33 -07003013 return ret;
3014}
3015#else
3016static inline int fbcon_unbind(void)
3017{
3018 return -EINVAL;
3019}
3020#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3021
Dave Airlie054430e2013-01-25 11:38:56 +10003022/* called with console_lock held */
Jesse Barnescfafca82007-07-17 04:05:33 -07003023static int fbcon_fb_unbind(int idx)
3024{
3025 int i, new_idx = -1, ret = 0;
3026
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003027 if (!fbcon_has_console_bind)
3028 return 0;
3029
Jesse Barnescfafca82007-07-17 04:05:33 -07003030 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3031 if (con2fb_map[i] != idx &&
3032 con2fb_map[i] != -1) {
3033 new_idx = i;
3034 break;
3035 }
3036 }
3037
3038 if (new_idx != -1) {
3039 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3040 if (con2fb_map[i] == idx)
3041 set_con2fb_map(i, new_idx, 0);
3042 }
Keith Packard5f4dc282014-01-20 13:31:10 -08003043 } else {
3044 struct fb_info *info = registered_fb[idx];
3045
3046 /* This is sort of like set_con2fb_map, except it maps
3047 * the consoles to no device and then releases the
3048 * oldinfo to free memory and cancel the cursor blink
3049 * timer. I can imagine this just becoming part of
3050 * set_con2fb_map where new_idx is -1
3051 */
3052 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3053 if (con2fb_map[i] == idx) {
3054 con2fb_map[i] = -1;
3055 if (!search_fb_in_map(idx)) {
3056 ret = con2fb_release_oldinfo(vc_cons[i].d,
3057 info, NULL, i,
3058 idx, 0);
3059 if (ret) {
3060 con2fb_map[i] = idx;
3061 return ret;
3062 }
3063 }
3064 }
3065 }
Jesse Barnescfafca82007-07-17 04:05:33 -07003066 ret = fbcon_unbind();
Keith Packard5f4dc282014-01-20 13:31:10 -08003067 }
Jesse Barnescfafca82007-07-17 04:05:33 -07003068
3069 return ret;
3070}
3071
Dave Airlie054430e2013-01-25 11:38:56 +10003072/* called with console_lock held */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003073static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003074{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003075 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003076
Andrea Righi66c1ca02009-03-31 15:25:18 -07003077 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003078 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3079 if (con2fb_map[i] == idx)
3080 con2fb_map[i] = -1;
3081 }
3082
3083 if (idx == info_idx) {
3084 info_idx = -1;
3085
3086 for (i = 0; i < FB_MAX; i++) {
3087 if (registered_fb[i] != NULL) {
3088 info_idx = i;
3089 break;
3090 }
3091 }
3092 }
3093
3094 if (info_idx != -1) {
3095 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3096 if (con2fb_map[i] == -1)
3097 con2fb_map[i] = info_idx;
3098 }
3099 }
3100
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003101 if (primary_device == idx)
3102 primary_device = -1;
3103
Andrea Righi66c1ca02009-03-31 15:25:18 -07003104 if (!num_registered_fb)
Takashi Iwaie93a9a82013-01-25 10:28:18 +10003105 do_unregister_con_driver(&fb_con);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003106
Antonino A. Daplase614b182006-06-26 00:27:09 -07003107 return 0;
3108}
3109
Dave Airlie054430e2013-01-25 11:38:56 +10003110/* called with console_lock held */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003111static void fbcon_remap_all(int idx)
3112{
3113 int i;
3114 for (i = first_fb_vc; i <= last_fb_vc; i++)
3115 set_con2fb_map(i, idx, 0);
3116
3117 if (con_is_bound(&fb_con)) {
3118 printk(KERN_INFO "fbcon: Remapping primary device, "
3119 "fb%i, to tty %i-%i\n", idx,
3120 first_fb_vc + 1, last_fb_vc + 1);
3121 info_idx = idx;
3122 }
3123}
3124
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003125#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003126static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003128 if (!map_override && primary_device == -1 &&
3129 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003130 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003131
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003132 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3133 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003134 primary_device = info->node;
3135
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003136 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003137 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003138
3139 if (con_is_bound(&fb_con)) {
3140 printk(KERN_INFO "fbcon: Remapping primary device, "
3141 "fb%i, to tty %i-%i\n", info->node,
3142 first_fb_vc + 1, last_fb_vc + 1);
3143 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003144 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003145 }
3146
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003147}
3148#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003149static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003150{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003151 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003152}
3153#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3154
Dave Airlie054430e2013-01-25 11:38:56 +10003155/* called with console_lock held */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003156static int fbcon_fb_registered(struct fb_info *info)
3157{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003158 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003159
Andrea Righi66c1ca02009-03-31 15:25:18 -07003160 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003161 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
3163 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003164 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 if (con2fb_map_boot[i] == idx) {
3166 info_idx = idx;
3167 break;
3168 }
3169 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003170
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 if (info_idx != -1)
Alan Cox50e244c2013-01-25 10:28:15 +10003172 ret = do_fbcon_takeover(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003174 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003175 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 set_con2fb_map(i, idx, 0);
3177 }
3178 }
3179
3180 return ret;
3181}
3182
3183static void fbcon_fb_blanked(struct fb_info *info, int blank)
3184{
3185 struct fbcon_ops *ops = info->fbcon_par;
3186 struct vc_data *vc;
3187
3188 if (!ops || ops->currcon < 0)
3189 return;
3190
3191 vc = vc_cons[ops->currcon].d;
3192 if (vc->vc_mode != KD_TEXT ||
3193 registered_fb[con2fb_map[ops->currcon]] != info)
3194 return;
3195
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02003196 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 if (blank)
3198 do_blank_screen(0);
3199 else
3200 do_unblank_screen(0);
3201 }
3202 ops->blank_state = blank;
3203}
3204
3205static void fbcon_new_modelist(struct fb_info *info)
3206{
3207 int i;
3208 struct vc_data *vc;
3209 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003210 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
Antonino A. Daplase614b182006-06-26 00:27:09 -07003212 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 if (registered_fb[con2fb_map[i]] != info)
3214 continue;
3215 if (!fb_display[i].mode)
3216 continue;
3217 vc = vc_cons[i].d;
3218 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003219 mode = fb_find_nearest_mode(fb_display[i].mode,
3220 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003222 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 }
3224}
3225
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003226static void fbcon_get_requirement(struct fb_info *info,
3227 struct fb_blit_caps *caps)
3228{
3229 struct vc_data *vc;
3230 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003231
3232 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003233 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003234
3235 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3236 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003237 if (vc && vc->vc_mode == KD_TEXT &&
3238 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003239 p = &fb_display[i];
3240 caps->x |= 1 << (vc->vc_font.width - 1);
3241 caps->y |= 1 << (vc->vc_font.height - 1);
3242 charcnt = (p->userfont) ?
3243 FNTCHARCNT(p->fontdata) : 256;
3244 if (caps->len < charcnt)
3245 caps->len = charcnt;
3246 }
3247 }
3248 } else {
3249 vc = vc_cons[fg_console].d;
3250
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003251 if (vc && vc->vc_mode == KD_TEXT &&
3252 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003253 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003254 caps->x = 1 << (vc->vc_font.width - 1);
3255 caps->y = 1 << (vc->vc_font.height - 1);
3256 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003257 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003258 }
3259 }
3260}
3261
Andrea Righi66c1ca02009-03-31 15:25:18 -07003262static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 unsigned long action, void *data)
3264{
3265 struct fb_event *event = data;
3266 struct fb_info *info = event->info;
3267 struct fb_videomode *mode;
3268 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003269 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003270 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
Antonino A. Daplase614b182006-06-26 00:27:09 -07003272 /*
3273 * ignore all events except driver registration and deregistration
3274 * if fbcon is not active
3275 */
3276 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3277 action == FB_EVENT_FB_UNREGISTERED))
3278 goto done;
3279
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 switch(action) {
3281 case FB_EVENT_SUSPEND:
3282 fbcon_suspended(info);
3283 break;
3284 case FB_EVENT_RESUME:
3285 fbcon_resumed(info);
3286 break;
3287 case FB_EVENT_MODE_CHANGE:
3288 fbcon_modechanged(info);
3289 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003290 case FB_EVENT_MODE_CHANGE_ALL:
3291 fbcon_set_all_vcs(info);
3292 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 case FB_EVENT_MODE_DELETE:
3294 mode = event->data;
3295 ret = fbcon_mode_deleted(info, mode);
3296 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003297 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003298 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003299 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003300 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003302 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003304 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003305 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003306 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 case FB_EVENT_SET_CONSOLE_MAP:
Dave Airlie054430e2013-01-25 11:38:56 +10003308 /* called with console lock held */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 con2fb = event->data;
3310 ret = set_con2fb_map(con2fb->console - 1,
3311 con2fb->framebuffer, 1);
3312 break;
3313 case FB_EVENT_GET_CONSOLE_MAP:
3314 con2fb = event->data;
3315 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3316 break;
3317 case FB_EVENT_BLANK:
3318 fbcon_fb_blanked(info, *(int *)event->data);
3319 break;
3320 case FB_EVENT_NEW_MODELIST:
3321 fbcon_new_modelist(info);
3322 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003323 case FB_EVENT_GET_REQ:
3324 caps = event->data;
3325 fbcon_get_requirement(info, caps);
3326 break;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003327 case FB_EVENT_REMAP_ALL_CONSOLE:
3328 idx = info->node;
3329 fbcon_remap_all(idx);
3330 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003332done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 return ret;
3334}
3335
3336/*
3337 * The console `switch' structure for the frame buffer based console
3338 */
3339
3340static const struct consw fb_con = {
3341 .owner = THIS_MODULE,
3342 .con_startup = fbcon_startup,
3343 .con_init = fbcon_init,
3344 .con_deinit = fbcon_deinit,
3345 .con_clear = fbcon_clear,
3346 .con_putc = fbcon_putc,
3347 .con_putcs = fbcon_putcs,
3348 .con_cursor = fbcon_cursor,
3349 .con_scroll = fbcon_scroll,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 .con_switch = fbcon_switch,
3351 .con_blank = fbcon_blank,
3352 .con_font_set = fbcon_set_font,
3353 .con_font_get = fbcon_get_font,
3354 .con_font_default = fbcon_set_def_font,
3355 .con_font_copy = fbcon_copy_font,
3356 .con_set_palette = fbcon_set_palette,
3357 .con_scrolldelta = fbcon_scrolldelta,
3358 .con_set_origin = fbcon_set_origin,
3359 .con_invert_region = fbcon_invert_region,
3360 .con_screen_pos = fbcon_screen_pos,
3361 .con_getxy = fbcon_getxy,
3362 .con_resize = fbcon_resize,
Jesse Barnesd219adc2010-08-02 12:05:41 -07003363 .con_debug_enter = fbcon_debug_enter,
3364 .con_debug_leave = fbcon_debug_leave,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365};
3366
3367static struct notifier_block fbcon_event_notifier = {
3368 .notifier_call = fbcon_event_notify,
3369};
3370
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003371static ssize_t store_rotate(struct device *device,
3372 struct device_attribute *attr, const char *buf,
3373 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003374{
3375 struct fb_info *info;
3376 int rotate, idx;
3377 char **last = NULL;
3378
Antonino A. Daplase614b182006-06-26 00:27:09 -07003379 if (fbcon_has_exited)
3380 return count;
3381
Torben Hohnac751ef2011-01-25 15:07:35 -08003382 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003383 idx = con2fb_map[fg_console];
3384
3385 if (idx == -1 || registered_fb[idx] == NULL)
3386 goto err;
3387
3388 info = registered_fb[idx];
3389 rotate = simple_strtoul(buf, last, 0);
3390 fbcon_rotate(info, rotate);
3391err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003392 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003393 return count;
3394}
3395
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003396static ssize_t store_rotate_all(struct device *device,
3397 struct device_attribute *attr,const char *buf,
3398 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003399{
3400 struct fb_info *info;
3401 int rotate, idx;
3402 char **last = NULL;
3403
Antonino A. Daplase614b182006-06-26 00:27:09 -07003404 if (fbcon_has_exited)
3405 return count;
3406
Torben Hohnac751ef2011-01-25 15:07:35 -08003407 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003408 idx = con2fb_map[fg_console];
3409
3410 if (idx == -1 || registered_fb[idx] == NULL)
3411 goto err;
3412
3413 info = registered_fb[idx];
3414 rotate = simple_strtoul(buf, last, 0);
3415 fbcon_rotate_all(info, rotate);
3416err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003417 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003418 return count;
3419}
3420
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003421static ssize_t show_rotate(struct device *device,
3422 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003423{
3424 struct fb_info *info;
3425 int rotate = 0, idx;
3426
Antonino A. Daplase614b182006-06-26 00:27:09 -07003427 if (fbcon_has_exited)
3428 return 0;
3429
Torben Hohnac751ef2011-01-25 15:07:35 -08003430 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003431 idx = con2fb_map[fg_console];
3432
3433 if (idx == -1 || registered_fb[idx] == NULL)
3434 goto err;
3435
3436 info = registered_fb[idx];
3437 rotate = fbcon_get_rotate(info);
3438err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003439 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003440 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3441}
3442
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003443static ssize_t show_cursor_blink(struct device *device,
3444 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003445{
3446 struct fb_info *info;
3447 struct fbcon_ops *ops;
3448 int idx, blink = -1;
3449
3450 if (fbcon_has_exited)
3451 return 0;
3452
Torben Hohnac751ef2011-01-25 15:07:35 -08003453 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003454 idx = con2fb_map[fg_console];
3455
3456 if (idx == -1 || registered_fb[idx] == NULL)
3457 goto err;
3458
3459 info = registered_fb[idx];
3460 ops = info->fbcon_par;
3461
3462 if (!ops)
3463 goto err;
3464
3465 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3466err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003467 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003468 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3469}
3470
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003471static ssize_t store_cursor_blink(struct device *device,
3472 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003473 const char *buf, size_t count)
3474{
3475 struct fb_info *info;
3476 int blink, idx;
3477 char **last = NULL;
3478
3479 if (fbcon_has_exited)
3480 return count;
3481
Torben Hohnac751ef2011-01-25 15:07:35 -08003482 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003483 idx = con2fb_map[fg_console];
3484
3485 if (idx == -1 || registered_fb[idx] == NULL)
3486 goto err;
3487
3488 info = registered_fb[idx];
3489
3490 if (!info->fbcon_par)
3491 goto err;
3492
3493 blink = simple_strtoul(buf, last, 0);
3494
3495 if (blink) {
3496 fbcon_cursor_noblink = 0;
3497 fbcon_add_cursor_timer(info);
3498 } else {
3499 fbcon_cursor_noblink = 1;
3500 fbcon_del_cursor_timer(info);
3501 }
3502
3503err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003504 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003505 return count;
3506}
3507
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003508static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003509 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3510 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003511 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3512 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003513};
3514
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003515static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003516{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003517 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003518
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003519 fbcon_has_sysfs = 1;
3520
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003521 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3522 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003523
3524 if (error)
3525 break;
3526 }
3527
3528 if (error) {
3529 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003530 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003531
3532 fbcon_has_sysfs = 0;
3533 }
3534
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003535 return 0;
3536}
3537
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003538static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003541 int i;
3542
Torben Hohnac751ef2011-01-25 15:07:35 -08003543 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003544
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 for (i = 0; i < FB_MAX; i++) {
3546 if (registered_fb[i] != NULL) {
3547 info_idx = i;
3548 break;
3549 }
3550 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003551
Wang YanQinge57f35d2013-05-09 02:13:30 +08003552 do_fbcon_takeover(0);
Torben Hohnac751ef2011-01-25 15:07:35 -08003553 console_unlock();
Wang YanQinge57f35d2013-05-09 02:13:30 +08003554
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556}
3557
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003558static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003559{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003560 struct fb_info *info;
3561 int i, j, mapped;
3562
Antonino A. Daplase614b182006-06-26 00:27:09 -07003563 if (fbcon_has_exited)
3564 return;
3565
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003566 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003567 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003568
3569 for (i = 0; i < FB_MAX; i++) {
Jarek Poplawski142092e2010-09-22 13:05:05 -07003570 int pending = 0;
Geoff Levandbeaa4862008-12-09 13:14:17 -08003571
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003572 mapped = 0;
3573 info = registered_fb[i];
3574
3575 if (info == NULL)
3576 continue;
3577
Jarek Poplawski142092e2010-09-22 13:05:05 -07003578 if (info->queue.func)
3579 pending = cancel_work_sync(&info->queue);
Geoff Levandbeaa4862008-12-09 13:14:17 -08003580 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3581 "no"));
3582
Antonino A. Daplase614b182006-06-26 00:27:09 -07003583 for (j = first_fb_vc; j <= last_fb_vc; j++) {
Wang YanQing5aa133d2013-12-27 10:39:18 +08003584 if (con2fb_map[j] == i) {
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003585 mapped = 1;
Wang YanQing5aa133d2013-12-27 10:39:18 +08003586 break;
3587 }
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003588 }
3589
3590 if (mapped) {
3591 if (info->fbops->fb_release)
3592 info->fbops->fb_release(info, 0);
3593 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003594
3595 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003596 struct fbcon_ops *ops = info->fbcon_par;
3597
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003598 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003599 kfree(ops->cursor_src);
Masami Ichikawa46862142013-12-25 23:47:37 +09003600 kfree(ops->cursor_state.mask);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003601 kfree(info->fbcon_par);
3602 info->fbcon_par = NULL;
3603 }
3604
3605 if (info->queue.func == fb_flashcursor)
3606 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003607 }
3608 }
3609
Antonino A. Daplase614b182006-06-26 00:27:09 -07003610 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003611}
3612
3613static int __init fb_console_init(void)
3614{
3615 int i;
3616
Torben Hohnac751ef2011-01-25 15:07:35 -08003617 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003618 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003619 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3620 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003621
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003622 if (IS_ERR(fbcon_device)) {
3623 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003624 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003625 PTR_ERR(fbcon_device));
3626 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003627 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003628 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003629
3630 for (i = 0; i < MAX_NR_CONSOLES; i++)
3631 con2fb_map[i] = -1;
3632
Torben Hohnac751ef2011-01-25 15:07:35 -08003633 console_unlock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003634 fbcon_start();
3635 return 0;
3636}
3637
Hans de Goedeba168a32014-11-14 13:26:54 +01003638fs_initcall(fb_console_init);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003639
3640#ifdef MODULE
3641
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003642static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003643{
3644 int i;
3645
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003646 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003647 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3648 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003649
3650 fbcon_has_sysfs = 0;
3651 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003652}
3653
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654static void __exit fb_console_exit(void)
3655{
Torben Hohnac751ef2011-01-25 15:07:35 -08003656 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003658 fbcon_deinit_device();
3659 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003660 fbcon_exit();
Wang YanQing70125e72013-05-09 02:14:39 +08003661 do_unregister_con_driver(&fb_con);
Torben Hohnac751ef2011-01-25 15:07:35 -08003662 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663}
3664
3665module_exit(fb_console_exit);
3666
3667#endif
3668
3669MODULE_LICENSE("GPL");