rsp.c 2.31 KB
#include <ultra64.h>
#include <assert.h>
#include <PR/ramrom.h>
#include "gng.h"

#ifdef __sgi__
#include <bstring.h>
#endif
#include <sptask.h>
#include <os_internal.h>
#include "rcp.h"

extern int     __osSpDeviceBusy(void);
extern s32     __osSpRawWriteIo(u32 devAddr, u32 data);
extern s32     __osSpRawReadIo(u32 devAddr, u32 *data);
extern OSIoMesg	dmaIOMessageBuf;
#include "rspcode.c"
extern OSMesgQueue  dmaMessageQ;
extern OSMesg  dummyMessage;
u8 rsp_buf[4096] __attribute__((aligned (16)));

int rsp(void)
{
    u32 data;
    u32 status=0;
    int errCount = 0;
    int noErrCount = 0;
    int j;
    int offset = 0;
    u32 mem_addr;
    char message[256];
    char trapbit=0;
    
    gng_report("    \nRunning SP test ", 1, GNG_INHIBIT_PRINT, 1);
    mem_addr = (u32) rspcodeSegment;
    for (j=0; j<391; j++) {
	offset = *((u64 *) mem_addr);
	
        bcopy((void *)(mem_addr + sizeof(u64)), rsp_buf, 4096);
        osWritebackDCacheAll();
	/* Load DMem */
	while(__osSpRawStartDma((u32) OS_WRITE,
				(u32) SP_DMEM_START,
				rsp_buf,
				(u32) offset) == -1)
	    ;
	while(__osSpDeviceBusy());
	mem_addr += offset + sizeof(u64);

	offset = *((u64 *) mem_addr);
        bcopy((void *) (mem_addr + sizeof(u64)), rsp_buf, 4096);
        osWritebackDCacheAll();
	
	/* Load IMem */
	while(__osSpRawStartDma((u32) OS_WRITE,
				(u32) SP_IMEM_START,
				rsp_buf,
				(u32) SP_UCODE_SIZE) == -1)
	    ;
	while(__osSpDeviceBusy())
	    ;
	mem_addr += offset + sizeof(u64);
	
	/*
	 * Set PC and run
	 */
	__osSpRawWriteIo(0x04080000, 0x00000000);   /* Initialize PC         */
	__osSpRawWriteIo(0x04040010, 0x00000005);   /* Clear break and halt  */
	do { 
	    __osSpRawReadIo(0x04040010, &status);   /* Check break status    */
	} while (!(status & 0x2));
	
	/* Check results in DMem */
	__osSpRawReadIo((0x04000f84), &data);
	
	if ((j==5) && (trapbit==1)) data=0; /* sasano trap */
	
	if (data!=0x0000feed && data!=0xfeed0000) {
	    errCount++;
	    sprintf(message, "RSP diagnostic\nsub-test %d failed\n", j);
	    gng_report(message, 1, GNG_PASS_FAIL_BIT, 0);
            return j;  /* break to reduce damage */
	} else {
	    noErrCount++;
	}
    }

    sprintf(message, "    SP tests Report \n\nTotal number: 392\nFailed:%d   Passed:%d \n\n\n", errCount, noErrCount+1);
    gng_report(message, 1, GNG_INHIBIT_PRINT, 1);
    return(errCount);
}