xref: /haiku/src/add-ons/accelerants/nvidia/engine/nv_general.c (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
1 /* Authors:
2    Mark Watson 12/1999,
3    Apsed,
4    Rudolf Cornelissen 10/2002-11/2005
5 */
6 
7 #define MODULE_BIT 0x00008000
8 
9 #include "nv_std.h"
10 
11 static status_t test_ram(void);
12 static status_t nvxx_general_powerup (void);
13 static void unlock_card(void);
14 static status_t nv_general_bios_to_powergraphics(void);
15 
16 static void nv_dump_configuration_space (void)
17 {
18 #define DUMP_CFG(reg, type) if (si->ps.card_type >= type) do { \
19 	uint32 value = CFGR(reg); \
20 	MSG(("configuration_space 0x%02x %20s 0x%08x\n", \
21 		NVCFG_##reg, #reg, value)); \
22 } while (0)
23 	DUMP_CFG (DEVID,	0);
24 	DUMP_CFG (DEVCTRL,	0);
25 	DUMP_CFG (CLASS,	0);
26 	DUMP_CFG (HEADER,	0);
27 	DUMP_CFG (BASE1REGS,0);
28 	DUMP_CFG (BASE2FB,	0);
29 	DUMP_CFG (BASE3,	0);
30 	DUMP_CFG (BASE4,	0);
31 	DUMP_CFG (BASE5,	0);
32 	DUMP_CFG (BASE6,	0);
33 	DUMP_CFG (BASE7,	0);
34 	DUMP_CFG (SUBSYSID1,0);
35 	DUMP_CFG (ROMBASE,	0);
36 	DUMP_CFG (CAPPTR,	0);
37 	DUMP_CFG (CFG_1,	0);
38 	DUMP_CFG (INTERRUPT,0);
39 	DUMP_CFG (SUBSYSID2,0);
40 	DUMP_CFG (AGPREF,	0);
41 	DUMP_CFG (AGPSTAT,	0);
42 	DUMP_CFG (AGPCMD,	0);
43 	DUMP_CFG (ROMSHADOW,0);
44 	DUMP_CFG (VGA,		0);
45 	DUMP_CFG (SCHRATCH,	0);
46 	DUMP_CFG (CFG_10,	0);
47 	DUMP_CFG (CFG_11,	0);
48 	DUMP_CFG (CFG_12,	0);
49 	DUMP_CFG (CFG_13,	0);
50 	DUMP_CFG (CFG_14,	0);
51 	DUMP_CFG (CFG_15,	0);
52 	DUMP_CFG (CFG_16,	0);
53 	DUMP_CFG (PCIEREF,	0);
54 	DUMP_CFG (PCIEDCAP,	0);
55 	DUMP_CFG (PCIEDCTST,0);
56 	DUMP_CFG (PCIELCAP,	0);
57 	DUMP_CFG (PCIELCTST,0);
58 	DUMP_CFG (CFG_22,	0);
59 	DUMP_CFG (CFG_23,	0);
60 	DUMP_CFG (CFG_24,	0);
61 	DUMP_CFG (CFG_25,	0);
62 	DUMP_CFG (CFG_26,	0);
63 	DUMP_CFG (CFG_27,	0);
64 	DUMP_CFG (CFG_28,	0);
65 	DUMP_CFG (CFG_29,	0);
66 	DUMP_CFG (CFG_30,	0);
67 	DUMP_CFG (CFG_31,	0);
68 	DUMP_CFG (CFG_32,	0);
69 	DUMP_CFG (CFG_33,	0);
70 	DUMP_CFG (CFG_34,	0);
71 	DUMP_CFG (CFG_35,	0);
72 	DUMP_CFG (CFG_36,	0);
73 	DUMP_CFG (CFG_37,	0);
74 	DUMP_CFG (CFG_38,	0);
75 	DUMP_CFG (CFG_39,	0);
76 	DUMP_CFG (CFG_40,	0);
77 	DUMP_CFG (CFG_41,	0);
78 	DUMP_CFG (CFG_42,	0);
79 	DUMP_CFG (CFG_43,	0);
80 	DUMP_CFG (CFG_44,	0);
81 	DUMP_CFG (CFG_45,	0);
82 	DUMP_CFG (CFG_46,	0);
83 	DUMP_CFG (CFG_47,	0);
84 	DUMP_CFG (CFG_48,	0);
85 	DUMP_CFG (CFG_49,	0);
86 	DUMP_CFG (CFG_50,	0);
87 #undef DUMP_CFG
88 }
89 
90 status_t nv_general_powerup()
91 {
92 	status_t status;
93 
94 	LOG(1,("POWERUP: Haiku nVidia Accelerant 0.63 running.\n"));
95 
96 	/* log VBLANK INT usability status */
97 	if (si->ps.int_assigned)
98 		LOG(4,("POWERUP: Usable INT assigned to HW; Vblank semaphore enabled\n"));
99 	else
100 		LOG(4,("POWERUP: No (usable) INT assigned to HW; Vblank semaphore disabled\n"));
101 
102 	/* preset no laptop */
103 	si->ps.laptop = false;
104 
105 	/* detect card type and power it up */
106 	switch(CFGR(DEVID))
107 	{
108 	/* Vendor Nvidia */
109 	case 0x002010de: /* Nvidia TNT1 */
110 		si->ps.card_type = NV04;
111 		si->ps.card_arch = NV04A;
112 		LOG(4,("POWERUP: Detected Nvidia TNT1 (NV04)\n"));
113 		status = nvxx_general_powerup();
114 		break;
115 	case 0x002810de: /* Nvidia TNT2 (pro) */
116 	case 0x002910de: /* Nvidia TNT2 Ultra */
117 	case 0x002a10de: /* Nvidia TNT2 */
118 	case 0x002b10de: /* Nvidia TNT2 */
119 		si->ps.card_type = NV05;
120 		si->ps.card_arch = NV04A;
121 		LOG(4,("POWERUP: Detected Nvidia TNT2 (NV05)\n"));
122 		status = nvxx_general_powerup();
123 		break;
124 	case 0x002c10de: /* Nvidia Vanta (Lt) */
125 		si->ps.card_type = NV05;
126 		si->ps.card_arch = NV04A;
127 		LOG(4,("POWERUP: Detected Nvidia Vanta (Lt) (NV05)\n"));
128 		status = nvxx_general_powerup();
129 		break;
130 	case 0x002d10de: /* Nvidia TNT2-M64 (Pro) */
131 		si->ps.card_type = NV05M64;
132 		si->ps.card_arch = NV04A;
133 		LOG(4,("POWERUP: Detected Nvidia TNT2-M64 (Pro) (NV05M64)\n"));
134 		status = nvxx_general_powerup();
135 		break;
136 	case 0x002e10de: /* Nvidia NV06 Vanta */
137 	case 0x002f10de: /* Nvidia NV06 Vanta */
138 		si->ps.card_type = NV06;
139 		si->ps.card_arch = NV04A;
140 		LOG(4,("POWERUP: Detected Nvidia Vanta (NV06)\n"));
141 		status = nvxx_general_powerup();
142 		break;
143 	case 0x004010de: /* Nvidia GeForce FX 6800 Ultra */
144 	case 0x004110de: /* Nvidia GeForce FX 6800 */
145 	case 0x004210de: /* Nvidia GeForce FX 6800LE */
146 		si->ps.card_type = NV40;
147 		si->ps.card_arch = NV40A;
148 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6800 (NV40)\n"));
149 		status = nvxx_general_powerup();
150 		break;
151 	case 0x004310de: /* Nvidia unknown FX */
152 		si->ps.card_type = NV40;
153 		si->ps.card_arch = NV40A;
154 		LOG(4,("POWERUP: Detected Nvidia unknown FX (NV40)\n"));
155 		status = nvxx_general_powerup();
156 		break;
157 	case 0x004510de: /* Nvidia GeForce FX 6800 GT */
158 		si->ps.card_type = NV40;
159 		si->ps.card_arch = NV40A;
160 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6800 GT (NV40)\n"));
161 		status = nvxx_general_powerup();
162 		break;
163 	case 0x004d10de: /* Nvidia Quadro FX 4400 */
164 	case 0x004e10de: /* Nvidia Quadro FX 4000 */
165 		si->ps.card_type = NV40;
166 		si->ps.card_arch = NV40A;
167 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 4000/4400 (NV40)\n"));
168 		status = nvxx_general_powerup();
169 		break;
170 	case 0x009210de: /* Nvidia Geforce 7800 GT PCIe */
171 		si->ps.card_type = NV47;
172 		si->ps.card_arch = NV40A;
173 		LOG(4,("POWERUP: Detected Nvidia Geforce 7800 GT PCIe (NV47)\n"));
174 		status = nvxx_general_powerup();
175 		break;
176 //fixme: reported, but yet untested card..
177 	case 0x009910de: /* Nvidia Geforce 7800 GTX Go PCIe */
178 		si->ps.card_type = NV47;
179 		si->ps.card_arch = NV40A;
180 		si->ps.laptop = true;
181 		LOG(4,("POWERUP: Detected Nvidia Geforce 7800 GTX Go PCIe (NV47)\n"));
182 		status = nvxx_general_powerup();
183 		break;
184 	case 0x00a010de: /* Nvidia Aladdin TNT2 */
185 		si->ps.card_type = NV05;
186 		si->ps.card_arch = NV04A;
187 		LOG(4,("POWERUP: Detected Nvidia Aladdin TNT2 (NV05)\n"));
188 		status = nvxx_general_powerup();
189 		break;
190 	case 0x00c010de: /* Nvidia unknown FX */
191 		si->ps.card_type = NV41;
192 		si->ps.card_arch = NV40A;
193 		LOG(4,("POWERUP: Detected Nvidia unknown FX (NV41)\n"));
194 		status = nvxx_general_powerup();
195 		break;
196 	case 0x00c110de: /* Nvidia GeForce FX 6800 */
197 	case 0x00c210de: /* Nvidia GeForce FX 6800LE */
198 		si->ps.card_type = NV41;
199 		si->ps.card_arch = NV40A;
200 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6800 (NV41)\n"));
201 		status = nvxx_general_powerup();
202 		break;
203 	case 0x00c810de: /* Nvidia GeForce FX 6800 Go */
204 	case 0x00c910de: /* Nvidia GeForce FX 6800 Ultra Go */
205 		si->ps.card_type = NV41;
206 		si->ps.card_arch = NV40A;
207 		si->ps.laptop = true;
208 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6800 Go (NV41)\n"));
209 		status = nvxx_general_powerup();
210 		break;
211 	case 0x00cc10de: /* Nvidia Quadro FX 1400 Go */
212 		si->ps.card_type = NV41;
213 		si->ps.card_arch = NV40A;
214 		si->ps.laptop = true;
215 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 1400 Go (NV41)\n"));
216 		status = nvxx_general_powerup();
217 		break;
218 	case 0x00cd10de: /* Nvidia Quadro FX 3450/4000 SDI */
219 		si->ps.card_type = NV41;
220 		si->ps.card_arch = NV40A;
221 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 3450/4000 SDI (NV41)\n"));
222 		status = nvxx_general_powerup();
223 		break;
224 	case 0x00ce10de: /* Nvidia Quadro FX 1400 */
225 		si->ps.card_type = NV41;
226 		si->ps.card_arch = NV40A;
227 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 1400 (NV41)\n"));
228 		status = nvxx_general_powerup();
229 		break;
230 	case 0x00f010de: /* Nvidia GeForce FX 6800 (Ultra) AGP(?) */
231 		si->ps.card_type = NV40;
232 		si->ps.card_arch = NV40A;
233 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6800 AGP(?) (NV40(?))\n"));
234 		status = nvxx_general_powerup();
235 		break;
236 	case 0x00f110de: /* Nvidia GeForce FX 6600 GT AGP */
237 	case 0x00f210de: /* Nvidia GeForce FX 6600 AGP */
238 		si->ps.card_type = NV43;
239 		si->ps.card_arch = NV40A;
240 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6600 (GT) AGP (NV43)\n"));
241 		status = nvxx_general_powerup();
242 		break;
243 	case 0x00f310de: /* Nvidia GeForce 6200 */
244 		si->ps.card_type = NV44;
245 		si->ps.card_arch = NV40A;
246 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200 (NV44)\n"));
247 		status = nvxx_general_powerup();
248 		break;
249 	case 0x00f810de: /* Nvidia Quadro FX 3400/4400 PCIe */
250 		si->ps.card_type = NV45;
251 		si->ps.card_arch = NV40A;
252 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 3400 PCIe (NV45)\n"));
253 		status = nvxx_general_powerup();
254 		break;
255 	case 0x00f910de: /* Nvidia GeForce PCX 6800 PCIe */
256 		si->ps.card_type = NV45;
257 		si->ps.card_arch = NV40A;
258 		LOG(4,("POWERUP: Detected Nvidia GeForce PCX 6800 PCIe (NV45)\n"));
259 		status = nvxx_general_powerup();
260 		break;
261 	case 0x00fa10de: /* Nvidia GeForce PCX 5750 PCIe */
262 		si->ps.card_type = NV36;
263 		si->ps.card_arch = NV30A;
264 		LOG(4,("POWERUP: Detected Nvidia GeForce PCX 5750 PCIe (NV36)\n"));
265 		status = nvxx_general_powerup();
266 		break;
267 	case 0x00fb10de: /* Nvidia GeForce PCX 5900 PCIe */
268 		si->ps.card_type = NV35;
269 		si->ps.card_arch = NV30A;
270 		LOG(4,("POWERUP: Detected Nvidia GeForce PCX 5900 PCIe (NV35(?))\n"));
271 		status = nvxx_general_powerup();
272 		break;
273 	case 0x00fc10de: /* Nvidia GeForce PCX 5300 PCIe */
274 		si->ps.card_type = NV34;
275 		si->ps.card_arch = NV30A;
276 		LOG(4,("POWERUP: Detected Nvidia GeForce PCX 5300 PCIe (NV34)\n"));
277 		status = nvxx_general_powerup();
278 		break;
279 	case 0x00fd10de: /* Nvidia Quadro PCX PCIe */
280 		si->ps.card_type = NV45;
281 		si->ps.card_arch = NV40A;
282 		LOG(4,("POWERUP: Detected Nvidia Quadro PCX PCIe (NV45)\n"));
283 		status = nvxx_general_powerup();
284 		break;
285 	case 0x00fe10de: /* Nvidia Quadro FX 1300 PCIe(?) */
286 		si->ps.card_type = NV36;
287 		si->ps.card_arch = NV30A;
288 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 1300 PCIe(?) (NV36(?))\n"));
289 		status = nvxx_general_powerup();
290 		break;
291 	case 0x00ff10de: /* Nvidia GeForce PCX 4300 PCIe */
292 		si->ps.card_type = NV18;
293 		si->ps.card_arch = NV10A;
294 		LOG(4,("POWERUP: Detected Nvidia GeForce PCX 4300 PCIe (NV18)\n"));
295 		status = nvxx_general_powerup();
296 		break;
297 	case 0x010010de: /* Nvidia GeForce256 SDR */
298 	case 0x010110de: /* Nvidia GeForce256 DDR */
299 	case 0x010210de: /* Nvidia GeForce256 Ultra */
300 		si->ps.card_type = NV10;
301 		si->ps.card_arch = NV10A;
302 		LOG(4,("POWERUP: Detected Nvidia GeForce256 (NV10)\n"));
303 		status = nvxx_general_powerup();
304 		break;
305 	case 0x010310de: /* Nvidia Quadro */
306 		si->ps.card_type = NV10;
307 		si->ps.card_arch = NV10A;
308 		LOG(4,("POWERUP: Detected Nvidia Quadro (NV10)\n"));
309 		status = nvxx_general_powerup();
310 		break;
311 	case 0x011010de: /* Nvidia GeForce2 MX/MX400 */
312 	case 0x011110de: /* Nvidia GeForce2 MX100/MX200 DDR */
313 		si->ps.card_type = NV11;
314 		si->ps.card_arch = NV10A;
315 		LOG(4,("POWERUP: Detected Nvidia GeForce2 MX (NV11)\n"));
316 		status = nvxx_general_powerup();
317 		break;
318 	case 0x011210de: /* Nvidia GeForce2 Go */
319 		si->ps.card_type = NV11;
320 		si->ps.card_arch = NV10A;
321 		si->ps.laptop = true;
322 		LOG(4,("POWERUP: Detected Nvidia GeForce2 Go (NV11)\n"));
323 		status = nvxx_general_powerup();
324 		break;
325 	case 0x011310de: /* Nvidia Quadro2 MXR/EX/Go */
326 		si->ps.card_type = NV11;
327 		si->ps.card_arch = NV10A;
328 		LOG(4,("POWERUP: Detected Nvidia Quadro2 MXR/EX/Go (NV11)\n"));
329 		status = nvxx_general_powerup();
330 		break;
331 	case 0x014010de: /* Nvidia GeForce FX 6600 GT */
332 	case 0x014110de: /* Nvidia GeForce FX 6600 */
333 		si->ps.card_type = NV43;
334 		si->ps.card_arch = NV40A;
335 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6600 (NV43)\n"));
336 		status = nvxx_general_powerup();
337 		break;
338 	case 0x014410de: /* Nvidia GeForce FX 6600 Go */
339 		si->ps.card_type = NV43;
340 		si->ps.card_arch = NV40A;
341 		si->ps.laptop = true;
342 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6600 Go (NV43)\n"));
343 		status = nvxx_general_powerup();
344 		break;
345 	case 0x014510de: /* Nvidia GeForce FX 6610 XL */
346 		si->ps.card_type = NV43;
347 		si->ps.card_arch = NV40A;
348 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6610 XL (NV43)\n"));
349 		status = nvxx_general_powerup();
350 		break;
351 	case 0x014610de: /* Nvidia GeForce FX 6600 TE Go / 6200 TE Go */
352 	case 0x014810de: /* Nvidia GeForce FX 6600 Go */
353 		si->ps.card_type = NV43;
354 		si->ps.card_arch = NV40A;
355 		si->ps.laptop = true;
356 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6600 Go / 6200 Go (NV43)\n"));
357 		status = nvxx_general_powerup();
358 		break;
359 	case 0x014e10de: /* Nvidia Quadro FX 540 */
360 		si->ps.card_type = NV43;
361 		si->ps.card_arch = NV40A;
362 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 540 (NV43)\n"));
363 		status = nvxx_general_powerup();
364 		break;
365 	case 0x014f10de: /* Nvidia GeForce 6200 PCIe (128Mb) */
366 		si->ps.card_type = NV44;
367 		si->ps.card_arch = NV40A;
368 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200 PCIe (128Mb) (NV44)\n"));
369 		status = nvxx_general_powerup();
370 		break;
371 	case 0x015010de: /* Nvidia GeForce2 GTS/Pro */
372 	case 0x015110de: /* Nvidia GeForce2 Ti DDR */
373 	case 0x015210de: /* Nvidia GeForce2 Ultra */
374 		si->ps.card_type = NV15;
375 		si->ps.card_arch = NV10A;
376 		LOG(4,("POWERUP: Detected Nvidia GeForce2 (NV15)\n"));
377 		status = nvxx_general_powerup();
378 		break;
379 	case 0x015310de: /* Nvidia Quadro2 Pro */
380 		si->ps.card_type = NV15;
381 		si->ps.card_arch = NV10A;
382 		LOG(4,("POWERUP: Detected Nvidia Quadro2 Pro (NV15)\n"));
383 		status = nvxx_general_powerup();
384 		break;
385 	case 0x016010de: /* Nvidia GeForce 6500 Go */
386 		si->ps.card_type = NV44;
387 		si->ps.card_arch = NV40A;
388 		si->ps.laptop = true;
389 		LOG(4,("POWERUP: Detected Nvidia GeForce 6500 Go (NV44)\n"));
390 		status = nvxx_general_powerup();
391 		break;
392 	case 0x016110de: /* Nvidia GeForce 6200 TurboCache */
393 		si->ps.card_type = NV44;
394 		si->ps.card_arch = NV40A;
395 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200 TurboCache (NV44)\n"));
396 		status = nvxx_general_powerup();
397 		break;
398 	case 0x016210de: /* Nvidia GeForce 6200SE TurboCache */
399 		si->ps.card_type = NV44;
400 		si->ps.card_arch = NV40A;
401 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200SE TurboCache (NV44)\n"));
402 		status = nvxx_general_powerup();
403 		break;
404 	case 0x016310de: /* Nvidia GeForce 6200LE */
405 		si->ps.card_type = NV44;
406 		si->ps.card_arch = NV40A;
407 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200LE (NV44)\n"));
408 		status = nvxx_general_powerup();
409 		break;
410 	case 0x016410de: /* Nvidia GeForce FX 6200 Go */
411 		si->ps.card_type = NV44;
412 		si->ps.card_arch = NV40A;
413 		si->ps.laptop = true;
414 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6200 Go (NV44)\n"));
415 		status = nvxx_general_powerup();
416 		break;
417 	case 0x016510de: /* Nvidia Quadro FX NVS 285 */
418 		si->ps.card_type = NV44;
419 		si->ps.card_arch = NV40A;
420 		LOG(4,("POWERUP: Detected Nvidia Quadro FX NVS 285 (NV44)\n"));
421 		status = nvxx_general_powerup();
422 		break;
423 	case 0x016610de: /* Nvidia GeForce 6400 Go */
424 		si->ps.card_type = NV44;
425 		si->ps.card_arch = NV40A;
426 		si->ps.laptop = true;
427 		LOG(4,("POWERUP: Detected Nvidia GeForce 6400 Go (NV44)\n"));
428 		status = nvxx_general_powerup();
429 		break;
430 	case 0x016710de: /* Nvidia GeForce 6200 Go */
431 		si->ps.card_type = NV44;
432 		si->ps.card_arch = NV40A;
433 		si->ps.laptop = true;
434 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200 Go (NV44)\n"));
435 		status = nvxx_general_powerup();
436 		break;
437 	case 0x016810de: /* Nvidia GeForce 6400 Go */
438 		si->ps.card_type = NV44;
439 		si->ps.card_arch = NV40A;
440 		si->ps.laptop = true;
441 		LOG(4,("POWERUP: Detected Nvidia GeForce 6400 Go (NV44)\n"));
442 		status = nvxx_general_powerup();
443 		break;
444 	case 0x016910de: /* Nvidia GeForce 6250 Go */
445 		si->ps.card_type = NV44;
446 		si->ps.card_arch = NV40A;
447 		si->ps.laptop = true;
448 		LOG(4,("POWERUP: Detected Nvidia GeForce 6250 Go (NV44)\n"));
449 		status = nvxx_general_powerup();
450 		break;
451 	case 0x016e10de: /* Nvidia unknown FX */
452 		si->ps.card_type = NV44;
453 		si->ps.card_arch = NV40A;
454 		LOG(4,("POWERUP: Detected Nvidia unknown FX (NV44)\n"));
455 		status = nvxx_general_powerup();
456 		break;
457 	case 0x017010de: /* Nvidia GeForce4 MX 460 */
458 	case 0x017110de: /* Nvidia GeForce4 MX 440 */
459 	case 0x017210de: /* Nvidia GeForce4 MX 420 */
460 	case 0x017310de: /* Nvidia GeForce4 MX 440SE */
461 		si->ps.card_type = NV17;
462 		si->ps.card_arch = NV10A;
463 		LOG(4,("POWERUP: Detected Nvidia GeForce4 MX (NV17)\n"));
464 		status = nvxx_general_powerup();
465 		break;
466 	case 0x017410de: /* Nvidia GeForce4 440 Go */
467 	case 0x017510de: /* Nvidia GeForce4 420 Go */
468 	case 0x017610de: /* Nvidia GeForce4 420 Go 32M */
469 	case 0x017710de: /* Nvidia GeForce4 460 Go */
470 	case 0x017910de: /* Nvidia GeForce4 440 Go 64M (on PPC GeForce4 MX) */
471 		si->ps.card_type = NV17;
472 		si->ps.card_arch = NV10A;
473 		si->ps.laptop = true;
474 		LOG(4,("POWERUP: Detected Nvidia GeForce4 Go (NV17)\n"));
475 		status = nvxx_general_powerup();
476 		break;
477 	case 0x017810de: /* Nvidia Quadro4 500 XGL/550 XGL */
478 	case 0x017a10de: /* Nvidia Quadro4 200 NVS/400 NVS */
479 		si->ps.card_type = NV17;
480 		si->ps.card_arch = NV10A;
481 		LOG(4,("POWERUP: Detected Nvidia Quadro4 (NV17)\n"));
482 		status = nvxx_general_powerup();
483 		break;
484 	case 0x017c10de: /* Nvidia Quadro4 500 GoGL */
485 		si->ps.card_type = NV17;
486 		si->ps.card_arch = NV10A;
487 		si->ps.laptop = true;
488 		LOG(4,("POWERUP: Detected Nvidia Quadro4 500 GoGL (NV17)\n"));
489 		status = nvxx_general_powerup();
490 		break;
491 	case 0x017d10de: /* Nvidia GeForce4 410 Go 16M*/
492 		si->ps.card_type = NV17;
493 		si->ps.card_arch = NV10A;
494 		si->ps.laptop = true;
495 		LOG(4,("POWERUP: Detected Nvidia GeForce4 410 Go (NV17)\n"));
496 		status = nvxx_general_powerup();
497 		break;
498 	case 0x018110de: /* Nvidia GeForce4 MX 440 AGP8X */
499 	case 0x018210de: /* Nvidia GeForce4 MX 440SE AGP8X */
500 	case 0x018310de: /* Nvidia GeForce4 MX 420 AGP8X */
501 	case 0x018510de: /* Nvidia GeForce4 MX 4000 AGP8X */
502 		si->ps.card_type = NV18;
503 		si->ps.card_arch = NV10A;
504 		LOG(4,("POWERUP: Detected Nvidia GeForce4 MX AGP8X (NV18)\n"));
505 		status = nvxx_general_powerup();
506 		break;
507 	case 0x018610de: /* Nvidia GeForce4 448 Go */
508 	case 0x018710de: /* Nvidia GeForce4 488 Go */
509 		si->ps.card_type = NV18;
510 		si->ps.card_arch = NV10A;
511 		si->ps.laptop = true;
512 		LOG(4,("POWERUP: Detected Nvidia GeForce4 Go (NV18)\n"));
513 		status = nvxx_general_powerup();
514 		break;
515 	case 0x018810de: /* Nvidia Quadro4 580 XGL */
516 		si->ps.card_type = NV18;
517 		si->ps.card_arch = NV10A;
518 		LOG(4,("POWERUP: Detected Nvidia Quadro4 (NV18)\n"));
519 		status = nvxx_general_powerup();
520 		break;
521 	case 0x018910de: /* Nvidia GeForce4 MX AGP8X (PPC) */
522 		si->ps.card_type = NV18;
523 		si->ps.card_arch = NV10A;
524 		LOG(4,("POWERUP: Detected Nvidia GeForce4 MX AGP8X (NV18)\n"));
525 		status = nvxx_general_powerup();
526 		break;
527 	case 0x018a10de: /* Nvidia Quadro4 280 NVS AGP8X */
528 	case 0x018b10de: /* Nvidia Quadro4 380 XGL */
529 	case 0x018c10de: /* Nvidia Quadro4 NVS 50 PCI */
530 		si->ps.card_type = NV18;
531 		si->ps.card_arch = NV10A;
532 		LOG(4,("POWERUP: Detected Nvidia Quadro4 (NV18)\n"));
533 		status = nvxx_general_powerup();
534 		break;
535 	case 0x018d10de: /* Nvidia GeForce4 448 Go */
536 		si->ps.card_type = NV18;
537 		si->ps.card_arch = NV10A;
538 		si->ps.laptop = true;
539 		LOG(4,("POWERUP: Detected Nvidia GeForce4 Go (NV18)\n"));
540 		status = nvxx_general_powerup();
541 		break;
542 	case 0x01a010de: /* Nvidia GeForce2 Integrated GPU */
543 		si->ps.card_type = NV11;
544 		si->ps.card_arch = NV10A;
545 		LOG(4,("POWERUP: Detected Nvidia GeForce2 Integrated GPU (CRUSH, NV11)\n"));
546 		status = nvxx_general_powerup();
547 		break;
548 	case 0x01f010de: /* Nvidia GeForce4 MX Integrated GPU */
549 		si->ps.card_type = NV17;
550 		si->ps.card_arch = NV10A;
551 		LOG(4,("POWERUP: Detected Nvidia GeForce4 MX Integrated GPU (NFORCE2, NV17)\n"));
552 		status = nvxx_general_powerup();
553 		break;
554 	case 0x020010de: /* Nvidia GeForce3 */
555 	case 0x020110de: /* Nvidia GeForce3 Ti 200 */
556 	case 0x020210de: /* Nvidia GeForce3 Ti 500 */
557 		si->ps.card_type = NV20;
558 		si->ps.card_arch = NV20A;
559 		LOG(4,("POWERUP: Detected Nvidia GeForce3 (NV20)\n"));
560 		status = nvxx_general_powerup();
561 		break;
562 	case 0x020310de: /* Nvidia Quadro DCC */
563 		si->ps.card_type = NV20;
564 		si->ps.card_arch = NV20A;
565 		LOG(4,("POWERUP: Detected Nvidia Quadro DCC (NV20)\n"));
566 		status = nvxx_general_powerup();
567 		break;
568 	case 0x021110de: /* Nvidia GeForce FX 6800 */
569 	case 0x021210de: /* Nvidia GeForce FX 6800LE */
570 	case 0x021510de: /* Nvidia GeForce FX 6800 GT */
571 		si->ps.card_type = NV45; /* NV48 is NV45 with 512Mb */
572 		si->ps.card_arch = NV40A;
573 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 6800 (NV48)\n"));
574 		status = nvxx_general_powerup();
575 		break;
576 	case 0x022110de: /* Nvidia GeForce 6200 AGP (256Mb - 128bit) */
577 		si->ps.card_type = NV44;
578 		si->ps.card_arch = NV40A;
579 		LOG(4,("POWERUP: Detected Nvidia GeForce 6200 AGP (256Mb - 128bit) (NV44)\n"));
580 		status = nvxx_general_powerup();
581 		break;
582 	case 0x025010de: /* Nvidia GeForce4 Ti 4600 */
583 	case 0x025110de: /* Nvidia GeForce4 Ti 4400 */
584 	case 0x025210de: /* Nvidia GeForce4 Ti 4600 */
585 	case 0x025310de: /* Nvidia GeForce4 Ti 4200 */
586 		si->ps.card_type = NV25;
587 		si->ps.card_arch = NV20A;
588 		LOG(4,("POWERUP: Detected Nvidia GeForce4 Ti (NV25)\n"));
589 		status = nvxx_general_powerup();
590 		break;
591 	case 0x025810de: /* Nvidia Quadro4 900 XGL */
592 	case 0x025910de: /* Nvidia Quadro4 750 XGL */
593 	case 0x025b10de: /* Nvidia Quadro4 700 XGL */
594 		si->ps.card_type = NV25;
595 		si->ps.card_arch = NV20A;
596 		LOG(4,("POWERUP: Detected Nvidia Quadro4 XGL (NV25)\n"));
597 		status = nvxx_general_powerup();
598 		break;
599 	case 0x028010de: /* Nvidia GeForce4 Ti 4800 AGP8X */
600 	case 0x028110de: /* Nvidia GeForce4 Ti 4200 AGP8X */
601 		si->ps.card_type = NV28;
602 		si->ps.card_arch = NV20A;
603 		LOG(4,("POWERUP: Detected Nvidia GeForce4 Ti AGP8X (NV28)\n"));
604 		status = nvxx_general_powerup();
605 		break;
606 	case 0x028210de: /* Nvidia GeForce4 Ti 4800SE */
607 		si->ps.card_type = NV28;
608 		si->ps.card_arch = NV20A;
609 		LOG(4,("POWERUP: Detected Nvidia GeForce4 Ti 4800SE (NV28)\n"));
610 		status = nvxx_general_powerup();
611 		break;
612 	case 0x028610de: /* Nvidia GeForce4 4200 Go */
613 		si->ps.card_type = NV28;
614 		si->ps.card_arch = NV20A;
615 		si->ps.laptop = true;
616 		LOG(4,("POWERUP: Detected Nvidia GeForce4 4200 Go (NV28)\n"));
617 		status = nvxx_general_powerup();
618 		break;
619 	case 0x028810de: /* Nvidia Quadro4 980 XGL */
620 	case 0x028910de: /* Nvidia Quadro4 780 XGL */
621 		si->ps.card_type = NV28;
622 		si->ps.card_arch = NV20A;
623 		LOG(4,("POWERUP: Detected Nvidia Quadro4 XGL (NV28)\n"));
624 		status = nvxx_general_powerup();
625 		break;
626 	case 0x028c10de: /* Nvidia Quadro4 700 GoGL */
627 		si->ps.card_type = NV28;
628 		si->ps.card_arch = NV20A;
629 		si->ps.laptop = true;
630 		LOG(4,("POWERUP: Detected Nvidia Quadro4 700 GoGL (NV28)\n"));
631 		status = nvxx_general_powerup();
632 		break;
633 	case 0x02a010de: /* Nvidia GeForce3 Integrated GPU */
634 		si->ps.card_type = NV20;
635 		si->ps.card_arch = NV20A;
636 		LOG(4,("POWERUP: Detected Nvidia GeForce3 Integrated GPU (XBOX, NV20)\n"));
637 		status = nvxx_general_powerup();
638 		break;
639 	case 0x030110de: /* Nvidia GeForce FX 5800 Ultra */
640 	case 0x030210de: /* Nvidia GeForce FX 5800 */
641 		si->ps.card_type = NV30;
642 		si->ps.card_arch = NV30A;
643 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5800 (NV30)\n"));
644 		status = nvxx_general_powerup();
645 		break;
646 	case 0x030810de: /* Nvidia Quadro FX 2000 */
647 	case 0x030910de: /* Nvidia Quadro FX 1000 */
648 		si->ps.card_type = NV30;
649 		si->ps.card_arch = NV30A;
650 		LOG(4,("POWERUP: Detected Nvidia Quadro FX (NV30)\n"));
651 		status = nvxx_general_powerup();
652 		break;
653 	case 0x031110de: /* Nvidia GeForce FX 5600 Ultra */
654 	case 0x031210de: /* Nvidia GeForce FX 5600 */
655 		si->ps.card_type = NV31;
656 		si->ps.card_arch = NV30A;
657 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5600 (NV31)\n"));
658 		status = nvxx_general_powerup();
659 		break;
660 	case 0x031310de: /* Nvidia unknown FX */
661 		si->ps.card_type = NV31;
662 		si->ps.card_arch = NV30A;
663 		LOG(4,("POWERUP: Detected Nvidia unknown FX (NV31)\n"));
664 		status = nvxx_general_powerup();
665 		break;
666 	case 0x031410de: /* Nvidia GeForce FX 5600XT */
667 		si->ps.card_type = NV31;
668 		si->ps.card_arch = NV30A;
669 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5600XT (NV31)\n"));
670 		status = nvxx_general_powerup();
671 		break;
672 	case 0x031610de: /* Nvidia unknown FX Go */
673 	case 0x031710de: /* Nvidia unknown FX Go */
674 		si->ps.card_type = NV31;
675 		si->ps.card_arch = NV30A;
676 		si->ps.laptop = true;
677 		LOG(4,("POWERUP: Detected Nvidia unknown FX Go (NV31)\n"));
678 		status = nvxx_general_powerup();
679 		break;
680 	case 0x031a10de: /* Nvidia GeForce FX 5600 Go */
681 		si->ps.card_type = NV31;
682 		si->ps.card_arch = NV30A;
683 		si->ps.laptop = true;
684 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5600 Go (NV31)\n"));
685 		status = nvxx_general_powerup();
686 		break;
687 	case 0x031b10de: /* Nvidia GeForce FX 5650 Go */
688 		si->ps.card_type = NV31;
689 		si->ps.card_arch = NV30A;
690 		si->ps.laptop = true;
691 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5650 Go (NV31)\n"));
692 		status = nvxx_general_powerup();
693 		break;
694 	case 0x031c10de: /* Nvidia Quadro FX 700 Go */
695 		si->ps.card_type = NV31;
696 		si->ps.card_arch = NV30A;
697 		si->ps.laptop = true;
698 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 700 Go (NV31)\n"));
699 		status = nvxx_general_powerup();
700 		break;
701 	case 0x031d10de: /* Nvidia unknown FX Go */
702 	case 0x031e10de: /* Nvidia unknown FX Go */
703 	case 0x031f10de: /* Nvidia unknown FX Go */
704 		si->ps.card_type = NV31;
705 		si->ps.card_arch = NV30A;
706 		si->ps.laptop = true;
707 		LOG(4,("POWERUP: Detected Nvidia unknown FX Go (NV31)\n"));
708 		status = nvxx_general_powerup();
709 		break;
710 	case 0x032010de: /* Nvidia GeForce FX 5200 */
711 	case 0x032110de: /* Nvidia GeForce FX 5200 Ultra */
712 	case 0x032210de: /* Nvidia GeForce FX 5200 */
713 	case 0x032310de: /* Nvidia GeForce FX 5200LE */
714 		si->ps.card_type = NV34;
715 		si->ps.card_arch = NV30A;
716 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5200 (NV34)\n"));
717 		status = nvxx_general_powerup();
718 		break;
719 	case 0x032410de: /* Nvidia GeForce FX 5200 Go */
720 		si->ps.card_type = NV34;
721 		si->ps.card_arch = NV30A;
722 		si->ps.laptop = true;
723 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5200 Go (NV34)\n"));
724 		status = nvxx_general_powerup();
725 		break;
726 	case 0x032510de: /* Nvidia GeForce FX 5250 Go */
727 		si->ps.card_type = NV34;
728 		si->ps.card_arch = NV30A;
729 		si->ps.laptop = true;
730 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5250 Go (NV34)\n"));
731 		status = nvxx_general_powerup();
732 		break;
733 	case 0x032610de: /* Nvidia GeForce FX 5500 */
734 		si->ps.card_type = NV34;
735 		si->ps.card_arch = NV30A;
736 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5500 (NV34)\n"));
737 		status = nvxx_general_powerup();
738 		break;
739 	case 0x032710de: /* Nvidia GeForce FX 5100 */
740 		si->ps.card_type = NV34;
741 		si->ps.card_arch = NV30A;
742 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5100 (NV34)\n"));
743 		status = nvxx_general_powerup();
744 		break;
745 	case 0x032810de: /* Nvidia GeForce FX 5200 Go 32M/64M */
746 		si->ps.card_type = NV34;
747 		si->ps.card_arch = NV30A;
748 		si->ps.laptop = true;
749 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5200 Go (NV34)\n"));
750 		status = nvxx_general_powerup();
751 		break;
752 	case 0x032910de: /* Nvidia GeForce FX 5200 (PPC) */
753 		si->ps.card_type = NV34;
754 		si->ps.card_arch = NV30A;
755 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5200 (NV34)\n"));
756 		status = nvxx_general_powerup();
757 		break;
758 	case 0x032a10de: /* Nvidia Quadro NVS 280 PCI */
759 		si->ps.card_type = NV34;
760 		si->ps.card_arch = NV30A;
761 		LOG(4,("POWERUP: Detected Nvidia Quadro NVS 280 PCI (NV34)\n"));
762 		status = nvxx_general_powerup();
763 		break;
764 	case 0x032b10de: /* Nvidia Quadro FX 500/600 PCI */
765 		si->ps.card_type = NV34;
766 		si->ps.card_arch = NV30A;
767 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 500/600 PCI (NV34)\n"));
768 		status = nvxx_general_powerup();
769 		break;
770 	case 0x032c10de: /* Nvidia GeForce FX 5300 Go */
771 	case 0x032d10de: /* Nvidia GeForce FX 5100 Go */
772 		si->ps.card_type = NV34;
773 		si->ps.card_arch = NV30A;
774 		si->ps.laptop = true;
775 		LOG(4,("POWERUP: Detected Nvidia GeForce FX Go (NV34)\n"));
776 		status = nvxx_general_powerup();
777 		break;
778 	case 0x032e10de: /* Nvidia unknown FX Go */
779 	case 0x032f10de: /* Nvidia unknown FX Go */
780 		si->ps.card_type = NV34;
781 		si->ps.card_arch = NV30A;
782 		si->ps.laptop = true;
783 		LOG(4,("POWERUP: Detected Nvidia unknown FX Go (NV34)\n"));
784 		status = nvxx_general_powerup();
785 		break;
786 	case 0x033010de: /* Nvidia GeForce FX 5900 Ultra */
787 	case 0x033110de: /* Nvidia GeForce FX 5900 */
788 		si->ps.card_type = NV35;
789 		si->ps.card_arch = NV30A;
790 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5900 (NV35)\n"));
791 		status = nvxx_general_powerup();
792 		break;
793 	case 0x033210de: /* Nvidia GeForce FX 5900 XT */
794 		si->ps.card_type = NV35;
795 		si->ps.card_arch = NV30A;
796 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5900 XT (NV35)\n"));
797 		status = nvxx_general_powerup();
798 		break;
799 	case 0x033310de: /* Nvidia GeForce FX 5950 Ultra */
800 		si->ps.card_type = NV38;
801 		si->ps.card_arch = NV30A;
802 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5950 Ultra (NV38)\n"));
803 		status = nvxx_general_powerup();
804 		break;
805 	case 0x033410de: /* Nvidia GeForce FX 5900 ZT */
806 		si->ps.card_type = NV38;
807 		si->ps.card_arch = NV30A;
808 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5900 ZT (NV38(?))\n"));
809 		status = nvxx_general_powerup();
810 		break;
811 	case 0x033810de: /* Nvidia Quadro FX 3000 */
812 		si->ps.card_type = NV35;
813 		si->ps.card_arch = NV30A;
814 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 3000 (NV35)\n"));
815 		status = nvxx_general_powerup();
816 		break;
817 	case 0x033f10de: /* Nvidia Quadro FX 700 */
818 		si->ps.card_type = NV35;
819 		si->ps.card_arch = NV30A;
820 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 700 (NV35)\n"));
821 		status = nvxx_general_powerup();
822 		break;
823 	case 0x034110de: /* Nvidia GeForce FX 5700 Ultra */
824 	case 0x034210de: /* Nvidia GeForce FX 5700 */
825 	case 0x034310de: /* Nvidia GeForce FX 5700LE */
826 	case 0x034410de: /* Nvidia GeForce FX 5700VE */
827 		si->ps.card_type = NV36;
828 		si->ps.card_arch = NV30A;
829 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5700 (NV36)\n"));
830 		status = nvxx_general_powerup();
831 		break;
832 	case 0x034710de: /* Nvidia GeForce FX 5700 Go */
833 	case 0x034810de: /* Nvidia GeForce FX 5700 Go */
834 		si->ps.card_type = NV36;
835 		si->ps.card_arch = NV30A;
836 		si->ps.laptop = true;
837 		LOG(4,("POWERUP: Detected Nvidia GeForce FX 5700 Go (NV36)\n"));
838 		status = nvxx_general_powerup();
839 		break;
840 	case 0x034c10de: /* Nvidia Quadro FX 1000 Go */
841 		si->ps.card_type = NV36;
842 		si->ps.card_arch = NV30A;
843 		si->ps.laptop = true;
844 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 1000 Go (NV36)\n"));
845 		status = nvxx_general_powerup();
846 		break;
847 	case 0x034e10de: /* Nvidia Quadro FX 1100 */
848 		si->ps.card_type = NV36;
849 		si->ps.card_arch = NV30A;
850 		LOG(4,("POWERUP: Detected Nvidia Quadro FX 1100 (NV36)\n"));
851 		status = nvxx_general_powerup();
852 		break;
853 	case 0x034f10de: /* Nvidia unknown FX */
854 		si->ps.card_type = NV36;
855 		si->ps.card_arch = NV30A;
856 		LOG(4,("POWERUP: Detected Nvidia unknown FX (NV36(?))\n"));
857 		status = nvxx_general_powerup();
858 		break;
859 	/* Vendor Elsa GmbH */
860 	case 0x0c601048: /* Elsa Gladiac Geforce2 MX */
861 		si->ps.card_type = NV11;
862 		si->ps.card_arch = NV10A;
863 		LOG(4,("POWERUP: Detected Elsa Gladiac Geforce2 MX (NV11)\n"));
864 		status = nvxx_general_powerup();
865 		break;
866 	/* Vendor Nvidia STB/SGS-Thompson */
867 	case 0x002012d2: /* Nvidia STB/SGS-Thompson TNT1 */
868 		si->ps.card_type = NV04;
869 		si->ps.card_arch = NV04A;
870 		LOG(4,("POWERUP: Detected Nvidia STB/SGS-Thompson TNT1 (NV04)\n"));
871 		status = nvxx_general_powerup();
872 		break;
873 	case 0x002812d2: /* Nvidia STB/SGS-Thompson TNT2 (pro) */
874 	case 0x002912d2: /* Nvidia STB/SGS-Thompson TNT2 Ultra */
875 	case 0x002a12d2: /* Nvidia STB/SGS-Thompson TNT2 */
876 	case 0x002b12d2: /* Nvidia STB/SGS-Thompson TNT2 */
877 		si->ps.card_type = NV05;
878 		si->ps.card_arch = NV04A;
879 		LOG(4,("POWERUP: Detected Nvidia STB/SGS-Thompson TNT2 (NV05)\n"));
880 		status = nvxx_general_powerup();
881 		break;
882 	case 0x002c12d2: /* Nvidia STB/SGS-Thompson Vanta (Lt) */
883 		si->ps.card_type = NV05;
884 		si->ps.card_arch = NV04A;
885 		LOG(4,("POWERUP: Detected Nvidia STB/SGS-Thompson Vanta (Lt) (NV05)\n"));
886 		status = nvxx_general_powerup();
887 		break;
888 	case 0x002d12d2: /* Nvidia STB/SGS-Thompson TNT2-M64 (Pro) */
889 		si->ps.card_type = NV05M64;
890 		si->ps.card_arch = NV04A;
891 		LOG(4,("POWERUP: Detected Nvidia STB/SGS-Thompson TNT2-M64 (Pro) (NV05M64)\n"));
892 		status = nvxx_general_powerup();
893 		break;
894 	case 0x002e12d2: /* Nvidia STB/SGS-Thompson NV06 Vanta */
895 	case 0x002f12d2: /* Nvidia STB/SGS-Thompson NV06 Vanta */
896 		si->ps.card_type = NV06;
897 		si->ps.card_arch = NV04A;
898 		LOG(4,("POWERUP: Detected Nvidia STB/SGS-Thompson Vanta (NV06)\n"));
899 		status = nvxx_general_powerup();
900 		break;
901 	case 0x00a012d2: /* Nvidia STB/SGS-Thompson Aladdin TNT2 */
902 		si->ps.card_type = NV05;
903 		si->ps.card_arch = NV04A;
904 		LOG(4,("POWERUP: Detected Nvidia STB/SGS-Thompson Aladdin TNT2 (NV05)\n"));
905 		status = nvxx_general_powerup();
906 		break;
907 	/* Vendor Varisys Limited */
908 	case 0x35031888: /* Varisys GeForce4 MX440 */
909 		si->ps.card_type = NV17;
910 		si->ps.card_arch = NV10A;
911 		LOG(4,("POWERUP: Detected Varisys GeForce4 MX440 (NV17)\n"));
912 		status = nvxx_general_powerup();
913 		break;
914 	case 0x35051888: /* Varisys GeForce4 Ti 4200 */
915 		si->ps.card_type = NV25;
916 		si->ps.card_arch = NV20A;
917 		LOG(4,("POWERUP: Detected Varisys GeForce4 Ti 4200 (NV25)\n"));
918 		status = nvxx_general_powerup();
919 		break;
920 	default:
921 		LOG(8,("POWERUP: Failed to detect valid card 0x%08x\n",CFGR(DEVID)));
922 		return B_ERROR;
923 	}
924 
925 	return status;
926 }
927 
928 static status_t test_ram()
929 {
930 	uint32 value, offset;
931 	status_t result = B_OK;
932 
933 	/* make sure we don't corrupt the hardware cursor by using fbc.frame_buffer. */
934 	if (si->fbc.frame_buffer == NULL)
935 	{
936 		LOG(8,("INIT: test_ram detected NULL pointer.\n"));
937 		return B_ERROR;
938 	}
939 
940 	for (offset = 0, value = 0x55aa55aa; offset < 256; offset++)
941 	{
942 		/* write testpattern to cardRAM */
943 		((uint32 *)si->fbc.frame_buffer)[offset] = value;
944 		/* toggle testpattern */
945 		value = 0xffffffff - value;
946 	}
947 
948 	for (offset = 0, value = 0x55aa55aa; offset < 256; offset++)
949 	{
950 		/* readback and verify testpattern from cardRAM */
951 		if (((uint32 *)si->fbc.frame_buffer)[offset] != value) result = B_ERROR;
952 		/* toggle testpattern */
953 		value = 0xffffffff - value;
954 	}
955 	return result;
956 }
957 
958 /* NOTE:
959  * This routine *has* to be done *after* SetDispplayMode has been executed,
960  * or test results will not be representative!
961  * (CAS latency is dependant on NV setup on some (DRAM) boards) */
962 status_t nv_set_cas_latency()
963 {
964 	status_t result = B_ERROR;
965 	uint8 latency = 0;
966 
967 	/* check current RAM access to see if we need to change anything */
968 	if (test_ram() == B_OK)
969 	{
970 		LOG(4,("INIT: RAM access OK.\n"));
971 		return B_OK;
972 	}
973 
974 	/* check if we read PINS at starttime so we have valid registersettings at our disposal */
975 	if (si->ps.pins_status != B_OK)
976 	{
977 		LOG(4,("INIT: RAM access errors; not fixable: PINS was not read from cardBIOS.\n"));
978 		return B_ERROR;
979 	}
980 
981 	/* OK. We might have a problem, try to fix it now.. */
982 	LOG(4,("INIT: RAM access errors; tuning CAS latency if prudent...\n"));
983 
984 	switch(si->ps.card_type)
985 	{
986 	default:
987 			LOG(4,("INIT: RAM CAS tuning not implemented for this card, aborting.\n"));
988 			return B_OK;
989 			break;
990 	}
991 	if (result == B_OK)
992 		LOG(4,("INIT: RAM access OK. CAS latency set to %d cycles.\n", latency));
993 	else
994 		LOG(4,("INIT: RAM access not fixable. CAS latency set to %d cycles.\n", latency));
995 
996 	return result;
997 }
998 
999 void setup_virtualized_heads(bool cross)
1000 {
1001 	if (cross)
1002 	{
1003 		head1_validate_timing	= (crtc_validate_timing)	nv_crtc2_validate_timing;
1004 		head1_set_timing		= (crtc_set_timing)			nv_crtc2_set_timing;
1005 		head1_depth				= (crtc_depth)				nv_crtc2_depth;
1006 		head1_dpms				= (crtc_dpms)				nv_crtc2_dpms;
1007 		head1_set_display_pitch	= (crtc_set_display_pitch)	nv_crtc2_set_display_pitch;
1008 		head1_set_display_start	= (crtc_set_display_start)	nv_crtc2_set_display_start;
1009 		head1_cursor_init		= (crtc_cursor_init)		nv_crtc2_cursor_init;
1010 		head1_cursor_show		= (crtc_cursor_show)		nv_crtc2_cursor_show;
1011 		head1_cursor_hide		= (crtc_cursor_hide)		nv_crtc2_cursor_hide;
1012 		head1_cursor_define		= (crtc_cursor_define)		nv_crtc2_cursor_define;
1013 		head1_cursor_position	= (crtc_cursor_position)	nv_crtc2_cursor_position;
1014 		head1_stop_tvout		= (crtc_stop_tvout)			nv_crtc2_stop_tvout;
1015 		head1_start_tvout		= (crtc_start_tvout)		nv_crtc2_start_tvout;
1016 
1017 		head1_mode				= (dac_mode)				nv_dac2_mode;
1018 		head1_palette			= (dac_palette)				nv_dac2_palette;
1019 		head1_set_pix_pll		= (dac_set_pix_pll)			nv_dac2_set_pix_pll;
1020 		head1_pix_pll_find		= (dac_pix_pll_find)		nv_dac2_pix_pll_find;
1021 
1022 		head2_validate_timing	= (crtc_validate_timing)	nv_crtc_validate_timing;
1023 		head2_set_timing		= (crtc_set_timing)			nv_crtc_set_timing;
1024 		head2_depth				= (crtc_depth)				nv_crtc_depth;
1025 		head2_dpms				= (crtc_dpms)				nv_crtc_dpms;
1026 		head2_set_display_pitch	= (crtc_set_display_pitch)	nv_crtc_set_display_pitch;
1027 		head2_set_display_start	= (crtc_set_display_start)	nv_crtc_set_display_start;
1028 		head2_cursor_init		= (crtc_cursor_init)		nv_crtc_cursor_init;
1029 		head2_cursor_show		= (crtc_cursor_show)		nv_crtc_cursor_show;
1030 		head2_cursor_hide		= (crtc_cursor_hide)		nv_crtc_cursor_hide;
1031 		head2_cursor_define		= (crtc_cursor_define)		nv_crtc_cursor_define;
1032 		head2_cursor_position	= (crtc_cursor_position)	nv_crtc_cursor_position;
1033 		head2_stop_tvout		= (crtc_stop_tvout)			nv_crtc_stop_tvout;
1034 		head2_start_tvout		= (crtc_start_tvout)		nv_crtc_start_tvout;
1035 
1036 		head2_mode				= (dac_mode)				nv_dac_mode;
1037 		head2_palette			= (dac_palette)				nv_dac_palette;
1038 		head2_set_pix_pll		= (dac_set_pix_pll)			nv_dac_set_pix_pll;
1039 		head2_pix_pll_find		= (dac_pix_pll_find)		nv_dac_pix_pll_find;
1040 	}
1041 	else
1042 	{
1043 		head1_validate_timing	= (crtc_validate_timing)	nv_crtc_validate_timing;
1044 		head1_set_timing		= (crtc_set_timing)			nv_crtc_set_timing;
1045 		head1_depth				= (crtc_depth)				nv_crtc_depth;
1046 		head1_dpms				= (crtc_dpms)				nv_crtc_dpms;
1047 		head1_set_display_pitch	= (crtc_set_display_pitch)	nv_crtc_set_display_pitch;
1048 		head1_set_display_start	= (crtc_set_display_start)	nv_crtc_set_display_start;
1049 		head1_cursor_init		= (crtc_cursor_init)		nv_crtc_cursor_init;
1050 		head1_cursor_show		= (crtc_cursor_show)		nv_crtc_cursor_show;
1051 		head1_cursor_hide		= (crtc_cursor_hide)		nv_crtc_cursor_hide;
1052 		head1_cursor_define		= (crtc_cursor_define)		nv_crtc_cursor_define;
1053 		head1_cursor_position	= (crtc_cursor_position)	nv_crtc_cursor_position;
1054 		head1_stop_tvout		= (crtc_stop_tvout)			nv_crtc_stop_tvout;
1055 		head1_start_tvout		= (crtc_start_tvout)		nv_crtc_start_tvout;
1056 
1057 		head1_mode				= (dac_mode)				nv_dac_mode;
1058 		head1_palette			= (dac_palette)				nv_dac_palette;
1059 		head1_set_pix_pll		= (dac_set_pix_pll)			nv_dac_set_pix_pll;
1060 		head1_pix_pll_find		= (dac_pix_pll_find)		nv_dac_pix_pll_find;
1061 
1062 		head2_validate_timing	= (crtc_validate_timing)	nv_crtc2_validate_timing;
1063 		head2_set_timing		= (crtc_set_timing)			nv_crtc2_set_timing;
1064 		head2_depth				= (crtc_depth)				nv_crtc2_depth;
1065 		head2_dpms				= (crtc_dpms)				nv_crtc2_dpms;
1066 		head2_set_display_pitch	= (crtc_set_display_pitch)	nv_crtc2_set_display_pitch;
1067 		head2_set_display_start	= (crtc_set_display_start)	nv_crtc2_set_display_start;
1068 		head2_cursor_init		= (crtc_cursor_init)		nv_crtc2_cursor_init;
1069 		head2_cursor_show		= (crtc_cursor_show)		nv_crtc2_cursor_show;
1070 		head2_cursor_hide		= (crtc_cursor_hide)		nv_crtc2_cursor_hide;
1071 		head2_cursor_define		= (crtc_cursor_define)		nv_crtc2_cursor_define;
1072 		head2_cursor_position	= (crtc_cursor_position)	nv_crtc2_cursor_position;
1073 		head2_stop_tvout		= (crtc_stop_tvout)			nv_crtc2_stop_tvout;
1074 		head2_start_tvout		= (crtc_start_tvout)		nv_crtc2_start_tvout;
1075 
1076 		head2_mode				= (dac_mode)				nv_dac2_mode;
1077 		head2_palette			= (dac_palette)				nv_dac2_palette;
1078 		head2_set_pix_pll		= (dac_set_pix_pll)			nv_dac2_set_pix_pll;
1079 		head2_pix_pll_find		= (dac_pix_pll_find)		nv_dac2_pix_pll_find;
1080 	}
1081 }
1082 
1083 void set_crtc_owner(bool head)
1084 {
1085 	if (si->ps.secondary_head)
1086 	{
1087 		if (!head)
1088 		{
1089 			/* note: 'OWNER' is a non-standard register in behaviour(!) on NV11's,
1090 			 * while non-NV11 cards behave normally.
1091 			 *
1092 			 * Double-write action needed on those strange NV11 cards: */
1093 			/* RESET: needed on NV11 */
1094 			CRTCW(OWNER, 0xff);
1095 			/* enable access to CRTC1, SEQ1, GRPH1, ATB1, ??? */
1096 			CRTCW(OWNER, 0x00);
1097 		}
1098 		else
1099 		{
1100 			/* note: 'OWNER' is a non-standard register in behaviour(!) on NV11's,
1101 			 * while non-NV11 cards behave normally.
1102 			 *
1103 			 * Double-write action needed on those strange NV11 cards: */
1104 			/* RESET: needed on NV11 */
1105 			CRTC2W(OWNER, 0xff);
1106 			/* enable access to CRTC2, SEQ2, GRPH2, ATB2, ??? */
1107 			CRTC2W(OWNER, 0x03);
1108 		}
1109 	}
1110 }
1111 
1112 static status_t nvxx_general_powerup()
1113 {
1114 	LOG(4, ("INIT: NV powerup\n"));
1115 
1116 	/* setup cardspecs */
1117 	/* note:
1118 	 * this MUST be done before the driver attempts a card coldstart */
1119 	set_specs();
1120 
1121 	/* only process BIOS for finetuning specs and coldstarting card if requested
1122 	 * by the user;
1123 	 * note:
1124 	 * this in fact frees the driver from relying on the BIOS to be executed
1125 	 * at system power-up POST time. */
1126 	if (!si->settings.usebios)
1127 	{
1128 		LOG(2, ("INIT: Attempting card coldstart!\n"));
1129 		/* update the cardspecs in the shared_info PINS struct according to reported
1130 		 * specs as much as is possible;
1131 		 * this also coldstarts the card if possible (executes BIOS CMD script(s)) */
1132 		parse_pins();
1133 	}
1134 	else
1135 	{
1136 		LOG(2, ("INIT: Skipping card coldstart!\n"));
1137 	}
1138 
1139 	unlock_card();
1140 
1141 	/* get RAM size, detect TV encoder and do fake panel startup (panel init code
1142 	 *  is still missing). */
1143 	fake_panel_start();
1144 
1145 	/* log the final card specifications */
1146 	dump_pins();
1147 
1148 	/* dump config space as it is after a possible coldstart attempt */
1149 	if (si->settings.logmask & 0x80000000) nv_dump_configuration_space();
1150 
1151 	/* setup CRTC and DAC functions access: determined in fake_panel_start */
1152 	setup_virtualized_heads(si->ps.crtc2_prim);
1153 
1154 	/* do powerup needed from pre-inited card state as done by system POST cardBIOS
1155 	 * execution or driver coldstart above */
1156 	return nv_general_bios_to_powergraphics();
1157 }
1158 
1159 /* this routine switches the CRTC/DAC sets to 'connectors', but only for analog
1160  * outputs. We need this to make sure the analog 'switch' is set in the same way the
1161  * digital 'switch' is set by the BIOS or we might not be able to use dualhead. */
1162 status_t nv_general_output_select(bool cross)
1163 {
1164 	/* make sure this call is warranted */
1165 	if (si->ps.secondary_head)
1166 	{
1167 		/* NV11 cards can't switch heads (confirmed) */
1168 		if (si->ps.card_type != NV11)
1169 		{
1170 			if (cross)
1171 			{
1172 				LOG(4,("INIT: switching analog outputs to be cross-connected\n"));
1173 
1174 				/* enable head 2 on connector 1 */
1175 				/* (b8 = select CRTC (head) for output,
1176 				 *  b4 = ??? (confirmed not to be a FP switch),
1177 				 *  b0 = enable CRT) */
1178 				DACW(OUTPUT, 0x00000101);
1179 				/* enable head 1 on connector 2 */
1180 				DAC2W(OUTPUT, 0x00000001);
1181 			}
1182 			else
1183 			{
1184 				LOG(4,("INIT: switching analog outputs to be straight-through\n"));
1185 
1186 				/* enable head 1 on connector 1 */
1187 				DACW(OUTPUT, 0x00000001);
1188 				/* enable head 2 on connector 2 */
1189 				DAC2W(OUTPUT, 0x00000101);
1190 			}
1191 		}
1192 		else
1193 		{
1194 			LOG(4,("INIT: NV11 analog outputs are hardwired to be straight-through\n"));
1195 		}
1196 		return B_OK;
1197 	}
1198 	else
1199 	{
1200 		return B_ERROR;
1201 	}
1202 }
1203 
1204 /* this routine switches CRTC/DAC set use. We need this because it's unknown howto
1205  * switch digital panels to/from a specific CRTC/DAC set. */
1206 status_t nv_general_head_select(bool cross)
1207 {
1208 	/* make sure this call is warranted */
1209 	if (si->ps.secondary_head)
1210 	{
1211 		/* invert CRTC/DAC use to do switching */
1212 		if (cross)
1213 		{
1214 			LOG(4,("INIT: switching CRTC/DAC use to be cross-connected\n"));
1215 			si->crtc_switch_mode = !si->ps.crtc2_prim;
1216 		}
1217 		else
1218 		{
1219 			LOG(4,("INIT: switching CRTC/DAC use to be straight-through\n"));
1220 			si->crtc_switch_mode = si->ps.crtc2_prim;
1221 		}
1222 		/* update CRTC and DAC functions access */
1223 		setup_virtualized_heads(si->crtc_switch_mode);
1224 
1225 		return B_OK;
1226 	}
1227 	else
1228 	{
1229 		return B_ERROR;
1230 	}
1231 }
1232 
1233 static void unlock_card(void)
1234 {
1235 	/* power-up all nvidia hardware function blocks */
1236 	/* bit 28: OVERLAY ENGINE (BES),
1237 	 * bit 25: CRTC2, (> NV04A)
1238 	 * bit 24: CRTC1,
1239 	 * bit 20: framebuffer,
1240 	 * bit 16: PPMI,
1241 	 * bit 12: PGRAPH,
1242 	 * bit  8: PFIFO,
1243 	 * bit  4: PMEDIA,
1244 	 * bit  0: TVOUT. (> NV04A) */
1245 	NV_REG32(NV32_PWRUPCTRL) = 0x13111111;
1246 
1247 	/* select colormode CRTC registers base adresses */
1248 	NV_REG8(NV8_MISCW) = 0xcb;
1249 
1250 	/* enable access to primary head */
1251 	set_crtc_owner(0);
1252 	/* unlock head's registers for R/W access */
1253 	CRTCW(LOCK, 0x57);
1254 	CRTCW(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
1255 	if (si->ps.secondary_head)
1256 	{
1257 		/* enable access to secondary head */
1258 		set_crtc_owner(1);
1259 		/* unlock head's registers for R/W access */
1260 		CRTC2W(LOCK, 0x57);
1261 		CRTC2W(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
1262 	}
1263 }
1264 
1265 /* basic change of card state from VGA to enhanced mode:
1266  * Should work from VGA BIOS POST init state. */
1267 static status_t nv_general_bios_to_powergraphics()
1268 {
1269 	/* let acc engine make power off/power on cycle to start 'fresh' */
1270 	NV_REG32(NV32_PWRUPCTRL) = 0x13110011;
1271 	snooze(1000);
1272 	NV_REG32(NV32_PWRUPCTRL) = 0x13111111;
1273 
1274 	unlock_card();
1275 
1276 	/* turn off both displays and the hardcursors (also disables transfers) */
1277 	head1_dpms(false, false, false, true);
1278 	head1_cursor_hide();
1279 	if (si->ps.secondary_head)
1280 	{
1281 		head2_dpms(false, false, false, true);
1282 		head2_cursor_hide();
1283 	}
1284 
1285 	if (si->ps.secondary_head)
1286 	{
1287 		/* switch overlay engine and TV encoder to CRTC1 */
1288 		/* bit 17: GPU FP port #1	(confirmed NV25, NV28, confirmed not on NV34),
1289 		 * bit 16: GPU FP port #2	(confirmed NV25, NV28, NV34),
1290 		 * bit 12: overlay engine	(all cards),
1291 		 * bit  9: TVout chip #2	(confirmed on NV18, NV25, NV28),
1292 		 * bit  8: TVout chip #1	(all cards),
1293 		 * bit  4: both I2C busses	(all cards) */
1294 		NV_REG32(NV32_2FUNCSEL) &= ~0x00001100;
1295 		NV_REG32(NV32_FUNCSEL) |= 0x00001100;
1296 	}
1297 	si->overlay.crtc = false;
1298 
1299 	/* enable 'enhanced' mode on primary head: */
1300 	/* enable access to primary head */
1301 	set_crtc_owner(0);
1302 	/* note: 'BUFFER' is a non-standard register in behaviour(!) on most
1303 	 * NV11's like the GeForce2 MX200, while the MX400 and non-NV11 cards
1304 	 * behave normally.
1305 	 * Also readback is not nessesarily what was written before!
1306 	 *
1307 	 * Double-write action needed on those strange NV11 cards: */
1308 	/* RESET: don't doublebuffer CRTC access: set programmed values immediately... */
1309 	CRTCW(BUFFER, 0xff);
1310 	/* ... and use fine pitched CRTC granularity on > NV4 cards (b2 = 0) */
1311 	/* note: this has no effect on possible bandwidth issues. */
1312 	CRTCW(BUFFER, 0xfb);
1313 	/* select VGA mode (old VGA register) */
1314 	CRTCW(MODECTL, 0xc3);
1315 	/* select graphics mode (old VGA register) */
1316 	SEQW(MEMMODE, 0x0e);
1317 	/* select 8 dots character clocks (old VGA register) */
1318 	SEQW(CLKMODE, 0x21);
1319 	/* select VGA mode (old VGA register) */
1320 	GRPHW(MODE, 0x00);
1321 	/* select graphics mode (old VGA register) */
1322 	GRPHW(MISC, 0x01);
1323 	/* select graphics mode (old VGA register) */
1324 	ATBW(MODECTL, 0x01);
1325 	/* enable 'enhanced mode', enable Vsync & Hsync,
1326 	 * set DAC palette to 8-bit width, disable large screen */
1327 	CRTCW(REPAINT1, 0x04);
1328 
1329 	/* enable 'enhanced' mode on secondary head: */
1330 	if (si->ps.secondary_head)
1331 	{
1332 		/* enable access to secondary head */
1333 		set_crtc_owner(1);
1334 		/* select colormode CRTC2 registers base adresses */
1335 		NV_REG8(NV8_MISCW) = 0xcb;
1336 		/* note: 'BUFFER' is a non-standard register in behaviour(!) on most
1337 		 * NV11's like the GeForce2 MX200, while the MX400 and non-NV11 cards
1338 		 * behave normally.
1339 		 * Also readback is not nessesarily what was written before!
1340 		 *
1341 		 * Double-write action needed on those strange NV11 cards: */
1342 		/* RESET: don't doublebuffer CRTC2 access: set programmed values immediately... */
1343 		CRTC2W(BUFFER, 0xff);
1344 		/* ... and use fine pitched CRTC granularity on > NV4 cards (b2 = 0) */
1345 		/* note: this has no effect on possible bandwidth issues. */
1346 		CRTC2W(BUFFER, 0xfb);
1347 		/* select VGA mode (old VGA register) */
1348 		CRTC2W(MODECTL, 0xc3);
1349 		/* select graphics mode (old VGA register) */
1350 		SEQW(MEMMODE, 0x0e);
1351 		/* select 8 dots character clocks (old VGA register) */
1352 		SEQW(CLKMODE, 0x21);
1353 		/* select VGA mode (old VGA register) */
1354 		GRPHW(MODE, 0x00);
1355 		/* select graphics mode (old VGA register) */
1356 		GRPHW(MISC, 0x01);
1357 		/* select graphics mode (old VGA register) */
1358 		ATB2W(MODECTL, 0x01);
1359 		/* enable 'enhanced mode', enable Vsync & Hsync,
1360 		 * set DAC palette to 8-bit width, disable large screen */
1361 		CRTC2W(REPAINT1, 0x04);
1362 	}
1363 
1364 	/* enable palettes */
1365 	DACW(GENCTRL, 0x00100100);
1366 	if (si->ps.secondary_head) DAC2W(GENCTRL, 0x00100100);
1367 
1368 	/* enable programmable PLLs */
1369 	/* (confirmed PLLSEL to be a write-only register on NV04 and NV11!) */
1370 	if (si->ps.secondary_head)
1371 		DACW(PLLSEL, 0x30000f00);
1372 	else
1373 		DACW(PLLSEL, 0x10000700);
1374 
1375 	/* turn on DAC and make sure detection testsignal routing is disabled
1376 	 * (b16 = disable DAC,
1377 	 *  b12 = enable testsignal output */
1378 	//fixme note: b20 ('DACTM_TEST') when set apparantly blocks a DAC's video output
1379 	//(confirmed NV43), while it's timing remains operational (black screen).
1380 	//It feels like in some screen configurations it can move the output to the other
1381 	//output connector as well...
1382 	DACW(TSTCTRL, (DACR(TSTCTRL) & 0xfffeefff));
1383 	/* turn on DAC2 if it exists
1384 	 * (NOTE: testsignal function block resides in DAC1 only (!)) */
1385 	if (si->ps.secondary_head) DAC2W(TSTCTRL, (DAC2R(TSTCTRL) & 0xfffeefff));
1386 
1387 	/* NV40 and NV45 need a 'tweak' to make sure the CRTC FIFO's/shiftregisters get
1388 	 * their data in time (otherwise momentarily ghost images of windows or such
1389 	 * may appear on heavy acceleration engine use for instance, especially in 32-bit
1390 	 * colordepth) */
1391 	if ((si->ps.card_type == NV40) || (si->ps.card_type == NV45))
1392 	{
1393 		/* clear b15: some framebuffer config item (unknown) */
1394 		NV_REG32(NV32_PFB_CLS_PAGE2) &= 0xffff7fff;
1395 	}
1396 
1397 	/* setup AGP:
1398 	 * Note:
1399 	 * This may only be done when no transfers are in progress on the bus, so now
1400 	 * is probably a good time.. */
1401 	nv_agp_setup();
1402 
1403 	return B_OK;
1404 }
1405 
1406 /* Check if mode virtual_size adheres to the cards _maximum_ contraints, and modify
1407  * virtual_size to the nearest valid maximum for the mode on the card if not so.
1408  * Also: check if virtual_width adheres to the cards granularity constraints, and
1409  * create mode slopspace if not so.
1410  * We use acc or crtc granularity constraints based on the 'worst case' scenario.
1411  *
1412  * Mode slopspace is reflected in fbc->bytes_per_row BTW. */
1413 status_t nv_general_validate_pic_size (display_mode *target, uint32 *bytes_per_row, bool *acc_mode)
1414 {
1415 	uint32 video_pitch;
1416 	uint32 acc_mask, crtc_mask;
1417 	uint32 max_crtc_width, max_acc_width;
1418 	uint8 depth = 8;
1419 
1420 	/* determine pixel multiple based on acceleration engine constraints */
1421 	/* note:
1422 	 * because of the seemingly 'random' variations in these constraints we take
1423 	 * a reasonable 'lowest common denominator' instead of always true constraints. */
1424 	switch (si->ps.card_arch)
1425 	{
1426 	case NV04A:
1427 		/* confirmed for:
1428 		 * TNT1 (NV04), TNT2 (NV05), TNT2-M64 (NV05M64), GeForce2 MX400 (NV11),
1429 		 * GeForce4 MX440 (NV18), GeForceFX 5200 (NV34) in PIO acc mode;
1430 		 * confirmed for:
1431 		 * TNT1 (NV04), TNT2 (NV05), TNT2-M64 (NV05M64), GeForce4 Ti4200 (NV28),
1432 		 * GeForceFX 5200 (NV34) in DMA acc mode. */
1433 		switch (target->space)
1434 		{
1435 			case B_CMAP8: acc_mask = 0x0f; depth =  8; break;
1436 			case B_RGB15: acc_mask = 0x07; depth = 16; break;
1437 			case B_RGB16: acc_mask = 0x07; depth = 16; break;
1438 			case B_RGB24: acc_mask = 0x0f; depth = 24; break;
1439 			case B_RGB32: acc_mask = 0x03; depth = 32; break;
1440 			default:
1441 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1442 				return B_ERROR;
1443 		}
1444 		break;
1445 	default:
1446 		/* confirmed for:
1447 		 * GeForce4 Ti4200 (NV28), GeForceFX 5600 (NV31) in PIO acc mode;
1448 		 * confirmed for:
1449 		 * GeForce2 MX400 (NV11), GeForce4 MX440 (NV18), GeForcePCX 5750 (NV36),
1450 		 * GeForcePCX 6600 GT (NV43) in DMA acc mode. */
1451 		switch (target->space)
1452 		{
1453 			case B_CMAP8: acc_mask = 0x3f; depth =  8; break;
1454 			case B_RGB15: acc_mask = 0x1f; depth = 16; break;
1455 			case B_RGB16: acc_mask = 0x1f; depth = 16; break;
1456 			case B_RGB24: acc_mask = 0x3f; depth = 24; break;
1457 			case B_RGB32: acc_mask = 0x0f; depth = 32; break;
1458 			default:
1459 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1460 				return B_ERROR;
1461 		}
1462 		break;
1463 	}
1464 
1465 	/* determine pixel multiple based on CRTC memory pitch constraints:
1466 	 * -> all NV cards have same granularity constraints on CRTC1 and CRTC2,
1467 	 *    provided that the CRTC1 and CRTC2 BUFFER register b2 = 0;
1468 	 *
1469 	 * (Note: Don't mix this up with CRTC timing contraints! Those are
1470 	 *        multiples of 8 for horizontal, 1 for vertical timing.) */
1471 	switch (si->ps.card_type)
1472 	{
1473 	default:
1474 //	case NV04:
1475 		/* confirmed for:
1476 		 * TNT1 always;
1477 		 * TNT2, TNT2-M64, GeForce2 MX400, GeForce4 MX440, GeForce4 Ti4200,
1478 		 * GeForceFX 5200: if the CRTC1 (and CRTC2) BUFFER register b2 = 0 */
1479 		/* NOTE:
1480 		 * Unfortunately older cards have a hardware fault that prevents use.
1481 		 * We need doubled granularity on those to prevent the single top line
1482 		 * from shifting to the left!
1483 		 * This is confirmed for TNT2, GeForce2 MX200, GeForce2 MX400.
1484 		 * Confirmed OK are:
1485 		 * GeForce4 MX440, GeForce4 Ti4200, GeForceFX 5200. */
1486 		switch (target->space)
1487 		{
1488 			case B_CMAP8: crtc_mask = 0x0f; break; /* 0x07 */
1489 			case B_RGB15: crtc_mask = 0x07; break; /* 0x03 */
1490 			case B_RGB16: crtc_mask = 0x07; break; /* 0x03 */
1491 			case B_RGB24: crtc_mask = 0x0f; break; /* 0x07 */
1492 			case B_RGB32: crtc_mask = 0x03; break; /* 0x01 */
1493 			default:
1494 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1495 				return B_ERROR;
1496 		}
1497 		break;
1498 //	default:
1499 		/* confirmed for:
1500 		 * TNT2, TNT2-M64, GeForce2 MX400, GeForce4 MX440, GeForce4 Ti4200,
1501 		 * GeForceFX 5200: if the CRTC1 (and CRTC2) BUFFER register b2 = 1 */
1502 /*		switch (target->space)
1503 		{
1504 			case B_CMAP8: crtc_mask = 0x1f; break;
1505 			case B_RGB15: crtc_mask = 0x0f; break;
1506 			case B_RGB16: crtc_mask = 0x0f; break;
1507 			case B_RGB24: crtc_mask = 0x1f; break;
1508 			case B_RGB32: crtc_mask = 0x07; break;
1509 			default:
1510 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1511 				return B_ERROR;
1512 		}
1513 		break;
1514 */	}
1515 
1516 	/* set virtual_width limit for accelerated modes */
1517 	/* note:
1518 	 * because of the seemingly 'random' variations in these constraints we take
1519 	 * a reasonable 'lowest common denominator' instead of always true constraints. */
1520 	switch (si->ps.card_arch)
1521 	{
1522 	case NV04A:
1523 		/* confirmed for:
1524 		 * TNT1 (NV04), TNT2 (NV05), TNT2-M64 (NV05M64) in both PIO and DMA acc mode. */
1525 		switch(target->space)
1526 		{
1527 			case B_CMAP8: max_acc_width = 8176; break;
1528 			case B_RGB15: max_acc_width = 4088; break;
1529 			case B_RGB16: max_acc_width = 4088; break;
1530 			case B_RGB24: max_acc_width = 2720; break;
1531 			case B_RGB32: max_acc_width = 2044; break;
1532 			default:
1533 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1534 				return B_ERROR;
1535 		}
1536 		break;
1537 	default:
1538 		/* confirmed for:
1539 		 * GeForce4 Ti4200 (NV28), GeForceFX 5600 (NV31) in PIO acc mode;
1540 		 * GeForce2 MX400 (NV11), GeForce4 MX440 (NV18), GeForceFX 5200 (NV34) can do
1541 		 * 16368/8184/8184/5456/4092, so a bit better in PIO acc mode;
1542 		 * confirmed for:
1543 		 * GeForce2 MX400 (NV11), GeForce4 MX440 (NV18), GeForcePCX 5750 (NV36),
1544 		 * GeForcePCX 6600 GT (NV43) in DMA acc mode;
1545 		 * GeForce4 Ti4200 (NV28), GeForceFX 5200 (NV34) can do
1546 		 * 16368/8184/8184/5456/4092, so a bit better in DMA acc mode. */
1547 		switch(target->space)
1548 		{
1549 			case B_CMAP8: max_acc_width = 16320; break;
1550 			case B_RGB15: max_acc_width =  8160; break;
1551 			case B_RGB16: max_acc_width =  8160; break;
1552 			case B_RGB24: max_acc_width =  5440; break;
1553 			case B_RGB32: max_acc_width =  4080; break;
1554 			default:
1555 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1556 				return B_ERROR;
1557 		}
1558 		break;
1559 	}
1560 
1561 	/* set virtual_width limit for unaccelerated modes */
1562 	switch (si->ps.card_type)
1563 	{
1564 	default:
1565 //	case NV04:
1566 		/* confirmed for:
1567 		 * TNT1 always;
1568 		 * TNT2, TNT2-M64, GeForce2 MX400, GeForce4 MX440, GeForce4 Ti4200,
1569 		 * GeForceFX 5200: if the CRTC1 (and CRTC2) BUFFER register b2 = 0 */
1570 		/* NOTE:
1571 		 * Unfortunately older cards have a hardware fault that prevents use.
1572 		 * We need doubled granularity on those to prevent the single top line
1573 		 * from shifting to the left!
1574 		 * This is confirmed for TNT2, GeForce2 MX200, GeForce2 MX400.
1575 		 * Confirmed OK are:
1576 		 * GeForce4 MX440, GeForce4 Ti4200, GeForceFX 5200. */
1577 		switch(target->space)
1578 		{
1579 			case B_CMAP8: max_crtc_width = 16368; break; /* 16376 */
1580 			case B_RGB15: max_crtc_width =  8184; break; /*  8188 */
1581 			case B_RGB16: max_crtc_width =  8184; break; /*  8188 */
1582 			case B_RGB24: max_crtc_width =  5456; break; /*  5456 */
1583 			case B_RGB32: max_crtc_width =  4092; break; /*  4094 */
1584 			default:
1585 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1586 				return B_ERROR;
1587 		}
1588 		break;
1589 //	default:
1590 		/* confirmed for:
1591 		 * TNT2, TNT2-M64, GeForce2 MX400, GeForce4 MX440, GeForce4 Ti4200,
1592 		 * GeForceFX 5200: if the CRTC1 (and CRTC2) BUFFER register b2 = 1 */
1593 /*		switch(target->space)
1594 		{
1595 			case B_CMAP8: max_crtc_width = 16352; break;
1596 			case B_RGB15: max_crtc_width =  8176; break;
1597 			case B_RGB16: max_crtc_width =  8176; break;
1598 			case B_RGB24: max_crtc_width =  5440; break;
1599 			case B_RGB32: max_crtc_width =  4088; break;
1600 			default:
1601 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1602 				return B_ERROR;
1603 		}
1604 		break;
1605 */	}
1606 
1607 	/* check for acc capability, and adjust mode to adhere to hardware constraints */
1608 	if (max_acc_width <= max_crtc_width)
1609 	{
1610 		/* check if we can setup this mode with acceleration */
1611 		*acc_mode = true;
1612 //temporary disabling ACC on NV47:
1613 if (si->ps.card_type == NV47) *acc_mode = false;
1614 		/* virtual_width */
1615 		if (target->virtual_width > max_acc_width) *acc_mode = false;
1616 		/* virtual_height */
1617 		/* (NV cards can even do more than this(?)...
1618 		 *  but 4096 is confirmed on all cards at max. accelerated width.) */
1619 		if (target->virtual_height > 4096) *acc_mode = false;
1620 
1621 		/* now check virtual_size based on CRTC constraints */
1622 		if (target->virtual_width > max_crtc_width) target->virtual_width = max_crtc_width;
1623 		/* virtual_height: The only constraint here is the cards memory size which is
1624 		 * checked later on in ProposeMode: virtual_height is adjusted then if needed.
1625 		 * 'Limiting here' to the variable size that's at least available (uint16). */
1626 		if (target->virtual_height > 65535) target->virtual_height = 65535;
1627 
1628 		/* OK, now we know that virtual_width is valid, and it's needing no slopspace if
1629 		 * it was confined above, so we can finally calculate safely if we need slopspace
1630 		 * for this mode... */
1631 		if (*acc_mode)
1632 		{
1633 			/* the mode needs to adhere to the largest granularity imposed... */
1634 			if (acc_mask < crtc_mask)
1635 				video_pitch = ((target->virtual_width + crtc_mask) & ~crtc_mask);
1636 			else
1637 				video_pitch = ((target->virtual_width + acc_mask) & ~acc_mask);
1638 		}
1639 		else /* unaccelerated mode */
1640 			video_pitch = ((target->virtual_width + crtc_mask) & ~crtc_mask);
1641 	}
1642 	else /* max_acc_width > max_crtc_width */
1643 	{
1644 		/* check if we can setup this mode with acceleration */
1645 		*acc_mode = true;
1646 //temporary disabling ACC on NV47:
1647 if (si->ps.card_type == NV47) *acc_mode = false;
1648 		/* (we already know virtual_width will be no problem) */
1649 		/* virtual_height */
1650 		/* (NV cards can even do more than this(?)...
1651 		 *  but 4096 is confirmed on all cards at max. accelerated width.) */
1652 		if (target->virtual_height > 4096) *acc_mode = false;
1653 
1654 		/* now check virtual_size based on CRTC constraints */
1655 		if (*acc_mode)
1656 		{
1657 			/* note that max_crtc_width already adheres to crtc_mask */
1658 			if (target->virtual_width > (max_crtc_width & ~acc_mask))
1659 					target->virtual_width = (max_crtc_width & ~acc_mask);
1660 		}
1661 		else /* unaccelerated mode */
1662 		{
1663 			if (target->virtual_width > max_crtc_width)
1664 					target->virtual_width = max_crtc_width;
1665 		}
1666 		/* virtual_height: The only constraint here is the cards memory size which is
1667 		 * checked later on in ProposeMode: virtual_height is adjusted then if needed.
1668 		 * 'Limiting here' to the variable size that's at least available (uint16). */
1669 		if (target->virtual_height > 65535) target->virtual_height = 65535;
1670 
1671 		/* OK, now we know that virtual_width is valid, and it's needing no slopspace if
1672 		 * it was confined above, so we can finally calculate safely if we need slopspace
1673 		 * for this mode... */
1674 		if (*acc_mode)
1675 		{
1676 			/* the mode needs to adhere to the largest granularity imposed... */
1677 			if (acc_mask < crtc_mask)
1678 				video_pitch = ((target->virtual_width + crtc_mask) & ~crtc_mask);
1679 			else
1680 				video_pitch = ((target->virtual_width + acc_mask) & ~acc_mask);
1681 		}
1682 		else /* unaccelerated mode */
1683 			video_pitch = ((target->virtual_width + crtc_mask) & ~crtc_mask);
1684 	}
1685 
1686 	LOG(2,("INIT: memory pitch will be set to %d pixels for colorspace 0x%08x\n",
1687 														video_pitch, target->space));
1688 	if (target->virtual_width != video_pitch)
1689 		LOG(2,("INIT: effective mode slopspace is %d pixels\n",
1690 											(video_pitch - target->virtual_width)));
1691 
1692 	/* now calculate bytes_per_row for this mode */
1693 	*bytes_per_row = video_pitch * (depth >> 3);
1694 
1695 	return B_OK;
1696 }
1697