Skip to contentSkip to conversation

memsize.c: support larger memory ranges

RFC PATCH Superseded Wolfgang Denk 1 participant 2 messages May 12, 2008 – Jun 4, 2008

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 memsize.c: support larger memory ranges

The "long" data types used so far in "common/memsize.c" cause problems with larger memories, i. e. when accessing memory above 0x80000000.

Pointed out by David Bellavance <[email protected]> on Tue, 1 Apr 2008 14:19:37 -0400

---
 common/memsize.c |   26 +++++++++++++-------------
 include/common.h |    2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)
common/memsize.c +13 -13
index 6c275c9..17965d1 100644
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2004
+ * (C) Copyright 2004-2008
  * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
  *
  * See file CREDITS for list of people who contributed to this
@@ -37,16 +37,16 @@
  * the actually available RAM size between addresses `base' and
  * `base + maxsize'.
  */
-long get_ram_size(volatile long *base, long maxsize)
+phys_addr_t get_ram_size(volatile phys_addr_t *base, phys_addr_t maxsize)
 {
-	volatile long *addr;
-	long           save[32];
-	long           cnt;
-	long           val;
-	long           size;
-	int            i = 0;
+	volatile phys_addr_t *addr;
+	phys_addr_t	save[64];
+	phys_addr_t	cnt;
+	phys_addr_t	val;
+	phys_addr_t	size;
+	int		i = 0;
 
-	for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
+	for (cnt = (maxsize / sizeof (phys_addr_t)) >> 1; cnt > 0; cnt >>= 1) {
 		addr = base + cnt;	/* pointer arith! */
 		sync ();
 		save[i++] = *addr;
@@ -66,7 +66,7 @@ long get_ram_size(volatile long *base, long maxsize)
 		 */
 		sync ();
 		*addr = save[i];
-		for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+		for (cnt = 1; cnt < maxsize / sizeof(phys_addr_t); cnt <<= 1) {
 			addr  = base + cnt;
 			sync ();
 			*addr = save[--i];
@@ -74,15 +74,15 @@ long get_ram_size(volatile long *base, long maxsize)
 		return (0);
 	}
 
-	for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+	for (cnt = 1; cnt < maxsize / sizeof (phys_addr_t); cnt <<= 1) {
 		addr = base + cnt;	/* pointer arith! */
 		val = *addr;
 		*addr = save[--i];
 		if (val != ~cnt) {
-			size = cnt * sizeof (long);
+			size = cnt * sizeof (phys_addr_t);
 			/* Restore the original data before leaving the function.
 			 */
-			for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+			for (cnt <<= 1; cnt < maxsize / sizeof (phys_addr_t); cnt <<= 1) {
 				addr  = base + cnt;
 				*addr = save[--i];
 			}
include/common.h +1 -1
index d0f5704..c10b138 100644
@@ -285,7 +285,7 @@ void	jumptable_init(void);
 void	api_init (void);
 
 /* common/memsize.c */
-long	get_ram_size  (volatile long *, long);
+phys_addr_t get_ram_size (volatile phys_addr_t *, phys_addr_t);
 
 /* $(BOARD)/$(BOARD).c */
 void	reset_phy     (void);
Signature · 1 line
1.5.4.2
#1 lore raw

PATCH v2 1/1 memsize.c: support larger memory ranges

The "long" data types used so far in "common/memsize.c" cause problems with larger memories, i. e. when accessing memory above 0x80000000.

Pointed out by David Bellavance <[email protected]> on Tue, 1 Apr 2008 14:19:37 -0400

---
 common/memsize.c |   26 +++++++++++++-------------
 include/common.h |    2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)
common/memsize.c +13 -13
index 6c275c9..70c2801 100644
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2004
+ * (C) Copyright 2004-2008
  * Wolfgang Denk, DENX Software Engineering, wd at denx.de.
  *
  * See file CREDITS for list of people who contributed to this
@@ -37,16 +37,16 @@
  * the actually available RAM size between addresses `base' and
  * `base + maxsize'.
  */
-long get_ram_size(volatile long *base, long maxsize)
+phys_size_t get_ram_size(volatile phys_addr_t *base, phys_size_t maxsize)
 {
-	volatile long *addr;
-	long           save[32];
-	long           cnt;
-	long           val;
-	long           size;
-	int            i = 0;
+	volatile phys_addr_t *addr;
+	phys_addr_t	save[64];
+	phys_size_t	cnt;
+	phys_size_t	val;
+	phys_size_t	size;
+	int		i = 0;
 
-	for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
+	for (cnt = (maxsize / sizeof (phys_addr_t)) >> 1; cnt > 0; cnt >>= 1) {
 		addr = base + cnt;	/* pointer arith! */
 		sync ();
 		save[i++] = *addr;
@@ -66,7 +66,7 @@ long get_ram_size(volatile long *base, long maxsize)
 		 */
 		sync ();
 		*addr = save[i];
-		for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
+		for (cnt = 1; cnt < maxsize / sizeof(phys_addr_t); cnt <<= 1) {
 			addr  = base + cnt;
 			sync ();
 			*addr = save[--i];
@@ -74,15 +74,15 @@ long get_ram_size(volatile long *base, long maxsize)
 		return (0);
 	}
 
-	for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+	for (cnt = 1; cnt < maxsize / sizeof (phys_addr_t); cnt <<= 1) {
 		addr = base + cnt;	/* pointer arith! */
 		val = *addr;
 		*addr = save[--i];
 		if (val != ~cnt) {
-			size = cnt * sizeof (long);
+			size = cnt * sizeof (phys_addr_t);
 			/* Restore the original data before leaving the function.
 			 */
-			for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
+			for (cnt <<= 1; cnt < maxsize / sizeof (phys_addr_t); cnt <<= 1) {
 				addr  = base + cnt;
 				*addr = save[--i];
 			}
include/common.h +1 -1
index d0f5704..eea609c 100644
@@ -285,7 +285,7 @@ void	jumptable_init(void);
 void	api_init (void);
 
 /* common/memsize.c */
-long	get_ram_size  (volatile long *, long);
+phys_size_t get_ram_size (volatile phys_addr_t *, phys_size_t);
 
 /* $(BOARD)/$(BOARD).c */
 void	reset_phy     (void);
Signature · 1 line
1.5.4.1