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