xpiapp.c
23.1 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
/**************************************************************************
*
* PI test program to be run on the target R4300
*
* $Revision: 1.1.1.1 $
*
*/
#include <stdarg.h>
#include "ultra64.h"
#include "boot.h"
#include "log.h"
static void nullproc(...);
#ifndef _STANDALONE
#undef LogEntry
#define LogEntry(a)
#undef LogInit
#define LogInit()
#define PRINTF rmonPrintf
#else
#define PRINTF nullproc
#endif /* STANDALONE */
/**************************************************************************
*
* Main definitions
*
*/
#define DIR_READ 0 /* Rdram <- device */
#define DIR_WRITE 1 /* Rdram -> device */
/*
* ROM and RDRAM test addresses
*/
#if 0
#define PI_ROM_ADDRESS 0x10100000 /* (Domain1:address2) + 1 MB */
#endif
/* (Domain2:address2) + 1 MB */
#define PI_ROM_ADDRESS (PI_DOM1_ADDR2+0x100000)
#define PI_RDRAM_ADDRESS 0x00050000 /* 64*5 KB boundary */
#define PI_TEST_START 0x12345678
#define PI_TEST_REG 0x0001
#define PI_TEST_IO 0x0002
#define PI_TEST_DMA_INIT 0x0003
#define PI_TEST_DMA 0x0004
#define PI_TEST_RESET 0x0005
#define PI_COMPARE 0x0006
#define PI_DONE 0xbeef
/**************************************************************************
*
* Function prototypes
*
*/
static int piTestReg(void);
static int piTestIo(void);
static int piTestDma(void);
static int piTestReset(void);
static int piTestConfig(void);
static int piPollStatus(unsigned int, int);
static int piIoWrite(unsigned int, unsigned int);
static unsigned int piIoRead(unsigned int);
static int piDmaCopy(int, unsigned int, unsigned int, int);
static int piCompare(unsigned int, unsigned int, int);
static void piConfigDomain(unsigned int, int, int, int, int);
static void piGetDomainParam(unsigned int, int *, int *, int *,
int *);
static void myPrintf(const char *, ...);
/**************************************************************************
*
* Extern functions
*
*/
#ifdef _STANDALONE
extern void LogInit(void);
extern void LogEntry(unsigned int);
extern void InitProgram(void);
extern void EndProgram(void);
#endif
static unsigned int errorTotal;
static int latency, pulseWidth, pageSize, release;
char BootStack[STACKSIZE];
static void startproc(void *);
static void main(void *);
static OSThread startThread;
static char startThreadStack[STACKSIZE];
static OSThread mainThread;
static char mainThreadStack[STACKSIZE];
static OSThread rmonThread;
static char rmonThreadStack[STACKSIZE];
#define NUM_PI_MSGS 8
static OSMesg PiMessages[NUM_PI_MSGS];
static OSMesgQueue PiMessageQ;
#ifndef _STANDALONE
void
boot(void *arg)
{
/* Initiliaze OS parameters and structures */
osInitialize();
/*
* Create start thread
*/
osCreateThread(&startThread, 3, startproc, arg,
startThreadStack+STACKSIZE, 10);
osStartThread(&startThread);
}
static void
startproc(void *arg)
{
/*
* Start PI Mgr for access to cartridge
*/
osCreatePiManager((OSPri)OS_PRIORITY_PIMGR, &PiMessageQ, PiMessages,
NUM_PI_MSGS);
/*
* Start RMON for debugging & data xfer (make sure to start
* PI Mgr first)
*/
osCreateThread(&rmonThread, 0, rmonMain, (void *)0,
rmonThreadStack+STACKSIZE, OS_PRIORITY_RMON);
osStartThread(&rmonThread);
/*
* Create main thread
*/
osCreateThread(&mainThread, 6, main, arg,
mainThreadStack+STACKSIZE, 10);
osStartThread(&mainThread);
/*
* Become the idle thread
*/
osSetThreadPri( 0, 0 );
osPause();
osExit();
}
#else
void
boot(void)
{
/* Initialize logging mechanism */
LogInit();
LogEntry(PI_TEST_START);
LogEntry(IO_READ(PI_STATUS_REG));
/* Clear all RCP interrupt masks */
IO_WRITE(MI_INTR_MASK_REG, (MI_INTR_MASK_CLR_SP | MI_INTR_MASK_CLR_SI |
MI_INTR_MASK_CLR_AI | MI_INTR_MASK_CLR_VI | MI_INTR_MASK_CLR_PI |
MI_INTR_MASK_CLR_DP));
/* Clear SP interrupt */
IO_WRITE(SP_STATUS_REG, SP_CLR_INTR);
/* Clear VI interrupt */
IO_WRITE(VI_CURRENT_REG, 0);
/* Clear AI interrupt */
IO_WRITE(AI_STATUS_REG, 1);
/* Clear PI interrupt */
IO_WRITE(PI_STATUS_REG, PI_CLR_INTR);
/* Clear SI interrupt */
IO_WRITE(SI_STATUS_REG, 1);
/* Clear DP interrupt */
IO_WRITE(MI_MODE_REG, MI_CLR_DP_INTR);
errorTotal = 0;
errorTotal = piTestReg();
errorTotal += piTestIo();
errorTotal += piTestDma();
errorTotal += piTestReset();
if (errorTotal != 0) {
LogEntry(PI_DONE|0xdead0000);
LogEntry(errorTotal);
}
else {
LogEntry(PI_DONE);
}
for (;;) {}
}
#endif /* _STANDALONE */
static void
main(void *arg)
{
int lat, pwd, pgs, rel;
latency = 0x10;
pulseWidth = 0x10;
pageSize = 1;
release = 3;
piConfigDomain(PI_DOMAIN1_REG, latency, pulseWidth, pageSize, release);
PRINTF("******************** Hello, I'm alive ********************\n");
PRINTF("Config parameters: lat=0x%02x, pwd=0x%02x, pgs=%2d, rls=%d\n",
latency, pulseWidth, pageSize, release);
errorTotal = 0;
errorTotal = piTestReg();
errorTotal += piTestIo();
errorTotal += piTestDma();
errorTotal += piTestReset();
errorTotal += piTestConfig();
piGetDomainParam(PI_DOMAIN1_REG, &lat, &pwd, &pgs, &rel);
PRINTF("\nConfig parameters: lat=0x%02x, pwd=0x%02x, pgs=%2d, rls=%d\n",
lat, pwd, pgs, rel);
PRINTF("\n******************** Total errors = %d ********************\n",
errorTotal);
if (errorTotal != 0) {
LogEntry(PI_DONE|0xdead0000);
LogEntry(errorTotal);
}
else {
LogEntry(PI_DONE);
}
for (;;) {}
} /* main */
/**************************************************************************
*
* Main PI test functions
*
**************************************************************************/
/**************************************************************************
* Perform PI I/O write/read test
*/
static int
piIoWRTest(unsigned int addr, unsigned int wdata)
{
unsigned int rdata;
piIoWrite(addr, wdata);
rdata = piIoRead(addr);
if (rdata != wdata) {
PRINTF("====> piIoWRTest: failed: addr=%08x, wdata=%08x, rdata=%08x \n", addr, wdata, rdata);
LogEntry(PI_TEST_IO| 0xdead0000);
LogEntry(addr);
LogEntry(wdata);
LogEntry(rdata);
return(1);
}
return(0);
} /* piIoWRTest */
/**************************************************************************
* REGISTER TESTS
**************************************************************************/
/* Data table */
static unsigned int regDataTable[] = {
0x12345678, 0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555, 0xDEADBEEF
};
static unsigned int regDataTableSize= sizeof(regDataTable)/sizeof(unsigned int);
int
piTestReg(void)
{
int i, errorCount = 0;
unsigned int w;
/*
* For each register address, test it with all the pattern data in
* data table.
*/
LogEntry(PI_TEST_REG| 0x11110000);
PRINTF("******************** piTestReg: starting ********************\n");
LogEntry(PI_TEST_IO| 0xdead0000);
/* We need to wait for PIC to be idle before we can write to any regs */
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
for (i = 0; i < regDataTableSize; i++) {
IO_WRITE(PI_DRAM_ADDR_REG, regDataTable[i]);
w = IO_READ(PI_DRAM_ADDR_REG);
if ((regDataTable[i] & 0x00FFFFFE) != w) {
PRINTF("====> piTestReg: failed: reg=%08x, data=%08x, exp=%08x \n", PI_DRAM_ADDR_REG, w, (regDataTable[i] & 0x00fffffe));
LogEntry(PI_TEST_REG| 0xdead0000);
LogEntry(regDataTable[i] & 0x00FFFFFE);
LogEntry(w);
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
errorCount++;
}
}
LogEntry(PI_TEST_REG| 0x22220000);
/* We need to wait for PIC to be idle before we can write to any regs */
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
for (i = 0; i < regDataTableSize; i++) {
IO_WRITE(PI_CART_ADDR_REG, regDataTable[i]);
w = IO_READ(PI_CART_ADDR_REG);
if ((regDataTable[i] & 0xFFFFFFFE) != w) {
PRINTF("====> piTestReg: failed: reg=%08x, data=%08x, exp=%08x \n", PI_CART_ADDR_REG, w, (regDataTable[i] & 0xfffffffe));
LogEntry(PI_TEST_REG| 0xdead0000);
LogEntry(regDataTable[i] & 0xFFFFFFFE);
LogEntry(w);
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
errorCount++;
}
}
PRINTF("******************** piTestReg: error=%d ********************\n",
errorCount);
return(errorCount);
} /* piTestReg */
/**************************************************************************
* PIO TESTS
**************************************************************************
* Perform IO Write/Read from different PI ROM address space
*/
/* Address and data tables */
static unsigned int ioAddrTable[] = {
PI_ROM_ADDRESS, PI_ROM_ADDRESS+4,
PI_ROM_ADDRESS+8, PI_ROM_ADDRESS+0x0c,
PI_ROM_ADDRESS+0x1000, PI_ROM_ADDRESS+0x1004,
PI_ROM_ADDRESS+0x1008, PI_ROM_ADDRESS+0x100c
};
static unsigned int ioAddrTableSize= sizeof(ioAddrTable)/sizeof(unsigned int);
static unsigned int ioDataTable[] = {
0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555, 0xA5A5A5A5, 0x5A5A5A5A
};
static unsigned int ioDataTableSize= sizeof(ioDataTable)/sizeof(unsigned int);
int
piTestIo(void)
{
int i, j;
int errorCount = 0;
/*
* Write/Read ROM with pattern data
*/
PRINTF("******************** piTestIo: starting ********************\n");
LogEntry(PI_TEST_IO);
for (i = 0; i < ioAddrTableSize; i++) {
for (j = 0; j < ioDataTableSize; j++) {
if (piIoWRTest(ioAddrTable[i], ioDataTable[j])) {
errorCount++;
}
}
}
PRINTF("******************** piTestIo: error=%d ********************\n",
errorCount);
return(errorCount);
} /* piTestIo */
/**************************************************************************
* DMA TESTS
**************************************************************************
*
* - Perform DMA to/from different ROM address space with different size
* (2B (minimum), 4B, 8B, 32B, 128B, 256B, 264B, 1024B)
*/
static unsigned int dmaSzTable[] = {
4, 6, 8, 32, 128, 132, 256, 264, 512, 1024, (64*1024), (128*1024),
(512*1024)
};
static unsigned int dmaSzTableSize= sizeof(dmaSzTable)/sizeof(unsigned int);
int
piTestDma(void)
{
int i, j, ret, size;
unsigned int romAddr, ramAddr, data, exp;
int errorCount = 0;
/*
* Initialize RamRom (4 MB) with data
*/
PRINTF("******************** piTestDma: starting ********************\n");
PRINTF("******************** piTestDma: initializing ROM ********************\n");
LogEntry(PI_TEST_DMA_INIT);
data = 0x12345678;
for (i = 0; i < 0x100000; i++) {
romAddr = PI_ROM_ADDRESS+(i*4);
data = romAddr;
if (piIoWRTest(romAddr, data)) {
errorCount++;
}
}
ramAddr = PI_RDRAM_ADDRESS;
romAddr = PI_ROM_ADDRESS;
/* DMA: 2 bytes ROM -> RDRAM */
PRINTF("******************** piTestDma: size=2 bytes ********************\n");
LogEntry(PI_TEST_DMA|0x00020000);
piDmaCopy(DIR_READ, romAddr, ramAddr, 2); /* Start DMA */
piPollStatus(PI_STATUS_DMA_BUSY, 1); /* Wait for DMA busy to clear */
if (piCompare(romAddr, ramAddr, 2)) { /* Compare data */
PRINTF("====> piTestDma: compare failed: rom=%08x, dram=%08x, size=%d\n", romAddr, ramAddr, 2);
errorCount++;
}
/* errlog(DEBUG, "--- PI DMA: checking for interrupt"); */
#ifdef _STANDALONE
LogEntry(PI_TEST_DMA|0x00021000);
piPollStatus(0x08, 0); /* Wait for interrupt bit set */
IO_WRITE(PI_STATUS_REG, PI_CLR_INTR); /* Clear interrupt */
piPollStatus(0x08, 1); /* Interrupt bit should clear */
#endif
ramAddr = (ramAddr+8) & 0xFFFFFFF8;
romAddr = (romAddr+4) & 0xFFFFFFFC;
/* DMA: X bytes ROM -> RDRAM */
for (i = 0; i < dmaSzTableSize; i++) {
size = dmaSzTable[i];
PRINTF("******************** piTestDma: size=%d bytes ********************\n", size);
LogEntry(PI_TEST_DMA| (size << 16));
piDmaCopy(DIR_READ, romAddr, ramAddr, size); /* Start DMA */
piPollStatus(PI_STATUS_DMA_BUSY, 1); /* Wait for DMA busy to clear */
if (piCompare(romAddr, ramAddr, size)) { /* Compare data */
PRINTF("====> piTestDma: compare failed: rom=%08x, dram=%08x, size=%d\n", romAddr, ramAddr, size);
errorCount++;
}
ramAddr = (PI_RDRAM_ADDRESS+size+8) & 0xFFFFFFF8;
romAddr = (PI_ROM_ADDRESS +size+4) & 0xFFFFFFFC;
}
/* DMA (4MB - 64KB) from RamRom to RDRAM */
ramAddr = PI_RDRAM_ADDRESS;
romAddr = PI_ROM_ADDRESS;
LogEntry(PI_TEST_DMA| 0xeeee0000);
size = (1024*1024*4) - 0x50000;
PRINTF("******************** piTestDma: size=%d bytes ********************\n", size);
piDmaCopy(DIR_READ, romAddr, ramAddr, size); /* Start DMA */
piPollStatus(PI_STATUS_DMA_BUSY, 1); /* Wait for DMA busy to clear */
if (piCompare(romAddr, ramAddr, size)) { /* Compare data */
PRINTF("====> piTestDma: compare failed: rom=%08x, dram=%08x, size=%d\n", romAddr, ramAddr, size);
errorCount++;
}
PRINTF("******************** piTestDma: error=%d ********************\n",
errorCount);
return(errorCount);
} /* piTestDma */
/**************************************************************************
* RESET TEST
**************************************************************************/
int
piTestReset(void)
{
int i, j, size;
unsigned int romAddr, ramAddr;
int errorCount = 0;
PRINTF("******************** piTestReset: starting ********************\n");
ramAddr = PI_RDRAM_ADDRESS;
romAddr = PI_ROM_ADDRESS;
LogEntry(PI_TEST_RESET); /* Log status register */
i = IO_READ(PI_STATUS_REG);
LogEntry(i);
size = 128;
piDmaCopy(DIR_READ, romAddr, ramAddr, size); /* Start DMA */
/* Issue an PIO read to force error bit to set */
j = IO_READ(LOG_ADDRESS);
LogEntry(PI_TEST_RESET|0x11110000);
piPollStatus(PI_STATUS_DMA_BUSY, 1); /* Wait for DMA busy to clear */
if (piCompare(romAddr, ramAddr, size)) { /* Compare data */
errorCount++;
}
/* Check for error bit set */
LogEntry(PI_TEST_RESET|0x22220000);
piPollStatus(PI_STATUS_ERROR, 0);
/* Reset the PI controller */
IO_WRITE(PI_STATUS_REG, PI_SET_RESET);
/* The error bit should clear */
LogEntry(PI_TEST_RESET|0x33330000);
piPollStatus(PI_STATUS_ERROR, 1);
/* Log the status register again */
LogEntry(IO_READ(PI_STATUS_REG));
/*
* This test only works in uncached mode and slow RamRom speed due to the
* time delay
*/
#ifdef _UNCACHE
/* Issue 2 PIO reads to force error bit set */
j = IO_READ(LOG_ADDRESS);
j = IO_READ(LOG_ADDRESS);
/* Check for error bit set */
LogEntry(PI_TEST_RESET|0x44440000);
piPollStatus(PI_STATUS_ERROR, 0);
/* Reset the PI controller */
IO_WRITE(PI_STATUS_REG, PI_SET_RESET);
/* The error bit should clear */
LogEntry(PI_TEST_RESET|0x55550000);
piPollStatus(PI_STATUS_ERROR, 1);
/* Log the status register again */
LogEntry(IO_READ(PI_STATUS_REG));
#endif
PRINTF("******************** piTestReset: error=%d ********************\n",
errorCount);
return(errorCount);
} /* piTestReset */
/**************************************************************************
* CONFIG TEST
**************************************************************************/
/* Bit format: 0-7:latency, 8-15:pulse_width, 16-19:page_size, 20-21:release */
static unsigned int configTable[] = {
0x0030ffff, 0x00308080, 0x00304040, 0x00302020, 0x00301010, 0x00300a0a,
0x0031ffff, 0x00318080, 0x00314040, 0x00312020, 0x00311010, 0x00310a0a,
0x0032ffff, 0x00328080, 0x00324040, 0x00322020, 0x00321010, 0x00320a0a,
0x0033ffff, 0x00338080, 0x00334040, 0x00332020, 0x00331010, 0x00330a0a,
0x0034ffff, 0x00348080, 0x00344040, 0x00342020, 0x00341010, 0x00340a0a,
0x0035ffff, 0x00358080, 0x00354040, 0x00352020, 0x00351010, 0x00350a0a,
0x0038ffff, 0x00388080, 0x00384040, 0x00382020, 0x00381010, 0x00380a0a,
0x003affff, 0x003a8080, 0x003a4040, 0x003a2020, 0x003a1010, 0x003a0a0a,
0x003fffff, 0x003f8080, 0x003f4040, 0x003f2020, 0x003f1010, 0x003f0a0a,
0x0020ffff, 0x00208080, 0x00204040, 0x00202020, 0x00201010, 0x00200a0a,
0x0021ffff, 0x00218080, 0x00214040, 0x00212020, 0x00211010, 0x00210a0a,
0x0022ffff, 0x00228080, 0x00224040, 0x00222020, 0x00221010, 0x00220a0a,
0x0023ffff, 0x00238080, 0x00234040, 0x00232020, 0x00231010, 0x00230a0a,
0x0024ffff, 0x00248080, 0x00244040, 0x00242020, 0x00241010, 0x00240a0a,
0x0025ffff, 0x00258080, 0x00254040, 0x00252020, 0x00251010, 0x00250a0a,
0x0028ffff, 0x00288080, 0x00284040, 0x00282020, 0x00281010, 0x00280a0a,
0x002affff, 0x002a8080, 0x002a4040, 0x002a2020, 0x002a1010, 0x002a0a0a,
0x002fffff, 0x002f8080, 0x002f4040, 0x002f2020, 0x002f1010, 0x002f0a0a,
};
static unsigned int configTableSize= sizeof(configTable)/sizeof(unsigned int);
int
piTestConfig(void)
{
int i, size;
unsigned int romAddr, ramAddr;
int errorCount = 0;
/* DMA from RamRom to RDRAM */
ramAddr = PI_RDRAM_ADDRESS;
romAddr = PI_ROM_ADDRESS;
size = (1024*4);
PRINTF("******************** piTestConfig: rom=0x%08x, ram=0x%08x, size=%d\n", romAddr, ramAddr, size);
for (i = 0; i < configTableSize; i++) {
latency = configTable[i] & 0xff;
pulseWidth = (configTable[i] >> 8) & 0xff;
pageSize = (configTable[i] >> 16) & 0x0f;
release = (configTable[i] >> 20) & 0x03;
PRINTF("Config parameters: lat=0x%02x, pwd=0x%02x, pgs=%2d, rls=%d\n",
latency, pulseWidth, pageSize, release);
piConfigDomain(PI_DOMAIN1_REG, latency, pulseWidth, pageSize, release);
piDmaCopy(DIR_READ, romAddr, ramAddr, size); /* Start DMA */
piPollStatus(PI_STATUS_DMA_BUSY, 1); /* Wait for DMA busy to clear */
if (piCompare(romAddr, ramAddr, size)) { /* Compare data */
errorCount++;
} /* if */
} /* for */
PRINTF("******************** piTestConfig: error=%d ********************\n", errorCount);
return(errorCount);
} /* piTestConfig */
/**************************************************************************
*
* The following functions are derived from IOSIM environment
*
**************************************************************************/
/**************************************************************************
* Configure the PI domain registers for better throughput
*/
void
piConfigDomain(unsigned int domReg, int lat, int pwd, int pgs, int rls)
{
IO_WRITE(domReg+PI_DOM_LAT_OFS, lat & 0xFF);
IO_WRITE(domReg+PI_DOM_PWD_OFS, pwd & 0xFF);
IO_WRITE(domReg+PI_DOM_PGS_OFS, pgs & 0x0F);
IO_WRITE(domReg+PI_DOM_RLS_OFS, rls & 0x03);
}
void
piGetDomainParam(unsigned int domReg, int *lat, int *pwd, int *pgs, int *rls)
{
*lat = IO_READ(domReg+PI_DOM_LAT_OFS);
*pwd = IO_READ(domReg+PI_DOM_PWD_OFS);
*pgs = IO_READ(domReg+PI_DOM_PGS_OFS);
*rls = IO_READ(domReg+PI_DOM_RLS_OFS);
}
/**************************************************************************
* Poll PI status register for bit pattern to either be set or cleared
*/
static int
piPollStatus(unsigned int bits, int cleared)
{
/* Poll PI status register for the statBits set */
unsigned int stat;
while (1) {
stat = IO_READ(PI_STATUS_REG);
if (cleared) {
if (!(stat & bits)) break;
}
else {
if (stat & bits) break;
}
}
return((int)stat);
} /* piPollStatus */
/**************************************************************************
* Perform PI I/O write
*/
int
piIoWrite(unsigned int addr, unsigned int data)
{
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
IO_WRITE(addr, data);
return(0);
} /* piIoWrite */
/**************************************************************************
* Perform PI I/O read
*/
unsigned int
piIoRead(unsigned int addr)
{
unsigned int data;
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
data = IO_READ(addr);
return(data);
} /* piIoRead */
/**************************************************************************
* Start PI DMA transaction between RDRAM and ROM
*/
int
piDmaCopy(int dir, unsigned int piAddr, unsigned int dramAddr, int length)
{
int ret;
unsigned int stat;
ret = 0;
piPollStatus(PI_STATUS_DMA_BUSY | PI_STATUS_IO_BUSY, 1);
IO_WRITE(PI_DRAM_ADDR_REG, dramAddr);
IO_WRITE(PI_CART_ADDR_REG, piAddr);
switch (dir) {
case DIR_READ: { /* PI -> RDRAM */
IO_WRITE(PI_WR_LEN_REG, length-1);
break;
}
case DIR_WRITE: { /* PI <- RDRAM */
IO_WRITE(PI_RD_LEN_REG, length-1);
break;
}
default: {
ret = 1;
}
} /* switch */
return(ret);
} /* piDmaCopy */
/**************************************************************************
* Perform 32-bit compare between PI and RDRAM
*/
int
piCompare(unsigned int piAddr, unsigned int rdramAddr, int nbytes)
{
/* Compare 'nbytes' bytes between source 'piAddr' and destination
* 'rdramAddr'
* 'nbytes' must be even and addresses word-aligned
*/
int i, errorCount;
unsigned int w1, w2;
errorCount = 0;
piAddr &= 0xFFFFFFFC; /* Ensure addresses are word-aligned */
rdramAddr &= 0xFFFFFFFC;
i = 0;
while (i < nbytes) {
w1 = piIoRead(piAddr+i);
w2 = IO_READ(rdramAddr+i);
i += 4;
if (i > nbytes ) {
/* Here, compare the LSB 2 bytes only */
if ((w1 & 0xFFFF0000) != (w2 & 0xFFFF0000)) {
PRINTF("====> piCompare: failed: rom=%08x:%08x, ram=%08x:%08x \n", piAddr+(i-4), w1, rdramAddr+(i-4), w2);
LogEntry(PI_TEST_IO| 0xdead0000);
LogEntry(PI_COMPARE|0xdead0000);
LogEntry(piAddr+(i-4));
LogEntry(w1 & 0xFFFF0000);
LogEntry(rdramAddr+(i-4));
LogEntry(w2 & 0xFFFF0000);
errorCount++;
break;
}
} else
if (w1 != w2) {
PRINTF("====> piCompare: failed: rom=%08x:%08x, ram=%08x:%08x \n", piAddr+(i-4), w1, rdramAddr+(i-4), w2);
LogEntry(PI_COMPARE|0xdead0000);
LogEntry(piAddr+(i-4));
LogEntry(w1);
LogEntry(rdramAddr+(i-4));
LogEntry(w2);
errorCount++;
break;
}
} /* while */
return(errorCount);
} /* piCompare */
static void
myPrintf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
/* Configure to something that we know works */
piConfigDomain(PI_DOMAIN1_REG, 0x10, 0x10, 1, 3);
rmonPrintf(fmt, ap);
/* Restore previous settings */
piConfigDomain(PI_DOMAIN1_REG, latency, pulseWidth, pageSize, release);
va_end(ap);
}
static void
nullproc(...)
{
}