iotestpi.c
5.72 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
/*************************************************************************
*
* File: iotestpi.c
*
* This file contains test routines for the Peripheral Interface (PI).
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/iotestpi.c,v 1.2 2002/05/30 05:52:50 whs Exp $
*
*/
#include <stdio.h>
#include "trace.h"
#include "iomap.h"
#include "iotest.h"
/***********************************************************************
* Test routines for PI
*/
static int
piPollStatus(unsigned int statBits, int reset)
{
/* Poll PI status register for the statBits set */
unsigned int stat;
do {
stat = IO_READ(PI_STATUS_REG);
_TRACE(DSTATUS,
fprintf(LogFp, "\n\tPI Status Reg = 0x%08x\t", stat));
if (stat & PI_STATUS_ERROR) {
_TRACE(DERROR,
fprintf(LogFp,"\n\tERROR: PI error bit set: %08x\t",
stat));
if (reset)
PI_RESET();
statBits &= ~PI_STATUS_ERROR;
}
}
while (stat & statBits);
return((int)stat);
} /* piPollStatus */
int
IoPiWrite(unsigned int address, unsigned int data)
{
piPollStatus(PI_STATUS_ERROR | PI_STATUS_DMA_BUSY |
PI_STATUS_IO_BUSY, FALSE);
IO_WRITE(address, data);
return(1); /* Return 1 to avoid printing Passed test */
} /* IoPiWrite */
int
IoPiRead(unsigned int address)
{
piPollStatus(PI_STATUS_ERROR | PI_STATUS_DMA_BUSY |
PI_STATUS_IO_BUSY, FALSE);
return(IO_READ(address));
} /* IoPiRead */
int
IoPiDmaCopy(int dir, unsigned int piAddr, unsigned int dramAddr, int length)
{
int ret;
unsigned int stat;
ret = 0;
#ifdef CHECK_STATUS
piPollStatus(PI_STATUS_ERROR | PI_STATUS_DMA_BUSY |
PI_STATUS_IO_BUSY, FALSE);
#endif
IO_WRITE(PI_DRAM_ADDR_REG, dramAddr);
IO_WRITE(PI_CART_ADDR_REG, piAddr);
switch (dir) {
case DIR_FROM_RAM: {
IO_WRITE(PI_RD_LEN_REG, length);
break;
}
case DIR_TO_RAM: {
IO_WRITE(PI_WR_LEN_REG, length);
break;
}
default: {
_TRACE(DERROR,
fprintf(LogFp,
"\tERROR: Illegal PiDmaCopy direction!\n"));
ret = -1;
}
} /* switch */
return(ret);
} /* IoPiDmaCopy */
int
PiTestStatus(int testBits, int reset, int a3, int a4)
{
/* Read the PI status reg and compare it against testBits */
piPollStatus(testBits, reset);
return(1); /* Return 1 to avoid printing Passed test */
} /* PiTestStatus */
int
PiTestReg(int regAddr, int data, int a3, int a4)
{
/* a1 = register address */
/* a2 = test data */
/* Write/Read to/from DRAM address and Cartridge registers */
unsigned int ret;
errorCount = 0;
regAddr &= 0xFFFFFFFC; /* Make sure that it's word-aligned */
_TRACE(DLOG, printf("\tPI Status Reg = 0x%08x\n",
IO_READ(PI_STATUS_REG)));
/* Hw reset the address to be 2-byte aligned
* Also, DMA RAM address is only 24-bit, upper 8 bits are
* also set to 0.
*/
IO_WRITE(regAddr, data);
ret = IO_READ(regAddr);
if (data != ret) {
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* PiTestReg */
int
PiTestIoRead(int domAddr, int data, int a3, int failExpected)
{
/* CPU performs read from cartridge devices */
unsigned int ret;
errorCount = 0;
domAddr &= 0xFFFFFFFC; /* Make sure that it's word aligned */
_TRACE(DLOG, printf("\tPI Status Reg = 0x%08x\n",
IO_READ(PI_STATUS_REG)));
ret = IoPiRead((unsigned int)domAddr);
if (data != ret) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* PiTestIoRead */
int
PiTestIoWrite(int domAddr, int data, int a3, int failExpected)
{
/* CPU performs write to cartridge devices */
unsigned int ret;
errorCount = 0;
domAddr &= 0xFFFFFFFC; /* Make sure that it's word aligned */
_TRACE(DLOG, printf("\tPI Status Reg = 0x%08x\n",
IO_READ(PI_STATUS_REG)));
IoPiWrite((unsigned int)domAddr, (unsigned int)data);
ret = IoPiRead((unsigned int)domAddr);
if (data != ret) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* PiTestIoWrite */
int
PiTestDma(int dir, int piAddr, int ramAddr, int nbytes)
{
/* CPU issues DMA (read/write) requests between PI devices and RDRAM */
unsigned int i, d1, d2;
errorCount = 0;
piAddr &= 0xFFFFFFFE; /* Make sure it's half-word aligned */
ramAddr &= 0xFFFFFFFE; /* Make sure it's half-word aligned */
/*
* DMA WRITE tests:
* - Assume that PI device has been pre-loaded with data
* - Transfer nbytes from PI -> RAM
* - Read each word from RAM and compare it against PI
* - Note that size of transfer = nbytes - 1
*/
if (IoPiDmaCopy(dir, (unsigned int)piAddr,
(unsigned int)ramAddr, nbytes-1) < 0) {
errorCount++;
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* PiTestDma */
int
PiTestDmaPg(int type, int piAddr, int dramAddr, int npages)
{
/*
* CPU issues DMA (read/write) requests between SI devices and
* RDRAM pages
* 2 RDRAMs: 1 RDRAM = 1 MBytes = 2 banks;
* 1 bank = 256 pages; 1 page = 2 KBytes
*/
int i, startPg, nbytes, dir;
unsigned int address;
errorCount = 0;
nbytes = 8;
dir = DIR_TO_RAM;
dramAddr &= 0xFFFFFFFC; /* Make sure addresses are word aligned */
piAddr &= 0xFFFFFFFC;
startPg = dramAddr / RDRAM_PAGE_SIZE;
i = MAX_RDRAM_PAGES - startPg;
if (npages > i)
npages = i;
for (i=0; i < npages; i++) {
#ifndef CHECK_STATUS
piPollStatus(PI_STATUS_ERROR | PI_STATUS_DMA_BUSY |
PI_STATUS_IO_BUSY, FALSE);
#endif
nbytes += (i*2);
address = (dramAddr + (i*RDRAM_PAGE_SIZE)) & 0xFFFFFFFC;
if (IoPiDmaCopy(dir, (unsigned int)piAddr,
(unsigned int)address, nbytes-1) < 0) {
errorCount++;
}
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* PiTestDmaPg */