Most devices on the RCPU memmap are not modeled yet in QEMU. Back the entire 4G memory view of the RCPU by a low priority unimplemented device. This prevents accesses to non-modeled device from faulting.
Signed-off-by: Portia Stephens <[email protected]> --- hw/riscv/Kconfig | 1 + hw/riscv/tt_atlantis.c | 20 ++++++++++++++++++++ include/hw/riscv/tt_atlantis.h | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index 4eccfa443e..8e1812923a 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -150,6 +150,7 @@ config TENSTORRENT select DS1338 select TMP105 select CPU_CLUSTER + select UNIMP config XIANGSHAN_KUNMINGHU bool diff --git a/hw/riscv/tt_atlantis.c b/hw/riscv/tt_atlantis.c index edf2180a98..66cbb2b8cf 100644 --- a/hw/riscv/tt_atlantis.c +++ b/hw/riscv/tt_atlantis.c @@ -519,6 +519,17 @@ static void load_fdt(TTAtlantisState *ams) create_fdt_memory(ms->fdt, ac->memmap, ms->ram_size); } +static void mmio_map_unimplemented(MemoryRegion *memory, SysBusDevice *dev, + const char *name, hwaddr addr, uint64_t size) +{ + qdev_prop_set_string(DEVICE(dev), "name", name); + qdev_prop_set_uint64(DEVICE(dev), "size", size); + sysbus_realize(dev, &error_abort); + + memory_region_add_subregion_overlap(memory, addr, + sysbus_mmio_get_region(dev, 0), -1000); +} + static void tt_atlantis_machine_done(Notifier *n, void *data) { TTAtlantisState *ams = container_of(n, TTAtlantisState, machine_done); @@ -596,6 +607,8 @@ static void tt_rcpu_cluster_init(Object *obj) TYPE_CPU_CLUSTER); object_initialize_child(OBJECT(&rc->cluster), "cpus", &rc->cpus, TYPE_RISCV_HART_ARRAY); + object_initialize_child(OBJECT(rc), "tt-rcpu.unimp-mem", &rc->unimp_mem, + TYPE_UNIMPLEMENTED_DEVICE); } static void tt_rcpu_cluster_realize(DeviceState *dev, Error **errp) @@ -651,6 +664,13 @@ static void tt_rcpu_cluster_realize(DeviceState *dev, Error **errp) if (!qdev_realize(DEVICE(&rc->cluster), NULL, errp)) { return; } + + /* + * Map the entire 4G memory view as unimplemented to prevent faults from + * devices that have not been modeled yet. + */ + mmio_map_unimplemented(&rc->memory, SYS_BUS_DEVICE(&rc->unimp_mem), + "tt-rcpu.unimp", 0, UINT32_MAX); } static void tt_rcpu_cluster_class_init(ObjectClass *oc, const void *data) diff --git a/include/hw/riscv/tt_atlantis.h b/include/hw/riscv/tt_atlantis.h index ceb138dc88..4dfeb993d4 100644 --- a/include/hw/riscv/tt_atlantis.h +++ b/include/hw/riscv/tt_atlantis.h @@ -16,6 +16,7 @@ #include "hw/misc/tt_atlantis_prcm.h" #include "hw/char/dw8250.h" #include "hw/cpu/cluster.h" +#include "hw/misc/unimp.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") @@ -63,6 +64,11 @@ struct TTRCPUClusterState { CPUClusterState cluster; MemoryRegion bootrom; MemoryRegion sram; + /* + * All device memory is backed by a catch-all unimplemented device to + * prevent faults on accesses to regions not modeled. + */ + UnimplementedDeviceState unimp_mem; }; struct TTAtlantisSoCState { -- 2.43.0
