blob: a44f5627b82a3f4e7e9b079e2546ad4a5f4931c5 [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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
168 int height, int width);
169static int fbcon_switch(struct vc_data *vc);
170static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
Jiri Slaby709280d2016-06-23 13:34:27 +0200171static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173/*
174 * Internal routines
175 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176static __inline__ void ywrap_up(struct vc_data *vc, int count);
177static __inline__ void ywrap_down(struct vc_data *vc, int count);
178static __inline__ void ypan_up(struct vc_data *vc, int count);
179static __inline__ void ypan_down(struct vc_data *vc, int count);
180static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
181 int dy, int dx, int height, int width, u_int y_break);
182static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700183 int unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
185 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800186static void fbcon_modechanged(struct fb_info *info);
187static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700188static void fbcon_start(void);
189static void fbcon_exit(void);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -0700190static struct device *fbcon_device;
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700191
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800192#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800193static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800194{
195 struct fbcon_ops *ops = info->fbcon_par;
196
197 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800198 ops->p->con_rotate < 4)
199 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800200 else
201 ops->rotate = 0;
202}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800203
204static void fbcon_rotate(struct fb_info *info, u32 rotate)
205{
206 struct fbcon_ops *ops= info->fbcon_par;
207 struct fb_info *fb_info;
208
209 if (!ops || ops->currcon == -1)
210 return;
211
212 fb_info = registered_fb[con2fb_map[ops->currcon]];
213
214 if (info == fb_info) {
215 struct display *p = &fb_display[ops->currcon];
216
217 if (rotate < 4)
218 p->con_rotate = rotate;
219 else
220 p->con_rotate = 0;
221
222 fbcon_modechanged(info);
223 }
224}
225
226static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
227{
228 struct fbcon_ops *ops = info->fbcon_par;
229 struct vc_data *vc;
230 struct display *p;
231 int i;
232
233 if (!ops || ops->currcon < 0 || rotate > 3)
234 return;
235
Antonino A. Daplase614b182006-06-26 00:27:09 -0700236 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800237 vc = vc_cons[i].d;
238 if (!vc || vc->vc_mode != KD_TEXT ||
239 registered_fb[con2fb_map[i]] != info)
240 continue;
241
242 p = &fb_display[vc->vc_num];
243 p->con_rotate = rotate;
244 }
245
246 fbcon_set_all_vcs(info);
247}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800248#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800249static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800250{
251 struct fbcon_ops *ops = info->fbcon_par;
252
253 ops->rotate = FB_ROTATE_UR;
254}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800255
256static void fbcon_rotate(struct fb_info *info, u32 rotate)
257{
258 return;
259}
260
261static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
262{
263 return;
264}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800265#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800266
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800267static int fbcon_get_rotate(struct fb_info *info)
268{
269 struct fbcon_ops *ops = info->fbcon_par;
270
271 return (ops) ? ops->rotate : 0;
272}
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
275{
276 struct fbcon_ops *ops = info->fbcon_par;
277
278 return (info->state != FBINFO_STATE_RUNNING ||
Jesse Barnes8fd4bd22010-06-23 12:56:12 -0700279 vc->vc_mode != KD_TEXT || ops->graphics) &&
280 !vt_force_oops_output(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
Denys Vlasenkoda909ce2010-08-10 18:02:29 -0700283static int get_color(struct vc_data *vc, struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 u16 c, int is_fg)
285{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700286 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 int color = 0;
288
289 if (console_blanked) {
290 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
291
292 c = vc->vc_video_erase_char & charmask;
293 }
294
295 if (depth != 1)
296 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
297 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
298
299 switch (depth) {
300 case 1:
301 {
Thomas Pfaff91c43132008-02-06 01:39:45 -0800302 int col = mono_col(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700304 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
305 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 if (console_blanked)
308 fg = bg;
309
310 color = (is_fg) ? fg : bg;
311 break;
312 }
313 case 2:
314 /*
315 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700316 * is grayscale. However, simply dividing the values by 4
317 * will not work, as colors 1, 2 and 3 will be scaled-down
318 * to zero rendering them invisible. So empirically convert
319 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700321 switch (color) {
322 case 0:
323 color = 0; /* black */
324 break;
325 case 1 ... 6:
326 color = 2; /* white */
327 break;
328 case 7 ... 8:
329 color = 1; /* gray */
330 break;
331 default:
332 color = 3; /* intense white */
333 break;
334 }
335 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 case 3:
337 /*
338 * Last 8 entries of default 16-color palette is a more intense
339 * version of the first 8 (i.e., same chrominance, different
340 * luminance).
341 */
342 color &= 7;
343 break;
344 }
345
346
347 return color;
348}
349
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800350static void fbcon_update_softback(struct vc_data *vc)
351{
352 int l = fbcon_softback_size / vc->vc_size_row;
353
354 if (l > 5)
355 softback_end = softback_buf + l * vc->vc_size_row;
356 else
357 /* Smaller scrollback makes no sense, and 0 would screw
358 the operation totally */
359 softback_top = 0;
360}
361
David Howellsc4028952006-11-22 14:57:56 +0000362static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
David Howellsc4028952006-11-22 14:57:56 +0000364 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 struct vc_data *vc = NULL;
367 int c;
368 int mode;
Dave Airlied8636a22012-08-21 16:29:47 +1000369 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Dave Airlied8636a22012-08-21 16:29:47 +1000371 /* FIXME: we should sort out the unbind locking instead */
372 /* instead we just fail to flash the cursor if we can't get
373 * the lock instead of blocking fbcon deinit */
374 ret = console_trylock();
375 if (ret == 0)
376 return;
377
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700378 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 vc = vc_cons[ops->currcon].d;
380
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +0200381 if (!vc || !con_is_visible(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700382 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700383 vc->vc_deccm != 1) {
Torben Hohnac751ef2011-01-25 15:07:35 -0800384 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700386 }
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 c = scr_readw((u16 *) vc->vc_pos);
389 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
390 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800391 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 get_color(vc, info, c, 0));
Torben Hohnac751ef2011-01-25 15:07:35 -0800393 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396static void cursor_timer_handler(unsigned long dev_addr)
397{
398 struct fb_info *info = (struct fb_info *) dev_addr;
399 struct fbcon_ops *ops = info->fbcon_par;
400
Viresh Kumara85f1a42013-04-24 17:12:57 +0530401 queue_work(system_power_efficient_wq, &info->queue);
Scot Doyle27a4c822015-03-26 13:56:38 +0000402 mod_timer(&ops->cursor_timer, jiffies + ops->cur_blink_jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700405static void fbcon_add_cursor_timer(struct fb_info *info)
406{
407 struct fbcon_ops *ops = info->fbcon_par;
408
409 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -0700410 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER) &&
411 !fbcon_cursor_noblink) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700412 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000413 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700414
415 init_timer(&ops->cursor_timer);
416 ops->cursor_timer.function = cursor_timer_handler;
Scot Doyle27a4c822015-03-26 13:56:38 +0000417 ops->cursor_timer.expires = jiffies + ops->cur_blink_jiffies;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700418 ops->cursor_timer.data = (unsigned long ) info;
419 add_timer(&ops->cursor_timer);
420 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
421 }
422}
423
424static void fbcon_del_cursor_timer(struct fb_info *info)
425{
426 struct fbcon_ops *ops = info->fbcon_par;
427
428 if (info->queue.func == fb_flashcursor &&
429 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
430 del_timer_sync(&ops->cursor_timer);
431 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
432 }
433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#ifndef MODULE
436static int __init fb_console_setup(char *this_opt)
437{
438 char *options;
439 int i, j;
440
441 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800442 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444 while ((options = strsep(&this_opt, ",")) != NULL) {
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200445 if (!strncmp(options, "font:", 5)) {
Paul Cercueile4329642012-07-24 03:00:24 +0200446 strlcpy(fontname, options + 5, sizeof(fontname));
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200447 continue;
448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (!strncmp(options, "scrollback:", 11)) {
451 options += 11;
452 if (*options) {
453 fbcon_softback_size = simple_strtoul(options, &options, 0);
454 if (*options == 'k' || *options == 'K') {
455 fbcon_softback_size *= 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200457 }
458 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
460
461 if (!strncmp(options, "map:", 4)) {
462 options += 4;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700463 if (*options) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
465 if (!options[j])
466 j = 0;
467 con2fb_map_boot[i] =
468 (options[j++]-'0') % FB_MAX;
469 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700470
Antonino A. Daplas4769a9a2007-08-10 13:00:46 -0700471 fbcon_map_override();
Antonino A. Daplas623e71b2007-07-17 04:05:28 -0700472 }
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200473 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
476 if (!strncmp(options, "vc:", 3)) {
477 options += 3;
478 if (*options)
479 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
480 if (first_fb_vc < 0)
481 first_fb_vc = 0;
482 if (*options++ == '-')
483 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
484 fbcon_is_default = 0;
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200485 continue;
486 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800487
488 if (!strncmp(options, "rotate:", 7)) {
489 options += 7;
490 if (*options)
Marcin Slusarz2428e592008-02-06 01:39:14 -0800491 initial_rotation = simple_strtoul(options, &options, 0);
492 if (initial_rotation > 3)
493 initial_rotation = 0;
Maarten ter Huurne37773c42014-10-09 11:48:30 +0200494 continue;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800497 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498}
499
500__setup("fbcon=", fb_console_setup);
501#endif
502
503static int search_fb_in_map(int idx)
504{
505 int i, retval = 0;
506
Antonino A. Daplase614b182006-06-26 00:27:09 -0700507 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (con2fb_map[i] == idx)
509 retval = 1;
510 }
511 return retval;
512}
513
514static int search_for_mapped_con(void)
515{
516 int i, retval = 0;
517
Antonino A. Daplase614b182006-06-26 00:27:09 -0700518 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (con2fb_map[i] != -1)
520 retval = 1;
521 }
522 return retval;
523}
524
Alan Cox50e244c2013-01-25 10:28:15 +1000525static int do_fbcon_takeover(int show_logo)
526{
527 int err, i;
528
529 if (!num_registered_fb)
530 return -ENODEV;
531
532 if (!show_logo)
533 logo_shown = FBCON_LOGO_DONTSHOW;
534
535 for (i = first_fb_vc; i <= last_fb_vc; i++)
536 con2fb_map[i] = info_idx;
537
538 err = do_take_over_console(&fb_con, first_fb_vc, last_fb_vc,
539 fbcon_is_default);
540
541 if (err) {
542 for (i = first_fb_vc; i <= last_fb_vc; i++)
543 con2fb_map[i] = -1;
544 info_idx = -1;
545 } else {
546 fbcon_has_console_bind = 1;
547 }
548
549 return err;
550}
551
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700552#ifdef MODULE
553static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
554 int cols, int rows, int new_cols, int new_rows)
555{
556 logo_shown = FBCON_LOGO_DONTSHOW;
557}
558#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
560 int cols, int rows, int new_cols, int new_rows)
561{
562 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800563 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 int cnt, erase = vc->vc_video_erase_char, step;
565 unsigned short *save = NULL, *r, *q;
Krzysztof Helt49a1d282008-07-23 21:31:21 -0700566 int logo_height;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700568 if (info->flags & FBINFO_MODULE) {
569 logo_shown = FBCON_LOGO_DONTSHOW;
570 return;
571 }
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 /*
574 * remove underline attribute from erase character
575 * if black and white framebuffer.
576 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700577 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800579 logo_height = fb_prepare_logo(info, ops->rotate);
Julia Lawall416e74e2008-04-28 02:14:51 -0700580 logo_lines = DIV_ROUND_UP(logo_height, vc->vc_font.height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 q = (unsigned short *) (vc->vc_origin +
582 vc->vc_size_row * rows);
583 step = logo_lines * cols;
584 for (r = q - logo_lines * cols; r < q; r++)
585 if (scr_readw(r) != vc->vc_video_erase_char)
586 break;
587 if (r != q && new_rows >= rows + logo_lines) {
588 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
589 if (save) {
590 int i = cols < new_cols ? cols : new_cols;
591 scr_memsetw(save, erase, logo_lines * new_cols * 2);
592 r = q - step;
593 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
594 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
595 r = q;
596 }
597 }
598 if (r == q) {
599 /* We can scroll screen down */
600 r = q - step - cols;
601 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
602 scr_memcpyw(r + step, r, vc->vc_size_row);
603 r -= cols;
604 }
605 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700606 int lines;
607 if (vc->vc_y + logo_lines >= rows)
608 lines = rows - vc->vc_y - 1;
609 else
610 lines = logo_lines;
611 vc->vc_y += lines;
612 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614 }
615 scr_memsetw((unsigned short *) vc->vc_origin,
616 erase,
617 vc->vc_size_row * logo_lines);
618
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +0200619 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 fbcon_clear_margins(vc, 0);
621 update_screen(vc);
622 }
623
624 if (save) {
625 q = (unsigned short *) (vc->vc_origin +
626 vc->vc_size_row *
627 rows);
628 scr_memcpyw(q, save, logo_lines * new_cols * 2);
629 vc->vc_y += logo_lines;
630 vc->vc_pos += logo_lines * vc->vc_size_row;
631 kfree(save);
632 }
633
634 if (logo_lines > vc->vc_bottom) {
635 logo_shown = FBCON_LOGO_CANSHOW;
636 printk(KERN_INFO
637 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
638 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
639 logo_shown = FBCON_LOGO_DRAW;
640 vc->vc_top = logo_lines;
641 }
642}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700643#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800646static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
648 struct fbcon_ops *ops = info->fbcon_par;
649
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800650 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800653 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800654 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800655 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700659
660static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
661{
662 int err = 0;
663
664 if (info->flags & FBINFO_MISC_TILEBLITTING &&
665 info->tileops->fb_get_tilemax(info) < charcount)
666 err = 1;
667
668 return err;
669}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800671static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
673 struct fbcon_ops *ops = info->fbcon_par;
674
675 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800676 ops->p = &fb_display[vc->vc_num];
677 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 fbcon_set_bitops(ops);
679}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700680
681static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
682{
683 return 0;
684}
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#endif /* CONFIG_MISC_TILEBLITTING */
687
688
689static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
690 int unit, int oldidx)
691{
692 struct fbcon_ops *ops = NULL;
693 int err = 0;
694
695 if (!try_module_get(info->fbops->owner))
696 err = -ENODEV;
697
698 if (!err && info->fbops->fb_open &&
699 info->fbops->fb_open(info, 0))
700 err = -ENODEV;
701
702 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800703 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 if (!ops)
705 err = -ENOMEM;
706 }
707
708 if (!err) {
Jean-Philippe Bruckera1e533e2016-02-15 18:41:33 +0000709 ops->cur_blink_jiffies = HZ / 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 info->fbcon_par = ops;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700711
712 if (vc)
713 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
715
716 if (err) {
717 con2fb_map[unit] = oldidx;
718 module_put(info->fbops->owner);
719 }
720
721 return err;
722}
723
724static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
725 struct fb_info *newinfo, int unit,
726 int oldidx, int found)
727{
728 struct fbcon_ops *ops = oldinfo->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700729 int err = 0, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (oldinfo->fbops->fb_release &&
732 oldinfo->fbops->fb_release(oldinfo, 0)) {
733 con2fb_map[unit] = oldidx;
734 if (!found && newinfo->fbops->fb_release)
735 newinfo->fbops->fb_release(newinfo, 0);
736 if (!found)
737 module_put(newinfo->fbops->owner);
738 err = -ENODEV;
739 }
740
741 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700742 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 kfree(ops->cursor_state.mask);
744 kfree(ops->cursor_data);
Masami Ichikawa7a966fb2014-04-23 23:35:22 +0900745 kfree(ops->cursor_src);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800746 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 kfree(oldinfo->fbcon_par);
748 oldinfo->fbcon_par = NULL;
749 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800750 /*
751 If oldinfo and newinfo are driving the same hardware,
752 the fb_release() method of oldinfo may attempt to
753 restore the hardware state. This will leave the
754 newinfo in an undefined state. Thus, a call to
755 fb_set_par() may be needed for the newinfo.
756 */
Keith Packard5f4dc282014-01-20 13:31:10 -0800757 if (newinfo && newinfo->fbops->fb_set_par) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700758 ret = newinfo->fbops->fb_set_par(newinfo);
759
760 if (ret)
761 printk(KERN_ERR "con2fb_release_oldinfo: "
762 "detected unhandled fb_set_par error, "
763 "error code %d\n", ret);
764 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 }
766
767 return err;
768}
769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
771 int unit, int show_logo)
772{
773 struct fbcon_ops *ops = info->fbcon_par;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700774 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 ops->currcon = fg_console;
777
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -0700778 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) {
779 ret = info->fbops->fb_set_par(info);
780
781 if (ret)
782 printk(KERN_ERR "con2fb_init_display: detected "
783 "unhandled fb_set_par error, "
784 "error code %d\n", ret);
785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 ops->flags |= FBCON_FLAGS_INIT;
788 ops->graphics = 0;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -0700789 fbcon_set_disp(info, &info->var, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 if (show_logo) {
792 struct vc_data *fg_vc = vc_cons[fg_console].d;
793 struct fb_info *fg_info =
794 registered_fb[con2fb_map[fg_console]];
795
796 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
797 fg_vc->vc_rows, fg_vc->vc_cols,
798 fg_vc->vc_rows);
799 }
800
801 update_screen(vc_cons[fg_console].d);
802}
803
804/**
805 * set_con2fb_map - map console to frame buffer device
806 * @unit: virtual console number to map
807 * @newidx: frame buffer index to map virtual console to
808 * @user: user request
809 *
810 * Maps a virtual console @unit to a frame buffer device
811 * @newidx.
Dave Airlie054430e2013-01-25 11:38:56 +1000812 *
813 * This should be called with the console lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 */
815static int set_con2fb_map(int unit, int newidx, int user)
816{
817 struct vc_data *vc = vc_cons[unit].d;
818 int oldidx = con2fb_map[unit];
819 struct fb_info *info = registered_fb[newidx];
820 struct fb_info *oldinfo = NULL;
821 int found, err = 0;
822
823 if (oldidx == newidx)
824 return 0;
825
Dave Airlie32b98bf2010-12-21 01:41:17 +0000826 if (!info)
Antonino A. Daplase614b182006-06-26 00:27:09 -0700827 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Dave Airlie32b98bf2010-12-21 01:41:17 +0000829 if (!search_for_mapped_con() || !con_is_bound(&fb_con)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 info_idx = newidx;
Dave Airlie054430e2013-01-25 11:38:56 +1000831 return do_fbcon_takeover(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
833
834 if (oldidx != -1)
835 oldinfo = registered_fb[oldidx];
836
837 found = search_fb_in_map(newidx);
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 con2fb_map[unit] = newidx;
840 if (!err && !found)
841 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
842
843
844 /*
845 * If old fb is not mapped to any of the consoles,
846 * fbcon should release it.
847 */
848 if (!err && oldinfo && !search_fb_in_map(oldidx))
849 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
850 found);
851
852 if (!err) {
853 int show_logo = (fg_console == 0 && !user &&
854 logo_shown != FBCON_LOGO_DONTSHOW);
855
856 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700857 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 con2fb_map_boot[unit] = newidx;
859 con2fb_init_display(vc, info, unit, show_logo);
860 }
861
Antonino A. Daplase614b182006-06-26 00:27:09 -0700862 if (!search_fb_in_map(info_idx))
863 info_idx = newidx;
864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 return err;
866}
867
868/*
869 * Low Level Operations
870 */
Wang YanQing155957f2013-05-21 13:15:12 +0800871/* NOTE: fbcon cannot be __init: it may be called from do_take_over_console later */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872static int var_to_display(struct display *disp,
873 struct fb_var_screeninfo *var,
874 struct fb_info *info)
875{
876 disp->xres_virtual = var->xres_virtual;
877 disp->yres_virtual = var->yres_virtual;
878 disp->bits_per_pixel = var->bits_per_pixel;
879 disp->grayscale = var->grayscale;
880 disp->nonstd = var->nonstd;
881 disp->accel_flags = var->accel_flags;
882 disp->height = var->height;
883 disp->width = var->width;
884 disp->red = var->red;
885 disp->green = var->green;
886 disp->blue = var->blue;
887 disp->transp = var->transp;
888 disp->rotate = var->rotate;
889 disp->mode = fb_match_mode(var, &info->modelist);
890 if (disp->mode == NULL)
891 /* This should not happen */
892 return -EINVAL;
893 return 0;
894}
895
896static void display_to_var(struct fb_var_screeninfo *var,
897 struct display *disp)
898{
899 fb_videomode_to_var(var, disp->mode);
900 var->xres_virtual = disp->xres_virtual;
901 var->yres_virtual = disp->yres_virtual;
902 var->bits_per_pixel = disp->bits_per_pixel;
903 var->grayscale = disp->grayscale;
904 var->nonstd = disp->nonstd;
905 var->accel_flags = disp->accel_flags;
906 var->height = disp->height;
907 var->width = disp->width;
908 var->red = disp->red;
909 var->green = disp->green;
910 var->blue = disp->blue;
911 var->transp = disp->transp;
912 var->rotate = disp->rotate;
913}
914
915static const char *fbcon_startup(void)
916{
917 const char *display_desc = "frame buffer device";
918 struct display *p = &fb_display[fg_console];
919 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700920 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 struct module *owner;
922 struct fb_info *info = NULL;
923 struct fbcon_ops *ops;
924 int rows, cols;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 /*
927 * If num_registered_fb is zero, this is a call for the dummy part.
928 * The frame buffer devices weren't initialized yet.
929 */
930 if (!num_registered_fb || info_idx == -1)
931 return display_desc;
932 /*
933 * Instead of blindly using registered_fb[0], we use info_idx, set by
934 * fb_console_init();
935 */
936 info = registered_fb[info_idx];
937 if (!info)
938 return NULL;
939
940 owner = info->fbops->owner;
941 if (!try_module_get(owner))
942 return NULL;
943 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
944 module_put(owner);
945 return NULL;
946 }
947
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800948 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 if (!ops) {
950 module_put(owner);
951 return NULL;
952 }
953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 ops->currcon = -1;
955 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800956 ops->cur_rotate = -1;
Jean-Philippe Bruckera1e533e2016-02-15 18:41:33 +0000957 ops->cur_blink_jiffies = HZ / 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 info->fbcon_par = ops;
Marcin Slusarz2428e592008-02-06 01:39:14 -0800959 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800960 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 if (info->fix.type != FB_TYPE_TEXT) {
963 if (fbcon_softback_size) {
964 if (!softback_buf) {
965 softback_buf =
966 (unsigned long)
967 kmalloc(fbcon_softback_size,
968 GFP_KERNEL);
969 if (!softback_buf) {
970 fbcon_softback_size = 0;
971 softback_top = 0;
972 }
973 }
974 } else {
975 if (softback_buf) {
976 kfree((void *) softback_buf);
977 softback_buf = 0;
978 softback_top = 0;
979 }
980 }
981 if (softback_buf)
982 softback_in = softback_top = softback_curr =
983 softback_buf;
984 softback_lines = 0;
985 }
986
987 /* Setup default font */
Dave Airlieae128782013-01-24 16:12:41 +1000988 if (!p->fontdata && !vc->vc_font.data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (!fontname[0] || !(font = find_font(fontname)))
990 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -0700991 info->var.yres,
992 info->pixmap.blit_x,
993 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 vc->vc_font.width = font->width;
995 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700996 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
Dave Airlieae128782013-01-24 16:12:41 +1000998 } else {
999 p->fontdata = vc->vc_font.data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
1001
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001002 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1003 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1004 cols /= vc->vc_font.width;
1005 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 vc_resize(vc, cols, rows);
1007
1008 DPRINTK("mode: %s\n", info->fix.id);
1009 DPRINTK("visual: %d\n", info->fix.visual);
1010 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1011 info->var.yres,
1012 info->var.bits_per_pixel);
1013
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001014 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001015 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 return display_desc;
1017}
1018
1019static void fbcon_init(struct vc_data *vc, int init)
1020{
1021 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1022 struct fbcon_ops *ops;
1023 struct vc_data **default_mode = vc->vc_display_fg;
1024 struct vc_data *svc = *default_mode;
1025 struct display *t, *p = &fb_display[vc->vc_num];
1026 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001027 int cap, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 if (info_idx == -1 || info == NULL)
1030 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001031
1032 cap = info->flags;
1033
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1035 (info->fix.type == FB_TYPE_TEXT))
1036 logo = 0;
1037
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (var_to_display(p, &info->var, info))
1039 return;
1040
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001041 if (!info->fbcon_par)
1042 con2fb_acquire_newinfo(vc, info, vc->vc_num, -1);
1043
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 /* If we are not the first console on this
1045 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001046 t = &fb_display[fg_console];
1047 if (!p->fontdata) {
1048 if (t->fontdata) {
1049 struct vc_data *fvc = vc_cons[fg_console].d;
1050
1051 vc->vc_font.data = (void *)(p->fontdata =
1052 fvc->vc_font.data);
1053 vc->vc_font.width = fvc->vc_font.width;
1054 vc->vc_font.height = fvc->vc_font.height;
1055 p->userfont = t->userfont;
1056
1057 if (p->userfont)
1058 REFCOUNT(p->fontdata)++;
1059 } else {
1060 const struct font_desc *font = NULL;
1061
1062 if (!fontname[0] || !(font = find_font(fontname)))
1063 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001064 info->var.yres,
1065 info->pixmap.blit_x,
1066 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001067 vc->vc_font.width = font->width;
1068 vc->vc_font.height = font->height;
1069 vc->vc_font.data = (void *)(p->fontdata = font->data);
1070 vc->vc_font.charcount = 256; /* FIXME Need to
1071 support more fonts */
1072 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001074
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 if (p->userfont)
1076 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001077
Jesse Barnes8fd4bd22010-06-23 12:56:12 -07001078 vc->vc_panic_force_write = !!(info->flags & FBINFO_CAN_FORCE_OUTPUT);
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001079 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1081 if (charcnt == 256) {
1082 vc->vc_hi_font_mask = 0;
1083 } else {
1084 vc->vc_hi_font_mask = 0x100;
1085 if (vc->vc_can_do_color)
1086 vc->vc_complement_mask <<= 1;
1087 }
1088
1089 if (!*svc->vc_uni_pagedir_loc)
1090 con_set_default_unimap(svc);
1091 if (!*vc->vc_uni_pagedir_loc)
1092 con_copy_unimap(vc, svc);
1093
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001094 ops = info->fbcon_par;
Scot Doylef235f662015-10-09 15:08:10 +00001095 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
Marcin Slusarz2428e592008-02-06 01:39:14 -08001096 p->con_rotate = initial_rotation;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001097 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 cols = vc->vc_cols;
1100 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001101 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1102 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1103 new_cols /= vc->vc_font.width;
1104 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 /*
1107 * We must always set the mode. The mode of the previous console
1108 * driver could be in the same resolution but we are using different
1109 * hardware so we have to initialize the hardware.
1110 *
1111 * We need to do it in fbcon_init() to prevent screen corruption.
1112 */
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02001113 if (con_is_visible(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (info->fbops->fb_set_par &&
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07001115 !(ops->flags & FBCON_FLAGS_INIT)) {
1116 ret = info->fbops->fb_set_par(info);
1117
1118 if (ret)
1119 printk(KERN_ERR "fbcon_init: detected "
1120 "unhandled fb_set_par error, "
1121 "error code %d\n", ret);
1122 }
1123
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 ops->flags |= FBCON_FLAGS_INIT;
1125 }
1126
1127 ops->graphics = 0;
1128
1129 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1130 !(cap & FBINFO_HWACCEL_DISABLED))
1131 p->scrollmode = SCROLL_MOVE;
1132 else /* default to something safe */
1133 p->scrollmode = SCROLL_REDRAW;
1134
1135 /*
1136 * ++guenther: console.c:vc_allocate() relies on initializing
1137 * vc_{cols,rows}, but we must not set those if we are only
1138 * resizing the console.
1139 */
Johannes Weiner0035fe02009-08-06 15:07:36 -07001140 if (init) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 vc->vc_cols = new_cols;
1142 vc->vc_rows = new_rows;
Johannes Weiner0035fe02009-08-06 15:07:36 -07001143 } else
1144 vc_resize(vc, new_cols, new_rows);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 if (logo)
1147 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1148
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001149 if (vc == svc && softback_buf)
1150 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001151
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001152 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001153 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001154 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001155 }
1156
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001157 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
Dave Airlieae128782013-01-24 16:12:41 +10001160static void fbcon_free_font(struct display *p, bool freefont)
Antonino A. Daplase614b182006-06-26 00:27:09 -07001161{
Dave Airlieae128782013-01-24 16:12:41 +10001162 if (freefont && p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001163 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1164 p->fontdata = NULL;
1165 p->userfont = 0;
1166}
1167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168static void fbcon_deinit(struct vc_data *vc)
1169{
1170 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001171 struct fb_info *info;
1172 struct fbcon_ops *ops;
1173 int idx;
Dave Airlieae128782013-01-24 16:12:41 +10001174 bool free_font = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Antonino A. Daplase614b182006-06-26 00:27:09 -07001176 idx = con2fb_map[vc->vc_num];
1177
1178 if (idx == -1)
1179 goto finished;
1180
1181 info = registered_fb[idx];
1182
1183 if (!info)
1184 goto finished;
1185
Dave Airlieae128782013-01-24 16:12:41 +10001186 if (info->flags & FBINFO_MISC_FIRMWARE)
1187 free_font = false;
Antonino A. Daplase614b182006-06-26 00:27:09 -07001188 ops = info->fbcon_par;
1189
1190 if (!ops)
1191 goto finished;
1192
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02001193 if (con_is_visible(vc))
Antonino A. Daplase614b182006-06-26 00:27:09 -07001194 fbcon_del_cursor_timer(info);
1195
1196 ops->flags &= ~FBCON_FLAGS_INIT;
1197finished:
1198
Dave Airlieae128782013-01-24 16:12:41 +10001199 fbcon_free_font(p, free_font);
Mika Kuoppalae6637d52013-04-22 14:19:26 +03001200 if (free_font)
1201 vc->vc_font.data = NULL;
Dave Airlieae128782013-01-24 16:12:41 +10001202
Antonino A. Daplase614b182006-06-26 00:27:09 -07001203 if (!con_is_bound(&fb_con))
1204 fbcon_exit();
1205
1206 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
1209/* ====================================================================== */
1210
1211/* fbcon_XXX routines - interface used by the world
1212 *
1213 * This system is now divided into two levels because of complications
1214 * caused by hardware scrolling. Top level functions:
1215 *
1216 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1217 *
1218 * handles y values in range [0, scr_height-1] that correspond to real
1219 * screen positions. y_wrap shift means that first line of bitmap may be
1220 * anywhere on this display. These functions convert lineoffsets to
1221 * bitmap offsets and deal with the wrap-around case by splitting blits.
1222 *
1223 * fbcon_bmove_physical_8() -- These functions fast implementations
1224 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1225 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1226 *
1227 * WARNING:
1228 *
1229 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1230 * Implies should only really hardware scroll in rows. Only reason for
1231 * restriction is simplicity & efficiency at the moment.
1232 */
1233
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1235 int width)
1236{
1237 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1238 struct fbcon_ops *ops = info->fbcon_par;
1239
1240 struct display *p = &fb_display[vc->vc_num];
1241 u_int y_break;
1242
1243 if (fbcon_is_inactive(vc, info))
1244 return;
1245
1246 if (!height || !width)
1247 return;
1248
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001249 if (sy < vc->vc_top && vc->vc_top == logo_lines) {
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001250 vc->vc_top = 0;
Kamal Mostafa256fc0e2013-02-21 16:42:07 -08001251 /*
1252 * If the font dimensions are not an integral of the display
1253 * dimensions then the ops->clear below won't end up clearing
1254 * the margins. Call clear_margins here in case the logo
1255 * bitmap stretched into the margin area.
1256 */
1257 fbcon_clear_margins(vc, 0);
1258 }
Krzysztof Heltc213ddf2008-08-05 13:01:26 -07001259
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 /* Split blits that cross physical y_wrap boundary */
1261
1262 y_break = p->vrows - p->yscroll;
1263 if (sy < y_break && sy + height - 1 >= y_break) {
1264 u_int b = y_break - sy;
1265 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1266 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1267 width);
1268 } else
1269 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1270}
1271
1272static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1273 int count, int ypos, int xpos)
1274{
1275 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1276 struct display *p = &fb_display[vc->vc_num];
1277 struct fbcon_ops *ops = info->fbcon_par;
1278
1279 if (!fbcon_is_inactive(vc, info))
1280 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1281 get_color(vc, info, scr_readw(s), 1),
1282 get_color(vc, info, scr_readw(s), 0));
1283}
1284
1285static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1286{
1287 unsigned short chr;
1288
1289 scr_writew(c, &chr);
1290 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1291}
1292
1293static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1294{
1295 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1296 struct fbcon_ops *ops = info->fbcon_par;
1297
1298 if (!fbcon_is_inactive(vc, info))
1299 ops->clear_margins(vc, info, bottom_only);
1300}
1301
1302static void fbcon_cursor(struct vc_data *vc, int mode)
1303{
1304 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1305 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 int y;
1307 int c = scr_readw((u16 *) vc->vc_pos);
1308
Scot Doyle2a17d7e2015-08-04 12:33:32 +00001309 ops->cur_blink_jiffies = msecs_to_jiffies(vc->vc_cur_blink_ms);
1310
Michal Januszewskid1e23062007-05-08 00:38:07 -07001311 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 return;
1313
Thierry Redinga5edce42015-05-21 09:58:03 +02001314 if (vc->vc_cursor_type & 0x10)
1315 fbcon_del_cursor_timer(info);
1316 else
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07001317 fbcon_add_cursor_timer(info);
1318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1320 if (mode & CM_SOFTBACK) {
1321 mode &= ~CM_SOFTBACK;
1322 y = softback_lines;
1323 } else {
1324 if (softback_lines)
1325 fbcon_set_origin(vc);
1326 y = 0;
1327 }
1328
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001329 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 get_color(vc, info, c, 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331}
1332
1333static int scrollback_phys_max = 0;
1334static int scrollback_max = 0;
1335static int scrollback_current = 0;
1336
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001338 int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339{
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001340 struct display *p, *t;
1341 struct vc_data **default_mode, *vc;
1342 struct vc_data *svc;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001343 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 int rows, cols, charcnt = 256;
1345
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001346 p = &fb_display[unit];
1347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 if (var_to_display(p, var, info))
1349 return;
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001350
1351 vc = vc_cons[unit].d;
1352
1353 if (!vc)
1354 return;
1355
1356 default_mode = vc->vc_display_fg;
1357 svc = *default_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 t = &fb_display[svc->vc_num];
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07001359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001361 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 vc->vc_font.width = (*default_mode)->vc_font.width;
1363 vc->vc_font.height = (*default_mode)->vc_font.height;
1364 p->userfont = t->userfont;
1365 if (p->userfont)
1366 REFCOUNT(p->fontdata)++;
1367 }
1368 if (p->userfont)
1369 charcnt = FNTCHARCNT(p->fontdata);
1370
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001371 var->activate = FB_ACTIVATE_NOW;
1372 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001373 var->yoffset = info->var.yoffset;
1374 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001375 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001376 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001377 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1379 if (charcnt == 256) {
1380 vc->vc_hi_font_mask = 0;
1381 } else {
1382 vc->vc_hi_font_mask = 0x100;
1383 if (vc->vc_can_do_color)
1384 vc->vc_complement_mask <<= 1;
1385 }
1386
1387 if (!*svc->vc_uni_pagedir_loc)
1388 con_set_default_unimap(svc);
1389 if (!*vc->vc_uni_pagedir_loc)
1390 con_copy_unimap(vc, svc);
1391
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001392 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1393 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1394 cols /= vc->vc_font.width;
1395 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001397
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02001398 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001400 if (softback_buf)
1401 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 }
1403}
1404
1405static __inline__ void ywrap_up(struct vc_data *vc, int count)
1406{
1407 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001408 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 struct display *p = &fb_display[vc->vc_num];
1410
1411 p->yscroll += count;
1412 if (p->yscroll >= p->vrows) /* Deal with wrap */
1413 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001414 ops->var.xoffset = 0;
1415 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1416 ops->var.vmode |= FB_VMODE_YWRAP;
1417 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 scrollback_max += count;
1419 if (scrollback_max > scrollback_phys_max)
1420 scrollback_max = scrollback_phys_max;
1421 scrollback_current = 0;
1422}
1423
1424static __inline__ void ywrap_down(struct vc_data *vc, int count)
1425{
1426 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001427 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 struct display *p = &fb_display[vc->vc_num];
1429
1430 p->yscroll -= count;
1431 if (p->yscroll < 0) /* Deal with wrap */
1432 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001433 ops->var.xoffset = 0;
1434 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1435 ops->var.vmode |= FB_VMODE_YWRAP;
1436 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 scrollback_max -= count;
1438 if (scrollback_max < 0)
1439 scrollback_max = 0;
1440 scrollback_current = 0;
1441}
1442
1443static __inline__ void ypan_up(struct vc_data *vc, int count)
1444{
1445 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1446 struct display *p = &fb_display[vc->vc_num];
1447 struct fbcon_ops *ops = info->fbcon_par;
1448
1449 p->yscroll += count;
1450 if (p->yscroll > p->vrows - vc->vc_rows) {
1451 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1452 0, 0, 0, vc->vc_rows, vc->vc_cols);
1453 p->yscroll -= p->vrows - vc->vc_rows;
1454 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001455
1456 ops->var.xoffset = 0;
1457 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1458 ops->var.vmode &= ~FB_VMODE_YWRAP;
1459 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 fbcon_clear_margins(vc, 1);
1461 scrollback_max += count;
1462 if (scrollback_max > scrollback_phys_max)
1463 scrollback_max = scrollback_phys_max;
1464 scrollback_current = 0;
1465}
1466
1467static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1468{
1469 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001470 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001474
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 if (p->yscroll > p->vrows - vc->vc_rows) {
1476 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001478 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001479
1480 ops->var.xoffset = 0;
1481 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1482 ops->var.vmode &= ~FB_VMODE_YWRAP;
1483 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 fbcon_clear_margins(vc, 1);
1485 scrollback_max += count;
1486 if (scrollback_max > scrollback_phys_max)
1487 scrollback_max = scrollback_phys_max;
1488 scrollback_current = 0;
1489}
1490
1491static __inline__ void ypan_down(struct vc_data *vc, int count)
1492{
1493 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1494 struct display *p = &fb_display[vc->vc_num];
1495 struct fbcon_ops *ops = info->fbcon_par;
1496
1497 p->yscroll -= count;
1498 if (p->yscroll < 0) {
1499 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1500 0, vc->vc_rows, vc->vc_cols);
1501 p->yscroll += p->vrows - vc->vc_rows;
1502 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001503
1504 ops->var.xoffset = 0;
1505 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1506 ops->var.vmode &= ~FB_VMODE_YWRAP;
1507 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 fbcon_clear_margins(vc, 1);
1509 scrollback_max -= count;
1510 if (scrollback_max < 0)
1511 scrollback_max = 0;
1512 scrollback_current = 0;
1513}
1514
1515static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1516{
1517 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001518 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 if (p->yscroll < 0) {
1524 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001526 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001527
1528 ops->var.xoffset = 0;
1529 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1530 ops->var.vmode &= ~FB_VMODE_YWRAP;
1531 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 fbcon_clear_margins(vc, 1);
1533 scrollback_max -= count;
1534 if (scrollback_max < 0)
1535 scrollback_max = 0;
1536 scrollback_current = 0;
1537}
1538
1539static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1540 long delta)
1541{
1542 int count = vc->vc_rows;
1543 unsigned short *d, *s;
1544 unsigned long n;
1545 int line = 0;
1546
1547 d = (u16 *) softback_curr;
1548 if (d == (u16 *) softback_in)
1549 d = (u16 *) vc->vc_origin;
1550 n = softback_curr + delta * vc->vc_size_row;
1551 softback_lines -= delta;
1552 if (delta < 0) {
1553 if (softback_curr < softback_top && n < softback_buf) {
1554 n += softback_end - softback_buf;
1555 if (n < softback_top) {
1556 softback_lines -=
1557 (softback_top - n) / vc->vc_size_row;
1558 n = softback_top;
1559 }
1560 } else if (softback_curr >= softback_top
1561 && n < softback_top) {
1562 softback_lines -=
1563 (softback_top - n) / vc->vc_size_row;
1564 n = softback_top;
1565 }
1566 } else {
1567 if (softback_curr > softback_in && n >= softback_end) {
1568 n += softback_buf - softback_end;
1569 if (n > softback_in) {
1570 n = softback_in;
1571 softback_lines = 0;
1572 }
1573 } else if (softback_curr <= softback_in && n > softback_in) {
1574 n = softback_in;
1575 softback_lines = 0;
1576 }
1577 }
1578 if (n == softback_curr)
1579 return;
1580 softback_curr = n;
1581 s = (u16 *) softback_curr;
1582 if (s == (u16 *) softback_in)
1583 s = (u16 *) vc->vc_origin;
1584 while (count--) {
1585 unsigned short *start;
1586 unsigned short *le;
1587 unsigned short c;
1588 int x = 0;
1589 unsigned short attr = 1;
1590
1591 start = s;
1592 le = advance_row(s, 1);
1593 do {
1594 c = scr_readw(s);
1595 if (attr != (c & 0xff00)) {
1596 attr = c & 0xff00;
1597 if (s > start) {
1598 fbcon_putcs(vc, start, s - start,
1599 line, x);
1600 x += s - start;
1601 start = s;
1602 }
1603 }
1604 if (c == scr_readw(d)) {
1605 if (s > start) {
1606 fbcon_putcs(vc, start, s - start,
1607 line, x);
1608 x += s - start + 1;
1609 start = s + 1;
1610 } else {
1611 x++;
1612 start++;
1613 }
1614 }
1615 s++;
1616 d++;
1617 } while (s < le);
1618 if (s > start)
1619 fbcon_putcs(vc, start, s - start, line, x);
1620 line++;
1621 if (d == (u16 *) softback_end)
1622 d = (u16 *) softback_buf;
1623 if (d == (u16 *) softback_in)
1624 d = (u16 *) vc->vc_origin;
1625 if (s == (u16 *) softback_end)
1626 s = (u16 *) softback_buf;
1627 if (s == (u16 *) softback_in)
1628 s = (u16 *) vc->vc_origin;
1629 }
1630}
1631
1632static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1633 int line, int count, int dy)
1634{
1635 unsigned short *s = (unsigned short *)
1636 (vc->vc_origin + vc->vc_size_row * line);
1637
1638 while (count--) {
1639 unsigned short *start = s;
1640 unsigned short *le = advance_row(s, 1);
1641 unsigned short c;
1642 int x = 0;
1643 unsigned short attr = 1;
1644
1645 do {
1646 c = scr_readw(s);
1647 if (attr != (c & 0xff00)) {
1648 attr = c & 0xff00;
1649 if (s > start) {
1650 fbcon_putcs(vc, start, s - start,
1651 dy, x);
1652 x += s - start;
1653 start = s;
1654 }
1655 }
1656 console_conditional_schedule();
1657 s++;
1658 } while (s < le);
1659 if (s > start)
1660 fbcon_putcs(vc, start, s - start, dy, x);
1661 console_conditional_schedule();
1662 dy++;
1663 }
1664}
1665
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001666static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1667 struct display *p, int line, int count, int ycount)
1668{
1669 int offset = ycount * vc->vc_cols;
1670 unsigned short *d = (unsigned short *)
1671 (vc->vc_origin + vc->vc_size_row * line);
1672 unsigned short *s = d + offset;
1673 struct fbcon_ops *ops = info->fbcon_par;
1674
1675 while (count--) {
1676 unsigned short *start = s;
1677 unsigned short *le = advance_row(s, 1);
1678 unsigned short c;
1679 int x = 0;
1680
1681 do {
1682 c = scr_readw(s);
1683
1684 if (c == scr_readw(d)) {
1685 if (s > start) {
1686 ops->bmove(vc, info, line + ycount, x,
1687 line, x, 1, s-start);
1688 x += s - start + 1;
1689 start = s + 1;
1690 } else {
1691 x++;
1692 start++;
1693 }
1694 }
1695
1696 scr_writew(c, d);
1697 console_conditional_schedule();
1698 s++;
1699 d++;
1700 } while (s < le);
1701 if (s > start)
1702 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1703 s-start);
1704 console_conditional_schedule();
1705 if (ycount > 0)
1706 line++;
1707 else {
1708 line--;
1709 /* NOTE: We subtract two lines from these pointers */
1710 s -= vc->vc_size_row;
1711 d -= vc->vc_size_row;
1712 }
1713 }
1714}
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716static void fbcon_redraw(struct vc_data *vc, struct display *p,
1717 int line, int count, int offset)
1718{
1719 unsigned short *d = (unsigned short *)
1720 (vc->vc_origin + vc->vc_size_row * line);
1721 unsigned short *s = d + offset;
1722
1723 while (count--) {
1724 unsigned short *start = s;
1725 unsigned short *le = advance_row(s, 1);
1726 unsigned short c;
1727 int x = 0;
1728 unsigned short attr = 1;
1729
1730 do {
1731 c = scr_readw(s);
1732 if (attr != (c & 0xff00)) {
1733 attr = c & 0xff00;
1734 if (s > start) {
1735 fbcon_putcs(vc, start, s - start,
1736 line, x);
1737 x += s - start;
1738 start = s;
1739 }
1740 }
1741 if (c == scr_readw(d)) {
1742 if (s > start) {
1743 fbcon_putcs(vc, start, s - start,
1744 line, x);
1745 x += s - start + 1;
1746 start = s + 1;
1747 } else {
1748 x++;
1749 start++;
1750 }
1751 }
1752 scr_writew(c, d);
1753 console_conditional_schedule();
1754 s++;
1755 d++;
1756 } while (s < le);
1757 if (s > start)
1758 fbcon_putcs(vc, start, s - start, line, x);
1759 console_conditional_schedule();
1760 if (offset > 0)
1761 line++;
1762 else {
1763 line--;
1764 /* NOTE: We subtract two lines from these pointers */
1765 s -= vc->vc_size_row;
1766 d -= vc->vc_size_row;
1767 }
1768 }
1769}
1770
1771static inline void fbcon_softback_note(struct vc_data *vc, int t,
1772 int count)
1773{
1774 unsigned short *p;
1775
1776 if (vc->vc_num != fg_console)
1777 return;
1778 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1779
1780 while (count) {
1781 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1782 count--;
1783 p = advance_row(p, 1);
1784 softback_in += vc->vc_size_row;
1785 if (softback_in == softback_end)
1786 softback_in = softback_buf;
1787 if (softback_in == softback_top) {
1788 softback_top += vc->vc_size_row;
1789 if (softback_top == softback_end)
1790 softback_top = softback_buf;
1791 }
1792 }
1793 softback_curr = softback_in;
1794}
1795
Jiri Slabyd705ff32016-10-03 11:18:33 +02001796static bool fbcon_scroll(struct vc_data *vc, unsigned int t, unsigned int b,
1797 enum con_scroll dir, unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798{
1799 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1800 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1802
1803 if (fbcon_is_inactive(vc, info))
Jiri Slabyd705ff32016-10-03 11:18:33 +02001804 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
1806 fbcon_cursor(vc, CM_ERASE);
1807
1808 /*
1809 * ++Geert: Only use ywrap/ypan if the console is in text mode
1810 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1811 * whole screen (prevents flicker).
1812 */
1813
1814 switch (dir) {
1815 case SM_UP:
1816 if (count > vc->vc_rows) /* Maximum realistic size */
1817 count = vc->vc_rows;
1818 if (softback_top)
1819 fbcon_softback_note(vc, t, count);
1820 if (logo_shown >= 0)
1821 goto redraw_up;
1822 switch (p->scrollmode) {
1823 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001824 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1825 count);
1826 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1827 scr_memsetw((unsigned short *) (vc->vc_origin +
1828 vc->vc_size_row *
1829 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001830 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001831 vc->vc_size_row * count);
Jiri Slabyd705ff32016-10-03 11:18:33 +02001832 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 break;
1834
1835 case SCROLL_WRAP_MOVE:
1836 if (b - t - count > 3 * vc->vc_rows >> 2) {
1837 if (t > 0)
1838 fbcon_bmove(vc, 0, 0, count, 0, t,
1839 vc->vc_cols);
1840 ywrap_up(vc, count);
1841 if (vc->vc_rows - b > 0)
1842 fbcon_bmove(vc, b - count, 0, b, 0,
1843 vc->vc_rows - b,
1844 vc->vc_cols);
1845 } else if (info->flags & FBINFO_READS_FAST)
1846 fbcon_bmove(vc, t + count, 0, t, 0,
1847 b - t - count, vc->vc_cols);
1848 else
1849 goto redraw_up;
1850 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1851 break;
1852
1853 case SCROLL_PAN_REDRAW:
1854 if ((p->yscroll + count <=
1855 2 * (p->vrows - vc->vc_rows))
1856 && ((!scroll_partial && (b - t == vc->vc_rows))
1857 || (scroll_partial
1858 && (b - t - count >
1859 3 * vc->vc_rows >> 2)))) {
1860 if (t > 0)
1861 fbcon_redraw_move(vc, p, 0, t, count);
1862 ypan_up_redraw(vc, t, count);
1863 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001864 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 vc->vc_rows - b, b);
1866 } else
1867 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1868 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1869 break;
1870
1871 case SCROLL_PAN_MOVE:
1872 if ((p->yscroll + count <=
1873 2 * (p->vrows - vc->vc_rows))
1874 && ((!scroll_partial && (b - t == vc->vc_rows))
1875 || (scroll_partial
1876 && (b - t - count >
1877 3 * vc->vc_rows >> 2)))) {
1878 if (t > 0)
1879 fbcon_bmove(vc, 0, 0, count, 0, t,
1880 vc->vc_cols);
1881 ypan_up(vc, count);
1882 if (vc->vc_rows - b > 0)
1883 fbcon_bmove(vc, b - count, 0, b, 0,
1884 vc->vc_rows - b,
1885 vc->vc_cols);
1886 } else if (info->flags & FBINFO_READS_FAST)
1887 fbcon_bmove(vc, t + count, 0, t, 0,
1888 b - t - count, vc->vc_cols);
1889 else
1890 goto redraw_up;
1891 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1892 break;
1893
1894 case SCROLL_REDRAW:
1895 redraw_up:
1896 fbcon_redraw(vc, p, t, b - t - count,
1897 count * vc->vc_cols);
1898 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1899 scr_memsetw((unsigned short *) (vc->vc_origin +
1900 vc->vc_size_row *
1901 (b - count)),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001902 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 vc->vc_size_row * count);
Jiri Slabyd705ff32016-10-03 11:18:33 +02001904 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 }
1906 break;
1907
1908 case SM_DOWN:
1909 if (count > vc->vc_rows) /* Maximum realistic size */
1910 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001911 if (logo_shown >= 0)
1912 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 switch (p->scrollmode) {
1914 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001915 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1916 -count);
1917 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1918 scr_memsetw((unsigned short *) (vc->vc_origin +
1919 vc->vc_size_row *
1920 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001921 vc->vc_video_erase_char,
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001922 vc->vc_size_row * count);
Jiri Slabyd705ff32016-10-03 11:18:33 +02001923 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 break;
1925
1926 case SCROLL_WRAP_MOVE:
1927 if (b - t - count > 3 * vc->vc_rows >> 2) {
1928 if (vc->vc_rows - b > 0)
1929 fbcon_bmove(vc, b, 0, b - count, 0,
1930 vc->vc_rows - b,
1931 vc->vc_cols);
1932 ywrap_down(vc, count);
1933 if (t > 0)
1934 fbcon_bmove(vc, count, 0, 0, 0, t,
1935 vc->vc_cols);
1936 } else if (info->flags & FBINFO_READS_FAST)
1937 fbcon_bmove(vc, t, 0, t + count, 0,
1938 b - t - count, vc->vc_cols);
1939 else
1940 goto redraw_down;
1941 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1942 break;
1943
1944 case SCROLL_PAN_MOVE:
1945 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1946 && ((!scroll_partial && (b - t == vc->vc_rows))
1947 || (scroll_partial
1948 && (b - t - count >
1949 3 * vc->vc_rows >> 2)))) {
1950 if (vc->vc_rows - b > 0)
1951 fbcon_bmove(vc, b, 0, b - count, 0,
1952 vc->vc_rows - b,
1953 vc->vc_cols);
1954 ypan_down(vc, count);
1955 if (t > 0)
1956 fbcon_bmove(vc, count, 0, 0, 0, t,
1957 vc->vc_cols);
1958 } else if (info->flags & FBINFO_READS_FAST)
1959 fbcon_bmove(vc, t, 0, t + count, 0,
1960 b - t - count, vc->vc_cols);
1961 else
1962 goto redraw_down;
1963 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1964 break;
1965
1966 case SCROLL_PAN_REDRAW:
1967 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1968 && ((!scroll_partial && (b - t == vc->vc_rows))
1969 || (scroll_partial
1970 && (b - t - count >
1971 3 * vc->vc_rows >> 2)))) {
1972 if (vc->vc_rows - b > 0)
1973 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
1974 b - count);
1975 ypan_down_redraw(vc, t, count);
1976 if (t > 0)
1977 fbcon_redraw_move(vc, p, count, t, 0);
1978 } else
1979 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
1980 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1981 break;
1982
1983 case SCROLL_REDRAW:
1984 redraw_down:
1985 fbcon_redraw(vc, p, b - 1, b - t - count,
1986 -count * vc->vc_cols);
1987 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1988 scr_memsetw((unsigned short *) (vc->vc_origin +
1989 vc->vc_size_row *
1990 t),
Linus Torvalds93f78da2008-10-14 12:12:02 -07001991 vc->vc_video_erase_char,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 vc->vc_size_row * count);
Jiri Slabyd705ff32016-10-03 11:18:33 +02001993 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 }
1995 }
Jiri Slabyd705ff32016-10-03 11:18:33 +02001996 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997}
1998
1999
2000static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2001 int height, int width)
2002{
2003 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2004 struct display *p = &fb_display[vc->vc_num];
2005
2006 if (fbcon_is_inactive(vc, info))
2007 return;
2008
2009 if (!width || !height)
2010 return;
2011
2012 /* Split blits that cross physical y_wrap case.
2013 * Pathological case involves 4 blits, better to use recursive
2014 * code rather than unrolled case
2015 *
2016 * Recursive invocations don't need to erase the cursor over and
2017 * over again, so we use fbcon_bmove_rec()
2018 */
2019 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2020 p->vrows - p->yscroll);
2021}
2022
2023static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2024 int dy, int dx, int height, int width, u_int y_break)
2025{
2026 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2027 struct fbcon_ops *ops = info->fbcon_par;
2028 u_int b;
2029
2030 if (sy < y_break && sy + height > y_break) {
2031 b = y_break - sy;
2032 if (dy < sy) { /* Avoid trashing self */
2033 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2034 y_break);
2035 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2036 height - b, width, y_break);
2037 } else {
2038 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2039 height - b, width, y_break);
2040 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2041 y_break);
2042 }
2043 return;
2044 }
2045
2046 if (dy < y_break && dy + height > y_break) {
2047 b = y_break - dy;
2048 if (dy < sy) { /* Avoid trashing self */
2049 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2050 y_break);
2051 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2052 height - b, width, y_break);
2053 } else {
2054 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2055 height - b, width, y_break);
2056 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2057 y_break);
2058 }
2059 return;
2060 }
2061 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2062 height, width);
2063}
2064
Marcin Slusarzdef1be22008-10-29 14:01:01 -07002065static void updatescrollmode(struct display *p,
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002066 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 struct vc_data *vc)
2068{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002069 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 int fh = vc->vc_font.height;
2071 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002072 u16 t = 0;
2073 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2074 info->fix.xpanstep);
2075 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2076 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2077 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2078 info->var.xres_virtual);
2079 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2080 divides(ypan, vc->vc_font.height) && vyres > yres;
2081 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2082 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002083 divides(vc->vc_font.height, vyres) &&
2084 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002086 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2087 !(cap & FBINFO_HWACCEL_DISABLED);
2088 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2089 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002091 p->vrows = vyres/fh;
2092 if (yres > (fh * (vc->vc_rows + 1)))
2093 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2094 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 p->vrows--;
2096
2097 if (good_wrap || good_pan) {
2098 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002099 p->scrollmode = good_wrap ?
2100 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 else
2102 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2103 SCROLL_PAN_REDRAW;
2104 } else {
2105 if (reading_fast || (fast_copyarea && !fast_imageblit))
2106 p->scrollmode = SCROLL_MOVE;
2107 else
2108 p->scrollmode = SCROLL_REDRAW;
2109 }
2110}
2111
2112static int fbcon_resize(struct vc_data *vc, unsigned int width,
Antonino A. Daplase400b6e2007-10-16 01:29:35 -07002113 unsigned int height, unsigned int user)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
2115 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002116 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct display *p = &fb_display[vc->vc_num];
2118 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002119 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002121 virt_w = FBCON_SWAP(ops->rotate, width, height);
2122 virt_h = FBCON_SWAP(ops->rotate, height, width);
2123 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2124 vc->vc_font.height);
2125 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2126 vc->vc_font.width);
2127 var.xres = virt_w * virt_fw;
2128 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 x_diff = info->var.xres - var.xres;
2130 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002131 if (x_diff < 0 || x_diff > virt_fw ||
2132 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002133 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
2135 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2136 mode = fb_find_best_mode(&var, &info->modelist);
2137 if (mode == NULL)
2138 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002139 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002141
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002142 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144
2145 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002146 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 var.activate = FB_ACTIVATE_NOW |
2148 FB_ACTIVATE_FORCE;
2149 fb_set_var(info, &var);
2150 }
2151 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002152 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 }
2154 updatescrollmode(p, info, vc);
2155 return 0;
2156}
2157
2158static int fbcon_switch(struct vc_data *vc)
2159{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002160 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002161 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 struct display *p = &fb_display[vc->vc_num];
2163 struct fb_var_screeninfo var;
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002164 int i, ret, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
2166 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002167 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 if (softback_lines)
2171 fbcon_set_origin(vc);
2172 softback_top = softback_curr = softback_in = softback_buf;
2173 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002174 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 }
2176
2177 if (logo_shown >= 0) {
2178 struct vc_data *conp2 = vc_cons[logo_shown].d;
2179
2180 if (conp2->vc_top == logo_lines
2181 && conp2->vc_bottom == conp2->vc_rows)
2182 conp2->vc_top = 0;
2183 logo_shown = FBCON_LOGO_CANSHOW;
2184 }
2185
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002186 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002187 if (prev_console != -1)
2188 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 /*
2190 * FIXME: If we have multiple fbdev's loaded, we need to
2191 * update all info->currcon. Perhaps, we can place this
2192 * in a centralized structure, but this might break some
2193 * drivers.
2194 *
2195 * info->currcon = vc->vc_num;
2196 */
2197 for (i = 0; i < FB_MAX; i++) {
2198 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002199 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002201 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
2203 }
2204 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2205 display_to_var(&var, p);
2206 var.activate = FB_ACTIVATE_NOW;
2207
2208 /*
2209 * make sure we don't unnecessarily trip the memcmp()
2210 * in fb_set_var()
2211 */
2212 info->var.activate = var.activate;
Krzysztof Helt10732c32008-06-05 22:46:33 -07002213 var.vmode |= info->var.vmode & ~FB_VMODE_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002215 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Knut Petersen39942fd2005-12-12 22:17:19 -08002217 if (old_info != NULL && (old_info != info ||
2218 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Florian Tobias Schandinat0fcf6ad2009-09-22 16:47:44 -07002219 if (info->fbops->fb_set_par) {
2220 ret = info->fbops->fb_set_par(info);
2221
2222 if (ret)
2223 printk(KERN_ERR "fbcon_switch: detected "
2224 "unhandled fb_set_par error, "
2225 "error code %d\n", ret);
2226 }
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002227
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002228 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002229 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002232 if (fbcon_is_inactive(vc, info) ||
2233 ops->blank_state != FB_BLANK_UNBLANK)
2234 fbcon_del_cursor_timer(info);
2235 else
2236 fbcon_add_cursor_timer(info);
2237
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002238 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002239 ops->cursor_reset = 1;
2240
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002241 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002242 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002243 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002246 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002248
2249 if (p->userfont)
2250 charcnt = FNTCHARCNT(vc->vc_font.data);
2251
2252 if (charcnt > 256)
2253 vc->vc_complement_mask <<= 1;
2254
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 updatescrollmode(p, info, vc);
2256
2257 switch (p->scrollmode) {
2258 case SCROLL_WRAP_MOVE:
2259 scrollback_phys_max = p->vrows - vc->vc_rows;
2260 break;
2261 case SCROLL_PAN_MOVE:
2262 case SCROLL_PAN_REDRAW:
2263 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2264 if (scrollback_phys_max < 0)
2265 scrollback_phys_max = 0;
2266 break;
2267 default:
2268 scrollback_phys_max = 0;
2269 break;
2270 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002271
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 scrollback_max = 0;
2273 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002274
2275 if (!fbcon_is_inactive(vc, info)) {
2276 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2277 ops->update_start(info);
2278 }
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 fbcon_set_palette(vc, color_table);
2281 fbcon_clear_margins(vc, 0);
2282
2283 if (logo_shown == FBCON_LOGO_DRAW) {
2284
2285 logo_shown = fg_console;
2286 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002287 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 update_region(vc,
2289 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2290 vc->vc_size_row * (vc->vc_bottom -
2291 vc->vc_top) / 2);
2292 return 0;
2293 }
2294 return 1;
2295}
2296
2297static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2298 int blank)
2299{
Richard Purdie994efac2007-02-09 09:46:45 +00002300 struct fb_event event;
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 if (blank) {
2303 unsigned short charmask = vc->vc_hi_font_mask ?
2304 0x1ff : 0xff;
2305 unsigned short oldc;
2306
2307 oldc = vc->vc_video_erase_char;
2308 vc->vc_video_erase_char &= charmask;
2309 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2310 vc->vc_video_erase_char = oldc;
2311 }
Richard Purdie994efac2007-02-09 09:46:45 +00002312
2313
Andrea Righi513adb52009-04-13 14:39:39 -07002314 if (!lock_fb_info(info))
2315 return;
Richard Purdie994efac2007-02-09 09:46:45 +00002316 event.info = info;
2317 event.data = &blank;
2318 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Andrea Righi513adb52009-04-13 14:39:39 -07002319 unlock_fb_info(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320}
2321
2322static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2323{
2324 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2325 struct fbcon_ops *ops = info->fbcon_par;
2326
2327 if (mode_switch) {
2328 struct fb_var_screeninfo var = info->var;
2329
2330 ops->graphics = 1;
2331
2332 if (!blank) {
2333 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2334 fb_set_var(info, &var);
2335 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002336 ops->var = info->var;
Krzysztof Heltf5c15d02009-11-11 14:26:22 -08002337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 }
2339
2340 if (!fbcon_is_inactive(vc, info)) {
2341 if (ops->blank_state != blank) {
2342 ops->blank_state = blank;
2343 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2344 ops->cursor_flash = (!blank);
2345
Dmitry Baryshkovbca404a2008-12-01 13:14:05 -08002346 if (!(info->flags & FBINFO_MISC_USEREVENT))
2347 if (fb_blank(info, blank))
2348 fbcon_generic_blank(vc, info, blank);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 }
2350
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002351 if (!blank)
2352 update_screen(vc);
2353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
Antonino Daplas4d8a2d92007-10-16 01:29:55 -07002355 if (mode_switch || fbcon_is_inactive(vc, info) ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002356 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002357 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002358 else
2359 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002360
2361 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362}
2363
Jesse Barnesd219adc2010-08-02 12:05:41 -07002364static int fbcon_debug_enter(struct vc_data *vc)
2365{
2366 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2367 struct fbcon_ops *ops = info->fbcon_par;
2368
2369 ops->save_graphics = ops->graphics;
2370 ops->graphics = 0;
2371 if (info->fbops->fb_debug_enter)
2372 info->fbops->fb_debug_enter(info);
2373 fbcon_set_palette(vc, color_table);
2374 return 0;
2375}
2376
2377static int fbcon_debug_leave(struct vc_data *vc)
2378{
2379 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2380 struct fbcon_ops *ops = info->fbcon_par;
2381
2382 ops->graphics = ops->save_graphics;
2383 if (info->fbops->fb_debug_leave)
2384 info->fbops->fb_debug_leave(info);
2385 return 0;
2386}
2387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2389{
2390 u8 *fontdata = vc->vc_font.data;
2391 u8 *data = font->data;
2392 int i, j;
2393
2394 font->width = vc->vc_font.width;
2395 font->height = vc->vc_font.height;
2396 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2397 if (!font->data)
2398 return 0;
2399
2400 if (font->width <= 8) {
2401 j = vc->vc_font.height;
2402 for (i = 0; i < font->charcount; i++) {
2403 memcpy(data, fontdata, j);
2404 memset(data + j, 0, 32 - j);
2405 data += 32;
2406 fontdata += j;
2407 }
2408 } else if (font->width <= 16) {
2409 j = vc->vc_font.height * 2;
2410 for (i = 0; i < font->charcount; i++) {
2411 memcpy(data, fontdata, j);
2412 memset(data + j, 0, 64 - j);
2413 data += 64;
2414 fontdata += j;
2415 }
2416 } else if (font->width <= 24) {
2417 for (i = 0; i < font->charcount; i++) {
2418 for (j = 0; j < vc->vc_font.height; j++) {
2419 *data++ = fontdata[0];
2420 *data++ = fontdata[1];
2421 *data++ = fontdata[2];
2422 fontdata += sizeof(u32);
2423 }
2424 memset(data, 0, 3 * (32 - j));
2425 data += 3 * (32 - j);
2426 }
2427 } else {
2428 j = vc->vc_font.height * 4;
2429 for (i = 0; i < font->charcount; i++) {
2430 memcpy(data, fontdata, j);
2431 memset(data + j, 0, 128 - j);
2432 data += 128;
2433 fontdata += j;
2434 }
2435 }
2436 return 0;
2437}
2438
2439static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002440 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441{
2442 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002443 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 struct display *p = &fb_display[vc->vc_num];
2445 int resize;
2446 int cnt;
2447 char *old_data = NULL;
2448
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002449 if (con_is_visible(vc) && softback_lines)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 fbcon_set_origin(vc);
2451
2452 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2453 if (p->userfont)
2454 old_data = vc->vc_font.data;
2455 if (userfont)
2456 cnt = FNTCHARCNT(data);
2457 else
2458 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002459 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 if ((p->userfont = userfont))
2461 REFCOUNT(data)++;
2462 vc->vc_font.width = w;
2463 vc->vc_font.height = h;
2464 if (vc->vc_hi_font_mask && cnt == 256) {
2465 vc->vc_hi_font_mask = 0;
2466 if (vc->vc_can_do_color) {
2467 vc->vc_complement_mask >>= 1;
2468 vc->vc_s_complement_mask >>= 1;
2469 }
2470
2471 /* ++Edmund: reorder the attribute bits */
2472 if (vc->vc_can_do_color) {
2473 unsigned short *cp =
2474 (unsigned short *) vc->vc_origin;
2475 int count = vc->vc_screenbuf_size / 2;
2476 unsigned short c;
2477 for (; count > 0; count--, cp++) {
2478 c = scr_readw(cp);
2479 scr_writew(((c & 0xfe00) >> 1) |
2480 (c & 0xff), cp);
2481 }
2482 c = vc->vc_video_erase_char;
2483 vc->vc_video_erase_char =
2484 ((c & 0xfe00) >> 1) | (c & 0xff);
2485 vc->vc_attr >>= 1;
2486 }
2487 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2488 vc->vc_hi_font_mask = 0x100;
2489 if (vc->vc_can_do_color) {
2490 vc->vc_complement_mask <<= 1;
2491 vc->vc_s_complement_mask <<= 1;
2492 }
2493
2494 /* ++Edmund: reorder the attribute bits */
2495 {
2496 unsigned short *cp =
2497 (unsigned short *) vc->vc_origin;
2498 int count = vc->vc_screenbuf_size / 2;
2499 unsigned short c;
2500 for (; count > 0; count--, cp++) {
2501 unsigned short newc;
2502 c = scr_readw(cp);
2503 if (vc->vc_can_do_color)
2504 newc =
2505 ((c & 0xff00) << 1) | (c &
2506 0xff);
2507 else
2508 newc = c & ~0x100;
2509 scr_writew(newc, cp);
2510 }
2511 c = vc->vc_video_erase_char;
2512 if (vc->vc_can_do_color) {
2513 vc->vc_video_erase_char =
2514 ((c & 0xff00) << 1) | (c & 0xff);
2515 vc->vc_attr <<= 1;
Linus Torvalds93f78da2008-10-14 12:12:02 -07002516 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 vc->vc_video_erase_char = c & ~0x100;
2518 }
2519
2520 }
2521
2522 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002523 int cols, rows;
2524
2525 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2526 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2527 cols /= w;
2528 rows /= h;
2529 vc_resize(vc, cols, rows);
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002530 if (con_is_visible(vc) && softback_buf)
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002531 fbcon_update_softback(vc);
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002532 } else if (con_is_visible(vc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 && vc->vc_mode == KD_TEXT) {
2534 fbcon_clear_margins(vc, 0);
2535 update_screen(vc);
2536 }
2537
2538 if (old_data && (--REFCOUNT(old_data) == 0))
2539 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2540 return 0;
2541}
2542
2543static int fbcon_copy_font(struct vc_data *vc, int con)
2544{
2545 struct display *od = &fb_display[con];
2546 struct console_font *f = &vc->vc_font;
2547
2548 if (od->fontdata == f->data)
2549 return 0; /* already the same font... */
2550 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2551}
2552
2553/*
2554 * User asked to set font; we are guaranteed that
2555 * a) width and height are in range 1..32
2556 * b) charcount does not exceed 512
2557 * but lets not assume that, since someone might someday want to use larger
2558 * fonts. And charcount of 512 is small for unicode support.
2559 *
2560 * However, user space gives the font in 32 rows , regardless of
2561 * actual font height. So a new API is needed if support for larger fonts
2562 * is ever implemented.
2563 */
2564
2565static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2566{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002567 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 unsigned charcount = font->charcount;
2569 int w = font->width;
2570 int h = font->height;
2571 int size;
2572 int i, csum;
2573 u8 *new_data, *data = font->data;
2574 int pitch = (font->width+7) >> 3;
2575
2576 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2577 * If not this check should be changed to charcount < 256 */
2578 if (charcount != 256 && charcount != 512)
2579 return -EINVAL;
2580
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002581 /* Make sure drawing engine can handle the font */
2582 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2583 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2584 return -EINVAL;
2585
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002586 /* Make sure driver can handle the font length */
2587 if (fbcon_invalid_charcount(info, charcount))
2588 return -EINVAL;
2589
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 size = h * pitch * charcount;
2591
2592 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2593
2594 if (!new_data)
2595 return -ENOMEM;
2596
2597 new_data += FONT_EXTRA_WORDS * sizeof(int);
2598 FNTSIZE(new_data) = size;
2599 FNTCHARCNT(new_data) = charcount;
2600 REFCOUNT(new_data) = 0; /* usage counter */
2601 for (i=0; i< charcount; i++) {
2602 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2603 }
2604
2605 /* Since linux has a nice crc32 function use it for counting font
2606 * checksums. */
2607 csum = crc32(0, new_data, size);
2608
2609 FNTSUM(new_data) = csum;
2610 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002611 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 struct vc_data *tmp = vc_cons[i].d;
2613
2614 if (fb_display[i].userfont &&
2615 fb_display[i].fontdata &&
2616 FNTSUM(fb_display[i].fontdata) == csum &&
2617 FNTSIZE(fb_display[i].fontdata) == size &&
2618 tmp->vc_font.width == w &&
2619 !memcmp(fb_display[i].fontdata, new_data, size)) {
2620 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002621 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 break;
2623 }
2624 }
2625 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2626}
2627
2628static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2629{
2630 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002631 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
2633 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002634 f = get_default_font(info->var.xres, info->var.yres,
2635 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 else if (!(f = find_font(name)))
2637 return -ENOENT;
2638
2639 font->width = f->width;
2640 font->height = f->height;
2641 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2642}
2643
2644static u16 palette_red[16];
2645static u16 palette_green[16];
2646static u16 palette_blue[16];
2647
2648static struct fb_cmap palette_cmap = {
2649 0, 16, palette_red, palette_green, palette_blue, NULL
2650};
2651
Jiri Slaby709280d2016-06-23 13:34:27 +02002652static void fbcon_set_palette(struct vc_data *vc, const unsigned char *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
2654 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2655 int i, j, k, depth;
2656 u8 val;
2657
2658 if (fbcon_is_inactive(vc, info))
Jiri Slaby709280d2016-06-23 13:34:27 +02002659 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002661 if (!con_is_visible(vc))
Jiri Slaby709280d2016-06-23 13:34:27 +02002662 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002664 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 if (depth > 3) {
2666 for (i = j = 0; i < 16; i++) {
2667 k = table[i];
2668 val = vc->vc_palette[j++];
2669 palette_red[k] = (val << 8) | val;
2670 val = vc->vc_palette[j++];
2671 palette_green[k] = (val << 8) | val;
2672 val = vc->vc_palette[j++];
2673 palette_blue[k] = (val << 8) | val;
2674 }
2675 palette_cmap.len = 16;
2676 palette_cmap.start = 0;
2677 /*
2678 * If framebuffer is capable of less than 16 colors,
2679 * use default palette of fbcon.
2680 */
2681 } else
2682 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2683
Jiri Slaby709280d2016-06-23 13:34:27 +02002684 fb_set_cmap(&palette_cmap, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685}
2686
2687static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2688{
2689 unsigned long p;
2690 int line;
2691
2692 if (vc->vc_num != fg_console || !softback_lines)
2693 return (u16 *) (vc->vc_origin + offset);
2694 line = offset / vc->vc_size_row;
2695 if (line >= softback_lines)
2696 return (u16 *) (vc->vc_origin + offset -
2697 softback_lines * vc->vc_size_row);
2698 p = softback_curr + offset;
2699 if (p >= softback_end)
2700 p += softback_buf - softback_end;
2701 return (u16 *) p;
2702}
2703
2704static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2705 int *px, int *py)
2706{
2707 unsigned long ret;
2708 int x, y;
2709
2710 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2711 unsigned long offset = (pos - vc->vc_origin) / 2;
2712
2713 x = offset % vc->vc_cols;
2714 y = offset / vc->vc_cols;
2715 if (vc->vc_num == fg_console)
2716 y += softback_lines;
2717 ret = pos + (vc->vc_cols - x) * 2;
2718 } else if (vc->vc_num == fg_console && softback_lines) {
2719 unsigned long offset = pos - softback_curr;
2720
2721 if (pos < softback_curr)
2722 offset += softback_end - softback_buf;
2723 offset /= 2;
2724 x = offset % vc->vc_cols;
2725 y = offset / vc->vc_cols;
2726 ret = pos + (vc->vc_cols - x) * 2;
2727 if (ret == softback_end)
2728 ret = softback_buf;
2729 if (ret == softback_in)
2730 ret = vc->vc_origin;
2731 } else {
2732 /* Should not happen */
2733 x = y = 0;
2734 ret = vc->vc_origin;
2735 }
2736 if (px)
2737 *px = x;
2738 if (py)
2739 *py = y;
2740 return ret;
2741}
2742
2743/* As we might be inside of softback, we may work with non-contiguous buffer,
2744 that's why we have to use a separate routine. */
2745static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2746{
2747 while (cnt--) {
2748 u16 a = scr_readw(p);
2749 if (!vc->vc_can_do_color)
2750 a ^= 0x0800;
2751 else if (vc->vc_hi_font_mask == 0x100)
2752 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2753 (((a) & 0x0e00) << 4);
2754 else
2755 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2756 (((a) & 0x0700) << 4);
2757 scr_writew(a, p++);
2758 if (p == (u16 *) softback_end)
2759 p = (u16 *) softback_buf;
2760 if (p == (u16 *) softback_in)
2761 p = (u16 *) vc->vc_origin;
2762 }
2763}
2764
Jiri Slaby97293de2016-06-23 13:34:26 +02002765static void fbcon_scrolldelta(struct vc_data *vc, int lines)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766{
2767 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002768 struct fbcon_ops *ops = info->fbcon_par;
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002769 struct display *disp = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 int offset, limit, scrollback_old;
2771
2772 if (softback_top) {
2773 if (vc->vc_num != fg_console)
Jiri Slaby97293de2016-06-23 13:34:26 +02002774 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 if (vc->vc_mode != KD_TEXT || !lines)
Jiri Slaby97293de2016-06-23 13:34:26 +02002776 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (logo_shown >= 0) {
2778 struct vc_data *conp2 = vc_cons[logo_shown].d;
2779
2780 if (conp2->vc_top == logo_lines
2781 && conp2->vc_bottom == conp2->vc_rows)
2782 conp2->vc_top = 0;
2783 if (logo_shown == vc->vc_num) {
2784 unsigned long p, q;
2785 int i;
2786
2787 p = softback_in;
2788 q = vc->vc_origin +
2789 logo_lines * vc->vc_size_row;
2790 for (i = 0; i < logo_lines; i++) {
2791 if (p == softback_top)
2792 break;
2793 if (p == softback_buf)
2794 p = softback_end;
2795 p -= vc->vc_size_row;
2796 q -= vc->vc_size_row;
2797 scr_memcpyw((u16 *) q, (u16 *) p,
2798 vc->vc_size_row);
2799 }
David Hollister308af922006-05-30 21:25:36 -07002800 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 update_region(vc, vc->vc_origin,
2802 logo_lines * vc->vc_cols);
2803 }
2804 logo_shown = FBCON_LOGO_CANSHOW;
2805 }
2806 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002807 fbcon_redraw_softback(vc, disp, lines);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
Jiri Slaby97293de2016-06-23 13:34:26 +02002809 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 }
2811
2812 if (!scrollback_phys_max)
Jiri Slaby97293de2016-06-23 13:34:26 +02002813 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
2815 scrollback_old = scrollback_current;
2816 scrollback_current -= lines;
2817 if (scrollback_current < 0)
2818 scrollback_current = 0;
2819 else if (scrollback_current > scrollback_max)
2820 scrollback_current = scrollback_max;
2821 if (scrollback_current == scrollback_old)
Jiri Slaby97293de2016-06-23 13:34:26 +02002822 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823
2824 if (fbcon_is_inactive(vc, info))
Jiri Slaby97293de2016-06-23 13:34:26 +02002825 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826
2827 fbcon_cursor(vc, CM_ERASE);
2828
Marcin Slusarz2c6cc352008-02-06 01:39:13 -08002829 offset = disp->yscroll - scrollback_current;
2830 limit = disp->vrows;
2831 switch (disp->scrollmode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 case SCROLL_WRAP_MOVE:
2833 info->var.vmode |= FB_VMODE_YWRAP;
2834 break;
2835 case SCROLL_PAN_MOVE:
2836 case SCROLL_PAN_REDRAW:
2837 limit -= vc->vc_rows;
2838 info->var.vmode &= ~FB_VMODE_YWRAP;
2839 break;
2840 }
2841 if (offset < 0)
2842 offset += limit;
2843 else if (offset >= limit)
2844 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002845
2846 ops->var.xoffset = 0;
2847 ops->var.yoffset = offset * vc->vc_font.height;
2848 ops->update_start(info);
2849
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 if (!scrollback_current)
2851 fbcon_cursor(vc, CM_DRAW);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852}
2853
2854static int fbcon_set_origin(struct vc_data *vc)
2855{
2856 if (softback_lines)
2857 fbcon_scrolldelta(vc, softback_lines);
2858 return 0;
2859}
2860
2861static void fbcon_suspended(struct fb_info *info)
2862{
2863 struct vc_data *vc = NULL;
2864 struct fbcon_ops *ops = info->fbcon_par;
2865
2866 if (!ops || ops->currcon < 0)
2867 return;
2868 vc = vc_cons[ops->currcon].d;
2869
2870 /* Clear cursor, restore saved data */
2871 fbcon_cursor(vc, CM_ERASE);
2872}
2873
2874static void fbcon_resumed(struct fb_info *info)
2875{
2876 struct vc_data *vc;
2877 struct fbcon_ops *ops = info->fbcon_par;
2878
2879 if (!ops || ops->currcon < 0)
2880 return;
2881 vc = vc_cons[ops->currcon].d;
2882
2883 update_screen(vc);
2884}
2885
2886static void fbcon_modechanged(struct fb_info *info)
2887{
2888 struct fbcon_ops *ops = info->fbcon_par;
2889 struct vc_data *vc;
2890 struct display *p;
2891 int rows, cols;
2892
2893 if (!ops || ops->currcon < 0)
2894 return;
2895 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002896 if (vc->vc_mode != KD_TEXT ||
2897 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 return;
2899
2900 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002901 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002903 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002905 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2906 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2907 cols /= vc->vc_font.width;
2908 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 vc_resize(vc, cols, rows);
2910 updatescrollmode(p, info, vc);
2911 scrollback_max = 0;
2912 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002913
2914 if (!fbcon_is_inactive(vc, info)) {
2915 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2916 ops->update_start(info);
2917 }
2918
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 fbcon_set_palette(vc, color_table);
2920 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002921 if (softback_buf)
2922 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 }
2924}
2925
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002926static void fbcon_set_all_vcs(struct fb_info *info)
2927{
2928 struct fbcon_ops *ops = info->fbcon_par;
2929 struct vc_data *vc;
2930 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002931 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002932
2933 if (!ops || ops->currcon < 0)
2934 return;
2935
Antonino A. Daplase614b182006-06-26 00:27:09 -07002936 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002937 vc = vc_cons[i].d;
2938 if (!vc || vc->vc_mode != KD_TEXT ||
2939 registered_fb[con2fb_map[i]] != info)
2940 continue;
2941
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02002942 if (con_is_visible(vc)) {
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002943 fg = i;
2944 continue;
2945 }
2946
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002947 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002948 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002949 var_to_display(p, &info->var, info);
Oleg Nesterov232fb692008-10-15 22:03:57 -07002950 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2951 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002952 cols /= vc->vc_font.width;
2953 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002954 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002955 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002956
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002957 if (fg != -1)
2958 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002959}
2960
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961static int fbcon_mode_deleted(struct fb_info *info,
2962 struct fb_videomode *mode)
2963{
2964 struct fb_info *fb_info;
2965 struct display *p;
2966 int i, j, found = 0;
2967
2968 /* before deletion, ensure that mode is not in use */
2969 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2970 j = con2fb_map[i];
2971 if (j == -1)
2972 continue;
2973 fb_info = registered_fb[j];
2974 if (fb_info != info)
2975 continue;
2976 p = &fb_display[i];
2977 if (!p || !p->mode)
2978 continue;
2979 if (fb_mode_is_equal(p->mode, mode)) {
2980 found = 1;
2981 break;
2982 }
2983 }
2984 return found;
2985}
2986
Jesse Barnescfafca82007-07-17 04:05:33 -07002987#ifdef CONFIG_VT_HW_CONSOLE_BINDING
2988static int fbcon_unbind(void)
2989{
2990 int ret;
2991
Takashi Iwaie93a9a82013-01-25 10:28:18 +10002992 ret = do_unbind_con_driver(&fb_con, first_fb_vc, last_fb_vc,
Jesse Barnescfafca82007-07-17 04:05:33 -07002993 fbcon_is_default);
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07002994
2995 if (!ret)
2996 fbcon_has_console_bind = 0;
2997
Jesse Barnescfafca82007-07-17 04:05:33 -07002998 return ret;
2999}
3000#else
3001static inline int fbcon_unbind(void)
3002{
3003 return -EINVAL;
3004}
3005#endif /* CONFIG_VT_HW_CONSOLE_BINDING */
3006
Dave Airlie054430e2013-01-25 11:38:56 +10003007/* called with console_lock held */
Jesse Barnescfafca82007-07-17 04:05:33 -07003008static int fbcon_fb_unbind(int idx)
3009{
3010 int i, new_idx = -1, ret = 0;
3011
Ian Armstrong2ddce3f2009-09-22 16:47:52 -07003012 if (!fbcon_has_console_bind)
3013 return 0;
3014
Jesse Barnescfafca82007-07-17 04:05:33 -07003015 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3016 if (con2fb_map[i] != idx &&
3017 con2fb_map[i] != -1) {
3018 new_idx = i;
3019 break;
3020 }
3021 }
3022
3023 if (new_idx != -1) {
3024 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3025 if (con2fb_map[i] == idx)
3026 set_con2fb_map(i, new_idx, 0);
3027 }
Keith Packard5f4dc282014-01-20 13:31:10 -08003028 } else {
3029 struct fb_info *info = registered_fb[idx];
3030
3031 /* This is sort of like set_con2fb_map, except it maps
3032 * the consoles to no device and then releases the
3033 * oldinfo to free memory and cancel the cursor blink
3034 * timer. I can imagine this just becoming part of
3035 * set_con2fb_map where new_idx is -1
3036 */
3037 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3038 if (con2fb_map[i] == idx) {
3039 con2fb_map[i] = -1;
3040 if (!search_fb_in_map(idx)) {
3041 ret = con2fb_release_oldinfo(vc_cons[i].d,
3042 info, NULL, i,
3043 idx, 0);
3044 if (ret) {
3045 con2fb_map[i] = idx;
3046 return ret;
3047 }
3048 }
3049 }
3050 }
Jesse Barnescfafca82007-07-17 04:05:33 -07003051 ret = fbcon_unbind();
Keith Packard5f4dc282014-01-20 13:31:10 -08003052 }
Jesse Barnescfafca82007-07-17 04:05:33 -07003053
3054 return ret;
3055}
3056
Dave Airlie054430e2013-01-25 11:38:56 +10003057/* called with console_lock held */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003058static int fbcon_fb_unregistered(struct fb_info *info)
Antonino A. Daplase614b182006-06-26 00:27:09 -07003059{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003060 int i, idx;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003061
Andrea Righi66c1ca02009-03-31 15:25:18 -07003062 idx = info->node;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003063 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3064 if (con2fb_map[i] == idx)
3065 con2fb_map[i] = -1;
3066 }
3067
3068 if (idx == info_idx) {
3069 info_idx = -1;
3070
3071 for (i = 0; i < FB_MAX; i++) {
3072 if (registered_fb[i] != NULL) {
3073 info_idx = i;
3074 break;
3075 }
3076 }
3077 }
3078
3079 if (info_idx != -1) {
3080 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3081 if (con2fb_map[i] == -1)
3082 con2fb_map[i] = info_idx;
3083 }
3084 }
3085
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003086 if (primary_device == idx)
3087 primary_device = -1;
3088
Andrea Righi66c1ca02009-03-31 15:25:18 -07003089 if (!num_registered_fb)
Takashi Iwaie93a9a82013-01-25 10:28:18 +10003090 do_unregister_con_driver(&fb_con);
Andrea Righi66c1ca02009-03-31 15:25:18 -07003091
Antonino A. Daplase614b182006-06-26 00:27:09 -07003092 return 0;
3093}
3094
Dave Airlie054430e2013-01-25 11:38:56 +10003095/* called with console_lock held */
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003096static void fbcon_remap_all(int idx)
3097{
3098 int i;
3099 for (i = first_fb_vc; i <= last_fb_vc; i++)
3100 set_con2fb_map(i, idx, 0);
3101
3102 if (con_is_bound(&fb_con)) {
3103 printk(KERN_INFO "fbcon: Remapping primary device, "
3104 "fb%i, to tty %i-%i\n", idx,
3105 first_fb_vc + 1, last_fb_vc + 1);
3106 info_idx = idx;
3107 }
3108}
3109
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003110#ifdef CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003111static void fbcon_select_primary(struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112{
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003113 if (!map_override && primary_device == -1 &&
3114 fb_is_primary_device(info)) {
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003115 int i;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003116
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003117 printk(KERN_INFO "fbcon: %s (fb%i) is primary device\n",
3118 info->fix.id, info->node);
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003119 primary_device = info->node;
3120
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003121 for (i = first_fb_vc; i <= last_fb_vc; i++)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003122 con2fb_map_boot[i] = primary_device;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003123
3124 if (con_is_bound(&fb_con)) {
3125 printk(KERN_INFO "fbcon: Remapping primary device, "
3126 "fb%i, to tty %i-%i\n", info->node,
3127 first_fb_vc + 1, last_fb_vc + 1);
3128 info_idx = primary_device;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003129 }
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003130 }
3131
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003132}
3133#else
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003134static inline void fbcon_select_primary(struct fb_info *info)
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003135{
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003136 return;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003137}
3138#endif /* CONFIG_FRAMEBUFFER_DETECT_PRIMARY */
3139
Dave Airlie054430e2013-01-25 11:38:56 +10003140/* called with console_lock held */
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003141static int fbcon_fb_registered(struct fb_info *info)
3142{
Andrea Righi66c1ca02009-03-31 15:25:18 -07003143 int ret = 0, i, idx;
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003144
Andrea Righi66c1ca02009-03-31 15:25:18 -07003145 idx = info->node;
Antonino A. Daplasafd1db12007-07-17 04:05:32 -07003146 fbcon_select_primary(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
3148 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003149 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 if (con2fb_map_boot[i] == idx) {
3151 info_idx = idx;
3152 break;
3153 }
3154 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003155
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 if (info_idx != -1)
Alan Cox50e244c2013-01-25 10:28:15 +10003157 ret = do_fbcon_takeover(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003159 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003160 if (con2fb_map_boot[i] == idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 set_con2fb_map(i, idx, 0);
3162 }
3163 }
3164
3165 return ret;
3166}
3167
3168static void fbcon_fb_blanked(struct fb_info *info, int blank)
3169{
3170 struct fbcon_ops *ops = info->fbcon_par;
3171 struct vc_data *vc;
3172
3173 if (!ops || ops->currcon < 0)
3174 return;
3175
3176 vc = vc_cons[ops->currcon].d;
3177 if (vc->vc_mode != KD_TEXT ||
3178 registered_fb[con2fb_map[ops->currcon]] != info)
3179 return;
3180
Jiri Slaby6ca8dfd2016-06-23 13:34:35 +02003181 if (con_is_visible(vc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 if (blank)
3183 do_blank_screen(0);
3184 else
3185 do_unblank_screen(0);
3186 }
3187 ops->blank_state = blank;
3188}
3189
3190static void fbcon_new_modelist(struct fb_info *info)
3191{
3192 int i;
3193 struct vc_data *vc;
3194 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003195 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
Antonino A. Daplase614b182006-06-26 00:27:09 -07003197 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 if (registered_fb[con2fb_map[i]] != info)
3199 continue;
3200 if (!fb_display[i].mode)
3201 continue;
3202 vc = vc_cons[i].d;
3203 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003204 mode = fb_find_nearest_mode(fb_display[i].mode,
3205 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 fb_videomode_to_var(&var, mode);
Antonino A. Daplasd1baa4f2007-07-17 04:05:32 -07003207 fbcon_set_disp(info, &var, vc->vc_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 }
3209}
3210
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003211static void fbcon_get_requirement(struct fb_info *info,
3212 struct fb_blit_caps *caps)
3213{
3214 struct vc_data *vc;
3215 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003216
3217 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003218 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003219
3220 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3221 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003222 if (vc && vc->vc_mode == KD_TEXT &&
3223 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003224 p = &fb_display[i];
3225 caps->x |= 1 << (vc->vc_font.width - 1);
3226 caps->y |= 1 << (vc->vc_font.height - 1);
3227 charcnt = (p->userfont) ?
3228 FNTCHARCNT(p->fontdata) : 256;
3229 if (caps->len < charcnt)
3230 caps->len = charcnt;
3231 }
3232 }
3233 } else {
3234 vc = vc_cons[fg_console].d;
3235
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003236 if (vc && vc->vc_mode == KD_TEXT &&
3237 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003238 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003239 caps->x = 1 << (vc->vc_font.width - 1);
3240 caps->y = 1 << (vc->vc_font.height - 1);
3241 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003242 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003243 }
3244 }
3245}
3246
Andrea Righi66c1ca02009-03-31 15:25:18 -07003247static int fbcon_event_notify(struct notifier_block *self,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 unsigned long action, void *data)
3249{
3250 struct fb_event *event = data;
3251 struct fb_info *info = event->info;
3252 struct fb_videomode *mode;
3253 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003254 struct fb_blit_caps *caps;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003255 int idx, ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256
Antonino A. Daplase614b182006-06-26 00:27:09 -07003257 /*
3258 * ignore all events except driver registration and deregistration
3259 * if fbcon is not active
3260 */
3261 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3262 action == FB_EVENT_FB_UNREGISTERED))
3263 goto done;
3264
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 switch(action) {
3266 case FB_EVENT_SUSPEND:
3267 fbcon_suspended(info);
3268 break;
3269 case FB_EVENT_RESUME:
3270 fbcon_resumed(info);
3271 break;
3272 case FB_EVENT_MODE_CHANGE:
3273 fbcon_modechanged(info);
3274 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003275 case FB_EVENT_MODE_CHANGE_ALL:
3276 fbcon_set_all_vcs(info);
3277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 case FB_EVENT_MODE_DELETE:
3279 mode = event->data;
3280 ret = fbcon_mode_deleted(info, mode);
3281 break;
Jesse Barnescfafca82007-07-17 04:05:33 -07003282 case FB_EVENT_FB_UNBIND:
Andrea Righi66c1ca02009-03-31 15:25:18 -07003283 idx = info->node;
Andrea Righi66c1ca02009-03-31 15:25:18 -07003284 ret = fbcon_fb_unbind(idx);
Jesse Barnescfafca82007-07-17 04:05:33 -07003285 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 case FB_EVENT_FB_REGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003287 ret = fbcon_fb_registered(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003289 case FB_EVENT_FB_UNREGISTERED:
Antonino A. Daplas623e71b2007-07-17 04:05:28 -07003290 ret = fbcon_fb_unregistered(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07003291 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 case FB_EVENT_SET_CONSOLE_MAP:
Dave Airlie054430e2013-01-25 11:38:56 +10003293 /* called with console lock held */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 con2fb = event->data;
3295 ret = set_con2fb_map(con2fb->console - 1,
3296 con2fb->framebuffer, 1);
3297 break;
3298 case FB_EVENT_GET_CONSOLE_MAP:
3299 con2fb = event->data;
3300 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3301 break;
3302 case FB_EVENT_BLANK:
3303 fbcon_fb_blanked(info, *(int *)event->data);
3304 break;
3305 case FB_EVENT_NEW_MODELIST:
3306 fbcon_new_modelist(info);
3307 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003308 case FB_EVENT_GET_REQ:
3309 caps = event->data;
3310 fbcon_get_requirement(info, caps);
3311 break;
Dave Airlie6a9ee8a2010-02-01 15:38:10 +10003312 case FB_EVENT_REMAP_ALL_CONSOLE:
3313 idx = info->node;
3314 fbcon_remap_all(idx);
3315 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003317done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 return ret;
3319}
3320
3321/*
3322 * The console `switch' structure for the frame buffer based console
3323 */
3324
3325static const struct consw fb_con = {
3326 .owner = THIS_MODULE,
3327 .con_startup = fbcon_startup,
3328 .con_init = fbcon_init,
3329 .con_deinit = fbcon_deinit,
3330 .con_clear = fbcon_clear,
3331 .con_putc = fbcon_putc,
3332 .con_putcs = fbcon_putcs,
3333 .con_cursor = fbcon_cursor,
3334 .con_scroll = fbcon_scroll,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 .con_switch = fbcon_switch,
3336 .con_blank = fbcon_blank,
3337 .con_font_set = fbcon_set_font,
3338 .con_font_get = fbcon_get_font,
3339 .con_font_default = fbcon_set_def_font,
3340 .con_font_copy = fbcon_copy_font,
3341 .con_set_palette = fbcon_set_palette,
3342 .con_scrolldelta = fbcon_scrolldelta,
3343 .con_set_origin = fbcon_set_origin,
3344 .con_invert_region = fbcon_invert_region,
3345 .con_screen_pos = fbcon_screen_pos,
3346 .con_getxy = fbcon_getxy,
3347 .con_resize = fbcon_resize,
Jesse Barnesd219adc2010-08-02 12:05:41 -07003348 .con_debug_enter = fbcon_debug_enter,
3349 .con_debug_leave = fbcon_debug_leave,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350};
3351
3352static struct notifier_block fbcon_event_notifier = {
3353 .notifier_call = fbcon_event_notify,
3354};
3355
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003356static ssize_t store_rotate(struct device *device,
3357 struct device_attribute *attr, const char *buf,
3358 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003359{
3360 struct fb_info *info;
3361 int rotate, idx;
3362 char **last = NULL;
3363
Antonino A. Daplase614b182006-06-26 00:27:09 -07003364 if (fbcon_has_exited)
3365 return count;
3366
Torben Hohnac751ef2011-01-25 15:07:35 -08003367 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003368 idx = con2fb_map[fg_console];
3369
3370 if (idx == -1 || registered_fb[idx] == NULL)
3371 goto err;
3372
3373 info = registered_fb[idx];
3374 rotate = simple_strtoul(buf, last, 0);
3375 fbcon_rotate(info, rotate);
3376err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003377 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003378 return count;
3379}
3380
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003381static ssize_t store_rotate_all(struct device *device,
3382 struct device_attribute *attr,const char *buf,
3383 size_t count)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003384{
3385 struct fb_info *info;
3386 int rotate, idx;
3387 char **last = NULL;
3388
Antonino A. Daplase614b182006-06-26 00:27:09 -07003389 if (fbcon_has_exited)
3390 return count;
3391
Torben Hohnac751ef2011-01-25 15:07:35 -08003392 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003393 idx = con2fb_map[fg_console];
3394
3395 if (idx == -1 || registered_fb[idx] == NULL)
3396 goto err;
3397
3398 info = registered_fb[idx];
3399 rotate = simple_strtoul(buf, last, 0);
3400 fbcon_rotate_all(info, rotate);
3401err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003402 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003403 return count;
3404}
3405
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003406static ssize_t show_rotate(struct device *device,
3407 struct device_attribute *attr,char *buf)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003408{
3409 struct fb_info *info;
3410 int rotate = 0, idx;
3411
Antonino A. Daplase614b182006-06-26 00:27:09 -07003412 if (fbcon_has_exited)
3413 return 0;
3414
Torben Hohnac751ef2011-01-25 15:07:35 -08003415 console_lock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003416 idx = con2fb_map[fg_console];
3417
3418 if (idx == -1 || registered_fb[idx] == NULL)
3419 goto err;
3420
3421 info = registered_fb[idx];
3422 rotate = fbcon_get_rotate(info);
3423err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003424 console_unlock();
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003425 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3426}
3427
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003428static ssize_t show_cursor_blink(struct device *device,
3429 struct device_attribute *attr, char *buf)
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003430{
3431 struct fb_info *info;
3432 struct fbcon_ops *ops;
3433 int idx, blink = -1;
3434
3435 if (fbcon_has_exited)
3436 return 0;
3437
Torben Hohnac751ef2011-01-25 15:07:35 -08003438 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003439 idx = con2fb_map[fg_console];
3440
3441 if (idx == -1 || registered_fb[idx] == NULL)
3442 goto err;
3443
3444 info = registered_fb[idx];
3445 ops = info->fbcon_par;
3446
3447 if (!ops)
3448 goto err;
3449
3450 blink = (ops->flags & FBCON_FLAGS_CURSOR_TIMER) ? 1 : 0;
3451err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003452 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003453 return snprintf(buf, PAGE_SIZE, "%d\n", blink);
3454}
3455
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003456static ssize_t store_cursor_blink(struct device *device,
3457 struct device_attribute *attr,
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003458 const char *buf, size_t count)
3459{
3460 struct fb_info *info;
3461 int blink, idx;
3462 char **last = NULL;
3463
3464 if (fbcon_has_exited)
3465 return count;
3466
Torben Hohnac751ef2011-01-25 15:07:35 -08003467 console_lock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003468 idx = con2fb_map[fg_console];
3469
3470 if (idx == -1 || registered_fb[idx] == NULL)
3471 goto err;
3472
3473 info = registered_fb[idx];
3474
3475 if (!info->fbcon_par)
3476 goto err;
3477
3478 blink = simple_strtoul(buf, last, 0);
3479
3480 if (blink) {
3481 fbcon_cursor_noblink = 0;
3482 fbcon_add_cursor_timer(info);
3483 } else {
3484 fbcon_cursor_noblink = 1;
3485 fbcon_del_cursor_timer(info);
3486 }
3487
3488err:
Torben Hohnac751ef2011-01-25 15:07:35 -08003489 console_unlock();
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003490 return count;
3491}
3492
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003493static struct device_attribute device_attrs[] = {
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003494 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3495 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
Antonino A. Daplasacba9cd2007-07-17 04:05:26 -07003496 __ATTR(cursor_blink, S_IRUGO|S_IWUSR, show_cursor_blink,
3497 store_cursor_blink),
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003498};
3499
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003500static int fbcon_init_device(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003501{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003502 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003503
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003504 fbcon_has_sysfs = 1;
3505
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003506 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
3507 error = device_create_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003508
3509 if (error)
3510 break;
3511 }
3512
3513 if (error) {
3514 while (--i >= 0)
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003515 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003516
3517 fbcon_has_sysfs = 0;
3518 }
3519
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003520 return 0;
3521}
3522
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003523static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003526 int i;
3527
Torben Hohnac751ef2011-01-25 15:07:35 -08003528 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003529
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 for (i = 0; i < FB_MAX; i++) {
3531 if (registered_fb[i] != NULL) {
3532 info_idx = i;
3533 break;
3534 }
3535 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003536
Wang YanQinge57f35d2013-05-09 02:13:30 +08003537 do_fbcon_takeover(0);
Torben Hohnac751ef2011-01-25 15:07:35 -08003538 console_unlock();
Wang YanQinge57f35d2013-05-09 02:13:30 +08003539
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541}
3542
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003543static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003544{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003545 struct fb_info *info;
3546 int i, j, mapped;
3547
Antonino A. Daplase614b182006-06-26 00:27:09 -07003548 if (fbcon_has_exited)
3549 return;
3550
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003551 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003552 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003553
3554 for (i = 0; i < FB_MAX; i++) {
Jarek Poplawski142092e2010-09-22 13:05:05 -07003555 int pending = 0;
Geoff Levandbeaa4862008-12-09 13:14:17 -08003556
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003557 mapped = 0;
3558 info = registered_fb[i];
3559
3560 if (info == NULL)
3561 continue;
3562
Jarek Poplawski142092e2010-09-22 13:05:05 -07003563 if (info->queue.func)
3564 pending = cancel_work_sync(&info->queue);
Geoff Levandbeaa4862008-12-09 13:14:17 -08003565 DPRINTK("fbcon: %s pending work\n", (pending ? "canceled" :
3566 "no"));
3567
Antonino A. Daplase614b182006-06-26 00:27:09 -07003568 for (j = first_fb_vc; j <= last_fb_vc; j++) {
Wang YanQing5aa133d2013-12-27 10:39:18 +08003569 if (con2fb_map[j] == i) {
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003570 mapped = 1;
Wang YanQing5aa133d2013-12-27 10:39:18 +08003571 break;
3572 }
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003573 }
3574
3575 if (mapped) {
3576 if (info->fbops->fb_release)
3577 info->fbops->fb_release(info, 0);
3578 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003579
3580 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003581 struct fbcon_ops *ops = info->fbcon_par;
3582
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003583 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003584 kfree(ops->cursor_src);
Masami Ichikawa46862142013-12-25 23:47:37 +09003585 kfree(ops->cursor_state.mask);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003586 kfree(info->fbcon_par);
3587 info->fbcon_par = NULL;
3588 }
3589
3590 if (info->queue.func == fb_flashcursor)
3591 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003592 }
3593 }
3594
Antonino A. Daplase614b182006-06-26 00:27:09 -07003595 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003596}
3597
3598static int __init fb_console_init(void)
3599{
3600 int i;
3601
Torben Hohnac751ef2011-01-25 15:07:35 -08003602 console_lock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003603 fb_register_client(&fbcon_event_notifier);
Greg Kroah-Hartman77997aa2008-07-21 20:03:34 -07003604 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3605 "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003606
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003607 if (IS_ERR(fbcon_device)) {
3608 printk(KERN_WARNING "Unable to create device "
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003609 "for fbcon; errno = %ld\n",
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003610 PTR_ERR(fbcon_device));
3611 fbcon_device = NULL;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003612 } else
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003613 fbcon_init_device();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003614
3615 for (i = 0; i < MAX_NR_CONSOLES; i++)
3616 con2fb_map[i] = -1;
3617
Torben Hohnac751ef2011-01-25 15:07:35 -08003618 console_unlock();
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003619 fbcon_start();
3620 return 0;
3621}
3622
Hans de Goedeba168a32014-11-14 13:26:54 +01003623fs_initcall(fb_console_init);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003624
3625#ifdef MODULE
3626
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003627static void __exit fbcon_deinit_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003628{
3629 int i;
3630
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003631 if (fbcon_has_sysfs) {
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003632 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
3633 device_remove_file(fbcon_device, &device_attrs[i]);
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003634
3635 fbcon_has_sysfs = 0;
3636 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003637}
3638
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639static void __exit fb_console_exit(void)
3640{
Torben Hohnac751ef2011-01-25 15:07:35 -08003641 console_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas0c6c1ce2007-07-17 04:05:26 -07003643 fbcon_deinit_device();
3644 device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003645 fbcon_exit();
Wang YanQing70125e72013-05-09 02:14:39 +08003646 do_unregister_con_driver(&fb_con);
Torben Hohnac751ef2011-01-25 15:07:35 -08003647 console_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648}
3649
3650module_exit(fb_console_exit);
3651
3652#endif
3653
3654MODULE_LICENSE("GPL");