Blame view
common/memsize.c
1.86 KB
c83bf6a2d Add a common get_... |
1 2 3 4 |
/* * (C) Copyright 2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
c83bf6a2d Add a common get_... |
6 |
*/ |
e38661634 common: Add get_e... |
7 8 9 |
#include <common.h> 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 28 29 30 31 32 33 34 35 |
{ 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! */ |
91650b3e4 Sequential access... |
36 |
sync (); |
c83bf6a2d Add a common get_... |
37 |
save[i++] = *addr; |
91650b3e4 Sequential access... |
38 |
sync (); |
c83bf6a2d Add a common get_... |
39 40 41 42 |
*addr = ~cnt; } addr = base; |
91650b3e4 Sequential access... |
43 |
sync (); |
c83bf6a2d Add a common get_... |
44 |
save[i] = *addr; |
91650b3e4 Sequential access... |
45 |
sync (); |
c83bf6a2d Add a common get_... |
46 |
*addr = 0; |
91650b3e4 Sequential access... |
47 |
sync (); |
c83bf6a2d Add a common get_... |
48 49 50 |
if ((val = *addr) != 0) { /* Restore the original data before leaving the function. */ |
91650b3e4 Sequential access... |
51 |
sync (); |
c83bf6a2d Add a common get_... |
52 53 54 |
*addr = save[i]; for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) { addr = base + cnt; |
91650b3e4 Sequential access... |
55 |
sync (); |
c83bf6a2d Add a common get_... |
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
*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); } |
e38661634 common: Add get_e... |
79 80 81 82 83 84 85 86 87 88 89 |
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 } |