OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [generic/] [ft/] [sw/] [tests/] [or1200ft/] [sim/] [or1200ft-parity.c] - Blame information for rev 483

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 483 julius
/*
2
 *
3
 * Communicate with the verilog testbench via memory, send commands for it to
4
 * inject errors to I/D cache content RAM and tag RAM, I/D MMU translate and
5
 * match RAMs, and the register file RAM.
6
 *
7
 * On instruction/data cache parity error we should receive an interrupt.
8
 *
9
 * On I/MMU parity error we should get an TLB miss exception, causing a software
10
 * flush before continuing.
11
 *
12
 * On register file parity error we reset via assertion of reset signal to
13
 * OR1200.
14
 *
15
 * To allow some variables to maintain their values between resets, we store
16
 * them in #defined memory locations.
17
 *
18
 * The interrupt and exception vector routines contain important code allowing
19
 * the test to proceed, so if they don't fire (due to parity errors not being
20
 * injected, exercised or detected properly) then the test will repeat itself
21
 * over and over with the same values, and should be stopped by the user and
22
 * investigated.
23
 *
24
 * The ft_state pointer points to the overall state of the test.
25
 *
26
 * Julius Baxter, julius@opencores.org
27
 *
28
 */
29
 
30
 
31
#include "cpu-utils.h"
32
#include "spr-defs.h"
33
#include "printf.h"
34
#include "board.h"
35
 
36
// define to jump to a certain test immediately
37
//#define JUMP_TO_TEST 3
38
 
39
#define FT_MEM 0x4
40
#define FT_GO_COMMAND 0x88000000
41
 
42
#define FT_STIM_CMD_OFF 24
43
 
44
#define FT_STIM_CMD_IC_RAM_FAULT 0x1
45
#define FT_STIM_CMD_IC_TAG_FAULT 0x2
46
#define FT_STIM_CMD_DC_RAM_FAULT 0x3
47
#define FT_STIM_CMD_DC_TAG_FAULT 0x4
48
 
49
#define FT_STIM_CMD_DMMU_MR_FAULT 0x5
50
#define FT_STIM_CMD_DMMU_TR_FAULT 0x6
51
#define FT_STIM_CMD_IMMU_MR_FAULT 0x7
52
#define FT_STIM_CMD_IMMU_TR_FAULT 0x8
53
#define FT_STIM_CMD_RF_FAULT 0x9
54
 
55
#define FT_STIM_CMD_DEBUG_ON (0xff<<FT_STIM_CMD_OFF)
56
#define FT_STIM_CMD_DEBUG_OFF (0xfe<<FT_STIM_CMD_OFF)
57
 
58
 
59
#define FT_STIM_WRITE(x) REG32(FT_MEM)=x
60
#define FT_STIM_WRITE_FAULT_CMD(x,y,z) \
61
  REG32(FT_MEM)=(x<<FT_STIM_CMD_OFF)|(((y)&0xff)<<16)|((z)&0xffff)
62
 
63
#define FT_STIM_WAIT_ACK while(REG32(FT_MEM)!=0)
64
 
65
#define FT_STATE_RECORD_MEM 0x8
66
#define FT_STATE_TEST_STATE1_MEM 0xc
67
#define FT_STATE_TEST_STATE2_MEM 0x10
68
#define FT_STATE_TEST_STATE3_MEM 0x14
69
 
70
#define PAGE_SIZE 8192
71
 
72
extern unsigned long _stack;
73
 
74
void
75
enable_bench_debug(void)
76
{
77
        FT_STIM_WRITE(FT_STIM_CMD_DEBUG_ON);
78
        FT_STIM_WAIT_ACK;
79
}
80
 
81
void
82
disable_bench_debug(void)
83
{
84
        FT_STIM_WRITE(FT_STIM_CMD_DEBUG_OFF);
85
        FT_STIM_WAIT_ACK;
86
}
87
 
88
 
89
void
90
dmmu_tlb_one_to_one_reset(void)
91
{
92
 
93
        int i, j, sets, ways;
94
        unsigned long dmmucfgr;
95
 
96
        // Determine number of TLB sets
97
        dmmucfgr = mfspr(SPR_DMMUCFGR);
98
 
99
        ways = (dmmucfgr & SPR_DMMUCFGR_NTW) + 1;
100
        sets = 1 << ((dmmucfgr & SPR_DMMUCFGR_NTS)>> SPR_DMMUCFGR_NTS_OFF);
101
 
102
 
103
 
104
        // Initialise all match/translate register pairs, set 1-1 mapping
105
        for (i = 0; i < ways; i++)
106
                for (j = 0; j < sets; j++){
107
                        mtspr (SPR_DTLBMR_BASE(i) + j, (j*PAGE_SIZE) |
108
                               SPR_DTLBMR_V);
109
                        mtspr (SPR_DTLBTR_BASE(i) + j, (j*PAGE_SIZE) |
110
                               DTLB_PR_NOLIMIT);
111
                }
112
 
113
        // Set cache inhibit for first page
114
        mtspr (SPR_DTLBTR_BASE(0), 0 | DTLB_PR_NOLIMIT | SPR_DTLBTR_CI);
115
 
116
}
117
 
118
 
119
// If DC is present, init DMMU to disable cache on first page, which we'll
120
// use to communicate to the fault injection testbench.
121
int
122
dmmu_init(void)
123
{
124
 
125
        unsigned long upr;
126
 
127
        // Only do this if DMMU and DC are here
128
 
129
        // Get the unit present register
130
        upr = mfspr(SPR_UPR);
131
        if ((upr & SPR_UPR_DCP) && !(upr & SPR_UPR_DMP))
132
                // Cannot do the test
133
                exit(1);
134
 
135
        if (!(upr & SPR_UPR_DCP))
136
                // No need to config MMU - no data cache
137
                return 1;
138
 
139
        dmmu_tlb_one_to_one_reset();
140
 
141
        /* Enable DMMU */
142
        lo_dmmu_en ();
143
 
144
        return 0;
145
 
146
}
147
 
148
// Initialise iMMU
149
void
150
immu_tlb_one_to_one_reset(void)
151
{
152
 
153
        int i, j, sets, ways;
154
        unsigned long immucfgr;
155
 
156
        // Determine number of TLB sets
157
        immucfgr = mfspr(SPR_IMMUCFGR);
158
 
159
        ways = (immucfgr & SPR_IMMUCFGR_NTW) + 1;
160
        sets = 1 << ((immucfgr & SPR_IMMUCFGR_NTS)>> SPR_IMMUCFGR_NTS_OFF);
161
 
162
        // Initialise all match/translate register pairs, set 1-1 mapping
163
        for (i = 0; i < ways; i++)
164
                for (j = 0; j < sets; j++){
165
                        mtspr (SPR_ITLBMR_BASE(i) + j, (j*PAGE_SIZE) |
166
                               SPR_ITLBMR_V);
167
                        mtspr (SPR_ITLBTR_BASE(i) + j, (j*PAGE_SIZE) |
168
                               ITLB_PR_NOLIMIT);
169
                }
170
}
171
 
172
void
173
test_state_update(void)
174
{
175
        volatile int * test_state1 = (volatile int*)FT_STATE_TEST_STATE1_MEM;
176
        volatile int * test_state2 = (volatile int*)FT_STATE_TEST_STATE2_MEM;
177
        volatile int * test_state3 = (volatile int*)FT_STATE_TEST_STATE3_MEM;
178
        volatile int * ft_state = (volatile int*)FT_STATE_RECORD_MEM;
179
 
180
        // Disable DC here
181
        mtspr(SPR_SR, (mfspr(SPR_SR) & ~SPR_SR_DCE));
182
        // Flush line of test state
183
        mtspr(SPR_DCBIR, (unsigned long) test_state1);
184
 
185
        (*test_state1)++;
186
 
187
        if (*test_state1 == *test_state2)
188
                (*ft_state)++;
189
 
190
}
191
 
192
// Initialise TLB contents and enable iMMU
193
int
194
immu_init(void)
195
{
196
 
197
        int i, j, sets, ways;
198
        unsigned long upr;
199
        unsigned long immucfgr;
200
 
201
        // Only do this if iMMU here
202
 
203
        // Get the unit present register
204
        upr = mfspr(SPR_UPR);
205
        if (!(upr & SPR_UPR_IMP))
206
                return 1;
207
 
208
        immu_tlb_one_to_one_reset();
209
 
210
        /* Enable IMMU */
211
        lo_immu_en ();
212
 
213
        return 0;
214
}
215
 
216
void
217
itlb_miss_handler (void)
218
{
219
        // This was probably cause by injection of parity error
220
        // We just reset iTLB in event of miss
221
        printf("iTLB miss handler resetting iTLB\n");
222
 
223
        immu_tlb_one_to_one_reset();
224
 
225
        test_state_update();
226
 
227
}
228
 
229
void
230
dtlb_miss_handler (void)
231
{
232
        // This was probably cause by injection of parity error
233
        // We just reset iTLB in event of miss
234
        printf("dTLB miss handler resetting iTLB\n");
235
 
236
        dmmu_tlb_one_to_one_reset();
237
 
238
        test_state_update();
239
 
240
}
241
 
242
 
243
unsigned long
244
inline inline_mfspr(unsigned long spr)
245
{
246
  unsigned long value;
247
  asm("l.mfspr\t\t%0,%1,0" : "=r" (value) : "r" (spr));
248
  return value;
249
}
250
 
251
void
252
parity_error_interrupt(void)
253
{
254
        // Read parity error indicator. Reading also clears interrupt line.
255
        char parerr = REG8(PARERR_BASE);
256
 
257
        printf("Parity error interrupt: 0x%02x\n",parerr);
258
 
259
        test_state_update();
260
 
261
        // Clear iTLB
262
        //immu_tlb_one_to_one_reset();
263
 
264
        return;
265
}
266
 
267
 
268
void
269
dummy_function()
270
{
271
        volatile int i;
272
 
273
        report(0xdfdfdfdf);
274
 
275
        for(i=0;i<64;i++);
276
 
277
        return;
278
}
279
 
280
void
281
copy_function(void *insn_area, void* dummy_function, int nwords)
282
{
283
        int i;
284
        unsigned long *p1 = (unsigned long *)insn_area;
285
        unsigned long *p2 = (unsigned long *)dummy_function;
286
        for (i = 0; i < nwords; i++)
287
                p1[i] = p2[i];
288
}
289
 
290
 
291
void
292
ic_test_setup()
293
{
294
        //Initialise handler vector
295
        int_init();
296
        int_add(PARERR_IRQ, parity_error_interrupt, 0);
297
 
298
        // Enable interrupts in supervisor register
299
        cpu_enable_user_interrupts();
300
}
301
 
302
 
303
void
304
dc_test_setup()
305
{
306
        //Initialise handler vector
307
        int_init();
308
        int_add(PARERR_IRQ, parity_error_interrupt, 0);
309
 
310
        // Enable interrupts in supervisor register
311
        cpu_enable_user_interrupts();
312
}
313
 
314
 
315
int
316
dmmu_test_setup(unsigned long data_location)
317
{
318
        unsigned long mmucfgr;
319
        int mmu_tlb_reg, mmusets;
320
 
321
        // Determine number of mmusets
322
        mmucfgr = mfspr (SPR_DMMUCFGR);
323
        mmusets = 1 << ((mmucfgr & SPR_DMMUCFGR_NTS)>>
324
                        SPR_DMMUCFGR_NTS_OFF);
325
        // Now get TLB register that will be used when matching/translating
326
        // VA for page dummy_function() is in.
327
 
328
        mmu_tlb_reg = (data_location / PAGE_SIZE) % mmusets;
329
        report (data_location);
330
        report (mmu_tlb_reg);
331
 
332
        // Enable interrupts and install handler. Error will trigger
333
        // an interrupt.
334
 
335
        //Initialise handler vector
336
        int_init();
337
        int_add(PARERR_IRQ, parity_error_interrupt, 0);
338
 
339
        // Add handler for dTLB miss (parity error may show up as
340
        // miss.)
341
        add_handler(0x9, dtlb_miss_handler);
342
 
343
        // Enable interrupts in supervisor register
344
        cpu_enable_user_interrupts();
345
 
346
        return mmu_tlb_reg;
347
 
348
}
349
 
350
 
351
 
352
int
353
immu_test_setup(void)
354
{
355
        unsigned long mmucfgr;
356
        int mmu_tlb_reg, mmusets;
357
 
358
        // Determine number of mmusets
359
        mmucfgr = mfspr(SPR_IMMUCFGR);
360
        mmusets = 1 << ((mmucfgr & SPR_IMMUCFGR_NTS)>>
361
                        SPR_IMMUCFGR_NTS_OFF);
362
        // Now get TLB register that will be used when matching/translating
363
        // VA for page dummy_function() is in.
364
 
365
        mmu_tlb_reg = ((unsigned long)dummy_function / PAGE_SIZE) % mmusets;
366
 
367
        report(mmu_tlb_reg);
368
 
369
        // Enable interrupts and install handler. Error will trigger
370
        // an interrupt.
371
 
372
        // iMMU parity errors trigger both a miss and the parity interrupt, but
373
        // for now we'll just have the miss vector do the handling
374
 
375
        //Initialise handler vector
376
        //int_init();
377
        //int_add(PARERR_IRQ, parity_error_interrupt, 0);
378
        // Enable interrupts in supervisor register
379
        //cpu_enable_user_interrupts();
380
 
381
        // Add handler for iTLB miss (parity error may show up as
382
        // miss.)
383
        add_handler(0xa, itlb_miss_handler);
384
 
385
 
386
        return mmu_tlb_reg;
387
}
388
 
389
 
390
void
391
gpr_test(int reg, int bit_number)
392
{
393
 
394
        switch(reg)
395
        {
396
        case 0:
397
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
398
                FT_STIM_WAIT_ACK;
399
                __asm__ ("l.add r23, r24, r0");
400
 
401
                break;
402
 
403
        case 1:
404
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
405
                FT_STIM_WAIT_ACK;
406
                __asm__ ("l.add r23, r24, r1");
407
 
408
                break;
409
 
410
        case 2:
411
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
412
                FT_STIM_WAIT_ACK;
413
                __asm__ ("l.add r23, r24, r2");
414
 
415
                break;
416
 
417
        case 3:
418
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
419
                FT_STIM_WAIT_ACK;
420
                __asm__ ("l.add r23, r24, r3");
421
 
422
                break;
423
 
424
        case 4:
425
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
426
                FT_STIM_WAIT_ACK;
427
                __asm__ ("l.add r23, r24, r4");
428
 
429
                break;
430
 
431
        case 5:
432
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
433
                FT_STIM_WAIT_ACK;
434
                __asm__ ("l.add r23, r24, r5");
435
 
436
                break;
437
 
438
        case 6:
439
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
440
                FT_STIM_WAIT_ACK;
441
                __asm__ ("l.add r23, r24, r6");
442
 
443
                break;
444
 
445
        case 7:
446
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
447
                FT_STIM_WAIT_ACK;
448
                __asm__ ("l.add r23, r24, r7");
449
 
450
                break;
451
 
452
        case 8:
453
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
454
                FT_STIM_WAIT_ACK;
455
                __asm__ ("l.add r23, r24, r8");
456
 
457
                break;
458
 
459
        case 9:
460
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
461
                FT_STIM_WAIT_ACK;
462
                __asm__ ("l.add r23, r24, r9");
463
 
464
                break;
465
 
466
        case 10:
467
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
468
                FT_STIM_WAIT_ACK;
469
                __asm__ ("l.add r23, r24, r10");
470
 
471
                break;
472
 
473
        case 11:
474
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
475
                FT_STIM_WAIT_ACK;
476
                __asm__ ("l.add r23, r24, r11");
477
 
478
                break;
479
 
480
        case 12:
481
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
482
                FT_STIM_WAIT_ACK;
483
                __asm__ ("l.add r23, r24, r12");
484
 
485
                break;
486
 
487
        case 13:
488
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
489
                FT_STIM_WAIT_ACK;
490
                __asm__ ("l.add r23, r24, r13");
491
 
492
                break;
493
 
494
        case 14:
495
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
496
                FT_STIM_WAIT_ACK;
497
                __asm__ ("l.add r23, r24, r14");
498
 
499
                break;
500
 
501
        case 15:
502
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
503
                FT_STIM_WAIT_ACK;
504
                __asm__ ("l.add r23, r24, r15");
505
 
506
                break;
507
 
508
        case 16:
509
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
510
                FT_STIM_WAIT_ACK;
511
                __asm__ ("l.add r23, r24, r16");
512
 
513
                break;
514
 
515
        case 17:
516
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
517
                FT_STIM_WAIT_ACK;
518
                __asm__ ("l.add r23, r24, r17");
519
 
520
                break;
521
 
522
        case 18:
523
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
524
                FT_STIM_WAIT_ACK;
525
                __asm__ ("l.add r23, r24, r18");
526
 
527
                break;
528
 
529
        case 19:
530
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
531
                FT_STIM_WAIT_ACK;
532
                __asm__ ("l.add r23, r24, r19");
533
 
534
                break;
535
 
536
        case 20:
537
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
538
                FT_STIM_WAIT_ACK;
539
                __asm__ ("l.add r23, r24, r20");
540
 
541
                break;
542
 
543
        case 21:
544
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
545
                FT_STIM_WAIT_ACK;
546
                __asm__ ("l.add r23, r24, r21");
547
 
548
                break;
549
 
550
        case 22:
551
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
552
                FT_STIM_WAIT_ACK;
553
                __asm__ ("l.add r23, r24, r22");
554
 
555
                break;
556
 
557
        case 23:
558
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
559
                FT_STIM_WAIT_ACK;
560
                __asm__ ("l.add r23, r24, r23");
561
 
562
                break;
563
 
564
        case 24:
565
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
566
                FT_STIM_WAIT_ACK;
567
                __asm__ ("l.add r23, r24, r24");
568
 
569
                break;
570
 
571
        case 25:
572
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
573
                FT_STIM_WAIT_ACK;
574
                __asm__ ("l.add r23, r24, r25");
575
 
576
                break;
577
 
578
        case 26:
579
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
580
                FT_STIM_WAIT_ACK;
581
                __asm__ ("l.add r23, r24, r26");
582
 
583
                break;
584
 
585
        case 27:
586
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
587
                FT_STIM_WAIT_ACK;
588
                __asm__ ("l.add r23, r24, r27");
589
 
590
                break;
591
 
592
        case 28:
593
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
594
                FT_STIM_WAIT_ACK;
595
                __asm__ ("l.add r23, r24, r28");
596
 
597
                break;
598
 
599
        case 29:
600
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
601
                FT_STIM_WAIT_ACK;
602
                __asm__ ("l.add r23, r24, r29");
603
 
604
                break;
605
 
606
        case 30:
607
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
608
                FT_STIM_WAIT_ACK;
609
                __asm__ ("l.add r23, r24, r30");
610
 
611
                break;
612
 
613
        case 31:
614
                FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_RF_FAULT,bit_number, reg);
615
                FT_STIM_WAIT_ACK;
616
                __asm__ ("l.add r23, r24, r31");
617
                break;
618
        }
619
}
620
 
621
 
622
int main(void)
623
{
624
 
625
        unsigned long cachecfgr, mmucfgr;
626
        int cachebs, cachesets, cachesize;
627
        int mmusets;
628
        unsigned long * stack_ptr;
629
        unsigned long * data_area;
630
        unsigned long * insn_area;
631
        int mmu_mr, mmu_tr;
632
        int bit_number, word_number;
633
 
634
        printf("\nParity Error Test Restart\n");
635
 
636
        // Setup DMMU with cache disable on first page
637
        dmmu_init();
638
 
639
        // This ft_state variable should retain its value between resets, as
640
        // we'll always store it back to its memory location when accessing it.
641
        volatile int * ft_state = (volatile int*)FT_STATE_RECORD_MEM;
642
 
643
        volatile int * test_state1 = (volatile int*)FT_STATE_TEST_STATE1_MEM;
644
        volatile int * test_state2 = (volatile int*)FT_STATE_TEST_STATE2_MEM;
645
 
646
 
647
        printf("Test state %d\n",*ft_state);
648
 
649
restart_tests:
650
 
651
        switch(*ft_state)
652
        {
653
        case 0:
654
                printf("State %d: Test initialisation\n", *ft_state);
655
 
656
                // Kickoff - tell testbench stimulus to start
657
                printf("Writing GO command\n");
658
                FT_STIM_WRITE(FT_GO_COMMAND);
659
                (*ft_state)++;
660
                FT_STIM_WAIT_ACK;
661
 
662
#ifdef JUMP_TO_TEST             
663
                *ft_state = JUMP_TO_TEST;
664
                goto restart_tests;
665
#endif
666
 
667
                // No break, fall through to case 1
668
        case 1:
669
                printf("\nState %d: IC instruction memory test\n", *ft_state);
670
 
671
                // IC instruction RAM fault injection.
672
 
673
                ic_test_setup();
674
 
675
                // Determine cache configuration
676
                cachecfgr = inline_mfspr(SPR_ICCFGR);
677
                // What is block size
678
                cachebs = (cachecfgr & SPR_ICCFGR_CBS) ? 32 : 16;
679
 
680
                cachesets = (1 << ((cachecfgr & SPR_ICCFGR_NCS)>>
681
                                   SPR_ICCFGR_NCS_OFF));
682
 
683
                // *ft_state increments when *test_state1 == *test_state2
684
                *test_state1 = 0;
685
                *test_state2 = 32;
686
 
687
                word_number = (((unsigned long)dummy_function >> 2) %
688
                               cachesets);
689
                report((unsigned long) dummy_function);
690
                report(word_number);
691
 
692
                // Call a function, so it's cached, inject an error into
693
                // the cache instruction RAM location where the first
694
                // instruction of that function is located, and call it again.
695
                // This should trip the parity error, and the interrupt.
696
 
697
                while(*ft_state == 1)
698
                {
699
                        dummy_function();
700
 
701
                        bit_number = *test_state1;
702
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_IC_RAM_FAULT,
703
                                                bit_number, word_number);
704
 
705
                        FT_STIM_WAIT_ACK;
706
 
707
                        dummy_function();
708
 
709
                }
710
        case 2:
711
                printf("\nState %d: IC tag memory test\n", *ft_state);
712
                // IC tag RAM fault injection.
713
 
714
                ic_test_setup();
715
 
716
                // Determine cache configuration
717
                cachecfgr = inline_mfspr(SPR_ICCFGR);
718
                // What is block size
719
                cachebs = (cachecfgr & SPR_ICCFGR_CBS) ? 32 : 16;
720
 
721
                cachesets = (1 << ((cachecfgr & SPR_ICCFGR_NCS)>>
722
                                   SPR_ICCFGR_NCS_OFF));
723
 
724
                cachesize = cachebs * cachesets;
725
 
726
                // Same as above, but this time for the tag RAM.
727
 
728
                // *ft_state increments when *test_state1 == *test_state2
729
                *test_state1 = 0;
730
                *test_state2 = 24;
731
 
732
                // Calculate word in tag RAM
733
                word_number = (((unsigned long)dummy_function %
734
                                cachesize ) / cachebs) ;
735
 
736
                while(*ft_state == 2)
737
                {
738
                        dummy_function();
739
                        bit_number = *test_state1;
740
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_IC_TAG_FAULT,
741
                                                bit_number, word_number);
742
 
743
                        FT_STIM_WAIT_ACK;
744
 
745
                        dummy_function();
746
 
747
                }
748
        case 3:
749
                // DC data RAM fault injection
750
                printf("\nState %d: DC data memory test\n", *ft_state);
751
 
752
                dc_test_setup();
753
 
754
                // Read a far off data address (outside first MMU page, at 
755
                // least), determine it's cache line, inject a fault and read 
756
                // it again.
757
                // Set up stack pointer variable, so we know where top of
758
                // stack is.
759
                stack_ptr = (unsigned long*)&_stack;
760
 
761
                // Put test area one page past it:
762
                data_area = stack_ptr;
763
                data_area += PAGE_SIZE;
764
 
765
                // Report address
766
                report((unsigned long)data_area);
767
                // Write a test variable there
768
                *data_area = 0xea5ecafe;
769
 
770
                // Determine cache set up
771
                cachecfgr = inline_mfspr(SPR_DCCFGR);
772
                // What is block size
773
                cachebs = (cachecfgr & SPR_DCCFGR_CBS) ? 32 : 16;
774
 
775
                cachesets = (1 << ((cachecfgr & SPR_DCCFGR_NCS)>>
776
                                   SPR_DCCFGR_NCS_OFF));
777
 
778
                cachesize = cachebs * cachesets;
779
 
780
                // Calculate address of word in DC RAM
781
                word_number = (((unsigned long)data_area % cachesize) >> 2);
782
 
783
                // *ft_state increments when *test_state1 == *test_state2
784
                *test_state1 = 0;
785
                *test_state2 = 32;
786
 
787
                while(*ft_state == 3)
788
                {
789
 
790
                        // Read the location, to cache it, or trigger read
791
                        // from cache
792
                        report(*data_area);
793
                        bit_number = *test_state1;
794
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_DC_RAM_FAULT,
795
                                                bit_number, word_number);
796
 
797
                        FT_STIM_WAIT_ACK;
798
 
799
                        //report(*data_area);
800
 
801
 
802
                }
803
        case 4:
804
                printf("\nState %d: DC tag memory test\n", *ft_state);
805
 
806
                dc_test_setup();
807
 
808
                // Same set up as data cache RAM test.
809
                stack_ptr = (unsigned long*)&_stack;
810
 
811
                // Put test area one page past it:
812
                data_area = stack_ptr;
813
                data_area += PAGE_SIZE;
814
 
815
                // Report address
816
                report((unsigned long)data_area);
817
                // Write a test variable there
818
                *data_area = 0xea5ecafe;
819
 
820
                // Determine cache set up
821
                cachecfgr = inline_mfspr(SPR_DCCFGR);
822
                // What is block size
823
                cachebs = (cachecfgr & SPR_DCCFGR_CBS) ? 32 : 16;
824
 
825
                cachesets = (1 << ((cachecfgr & SPR_DCCFGR_NCS)>>
826
                                   SPR_DCCFGR_NCS_OFF));
827
 
828
                cachesize = cachebs * cachesets;
829
 
830
                // Calculate address of word in DC RAM
831
                word_number = (((unsigned long)data_area % cachesize)/cachebs);
832
 
833
                // *ft_state increments when *test_state1 == *test_state2
834
                *test_state1 = 0;
835
                *test_state2 = 24;
836
 
837
                while(*ft_state == 4)
838
                {
839
 
840
                        // Read the location, to cache it, or trigger read
841
                        // from cache
842
                        report(*data_area);
843
                        bit_number = *test_state1;
844
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_DC_TAG_FAULT,
845
                                                bit_number, word_number);
846
                        FT_STIM_WAIT_ACK;
847
 
848
                        report(*data_area);
849
 
850
                }
851
        case 5:
852
                // Instruction MMU TLB match register corruption test
853
                // Parity error should just trigger an interrupt, not
854
                // reset the system
855
                printf("\nState %d: IMMU match register memory test\n",
856
                       *ft_state);
857
 
858
                if  (immu_init())
859
                {
860
 
861
                        printf("\nSkipping test %d - no iMMU present\n",
862
                               *ft_state);
863
                        (*ft_state)++;
864
                        goto restart_tests;
865
                }
866
 
867
                mmu_mr = immu_test_setup();
868
 
869
                *test_state1 = 0;
870
                *test_state2 = 16;
871
 
872
                while (*ft_state==5)
873
                {
874
                        bit_number = *test_state1;
875
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_IMMU_MR_FAULT,
876
                                                bit_number, mmu_mr);
877
                        FT_STIM_WAIT_ACK;
878
 
879
                        dummy_function();
880
                }
881
 
882
 
883
 
884
        case 6:
885
                // Instruction MMU TLB match register corruption test
886
                // Should just trigger interrupt, not reset.
887
                printf("\nState %d: IMMU translate register memory test\n",
888
                       *ft_state);
889
                if  (immu_init())
890
                {
891
 
892
                        printf("\nSkipping test %d - no iMMU present\n",
893
                               *ft_state);
894
                        (*ft_state)++;
895
                        goto restart_tests;
896
                }
897
 
898
                mmu_tr = immu_test_setup();
899
 
900
                *test_state1 = 0;
901
                *test_state2 = 24;
902
 
903
                while (*ft_state==6)
904
                {
905
                        bit_number = *test_state1;
906
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_IMMU_TR_FAULT,
907
                                                bit_number, mmu_mr );
908
                        FT_STIM_WAIT_ACK;
909
 
910
                        dummy_function();
911
                }
912
 
913
        case 7:
914
                // Data MMU TLB match register corruption test
915
                // Parity error should just trigger an interrupt, not
916
                // reset the system
917
                printf("\nState %d: DMMU match register memory test\n",
918
                       *ft_state);
919
 
920
                if  (dmmu_init())
921
                {
922
 
923
                        printf("\nSkipping test %d - no dMMU present\n",
924
                               *ft_state);
925
                        (*ft_state)++;
926
                        goto restart_tests;
927
                }
928
 
929
                // Choose address for test
930
                data_area = stack_ptr;
931
                data_area += PAGE_SIZE;
932
 
933
                *data_area = 0xeaaaa51e;
934
 
935
                mmu_mr = dmmu_test_setup((unsigned long) data_area);
936
 
937
                *test_state1 = 0;
938
                *test_state2 = 16;
939
 
940
                while (*ft_state==7)
941
                {
942
                        bit_number = *test_state1;
943
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_DMMU_MR_FAULT,
944
                                                bit_number, mmu_mr );
945
                        FT_STIM_WAIT_ACK;
946
 
947
                        report (*data_area);
948
                }
949
 
950
        case 8:
951
                // Data MMU TLB translate register corruption test
952
                // Parity error should just trigger an interrupt, not
953
                // reset the system
954
                printf("\nState %d: DMMU translate register memory test\n",
955
                       *ft_state);
956
 
957
                if  (dmmu_init())
958
                {
959
 
960
                        printf("\nSkipping test %d - no dMMU present\n",
961
                               *ft_state);
962
                        (*ft_state)++;
963
                        goto restart_tests;
964
                }
965
 
966
                // Choose address for test
967
                data_area = stack_ptr;
968
                data_area += (PAGE_SIZE<<2);
969
 
970
                *data_area = 0xdeadc0de;
971
 
972
                mmu_tr = dmmu_test_setup((unsigned long) data_area);
973
 
974
                *test_state1 = 0;
975
                *test_state2 = 24;
976
 
977
                while (*ft_state==8)
978
                {
979
                        bit_number = *test_state1;
980
                        FT_STIM_WRITE_FAULT_CMD(FT_STIM_CMD_DMMU_TR_FAULT,
981
                                                bit_number, mmu_tr );
982
                        FT_STIM_WAIT_ACK;
983
 
984
                        report (*data_area);
985
                }
986
 
987
                // Sometimes the interrupt triggers twice here, meaning
988
                // ft_state was incremented twice. So manually put it back,
989
                // just in case.
990
                *ft_state = 9;
991
 
992
        case 9:
993
                printf("\nState %d: Register file memory test\n",
994
                       *ft_state);
995
 
996
                // Inject an error into a reg, then schedule an instruction to
997
                // read it.
998
                (*ft_state)++;
999
 
1000
                // initialise variables here
1001
                *test_state1 = -1;  // Bit number
1002
                *test_state2 = 0; // GPR number
1003
 
1004
        case 10:
1005
                // Sit in this state to do the tests
1006
                (*test_state1)++;
1007
 
1008
                if (*test_state1 == 32)
1009
                {
1010
                        (*test_state2)++;
1011
                        *test_state1 = 0;
1012
 
1013
                        if (*test_state2 == 32)
1014
                                (*ft_state)++;
1015
                }
1016
 
1017
                bit_number = *test_state1;
1018
 
1019
                while (*ft_state==10)
1020
                {
1021
                        gpr_test(*test_state2,bit_number);
1022
                }
1023
 
1024
        case 11:
1025
                printf("Tests done\n");
1026
                report(0x8000000d);
1027
                return 0;
1028
        default:
1029
                // Shouldn't be here. ft_state somhow got corrupted.
1030
                exit(1);
1031
                break;
1032
        }
1033
 
1034
        return 0;
1035
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.