Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 3 | |
Jacob Garber | 5cf9ccc | 2019-08-08 13:35:31 -0600 | [diff] [blame] | 4 | #include <stdint.h> |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 5 | #include <lib.h> |
| 6 | #include <console/console.h> |
| 7 | |
| 8 | int 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 Leahy | 45fde70 | 2017-03-08 18:02:24 -0800 | [diff] [blame] | 16 | for (i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) { |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 17 | 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 Leahy | 45fde70 | 2017-03-08 18:02:24 -0800 | [diff] [blame] | 29 | for (i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) { |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 30 | 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 | } |