2010-10-05 11:07:10 +02:00
|
|
|
#include <stdint.h>
|
2010-03-19 03:33:40 +01:00
|
|
|
#include <lib.h> /* Prototypes */
|
2010-10-05 11:07:10 +02:00
|
|
|
#include <console/console.h>
|
2010-03-19 03:33:40 +01:00
|
|
|
|
2010-03-28 23:31:30 +02:00
|
|
|
static void write_phys(unsigned long addr, u32 value)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2010-02-25 14:40:49 +01:00
|
|
|
// Assembler in lib/ is very ugly. But we properly guarded
|
|
|
|
// it so let's obey this one for now
|
|
|
|
#if CONFIG_SSE2
|
2003-06-17 10:42:17 +02:00
|
|
|
asm volatile(
|
|
|
|
"movnti %1, (%0)"
|
|
|
|
: /* outputs */
|
|
|
|
: "r" (addr), "r" (value) /* inputs */
|
2010-03-28 23:31:30 +02:00
|
|
|
#ifndef __GNUC__ /* GCC does not like empty clobbers? */
|
2003-06-17 10:42:17 +02:00
|
|
|
: /* clobbers */
|
2004-05-27 13:13:24 +02:00
|
|
|
#endif
|
2003-06-17 10:42:17 +02:00
|
|
|
);
|
|
|
|
#else
|
2003-05-19 21:16:21 +02:00
|
|
|
volatile unsigned long *ptr;
|
2003-04-22 21:02:15 +02:00
|
|
|
ptr = (void *)addr;
|
|
|
|
*ptr = value;
|
2003-06-17 10:42:17 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2010-03-28 23:31:30 +02:00
|
|
|
static u32 read_phys(unsigned long addr)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2003-05-19 21:16:21 +02:00
|
|
|
volatile unsigned long *ptr;
|
2003-04-22 21:02:15 +02:00
|
|
|
ptr = (void *)addr;
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
2010-03-28 23:31:30 +02:00
|
|
|
static void phys_memory_barrier(void)
|
|
|
|
{
|
|
|
|
#if CONFIG_SSE2
|
|
|
|
// Needed for movnti
|
|
|
|
asm volatile (
|
|
|
|
"sfence"
|
|
|
|
::
|
|
|
|
#ifdef __GNUC__ /* ROMCC does not like memory clobbers */
|
|
|
|
: "memory"
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
#ifdef __GNUC__ /* ROMCC does not like empty asm statements */
|
|
|
|
asm volatile ("" ::: "memory");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 08:09:14 +01:00
|
|
|
/**
|
|
|
|
* Rotate ones test pattern that access every bit on a 128bit wide
|
|
|
|
* memory bus. To test most address lines, addresses are scattered
|
|
|
|
* using 256B, 4kB and 64kB increments.
|
|
|
|
*
|
2015-01-05 00:47:39 +01:00
|
|
|
* @param idx Index to test pattern (0=<idx<0x400)
|
|
|
|
* @param addr Memory to access on idx
|
|
|
|
* @param value Value to write or read at addr
|
2012-03-17 08:09:14 +01:00
|
|
|
*/
|
|
|
|
static inline void test_pattern(unsigned short int idx,
|
|
|
|
unsigned long *addr, unsigned long *value)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2012-03-17 08:09:14 +01:00
|
|
|
uint8_t j, k;
|
|
|
|
|
|
|
|
k = (idx >> 8) + 1;
|
|
|
|
j = (idx >> 4) & 0x0f;
|
|
|
|
*addr = idx & 0x0f;
|
|
|
|
*addr |= j << (4*k);
|
|
|
|
*value = 0x01010101 << (j & 7);
|
|
|
|
if (j & 8)
|
|
|
|
*value = ~(*value);
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2012-03-17 08:09:14 +01:00
|
|
|
/**
|
|
|
|
* Simple write-read-verify memory test. See console debug output for
|
|
|
|
* any dislocated bytes.
|
|
|
|
*
|
2015-01-05 00:47:39 +01:00
|
|
|
* @param start System memory offset, aligned to 128bytes
|
2012-03-17 08:09:14 +01:00
|
|
|
*/
|
|
|
|
static int ram_bitset_nodie(unsigned long start)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2012-03-17 08:09:14 +01:00
|
|
|
unsigned long addr, value, value2;
|
|
|
|
unsigned short int idx;
|
|
|
|
unsigned char failed, failures;
|
|
|
|
uint8_t verbose = 0;
|
|
|
|
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2012-03-17 08:09:14 +01:00
|
|
|
printk(BIOS_DEBUG, "DRAM bitset write: 0x%08lx\n", start);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2012-03-17 08:09:14 +01:00
|
|
|
print_debug("DRAM bitset write: 0x");
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug_hex32(start);
|
2010-03-31 16:47:43 +02:00
|
|
|
print_debug("\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2012-03-17 08:09:14 +01:00
|
|
|
for (idx=0; idx<0x400; idx+=4) {
|
|
|
|
test_pattern(idx, &addr, &value);
|
|
|
|
write_phys(start + addr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we don't read before we wrote */
|
|
|
|
phys_memory_barrier();
|
|
|
|
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2012-03-17 08:09:14 +01:00
|
|
|
printk(BIOS_DEBUG, "DRAM bitset verify: 0x%08lx\n", start);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2012-03-17 08:09:14 +01:00
|
|
|
print_debug("DRAM bitset verify: 0x");
|
|
|
|
print_debug_hex32(start);
|
|
|
|
print_debug("\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2012-03-17 08:09:14 +01:00
|
|
|
failures = 0;
|
|
|
|
for (idx=0; idx<0x400; idx+=4) {
|
|
|
|
test_pattern(idx, &addr, &value);
|
|
|
|
value2 = read_phys(start + addr);
|
|
|
|
|
|
|
|
failed = (value2 != value);
|
|
|
|
failures |= failed;
|
|
|
|
if (failed && !verbose) {
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2012-03-17 08:09:14 +01:00
|
|
|
printk(BIOS_ERR, "0x%08lx wr: 0x%08lx rd: 0x%08lx FAIL\n",
|
|
|
|
start + addr, value, value2);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2012-03-17 08:09:14 +01:00
|
|
|
print_err_hex32(start + addr);
|
|
|
|
print_err(" wr: 0x");
|
2003-04-22 21:02:15 +02:00
|
|
|
print_err_hex32(value);
|
2012-03-17 08:09:14 +01:00
|
|
|
print_err(" rd: 0x");
|
|
|
|
print_err_hex32(value2);
|
|
|
|
print_err(" FAIL\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2012-03-17 08:09:14 +01:00
|
|
|
}
|
|
|
|
if (verbose) {
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2012-03-17 08:09:14 +01:00
|
|
|
if ((addr & 0x0f) == 0)
|
|
|
|
printk(BIOS_DEBUG, "%08lx wr: %08lx rd:",
|
|
|
|
start + addr, value);
|
|
|
|
if (failed)
|
|
|
|
printk(BIOS_DEBUG, " %08lx!", value2);
|
|
|
|
else
|
|
|
|
printk(BIOS_DEBUG, " %08lx ", value2);
|
|
|
|
if ((addr & 0x0f) == 0xc)
|
|
|
|
printk(BIOS_DEBUG, "\n");
|
|
|
|
#else
|
|
|
|
if ((addr & 0x0f) == 0) {
|
|
|
|
print_dbg_hex32(start + addr);
|
|
|
|
print_dbg(" wr: ");
|
|
|
|
print_dbg_hex32(value);
|
|
|
|
print_dbg(" rd: ");
|
2006-04-01 06:10:44 +02:00
|
|
|
}
|
2012-03-17 08:09:14 +01:00
|
|
|
print_dbg_hex32(value2);
|
|
|
|
if (failed)
|
|
|
|
print_dbg("! ");
|
|
|
|
else
|
|
|
|
print_dbg(" ");
|
|
|
|
if ((addr & 0x0f) == 0xc)
|
|
|
|
print_dbg("\n");
|
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
}
|
2012-03-17 08:09:14 +01:00
|
|
|
if (failures) {
|
|
|
|
post_code(0xea);
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2010-03-31 16:47:43 +02:00
|
|
|
printk(BIOS_DEBUG, "\nDRAM did _NOT_ verify!\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2010-03-31 16:47:43 +02:00
|
|
|
print_debug("\nDRAM did _NOT_ verify!\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2011-12-02 16:23:06 +01:00
|
|
|
return 1;
|
2006-04-01 06:10:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2010-03-31 16:47:43 +02:00
|
|
|
printk(BIOS_DEBUG, "\nDRAM range verified.\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2010-03-31 16:47:43 +02:00
|
|
|
print_debug("\nDRAM range verified.\n");
|
2011-12-02 16:23:06 +01:00
|
|
|
return 0;
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2006-04-01 06:10:44 +02:00
|
|
|
}
|
2011-12-02 16:23:06 +01:00
|
|
|
return 0;
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 10:42:17 +02:00
|
|
|
void ram_check(unsigned long start, unsigned long stop)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This is much more of a "Is my DRAM properly configured?"
|
|
|
|
* test than a "Is my DRAM faulty?" test. Not all bits
|
|
|
|
* are tested. -Tyson
|
|
|
|
*/
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2012-03-17 08:09:14 +01:00
|
|
|
printk(BIOS_DEBUG, "Testing DRAM at: %08lx\n", start);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2012-03-17 08:09:14 +01:00
|
|
|
print_debug("Testing DRAM at: ");
|
2004-03-22 05:24:29 +01:00
|
|
|
print_debug_hex32(start);
|
2010-03-31 16:47:43 +02:00
|
|
|
print_debug("\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2012-03-17 08:09:14 +01:00
|
|
|
if (ram_bitset_nodie(start))
|
2011-12-02 16:23:06 +01:00
|
|
|
die("DRAM ERROR");
|
|
|
|
#if !defined(__ROMCC__)
|
|
|
|
printk(BIOS_DEBUG, "Done.\n");
|
|
|
|
#else
|
|
|
|
print_debug("Done.\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ram_check_nodie(unsigned long start, unsigned long stop)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
/*
|
|
|
|
* This is much more of a "Is my DRAM properly configured?"
|
|
|
|
* test than a "Is my DRAM faulty?" test. Not all bits
|
|
|
|
* are tested. -Tyson
|
|
|
|
*/
|
|
|
|
#if !defined(__ROMCC__)
|
2012-03-17 08:09:14 +01:00
|
|
|
printk(BIOS_DEBUG, "Testing DRAM at : %08lx\n", start);
|
2011-12-02 16:23:06 +01:00
|
|
|
#else
|
2012-03-17 08:09:14 +01:00
|
|
|
print_debug("Testing DRAM at : ");
|
2011-12-02 16:23:06 +01:00
|
|
|
print_debug_hex32(start);
|
|
|
|
print_debug("\n");
|
|
|
|
#endif
|
|
|
|
|
2012-03-17 08:09:14 +01:00
|
|
|
ret = ram_bitset_nodie(start);
|
2011-10-28 15:15:47 +02:00
|
|
|
#if !defined(__ROMCC__)
|
2010-03-31 16:47:43 +02:00
|
|
|
printk(BIOS_DEBUG, "Done.\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2010-03-31 16:47:43 +02:00
|
|
|
print_debug("Done.\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2011-12-02 16:23:06 +01:00
|
|
|
return ret;
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2013-06-08 18:32:36 +02:00
|
|
|
int ram_check_noprint_nodie(unsigned long start, unsigned long stop)
|
|
|
|
{
|
|
|
|
unsigned long addr, value, value2;
|
|
|
|
unsigned short int idx;
|
|
|
|
unsigned char failed, failures;
|
|
|
|
|
|
|
|
for (idx=0; idx<0x400; idx+=4) {
|
|
|
|
test_pattern(idx, &addr, &value);
|
|
|
|
write_phys(start + addr, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we don't read before we wrote */
|
|
|
|
phys_memory_barrier();
|
|
|
|
|
|
|
|
failures = 0;
|
|
|
|
for (idx=0; idx<0x400; idx+=4) {
|
|
|
|
test_pattern(idx, &addr, &value);
|
|
|
|
value2 = read_phys(start + addr);
|
|
|
|
|
|
|
|
failed = (value2 != value);
|
|
|
|
failures |= failed;
|
|
|
|
}
|
|
|
|
return failures;
|
|
|
|
}
|
|
|
|
|
2010-03-28 23:31:30 +02:00
|
|
|
void quick_ram_check(void)
|
|
|
|
{
|
|
|
|
int fail = 0;
|
|
|
|
u32 backup;
|
|
|
|
backup = read_phys(CONFIG_RAMBASE);
|
|
|
|
write_phys(CONFIG_RAMBASE, 0x55555555);
|
|
|
|
phys_memory_barrier();
|
|
|
|
if (read_phys(CONFIG_RAMBASE) != 0x55555555)
|
|
|
|
fail=1;
|
|
|
|
write_phys(CONFIG_RAMBASE, 0xaaaaaaaa);
|
|
|
|
phys_memory_barrier();
|
|
|
|
if (read_phys(CONFIG_RAMBASE) != 0xaaaaaaaa)
|
|
|
|
fail=1;
|
|
|
|
write_phys(CONFIG_RAMBASE, 0x00000000);
|
|
|
|
phys_memory_barrier();
|
|
|
|
if (read_phys(CONFIG_RAMBASE) != 0x00000000)
|
|
|
|
fail=1;
|
|
|
|
write_phys(CONFIG_RAMBASE, 0xffffffff);
|
|
|
|
phys_memory_barrier();
|
|
|
|
if (read_phys(CONFIG_RAMBASE) != 0xffffffff)
|
|
|
|
fail=1;
|
|
|
|
|
|
|
|
write_phys(CONFIG_RAMBASE, backup);
|
|
|
|
if (fail) {
|
|
|
|
post_code(0xea);
|
|
|
|
die("RAM INIT FAILURE!\n");
|
|
|
|
}
|
|
|
|
phys_memory_barrier();
|
|
|
|
}
|