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