md_ind_test.c
3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#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);
}
}