summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEddy Petrișor <eddy.petrisor@gmail.com>2016-02-02 22:15:28 +0200
committerTom Rini <trini@konsulko.com>2016-02-08 10:10:49 -0500
commit8e7cba048baae68ee0916a8f52b4304277328d5e (patch)
tree793b2b398d9a81aa9a8c800d3a332b4349d1aef7
parentab8dd5e6e66b9da31adaecdee473c8c962aaf837 (diff)
common/memsize.c: Simplify RAM size detection
The case of memory of size 0 is not that different from a memory of any other size, so we remove the duplicate code and treat the small differences when it is the case. Signed-off-by: Eddy Petrișor <eddy.petrisor@gmail.com>
-rw-r--r--common/memsize.c47
1 files changed, 21 insertions, 26 deletions
diff --git a/common/memsize.c b/common/memsize.c
index 0fb9ba57b6..5c0d279625 100644
--- a/common/memsize.c
+++ b/common/memsize.c
@@ -33,38 +33,28 @@ long get_ram_size(long *base, long maxsize)
long size;
int i = 0;
- for (cnt = (maxsize / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
+ for (cnt = (maxsize / sizeof(long)) >> 1; cnt >= 0; cnt >>= 1) {
addr = base + cnt; /* pointer arith! */
sync();
- save[i++] = *addr;
+ save[i] = *addr;
sync();
- *addr = ~cnt;
- }
-
- addr = base;
- sync();
- save[i] = *addr;
- sync();
- *addr = 0;
-
- sync();
- if ((val = *addr) != 0) {
- /* Restore the original data before leaving the function. */
- sync();
- *addr = save[i];
- for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
- addr = base + cnt;
- sync();
- *addr = save[--i];
+ if (cnt) {
+ i++;
+ *addr = ~cnt;
+ } else {
+ *addr = 0;
}
- return (0);
}
- for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+ sync();
+ cnt = 0;
+ do {
addr = base + cnt; /* pointer arith! */
val = *addr;
- *addr = save[--i];
- if (val != ~cnt) {
+ *addr = save[i--];
+ sync();
+ if (((cnt == 0) && (val != 0)) ||
+ ((cnt != 0) && (val != ~cnt))) {
size = cnt * sizeof(long);
/*
* Restore the original data
@@ -74,11 +64,16 @@ long get_ram_size(long *base, long maxsize)
cnt < maxsize / sizeof(long);
cnt <<= 1) {
addr = base + cnt;
- *addr = save[--i];
+ *addr = save[i--];
}
return (size);
}
- }
+
+ if (cnt)
+ cnt = cnt << 1;
+ else
+ cnt = 1;
+ } while (cnt < maxsize / sizeof(long));
return (maxsize);
}