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