public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: u-boot@lists.denx.de
Cc: Simon Glass <sjg@chromium.org>
Subject: [PATCH] board_f: show_dram_config: Print also real DRAM size
Date: Sun, 11 Sep 2022 11:39:42 +0200	[thread overview]
Message-ID: <20220911093942.9570-1-pali@kernel.org> (raw)

32-bit U-Boot builds cannot use more than around 2 GB of DDR memory. But on
some platforms/boards it is possible to connect also 4 GB SODIMM DDR memory.
U-Boot currently prints only effective size of RAM which can use, which may
be misleading as somebody would expect that this line prints total size of
connected DDR modules. So change show_dram_config code to prints both real
and effective DRAM size if they are different. If they are same then print
just one number like before. It is possible that effective size is just few
bytes smaller than the real size, so print both numbers only in case
function print_size() prints formats them differently.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 common/board_f.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/common/board_f.c b/common/board_f.c
index 9e34fbee147e..3131a06db940 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -54,6 +54,7 @@
 #include <asm/sections.h>
 #include <dm/root.h>
 #include <linux/errno.h>
+#include <linux/log2.h>
 
 /*
  * Pointer to initial global data area
@@ -213,6 +214,30 @@ static int announce_dram_init(void)
 	return 0;
 }
 
+/*
+ * Check if the sizes in their natural units written in decimal format with
+ * one fraction number are same.
+ */
+static int sizes_near(unsigned long long size1, unsigned long long size2)
+{
+	unsigned int size1_scale = ilog2(size1) / 10 * 10;
+	unsigned int size1_val = (10 * size1 + ((1ULL << size1_scale) >> 1)) >> size1_scale;
+	unsigned int size2_scale = ilog2(size2) / 10 * 10;
+	unsigned int size2_val = (10 * size2 + ((1ULL << size2_scale) >> 1)) >> size2_scale;
+
+	if (size1_val == 10240) {
+		size1_val = 10;
+		size1_scale += 10;
+	}
+
+	if (size2_val == 10240) {
+		size2_val = 10;
+		size2_scale += 10;
+	}
+
+	return size1_scale == size2_scale && size1_val == size2_val;
+}
+
 static int show_dram_config(void)
 {
 	unsigned long long size;
@@ -229,7 +254,11 @@ static int show_dram_config(void)
 	}
 	debug("\nDRAM:  ");
 
-	print_size(size, "");
+	print_size(gd->ram_size, "");
+	if (!sizes_near(gd->ram_size, size)) {
+		printf(" (effective ");
+		print_size(size, ")");
+	}
 	board_add_ram_info(0);
 	putc('\n');
 
-- 
2.20.1


             reply	other threads:[~2022-09-11  9:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-11  9:39 Pali Rohár [this message]
2022-09-12 13:34 ` [PATCH] board_f: show_dram_config: Print also real DRAM size Simon Glass
2022-09-12 18:56   ` Pali Rohár
2022-09-12 21:58     ` Sean Anderson
2022-09-14 17:10       ` Simon Glass
2022-09-14 17:32         ` Pali Rohár
2022-09-14 18:31           ` Simon Glass
2022-09-18 11:30       ` Pali Rohár
2022-09-19 21:10         ` Simon Glass
2022-09-18 11:23 ` [PATCH v2] " Pali Rohár
2022-09-23 22:48   ` Tom Rini

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=20220911093942.9570-1-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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