blob: 6154f221a0dfb40243a5c3aa6a2e19aad642212c [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
David Hendricks560c6432014-02-13 13:07:50 -08003
Jacob Garber5cf9ccc2019-08-08 13:35:31 -06004#include <stdint.h>
David Hendricks560c6432014-02-13 13:07:50 -08005#include <lib.h>
6#include <console/console.h>
7
8int primitive_memtest(uintptr_t base, uintptr_t size)
9{
10 uintptr_t *p;
11 uintptr_t i;
12 int bad = 0;
13
14 printk(BIOS_SPEW, "Performing primitive memory test.\n");
15 printk(BIOS_SPEW, "DRAM start: 0x%08x, DRAM size: 0x%08x", base, size);
Lee Leahy45fde702017-03-08 18:02:24 -080016 for (i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) {
David Hendricks560c6432014-02-13 13:07:50 -080017 if (i % 0x100000 == 0) {
18 if ((i % 0x800000) == 0)
19 printk(BIOS_SPEW, "\n");
20 else if (i != 0)
21 printk(BIOS_SPEW, " ");
22 printk(BIOS_SPEW, "0x%08x", i);
23 }
24 p = (uintptr_t *)i;
25 *p = i;
26 }
27
28 printk(BIOS_SPEW, "\n\nReading back DRAM content");
Lee Leahy45fde702017-03-08 18:02:24 -080029 for (i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) {
David Hendricks560c6432014-02-13 13:07:50 -080030 if (i % 0x100000 == 0) {
31 if ((i % 0x800000) == 0)
32 printk(BIOS_SPEW, "\n");
33 else if (i != 0)
34 printk(BIOS_SPEW, " ");
35 printk(BIOS_SPEW, "0x%08x", i);
36 }
37
38 p = (uintptr_t *)i;
39 if (*p != i) {
40 printk(BIOS_SPEW, "\n0x%08zx: got 0x%zx\n", i, *p);
41 bad++;
42 }
43 }
44
45 printk(BIOS_SPEW, "\n");
46 printk(BIOS_SPEW, "%d errors\n", bad);
47
48 return bad;
49}