summaryrefslogtreecommitdiff
path: root/src/mainboard/emulation/qemu-riscv/cbmem.c
diff options
context:
space:
mode:
authorAlper Nebi Yasak <alpernebiyasak@gmail.com>2024-02-05 20:16:26 +0300
committerFelix Held <felix-coreboot@felixheld.de>2024-06-14 12:35:22 +0000
commit08d7d31384e94cb4972206cc37b7c8accd55209c (patch)
tree3e11f4cd1d5a14eae3b5d77f530f5dd2fa4c1650 /src/mainboard/emulation/qemu-riscv/cbmem.c
parentd41ad724cd2430558e4ecbb5e90b769555b68c34 (diff)
mainboard/qemu-riscv: Get top of memory from device-tree blob
Trying to probe RAM space to figure out top of memory causes an exception on RISC-V virtual machines with recent versions of QEMU, but we temporarily enable exception handlers for that and use it to help detect if a RAM address is usable or not. However, QEMU docs recommend reading device information from the device-tree blob it provides us at the start of RAM. A previous commit adds a library function to parse device-tree blob that QEMU provides us. Use it to determine top of memory in RISC-V QEMU virtual machines, but still fall back to the RAM probing approach as a last-ditch effort. Change-Id: I9e4a95f49ad373675939329eef40d7423a4132ab Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/80363 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com>
Diffstat (limited to 'src/mainboard/emulation/qemu-riscv/cbmem.c')
-rw-r--r--src/mainboard/emulation/qemu-riscv/cbmem.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/mainboard/emulation/qemu-riscv/cbmem.c b/src/mainboard/emulation/qemu-riscv/cbmem.c
index e4d21ccb80..8c37957dd8 100644
--- a/src/mainboard/emulation/qemu-riscv/cbmem.c
+++ b/src/mainboard/emulation/qemu-riscv/cbmem.c
@@ -3,10 +3,17 @@
#include <cbmem.h>
#include <symbols.h>
#include <ramdetect.h>
+#include <device_tree.h>
+#include <mcall.h>
uintptr_t cbmem_top_chipset(void)
{
- //TODO get memory range from QEMUs FDT
+ uint64_t top;
+
+ top = fdt_get_memory_top((void *)HLS()->fdt);
+ if (top)
+ return MIN(top, (uint64_t)4 * GiB - 1);
+
size_t dram_mb_detected = probe_ramsize((uintptr_t)_dram, CONFIG_DRAM_SIZE_MB);
return (uintptr_t)_dram + dram_mb_detected * MiB;
}