[PATCH 2/2] rockchip: rk3588: Add Support for RAM Defines from ATAGs
Chris Morgan
macroalpha82 at gmail.com
Tue Mar 26 21:49:44 CET 2024
From: Chris Morgan <macromorgan at 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 at 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
More information about the U-Boot
mailing list