| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <linux/module.h> | 
 | 62 | #include <linux/types.h> | 
 | 63 | #include <linux/sched.h> | 
 | 64 | #include <linux/fs.h> | 
 | 65 | #include <linux/kernel.h> | 
 | 66 | #include <linux/delay.h>	/* MSch: for IRQ probe */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <linux/console.h> | 
 | 68 | #include <linux/string.h> | 
 | 69 | #include <linux/kd.h> | 
 | 70 | #include <linux/slab.h> | 
 | 71 | #include <linux/fb.h> | 
 | 72 | #include <linux/vt_kern.h> | 
 | 73 | #include <linux/selection.h> | 
 | 74 | #include <linux/font.h> | 
 | 75 | #include <linux/smp.h> | 
 | 76 | #include <linux/init.h> | 
 | 77 | #include <linux/interrupt.h> | 
 | 78 | #include <linux/crc32.h> /* For counting font checksums */ | 
 | 79 | #include <asm/irq.h> | 
 | 80 | #include <asm/system.h> | 
 | 81 | #include <asm/uaccess.h> | 
 | 82 | #ifdef CONFIG_ATARI | 
 | 83 | #include <asm/atariints.h> | 
 | 84 | #endif | 
 | 85 | #ifdef CONFIG_MAC | 
 | 86 | #include <asm/macints.h> | 
 | 87 | #endif | 
 | 88 | #if defined(__mc68000__) || defined(CONFIG_APUS) | 
 | 89 | #include <asm/machdep.h> | 
 | 90 | #include <asm/setup.h> | 
 | 91 | #endif | 
 | 92 |  | 
 | 93 | #include "fbcon.h" | 
 | 94 |  | 
 | 95 | #ifdef FBCONDEBUG | 
 | 96 | #  define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args) | 
 | 97 | #else | 
 | 98 | #  define DPRINTK(fmt, args...) | 
 | 99 | #endif | 
 | 100 |  | 
 | 101 | enum { | 
 | 102 | 	FBCON_LOGO_CANSHOW	= -1,	/* the logo can be shown */ | 
 | 103 | 	FBCON_LOGO_DRAW		= -2,	/* draw the logo to a console */ | 
 | 104 | 	FBCON_LOGO_DONTSHOW	= -3	/* do not show the logo */ | 
 | 105 | }; | 
 | 106 |  | 
| Antonino A. Daplas | ab76720 | 2005-11-13 16:06:32 -0800 | [diff] [blame] | 107 | static struct display fb_display[MAX_NR_CONSOLES]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 108 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static signed char con2fb_map[MAX_NR_CONSOLES]; | 
 | 110 | static signed char con2fb_map_boot[MAX_NR_CONSOLES]; | 
 | 111 | static int logo_height; | 
 | 112 | static int logo_lines; | 
 | 113 | /* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO | 
 | 114 |    enums.  */ | 
 | 115 | static int logo_shown = FBCON_LOGO_CANSHOW; | 
 | 116 | /* Software scrollback */ | 
 | 117 | static int fbcon_softback_size = 32768; | 
 | 118 | static unsigned long softback_buf, softback_curr; | 
 | 119 | static unsigned long softback_in; | 
 | 120 | static unsigned long softback_top, softback_end; | 
 | 121 | static int softback_lines; | 
 | 122 | /* console mappings */ | 
 | 123 | static int first_fb_vc; | 
 | 124 | static int last_fb_vc = MAX_NR_CONSOLES - 1; | 
 | 125 | static int fbcon_is_default = 1;  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 126 | static int fbcon_has_exited; | 
 | 127 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | /* font data */ | 
 | 129 | static char fontname[40]; | 
 | 130 |  | 
 | 131 | /* current fb_info */ | 
 | 132 | static int info_idx = -1; | 
 | 133 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 134 | /* console rotation */ | 
 | 135 | static int rotate; | 
| Antonino A. Daplas | 0a727de | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 136 | static int fbcon_has_sysfs; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 137 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static const struct consw fb_con; | 
 | 139 |  | 
 | 140 | #define CM_SOFTBACK	(8) | 
 | 141 |  | 
 | 142 | #define advance_row(p, delta) (unsigned short *)((unsigned long)(p) + (delta) * vc->vc_size_row) | 
 | 143 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static int fbcon_set_origin(struct vc_data *); | 
 | 145 |  | 
 | 146 | #define CURSOR_DRAW_DELAY		(1) | 
 | 147 |  | 
 | 148 | /* # VBL ints between cursor state changes */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | #define ATARI_CURSOR_BLINK_RATE		(42) | 
 | 150 | #define MAC_CURSOR_BLINK_RATE		(32) | 
 | 151 | #define DEFAULT_CURSOR_BLINK_RATE	(20) | 
 | 152 |  | 
 | 153 | static int vbl_cursor_cnt; | 
 | 154 |  | 
 | 155 | #define divides(a, b)	((!(a) || (b)%(a)) ? 0 : 1) | 
 | 156 |  | 
 | 157 | /* | 
 | 158 |  *  Interface used by the world | 
 | 159 |  */ | 
 | 160 |  | 
 | 161 | static const char *fbcon_startup(void); | 
 | 162 | static void fbcon_init(struct vc_data *vc, int init); | 
 | 163 | static void fbcon_deinit(struct vc_data *vc); | 
 | 164 | static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, | 
 | 165 | 			int width); | 
 | 166 | static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos); | 
 | 167 | static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, | 
 | 168 | 			int count, int ypos, int xpos); | 
 | 169 | static void fbcon_clear_margins(struct vc_data *vc, int bottom_only); | 
 | 170 | static void fbcon_cursor(struct vc_data *vc, int mode); | 
 | 171 | static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | 
 | 172 | 			int count); | 
 | 173 | static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, | 
 | 174 | 			int height, int width); | 
 | 175 | static int fbcon_switch(struct vc_data *vc); | 
 | 176 | static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch); | 
 | 177 | static int fbcon_set_palette(struct vc_data *vc, unsigned char *table); | 
 | 178 | static int fbcon_scrolldelta(struct vc_data *vc, int lines); | 
 | 179 |  | 
 | 180 | /* | 
 | 181 |  *  Internal routines | 
 | 182 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | static __inline__ void ywrap_up(struct vc_data *vc, int count); | 
 | 184 | static __inline__ void ywrap_down(struct vc_data *vc, int count); | 
 | 185 | static __inline__ void ypan_up(struct vc_data *vc, int count); | 
 | 186 | static __inline__ void ypan_down(struct vc_data *vc, int count); | 
 | 187 | static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx, | 
 | 188 | 			    int dy, int dx, int height, int width, u_int y_break); | 
 | 189 | static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var, | 
 | 190 | 			   struct vc_data *vc); | 
 | 191 | static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var, | 
 | 192 | 			      int unit); | 
 | 193 | static void fbcon_redraw_move(struct vc_data *vc, struct display *p, | 
 | 194 | 			      int line, int count, int dy); | 
| Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 195 | static void fbcon_modechanged(struct fb_info *info); | 
 | 196 | static void fbcon_set_all_vcs(struct fb_info *info); | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 197 | static void fbcon_start(void); | 
 | 198 | static void fbcon_exit(void); | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 199 | static struct class_device *fbcon_class_device; | 
 | 200 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | #ifdef CONFIG_MAC | 
 | 202 | /* | 
 | 203 |  * On the Macintoy, there may or may not be a working VBL int. We need to probe | 
 | 204 |  */ | 
 | 205 | static int vbl_detected; | 
 | 206 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 207 | static irqreturn_t fb_vbl_detect(int irq, void *dummy) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | { | 
 | 209 | 	vbl_detected++; | 
 | 210 | 	return IRQ_HANDLED; | 
 | 211 | } | 
 | 212 | #endif | 
 | 213 |  | 
| Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 214 | #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 215 | static inline void fbcon_set_rotation(struct fb_info *info) | 
| Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 216 | { | 
 | 217 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 218 |  | 
 | 219 | 	if (!(info->flags & FBINFO_MISC_TILEBLITTING) && | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 220 | 	    ops->p->con_rotate < 4) | 
 | 221 | 		ops->rotate = ops->p->con_rotate; | 
| Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 222 | 	else | 
 | 223 | 		ops->rotate = 0; | 
 | 224 | } | 
| Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 225 |  | 
 | 226 | static void fbcon_rotate(struct fb_info *info, u32 rotate) | 
 | 227 | { | 
 | 228 | 	struct fbcon_ops *ops= info->fbcon_par; | 
 | 229 | 	struct fb_info *fb_info; | 
 | 230 |  | 
 | 231 | 	if (!ops || ops->currcon == -1) | 
 | 232 | 		return; | 
 | 233 |  | 
 | 234 | 	fb_info = registered_fb[con2fb_map[ops->currcon]]; | 
 | 235 |  | 
 | 236 | 	if (info == fb_info) { | 
 | 237 | 		struct display *p = &fb_display[ops->currcon]; | 
 | 238 |  | 
 | 239 | 		if (rotate < 4) | 
 | 240 | 			p->con_rotate = rotate; | 
 | 241 | 		else | 
 | 242 | 			p->con_rotate = 0; | 
 | 243 |  | 
 | 244 | 		fbcon_modechanged(info); | 
 | 245 | 	} | 
 | 246 | } | 
 | 247 |  | 
 | 248 | static void fbcon_rotate_all(struct fb_info *info, u32 rotate) | 
 | 249 | { | 
 | 250 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 251 | 	struct vc_data *vc; | 
 | 252 | 	struct display *p; | 
 | 253 | 	int i; | 
 | 254 |  | 
 | 255 | 	if (!ops || ops->currcon < 0 || rotate > 3) | 
 | 256 | 		return; | 
 | 257 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 258 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 259 | 		vc = vc_cons[i].d; | 
 | 260 | 		if (!vc || vc->vc_mode != KD_TEXT || | 
 | 261 | 		    registered_fb[con2fb_map[i]] != info) | 
 | 262 | 			continue; | 
 | 263 |  | 
 | 264 | 		p = &fb_display[vc->vc_num]; | 
 | 265 | 		p->con_rotate = rotate; | 
 | 266 | 	} | 
 | 267 |  | 
 | 268 | 	fbcon_set_all_vcs(info); | 
 | 269 | } | 
| Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 270 | #else | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 271 | static inline void fbcon_set_rotation(struct fb_info *info) | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 272 | { | 
 | 273 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 274 |  | 
 | 275 | 	ops->rotate = FB_ROTATE_UR; | 
 | 276 | } | 
| Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 277 |  | 
 | 278 | static void fbcon_rotate(struct fb_info *info, u32 rotate) | 
 | 279 | { | 
 | 280 | 	return; | 
 | 281 | } | 
 | 282 |  | 
 | 283 | static void fbcon_rotate_all(struct fb_info *info, u32 rotate) | 
 | 284 | { | 
 | 285 | 	return; | 
 | 286 | } | 
| Antonino A. Daplas | dbcbfe1 | 2005-11-08 21:39:12 -0800 | [diff] [blame] | 287 | #endif /* CONFIG_FRAMEBUFFER_CONSOLE_ROTATION */ | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 288 |  | 
| Antonino A. Daplas | a812c94 | 2005-11-08 21:39:15 -0800 | [diff] [blame] | 289 | static int fbcon_get_rotate(struct fb_info *info) | 
 | 290 | { | 
 | 291 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 292 |  | 
 | 293 | 	return (ops) ? ops->rotate : 0; | 
 | 294 | } | 
 | 295 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | static inline int fbcon_is_inactive(struct vc_data *vc, struct fb_info *info) | 
 | 297 | { | 
 | 298 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 299 |  | 
 | 300 | 	return (info->state != FBINFO_STATE_RUNNING || | 
 | 301 | 		vc->vc_mode != KD_TEXT || ops->graphics); | 
 | 302 | } | 
 | 303 |  | 
 | 304 | static inline int get_color(struct vc_data *vc, struct fb_info *info, | 
 | 305 | 	      u16 c, int is_fg) | 
 | 306 | { | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 307 | 	int depth = fb_get_color_depth(&info->var, &info->fix); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | 	int color = 0; | 
 | 309 |  | 
 | 310 | 	if (console_blanked) { | 
 | 311 | 		unsigned short charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff; | 
 | 312 |  | 
 | 313 | 		c = vc->vc_video_erase_char & charmask; | 
 | 314 | 	} | 
 | 315 |  | 
 | 316 | 	if (depth != 1) | 
 | 317 | 		color = (is_fg) ? attr_fgcol((vc->vc_hi_font_mask) ? 9 : 8, c) | 
 | 318 | 			: attr_bgcol((vc->vc_hi_font_mask) ? 13 : 12, c); | 
 | 319 |  | 
 | 320 | 	switch (depth) { | 
 | 321 | 	case 1: | 
 | 322 | 	{ | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 323 | 		int col = ~(0xfff << (max(info->var.green.length, | 
 | 324 | 					  max(info->var.red.length, | 
 | 325 | 					      info->var.blue.length)))) & 0xff; | 
 | 326 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | 		/* 0 or 1 */ | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 328 | 		int fg = (info->fix.visual != FB_VISUAL_MONO01) ? col : 0; | 
 | 329 | 		int bg = (info->fix.visual != FB_VISUAL_MONO01) ? 0 : col; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 |  | 
 | 331 | 		if (console_blanked) | 
 | 332 | 			fg = bg; | 
 | 333 |  | 
 | 334 | 		color = (is_fg) ? fg : bg; | 
 | 335 | 		break; | 
 | 336 | 	} | 
 | 337 | 	case 2: | 
 | 338 | 		/* | 
 | 339 | 		 * Scale down 16-colors to 4 colors. Default 4-color palette | 
| Antonino A. Daplas | 2cc38ed | 2005-09-09 13:04:38 -0700 | [diff] [blame] | 340 | 		 * is grayscale. However, simply dividing the values by 4 | 
 | 341 | 		 * will not work, as colors 1, 2 and 3 will be scaled-down | 
 | 342 | 		 * to zero rendering them invisible.  So empirically convert | 
 | 343 | 		 * colors to a sane 4-level grayscale. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | 		 */ | 
| Antonino A. Daplas | 2cc38ed | 2005-09-09 13:04:38 -0700 | [diff] [blame] | 345 | 		switch (color) { | 
 | 346 | 		case 0: | 
 | 347 | 			color = 0; /* black */ | 
 | 348 | 			break; | 
 | 349 | 		case 1 ... 6: | 
 | 350 | 			color = 2; /* white */ | 
 | 351 | 			break; | 
 | 352 | 		case 7 ... 8: | 
 | 353 | 			color = 1; /* gray */ | 
 | 354 | 			break; | 
 | 355 | 		default: | 
 | 356 | 			color = 3; /* intense white */ | 
 | 357 | 			break; | 
 | 358 | 		} | 
 | 359 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | 	case 3: | 
 | 361 | 		/* | 
 | 362 | 		 * Last 8 entries of default 16-color palette is a more intense | 
 | 363 | 		 * version of the first 8 (i.e., same chrominance, different | 
 | 364 | 		 * luminance). | 
 | 365 | 		 */ | 
 | 366 | 		color &= 7; | 
 | 367 | 		break; | 
 | 368 | 	} | 
 | 369 |  | 
 | 370 |  | 
 | 371 | 	return color; | 
 | 372 | } | 
 | 373 |  | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 374 | static void fbcon_update_softback(struct vc_data *vc) | 
 | 375 | { | 
 | 376 | 	int l = fbcon_softback_size / vc->vc_size_row; | 
 | 377 |  | 
 | 378 | 	if (l > 5) | 
 | 379 | 		softback_end = softback_buf + l * vc->vc_size_row; | 
 | 380 | 	else | 
 | 381 | 		/* Smaller scrollback makes no sense, and 0 would screw | 
 | 382 | 		   the operation totally */ | 
 | 383 | 		softback_top = 0; | 
 | 384 | } | 
 | 385 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | static void fb_flashcursor(void *private) | 
 | 387 | { | 
 | 388 | 	struct fb_info *info = private; | 
 | 389 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 390 | 	struct display *p; | 
 | 391 | 	struct vc_data *vc = NULL; | 
 | 392 | 	int c; | 
 | 393 | 	int mode; | 
 | 394 |  | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 395 | 	acquire_console_sem(); | 
 | 396 | 	if (ops && ops->currcon != -1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | 		vc = vc_cons[ops->currcon].d; | 
 | 398 |  | 
 | 399 | 	if (!vc || !CON_IS_VISIBLE(vc) || | 
| Michal Januszewski | dbd4f12 | 2005-07-27 11:46:06 -0700 | [diff] [blame] | 400 |  	    registered_fb[con2fb_map[vc->vc_num]] != info || | 
| Antonino A. Daplas | 212f263 | 2006-10-03 01:14:48 -0700 | [diff] [blame] | 401 | 	    vc->vc_deccm != 1) { | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 402 | 		release_console_sem(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 		return; | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 404 | 	} | 
 | 405 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | 	p = &fb_display[vc->vc_num]; | 
 | 407 | 	c = scr_readw((u16 *) vc->vc_pos); | 
 | 408 | 	mode = (!ops->cursor_flash || ops->cursor_state.enable) ? | 
 | 409 | 		CM_ERASE : CM_DRAW; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 410 | 	ops->cursor(vc, info, mode, softback_lines, get_color(vc, info, c, 1), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | 		    get_color(vc, info, c, 0)); | 
 | 412 | 	release_console_sem(); | 
 | 413 | } | 
 | 414 |  | 
| Russell King | 41359dc | 2005-06-30 16:30:07 +0100 | [diff] [blame] | 415 | #if defined(CONFIG_ATARI) || defined(CONFIG_MAC) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | static int cursor_blink_rate; | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 417 | static irqreturn_t fb_vbl_handler(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { | 
 | 419 | 	struct fb_info *info = dev_id; | 
 | 420 |  | 
 | 421 | 	if (vbl_cursor_cnt && --vbl_cursor_cnt == 0) { | 
 | 422 | 		schedule_work(&info->queue);	 | 
 | 423 | 		vbl_cursor_cnt = cursor_blink_rate;  | 
 | 424 | 	} | 
 | 425 | 	return IRQ_HANDLED; | 
 | 426 | } | 
 | 427 | #endif | 
 | 428 | 	 | 
 | 429 | static void cursor_timer_handler(unsigned long dev_addr) | 
 | 430 | { | 
 | 431 | 	struct fb_info *info = (struct fb_info *) dev_addr; | 
 | 432 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 433 |  | 
 | 434 | 	schedule_work(&info->queue); | 
 | 435 | 	mod_timer(&ops->cursor_timer, jiffies + HZ/5); | 
 | 436 | } | 
 | 437 |  | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 438 | static void fbcon_add_cursor_timer(struct fb_info *info) | 
 | 439 | { | 
 | 440 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 441 |  | 
 | 442 | 	if ((!info->queue.func || info->queue.func == fb_flashcursor) && | 
 | 443 | 	    !(ops->flags & FBCON_FLAGS_CURSOR_TIMER)) { | 
 | 444 | 		if (!info->queue.func) | 
 | 445 | 			INIT_WORK(&info->queue, fb_flashcursor, info); | 
 | 446 |  | 
 | 447 | 		init_timer(&ops->cursor_timer); | 
 | 448 | 		ops->cursor_timer.function = cursor_timer_handler; | 
 | 449 | 		ops->cursor_timer.expires = jiffies + HZ / 5; | 
 | 450 | 		ops->cursor_timer.data = (unsigned long ) info; | 
 | 451 | 		add_timer(&ops->cursor_timer); | 
 | 452 | 		ops->flags |= FBCON_FLAGS_CURSOR_TIMER; | 
 | 453 | 	} | 
 | 454 | } | 
 | 455 |  | 
 | 456 | static void fbcon_del_cursor_timer(struct fb_info *info) | 
 | 457 | { | 
 | 458 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 459 |  | 
 | 460 | 	if (info->queue.func == fb_flashcursor && | 
 | 461 | 	    ops->flags & FBCON_FLAGS_CURSOR_TIMER) { | 
 | 462 | 		del_timer_sync(&ops->cursor_timer); | 
 | 463 | 		ops->flags &= ~FBCON_FLAGS_CURSOR_TIMER; | 
 | 464 | 	} | 
 | 465 | } | 
 | 466 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | #ifndef MODULE | 
 | 468 | static int __init fb_console_setup(char *this_opt) | 
 | 469 | { | 
 | 470 | 	char *options; | 
 | 471 | 	int i, j; | 
 | 472 |  | 
 | 473 | 	if (!this_opt || !*this_opt) | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 474 | 		return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 |  | 
 | 476 | 	while ((options = strsep(&this_opt, ",")) != NULL) { | 
 | 477 | 		if (!strncmp(options, "font:", 5)) | 
 | 478 | 			strcpy(fontname, options + 5); | 
 | 479 | 		 | 
 | 480 | 		if (!strncmp(options, "scrollback:", 11)) { | 
 | 481 | 			options += 11; | 
 | 482 | 			if (*options) { | 
 | 483 | 				fbcon_softback_size = simple_strtoul(options, &options, 0); | 
 | 484 | 				if (*options == 'k' || *options == 'K') { | 
 | 485 | 					fbcon_softback_size *= 1024; | 
 | 486 | 					options++; | 
 | 487 | 				} | 
 | 488 | 				if (*options != ',') | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 489 | 					return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | 				options++; | 
 | 491 | 			} else | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 492 | 				return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | 		} | 
 | 494 | 		 | 
 | 495 | 		if (!strncmp(options, "map:", 4)) { | 
 | 496 | 			options += 4; | 
 | 497 | 			if (*options) | 
 | 498 | 				for (i = 0, j = 0; i < MAX_NR_CONSOLES; i++) { | 
 | 499 | 					if (!options[j]) | 
 | 500 | 						j = 0; | 
 | 501 | 					con2fb_map_boot[i] = | 
 | 502 | 						(options[j++]-'0') % FB_MAX; | 
 | 503 | 				} | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 504 | 			return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | 		} | 
 | 506 |  | 
 | 507 | 		if (!strncmp(options, "vc:", 3)) { | 
 | 508 | 			options += 3; | 
 | 509 | 			if (*options) | 
 | 510 | 				first_fb_vc = simple_strtoul(options, &options, 10) - 1; | 
 | 511 | 			if (first_fb_vc < 0) | 
 | 512 | 				first_fb_vc = 0; | 
 | 513 | 			if (*options++ == '-') | 
 | 514 | 				last_fb_vc = simple_strtoul(options, &options, 10) - 1; | 
 | 515 | 			fbcon_is_default = 0;  | 
 | 516 | 		}	 | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 517 |  | 
 | 518 | 		if (!strncmp(options, "rotate:", 7)) { | 
 | 519 | 			options += 7; | 
 | 520 | 			if (*options) | 
 | 521 | 				rotate = simple_strtoul(options, &options, 0); | 
 | 522 | 			if (rotate > 3) | 
 | 523 | 				rotate = 0; | 
 | 524 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | 	} | 
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 526 | 	return 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } | 
 | 528 |  | 
 | 529 | __setup("fbcon=", fb_console_setup); | 
 | 530 | #endif | 
 | 531 |  | 
 | 532 | static int search_fb_in_map(int idx) | 
 | 533 | { | 
 | 534 | 	int i, retval = 0; | 
 | 535 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 536 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | 		if (con2fb_map[i] == idx) | 
 | 538 | 			retval = 1; | 
 | 539 | 	} | 
 | 540 | 	return retval; | 
 | 541 | } | 
 | 542 |  | 
 | 543 | static int search_for_mapped_con(void) | 
 | 544 | { | 
 | 545 | 	int i, retval = 0; | 
 | 546 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 547 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | 		if (con2fb_map[i] != -1) | 
 | 549 | 			retval = 1; | 
 | 550 | 	} | 
 | 551 | 	return retval; | 
 | 552 | } | 
 | 553 |  | 
 | 554 | static int fbcon_takeover(int show_logo) | 
 | 555 | { | 
 | 556 | 	int err, i; | 
 | 557 |  | 
 | 558 | 	if (!num_registered_fb) | 
 | 559 | 		return -ENODEV; | 
 | 560 |  | 
 | 561 | 	if (!show_logo) | 
 | 562 | 		logo_shown = FBCON_LOGO_DONTSHOW; | 
 | 563 |  | 
 | 564 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) | 
 | 565 | 		con2fb_map[i] = info_idx; | 
 | 566 |  | 
 | 567 | 	err = take_over_console(&fb_con, first_fb_vc, last_fb_vc, | 
 | 568 | 				fbcon_is_default); | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 569 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | 	if (err) { | 
 | 571 | 		for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
 | 572 | 			con2fb_map[i] = -1; | 
 | 573 | 		} | 
 | 574 | 		info_idx = -1; | 
 | 575 | 	} | 
 | 576 |  | 
 | 577 | 	return err; | 
 | 578 | } | 
 | 579 |  | 
 | 580 | static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, | 
 | 581 | 			       int cols, int rows, int new_cols, int new_rows) | 
 | 582 | { | 
 | 583 | 	/* Need to make room for the logo */ | 
| Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 584 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 	int cnt, erase = vc->vc_video_erase_char, step; | 
 | 586 | 	unsigned short *save = NULL, *r, *q; | 
 | 587 |  | 
 | 588 | 	/* | 
 | 589 | 	 * remove underline attribute from erase character | 
 | 590 | 	 * if black and white framebuffer. | 
 | 591 | 	 */ | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 592 | 	if (fb_get_color_depth(&info->var, &info->fix) == 1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | 		erase &= ~0x400; | 
| Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 594 | 	logo_height = fb_prepare_logo(info, ops->rotate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | 	logo_lines = (logo_height + vc->vc_font.height - 1) / | 
 | 596 | 		vc->vc_font.height; | 
 | 597 | 	q = (unsigned short *) (vc->vc_origin + | 
 | 598 | 				vc->vc_size_row * rows); | 
 | 599 | 	step = logo_lines * cols; | 
 | 600 | 	for (r = q - logo_lines * cols; r < q; r++) | 
 | 601 | 		if (scr_readw(r) != vc->vc_video_erase_char) | 
 | 602 | 			break; | 
 | 603 | 	if (r != q && new_rows >= rows + logo_lines) { | 
 | 604 | 		save = kmalloc(logo_lines * new_cols * 2, GFP_KERNEL); | 
 | 605 | 		if (save) { | 
 | 606 | 			int i = cols < new_cols ? cols : new_cols; | 
 | 607 | 			scr_memsetw(save, erase, logo_lines * new_cols * 2); | 
 | 608 | 			r = q - step; | 
 | 609 | 			for (cnt = 0; cnt < logo_lines; cnt++, r += i) | 
 | 610 | 				scr_memcpyw(save + cnt * new_cols, r, 2 * i); | 
 | 611 | 			r = q; | 
 | 612 | 		} | 
 | 613 | 	} | 
 | 614 | 	if (r == q) { | 
 | 615 | 		/* We can scroll screen down */ | 
 | 616 | 		r = q - step - cols; | 
 | 617 | 		for (cnt = rows - logo_lines; cnt > 0; cnt--) { | 
 | 618 | 			scr_memcpyw(r + step, r, vc->vc_size_row); | 
 | 619 | 			r -= cols; | 
 | 620 | 		} | 
 | 621 | 		if (!save) { | 
 | 622 | 			vc->vc_y += logo_lines; | 
 | 623 | 			vc->vc_pos += logo_lines * vc->vc_size_row; | 
 | 624 | 		} | 
 | 625 | 	} | 
 | 626 | 	scr_memsetw((unsigned short *) vc->vc_origin, | 
 | 627 | 		    erase, | 
 | 628 | 		    vc->vc_size_row * logo_lines); | 
 | 629 |  | 
 | 630 | 	if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) { | 
 | 631 | 		fbcon_clear_margins(vc, 0); | 
 | 632 | 		update_screen(vc); | 
 | 633 | 	} | 
 | 634 |  | 
 | 635 | 	if (save) { | 
 | 636 | 		q = (unsigned short *) (vc->vc_origin + | 
 | 637 | 					vc->vc_size_row * | 
 | 638 | 					rows); | 
 | 639 | 		scr_memcpyw(q, save, logo_lines * new_cols * 2); | 
 | 640 | 		vc->vc_y += logo_lines; | 
 | 641 | 		vc->vc_pos += logo_lines * vc->vc_size_row; | 
 | 642 | 		kfree(save); | 
 | 643 | 	} | 
 | 644 |  | 
 | 645 | 	if (logo_lines > vc->vc_bottom) { | 
 | 646 | 		logo_shown = FBCON_LOGO_CANSHOW; | 
 | 647 | 		printk(KERN_INFO | 
 | 648 | 		       "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n"); | 
 | 649 | 	} else if (logo_shown != FBCON_LOGO_DONTSHOW) { | 
 | 650 | 		logo_shown = FBCON_LOGO_DRAW; | 
 | 651 | 		vc->vc_top = logo_lines; | 
 | 652 | 	} | 
 | 653 | } | 
 | 654 |  | 
 | 655 | #ifdef CONFIG_FB_TILEBLITTING | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 656 | static void set_blitting_type(struct vc_data *vc, struct fb_info *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { | 
 | 658 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 659 |  | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 660 | 	ops->p = &fb_display[vc->vc_num]; | 
| Antonino A. Daplas | ab76720 | 2005-11-13 16:06:32 -0800 | [diff] [blame] | 661 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | 	if ((info->flags & FBINFO_MISC_TILEBLITTING)) | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 663 | 		fbcon_set_tileops(vc, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 664 | 	else { | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 665 | 		fbcon_set_rotation(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | 		fbcon_set_bitops(ops); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 667 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } | 
 | 669 | #else | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 670 | static void set_blitting_type(struct vc_data *vc, struct fb_info *info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { | 
 | 672 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 673 |  | 
 | 674 | 	info->flags &= ~FBINFO_MISC_TILEBLITTING; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 675 | 	ops->p = &fb_display[vc->vc_num]; | 
 | 676 | 	fbcon_set_rotation(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | 	fbcon_set_bitops(ops); | 
 | 678 | } | 
 | 679 | #endif /* CONFIG_MISC_TILEBLITTING */ | 
 | 680 |  | 
 | 681 |  | 
 | 682 | static int con2fb_acquire_newinfo(struct vc_data *vc, struct fb_info *info, | 
 | 683 | 				  int unit, int oldidx) | 
 | 684 | { | 
 | 685 | 	struct fbcon_ops *ops = NULL; | 
 | 686 | 	int err = 0; | 
 | 687 |  | 
 | 688 | 	if (!try_module_get(info->fbops->owner)) | 
 | 689 | 		err = -ENODEV; | 
 | 690 |  | 
 | 691 | 	if (!err && info->fbops->fb_open && | 
 | 692 | 	    info->fbops->fb_open(info, 0)) | 
 | 693 | 		err = -ENODEV; | 
 | 694 |  | 
 | 695 | 	if (!err) { | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 696 | 		ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | 		if (!ops) | 
 | 698 | 			err = -ENOMEM; | 
 | 699 | 	} | 
 | 700 |  | 
 | 701 | 	if (!err) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | 		info->fbcon_par = ops; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 703 | 		set_blitting_type(vc, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | 	} | 
 | 705 |  | 
 | 706 | 	if (err) { | 
 | 707 | 		con2fb_map[unit] = oldidx; | 
 | 708 | 		module_put(info->fbops->owner); | 
 | 709 | 	} | 
 | 710 |  | 
 | 711 | 	return err; | 
 | 712 | } | 
 | 713 |  | 
 | 714 | static int con2fb_release_oldinfo(struct vc_data *vc, struct fb_info *oldinfo, | 
 | 715 | 				  struct fb_info *newinfo, int unit, | 
 | 716 | 				  int oldidx, int found) | 
 | 717 | { | 
 | 718 | 	struct fbcon_ops *ops = oldinfo->fbcon_par; | 
 | 719 | 	int err = 0; | 
 | 720 |  | 
 | 721 | 	if (oldinfo->fbops->fb_release && | 
 | 722 | 	    oldinfo->fbops->fb_release(oldinfo, 0)) { | 
 | 723 | 		con2fb_map[unit] = oldidx; | 
 | 724 | 		if (!found && newinfo->fbops->fb_release) | 
 | 725 | 			newinfo->fbops->fb_release(newinfo, 0); | 
 | 726 | 		if (!found) | 
 | 727 | 			module_put(newinfo->fbops->owner); | 
 | 728 | 		err = -ENODEV; | 
 | 729 | 	} | 
 | 730 |  | 
 | 731 | 	if (!err) { | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 732 | 		fbcon_del_cursor_timer(oldinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | 		kfree(ops->cursor_state.mask); | 
 | 734 | 		kfree(ops->cursor_data); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 735 | 		kfree(ops->fontbuffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | 		kfree(oldinfo->fbcon_par); | 
 | 737 | 		oldinfo->fbcon_par = NULL; | 
 | 738 | 		module_put(oldinfo->fbops->owner); | 
| Antonino A. Daplas | dd0314f | 2005-11-07 01:00:38 -0800 | [diff] [blame] | 739 | 		/* | 
 | 740 | 		  If oldinfo and newinfo are driving the same hardware, | 
 | 741 | 		  the fb_release() method of oldinfo may attempt to | 
 | 742 | 		  restore the hardware state.  This will leave the | 
 | 743 | 		  newinfo in an undefined state. Thus, a call to | 
 | 744 | 		  fb_set_par() may be needed for the newinfo. | 
 | 745 | 		*/ | 
 | 746 | 		if (newinfo->fbops->fb_set_par) | 
 | 747 | 			newinfo->fbops->fb_set_par(newinfo); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | 	} | 
 | 749 |  | 
 | 750 | 	return err; | 
 | 751 | } | 
 | 752 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | static void con2fb_init_display(struct vc_data *vc, struct fb_info *info, | 
 | 754 | 				int unit, int show_logo) | 
 | 755 | { | 
 | 756 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 757 |  | 
 | 758 | 	ops->currcon = fg_console; | 
 | 759 |  | 
 | 760 | 	if (info->fbops->fb_set_par && !(ops->flags & FBCON_FLAGS_INIT)) | 
 | 761 | 		info->fbops->fb_set_par(info); | 
 | 762 |  | 
 | 763 | 	ops->flags |= FBCON_FLAGS_INIT; | 
 | 764 | 	ops->graphics = 0; | 
 | 765 |  | 
 | 766 | 	if (vc) | 
 | 767 | 		fbcon_set_disp(info, &info->var, vc); | 
 | 768 | 	else | 
 | 769 | 		fbcon_preset_disp(info, &info->var, unit); | 
 | 770 |  | 
 | 771 | 	if (show_logo) { | 
 | 772 | 		struct vc_data *fg_vc = vc_cons[fg_console].d; | 
 | 773 | 		struct fb_info *fg_info = | 
 | 774 | 			registered_fb[con2fb_map[fg_console]]; | 
 | 775 |  | 
 | 776 | 		fbcon_prepare_logo(fg_vc, fg_info, fg_vc->vc_cols, | 
 | 777 | 				   fg_vc->vc_rows, fg_vc->vc_cols, | 
 | 778 | 				   fg_vc->vc_rows); | 
 | 779 | 	} | 
 | 780 |  | 
 | 781 | 	update_screen(vc_cons[fg_console].d); | 
 | 782 | } | 
 | 783 |  | 
 | 784 | /** | 
 | 785 |  *	set_con2fb_map - map console to frame buffer device | 
 | 786 |  *	@unit: virtual console number to map | 
 | 787 |  *	@newidx: frame buffer index to map virtual console to | 
 | 788 |  *      @user: user request | 
 | 789 |  * | 
 | 790 |  *	Maps a virtual console @unit to a frame buffer device | 
 | 791 |  *	@newidx. | 
 | 792 |  */ | 
 | 793 | static int set_con2fb_map(int unit, int newidx, int user) | 
 | 794 | { | 
 | 795 | 	struct vc_data *vc = vc_cons[unit].d; | 
 | 796 | 	int oldidx = con2fb_map[unit]; | 
 | 797 | 	struct fb_info *info = registered_fb[newidx]; | 
 | 798 | 	struct fb_info *oldinfo = NULL; | 
 | 799 |  	int found, err = 0; | 
 | 800 |  | 
 | 801 | 	if (oldidx == newidx) | 
 | 802 | 		return 0; | 
 | 803 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 804 | 	if (!info || fbcon_has_exited) | 
 | 805 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 |  | 
 | 807 |  	if (!err && !search_for_mapped_con()) { | 
 | 808 | 		info_idx = newidx; | 
 | 809 | 		return fbcon_takeover(0); | 
 | 810 | 	} | 
 | 811 |  | 
 | 812 | 	if (oldidx != -1) | 
 | 813 | 		oldinfo = registered_fb[oldidx]; | 
 | 814 |  | 
 | 815 | 	found = search_fb_in_map(newidx); | 
 | 816 |  | 
 | 817 | 	acquire_console_sem(); | 
 | 818 | 	con2fb_map[unit] = newidx; | 
 | 819 | 	if (!err && !found) | 
 | 820 |  		err = con2fb_acquire_newinfo(vc, info, unit, oldidx); | 
 | 821 |  | 
 | 822 |  | 
 | 823 | 	/* | 
 | 824 | 	 * If old fb is not mapped to any of the consoles, | 
 | 825 | 	 * fbcon should release it. | 
 | 826 | 	 */ | 
 | 827 |  	if (!err && oldinfo && !search_fb_in_map(oldidx)) | 
 | 828 |  		err = con2fb_release_oldinfo(vc, oldinfo, info, unit, oldidx, | 
 | 829 |  					     found); | 
 | 830 |  | 
 | 831 |  	if (!err) { | 
 | 832 |  		int show_logo = (fg_console == 0 && !user && | 
 | 833 |  				 logo_shown != FBCON_LOGO_DONTSHOW); | 
 | 834 |  | 
 | 835 |  		if (!found) | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 836 |  			fbcon_add_cursor_timer(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 |  		con2fb_map_boot[unit] = newidx; | 
 | 838 |  		con2fb_init_display(vc, info, unit, show_logo); | 
 | 839 | 	} | 
 | 840 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 841 | 	if (!search_fb_in_map(info_idx)) | 
 | 842 | 		info_idx = newidx; | 
 | 843 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | 	release_console_sem(); | 
 | 845 |  	return err; | 
 | 846 | } | 
 | 847 |  | 
 | 848 | /* | 
 | 849 |  *  Low Level Operations | 
 | 850 |  */ | 
 | 851 | /* NOTE: fbcon cannot be __init: it may be called from take_over_console later */ | 
 | 852 | static int var_to_display(struct display *disp, | 
 | 853 | 			  struct fb_var_screeninfo *var, | 
 | 854 | 			  struct fb_info *info) | 
 | 855 | { | 
 | 856 | 	disp->xres_virtual = var->xres_virtual; | 
 | 857 | 	disp->yres_virtual = var->yres_virtual; | 
 | 858 | 	disp->bits_per_pixel = var->bits_per_pixel; | 
 | 859 | 	disp->grayscale = var->grayscale; | 
 | 860 | 	disp->nonstd = var->nonstd; | 
 | 861 | 	disp->accel_flags = var->accel_flags; | 
 | 862 | 	disp->height = var->height; | 
 | 863 | 	disp->width = var->width; | 
 | 864 | 	disp->red = var->red; | 
 | 865 | 	disp->green = var->green; | 
 | 866 | 	disp->blue = var->blue; | 
 | 867 | 	disp->transp = var->transp; | 
 | 868 | 	disp->rotate = var->rotate; | 
 | 869 | 	disp->mode = fb_match_mode(var, &info->modelist); | 
 | 870 | 	if (disp->mode == NULL) | 
 | 871 | 		/* This should not happen */ | 
 | 872 | 		return -EINVAL; | 
 | 873 | 	return 0; | 
 | 874 | } | 
 | 875 |  | 
 | 876 | static void display_to_var(struct fb_var_screeninfo *var, | 
 | 877 | 			   struct display *disp) | 
 | 878 | { | 
 | 879 | 	fb_videomode_to_var(var, disp->mode); | 
 | 880 | 	var->xres_virtual = disp->xres_virtual; | 
 | 881 | 	var->yres_virtual = disp->yres_virtual; | 
 | 882 | 	var->bits_per_pixel = disp->bits_per_pixel; | 
 | 883 | 	var->grayscale = disp->grayscale; | 
 | 884 | 	var->nonstd = disp->nonstd; | 
 | 885 | 	var->accel_flags = disp->accel_flags; | 
 | 886 | 	var->height = disp->height; | 
 | 887 | 	var->width = disp->width; | 
 | 888 | 	var->red = disp->red; | 
 | 889 | 	var->green = disp->green; | 
 | 890 | 	var->blue = disp->blue; | 
 | 891 | 	var->transp = disp->transp; | 
 | 892 | 	var->rotate = disp->rotate; | 
 | 893 | } | 
 | 894 |  | 
 | 895 | static const char *fbcon_startup(void) | 
 | 896 | { | 
 | 897 | 	const char *display_desc = "frame buffer device"; | 
 | 898 | 	struct display *p = &fb_display[fg_console]; | 
 | 899 | 	struct vc_data *vc = vc_cons[fg_console].d; | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 900 | 	const struct font_desc *font = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | 	struct module *owner; | 
 | 902 | 	struct fb_info *info = NULL; | 
 | 903 | 	struct fbcon_ops *ops; | 
 | 904 | 	int rows, cols; | 
 | 905 | 	int irqres; | 
 | 906 |  | 
 | 907 | 	irqres = 1; | 
 | 908 | 	/* | 
 | 909 | 	 *  If num_registered_fb is zero, this is a call for the dummy part. | 
 | 910 | 	 *  The frame buffer devices weren't initialized yet. | 
 | 911 | 	 */ | 
 | 912 | 	if (!num_registered_fb || info_idx == -1) | 
 | 913 | 		return display_desc; | 
 | 914 | 	/* | 
 | 915 | 	 * Instead of blindly using registered_fb[0], we use info_idx, set by | 
 | 916 | 	 * fb_console_init(); | 
 | 917 | 	 */ | 
 | 918 | 	info = registered_fb[info_idx]; | 
 | 919 | 	if (!info) | 
 | 920 | 		return NULL; | 
 | 921 | 	 | 
 | 922 | 	owner = info->fbops->owner; | 
 | 923 | 	if (!try_module_get(owner)) | 
 | 924 | 		return NULL; | 
 | 925 | 	if (info->fbops->fb_open && info->fbops->fb_open(info, 0)) { | 
 | 926 | 		module_put(owner); | 
 | 927 | 		return NULL; | 
 | 928 | 	} | 
 | 929 |  | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 930 | 	ops = kzalloc(sizeof(struct fbcon_ops), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | 	if (!ops) { | 
 | 932 | 		module_put(owner); | 
 | 933 | 		return NULL; | 
 | 934 | 	} | 
 | 935 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | 	ops->currcon = -1; | 
 | 937 | 	ops->graphics = 1; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 938 | 	ops->cur_rotate = -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | 	info->fbcon_par = ops; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 940 | 	p->con_rotate = rotate; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 941 | 	set_blitting_type(vc, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 |  | 
 | 943 | 	if (info->fix.type != FB_TYPE_TEXT) { | 
 | 944 | 		if (fbcon_softback_size) { | 
 | 945 | 			if (!softback_buf) { | 
 | 946 | 				softback_buf = | 
 | 947 | 				    (unsigned long) | 
 | 948 | 				    kmalloc(fbcon_softback_size, | 
 | 949 | 					    GFP_KERNEL); | 
 | 950 | 				if (!softback_buf) { | 
 | 951 | 					fbcon_softback_size = 0; | 
 | 952 | 					softback_top = 0; | 
 | 953 | 				} | 
 | 954 | 			} | 
 | 955 | 		} else { | 
 | 956 | 			if (softback_buf) { | 
 | 957 | 				kfree((void *) softback_buf); | 
 | 958 | 				softback_buf = 0; | 
 | 959 | 				softback_top = 0; | 
 | 960 | 			} | 
 | 961 | 		} | 
 | 962 | 		if (softback_buf) | 
 | 963 | 			softback_in = softback_top = softback_curr = | 
 | 964 | 			    softback_buf; | 
 | 965 | 		softback_lines = 0; | 
 | 966 | 	} | 
 | 967 |  | 
 | 968 | 	/* Setup default font */ | 
 | 969 | 	if (!p->fontdata) { | 
 | 970 | 		if (!fontname[0] || !(font = find_font(fontname))) | 
 | 971 | 			font = get_default_font(info->var.xres, | 
 | 972 | 						info->var.yres); | 
 | 973 | 		vc->vc_font.width = font->width; | 
 | 974 | 		vc->vc_font.height = font->height; | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 975 | 		vc->vc_font.data = (void *)(p->fontdata = font->data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | 		vc->vc_font.charcount = 256; /* FIXME  Need to support more fonts */ | 
 | 977 | 	} | 
 | 978 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 979 | 	cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); | 
 | 980 | 	rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 981 | 	cols /= vc->vc_font.width; | 
 | 982 | 	rows /= vc->vc_font.height; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | 	vc_resize(vc, cols, rows); | 
 | 984 |  | 
 | 985 | 	DPRINTK("mode:   %s\n", info->fix.id); | 
 | 986 | 	DPRINTK("visual: %d\n", info->fix.visual); | 
 | 987 | 	DPRINTK("res:    %dx%d-%d\n", info->var.xres, | 
 | 988 | 		info->var.yres, | 
 | 989 | 		info->var.bits_per_pixel); | 
 | 990 |  | 
 | 991 | #ifdef CONFIG_ATARI | 
 | 992 | 	if (MACH_IS_ATARI) { | 
 | 993 | 		cursor_blink_rate = ATARI_CURSOR_BLINK_RATE; | 
 | 994 | 		irqres = | 
 | 995 | 		    request_irq(IRQ_AUTO_4, fb_vbl_handler, | 
 | 996 | 				IRQ_TYPE_PRIO, "framebuffer vbl", | 
 | 997 | 				info); | 
 | 998 | 	} | 
 | 999 | #endif				/* CONFIG_ATARI */ | 
 | 1000 |  | 
 | 1001 | #ifdef CONFIG_MAC | 
 | 1002 | 	/* | 
 | 1003 | 	 * On a Macintoy, the VBL interrupt may or may not be active.  | 
 | 1004 | 	 * As interrupt based cursor is more reliable and race free, we  | 
 | 1005 | 	 * probe for VBL interrupts. | 
 | 1006 | 	 */ | 
 | 1007 | 	if (MACH_IS_MAC) { | 
 | 1008 | 		int ct = 0; | 
 | 1009 | 		/* | 
 | 1010 | 		 * Probe for VBL: set temp. handler ... | 
 | 1011 | 		 */ | 
 | 1012 | 		irqres = request_irq(IRQ_MAC_VBL, fb_vbl_detect, 0, | 
 | 1013 | 				     "framebuffer vbl", info); | 
 | 1014 | 		vbl_detected = 0; | 
 | 1015 |  | 
 | 1016 | 		/* | 
 | 1017 | 		 * ... and spin for 20 ms ... | 
 | 1018 | 		 */ | 
 | 1019 | 		while (!vbl_detected && ++ct < 1000) | 
 | 1020 | 			udelay(20); | 
 | 1021 |  | 
 | 1022 | 		if (ct == 1000) | 
 | 1023 | 			printk | 
 | 1024 | 			    ("fbcon_startup: No VBL detected, using timer based cursor.\n"); | 
 | 1025 |  | 
 | 1026 | 		free_irq(IRQ_MAC_VBL, fb_vbl_detect); | 
 | 1027 |  | 
 | 1028 | 		if (vbl_detected) { | 
 | 1029 | 			/* | 
 | 1030 | 			 * interrupt based cursor ok | 
 | 1031 | 			 */ | 
 | 1032 | 			cursor_blink_rate = MAC_CURSOR_BLINK_RATE; | 
 | 1033 | 			irqres = | 
 | 1034 | 			    request_irq(IRQ_MAC_VBL, fb_vbl_handler, 0, | 
 | 1035 | 					"framebuffer vbl", info); | 
 | 1036 | 		} else { | 
 | 1037 | 			/* | 
 | 1038 | 			 * VBL not detected: fall through, use timer based cursor | 
 | 1039 | 			 */ | 
 | 1040 | 			irqres = 1; | 
 | 1041 | 		} | 
 | 1042 | 	} | 
 | 1043 | #endif				/* CONFIG_MAC */ | 
 | 1044 |  | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 1045 | 	fbcon_add_cursor_timer(info); | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1046 | 	fbcon_has_exited = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | 	return display_desc; | 
 | 1048 | } | 
 | 1049 |  | 
 | 1050 | static void fbcon_init(struct vc_data *vc, int init) | 
 | 1051 | { | 
 | 1052 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1053 | 	struct fbcon_ops *ops; | 
 | 1054 | 	struct vc_data **default_mode = vc->vc_display_fg; | 
 | 1055 | 	struct vc_data *svc = *default_mode; | 
 | 1056 | 	struct display *t, *p = &fb_display[vc->vc_num]; | 
 | 1057 | 	int logo = 1, new_rows, new_cols, rows, cols, charcnt = 256; | 
| Adrian Bunk | 306958e | 2005-05-01 08:59:23 -0700 | [diff] [blame] | 1058 | 	int cap; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 |  | 
 | 1060 | 	if (info_idx == -1 || info == NULL) | 
 | 1061 | 	    return; | 
| Adrian Bunk | 306958e | 2005-05-01 08:59:23 -0700 | [diff] [blame] | 1062 |  | 
 | 1063 | 	cap = info->flags; | 
 | 1064 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | 	if (vc != svc || logo_shown == FBCON_LOGO_DONTSHOW || | 
 | 1066 | 	    (info->fix.type == FB_TYPE_TEXT)) | 
 | 1067 | 		logo = 0; | 
 | 1068 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | 	if (var_to_display(p, &info->var, info)) | 
 | 1070 | 		return; | 
 | 1071 |  | 
 | 1072 | 	/* If we are not the first console on this | 
 | 1073 | 	   fb, copy the font from that console */ | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1074 | 	t = &fb_display[fg_console]; | 
 | 1075 | 	if (!p->fontdata) { | 
 | 1076 | 		if (t->fontdata) { | 
 | 1077 | 			struct vc_data *fvc = vc_cons[fg_console].d; | 
 | 1078 |  | 
 | 1079 | 			vc->vc_font.data = (void *)(p->fontdata = | 
 | 1080 | 						    fvc->vc_font.data); | 
 | 1081 | 			vc->vc_font.width = fvc->vc_font.width; | 
 | 1082 | 			vc->vc_font.height = fvc->vc_font.height; | 
 | 1083 | 			p->userfont = t->userfont; | 
 | 1084 |  | 
 | 1085 | 			if (p->userfont) | 
 | 1086 | 				REFCOUNT(p->fontdata)++; | 
 | 1087 | 		} else { | 
 | 1088 | 			const struct font_desc *font = NULL; | 
 | 1089 |  | 
 | 1090 | 			if (!fontname[0] || !(font = find_font(fontname))) | 
 | 1091 | 				font = get_default_font(info->var.xres, | 
 | 1092 | 							info->var.yres); | 
 | 1093 | 			vc->vc_font.width = font->width; | 
 | 1094 | 			vc->vc_font.height = font->height; | 
 | 1095 | 			vc->vc_font.data = (void *)(p->fontdata = font->data); | 
 | 1096 | 			vc->vc_font.charcount = 256; /* FIXME  Need to | 
 | 1097 | 							support more fonts */ | 
 | 1098 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | 	} | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1100 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | 	if (p->userfont) | 
 | 1102 | 		charcnt = FNTCHARCNT(p->fontdata); | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1103 |  | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 1104 | 	vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | 	vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; | 
 | 1106 | 	if (charcnt == 256) { | 
 | 1107 | 		vc->vc_hi_font_mask = 0; | 
 | 1108 | 	} else { | 
 | 1109 | 		vc->vc_hi_font_mask = 0x100; | 
 | 1110 | 		if (vc->vc_can_do_color) | 
 | 1111 | 			vc->vc_complement_mask <<= 1; | 
 | 1112 | 	} | 
 | 1113 |  | 
 | 1114 | 	if (!*svc->vc_uni_pagedir_loc) | 
 | 1115 | 		con_set_default_unimap(svc); | 
 | 1116 | 	if (!*vc->vc_uni_pagedir_loc) | 
 | 1117 | 		con_copy_unimap(vc, svc); | 
 | 1118 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1119 | 	ops = info->fbcon_par; | 
 | 1120 | 	p->con_rotate = rotate; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 1121 | 	set_blitting_type(vc, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1122 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | 	cols = vc->vc_cols; | 
 | 1124 | 	rows = vc->vc_rows; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1125 | 	new_cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); | 
 | 1126 | 	new_rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 1127 | 	new_cols /= vc->vc_font.width; | 
 | 1128 | 	new_rows /= vc->vc_font.height; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | 	vc_resize(vc, new_cols, new_rows); | 
 | 1130 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | 	/* | 
 | 1132 | 	 * We must always set the mode. The mode of the previous console | 
 | 1133 | 	 * driver could be in the same resolution but we are using different | 
 | 1134 | 	 * hardware so we have to initialize the hardware. | 
 | 1135 | 	 * | 
 | 1136 | 	 * We need to do it in fbcon_init() to prevent screen corruption. | 
 | 1137 | 	 */ | 
| Knut Petersen | d354d9a | 2006-01-07 10:22:04 +0100 | [diff] [blame] | 1138 | 	if (CON_IS_VISIBLE(vc) && vc->vc_mode == KD_TEXT) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | 		if (info->fbops->fb_set_par && | 
 | 1140 | 		    !(ops->flags & FBCON_FLAGS_INIT)) | 
 | 1141 | 			info->fbops->fb_set_par(info); | 
 | 1142 | 		ops->flags |= FBCON_FLAGS_INIT; | 
 | 1143 | 	} | 
 | 1144 |  | 
 | 1145 | 	ops->graphics = 0; | 
 | 1146 |  | 
 | 1147 | 	if ((cap & FBINFO_HWACCEL_COPYAREA) && | 
 | 1148 | 	    !(cap & FBINFO_HWACCEL_DISABLED)) | 
 | 1149 | 		p->scrollmode = SCROLL_MOVE; | 
 | 1150 | 	else /* default to something safe */ | 
 | 1151 | 		p->scrollmode = SCROLL_REDRAW; | 
 | 1152 |  | 
 | 1153 | 	/* | 
 | 1154 | 	 *  ++guenther: console.c:vc_allocate() relies on initializing | 
 | 1155 | 	 *  vc_{cols,rows}, but we must not set those if we are only | 
 | 1156 | 	 *  resizing the console. | 
 | 1157 | 	 */ | 
 | 1158 | 	if (!init) { | 
 | 1159 | 		vc->vc_cols = new_cols; | 
 | 1160 | 		vc->vc_rows = new_rows; | 
 | 1161 | 	} | 
 | 1162 |  | 
 | 1163 | 	if (logo) | 
 | 1164 | 		fbcon_prepare_logo(vc, info, cols, rows, new_cols, new_rows); | 
 | 1165 |  | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 1166 | 	if (vc == svc && softback_buf) | 
 | 1167 | 		fbcon_update_softback(vc); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1168 |  | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 1169 | 	if (ops->rotate_font && ops->rotate_font(info, vc)) { | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1170 | 		ops->rotate = FB_ROTATE_UR; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 1171 | 		set_blitting_type(vc, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1172 | 	} | 
 | 1173 |  | 
| Antonino A. Daplas | 1a37d5f | 2006-03-31 02:31:45 -0800 | [diff] [blame] | 1174 | 	ops->p = &fb_display[fg_console]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | } | 
 | 1176 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1177 | static void fbcon_free_font(struct display *p) | 
 | 1178 | { | 
 | 1179 | 	if (p->userfont && p->fontdata && (--REFCOUNT(p->fontdata) == 0)) | 
 | 1180 | 		kfree(p->fontdata - FONT_EXTRA_WORDS * sizeof(int)); | 
 | 1181 | 	p->fontdata = NULL; | 
 | 1182 | 	p->userfont = 0; | 
 | 1183 | } | 
 | 1184 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | static void fbcon_deinit(struct vc_data *vc) | 
 | 1186 | { | 
 | 1187 | 	struct display *p = &fb_display[vc->vc_num]; | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1188 | 	struct fb_info *info; | 
 | 1189 | 	struct fbcon_ops *ops; | 
 | 1190 | 	int idx; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | 	fbcon_free_font(p); | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 1193 | 	idx = con2fb_map[vc->vc_num]; | 
 | 1194 |  | 
 | 1195 | 	if (idx == -1) | 
 | 1196 | 		goto finished; | 
 | 1197 |  | 
 | 1198 | 	info = registered_fb[idx]; | 
 | 1199 |  | 
 | 1200 | 	if (!info) | 
 | 1201 | 		goto finished; | 
 | 1202 |  | 
 | 1203 | 	ops = info->fbcon_par; | 
 | 1204 |  | 
 | 1205 | 	if (!ops) | 
 | 1206 | 		goto finished; | 
 | 1207 |  | 
 | 1208 | 	if (CON_IS_VISIBLE(vc)) | 
 | 1209 | 		fbcon_del_cursor_timer(info); | 
 | 1210 |  | 
 | 1211 | 	ops->flags &= ~FBCON_FLAGS_INIT; | 
 | 1212 | finished: | 
 | 1213 |  | 
 | 1214 | 	if (!con_is_bound(&fb_con)) | 
 | 1215 | 		fbcon_exit(); | 
 | 1216 |  | 
 | 1217 | 	return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } | 
 | 1219 |  | 
 | 1220 | /* ====================================================================== */ | 
 | 1221 |  | 
 | 1222 | /*  fbcon_XXX routines - interface used by the world | 
 | 1223 |  * | 
 | 1224 |  *  This system is now divided into two levels because of complications | 
 | 1225 |  *  caused by hardware scrolling. Top level functions: | 
 | 1226 |  * | 
 | 1227 |  *	fbcon_bmove(), fbcon_clear(), fbcon_putc(), fbcon_clear_margins() | 
 | 1228 |  * | 
 | 1229 |  *  handles y values in range [0, scr_height-1] that correspond to real | 
 | 1230 |  *  screen positions. y_wrap shift means that first line of bitmap may be | 
 | 1231 |  *  anywhere on this display. These functions convert lineoffsets to | 
 | 1232 |  *  bitmap offsets and deal with the wrap-around case by splitting blits. | 
 | 1233 |  * | 
 | 1234 |  *	fbcon_bmove_physical_8()    -- These functions fast implementations | 
 | 1235 |  *	fbcon_clear_physical_8()    -- of original fbcon_XXX fns. | 
 | 1236 |  *	fbcon_putc_physical_8()	    -- (font width != 8) may be added later | 
 | 1237 |  * | 
 | 1238 |  *  WARNING: | 
 | 1239 |  * | 
 | 1240 |  *  At the moment fbcon_putc() cannot blit across vertical wrap boundary | 
 | 1241 |  *  Implies should only really hardware scroll in rows. Only reason for | 
 | 1242 |  *  restriction is simplicity & efficiency at the moment. | 
 | 1243 |  */ | 
 | 1244 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | static void fbcon_clear(struct vc_data *vc, int sy, int sx, int height, | 
 | 1246 | 			int width) | 
 | 1247 | { | 
 | 1248 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1249 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1250 |  | 
 | 1251 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1252 | 	u_int y_break; | 
 | 1253 |  | 
 | 1254 | 	if (fbcon_is_inactive(vc, info)) | 
 | 1255 | 		return; | 
 | 1256 |  | 
 | 1257 | 	if (!height || !width) | 
 | 1258 | 		return; | 
 | 1259 |  | 
 | 1260 | 	/* Split blits that cross physical y_wrap boundary */ | 
 | 1261 |  | 
 | 1262 | 	y_break = p->vrows - p->yscroll; | 
 | 1263 | 	if (sy < y_break && sy + height - 1 >= y_break) { | 
 | 1264 | 		u_int b = y_break - sy; | 
 | 1265 | 		ops->clear(vc, info, real_y(p, sy), sx, b, width); | 
 | 1266 | 		ops->clear(vc, info, real_y(p, sy + b), sx, height - b, | 
 | 1267 | 				 width); | 
 | 1268 | 	} else | 
 | 1269 | 		ops->clear(vc, info, real_y(p, sy), sx, height, width); | 
 | 1270 | } | 
 | 1271 |  | 
 | 1272 | static void fbcon_putcs(struct vc_data *vc, const unsigned short *s, | 
 | 1273 | 			int count, int ypos, int xpos) | 
 | 1274 | { | 
 | 1275 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1276 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1277 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1278 |  | 
 | 1279 | 	if (!fbcon_is_inactive(vc, info)) | 
 | 1280 | 		ops->putcs(vc, info, s, count, real_y(p, ypos), xpos, | 
 | 1281 | 			   get_color(vc, info, scr_readw(s), 1), | 
 | 1282 | 			   get_color(vc, info, scr_readw(s), 0)); | 
 | 1283 | } | 
 | 1284 |  | 
 | 1285 | static void fbcon_putc(struct vc_data *vc, int c, int ypos, int xpos) | 
 | 1286 | { | 
 | 1287 | 	unsigned short chr; | 
 | 1288 |  | 
 | 1289 | 	scr_writew(c, &chr); | 
 | 1290 | 	fbcon_putcs(vc, &chr, 1, ypos, xpos); | 
 | 1291 | } | 
 | 1292 |  | 
 | 1293 | static void fbcon_clear_margins(struct vc_data *vc, int bottom_only) | 
 | 1294 | { | 
 | 1295 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1296 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1297 |  | 
 | 1298 | 	if (!fbcon_is_inactive(vc, info)) | 
 | 1299 | 		ops->clear_margins(vc, info, bottom_only); | 
 | 1300 | } | 
 | 1301 |  | 
 | 1302 | static void fbcon_cursor(struct vc_data *vc, int mode) | 
 | 1303 | { | 
 | 1304 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1305 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | 	int y; | 
 | 1307 |  	int c = scr_readw((u16 *) vc->vc_pos); | 
 | 1308 |  | 
 | 1309 | 	if (fbcon_is_inactive(vc, info)) | 
 | 1310 | 		return; | 
 | 1311 |  | 
 | 1312 | 	ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1; | 
 | 1313 | 	if (mode & CM_SOFTBACK) { | 
 | 1314 | 		mode &= ~CM_SOFTBACK; | 
 | 1315 | 		y = softback_lines; | 
 | 1316 | 	} else { | 
 | 1317 | 		if (softback_lines) | 
 | 1318 | 			fbcon_set_origin(vc); | 
 | 1319 | 		y = 0; | 
 | 1320 | 	} | 
 | 1321 |  | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 1322 | 	ops->cursor(vc, info, mode, y, get_color(vc, info, c, 1), | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | 		    get_color(vc, info, c, 0)); | 
 | 1324 | 	vbl_cursor_cnt = CURSOR_DRAW_DELAY; | 
 | 1325 | } | 
 | 1326 |  | 
 | 1327 | static int scrollback_phys_max = 0; | 
 | 1328 | static int scrollback_max = 0; | 
 | 1329 | static int scrollback_current = 0; | 
 | 1330 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | /* | 
 | 1332 |  * If no vc is existent yet, just set struct display | 
 | 1333 |  */ | 
 | 1334 | static void fbcon_preset_disp(struct fb_info *info, struct fb_var_screeninfo *var, | 
 | 1335 | 			      int unit) | 
 | 1336 | { | 
 | 1337 | 	struct display *p = &fb_display[unit]; | 
 | 1338 | 	struct display *t = &fb_display[fg_console]; | 
 | 1339 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | 	if (var_to_display(p, var, info)) | 
 | 1341 | 		return; | 
 | 1342 |  | 
 | 1343 | 	p->fontdata = t->fontdata; | 
 | 1344 | 	p->userfont = t->userfont; | 
 | 1345 | 	if (p->userfont) | 
 | 1346 | 		REFCOUNT(p->fontdata)++; | 
 | 1347 | } | 
 | 1348 |  | 
 | 1349 | static void fbcon_set_disp(struct fb_info *info, struct fb_var_screeninfo *var, | 
 | 1350 | 			   struct vc_data *vc) | 
 | 1351 | { | 
 | 1352 | 	struct display *p = &fb_display[vc->vc_num], *t; | 
 | 1353 | 	struct vc_data **default_mode = vc->vc_display_fg; | 
 | 1354 | 	struct vc_data *svc = *default_mode; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1355 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | 	int rows, cols, charcnt = 256; | 
 | 1357 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | 	if (var_to_display(p, var, info)) | 
 | 1359 | 		return; | 
 | 1360 | 	t = &fb_display[svc->vc_num]; | 
 | 1361 | 	if (!vc->vc_font.data) { | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 1362 | 		vc->vc_font.data = (void *)(p->fontdata = t->fontdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | 		vc->vc_font.width = (*default_mode)->vc_font.width; | 
 | 1364 | 		vc->vc_font.height = (*default_mode)->vc_font.height; | 
 | 1365 | 		p->userfont = t->userfont; | 
 | 1366 | 		if (p->userfont) | 
 | 1367 | 			REFCOUNT(p->fontdata)++; | 
 | 1368 | 	} | 
 | 1369 | 	if (p->userfont) | 
 | 1370 | 		charcnt = FNTCHARCNT(p->fontdata); | 
 | 1371 |  | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 1372 | 	var->activate = FB_ACTIVATE_NOW; | 
 | 1373 | 	info->var.activate = var->activate; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1374 | 	var->yoffset = info->var.yoffset; | 
 | 1375 | 	var->xoffset = info->var.xoffset; | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 1376 | 	fb_set_var(info, var); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1377 | 	ops->var = info->var; | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 1378 | 	vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | 	vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; | 
 | 1380 | 	if (charcnt == 256) { | 
 | 1381 | 		vc->vc_hi_font_mask = 0; | 
 | 1382 | 	} else { | 
 | 1383 | 		vc->vc_hi_font_mask = 0x100; | 
 | 1384 | 		if (vc->vc_can_do_color) | 
 | 1385 | 			vc->vc_complement_mask <<= 1; | 
 | 1386 | 	} | 
 | 1387 |  | 
 | 1388 | 	if (!*svc->vc_uni_pagedir_loc) | 
 | 1389 | 		con_set_default_unimap(svc); | 
 | 1390 | 	if (!*vc->vc_uni_pagedir_loc) | 
 | 1391 | 		con_copy_unimap(vc, svc); | 
 | 1392 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1393 | 	cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); | 
 | 1394 | 	rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 1395 | 	cols /= vc->vc_font.width; | 
 | 1396 | 	rows /= vc->vc_font.height; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | 	vc_resize(vc, cols, rows); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1398 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | 	if (CON_IS_VISIBLE(vc)) { | 
 | 1400 | 		update_screen(vc); | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 1401 | 		if (softback_buf) | 
 | 1402 | 			fbcon_update_softback(vc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | 	} | 
 | 1404 | } | 
 | 1405 |  | 
 | 1406 | static __inline__ void ywrap_up(struct vc_data *vc, int count) | 
 | 1407 | { | 
 | 1408 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1409 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1411 | 	 | 
 | 1412 | 	p->yscroll += count; | 
 | 1413 | 	if (p->yscroll >= p->vrows)	/* Deal with wrap */ | 
 | 1414 | 		p->yscroll -= p->vrows; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1415 | 	ops->var.xoffset = 0; | 
 | 1416 | 	ops->var.yoffset = p->yscroll * vc->vc_font.height; | 
 | 1417 | 	ops->var.vmode |= FB_VMODE_YWRAP; | 
 | 1418 | 	ops->update_start(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | 	scrollback_max += count; | 
 | 1420 | 	if (scrollback_max > scrollback_phys_max) | 
 | 1421 | 		scrollback_max = scrollback_phys_max; | 
 | 1422 | 	scrollback_current = 0; | 
 | 1423 | } | 
 | 1424 |  | 
 | 1425 | static __inline__ void ywrap_down(struct vc_data *vc, int count) | 
 | 1426 | { | 
 | 1427 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1428 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1430 | 	 | 
 | 1431 | 	p->yscroll -= count; | 
 | 1432 | 	if (p->yscroll < 0)	/* Deal with wrap */ | 
 | 1433 | 		p->yscroll += p->vrows; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1434 | 	ops->var.xoffset = 0; | 
 | 1435 | 	ops->var.yoffset = p->yscroll * vc->vc_font.height; | 
 | 1436 | 	ops->var.vmode |= FB_VMODE_YWRAP; | 
 | 1437 | 	ops->update_start(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | 	scrollback_max -= count; | 
 | 1439 | 	if (scrollback_max < 0) | 
 | 1440 | 		scrollback_max = 0; | 
 | 1441 | 	scrollback_current = 0; | 
 | 1442 | } | 
 | 1443 |  | 
 | 1444 | static __inline__ void ypan_up(struct vc_data *vc, int count) | 
 | 1445 | { | 
 | 1446 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1447 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1448 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1449 |  | 
 | 1450 | 	p->yscroll += count; | 
 | 1451 | 	if (p->yscroll > p->vrows - vc->vc_rows) { | 
 | 1452 | 		ops->bmove(vc, info, p->vrows - vc->vc_rows, | 
 | 1453 | 			    0, 0, 0, vc->vc_rows, vc->vc_cols); | 
 | 1454 | 		p->yscroll -= p->vrows - vc->vc_rows; | 
 | 1455 | 	} | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1456 |  | 
 | 1457 | 	ops->var.xoffset = 0; | 
 | 1458 | 	ops->var.yoffset = p->yscroll * vc->vc_font.height; | 
 | 1459 | 	ops->var.vmode &= ~FB_VMODE_YWRAP; | 
 | 1460 | 	ops->update_start(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | 	fbcon_clear_margins(vc, 1); | 
 | 1462 | 	scrollback_max += count; | 
 | 1463 | 	if (scrollback_max > scrollback_phys_max) | 
 | 1464 | 		scrollback_max = scrollback_phys_max; | 
 | 1465 | 	scrollback_current = 0; | 
 | 1466 | } | 
 | 1467 |  | 
 | 1468 | static __inline__ void ypan_up_redraw(struct vc_data *vc, int t, int count) | 
 | 1469 | { | 
 | 1470 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1471 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | 	struct display *p = &fb_display[vc->vc_num]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 |  | 
 | 1474 | 	p->yscroll += count; | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 1475 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | 	if (p->yscroll > p->vrows - vc->vc_rows) { | 
 | 1477 | 		p->yscroll -= p->vrows - vc->vc_rows; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | 		fbcon_redraw_move(vc, p, t + count, vc->vc_rows - count, t); | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 1479 | 	} | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1480 |  | 
 | 1481 | 	ops->var.xoffset = 0; | 
 | 1482 | 	ops->var.yoffset = p->yscroll * vc->vc_font.height; | 
 | 1483 | 	ops->var.vmode &= ~FB_VMODE_YWRAP; | 
 | 1484 | 	ops->update_start(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | 	fbcon_clear_margins(vc, 1); | 
 | 1486 | 	scrollback_max += count; | 
 | 1487 | 	if (scrollback_max > scrollback_phys_max) | 
 | 1488 | 		scrollback_max = scrollback_phys_max; | 
 | 1489 | 	scrollback_current = 0; | 
 | 1490 | } | 
 | 1491 |  | 
 | 1492 | static __inline__ void ypan_down(struct vc_data *vc, int count) | 
 | 1493 | { | 
 | 1494 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1495 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1496 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1497 | 	 | 
 | 1498 | 	p->yscroll -= count; | 
 | 1499 | 	if (p->yscroll < 0) { | 
 | 1500 | 		ops->bmove(vc, info, 0, 0, p->vrows - vc->vc_rows, | 
 | 1501 | 			    0, vc->vc_rows, vc->vc_cols); | 
 | 1502 | 		p->yscroll += p->vrows - vc->vc_rows; | 
 | 1503 | 	} | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1504 |  | 
 | 1505 | 	ops->var.xoffset = 0; | 
 | 1506 | 	ops->var.yoffset = p->yscroll * vc->vc_font.height; | 
 | 1507 | 	ops->var.vmode &= ~FB_VMODE_YWRAP; | 
 | 1508 | 	ops->update_start(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | 	fbcon_clear_margins(vc, 1); | 
 | 1510 | 	scrollback_max -= count; | 
 | 1511 | 	if (scrollback_max < 0) | 
 | 1512 | 		scrollback_max = 0; | 
 | 1513 | 	scrollback_current = 0; | 
 | 1514 | } | 
 | 1515 |  | 
 | 1516 | static __inline__ void ypan_down_redraw(struct vc_data *vc, int t, int count) | 
 | 1517 | { | 
 | 1518 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1519 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | 	struct display *p = &fb_display[vc->vc_num]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 |  | 
 | 1522 | 	p->yscroll -= count; | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 1523 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | 	if (p->yscroll < 0) { | 
 | 1525 | 		p->yscroll += p->vrows - vc->vc_rows; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | 		fbcon_redraw_move(vc, p, t, vc->vc_rows - count, t + count); | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 1527 | 	} | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 1528 |  | 
 | 1529 | 	ops->var.xoffset = 0; | 
 | 1530 | 	ops->var.yoffset = p->yscroll * vc->vc_font.height; | 
 | 1531 | 	ops->var.vmode &= ~FB_VMODE_YWRAP; | 
 | 1532 | 	ops->update_start(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | 	fbcon_clear_margins(vc, 1); | 
 | 1534 | 	scrollback_max -= count; | 
 | 1535 | 	if (scrollback_max < 0) | 
 | 1536 | 		scrollback_max = 0; | 
 | 1537 | 	scrollback_current = 0; | 
 | 1538 | } | 
 | 1539 |  | 
 | 1540 | static void fbcon_redraw_softback(struct vc_data *vc, struct display *p, | 
 | 1541 | 				  long delta) | 
 | 1542 | { | 
 | 1543 | 	int count = vc->vc_rows; | 
 | 1544 | 	unsigned short *d, *s; | 
 | 1545 | 	unsigned long n; | 
 | 1546 | 	int line = 0; | 
 | 1547 |  | 
 | 1548 | 	d = (u16 *) softback_curr; | 
 | 1549 | 	if (d == (u16 *) softback_in) | 
 | 1550 | 		d = (u16 *) vc->vc_origin; | 
 | 1551 | 	n = softback_curr + delta * vc->vc_size_row; | 
 | 1552 | 	softback_lines -= delta; | 
 | 1553 | 	if (delta < 0) { | 
 | 1554 | 		if (softback_curr < softback_top && n < softback_buf) { | 
 | 1555 | 			n += softback_end - softback_buf; | 
 | 1556 | 			if (n < softback_top) { | 
 | 1557 | 				softback_lines -= | 
 | 1558 | 				    (softback_top - n) / vc->vc_size_row; | 
 | 1559 | 				n = softback_top; | 
 | 1560 | 			} | 
 | 1561 | 		} else if (softback_curr >= softback_top | 
 | 1562 | 			   && n < softback_top) { | 
 | 1563 | 			softback_lines -= | 
 | 1564 | 			    (softback_top - n) / vc->vc_size_row; | 
 | 1565 | 			n = softback_top; | 
 | 1566 | 		} | 
 | 1567 | 	} else { | 
 | 1568 | 		if (softback_curr > softback_in && n >= softback_end) { | 
 | 1569 | 			n += softback_buf - softback_end; | 
 | 1570 | 			if (n > softback_in) { | 
 | 1571 | 				n = softback_in; | 
 | 1572 | 				softback_lines = 0; | 
 | 1573 | 			} | 
 | 1574 | 		} else if (softback_curr <= softback_in && n > softback_in) { | 
 | 1575 | 			n = softback_in; | 
 | 1576 | 			softback_lines = 0; | 
 | 1577 | 		} | 
 | 1578 | 	} | 
 | 1579 | 	if (n == softback_curr) | 
 | 1580 | 		return; | 
 | 1581 | 	softback_curr = n; | 
 | 1582 | 	s = (u16 *) softback_curr; | 
 | 1583 | 	if (s == (u16 *) softback_in) | 
 | 1584 | 		s = (u16 *) vc->vc_origin; | 
 | 1585 | 	while (count--) { | 
 | 1586 | 		unsigned short *start; | 
 | 1587 | 		unsigned short *le; | 
 | 1588 | 		unsigned short c; | 
 | 1589 | 		int x = 0; | 
 | 1590 | 		unsigned short attr = 1; | 
 | 1591 |  | 
 | 1592 | 		start = s; | 
 | 1593 | 		le = advance_row(s, 1); | 
 | 1594 | 		do { | 
 | 1595 | 			c = scr_readw(s); | 
 | 1596 | 			if (attr != (c & 0xff00)) { | 
 | 1597 | 				attr = c & 0xff00; | 
 | 1598 | 				if (s > start) { | 
 | 1599 | 					fbcon_putcs(vc, start, s - start, | 
 | 1600 | 						    line, x); | 
 | 1601 | 					x += s - start; | 
 | 1602 | 					start = s; | 
 | 1603 | 				} | 
 | 1604 | 			} | 
 | 1605 | 			if (c == scr_readw(d)) { | 
 | 1606 | 				if (s > start) { | 
 | 1607 | 					fbcon_putcs(vc, start, s - start, | 
 | 1608 | 						    line, x); | 
 | 1609 | 					x += s - start + 1; | 
 | 1610 | 					start = s + 1; | 
 | 1611 | 				} else { | 
 | 1612 | 					x++; | 
 | 1613 | 					start++; | 
 | 1614 | 				} | 
 | 1615 | 			} | 
 | 1616 | 			s++; | 
 | 1617 | 			d++; | 
 | 1618 | 		} while (s < le); | 
 | 1619 | 		if (s > start) | 
 | 1620 | 			fbcon_putcs(vc, start, s - start, line, x); | 
 | 1621 | 		line++; | 
 | 1622 | 		if (d == (u16 *) softback_end) | 
 | 1623 | 			d = (u16 *) softback_buf; | 
 | 1624 | 		if (d == (u16 *) softback_in) | 
 | 1625 | 			d = (u16 *) vc->vc_origin; | 
 | 1626 | 		if (s == (u16 *) softback_end) | 
 | 1627 | 			s = (u16 *) softback_buf; | 
 | 1628 | 		if (s == (u16 *) softback_in) | 
 | 1629 | 			s = (u16 *) vc->vc_origin; | 
 | 1630 | 	} | 
 | 1631 | } | 
 | 1632 |  | 
 | 1633 | static void fbcon_redraw_move(struct vc_data *vc, struct display *p, | 
 | 1634 | 			      int line, int count, int dy) | 
 | 1635 | { | 
 | 1636 | 	unsigned short *s = (unsigned short *) | 
 | 1637 | 		(vc->vc_origin + vc->vc_size_row * line); | 
 | 1638 |  | 
 | 1639 | 	while (count--) { | 
 | 1640 | 		unsigned short *start = s; | 
 | 1641 | 		unsigned short *le = advance_row(s, 1); | 
 | 1642 | 		unsigned short c; | 
 | 1643 | 		int x = 0; | 
 | 1644 | 		unsigned short attr = 1; | 
 | 1645 |  | 
 | 1646 | 		do { | 
 | 1647 | 			c = scr_readw(s); | 
 | 1648 | 			if (attr != (c & 0xff00)) { | 
 | 1649 | 				attr = c & 0xff00; | 
 | 1650 | 				if (s > start) { | 
 | 1651 | 					fbcon_putcs(vc, start, s - start, | 
 | 1652 | 						    dy, x); | 
 | 1653 | 					x += s - start; | 
 | 1654 | 					start = s; | 
 | 1655 | 				} | 
 | 1656 | 			} | 
 | 1657 | 			console_conditional_schedule(); | 
 | 1658 | 			s++; | 
 | 1659 | 		} while (s < le); | 
 | 1660 | 		if (s > start) | 
 | 1661 | 			fbcon_putcs(vc, start, s - start, dy, x); | 
 | 1662 | 		console_conditional_schedule(); | 
 | 1663 | 		dy++; | 
 | 1664 | 	} | 
 | 1665 | } | 
 | 1666 |  | 
 | 1667 | static void fbcon_redraw(struct vc_data *vc, struct display *p, | 
 | 1668 | 			 int line, int count, int offset) | 
 | 1669 | { | 
 | 1670 | 	unsigned short *d = (unsigned short *) | 
 | 1671 | 	    (vc->vc_origin + vc->vc_size_row * line); | 
 | 1672 | 	unsigned short *s = d + offset; | 
 | 1673 |  | 
 | 1674 | 	while (count--) { | 
 | 1675 | 		unsigned short *start = s; | 
 | 1676 | 		unsigned short *le = advance_row(s, 1); | 
 | 1677 | 		unsigned short c; | 
 | 1678 | 		int x = 0; | 
 | 1679 | 		unsigned short attr = 1; | 
 | 1680 |  | 
 | 1681 | 		do { | 
 | 1682 | 			c = scr_readw(s); | 
 | 1683 | 			if (attr != (c & 0xff00)) { | 
 | 1684 | 				attr = c & 0xff00; | 
 | 1685 | 				if (s > start) { | 
 | 1686 | 					fbcon_putcs(vc, start, s - start, | 
 | 1687 | 						    line, x); | 
 | 1688 | 					x += s - start; | 
 | 1689 | 					start = s; | 
 | 1690 | 				} | 
 | 1691 | 			} | 
 | 1692 | 			if (c == scr_readw(d)) { | 
 | 1693 | 				if (s > start) { | 
 | 1694 | 					fbcon_putcs(vc, start, s - start, | 
 | 1695 | 						     line, x); | 
 | 1696 | 					x += s - start + 1; | 
 | 1697 | 					start = s + 1; | 
 | 1698 | 				} else { | 
 | 1699 | 					x++; | 
 | 1700 | 					start++; | 
 | 1701 | 				} | 
 | 1702 | 			} | 
 | 1703 | 			scr_writew(c, d); | 
 | 1704 | 			console_conditional_schedule(); | 
 | 1705 | 			s++; | 
 | 1706 | 			d++; | 
 | 1707 | 		} while (s < le); | 
 | 1708 | 		if (s > start) | 
 | 1709 | 			fbcon_putcs(vc, start, s - start, line, x); | 
 | 1710 | 		console_conditional_schedule(); | 
 | 1711 | 		if (offset > 0) | 
 | 1712 | 			line++; | 
 | 1713 | 		else { | 
 | 1714 | 			line--; | 
 | 1715 | 			/* NOTE: We subtract two lines from these pointers */ | 
 | 1716 | 			s -= vc->vc_size_row; | 
 | 1717 | 			d -= vc->vc_size_row; | 
 | 1718 | 		} | 
 | 1719 | 	} | 
 | 1720 | } | 
 | 1721 |  | 
 | 1722 | static inline void fbcon_softback_note(struct vc_data *vc, int t, | 
 | 1723 | 				       int count) | 
 | 1724 | { | 
 | 1725 | 	unsigned short *p; | 
 | 1726 |  | 
 | 1727 | 	if (vc->vc_num != fg_console) | 
 | 1728 | 		return; | 
 | 1729 | 	p = (unsigned short *) (vc->vc_origin + t * vc->vc_size_row); | 
 | 1730 |  | 
 | 1731 | 	while (count) { | 
 | 1732 | 		scr_memcpyw((u16 *) softback_in, p, vc->vc_size_row); | 
 | 1733 | 		count--; | 
 | 1734 | 		p = advance_row(p, 1); | 
 | 1735 | 		softback_in += vc->vc_size_row; | 
 | 1736 | 		if (softback_in == softback_end) | 
 | 1737 | 			softback_in = softback_buf; | 
 | 1738 | 		if (softback_in == softback_top) { | 
 | 1739 | 			softback_top += vc->vc_size_row; | 
 | 1740 | 			if (softback_top == softback_end) | 
 | 1741 | 				softback_top = softback_buf; | 
 | 1742 | 		} | 
 | 1743 | 	} | 
 | 1744 | 	softback_curr = softback_in; | 
 | 1745 | } | 
 | 1746 |  | 
 | 1747 | static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir, | 
 | 1748 | 			int count) | 
 | 1749 | { | 
 | 1750 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1751 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1752 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1753 | 	int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK; | 
 | 1754 |  | 
 | 1755 | 	if (fbcon_is_inactive(vc, info)) | 
 | 1756 | 		return -EINVAL; | 
 | 1757 |  | 
 | 1758 | 	fbcon_cursor(vc, CM_ERASE); | 
 | 1759 |  | 
 | 1760 | 	/* | 
 | 1761 | 	 * ++Geert: Only use ywrap/ypan if the console is in text mode | 
 | 1762 | 	 * ++Andrew: Only use ypan on hardware text mode when scrolling the | 
 | 1763 | 	 *           whole screen (prevents flicker). | 
 | 1764 | 	 */ | 
 | 1765 |  | 
 | 1766 | 	switch (dir) { | 
 | 1767 | 	case SM_UP: | 
 | 1768 | 		if (count > vc->vc_rows)	/* Maximum realistic size */ | 
 | 1769 | 			count = vc->vc_rows; | 
 | 1770 | 		if (softback_top) | 
 | 1771 | 			fbcon_softback_note(vc, t, count); | 
 | 1772 | 		if (logo_shown >= 0) | 
 | 1773 | 			goto redraw_up; | 
 | 1774 | 		switch (p->scrollmode) { | 
 | 1775 | 		case SCROLL_MOVE: | 
 | 1776 | 			ops->bmove(vc, info, t + count, 0, t, 0, | 
 | 1777 | 				    b - t - count, vc->vc_cols); | 
 | 1778 | 			ops->clear(vc, info, b - count, 0, count, | 
 | 1779 | 				  vc->vc_cols); | 
 | 1780 | 			break; | 
 | 1781 |  | 
 | 1782 | 		case SCROLL_WRAP_MOVE: | 
 | 1783 | 			if (b - t - count > 3 * vc->vc_rows >> 2) { | 
 | 1784 | 				if (t > 0) | 
 | 1785 | 					fbcon_bmove(vc, 0, 0, count, 0, t, | 
 | 1786 | 						    vc->vc_cols); | 
 | 1787 | 				ywrap_up(vc, count); | 
 | 1788 | 				if (vc->vc_rows - b > 0) | 
 | 1789 | 					fbcon_bmove(vc, b - count, 0, b, 0, | 
 | 1790 | 						    vc->vc_rows - b, | 
 | 1791 | 						    vc->vc_cols); | 
 | 1792 | 			} else if (info->flags & FBINFO_READS_FAST) | 
 | 1793 | 				fbcon_bmove(vc, t + count, 0, t, 0, | 
 | 1794 | 					    b - t - count, vc->vc_cols); | 
 | 1795 | 			else | 
 | 1796 | 				goto redraw_up; | 
 | 1797 | 			fbcon_clear(vc, b - count, 0, count, vc->vc_cols); | 
 | 1798 | 			break; | 
 | 1799 |  | 
 | 1800 | 		case SCROLL_PAN_REDRAW: | 
 | 1801 | 			if ((p->yscroll + count <= | 
 | 1802 | 			     2 * (p->vrows - vc->vc_rows)) | 
 | 1803 | 			    && ((!scroll_partial && (b - t == vc->vc_rows)) | 
 | 1804 | 				|| (scroll_partial | 
 | 1805 | 				    && (b - t - count > | 
 | 1806 | 					3 * vc->vc_rows >> 2)))) { | 
 | 1807 | 				if (t > 0) | 
 | 1808 | 					fbcon_redraw_move(vc, p, 0, t, count); | 
 | 1809 | 				ypan_up_redraw(vc, t, count); | 
 | 1810 | 				if (vc->vc_rows - b > 0) | 
| Malcom Parsons | 26e780e | 2006-06-08 00:43:42 -0700 | [diff] [blame] | 1811 | 					fbcon_redraw_move(vc, p, b, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | 							  vc->vc_rows - b, b); | 
 | 1813 | 			} else | 
 | 1814 | 				fbcon_redraw_move(vc, p, t + count, b - t - count, t); | 
 | 1815 | 			fbcon_clear(vc, b - count, 0, count, vc->vc_cols); | 
 | 1816 | 			break; | 
 | 1817 |  | 
 | 1818 | 		case SCROLL_PAN_MOVE: | 
 | 1819 | 			if ((p->yscroll + count <= | 
 | 1820 | 			     2 * (p->vrows - vc->vc_rows)) | 
 | 1821 | 			    && ((!scroll_partial && (b - t == vc->vc_rows)) | 
 | 1822 | 				|| (scroll_partial | 
 | 1823 | 				    && (b - t - count > | 
 | 1824 | 					3 * vc->vc_rows >> 2)))) { | 
 | 1825 | 				if (t > 0) | 
 | 1826 | 					fbcon_bmove(vc, 0, 0, count, 0, t, | 
 | 1827 | 						    vc->vc_cols); | 
 | 1828 | 				ypan_up(vc, count); | 
 | 1829 | 				if (vc->vc_rows - b > 0) | 
 | 1830 | 					fbcon_bmove(vc, b - count, 0, b, 0, | 
 | 1831 | 						    vc->vc_rows - b, | 
 | 1832 | 						    vc->vc_cols); | 
 | 1833 | 			} else if (info->flags & FBINFO_READS_FAST) | 
 | 1834 | 				fbcon_bmove(vc, t + count, 0, t, 0, | 
 | 1835 | 					    b - t - count, vc->vc_cols); | 
 | 1836 | 			else | 
 | 1837 | 				goto redraw_up; | 
 | 1838 | 			fbcon_clear(vc, b - count, 0, count, vc->vc_cols); | 
 | 1839 | 			break; | 
 | 1840 |  | 
 | 1841 | 		case SCROLL_REDRAW: | 
 | 1842 | 		      redraw_up: | 
 | 1843 | 			fbcon_redraw(vc, p, t, b - t - count, | 
 | 1844 | 				     count * vc->vc_cols); | 
 | 1845 | 			fbcon_clear(vc, b - count, 0, count, vc->vc_cols); | 
 | 1846 | 			scr_memsetw((unsigned short *) (vc->vc_origin + | 
 | 1847 | 							vc->vc_size_row * | 
 | 1848 | 							(b - count)), | 
 | 1849 | 				    vc->vc_video_erase_char, | 
 | 1850 | 				    vc->vc_size_row * count); | 
 | 1851 | 			return 1; | 
 | 1852 | 		} | 
 | 1853 | 		break; | 
 | 1854 |  | 
 | 1855 | 	case SM_DOWN: | 
 | 1856 | 		if (count > vc->vc_rows)	/* Maximum realistic size */ | 
 | 1857 | 			count = vc->vc_rows; | 
| Jan Beulich | e703ecc | 2005-09-13 01:25:43 -0700 | [diff] [blame] | 1858 | 		if (logo_shown >= 0) | 
 | 1859 | 			goto redraw_down; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | 		switch (p->scrollmode) { | 
 | 1861 | 		case SCROLL_MOVE: | 
 | 1862 | 			ops->bmove(vc, info, t, 0, t + count, 0, | 
 | 1863 | 				    b - t - count, vc->vc_cols); | 
 | 1864 | 			ops->clear(vc, info, t, 0, count, vc->vc_cols); | 
 | 1865 | 			break; | 
 | 1866 |  | 
 | 1867 | 		case SCROLL_WRAP_MOVE: | 
 | 1868 | 			if (b - t - count > 3 * vc->vc_rows >> 2) { | 
 | 1869 | 				if (vc->vc_rows - b > 0) | 
 | 1870 | 					fbcon_bmove(vc, b, 0, b - count, 0, | 
 | 1871 | 						    vc->vc_rows - b, | 
 | 1872 | 						    vc->vc_cols); | 
 | 1873 | 				ywrap_down(vc, count); | 
 | 1874 | 				if (t > 0) | 
 | 1875 | 					fbcon_bmove(vc, count, 0, 0, 0, t, | 
 | 1876 | 						    vc->vc_cols); | 
 | 1877 | 			} else if (info->flags & FBINFO_READS_FAST) | 
 | 1878 | 				fbcon_bmove(vc, t, 0, t + count, 0, | 
 | 1879 | 					    b - t - count, vc->vc_cols); | 
 | 1880 | 			else | 
 | 1881 | 				goto redraw_down; | 
 | 1882 | 			fbcon_clear(vc, t, 0, count, vc->vc_cols); | 
 | 1883 | 			break; | 
 | 1884 |  | 
 | 1885 | 		case SCROLL_PAN_MOVE: | 
 | 1886 | 			if ((count - p->yscroll <= p->vrows - vc->vc_rows) | 
 | 1887 | 			    && ((!scroll_partial && (b - t == vc->vc_rows)) | 
 | 1888 | 				|| (scroll_partial | 
 | 1889 | 				    && (b - t - count > | 
 | 1890 | 					3 * vc->vc_rows >> 2)))) { | 
 | 1891 | 				if (vc->vc_rows - b > 0) | 
 | 1892 | 					fbcon_bmove(vc, b, 0, b - count, 0, | 
 | 1893 | 						    vc->vc_rows - b, | 
 | 1894 | 						    vc->vc_cols); | 
 | 1895 | 				ypan_down(vc, count); | 
 | 1896 | 				if (t > 0) | 
 | 1897 | 					fbcon_bmove(vc, count, 0, 0, 0, t, | 
 | 1898 | 						    vc->vc_cols); | 
 | 1899 | 			} else if (info->flags & FBINFO_READS_FAST) | 
 | 1900 | 				fbcon_bmove(vc, t, 0, t + count, 0, | 
 | 1901 | 					    b - t - count, vc->vc_cols); | 
 | 1902 | 			else | 
 | 1903 | 				goto redraw_down; | 
 | 1904 | 			fbcon_clear(vc, t, 0, count, vc->vc_cols); | 
 | 1905 | 			break; | 
 | 1906 |  | 
 | 1907 | 		case SCROLL_PAN_REDRAW: | 
 | 1908 | 			if ((count - p->yscroll <= p->vrows - vc->vc_rows) | 
 | 1909 | 			    && ((!scroll_partial && (b - t == vc->vc_rows)) | 
 | 1910 | 				|| (scroll_partial | 
 | 1911 | 				    && (b - t - count > | 
 | 1912 | 					3 * vc->vc_rows >> 2)))) { | 
 | 1913 | 				if (vc->vc_rows - b > 0) | 
 | 1914 | 					fbcon_redraw_move(vc, p, b, vc->vc_rows - b, | 
 | 1915 | 							  b - count); | 
 | 1916 | 				ypan_down_redraw(vc, t, count); | 
 | 1917 | 				if (t > 0) | 
 | 1918 | 					fbcon_redraw_move(vc, p, count, t, 0); | 
 | 1919 | 			} else | 
 | 1920 | 				fbcon_redraw_move(vc, p, t, b - t - count, t + count); | 
 | 1921 | 			fbcon_clear(vc, t, 0, count, vc->vc_cols); | 
 | 1922 | 			break; | 
 | 1923 |  | 
 | 1924 | 		case SCROLL_REDRAW: | 
 | 1925 | 		      redraw_down: | 
 | 1926 | 			fbcon_redraw(vc, p, b - 1, b - t - count, | 
 | 1927 | 				     -count * vc->vc_cols); | 
 | 1928 | 			fbcon_clear(vc, t, 0, count, vc->vc_cols); | 
 | 1929 | 			scr_memsetw((unsigned short *) (vc->vc_origin + | 
 | 1930 | 							vc->vc_size_row * | 
 | 1931 | 							t), | 
 | 1932 | 				    vc->vc_video_erase_char, | 
 | 1933 | 				    vc->vc_size_row * count); | 
 | 1934 | 			return 1; | 
 | 1935 | 		} | 
 | 1936 | 	} | 
 | 1937 | 	return 0; | 
 | 1938 | } | 
 | 1939 |  | 
 | 1940 |  | 
 | 1941 | static void fbcon_bmove(struct vc_data *vc, int sy, int sx, int dy, int dx, | 
 | 1942 | 			int height, int width) | 
 | 1943 | { | 
 | 1944 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1945 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 1946 | 	 | 
 | 1947 | 	if (fbcon_is_inactive(vc, info)) | 
 | 1948 | 		return; | 
 | 1949 |  | 
 | 1950 | 	if (!width || !height) | 
 | 1951 | 		return; | 
 | 1952 |  | 
 | 1953 | 	/*  Split blits that cross physical y_wrap case. | 
 | 1954 | 	 *  Pathological case involves 4 blits, better to use recursive | 
 | 1955 | 	 *  code rather than unrolled case | 
 | 1956 | 	 * | 
 | 1957 | 	 *  Recursive invocations don't need to erase the cursor over and | 
 | 1958 | 	 *  over again, so we use fbcon_bmove_rec() | 
 | 1959 | 	 */ | 
 | 1960 | 	fbcon_bmove_rec(vc, p, sy, sx, dy, dx, height, width, | 
 | 1961 | 			p->vrows - p->yscroll); | 
 | 1962 | } | 
 | 1963 |  | 
 | 1964 | static void fbcon_bmove_rec(struct vc_data *vc, struct display *p, int sy, int sx,  | 
 | 1965 | 			    int dy, int dx, int height, int width, u_int y_break) | 
 | 1966 | { | 
 | 1967 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 1968 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 1969 | 	u_int b; | 
 | 1970 |  | 
 | 1971 | 	if (sy < y_break && sy + height > y_break) { | 
 | 1972 | 		b = y_break - sy; | 
 | 1973 | 		if (dy < sy) {	/* Avoid trashing self */ | 
 | 1974 | 			fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, | 
 | 1975 | 					y_break); | 
 | 1976 | 			fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, | 
 | 1977 | 					height - b, width, y_break); | 
 | 1978 | 		} else { | 
 | 1979 | 			fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, | 
 | 1980 | 					height - b, width, y_break); | 
 | 1981 | 			fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, | 
 | 1982 | 					y_break); | 
 | 1983 | 		} | 
 | 1984 | 		return; | 
 | 1985 | 	} | 
 | 1986 |  | 
 | 1987 | 	if (dy < y_break && dy + height > y_break) { | 
 | 1988 | 		b = y_break - dy; | 
 | 1989 | 		if (dy < sy) {	/* Avoid trashing self */ | 
 | 1990 | 			fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, | 
 | 1991 | 					y_break); | 
 | 1992 | 			fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, | 
 | 1993 | 					height - b, width, y_break); | 
 | 1994 | 		} else { | 
 | 1995 | 			fbcon_bmove_rec(vc, p, sy + b, sx, dy + b, dx, | 
 | 1996 | 					height - b, width, y_break); | 
 | 1997 | 			fbcon_bmove_rec(vc, p, sy, sx, dy, dx, b, width, | 
 | 1998 | 					y_break); | 
 | 1999 | 		} | 
 | 2000 | 		return; | 
 | 2001 | 	} | 
 | 2002 | 	ops->bmove(vc, info, real_y(p, sy), sx, real_y(p, dy), dx, | 
 | 2003 | 		   height, width); | 
 | 2004 | } | 
 | 2005 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2006 | static __inline__ void updatescrollmode(struct display *p, | 
 | 2007 | 					struct fb_info *info, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | 					struct vc_data *vc) | 
 | 2009 | { | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2010 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | 	int fh = vc->vc_font.height; | 
 | 2012 | 	int cap = info->flags; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2013 | 	u16 t = 0; | 
 | 2014 | 	int ypan = FBCON_SWAP(ops->rotate, info->fix.ypanstep, | 
 | 2015 | 				  info->fix.xpanstep); | 
 | 2016 | 	int ywrap = FBCON_SWAP(ops->rotate, info->fix.ywrapstep, t); | 
 | 2017 | 	int yres = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 2018 | 	int vyres = FBCON_SWAP(ops->rotate, info->var.yres_virtual, | 
 | 2019 | 				   info->var.xres_virtual); | 
 | 2020 | 	int good_pan = (cap & FBINFO_HWACCEL_YPAN) && | 
 | 2021 | 		divides(ypan, vc->vc_font.height) && vyres > yres; | 
 | 2022 | 	int good_wrap = (cap & FBINFO_HWACCEL_YWRAP) && | 
 | 2023 | 		divides(ywrap, vc->vc_font.height) && | 
| Knut Petersen | 244ab72 | 2006-01-09 20:53:36 -0800 | [diff] [blame] | 2024 | 		divides(vc->vc_font.height, vyres) && | 
 | 2025 | 		divides(vc->vc_font.height, yres); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | 	int reading_fast = cap & FBINFO_READS_FAST; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2027 | 	int fast_copyarea = (cap & FBINFO_HWACCEL_COPYAREA) && | 
 | 2028 | 		!(cap & FBINFO_HWACCEL_DISABLED); | 
 | 2029 | 	int fast_imageblit = (cap & FBINFO_HWACCEL_IMAGEBLIT) && | 
 | 2030 | 		!(cap & FBINFO_HWACCEL_DISABLED); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2032 | 	p->vrows = vyres/fh; | 
 | 2033 | 	if (yres > (fh * (vc->vc_rows + 1))) | 
 | 2034 | 		p->vrows -= (yres - (fh * vc->vc_rows)) / fh; | 
 | 2035 | 	if ((yres % fh) && (vyres % fh < yres % fh)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | 		p->vrows--; | 
 | 2037 |  | 
 | 2038 | 	if (good_wrap || good_pan) { | 
 | 2039 | 		if (reading_fast || fast_copyarea) | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2040 | 			p->scrollmode = good_wrap ? | 
 | 2041 | 				SCROLL_WRAP_MOVE : SCROLL_PAN_MOVE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | 		else | 
 | 2043 | 			p->scrollmode = good_wrap ? SCROLL_REDRAW : | 
 | 2044 | 				SCROLL_PAN_REDRAW; | 
 | 2045 | 	} else { | 
 | 2046 | 		if (reading_fast || (fast_copyarea && !fast_imageblit)) | 
 | 2047 | 			p->scrollmode = SCROLL_MOVE; | 
 | 2048 | 		else | 
 | 2049 | 			p->scrollmode = SCROLL_REDRAW; | 
 | 2050 | 	} | 
 | 2051 | } | 
 | 2052 |  | 
 | 2053 | static int fbcon_resize(struct vc_data *vc, unsigned int width,  | 
 | 2054 | 			unsigned int height) | 
 | 2055 | { | 
 | 2056 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2057 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 2059 | 	struct fb_var_screeninfo var = info->var; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2060 | 	int x_diff, y_diff, virt_w, virt_h, virt_fw, virt_fh; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2062 | 	virt_w = FBCON_SWAP(ops->rotate, width, height); | 
 | 2063 | 	virt_h = FBCON_SWAP(ops->rotate, height, width); | 
 | 2064 | 	virt_fw = FBCON_SWAP(ops->rotate, vc->vc_font.width, | 
 | 2065 | 				 vc->vc_font.height); | 
 | 2066 | 	virt_fh = FBCON_SWAP(ops->rotate, vc->vc_font.height, | 
 | 2067 | 				 vc->vc_font.width); | 
 | 2068 | 	var.xres = virt_w * virt_fw; | 
 | 2069 | 	var.yres = virt_h * virt_fh; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | 	x_diff = info->var.xres - var.xres; | 
 | 2071 | 	y_diff = info->var.yres - var.yres; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2072 | 	if (x_diff < 0 || x_diff > virt_fw || | 
 | 2073 | 	    y_diff < 0 || y_diff > virt_fh) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | 		struct fb_videomode *mode; | 
 | 2075 |  | 
 | 2076 | 		DPRINTK("attempting resize %ix%i\n", var.xres, var.yres); | 
 | 2077 | 		mode = fb_find_best_mode(&var, &info->modelist); | 
 | 2078 | 		if (mode == NULL) | 
 | 2079 | 			return -EINVAL; | 
| Antonino A. Daplas | 3084a89 | 2005-11-07 01:00:37 -0800 | [diff] [blame] | 2080 | 		display_to_var(&var, p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | 		fb_videomode_to_var(&var, mode); | 
| Antonino A. Daplas | 3084a89 | 2005-11-07 01:00:37 -0800 | [diff] [blame] | 2082 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2083 | 		if (virt_w > var.xres/virt_fw || virt_h > var.yres/virt_fh) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | 			return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 |  | 
 | 2086 | 		DPRINTK("resize now %ix%i\n", var.xres, var.yres); | 
 | 2087 | 		if (CON_IS_VISIBLE(vc)) { | 
 | 2088 | 			var.activate = FB_ACTIVATE_NOW | | 
 | 2089 | 				FB_ACTIVATE_FORCE; | 
 | 2090 | 			fb_set_var(info, &var); | 
 | 2091 | 		} | 
 | 2092 | 		var_to_display(p, &info->var, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2093 | 		ops->var = info->var; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | 	} | 
 | 2095 | 	updatescrollmode(p, info, vc); | 
 | 2096 | 	return 0; | 
 | 2097 | } | 
 | 2098 |  | 
 | 2099 | static int fbcon_switch(struct vc_data *vc) | 
 | 2100 | { | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2101 | 	struct fb_info *info, *old_info = NULL; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2102 | 	struct fbcon_ops *ops; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 2104 | 	struct fb_var_screeninfo var; | 
| Antonino A. Daplas | 56f0d64 | 2005-12-12 22:17:15 -0800 | [diff] [blame] | 2105 | 	int i, prev_console, charcnt = 256; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 |  | 
 | 2107 | 	info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2108 | 	ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 |  | 
 | 2110 | 	if (softback_top) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | 		if (softback_lines) | 
 | 2112 | 			fbcon_set_origin(vc); | 
 | 2113 | 		softback_top = softback_curr = softback_in = softback_buf; | 
 | 2114 | 		softback_lines = 0; | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 2115 | 		fbcon_update_softback(vc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | 	} | 
 | 2117 |  | 
 | 2118 | 	if (logo_shown >= 0) { | 
 | 2119 | 		struct vc_data *conp2 = vc_cons[logo_shown].d; | 
 | 2120 |  | 
 | 2121 | 		if (conp2->vc_top == logo_lines | 
 | 2122 | 		    && conp2->vc_bottom == conp2->vc_rows) | 
 | 2123 | 			conp2->vc_top = 0; | 
 | 2124 | 		logo_shown = FBCON_LOGO_CANSHOW; | 
 | 2125 | 	} | 
 | 2126 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2127 | 	prev_console = ops->currcon; | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2128 | 	if (prev_console != -1) | 
 | 2129 | 		old_info = registered_fb[con2fb_map[prev_console]]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | 	/* | 
 | 2131 | 	 * FIXME: If we have multiple fbdev's loaded, we need to | 
 | 2132 | 	 * update all info->currcon.  Perhaps, we can place this | 
 | 2133 | 	 * in a centralized structure, but this might break some | 
 | 2134 | 	 * drivers. | 
 | 2135 | 	 * | 
 | 2136 | 	 * info->currcon = vc->vc_num; | 
 | 2137 | 	 */ | 
 | 2138 | 	for (i = 0; i < FB_MAX; i++) { | 
 | 2139 | 		if (registered_fb[i] != NULL && registered_fb[i]->fbcon_par) { | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2140 | 			struct fbcon_ops *o = registered_fb[i]->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 |  | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2142 | 			o->currcon = vc->vc_num; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | 		} | 
 | 2144 | 	} | 
 | 2145 | 	memset(&var, 0, sizeof(struct fb_var_screeninfo)); | 
 | 2146 | 	display_to_var(&var, p); | 
 | 2147 | 	var.activate = FB_ACTIVATE_NOW; | 
 | 2148 |  | 
 | 2149 | 	/* | 
 | 2150 | 	 * make sure we don't unnecessarily trip the memcmp() | 
 | 2151 | 	 * in fb_set_var() | 
 | 2152 | 	 */ | 
 | 2153 | 	info->var.activate = var.activate; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2154 | 	var.yoffset = info->var.yoffset; | 
 | 2155 | 	var.xoffset = info->var.xoffset; | 
 | 2156 | 	var.vmode = info->var.vmode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | 	fb_set_var(info, &var); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2158 | 	ops->var = info->var; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 |  | 
| Knut Petersen | 39942fd | 2005-12-12 22:17:19 -0800 | [diff] [blame] | 2160 | 	if (old_info != NULL && (old_info != info || | 
 | 2161 | 				 info->flags & FBINFO_MISC_ALWAYS_SETPAR)) { | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2162 | 		if (info->fbops->fb_set_par) | 
 | 2163 | 			info->fbops->fb_set_par(info); | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 2164 |  | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 2165 | 		if (old_info != info) | 
| Antonino A. Daplas | a39bc34 | 2006-01-09 20:53:44 -0800 | [diff] [blame] | 2166 | 			fbcon_del_cursor_timer(old_info); | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2167 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 |  | 
| Antonino A. Daplas | 212f263 | 2006-10-03 01:14:48 -0700 | [diff] [blame] | 2169 | 	if (fbcon_is_inactive(vc, info) || | 
 | 2170 | 	    ops->blank_state != FB_BLANK_UNBLANK) | 
 | 2171 | 		fbcon_del_cursor_timer(info); | 
 | 2172 | 	else | 
 | 2173 | 		fbcon_add_cursor_timer(info); | 
 | 2174 |  | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 2175 | 	set_blitting_type(vc, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2176 | 	ops->cursor_reset = 1; | 
 | 2177 |  | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 2178 | 	if (ops->rotate_font && ops->rotate_font(info, vc)) { | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2179 | 		ops->rotate = FB_ROTATE_UR; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 2180 | 		set_blitting_type(vc, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2181 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 |  | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 2183 | 	vc->vc_can_do_color = (fb_get_color_depth(&info->var, &info->fix)!=1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | 	vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800; | 
| Antonino A. Daplas | 56f0d64 | 2005-12-12 22:17:15 -0800 | [diff] [blame] | 2185 |  | 
 | 2186 | 	if (p->userfont) | 
 | 2187 | 		charcnt = FNTCHARCNT(vc->vc_font.data); | 
 | 2188 |  | 
 | 2189 | 	if (charcnt > 256) | 
 | 2190 | 		vc->vc_complement_mask <<= 1; | 
 | 2191 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | 	updatescrollmode(p, info, vc); | 
 | 2193 |  | 
 | 2194 | 	switch (p->scrollmode) { | 
 | 2195 | 	case SCROLL_WRAP_MOVE: | 
 | 2196 | 		scrollback_phys_max = p->vrows - vc->vc_rows; | 
 | 2197 | 		break; | 
 | 2198 | 	case SCROLL_PAN_MOVE: | 
 | 2199 | 	case SCROLL_PAN_REDRAW: | 
 | 2200 | 		scrollback_phys_max = p->vrows - 2 * vc->vc_rows; | 
 | 2201 | 		if (scrollback_phys_max < 0) | 
 | 2202 | 			scrollback_phys_max = 0; | 
 | 2203 | 		break; | 
 | 2204 | 	default: | 
 | 2205 | 		scrollback_phys_max = 0; | 
 | 2206 | 		break; | 
 | 2207 | 	} | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2208 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | 	scrollback_max = 0; | 
 | 2210 | 	scrollback_current = 0; | 
| Antonino A. Daplas | 4e1567d | 2005-12-12 22:17:18 -0800 | [diff] [blame] | 2211 |  | 
 | 2212 | 	if (!fbcon_is_inactive(vc, info)) { | 
 | 2213 | 	    ops->var.xoffset = ops->var.yoffset = p->yscroll = 0; | 
 | 2214 | 	    ops->update_start(info); | 
 | 2215 | 	} | 
 | 2216 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | 	fbcon_set_palette(vc, color_table); 	 | 
 | 2218 | 	fbcon_clear_margins(vc, 0); | 
 | 2219 |  | 
 | 2220 | 	if (logo_shown == FBCON_LOGO_DRAW) { | 
 | 2221 |  | 
 | 2222 | 		logo_shown = fg_console; | 
 | 2223 | 		/* This is protected above by initmem_freed */ | 
| Antonino A. Daplas | 9c44e5f | 2005-11-08 21:39:10 -0800 | [diff] [blame] | 2224 | 		fb_show_logo(info, ops->rotate); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | 		update_region(vc, | 
 | 2226 | 			      vc->vc_origin + vc->vc_size_row * vc->vc_top, | 
 | 2227 | 			      vc->vc_size_row * (vc->vc_bottom - | 
 | 2228 | 						 vc->vc_top) / 2); | 
 | 2229 | 		return 0; | 
 | 2230 | 	} | 
 | 2231 | 	return 1; | 
 | 2232 | } | 
 | 2233 |  | 
 | 2234 | static void fbcon_generic_blank(struct vc_data *vc, struct fb_info *info, | 
 | 2235 | 				int blank) | 
 | 2236 | { | 
 | 2237 | 	if (blank) { | 
 | 2238 | 		unsigned short charmask = vc->vc_hi_font_mask ? | 
 | 2239 | 			0x1ff : 0xff; | 
 | 2240 | 		unsigned short oldc; | 
 | 2241 |  | 
 | 2242 | 		oldc = vc->vc_video_erase_char; | 
 | 2243 | 		vc->vc_video_erase_char &= charmask; | 
 | 2244 | 		fbcon_clear(vc, 0, 0, vc->vc_rows, vc->vc_cols); | 
 | 2245 | 		vc->vc_video_erase_char = oldc; | 
 | 2246 | 	} | 
 | 2247 | } | 
 | 2248 |  | 
 | 2249 | static int fbcon_blank(struct vc_data *vc, int blank, int mode_switch) | 
 | 2250 | { | 
 | 2251 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 2252 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 2253 |  | 
 | 2254 | 	if (mode_switch) { | 
 | 2255 | 		struct fb_var_screeninfo var = info->var; | 
 | 2256 |  | 
 | 2257 | 		ops->graphics = 1; | 
 | 2258 |  | 
 | 2259 | 		if (!blank) { | 
| Antonino A. Daplas | 4743484 | 2005-12-12 22:17:16 -0800 | [diff] [blame] | 2260 | 			if (info->fbops->fb_save_state) | 
 | 2261 | 				info->fbops->fb_save_state(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2262 | 			var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE; | 
 | 2263 | 			fb_set_var(info, &var); | 
 | 2264 | 			ops->graphics = 0; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2265 | 			ops->var = info->var; | 
| Antonino A. Daplas | 4743484 | 2005-12-12 22:17:16 -0800 | [diff] [blame] | 2266 | 		} else if (info->fbops->fb_restore_state) | 
 | 2267 | 			info->fbops->fb_restore_state(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | 	} | 
 | 2269 |  | 
 | 2270 |  	if (!fbcon_is_inactive(vc, info)) { | 
 | 2271 | 		if (ops->blank_state != blank) { | 
 | 2272 | 			ops->blank_state = blank; | 
 | 2273 | 			fbcon_cursor(vc, blank ? CM_ERASE : CM_DRAW); | 
 | 2274 | 			ops->cursor_flash = (!blank); | 
 | 2275 |  | 
 | 2276 | 			if (fb_blank(info, blank)) | 
 | 2277 | 				fbcon_generic_blank(vc, info, blank); | 
 | 2278 | 		} | 
 | 2279 |  | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2280 | 		if (!blank) | 
 | 2281 | 			update_screen(vc); | 
 | 2282 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 |  | 
| Antonino A. Daplas | 212f263 | 2006-10-03 01:14:48 -0700 | [diff] [blame] | 2284 | 	if (fbcon_is_inactive(vc, info) || | 
 | 2285 | 	    ops->blank_state != FB_BLANK_UNBLANK) | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2286 | 		fbcon_del_cursor_timer(info); | 
| Antonino A. Daplas | 212f263 | 2006-10-03 01:14:48 -0700 | [diff] [blame] | 2287 | 	else | 
 | 2288 | 		fbcon_add_cursor_timer(info); | 
| Antonino A. Daplas | 88fb2c6 | 2005-09-09 13:10:00 -0700 | [diff] [blame] | 2289 |  | 
 | 2290 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | } | 
 | 2292 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | static int fbcon_get_font(struct vc_data *vc, struct console_font *font) | 
 | 2294 | { | 
 | 2295 | 	u8 *fontdata = vc->vc_font.data; | 
 | 2296 | 	u8 *data = font->data; | 
 | 2297 | 	int i, j; | 
 | 2298 |  | 
 | 2299 | 	font->width = vc->vc_font.width; | 
 | 2300 | 	font->height = vc->vc_font.height; | 
 | 2301 | 	font->charcount = vc->vc_hi_font_mask ? 512 : 256; | 
 | 2302 | 	if (!font->data) | 
 | 2303 | 		return 0; | 
 | 2304 |  | 
 | 2305 | 	if (font->width <= 8) { | 
 | 2306 | 		j = vc->vc_font.height; | 
 | 2307 | 		for (i = 0; i < font->charcount; i++) { | 
 | 2308 | 			memcpy(data, fontdata, j); | 
 | 2309 | 			memset(data + j, 0, 32 - j); | 
 | 2310 | 			data += 32; | 
 | 2311 | 			fontdata += j; | 
 | 2312 | 		} | 
 | 2313 | 	} else if (font->width <= 16) { | 
 | 2314 | 		j = vc->vc_font.height * 2; | 
 | 2315 | 		for (i = 0; i < font->charcount; i++) { | 
 | 2316 | 			memcpy(data, fontdata, j); | 
 | 2317 | 			memset(data + j, 0, 64 - j); | 
 | 2318 | 			data += 64; | 
 | 2319 | 			fontdata += j; | 
 | 2320 | 		} | 
 | 2321 | 	} else if (font->width <= 24) { | 
 | 2322 | 		for (i = 0; i < font->charcount; i++) { | 
 | 2323 | 			for (j = 0; j < vc->vc_font.height; j++) { | 
 | 2324 | 				*data++ = fontdata[0]; | 
 | 2325 | 				*data++ = fontdata[1]; | 
 | 2326 | 				*data++ = fontdata[2]; | 
 | 2327 | 				fontdata += sizeof(u32); | 
 | 2328 | 			} | 
 | 2329 | 			memset(data, 0, 3 * (32 - j)); | 
 | 2330 | 			data += 3 * (32 - j); | 
 | 2331 | 		} | 
 | 2332 | 	} else { | 
 | 2333 | 		j = vc->vc_font.height * 4; | 
 | 2334 | 		for (i = 0; i < font->charcount; i++) { | 
 | 2335 | 			memcpy(data, fontdata, j); | 
 | 2336 | 			memset(data + j, 0, 128 - j); | 
 | 2337 | 			data += 128; | 
 | 2338 | 			fontdata += j; | 
 | 2339 | 		} | 
 | 2340 | 	} | 
 | 2341 | 	return 0; | 
 | 2342 | } | 
 | 2343 |  | 
 | 2344 | static int fbcon_do_set_font(struct vc_data *vc, int w, int h, | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 2345 | 			     const u8 * data, int userfont) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | { | 
 | 2347 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2348 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | 	struct display *p = &fb_display[vc->vc_num]; | 
 | 2350 | 	int resize; | 
 | 2351 | 	int cnt; | 
 | 2352 | 	char *old_data = NULL; | 
 | 2353 |  | 
 | 2354 | 	if (CON_IS_VISIBLE(vc) && softback_lines) | 
 | 2355 | 		fbcon_set_origin(vc); | 
 | 2356 |  | 
 | 2357 | 	resize = (w != vc->vc_font.width) || (h != vc->vc_font.height); | 
 | 2358 | 	if (p->userfont) | 
 | 2359 | 		old_data = vc->vc_font.data; | 
 | 2360 | 	if (userfont) | 
 | 2361 | 		cnt = FNTCHARCNT(data); | 
 | 2362 | 	else | 
 | 2363 | 		cnt = 256; | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 2364 | 	vc->vc_font.data = (void *)(p->fontdata = data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | 	if ((p->userfont = userfont)) | 
 | 2366 | 		REFCOUNT(data)++; | 
 | 2367 | 	vc->vc_font.width = w; | 
 | 2368 | 	vc->vc_font.height = h; | 
 | 2369 | 	if (vc->vc_hi_font_mask && cnt == 256) { | 
 | 2370 | 		vc->vc_hi_font_mask = 0; | 
 | 2371 | 		if (vc->vc_can_do_color) { | 
 | 2372 | 			vc->vc_complement_mask >>= 1; | 
 | 2373 | 			vc->vc_s_complement_mask >>= 1; | 
 | 2374 | 		} | 
 | 2375 | 			 | 
 | 2376 | 		/* ++Edmund: reorder the attribute bits */ | 
 | 2377 | 		if (vc->vc_can_do_color) { | 
 | 2378 | 			unsigned short *cp = | 
 | 2379 | 			    (unsigned short *) vc->vc_origin; | 
 | 2380 | 			int count = vc->vc_screenbuf_size / 2; | 
 | 2381 | 			unsigned short c; | 
 | 2382 | 			for (; count > 0; count--, cp++) { | 
 | 2383 | 				c = scr_readw(cp); | 
 | 2384 | 				scr_writew(((c & 0xfe00) >> 1) | | 
 | 2385 | 					   (c & 0xff), cp); | 
 | 2386 | 			} | 
 | 2387 | 			c = vc->vc_video_erase_char; | 
 | 2388 | 			vc->vc_video_erase_char = | 
 | 2389 | 			    ((c & 0xfe00) >> 1) | (c & 0xff); | 
 | 2390 | 			vc->vc_attr >>= 1; | 
 | 2391 | 		} | 
 | 2392 | 	} else if (!vc->vc_hi_font_mask && cnt == 512) { | 
 | 2393 | 		vc->vc_hi_font_mask = 0x100; | 
 | 2394 | 		if (vc->vc_can_do_color) { | 
 | 2395 | 			vc->vc_complement_mask <<= 1; | 
 | 2396 | 			vc->vc_s_complement_mask <<= 1; | 
 | 2397 | 		} | 
 | 2398 | 			 | 
 | 2399 | 		/* ++Edmund: reorder the attribute bits */ | 
 | 2400 | 		{ | 
 | 2401 | 			unsigned short *cp = | 
 | 2402 | 			    (unsigned short *) vc->vc_origin; | 
 | 2403 | 			int count = vc->vc_screenbuf_size / 2; | 
 | 2404 | 			unsigned short c; | 
 | 2405 | 			for (; count > 0; count--, cp++) { | 
 | 2406 | 				unsigned short newc; | 
 | 2407 | 				c = scr_readw(cp); | 
 | 2408 | 				if (vc->vc_can_do_color) | 
 | 2409 | 					newc = | 
 | 2410 | 					    ((c & 0xff00) << 1) | (c & | 
 | 2411 | 								   0xff); | 
 | 2412 | 				else | 
 | 2413 | 					newc = c & ~0x100; | 
 | 2414 | 				scr_writew(newc, cp); | 
 | 2415 | 			} | 
 | 2416 | 			c = vc->vc_video_erase_char; | 
 | 2417 | 			if (vc->vc_can_do_color) { | 
 | 2418 | 				vc->vc_video_erase_char = | 
 | 2419 | 				    ((c & 0xff00) << 1) | (c & 0xff); | 
 | 2420 | 				vc->vc_attr <<= 1; | 
 | 2421 | 			} else | 
 | 2422 | 				vc->vc_video_erase_char = c & ~0x100; | 
 | 2423 | 		} | 
 | 2424 |  | 
 | 2425 | 	} | 
 | 2426 |  | 
 | 2427 | 	if (resize) { | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2428 | 		int cols, rows; | 
 | 2429 |  | 
 | 2430 | 		cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); | 
 | 2431 | 		rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 2432 | 		cols /= w; | 
 | 2433 | 		rows /= h; | 
 | 2434 | 		vc_resize(vc, cols, rows); | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 2435 | 		if (CON_IS_VISIBLE(vc) && softback_buf) | 
 | 2436 | 			fbcon_update_softback(vc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | 	} else if (CON_IS_VISIBLE(vc) | 
 | 2438 | 		   && vc->vc_mode == KD_TEXT) { | 
 | 2439 | 		fbcon_clear_margins(vc, 0); | 
 | 2440 | 		update_screen(vc); | 
 | 2441 | 	} | 
 | 2442 |  | 
 | 2443 | 	if (old_data && (--REFCOUNT(old_data) == 0)) | 
 | 2444 | 		kfree(old_data - FONT_EXTRA_WORDS * sizeof(int)); | 
 | 2445 | 	return 0; | 
 | 2446 | } | 
 | 2447 |  | 
 | 2448 | static int fbcon_copy_font(struct vc_data *vc, int con) | 
 | 2449 | { | 
 | 2450 | 	struct display *od = &fb_display[con]; | 
 | 2451 | 	struct console_font *f = &vc->vc_font; | 
 | 2452 |  | 
 | 2453 | 	if (od->fontdata == f->data) | 
 | 2454 | 		return 0;	/* already the same font... */ | 
 | 2455 | 	return fbcon_do_set_font(vc, f->width, f->height, od->fontdata, od->userfont); | 
 | 2456 | } | 
 | 2457 |  | 
 | 2458 | /* | 
 | 2459 |  *  User asked to set font; we are guaranteed that | 
 | 2460 |  *	a) width and height are in range 1..32 | 
 | 2461 |  *	b) charcount does not exceed 512 | 
 | 2462 |  *  but lets not assume that, since someone might someday want to use larger | 
 | 2463 |  *  fonts. And charcount of 512 is small for unicode support. | 
 | 2464 |  * | 
 | 2465 |  *  However, user space gives the font in 32 rows , regardless of | 
 | 2466 |  *  actual font height. So a new API is needed if support for larger fonts | 
 | 2467 |  *  is ever implemented. | 
 | 2468 |  */ | 
 | 2469 |  | 
 | 2470 | static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags) | 
 | 2471 | { | 
 | 2472 | 	unsigned charcount = font->charcount; | 
 | 2473 | 	int w = font->width; | 
 | 2474 | 	int h = font->height; | 
 | 2475 | 	int size; | 
 | 2476 | 	int i, csum; | 
 | 2477 | 	u8 *new_data, *data = font->data; | 
 | 2478 | 	int pitch = (font->width+7) >> 3; | 
 | 2479 |  | 
 | 2480 | 	/* Is there a reason why fbconsole couldn't handle any charcount >256? | 
 | 2481 | 	 * If not this check should be changed to charcount < 256 */ | 
 | 2482 | 	if (charcount != 256 && charcount != 512) | 
 | 2483 | 		return -EINVAL; | 
 | 2484 |  | 
 | 2485 | 	size = h * pitch * charcount; | 
 | 2486 |  | 
 | 2487 | 	new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER); | 
 | 2488 |  | 
 | 2489 | 	if (!new_data) | 
 | 2490 | 		return -ENOMEM; | 
 | 2491 |  | 
 | 2492 | 	new_data += FONT_EXTRA_WORDS * sizeof(int); | 
 | 2493 | 	FNTSIZE(new_data) = size; | 
 | 2494 | 	FNTCHARCNT(new_data) = charcount; | 
 | 2495 | 	REFCOUNT(new_data) = 0;	/* usage counter */ | 
 | 2496 | 	for (i=0; i< charcount; i++) { | 
 | 2497 | 		memcpy(new_data + i*h*pitch, data +  i*32*pitch, h*pitch); | 
 | 2498 | 	} | 
 | 2499 |  | 
 | 2500 | 	/* Since linux has a nice crc32 function use it for counting font | 
 | 2501 | 	 * checksums. */ | 
 | 2502 | 	csum = crc32(0, new_data, size); | 
 | 2503 |  | 
 | 2504 | 	FNTSUM(new_data) = csum; | 
 | 2505 | 	/* Check if the same font is on some other console already */ | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2506 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | 		struct vc_data *tmp = vc_cons[i].d; | 
 | 2508 | 		 | 
 | 2509 | 		if (fb_display[i].userfont && | 
 | 2510 | 		    fb_display[i].fontdata && | 
 | 2511 | 		    FNTSUM(fb_display[i].fontdata) == csum && | 
 | 2512 | 		    FNTSIZE(fb_display[i].fontdata) == size && | 
 | 2513 | 		    tmp->vc_font.width == w && | 
 | 2514 | 		    !memcmp(fb_display[i].fontdata, new_data, size)) { | 
 | 2515 | 			kfree(new_data - FONT_EXTRA_WORDS * sizeof(int)); | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 2516 | 			new_data = (u8 *)fb_display[i].fontdata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | 			break; | 
 | 2518 | 		} | 
 | 2519 | 	} | 
 | 2520 | 	return fbcon_do_set_font(vc, font->width, font->height, new_data, 1); | 
 | 2521 | } | 
 | 2522 |  | 
 | 2523 | static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, char *name) | 
 | 2524 | { | 
 | 2525 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
| Jan Beulich | 2f4516d | 2005-09-13 01:25:44 -0700 | [diff] [blame] | 2526 | 	const struct font_desc *f; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 |  | 
 | 2528 | 	if (!name) | 
 | 2529 | 		f = get_default_font(info->var.xres, info->var.yres); | 
 | 2530 | 	else if (!(f = find_font(name))) | 
 | 2531 | 		return -ENOENT; | 
 | 2532 |  | 
 | 2533 | 	font->width = f->width; | 
 | 2534 | 	font->height = f->height; | 
 | 2535 | 	return fbcon_do_set_font(vc, f->width, f->height, f->data, 0); | 
 | 2536 | } | 
 | 2537 |  | 
 | 2538 | static u16 palette_red[16]; | 
 | 2539 | static u16 palette_green[16]; | 
 | 2540 | static u16 palette_blue[16]; | 
 | 2541 |  | 
 | 2542 | static struct fb_cmap palette_cmap = { | 
 | 2543 | 	0, 16, palette_red, palette_green, palette_blue, NULL | 
 | 2544 | }; | 
 | 2545 |  | 
 | 2546 | static int fbcon_set_palette(struct vc_data *vc, unsigned char *table) | 
 | 2547 | { | 
 | 2548 | 	struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; | 
 | 2549 | 	int i, j, k, depth; | 
 | 2550 | 	u8 val; | 
 | 2551 |  | 
 | 2552 | 	if (fbcon_is_inactive(vc, info)) | 
 | 2553 | 		return -EINVAL; | 
 | 2554 |  | 
 | 2555 | 	if (!CON_IS_VISIBLE(vc)) | 
 | 2556 | 		return 0; | 
 | 2557 |  | 
| Antonino A. Daplas | b8c9094 | 2005-09-09 13:04:37 -0700 | [diff] [blame] | 2558 | 	depth = fb_get_color_depth(&info->var, &info->fix); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | 	if (depth > 3) { | 
 | 2560 | 		for (i = j = 0; i < 16; i++) { | 
 | 2561 | 			k = table[i]; | 
 | 2562 | 			val = vc->vc_palette[j++]; | 
 | 2563 | 			palette_red[k] = (val << 8) | val; | 
 | 2564 | 			val = vc->vc_palette[j++]; | 
 | 2565 | 			palette_green[k] = (val << 8) | val; | 
 | 2566 | 			val = vc->vc_palette[j++]; | 
 | 2567 | 			palette_blue[k] = (val << 8) | val; | 
 | 2568 | 		} | 
 | 2569 | 		palette_cmap.len = 16; | 
 | 2570 | 		palette_cmap.start = 0; | 
 | 2571 | 	/* | 
 | 2572 | 	 * If framebuffer is capable of less than 16 colors, | 
 | 2573 | 	 * use default palette of fbcon. | 
 | 2574 | 	 */ | 
 | 2575 | 	} else | 
 | 2576 | 		fb_copy_cmap(fb_default_cmap(1 << depth), &palette_cmap); | 
 | 2577 |  | 
 | 2578 | 	return fb_set_cmap(&palette_cmap, info); | 
 | 2579 | } | 
 | 2580 |  | 
 | 2581 | static u16 *fbcon_screen_pos(struct vc_data *vc, int offset) | 
 | 2582 | { | 
 | 2583 | 	unsigned long p; | 
 | 2584 | 	int line; | 
 | 2585 | 	 | 
 | 2586 | 	if (vc->vc_num != fg_console || !softback_lines) | 
 | 2587 | 		return (u16 *) (vc->vc_origin + offset); | 
 | 2588 | 	line = offset / vc->vc_size_row; | 
 | 2589 | 	if (line >= softback_lines) | 
 | 2590 | 		return (u16 *) (vc->vc_origin + offset - | 
 | 2591 | 				softback_lines * vc->vc_size_row); | 
 | 2592 | 	p = softback_curr + offset; | 
 | 2593 | 	if (p >= softback_end) | 
 | 2594 | 		p += softback_buf - softback_end; | 
 | 2595 | 	return (u16 *) p; | 
 | 2596 | } | 
 | 2597 |  | 
 | 2598 | static unsigned long fbcon_getxy(struct vc_data *vc, unsigned long pos, | 
 | 2599 | 				 int *px, int *py) | 
 | 2600 | { | 
 | 2601 | 	unsigned long ret; | 
 | 2602 | 	int x, y; | 
 | 2603 |  | 
 | 2604 | 	if (pos >= vc->vc_origin && pos < vc->vc_scr_end) { | 
 | 2605 | 		unsigned long offset = (pos - vc->vc_origin) / 2; | 
 | 2606 |  | 
 | 2607 | 		x = offset % vc->vc_cols; | 
 | 2608 | 		y = offset / vc->vc_cols; | 
 | 2609 | 		if (vc->vc_num == fg_console) | 
 | 2610 | 			y += softback_lines; | 
 | 2611 | 		ret = pos + (vc->vc_cols - x) * 2; | 
 | 2612 | 	} else if (vc->vc_num == fg_console && softback_lines) { | 
 | 2613 | 		unsigned long offset = pos - softback_curr; | 
 | 2614 |  | 
 | 2615 | 		if (pos < softback_curr) | 
 | 2616 | 			offset += softback_end - softback_buf; | 
 | 2617 | 		offset /= 2; | 
 | 2618 | 		x = offset % vc->vc_cols; | 
 | 2619 | 		y = offset / vc->vc_cols; | 
 | 2620 | 		ret = pos + (vc->vc_cols - x) * 2; | 
 | 2621 | 		if (ret == softback_end) | 
 | 2622 | 			ret = softback_buf; | 
 | 2623 | 		if (ret == softback_in) | 
 | 2624 | 			ret = vc->vc_origin; | 
 | 2625 | 	} else { | 
 | 2626 | 		/* Should not happen */ | 
 | 2627 | 		x = y = 0; | 
 | 2628 | 		ret = vc->vc_origin; | 
 | 2629 | 	} | 
 | 2630 | 	if (px) | 
 | 2631 | 		*px = x; | 
 | 2632 | 	if (py) | 
 | 2633 | 		*py = y; | 
 | 2634 | 	return ret; | 
 | 2635 | } | 
 | 2636 |  | 
 | 2637 | /* As we might be inside of softback, we may work with non-contiguous buffer, | 
 | 2638 |    that's why we have to use a separate routine. */ | 
 | 2639 | static void fbcon_invert_region(struct vc_data *vc, u16 * p, int cnt) | 
 | 2640 | { | 
 | 2641 | 	while (cnt--) { | 
 | 2642 | 		u16 a = scr_readw(p); | 
 | 2643 | 		if (!vc->vc_can_do_color) | 
 | 2644 | 			a ^= 0x0800; | 
 | 2645 | 		else if (vc->vc_hi_font_mask == 0x100) | 
 | 2646 | 			a = ((a) & 0x11ff) | (((a) & 0xe000) >> 4) | | 
 | 2647 | 			    (((a) & 0x0e00) << 4); | 
 | 2648 | 		else | 
 | 2649 | 			a = ((a) & 0x88ff) | (((a) & 0x7000) >> 4) | | 
 | 2650 | 			    (((a) & 0x0700) << 4); | 
 | 2651 | 		scr_writew(a, p++); | 
 | 2652 | 		if (p == (u16 *) softback_end) | 
 | 2653 | 			p = (u16 *) softback_buf; | 
 | 2654 | 		if (p == (u16 *) softback_in) | 
 | 2655 | 			p = (u16 *) vc->vc_origin; | 
 | 2656 | 	} | 
 | 2657 | } | 
 | 2658 |  | 
 | 2659 | static int fbcon_scrolldelta(struct vc_data *vc, int lines) | 
 | 2660 | { | 
 | 2661 | 	struct fb_info *info = registered_fb[con2fb_map[fg_console]]; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2662 | 	struct fbcon_ops *ops = info->fbcon_par; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | 	struct display *p = &fb_display[fg_console]; | 
 | 2664 | 	int offset, limit, scrollback_old; | 
 | 2665 |  | 
 | 2666 | 	if (softback_top) { | 
 | 2667 | 		if (vc->vc_num != fg_console) | 
 | 2668 | 			return 0; | 
 | 2669 | 		if (vc->vc_mode != KD_TEXT || !lines) | 
 | 2670 | 			return 0; | 
 | 2671 | 		if (logo_shown >= 0) { | 
 | 2672 | 			struct vc_data *conp2 = vc_cons[logo_shown].d; | 
 | 2673 |  | 
 | 2674 | 			if (conp2->vc_top == logo_lines | 
 | 2675 | 			    && conp2->vc_bottom == conp2->vc_rows) | 
 | 2676 | 				conp2->vc_top = 0; | 
 | 2677 | 			if (logo_shown == vc->vc_num) { | 
 | 2678 | 				unsigned long p, q; | 
 | 2679 | 				int i; | 
 | 2680 |  | 
 | 2681 | 				p = softback_in; | 
 | 2682 | 				q = vc->vc_origin + | 
 | 2683 | 				    logo_lines * vc->vc_size_row; | 
 | 2684 | 				for (i = 0; i < logo_lines; i++) { | 
 | 2685 | 					if (p == softback_top) | 
 | 2686 | 						break; | 
 | 2687 | 					if (p == softback_buf) | 
 | 2688 | 						p = softback_end; | 
 | 2689 | 					p -= vc->vc_size_row; | 
 | 2690 | 					q -= vc->vc_size_row; | 
 | 2691 | 					scr_memcpyw((u16 *) q, (u16 *) p, | 
 | 2692 | 						    vc->vc_size_row); | 
 | 2693 | 				} | 
| David Hollister | 308af92 | 2006-05-30 21:25:36 -0700 | [diff] [blame] | 2694 | 				softback_in = softback_curr = p; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | 				update_region(vc, vc->vc_origin, | 
 | 2696 | 					      logo_lines * vc->vc_cols); | 
 | 2697 | 			} | 
 | 2698 | 			logo_shown = FBCON_LOGO_CANSHOW; | 
 | 2699 | 		} | 
 | 2700 | 		fbcon_cursor(vc, CM_ERASE | CM_SOFTBACK); | 
 | 2701 | 		fbcon_redraw_softback(vc, p, lines); | 
 | 2702 | 		fbcon_cursor(vc, CM_DRAW | CM_SOFTBACK); | 
 | 2703 | 		return 0; | 
 | 2704 | 	} | 
 | 2705 |  | 
 | 2706 | 	if (!scrollback_phys_max) | 
 | 2707 | 		return -ENOSYS; | 
 | 2708 |  | 
 | 2709 | 	scrollback_old = scrollback_current; | 
 | 2710 | 	scrollback_current -= lines; | 
 | 2711 | 	if (scrollback_current < 0) | 
 | 2712 | 		scrollback_current = 0; | 
 | 2713 | 	else if (scrollback_current > scrollback_max) | 
 | 2714 | 		scrollback_current = scrollback_max; | 
 | 2715 | 	if (scrollback_current == scrollback_old) | 
 | 2716 | 		return 0; | 
 | 2717 |  | 
 | 2718 | 	if (fbcon_is_inactive(vc, info)) | 
 | 2719 | 		return 0; | 
 | 2720 |  | 
 | 2721 | 	fbcon_cursor(vc, CM_ERASE); | 
 | 2722 |  | 
 | 2723 | 	offset = p->yscroll - scrollback_current; | 
 | 2724 | 	limit = p->vrows; | 
 | 2725 | 	switch (p->scrollmode) { | 
 | 2726 | 	case SCROLL_WRAP_MOVE: | 
 | 2727 | 		info->var.vmode |= FB_VMODE_YWRAP; | 
 | 2728 | 		break; | 
 | 2729 | 	case SCROLL_PAN_MOVE: | 
 | 2730 | 	case SCROLL_PAN_REDRAW: | 
 | 2731 | 		limit -= vc->vc_rows; | 
 | 2732 | 		info->var.vmode &= ~FB_VMODE_YWRAP; | 
 | 2733 | 		break; | 
 | 2734 | 	} | 
 | 2735 | 	if (offset < 0) | 
 | 2736 | 		offset += limit; | 
 | 2737 | 	else if (offset >= limit) | 
 | 2738 | 		offset -= limit; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2739 |  | 
 | 2740 | 	ops->var.xoffset = 0; | 
 | 2741 | 	ops->var.yoffset = offset * vc->vc_font.height; | 
 | 2742 | 	ops->update_start(info); | 
 | 2743 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | 	if (!scrollback_current) | 
 | 2745 | 		fbcon_cursor(vc, CM_DRAW); | 
 | 2746 | 	return 0; | 
 | 2747 | } | 
 | 2748 |  | 
 | 2749 | static int fbcon_set_origin(struct vc_data *vc) | 
 | 2750 | { | 
 | 2751 | 	if (softback_lines) | 
 | 2752 | 		fbcon_scrolldelta(vc, softback_lines); | 
 | 2753 | 	return 0; | 
 | 2754 | } | 
 | 2755 |  | 
 | 2756 | static void fbcon_suspended(struct fb_info *info) | 
 | 2757 | { | 
 | 2758 | 	struct vc_data *vc = NULL; | 
 | 2759 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 2760 |  | 
 | 2761 | 	if (!ops || ops->currcon < 0) | 
 | 2762 | 		return; | 
 | 2763 | 	vc = vc_cons[ops->currcon].d; | 
 | 2764 |  | 
 | 2765 | 	/* Clear cursor, restore saved data */ | 
 | 2766 | 	fbcon_cursor(vc, CM_ERASE); | 
 | 2767 | } | 
 | 2768 |  | 
 | 2769 | static void fbcon_resumed(struct fb_info *info) | 
 | 2770 | { | 
 | 2771 | 	struct vc_data *vc; | 
 | 2772 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 2773 |  | 
 | 2774 | 	if (!ops || ops->currcon < 0) | 
 | 2775 | 		return; | 
 | 2776 | 	vc = vc_cons[ops->currcon].d; | 
 | 2777 |  | 
 | 2778 | 	update_screen(vc); | 
 | 2779 | } | 
 | 2780 |  | 
 | 2781 | static void fbcon_modechanged(struct fb_info *info) | 
 | 2782 | { | 
 | 2783 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 2784 | 	struct vc_data *vc; | 
 | 2785 | 	struct display *p; | 
 | 2786 | 	int rows, cols; | 
 | 2787 |  | 
 | 2788 | 	if (!ops || ops->currcon < 0) | 
 | 2789 | 		return; | 
 | 2790 | 	vc = vc_cons[ops->currcon].d; | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2791 | 	if (vc->vc_mode != KD_TEXT || | 
 | 2792 | 	    registered_fb[con2fb_map[ops->currcon]] != info) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2793 | 		return; | 
 | 2794 |  | 
 | 2795 | 	p = &fb_display[vc->vc_num]; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 2796 | 	set_blitting_type(vc, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 |  | 
 | 2798 | 	if (CON_IS_VISIBLE(vc)) { | 
 | 2799 | 		var_to_display(p, &info->var, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2800 | 		cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); | 
 | 2801 | 		rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 2802 | 		cols /= vc->vc_font.width; | 
 | 2803 | 		rows /= vc->vc_font.height; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | 		vc_resize(vc, cols, rows); | 
 | 2805 | 		updatescrollmode(p, info, vc); | 
 | 2806 | 		scrollback_max = 0; | 
 | 2807 | 		scrollback_current = 0; | 
| Antonino A. Daplas | 4e1567d | 2005-12-12 22:17:18 -0800 | [diff] [blame] | 2808 |  | 
 | 2809 | 		if (!fbcon_is_inactive(vc, info)) { | 
 | 2810 | 		    ops->var.xoffset = ops->var.yoffset = p->yscroll = 0; | 
 | 2811 | 		    ops->update_start(info); | 
 | 2812 | 		} | 
 | 2813 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | 		fbcon_set_palette(vc, color_table); | 
 | 2815 | 		update_screen(vc); | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 2816 | 		if (softback_buf) | 
 | 2817 | 			fbcon_update_softback(vc); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | 	} | 
 | 2819 | } | 
 | 2820 |  | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2821 | static void fbcon_set_all_vcs(struct fb_info *info) | 
 | 2822 | { | 
 | 2823 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 2824 | 	struct vc_data *vc; | 
 | 2825 | 	struct display *p; | 
 | 2826 | 	int i, rows, cols; | 
 | 2827 |  | 
 | 2828 | 	if (!ops || ops->currcon < 0) | 
 | 2829 | 		return; | 
 | 2830 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2831 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2832 | 		vc = vc_cons[i].d; | 
 | 2833 | 		if (!vc || vc->vc_mode != KD_TEXT || | 
 | 2834 | 		    registered_fb[con2fb_map[i]] != info) | 
 | 2835 | 			continue; | 
 | 2836 |  | 
 | 2837 | 		p = &fb_display[vc->vc_num]; | 
| Antonino A. Daplas | b73deed | 2006-01-09 20:52:56 -0800 | [diff] [blame] | 2838 | 		set_blitting_type(vc, info); | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2839 | 		var_to_display(p, &info->var, info); | 
| Antonino A. Daplas | e4fc276 | 2005-11-08 21:39:09 -0800 | [diff] [blame] | 2840 | 		cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); | 
 | 2841 | 		rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); | 
 | 2842 | 		cols /= vc->vc_font.width; | 
 | 2843 | 		rows /= vc->vc_font.height; | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2844 | 		vc_resize(vc, cols, rows); | 
 | 2845 |  | 
 | 2846 | 		if (CON_IS_VISIBLE(vc)) { | 
 | 2847 | 			updatescrollmode(p, info, vc); | 
 | 2848 | 			scrollback_max = 0; | 
 | 2849 | 			scrollback_current = 0; | 
| Antonino A. Daplas | 4e1567d | 2005-12-12 22:17:18 -0800 | [diff] [blame] | 2850 |  | 
 | 2851 | 			if (!fbcon_is_inactive(vc, info)) { | 
 | 2852 | 			    ops->var.xoffset = ops->var.yoffset = | 
 | 2853 | 				p->yscroll = 0; | 
 | 2854 | 			    ops->update_start(info); | 
 | 2855 | 			} | 
 | 2856 |  | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2857 | 			fbcon_set_palette(vc, color_table); | 
 | 2858 | 			update_screen(vc); | 
| Antonino A. Daplas | 4d9c5b6 | 2005-11-07 01:00:36 -0800 | [diff] [blame] | 2859 | 			if (softback_buf) | 
 | 2860 | 				fbcon_update_softback(vc); | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2861 | 		} | 
 | 2862 | 	} | 
| Antonino A. Daplas | 04a2fe5 | 2006-01-09 20:52:58 -0800 | [diff] [blame] | 2863 |  | 
 | 2864 | 	ops->p = &fb_display[ops->currcon]; | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 2865 | } | 
 | 2866 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | static int fbcon_mode_deleted(struct fb_info *info, | 
 | 2868 | 			      struct fb_videomode *mode) | 
 | 2869 | { | 
 | 2870 | 	struct fb_info *fb_info; | 
 | 2871 | 	struct display *p; | 
 | 2872 | 	int i, j, found = 0; | 
 | 2873 |  | 
 | 2874 | 	/* before deletion, ensure that mode is not in use */ | 
 | 2875 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
 | 2876 | 		j = con2fb_map[i]; | 
 | 2877 | 		if (j == -1) | 
 | 2878 | 			continue; | 
 | 2879 | 		fb_info = registered_fb[j]; | 
 | 2880 | 		if (fb_info != info) | 
 | 2881 | 			continue; | 
 | 2882 | 		p = &fb_display[i]; | 
 | 2883 | 		if (!p || !p->mode) | 
 | 2884 | 			continue; | 
 | 2885 | 		if (fb_mode_is_equal(p->mode, mode)) { | 
 | 2886 | 			found = 1; | 
 | 2887 | 			break; | 
 | 2888 | 		} | 
 | 2889 | 	} | 
 | 2890 | 	return found; | 
 | 2891 | } | 
 | 2892 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2893 | static int fbcon_fb_unregistered(int idx) | 
 | 2894 | { | 
 | 2895 | 	int i; | 
 | 2896 |  | 
 | 2897 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
 | 2898 | 		if (con2fb_map[i] == idx) | 
 | 2899 | 			con2fb_map[i] = -1; | 
 | 2900 | 	} | 
 | 2901 |  | 
 | 2902 | 	if (idx == info_idx) { | 
 | 2903 | 		info_idx = -1; | 
 | 2904 |  | 
 | 2905 | 		for (i = 0; i < FB_MAX; i++) { | 
 | 2906 | 			if (registered_fb[i] != NULL) { | 
 | 2907 | 				info_idx = i; | 
 | 2908 | 				break; | 
 | 2909 | 			} | 
 | 2910 | 		} | 
 | 2911 | 	} | 
 | 2912 |  | 
 | 2913 | 	if (info_idx != -1) { | 
 | 2914 | 		for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
 | 2915 | 			if (con2fb_map[i] == -1) | 
 | 2916 | 				con2fb_map[i] = info_idx; | 
 | 2917 | 		} | 
 | 2918 | 	} | 
 | 2919 |  | 
 | 2920 | 	if (!num_registered_fb) | 
 | 2921 | 		unregister_con_driver(&fb_con); | 
 | 2922 |  | 
 | 2923 | 	return 0; | 
 | 2924 | } | 
 | 2925 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | static int fbcon_fb_registered(int idx) | 
 | 2927 | { | 
 | 2928 | 	int ret = 0, i; | 
 | 2929 |  | 
 | 2930 | 	if (info_idx == -1) { | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2931 | 		for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | 			if (con2fb_map_boot[i] == idx) { | 
 | 2933 | 				info_idx = idx; | 
 | 2934 | 				break; | 
 | 2935 | 			} | 
 | 2936 | 		} | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2937 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | 		if (info_idx != -1) | 
 | 2939 | 			ret = fbcon_takeover(1); | 
 | 2940 | 	} else { | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2941 | 		for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 2942 | 			if (con2fb_map_boot[i] == idx && | 
 | 2943 | 			    con2fb_map[i] == -1) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | 				set_con2fb_map(i, idx, 0); | 
 | 2945 | 		} | 
 | 2946 | 	} | 
 | 2947 |  | 
 | 2948 | 	return ret; | 
 | 2949 | } | 
 | 2950 |  | 
 | 2951 | static void fbcon_fb_blanked(struct fb_info *info, int blank) | 
 | 2952 | { | 
 | 2953 | 	struct fbcon_ops *ops = info->fbcon_par; | 
 | 2954 | 	struct vc_data *vc; | 
 | 2955 |  | 
 | 2956 | 	if (!ops || ops->currcon < 0) | 
 | 2957 | 		return; | 
 | 2958 |  | 
 | 2959 | 	vc = vc_cons[ops->currcon].d; | 
 | 2960 | 	if (vc->vc_mode != KD_TEXT || | 
 | 2961 | 			registered_fb[con2fb_map[ops->currcon]] != info) | 
 | 2962 | 		return; | 
 | 2963 |  | 
 | 2964 | 	if (CON_IS_VISIBLE(vc)) { | 
 | 2965 | 		if (blank) | 
 | 2966 | 			do_blank_screen(0); | 
 | 2967 | 		else | 
 | 2968 | 			do_unblank_screen(0); | 
 | 2969 | 	} | 
 | 2970 | 	ops->blank_state = blank; | 
 | 2971 | } | 
 | 2972 |  | 
 | 2973 | static void fbcon_new_modelist(struct fb_info *info) | 
 | 2974 | { | 
 | 2975 | 	int i; | 
 | 2976 | 	struct vc_data *vc; | 
 | 2977 | 	struct fb_var_screeninfo var; | 
 | 2978 | 	struct fb_videomode *mode; | 
 | 2979 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 2980 | 	for (i = first_fb_vc; i <= last_fb_vc; i++) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | 		if (registered_fb[con2fb_map[i]] != info) | 
 | 2982 | 			continue; | 
 | 2983 | 		if (!fb_display[i].mode) | 
 | 2984 | 			continue; | 
 | 2985 | 		vc = vc_cons[i].d; | 
 | 2986 | 		display_to_var(&var, &fb_display[i]); | 
| Michal Januszewski | 8fb6567 | 2005-11-07 01:00:47 -0800 | [diff] [blame] | 2987 | 		mode = fb_find_nearest_mode(fb_display[i].mode, | 
 | 2988 | 					    &info->modelist); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | 		fb_videomode_to_var(&var, mode); | 
 | 2990 |  | 
 | 2991 | 		if (vc) | 
 | 2992 | 			fbcon_set_disp(info, &var, vc); | 
 | 2993 | 		else | 
 | 2994 | 			fbcon_preset_disp(info, &var, i); | 
 | 2995 |  | 
 | 2996 | 	} | 
 | 2997 | } | 
 | 2998 |  | 
 | 2999 | static int fbcon_event_notify(struct notifier_block *self,  | 
 | 3000 | 			      unsigned long action, void *data) | 
 | 3001 | { | 
 | 3002 | 	struct fb_event *event = data; | 
 | 3003 | 	struct fb_info *info = event->info; | 
 | 3004 | 	struct fb_videomode *mode; | 
 | 3005 | 	struct fb_con2fbmap *con2fb; | 
 | 3006 | 	int ret = 0; | 
 | 3007 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3008 | 	/* | 
 | 3009 | 	 * ignore all events except driver registration and deregistration | 
 | 3010 | 	 * if fbcon is not active | 
 | 3011 | 	 */ | 
 | 3012 | 	if (fbcon_has_exited && !(action == FB_EVENT_FB_REGISTERED || | 
 | 3013 | 				  action == FB_EVENT_FB_UNREGISTERED)) | 
 | 3014 | 		goto done; | 
 | 3015 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | 	switch(action) { | 
 | 3017 | 	case FB_EVENT_SUSPEND: | 
 | 3018 | 		fbcon_suspended(info); | 
 | 3019 | 		break; | 
 | 3020 | 	case FB_EVENT_RESUME: | 
 | 3021 | 		fbcon_resumed(info); | 
 | 3022 | 		break; | 
 | 3023 | 	case FB_EVENT_MODE_CHANGE: | 
 | 3024 | 		fbcon_modechanged(info); | 
 | 3025 | 		break; | 
| Antonino A. Daplas | 7726e9e | 2005-09-09 13:04:29 -0700 | [diff] [blame] | 3026 | 	case FB_EVENT_MODE_CHANGE_ALL: | 
 | 3027 | 		fbcon_set_all_vcs(info); | 
 | 3028 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | 	case FB_EVENT_MODE_DELETE: | 
 | 3030 | 		mode = event->data; | 
 | 3031 | 		ret = fbcon_mode_deleted(info, mode); | 
 | 3032 | 		break; | 
 | 3033 | 	case FB_EVENT_FB_REGISTERED: | 
 | 3034 | 		ret = fbcon_fb_registered(info->node); | 
 | 3035 | 		break; | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3036 | 	case FB_EVENT_FB_UNREGISTERED: | 
 | 3037 | 		ret = fbcon_fb_unregistered(info->node); | 
 | 3038 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | 	case FB_EVENT_SET_CONSOLE_MAP: | 
 | 3040 | 		con2fb = event->data; | 
 | 3041 | 		ret = set_con2fb_map(con2fb->console - 1, | 
 | 3042 | 				     con2fb->framebuffer, 1); | 
 | 3043 | 		break; | 
 | 3044 | 	case FB_EVENT_GET_CONSOLE_MAP: | 
 | 3045 | 		con2fb = event->data; | 
 | 3046 | 		con2fb->framebuffer = con2fb_map[con2fb->console - 1]; | 
 | 3047 | 		break; | 
 | 3048 | 	case FB_EVENT_BLANK: | 
 | 3049 | 		fbcon_fb_blanked(info, *(int *)event->data); | 
 | 3050 | 		break; | 
 | 3051 | 	case FB_EVENT_NEW_MODELIST: | 
 | 3052 | 		fbcon_new_modelist(info); | 
 | 3053 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | 	} | 
 | 3055 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3056 | done: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | 	return ret; | 
 | 3058 | } | 
 | 3059 |  | 
 | 3060 | /* | 
 | 3061 |  *  The console `switch' structure for the frame buffer based console | 
 | 3062 |  */ | 
 | 3063 |  | 
 | 3064 | static const struct consw fb_con = { | 
 | 3065 | 	.owner			= THIS_MODULE, | 
 | 3066 | 	.con_startup 		= fbcon_startup, | 
 | 3067 | 	.con_init 		= fbcon_init, | 
 | 3068 | 	.con_deinit 		= fbcon_deinit, | 
 | 3069 | 	.con_clear 		= fbcon_clear, | 
 | 3070 | 	.con_putc 		= fbcon_putc, | 
 | 3071 | 	.con_putcs 		= fbcon_putcs, | 
 | 3072 | 	.con_cursor 		= fbcon_cursor, | 
 | 3073 | 	.con_scroll 		= fbcon_scroll, | 
 | 3074 | 	.con_bmove 		= fbcon_bmove, | 
 | 3075 | 	.con_switch 		= fbcon_switch, | 
 | 3076 | 	.con_blank 		= fbcon_blank, | 
 | 3077 | 	.con_font_set 		= fbcon_set_font, | 
 | 3078 | 	.con_font_get 		= fbcon_get_font, | 
 | 3079 | 	.con_font_default	= fbcon_set_def_font, | 
 | 3080 | 	.con_font_copy 		= fbcon_copy_font, | 
 | 3081 | 	.con_set_palette 	= fbcon_set_palette, | 
 | 3082 | 	.con_scrolldelta 	= fbcon_scrolldelta, | 
 | 3083 | 	.con_set_origin 	= fbcon_set_origin, | 
 | 3084 | 	.con_invert_region 	= fbcon_invert_region, | 
 | 3085 | 	.con_screen_pos 	= fbcon_screen_pos, | 
 | 3086 | 	.con_getxy 		= fbcon_getxy, | 
 | 3087 | 	.con_resize             = fbcon_resize, | 
 | 3088 | }; | 
 | 3089 |  | 
 | 3090 | static struct notifier_block fbcon_event_notifier = { | 
 | 3091 | 	.notifier_call	= fbcon_event_notify, | 
 | 3092 | }; | 
 | 3093 |  | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3094 | static ssize_t store_rotate(struct class_device *class_device, | 
 | 3095 | 			    const char *buf, size_t count) | 
 | 3096 | { | 
 | 3097 | 	struct fb_info *info; | 
 | 3098 | 	int rotate, idx; | 
 | 3099 | 	char **last = NULL; | 
 | 3100 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3101 | 	if (fbcon_has_exited) | 
 | 3102 | 		return count; | 
 | 3103 |  | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3104 | 	acquire_console_sem(); | 
 | 3105 | 	idx = con2fb_map[fg_console]; | 
 | 3106 |  | 
 | 3107 | 	if (idx == -1 || registered_fb[idx] == NULL) | 
 | 3108 | 		goto err; | 
 | 3109 |  | 
 | 3110 | 	info = registered_fb[idx]; | 
 | 3111 | 	rotate = simple_strtoul(buf, last, 0); | 
 | 3112 | 	fbcon_rotate(info, rotate); | 
 | 3113 | err: | 
 | 3114 | 	release_console_sem(); | 
 | 3115 | 	return count; | 
 | 3116 | } | 
 | 3117 |  | 
 | 3118 | static ssize_t store_rotate_all(struct class_device *class_device, | 
 | 3119 | 				const char *buf, size_t count) | 
 | 3120 | { | 
 | 3121 | 	struct fb_info *info; | 
 | 3122 | 	int rotate, idx; | 
 | 3123 | 	char **last = NULL; | 
 | 3124 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3125 | 	if (fbcon_has_exited) | 
 | 3126 | 		return count; | 
 | 3127 |  | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3128 | 	acquire_console_sem(); | 
 | 3129 | 	idx = con2fb_map[fg_console]; | 
 | 3130 |  | 
 | 3131 | 	if (idx == -1 || registered_fb[idx] == NULL) | 
 | 3132 | 		goto err; | 
 | 3133 |  | 
 | 3134 | 	info = registered_fb[idx]; | 
 | 3135 | 	rotate = simple_strtoul(buf, last, 0); | 
 | 3136 | 	fbcon_rotate_all(info, rotate); | 
 | 3137 | err: | 
 | 3138 | 	release_console_sem(); | 
 | 3139 | 	return count; | 
 | 3140 | } | 
 | 3141 |  | 
 | 3142 | static ssize_t show_rotate(struct class_device *class_device, char *buf) | 
 | 3143 | { | 
 | 3144 | 	struct fb_info *info; | 
 | 3145 | 	int rotate = 0, idx; | 
 | 3146 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3147 | 	if (fbcon_has_exited) | 
 | 3148 | 		return 0; | 
 | 3149 |  | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3150 | 	acquire_console_sem(); | 
 | 3151 | 	idx = con2fb_map[fg_console]; | 
 | 3152 |  | 
 | 3153 | 	if (idx == -1 || registered_fb[idx] == NULL) | 
 | 3154 | 		goto err; | 
 | 3155 |  | 
 | 3156 | 	info = registered_fb[idx]; | 
 | 3157 | 	rotate = fbcon_get_rotate(info); | 
 | 3158 | err: | 
 | 3159 | 	release_console_sem(); | 
 | 3160 | 	return snprintf(buf, PAGE_SIZE, "%d\n", rotate); | 
 | 3161 | } | 
 | 3162 |  | 
 | 3163 | static struct class_device_attribute class_device_attrs[] = { | 
 | 3164 | 	__ATTR(rotate, S_IRUGO|S_IWUSR, show_rotate, store_rotate), | 
 | 3165 | 	__ATTR(rotate_all, S_IWUSR, NULL, store_rotate_all), | 
 | 3166 | }; | 
 | 3167 |  | 
 | 3168 | static int fbcon_init_class_device(void) | 
 | 3169 | { | 
| Antonino A. Daplas | 0a727de | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 3170 | 	int i, error = 0; | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3171 |  | 
| Antonino A. Daplas | 0a727de | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 3172 | 	fbcon_has_sysfs = 1; | 
 | 3173 |  | 
 | 3174 | 	for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) { | 
 | 3175 | 		error = class_device_create_file(fbcon_class_device, | 
 | 3176 | 						 &class_device_attrs[i]); | 
 | 3177 |  | 
 | 3178 | 		if (error) | 
 | 3179 | 			break; | 
 | 3180 | 	} | 
 | 3181 |  | 
 | 3182 | 	if (error) { | 
 | 3183 | 		while (--i >= 0) | 
 | 3184 | 			class_device_remove_file(fbcon_class_device, | 
 | 3185 | 						 &class_device_attrs[i]); | 
 | 3186 |  | 
 | 3187 | 		fbcon_has_sysfs = 0; | 
 | 3188 | 	} | 
 | 3189 |  | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3190 | 	return 0; | 
 | 3191 | } | 
 | 3192 |  | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3193 | static void fbcon_start(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | 	if (num_registered_fb) { | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3196 | 		int i; | 
 | 3197 |  | 
 | 3198 | 		acquire_console_sem(); | 
 | 3199 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | 		for (i = 0; i < FB_MAX; i++) { | 
 | 3201 | 			if (registered_fb[i] != NULL) { | 
 | 3202 | 				info_idx = i; | 
 | 3203 | 				break; | 
 | 3204 | 			} | 
 | 3205 | 		} | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3206 |  | 
 | 3207 | 		release_console_sem(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | 		fbcon_takeover(0); | 
 | 3209 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | } | 
 | 3211 |  | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3212 | static void fbcon_exit(void) | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3213 | { | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3214 | 	struct fb_info *info; | 
 | 3215 | 	int i, j, mapped; | 
 | 3216 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3217 | 	if (fbcon_has_exited) | 
 | 3218 | 		return; | 
 | 3219 |  | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3220 | #ifdef CONFIG_ATARI | 
| Al Viro | 956295d | 2006-09-23 01:27:30 +0100 | [diff] [blame] | 3221 | 	free_irq(IRQ_AUTO_4, fb_vbl_handler); | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3222 | #endif | 
 | 3223 | #ifdef CONFIG_MAC | 
 | 3224 | 	if (MACH_IS_MAC && vbl_detected) | 
| Al Viro | 956295d | 2006-09-23 01:27:30 +0100 | [diff] [blame] | 3225 | 		free_irq(IRQ_MAC_VBL, fb_vbl_handler); | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3226 | #endif | 
 | 3227 |  | 
 | 3228 | 	kfree((void *)softback_buf); | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3229 | 	softback_buf = 0UL; | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3230 |  | 
 | 3231 | 	for (i = 0; i < FB_MAX; i++) { | 
 | 3232 | 		mapped = 0; | 
 | 3233 | 		info = registered_fb[i]; | 
 | 3234 |  | 
 | 3235 | 		if (info == NULL) | 
 | 3236 | 			continue; | 
 | 3237 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3238 | 		for (j = first_fb_vc; j <= last_fb_vc; j++) { | 
 | 3239 | 			if (con2fb_map[j] == i) | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3240 | 				mapped = 1; | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3241 | 		} | 
 | 3242 |  | 
 | 3243 | 		if (mapped) { | 
 | 3244 | 			if (info->fbops->fb_release) | 
 | 3245 | 				info->fbops->fb_release(info, 0); | 
 | 3246 | 			module_put(info->fbops->owner); | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3247 |  | 
 | 3248 | 			if (info->fbcon_par) { | 
| Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 3249 | 				struct fbcon_ops *ops = info->fbcon_par; | 
 | 3250 |  | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3251 | 				fbcon_del_cursor_timer(info); | 
| Dave Jones | e299dd4 | 2006-10-03 01:14:47 -0700 | [diff] [blame] | 3252 | 				kfree(ops->cursor_src); | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3253 | 				kfree(info->fbcon_par); | 
 | 3254 | 				info->fbcon_par = NULL; | 
 | 3255 | 			} | 
 | 3256 |  | 
 | 3257 | 			if (info->queue.func == fb_flashcursor) | 
 | 3258 | 				info->queue.func = NULL; | 
| Antonino A. Daplas | e55186f | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3259 | 		} | 
 | 3260 | 	} | 
 | 3261 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3262 | 	fbcon_has_exited = 1; | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3263 | } | 
 | 3264 |  | 
 | 3265 | static int __init fb_console_init(void) | 
 | 3266 | { | 
 | 3267 | 	int i; | 
 | 3268 |  | 
 | 3269 | 	acquire_console_sem(); | 
 | 3270 | 	fb_register_client(&fbcon_event_notifier); | 
 | 3271 | 	fbcon_class_device = | 
| Antonino A. Daplas | 5bd4253 | 2006-06-26 00:27:13 -0700 | [diff] [blame] | 3272 | 	    class_device_create(fb_class, NULL, MKDEV(0, 0), NULL, "fbcon"); | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3273 |  | 
 | 3274 | 	if (IS_ERR(fbcon_class_device)) { | 
 | 3275 | 		printk(KERN_WARNING "Unable to create class_device " | 
 | 3276 | 		       "for fbcon; errno = %ld\n", | 
 | 3277 | 		       PTR_ERR(fbcon_class_device)); | 
 | 3278 | 		fbcon_class_device = NULL; | 
 | 3279 | 	} else | 
 | 3280 | 		fbcon_init_class_device(); | 
 | 3281 |  | 
 | 3282 | 	for (i = 0; i < MAX_NR_CONSOLES; i++) | 
 | 3283 | 		con2fb_map[i] = -1; | 
 | 3284 |  | 
 | 3285 | 	release_console_sem(); | 
 | 3286 | 	fbcon_start(); | 
 | 3287 | 	return 0; | 
 | 3288 | } | 
 | 3289 |  | 
 | 3290 | module_init(fb_console_init); | 
 | 3291 |  | 
 | 3292 | #ifdef MODULE | 
 | 3293 |  | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3294 | static void __exit fbcon_deinit_class_device(void) | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3295 | { | 
 | 3296 | 	int i; | 
 | 3297 |  | 
| Antonino A. Daplas | 0a727de | 2006-10-03 01:14:50 -0700 | [diff] [blame] | 3298 | 	if (fbcon_has_sysfs) { | 
 | 3299 | 		for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) | 
 | 3300 | 			class_device_remove_file(fbcon_class_device, | 
 | 3301 | 						 &class_device_attrs[i]); | 
 | 3302 |  | 
 | 3303 | 		fbcon_has_sysfs = 0; | 
 | 3304 | 	} | 
| Antonino A. Daplas | 9a17917 | 2006-06-26 00:27:05 -0700 | [diff] [blame] | 3305 | } | 
 | 3306 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3307 | static void __exit fb_console_exit(void) | 
 | 3308 | { | 
 | 3309 | 	acquire_console_sem(); | 
 | 3310 | 	fb_unregister_client(&fbcon_event_notifier); | 
| Antonino A. Daplas | 5428b04 | 2006-06-26 00:27:06 -0700 | [diff] [blame] | 3311 | 	fbcon_deinit_class_device(); | 
| Antonino A. Daplas | 5bd4253 | 2006-06-26 00:27:13 -0700 | [diff] [blame] | 3312 | 	class_device_destroy(fb_class, MKDEV(0, 0)); | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3313 | 	fbcon_exit(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | 	release_console_sem(); | 
| Antonino A. Daplas | e614b18 | 2006-06-26 00:27:09 -0700 | [diff] [blame] | 3315 | 	unregister_con_driver(&fb_con); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | }	 | 
 | 3317 |  | 
 | 3318 | module_exit(fb_console_exit); | 
 | 3319 |  | 
 | 3320 | #endif | 
 | 3321 |  | 
 | 3322 | MODULE_LICENSE("GPL"); |