Rev 443 | Rev 448 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | #include <ll/i386/hw-data.h> |
2 | #include <ll/i386/mem.h> |
||
3 | #include <ll/i386/cons.h> |
||
4 | #include <ll/sys/ll/ll-func.h> |
||
5 | |||
6 | #include <drivers/llpci.h> |
||
7 | #include <drivers/pci.h> |
||
8 | |||
9 | #include <drivers/gd.h> |
||
10 | |||
11 | #include "drivers/s3.h" |
||
12 | #include "drivers/trident.h" |
||
13 | #include "drivers/vesa.h" |
||
14 | #include "drivers/chips.h" |
||
15 | |||
16 | BYTE bus, dev; |
||
17 | ModeInfoBlock vbemi; |
||
18 | BYTE actbank; |
||
19 | BYTE type; |
||
20 | |||
21 | DWORD flb=0; |
||
22 | int linear; |
||
23 | BYTE trylinear; |
||
24 | /*BYTE gmode = FALSE;*/ |
||
25 | |||
26 | #define NMODES 13 |
||
27 | static struct gmode allmodes[NMODES] = { |
||
28 | {640, 400, 640, 8, 0x100}, |
||
29 | {640, 480, 640, 8, 0x101}, |
||
30 | {800, 600, 800, 8, 0x103}, |
||
31 | {1024, 768, 1024, 8, 0x105}, |
||
32 | {640, 480, 1280, 15, 0x110}, |
||
33 | {800, 600, 1600, 15, 0x113}, |
||
34 | {1024, 768, 2048, 15, 0x116}, |
||
35 | {640, 480, 1280, 16, 0x111}, |
||
36 | {800, 600, 1600, 16, 0x114}, |
||
37 | {1024, 768, 2048, 16, 0x117}, |
||
38 | {640, 480, 1920, 24, 0x112}, |
||
39 | {800, 600, 2400, 24, 0x115}, |
||
40 | {1024, 768, 3072, 24, 0x118} |
||
41 | }; |
||
42 | static struct gmode actualmode; |
||
43 | |||
44 | |||
45 | static int myceil(float f) |
||
46 | { |
||
47 | int i = (int) f; |
||
48 | float f1 = f - i; |
||
49 | |||
50 | if (f1 != 0) { |
||
51 | return i + 1; |
||
52 | } else { |
||
53 | return i; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | /************************************************************************/ |
||
58 | /* GD Common Interface */ |
||
59 | /************************************************************************/ |
||
60 | int gd_init(WORD flags) |
||
61 | { |
||
62 | struct pci_regs *r; |
||
63 | int dummy; |
||
64 | |||
65 | memset(&actualmode, 0, sizeof(struct gmode)); |
||
66 | type = UNKNOWN; |
||
67 | |||
68 | if (pci_init() == 1) { |
||
69 | if ((r = pci_class((0x0300) << 8, 0, &bus, &dev)) != NULL) { |
||
70 | cprintf("PCI video card found!!!\n"); |
||
71 | cprintf("Vendor: %x\n", r->VendorId); |
||
72 | cprintf("Card: %x\n", r->DeviceId); |
||
73 | /* flb = r->IoBaseAddress & 0xFF800000; */ |
||
74 | |||
75 | dummy = pcibios_read_config_dword(bus, dev, 16, &flb); |
||
76 | flb = flb & 0xFF800000; |
||
77 | /* Err... Have to set type!!! */ |
||
78 | |||
79 | cprintf("FLB @ %lx\n", flb); |
||
80 | if (flb < 32 * 1024 * 1024) { |
||
81 | /*flb = 32 * 0x1000000;*/ |
||
82 | /*flb = 0xF3000000;*/ |
||
83 | flb = 0x02000000; |
||
84 | cprintf("Wrong FLB!!! Forced to %lx\n", flb); |
||
85 | pcibios_write_config_dword(bus, dev, 16, flb); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | /* VESA driver needs the V86 Mode... */ |
||
444 | giacomo | 91 | vm86_init(); |
2 | pj | 92 | |
93 | /* First, check VESA... */ |
||
94 | if (vbe_getinfo() == 1) { |
||
95 | type = VESA; |
||
96 | if (flags & NOLINEAR) { |
||
97 | trylinear = 0; |
||
98 | } else { |
||
99 | trylinear = 1; |
||
100 | } |
||
444 | giacomo | 101 | return 1; |
2 | pj | 102 | } |
103 | |||
104 | /* Then, the other graph cards... Override VESA!!! */ |
||
105 | if (trident_test() == 1) { |
||
106 | type = TRIDENT; |
||
107 | trylinear = 0; |
||
108 | } |
||
109 | |||
110 | if (s3_test() == 1) { |
||
111 | type = S3; |
||
112 | if (flags & NOLINEAR) { |
||
113 | trylinear = 0; |
||
114 | } else { |
||
115 | trylinear = 1; |
||
116 | } |
||
117 | return 1; |
||
118 | } |
||
119 | |||
120 | if (type == UNKNOWN) { |
||
121 | return -1; |
||
122 | } |
||
444 | giacomo | 123 | |
2 | pj | 124 | return -2; |
125 | } |
||
126 | |||
127 | void gd_showmodeinfo(void) |
||
128 | { |
||
129 | cprintf("Mode number %x\n", actualmode.modenum); |
||
130 | cprintf("MaxX: %u\n", actualmode.xdim); |
||
131 | cprintf("MaxY: %u\n", actualmode.ydim); |
||
132 | cprintf("BPR: %u\n", actualmode.bpr); |
||
133 | } |
||
134 | |||
135 | void gd_showinfo(void) |
||
136 | { |
||
137 | DWORD addr; |
||
138 | |||
139 | addr = gd_getflb(); |
||
140 | |||
141 | if (addr != 0) { |
||
142 | cprintf ("\t gd: Frame Linear Buffer @ %lx (%luM)\n", |
||
143 | addr, (addr / 0x1000000)); |
||
144 | } |
||
145 | |||
146 | if (type == VESA) { |
||
147 | cprintf("Vesa SVGA card\n"); |
||
148 | vbe_showinfo(); |
||
149 | } |
||
150 | if (type == TRIDENT) { |
||
151 | cprintf("Trident graphic card\n"); |
||
152 | trident_showinfo(); |
||
153 | } |
||
154 | |||
155 | if (type == S3) { |
||
156 | cprintf("S3 graphic card\n"); |
||
157 | s3_showinfo(); |
||
158 | } |
||
159 | } |
||
160 | |||
161 | int gd_setmode(WORD mode) |
||
162 | { |
||
163 | WORD app; |
||
164 | int i; |
||
165 | #ifndef VM86 |
||
166 | BYTE p1, p2; |
||
167 | #endif |
||
168 | |||
169 | if (mode == 0) { |
||
170 | X_REGS16 inregs, outregs; |
||
171 | X_SREGS16 sregs; |
||
172 | |||
173 | if (actualmode.modenum != 0) { |
||
174 | inregs.x.ax = 0x03; |
||
175 | #ifndef VM86 |
||
176 | p1 = inp(0x21); |
||
177 | p2 = inp(0xA1); |
||
178 | outp(0x21,0xFF); |
||
179 | outp(0xA1,0xFF); |
||
180 | X_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
181 | outp(0x21,p1); |
||
182 | outp(0xA1,p2); |
||
183 | #else |
||
184 | vm86_callBIOS(0x10, &inregs, &outregs, &sregs); |
||
185 | #endif |
||
186 | } |
||
187 | return 1; |
||
188 | } |
||
189 | |||
190 | for (i = 0; i < NMODES; i++) { |
||
191 | if ((mode == allmodes[i].modenum)) { |
||
192 | memcpy(&actualmode, &(allmodes[i]), sizeof(struct gmode)); |
||
193 | } |
||
194 | } |
||
195 | |||
196 | if (type == VESA) { |
||
444 | giacomo | 197 | |
2 | pj | 198 | if (vbe_getmodeinfo(&vbemi, mode) < 0) { |
444 | giacomo | 199 | return -1; |
200 | } |
||
2 | pj | 201 | |
202 | app = mode; |
||
203 | if (trylinear) { |
||
204 | /* try linear... */ |
||
205 | mode = mode | 0x4000; |
||
206 | linear = TRUE; |
||
207 | if (vbe_setmode(mode) == 1) { |
||
208 | return linear; |
||
209 | } |
||
210 | } |
||
211 | actbank = 0; |
||
212 | Load_Write_Bank_256(0); |
||
213 | linear = FALSE; |
||
214 | mode = app; |
||
215 | if (vbe_setmode(mode) < 0) { |
||
216 | return -1; |
||
217 | } |
||
218 | return linear; |
||
219 | } |
||
220 | |||
221 | if (type == S3) { |
||
222 | /* Still use VESA to open graph... */ |
||
223 | if (vbe_getmodeinfo(&vbemi, mode) < 0) { |
||
224 | return -1; |
||
225 | } |
||
226 | if (vbe_setmode(mode) < 0) { |
||
227 | return -1; |
||
228 | } |
||
229 | if ((flb != 0) && trylinear) { |
||
230 | linear = TRUE; |
||
231 | s3_linear(flb); |
||
232 | pcibios_write_config_dword(bus, dev, 16, flb); |
||
233 | return TRUE; |
||
234 | } |
||
235 | linear = FALSE; |
||
236 | actbank = 0; |
||
237 | Load_Write_Bank_256(0); |
||
238 | return FALSE; |
||
239 | } |
||
240 | |||
241 | if (type == TRIDENT) { |
||
242 | /* Still use VESA to open graph... */ |
||
243 | if (vbe_getmodeinfo(&vbemi, mode) < 0) { |
||
244 | return -1; |
||
245 | } |
||
246 | if (vbe_setmode(mode) < 0) { |
||
247 | return -1; |
||
248 | } |
||
249 | |||
250 | actbank = 0; |
||
251 | Load_Write_Bank_256(0); |
||
252 | return FALSE; |
||
253 | } |
||
254 | |||
255 | return -2; |
||
256 | } |
||
257 | |||
258 | DWORD gd_getflb(void) |
||
259 | { |
||
260 | if (type == VESA) { |
||
261 | return vbe_getflb(); |
||
262 | } |
||
263 | if (type == S3) { |
||
264 | return flb; |
||
265 | } |
||
266 | return 0; |
||
267 | } |
||
268 | |||
269 | DWORD gd_getmem(void) |
||
270 | { |
||
271 | if (type == VESA) { |
||
272 | return vbe_getmem(); |
||
273 | } |
||
274 | if (type == S3) { |
||
275 | return s3_getmem(); |
||
276 | } |
||
277 | if (type == TRIDENT) { |
||
278 | return trident_getmem(); |
||
279 | } |
||
280 | |||
281 | return 0; |
||
282 | } |
||
283 | |||
284 | WORD gd_getbpr(void) |
||
285 | { |
||
286 | if (actualmode.bpr) return actualmode.bpr; |
||
287 | return -2; |
||
288 | } |
||
289 | |||
51 | pj | 290 | int gd_getmodeinfo(grx_vga_modeinfo *m) |
2 | pj | 291 | { |
292 | if (actualmode.modenum == 0) { |
||
293 | return -1; |
||
294 | } |
||
295 | |||
296 | m->width = actualmode.xdim; |
||
297 | m->height = actualmode.ydim; |
||
298 | m->bytesperpixel = (myceil((float)actualmode.bpp / 8)); |
||
299 | /* m->colors = myexp(2, actualmode.bpp); */ |
||
300 | m->colors = 1 << actualmode.bpp; |
||
301 | m->linewidth = gd_getbpr(); |
||
302 | m->maxlogicalwidth = gd_getbpr(); /* 4 the moment... */ |
||
303 | m->startaddressrange = 0; /* don't know :( */ |
||
304 | m->maxpixels = gd_getmem() / m->bytesperpixel; |
||
305 | m->haveblit = 0; |
||
306 | m->flags = 0; |
||
307 | |||
308 | /* Extended fields: */ |
||
309 | m->chiptype = type; /* Chiptype detected */ |
||
310 | m->memory = gd_getmem(); |
||
311 | m->linewidth_unit = 0; /* don't know :( */ |
||
312 | if (linear) { |
||
313 | m->linear_aperture = (LIN_ADDR)gd_getflb(); |
||
314 | m->aperture_size = gd_getmem(); |
||
315 | } else { |
||
316 | m->linear_aperture = 0; |
||
317 | m->aperture_size = 0xFFFF; |
||
318 | } |
||
319 | m->set_aperture_page = NULL; |
||
320 | m->extensions = NULL; |
||
321 | return 1; |
||
322 | } |
||
323 | |||
324 | void Load_Write_Bank_256(BYTE bank) |
||
325 | { |
||
326 | if (bank != actbank) { |
||
327 | actbank = bank; |
||
328 | if (type == VESA) { |
||
329 | if (vbe_setbank(&vbemi, bank) < 0) |
||
330 | ll_abort(259); |
||
331 | } |
||
332 | if (type == S3) { |
||
333 | s3_setpage(bank); |
||
334 | } |
||
335 | if (type == TRIDENT) { |
||
336 | trident_setpage(bank); |
||
337 | } |
||
338 | } |
||
339 | } |
||
340 | |||
341 | /************************************************************************/ |
||
342 | /* BANK HANDLING FUNCS */ |
||
343 | /************************************************************************/ |
||
344 | |||
345 | LIN_ADDR start_address(WORD bpr, WORD x, WORD y) |
||
346 | { |
||
347 | LIN_ADDR a; |
||
348 | |||
349 | a = (LIN_ADDR)(y * bpr +x); |
||
350 | return a; |
||
351 | } |
||
352 | |||
353 | void Seg_Off_256(WORD x, WORD y, WORD pitch, WORD *offs, WORD *seg) |
||
354 | { |
||
355 | DWORD a; |
||
356 | |||
357 | a = y * pitch + x; |
||
358 | *offs = a & 0x0000FFFF; |
||
359 | *seg = a >> 16; |
||
360 | } |
||
361 | |||
362 | void Seg_Off_Hi(WORD x, WORD y, WORD pitch, WORD *offs, WORD *seg) |
||
363 | { |
||
364 | DWORD a; |
||
365 | |||
366 | a = y * pitch + x * 2; |
||
367 | *offs = a & 0x0000FFFF; |
||
368 | *seg = a >> 16; |
||
369 | } |
||
370 | |||
371 | int gd_modenum(WORD x, WORD y, BYTE depth) |
||
372 | { |
||
373 | int mode, i; |
||
374 | |||
375 | mode = -1; |
||
376 | |||
377 | for (i = 0; i < NMODES; i++) { |
||
378 | if ((depth == allmodes[i].bpp) && (x == allmodes[i].xdim) && (y == allmodes[i].ydim)) { |
||
379 | mode = allmodes[i].modenum; |
||
380 | } else { |
||
381 | } |
||
382 | } |
||
383 | |||
384 | if ((mode != -1) && (vbe_checkmode(mode) != -1)) |
||
385 | return mode; |
||
386 | return -1; |
||
387 | } |