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 phys_size_t ram_size = gd->ram_size;
101 * Check for overflow and limit ram size to some representable value.
102 * It is required that ram_base + ram_size must be representable by
103 * phys_size_t type and must be aligned by direct access, therefore
104 * calculate it from last 4kB sector which should work as alignment
107 if (gd->ram_base + ram_size < gd->ram_base)
108 ram_size = ((phys_size_t)~0xfffULL) - gd->ram_base;
111 #ifndef CONFIG_MAX_MEM_MAPPED
114 /* limit stack to what we can reasonable map */
115 return ((ram_size > CONFIG_MAX_MEM_MAPPED) ?
116 CONFIG_MAX_MEM_MAPPED : ram_size);