2 * linux/drivers/video/fbcon-vga.c -- Low level frame buffer operations for
3 * VGA characters/attributes
5 * Created 28 Mar 1998 by Geert Uytterhoeven
6 * Monochrome attributes added May 1998 by Andrew Apted
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
13 #include <linux/module.h>
14 #include <linux/tty.h>
15 #include <linux/console.h>
16 #include <linux/string.h>
21 #include <video/fbcon.h>
22 #include <video/fbcon-vga.h>
29 static inline void vga_writew(u16 val, u16 *addr)
34 writew(val, (unsigned long)addr);
35 #endif /* !__powerpc__ */
38 static inline u16 vga_readw(u16 *addr)
43 return readw((unsigned long)addr);
44 #endif /* !__powerpc__ */
47 static inline void vga_memsetw(void *s, u16 c, unsigned int count)
53 vga_writew(c, addr++);
57 static inline void vga_memmovew(u16 *to, u16 *from, unsigned int count)
62 vga_writew(vga_readw(from++), to++);
69 vga_writew(vga_readw(--from), --to);
76 * VGA characters/attributes
79 static inline u16 fbcon_vga_attr(struct display *p,
82 /* Underline and reverse-video are mutually exclusive on MDA.
83 * Since reverse-video is used for cursors and selected areas,
84 * it takes precedence.
87 return (attr_reverse(p, s) ? 0x7000 :
88 (attr_underline(p, s) ? 0x0100 : 0x0700)) |
89 (attr_bold(p, s) ? 0x0800 : 0) |
90 (attr_blink(p, s) ? 0x8000 : 0);
93 void fbcon_vga_setup(struct display *p)
95 p->next_line = p->line_length;
99 void fbcon_vga_bmove(struct display *p, int sy, int sx, int dy, int dx,
100 int height, int width)
105 if (sx == 0 && dx == 0 && width == p->next_line/2) {
106 src = (u16 *)(p->screen_base+sy*p->next_line);
107 dst = (u16 *)(p->screen_base+dy*p->next_line);
108 vga_memmovew(dst, src, height*width);
109 } else if (dy < sy || (dy == sy && dx < sx)) {
110 src = (u16 *)(p->screen_base+sy*p->next_line+sx*2);
111 dst = (u16 *)(p->screen_base+dy*p->next_line+dx*2);
112 for (rows = height; rows-- ;) {
113 vga_memmovew(dst, src, width);
114 src += p->next_line/2;
115 dst += p->next_line/2;
118 src = (u16 *)(p->screen_base+(sy+height-1)*p->next_line+sx*2);
119 dst = (u16 *)(p->screen_base+(dy+height-1)*p->next_line+dx*2);
120 for (rows = height; rows-- ;) {
121 vga_memmovew(dst, src, width);
122 src -= p->next_line/2;
123 dst -= p->next_line/2;
128 void fbcon_vga_clear(struct vc_data *conp, struct display *p, int sy, int sx,
129 int height, int width)
131 u16 *dest = (u16 *)(p->screen_base+sy*p->next_line+sx*2);
134 if (sx == 0 && width*2 == p->next_line)
135 vga_memsetw(dest, conp->vc_video_erase_char, height*width);
137 for (rows = height; rows-- ; dest += p->next_line/2)
138 vga_memsetw(dest, conp->vc_video_erase_char, width);
141 void fbcon_vga_putc(struct vc_data *conp, struct display *p, int c, int y,
144 u16 *dst = (u16 *)(p->screen_base+y*p->next_line+x*2);
145 if (conp->vc_can_do_color)
148 vga_writew(fbcon_vga_attr(p, c) | (c & 0xff), dst);
151 void fbcon_vga_putcs(struct vc_data *conp, struct display *p,
152 const unsigned short *s, int count, int y, int x)
154 u16 *dst = (u16 *)(p->screen_base+y*p->next_line+x*2);
156 if (conp->vc_can_do_color)
158 vga_writew(scr_readw(s++), dst++);
160 sattr = fbcon_vga_attr(p, scr_readw(s));
162 vga_writew(sattr | ((int) (scr_readw(s++)) & 0xff), dst++);
166 void fbcon_vga_revc(struct display *p, int x, int y)
168 u16 *dst = (u16 *)(p->screen_base+y*p->next_line+x*2);
169 u16 val = vga_readw(dst);
170 val = (val & 0x88ff) | ((val<<4) & 0x7000) | ((val>>4) & 0x0700);
171 vga_writew(val, dst);
176 * `switch' for the low level operations
179 struct display_switch fbcon_vga = {
180 setup: fbcon_vga_setup,
181 bmove: fbcon_vga_bmove,
182 clear: fbcon_vga_clear,
183 putc: fbcon_vga_putc,
184 putcs: fbcon_vga_putcs,
185 revc: fbcon_vga_revc,
186 fontwidthmask: FONTWIDTH(8)
191 MODULE_LICENSE("GPL");
193 int init_module(void)
198 void cleanup_module(void)
204 * Visible symbols for modules
207 EXPORT_SYMBOL(fbcon_vga);
208 EXPORT_SYMBOL(fbcon_vga_setup);
209 EXPORT_SYMBOL(fbcon_vga_bmove);
210 EXPORT_SYMBOL(fbcon_vga_clear);
211 EXPORT_SYMBOL(fbcon_vga_putc);
212 EXPORT_SYMBOL(fbcon_vga_putcs);
213 EXPORT_SYMBOL(fbcon_vga_revc);