iotestsi.c
5.89 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
/*************************************************************************
*
* File: iotestsi.c
*
* This file contains test routines for the Serial Interface (SI).
*
* $Header: /root/leakn64/depot/rf/sw/n64os20l/iosim/src/iotestsi.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 SI
*
* Note: The SI DRAM address reg (SI_DRAM_ADDR_REG) supports only 24-bit
* address; the most significant byte and the least significant 2 bits
* are masked off. The address needs to be word-aligned.
*/
static int
siPollStatus(unsigned int statBits)
{
/* Poll PI status register for the statBits set */
unsigned int stat;
do {
stat = IO_READ(SI_STATUS_REG);
_TRACE(DSTATUS,
fprintf(LogFp, "\n\tSI Status Reg = 0x%08x\t\t", stat));
if (stat & SI_STATUS_DMA_ERROR) {
_TRACE(DERROR,
fprintf(LogFp,
"\n\t****ERROR: SI error bit set: %08x\t\t",
stat));
statBits &= ~SI_STATUS_DMA_ERROR;
}
}
while (stat & statBits);
return((int)stat);
} /* siPollStatus */
int
IoSiWrite(unsigned int address, unsigned int data)
{
siPollStatus(SI_STATUS_DMA_ERROR | SI_STATUS_RD_BUSY);
IO_WRITE(address, data);
return(1); /* Return 1 to avoid printing Passed test */
} /* IoSiWrite */
int
IoSiRead(unsigned int address)
{
unsigned int stat;
siPollStatus(SI_STATUS_DMA_ERROR | SI_STATUS_RD_BUSY);
return(IO_READ(address));
} /* IoSiRead */
int
IoSiDmaCopy(int type, unsigned int pifAddr, unsigned int dramAddr)
{
int ret;
ret = 0;
#ifdef CHECK_STATUS
siPollStatus(SI_STATUS_DMA_ERROR | SI_STATUS_DMA_BUSY);
#endif
IO_WRITE(SI_DRAM_ADDR_REG, dramAddr);
switch (type) {
case SI_RD64B: {
_TRACE(DLOG,
printf("\tIoSiDmaCopy: RD64B: R=%08x P=%08x\n",
dramAddr, pifAddr));
IO_WRITE(SI_PIF_ADDR_RD64B_REG, pifAddr);
break;
}
case SI_WR64B: {
_TRACE(DLOG,
printf("\tIoSiDmaCopy: WR64B: R=%08x P=%08x\n",
dramAddr, pifAddr));
IO_WRITE(SI_PIF_ADDR_WR64B_REG, pifAddr);
break;
}
default: {
_TRACE(DERROR, fprintf(LogFp,
"\t****ERROR: Illegal SiDmaCopy type!\t"));
ret = -1;
}
}
return(ret);
} /* IoSiDmaCopy */
int
SiTestStatus(int testBits, int a2, int a3, int a4)
{
/* Read the SI status reg and compare it against testBits */
siPollStatus(testBits);
return(1); /* Return 1 to avoid test passed printout */
} /* SiTestStatus */
int
SiTestReg(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 */
/* 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);
siPollStatus(SI_STATUS_RD_BUSY);
ret = IO_READ(regAddr);
/*
* Since the only valid register R/W test is for SI_DRAM_ADDR_REG.
* We need to mask off upper 2 bytes and lower 2 bits so that data
* is word-aligned and within 24-bit addressing of RDRAM
*/
if ((data & 0x00FFFFFC) != ret) {
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* SiTestReg */
int
SiTestIoRead(int pifAddr, int data, int a3, int failExpected)
{
/* CPU performs read from PIF address space */
unsigned int ret;
errorCount = 0;
pifAddr &= 0xFFFFFFFC; /* Make sure it's word-aligned */
_TRACE(DLOG, printf("\tSI Status Reg = 0x%08x\n",
IO_READ(SI_STATUS_REG)));
ret = IoSiRead((unsigned int)pifAddr);
if (data != ret) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* SiTestIoRead */
int
SiTestIoWrite(int pifAddr, int data, int a3, int failExpected)
{
/* CPU performs write to cartridge devices */
unsigned int ret;
errorCount = 0;
pifAddr &= 0xFFFFFFFC; /* Make sure that it's word aligned */
_TRACE(DLOG, printf("\tSI Status Reg = 0x%08x\n",
IO_READ(SI_STATUS_REG)));
IoSiWrite((unsigned int)pifAddr, (unsigned int)data);
ret = IoSiRead((unsigned int)pifAddr);
if (data != ret) {
if (!failExpected)
errorCount++;
_TRACE(DERROR, LOG_ERROR(data, ret));
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* SiTestIoWrite */
int
SiTestDma(int type, int pifAddr, int dramAddr, int a4)
{
/* CPU issues DMA (read/write) requests between SI devices and RDRAM */
unsigned int i, d1, d2;
errorCount = 0;
dramAddr &= 0xFFFFFFFC; /* Make sure it's word aligned */
pifAddr &= 0xFFFFFFFC; /* Make sure it's word aligned */
/*
* DMA WRITE tests:
* - Transfer 4/64 bytes between PI <-> RAM
* - Read each word from RAM and compare it against SI
*/
if (IoSiDmaCopy(type, (unsigned int)pifAddr,
(unsigned int)dramAddr) < 0) {
errorCount++;
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* SiTestDma */
int
SiTestDmaPg(int type, int pifAddr, 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;
unsigned int address;
errorCount = 0;
dramAddr &= 0xFFFFFFFC; /* Make sure addresses are word aligned */
pifAddr &= 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
siPollStatus(SI_STATUS_DMA_ERROR | SI_STATUS_DMA_BUSY);
#endif
address = (dramAddr + (i*RDRAM_PAGE_SIZE)) & 0xFFFFFFFC;
if (IoSiDmaCopy(type, (unsigned int)pifAddr,
(unsigned int)address) < 0) {
errorCount++;
}
}
errorTotal += errorCount;
return((errorCount == 0) ? 0 : -1);
} /* SiTestDmaPg */