xref: /haiku/src/add-ons/accelerants/nvidia/engine/nv_info.c (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
1 /* Read initialisation information from card */
2 /* some bits are hacks, where PINS is not known */
3 /* Author:
4    Rudolf Cornelissen 7/2003-5/2009
5 */
6 
7 #define MODULE_BIT 0x00002000
8 
9 #include "nv_std.h"
10 
11 /* pins V5.16 and up ROM infoblock stuff */
12 typedef struct {
13 	uint16	InitScriptTablePtr;		/* ptr to list of ptrs to scripts to exec */
14 	uint16	MacroIndexTablePtr;		/* ptr to list with indexes and sizes of items in MacroTable */
15 	uint16	MacroTablePtr;			/* ptr to list with items containing multiple 32bit reg writes */
16 	uint16	ConditionTablePtr;		/* ptr to list of PCI regs and bits to tst for exec mode */
17 	uint16	IOConditionTablePtr;	/* ptr to list of ISA regs and bits to tst for exec mode */
18 	uint16	IOFlagConditionTablePtr;/* ptr to list of ISA regs and bits to tst, ref'd to a matrix, for exec mode */
19 	uint16	InitFunctionTablePtr;	/* ptr to list of startadresses of fixed ROM init routines */
20 } PinsTables;
21 
22 static void detect_panels(void);
23 static void setup_output_matrix(void);
24 static void pinsnv4_fake(void);
25 static void pinsnv5_nv5m64_fake(void);
26 static void pinsnv6_fake(void);
27 static void pinsnv10_arch_fake(void);
28 static void pinsnv20_arch_fake(void);
29 static void pinsnv30_arch_fake(void);
30 static void getRAMsize_arch_nv4(void);
31 static void getstrap_arch_nv4(void);
32 static void getRAMsize_arch_nv10_20_30_40(void);
33 static void getstrap_arch_nv10_20_30_40(void);
34 static status_t pins2_read(uint8 *rom, uint32 offset);
35 static status_t pins3_5_read(uint8 *rom, uint32 offset);
36 static status_t coldstart_card(uint8* rom, uint16 init1, uint16 init2, uint16 init_size, uint16 ram_tab);
37 static status_t coldstart_card_516_up(uint8* rom, PinsTables tabs, uint16 ram_tab);
38 static status_t exec_type1_script(uint8* rom, uint16 adress, int16* size, uint16 ram_tab);
39 static status_t exec_type2_script(uint8* rom, uint16 adress, int16* size, PinsTables tabs, uint16 ram_tab);
40 static status_t exec_type2_script_mode(uint8* rom, uint16* adress, int16* size, PinsTables tabs, uint16 ram_tab, bool* exec);
41 static void	exec_cmd_39_type2(uint8* rom, uint32 data, PinsTables tabs, bool* exec);
42 static void log_pll(uint32 reg, uint32 freq);
43 static void	setup_ram_config(uint8* rom, uint16 ram_tab);
44 static void	setup_ram_config_nv10_up(uint8* rom);
45 static void	setup_ram_config_nv28(uint8* rom);
46 static status_t translate_ISA_PCI(uint32* reg);
47 static status_t	nv_crtc_setup_fifo(void);
48 
49 /* Parse the BIOS PINS structure if there */
50 status_t parse_pins ()
51 {
52 	uint8 *rom;
53 	uint8 chksum = 0;
54 	int i;
55 	uint32 offset;
56 	status_t result = B_ERROR;
57 
58 	/* preset PINS read status to failed */
59 	si->ps.pins_status = B_ERROR;
60 
61 	/* check the validity of PINS */
62 	LOG(2,("INFO: Reading PINS info\n"));
63 	rom = (uint8 *) si->rom_mirror;
64 	/* check BIOS signature - this is defined in the PCI standard */
65 	if (rom[0]!=0x55 || rom[1]!=0xaa)
66 	{
67 		LOG(8,("INFO: BIOS signature not found\n"));
68 		return B_ERROR;
69 	}
70 	LOG(2,("INFO: BIOS signature $AA55 found OK\n"));
71 
72 	/* find the PINS struct adress */
73 	for (offset = 0; offset < 65536; offset++)
74 	{
75 		if (rom[offset    ] != 0xff) continue;
76 		if (rom[offset + 1] != 0x7f) continue;
77 		if (rom[offset + 2] != 0x4e) continue; /* N */
78 		if (rom[offset + 3] != 0x56) continue; /* V */
79 		if (rom[offset + 4] != 0x00) continue;
80 
81 		LOG(8,("INFO: PINS signature found\n"));
82 		break;
83 	}
84 
85 	if (offset > 65535)
86 	{
87 		LOG(8,("INFO: PINS signature not found\n"));
88 		return B_ERROR;
89 	}
90 
91 	/* verify PINS checksum */
92 	for (i = 0; i < 8; i++)
93 	{
94 		chksum += rom[offset + i];
95 	}
96 	if (chksum)
97 	{
98 		LOG(8,("INFO: PINS checksum error\n"));
99 		return B_ERROR;
100 	}
101 
102 	/* checkout PINS struct version */
103 	LOG(2,("INFO: PINS checksum is OK; PINS version is %d.%d\n",
104 		rom[offset + 5], rom[offset + 6]));
105 
106 	/* update the si->ps struct as far as is possible and coldstart card */
107 	//fixme: NV40 and up(?) nolonger use this system...
108 	switch (rom[offset + 5])
109 	{
110 	case 2:
111 		result = pins2_read(rom, offset);
112 		break;
113 	case 3:
114 	case 4:
115 	case 5:
116 		result = pins3_5_read(rom, offset);
117 		break;
118 	default:
119 		LOG(8,("INFO: unknown PINS version\n"));
120 		return B_ERROR;
121 		break;
122 	}
123 
124 	/* check PINS read result */
125 	if (result == B_ERROR)
126 	{
127 		LOG(8,("INFO: PINS read/decode/execute error\n"));
128 		return B_ERROR;
129 	}
130 	/* PINS scan succeeded */
131 	si->ps.pins_status = B_OK;
132 	LOG(2,("INFO: PINS scan completed succesfully\n"));
133 	return B_OK;
134 }
135 
136 static status_t pins2_read(uint8 *rom, uint32 offset)
137 {
138 	uint16 init1 = rom[offset + 18] + (rom[offset + 19] * 256);
139 	uint16 init2 = rom[offset + 20] + (rom[offset + 21] * 256);
140 	uint16 init_size = rom[offset + 22] + (rom[offset + 23] * 256) + 1;
141 	/* confirmed by comparing cards */
142 	uint16 ram_tab = init1 - 0x0010;
143 	/* fixme: PPC BIOSes (might) return NULL pointers for messages here */
144 	char* signon_msg   = &(rom[(rom[offset + 24] + (rom[offset + 25] * 256))]);
145 	char* vendor_name  = &(rom[(rom[offset + 40] + (rom[offset + 41] * 256))]);
146 	char* product_name = &(rom[(rom[offset + 42] + (rom[offset + 43] * 256))]);
147 	char* product_rev  = &(rom[(rom[offset + 44] + (rom[offset + 45] * 256))]);
148 
149 	LOG(8,("INFO: cmdlist 1: $%04x, 2: $%04x, max. size $%04x\n", init1, init2, init_size));
150 	LOG(8,("INFO: signon msg:\n%s\n", signon_msg));
151 	LOG(8,("INFO: vendor name: %s\n", vendor_name));
152 	LOG(8,("INFO: product name: %s\n", product_name));
153 	LOG(8,("INFO: product rev: %s\n", product_rev));
154 
155 	return coldstart_card(rom, init1, init2, init_size, ram_tab);
156 }
157 
158 static status_t pins3_5_read(uint8 *rom, uint32 offset)
159 {
160 	uint16 init1 = rom[offset + 18] + (rom[offset + 19] * 256);
161 	uint16 init2 = rom[offset + 20] + (rom[offset + 21] * 256);
162 	uint16 init_size = rom[offset + 22] + (rom[offset + 23] * 256) + 1;
163 	/* confirmed on a TNT2-M64 with pins V5.1 */
164 	uint16 ram_tab = rom[offset + 24] + (rom[offset + 25] * 256);
165 	/* fixme: PPC BIOSes (might) return NULL pointers for messages here */
166 	char* signon_msg   = &(rom[(rom[offset + 30] + (rom[offset + 31] * 256))]);
167 	char* vendor_name  = &(rom[(rom[offset + 46] + (rom[offset + 47] * 256))]);
168 	char* product_name = &(rom[(rom[offset + 48] + (rom[offset + 49] * 256))]);
169 	char* product_rev  = &(rom[(rom[offset + 50] + (rom[offset + 51] * 256))]);
170 
171 	LOG(8,("INFO: pre PINS 5.16 cmdlist 1: $%04x, 2: $%04x, max. size $%04x\n", init1, init2, init_size));
172 	LOG(8,("INFO: signon msg:\n%s\n", signon_msg));
173 	LOG(8,("INFO: vendor name: %s\n", vendor_name));
174 	LOG(8,("INFO: product name: %s\n", product_name));
175 	LOG(8,("INFO: product rev: %s\n", product_rev));
176 
177 	/* pins 5.06 and higher has VCO range info */
178 	if (((rom[offset + 5]) == 5) && ((rom[offset + 6]) >= 0x06))
179 	{
180 		/* get PLL VCO range info */
181 		uint32 fvco_max = *((uint32*)(&(rom[offset + 67])));
182 		uint32 fvco_min = *((uint32*)(&(rom[offset + 71])));
183 
184 		LOG(8,("INFO: PLL VCO range is %dkHz - %dkHz\n", fvco_min, fvco_max));
185 
186 		/* modify presets to reflect card capability */
187 		si->ps.min_system_vco = fvco_min / 1000;
188 		si->ps.max_system_vco = fvco_max / 1000;
189 		//fixme: enable and modify PLL code...
190 		//si->ps.min_pixel_vco = fvco_min / 1000;
191 		//si->ps.max_pixel_vco = fvco_max / 1000;
192 		//si->ps.min_video_vco = fvco_min / 1000;
193 		//si->ps.max_video_vco = fvco_max / 1000;
194 	}
195 
196 	//fixme: add 'parsing scripts while not actually executing' as warmstart method,
197 	//       instead of not parsing at all: this will update the driver's speeds
198 	//       as below, while logging the scripts as well (for our learning pleasure :)
199 
200 	/* pins 5.16 and higher is more extensive, and works differently from before */
201 	if (((rom[offset + 5]) == 5) && ((rom[offset + 6]) >= 0x10))
202 	{
203 		/* pins 5.16 and up have a more extensive command list table, and have more
204 		 * commands to choose from as well. */
205 		PinsTables tabs;
206 		tabs.InitScriptTablePtr = rom[offset + 75] + (rom[offset + 76] * 256);
207 		tabs.MacroIndexTablePtr = rom[offset + 77] + (rom[offset + 78] * 256);
208 		tabs.MacroTablePtr = rom[offset + 79] + (rom[offset + 80] * 256);
209 		tabs.ConditionTablePtr = rom[offset + 81] + (rom[offset + 82] * 256);
210 		tabs.IOConditionTablePtr = rom[offset + 83] + (rom[offset + 84] * 256);
211 		tabs.IOFlagConditionTablePtr = rom[offset + 85] + (rom[offset + 86] * 256);
212 		tabs.InitFunctionTablePtr = rom[offset + 87] + (rom[offset + 88] * 256);
213 
214 		LOG(8,("INFO: PINS 5.16 and later cmdlist pointers:\n"));
215 		LOG(8,("INFO: InitScriptTablePtr: $%04x\n", tabs.InitScriptTablePtr));
216 		LOG(8,("INFO: MacroIndexTablePtr: $%04x\n", tabs.MacroIndexTablePtr));
217 		LOG(8,("INFO: MacroTablePtr: $%04x\n", tabs.MacroTablePtr));
218 		LOG(8,("INFO: ConditionTablePtr: $%04x\n", tabs.ConditionTablePtr));
219 		LOG(8,("INFO: IOConditionTablePtr: $%04x\n", tabs.IOConditionTablePtr));
220 		LOG(8,("INFO: IOFlagConditionTablePtr: $%04x\n", tabs.IOFlagConditionTablePtr));
221 		LOG(8,("INFO: InitFunctionTablePtr: $%04x\n", tabs.InitFunctionTablePtr));
222 
223 		return coldstart_card_516_up(rom, tabs, ram_tab);
224 	}
225 	else
226 	{
227 		/* pre 'pins 5.16' still uses the 'old' method in which the command list
228 		 * table always has two entries. */
229 		return coldstart_card(rom, init1, init2, init_size, ram_tab);
230 	}
231 }
232 
233 static status_t coldstart_card(uint8* rom, uint16 init1, uint16 init2, uint16 init_size, uint16 ram_tab)
234 {
235 	status_t result = B_OK;
236 	int16 size = init_size;
237 
238 	LOG(8,("INFO: now executing coldstart...\n"));
239 
240 	/* select colormode CRTC registers base adresses */
241 	NV_REG8(NV8_MISCW) = 0xcb;
242 
243 	/* unknown.. */
244 	NV_REG8(NV8_VSE2) = 0x01;
245 
246 	/* enable access to primary head */
247 	set_crtc_owner(0);
248 	/* unlock head's registers for R/W access */
249 	CRTCW(LOCK, 0x57);
250 	CRTCW(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
251 	/* disable RMA as it's not used */
252 	/* (RMA is the cmd register for the 32bit port in the GPU to access 32bit registers
253 	 *  and framebuffer via legacy ISA I/O space.) */
254 	CRTCW(RMA, 0x00);
255 
256 	if (si->ps.secondary_head)
257 	{
258 		/* enable access to secondary head */
259 		set_crtc_owner(1);
260 		/* unlock head's registers for R/W access */
261 		CRTC2W(LOCK, 0x57);
262 		CRTC2W(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
263 	}
264 
265 	/* turn off both displays and the hardcursors (also disables transfers) */
266 	nv_crtc_dpms(false, false, false, true);
267 	nv_crtc_cursor_hide();
268 	if (si->ps.secondary_head)
269 	{
270 		nv_crtc2_dpms(false, false, false, true);
271 		nv_crtc2_cursor_hide();
272 	}
273 
274 	/* execute BIOS coldstart script(s) */
275 	if (init1 || init2)
276 	{
277 		if (init1)
278 			if (exec_type1_script(rom, init1, &size, ram_tab) != B_OK) result = B_ERROR;
279 		if (init2 && (result == B_OK))
280 			if (exec_type1_script(rom, init2, &size, ram_tab) != B_OK) result = B_ERROR;
281 
282 		/* now enable ROM shadow or the card will remain shut-off! */
283 		CFGW(ROMSHADOW, (CFGR(ROMSHADOW) |= 0x00000001));
284 
285 		//temporary: should be called from setmode probably..
286 		nv_crtc_setup_fifo();
287 	}
288 	else
289 	{
290 		result = B_ERROR;
291 	}
292 
293 	if (result != B_OK)
294 		LOG(8,("INFO: coldstart failed.\n"));
295 	else
296 		LOG(8,("INFO: coldstart execution completed OK.\n"));
297 
298 	return result;
299 }
300 
301 static status_t coldstart_card_516_up(uint8* rom, PinsTables tabs, uint16 ram_tab)
302 {
303 	status_t result = B_OK;
304 	uint16 adress;
305 	uint32 fb_mrs1 = 0;
306 	uint32 fb_mrs2 = 0;
307 
308 	LOG(8,("INFO: now executing coldstart...\n"));
309 
310 	/* get some strapinfo(?) for NV28 framebuffer access */
311 	//fixme?: works on at least one NV28... how about other cards?
312 	if (si->ps.card_type == NV28)
313 	{
314 		fb_mrs2 = NV_REG32(NV32_FB_MRS2);
315 		fb_mrs1 = NV_REG32(NV32_FB_MRS1);
316 	}
317 
318 	/* select colormode CRTC registers base adresses */
319 	NV_REG8(NV8_MISCW) = 0xcb;
320 
321 	/* unknown.. */
322 	NV_REG8(NV8_VSE2) = 0x01;
323 
324 	/* enable access to primary head */
325 	set_crtc_owner(0);
326 	/* unlock head's registers for R/W access */
327 	CRTCW(LOCK, 0x57);
328 	CRTCW(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
329 	/* disable RMA as it's not used */
330 	/* (RMA is the cmd register for the 32bit port in the GPU to access 32bit registers
331 	 *  and framebuffer via legacy ISA I/O space.) */
332 	CRTCW(RMA, 0x00);
333 
334 	if (si->ps.secondary_head)
335 	{
336 		/* enable access to secondary head */
337 		set_crtc_owner(1);
338 		/* unlock head's registers for R/W access */
339 		CRTC2W(LOCK, 0x57);
340 		CRTC2W(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
341 	}
342 
343 	/* turn off both displays and the hardcursors (also disables transfers) */
344 	nv_crtc_dpms(false, false, false, true);
345 	nv_crtc_cursor_hide();
346 	if (si->ps.secondary_head)
347 	{
348 		nv_crtc2_dpms(false, false, false, true);
349 		nv_crtc2_cursor_hide();
350 	}
351 
352 	/* execute all BIOS coldstart script(s) */
353 	if (tabs.InitScriptTablePtr)
354 	{
355 		/* size is nolonger used, keeping it anyway for testing purposes :) */
356 		int16 size = 32767;
357 		uint16 index = tabs.InitScriptTablePtr;
358 
359 		adress = *((uint16*)(&(rom[index])));
360 		if (!adress)
361 		{
362 			LOG(8,("INFO: no cmdlist found!\n"));
363 			result = B_ERROR;
364 		}
365 
366 		while (adress && (result == B_OK))
367 		{
368 			result = exec_type2_script(rom, adress, &size, tabs, ram_tab);
369 			/* next command script, please */
370 			index += 2;
371 			adress = *((uint16*)(&(rom[index])));
372 		}
373 
374 		/* do some NV28 specific extra stuff */
375 		//fixme: NV28 only??
376 		if (si->ps.card_type == NV28)
377 		{
378 			/* setup PTIMER */
379 			ACCW(PT_NUMERATOR, (si->ps.std_engine_clock * 20));
380 			ACCW(PT_DENOMINATR, 0x00000271);
381 
382 			/* get NV28 RAM access up and running */
383 			//fixme?: works on at least one NV28... how about other cards?
384 			NV_REG32(NV32_FB_MRS2) = fb_mrs2;
385 			NV_REG32(NV32_FB_MRS1) = fb_mrs1;
386 		}
387 
388 		/* now enable ROM shadow or the card will remain shut-off! */
389 		CFGW(ROMSHADOW, (CFGR(ROMSHADOW) |= 0x00000001));
390 
391 		//temporary: should be called from setmode probably..
392 		nv_crtc_setup_fifo();
393 	}
394 	else
395 	{
396 		result = B_ERROR;
397 	}
398 
399 	if (result != B_OK)
400 		LOG(8,("INFO: coldstart failed.\n"));
401 	else
402 		LOG(8,("INFO: coldstart execution completed OK.\n"));
403 
404 	return result;
405 }
406 
407 /* This routine is complete, and is used for pre-NV10 cards. It's tested on a Elsa
408  * Erazor III with TNT2 (NV05) and on two no-name TNT2-M64's. All cards coldstart
409  * perfectly. */
410 static status_t exec_type1_script(uint8* rom, uint16 adress, int16* size, uint16 ram_tab)
411 {
412 	status_t result = B_OK;
413 	bool end = false;
414 	bool exec = true;
415 	uint8 index, byte;
416 	uint32 reg, data, data2, and_out, or_in;
417 
418 	LOG(8,("\nINFO: executing type1 script at adress $%04x...\n", adress));
419 	LOG(8,("INFO: ---Executing following command(s):\n"));
420 
421 	while (!end)
422 	{
423 		LOG(8,("INFO: $%04x ($%02x); ", adress, rom[adress]));
424 
425 		switch (rom[adress])
426 		{
427 		case 0x59:
428 			*size -= 7;
429 			if (*size < 0)
430 			{
431 				LOG(8,("script size error, aborting!\n\n"));
432 				end = true;
433 				result = B_ERROR;
434 				break;
435 			}
436 
437 			/* execute */
438 			adress += 1;
439 			reg = *((uint32*)(&(rom[adress])));
440 			adress += 4;
441 			data = *((uint16*)(&(rom[adress])));
442 			adress += 2;
443 			data2 = *((uint16*)(&(rom[data])));
444 			LOG(8,("cmd 'calculate indirect and set PLL 32bit reg $%08x for %.3fMHz'\n",
445 				reg, ((float)data2)));
446 			if (exec)
447 			{
448 				float calced_clk;
449 				uint8 m, n, p;
450 				nv_dac_sys_pll_find(((float)data2), &calced_clk, &m, &n, &p, 0);
451 				NV_REG32(reg) = ((p << 16) | (n << 8) | m);
452 			}
453 			log_pll(reg, data2);
454 			break;
455 		case 0x5a:
456 			*size -= 7;
457 			if (*size < 0)
458 			{
459 				LOG(8,("script size error, aborting!\n\n"));
460 				end = true;
461 				result = B_ERROR;
462 				break;
463 			}
464 
465 			/* execute */
466 			adress += 1;
467 			reg = *((uint32*)(&(rom[adress])));
468 			adress += 4;
469 			data = *((uint16*)(&(rom[adress])));
470 			adress += 2;
471 			data2 = *((uint32*)(&(rom[data])));
472 			LOG(8,("cmd 'WR indirect 32bit reg' $%08x = $%08x\n", reg, data2));
473 			if (exec) NV_REG32(reg) = data2;
474 			break;
475 		case 0x63:
476 			*size -= 1;
477 			if (*size < 0)
478 			{
479 				LOG(8,("script size error, aborting!\n\n"));
480 				end = true;
481 				result = B_ERROR;
482 				break;
483 			}
484 
485 			/* execute */
486 			adress += 1;
487 			LOG(8,("cmd 'setup RAM config' (always done)\n"));
488 			/* always done */
489 			setup_ram_config(rom, ram_tab);
490 			break;
491 		case 0x65:
492 			*size -= 13;
493 			if (*size < 0)
494 			{
495 				LOG(8,("script size error, aborting!\n\n"));
496 				end = true;
497 				result = B_ERROR;
498 				break;
499 			}
500 
501 			/* execute */
502 			adress += 1;
503 			reg = *((uint32*)(&(rom[adress])));
504 			adress += 4;
505 			data = *((uint32*)(&(rom[adress])));
506 			adress += 4;
507 			data2 = *((uint32*)(&(rom[adress])));
508 			adress += 4;
509 			LOG(8,("cmd 'WR 32bit reg $%08x = $%08x, then = $%08x' (always done)\n",
510 				reg, data, data2));
511 			/* always done */
512 			NV_REG32(reg) = data;
513 			NV_REG32(reg) = data2;
514 			CFGW(ROMSHADOW, (CFGR(ROMSHADOW) & 0xfffffffe));
515 			break;
516 		case 0x69:
517 			*size -= 5;
518 			if (*size < 0)
519 			{
520 				LOG(8,("script size error, aborting!\n\n"));
521 				end = true;
522 				result = B_ERROR;
523 				break;
524 			}
525 
526 			/* execute */
527 			adress += 1;
528 			reg = *((uint16*)(&(rom[adress])));
529 			adress += 2;
530 			and_out = *((uint8*)(&(rom[adress])));
531 			adress += 1;
532 			or_in = *((uint8*)(&(rom[adress])));
533 			adress += 1;
534 			LOG(8,("cmd 'RD 8bit ISA reg $%04x, AND-out = $%02x, OR-in = $%02x, WR-bk'\n",
535 				reg, and_out, or_in));
536 			if (exec)
537 			{
538 				translate_ISA_PCI(&reg);
539 				byte = NV_REG8(reg);
540 				byte &= (uint8)and_out;
541 				byte |= (uint8)or_in;
542 				NV_REG8(reg) = byte;
543 			}
544 			break;
545 		case 0x6d:
546 			*size -= 3;
547 			if (*size < 0)
548 			{
549 				LOG(8,("script size error, aborting!\n\n"));
550 				end = true;
551 				result = B_ERROR;
552 				break;
553 			}
554 
555 			/* execute */
556 			adress += 1;
557 			data = NV_REG32(NV32_NV4STRAPINFO);
558 			and_out = *((uint8*)(&(rom[adress])));
559 			adress += 1;
560 			byte = *((uint8*)(&(rom[adress])));
561 			adress += 1;
562 			data &= (uint32)and_out;
563 			LOG(8,("cmd 'CHK bits AND-out $%02x RAMCFG for $%02x'\n",
564 				and_out, byte));
565 			if (((uint8)data) != byte)
566 			{
567 				LOG(8,("INFO: ---No match: not executing following command(s):\n"));
568 				exec = false;
569 			}
570 			else
571 			{
572 				LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));
573 			}
574 			break;
575 		case 0x6e:
576 			*size -= 13;
577 			if (*size < 0)
578 			{
579 				LOG(8,("script size error, aborting!\n\n"));
580 				end = true;
581 				result = B_ERROR;
582 				break;
583 			}
584 
585 			/* execute */
586 			adress += 1;
587 			reg = *((uint32*)(&(rom[adress])));
588 			adress += 4;
589 			and_out = *((uint32*)(&(rom[adress])));
590 			adress += 4;
591 			or_in = *((uint32*)(&(rom[adress])));
592 			adress += 4;
593 			LOG(8,("cmd 'RD 32bit reg $%08x, AND-out = $%08x, OR-in = $%08x, WR-bk'\n",
594 				reg, and_out, or_in));
595 			if (exec)
596 			{
597 				data = NV_REG32(reg);
598 				data &= and_out;
599 				data |= or_in;
600 				NV_REG32(reg) = data;
601 			}
602 			break;
603 		case 0x71:
604 			LOG(8,("cmd 'END', execution completed.\n\n"));
605 			end = true;
606 
607 			*size -= 1;
608 			if (*size < 0)
609 			{
610 				LOG(8,("script size error!\n\n"));
611 				result = B_ERROR;
612 			}
613 			break;
614 		case 0x72:
615 			*size -= 1;
616 			if (*size < 0)
617 			{
618 				LOG(8,("script size error!\n\n"));
619 				result = B_ERROR;
620 			}
621 
622 			/* execute */
623 			adress += 1;
624 			LOG(8,("cmd 'PGM commands'\n"));
625 			LOG(8,("INFO: ---Executing following command(s):\n"));
626 			exec = true;
627 			break;
628 		case 0x73:
629 			*size -= 9;
630 			if (*size < 0)
631 			{
632 				LOG(8,("script size error, aborting!\n\n"));
633 				end = true;
634 				result = B_ERROR;
635 				break;
636 			}
637 
638 			/* execute */
639 			adress += 1;
640 			data = NV_REG32(NV32_NVSTRAPINFO2);
641 			and_out = *((uint32*)(&(rom[adress])));
642 			adress += 4;
643 			data2 = *((uint32*)(&(rom[adress])));
644 			adress += 4;
645 			data &= and_out;
646 			LOG(8,("cmd 'CHK bits AND-out $%08x STRAPCFG2 for $%08x'\n",
647 				and_out, data2));
648 			if (data != data2)
649 			{
650 				LOG(8,("INFO: ---No match: not executing following command(s):\n"));
651 				exec = false;
652 			}
653 			else
654 			{
655 				LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));
656 			}
657 			break;
658 		case 0x74:
659 			*size -= 3;
660 			if (*size < 0)
661 			{
662 				LOG(8,("script size error, aborting!\n\n"));
663 				end = true;
664 				result = B_ERROR;
665 				break;
666 			}
667 
668 			/* execute */
669 			adress += 1;
670 			data = *((uint16*)(&(rom[adress])));
671 			adress += 2;
672 			LOG(8,("cmd 'SNOOZE for %d ($%04x) microSeconds' (always done)\n", data, data));
673 			/* always done */
674 			snooze(data);
675 			break;
676 		case 0x77:
677 			*size -= 7;
678 			if (*size < 0)
679 			{
680 				LOG(8,("script size error, aborting!\n\n"));
681 				end = true;
682 				result = B_ERROR;
683 				break;
684 			}
685 
686 			/* execute */
687 			adress += 1;
688 			reg = *((uint32*)(&(rom[adress])));
689 			adress += 4;
690 			data = *((uint16*)(&(rom[adress])));
691 			adress += 2;
692 			LOG(8,("cmd 'WR 32bit reg' $%08x = $%08x (b31-16 = '0', b15-0 = data)\n",
693 				reg, data));
694 			if (exec) NV_REG32(reg) = data;
695 			break;
696 		case 0x78:
697 			*size -= 6;
698 			if (*size < 0)
699 			{
700 				LOG(8,("script size error, aborting!\n\n"));
701 				end = true;
702 				result = B_ERROR;
703 				break;
704 			}
705 
706 			/* execute */
707 			adress += 1;
708 			reg = *((uint16*)(&(rom[adress])));
709 			adress += 2;
710 			index = *((uint8*)(&(rom[adress])));
711 			adress += 1;
712 			and_out = *((uint8*)(&(rom[adress])));
713 			adress += 1;
714 			or_in = *((uint8*)(&(rom[adress])));
715 			adress += 1;
716 			LOG(8,("cmd 'RD idx ISA reg $%02x via $%04x, AND-out = $%02x, OR-in = $%02x, WR-bk'\n",
717 				index, reg, and_out, or_in));
718 			if (exec)
719 			{
720 				translate_ISA_PCI(&reg);
721 				NV_REG8(reg) = index;
722 				byte = NV_REG8(reg + 1);
723 				byte &= (uint8)and_out;
724 				byte |= (uint8)or_in;
725 				NV_REG8(reg + 1) = byte;
726 			}
727 			break;
728 		case 0x79:
729 			*size -= 7;
730 			if (*size < 0)
731 			{
732 				LOG(8,("script size error, aborting!\n\n"));
733 				end = true;
734 				result = B_ERROR;
735 				break;
736 			}
737 
738 			/* execute */
739 			adress += 1;
740 			reg = *((uint32*)(&(rom[adress])));
741 			adress += 4;
742 			data = *((uint16*)(&(rom[adress])));
743 			adress += 2;
744 			LOG(8,("cmd 'calculate and set PLL 32bit reg $%08x for %.3fMHz'\n", reg, (data / 100.0)));
745 			if (exec)
746 			{
747 				float calced_clk;
748 				uint8 m, n, p;
749 				nv_dac_sys_pll_find((data / 100.0), &calced_clk, &m, &n, &p, 0);
750 				NV_REG32(reg) = ((p << 16) | (n << 8) | m);
751 			}
752 			log_pll(reg, (data / 100));
753 			break;
754 		case 0x7a:
755 			*size -= 9;
756 			if (*size < 0)
757 			{
758 				LOG(8,("script size error, aborting!\n\n"));
759 				end = true;
760 				result = B_ERROR;
761 				break;
762 			}
763 
764 			/* execute */
765 			adress += 1;
766 			reg = *((uint32*)(&(rom[adress])));
767 			adress += 4;
768 			data = *((uint32*)(&(rom[adress])));
769 			adress += 4;
770 			LOG(8,("cmd 'WR 32bit reg' $%08x = $%08x\n", reg, data));
771 			if (exec) NV_REG32(reg) = data;
772 			break;
773 		default:
774 			LOG(8,("unknown cmd, aborting!\n\n"));
775 			end = true;
776 			result = B_ERROR;
777 			break;
778 		}
779 	}
780 
781 	return result;
782 }
783 
784 static void log_pll(uint32 reg, uint32 freq)
785 {
786 	if ((si->ps.card_type == NV31) || (si->ps.card_type == NV36))
787 		LOG(8,("INFO: ---WARNING: check/update PLL programming script code!!!\n"));
788 	switch (reg)
789 	{
790 	case NV32_MEMPLL:
791 		LOG(8,("INFO: ---Memory PLL accessed.\n"));
792 		/* update the card's specs */
793 		si->ps.std_memory_clock = freq;
794 		break;
795 	case NV32_COREPLL:
796 		LOG(8,("INFO: ---Core PLL accessed.\n"));
797 		/* update the card's specs */
798 		si->ps.std_engine_clock = freq;
799 		break;
800 	case NVDAC_PIXPLLC:
801 		LOG(8,("INFO: ---DAC1 PLL accessed.\n"));
802 		break;
803 	case NVDAC2_PIXPLLC:
804 		LOG(8,("INFO: ---DAC2 PLL accessed.\n"));
805 		break;
806 	/* unexpected cases, here for learning goals... */
807 	case NV32_MEMPLL2:
808 		LOG(8,("INFO: ---NV31/NV36 extension to memory PLL accessed only!\n"));
809 		break;
810 	case NV32_COREPLL2:
811 		LOG(8,("INFO: ---NV31/NV36 extension to core PLL accessed only!\n"));
812 		break;
813 	case NVDAC_PIXPLLC2:
814 		LOG(8,("INFO: ---NV31/NV36 extension to DAC1 PLL accessed only!\n"));
815 		break;
816 	case NVDAC2_PIXPLLC2:
817 		LOG(8,("INFO: ---NV31/NV36 extension to DAC2 PLL accessed only!\n"));
818 		break;
819 	default:
820 		LOG(8,("INFO: ---Unknown PLL accessed!\n"));
821 		break;
822 	}
823 }
824 
825 static void	setup_ram_config(uint8* rom, uint16 ram_tab)
826 {
827 	uint32 ram_cfg, data;
828 	uint8 cnt;
829 
830 	/* set MRS = 256 */
831 	NV_REG32(NV32_PFB_DEBUG_0) &= 0xffffffef;
832 	/* read RAM config hardware(?) strap */
833 	ram_cfg = ((NV_REG32(NV32_NVSTRAPINFO2) >> 2) & 0x0000000f);
834 	LOG(8,("INFO: ---RAM config strap is $%01x\n", ram_cfg));
835 	/* use it as a pointer in a BIOS table for prerecorded RAM configurations */
836 	ram_cfg = *((uint16*)(&(rom[(ram_tab + (ram_cfg * 2))])));
837 	/* log info */
838 	switch (ram_cfg & 0x00000003)
839 	{
840 	case 0:
841 		LOG(8,("INFO: ---32Mb RAM should be connected\n"));
842 		break;
843 	case 1:
844 		LOG(8,("INFO: ---4Mb RAM should be connected\n"));
845 		break;
846 	case 2:
847 		LOG(8,("INFO: ---8Mb RAM should be connected\n"));
848 		break;
849 	case 3:
850 		LOG(8,("INFO: ---16Mb RAM should be connected\n"));
851 		break;
852 	}
853 	if (ram_cfg & 0x00000004)
854 		LOG(8,("INFO: ---RAM should be 128bits wide\n"));
855 	else
856 		LOG(8,("INFO: ---RAM should be 64bits wide\n"));
857 	switch ((ram_cfg & 0x00000038) >> 3)
858 	{
859 	case 0:
860 		LOG(8,("INFO: ---RAM type: 8Mbit SGRAM\n"));
861 		break;
862 	case 1:
863 		LOG(8,("INFO: ---RAM type: 16Mbit SGRAM\n"));
864 		break;
865 	case 2:
866 		LOG(8,("INFO: ---RAM type: 4 banks of 16Mbit SGRAM\n"));
867 		break;
868 	case 3:
869 		LOG(8,("INFO: ---RAM type: 16Mbit SDRAM\n"));
870 		break;
871 	case 4:
872 		LOG(8,("INFO: ---RAM type: 64Mbit SDRAM\n"));
873 		break;
874 	case 5:
875 		LOG(8,("INFO: ---RAM type: 64Mbit x16 SDRAM\n"));
876 		break;
877 	}
878 	/* set RAM amount, width and type */
879 	data = (NV_REG32(NV32_NV4STRAPINFO) & 0xffffffc0);
880 	NV_REG32(NV32_NV4STRAPINFO) = (data | (ram_cfg & 0x0000003f));
881 	/* setup write to read delay (?) */
882 	data = (NV_REG32(NV32_PFB_CONFIG_1) & 0xff8ffffe);
883 	data |= ((ram_cfg & 0x00000700) << 12);
884 	/* force update via b0 = 0... */
885 	NV_REG32(NV32_PFB_CONFIG_1) = data;
886 	/* ... followed by b0 = 1(?) */
887 	NV_REG32(NV32_PFB_CONFIG_1) = (data | 0x00000001);
888 
889 	/* do RAM width test to confirm RAM width set to be correct */
890 	/* write testpattern to first 128 bits of graphics memory... */
891 	data = 0x4e563541;
892 	for (cnt = 0; cnt < 4; cnt++)
893 		((volatile uint32 *)si->framebuffer)[cnt] = data;
894 	/* ... if second 64 bits does not contain the testpattern we are apparantly
895 	 * set to 128bits width while we should be set to 64bits width, so correct. */
896 	if (((volatile uint32 *)si->framebuffer)[3] != data)
897 	{
898 		LOG(8,("INFO: ---RAM width tested: width is 64bits, correcting settings.\n"));
899 		NV_REG32(NV32_NV4STRAPINFO) &= ~0x00000004;
900 	}
901 	else
902 	{
903 		LOG(8,("INFO: ---RAM width tested: access is OK.\n"));
904 	}
905 
906 	/* do RAM size test to confirm RAM size set to be correct */
907 	ram_cfg = (NV_REG32(NV32_NV4STRAPINFO) & 0x00000003);
908 	data = 0x4e563542;
909 	/* first check for 32Mb... */
910 	if (!ram_cfg)
911 	{
912 		/* write testpattern to just above the 16Mb boundary */
913 		((volatile uint32 *)si->framebuffer)[(16 * 1024 * 1024) >> 2] = data;
914 		/* check if pattern reads back */
915 		if (((volatile uint32 *)si->framebuffer)[(16 * 1024 * 1024) >> 2] == data)
916 		{
917 			/* write second testpattern to base adress */
918 			data = 0x4135564e;
919 			((volatile uint32 *)si->framebuffer)[0] = data;
920 			if (((volatile uint32 *)si->framebuffer)[0] == data)
921 			{
922 				LOG(8,("INFO: ---RAM size tested: size was set OK (32Mb).\n"));
923 				return;
924 			}
925 		}
926 		/* one of the two tests for 32Mb failed, we must have 16Mb */
927 		ram_cfg = 0x00000003;
928 		LOG(8,("INFO: ---RAM size tested: size is 16Mb, correcting settings.\n"));
929 		NV_REG32(NV32_NV4STRAPINFO) =
930 			 (((NV_REG32(NV32_NV4STRAPINFO)) & 0xfffffffc) | ram_cfg);
931 		return;
932 	}
933 	/* ... now check for 16Mb... */
934 	if (ram_cfg == 0x00000003)
935 	{
936 		/* increment testpattern */
937 		data++;
938 		/* write testpattern to just above the 8Mb boundary */
939 		((volatile uint32 *)si->framebuffer)[(8 * 1024 * 1024) >> 2] = data;
940 		/* check if pattern reads back */
941 		if (((volatile uint32 *)si->framebuffer)[(8 * 1024 * 1024) >> 2] == data)
942 		{
943 			LOG(8,("INFO: ---RAM size tested: size was set OK (16Mb).\n"));
944 			return;
945 		}
946 		else
947 		{
948 			/* assuming 8Mb: retesting below! */
949 			ram_cfg = 0x00000002;
950 			LOG(8,("INFO: ---RAM size tested: size is NOT 16Mb, testing for 8Mb...\n"));
951 			NV_REG32(NV32_NV4STRAPINFO) =
952 				 (((NV_REG32(NV32_NV4STRAPINFO)) & 0xfffffffc) | ram_cfg);
953 		}
954 	}
955 	/* ... and now check for 8Mb! (ram_cfg will be 'pre'set to 4Mb or 8Mb here) */
956 	{
957 		/* increment testpattern (again) */
958 		data++;
959 		/* write testpattern to just above the 4Mb boundary */
960 		((volatile uint32 *)si->framebuffer)[(4 * 1024 * 1024) >> 2] = data;
961 		/* check if pattern reads back */
962 		if (((volatile uint32 *)si->framebuffer)[(4 * 1024 * 1024) >> 2] == data)
963 		{
964 			/* we have 8Mb, make sure this is set. */
965 			ram_cfg = 0x00000002;
966 			LOG(8,("INFO: ---RAM size tested: size is 8Mb, setting 8Mb.\n"));
967 			/* fixme? assuming this should be done here! */
968 			NV_REG32(NV32_NV4STRAPINFO) =
969 				 (((NV_REG32(NV32_NV4STRAPINFO)) & 0xfffffffc) | ram_cfg);
970 			return;
971 		}
972 		else
973 		{
974 			/* we must have 4Mb, make sure this is set. */
975 			ram_cfg = 0x00000001;
976 			LOG(8,("INFO: ---RAM size tested: size is 4Mb, setting 4Mb.\n"));
977 			NV_REG32(NV32_NV4STRAPINFO) =
978 				 (((NV_REG32(NV32_NV4STRAPINFO)) & 0xfffffffc) | ram_cfg);
979 			return;
980 		}
981 	}
982 }
983 
984 /* this routine is used for NV10 and later */
985 static status_t exec_type2_script(uint8* rom, uint16 adress, int16* size, PinsTables tabs, uint16 ram_tab)
986 {
987 	bool exec = true;
988 
989 	LOG(8,("\nINFO: executing type2 script at adress $%04x...\n", adress));
990 	LOG(8,("INFO: ---Executing following command(s):\n"));
991 
992 	return exec_type2_script_mode(rom, &adress, size, tabs, ram_tab, &exec);
993 }
994 
995 /* this routine is used for NV10 and later. It's tested on a GeForce2 MX400 (NV11),
996  * GeForce4 MX440 (NV18), GeForce4 Ti4200 (NV28) and a GeForceFX 5200 (NV34).
997  * These cards coldstart perfectly. */
998 static status_t exec_type2_script_mode(uint8* rom, uint16* adress, int16* size, PinsTables tabs, uint16 ram_tab, bool* exec)
999 {
1000 	status_t result = B_OK;
1001 	bool end = false;
1002 	uint8 index, byte, byte2, shift;
1003 	uint32 reg, reg2, data, data2, and_out, and_out2, or_in, or_in2, safe32, offset32, size32;
1004 
1005 	while (!end)
1006 	{
1007 		LOG(8,("INFO: $%04x ($%02x); ", *adress, rom[*adress]));
1008 
1009 		/* all commands are here (verified NV11 and NV28) */
1010 		switch (rom[*adress])
1011 		{
1012 		case 0x31: /* new */
1013 			*size -= (15 + ((*((uint8*)(&(rom[(*adress + 10)])))) << 2));
1014 			if (*size < 0)
1015 			{
1016 				LOG(8,("script size error, aborting!\n\n"));
1017 				end = true;
1018 				result = B_ERROR;
1019 				break;
1020 			}
1021 
1022 			/* execute */
1023 			*adress += 1;
1024 			reg = *((uint32*)(&(rom[*adress])));
1025 			*adress += 4;
1026 			and_out = *((uint32*)(&(rom[*adress])));
1027 			*adress += 4;
1028 			shift = *((uint8*)(&(rom[*adress])));
1029 			*adress += 1;
1030 			size32 = ((*((uint8*)(&(rom[*adress])))) << 2);
1031 			*adress += 1;
1032 			reg2 = *((uint32*)(&(rom[*adress])));
1033 			*adress += 4;
1034 			LOG(8,("cmd 'RD 32bit reg $%08x, AND-out = $%08x, shift-right = $%02x,\n",
1035 				reg, and_out, shift));
1036 			LOG(8,("INFO: (cont.) RD 32bit data from subtable with size $%04x, at offset (result << 2),\n",
1037 				size32));
1038 			LOG(8,("INFO: (cont.) then WR result data to 32bit reg $%08x'\n", reg2));
1039 			if (*exec && reg2)
1040 			{
1041 				data = NV_REG32(reg);
1042 				data &= and_out;
1043 				data >>= shift;
1044 				data2 = *((uint32*)(&(rom[(*adress + (data << 2))])));
1045 				NV_REG32(reg2) = data2;
1046 			}
1047 			*adress += size32;
1048 			break;
1049 		case 0x32: /* new */
1050 			*size -= (11 + ((*((uint8*)(&(rom[(*adress + 6)])))) << 2));
1051 			if (*size < 0)
1052 			{
1053 				LOG(8,("script size error, aborting!\n\n"));
1054 				end = true;
1055 				result = B_ERROR;
1056 				break;
1057 			}
1058 
1059 			/* execute */
1060 			*adress += 1;
1061 			reg = *((uint16*)(&(rom[*adress])));
1062 			*adress += 2;
1063 			index = *((uint8*)(&(rom[*adress])));
1064 			*adress += 1;
1065 			and_out = *((uint8*)(&(rom[*adress])));
1066 			*adress += 1;
1067 			byte2 = *((uint8*)(&(rom[*adress])));
1068 			*adress += 1;
1069 			size32 = ((*((uint8*)(&(rom[*adress])))) << 2);
1070 			*adress += 1;
1071 			reg2 = *((uint32*)(&(rom[*adress])));
1072 			*adress += 4;
1073 			LOG(8,("cmd 'RD idx ISA reg $%02x via $%04x, AND-out = $%02x, shift-right = $%02x,\n",
1074 				index, reg, and_out, byte2));
1075 			LOG(8,("INFO: (cont.) RD 32bit data from subtable with size $%04x, at offset (result << 2),\n",
1076 				size32));
1077 			LOG(8,("INFO: (cont.) then WR result data to 32bit reg $%08x'\n", reg2));
1078 			if (*exec && reg2)
1079 			{
1080 				translate_ISA_PCI(&reg);
1081 				NV_REG8(reg) = index;
1082 				byte = NV_REG8(reg + 1);
1083 				byte &= (uint8)and_out;
1084 				byte >>= byte2;
1085 				offset32 = (byte << 2);
1086 				data = *((uint32*)(&(rom[(*adress + offset32)])));
1087 				NV_REG32(reg2) = data;
1088 			}
1089 			*adress += size32;
1090 			break;
1091 		case 0x33: /* new */
1092 			*size -= 2;
1093 			if (*size < 0)
1094 			{
1095 				LOG(8,("script size error, aborting!\n\n"));
1096 				end = true;
1097 				result = B_ERROR;
1098 				break;
1099 			}
1100 
1101 			/* execute */
1102 			*adress += 1;
1103 			size32 = *((uint8*)(&(rom[*adress])));
1104 			*adress += 1;
1105 			/* executed 1-256 times */
1106 			if (!size32) size32 = 256;
1107 			/* remember where to start each time */
1108 			safe32 = *adress;
1109 			LOG(8,("cmd 'execute following part of this script $%03x times' (always done)\n", size32));
1110 			for (offset32 = 0; offset32 < size32; offset32++)
1111 			{
1112 				LOG(8,("\nINFO: (#$%02x) executing part of type2 script at adress $%04x...\n",
1113 					offset32, *adress));
1114 				LOG(8,("INFO: ---Not touching 'execution' mode at this time:\n"));
1115 				*adress = safe32;
1116 				result = exec_type2_script_mode(rom, adress, size, tabs, ram_tab, exec);
1117 			}
1118 			LOG(8,("INFO: ---Continuing script:\n"));
1119 			break;
1120 		case 0x34: /* new */
1121 			*size -= (12 + ((*((uint8*)(&(rom[(*adress + 7)])))) << 1));
1122 			if (*size < 0)
1123 			{
1124 				LOG(8,("script size error, aborting!\n\n"));
1125 				end = true;
1126 				result = B_ERROR;
1127 				break;
1128 			}
1129 
1130 			/* execute */
1131 			*adress += 1;
1132 			reg = *((uint16*)(&(rom[*adress])));
1133 			*adress += 2;
1134 			index = *((uint8*)(&(rom[*adress])));
1135 			*adress += 1;
1136 			and_out = *((uint8*)(&(rom[*adress])));
1137 			*adress += 1;
1138 			shift = *((uint8*)(&(rom[*adress])));
1139 			*adress += 1;
1140 			offset32 = *((uint8*)(&(rom[*adress])));
1141 			*adress += 1;
1142 			size32 = ((*((uint8*)(&(rom[*adress])))) << 1);
1143 			*adress += 1;
1144 			reg2 = *((uint32*)(&(rom[*adress])));
1145 			*adress += 4;
1146 			LOG(8,("cmd 'RD idx ISA reg $%02x via $%04x, AND-out = $%02x, shift-right = $%02x,\n",
1147 				index, reg, and_out, shift));
1148 			LOG(8,("INFO: (cont.) RD 16bit PLL frequency to pgm from subtable with size $%04x, at offset (result << 1),\n",
1149 				size32));
1150 			LOG(8,("INFO: (cont.) RD table-index ($%02x) for cmd $39'\n",
1151 				offset32));
1152 			translate_ISA_PCI(&reg);
1153 			NV_REG8(reg) = index;
1154 			byte = NV_REG8(reg + 1);
1155 			byte &= (uint8)and_out;
1156 			data = (byte >> shift);
1157 			data <<= 1;
1158 			data2 = *((uint16*)(&(rom[(*adress + data)])));
1159 			if (offset32 < 0x80)
1160 			{
1161 				bool double_f = true;
1162 				LOG(8,("INFO: Do subcmd ($39); "));
1163 				exec_cmd_39_type2(rom, offset32, tabs, &double_f);
1164 				LOG(8,("INFO: (cont. cmd $34) Doubling PLL frequency to be set for cmd $34.\n"));
1165 				if (double_f) data2 <<= 1;
1166 				LOG(8,("INFO: ---Reverting to pre-subcmd ($39) 'execution' mode.\n"));
1167 			}
1168 			else
1169 			{
1170 				LOG(8,("INFO: table index is negative, not executing subcmd ($39).\n"));
1171 			}
1172 			LOG(8,("INFO: (cont.) 'calc and set PLL 32bit reg $%08x for %.3fMHz'\n",
1173 				reg2, (data2 / 100.0)));
1174 			if (*exec && reg2)
1175 			{
1176 				float calced_clk;
1177 				uint8 m, n, p;
1178 				nv_dac_sys_pll_find((data2 / 100.0), &calced_clk, &m, &n, &p, 0);
1179 				/* programming the PLL needs to be done in steps! (confirmed NV28) */
1180 				data = NV_REG32(reg2);
1181 				NV_REG32(reg2) = ((data & 0xffff0000) | (n << 8) | m);
1182 				data = NV_REG32(reg2);
1183 				NV_REG32(reg2) = ((p << 16) | (n << 8) | m);
1184 //fixme?
1185 				/* program 2nd set N and M scalers if they exist (b31=1 enables them) */
1186 //				if ((si->ps.card_type == NV31) || (si->ps.card_type == NV36))
1187 //					DACW(PIXPLLC2, 0x80000401);
1188 			}
1189 			log_pll(reg2, (data2 / 100));
1190 			*adress += size32;
1191 			break;
1192 		case 0x35: /* new */
1193 			*size -= 2;
1194 			if (*size < 0)
1195 			{
1196 				LOG(8,("script size error, aborting!\n\n"));
1197 				end = true;
1198 				result = B_ERROR;
1199 				break;
1200 			}
1201 
1202 			/* execute */
1203 			*adress += 1;
1204 			byte = *((uint8*)(&(rom[*adress])));
1205  			*adress += 1;
1206 			offset32 = (byte << 1);
1207 			offset32 += tabs.InitFunctionTablePtr;
1208 			LOG(8,("cmd 'execute fixed VGA BIOS routine #$%02x at adress $%04x'\n",
1209 				byte, offset32));
1210 			/* note:
1211 			 * This command is BIOS/'pins' version specific. Confirmed a NV28 having NO
1212 			 * entries at all in InitFunctionTable!
1213 			 * (BIOS version 4.28.20.05.11; 'pins' version 5.21) */
1214 			//fixme: impl. if it turns out this cmd is used.. (didn't see that yet)
1215 			if (*exec)
1216 			{
1217 				//fixme: add BIOS/'pins' version dependancy...
1218 				switch(byte)
1219 				{
1220 				default:
1221 					LOG(8,("\n\nINFO: WARNING: function not implemented, skipping!\n\n"));
1222 					break;
1223 				}
1224 			}
1225 			break;
1226 		case 0x37: /* new */
1227 			*size -= 11;
1228 			if (*size < 0)
1229 			{
1230 				LOG(8,("script size error, aborting!\n\n"));
1231 				end = true;
1232 				result = B_ERROR;
1233 				break;
1234 			}
1235 
1236 			/* execute */
1237 			*adress += 1;
1238 			reg = *((uint32*)(&(rom[*adress])));
1239 			*adress += 4;
1240 			byte2 = *((uint8*)(&(rom[*adress])));
1241 			*adress += 1;
1242 			and_out = *((uint8*)(&(rom[*adress])));
1243 			*adress += 1;
1244 			reg2 = *((uint16*)(&(rom[*adress])));
1245 			*adress += 2;
1246 			index = *((uint8*)(&(rom[*adress])));
1247 			*adress += 1;
1248 			and_out2 = *((uint8*)(&(rom[*adress])));
1249 			*adress += 1;
1250 			LOG(8,("cmd 'RD 32bit reg $%08x, shift-right = $%02x, AND-out lsb = $%02x,\n",
1251 				reg, byte2, and_out));
1252 			LOG(8,("INFO: (cont.) RD 8bit ISA reg $%02x via $%04x, AND-out = $%02x, OR-in lsb result 32bit, WR-bk'\n",
1253 				index, reg2, and_out2));
1254 			if (*exec)
1255 			{
1256 				data = NV_REG32(reg);
1257 				if (byte2 < 0x80)
1258 				{
1259 					data >>= byte2;
1260 				}
1261 				else
1262 				{
1263 					data <<= (0x0100 - byte2);
1264 				}
1265 				data &= and_out;
1266 				translate_ISA_PCI(&reg2);
1267 				NV_REG8(reg2) = index;
1268 				byte = NV_REG8(reg2 + 1);
1269 				byte &= (uint8)and_out2;
1270 				byte |= (uint8)data;
1271 				NV_REG8(reg2 + 1) = byte;
1272 			}
1273 			break;
1274 		case 0x38: /* new */
1275 			*size -= 1;
1276 			if (*size < 0)
1277 			{
1278 				LOG(8,("script size error, aborting!\n\n"));
1279 				end = true;
1280 				result = B_ERROR;
1281 				break;
1282 			}
1283 
1284 			/* execute */
1285 			*adress += 1;
1286 			LOG(8,("cmd 'invert current mode'\n"));
1287 			*exec = !(*exec);
1288 			if (*exec)
1289 				LOG(8,("INFO: ---Executing following command(s):\n"));
1290 			else
1291 				LOG(8,("INFO: ---Not executing following command(s):\n"));
1292 			break;
1293 		case 0x39: /* new */
1294 			*size -= 2;
1295 			if (*size < 0)
1296 			{
1297 				LOG(8,("script size error, aborting!\n\n"));
1298 				end = true;
1299 				result = B_ERROR;
1300 				break;
1301 			}
1302 
1303 			/* execute */
1304 			*adress += 1;
1305 			data = *((uint8*)(&(rom[*adress])));
1306 			*adress += 1;
1307 			exec_cmd_39_type2(rom, data, tabs, exec);
1308 			break;
1309 		case 0x49: /* new */
1310 			size32 = *((uint8*)(&(rom[*adress + 17])));
1311 			if (!size32) size32 = 256;
1312 			*size -= (18 + (size32 << 1));
1313 			if (*size < 0)
1314 			{
1315 				LOG(8,("script size error, aborting!\n\n"));
1316 				end = true;
1317 				result = B_ERROR;
1318 				break;
1319 			}
1320 
1321 			/* execute */
1322 			*adress += 1;
1323 			reg = *((uint32*)(&(rom[*adress])));
1324 			*adress += 4;
1325 			reg2 = *((uint32*)(&(rom[*adress])));
1326 			*adress += 4;
1327 			and_out = *((uint32*)(&(rom[*adress])));
1328 			*adress += 4;
1329 			or_in = *((uint32*)(&(rom[*adress])));
1330 			*adress += 4;
1331 			size32 = *((uint8*)(&(rom[*adress])));
1332 			if (!size32) size32 = 256;
1333 			*adress += 1;
1334 			LOG(8,("cmd 'do following cmd structure $%03x time(s)':\n", size32));
1335 			for (offset32 = 0; offset32 < size32; offset32++)
1336 			{
1337 				or_in2 = *((uint8*)(&(rom[(*adress + (offset32 << 1))])));
1338 				data2 = *((uint8*)(&(rom[(*adress + (offset32 << 1) + 1)])));
1339 				LOG(8,("INFO (cont.) (#$%02x) cmd 'WR 32bit reg $%08x = $%08x, RD 32bit reg $%08x,\n",
1340 					offset32, reg2, data2, reg));
1341 				LOG(8,("INFO (cont.) AND-out $%08x, OR-in $%08x, OR-in $%08x, WR-bk'\n",
1342 					and_out, or_in, or_in2));
1343 			}
1344 			if (*exec)
1345 			{
1346 				for (index = 0; index < size32; index++)
1347 				{
1348 					or_in2 = *((uint8*)(&(rom[*adress])));
1349 					*adress += 1;
1350 					data2 = *((uint8*)(&(rom[*adress])));
1351 					*adress += 1;
1352 					NV_REG32(reg2) = data2;
1353 					data = NV_REG32(reg);
1354 					data &= and_out;
1355 					data |= or_in;
1356 					data |= or_in2;
1357 					NV_REG32(reg) = data;
1358 				}
1359 			}
1360 			else
1361 			{
1362 				*adress += (size32 << 1);
1363 			}
1364 			break;
1365 		case 0x61: /* new */
1366 			*size -= 4;
1367 			if (*size < 0)
1368 			{
1369 				LOG(8,("script size error, aborting!\n\n"));
1370 				end = true;
1371 				result = B_ERROR;
1372 				break;
1373 			}
1374 
1375 			/* execute */
1376 			*adress += 1;
1377 			reg = *((uint16*)(&(rom[*adress])));
1378 			*adress += 2;
1379 			byte = *((uint8*)(&(rom[*adress])));
1380 			*adress += 1;
1381 			LOG(8,("cmd 'WR ISA reg $%04x = $%02x'\n", reg, byte));
1382 			if (*exec)
1383 			{
1384 				translate_ISA_PCI(&reg);
1385 				NV_REG8(reg) = byte;
1386 			}
1387 			break;
1388 		case 0x62: /* new */
1389 			*size -= 5;
1390 			if (*size < 0)
1391 			{
1392 				LOG(8,("script size error, aborting!\n\n"));
1393 				end = true;
1394 				result = B_ERROR;
1395 				break;
1396 			}
1397 
1398 			/* execute */
1399 			*adress += 1;
1400 			reg = *((uint16*)(&(rom[*adress])));
1401 			*adress += 2;
1402 			index = *((uint8*)(&(rom[*adress])));
1403 			*adress += 1;
1404 			byte = *((uint8*)(&(rom[*adress])));
1405 			*adress += 1;
1406 			LOG(8,("cmd 'WR idx ISA reg $%02x via $%04x = $%02x'\n", index, reg, byte));
1407 			if (*exec)
1408 			{
1409 				translate_ISA_PCI(&reg);
1410 				NV_REG16(reg) = ((((uint16)byte) << 8) | index);
1411 			}
1412 			break;
1413 		case 0x63: /* new setup compared to pre-NV10 version */
1414 			*size -= 1;
1415 			if (*size < 0)
1416 			{
1417 				LOG(8,("script size error, aborting!\n\n"));
1418 				end = true;
1419 				result = B_ERROR;
1420 				break;
1421 			}
1422 
1423 			/* execute */
1424 			*adress += 1;
1425 			LOG(8,("cmd 'setup RAM config' (always done)\n"));
1426 			/* always done */
1427 			switch (si->ps.card_type)
1428 			{
1429 			case NV28:
1430 				setup_ram_config_nv28(rom);
1431 				break;
1432 			default:
1433 				setup_ram_config_nv10_up(rom);
1434 				break;
1435 			}
1436 			break;
1437 		case 0x65: /* identical to type1 */
1438 			*size -= 13;
1439 			if (*size < 0)
1440 			{
1441 				LOG(8,("script size error, aborting!\n\n"));
1442 				end = true;
1443 				result = B_ERROR;
1444 				break;
1445 			}
1446 
1447 			/* execute */
1448 			*adress += 1;
1449 			reg = *((uint32*)(&(rom[*adress])));
1450 			*adress += 4;
1451 			data = *((uint32*)(&(rom[*adress])));
1452 			*adress += 4;
1453 			data2 = *((uint32*)(&(rom[*adress])));
1454 			*adress += 4;
1455 			LOG(8,("cmd 'WR 32bit reg $%08x = $%08x, then = $%08x' (always done)\n",
1456 				reg, data, data2));
1457 			/* always done */
1458 			NV_REG32(reg) = data;
1459 			NV_REG32(reg) = data2;
1460 			CFGW(ROMSHADOW, (CFGR(ROMSHADOW) & 0xfffffffe));
1461 			break;
1462 		case 0x69: /* identical to type1 */
1463 			*size -= 5;
1464 			if (*size < 0)
1465 			{
1466 				LOG(8,("script size error, aborting!\n\n"));
1467 				end = true;
1468 				result = B_ERROR;
1469 				break;
1470 			}
1471 
1472 			/* execute */
1473 			*adress += 1;
1474 			reg = *((uint16*)(&(rom[*adress])));
1475 			*adress += 2;
1476 			and_out = *((uint8*)(&(rom[*adress])));
1477 			*adress += 1;
1478 			or_in = *((uint8*)(&(rom[*adress])));
1479 			*adress += 1;
1480 			LOG(8,("cmd 'RD 8bit ISA reg $%04x, AND-out = $%02x, OR-in = $%02x, WR-bk'\n",
1481 				reg, and_out, or_in));
1482 			if (*exec)
1483 			{
1484 				translate_ISA_PCI(&reg);
1485 				byte = NV_REG8(reg);
1486 				byte &= (uint8)and_out;
1487 				byte |= (uint8)or_in;
1488 				NV_REG8(reg) = byte;
1489 			}
1490 			break;
1491 		case 0x6a: /* new */
1492 			*size -= 2;
1493 			if (*size < 0)
1494 			{
1495 				LOG(8,("script size error, aborting!\n\n"));
1496 				end = true;
1497 				result = B_ERROR;
1498 				break;
1499 			}
1500 
1501 			/* execute */
1502 			*adress += 1;
1503 			data = *((uint8*)(&(rom[*adress])));
1504 			*adress += 1;
1505 			data2 = *((uint16*)(&(rom[(tabs.InitScriptTablePtr + (data << 1))])));
1506 			LOG(8,("cmd 'jump to script #$%02x at adress $%04x'\n", data, data2));
1507 			if (*exec)
1508 			{
1509 				*adress = data2;
1510 				LOG(8,("INFO: ---Jumping; not touching 'execution' mode.\n"));
1511 			}
1512 			break;
1513 		case 0x6b: /* new */
1514 			*size -= 2;
1515 			if (*size < 0)
1516 			{
1517 				LOG(8,("script size error, aborting!\n\n"));
1518 				end = true;
1519 				result = B_ERROR;
1520 				break;
1521 			}
1522 
1523 			/* execute */
1524 			*adress += 1;
1525 			data = *((uint8*)(&(rom[*adress])));
1526 			*adress += 1;
1527 			data2 = *((uint16*)(&(rom[(tabs.InitScriptTablePtr + (data << 1))])));
1528 			LOG(8,("cmd 'gosub script #$%02x at adress $%04x'\n", data, data2));
1529 			if (*exec && data2)
1530 			{
1531 				result = exec_type2_script(rom, data2, size, tabs, ram_tab);
1532 				LOG(8,("INFO: ---Reverting to pre-gosub 'execution' mode.\n"));
1533 			}
1534 			break;
1535 		case 0x6e: /* identical to type1 */
1536 			*size -= 13;
1537 			if (*size < 0)
1538 			{
1539 				LOG(8,("script size error, aborting!\n\n"));
1540 				end = true;
1541 				result = B_ERROR;
1542 				break;
1543 			}
1544 
1545 			/* execute */
1546 			*adress += 1;
1547 			reg = *((uint32*)(&(rom[*adress])));
1548 			*adress += 4;
1549 			and_out = *((uint32*)(&(rom[*adress])));
1550 			*adress += 4;
1551 			or_in = *((uint32*)(&(rom[*adress])));
1552 			*adress += 4;
1553 			LOG(8,("cmd 'RD 32bit reg $%08x, AND-out = $%08x, OR-in = $%08x, WR-bk'\n",
1554 				reg, and_out, or_in));
1555 			if (*exec)
1556 			{
1557 				data = NV_REG32(reg);
1558 				data &= and_out;
1559 				data |= or_in;
1560 				NV_REG32(reg) = data;
1561 			}
1562 			break;
1563 		case 0x6f: /* new */
1564 			*size -= 2;
1565 			if (*size < 0)
1566 			{
1567 				LOG(8,("script size error, aborting!\n\n"));
1568 				end = true;
1569 				result = B_ERROR;
1570 				break;
1571 			}
1572 
1573 			/* execute */
1574 			*adress += 1;
1575 			byte = *((uint8*)(&(rom[*adress])));
1576 			*adress += 1;
1577 			data = tabs.MacroIndexTablePtr + (byte << 1);
1578 			offset32 = (*((uint8*)(&(rom[data]))) << 3);
1579 			size32 = *((uint8*)(&(rom[(data + 1)])));
1580 			offset32 += tabs.MacroTablePtr;
1581 			/* note: min 1, max 255 commands can be requested */
1582 			LOG(8,("cmd 'do $%02x time(s) a 32bit reg WR with 32bit data' (MacroIndexTable idx = $%02x):\n",
1583 				size32, byte));
1584 			safe32 = 0;
1585 			while (safe32 < size32)
1586 			{
1587 				reg2 = *((uint32*)(&(rom[(offset32 + (safe32 << 3))])));
1588 				data2 = *((uint32*)(&(rom[(offset32 + (safe32 << 3) + 4)])));
1589 				LOG(8,("INFO: (cont.) (#$%02x) cmd 'WR 32bit reg' $%08x = $%08x\n",
1590 					safe32, reg2, data2));
1591 				safe32++;
1592  			}
1593 			if (*exec)
1594 			{
1595 				safe32 = 0;
1596 				while (safe32 < size32)
1597 				{
1598 					reg2 = *((uint32*)(&(rom[(offset32 + (safe32 << 3))])));
1599 					data2 = *((uint32*)(&(rom[(offset32 + (safe32 << 3) + 4)])));
1600 					NV_REG32(reg2) = data2;
1601 					safe32++;
1602 				}
1603 			}
1604 			break;
1605 		case 0x36: /* new */
1606 		case 0x66: /* new */
1607 		case 0x67: /* new */
1608 		case 0x68: /* new */
1609 		case 0x6c: /* new */
1610 		case 0x71: /* identical to type1 */
1611 			LOG(8,("cmd 'END', execution completed.\n\n"));
1612 			end = true;
1613 
1614 			*size -= 1;
1615 			if (*size < 0)
1616 			{
1617 				LOG(8,("script size error!\n\n"));
1618 				result = B_ERROR;
1619 			}
1620 
1621 			/* execute */
1622 			*adress += 1; /* needed to make cmd #$33 work correctly! */
1623 			break;
1624 		case 0x72: /* identical to type1 */
1625 			*size -= 1;
1626 			if (*size < 0)
1627 			{
1628 				LOG(8,("script size error!\n\n"));
1629 				result = B_ERROR;
1630 			}
1631 
1632 			/* execute */
1633 			*adress += 1;
1634 			LOG(8,("cmd 'PGM commands'\n"));
1635 			LOG(8,("INFO: ---Executing following command(s):\n"));
1636 			*exec = true;
1637 			break;
1638 		case 0x74: /* identical to type1 */
1639 			//fixme? on at least NV28 this cmd hammers the CRTC PCI-timeout register
1640 			//'data' number of times instead of snoozing.
1641 			//Couldn't see any diff in behaviour though!
1642 			*size -= 3;
1643 			if (*size < 0)
1644 			{
1645 				LOG(8,("script size error, aborting!\n\n"));
1646 				end = true;
1647 				result = B_ERROR;
1648 				break;
1649 			}
1650 
1651 			/* execute */
1652 			*adress += 1;
1653 			data = *((uint16*)(&(rom[*adress])));
1654 			*adress += 2;
1655 			LOG(8,("cmd 'SNOOZE for %d ($%04x) microSeconds' (always done)\n", data, data));
1656 			/* always done */
1657 			snooze(data);
1658 			break;
1659 		case 0x75: /* new */
1660 			*size -= 2;
1661 			if (*size < 0)
1662 			{
1663 				LOG(8,("script size error!\n\n"));
1664 				result = B_ERROR;
1665 			}
1666 
1667 			/* execute */
1668 			*adress += 1;
1669 			data = *((uint8*)(&(rom[*adress])));
1670 			*adress += 1;
1671 			data *= 12;
1672 			data += tabs.ConditionTablePtr;
1673 			reg = *((uint32*)(&(rom[data])));
1674 			and_out = *((uint32*)(&(rom[(data + 4)])));
1675 			data2 = *((uint32*)(&(rom[(data + 8)])));
1676 			data = NV_REG32(reg);
1677 			data &= and_out;
1678 			LOG(8,("cmd 'CHK bits AND-out $%08x reg $%08x for $%08x'\n",
1679 				and_out, reg, data2));
1680 			if (data != data2)
1681 			{
1682 				LOG(8,("INFO: ---No match: not executing following command(s):\n"));
1683 				*exec = false;
1684 			}
1685 			else
1686 			{
1687 				LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));
1688 			}
1689 			break;
1690 		case 0x76: /* new */
1691 			*size -= 2;
1692 			if (*size < 0)
1693 			{
1694 				LOG(8,("script size error!\n\n"));
1695 				result = B_ERROR;
1696 			}
1697 
1698 			/* execute */
1699 			*adress += 1;
1700 			data = *((uint8*)(&(rom[*adress])));
1701 			*adress += 1;
1702 			data *= 5;
1703 			data += tabs.IOConditionTablePtr;
1704 			reg = *((uint16*)(&(rom[data])));
1705 			index = *((uint8*)(&(rom[(data + 2)])));
1706 			and_out = *((uint8*)(&(rom[(data + 3)])));
1707 			byte2 = *((uint8*)(&(rom[(data + 4)])));
1708 			LOG(8,("cmd 'CHK bits AND-out $%02x idx ISA reg $%02x via $%04x for $%02x'\n",
1709 				and_out, index, reg, byte2));
1710 			translate_ISA_PCI(&reg);
1711 			NV_REG8(reg) = index;
1712 			byte = NV_REG8(reg + 1);
1713 			byte &= (uint8)and_out;
1714 			if (byte != byte2)
1715 			{
1716 				LOG(8,("INFO: ---No match: not executing following command(s):\n"));
1717 				*exec = false;
1718 			}
1719 			else
1720 			{
1721 				LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));
1722 			}
1723 			break;
1724 		case 0x78: /* identical to type1 */
1725 			*size -= 6;
1726 			if (*size < 0)
1727 			{
1728 				LOG(8,("script size error, aborting!\n\n"));
1729 				end = true;
1730 				result = B_ERROR;
1731 				break;
1732 			}
1733 
1734 			/* execute */
1735 			*adress += 1;
1736 			reg = *((uint16*)(&(rom[*adress])));
1737 			*adress += 2;
1738 			index = *((uint8*)(&(rom[*adress])));
1739 			*adress += 1;
1740 			and_out = *((uint8*)(&(rom[*adress])));
1741 			*adress += 1;
1742 			or_in = *((uint8*)(&(rom[*adress])));
1743 			*adress += 1;
1744 			LOG(8,("cmd 'RD idx ISA reg $%02x via $%04x, AND-out = $%02x, OR-in = $%02x, WR-bk'\n",
1745 				index, reg, and_out, or_in));
1746 			if (*exec)
1747 			{
1748 				translate_ISA_PCI(&reg);
1749 				NV_REG8(reg) = index;
1750 				byte = NV_REG8(reg + 1);
1751 				byte &= (uint8)and_out;
1752 				byte |= (uint8)or_in;
1753 				NV_REG8(reg + 1) = byte;
1754 			}
1755 			break;
1756 		case 0x79:
1757 			*size -= 7;
1758 			if (*size < 0)
1759 			{
1760 				LOG(8,("script size error, aborting!\n\n"));
1761 				end = true;
1762 				result = B_ERROR;
1763 				break;
1764 			}
1765 
1766 			/* execute */
1767 			*adress += 1;
1768 			reg = *((uint32*)(&(rom[*adress])));
1769 			*adress += 4;
1770 			data = *((uint16*)(&(rom[*adress])));
1771 			*adress += 2;
1772 			LOG(8,("cmd 'calculate and set PLL 32bit reg $%08x for %.3fMHz'\n", reg, (data / 100.0)));
1773 			if (*exec)
1774 			{
1775 				float calced_clk;
1776 				uint8 m, n, p;
1777 				nv_dac_sys_pll_find((data / 100.0), &calced_clk, &m, &n, &p, 0);
1778 				/* programming the PLL needs to be done in steps! (confirmed NV28) */
1779 				data2 = NV_REG32(reg);
1780 				NV_REG32(reg) = ((data2 & 0xffff0000) | (n << 8) | m);
1781 				data2 = NV_REG32(reg);
1782 				NV_REG32(reg) = ((p << 16) | (n << 8) | m);
1783 //fixme?
1784 				/* program 2nd set N and M scalers if they exist (b31=1 enables them) */
1785 //				if ((si->ps.card_type == NV31) || (si->ps.card_type == NV36))
1786 //					DACW(PIXPLLC2, 0x80000401);
1787 			}
1788 			log_pll(reg, (data / 100));
1789 			break;
1790 		case 0x7a: /* identical to type1 */
1791 			*size -= 9;
1792 			if (*size < 0)
1793 			{
1794 				LOG(8,("script size error, aborting!\n\n"));
1795 				end = true;
1796 				result = B_ERROR;
1797 				break;
1798 			}
1799 
1800 			/* execute */
1801 			*adress += 1;
1802 			reg = *((uint32*)(&(rom[*adress])));
1803 			*adress += 4;
1804 			data = *((uint32*)(&(rom[*adress])));
1805 			*adress += 4;
1806 			LOG(8,("cmd 'WR 32bit reg' $%08x = $%08x\n", reg, data));
1807 			if (*exec) NV_REG32(reg) = data;
1808 			break;
1809 		default:
1810 			LOG(8,("unknown cmd, aborting!\n\n"));
1811 			end = true;
1812 			result = B_ERROR;
1813 			break;
1814 		}
1815 	}
1816 
1817 	return result;
1818 }
1819 
1820 static void	exec_cmd_39_type2(uint8* rom, uint32 data, PinsTables tabs, bool* exec)
1821 {
1822 	uint8 index, byte, byte2, safe, shift;
1823 	uint32 reg, and_out, and_out2, offset32;
1824 
1825 	data *= 9;
1826 	data += tabs.IOFlagConditionTablePtr;
1827 	reg = *((uint16*)(&(rom[data])));
1828 	index = *((uint8*)(&(rom[(data + 2)])));
1829 	and_out = *((uint8*)(&(rom[(data + 3)])));
1830 	shift = *((uint8*)(&(rom[(data + 4)])));
1831 	offset32 = *((uint16*)(&(rom[data + 5])));
1832 	and_out2 = *((uint8*)(&(rom[(data + 7)])));
1833 	byte2 = *((uint8*)(&(rom[(data + 8)])));
1834 	LOG(8,("cmd 'AND-out bits $%02x idx ISA reg $%02x via $%04x, shift-right = $%02x,\n",
1835 		and_out, index, reg, shift));
1836 	translate_ISA_PCI(&reg);
1837 	NV_REG8(reg) = index;
1838 	byte = NV_REG8(reg + 1);
1839 	byte &= (uint8)and_out;
1840 	offset32 += (byte >> shift);
1841 	safe = byte = *((uint8*)(&(rom[offset32])));
1842 	byte &= (uint8)and_out2;
1843 	LOG(8,("INFO: (cont.) use result as index in table to get data $%02x,\n",
1844 		safe));
1845 	LOG(8,("INFO: (cont.) then chk bits AND-out $%02x of data for $%02x'\n",
1846 		and_out2, byte2));
1847 	if (byte != byte2)
1848 	{
1849 		LOG(8,("INFO: ---No match: not executing following command(s):\n"));
1850 		*exec = false;
1851 	}
1852 	else
1853 	{
1854 		LOG(8,("INFO: ---Match, so this cmd has no effect.\n"));
1855 	}
1856 }
1857 
1858 static void	setup_ram_config_nv10_up(uint8* rom)
1859 {
1860 	/* note:
1861 	 * After writing data to RAM a snooze is required to make the test work.
1862 	 * Confirmed a NV11: without snooze it worked OK on a low-voltage AGP2.0 slot,
1863 	 * but on a higher-voltage AGP 1.0 slot it failed to identify errors correctly!!
1864 	 * Adding the snooze fixed that. */
1865 
1866 	uint32 data, dummy;
1867 	uint8 cnt = 0;
1868 	status_t stat = B_ERROR;
1869 
1870 	/* set 'refctrl is valid' */
1871 	NV_REG32(NV32_PFB_REFCTRL) = 0x80000000;
1872 
1873 	/* check RAM for 256bits buswidth(?) */
1874 	while ((cnt < 4) && (stat != B_OK))
1875 	{
1876 		/* reset RAM bits at offset 224-255 bits four times */
1877 		((volatile uint32 *)si->framebuffer)[0x07] = 0x00000000;
1878 		snooze(10);
1879 		((volatile uint32 *)si->framebuffer)[0x07] = 0x00000000;
1880 		snooze(10);
1881 		((volatile uint32 *)si->framebuffer)[0x07] = 0x00000000;
1882 		snooze(10);
1883 		((volatile uint32 *)si->framebuffer)[0x07] = 0x00000000;
1884 		snooze(10);
1885 		/* write testpattern */
1886 		((volatile uint32 *)si->framebuffer)[0x07] = 0x4e563131;
1887 		snooze(10);
1888 		/* reset RAM bits at offset 480-511 bits */
1889 		((volatile uint32 *)si->framebuffer)[0x0f] = 0x00000000;
1890 		snooze(10);
1891 		/* check testpattern to have survived */
1892 		if (((volatile uint32 *)si->framebuffer)[0x07] == 0x4e563131) stat = B_OK;
1893 		cnt++;
1894 	}
1895 
1896 	/* if pattern did not hold modify RAM-type setup */
1897 	if (stat != B_OK)
1898 	{
1899 		LOG(8,("INFO: ---RAM test #1 done: access errors, modified setup.\n"));
1900 		data = NV_REG32(NV32_PFB_CONFIG_0);
1901 		if (data & 0x00000010)
1902 		{
1903 			data &= 0xffffffcf;
1904 		}
1905 		else
1906 		{
1907 			data &= 0xffffffcf;
1908 			data |= 0x00000020;
1909 		}
1910 		NV_REG32(NV32_PFB_CONFIG_0) = data;
1911 	}
1912 	else
1913 	{
1914 		LOG(8,("INFO: ---RAM test #1 done: access is OK.\n"));
1915 	}
1916 
1917 	/* check RAM bankswitching stuff(?) */
1918 	cnt = 0;
1919 	stat = B_ERROR;
1920 	while ((cnt < 4) && (stat != B_OK))
1921 	{
1922 		/* read RAM size */
1923 		data = NV_REG32(NV32_NV10STRAPINFO);
1924 		/* subtract 1MB */
1925 		data -= 0x00100000;
1926 		/* write testpattern at generated RAM adress */
1927 		((volatile uint32 *)si->framebuffer)[(data >> 2)] = 0x4e564441;
1928 		snooze(10);
1929 		/* reset first RAM adress */
1930 		((volatile uint32 *)si->framebuffer)[0x00] = 0x00000000;
1931 		snooze(10);
1932 		/* dummyread first RAM adress four times */
1933 		dummy = ((volatile uint32 *)si->framebuffer)[0x00];
1934 		dummy = ((volatile uint32 *)si->framebuffer)[0x00];
1935 		dummy = ((volatile uint32 *)si->framebuffer)[0x00];
1936 		dummy = ((volatile uint32 *)si->framebuffer)[0x00];
1937 		/* check testpattern to have survived */
1938 		if (((volatile uint32 *)si->framebuffer)[(data >> 2)] == 0x4e564441) stat = B_OK;
1939 		cnt++;
1940 	}
1941 
1942 	/* if pattern did not hold modify RAM-type setup */
1943 	if (stat != B_OK)
1944 	{
1945 		LOG(8,("INFO: ---RAM test #2 done: access errors, modified setup.\n"));
1946 		NV_REG32(NV32_PFB_CONFIG_0) &= 0xffffefff;
1947 	}
1948 	else
1949 	{
1950 		LOG(8,("INFO: ---RAM test #2 done: access is OK.\n"));
1951 	}
1952 }
1953 
1954 /* Note: this routine assumes at least 128Mb was mapped to memory (kerneldriver).
1955  * It doesn't matter if the card actually _has_ this amount of RAM or not(!) */
1956 static void	setup_ram_config_nv28(uint8* rom)
1957 {
1958 	/* note:
1959 	 * After writing data to RAM a snooze is required to make the test work.
1960 	 * Confirmed a NV11: without snooze it worked OK on a low-voltage AGP2.0 slot,
1961 	 * but on a higher-voltage AGP 1.0 slot it failed to identify errors correctly!!
1962 	 * Adding the snooze fixed that. */
1963 
1964 	uint32 dummy;
1965 	uint8 cnt = 0;
1966 	status_t stat = B_ERROR;
1967 
1968 	/* set 'refctrl is valid' */
1969 	NV_REG32(NV32_PFB_REFCTRL) = 0x80000000;
1970 
1971 	/* check RAM */
1972 	while ((cnt < 4) && (stat != B_OK))
1973 	{
1974 		/* set bit 11: 'pulse' something into a new setting? */
1975 		NV_REG32(NV32_PFB_CONFIG_0) |= 0x00000800;
1976 		/* write testpattern to RAM adress 127Mb */
1977 		((volatile uint32 *)si->framebuffer)[0x01fc0000] = 0x4e564441;
1978 		snooze(10);
1979 		/* reset first RAM adress */
1980 		((volatile uint32 *)si->framebuffer)[0x00000000] = 0x00000000;
1981 		snooze(10);
1982 		/* dummyread first RAM adress four times */
1983 		dummy = ((volatile uint32 *)si->framebuffer)[0x00000000];
1984 		LOG(8,("INFO: (#%d) dummy1 = $%08x, ", cnt, dummy));
1985 		dummy = ((volatile uint32 *)si->framebuffer)[0x00000000];
1986 		LOG(8,("dummy2 = $%08x, ", dummy));
1987 		dummy = ((volatile uint32 *)si->framebuffer)[0x00000000];
1988 		LOG(8,("dummy3 = $%08x, ", dummy));
1989 		dummy = ((volatile uint32 *)si->framebuffer)[0x00000000];
1990 		LOG(8,("dummy4 = $%08x\n", dummy));
1991 		/* check testpattern to have survived */
1992 		if (((volatile uint32 *)si->framebuffer)[0x01fc0000] == 0x4e564441) stat = B_OK;
1993 		cnt++;
1994 	}
1995 
1996 	/* clear bit 11: set normal mode */
1997 	NV_REG32(NV32_PFB_CONFIG_0) &= ~0x00000800;
1998 
1999 	if (stat == B_OK)
2000 		LOG(8,("INFO: ---RAM test done: access was OK within %d iteration(s).\n", cnt));
2001 	else
2002 		LOG(8,("INFO: ---RAM test done: access was still not OK after 4 iterations.\n"));
2003 }
2004 
2005 static status_t translate_ISA_PCI(uint32* reg)
2006 {
2007 	switch (*reg)
2008 	{
2009 	case 0x03c0:
2010 		*reg = NV8_ATTRDATW;
2011 		break;
2012 	case 0x03c1:
2013 		*reg = NV8_ATTRDATR;
2014 		break;
2015 	case 0x03c2:
2016 		*reg = NV8_MISCW;
2017 		break;
2018 	case 0x03c4:
2019 		*reg = NV8_SEQIND;
2020 		break;
2021 	case 0x03c5:
2022 		*reg = NV8_SEQDAT;
2023 		break;
2024 	case 0x03c6:
2025 		*reg = NV8_PALMASK;
2026 		break;
2027 	case 0x03c7:
2028 		*reg = NV8_PALINDR;
2029 		break;
2030 	case 0x03c8:
2031 		*reg = NV8_PALINDW;
2032 		break;
2033 	case 0x03c9:
2034 		*reg = NV8_PALDATA;
2035 		break;
2036 	case 0x03cc:
2037 		*reg = NV8_MISCR;
2038 		break;
2039 	case 0x03ce:
2040 		*reg = NV8_GRPHIND;
2041 		break;
2042 	case 0x03cf:
2043 		*reg = NV8_GRPHDAT;
2044 		break;
2045 	case 0x03d4:
2046 		*reg = NV8_CRTCIND;
2047 		break;
2048 	case 0x03d5:
2049 		*reg = NV8_CRTCDAT;
2050 		break;
2051 	case 0x03da:
2052 		*reg = NV8_INSTAT1;
2053 		break;
2054 	default:
2055 		LOG(8,("\n\nINFO: WARNING: ISA->PCI register adress translation failed!\n\n"));
2056 		return B_ERROR;
2057 		break;
2058 	}
2059 
2060 	return B_OK;
2061 }
2062 
2063 void set_pll(uint32 reg, uint32 req_clk)
2064 {
2065 	uint32 data;
2066 	float calced_clk;
2067 	uint8 m, n, p;
2068 	nv_dac_sys_pll_find(req_clk, &calced_clk, &m, &n, &p, 0);
2069 	/* programming the PLL needs to be done in steps! (confirmed NV28) */
2070 	data = NV_REG32(reg);
2071 	NV_REG32(reg) = ((data & 0xffff0000) | (n << 8) | m);
2072 	data = NV_REG32(reg);
2073 	NV_REG32(reg) = ((p << 16) | (n << 8) | m);
2074 
2075 //fixme?
2076 	/* program 2nd set N and M scalers if they exist (b31=1 enables them) */
2077 	if (si->ps.ext_pll)
2078 	{
2079 		if (reg == NV32_COREPLL) NV_REG32(NV32_COREPLL2) = 0x80000401;
2080 		if (reg == NV32_MEMPLL) NV_REG32(NV32_MEMPLL2) = 0x80000401;
2081 	}
2082 
2083 	log_pll(reg, req_clk);
2084 }
2085 
2086 /* doing general fail-safe default setup here */
2087 static status_t	nv_crtc_setup_fifo()
2088 {
2089 	/* enable access to primary head */
2090 	set_crtc_owner(0);
2091 
2092 	/* set CRTC FIFO burst size to 256 */
2093 	CRTCW(FIFO, 0x03);
2094 
2095 	/* set CRTC FIFO low watermark to 32 */
2096 	CRTCW(FIFO_LWM, 0x20);
2097 
2098 	return B_OK;
2099 }
2100 
2101 /* (pre)set 'fixed' card specifications */
2102 void set_specs(void)
2103 {
2104 	LOG(8,("INFO: setting up card specifications\n"));
2105 
2106 	/* set failsave speeds */
2107 	switch (si->ps.card_type)
2108 	{
2109 	case NV04:
2110 		pinsnv4_fake();
2111 		break;
2112 	case NV05:
2113 	case NV05M64:
2114 		pinsnv5_nv5m64_fake();
2115 		break;
2116 	case NV06:
2117 		pinsnv6_fake();
2118 		break;
2119 	default:
2120 		switch (si->ps.card_arch)
2121 		{
2122 		case NV10A:
2123 			pinsnv10_arch_fake();
2124 			break;
2125 		case NV20A:
2126 			pinsnv20_arch_fake();
2127 			break;
2128 		case NV30A:
2129 		case NV40A:
2130 			pinsnv30_arch_fake();
2131 			break;
2132 		default:
2133 			/* 'failsafe' values... */
2134 			pinsnv10_arch_fake();
2135 			break;
2136 		}
2137 		break;
2138 	}
2139 
2140 	/* detect reference crystal frequency and dualhead */
2141 	switch (si->ps.card_arch)
2142 	{
2143 	case NV04A:
2144 		getstrap_arch_nv4();
2145 		break;
2146 	default:
2147 		getstrap_arch_nv10_20_30_40();
2148 		break;
2149 	}
2150 }
2151 
2152 /* this routine presumes the card was coldstarted by the card's BIOS for panel stuff */
2153 void fake_panel_start(void)
2154 {
2155 	LOG(8,("INFO: detecting RAM size\n"));
2156 
2157 	/* detect RAM amount */
2158 	switch (si->ps.card_arch)
2159 	{
2160 	case NV04A:
2161 		getRAMsize_arch_nv4();
2162 		break;
2163 	default:
2164 		getRAMsize_arch_nv10_20_30_40();
2165 		break;
2166 	}
2167 
2168 	/* override memory detection if requested by user */
2169 	if (si->settings.memory != 0)
2170 	{
2171 		LOG(2,("INFO: forcing memory size (specified in settings file)\n"));
2172 		si->ps.memory_size = si->settings.memory * 1024 * 1024;
2173 	}
2174 
2175 	/* find out if the card has a tvout chip */
2176 	si->ps.tvout = false;
2177 	si->ps.tv_encoder.type = NONE;
2178 	si->ps.tv_encoder.version = 0;
2179 	i2c_init();
2180 	//fixme: add support for more encoders...
2181 	BT_probe();
2182 
2183 	LOG(8,("INFO: faking panel startup\n"));
2184 
2185 	/* find out the BIOS preprogrammed panel use status... */
2186 	detect_panels();
2187 
2188 	/* determine and setup output devices and heads */
2189 	setup_output_matrix();
2190 
2191 	/* select other CRTC for primary head use if specified by user in settings file */
2192 	if (si->ps.secondary_head && si->settings.switchhead)
2193 	{
2194 		LOG(2,("INFO: inverting head use (specified in settings file)\n"));
2195 		si->ps.crtc2_prim = !si->ps.crtc2_prim;
2196 	}
2197 }
2198 
2199 static void detect_panels()
2200 {
2201 	/* detect if the BIOS enabled LCD's (internal panels or DVI) or TVout */
2202 
2203 	/* both external TMDS transmitters (used for LCD/DVI) and external TVencoders
2204 	 * (can) use the CRTC's in slaved mode. */
2205 	/* Note:
2206 	 * DFP's are programmed with standard VESA modelines by the card's BIOS! */
2207 	bool slaved_for_dev1 = false, slaved_for_dev2 = false;
2208 	bool tvout1 = false, tvout2 = false;
2209 
2210 	/* check primary head: */
2211 	/* enable access to primary head */
2212 	set_crtc_owner(0);
2213 
2214 	/* unlock head's registers for R/W access */
2215 	CRTCW(LOCK, 0x57);
2216 	CRTCW(VSYNCE ,(CRTCR(VSYNCE) & 0x7f));
2217 
2218 	LOG(2,("INFO: Dumping flatpanel related CRTC registers:\n"));
2219 	/* related info PIXEL register:
2220 	 * b7: 1 = slaved mode										(all cards). */
2221 	LOG(2,("CRTC1: PIXEL register: $%02x\n", CRTCR(PIXEL)));
2222 	/* info LCD register:
2223 	 * b7: 1 = stereo view (shutter glasses use)				(all cards),
2224 	 * b5: 1 = power ext. TMDS (or something)/0 = TVout	use	(?)	(confirmed NV17, NV28),
2225 	 * b4: 1 = power ext. TMDS (or something)/0 = TVout use	(?)	(confirmed NV34),
2226 	 * b3: 1 = ??? (not panel related probably!)				(confirmed NV34),
2227 	 * b1: 1 = power ext. TMDS (or something) (?)				(confirmed NV05?, NV17),
2228 	 * b0: 1 = select panel encoder / 0 = select TVout encoder	(all cards). */
2229 	LOG(2,("CRTC1: LCD register: $%02x\n", CRTCR(LCD)));
2230 	/* info 0x59 register:
2231 	 * b0: 1 = enable ext. TMDS clock (DPMS)					(confirmed NV28, NV34). */
2232 	LOG(2,("CRTC1: register $59: $%02x\n", CRTCR(0x59)));
2233 	/* info 0x9f register:
2234 	 * b4: 0 = TVout use (?). */
2235 	LOG(2,("CRTC1: register $9f: $%02x\n", CRTCR(0x9f)));
2236 
2237 	/* detect active slave device (if any) */
2238 	slaved_for_dev1 = (CRTCR(PIXEL) & 0x80);
2239 	if (slaved_for_dev1)
2240 	{
2241 		/* if the panel isn't selected, tvout is.. */
2242 		tvout1 = !(CRTCR(LCD) & 0x01);
2243 	}
2244 
2245 	if (si->ps.secondary_head)
2246 	{
2247 		/* check secondary head: */
2248 		/* enable access to secondary head */
2249 		set_crtc_owner(1);
2250 		/* unlock head's registers for R/W access */
2251 		CRTC2W(LOCK, 0x57);
2252 		CRTC2W(VSYNCE ,(CRTC2R(VSYNCE) & 0x7f));
2253 
2254 		LOG(2,("CRTC2: PIXEL register: $%02x\n", CRTC2R(PIXEL)));
2255 		LOG(2,("CRTC2: LCD register: $%02x\n", CRTC2R(LCD)));
2256 		LOG(2,("CRTC2: register $59: $%02x\n", CRTC2R(0x59)));
2257 		LOG(2,("CRTC2: register $9f: $%02x\n", CRTC2R(0x9f)));
2258 
2259 		/* detect active slave device (if any) */
2260 		slaved_for_dev2 = (CRTC2R(PIXEL) & 0x80);
2261 		if (slaved_for_dev2)
2262 		{
2263 			/* if the panel isn't selected, tvout is.. */
2264 			tvout2 = !(CRTC2R(LCD) & 0x01);
2265 		}
2266 	}
2267 
2268 	LOG(2,("INFO: End flatpanel related CRTC registers dump.\n"));
2269 
2270 	/* do some presets */
2271 	si->ps.p1_timing.h_display = 0;
2272 	si->ps.p1_timing.v_display = 0;
2273 	si->ps.panel1_aspect = 0;
2274 	si->ps.p2_timing.h_display = 0;
2275 	si->ps.p2_timing.v_display = 0;
2276 	si->ps.panel2_aspect = 0;
2277 	si->ps.slaved_tmds1 = false;
2278 	si->ps.slaved_tmds2 = false;
2279 	si->ps.master_tmds1 = false;
2280 	si->ps.master_tmds2 = false;
2281 	si->ps.tmds1_active = false;
2282 	si->ps.tmds2_active = false;
2283 	/* determine the situation we are in... (regarding flatpanels) */
2284 	/* fixme: add VESA DDC EDID stuff one day... */
2285 	/* fixme: find out how to program those transmitters one day instead of
2286 	 * relying on the cards BIOS to do it. This adds TVout options where panels
2287 	 * are used!
2288 	 * Currently we'd loose the panel setup while not being able to restore it. */
2289 
2290 	/* note: (facts)
2291 	 * -> NV11 and NV17 laptops have LVDS panels, programmed in both sets registers;
2292 	 * -> NV34 laptops have TMDS panels, programmed in only one set of registers;
2293 	 * -> NV11, NV25 and NV34 DVI cards, so external panels (TMDS) are programmed
2294 	 *    in only one set of registers;
2295 	 * -> a register-set's FP_TG_CTRL register, bit 31 tells you if a LVDS panel is
2296 	 *    connected to the primary head (0), or to the secondary head (1) except
2297 	 *    on some NV11's if this bit is '0' there;
2298 	 * -> for LVDS panels both registersets are programmed identically by the card's
2299 	 *    BIOSes;
2300 	 * -> the programmed set of registers tells you where a TMDS (DVI) panel is
2301 	 *    connected;
2302 	 * -> On all cards a CRTC is used in slaved mode when a panel is connected,
2303 	 *    except on NV11: here master mode is (might be?) detected. */
2304 	/* note also:
2305 	 * external TMDS encoders are only used for logic-level translation: it's
2306 	 * modeline registers are not used. Instead the GPU's internal modeline registers
2307 	 * are used. The external encoder is not connected to a I2C bus (confirmed NV34). */
2308 	if (slaved_for_dev1 && !tvout1)
2309 	{
2310 		uint16 width = ((DACR(FP_HDISPEND) & 0x0000ffff) + 1);
2311 		uint16 height = ((DACR(FP_VDISPEND) & 0x0000ffff) + 1);
2312 		if ((width >= 640) && (height >= 480))
2313 		{
2314 			si->ps.slaved_tmds1 = true;
2315 			si->ps.tmds1_active = true;
2316 			si->ps.p1_timing.h_display = width;
2317 			si->ps.p1_timing.v_display = height;
2318 		}
2319 	}
2320 
2321 	if (si->ps.secondary_head && slaved_for_dev2 && !tvout2)
2322 	{
2323 		uint16 width = ((DAC2R(FP_HDISPEND) & 0x0000ffff) + 1);
2324 		uint16 height = ((DAC2R(FP_VDISPEND) & 0x0000ffff) + 1);
2325 		if ((width >= 640) && (height >= 480))
2326 		{
2327 			si->ps.slaved_tmds2 = true;
2328 			si->ps.tmds2_active = true;
2329 			si->ps.p2_timing.h_display = width;
2330 			si->ps.p2_timing.v_display = height;
2331 		}
2332 	}
2333 
2334 	if ((si->ps.card_type == NV11) &&
2335 		!si->ps.slaved_tmds1 && !tvout1)
2336 	{
2337 		uint16 width = ((DACR(FP_HDISPEND) & 0x0000ffff) + 1);
2338 		uint16 height = ((DACR(FP_VDISPEND) & 0x0000ffff) + 1);
2339 		if ((width >= 640) && (height >= 480))
2340 		{
2341 			si->ps.master_tmds1 = true;
2342 			si->ps.tmds1_active = true;
2343 			si->ps.p1_timing.h_display = width;
2344 			si->ps.p1_timing.v_display = height;
2345 		}
2346 	}
2347 
2348 	if ((si->ps.card_type == NV11) &&
2349 		si->ps.secondary_head && !si->ps.slaved_tmds2 && !tvout2)
2350 	{
2351 		uint16 width = ((DAC2R(FP_HDISPEND) & 0x0000ffff) + 1);
2352 		uint16 height = ((DAC2R(FP_VDISPEND) & 0x0000ffff) + 1);
2353 		if ((width >= 640) && (height >= 480))
2354 		{
2355 			si->ps.master_tmds2 = true;
2356 			si->ps.tmds2_active = true;
2357 			si->ps.p2_timing.h_display = width;
2358 			si->ps.p2_timing.v_display = height;
2359 		}
2360 	}
2361 
2362 	//fixme...:
2363 	//we are assuming that no DVI is used as external monitor on laptops;
2364 	//otherwise we probably get into trouble here if the checked specs match.
2365 	if (si->ps.laptop && si->ps.tmds1_active && si->ps.tmds2_active &&
2366 		((DACR(FP_TG_CTRL) & 0x80000000) == (DAC2R(FP_TG_CTRL) & 0x80000000)) &&
2367 		(si->ps.p1_timing.h_display == si->ps.p2_timing.h_display) &&
2368 		(si->ps.p1_timing.v_display == si->ps.p2_timing.v_display))
2369 	{
2370 		LOG(2,("INFO: correcting double detection of single panel!\n"));
2371 
2372 		if (si->ps.card_type == NV11)
2373 		{
2374 			/* LVDS panel is _always_ on CRTC2, so clear false primary detection */
2375 			si->ps.slaved_tmds1 = false;
2376 			si->ps.master_tmds1 = false;
2377 			si->ps.tmds1_active = false;
2378 			si->ps.p1_timing.h_display = 0;
2379 			si->ps.p1_timing.v_display = 0;
2380 		}
2381 		else
2382 		{
2383 			if (DACR(FP_TG_CTRL) & 0x80000000)
2384 			{
2385 				/* LVDS panel is on CRTC2, so clear false primary detection */
2386 				si->ps.slaved_tmds1 = false;
2387 				si->ps.master_tmds1 = false;
2388 				si->ps.tmds1_active = false;
2389 				si->ps.p1_timing.h_display = 0;
2390 				si->ps.p1_timing.v_display = 0;
2391 			}
2392 			else
2393 			{
2394 				/* LVDS panel is on CRTC1, so clear false secondary detection */
2395 				si->ps.slaved_tmds2 = false;
2396 				si->ps.master_tmds2 = false;
2397 				si->ps.tmds2_active = false;
2398 				si->ps.p2_timing.h_display = 0;
2399 				si->ps.p2_timing.v_display = 0;
2400 			}
2401 		}
2402 	}
2403 
2404 	/* fetch panel(s) modeline(s) */
2405 	if (si->ps.tmds1_active)
2406 	{
2407 		/* determine panel aspect ratio */
2408 		si->ps.panel1_aspect =
2409 			(si->ps.p1_timing.h_display / ((float)si->ps.p1_timing.v_display));
2410 		/* force widescreen type if requested */
2411 		if (si->settings.force_ws) si->ps.panel1_aspect = 1.60;
2412 		/* horizontal timing */
2413 		si->ps.p1_timing.h_sync_start = (DACR(FP_HSYNC_S) & 0x0000ffff) + 1;
2414 		si->ps.p1_timing.h_sync_end = (DACR(FP_HSYNC_E) & 0x0000ffff) + 1;
2415 		si->ps.p1_timing.h_total = (DACR(FP_HTOTAL) & 0x0000ffff) + 1;
2416 		/* vertical timing */
2417 		si->ps.p1_timing.v_sync_start = (DACR(FP_VSYNC_S) & 0x0000ffff) + 1;
2418 		si->ps.p1_timing.v_sync_end = (DACR(FP_VSYNC_E) & 0x0000ffff) + 1;
2419 		si->ps.p1_timing.v_total = (DACR(FP_VTOTAL) & 0x0000ffff) + 1;
2420 		/* sync polarity */
2421 		si->ps.p1_timing.flags = 0;
2422 		if (DACR(FP_TG_CTRL) & 0x00000001) si->ps.p1_timing.flags |= B_POSITIVE_VSYNC;
2423 		if (DACR(FP_TG_CTRL) & 0x00000010) si->ps.p1_timing.flags |= B_POSITIVE_HSYNC;
2424 		/* display enable polarity (not an official flag) */
2425 		if (DACR(FP_TG_CTRL) & 0x10000000) si->ps.p1_timing.flags |= B_BLANK_PEDESTAL;
2426 		/* refreshrate:
2427 		 * fix a DVI or laptop flatpanel to 60Hz refresh! */
2428 		si->ps.p1_timing.pixel_clock =
2429 			(si->ps.p1_timing.h_total * si->ps.p1_timing.v_total * 60) / 1000;
2430 	}
2431 	if (si->ps.tmds2_active)
2432 	{
2433 		/* determine panel aspect ratio */
2434 		si->ps.panel2_aspect =
2435 			(si->ps.p2_timing.h_display / ((float)si->ps.p2_timing.v_display));
2436 		/* force widescreen type if requested */
2437 		if (si->settings.force_ws) si->ps.panel2_aspect = 1.60;
2438 		/* horizontal timing */
2439 		si->ps.p2_timing.h_sync_start = (DAC2R(FP_HSYNC_S) & 0x0000ffff) + 1;
2440 		si->ps.p2_timing.h_sync_end = (DAC2R(FP_HSYNC_E) & 0x0000ffff) + 1;
2441 		si->ps.p2_timing.h_total = (DAC2R(FP_HTOTAL) & 0x0000ffff) + 1;
2442 		/* vertical timing */
2443 		si->ps.p2_timing.v_sync_start = (DAC2R(FP_VSYNC_S) & 0x0000ffff) + 1;
2444 		si->ps.p2_timing.v_sync_end = (DAC2R(FP_VSYNC_E) & 0x0000ffff) + 1;
2445 		si->ps.p2_timing.v_total = (DAC2R(FP_VTOTAL) & 0x0000ffff) + 1;
2446 		/* sync polarity */
2447 		si->ps.p2_timing.flags = 0;
2448 		if (DAC2R(FP_TG_CTRL) & 0x00000001) si->ps.p2_timing.flags |= B_POSITIVE_VSYNC;
2449 		if (DAC2R(FP_TG_CTRL) & 0x00000010) si->ps.p2_timing.flags |= B_POSITIVE_HSYNC;
2450 		/* display enable polarity (not an official flag) */
2451 		if (DAC2R(FP_TG_CTRL) & 0x10000000) si->ps.p2_timing.flags |= B_BLANK_PEDESTAL;
2452 		/* refreshrate:
2453 		 * fix a DVI or laptop flatpanel to 60Hz refresh! */
2454 		si->ps.p2_timing.pixel_clock =
2455 			(si->ps.p2_timing.h_total * si->ps.p2_timing.v_total * 60) / 1000;
2456 	}
2457 
2458 	/* dump some panel configuration registers... */
2459 	LOG(2,("INFO: Dumping flatpanel registers:\n"));
2460 	LOG(2,("DUALHEAD_CTRL: $%08x\n", NV_REG32(NV32_DUALHEAD_CTRL)));
2461 	LOG(2,("DAC1: FP_HDISPEND: %d\n", DACR(FP_HDISPEND)));
2462 	LOG(2,("DAC1: FP_HTOTAL: %d\n", DACR(FP_HTOTAL)));
2463 	LOG(2,("DAC1: FP_HCRTC: %d\n", DACR(FP_HCRTC)));
2464 	LOG(2,("DAC1: FP_HSYNC_S: %d\n", DACR(FP_HSYNC_S)));
2465 	LOG(2,("DAC1: FP_HSYNC_E: %d\n", DACR(FP_HSYNC_E)));
2466 	LOG(2,("DAC1: FP_HVALID_S: %d\n", DACR(FP_HVALID_S)));
2467 	LOG(2,("DAC1: FP_HVALID_E: %d\n", DACR(FP_HVALID_E)));
2468 
2469 	LOG(2,("DAC1: FP_VDISPEND: %d\n", DACR(FP_VDISPEND)));
2470 	LOG(2,("DAC1: FP_VTOTAL: %d\n", DACR(FP_VTOTAL)));
2471 	LOG(2,("DAC1: FP_VCRTC: %d\n", DACR(FP_VCRTC)));
2472 	LOG(2,("DAC1: FP_VSYNC_S: %d\n", DACR(FP_VSYNC_S)));
2473 	LOG(2,("DAC1: FP_VSYNC_E: %d\n", DACR(FP_VSYNC_E)));
2474 	LOG(2,("DAC1: FP_VVALID_S: %d\n", DACR(FP_VVALID_S)));
2475 	LOG(2,("DAC1: FP_VVALID_E: %d\n", DACR(FP_VVALID_E)));
2476 
2477 	LOG(2,("DAC1: FP_CHKSUM: $%08x = (dec) %d\n", DACR(FP_CHKSUM),DACR(FP_CHKSUM)));
2478 	LOG(2,("DAC1: FP_TST_CTRL: $%08x\n", DACR(FP_TST_CTRL)));
2479 	LOG(2,("DAC1: FP_TG_CTRL: $%08x\n", DACR(FP_TG_CTRL)));
2480 	LOG(2,("DAC1: FP_DEBUG0: $%08x\n", DACR(FP_DEBUG0)));
2481 	LOG(2,("DAC1: FP_DEBUG1: $%08x\n", DACR(FP_DEBUG1)));
2482 	LOG(2,("DAC1: FP_DEBUG2: $%08x\n", DACR(FP_DEBUG2)));
2483 	LOG(2,("DAC1: FP_DEBUG3: $%08x\n", DACR(FP_DEBUG3)));
2484 
2485 	LOG(2,("DAC1: FUNCSEL: $%08x\n", NV_REG32(NV32_FUNCSEL)));
2486 	LOG(2,("DAC1: PANEL_PWR: $%08x\n", NV_REG32(NV32_PANEL_PWR)));
2487 
2488 	if(si->ps.secondary_head)
2489 	{
2490 		LOG(2,("DAC2: FP_HDISPEND: %d\n", DAC2R(FP_HDISPEND)));
2491 		LOG(2,("DAC2: FP_HTOTAL: %d\n", DAC2R(FP_HTOTAL)));
2492 		LOG(2,("DAC2: FP_HCRTC: %d\n", DAC2R(FP_HCRTC)));
2493 		LOG(2,("DAC2: FP_HSYNC_S: %d\n", DAC2R(FP_HSYNC_S)));
2494 		LOG(2,("DAC2: FP_HSYNC_E: %d\n", DAC2R(FP_HSYNC_E)));
2495 		LOG(2,("DAC2: FP_HVALID_S:%d\n", DAC2R(FP_HVALID_S)));
2496 		LOG(2,("DAC2: FP_HVALID_E: %d\n", DAC2R(FP_HVALID_E)));
2497 
2498 		LOG(2,("DAC2: FP_VDISPEND: %d\n", DAC2R(FP_VDISPEND)));
2499 		LOG(2,("DAC2: FP_VTOTAL: %d\n", DAC2R(FP_VTOTAL)));
2500 		LOG(2,("DAC2: FP_VCRTC: %d\n", DAC2R(FP_VCRTC)));
2501 		LOG(2,("DAC2: FP_VSYNC_S: %d\n", DAC2R(FP_VSYNC_S)));
2502 		LOG(2,("DAC2: FP_VSYNC_E: %d\n", DAC2R(FP_VSYNC_E)));
2503 		LOG(2,("DAC2: FP_VVALID_S: %d\n", DAC2R(FP_VVALID_S)));
2504 		LOG(2,("DAC2: FP_VVALID_E: %d\n", DAC2R(FP_VVALID_E)));
2505 
2506 		LOG(2,("DAC2: FP_CHKSUM: $%08x = (dec) %d\n", DAC2R(FP_CHKSUM),DAC2R(FP_CHKSUM)));
2507 		LOG(2,("DAC2: FP_TST_CTRL: $%08x\n", DAC2R(FP_TST_CTRL)));
2508 		LOG(2,("DAC2: FP_TG_CTRL: $%08x\n", DAC2R(FP_TG_CTRL)));
2509 		LOG(2,("DAC2: FP_DEBUG0: $%08x\n", DAC2R(FP_DEBUG0)));
2510 		LOG(2,("DAC2: FP_DEBUG1: $%08x\n", DAC2R(FP_DEBUG1)));
2511 		LOG(2,("DAC2: FP_DEBUG2: $%08x\n", DAC2R(FP_DEBUG2)));
2512 		LOG(2,("DAC2: FP_DEBUG3: $%08x\n", DAC2R(FP_DEBUG3)));
2513 
2514 		LOG(2,("DAC2: FUNCSEL: $%08x\n", NV_REG32(NV32_2FUNCSEL)));
2515 		LOG(2,("DAC2: PANEL_PWR: $%08x\n", NV_REG32(NV32_2PANEL_PWR)));
2516 	}
2517 
2518 	/* determine flatpanel type(s) */
2519 	/* note:
2520 	 * - on NV11 accessing registerset(s) hangs card.
2521 	 * - the same applies for NV34.
2522 	 *   Confirmed for DAC2 access on ID 0x0322,
2523 	 *   but only after a failed VESA modeswitch by the HAIKU kernel
2524 	 *   at boot time caused by a BIOS fault inside the gfx card: it says
2525 	 *   it can do VESA 1280x1024x32 on CRTC1/DAC1 but it fails: no signal. */
2526 	if (si->ps.tmds1_active && (si->ps.card_type != NV11))
2527 	{
2528 		/* Read a indexed register to see if it indicates LVDS or TMDS panel presence.
2529 		 * b0-7 = adress, b16 = 1 = write_enable */
2530 		DACW(FP_TMDS_CTRL, ((1 << 16) | 0x04));
2531 		/* (b0-7 = data) */
2532 		if (DACR(FP_TMDS_DATA) & 0x01)
2533 			LOG(2,("INFO: Flatpanel on head 1 is LVDS type\n"));
2534 		else
2535 			LOG(2,("INFO: Flatpanel on head 1 is TMDS type\n"));
2536 	}
2537 	if (si->ps.tmds2_active && (si->ps.card_type != NV11))
2538 	{
2539 		/* Read a indexed register to see if it indicates LVDS or TMDS panel presence.
2540 		 * b0-7 = adress, b16 = 1 = write_enable */
2541 		DAC2W(FP_TMDS_CTRL, ((1 << 16) | 0x04));
2542 		/* (b0-7 = data) */
2543 		if (DAC2R(FP_TMDS_DATA) & 0x01)
2544 			LOG(2,("INFO: Flatpanel on head 2 is LVDS type\n"));
2545 		else
2546 			LOG(2,("INFO: Flatpanel on head 2 is TMDS type\n"));
2547 	}
2548 
2549 	LOG(2,("INFO: End flatpanel registers dump.\n"));
2550 }
2551 
2552 static void setup_output_matrix()
2553 {
2554 	/* setup defaults: */
2555 	/* no monitors (output devices) detected */
2556 	si->ps.monitors = 0x00;
2557 	/* head 1 will be the primary head */
2558 	si->ps.crtc2_prim = false;
2559 
2560 	/* setup output devices and heads */
2561 	if (si->ps.secondary_head)
2562 	{
2563 		if (si->ps.card_type != NV11)
2564 		{
2565 			/* setup defaults: */
2566 			/* connect analog outputs straight through */
2567 			nv_general_output_select(false);
2568 
2569 			/* presetup by the card's BIOS, we can't change this (lack of info) */
2570 			if (si->ps.tmds1_active) si->ps.monitors |= 0x01;
2571 			if (si->ps.tmds2_active) si->ps.monitors |= 0x10;
2572 			/* detect analog monitors (confirmed working OK on NV18, NV28 and NV34): */
2573 			/* sense analog monitor on primary connector */
2574 			if (nv_dac_crt_connected()) si->ps.monitors |= 0x02;
2575 			/* sense analog monitor on secondary connector */
2576 			if (nv_dac2_crt_connected()) si->ps.monitors |= 0x20;
2577 
2578 			/* setup correct output and head use */
2579 			//fixme? add TVout (only, so no CRT(s) connected) support...
2580 			switch (si->ps.monitors)
2581 			{
2582 			case 0x00: /* no monitor found at all */
2583 				LOG(2,("INFO: head 1 has nothing connected;\n"));
2584 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2585 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2586 				break;
2587 			case 0x01: /* digital panel on head 1, nothing on head 2 */
2588 				LOG(2,("INFO: head 1 has a digital panel;\n"));
2589 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2590 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2591 				break;
2592 			case 0x02: /* analog panel or CRT on head 1, nothing on head 2 */
2593 				LOG(2,("INFO: head 1 has an analog panel or CRT;\n"));
2594 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2595 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2596 				break;
2597 			case 0x03: /* both types on head 1, nothing on head 2 */
2598 				LOG(2,("INFO: head 1 has a digital panel AND an analog panel or CRT;\n"));
2599 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2600 				LOG(2,("INFO: correcting...\n"));
2601 				/* cross connect analog outputs so analog panel or CRT gets head 2 */
2602 				nv_general_output_select(true);
2603 				LOG(2,("INFO: head 1 has a digital panel;\n"));
2604 				LOG(2,("INFO: head 2 has an analog panel or CRT:\n"));
2605 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2606 				break;
2607 			case 0x10: /* nothing on head 1, digital panel on head 2 */
2608 				LOG(2,("INFO: head 1 has nothing connected;\n"));
2609 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2610 				LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2611 				si->ps.crtc2_prim = true;
2612 				break;
2613 			case 0x20: /* nothing on head 1, analog panel or CRT on head 2 */
2614 				LOG(2,("INFO: head 1 has nothing connected;\n"));
2615 				LOG(2,("INFO: head 2 has an analog panel or CRT:\n"));
2616 				LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2617 				si->ps.crtc2_prim = true;
2618 				break;
2619 			case 0x30: /* nothing on head 1, both types on head 2 */
2620 				LOG(2,("INFO: head 1 has nothing connected;\n"));
2621 				LOG(2,("INFO: head 2 has a digital panel AND an analog panel or CRT:\n"));
2622 				LOG(2,("INFO: correcting...\n"));
2623 				/* cross connect analog outputs so analog panel or CRT gets head 1 */
2624 				nv_general_output_select(true);
2625 				LOG(2,("INFO: head 1 has an analog panel or CRT;\n"));
2626 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2627 				LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2628 				si->ps.crtc2_prim = true;
2629 				break;
2630 			case 0x11: /* digital panels on both heads */
2631 				LOG(2,("INFO: head 1 has a digital panel;\n"));
2632 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2633 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2634 				break;
2635 			case 0x12: /* analog panel or CRT on head 1, digital panel on head 2 */
2636 				LOG(2,("INFO: head 1 has an analog panel or CRT;\n"));
2637 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2638 				LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2639 				si->ps.crtc2_prim = true;
2640 				break;
2641 			case 0x21: /* digital panel on head 1, analog panel or CRT on head 2 */
2642 				LOG(2,("INFO: head 1 has a digital panel;\n"));
2643 				LOG(2,("INFO: head 2 has an analog panel or CRT:\n"));
2644 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2645 				break;
2646 			case 0x22: /* analog panel(s) or CRT(s) on both heads */
2647 				LOG(2,("INFO: head 1 has an analog panel or CRT;\n"));
2648 				LOG(2,("INFO: head 2 has an analog panel or CRT:\n"));
2649 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2650 				break;
2651 			case 0x32: /* more than two monitors connected to just two outputs: illegal! */
2652 				//general fixme:
2653 				//NV40 architecture contains (an) additional switch(es) to
2654 				//connect a CRTC/DAC combination to a connector. We can't work as
2655 				//usual (yet) because this interferes via BIOS card pre-programming.
2656 				//
2657 				//Also: it looks as if each pixelclock PLL can select different CRTC's
2658 				//as well now via a new register: one PLL can be driving both CRTC's
2659 				//and there's nothing we can do about that (yet). (DVI/dualhead trouble)
2660 				if (si->ps.card_arch < NV40A)
2661 				{
2662 					LOG(2,("INFO: illegal monitor setup ($%02x):\n", si->ps.monitors));
2663 					/* head 2 takes precedence because it has a digital panel while
2664 					 * head 1 has not. */
2665 					LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2666 					si->ps.crtc2_prim = true;
2667 					break;
2668 				}
2669 			default: /* more than two monitors connected to just two outputs: illegal! */
2670 				LOG(2,("INFO: illegal monitor setup ($%02x):\n", si->ps.monitors));
2671 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2672 				break;
2673 			}
2674 		}
2675 		else /* dualhead NV11 cards */
2676 		{
2677 			/* confirmed no analog output switch-options for NV11 */
2678 			LOG(2,("INFO: NV11 outputs are hardwired to be straight-through\n"));
2679 
2680 			/* presetup by the card's BIOS, we can't change this (lack of info) */
2681 			if (si->ps.tmds1_active) si->ps.monitors |= 0x01;
2682 			if (si->ps.tmds2_active) si->ps.monitors |= 0x10;
2683 			/* detect analog monitor (confirmed working OK on NV11): */
2684 			/* sense analog monitor on primary connector */
2685 			if (nv_dac_crt_connected()) si->ps.monitors |= 0x02;
2686 			/* (sense analog monitor on secondary connector is impossible on NV11) */
2687 
2688 			/* setup correct output and head use */
2689 			//fixme? add TVout (only, so no CRT(s) connected) support...
2690 			switch (si->ps.monitors)
2691 			{
2692 			case 0x00: /* no monitor found at all */
2693 				LOG(2,("INFO: head 1 has nothing connected;\n"));
2694 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2695 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2696 				break;
2697 			case 0x01: /* digital panel on head 1, nothing on head 2 */
2698 				LOG(2,("INFO: head 1 has a digital panel;\n"));
2699 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2700 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2701 				break;
2702 			case 0x02: /* analog panel or CRT on head 1, nothing on head 2 */
2703 				LOG(2,("INFO: head 1 has an analog panel or CRT;\n"));
2704 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2705 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2706 				break;
2707 			case 0x03: /* both types on head 1, nothing on head 2 */
2708 				LOG(2,("INFO: head 1 has a digital panel AND an analog panel or CRT;\n"));
2709 				LOG(2,("INFO: head 2 has nothing connected:\n"));
2710 				LOG(2,("INFO: correction not possible...\n"));
2711 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2712 				break;
2713 			case 0x10: /* nothing on head 1, digital panel on head 2 */
2714 				LOG(2,("INFO: head 1 has nothing connected;\n"));
2715 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2716 				LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2717 				si->ps.crtc2_prim = true;
2718 				break;
2719 			case 0x11: /* digital panels on both heads */
2720 				LOG(2,("INFO: head 1 has a digital panel;\n"));
2721 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2722 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2723 				break;
2724 			case 0x12: /* analog panel or CRT on head 1, digital panel on head 2 */
2725 				LOG(2,("INFO: head 1 has an analog panel or CRT;\n"));
2726 				LOG(2,("INFO: head 2 has a digital panel:\n"));
2727 				LOG(2,("INFO: defaulting to head 2 for primary use.\n"));
2728 				si->ps.crtc2_prim = true;
2729 				break;
2730 			default: /* more than two monitors connected to just two outputs: illegal! */
2731 				LOG(2,("INFO: illegal monitor setup ($%02x):\n", si->ps.monitors));
2732 				LOG(2,("INFO: defaulting to head 1 for primary use.\n"));
2733 				break;
2734 			}
2735 		}
2736 	}
2737 	else /* singlehead cards */
2738 	{
2739 		/* presetup by the card's BIOS, we can't change this (lack of info) */
2740 		if (si->ps.tmds1_active) si->ps.monitors |= 0x01;
2741 		/* detect analog monitor (confirmed working OK on all cards): */
2742 		/* sense analog monitor on primary connector */
2743 		if (nv_dac_crt_connected()) si->ps.monitors |= 0x02;
2744 
2745 		//fixme? add TVout (only, so no CRT connected) support...
2746 	}
2747 }
2748 
2749 void get_panel_modes(display_mode *p1, display_mode *p2, bool *pan1, bool *pan2)
2750 {
2751 	if (si->ps.tmds1_active)
2752 	{
2753 		/* timing ('modeline') */
2754 		p1->timing = si->ps.p1_timing;
2755 		/* setup the rest */
2756 		p1->space = B_CMAP8;
2757 		p1->virtual_width = p1->timing.h_display;
2758 		p1->virtual_height = p1->timing.v_display;
2759 		p1->h_display_start = 0;
2760 		p1->v_display_start = 0;
2761 		p1->flags = 0;
2762 		*pan1 = true;
2763 	}
2764 	else
2765 		*pan1 = false;
2766 
2767 	if (si->ps.tmds2_active)
2768 	{
2769 		/* timing ('modeline') */
2770 		p2->timing = si->ps.p2_timing;
2771 		/* setup the rest */
2772 		p2->space = B_CMAP8;
2773 		p2->virtual_width = p2->timing.h_display;
2774 		p2->virtual_height = p2->timing.v_display;
2775 		p2->h_display_start = 0;
2776 		p2->v_display_start = 0;
2777 		p2->flags = 0;
2778 		*pan2 = true;
2779 	}
2780 	else
2781 		*pan2 = false;
2782 }
2783 
2784 static void pinsnv4_fake(void)
2785 {
2786 	/* we have a standard PLL */
2787 	si->ps.ext_pll = false;
2788 	/* carefull not to take to high limits, and high should be >= 2x low. */
2789 	si->ps.max_system_vco = 256;
2790 	si->ps.min_system_vco = 128;
2791 	si->ps.max_pixel_vco = 256;
2792 	si->ps.min_pixel_vco = 128;
2793 	si->ps.max_video_vco = 0;
2794 	si->ps.min_video_vco = 0;
2795 	si->ps.max_dac1_clock = 250;
2796 	si->ps.max_dac1_clock_8 = 250;
2797 	si->ps.max_dac1_clock_16 = 250;
2798 	/* 'failsave' values */
2799 	si->ps.max_dac1_clock_24 = 220;
2800 	si->ps.max_dac1_clock_32 = 180;
2801 	si->ps.max_dac1_clock_32dh = 180;
2802 	/* secondary head */
2803 	si->ps.max_dac2_clock = 0;
2804 	si->ps.max_dac2_clock_8 = 0;
2805 	si->ps.max_dac2_clock_16 = 0;
2806 	si->ps.max_dac2_clock_24 = 0;
2807 	si->ps.max_dac2_clock_32 = 0;
2808 	/* 'failsave' values */
2809 	si->ps.max_dac2_clock_32dh = 0;
2810 	//fixme: primary & secondary_dvi should be overrule-able via nv.settings
2811 	si->ps.primary_dvi = false;
2812 	si->ps.secondary_dvi = false;
2813 	/* not used (yet) because no coldstart will be attempted (yet) */
2814 	si->ps.std_engine_clock = 90;
2815 	si->ps.std_memory_clock = 110;
2816 }
2817 
2818 static void pinsnv5_nv5m64_fake(void)
2819 {
2820 	/* we have a standard PLL */
2821 	si->ps.ext_pll = false;
2822 	/* carefull not to take to high limits, and high should be >= 2x low. */
2823 	si->ps.max_system_vco = 300;
2824 	si->ps.min_system_vco = 128;
2825 	si->ps.max_pixel_vco = 300;
2826 	si->ps.min_pixel_vco = 128;
2827 	si->ps.max_video_vco = 0;
2828 	si->ps.min_video_vco = 0;
2829 	si->ps.max_dac1_clock = 300;
2830 	si->ps.max_dac1_clock_8 = 300;
2831 	si->ps.max_dac1_clock_16 = 300;
2832 	/* 'failsave' values */
2833 	si->ps.max_dac1_clock_24 = 270;
2834 	si->ps.max_dac1_clock_32 = 230;
2835 	si->ps.max_dac1_clock_32dh = 230;
2836 	/* secondary head */
2837 	si->ps.max_dac2_clock = 0;
2838 	si->ps.max_dac2_clock_8 = 0;
2839 	si->ps.max_dac2_clock_16 = 0;
2840 	si->ps.max_dac2_clock_24 = 0;
2841 	si->ps.max_dac2_clock_32 = 0;
2842 	/* 'failsave' values */
2843 	si->ps.max_dac2_clock_32dh = 0;
2844 	//fixme: primary & secondary_dvi should be overrule-able via nv.settings
2845 	si->ps.primary_dvi = false;
2846 	si->ps.secondary_dvi = false;
2847 	/* not used (yet) because no coldstart will be attempted (yet) */
2848 	si->ps.std_engine_clock = 125;
2849 	si->ps.std_memory_clock = 150;
2850 }
2851 
2852 static void pinsnv6_fake(void)
2853 {
2854 	/* we have a standard PLL */
2855 	si->ps.ext_pll = false;
2856 	/* carefull not to take to high limits, and high should be >= 2x low. */
2857 	si->ps.max_system_vco = 300;
2858 	si->ps.min_system_vco = 128;
2859 	si->ps.max_pixel_vco = 300;
2860 	si->ps.min_pixel_vco = 128;
2861 	si->ps.max_video_vco = 0;
2862 	si->ps.min_video_vco = 0;
2863 	si->ps.max_dac1_clock = 300;
2864 	si->ps.max_dac1_clock_8 = 300;
2865 	si->ps.max_dac1_clock_16 = 300;
2866 	/* 'failsave' values */
2867 	si->ps.max_dac1_clock_24 = 270;
2868 	si->ps.max_dac1_clock_32 = 230;
2869 	si->ps.max_dac1_clock_32dh = 230;
2870 	/* secondary head */
2871 	si->ps.max_dac2_clock = 0;
2872 	si->ps.max_dac2_clock_8 = 0;
2873 	si->ps.max_dac2_clock_16 = 0;
2874 	si->ps.max_dac2_clock_24 = 0;
2875 	si->ps.max_dac2_clock_32 = 0;
2876 	/* 'failsave' values */
2877 	si->ps.max_dac2_clock_32dh = 0;
2878 	//fixme: primary & secondary_dvi should be overrule-able via nv.settings
2879 	si->ps.primary_dvi = false;
2880 	si->ps.secondary_dvi = false;
2881 	/* not used (yet) because no coldstart will be attempted (yet) */
2882 	si->ps.std_engine_clock = 100;
2883 	si->ps.std_memory_clock = 125;
2884 }
2885 
2886 static void pinsnv10_arch_fake(void)
2887 {
2888 	/* we have a standard PLL */
2889 	si->ps.ext_pll = false;
2890 	/* carefull not to take to high limits, and high should be >= 2x low. */
2891 	si->ps.max_system_vco = 350;
2892 	si->ps.min_system_vco = 128;
2893 	si->ps.max_pixel_vco = 350;
2894 	si->ps.min_pixel_vco = 128;
2895 	si->ps.max_video_vco = 350;
2896 	si->ps.min_video_vco = 128;
2897 	si->ps.max_dac1_clock = 350;
2898 	si->ps.max_dac1_clock_8 = 350;
2899 	si->ps.max_dac1_clock_16 = 350;
2900 	/* 'failsave' values */
2901 	si->ps.max_dac1_clock_24 = 320;
2902 	si->ps.max_dac1_clock_32 = 280;
2903 	si->ps.max_dac1_clock_32dh = 250;
2904 	/* secondary head */
2905 	if (si->ps.card_type < NV17)
2906 	{
2907 		/* if a GeForce2 has analog VGA dualhead capability,
2908 		 * it uses an external secondary DAC probably with limited capability. */
2909 		/* (called twinview technology) */
2910 		si->ps.max_dac2_clock = 200;
2911 		si->ps.max_dac2_clock_8 = 200;
2912 		si->ps.max_dac2_clock_16 = 200;
2913 		si->ps.max_dac2_clock_24 = 200;
2914 		si->ps.max_dac2_clock_32 = 200;
2915 		/* 'failsave' values */
2916 		si->ps.max_dac2_clock_32dh = 180;
2917 	}
2918 	else
2919 	{
2920 		/* GeForce4 cards have dual integrated DACs with identical capaability */
2921 		/* (called nview technology) */
2922 		si->ps.max_dac2_clock = 350;
2923 		si->ps.max_dac2_clock_8 = 350;
2924 		si->ps.max_dac2_clock_16 = 350;
2925 		/* 'failsave' values */
2926 		si->ps.max_dac2_clock_24 = 320;
2927 		si->ps.max_dac2_clock_32 = 280;
2928 		si->ps.max_dac2_clock_32dh = 250;
2929 	}
2930 	//fixme: primary & secondary_dvi should be overrule-able via nv.settings
2931 	si->ps.primary_dvi = false;
2932 	si->ps.secondary_dvi = false;
2933 	/* not used (yet) because no coldstart will be attempted (yet) */
2934 	si->ps.std_engine_clock = 120;
2935 	si->ps.std_memory_clock = 150;
2936 }
2937 
2938 static void pinsnv20_arch_fake(void)
2939 {
2940 	/* we have a standard PLL */
2941 	si->ps.ext_pll = false;
2942 	/* carefull not to take to high limits, and high should be >= 2x low. */
2943 	si->ps.max_system_vco = 350;
2944 	si->ps.min_system_vco = 128;
2945 	si->ps.max_pixel_vco = 350;
2946 	si->ps.min_pixel_vco = 128;
2947 	si->ps.max_video_vco = 350;
2948 	si->ps.min_video_vco = 128;
2949 	si->ps.max_dac1_clock = 350;
2950 	si->ps.max_dac1_clock_8 = 350;
2951 	si->ps.max_dac1_clock_16 = 350;
2952 	/* 'failsave' values */
2953 	si->ps.max_dac1_clock_24 = 320;
2954 	si->ps.max_dac1_clock_32 = 280;
2955 	si->ps.max_dac1_clock_32dh = 250;
2956 	/* secondary head */
2957 	/* GeForce4 cards have dual integrated DACs with identical capaability */
2958 	/* (called nview technology) */
2959 	si->ps.max_dac2_clock = 350;
2960 	si->ps.max_dac2_clock_8 = 350;
2961 	si->ps.max_dac2_clock_16 = 350;
2962 	/* 'failsave' values */
2963 	si->ps.max_dac2_clock_24 = 320;
2964 	si->ps.max_dac2_clock_32 = 280;
2965 	si->ps.max_dac2_clock_32dh = 250;
2966 	//fixme: primary & secondary_dvi should be overrule-able via nv.settings
2967 	si->ps.primary_dvi = false;
2968 	si->ps.secondary_dvi = false;
2969 	/* not used (yet) because no coldstart will be attempted (yet) */
2970 	si->ps.std_engine_clock = 175;
2971 	si->ps.std_memory_clock = 200;
2972 }
2973 
2974 static void pinsnv30_arch_fake(void)
2975 {
2976 	/* determine PLL type */
2977 	if ((si->ps.card_type == NV31) ||
2978 		(si->ps.card_type == NV36) ||
2979 		(si->ps.card_type >= NV40))
2980 	{
2981 		/* we have a extended PLL */
2982 		si->ps.ext_pll = true;
2983 	}
2984 	else
2985 	{
2986 		/* we have a standard PLL */
2987 		si->ps.ext_pll = false;
2988 	}
2989 	/* carefull not to take to high limits, and high should be >= 2x low. */
2990 	si->ps.max_system_vco = 350;
2991 	si->ps.min_system_vco = 128;
2992 	if (si->ps.ext_pll)
2993 	{
2994 		si->ps.max_pixel_vco = 600;
2995 		si->ps.min_pixel_vco = 220;
2996 		si->ps.max_video_vco = 600;
2997 		si->ps.min_video_vco = 220;
2998 	}
2999 	else
3000 	{
3001 		si->ps.max_pixel_vco = 350;
3002 		si->ps.min_pixel_vco = 128;
3003 		si->ps.max_video_vco = 350;
3004 		si->ps.min_video_vco = 128;
3005 	}
3006 	si->ps.max_dac1_clock = 350;
3007 	si->ps.max_dac1_clock_8 = 350;
3008 	si->ps.max_dac1_clock_16 = 350;
3009 	/* 'failsave' values */
3010 	si->ps.max_dac1_clock_24 = 320;
3011 	si->ps.max_dac1_clock_32 = 280;
3012 	si->ps.max_dac1_clock_32dh = 250;
3013 	/* secondary head */
3014 	/* GeForceFX cards have dual integrated DACs with identical capability */
3015 	/* (called nview technology) */
3016 	si->ps.max_dac2_clock = 350;
3017 	si->ps.max_dac2_clock_8 = 350;
3018 	si->ps.max_dac2_clock_16 = 350;
3019 	/* 'failsave' values */
3020 	si->ps.max_dac2_clock_24 = 320;
3021 	si->ps.max_dac2_clock_32 = 280;
3022 	si->ps.max_dac2_clock_32dh = 250;
3023 	//fixme: primary & secondary_dvi should be overrule-able via nv.settings
3024 	si->ps.primary_dvi = false;
3025 	si->ps.secondary_dvi = false;
3026 	/* not used (yet) because no coldstart will be attempted (yet) */
3027 	si->ps.std_engine_clock = 190;
3028 	si->ps.std_memory_clock = 190;
3029 }
3030 
3031 static void getRAMsize_arch_nv4(void)
3032 {
3033 	uint32 strapinfo = NV_REG32(NV32_NV4STRAPINFO);
3034 
3035 	if (strapinfo & 0x00000100)
3036 	{
3037 		/* Unified memory architecture used */
3038 		si->ps.memory_size = 1024 * 1024 *
3039 			((((strapinfo & 0x0000f000) >> 12) * 2) + 2);
3040 
3041 		LOG(8,("INFO: NV4 architecture chip with UMA detected\n"));
3042 	}
3043 	else
3044 	{
3045 		/* private memory architecture used */
3046 		switch (strapinfo & 0x00000003)
3047 		{
3048 		case 0:
3049 			si->ps.memory_size = 32 * 1024 * 1024;
3050 			break;
3051 		case 1:
3052 			si->ps.memory_size = 4 * 1024 * 1024;
3053 			break;
3054 		case 2:
3055 			si->ps.memory_size = 8 * 1024 * 1024;
3056 			break;
3057 		case 3:
3058 			si->ps.memory_size = 16 * 1024 * 1024;
3059 			break;
3060 		}
3061 	}
3062 }
3063 
3064 static void getstrap_arch_nv4(void)
3065 {
3066 	uint32 strapinfo = NV_REG32(NV32_NVSTRAPINFO2);
3067 
3068 	/* determine PLL reference crystal frequency */
3069 	if (strapinfo & 0x00000040)
3070 		si->ps.f_ref = 14.31818;
3071 	else
3072 		si->ps.f_ref = 13.50000;
3073 
3074 	/* these cards are always singlehead */
3075 	si->ps.secondary_head = false;
3076 }
3077 
3078 static void getRAMsize_arch_nv10_20_30_40(void)
3079 {
3080 	uint32 dev_manID = CFGR(DEVID);
3081 	uint32 strapinfo = NV_REG32(NV32_NV10STRAPINFO);
3082 
3083 	switch (dev_manID)
3084 	{
3085 	case 0x01a010de: /* Nvidia GeForce2 Integrated GPU */
3086 	case 0x01f010de: /* Nvidia GeForce4 MX Integrated GPU */
3087 		/* the kerneldriver already determined the amount of RAM these cards have at
3088 		 * their disposal (UMA, values read from PCI config space in other device) */
3089 		LOG(8,("INFO: nVidia GPU with UMA detected\n"));
3090 		break;
3091 	default:
3092 		LOG(8,("INFO: (Memory detection) Strapinfo value is: $%08x\n", strapinfo));
3093 
3094 		switch ((strapinfo & 0x3ff00000) >> 20)
3095 		{
3096 		case 2:
3097 			si->ps.memory_size = 2 * 1024 * 1024;
3098 			break;
3099 		case 4:
3100 			si->ps.memory_size = 4 * 1024 * 1024;
3101 			break;
3102 		case 8:
3103 			si->ps.memory_size = 8 * 1024 * 1024;
3104 			break;
3105 		case 16:
3106 			si->ps.memory_size = 16 * 1024 * 1024;
3107 			break;
3108 		case 32:
3109 			si->ps.memory_size = 32 * 1024 * 1024;
3110 			break;
3111 		case 64:
3112 			si->ps.memory_size = 64 * 1024 * 1024;
3113 			break;
3114 		case 128:
3115 			si->ps.memory_size = 128 * 1024 * 1024;
3116 			break;
3117 		case 256:
3118 			si->ps.memory_size = 256 * 1024 * 1024;
3119 			break;
3120 		case 512:
3121 			si->ps.memory_size = 512 * 1024 * 1024;
3122 			break;
3123 		default:
3124 			si->ps.memory_size = 16 * 1024 * 1024;
3125 
3126 			LOG(8,("INFO: NV10/20/30 architecture chip with unknown RAM amount detected;\n"));
3127 			LOG(8,("INFO: Setting 16Mb\n"));
3128 			break;
3129 		}
3130 	}
3131 }
3132 
3133 static void getstrap_arch_nv10_20_30_40(void)
3134 {
3135 	uint32 dev_manID = CFGR(DEVID);
3136 	uint32 strapinfo = NV_REG32(NV32_NVSTRAPINFO2);
3137 
3138 	/* determine if we have a dualhead card */
3139 	si->ps.secondary_head = false;
3140 	switch (si->ps.card_type)
3141 	{
3142 	case NV04:
3143 	case NV05:
3144 	case NV05M64:
3145 	case NV06:
3146 	case NV10:
3147 	case NV15:
3148 	case NV20:
3149 		break;
3150 	default:
3151 		if ((dev_manID & 0xfff0ffff) == 0x01a010de)
3152 		{
3153 			/* this is a singlehead NV11! */
3154 		}
3155 		else
3156 		{
3157 			si->ps.secondary_head = true;
3158 		}
3159 	}
3160 
3161 	/* determine PLL reference crystal frequency: three types are used... */
3162 	if (strapinfo & 0x00000040)
3163 		si->ps.f_ref = 14.31818;
3164 	else
3165 		si->ps.f_ref = 13.50000;
3166 
3167 	if ((si->ps.secondary_head) && (si->ps.card_type != NV11))
3168 	{
3169 		if (strapinfo & 0x00400000) si->ps.f_ref = 27.00000;
3170 	}
3171 }
3172 
3173 void dump_pins(void)
3174 {
3175 	char *msg = "";
3176 
3177 	LOG(2,("INFO: pinsdump follows:\n"));
3178 	LOG(2,("PLL type: "));
3179 	if (si->ps.ext_pll) LOG(2,("extended\n")); else LOG(2,("standard\n"));
3180 	LOG(2,("f_ref: %fMhz\n", si->ps.f_ref));
3181 	LOG(2,("max_system_vco: %dMhz\n", si->ps.max_system_vco));
3182 	LOG(2,("min_system_vco: %dMhz\n", si->ps.min_system_vco));
3183 	LOG(2,("max_pixel_vco: %dMhz\n", si->ps.max_pixel_vco));
3184 	LOG(2,("min_pixel_vco: %dMhz\n", si->ps.min_pixel_vco));
3185 	LOG(2,("max_video_vco: %dMhz\n", si->ps.max_video_vco));
3186 	LOG(2,("min_video_vco: %dMhz\n", si->ps.min_video_vco));
3187 	LOG(2,("std_engine_clock: %dMhz\n", si->ps.std_engine_clock));
3188 	LOG(2,("std_memory_clock: %dMhz\n", si->ps.std_memory_clock));
3189 	LOG(2,("max_dac1_clock: %dMhz\n", si->ps.max_dac1_clock));
3190 	LOG(2,("max_dac1_clock_8: %dMhz\n", si->ps.max_dac1_clock_8));
3191 	LOG(2,("max_dac1_clock_16: %dMhz\n", si->ps.max_dac1_clock_16));
3192 	LOG(2,("max_dac1_clock_24: %dMhz\n", si->ps.max_dac1_clock_24));
3193 	LOG(2,("max_dac1_clock_32: %dMhz\n", si->ps.max_dac1_clock_32));
3194 	LOG(2,("max_dac1_clock_32dh: %dMhz\n", si->ps.max_dac1_clock_32dh));
3195 	LOG(2,("max_dac2_clock: %dMhz\n", si->ps.max_dac2_clock));
3196 	LOG(2,("max_dac2_clock_8: %dMhz\n", si->ps.max_dac2_clock_8));
3197 	LOG(2,("max_dac2_clock_16: %dMhz\n", si->ps.max_dac2_clock_16));
3198 	LOG(2,("max_dac2_clock_24: %dMhz\n", si->ps.max_dac2_clock_24));
3199 	LOG(2,("max_dac2_clock_32: %dMhz\n", si->ps.max_dac2_clock_32));
3200 	LOG(2,("max_dac2_clock_32dh: %dMhz\n", si->ps.max_dac2_clock_32dh));
3201 	LOG(2,("secondary_head: "));
3202 	if (si->ps.secondary_head) LOG(2,("present\n")); else LOG(2,("absent\n"));
3203 	LOG(2,("tvout: "));
3204 	if (si->ps.tvout) LOG(2,("present\n")); else LOG(2,("absent\n"));
3205 	/* setup TVout logmessage text */
3206 	switch (si->ps.tv_encoder.type)
3207 	{
3208 	case NONE:
3209 		msg = "No";
3210 		break;
3211 	case CH7003:
3212 		msg = "Chrontel CH7003";
3213 		break;
3214 	case CH7004:
3215 		msg = "Chrontel CH7004";
3216 		break;
3217 	case CH7005:
3218 		msg = "Chrontel CH7005";
3219 		break;
3220 	case CH7006:
3221 		msg = "Chrontel CH7006";
3222 		break;
3223 	case CH7007:
3224 		msg = "Chrontel CH7007";
3225 		break;
3226 	case CH7008:
3227 		msg = "Chrontel CH7008";
3228 		break;
3229 	case SAA7102:
3230 		msg = "Philips SAA7102";
3231 		break;
3232 	case SAA7103:
3233 		msg = "Philips SAA7103";
3234 		break;
3235 	case SAA7104:
3236 		msg = "Philips SAA7104";
3237 		break;
3238 	case SAA7105:
3239 		msg = "Philips SAA7105";
3240 		break;
3241 	case BT868:
3242 		msg = "Brooktree/Conexant BT868";
3243 		break;
3244 	case BT869:
3245 		msg = "Brooktree/Conexant BT869";
3246 		break;
3247 	case CX25870:
3248 		msg = "Conexant CX25870";
3249 		break;
3250 	case CX25871:
3251 		msg = "Conexant CX25871";
3252 		break;
3253 	case NVIDIA:
3254 		msg = "Nvidia internal";
3255 		break;
3256 	default:
3257 		msg = "Unknown";
3258 		break;
3259 	}
3260 	LOG(2, ("%s TV encoder detected; silicon revision is $%02x\n",
3261 		msg, si->ps.tv_encoder.version));
3262 //	LOG(2,("primary_dvi: "));
3263 //	if (si->ps.primary_dvi) LOG(2,("present\n")); else LOG(2,("absent\n"));
3264 //	LOG(2,("secondary_dvi: "));
3265 //	if (si->ps.secondary_dvi) LOG(2,("present\n")); else LOG(2,("absent\n"));
3266 	LOG(2,("card memory_size: %3.3fMb\n", (si->ps.memory_size / (1024.0 * 1024.0))));
3267 	LOG(2,("laptop: "));
3268 	if (si->ps.laptop) LOG(2,("yes\n")); else LOG(2,("no\n"));
3269 	if (si->ps.tmds1_active)
3270 	{
3271 		LOG(2,("found DFP (digital flatpanel) on CRTC1; CRTC1 is "));
3272 		if (si->ps.slaved_tmds1) LOG(2,("slaved\n")); else LOG(2,("master\n"));
3273 		LOG(2,("panel width: %d, height: %d, aspect ratio: %1.2f\n",
3274 			si->ps.p1_timing.h_display, si->ps.p1_timing.v_display, si->ps.panel1_aspect));
3275 	}
3276 	if (si->ps.tmds2_active)
3277 	{
3278 		LOG(2,("found DFP (digital flatpanel) on CRTC2; CRTC2 is "));
3279 		if (si->ps.slaved_tmds2) LOG(2,("slaved\n")); else LOG(2,("master\n"));
3280 		LOG(2,("panel width: %d, height: %d, aspect ratio: %1.2f\n",
3281 			si->ps.p2_timing.h_display, si->ps.p2_timing.v_display, si->ps.panel2_aspect));
3282 	}
3283 	LOG(2,("monitor (output devices) setup matrix: $%02x\n", si->ps.monitors));
3284 	LOG(2,("INFO: end pinsdump.\n"));
3285 }
3286