hw/riscv: Server Platform Reference Board
Subsystems (2)
v11 cover hw/riscv: Server Platform Reference Board
Greetings,
This version has review changes proposed by Drew in v10.
Most notable change is that we're now defaulting s->aia_guests to 5. Users can set a different value N using the already existing "aia_guests" machine option:
"-M riscv-server-ref,aia-guests=N"
Docs were also updated. We're now commiting to do a new board version for every riscv-server-ref spec release.
Patches are based on top of sdext-v9 patches:
"[PATCH v9 0/7] riscv: add initial sdext support"
Changes from v10:
- patch 2:
- added sdext as dependency
- renamed profile to "riscv-server-ref-1.0"
- reworded profile comment
- patch 3:
- added RVSERVER_IRQCHIP_DEFAULT_AIA_GUESTS macro, default value = 5
- s->aia_guests is now set to 5 by default. Users can set a different
value for testing purposes using "-M riscv-server-ref,aia-guests=N"
- fixed whitespace issues
- patch 5:
- reworded the "versioning" paragraph to make it clear that every new riscv-server-ref spec version will trigger a new version of the
riscv-server-ref board
- v10 link: https://lore.kernel.org/qemu-devel/[email protected]/
Daniel Henrique Barboza (5):
target/riscv/cpu.c: remove 'bare' condition for .profile target/riscv: add riscv-server-ref CPU hw/riscv: server platform reference machine tests/functional/riscv64: add riscv-server-ref tests
docs: add riscv-server-ref.rst
configs/devices/riscv64-softmmu/default.mak | 1 + docs/system/riscv/riscv-server-ref.rst | 65 ++ docs/system/target-riscv.rst | 1 + hw/riscv/Kconfig | 16 + hw/riscv/meson.build | 1 + hw/riscv/server_platform_ref.c | 790 ++++++++++++++++++++ target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 33 +- tests/functional/riscv64/meson.build | 2 + tests/functional/riscv64/test_opensbi.py | 4 + tests/functional/riscv64/test_server_ref.py | 88 +++ 11 files changed, 1001 insertions(+), 1 deletion(-) create mode 100644 docs/system/riscv/riscv-server-ref.rst create mode 100644 hw/riscv/server_platform_ref.c create mode 100755 tests/functional/riscv64/test_server_ref.py
Signature · 1 line
2.43.0
PATCH v11 1/5 target/riscv/cpu.c: remove 'bare' condition for .profile
We want to configure other CPU types to use profiles as an alternative to adding every profile extension explicitly, i.e. a profile is nothing more than an extension bundle.
This means that a vendor CPU can set .profile=rva23s64 while having the same handling as any other vendor CPU. Same thing with all other CPU types.
--- target/riscv/cpu.c | 1 - 1 file changed, 1 deletion(-)
target/riscv/cpu.c +0 -1
@@ -3103,7 +3103,6 @@ static void riscv_cpu_class_base_init(ObjectClass *c, const void *data) mcc->def->bare |= def->bare;if (def->profile) {assert (profile_extends (def->profile, mcc->def->profile)); -assert (mcc->def->bare); mcc->def->profile = def->profile; }if (def->misa_mxl_max) {
Signature · 1 line
2.43.0
PATCH v11 2/5 target/riscv: add riscv-server-ref CPU
In reply to Daniel Henrique BarbozaThe harts requirements of RISC-V server platform [1] require RVA23 ISA profile support and others.
We're going for a profile-based implementation, instead of a regular CPU that can inherit RVA23, to allow future CPUs to use it internally as a starting base for their own extension sets. There's also a new 'rvserver-ref-1.0' flag that can be used to set the extensions in the command line for other CPUs, which can be used for testing/debugging purposes.
Note that for all intents and purposes "riscv-server-ref" is a regular CPU and no, we're not trying to set a precedent of calling the riscv server platform spec a profile.
[1] defines in rule SEE_020 that we must support at least 11 debug triggers (4 for insn address, 4 for insn load/store, 1 for icount, one for int, one for excp). We're going for the minimum. If more triggers are needed users can set any trigger amount with:
-cpu riscv-server-ref,trigger-count=N
Note that N must be <= 128.
[1] https://github.com/riscv-non-isa/riscv-server-platform/blob/main/server_platform_requirements.adoc
--- target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
target/riscv/cpu-qom.h +1 -0
@@ -42,6 +42,7 @@#define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64")#define TYPE_RISCV_CPU_RVA23U64 RISCV_CPU_TYPE_NAME("rva23u64")#define TYPE_RISCV_CPU_RVA23S64 RISCV_CPU_TYPE_NAME("rva23s64") +#define TYPE_RISCV_CPU_RVSERVER_REF RISCV_CPU_TYPE_NAME("riscv-server-ref")#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")#define TYPE_RISCV_CPU_SIFIVE_E RISCV_CPU_TYPE_NAME("sifive-e")
target/riscv/cpu.c +32 -0
@@ -2424,11 +2424,36 @@ static RISCVCPUProfile RVA23S64 = { } }; +/* +* This riscv-server-ref entry isn't a profile per se but its +* CPU definition can be modelled as a profile that extends +* RVA23, with additional things on top of it, and allowing +* future CPUs to derive from it via +* ".profile = &RVServerRef1_0;". +*/ +static RISCVCPUProfile RVServerRef1_0 = { + .s_parent = &RVA23S64 , + .name ="riscv-server-ref-1.0" , + .satp_mode =VM_1_10_SV48 , + .ext_offsets = { +CPU_CFG_OFFSET (ext_zkr), +CPU_CFG_OFFSET (ext_sdext), +CPU_CFG_OFFSET (ext_sdtrig), +CPU_CFG_OFFSET (ext_ssaia), +CPU_CFG_OFFSET (ext_ssccfg), +/* ssstrict is always enabled for PRIV_VER_1_12 */ + +RISCV_PROFILE_EXT_LIST_END + } +}; + +RISCVCPUProfile *riscv_profiles[] = { &RVA22U64 , &RVA22S64 , &RVA23U64 , &RVA23S64 , + &RVServerRef1_0,NULL , };
@@ -3766,6 +3791,13 @@ static const TypeInfo riscv_cpu_type_infos[] = {#endif ), + DEFINE_RISCV_CPU(TYPE_RISCV_CPU_RVSERVER_REF, TYPE_RISCV_BARE_CPU, + .profile = &RVServerRef1_0, + .misa_mxl_max = MXL_RV64, + .cfg.max_satp_mode = VM_1_10_SV57, + .num_triggers = 11, + ), +#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY ) DEFINE_RISCV_CPU(TYPE_RISCV_CPU_BASE128, TYPE_RISCV_DYNAMIC_CPU, .cfg.max_satp_mode = VM_1_10_SV57,
Signature · 1 line
2.43.0
Re: [PATCH v11 2/5] target/riscv: add riscv-server-ref CPU
Quoted 107 lines · Daniel Henrique Barboza
The harts requirements of RISC-V server platform [1] require RVA23 ISA profile support and others.
We're going for a profile-based implementation, instead of a regular CPU that can inherit RVA23, to allow future CPUs to use it internally as a starting base for their own extension sets. There's also a new 'rvserver-ref-1.0' flag that can be used to set the extensions in the command line for other CPUs, which can be used for testing/debugging purposes.
Note that for all intents and purposes "riscv-server-ref" is a regular CPU and no, we're not trying to set a precedent of calling the riscv server platform spec a profile.
[1] defines in rule
SEE_020that we must support at least 11 debug triggers (4 for insn address, 4 for insn load/store, 1 for icount, one for int, one for excp). We're going for the minimum. If more triggers are needed users can set any trigger amount with:-cpu riscv-server-ref,trigger-count=N
Note that N must be <= 128.
[1] https://github.com/riscv-non-isa/riscv-server-platform/blob/main/server_platform_requirements.adoc
Suggested-by Icenowy Zheng <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Alistair Francis <[email protected]>Reviewed-by Matheus Ferst <[email protected]>Reviewed-by Chao Liu <[email protected]>Reviewed-by Sunil V L <[email protected]>--- target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)target/riscv/cpu-qom.h +1
-0@@ -42,6 +42,7 @@#define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64")#define TYPE_RISCV_CPU_RVA23U64 RISCV_CPU_TYPE_NAME("rva23u64")#define TYPE_RISCV_CPU_RVA23S64 RISCV_CPU_TYPE_NAME("rva23s64") +#define TYPE_RISCV_CPU_RVSERVER_REF RISCV_CPU_TYPE_NAME("riscv-server-ref")#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")#define TYPE_RISCV_CPU_SIFIVE_E RISCV_CPU_TYPE_NAME("sifive-e")target/riscv/cpu.c +32
-0@@ -2424,11 +2424,36 @@ static RISCVCPUProfile RVA23S64 = { } }; +/* +* This riscv-server-ref entry isn't a profile per se but its +* CPU definition can be modelled as a profile that extends +* RVA23, with additional things on top of it, and allowing +* future CPUs to derive from it via +* ".profile = &RVServerRef1_0;". +*/ +static RISCVCPUProfile RVServerRef1_0 = { + .s_parent = &RVA23S64 , + .name ="riscv-server-ref-1.0" , + .satp_mode =VM_1_10_SV48 , + .ext_offsets = { +CPU_CFG_OFFSET (ext_zkr), +CPU_CFG_OFFSET (ext_sdext), +CPU_CFG_OFFSET (ext_sdtrig), +CPU_CFG_OFFSET (ext_ssaia), +CPU_CFG_OFFSET (ext_ssccfg), +/* ssstrict is always enabled for PRIV_VER_1_12 */ + +RISCV_PROFILE_EXT_LIST_END + } +}; + +RISCVCPUProfile *riscv_profiles[] = { &RVA22U64 , &RVA22S64 , &RVA23U64 , &RVA23S64 , + &RVServerRef1_0,NULL , };@@ -3766,6 +3791,13 @@ static const TypeInfo riscv_cpu_type_infos[] = {#endif ), + DEFINE_RISCV_CPU(TYPE_RISCV_CPU_RVSERVER_REF, TYPE_RISCV_BARE_CPU, + .profile = &RVServerRef1_0, + .misa_mxl_max = MXL_RV64, + .cfg.max_satp_mode = VM_1_10_SV57, + .num_triggers = 11, + ), +#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY ) DEFINE_RISCV_CPU(TYPE_RISCV_CPU_BASE128, TYPE_RISCV_DYNAMIC_CPU, .cfg.max_satp_mode = VM_1_10_SV57,Signature · 1 line
2.43.0
Re: [PATCH v11 2/5] target/riscv: add riscv-server-ref CPU
More comments...
Quoted 15 lines · Andrew Jones
Quoted 14 lines · Daniel Henrique Barboza
The harts requirements of RISC-V server platform [1] require RVA23 ISA profile support and others.
We're going for a profile-based implementation, instead of a regular CPU that can inherit RVA23, to allow future CPUs to use it internally as a starting base for their own extension sets. There's also a new 'rvserver-ref-1.0' flag that can be used to set the extensions in the command line for other CPUs, which can be used for testing/debugging purposes.
Note that for all intents and purposes "riscv-server-ref" is a regular CPU and no, we're not trying to set a precedent of calling the riscv server platform spec a profile.
Quoted 6 lines
Quoted 6 lines
[1] defines in rule
SEE_020that we must support at least 11 debug triggers (4 for insn address, 4 for insn load/store, 1 for icount, one for int, one for excp). We're going for the minimum. If more triggers are needed users can set any trigger amount with:-cpu riscv-server-ref,trigger-count=N
s/trigger-count/num-triggers/
Quoted 2 lines
Quoted 2 lines
Note that N must be <= 128.
Why? Isn't the limit RV_MAX_TRIGGERS == 1024?
Quoted 34 lines
Quoted 34 lines
[1] https://github.com/riscv-non-isa/riscv-server-platform/blob/main/server_platform_requirements.adoc
Suggested-by Icenowy Zheng <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Alistair Francis <[email protected]>Reviewed-by Matheus Ferst <[email protected]>Reviewed-by Chao Liu <[email protected]>Reviewed-by Sunil V L <[email protected]>--- target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)target/riscv/cpu-qom.h +1
-0@@ -42,6 +42,7 @@#define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64")#define TYPE_RISCV_CPU_RVA23U64 RISCV_CPU_TYPE_NAME("rva23u64")#define TYPE_RISCV_CPU_RVA23S64 RISCV_CPU_TYPE_NAME("rva23s64") +#define TYPE_RISCV_CPU_RVSERVER_REF RISCV_CPU_TYPE_NAME("riscv-server-ref")#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")#define TYPE_RISCV_CPU_SIFIVE_E RISCV_CPU_TYPE_NAME("sifive-e")target/riscv/cpu.c +0
-0@@ -2424,11 +2424,36 @@ static RISCVCPUProfile RVA23S64 = { } };
Quoted 10 lines
target/riscv/cpu.c static RISCVCPUProfile RVA23S64 = { · line 2436
Quoted 10 lines
target/riscv/cpu.c +10
-0+/* +* This riscv-server-ref entry isn't a profile per se but its +* CPU definition can be modelled as a profile that extends +* RVA23, with additional things on top of it, and allowing +* future CPUs to derive from it via +* ".profile = &RVServerRef1_0;". +*/ +static RISCVCPUProfile RVServerRef1_0 = { + .s_parent = &RVA23S64 , + .name ="riscv-server-ref-1.0" ,
rva23 mandates Ss1p13, so shouldn't we have an explicit
.priv_spec = PRIV_VERSION_1_13_0
here?
Quoted 23 lines
Quoted 23 lines
target/riscv/cpu.c +15
-0+ .satp_mode = VM_1_10_SV48, + .ext_offsets = { +CPU_CFG_OFFSET (ext_zkr), +CPU_CFG_OFFSET (ext_sdext), +CPU_CFG_OFFSET (ext_sdtrig), +CPU_CFG_OFFSET (ext_ssaia), +CPU_CFG_OFFSET (ext_ssccfg), +/* ssstrict is always enabled for PRIV_VER_1_12 */ + + RISCV_PROFILE_EXT_LIST_END + } +}; + +RISCVCPUProfile *riscv_profiles[] = { &RVA22U64 , &RVA22S64 , &RVA23U64 , &RVA23S64 , + &RVServerRef1_0,NULL , };
Quoted 8 lines
target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3797
Quoted 8 lines
target/riscv/cpu.c +4
-0@@ -3766,6 +3791,13 @@ static const TypeInfo riscv_cpu_type_infos[] = {#endif ), + DEFINE_RISCV_CPU(TYPE_RISCV_CPU_RVSERVER_REF, TYPE_RISCV_BARE_CPU, + .profile = &RVServerRef1_0, + .misa_mxl_max = MXL_RV64, + .cfg.max_satp_mode = VM_1_10_SV57,
To stick to our minimalist approach, we could default the number of counters to six
.cfg.pmu_mask = MAKE_64BIT_MASK(3, 6),
See RVA_060. The user can get more counters with pmu-mask/pmu-num.
Quoted 1 line
target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3798
Quoted 1 line
target/riscv/cpu.c +1
-0+ .num_triggers = 11,
Outside the scope of this series, more debug-trigger work is needed for complete SEE_020 support. In particular, QEMU still needs interrupt and exception triggers and the required VMID/ASID filtering. The 11 slots configured here provide the intended capacity, but do not by themselves provide all the required trigger capabilities.
Quoted 10 lines
Quoted 9 lines
target/riscv/cpu.c +2
-0+ ), +#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY ) DEFINE_RISCV_CPU(TYPE_RISCV_CPU_BASE128, TYPE_RISCV_DYNAMIC_CPU, .cfg.max_satp_mode = VM_1_10_SV57,Signature · 1 line
2.43.0
Thanks,
drew
Re: [PATCH v11 2/5] target/riscv: add riscv-server-ref CPU
Quoted 24 lines · Andrew Jones
More comments...
Quoted 20 lines · Andrew Jones
Quoted 19 lines · Daniel Henrique Barboza
The harts requirements of RISC-V server platform [1] require RVA23 ISA profile support and others.
We're going for a profile-based implementation, instead of a regular CPU that can inherit RVA23, to allow future CPUs to use it internally as a starting base for their own extension sets. There's also a new 'rvserver-ref-1.0' flag that can be used to set the extensions in the command line for other CPUs, which can be used for testing/debugging purposes.
Note that for all intents and purposes "riscv-server-ref" is a regular CPU and no, we're not trying to set a precedent of calling the riscv server platform spec a profile.
[1] defines in rule
SEE_020that we must support at least 11 debug triggers (4 for insn address, 4 for insn load/store, 1 for icount, one for int, one for excp). We're going for the minimum. If more triggers are needed users can set any trigger amount with:
Quoted 8 lines
Quoted 1 line
Quoted 1 line
-cpu riscv-server-ref,trigger-count=N
s/trigger-count/num-triggers/
Quoted 2 lines
Quoted 2 lines
Note that N must be <= 128.
Why? Isn't the limit
RV_MAX_TRIGGERS== 1024?
Mostly because 1024 triggers is a silly number, a theoretical cap I came up with to not revisit the value later. Most CPUs in the wild has less that 16.
Alas, we're not doing any check for <= 128 triggers anyway so this part of the commit msg is misleading. I'll remove it to avoid confusion. The 1024 limit will still be enforced in the trigger code.
Quoted 48 lines
Quoted 35 lines
Quoted 35 lines
[1] https://github.com/riscv-non-isa/riscv-server-platform/blob/main/server_platform_requirements.adoc
Suggested-by Icenowy Zheng <[email protected]>Signed-off-by Daniel Henrique Barboza <[email protected]>Reviewed-by Alistair Francis <[email protected]>Reviewed-by Matheus Ferst <[email protected]>Reviewed-by Chao Liu <[email protected]>Reviewed-by Sunil V L <[email protected]>--- target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)target/riscv/cpu-qom.h +1
-0@@ -42,6 +42,7 @@#define TYPE_RISCV_CPU_RVA22S64 RISCV_CPU_TYPE_NAME("rva22s64")#define TYPE_RISCV_CPU_RVA23U64 RISCV_CPU_TYPE_NAME("rva23u64")#define TYPE_RISCV_CPU_RVA23S64 RISCV_CPU_TYPE_NAME("rva23s64") +#define TYPE_RISCV_CPU_RVSERVER_REF RISCV_CPU_TYPE_NAME("riscv-server-ref")#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")#define TYPE_RISCV_CPU_SIFIVE_E RISCV_CPU_TYPE_NAME("sifive-e")target/riscv/cpu.c +0
-0@@ -2424,11 +2424,36 @@ static RISCVCPUProfile RVA23S64 = { } };Quoted 10 lines
target/riscv/cpu.c static RISCVCPUProfile RVA23S64 = { · line 2436
Quoted 10 lines
target/riscv/cpu.c +10
-0+/* +* This riscv-server-ref entry isn't a profile per se but its +* CPU definition can be modelled as a profile that extends +* RVA23, with additional things on top of it, and allowing +* future CPUs to derive from it via +* ".profile = &RVServerRef1_0;". +*/ +static RISCVCPUProfile RVServerRef1_0 = { + .s_parent = &RVA23S64 , + .name ="riscv-server-ref-1.0" ,rva23 mandates Ss1p13, so shouldn't we have an explicit
Quoted 3 lines
.priv_spec =
PRIV_VERSION_1_13_0here?
We have code that updates priv_spec based on the highest priv version required for the profile.
I don't mind adding it explicitly here though, so might as well.
Quoted 36 lines
Quoted 24 lines
Quoted 24 lines
target/riscv/cpu.c +15
-0+ .satp_mode = VM_1_10_SV48, + .ext_offsets = { +CPU_CFG_OFFSET (ext_zkr), +CPU_CFG_OFFSET (ext_sdext), +CPU_CFG_OFFSET (ext_sdtrig), +CPU_CFG_OFFSET (ext_ssaia), +CPU_CFG_OFFSET (ext_ssccfg), +/* ssstrict is always enabled for PRIV_VER_1_12 */ + + RISCV_PROFILE_EXT_LIST_END + } +}; + +RISCVCPUProfile *riscv_profiles[] = { &RVA22U64 , &RVA22S64 , &RVA23U64 , &RVA23S64 , + &RVServerRef1_0,NULL , };Quoted 8 lines
target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3797
Quoted 8 lines
target/riscv/cpu.c +4
-0@@ -3766,6 +3791,13 @@ static const TypeInfo riscv_cpu_type_infos[] = {#endif ), + DEFINE_RISCV_CPU(TYPE_RISCV_CPU_RVSERVER_REF, TYPE_RISCV_BARE_CPU, + .profile = &RVServerRef1_0, + .misa_mxl_max = MXL_RV64, + .cfg.max_satp_mode = VM_1_10_SV57,To stick to our minimalist approach, we could default the number of counters to six
Quoted 3 lines
.cfg.pmu_mask =
MAKE_64BIT_MASK(3, 6),See
RVA_060. The user can get more counters with pmu-mask/pmu-num.
Fair enough.
Quoted 9 lines
Quoted 3 lines
target/riscv/cpu.c static const TypeInfo riscv_cpu_type_infos[] = { · line 3798
Quoted 3 lines
target/riscv/cpu.c +1
-0+ .num_triggers = 11,Outside the scope of this series, more debug-trigger work is needed for complete
SEE_020support. In particular, QEMU still needs interrupt and exception triggers and the required VMID/ASID filtering. The 11 slots configured here provide the intended capacity, but do not by themselves provide all the required trigger capabilities.
Right. This is sdtrig/sdext code (I guess) and we'll have to address it in a generic manner. We'll address that in a follow up.
Thanks,
Daniel
Quoted 15 lines
Quoted 11 lines
Quoted 10 lines
target/riscv/cpu.c +2
-0+ ), +#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY ) DEFINE_RISCV_CPU(TYPE_RISCV_CPU_BASE128, TYPE_RISCV_DYNAMIC_CPU, .cfg.max_satp_mode = VM_1_10_SV57,Signature · 1 line
2.43.0Thanks,
drew
PATCH v11 3/5 hw/riscv: server platform reference machine
In reply to Daniel Henrique BarbozaThe RISC-V Server Platform specification [1] defines a standardized set of hardware and software capabilities, that portable system software, such as OS and hypervisors can rely on being present in a RISC-V server platform.
The main features included in this emulation are:
- Based on riscv virt machine type;
- A new memory map as close as virt machine as possible;
- An always present IOMMU platform device (riscv-iommu-sys) that uses IRQs 36 to 39, one IRQ for queue, similar to the 'virt' board;
- AIA;
- PCIe AHCI;
- PCIe NIC;
- No virtio device;
- No fw_cfg device;
- No ACPI table provided;
- Only minimal device tree nodes;
- a platform bus for TPM support.
A note about TPM support: TPM devices in QEMU comes usually in two flavors - emulated or passthrough. A passthrough device requires a host TPM device that the QEMU process can borrow and it's usually coupled with KVM acceleration.
To use the TPM emulator we'll need help from an external TPM emulator called swtpm. More info can be found in [2]. For our purposes this is a process that, if running Ubuntu, can be installed via 'swtpm' package. We'll go back to it shortly.
For now, adding support for the emulated TPM device 'tpm-tis' (other TPM flavors might work as well, 'tpm-tis' is the one tested with this work) requires a platform bus. Adding a platform bus will open the door for more devices to be added in the board. This is ok - a reference board isn't a restricted board and users are free to add devices at their leisure.
Here's how to use tpm-tis with the riscv-server-ref board:
- in a separated shell/term run 'swtpm' (--log is optional):
$ mkdir /tmp/mytpm1 $ swtpm socket --tpmstate dir=/tmp/mytpm1 \ --ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock \ --tpm2 \ --log level=20
Then start QEMU with:
$ qemu-system-riscv64 -M riscv-server-ref (...) \ -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ -tpmdev emulator,id=tpm0,chardev=chrtpm\ -device tpm-tis-device,tpmdev=tpm0
[1] https://github.com/riscv-non-isa/riscv-server-platform
[2] https://qemu-project.gitlab.io/qemu/specs/tpm.html
--- configs/devices/riscv64-softmmu/default.mak | 1 + hw/riscv/Kconfig | 16 + hw/riscv/meson.build | 1 + hw/riscv/server_platform_ref.c | 790 ++++++++++++++++++++ 4 files changed, 808 insertions(+) create mode 100644 hw/riscv/server_platform_ref.c
configs/devices/riscv64-softmmu/default.mak +1 -0
@@ -9,6 +9,7 @@ # CONFIG_SIFIVE_E=n # CONFIG_SIFIVE_U=n # CONFIG_RISCV_VIRT=n +# CONFIG_RISCV_SERVER_PLATFORM_REF=n # CONFIG_MICROCHIP_PFSOC=n # CONFIG_SHAKTI_C=n # CONFIG_XIANGSHAN_KUNMINGHU=n
hw/riscv/Kconfig +16 -0
@@ -69,6 +69,22 @@ config RISCV_VIRT select ACPI select ACPI_PCI +config RISCV_SERVER_PLATFORM_REF + bool + default y + depends on RISCV64 + imply TPM_TIS_SYSBUS + select RISCV_NUMA + select GOLDFISH_RTC + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE + select PFLASH_CFI01 + select SERIAL + select RISCV_ACLINT + select RISCV_APLIC + select RISCV_IMSIC + select RISCV_IOMMU + config SHAKTI_C bool default y
hw/riscv/meson.build +1 -0
@@ -7,6 +7,7 @@ riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c')) riscv_ss.add(files('riscv_hart.c')) riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) +riscv_ss.add(when: 'CONFIG_RISCV_SERVER_PLATFORM_REF', if_true: files('server_platform_ref.c')) riscv_ss.add(when: 'CONFIG_SHAKTI_C', if_true: files('shakti_c.c')) riscv_ss.add(when: 'CONFIG_SIFIVE_E', if_true: files('sifive_e.c')) riscv_ss.add(when: 'CONFIG_SIFIVE_U', if_true: files('sifive_u.c'))
hw/riscv/server_platform_ref.c new file +790 -0
790 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v11 3/5] hw/riscv: server platform reference machine
Quoted 9 lines · Daniel Henrique Barboza
hw/riscv/Kconfig +1
-0@@ -69,6 +69,22 @@ config RISCV_VIRT select ACPI select ACPI_PCI +config RISCV_SERVER_PLATFORM_REF
hw/riscv/Kconfig config RISCV_VIRT · line 82
Quoted 10 lines
hw/riscv/Kconfig +10
-0+ bool + default y + depends on RISCV64 + imply TPM_TIS_SYSBUS + select RISCV_NUMA + select GOLDFISH_RTC + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE + select PFLASH_CFI01 + select SERIAL
This needs to select SERIAL_MM rather than SERIAL, since the machine calls serial_mm_init(). It also directly uses the platform bus, so it needs
select PLATFORM_BUS
The machine also creates an ICH9 AHCI controller, so keeping it would require selecting AHCI_ICH9.
However, SATA is optional for Server Platform v1.0, so I suggest dropping the default ICH9 AHCI controller instead. That would also remove the IDE/AHCI includes, NUM_SATA_PORTS, the AHCI-specific state, and its initialization. The base machine would then have no default storage controller, and users could add NVMe explicitly when needed.
Likewise, networking hardware is optional, so I suggest dropping the e1000e default NIC. pci_init_nic_devices() may remain for explicit -nic requests.
To make suitable optional devices such as NVMe available, I suggest
imply PCIE_DEVICES
rather than the broader PCI_DEVICES set.
hw/riscv/Kconfig config RISCV_VIRT · line 88
Quoted 6 lines
hw/riscv/Kconfig +6
-0+#include "system/kvm.h" +#include "system/qtest.h" +#include "system/tcg.h" +#include "kvm/kvm_riscv.h" +#include "system/tpm.h" +#include "system/qtest.h"
Duplicate system/qtest.h include.
hw/riscv/Kconfig config RISCV_VIRT
Quoted 7 lines
hw/riscv/Kconfig +7
-0+#define RVSERVER_IRQCHIP_NUM_MSIS 255 +#define RVSERVER_IRQCHIP_NUM_SOURCES 96 +#define RVSERVER_IRQCHIP_NUM_PRIO_BITS 3 +#define RVSERVER_IRQCHIP_MAX_GUESTS_BITS 3 +#define RVSERVER_IRQCHIP_MAX_GUESTS \ + ((1U << RVSERVER_IRQCHIP_MAX_GUESTS_BITS) - 1U) +#define RVSERVER_IRQCHIP_DEFAULT_AIA_GUESTS 5
nit: Please align these definitions with the related definitions above. Also, the two nearby #error strings have "accomodate" rather than "accommodate".
hw/riscv/Kconfig
Quoted 7 lines
hw/riscv/Kconfig +7
-0+enum { + RVSERVER_UART0_IRQ = 10, + RVSERVER_RTC_IRQ = 11, + RVSERVER_PCIE_IRQ = 32, /* 32 to 35 */ + IOMMU_SYS_IRQ = 36, /* 36 to 39 */ + RVSERVER_PLATFORM_BUS_IRQ = 40, /* 40 to 48 */ +};
RVSERVER_PLATFORM_BUS_NUM_IRQS is 8, so this should say 40 to 47. Please also align the assignments.
hw/riscv/Kconfig
Quoted 2 lines
hw/riscv/Kconfig +2
-0+static const MemMapEntry rvserver_ref_memmap[] = { + [RVSERVER_DEBUG] = { 0x0, 0x100 },
RVSERVER_DEBUG does not appear to be used.
hw/riscv/Kconfig
Quoted 7 lines
hw/riscv/Kconfig +7
-0+ riscv_aclint_mtimer_create(memmap[RVSERVER_ACLINT].base + + i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, + RISCV_ACLINT_DEFAULT_MTIMER_SIZE, + base_hartid, hart_count, + RISCV_ACLINT_DEFAULT_MTIMECMP, + RISCV_ACLINT_DEFAULT_MTIME, + RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true);
Server SoC v1.0 CTI_010 requires the time CSR to count in units of 1 ns, so we should define a machine-specific 1 GHz timebase rather than using the 10 MHz virt default, for example
#define RVSERVER_ACLINT_TIMEBASE_FREQ 1000000000
and use RVSERVER_ACLINT_TIMEBASE_FREQ in this call. The CPU FDT timebase-frequency property should use
kvm_enabled() ? kvm_riscv_get_timebase_frequency(&s->soc->harts[0]) :
RVSERVER_ACLINT_TIMEBASE_FREQhw/riscv/Kconfig
Quoted 4 lines
hw/riscv/Kconfig +4
-0+ if (!rvserver_aclint_allowed()) { + error_report("'aclint' is only available with TCG acceleration"); + exit(1); + }
This makes the machine TCG/qtest only. We can follow virt's support of KVM to enable it. The documentation can state that a conformant guest requires a conformant host, while allowing nonconformant hosts to be used for functional KVM testing.
hw/riscv/Kconfig
Quoted 12 lines
hw/riscv/Kconfig +12
-0+static void rvserver_ref_machine_instance_init(Object *obj) +{ + RISCVServerRefMachineState *s = RISCV_SERVER_REF_MACHINE(obj); + + s->flash[0] = riscv_flash_create(OBJECT(s), + "riscv-server-ref.flash0", + "pflash0", + RVSERVER_FLASH_SECTOR_SIZE); + s->flash[1] = riscv_flash_create(OBJECT(s), + "riscv-server-ref.flash1", + "pflash1", + RVSERVER_FLASH_SECTOR_SIZE);
virt has an instance finalizer which unreferences either flash device when initialization fails before realization. This machine should have the same cleanup and set instance_finalize in its TypeInfo.
hw/riscv/Kconfig
Quoted 3 lines
hw/riscv/Kconfig +3
-0+ static const char * const valid_cpu_types[] = { + TYPE_RISCV_CPU_RVSERVER_REF, + };
This needs a NULL terminator. MachineClass.valid_cpu_types is walked until NULL. For example, testing this with "-cpu max" printed:
The valid models are: riscv-server-ref, (null), (null)
KVM also needs TYPE_RISCV_CPU_HOST in the valid CPU types.
Thanks,
drew
Re: [PATCH v11 3/5] hw/riscv: server platform reference machine
Quoted 26 lines · Andrew Jones
Quoted 9 lines · Daniel Henrique Barboza
hw/riscv/Kconfig +1
-0@@ -69,6 +69,22 @@ config RISCV_VIRT select ACPI select ACPI_PCI +config RISCV_SERVER_PLATFORM_REFhw/riscv/Kconfig config RISCV_VIRT · line 82
Quoted 10 lines
hw/riscv/Kconfig +10
-0+ bool + default y + depends on RISCV64 + imply TPM_TIS_SYSBUS + select RISCV_NUMA + select GOLDFISH_RTC + select PCI + select PCI_EXPRESS_GENERIC_BRIDGE + select PFLASH_CFI01 + select SERIALThis needs to select
SERIAL_MMrather than SERIAL, since the machine callsserial_mm_init(). It also directly uses the platform bus, so it needsselect
PLATFORM_BUS
Quoted 8 lines
The machine also creates an ICH9 AHCI controller, so keeping it would require selecting
AHCI_ICH9.However, SATA is optional for Server Platform v1.0, so I suggest dropping the default ICH9 AHCI controller instead. That would also remove the IDE/AHCI includes,
NUM_SATA_PORTS, the AHCI-specific state, and its initialization. The base machine would then have no default storage controller, and users could add NVMe explicitly when needed.
I'll play around and see if we can still use SATA + ICH9 via the platform bus. We'll probably need to update the docs and tests too.
Note that this might imply adding additional stuff to support SATA hotplug as well. If the resulting code is more complex than what we have then I'd rather keep SATA + ich9 by default.
Quoted 3 lines
Likewise, networking hardware is optional, so I suggest dropping the e1000e default NIC.
pci_init_nic_devices()may remain for explicit -nic requests.
Same as above.
Quoted 16 lines
To make suitable optional devices such as NVMe available, I suggest
imply
PCIE_DEVICESrather than the broader
PCI_DEVICESset.hw/riscv/Kconfig config RISCV_VIRT · line 88
Quoted 6 lines
hw/riscv/Kconfig +6
-0+#include "system/kvm.h" +#include "system/qtest.h" +#include "system/tcg.h" +#include "kvm/kvm_riscv.h" +#include "system/tpm.h" +#include "system/qtest.h"Duplicate
system/qtest.hinclude.
Quoted 9 lines
hw/riscv/Kconfig config RISCV_VIRT
Quoted 7 lines
hw/riscv/Kconfig +7
-0+#define RVSERVER_IRQCHIP_NUM_MSIS 255 +#define RVSERVER_IRQCHIP_NUM_SOURCES 96 +#define RVSERVER_IRQCHIP_NUM_PRIO_BITS 3 +#define RVSERVER_IRQCHIP_MAX_GUESTS_BITS 3 +#define RVSERVER_IRQCHIP_MAX_GUESTS \ + ((1U << RVSERVER_IRQCHIP_MAX_GUESTS_BITS) - 1U) +#define RVSERVER_IRQCHIP_DEFAULT_AIA_GUESTS 5nit: Please align these definitions with the related definitions above.
I suppose you're talking about aligning the macros.
Quoted 31 lines
Also, the two nearby #error strings have "accomodate" rather than "accommodate".
hw/riscv/Kconfig
Quoted 7 lines
hw/riscv/Kconfig +7
-0+enum { + RVSERVER_UART0_IRQ = 10, + RVSERVER_RTC_IRQ = 11, + RVSERVER_PCIE_IRQ = 32, /* 32 to 35 */ + IOMMU_SYS_IRQ = 36, /* 36 to 39 */ + RVSERVER_PLATFORM_BUS_IRQ = 40, /* 40 to 48 */ +};
RVSERVER_PLATFORM_BUS_NUM_IRQSis 8, so this should say 40 to 47. Please also align the assignments.hw/riscv/Kconfig
Quoted 2 lines
hw/riscv/Kconfig +2
-0+static const MemMapEntry rvserver_ref_memmap[] = { + [RVSERVER_DEBUG] = { 0x0, 0x100 },
RVSERVER_DEBUGdoes not appear to be used.hw/riscv/Kconfig
Quoted 7 lines
hw/riscv/Kconfig +7
-0+ riscv_aclint_mtimer_create(memmap[RVSERVER_ACLINT].base + + i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, + RISCV_ACLINT_DEFAULT_MTIMER_SIZE, + base_hartid, hart_count, + RISCV_ACLINT_DEFAULT_MTIMECMP, + RISCV_ACLINT_DEFAULT_MTIME, + RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true);Server SoC v1.0
CTI_010requires the time CSR to count in units of 1 ns, so we should define a machine-specific 1 GHz timebase rather than using the 10 MHz virt default, for example
Quoted 7 lines
#define RVSERVER_ACLINT_TIMEBASE_FREQ 1000000000and use
RVSERVER_ACLINT_TIMEBASE_FREQin this call. The CPU FDT timebase-frequency property should usekvm_enabled() ? kvm_riscv_get_timebase_frequency(&s->soc->harts[0]) : RVSERVER_ACLINT_TIMEBASE_FREQ
The FDT code is doing all that, so in the end what we want is just a new RVSERVER macro with the 1Gb clock.
Quoted 10 lines
hw/riscv/Kconfig
Quoted 5 lines
hw/riscv/Kconfig +4
-0+ if (!rvserver_aclint_allowed()) { + error_report("'aclint' is only available with TCG acceleration"); + exit(1); + }This makes the machine TCG/qtest only. We can follow virt's support of KVM to enable it. The documentation can state that a conformant guest requires a conformant host, while allowing nonconformant hosts to be used for functional KVM testing.
I don't want to hold upstreaming of the base emulation because of KVM, in particular because there's a very, very high chance that we do not have KVM support for all the riscv-server-ref extensions anyway.
My idea is to implement KVM support for this board as a follow-up. We'll mark it as "experimental" since we'll boot with a KVM cpu that doesn't have all the required extensions (again, most likely).
We'll probably need to discuss if we're going to stick with just the "host" CPU type or if we want a riscv-server-ref type for KVM too.
Quoted 18 lines
hw/riscv/Kconfig
Quoted 13 lines
hw/riscv/Kconfig +12
-0+static void rvserver_ref_machine_instance_init(Object *obj) +{ + RISCVServerRefMachineState *s = RISCV_SERVER_REF_MACHINE(obj); + + s->flash[0] = riscv_flash_create(OBJECT(s), + "riscv-server-ref.flash0", + "pflash0", + RVSERVER_FLASH_SECTOR_SIZE); + s->flash[1] = riscv_flash_create(OBJECT(s), + "riscv-server-ref.flash1", + "pflash1", + RVSERVER_FLASH_SECTOR_SIZE);virt has an instance finalizer which unreferences either flash device when initialization fails before realization. This machine should have the same cleanup and set
instance_finalizein its TypeInfo.
Quoted 8 lines
hw/riscv/Kconfig
Quoted 3 lines
hw/riscv/Kconfig +3
-0+ static const char * const valid_cpu_types[] = { + TYPE_RISCV_CPU_RVSERVER_REF, + };This needs a NULL terminator. MachineClass.valid_cpu_types is walked until NULL. For example, testing this with "-cpu max" printed:
The valid models are: riscv-server-ref, (null), (null)
That's a good catch.
Quoted 2 lines
KVM also needs
TYPE_RISCV_CPU_HOSTin the valid CPU types.
True. We'll do it as a follow-up when we're sure which KVM types we're going to support
Thanks,
Daniel
Quoted 3 lines
Thanks,
drew
PATCH v11 4/5 tests/functional/riscv64: add riscv-server-ref tests
In reply to Daniel Henrique BarbozaAdd tests for the recently added riscv-server-ref machine:
- a new test_opensbi.py test. The idea is to have a quick test that can catch trivial regressions that would prevent OpenSBI to finish;
- a new Linux boot "thorough" test that will boot the machine up to the buildroot prompt.
- a TPM specific selftest for the riscv-server-ref board. The test will be skipped if there's no 'swtpm' in the host.
--- tests/functional/riscv64/meson.build | 2 + tests/functional/riscv64/test_opensbi.py | 4 + tests/functional/riscv64/test_server_ref.py | 88 +++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100755 tests/functional/riscv64/test_server_ref.py
tests/functional/riscv64/meson.build +2 -0
@@ -3,6 +3,7 @@ test_riscv64_timeouts = { 'boston' : 120, 'k230' : 120, + 'server_ref' : 120, 'tuxrun' : 120, }
@@ -15,6 +16,7 @@ tests_riscv64_system_thorough = [ 'endianness', 'boston', 'k230', + 'server_ref', 'sifive_u', 'tt_atlantis', 'tuxrun',
tests/functional/riscv64/test_opensbi.py +4 -0
@@ -36,5 +36,9 @@ def test_riscv_virt(self): self.set_machine('virt') self.boot_opensbi() + def test_riscv_server_ref(self): + self.set_machine('riscv-server-ref') + self.boot_opensbi() + if __name__ == '__main__': QemuSystemTest.main()
tests/functional/riscv64/test_server_ref.py new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v11 5/5 docs: add riscv-server-ref.rst
In reply to Daniel Henrique BarbozaAdd documentation for the new riscv-server-ref board.
--- docs/system/riscv/riscv-server-ref.rst | 65 ++++++++++++++++++++++++++ docs/system/target-riscv.rst | 1 + 2 files changed, 66 insertions(+) create mode 100644 docs/system/riscv/riscv-server-ref.rst
docs/system/riscv/riscv-server-ref.rst new file +65 -0
@@ -0,0 +1,65 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +RISC-V Server Platform Reference board (``riscv-server-ref``) +============================================================= + +The RISC-V Server Platform specification `spec`_ defines a standardized +set of hardware and software capabilities that portable system software, +such as OS and hypervisors, can rely on being present in a RISC-V server +platform. This machine aims to emulate this specification, providing +an environment for firmware/OS development and testing. + +`spec`_ is version 1.0 at the introduction of this board. For each new +supported spec version a new versioned board will be added, keeping +"riscv-server-ref" as an alias for the newest version supported. E.g. +for spec version 2.0: + +* riscv-server-ref-1.0 - board that complies with spec version 1.0 +* riscv-server-ref-2.0 - board that complies with spec version 2.0 +* riscv-server-ref - alias for riscv-server-ref-2.0 + +The main features included in the riscv-server-ref board are: + +* IOMMU platform device (riscv-iommu-sys) +* AIA +* PCIe AHCI +* PCIe NIC +* No virtio mmio bus +* No fw_cfg device +* No ACPI table +* Minimal device tree nodes + +There are multiple ways of using this reference board. The spec compliant way +is using an EDK2 image and a TPM device. The board was tested with the TPM +device ``tpm-tis`` that uses the external ``swtpm`` emulator. More info on how +to use this device can be found in `tpm`_. + +To use this board coupled with the tpm-tis device, first start the ``swtpm`` +process in a shell (the ``log`` parameter is optional): + +.. code-block:: bash + + $ mkdir /tmp/mytpm1 + $ swtpm socket --tpmstate dir=/tmp/mytpm1 \ + --ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock \ + --tpm2 \ + --log level=20 + +And then start QEMU with: + +.. code-block:: bash + + qemu-system-riscv64 -M riscv-server-ref \ + -bios fw_dynamic.bin \ + -kernel EDK2.fd \ + -drive file=nvme_disk.ext2,format=raw,id=hd0,if=none \ + -device ahci,id=ahci \ + -device ide-hd,drive=hd0,bus=ahci.0 \ + -chardev socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-tis-device,tpmdev=tpm0 \ + -nographic + + +.. _spec: https://github.com/riscv-non-isa/riscv-server-platform +.. _tpm: https://qemu-project.gitlab.io/qemu/specs/tpm.html
docs/system/target-riscv.rst +1 -0
@@ -70,6 +70,7 @@ undocumented; you can get a complete list by running riscv/microblaze-v-generic riscv/microchip-icicle-kit riscv/mips + riscv/riscv-server-ref riscv/shakti-c riscv/sifive_u riscv/tt_atlantis
Signature · 1 line
2.43.0
Re: [PATCH v11 5/5] docs: add riscv-server-ref.rst
On Wed, Sep 09, 2026 at 06:07:55PM -0300, Daniel Henrique Barboza wrote:
...
docs/system/riscv/riscv-server-ref.rst line 57
Quoted 3 lines
docs/system/riscv/riscv-server-ref.rst new file +3
-0+ -drive file=nvme_disk.ext2,format=raw,id=hd0,if=none \ + -device ahci,id=ahci \ + -device ide-hd,drive=hd0,bus=ahci.0 \
The image is named nvme_disk.ext2 but is attached as an AHCI IDE disk. If the default AHCI controller is removed as suggested in 3/5, please update the feature list and use an explicit NVMe device here, for example
-drive file=nvme_disk.ext2,format=raw,id=hd0,if=none \
-device nvme,drive=hd0,serial=ddaaddaa \The documentation should also state that the base machine has no default storage controller or NIC.
Also, checkpatch reports that the new documentation file is not covered by MAINTAINERS.
Thanks,
drew