From 08d7d31384e94cb4972206cc37b7c8accd55209c Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Mon, 5 Feb 2024 20:16:26 +0300 Subject: 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/80363 Tested-by: build bot (Jenkins) Reviewed-by: Maximilian Brune --- src/mainboard/emulation/qemu-riscv/Kconfig | 1 + src/mainboard/emulation/qemu-riscv/cbmem.c | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/mainboard/emulation/qemu-riscv') diff --git a/src/mainboard/emulation/qemu-riscv/Kconfig b/src/mainboard/emulation/qemu-riscv/Kconfig index 94f9e56c5a..27b1b58127 100644 --- a/src/mainboard/emulation/qemu-riscv/Kconfig +++ b/src/mainboard/emulation/qemu-riscv/Kconfig @@ -23,6 +23,7 @@ if BOARD_EMULATION_QEMU_RISCV config BOARD_SPECIFIC_OPTIONS def_bool y select BOARD_ROMSIZE_KB_32768 + select FLATTENED_DEVICE_TREE select MISSING_BOARD_RESET select DRIVERS_UART_8250MEM select RISCV_HAS_OPENSBI 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 #include #include +#include +#include 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; } -- cgit v1.2.3