Add constants for fast path resume copying
[coreboot.git] / src / pc80 / vga / vga_io.c
1 /*
2  * Copyright (C)  2007-2009  Luc Verhaegen <libv@skynet.be>
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /*
20  * All IO necessary to poke VGA registers.
21  */
22 #include <pc80/vga_io.h>
23
24 #include <arch/io.h>
25
26 #define VGA_CR_INDEX          0x3D4
27 #define VGA_CR_VALUE          0x3D5
28
29 #define VGA_SR_INDEX          0x3C4
30 #define VGA_SR_VALUE          0x3C5
31
32 #define VGA_GR_INDEX          0x3CE
33 #define VGA_GR_VALUE          0x3CF
34
35 #define VGA_AR_INDEX          0x3C0
36 #define VGA_AR_VALUE_READ     0x3C1
37 #define VGA_AR_VALUE_WRITE    VGA_AR_INDEX
38
39 #define VGA_MISC_WRITE        0x3C2
40 #define VGA_MISC_READ         0x3CC
41
42 #define VGA_ENABLE            0x3C3
43 #define VGA_STAT1             0x3DA
44
45 #define VGA_DAC_MASK          0x3C6
46 #define VGA_DAC_READ_ADDRESS  0x3C7
47 #define VGA_DAC_WRITE_ADDRESS 0x3C8
48 #define VGA_DAC_DATA          0x3C9
49
50 /*
51  * VGA enable. Poke this to have the PCI IO enabled device accept VGA IO.
52  */
53 unsigned char
54 vga_enable_read(void)
55 {
56         return inb(VGA_ENABLE);
57 }
58
59 void
60 vga_enable_write(unsigned char value)
61 {
62         outb(value, VGA_ENABLE);
63 }
64
65 void
66 vga_enable_mask(unsigned char value, unsigned char mask)
67 {
68         unsigned char tmp;
69
70         tmp = vga_enable_read();
71         tmp &= ~mask;
72         tmp |= (value & mask);
73         vga_enable_write(tmp);
74 }
75
76 /*
77  * Miscellaneous register.
78  */
79 unsigned char
80 vga_misc_read(void)
81 {
82         return inb(VGA_MISC_READ);
83 }
84
85 void
86 vga_misc_write(unsigned char value)
87 {
88         outb(value, VGA_MISC_WRITE);
89 }
90
91 void
92 vga_misc_mask(unsigned char value, unsigned char mask)
93 {
94         unsigned char tmp;
95
96         tmp = vga_misc_read();
97         tmp &= ~mask;
98         tmp |= (value & mask);
99         vga_misc_write(tmp);
100 }
101
102 /*
103  * Sequencer registers.
104  */
105 unsigned char
106 vga_sr_read(unsigned char index)
107 {
108         outb(index, VGA_SR_INDEX);
109         return (inb(VGA_SR_VALUE));
110 }
111
112 void
113 vga_sr_write(unsigned char index, unsigned char value)
114 {
115         outb(index, VGA_SR_INDEX);
116         outb(value, VGA_SR_VALUE);
117 }
118
119 void
120 vga_sr_mask(unsigned char index, unsigned char value, unsigned char mask)
121 {
122         unsigned char tmp;
123
124         tmp = vga_sr_read(index);
125         tmp &= ~mask;
126         tmp |= (value & mask);
127         vga_sr_write(index, tmp);
128 }
129
130 /*
131  * CRTC registers.
132  */
133 unsigned char
134 vga_cr_read(unsigned char index)
135 {
136         outb(index, VGA_CR_INDEX);
137         return (inb(VGA_CR_VALUE));
138 }
139
140 void
141 vga_cr_write(unsigned char index, unsigned char value)
142 {
143         outb(index, VGA_CR_INDEX);
144         outb(value, VGA_CR_VALUE);
145 }
146
147 void
148 vga_cr_mask(unsigned char index, unsigned char value, unsigned char mask)
149 {
150         unsigned char tmp;
151
152         tmp = vga_cr_read(index);
153         tmp &= ~mask;
154         tmp |= (value & mask);
155         vga_cr_write(index, tmp);
156 }
157
158 /*
159  * Attribute registers.
160  */
161 unsigned char
162 vga_ar_read(unsigned char index)
163 {
164         unsigned char ret;
165
166         (void) inb(VGA_STAT1);
167         outb(index, VGA_AR_INDEX);
168         ret = inb(VGA_AR_VALUE_READ);
169         (void) inb(VGA_STAT1);
170
171         return ret;
172 }
173
174 void
175 vga_ar_write(unsigned char index, unsigned char value)
176 {
177         (void) inb(VGA_STAT1);
178         outb(index, VGA_AR_INDEX);
179         outb(value, VGA_AR_VALUE_WRITE);
180         (void) inb(VGA_STAT1);
181 }
182
183 void
184 vga_ar_mask(unsigned char index, unsigned char value, unsigned char mask)
185 {
186         unsigned char tmp;
187
188         tmp = vga_ar_read(index);
189         tmp &= ~mask;
190         tmp |= (value & mask);
191         vga_ar_write(index, tmp);
192 }
193
194 /*
195  * Graphics registers.
196  */
197 unsigned char
198 vga_gr_read(unsigned char index)
199 {
200         outb(index, VGA_GR_INDEX);
201         return (inb(VGA_GR_VALUE));
202 }
203
204 void
205 vga_gr_write(unsigned char index, unsigned char value)
206 {
207         outb(index, VGA_GR_INDEX);
208         outb(value, VGA_GR_VALUE);
209 }
210
211 void
212 vga_gr_mask(unsigned char index, unsigned char value, unsigned char mask)
213 {
214         unsigned char tmp;
215
216         tmp = vga_gr_read(index);
217         tmp &= ~mask;
218         tmp |= (value & mask);
219         vga_gr_write(index, tmp);
220 }
221
222 /*
223  * DAC functions.
224  */
225 void
226 vga_palette_enable(void)
227 {
228         (void) inb(VGA_STAT1);
229         outb(0x00, VGA_AR_INDEX);
230         (void) inb(VGA_STAT1);
231 }
232
233 void
234 vga_palette_disable(void)
235 {
236         (void) inb(VGA_STAT1);
237         outb(0x20, VGA_AR_INDEX);
238         (void) inb(VGA_STAT1);
239 }
240
241 unsigned char
242 vga_dac_mask_read(void)
243 {
244         return inb(VGA_DAC_MASK);
245 }
246
247 void
248 vga_dac_mask_write(unsigned char mask)
249 {
250         outb(mask, VGA_DAC_MASK);
251 }
252
253 void
254 vga_dac_read_address(unsigned char address)
255 {
256         outb(address, VGA_DAC_READ_ADDRESS);
257 }
258
259 void
260 vga_dac_write_address(unsigned char address)
261 {
262         outb(address, VGA_DAC_WRITE_ADDRESS);
263 }
264
265 unsigned char
266 vga_dac_data_read(void)
267 {
268         return inb(VGA_DAC_DATA);
269 }
270
271 void
272 vga_dac_data_write(unsigned char data)
273 {
274         outb(data, VGA_DAC_DATA);
275 }