-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
369 lines (303 loc) · 8.35 KB
/
init.c
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
/*
* MemTest86+ V5 Specific code (GPL V2.0)
* By Samuel DEMEULEMEESTER, [email protected]
* http://www.canardpc.com - http://www.memtest.org
* ------------------------------------------------
* init.c - MemTest-86 Version 3.6
*
* Released under version 2 of the Gnu Public License.
* By Chris Brady
*/
#include <stdint.h>
#include <stddef.h>
#include "arch.h"
#include "test.h"
#include "config.h"
#include "smp.h"
#include "io.h"
#include "spd.h"
#include "pci.h"
#include "controller.h"
extern void initialise_cpus();
/* Here we store all of the cpuid data */
extern struct cpu_ident cpu_id;
int l1_cache=0, l2_cache=0, l3_cache=0;
ulong extclock;
int beepmode;
/* Failsafe function */
/* msec: number of ms to wait - scs: scancode expected to stop */
/* bits: 0 = extended detection - 1: SMP - 2: Temp Check */
/* 3: MP SMP - 4-7: RSVD */
void failsafe(int msec, int scs)
{
int i;
uint64_t deadline;
unsigned char c;
volatile char *pp;
for(i=0, pp=(char *)(SCREEN_ADR+(18*160)+(18*2)+1); i<40; i++, pp+=2) {
*pp = 0x1E;
}
for(i=0, pp=(char *)(SCREEN_ADR+(18*160)+(18*2)+1); i<3; i++, pp+=2) {
*pp = 0x9E;
}
for(i=0, pp=(char *)(SCREEN_ADR+(18*160)+(55*2)+1); i<3; i++, pp+=2) {
*pp = 0x9E;
}
cprint(18, 18, "==> Press F1 to enter Fail-Safe Mode <==");
if(v->fail_safe & 2)
{
cprint(19, 15, "==> Press F2 to force Multi-Threading (SMP) <==");
}
deadline = RDTSC() + ((uint64_t)v->clks_msec) * msec;
/* loop for n seconds */
while (1) {
/* Is the time up? */
if (RDTSC() >= deadline) { break; }
/* Is expected Scan code pressed? */
c = get_key();
c &= 0x7f;
/* F1 */
if(c == scs) { v->fail_safe |= 1; break; }
/* F2 */
if(c == scs+1)
{
v->fail_safe ^= 2;
break;
}
/* F3 */
if(c == scs+2)
{
if(v->fail_safe & 2) { v->fail_safe ^= 2; }
v->fail_safe |= 8;
break;
}
}
cprint(18, 18, " ");
cprint(19, 15, " ");
for(i=0, pp=(char *)(SCREEN_ADR+(18*160)+(18*2)+1); i<40; i++, pp+=2) {
*pp = 0x17;
}
}
static void display_init(void)
{
int i;
volatile char *pp;
serial_echo_init();
serial_echo_print("[LINE_SCROLL;24r"); /* Set scroll area row 7-23 */
serial_echo_print("[H[2J"); /* Clear Screen */
serial_echo_print("[37m[44m");
serial_echo_print("[0m");
serial_echo_print("[37m[44m");
/* Clear screen & set background to blue */
for(i=0, pp=(char *)(SCREEN_ADR); i<80*24; i++) {
*pp++ = ' ';
*pp++ = 0x17;
}
/* Make the name background green */
for(i=0, pp=(char *)(SCREEN_ADR+1); i<TITLE_WIDTH; i++, pp+=2) {
*pp = 0x20;
}
cprint(0, 0, " Memtest86 5.01 ");
/* Set Blinking "+" */
for(i=0, pp=(char *)(SCREEN_ADR+1); i<2; i++, pp+=30) {
*pp = 0xA4;
}
cprint(0, 15, "+");
/* Do reverse video for the bottom display line */
for(i=0, pp=(char *)(SCREEN_ADR+1+(24 * 160)); i<80; i++, pp+=2) {
*pp = 0x71;
}
serial_echo_print("[0m");
}
/*
* Initialize test, setup screen and find out how much memory there is.
*/
void init(void)
{
int i;
arch_init_early();
display_init();
cprint(5, 60, "| Time: 0:00:00");
cprint(1, COL_MID,"Pass %");
cprint(2, COL_MID,"Test %");
cprint(3, COL_MID,"Test #");
cprint(4, COL_MID,"Testing: ");
cprint(5, COL_MID,"Pattern: ");
cprint(1, 0, "CLK: (32b Mode)");
cprint(2, 0, "L1 Cache: Unknown ");
cprint(3, 0, "L2 Cache: Unknown ");
cprint(4, 0, "L3 Cache: None ");
cprint(5, 0, "Memory : ");
cprint(6, 0, "------------------------------------------------------------------------------");
cprint(7, 0, "Core#:");
cprint(8, 0, "State:");
cprint(9, 0, "Cores: Active / Total (Run: All) | Pass: 0 Errors: 0 ");
cprint(10, 0, "------------------------------------------------------------------------------");
/*
for(i=0, pp=(char *)(SCREEN_ADR+(5*160)+(53*2)+1); i<20; i++, pp+=2) {
*pp = 0x92;
}
for(i=0, pp=(char *)(SCREEN_ADR+0*160+1); i<80; i++, pp+=2) {
*pp = 0x47;
}
*/
cprint(7, 39, "| Chipset : Unknown");
cprint(8, 39, "| Memory Type : Unknown");
for(i=0; i < 6; i++) {
cprint(i, COL_MID-2, "| ");
}
footer();
aprint(5, 10, v->test_pages);
v->pass = 0;
v->msg_line = 0;
v->ecount = 0;
v->ecc_ecount = 0;
v->testsel = -1;
v->msg_line = LINE_SCROLL-1;
v->scroll_start = v->msg_line * 160;
v->erri.low_addr.page = 0x7fffffff;
v->erri.low_addr.offset = 0xfff;
v->erri.high_addr.page = 0;
v->erri.high_addr.offset = 0;
v->erri.min_bits = 32;
v->erri.max_bits = 0;
v->erri.min_bits = 32;
v->erri.max_bits = 0;
v->erri.maxl = 0;
v->erri.cor_err = 0;
v->erri.ebits = 0;
v->erri.hdr_flag = 0;
v->erri.tbits = 0;
for (i=0; tseq[i].msg != NULL; i++) {
tseq[i].errors = 0;
}
if (dmi_initialized) {
for (i=0; i < MAX_DMI_MEMDEVS; i++){
if (dmi_err_cnts[i] > 0) {
dmi_err_cnts[i] = 0;
}
}
}
arch_init();
/* Check fail safe */
failsafe(5000, 0x3B);
/* Initalize SMP */
initialise_cpus();
for (i = 0; i <num_cpus; i++) {
dprint(7, i+7, i%10, 1, 0);
cprint(8, i+7, "S");
}
dprint(9, 19, num_cpus, 2, 0);
if((v->fail_safe & 3) == 2)
{
cprint(LINE_CPU,9, "(SMP: Disabled)");
cprint(LINE_RAM,9, "Running...");
}
// dprint(10, 5, found_cpus, 2, 0);
/* Find Memory Specs */
if(v->fail_safe & 1)
{
cprint(LINE_CPU, COL_SPEC, " **** FAIL SAFE **** FAIL SAFE **** ");
cprint(LINE_RAM, COL_SPEC, " No detection, same reliability ");
} else {
find_controller();
get_spd_spec();
if(num_cpus <= 16 && !(v->fail_safe & 4)) { coretemp(); }
}
if(v->check_temp > 0 && !(v->fail_safe & 4))
{
cprint(LINE_CPU, 26, "| CPU Temp");
cprint(LINE_CPU+1, 26, "| øC");
}
beep(600);
beep(1000);
/* Record the start time */
v->startt = RDTSC();
v->snapt = v->startt;
if (l1_cache == 0) { l1_cache = 64; }
if (l2_cache == 0) { l1_cache = 512; }
v->printmode=PRINTMODE_ADDRESSES;
v->numpatn=0;
}
#define STEST_ADDR 0x100000 /* Measure memory speed starting at 1MB */
/* Measure and display CPU and cache sizes and speeds */
void cpu_cache_speed()
{
int i, off = 4;
ulong speed;
/* Print CPU speed */
if ((speed = cpuspeed()) > 0) {
if (speed < 999499) {
speed += 50; /* for rounding */
cprint(1, off, " . MHz");
dprint(1, off+1, speed/1000, 3, 1);
dprint(1, off+5, (speed/100)%10, 1, 0);
} else {
speed += 500; /* for rounding */
cprint(1, off, " MHz");
dprint(1, off, speed/1000, 5, 0);
}
extclock = speed;
}
/* Print out L1 cache info */
/* To measure L1 cache speed we use a block size that is 1/4th */
/* of the total L1 cache size since half of it is for instructions */
if (l1_cache) {
cprint(2, 0, "L1 Cache: K ");
dprint(2, 11, l1_cache, 3, 0);
if ((speed=memspeed(STEST_ADDR, (l1_cache/2)*1024, 200))) {
cprint(2, 16, " MB/s");
dprint(2, 16, speed, 6, 0);
}
}
/* Print out L2 cache info */
/* We measure the L2 cache speed by using a block size that is */
/* the size of the L1 cache. We have to fudge if the L1 */
/* cache is bigger than the L2 */
if (l2_cache) {
cprint(3, 0, "L2 Cache: K ");
dprint(3, 10, l2_cache, 4, 0);
if (l2_cache < l1_cache) {
i = l1_cache / 4 + l2_cache / 4;
} else {
i = l1_cache;
}
if ((speed=memspeed(STEST_ADDR, i*1024, 200))) {
cprint(3, 16, " MB/s");
dprint(3, 16, speed, 6, 0);
}
}
/* Print out L3 cache info */
/* We measure the L3 cache speed by using a block size that is */
/* 2X the size of the L2 cache. */
if (l3_cache)
{
cprint(4, 0, "L3 Cache: K ");
aprint(4, 10, l3_cache/4);
//dprint(4, 10, l3_cache, 4, 0);
i = l2_cache*2;
if ((speed=memspeed(STEST_ADDR, i*1024, 150))) {
cprint(4, 16, " MB/s");
dprint(4, 16, speed, 6, 0);
}
}
}
/* Measure and display memory speed, multitasked using all CPUs */
ulong spd[MAX_CPUS];
void get_mem_speed(int me, int ncpus)
{
int i;
ulong speed=0;
/* Determine memory speed. To find the memory speed we use
* A block size that is the sum of all the L1, L2 & L3 caches
* in all cpus * 6 */
i = (l3_cache + l2_cache + l1_cache) * 4;
/* Make sure that we have enough memory to do the test */
/* If not use all we have */
if ((1 + (i * 2)) > (v->plim_upper << 2)) {
i = ((v->plim_upper <<2) - 1) / 2;
}
speed = memspeed(STEST_ADDR, i * 1024, 100);
cprint(5, 16, " MB/s");
dprint(5, 16, speed, 6, 0);
}