David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
David Hendricks | 560c643 | 2014-02-13 13:07:50 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <inttypes.h> |
| 17 | #include <lib.h> |
| 18 | #include <console/console.h> |
| 19 | |
| 20 | int primitive_memtest(uintptr_t base, uintptr_t size) |
| 21 | { |
| 22 | uintptr_t *p; |
| 23 | uintptr_t i; |
| 24 | int bad = 0; |
| 25 | |
| 26 | printk(BIOS_SPEW, "Performing primitive memory test.\n"); |
| 27 | printk(BIOS_SPEW, "DRAM start: 0x%08x, DRAM size: 0x%08x", base, size); |
| 28 | for(i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) { |
| 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 | p = (uintptr_t *)i; |
| 37 | *p = i; |
| 38 | } |
| 39 | |
| 40 | printk(BIOS_SPEW, "\n\nReading back DRAM content"); |
| 41 | for(i = base; i < base + (size - 1) - sizeof(p); i += sizeof(p)) { |
| 42 | if (i % 0x100000 == 0) { |
| 43 | if ((i % 0x800000) == 0) |
| 44 | printk(BIOS_SPEW, "\n"); |
| 45 | else if (i != 0) |
| 46 | printk(BIOS_SPEW, " "); |
| 47 | printk(BIOS_SPEW, "0x%08x", i); |
| 48 | } |
| 49 | |
| 50 | p = (uintptr_t *)i; |
| 51 | if (*p != i) { |
| 52 | printk(BIOS_SPEW, "\n0x%08zx: got 0x%zx\n", i, *p); |
| 53 | bad++; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | printk(BIOS_SPEW, "\n"); |
| 58 | printk(BIOS_SPEW, "%d errors\n", bad); |
| 59 | |
| 60 | return bad; |
| 61 | } |