Import 2.3.2
[davej-history.git] / drivers / video / fbcon-vga-planes.c
blob391ceb22ec4c3338c36f3d5ed201c350df92905d
1 /*
2 * linux/drivers/video/fbcon-vga-planes.c -- Low level frame buffer operations
3 * for VGA 4-plane modes
5 * Copyright 1999 Ben Pfaff <pfaffben@debian.org> and Petr Vandrovec <VANDROVE@vc.cvut.cz>
6 * Based on code by Michael Schmitz
7 * Based on the old macfb.c 4bpp code by Alan Cox
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file COPYING in the main directory of this
11 * archive for more details. */
13 #include <linux/module.h>
14 #include <linux/tty.h>
15 #include <linux/console.h>
16 #include <linux/string.h>
17 #include <linux/fb.h>
18 #include <linux/vt_buffer.h>
20 #include <asm/io.h>
22 #include <video/fbcon.h>
23 #include <video/fbcon-vga-planes.h>
25 #define GRAPHICS_ADDR_REG 0x3ce /* Graphics address register. */
26 #define GRAPHICS_DATA_REG 0x3cf /* Graphics data register. */
28 #define SET_RESET_INDEX 0 /* Set/Reset Register index. */
29 #define ENABLE_SET_RESET_INDEX 1 /* Enable Set/Reset Register index. */
30 #define DATA_ROTATE_INDEX 3 /* Data Rotate Register index. */
31 #define GRAPHICS_MODE_INDEX 5 /* Graphics Mode Register index. */
32 #define BIT_MASK_INDEX 8 /* Bit Mask Register index. */
34 /* The VGA's weird architecture often requires that we read a byte and
35 write a byte to the same location. It doesn't matter *what* byte
36 we write, however. This is because all the action goes on behind
37 the scenes in the VGA's 32-bit latch register, and reading and writing
38 video memory just invokes latch behavior.
40 To avoid race conditions (is this necessary?), reading and writing
41 the memory byte should be done with a single instruction. One
42 suitable instruction is the x86 bitwise OR. The following
43 read-modify-write routine should optimize to one such bitwise
44 OR. */
45 static inline void rmw(volatile char *p)
47 *p |= 1;
50 /* Set the Graphics Mode Register. Bits 0-1 are write mode, bit 3 is
51 read mode. */
52 static inline void setmode(int mode)
54 outb(GRAPHICS_MODE_INDEX, GRAPHICS_ADDR_REG);
55 outb(mode, GRAPHICS_DATA_REG);
58 /* Select the Bit Mask Register. */
59 static inline void selectmask(void)
61 outb(BIT_MASK_INDEX, GRAPHICS_ADDR_REG);
64 /* Set the value of the Bit Mask Register. It must already have been
65 selected with selectmask(). */
66 static inline void setmask(int mask)
68 outb(mask, GRAPHICS_DATA_REG);
71 /* Set the Data Rotate Register. Bits 0-2 are rotate count, bits 3-4
72 are logical operation (0=NOP, 1=AND, 2=OR, 3=XOR). */
73 static inline void setop(int op)
75 outb(DATA_ROTATE_INDEX, GRAPHICS_ADDR_REG);
76 outb(op, GRAPHICS_DATA_REG);
79 /* Set the Enable Set/Reset Register. The code here always uses value
80 0xf for this register. */
81 static inline void setsr(int sr)
83 outb(ENABLE_SET_RESET_INDEX, GRAPHICS_ADDR_REG);
84 outb(sr, GRAPHICS_DATA_REG);
87 /* Set the Set/Reset Register. */
88 static inline void setcolor(int color)
90 outb(SET_RESET_INDEX, GRAPHICS_ADDR_REG);
91 outb(color, GRAPHICS_DATA_REG);
94 /* Set the value in the Graphics Address Register. */
95 static inline void setindex(int index)
97 outb(index, GRAPHICS_ADDR_REG);
100 void fbcon_vga_planes_setup(struct display *p)
104 void fbcon_vga_planes_bmove(struct display *p, int sy, int sx, int dy, int dx,
105 int height, int width)
107 char *src;
108 char *dest;
109 int line_ofs;
110 int x;
112 setmode(1);
113 setop(0);
114 setsr(0xf);
116 sy *= fontheight(p);
117 dy *= fontheight(p);
118 height *= fontheight(p);
120 if (dy < sy || (dy == sy && dx < sx)) {
121 line_ofs = p->line_length - width;
122 dest = p->screen_base + dx + dy * p->line_length;
123 src = p->screen_base + sx + sy * p->line_length;
124 while (height--) {
125 for (x = 0; x < width; x++)
126 *dest++ = *src++;
127 src += line_ofs;
128 dest += line_ofs;
130 } else {
131 line_ofs = p->line_length - width;
132 dest = p->screen_base + dx + width + (dy + height - 1) * p->line_length;
133 src = p->screen_base + sx + width + (sy + height - 1) * p->line_length;
134 while (height--) {
135 for (x = 0; x < width; x++)
136 *--dest = *--src;
137 src -= line_ofs;
138 dest -= line_ofs;
143 void fbcon_vga_planes_clear(struct vc_data *conp, struct display *p, int sy, int sx,
144 int height, int width)
146 int line_ofs = p->line_length - width;
147 char *where;
148 int x;
150 setmode(0);
151 setop(0);
152 setsr(0xf);
153 setcolor(attr_bgcol_ec(p, conp));
154 selectmask();
156 setmask(0xff);
158 sy *= fontheight(p);
159 height *= fontheight(p);
161 where = p->screen_base + sx + sy * p->line_length;
162 while (height--) {
163 for (x = 0; x < width; x++)
164 *where++ = 0;
165 where += line_ofs;
169 void fbcon_ega_planes_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx)
171 int fg = attr_fgcol(p,c);
172 int bg = attr_bgcol(p,c);
174 int y;
175 u8 *cdat = p->fontdata + (c & p->charmask) * fontheight(p);
176 char *where = p->screen_base + xx + yy * p->line_length * fontheight(p);
178 setmode(0);
179 setop(0);
180 setsr(0xf);
181 setcolor(bg);
182 selectmask();
184 setmask(0xff);
185 for (y = 0; y < fontheight(p); y++, where += p->line_length)
186 rmw(where);
188 where -= p->line_length * y;
189 setcolor(fg);
190 selectmask();
191 for (y = 0; y < fontheight(p); y++, where += p->line_length)
192 if (cdat[y]) {
193 setmask(cdat[y]);
194 rmw(where);
198 void fbcon_vga_planes_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx)
200 int fg = attr_fgcol(p,c);
201 int bg = attr_bgcol(p,c);
203 int y;
204 u8 *cdat = p->fontdata + (c & p->charmask) * fontheight(p);
205 char *where = p->screen_base + xx + yy * p->line_length * fontheight(p);
207 setmode(2);
208 setop(0);
209 setsr(0xf);
210 setcolor(fg);
211 selectmask();
213 setmask(0xff);
214 *where = bg;
215 rmb();
216 *(volatile char*)where; /* fill latches */
217 setmode(3);
218 wmb();
219 for (y = 0; y < fontheight(p); y++, where += p->line_length)
220 *where = cdat[y];
221 wmb();
224 /* 28.50 in my test */
225 void fbcon_ega_planes_putcs(struct vc_data *conp, struct display *p, const unsigned short *s,
226 int count, int yy, int xx)
228 int fg = attr_fgcol(p,scr_readw(s));
229 int bg = attr_bgcol(p,scr_readw(s));
231 char *where;
232 int n;
234 setmode(2);
235 setop(0);
236 selectmask();
238 setmask(0xff);
239 where = p->screen_base + xx + yy * p->line_length * fontheight(p);
240 *where = bg;
241 rmb();
242 *(volatile char*)where;
243 wmb();
244 selectmask();
245 for (n = 0; n < count; n++) {
246 int c = scr_readw(s++) & p->charmask;
247 u8 *cdat = p->fontdata + c * fontheight(p);
248 u8 *end = cdat + fontheight(p);
250 while (cdat < end) {
251 outb(*cdat++, GRAPHICS_DATA_REG);
252 wmb();
253 *where = fg;
254 where += p->line_length;
256 where += 1 - p->line_length * fontheight(p);
259 wmb();
262 /* 6.96 in my test */
263 void fbcon_vga_planes_putcs(struct vc_data *conp, struct display *p, const unsigned short *s,
264 int count, int yy, int xx)
266 int fg = attr_fgcol(p,*s);
267 int bg = attr_bgcol(p,*s);
269 char *where;
270 int n;
272 setmode(2);
273 setop(0);
274 setsr(0xf);
275 setcolor(fg);
276 selectmask();
278 setmask(0xff);
279 where = p->screen_base + xx + yy * p->line_length * fontheight(p);
280 *where = bg;
281 rmb();
282 *(volatile char*)where; /* fill latches with background */
283 setmode(3);
284 wmb();
285 for (n = 0; n < count; n++) {
286 int y;
287 int c = *s++ & p->charmask;
288 u8 *cdat = p->fontdata + (c & p->charmask) * fontheight(p);
290 for (y = 0; y < fontheight(p); y++, cdat++) {
291 *where = *cdat;
292 where += p->line_length;
294 where += 1 - p->line_length * fontheight(p);
297 wmb();
300 void fbcon_vga_planes_revc(struct display *p, int xx, int yy)
302 char *where = p->screen_base + xx + yy * p->line_length * fontheight(p);
303 int y;
305 setmode(0);
306 setop(0x18);
307 setsr(0xf);
308 setcolor(0xf);
309 selectmask();
311 setmask(0xff);
312 for (y = 0; y < fontheight(p); y++) {
313 rmw(where);
314 where += p->line_length;
318 struct display_switch fbcon_vga_planes = {
319 fbcon_vga_planes_setup, fbcon_vga_planes_bmove, fbcon_vga_planes_clear,
320 fbcon_vga_planes_putc, fbcon_vga_planes_putcs, fbcon_vga_planes_revc,
321 NULL, NULL, NULL, FONTWIDTH(8)
324 struct display_switch fbcon_ega_planes = {
325 fbcon_vga_planes_setup, fbcon_vga_planes_bmove, fbcon_vga_planes_clear,
326 fbcon_ega_planes_putc, fbcon_ega_planes_putcs, fbcon_vga_planes_revc,
327 NULL, NULL, NULL, FONTWIDTH(8)
330 #ifdef MODULE
331 int init_module(void)
333 return 0;
336 void cleanup_module(void)
338 #endif /* MODULE */
342 * Visible symbols for modules
345 EXPORT_SYMBOL(fbcon_vga_planes);
346 EXPORT_SYMBOL(fbcon_vga_planes_setup);
347 EXPORT_SYMBOL(fbcon_vga_planes_bmove);
348 EXPORT_SYMBOL(fbcon_vga_planes_clear);
349 EXPORT_SYMBOL(fbcon_vga_planes_putc);
350 EXPORT_SYMBOL(fbcon_vga_planes_putcs);
351 EXPORT_SYMBOL(fbcon_vga_planes_revc);
353 EXPORT_SYMBOL(fbcon_ega_planes);
354 EXPORT_SYMBOL(fbcon_ega_planes_putc);
355 EXPORT_SYMBOL(fbcon_ega_planes_putcs);
358 * Overrides for Emacs so that we follow Linus's tabbing style.
359 * ---------------------------------------------------------------------------
360 * Local variables:
361 * c-basic-offset: 8
362 * End: