Blame view
common/memsize.c
2.18 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
c83bf6a2d Add a common get_... |
2 3 4 |
/* * (C) Copyright 2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
c83bf6a2d Add a common get_... |
5 |
*/ |
e38661634 common: Add get_e... |
6 |
#include <common.h> |
9b4a205f4 common: Move RAM-... |
7 |
#include <init.h> |
e38661634 common: Add get_e... |
8 9 |
DECLARE_GLOBAL_DATA_PTR; |
91650b3e4 Sequential access... |
10 11 12 13 14 15 16 17 18 |
#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 |
c83bf6a2d Add a common get_... |
19 20 21 22 23 24 |
/* * Check memory range for valid RAM. A simple memory test determines * the actually available RAM size between addresses `base' and * `base + maxsize'. */ |
a55d23ccf Remove volatile q... |
25 |
long get_ram_size(long *base, long maxsize) |
c83bf6a2d Add a common get_... |
26 27 |
{ volatile long *addr; |
67a2616af common/memsize.c:... |
28 |
long save[BITS_PER_LONG - 1]; |
c5da05cd4 common/memsize.c:... |
29 |
long save_base; |
c83bf6a2d Add a common get_... |
30 31 32 33 |
long cnt; long val; long size; int i = 0; |
cc8d698fa Revert "common/me... |
34 |
for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) { |
c83bf6a2d Add a common get_... |
35 |
addr = base + cnt; /* pointer arith! */ |
95099fee4 common/memsize.c:... |
36 |
sync(); |
cc8d698fa Revert "common/me... |
37 |
save[i++] = *addr; |
95099fee4 common/memsize.c:... |
38 |
sync(); |
cc8d698fa Revert "common/me... |
39 |
*addr = ~cnt; |
c83bf6a2d Add a common get_... |
40 |
} |
cc8d698fa Revert "common/me... |
41 42 |
addr = base; sync(); |
c5da05cd4 common/memsize.c:... |
43 |
save_base = *addr; |
cc8d698fa Revert "common/me... |
44 45 |
sync(); *addr = 0; |
8e7cba048 common/memsize.c:... |
46 |
sync(); |
cc8d698fa Revert "common/me... |
47 48 49 |
if ((val = *addr) != 0) { /* Restore the original data before leaving the function. */ sync(); |
c5da05cd4 common/memsize.c:... |
50 |
*base = save_base; |
cc8d698fa Revert "common/me... |
51 52 53 54 55 56 57 58 59 |
for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) { addr = base + cnt; sync(); *addr = save[--i]; } return (0); } for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) { |
c83bf6a2d Add a common get_... |
60 61 |
addr = base + cnt; /* pointer arith! */ val = *addr; |
cc8d698fa Revert "common/me... |
62 63 |
*addr = save[--i]; if (val != ~cnt) { |
95099fee4 common/memsize.c:... |
64 65 66 67 |
size = cnt * sizeof(long); /* * Restore the original data * before leaving the function. |
c83bf6a2d Add a common get_... |
68 |
*/ |
95099fee4 common/memsize.c:... |
69 70 71 |
for (cnt <<= 1; cnt < maxsize / sizeof(long); cnt <<= 1) { |
c83bf6a2d Add a common get_... |
72 |
addr = base + cnt; |
cc8d698fa Revert "common/me... |
73 |
*addr = save[--i]; |
c83bf6a2d Add a common get_... |
74 |
} |
218da804e common/memsize.c:... |
75 76 77 78 79 80 |
/* warning: don't restore save_base in this case, * it is already done in the loop because * base and base+size share the same physical memory * and *base is saved after *(base+size) modification * in first loop */ |
c83bf6a2d Add a common get_... |
81 82 |
return (size); } |
cc8d698fa Revert "common/me... |
83 |
} |
218da804e common/memsize.c:... |
84 |
*base = save_base; |
c83bf6a2d Add a common get_... |
85 86 87 |
return (maxsize); } |
e38661634 common: Add get_e... |
88 89 90 91 92 93 94 95 96 97 98 |
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 } |