pi.c
14.4 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
/**************************************************************************
*
* Main file for PI test functions
*
* $Revision: 1.2 $
*
*/
#include <sys/types.h>
#ifdef __sgi__
#include <sys/sbd.h>
#endif
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __sgi__
#include <sys/sema.h>
#endif
#include <netinet/in.h>
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <getopt.h>
#ifdef __sgi__
#include <sys/u64driver.h>
#else
#include <PR/R4300.h>
#endif
#include <rcp.h>
/*
* From $ROOT/usr/include/ide, which is installed from $ROOT/PR/diags/include
*/
#include "diag.h"
#include "dbg_comm.h"
/**************************************************************************
*
* Main definitions
*
*/
#define DIR_READ 0 /* Rdram <- device */
#define DIR_WRITE 1 /* Rdram -> device */
#define PI_TEST_BASE 20
/*
* ROM and RDRAM test addresses
*/
#define PI_ROM_ADDRESS 0x10800000 /* (Domain1:address2) + 8 MB */
#define PI_RDRAM_ADDRESS 0x00002000
/**************************************************************************
*
* Function prototypes
*
*/
static int testInit();
static int testDo(TEST_REF *test_ref);
static int piTestReg(TEST_REF *test_ref);
static int piTestIo(TEST_REF *test_ref);
static int piTestDma(TEST_REF *test_ref);
static int piPollStatus(unsigned int, int);
int piIoWrite(unsigned int, unsigned int);
unsigned int piIoRead(unsigned int);
int piDmaCopy(int, unsigned int, unsigned int, int);
int piCompare(unsigned int, unsigned int, int);
void piConfigDomain(unsigned int, int, int, int, int);
/**************************************************************************
*
* Private global variables
*
*/
/*
* Create an array of tests, each of which corresponds to a separate menu
* item callable from the master ide menu.
*/
static TEST_REF testRefs[] = {
{"PI register test", PI_TEST_BASE+0, piTestReg},
{"PI I/O read/write test", PI_TEST_BASE+1, piTestIo},
{"PI DMA test", PI_TEST_BASE+2, piTestDma},
{"END OF TESTS",0,0}
};
static int Initialize = 1;
static int NumFailures = 0;
static int Failed = 0;
/**************************************************************************
*
* Functions
*
*/
/*
* diagnostic entry point:
*
* Each separately invokable ide diagnostic command corresponds to an
* independent ".c" module; the entry point herein must match
* the test name as specified in the rdpcmd.awk script. These command
* names correspond to the names you see from the ide menu. For this
* module, there will be an ide command "pi" (until this
* silly module is retired, that is).
*/
int piTestEntry()
{
int c;
int testNum;
Initialize = 1;
Failed = 0;
NumFailures = 0;
/*
* Sample of how to parse command line args received from ide
*/
while ((c = getopt(pGlobalComm->argc, pGlobalComm->argv, "ht:I")) != EOF) {
switch(c) {
case 'h':
/*
* Print out the available subtests, then return without
* invoking any subtests (which is done by calling diaginit()).
*/
dgListSubTests(testRefs);
return(0);
break;
case 't':
testNum = atoi(optarg);
pGlobalComm->entryNum = -(testNum);
break;
case 'I':
Initialize = 0;
break;
default:
printf("weird option character %c = 0x%x\n", c, c);
break;
}
}
/*
* IDE will call our one-time initialization function testInit(),
* then invoke testDo() for as many tests as we've put into the
* global test array "testRefs", declared at the top of this module.
*/
diaginit(testRefs, testInit, testDo);
if (Failed) {
errlog(INFO, "... test %s FAILED", ideTestName);
} else {
errlog(INFO, "... test %s PASSED", ideTestName);
}
} /* piTestEntry */
/**************************************************************************
* Test init fuction
*/
static int testInit()
{
errlog(INFO, "Starting test %s ... ", ideTestName);
return(0);
} /* testInit */
/**************************************************************************
* Test caller
*/
static int testDo(TEST_REF *test_ref)
{
int rc;
int errorCount;
errlog(INFO, "--- starting subtest %s (%d)", test_ref->name, test_ref->num);
/*
* Reset the target system, if necessary
* Setup the diagnostic communication link to the target system.
*/
if (Initialize) {
errlog(DEBUG, "--- initializing target");
dgInitComm();
errlog(DEBUG, "--- configuring PI domains");
/*
piConfigDomain(PI_DOMAIN1_REG, 0x80, 0x20, 0x02, 0x03);
piConfigDomain(PI_DOMAIN2_REG, 0x80, 0x20, 0x02, 0x03);
*/
/* New domain parameters for faster access of RAMROM */
piConfigDomain(PI_DOMAIN1_REG, 0x6, 0x3, 0x6, 0x2);
piConfigDomain(PI_DOMAIN2_REG, 0x6, 0x3, 0x6, 0x2);
}
/*
* Invoke the actual test from the "TEST_REF" array statically declared
* as a global within this test module.
*/
if (errorCount = test_ref->fnc(test_ref)) {
NumFailures += errorCount;
Failed = 1;
errlog(INFO, "--- subtest %s FAILED, %d failures",
test_ref->name, errorCount);
} else {
errlog(INFO, "--- subtest %s PASSED", test_ref->name);
}
return(0);
} /* testDo */
/**************************************************************************
*
* 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) {
errlog(ERR_SEVERE,
"data miscompare - ad = %08x, wr = %08x, rd = %08x",
addr, wdata, rdata);
return(1);
}
else {
errlog(DEBUG,
"compare - ad = %08x, wr = %08x, rd = %08x", addr, wdata, rdata);
}
return(0);
} /* piIoWRTest */
/**************************************************************************
* REGISTER TESTS
**************************************************************************/
/* Data table */
static unsigned int regDataTable[] = {
0x00000000, 0xFFFFFFFF, 0xAAAAAAAA, 0x55555555, 0xDEADBEEF
};
static unsigned int regDataTableSize= sizeof(regDataTable)/sizeof(unsigned int);
int
piTestReg(TEST_REF *test_ref)
{
int i, j;
int errorCount = 0;
/*
* For each register address, test it with all the pattern data in
* data table.
*/
for (j = 0; j < regDataTableSize; j++) {
if (dgTestReg(PI_DRAM_ADDR_REG, regDataTable[j],
(regDataTable[j] & 0x00FFFFF8))) {
errorCount++;
}
}
for (j = 0; j < regDataTableSize; j++) {
if (dgTestReg(PI_CART_ADDR_REG, regDataTable[j],
(regDataTable[j] & 0xFFFFFFFE))) {
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(TEST_REF *test_ref)
{
int i, j;
int errorCount = 0;
/*
* Write/Read ROM with pattern data
*/
for (i = 0; i < ioAddrTableSize; i++) {
for (j = 0; j < ioDataTableSize; j++) {
if (piIoWRTest(ioAddrTable[i], ioDataTable[j])) {
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
};
static unsigned int dmaSzTableSize= sizeof(dmaSzTable)/sizeof(unsigned int);
int
piTestDma(TEST_REF *test_ref)
{
int i, j, ret, size;
unsigned int romAddr, ramAddr, data, exp;
int errorCount = 0;
/*
* Initialize WROM (4 KB) with data = address
*/
errlog(DEBUG, "--- PI DMA: initializing ROM address");
data = 0x12345678;
for (i = 0; i < 1024; 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 */
errlog(DEBUG, "--- PI DMA: pi=%08x, ram=%08x, size=%08x",
romAddr, ramAddr, 2);
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 */
errorCount++;
}
errlog(DEBUG, "--- PI DMA: checking for interrupt");
piPollStatus(0x08, 0); /* Wait for interrupt bit set */
dgWriteWord(PI_STATUS_REG, PI_CLR_INTR); /* Clear interrupt */
piPollStatus(0x08, 1); /* Interrupt bit should clear */
ramAddr = (ramAddr+8) & 0xFFFFFFF8;
romAddr = (romAddr+4) & 0xFFFFFFFC;
/* DMA: X bytes ROM -> RDRAM */
for (i = 0; i < dmaSzTableSize; i++) {
size = dmaSzTable[i];
errlog(DEBUG, "--- PI DMA: starting with pi=%08x, ram=%08x, size=%08x",
romAddr, ramAddr, size);
piDmaCopy(DIR_READ, romAddr, ramAddr, size); /* Start DMA */
errlog(DEBUG, "--- PI DMA: waiting for busy bit cleared");
piPollStatus(PI_STATUS_DMA_BUSY, 1); /* Wait for DMA busy to clear */
errlog(DEBUG, "--- PI DMA: comparing src and dst data");
if (piCompare(romAddr, ramAddr, size)) { /* Compare data */
errorCount++;
}
ramAddr = (PI_RDRAM_ADDRESS+size+8) & 0xFFFFFFF8;
romAddr = (PI_ROM_ADDRESS +size+4) & 0xFFFFFFFC;
}
return(errorCount);
} /* piTestDma */
/**************************************************************************
*
* 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)
{
dgWriteWord(domReg+PI_DOM_LAT_OFS, lat & 0xFF);
dgWriteWord(domReg+PI_DOM_PWD_OFS, pwd & 0xFF);
dgWriteWord(domReg+PI_DOM_PGS_OFS, pgs & 0x0F);
dgWriteWord(domReg+PI_DOM_RLS_OFS, rls & 0x03);
}
/**************************************************************************
* 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) {
dgReadWord(PI_STATUS_REG, &stat);
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);
dgWriteWord(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);
dgReadWord(addr, &data);
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);
dgWriteWord(PI_DRAM_ADDR_REG, dramAddr);
dgWriteWord(PI_CART_ADDR_REG, piAddr);
switch (dir) {
case DIR_READ: { /* PI -> RDRAM */
dgWriteWord(PI_WR_LEN_REG, length-1);
break;
}
case DIR_WRITE: { /* PI <- RDRAM */
dgWriteWord(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);
dgReadWord(rdramAddr+i, &w2);
i += 4;
if (i > nbytes ) {
/* Here, compare the LSB 2 bytes only */
if ((w1 & 0xFFFF0000) != (w2 & 0xFFFF0000)) {
errlog(ERR_SEVERE,
"data miscompare - pi = (%08x:%08x), ram = (%08x:%08x)",
piAddr+(i-4), (w1 & 0xFFFF0000), rdramAddr+(i-4),
(w2 & 0xFFFF0000));
errorCount++;
break;
}
} else
if (w1 != w2) {
errlog(ERR_SEVERE,
"data miscompare - pi = (%08x:%08x), ram = (%08x:%08x)",
piAddr+(i-4), w1, rdramAddr+(i-4), w2);
errorCount++;
break;
}
} /* while */
return(errorCount);
} /* piCompare */