riscv-to-apply queue
Subsystems (3)
From: Alistair Francis <[email protected]>
The following changes since commit 30e8a06b64aa58a3990ba39cb5d09531e7d265e0:
Merge tag 'net-pull-request' of https://github.com/jasowang/qemu into staging (2026-06-29 17:41:42 +0200)
are available in the Git repository at:
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20260701
for you to fetch changes up to 64ce9ac18757d79f3b5b337f7bcbdd0dabef3ce1:
hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0 (2026-07-01 20:14:20 +1000)
----------------------------------------------------------------
RISC-V PR for 11.1
* Fix IMSIC CSR write and add tests
* Parametrise debug trigger number
* Add 'svbare' satp-mode
* Fix RINTC PLIC context ID for KVM
* Avoid abort when reading vtype before env->xl is set
* Skip reset for KVM irqchip
* Skip FP/Vector sync on KVM_PUT_RUNTIME_STATE
* More FDT cleanups (PLIC)
* Make FCTL.BE in IOMMU read only 0
* Check DC.TC reserved bits in IOMMU
* Apply UXL WARL handling to vsstatus
* Set cmd_ill IOFENCE.C if rsvp bits are set in IOMMU
* Set RISCV_IOMMU_FQ_HDR_PV appropriately
* Fix MSI MRIF IOMMU interrupt-pending offset
* Report QEMU CPU archid as 42
* Check PMP before updating PTE
* Add the Tenstorrent Atlantis machine
----------------------------------------------------------------
Alistair Francis (1):
hw/riscv/atlantis: Ensure OpenSBI has a non-zero next_addr
Charlie Jenkins (1):
target/riscv: Report QEMU CPU archid as 42
Chris Rauer (1):
hw/i2c: Add DesignWare I2C Controller
Daniel Henrique Barboza (16):
target/riscv/cpu: add CPU unrealize callback target/riscv: dynamic alloc of debug trigger arrays target/riscv: add 'num-triggers' debug property target/riscv/cpu.c: add 'svbare' satp-mode hw/riscv/sifive_u.c: remove unneeded qemu_fdt_get_phandle() call hw/riscv/sifive_u.c: use intc_phandle in plic creation hw/riscv/sifive_u: add #address-cells in PLIC FDT hw/riscv/virt.c: change 'plic' nodename to 'interrupt-controller' hw/riscv: add create_fdt_plic() helper hw/riscv/riscv-iommu: rename regs_rw to regs hw/riscv/riscv-iommu.c: make FCTL.BE read only 0 hw/riscv/riscv-iommu: check DC.TC reserved bits hw/riscv/riscv-iommu: set cmd_ill IOFENCE.C rsvp bits are set hw/riscv/riscv-iommu.c: set RISCV_IOMMU_FQ_HDR_PV appropriately hw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offset hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0
Inochi Amaoto (1):
target/riscv: Check PMP before updating PTE
Joel Stanley (9):
target/riscv: Avoid NULL deref in IMSIC CSR write tests/functional/riscv64: Use newer kernel for tuxrun boot tests/functional/riscv64: Add virt machine AIA boot test hw/riscv/virt: Move AIA initialisation to helper file hw/riscv/aia: Provide number of irq sources hw/riscv/aia: Configure stride for the M-mode IMSIC hw/riscv: Add Tenstorrent Atlantis machine hw/riscv/atlantis: Integrate i2c controllers hw/riscv/atlantis: Add some i2c peripherals
Meng Zhuo (1):
target/riscv/kvm: skip FP/Vector sync on KVM_PUT_RUNTIME_STATE
Nicholas Piggin (4):
hw/riscv/boot: Describe discontiguous memory in boot_info hw/riscv/boot: Account for discontiguous memory when loading firmware target/riscv: tt-ascalon: Enable Zkr extension tests/functional/riscv64: Add tt-atlantis tests
Qingwei Hu (3):
hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM hw/intc: riscv_aplic: Skip reset for KVM irqchip hw/intc: riscv_imsic: Skip reset for KVM irqchip
SeungJu Cheon (1):
target/riscv: Apply UXL WARL handling to vsstatus
ZhengXiang Qin (1):
target/riscv: avoid abort when reading vtype before env->xl is set
MAINTAINERS | 21 + docs/system/riscv/tt_atlantis.rst | 41 ++ docs/system/target-riscv.rst | 1 + hw/riscv/aia.h | 26 + hw/riscv/riscv-iommu-bits.h | 4 + hw/riscv/riscv-iommu.h | 26 +- include/hw/i2c/designware_i2c.h | 56 ++ include/hw/riscv/boot.h | 12 +- include/hw/riscv/fdt-common.h | 5 + include/hw/riscv/sifive_u.h | 2 + include/hw/riscv/tt_atlantis.h | 64 +++ include/hw/riscv/virt.h | 2 +- target/riscv/cpu.h | 39 +- target/riscv/debug.h | 1 + hw/i2c/designware_i2c.c | 745 +++++++++++++++++++++++++++ hw/intc/riscv_aplic.c | 4 + hw/intc/riscv_imsic.c | 4 + hw/riscv/aia.c | 94 ++++ hw/riscv/boot.c | 34 +- hw/riscv/fdt-common.c | 30 ++ hw/riscv/k230.c | 8 +- hw/riscv/microchip_pfsoc.c | 8 +- hw/riscv/opentitan.c | 6 +- hw/riscv/riscv-iommu-hpm.c | 4 +- hw/riscv/riscv-iommu.c | 73 ++- hw/riscv/shakti_c.c | 6 +- hw/riscv/sifive_u.c | 48 +- hw/riscv/spike.c | 6 +- hw/riscv/tt_atlantis.c | 617 ++++++++++++++++++++++ hw/riscv/virt-acpi-build.c | 29 +- hw/riscv/virt.c | 148 ++---- hw/riscv/xiangshan_kmh.c | 6 +- target/riscv/cpu.c | 43 +- target/riscv/cpu_helper.c | 8 + target/riscv/csr.c | 48 +- target/riscv/debug.c | 46 +- target/riscv/kvm/kvm-cpu.c | 19 +- target/riscv/machine.c | 16 +- hw/i2c/Kconfig | 5 + hw/i2c/meson.build | 1 + hw/riscv/Kconfig | 13 + hw/riscv/meson.build | 2 + tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_opensbi.py | 4 + tests/functional/riscv64/test_tt_atlantis.py | 57 ++ tests/functional/riscv64/test_tuxrun.py | 11 +- 46 files changed, 2196 insertions(+), 248 deletions(-) create mode 100644 docs/system/riscv/tt_atlantis.rst create mode 100644 hw/riscv/aia.h create mode 100644 include/hw/i2c/designware_i2c.h create mode 100644 include/hw/riscv/tt_atlantis.h create mode 100644 hw/i2c/designware_i2c.c create mode 100644 hw/riscv/aia.c create mode 100644 hw/riscv/tt_atlantis.c create mode 100755 tests/functional/riscv64/test_tt_atlantis.py
[PULL 02/39] tests/functional/riscv64: Use newer kernel for tuxrun boot
From: Joel Stanley <[email protected]>
The published tuxrun kernel is 6.4 which predates the introduction of AIA support in Linux. Update it to a 6.11 kernel, the newest build on the tuxrun site.
Boot times on a laptop are slightly longer but still reasonable:
| v6.4.16 | v6.11.9 ---------------------|---------|-------- test_riscv64 | 4.82s | 5.56s ---------------------|---------|-------- test_riscv64_maxcpu | 4.94s | 5.30s
Message-ID: <[email protected]>
--- tests/functional/riscv64/test_tuxrun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/functional/riscv64/test_tuxrun.py +2 -2
@@ -17,8 +17,8 @@ class TuxRunRiscV64Test(TuxRunBaselineTest): ASSET_RISCV64_KERNEL = Asset( - 'https://storage.tuxboot.com/buildroot/20241119/riscv64/Image', - '2bd8132a3bf21570290042324fff48c987f42f2a00c08de979f43f0662ebadba') + 'https://storage.tuxboot.com/kernels/6.11.9/riscv64/Image', + '174f8bb87f08961e54fa3fcd954a8e31f4645f6d6af4dd43983d5e9841490fb0') ASSET_RISCV64_ROOTFS = Asset( 'https://storage.tuxboot.com/buildroot/20241119/riscv64/rootfs.ext4.zst', 'aa4736a9872651dfc0d95e709465eedf1134fd19d42b8cb305bfd776f9801004')
Signature · 1 line
2.54.0
[PULL 07/39] target/riscv/cpu.c: add 'svbare' satp-mode
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Seems like we forgot to add a flag to set satp-mode=bare. What we're doing instead is to set the CPU default satp-mode to 'off' to set it to bare ... assuming we know the default satp-mode. Otherwise one needs to do -cpu X,sv39=off,sv48=off,sv57=off,sv64=off to get a bare-mode CPU.
Add a flag to make this process easier. The name choice is based on the fact that I didn't find many references to 'mbare' in RISC-V docs, but 'svbare' is a flag name that toolchain uses to set satp-mode=bare. Might as well use the same name to help with cross project compat.
After this patch:
$ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64
$ dtc -I dtb -O dts fdt.dtb | grep mmu-type
mmu-type = "riscv,sv57";
$ ./build/qemu-system-riscv64 -M virt,dumpdtb=fdt.dtb -cpu rv64,svbare=on
$ dtc -I dtb -O dts fdt.dtb | grep mmu-type
mmu-type = "riscv,none";Message-ID: <[email protected]>
--- target/riscv/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/riscv/cpu.c +4 -1
@@ -418,7 +418,7 @@ int riscv_cpu_max_xlen(RISCVCPUClass *mcc)#ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str (const char *satp_mode_str) { -if (!strncmp (satp_mode_str,"mbare" ,5 )) { +if (!strncmp (satp_mode_str,"svbare" ,6 )) {return VM_1_10_MBARE ; }
@@ -1063,6 +1063,9 @@ void riscv_add_satp_mode_properties(Object *obj) {RISCVCPU *cpu =RISCV_CPU (obj); +object_property_add (obj,"svbare" ,"bool" , cpu_riscv_get_satp, + cpu_riscv_set_satp,NULL , &cpu->satp_modes); +if (cpu->env.misa_mxl ==MXL_RV32 ) {object_property_add (obj,"sv32" ,"bool" , cpu_riscv_get_satp, cpu_riscv_set_satp,NULL , &cpu->satp_modes);
Signature · 1 line
2.54.0
[PULL 06/39] target/riscv: add 'num-triggers' debug property
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
All CPUs have the same amount of triggers: 2 triggers per hart, set via RV_MAX_TRIGGERS. This is not enough anymore: we'll have at least one future CPU that will demand more triggers per hart when implementing the RISC-V Server Ref Platform, requiring at least 11 triggers per hart.
Parametrize the trigger amount using a new 'num_triggers' property. The default amount is kept at 2 for backwards compatibility. The new maximum is bumped to a generous 1024 triggers per hart, which hopefully will be enough for the foreseeable future.
The property can be set in two ways:
- a '.num_triggers' CPU definition flag, allowing CPUs to set a custom amount inside the CPU def in DEFINE_RISCV_CPU();
- a new 'num-triggers' user property. The user property has a higher priority than an existing '.num_triggers' CPU def setting.
Assuming a hypothetical case where a CPU 'X' is defined with '.num_triggers = 8':
- -cpu X,num-triggers=30 => num_triggers set to 30
- -cpu X (...) => num_triggers set to 8
For a CPU that doesn't set '.num_triggers':
- -cpu rv64,num-triggers=30 => num_triggers set to 30
- -cpu rv64 (...) => num_triggers set to 2
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 19 ++++++++++++++++++- target/riscv/cpu.c | 11 +++++++++++ target/riscv/debug.c | 16 ++++++++-------- 3 files changed, 37 insertions(+), 9 deletions(-)
target/riscv/cpu.h +18 -1
@@ -189,7 +189,22 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[];#define RV_VLEN_MAX 1024#define RV_MAX_MHPMEVENTS 32#define RV_MAX_MHPMCOUNTERS 32 -#define RV_MAX_TRIGGERS 2 + +/* +* The Debug 1.0 spec allows a humongous amount of triggers. Section +* "Enumeration" says: "The above algorithm reads back tselect so that +* implementations which have 2^n triggers only need to implement n +* bits of tselect.". tselect can have up to XLEN bits, so the max +* theoretical RV_MAX_TRIGGERS value is 2^XLEN. +* +* Allowing 2^XLEN triggers per hart is silly so we'll set a max to a +* modest 1024 triggers, which is way more than what we see current +* hardware use (most chips uses 2-4 triggers per hart, RISC-V Server +* Ref requires at least 11). With a 1024 max per hart we'll be set +* for a long time ... hopefully. +*/ +#define RV_MAX_TRIGGERS 1024 +#define RV_DEFAULT_NUM_TRIGGERS 2 FIELD(VTYPE, VLMUL, 0, 3)FIELD (VTYPE ,VSEW ,3 ,3 )
@@ -577,6 +592,8 @@ typedef struct RISCVCPUDef {RISCVCPUConfig cfg;bool bare;const RISCVCSR *custom_csrs; +/* This is just a setter for env->num_triggers. */ +uint32_t num_triggers; } RISCVCPUDef;/**
target/riscv/cpu.c +11 -0
@@ -1164,6 +1164,11 @@ static void riscv_cpu_init(Object *obj) IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);qdev_init_gpio_in_named (DEVICE (cpu), riscv_cpu_set_nmi,"riscv.cpu.rnmi" ,RNMI_MAX ); + +if (mcc->def->num_triggers) { + env->num_triggers = mcc->def->num_triggers; + } +#endif /* CONFIG_USER_ONLY */ cpu->user_options =g_hash_table_new (g_str_hash, g_str_equal);
@@ -2616,6 +2621,8 @@ static const Property riscv_cpu_properties[] = { DEFAULT_RNMI_IRQVEC),DEFINE_PROP_UINT64 ("rnmi-exception-vector" ,RISCVCPU , env.rnmi_excpvec,DEFAULT_RNMI_EXCPVEC ), +DEFINE_PROP_UINT32 ("num-triggers" ,RISCVCPU , env.num_triggers, +RV_DEFAULT_NUM_TRIGGERS ), #endif DEFINE_PROP_BOOL("short-isa-string", RISCVCPU, cfg.short_isa_string, false),
@@ -2761,6 +2768,10 @@ static void riscv_cpu_class_base_init(ObjectClass *c, const void *data) !valid_vm_1_10_32[mcc->def->cfg.max_satp_mode]) { mcc->def->cfg.max_satp_mode =VM_1_10_SV32 ; } + +if (def->num_triggers) { + mcc->def->num_triggers = def->num_triggers; + }#endif }if (def->priv_spec !=RISCV_PROFILE_ATTR_UNUSED ) {
target/riscv/debug.c +8 -8
@@ -26,6 +26,7 @@#include "qemu/osdep.h" #include "qemu/log.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "cpu.h" #include "target/riscv/debug.h" #include "trace.h"
@@ -1049,14 +1050,13 @@ void riscv_trigger_realize(CPURISCVState *env) {int i; -/* -* Alloc env->tdata1/2/3, cpu_breakpoint, cpu_watchpoint and -* itrigger_timer dynamically. This is overkill now -* given that they could be static arrays with RV_MAX_TRIGGERS -* but we'll parametrize the trigger number later, i.e. the -* array length won't be static. -*/ - env->num_triggers =RV_MAX_TRIGGERS ; +if (env->num_triggers >RV_MAX_TRIGGERS ) { +error_report ( +"Invalid configuration: 'num-triggers' must be less than %u" , +RV_MAX_TRIGGERS ); +exit (1 ); + } + env->tdata1 =g_new0 (uint64_t, env->num_triggers); env->tdata2 =g_new0 (uint64_t, env->num_triggers); env->tdata3 =g_new0 (uint64_t, env->num_triggers);
Signature · 1 line
2.54.0
[PULL 01/39] target/riscv: Avoid NULL deref in IMSIC CSR write
In reply to [email protected]From: Joel Stanley <[email protected]>
rmw_xireg_aia() and rmw_xtopei() were changed to store the IMSIC callback's value in a local before passing it back to the caller. For write only CSR accesses that pointer is NULL, causing a crash when guest programs write to xireg or xtopei, such as when the guest sets up the IMSIC.
This only happens when setting aia=aplic-imsic so none of the existing boot tests caught it.
Fix it by guarding the pointer dereference as done for other CSRs.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
target/riscv/csr.c +6 -2
@@ -2733,7 +2733,9 @@ static RISCVException rmw_xireg_aia(CPURISCVState *env, int csrno,AIA_MAKE_IREG (isel, priv, virt, vgein,riscv_cpu_mxl_bits (env)), &wide_val, new_val, wr_mask); - *val = wide_val; +if (val) { + *val = wide_val; + } } }else { isel_reserved = true;
@@ -3009,7 +3011,9 @@ static RISCVException rmw_xtopei(CPURISCVState *env, int csrno,AIA_MAKE_IREG (ISELECT_IMSIC_TOPEI , priv, virt, vgein,riscv_cpu_mxl_bits (env)), &wide_val, new_val, wr_mask); - *val = wide_val; +if (val) { + *val = wide_val; + } done:if (ret) {
Signature · 1 line
2.54.0
[PULL 11/39] hw/intc: riscv_imsic: Skip reset for KVM irqchip
In reply to [email protected]From: Qingwei Hu <[email protected]>
The emulated IMSIC state arrays are only allocated when QEMU handles the interrupt controller state itself. With KVM AIA/APLIC-IMSIC, the interrupt controller state is owned by the KVM in-kernel irqchip, so these emulated state arrays are not allocated.
The IMSIC reset handler still clears those arrays unconditionally. This makes qemu_system_reset(), which runs during machine creation, dereference NULL pointers with -machine virt,aia=aplic-imsic and KVM.
Skip the emulated IMSIC reset path when the interrupt controller is handled by KVM. The emulated path is unchanged for TCG and for configurations that use QEMU emulation.
Message-ID: <[email protected]>
--- hw/intc/riscv_imsic.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/intc/riscv_imsic.c +4 -0
@@ -347,6 +347,10 @@ static void riscv_imsic_reset_enter(Object *obj, ResetType type)RISCVIMSICState *imsic =RISCV_IMSIC (obj);int i; +if (kvm_irqchip_in_kernel ()) { +return ; + } +memset (imsic->eidelivery,0 ,sizeof (uint32_t ) * imsic->num_pages);memset (imsic->eithreshold,0 ,sizeof (uint32_t ) * imsic->num_pages);
Signature · 1 line
2.54.0
[PULL 08/39] hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM
In reply to [email protected]From: Qingwei Hu <[email protected]>
Each RISC-V MADT RINTC entry contains an External Interrupt Controller ID field. On the virt machine without AIA, this field identifies the S-mode PLIC context associated with the hart.
TCG virt has both M-mode and S-mode PLIC contexts, so the S-mode context ID is odd and 2 * local_cpu_id + 1 is correct. KVM virt exposes only S-mode PLIC contexts, and those contexts are numbered contiguously from
0. Reporting the TCG context ID for KVM makes the guest enable a different PLIC context from the one used by QEMU.
With ACPI enabled, this can leave PCI INTx interrupts pending in QEMU while the guest-programmed PLIC context remains disabled. A virtio-blk root disk can then stall during boot because its first interrupt is never delivered.
Use local_cpu_id for KVM and keep the existing odd S-mode context ID for TCG.
Message-ID: <[email protected]>
--- hw/riscv/virt-acpi-build.c | 2 ++ 1 file changed, 2 insertions(+)
hw/riscv/virt-acpi-build.c +2 -0
@@ -100,6 +100,8 @@ static void riscv_acpi_madt_add_rintc(uint32_t uid,build_append_int_noprefix (entry,ACPI_BUILD_INTC_ID ( arch_ids->cpus[uid].props.node_id, +kvm_enabled () ? + local_cpu_id :2 * local_cpu_id +1 ),4 ); }else {
Signature · 1 line
2.54.0
[PULL 04/39] target/riscv/cpu: add CPU unrealize callback
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Next patch is going to dynamically allocate debug trigger arrays during realize() time. We need a way of freeing them during unrealize(), which doesn't exist at this moment.
There's a lot going on in that patch already so we're adding the callback infrastructure beforehand.
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 2 ++ target/riscv/cpu.c | 9 +++++++++ 2 files changed, 11 insertions(+)
target/riscv/cpu.h +2 -0
@@ -576,6 +576,7 @@ typedef struct RISCVCPUDef {/** * RISCVCPUClass: * @parent_realize: The parent class' realize handler. +* @parent_unrealize: The parent class' unrealize handler. * @parent_phases: The parent class' reset phase handlers. * * A RISCV CPU model.
@@ -584,6 +585,7 @@ struct RISCVCPUClass {CPUClass parent_class;DeviceRealize parent_realize; +DeviceUnrealize parent_unrealize;ResettablePhases parent_phases;RISCVCPUDef *def; };
target/riscv/cpu.c +9 -0
@@ -1009,6 +1009,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) mcc->parent_realize (dev, errp); } +static void riscv_cpu_unrealize (DeviceState *dev) +{ +RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev); + + mcc->parent_unrealize (dev); +} +bool riscv_cpu_accelerator_compatible (RISCVCPU *cpu) {if (tcg_enabled ()) {
@@ -2664,6 +2671,8 @@ static void riscv_cpu_common_class_init(ObjectClass *c, const void *data)device_class_set_parent_realize (dc, riscv_cpu_realize, &mcc->parent_realize); +device_class_set_parent_unrealize (dc, riscv_cpu_unrealize, + &mcc->parent_unrealize);resettable_class_set_parent_phases (rc,NULL , riscv_cpu_reset_hold,NULL , &mcc->parent_phases);
Signature · 1 line
2.54.0
[PULL 13/39] hw/riscv/sifive_u.c: remove unneeded qemu_fdt_get_phandle() call
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
create_fdt() has the following code sequence:
plic_phandle = phandle++;
(...)
qemu_fdt_setprop_cell(fdt, nodename, "phandle", plic_phandle);
plic_phandle = qemu_fdt_get_phandle(fdt, nodename);What this is doing is assigning a value to plic_phandle, then use that as phandle of "nodename", and then fetching the phandle of "nodename" again in the same variable that already had the right phandle val.
Here's how it looks like in gdb:
Thread 1 "qemu-system-ris" hit Breakpoint 1, create_fdt
(s=0xaaaaac162a30, memmap=0xaaaaab8f70c8 <sifive_u_memmap>,
is_32_bit=false) at ../hw/riscv/sifive_u.c:199199 plic_phandle = phandle++;
(gdb) n
200 cells = g_new0(uint32_t, ms->smp.cpus * 4 - 2);
(gdb) p plic_phandle
$3 = 12
(gdb) c
Continuing.
Thread 1 "qemu-system-ris" hit Breakpoint 2, create_fdt
(s=0xaaaaac162a30, memmap=0xaaaaab8f70c8 <sifive_u_memmap>,
is_32_bit=false) at ../hw/riscv/sifive_u.c:232232 plic_phandle = qemu_fdt_get_phandle(fdt, nodename);
(gdb) n
233 g_free(cells);
(gdb) p plic_phandle
$4 = 12
(gdb)
Remove the extra qemu_fdt_get_phandle() call.
Message-ID: <[email protected]>
--- hw/riscv/sifive_u.c | 1 - 1 file changed, 1 deletion(-)
hw/riscv/sifive_u.c +0 -1
@@ -229,7 +229,6 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,qemu_fdt_setprop_cell (fdt, nodename,"riscv,ndev" ,SIFIVE_U_PLIC_NUM_SOURCES -1 );qemu_fdt_setprop_cell (fdt, nodename,"phandle" , plic_phandle); - plic_phandle =qemu_fdt_get_phandle (fdt, nodename);g_free (cells);g_free (nodename);
Signature · 1 line
2.54.0
[PULL 05/39] target/riscv: dynamic alloc of debug trigger arrays
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
The debug trigger facility consists of a set of arrays: tdata1-3, cpu_breakpoint, cpu_watchpoint and itrigger_timer. All of them are static allocated with RV_MAX_TRIGGERS (2). This means that all RISC-V cpus will have 2 triggers per hart.
The RISC-V Server Ref demands at least 11 triggers per hart, and several CPUs in the wild works with 4+ triggers. We need more flexibility, ergo we need to parametrize the amount of triggers and make it configurable.
Before doing that we need to handle a situation faced in a previous attempt [1]. We were unable to set the tdataN array length in vmstate_debug, meaning that we would always migrate RV_MAX_TRIGGERS regardless of the actual amount of triggers in play. To fix that we need to change the tdata arrays from static to dynamic, allowing us to use VMSTATE_VARRAY_UINT32(). This also means that, in contrast with [1], we have the opportunity to turn all trigger arrays into dynamic allocation and reduce the amount of stuff being carried by CPURISCVState, or in other words, we can carry just what we're using instead of a static max value.
All the forementioned trigger facility arrays are now dynamic. They are allocated and freed during realize/unrealize, and their size is expressed by env->num_triggers. All relevant code is changed to use env->num_triggers instead of the RV_MAX_TRIGGERS to loop through each array.
This will make it easier for the next patch to parametrize env->num_triggers.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 18 +++++++++++------ target/riscv/debug.h | 1 + target/riscv/cpu.c | 6 ++++++ target/riscv/csr.c | 2 +- target/riscv/debug.c | 46 ++++++++++++++++++++++++++++++++++-------- target/riscv/machine.c | 16 ++++++++++----- 6 files changed, 69 insertions(+), 20 deletions(-)
target/riscv/cpu.h +12 -6
@@ -467,12 +467,18 @@ struct CPUArchState {/* trigger module */ uint16_t mcontext;uint8_t trigger_cur; -uint64_t tdata1[RV_MAX_TRIGGERS ]; -uint64_t tdata2[RV_MAX_TRIGGERS ]; -uint64_t tdata3[RV_MAX_TRIGGERS ]; -struct CPUBreakpoint *cpu_breakpoint[RV_MAX_TRIGGERS ]; -struct CPUWatchpoint *cpu_watchpoint[RV_MAX_TRIGGERS ]; -QEMUTimer *itrigger_timer[RV_MAX_TRIGGERS ]; +/* +* num_triggers is the length of tdata1, tdata2, tdata3, +* cpu_breakpoint, cpu_watchpoint and itrigger_timer +* arrays. +*/ +uint32_t num_triggers; +uint64_t *tdata1; +uint64_t *tdata2; +uint64_t *tdata3; +struct CPUBreakpoint **cpu_breakpoint; +struct CPUWatchpoint **cpu_watchpoint; +QEMUTimer **itrigger_timer;int64_t last_icount;bool itrigger_enabled;
target/riscv/debug.h +1 -0
@@ -148,6 +148,7 @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs);bool riscv_cpu_debug_check_watchpoint (CPUState *cs,CPUWatchpoint *wp);void riscv_trigger_realize (CPURISCVState *env); +void riscv_trigger_unrealize (CPURISCVState *env);void riscv_trigger_reset_hold (CPURISCVState *env);bool riscv_itrigger_enabled (CPURISCVState *env);
target/riscv/cpu.c +6 -0
@@ -1012,7 +1012,13 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)static void riscv_cpu_unrealize (DeviceState *dev) {RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev); +#ifndef CONFIG_USER_ONLY +RISCVCPU *cpu =RISCV_CPU (dev); +if (cpu->cfg.debug) { +riscv_trigger_unrealize (&cpu->env); + } +#endif mcc->parent_unrealize (dev); }
target/riscv/csr.c +1 -1
@@ -5441,7 +5441,7 @@ static RISCVException read_tdata(CPURISCVState *env, int csrno, target_ulong *val) {/* return 0 in tdata1 to end the trigger enumeration */ -if (env->trigger_cur >=RV_MAX_TRIGGERS && csrno ==CSR_TDATA1 ) { +if (env->trigger_cur >= env->num_triggers && csrno ==CSR_TDATA1 ) { *val =0 ;return RISCV_EXCP_NONE ; }
target/riscv/debug.c +38 -8
99 lines not on this page · raw message
target/riscv/machine.c +11 -5
@@ -240,16 +240,22 @@ static int debug_post_load(void *opaque, int version_id)static const VMStateDescription vmstate_debug = { .name ="cpu/debug" , - .version_id =3 , - .minimum_version_id =3 , + .version_id =4 , + .minimum_version_id =4 , .needed = debug_needed, .post_load = debug_post_load, .fields = (const VMStateField []) {VMSTATE_UINT16 (env.mcontext,RISCVCPU ),VMSTATE_UINT8 (env.trigger_cur,RISCVCPU ), -VMSTATE_UINT64_ARRAY (env.tdata1,RISCVCPU ,RV_MAX_TRIGGERS ), -VMSTATE_UINT64_ARRAY (env.tdata2,RISCVCPU ,RV_MAX_TRIGGERS ), -VMSTATE_UINT64_ARRAY (env.tdata3,RISCVCPU ,RV_MAX_TRIGGERS ), +VMSTATE_VARRAY_UINT32 (env.tdata1,RISCVCPU , + env.num_triggers,0 , + vmstate_info_uint64, uint64_t), +VMSTATE_VARRAY_UINT32 (env.tdata2,RISCVCPU , + env.num_triggers,0 , + vmstate_info_uint64, uint64_t), +VMSTATE_VARRAY_UINT32 (env.tdata3,RISCVCPU , + env.num_triggers,0 , + vmstate_info_uint64, uint64_t),VMSTATE_END_OF_LIST () } };
Signature · 1 line
2.54.0
[PULL 22/39] hw/riscv/riscv-iommu: set cmd_ill IOFENCE.C rsvp bits are set
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We're not setting RISCV_IOMMU_CQCSR_CMD_ILL if a reserved bit happens to be set in an IOFENCE.C command.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3575
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu-bits.h | 1 + hw/riscv/riscv-iommu.c | 4 ++++ 2 files changed, 5 insertions(+)
hw/riscv/riscv-iommu-bits.h +1 -0
@@ -347,6 +347,7 @@ struct riscv_iommu_command {#define RISCV_IOMMU_CMD_IOFENCE_OPCODE 2#define RISCV_IOMMU_CMD_IOFENCE_FUNC_C 0#define RISCV_IOMMU_CMD_IOFENCE_AV BIT_ULL(10) +#define RISCV_IOMMU_CMD_IOFENCE_RESERVED GENMASK_ULL(31, 14)#define RISCV_IOMMU_CMD_IOFENCE_DATA GENMASK_ULL(63, 32)#define RISCV_IOMMU_CMD_IODIR_OPCODE 3
hw/riscv/riscv-iommu.c +4 -0
@@ -1880,6 +1880,10 @@ static void riscv_iommu_process_cq_tail(RISCVIOMMUState *s)switch (cmd_opcode) {case RISCV_IOMMU_CMD (RISCV_IOMMU_CMD_IOFENCE_FUNC_C ,RISCV_IOMMU_CMD_IOFENCE_OPCODE ): +if (cmd.dword0 &RISCV_IOMMU_CMD_IOFENCE_RESERVED ) { + goto cmd_ill; + } + res =riscv_iommu_iofence (s, cmd.dword0 &RISCV_IOMMU_CMD_IOFENCE_AV , cmd.dword1 <<2 ,get_field (cmd.dword0,RISCV_IOMMU_CMD_IOFENCE_DATA ));
Signature · 1 line
2.54.0
[PULL 18/39] hw/riscv/riscv-iommu: rename regs_rw to regs
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
The existing nomenclature can be misleading: regs_rw can cosplay as 'read and write' mask, in particular because we have regs_ro which is a read only mask.
regs_rw is the current reg value, and all bits that aren't on the regs_ro mask is considered r/w bits.
Rename regs_rw to 'regs' to be on par with the nomenclature other devices uses (e.g. cadence_gem).
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.h | 26 +++++++++++++++----------- hw/riscv/riscv-iommu-hpm.c | 4 ++-- hw/riscv/riscv-iommu.c | 36 ++++++++++++++++++------------------ 3 files changed, 35 insertions(+), 31 deletions(-)
hw/riscv/riscv-iommu.h +15 -11
@@ -76,9 +76,13 @@ struct RISCVIOMMUState {/* MMIO Hardware Interface */ MemoryRegion regs_mr; -uint8_t *regs_rw;/* register state (user write) */ +uint8_t *regs;/* current register state */ uint8_t *regs_wc;/* write-1-to-clear mask */ -uint8_t *regs_ro;/* read-only mask */ +/* +* read-only mask. NOTE: bits not present in this RO +* mask are assumed to be read and write. +*/ +uint8_t *regs_ro;QLIST_ENTRY (RISCVIOMMUState) iommus; QLIST_HEAD(, RISCVIOMMUSpace) spaces;
@@ -120,39 +124,39 @@ struct RISCVIOMMUContext {static inline uint32_t riscv_iommu_reg_mod32 (RISCVIOMMUState *s,unsigned idx,uint32_t set,uint32_t clr) { -uint32_t val =ldl_le_p (s->regs_rw + idx); -stl_le_p (s->regs_rw + idx, (val & ~clr) | set); +uint32_t val =ldl_le_p (s->regs + idx); +stl_le_p (s->regs + idx, (val & ~clr) | set);return val; }static inline void riscv_iommu_reg_set32 (RISCVIOMMUState *s,unsigned idx,uint32_t set) { -stl_le_p (s->regs_rw + idx, set); +stl_le_p (s->regs + idx, set); }static inline uint32_t riscv_iommu_reg_get32 (RISCVIOMMUState *s,unsigned idx) { -return ldl_le_p (s->regs_rw + idx); +return ldl_le_p (s->regs + idx); }static inline uint64_t riscv_iommu_reg_mod64 (RISCVIOMMUState *s,unsigned idx,uint64_t set,uint64_t clr) { -uint64_t val =ldq_le_p (s->regs_rw + idx); -stq_le_p (s->regs_rw + idx, (val & ~clr) | set); +uint64_t val =ldq_le_p (s->regs + idx); +stq_le_p (s->regs + idx, (val & ~clr) | set);return val; }static inline void riscv_iommu_reg_set64 (RISCVIOMMUState *s,unsigned idx,uint64_t set) { -stq_le_p (s->regs_rw + idx, set); +stq_le_p (s->regs + idx, set); }static inline uint64_t riscv_iommu_reg_get64 (RISCVIOMMUState *s, -unsigned idx) +unsigned idx) { -return ldq_le_p (s->regs_rw + idx); +return ldq_le_p (s->regs + idx); }#endif
hw/riscv/riscv-iommu-hpm.c +2 -2
@@ -60,8 +60,8 @@ static void hpm_incr_ctr(RISCVIOMMUState *s, uint32_t ctr_idx)const uint32_t off = ctr_idx <<3 ;uint64_t cntr_val; - cntr_val =ldq_le_p (&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off]); -stq_le_p (&s->regs_rw[RISCV_IOMMU_REG_IOHPMCTR_BASE + off], cntr_val +1 ); + cntr_val =ldq_le_p (&s->regs[RISCV_IOMMU_REG_IOHPMCTR_BASE + off]); +stq_le_p (&s->regs[RISCV_IOMMU_REG_IOHPMCTR_BASE + off], cntr_val +1 );trace_riscv_iommu_hpm_incr_ctr (cntr_val);
hw/riscv/riscv-iommu.c +18 -18
@@ -2034,8 +2034,8 @@ static void riscv_iommu_process_cq_control(RISCVIOMMUState *s) s->cq_mask = (2ULL <<get_field (base,RISCV_IOMMU_CQB_LOG2SZ )) -1 ; s->cq_addr =PPN_PHYS (get_field (base,RISCV_IOMMU_CQB_PPN ));stl_le_p (&s->regs_ro[RISCV_IOMMU_REG_CQT ], ~s->cq_mask); -stl_le_p (&s->regs_rw[RISCV_IOMMU_REG_CQH ],0 ); -stl_le_p (&s->regs_rw[RISCV_IOMMU_REG_CQT ],0 ); +stl_le_p (&s->regs[RISCV_IOMMU_REG_CQH ],0 ); +stl_le_p (&s->regs[RISCV_IOMMU_REG_CQT ],0 ); ctrl_set =RISCV_IOMMU_CQCSR_CQON ; ctrl_clr =RISCV_IOMMU_CQCSR_BUSY |RISCV_IOMMU_CQCSR_CQMF | RISCV_IOMMU_CQCSR_CMD_ILL | RISCV_IOMMU_CQCSR_CMD_TO |
@@ -2075,8 +2075,8 @@ static void riscv_iommu_process_fq_control(RISCVIOMMUState *s) s->fq_mask = (2ULL <<get_field (base,RISCV_IOMMU_FQB_LOG2SZ )) -1 ; s->fq_addr =PPN_PHYS (get_field (base,RISCV_IOMMU_FQB_PPN ));stl_le_p (&s->regs_ro[RISCV_IOMMU_REG_FQH ], ~s->fq_mask); -stl_le_p (&s->regs_rw[RISCV_IOMMU_REG_FQH ],0 ); -stl_le_p (&s->regs_rw[RISCV_IOMMU_REG_FQT ],0 ); +stl_le_p (&s->regs[RISCV_IOMMU_REG_FQH ],0 ); +stl_le_p (&s->regs[RISCV_IOMMU_REG_FQT ],0 ); ctrl_set =RISCV_IOMMU_FQCSR_FQON ; ctrl_clr =RISCV_IOMMU_FQCSR_BUSY |RISCV_IOMMU_FQCSR_FQMF |RISCV_IOMMU_FQCSR_FQOF ;
@@ -2105,8 +2105,8 @@ static void riscv_iommu_process_pq_control(RISCVIOMMUState *s) s->pq_mask = (2ULL <<get_field (base,RISCV_IOMMU_PQB_LOG2SZ )) -1 ; s->pq_addr =PPN_PHYS (get_field (base,RISCV_IOMMU_PQB_PPN ));stl_le_p (&s->regs_ro[RISCV_IOMMU_REG_PQH ], ~s->pq_mask); -stl_le_p (&s->regs_rw[RISCV_IOMMU_REG_PQH ],0 ); -stl_le_p (&s->regs_rw[RISCV_IOMMU_REG_PQT ],0 ); +stl_le_p (&s->regs[RISCV_IOMMU_REG_PQH ],0 ); +stl_le_p (&s->regs[RISCV_IOMMU_REG_PQT ],0 ); ctrl_set =RISCV_IOMMU_PQCSR_PQON ; ctrl_clr =RISCV_IOMMU_PQCSR_BUSY |RISCV_IOMMU_PQCSR_PQMF |RISCV_IOMMU_PQCSR_PQOF ;
@@ -2276,9 +2276,9 @@ static void riscv_iommu_write_reg_val(RISCVIOMMUState *s, {uint64_t ro =ldn_le_p (&s->regs_ro[reg_addr], size);uint64_t wc =ldn_le_p (&s->regs_wc[reg_addr], size); -uint64_t rw =ldn_le_p (&s->regs_rw[reg_addr], size); +uint64_t curr_val =ldn_le_p (&s->regs[reg_addr], size); -stn_le_p (dest, size, ((rw & ro) | (data & ~ro)) & ~(data & wc)); +stn_le_p (dest, size, ((curr_val & ro) | (data & ~ro)) & ~(data & wc)); } static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr,
@@ -2378,12 +2378,12 @@ static MemTxResult riscv_iommu_mmio_write(void *opaque, hwaddr addr,* is set IOMMU behavior of additional writes to the register * is UNSPECIFIED. */ -riscv_iommu_write_reg_val (s, &s->regs_rw[addr], addr, size, data); +riscv_iommu_write_reg_val (s, &s->regs[addr], addr, size, data);/* Busy flag update, MSB 4-byte register. */ if (busy) { -uint32_t rw =ldl_le_p (&s->regs_rw[regb]); -stl_le_p (&s->regs_rw[regb], rw | busy); +uint32_t rw =ldl_le_p (&s->regs[regb]); +stl_le_p (&s->regs[regb], rw | busy); }/* Process HPM writes and update any internal state if needed. */
@@ -2428,13 +2428,13 @@ static MemTxResult riscv_iommu_mmio_read(void *opaque, hwaddr addr,* it's not dependent over the timer callback and is computed * from cycle overflow. */ - val =ldq_le_p (&s->regs_rw[addr]); + val =ldq_le_p (&s->regs[addr]); val |= (riscv_iommu_hpmcycle_read (s) &RISCV_IOMMU_IOHPMCYCLES_OVF ) ?RISCV_IOMMU_IOCOUNTOVF_CY :0 ; ptr = (uint8_t *)&val + (addr &3 ); }else { - ptr = &s->regs_rw[addr]; + ptr = &s->regs[addr]; } val =ldn_le_p (ptr, size);
@@ -2529,7 +2529,7 @@ static void riscv_iommu_instance_init(Object *obj) s->cap |=RISCV_IOMMU_CAP_PD8 ;/* register storage */ - s->regs_rw =g_new0 (uint8_t,RISCV_IOMMU_REG_SIZE ); + s->regs =g_new0 (uint8_t,RISCV_IOMMU_REG_SIZE ); s->regs_ro =g_new0 (uint8_t,RISCV_IOMMU_REG_SIZE ); s->regs_wc =g_new0 (uint8_t,RISCV_IOMMU_REG_SIZE );
@@ -2554,7 +2554,7 @@ static void riscv_iommu_instance_finalize(Object *obj) {RISCVIOMMUState *s =RISCV_IOMMU (obj); -g_free (s->regs_rw); +g_free (s->regs);g_free (s->regs_ro);g_free (s->regs_wc);
@@ -2608,8 +2608,8 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) "riscv-iommu-regs", RISCV_IOMMU_REG_SIZE);/* Set power-on register state */ -stq_le_p (&s->regs_rw[RISCV_IOMMU_REG_CAP ], s->cap); -stq_le_p (&s->regs_rw[RISCV_IOMMU_REG_FCTL ],0 ); +stq_le_p (&s->regs[RISCV_IOMMU_REG_CAP ], s->cap); +stq_le_p (&s->regs[RISCV_IOMMU_REG_FCTL ],0 );stq_le_p (&s->regs_ro[RISCV_IOMMU_REG_FCTL ], ~(RISCV_IOMMU_FCTL_BE |RISCV_IOMMU_FCTL_WSI )); stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_DDTP],
@@ -2634,7 +2634,7 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) RISCV_IOMMU_PQCSR_BUSY);stl_le_p (&s->regs_wc[RISCV_IOMMU_REG_IPSR ], ~0 );stl_le_p (&s->regs_ro[RISCV_IOMMU_REG_ICVEC ],0 ); -stq_le_p (&s->regs_rw[RISCV_IOMMU_REG_DDTP ], s->ddtp); +stq_le_p (&s->regs[RISCV_IOMMU_REG_DDTP ], s->ddtp);/* If debug registers enabled. */ if (s->cap &RISCV_IOMMU_CAP_DBG ) {stq_le_p (&s->regs_ro[RISCV_IOMMU_REG_TR_REQ_IOVA ],0 );
Signature · 1 line
2.54.0
[PULL 10/39] hw/intc: riscv_aplic: Skip reset for KVM irqchip
In reply to [email protected]From: Qingwei Hu <[email protected]>
The emulated APLIC state arrays are only allocated when QEMU handles the interrupt controller state itself. With KVM AIA/APLIC-IMSIC, the interrupt controller state is owned by the KVM in-kernel irqchip, so these emulated state arrays are not allocated.
The APLIC reset handler still clears those arrays unconditionally. This makes qemu_system_reset(), which runs during machine creation, dereference NULL pointers with -machine virt,aia=aplic-imsic and KVM.
Skip the emulated APLIC reset path when the interrupt controller is handled by KVM. The emulated path is unchanged for TCG and for configurations that use QEMU emulation.
Message-ID: <[email protected]>
--- hw/intc/riscv_aplic.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/intc/riscv_aplic.c +4 -0
@@ -910,6 +910,10 @@ static void riscv_aplic_reset_enter(Object *obj, ResetType type)RISCVAPLICState *aplic =RISCV_APLIC (obj);int i; +if (!riscv_use_emulated_aplic (aplic->msimode)) { +return ; + } + aplic->domaincfg =0 ;memset (aplic->sourcecfg,0 ,sizeof (uint32_t ) * aplic->num_irqs);memset (aplic->target,0 ,sizeof (uint32_t ) * aplic->num_irqs);
Signature · 1 line
2.54.0
[PULL 24/39] hw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offset
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We're doing a wrong shift when calculating the offset for the interrupt-pending bits, off by one right shift order.
This went undercover for awhile because the calculation works for interrupt entities 1 to 63. The math goes wrong when using interrupt entities 64 or greater.
Instead of fixing the issue and running we're also adding some notes on where this calc comes from.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3561
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +20 -1
@@ -686,7 +686,26 @@ static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s,/* MRIF pending bit address */ addr =get_field (pte[0 ],RISCV_IOMMU_MSI_PTE_MRIF_ADDR ) <<9 ; - addr = addr | ((data &0x7c0 ) >>3 ); +/* +* AIA spec section "Format of a memory-resident interrupt file": +* address offset 0x000 contains interrupt-pending bits for +* identities 1-63, offfset 0x010 for identities 64-127, and +* so it goes up to 0x1F0 for identities 1984-2047. +* +* Hence each batch of identities advances offset by 16 (0x010) +* for every interrupt-pending bits. This means that doing +* (data & 0x7c0) will filter out the first 6 bits, then +* a >> 2 will turn the result in the 0x10 steps we need. +* +* E.g: +* +* - (1-63 & 0x7c0) = 0, 0 >> 2 = 0, offset 0x000 +* - (64-127 & 0x7c0) = 64, 64 >> 2 = 16, offset 0x010 +* - (128-191 & 0x7c0) = 128, 128 >> 2 = 32, offset 0x020 +* +* and so on. +*/ + addr = addr | ((data &0x7c0 ) >>2 ); trace_riscv_iommu_msi(s->parent_obj.id, PCI_BUS_NUM(ctx->devid), PCI_SLOT(ctx->devid), PCI_FUNC(ctx->devid),
Signature · 1 line
2.54.0
[PULL 19/39] hw/riscv/riscv-iommu.c: make FCTL.BE read only 0
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We do not support FCTL.BE equal to 1 hence do not allow this bit to be set by software.
While we're at it: the riscv-iommu spec allows FCTL.GXL to be set freely and we do not have hardcoded restrictions on it, so make it writable.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3576
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +3 -1
@@ -2609,9 +2609,11 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp)/* Set power-on register state */ stq_le_p (&s->regs[RISCV_IOMMU_REG_CAP ], s->cap); +stq_le_p (&s->regs[RISCV_IOMMU_REG_FCTL ],0 );stq_le_p (&s->regs_ro[RISCV_IOMMU_REG_FCTL ], - ~(RISCV_IOMMU_FCTL_BE |RISCV_IOMMU_FCTL_WSI )); + ~(RISCV_IOMMU_FCTL_GXL |RISCV_IOMMU_FCTL_WSI )); +stq_le_p (&s->regs_ro[RISCV_IOMMU_REG_DDTP ], ~(RISCV_IOMMU_DDTP_PPN |RISCV_IOMMU_DDTP_MODE )); stq_le_p(&s->regs_ro[RISCV_IOMMU_REG_CQB],
Signature · 1 line
2.54.0
[PULL 15/39] hw/riscv/sifive_u: add #address-cells in PLIC FDT
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
By Linux FDT docs in [1] the "address-cells" property is mandatory. Set it to zero.
While we're at it let's also put this new value and the interrupt-cells value in macros, like the 'virt' board is doing.
Message-ID: <[email protected]>
--- include/hw/riscv/sifive_u.h | 2 ++ hw/riscv/sifive_u.c | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/riscv/sifive_u.h +2 -0
@@ -156,6 +156,8 @@ enum {#define SIFIVE_U_MANAGEMENT_CPU_COUNT 1#define SIFIVE_U_COMPUTE_CPU_COUNT 4 +#define SIFIVE_U_PLIC_ADDR_CELLS 0 +#define SIFIVE_U_PLIC_INT_CELLS 1#define SIFIVE_U_PLIC_NUM_SOURCES 54#define SIFIVE_U_PLIC_NUM_PRIORITIES 7#define SIFIVE_U_PLIC_PRIORITY_BASE 0x00
hw/riscv/sifive_u.c +4 -1
@@ -213,7 +213,10 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, nodename =g_strdup_printf ("/soc/interrupt-controller@%lx" , (long )memmap[SIFIVE_U_DEV_PLIC ].base);qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" ,1 ); +qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" , +SIFIVE_U_PLIC_INT_CELLS ); +qemu_fdt_setprop_cell (fdt, nodename,"#address-cells" , +SIFIVE_U_PLIC_ADDR_CELLS );qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , (char **)&plic_compat,ARRAY_SIZE (plic_compat));qemu_fdt_setprop (fdt, nodename,"interrupt-controller" ,NULL ,0 );
Signature · 1 line
2.54.0
[PULL 14/39] hw/riscv/sifive_u.c: use intc_phandle in plic creation
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
The info about intc_phandles for each CPU is already stored in the intc_phandles array. We don't need to fetch them again using qemu_fdt_get_phandle().
Message-ID: <[email protected]>
--- hw/riscv/sifive_u.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
hw/riscv/sifive_u.c +3 -7
@@ -199,20 +199,16 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, plic_phandle = phandle++; cells =g_new0 (uint32_t, ms->smp.cpus *4 -2 );for (cpu =0 ; cpu < ms->smp.cpus; cpu++) { - nodename = -g_strdup_printf ("/cpus/cpu@%d/interrupt-controller" , cpu); -uint32_t intc_phandle =qemu_fdt_get_phandle (fdt, nodename);/* cpu 0 is the management hart that does not have S-mode */ if (cpu ==0 ) { - cells[0 ] =cpu_to_be32 (intc_phandle); + cells[0 ] =cpu_to_be32 (intc_phandles[cpu]); cells[1 ] =cpu_to_be32 (IRQ_M_EXT ); }else { - cells[cpu *4 -2 ] =cpu_to_be32 (intc_phandle); + cells[cpu *4 -2 ] =cpu_to_be32 (intc_phandles[cpu]); cells[cpu *4 -1 ] =cpu_to_be32 (IRQ_M_EXT ); - cells[cpu *4 +0 ] =cpu_to_be32 (intc_phandle); + cells[cpu *4 +0 ] =cpu_to_be32 (intc_phandles[cpu]); cells[cpu *4 +1 ] =cpu_to_be32 (IRQ_S_EXT ); } -g_free (nodename); } nodename =g_strdup_printf ("/soc/interrupt-controller@%lx" , (long )memmap[SIFIVE_U_DEV_PLIC ].base);
Signature · 1 line
2.54.0
[PULL 30/39] hw/riscv/aia: Provide number of irq sources
In reply to [email protected]From: Joel Stanley <[email protected]>
Instead of hard coding the number of IRQ sources used by the APLIC pass it in as a parameter. This allows other machines to configure this as required.
The maximum number of sources is 1023.
Message-ID: <[email protected]>
--- hw/riscv/aia.h | 3 +-- include/hw/riscv/virt.h | 1 + hw/riscv/aia.c | 8 ++++++-- hw/riscv/virt-acpi-build.c | 25 ++++++++++++++++--------- hw/riscv/virt.c | 2 ++ 5 files changed, 26 insertions(+), 13 deletions(-)
hw/riscv/aia.h +1 -2
@@ -11,11 +11,10 @@#include "exec/hwaddr.h" -#define VIRT_IRQCHIP_NUM_SOURCES 96 -uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m,
include/hw/riscv/virt.h +1 -0
@@ -64,6 +64,7 @@ struct RISCVVirtState {struct GPEXHost *gpex_host;OnOffAuto iommu_sys;uint16_t pci_iommu_bdf; +uint16_t num_sources; };enum {
hw/riscv/aia.c +6 -2
@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s, const MemMapEntry *imsic_m,
@@ -38,6 +39,9 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,DeviceState *aplic_s_dev =NULL ;DeviceState *aplic_m_dev =NULL ; +/* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ +g_assert (num_sources <=1023 ); +if (msimode) {if (!kvm_enabled ()) {/* Per-socket M-level IMSICs */
@@ -66,7 +70,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_m->size, (msimode) ?0 : base_hartid, (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , + num_sources, num_prio_bits, msimode, true, NULL); }
@@ -77,7 +81,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests, aplic_s->size, (msimode) ?0 : base_hartid, (msimode) ?0 : hart_count, -VIRT_IRQCHIP_NUM_SOURCES , + num_sources, num_prio_bits, msimode, false, aplic_m_dev);
hw/riscv/virt-acpi-build.c +16 -9
@@ -148,6 +148,7 @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s) }static void acpi_dsdt_add_plic_aplic (Aml *scope,uint8_t socket_count, +uint16_t num_sources,uint64_t mmio_base,uint64_t mmio_size,const char *hid) {
@@ -155,9 +156,12 @@ static void acpi_dsdt_add_plic_aplic(Aml *scope, uint8_t socket_count,uint32_t gsi_base;uint8_t socket; +/* The RISC-V Advanced Interrupt Architecture, Chapter 1.2. Limits */ +g_assert (num_sources <=1023 ); +for (socket =0 ; socket < socket_count; socket++) { plic_aplic_addr = mmio_base + mmio_size * socket; - gsi_base =VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = num_sources * socket;Aml *dev =aml_device ("IC%.02X" , socket);aml_append (dev,aml_name_decl ("_HID" ,aml_string ("%s" , hid)));aml_append (dev,aml_name_decl ("_UID" ,aml_int (socket)));
@@ -476,10 +480,13 @@ static void build_dsdt(GArray *table_data, socket_count =riscv_socket_count (ms);if (s->aia_type ==VIRT_AIA_TYPE_NONE ) { -acpi_dsdt_add_plic_aplic (scope, socket_count, memmap[VIRT_PLIC ].base, - memmap[VIRT_PLIC ].size,"RSCV0001" ); +acpi_dsdt_add_plic_aplic (scope, socket_count, s->num_sources, + memmap[VIRT_PLIC ].base, + memmap[VIRT_PLIC ].size, +"RSCV0001" ); }else { -acpi_dsdt_add_plic_aplic (scope, socket_count, memmap[VIRT_APLIC_S ].base, +acpi_dsdt_add_plic_aplic (scope, socket_count, s->num_sources, + memmap[VIRT_APLIC_S ].base, memmap[VIRT_APLIC_S ].size,"RSCV0002" ); }
@@ -496,15 +503,15 @@ static void build_dsdt(GArray *table_data, }else if (socket_count ==2 ) {virtio_acpi_dsdt_add (scope, memmap[VIRT_VIRTIO ].base, memmap[VIRT_VIRTIO ].size, -VIRTIO_IRQ +VIRT_IRQCHIP_NUM_SOURCES ,0 , +VIRTIO_IRQ + s->num_sources,0 ,VIRTIO_COUNT ); -acpi_dsdt_add_gpex_host (scope,PCIE_IRQ +VIRT_IRQCHIP_NUM_SOURCES ); +acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources); }else {virtio_acpi_dsdt_add (scope, memmap[VIRT_VIRTIO ].base, memmap[VIRT_VIRTIO ].size, -VIRTIO_IRQ +VIRT_IRQCHIP_NUM_SOURCES ,0 , +VIRTIO_IRQ + s->num_sources,0 ,VIRTIO_COUNT ); -acpi_dsdt_add_gpex_host (scope,PCIE_IRQ +VIRT_IRQCHIP_NUM_SOURCES *2 ); +acpi_dsdt_add_gpex_host (scope,PCIE_IRQ + s->num_sources *2 ); }aml_append (dsdt, scope);
@@ -583,7 +590,7 @@ static void build_madt(GArray *table_data,for (socket =0 ; socket <riscv_socket_count (ms); socket++) { aplic_addr = s->memmap[VIRT_APLIC_S ].base + s->memmap[VIRT_APLIC_S ].size * socket; - gsi_base =VIRT_IRQCHIP_NUM_SOURCES * socket; + gsi_base = s->num_sources * socket;build_append_int_noprefix (table_data,0x1A ,1 );/* Type */ build_append_int_noprefix (table_data,36 ,1 );/* Length */ build_append_int_noprefix (table_data,1 ,1 );/* Version */
hw/riscv/virt.c +2 -0
@@ -1401,6 +1401,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S], &s->memmap[VIRT_IMSIC_M],
@@ -1557,6 +1558,7 @@ static void virt_machine_instance_init(Object *obj) s->oem_table_id =g_strndup (ACPI_BUILD_APPNAME8 ,8 ); s->acpi =ON_OFF_AUTO_AUTO ; s->iommu_sys =ON_OFF_AUTO_AUTO ; + s->num_sources =VIRT_IRQCHIP_NUM_SOURCES ; }static char *virt_get_aia_guests (Object *obj,Error **errp)
Signature · 1 line
2.54.0
[PULL 03/39] tests/functional/riscv64: Add virt machine AIA boot test
In reply to [email protected]From: Joel Stanley <[email protected]>
Add coverage of the riscv64 virt machine's Advanced Interrupt Architecture models. With this the APLIC and IMSIC models are used by Linux, catching regressions.
This test requires a kernel >= 6.10, as AIA drivers were added to Linux in 6.10.
Boot time is ~5s on a laptop.
Message-ID: <[email protected]>
--- tests/functional/riscv64/test_tuxrun.py | 7 +++++++ 1 file changed, 7 insertions(+)
tests/functional/riscv64/test_tuxrun.py +7 -0
@@ -41,6 +41,13 @@ def test_riscv64_maxcpu(self): self.common_tuxrun(kernel_asset=self.ASSET_RISCV64_KERNEL, rootfs_asset=self.ASSET_RISCV64_ROOTFS) + def test_riscv64_aia(self): + self.set_machine('virt') + self.vm.set_machine('virt,aia=aplic-imsic') + self.cpu='max' + self.common_tuxrun(kernel_asset=self.ASSET_RISCV64_KERNEL, + rootfs_asset=self.ASSET_RISCV64_ROOTFS) + def test_riscv64_rv32(self): self.set_machine('virt') self.cpu='rv32'
Signature · 1 line
2.54.0
[PULL 27/39] hw/riscv/boot: Describe discontiguous memory in boot_info
In reply to [email protected]From: Nicholas Piggin <[email protected]>
Machines that have discontiguous memory may need to adjust where firmware and images are loaded at boot. Provide an interface for machines to describe a discontiguous low/high RAM scheme for this purpose.
Message-ID: <[email protected]>
--- include/hw/riscv/boot.h | 7 +++++++ hw/riscv/boot.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+)
include/hw/riscv/boot.h +7 -0
@@ -28,6 +28,10 @@#define RISCV64_BIOS_BIN "opensbi-riscv64-generic-fw_dynamic.bin" typedef struct RISCVBootInfo { + /* First contiguous RAM region. If size is zero then assume entire RAM */ + hwaddr ram_low_start; + hwaddr ram_low_size; + ssize_t kernel_size; hwaddr image_low_addr; hwaddr image_high_addr;
@@ -43,6 +47,9 @@ bool riscv_is_32bit(RISCVHartArrayState *harts);char *riscv_plic_hart_config_string (int hart_count);void riscv_boot_info_init (RISCVBootInfo *info,RISCVHartArrayState *harts); +void riscv_boot_info_init_discontig_mem (RISCVBootInfo *info, +RISCVHartArrayState *harts, +hwaddr low_start,hwaddr low_size);vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr); hwaddr riscv_find_and_load_firmware(MachineState *machine,
hw/riscv/boot.c +16 -0
@@ -70,11 +70,27 @@ char *riscv_plic_hart_config_string(int hart_count)void riscv_boot_info_init (RISCVBootInfo *info,RISCVHartArrayState *harts) { + info->ram_low_start =0 ; + info->ram_low_size =0 ; info->kernel_size =0 ; info->initrd_size =0 ; info->is_32bit =riscv_is_32bit (harts); } +/* +* This can be used instead of riscv_boot_info_init() if the machine has +* discontiguous physical memory. The low memory range specified will be +* used to place firmware images. +*/ +void riscv_boot_info_init_discontig_mem (RISCVBootInfo *info, +RISCVHartArrayState *harts, +hwaddr low_start,hwaddr low_size) +{ +riscv_boot_info_init (info, harts); + info->ram_low_start = low_start; + info->ram_low_size = low_size; +} +vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr) {if (info->is_32bit) {
Signature · 1 line
2.54.0
[PULL 33/39] hw/riscv: Add Tenstorrent Atlantis machine
In reply to [email protected]From: Joel Stanley <[email protected]>
The Tenstorrent Atlantis platform is a collaboration between Tenstorrent and CoreLab Technology. It is based on the Atlantis SoC, which includes the Ascalon-X CPU and other IP from Tenstorrent and CoreLab Technology. The Tenstorrent Ascalon-X is a high performance 64-bit RVA23 compliant RISC-V CPU.
Add the tt-atlantis machine containing serial console, interrupt controllers, and device tree support.
The Atlantis boot images loaded from include OpenSBI and an initial DTB that is passed to OpenSBI. This is approximated in the model by having QEMU build the device tree rather than load a DTB image directly. Subsequent stages may use the modified DTB provided by OpenSBI or opt to supply their own.
qemu-system-riscv64 -M tt-atlantis -m 512M \ -kernel Image -initrd rootfs.cpio -nographic
Message-ID: <[email protected]>
--- MAINTAINERS | 12 + docs/system/riscv/tt_atlantis.rst | 41 +++ docs/system/target-riscv.rst | 1 + include/hw/riscv/tt_atlantis.h | 50 +++ hw/riscv/tt_atlantis.c | 523 ++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 10 + hw/riscv/meson.build | 1 + 7 files changed, 638 insertions(+) create mode 100644 docs/system/riscv/tt_atlantis.rst create mode 100644 include/hw/riscv/tt_atlantis.h create mode 100644 hw/riscv/tt_atlantis.c
MAINTAINERS +12 -0
@@ -1790,6 +1790,18 @@ F: hw/*/*sifive*.c F: include/hw/*/*sifive*.h F: tests/functional/riscv64/test_sifive_u.py +Tenstorrent Machines +M: Joel Stanley <[email protected]> +M: Nicholas Piggin <[email protected]> +R: Anirudh Srinivasan <[email protected]> +R: Michael Ellerman <[email protected]> +R: Portia Stephens <[email protected]> +L: [email protected] +S: Supported +F: docs/system/riscv/tt_*.rst +F: hw/riscv/tt_*.c +F: include/hw/riscv/tt_*.h + AMD Microblaze-V Generic Board M: Sai Pavan Boddu <[email protected]> S: Maintained
docs/system/riscv/tt_atlantis.rst new file +41 -0
41 lines not on this page · raw message
docs/system/target-riscv.rst +1 -0
@@ -72,6 +72,7 @@ undocumented; you can get a complete list by running riscv/mips riscv/shakti-c riscv/sifive_u + riscv/tt_atlantis riscv/virt riscv/xiangshan-kunminghu
include/hw/riscv/tt_atlantis.h new file +50 -0
50 lines not on this page · raw message
hw/riscv/tt_atlantis.c new file +523 -0
523 lines not on this page · raw message
hw/riscv/Kconfig +10 -0
@@ -120,6 +120,16 @@ config SPIKE select RISCV_ACLINT select SIFIVE_PLIC +config TENSTORRENT + bool + default y + depends on RISCV64 + select RISCV_ACLINT + select RISCV_APLIC + select RISCV_IMSIC + select SERIAL_MM + select DEVICE_TREE + config XIANGSHAN_KUNMINGHU bool default y
hw/riscv/meson.build +1 -0
@@ -11,6 +11,7 @@ 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')) riscv_ss.add(when: 'CONFIG_SPIKE', if_true: files('spike.c')) riscv_ss.add(when: 'CONFIG_MICROCHIP_PFSOC', if_true: files('microchip_pfsoc.c')) +riscv_ss.add(when: 'CONFIG_TENSTORRENT', if_true: files('tt_atlantis.c')) riscv_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) riscv_ss.add(when: 'CONFIG_RISCV_IOMMU', if_true: files( 'riscv-iommu.c', 'riscv-iommu-pci.c', 'riscv-iommu-sys.c', 'riscv-iommu-hpm.c'))
Signature · 1 line
2.54.0
[PULL 34/39] hw/riscv/atlantis: Ensure OpenSBI has a non-zero next_addr
In reply to [email protected]From: Alistair Francis <[email protected]>
When using OpenSBI fw_dynamic on the Atlantis board OpenSBI fails to print any output, as it hits an error early on
in the boot process and gets stuck in sbi_hart_hang().
The error occurs in the sanitize_domain() function inside OpenSBI. sanitize_domain() is called after a M-Mode OpenSBI Firmware and a generic coverall S-Mode RWX memory region are created. sanitize_domain() is checking that the next address is executable.
If no next address is provided (which occurs on QEMU with an empty payload), then dom->next_addr will be 0. On most RISC-V boards address 0 will fall inside the coverall S-Mode RWX memory region and pass this check. On Atlantis the OpenSBI firmware is running at address 0, so this address falls inside the M-Mode only OpenSBI firmware region and fails the check.
Once the check has failed OpenSBI aborts and the user doesn't see any messages. This can be fixed by either supplying a payload, or just manually forcing a non-zero address (actually just any address that isn't the OpenSBI firmware) for next_addr.
This patch ensures that if no kernel is loaded we still specify a default kernel_entry so that OpenSBI happily boots and jumps to the first address in memory.
Message-ID: <[email protected]>
--- hw/riscv/tt_atlantis.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
hw/riscv/tt_atlantis.c +9 -1
@@ -377,8 +377,16 @@ static void tt_atlantis_machine_done(Notifier *notifier, void *data)if (machine->kernel_filename) {riscv_load_kernel (machine, &boot_info, kernel_start_addr, true,NULL ); + kernel_entry = boot_info.image_low_addr; + }else { +/* If we aren't loading a payload, OpenSBI thinks we are trying to boot +* address 0, which fails `sbi_domain_check_addr()` as that is where +* OpenSBI is running. Instead point OpenSBI to the end of the region +* where it was loaded, which avoids the early hang, allowing the +* system to proceed with the OpenSBI boot output. +*/ + kernel_entry = kernel_start_addr; } - kernel_entry = boot_info.image_low_addr; fdt_load_addr = riscv_compute_fdt_addr(s->memmap[TT_ATL_DDR_LO].base, s->memmap[TT_ATL_DDR_LO].size,
Signature · 1 line
2.54.0
[PULL 16/39] hw/riscv/virt.c: change 'plic' nodename to 'interrupt-controller'
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We're still using "/soc/plic@..." as FDT nodename in virt.c. This is not the right nodename per the DT docs:
The nodename must be 'interrupt-controller@...' since the node inherits the 'interrupt-controller' type. In fact, ever since at least the 2020 Linux kernel commit c825a081c169cc7f ("dt-bindings: riscv: convert plic bindings to json-schema") the correct nodename has been 'interrupt-controller' for the sifive PLIC controller.
There's no deprecation needed for bug fixes so we're just fixing the name. This was the policy we dud when fixing the aplic [1] and the imsic [2] nodenames to 'interrupt-controller@...' as well.
The sifive_u PLIC FDT already uses the correct nodename for PLIC, so it is safe to assume that available SW is already aware of the correct nodename and this change won't affect well-behaved SW.
[1] commit 29390fd ("hw/riscv/virt.c: rename aplic nodename to 'interrupt-controller'")
[2] commit e8ad581 ("hw/riscv/virt.c: change imsic nodename to 'interrupt-controller'")
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/virt.c +1 -1
@@ -335,7 +335,7 @@ static void create_fdt_socket_plic(RISCVVirtState *s, plic_phandles[socket] = (*phandle)++; plic_addr = s->memmap[VIRT_PLIC ].base + (s->memmap[VIRT_PLIC ].size * socket); - plic_name =g_strdup_printf ("/soc/plic@%lx" , plic_addr); + plic_name =g_strdup_printf ("/soc/interrupt-controller@%lx" , plic_addr);qemu_fdt_add_subnode (ms->fdt, plic_name);qemu_fdt_setprop_cell (ms->fdt, plic_name,"#interrupt-cells" ,FDT_PLIC_INT_CELLS );
Signature · 1 line
2.54.0
[PULL 28/39] hw/riscv/boot: Account for discontiguous memory when loading firmware
In reply to [email protected]From: Nicholas Piggin <[email protected]>
This loads firmware into the first (low) memory range, accounting for machines having discontiguous memory regions.
Message-ID: <[email protected]>
--- include/hw/riscv/boot.h | 5 ++++- hw/riscv/boot.c | 18 ++++++++++++------ hw/riscv/k230.c | 8 ++++++-- hw/riscv/microchip_pfsoc.c | 8 ++++++-- hw/riscv/opentitan.c | 6 ++++-- hw/riscv/shakti_c.c | 6 +++++- hw/riscv/sifive_u.c | 6 ++++-- hw/riscv/spike.c | 6 ++++-- hw/riscv/virt.c | 7 ++++--- hw/riscv/xiangshan_kmh.c | 6 +++++- 10 files changed, 54 insertions(+), 22 deletions(-)
include/hw/riscv/boot.h +4 -1
@@ -53,13 +53,16 @@ void riscv_boot_info_init_discontig_mem(RISCVBootInfo *info,vaddr riscv_calc_kernel_start_addr (RISCVBootInfo *info,hwaddr firmware_end_addr);hwaddr riscv_find_and_load_firmware (MachineState *machine, +RISCVBootInfo *info,const char *default_machine_firmware,hwaddr *firmware_load_addr,symbol_fn_t sym_cb);const char *riscv_default_firmware_name (RISCVHartArrayState *harts);char *riscv_find_firmware (const char *firmware_filename,const char *default_machine_firmware); -hwaddr riscv_load_firmware (const char *firmware_filename, +hwaddr riscv_load_firmware (MachineState *machine, +const RISCVBootInfo *info, +const char *firmware_filename,hwaddr *firmware_load_addr,symbol_fn_t sym_cb); void riscv_load_kernel(MachineState *machine,
hw/riscv/boot.c +12 -6
@@ -151,6 +151,7 @@ char *riscv_find_firmware(const char *firmware_filename, }hwaddr riscv_find_and_load_firmware (MachineState *machine, +RISCVBootInfo *info,const char *default_machine_firmware,hwaddr *firmware_load_addr,symbol_fn_t sym_cb)
@@ -163,7 +164,8 @@ hwaddr riscv_find_and_load_firmware(MachineState *machine,if (firmware_filename) {/* If not "none" load the firmware */ - firmware_end_addr =riscv_load_firmware (firmware_filename, + firmware_end_addr =riscv_load_firmware (machine, info, + firmware_filename, firmware_load_addr, sym_cb);g_free (firmware_filename); }
@@ -171,10 +173,13 @@ hwaddr riscv_find_and_load_firmware(MachineState *machine,return firmware_end_addr; } -hwaddr riscv_load_firmware (const char *firmware_filename, +hwaddr riscv_load_firmware (MachineState *machine, +const RISCVBootInfo *info, +const char *firmware_filename,hwaddr *firmware_load_addr,symbol_fn_t sym_cb) { +uint64_t mem_size = info->ram_low_size ?: machine->ram_size;uint64_t firmware_entry, firmware_end;ssize_t firmware_size;
@@ -203,7 +208,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename, firmware_size =load_image_targphys_as (firmware_filename, *firmware_load_addr, - current_machine->ram_size,NULL , + mem_size,NULL ,NULL );if (firmware_size >0 ) {
@@ -218,7 +223,7 @@ hwaddr riscv_load_firmware(const char *firmware_filename,static void riscv_load_initrd (MachineState *machine,RISCVBootInfo *info) {const char *filename = machine->initrd_filename; -uint64_t mem_size = machine->ram_size; +uint64_t mem_size = info->ram_low_size ?: machine->ram_size;void *fdt = machine->fdt;hwaddr start, end;ssize_t size;
@@ -264,6 +269,7 @@ void riscv_load_kernel(MachineState *machine,bool load_initrd, symbol_fn_t sym_cb) { + uint64_t mem_size = info->ram_low_size ?: machine->ram_size;const char *kernel_filename = machine->kernel_filename;ssize_t kernel_size;void *fdt = machine->fdt;
@@ -295,7 +301,7 @@ void riscv_load_kernel(MachineState *machine, } kernel_size =load_image_targphys_as (kernel_filename, kernel_start_addr, - current_machine->ram_size,NULL ,NULL ); + mem_size,NULL ,NULL );if (kernel_size >0 ) { info->kernel_size = kernel_size; info->image_low_addr = kernel_start_addr;
@@ -391,7 +397,7 @@ uint64_t riscv_compute_fdt_addr(hwaddr dram_base, hwaddr dram_size, dtb_start =QEMU_ALIGN_DOWN (temp - fdtsize,2 * MiB);if (dtb_start_limit && (dtb_start < dtb_start_limit)) { -error_report ("No enough memory to place DTB after kernel/initrd" ); +error_report ("Not enough memory to place DTB after kernel/initrd" );exit (1 ); }
hw/riscv/k230.c +6 -2
@@ -424,7 +424,8 @@ static void k230_direct_boot(K230MachineState *s, MachineState *machine)riscv_load_fdt (K230_DIRECT_DTB_ADDR , machine->fdt); - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL );if (firmware_end_addr >K230_DIRECT_KERNEL_ADDR ) { error_report("K230 firmware overlaps kernel address 0x%x",
@@ -442,13 +443,16 @@ static void k230_firmware_boot(K230MachineState *s, MachineState *machine) {const char *firmware_name =riscv_default_firmware_name (&s->soc.c908_cpu);hwaddr start_addr = memmap[K230_DEV_DDRC ].base; +RISCVBootInfo boot_info = {0 };if (machine->dtb || (machine->kernel_cmdline && *machine->kernel_cmdline)) {error_report ("K230 firmware boot does not support -dtb or -append" );exit (EXIT_FAILURE ); } -riscv_find_and_load_firmware (machine, firmware_name, &start_addr,NULL ); +riscv_boot_info_init (&boot_info, &s->soc.c908_cpu); +riscv_find_and_load_firmware (machine, &boot_info, firmware_name, + &start_addr,NULL ); riscv_setup_rom_reset_vec(machine, &s->soc.c908_cpu, start_addr, memmap[K230_DEV_BOOTROM].base,
hw/riscv/microchip_pfsoc.c +6 -2
@@ -619,18 +619,22 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) firmware_load_addr =RESET_VECTOR ; } +riscv_boot_info_init_discontig_mem (&boot_info, &s->soc.u_cpus, + memmap[MICROCHIP_PFSOC_DRAM_LO ].base, + mem_low_size); +/* Load the firmware if necessary */ firmware_end_addr = firmware_load_addr;if (firmware_name) {char *filename =riscv_find_firmware (firmware_name,NULL );if (filename) { - firmware_end_addr =riscv_load_firmware (filename, + firmware_end_addr =riscv_load_firmware (machine, &boot_info, + filename, &firmware_load_addr,NULL );g_free (filename); } } -riscv_boot_info_init (&boot_info, &s->soc.u_cpus);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/opentitan.c +4 -2
@@ -100,12 +100,14 @@ static void opentitan_machine_init(MachineState *machine)memory_region_add_subregion (sys_mem, memmap[IBEX_DEV_RAM ].base, machine->ram); +riscv_boot_info_init (&boot_info, &s->soc.cpus); +if (machine->firmware) {hwaddr firmware_load_addr = memmap[IBEX_DEV_RAM ].base; -riscv_load_firmware (machine->firmware, &firmware_load_addr,NULL ); +riscv_load_firmware (machine, &boot_info, machine->firmware, + &firmware_load_addr,NULL ); } -riscv_boot_info_init (&boot_info, &s->soc.cpus);if (machine->kernel_filename) { riscv_load_kernel(machine, &boot_info, memmap[IBEX_DEV_RAM].base,
hw/riscv/shakti_c.c +5 -1
@@ -46,6 +46,7 @@ static void shakti_c_machine_state_init(MachineState *mstate) {ShaktiCMachineState *sms =RISCV_SHAKTI_MACHINE (mstate);MemoryRegion *system_memory =get_system_memory (); +RISCVBootInfo boot_info;hwaddr firmware_load_addr = shakti_c_memmap[SHAKTI_C_RAM ].base;/* Initialize SoC */
@@ -58,8 +59,11 @@ static void shakti_c_machine_state_init(MachineState *mstate) shakti_c_memmap[SHAKTI_C_RAM ].base, mstate->ram); +riscv_boot_info_init (&boot_info, &sms->soc.cpus); +if (mstate->firmware) { -riscv_load_firmware (mstate->firmware, &firmware_load_addr,NULL ); +riscv_load_firmware (mstate, &boot_info, mstate->firmware, + &firmware_load_addr,NULL ); }/* ROM reset vector */
hw/riscv/sifive_u.c +4 -2
@@ -524,11 +524,13 @@ static void sifive_u_machine_init(MachineState *machine)break ; } +riscv_boot_info_init (&boot_info, &s->soc.u_cpus); + firmware_name =riscv_default_firmware_name (&s->soc.u_cpus); - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL ); -riscv_boot_info_init (&boot_info, &s->soc.u_cpus);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/spike.c +4 -2
@@ -205,9 +205,12 @@ static void spike_board_init(MachineState *machine) } } +riscv_boot_info_init (&boot_info, &s->soc[0 ]); +/* Load firmware */ if (firmware_name) { - firmware_end_addr =riscv_load_firmware (firmware_name, + firmware_end_addr =riscv_load_firmware (machine, &boot_info, + firmware_name, &firmware_load_addr, htif_symbol_callback);g_free (firmware_name);
@@ -217,7 +220,6 @@ static void spike_board_init(MachineState *machine)create_fdt (s, memmap,riscv_is_32bit (&s->soc[0 ]), htif_custom_base);/* Load kernel */ -riscv_boot_info_init (&boot_info, &s->soc[0 ]);if (machine->kernel_filename) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/virt.c +4 -3
@@ -1310,7 +1310,10 @@ static void virt_machine_done(Notifier *notifier, void *data) } } - firmware_end_addr =riscv_find_and_load_firmware (machine, firmware_name, +riscv_boot_info_init (&boot_info, &s->soc[0 ]); + + firmware_end_addr =riscv_find_and_load_firmware (machine, &boot_info, + firmware_name, &start_addr,NULL ); pflash_blk0 =pflash_cfi01_get_blk (s->flash[0 ]);
@@ -1333,8 +1336,6 @@ static void virt_machine_done(Notifier *notifier, void *data) } } -riscv_boot_info_init (&boot_info, &s->soc[0 ]); -if (machine->kernel_filename && !kernel_entry) { kernel_start_addr =riscv_calc_kernel_start_addr (&boot_info, firmware_end_addr);
hw/riscv/xiangshan_kmh.c +5 -1
@@ -167,6 +167,7 @@ static void xiangshan_kmh_machine_init(MachineState *machine)const MemMapEntry *memmap = xiangshan_kmh_memmap;MemoryRegion *system_memory =get_system_memory ();hwaddr start_addr = memmap[XIANGSHAN_KMH_DRAM ].base; +RISCVBootInfo boot_info;/* Initialize SoC */ object_initialize_child(OBJECT(machine), "soc", &s->soc,
@@ -178,13 +179,16 @@ static void xiangshan_kmh_machine_init(MachineState *machine) memmap[XIANGSHAN_KMH_DRAM ].base, machine->ram); +riscv_boot_info_init (&boot_info, &s->soc.cpus); +/* ROM reset vector */ riscv_setup_rom_reset_vec (machine, &s->soc.cpus, start_addr, memmap[XIANGSHAN_KMH_ROM ].base, memmap[XIANGSHAN_KMH_ROM ].size,0 ,0 );if (machine->firmware) { -riscv_load_firmware (machine->firmware, &start_addr,NULL ); +riscv_load_firmware (machine, &boot_info, machine->firmware, + &start_addr,NULL ); }/* Note: dtb has been integrated into firmware(OpenSBI) when compiling */
Signature · 1 line
2.54.0
[PULL 29/39] hw/riscv/virt: Move AIA initialisation to helper file
In reply to [email protected]From: Joel Stanley <[email protected]>
The AIA init will be used by any server class riscv machine. Separate it out in order to share code with such systems.
The virt machine keeps machine specific #defines such as VIRT_IRQCHIP_NUM_MSIS, VIRT_IRQCHIP_NUM_PRIO_BITS.
Message-ID: <[email protected]>
--- hw/riscv/aia.h | 26 +++++++++++ include/hw/riscv/virt.h | 1 - hw/riscv/aia.c | 89 ++++++++++++++++++++++++++++++++++++++ hw/riscv/virt-acpi-build.c | 2 + hw/riscv/virt.c | 87 +++++-------------------------------- hw/riscv/meson.build | 1 + 6 files changed, 129 insertions(+), 77 deletions(-) create mode 100644 hw/riscv/aia.h create mode 100644 hw/riscv/aia.c
hw/riscv/aia.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* QEMU RISC-V Advanced Interrupt Architecture (AIA) +* +* Copyright (C) 2019 Western Digital Corporation or its affiliates. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_RISCV_AIA_H +#define HW_RISCV_AIA_H + +#include "exec/hwaddr.h" + +#define VIRT_IRQCHIP_NUM_SOURCES 96 + +uint32_t imsic_num_bits (uint32_t count); + +DeviceState *riscv_create_aia (bool msimode,int aia_guests, +const MemMapEntry *aplic_m, +const MemMapEntry *aplic_s, +const MemMapEntry *imsic_m, +const MemMapEntry *imsic_s, +int socket,int base_hartid,int hart_count, +uint32_t num_msis,uint32_t num_prio_bits); + +#endif
include/hw/riscv/virt.h +0 -1
@@ -135,7 +135,6 @@ enum {bool virt_is_acpi_enabled (RISCVVirtState *s);bool virt_is_iommu_sys_enabled (RISCVVirtState *s);void virt_acpi_setup (RISCVVirtState *vms); -uint32_t imsic_num_bits (uint32_t count);/* * The virt machine physical address space used by some of the devices
hw/riscv/aia.c new file +89 -0
89 lines not on this page · raw message
hw/riscv/virt-acpi-build.c +2 -0
@@ -42,6 +42,8 @@#include "system/kvm.h" #include "system/reset.h" +#include "aia.h" +#define ACPI_BUILD_TABLE_SIZE 0x20000#define ACPI_BUILD_INTC_ID (socket, index) ((socket << 24) | (index))
hw/riscv/virt.c +11 -76
111 lines not on this page · raw message
hw/riscv/meson.build +1 -0
@@ -1,4 +1,5 @@ riscv_ss = ss.source_set() +riscv_ss.add(files('aia.c')) riscv_ss.add(files('boot.c')) riscv_ss.add(files('fdt-common.c')) riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c'))
Signature · 1 line
2.54.0
[PULL 37/39] hw/riscv/atlantis: Integrate i2c controllers
In reply to [email protected]From: Joel Stanley <[email protected]>
Add DesignWare I2C controllers to the tt-atlantis machine.
Provide a fixed clock in the device tree so that the Linux driver probes without WARNing.
Message-ID: <[email protected]>
--- include/hw/riscv/tt_atlantis.h | 14 ++++++++ hw/riscv/tt_atlantis.c | 59 ++++++++++++++++++++++++++++++++++ hw/riscv/Kconfig | 1 + 3 files changed, 74 insertions(+)
include/hw/riscv/tt_atlantis.h +14 -0
@@ -11,12 +11,15 @@#include "hw/core/boards.h" #include "hw/core/sysbus.h" +#include "hw/i2c/designware_i2c.h" #include "hw/intc/riscv_imsic.h" #include "hw/riscv/riscv_hart.h" #define TYPE_TT_ATLANTIS_MACHINE MACHINE_TYPE_NAME("tt-atlantis") OBJECT_DECLARE_SIMPLE_TYPE(TTAtlantisState, TT_ATLANTIS_MACHINE) +#define TT_ATL_NUM_I2C 5 +struct TTAtlantisState {/*< private >*/ MachineState parent;
@@ -27,11 +30,17 @@ struct TTAtlantisState {RISCVHartArrayState soc;DeviceState *irqchip; +DesignWareI2CState i2c[TT_ATL_NUM_I2C ];int fdt_size; };enum { +TT_ATL_I2C0_IRQ =33 , +TT_ATL_I2C1_IRQ =34 , +TT_ATL_I2C2_IRQ =35 , +TT_ATL_I2C3_IRQ =36 , +TT_ATL_I2C4_IRQ =37 ,TT_ATL_UART1_IRQ =39 , };
@@ -40,6 +49,11 @@ enum {TT_ATL_BOOTROM ,TT_ATL_DDR_LO ,TT_ATL_DDR_HI , +TT_ATL_I2C0 , +TT_ATL_I2C1 , +TT_ATL_I2C2 , +TT_ATL_I2C3 , +TT_ATL_I2C4 ,TT_ATL_MAPLIC ,TT_ATL_MIMSIC , TT_ATL_SAPLIC,
hw/riscv/tt_atlantis.c +59 -0
87 lines not on this page · raw message
hw/riscv/Kconfig +1 -0
@@ -129,6 +129,7 @@ config TENSTORRENT select RISCV_IMSIC select SERIAL_MM select DEVICE_TREE + select DESIGNWARE_I2C config XIANGSHAN_KUNMINGHU bool
Signature · 1 line
2.54.0
[PULL 25/39] target/riscv: Report QEMU CPU archid as 42
In reply to [email protected]From: Charlie Jenkins <[email protected]>
When a non-vendor CPU is used, report the archid as 42 which has been allocated for QEMU in the riscv isa manual [1]. This can help software check if it is running in QEMU.
[1] https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
target/riscv/cpu.c +11 -0
@@ -47,6 +47,13 @@static const char riscv_single_letter_exts[] ="IEMAFDQCBPVH" ;const uint32_t misa_bits[] = {RVI ,RVE ,RVM ,RVA ,RVF ,RVD ,RVV ,RVC ,RVS ,RVU ,RVH ,RVG ,RVB ,0 }; +#define RISCV_CPU_MVENDORID 0 +#define RISCV_CPU_MIMPID 0 +/* +* marchid allocated for qemu: +* https://github.com/riscv/riscv-isa-manual/blob/main/marchid.md +*/ +#define RISCV_CPU_MARCHID 42/* * From vector_helper.c
@@ -1204,6 +1211,10 @@ static void riscv_cpu_init(Object *obj) mcc->def->profile->enabled = true; } + cpu->cfg.mvendorid =RISCV_CPU_MVENDORID ; + cpu->cfg.marchid =RISCV_CPU_MARCHID ; + cpu->cfg.mimpid =RISCV_CPU_MIMPID ; + env->misa_ext_mask = env->misa_ext = mcc->def->misa_ext;riscv_cpu_cfg_merge (&cpu->cfg, &mcc->def->cfg);
Signature · 1 line
2.54.0
[PULL 21/39] target/riscv: Apply UXL WARL handling to vsstatus
In reply to [email protected]From: SeungJu Cheon <[email protected]>
write_mstatus() already handles the reserved UXL value by writing a legal value instead.
Apply the same handling when writing vsstatus so that reserved UXL values follow the same WARL behavior.
Factor the common logic into a local helper riscv_write_uxl() and use it for both mstatus and vsstatus.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
target/riscv/csr.c +17 -10
@@ -2021,6 +2021,20 @@ static target_ulong legalize_mpp(CPURISCVState *env, target_ulong old_mpp,return val; } +static uint64_t riscv_write_uxl (CPURISCVState *env,uint64_t val, +uint64_t field) +{ +RISCVMXL xl =riscv_cpu_mxl (env); +uint64_t uxl =get_field (val, field); + +if (uxl ==MXL_RV128 ) { + uxl = xl ==MXL_RV128 ?MXL_RV64 : xl; + val =set_field (val, field, uxl); + } + +return val; +} +static RISCVException write_mstatus (CPURISCVState *env,int csrno,target_ulong val,uintptr_t ra) {
@@ -2067,17 +2081,8 @@ static RISCVException write_mstatus(CPURISCVState *env, int csrno,if (xl !=MXL_RV32 || env->debugger) {if ((val &MSTATUS64_UXL ) !=0 ) { -uint64_t uxl = val &MSTATUS64_UXL >>32 ; mask |=MSTATUS64_UXL ; - -/* -* uxl = 3 is reserved so write the current xl instead. -* In case xl = MXL_RV128 (3) write MXL_RV64. -*/ -if (uxl ==3 ) { - uxl = xl ==MXL_RV128 ?MXL_RV64 : xl; - val =deposit64 (val,32 ,2 , uxl); - } + val =riscv_write_uxl (env, val,MSTATUS64_UXL ); } }
@@ -5239,6 +5244,8 @@ static RISCVException write_vsstatus(CPURISCVState *env, int csrno,uint64_t mask = (target_ulong)-1 ;if ((val &VSSTATUS64_UXL ) ==0 ) { mask &= ~VSSTATUS64_UXL ; + }else { + val =riscv_write_uxl (env, val,VSSTATUS64_UXL ); }if ((env->henvcfg &HENVCFG_DTE )) {if ((val &SSTATUS_SDT ) !=0 ) {
Signature · 1 line
2.54.0
[PULL 38/39] hw/riscv/atlantis: Add some i2c peripherals
In reply to [email protected]From: Joel Stanley <[email protected]>
Add an I2C RTC device and a temperature sensor. These are not present on the board but help for testing.
The tmp105 is a lm75 compatible temperature sensor used by the SENSORS_LM75 Linux kernel driver.
The ds1338 is a RTC device that is used by the RTC_DRV_DS1307 Linux kernel driver.
Message-ID: <[email protected]>
--- hw/riscv/tt_atlantis.c | 27 +++++++++++++++++++++++++++ hw/riscv/Kconfig | 2 ++ 2 files changed, 29 insertions(+)
hw/riscv/tt_atlantis.c +27 -0
@@ -64,6 +64,13 @@ static const MemMapEntry tt_atlantis_memmap[] = { [TT_ATL_DDR_HI] = { 0x100000000, 0x1000000000 }, }; +static I2CBus *i2c_get_bus (TTAtlantisState *s,unsigned busnr) +{ +assert (busnr <TT_ATL_NUM_I2C ); + +return s->i2c[busnr].bus; +} +static uint32_t fdt_phandle =1 ;static uint32_t next_phandle (void ) {
@@ -309,6 +316,19 @@ static void create_fdt_i2c(void *fdt, const MemMapEntry *mem, uint32_t irq,qemu_fdt_setprop_cell (fdt, name,"#size-cells" ,0 ); } +static void create_fdt_i2c_device (TTAtlantisState *s,int bus, +const char *compat,int addr) +{ +void *fdt =MACHINE (s)->fdt; +hwaddr base = s->memmap[TT_ATL_I2C0 + bus].base; + g_autofree char *name = g_strdup_printf("/soc/i2c@%"HWADDR_PRIX"/sensor@%x", + base, addr); + +qemu_fdt_add_subnode (fdt, name); +qemu_fdt_setprop_string (fdt, name,"compatible" , compat); +qemu_fdt_setprop_cell (fdt, name,"reg" , addr); +} +static void finalize_fdt (TTAtlantisState *s) {uint32_t aplic_s_phandle =next_phandle ();
@@ -336,6 +356,9 @@ static void finalize_fdt(TTAtlantisState *s)TT_ATL_I2C0_IRQ + i, aplic_s_phandle, periph_clk_phandle); } + +create_fdt_i2c_device (s,0 ,"dallas,ds1338" ,0x6f ); +create_fdt_i2c_device (s,4 ,"ti,tmp105" ,0x48 ); }static void create_fdt (TTAtlantisState *s)
@@ -551,6 +574,10 @@ static void tt_atlantis_machine_init(MachineState *machine) qdev_get_gpio_in(s->irqchip, TT_ATL_I2C0_IRQ + i)); } +/* I2C peripherals: qemu specific */ +i2c_slave_create_simple (i2c_get_bus (s,0 ),"ds1338" ,0x6f ); +i2c_slave_create_simple (i2c_get_bus (s,4 ),"tmp105" ,0x48 ); +/* Load or create device tree */ if (machine->dtb) {load_fdt (s);
hw/riscv/Kconfig +2 -0
@@ -130,6 +130,8 @@ config TENSTORRENT select SERIAL_MM select DEVICE_TREE select DESIGNWARE_I2C + select DS1338 + select TMP105 config XIANGSHAN_KUNMINGHU bool
Signature · 1 line
2.54.0
[PULL 12/39] target/riscv/kvm: skip FP/Vector sync on KVM_PUT_RUNTIME_STATE
In reply to [email protected]From: Meng Zhuo <[email protected]>
During KVM exit processing (KVM_PUT_RUNTIME_STATE), QEMU never modifies FP or Vector registers — only core GPRs/PC and CSRs are potentially changed. Re-syncing 32 FP and 32 Vector registers on every KVM exit wastes 36-68 individual KVM_SET_ONE_REG ioctls per vCPU exit.
Follow the s390x pattern: early return on RUNTIME after syncing core registers and CSRs. KVM_PUT_FULL_STATE and KVM_PUT_RESET_STATE continue to sync everything for correctness during migration and initialization.
Message-ID: <[email protected]>
--- target/riscv/kvm/kvm-cpu.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
target/riscv/kvm/kvm-cpu.c +14 -5
@@ -1395,6 +1395,17 @@ int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp)return ret; } +/* +* For RUNTIME_STATE, KVM already has the correct FP and Vector state +* from the preceding KVM_RUN exit. QEMU never modifies these registers +* during exit handling, so re-syncing is unnecessary. This saves ~68 +* KVM_SET_ONE_REG ioctls per vCPU exit. See also s390x which uses +* the same pattern. +*/ +if (KVM_PUT_RUNTIME_STATE == level) { +return ret; + } + ret =kvm_riscv_put_regs_fp (cs);if (ret) {return ret;
@@ -1407,11 +1418,9 @@ int kvm_arch_put_registers(CPUState *cs, KvmPutState level, Error **errp)if (KVM_PUT_RESET_STATE == level) {RISCVCPU *cpu =RISCV_CPU (cs); -if (cs->cpu_index ==0 ) { - ret =kvm_riscv_sync_mpstate_to_kvm (cpu,KVM_MP_STATE_RUNNABLE ); - }else { - ret =kvm_riscv_sync_mpstate_to_kvm (cpu,KVM_MP_STATE_STOPPED ); - } +int state = cs->cpu_index ==0 ?KVM_MP_STATE_RUNNABLE + :KVM_MP_STATE_STOPPED ; + ret =kvm_riscv_sync_mpstate_to_kvm (cpu, state);if (ret) {return ret; }
Signature · 1 line
2.54.0
[PULL 20/39] hw/riscv/riscv-iommu: check DC.TC reserved bits
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We are not checking for reserved TC bits being set during device context validation.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3548
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu-bits.h | 3 +++ hw/riscv/riscv-iommu.c | 4 ++++ 2 files changed, 7 insertions(+)
hw/riscv/riscv-iommu-bits.h +3 -0
@@ -308,6 +308,9 @@ struct riscv_iommu_dc {#define RISCV_IOMMU_DC_IOHGATP_GSCID GENMASK_ULL(59, 44)#define RISCV_IOMMU_DC_IOHGATP_MODE RISCV_IOMMU_ATP_MODE_FIELD +#define RISCV_IOMMU_DC_TC_RESERVED (GENMASK_ULL(23, 12) \ + | GENMASK_ULL(63, 32)) +enum riscv_iommu_dc_iohgatp_modes {RISCV_IOMMU_DC_IOHGATP_MODE_BARE =0 ,RISCV_IOMMU_DC_IOHGATP_MODE_SV32X4 =8 ,
hw/riscv/riscv-iommu.c +4 -0
@@ -752,6 +752,10 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMUState *s,uint32_t fsc_mode, msi_mode;uint64_t gatp; +if (ctx->tc &RISCV_IOMMU_DC_TC_RESERVED ) { +return false; + } + if (!(s->cap & RISCV_IOMMU_CAP_ATS) && (ctx->tc & RISCV_IOMMU_DC_TC_EN_ATS || ctx->tc & RISCV_IOMMU_DC_TC_EN_PRI ||
Signature · 1 line
2.54.0
[PULL 35/39] tests/functional/riscv64: Add tt-atlantis tests
In reply to [email protected]From: Nicholas Piggin <[email protected]>
Add OpenSBI and Linux boot tests for the tt-atlantis machine. Based on tests/functional/riscv64/test_sifive_u.py.
Message-ID: <[email protected]>
--- MAINTAINERS | 1 + tests/functional/riscv64/meson.build | 1 + tests/functional/riscv64/test_opensbi.py | 4 ++ tests/functional/riscv64/test_tt_atlantis.py | 57 ++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100755 tests/functional/riscv64/test_tt_atlantis.py
MAINTAINERS +1 -0
@@ -1801,6 +1801,7 @@ S: Supported F: docs/system/riscv/tt_*.rst F: hw/riscv/tt_*.c F: include/hw/riscv/tt_*.h +F: tests/functional/riscv64/test_tt_*.py AMD Microblaze-V Generic Board M: Sai Pavan Boddu <[email protected]>
tests/functional/riscv64/meson.build +1 -0
@@ -14,5 +14,6 @@ tests_riscv64_system_thorough = [ 'endianness', 'boston', 'sifive_u', + 'tt_atlantis', 'tuxrun', ]
tests/functional/riscv64/test_opensbi.py +4 -0
@@ -28,6 +28,10 @@ def test_riscv_sifive_u(self): self.set_machine('sifive_u') self.boot_opensbi() + def test_riscv_tt_atlantis(self): + self.set_machine('tt-atlantis') + self.boot_opensbi() + def test_riscv_virt(self): self.set_machine('virt') self.boot_opensbi()
tests/functional/riscv64/test_tt_atlantis.py new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.54.0
[PULL 09/39] target/riscv: avoid abort when reading vtype before env->xl is set
In reply to [email protected]From: ZhengXiang Qin <[email protected]>
TCG plugins may read registers from the vcpu_init_cb() callback. For vtype, this reaches read_vtype() before env->xl has been initialized.
In that case read_vtype() currently hits g_assert_not_reached() because env->xl is zero. Fall back to the CPU's maximum XLEN only for this early-init case.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3545
Message-ID: <[email protected]>
--- target/riscv/csr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
target/riscv/csr.c +10 -1
@@ -949,7 +949,16 @@ static RISCVException read_vtype(CPURISCVState *env, int csrno, target_ulong *val) {uint64_t vill; -switch (env->xl) { +int xl = env->xl; +/* +* TCG plugins can read registers before env->xl is initialized. +* Fall back to the CPU's maximum XLEN in that early-init case. +*/ +if (xl ==0 ) { + xl =riscv_cpu_mxl (env); + } + +switch (xl) {case MXL_RV32 : vill = (uint32_t )env->vill <<31 ;break ;
Signature · 1 line
2.54.0
[PULL 17/39] hw/riscv: add create_fdt_plic() helper
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Consolidate the common plic FDT code between 'virt' and sifive_u boards into a single place.
Message-ID: <[email protected]>
--- include/hw/riscv/fdt-common.h | 5 ++++ hw/riscv/fdt-common.c | 30 +++++++++++++++++++++ hw/riscv/sifive_u.c | 34 +++++++----------------- hw/riscv/virt.c | 49 ++++++++++++----------------------- 4 files changed, 61 insertions(+), 57 deletions(-)
include/hw/riscv/fdt-common.h +5 -0
@@ -30,4 +30,9 @@ void create_fdt_socket_cpu_sifive(void *fdt, char *clust_name, int cpu_id, int socket_id, int socket_hartid_base, uint32_t *phandle, uint32_t *intc_phandles); +void create_fdt_plic (void *fdt,hwaddr addr,uint64_t size, +uint32_t plic_phandle,uint32_t int_cells, +uint32_t addr_cells,uint32_t *plic_cells, +uint32_t cells_size,uint32_t ndev_sources, +bool numa_enabled,int socket);#endif
hw/riscv/fdt-common.c +30 -0
@@ -200,3 +200,33 @@ create_fdt_socket_cpu_sifive(void *fdt, char *clust_name, socket_id, socket_hartid_base, phandle, intc_phandles, false, false); } + +void create_fdt_plic (void *fdt,hwaddr addr,uint64_t size, +uint32_t plic_phandle,uint32_t int_cells, +uint32_t addr_cells,uint32_t *plic_cells, +uint32_t cells_size,uint32_t ndev_sources, +bool numa_enabled,int socket_id) +{ + g_autofree char *nodename = NULL; +static const char *const plic_compat[2 ] = { +"sifive,plic-1.0.0" ,"riscv,plic0" + }; + + nodename =g_strdup_printf ("/soc/interrupt-controller@%" HWADDR_PRIx, addr); + +qemu_fdt_add_subnode (fdt, nodename); +qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" , int_cells); +qemu_fdt_setprop_cell (fdt, nodename,"#address-cells" , addr_cells); +qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , + (char **)&plic_compat,ARRAY_SIZE (plic_compat)); +qemu_fdt_setprop (fdt, nodename,"interrupt-controller" ,NULL ,0 ); +qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , + plic_cells, cells_size); +qemu_fdt_setprop_sized_cells (fdt, nodename,"reg" , +2 , addr,2 , size); +qemu_fdt_setprop_cell (fdt, nodename,"riscv,ndev" , ndev_sources); +if (numa_enabled) { +qemu_fdt_setprop_cell (fdt, nodename,"numa-node-id" , socket_id); + } +qemu_fdt_setprop_cell (fdt, nodename,"phandle" , plic_phandle); +}
hw/riscv/sifive_u.c +10 -24
@@ -100,14 +100,11 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,MachineState *ms =MACHINE (s);void *fdt;int cpu; -uint32_t *cells; +uint32_t *cells, cells_length;char *nodename;uint32_t plic_phandle, prci_phandle, gpio_phandle, phandle =1 ;uint32_t hfclk_phandle, rtcclk_phandle, phy_phandle;static const char *const ethclk_names[2 ] = {"pclk" ,"hclk" }; -static const char *const plic_compat[2 ] = { -"sifive,plic-1.0.0" ,"riscv,plic0" - }; g_autofree uint32_t *intc_phandles = g_new0(uint32_t, ms->smp.cpus); g_autofree char *clust_name = NULL;
@@ -197,7 +194,8 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,g_free (nodename); plic_phandle = phandle++; - cells =g_new0 (uint32_t, ms->smp.cpus *4 -2 ); + cells_length = ms->smp.cpus *4 -2 ; + cells =g_new0 (uint32_t, cells_length);for (cpu =0 ; cpu < ms->smp.cpus; cpu++) {/* cpu 0 is the management hart that does not have S-mode */ if (cpu ==0 ) {
@@ -210,26 +208,14 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, cells[cpu *4 +1 ] =cpu_to_be32 (IRQ_S_EXT ); } } - nodename =g_strdup_printf ("/soc/interrupt-controller@%lx" , - (long )memmap[SIFIVE_U_DEV_PLIC ].base); -qemu_fdt_add_subnode (fdt, nodename); -qemu_fdt_setprop_cell (fdt, nodename,"#interrupt-cells" , -SIFIVE_U_PLIC_INT_CELLS ); -qemu_fdt_setprop_cell (fdt, nodename,"#address-cells" , -SIFIVE_U_PLIC_ADDR_CELLS ); -qemu_fdt_setprop_string_array (fdt, nodename,"compatible" , - (char **)&plic_compat,ARRAY_SIZE (plic_compat)); -qemu_fdt_setprop (fdt, nodename,"interrupt-controller" ,NULL ,0 ); -qemu_fdt_setprop (fdt, nodename,"interrupts-extended" , - cells, (ms->smp.cpus *4 -2 ) *sizeof (uint32_t )); -qemu_fdt_setprop_cells (fdt, nodename,"reg" , -0x0 , memmap[SIFIVE_U_DEV_PLIC ].base, -0x0 , memmap[SIFIVE_U_DEV_PLIC ].size); -qemu_fdt_setprop_cell (fdt, nodename,"riscv,ndev" , -SIFIVE_U_PLIC_NUM_SOURCES -1 ); -qemu_fdt_setprop_cell (fdt, nodename,"phandle" , plic_phandle); + +create_fdt_plic (fdt, memmap[SIFIVE_U_DEV_PLIC ].base, + memmap[SIFIVE_U_DEV_PLIC ].size, + plic_phandle,SIFIVE_U_PLIC_INT_CELLS , +SIFIVE_U_PLIC_ADDR_CELLS , cells, + cells_length *sizeof (uint32_t ), +SIFIVE_U_PLIC_NUM_SOURCES -1 , false,0 );g_free (cells); -g_free (nodename); gpio_phandle = phandle++; nodename = g_strdup_printf("/soc/gpio@%lx",
hw/riscv/virt.c +16 -33
74 lines not on this page · raw message
Signature · 1 line
2.54.0
[PULL 32/39] target/riscv: tt-ascalon: Enable Zkr extension
In reply to [email protected]From: Nicholas Piggin <[email protected]>
Ascalon supports Zkr and the SEED CSR.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/cpu.c +1 -0
@@ -3251,6 +3251,7 @@ static const TypeInfo riscv_cpu_type_infos[] = { .cfg.ext_zba = true, .cfg.ext_zbb = true, .cfg.ext_zbs = true, + .cfg.ext_zkr = true, .cfg.ext_zkt = true, .cfg.ext_zvbb = true, .cfg.ext_zvbc = true,
Signature · 1 line
2.54.0
[PULL 23/39] hw/riscv/riscv-iommu.c: set RISCV_IOMMU_FQ_HDR_PV appropriately
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We're hardcoding 'true' to FQ_HDR_PV in riscv_iommu_report_fault(). Use the 'pv' bool the caller provides that indicates if the process_id is valid.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3556
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +1 -1
@@ -580,7 +580,7 @@ static void riscv_iommu_report_fault(RISCVIOMMUState *s, ev.hdr =set_field (ev.hdr,RISCV_IOMMU_FQ_HDR_CAUSE , cause); ev.hdr =set_field (ev.hdr,RISCV_IOMMU_FQ_HDR_TTYPE , fault_type); ev.hdr =set_field (ev.hdr,RISCV_IOMMU_FQ_HDR_DID , ctx->devid); - ev.hdr =set_field (ev.hdr,RISCV_IOMMU_FQ_HDR_PV , true); + ev.hdr =set_field (ev.hdr,RISCV_IOMMU_FQ_HDR_PV , pv);if (pv) { ev.hdr =set_field (ev.hdr,RISCV_IOMMU_FQ_HDR_PID , ctx->process_id);
Signature · 1 line
2.54.0
[PULL 31/39] hw/riscv/aia: Configure stride for the M-mode IMSIC
In reply to [email protected]From: Joel Stanley <[email protected]>
riscv_create_aia() currently hard-codes the M-IMSIC at one 4 KiB page per hart and gives callers no way to widen it.
Add an m_imsic_stride parameter that supplies the per hart byte stride directly. The virt machine passes IMSIC_HART_SIZE(0) (= 4 KiB), preserving its existing compact layout.
The parameter only changes how the slots are spaced, with the rest of each slot reserved. This allows future platforms that have different layouts to control the stride.
Message-ID: <[email protected]>
--- hw/riscv/aia.h | 1 + hw/riscv/aia.c | 3 ++- hw/riscv/virt.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-)
hw/riscv/aia.h +1 -0
@@ -14,6 +14,7 @@uint32_t imsic_num_bits (uint32_t count); DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint32_t m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,
hw/riscv/aia.c +2 -1
@@ -25,6 +25,7 @@ uint32_t imsic_num_bits(uint32_t count) } DeviceState *riscv_create_aia(bool msimode, int aia_guests, + uint32_t m_imsic_stride, uint16_t num_sources, const MemMapEntry *aplic_m, const MemMapEntry *aplic_s,
@@ -47,7 +48,7 @@ DeviceState *riscv_create_aia(bool msimode, int aia_guests,/* Per-socket M-level IMSICs */ addr = imsic_m->base + socket * (1U <<IMSIC_MMIO_GROUP_MIN_SHIFT );for (i =0 ; i < hart_count; i++) { -riscv_imsic_create (addr + i *IMSIC_HART_SIZE (0 ), +riscv_imsic_create (addr + i * m_imsic_stride, base_hartid + i, true,1 , num_msis); }
hw/riscv/virt.c +1 -0
@@ -1401,6 +1401,7 @@ static void virt_machine_init(MachineState *machine) }else { s->irqchip[i] = riscv_create_aia(s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC, s->aia_guests, + IMSIC_HART_SIZE(0), s->num_sources, &s->memmap[VIRT_APLIC_M], &s->memmap[VIRT_APLIC_S],
Signature · 1 line
2.54.0
[PULL 36/39] hw/i2c: Add DesignWare I2C Controller
In reply to [email protected]From: Chris Rauer <[email protected]>
Add a model for the Synopsys DesignWare Advanced I2C/SMBus Controller with sufficient functionality to be used by the Linux Designware I2C platform driver.
This IP is used in the Tenstorrent Atlantis RISC-V SoC and will be added to the QEMU tt-atlantis machine.
[npiggin: changelog, code cleanups and fixes as-per below link]
Message-ID: <[email protected]>
--- MAINTAINERS | 8 + include/hw/i2c/designware_i2c.h | 56 +++ hw/i2c/designware_i2c.c | 745 ++++++++++++++++++++++++++++++++ hw/i2c/Kconfig | 5 + hw/i2c/meson.build | 1 + 5 files changed, 815 insertions(+) create mode 100644 include/hw/i2c/designware_i2c.h create mode 100644 hw/i2c/designware_i2c.c
MAINTAINERS +8 -0
@@ -2766,6 +2766,14 @@ S: Orphan F: hw/gpio/pcf8574.c F: include/hw/gpio/pcf8574.h +DesignWare I2C +M: Chris Rauer <[email protected]> +R: Alano Song <[email protected]> +R: Joel Stanley <[email protected]> +S: Maintained +F: hw/i2c/designware_i2c.c +F: include/hw/i2c/designware_i2c.h + Generic Loader M: Alistair Francis <[email protected]> S: Maintained
include/hw/i2c/designware_i2c.h new file +56 -0
56 lines not on this page · raw message
hw/i2c/designware_i2c.c new file +745 -0
745 lines not on this page · raw message
hw/i2c/Kconfig +5 -0
@@ -18,6 +18,11 @@ config ARM_SBCON_I2C bool select BITBANG_I2C +config DESIGNWARE_I2C + bool + select REGISTER + select I2C + config ACPI_SMBUS bool select SMBUS
hw/i2c/meson.build +1 -0
@@ -11,6 +11,7 @@ i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) i2c_ss.add(when: 'CONFIG_ALLWINNER_I2C', if_true: files('allwinner-i2c.c')) i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c')) i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c')) +i2c_ss.add(when: 'CONFIG_DESIGNWARE_I2C', if_true: files('designware_i2c.c')) i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c')) i2c_ss.add(when: 'CONFIG_ARM_SBCON_I2C', if_true: files('arm_sbcon_i2c.c')) i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c'))
Signature · 1 line
2.54.0
[PULL 26/39] target/riscv: Check PMP before updating PTE
In reply to [email protected]From: Inochi Amaoto <[email protected]>
According to the RISC-V spec, the PTE update is a supervisor write operations, and it should also follow the CPU PMP configuration like the PTE read.
Message-ID: <[email protected]>
--- target/riscv/cpu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/riscv/cpu_helper.c +8 -0
@@ -1655,10 +1655,18 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,/* Page table updates need to be atomic with MTTCG enabled */ if (updated_pte != pte && !is_debug) { +int pmp_prot, pmp_ret; +if (!adue) {return TRANSLATE_FAIL ; } + pmp_ret =get_physical_address_pmp (env, &pmp_prot, pte_addr, + sxlen_bytes,MMU_DATA_STORE ,PRV_S ); +if (pmp_ret !=TRANSLATE_SUCCESS ) { +return TRANSLATE_PMP_FAIL ; + } +/* * - if accessed or dirty bits need updating, and the PTE is * in RAM, then we do so atomically with a compare and swap.
Signature · 1 line
2.54.0
[PULL 39/39] hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
riscv-iommu spec: "If SADE is 1, the IOMMU updates A and D bits in first-stage PTEs atomically. If SADE is 0, the IOMMU causes a page-fault corresponding to the original access type if the A bit is 0 or if the memory access is a store and the D bit is 0.".
Note that SADE=0 and A=0 will always cause a fault regardless of the original access type. Right now we're faulting in this case just for reads.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3551
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +1 -1
@@ -480,7 +480,7 @@ static int riscv_iommu_spa_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx,break ;/* Read access check failed */ }else if ((iotlb->perm &IOMMU_WO ) && !(pte &PTE_W )) {break ;/* Write access check failed */ - }else if ((iotlb->perm &IOMMU_RO ) && !ade && !(pte &PTE_A )) { + }else if (!ade && !(pte &PTE_A )) {break ;/* Access bit not set */ }else if ((iotlb->perm &IOMMU_WO ) && !ade && !(pte &PTE_D )) {break ;/* Dirty bit not set */
Signature · 1 line
2.54.0
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/11.1 for any user-visible changes.
On 01.07.2026 13:17, [email protected] wrote:
...
Quoted 76 lines
RISC-V PR for 11.1
* Fix IMSIC CSR write and add tests
* Parametrise debug trigger number
* Add 'svbare' satp-mode
* Fix RINTC PLIC context ID for KVM
* Avoid abort when reading vtype beforeenv->xlis set
* Skip reset for KVM irqchip
* Skip FP/Vector sync onKVM_PUT_RUNTIME_STATE
* More FDT cleanups (PLIC)
* Make FCTL.BE in IOMMU read only 0
* Check DC.TC reserved bits in IOMMU
* Apply UXL WARL handling to vsstatus
* Setcmd_illIOFENCE.C if rsvp bits are set in IOMMU
* SetRISCV_IOMMU_FQ_HDR_PVappropriately
* Fix MSI MRIF IOMMU interrupt-pending offset
* Report QEMU CPU archid as 42
* Check PMP before updating PTE
* Add the Tenstorrent Atlantis machine----------------------------------------------------------------
Alistair Francis (1):
hw/riscv/atlantis: Ensure OpenSBI has a non-zeronext_addrCharlie Jenkins (1):
target/riscv: Report QEMU CPU archid as 42Chris Rauer (1):
hw/i2c: Add DesignWare I2C ControllerDaniel Henrique Barboza (16):
target/riscv/cpu: add CPU unrealize callback target/riscv: dynamic alloc of debug trigger arrays target/riscv: add 'num-triggers' debug propertytarget/riscv/cpu.c: add 'svbare' satp-modehw/riscv/sifive_u.c: remove unneededqemu_fdt_get_phandle()callhw/riscv/sifive_u.c: useintc_phandlein plic creation hw/riscv/sifive_u: add #address-cells in PLIC FDThw/riscv/virt.c: change 'plic' nodename to 'interrupt-controller' hw/riscv: addcreate_fdt_plic()helper hw/riscv/riscv-iommu: renameregs_rwto regshw/riscv/riscv-iommu.c: make FCTL.BE read only 0 hw/riscv/riscv-iommu: check DC.TC reserved bits hw/riscv/riscv-iommu: setcmd_illIOFENCE.C rsvp bits are sethw/riscv/riscv-iommu.c: setRISCV_IOMMU_FQ_HDR_PVappropriatelyhw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offsethw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0Inochi Amaoto (1):
target/riscv: Check PMP before updating PTEJoel Stanley (9):
target/riscv: Avoid NULL deref in IMSIC CSR write tests/functional/riscv64: Use newer kernel for tuxrun boot tests/functional/riscv64: Add virt machine AIA boot test hw/riscv/virt: Move AIA initialisation to helper file hw/riscv/aia: Provide number of irq sources hw/riscv/aia: Configure stride for the M-mode IMSIC hw/riscv: Add Tenstorrent Atlantis machine hw/riscv/atlantis: Integrate i2c controllers hw/riscv/atlantis: Add some i2c peripheralsMeng Zhuo (1):
target/riscv/kvm: skip FP/Vector sync onKVM_PUT_RUNTIME_STATENicholas Piggin (4):
hw/riscv/boot: Describe discontiguous memory inboot_infohw/riscv/boot: Account for discontiguous memory when loading firmware target/riscv: tt-ascalon: Enable Zkr extension tests/functional/riscv64: Add tt-atlantis testsQingwei Hu (3):
hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM hw/intc:riscv_aplic: Skip reset for KVM irqchip hw/intc:riscv_imsic: Skip reset for KVM irqchip
Quoted 5 lines
SeungJu Cheon (1):
target/riscv: Apply UXL WARL handling to vsstatusZhengXiang Qin (1):
target/riscv: avoid abort when reading vtype before env->xl is set
Hi!
Is there anything here worth picking up for the stable series (besides "target/riscv: Check PMP before updating PTE")?
For example,
46d96da130 target/riscv: avoid abort when reading vtype before env->xl
is set
5a3fd18f4f hw/riscv/riscv-iommu.c: make FCTL.BE read only 0 13c2fc34f1 hw/riscv/riscv-iommu: check DC.TC reserved bits 6ed77682d5 hw/riscv/riscv-iommu: set cmd_ill IOFENCE.C rsvp bits are set 887d2d75b1 hw/riscv/riscv-iommu.c: set RISCV_IOMMU_FQ_HDR_PV appropriately 3cee183ff9 hw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offset 64ce9ac187 hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0
resolves various bugs from the qemu issue/work-items tracker.
Thanks,
/mjt
Hi Michael,
Quoted 100 lines · Michael Tokarev
On 01.07.2026 13:17, [email protected] wrote:
...Quoted 76 lines
RISC-V PR for 11.1
* Fix IMSIC CSR write and add tests
* Parametrise debug trigger number
* Add 'svbare' satp-mode
* Fix RINTC PLIC context ID for KVM
* Avoid abort when reading vtype beforeenv->xlis set
* Skip reset for KVM irqchip
* Skip FP/Vector sync onKVM_PUT_RUNTIME_STATE
* More FDT cleanups (PLIC)
* Make FCTL.BE in IOMMU read only 0
* Check DC.TC reserved bits in IOMMU
* Apply UXL WARL handling to vsstatus
* Setcmd_illIOFENCE.C if rsvp bits are set in IOMMU
* SetRISCV_IOMMU_FQ_HDR_PVappropriately
* Fix MSI MRIF IOMMU interrupt-pending offset
* Report QEMU CPU archid as 42
* Check PMP before updating PTE
* Add the Tenstorrent Atlantis machine----------------------------------------------------------------
Alistair Francis (1):
hw/riscv/atlantis: Ensure OpenSBI has a non-zeronext_addrCharlie Jenkins (1):
target/riscv: Report QEMU CPU archid as 42Chris Rauer (1):
hw/i2c: Add DesignWare I2C ControllerDaniel Henrique Barboza (16):
target/riscv/cpu: add CPU unrealize callback target/riscv: dynamic alloc of debug trigger arrays target/riscv: add 'num-triggers' debug propertytarget/riscv/cpu.c: add 'svbare' satp-modehw/riscv/sifive_u.c: remove unneededqemu_fdt_get_phandle()callhw/riscv/sifive_u.c: useintc_phandlein plic creation hw/riscv/sifive_u: add #address-cells in PLIC FDThw/riscv/virt.c: change 'plic' nodename to 'interrupt-controller' hw/riscv: addcreate_fdt_plic()helper hw/riscv/riscv-iommu: renameregs_rwto regshw/riscv/riscv-iommu.c: make FCTL.BE read only 0 hw/riscv/riscv-iommu: check DC.TC reserved bits hw/riscv/riscv-iommu: setcmd_illIOFENCE.C rsvp bits are sethw/riscv/riscv-iommu.c: setRISCV_IOMMU_FQ_HDR_PVappropriatelyhw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offsethw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0Inochi Amaoto (1):
target/riscv: Check PMP before updating PTEJoel Stanley (9):
target/riscv: Avoid NULL deref in IMSIC CSR write tests/functional/riscv64: Use newer kernel for tuxrun boot tests/functional/riscv64: Add virt machine AIA boot test hw/riscv/virt: Move AIA initialisation to helper file hw/riscv/aia: Provide number of irq sources hw/riscv/aia: Configure stride for the M-mode IMSIC hw/riscv: Add Tenstorrent Atlantis machine hw/riscv/atlantis: Integrate i2c controllers hw/riscv/atlantis: Add some i2c peripheralsMeng Zhuo (1):
target/riscv/kvm: skip FP/Vector sync onKVM_PUT_RUNTIME_STATENicholas Piggin (4):
hw/riscv/boot: Describe discontiguous memory inboot_infohw/riscv/boot: Account for discontiguous memory when loading firmware target/riscv: tt-ascalon: Enable Zkr extension tests/functional/riscv64: Add tt-atlantis testsQingwei Hu (3):
hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM hw/intc:riscv_aplic: Skip reset for KVM irqchip hw/intc:riscv_imsic: Skip reset for KVM irqchipQuoted 5 lines
SeungJu Cheon (1):
target/riscv: Apply UXL WARL handling to vsstatusZhengXiang Qin (1):
target/riscv: avoid abort when reading vtype beforeenv->xlis setHi!
Is there anything here worth picking up for the stable series (besides "target/riscv: Check PMP before updating PTE")?
For example,
46d96da130 target/riscv: avoid abort when reading vtype before
env->xlis set5a3fd18f4fhw/riscv/riscv-iommu.c: make FCTL.BE read only 013c2fc34f1hw/riscv/riscv-iommu: check DC.TC reserved bits6ed77682d5hw/riscv/riscv-iommu: setcmd_illIOFENCE.C rsvp bits are set887d2d75b1hw/riscv/riscv-iommu.c: setRISCV_IOMMU_FQ_HDR_PVappropriately3cee183ff9hw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offset64ce9ac187hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0
Quoted 1 line
resolves various bugs from the qemu issue/work-items tracker.
All riscv-iommu stuff is worth getting. They are all fixes for code that is around since QEMU 9.x or something.
In fact there's more to come in future PRs (I'm actively hunting riscv-iommu stuff in gitlab) so same thing applies for those future cases too.
Cheers,
Daniel
Quoted 4 lines
Thanks,
/mjt
Quoted 102 lines · Michael Tokarev
On 01.07.2026 13:17, [email protected] wrote:
...Quoted 76 lines
RISC-V PR for 11.1
* Fix IMSIC CSR write and add tests
* Parametrise debug trigger number
* Add 'svbare' satp-mode
* Fix RINTC PLIC context ID for KVM
* Avoid abort when reading vtype beforeenv->xlis set
* Skip reset for KVM irqchip
* Skip FP/Vector sync onKVM_PUT_RUNTIME_STATE
* More FDT cleanups (PLIC)
* Make FCTL.BE in IOMMU read only 0
* Check DC.TC reserved bits in IOMMU
* Apply UXL WARL handling to vsstatus
* Setcmd_illIOFENCE.C if rsvp bits are set in IOMMU
* SetRISCV_IOMMU_FQ_HDR_PVappropriately
* Fix MSI MRIF IOMMU interrupt-pending offset
* Report QEMU CPU archid as 42
* Check PMP before updating PTE
* Add the Tenstorrent Atlantis machine----------------------------------------------------------------
Alistair Francis (1):
hw/riscv/atlantis: Ensure OpenSBI has a non-zeronext_addrCharlie Jenkins (1):
target/riscv: Report QEMU CPU archid as 42Chris Rauer (1):
hw/i2c: Add DesignWare I2C ControllerDaniel Henrique Barboza (16):
target/riscv/cpu: add CPU unrealize callback target/riscv: dynamic alloc of debug trigger arrays target/riscv: add 'num-triggers' debug propertytarget/riscv/cpu.c: add 'svbare' satp-modehw/riscv/sifive_u.c: remove unneededqemu_fdt_get_phandle()callhw/riscv/sifive_u.c: useintc_phandlein plic creation hw/riscv/sifive_u: add #address-cells in PLIC FDThw/riscv/virt.c: change 'plic' nodename to 'interrupt-controller' hw/riscv: addcreate_fdt_plic()helper hw/riscv/riscv-iommu: renameregs_rwto regshw/riscv/riscv-iommu.c: make FCTL.BE read only 0 hw/riscv/riscv-iommu: check DC.TC reserved bits hw/riscv/riscv-iommu: setcmd_illIOFENCE.C rsvp bits are sethw/riscv/riscv-iommu.c: setRISCV_IOMMU_FQ_HDR_PVappropriatelyhw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offsethw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0Inochi Amaoto (1):
target/riscv: Check PMP before updating PTEJoel Stanley (9):
target/riscv: Avoid NULL deref in IMSIC CSR write tests/functional/riscv64: Use newer kernel for tuxrun boot tests/functional/riscv64: Add virt machine AIA boot test hw/riscv/virt: Move AIA initialisation to helper file hw/riscv/aia: Provide number of irq sources hw/riscv/aia: Configure stride for the M-mode IMSIC hw/riscv: Add Tenstorrent Atlantis machine hw/riscv/atlantis: Integrate i2c controllers hw/riscv/atlantis: Add some i2c peripheralsMeng Zhuo (1):
target/riscv/kvm: skip FP/Vector sync onKVM_PUT_RUNTIME_STATENicholas Piggin (4):
hw/riscv/boot: Describe discontiguous memory inboot_infohw/riscv/boot: Account for discontiguous memory when loading firmware target/riscv: tt-ascalon: Enable Zkr extension tests/functional/riscv64: Add tt-atlantis testsQingwei Hu (3):
hw/riscv/virt-acpi-build: Fix RINTC PLIC context ID for KVM hw/intc:riscv_aplic: Skip reset for KVM irqchip hw/intc:riscv_imsic: Skip reset for KVM irqchipQuoted 5 lines
SeungJu Cheon (1):
target/riscv: Apply UXL WARL handling to vsstatusZhengXiang Qin (1):
target/riscv: avoid abort when reading vtype before env->xl is setHi!
Is there anything here worth picking up for the stable series (besides "target/riscv: Check PMP before updating PTE")?
For example,
46d96da130target/riscv: avoid abort when reading vtype beforeenv->xl
is set
5a3fd18f4fhw/riscv/riscv-iommu.c: make FCTL.BE read only 013c2fc34f1hw/riscv/riscv-iommu: check DC.TC reserved bits6ed77682d5hw/riscv/riscv-iommu: setcmd_illIOFENCE.C rsvp bits are set887d2d75b1hw/riscv/riscv-iommu.c: setRISCV_IOMMU_FQ_HDR_PVappropriately3cee183ff9hw/riscv/riscv-iommu.c: fix MSI MRIF interrupt-pending offset64ce9ac187hw/riscv/riscv-iommu.c: always fault with SADE=0 and A=0
Quoted 1 line
resolves various bugs from the qemu issue/work-items tracker.
Everything with a Fixes tag should be backported to releases that have the relevant commits
Alistair
Quoted 4 lines
Thanks,
/mjt