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>
18 #include <linux/vt_buffer.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
45 static inline void rmw(volatile char *p
)
50 /* Set the Graphics Mode Register. Bits 0-1 are write mode, bit 3 is
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
)
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
;
125 for (x
= 0; x
< width
; x
++)
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
;
135 for (x
= 0; x
< width
; x
++)
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
;
153 setcolor(attr_bgcol_ec(p
, conp
));
159 height
*= fontheight(p
);
161 where
= p
->screen_base
+ sx
+ sy
* p
->line_length
;
163 for (x
= 0; x
< width
; x
++)
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
);
175 u8
*cdat
= p
->fontdata
+ (c
& p
->charmask
) * fontheight(p
);
176 char *where
= p
->screen_base
+ xx
+ yy
* p
->line_length
* fontheight(p
);
185 for (y
= 0; y
< fontheight(p
); y
++, where
+= p
->line_length
)
188 where
-= p
->line_length
* y
;
191 for (y
= 0; y
< fontheight(p
); y
++, where
+= p
->line_length
)
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
);
204 u8
*cdat
= p
->fontdata
+ (c
& p
->charmask
) * fontheight(p
);
205 char *where
= p
->screen_base
+ xx
+ yy
* p
->line_length
* fontheight(p
);
216 *(volatile char*)where
; /* fill latches */
219 for (y
= 0; y
< fontheight(p
); y
++, where
+= p
->line_length
)
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
));
239 where
= p
->screen_base
+ xx
+ yy
* p
->line_length
* fontheight(p
);
242 *(volatile char*)where
;
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
);
251 outb(*cdat
++, GRAPHICS_DATA_REG
);
254 where
+= p
->line_length
;
256 where
+= 1 - p
->line_length
* fontheight(p
);
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
);
279 where
= p
->screen_base
+ xx
+ yy
* p
->line_length
* fontheight(p
);
282 *(volatile char*)where
; /* fill latches with background */
285 for (n
= 0; n
< count
; n
++) {
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
++) {
292 where
+= p
->line_length
;
294 where
+= 1 - p
->line_length
* fontheight(p
);
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
);
312 for (y
= 0; y
< fontheight(p
); y
++) {
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)
331 int init_module(void)
336 void cleanup_module(void)
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 * ---------------------------------------------------------------------------