target/riscv: Support configuarable marchid, mvendorid, mipid CSR values
PATCH 1/1 target/riscv: Support configuarable marchid, mvendorid, mipid CSR values
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)
target/riscv/cpu.c +4 -0
@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), +DEFINE_PROP_UINT64 ("mipid" ,RISCVCPU , cfg.mipid,0 ), +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),
target/riscv/cpu.h +4 -0
@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;
target/riscv/csr.c +34 -4
@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {
@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL,
Signature · 1 line
2.35.1
Quoted 19 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 6 lines
target/riscv/cpu.c +3
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),
Should we have non-zero defaults here?
Alistair
Quoted 79 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;target/riscv/csr.c +34
-5@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID ] = {"mhartid" , any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL, --2.35.1
Quoted 24 lines · Alistair Francis
Quoted 22 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
Quoted 5 lines
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 3 lines
target/riscv/cpu.c +3
-0+DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),Should we have non-zero defaults here?
To do that, we need mvendorid for QEMU RISC-V.
The marchid and mipid can be based on the QEMU version number.
Regards,
Anup
Quoted 83 lines
Alistair
Quoted 79 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;target/riscv/csr.c +34
-5@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID ] = {"mhartid" , any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL, --2.35.1
Quoted 32 lines · Anup Patel
Quoted 24 lines · Alistair Francis
Quoted 22 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),Quoted 5 lines
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 3 lines
target/riscv/cpu.c +3
-0+DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),Should we have non-zero defaults here?
Quoted 7 lines
To do that, we need mvendorid for QEMU RISC-V.
The marchid and mipid can be based on the QEMU version number.
Regards,
Anup
The original intention for this patch is to allow users to define their own $mvendorid, $marchid, and $mipid through the command line when they initiate QEMU.
If we want to provide the default values for QEMU RISC-V CPU, just like what Anup said.
We need to define our own mvendorid, which should be a JEDEC manufacturer ID.
(Perhaps it's fine to just give some random legal JEDEC manufacturer ID as I don't think we would really want to spend the money on that.)
For $marchid and $mipid,
I agree that it could base on QEMU's version from the QEMU_FULL_VERSION macro.
(and $marchid should have MSB set to 1 for open-source projects.)
Regards,
Frank Chang
Quoted 88 lines
Quoted 23 lines
Alistair
Quoted 19 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;Quoted 5 lines
target/riscv/csr.c static RISCVException write_ignore(CPURISCVState
Quoted 5 lines
target/riscv/csr.c +0
-0@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState*env, int csrno,
Quoted 29 lines
Quoted 29 lines
target/riscv/csr.c +26
-0return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); +Quoted 8 lines
target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =
Quoted 8 lines
target/riscv/csr.c +4
-0+ *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] ={
Quoted 12 lines
Quoted 12 lines
target/riscv/csr.c +4
-4[CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid },Quoted 2 lines
target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = · line 3137
Quoted 2 lines
target/riscv/csr.c +0
-0/* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus,
write_mstatus, NULL,Quoted 5 lines
Quoted 4 lines
--
2.35.1
Quoted 54 lines · Frank Chang
Quoted 32 lines · Anup Patel
Quoted 24 lines · Alistair Francis
Quoted 22 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),Quoted 5 lines
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 3 lines
target/riscv/cpu.c +3
-0+DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),Should we have non-zero defaults here?
Quoted 7 lines
To do that, we need mvendorid for QEMU RISC-V.
The marchid and mipid can be based on the QEMU version number.
Regards,
AnupThe original intention for this patch is to allow users to define their own $mvendorid, $marchid, and $mipid through the command line when they initiate QEMU.
If we want to provide the default values for QEMU RISC-V CPU, just like what Anup said.
We need to define our own mvendorid, which should be a JEDEC manufacturer ID.
(Perhaps it's fine to just give some random legal JEDEC manufacturer ID as I don't think we would really want to spend the money on that.)
Quoted 8 lines
For $marchid and $mipid,
I agree that it could base on QEMU's version from theQEMU_FULL_VERSIONmacro.
(and $marchid should have MSB set to 1 for open-source projects.)Regards,
Frank Chang
Another simpler way is to stick with the current approach and leave $mvendorid, $marchid and $mipid default to 0. Which is still legal as RISC-V privilege spec says:
"A value of 0 can be returned to indicate the field is not implemented."
Regards,
Frank Chang
Quoted 91 lines
Quoted 90 lines
Quoted 25 lines
Alistair
Quoted 19 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;Quoted 5 lines
target/riscv/csr.c static RISCVException write_ignore(CPURISCVState
Quoted 5 lines
target/riscv/csr.c +0
-0@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState*env, int csrno,
Quoted 29 lines
Quoted 29 lines
target/riscv/csr.c +26
-0return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); +Quoted 8 lines
target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE]
Quoted 8 lines
target/riscv/csr.c +4
-0+ *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE]= {
Quoted 12 lines
Quoted 12 lines
target/riscv/csr.c +4
-4[CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid },Quoted 2 lines
target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] · line 3137
Quoted 2 lines
target/riscv/csr.c +0
-0/* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus,
write_mstatus, NULL,Quoted 5 lines
Quoted 4 lines
--
2.35.1
Quoted 48 lines · Frank Chang
Quoted 46 lines · Frank Chang
Quoted 32 lines · Anup Patel
Quoted 24 lines · Alistair Francis
Quoted 22 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),Quoted 5 lines
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 3 lines
target/riscv/cpu.c +3
-0+DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),Should we have non-zero defaults here?
Quoted 6 lines
To do that, we need mvendorid for QEMU RISC-V.
The marchid and mipid can be based on the QEMU version number.
Regards,
AnupThe original intention for this patch is to allow users to define their own $mvendorid, $marchid, and $mipid through the command line when they initiate QEMU.
Quoted 5 lines
Quoted 5 lines
If we want to provide the default values for QEMU RISC-V CPU, just like what Anup said.
We need to define our own mvendorid, which should be a JEDEC manufacturer ID. (Perhaps it's fine to just give some random legal JEDEC manufacturer ID as I don't think we would really want to spend the money on that.)
This is fine as zero I think.
Quoted 4 lines
Quoted 4 lines
For $marchid and $mipid,
I agree that it could base on QEMU's version from theQEMU_FULL_VERSIONmacro. (and $marchid should have MSB set to 1 for open-source projects.)
There could be some use in setting this to the QEMU version by default. It doesn't really get us much though, but might be useful.
I'll take this patch as is, feel free to send a new patch if you want to add a default value
Alistair
Quoted 100 lines
Quoted 3 lines
Regards,
Frank ChangAnother simpler way is to stick with the current approach and leave $mvendorid, $marchid and $mipid default to 0. Which is still legal as RISC-V privilege spec says:
"A value of 0 can be returned to indicate the field is not implemented."Regards,
Frank ChangQuoted 87 lines
Quoted 87 lines
Quoted 87 lines
Alistair
Quoted 79 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;target/riscv/csr.c +34
-5@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID ] = {"mhartid" , any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL, --2.35.1
Quoted 68 lines · Alistair Francis
Quoted 2 lines · Frank Chang
On Tue, Apr 19, 2022 at 2:00 PM Frank Chang <[email protected]>
Quoted 2 lines · wrote:
Quoted 2 lines
On Tue, Apr 19, 2022 at 1:27 PM Anup Patel <[email protected]>
Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines
On Tue, Apr 19, 2022 at 10:52 AM Alistair Francis <
Quoted 38 lines · [email protected]> wrote:
Quoted 38 lines
Quoted 36 lines
Quoted 24 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
Quoted 22 lines
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),Quoted 5 lines
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 3 lines
target/riscv/cpu.c +3
-0+DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),Should we have non-zero defaults here?
To do that, we need mvendorid for QEMU RISC-V.
The marchid and mipid can be based on the QEMU version number.
Regards,
AnupQuoted 7 lines
Quoted 7 lines
The original intention for this patch is to allow users to define their own $mvendorid, $marchid, and $mipid through the command line when they initiate QEMU.
If we want to provide the default values for QEMU RISC-V CPU, just like what Anup said.
We need to define our own mvendorid, which should be a JEDECmanufacturer ID.
Quoted 2 lines
Quoted 2 lines
(Perhaps it's fine to just give some random legal JEDEC manufacturer ID as I don't think we would really want to spend the money on that.)
This is fine as zero I think.
Quoted 3 lines
Quoted 3 lines
For $marchid and $mipid,
I agree that it could base on QEMU's version from theQEMU_FULL_VERSIONmacro.
Quoted 1 line
Quoted 1 line
(and $marchid should have MSB set to 1 for open-source projects.)
Quoted 8 lines
There could be some use in setting this to the QEMU version by default. It doesn't really get us much though, but might be useful.
I'll take this patch as is, feel free to send a new patch if you want to add a default value
Alistair
Sure, I'll set QEMU version by default in the next version patchset.
Regards,
Frank Chang
Quoted 106 lines
Quoted 40 lines
Quoted 4 lines
Regards,
Frank ChangAnother simpler way is to stick with the current approach and leave $mvendorid, $marchid and $mipid default to 0. Which is still legal as RISC-V privilege spec says:
"A value of 0 can be returned to indicate the field is not implemented."Regards,
Frank ChangQuoted 26 lines
Quoted 26 lines
Quoted 26 lines
Alistair
Quoted 19 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
target/riscv/csr.c static RISCVException
Quoted 5 lines
target/riscv/csr.c +0
-0@@ -603,6 +603,36 @@ static RISCVExceptionwrite_ignore(CPURISCVState *env, int csrno,
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
target/riscv/csr.c static RISCVException write_ignore(CPURISCVState *env, int csrno,
Quoted 4 lines
target/riscv/csr.c +1
-0return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid(CPURISCVState *env, intcsrno,
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
target/riscv/csr.c +25
-0+ target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); +Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
target/riscv/csr.c riscv_csr_operations
Quoted 8 lines
target/riscv/csr.c +4
-0+ *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operationscsr_ops[CSR_TABLE_SIZE] = {
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
target/riscv/csr.c +4
-4[CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid },Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
target/riscv/csr.c riscv_csr_operations · line 3137
Quoted 2 lines
target/riscv/csr.c +0
-0/* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus,
write_mstatus, NULL,Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
--
2.35.1
Quoted 54 lines · Frank Chang
Quoted 32 lines · Anup Patel
Quoted 24 lines · Alistair Francis
Quoted 22 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +0
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ), DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),Quoted 5 lines
target/riscv/cpu.c static Property riscv_cpu_properties[] = { · line 791
Quoted 3 lines
target/riscv/cpu.c +3
-0+DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, 0),Should we have non-zero defaults here?
Quoted 7 lines
To do that, we need mvendorid for QEMU RISC-V.
The marchid and mipid can be based on the QEMU version number.
Regards,
AnupThe original intention for this patch is to allow users to define their own $mvendorid, $marchid, and $mipid through the command line when they initiate QEMU.
If we want to provide the default values for QEMU RISC-V CPU, just like what Anup said.
We need to define our own mvendorid, which should be a JEDEC manufacturer ID.
(Perhaps it's fine to just give some random legal JEDEC manufacturer ID as I don't think we would really want to spend the money on that.)
Quoted 5 lines
For $marchid and $mipid,
I agree that it could base on QEMU's version from theQEMU_FULL_VERSIONmacro.
(and $marchid should have MSB set to 1 for open-source projects.)
Sorry, I made a mistake.
The MSB of $marchid should be cleared for open source projects:
"Open-source project architecture IDs are allocated globally by the RISC-V Foundation, and have
non-zero architecture IDs with a zero most-significant-bit (MSB). Commercial architecture IDs are
allocated by each commercial vendor independently, but must have the MSB set and cannot contain
zero in the remaining MXLEN-1 bits."
Regards,
Frank Chang
Quoted 94 lines
Regards,
Frank ChangQuoted 88 lines
Quoted 23 lines
Alistair
Quoted 19 lines
target/riscv/cpu.c +1
-0+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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;Quoted 5 lines
target/riscv/csr.c static RISCVException write_ignore(CPURISCVState
Quoted 5 lines
target/riscv/csr.c +0
-0@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState*env, int csrno,
Quoted 29 lines
Quoted 29 lines
target/riscv/csr.c +26
-0return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); +Quoted 8 lines
target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE]
Quoted 8 lines
target/riscv/csr.c +4
-0+ *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE]= {
Quoted 12 lines
Quoted 12 lines
target/riscv/csr.c +4
-4[CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid },Quoted 2 lines
target/riscv/csr.c riscv_csr_operations csr_ops[CSR_TABLE_SIZE] · line 3137
Quoted 2 lines
target/riscv/csr.c +0
-0/* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus,
write_mstatus, NULL,Quoted 5 lines
Quoted 4 lines
--
2.35.1
Quoted 8 lines · On Fri, Apr 15, 2022 at 7:37 PM <[email protected]> wrote:
From: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
Signed-off-by Frank Chang <[email protected]>Reviewed-by Jim Shu <[email protected]>
Alistair
Quoted 96 lines
--- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 4 ++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-)target/riscv/cpu.c +4
-0@@ -786,6 +786,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,0 ), +DEFINE_PROP_UINT64 ("mipid" ,RISCVCPU , cfg.mipid,0 ), +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),target/riscv/cpu.h +4
-0@@ -370,6 +370,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;target/riscv/csr.c +34
-5@@ -603,6 +603,36 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {@@ -3098,10 +3128,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID ] = {"mhartid" , any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL, --2.35.1