mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: andrew.smirnov@gmail.com
Subject: [PATCH] i.MX6: esdctl: Fix a bug in memory probing code
Date: Thu, 13 Nov 2014 15:24:57 -0800	[thread overview]
Message-ID: <1415921097-26063-1-git-send-email-andrew.smirnov@gmail.com> (raw)

Old version of imx6_mmdc_add_mem did not use 64-bit arithmetic and
thus was prone to overflow on systems with 4GB of memory. It also did
not take into account the fact that i.MX6 does not support more than
3.8GB of memory and would report incorrect memory size. This commit
fixes both issues.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/esdctl.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
index f0d2b5b..566ec54 100644
--- a/arch/arm/mach-imx/esdctl.c
+++ b/arch/arm/mach-imx/esdctl.c
@@ -38,6 +38,13 @@
 #include <mach/imx53-regs.h>
 #include <mach/imx6-regs.h>
 
+
+#define MIN(a,b)				\
+	({ __typeof__ (a) _a = (a);		\
+		__typeof__ (b) _b = (b);	\
+		_a < _b ? _a : _b; })
+
+
 struct imx_esdctl_data {
 	unsigned long base0;
 	unsigned long base1;
@@ -280,11 +287,28 @@ static void imx_esdctl_v4_add_mem(void *esdctlbase, struct imx_esdctl_data *data
 			data->base1, imx_v4_sdram_size(esdctlbase, 1));
 }
 
+/*
+  On i.MX6 the adress space reserved for SDRAM is 0x10000000 to 0xFFFFFFFF
+  which makse the maximum supported RAM size to be 0xF0000000
+ */
+#define IMX6_MAX_SDRAM_SIZE (0xF0000000)
+
 static void imx6_mmdc_add_mem(void *mmdcbase, struct imx_esdctl_data *data)
 {
+	/* It is possible to have a configuration in which both chip
+	 * selects of the memory controller have 2GB of memory. To
+	 * account for this case we need to use 64-bit arithmetic and
+	 * also make sure we do not report more than
+	 * IMX6_MAX_SDRAM_SIZE bytes of memory availible */
+
+	u64 size_cs0 = imx6_mmdc_sdram_size(mmdcbase, 0);
+	u64 size_cs1 = imx6_mmdc_sdram_size(mmdcbase, 1);
+	u64 total    = size_cs0 + size_cs1;
+
+	resource_size_t size = MIN(total, IMX6_MAX_SDRAM_SIZE);
+
 	arm_add_mem_device("ram0", data->base0,
-			imx6_mmdc_sdram_size(mmdcbase, 0) +
-			imx6_mmdc_sdram_size(mmdcbase, 1));
+			size);
 }
 
 static int imx_esdctl_probe(struct device_d *dev)
-- 
1.9.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2014-11-13 23:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 23:24 Andrey Smirnov [this message]
2014-11-17  7:48 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415921097-26063-1-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox