/***
 *
 *  Trade secret of ATI Technologies Inc.
 *  Unpublished work, Copyright 2005 ATI Technologies Inc.
 *
 *  Unpublished work, Copyright 2005 BroadOn Communications Corp..
 *
 *  All rights reserved.  This notice is intended as a precaution against
 *  inadvertent publication and does not imply publication or any waiver
 *  of confidentiality.  The year included in the foregoing notice is the
 *  year of creation of the work.
 *
 ***/

#include <diag.h>
#include <iop.h>
#include <rvldv.h>
#include "initvar.h"


extern void setupAccess();


/* 
 * This is a simple register test of the SHA
 * All registers are read and compared to default values
 */
int shaRegTest()
{
    int err = 0;
    u32 d = 0;
    u32 expected = 0;

    /* Read SHA controller reg: 
       Bits 9:0=0 */
    expected = 0;
    d = busRd32((u32)(SHA_CTRL_REG));
    busPrintf("%s: Reading SHACTRL(0x%08x) = 0x%x\n", __FILE__, SHA_CTRL_REG,d);
    if ((d & 0xFFFFFFC0) != expected) {
        err = 1;
        busPrintf(">>> %s: SHACTRL failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    /* Read/Write/Read SHA read pointer
       Bits: 5:0=0 */
    expected = 0;
    d = busRd32((u32)(SHA_RPTR_REG));
    busPrintf("%s: Reading SHARPTR(0x%08x) = 0x%x\n", __FILE__, SHA_RPTR_REG,d);
    if ((d & 0x0000003F) != expected) {
        err = 1;
        busPrintf(">>> %s: SHARPTR failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }
    expected = 0xbabecac0;
    busPrintf("%s: Writing SHARPTR(0x%08x) <- 0x%x\n", __FILE__, 
        SHA_RPTR_REG, expected);
    busWrt32((u32)(SHA_RPTR_REG), expected);
    d = busRd32((u32)(SHA_RPTR_REG));
    if (d != expected) {
        err = 1;
        busPrintf(">>> %s: SHARPTR failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    /* Read/Write/Read SHA result buf0 
       Bits: 3:0=0 */
    expected = 0xbabecafe;
    d = busRd32((u32)(SHA_BUF0_REG));
    busPrintf("%s: Reading SHA_BUF0_REG(0x%08x) = 0x%x\n", __FILE__, 
        SHA_BUF0_REG, d);
    busPrintf("%s: Writing SHA_BUF0_REG(0x%08x) <- 0x%x\n", __FILE__, 
        SHA_BUF0_REG, expected);
    busWrt32((u32)(SHA_BUF0_REG), expected);
    d = busRd32((u32)(SHA_BUF0_REG));
    if (d != expected) {
        err = 1;
        busPrintf(">>> %s: SHABUF0 failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    /* Read/Write/Read SHA result buf1
       Bits: 3:0=0 */
    expected = 0xbabecafe;
    d = busRd32((u32)(SHA_BUF1_REG));
    busPrintf("%s: Reading SHA_BUF1_REG(0x%08x) = 0x%x\n", __FILE__, 
        SHA_BUF1_REG, d);
    busPrintf("%s: Writing SHA_BUF1_REG(0x%08x) <- 0x%x\n", __FILE__, 
        SHA_BUF1_REG, expected);
    busWrt32((u32)(SHA_BUF1_REG), expected);
    d = busRd32((u32)(SHA_BUF1_REG));
    if (d != expected) {
        err = 1;
        busPrintf(">>> %s: SHA.SHABUF1 failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    /* Read/Write/Read SHA result buf2 */
    expected = 0xbabecafe;
    d = busRd32((u32)(SHA_BUF2_REG));
    busPrintf("%s: Reading SHA_BUF2_REG(0x%08x) = 0x%x\n", __FILE__, 
        SHA_BUF2_REG, d);
    busPrintf("%s: Writing SHA_BUF2_REG(0x%08x) <- 0x%x\n", __FILE__, 
        SHA_BUF2_REG, expected );
    busWrt32((u32)(SHA_BUF2_REG), expected);
    d = busRd32((u32)(SHA_BUF2_REG));
    if (d != expected) {
        err = 1;
        busPrintf(">>> %s: SHABUF2 failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    /* Read/Write/Read SHA result buf3 */
    expected = 0xbabecafe;
    d = busRd32((u32)(SHA_BUF3_REG));
    busPrintf("%s: Reading SHA_BUF3_REG(0x%08x) = 0x%x\n", __FILE__, 
        SHA_BUF3_REG, d);
    busPrintf("%s: Writing SHA_BUF3_REG(0x%08x) <- 0x%x\n", __FILE__, 
        SHA_BUF3_REG,  expected);
    busWrt32((u32)(SHA_BUF3_REG), expected);
    d = busRd32((u32)(SHA_BUF3_REG));
    if (d != expected) {
        err = 1;
        busPrintf(">>> %s: SHABUF3 failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    /* Read/Write/Read SHA result buf4 */
    expected = 0xbabecafe;
    d = busRd32((u32)(SHA_BUF4_REG));
    busPrintf("%s: Reading SHA_BUF4_REG(0x%08x) = 0x%x\n", __FILE__, 
        SHA_BUF4_REG, d);
    busPrintf("%s: Writing SHA_BUF4_REG(0x%08x) <- 0x%x\n", __FILE__, 
        SHA_BUF4_REG, expected);
    busWrt32((u32)(SHA_BUF4_REG), expected);
    d = busRd32((u32)(SHA_BUF4_REG));
    if (d != expected) {
        err = 1;
        busPrintf(">>> %s: SHABUF4 failed, got=0x%x exp=0x%x\n", 
                  __FILE__, d, expected);
    }

    return(err);
}


int main()
{
    int err = 0;


    setupAccess();

    err = shaRegTest();

    if (err)
        printf("SHA Reg Test -> FAILED\n");
    else
        printf("SHA Reg Test -> PASSED\n");

    return 0;

}
