[PATCH v2 12/16] riscv: Probe ram in dram_init

Sean Anderson seanga2 at gmail.com
Mon Oct 12 20:13:41 CEST 2020


If CONFIG_RAM is enabled, use the ram device to get the base/size of
memory. This provides an easy way for boards/cpus to hook into the
dram_init logic, without needing to provide a second SYS_CPU.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

(no changes since v1)

 arch/riscv/cpu/generic/dram.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/arch/riscv/cpu/generic/dram.c b/arch/riscv/cpu/generic/dram.c
index 1dc77efeca..fbcd4ddf5f 100644
--- a/arch/riscv/cpu/generic/dram.c
+++ b/arch/riscv/cpu/generic/dram.c
@@ -4,15 +4,41 @@
  */
 
 #include <common.h>
+#include <dm.h>
 #include <fdtdec.h>
 #include <init.h>
+#include <log.h>
+#include <ram.h>
 #include <linux/sizes.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
 {
+#if CONFIG_IS_ENABLED(RAM)
+	int ret;
+	struct ram_info info;
+	struct udevice *dev;
+
+	ret = uclass_get_device(UCLASS_RAM, 0, &dev);
+	if (ret) {
+		debug("DRAM init failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = ram_get_info(dev, &info);
+	if (ret) {
+		debug("Cannot get DRAM size: %d\n", ret);
+		return ret;
+	}
+
+	gd->ram_base = info.base;
+	gd->ram_size = info.size;
+
+	return 0;
+#else
 	return fdtdec_setup_mem_size_base();
+#endif
 }
 
 int dram_init_banksize(void)
-- 
2.28.0



More information about the U-Boot mailing list