riscv-to-apply queue
Subsystems (3)
From: Alistair Francis <[email protected]>
The following changes since commit c77283dd5d79149f4e7e9edd00f65416c648ee59:
Merge tag 'pull-request-2025-07-02' of https://gitlab.com/thuth/qemu into staging (2025-07-03 06:01:41 -0400)
are available in the Git repository at:
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20250704
for you to fetch changes up to dc8bffc4eb0a93d3266cea1b17f8848dea5b915c:
target: riscv: Add Svrsw60t59b extension support (2025-07-04 21:09:49 +1000)
----------------------------------------------------------------
Second RISC-V PR for 10.1
* sstc extension fixes
* Fix zama16b order in isa_edata_arr
* Profile handling fixes
* Extend PMP region up to 64
* Remove capital 'Z' CPU properties
* Add missing named features
* Support atomic instruction fetch (Ziccif)
* Add max_satp_mode from host cpu
* Extend and configure PMP region count
* Fix PPN field of Translation-reponse register
* Use qemu_chr_fe_write_all() in DBCN_CONSOLE_WRITE_BYTE
* Fix fcvt.s.bf16 NaN box checking
* Avoid infinite delay of async xmit function
* Device tree reg cleanups
* Add Kunminghu CPU and platform
* Fix missing exit TB flow for ldff_trans
* Fix migration failure when aia is configured as aplic-imsic
* Fix MEPC/SEPC bit masking for IALIGN
* Add a property to set vill bit on reserved usage of vsetvli instruction
* Add Svrsw60t59b extension support
----------------------------------------------------------------
Alexandre Ghiti (1):
target: riscv: Add Svrsw60t59b extension support
Anton Blanchard (1):
target/riscv: Fix fcvt.s.bf16 NaN box checking
Charalampos Mitrodimas (2):
target/riscv: Fix MEPC/SEPC bit masking for IALIGN tests/tcg/riscv64: Add test for MEPC bit masking
Daniel Henrique Barboza (9):
target/riscv/cpu.c: fix zama16b order in isa_edata_arr[] target/riscv/tcg: restrict satp_mode changes in cpu_set_profile target/riscv/tcg: decouple profile enablement from user prop target/riscv: add profile->present flag
target/riscv: remove capital 'Z' CPU properties target/riscv/cpu.c: add 'sdtrig' in riscv,isa target/riscv/cpu.c: add 'ssstrict' to riscv, isa target/riscv/cpu.c: do better with 'named features' doc target/riscv: use qemu_chr_fe_write_all() in DBCN_CONSOLE_WRITE_BYTE
Florian Lugou (1):
hw/char: sifive_uart: Avoid infinite delay of async xmit function
Huang Borong (2):
target/riscv: Add BOSC's Xiangshan Kunminghu CPU
hw/riscv: Initial support for BOSC's Xiangshan Kunminghu FPGA prototype
Jay Chang (2):
target/riscv: Extend PMP region up to 64 target/riscv: Make PMP region count configurable
Jim Shu (5):
target/riscv: Add the checking into stimecmp write function. hw/intc: riscv_aclint: Fix mtime write for sstc extension target/riscv: Fix VSTIP bit in sstc extension. target/riscv: Enable/Disable S/VS-mode Timer when STCE bit is changed target/riscv: support atomic instruction fetch (Ziccif)
Joel Stanley (12):
hw/riscv/virt: Fix clint base address type hw/riscv/virt: Use setprop_sized_cells for clint hw/riscv/virt: Use setprop_sized_cells for memory hw/riscv/virt: Use setprop_sized_cells for aplic hw/riscv/virt: Use setprop_sized_cells for aclint hw/riscv/virt: Use setprop_sized_cells for plic hw/riscv/virt: Use setprop_sized_cells for virtio hw/riscv/virt: Use setprop_sized_cells for reset hw/riscv/virt: Use setprop_sized_cells for uart hw/riscv/virt: Use setprop_sized_cells for rtc hw/riscv/virt: Use setprop_sized_cells for iommu hw/riscv/virt: Use setprop_sized_cells for pcie
Max Chou (1):
target/riscv: rvv: Fix missing exit TB flow for ldff_trans
Meng Zhuo (1):
target/riscv/kvm: add max_satp_mode from host cpu
Nutty Liu (1):
hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register
Vasilis Liaskovitis (1):
target/riscv: Add a property to set vill bit on reserved usage of vsetvli instruction
[email protected] (1):
migration: Fix migration failure when aia is configured as aplic-imsic
MAINTAINERS | 7 + docs/system/riscv/xiangshan-kunminghu.rst | 39 +++++ docs/system/target-riscv.rst | 1 + configs/devices/riscv64-softmmu/default.mak | 1 + hw/riscv/riscv-iommu-bits.h | 1 + include/hw/riscv/xiangshan_kmh.h | 68 +++++++++ target/riscv/cpu-qom.h | 1 + target/riscv/cpu.h | 19 ++- target/riscv/cpu_bits.h | 63 +++++++- target/riscv/helper.h | 2 +- target/riscv/internals.h | 27 ++++ target/riscv/time_helper.h | 1 + target/riscv/cpu_cfg_fields.h.inc | 3 + hw/char/sifive_uart.c | 6 +- hw/intc/riscv_aclint.c | 5 + hw/intc/riscv_aplic.c | 12 +- hw/intc/riscv_imsic.c | 10 +- hw/riscv/riscv-iommu.c | 9 +- hw/riscv/virt.c | 66 ++++----- hw/riscv/xiangshan_kmh.c | 220 ++++++++++++++++++++++++++++ target/riscv/cpu.c | 144 +++++++++++++++--- target/riscv/cpu_helper.c | 3 +- target/riscv/csr.c | 192 +++++++++++++++++++++++- target/riscv/fpu_helper.c | 2 +- target/riscv/kvm/kvm-cpu.c | 18 ++- target/riscv/machine.c | 3 +- target/riscv/op_helper.c | 4 +- target/riscv/pmp.c | 28 ++-- target/riscv/riscv-qmp-cmds.c | 2 +- target/riscv/tcg/tcg-cpu.c | 186 +++++++++++------------ target/riscv/time_helper.c | 65 +++++++- target/riscv/translate.c | 46 ++++-- target/riscv/vector_helper.c | 12 +- target/riscv/insn_trans/trans_rvv.c.inc | 10 +- hw/riscv/Kconfig | 9 ++ hw/riscv/meson.build | 1 + tests/data/acpi/riscv64/virt/RHCT | Bin 400 -> 416 bytes tests/tcg/riscv64/Makefile.softmmu-target | 4 + tests/tcg/riscv64/test-mepc-masking.S | 73 +++++++++ 39 files changed, 1151 insertions(+), 212 deletions(-) create mode 100644 docs/system/riscv/xiangshan-kunminghu.rst create mode 100644 include/hw/riscv/xiangshan_kmh.h create mode 100644 hw/riscv/xiangshan_kmh.c create mode 100644 tests/tcg/riscv64/test-mepc-masking.S
[PULL 05/40] target/riscv/cpu.c: fix zama16b order in isa_edata_arr[]
From: Daniel Henrique Barboza <[email protected]>
Put it after zalrsc and before zawrs.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -127,8 +127,8 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zaamo,PRIV_VERSION_1_12_0 , ext_zaamo),ISA_EXT_DATA_ENTRY (zabha,PRIV_VERSION_1_13_0 , ext_zabha),ISA_EXT_DATA_ENTRY (zacas,PRIV_VERSION_1_12_0 , ext_zacas), -ISA_EXT_DATA_ENTRY (zama16b,PRIV_VERSION_1_13_0 , ext_zama16b),ISA_EXT_DATA_ENTRY (zalrsc,PRIV_VERSION_1_12_0 , ext_zalrsc), +ISA_EXT_DATA_ENTRY (zama16b,PRIV_VERSION_1_13_0 , ext_zama16b),ISA_EXT_DATA_ENTRY (zawrs,PRIV_VERSION_1_12_0 , ext_zawrs),ISA_EXT_DATA_ENTRY (zfa,PRIV_VERSION_1_12_0 , ext_zfa), ISA_EXT_DATA_ENTRY(zfbfmin, PRIV_VERSION_1_12_0, ext_zfbfmin),
Signature · 1 line
2.50.0
[PULL 03/40] target/riscv: Fix VSTIP bit in sstc extension.
In reply to [email protected]From: Jim Shu <[email protected]>
VSTIP is only writable when both [mh]envcfg.STCE is enabled, or it will revert it's defined behavior as if sstc extension is not implemented.
Message-ID: <[email protected]>
--- target/riscv/csr.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
target/riscv/csr.c +8 -1
@@ -3651,7 +3651,14 @@ static RISCVException rmw_mip64(CPURISCVState *env, int csrno,if (riscv_cpu_cfg (env)->ext_sstc && (env->priv ==PRV_M ) &&get_field (env->menvcfg,MENVCFG_STCE )) {/* sstc extension forbids STIP & VSTIP to be writeable in mip */ - mask = mask & ~(MIP_STIP |MIP_VSTIP ); + +/* STIP is not writable when menvcfg.STCE is enabled. */ + mask = mask & ~MIP_STIP ; + +/* VSTIP is not writable when both [mh]envcfg.STCE are enabled. */ +if (get_field (env->henvcfg,HENVCFG_STCE )) { + mask = mask & ~MIP_VSTIP ; + } }if (mask) {
Signature · 1 line
2.50.0
[PULL 04/40] target/riscv: Enable/Disable S/VS-mode Timer when STCE bit is changed
In reply to [email protected]From: Jim Shu <[email protected]>
Updating STCE will enable/disable SSTC in S-mode or/and VS-mode, so we also need to update S/VS-mode Timer and S/VSTIP bits in $mip CSR.
Message-ID: <[email protected]>
--- target/riscv/time_helper.h | 1 + target/riscv/csr.c | 46 ++++++++++++++++++++++++++++++++++++++ target/riscv/time_helper.c | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+)
target/riscv/time_helper.h +1 -0
@@ -25,6 +25,7 @@void riscv_timer_write_timecmp (CPURISCVState *env,QEMUTimer *timer,uint64_t timecmp,uint64_t delta,uint32_t timer_irq); +void riscv_timer_stce_changed (CPURISCVState *env,bool is_m_mode,bool enable);void riscv_timer_init (RISCVCPU *cpu);#endif
target/riscv/csr.c +46 -0
111 lines not on this page · raw message
target/riscv/time_helper.c +46 -0
52 lines not on this page · raw message
Signature · 1 line
2.50.0
[PULL 02/40] hw/intc: riscv_aclint: Fix mtime write for sstc extension
In reply to [email protected]From: Jim Shu <[email protected]>
When changing the mtime value, the period of [s|vs]timecmp timers should also be updated, similar to the period of mtimecmp timer.
The period of the stimecmp timer is the time until the next S-mode timer IRQ. The value is calculated as "stimecmp - time". [1] It is equal to "stimecmp - mtime" since the time CSR is a read-only shadow of the memory-mapped mtime register.
Thus, changing mtime value will update the period of stimecmp timer.
Similarly, the period of vstimecmp timer is calculated as "vstimecmp - (mtime + htimedelta)" [2], so changing mtime value will update the period of vstimecmp timer.
[1] RISC-V Priv spec ch 9.1.1. Supervisor Timer (stimecmp) Register A supervisor timer interrupt becomes pending, as reflected in the STIP bit in the mip and sip registers whenever time contains a value greater than or equal to stimecmp.
[2] RISC-V Priv spec ch19.2.1. Virtual Supervisor Timer (vstimecmp) Register A virtual supervisor timer interrupt becomes pending, as reflected in the VSTIP bit in the hip register, whenever (time + htimedelta), truncated to 64 bits, contains a value greater than or equal to vstimecmp
Message-ID: <[email protected]>
--- hw/intc/riscv_aclint.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/intc/riscv_aclint.c +5 -0
@@ -28,6 +28,7 @@#include "qemu/module.h" #include "hw/sysbus.h" #include "target/riscv/cpu.h" +#include "target/riscv/time_helper.h" #include "hw/qdev-properties.h" #include "hw/intc/riscv_aclint.h" #include "qemu/timer.h"
@@ -240,6 +241,10 @@ static void riscv_aclint_mtimer_write(void *opaque, hwaddr addr,riscv_aclint_mtimer_write_timecmp (mtimer,RISCV_CPU (cpu), mtimer->hartid_base + i, mtimer->timecmp[i]); +riscv_timer_write_timecmp (env, env->stimer, env->stimecmp,0 ,MIP_STIP ); +riscv_timer_write_timecmp (env, env->vstimer, env->vstimecmp, + env->htimedelta,MIP_VSTIP ); + }return ; }
Signature · 1 line
2.50.0
[PULL 11/40] target/riscv/cpu.c: add 'sdtrig' in riscv,isa
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We have support for sdtrig for awhile but we are not advertising it. It is enabled by default via the 'debug' flag. Use the same flag to also advertise sdtrig.
Add an exception in disable_priv_spec_isa_exts() to avoid spamming warnings for 'sdtrig' for vendor CPUs like sifive_u.
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 1 + target/riscv/tcg/tcg-cpu.c | 9 +++++++++ tests/data/acpi/riscv64/virt/RHCT | Bin 400 -> 406 bytes 3 files changed, 10 insertions(+)
target/riscv/cpu.c +1 -0
@@ -189,6 +189,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (zvkt,PRIV_VERSION_1_12_0 , ext_zvkt),ISA_EXT_DATA_ENTRY (zhinx,PRIV_VERSION_1_12_0 , ext_zhinx),ISA_EXT_DATA_ENTRY (zhinxmin,PRIV_VERSION_1_12_0 , ext_zhinxmin), +ISA_EXT_DATA_ENTRY (sdtrig,PRIV_VERSION_1_12_0 , debug),ISA_EXT_DATA_ENTRY (shcounterenw,PRIV_VERSION_1_12_0 , has_priv_1_12),ISA_EXT_DATA_ENTRY (sha,PRIV_VERSION_1_12_0 , ext_sha), ISA_EXT_DATA_ENTRY(shgatpa, PRIV_VERSION_1_12_0, has_priv_1_12),
target/riscv/tcg/tcg-cpu.c +9 -0
@@ -451,6 +451,15 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)continue ; } +/* +* cpu.debug = true is marked as 'sdtrig', priv spec 1.12. +* Skip this warning since existing CPUs with older priv +* spec and debug = true will be impacted. +*/ +if (!strcmp (edata->name,"sdtrig" )) { +continue ; + } +isa_ext_update_enabled (cpu, edata->ext_enable_offset, false);/*
tests/data/acpi/riscv64/virt/RHCT binary +0 -0
Signature · 1 line
2.50.0
[PULL 23/40] hw/riscv/virt: Use setprop_sized_cells for memory
In reply to [email protected]From: Joel Stanley <[email protected]>
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/riscv/virt.c +1 -2
@@ -311,8 +311,7 @@ static void create_fdt_socket_memory(RISCVVirtState *s, int socket) size =riscv_socket_mem_size (ms, socket); mem_name =g_strdup_printf ("/memory@%" HWADDR_PRIx, addr);qemu_fdt_add_subnode (ms->fdt, mem_name); -qemu_fdt_setprop_cells (ms->fdt, mem_name,"reg" , - addr >>32 , addr, size >>32 , size); +qemu_fdt_setprop_sized_cells (ms->fdt, mem_name,"reg" ,2 , addr,2 , size);qemu_fdt_setprop_string (ms->fdt, mem_name,"device_type" ,"memory" );riscv_socket_fdt_write_id (ms, mem_name, socket); }
Signature · 1 line
2.50.0
[PULL 27/40] hw/riscv/virt: Use setprop_sized_cells for virtio
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
hw/riscv/virt.c +1 -3
@@ -856,9 +856,7 @@ static void create_fdt_virtio(RISCVVirtState *s, uint32_t irq_virtio_phandle)qemu_fdt_add_subnode (ms->fdt, name);qemu_fdt_setprop_string (ms->fdt, name,"compatible" ,"virtio,mmio" ); -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , addr, -0x0 , size); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" ,2 , addr,2 , size);qemu_fdt_setprop_cell (ms->fdt, name,"interrupt-parent" , irq_virtio_phandle);if (s->aia_type ==VIRT_AIA_TYPE_NONE ) {
Signature · 1 line
2.50.0
[PULL 10/40] target/riscv: remove capital 'Z' CPU properties
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
These properties were deprecated in QEMU 8.2, commit 8043effd9b.
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 1 - target/riscv/cpu.c | 17 ----------------- target/riscv/tcg/tcg-cpu.c | 31 +------------------------------ 3 files changed, 1 insertion(+), 48 deletions(-)
target/riscv/cpu.h +0 -1
@@ -951,7 +951,6 @@ extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[]; -extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[]; typedef struct isa_ext_data { const char *name;
target/riscv/cpu.c +0 -17
@@ -1387,23 +1387,6 @@ const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = { { }, }; -/* Deprecated entries marked for future removal */ -const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = { -MULTI_EXT_CFG_BOOL ("Zifencei" , ext_zifencei, true), -MULTI_EXT_CFG_BOOL ("Zicsr" , ext_zicsr, true), -MULTI_EXT_CFG_BOOL ("Zihintntl" , ext_zihintntl, true), -MULTI_EXT_CFG_BOOL ("Zihintpause" , ext_zihintpause, true), -MULTI_EXT_CFG_BOOL ("Zawrs" , ext_zawrs, true), -MULTI_EXT_CFG_BOOL ("Zfa" , ext_zfa, true), -MULTI_EXT_CFG_BOOL ("Zfh" , ext_zfh, false), -MULTI_EXT_CFG_BOOL ("Zfhmin" , ext_zfhmin, false), -MULTI_EXT_CFG_BOOL ("Zve32f" , ext_zve32f, false), -MULTI_EXT_CFG_BOOL ("Zve64f" , ext_zve64f, false), -MULTI_EXT_CFG_BOOL ("Zve64d" , ext_zve64d, false), - - { }, -}; -static void cpu_set_prop_err (RISCVCPU *cpu,const char *propname,Error **errp) {
target/riscv/tcg/tcg-cpu.c +1 -30
@@ -1442,25 +1442,6 @@ static void riscv_cpu_add_profiles(Object *cpu_obj) } } -static bool cpu_ext_is_deprecated (const char *ext_name) -{ -return isupper (ext_name[0 ]); -} - -/* -* String will be allocated in the heap. Caller is responsible -* for freeing it. -*/ -static char *cpu_ext_to_lower (const char *ext_name) -{ -char *ret =g_malloc0 (strlen (ext_name) +1 ); - -strcpy (ret, ext_name); - ret[0 ] =tolower (ret[0 ]); - -return ret; -} -static void cpu_set_multi_ext_cfg (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) {
@@ -1473,13 +1454,6 @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,return ; } -if (cpu_ext_is_deprecated (multi_ext_cfg->name)) { - g_autofree char *lower = cpu_ext_to_lower(multi_ext_cfg->name); - -warn_report ("CPU property '%s' is deprecated. Please use '%s' instead" , - multi_ext_cfg->name, lower); - } -cpu_cfg_ext_add_user_opt (multi_ext_cfg->offset, value); prev_val =isa_ext_is_enabled (cpu, multi_ext_cfg->offset);
@@ -1515,14 +1489,13 @@ static void cpu_add_multi_ext_prop(Object *cpu_obj, const RISCVCPUMultiExtConfig *multi_cfg) {bool generic_cpu =riscv_cpu_is_generic (cpu_obj); -bool deprecated_ext =cpu_ext_is_deprecated (multi_cfg->name);object_property_add (cpu_obj, multi_cfg->name,"bool" , cpu_get_multi_ext_cfg, cpu_set_multi_ext_cfg,NULL , (void *)multi_cfg); -if (!generic_cpu || deprecated_ext) { +if (!generic_cpu) {return ; }
@@ -1565,8 +1538,6 @@ static void riscv_cpu_add_user_properties(Object *obj)riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_vendor_exts);riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_experimental_exts); -riscv_cpu_add_multiext_prop_array (obj, riscv_cpu_deprecated_exts); -riscv_cpu_add_profiles (obj); }
Signature · 1 line
2.50.0
[PULL 17/40] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register
In reply to [email protected]From: Nutty Liu <[email protected]>
The original implementation incorrectly performed a bitwise AND operation between the PPN of iova and PPN Mask, leading to an incorrect PPN field in Translation-reponse register.
The PPN of iova should be set entirely in the PPN field of Translation-reponse register.
Also remove the code that was used to clear S field since this field is already zero.
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
hw/riscv/riscv-iommu.c +1 -5
@@ -1935,11 +1935,7 @@ static void riscv_iommu_process_dbg(RISCVIOMMUState *s) iova =RISCV_IOMMU_TR_RESPONSE_FAULT | (((uint64_t ) fault) <<10 ); }else { iova = iotlb.translated_addr & ~iotlb.addr_mask; - iova >>=TARGET_PAGE_BITS ; - iova &=RISCV_IOMMU_TR_RESPONSE_PPN ; - -/* We do not support superpages (> 4kbs) for now */ - iova &= ~RISCV_IOMMU_TR_RESPONSE_S ; + iova =set_field (0 ,RISCV_IOMMU_TR_RESPONSE_PPN ,PPN_DOWN (iova)); }riscv_iommu_reg_set64 (s,RISCV_IOMMU_REG_TR_RESPONSE , iova); }
Signature · 1 line
2.50.0
[PULL 26/40] hw/riscv/virt: Use setprop_sized_cells for plic
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/riscv/virt.c +2 -2
@@ -493,8 +493,8 @@ static void create_fdt_socket_plic(RISCVVirtState *s, s->soc[socket].num_harts * sizeof(uint32_t) * 4); } -qemu_fdt_setprop_cells (ms->fdt, plic_name,"reg" , -0x0 , plic_addr,0x0 , s->memmap[VIRT_PLIC ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, plic_name,"reg" , +2 , plic_addr,2 , s->memmap[VIRT_PLIC ].size);qemu_fdt_setprop_cell (ms->fdt, plic_name,"riscv,ndev" ,VIRT_IRQCHIP_NUM_SOURCES -1 );riscv_socket_fdt_write_id (ms, plic_name, socket);
Signature · 1 line
2.50.0
[PULL 15/40] target/riscv/kvm: add max_satp_mode from host cpu
In reply to [email protected]From: Meng Zhuo <[email protected]>
This patch adds max_satp_mode from host kvm cpu setting.
Tested on: Milkv Megrez (Eswin 7700x)
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2931
Message-ID: <[email protected]>
--- target/riscv/kvm/kvm-cpu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
target/riscv/kvm/kvm-cpu.c +15 -1
@@ -999,6 +999,19 @@ static void kvm_riscv_destroy_scratch_vcpu(KVMScratchCPU *scratch)close (scratch->kvmfd); } +static void kvm_riscv_init_max_satp_mode (RISCVCPU *cpu,KVMScratchCPU *kvmcpu) +{ +struct kvm_one_reg reg; +int ret; + + reg.id =RISCV_CONFIG_REG (satp_mode); + reg.addr = (uint64_t )&cpu->cfg.max_satp_mode; + ret =ioctl (kvmcpu->cpufd,KVM_GET_ONE_REG , ®); +if (ret !=0 ) { +error_report ("Unable to retrieve satp mode from host, error %d" , ret); + } +} +static void kvm_riscv_init_machine_ids (RISCVCPU *cpu,KVMScratchCPU *kvmcpu) {struct kvm_one_reg reg;
@@ -1302,6 +1315,7 @@ static void riscv_init_kvm_registers(Object *cpu_obj)kvm_riscv_init_machine_ids (cpu, &kvmcpu);kvm_riscv_init_misa_ext_mask (cpu, &kvmcpu);kvm_riscv_init_cfg (cpu, &kvmcpu); +kvm_riscv_init_max_satp_mode (cpu, &kvmcpu);kvm_riscv_destroy_scratch_vcpu (&kvmcpu); }
@@ -1985,7 +1999,7 @@ static bool kvm_cpu_realize(CPUState *cs, Error **errp) } } -return true; +return true; }void riscv_kvm_cpu_finalize_features (RISCVCPU *cpu,Error **errp)
Signature · 1 line
2.50.0
[PULL 36/40] migration: Fix migration failure when aia is configured as aplic-imsic
In reply to [email protected]From: "[email protected]" <[email protected]>
Address an error in migration when aia is configured as 'aplic-imsic' in riscv kvm vm by adding riscv_aplic_state_needed() and riscv_imsic_state_needed() to determine whether the corresponding sates are needed.
Previously, the fields in the vmsds of 'riscv_aplic' and 'riscv_imsic' can only be initialized under certain special conditions in commit 95a97b3fd2. However, the corresponding ses of these vmsds are inserted into the savevm_state.handlers unconditionally. This led to migration failure characterized by uninitialized fields when save vm state:
qemu-system-riscv64: ../migration/vmstate.c:433: vmstate_save_state_v:
Assertion 'first_elem || !n_elems || !size' failed.
Message-ID: <[email protected]>
--- hw/intc/riscv_aplic.c | 12 ++++++++++-- hw/intc/riscv_imsic.c | 10 ++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-)
hw/intc/riscv_aplic.c +10 -2
@@ -962,10 +962,18 @@ static const Property riscv_aplic_properties[] = { DEFINE_PROP_BOOL("mmode", RISCVAPLICState, mmode, 0), }; +static bool riscv_aplic_state_needed (void *opaque) +{ +RISCVAPLICState *aplic = opaque; + +return riscv_use_emulated_aplic (aplic->msimode); +} +static const VMStateDescription vmstate_riscv_aplic = { .name ="riscv_aplic" , - .version_id =2 , - .minimum_version_id =2 , + .version_id =3 , + .minimum_version_id =3 , + .needed = riscv_aplic_state_needed, .fields = (const VMStateField []) {VMSTATE_UINT32 (domaincfg, RISCVAPLICState),VMSTATE_UINT32 (mmsicfgaddr, RISCVAPLICState),
hw/intc/riscv_imsic.c +8 -2
@@ -398,10 +398,16 @@ static const Property riscv_imsic_properties[] = { DEFINE_PROP_UINT32("num-irqs", RISCVIMSICState, num_irqs, 0), }; +static bool riscv_imsic_state_needed (void *opaque) +{ +return !kvm_irqchip_in_kernel (); +} +static const VMStateDescription vmstate_riscv_imsic = { .name ="riscv_imsic" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , + .needed = riscv_imsic_state_needed, .fields = (const VMStateField []) { VMSTATE_VARRAY_UINT32(eidelivery, RISCVIMSICState, num_pages, 0,
Signature · 1 line
2.50.0
[PULL 08/40] target/riscv: add profile->present flag
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Björn reported in [1] a case where a rv64 CPU is going through the profile code path to enable satp mode. In this case,the amount of extensions on top of the rv64 CPU made it compliant with the RVA22S64 profile during the validation of CPU 0. When the subsequent CPUs were initialized the static profile object has the 'enable' flag set, enabling the profile code path for those CPUs.
This happens because we are initializing and realizing each CPU before going to the next, i.e. init and realize CPU0, then init and realize CPU1 and so on. If we change any persistent state during the validation of CPU N it will interfere with the init/realization of CPU N+1.
We're using the 'enabled' profile flag to do two distinct things: inform cpu_init() that we want profile extensions to be enabled, and telling QMP that a profile is currently enabled in the CPU. We want to be flexible enough to recognize profile support for all CPUs that has the extension prerequisites, but we do not want to force the profile code path if a profile wasn't set too.
Add a new 'present' flag for profiles that will coexist with the 'enabled' flag. Enabling a profile means "we want to switch on all its mandatory extensions". A profile is 'present' if we asserted during validation that the CPU has the needed prerequisites.
This means that the case reported by Björn now results in RVA22S64.enabled=false and RVA22S64.present=true. QMP will recognize it as a RVA22 compliant CPU and we won't force the CPU into the profile path.
[1] https://lore.kernel.org/qemu-riscv/[email protected]/
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 15 +++++++++++++++ target/riscv/riscv-qmp-cmds.c | 2 +- target/riscv/tcg/tcg-cpu.c | 11 +++-------- 3 files changed, 19 insertions(+), 9 deletions(-)
target/riscv/cpu.h +15 -0
@@ -82,7 +82,22 @@ typedef struct riscv_cpu_profile {struct riscv_cpu_profile *s_parent;const char *name;uint32_t misa_ext; +/* +* The profile is enabled/disabled via command line or +* via cpu_init(). Enabling a profile will add all its +* mandatory extensions in the CPU during init(). +*/ bool enabled; +/* +* The profile is present in the CPU, i.e. the current set of +* CPU extensions complies with it. A profile can be enabled +* and not present (e.g. the user disabled a mandatory extension) +* and the other way around (e.g. all mandatory extensions are +* present in a non-profile CPU). +* +* QMP uses this flag. +*/ +bool present;bool user_set;int priv_spec;int satp_mode;
target/riscv/riscv-qmp-cmds.c +1 -1
@@ -121,7 +121,7 @@ static void riscv_obj_add_profiles_qdict(Object *obj, QDict *qdict_out)for (int i =0 ; riscv_profiles[i] !=NULL ; i++) { profile = riscv_profiles[i]; - value =QOBJECT (qbool_from_bool (profile->enabled)); + value =QOBJECT (qbool_from_bool (profile->present));qdict_put_obj (qdict_out, profile->name, value); }
target/riscv/tcg/tcg-cpu.c +3 -8
@@ -867,16 +867,11 @@ static void riscv_cpu_check_parent_profile(RISCVCPU *cpu, RISCVCPUProfile *profile, RISCVCPUProfile *parent) { -const char *parent_name; -bool parent_enabled; - -if (!profile->enabled || !parent) { +if (!profile->present || !parent) {return ; } - parent_name = parent->name; - parent_enabled =object_property_get_bool (OBJECT (cpu), parent_name,NULL ); - profile->enabled = parent_enabled; + profile->present = parent->present; } static void riscv_cpu_validate_profile(RISCVCPU *cpu,
@@ -937,7 +932,7 @@ static void riscv_cpu_validate_profile(RISCVCPU *cpu, } } - profile->enabled = profile_impl; + profile->present = profile_impl;riscv_cpu_check_parent_profile (cpu, profile, profile->u_parent);riscv_cpu_check_parent_profile (cpu, profile, profile->s_parent);
Signature · 1 line
2.50.0
[PULL 31/40] hw/riscv/virt: Use setprop_sized_cells for iommu
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/riscv/virt.c +1 -2
@@ -1088,8 +1088,7 @@ static void create_fdt_iommu_sys(RISCVVirtState *s, uint32_t irq_chip,qemu_fdt_setprop_cell (fdt, iommu_node,"#iommu-cells" ,1 );qemu_fdt_setprop_cell (fdt, iommu_node,"phandle" , iommu_phandle); -qemu_fdt_setprop_cells (fdt, iommu_node,"reg" , - addr >>32 , addr, size >>32 , size); +qemu_fdt_setprop_sized_cells (fdt, iommu_node,"reg" ,2 , addr,2 , size);qemu_fdt_setprop_cell (fdt, iommu_node,"interrupt-parent" , irq_chip); qemu_fdt_setprop_cells(fdt, iommu_node, "interrupts",
Signature · 1 line
2.50.0
[PULL 28/40] hw/riscv/virt: Use setprop_sized_cells for reset
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/riscv/virt.c +3 -2
@@ -932,8 +932,9 @@ static void create_fdt_reset(RISCVVirtState *s, uint32_t *phandle)qemu_fdt_setprop_string_array (ms->fdt, name,"compatible" , (char **)&compat,ARRAY_SIZE (compat)); } -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , s->memmap[VIRT_TEST ].base,0x0 , s->memmap[VIRT_TEST ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" , +2 , s->memmap[VIRT_TEST ].base, +2 , s->memmap[VIRT_TEST ].size);qemu_fdt_setprop_cell (ms->fdt, name,"phandle" , test_phandle); test_phandle =qemu_fdt_get_phandle (ms->fdt, name);g_free (name);
Signature · 1 line
2.50.0
[PULL 18/40] target/riscv: use qemu_chr_fe_write_all() in DBCN_CONSOLE_WRITE_BYTE
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
The SBI spec states, for console write byte:
"This is a blocking SBI call and it will only return after writing the specified byte to the debug console. It will also return, with SBI_ERR_FAILED, if there are I/O errors."
Being a blocker call will either succeed writing the byte or error out, it's feasible to use the blocking qemu_chr_fe_write_all() instead of qemu_chr_fe_write().
Last but not the least, we will duck possible changes in qemu_chr_fe_write() where ret = 0 will have a 'zero byte written' semantic [1] - something that we're not ready to deal in this current state.
Message-ID: <[email protected]>
--- target/riscv/kvm/kvm-cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/kvm/kvm-cpu.c +1 -1
@@ -1619,7 +1619,7 @@ static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run)break ;case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE : ch = run->riscv_sbi.args[0 ]; - ret =qemu_chr_fe_write (serial_hd (0 )->be, &ch,sizeof (ch)); + ret =qemu_chr_fe_write_all (serial_hd (0 )->be, &ch,sizeof (ch));if (ret <0 ) { error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when "
Signature · 1 line
2.50.0
[PULL 06/40] target/riscv/tcg: restrict satp_mode changes in cpu_set_profile
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We're changing 'mmu' to true regardless of whether the profile is being enabled or not, and at the same time we're changing satp_mode to profile->enabled.
This will promote a situation where we'll set mmu=on without a virtual memory mode, which is a mistake.
Only touch 'mmu' and satp_mode if the profile is being enabled.
Message-ID: <[email protected]>
--- target/riscv/tcg/tcg-cpu.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
target/riscv/tcg/tcg-cpu.c +7 -7
@@ -1365,16 +1365,16 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,if (profile->enabled) { cpu->env.priv_ver = profile->priv_spec; - }#ifndef CONFIG_USER_ONLY -if (profile->satp_mode !=RISCV_PROFILE_ATTR_UNUSED ) { -object_property_set_bool (obj,"mmu" , true,NULL ); -const char *satp_prop =satp_mode_str (profile->satp_mode, -riscv_cpu_is_32bit (cpu)); -object_property_set_bool (obj, satp_prop, profile->enabled,NULL ); - } +if (profile->satp_mode !=RISCV_PROFILE_ATTR_UNUSED ) { +object_property_set_bool (obj,"mmu" , true,NULL ); +const char *satp_prop =satp_mode_str (profile->satp_mode, +riscv_cpu_is_32bit (cpu)); +object_property_set_bool (obj, satp_prop, true,NULL ); + }#endif + }for (i =0 ; misa_bits[i] !=0 ; i++) {uint32_t bit = misa_bits[i];
Signature · 1 line
2.50.0
[PULL 13/40] target/riscv/cpu.c: do better with 'named features' doc
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
Most of the named features are added directly in isa_edata_arr[], some of them are also added in riscv_cpu_named_features(). There is a reason for that, and the existing docs can do better explaining it.
Message-ID: <[email protected]>
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
target/riscv/cpu.c +12 -2
@@ -1377,13 +1377,23 @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {* 'Named features' is the name we give to extensions that we * don't want to expose to users. They are either immutable * (always enabled/disable) or they'll vary depending on -* the resulting CPU state. They have riscv,isa strings -* and priv_ver like regular extensions. +* the resulting CPU state. +* +* Some of them are always enabled depending on priv version +* of the CPU and are declared directly in isa_edata_arr[]. +* The ones listed here have special checks during finalize() +* time and require their own flags like regular extensions. +* See riscv_cpu_update_named_features() for more info. */ const RISCVCPUMultiExtConfig riscv_cpu_named_features[] = {MULTI_EXT_CFG_BOOL ("zic64b" , ext_zic64b, true),MULTI_EXT_CFG_BOOL ("ssstateen" , ext_ssstateen, true),MULTI_EXT_CFG_BOOL ("sha" , ext_sha, true), + +/* +* 'ziccrse' has its own flag because the KVM driver +* wants to enable/disable it on its own accord. +*/ MULTI_EXT_CFG_BOOL ("ziccrse" , ext_ziccrse, true), { },
Signature · 1 line
2.50.0
[PULL 22/40] hw/riscv/virt: Use setprop_sized_cells for clint
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/riscv/virt.c +2 -2
@@ -346,8 +346,8 @@ static void create_fdt_socket_clint(RISCVVirtState *s,qemu_fdt_setprop_string_array (ms->fdt, clint_name,"compatible" , (char **)&clint_compat,ARRAY_SIZE (clint_compat)); -qemu_fdt_setprop_cells (ms->fdt, clint_name,"reg" , -0x0 , clint_addr,0x0 , s->memmap[VIRT_CLINT ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, clint_name,"reg" , +2 , clint_addr,2 , s->memmap[VIRT_CLINT ].size);qemu_fdt_setprop (ms->fdt, clint_name,"interrupts-extended" , clint_cells, s->soc[socket].num_harts *sizeof (uint32_t ) *4 );riscv_socket_fdt_write_id (ms, clint_name, socket);
Signature · 1 line
2.50.0
[PULL 07/40] target/riscv/tcg: decouple profile enablement from user prop
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
We have code in riscv_cpu_add_profiles() to enable a profile right away in case a CPU chose the profile during its cpu_init(). But we're using the user callback option to do so, setting profile->user_set.
Create a new helper that does all the grunt work to enable/disable a given profile. Use this new helper in the cases where we want a CPU to be compatible to a certain profile, leaving the user callback to be used exclusively by users.
Message-ID: <[email protected]>
--- target/riscv/tcg/tcg-cpu.c | 127 +++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 60 deletions(-)
target/riscv/tcg/tcg-cpu.c +67 -60
@@ -1166,6 +1166,70 @@ static bool riscv_cpu_is_generic(Object *cpu_obj)return object_dynamic_cast (cpu_obj,TYPE_RISCV_DYNAMIC_CPU ) !=NULL ; } +static void riscv_cpu_set_profile (RISCVCPU *cpu, +RISCVCPUProfile *profile, +bool enabled) +{ +int i, ext_offset; + +if (profile->u_parent !=NULL ) { +riscv_cpu_set_profile (cpu, profile->u_parent, enabled); + } + +if (profile->s_parent !=NULL ) { +riscv_cpu_set_profile (cpu, profile->s_parent, enabled); + } + + profile->enabled = enabled; + +if (profile->enabled) { + cpu->env.priv_ver = profile->priv_spec; + +#ifndef CONFIG_USER_ONLY +if (profile->satp_mode !=RISCV_PROFILE_ATTR_UNUSED ) { +object_property_set_bool (OBJECT (cpu),"mmu" , true,NULL ); +const char *satp_prop =satp_mode_str (profile->satp_mode, +riscv_cpu_is_32bit (cpu)); +object_property_set_bool (OBJECT (cpu), satp_prop, true,NULL ); + } +#endif + } + +for (i =0 ; misa_bits[i] !=0 ; i++) { +uint32_t bit = misa_bits[i]; + +if (!(profile->misa_ext & bit)) { +continue ; + } + +if (bit ==RVI && !profile->enabled) { +/* +* Disabling profiles will not disable the base +* ISA RV64I. +*/ +continue ; + } + +cpu_misa_ext_add_user_opt (bit, profile->enabled); +riscv_cpu_write_misa_bit (cpu, bit, profile->enabled); + } + +for (i =0 ; profile->ext_offsets[i] !=RISCV_PROFILE_EXT_LIST_END ; i++) { + ext_offset = profile->ext_offsets[i]; + +if (profile->enabled) { +if (cpu_cfg_offset_is_named_feat (ext_offset)) { +riscv_cpu_enable_named_feat (cpu, ext_offset); + } + +cpu_bump_multi_ext_priv_ver (&cpu->env, ext_offset); + } + +cpu_cfg_ext_add_user_opt (ext_offset, profile->enabled); +isa_ext_update_enabled (cpu, ext_offset, profile->enabled); + } +} +/* * We'll get here via the following path: *
@@ -1332,7 +1396,6 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,RISCVCPUProfile *profile = opaque;RISCVCPU *cpu =RISCV_CPU (obj);bool value; -int i, ext_offset;if (riscv_cpu_is_vendor (obj)) { error_setg(errp, "Profile %s is not available for vendor CPUs",
@@ -1351,64 +1414,8 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name, } profile->user_set = true; - profile->enabled = value; - -if (profile->u_parent !=NULL ) { -object_property_set_bool (obj, profile->u_parent->name, - profile->enabled,NULL ); - } - -if (profile->s_parent !=NULL ) { -object_property_set_bool (obj, profile->s_parent->name, - profile->enabled,NULL ); - } - -if (profile->enabled) { - cpu->env.priv_ver = profile->priv_spec; - -#ifndef CONFIG_USER_ONLY -if (profile->satp_mode !=RISCV_PROFILE_ATTR_UNUSED ) { -object_property_set_bool (obj,"mmu" , true,NULL ); -const char *satp_prop =satp_mode_str (profile->satp_mode, -riscv_cpu_is_32bit (cpu)); -object_property_set_bool (obj, satp_prop, true,NULL ); - } -#endif - } - -for (i =0 ; misa_bits[i] !=0 ; i++) { -uint32_t bit = misa_bits[i]; - -if (!(profile->misa_ext & bit)) { -continue ; - } -if (bit ==RVI && !profile->enabled) { -/* -* Disabling profiles will not disable the base -* ISA RV64I. -*/ -continue ; - } - -cpu_misa_ext_add_user_opt (bit, profile->enabled); -riscv_cpu_write_misa_bit (cpu, bit, profile->enabled); - } - -for (i =0 ; profile->ext_offsets[i] !=RISCV_PROFILE_EXT_LIST_END ; i++) { - ext_offset = profile->ext_offsets[i]; - -if (profile->enabled) { -if (cpu_cfg_offset_is_named_feat (ext_offset)) { -riscv_cpu_enable_named_feat (cpu, ext_offset); - } - -cpu_bump_multi_ext_priv_ver (&cpu->env, ext_offset); - } - -cpu_cfg_ext_add_user_opt (ext_offset, profile->enabled); -isa_ext_update_enabled (cpu, ext_offset, profile->enabled); - } +riscv_cpu_set_profile (cpu, profile, value); } static void cpu_get_profile(Object *obj, Visitor *v, const char *name,
@@ -1423,7 +1430,7 @@ static void cpu_get_profile(Object *obj, Visitor *v, const char *name,static void riscv_cpu_add_profiles (Object *cpu_obj) {for (int i =0 ; riscv_profiles[i] !=NULL ; i++) { -const RISCVCPUProfile *profile = riscv_profiles[i]; +RISCVCPUProfile *profile = riscv_profiles[i]; object_property_add(cpu_obj, profile->name, "bool", cpu_get_profile, cpu_set_profile,
@@ -1435,7 +1442,7 @@ static void riscv_cpu_add_profiles(Object *cpu_obj)* case. */ if (profile->enabled) { -object_property_set_bool (cpu_obj, profile->name, true,NULL ); +riscv_cpu_set_profile (RISCV_CPU (cpu_obj), profile, true); } } }
Signature · 1 line
2.50.0
[PULL 24/40] hw/riscv/virt: Use setprop_sized_cells for aplic
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/riscv/virt.c +2 -2
@@ -655,8 +655,8 @@ static void create_fdt_one_aplic(RISCVVirtState *s, int socket,qemu_fdt_setprop_cell (ms->fdt, aplic_name,"msi-parent" , msi_phandle); } -qemu_fdt_setprop_cells (ms->fdt, aplic_name,"reg" , -0x0 , aplic_addr,0x0 , aplic_size); +qemu_fdt_setprop_sized_cells (ms->fdt, aplic_name,"reg" , +2 , aplic_addr,2 , aplic_size);qemu_fdt_setprop_cell (ms->fdt, aplic_name,"riscv,num-sources" ,VIRT_IRQCHIP_NUM_SOURCES );
Signature · 1 line
2.50.0
[PULL 39/40] target/riscv: Add a property to set vill bit on reserved usage of vsetvli instruction
In reply to [email protected]From: Vasilis Liaskovitis <[email protected]>
Usage of vsetvli instruction is reserved if VLMAX is changed when vsetvli rs1 and rd arguments are x0.
In this case, if the new property is true, only the vill bit will be set.
See https://github.com/riscv/riscv-isa-manual/blob/main/src/v-st-ext.adoc#avl-encoding
According to the spec, the above use cases are reserved, and "Implementations may set vill in either case."
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2422
Message-ID: <[email protected]>
--- target/riscv/helper.h | 2 +- target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/cpu.c | 1 + target/riscv/vector_helper.c | 12 +++++++++++- target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- 5 files changed, 16 insertions(+), 4 deletions(-)
target/riscv/helper.h +1 -1
@@ -159,7 +159,7 @@ DEF_HELPER_FLAGS_3(hyp_hsv_d, TCG_CALL_NO_WG, void, env, tl, tl)#endif /* Vector functions */ -DEF_HELPER_3(vsetvl, tl, env, tl, tl) +DEF_HELPER_4(vsetvl, tl, env, tl, tl, tl) DEF_HELPER_5(vle8_v, void, ptr, ptr, tl, env, i32) DEF_HELPER_5(vle16_v, void, ptr, ptr, tl, env, i32)DEF_HELPER_5 (vle32_v, void, ptr, ptr, tl, env, i32)
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -114,6 +114,7 @@ BOOL_FIELD(ext_supm) BOOL_FIELD(rvv_ta_all_1s) BOOL_FIELD(rvv_ma_all_1s) BOOL_FIELD(rvv_vl_half_avl) +BOOL_FIELD(rvv_vsetvl_x0_vill) /* Named features */ BOOL_FIELD(ext_svade) BOOL_FIELD(ext_zic64b)
target/riscv/cpu.c +1 -0
@@ -2632,6 +2632,7 @@ static const Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("rvv_ta_all_1s" ,RISCVCPU , cfg.rvv_ta_all_1s, false),DEFINE_PROP_BOOL ("rvv_ma_all_1s" ,RISCVCPU , cfg.rvv_ma_all_1s, false),DEFINE_PROP_BOOL ("rvv_vl_half_avl" ,RISCVCPU , cfg.rvv_vl_half_avl, false), + DEFINE_PROP_BOOL("rvv_vsetvl_x0_vill", RISCVCPU, cfg.rvv_vsetvl_x0_vill, false),/* * write_misa() is marked as experimental for now so mark
target/riscv/vector_helper.c +11 -1
@@ -35,7 +35,7 @@#include <math.h> target_ulong HELPER (vsetvl )(CPURISCVState *env,target_ulong s1, -target_ulong s2) +target_ulong s2,target_ulong x0) {int vlmax, vl;RISCVCPU *cpu =env_archcpu (env);
@@ -83,6 +83,16 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, }else { vl = vlmax; } + +if (cpu->cfg.rvv_vsetvl_x0_vill && x0 && (env->vl != vl)) { +/* only set vill bit. */ + env->vill =1 ; + env->vtype =0 ; + env->vl =0 ; + env->vstart =0 ; +return 0 ; + } + env->vl = vl; env->vtype = s2; env->vstart =0 ;
target/riscv/insn_trans/trans_rvv.c.inc +2 -2
@@ -202,7 +202,7 @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) s1 = get_gpr(s, rs1, EXT_ZERO); } - gen_helper_vsetvl(dst, tcg_env, s1, s2); + gen_helper_vsetvl(dst, tcg_env, s1, s2, tcg_constant_tl((int) (rd == 0 && rs1 == 0))); gen_set_gpr(s, rd, dst); finalize_rvv_inst(s);
@@ -222,7 +222,7 @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) dst = dest_gpr(s, rd); - gen_helper_vsetvl(dst, tcg_env, s1, s2); + gen_helper_vsetvl(dst, tcg_env, s1, s2, tcg_constant_tl(0)); gen_set_gpr(s, rd, dst); finalize_rvv_inst(s); gen_update_pc(s, s->cur_insn_len);
Signature · 1 line
2.50.0
[PULL 40/40] target: riscv: Add Svrsw60t59b extension support
In reply to [email protected]From: Alexandre Ghiti <[email protected]>
The Svrsw60t59b extension allows to free the PTE reserved bits 60 and 59 for software to use.
Message-ID: <[email protected]>
--- hw/riscv/riscv-iommu-bits.h | 1 + target/riscv/cpu_bits.h | 3 ++- target/riscv/cpu_cfg_fields.h.inc | 1 + hw/riscv/riscv-iommu.c | 3 ++- target/riscv/cpu.c | 2 ++ target/riscv/cpu_helper.c | 3 ++- target/riscv/tcg/tcg-cpu.c | 8 ++++++++ 7 files changed, 18 insertions(+), 3 deletions(-)
hw/riscv/riscv-iommu-bits.h +1 -0
@@ -79,6 +79,7 @@ struct riscv_iommu_pq_record {#define RISCV_IOMMU_CAP_SV39 BIT_ULL(9)#define RISCV_IOMMU_CAP_SV48 BIT_ULL(10)#define RISCV_IOMMU_CAP_SV57 BIT_ULL(11) +#define RISCV_IOMMU_CAP_SVRSW60T59B BIT_ULL(14)#define RISCV_IOMMU_CAP_SV32X4 BIT_ULL(16)#define RISCV_IOMMU_CAP_SV39X4 BIT_ULL(17)#define RISCV_IOMMU_CAP_SV48X4 BIT_ULL(18)
target/riscv/cpu_bits.h +2 -1
@@ -735,7 +735,8 @@ typedef enum {#define PTE_SOFT 0x300/* Reserved for Software */ #define PTE_PBMT 0x6000000000000000ULL/* Page-based memory types */ #define PTE_N 0x8000000000000000ULL/* NAPOT translation */ -#define PTE_RESERVED 0x1FC0000000000000ULL/* Reserved bits */ +#define PTE_RESERVED (svrsw60t59b) \ + (svrsw60t59b ? 0x07C0000000000000ULL : 0x1FC0000000000000ULL)/* Reserved bits */ #define PTE_ATTR (PTE_N | PTE_PBMT)/* All attributes bits */ /* Page table PPN shift amount */
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -57,6 +57,7 @@ BOOL_FIELD(ext_svadu) BOOL_FIELD(ext_svinval) BOOL_FIELD(ext_svnapot) BOOL_FIELD(ext_svpbmt) +BOOL_FIELD(ext_svrsw60t59b) BOOL_FIELD(ext_svvptc) BOOL_FIELD(ext_svukte) BOOL_FIELD(ext_zdinx)
hw/riscv/riscv-iommu.c +2 -1
@@ -2351,7 +2351,8 @@ static void riscv_iommu_realize(DeviceState *dev, Error **errp) }if (s->enable_g_stage) { s->cap |=RISCV_IOMMU_CAP_SV32X4 |RISCV_IOMMU_CAP_SV39X4 | -RISCV_IOMMU_CAP_SV48X4 |RISCV_IOMMU_CAP_SV57X4 ; +RISCV_IOMMU_CAP_SV48X4 |RISCV_IOMMU_CAP_SV57X4 | +RISCV_IOMMU_CAP_SVRSW60T59B ; }if (s->hpm_cntrs >0 ) {
target/riscv/cpu.c +2 -0
@@ -230,6 +230,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (svinval,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot,PRIV_VERSION_1_12_0 , ext_svnapot),ISA_EXT_DATA_ENTRY (svpbmt,PRIV_VERSION_1_12_0 , ext_svpbmt), +ISA_EXT_DATA_ENTRY (svrsw60t59b,PRIV_VERSION_1_13_0 , ext_svrsw60t59b),ISA_EXT_DATA_ENTRY (svukte,PRIV_VERSION_1_13_0 , ext_svukte),ISA_EXT_DATA_ENTRY (svvptc,PRIV_VERSION_1_13_0 , ext_svvptc), ISA_EXT_DATA_ENTRY(xtheadba, PRIV_VERSION_1_11_0, ext_xtheadba),
@@ -1285,6 +1286,7 @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {MULTI_EXT_CFG_BOOL ("svinval" , ext_svinval, false),MULTI_EXT_CFG_BOOL ("svnapot" , ext_svnapot, false),MULTI_EXT_CFG_BOOL ("svpbmt" , ext_svpbmt, false), +MULTI_EXT_CFG_BOOL ("svrsw60t59b" , ext_svrsw60t59b, false),MULTI_EXT_CFG_BOOL ("svvptc" , ext_svvptc, true), MULTI_EXT_CFG_BOOL("zicntr", ext_zicntr, true),
target/riscv/cpu_helper.c +2 -1
@@ -1309,6 +1309,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,bool svade =riscv_cpu_cfg (env)->ext_svade;bool svadu =riscv_cpu_cfg (env)->ext_svadu;bool adue = svadu ? env->menvcfg &MENVCFG_ADUE : !svade; +bool svrsw60t59b =riscv_cpu_cfg (env)->ext_svrsw60t59b;if (first_stage && two_stage && env->virt_enabled) { pbmte = pbmte && (env->henvcfg &HENVCFG_PBMTE );
@@ -1376,7 +1377,7 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,if (riscv_cpu_sxl (env) ==MXL_RV32 ) { ppn = pte >>PTE_PPN_SHIFT ; }else { -if (pte &PTE_RESERVED ) { +if (pte &PTE_RESERVED (svrsw60t59b)) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: reserved bits set in PTE: " "addr: 0x%" HWADDR_PRIx" pte: 0x" TARGET_FMT_lx"\n" , __func__, pte_addr, pte);
target/riscv/tcg/tcg-cpu.c +8 -0
@@ -839,6 +839,12 @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) cpu->cfg.ext_ssctr = false; } +if (cpu->cfg.ext_svrsw60t59b && + (!cpu->cfg.mmu || mcc->def->misa_mxl_max ==MXL_RV32 )) { +error_setg (errp,"svrsw60t59b is not supported on RV32 and MMU-less platforms" ); +return ; + } +/* * Disable isa extensions based on priv spec after we * validated and set everything we need.
@@ -1588,6 +1594,8 @@ static void riscv_init_max_cpu_extensions(Object *obj)if (env->misa_mxl !=MXL_RV32 ) {isa_ext_update_enabled (cpu,CPU_CFG_OFFSET (ext_zcf), false); + }else { +isa_ext_update_enabled (cpu,CPU_CFG_OFFSET (ext_svrsw60t59b), false); }/*
Signature · 1 line
2.50.0
[PULL 25/40] hw/riscv/virt: Use setprop_sized_cells for aclint
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
hw/riscv/virt.c +9 -9
@@ -387,8 +387,8 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,qemu_fdt_add_subnode (ms->fdt, name);qemu_fdt_setprop_string (ms->fdt, name,"compatible" ,"riscv,aclint-mswi" ); -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , addr,0x0 ,RISCV_ACLINT_SWI_SIZE ); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" , +2 , addr,2 ,RISCV_ACLINT_SWI_SIZE );qemu_fdt_setprop (ms->fdt, name,"interrupts-extended" , aclint_mswi_cells, aclint_cells_size);qemu_fdt_setprop (ms->fdt, name,"interrupt-controller" ,NULL ,0 );
@@ -410,11 +410,11 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,qemu_fdt_add_subnode (ms->fdt, name);qemu_fdt_setprop_string (ms->fdt, name,"compatible" ,"riscv,aclint-mtimer" ); -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , addr +RISCV_ACLINT_DEFAULT_MTIME , -0x0 , size -RISCV_ACLINT_DEFAULT_MTIME , -0x0 , addr +RISCV_ACLINT_DEFAULT_MTIMECMP , -0x0 ,RISCV_ACLINT_DEFAULT_MTIME ); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" , +2 , addr +RISCV_ACLINT_DEFAULT_MTIME , +2 , size -RISCV_ACLINT_DEFAULT_MTIME , +2 , addr +RISCV_ACLINT_DEFAULT_MTIMECMP , +2 ,RISCV_ACLINT_DEFAULT_MTIME );qemu_fdt_setprop (ms->fdt, name,"interrupts-extended" , aclint_mtimer_cells, aclint_cells_size);riscv_socket_fdt_write_id (ms, name, socket);
@@ -428,8 +428,8 @@ static void create_fdt_socket_aclint(RISCVVirtState *s,qemu_fdt_add_subnode (ms->fdt, name);qemu_fdt_setprop_string (ms->fdt, name,"compatible" ,"riscv,aclint-sswi" ); -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , addr,0x0 , s->memmap[VIRT_ACLINT_SSWI ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" , +2 , addr,2 , s->memmap[VIRT_ACLINT_SSWI ].size);qemu_fdt_setprop (ms->fdt, name,"interrupts-extended" , aclint_sswi_cells, aclint_cells_size);qemu_fdt_setprop (ms->fdt, name,"interrupt-controller" ,NULL ,0 );
Signature · 1 line
2.50.0
[PULL 21/40] hw/riscv/virt: Fix clint base address type
In reply to [email protected]From: Joel Stanley <[email protected]>
The address is a hardware address, so use hwaddr for consistency with the rest of the machine.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/riscv/virt.c +3 -3
@@ -324,7 +324,7 @@ static void create_fdt_socket_clint(RISCVVirtState *s,int cpu; g_autofree char *clint_name = NULL; g_autofree uint32_t *clint_cells = NULL; -unsigned long clint_addr; +hwaddr clint_addr;MachineState *ms =MACHINE (s);static const char *const clint_compat[2 ] = {"sifive,clint0" ,"riscv,clint0"
@@ -340,8 +340,8 @@ static void create_fdt_socket_clint(RISCVVirtState *s, } clint_addr = s->memmap[VIRT_CLINT ].base + - (s->memmap[VIRT_CLINT ].size * socket); - clint_name =g_strdup_printf ("/soc/clint@%lx" , clint_addr); + s->memmap[VIRT_CLINT ].size * socket; + clint_name =g_strdup_printf ("/soc/clint@%" HWADDR_PRIx, clint_addr);qemu_fdt_add_subnode (ms->fdt, clint_name); qemu_fdt_setprop_string_array(ms->fdt, clint_name, "compatible", (char **)&clint_compat,
Signature · 1 line
2.50.0
[PULL 30/40] hw/riscv/virt: Use setprop_sized_cells for rtc
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/riscv/virt.c +3 -2
@@ -992,8 +992,9 @@ static void create_fdt_rtc(RISCVVirtState *s,qemu_fdt_add_subnode (ms->fdt, name);qemu_fdt_setprop_string (ms->fdt, name,"compatible" ,"google,goldfish-rtc" ); -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , s->memmap[VIRT_RTC ].base,0x0 , s->memmap[VIRT_RTC ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" , +2 , s->memmap[VIRT_RTC ].base, +2 , s->memmap[VIRT_RTC ].size);qemu_fdt_setprop_cell (ms->fdt, name,"interrupt-parent" , irq_mmio_phandle);if (s->aia_type ==VIRT_AIA_TYPE_NONE ) {
Signature · 1 line
2.50.0
[PULL 32/40] hw/riscv/virt: Use setprop_sized_cells for pcie
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/riscv/virt.c +2 -2
@@ -894,8 +894,8 @@ static void create_fdt_pcie(RISCVVirtState *s,if (s->aia_type ==VIRT_AIA_TYPE_APLIC_IMSIC ) {qemu_fdt_setprop_cell (ms->fdt, name,"msi-parent" , msi_pcie_phandle); } -qemu_fdt_setprop_cells (ms->fdt, name,"reg" ,0 , - s->memmap[VIRT_PCIE_ECAM ].base,0 , s->memmap[VIRT_PCIE_ECAM ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" ,2 , + s->memmap[VIRT_PCIE_ECAM ].base,2 , s->memmap[VIRT_PCIE_ECAM ].size); qemu_fdt_setprop_sized_cells(ms->fdt, name, "ranges", 1, FDT_PCI_RANGE_IOPORT, 2, 0, 2, s->memmap[VIRT_PCIE_PIO].base, 2, s->memmap[VIRT_PCIE_PIO].size,
Signature · 1 line
2.50.0
[PULL 35/40] target/riscv: rvv: Fix missing exit TB flow for ldff_trans
In reply to [email protected]From: Max Chou <[email protected]>
According to the V spec, the vector fault-only-first load instructions may change the VL CSR.
So the ldff_trans TCG translation function should generate the lookup_and_goto_ptr flow as the vsetvl/vsetvli translation function to make sure the vl_eq_vlmax TB flag is correct.
Message-ID: <[email protected]>
--- target/riscv/insn_trans/trans_rvv.c.inc | 6 ++++++ 1 file changed, 6 insertions(+)
target/riscv/insn_trans/trans_rvv.c.inc +6 -0
@@ -1361,6 +1361,12 @@ static bool ldff_trans(uint32_t vd, uint32_t rs1, uint32_t data, fn(dest, mask, base, tcg_env, desc); finalize_rvv_inst(s); + + /* vector unit-stride fault-only-first load may modify vl CSR */ + gen_update_pc(s, s->cur_insn_len); + lookup_and_goto_ptr(s); + s->base.is_jmp = DISAS_NORETURN; + return true; }
Signature · 1 line
2.50.0
[PULL 12/40] target/riscv/cpu.c: add 'ssstrict' to riscv, isa
In reply to [email protected]From: Daniel Henrique Barboza <[email protected]>
'ssstrict' is a RVA23 profile-defined extension defined as follows:
"No non-conforming extensions are present. Attempts to execute unimplemented opcodes or access unimplemented CSRs in the standard or reserved encoding spaces raises an illegal instruction exception that results in a contained trap to the supervisor-mode trap handler."
In short, we need to throw an exception when accessing unimplemented CSRs or opcodes. We do that, so let's advertise it.
Message-ID: <[email protected]>
Message-ID: <[email protected]>
--- target/riscv/cpu.c | 1 + tests/data/acpi/riscv64/virt/RHCT | Bin 406 -> 416 bytes 2 files changed, 1 insertion(+)
target/riscv/cpu.c +1 -0
@@ -217,6 +217,7 @@ const RISCVIsaExtData isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (ssnpm,PRIV_VERSION_1_13_0 , ext_ssnpm),ISA_EXT_DATA_ENTRY (sspm,PRIV_VERSION_1_13_0 , ext_sspm),ISA_EXT_DATA_ENTRY (ssstateen,PRIV_VERSION_1_12_0 , ext_ssstateen), +ISA_EXT_DATA_ENTRY (ssstrict,PRIV_VERSION_1_12_0 , has_priv_1_12),ISA_EXT_DATA_ENTRY (sstc,PRIV_VERSION_1_12_0 , ext_sstc),ISA_EXT_DATA_ENTRY (sstvala,PRIV_VERSION_1_12_0 , has_priv_1_12), ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12),
tests/data/acpi/riscv64/virt/RHCT binary +0 -0
Signature · 1 line
2.50.0
[PULL 14/40] target/riscv: support atomic instruction fetch (Ziccif)
In reply to [email protected]From: Jim Shu <[email protected]>
Support 4-byte atomic instruction fetch when instruction is natural aligned.
Current implementation is not atomic because it loads instruction twice for first and last 2 bytes. We load 4 bytes at once to keep the atomicity. This instruction preload method only applys when instruction is 4-byte aligned. If instruction is unaligned, it could be across pages so that preload will trigger additional page fault.
We encounter this issue when doing pressure test of enabling & disabling Linux kernel ftrace. Ftrace with kernel preemption requires concurrent modification and execution of instruction, so non-atomic instruction fetch will cause the race condition. We may fetch the wrong instruction which is the mixing of 2 instructions.
Also, RISC-V Profile wants to provide this feature by HW. RVA20U64 Ziccif protects the atomicity of instruction fetch when it is natural aligned.
This commit depends on the atomic read support of translator_ld in the commit 6a9dfe1984b0c593fb0ddb52d4e70832e6201dd6.
Message-ID: <[email protected]>
--- target/riscv/translate.c | 46 +++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-)
target/riscv/translate.c +34 -12
@@ -1217,13 +1217,35 @@ const RISCVDecoder decoder_table[] = {const size_t decoder_table_size =ARRAY_SIZE (decoder_table); -static void decode_opc (CPURISCVState *env,DisasContext *ctx,uint16_t opcode) +static void decode_opc (CPURISCVState *env,DisasContext *ctx) { +uint32_t opcode; +bool pc_is_4byte_align = ((ctx->base.pc_next %4 ) ==0 ); + ctx->virt_inst_excp = false; - ctx->cur_insn_len =insn_len (opcode); +if (pc_is_4byte_align) { +/* +* Load 4 bytes at once to make instruction fetch atomically. +* +* Note: When pc is 4-byte aligned, 4-byte instruction wouldn't be +* across pages. We could preload 4 bytes instruction no matter +* real one is 2 or 4 bytes. Instruction preload wouldn't trigger +* additional page fault. +*/ + opcode =translator_ldl (env, &ctx->base, ctx->base.pc_next); + }else { +/* +* For unaligned pc, instruction preload may trigger additional +* page fault so we only load 2 bytes here. +*/ + opcode = (uint32_t )translator_lduw (env, &ctx->base, ctx->base.pc_next); + } + ctx->ol = ctx->xl; + + ctx->cur_insn_len =insn_len ((uint16_t )opcode);/* Check for compressed insn */ if (ctx->cur_insn_len ==2 ) { - ctx->opcode = opcode; + ctx->opcode = (uint16_t )opcode;/* * The Zca extension is added as way to refer to instructions in the C * extension that do not include the floating-point loads and stores
@@ -1233,15 +1255,17 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)return ; } }else { -uint32_t opcode32 = opcode; - opcode32 =deposit32 (opcode32,16 ,16 , -translator_lduw (env, &ctx->base, - ctx->base.pc_next +2 )); - ctx->opcode = opcode32; +if (!pc_is_4byte_align) { +/* Load last 2 bytes of instruction here */ + opcode =deposit32 (opcode,16 ,16 , +translator_lduw (env, &ctx->base, + ctx->base.pc_next +2 )); + } + ctx->opcode = opcode;for (guint i =0 ; i < ctx->decoders->len; ++i) {riscv_cpu_decode_fn func =g_ptr_array_index (ctx->decoders, i); -if (func (ctx, opcode32)) { +if (func (ctx, opcode)) {return ; } }
@@ -1319,10 +1343,8 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPURISCVState *env =cpu_env (cpu); -uint16_t opcode16 =translator_lduw (env, &ctx->base, ctx->base.pc_next); - ctx->ol = ctx->xl; -decode_opc (env, ctx, opcode16); +decode_opc (env, ctx); ctx->base.pc_next += ctx->cur_insn_len;/*
Signature · 1 line
2.50.0
[PULL 37/40] target/riscv: Fix MEPC/SEPC bit masking for IALIGN
In reply to [email protected]From: Charalampos Mitrodimas <[email protected]>
According to the RISC-V Privileged Architecture specification, the low bit of MEPC/SEPC must always be zero. When IALIGN=32, the two low bits must be zero.
This commit fixes the behavior of MEPC/SEPC CSR reads and writes, and the implicit reads by MRET/SRET instructions to properly mask the lowest bit(s) based on whether the C extension is enabled:
- When C extension is enabled (IALIGN=16): mask bit 0
- When C extension is disabled (IALIGN=32): mask bits [1:0]
Previously, when vectored mode bits from STVEC (which sets bit 0 for vectored mode) were written to MEPC, the bits would not be cleared correctly, causing incorrect behavior on MRET.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2855
Message-ID: <[email protected]>
--- target/riscv/internals.h | 11 +++++++++++ target/riscv/csr.c | 8 ++++---- target/riscv/op_helper.c | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-)
target/riscv/internals.h +11 -0
@@ -158,6 +158,17 @@ static inline float16 check_nanbox_bf16(CPURISCVState *env, uint64_t f) } } +static inline target_ulong get_xepc_mask (CPURISCVState *env) +{ +/* When IALIGN=32, both low bits must be zero. +* When IALIGN=16 (has C extension), only bit 0 must be zero. */ +if (riscv_has_ext (env,RVC )) { +return ~(target_ulong )1 ; + }else { +return ~(target_ulong )3 ; + } +} +#ifndef CONFIG_USER_ONLY /* Our implementation of SysemuCPUOps::has_work */ bool riscv_cpu_has_work (CPUState *cs);
target/riscv/csr.c +4 -4
@@ -3129,14 +3129,14 @@ static RISCVException write_mscratch(CPURISCVState *env, int csrno,static RISCVException read_mepc (CPURISCVState *env,int csrno,target_ulong *val) { - *val = env->mepc; + *val = env->mepc &get_xepc_mask (env);return RISCV_EXCP_NONE ; }static RISCVException write_mepc (CPURISCVState *env,int csrno,target_ulong val,uintptr_t ra) { - env->mepc = val; + env->mepc = val &get_xepc_mask (env);return RISCV_EXCP_NONE ; }
@@ -4169,14 +4169,14 @@ static RISCVException write_sscratch(CPURISCVState *env, int csrno,static RISCVException read_sepc (CPURISCVState *env,int csrno,target_ulong *val) { - *val = env->sepc; + *val = env->sepc &get_xepc_mask (env);return RISCV_EXCP_NONE ; }static RISCVException write_sepc (CPURISCVState *env,int csrno,target_ulong val,uintptr_t ra) { - env->sepc = val; + env->sepc = val &get_xepc_mask (env);return RISCV_EXCP_NONE ; }
target/riscv/op_helper.c +2 -2
@@ -280,7 +280,7 @@ target_ulong helper_sret(CPURISCVState *env)riscv_raise_exception (env,RISCV_EXCP_ILLEGAL_INST ,GETPC ()); } -target_ulong retpc = env->sepc; +target_ulong retpc = env->sepc &get_xepc_mask (env);if (!riscv_cpu_allow_16bit_insn (&env_archcpu (env)->cfg, env->priv_ver, env->misa_ext) && (retpc &0x3 )) {
@@ -391,7 +391,7 @@ static target_ulong ssdbltrp_mxret(CPURISCVState *env, target_ulong mstatus,target_ulong helper_mret (CPURISCVState *env) { -target_ulong retpc = env->mepc; +target_ulong retpc = env->mepc &get_xepc_mask (env);uint64_t mstatus = env->mstatus;target_ulong prev_priv =get_field (mstatus,MSTATUS_MPP );
Signature · 1 line
2.50.0
[PULL 29/40] hw/riscv/virt: Use setprop_sized_cells for uart
In reply to [email protected]From: Joel Stanley <[email protected]>
The current device tree property uses two cells for the address (and for the size), but assumes the they are less than 32 bits by hard coding the high cell to zero.
Use qemu_fdt_setprop_sized_cells to do the job of splitting the upper and lower 32 bits across cells.
Message-ID: <[email protected]>
--- hw/riscv/virt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/riscv/virt.c +3 -3
@@ -966,9 +966,9 @@ static void create_fdt_uart(RISCVVirtState *s, s->memmap[VIRT_UART0].base);qemu_fdt_add_subnode (ms->fdt, name);qemu_fdt_setprop_string (ms->fdt, name,"compatible" ,"ns16550a" ); -qemu_fdt_setprop_cells (ms->fdt, name,"reg" , -0x0 , s->memmap[VIRT_UART0 ].base, -0x0 , s->memmap[VIRT_UART0 ].size); +qemu_fdt_setprop_sized_cells (ms->fdt, name,"reg" , +2 , s->memmap[VIRT_UART0 ].base, +2 , s->memmap[VIRT_UART0 ].size);qemu_fdt_setprop_cell (ms->fdt, name,"clock-frequency" ,3686400 );qemu_fdt_setprop_cell (ms->fdt, name,"interrupt-parent" , irq_mmio_phandle);if (s->aia_type ==VIRT_AIA_TYPE_NONE ) {
Signature · 1 line
2.50.0
[PULL 20/40] hw/char: sifive_uart: Avoid infinite delay of async xmit function
In reply to [email protected]From: Florian Lugou <[email protected]>
The current handler for TXFIFO writes schedules an async callback to pop characters from the queue. When software writes to TXFIFO faster than the async callback delay (100ns), the timer may be pushed back while the previous character has not be dequeued yet. This happens in particular when using -icount with small shift values. This is especially worrysome when software repetitively issues amoor.w instructions (as suggested by SiFive specification) and the FIFO is full, leading to the callback being infinitly pushed back.
This commit fixes the issue by never pushing back the timer, only updating it if it is not already active.
Message-ID: <[email protected]>
--- hw/char/sifive_uart.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/char/sifive_uart.c +4 -2
@@ -128,8 +128,10 @@ static void sifive_uart_write_tx_fifo(SiFiveUARTState *s, const uint8_t *buf, s->txfifo |=SIFIVE_UART_TXFIFO_FULL ; } -timer_mod (s->fifo_trigger_handle, current_time + -TX_INTERRUPT_TRIGGER_DELAY_NS ); +if (!timer_pending (s->fifo_trigger_handle)) { +timer_mod (s->fifo_trigger_handle, current_time + +TX_INTERRUPT_TRIGGER_DELAY_NS ); + } } static uint64_t
Signature · 1 line
2.50.0
[PULL 19/40] target/riscv: Fix fcvt.s.bf16 NaN box checking
In reply to [email protected]From: Anton Blanchard <[email protected]>
fcvt.s.bf16 uses the FP16 check_nanbox_h() which returns an FP16 quiet NaN. Add check_nanbox_bf16() which returns a BF16 quiet NaN.
Message-ID: <[email protected]>
--- target/riscv/internals.h | 16 ++++++++++++++++ target/riscv/fpu_helper.c | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-)
target/riscv/internals.h +16 -0
@@ -142,6 +142,22 @@ static inline float16 check_nanbox_h(CPURISCVState *env, uint64_t f) } } +static inline float16 check_nanbox_bf16 (CPURISCVState *env,uint64_t f) +{ +/* Disable nanbox check when enable zfinx */ +if (env_archcpu (env)->cfg.ext_zfinx) { +return (uint16_t )f; + } + +uint64_t mask =MAKE_64BIT_MASK (16 ,48 ); + +if (likely ((f & mask) == mask)) { +return (uint16_t )f; + }else { +return 0x7FC0u ;/* default qnan */ + } +} +#ifndef CONFIG_USER_ONLY /* Our implementation of SysemuCPUOps::has_work */ bool riscv_cpu_has_work (CPUState *cs);
target/riscv/fpu_helper.c +1 -1
@@ -755,6 +755,6 @@ uint64_t helper_fcvt_bf16_s(CPURISCVState *env, uint64_t rs1)uint64_t helper_fcvt_s_bf16 (CPURISCVState *env,uint64_t rs1) { -float16 frs1 =check_nanbox_h (env, rs1); +float16 frs1 =check_nanbox_bf16 (env, rs1);return nanbox_s (env,bfloat16_to_float32 (frs1, &env->fp_status)); }
Signature · 1 line
2.50.0
[PULL 33/40] target/riscv: Add BOSC's Xiangshan Kunminghu CPU
In reply to [email protected]From: Huang Borong <[email protected]>
Add a CPU entry for the Xiangshan Kunminghu CPU, an open-source, high-performance RISC-V processor. More details can be found at:
https://github.com/OpenXiangShan/XiangShan
Note: The ISA extensions supported by the Xiangshan Kunminghu CPU are categorized based on four RISC-V specifications: Volume I: Unprivileged Architecture, Volume II: Privileged Architecture, AIA, and RVA23. The extensions within each category are organized according to the chapter order in the specifications.
Message-ID: <[email protected]>
--- target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+)
target/riscv/cpu-qom.h +1 -0
@@ -55,6 +55,7 @@#define TYPE_RISCV_CPU_VEYRON_V1 RISCV_CPU_TYPE_NAME("veyron-v1")#define TYPE_RISCV_CPU_TT_ASCALON RISCV_CPU_TYPE_NAME("tt-ascalon")#define TYPE_RISCV_CPU_XIANGSHAN_NANHU RISCV_CPU_TYPE_NAME("xiangshan-nanhu") +#define TYPE_RISCV_CPU_XIANGSHAN_KMH RISCV_CPU_TYPE_NAME("xiangshan-kunminghu")#define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host")OBJECT_DECLARE_CPU_TYPE (RISCVCPU , RISCVCPUClass,RISCV_CPU )
target/riscv/cpu.c +58 -0
64 lines not on this page · raw message
Signature · 1 line
2.50.0
[PULL 34/40] hw/riscv: Initial support for BOSC's Xiangshan Kunminghu FPGA prototype
In reply to [email protected]From: Huang Borong <[email protected]>
This implementation provides emulation for the Xiangshan Kunminghu FPGA prototype platform, including support for UART, CLINT, IMSIC, and APLIC devices. More details can be found at
https://github.com/OpenXiangShan/XiangShan
Message-ID: <[email protected]>
--- MAINTAINERS | 7 + docs/system/riscv/xiangshan-kunminghu.rst | 39 ++++ docs/system/target-riscv.rst | 1 + configs/devices/riscv64-softmmu/default.mak | 1 + include/hw/riscv/xiangshan_kmh.h | 68 ++++++ hw/riscv/xiangshan_kmh.c | 220 ++++++++++++++++++++ hw/riscv/Kconfig | 9 + hw/riscv/meson.build | 1 + 8 files changed, 346 insertions(+) create mode 100644 docs/system/riscv/xiangshan-kunminghu.rst create mode 100644 include/hw/riscv/xiangshan_kmh.h create mode 100644 hw/riscv/xiangshan_kmh.c
MAINTAINERS +7 -0
@@ -1697,6 +1697,13 @@ S: Maintained F: hw/riscv/microblaze-v-generic.c F: docs/system/riscv/microblaze-v-generic.rst +Xiangshan Kunminghu +M: Ran Wang <[email protected]> +S: Maintained +F: docs/system/riscv/xiangshan-kunminghu.rst +F: hw/riscv/xiangshan_kmh.c +F: include/hw/riscv/xiangshan_kmh.h + RX Machines ----------- rx-gdbsim
docs/system/riscv/xiangshan-kunminghu.rst new file +39 -0
@@ -0,0 +1,39 @@ +BOSC Xiangshan Kunminghu FPGA prototype platform (``xiangshan-kunminghu``) +========================================================================== +The ``xiangshan-kunminghu`` machine is compatible with our FPGA prototype +platform. + +XiangShan is an open-source high-performance RISC-V processor project. +The third generation processor is called Kunminghu. Kunminghu is a 64-bit +RV64GCBSUHV processor core. More information can be found in our Github +repository: +https://github.com/OpenXiangShan/XiangShan + +Supported devices +----------------- +The ``xiangshan-kunminghu`` machine supports the following devices: + +* Up to 16 xiangshan-kunminghu cores +* Core Local Interruptor (CLINT) +* Incoming MSI Controller (IMSIC) +* Advanced Platform-Level Interrupt Controller (APLIC) +* 1 UART + +Boot options +------------ +The ``xiangshan-kunminghu`` machine can start using the standard ``-bios`` +functionality for loading the boot image. You need to compile and link +the firmware, kernel, and Device Tree (FDT) into a single binary file, +such as ``fw_payload.bin``. + +Running +------- +Below is an example command line for running the ``xiangshan-kunminghu`` +machine: + +.. code-block:: bash + + $ qemu-system-riscv64 -machine xiangshan-kunminghu \ + -smp 16 -m 16G \ + -bios path/to/opensbi/platform/generic/firmware/fw_payload.bin \ + -nographic
docs/system/target-riscv.rst +1 -0
@@ -71,6 +71,7 @@ undocumented; you can get a complete list by running riscv/shakti-c riscv/sifive_u riscv/virt + riscv/xiangshan-kunminghu RISC-V CPU firmware -------------------
configs/devices/riscv64-softmmu/default.mak +1 -0
@@ -11,3 +11,4 @@ # CONFIG_RISCV_VIRT=n # CONFIG_MICROCHIP_PFSOC=n # CONFIG_SHAKTI_C=n +# CONFIG_XIANGSHAN_KUNMINGHU=n
include/hw/riscv/xiangshan_kmh.h new file +68 -0
68 lines not on this page · raw message
hw/riscv/xiangshan_kmh.c new file +220 -0
220 lines not on this page · raw message
hw/riscv/Kconfig +9 -0
@@ -119,3 +119,12 @@ config SPIKE select HTIF select RISCV_ACLINT select SIFIVE_PLIC + +config XIANGSHAN_KUNMINGHU + bool + default y + depends on RISCV64 + select RISCV_ACLINT + select RISCV_APLIC + select RISCV_IMSIC + select SERIAL_MM
hw/riscv/meson.build +1 -0
@@ -13,5 +13,6 @@ 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')) riscv_ss.add(when: 'CONFIG_MICROBLAZE_V', if_true: files('microblaze-v-generic.c')) +riscv_ss.add(when: 'CONFIG_XIANGSHAN_KUNMINGHU', if_true: files('xiangshan_kmh.c')) hw_arch += {'riscv': riscv_ss}
Signature · 1 line
2.50.0
[PULL 16/40] target/riscv: Make PMP region count configurable
In reply to [email protected]From: Jay Chang <[email protected]>
Previously, the number of PMP regions was hardcoded to 16 in QEMU. This patch replaces the fixed value with a new pmp_regions field, allowing platforms to configure the number of PMP regions.
If no specific value is provided, the default number of PMP regions remains 16 to preserve the existing behavior.
A new CPU parameter num-pmp-regions has been introduced to the QEMU command line. For example:
-cpu rv64, g=true, c=true, pmp=true, num-pmp-regions=8
Message-ID: <[email protected]>
--- target/riscv/cpu.h | 3 +- target/riscv/cpu_cfg_fields.h.inc | 1 + target/riscv/cpu.c | 48 +++++++++++++++++++++++++++++-- target/riscv/csr.c | 5 +++- target/riscv/machine.c | 3 +- target/riscv/pmp.c | 28 ++++++++++++------ 6 files changed, 74 insertions(+), 14 deletions(-)
target/riscv/cpu.h +2 -1
@@ -174,7 +174,8 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_implied_rules[];#define MMU_USER_IDX 3 -#define MAX_RISCV_PMPS (16) +#define MAX_RISCV_PMPS (64) +#define OLD_MAX_RISCV_PMPS (16)#if !defined(CONFIG_USER_ONLY )#include "pmp.h"
target/riscv/cpu_cfg_fields.h.inc +1 -0
@@ -163,6 +163,7 @@ TYPED_FIELD(uint16_t, elen, 0) TYPED_FIELD(uint16_t, cbom_blocksize, 0) TYPED_FIELD(uint16_t, cbop_blocksize, 0) TYPED_FIELD(uint16_t, cboz_blocksize, 0) +TYPED_FIELD(uint8_t, pmp_regions, 0) TYPED_FIELD(int8_t, max_satp_mode, -1)
target/riscv/cpu.c +46 -2
78 lines not on this page · raw message
target/riscv/csr.c +4 -1
@@ -738,7 +738,10 @@ static RISCVException dbltrp_hmode(CPURISCVState *env, int csrno)static RISCVException pmp (CPURISCVState *env,int csrno) {if (riscv_cpu_cfg (env)->pmp) { -if (csrno <=CSR_PMPCFG3 ) { +int max_pmpcfg = (env->priv_ver >=PRIV_VERSION_1_12_0 ) ? ++CSR_PMPCFG15 :CSR_PMPCFG3 ; + +if (csrno <= max_pmpcfg) {uint32_t reg_index = csrno -CSR_PMPCFG0 ;/* TODO: RV128 restriction check */
target/riscv/machine.c +2 -1
@@ -36,8 +36,9 @@ static int pmp_post_load(void *opaque, int version_id)RISCVCPU *cpu = opaque;CPURISCVState *env = &cpu->env;int i; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions; -for (i =0 ; i <MAX_RISCV_PMPS ; i++) { +for (i =0 ; i < pmp_regions; i++) {pmp_update_rule_addr (env, i); }pmp_update_rule_nums (env);
target/riscv/pmp.c +19 -9
@@ -122,7 +122,9 @@ uint32_t pmp_get_num_rules(CPURISCVState *env)*/ static inline uint8_t pmp_read_cfg (CPURISCVState *env,uint32_t pmp_index) { -if (pmp_index <MAX_RISCV_PMPS ) { +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions; + +if (pmp_index < pmp_regions) {return env->pmp_state.pmp[pmp_index].cfg_reg; }
@@ -136,7 +138,9 @@ static inline uint8_t pmp_read_cfg(CPURISCVState *env, uint32_t pmp_index)*/ static bool pmp_write_cfg (CPURISCVState *env,uint32_t pmp_index,uint8_t val) { -if (pmp_index <MAX_RISCV_PMPS ) { +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions; + +if (pmp_index < pmp_regions) {if (env->pmp_state.pmp[pmp_index].cfg_reg == val) {/* no change */ return false;
@@ -236,9 +240,10 @@ void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index)void pmp_update_rule_nums (CPURISCVState *env) {int i; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions; env->pmp_state.num_rules =0 ; -for (i =0 ; i <MAX_RISCV_PMPS ; i++) { +for (i =0 ; i < pmp_regions; i++) {const uint8_t a_field =pmp_get_a_field (env->pmp_state.pmp[i].cfg_reg);if (PMP_AMATCH_OFF != a_field) {
@@ -332,6 +337,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,int pmp_size =0 ;hwaddr s =0 ;hwaddr e =0 ; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions;/* Short cut if no rules */ if (0 ==pmp_get_num_rules (env)) {
@@ -356,7 +362,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, hwaddr addr,* 1.10 draft priv spec states there is an implicit order * from low to high */ -for (i =0 ; i <MAX_RISCV_PMPS ; i++) { +for (i =0 ; i < pmp_regions; i++) { s =pmp_is_in_range (env, i, addr); e =pmp_is_in_range (env, i, addr + pmp_size -1 );
@@ -527,8 +533,9 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, {trace_pmpaddr_csr_write (env->mhartid, addr_index, val);bool is_next_cfg_tor = false; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions; -if (addr_index <MAX_RISCV_PMPS ) { +if (addr_index < pmp_regions) {if (env->pmp_state.pmp[addr_index].addr_reg == val) {/* no change */ return ;
@@ -538,7 +545,7 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,* In TOR mode, need to check the lock bit of the next pmp * (if there is a next). */ -if (addr_index +1 <MAX_RISCV_PMPS ) { +if (addr_index +1 < pmp_regions) {uint8_t pmp_cfg = env->pmp_state.pmp[addr_index +1 ].cfg_reg; is_next_cfg_tor =PMP_AMATCH_TOR ==pmp_get_a_field (pmp_cfg);
@@ -573,8 +580,9 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,target_ulong pmpaddr_csr_read (CPURISCVState *env,uint32_t addr_index) {target_ulong val =0 ; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions; -if (addr_index <MAX_RISCV_PMPS ) { +if (addr_index < pmp_regions) { val = env->pmp_state.pmp[addr_index].addr_reg;trace_pmpaddr_csr_read (env->mhartid, addr_index, val); }else {
@@ -592,6 +600,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val) {int i;uint64_t mask =MSECCFG_MMWP |MSECCFG_MML ; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions;/* Update PMM field only if the value is valid according to Zjpm v1.0 */ if (riscv_cpu_cfg(env)->ext_smmpm && riscv_cpu_mxl(env) == MXL_RV64 &&
@@ -603,7 +612,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val)/* RLB cannot be enabled if it's already 0 and if any regions are locked */ if (!MSECCFG_RLB_ISSET (env)) { -for (i =0 ; i <MAX_RISCV_PMPS ; i++) { +for (i =0 ; i < pmp_regions; i++) {if (pmp_is_locked (env, i)) { val &= ~MSECCFG_RLB ;break ;
@@ -659,6 +668,7 @@ target_ulong pmp_get_tlb_size(CPURISCVState *env, hwaddr addr)hwaddr tlb_sa = addr & ~(TARGET_PAGE_SIZE -1 );hwaddr tlb_ea = tlb_sa +TARGET_PAGE_SIZE -1 ;int i; +uint8_t pmp_regions =riscv_cpu_cfg (env)->pmp_regions;/* * If PMP is not supported or there are no PMP rules, the TLB page will not
@@ -669,7 +679,7 @@ target_ulong pmp_get_tlb_size(CPURISCVState *env, hwaddr addr)return TARGET_PAGE_SIZE ; } -for (i =0 ; i <MAX_RISCV_PMPS ; i++) { +for (i =0 ; i < pmp_regions; i++) {if (pmp_get_a_field (env->pmp_state.pmp[i].cfg_reg) ==PMP_AMATCH_OFF ) {continue ; }
Signature · 1 line
2.50.0
[PULL 01/40] target/riscv: Add the checking into stimecmp write function.
In reply to [email protected]From: Jim Shu <[email protected]>
Preparation commit to let aclint timer to use stimecmp write function. Aclint timer doesn't call sstc() predicate so we need to check inside the stimecmp write function.
Message-ID: <[email protected]>
--- target/riscv/time_helper.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
target/riscv/time_helper.c +17 -2
@@ -46,8 +46,23 @@ void riscv_timer_write_timecmp(CPURISCVState *env, QEMUTimer *timer, {uint64_t diff, ns_diff, next;RISCVAclintMTimerState *mtimer = env->rdtime_fn_arg; -uint32_t timebase_freq = mtimer->timebase_freq; -uint64_t rtc_r = env->rdtime_fn (env->rdtime_fn_arg) + delta; +uint32_t timebase_freq; +uint64_t rtc_r; + +if (!riscv_cpu_cfg (env)->ext_sstc || !env->rdtime_fn || + !env->rdtime_fn_arg || !get_field (env->menvcfg,MENVCFG_STCE )) { +/* S/VS Timer IRQ depends on sstc extension, rdtime_fn(), and STCE. */ +return ; + } + +if (timer_irq ==MIP_VSTIP && + (!riscv_has_ext (env,RVH ) || !get_field (env->henvcfg,HENVCFG_STCE ))) { +/* VS Timer IRQ also depends on RVH and henvcfg.STCE. */ +return ; + } + + timebase_freq = mtimer->timebase_freq; + rtc_r = env->rdtime_fn (env->rdtime_fn_arg) + delta;if (timecmp <= rtc_r) {/*
Signature · 1 line
2.50.0
[PULL 09/40] target/riscv: Extend PMP region up to 64
In reply to [email protected]From: Jay Chang <[email protected]>
According to the RISC-V Privileged Specification (version >1.12), RV32 supports 16 CSRs (pmpcfg0–pmpcfg15) to configure 64 PMP regions (pmpaddr0–pmpaddr63).
Message-ID: <[email protected]>
--- target/riscv/cpu_bits.h | 60 +++++++++++++++++++ target/riscv/csr.c | 124 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 182 insertions(+), 2 deletions(-)
target/riscv/cpu_bits.h +60 -0
@@ -372,6 +372,18 @@#define CSR_PMPCFG1 0x3a1#define CSR_PMPCFG2 0x3a2#define CSR_PMPCFG3 0x3a3 +#define CSR_PMPCFG4 0x3a4 +#define CSR_PMPCFG5 0x3a5 +#define CSR_PMPCFG6 0x3a6 +#define CSR_PMPCFG7 0x3a7 +#define CSR_PMPCFG8 0x3a8 +#define CSR_PMPCFG9 0x3a9 +#define CSR_PMPCFG10 0x3aa +#define CSR_PMPCFG11 0x3ab +#define CSR_PMPCFG12 0x3ac +#define CSR_PMPCFG13 0x3ad +#define CSR_PMPCFG14 0x3ae +#define CSR_PMPCFG15 0x3af#define CSR_PMPADDR0 0x3b0#define CSR_PMPADDR1 0x3b1#define CSR_PMPADDR2 0x3b2
@@ -388,6 +400,54 @@#define CSR_PMPADDR13 0x3bd#define CSR_PMPADDR14 0x3be#define CSR_PMPADDR15 0x3bf +#define CSR_PMPADDR16 0x3c0 +#define CSR_PMPADDR17 0x3c1 +#define CSR_PMPADDR18 0x3c2 +#define CSR_PMPADDR19 0x3c3 +#define CSR_PMPADDR20 0x3c4 +#define CSR_PMPADDR21 0x3c5 +#define CSR_PMPADDR22 0x3c6 +#define CSR_PMPADDR23 0x3c7 +#define CSR_PMPADDR24 0x3c8 +#define CSR_PMPADDR25 0x3c9 +#define CSR_PMPADDR26 0x3ca +#define CSR_PMPADDR27 0x3cb +#define CSR_PMPADDR28 0x3cc +#define CSR_PMPADDR29 0x3cd +#define CSR_PMPADDR30 0x3ce +#define CSR_PMPADDR31 0x3cf +#define CSR_PMPADDR32 0x3d0 +#define CSR_PMPADDR33 0x3d1 +#define CSR_PMPADDR34 0x3d2 +#define CSR_PMPADDR35 0x3d3 +#define CSR_PMPADDR36 0x3d4 +#define CSR_PMPADDR37 0x3d5 +#define CSR_PMPADDR38 0x3d6 +#define CSR_PMPADDR39 0x3d7 +#define CSR_PMPADDR40 0x3d8 +#define CSR_PMPADDR41 0x3d9 +#define CSR_PMPADDR42 0x3da +#define CSR_PMPADDR43 0x3db +#define CSR_PMPADDR44 0x3dc +#define CSR_PMPADDR45 0x3dd +#define CSR_PMPADDR46 0x3de +#define CSR_PMPADDR47 0x3df +#define CSR_PMPADDR48 0x3e0 +#define CSR_PMPADDR49 0x3e1 +#define CSR_PMPADDR50 0x3e2 +#define CSR_PMPADDR51 0x3e3 +#define CSR_PMPADDR52 0x3e4 +#define CSR_PMPADDR53 0x3e5 +#define CSR_PMPADDR54 0x3e6 +#define CSR_PMPADDR55 0x3e7 +#define CSR_PMPADDR56 0x3e8 +#define CSR_PMPADDR57 0x3e9 +#define CSR_PMPADDR58 0x3ea +#define CSR_PMPADDR59 0x3eb +#define CSR_PMPADDR60 0x3ec +#define CSR_PMPADDR61 0x3ed +#define CSR_PMPADDR62 0x3ee +#define CSR_PMPADDR63 0x3ef/* RNMI */ #define CSR_MNSCRATCH 0x740
target/riscv/csr.c +122 -2
136 lines not on this page · raw message
Signature · 1 line
2.50.0
[PULL 38/40] tests/tcg/riscv64: Add test for MEPC bit masking
In reply to [email protected]From: Charalampos Mitrodimas <[email protected]>
Add a regression test to verify that MEPC properly masks the lower bits when an address with mode bits is written to it, as required by the RISC-V Privileged Architecture specification.
The test sets STVEC to an address with bit 0 set (vectored mode), triggers an illegal instruction exception, copies STVEC to MEPC in the trap handler, and verifies that MEPC masks bits [1:0] correctly for IALIGN=32.
Without the fix, MEPC retains the mode bits (returns non-zero/FAIL). With the fix, MEPC clears bits [1:0] (returns 0/PASS).
Message-ID: <[email protected]>
--- tests/tcg/riscv64/Makefile.softmmu-target | 4 ++ tests/tcg/riscv64/test-mepc-masking.S | 73 +++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 tests/tcg/riscv64/test-mepc-masking.S
tests/tcg/riscv64/Makefile.softmmu-target +4 -0
@@ -20,5 +20,9 @@ EXTRA_RUNS += run-issue1060 run-issue1060: issue1060 $(call run-test, $<, $(QEMU) $(QEMU_OPTS)$<) +EXTRA_RUNS += run-test-mepc-masking +run-test-mepc-masking: test-mepc-masking + $(call run-test, $<, $(QEMU) $(QEMU_OPTS)$<) + # We don't currently support the multiarch system tests undefine MULTIARCH_TESTS
tests/tcg/riscv64/test-mepc-masking.S new file +73 -0
73 lines not on this page · raw message
Signature · 1 line
2.50.0
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.1 for any user-visible changes.