Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 2 | |
Jacob Garber | 5cf9ccc | 2019-08-08 13:35:31 -0600 | [diff] [blame] | 3 | #include <stdint.h> |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 4 | #include <lib.h> |
| 5 | #include <console/console.h> |
| 6 | |
| 7 | int primitive_memtest(uintptr_t base, uintptr_t size) |
| 8 | { |
| 9 | uintptr_t *p; |
| 10 | uintptr_t i; |
| 11 | int bad = 0; |
| 12 | |
| 13 | printk(BIOS_SPEW, "Performing primitive memory test.\n"); |
| 14 | 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] | 15 | for (i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) { |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 16 | if (i % 0x100000 == 0) { |
| 17 | if ((i % 0x800000) == 0) |
| 18 | printk(BIOS_SPEW, "\n"); |
| 19 | else if (i != 0) |
| 20 | printk(BIOS_SPEW, " "); |
| 21 | printk(BIOS_SPEW, "0x%08x", i); |
| 22 | } |
| 23 | p = (uintptr_t *)i; |
| 24 | *p = i; |
| 25 | } |
| 26 | |
| 27 | printk(BIOS_SPEW, "\n\nReading back DRAM content"); |
Lee Leahy | 45fde70 | 2017-03-08 18:02:24 -0800 | [diff] [blame] | 28 | for (i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) { |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 29 | if (i % 0x100000 == 0) { |
| 30 | if ((i % 0x800000) == 0) |
| 31 | printk(BIOS_SPEW, "\n"); |
| 32 | else if (i != 0) |
| 33 | printk(BIOS_SPEW, " "); |
| 34 | printk(BIOS_SPEW, "0x%08x", i); |
| 35 | } |
| 36 | |
| 37 | p = (uintptr_t *)i; |
| 38 | if (*p != i) { |
| 39 | printk(BIOS_SPEW, "\n0x%08zx: got 0x%zx\n", i, *p); |
| 40 | bad++; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | printk(BIOS_SPEW, "\n"); |
| 45 | printk(BIOS_SPEW, "%d errors\n", bad); |
| 46 | |
| 47 | return bad; |
| 48 | } |