1 /* 2 * linux/drivers/video/console/fbcon.h -- Low level frame buffer based console driver 3 * 4 * Copyright (C) 1997 Geert Uytterhoeven 5 * 6 * This file is subject to the terms and conditions of the GNU General Public 7 * License. See the file COPYING in the main directory of this archive 8 * for more details. 9 */ 10 11 #ifndef _VIDEO_FBCON_H 12 #define _VIDEO_FBCON_H 13 14 #include <linux/font.h> 15 #include <linux/types.h> 16 #include <linux/vt_buffer.h> 17 #include <linux/vt_kern.h> 18 #include <linux/workqueue.h> 19 20 #include <asm/io.h> 21 22 /* 23 * This is the interface between the low-level console driver and the 24 * low-level frame buffer device 25 */ 26 27 struct fbcon_display { 28 /* Filled in by the low-level console driver */ 29 font_data_t *fontdata; 30 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION 31 u_short scrollmode; /* Scroll Method, use fb_scrollmode() */ 32 #endif 33 short yscroll; /* Hardware scrolling */ 34 int vrows; /* number of virtual rows */ 35 int cursor_shape; 36 int con_rotate; 37 u32 xres_virtual; 38 u32 yres_virtual; 39 u32 height; 40 u32 width; 41 u32 bits_per_pixel; 42 u32 grayscale; 43 u32 nonstd; 44 u32 accel_flags; 45 u32 rotate; 46 struct fb_bitfield red; 47 struct fb_bitfield green; 48 struct fb_bitfield blue; 49 struct fb_bitfield transp; 50 const struct fb_videomode *mode; 51 }; 52 53 struct fbcon_bitops { 54 void (*bmove)(struct vc_data *vc, struct fb_info *info, int sy, 55 int sx, int dy, int dx, int height, int width); 56 void (*clear)(struct vc_data *vc, struct fb_info *info, int sy, 57 int sx, int height, int width, int fb, int bg); 58 void (*putcs)(struct vc_data *vc, struct fb_info *info, 59 const unsigned short *s, int count, int yy, int xx, 60 int fg, int bg); 61 void (*clear_margins)(struct vc_data *vc, struct fb_info *info, 62 int color, int bottom_only); 63 void (*cursor)(struct vc_data *vc, struct fb_info *info, 64 bool enable, int fg, int bg); 65 int (*update_start)(struct fb_info *info); 66 int (*rotate_font)(struct fb_info *info, struct vc_data *vc); 67 }; 68 69 struct fbcon_par { 70 struct fb_var_screeninfo var; /* copy of the current fb_var_screeninfo */ 71 struct delayed_work cursor_work; /* Cursor timer */ 72 struct fb_cursor cursor_state; 73 struct fbcon_display *p; 74 struct fb_info *info; 75 int currcon; /* Current VC. */ 76 int cur_blink_jiffies; 77 int cursor_flash; 78 int cursor_reset; 79 int blank_state; 80 int graphics; 81 bool initialized; 82 int rotate; 83 char *cursor_data; 84 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_ROTATION 85 struct { 86 font_data_t *fontdata; /* source font */ 87 u8 *buf; /* rotated glyphs */ 88 size_t bufsize; 89 int buf_rotate; /* rotation of buf */ 90 } rotated; 91 #endif 92 u8 *cursor_src; 93 u32 cursor_size; 94 95 const struct fbcon_bitops *bitops; 96 }; 97 98 /* 99 * Attribute Decoding 100 */ 101 102 /* Color */ 103 #define attr_fgcol(fgshift,s) \ 104 (((s) >> (fgshift)) & 0x0f) 105 #define attr_bgcol(bgshift,s) \ 106 (((s) >> (bgshift)) & 0x0f) 107 108 /* Monochrome */ 109 #define attr_bold(s) \ 110 ((s) & 0x200) 111 #define attr_reverse(s) \ 112 ((s) & 0x800) 113 #define attr_underline(s) \ 114 ((s) & 0x400) 115 #define attr_blink(s) \ 116 ((s) & 0x8000) 117 118 static inline int mono_col(const struct fb_info *info) 119 { 120 __u32 max_len; 121 max_len = max(info->var.green.length, info->var.red.length); 122 max_len = max(info->var.blue.length, max_len); 123 return (~(0xfff << max_len)) & 0xff; 124 } 125 126 /* 127 * Scroll Method 128 */ 129 130 /* There are several methods fbcon can use to move text around the screen: 131 * 132 * Operation Pan Wrap 133 *--------------------------------------------- 134 * SCROLL_MOVE copyarea No No 135 * SCROLL_PAN_MOVE copyarea Yes No 136 * SCROLL_WRAP_MOVE copyarea No Yes 137 * SCROLL_REDRAW imageblit No No 138 * SCROLL_PAN_REDRAW imageblit Yes No 139 * SCROLL_WRAP_REDRAW imageblit No Yes 140 * 141 * (SCROLL_WRAP_REDRAW is not implemented yet) 142 * 143 * In general, fbcon will choose the best scrolling 144 * method based on the rule below: 145 * 146 * Pan/Wrap > accel imageblit > accel copyarea > 147 * soft imageblit > (soft copyarea) 148 * 149 * Exception to the rule: Pan + accel copyarea is 150 * preferred over Pan + accel imageblit. 151 * 152 * The above is typical for PCI/AGP cards. Unless 153 * overridden, fbcon will never use soft copyarea. 154 * 155 * If you need to override the above rule, set the 156 * appropriate flags in fb_info->flags. For example, 157 * to prefer copyarea over imageblit, set 158 * FBINFO_READS_FAST. 159 * 160 * Other notes: 161 * + use the hardware engine to move the text 162 * (hw-accelerated copyarea() and fillrect()) 163 * + use hardware-supported panning on a large virtual screen 164 * + amifb can not only pan, but also wrap the display by N lines 165 * (i.e. visible line i = physical line (i+N) % yres). 166 * + read what's already rendered on the screen and 167 * write it in a different place (this is cfb_copyarea()) 168 * + re-render the text to the screen 169 * 170 * Whether to use wrapping or panning can only be figured out at 171 * runtime (when we know whether our font height is a multiple 172 * of the pan/wrap step) 173 * 174 */ 175 176 #define SCROLL_MOVE 0x001 177 #define SCROLL_PAN_MOVE 0x002 178 #define SCROLL_WRAP_MOVE 0x003 179 #define SCROLL_REDRAW 0x004 180 #define SCROLL_PAN_REDRAW 0x005 181 182 static inline u_short fb_scrollmode(struct fbcon_display *fb) 183 { 184 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION 185 return fb->scrollmode; 186 #else 187 /* hardcoded to SCROLL_REDRAW if acceleration was disabled. */ 188 return SCROLL_REDRAW; 189 #endif 190 } 191 192 193 #ifdef CONFIG_FB_TILEBLITTING 194 extern void fbcon_set_tileops(struct vc_data *vc, struct fb_info *info); 195 #endif 196 extern void fbcon_set_bitops_ur(struct fbcon_par *par); 197 extern int soft_cursor(struct fb_info *info, struct fb_cursor *cursor); 198 199 void fbcon_fill_cursor_mask(struct fbcon_par *par, struct vc_data *vc, unsigned char *mask); 200 201 #define FBCON_ATTRIBUTE_UNDERLINE 1 202 #define FBCON_ATTRIBUTE_REVERSE 2 203 #define FBCON_ATTRIBUTE_BOLD 4 204 205 static inline int real_y(struct fbcon_display *p, int ypos) 206 { 207 int rows = p->vrows; 208 209 ypos += p->yscroll; 210 return ypos < rows ? ypos : ypos - rows; 211 } 212 213 214 static inline int get_attribute(struct fb_info *info, u16 c) 215 { 216 int attribute = 0; 217 218 if (fb_get_color_depth(&info->var, &info->fix) == 1) { 219 if (attr_underline(c)) 220 attribute |= FBCON_ATTRIBUTE_UNDERLINE; 221 if (attr_reverse(c)) 222 attribute |= FBCON_ATTRIBUTE_REVERSE; 223 if (attr_bold(c)) 224 attribute |= FBCON_ATTRIBUTE_BOLD; 225 } 226 227 return attribute; 228 } 229 230 #define FBCON_SWAP(i,r,v) ({ \ 231 typeof(r) _r = (r); \ 232 typeof(v) _v = (v); \ 233 (void) (&_r == &_v); \ 234 (i == FB_ROTATE_UR || i == FB_ROTATE_UD) ? _r : _v; }) 235 236 #endif /* _VIDEO_FBCON_H */ 237