2004-01-07 06:38:14 +08:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 15:37:19 +08:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2004-01-07 06:38:14 +08:00
|
|
|
*/
|
|
|
|
|
2014-02-12 03:57:26 +08:00
|
|
|
#include <common.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2006-11-07 00:06:36 +08:00
|
|
|
#ifdef __PPC__
|
|
|
|
/*
|
|
|
|
* At least on G2 PowerPC cores, sequential accesses to non-existent
|
|
|
|
* memory must be synchronized.
|
|
|
|
*/
|
|
|
|
# include <asm/io.h> /* for sync() */
|
|
|
|
#else
|
|
|
|
# define sync() /* nothing */
|
|
|
|
#endif
|
2004-01-07 06:38:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check memory range for valid RAM. A simple memory test determines
|
|
|
|
* the actually available RAM size between addresses `base' and
|
|
|
|
* `base + maxsize'.
|
|
|
|
*/
|
2011-07-03 13:55:33 +08:00
|
|
|
long get_ram_size(long *base, long maxsize)
|
2004-01-07 06:38:14 +08:00
|
|
|
{
|
|
|
|
volatile long *addr;
|
|
|
|
long save[32];
|
|
|
|
long cnt;
|
|
|
|
long val;
|
|
|
|
long size;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
|
|
|
|
addr = base + cnt; /* pointer arith! */
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
save[i++] = *addr;
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
*addr = ~cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = base;
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
save[i] = *addr;
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
*addr = 0;
|
|
|
|
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
if ((val = *addr) != 0) {
|
|
|
|
/* Restore the original data before leaving the function.
|
|
|
|
*/
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
*addr = save[i];
|
|
|
|
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
|
|
|
|
addr = base + cnt;
|
2006-11-07 00:06:36 +08:00
|
|
|
sync ();
|
2004-01-07 06:38:14 +08:00
|
|
|
*addr = save[--i];
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
|
|
|
|
addr = base + cnt; /* pointer arith! */
|
|
|
|
val = *addr;
|
|
|
|
*addr = save[--i];
|
|
|
|
if (val != ~cnt) {
|
|
|
|
size = cnt * sizeof (long);
|
|
|
|
/* Restore the original data before leaving the function.
|
|
|
|
*/
|
|
|
|
for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
|
|
|
|
addr = base + cnt;
|
|
|
|
*addr = save[--i];
|
|
|
|
}
|
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (maxsize);
|
|
|
|
}
|
2014-02-12 03:57:26 +08:00
|
|
|
|
|
|
|
phys_size_t __weak get_effective_memsize(void)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_VERY_BIG_RAM
|
|
|
|
return gd->ram_size;
|
|
|
|
#else
|
|
|
|
/* limit stack to what we can reasonable map */
|
|
|
|
return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
|
|
|
|
CONFIG_MAX_MEM_MAPPED : gd->ram_size);
|
|
|
|
#endif
|
|
|
|
}
|