xref: /haiku/src/add-ons/accelerants/matrox/engine/mga_general.c (revision a6e6b1d36f598254b8c1f548724abc8359f5d60c)
1 /* Authors:
2    Mark Watson 12/1999,
3    Apsed,
4    Rudolf Cornelissen 10/2002-11/2005
5 */
6 
7 #define MODULE_BIT 0x00008000
8 
9 #include "mga_std.h"
10 
11 static status_t test_ram(void);
12 static status_t mil_general_powerup (void);
13 static status_t g100_general_powerup (void);
14 static status_t g200_general_powerup (void);
15 static status_t g400_general_powerup (void);
16 static status_t g450_general_powerup (void);
17 static status_t gx00_general_bios_to_powergraphics(void);
18 
19 static void mga_dump_configuration_space (void)
20 {
21 #define DUMP_CFG(reg, type) if (si->ps.card_type >= type) do { \
22 	uint32 value = CFGR(reg); \
23 	MSG(("configuration_space 0x%02x %20s 0x%08x\n", \
24 		MGACFG_##reg, #reg, value)); \
25 } while (0)
26 	DUMP_CFG (DEVID,     0);
27 	DUMP_CFG (DEVCTRL,   0);
28 	DUMP_CFG (CLASS,     0);
29 	DUMP_CFG (HEADER,    0);
30 	DUMP_CFG (MGABASE2,  0);
31 	DUMP_CFG (MGABASE1,  0);
32 	DUMP_CFG (MGABASE3,  MYST);
33 	DUMP_CFG (SUBSYSIDR, MYST);
34 	DUMP_CFG (ROMBASE,   0);
35 	DUMP_CFG (CAP_PTR,   MIL2);
36 	DUMP_CFG (INTCTRL,   0);
37 	DUMP_CFG (OPTION,    0);
38 	DUMP_CFG (MGA_INDEX, 0);
39 	DUMP_CFG (MGA_DATA,  0);
40 	DUMP_CFG (SUBSYSIDW, MYST);
41 	DUMP_CFG (OPTION2,   G100);
42 	DUMP_CFG (OPTION3,   G400);
43 	DUMP_CFG (OPTION4,   G400);
44 	DUMP_CFG (PM_IDENT,  G100);
45 	DUMP_CFG (PM_CSR,    G100);
46 	DUMP_CFG (AGP_IDENT, MIL2);
47 	DUMP_CFG (AGP_STS,   MIL2);
48 	DUMP_CFG (AGP_CMD,   MIL2);
49 #undef DUMP_CFG
50 }
51 
52 status_t gx00_general_powerup()
53 {
54 	status_t status;
55 	uint32 card_class;
56 
57 	LOG(1,("POWERUP: Haiku Matrox Accelerant 0.26 running.\n"));
58 
59 	/* log VBLANK INT usability status */
60 	if (si->ps.int_assigned)
61 		LOG(4,("POWERUP: Usable INT assigned to HW; Vblank semaphore enabled\n"));
62 	else
63 		LOG(4,("POWERUP: No (usable) INT assigned to HW; Vblank semaphore disabled\n"));
64 
65 	/* detect card type and power it up */
66 	switch(CFGR(DEVID))
67 	{
68 	case 0x051a102b: //MGA-1064 Mystic PCI
69 		LOG(8,("POWERUP: Unimplemented Matrox device %08x\n",CFGR(DEVID)));
70 		return B_ERROR;
71 	case 0x0519102b: //MGA-2064 Millenium PCI
72 		si->ps.card_type = MIL1;
73 		LOG(4,("POWERUP: Detected MGA-2064 Millennium 1\n"));
74 		status = mil_general_powerup();
75 		break;
76 	case 0x051b102b:case 0x051f102b: //MGA-2164 Millenium 2 PCI/AGP
77 		si->ps.card_type = MIL2;
78 		LOG(4,("POWERUP: Detected MGA-2164 Millennium 2\n"));
79 		status = mil_general_powerup();
80 		break;
81 	case 0x1000102b:case 0x1001102b: //G100
82 		si->ps.card_type = G100;
83 		LOG(4,("POWERUP: Detected G100\n"));
84 		status = g100_general_powerup();
85 		break;
86 	case 0x0520102b:case 0x0521102b: //G200
87 		si->ps.card_type = G200;
88 		LOG(4,("POWERUP: Detected G200\n"));
89 		status = g200_general_powerup();
90 		break;
91 	case 0x0525102b: //G400, G400MAX or G450
92 		LOG(4,("POWERUP: Detected G4"));
93 		/* get classinfo to distinguish different types */
94 		card_class = CFGR(CLASS) & 0xff;
95 		if (card_class & 0x80)
96 		{
97 			/* G450 */
98 			si->ps.card_type = G450;
99 			LOG(4, ("50 revision %x\n", card_class & 0x7f));
100 			status = g450_general_powerup();
101 		}
102 		else
103 		{
104 			/* standard G400, G400MAX */
105 			/* the only difference is the max RAMDAC speed, accounted for via pins. */
106 			si->ps.card_type = G400;
107 			LOG(4, ("00 revision %x\n", card_class & 0x7f));
108 			status = g400_general_powerup();
109 		}
110 		break;
111 	case 0x2527102b://G550 patch from Jean-Michel Batto
112 		si->ps.card_type = G450;
113 		LOG(4,("POWERUP: Detected G550\n"));
114 		status = g450_general_powerup();
115 		break;
116 	default:
117 		LOG(8,("POWERUP: Failed to detect valid card 0x%08x\n",CFGR(DEVID)));
118 		return B_ERROR;
119 	}
120 
121 	/* override memory detection if requested by user */
122 	if (si->settings.memory != 0)
123 		si->ps.memory_size = si->settings.memory;
124 
125 	return status;
126 }
127 
128 static status_t test_ram()
129 {
130 	uint32 value, offset;
131 	status_t result = B_OK;
132 
133 	/* make sure we don't corrupt the hardware cursor by using fbc.frame_buffer. */
134 	if (si->fbc.frame_buffer == NULL)
135 	{
136 		LOG(8,("INIT: test_ram detected NULL pointer.\n"));
137 		return B_ERROR;
138 	}
139 
140 	for (offset = 0, value = 0x55aa55aa; offset < 256; offset++)
141 	{
142 		/* write testpattern to cardRAM */
143 		((uint32 *)si->fbc.frame_buffer)[offset] = value;
144 		/* toggle testpattern */
145 		value = 0xffffffff - value;
146 	}
147 
148 	for (offset = 0, value = 0x55aa55aa; offset < 256; offset++)
149 	{
150 		/* readback and verify testpattern from cardRAM */
151 		if (((uint32 *)si->fbc.frame_buffer)[offset] != value) result = B_ERROR;
152 		/* toggle testpattern */
153 		value = 0xffffffff - value;
154 	}
155 	return result;
156 }
157 
158 /* NOTE:
159  * This routine *has* to be done *after* SetDispplayMode has been executed,
160  * or test results will not be representative!
161  * (CAS latency is dependant on MGA setup on some (DRAM) boards) */
162 status_t mga_set_cas_latency()
163 {
164 	status_t result = B_ERROR;
165 	uint8 latency = 0;
166 
167 	/* check current RAM access to see if we need to change anything */
168 	if (test_ram() == B_OK)
169 	{
170 		LOG(4,("INIT: RAM access OK.\n"));
171 		return B_OK;
172 	}
173 
174 	/* check if we read PINS at starttime so we have valid registersettings at our disposal */
175 	if (si->ps.pins_status != B_OK)
176 	{
177 		LOG(4,("INIT: RAM access errors; not fixable: PINS was not read from cardBIOS.\n"));
178 		return B_ERROR;
179 	}
180 
181 	/* OK. We might have a problem, try to fix it now.. */
182 	LOG(4,("INIT: RAM access errors; tuning CAS latency if prudent...\n"));
183 
184 	switch(si->ps.card_type)
185 	{
186 	case G100:
187 			if (!si->ps.sdram)
188 			{
189 				LOG(4,("INIT: G100 SGRAM CAS tuning not permitted, aborting.\n"));
190 				return B_OK;
191 			}
192 			/* SDRAM card */
193 			for (latency = 4; latency >= 2; latency-- )
194 			{
195 				/* MCTLWTST is a write-only register! */
196 				ACCW(MCTLWTST, ((si->ps.mctlwtst_reg & 0xfffffffc) | (latency - 2)));
197 				result = test_ram();
198 				if (result == B_OK) break;
199 			}
200 			break;
201 	case G200:
202 			/* fixme: implement this */
203 			LOG(4,("INIT: G200 RAM CAS tuning not implemented, aborting.\n"));
204 			return B_OK;
205 			break;
206 	case G400:
207 	case G400MAX:
208 			/* fixme: implement this if needed */
209 			LOG(4,("INIT: G400/G400MAX RAM CAS tuning not implemented, aborting.\n"));
210 			return B_OK;
211 			break;
212 	case G450:
213 	case G550:
214 			/* fixme: implement this if needed */
215 			LOG(4,("INIT: G450/G550 RAM CAS tuning not implemented, aborting.\n"));
216 			return B_OK;
217 			break;
218 	default:
219 			/* fixme: Millenium2 and others if needed */
220 			LOG(4,("INIT: RAM CAS tuning not implemented for this card, aborting.\n"));
221 			return B_OK;
222 			break;
223 	}
224 	if (result == B_OK)
225 		LOG(4,("INIT: RAM access OK. CAS latency set to %d cycles.\n", latency));
226 	else
227 		LOG(4,("INIT: RAM access not fixable. CAS latency set to %d cycles.\n", latency));
228 
229 	return result;
230 }
231 
232 static
233 status_t mil_general_powerup()
234 {
235 	status_t result;
236 
237 	LOG(4, ("INIT: Millenium I/II powerup\n"));
238 	if (si->settings.logmask & 0x80000000) mga_dump_configuration_space();
239 
240 	/* initialize the shared_info PINS struct */
241 	result = parse_pins();
242 	if (result != B_OK) fake_pins();
243 
244 	/* log the PINS struct settings */
245 	dump_pins();
246 
247 //remove this:
248 	fake_pins();
249 	LOG(2, ("INIT: Using faked PINS for now:\n"));
250 	dump_pins();
251 //end remove this.
252 
253 	/* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */
254 //restore this line:
255 //	if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics();
256 
257 	//set to powergraphics etc.
258 	LOG(2, ("INIT: Skipping card coldstart!\n"));
259 	mil2_dac_init();
260 
261 //ok:
262 	/* disable overscan, select 0 IRE, select straight-through sync signals from CRTC */
263 	DXIW (GENCTRL, (DXIR (GENCTRL) & 0x0c));
264 	/* fixme: checkout if we need this sync inverting stuff: already done via CRTC!?!
265 		| (vsync_pos?  0x00:0x02)
266 		| (hsync_pos?  0x00:0x01)); */
267 
268 	/* 8-bit DAC, enable DAC */
269 	DXIW(MISCCTRL, 0x0c);
270 //
271 
272 	VGAW_I(SEQ,1,0x00);
273 	/*enable screen*/
274 
275 	return B_OK;
276 }
277 
278 static
279 status_t g100_general_powerup()
280 {
281 	status_t result;
282 
283 	LOG(4, ("INIT: G100 powerup\n"));
284 	if (si->settings.logmask & 0x80000000) mga_dump_configuration_space();
285 
286 	/* initialize the shared_info PINS struct */
287 	result = parse_pins();
288 	if (result != B_OK) fake_pins();
289 
290 	/* log the PINS struct settings */
291 	dump_pins();
292 
293 	/* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */
294 	if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics();
295 
296 	/*power up the PLLs,LUT,DAC*/
297 	LOG(2,("INIT: PLL/LUT/DAC powerup\n"));
298 	/* turn off both displays and the hardcursor (also disables transfers) */
299 	gx00_crtc_dpms(false, false, false);
300 	gx00_crtc_cursor_hide();
301 	/* G100 SGRAM and SDRAM use external pix and dac refs, do *not* activate internals!
302 	 * (this would create electrical shortcuts,
303 	 * resulting in extra chip heat and distortions visible on screen */
304 	/* set voltage reference - using DAC reference block partly */
305 	DXIW(VREFCTRL,0x03);
306 	/* wait for 100ms for voltage reference to stabilize */
307 	delay(100000);
308 	/* power up the SYSPLL */
309 	CFGW(OPTION,CFGR(OPTION)|0x20);
310 	/* power up the PIXPLL */
311 	DXIW(PIXCLKCTRL,0x08);
312 
313 	/* disable pixelclock oscillations before switching on CLUT */
314 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04));
315 	/* disable 15bit mode CLUT-overlay function */
316 	DXIW(GENCTRL, DXIR(GENCTRL & 0xfd));
317 	/* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */
318 	DXIW(MISCCTRL,0x1b);
319 	snooze(250);
320 	/* re-enable pixelclock oscillations */
321 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb));
322 
323 	/* setup i2c bus */
324 	i2c_init();
325 
326 	/*make sure card is in powergraphics mode*/
327 	VGAW_I(CRTCEXT,3,0x80);
328 
329 	/*set the system clocks to powergraphics speed*/
330 	LOG(2,("INIT: Setting system PLL to powergraphics speeds\n"));
331 	g100_dac_set_sys_pll();
332 
333 	/* 'official' RAM initialisation */
334 	LOG(2,("INIT: RAM init\n"));
335 	/* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */
336 	ACCW(PLNWT,0x00000000);
337 	ACCW(PLNWT,0xffffffff);
338 	/* program memory control waitstates */
339 	ACCW(MCTLWTST,si->ps.mctlwtst_reg);
340 	/* set memory configuration including:
341 	 * - no split framebuffer.
342 	 * - Mark says b14 (G200) should be done also though not defined for G100 in spec,
343 	 * - b3 v3_mem_type was included by Mark for memconfig setup: but looks like not defined */
344 	CFGW(OPTION,(CFGR(OPTION)&0xFFFF8FFF) | ((si->ps.v3_mem_type & 0x04) << 10));
345 	/* set memory buffer type:
346 	 * - Mark says: if((v3_mem_type & 0x03) == 0x03) then do not or-in bits in option2;
347 	 *   but looks like v3_mem_type b1 is not defined,
348 	 * - Mark also says: place v3_mem_type b1 in option2 bit13 (if not 0x03) but b13 = reserved. */
349 	CFGW(OPTION2,(CFGR(OPTION2)&0xFFFFCFFF)|((si->ps.v3_mem_type & 0x01) << 12));
350 	/* set RAM read tap delay */
351 	CFGW(OPTION2,(CFGR(OPTION2)&0xFFFFFFF0) | ((si->ps.v3_mem_type & 0xf0) >> 4));
352 	/* wait 200uS minimum */
353 	snooze(250);
354 
355 	/* reset memory (MACCESS is a write only register!) */
356 	ACCW(MACCESS, 0x00000000);
357 	/* select JEDEC reset method */
358 	ACCW(MACCESS, 0x00004000);
359 	/* perform actual RAM reset */
360 	ACCW(MACCESS, 0x0000c000);
361 	snooze(250);
362 	/* start memory refresh */
363 	CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000));
364 	/* set memory control waitstate again AFTER the RAM reset */
365 	ACCW(MCTLWTST,si->ps.mctlwtst_reg);
366 	/* end 'official' RAM initialisation. */
367 
368 	/* Bus parameters: enable retries, use advanced read */
369 	CFGW(OPTION,(CFGR(OPTION)|(1<<22)|(0<<29)));
370 
371 	/*enable writing to crtc registers*/
372 	VGAW_I(CRTC,0x11,0);
373 
374 	return B_OK;
375 }
376 
377 static
378 status_t g200_general_powerup()
379 {
380 	status_t result;
381 
382 	LOG(4, ("INIT: G200 powerup\n"));
383 	if (si->settings.logmask & 0x80000000) mga_dump_configuration_space();
384 
385 	/* initialize the shared_info PINS struct */
386 	result = parse_pins();
387 	if (result != B_OK) fake_pins();
388 
389 	/* log the PINS struct settings */
390 	dump_pins();
391 
392 	/* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */
393 	if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics();
394 
395 	/*power up the PLLs,LUT,DAC*/
396 	LOG(2,("INIT: PLL/LUT/DAC powerup\n"));
397 	/* turn off both displays and the hardcursor (also disables transfers) */
398 	gx00_crtc_dpms(false, false, false);
399 	gx00_crtc_cursor_hide();
400 	/* G200 SGRAM and SDRAM use external pix and dac refs, do *not* activate internals!
401 	 * (this would create electrical shortcuts,
402 	 * resulting in extra chip heat and distortions visible on screen */
403 	/* set voltage reference - using DAC reference block partly */
404 	DXIW(VREFCTRL,0x03);
405 	/* wait for 100ms for voltage reference to stabilize */
406 	delay(100000);
407 	/* power up the SYSPLL */
408 	CFGW(OPTION,CFGR(OPTION)|0x20);
409 	/* power up the PIXPLL */
410 	DXIW(PIXCLKCTRL,0x08);
411 
412 	/* disable pixelclock oscillations before switching on CLUT */
413 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04));
414 	/* disable 15bit mode CLUT-overlay function */
415 	DXIW(GENCTRL, DXIR(GENCTRL & 0xfd));
416 	/* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */
417 	DXIW(MISCCTRL,0x1b);
418 	snooze(250);
419 	/* re-enable pixelclock oscillations */
420 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb));
421 
422 	/* setup i2c bus */
423 	i2c_init();
424 
425 	/*make sure card is in powergraphics mode*/
426 	VGAW_I(CRTCEXT,3,0x80);
427 
428 	/*set the system clocks to powergraphics speed*/
429 	LOG(2,("INIT: Setting system PLL to powergraphics speeds\n"));
430 	g200_dac_set_sys_pll();
431 
432 	/* 'official' RAM initialisation */
433 	LOG(2,("INIT: RAM init\n"));
434 	/* disable hardware plane write mask if SDRAM card */
435 	if (si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) & 0xffffbfff));
436 	/* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */
437 	ACCW(PLNWT,0x00000000);
438 	ACCW(PLNWT,0xffffffff);
439 	/* program memory control waitstates */
440 	ACCW(MCTLWTST,si->ps.mctlwtst_reg);
441 	/* set memory configuration including:
442 	 * - SDRAM / SGRAM special functions select. */
443 	CFGW(OPTION,(CFGR(OPTION)&0xFFFF83FF) | ((si->ps.v3_mem_type & 0x07) << 10));
444 	if (!si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) | (0x01 << 14)));
445 	/* set memory buffer type */
446 	CFGW(OPTION2,(CFGR(OPTION2)&0xFFFFCFFF)|((si->ps.v3_option2_reg & 0x03) << 12));
447 	/* set mode register opcode and streamer flow control */
448 	ACCW(MEMRDBK,(ACCR(MEMRDBK)&0x0000FFFF)|(si->ps.memrdbk_reg & 0xffff0000));
449 	/* set RAM read tap delays */
450 	ACCW(MEMRDBK,(ACCR(MEMRDBK)&0xFFFF0000)|(si->ps.memrdbk_reg & 0x0000ffff));
451 	/* wait 200uS minimum */
452 	snooze(250);
453 
454 	/* reset memory (MACCESS is a write only register!) */
455 	ACCW(MACCESS, 0x00000000);
456 	/* perform actual RAM reset */
457 	ACCW(MACCESS, 0x00008000);
458 	snooze(250);
459 	/* start memory refresh */
460 	CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000));
461 	/* set memory control waitstate again AFTER the RAM reset */
462 	ACCW(MCTLWTST,si->ps.mctlwtst_reg);
463 	/* end 'official' RAM initialisation. */
464 
465 	/* Bus parameters: enable retries, use advanced read */
466 	CFGW(OPTION,(CFGR(OPTION)|(1<<22)|(0<<29)));
467 
468 	/*enable writing to crtc registers*/
469 	VGAW_I(CRTC,0x11,0);
470 
471 	return B_OK;
472 }
473 
474 static
475 status_t g400_general_powerup()
476 {
477 	status_t result;
478 
479 	LOG(4, ("INIT: G400/G400MAX powerup\n"));
480 	if (si->settings.logmask & 0x80000000) mga_dump_configuration_space();
481 
482 	/* initialize the shared_info PINS struct */
483 	result = parse_pins();
484 	if (result != B_OK) fake_pins();
485 
486 	/* log the PINS struct settings */
487 	dump_pins();
488 
489 	/* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */
490 	if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics();
491 
492 	/* reset MAVEN so we know the sync polarity is at reset situation (Hpos, Vpos) */
493 	if (si->ps.secondary_tvout)
494 	{
495 		ACCW(RST, 0x00000002);
496 		snooze(1000);
497 		ACCW(RST, 0x00000000);
498 	}
499 
500 	/*power up the PLLs,LUT,DAC*/
501 	LOG(4,("INIT: PLL/LUT/DAC powerup\n"));
502 	/* turn off both displays and the hardcursor (also disables transfers) */
503 	gx00_crtc_dpms(false, false, false);
504 	g400_crtc2_dpms(false, false, false);
505 	gx00_crtc_cursor_hide();
506 
507 	/* set voltage reference - not using DAC reference block */
508 	DXIW(VREFCTRL,0x00);
509 	/* wait for 100ms for voltage reference to stabilize */
510 	delay(100000);
511 	/* power up the SYSPLL */
512 	CFGW(OPTION,CFGR(OPTION)|0x20);
513 	/* power up the PIXPLL */
514 	DXIW(PIXCLKCTRL,0x08);
515 
516 	/* disable pixelclock oscillations before switching on CLUT */
517 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04));
518 	/* disable 15bit mode CLUT-overlay function */
519 	DXIW(GENCTRL, DXIR(GENCTRL & 0xfd));
520 	/* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */
521 	DXIW(MISCCTRL,0x9b);
522 	snooze(250);
523 	/* re-enable pixelclock oscillations */
524 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb));
525 
526 	DXIW(MAFCDEL,0x02);                 /*makes CRTC2 stable! Matrox specify 8, but use 4 - grrrr!*/
527 	DXIW(PANELMODE,0x00);               /*eclipse panellink*/
528 
529 	/* setup i2c bus */
530 	i2c_init();
531 
532 	/* make sure card is in powergraphics mode */
533 	VGAW_I(CRTCEXT,3,0x80);
534 
535 	/* set the system clocks to powergraphics speed */
536 	LOG(2,("INIT: Setting system PLL to powergraphics speeds\n"));
537 	g400_dac_set_sys_pll();
538 
539 	/* 'official' RAM initialisation */
540 	LOG(2,("INIT: RAM init\n"));
541 	/* disable hardware plane write mask if SDRAM card */
542 	if (si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) & 0xffffbfff));
543 	/* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */
544 	ACCW(PLNWT,0x00000000);
545 	ACCW(PLNWT,0xffffffff);
546 	/* program memory control waitstates */
547 	ACCW(MCTLWTST, si->ps.mctlwtst_reg);
548 	/* set memory configuration including:
549 	 * - SDRAM / SGRAM special functions select. */
550 	CFGW(OPTION,(CFGR(OPTION)&0xFFFF83FF) | (si->ps.option_reg & 0x00001c00));
551 	if (!si->ps.sdram) CFGW(OPTION,(CFGR(OPTION) | (0x01 << 14)));
552 	/* set mode register opcode and streamer flow control */
553 	ACCW(MEMRDBK,(ACCR(MEMRDBK)&0x0000FFFF)|(si->ps.memrdbk_reg & 0xffff0000));
554 	/* set RAM read tap delays */
555 	ACCW(MEMRDBK,(ACCR(MEMRDBK)&0xFFFF0000)|(si->ps.memrdbk_reg & 0x0000ffff));
556 	/* wait 200uS minimum */
557 	snooze(250);
558 
559 	/* reset memory (MACCESS is a write only register!) */
560 	ACCW(MACCESS, 0x00000000);
561 	/* perform actual RAM reset */
562 	ACCW(MACCESS, 0x00008000);
563 	snooze(250);
564 	/* start memory refresh */
565 	CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000));
566 	/* set memory control waitstate again AFTER the RAM reset */
567 	ACCW(MCTLWTST,si->ps.mctlwtst_reg);
568 	/* end 'official' RAM initialisation. */
569 
570 	/* 'advance read' busparameter and 'memory priority' enable/disable setup */
571 	CFGW(OPTION, ((CFGR(OPTION) & 0xefbfffff) | (si->ps.option_reg & 0x10400000)));
572 
573 	/*enable writing to crtc registers*/
574 	VGAW_I(CRTC,0x11,0);
575 	if (si->ps.secondary_head)
576 	{
577 		MAVW(LOCK,0x01);
578 		CR2W(DATACTL,0x00000000);
579 	}
580 
581 	return B_OK;
582 }
583 
584 static
585 status_t g450_general_powerup()
586 {
587 	status_t result;
588 	uint32 pwr_cas[] = {0, 1, 5, 6, 7, 5, 2, 3};
589 
590 	/* used for convenience: MACCESS is a write only register! */
591 	uint32 maccess = 0x00000000;
592 
593 	LOG(4, ("INIT: G450/G550 powerup\n"));
594 	if (si->settings.logmask & 0x80000000) mga_dump_configuration_space();
595 
596 	/* initialize the shared_info PINS struct */
597 	result = parse_pins();
598 	if (result != B_OK) fake_pins();
599 
600 	/* log the PINS struct settings */
601 	dump_pins();
602 
603 	/* check output connector setup */
604 	if (si->ps.primary_dvi && si->ps.secondary_head &&
605 		si->ps.secondary_tvout && (i2c_sec_tv_adapter() != B_OK))
606 	{
607 		/* signal CRTC2 DPMS which connector to program or readout */
608 		si->crossed_conns = true;
609 	}
610 
611 	/* if the user doesn't want a coldstart OR the BIOS pins info could not be found warmstart */
612 	if (si->settings.usebios || (result != B_OK)) return gx00_general_bios_to_powergraphics();
613 
614 	/* power up the PLLs,LUT,DAC */
615 	LOG(4,("INIT: PLL/LUT/DAC powerup\n"));
616 	/* disable outputs */
617 	DXIW(OUTPUTCONN,0x00);
618 	/* turn off both displays and the hardcursor (also disables transfers) */
619 	gx00_crtc_dpms(false, false, false);
620 	g400_crtc2_dpms(false, false, false);
621 	gx00_crtc_cursor_hide();
622 
623 	/* power up everything except DVI electronics (for now) */
624 	DXIW(PWRCTRL,0x1b);
625 	/* set voltage reference - not using DAC reference block */
626 	DXIW(VREFCTRL,0x00);
627 	/* wait for 100ms for voltage reference to stabilize */
628 	delay(100000);
629 	/* power up the SYSPLL */
630 	CFGW(OPTION,CFGR(OPTION)|0x20);
631 	/* power up the PIXPLL */
632 	DXIW(PIXCLKCTRL,0x08);
633 
634 	/* disable pixelclock oscillations before switching on CLUT */
635 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) | 0x04));
636 	/* disable 15bit mode CLUT-overlay function */
637 	DXIW(GENCTRL, DXIR(GENCTRL & 0xfd));
638 	/* CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC */
639 	DXIW(MISCCTRL,0x9b);
640 	snooze(250);
641 
642 	/* re-enable pixelclock oscillations */
643 	DXIW(PIXCLKCTRL, (DXIR(PIXCLKCTRL) & 0xfb));
644 
645 	//fixme:
646 	DXIW(MAFCDEL,0x02);                 /*makes CRTC2 stable! Matrox specify 8, but use 4 - grrrr!*/
647 	DXIW(PANELMODE,0x00);               /*eclipse panellink*/
648 
649 	/* setup i2c bus */
650 	i2c_init();
651 
652 	/* make sure card is in powergraphics mode */
653 	VGAW_I(CRTCEXT,3,0x80);
654 
655 	/* set the system clocks to powergraphics speed */
656 	LOG(2,("INIT: Setting system PLL to powergraphics speeds\n"));
657 	g450_dac_set_sys_pll();
658 
659 	/* 'official' RAM initialisation */
660 	LOG(2,("INIT: RAM init\n"));
661 	/* stop memory refresh, and setup b9, memconfig, b13, sgram planemask function, b21 fields,
662 	 * and don't touch the rest */
663 	CFGW(OPTION, ((CFGR(OPTION) & 0xf8400164) | (si->ps.option_reg & 0x00207e00)));
664 	/* setup b10-b15 unknown field */
665 	CFGW(OPTION2, ((CFGR(OPTION2) & 0xffff0200) | (si->ps.option2_reg & 0x0000fc00)));
666 
667 	/* program memory control waitstates */
668 	ACCW(MCTLWTST, si->ps.mctlwtst_reg);
669 	/* program option4 b0-3 and b29-30 fields, reset the rest: stop memory clock */
670 	CFGW(OPTION4, (si->ps.option4_reg & 0x6000000f));
671 	/* set RAM read tap delays and mode register opcode / streamer flow control */
672 	ACCW(MEMRDBK, si->ps.memrdbk_reg);
673 	/* b7 v5_mem_type = done by Mark Watson. fixme: still confirm! (unknown bits) */
674 	maccess = ((((uint32)si->ps.v5_mem_type) & 0x80) >> 1);
675 	ACCW(MACCESS, maccess);
676 	/* clear b0-1 and 3, and set b31 in option4: re-enable memory clock */
677 	CFGW(OPTION4, ((si->ps.option4_reg & 0x60000004) | 0x80000000));
678 	snooze(250);
679 
680 	/* if DDR RAM */
681 	if ((si->ps.v5_mem_type & 0x0060) == 0x0020)
682 	{
683 		/* if not 'EMRSW RAM-option' available */
684 		if (!(si->ps.v5_mem_type & 0x0100))
685 		{
686 			/* clear unknown bits */
687 			maccess = 0x00000000;
688 			ACCW(MACCESS, maccess);
689 			/* clear b12: unknown bit */
690 			ACCW(MEMRDBK, (si->ps.memrdbk_reg & 0xffffefff));
691 		}
692 		else
693 			/* if not 'DLL RAM-option' available */
694 			if (!(si->ps.v5_mem_type & 0x0200))
695 			{
696 				/* clear b12: unknown bit */
697 				ACCW(MEMRDBK, (si->ps.memrdbk_reg & 0xffffefff));
698 			}
699 	}
700 
701 	/* create positive flank to generate memory reset */
702 	ACCW(MACCESS, (maccess & 0xffff7fff));
703 	ACCW(MACCESS, (maccess | 0x00008000));
704 	snooze(250);
705 
706 	/* start memory refresh */
707 	CFGW(OPTION,(CFGR(OPTION)&0xffe07fff) | (si->ps.option_reg & 0x001f8000));
708 
709 	/* disable plane write mask (needed for SDRAM): actual change needed to get it sent to RAM */
710 	ACCW(PLNWT,0x00000000);
711 	ACCW(PLNWT,0xffffffff);
712 
713 	/* if not 'MEMCASLT RAM-option' available */
714 	if (!(si->ps.v5_mem_type & 0x0400))
715 	{
716 		/* calculate powergraphics CAS-latency from pins CAS-latency, and update register setting */
717 		ACCW(MCTLWTST,
718 			((si->ps.mctlwtst_reg & 0xfffffff8) | pwr_cas[(si->ps.mctlwtst_reg & 0x07)]));
719 
720 	}
721 
722 	/*enable writing to crtc registers*/
723 	VGAW_I(CRTC,0x11,0);
724 	//fixme..
725 	if (si->ps.secondary_head)
726 	{
727 		//MAVW(LOCK,0x01);
728 		CR2W(DATACTL,0x00000000);
729 	}
730 
731 	/* enable primary analog output */
732 	gx50_general_output_select();
733 
734 	/* enable 'straight-through' sync outputs on both analog output connectors and
735 	 * make sure CRTC1 sync outputs are patched through! */
736 	DXIW(SYNCCTRL,0x00);
737 
738 	return B_OK;
739 }
740 
741 status_t gx50_general_output_select()
742 {
743 	/* make sure this call is warranted */
744 	if ((si->ps.card_type != G450) && (si->ps.card_type != G550)) return B_ERROR;
745 
746 	/* choose primary analog outputconnector */
747 	if (si->ps.primary_dvi && si->ps.secondary_head && si->ps.secondary_tvout)
748 	{
749 		if (i2c_sec_tv_adapter() == B_OK)
750 		{
751 			LOG(4,("INIT: secondary TV-adapter detected, using primary connector\n"));
752 			DXIW(OUTPUTCONN,0x01);
753 			/* signal CRTC2 DPMS which connector to program */
754 			si->crossed_conns = false;
755 		}
756 		else
757 		{
758 			LOG(4,("INIT: no secondary TV-adapter detected, using secondary connector\n"));
759 			DXIW(OUTPUTCONN,0x04);
760 			/* signal CRTC2 DPMS which connector to program */
761 			si->crossed_conns = true;
762 		}
763 	}
764 	else
765 	{
766 		LOG(4,("INIT: using primary connector\n"));
767 		DXIW(OUTPUTCONN,0x01);
768 		/* signal CRTC2 DPMS which connector to program */
769 		si->crossed_conns = false;
770 	}
771 	return B_OK;
772 }
773 
774 /*connect CRTC1 to the specified DAC*/
775 status_t gx00_general_dac_select(int dac)
776 {
777 	if (!si->ps.secondary_head)
778 		return B_ERROR;
779 
780 	/*MISCCTRL, clock src,...*/
781 	switch(dac)
782 	{
783 		/* G400 */
784 		case DS_CRTC1DAC_CRTC2MAVEN:
785 			/* connect CRTC1 to pixPLL */
786 			DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x1);
787 			/* connect CRTC2 to vidPLL, connect CRTC1 to internal DAC and
788 			 * enable CRTC2 external video timing reset signal.
789 			 * (Setting for MAVEN 'master mode' TVout signal generation.) */
790 			CR2W(CTL,(CR2R(CTL)&0xffe00779)|0xD0000002);
791 			/* disable CRTC1 external video timing reset signal */
792 			VGAW_I(CRTCEXT,1,(VGAR_I(CRTCEXT,1)&0x77));
793 			/* select CRTC2 RGB24 MAFC mode: connects CRTC2 to MAVEN DAC */
794 			DXIW(MISCCTRL,(DXIR(MISCCTRL)&0x19)|0x82);
795 			break;
796 		case DS_CRTC1MAVEN_CRTC2DAC:
797 			/* connect CRTC1 to vidPLL */
798 			DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x2);
799 			/* connect CRTC2 to pixPLL and internal DAC and
800 			 * disable CRTC2 external video timing reset signal */
801 			CR2W(CTL,(CR2R(CTL)&0x2fe00779)|0x4|(0x1<<20));
802 			/* enable CRTC1 external video timing reset signal.
803 			 * note: this is nolonger used as G450/G550 cannot do TVout on CRTC1 */
804 			VGAW_I(CRTCEXT,1,(VGAR_I(CRTCEXT,1)|0x88));
805 			/* select CRTC1 RGB24 MAFC mode: connects CRTC1 to MAVEN DAC */
806 			DXIW(MISCCTRL,(DXIR(MISCCTRL)&0x19)|0x02);
807 			break;
808 		/* G450/G550 */
809 		case DS_CRTC1CON1_CRTC2CON2:
810 			/* connect CRTC1 to pixPLL */
811 			DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x1);
812 			/* connect CRTC2 to vidPLL, connect CRTC1 to DAC1, disable CRTC2
813 			 * external video timing reset signal, set CRTC2 progressive scan mode
814 			 * and disable TVout mode (b12).
815 			 * (Setting for MAVEN 'slave mode' TVout signal generation.) */
816 			//fixme: enable timing resets if TVout is used in master mode!
817 			//otherwise keep it disabled.
818 			CR2W(CTL,(CR2R(CTL)&0x2de00779)|0x6|(0x0<<20));
819 			/* connect DAC1 to CON1, CRTC2/'DAC2' to CON2 (monitor mode) */
820 			DXIW(OUTPUTCONN,0x09);
821 			/* Select 1.5 Volt MAVEN DAC ref. for monitor mode */
822 			DXIW(GENIOCTRL, DXIR(GENIOCTRL) & ~0x40);
823 			DXIW(GENIODATA, 0x00);
824 			/* signal CRTC2 DPMS which connector to program */
825 			si->crossed_conns = false;
826 			break;
827 		//fixme: toggle PLL's below if possible:
828 		//       otherwise toggle PLL's for G400 2nd case?
829 		case DS_CRTC1CON2_CRTC2CON1:
830 			/* connect CRTC1 to pixPLL */
831 			DXIW(PIXCLKCTRL,(DXIR(PIXCLKCTRL)&0xc)|0x1);
832 			/* connect CRTC2 to vidPLL and DAC1, disable CRTC2 external
833 			 * video timing reset signal, and set CRTC2 progressive scan mode and
834 			 * disable TVout mode (b12). */
835 			CR2W(CTL,(CR2R(CTL)&0x2de00779)|0x6|(0x1<<20));
836 			/* connect DAC1 to CON2 (monitor mode), CRTC2/'DAC2' to CON1 */
837 			DXIW(OUTPUTCONN,0x05);
838 			/* Select 1.5 Volt MAVEN DAC ref. for monitor mode */
839 			DXIW(GENIOCTRL, DXIR(GENIOCTRL) & ~0x40);
840 			DXIW(GENIODATA, 0x00);
841 			/* signal CRTC2 DPMS which connector to program */
842 			si->crossed_conns = true;
843 			break;
844 		default:
845 			return B_ERROR;
846 	}
847 	return B_OK;
848 }
849 
850 /* basic change of card state from VGA to powergraphics -> should work from BIOS init state*/
851 static
852 status_t gx00_general_bios_to_powergraphics()
853 {
854 	LOG(2, ("INIT: Skipping card coldstart!\n"));
855 
856 	//set to powergraphics etc.
857 	CFGW(DEVCTRL,(2|CFGR(DEVCTRL)));
858 	/*enable device response (already enabled here!)*/
859 
860 	VGAW_I(CRTC,0x11,0);
861 	/*allow me to change CRTC*/
862 
863 	VGAW_I(CRTCEXT,3,0x80);
864 	/*use powergraphix (+ trash other bits, they are set later)*/
865 
866 	VGAW(MISCW,0x08);
867 	/*set only MGA pixel clock in MISC - I don't want to map VGA stuff under this OS*/
868 
869 	switch (si->ps.card_type)
870 	{
871 		case G400:
872 		case G400MAX:
873 			/* reset MAVEN so we know the sync polarity is at reset situation (Hpos, Vpos) */
874 			if (si->ps.secondary_tvout)
875 			{
876 				ACCW(RST, 0x00000002);
877 				snooze(1000);
878 				ACCW(RST, 0x00000000);
879 			}
880 			/* makes CRTC2 stable! Matrox specify 8, but use 4 - grrrr! */
881 			DXIW(MAFCDEL,0x02);
882 			break;
883 		case G450:
884 		case G550:
885 			/* power up everything except DVI electronics (for now) */
886 			DXIW(PWRCTRL,0x1b);
887 			/* enable 'straight-through' sync outputs on both analog output
888 			 * connectors and make sure CRTC1 sync outputs are patched through! */
889 			DXIW(SYNCCTRL,0x00);
890 			break;
891 		default:
892 			break;
893 	}
894 
895 	if (si->ps.card_type >= G100)
896 	{
897 		DXIW(MISCCTRL,0x9b);
898 		/*CRTC2->MAFC, 8-bit DAC, CLUT enabled, enable DAC*/
899 
900 		DXIW(MULCTRL,0x4);
901 		/*RGBA direct mode*/
902 	}
903 	else
904 	{
905 		LOG(8, ("INIT: < G100 DAC powerup badly implemented, MISC 0x%02x\n", VGAR(MISCR)));
906 	} // apsed TODO MIL2
907 
908 	VGAW_I(SEQ,1,0x00);
909 	/*enable screen*/
910 
911 	return B_OK;
912 }
913 
914 /* Check if mode virtual_size adheres to the cards _maximum_ contraints, and modify
915  * virtual_size to the nearest valid maximum for the mode on the card if not so.
916  * Then: check if virtual_width adheres to the cards _multiple_ constraints, and
917  * create mode slopspace if not so.
918  * We use acc multiple constraints here if we expect we can use acceleration, because
919  * acc constraints are worse than CRTC constraints.
920  *
921  * Mode slopspace is reflected in fbc->bytes_per_row BTW. */
922 //fixme: seperate heads for real dualhead modes:
923 //CRTC1 and 2 constraints differ!
924 status_t gx00_general_validate_pic_size (display_mode *target, uint32 *bytes_per_row, bool *acc_mode)
925 {
926 	/* Note:
927 	 * This routine assumes that the CRTC memory pitch granularity is 'smaller than',
928 	 * or 'equals' the acceleration engine memory pitch granularity! */
929 
930 	uint32 video_pitch;
931 	uint32 acc_mask, crtc_mask;
932 	uint8 depth = 8;
933 
934 	/* determine pixel multiple based on 2D/3D engine constraints */
935 	switch (si->ps.card_type)
936 	{
937 	case MIL1:
938 	case MIL2:
939 		/* see MIL1/2 specs:
940 		 * these cards always use a 64bit RAMDAC (TVP3026) and interleaved memory */
941 		switch (target->space)
942 		{
943 			case B_CMAP8: acc_mask = 0x7f; depth =  8; break;
944 			case B_RGB15: acc_mask = 0x3f; depth = 16; break;
945 			case B_RGB16: acc_mask = 0x3f; depth = 16; break;
946 			case B_RGB24: acc_mask = 0x7f; depth = 24; break;
947 			case B_RGB32: acc_mask = 0x1f; depth = 32; break;
948 			default:
949 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
950 				return B_ERROR;
951 		}
952 		break;
953 	default:
954 		/* see G100 and up specs:
955 		 * these cards can do 2D as long as multiples of 32 are used.
956 		 * (Note: don't mix this up with adress linearisation!) */
957 		switch (target->space)
958 		{
959 			case B_CMAP8: depth =  8; break;
960 			case B_RGB15: depth = 16; break;
961 			case B_RGB16: depth = 16; break;
962 			case B_RGB24: depth = 24; break;
963 			case B_RGB32: depth = 32; break;
964 			default:
965 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
966 				return B_ERROR;
967 		}
968 		acc_mask = 0x1f;
969 		break;
970 	}
971 
972 	/* determine pixel multiple based on CRTC memory pitch constraints.
973 	 * (Note: Don't mix this up with CRTC timing contraints! Those are
974 	 *        multiples of 8 for horizontal, 1 for vertical timing.) */
975 	switch (si->ps.card_type)
976 	{
977 	case MIL1:
978 	case MIL2:
979 		/* see MIL1/2 specs:
980 		 * these cards always use a 64bit RAMDAC and interleaved memory */
981 		switch (target->space)
982 		{
983 			case B_CMAP8: crtc_mask = 0x7f; break;
984 			case B_RGB15: crtc_mask = 0x3f; break;
985 			case B_RGB16: crtc_mask = 0x3f; break;
986 			/* for B_RGB24 crtc_mask 0x7f is worst case scenario (MIL2 constraint) */
987 			case B_RGB24: crtc_mask = 0x7f; break;
988 			case B_RGB32: crtc_mask = 0x1f; break;
989 			default:
990 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
991 				return B_ERROR;
992 		}
993 		break;
994 	default:
995 		/* see G100 and up specs */
996 		switch (target->space)
997 		{
998 			case B_CMAP8: crtc_mask = 0x0f; break;
999 			case B_RGB15: crtc_mask = 0x07; break;
1000 			case B_RGB16: crtc_mask = 0x07; break;
1001 			case B_RGB24: crtc_mask = 0x0f; break;
1002 			case B_RGB32: crtc_mask = 0x03; break;
1003 			default:
1004 				LOG(8,("INIT: unknown color space: 0x%08x\n", target->space));
1005 				return B_ERROR;
1006 		}
1007 		/* see G400 specs: CRTC2 has different constraints */
1008 		/* Note:
1009 		 * set for RGB and B_YCbCr422 modes. Other modes need larger multiples! */
1010 		if (target->flags & DUALHEAD_BITS)
1011 		{
1012 			switch (target->space)
1013 			{
1014 				case B_RGB16: crtc_mask = 0x1f; break;
1015 				case B_RGB32: crtc_mask = 0x0f; break;
1016 				default:
1017 					LOG(8,("INIT: illegal DH color space: 0x%08x\n", target->space));
1018 					return B_ERROR;
1019 			}
1020 		}
1021 		break;
1022 	}
1023 
1024 	/* check if we can setup this mode with acceleration:
1025 	 * Max sizes need to adhere to both the acceleration engine _and_ the CRTC constraints! */
1026 	*acc_mode = true;
1027 	/* check virtual_width */
1028 	switch (si->ps.card_type)
1029 	{
1030 	case MIL1:
1031 	case MIL2:
1032 	case G100:
1033 		/* acc constraint: */
1034 		if (target->virtual_width > 2048) *acc_mode = false;
1035 		break;
1036 	default:
1037 		/* G200-G550 */
1038 		/* acc constraint: */
1039 		if (target->virtual_width > 4096) *acc_mode = false;
1040 		/* for 32bit mode a lower CRTC1 restriction applies! */
1041 		if ((target->space == B_RGB32_LITTLE) && (target->virtual_width > (4092 & ~acc_mask)))
1042 			*acc_mode = false;
1043 		break;
1044 	}
1045 	/* virtual_height */
1046 	if (target->virtual_height > 2048) *acc_mode = false;
1047 
1048 	/* now check virtual_size based on CRTC constraints,
1049 	 * making sure virtual_width stays within the 'mask' constraint: which is only
1050 	 * nessesary because of an extra constraint in MIL1/2 cards that exists here. */
1051 	{
1052 		/* virtual_width */
1053 		//fixme for CRTC2 (identical on all G400+ cards):
1054 		//16bit mode: max. virtual_width == 16352 (no extra mask needed);
1055 		//32bit mode: max. virtual_width == 8176 (no extra mask needed);
1056 		//other colordepths are unsupported on CRTC2.
1057 		switch(target->space)
1058 		{
1059 		case B_CMAP8:
1060 			if (target->virtual_width > (16368 & ~crtc_mask))
1061 				target->virtual_width = (16368 & ~crtc_mask);
1062 			break;
1063 		case B_RGB15_LITTLE:
1064 		case B_RGB16_LITTLE:
1065 			if (target->virtual_width > (8184 & ~crtc_mask))
1066 				target->virtual_width = (8184 & ~crtc_mask);
1067 			break;
1068 		case B_RGB24_LITTLE:
1069 			if (target->virtual_width > (5456 & ~crtc_mask))
1070 				target->virtual_width = (5456 & ~crtc_mask);
1071 			break;
1072 		case B_RGB32_LITTLE:
1073 			if (target->virtual_width > (4092 & ~crtc_mask))
1074 				target->virtual_width = (4092 & ~crtc_mask);
1075 			break;
1076 		}
1077 
1078 		/* virtual_height: The only constraint here is the cards memory size which is
1079 		 * checked later on in ProposeMode: virtual_height is adjusted then if needed.
1080 		 * 'Limiting here' to the variable size that's at least available (uint16). */
1081 		if (target->virtual_height > 65535) target->virtual_height = 65535;
1082 	}
1083 
1084 	/* OK, now we know that virtual_width is valid, and it's needing no slopspace if
1085 	 * it was confined above, so we can finally calculate safely if we need slopspace
1086 	 * for this mode... */
1087 	if (*acc_mode)
1088 		video_pitch = ((target->virtual_width + acc_mask) & ~acc_mask);
1089 	else
1090 		video_pitch = ((target->virtual_width + crtc_mask) & ~crtc_mask);
1091 
1092 	LOG(2,("INIT: memory pitch will be set to %d pixels for colorspace 0x%08x\n",
1093 														video_pitch, target->space));
1094 	if (target->virtual_width != video_pitch)
1095 		LOG(2,("INIT: effective mode slopspace is %d pixels\n",
1096 											(video_pitch - target->virtual_width)));
1097 
1098 	/* now calculate bytes_per_row for this mode */
1099 	*bytes_per_row = video_pitch * (depth >> 3);
1100 
1101 	return B_OK;
1102 }
1103