2010-03-19 03:33:40 +01:00
|
|
|
#include <lib.h> /* Prototypes */
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2003-06-17 10:42:17 +02:00
|
|
|
static void ram_fill(unsigned long start, unsigned long stop)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
unsigned long addr;
|
|
|
|
/*
|
|
|
|
* Fill.
|
|
|
|
*/
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "DRAM fill: 0x%08lx-0x%08lx\r\n", start, stop);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug("DRAM fill: ");
|
|
|
|
print_debug_hex32(start);
|
|
|
|
print_debug("-");
|
|
|
|
print_debug_hex32(stop);
|
|
|
|
print_debug("\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
for(addr = start; addr < stop ; addr += 4) {
|
|
|
|
/* Display address being filled */
|
2008-08-01 14:12:37 +02:00
|
|
|
if (!(addr & 0xfffff)) {
|
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "%08lx \r", addr);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug_hex32(addr);
|
2004-11-11 07:53:24 +01:00
|
|
|
print_debug(" \r");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
2010-03-28 23:31:30 +02:00
|
|
|
write_phys(addr, (u32)addr);
|
2003-04-22 21:02:15 +02:00
|
|
|
};
|
|
|
|
/* Display final address */
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "%08lx\r\nDRAM filled\r\n", addr);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug_hex32(addr);
|
|
|
|
print_debug("\r\nDRAM filled\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2003-06-17 10:42:17 +02:00
|
|
|
static void ram_verify(unsigned long start, unsigned long stop)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
unsigned long addr;
|
2004-11-11 07:53:24 +01:00
|
|
|
int i = 0;
|
2003-04-22 21:02:15 +02:00
|
|
|
/*
|
|
|
|
* Verify.
|
|
|
|
*/
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "DRAM verify: 0x%08lx-0x%08lx\r\n", start, stop);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug("DRAM verify: ");
|
|
|
|
print_debug_hex32(start);
|
|
|
|
print_debug_char('-');
|
|
|
|
print_debug_hex32(stop);
|
|
|
|
print_debug("\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
for(addr = start; addr < stop ; addr += 4) {
|
|
|
|
unsigned long value;
|
|
|
|
/* Display address being tested */
|
2008-08-01 14:12:37 +02:00
|
|
|
if (!(addr & 0xfffff)) {
|
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "%08lx \r", addr);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug_hex32(addr);
|
2004-11-11 07:53:24 +01:00
|
|
|
print_debug(" \r");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
value = read_phys(addr);
|
|
|
|
if (value != addr) {
|
|
|
|
/* Display address with error */
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_ERR, "Fail: @0x%08lx Read value=0x%08lx\r\n", addr, value);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2006-04-01 06:10:44 +02:00
|
|
|
print_err("Fail: @0x");
|
2003-04-22 21:02:15 +02:00
|
|
|
print_err_hex32(addr);
|
2006-04-01 06:10:44 +02:00
|
|
|
print_err(" Read value=0x");
|
2003-04-22 21:02:15 +02:00
|
|
|
print_err_hex32(value);
|
|
|
|
print_err("\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2004-11-11 07:53:24 +01:00
|
|
|
i++;
|
2006-04-01 06:10:44 +02:00
|
|
|
if(i>256) {
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "Aborting.\n\r");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2006-04-01 06:10:44 +02:00
|
|
|
print_debug("Aborting.\n\r");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2006-04-01 06:10:44 +02:00
|
|
|
break;
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Display final address */
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "%08lx", addr);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2003-04-22 21:02:15 +02:00
|
|
|
print_debug_hex32(addr);
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
|
|
|
|
2006-04-01 06:10:44 +02:00
|
|
|
if (i) {
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "\r\nDRAM did _NOT_ verify!\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2006-04-01 06:10:44 +02:00
|
|
|
print_debug("\r\nDRAM did _NOT_ verify!\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
|
|
|
die("DRAM ERROR");
|
2006-04-01 06:10:44 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "\r\nDRAM range verified.\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2006-04-01 06:10:44 +02:00
|
|
|
print_debug("\r\nDRAM range verified.\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2006-04-01 06:10:44 +02:00
|
|
|
}
|
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
|
|
|
|
*/
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "Testing DRAM : %08lx - %08lx\r\n", start, stop);
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2004-03-22 05:24:29 +01:00
|
|
|
print_debug("Testing DRAM : ");
|
|
|
|
print_debug_hex32(start);
|
|
|
|
print_debug("-");
|
|
|
|
print_debug_hex32(stop);
|
|
|
|
print_debug("\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
ram_fill(start, stop);
|
2010-03-28 23:31:30 +02:00
|
|
|
/* Make sure we don't read before we wrote */
|
|
|
|
phys_memory_barrier();
|
2003-04-22 21:02:15 +02:00
|
|
|
ram_verify(start, stop);
|
2008-08-01 14:12:37 +02:00
|
|
|
#if CONFIG_USE_PRINTK_IN_CAR
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "Done.\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#else
|
2004-03-22 05:24:29 +01:00
|
|
|
print_debug("Done.\r\n");
|
2008-08-01 14:12:37 +02:00
|
|
|
#endif
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|