The riscv server soc requirements [1] dictates in rule "IOM_200" that the IOMMU must have at least 4 event counters. As it stands today we're creating an iommu-sys device with RISCV_IOMMU_IOCOUNT_NUM (31) counters.
Following the design of setting just the minimal spec requirements, set hpm-counters to 4. We're doing that by adding a new argument in riscv_create_iommu_sys(). In case more IOMMU parameters need to tweaked in the device we might consider a different approach, but for now this suffices. The hpm-counters value used in the 'virt' board is default val from riscv-iommu, i.e. there's no change in 'virt' board configuration with this patch. [1] https://docs.riscv.org/reference/server-soc/v1.0/server_soc_requirements.html Signed-off-by: Daniel Henrique Barboza <[email protected]> --- hw/riscv/riscv-iommu-sys.c | 4 ++++ hw/riscv/riscv-iommu.h | 1 + hw/riscv/server_platform_ref.c | 2 ++ hw/riscv/virt.c | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hw/riscv/riscv-iommu-sys.c b/hw/riscv/riscv-iommu-sys.c index 258c171efd..3a9e22080a 100644 --- a/hw/riscv/riscv-iommu-sys.c +++ b/hw/riscv/riscv-iommu-sys.c @@ -219,6 +219,7 @@ static void riscv_iommu_sys_init(Object *obj) DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, hwaddr addr, int base_irq, + int hpm_counters, bool is_32_bit) { DeviceState *iommu_sys = qdev_new(TYPE_RISCV_IOMMU_SYS); @@ -237,6 +238,9 @@ DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, is_32_bit ? 34 : 56, &error_fatal); + object_property_set_int(OBJECT(iommu_sys), "hpm-counters", + hpm_counters, &error_abort); + sysbus_realize_and_unref(SYS_BUS_DEVICE(iommu_sys), &error_fatal); return iommu_sys; diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h index 403d10b321..0f755b0992 100644 --- a/hw/riscv/riscv-iommu.h +++ b/hw/riscv/riscv-iommu.h @@ -107,6 +107,7 @@ void riscv_iommu_notify(RISCVIOMMUState *s, int vec_type); void riscv_iommu_fault(RISCVIOMMUState *s, struct riscv_iommu_fq_record *ev); DeviceState *riscv_create_iommu_sys(DeviceState *mmio_irqchip, hwaddr addr, int base_irq, + int hpm_counters, bool is_32_bit); typedef struct RISCVIOMMUContext RISCVIOMMUContext; diff --git a/hw/riscv/server_platform_ref.c b/hw/riscv/server_platform_ref.c index 5f485b1c79..f8016e14b0 100644 --- a/hw/riscv/server_platform_ref.c +++ b/hw/riscv/server_platform_ref.c @@ -67,6 +67,7 @@ #define SYSCON_POWEROFF 0x2 #define RVSERVER_PLATFORM_BUS_NUM_IRQS 8 +#define RVSERVER_IOMMU_HPM_COUNTERS 4 #define TYPE_RISCV_SERVER_REF_MACHINE MACHINE_TYPE_NAME("riscv-server-ref") OBJECT_DECLARE_SIMPLE_TYPE(RISCVServerRefMachineState, RISCV_SERVER_REF_MACHINE) @@ -636,6 +637,7 @@ static void rvserver_ref_machine_init(MachineState *machine) } riscv_create_iommu_sys(mmio_irqchip, s->memmap[RVSERVER_IOMMU_SYS].base, + RVSERVER_IOMMU_HPM_COUNTERS, IOMMU_SYS_IRQ, false); s->machine_done.notify = rvserver_ref_machine_done; diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 8bc5a7b072..88de49aa6e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -947,7 +947,8 @@ static void virt_machine_init(MachineState *machine) if (virt_is_iommu_sys_enabled(s)) { riscv_create_iommu_sys(mmio_irqchip, s->memmap[VIRT_IOMMU_SYS].base, - IOMMU_SYS_IRQ, riscv_is_32bit(&s->soc[0])); + IOMMU_SYS_IRQ, RISCV_IOMMU_IOCOUNT_NUM, + riscv_is_32bit(&s->soc[0])); } s->machine_done.notify = virt_machine_done; -- 2.43.0
