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