Rev 74 | Rev 169 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
54 | pj | 1 | /* SVGA Lib - Linker module to use the low level driver |
2 | * without the vga.c support |
||
3 | * |
||
4 | */ |
||
5 | |||
6 | /* variables used to shift between monchrome and color emulation */ |
||
7 | #include <stdint.h> |
||
8 | #include <unistd.h> |
||
9 | |||
10 | #include <ll/i386/hw-data.h> |
||
11 | #include <ll/i386/mem.h> |
||
12 | #include <ll/i386/cons.h> |
||
13 | #include <ll/sys/ll/ll-func.h> |
||
14 | |||
15 | #include "libvga.h" |
||
16 | #include "vgaversion.h" |
||
17 | #include "vgaio.h" |
||
18 | #include "driver.h" |
||
19 | |||
20 | int __svgalib_CRT_I; /* current CRT index register address */ |
||
21 | int __svgalib_CRT_D; /* current CRT data register address */ |
||
22 | int __svgalib_IS1_R; /* current input status register address */ |
||
23 | static int color_text; /* true if color text emulation */ |
||
24 | |||
25 | uint8_t *BANKED_POINTER=NULL, *LINEAR_POINTER; |
||
26 | uint8_t *MMIO_POINTER; |
||
27 | uint8_t *SPARSE_MMIO; |
||
28 | static int mmio_mapped=0, mem_mapped=0; |
||
29 | static uint8_t *B8000_POINTER=NULL; |
||
30 | unsigned long __svgalib_banked_mem_base, __svgalib_banked_mem_size; |
||
31 | unsigned long __svgalib_mmio_base, __svgalib_mmio_size=0; |
||
32 | unsigned long __svgalib_linear_mem_base=0, __svgalib_linear_mem_size=0; |
||
33 | |||
34 | extern int init_vgapci(void); |
||
35 | extern int nv3_test(void); |
||
36 | extern int savage_test(void); |
||
74 | giacomo | 37 | extern int r128_test(void); |
132 | giacomo | 38 | extern int neo_test(void); |
39 | extern int vesa_test(void); |
||
54 | pj | 40 | |
41 | /* If == 0 then nothing is defined by the user... */ |
||
42 | int __svgalib_default_mode = 10; |
||
43 | |||
44 | struct info infotable[] = |
||
45 | { |
||
46 | {80, 25, 16, 160, 0}, /* VGAlib VGA modes */ |
||
47 | {320, 200, 16, 40, 0}, |
||
48 | {640, 200, 16, 80, 0}, |
||
49 | {640, 350, 16, 80, 0}, |
||
50 | {640, 480, 16, 80, 0}, |
||
51 | {320, 200, 256, 320, 1}, |
||
52 | {320, 240, 256, 80, 0}, |
||
53 | {320, 400, 256, 80, 0}, |
||
54 | {360, 480, 256, 90, 0}, |
||
55 | {640, 480, 2, 80, 0}, |
||
56 | |||
57 | {640, 480, 256, 640, 1}, /* VGAlib SVGA modes */ |
||
58 | {800, 600, 256, 800, 1}, |
||
59 | {1024, 768, 256, 1024, 1}, |
||
60 | {1280, 1024, 256, 1280, 1}, |
||
61 | |||
62 | {320, 200, 1 << 15, 640, 2}, /* Hicolor/truecolor modes */ |
||
63 | {320, 200, 1 << 16, 640, 2}, |
||
64 | {320, 200, 1 << 24, 320 * 3, 3}, |
||
65 | {640, 480, 1 << 15, 640 * 2, 2}, |
||
66 | {640, 480, 1 << 16, 640 * 2, 2}, |
||
67 | {640, 480, 1 << 24, 640 * 3, 3}, |
||
68 | {800, 600, 1 << 15, 800 * 2, 2}, |
||
69 | {800, 600, 1 << 16, 800 * 2, 2}, |
||
70 | {800, 600, 1 << 24, 800 * 3, 3}, |
||
71 | {1024, 768, 1 << 15, 1024 * 2, 2}, |
||
72 | {1024, 768, 1 << 16, 1024 * 2, 2}, |
||
73 | {1024, 768, 1 << 24, 1024 * 3, 3}, |
||
74 | {1280, 1024, 1 << 15, 1280 * 2, 2}, |
||
75 | {1280, 1024, 1 << 16, 1280 * 2, 2}, |
||
76 | {1280, 1024, 1 << 24, 1280 * 3, 3}, |
||
77 | |||
78 | {800, 600, 16, 100, 0}, /* SVGA 16-color modes */ |
||
79 | {1024, 768, 16, 128, 0}, |
||
80 | {1280, 1024, 16, 160, 0}, |
||
81 | |||
82 | {720, 348, 2, 90, 0}, /* Hercules emulation mode */ |
||
83 | |||
84 | {320, 200, 1 << 24, 320 * 4, 4}, |
||
85 | {640, 480, 1 << 24, 640 * 4, 4}, |
||
86 | {800, 600, 1 << 24, 800 * 4, 4}, |
||
87 | {1024, 768, 1 << 24, 1024 * 4, 4}, |
||
88 | {1280, 1024, 1 << 24, 1280 * 4, 4}, |
||
89 | |||
90 | {1152, 864, 16, 144, 0}, |
||
91 | {1152, 864, 256, 1152, 1}, |
||
92 | {1152, 864, 1 << 15, 1152 * 2, 2}, |
||
93 | {1152, 864, 1 << 16, 1152 * 2, 2}, |
||
94 | {1152, 864, 1 << 24, 1152 * 3, 3}, |
||
95 | {1152, 864, 1 << 24, 1152 * 4, 4}, |
||
96 | |||
97 | {1600, 1200, 16, 200, 0}, |
||
98 | {1600, 1200, 256, 1600, 1}, |
||
99 | {1600, 1200, 1 << 15, 1600 * 2, 2}, |
||
100 | {1600, 1200, 1 << 16, 1600 * 2, 2}, |
||
101 | {1600, 1200, 1 << 24, 1600 * 3, 3}, |
||
102 | {1600, 1200, 1 << 24, 1600 * 4, 4}, |
||
103 | |||
104 | {320, 240, 256, 320, 1}, |
||
105 | {320, 240, 1<<15, 320*2, 2}, |
||
106 | {320, 240, 1<<16, 320*2, 2}, |
||
107 | {320, 240, 1<<24, 320*3, 3}, |
||
108 | {320, 240, 1<<24, 320*4, 4}, |
||
109 | |||
110 | {400, 300, 256, 400, 1}, |
||
111 | {400, 300, 1<<15, 400*2, 2}, |
||
112 | {400, 300, 1<<16, 400*2, 2}, |
||
113 | {400, 300, 1<<24, 400*3, 3}, |
||
114 | {400, 300, 1<<24, 400*4, 4}, |
||
115 | |||
116 | {512, 384, 256, 512, 1}, |
||
117 | {512, 384, 1<<15, 512*2, 2}, |
||
118 | {512, 384, 1<<16, 512*2, 2}, |
||
119 | {512, 384, 1<<24, 512*3, 3}, |
||
120 | {512, 384, 1<<24, 512*4, 4}, |
||
121 | |||
122 | {960, 720, 256, 960, 1}, |
||
123 | {960, 720, 1<<15, 960*2, 2}, |
||
124 | {960, 720, 1<<16, 960*2, 2}, |
||
125 | {960, 720, 1<<24, 960*3, 3}, |
||
126 | {960, 720, 1<<24, 960*4, 4}, |
||
127 | |||
128 | {1920, 1440, 256, 1920, 1}, |
||
129 | {1920, 1440, 1<<15, 1920*2, 2}, |
||
130 | {1920, 1440, 1<<16, 1920*2, 2}, |
||
131 | {1920, 1440, 1<<24, 1920*3, 3}, |
||
132 | {1920, 1440, 1<<24, 1920*4, 4}, |
||
133 | |||
134 | {320, 400, 1<<8, 320, 1}, |
||
135 | {320, 400, 1<<15, 320*2, 2}, |
||
136 | {320, 400, 1<<16, 320*2, 2}, |
||
137 | {320, 400, 1<<24, 320*3, 3}, |
||
138 | {320, 400, 1<<24, 320*4, 4}, |
||
139 | |||
140 | {640, 400, 256, 640, 1}, |
||
141 | {640, 400, 1<<15, 640*2, 2}, |
||
142 | {640, 400, 1<<16, 640*2, 2}, |
||
143 | {640, 400, 1<<24, 640*3, 3}, |
||
144 | {640, 400, 1<<24, 640*4, 4}, |
||
145 | |||
146 | {320, 480, 256, 320, 1}, |
||
147 | {320, 480, 1<<15, 320*2, 2}, |
||
148 | {320, 480, 1<<16, 320*2, 2}, |
||
149 | {320, 480, 1<<24, 320*3, 3}, |
||
150 | {320, 480, 1<<24, 320*4, 4}, |
||
151 | |||
152 | {720, 540, 256, 720, 1}, |
||
153 | {720, 540, 1<<15, 720*2, 2}, |
||
154 | {720, 540, 1<<16, 720*2, 2}, |
||
155 | {720, 540, 1<<24, 720*3, 3}, |
||
156 | {720, 540, 1<<24, 720*4, 4}, |
||
157 | |||
158 | {848, 480, 256, 848, 1}, |
||
159 | {848, 480, 1<<15, 848*2, 2}, |
||
160 | {848, 480, 1<<16, 848*2, 2}, |
||
161 | {848, 480, 1<<24, 848*3, 3}, |
||
162 | {848, 480, 1<<24, 848*4, 4}, |
||
163 | |||
164 | {1072, 600, 256, 1072, 1}, |
||
165 | {1072, 600, 1<<15, 1072*2, 2}, |
||
166 | {1072, 600, 1<<16, 1072*2, 2}, |
||
167 | {1072, 600, 1<<24, 1072*3, 3}, |
||
168 | {1072, 600, 1<<24, 1072*4, 4}, |
||
169 | |||
170 | {1280, 720, 256, 1280, 1}, |
||
171 | {1280, 720, 1<<15, 1280*2, 2}, |
||
172 | {1280, 720, 1<<16, 1280*2, 2}, |
||
173 | {1280, 720, 1<<24, 1280*3, 3}, |
||
174 | {1280, 720, 1<<24, 1280*4, 4}, |
||
175 | |||
176 | {1360, 768, 256, 1360, 1}, |
||
177 | {1360, 768, 1<<15, 1360*2, 2}, |
||
178 | {1360, 768, 1<<16, 1360*2, 2}, |
||
179 | {1360, 768, 1<<24, 1360*3, 3}, |
||
180 | {1360, 768, 1<<24, 1360*4, 4}, |
||
181 | |||
182 | {1800, 1012, 256, 1800, 1}, |
||
183 | {1800, 1012, 1<<15, 1800*2, 2}, |
||
184 | {1800, 1012, 1<<16, 1800*2, 2}, |
||
185 | {1800, 1012, 1<<24, 1800*3, 3}, |
||
186 | {1800, 1012, 1<<24, 1800*4, 4}, |
||
187 | |||
188 | {1920, 1080, 256, 1920, 1}, |
||
189 | {1920, 1080, 1<<15, 1920*2, 2}, |
||
190 | {1920, 1080, 1<<16, 1920*2, 2}, |
||
191 | {1920, 1080, 1<<24, 1920*3, 3}, |
||
192 | {1920, 1080, 1<<24, 1920*4, 4}, |
||
193 | |||
194 | {2048, 1152, 256, 2048, 1}, |
||
195 | {2048, 1152, 1<<15, 2048*2, 2}, |
||
196 | {2048, 1152, 1<<16, 2048*2, 2}, |
||
197 | {2048, 1152, 1<<24, 2048*3, 3}, |
||
198 | {2048, 1152, 1<<24, 2048*4, 4}, |
||
199 | |||
200 | {2048, 1536, 256, 2048, 1}, |
||
201 | {2048, 1536, 1<<15, 2048*2, 2}, |
||
202 | {2048, 1536, 1<<16, 2048*2, 2}, |
||
203 | {2048, 1536, 1<<24, 2048*3, 3}, |
||
204 | {2048, 1536, 1<<24, 2048*4, 4}, |
||
205 | |||
206 | {512, 480, 256, 512, 1}, |
||
207 | {512, 480, 1<<15, 512*2, 2}, |
||
208 | {512, 480, 1<<16, 512*2, 2}, |
||
209 | {512, 480, 1<<24, 512*3, 3}, |
||
210 | {512, 480, 1<<24, 512*4, 4}, |
||
211 | |||
212 | {400, 600, 256, 400, 1}, |
||
213 | {400, 600, 1<<15, 400*2, 2}, |
||
214 | {400, 600, 1<<16, 400*2, 2}, |
||
215 | {400, 600, 1<<24, 400*3, 3}, |
||
216 | {400, 600, 1<<24, 400*4, 4}, |
||
217 | |||
218 | {400, 300, 256, 100, 0}, |
||
219 | {320, 200, 256, 320, 1}, |
||
220 | {0, 0, 0, 0, 0}, |
||
221 | {0, 0, 0, 0, 0}, |
||
222 | {0, 0, 0, 0, 0}, |
||
223 | {0, 0, 0, 0, 0}, |
||
224 | {0, 0, 0, 0, 0}, |
||
225 | {0, 0, 0, 0, 0}, |
||
226 | {0, 0, 0, 0, 0}, |
||
227 | {0, 0, 0, 0, 0}, |
||
228 | {0, 0, 0, 0, 0}, |
||
229 | {0, 0, 0, 0, 0}, |
||
230 | {0, 0, 0, 0, 0}, |
||
231 | {0, 0, 0, 0, 0}, |
||
232 | {0, 0, 0, 0, 0}, |
||
233 | {0, 0, 0, 0, 0}, |
||
234 | {0, 0, 0, 0, 0} |
||
235 | }; |
||
236 | |||
237 | #define MAX_MODES (sizeof(infotable) / sizeof(struct info)) |
||
238 | |||
239 | void (*__svgalib_go_to_background) (void) = 0; |
||
240 | void (*__svgalib_come_from_background) (void) = 0; |
||
241 | static int release_acquire=0; |
||
242 | |||
243 | unsigned long __svgalib_graph_base = GRAPH_BASE; |
||
244 | |||
245 | unsigned char __svgalib_novga = 0; /* Does not have VGA circuitry on board */ |
||
246 | unsigned char __svgalib_vesatext = 0; |
||
247 | unsigned char __svgalib_textprog = 0; /* run a program when returning to text mode */ |
||
248 | unsigned char __svgalib_secondary = 0; /* this is not the main card with VC'S ) */ |
||
249 | unsigned char __svgalib_emulatepage = 0; /* don't use 0xa0000 memory */ |
||
250 | unsigned char __svgalib_novccontrol = 0; /* this is not the main card with VC'S */ |
||
251 | unsigned char __svgalib_ragedoubleclock = 0; |
||
252 | unsigned char __svgalib_simple = 0; |
||
253 | |||
254 | /* default palette values */ |
||
255 | static const unsigned char default_red[256] |
||
256 | = |
||
257 | {0, 0, 0, 0, 42, 42, 42, 42, 21, 21, 21, 21, 63, 63, 63, 63, |
||
258 | 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63, |
||
259 | 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 47, 31, 16, |
||
260 | 0, 0, 0, 0, 0, 0, 0, 0, 31, 39, 47, 55, 63, 63, 63, 63, |
||
261 | 63, 63, 63, 63, 63, 55, 47, 39, 31, 31, 31, 31, 31, 31, 31, 31, |
||
262 | 45, 49, 54, 58, 63, 63, 63, 63, 63, 63, 63, 63, 63, 58, 54, 49, |
||
263 | 45, 45, 45, 45, 45, 45, 45, 45, 0, 7, 14, 21, 28, 28, 28, 28, |
||
264 | 28, 28, 28, 28, 28, 21, 14, 7, 0, 0, 0, 0, 0, 0, 0, 0, |
||
265 | 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 24, 21, 17, |
||
266 | 14, 14, 14, 14, 14, 14, 14, 14, 20, 22, 24, 26, 28, 28, 28, 28, |
||
267 | 28, 28, 28, 28, 28, 26, 24, 22, 20, 20, 20, 20, 20, 20, 20, 20, |
||
268 | 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 8, 4, |
||
269 | 0, 0, 0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 16, 16, 16, |
||
270 | 16, 16, 16, 16, 16, 14, 12, 10, 8, 8, 8, 8, 8, 8, 8, 8, |
||
271 | 11, 12, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 13, 12, |
||
272 | 11, 11, 11, 11, 11, 11, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0}; |
||
273 | static const unsigned char default_green[256] |
||
274 | = |
||
275 | {0, 0, 42, 42, 0, 0, 21, 42, 21, 21, 63, 63, 21, 21, 63, 63, |
||
276 | 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63, |
||
277 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 31, 47, 63, 63, 63, 63, |
||
278 | 63, 63, 63, 63, 63, 47, 31, 16, 31, 31, 31, 31, 31, 31, 31, 31, |
||
279 | 31, 39, 47, 55, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39, |
||
280 | 45, 45, 45, 45, 45, 45, 45, 45, 45, 49, 54, 58, 63, 63, 63, 63, |
||
281 | 63, 63, 63, 63, 63, 58, 54, 49, 0, 0, 0, 0, 0, 0, 0, 0, |
||
282 | 0, 7, 14, 21, 29, 28, 28, 28, 28, 28, 28, 28, 28, 21, 14, 7, |
||
283 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 17, 21, 24, 28, 28, 28, 28, |
||
284 | 28, 28, 28, 28, 28, 24, 21, 17, 20, 20, 20, 20, 20, 20, 20, 20, |
||
285 | 20, 22, 24, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22, |
||
286 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 12, 16, 16, 16, 16, |
||
287 | 16, 16, 16, 16, 16, 12, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8, |
||
288 | 8, 10, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, |
||
289 | 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 15, 16, 16, 16, 16, |
||
290 | 16, 16, 16, 16, 16, 15, 13, 12, 0, 0, 0, 0, 0, 0, 0, 0}; |
||
291 | static const unsigned char default_blue[256] |
||
292 | = |
||
293 | {0, 42, 0, 42, 0, 42, 0, 42, 21, 63, 21, 63, 21, 63, 21, 63, |
||
294 | 0, 5, 8, 11, 14, 17, 20, 24, 28, 32, 36, 40, 45, 50, 56, 63, |
||
295 | 63, 63, 63, 63, 63, 47, 31, 16, 0, 0, 0, 0, 0, 0, 0, 0, |
||
296 | 0, 16, 31, 47, 63, 63, 63, 63, 63, 63, 63, 63, 63, 55, 47, 39, |
||
297 | 31, 31, 31, 31, 31, 31, 31, 31, 31, 39, 47, 55, 63, 63, 63, 63, |
||
298 | 63, 63, 63, 63, 63, 58, 54, 49, 45, 45, 45, 45, 45, 45, 45, 45, |
||
299 | 45, 49, 54, 58, 63, 63, 63, 63, 28, 28, 28, 28, 28, 21, 14, 7, |
||
300 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 14, 21, 28, 28, 28, 28, |
||
301 | 28, 28, 28, 28, 28, 24, 21, 17, 14, 14, 14, 14, 14, 14, 14, 14, |
||
302 | 14, 17, 21, 24, 28, 28, 28, 28, 28, 28, 28, 28, 28, 26, 24, 22, |
||
303 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 22, 24, 26, 28, 28, 28, 28, |
||
304 | 16, 16, 16, 16, 16, 12, 8, 4, 0, 0, 0, 0, 0, 0, 0, 0, |
||
305 | 0, 4, 8, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 10, |
||
306 | 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 12, 14, 16, 16, 16, 16, |
||
307 | 16, 16, 16, 16, 16, 15, 13, 12, 11, 11, 11, 11, 11, 11, 11, 11, |
||
308 | 11, 12, 13, 15, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0}; |
||
309 | |||
310 | static unsigned char text_regs[MAX_REGS]; /* VGA registers for saved text mode */ |
||
311 | |||
312 | char *__svgalib_TextProg_argv[16]; /* should be enough */ |
||
313 | char *__svgalib_TextProg; |
||
314 | |||
315 | /* saved text mode palette values */ |
||
316 | static unsigned char text_red[256]; |
||
317 | static unsigned char text_green[256]; |
||
318 | static unsigned char text_blue[256]; |
||
319 | |||
320 | /* saved graphics mode palette values */ |
||
321 | static unsigned char graph_red[256]; |
||
322 | static unsigned char graph_green[256]; |
||
323 | static unsigned char graph_blue[256]; |
||
324 | |||
325 | static int prv_mode = TEXT; /* previous video mode */ |
||
326 | static int flip_mode = TEXT; /* flipped video mode */ |
||
327 | |||
328 | int CM = TEXT; /* current video mode */ |
||
329 | struct info CI; /* current video parameters */ |
||
330 | int COL; /* current color */ |
||
331 | |||
332 | static int initialized = 0; /* flag: initialize() called ? */ |
||
333 | static int flip = 0; /* flag: executing vga_flip() ? */ |
||
334 | static int background_fd = -1; |
||
335 | |||
336 | /* svgalib additions: */ |
||
337 | int __svgalib_chipset = UNDEFINED; |
||
338 | int __svgalib_driver_report = 1; |
||
339 | /* report driver used after chipset detection */ |
||
340 | int __svgalib_videomemoryused = -1; |
||
341 | int __svgalib_modeX = 0; /* true after vga_setmodeX() */ |
||
342 | int __svgalib_modeflags = 0; /* copy of flags for current mode */ |
||
343 | int __svgalib_critical = 0; /* indicates blitter is busy */ |
||
344 | int __svgalib_screenon = 1; /* screen visible if != 0 */ |
||
345 | int __svgalib_vgacolormode = 1; /* assume color for now. needs to be |
||
346 | config file option */ |
||
347 | |||
348 | static int __svgalib_savemem=0; |
||
349 | |||
350 | RefreshRange __svgalib_horizsync = |
||
351 | {31500U, 60000U}; /* horz. refresh (Hz) min, max */ |
||
352 | RefreshRange __svgalib_vertrefresh = |
||
353 | {50U, 70U}; /* vert. refresh (Hz) min, max */ |
||
354 | int __svgalib_bandwidth=50000; /* monitor maximum bandwidth (kHz) */ |
||
355 | int __svgalib_grayscale = 0; /* grayscale vs. color mode */ |
||
356 | int __svgalib_modeinfo_linearset = 0; /* IS_LINEAR handled via extended vga_modeinfo */ |
||
357 | const int __svgalib_max_modes = MAX_MODES; /* Needed for dynamical allocated tables in mach32.c */ |
||
358 | |||
359 | static unsigned __svgalib_maxhsync[] = |
||
360 | { |
||
361 | 31500, 35100, 35500, 37900, 48300, 56000, 60000 |
||
362 | }; |
||
363 | |||
364 | static int lastmodenumber = __GLASTMODE; /* Last defined mode */ |
||
365 | static int my_pid = 0; /* process PID, used with atexit() */ |
||
366 | static int __svgalib_currentpage; |
||
367 | static int vga_page_offset; /* offset to add to all vga_set*page() calls */ |
||
368 | static int currentlogicalwidth; |
||
369 | static int currentdisplaystart; |
||
370 | static int mouse_support = 0; |
||
371 | int mouse_open = 0; |
||
372 | static int mouse_mode = 0; |
||
373 | static int mouse_type = -1; |
||
374 | static int mouse_modem_ctl = 0; |
||
375 | char *__svgalib_mouse_device = "/dev/mouse"; |
||
376 | int __svgalib_mouse_flag; |
||
377 | static char *mem_device = "/dev/svga"; |
||
378 | static int __svgalib_oktowrite = 1; |
||
379 | static int modeinfo_mask = ~0; |
||
380 | |||
381 | int __svgalib_mem_fd = -1; /* /dev/svga file descriptor */ |
||
382 | int __svgalib_tty_fd = -1; /* /dev/tty file descriptor */ |
||
383 | int __svgalib_nosigint = 0; /* Don't generate SIGINT in graphics mode */ |
||
384 | int __svgalib_runinbackground = 0; |
||
385 | int __svgalib_startup_vc = -1; |
||
386 | static int __svgalib_security_revokeallprivs = 1; |
||
387 | static unsigned fontbufsize = 8192; /* compatibility */ |
||
388 | |||
389 | /* Dummy buffer for mmapping grahics memory; points to 64K VGA framebuffer. */ |
||
390 | unsigned char *GM; |
||
391 | /* Exported variable (read-only) is shadowed from internal variable, for */ |
||
392 | /* better shared library performance. */ |
||
393 | unsigned char *graph_mem; |
||
394 | |||
395 | void *__svgalib_physaddr; |
||
396 | int __svgalib_linear_memory_size; |
||
397 | |||
398 | static unsigned long graph_buf_size = 0; |
||
399 | static unsigned char *graph_buf = NULL; /* saves graphics data during flip */ |
||
400 | static int inbackground=0; |
||
401 | |||
402 | static unsigned char *font_buf1; /* saved font data - plane 2 */ |
||
403 | static unsigned char *font_buf2; /* saved font data - plane 3 */ |
||
404 | static unsigned char *text_buf1=NULL; /* saved text data - plane 0 */ |
||
405 | static unsigned char *text_buf2; /* saved text data - plane 1 */ |
||
406 | |||
407 | int __svgalib_flipchar = '\x1b'; /* flip character - initially ESCAPE */ |
||
408 | |||
409 | /* Chipset specific functions */ |
||
410 | |||
411 | DriverSpecs *__svgalib_driverspecs = &__svgalib_vga_driverspecs; |
||
412 | |||
413 | static void (*__svgalib_setpage) (int); /* gives little faster vga_setpage() */ |
||
414 | static void (*__svgalib_setrdpage) (int); |
||
415 | static void (*__svgalib_setwrpage) (int); |
||
416 | |||
417 | int (*__svgalib_inmisc)(void); |
||
418 | void (*__svgalib_outmisc)(int); |
||
419 | int (*__svgalib_incrtc)(int); |
||
420 | void (*__svgalib_outcrtc)(int,int); |
||
421 | int (*__svgalib_inseq)(int); |
||
422 | void (*__svgalib_outseq)(int,int); |
||
423 | int (*__svgalib_ingra)(int); |
||
424 | void (*__svgalib_outgra)(int,int); |
||
425 | int (*__svgalib_inatt)(int); |
||
426 | void (*__svgalib_outatt)(int,int); |
||
427 | void (*__svgalib_attscreen)(int); |
||
428 | void (*__svgalib_inpal)(int,int*,int*,int*); |
||
429 | void (*__svgalib_outpal)(int,int,int,int); |
||
430 | int (*__svgalib_inis1)(void); |
||
431 | |||
432 | void map_banked(void); |
||
433 | void map_banked_fix(void); |
||
434 | inline void vga_setpage(int p); |
||
435 | |||
436 | DriverSpecs *__svgalib_driverspecslist[] = |
||
437 | { |
||
438 | NULL, /* chipset undefined */ |
||
439 | &__svgalib_vga_driverspecs, |
||
440 | #ifdef INCLUDE_ET4000_DRIVER |
||
441 | &__svgalib_et4000_driverspecs, |
||
442 | #else |
||
443 | NULL, |
||
444 | #endif |
||
445 | #ifdef INCLUDE_CIRRUS_DRIVER |
||
446 | &__svgalib_cirrus_driverspecs, |
||
447 | #else |
||
448 | NULL, |
||
449 | #endif |
||
450 | #ifdef INCLUDE_TVGA_DRIVER |
||
451 | &__svgalib_tvga8900_driverspecs, |
||
452 | #else |
||
453 | NULL, |
||
454 | #endif |
||
455 | #ifdef INCLUDE_OAK_DRIVER |
||
456 | &__svgalib_oak_driverspecs, |
||
457 | #else |
||
458 | NULL, |
||
459 | #endif |
||
460 | #ifdef INCLUDE_EGA_DRIVER |
||
461 | &__svgalib_ega_driverspecs, |
||
462 | #else |
||
463 | NULL, |
||
464 | #endif |
||
465 | #ifdef INCLUDE_S3_DRIVER |
||
466 | &__svgalib_s3_driverspecs, |
||
467 | #else |
||
468 | NULL, |
||
469 | #endif |
||
470 | #ifdef INCLUDE_ET3000_DRIVER |
||
471 | &__svgalib_et3000_driverspecs, |
||
472 | #else |
||
473 | NULL, |
||
474 | #endif |
||
475 | #ifdef INCLUDE_MACH32_DRIVER |
||
476 | &__svgalib_mach32_driverspecs, |
||
477 | #else |
||
478 | NULL, |
||
479 | #endif |
||
480 | #ifdef INCLUDE_GVGA6400_DRIVER |
||
481 | &__svgalib_gvga6400_driverspecs, |
||
482 | #else |
||
483 | NULL, |
||
484 | #endif |
||
485 | #ifdef INCLUDE_ARK_DRIVER |
||
486 | &__svgalib_ark_driverspecs, |
||
487 | #else |
||
488 | NULL, |
||
489 | #endif |
||
490 | #ifdef INCLUDE_ATI_DRIVER |
||
491 | &__svgalib_ati_driverspecs, |
||
492 | #else |
||
493 | NULL, |
||
494 | #endif |
||
495 | #ifdef INCLUDE_ALI_DRIVER |
||
496 | &__svgalib_ali_driverspecs, |
||
497 | #else |
||
498 | NULL, |
||
499 | #endif |
||
500 | #ifdef INCLUDE_MACH64_DRIVER |
||
501 | &__svgalib_mach64_driverspecs, |
||
502 | #else |
||
503 | NULL, |
||
504 | #endif |
||
505 | #ifdef INCLUDE_CHIPS_DRIVER |
||
506 | &__svgalib_chips_driverspecs, |
||
507 | #else |
||
508 | NULL, |
||
509 | #endif |
||
510 | #ifdef INCLUDE_APM_DRIVER |
||
511 | &__svgalib_apm_driverspecs, |
||
512 | #else |
||
513 | NULL, |
||
514 | #endif |
||
515 | #ifdef INCLUDE_NV3_DRIVER |
||
516 | &__svgalib_nv3_driverspecs, |
||
517 | #else |
||
518 | NULL, |
||
519 | #endif |
||
520 | #ifdef INCLUDE_ET6000_DRIVER |
||
521 | &__svgalib_et6000_driverspecs, |
||
522 | #else |
||
523 | NULL, |
||
524 | #endif |
||
525 | #ifdef INCLUDE_VESA_DRIVER |
||
526 | &__svgalib_vesa_driverspecs, |
||
527 | #else |
||
528 | NULL, |
||
529 | #endif |
||
530 | #ifdef INCLUDE_MX_DRIVER |
||
531 | &__svgalib_mx_driverspecs, |
||
532 | #else |
||
533 | NULL, |
||
534 | #endif |
||
535 | #ifdef INCLUDE_PARADISE_DRIVER |
||
536 | &__svgalib_paradise_driverspecs, |
||
537 | #else |
||
538 | NULL, |
||
539 | #endif |
||
540 | #ifdef INCLUDE_RAGE_DRIVER |
||
541 | &__svgalib_rage_driverspecs, |
||
542 | #else |
||
543 | NULL, |
||
544 | #endif |
||
545 | #ifdef INCLUDE_BANSHEE_DRIVER |
||
546 | &__svgalib_banshee_driverspecs, |
||
547 | #else |
||
548 | NULL, |
||
549 | #endif |
||
550 | #ifdef INCLUDE_SIS_DRIVER |
||
551 | &__svgalib_sis_driverspecs, |
||
552 | #else |
||
553 | NULL, |
||
554 | #endif |
||
555 | #ifdef INCLUDE_I740_DRIVER |
||
556 | &__svgalib_i740_driverspecs, |
||
557 | #else |
||
558 | NULL, |
||
559 | #endif |
||
560 | #ifdef INCLUDE_NEO_DRIVER |
||
561 | &__svgalib_neo_driverspecs, |
||
562 | #else |
||
563 | NULL, |
||
564 | #endif |
||
565 | #ifdef INCLUDE_LAGUNA_DRIVER |
||
566 | &__svgalib_laguna_driverspecs, |
||
567 | #else |
||
568 | NULL, |
||
569 | #endif |
||
570 | #ifdef INCLUDE_FBDEV_DRIVER |
||
571 | &__svgalib_fbdev_driverspecs, |
||
572 | #else |
||
573 | NULL, |
||
574 | #endif |
||
575 | #ifdef INCLUDE_G400_DRIVER |
||
576 | &__svgalib_g400_driverspecs, |
||
577 | #else |
||
578 | NULL, |
||
579 | #endif |
||
580 | #ifdef INCLUDE_R128_DRIVER |
||
581 | &__svgalib_r128_driverspecs, |
||
582 | #else |
||
583 | NULL, |
||
584 | #endif |
||
585 | #ifdef INCLUDE_SAVAGE_DRIVER |
||
586 | &__svgalib_savage_driverspecs, |
||
587 | #else |
||
588 | NULL, |
||
589 | #endif |
||
590 | #ifdef INCLUDE_MILLENNIUM_DRIVER |
||
591 | &__svgalib_mil_driverspecs, |
||
592 | #else |
||
593 | NULL, |
||
594 | #endif |
||
595 | #ifdef INCLUDE_I810_DRIVER |
||
596 | &__svgalib_i810_driverspecs, |
||
597 | #else |
||
598 | NULL, |
||
599 | #endif |
||
600 | #ifdef INCLUDE_TRIDENT_DRIVER |
||
601 | &__svgalib_trident_driverspecs, |
||
602 | #else |
||
603 | NULL, |
||
604 | #endif |
||
605 | #ifdef INCLUDE_RENDITION_DRIVER |
||
606 | &__svgalib_rendition_driverspecs, |
||
607 | #else |
||
608 | NULL, |
||
609 | #endif |
||
610 | #ifdef INCLUDE_G450C2_DRIVER |
||
611 | &__svgalib_g450c2_driverspecs, |
||
612 | #else |
||
613 | NULL, |
||
614 | #endif |
||
615 | #ifdef INCLUDE_PM2_DRIVER |
||
616 | &__svgalib_pm2_driverspecs, |
||
617 | #else |
||
618 | NULL, |
||
619 | #endif |
||
620 | }; |
||
621 | |||
622 | static char *driver_names[] = |
||
623 | { |
||
624 | "", |
||
625 | "VGA", |
||
626 | "ET4000", |
||
627 | "Cirrus", |
||
628 | "TVGA", |
||
629 | "Oak", |
||
630 | "EGA", |
||
631 | "S3", |
||
632 | "ET3000", |
||
633 | "Mach32", |
||
634 | "GVGA6400", |
||
635 | "ARK", |
||
636 | "ATI", |
||
637 | "ALI", |
||
638 | "Mach64", |
||
639 | "C&T", |
||
640 | "APM", |
||
641 | "NV3", |
||
642 | "ET6000", |
||
643 | "VESA", |
||
644 | "MX", |
||
645 | "PARADISE", |
||
646 | "RAGE", |
||
647 | "BANSHEE", |
||
648 | "SIS", |
||
649 | "I740", |
||
650 | "NEOMAGIC", |
||
651 | "LAGUNA", |
||
652 | "FBDev", |
||
653 | "G400", |
||
654 | "R128", |
||
655 | "SAVAGE", |
||
656 | "MILLENNIUM", |
||
657 | "I810", |
||
658 | "TRIDENT", |
||
659 | "RENDITION", |
||
660 | "G450C2", |
||
661 | "PM2", |
||
662 | NULL}; |
||
663 | |||
664 | /* Chipset drivers */ |
||
665 | |||
666 | /* vgadrv Standard VGA (also used by drivers below) */ |
||
667 | /* et4000 Tseng ET4000 (from original vgalib) */ |
||
668 | /* cirrus Cirrus Logic GD542x */ |
||
669 | /* tvga8900 Trident TVGA 8900/9000 (derived from tvgalib) */ |
||
670 | /* oak Oak Technologies 037/067/077 */ |
||
671 | /* egadrv IBM EGA (subset of VGA) */ |
||
672 | /* s3 S3 911 */ |
||
673 | /* mach32 ATI MACH32 */ |
||
674 | /* ark ARK Logic */ |
||
675 | /* gvga6400 Genoa 6400 (old SVGA) */ |
||
676 | /* ati ATI */ |
||
677 | /* ali ALI2301 */ |
||
678 | /* mach64 ATI MACH64 */ |
||
679 | /* chips chips & technologies*/ |
||
680 | /* et6000 Tseng ET6000 */ /* DS */ |
||
681 | |||
682 | inline void vga_setpage(int p) |
||
683 | { |
||
684 | p += vga_page_offset; |
||
685 | if (p == __svgalib_currentpage) |
||
686 | return; |
||
687 | |||
688 | __svgalib_currentpage = p; |
||
689 | } |
||
690 | |||
691 | int __svgalib_setregs(const unsigned char *regs) |
||
692 | { |
||
693 | int i; |
||
694 | |||
695 | if(__svgalib_novga) return 1; |
||
696 | |||
697 | if (__svgalib_chipset == EGA) { |
||
698 | /* Enable graphics register modification */ |
||
699 | port_out(0x00, GRA_E0); |
||
700 | port_out(0x01, GRA_E1); |
||
701 | } |
||
702 | /* update misc output register */ |
||
703 | __svgalib_outmisc(regs[MIS]); |
||
704 | |||
705 | /* synchronous reset on */ |
||
706 | __svgalib_outseq(0x00,0x01); |
||
707 | |||
708 | /* write sequencer registers */ |
||
709 | __svgalib_outseq(0x01,regs[SEQ + 1] | 0x20); |
||
710 | for (i = 2; i < SEQ_C; i++) { |
||
711 | __svgalib_outseq(i,regs[SEQ + i]); |
||
712 | } |
||
713 | |||
714 | /* synchronous reset off */ |
||
715 | __svgalib_outseq(0x00,0x03); |
||
716 | |||
717 | if (__svgalib_chipset != EGA) { |
||
718 | /* deprotect CRT registers 0-7 */ |
||
719 | __svgalib_outcrtc(0x11,__svgalib_incrtc(0x11)&0x7f); |
||
720 | } |
||
721 | /* write CRT registers */ |
||
722 | for (i = 0; i < CRT_C; i++) { |
||
723 | __svgalib_outcrtc(i,regs[CRT + i]); |
||
724 | } |
||
725 | |||
726 | /* write graphics controller registers */ |
||
727 | for (i = 0; i < GRA_C; i++) { |
||
728 | __svgalib_outgra(i,regs[GRA+i]); |
||
729 | } |
||
730 | |||
731 | /* write attribute controller registers */ |
||
732 | for (i = 0; i < ATT_C; i++) { |
||
733 | __svgalib_outatt(i,regs[ATT+i]); |
||
734 | } |
||
735 | |||
736 | return 0; |
||
737 | } |
||
738 | |||
739 | int vga_screenon(void) |
||
740 | { |
||
741 | int tmp = 0; |
||
742 | |||
743 | SCREENON = 1; |
||
744 | if(__svgalib_novga) return 0; |
||
745 | if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->screenon) { |
||
746 | tmp = __svgalib_driverspecs->emul->screenon(); |
||
747 | } else { |
||
748 | /* turn screen back on */ |
||
749 | if ((CHIPSET != EGA) && !__svgalib_novga) { |
||
750 | __svgalib_outseq(0x01,__svgalib_inseq(0x01) & 0xdf); |
||
751 | } |
||
752 | /* #ifdef DISABLE_VIDEO_OUTPUT */ |
||
753 | /* enable video output */ |
||
754 | __svgalib_attscreen(0x20); |
||
755 | /* #endif */ |
||
756 | } |
||
757 | |||
758 | return 0; |
||
759 | } |
||
760 | |||
761 | int vga_claimvideomemory(int m) |
||
762 | { |
||
763 | vga_modeinfo *modeinfo; |
||
764 | int cardmemory; |
||
765 | |||
766 | modeinfo = vga_getmodeinfo(CM); |
||
767 | if (m < VMEM) |
||
768 | return 0; |
||
769 | if (modeinfo->colors == 16) |
||
770 | cardmemory = modeinfo->maxpixels / 2; |
||
771 | else |
||
772 | cardmemory = (modeinfo->maxpixels * modeinfo->bytesperpixel |
||
773 | + 2) & 0xffff0000; |
||
774 | /* maxpixels * bytesperpixel can be 2 less than video memory in */ |
||
775 | /* 3 byte-per-pixel modes; assume memory is multiple of 64K */ |
||
776 | if (m > cardmemory) |
||
777 | return -1; |
||
778 | VMEM = m; |
||
779 | return 0; |
||
780 | } |
||
781 | |||
782 | void map_banked() { |
||
783 | |||
784 | if(__svgalib_emulatepage){ |
||
785 | BANKED_POINTER=(void *)__svgalib_linear_mem_base; |
||
786 | } else { |
||
787 | BANKED_POINTER=(void *)__svgalib_banked_mem_base; |
||
788 | } |
||
789 | |||
790 | } |
||
791 | |||
792 | void map_mmio() { |
||
793 | |||
794 | if(mmio_mapped) return; |
||
795 | |||
796 | if(__svgalib_mmio_size) { |
||
797 | mmio_mapped=1; |
||
798 | MMIO_POINTER=(void *)__svgalib_mmio_base; |
||
799 | } else { |
||
800 | MMIO_POINTER=NULL; |
||
801 | SPARSE_MMIO=NULL; |
||
802 | } |
||
803 | } |
||
804 | |||
805 | void map_mem() { |
||
806 | |||
807 | if(mem_mapped) return; |
||
808 | |||
809 | if(__svgalib_banked_mem_size==0) __svgalib_banked_mem_size = 0x10000; |
||
810 | |||
811 | map_banked(); |
||
812 | |||
813 | if(__svgalib_linear_mem_size) { |
||
814 | map_linear(__svgalib_linear_mem_base, __svgalib_linear_mem_size); |
||
815 | }; |
||
816 | |||
817 | B8000_POINTER = (void *)0xb8000; |
||
818 | |||
819 | mem_mapped = 1; |
||
820 | |||
821 | } |
||
822 | |||
823 | static void __vga_map(void) |
||
824 | { |
||
825 | GM = (unsigned char *) BANKED_POINTER; |
||
826 | graph_mem = GM; /* Exported variable. */ |
||
827 | } |
||
828 | |||
74 | giacomo | 829 | void __svgalib_emul_setpage(int page) |
830 | { |
||
831 | static int oldpage = -2; |
||
832 | |||
833 | if (page != oldpage) |
||
834 | { |
||
835 | oldpage = page; |
||
836 | } |
||
837 | } |
||
838 | |||
54 | pj | 839 | static void map_vgaio(void) |
840 | { |
||
841 | __svgalib_inmisc=__svgalib_vga_inmisc; |
||
842 | __svgalib_outmisc=__svgalib_vga_outmisc; |
||
843 | __svgalib_incrtc=__svgalib_vga_incrtc; |
||
844 | __svgalib_outcrtc=__svgalib_vga_outcrtc; |
||
845 | __svgalib_inseq=__svgalib_vga_inseq; |
||
846 | __svgalib_outseq=__svgalib_vga_outseq; |
||
847 | __svgalib_ingra=__svgalib_vga_ingra; |
||
848 | __svgalib_outgra=__svgalib_vga_outgra; |
||
849 | __svgalib_inatt=__svgalib_vga_inatt; |
||
850 | __svgalib_outatt=__svgalib_vga_outatt; |
||
851 | __svgalib_attscreen=__svgalib_vga_attscreen; |
||
852 | __svgalib_inpal=__svgalib_vga_inpal; |
||
853 | __svgalib_outpal=__svgalib_vga_outpal; |
||
854 | __svgalib_inis1=__svgalib_vga_inis1; |
||
855 | } |
||
856 | |||
857 | int __svgalib_saveregs(unsigned char *regs) |
||
858 | { |
||
859 | int i; |
||
860 | |||
861 | if (__svgalib_chipset == EGA || __svgalib_novga) { |
||
862 | /* Special case: Don't save standard VGA registers. */ |
||
863 | return chipset_saveregs(regs); |
||
864 | } |
||
865 | /* save VGA registers */ |
||
866 | for (i = 0; i < CRT_C; i++) { |
||
867 | regs[CRT + i] = __svgalib_incrtc(i); |
||
868 | } |
||
869 | for (i = 0; i < ATT_C; i++) { |
||
870 | regs[ATT + i] = __svgalib_inatt(i); |
||
871 | } |
||
872 | for (i = 0; i < GRA_C; i++) { |
||
873 | regs[GRA + i] = __svgalib_ingra(i); |
||
874 | } |
||
875 | for (i = 0; i < SEQ_C; i++) { |
||
876 | regs[SEQ + i] = __svgalib_inseq(i); |
||
877 | } |
||
878 | regs[MIS] = __svgalib_inmisc(); |
||
879 | |||
880 | i = chipset_saveregs(regs); /* save chipset-specific registers */ |
||
881 | /* i : additional registers */ |
||
882 | if (!SCREENON) { /* We turned off the screen */ |
||
883 | __svgalib_attscreen(0x20); |
||
884 | } |
||
885 | return CRT_C + ATT_C + GRA_C + SEQ_C + 1 + i; |
||
886 | } |
||
887 | |||
888 | int vga_setcolor(int color) |
||
889 | { |
||
890 | switch (CI.colors) { |
||
891 | case 2: |
||
892 | if (color != 0) |
||
893 | color = 15; |
||
894 | case 16: /* update set/reset register */ |
||
895 | __svgalib_outgra(0x00,color&0x0f); |
||
896 | break; |
||
897 | default: |
||
898 | COL = color; |
||
899 | break; |
||
900 | } |
||
901 | return 0; |
||
902 | } |
||
903 | |||
904 | vga_modeinfo *vga_getmodeinfo(int mode) |
||
905 | { |
||
906 | static vga_modeinfo modeinfo; |
||
907 | int is_modeX = (CM == mode) && MODEX; |
||
908 | |||
909 | printk(KERN_INFO "getmodeinfo %i\n",mode); |
||
910 | |||
911 | modeinfo.linewidth = infotable[mode].xbytes; |
||
912 | __svgalib_getchipset(CHIPSET); |
||
913 | if (mode > vga_lastmodenumber()) |
||
914 | return NULL; |
||
915 | modeinfo.width = infotable[mode].xdim; |
||
916 | modeinfo.height = infotable[mode].ydim; |
||
917 | modeinfo.bytesperpixel = infotable[mode].bytesperpixel; |
||
918 | modeinfo.colors = infotable[mode].colors; |
||
919 | if (is_modeX) { |
||
920 | modeinfo.linewidth = modeinfo.width / 4; |
||
921 | modeinfo.bytesperpixel = 0; |
||
922 | } |
||
923 | if (mode == TEXT) { |
||
924 | modeinfo.flags = HAVE_EXT_SET; |
||
925 | return &modeinfo; |
||
926 | } |
||
927 | modeinfo.flags = 0; |
||
928 | if ((STDVGAMODE(mode) && mode != G320x200x256) || is_modeX) |
||
929 | __svgalib_vga_driverspecs.getmodeinfo(mode, &modeinfo); |
||
930 | else |
||
931 | /* Get chipset specific info for SVGA modes and */ |
||
932 | /* 320x200x256 (chipsets may support more pages) */ |
||
933 | chipset_getmodeinfo(mode, &modeinfo); |
||
934 | |||
935 | if (modeinfo.colors == 256 && modeinfo.bytesperpixel == 0) |
||
936 | modeinfo.flags |= IS_MODEX; |
||
937 | if (mode > __GLASTMODE) |
||
938 | modeinfo.flags |= IS_DYNAMICMODE; |
||
939 | |||
940 | /* Maskout CAPABLE_LINEAR if requested by config file */ |
||
941 | modeinfo.flags &= modeinfo_mask; |
||
942 | |||
943 | /* Many cards have problems with linear 320x200x256 mode */ |
||
944 | if(mode==G320x200x256)modeinfo.flags &= (~CAPABLE_LINEAR) & (~IS_LINEAR) ; |
||
945 | |||
946 | /* If all needed info is here, signal if linear support has been enabled */ |
||
947 | if ((modeinfo.flags & (CAPABLE_LINEAR | EXT_INFO_AVAILABLE)) == |
||
948 | (CAPABLE_LINEAR | EXT_INFO_AVAILABLE)) { |
||
949 | modeinfo.flags |= __svgalib_modeinfo_linearset; |
||
950 | } |
||
951 | |||
952 | return &modeinfo; |
||
953 | } |
||
954 | |||
955 | char *__svgalib_token(char **ptr) |
||
956 | { |
||
957 | char *p; |
||
958 | p=*ptr; |
||
959 | while(*p==' ')p++; |
||
960 | |||
961 | if(*p != '\0' ) { |
||
962 | char *t; |
||
963 | t=p; |
||
964 | while((*t != '\0') && (*t != ' '))t++; |
||
965 | if(*t==' ') { |
||
966 | *t='\0'; |
||
967 | t++; |
||
968 | } |
||
969 | *ptr=t; |
||
970 | return p; |
||
971 | } else { |
||
972 | *ptr=NULL; |
||
973 | return NULL; |
||
974 | } |
||
975 | } |
||
976 | |||
977 | int vga_lastmodenumber(void) |
||
978 | { |
||
979 | __svgalib_getchipset(CHIPSET); |
||
980 | return lastmodenumber; |
||
981 | } |
||
982 | |||
983 | int __svgalib_getchipset(int set_chipset) |
||
984 | { |
||
985 | |||
986 | /* SHARK: Supported Graphics Drivers |
||
987 | * |
||
74 | giacomo | 988 | * NV3 (NVIDIA: GEFORCE/TNT/TNT2) |
989 | * SAVAGE (S3: VIRGE/SAVAGE |
||
990 | * R128 (ATI: RAGE 128/RADEON) |
||
132 | giacomo | 991 | * NEOMAGIC (NEOMAGIC CARD) |
992 | * |
||
54 | pj | 993 | */ |
994 | |||
995 | CHIPSET = set_chipset; |
||
996 | |||
997 | if(!initialized) { |
||
998 | |||
999 | map_vgaio(); |
||
1000 | init_vgapci(); |
||
1001 | |||
1002 | switch(CHIPSET) { |
||
1003 | case NV3: |
||
1004 | nv3_test(); |
||
1005 | break; |
||
1006 | case SAVAGE: |
||
1007 | savage_test(); |
||
1008 | break; |
||
74 | giacomo | 1009 | case R128: |
1010 | r128_test(); |
||
1011 | break; |
||
132 | giacomo | 1012 | case NEOMAGIC: |
1013 | neo_test(); |
||
1014 | break; |
||
1015 | case VESA: |
||
1016 | vesa_test(); |
||
1017 | break; |
||
54 | pj | 1018 | } |
1019 | |||
1020 | } |
||
1021 | |||
1022 | return CHIPSET; |
||
1023 | |||
1024 | } |
||
1025 | |||
74 | giacomo | 1026 | int vga_getxdim(void) |
1027 | { |
||
1028 | return CI.xdim; |
||
1029 | } |
||
1030 | |||
1031 | |||
1032 | int vga_getydim(void) |
||
1033 | { |
||
1034 | return CI.ydim; |
||
1035 | } |
||
1036 | |||
1037 | |||
1038 | int vga_getcolors(void) |
||
1039 | { |
||
1040 | return CI.colors; |
||
1041 | } |
||
1042 | |||
1043 | int vga_white(void) |
||
1044 | { |
||
1045 | switch (CI.colors) { |
||
1046 | case 2: |
||
1047 | case 16: |
||
1048 | case 256: |
||
1049 | return 15; |
||
1050 | case 1 << 15: |
||
1051 | return 32767; |
||
1052 | case 1 << 16: |
||
1053 | return 65535; |
||
1054 | case 1 << 24: |
||
1055 | return (1 << 24) - 1; |
||
1056 | } |
||
1057 | return CI.colors - 1; |
||
1058 | } |
||
1059 | |||
54 | pj | 1060 | void __svgalib_delay(void) |
1061 | { |
||
1062 | int i; |
||
1063 | for (i = 0; i < 10; i++); |
||
1064 | } |
||
1065 | |||
1066 | int vga_screenoff(void) |
||
1067 | { |
||
1068 | int tmp = 0; |
||
1069 | |||
1070 | SCREENON = 0; |
||
1071 | |||
1072 | if(__svgalib_novga) return 0; |
||
1073 | |||
1074 | if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->screenoff) { |
||
1075 | tmp = __svgalib_driverspecs->emul->screenoff(); |
||
1076 | } else { |
||
1077 | /* turn off screen for faster VGA memory acces */ |
||
1078 | if ((CHIPSET != EGA) && !__svgalib_novga) { |
||
1079 | __svgalib_outseq(0x01,__svgalib_inseq(0x01) | 0x20); |
||
1080 | } |
||
1081 | /* Disable video output */ |
||
1082 | #ifdef DISABLE_VIDEO_OUTPUT |
||
1083 | __svgalib_attscreen(0); |
||
1084 | #endif |
||
1085 | } |
||
1086 | |||
1087 | return tmp; |
||
1088 | } |
||
1089 | |||
1090 | static void setcoloremulation(void) |
||
1091 | { |
||
1092 | /* shift to color emulation */ |
||
1093 | __svgalib_CRT_I = CRT_IC; |
||
1094 | __svgalib_CRT_D = CRT_DC; |
||
1095 | __svgalib_IS1_R = IS1_RC; |
||
1096 | __svgalib_vgacolormode=1; |
||
1097 | if (CHIPSET != EGA && !__svgalib_novga) |
||
1098 | __svgalib_outmisc(__svgalib_inmisc()|0x01); |
||
1099 | } |
||
1100 | |||
1101 | void map_linear(unsigned long base, unsigned long size) { |
||
1102 | |||
1103 | LINEAR_POINTER= (void *)base; |
||
1104 | |||
1105 | } |
||
1106 | |||
1107 | static void savepalette(unsigned char *red, unsigned char *green, |
||
1108 | unsigned char *blue) |
||
1109 | { |
||
1110 | int i; |
||
1111 | |||
1112 | if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->savepalette) |
||
1113 | return (__svgalib_driverspecs->emul->savepalette(red, green, blue)); |
||
1114 | |||
1115 | if (CHIPSET == EGA || __svgalib_novga) |
||
1116 | return; |
||
1117 | |||
1118 | /* save graphics mode palette */ |
||
1119 | |||
1120 | for (i = 0; i < 256; i++) { |
||
1121 | int r,g,b; |
||
1122 | __svgalib_inpal(i,&r,&g,&b); |
||
1123 | *(red++) = r; |
||
1124 | *(green++) = g; |
||
1125 | *(blue++) = b; |
||
1126 | } |
||
1127 | } |
||
1128 | |||
1129 | static void restorepalette(const unsigned char *red, |
||
1130 | const unsigned char *green, const unsigned char *blue) |
||
1131 | { |
||
1132 | int i; |
||
1133 | |||
1134 | if (__svgalib_driverspecs->emul && __svgalib_driverspecs->emul->restorepalette) |
||
1135 | return (__svgalib_driverspecs->emul->restorepalette(red, green, blue)); |
||
1136 | |||
1137 | if (CHIPSET == EGA || __svgalib_novga) |
||
1138 | return; |
||
1139 | |||
1140 | /* restore saved palette */ |
||
1141 | /* read RGB components - index is autoincremented */ |
||
1142 | for (i = 0; i < 256; i++) { |
||
1143 | __svgalib_outpal(i,*(red++),*(green++),*(blue++)); |
||
1144 | } |
||
1145 | } |
||
1146 | |||
1147 | int vga_getcurrentmode(void) |
||
1148 | { |
||
1149 | return CM; |
||
1150 | } |
||
1151 | |||
1152 | |||
1153 | static void initialize(int set_chipset) |
||
1154 | { |
||
1155 | int i; |
||
1156 | |||
1157 | printk(KERN_INFO "Initialize\n"); |
||
1158 | |||
1159 | // __svgalib_disable_interrupt(); /* Is reenabled later by set_texttermio */ |
||
1160 | |||
1161 | __svgalib_getchipset(set_chipset); |
||
1162 | chipset_unlock(); |
||
1163 | |||
1164 | /* mmap graphics memory */ |
||
1165 | map_mem(); |
||
1166 | map_mmio(); |
||
1167 | |||
1168 | __vga_map(); |
||
1169 | |||
1170 | /* disable video */ |
||
1171 | vga_screenoff(); |
||
1172 | |||
1173 | /* Sanity check: (from painful experience) */ |
||
1174 | i = __svgalib_saveregs(text_regs); |
||
1175 | if (i > MAX_REGS) { |
||
1176 | printk(KERN_INFO "svgalib: FATAL internal error:\n"); |
||
1177 | printk(KERN_INFO "Set MAX_REGS at least to %d in src/driver.h and recompile everything.\n", |
||
1178 | i); |
||
1179 | } |
||
1180 | |||
1181 | /* save text mode palette */ |
||
1182 | savepalette(text_red, text_green, text_blue); |
||
1183 | |||
1184 | /* shift to color emulation */ |
||
1185 | setcoloremulation(); |
||
1186 | |||
1187 | initialized = 1; |
||
1188 | |||
1189 | /* vga_unlockvc(); */ |
||
1190 | |||
1191 | } |
||
1192 | |||
1193 | void vga_gettextfont(void *font) |
||
1194 | { |
||
1195 | unsigned int getsize; |
||
1196 | |||
1197 | getsize = fontbufsize; |
||
1198 | if (getsize > FONT_SIZE) |
||
1199 | getsize = FONT_SIZE; |
||
1200 | memcpy(font, font_buf1, getsize); |
||
1201 | if (fontbufsize > getsize) |
||
1202 | memset(((char *)font) + getsize, 0, (size_t)(fontbufsize - getsize)); |
||
1203 | } |
||
1204 | |||
1205 | void vga_puttextfont(void *font) |
||
1206 | { |
||
1207 | unsigned int putsize; |
||
1208 | |||
1209 | putsize = fontbufsize; |
||
1210 | if (putsize > FONT_SIZE) |
||
1211 | putsize = FONT_SIZE; |
||
1212 | memcpy(font_buf1, font, putsize); |
||
1213 | memcpy(font_buf2, font, putsize); |
||
1214 | if (putsize < FONT_SIZE) { |
||
1215 | memset(font_buf1 + putsize, 0, (size_t)(FONT_SIZE - putsize)); |
||
1216 | memset(font_buf2 + putsize, 0, (size_t)(FONT_SIZE - putsize)); |
||
1217 | } |
||
1218 | |||
1219 | } |
||
1220 | |||
1221 | int vga_setmode(int mode,int set_chipset) |
||
1222 | { |
||
1223 | int modeflags=mode&0xfffff000; |
||
1224 | #ifndef VM86 |
||
1225 | BYTE p1,p2; |
||
1226 | #endif |
||
1227 | |||
1228 | printk(KERN_INFO "Setmode %i from %i\n", mode, CM); |
||
1229 | |||
1230 | if(mode==-1)return vga_version; |
||
1231 | |||
1232 | mode&=0xfff; |
||
1233 | |||
1234 | if (!initialized) { |
||
1235 | if (mode == TEXT) return 0; |
||
1236 | initialize(set_chipset); |
||
1237 | } |
||
1238 | |||
1239 | if (mode != TEXT && !chipset_modeavailable(mode)) { |
||
1240 | return -1; |
||
1241 | } |
||
1242 | |||
1243 | // __svgalib_disable_interrupt(); |
||
1244 | |||
1245 | prv_mode = CM; |
||
1246 | CM = mode; |
||
1247 | |||
1248 | /* disable video */ |
||
1249 | vga_screenoff(); |
||
1250 | |||
1251 | if (mode == TEXT) { |
||
1252 | /* Returning to textmode. */ |
||
1253 | |||
1254 | X_REGS16 inregs, outregs; |
||
1255 | X_SREGS16 sregs; |
||
1256 | |||
1257 | inregs.x.ax = 0x03; |
||
1258 | #ifndef VM86 |
||
1259 | p1 = inp(0x21); |
||
1260 | p2 = inp(0xA1); |
||
1261 | outp(0x21,0xFF); |
||
1262 | outp(0xA1,0xFF); |
||
1263 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
1264 | outp(0x21,p1); |
||
1265 | outp(0xA1,p2); |
||
1266 | #else |
||
1267 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
1268 | #endif |
||
1269 | |||
1270 | if (SVGAMODE(prv_mode)) vga_setpage(0); |
||
1271 | |||
1272 | } else { |
||
1273 | /* Setting a graphics mode. */ |
||
1274 | |||
1275 | if (SVGAMODE(prv_mode)) { |
||
1276 | /* The current mode is an SVGA mode, and we now want to */ |
||
1277 | /* set a standard VGA mode. Make sure the extended regs */ |
||
1278 | /* are restored. */ |
||
1279 | /* Also used when setting another SVGA mode to hopefully */ |
||
1280 | /* eliminate lock-ups. */ |
||
1281 | vga_setpage(0); |
||
1282 | chipset_setregs(text_regs, mode); |
||
1283 | /* restore old extended regs */ |
||
1284 | } |
||
1285 | /* shift to color emulation */ |
||
1286 | setcoloremulation(); |
||
1287 | |||
1288 | CI.xdim = infotable[mode].xdim; |
||
1289 | CI.ydim = infotable[mode].ydim; |
||
1290 | CI.colors = infotable[mode].colors; |
||
1291 | CI.xbytes = infotable[mode].xbytes; |
||
1292 | CI.bytesperpixel = infotable[mode].bytesperpixel; |
||
1293 | |||
1294 | chipset_setmode(mode, prv_mode); |
||
1295 | MODEX = 0; |
||
1296 | |||
1297 | /* Set default claimed memory (moved here from initialize - Michael.) */ |
||
1298 | if (mode == G320x200x256) |
||
1299 | VMEM = 65536; |
||
1300 | else if (STDVGAMODE(mode)) |
||
1301 | VMEM = 256 * 1024; /* Why always 256K ??? - Michael */ |
||
1302 | else { |
||
1303 | vga_modeinfo *modeinfo; |
||
1304 | |||
1305 | modeinfo = vga_getmodeinfo(mode); |
||
1306 | VMEM = modeinfo->linewidth * modeinfo->height; |
||
1307 | CI.xbytes = modeinfo->linewidth; |
||
1308 | } |
||
1309 | |||
1310 | if (!flip) { |
||
1311 | /* set default palette */ |
||
1312 | if (CI.colors <= 256) |
||
1313 | restorepalette(default_red, default_green, default_blue); |
||
1314 | |||
1315 | /* clear screen (sets current color to 15) */ |
||
1316 | __svgalib_currentpage = -1; |
||
1317 | if(!(modeflags&0x8000))vga_clear(); |
||
1318 | |||
1319 | if (SVGAMODE(CM)) |
||
1320 | vga_setpage(0); |
||
1321 | } |
||
1322 | __svgalib_currentpage = -1; |
||
1323 | currentlogicalwidth = CI.xbytes; |
||
1324 | currentdisplaystart = 0; |
||
1325 | |||
1326 | /* enable video */ |
||
1327 | if (!flip) |
||
1328 | vga_screenon(); |
||
1329 | |||
1330 | { |
||
1331 | vga_modeinfo *modeinfo; |
||
1332 | modeinfo = vga_getmodeinfo(mode); |
||
1333 | MODEX = ((MODEFLAGS = modeinfo->flags) & IS_MODEX); |
||
1334 | } |
||
1335 | |||
1336 | // __svgalib_enable_interrupt(); |
||
1337 | } |
||
1338 | |||
1339 | return 0; |
||
1340 | |||
1341 | } |
||
1342 | |||
1343 | inline void copy_videomem_32to16(void *src, void *dst, unsigned long int memdiv2) |
||
1344 | { |
||
1345 | __asm__ __volatile__("push %%esi |
||
1346 | push %%edi |
||
1347 | movl %1, %%esi |
||
1348 | movl %2, %%edi |
||
1349 | 1: |
||
1350 | movl (%%esi), %%edx |
||
1351 | xorl %%ebx, %%ebx |
||
1352 | xorw %%ax, %%ax |
||
1353 | movb %%dl, %%al |
||
1354 | shrl $0x8, %%edx |
||
1355 | shrw $0x3, %%ax |
||
1356 | orw %%ax, %%bx |
||
1357 | shll $0x6, %%ebx |
||
1358 | xorw %%ax, %%ax |
||
1359 | movb %%dl, %%al |
||
1360 | shrl $0x8, %%edx |
||
1361 | shrw $0x2, %%ax |
||
1362 | orw %%ax, %%bx |
||
1363 | shll $0x5, %%ebx |
||
1364 | xorw %%ax, %%ax |
||
1365 | movb %%dl, %%al |
||
1366 | shrw $0x3, %%ax |
||
1367 | orw %%ax, %%bx |
||
1368 | shll $0x5, %%ebx |
||
1369 | incl %%esi |
||
1370 | incl %%esi |
||
1371 | incl %%esi |
||
1372 | incl %%esi |
||
1373 | movl (%%esi), %%edx |
||
1374 | xorw %%ax, %%ax |
||
1375 | movb %%dl, %%al |
||
1376 | shrl $0x8,%%edx |
||
1377 | shrw $0x3, %%ax |
||
1378 | orw %%ax, %%bx |
||
1379 | shll $0x6, %%ebx |
||
1380 | xorw %%ax, %%ax |
||
1381 | movb %%dl, %%al |
||
1382 | shrl $0x8, %%edx |
||
1383 | shrw $0x2, %%ax |
||
1384 | orw %%ax, %%bx |
||
1385 | shll $0x5, %%ebx |
||
1386 | xorw %%ax, %%ax |
||
1387 | movb %%dl, %%al |
||
1388 | shrw $0x3, %%ax |
||
1389 | orw %%ax, %%bx |
||
1390 | rorl $0x10, %%ebx |
||
1391 | movl %%ebx, (%%edi) |
||
1392 | incl %%esi |
||
1393 | incl %%esi |
||
1394 | incl %%esi |
||
1395 | incl %%esi |
||
1396 | incl %%edi |
||
1397 | incl %%edi |
||
1398 | incl %%edi |
||
1399 | incl %%edi |
||
1400 | loop 1b |
||
1401 | pop %%edi |
||
1402 | pop %%esi" |
||
1403 | : |
||
1404 | : "c" (memdiv2), "a" (src), "b" (dst)); |
||
1405 | |||
1406 | } |
||
74 | giacomo | 1407 | |
1408 | inline void copy_videomem_16to16(void *src, void *dst, unsigned long int memdiv4) |
||
1409 | { |
||
1410 | __asm__ __volatile__("push %%esi |
||
1411 | push %%edi |
||
1412 | movl %1, %%esi |
||
1413 | movl %2, %%edi |
||
1414 | cld |
||
1415 | rep |
||
1416 | movsl |
||
1417 | |||
1418 | pop %%edi |
||
1419 | pop %%esi" |
||
1420 | : |
||
1421 | : "c" (memdiv4), "a" (src), "b" (dst)); |
||
1422 | |||
1423 | } |