Add the virt machine rpmi=on/off option and wire the initial RPMI Base transport into machine realization for firmware clients that use RPMI platform management.
The option remains disabled by default. Enabling it requires a librpmi-enabled TCG build; KVM and builds without librpmi reject the configuration. The RPMI mailbox node is emitted when enabled, while the legacy reset and poweroff nodes remain available until the later service patches select the RPMI reset path. Size each A2P queue from one quarter of shared memory after reserving 8 KiB: 30 KiB per queue on virt. Signed-off-by: Subrahmanya Lingappa <[email protected]> --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 90 +++++++++++++++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 3 ++ 3 files changed, 94 insertions(+) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index d89fdfcc86..28d108faf8 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -49,6 +49,7 @@ config RISCV_VIRT imply VIRTIO_VGA imply TEST_DEVICES imply TPM_TIS_SYSBUS + imply RISCV_RPMI select DEVICE_TREE select RISCV_NUMA select GOLDFISH_RTC diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index de1c92463a..8a2ed43029 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -46,6 +46,8 @@ #include "hw/intc/riscv_aplic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" +#include "hw/misc/riscv_rpmi.h" +#include "hw/riscv/rpmi-fdt.h" #include "hw/core/platform-bus.h" #include "chardev/char.h" #include "system/device_tree.h" @@ -107,6 +109,8 @@ static const MemMapEntry virt_memmap[] = { /* UART1 supports page isolation from UART0 */ [VIRT_UART1] = { 0x1000a000, 0x100 }, [VIRT_FW_CFG] = { 0x10100000, 0x18 }, + [VIRT_RPMI_SHMEM] = { 0x10200000, 0x20000 }, + [VIRT_RPMI_DOORBELL] = { 0x10230000, 0x1000 }, [VIRT_FLASH] = { 0x20000000, 0x4000000 }, [VIRT_IMSIC_M] = { 0x24000000, VIRT_IMSIC_MAX_SIZE }, [VIRT_IMSIC_S] = { 0x28000000, VIRT_IMSIC_MAX_SIZE }, @@ -115,6 +119,10 @@ static const MemMapEntry virt_memmap[] = { [VIRT_DRAM] = { 0x80000000, 0x0 }, }; +#define VIRT_RPMI_A2P_REQ_SIZE \ + ((virt_memmap[VIRT_RPMI_SHMEM].size - 0x2000) / 4) +#define VIRT_RPMI_P2A_REQ_SIZE 0 + /* PCIe high mmio is fixed for RV32 */ #define VIRT32_HIGH_PCIE_MMIO_BASE 0x300000000ULL #define VIRT32_HIGH_PCIE_MMIO_SIZE (4 * GiB) @@ -470,6 +478,35 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16_t bdf) s->pci_iommu_bdf = bdf; } +static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState *s, + const uint32_t *hart_ids, + uint32_t hart_count) +{ + return (RiscvRpmiConfig) { + .doorbell_base = s->memmap[VIRT_RPMI_DOORBELL].base, + .shmem_base = s->memmap[VIRT_RPMI_SHMEM].base, + .shmem_size = s->memmap[VIRT_RPMI_SHMEM].size, + .a2p_req_size = VIRT_RPMI_A2P_REQ_SIZE, + .p2a_req_size = VIRT_RPMI_P2A_REQ_SIZE, + .platform_info = "QEMU RISC-V virt RPMI", + .hart_ids = hart_ids, + .hart_count = hart_count, + }; +} + +static void create_fdt_rpmi(RISCVVirtState *s, uint32_t *phandle) +{ + RiscvRpmiFdtMboxConfig cfg = { + .shmem_base = s->memmap[VIRT_RPMI_SHMEM].base, + .doorbell_base = s->memmap[VIRT_RPMI_DOORBELL].base, + .a2p_req_size = VIRT_RPMI_A2P_REQ_SIZE, + .p2a_req_size = VIRT_RPMI_P2A_REQ_SIZE, + .doorbell_size = s->memmap[VIRT_RPMI_DOORBELL].size, + }; + + riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, NULL); +} + static void finalize_fdt(RISCVVirtState *s) { uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1; @@ -506,6 +543,9 @@ static void finalize_fdt(RISCVVirtState *s) s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, FINISHER_RESET, FINISHER_PASS, true); + if (s->have_rpmi) { + create_fdt_rpmi(s, &phandle); + } create_fdt_uarts(s, irq_mmio_phandle); @@ -739,6 +779,18 @@ static void virt_machine_init(MachineState *machine) exit(1); } + if (s->have_rpmi) { +#ifndef CONFIG_LIBRPMI + error_report("RISC-V RPMI support is not compiled in"); + exit(1); +#else + if (kvm_enabled()) { + error_report("RISC-V RPMI support is not available with KVM"); + exit(1); + } +#endif + } + /* Initialize sockets */ mmio_irqchip = virtio_irqchip = pcie_irqchip = NULL; for (i = 0; i < socket_count; i++) { @@ -897,6 +949,21 @@ static void virt_machine_init(MachineState *machine) /* SiFive Test MMIO device */ sifive_test_create(s->memmap[VIRT_TEST].base); + if (s->have_rpmi) { + MachineClass *mc = MACHINE_GET_CLASS(machine); + const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine); + g_autofree uint32_t *rpmi_hart_ids = + g_new0(uint32_t, machine->smp.cpus); + RiscvRpmiConfig rpmi_cfg; + + for (i = 0; i < machine->smp.cpus; i++) { + rpmi_hart_ids[i] = possible_cpus->cpus[i].arch_id; + } + + rpmi_cfg = virt_rpmi_config(s, rpmi_hart_ids, machine->smp.cpus); + riscv_rpmi_create(&rpmi_cfg, &error_fatal); + } + /* VirtIO MMIO devices */ for (i = 0; i < VIRTIO_COUNT; i++) { sysbus_create_simple("virtio-mmio", @@ -1050,6 +1117,20 @@ static void virt_set_aclint(Object *obj, bool value, Error **errp) s->have_aclint = value; } +static bool virt_get_rpmi(Object *obj, Error **errp) +{ + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); + + return s->have_rpmi; +} + +static void virt_set_rpmi(Object *obj, bool value, Error **errp) +{ + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); + + s->have_rpmi = value; +} + bool virt_is_iommu_sys_enabled(RISCVVirtState *s) { return s->iommu_sys == ON_OFF_AUTO_ON; @@ -1166,6 +1247,15 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) "enable/disable emulating " "ACLINT devices"); + + object_class_property_add_bool(oc, "rpmi", virt_get_rpmi, + virt_set_rpmi); + object_class_property_set_description(oc, "rpmi", + "Set on/off to enable/disable " + "RISC-V RPMI devices; requires " + "librpmi and is unavailable with " + "KVM"); + object_class_property_add_str(oc, "aia", virt_get_aia, virt_set_aia); object_class_property_set_description(oc, "aia", diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 6e4fbf4b64..c9fb118fc8 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -55,6 +55,7 @@ struct RISCVVirtState { int fdt_size; bool have_aclint; + bool have_rpmi; RISCVVirtAIAType aia_type; int aia_guests; char *oem_id; @@ -82,6 +83,8 @@ enum { VIRT_VIRTIO, VIRT_UART1, VIRT_FW_CFG, + VIRT_RPMI_SHMEM, + VIRT_RPMI_DOORBELL, VIRT_IMSIC_M, VIRT_IMSIC_S, VIRT_FLASH,
