#ident "stand/arcs/ide/IP30/field: $Revision: 1.1"
#
# this script is run when diagnostics are run from the prom (key 3)
# It is intended to be used by field engineers: upon ^C, S/he should
#  be able to run sub-scripts (regular_tests & extended_tests).
# NOTE: although some scripts in shell and field have the same name, 
#  they may not test the same functionalities.
# TO DO: pci script for add-on PCI board XXX

#
# Get fe Arg - check in both $1 and $2
#
$fe = 0;
if (($1 == "fe") || ($2 == "fe")) {
	$fe = 1;
}

#
# Get extended Arg - check in both $1 and $2
#	NOTE: "extended" also means more verbosity
#
$extended = 0;
if (($1 == "extended") || ($2 == "extended")) {
	$extended = 1;
}

#
# Allow flag to turn on serial debugging for console=g.
#
if (($1 == "debug") || ($2 == "debug") || ($3 == "debug"))
	ttyprint 1;

# find out of we are MP
$mp = ismp
$slave = slavecpu

#
# This is an ide startup file intended for use in the field by customers
# and Field Engineers.
#
if ($fe || $extended) {
	echo "Report level set to VERBOSE";
	report = 4;
}
else {
	report = 0;
}
fi


#   NOTE: emfail numbers must match the D_FRU_*
#	  numbers in ide/godzilla/include/d_frus.h
#   NOTE: for gfx FRU's, use D_FRU_GFX 
#		D_FRU_PMXX              0x0
#		D_FRU_IP30              0x1
#		D_FRU_FRONT_PLANE       0x2
#		D_FRU_PCI_CARD          0x3
#		D_FRU_MEM               0x4
#		D_FRU_GFX		0x5	XIOslot
#

# Initialize script variables
#   NOTE: At the end of the startup script each variable that is still set
#         to 2 will indicate some tests that haven't been run (like after
#         an error).
init_vars {
	$pmfailed = 2;
	$memfailed = 2;
	$frontfailed = 2;
	$cpufailed = 2;
	$scsifailed = 2;
	$pcifailed = 2;
	$audiofailed = 0;
	
	# gfx
	$impact_0_failed = 2;
	$impact_1_failed = 2;
	$impact_0_used = 0;
	$impact_1_used = 0;
	$repprdram_sync = 1;
	$tram = 0;
	$solid = 0;
}
init_vars

# processor module
pm {
	# initialize the error flag 
	$pmfailed=0;

	$tmp = fpu;
	if ($tmp) {
		if (!$report) {
			emfail 0;
			wait;
			exit;
		}
		$pmfailed=1;
	}
	if ($mp) {
		$tmp = exec -v $slave -f fpu
		if ($tmp) {
			if (!$report) {
				emfail 0;
				wait;
				exit;
			}
			$pmfailed=1;
		}
	}

	$tmp = icache2;
	if ($tmp) {
		if (!$report) {
			emfail 0;
			wait;
			exit;
		}
		$pmfailed=1;
	}
	if ($mp) {
		$tmp = exec -v $slave -f icache2
		if ($tmp) {
			if (!$report) {
				emfail 0;
				wait;
				exit;
			}
			$pmfailed=1;
		}
	}

# XXX broken
#	$tmp = dcache1;
#	if ($tmp) {
#		if (!$report) {
#			emfail 0;
#			wait;
#			exit;
#		}
#		$pmfailed=1;
#	}
#	if ($mp) {
#		$tmp = exec -v $slave -f dcache1;
#		if ($tmp) {
#			if (!$report) {
#				emfail 0;
#				wait;
#				exit;
#			}
#			$pmfailed=1;
#		}
#	}

	$tmp = scache1;
	if ($tmp) {
		if (!$report) {
			emfail 0;
			wait;
			exit;
		}
		$pmfailed=1;
	}
	if ($mp) {
		$tmp = exec -v $slave -f scache1;
		if ($tmp) {
			if (!$report) {
				emfail 0;
				wait;
				exit;
			}
			$pmfailed=1;
		}
	}

	$tmp = tlb;
	if ($tmp) {
		if (!$report) {
			emfail 0;
			wait;
			exit;
		}
		$pmfailed=1;
	}
	if ($mp) {
		$tmp = exec -v $slave -f tlb;
		if ($tmp) {
			if (!$report) {
				emfail 0;
				wait;
				exit;
			}
			$pmfailed=1;
		}
	}
	$tmp = utlb;
	if ($tmp) {
		if (!$report) {
			emfail 0;
			wait;
			exit;
		}
		$pmfailed=1;
	}
	if ($mp) {
		$tmp = exec -v $slave -f utlb;
		if ($tmp) {
			if (!$report) {
				emfail 0;
				wait;
				exit;
			}
			$pmfailed=1;
		}
	}
}
# end of processor module script

# 
# b_pci: this is the pci features off the bridge on IP30, not the add-on PCI
#
b_pci {
        $tmp = pci_sio -p 1 -t abc -b 50;
        if ($tmp) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
	$cpufailed=1;
	}

        $tmp = pci_sio -p 1 -t abc -b 2000;
        if ($tmp) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
	$cpufailed=1;
	}

        if ($tmp) {
        $tmp = pci_sio -p 1 -t abc -b 384000;
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
	$cpufailed=1;
	}

        $tmp = pci_par;
        if ($tmp) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
	$cpufailed=1;
	}
}
# end of b_pci script

# ethernet in IP30: the baseio enet is on the ioc3 on IP30.
# 	There is also an off-board PCI card which can contain ioc3 enet
# 	and also MENET which is a XTALK card with 4 ioc3 enets.
# ethernet needs a loopback plug in place XXX
ethernet {
	# off ioc3 
	wait "install ethernet loopback plug first"
	if (enet) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
}

# serial needs a loopback cable in place XXX
serial {
	# off ioc3 
	wait "install serial loopback cable first"
	if (duart_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
}

# implement XXX
# use pcifailed flag 
pci {
	echo "pci diag not implemented yet"
}

# THE FOLLOWING IS THE STARTUP SCRIPT FOR THE CPU DIAGNOSTICS.
#
# IN ORDER FOR THE SCRIPT TO RUN PROPERLY, THE FOLLOWING MUST BE DONE: XXX
#	1. CONNECT THE TRANSMIT AND RECEIVE PINS ON CHANNEL A AND B OF DUART 0,
#	   CHANNEL B OF DUART 1 (FOR CHANNEL B OF DUART 1, THE REQUEST_TO_SEND
#	   AND CLEAR_TO_SEND PINS MUST ALSO BE CONNECTED).

#
# main logic board
#
# bare bone ip30 script: 
short_ip30 {
	# initialize error flags
	$cpufailed = 0;

	#
	# ASIC's 
	#
	# heart
	if (hr_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# bridge
	if (br_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# ioc3 
	if (ioc3_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# ds1687 RTC
	if (rtc_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# rad
	if (rad_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$audiofailed=1;
	}

	# Test SCSI devices
	$scsifailed = 0;
	$tmp = scsi_test;
	if ($tmp) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$scsifailed=1;
	}
}

ip30 {
# IP30 field script for ip30

	# initialize error flags
	$cpufailed = 0;
	$memfailed = 0;

	#
	# ASIC's 
	#
	# heart
	if (hr_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# bridge
	if (br_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	if (pci_par) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# ioc3 
	if (ioc3_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$cpufailed=1;
	}
	# rad
	if (rad_regs) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$audiofailed=1;
	}

	# Test SCSI devices
	$scsifailed = 0;
	$tmp = scsi_test;
	if ($tmp) {
		if (!$report) {
			emfail 1;
			wait;
			exit;
		}
		$scsifailed=1;
	}
}

#
# memory
#

#wrappers for low memory tests
ldram {
	$tmp = ldram_bkend -- -p --;
	return ($tmp);
}
lkh {
	$tmp = lkh_bkend -- -p --;
	return ($tmp);
}

short_memory {
	# initialize error flags
	$memfailed = 0;

	# Test low local memory (0-16MB)
	$tmp = ldram;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}
	# Kh test
	$tmp = memtest 1;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}
}
# end of short_memory script
memory {
# NOTE: memory is on DIMM's, thus not technically *on* IP30
#	and not using the same emfail number

	# initialize error flags
	$memfailed = 0;

	# Test low local memory (0-16MB)
	$tmp = ldram;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}
	$tmp = lkh;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}

	# Test rest of local memory
	# Kh test
	$tmp = memtest 1;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}

	# Address uniqueness test
	$tmp = memtest 0;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}

	# Butterfly test
	$tmp = memtest 6;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}

	# March Y test
	$tmp = memtest 3;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}

	# Walking Bit Test
	$tmp = memtest 9;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}

	# ECC tests
	$tmp = ecctest;
	if ($tmp) {
		if (!$report) {
			emfail 4;
			wait;
			exit;
		}
		$memfailed=1;
	}
}
# end of memory script


# frontplane (aka backplane); mostly the xbow
frontplane {
	$frontfailed=0;

	$tmp = x_regs;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
			exit;
		}
	$frontfailed=1;
	}

	$tmp = x_acc;
	if ($tmp) {
		if (!$report) {
			emfail 2;
			wait;
		exit;
		}
	$frontfailed=1;
	}

} 
# end of frontplane script 

#
# G F X
#
# GM10  	SI
# GM10/TRAM 	SI + texture
# GM20		SSI
# GM20/TRAM	MXI
#
# from IP30/ip30imp 10-31-96
# TO DO: XXX
#	the lines starting with #XXXX were commented out from IP30/ip30imp
#		as they called mfg-only code; the other commented out lines
#		were already commented out in ip30imp. I kept them in.
#	comment out all the verbosity
#	add emfail calls with appropriate fru numbers 
#		(see above under D_FRU_GFX)
#	remove the "# needed" used only to keep track of what really has
#		to be part of field
# 

delay {
	ide_delay -s 2;
}

# needed
mg_rtfifo_loop {
	$status = mg_setboard;
	if ($status == 0)
		return(1);
	delay; mg_hqfifoinit

	# Data Format tests done through PIO
	$status = mg_rtpio_loop -i 4 -o 0
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 4 -o 1
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 3 -o 2
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 2 -o 0
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 2 -o 1
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 1 -o 0
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 1 -o 1
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 0 -o 0
	if ($status == 1)
		return(1);
	$status = mg_rtpio_loop -i 0 -o 1
	if ($status == 1) 
		return(1);

	$status = mg_setboard
	if ($status == 1)
		return(1);
	delay; mg_hqfifoinit

	$status = mg_rtdma_loop -p 2 ;
	if ($status == 1) 
		return(1);

	return(0);
}

# needed
enabdisp {
	mg_pokexmap -r XMAP_DIB_CTRL0 -d 0x100
}

# needed
allsetup {
     	mg_gfxreset;
	delay;
	delay;
        $status = mg_setboard;
	if ($status == 0)
		return(1);
	delay;
	mg_hqfifoinit
	delay;
	mg_set_0ge;
	delay;
	$status = mg_reset;
	if ($status)
		return(1);
	delay;
	delay;
	resetcons
	if (!mg_gfxconsole) {
		$status = mg_sync_repp
		if ($status)
			return(1);
        	$status = mg_sync_pprdram
		if ($status)
			return(1);
        	mg_xmapinit
		$status = mg_rdram_ccsearch
		if ($status)
			return(1);
        	mg_initppregs
		enabdisp	
		mg0_clear_color
	}
}

# needed
mg_tram_rev_nobuff {
	$status = mg_dma_tram -r -e 1 -p
	if ($status)
		return(1);
	$status = mg_setnumre4s -q
	if ($status == 2) {
		$status = mg_dma_tram -r -e 1 -p -n 1
		return($status)
	}
	return(0);
}

# needed
hq3test {
	if ($report != 0)
		echo "------ Executing HQ4 Test Suite ------"
        $status = mg_setboard;
	if ($status == 0)
		return(1);
	delay; mg_hqfifoinit;
	delay;
	mg_hqfifoinit
	mg_set_0ge

        $status  	= 	mg_hq3;
        if ($status)
                return(1);
        $status = mg_setboard;
	if ($status == 0)
		return(1);
	delay; mg_hqfifoinit;
	delay;
     	$status  	= 	mg_hq3_cp;
     	if ($status)
		return(1);

     	$status  	= 	mg_hq3_converter;
     	if ($status)
		return(1);

        $status  	= 	mg_hq3_cfifo;
        if ($status)
		return(1);

	$status     =  mg_hq4reg;
	if ($status)
		return(1);

	if ($report != 0)
		echo "****** HQ4 Test Suite Execution Completed ******"

	resetcons

	return(0);
}

# needed
dactest {
	if ($report != 0)
		echo "------ Executing DAC Test Suite ------"
        $status 	=	mg_dacreset;
        if ($status)
                return(1);

        $status 	=	mg_dacmodereg;
        if ($status)
                return(1);

        $status 	=	mg_dacreset;
        if ($status)
                return(1);

        $status 	=	mg_dacaddrreg;
	if ($status)
		return(1);

        $status 	=	mg_dacreset;
        if ($status)
                return(1);

        $status 	=	mg_clrpaletteaddrUniq;
        if ($status)
                return(1);

        $status 	=	mg_dacreset;
        if ($status)
                return(1);

        $status 	=	mg_clrpalettewalkbit;
        if ($status)
		return(1);

        $status 	=	mg_dacreset;
        if ($status)
		return(1);

        $status 	=	mg_clrpalettepatrn;
        if ($status)
		return(1);

        $status 	=	mg_dacreset;
        if ($status)
                return(1);

	if ($report != 0)
		echo "****** DAC Test Suite Execution Completed ******"

	return(0);
}

# needed
vc3test {
	if ($report != 0)
		echo "------ Executing VC3 Test Suite ------"

        $status 	=	mg_vc3reset;
        if ($status)
                return(1);

        $status 	=	mg_vc3internalreg;
        if ($status)
		return(1);

        $status 	=	mg_vc3addrsbus;
        if ($status)
                return(1);

        $status 	=	mg_vc3databus;
        if ($status)
		return(1);

        $status 	=	mg_vc3addrsuniq;
        if ($status)
		return(1);

        $status 	=	mg_vc3patrn;
        if ($status)
                return(1);

	if ($report != 0)
		echo "****** VC3 Test Suite Execution Completed ********"

	return(0);
}

# needed
cmaptest {
	if ($report != 0)
		echo "------ Executing CMAP Test Suite ------"
        $status 	=	mg_vc3init -t 0x107;
        if ($status)
		return(1);

        $status 	=	mg_cmaprev;
        if (!$status)
		return(1);

        $status 	=	mg_cmapdatabus 0;
        if ($status)
		return(1);

        $status 	=	mg_cmappatrn -w 0 -f 0 -l 8191;
        if ($status)
		return(1);

        $status 	=	mg_cmapaddrsuniq 0;
        if ($status)
		return(1);

        $status 	=	mg_cmapdatabus 1;
        if ($status)
		return(1);

        $status 	=	mg_cmapaddrsbus 1;
        if ($status)
		return(1);

        $status 	=	mg_cmappatrn -w 1 -f 0 -l 8191;
        if ($status)
		return(1);

        $status 	=	mg_cmapaddrsuniq 1;
        if ($status)
		return(1);

	if ($report != 0)
		echo "****** CMAP Test Suite Execution Completed ******"

	return(0);
}

# needed
mg_dcbdma_tests {
	$status = mg_setboard;
	if ($status == 0)
		return(1);

	delay; mg_hqfifoinit;

	mg_dcbdma 1;
	delay ; delay ; delay;
        $status     =   dactest;
        if ($status) {
   		mg_dcbdma 0;
                return(1);
        }

        $status     =   vc3test;
        if ($status) {
    		mg_dcbdma 0;
                return(1);
        }
 	delay ; delay ; delay;

        $status     =   mg_reset;
        if ($status)
                return(1);
	delay;

	return(0);
}

# needed
bkend {
	$status = mg_setboard;
	if ($status == 0) {
		return(1);
	}
	delay; mg_hqfifoinit;
	if ($report != 0)
		echo "------ Executing Back End Test Suite ------"
        $status 	=	dactest;
        if ($status)
                return(1);

        $status 	=	vc3test;
        if ($status)
                return(1);

        $status 	=	cmaptest;
        if ($status)
                return(1);

        $status 	=	mg_reset; 
        if ($status)
                return(1);
	delay;

	$status = mg_dcbdma_tests;
	if ($status == 1)
       		 return(1);

   	$status     =   mg_reset;
        if ($status)
                return(1);
	delay;

        $status 	=	mg_xmapdcbreg 0;
        if ($status)
                return(1);

        $status 	=	mg_xmapdcbreg 1;
        if ($status)
                return(1);

	$tmp = mg_setnumre4s -q
	if ($tmp == 2) {
		$status         =       mg_xmapdcbreg 2;
        	if ($status)
                	return(1);
		$status         =       mg_xmapdcbreg 3;
        	if ($status)
                	return(1);
	}

        $status 	=	mg_reset; 
        if ($status)
                return(1);
	delay;

     	mg_starttiming;
     	$status 	=	mg_crcwalk;
     	if ($status)
     		return(1);

 	$status		=	mg_vc3init -t 0x139
 	if ($status)
 		return(1);
 	$status 	=	mg_crcwalk;
 	if ($status)
 		return(1);
 	$status 	=	mg_reset; 
 	if ($status)
 		return(1);
 
	mg_stoptiming;
 	$status	=	mg_vc3init -t 0x159
 	if ($status)
 		return(1);
 	mg_starttiming;
 	$status	=	mg_crcwalk;
 	if ($status)
 		return(1);

     	delay;
     	$status = mg_reset;
     	if ($status)
     		return(1);
     	delay;
     	mg_xmapinit;
     	delay; delay; delay; delay;
     
     	$status 	=	mg_vc3cursorposition;
     	if ($status) {
		resetcons;
                return(1);
	}
     	
	resetcons

	if ($report != 0)
		echo "****** Back End Test Suite Execution Completed ******"

	return(0);
}

re4test {
	if ($report != 0)
		echo "------ Executing RE4 Test Suite ------"
	$status 	=	mg_re_status_reg;
	if ($status)
		return(1);

	$status 	=	mg_re_rdwr_regs;
	if ($status)
		return(1);

	$status 	=	mg_re_internal_ram -t0;
	if ($status)
		return(1);

	$status 	=	mg_re_internal_ram -t1;
	if ($status)
		return(1);

	$status 	=	mg_re_internal_ram -t2;
	if ($status)
		return(1);

	$status 	=	mg_re_internal_ram -t3;
	if ($status)
		return(1);

	$status 	=	mg_re_internal_ram -t4;
	if ($status)
		return(1);

	$status 	=	mg_re_internal_ram -t5;
	if ($status)
		return(1);

	if ($report != 0)
		echo "****** RE4 Test Suite Execution Completed  ******"

	return(0);
}

dmatest {
	if ($report != 0)
		echo "------ Executing DMA Test Suite ------"
        $status 	=	mg_host_hqdma;
	if ($status)
		return(1);

        $status 	=	mg_host_hq_cp_dma;
	if ($status)
		return(1);

#	DMA PIO Test
	$status = mg_dma_pp  -r1 -e1 -w1 -d1  -t  -m 0 0 -b 0x240 -y 16 -z 192
	if ($status)
		return(1);

	if ($report != 0)
		echo "****** DMA Test Suite Execution Completed ******"

	return(0);
}

# allows colors to be correct for drawings
drawsetup {
	delay;
	delay;
	delay;
	mg_xmapinit;
}

drawclose {
	delay;
	resetcons;
	delay;
	delay;
}

tex_draw_test {
	if ($report != 0)
		echo "------ Executing tex_draw_test Suite ------"

	drawsetup;
	$status		=	mg_notex_line
	delay;
	if ($status)
		return(1);

	delay;
	$status		=	mg_notex_poly
	delay;
	if ($status)
		return(1);

	delay;
	$status		=	mg_tex_poly 
	delay;
	if ($status)
		return(1);

	delay;
	$status		=	mg_tex_lut4d
	delay;
	if ($status)
		return(1);

	delay;
	$status		=	mg_tex_mddma
	delay
	if ($status)
		return(1);

	drawclose;

	if ($report != 0)
		echo "****** tex_draw_test Suite Execution Completed *******"

	return(0);
}


# needed
repp_test {
	if ($report != 0)
		echo "------ Executing RE-PP Test Suite ------"
	$status = allsetup;
	if ($status)
		return(1);
	resetcons; buffon
	delay; delay; delay;
	drawsetup;
	delay;
	$status		=	mg_z_tri 
	delay;
	if ($status)
		return(1);

	delay; delay; delay;
	$status		=	mg_lines 
	delay;
        if ($status)
                return(1);

	delay;
	$status		=	mg_points 
	delay;
	if ($status)
                return(1);

	delay;
	$status		=	mg_stip_tri  
	delay;
        if ($status)
                return(1);

	delay;
	$status		=	mg_xblock 
	delay;
        if ($status)
                return(1);

	delay;
	$status		=	mg_chars 
	delay;
        if ($status)
                return(1);

	delay;
	$status		=	mg_logicop 
	delay;
        if ($status)
                return(1);

	delay;
	$status		=	mg_dither 
	delay;
        if ($status)
                return(1);

	delay;
	$status		=	mg_color_tri  
	delay;
        if ($status)
                return(1);

 	delay
 	drawclose;

	if ($report != 0)
		echo "****** RE/PP Test Suite Execution Completed ******"

	return(0);
}

rdram_mem_quick {
	if ($report != 0)
        	echo "------ Executing FRAME BUFFER QUICK Test Suite ------"

        drawsetup
        $status = mg_dma_pp -r0 -e0 -w0 -d0 -b 0x240 -p0 -x 0 -y 4 -z 12 -m 0 0
	if ($status)
		return(1);
	return(0);
}

rdram_mem {
	if ($report != 0)
        	echo "------ Executing FRAME BUFFER Test Suite ------"

#       Z Buffer Test
	drawsetup
        $status = mg_dma_pp  -r0 -e0 -w0 -d0 -b 0x0 -p3 -x 0x0
	if ($status)
		return(1);

#       Color Buffer Test
        $status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x240 -p3 -x 0x0
	if ($status)
		return(1);

#	Overlay Buffer Test
        $status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x1c0 -p3 -x 0x0
	if ($status)
		return(1);

 	$tmp = mg_setnumre4s -q
 	if ($tmp == 2) {
# 		Display Buffer-CD Test
         	$status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x320 -p3 -x 0x0
         	if ($status)
 			return(1);
#		ACC36 or AUX 0 Buffer
        	$status = mg_dma_pp  -r0 -e0 -w0 -d0  -b 0x0e0 -p3 -x 0x0
        	if ($status)
			return(1);
	}
		
	if ($report != 0)
        	echo "****** FRAME BUFFER Test Suite Execution Completed ******"

	return(0);
}


# needed
tram_mem {
	mg0_clear_color; ide_delay -s 2 ;
	delay;
	if ($report != 0)
        	echo "------ Executing TRAM Memory Test Suite ------"
	delay
	$status = mg_tram_rev_nobuff
	if ($status) {
		echo "mg_tram_rev_nobuff failed"
		return(1);
	}
	delay;
	$status         =       mg_dma_tram -m 3 -e 0
	if ($status)
		return(1);
	delay
	$status = mg_setnumre4s -q
	delay
	if ($status == 2) {
  		$status         =       mg_dma_tram -m 3 -e 0 -n 1
		if ($status)
			return(1);
	}

	return(0);
}

# needed
re4flextest {
	$status	= mg_hq3 4
        if ($status)
		return(1);
	resetcons
	return(0);
}

# separate from mg_test_all to test tmezz install independently.
mg_test_tram {
	allsetup;
	$status = tram_mem;
	if ($status) {
		echo "tram test FAILED"
		return(1);
	}
	$status = tex_draw_test;
	if ($status) {
		echo "tex_draw test FAILED"
		return(1);
	}

	return(0);
}

# must have already set the board-up.
mg_test_all {
	$status = mg_setboard;
	if ($status == 0)
		return(1);
	mg_hqfifoinit;
	ide_delay -s 6;
	buffon
	$status = mg_reset;
	if ($status) {
		resetcons; buffoff;
		return(1);
	}

	delay;
	delay;
	$status	= hq3test;
	if ($status) {
		echo "HQ test FAILED"
		resetcons; buffoff;
		return($status);
	}

	delay;
	delay;

# XXX this test fails sometimes on MXI 1/24/97
#	$status = mg_rtfifo_loop;
#	if ($status) {
#		echo "RT FIFO Test FAILED"
#		resetcons; buffoff;
#		return($status);
#	}

	resetcons

	$status	= re4flextest;
	if ($status) {
		echo "Flex Test FAILED"
		resetcons; buffoff;
		return($status);
	}
	
	resetcons;
	$status = mg_reset;
	if ($status) {
		buffoff;
		return(1);
	}
	delay;
	delay;
	resetcons;

	$status = bkend;
	if ($status) {
		echo "bkend FAILED" 
		resetcons; buffoff;
		return($status);
	}

	resetcons

	$status = mg_reset;
	if ($status) {
		resetcons; buffoff;
		return(1);
	}

#	GE11 tests not in field IDE.  Could be added from ip30imp.
	
	delay; delay; delay; delay;

	$status = allsetup;
	if ($status) {
		echo "allsetup FAILED"
		resetcons; buffoff;
		return(1);
	}

	$status	= re4test;
	if ($status) {
		echo "re4test FAILED"
		resetcons; buffoff;
		return(1);
	}

	$status = dmatest;
	if ($status) {
		echo "dmatest FAILED"
		resetcons; buffoff;
		return($status);
	}

	resetcons

	$status	= rdram_mem_quick;
	if ($status) {
		echo "RDRAM QUICK FAILED"
		resetcons; buffoff;
		return($status);
	}

	resetcons
	delay; delay; delay; delay; delay;
	delay; delay; delay; delay; delay;

	$status	= repp_test;
	if ($status) {
		echo "repp_test FAILED"
		resetcons; buffoff;
		return($status);
	}

	delay; delay; delay; delay; delay;
	delay; delay; delay; delay; delay;
	resetcons

	$solid = mg_issolid;
	if ($solid == 0) {
		echo "Testing TMEZZ option card."
		$status = mg_test_tram;
		if ($status) {
			echo "ERROR: Failure detected on TMEZZ board"
			resetcons; buffoff;
			return(1);
		}
		echo "TMEZZ board test PASSED"	
	}

	delay;
	delay;
	resetcons; buffoff;

	echo ""
	echo "All graphics tests have passed"

	return(0);
}

# Assumes only 2 heads
gfx {
	$is_odsy = xtalk_nic_probe;
	if ($is_odsy == 49171) { # 0xc013
		echo "\nDiagnostics for Odyssey graphics boards are Unix-based"
		return (0);
	}
	if ($is_odsy == 49155) { # 0xc003	
	$impact_0_used = 0;
	$impact_1_used = 0;

	$status = mg_setport 9;
	if ($status == 1) {
		echo "Testing Graphics in XIO slot 9";
		$result=0;

		if ($impact_0_used == 0)
			$impact_0_failed = 2;
		else
			$impact_1_failed = 2;

		$status = mg_test_all
		if ($status == 1) {
			$result=1;
			if (!$report) {
				emfail 5 9;
				wait;
				exit;
			}
			else
		echo "ERROR: Failure detected on Graphics in XIO slot 9"
		}
		if ($impact_0_used == 0) {
			$impact_0_failed = $result;
			$impact_0_used = 1;
		}
		else {
			$impact_1_failed = $result;
			$impact_1_used = 1;
		}
	}

	$status = mg_setport 10;
	if ($status == 1) {
		echo "Testing Graphics in XIO slot 10";
		$result=0;

		if ($impact_0_used == 0)
			$impact_0_failed = 2;
		else
			$impact_1_failed = 2;

		$status = mg_test_all
		if ($status == 1) {
			$result=1;
			if (!$report) {
				emfail 5 10;
				wait;
				exit;
			}
			else
		echo "ERROR: Failure detected on Graphics in XIO slot 10"
		}
		if ($impact_0_used == 0) {
			$impact_0_failed = $result;
			$impact_0_used = 1;
		}
		else {
			$impact_1_failed = $result;
			$impact_1_used = 1;
		}
	}

	$status = mg_setport 11;
	if ($status == 1) {
		echo "Testing Graphics in XIO slot 11";
		$result=0;

		if ($impact_0_used == 0)
			$impact_0_failed = 2;
		else
			$impact_1_failed = 2;

		mg_test_all
		if ($status == 1) {
			$result=1;
			if (!$report) {
				emfail 5 11;
				wait;
				exit;
			}
			else
		echo "ERROR: Failure detected on Graphics in XIO slot 11"
		}
		if ($impact_0_used == 0) {
			$impact_0_failed = $result;
			$impact_0_used = 1;
		}
		else {
			$impact_1_failed = $result;
			$impact_1_used = 1;
		}
	}

	$status = mg_setport 12;
	if ($status == 1) {
		echo "Testing Graphics in XIO slot 12";
		$result=0;

		if ($impact_0_used == 0)
			$impact_0_failed = 2;
		else
			$impact_1_failed = 2;

		mg_test_all
		if ($status == 1) {
			$result=1;
			if (!$report) {
				emfail 5 12;
				wait;
				exit;
			}
			else
		echo "ERROR: Failure detected on Graphics in XIO slot 12"
		}
		if ($impact_0_used == 0) {
			$impact_0_failed = $result;
			$impact_0_used = 1;
		}
		else {
			$impact_1_failed = $result;
			$impact_1_used = 1;
		}
	}

	if ($impact_0_used == 0)
		$impact_0_failed = 0;
	if ($impact_1_used == 0)
		$impact_1_failed = 0;
	}
	else {
		echo "\nNo graphics boards detected"
		return(0);
	}
}

tmezz {
	$solid = mg_issolid;
	if ($solid == 0) {
		buffon;
		$status = mg_test_tram;
		resetcons;
		buffoff;
		return($status);
	}

	return(0);
}

#
# end of gfx
#

print_test_results {
echo "TEST RESULTS:";
if ($pmfailed == 1) echo "Failure detected on PMXX board.";
if ($pmfailed == 2) echo "Processor Module tests NOT completed.";
if (!$pmfailed) echo "Processor Module tests completed.";

if ($memfailed == 1) echo "Failure detected on MEMORY.";
if ($memfailed == 2) echo "Memory tests NOT completed.";
if (!$memfailed) echo "Memory tests completed.";

if ($frontfailed == 1) echo "Failure detected on Frontplane board.";
if ($frontfailed == 2) echo "Frontplane tests NOT completed.";
if (!$frontfailed) echo "Frontplane tests completed.";

if ($cpufailed == 1) echo "Failure detected on CPU board.";
if ($cpufailed == 2) echo "CPU tests NOT completed.";
if (!$cpufailed) echo "CPU tests completed.";

if ($audiofailed == 1) echo "Failure detected on audio.";
if ($audiofailed == 2) echo "Audio tests NOT completed.";
if (!$audiofailed) echo "Audio tests completed.";

# if ($pcifailed == 1) echo "Failure detected on PCI device[s].";
# if ($pcifailed == 2) echo "PCI tests NOT completed.";
# if (!$pcifailed) echo "PCI tests completed.";

if ($scsifailed == 1) echo "Failure detected on SCSI device[s].";
if ($scsifailed == 2) echo "SCSI tests NOT completed.";
if (!$scsifailed) echo "SCSI tests completed.";

if ($impact_0_used == 1) {
    if ($impact_0_failed == 1) echo "Failure detected on graphics board 0.";
    if ($impact_0_failed == 2) echo "Graphics board 0 tests NOT completed.";
    if (!$impact_0_failed) echo "Graphics board 0 tests completed.";
}

if ($impact_1_used == 1) {
    if ($impact_1_failed == 1) echo "Failure detected on graphics board 1.";
    if ($impact_1_failed == 2) echo "Graphics board 1 tests NOT completed.";
    if (!$impact_1_failed) echo "Graphics board 1 tests completed.";
}

wait "Diagnostics completed";
}

regular_tests {
	echo "    This test takes approximately 12 minutes on a good"
	echo "    dual processor machine with 128MB memory and MXI graphics."
	echo ""
	init_vars;

	pm;

	short_ip30;

	short_memory;

# 	pci;

	frontplane;

	# same old gfx
	gfx

	print_test_results;
}

extended_tests {
	echo "    The extended tests takes approximately 25 minutes on a good"
	echo "    dual processor machine with 128MB memory and MXI graphics."
	echo ""
	init_vars;

	pm;

	ip30;

	memory;

# 	pci;

	frontplane;

	gfx;

	print_test_results;
}

help_ide {
	# give some help lines similar to those in shell 
	echo ""
	echo "Field included scripts (help_ide to get this again):"
	echo "  ALL:    regular_tests"
	echo "          extended_tests"
	echo "  FRUs:   ip30   frontplane   memory"
	echo "          pm (processor module)"
	echo "          gfx   tmezz"
	echo "  subsystems: serial (loopback)   ethernet (loopback)"
	echo "  useful scripts:	help_ide   help_mem"
	echo ""
}

#
# S T A R T 
#
# Here lies what is actually executed at start-up

hinv;

help_ide;

if ($extended == 1) {
	extended_tests;
}
else {
	regular_tests;
}
fi
