md_ind_test.c 3.11 KB
#include "pi_util.h"



int setMdSkAndIntEnable( int sk, int eint )
{
    u32 smd_en, mismr;
    u32 int_en, mintem;

    int_en = eint ? MI_INTR_MASK_SET_MD : MI_INTR_MASK_CLR_MD;
    IO_WRITE(MI_INTR_EMASK_REG, int_en);
    mintem = IO_READ(MI_INTR_EMASK_REG);
    if( ( eint && !(mintem & MI_INTR_MASK_MD)) ||
        (!eint &&  (mintem & MI_INTR_MASK_MD)) ){
        printf("memModIndicators: couldn't %s MI_INTR_MASK_MD:  MI_INTR_EMASK_REG==%08x   ", (eint?"set":"clear"), mintem);
        OUTPUT_TEST_PASSFAIL(FAIL);
        fflush(NULL);
        return FAIL;
    }

    smd_en = sk ? MI_SEC_MODE_MD_TRAP_EN : 0;
    mismr = IO_READ(MI_SEC_MODE_REG);
    IO_WRITE(MI_SEC_MODE_REG, (mismr&(~MI_SEC_MODE_MD_TRAP_EN))|smd_en);
    mismr = IO_READ(MI_SEC_MODE_REG);
    if( ( sk && !(mismr & MI_SEC_MODE_MD_TRAP_EN)) ||
        (!sk &&  (mismr & MI_SEC_MODE_MD_TRAP_EN)) ){
        printf("memModIndicators: couldn't %s MI_SEC_MODE_MD_TRAP_EN %s:  MI_SEC_MODE_REG==%08x:  ", (sk?"set":"clear"), mismr);
        OUTPUT_TEST_PASSFAIL(FAIL);
        fflush(NULL);
        return FAIL;
    }

    return PASS;
}


/*assumes started in secure mode */
void memModIndicators()
{
    typedef struct { int sk; int eint; } skeint;

    skeint testcase[] = { {0,1},{1,0},{1,1},{0,0} };
    int i, sk, eint, ret;
    u32 smd_en, mismr;
    u32 int_en, mintem;

    for(i=0; i < sizeof(testcase)/sizeof(testcase[0]);  ++i) {
        sk   = testcase[i].sk;
        eint = testcase[i].eint;

        if(setMdSkAndIntEnable(sk, eint)!=PASS)
            goto end;

        _TRACE(DSTATUS,fprintf(LogFp,"start remove memory module test, sk==%d, eint=%d\n", sk, eint));
        fflush(NULL);

        /* init to insert state before remove test */
        ret = insertMemModule();
        if(ret==PASS) {
            ret = removeMemModule();
            printf("remove memory module, sk==%d, eint=%d:  ", sk, eint);
            OUTPUT_TEST_PASSFAIL(ret);
            fflush(NULL);
            if(ret!=PASS)
                goto end;
            ret = insertMemModule();
        }

        printf("insert memory module, sk==%d, eint=%d:  ", sk, eint);
        OUTPUT_TEST_PASSFAIL(ret);
        fflush(NULL);
        if(ret!=PASS)
            goto end;

        mintem = IO_READ(MI_INTR_EMASK_REG);
        if( ( eint && !(mintem & MI_INTR_MASK_MD)) ||
            (!eint &&  (mintem & MI_INTR_MASK_MD)) ){
            printf("memModIndicators: expected MI_INTR_MASK_MD %s at end: %08x   ", (eint?"set":"clear"), mintem);
            OUTPUT_TEST_PASSFAIL(FAIL);
            fflush(NULL);
            goto end;
        }
        mismr = IO_READ(MI_SEC_MODE_REG);
        if( ( sk && !(mismr & MI_SEC_MODE_MD_TRAP_EN)) ||
            (!sk &&  (mismr & MI_SEC_MODE_MD_TRAP_EN)) ){
            printf("memModIndicators: expected MI_SEC_MODE_MD_TRAP_EN %s at end:  MI_SEC_MODE_REG==%08x:  ", (sk?"set":"clear"), mismr);
            OUTPUT_TEST_PASSFAIL(FAIL);
            fflush(NULL);
            goto end;
        }
    }
end:
    setMdSkAndIntEnable(0,0);
    if(insertMemModule()!=PASS) {
        printf("insert memory module:  ");
        OUTPUT_TEST_PASSFAIL(FAIL);
        fflush(NULL);
    }
}