diff mbox series

[PULL,18/19] hw/riscv: virt: Limit RAM size in a 32-bit system

Message ID 20210218015934.1623959-19-alistair.francis@wdc.com
State New
Headers show
Series [PULL,01/19] target/riscv: Declare csr_ops[] with a known size | expand

Commit Message

Alistair Francis Feb. 18, 2021, 1:59 a.m. UTC
From: Bin Meng <bin.meng@windriver.com>

RV32 supports 34-bit physical address hence the maximum RAM size
should be limitted. Limit the RAM size to 10 GiB, which leaves
some room for PCIe high mmio space.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-id: 20210122122958.12311-4-bmeng.cn@gmail.com
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
 hw/riscv/virt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 1d05bb3ef9..4f44509360 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -590,6 +590,19 @@  static void virt_machine_init(MachineState *machine)
         }
     }
 
+    /* limit RAM size in a 32-bit system */
+    if (riscv_is_32bit(&s->soc[0])) {
+        /*
+         * Cast machine->ram_size to 64-bit for 32-bit host,
+         * to make the build on 32-bit host happy.
+         */
+        if ((uint64_t)(machine->ram_size) > 10 * GiB) {
+            /* 32-bit host won't have a chance to execute here */
+            machine->ram_size = 10 * GiB;
+            error_report("Limitting RAM size to 10 GiB");
+        }
+    }
+
     /* register system main memory (actual RAM) */
     memory_region_init_ram(main_mem, NULL, "riscv_virt_board.ram",
                            machine->ram_size, &error_fatal);