#########################################################################
#	IP28 Script - Includes PM, CPU, MEM, and GFX TESTS		#
#########################################################################
report=4 # set verbose, but not debug
$stoponerr=1
$oven = 0;
$quick = 0;
$solid = 0;
$gounix = 1;
hinv -v
delay {
	ide_delay -s 2;
}
cv_low {
	echo "Changing Voltage to 4.75V"
	chg_volt 1; 
	repeat 8 {
		delay;
	}
	chg_volt 0; 
	repeat 8 {
		delay;
	}
}
cv_nom {
	echo "Changing Voltage to 5.00V"
	chg_volt 1;
	repeat 8 {
		delay;
	}
}
cv_high {
	echo "Changing Voltage to 5.25V"
	chg_volt 1; 
	repeat 8 {
		delay;
	}
	chg_volt 2;
	repeat 8 {
		delay;
	}
}
unix {
	echo "<<<< About to to boot UNIX......>>>>"
	boot dksc(0,1,0)unix;
}

#########################################################################
#	Processor Module Tests and Scripts				#
#########################################################################
pm {
	echo "PMT5 Processor Module Tests...."
	setenv TEST_NAME_IN_OVEN	_001
	if(tlb) {
		echo "Failure detected in tlb test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_002
	if(utlb) {
		echo "Failure detected in utlb test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_003
	$tmp = dcache1
	if($tmp) {
		echo "Failure detected in dcache1 test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_004
	$tmp = icache1
	if($tmp) {
		echo "Failure detected in icache1 test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_005
	$tmp = icache2
	if($tmp) {
		echo "Failure detected in icache2 test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_006
	if(scache1) {
		echo "Failure detected in scache1 test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_007
	if(hpc3) {
		echo "Failure detected in hpc3 test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_008
	if(fpu) {
		echo "Failure detected in fpu test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_009
	if(ecc) {
		echo "Failure detected in ecc test"
		$failed=1;
		return(-1);
	}
	echo "PMT5 Processor Module Tests Passed...."
}

#########################################################################
#	Memory Tests and Scripts					#
#########################################################################
memory {
	echo "Memory tests...."
	setenv TEST_NAME_IN_OVEN	_100
	$tmp = memtest;
	if ($tmp) {
		echo "Failure detected in memtest test"
		$failed = 1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_101
	$tmp = ldram;
	if ($tmp) {
		echo "Failure detected in ldram test"
		$failed = 1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_102
	$tmp = dram;
	if ($tmp) {
		echo "Failure detected in dram test"
		$failed = 1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_103
	if(lkh_aa) {
		echo "Failure detected in lkh_aa test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_104
	$tmp = memtest 3
	if($tmp) {
		echo "Failure detected in local memory Kh test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_105
	$tmp = memtest 0
	if($tmp) {
		echo "Failure detected in Address Uniqueness test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_106
	$tmp = memtest 7
	if($tmp) {
		echo "Failure detected in Butterfly test test"
		$failed=1;
		return(-1);
	}
	setenv TEST_NAME_IN_OVEN	_107
	$tmp = memtest 9
	if($tmp) {
		echo "Failure detected in March Y test test"
		$failed=1;
		return(-1);
	}
	echo "Memory tests Passed...."
}

#########################################################################
#	Audio Tests and Scripts						#
#########################################################################

#########################################################################
#	MEM, INT and SCSI tests and scripts				#
#########################################################################
ip {
	echo "IP28 interrupt, duart, scsi tests...."
	$tmp = 0;

	setenv TEST_NAME_IN_OVEN	_200
	if(int2) {
		echo "Failure detected in int2 test"
		$failed=1;
		return(-1);
	}
	if ($skip_timer !=1) {
		setenv TEST_NAME_IN_OVEN	_201
		if(clock) {
			echo "Failure detected in clock test"
			$failed=1;
			return(-1);
		}
		setenv TEST_NAME_IN_OVEN	_202
		if(timer) {
			echo "Failure detected in timer test"
			$failed=1;
			return(-1);
		}
	}

	setenv TEST_NAME_IN_OVEN	_203
	$tmp = duart -i1;
	if($tmp) {
		resetcons 1;
		echo "Failure detected in duart test"
		$failed=1;
		return(-1);
	}
	if ($skip_eisa != 1) {
		setenv TEST_NAME_IN_OVEN	_204
		if(eisa) {
			echo "Failure detected in eisa test"
			$failed=1;
			return(-1);
		}
	}
	setenv TEST_NAME_IN_OVEN	_205
	$scsi_status = scsi;
	if($scsi_status) {
		echo "Failure detected in SCSI test"
		$failed=1;
		return(-1);
	}
	echo "IP28 interrupt, duart, scsi tests Passed...."
}	

#########################################################################
#	ALL IP28 (PM/CPU/MEM/AUDIO/SCSI) TESTS and SCRIPTS		#
#########################################################################
ip28 {
	echo "ALL Tests in IP28...."
        $skip_eisa = 0;
	$failed = 0;

	pm;
	if($failed) {
		return(-1);
	} 

	if ($oven) {
		memory;
		if($failed) {
			return(-1);
		} 
	}

	ip;
	if($failed) {
		return(-1);
	} 

	echo "ALL Tests in IP28 Passed...."
}

#########################################################################
#	ALL IP28 (PM/CPU/MEM/AUDIO/SCSI) WITH VOLTAGE CHANGES		#
#########################################################################
ip28va {
	cv_low;
	ip28;
	if ($failed) {
		return(-1);
	}
	cv_high;
	ip28;
	if ($failed) {
		return(-1);
	}
}

#########################################################################
#	GR2 TESTS and SCRIPTS						#
#########################################################################
# Initialize variables used by GR2.
$stride_failed=0 ;
$zb_failed=0 ;
$gr2_failed=0;
$chkbt457_failed=0;
$bp_failed=0;
$shramre3_failed=0;
$cpushram_failed=0;
$cpure3_failed=0;
$ctxsw_failed=0;
$vdma_failed=0;
$quad_failed=0;
$fourquad_failed=0;
$mon=0;

$test_xmap_failed = 0;
$test_xmap_clut_failed = 0;

gr2_vhwinit {
	gr2_videoclk 0x47
	if ($mon ==1 ) gr2_initclock 0x132;
	else gr2_initclock 0x107;
	fi
	gr2_wrconfig 0x0
	gr2_delay 3
	gr2_wrconfig 0x1
	gr2_vinitdac
}

gr2_initre {
	$a = gr2_getGR2ver;
	if ($a < 4) gr2_wrfifo 0 0;
	else if ($a == 4) gr2_wrfifo 0 1;
	else gr2_wrfifo 0 2;
}

gr2_initsys {
	gr2_reset
	gr2_vhwinit
	$mon = gr2_getMonType;
	if ($mon == 1) gr2_initvc1 4;
	else gr2_initvc1 20;
	fi
	gr2_xcol
	gr2_inithq
	gr2_load_ucode ge
	gr2_load_ucode hq
	gr2_unstall
	gr2_initre
}

clear {
	gr2_wrfifo 35 0
	gr2_wrfifo 6 0
}

gr2_quad {
	gr2_wrfifo 33 0
}

gr2_fourquad {
	gr2_wrfifo 34 0
}

test_xmap {
	gr2_initsys;
	$a=gr2_txmap;
	return $a;
}

test_xmap_clut {
	gr2_initsys;
	$a=gr2_txmap_clut;
	return $a;
}

gr2_vdma {
	gr2_initsys;
	$b=gr2_cachefdma 32 1;
	$b=$b+gr2_cachefdma 256 1;
	$b=$b+gr2_cachefdma 512 1;
	$b=$b+gr2_cachefdma 128 1;
	$b=$b+gr2_yzoomdma ;
	$b=$b+gr2_yzoomdma 32 32;
	$b=$b+gr2_yzoomdma 128 128;
	$b=$b+gr2_yzoomdma 256 256;
	$b=$b+gr2_stridedma;
	$b=$b+gr2_stridedma 32 32;
	$b=$b+gr2_stridedma 256 1;
	$b=$b+gr2_stridedma 512 0;

	return $b;
}

gr2 {
# Too verbose with report=4
	report=3;

	$stride_failed=0 ;
	$zb_failed=0 ;
	$gr2_failed=0;
	$chkbt457_failed=0;
	$bp_failed=0;
	$shramre3_failed=0;
	$cpushram_failed=0;
	$cpure3_failed=0;
	$ctxsw_failed=0;
	$vdma_failed=0;
	$quad_failed=0;
	$fourquad_failed=0;

	$test_xmap_failed = 0;
	$test_xmap_clut_failed = 0;

	gr2_reset;
	buffon


# HQ2 internal register 19  must read 0xdeadbeef
	report = 2;
	gr2_rdhqint 19;
	report = 1;

# Test VC1 SRAM 
	gr2_vhwinit
	report =3 
	if (gr2_vc1_sram) {
		echo "VC1 SRAM test failed";
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test ram 0 at Ge7 at 0
	$tmp = gr2_tram 0;
	if ($tmp) {
		echo "GE7 at 0 RAM0 test failed"
		resetcons;
		buffoff;
		$err = 1;
        	wait;
	}
# Test ram 0 at Ge7 at 1
	$tmp = gr2_tram 1;
	if ($tmp) {
		echo "GE7 at 1 RAM0 test failed"
		resetcons;
		buffoff;
		$err = 1;
        	wait;
	}
# Test ram 0 at Ge7 at 2
	$tmp = gr2_tram 2;
	if ($tmp) {
		echo "GE7 at 2 RAM0 test failed"
		resetcons;
		buffoff;
		$err = 1;
        	wait;
	}
# Test ram 0 at Ge7 at 3
	$tmp = gr2_tram 3 ;
	if ($tmp) {
		echo "GE7 at 3 RAM0 test failed"
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test ram 0 at Ge7 at 4
	$tmp = gr2_tram 4 ;
	if ($tmp) {
		echo "GE7 at 4 RAM0 test failed"
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test ram 0 at Ge7 at 5
	$tmp = gr2_tram 5 ;
	if ($tmp) {
		echo "GE7 at 5 RAM0 test failed"
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test ram 0 at Ge7 at 6
	$tmp = gr2_tram 6 ;
	if ($tmp) {
		echo "GE7 at 6 RAM0 test failed"
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test ram 0 at Ge7 at 7
	$tmp = gr2_tram 7 ;
	if ($tmp) {
		echo "GE7 at 7 RAM0 test failed"
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test shram  
	$tmp = gr2_tram 8 ;
	if ($tmp) {
		echo "Share ram test failed "; 
		resetcons;
		buffoff;
        	wait;
		$err = 1;
	}
# Test Hq2uram
	$tmp = gr2_tram 9 ;
	if ($tmp) {
		echo "HQ2 uram test failed "; 
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
# Test ge7uram
	$tmp = gr2_tram 10;
	if ($tmp) {
		echo "GE7 uram test failed "; 
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
	gr2_initsys;
	clear;

# Test HQ2
	if(gr2_hq2test) {
		echo "HQ2 test failed "; 
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
# Test shareram using Ucode
	if (gr2_shram) {
		echo "Shram test failed"
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
# Test internal GE7 ram
	if (gr2_ram12) {
		echo "GE7 internal test failed"
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
# Test seedrom 
	if (gr2_seedrom) {
		echo "GE7 seedrom test failed"
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
# Test the squaroot rom
	if (gr2_sqrom) { 
		echo "GE7 sqrom test failed"
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
	gr2_initsys ;

# Test Ge 7 bus
	if (gr2_gebus) {
		echo "GE7 bus test failed"
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}

# Test ge floating point unit
	if (gr2_gefloat) {
		echo "GE7 floating point test failed"
		resetcons;
		buffoff;
        	wait;
	    	$err = 1;
	}
	gr2_initsys;
	clear;

	if ( $err ) {
		echo "HQ & GE Tests failed\n";
		resetcons;
		buffoff;
		wait;
		$err=0
		$gr2_failed=1
	}
	else {
		resetcons;
		buffoff;
		echo "HQ & GE Tests passed\n"
	}
	buffon

# Test bt457 
	if (gr2_chkbt457) {
		resetcons;
		buffoff;
        	wait;
	    	$chkbt457_failed = 1;
	    	$err=1;
	}
# Test bitplane VM2
	gr2_initsys
	if (gr2_bp) {
		$bp_failed = 1;
		$err=1;
		resetcons;
		buffoff;
	    wait;
	}
# Test Shared ram and Re
	gr2_initsys
	$tmp = gr2_shramre3
	if ($tmp) {
		resetcons;
		buffoff;
        	wait;
	    	$shramre3_failed =1;
	    	$err=1;
	}
# Test DMA between host and GE7 shared ram
	gr2_initsys
	clear
	$tmp = gr2_cpushram
	if ($tmp) {
		resetcons;
		buffoff;
        	wait;
	    	$cpushram_failed =1;
	    	$err=1;
	}
# Test DMA between host and and RE3
	resetcons
	buffon
	gr2_initsys
	$tmp = gr2_cpure3
	if ($tmp) {
		resetcons;
		buffoff;
        	wait;
	    	$cpure3_failed =1;
	    	$err=1;
	}
# Test GE7 context switching
	if(gr2_ctxsw) {
		resetcons;
		buffoff;
        	wait;
	    	$ctxsw_failed =1;
	    	$err=1;
	}
	clear;
# Test quad drawing
	$tmp = gr2_quad
	if ($tmp) {
		resetcons;
		buffoff;
        	wait;
	    	$quad_failed =1;
	    	$err=1;
	}
	$tmp = gr2_fourquad
	if ($tmp){
		resetcons;
		buffoff;
		wait;
	    	$fourquad_failed = 1;
	    	$err=1;
	}
	clear;
	if ($chkbt457_failed) echo "Bt457 test failed";
	if ($bp_failed)  echo "bitplane test failed";
	if ($shramre3_failed) echo "shramre3 test failed"
	if ($cpushram_failed) echo "CPU shram test failed";
	if ($cpure3_failed) echo "cpure3 test failed ";
	if ($ctxsw_failed) echo "context switching test failed ";
	if ($vdma_failed) echo "vdma controller test failed ";
	if ($quad_failed) echo "quad test failed";
	if ($fourquad_failed) echo "fourquad test failed";

	if ($err)
	{
	    if (!$report) {
		emfail 2;
		wait;
		exit;
	    }	
	    echo "******  PRESS RETURN TO CONTINUE OR ^C TO EXIT ************"
	    $err=0
	    $gr2_failed=1
	    resetcons;
	    buffoff;
	    wait;
	}
	else {
	    resetcons;
	    buffoff;
	    echo "BT457, Bit-Plane, DMA and QUADs Tests Passed.\n"
	}
	buffon

# Test stridedma between shram and re3
	gr2_initsys
	$tmp = gr2_stride
	if ($tmp)  {
	    $stride_failed =1 ;
	    $err=1;
	    resetcons;
	    buffoff;
	    wait;
	}
# Test Zbuffer
	gr2_initsys
	$tmp=gr2_zb
	if($tmp)  {
	    $zb_failed =1;
	    $err=1;
	    resetcons;
	    buffoff;
	    wait;
	}
	resetcons
	buffoff
	echo "************************* RESULTS ********************************"
	if ($stride_failed)  {
	    echo "stride test failed";
	    $gr2_failed = 1;
	    wait;
	}
	if ($zb_failed) { 
	    echo "Zbuffer test failed";
	    $gr2_failed = 1;
	    wait;
	}
	if (!$gr2_failed) echo "Stride DMA, and Z-Buffer Test Passed.\n"
# Test Xmap 
	buffon
	echo "testing XMAP"
	if (test_xmap) {
	    $test_xmap_failed =1;
	    $err=1;
	    resetcons;
	    buffoff;
	    wait;
	}
#Test Xmap CLUT 
	if (test_xmap_clut) {
	    $test_xmap_clut_failed =1;
	    $err=1;
	    resetcons;
	    buffoff;
	    wait;
	}
	resetcons
	buffoff
	echo "************************* RESULTS ********************************"
	if ($test_xmap_failed) {
	    echo "test_xmap test failed";
	    $gr2_failed = 1;
	}
	if ($test_xmap_clut_failed) {
	    echo "test_xmap_clut test failed";
	    $gr2_failed = 1;
	}
	if (!$err) echo "XMAPs Test Passed.\n"
	if ($gr2_failed) {
		echo "ERROR: Failure detected on graphics board."
		wait;
	}
	else echo "graphics board tests passed"
	fi
	echo " *****************END OF THE TEST *****************"

	# Restore verbosity
	report=4
}

gr2_all {
        $tmp = gr2_setboard 0;
        if ($tmp) {
			
		echo "Testing gr3/gu1 in slot 0."
                gr2;
        	if ($gr2_failed) {
			echo "ERROR: Failure detected on gr3/gu1 in slot 0."
		}
        }

        $tmp = gr2_setboard 1;
        if ($tmp) {
		echo "Testing gr3/gu1 in slot 1."
                gr2;
	        if ($gr2_failed) {
			echo "ERROR: Failure detected on gr3/gu1 in slot 1."
		}
        }
}

gfx {
    $express = gr2_probe;
    if ($express) {
	gr2_all;
    }
    if ($gounix) {
	if ($failed == 0) {
		unix;
	}
    }
} 

gfxva {
    $gounix = 0;
    cv_low;
    gfx;

    $gounix = 1;
    cv_high;
    gfx;
}

gfx_quick {
    $gounix = 0;
    echo "----- Executing the QUICK version of the GFX Tests -----"
    $quick = 1;
    gfx;
    $quick = 0;
    echo "----- QUICK version of the GFX Tests is DONE -----"
}

gfxva_quick {
    $gounix = 0;
    echo "----- Executing the QUICK version of the GFX Tests with Chg Vol.-----"
    $quick = 1;
    gfxva;
    $quick = 0;
    echo "----- QUICK version of the GFX Tests with Change Voltage is DONE -----"
}

#########################################################################
#	IP28 + GFX ASRS OVEN SCRIPT					#
#########################################################################
ip28_gfx_asrs {
	report=2;
	echo "=========================================="
	echo "WELCOME TO IP28 + EXPRESS GFX  ASRS TEST SUITE"
	echo "=========================================="
	cv_low;
	boot -f bootp()voltage_low.pass
	$skip_timer =0;
	$skip_eisa = 1;
	$oven = 1;
	$volts = 0;
	ip28;
	if ($failed) {
		boot -f bootp()IP28_L.failed
	} else {
		unsetenv TEST_NAME_IN_OVEN
		boot -f bootp()IP28_L.passed
	}
	gfx;
	if ($failed) {
		boot -f bootp()GFX_L.failed
	} else {
		unsetenv TEST_NAME_IN_OVEN
		boot -f bootp()GFX_L.passed
	}

	cv_high;
	boot -f bootp()voltage_hi.pass
	$skip_timer =1;
	$volts = 2;
	$skip_eisa = 1;
	ip28;
	if ($failed) {
		boot -f bootp()IP28_H.failed
	} else {
		unsetenv TEST_NAME_IN_OVEN
		boot -f bootp()IP28_H.passed
	}
	gfx;
	if ($failed) {
		boot -f bootp()GFX_H.failed
	} else {
		unsetenv TEST_NAME_IN_OVEN
		boot -f bootp()GFX_H.passed
	}

	cv_nom;
	boot -f bootp()start_unix;
	unix;
}

#########################################################################
#	IP28 + GFX  FUNCTION TEST & REPAIR SCRIPT			#
#########################################################################
i2frmenu {
	echo "==================================================="
	echo "WELCOME TO IP28 + EXPRESS FUNCTION TEST & REPAIR SUITE"
	echo "==================================================="
	echo "Command	Description"
	echo "=======	==========="
	echo "ip28	IP28 tests (PMT5, CPU, MEM)"
	echo "ip28va	IP28 tests with automatic voltage change"
	echo ""
	echo "gfx	EXPRESS GFX tests"
	echo "gfxva	EXPRESS GFX tests with automatic voltage change"
	echo ""
	echo "i2frmenu	To display the above menu"
	echo ""
}
ip28_gfx_func_repair {
	report=2;
	i2frmenu;
}

$suite = gr2_test_suite;
if ($suite == 1) {
	ip28_gfx_asrs;
} else {
	ip28_gfx_func_repair;
}
echo ""

