blob: 7888e319f9e193623aa99da07d5c7d4aeb9ca426 [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 */
78#include <asm/irq.h>
79#include <asm/system.h>
80#include <asm/uaccess.h>
81#ifdef CONFIG_ATARI
82#include <asm/atariints.h>
83#endif
84#ifdef CONFIG_MAC
85#include <asm/macints.h>
86#endif
87#if defined(__mc68000__) || defined(CONFIG_APUS)
88#include <asm/machdep.h>
89#include <asm/setup.h>
90#endif
91
92#include "fbcon.h"
93
94#ifdef FBCONDEBUG
95# define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
96#else
97# define DPRINTK(fmt, args...)
98#endif
99
100enum {
101 FBCON_LOGO_CANSHOW = -1, /* the logo can be shown */
102 FBCON_LOGO_DRAW = -2, /* draw the logo to a console */
103 FBCON_LOGO_DONTSHOW = -3 /* do not show the logo */
104};
105
Antonino A. Daplasab767202005-11-13 16:06:32 -0800106static struct display fb_display[MAX_NR_CONSOLES];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static signed char con2fb_map[MAX_NR_CONSOLES];
109static signed char con2fb_map_boot[MAX_NR_CONSOLES];
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700110#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111static int logo_height;
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113static int logo_lines;
114/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
115 enums. */
116static int logo_shown = FBCON_LOGO_CANSHOW;
117/* Software scrollback */
118static int fbcon_softback_size = 32768;
119static unsigned long softback_buf, softback_curr;
120static unsigned long softback_in;
121static unsigned long softback_top, softback_end;
122static int softback_lines;
123/* console mappings */
124static int first_fb_vc;
125static int last_fb_vc = MAX_NR_CONSOLES - 1;
126static int fbcon_is_default = 1;
Antonino A. Daplase614b182006-06-26 00:27:09 -0700127static int fbcon_has_exited;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/* font data */
130static char fontname[40];
131
132/* current fb_info */
133static int info_idx = -1;
134
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800135/* console rotation */
136static int rotate;
Antonino A. Daplas0a727de2006-10-03 01:14:50 -0700137static int fbcon_has_sysfs;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139static const struct consw fb_con;
140
141#define CM_SOFTBACK (8)
142
143#define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static int fbcon_set_origin(struct vc_data *);
146
147#define CURSOR_DRAW_DELAY (1)
148
149/* # VBL ints between cursor state changes */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#define ATARI_CURSOR_BLINK_RATE (42)
151#define MAC_CURSOR_BLINK_RATE (32)
152#define DEFAULT_CURSOR_BLINK_RATE (20)
153
154static int vbl_cursor_cnt;
155
156#define divides(a, b) ((!(a) || (b)%(a)) ? 0 : 1)
157
158/*
159 * Interface used by the world
160 */
161
162static const char *fbcon_startup(void);
163static void fbcon_init(struct vc_data *vc, int init);
164static void fbcon_deinit(struct vc_data *vc);
165static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
166 int width);
167static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos);
168static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
169 int count, int ypos, int xpos);
170static void fbcon_clear_margins(struct vc_data *vc, int bottom_only);
171static void fbcon_cursor(struct vc_data *vc, int mode);
172static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
173 int count);
174static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
175 int height, int width);
176static int fbcon_switch(struct vc_data *vc);
177static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch);
178static int fbcon_set_palette(struct vc_data *vc, unsigned char *table);
179static int fbcon_scrolldelta(struct vc_data *vc, int lines);
180
181/*
182 * Internal routines
183 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184static __inline__ void ywrap_up(struct vc_data *vc, int count);
185static __inline__ void ywrap_down(struct vc_data *vc, int count);
186static __inline__ void ypan_up(struct vc_data *vc, int count);
187static __inline__ void ypan_down(struct vc_data *vc, int count);
188static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
189 int dy, int dx, int height, int width, u_int y_break);
190static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
191 struct vc_data *vc);
192static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
193 int unit);
194static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
195 int line, int count, int dy);
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800196static void fbcon_modechanged(struct fb_info *info);
197static void fbcon_set_all_vcs(struct fb_info *info);
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700198static void fbcon_start(void);
199static void fbcon_exit(void);
Antonino A. Daplas9a179172006-06-26 00:27:05 -0700200static struct class_device *fbcon_class_device;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#ifdef CONFIG_MAC
203/*
204 * On the Macintoy, there may or may not be a working VBL int. We need to probe
205 */
206static int vbl_detected;
207
David Howells7d12e782006-10-05 14:55:46 +0100208static irqreturn_t fb_vbl_detect(int irq, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
210 vbl_detected++;
211 return IRQ_HANDLED;
212}
213#endif
214
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800215#ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800216static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800217{
218 struct fbcon_ops *ops = info->fbcon_par;
219
220 if (!(info->flags & FBINFO_MISC_TILEBLITTING) &&
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800221 ops->p->con_rotate < 4)
222 ops->rotate = ops->p->con_rotate;
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800223 else
224 ops->rotate = 0;
225}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800226
227static void fbcon_rotate(struct fb_info *info, u32 rotate)
228{
229 struct fbcon_ops *ops= info->fbcon_par;
230 struct fb_info *fb_info;
231
232 if (!ops || ops->currcon == -1)
233 return;
234
235 fb_info = registered_fb[con2fb_map[ops->currcon]];
236
237 if (info == fb_info) {
238 struct display *p = &fb_display[ops->currcon];
239
240 if (rotate < 4)
241 p->con_rotate = rotate;
242 else
243 p->con_rotate = 0;
244
245 fbcon_modechanged(info);
246 }
247}
248
249static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
250{
251 struct fbcon_ops *ops = info->fbcon_par;
252 struct vc_data *vc;
253 struct display *p;
254 int i;
255
256 if (!ops || ops->currcon < 0 || rotate > 3)
257 return;
258
Antonino A. Daplase614b182006-06-26 00:27:09 -0700259 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800260 vc = vc_cons[i].d;
261 if (!vc || vc->vc_mode != KD_TEXT ||
262 registered_fb[con2fb_map[i]] != info)
263 continue;
264
265 p = &fb_display[vc->vc_num];
266 p->con_rotate = rotate;
267 }
268
269 fbcon_set_all_vcs(info);
270}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800271#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800272static inline void fbcon_set_rotation(struct fb_info *info)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800273{
274 struct fbcon_ops *ops = info->fbcon_par;
275
276 ops->rotate = FB_ROTATE_UR;
277}
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800278
279static void fbcon_rotate(struct fb_info *info, u32 rotate)
280{
281 return;
282}
283
284static void fbcon_rotate_all(struct fb_info *info, u32 rotate)
285{
286 return;
287}
Antonino A. Daplasdbcbfe12005-11-08 21:39:12 -0800288#endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800289
Antonino A. Daplasa812c942005-11-08 21:39:15 -0800290static int fbcon_get_rotate(struct fb_info *info)
291{
292 struct fbcon_ops *ops = info->fbcon_par;
293
294 return (ops) ? ops->rotate : 0;
295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info)
298{
299 struct fbcon_ops *ops = info->fbcon_par;
300
301 return (info->state != FBINFO_STATE_RUNNING ||
302 vc->vc_mode != KD_TEXT || ops->graphics);
303}
304
305static inline int get_color(struct vc_data *vc, struct fb_info *info,
306 u16 c, int is_fg)
307{
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700308 int depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 int color = 0;
310
311 if (console_blanked) {
312 unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
313
314 c = vc->vc_video_erase_char & charmask;
315 }
316
317 if (depth != 1)
318 color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c)
319 : attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c);
320
321 switch (depth) {
322 case 1:
323 {
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700324 int col = ~(0xfff << (max(info->var.green.length,
325 max(info->var.red.length,
326 info->var.blue.length)))) & 0xff;
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 /* 0 or 1 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700329 int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0;
330 int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 if (console_blanked)
333 fg = bg;
334
335 color = (is_fg) ? fg : bg;
336 break;
337 }
338 case 2:
339 /*
340 * Scale down 16-colors to 4 colors. Default 4-color palette
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700341 * is grayscale. However, simply dividing the values by 4
342 * will not work, as colors 1, 2 and 3 will be scaled-down
343 * to zero rendering them invisible. So empirically convert
344 * colors to a sane 4-level grayscale.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 */
Antonino A. Daplas2cc38ed2005-09-09 13:04:38 -0700346 switch (color) {
347 case 0:
348 color = 0; /* black */
349 break;
350 case 1 ... 6:
351 color = 2; /* white */
352 break;
353 case 7 ... 8:
354 color = 1; /* gray */
355 break;
356 default:
357 color = 3; /* intense white */
358 break;
359 }
360 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 case 3:
362 /*
363 * Last 8 entries of default 16-color palette is a more intense
364 * version of the first 8 (i.e., same chrominance, different
365 * luminance).
366 */
367 color &= 7;
368 break;
369 }
370
371
372 return color;
373}
374
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -0800375static void fbcon_update_softback(struct vc_data *vc)
376{
377 int l = fbcon_softback_size / vc->vc_size_row;
378
379 if (l > 5)
380 softback_end = softback_buf + l * vc->vc_size_row;
381 else
382 /* Smaller scrollback makes no sense, and 0 would screw
383 the operation totally */
384 softback_top = 0;
385}
386
David Howellsc4028952006-11-22 14:57:56 +0000387static void fb_flashcursor(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
David Howellsc4028952006-11-22 14:57:56 +0000389 struct fb_info *info = container_of(work, struct fb_info, queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 struct fbcon_ops *ops = info->fbcon_par;
391 struct display *p;
392 struct vc_data *vc = NULL;
393 int c;
394 int mode;
395
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700396 acquire_console_sem();
397 if (ops && ops->currcon != -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 vc = vc_cons[ops->currcon].d;
399
400 if (!vc || !CON_IS_VISIBLE(vc) ||
Michal Januszewskidbd4f122005-07-27 11:46:06 -0700401 registered_fb[con2fb_map[vc->vc_num]] != info ||
Antonino A. Daplas212f2632006-10-03 01:14:48 -0700402 vc->vc_deccm != 1) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700403 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 return;
Antonino A. Daplas5428b042006-06-26 00:27:06 -0700405 }
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 p = &fb_display[vc->vc_num];
408 c = scr_readw((u16 *) vc->vc_pos);
409 mode = (!ops->cursor_flash || ops->cursor_state.enable) ?
410 CM_ERASE : CM_DRAW;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800411 ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 get_color(vc, info, c, 0));
413 release_console_sem();
414}
415
Russell King41359dc2005-06-30 16:30:07 +0100416#if defined(CONFIG_ATARI) || defined(CONFIG_MAC)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417static int cursor_blink_rate;
David Howells7d12e782006-10-05 14:55:46 +0100418static irqreturn_t fb_vbl_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 struct fb_info *info = dev_id;
421
422 if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) {
423 schedule_work(&info->queue);
424 vbl_cursor_cnt = cursor_blink_rate;
425 }
426 return IRQ_HANDLED;
427}
428#endif
429
430static void cursor_timer_handler(unsigned long dev_addr)
431{
432 struct fb_info *info = (struct fb_info *) dev_addr;
433 struct fbcon_ops *ops = info->fbcon_par;
434
435 schedule_work(&info->queue);
436 mod_timer(&ops->cursor_timer, jiffies + HZ/5);
437}
438
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700439static void fbcon_add_cursor_timer(struct fb_info *info)
440{
441 struct fbcon_ops *ops = info->fbcon_par;
442
443 if ((!info->queue.func || info->queue.func == fb_flashcursor) &&
444 !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) {
445 if (!info->queue.func)
David Howellsc4028952006-11-22 14:57:56 +0000446 INIT_WORK(&info->queue, fb_flashcursor);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700447
448 init_timer(&ops->cursor_timer);
449 ops->cursor_timer.function = cursor_timer_handler;
450 ops->cursor_timer.expires = jiffies + HZ / 5;
451 ops->cursor_timer.data = (unsigned long ) info;
452 add_timer(&ops->cursor_timer);
453 ops->flags |= FBCON_FLAGS_CURSOR_TIMER;
454 }
455}
456
457static void fbcon_del_cursor_timer(struct fb_info *info)
458{
459 struct fbcon_ops *ops = info->fbcon_par;
460
461 if (info->queue.func == fb_flashcursor &&
462 ops->flags & FBCON_FLAGS_CURSOR_TIMER) {
463 del_timer_sync(&ops->cursor_timer);
464 ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER;
465 }
466}
467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#ifndef MODULE
469static int __init fb_console_setup(char *this_opt)
470{
471 char *options;
472 int i, j;
473
474 if (!this_opt || !*this_opt)
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800475 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 while ((options = strsep(&this_opt, ",")) != NULL) {
478 if (!strncmp(options, "font:", 5))
479 strcpy(fontname, options + 5);
480
481 if (!strncmp(options, "scrollback:", 11)) {
482 options += 11;
483 if (*options) {
484 fbcon_softback_size = simple_strtoul(options, &options, 0);
485 if (*options == 'k' || *options == 'K') {
486 fbcon_softback_size *= 1024;
487 options++;
488 }
489 if (*options != ',')
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800490 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 options++;
492 } else
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800493 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 }
495
496 if (!strncmp(options, "map:", 4)) {
497 options += 4;
498 if (*options)
499 for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) {
500 if (!options[j])
501 j = 0;
502 con2fb_map_boot[i] =
503 (options[j++]-'0') % FB_MAX;
504 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800505 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
508 if (!strncmp(options, "vc:", 3)) {
509 options += 3;
510 if (*options)
511 first_fb_vc = simple_strtoul(options, &options, 10) - 1;
512 if (first_fb_vc < 0)
513 first_fb_vc = 0;
514 if (*options++ == '-')
515 last_fb_vc = simple_strtoul(options, &options, 10) - 1;
516 fbcon_is_default = 0;
517 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800518
519 if (!strncmp(options, "rotate:", 7)) {
520 options += 7;
521 if (*options)
522 rotate = simple_strtoul(options, &options, 0);
523 if (rotate > 3)
524 rotate = 0;
525 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
OGAWA Hirofumi9b410462006-03-31 02:30:33 -0800527 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528}
529
530__setup("fbcon=", fb_console_setup);
531#endif
532
533static int search_fb_in_map(int idx)
534{
535 int i, retval = 0;
536
Antonino A. Daplase614b182006-06-26 00:27:09 -0700537 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (con2fb_map[i] == idx)
539 retval = 1;
540 }
541 return retval;
542}
543
544static int search_for_mapped_con(void)
545{
546 int i, retval = 0;
547
Antonino A. Daplase614b182006-06-26 00:27:09 -0700548 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 if (con2fb_map[i] != -1)
550 retval = 1;
551 }
552 return retval;
553}
554
555static int fbcon_takeover(int show_logo)
556{
557 int err, i;
558
559 if (!num_registered_fb)
560 return -ENODEV;
561
562 if (!show_logo)
563 logo_shown = FBCON_LOGO_DONTSHOW;
564
565 for (i = first_fb_vc; i <= last_fb_vc; i++)
566 con2fb_map[i] = info_idx;
567
568 err = take_over_console(&fb_con, first_fb_vc, last_fb_vc,
569 fbcon_is_default);
Antonino A. Daplase614b182006-06-26 00:27:09 -0700570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (err) {
572 for (i = first_fb_vc; i <= last_fb_vc; i++) {
573 con2fb_map[i] = -1;
574 }
575 info_idx = -1;
576 }
577
578 return err;
579}
580
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700581#ifdef MODULE
582static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
583 int cols, int rows, int new_cols, int new_rows)
584{
585 logo_shown = FBCON_LOGO_DONTSHOW;
586}
587#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
589 int cols, int rows, int new_cols, int new_rows)
590{
591 /* Need to make room for the logo */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800592 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 int cnt, erase = vc->vc_video_erase_char, step;
594 unsigned short *save = NULL, *r, *q;
595
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700596 if (info->flags & FBINFO_MODULE) {
597 logo_shown = FBCON_LOGO_DONTSHOW;
598 return;
599 }
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 /*
602 * remove underline attribute from erase character
603 * if black and white framebuffer.
604 */
Antonino A. Daplasb8c90942005-09-09 13:04:37 -0700605 if (fb_get_color_depth(&info->var, &info->fix) == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 erase &= ~0x400;
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -0800607 logo_height = fb_prepare_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 logo_lines = (logo_height + vc->vc_font.height - 1) /
609 vc->vc_font.height;
610 q = (unsigned short *) (vc->vc_origin +
611 vc->vc_size_row * rows);
612 step = logo_lines * cols;
613 for (r = q - logo_lines * cols; r < q; r++)
614 if (scr_readw(r) != vc->vc_video_erase_char)
615 break;
616 if (r != q && new_rows >= rows + logo_lines) {
617 save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL);
618 if (save) {
619 int i = cols < new_cols ? cols : new_cols;
620 scr_memsetw(save, erase, logo_lines * new_cols * 2);
621 r = q - step;
622 for (cnt = 0; cnt < logo_lines; cnt++, r += i)
623 scr_memcpyw(save + cnt * new_cols, r, 2 * i);
624 r = q;
625 }
626 }
627 if (r == q) {
628 /* We can scroll screen down */
629 r = q - step - cols;
630 for (cnt = rows - logo_lines; cnt > 0; cnt--) {
631 scr_memcpyw(r + step, r, vc->vc_size_row);
632 r -= cols;
633 }
634 if (!save) {
Geert Uytterhoeven250038f2007-05-08 00:37:53 -0700635 int lines;
636 if (vc->vc_y + logo_lines >= rows)
637 lines = rows - vc->vc_y - 1;
638 else
639 lines = logo_lines;
640 vc->vc_y += lines;
641 vc->vc_pos += lines * vc->vc_size_row;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 }
644 scr_memsetw((unsigned short *) vc->vc_origin,
645 erase,
646 vc->vc_size_row * logo_lines);
647
648 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
649 fbcon_clear_margins(vc, 0);
650 update_screen(vc);
651 }
652
653 if (save) {
654 q = (unsigned short *) (vc->vc_origin +
655 vc->vc_size_row *
656 rows);
657 scr_memcpyw(q, save, logo_lines * new_cols * 2);
658 vc->vc_y += logo_lines;
659 vc->vc_pos += logo_lines * vc->vc_size_row;
660 kfree(save);
661 }
662
663 if (logo_lines > vc->vc_bottom) {
664 logo_shown = FBCON_LOGO_CANSHOW;
665 printk(KERN_INFO
666 "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n");
667 } else if (logo_shown != FBCON_LOGO_DONTSHOW) {
668 logo_shown = FBCON_LOGO_DRAW;
669 vc->vc_top = logo_lines;
670 }
671}
Antonino A. Daplas70802c62007-05-08 00:38:14 -0700672#endif /* MODULE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674#ifdef CONFIG_FB_TILEBLITTING
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800675static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
677 struct fbcon_ops *ops = info->fbcon_par;
678
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800679 ops->p = &fb_display[vc->vc_num];
Antonino A. Daplasab767202005-11-13 16:06:32 -0800680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 if ((info->flags & FBINFO_MISC_TILEBLITTING))
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800682 fbcon_set_tileops(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800683 else {
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800684 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 fbcon_set_bitops(ops);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700688
689static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
690{
691 int err = 0;
692
693 if (info->flags & FBINFO_MISC_TILEBLITTING &&
694 info->tileops->fb_get_tilemax(info) < charcount)
695 err = 1;
696
697 return err;
698}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#else
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800700static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
702 struct fbcon_ops *ops = info->fbcon_par;
703
704 info->flags &= ~FBINFO_MISC_TILEBLITTING;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800705 ops->p = &fb_display[vc->vc_num];
706 fbcon_set_rotation(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 fbcon_set_bitops(ops);
708}
Antonino A. Daplas38b49822007-05-08 00:39:19 -0700709
710static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
711{
712 return 0;
713}
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715#endif /* CONFIG_MISC_TILEBLITTING */
716
717
718static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info,
719 int unit, int oldidx)
720{
721 struct fbcon_ops *ops = NULL;
722 int err = 0;
723
724 if (!try_module_get(info->fbops->owner))
725 err = -ENODEV;
726
727 if (!err && info->fbops->fb_open &&
728 info->fbops->fb_open(info, 0))
729 err = -ENODEV;
730
731 if (!err) {
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800732 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (!ops)
734 err = -ENOMEM;
735 }
736
737 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 info->fbcon_par = ops;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800739 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 }
741
742 if (err) {
743 con2fb_map[unit] = oldidx;
744 module_put(info->fbops->owner);
745 }
746
747 return err;
748}
749
750static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo,
751 struct fb_info *newinfo, int unit,
752 int oldidx, int found)
753{
754 struct fbcon_ops *ops = oldinfo->fbcon_par;
755 int err = 0;
756
757 if (oldinfo->fbops->fb_release &&
758 oldinfo->fbops->fb_release(oldinfo, 0)) {
759 con2fb_map[unit] = oldidx;
760 if (!found && newinfo->fbops->fb_release)
761 newinfo->fbops->fb_release(newinfo, 0);
762 if (!found)
763 module_put(newinfo->fbops->owner);
764 err = -ENODEV;
765 }
766
767 if (!err) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700768 fbcon_del_cursor_timer(oldinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 kfree(ops->cursor_state.mask);
770 kfree(ops->cursor_data);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800771 kfree(ops->fontbuffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 kfree(oldinfo->fbcon_par);
773 oldinfo->fbcon_par = NULL;
774 module_put(oldinfo->fbops->owner);
Antonino A. Daplasdd0314f2005-11-07 01:00:38 -0800775 /*
776 If oldinfo and newinfo are driving the same hardware,
777 the fb_release() method of oldinfo may attempt to
778 restore the hardware state. This will leave the
779 newinfo in an undefined state. Thus, a call to
780 fb_set_par() may be needed for the newinfo.
781 */
782 if (newinfo->fbops->fb_set_par)
783 newinfo->fbops->fb_set_par(newinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
785
786 return err;
787}
788
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789static void con2fb_init_display(struct vc_data *vc, struct fb_info *info,
790 int unit, int show_logo)
791{
792 struct fbcon_ops *ops = info->fbcon_par;
793
794 ops->currcon = fg_console;
795
796 if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT))
797 info->fbops->fb_set_par(info);
798
799 ops->flags |= FBCON_FLAGS_INIT;
800 ops->graphics = 0;
801
802 if (vc)
803 fbcon_set_disp(info, &info->var, vc);
804 else
805 fbcon_preset_disp(info, &info->var, unit);
806
807 if (show_logo) {
808 struct vc_data *fg_vc = vc_cons[fg_console].d;
809 struct fb_info *fg_info =
810 registered_fb[con2fb_map[fg_console]];
811
812 fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols,
813 fg_vc->vc_rows, fg_vc->vc_cols,
814 fg_vc->vc_rows);
815 }
816
817 update_screen(vc_cons[fg_console].d);
818}
819
820/**
821 * set_con2fb_map - map console to frame buffer device
822 * @unit: virtual console number to map
823 * @newidx: frame buffer index to map virtual console to
824 * @user: user request
825 *
826 * Maps a virtual console @unit to a frame buffer device
827 * @newidx.
828 */
829static int set_con2fb_map(int unit, int newidx, int user)
830{
831 struct vc_data *vc = vc_cons[unit].d;
832 int oldidx = con2fb_map[unit];
833 struct fb_info *info = registered_fb[newidx];
834 struct fb_info *oldinfo = NULL;
835 int found, err = 0;
836
837 if (oldidx == newidx)
838 return 0;
839
Antonino A. Daplase614b182006-06-26 00:27:09 -0700840 if (!info || fbcon_has_exited)
841 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 if (!err && !search_for_mapped_con()) {
844 info_idx = newidx;
845 return fbcon_takeover(0);
846 }
847
848 if (oldidx != -1)
849 oldinfo = registered_fb[oldidx];
850
851 found = search_fb_in_map(newidx);
852
853 acquire_console_sem();
854 con2fb_map[unit] = newidx;
855 if (!err && !found)
856 err = con2fb_acquire_newinfo(vc, info, unit, oldidx);
857
858
859 /*
860 * If old fb is not mapped to any of the consoles,
861 * fbcon should release it.
862 */
863 if (!err && oldinfo && !search_fb_in_map(oldidx))
864 err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx,
865 found);
866
867 if (!err) {
868 int show_logo = (fg_console == 0 && !user &&
869 logo_shown != FBCON_LOGO_DONTSHOW);
870
871 if (!found)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -0700872 fbcon_add_cursor_timer(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 con2fb_map_boot[unit] = newidx;
874 con2fb_init_display(vc, info, unit, show_logo);
875 }
876
Antonino A. Daplase614b182006-06-26 00:27:09 -0700877 if (!search_fb_in_map(info_idx))
878 info_idx = newidx;
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 release_console_sem();
881 return err;
882}
883
884/*
885 * Low Level Operations
886 */
887/* NOTE: fbcon cannot be __init: it may be called from take_over_console later */
888static int var_to_display(struct display *disp,
889 struct fb_var_screeninfo *var,
890 struct fb_info *info)
891{
892 disp->xres_virtual = var->xres_virtual;
893 disp->yres_virtual = var->yres_virtual;
894 disp->bits_per_pixel = var->bits_per_pixel;
895 disp->grayscale = var->grayscale;
896 disp->nonstd = var->nonstd;
897 disp->accel_flags = var->accel_flags;
898 disp->height = var->height;
899 disp->width = var->width;
900 disp->red = var->red;
901 disp->green = var->green;
902 disp->blue = var->blue;
903 disp->transp = var->transp;
904 disp->rotate = var->rotate;
905 disp->mode = fb_match_mode(var, &info->modelist);
906 if (disp->mode == NULL)
907 /* This should not happen */
908 return -EINVAL;
909 return 0;
910}
911
912static void display_to_var(struct fb_var_screeninfo *var,
913 struct display *disp)
914{
915 fb_videomode_to_var(var, disp->mode);
916 var->xres_virtual = disp->xres_virtual;
917 var->yres_virtual = disp->yres_virtual;
918 var->bits_per_pixel = disp->bits_per_pixel;
919 var->grayscale = disp->grayscale;
920 var->nonstd = disp->nonstd;
921 var->accel_flags = disp->accel_flags;
922 var->height = disp->height;
923 var->width = disp->width;
924 var->red = disp->red;
925 var->green = disp->green;
926 var->blue = disp->blue;
927 var->transp = disp->transp;
928 var->rotate = disp->rotate;
929}
930
931static const char *fbcon_startup(void)
932{
933 const char *display_desc = "frame buffer device";
934 struct display *p = &fb_display[fg_console];
935 struct vc_data *vc = vc_cons[fg_console].d;
Jan Beulich2f4516d2005-09-13 01:25:44 -0700936 const struct font_desc *font = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 struct module *owner;
938 struct fb_info *info = NULL;
939 struct fbcon_ops *ops;
940 int rows, cols;
941 int irqres;
942
943 irqres = 1;
944 /*
945 * If num_registered_fb is zero, this is a call for the dummy part.
946 * The frame buffer devices weren't initialized yet.
947 */
948 if (!num_registered_fb || info_idx == -1)
949 return display_desc;
950 /*
951 * Instead of blindly using registered_fb[0], we use info_idx, set by
952 * fb_console_init();
953 */
954 info = registered_fb[info_idx];
955 if (!info)
956 return NULL;
957
958 owner = info->fbops->owner;
959 if (!try_module_get(owner))
960 return NULL;
961 if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) {
962 module_put(owner);
963 return NULL;
964 }
965
Antonino A. Daplasa39bc342006-01-09 20:53:44 -0800966 ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (!ops) {
968 module_put(owner);
969 return NULL;
970 }
971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 ops->currcon = -1;
973 ops->graphics = 1;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800974 ops->cur_rotate = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 info->fbcon_par = ops;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -0800976 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -0800977 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 if (info->fix.type != FB_TYPE_TEXT) {
980 if (fbcon_softback_size) {
981 if (!softback_buf) {
982 softback_buf =
983 (unsigned long)
984 kmalloc(fbcon_softback_size,
985 GFP_KERNEL);
986 if (!softback_buf) {
987 fbcon_softback_size = 0;
988 softback_top = 0;
989 }
990 }
991 } else {
992 if (softback_buf) {
993 kfree((void *) softback_buf);
994 softback_buf = 0;
995 softback_top = 0;
996 }
997 }
998 if (softback_buf)
999 softback_in = softback_top = softback_curr =
1000 softback_buf;
1001 softback_lines = 0;
1002 }
1003
1004 /* Setup default font */
1005 if (!p->fontdata) {
1006 if (!fontname[0] || !(font = find_font(fontname)))
1007 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001008 info->var.yres,
1009 info->pixmap.blit_x,
1010 info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 vc->vc_font.width = font->width;
1012 vc->vc_font.height = font->height;
Jan Beulich2f4516d2005-09-13 01:25:44 -07001013 vc->vc_font.data = (void *)(p->fontdata = font->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 vc->vc_font.charcount = 256; /* FIXME Need to support more fonts */
1015 }
1016
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001017 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1018 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1019 cols /= vc->vc_font.width;
1020 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 vc_resize(vc, cols, rows);
1022
1023 DPRINTK("mode: %s\n", info->fix.id);
1024 DPRINTK("visual: %d\n", info->fix.visual);
1025 DPRINTK("res: %dx%d-%d\n", info->var.xres,
1026 info->var.yres,
1027 info->var.bits_per_pixel);
1028
1029#ifdef CONFIG_ATARI
1030 if (MACH_IS_ATARI) {
1031 cursor_blink_rate = ATARI_CURSOR_BLINK_RATE;
1032 irqres =
1033 request_irq(IRQ_AUTO_4, fb_vbl_handler,
1034 IRQ_TYPE_PRIO, "framebuffer vbl",
1035 info);
1036 }
1037#endif /* CONFIG_ATARI */
1038
1039#ifdef CONFIG_MAC
1040 /*
1041 * On a Macintoy, the VBL interrupt may or may not be active.
1042 * As interrupt based cursor is more reliable and race free, we
1043 * probe for VBL interrupts.
1044 */
1045 if (MACH_IS_MAC) {
1046 int ct = 0;
1047 /*
1048 * Probe for VBL: set temp. handler ...
1049 */
1050 irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0,
1051 "framebuffer vbl", info);
1052 vbl_detected = 0;
1053
1054 /*
1055 * ... and spin for 20 ms ...
1056 */
1057 while (!vbl_detected && ++ct < 1000)
1058 udelay(20);
1059
1060 if (ct == 1000)
1061 printk
1062 ("fbcon_startup: No VBL detected, using timer based cursor.\n");
1063
1064 free_irq(IRQ_MAC_VBL, fb_vbl_detect);
1065
1066 if (vbl_detected) {
1067 /*
1068 * interrupt based cursor ok
1069 */
1070 cursor_blink_rate = MAC_CURSOR_BLINK_RATE;
1071 irqres =
1072 request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0,
1073 "framebuffer vbl", info);
1074 } else {
1075 /*
1076 * VBL not detected: fall through, use timer based cursor
1077 */
1078 irqres = 1;
1079 }
1080 }
1081#endif /* CONFIG_MAC */
1082
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07001083 fbcon_add_cursor_timer(info);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001084 fbcon_has_exited = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 return display_desc;
1086}
1087
1088static void fbcon_init(struct vc_data *vc, int init)
1089{
1090 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1091 struct fbcon_ops *ops;
1092 struct vc_data **default_mode = vc->vc_display_fg;
1093 struct vc_data *svc = *default_mode;
1094 struct display *t, *p = &fb_display[vc->vc_num];
1095 int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256;
Adrian Bunk306958e2005-05-01 08:59:23 -07001096 int cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 if (info_idx == -1 || info == NULL)
1099 return;
Adrian Bunk306958e2005-05-01 08:59:23 -07001100
1101 cap = info->flags;
1102
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW ||
1104 (info->fix.type == FB_TYPE_TEXT))
1105 logo = 0;
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if (var_to_display(p, &info->var, info))
1108 return;
1109
1110 /* If we are not the first console on this
1111 fb, copy the font from that console */
Antonino A. Daplase614b182006-06-26 00:27:09 -07001112 t = &fb_display[fg_console];
1113 if (!p->fontdata) {
1114 if (t->fontdata) {
1115 struct vc_data *fvc = vc_cons[fg_console].d;
1116
1117 vc->vc_font.data = (void *)(p->fontdata =
1118 fvc->vc_font.data);
1119 vc->vc_font.width = fvc->vc_font.width;
1120 vc->vc_font.height = fvc->vc_font.height;
1121 p->userfont = t->userfont;
1122
1123 if (p->userfont)
1124 REFCOUNT(p->fontdata)++;
1125 } else {
1126 const struct font_desc *font = NULL;
1127
1128 if (!fontname[0] || !(font = find_font(fontname)))
1129 font = get_default_font(info->var.xres,
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07001130 info->var.yres,
1131 info->pixmap.blit_x,
1132 info->pixmap.blit_y);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001133 vc->vc_font.width = font->width;
1134 vc->vc_font.height = font->height;
1135 vc->vc_font.data = (void *)(p->fontdata = font->data);
1136 vc->vc_font.charcount = 256; /* FIXME Need to
1137 support more fonts */
1138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 if (p->userfont)
1142 charcnt = FNTCHARCNT(p->fontdata);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001143
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001144 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1146 if (charcnt == 256) {
1147 vc->vc_hi_font_mask = 0;
1148 } else {
1149 vc->vc_hi_font_mask = 0x100;
1150 if (vc->vc_can_do_color)
1151 vc->vc_complement_mask <<= 1;
1152 }
1153
1154 if (!*svc->vc_uni_pagedir_loc)
1155 con_set_default_unimap(svc);
1156 if (!*vc->vc_uni_pagedir_loc)
1157 con_copy_unimap(vc, svc);
1158
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001159 ops = info->fbcon_par;
1160 p->con_rotate = rotate;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001161 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 cols = vc->vc_cols;
1164 rows = vc->vc_rows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001165 new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1166 new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1167 new_cols /= vc->vc_font.width;
1168 new_rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 vc_resize(vc, new_cols, new_rows);
1170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /*
1172 * We must always set the mode. The mode of the previous console
1173 * driver could be in the same resolution but we are using different
1174 * hardware so we have to initialize the hardware.
1175 *
1176 * We need to do it in fbcon_init() to prevent screen corruption.
1177 */
Knut Petersend354d9a2006-01-07 10:22:04 +01001178 if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (info->fbops->fb_set_par &&
1180 !(ops->flags & FBCON_FLAGS_INIT))
1181 info->fbops->fb_set_par(info);
1182 ops->flags |= FBCON_FLAGS_INIT;
1183 }
1184
1185 ops->graphics = 0;
1186
1187 if ((cap & FBINFO_HWACCEL_COPYAREA) &&
1188 !(cap & FBINFO_HWACCEL_DISABLED))
1189 p->scrollmode = SCROLL_MOVE;
1190 else /* default to something safe */
1191 p->scrollmode = SCROLL_REDRAW;
1192
1193 /*
1194 * ++guenther: console.c:vc_allocate() relies on initializing
1195 * vc_{cols,rows}, but we must not set those if we are only
1196 * resizing the console.
1197 */
1198 if (!init) {
1199 vc->vc_cols = new_cols;
1200 vc->vc_rows = new_rows;
1201 }
1202
1203 if (logo)
1204 fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows);
1205
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001206 if (vc == svc && softback_buf)
1207 fbcon_update_softback(vc);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001208
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001209 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001210 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001211 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001212 }
1213
Antonino A. Daplas1a37d5f2006-03-31 02:31:45 -08001214 ops->p = &fb_display[fg_console];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Antonino A. Daplase614b182006-06-26 00:27:09 -07001217static void fbcon_free_font(struct display *p)
1218{
1219 if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0))
1220 kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int));
1221 p->fontdata = NULL;
1222 p->userfont = 0;
1223}
1224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225static void fbcon_deinit(struct vc_data *vc)
1226{
1227 struct display *p = &fb_display[vc->vc_num];
Antonino A. Daplase614b182006-06-26 00:27:09 -07001228 struct fb_info *info;
1229 struct fbcon_ops *ops;
1230 int idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 fbcon_free_font(p);
Antonino A. Daplase614b182006-06-26 00:27:09 -07001233 idx = con2fb_map[vc->vc_num];
1234
1235 if (idx == -1)
1236 goto finished;
1237
1238 info = registered_fb[idx];
1239
1240 if (!info)
1241 goto finished;
1242
1243 ops = info->fbcon_par;
1244
1245 if (!ops)
1246 goto finished;
1247
1248 if (CON_IS_VISIBLE(vc))
1249 fbcon_del_cursor_timer(info);
1250
1251 ops->flags &= ~FBCON_FLAGS_INIT;
1252finished:
1253
1254 if (!con_is_bound(&fb_con))
1255 fbcon_exit();
1256
1257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258}
1259
1260/* ====================================================================== */
1261
1262/* fbcon_XXX routines - interface used by the world
1263 *
1264 * This system is now divided into two levels because of complications
1265 * caused by hardware scrolling. Top level functions:
1266 *
1267 * fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins()
1268 *
1269 * handles y values in range [0, scr_height-1] that correspond to real
1270 * screen positions. y_wrap shift means that first line of bitmap may be
1271 * anywhere on this display. These functions convert lineoffsets to
1272 * bitmap offsets and deal with the wrap-around case by splitting blits.
1273 *
1274 * fbcon_bmove_physical_8() -- These functions fast implementations
1275 * fbcon_clear_physical_8() -- of original fbcon_XXX fns.
1276 * fbcon_putc_physical_8() -- (font width != 8) may be added later
1277 *
1278 * WARNING:
1279 *
1280 * At the moment fbcon_putc() cannot blit across vertical wrap boundary
1281 * Implies should only really hardware scroll in rows. Only reason for
1282 * restriction is simplicity & efficiency at the moment.
1283 */
1284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height,
1286 int width)
1287{
1288 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1289 struct fbcon_ops *ops = info->fbcon_par;
1290
1291 struct display *p = &fb_display[vc->vc_num];
1292 u_int y_break;
1293
1294 if (fbcon_is_inactive(vc, info))
1295 return;
1296
1297 if (!height || !width)
1298 return;
1299
1300 /* Split blits that cross physical y_wrap boundary */
1301
1302 y_break = p->vrows - p->yscroll;
1303 if (sy < y_break && sy + height - 1 >= y_break) {
1304 u_int b = y_break - sy;
1305 ops->clear(vc, info, real_y(p, sy), sx, b, width);
1306 ops->clear(vc, info, real_y(p, sy + b), sx, height - b,
1307 width);
1308 } else
1309 ops->clear(vc, info, real_y(p, sy), sx, height, width);
1310}
1311
1312static void fbcon_putcs(struct vc_data *vc, const unsigned short *s,
1313 int count, int ypos, int xpos)
1314{
1315 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1316 struct display *p = &fb_display[vc->vc_num];
1317 struct fbcon_ops *ops = info->fbcon_par;
1318
1319 if (!fbcon_is_inactive(vc, info))
1320 ops->putcs(vc, info, s, count, real_y(p, ypos), xpos,
1321 get_color(vc, info, scr_readw(s), 1),
1322 get_color(vc, info, scr_readw(s), 0));
1323}
1324
1325static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos)
1326{
1327 unsigned short chr;
1328
1329 scr_writew(c, &chr);
1330 fbcon_putcs(vc, &chr, 1, ypos, xpos);
1331}
1332
1333static void fbcon_clear_margins(struct vc_data *vc, int bottom_only)
1334{
1335 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1336 struct fbcon_ops *ops = info->fbcon_par;
1337
1338 if (!fbcon_is_inactive(vc, info))
1339 ops->clear_margins(vc, info, bottom_only);
1340}
1341
1342static void fbcon_cursor(struct vc_data *vc, int mode)
1343{
1344 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1345 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 int y;
1347 int c = scr_readw((u16 *) vc->vc_pos);
1348
Michal Januszewskid1e23062007-05-08 00:38:07 -07001349 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 return;
1351
1352 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
1353 if (mode & CM_SOFTBACK) {
1354 mode &= ~CM_SOFTBACK;
1355 y = softback_lines;
1356 } else {
1357 if (softback_lines)
1358 fbcon_set_origin(vc);
1359 y = 0;
1360 }
1361
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08001362 ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 get_color(vc, info, c, 0));
1364 vbl_cursor_cnt = CURSOR_DRAW_DELAY;
1365}
1366
1367static int scrollback_phys_max = 0;
1368static int scrollback_max = 0;
1369static int scrollback_current = 0;
1370
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371/*
1372 * If no vc is existent yet, just set struct display
1373 */
1374static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1375 int unit)
1376{
1377 struct display *p = &fb_display[unit];
1378 struct display *t = &fb_display[fg_console];
1379
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (var_to_display(p, var, info))
1381 return;
1382
1383 p->fontdata = t->fontdata;
1384 p->userfont = t->userfont;
1385 if (p->userfont)
1386 REFCOUNT(p->fontdata)++;
1387}
1388
1389static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var,
1390 struct vc_data *vc)
1391{
1392 struct display *p = &fb_display[vc->vc_num], *t;
1393 struct vc_data **default_mode = vc->vc_display_fg;
1394 struct vc_data *svc = *default_mode;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001395 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 int rows, cols, charcnt = 256;
1397
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 if (var_to_display(p, var, info))
1399 return;
1400 t = &fb_display[svc->vc_num];
1401 if (!vc->vc_font.data) {
Jan Beulich2f4516d2005-09-13 01:25:44 -07001402 vc->vc_font.data = (void *)(p->fontdata = t->fontdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 vc->vc_font.width = (*default_mode)->vc_font.width;
1404 vc->vc_font.height = (*default_mode)->vc_font.height;
1405 p->userfont = t->userfont;
1406 if (p->userfont)
1407 REFCOUNT(p->fontdata)++;
1408 }
1409 if (p->userfont)
1410 charcnt = FNTCHARCNT(p->fontdata);
1411
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001412 var->activate = FB_ACTIVATE_NOW;
1413 info->var.activate = var->activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001414 var->yoffset = info->var.yoffset;
1415 var->xoffset = info->var.xoffset;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001416 fb_set_var(info, var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001417 ops->var = info->var;
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07001418 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
1420 if (charcnt == 256) {
1421 vc->vc_hi_font_mask = 0;
1422 } else {
1423 vc->vc_hi_font_mask = 0x100;
1424 if (vc->vc_can_do_color)
1425 vc->vc_complement_mask <<= 1;
1426 }
1427
1428 if (!*svc->vc_uni_pagedir_loc)
1429 con_set_default_unimap(svc);
1430 if (!*vc->vc_uni_pagedir_loc)
1431 con_copy_unimap(vc, svc);
1432
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001433 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
1434 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
1435 cols /= vc->vc_font.width;
1436 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 vc_resize(vc, cols, rows);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (CON_IS_VISIBLE(vc)) {
1440 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08001441 if (softback_buf)
1442 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 }
1444}
1445
1446static __inline__ void ywrap_up(struct vc_data *vc, int count)
1447{
1448 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001449 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 struct display *p = &fb_display[vc->vc_num];
1451
1452 p->yscroll += count;
1453 if (p->yscroll >= p->vrows) /* Deal with wrap */
1454 p->yscroll -= p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001455 ops->var.xoffset = 0;
1456 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1457 ops->var.vmode |= FB_VMODE_YWRAP;
1458 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 scrollback_max += count;
1460 if (scrollback_max > scrollback_phys_max)
1461 scrollback_max = scrollback_phys_max;
1462 scrollback_current = 0;
1463}
1464
1465static __inline__ void ywrap_down(struct vc_data *vc, int count)
1466{
1467 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001468 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 struct display *p = &fb_display[vc->vc_num];
1470
1471 p->yscroll -= count;
1472 if (p->yscroll < 0) /* Deal with wrap */
1473 p->yscroll += p->vrows;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001474 ops->var.xoffset = 0;
1475 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1476 ops->var.vmode |= FB_VMODE_YWRAP;
1477 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 scrollback_max -= count;
1479 if (scrollback_max < 0)
1480 scrollback_max = 0;
1481 scrollback_current = 0;
1482}
1483
1484static __inline__ void ypan_up(struct vc_data *vc, int count)
1485{
1486 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1487 struct display *p = &fb_display[vc->vc_num];
1488 struct fbcon_ops *ops = info->fbcon_par;
1489
1490 p->yscroll += count;
1491 if (p->yscroll > p->vrows - vc->vc_rows) {
1492 ops->bmove(vc, info, p->vrows - vc->vc_rows,
1493 0, 0, 0, vc->vc_rows, vc->vc_cols);
1494 p->yscroll -= p->vrows - vc->vc_rows;
1495 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001496
1497 ops->var.xoffset = 0;
1498 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1499 ops->var.vmode &= ~FB_VMODE_YWRAP;
1500 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 fbcon_clear_margins(vc, 1);
1502 scrollback_max += count;
1503 if (scrollback_max > scrollback_phys_max)
1504 scrollback_max = scrollback_phys_max;
1505 scrollback_current = 0;
1506}
1507
1508static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count)
1509{
1510 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001511 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 p->yscroll += count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 if (p->yscroll > p->vrows - vc->vc_rows) {
1517 p->yscroll -= p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001519 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001520
1521 ops->var.xoffset = 0;
1522 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1523 ops->var.vmode &= ~FB_VMODE_YWRAP;
1524 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 fbcon_clear_margins(vc, 1);
1526 scrollback_max += count;
1527 if (scrollback_max > scrollback_phys_max)
1528 scrollback_max = scrollback_phys_max;
1529 scrollback_current = 0;
1530}
1531
1532static __inline__ void ypan_down(struct vc_data *vc, int count)
1533{
1534 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1535 struct display *p = &fb_display[vc->vc_num];
1536 struct fbcon_ops *ops = info->fbcon_par;
1537
1538 p->yscroll -= count;
1539 if (p->yscroll < 0) {
1540 ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows,
1541 0, vc->vc_rows, vc->vc_cols);
1542 p->yscroll += p->vrows - vc->vc_rows;
1543 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001544
1545 ops->var.xoffset = 0;
1546 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1547 ops->var.vmode &= ~FB_VMODE_YWRAP;
1548 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 fbcon_clear_margins(vc, 1);
1550 scrollback_max -= count;
1551 if (scrollback_max < 0)
1552 scrollback_max = 0;
1553 scrollback_current = 0;
1554}
1555
1556static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count)
1557{
1558 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001559 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 p->yscroll -= count;
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001563
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 if (p->yscroll < 0) {
1565 p->yscroll += p->vrows - vc->vc_rows;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08001567 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08001568
1569 ops->var.xoffset = 0;
1570 ops->var.yoffset = p->yscroll * vc->vc_font.height;
1571 ops->var.vmode &= ~FB_VMODE_YWRAP;
1572 ops->update_start(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 fbcon_clear_margins(vc, 1);
1574 scrollback_max -= count;
1575 if (scrollback_max < 0)
1576 scrollback_max = 0;
1577 scrollback_current = 0;
1578}
1579
1580static void fbcon_redraw_softback(struct vc_data *vc, struct display *p,
1581 long delta)
1582{
1583 int count = vc->vc_rows;
1584 unsigned short *d, *s;
1585 unsigned long n;
1586 int line = 0;
1587
1588 d = (u16 *) softback_curr;
1589 if (d == (u16 *) softback_in)
1590 d = (u16 *) vc->vc_origin;
1591 n = softback_curr + delta * vc->vc_size_row;
1592 softback_lines -= delta;
1593 if (delta < 0) {
1594 if (softback_curr < softback_top && n < softback_buf) {
1595 n += softback_end - softback_buf;
1596 if (n < softback_top) {
1597 softback_lines -=
1598 (softback_top - n) / vc->vc_size_row;
1599 n = softback_top;
1600 }
1601 } else if (softback_curr >= softback_top
1602 && n < softback_top) {
1603 softback_lines -=
1604 (softback_top - n) / vc->vc_size_row;
1605 n = softback_top;
1606 }
1607 } else {
1608 if (softback_curr > softback_in && n >= softback_end) {
1609 n += softback_buf - softback_end;
1610 if (n > softback_in) {
1611 n = softback_in;
1612 softback_lines = 0;
1613 }
1614 } else if (softback_curr <= softback_in && n > softback_in) {
1615 n = softback_in;
1616 softback_lines = 0;
1617 }
1618 }
1619 if (n == softback_curr)
1620 return;
1621 softback_curr = n;
1622 s = (u16 *) softback_curr;
1623 if (s == (u16 *) softback_in)
1624 s = (u16 *) vc->vc_origin;
1625 while (count--) {
1626 unsigned short *start;
1627 unsigned short *le;
1628 unsigned short c;
1629 int x = 0;
1630 unsigned short attr = 1;
1631
1632 start = s;
1633 le = advance_row(s, 1);
1634 do {
1635 c = scr_readw(s);
1636 if (attr != (c & 0xff00)) {
1637 attr = c & 0xff00;
1638 if (s > start) {
1639 fbcon_putcs(vc, start, s - start,
1640 line, x);
1641 x += s - start;
1642 start = s;
1643 }
1644 }
1645 if (c == scr_readw(d)) {
1646 if (s > start) {
1647 fbcon_putcs(vc, start, s - start,
1648 line, x);
1649 x += s - start + 1;
1650 start = s + 1;
1651 } else {
1652 x++;
1653 start++;
1654 }
1655 }
1656 s++;
1657 d++;
1658 } while (s < le);
1659 if (s > start)
1660 fbcon_putcs(vc, start, s - start, line, x);
1661 line++;
1662 if (d == (u16 *) softback_end)
1663 d = (u16 *) softback_buf;
1664 if (d == (u16 *) softback_in)
1665 d = (u16 *) vc->vc_origin;
1666 if (s == (u16 *) softback_end)
1667 s = (u16 *) softback_buf;
1668 if (s == (u16 *) softback_in)
1669 s = (u16 *) vc->vc_origin;
1670 }
1671}
1672
1673static void fbcon_redraw_move(struct vc_data *vc, struct display *p,
1674 int line, int count, int dy)
1675{
1676 unsigned short *s = (unsigned short *)
1677 (vc->vc_origin + vc->vc_size_row * line);
1678
1679 while (count--) {
1680 unsigned short *start = s;
1681 unsigned short *le = advance_row(s, 1);
1682 unsigned short c;
1683 int x = 0;
1684 unsigned short attr = 1;
1685
1686 do {
1687 c = scr_readw(s);
1688 if (attr != (c & 0xff00)) {
1689 attr = c & 0xff00;
1690 if (s > start) {
1691 fbcon_putcs(vc, start, s - start,
1692 dy, x);
1693 x += s - start;
1694 start = s;
1695 }
1696 }
1697 console_conditional_schedule();
1698 s++;
1699 } while (s < le);
1700 if (s > start)
1701 fbcon_putcs(vc, start, s - start, dy, x);
1702 console_conditional_schedule();
1703 dy++;
1704 }
1705}
1706
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001707static void fbcon_redraw_blit(struct vc_data *vc, struct fb_info *info,
1708 struct display *p, int line, int count, int ycount)
1709{
1710 int offset = ycount * vc->vc_cols;
1711 unsigned short *d = (unsigned short *)
1712 (vc->vc_origin + vc->vc_size_row * line);
1713 unsigned short *s = d + offset;
1714 struct fbcon_ops *ops = info->fbcon_par;
1715
1716 while (count--) {
1717 unsigned short *start = s;
1718 unsigned short *le = advance_row(s, 1);
1719 unsigned short c;
1720 int x = 0;
1721
1722 do {
1723 c = scr_readw(s);
1724
1725 if (c == scr_readw(d)) {
1726 if (s > start) {
1727 ops->bmove(vc, info, line + ycount, x,
1728 line, x, 1, s-start);
1729 x += s - start + 1;
1730 start = s + 1;
1731 } else {
1732 x++;
1733 start++;
1734 }
1735 }
1736
1737 scr_writew(c, d);
1738 console_conditional_schedule();
1739 s++;
1740 d++;
1741 } while (s < le);
1742 if (s > start)
1743 ops->bmove(vc, info, line + ycount, x, line, x, 1,
1744 s-start);
1745 console_conditional_schedule();
1746 if (ycount > 0)
1747 line++;
1748 else {
1749 line--;
1750 /* NOTE: We subtract two lines from these pointers */
1751 s -= vc->vc_size_row;
1752 d -= vc->vc_size_row;
1753 }
1754 }
1755}
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757static void fbcon_redraw(struct vc_data *vc, struct display *p,
1758 int line, int count, int offset)
1759{
1760 unsigned short *d = (unsigned short *)
1761 (vc->vc_origin + vc->vc_size_row * line);
1762 unsigned short *s = d + offset;
1763
1764 while (count--) {
1765 unsigned short *start = s;
1766 unsigned short *le = advance_row(s, 1);
1767 unsigned short c;
1768 int x = 0;
1769 unsigned short attr = 1;
1770
1771 do {
1772 c = scr_readw(s);
1773 if (attr != (c & 0xff00)) {
1774 attr = c & 0xff00;
1775 if (s > start) {
1776 fbcon_putcs(vc, start, s - start,
1777 line, x);
1778 x += s - start;
1779 start = s;
1780 }
1781 }
1782 if (c == scr_readw(d)) {
1783 if (s > start) {
1784 fbcon_putcs(vc, start, s - start,
1785 line, x);
1786 x += s - start + 1;
1787 start = s + 1;
1788 } else {
1789 x++;
1790 start++;
1791 }
1792 }
1793 scr_writew(c, d);
1794 console_conditional_schedule();
1795 s++;
1796 d++;
1797 } while (s < le);
1798 if (s > start)
1799 fbcon_putcs(vc, start, s - start, line, x);
1800 console_conditional_schedule();
1801 if (offset > 0)
1802 line++;
1803 else {
1804 line--;
1805 /* NOTE: We subtract two lines from these pointers */
1806 s -= vc->vc_size_row;
1807 d -= vc->vc_size_row;
1808 }
1809 }
1810}
1811
1812static inline void fbcon_softback_note(struct vc_data *vc, int t,
1813 int count)
1814{
1815 unsigned short *p;
1816
1817 if (vc->vc_num != fg_console)
1818 return;
1819 p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row);
1820
1821 while (count) {
1822 scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row);
1823 count--;
1824 p = advance_row(p, 1);
1825 softback_in += vc->vc_size_row;
1826 if (softback_in == softback_end)
1827 softback_in = softback_buf;
1828 if (softback_in == softback_top) {
1829 softback_top += vc->vc_size_row;
1830 if (softback_top == softback_end)
1831 softback_top = softback_buf;
1832 }
1833 }
1834 softback_curr = softback_in;
1835}
1836
1837static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1838 int count)
1839{
1840 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1841 struct display *p = &fb_display[vc->vc_num];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1843
1844 if (fbcon_is_inactive(vc, info))
1845 return -EINVAL;
1846
1847 fbcon_cursor(vc, CM_ERASE);
1848
1849 /*
1850 * ++Geert: Only use ywrap/ypan if the console is in text mode
1851 * ++Andrew: Only use ypan on hardware text mode when scrolling the
1852 * whole screen (prevents flicker).
1853 */
1854
1855 switch (dir) {
1856 case SM_UP:
1857 if (count > vc->vc_rows) /* Maximum realistic size */
1858 count = vc->vc_rows;
1859 if (softback_top)
1860 fbcon_softback_note(vc, t, count);
1861 if (logo_shown >= 0)
1862 goto redraw_up;
1863 switch (p->scrollmode) {
1864 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001865 fbcon_redraw_blit(vc, info, p, t, b - t - count,
1866 count);
1867 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1868 scr_memsetw((unsigned short *) (vc->vc_origin +
1869 vc->vc_size_row *
1870 (b - count)),
1871 vc->vc_video_erase_char,
1872 vc->vc_size_row * count);
1873 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 break;
1875
1876 case SCROLL_WRAP_MOVE:
1877 if (b - t - count > 3 * vc->vc_rows >> 2) {
1878 if (t > 0)
1879 fbcon_bmove(vc, 0, 0, count, 0, t,
1880 vc->vc_cols);
1881 ywrap_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_PAN_REDRAW:
1895 if ((p->yscroll + count <=
1896 2 * (p->vrows - vc->vc_rows))
1897 && ((!scroll_partial && (b - t == vc->vc_rows))
1898 || (scroll_partial
1899 && (b - t - count >
1900 3 * vc->vc_rows >> 2)))) {
1901 if (t > 0)
1902 fbcon_redraw_move(vc, p, 0, t, count);
1903 ypan_up_redraw(vc, t, count);
1904 if (vc->vc_rows - b > 0)
Malcom Parsons26e780e2006-06-08 00:43:42 -07001905 fbcon_redraw_move(vc, p, b,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 vc->vc_rows - b, b);
1907 } else
1908 fbcon_redraw_move(vc, p, t + count, b - t - count, t);
1909 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1910 break;
1911
1912 case SCROLL_PAN_MOVE:
1913 if ((p->yscroll + count <=
1914 2 * (p->vrows - vc->vc_rows))
1915 && ((!scroll_partial && (b - t == vc->vc_rows))
1916 || (scroll_partial
1917 && (b - t - count >
1918 3 * vc->vc_rows >> 2)))) {
1919 if (t > 0)
1920 fbcon_bmove(vc, 0, 0, count, 0, t,
1921 vc->vc_cols);
1922 ypan_up(vc, count);
1923 if (vc->vc_rows - b > 0)
1924 fbcon_bmove(vc, b - count, 0, b, 0,
1925 vc->vc_rows - b,
1926 vc->vc_cols);
1927 } else if (info->flags & FBINFO_READS_FAST)
1928 fbcon_bmove(vc, t + count, 0, t, 0,
1929 b - t - count, vc->vc_cols);
1930 else
1931 goto redraw_up;
1932 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1933 break;
1934
1935 case SCROLL_REDRAW:
1936 redraw_up:
1937 fbcon_redraw(vc, p, t, b - t - count,
1938 count * vc->vc_cols);
1939 fbcon_clear(vc, b - count, 0, count, vc->vc_cols);
1940 scr_memsetw((unsigned short *) (vc->vc_origin +
1941 vc->vc_size_row *
1942 (b - count)),
1943 vc->vc_video_erase_char,
1944 vc->vc_size_row * count);
1945 return 1;
1946 }
1947 break;
1948
1949 case SM_DOWN:
1950 if (count > vc->vc_rows) /* Maximum realistic size */
1951 count = vc->vc_rows;
Jan Beuliche703ecc2005-09-13 01:25:43 -07001952 if (logo_shown >= 0)
1953 goto redraw_down;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 switch (p->scrollmode) {
1955 case SCROLL_MOVE:
Krzysztof Heltbad07ff2007-07-17 04:05:25 -07001956 fbcon_redraw_blit(vc, info, p, b - 1, b - t - count,
1957 -count);
1958 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1959 scr_memsetw((unsigned short *) (vc->vc_origin +
1960 vc->vc_size_row *
1961 t),
1962 vc->vc_video_erase_char,
1963 vc->vc_size_row * count);
1964 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 break;
1966
1967 case SCROLL_WRAP_MOVE:
1968 if (b - t - count > 3 * vc->vc_rows >> 2) {
1969 if (vc->vc_rows - b > 0)
1970 fbcon_bmove(vc, b, 0, b - count, 0,
1971 vc->vc_rows - b,
1972 vc->vc_cols);
1973 ywrap_down(vc, count);
1974 if (t > 0)
1975 fbcon_bmove(vc, count, 0, 0, 0, t,
1976 vc->vc_cols);
1977 } else if (info->flags & FBINFO_READS_FAST)
1978 fbcon_bmove(vc, t, 0, t + count, 0,
1979 b - t - count, vc->vc_cols);
1980 else
1981 goto redraw_down;
1982 fbcon_clear(vc, t, 0, count, vc->vc_cols);
1983 break;
1984
1985 case SCROLL_PAN_MOVE:
1986 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
1987 && ((!scroll_partial && (b - t == vc->vc_rows))
1988 || (scroll_partial
1989 && (b - t - count >
1990 3 * vc->vc_rows >> 2)))) {
1991 if (vc->vc_rows - b > 0)
1992 fbcon_bmove(vc, b, 0, b - count, 0,
1993 vc->vc_rows - b,
1994 vc->vc_cols);
1995 ypan_down(vc, count);
1996 if (t > 0)
1997 fbcon_bmove(vc, count, 0, 0, 0, t,
1998 vc->vc_cols);
1999 } else if (info->flags & FBINFO_READS_FAST)
2000 fbcon_bmove(vc, t, 0, t + count, 0,
2001 b - t - count, vc->vc_cols);
2002 else
2003 goto redraw_down;
2004 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2005 break;
2006
2007 case SCROLL_PAN_REDRAW:
2008 if ((count - p->yscroll <= p->vrows - vc->vc_rows)
2009 && ((!scroll_partial && (b - t == vc->vc_rows))
2010 || (scroll_partial
2011 && (b - t - count >
2012 3 * vc->vc_rows >> 2)))) {
2013 if (vc->vc_rows - b > 0)
2014 fbcon_redraw_move(vc, p, b, vc->vc_rows - b,
2015 b - count);
2016 ypan_down_redraw(vc, t, count);
2017 if (t > 0)
2018 fbcon_redraw_move(vc, p, count, t, 0);
2019 } else
2020 fbcon_redraw_move(vc, p, t, b - t - count, t + count);
2021 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2022 break;
2023
2024 case SCROLL_REDRAW:
2025 redraw_down:
2026 fbcon_redraw(vc, p, b - 1, b - t - count,
2027 -count * vc->vc_cols);
2028 fbcon_clear(vc, t, 0, count, vc->vc_cols);
2029 scr_memsetw((unsigned short *) (vc->vc_origin +
2030 vc->vc_size_row *
2031 t),
2032 vc->vc_video_erase_char,
2033 vc->vc_size_row * count);
2034 return 1;
2035 }
2036 }
2037 return 0;
2038}
2039
2040
2041static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx,
2042 int height, int width)
2043{
2044 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2045 struct display *p = &fb_display[vc->vc_num];
2046
2047 if (fbcon_is_inactive(vc, info))
2048 return;
2049
2050 if (!width || !height)
2051 return;
2052
2053 /* Split blits that cross physical y_wrap case.
2054 * Pathological case involves 4 blits, better to use recursive
2055 * code rather than unrolled case
2056 *
2057 * Recursive invocations don't need to erase the cursor over and
2058 * over again, so we use fbcon_bmove_rec()
2059 */
2060 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width,
2061 p->vrows - p->yscroll);
2062}
2063
2064static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,
2065 int dy, int dx, int height, int width, u_int y_break)
2066{
2067 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2068 struct fbcon_ops *ops = info->fbcon_par;
2069 u_int b;
2070
2071 if (sy < y_break && sy + height > y_break) {
2072 b = y_break - sy;
2073 if (dy < sy) { /* Avoid trashing self */
2074 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2075 y_break);
2076 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2077 height - b, width, y_break);
2078 } else {
2079 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2080 height - b, width, y_break);
2081 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2082 y_break);
2083 }
2084 return;
2085 }
2086
2087 if (dy < y_break && dy + height > y_break) {
2088 b = y_break - dy;
2089 if (dy < sy) { /* Avoid trashing self */
2090 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2091 y_break);
2092 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2093 height - b, width, y_break);
2094 } else {
2095 fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx,
2096 height - b, width, y_break);
2097 fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width,
2098 y_break);
2099 }
2100 return;
2101 }
2102 ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx,
2103 height, width);
2104}
2105
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002106static __inline__ void updatescrollmode(struct display *p,
2107 struct fb_info *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 struct vc_data *vc)
2109{
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002110 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 int fh = vc->vc_font.height;
2112 int cap = info->flags;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002113 u16 t = 0;
2114 int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep,
2115 info->fix.xpanstep);
2116 int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t);
2117 int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2118 int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual,
2119 info->var.xres_virtual);
2120 int good_pan = (cap & FBINFO_HWACCEL_YPAN) &&
2121 divides(ypan, vc->vc_font.height) && vyres > yres;
2122 int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) &&
2123 divides(ywrap, vc->vc_font.height) &&
Knut Petersen244ab722006-01-09 20:53:36 -08002124 divides(vc->vc_font.height, vyres) &&
2125 divides(vc->vc_font.height, yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 int reading_fast = cap & FBINFO_READS_FAST;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002127 int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) &&
2128 !(cap & FBINFO_HWACCEL_DISABLED);
2129 int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) &&
2130 !(cap & FBINFO_HWACCEL_DISABLED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002132 p->vrows = vyres/fh;
2133 if (yres > (fh * (vc->vc_rows + 1)))
2134 p->vrows -= (yres - (fh * vc->vc_rows)) / fh;
2135 if ((yres % fh) && (vyres % fh < yres % fh))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 p->vrows--;
2137
2138 if (good_wrap || good_pan) {
2139 if (reading_fast || fast_copyarea)
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002140 p->scrollmode = good_wrap ?
2141 SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 else
2143 p->scrollmode = good_wrap ? SCROLL_REDRAW :
2144 SCROLL_PAN_REDRAW;
2145 } else {
2146 if (reading_fast || (fast_copyarea && !fast_imageblit))
2147 p->scrollmode = SCROLL_MOVE;
2148 else
2149 p->scrollmode = SCROLL_REDRAW;
2150 }
2151}
2152
2153static int fbcon_resize(struct vc_data *vc, unsigned int width,
2154 unsigned int height)
2155{
2156 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002157 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct display *p = &fb_display[vc->vc_num];
2159 struct fb_var_screeninfo var = info->var;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002160 int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002162 virt_w = FBCON_SWAP(ops->rotate, width, height);
2163 virt_h = FBCON_SWAP(ops->rotate, height, width);
2164 virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width,
2165 vc->vc_font.height);
2166 virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height,
2167 vc->vc_font.width);
2168 var.xres = virt_w * virt_fw;
2169 var.yres = virt_h * virt_fh;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 x_diff = info->var.xres - var.xres;
2171 y_diff = info->var.yres - var.yres;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002172 if (x_diff < 0 || x_diff > virt_fw ||
2173 y_diff < 0 || y_diff > virt_fh) {
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08002174 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2177 mode = fb_find_best_mode(&var, &info->modelist);
2178 if (mode == NULL)
2179 return -EINVAL;
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002180 display_to_var(&var, p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 fb_videomode_to_var(&var, mode);
Antonino A. Daplas3084a892005-11-07 01:00:37 -08002182
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002183 if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
2186 DPRINTK("resize now %ix%i\n", var.xres, var.yres);
2187 if (CON_IS_VISIBLE(vc)) {
2188 var.activate = FB_ACTIVATE_NOW |
2189 FB_ACTIVATE_FORCE;
2190 fb_set_var(info, &var);
2191 }
2192 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002193 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 }
2195 updatescrollmode(p, info, vc);
2196 return 0;
2197}
2198
2199static int fbcon_switch(struct vc_data *vc)
2200{
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002201 struct fb_info *info, *old_info = NULL;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002202 struct fbcon_ops *ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 struct display *p = &fb_display[vc->vc_num];
2204 struct fb_var_screeninfo var;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002205 int i, prev_console, charcnt = 256;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
2207 info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002208 ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
2210 if (softback_top) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 if (softback_lines)
2212 fbcon_set_origin(vc);
2213 softback_top = softback_curr = softback_in = softback_buf;
2214 softback_lines = 0;
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002215 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 }
2217
2218 if (logo_shown >= 0) {
2219 struct vc_data *conp2 = vc_cons[logo_shown].d;
2220
2221 if (conp2->vc_top == logo_lines
2222 && conp2->vc_bottom == conp2->vc_rows)
2223 conp2->vc_top = 0;
2224 logo_shown = FBCON_LOGO_CANSHOW;
2225 }
2226
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002227 prev_console = ops->currcon;
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002228 if (prev_console != -1)
2229 old_info = registered_fb[con2fb_map[prev_console]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 /*
2231 * FIXME: If we have multiple fbdev's loaded, we need to
2232 * update all info->currcon. Perhaps, we can place this
2233 * in a centralized structure, but this might break some
2234 * drivers.
2235 *
2236 * info->currcon = vc->vc_num;
2237 */
2238 for (i = 0; i < FB_MAX; i++) {
2239 if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002240 struct fbcon_ops *o = registered_fb[i]->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002242 o->currcon = vc->vc_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 }
2244 }
2245 memset(&var, 0, sizeof(struct fb_var_screeninfo));
2246 display_to_var(&var, p);
2247 var.activate = FB_ACTIVATE_NOW;
2248
2249 /*
2250 * make sure we don't unnecessarily trip the memcmp()
2251 * in fb_set_var()
2252 */
2253 info->var.activate = var.activate;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002254 var.yoffset = info->var.yoffset;
2255 var.xoffset = info->var.xoffset;
2256 var.vmode = info->var.vmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 fb_set_var(info, &var);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002258 ops->var = info->var;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Knut Petersen39942fd2005-12-12 22:17:19 -08002260 if (old_info != NULL && (old_info != info ||
2261 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) {
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002262 if (info->fbops->fb_set_par)
2263 info->fbops->fb_set_par(info);
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002264
Antonino A. Daplas5428b042006-06-26 00:27:06 -07002265 if (old_info != info)
Antonino A. Daplasa39bc342006-01-09 20:53:44 -08002266 fbcon_del_cursor_timer(old_info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002269 if (fbcon_is_inactive(vc, info) ||
2270 ops->blank_state != FB_BLANK_UNBLANK)
2271 fbcon_del_cursor_timer(info);
2272 else
2273 fbcon_add_cursor_timer(info);
2274
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002275 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002276 ops->cursor_reset = 1;
2277
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002278 if (ops->rotate_font && ops->rotate_font(info, vc)) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002279 ops->rotate = FB_ROTATE_UR;
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002280 set_blitting_type(vc, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002283 vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;
Antonino A. Daplas56f0d642005-12-12 22:17:15 -08002285
2286 if (p->userfont)
2287 charcnt = FNTCHARCNT(vc->vc_font.data);
2288
2289 if (charcnt > 256)
2290 vc->vc_complement_mask <<= 1;
2291
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 updatescrollmode(p, info, vc);
2293
2294 switch (p->scrollmode) {
2295 case SCROLL_WRAP_MOVE:
2296 scrollback_phys_max = p->vrows - vc->vc_rows;
2297 break;
2298 case SCROLL_PAN_MOVE:
2299 case SCROLL_PAN_REDRAW:
2300 scrollback_phys_max = p->vrows - 2 * vc->vc_rows;
2301 if (scrollback_phys_max < 0)
2302 scrollback_phys_max = 0;
2303 break;
2304 default:
2305 scrollback_phys_max = 0;
2306 break;
2307 }
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 scrollback_max = 0;
2310 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002311
2312 if (!fbcon_is_inactive(vc, info)) {
2313 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2314 ops->update_start(info);
2315 }
2316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 fbcon_set_palette(vc, color_table);
2318 fbcon_clear_margins(vc, 0);
2319
2320 if (logo_shown == FBCON_LOGO_DRAW) {
2321
2322 logo_shown = fg_console;
2323 /* This is protected above by initmem_freed */
Antonino A. Daplas9c44e5f2005-11-08 21:39:10 -08002324 fb_show_logo(info, ops->rotate);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 update_region(vc,
2326 vc->vc_origin + vc->vc_size_row * vc->vc_top,
2327 vc->vc_size_row * (vc->vc_bottom -
2328 vc->vc_top) / 2);
2329 return 0;
2330 }
2331 return 1;
2332}
2333
2334static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info,
2335 int blank)
2336{
Richard Purdie994efac2007-02-09 09:46:45 +00002337 struct fb_event event;
2338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (blank) {
2340 unsigned short charmask = vc->vc_hi_font_mask ?
2341 0x1ff : 0xff;
2342 unsigned short oldc;
2343
2344 oldc = vc->vc_video_erase_char;
2345 vc->vc_video_erase_char &= charmask;
2346 fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols);
2347 vc->vc_video_erase_char = oldc;
2348 }
Richard Purdie994efac2007-02-09 09:46:45 +00002349
2350
2351 event.info = info;
2352 event.data = &blank;
2353 fb_notifier_call_chain(FB_EVENT_CONBLANK, &event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354}
2355
2356static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch)
2357{
2358 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2359 struct fbcon_ops *ops = info->fbcon_par;
2360
2361 if (mode_switch) {
2362 struct fb_var_screeninfo var = info->var;
2363
2364 ops->graphics = 1;
2365
2366 if (!blank) {
Antonino A. Daplas47434842005-12-12 22:17:16 -08002367 if (info->fbops->fb_save_state)
2368 info->fbops->fb_save_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
2370 fb_set_var(info, &var);
2371 ops->graphics = 0;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002372 ops->var = info->var;
Antonino A. Daplas47434842005-12-12 22:17:16 -08002373 } else if (info->fbops->fb_restore_state)
2374 info->fbops->fb_restore_state(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 }
2376
2377 if (!fbcon_is_inactive(vc, info)) {
2378 if (ops->blank_state != blank) {
2379 ops->blank_state = blank;
2380 fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW);
2381 ops->cursor_flash = (!blank);
2382
2383 if (fb_blank(info, blank))
2384 fbcon_generic_blank(vc, info, blank);
2385 }
2386
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002387 if (!blank)
2388 update_screen(vc);
2389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002391 if (fbcon_is_inactive(vc, info) ||
2392 ops->blank_state != FB_BLANK_UNBLANK)
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002393 fbcon_del_cursor_timer(info);
Antonino A. Daplas212f2632006-10-03 01:14:48 -07002394 else
2395 fbcon_add_cursor_timer(info);
Antonino A. Daplas88fb2c62005-09-09 13:10:00 -07002396
2397 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398}
2399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400static int fbcon_get_font(struct vc_data *vc, struct console_font *font)
2401{
2402 u8 *fontdata = vc->vc_font.data;
2403 u8 *data = font->data;
2404 int i, j;
2405
2406 font->width = vc->vc_font.width;
2407 font->height = vc->vc_font.height;
2408 font->charcount = vc->vc_hi_font_mask ? 512 : 256;
2409 if (!font->data)
2410 return 0;
2411
2412 if (font->width <= 8) {
2413 j = vc->vc_font.height;
2414 for (i = 0; i < font->charcount; i++) {
2415 memcpy(data, fontdata, j);
2416 memset(data + j, 0, 32 - j);
2417 data += 32;
2418 fontdata += j;
2419 }
2420 } else if (font->width <= 16) {
2421 j = vc->vc_font.height * 2;
2422 for (i = 0; i < font->charcount; i++) {
2423 memcpy(data, fontdata, j);
2424 memset(data + j, 0, 64 - j);
2425 data += 64;
2426 fontdata += j;
2427 }
2428 } else if (font->width <= 24) {
2429 for (i = 0; i < font->charcount; i++) {
2430 for (j = 0; j < vc->vc_font.height; j++) {
2431 *data++ = fontdata[0];
2432 *data++ = fontdata[1];
2433 *data++ = fontdata[2];
2434 fontdata += sizeof(u32);
2435 }
2436 memset(data, 0, 3 * (32 - j));
2437 data += 3 * (32 - j);
2438 }
2439 } else {
2440 j = vc->vc_font.height * 4;
2441 for (i = 0; i < font->charcount; i++) {
2442 memcpy(data, fontdata, j);
2443 memset(data + j, 0, 128 - j);
2444 data += 128;
2445 fontdata += j;
2446 }
2447 }
2448 return 0;
2449}
2450
2451static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
Jan Beulich2f4516d2005-09-13 01:25:44 -07002452 const u8 * data, int userfont)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453{
2454 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002455 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 struct display *p = &fb_display[vc->vc_num];
2457 int resize;
2458 int cnt;
2459 char *old_data = NULL;
2460
2461 if (CON_IS_VISIBLE(vc) && softback_lines)
2462 fbcon_set_origin(vc);
2463
2464 resize = (w != vc->vc_font.width) || (h != vc->vc_font.height);
2465 if (p->userfont)
2466 old_data = vc->vc_font.data;
2467 if (userfont)
2468 cnt = FNTCHARCNT(data);
2469 else
2470 cnt = 256;
Jan Beulich2f4516d2005-09-13 01:25:44 -07002471 vc->vc_font.data = (void *)(p->fontdata = data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 if ((p->userfont = userfont))
2473 REFCOUNT(data)++;
2474 vc->vc_font.width = w;
2475 vc->vc_font.height = h;
2476 if (vc->vc_hi_font_mask && cnt == 256) {
2477 vc->vc_hi_font_mask = 0;
2478 if (vc->vc_can_do_color) {
2479 vc->vc_complement_mask >>= 1;
2480 vc->vc_s_complement_mask >>= 1;
2481 }
2482
2483 /* ++Edmund: reorder the attribute bits */
2484 if (vc->vc_can_do_color) {
2485 unsigned short *cp =
2486 (unsigned short *) vc->vc_origin;
2487 int count = vc->vc_screenbuf_size / 2;
2488 unsigned short c;
2489 for (; count > 0; count--, cp++) {
2490 c = scr_readw(cp);
2491 scr_writew(((c & 0xfe00) >> 1) |
2492 (c & 0xff), cp);
2493 }
2494 c = vc->vc_video_erase_char;
2495 vc->vc_video_erase_char =
2496 ((c & 0xfe00) >> 1) | (c & 0xff);
2497 vc->vc_attr >>= 1;
2498 }
2499 } else if (!vc->vc_hi_font_mask && cnt == 512) {
2500 vc->vc_hi_font_mask = 0x100;
2501 if (vc->vc_can_do_color) {
2502 vc->vc_complement_mask <<= 1;
2503 vc->vc_s_complement_mask <<= 1;
2504 }
2505
2506 /* ++Edmund: reorder the attribute bits */
2507 {
2508 unsigned short *cp =
2509 (unsigned short *) vc->vc_origin;
2510 int count = vc->vc_screenbuf_size / 2;
2511 unsigned short c;
2512 for (; count > 0; count--, cp++) {
2513 unsigned short newc;
2514 c = scr_readw(cp);
2515 if (vc->vc_can_do_color)
2516 newc =
2517 ((c & 0xff00) << 1) | (c &
2518 0xff);
2519 else
2520 newc = c & ~0x100;
2521 scr_writew(newc, cp);
2522 }
2523 c = vc->vc_video_erase_char;
2524 if (vc->vc_can_do_color) {
2525 vc->vc_video_erase_char =
2526 ((c & 0xff00) << 1) | (c & 0xff);
2527 vc->vc_attr <<= 1;
2528 } else
2529 vc->vc_video_erase_char = c & ~0x100;
2530 }
2531
2532 }
2533
2534 if (resize) {
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002535 int cols, rows;
2536
2537 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2538 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2539 cols /= w;
2540 rows /= h;
2541 vc_resize(vc, cols, rows);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002542 if (CON_IS_VISIBLE(vc) && softback_buf)
2543 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 } else if (CON_IS_VISIBLE(vc)
2545 && vc->vc_mode == KD_TEXT) {
2546 fbcon_clear_margins(vc, 0);
2547 update_screen(vc);
2548 }
2549
2550 if (old_data && (--REFCOUNT(old_data) == 0))
2551 kfree(old_data - FONT_EXTRA_WORDS * sizeof(int));
2552 return 0;
2553}
2554
2555static int fbcon_copy_font(struct vc_data *vc, int con)
2556{
2557 struct display *od = &fb_display[con];
2558 struct console_font *f = &vc->vc_font;
2559
2560 if (od->fontdata == f->data)
2561 return 0; /* already the same font... */
2562 return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont);
2563}
2564
2565/*
2566 * User asked to set font; we are guaranteed that
2567 * a) width and height are in range 1..32
2568 * b) charcount does not exceed 512
2569 * but lets not assume that, since someone might someday want to use larger
2570 * fonts. And charcount of 512 is small for unicode support.
2571 *
2572 * However, user space gives the font in 32 rows , regardless of
2573 * actual font height. So a new API is needed if support for larger fonts
2574 * is ever implemented.
2575 */
2576
2577static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2578{
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002579 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 unsigned charcount = font->charcount;
2581 int w = font->width;
2582 int h = font->height;
2583 int size;
2584 int i, csum;
2585 u8 *new_data, *data = font->data;
2586 int pitch = (font->width+7) >> 3;
2587
2588 /* Is there a reason why fbconsole couldn't handle any charcount >256?
2589 * If not this check should be changed to charcount < 256 */
2590 if (charcount != 256 && charcount != 512)
2591 return -EINVAL;
2592
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002593 /* Make sure drawing engine can handle the font */
2594 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2595 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2596 return -EINVAL;
2597
Antonino A. Daplas38b49822007-05-08 00:39:19 -07002598 /* Make sure driver can handle the font length */
2599 if (fbcon_invalid_charcount(info, charcount))
2600 return -EINVAL;
2601
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 size = h * pitch * charcount;
2603
2604 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
2605
2606 if (!new_data)
2607 return -ENOMEM;
2608
2609 new_data += FONT_EXTRA_WORDS * sizeof(int);
2610 FNTSIZE(new_data) = size;
2611 FNTCHARCNT(new_data) = charcount;
2612 REFCOUNT(new_data) = 0; /* usage counter */
2613 for (i=0; i< charcount; i++) {
2614 memcpy(new_data + i*h*pitch, data + i*32*pitch, h*pitch);
2615 }
2616
2617 /* Since linux has a nice crc32 function use it for counting font
2618 * checksums. */
2619 csum = crc32(0, new_data, size);
2620
2621 FNTSUM(new_data) = csum;
2622 /* Check if the same font is on some other console already */
Antonino A. Daplase614b182006-06-26 00:27:09 -07002623 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 struct vc_data *tmp = vc_cons[i].d;
2625
2626 if (fb_display[i].userfont &&
2627 fb_display[i].fontdata &&
2628 FNTSUM(fb_display[i].fontdata) == csum &&
2629 FNTSIZE(fb_display[i].fontdata) == size &&
2630 tmp->vc_font.width == w &&
2631 !memcmp(fb_display[i].fontdata, new_data, size)) {
2632 kfree(new_data - FONT_EXTRA_WORDS * sizeof(int));
Jan Beulich2f4516d2005-09-13 01:25:44 -07002633 new_data = (u8 *)fb_display[i].fontdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 break;
2635 }
2636 }
2637 return fbcon_do_set_font(vc, font->width, font->height, new_data, 1);
2638}
2639
2640static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name)
2641{
2642 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
Jan Beulich2f4516d2005-09-13 01:25:44 -07002643 const struct font_desc *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644
2645 if (!name)
Antonino A. Daplas2d2699d2007-05-08 00:39:11 -07002646 f = get_default_font(info->var.xres, info->var.yres,
2647 info->pixmap.blit_x, info->pixmap.blit_y);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 else if (!(f = find_font(name)))
2649 return -ENOENT;
2650
2651 font->width = f->width;
2652 font->height = f->height;
2653 return fbcon_do_set_font(vc, f->width, f->height, f->data, 0);
2654}
2655
2656static u16 palette_red[16];
2657static u16 palette_green[16];
2658static u16 palette_blue[16];
2659
2660static struct fb_cmap palette_cmap = {
2661 0, 16, palette_red, palette_green, palette_blue, NULL
2662};
2663
2664static int fbcon_set_palette(struct vc_data *vc, unsigned char *table)
2665{
2666 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2667 int i, j, k, depth;
2668 u8 val;
2669
2670 if (fbcon_is_inactive(vc, info))
2671 return -EINVAL;
2672
2673 if (!CON_IS_VISIBLE(vc))
2674 return 0;
2675
Antonino A. Daplasb8c90942005-09-09 13:04:37 -07002676 depth = fb_get_color_depth(&info->var, &info->fix);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 if (depth > 3) {
2678 for (i = j = 0; i < 16; i++) {
2679 k = table[i];
2680 val = vc->vc_palette[j++];
2681 palette_red[k] = (val << 8) | val;
2682 val = vc->vc_palette[j++];
2683 palette_green[k] = (val << 8) | val;
2684 val = vc->vc_palette[j++];
2685 palette_blue[k] = (val << 8) | val;
2686 }
2687 palette_cmap.len = 16;
2688 palette_cmap.start = 0;
2689 /*
2690 * If framebuffer is capable of less than 16 colors,
2691 * use default palette of fbcon.
2692 */
2693 } else
2694 fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap);
2695
2696 return fb_set_cmap(&palette_cmap, info);
2697}
2698
2699static u16 *fbcon_screen_pos(struct vc_data *vc, int offset)
2700{
2701 unsigned long p;
2702 int line;
2703
2704 if (vc->vc_num != fg_console || !softback_lines)
2705 return (u16 *) (vc->vc_origin + offset);
2706 line = offset / vc->vc_size_row;
2707 if (line >= softback_lines)
2708 return (u16 *) (vc->vc_origin + offset -
2709 softback_lines * vc->vc_size_row);
2710 p = softback_curr + offset;
2711 if (p >= softback_end)
2712 p += softback_buf - softback_end;
2713 return (u16 *) p;
2714}
2715
2716static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos,
2717 int *px, int *py)
2718{
2719 unsigned long ret;
2720 int x, y;
2721
2722 if (pos >= vc->vc_origin && pos < vc->vc_scr_end) {
2723 unsigned long offset = (pos - vc->vc_origin) / 2;
2724
2725 x = offset % vc->vc_cols;
2726 y = offset / vc->vc_cols;
2727 if (vc->vc_num == fg_console)
2728 y += softback_lines;
2729 ret = pos + (vc->vc_cols - x) * 2;
2730 } else if (vc->vc_num == fg_console && softback_lines) {
2731 unsigned long offset = pos - softback_curr;
2732
2733 if (pos < softback_curr)
2734 offset += softback_end - softback_buf;
2735 offset /= 2;
2736 x = offset % vc->vc_cols;
2737 y = offset / vc->vc_cols;
2738 ret = pos + (vc->vc_cols - x) * 2;
2739 if (ret == softback_end)
2740 ret = softback_buf;
2741 if (ret == softback_in)
2742 ret = vc->vc_origin;
2743 } else {
2744 /* Should not happen */
2745 x = y = 0;
2746 ret = vc->vc_origin;
2747 }
2748 if (px)
2749 *px = x;
2750 if (py)
2751 *py = y;
2752 return ret;
2753}
2754
2755/* As we might be inside of softback, we may work with non-contiguous buffer,
2756 that's why we have to use a separate routine. */
2757static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt)
2758{
2759 while (cnt--) {
2760 u16 a = scr_readw(p);
2761 if (!vc->vc_can_do_color)
2762 a ^= 0x0800;
2763 else if (vc->vc_hi_font_mask == 0x100)
2764 a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) |
2765 (((a) & 0x0e00) << 4);
2766 else
2767 a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) |
2768 (((a) & 0x0700) << 4);
2769 scr_writew(a, p++);
2770 if (p == (u16 *) softback_end)
2771 p = (u16 *) softback_buf;
2772 if (p == (u16 *) softback_in)
2773 p = (u16 *) vc->vc_origin;
2774 }
2775}
2776
2777static int fbcon_scrolldelta(struct vc_data *vc, int lines)
2778{
2779 struct fb_info *info = registered_fb[con2fb_map[fg_console]];
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002780 struct fbcon_ops *ops = info->fbcon_par;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 struct display *p = &fb_display[fg_console];
2782 int offset, limit, scrollback_old;
2783
2784 if (softback_top) {
2785 if (vc->vc_num != fg_console)
2786 return 0;
2787 if (vc->vc_mode != KD_TEXT || !lines)
2788 return 0;
2789 if (logo_shown >= 0) {
2790 struct vc_data *conp2 = vc_cons[logo_shown].d;
2791
2792 if (conp2->vc_top == logo_lines
2793 && conp2->vc_bottom == conp2->vc_rows)
2794 conp2->vc_top = 0;
2795 if (logo_shown == vc->vc_num) {
2796 unsigned long p, q;
2797 int i;
2798
2799 p = softback_in;
2800 q = vc->vc_origin +
2801 logo_lines * vc->vc_size_row;
2802 for (i = 0; i < logo_lines; i++) {
2803 if (p == softback_top)
2804 break;
2805 if (p == softback_buf)
2806 p = softback_end;
2807 p -= vc->vc_size_row;
2808 q -= vc->vc_size_row;
2809 scr_memcpyw((u16 *) q, (u16 *) p,
2810 vc->vc_size_row);
2811 }
David Hollister308af922006-05-30 21:25:36 -07002812 softback_in = softback_curr = p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 update_region(vc, vc->vc_origin,
2814 logo_lines * vc->vc_cols);
2815 }
2816 logo_shown = FBCON_LOGO_CANSHOW;
2817 }
2818 fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK);
2819 fbcon_redraw_softback(vc, p, lines);
2820 fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK);
2821 return 0;
2822 }
2823
2824 if (!scrollback_phys_max)
2825 return -ENOSYS;
2826
2827 scrollback_old = scrollback_current;
2828 scrollback_current -= lines;
2829 if (scrollback_current < 0)
2830 scrollback_current = 0;
2831 else if (scrollback_current > scrollback_max)
2832 scrollback_current = scrollback_max;
2833 if (scrollback_current == scrollback_old)
2834 return 0;
2835
2836 if (fbcon_is_inactive(vc, info))
2837 return 0;
2838
2839 fbcon_cursor(vc, CM_ERASE);
2840
2841 offset = p->yscroll - scrollback_current;
2842 limit = p->vrows;
2843 switch (p->scrollmode) {
2844 case SCROLL_WRAP_MOVE:
2845 info->var.vmode |= FB_VMODE_YWRAP;
2846 break;
2847 case SCROLL_PAN_MOVE:
2848 case SCROLL_PAN_REDRAW:
2849 limit -= vc->vc_rows;
2850 info->var.vmode &= ~FB_VMODE_YWRAP;
2851 break;
2852 }
2853 if (offset < 0)
2854 offset += limit;
2855 else if (offset >= limit)
2856 offset -= limit;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002857
2858 ops->var.xoffset = 0;
2859 ops->var.yoffset = offset * vc->vc_font.height;
2860 ops->update_start(info);
2861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 if (!scrollback_current)
2863 fbcon_cursor(vc, CM_DRAW);
2864 return 0;
2865}
2866
2867static int fbcon_set_origin(struct vc_data *vc)
2868{
2869 if (softback_lines)
2870 fbcon_scrolldelta(vc, softback_lines);
2871 return 0;
2872}
2873
2874static void fbcon_suspended(struct fb_info *info)
2875{
2876 struct vc_data *vc = NULL;
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 /* Clear cursor, restore saved data */
2884 fbcon_cursor(vc, CM_ERASE);
2885}
2886
2887static void fbcon_resumed(struct fb_info *info)
2888{
2889 struct vc_data *vc;
2890 struct fbcon_ops *ops = info->fbcon_par;
2891
2892 if (!ops || ops->currcon < 0)
2893 return;
2894 vc = vc_cons[ops->currcon].d;
2895
2896 update_screen(vc);
2897}
2898
2899static void fbcon_modechanged(struct fb_info *info)
2900{
2901 struct fbcon_ops *ops = info->fbcon_par;
2902 struct vc_data *vc;
2903 struct display *p;
2904 int rows, cols;
2905
2906 if (!ops || ops->currcon < 0)
2907 return;
2908 vc = vc_cons[ops->currcon].d;
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002909 if (vc->vc_mode != KD_TEXT ||
2910 registered_fb[con2fb_map[ops->currcon]] != info)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 return;
2912
2913 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002914 set_blitting_type(vc, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
2916 if (CON_IS_VISIBLE(vc)) {
2917 var_to_display(p, &info->var, info);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002918 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
2919 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
2920 cols /= vc->vc_font.width;
2921 rows /= vc->vc_font.height;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 vc_resize(vc, cols, rows);
2923 updatescrollmode(p, info, vc);
2924 scrollback_max = 0;
2925 scrollback_current = 0;
Antonino A. Daplas4e1567d2005-12-12 22:17:18 -08002926
2927 if (!fbcon_is_inactive(vc, info)) {
2928 ops->var.xoffset = ops->var.yoffset = p->yscroll = 0;
2929 ops->update_start(info);
2930 }
2931
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 fbcon_set_palette(vc, color_table);
2933 update_screen(vc);
Antonino A. Daplas4d9c5b62005-11-07 01:00:36 -08002934 if (softback_buf)
2935 fbcon_update_softback(vc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
2937}
2938
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002939static void fbcon_set_all_vcs(struct fb_info *info)
2940{
2941 struct fbcon_ops *ops = info->fbcon_par;
2942 struct vc_data *vc;
2943 struct display *p;
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002944 int i, rows, cols, fg = -1;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002945
2946 if (!ops || ops->currcon < 0)
2947 return;
2948
Antonino A. Daplase614b182006-06-26 00:27:09 -07002949 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002950 vc = vc_cons[i].d;
2951 if (!vc || vc->vc_mode != KD_TEXT ||
2952 registered_fb[con2fb_map[i]] != info)
2953 continue;
2954
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002955 if (CON_IS_VISIBLE(vc)) {
2956 fg = i;
2957 continue;
2958 }
2959
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002960 p = &fb_display[vc->vc_num];
Antonino A. Daplasb73deed2006-01-09 20:52:56 -08002961 set_blitting_type(vc, info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002962 var_to_display(p, &info->var, info);
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002963 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2964 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
Antonino A. Daplase4fc2762005-11-08 21:39:09 -08002965 cols /= vc->vc_font.width;
2966 rows /= vc->vc_font.height;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002967 vc_resize(vc, cols, rows);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002968 }
Antonino A. Daplas04a2fe52006-01-09 20:52:58 -08002969
Antonino A. Daplas95d67bb2007-05-08 00:38:40 -07002970 if (fg != -1)
2971 fbcon_modechanged(info);
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07002972}
2973
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974static int fbcon_mode_deleted(struct fb_info *info,
2975 struct fb_videomode *mode)
2976{
2977 struct fb_info *fb_info;
2978 struct display *p;
2979 int i, j, found = 0;
2980
2981 /* before deletion, ensure that mode is not in use */
2982 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2983 j = con2fb_map[i];
2984 if (j == -1)
2985 continue;
2986 fb_info = registered_fb[j];
2987 if (fb_info != info)
2988 continue;
2989 p = &fb_display[i];
2990 if (!p || !p->mode)
2991 continue;
2992 if (fb_mode_is_equal(p->mode, mode)) {
2993 found = 1;
2994 break;
2995 }
2996 }
2997 return found;
2998}
2999
Antonino A. Daplase614b182006-06-26 00:27:09 -07003000static int fbcon_fb_unregistered(int idx)
3001{
3002 int i;
3003
3004 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3005 if (con2fb_map[i] == idx)
3006 con2fb_map[i] = -1;
3007 }
3008
3009 if (idx == info_idx) {
3010 info_idx = -1;
3011
3012 for (i = 0; i < FB_MAX; i++) {
3013 if (registered_fb[i] != NULL) {
3014 info_idx = i;
3015 break;
3016 }
3017 }
3018 }
3019
3020 if (info_idx != -1) {
3021 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3022 if (con2fb_map[i] == -1)
3023 con2fb_map[i] = info_idx;
3024 }
3025 }
3026
3027 if (!num_registered_fb)
3028 unregister_con_driver(&fb_con);
3029
3030 return 0;
3031}
3032
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033static int fbcon_fb_registered(int idx)
3034{
3035 int ret = 0, i;
3036
3037 if (info_idx == -1) {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003038 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 if (con2fb_map_boot[i] == idx) {
3040 info_idx = idx;
3041 break;
3042 }
3043 }
Antonino A. Daplase614b182006-06-26 00:27:09 -07003044
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 if (info_idx != -1)
3046 ret = fbcon_takeover(1);
3047 } else {
Antonino A. Daplase614b182006-06-26 00:27:09 -07003048 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003049 if (con2fb_map_boot[i] == idx &&
3050 con2fb_map[i] == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 set_con2fb_map(i, idx, 0);
3052 }
3053 }
3054
3055 return ret;
3056}
3057
3058static void fbcon_fb_blanked(struct fb_info *info, int blank)
3059{
3060 struct fbcon_ops *ops = info->fbcon_par;
3061 struct vc_data *vc;
3062
3063 if (!ops || ops->currcon < 0)
3064 return;
3065
3066 vc = vc_cons[ops->currcon].d;
3067 if (vc->vc_mode != KD_TEXT ||
3068 registered_fb[con2fb_map[ops->currcon]] != info)
3069 return;
3070
3071 if (CON_IS_VISIBLE(vc)) {
3072 if (blank)
3073 do_blank_screen(0);
3074 else
3075 do_unblank_screen(0);
3076 }
3077 ops->blank_state = blank;
3078}
3079
3080static void fbcon_new_modelist(struct fb_info *info)
3081{
3082 int i;
3083 struct vc_data *vc;
3084 struct fb_var_screeninfo var;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08003085 const struct fb_videomode *mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086
Antonino A. Daplase614b182006-06-26 00:27:09 -07003087 for (i = first_fb_vc; i <= last_fb_vc; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 if (registered_fb[con2fb_map[i]] != info)
3089 continue;
3090 if (!fb_display[i].mode)
3091 continue;
3092 vc = vc_cons[i].d;
3093 display_to_var(&var, &fb_display[i]);
Michal Januszewski8fb65672005-11-07 01:00:47 -08003094 mode = fb_find_nearest_mode(fb_display[i].mode,
3095 &info->modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 fb_videomode_to_var(&var, mode);
3097
3098 if (vc)
3099 fbcon_set_disp(info, &var, vc);
3100 else
3101 fbcon_preset_disp(info, &var, i);
3102
3103 }
3104}
3105
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003106static void fbcon_get_requirement(struct fb_info *info,
3107 struct fb_blit_caps *caps)
3108{
3109 struct vc_data *vc;
3110 struct display *p;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003111
3112 if (caps->flags) {
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003113 int i, charcnt;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003114
3115 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3116 vc = vc_cons[i].d;
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003117 if (vc && vc->vc_mode == KD_TEXT &&
3118 info->node == con2fb_map[i]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003119 p = &fb_display[i];
3120 caps->x |= 1 << (vc->vc_font.width - 1);
3121 caps->y |= 1 << (vc->vc_font.height - 1);
3122 charcnt = (p->userfont) ?
3123 FNTCHARCNT(p->fontdata) : 256;
3124 if (caps->len < charcnt)
3125 caps->len = charcnt;
3126 }
3127 }
3128 } else {
3129 vc = vc_cons[fg_console].d;
3130
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003131 if (vc && vc->vc_mode == KD_TEXT &&
3132 info->node == con2fb_map[fg_console]) {
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003133 p = &fb_display[fg_console];
Antonino A. Daplas167f07f2007-05-08 00:39:54 -07003134 caps->x = 1 << (vc->vc_font.width - 1);
3135 caps->y = 1 << (vc->vc_font.height - 1);
3136 caps->len = (p->userfont) ?
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003137 FNTCHARCNT(p->fontdata) : 256;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003138 }
3139 }
3140}
3141
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142static int fbcon_event_notify(struct notifier_block *self,
3143 unsigned long action, void *data)
3144{
3145 struct fb_event *event = data;
3146 struct fb_info *info = event->info;
3147 struct fb_videomode *mode;
3148 struct fb_con2fbmap *con2fb;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003149 struct fb_blit_caps *caps;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 int ret = 0;
3151
Antonino A. Daplase614b182006-06-26 00:27:09 -07003152 /*
3153 * ignore all events except driver registration and deregistration
3154 * if fbcon is not active
3155 */
3156 if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED ||
3157 action == FB_EVENT_FB_UNREGISTERED))
3158 goto done;
3159
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 switch(action) {
3161 case FB_EVENT_SUSPEND:
3162 fbcon_suspended(info);
3163 break;
3164 case FB_EVENT_RESUME:
3165 fbcon_resumed(info);
3166 break;
3167 case FB_EVENT_MODE_CHANGE:
3168 fbcon_modechanged(info);
3169 break;
Antonino A. Daplas7726e9e2005-09-09 13:04:29 -07003170 case FB_EVENT_MODE_CHANGE_ALL:
3171 fbcon_set_all_vcs(info);
3172 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 case FB_EVENT_MODE_DELETE:
3174 mode = event->data;
3175 ret = fbcon_mode_deleted(info, mode);
3176 break;
3177 case FB_EVENT_FB_REGISTERED:
3178 ret = fbcon_fb_registered(info->node);
3179 break;
Antonino A. Daplase614b182006-06-26 00:27:09 -07003180 case FB_EVENT_FB_UNREGISTERED:
3181 ret = fbcon_fb_unregistered(info->node);
3182 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 case FB_EVENT_SET_CONSOLE_MAP:
3184 con2fb = event->data;
3185 ret = set_con2fb_map(con2fb->console - 1,
3186 con2fb->framebuffer, 1);
3187 break;
3188 case FB_EVENT_GET_CONSOLE_MAP:
3189 con2fb = event->data;
3190 con2fb->framebuffer = con2fb_map[con2fb->console - 1];
3191 break;
3192 case FB_EVENT_BLANK:
3193 fbcon_fb_blanked(info, *(int *)event->data);
3194 break;
3195 case FB_EVENT_NEW_MODELIST:
3196 fbcon_new_modelist(info);
3197 break;
Antonino A. Daplas38a3dc52007-05-08 00:39:37 -07003198 case FB_EVENT_GET_REQ:
3199 caps = event->data;
3200 fbcon_get_requirement(info, caps);
3201 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 }
3203
Antonino A. Daplase614b182006-06-26 00:27:09 -07003204done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 return ret;
3206}
3207
3208/*
3209 * The console `switch' structure for the frame buffer based console
3210 */
3211
3212static const struct consw fb_con = {
3213 .owner = THIS_MODULE,
3214 .con_startup = fbcon_startup,
3215 .con_init = fbcon_init,
3216 .con_deinit = fbcon_deinit,
3217 .con_clear = fbcon_clear,
3218 .con_putc = fbcon_putc,
3219 .con_putcs = fbcon_putcs,
3220 .con_cursor = fbcon_cursor,
3221 .con_scroll = fbcon_scroll,
3222 .con_bmove = fbcon_bmove,
3223 .con_switch = fbcon_switch,
3224 .con_blank = fbcon_blank,
3225 .con_font_set = fbcon_set_font,
3226 .con_font_get = fbcon_get_font,
3227 .con_font_default = fbcon_set_def_font,
3228 .con_font_copy = fbcon_copy_font,
3229 .con_set_palette = fbcon_set_palette,
3230 .con_scrolldelta = fbcon_scrolldelta,
3231 .con_set_origin = fbcon_set_origin,
3232 .con_invert_region = fbcon_invert_region,
3233 .con_screen_pos = fbcon_screen_pos,
3234 .con_getxy = fbcon_getxy,
3235 .con_resize = fbcon_resize,
3236};
3237
3238static struct notifier_block fbcon_event_notifier = {
3239 .notifier_call = fbcon_event_notify,
3240};
3241
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003242static ssize_t store_rotate(struct class_device *class_device,
3243 const char *buf, size_t count)
3244{
3245 struct fb_info *info;
3246 int rotate, idx;
3247 char **last = NULL;
3248
Antonino A. Daplase614b182006-06-26 00:27:09 -07003249 if (fbcon_has_exited)
3250 return count;
3251
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003252 acquire_console_sem();
3253 idx = con2fb_map[fg_console];
3254
3255 if (idx == -1 || registered_fb[idx] == NULL)
3256 goto err;
3257
3258 info = registered_fb[idx];
3259 rotate = simple_strtoul(buf, last, 0);
3260 fbcon_rotate(info, rotate);
3261err:
3262 release_console_sem();
3263 return count;
3264}
3265
3266static ssize_t store_rotate_all(struct class_device *class_device,
3267 const char *buf, size_t count)
3268{
3269 struct fb_info *info;
3270 int rotate, idx;
3271 char **last = NULL;
3272
Antonino A. Daplase614b182006-06-26 00:27:09 -07003273 if (fbcon_has_exited)
3274 return count;
3275
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003276 acquire_console_sem();
3277 idx = con2fb_map[fg_console];
3278
3279 if (idx == -1 || registered_fb[idx] == NULL)
3280 goto err;
3281
3282 info = registered_fb[idx];
3283 rotate = simple_strtoul(buf, last, 0);
3284 fbcon_rotate_all(info, rotate);
3285err:
3286 release_console_sem();
3287 return count;
3288}
3289
3290static ssize_t show_rotate(struct class_device *class_device, char *buf)
3291{
3292 struct fb_info *info;
3293 int rotate = 0, idx;
3294
Antonino A. Daplase614b182006-06-26 00:27:09 -07003295 if (fbcon_has_exited)
3296 return 0;
3297
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003298 acquire_console_sem();
3299 idx = con2fb_map[fg_console];
3300
3301 if (idx == -1 || registered_fb[idx] == NULL)
3302 goto err;
3303
3304 info = registered_fb[idx];
3305 rotate = fbcon_get_rotate(info);
3306err:
3307 release_console_sem();
3308 return snprintf(buf, PAGE_SIZE, "%d\n", rotate);
3309}
3310
3311static struct class_device_attribute class_device_attrs[] = {
3312 __ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate),
3313 __ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all),
3314};
3315
3316static int fbcon_init_class_device(void)
3317{
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003318 int i, error = 0;
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003319
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003320 fbcon_has_sysfs = 1;
3321
3322 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
3323 error = class_device_create_file(fbcon_class_device,
3324 &class_device_attrs[i]);
3325
3326 if (error)
3327 break;
3328 }
3329
3330 if (error) {
3331 while (--i >= 0)
3332 class_device_remove_file(fbcon_class_device,
3333 &class_device_attrs[i]);
3334
3335 fbcon_has_sysfs = 0;
3336 }
3337
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003338 return 0;
3339}
3340
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003341static void fbcon_start(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 if (num_registered_fb) {
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003344 int i;
3345
3346 acquire_console_sem();
3347
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 for (i = 0; i < FB_MAX; i++) {
3349 if (registered_fb[i] != NULL) {
3350 info_idx = i;
3351 break;
3352 }
3353 }
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003354
3355 release_console_sem();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 fbcon_takeover(0);
3357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358}
3359
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003360static void fbcon_exit(void)
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003361{
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003362 struct fb_info *info;
3363 int i, j, mapped;
3364
Antonino A. Daplase614b182006-06-26 00:27:09 -07003365 if (fbcon_has_exited)
3366 return;
3367
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003368#ifdef CONFIG_ATARI
Al Viro956295d2006-09-23 01:27:30 +01003369 free_irq(IRQ_AUTO_4, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003370#endif
3371#ifdef CONFIG_MAC
3372 if (MACH_IS_MAC && vbl_detected)
Al Viro956295d2006-09-23 01:27:30 +01003373 free_irq(IRQ_MAC_VBL, fb_vbl_handler);
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003374#endif
3375
3376 kfree((void *)softback_buf);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003377 softback_buf = 0UL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003378
3379 for (i = 0; i < FB_MAX; i++) {
3380 mapped = 0;
3381 info = registered_fb[i];
3382
3383 if (info == NULL)
3384 continue;
3385
Antonino A. Daplase614b182006-06-26 00:27:09 -07003386 for (j = first_fb_vc; j <= last_fb_vc; j++) {
3387 if (con2fb_map[j] == i)
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003388 mapped = 1;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003389 }
3390
3391 if (mapped) {
3392 if (info->fbops->fb_release)
3393 info->fbops->fb_release(info, 0);
3394 module_put(info->fbops->owner);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003395
3396 if (info->fbcon_par) {
Dave Jonese299dd42006-10-03 01:14:47 -07003397 struct fbcon_ops *ops = info->fbcon_par;
3398
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003399 fbcon_del_cursor_timer(info);
Dave Jonese299dd42006-10-03 01:14:47 -07003400 kfree(ops->cursor_src);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003401 kfree(info->fbcon_par);
3402 info->fbcon_par = NULL;
3403 }
3404
3405 if (info->queue.func == fb_flashcursor)
3406 info->queue.func = NULL;
Antonino A. Daplase55186f2006-06-26 00:27:05 -07003407 }
3408 }
3409
Antonino A. Daplase614b182006-06-26 00:27:09 -07003410 fbcon_has_exited = 1;
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003411}
3412
3413static int __init fb_console_init(void)
3414{
3415 int i;
3416
3417 acquire_console_sem();
3418 fb_register_client(&fbcon_event_notifier);
3419 fbcon_class_device =
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003420 class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon");
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003421
3422 if (IS_ERR(fbcon_class_device)) {
3423 printk(KERN_WARNING "Unable to create class_device "
3424 "for fbcon; errno = %ld\n",
3425 PTR_ERR(fbcon_class_device));
3426 fbcon_class_device = NULL;
3427 } else
3428 fbcon_init_class_device();
3429
3430 for (i = 0; i < MAX_NR_CONSOLES; i++)
3431 con2fb_map[i] = -1;
3432
3433 release_console_sem();
3434 fbcon_start();
3435 return 0;
3436}
3437
3438module_init(fb_console_init);
3439
3440#ifdef MODULE
3441
Antonino A. Daplase614b182006-06-26 00:27:09 -07003442static void __exit fbcon_deinit_class_device(void)
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003443{
3444 int i;
3445
Antonino A. Daplas0a727de2006-10-03 01:14:50 -07003446 if (fbcon_has_sysfs) {
3447 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++)
3448 class_device_remove_file(fbcon_class_device,
3449 &class_device_attrs[i]);
3450
3451 fbcon_has_sysfs = 0;
3452 }
Antonino A. Daplas9a179172006-06-26 00:27:05 -07003453}
3454
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455static void __exit fb_console_exit(void)
3456{
3457 acquire_console_sem();
3458 fb_unregister_client(&fbcon_event_notifier);
Antonino A. Daplas5428b042006-06-26 00:27:06 -07003459 fbcon_deinit_class_device();
Antonino A. Daplas5bd42532006-06-26 00:27:13 -07003460 class_device_destroy(fb_class, MKDEV(0, 0));
Antonino A. Daplase614b182006-06-26 00:27:09 -07003461 fbcon_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 release_console_sem();
Antonino A. Daplase614b182006-06-26 00:27:09 -07003463 unregister_con_driver(&fb_con);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464}
3465
3466module_exit(fb_console_exit);
3467
3468#endif
3469
3470MODULE_LICENSE("GPL");