1
2
3
4
5
6
7#include <common.h>
8
9DECLARE_GLOBAL_DATA_PTR;
10
11#ifdef __PPC__
12
13
14
15
16# include <asm/io.h>
17#else
18# define sync()
19#endif
20
21
22
23
24
25
26long get_ram_size(long *base, long maxsize)
27{
28 volatile long *addr;
29 long save[BITS_PER_LONG - 1];
30 long save_base;
31 long cnt;
32 long val;
33 long size;
34 int i = 0;
35
36 for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
37 addr = base + cnt;
38 sync();
39 save[i++] = *addr;
40 sync();
41 *addr = ~cnt;
42 }
43
44 addr = base;
45 sync();
46 save_base = *addr;
47 sync();
48 *addr = 0;
49
50 sync();
51 if ((val = *addr) != 0) {
52
53 sync();
54 *base = save_base;
55 for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
56 addr = base + cnt;
57 sync();
58 *addr = save[--i];
59 }
60 return (0);
61 }
62
63 for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
64 addr = base + cnt;
65 val = *addr;
66 *addr = save[--i];
67 if (val != ~cnt) {
68 size = cnt * sizeof(long);
69
70
71
72
73 for (cnt <<= 1;
74 cnt < maxsize / sizeof(long);
75 cnt <<= 1) {
76 addr = base + cnt;
77 *addr = save[--i];
78 }
79
80
81
82
83
84
85 return (size);
86 }
87 }
88 *base = save_base;
89
90 return (maxsize);
91}
92
93phys_size_t __weak get_effective_memsize(void)
94{
95#ifndef CONFIG_VERY_BIG_RAM
96 return gd->ram_size;
97#else
98
99 return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
100 CONFIG_MAX_MEM_MAPPED : gd->ram_size);
101#endif
102}
103