public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Chris Morgan <macroalpha82@gmail.com>
To: u-boot@lists.denx.de
Cc: xypron.glpk@gmx.de, cym@rock-chips.com,
	kever.yang@rock-chips.com, philipp.tomsich@vrull.eu,
	sjg@chromium.org, trini@konsulko.com,
	eugen.hristev@collabora.com, jonas@kwiboo.se,
	Chris Morgan <macromorgan@hotmail.com>
Subject: [PATCH 2/2] rockchip: rk3588: Add Support for RAM Defines from ATAGs
Date: Tue, 26 Mar 2024 15:49:44 -0500	[thread overview]
Message-ID: <20240326204944.1572667-3-macroalpha82@gmail.com> (raw)
In-Reply-To: <20240326204944.1572667-1-macroalpha82@gmail.com>

From: Chris Morgan <macromorgan@hotmail.com>

Add support for defining the usable RAM from ATAGs provided by the
Rockchip binary TPL loader. This allows us to automatically account
for necessary memory holes on RK3588 devices with 16GB of RAM or
more, as well as ensure we can use the full amount of RAM available.

In the event we can't cleanly read the ATAG values from RAM or are
not running an RK3588 board, simply fall back to the old method of
detecting the RAM.

Tested on Indiedroid Nova with 4GB and 16GB of RAM.

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
---
 arch/arm/mach-rockchip/sdram.c | 58 ++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/arch/arm/mach-rockchip/sdram.c b/arch/arm/mach-rockchip/sdram.c
index 0d9a0aef6f..58b78466b0 100644
--- a/arch/arm/mach-rockchip/sdram.c
+++ b/arch/arm/mach-rockchip/sdram.c
@@ -10,6 +10,7 @@
 #include <ram.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
+#include <asm/arch-rockchip/atags.h>
 #include <asm/arch-rockchip/sdram.h>
 #include <dm/uclass-internal.h>
 
@@ -35,12 +36,69 @@ struct tos_parameter_t {
 	s64 reserve[8];
 };
 
+/*
+ * Read the ATAGs to identify all the memory banks. If we can't do it
+ * cleanly return 1 to note an unsuccessful attempt, otherwise return
+ * 0 for a successful attempt.
+ */
+int rockchip_atag_ram_banks(void)
+{
+	struct tag *t;
+	int bank_cnt;
+	size_t tmp;
+
+	if (!CONFIG_IS_ENABLED(ARM64) && !CONFIG_IS_ENABLED(ROCKCHIP_RK3588))
+		return 1;
+
+	t = atags_get_tag(ATAG_DDR_MEM);
+	if (!t)
+		return 1;
+
+	bank_cnt = t->u.ddr_mem.count;
+
+	/*
+	 * Check to make sure the first bank ends at 0xf0000000, if it
+	 * does not fall back to the other methods of RAM bank
+	 * detection.
+	 */
+	if (t->u.ddr_mem.bank[t->u.ddr_mem.count] != 0xf0000000)
+		return 1;
+
+	/*
+	 * Iterate over the RAM banks. If the start address of bank 0
+	 * is less than or equal to 0x200000, set it to 0x200000 to
+	 * reserve room for A-TF. Make sure the size of bank 0 doesn't
+	 * bleed into the address space for hardware (starting at
+	 * 0xf0000000). Banks 1 and on can be defined as-is.
+	 */
+	for (int i = 0; i < (t->u.ddr_mem.count); i++) {
+		if (i == 0) {
+			if (t->u.ddr_mem.bank[i] <= 0x200000)
+				gd->bd->bi_dram[i].start = 0x200000;
+			else
+				gd->bd->bi_dram[i].start = t->u.ddr_mem.bank[i];
+			tmp = gd->bd->bi_dram[i].start + t->u.ddr_mem.bank[(bank_cnt + i)];
+			if (tmp > 0xf0000000)
+				gd->bd->bi_dram[i].size = 0xf0000000 - gd->bd->bi_dram[i].start;
+			else
+				gd->bd->bi_dram[i].size = t->u.ddr_mem.bank[(bank_cnt + i)];
+		} else {
+			gd->bd->bi_dram[i].start = t->u.ddr_mem.bank[i];
+			gd->bd->bi_dram[i].size = t->u.ddr_mem.bank[(bank_cnt + i)];
+		}
+	};
+
+	return 0;
+}
+
 int dram_init_banksize(void)
 {
 	size_t ram_top = (unsigned long)(gd->ram_size + CFG_SYS_SDRAM_BASE);
 	size_t top = min((unsigned long)ram_top, (unsigned long)(gd->ram_top));
 
 #ifdef CONFIG_ARM64
+	if (!rockchip_atag_ram_banks())
+		return 0;
 	/* Reserve 0x200000 for ATF bl31 */
 	gd->bd->bi_dram[0].start = 0x200000;
 	gd->bd->bi_dram[0].size = top - gd->bd->bi_dram[0].start;
-- 
2.34.1


  parent reply	other threads:[~2024-03-26 20:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 20:49 [PATCH 0/2] Use ATAGs for RK3588 For RAM Info Chris Morgan
2024-03-26 20:49 ` [PATCH 1/2] rockchip: rk3588: Add support for ATAG parsing Chris Morgan
2024-03-27  9:45   ` Quentin Schulz
2024-03-27 10:32   ` Kever Yang
2024-03-27 12:12     ` Tom Rini
2024-03-27 13:32     ` Chris Morgan
2024-03-27 14:21       ` Eugen Hristev
2024-03-27 15:03         ` Chris Morgan
2024-03-28 20:02           ` Tom Rini
2024-03-28 21:58             ` Chris Morgan
2024-03-28 22:13               ` Tom Rini
2024-03-26 20:49 ` Chris Morgan [this message]
2024-03-27 10:51   ` [PATCH 2/2] rockchip: rk3588: Add Support for RAM Defines from ATAGs Quentin Schulz
2024-03-27 13:10     ` Jonas Karlman

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=20240326204944.1572667-3-macroalpha82@gmail.com \
    --to=macroalpha82@gmail.com \
    --cc=cym@rock-chips.com \
    --cc=eugen.hristev@collabora.com \
    --cc=jonas@kwiboo.se \
    --cc=kever.yang@rock-chips.com \
    --cc=macromorgan@hotmail.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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