Add epmp to extensions list and rename it to smepmp
PATCH 1/1 Add epmp to extensions list and rename it to smepmp
Smepmp is a ratified extension which qemu refers to as epmp. Rename epmp to smepmp and add it to extension list so that it is added to the isa string.
--- target/riscv/cpu.c | 9 +++++---- target/riscv/cpu_cfg.h | 2 +- target/riscv/csr.c | 6 +++--- target/riscv/pmp.c | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-)
target/riscv/cpu.c +5 -4
@@ -127,6 +127,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (svinval,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot,PRIV_VERSION_1_12_0 , ext_svnapot),ISA_EXT_DATA_ENTRY (svpbmt,PRIV_VERSION_1_12_0 , ext_svpbmt), +ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp),ISA_EXT_DATA_ENTRY (xtheadba,PRIV_VERSION_1_11_0 , ext_xtheadba),ISA_EXT_DATA_ENTRY (xtheadbb,PRIV_VERSION_1_11_0 , ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs),
@@ -547,7 +548,7 @@ static void rv32_ibex_cpu_init(Object *obj)#ifndef CONFIG_USER_ONLY set_satp_mode_max_supported (cpu,VM_1_10_MBARE );#endif - cpu->cfg.epmp = true; + cpu->cfg.ext_smepmp = true;/* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei = true;
@@ -1336,12 +1337,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)return ; } -if (cpu->cfg.epmp && !cpu->cfg.pmp) { +if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available * on harts with PMP support */ -error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +error_setg (errp,"Invalid configuration: SMEPMP requires PMP support" );return ; }
@@ -1676,7 +1677,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false),/* ePMP 0.9.3 */ -DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("smepmp" ,RISCVCPU , cfg.ext_smepmp, false),DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), DEFINE_PROP_BOOL("x-ssaia", RISCVCPU, cfg.ext_ssaia, false),
target/riscv/cpu_cfg.h +1 -1
@@ -87,6 +87,7 @@ struct RISCVCPUConfig {bool ext_zvfh;bool ext_zvfhmin;bool ext_smaia; +bool ext_smepmp;bool ext_ssaia;bool ext_sscofpmf;bool rvv_ta_all_1s;
@@ -121,7 +122,6 @@ struct RISCVCPUConfig {uint16_t cboz_blocksize;bool mmu;bool pmp; -bool epmp;bool debug;bool misa_w;
target/riscv/csr.c +3 -3
@@ -523,9 +523,9 @@ static RISCVException pmp(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } -static RISCVException epmp (CPURISCVState *env,int csrno) +static RISCVException smepmp (CPURISCVState *env,int csrno) { -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {return RISCV_EXCP_NONE ; }
@@ -4356,7 +4356,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, /* Physical Memory Protection */ - [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg, + [CSR_MSECCFG] = { "mseccfg", smepmp, read_mseccfg, write_mseccfg, .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },
target/riscv/pmp.c +6 -6
@@ -87,7 +87,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)if (pmp_index <MAX_RISCV_PMPS ) {bool locked = true; -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET (env)) { locked = false;
@@ -337,9 +337,9 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* * Convert the PMP permissions to match the truth table in the -* ePMP spec. +* SMEPMP spec. */ -const uint8_t epmp_operation = +const uint8_t smepmp_operation = ((env->pmp_state.pmp[i].cfg_reg &PMP_LOCK ) >>4 ) | ((env->pmp_state.pmp[i].cfg_reg &PMP_READ ) <<2 ) | (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |
@@ -364,7 +364,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,* If mseccfg.MML Bit set, do the enhanced pmp priv check */ if (mode ==PRV_M ) { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 1 :case 4 :
@@ -395,7 +395,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,g_assert_not_reached (); } }else { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 8 :case 9 :
@@ -576,7 +576,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val) } } -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* Sticky bits */ val |= (env->mseccfg & (MSECCFG_MMWP |MSECCFG_MML ));if ((val ^ env->mseccfg) & (MSECCFG_MMWP |MSECCFG_MML )) {
Signature · 1 line
2.34.1
Quoted 6 lines · Himanshu Chauhan
Smepmp is a ratified extension which qemu refers to as epmp. Rename epmp to smepmp and add it to extension list so that it is added to the isa string.
Signed-off-by Himanshu Chauhan <[email protected]>---
Quoted 148 lines
target/riscv/cpu.c | 9 +++++---- target/riscv/cpu_cfg.h | 2 +- target/riscv/csr.c | 6 +++--- target/riscv/pmp.c | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-)target/riscv/cpu.c +5
-4@@ -127,6 +127,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (svinval,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot,PRIV_VERSION_1_12_0 , ext_svnapot),ISA_EXT_DATA_ENTRY (svpbmt,PRIV_VERSION_1_12_0 , ext_svpbmt), +ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp),ISA_EXT_DATA_ENTRY (xtheadba,PRIV_VERSION_1_11_0 , ext_xtheadba),ISA_EXT_DATA_ENTRY (xtheadbb,PRIV_VERSION_1_11_0 , ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs),@@ -547,7 +548,7 @@ static void rv32_ibex_cpu_init(Object *obj)#ifndef CONFIG_USER_ONLY set_satp_mode_max_supported (cpu,VM_1_10_MBARE );#endif - cpu->cfg.epmp = true; + cpu->cfg.ext_smepmp = true;/* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei = true;@@ -1336,12 +1337,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)return ; } -if (cpu->cfg.epmp && !cpu->cfg.pmp) { +if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available * on harts with PMP support */ -error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +error_setg (errp,"Invalid configuration: SMEPMP requires PMP support" );return ; }@@ -1676,7 +1677,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false),/* ePMP 0.9.3 */ -DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("smepmp" ,RISCVCPU , cfg.ext_smepmp, false),DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), DEFINE_PROP_BOOL("x-ssaia", RISCVCPU, cfg.ext_ssaia, false),target/riscv/cpu_cfg.h +1
-1@@ -87,6 +87,7 @@ struct RISCVCPUConfig {bool ext_zvfh;bool ext_zvfhmin;bool ext_smaia; +bool ext_smepmp;bool ext_ssaia;bool ext_sscofpmf;bool rvv_ta_all_1s;@@ -121,7 +122,6 @@ struct RISCVCPUConfig {uint16_t cboz_blocksize;bool mmu;bool pmp; -bool epmp;bool debug;bool misa_w;target/riscv/csr.c +3
-3@@ -523,9 +523,9 @@ static RISCVException pmp(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } -static RISCVException epmp (CPURISCVState *env,int csrno) +static RISCVException smepmp (CPURISCVState *env,int csrno) { -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {return RISCV_EXCP_NONE ; }@@ -4356,7 +4356,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, /* Physical Memory Protection */ - [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg, + [CSR_MSECCFG] = { "mseccfg", smepmp, read_mseccfg, write_mseccfg, .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },target/riscv/pmp.c +6
-6@@ -87,7 +87,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)if (pmp_index <MAX_RISCV_PMPS ) {bool locked = true; -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET (env)) { locked = false;@@ -337,9 +337,9 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* * Convert the PMP permissions to match the truth table in the -* ePMP spec. +* SMEPMP spec. */ -const uint8_t epmp_operation = +const uint8_t smepmp_operation = ((env->pmp_state.pmp[i].cfg_reg &PMP_LOCK ) >>4 ) | ((env->pmp_state.pmp[i].cfg_reg &PMP_READ ) <<2 ) | (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |@@ -364,7 +364,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,* If mseccfg.MML Bit set, do the enhanced pmp priv check */ if (mode ==PRV_M ) { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 1 :case 4 :@@ -395,7 +395,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,g_assert_not_reached (); } }else { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 8 :case 9 :@@ -576,7 +576,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val) } } -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* Sticky bits */ val |= (env->mseccfg & (MSECCFG_MMWP |MSECCFG_MML ));if ((val ^ env->mseccfg) & (MSECCFG_MMWP |MSECCFG_MML )) {
Quoted 26 lines · Himanshu Chauhan
Smepmp is a ratified extension which qemu refers to as epmp. Rename epmp to smepmp and add it to extension list so that it is added to the isa string.
Signed-off-by Himanshu Chauhan <[email protected]>--- target/riscv/cpu.c | 9 +++++---- target/riscv/cpu_cfg.h | 2 +- target/riscv/csr.c | 6 +++--- target/riscv/pmp.c | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-)target/riscv/cpu.c +1
-0@@ -127,6 +127,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (svinval,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot,PRIV_VERSION_1_12_0 , ext_svnapot),ISA_EXT_DATA_ENTRY (svpbmt,PRIV_VERSION_1_12_0 , ext_svpbmt), +ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp),ISA_EXT_DATA_ENTRY (xtheadba,PRIV_VERSION_1_11_0 , ext_xtheadba),ISA_EXT_DATA_ENTRY (xtheadbb,PRIV_VERSION_1_11_0 , ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs),
target/riscv/cpu.c static void rv32_ibex_cpu_init(Object *obj) · line 552
Quoted 6 lines
target/riscv/cpu.c +1
-1@@ -547,7 +548,7 @@ static void rv32_ibex_cpu_init(Object *obj)#ifndef CONFIG_USER_ONLY set_satp_mode_max_supported (cpu,VM_1_10_MBARE );#endif - cpu->cfg.epmp = true; + cpu->cfg.ext_smepmp = true;
Should also update Ibex CPU to priv level 1.12 otherwise Smepmp will be disabled since it is now declared PRIV_VERSION_1_12_0 in isa_edata_arr.
Quoted 6 lines
target/riscv/cpu.c +0
-0/* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei = true;@@ -1336,12 +1337,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)return ; }
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 1347
Quoted 10 lines
target/riscv/cpu.c +2
-2-if (cpu->cfg.epmp && !cpu->cfg.pmp) { +if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available * on harts with PMP support */ -error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +error_setg (errp,"Invalid configuration: SMEPMP requires PMP support" );return ; }
Nitpick: the spec uses "Smepmp", not "SMEPMP".
target/riscv/cpu.c static Property riscv_cpu_extensions[] = { · line 1683
Quoted 10 lines
target/riscv/cpu.c +1
-1@@ -1676,7 +1677,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false),/* ePMP 0.9.3 */ -DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("smepmp" ,RISCVCPU , cfg.ext_smepmp, false),DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), DEFINE_PROP_BOOL("x-ssaia", RISCVCPU, cfg.ext_ssaia, false),
You missed the comment update but maybe just move the definition next to pmp and drop the comment since it's now ratified?
Quoted 59 lines
target/riscv/cpu_cfg.h +1
-1@@ -87,6 +87,7 @@ struct RISCVCPUConfig {bool ext_zvfh;bool ext_zvfhmin;bool ext_smaia; +bool ext_smepmp;bool ext_ssaia;bool ext_sscofpmf;bool rvv_ta_all_1s;@@ -121,7 +122,6 @@ struct RISCVCPUConfig {uint16_t cboz_blocksize;bool mmu;bool pmp; -bool epmp;bool debug;bool misa_w;target/riscv/csr.c +3
-3@@ -523,9 +523,9 @@ static RISCVException pmp(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } -static RISCVException epmp (CPURISCVState *env,int csrno) +static RISCVException smepmp (CPURISCVState *env,int csrno) { -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {return RISCV_EXCP_NONE ; }@@ -4356,7 +4356,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, /* Physical Memory Protection */ - [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg, + [CSR_MSECCFG] = { "mseccfg", smepmp, read_mseccfg, write_mseccfg, .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },target/riscv/pmp.c +1
-1@@ -87,7 +87,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)if (pmp_index <MAX_RISCV_PMPS ) {bool locked = true; -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET (env)) { locked = false;
target/riscv/pmp.c bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, · line 341
Quoted 6 lines
target/riscv/pmp.c +1
-1@@ -337,9 +337,9 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* * Convert the PMP permissions to match the truth table in the -* ePMP spec. +* SMEPMP spec. */
Smepmp
Quoted 36 lines
target/riscv/pmp.c +4
-5-const uint8_t epmp_operation = +const uint8_t smepmp_operation = ((env->pmp_state.pmp[i].cfg_reg &PMP_LOCK ) >>4 ) | ((env->pmp_state.pmp[i].cfg_reg &PMP_READ ) <<2 ) | (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |@@ -364,7 +364,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,* If mseccfg.MML Bit set, do the enhanced pmp priv check */ if (mode ==PRV_M ) { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 1 :case 4 :@@ -395,7 +395,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,g_assert_not_reached (); } }else { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 8 :case 9 :@@ -576,7 +576,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val) } } -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* Sticky bits */ val |= (env->mseccfg & (MSECCFG_MMWP |MSECCFG_MML ));if ((val ^ env->mseccfg) & (MSECCFG_MMWP |MSECCFG_MML )) { --2.34.1
Quoted 29 lines · Loïc Lefort
Quoted 27 lines · Himanshu Chauhan
Smepmp is a ratified extension which qemu refers to as epmp. Rename epmp to smepmp and add it to extension list so that it is added to the isa string.
Signed-off-by Himanshu Chauhan <[email protected]>--- target/riscv/cpu.c | 9 +++++---- target/riscv/cpu_cfg.h | 2 +- target/riscv/csr.c | 6 +++--- target/riscv/pmp.c | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-)target/riscv/cpu.c +1
-0@@ -127,6 +127,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (svinval,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot,PRIV_VERSION_1_12_0 , ext_svnapot),ISA_EXT_DATA_ENTRY (svpbmt,PRIV_VERSION_1_12_0 , ext_svpbmt), +ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp),ISA_EXT_DATA_ENTRY (xtheadba,PRIV_VERSION_1_11_0 , ext_xtheadba),ISA_EXT_DATA_ENTRY (xtheadbb,PRIV_VERSION_1_11_0 , ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs),@@ -547,7 +548,7 @@ static void rv32_ibex_cpu_init(Object *obj)#ifndef CONFIG_USER_ONLY
Quoted 8 lines
target/riscv/cpu.c static void rv32_ibex_cpu_init(Object *obj) · line 552
Quoted 5 lines
target/riscv/cpu.c +1
-1set_satp_mode_max_supported (cpu,VM_1_10_MBARE );#endif - cpu->cfg.epmp = true; + cpu->cfg.ext_smepmp = true;Should also update Ibex CPU to priv level 1.12 otherwise Smepmp will be disabled since it is now declared
PRIV_VERSION_1_12_0inisa_edata_arr.
(--- added Alistair in CC since he added the Ibex CPU back in 2020 ---)
Good point. Commit ed6eebaaafd states that the Ibex CPU has ePMP support and this patch would break it.
I suggest changing the priv_version in a separated patch to facilitate future rebases/bisects.
Thanks,
Daniel
Quoted 136 lines
Quoted 7 lines
target/riscv/cpu.c +0
-0/* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei = true;@@ -1336,12 +1337,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)return ; }target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 1347
Quoted 10 lines
target/riscv/cpu.c +2
-2-if (cpu->cfg.epmp && !cpu->cfg.pmp) { +if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available * on harts with PMP support */ -error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +error_setg (errp,"Invalid configuration: SMEPMP requires PMP support" );return ; }Nitpick: the spec uses "Smepmp", not "SMEPMP".
target/riscv/cpu.c static Property riscv_cpu_extensions[] = { · line 1683
Quoted 10 lines
target/riscv/cpu.c +1
-1@@ -1676,7 +1677,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false),/* ePMP 0.9.3 */ -DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("smepmp" ,RISCVCPU , cfg.ext_smepmp, false),DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), DEFINE_PROP_BOOL("x-ssaia", RISCVCPU, cfg.ext_ssaia, false),You missed the comment update but maybe just move the definition next to pmp and drop the comment since it's now ratified?
Quoted 59 lines
target/riscv/cpu_cfg.h +1
-1@@ -87,6 +87,7 @@ struct RISCVCPUConfig {bool ext_zvfh;bool ext_zvfhmin;bool ext_smaia; +bool ext_smepmp;bool ext_ssaia;bool ext_sscofpmf;bool rvv_ta_all_1s;@@ -121,7 +122,6 @@ struct RISCVCPUConfig {uint16_t cboz_blocksize;bool mmu;bool pmp; -bool epmp;bool debug;bool misa_w;target/riscv/csr.c +3
-3@@ -523,9 +523,9 @@ static RISCVException pmp(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } -static RISCVException epmp (CPURISCVState *env,int csrno) +static RISCVException smepmp (CPURISCVState *env,int csrno) { -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {return RISCV_EXCP_NONE ; }@@ -4356,7 +4356,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, /* Physical Memory Protection */ - [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg, + [CSR_MSECCFG] = { "mseccfg", smepmp, read_mseccfg, write_mseccfg, .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },target/riscv/pmp.c +1
-1@@ -87,7 +87,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)if (pmp_index <MAX_RISCV_PMPS ) {bool locked = true; -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET (env)) { locked = false;target/riscv/pmp.c bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, · line 341
Quoted 6 lines
target/riscv/pmp.c +1
-1@@ -337,9 +337,9 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* * Convert the PMP permissions to match the truth table in the -* ePMP spec. +* SMEPMP spec. */ Smepmp
Quoted 36 lines
target/riscv/pmp.c +4
-5-const uint8_t epmp_operation = +const uint8_t smepmp_operation = ((env->pmp_state.pmp[i].cfg_reg &PMP_LOCK ) >>4 ) | ((env->pmp_state.pmp[i].cfg_reg &PMP_READ ) <<2 ) | (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |@@ -364,7 +364,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,* If mseccfg.MML Bit set, do the enhanced pmp priv check */ if (mode ==PRV_M ) { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 1 :case 4 :@@ -395,7 +395,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,g_assert_not_reached (); } }else { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 8 :case 9 :@@ -576,7 +576,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val) } } -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* Sticky bits */ val |= (env->mseccfg & (MSECCFG_MMWP |MSECCFG_MML ));if ((val ^ env->mseccfg) & (MSECCFG_MMWP |MSECCFG_MML )) { --2.34.1
Quoted 42 lines · Daniel Henrique Barboza
Quoted 29 lines · Loïc Lefort
Quoted 27 lines · Himanshu Chauhan
Smepmp is a ratified extension which qemu refers to as epmp. Rename epmp to smepmp and add it to extension list so that it is added to the isa string.
Signed-off-by Himanshu Chauhan <[email protected]>--- target/riscv/cpu.c | 9 +++++---- target/riscv/cpu_cfg.h | 2 +- target/riscv/csr.c | 6 +++--- target/riscv/pmp.c | 12 ++++++------ 4 files changed, 15 insertions(+), 14 deletions(-)target/riscv/cpu.c +1
-0@@ -127,6 +127,7 @@ static const struct isa_ext_data isa_edata_arr[] = {ISA_EXT_DATA_ENTRY (svinval,PRIV_VERSION_1_12_0 , ext_svinval),ISA_EXT_DATA_ENTRY (svnapot,PRIV_VERSION_1_12_0 , ext_svnapot),ISA_EXT_DATA_ENTRY (svpbmt,PRIV_VERSION_1_12_0 , ext_svpbmt), +ISA_EXT_DATA_ENTRY (smepmp,PRIV_VERSION_1_12_0 , ext_smepmp),ISA_EXT_DATA_ENTRY (xtheadba,PRIV_VERSION_1_11_0 , ext_xtheadba),ISA_EXT_DATA_ENTRY (xtheadbb,PRIV_VERSION_1_11_0 , ext_xtheadbb), ISA_EXT_DATA_ENTRY(xtheadbs, PRIV_VERSION_1_11_0, ext_xtheadbs),@@ -547,7 +548,7 @@ static void rv32_ibex_cpu_init(Object *obj)#ifndef CONFIG_USER_ONLY Quoted 8 lines
target/riscv/cpu.c static void rv32_ibex_cpu_init(Object *obj) · line 552
Quoted 5 lines
target/riscv/cpu.c +1
-1set_satp_mode_max_supported (cpu,VM_1_10_MBARE );#endif - cpu->cfg.epmp = true; + cpu->cfg.ext_smepmp = true;Should also update Ibex CPU to priv level 1.12 otherwise Smepmp will be disabled since it is now declared
PRIV_VERSION_1_12_0inisa_edata_arr.
Quoted 7 lines
(--- added Alistair in CC since he added the Ibex CPU back in 2020 ---)
Good point. Commit
ed6eebaaafdstates that the Ibex CPU has ePMP support and this patch would break it.I suggest changing the
priv_versionin a separated patch to facilitate future rebases/bisects.
Agreed!
Thanks for the patch as well, I have been meaning to get around to fix this
Alistair
Quoted 145 lines
Thanks,
Daniel
Quoted 136 lines
Quoted 7 lines
target/riscv/cpu.c +0
-0/* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei = true;@@ -1336,12 +1337,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)return ; }target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 1347
Quoted 10 lines
target/riscv/cpu.c +2
-2-if (cpu->cfg.epmp && !cpu->cfg.pmp) { +if (cpu->cfg.ext_smepmp && !cpu->cfg.pmp) {/* * Enhanced PMP should only be available * on harts with PMP support */ -error_setg (errp,"Invalid configuration: EPMP requires PMP support" ); +error_setg (errp,"Invalid configuration: SMEPMP requires PMP support" );return ; }Nitpick: the spec uses "Smepmp", not "SMEPMP".
target/riscv/cpu.c static Property riscv_cpu_extensions[] = { · line 1683
Quoted 10 lines
target/riscv/cpu.c +1
-1@@ -1676,7 +1677,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false),/* ePMP 0.9.3 */ -DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("smepmp" ,RISCVCPU , cfg.ext_smepmp, false),DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), DEFINE_PROP_BOOL("x-ssaia", RISCVCPU, cfg.ext_ssaia, false),You missed the comment update but maybe just move the definition next to pmp and drop the comment since it's now ratified?
Quoted 59 lines
target/riscv/cpu_cfg.h +1
-1@@ -87,6 +87,7 @@ struct RISCVCPUConfig {bool ext_zvfh;bool ext_zvfhmin;bool ext_smaia; +bool ext_smepmp;bool ext_ssaia;bool ext_sscofpmf;bool rvv_ta_all_1s;@@ -121,7 +122,6 @@ struct RISCVCPUConfig {uint16_t cboz_blocksize;bool mmu;bool pmp; -bool epmp;bool debug;bool misa_w;target/riscv/csr.c +3
-3@@ -523,9 +523,9 @@ static RISCVException pmp(CPURISCVState *env, int csrno)return RISCV_EXCP_ILLEGAL_INST ; } -static RISCVException epmp (CPURISCVState *env,int csrno) +static RISCVException smepmp (CPURISCVState *env,int csrno) { -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {return RISCV_EXCP_NONE ; }@@ -4356,7 +4356,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, /* Physical Memory Protection */ - [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg, + [CSR_MSECCFG] = { "mseccfg", smepmp, read_mseccfg, write_mseccfg, .min_priv_ver = PRIV_VERSION_1_11_0 }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg },target/riscv/pmp.c +1
-1@@ -87,7 +87,7 @@ static bool pmp_write_cfg(CPURISCVState *env, uint32_t pmp_index, uint8_t val)if (pmp_index <MAX_RISCV_PMPS ) {bool locked = true; -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* mseccfg.RLB is set */ if (MSECCFG_RLB_ISSET (env)) { locked = false;target/riscv/pmp.c bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, · line 341
Quoted 6 lines
target/riscv/pmp.c +1
-1@@ -337,9 +337,9 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,/* * Convert the PMP permissions to match the truth table in the -* ePMP spec. +* SMEPMP spec. */ Smepmp
Quoted 36 lines
target/riscv/pmp.c +4
-5-const uint8_t epmp_operation = +const uint8_t smepmp_operation = ((env->pmp_state.pmp[i].cfg_reg &PMP_LOCK ) >>4 ) | ((env->pmp_state.pmp[i].cfg_reg &PMP_READ ) <<2 ) | (env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |@@ -364,7 +364,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,* If mseccfg.MML Bit set, do the enhanced pmp priv check */ if (mode ==PRV_M ) { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 1 :case 4 :@@ -395,7 +395,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,g_assert_not_reached (); } }else { -switch (epmp_operation) { +switch (smepmp_operation) {case 0 :case 8 :case 9 :@@ -576,7 +576,7 @@ void mseccfg_csr_write(CPURISCVState *env, target_ulong val) } } -if (riscv_cpu_cfg (env)->epmp) { +if (riscv_cpu_cfg (env)->ext_smepmp) {/* Sticky bits */ val |= (env->mseccfg & (MSECCFG_MMWP |MSECCFG_MML ));if ((val ^ env->mseccfg) & (MSECCFG_MMWP |MSECCFG_MML )) { --2.34.1