Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | /* * linux/drivers/video/fbcon-vga-planes.c -- Low level frame buffer operations * for VGA 4-plane modes * * Copyright 1999 Ben Pfaff <pfaffben@debian.org> and Petr Vandrovec <VANDROVE@vc.cvut.cz> * Based on code by Michael Schmitz * Based on the old macfb.c 4bpp code by Alan Cox * * This file is subject to the terms and conditions of the GNU General * Public License. See the file COPYING in the main directory of this * archive for more details. */ #include <linux/module.h> #include <linux/tty.h> #include <linux/console.h> #include <linux/string.h> #include <linux/fb.h> #include <linux/vt_buffer.h> #include <asm/io.h> #include <video/fbcon.h> #include <video/fbcon-vga-planes.h> #define GRAPHICS_ADDR_REG 0x3ce /* Graphics address register. */ #define GRAPHICS_DATA_REG 0x3cf /* Graphics data register. */ #define SET_RESET_INDEX 0 /* Set/Reset Register index. */ #define ENABLE_SET_RESET_INDEX 1 /* Enable Set/Reset Register index. */ #define DATA_ROTATE_INDEX 3 /* Data Rotate Register index. */ #define GRAPHICS_MODE_INDEX 5 /* Graphics Mode Register index. */ #define BIT_MASK_INDEX 8 /* Bit Mask Register index. */ /* The VGA's weird architecture often requires that we read a byte and write a byte to the same location. It doesn't matter *what* byte we write, however. This is because all the action goes on behind the scenes in the VGA's 32-bit latch register, and reading and writing video memory just invokes latch behavior. To avoid race conditions (is this necessary?), reading and writing the memory byte should be done with a single instruction. One suitable instruction is the x86 bitwise OR. The following read-modify-write routine should optimize to one such bitwise OR. */ static inline void rmw(volatile char *p) { readb(p); writeb(1, p); } /* Set the Graphics Mode Register. Bits 0-1 are write mode, bit 3 is read mode. */ static inline void setmode(int mode) { outb(GRAPHICS_MODE_INDEX, GRAPHICS_ADDR_REG); outb(mode, GRAPHICS_DATA_REG); } /* Select the Bit Mask Register. */ static inline void selectmask(void) { outb(BIT_MASK_INDEX, GRAPHICS_ADDR_REG); } /* Set the value of the Bit Mask Register. It must already have been selected with selectmask(). */ static inline void setmask(int mask) { outb(mask, GRAPHICS_DATA_REG); } /* Set the Data Rotate Register. Bits 0-2 are rotate count, bits 3-4 are logical operation (0=NOP, 1=AND, 2=OR, 3=XOR). */ static inline void setop(int op) { outb(DATA_ROTATE_INDEX, GRAPHICS_ADDR_REG); outb(op, GRAPHICS_DATA_REG); } /* Set the Enable Set/Reset Register. The code here always uses value 0xf for this register. */ static inline void setsr(int sr) { outb(ENABLE_SET_RESET_INDEX, GRAPHICS_ADDR_REG); outb(sr, GRAPHICS_DATA_REG); } /* Set the Set/Reset Register. */ static inline void setcolor(int color) { outb(SET_RESET_INDEX, GRAPHICS_ADDR_REG); outb(color, GRAPHICS_DATA_REG); } /* Set the value in the Graphics Address Register. */ static inline void setindex(int index) { outb(index, GRAPHICS_ADDR_REG); } void fbcon_vga_planes_setup(struct display *p) { } void fbcon_vga_planes_bmove(struct display *p, int sy, int sx, int dy, int dx, int height, int width) { char *src; char *dest; int line_ofs; int x; setmode(1); setop(0); setsr(0xf); sy *= fontheight(p); dy *= fontheight(p); height *= fontheight(p); if (dy < sy || (dy == sy && dx < sx)) { line_ofs = p->line_length - width; dest = p->screen_base + dx + dy * p->line_length; src = p->screen_base + sx + sy * p->line_length; while (height--) { for (x = 0; x < width; x++) { readb(src); writeb(0, dest); dest++; src++; } src += line_ofs; dest += line_ofs; } } else { line_ofs = p->line_length - width; dest = p->screen_base + dx + width + (dy + height - 1) * p->line_length; src = p->screen_base + sx + width + (sy + height - 1) * p->line_length; while (height--) { for (x = 0; x < width; x++) { dest--; src--; readb(src); writeb(0, dest); } src -= line_ofs; dest -= line_ofs; } } } void fbcon_vga_planes_clear(struct vc_data *conp, struct display *p, int sy, int sx, int height, int width) { int line_ofs = p->line_length - width; char *where; int x; setmode(0); setop(0); setsr(0xf); setcolor(attr_bgcol_ec(p, conp)); selectmask(); setmask(0xff); sy *= fontheight(p); height *= fontheight(p); where = p->screen_base + sx + sy * p->line_length; while (height--) { for (x = 0; x < width; x++) { writeb(0, where); where++; } where += line_ofs; } } void fbcon_ega_planes_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx) { int fg = attr_fgcol(p,c); int bg = attr_bgcol(p,c); int y; u8 *cdat = p->fontdata + (c & p->charmask) * fontheight(p); char *where = p->screen_base + xx + yy * p->line_length * fontheight(p); setmode(0); setop(0); setsr(0xf); setcolor(bg); selectmask(); setmask(0xff); for (y = 0; y < fontheight(p); y++, where += p->line_length) rmw(where); where -= p->line_length * y; setcolor(fg); selectmask(); for (y = 0; y < fontheight(p); y++, where += p->line_length) if (cdat[y]) { setmask(cdat[y]); rmw(where); } } void fbcon_vga_planes_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx) { int fg = attr_fgcol(p,c); int bg = attr_bgcol(p,c); int y; u8 *cdat = p->fontdata + (c & p->charmask) * fontheight(p); char *where = p->screen_base + xx + yy * p->line_length * fontheight(p); setmode(2); setop(0); setsr(0xf); setcolor(fg); selectmask(); setmask(0xff); writeb(bg, where); rmb(); readb(where); /* fill latches */ setmode(3); wmb(); for (y = 0; y < fontheight(p); y++, where += p->line_length) writeb(cdat[y], where); wmb(); } /* 28.50 in my test */ void fbcon_ega_planes_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx) { int fg = attr_fgcol(p,scr_readw(s)); int bg = attr_bgcol(p,scr_readw(s)); char *where; int n; setmode(2); setop(0); selectmask(); setmask(0xff); where = p->screen_base + xx + yy * p->line_length * fontheight(p); writeb(bg, where); rmb(); readb(where); /* fill latches */ wmb(); selectmask(); for (n = 0; n < count; n++) { int c = scr_readw(s++) & p->charmask; u8 *cdat = p->fontdata + c * fontheight(p); u8 *end = cdat + fontheight(p); while (cdat < end) { outb(*cdat++, GRAPHICS_DATA_REG); wmb(); writeb(fg, where); where += p->line_length; } where += 1 - p->line_length * fontheight(p); } wmb(); } /* 6.96 in my test */ void fbcon_vga_planes_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx) { int fg = attr_fgcol(p,*s); int bg = attr_bgcol(p,*s); char *where; int n; setmode(2); setop(0); setsr(0xf); setcolor(fg); selectmask(); setmask(0xff); where = p->screen_base + xx + yy * p->line_length * fontheight(p); writeb(bg, where); rmb(); readb(where); /* fill latches */ setmode(3); wmb(); for (n = 0; n < count; n++) { int y; int c = *s++ & p->charmask; u8 *cdat = p->fontdata + (c & p->charmask) * fontheight(p); for (y = 0; y < fontheight(p); y++, cdat++) { writeb (*cdat, where); where += p->line_length; } where += 1 - p->line_length * fontheight(p); } wmb(); } void fbcon_vga_planes_revc(struct display *p, int xx, int yy) { char *where = p->screen_base + xx + yy * p->line_length * fontheight(p); int y; setmode(0); setop(0x18); setsr(0xf); setcolor(0xf); selectmask(); setmask(0xff); for (y = 0; y < fontheight(p); y++) { rmw(where); where += p->line_length; } } struct display_switch fbcon_vga_planes = { setup: fbcon_vga_planes_setup, bmove: fbcon_vga_planes_bmove, clear: fbcon_vga_planes_clear, putc: fbcon_vga_planes_putc, putcs: fbcon_vga_planes_putcs, revc: fbcon_vga_planes_revc, fontwidthmask: FONTWIDTH(8) }; struct display_switch fbcon_ega_planes = { setup: fbcon_vga_planes_setup, bmove: fbcon_vga_planes_bmove, clear: fbcon_vga_planes_clear, putc: fbcon_ega_planes_putc, putcs: fbcon_ega_planes_putcs, revc: fbcon_vga_planes_revc, fontwidthmask: FONTWIDTH(8) }; #ifdef MODULE int init_module(void) { return 0; } void cleanup_module(void) {} #endif /* MODULE */ /* * Visible symbols for modules */ EXPORT_SYMBOL(fbcon_vga_planes); EXPORT_SYMBOL(fbcon_vga_planes_setup); EXPORT_SYMBOL(fbcon_vga_planes_bmove); EXPORT_SYMBOL(fbcon_vga_planes_clear); EXPORT_SYMBOL(fbcon_vga_planes_putc); EXPORT_SYMBOL(fbcon_vga_planes_putcs); EXPORT_SYMBOL(fbcon_vga_planes_revc); EXPORT_SYMBOL(fbcon_ega_planes); EXPORT_SYMBOL(fbcon_ega_planes_putc); EXPORT_SYMBOL(fbcon_ega_planes_putcs); /* * Overrides for Emacs so that we follow Linus's tabbing style. * --------------------------------------------------------------------------- * Local variables: * c-basic-offset: 8 * End: */ |