1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 #include <asm/global_data.h>
11 DECLARE_GLOBAL_DATA_PTR;
15 * At least on G2 PowerPC cores, sequential accesses to non-existent
16 * memory must be synchronized.
18 # include <asm/io.h> /* for sync() */
20 # define sync() /* nothing */
24 * Check memory range for valid RAM. A simple memory test determines
25 * the actually available RAM size between addresses `base' and
28 long get_ram_size(long *base, long maxsize)
31 long save[BITS_PER_LONG - 1];
38 for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
39 addr = base + cnt; /* pointer arith! */
53 if ((val = *addr) != 0) {
54 /* Restore the original data before leaving the function. */
57 for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
65 for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
66 addr = base + cnt; /* pointer arith! */
70 size = cnt * sizeof(long);
72 * Restore the original data
73 * before leaving the function.
76 cnt < maxsize / sizeof(long);
81 /* warning: don't restore save_base in this case,
82 * it is already done in the loop because
83 * base and base+size share the same physical memory
84 * and *base is saved after *(base+size) modification
95 phys_size_t __weak get_effective_memsize(void)
97 #ifndef CONFIG_VERY_BIG_RAM
100 /* limit stack to what we can reasonable map */
101 return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
102 CONFIG_MAX_MEM_MAPPED : gd->ram_size);