ndev_bzero.c
4.61 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
#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 <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 <sys/u64gio.h>
/*
* From $ROOT/usr/include/ide, which is installed from $ROOT/PR/diags/include
*/
#include "diag.h"
/*
* Local definitions
*/
#define GIOBUS_BASE 0x1f400000
#define GIOBUS_SIZE 0x200000 /* 2 MB */
#define U64_GIO_MEMTEST_BASE 10
static int gio_bzerotest(TEST_REF *test_ref);
/*
* Create an array of tests, each of which corresponds to a separate menu
* item callable from the master ide menu.
*/
static TEST_REF TestRefs[] = {
{"GIO memory test (fast bzero)", U64_GIO_MEMTEST_BASE+0, gio_bzerotest},
{"",0,0}
};
static char *TestName, *addr, *mask, *count;
static int NumFailures = 0;
static int ShortMsg = 0;
static int DebugLevel = 0;
static int gio_bzeroInit();
static int gio_bzeroDo(TEST_REF *test_ref);
/*
* diagnostic entry point
*/
int gio_bzeroEntry()
{
TestName = pGlobalComm->argv[0];
diaginit(TestRefs, gio_bzeroInit, gio_bzeroDo);
if (NumFailures) {
errlog(INFO_END, "... test %s FAILED, %d failures.",
TestName, NumFailures);
} else {
errlog(INFO_END, "... test %s PASSED", TestName);
}
}
static int gio_bzeroInit()
{
char *env;
errlog(INFO_START, "Starting test %s ... ", TestName);
NumFailures = 0;
/*
* We could do the memory mapping here, but we don't have a convenient way
* of maintaining the pointer to the memory, other than as a static global.
*
* Thus, it's just as easy (and arguably better coding style) to do the
* test setup in the body of the test itself.
*/
return(0);
}
static int gio_bzeroDo(TEST_REF *test_ref)
{
int rc;
errlog(DEBUG,
"%s: starting subtest %s (%d) ...",
TestName, test_ref->name, test_ref->num);
/*
* Invoke the actual test from the "TEST_REF" array statically declared
* as a global within this test module.
*/
if (rc = test_ref->fnc(test_ref)) NumFailures++;
if (rc == 0) {
errlog(DEBUG, "... PASSED");
} else {
errlog(INFO_END, "... FAILED");
}
return(NumFailures);
}
/*
* Return value: number of errors encountered. "Zero" indicates success.
*/
int
gio_bzerotest(TEST_REF *test_ref)
{
int mmemFd;
unsigned char *mapbase;
int pageIndex, memIndex;
struct u64_board *pBoard;
int c;
int verbose = 0;
int errorCount0, errorCount1;
unsigned int readLong, readLongAddr;
unsigned short readShort, readShortAddr;
if ((mmemFd = open("/dev/mmem", 2)) < 0) {
perror("open of /dev/mmem failed");
return(1);
}
if ((mapbase = (unsigned char *)mmap(0, GIOBUS_SIZE, PROT_READ|PROT_WRITE,
(MAP_PRIVATE), mmemFd,
PHYS_TO_K1(GIOBUS_BASE))) == (unsigned char *)-1) {
errlog(ERR_SEVERE,
"%s: cannot map 0x%x (errno = %d)\n",
test_ref->name, GIOBUS_BASE, errno);
perror("mmap");
return(1);
}
pBoard = (struct u64_board *)(mapbase);
/*
* Loop through each 1MB page of memory and clear memory to a
* known, chaning pattern (simple address to address test). Then
* go through and do a fast bzero clear of memory to zero & validate.
* Use 32 bit addressing.
*/
for (pageIndex = 0, errorCount0 = 0; pageIndex < 16; pageIndex++) {
errlog(DEBUG,
"testing page %d, addr to addr.\n", pageIndex);
/*
* Setup the page pointer in the page control register.
*/
pBoard->dram_page_cntrl = (pageIndex << 20);
/*
* Write address to address slowly, using proven (slow) 32 bit method.
*/
for (memIndex = 0,
readLongAddr = (((int)mapbase) + U64_MEM_SIZE);
memIndex < (U64_MEM_SIZE >> 2); memIndex++, readLongAddr += 4) {
*((unsigned int *)readLongAddr) = readLongAddr;
}
/*
* Clear memory using fast bzero.
*/
bzero( (((int)mapbase) + U64_MEM_SIZE), U64_MEM_SIZE );
for (memIndex = 0,
readLongAddr = (((int)mapbase) + U64_MEM_SIZE);
memIndex < (U64_MEM_SIZE >> 2); memIndex++, readLongAddr += 4) {
readLong = *((unsigned int *)(readLongAddr));
if (readLong != 0) {
errlog(ERR_SIMPLE,
"0x%x, read 0x%x, exp 0x%x, rd^exp = 0x%x\n",
readLongAddr, readLong, 0,
(readLong ^ 0));
++errorCount0;
}
}
}
if (errorCount0 > 0) {
errlog(ERR_SEVERE,
"(addr to addr test): 0x%x (%d) errors encountered.\n",
errorCount0, errorCount0);
} else {
errlog(DEBUG,
"(addr to addr test): no errors encountered.\n");
}
return(errorCount0);
}