riscv-to-apply queue
Subsystems (2)
From: Alistair Francis <[email protected]>
The following changes since commit ad38520bdeb2b1e0b487db317f29119e94c1c88d:
Merge remote-tracking branch 'remotes/stefanha-gitlab/tags/block-pull-request' into staging (2022-02-15 19:30:33 +0000)
are available in the Git repository at:
[email protected]:alistair23/qemu.git tags/pull-riscv-to-apply-20220216
for you to fetch changes up to 7035b8420fa52e8c94cf4317c0f88c1b73ced28d:
docs/system: riscv: Update description of CPU (2022-02-16 12:25:52 +1000)
----------------------------------------------------------------
Fourth RISC-V PR for QEMU 7.0
* Remove old Ibex PLIC header file
* Allow writing 8 bytes with generic loader
* Fixes for RV128
* Refactor RISC-V CPU configs
* Initial support for XVentanaCondOps custom extension
* Fix for vill field in vtype
* Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode
* Support for svnapot, svinval and svpbmt extensions
----------------------------------------------------------------
Anup Patel (18):
target/riscv: Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode target/riscv: Implement SGEIP bit in hip and hie CSRs target/riscv: Implement hgeie and hgeip CSRs
target/riscv: Improve delivery of guest external interrupts target/riscv: Allow setting CPU feature from machine/device emulation target/riscv: Add AIA cpu feature
target/riscv: Add defines for AIA CSRs
target/riscv: Allow AIA device emulation to set ireg rmw callback target/riscv: Implement AIA local interrupt priorities target/riscv: Implement AIA CSRs for 64 local interrupts on RV32 target/riscv: Implement AIA hvictl and hviprioX CSRs target/riscv: Implement AIA interrupt filtering CSRs target/riscv: Implement AIA mtopi, stopi, and vstopi CSRs target/riscv: Implement AIA xiselect and xireg CSRs target/riscv: Implement AIA IMSIC interface CSRs
hw/riscv: virt: Use AIA INTC compatible string when available target/riscv: Allow users to force enable AIA CSRs in HART hw/intc: Add RISC-V AIA APLIC device emulation
Frédéric Pétrot (1):
target/riscv: correct "code should not be reached" for x-rv128
Guo Ren (1):
target/riscv: Ignore reserved bits in PTE for RV64
LIU Zhiwei (1):
target/riscv: Fix vill field write in vtype
Petr Tesarik (1):
Allow setting up to 8 bytes with the generic loader
Philipp Tomsich (7):
target/riscv: refactor (anonymous struct) RISCVCPU.cfg into 'struct RISCVCPUConfig' target/riscv: riscv_tr_init_disas_context: copy pointer-to-cfg into cfg_ptr target/riscv: access configuration through cfg_ptr in DisasContext target/riscv: access cfg structure through DisasContext
target/riscv: iterate over a table of decoders
target/riscv: Add XVentanaCondOps custom extension
target/riscv: add a MAINTAINERS entry for XVentanaCondOps
Weiwei Li (4):
target/riscv: add PTE_A/PTE_D/PTE_U bits check for inner PTE target/riscv: add support for svnapot extension target/riscv: add support for svinval extension target/riscv: add support for svpbmt extension
Wilfred Mallawa (1):
include: hw: remove ibex_plic.h
Yu Li (1):
docs/system: riscv: Update description of CPU
docs/system/riscv/virt.rst | 6 +- include/hw/intc/ibex_plic.h | 67 - include/hw/intc/riscv_aplic.h | 79 ++ target/riscv/cpu.h | 169 ++- target/riscv/cpu_bits.h | 129 ++ target/riscv/XVentanaCondOps.decode | 25 + target/riscv/insn32.decode | 7 + hw/core/generic-loader.c | 2 +- hw/intc/riscv_aplic.c | 978 +++++++++++++++ hw/riscv/virt.c | 13 +- target/riscv/cpu.c | 113 +- target/riscv/cpu_helper.c | 377 +++++- target/riscv/csr.c | 1282 ++++++++++++++++++-- target/riscv/gdbstub.c | 3 + target/riscv/machine.c | 24 +- target/riscv/translate.c | 61 +- target/riscv/vector_helper.c | 1 + target/riscv/insn_trans/trans_rvb.c.inc | 8 +- target/riscv/insn_trans/trans_rvi.c.inc | 2 +- target/riscv/insn_trans/trans_rvv.c.inc | 146 ++- target/riscv/insn_trans/trans_rvzfh.c.inc | 4 +- target/riscv/insn_trans/trans_svinval.c.inc | 75 ++ .../riscv/insn_trans/trans_xventanacondops.c.inc | 39 + MAINTAINERS | 7 + hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + target/riscv/meson.build | 1 + 27 files changed, 3252 insertions(+), 370 deletions(-) delete mode 100644 include/hw/intc/ibex_plic.h create mode 100644 include/hw/intc/riscv_aplic.h create mode 100644 target/riscv/XVentanaCondOps.decode create mode 100644 hw/intc/riscv_aplic.c create mode 100644 target/riscv/insn_trans/trans_svinval.c.inc create mode 100644 target/riscv/insn_trans/trans_xventanacondops.c.inc
[PULL v2 06/35] target/riscv: access configuration through cfg_ptr in DisasContext
From: Philipp Tomsich <[email protected]>
The implementation in trans_{rvi,rvv,rvzfh}.c.inc accesses the shallow copies (in DisasContext) of some of the elements available in the RISCVCPUConfig structure. This commit redirects accesses to use the cfg_ptr copied into DisasContext and removes the shallow copies.
Message-Id: <[email protected]> [ Changes by AF:
- Fixup checkpatch failures
]
--- target/riscv/translate.c | 14 --- target/riscv/insn_trans/trans_rvi.c.inc | 2 +- target/riscv/insn_trans/trans_rvv.c.inc | 146 ++++++++++++++-------- target/riscv/insn_trans/trans_rvzfh.c.inc | 4 +- 4 files changed, 97 insertions(+), 69 deletions(-)
target/riscv/translate.c +0 -14
@@ -77,11 +77,6 @@ typedef struct DisasContext {RISCVMXL ol;bool virt_enabled;const RISCVCPUConfig *cfg_ptr; -bool ext_ifencei; -bool ext_zfh; -bool ext_zfhmin; -bool ext_zve32f; -bool ext_zve64f;bool hlsx;/* vector extension */ bool vill;
@@ -99,8 +94,6 @@ typedef struct DisasContext {*/ int8_t lmul;uint8_t sew; -uint16_t vlen; -uint16_t elen;target_ulong vstart;bool vl_eq_vlmax;uint8_t ntemp;
@@ -910,13 +903,6 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) ctx->misa_ext = env->misa_ext; ctx->frm =-1 ;/* unknown rounding mode */ ctx->cfg_ptr = &(cpu->cfg); - ctx->ext_ifencei = cpu->cfg.ext_ifencei; - ctx->ext_zfh = cpu->cfg.ext_zfh; - ctx->ext_zfhmin = cpu->cfg.ext_zfhmin; - ctx->ext_zve32f = cpu->cfg.ext_zve32f; - ctx->ext_zve64f = cpu->cfg.ext_zve64f; - ctx->vlen = cpu->cfg.vlen; - ctx->elen = cpu->cfg.elen; ctx->mstatus_hs_fs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_FS ); ctx->mstatus_hs_vs =FIELD_EX32 (tb_flags,TB_FLAGS ,MSTATUS_HS_VS ); ctx->hlsx =FIELD_EX32 (tb_flags,TB_FLAGS ,HLSX );
target/riscv/insn_trans/trans_rvi.c.inc +1 -1
@@ -806,7 +806,7 @@ static bool trans_fence(DisasContext *ctx, arg_fence *a) static bool trans_fence_i(DisasContext *ctx, arg_fence_i *a) { - if (!ctx->ext_ifencei) { + if (!ctx->cfg_ptr->ext_ifencei) { return false; }
target/riscv/insn_trans/trans_rvv.c.inc +94 -52
458 lines not on this page · raw message
target/riscv/insn_trans/trans_rvzfh.c.inc +2 -2
@@ -17,13 +17,13 @@ */ #define REQUIRE_ZFH(ctx) do { \ - if (!ctx->ext_zfh) { \ + if (!ctx->cfg_ptr->ext_zfh) { \ return false; \ } \ } while (0) #define REQUIRE_ZFH_OR_ZFHMIN(ctx) do { \ - if (!(ctx->ext_zfh || ctx->ext_zfhmin)) { \ + if (!(ctx->cfg_ptr->ext_zfh || ctx->cfg_ptr->ext_zfhmin)) { \ return false; \ } \ } while (0)
Signature · 1 line
2.34.1
[PULL v2 22/35] target/riscv: Implement AIA hvictl and hviprioX CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA hvictl and hviprioX CSRs allow hypervisor to control interrupts visible at VS-level. This patch implements AIA hvictl and hviprioX CSRs.
Message-id: [email protected] [ Changes by AF:
- Fix possible unintilised variable error in rmw_sie()
]
--- target/riscv/cpu.h | 2 + target/riscv/csr.c | 128 ++++++++++++++++++++++++++++++++++++++++- target/riscv/machine.c | 2 + 3 files changed, 131 insertions(+), 1 deletion(-)
target/riscv/cpu.h +2 -0
@@ -209,6 +209,7 @@ struct CPURISCVState {uint64_t htimedelta;/* Hypervisor controlled virtual interrupt priorities */ +target_ulong hvictl;uint8_t hviprio[64 ];/* Upper 64-bits of 128-bit CSRs */
@@ -512,6 +513,7 @@ static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env) return env->misa_mxl; }#endif +#define riscv_cpu_mxl_bits (env) (1UL << (4 + riscv_cpu_mxl(env)))#if defined(TARGET_RISCV32 )#define cpu_recompute_xl (env) ((void)(env), MXL_RV32)
target/riscv/csr.c +127 -1
167 lines not on this page · raw message
target/riscv/machine.c +2 -0
@@ -92,6 +92,8 @@ static const VMStateDescription vmstate_hyper = {VMSTATE_UINTTL (env.hgeie,RISCVCPU ),VMSTATE_UINTTL (env.hgeip,RISCVCPU ),VMSTATE_UINT64 (env.htimedelta,RISCVCPU ), + +VMSTATE_UINTTL (env.hvictl,RISCVCPU ),VMSTATE_UINT8_ARRAY (env.hviprio,RISCVCPU ,64 ), VMSTATE_UINT64(env.vsstatus, RISCVCPU),
Signature · 1 line
2.34.1
[PULL v2 23/35] target/riscv: Implement AIA interrupt filtering CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA specificaiton adds interrupt filtering support for M-mode and HS-mode. Using AIA interrupt filtering M-mode and H-mode can take local interrupt 13 or above and selectively inject same local interrupt to lower privilege modes.
At the moment, we don't have any local interrupts above 12 so we add dummy implementation (i.e. read zero and ignore write) of AIA interrupt filtering CSRs.
Message-id: [email protected]
--- target/riscv/csr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
target/riscv/csr.c +23 -0
@@ -158,6 +158,15 @@ static RISCVException any32(CPURISCVState *env, int csrno) } +static int aia_any (CPURISCVState *env,int csrno) +{ +if (!riscv_feature (env,RISCV_FEATURE_AIA )) { +return RISCV_EXCP_ILLEGAL_INST ; + } + +return any (env, csrno); +} +static int aia_any32 (CPURISCVState *env,int csrno) {if (!riscv_feature (env,RISCV_FEATURE_AIA )) {
@@ -568,6 +577,12 @@ static RISCVException read_zero(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException write_ignore (CPURISCVState *env,int csrno, +target_ulong val) +{ +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {
@@ -2598,9 +2613,15 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, + /* Virtual Interrupts for Supervisor Level (AIA) */ + [CSR_MVIEN] = { "mvien", aia_any, read_zero, write_ignore }, + [CSR_MVIP] = { "mvip", aia_any, read_zero, write_ignore }, + /* Machine-Level High-Half CSRs (AIA) */ [CSR_MIDELEGH] = { "midelegh", aia_any32, NULL, NULL, rmw_midelegh }, [CSR_MIEH] = { "mieh", aia_any32, NULL, NULL, rmw_mieh }, + [CSR_MVIENH] = { "mvienh", aia_any32, read_zero, write_ignore }, + [CSR_MVIPH] = { "mviph", aia_any32, read_zero, write_ignore }, [CSR_MIPH] = { "miph", aia_any32, NULL, NULL, rmw_miph }, /* Supervisor Trap Setup */
@@ -2654,12 +2675,14 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, /* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ + [CSR_HVIEN] = { "hvien", aia_hmode, read_zero, write_ignore }, [CSR_HVICTL] = { "hvictl", aia_hmode, read_hvictl, write_hvictl }, [CSR_HVIPRIO1] = { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 }, [CSR_HVIPRIO2] = { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 }, /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, + [CSR_HVIENH] = { "hvienh", aia_hmode32, read_zero, write_ignore }, [CSR_HVIPH] = { "hviph", aia_hmode32, NULL, NULL, rmw_hviph }, [CSR_HVIPRIO1H] = { "hviprio1h", aia_hmode32, read_hviprio1h, write_hviprio1h }, [CSR_HVIPRIO2H] = { "hviprio2h", aia_hmode32, read_hviprio2h, write_hviprio2h },
Signature · 1 line
2.34.1
[PULL v2 03/35] target/riscv: correct "code should not be reached" for x-rv128
In reply to Alistair FrancisFrom: Frédéric Pétrot <[email protected]>
The addition of uxl support in gdbstub adds a few checks on the maximum register length, but omitted MXL_RV128, an experimental feature. This patch makes rv128 react as rv64, as previously.
Message-id: [email protected]
--- target/riscv/cpu.c | 3 +-- target/riscv/gdbstub.c | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-)
target/riscv/cpu.c +1 -2
@@ -528,9 +528,8 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)switch (env->misa_mxl_max) {#ifdef TARGET_RISCV64 case MXL_RV64 : - cc->gdb_core_xml_file ="riscv-64bit-cpu.xml" ; -break ;case MXL_RV128 : + cc->gdb_core_xml_file ="riscv-64bit-cpu.xml" ;break ;#endif case MXL_RV32 :
target/riscv/gdbstub.c +3 -0
@@ -64,6 +64,7 @@ int riscv_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)case MXL_RV32 :return gdb_get_reg32 (mem_buf, tmp);case MXL_RV64 : +case MXL_RV128 :return gdb_get_reg64 (mem_buf, tmp);default :g_assert_not_reached ();
@@ -84,6 +85,7 @@ int riscv_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) length =4 ;break ;case MXL_RV64 : +case MXL_RV128 :if (env->xl <MXL_RV64 ) { tmp = (int32_t )ldq_p (mem_buf); }else {
@@ -420,6 +422,7 @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) 1, "riscv-32bit-virtual.xml", 0);break ;case MXL_RV64 : +case MXL_RV128 :gdb_register_coprocessor (cs, riscv_gdb_get_virtual, riscv_gdb_set_virtual,1 ,"riscv-64bit-virtual.xml" ,0 );
Signature · 1 line
2.34.1
[PULL v2 31/35] target/riscv: add PTE_A/PTE_D/PTE_U bits check for inner PTE
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
For non-leaf PTEs, the D, A, and U bits are reserved for future standard use.
Message-Id: <[email protected]>
--- target/riscv/cpu_helper.c | 3 +++ 1 file changed, 3 insertions(+)
target/riscv/cpu_helper.c +3 -0
@@ -937,6 +937,9 @@ restart:return TRANSLATE_FAIL ; }else if (!(pte & (PTE_R |PTE_W |PTE_X ))) {/* Inner PTE, continue walking */ +if (pte & (PTE_D |PTE_A |PTE_U )) { +return TRANSLATE_FAIL ; + } base = ppn <<PGSHIFT ; }else if ((pte & (PTE_R |PTE_W |PTE_X )) ==PTE_W ) {/* Reserved leaf PTE flags: PTE_W */
Signature · 1 line
2.34.1
[PULL v2 05/35] target/riscv: riscv_tr_init_disas_context: copy pointer-to-cfg into cfg_ptr
In reply to Alistair FrancisFrom: Philipp Tomsich <[email protected]>
As the number of extensions is growing, copying them individiually into the DisasContext will scale less and less... instead we populate a pointer to the RISCVCPUConfig structure in the DisasContext.
This adds an extra indirection when checking for the availability of an extension (compared to copying the fields into DisasContext). While not a performance problem today, we can always (shallow) copy the entire structure into the DisasContext (instead of putting a pointer to it) if this is ever deemed necessary.
Message-Id: <[email protected]>
--- target/riscv/translate.c | 2 ++ 1 file changed, 2 insertions(+)
target/riscv/translate.c +2 -0
@@ -76,6 +76,7 @@ typedef struct DisasContext {int frm;RISCVMXL ol;bool virt_enabled; +const RISCVCPUConfig *cfg_ptr;bool ext_ifencei;bool ext_zfh;bool ext_zfhmin;
@@ -908,6 +909,7 @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)#endif ctx->misa_ext = env->misa_ext; ctx->frm =-1 ;/* unknown rounding mode */ + ctx->cfg_ptr = &(cpu->cfg); ctx->ext_ifencei = cpu->cfg.ext_ifencei; ctx->ext_zfh = cpu->cfg.ext_zfh; ctx->ext_zfhmin = cpu->cfg.ext_zfhmin;
Signature · 1 line
2.34.1
[PULL v2 07/35] target/riscv: access cfg structure through DisasContext
In reply to Alistair FrancisFrom: Philipp Tomsich <[email protected]>
The Zb[abcs] support code still uses the RISCV_CPU macros to access the configuration information (i.e., check whether an extension is available/enabled). Now that we provide this information directly from DisasContext, we can access this directly via the cfg_ptr field.
Message-Id: <[email protected]>
--- target/riscv/insn_trans/trans_rvb.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/riscv/insn_trans/trans_rvb.c.inc +4 -4
@@ -19,25 +19,25 @@ */ #define REQUIRE_ZBA(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zba) { \ + if (ctx->cfg_ptr->ext_zba) { \ return false; \ } \ } while (0) #define REQUIRE_ZBB(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbb) { \ + if (ctx->cfg_ptr->ext_zbb) { \ return false; \ } \ } while (0) #define REQUIRE_ZBC(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ + if (ctx->cfg_ptr->ext_zbc) { \ return false; \ } \ } while (0) #define REQUIRE_ZBS(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ + if (ctx->cfg_ptr->ext_zbs) { \ return false; \ } \ } while (0)
Signature · 1 line
2.34.1
Re: [PULL v2 07/35] target/riscv: access cfg structure through DisasContext
Alistair,
This PULL seems not to include the fixup (which you had intended to squash into it) for the regression introduced (i.e. the condition being inverted):
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Without that change this will introduce a regression in Zb[abcs] (i.e., it will be enabled when it shouldn't be, and will be disabled when it should be on).
Please ignore, if I missed a later stand-alone patch (I just looked at the series in Patchworks).
Thanks,
Philipp.
Quoted 55 lines · Alistair Francis
From: Philipp Tomsich <[email protected]>
The Zb[abcs] support code still uses the
RISCV_CPUmacros to access the configuration information (i.e., check whether an extension is available/enabled). Now that we provide this information directly from DisasContext, we can access this directly via thecfg_ptrfield.Signed-off-by Philipp Tomsich <[email protected]>Reviewed-by Alistair Francis <[email protected]>Suggested-by Richard Henderson <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Signed-off-by Alistair Francis <[email protected]>--- target/riscv/insn_trans/trans_rvb.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/riscv/insn_trans/trans_rvb.c.inc +4
-5@@ -19,25 +19,25 @@ */ #define REQUIRE_ZBA(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zba) { \ + if (ctx->cfg_ptr->ext_zba) { \ return false; \ } \ } while (0) #define REQUIRE_ZBB(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbb) { \ + if (ctx->cfg_ptr->ext_zbb) { \ return false; \ } \ } while (0) #define REQUIRE_ZBC(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ + if (ctx->cfg_ptr->ext_zbc) { \ return false; \ } \ } while (0) #define REQUIRE_ZBS(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ + if (ctx->cfg_ptr->ext_zbs) { \ return false; \ } \ } while (0) --2.34.1
Re: [PULL v2 07/35] target/riscv: access cfg structure through DisasContext
Quoted 7 lines · Philipp Tomsich
Alistair,
This PULL seems not to include the fixup (which you had intended to squash into it) for the regression introduced (i.e. the condition being inverted):
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Well....
It does not include it and I'm not really sure why it doesn't. The V1 PR didn't either.
I thought I had applied it, but I guess not. I have actually applied it to riscv-to-apply.next now
Alistair
Quoted 68 lines
Without that change this will introduce a regression in Zb[abcs] (i.e., it will be enabled when it shouldn't be, and will be disabled when it should be on).
Please ignore, if I missed a later stand-alone patch (I just looked at the series in Patchworks).
Thanks,
Philipp.Quoted 55 lines · Alistair Francis
From: Philipp Tomsich <[email protected]>
The Zb[abcs] support code still uses the
RISCV_CPUmacros to access the configuration information (i.e., check whether an extension is available/enabled). Now that we provide this information directly from DisasContext, we can access this directly via thecfg_ptrfield.Signed-off-by Philipp Tomsich <[email protected]>Reviewed-by Alistair Francis <[email protected]>Suggested-by Richard Henderson <[email protected]>Reviewed-by Richard Henderson <[email protected]>Message-Id: <[email protected]>
Signed-off-by Alistair Francis <[email protected]>--- target/riscv/insn_trans/trans_rvb.c.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)target/riscv/insn_trans/trans_rvb.c.inc +4
-5@@ -19,25 +19,25 @@ */ #define REQUIRE_ZBA(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zba) { \ + if (ctx->cfg_ptr->ext_zba) { \ return false; \ } \ } while (0) #define REQUIRE_ZBB(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbb) { \ + if (ctx->cfg_ptr->ext_zbb) { \ return false; \ } \ } while (0) #define REQUIRE_ZBC(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ + if (ctx->cfg_ptr->ext_zbc) { \ return false; \ } \ } while (0) #define REQUIRE_ZBS(ctx) do { \ - if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ + if (ctx->cfg_ptr->ext_zbs) { \ return false; \ } \ } while (0) --2.34.1
[PULL v2 33/35] target/riscv: add support for svinval extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- sinval.vma, hinval.vvma and hinval.gvma do the same as sfence.vma, hfence.vvma and hfence.gvma except extension check
- do nothing other than extension check for sfence.w.inval and sfence.inval.ir
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 1 + target/riscv/insn32.decode | 7 ++ target/riscv/cpu.c | 1 + target/riscv/translate.c | 1 + target/riscv/insn_trans/trans_svinval.c.inc | 75 +++++++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 target/riscv/insn_trans/trans_svinval.c.inc
target/riscv/cpu.h +1 -0
@@ -359,6 +359,7 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_svinval;bool ext_svnapot;bool ext_svpbmt;bool ext_zfh;
target/riscv/insn32.decode +7 -0
@@ -809,3 +809,10 @@ fcvt_l_h 1100010 00010 ..... ... ..... 1010011 @r2_rm fcvt_lu_h 1100010 00011 ..... ... ..... 1010011 @r2_rm fcvt_h_l 1101010 00010 ..... ... ..... 1010011 @r2_rm fcvt_h_lu 1101010 00011 ..... ... ..... 1010011 @r2_rm + +# *** Svinval Standard Extension *** +sinval_vma 0001011 ..... ..... 000 00000 1110011 @sfence_vma +sfence_w_inval 0001100 00000 00000 000 00000 1110011 +sfence_inval_ir 0001100 00001 00000 000 00000 1110011 +hinval_vvma 0010011 ..... ..... 000 00000 1110011 @hfence_vvma +hinval_gvma 0110011 ..... ..... 000 00000 1110011 @hfence_gvma
target/riscv/cpu.c +1 -0
@@ -774,6 +774,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false),DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false), DEFINE_PROP_BOOL("zba", RISCVCPU, cfg.ext_zba, true),
target/riscv/translate.c +1 -0
@@ -862,6 +862,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvb.c.inc" #include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_privileged.c.inc" +#include "insn_trans/trans_svinval.c.inc" #include "insn_trans/trans_xventanacondops.c.inc" /* Include the auto-generated decoder for 16 bit insn */
target/riscv/insn_trans/trans_svinval.c.inc new file +75 -0
75 lines not on this page · raw message
Signature · 1 line
2.34.1
[PULL v2 08/35] target/riscv: iterate over a table of decoders
In reply to Alistair FrancisFrom: Philipp Tomsich <[email protected]>
To split up the decoder into multiple functions (both to support vendor-specific opcodes in separate files and to simplify maintenance of orthogonal extensions), this changes decode_op to iterate over a table of decoders predicated on guard functions.
This commit only adds the new structure and the table, allowing for the easy addition of additional decoders in the future.
Message-Id: <[email protected]>
--- target/riscv/translate.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
target/riscv/translate.c +27 -5
@@ -111,6 +111,11 @@ static inline bool has_ext(DisasContext *ctx, uint32_t ext)return ctx->misa_ext & ext; } +static bool always_true_p (DisasContext *ctx __attribute__((__unused__))) +{ +return true; +} +#ifdef TARGET_RISCV32 #define get_xl (ctx) MXL_RV32#elif defined(CONFIG_USER_ONLY )
@@ -855,15 +860,26 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)static void decode_opc (CPURISCVState *env,DisasContext *ctx,uint16_t opcode) { -/* check for compressed insn */ +/* +* A table with predicate (i.e., guard) functions and decoder functions +* that are tested in-order until a decoder matches onto the opcode. +*/ +static const struct { +bool (*guard_func)(DisasContext *); +bool (*decode_func)(DisasContext *,uint32_t ); + } decoders[] = { + { always_true_p, decode_insn32 }, + }; + +/* Check for compressed insn */ if (extract16 (opcode,0 ,2 ) !=3 ) {if (!has_ext (ctx,RVC )) {gen_exception_illegal (ctx); }else { ctx->opcode = opcode; ctx->pc_succ_insn = ctx->base.pc_next +2 ; -if (!decode_insn16 (ctx, opcode)) { -gen_exception_illegal (ctx); +if (decode_insn16 (ctx, opcode)) { +return ; } } }else {
@@ -873,10 +889,16 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) ctx->base.pc_next + 2)); ctx->opcode = opcode32; ctx->pc_succ_insn = ctx->base.pc_next +4 ; -if (!decode_insn32 (ctx, opcode32)) { -gen_exception_illegal (ctx); + +for (size_t i =0 ; i <ARRAY_SIZE (decoders); ++i) { +if (decoders[i].guard_func (ctx) && + decoders[i].decode_func (ctx, opcode32)) { +return ; + } } } + +gen_exception_illegal (ctx); }static void riscv_tr_init_disas_context (DisasContextBase *dcbase,CPUState *cs)
Signature · 1 line
2.34.1
[PULL v2 01/35] include: hw: remove ibex_plic.h
In reply to Alistair FrancisFrom: Wilfred Mallawa <[email protected]>
This patch removes the left-over/unused ibex_plic.h file. Previously used by opentitan, which now follows the RISC-V standard and uses the SiFivePlicState.
Message-id: [email protected]
--- include/hw/intc/ibex_plic.h | 67 ------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 include/hw/intc/ibex_plic.h
include/hw/intc/ibex_plic.h deleted +0 -67
@@ -1,67 +0,0 @@ -/* -* QEMU RISC-V lowRISC Ibex PLIC -* -* Copyright (c) 2020 Western Digital -* -* This program is free software; you can redistribute it and/or modify it -* under the terms and conditions of the GNU General Public License, -* version 2 or later, as published by the Free Software Foundation. -* -* This program is distributed in the hope it will be useful, but WITHOUT -* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -* more details. -* -* You should have received a copy of the GNU General Public License along with -* this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef HW_IBEX_PLIC_H -#define HW_IBEX_PLIC_H - -#include "hw/sysbus.h" -#include "qom/object.h" - -#define TYPE_IBEX_PLIC "ibex-plic" -OBJECT_DECLARE_SIMPLE_TYPE(IbexPlicState, IBEX_PLIC) - -struct IbexPlicState { -/*< private >*/ -SysBusDevice parent_obj; - -/*< public >*/ -MemoryRegion mmio; - -uint32_t *pending; -uint32_t *hidden_pending; -uint32_t *claimed; -uint32_t *source; -uint32_t *priority; -uint32_t *enable; -uint32_t threshold; -uint32_t claim; - -/* config */ -uint32_t num_cpus; -uint32_t num_sources; - -uint32_t pending_base; -uint32_t pending_num; - -uint32_t source_base; -uint32_t source_num; - -uint32_t priority_base; -uint32_t priority_num; - -uint32_t enable_base; -uint32_t enable_num; - -uint32_t threshold_base; - -uint32_t claim_base; - -qemu_irq *external_irqs; -}; - -#endif /* HW_IBEX_PLIC_H */
Signature · 1 line
2.34.1
[PULL v2 11/35] target/riscv: Fix vill field write in vtype
In reply to Alistair FrancisFrom: LIU Zhiwei <[email protected]>
The guest should be able to set the vill bit as part of vsetvl.
Currently we may set env->vill to 1 in the vsetvl helper, but there is nowhere that we set it to 0, so once it transitions to 1 it's stuck there until the system is reset.
Message-Id: <[email protected]>
--- target/riscv/vector_helper.c | 1 + 1 file changed, 1 insertion(+)
target/riscv/vector_helper.c +1 -0
@@ -71,6 +71,7 @@ target_ulong HELPER(vsetvl)(CPURISCVState *env, target_ulong s1, env->vl = vl; env->vtype = s2; env->vstart =0 ; + env->vill =0 ;return vl; }
Signature · 1 line
2.34.1
[PULL v2 13/35] target/riscv: Implement SGEIP bit in hip and hie CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
A hypervisor can optionally take guest external interrupts using SGEIP bit of hip and hie CSRs.
Message-id: [email protected]
--- target/riscv/cpu_bits.h | 3 +++ target/riscv/cpu.c | 3 ++- target/riscv/csr.c | 18 +++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-)
target/riscv/cpu_bits.h +3 -0
@@ -540,6 +540,8 @@ typedef enum RISCVException {#define IRQ_S_EXT 9#define IRQ_VS_EXT 10#define IRQ_M_EXT 11 +#define IRQ_S_GEXT 12 +#define IRQ_LOCAL_MAX 16/* mip masks */ #define MIP_USIP (1 << IRQ_U_SOFT)
@@ -554,6 +556,7 @@ typedef enum RISCVException {#define MIP_SEIP (1 << IRQ_S_EXT)#define MIP_VSEIP (1 << IRQ_VS_EXT)#define MIP_MEIP (1 << IRQ_M_EXT) +#define MIP_SGEIP (1 << IRQ_S_GEXT)/* sip masks */ #define SIP_SSIP MIP_SSIP
target/riscv/cpu.c +2 -1
@@ -434,6 +434,7 @@ static void riscv_cpu_reset(DeviceState *dev) } } env->mcause =0 ; + env->miclaim =MIP_SGEIP ; env->pc = env->resetvec; env->two_stage_lookup = false;/* mmte is supposed to have pm.current hardwired to 1 */
@@ -695,7 +696,7 @@ static void riscv_cpu_init(Object *obj)cpu_set_cpustate_pointers (cpu);#ifndef CONFIG_USER_ONLY -qdev_init_gpio_in (DEVICE (cpu), riscv_cpu_set_irq,12 ); +qdev_init_gpio_in (DEVICE (cpu), riscv_cpu_set_irq,IRQ_LOCAL_MAX );#endif /* CONFIG_USER_ONLY */ }
target/riscv/csr.c +11 -7
@@ -461,12 +461,13 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno,#define M_MODE_INTERRUPTS (MIP_MSIP | MIP_MTIP | MIP_MEIP)#define S_MODE_INTERRUPTS (MIP_SSIP | MIP_STIP | MIP_SEIP)#define VS_MODE_INTERRUPTS (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP) +#define HS_MODE_INTERRUPTS (MIP_SGEIP | VS_MODE_INTERRUPTS)static const target_ulong delegable_ints =S_MODE_INTERRUPTS |VS_MODE_INTERRUPTS ;static const target_ulong vs_delegable_ints =VS_MODE_INTERRUPTS ;static const target_ulong all_ints =M_MODE_INTERRUPTS |S_MODE_INTERRUPTS | -VS_MODE_INTERRUPTS ; +HS_MODE_INTERRUPTS ;#define DELEGABLE_EXCPS ((1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | \ (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | \ (1ULL << (RISCV_EXCP_ILLEGAL_INST)) | \
@@ -748,7 +749,7 @@ static RISCVException write_mideleg(CPURISCVState *env, int csrno, { env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints);if (riscv_has_ext (env,RVH )) { - env->mideleg |=VS_MODE_INTERRUPTS ; + env->mideleg |=HS_MODE_INTERRUPTS ; }return RISCV_EXCP_NONE ; }
@@ -764,6 +765,9 @@ static RISCVException write_mie(CPURISCVState *env, int csrno, target_ulong val) { env->mie = (env->mie & ~all_ints) | (val & all_ints); +if (!riscv_has_ext (env,RVH )) { + env->mie &= ~MIP_SGEIP ; + }return RISCV_EXCP_NONE ; }
@@ -1110,7 +1114,7 @@ static RISCVException rmw_sip(CPURISCVState *env, int csrno, }if (ret_value) { - *ret_value &= env->mideleg; + *ret_value &= env->mideleg &S_MODE_INTERRUPTS ; }return ret; }
@@ -1228,7 +1232,7 @@ static RISCVException rmw_hvip(CPURISCVState *env, int csrno, write_mask & hvip_writable_mask);if (ret_value) { - *ret_value &= hvip_writable_mask; + *ret_value &=VS_MODE_INTERRUPTS ; }return ret; }
@@ -1241,7 +1245,7 @@ static RISCVException rmw_hip(CPURISCVState *env, int csrno, write_mask & hip_writable_mask);if (ret_value) { - *ret_value &= hip_writable_mask; + *ret_value &=HS_MODE_INTERRUPTS ; }return ret; }
@@ -1249,14 +1253,14 @@ static RISCVException rmw_hip(CPURISCVState *env, int csrno,static RISCVException read_hie (CPURISCVState *env,int csrno,target_ulong *val) { - *val = env->mie &VS_MODE_INTERRUPTS ; + *val = env->mie &HS_MODE_INTERRUPTS ;return RISCV_EXCP_NONE ; }static RISCVException write_hie (CPURISCVState *env,int csrno,target_ulong val) { -target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS ) | (val &VS_MODE_INTERRUPTS ); +target_ulong newval = (env->mie & ~HS_MODE_INTERRUPTS ) | (val &HS_MODE_INTERRUPTS );return write_mie (env,CSR_MIE , newval); }
Signature · 1 line
2.34.1
[PULL v2 02/35] Allow setting up to 8 bytes with the generic loader
In reply to Alistair FrancisFrom: Petr Tesarik <[email protected]>
The documentation for the generic loader says that "the maximum size of the data is 8 bytes". However, attempts to set data-len=8 trigger the following assertion failure:
../hw/core/generic-loader.c:59: generic_loader_reset: Assertion `s->data_len < sizeof(s->data)' failed.
The type of s->data is uint64_t (i.e. 8 bytes long), so I believe this assert should use <= instead of <.
Message-id: [email protected]
--- hw/core/generic-loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/core/generic-loader.c +1 -1
@@ -56,7 +56,7 @@ static void generic_loader_reset(void *opaque) }if (s->data_len) { -assert (s->data_len <sizeof (s->data)); +assert (s->data_len <=sizeof (s->data));dma_memory_write (s->cpu->as, s->addr, &s->data, s->data_len,MEMTXATTRS_UNSPECIFIED ); }
Signature · 1 line
2.34.1
[PULL v2 04/35] target/riscv: refactor (anonymous struct) RISCVCPU.cfg into 'struct RISCVCPUConfig'
In reply to Alistair FrancisFrom: Philipp Tomsich <[email protected]>
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 78 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 37 deletions(-)
target/riscv/cpu.h +41 -37
@@ -303,6 +303,46 @@ struct RISCVCPUClass {DeviceReset parent_reset; }; +struct RISCVCPUConfig { +bool ext_i; +bool ext_e; +bool ext_g; +bool ext_m; +bool ext_a; +bool ext_f; +bool ext_d; +bool ext_c; +bool ext_s; +bool ext_u; +bool ext_h; +bool ext_j; +bool ext_v; +bool ext_zba; +bool ext_zbb; +bool ext_zbc; +bool ext_zbs; +bool ext_counters; +bool ext_ifencei; +bool ext_icsr; +bool ext_zfh; +bool ext_zfhmin; +bool ext_zve32f; +bool ext_zve64f; + +char *priv_spec; +char *user_spec; +char *bext_spec; +char *vext_spec; +uint16_t vlen; +uint16_t elen; +bool mmu; +bool pmp; +bool epmp; +uint64_t resetvec; +}; + +typedef struct RISCVCPUConfig RISCVCPUConfig ; +/** * RISCVCPU: * @env: #CPURISCVState
@@ -320,43 +360,7 @@ struct RISCVCPU {char *dyn_vreg_xml;/* Configuration Settings */ -struct { -bool ext_i; -bool ext_e; -bool ext_g; -bool ext_m; -bool ext_a; -bool ext_f; -bool ext_d; -bool ext_c; -bool ext_s; -bool ext_u; -bool ext_h; -bool ext_j; -bool ext_v; -bool ext_zba; -bool ext_zbb; -bool ext_zbc; -bool ext_zbs; -bool ext_counters; -bool ext_ifencei; -bool ext_icsr; -bool ext_zfh; -bool ext_zfhmin; -bool ext_zve32f; -bool ext_zve64f; - -char *priv_spec; -char *user_spec; -char *bext_spec; -char *vext_spec; -uint16_t vlen; -uint16_t elen; -bool mmu; -bool pmp; -bool epmp; -uint64_t resetvec; - } cfg; +RISCVCPUConfig cfg; };static inline int riscv_has_ext (CPURISCVState *env,target_ulong ext)
Signature · 1 line
2.34.1
[PULL v2 12/35] target/riscv: Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
We should be returning illegal instruction trap when RV64 HS-mode tries to access RV32 HS-mode CSR.
Message-id: [email protected]
--- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/csr.c +1 -1
@@ -186,7 +186,7 @@ static RISCVException hmode(CPURISCVState *env, int csrno)static RISCVException hmode32 (CPURISCVState *env,int csrno) {if (riscv_cpu_mxl (env) !=MXL_RV32 ) { -if (riscv_cpu_virt_enabled (env)) { +if (!riscv_cpu_virt_enabled (env)) {return RISCV_EXCP_ILLEGAL_INST ; }else {return RISCV_EXCP_VIRT_INSTRUCTION_FAULT ;
Signature · 1 line
2.34.1
[PULL v2 24/35] target/riscv: Implement AIA mtopi, stopi, and vstopi CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA specification introduces new [m|s|vs]topi CSRs for reporting pending local IRQ number and associated IRQ priority.
Message-id: [email protected] [ Changed by AF:
- Fixup indentation
]
--- target/riscv/csr.c | 156 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+)
target/riscv/csr.c +156 -0
@@ -194,6 +194,15 @@ static int smode32(CPURISCVState *env, int csrno)return smode (env, csrno); } +static int aia_smode (CPURISCVState *env,int csrno) +{ +if (!riscv_feature (env,RISCV_FEATURE_AIA )) { +return RISCV_EXCP_ILLEGAL_INST ; + } + +return smode (env, csrno); +} +static int aia_smode32 (CPURISCVState *env,int csrno) {if (!riscv_feature (env,RISCV_FEATURE_AIA )) {
@@ -517,6 +526,8 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno,#define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP))#define HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS)) +#define VSTOPI_NUM_SRCS 5 +static const uint64_t delegable_ints =S_MODE_INTERRUPTS |VS_MODE_INTERRUPTS ;static const uint64_t vs_delegable_ints =VS_MODE_INTERRUPTS ;
@@ -898,6 +909,28 @@ static RISCVException rmw_mieh(CPURISCVState *env, int csrno,return ret; } +static int read_mtopi (CPURISCVState *env,int csrno,target_ulong *val) +{ +int irq; +uint8_t iprio; + + irq =riscv_cpu_mirq_pending (env); +if (irq <=0 || irq >63 ) { + *val =0 ; + }else { + iprio = env->miprio[irq]; +if (!iprio) { +if (riscv_cpu_default_priority (irq) >IPRIO_DEFAULT_M ) { + iprio =IPRIO_MMAXIPRIO ; + } + } + *val = (irq &TOPI_IID_MASK ) <<TOPI_IID_SHIFT ; + *val |= iprio; + } + +return RISCV_EXCP_NONE ; +} +static RISCVException read_mtvec (CPURISCVState *env,int csrno,target_ulong *val) {
@@ -1478,6 +1511,120 @@ static RISCVException write_satp(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static int read_vstopi (CPURISCVState *env,int csrno,target_ulong *val) +{ +int irq, ret; +target_ulong topei; +uint64_t vseip, vsgein; +uint32_t iid, iprio, hviid, hviprio, gein; +uint32_t s, scount =0 , siid[VSTOPI_NUM_SRCS ], siprio[VSTOPI_NUM_SRCS ]; + + gein =get_field (env->hstatus,HSTATUS_VGEIN ); + hviid =get_field (env->hvictl,HVICTL_IID ); + hviprio =get_field (env->hvictl,HVICTL_IPRIO ); + +if (gein) { + vsgein = (env->hgeip & (1ULL << gein)) ?MIP_VSEIP :0 ; + vseip = env->mie & (env->mip | vsgein) &MIP_VSEIP ; +if (gein <= env->geilen && vseip) { + siid[scount] =IRQ_S_EXT ; + siprio[scount] =IPRIO_MMAXIPRIO +1 ; +if (env->aia_ireg_rmw_fn[PRV_S ]) { +/* +* Call machine specific IMSIC register emulation for +* reading TOPEI. +*/ + ret = env->aia_ireg_rmw_fn[PRV_S ]( + env->aia_ireg_rmw_fn_arg[PRV_S ], +AIA_MAKE_IREG (ISELECT_IMSIC_TOPEI ,PRV_S , true, gein, +riscv_cpu_mxl_bits (env)), + &topei,0 ,0 ); +if (!ret && topei) { + siprio[scount] = topei &IMSIC_TOPEI_IPRIO_MASK ; + } + } + scount++; + } + }else { +if (hviid ==IRQ_S_EXT && hviprio) { + siid[scount] =IRQ_S_EXT ; + siprio[scount] = hviprio; + scount++; + } + } + +if (env->hvictl &HVICTL_VTI ) { +if (hviid !=IRQ_S_EXT ) { + siid[scount] = hviid; + siprio[scount] = hviprio; + scount++; + } + }else { + irq =riscv_cpu_vsirq_pending (env); +if (irq !=IRQ_S_EXT &&0 < irq && irq <=63 ) { + siid[scount] = irq; + siprio[scount] = env->hviprio[irq]; + scount++; + } + } + + iid =0 ; + iprio =UINT_MAX ; +for (s =0 ; s < scount; s++) { +if (siprio[s] < iprio) { + iid = siid[s]; + iprio = siprio[s]; + } + } + +if (iid) { +if (env->hvictl &HVICTL_IPRIOM ) { +if (iprio >IPRIO_MMAXIPRIO ) { + iprio =IPRIO_MMAXIPRIO ; + } +if (!iprio) { +if (riscv_cpu_default_priority (iid) >IPRIO_DEFAULT_S ) { + iprio =IPRIO_MMAXIPRIO ; + } + } + }else { + iprio =1 ; + } + }else { + iprio =0 ; + } + + *val = (iid &TOPI_IID_MASK ) <<TOPI_IID_SHIFT ; + *val |= iprio; +return RISCV_EXCP_NONE ; +} + +static int read_stopi (CPURISCVState *env,int csrno,target_ulong *val) +{ +int irq; +uint8_t iprio; + +if (riscv_cpu_virt_enabled (env)) { +return read_vstopi (env,CSR_VSTOPI , val); + } + + irq =riscv_cpu_sirq_pending (env); +if (irq <=0 || irq >63 ) { + *val =0 ; + }else { + iprio = env->siprio[irq]; +if (!iprio) { +if (riscv_cpu_default_priority (irq) >IPRIO_DEFAULT_S ) { + iprio =IPRIO_MMAXIPRIO ; + } + } + *val = (irq &TOPI_IID_MASK ) <<TOPI_IID_SHIFT ; + *val |= iprio; + } + +return RISCV_EXCP_NONE ; +} +/* Hypervisor Extensions */ static RISCVException read_hstatus (CPURISCVState *env,int csrno,target_ulong *val)
@@ -2613,6 +2760,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, + /* Machine-Level Interrupts (AIA) */ + [CSR_MTOPI] = { "mtopi", aia_any, read_mtopi }, + /* Virtual Interrupts for Supervisor Level (AIA) */ [CSR_MVIEN] = { "mvien", aia_any, read_zero, write_ignore }, [CSR_MVIP] = { "mvip", aia_any, read_zero, write_ignore },
@@ -2642,6 +2792,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Supervisor Protection and Translation */ [CSR_SATP] = { "satp", smode, read_satp, write_satp }, + /* Supervisor-Level Interrupts (AIA) */ + [CSR_STOPI] = { "stopi", aia_smode, read_stopi }, + /* Supervisor-Level High-Half CSRs (AIA) */ [CSR_SIEH] = { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, [CSR_SIPH] = { "siph", aia_smode32, NULL, NULL, rmw_siph },
@@ -2680,6 +2833,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_HVIPRIO1] = { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 }, [CSR_HVIPRIO2] = { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 }, + /* VS-Level Interrupts (H-extension with AIA) */ + [CSR_VSTOPI] = { "vstopi", aia_hmode, read_vstopi }, + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, [CSR_HVIENH] = { "hvienh", aia_hmode32, read_zero, write_ignore },
Signature · 1 line
2.34.1
[PULL v2 14/35] target/riscv: Implement hgeie and hgeip CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The hgeie and hgeip CSRs are required for emulating an external interrupt controller capable of injecting virtual external interrupt to Guest/VM running at VS-level.
Message-id: [email protected]
--- target/riscv/cpu.h | 5 +++ target/riscv/cpu_bits.h | 1 + target/riscv/cpu.c | 67 +++++++++++++++++++++++++++------------ target/riscv/cpu_helper.c | 37 +++++++++++++++++++-- target/riscv/csr.c | 43 +++++++++++++++++-------- target/riscv/machine.c | 6 ++-- 6 files changed, 121 insertions(+), 38 deletions(-)
target/riscv/cpu.h +5 -0
@@ -161,6 +161,7 @@ struct CPURISCVState {target_ulong priv;/* This contains QEMU specific information about the virt state. */ target_ulong virt; +target_ulong geilen;target_ulong resetvec;target_ulong mhartid;
@@ -198,6 +199,8 @@ struct CPURISCVState {target_ulong htval;target_ulong htinst;target_ulong hgatp; +target_ulong hgeie; +target_ulong hgeip;uint64_t htimedelta;/* Upper 64-bits of 128-bit CSRs */
@@ -391,6 +394,8 @@ int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,int riscv_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int riscv_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);bool riscv_cpu_fp_enabled (CPURISCVState *env); +target_ulong riscv_cpu_get_geilen (CPURISCVState *env); +void riscv_cpu_set_geilen (CPURISCVState *env,target_ulong geilen);bool riscv_cpu_vector_enabled (CPURISCVState *env);bool riscv_cpu_virt_enabled (CPURISCVState *env);void riscv_cpu_set_virt_enabled (CPURISCVState *env,bool enable);
target/riscv/cpu_bits.h +1 -0
@@ -542,6 +542,7 @@ typedef enum RISCVException {#define IRQ_M_EXT 11#define IRQ_S_GEXT 12#define IRQ_LOCAL_MAX 16 +#define IRQ_LOCAL_GUEST_MAX (TARGET_LONG_BITS - 1)/* mip masks */ #define MIP_USIP (1 << IRQ_U_SOFT)
target/riscv/cpu.c +47 -20
81 lines not on this page · raw message
target/riscv/cpu_helper.c +34 -3
@@ -159,7 +159,11 @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env)target_ulong mstatus_mie =get_field (env->mstatus,MSTATUS_MIE );target_ulong mstatus_sie =get_field (env->mstatus,MSTATUS_SIE ); -target_ulong pending = env->mip & env->mie; +target_ulong vsgemask = + (target_ulong )1 <<get_field (env->hstatus,HSTATUS_VGEIN ); +target_ulong vsgein = (env->hgeip & vsgemask) ?MIP_VSEIP :0 ; + +target_ulong pending = (env->mip | vsgein) & env->mie;target_ulong mie = env->priv <PRV_M || (env->priv ==PRV_M && mstatus_mie);
@@ -279,6 +283,28 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) } } +target_ulong riscv_cpu_get_geilen (CPURISCVState *env) +{ +if (!riscv_has_ext (env,RVH )) { +return 0 ; + } + +return env->geilen; +} + +void riscv_cpu_set_geilen (CPURISCVState *env,target_ulong geilen) +{ +if (!riscv_has_ext (env,RVH )) { +return ; + } + +if (geilen > (TARGET_LONG_BITS -1 )) { +return ; + } + + env->geilen = geilen; +} +bool riscv_cpu_virt_enabled (CPURISCVState *env) {if (!riscv_has_ext (env,RVH )) {
@@ -322,9 +348,14 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) {CPURISCVState *env = &cpu->env;CPUState *cs =CPU (cpu); -uint32_t old = env->mip; +uint32_t gein, vsgein =0 , old = env->mip;bool locked = false; +if (riscv_cpu_virt_enabled (env)) { + gein =get_field (env->hstatus,HSTATUS_VGEIN ); + vsgein = (env->hgeip & (1ULL << gein)) ?MIP_VSEIP :0 ; + } +if (!qemu_mutex_iothread_locked ()) { locked = true;qemu_mutex_lock_iothread ();
@@ -332,7 +363,7 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) env->mip = (env->mip & ~mask) | (value & mask); -if (env->mip) { +if (env->mip | vsgein) {cpu_interrupt (cs,CPU_INTERRUPT_HARD ); }else {cpu_reset_interrupt (cs,CPU_INTERRUPT_HARD );
target/riscv/csr.c +30 -13
107 lines not on this page · raw message
target/riscv/machine.c +4 -2
@@ -78,8 +78,8 @@ static bool hyper_needed(void *opaque)static const VMStateDescription vmstate_hyper = { .name ="cpu/hyper" , - .version_id =1 , - .minimum_version_id =1 , + .version_id =2 , + .minimum_version_id =2 , .needed = hyper_needed, .fields = (VMStateField []) {VMSTATE_UINTTL (env.hstatus,RISCVCPU ),
@@ -89,6 +89,8 @@ static const VMStateDescription vmstate_hyper = {VMSTATE_UINTTL (env.htval,RISCVCPU ),VMSTATE_UINTTL (env.htinst,RISCVCPU ),VMSTATE_UINTTL (env.hgatp,RISCVCPU ), +VMSTATE_UINTTL (env.hgeie,RISCVCPU ), +VMSTATE_UINTTL (env.hgeip,RISCVCPU ),VMSTATE_UINT64 (env.htimedelta,RISCVCPU ), VMSTATE_UINT64(env.vsstatus, RISCVCPU),
Signature · 1 line
2.34.1
[PULL v2 34/35] target/riscv: add support for svpbmt extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add PTE_PBMT bits: It uses two PTE bits, but otherwise has no effect on QEMU, since QEMU is sequentially consistent and doesn't model PMAs currently
- add PTE_PBMT bit check for inner PTE
Message-Id: <[email protected]>
--- target/riscv/cpu_bits.h | 2 ++ target/riscv/cpu.c | 1 + target/riscv/cpu_helper.c | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-)
target/riscv/cpu_bits.h +2 -0
@@ -561,7 +561,9 @@ typedef enum {#define PTE_A 0x040/* Accessed */ #define PTE_D 0x080/* Dirty */ #define PTE_SOFT 0x300/* Reserved for Software */ +#define PTE_PBMT 0x6000000000000000ULL/* Page-based memory types */ #define PTE_N 0x8000000000000000ULL/* NAPOT translation */ +#define PTE_ATTR (PTE_N | PTE_PBMT)/* All attributes bits */ /* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10
target/riscv/cpu.c +1 -0
@@ -776,6 +776,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false),DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false), +DEFINE_PROP_BOOL ("svpbmt" ,RISCVCPU , cfg.ext_svpbmt, false),DEFINE_PROP_BOOL ("zba" ,RISCVCPU , cfg.ext_zba, true), DEFINE_PROP_BOOL("zbb", RISCVCPU, cfg.ext_zbb, true),
target/riscv/cpu_helper.c +3 -1
@@ -937,9 +937,11 @@ restart:if (!(pte &PTE_V )) {/* Invalid PTE */ return TRANSLATE_FAIL ; + }else if (!cpu->cfg.ext_svpbmt && (pte &PTE_PBMT )) { +return TRANSLATE_FAIL ; }else if (!(pte & (PTE_R |PTE_W |PTE_X ))) {/* Inner PTE, continue walking */ -if (pte & (PTE_D |PTE_A |PTE_U |PTE_N )) { +if (pte & (PTE_D |PTE_A |PTE_U |PTE_ATTR )) {return TRANSLATE_FAIL ; } base = ppn <<PGSHIFT ;
Signature · 1 line
2.34.1
[PULL v2 09/35] target/riscv: Add XVentanaCondOps custom extension
In reply to Alistair FrancisFrom: Philipp Tomsich <[email protected]>
This adds the decoder and translation for the XVentanaCondOps custom
extension (vendor-defined by Ventana Micro Systems), which is
documented at https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf
This commit then also adds a guard-function (has_XVentanaCondOps_p) and the decoder function to the table of decoders, enabling the support for the XVentanaCondOps extension.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 3 ++ target/riscv/XVentanaCondOps.decode | 25 ++++++++++++ target/riscv/cpu.c | 3 ++ target/riscv/translate.c | 12 ++++++ .../insn_trans/trans_xventanacondops.c.inc | 39 +++++++++++++++++++ target/riscv/meson.build | 1 + 6 files changed, 83 insertions(+) create mode 100644 target/riscv/XVentanaCondOps.decode create mode 100644 target/riscv/insn_trans/trans_xventanacondops.c.inc
target/riscv/cpu.h +3 -0
@@ -329,6 +329,9 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +/* Vendor-specific custom extensions */ +bool ext_XVentanaCondOps; +char *priv_spec;char *user_spec;char *bext_spec;
target/riscv/XVentanaCondOps.decode new file +25 -0
@@ -0,0 +1,25 @@ +# +# RISC-V translation routines for the XVentanaCondOps extension +# +# Copyright (c) 2022 Dr. Philipp Tomsich, [email protected] +# +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# Reference: VTx-family custom instructions +# Custom ISA extensions for Ventana Micro Systems RISC-V cores +# (https://github.com/ventanamicro/ventana-custom-extensions/releases/download/v1.0.0/ventana-custom-extensions-v1.0.0.pdf) + +# Fields +%rs2 20:5 +%rs1 15:5 +%rd 7:5 + +# Argument sets +&r rd rs1 rs2 !extern + +# Formats +@r ....... ..... ..... ... ..... ....... &r %rs2 %rs1 %rd + +# *** RV64 Custom-3 Extension *** +vt_maskc 0000000 ..... ..... 110 ..... 1111011 @r +vt_maskcn 0000000 ..... ..... 111 ..... 1111011 @r
target/riscv/cpu.c +3 -0
@@ -733,6 +733,9 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("zbc" ,RISCVCPU , cfg.ext_zbc, true),DEFINE_PROP_BOOL ("zbs" ,RISCVCPU , cfg.ext_zbs, true), +/* Vendor-specific custom extensions */ +DEFINE_PROP_BOOL ("xventanacondops" ,RISCVCPU , cfg.ext_XVentanaCondOps, false), +/* These are experimental so mark with 'x-' */ DEFINE_PROP_BOOL("x-j", RISCVCPU, cfg.ext_j, false),/* ePMP 0.9.3 */
target/riscv/translate.c +12 -0
@@ -116,6 +116,14 @@ static bool always_true_p(DisasContext *ctx __attribute__((__unused__)))return true; } +#define MATERIALISE_EXT_PREDICATE (ext) \ + static bool has_ ## ext ## _p(DisasContext *ctx) \ + { \ + return ctx->cfg_ptr->ext_ ## ext ; \ + } + +MATERIALISE_EXT_PREDICATE (XVentanaCondOps); +#ifdef TARGET_RISCV32 #define get_xl (ctx) MXL_RV32#elif defined(CONFIG_USER_ONLY )
@@ -854,9 +862,12 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvb.c.inc" #include "insn_trans/trans_rvzfh.c.inc" #include "insn_trans/trans_privileged.c.inc" +#include "insn_trans/trans_xventanacondops.c.inc" /* Include the auto-generated decoder for 16 bit insn */ #include "decode-insn16.c.inc" +/* Include decoders for factored-out extensions */ +#include "decode-XVentanaCondOps.c.inc" static void decode_opc (CPURISCVState *env,DisasContext *ctx,uint16_t opcode) {
@@ -869,6 +880,7 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)bool (*decode_func)(DisasContext *,uint32_t ); } decoders[] = { { always_true_p, decode_insn32 }, + { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, }; /* Check for compressed insn */
target/riscv/insn_trans/trans_xventanacondops.c.inc new file +39 -0
@@ -0,0 +1,39 @@ +/* + * RISC-V translation routines for the XVentanaCondOps extension. + * + * Copyright (c) 2021-2022 VRULL GmbH. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ + +static bool gen_vt_condmask(DisasContext *ctx, arg_r *a, TCGCond cond) +{ + TCGv dest = dest_gpr(ctx, a->rd); + TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); + TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); + + tcg_gen_movcond_tl(cond, dest, src2, ctx->zero, src1, ctx->zero); + + gen_set_gpr(ctx, a->rd, dest); + return true; +} + +static bool trans_vt_maskc(DisasContext *ctx, arg_r *a) +{ + return gen_vt_condmask(ctx, a, TCG_COND_NE); +} + +static bool trans_vt_maskcn(DisasContext *ctx, arg_r *a) +{ + return gen_vt_condmask(ctx, a, TCG_COND_EQ); +}
target/riscv/meson.build +1 -0
@@ -4,6 +4,7 @@ dir = meson.current_source_dir() gen = [ decodetree.process('insn16.decode', extra_args: ['--static-decode=decode_insn16', '--insnwidth=16']), decodetree.process('insn32.decode', extra_args: '--static-decode=decode_insn32'), + decodetree.process('XVentanaCondOps.decode', extra_args: '--static-decode=decode_XVentanaCodeOps'), ] riscv_ss = ss.source_set()
Signature · 1 line
2.34.1
[PULL v2 17/35] target/riscv: Add AIA cpu feature
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
We define a CPU feature for AIA CSR support in RISC-V CPUs which can be set by machine/device emulation. The RISC-V CSR emulation will also check this feature for emulating AIA CSRs.
Message-id: [email protected]
--- target/riscv/cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/riscv/cpu.h +2 -1
@@ -78,7 +78,8 @@ enum {RISCV_FEATURE_MMU ,RISCV_FEATURE_PMP ,RISCV_FEATURE_EPMP , - RISCV_FEATURE_MISA +RISCV_FEATURE_MISA , + RISCV_FEATURE_AIA };#define PRIV_VERSION_1_10_0 0x00011000
Signature · 1 line
2.34.1
[PULL v2 10/35] target/riscv: add a MAINTAINERS entry for XVentanaCondOps
In reply to Alistair FrancisFrom: Philipp Tomsich <[email protected]>
The XVentanaCondOps extension is supported by VRULL on behalf of the Ventana Micro. Add myself as a point-of-contact.
Message-Id: <[email protected]>
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -286,6 +286,13 @@ F: include/hw/riscv/ F: linux-user/host/riscv32/ F: linux-user/host/riscv64/ +RISC-V XVentanaCondOps extension +M: Philipp Tomsich <[email protected]> +L: [email protected] +S: Supported +F: target/riscv/XVentanaCondOps.decode +F: target/riscv/insn_trans/trans_xventanacondops.c.inc + RENESAS RX CPUs R: Yoshinori Sato <[email protected]> S: Orphan
Signature · 1 line
2.34.1
[PULL v2 19/35] target/riscv: Allow AIA device emulation to set ireg rmw callback
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA device emulation (such as AIA IMSIC) should be able to set (or provide) AIA ireg read-modify-write callback for each privilege level of a RISC-V HART.
Message-id: [email protected]
--- target/riscv/cpu.h | 23 +++++++++++++++++++++++ target/riscv/cpu_helper.c | 14 ++++++++++++++ 2 files changed, 37 insertions(+)
target/riscv/cpu.h +23 -0
@@ -256,6 +256,22 @@ struct CPURISCVState {uint64_t (*rdtime_fn)(uint32_t );uint32_t rdtime_fn_arg; +/* machine specific AIA ireg read-modify-write callback */ +#define AIA_MAKE_IREG (__isel, __priv, __virt, __vgein, __xlen) \ + ((((__xlen) & 0xff) << 24) | \ + (((__vgein) & 0x3f) << 20) | \ + (((__virt) & 0x1) << 18) | \ + (((__priv) & 0x3) << 16) | \ + (__isel & 0xffff)) +#define AIA_IREG_ISEL (__ireg) ((__ireg) & 0xffff) +#define AIA_IREG_PRIV (__ireg) (((__ireg) >> 16) & 0x3) +#define AIA_IREG_VIRT (__ireg) (((__ireg) >> 18) & 0x1) +#define AIA_IREG_VGEIN (__ireg) (((__ireg) >> 20) & 0x3f) +#define AIA_IREG_XLEN (__ireg) (((__ireg) >> 24) & 0xff) +int (*aia_ireg_rmw_fn[4 ])(void *arg,target_ulong reg, +target_ulong *val,target_ulong new_val,target_ulong write_mask); +void *aia_ireg_rmw_fn_arg[4 ]; +/* True if in debugger mode. */ bool debugger;
@@ -433,6 +449,13 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value);#define BOOL_TO_MASK (x) (-!!(x))/* helper for riscv_cpu_update_mip value */ void riscv_cpu_set_rdtime_fn (CPURISCVState *env,uint64_t (*fn)(uint32_t ),uint32_t arg); +void riscv_cpu_set_aia_ireg_rmw_fn (CPURISCVState *env,uint32_t priv, +int (*rmw_fn)(void *arg, +target_ulong reg, +target_ulong *val, +target_ulong new_val, +target_ulong write_mask), +void *rmw_fn_arg);#endif void riscv_cpu_set_mode (CPURISCVState *env,target_ulong newpriv);
target/riscv/cpu_helper.c +14 -0
@@ -396,6 +396,20 @@ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), env->rdtime_fn_arg = arg; } +void riscv_cpu_set_aia_ireg_rmw_fn (CPURISCVState *env,uint32_t priv, +int (*rmw_fn)(void *arg, +target_ulong reg, +target_ulong *val, +target_ulong new_val, +target_ulong write_mask), +void *rmw_fn_arg) +{ +if (priv <=PRV_M ) { + env->aia_ireg_rmw_fn[priv] = rmw_fn; + env->aia_ireg_rmw_fn_arg[priv] = rmw_fn_arg; + } +} +void riscv_cpu_set_mode (CPURISCVState *env,target_ulong newpriv) {if (newpriv >PRV_M ) {
Signature · 1 line
2.34.1
[PULL v2 26/35] target/riscv: Implement AIA IMSIC interface CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA specification defines IMSIC interface CSRs for easy access to the per-HART IMSIC registers without using indirect xiselect and xireg CSRs. This patch implements the AIA IMSIC interface CSRs.
Message-id: [email protected]
--- target/riscv/csr.c | 203 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+)
target/riscv/csr.c +203 -0
@@ -942,6 +942,16 @@ static int aia_xlate_vs_csrno(CPURISCVState *env, int csrno)return CSR_VSISELECT ;case CSR_SIREG :return CSR_VSIREG ; +case CSR_SSETEIPNUM : +return CSR_VSSETEIPNUM ; +case CSR_SCLREIPNUM : +return CSR_VSCLREIPNUM ; +case CSR_SSETEIENUM : +return CSR_VSSETEIENUM ; +case CSR_SCLREIENUM : +return CSR_VSCLREIENUM ; +case CSR_STOPEI : +return CSR_VSTOPEI ;default :return csrno; };
@@ -1094,6 +1104,178 @@ done:return RISCV_EXCP_NONE ; } +static int rmw_xsetclreinum (CPURISCVState *env,int csrno,target_ulong *val, +target_ulong new_val,target_ulong wr_mask) +{ +int ret = -EINVAL ; +bool set, pend, virt; +target_ulong priv, isel, vgein, xlen, nval, wmask; + +/* Translate CSR number for VS-mode */ + csrno =aia_xlate_vs_csrno (env, csrno); + +/* Decode register details from CSR number */ + virt = set = pend = false; +switch (csrno) { +case CSR_MSETEIPNUM : + priv =PRV_M ; + set = true; + pend = true; +break ; +case CSR_MCLREIPNUM : + priv =PRV_M ; + pend = true; +break ; +case CSR_MSETEIENUM : + priv =PRV_M ; + set = true; +break ; +case CSR_MCLREIENUM : + priv =PRV_M ; +break ; +case CSR_SSETEIPNUM : + priv =PRV_S ; + set = true; + pend = true; +break ; +case CSR_SCLREIPNUM : + priv =PRV_S ; + pend = true; +break ; +case CSR_SSETEIENUM : + priv =PRV_S ; + set = true; +break ; +case CSR_SCLREIENUM : + priv =PRV_S ; +break ; +case CSR_VSSETEIPNUM : + priv =PRV_S ; + virt = true; + set = true; + pend = true; +break ; +case CSR_VSCLREIPNUM : + priv =PRV_S ; + virt = true; + pend = true; +break ; +case CSR_VSSETEIENUM : + priv =PRV_S ; + virt = true; + set = true; +break ; +case CSR_VSCLREIENUM : + priv =PRV_S ; + virt = true; +break ; +default : + goto done; + }; + +/* IMSIC CSRs only available when machine implements IMSIC. */ +if (!env->aia_ireg_rmw_fn[priv]) { + goto done; + } + +/* Find the selected guest interrupt file */ + vgein = (virt) ?get_field (env->hstatus,HSTATUS_VGEIN ) :0 ; + +/* Selected guest interrupt file should be valid */ +if (virt && (!vgein || env->geilen < vgein)) { + goto done; + } + +/* Set/Clear CSRs always read zero */ +if (val) { + *val =0 ; + } + +if (wr_mask) { +/* Get interrupt number */ + new_val &= wr_mask; + +/* Find target interrupt pending/enable register */ + xlen =riscv_cpu_mxl_bits (env); + isel = (new_val / xlen); + isel *= (xlen / IMSIC_EIPx_BITS); + isel += (pend) ?ISELECT_IMSIC_EIP0 :ISELECT_IMSIC_EIE0 ; + +/* Find the interrupt bit to be set/clear */ + wmask = ((target_ulong )1 ) << (new_val % xlen); + nval = (set) ? wmask :0 ; + +/* Call machine specific IMSIC register emulation */ + ret = env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], +AIA_MAKE_IREG (isel, priv, virt, + vgein, xlen), +NULL , nval, wmask); + }else { + ret =0 ; + } + +done: +if (ret) { +return (riscv_cpu_virt_enabled (env) && virt) ? +RISCV_EXCP_VIRT_INSTRUCTION_FAULT :RISCV_EXCP_ILLEGAL_INST ; + } +return RISCV_EXCP_NONE ; +} + +static int rmw_xtopei (CPURISCVState *env,int csrno,target_ulong *val, +target_ulong new_val,target_ulong wr_mask) +{ +bool virt; +int ret = -EINVAL ; +target_ulong priv, vgein; + +/* Translate CSR number for VS-mode */ + csrno =aia_xlate_vs_csrno (env, csrno); + +/* Decode register details from CSR number */ + virt = false; +switch (csrno) { +case CSR_MTOPEI : + priv =PRV_M ; +break ; +case CSR_STOPEI : + priv =PRV_S ; +break ; +case CSR_VSTOPEI : + priv =PRV_S ; + virt = true; +break ; +default : + goto done; + }; + +/* IMSIC CSRs only available when machine implements IMSIC. */ +if (!env->aia_ireg_rmw_fn[priv]) { + goto done; + } + +/* Find the selected guest interrupt file */ + vgein = (virt) ?get_field (env->hstatus,HSTATUS_VGEIN ) :0 ; + +/* Selected guest interrupt file should be valid */ +if (virt && (!vgein || env->geilen < vgein)) { + goto done; + } + +/* Call machine specific IMSIC register emulation for TOPEI */ + ret = env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], +AIA_MAKE_IREG (ISELECT_IMSIC_TOPEI , priv, virt, vgein, +riscv_cpu_mxl_bits (env)), + val, new_val, wr_mask); + +done: +if (ret) { +return (riscv_cpu_virt_enabled (env) && virt) ? +RISCV_EXCP_VIRT_INSTRUCTION_FAULT :RISCV_EXCP_ILLEGAL_INST ; + } +return RISCV_EXCP_NONE ; +} +static RISCVException read_mtvec (CPURISCVState *env,int csrno,target_ulong *val) {
@@ -2930,6 +3112,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Machine-Level Interrupts (AIA) */ [CSR_MTOPI] = { "mtopi", aia_any, read_mtopi }, + /* Machine-Level IMSIC Interface (AIA) */ + [CSR_MSETEIPNUM] = { "mseteipnum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MCLREIPNUM] = { "mclreipnum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MSETEIENUM] = { "mseteienum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MCLREIENUM] = { "mclreienum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MTOPEI] = { "mtopei", aia_any, NULL, NULL, rmw_xtopei }, + /* Virtual Interrupts for Supervisor Level (AIA) */ [CSR_MVIEN] = { "mvien", aia_any, read_zero, write_ignore }, [CSR_MVIP] = { "mvip", aia_any, read_zero, write_ignore },
@@ -2966,6 +3155,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Supervisor-Level Interrupts (AIA) */ [CSR_STOPI] = { "stopi", aia_smode, read_stopi }, + /* Supervisor-Level IMSIC Interface (AIA) */ + [CSR_SSETEIPNUM] = { "sseteipnum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_SCLREIPNUM] = { "sclreipnum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_SSETEIENUM] = { "sseteienum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_SCLREIENUM] = { "sclreienum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_STOPEI] = { "stopei", aia_smode, NULL, NULL, rmw_xtopei }, + /* Supervisor-Level High-Half CSRs (AIA) */ [CSR_SIEH] = { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, [CSR_SIPH] = { "siph", aia_smode32, NULL, NULL, rmw_siph },
@@ -3013,6 +3209,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* VS-Level Interrupts (H-extension with AIA) */ [CSR_VSTOPI] = { "vstopi", aia_hmode, read_vstopi }, + /* VS-Level IMSIC Interface (H-extension with AIA) */ + [CSR_VSSETEIPNUM] = { "vsseteipnum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSCLREIPNUM] = { "vsclreipnum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSSETEIENUM] = { "vsseteienum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSCLREIENUM] = { "vsclreienum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSTOPEI] = { "vstopei", aia_hmode, NULL, NULL, rmw_xtopei }, + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, [CSR_HVIENH] = { "hvienh", aia_hmode32, read_zero, write_ignore },
Signature · 1 line
2.34.1
[PULL v2 15/35] target/riscv: Improve delivery of guest external interrupts
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The guest external interrupts from an interrupt controller are delivered only when the Guest/VM is running (i.e. V=1). This means any guest external interrupt which is triggered while the Guest/VM is not running (i.e. V=0) will be missed on QEMU resulting in Guest with sluggish response to serial console input and other I/O events.
To solve this, we check and inject interrupt after setting V=1.
Message-id: [email protected]
--- target/riscv/cpu_helper.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
target/riscv/cpu_helper.c +13 -0
@@ -326,6 +326,19 @@ void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable) } env->virt =set_field (env->virt,VIRT_ONOFF , enable); + +if (enable) { +/* +* The guest external interrupts from an interrupt controller are +* delivered only when the Guest/VM is running (i.e. V=1). This means +* any guest external interrupt which is triggered while the Guest/VM +* is not running (i.e. V=0) will be missed on QEMU resulting in guest +* with sluggish response to serial console input and other I/O events. +* +* To solve this, we check and inject interrupt after setting V=1. +*/ +riscv_cpu_update_mip (env_archcpu (env),0 ,0 ); + } }bool riscv_cpu_two_stage_lookup (int mmu_idx)
Signature · 1 line
2.34.1
[PULL v2 28/35] target/riscv: Allow users to force enable AIA CSRs in HART
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
We add "x-aia" command-line option for RISC-V HART using which allows users to force enable CPU AIA CSRs without changing the interrupt controller available in RISC-V machine.
Message-id: [email protected]
--- target/riscv/cpu.h | 1 + target/riscv/cpu.c | 5 +++++ 2 files changed, 6 insertions(+)
target/riscv/cpu.h +1 -0
@@ -376,6 +376,7 @@ struct RISCVCPUConfig {bool mmu;bool pmp;bool epmp; +bool aia;uint64_t resetvec; };
target/riscv/cpu.c +5 -0
@@ -537,6 +537,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } +if (cpu->cfg.aia) { +riscv_set_feature (env,RISCV_FEATURE_AIA ); + } +set_resetvec (env, cpu->cfg.resetvec);/* Validate that MISA_MXL is set properly. */
@@ -782,6 +786,7 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("x-j" ,RISCVCPU , cfg.ext_j, false),/* ePMP 0.9.3 */ DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("x-aia" ,RISCVCPU , cfg.aia, false),DEFINE_PROP_UINT64 ("resetvec" ,RISCVCPU , cfg.resetvec,DEFAULT_RSTVEC ), DEFINE_PROP_END_OF_LIST(),
Signature · 1 line
2.34.1
[PULL v2 16/35] target/riscv: Allow setting CPU feature from machine/device emulation
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The machine or device emulation should be able to force set certain CPU features because:
1) We can have certain CPU features which are in-general optional but implemented by RISC-V CPUs on the machine.
2) We can have devices which require a certain CPU feature. For example, AIA IMSIC devices expect AIA CSRs implemented by RISC-V CPUs.
Message-id: [email protected]
--- target/riscv/cpu.h | 5 +++++ target/riscv/cpu.c | 11 +++-------- 2 files changed, 8 insertions(+), 8 deletions(-)
target/riscv/cpu.h +5 -0
@@ -379,6 +379,11 @@ static inline bool riscv_feature(CPURISCVState *env, int feature)return env->features & (1ULL << feature); } +static inline void riscv_set_feature (CPURISCVState *env,int feature) +{ + env->features |= (1ULL << feature); +} +#include "cpu_user.h" extern const char *const riscv_int_regnames[];
target/riscv/cpu.c +3 -8
@@ -135,11 +135,6 @@ static void set_vext_version(CPURISCVState *env, int vext_ver) env->vext_ver = vext_ver; } -static void set_feature (CPURISCVState *env,int feature) -{ - env->features |= (1ULL << feature); -} -static void set_resetvec (CPURISCVState *env,target_ulong resetvec) {#ifndef CONFIG_USER_ONLY
@@ -508,18 +503,18 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) }if (cpu->cfg.mmu) { -set_feature (env,RISCV_FEATURE_MMU ); +riscv_set_feature (env,RISCV_FEATURE_MMU ); }if (cpu->cfg.pmp) { -set_feature (env,RISCV_FEATURE_PMP ); +riscv_set_feature (env,RISCV_FEATURE_PMP );/* * Enhanced PMP should only be available * on harts with PMP support */ if (cpu->cfg.epmp) { -set_feature (env,RISCV_FEATURE_EPMP ); +riscv_set_feature (env,RISCV_FEATURE_EPMP ); } }
Signature · 1 line
2.34.1
[PULL v2 27/35] hw/riscv: virt: Use AIA INTC compatible string when available
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
We should use the AIA INTC compatible string in the CPU INTC DT nodes when the CPUs support AIA feature. This will allow Linux INTC driver to use AIA local interrupt CSRs.
Message-id: [email protected]
--- hw/riscv/virt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
hw/riscv/virt.c +11 -2
@@ -212,8 +212,17 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket,qemu_fdt_add_subnode (mc->fdt, intc_name);qemu_fdt_setprop_cell (mc->fdt, intc_name,"phandle" , intc_phandles[cpu]); -qemu_fdt_setprop_string (mc->fdt, intc_name,"compatible" , -"riscv,cpu-intc" ); +if (riscv_feature (&s->soc[socket].harts[cpu].env, +RISCV_FEATURE_AIA )) { +static const char *const compat[2 ] = { +"riscv,cpu-intc-aia" ,"riscv,cpu-intc" + }; +qemu_fdt_setprop_string_array (mc->fdt, intc_name,"compatible" , + (char **)&compat,ARRAY_SIZE (compat)); + }else { +qemu_fdt_setprop_string (mc->fdt, intc_name,"compatible" , +"riscv,cpu-intc" ); + }qemu_fdt_setprop (mc->fdt, intc_name,"interrupt-controller" ,NULL ,0 );qemu_fdt_setprop_cell (mc->fdt, intc_name,"#interrupt-cells" ,1 );
Signature · 1 line
2.34.1
[PULL v2 29/35] hw/intc: Add RISC-V AIA APLIC device emulation
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for wired interrupts called APLIC (Advanced Platform Level Interrupt Controller). The APLIC is capabable of forwarding wired interupts to RISC-V HARTs directly or as MSIs (Message Signaled Interupts).
This patch adds device emulation for RISC-V AIA APLIC.
Message-id: [email protected]
--- include/hw/intc/riscv_aplic.h | 79 +++ hw/intc/riscv_aplic.c | 978 ++++++++++++++++++++++++++++++++++ hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + 4 files changed, 1061 insertions(+) create mode 100644 include/hw/intc/riscv_aplic.h create mode 100644 hw/intc/riscv_aplic.c
include/hw/intc/riscv_aplic.h new file +79 -0
@@ -0,0 +1,79 @@ +/* +* RISC-V APLIC (Advanced Platform Level Interrupt Controller) interface +* +* Copyright (c) 2021 Western Digital Corporation or its affiliates. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2 or later, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef HW_RISCV_APLIC_H +#define HW_RISCV_APLIC_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_RISCV_APLIC "riscv.aplic" + +typedef struct RISCVAPLICState RISCVAPLICState ; +DECLARE_INSTANCE_CHECKER(RISCVAPLICState, RISCV_APLIC, TYPE_RISCV_APLIC) + +#define APLIC_MIN_SIZE 0x4000 +#define APLIC_SIZE_ALIGN (__x) (((__x) + (APLIC_MIN_SIZE - 1)) & \ + ~(APLIC_MIN_SIZE - 1)) +#define APLIC_SIZE (__num_harts) (APLIC_MIN_SIZE + \ + APLIC_SIZE_ALIGN(32 * (__num_harts))) + +struct RISCVAPLICState { +/*< private >*/ +SysBusDevice parent_obj; +qemu_irq *external_irqs; + +/*< public >*/ +MemoryRegion mmio; +uint32_t bitfield_words; +uint32_t domaincfg; +uint32_t mmsicfgaddr; +uint32_t mmsicfgaddrH; +uint32_t smsicfgaddr; +uint32_t smsicfgaddrH; +uint32_t genmsi; +uint32_t *sourcecfg; +uint32_t *state; +uint32_t *target; +uint32_t *idelivery; +uint32_t *iforce; +uint32_t *ithreshold; + +/* topology */ +#define QEMU_APLIC_MAX_CHILDREN 16 +struct RISCVAPLICState *parent; +struct RISCVAPLICState *children[QEMU_APLIC_MAX_CHILDREN ]; +uint16_t num_children; + +/* config */ +uint32_t aperture_size; +uint32_t hartid_base; +uint32_t num_harts; +uint32_t iprio_mask; +uint32_t num_irqs; +bool msimode; +bool mmode; +}; + +void riscv_aplic_add_child (DeviceState *parent,DeviceState *child); + +DeviceState *riscv_aplic_create (hwaddr addr,hwaddr size, +uint32_t hartid_base,uint32_t num_harts,uint32_t num_sources, +uint32_t iprio_bits,bool msimode,bool mmode,DeviceState *parent); + +#endif
hw/intc/riscv_aplic.c new file +978 -0
978 lines not on this page · raw message
hw/intc/Kconfig +3 -0
@@ -70,6 +70,9 @@ config LOONGSON_LIOINTC config RISCV_ACLINT bool +config RISCV_APLIC + bool + config SIFIVE_PLIC bool
hw/intc/meson.build +1 -0
@@ -50,6 +50,7 @@ specific_ss.add(when: 'CONFIG_S390_FLIC', if_true: files('s390_flic.c')) specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) specific_ss.add(when: 'CONFIG_SH_INTC', if_true: files('sh_intc.c')) specific_ss.add(when: 'CONFIG_RISCV_ACLINT', if_true: files('riscv_aclint.c')) +specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'],
Signature · 1 line
2.34.1
Re: [PULL v2 29/35] hw/intc: Add RISC-V AIA APLIC device emulation
Quoted 10 lines · Alistair Francis
From: Anup Patel <[email protected]>
The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for wired interrupts called APLIC (Advanced Platform Level Interrupt Controller). The APLIC is capabable of forwarding wired interupts to RISC-V HARTs directly or as MSIs (Message Signaled Interupts).
This patch adds device emulation for RISC-V AIA APLIC.
Hi; Coverity has some issues with this change; they're kind of false positives but they do flag up a minor issue with the code. This is CID 1487105, 1487113, 1487185, 1487208.
hw/intc/riscv_aplic.c line 613
Quoted 7 lines
hw/intc/riscv_aplic.c new file +7
-0+ }else if ((APLIC_TARGET_BASE <= addr) && + (addr < (APLIC_TARGET_BASE + (aplic->num_irqs -1 ) *4 ))) { + irq = ((addr -APLIC_TARGET_BASE ) >>2 ) +1 ; +return aplic->target[irq]; + }else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) && + (addr < (APLIC_IDC_BASE + aplic->num_harts *APLIC_IDC_SIZE ))) { + idc = (addr -APLIC_IDC_BASE ) /APLIC_IDC_SIZE ;
In expressions like these where we're checking "is addr between some base address and an upper bound calculated from num_irqs or num_harts", Coverity warns that we calculate expressions like (APLIC_TARGET_BASE + (aplic->num_irqs - 1) * 4) using 32-bits and then compare against the 64-bit 'addr', so there might be an unintentional overflow. Now clearly in this case num_irqs and num_harts should never be so large that there is an overflow, so in that sense Coverity is wrong and these are false positives. However...
Quoted 39 lines
hw/intc/riscv_aplic.c new file +39
-0+static void riscv_aplic_realize (DeviceState *dev,Error **errp) +{ +uint32_t i; +RISCVAPLICState *aplic =RISCV_APLIC (dev); + + aplic->bitfield_words = (aplic->num_irqs +31 ) >>5 ; + aplic->sourcecfg =g_new0 (uint32_t, aplic->num_irqs); + aplic->state =g_new (uint32_t, aplic->num_irqs); + aplic->target =g_new0 (uint32_t, aplic->num_irqs); +if (!aplic->msimode) { +for (i =0 ; i < aplic->num_irqs; i++) { + aplic->target[i] =1 ; + } + } + aplic->idelivery =g_new0 (uint32_t, aplic->num_harts); + aplic->iforce =g_new0 (uint32_t, aplic->num_harts); + aplic->ithreshold =g_new0 (uint32_t, aplic->num_harts); + +memory_region_init_io (&aplic->mmio,OBJECT (dev), &riscv_aplic_ops, aplic, +TYPE_RISCV_APLIC , aplic->aperture_size); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &aplic->mmio); + +/* +* Only root APLICs have hardware IRQ lines. All non-root APLICs +* have IRQ lines delegated by their parent APLIC. +*/ +if (!aplic->parent) { +qdev_init_gpio_in (dev, riscv_aplic_request, aplic->num_irqs); + } + +/* Create output IRQ lines for non-MSI mode */ +if (!aplic->msimode) { + aplic->external_irqs =g_malloc (sizeof (qemu_irq) * aplic->num_harts); +qdev_init_gpio_out (dev, aplic->external_irqs, aplic->num_harts); + +/* Claim the CPU interrupt to be triggered by this APLIC */ +for (i =0 ; i < aplic->num_harts; i++) { +RISCVCPU *cpu =RISCV_CPU (qemu_get_cpu (aplic->hartid_base + i)); + if (riscv_cpu_claim_interrupts(cpu,
hw/intc/riscv_aplic.c line 847
Quoted 10 lines
hw/intc/riscv_aplic.c new file +10
-0+ (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { +error_report ("%s already claimed" , + (aplic->mmode) ?"MEIP" :"SEIP" ); +exit (1 ); + } + } + } + + msi_nonbroken = true; +}
...in the realize method we don't do any sanity checking of our QOM properties that set aplic->num_irqs and aplic->num_harts, so the creator of the device could in theory pass us some bogus values that cause overflow and other bad things.
Quoted 11 lines
hw/intc/riscv_aplic.c new file +11
-0+/* +* Create APLIC device. +*/ +DeviceState *riscv_aplic_create (hwaddr addr,hwaddr size, +uint32_t hartid_base,uint32_t num_harts,uint32_t num_sources, +uint32_t iprio_bits,bool msimode,bool mmode,DeviceState *parent) +{ +DeviceState *dev =qdev_new (TYPE_RISCV_APLIC ); +uint32_t i; + +assert (num_harts <APLIC_MAX_IDC );
hw/intc/riscv_aplic.c line 956
Quoted 10 lines
hw/intc/riscv_aplic.c new file +10
-0+assert ((APLIC_IDC_BASE + (num_harts *APLIC_IDC_SIZE )) <= size); +assert (num_sources <APLIC_MAX_SOURCE ); +assert (APLIC_MIN_IPRIO_BITS <= iprio_bits); +assert (iprio_bits <=APLIC_MAX_IPRIO_BITS ); + +qdev_prop_set_uint32 (dev,"aperture-size" , size); +qdev_prop_set_uint32 (dev,"hartid-base" , hartid_base); +qdev_prop_set_uint32 (dev,"num-harts" , num_harts); +qdev_prop_set_uint32 (dev,"iprio-mask" , ((1U << iprio_bits) -1 )); +qdev_prop_set_uint32 (dev,"num-irqs" , num_sources +1 );
You do make some assert()s on num_harts and num_sources here, but this is the wrong place to do this error checking, because there's no particular reason why a board model has to use this function rather than directly creating the device. Instead these checks should go in the realize method and should cause realize to fail.
hw/intc/riscv_aplic.c line 961
Quoted 5 lines
hw/intc/riscv_aplic.c new file +5
-0+qdev_prop_set_bit (dev,"msimode" , msimode); +qdev_prop_set_bit (dev,"mmode" , mmode); + +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr);
thanks
-- PMM
Re: [PULL v2 29/35] hw/intc: Add RISC-V AIA APLIC device emulation
Quoted 109 lines · Peter Maydell
Quoted 10 lines · Alistair Francis
From: Anup Patel <[email protected]>
The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for wired interrupts called APLIC (Advanced Platform Level Interrupt Controller). The APLIC is capabable of forwarding wired interupts to RISC-V HARTs directly or as MSIs (Message Signaled Interupts).
This patch adds device emulation for RISC-V AIA APLIC.
Hi; Coverity has some issues with this change; they're kind of false positives but they do flag up a minor issue with the code. This is CID 1487105, 1487113, 1487185, 1487208.
hw/intc/riscv_aplic.c line 613
Quoted 7 lines
hw/intc/riscv_aplic.c new file +7
-0+ }else if ((APLIC_TARGET_BASE <= addr) && + (addr < (APLIC_TARGET_BASE + (aplic->num_irqs -1 ) *4 ))) { + irq = ((addr -APLIC_TARGET_BASE ) >>2 ) +1 ; +return aplic->target[irq]; + }else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) && + (addr < (APLIC_IDC_BASE + aplic->num_harts *APLIC_IDC_SIZE ))) { + idc = (addr -APLIC_IDC_BASE ) /APLIC_IDC_SIZE ;In expressions like these where we're checking "is addr between some base address and an upper bound calculated from
num_irqsornum_harts", Coverity warns that we calculate expressions like (APLIC_TARGET_BASE+ (aplic->num_irqs- 1) * 4) using 32-bits and then compare against the 64-bit 'addr', so there might be an unintentional overflow. Now clearly in this casenum_irqsandnum_hartsshould never be so large that there is an overflow, so in that sense Coverity is wrong and these are false positives. However...Quoted 39 lines
hw/intc/riscv_aplic.c new file +39
-0+static void riscv_aplic_realize (DeviceState *dev,Error **errp) +{ +uint32_t i; +RISCVAPLICState *aplic =RISCV_APLIC (dev); + + aplic->bitfield_words = (aplic->num_irqs +31 ) >>5 ; + aplic->sourcecfg =g_new0 (uint32_t, aplic->num_irqs); + aplic->state =g_new (uint32_t, aplic->num_irqs); + aplic->target =g_new0 (uint32_t, aplic->num_irqs); +if (!aplic->msimode) { +for (i =0 ; i < aplic->num_irqs; i++) { + aplic->target[i] =1 ; + } + } + aplic->idelivery =g_new0 (uint32_t, aplic->num_harts); + aplic->iforce =g_new0 (uint32_t, aplic->num_harts); + aplic->ithreshold =g_new0 (uint32_t, aplic->num_harts); + +memory_region_init_io (&aplic->mmio,OBJECT (dev), &riscv_aplic_ops, aplic, +TYPE_RISCV_APLIC , aplic->aperture_size); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &aplic->mmio); + +/* +* Only root APLICs have hardware IRQ lines. All non-root APLICs +* have IRQ lines delegated by their parent APLIC. +*/ +if (!aplic->parent) { +qdev_init_gpio_in (dev, riscv_aplic_request, aplic->num_irqs); + } + +/* Create output IRQ lines for non-MSI mode */ +if (!aplic->msimode) { + aplic->external_irqs =g_malloc (sizeof (qemu_irq) * aplic->num_harts); +qdev_init_gpio_out (dev, aplic->external_irqs, aplic->num_harts); + +/* Claim the CPU interrupt to be triggered by this APLIC */ +for (i =0 ; i < aplic->num_harts; i++) { +RISCVCPU *cpu =RISCV_CPU (qemu_get_cpu (aplic->hartid_base + i)); + if (riscv_cpu_claim_interrupts(cpu,hw/intc/riscv_aplic.c line 847
Quoted 10 lines
hw/intc/riscv_aplic.c new file +10
-0+ (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { +error_report ("%s already claimed" , + (aplic->mmode) ?"MEIP" :"SEIP" ); +exit (1 ); + } + } + } + + msi_nonbroken = true; +}...in the realize method we don't do any sanity checking of our QOM properties that set
aplic->num_irqsandaplic->num_harts, so the creator of the device could in theory pass us some bogus values that cause overflow and other bad things.Quoted 19 lines
hw/intc/riscv_aplic.c new file +19
-0+/* +* Create APLIC device. +*/ +DeviceState *riscv_aplic_create (hwaddr addr,hwaddr size, +uint32_t hartid_base,uint32_t num_harts,uint32_t num_sources, +uint32_t iprio_bits,bool msimode,bool mmode,DeviceState *parent) +{ +DeviceState *dev =qdev_new (TYPE_RISCV_APLIC ); +uint32_t i; + +assert (num_harts <APLIC_MAX_IDC ); +assert ((APLIC_IDC_BASE + (num_harts *APLIC_IDC_SIZE )) <= size); +assert (num_sources <APLIC_MAX_SOURCE ); +assert (APLIC_MIN_IPRIO_BITS <= iprio_bits); +assert (iprio_bits <=APLIC_MAX_IPRIO_BITS ); + +qdev_prop_set_uint32 (dev,"aperture-size" , size); +qdev_prop_set_uint32 (dev,"hartid-base" , hartid_base); +qdev_prop_set_uint32 (dev,"num-harts" , num_harts);
Quoted 8 lines
hw/intc/riscv_aplic.c line 956
Quoted 2 lines
hw/intc/riscv_aplic.c new file +2
-0+qdev_prop_set_uint32 (dev,"iprio-mask" , ((1U << iprio_bits) -1 )); +qdev_prop_set_uint32 (dev,"num-irqs" , num_sources +1 );You do make some assert()s on
num_hartsandnum_sourceshere, but this is the wrong place to do this error checking, because there's no particular reason why a board model has to use this function rather than directly creating the device. Instead these checks should go in the realize method and should cause realize to fail.
@Anup Patel are you able to send a patch adding some error checking?
Alistair
Quoted 9 lines
hw/intc/riscv_aplic.c line 961
Quoted 6 lines
hw/intc/riscv_aplic.c new file +5
-0+qdev_prop_set_bit (dev,"msimode" , msimode); +qdev_prop_set_bit (dev,"mmode" , mmode); + +sysbus_realize_and_unref (SYS_BUS_DEVICE (dev), &error_fatal); +sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , addr);thanks
-- PMM
[PULL v2 18/35] target/riscv: Add defines for AIA CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The RISC-V AIA specification extends RISC-V local interrupts and introduces new CSRs. This patch adds defines for the new AIA CSRs.
Message-id: [email protected]
--- target/riscv/cpu_bits.h | 119 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+)
target/riscv/cpu_bits.h +119 -0
@@ -168,6 +168,31 @@#define CSR_MTVAL 0x343#define CSR_MIP 0x344 +/* Machine-Level Window to Indirectly Accessed Registers (AIA) */ +#define CSR_MISELECT 0x350 +#define CSR_MIREG 0x351 + +/* Machine-Level Interrupts (AIA) */ +#define CSR_MTOPI 0xfb0 + +/* Machine-Level IMSIC Interface (AIA) */ +#define CSR_MSETEIPNUM 0x358 +#define CSR_MCLREIPNUM 0x359 +#define CSR_MSETEIENUM 0x35a +#define CSR_MCLREIENUM 0x35b +#define CSR_MTOPEI 0x35c + +/* Virtual Interrupts for Supervisor Level (AIA) */ +#define CSR_MVIEN 0x308 +#define CSR_MVIP 0x309 + +/* Machine-Level High-Half CSRs (AIA) */ +#define CSR_MIDELEGH 0x313 +#define CSR_MIEH 0x314 +#define CSR_MVIENH 0x318 +#define CSR_MVIPH 0x319 +#define CSR_MIPH 0x354 +/* Supervisor Trap Setup */ #define CSR_SSTATUS 0x100#define CSR_SEDELEG 0x102
@@ -187,6 +212,24 @@#define CSR_SPTBR 0x180#define CSR_SATP 0x180 +/* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */ +#define CSR_SISELECT 0x150 +#define CSR_SIREG 0x151 + +/* Supervisor-Level Interrupts (AIA) */ +#define CSR_STOPI 0xdb0 + +/* Supervisor-Level IMSIC Interface (AIA) */ +#define CSR_SSETEIPNUM 0x158 +#define CSR_SCLREIPNUM 0x159 +#define CSR_SSETEIENUM 0x15a +#define CSR_SCLREIENUM 0x15b +#define CSR_STOPEI 0x15c + +/* Supervisor-Level High-Half CSRs (AIA) */ +#define CSR_SIEH 0x114 +#define CSR_SIPH 0x154 +/* Hpervisor CSRs */ #define CSR_HSTATUS 0x600#define CSR_HEDELEG 0x602
@@ -217,6 +260,35 @@#define CSR_MTINST 0x34a#define CSR_MTVAL2 0x34b +/* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ +#define CSR_HVIEN 0x608 +#define CSR_HVICTL 0x609 +#define CSR_HVIPRIO1 0x646 +#define CSR_HVIPRIO2 0x647 + +/* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA) */ +#define CSR_VSISELECT 0x250 +#define CSR_VSIREG 0x251 + +/* VS-Level Interrupts (H-extension with AIA) */ +#define CSR_VSTOPI 0xeb0 + +/* VS-Level IMSIC Interface (H-extension with AIA) */ +#define CSR_VSSETEIPNUM 0x258 +#define CSR_VSCLREIPNUM 0x259 +#define CSR_VSSETEIENUM 0x25a +#define CSR_VSCLREIENUM 0x25b +#define CSR_VSTOPEI 0x25c + +/* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ +#define CSR_HIDELEGH 0x613 +#define CSR_HVIENH 0x618 +#define CSR_HVIPH 0x655 +#define CSR_HVIPRIO1H 0x656 +#define CSR_HVIPRIO2H 0x657 +#define CSR_VSIEH 0x214 +#define CSR_VSIPH 0x254 +/* Enhanced Physical Memory Protection (ePMP) */ #define CSR_MSECCFG 0x747#define CSR_MSECCFGH 0x757
@@ -635,4 +707,51 @@ typedef enum RISCVException {#define UMTE_U_PM_INSN U_PM_INSN#define UMTE_MASK (UMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | UMTE_U_PM_INSN) +/* MISELECT, SISELECT, and VSISELECT bits (AIA) */ +#define ISELECT_IPRIO0 0x30 +#define ISELECT_IPRIO15 0x3f +#define ISELECT_IMSIC_EIDELIVERY 0x70 +#define ISELECT_IMSIC_EITHRESHOLD 0x72 +#define ISELECT_IMSIC_EIP0 0x80 +#define ISELECT_IMSIC_EIP63 0xbf +#define ISELECT_IMSIC_EIE0 0xc0 +#define ISELECT_IMSIC_EIE63 0xff +#define ISELECT_IMSIC_FIRST ISELECT_IMSIC_EIDELIVERY +#define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63 +#define ISELECT_MASK 0x1ff + +/* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */ +#define ISELECT_IMSIC_TOPEI (ISELECT_MASK + 1) + +/* IMSIC bits (AIA) */ +#define IMSIC_TOPEI_IID_SHIFT 16 +#define IMSIC_TOPEI_IID_MASK 0x7ff +#define IMSIC_TOPEI_IPRIO_MASK 0x7ff +#define IMSIC_EIPx_BITS 32 +#define IMSIC_EIEx_BITS 32 + +/* MTOPI and STOPI bits (AIA) */ +#define TOPI_IID_SHIFT 16 +#define TOPI_IID_MASK 0xfff +#define TOPI_IPRIO_MASK 0xff + +/* Interrupt priority bits (AIA) */ +#define IPRIO_IRQ_BITS 8 +#define IPRIO_MMAXIPRIO 255 +#define IPRIO_DEFAULT_UPPER 4 +#define IPRIO_DEFAULT_MIDDLE (IPRIO_DEFAULT_UPPER + 24) +#define IPRIO_DEFAULT_M IPRIO_DEFAULT_MIDDLE +#define IPRIO_DEFAULT_S (IPRIO_DEFAULT_M + 3) +#define IPRIO_DEFAULT_SGEXT (IPRIO_DEFAULT_S + 3) +#define IPRIO_DEFAULT_VS (IPRIO_DEFAULT_SGEXT + 1) +#define IPRIO_DEFAULT_LOWER (IPRIO_DEFAULT_VS + 3) + +/* HVICTL bits (AIA) */ +#define HVICTL_VTI 0x40000000 +#define HVICTL_IID 0x0fff0000 +#define HVICTL_IPRIOM 0x00000100 +#define HVICTL_IPRIO 0x000000ff +#define HVICTL_VALID_MASK \ + (HVICTL_VTI | HVICTL_IID | HVICTL_IPRIOM | HVICTL_IPRIO) +#endif
Signature · 1 line
2.34.1
[PULL v2 30/35] target/riscv: Ignore reserved bits in PTE for RV64
In reply to Alistair FrancisFrom: Guo Ren <[email protected]>
Highest bits of PTE has been used for svpbmt, ref: [1], [2], so we need to ignore them. They cannot be a part of ppn.
1: The RISC-V Instruction Set Manual, Volume II: Privileged Architecture
4.4 Sv39: Page-Based 39-bit Virtual-Memory System
4.5 Sv48: Page-Based 48-bit Virtual-Memory System
2: https://github.com/riscv/virtual-memory/blob/main/specs/663-Svpbmt-diff.pdf
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 15 +++++++++++++++ target/riscv/cpu_bits.h | 3 +++ target/riscv/cpu_helper.c | 13 ++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-)
target/riscv/cpu.h +15 -0
@@ -359,6 +359,8 @@ struct RISCVCPUConfig {bool ext_counters;bool ext_ifencei;bool ext_icsr; +bool ext_svnapot; +bool ext_svpbmt;bool ext_zfh;bool ext_zfhmin;bool ext_zve32f;
@@ -558,6 +560,19 @@ static inline int riscv_cpu_xlen(CPURISCVState *env)return 16 << env->xl; } +#ifdef TARGET_RISCV32 +#define riscv_cpu_sxl (env) ((void)(env), MXL_RV32) +#else +static inline RISCVMXL riscv_cpu_sxl (CPURISCVState *env) +{ +#ifdef CONFIG_USER_ONLY +return env->misa_mxl; +#else +return get_field (env->mstatus,MSTATUS64_SXL ); +#endif +} +#endif +/* * Encode LMUL to lmul as follows: * LMUL vlmul lmul
target/riscv/cpu_bits.h +3 -0
@@ -565,6 +565,9 @@ typedef enum {/* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10 +/* Page table PPN mask */ +#define PTE_PPN_MASK 0x3FFFFFFFFFFC00ULL +/* Leaf page shift amount */ #define PGSHIFT 12
target/riscv/cpu_helper.c +12 -1
@@ -751,6 +751,8 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,MemTxAttrs attrs =MEMTXATTRS_UNSPECIFIED ;int mode = mmu_idx &TB_FLAGS_PRIV_MMU_MASK ;bool use_background = false; +hwaddr ppn; +RISCVCPU *cpu =env_archcpu (env);/* * Check if we should use the background registers for the two
@@ -919,7 +921,16 @@ restart:return TRANSLATE_FAIL ; } -hwaddr ppn = pte >>PTE_PPN_SHIFT ; +if (riscv_cpu_sxl (env) ==MXL_RV32 ) { + ppn = pte >>PTE_PPN_SHIFT ; + }else if (cpu->cfg.ext_svpbmt || cpu->cfg.ext_svnapot) { + ppn = (pte & (target_ulong )PTE_PPN_MASK ) >>PTE_PPN_SHIFT ; + }else { + ppn = pte >>PTE_PPN_SHIFT ; +if ((pte & ~(target_ulong )PTE_PPN_MASK ) >>PTE_PPN_SHIFT ) { +return TRANSLATE_FAIL ; + } + }if (!(pte &PTE_V )) {/* Invalid PTE */
Signature · 1 line
2.34.1
[PULL v2 32/35] target/riscv: add support for svnapot extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add PTE_N bit
- add PTE_N bit check for inner PTE
- update address translation to support 64KiB continuous region (napot_bits = 4)
Message-Id: <[email protected]>
--- target/riscv/cpu_bits.h | 1 + target/riscv/cpu.c | 2 ++ target/riscv/cpu_helper.c | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-)
target/riscv/cpu_bits.h +1 -0
@@ -561,6 +561,7 @@ typedef enum {#define PTE_A 0x040/* Accessed */ #define PTE_D 0x080/* Dirty */ #define PTE_SOFT 0x300/* Reserved for Software */ +#define PTE_N 0x8000000000000000ULL/* NAPOT translation */ /* Page table PPN shift amount */ #define PTE_PPN_SHIFT 10
target/riscv/cpu.c +2 -0
@@ -774,6 +774,8 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false), +DEFINE_PROP_BOOL ("zba" ,RISCVCPU , cfg.ext_zba, true),DEFINE_PROP_BOOL ("zbb" ,RISCVCPU , cfg.ext_zbb, true), DEFINE_PROP_BOOL("zbc", RISCVCPU, cfg.ext_zbc, true),
target/riscv/cpu_helper.c +15 -3
@@ -753,6 +753,8 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,bool use_background = false;hwaddr ppn;RISCVCPU *cpu =env_archcpu (env); +int napot_bits =0 ; +target_ulong napot_mask;/* * Check if we should use the background registers for the two
@@ -937,7 +939,7 @@ restart:return TRANSLATE_FAIL ; }else if (!(pte & (PTE_R |PTE_W |PTE_X ))) {/* Inner PTE, continue walking */ -if (pte & (PTE_D |PTE_A |PTE_U )) { +if (pte & (PTE_D |PTE_A |PTE_U |PTE_N )) {return TRANSLATE_FAIL ; } base = ppn <<PGSHIFT ;
@@ -1013,8 +1015,18 @@ restart:/* for superpage mappings, make a fake leaf PTE for the TLB's benefit. */ target_ulong vpn = addr >>PGSHIFT ; - *physical = ((ppn | (vpn & ((1L << ptshift) -1 ))) <<PGSHIFT ) | - (addr & ~TARGET_PAGE_MASK ); + +if (cpu->cfg.ext_svnapot && (pte &PTE_N )) { + napot_bits =ctzl (ppn) +1 ; +if ((i != (levels -1 )) || (napot_bits !=4 )) { +return TRANSLATE_FAIL ; + } + } + + napot_mask = (1 << napot_bits) -1 ; + *physical = (((ppn & ~napot_mask) | (vpn & napot_mask) | + (vpn & (((target_ulong )1 << ptshift) -1 )) + ) <<PGSHIFT ) | (addr & ~TARGET_PAGE_MASK );/* set permissions on the TLB entry */ if ((pte &PTE_R ) || ((pte &PTE_X ) && mxr)) {
Signature · 1 line
2.34.1
[PULL v2 20/35] target/riscv: Implement AIA local interrupt priorities
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA spec defines programmable 8-bit priority for each local interrupt at M-level, S-level and VS-level so we extend local interrupt processing to consider AIA interrupt priorities. The AIA CSRs which help software configure local interrupt priorities will be added by subsequent patches.
Message-id: [email protected]
--- target/riscv/cpu.h | 12 ++ target/riscv/cpu.c | 19 +++ target/riscv/cpu_helper.c | 281 +++++++++++++++++++++++++++++++++++--- target/riscv/machine.c | 3 + 4 files changed, 294 insertions(+), 21 deletions(-)
target/riscv/cpu.h +12 -0
@@ -192,6 +192,10 @@ struct CPURISCVState {target_ulong mcause;target_ulong mtval;/* since: priv-1.10.0 */ +/* Machine and Supervisor interrupt priorities */ +uint8_t miprio[64 ]; +uint8_t siprio[64 ]; +/* Hypervisor CSRs */ target_ulong hstatus;target_ulong hedeleg;
@@ -204,6 +208,9 @@ struct CPURISCVState {target_ulong hgeip;uint64_t htimedelta; +/* Hypervisor controlled virtual interrupt priorities */ +uint8_t hviprio[64 ]; +/* Upper 64-bits of 128-bit CSRs */ uint64_t mscratchh;uint64_t sscratchh;
@@ -415,6 +422,11 @@ int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque);int riscv_cpu_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int riscv_cpu_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg); +int riscv_cpu_hviprio_index2irq (int index,int *out_irq,int *out_rdzero); +uint8_t riscv_cpu_default_priority (int irq); +int riscv_cpu_mirq_pending (CPURISCVState *env); +int riscv_cpu_sirq_pending (CPURISCVState *env); +int riscv_cpu_vsirq_pending (CPURISCVState *env);bool riscv_cpu_fp_enabled (CPURISCVState *env);target_ulong riscv_cpu_get_geilen (CPURISCVState *env);void riscv_cpu_set_geilen (CPURISCVState *env,target_ulong geilen);
target/riscv/cpu.c +19 -0
@@ -400,6 +400,10 @@ void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb,static void riscv_cpu_reset (DeviceState *dev) { +#ifndef CONFIG_USER_ONLY +uint8_t iprio; +int i, irq, rdzero; +#endif CPUState *cs =CPU (dev);RISCVCPU *cpu =RISCV_CPU (cs);RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (cpu);
@@ -432,6 +436,21 @@ static void riscv_cpu_reset(DeviceState *dev) env->miclaim =MIP_SGEIP ; env->pc = env->resetvec; env->two_stage_lookup = false; + +/* Initialized default priorities of local interrupts. */ +for (i =0 ; i <ARRAY_SIZE (env->miprio); i++) { + iprio =riscv_cpu_default_priority (i); + env->miprio[i] = (i ==IRQ_M_EXT ) ?0 : iprio; + env->siprio[i] = (i ==IRQ_S_EXT ) ?0 : iprio; + env->hviprio[i] =0 ; + } + i =0 ; +while (!riscv_cpu_hviprio_index2irq (i, &irq, &rdzero)) { +if (!rdzero) { + env->hviprio[irq] = env->miprio[irq]; + } + i++; + }/* mmte is supposed to have pm.current hardwired to 1 */ env->mmte |= (PM_EXT_INITIAL |MMTE_M_PM_CURRENT );#endif
target/riscv/cpu_helper.c +260 -21
296 lines not on this page · raw message
target/riscv/machine.c +3 -0
@@ -92,6 +92,7 @@ static const VMStateDescription vmstate_hyper = {VMSTATE_UINTTL (env.hgeie,RISCVCPU ),VMSTATE_UINTTL (env.hgeip,RISCVCPU ),VMSTATE_UINT64 (env.htimedelta,RISCVCPU ), +VMSTATE_UINT8_ARRAY (env.hviprio,RISCVCPU ,64 ),VMSTATE_UINT64 (env.vsstatus,RISCVCPU ), VMSTATE_UINTTL(env.vstvec, RISCVCPU),
@@ -235,6 +236,8 @@ const VMStateDescription vmstate_riscv_cpu = { .fields = (VMStateField[]) {VMSTATE_UINTTL_ARRAY (env.gpr,RISCVCPU ,32 ),VMSTATE_UINT64_ARRAY (env.fpr,RISCVCPU ,32 ), +VMSTATE_UINT8_ARRAY (env.miprio,RISCVCPU ,64 ), +VMSTATE_UINT8_ARRAY (env.siprio,RISCVCPU ,64 ),VMSTATE_UINTTL (env.pc,RISCVCPU ),VMSTATE_UINTTL (env.load_res,RISCVCPU ),VMSTATE_UINTTL (env.load_val,RISCVCPU ),
Signature · 1 line
2.34.1
[PULL v2 21/35] target/riscv: Implement AIA CSRs for 64 local interrupts on RV32
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA specification adds new CSRs for RV32 so that RISC-V hart can support 64 local interrupts on both RV32 and RV64.
Message-id: [email protected]
--- target/riscv/cpu.h | 14 +- target/riscv/cpu_helper.c | 10 +- target/riscv/csr.c | 560 +++++++++++++++++++++++++++++++------- target/riscv/machine.c | 10 +- 4 files changed, 474 insertions(+), 120 deletions(-)
target/riscv/cpu.h +7 -7
@@ -172,12 +172,12 @@ struct CPURISCVState {*/ uint64_t mstatus; -target_ulong mip; +uint64_t mip; -uint32_t miclaim; +uint64_t miclaim; -target_ulong mie; -target_ulong mideleg; +uint64_t mie; +uint64_t mideleg;target_ulong satp;/* since: priv-1.10.0 */ target_ulong stval;
@@ -199,7 +199,7 @@ struct CPURISCVState {/* Hypervisor CSRs */ target_ulong hstatus;target_ulong hedeleg; -target_ulong hideleg; +uint64_t hideleg;target_ulong hcounteren;target_ulong htval;target_ulong htinst;
@@ -456,8 +456,8 @@ void riscv_cpu_list(void);#ifndef CONFIG_USER_ONLY bool riscv_cpu_exec_interrupt (CPUState *cs,int interrupt_request);void riscv_cpu_swap_hypervisor_regs (CPURISCVState *env); -int riscv_cpu_claim_interrupts (RISCVCPU *cpu,uint32_t interrupts); -uint32_t riscv_cpu_update_mip (RISCVCPU *cpu,uint32_t mask,uint32_t value); +int riscv_cpu_claim_interrupts (RISCVCPU *cpu,uint64_t interrupts); +uint64_t riscv_cpu_update_mip (RISCVCPU *cpu,uint64_t mask,uint64_t value);#define BOOL_TO_MASK (x) (-!!(x))/* helper for riscv_cpu_update_mip value */ void riscv_cpu_set_rdtime_fn (CPURISCVState *env,uint64_t (*fn)(uint32_t ),uint32_t arg);
target/riscv/cpu_helper.c +5 -5
@@ -585,7 +585,7 @@ bool riscv_cpu_two_stage_lookup(int mmu_idx)return mmu_idx &TB_FLAGS_PRIV_HYP_ACCESS_MASK ; } -int riscv_cpu_claim_interrupts (RISCVCPU *cpu,uint32_t interrupts) +int riscv_cpu_claim_interrupts (RISCVCPU *cpu,uint64_t interrupts) {CPURISCVState *env = &cpu->env;if (env->miclaim & interrupts) {
@@ -596,11 +596,11 @@ int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts) } } -uint32_t riscv_cpu_update_mip (RISCVCPU *cpu,uint32_t mask,uint32_t value) +uint64_t riscv_cpu_update_mip (RISCVCPU *cpu,uint64_t mask,uint64_t value) {CPURISCVState *env = &cpu->env;CPUState *cs =CPU (cpu); -uint32_t gein, vsgein =0 , old = env->mip; +uint64_t gein, vsgein =0 , old = env->mip;bool locked = false;if (riscv_cpu_virt_enabled (env)) {
@@ -1306,7 +1306,7 @@ void riscv_cpu_do_interrupt(CPUState *cs)*/ bool async = !!(cs->exception_index &RISCV_EXCP_INT_FLAG );target_ulong cause = cs->exception_index &RISCV_EXCP_INT_MASK ; -target_ulong deleg = async ? env->mideleg : env->medeleg; +uint64_t deleg = async ? env->mideleg : env->medeleg;target_ulong tval =0 ;target_ulong htval =0 ;target_ulong mtval2 =0 ;
@@ -1373,7 +1373,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) cause < TARGET_LONG_BITS && ((deleg >> cause) & 1)) {/* handle the trap in S-mode */ if (riscv_has_ext (env,RVH )) { -target_ulong hdeleg = async ? env->hideleg : env->hedeleg; +uint64_t hdeleg = async ? env->hideleg : env->hedeleg;if (riscv_cpu_virt_enabled (env) && ((hdeleg >> cause) &1 )) {/* Trap to VS mode */
target/riscv/csr.c +457 -103
735 lines not on this page · raw message
target/riscv/machine.c +5 -5
@@ -84,7 +84,7 @@ static const VMStateDescription vmstate_hyper = { .fields = (VMStateField[]) {VMSTATE_UINTTL (env.hstatus,RISCVCPU ),VMSTATE_UINTTL (env.hedeleg,RISCVCPU ), -VMSTATE_UINTTL (env.hideleg,RISCVCPU ), +VMSTATE_UINT64 (env.hideleg,RISCVCPU ),VMSTATE_UINTTL (env.hcounteren,RISCVCPU ),VMSTATE_UINTTL (env.htval,RISCVCPU ),VMSTATE_UINTTL (env.htinst,RISCVCPU ),
@@ -256,10 +256,10 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINTTL (env.resetvec,RISCVCPU ),VMSTATE_UINTTL (env.mhartid,RISCVCPU ),VMSTATE_UINT64 (env.mstatus,RISCVCPU ), -VMSTATE_UINTTL (env.mip,RISCVCPU ), -VMSTATE_UINT32 (env.miclaim,RISCVCPU ), -VMSTATE_UINTTL (env.mie,RISCVCPU ), -VMSTATE_UINTTL (env.mideleg,RISCVCPU ), +VMSTATE_UINT64 (env.mip,RISCVCPU ), +VMSTATE_UINT64 (env.miclaim,RISCVCPU ), +VMSTATE_UINT64 (env.mie,RISCVCPU ), +VMSTATE_UINT64 (env.mideleg,RISCVCPU ),VMSTATE_UINTTL (env.satp,RISCVCPU ),VMSTATE_UINTTL (env.stval,RISCVCPU ), VMSTATE_UINTTL(env.medeleg, RISCVCPU),
Signature · 1 line
2.34.1
[PULL v2 25/35] target/riscv: Implement AIA xiselect and xireg CSRs
In reply to Alistair FrancisFrom: Anup Patel <[email protected]>
The AIA specification defines [m|s|vs]iselect and [m|s|vs]ireg CSRs which allow indirect access to interrupt priority arrays and per-HART IMSIC registers. This patch implements AIA xiselect and xireg CSRs.
Message-id: [email protected]
--- target/riscv/cpu.h | 7 ++ target/riscv/csr.c | 177 +++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 3 + 3 files changed, 187 insertions(+)
target/riscv/cpu.h +7 -0
@@ -196,6 +196,10 @@ struct CPURISCVState {uint8_t miprio[64 ];uint8_t siprio[64 ]; +/* AIA CSRs */ +target_ulong miselect; +target_ulong siselect; +/* Hypervisor CSRs */ target_ulong hstatus;target_ulong hedeleg;
@@ -229,6 +233,9 @@ struct CPURISCVState {target_ulong vstval;target_ulong vsatp; +/* AIA VS-mode CSRs */ +target_ulong vsiselect; +target_ulong mtval2;target_ulong mtinst;
target/riscv/csr.c +177 -0
201 lines not on this page · raw message
target/riscv/machine.c +3 -0
@@ -103,6 +103,7 @@ static const VMStateDescription vmstate_hyper = {VMSTATE_UINTTL (env.vscause,RISCVCPU ),VMSTATE_UINTTL (env.vstval,RISCVCPU ),VMSTATE_UINTTL (env.vsatp,RISCVCPU ), +VMSTATE_UINTTL (env.vsiselect,RISCVCPU ),VMSTATE_UINTTL (env.mtval2,RISCVCPU ), VMSTATE_UINTTL(env.mtinst, RISCVCPU),
@@ -272,6 +273,8 @@ const VMStateDescription vmstate_riscv_cpu = {VMSTATE_UINTTL (env.mepc,RISCVCPU ),VMSTATE_UINTTL (env.mcause,RISCVCPU ),VMSTATE_UINTTL (env.mtval,RISCVCPU ), +VMSTATE_UINTTL (env.miselect,RISCVCPU ), +VMSTATE_UINTTL (env.siselect,RISCVCPU ),VMSTATE_UINTTL (env.scounteren,RISCVCPU ),VMSTATE_UINTTL (env.mcounteren,RISCVCPU ), VMSTATE_UINTTL(env.sscratch, RISCVCPU),
Signature · 1 line
2.34.1
[PULL v2 35/35] docs/system: riscv: Update description of CPU
In reply to Alistair FrancisFrom: Yu Li <[email protected]>
Since the hypervisor extension been non experimental and enabled for default CPU, the previous command is no longer available and the option x-h=true or h=true is also no longer required.
Message-Id: <[email protected]>
--- docs/system/riscv/virt.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
docs/system/riscv/virt.rst +3 -3
@@ -23,9 +23,9 @@ The ``virt`` machine supports the following devices: * 1 generic PCIe host bridge * The fw_cfg device that allows a guest to obtain data from QEMU -Note that the default CPU is a generic RV32GC/RV64GC. Optional extensions -can be enabled via command line parameters, e.g.: ``-cpu rv64,x-h=true`` -enables the hypervisor extension for RV64. +The hypervisor extension has been enabled for the default CPU, so virtual +machines with hypervisor extension can simply be used without explicitly +declaring. Hardware configuration information ----------------------------------
Signature · 1 line
2.34.1
Peter Maydell
AppliedQuoted 27 lines · Alistair Francis
From: Alistair Francis <[email protected]>
The following changes since commit
ad38520bdeb2b1e0b487db317f29119e94c1c88d:Merge remote-tracking branch 'remotes/stefanha-gitlab/tags/block-pull-request' into staging (2022-02-15 19:30:33 +0000)
are available in the Git repository at:
[email protected]:alistair23/qemu.git tags/pull-riscv-to-apply-20220216
for you to fetch changes up to
7035b8420fa52e8c94cf4317c0f88c1b73ced28d:docs/system: riscv: Update description of CPU (2022-02-16 12:25:52 +1000)
----------------------------------------------------------------
Fourth RISC-V PR for QEMU 7.0* Remove old Ibex PLIC header file
* Allow writing 8 bytes with generic loader
* Fixes for RV128
* Refactor RISC-V CPU configs
* Initial support for XVentanaCondOps custom extension
* Fix for vill field in vtype
* Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode
* Support for svnapot, svinval and svpbmt extensions
Quoted 1 line
----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/7.0
for any user-visible changes.
-- PMM