... | ... | ||
---|---|---|---|
32 | while patch3 adds stateen bits validation for AIA. | 32 | while patch3 adds stateen bits validation for AIA. |
33 | The PATCH4 implements indirect CSR extensions while remaining patches | 33 | The PATCH4 implements indirect CSR extensions while remaining patches |
34 | implement the counter delegation extensions. | 34 | implement the counter delegation extensions. |
35 | 35 | ||
36 | The Qemu patches can be found here: | 36 | The Qemu patches can be found here: |
37 | https://github.com/atishp04/qemu/tree/b4/counter_delegation_v3 | 37 | https://github.com/atishp04/qemu/tree/b4/counter_delegation_v4 |
38 | The Linux kernel patches can be found here (WIP version due to onging upstream | 38 | The Linux kernel patches can be found here (WIP version due to onging upstream |
39 | dependant patches): | 39 | dependant patches): |
40 | https://github.com/atishp04/linux/tree/b4/counter_delegation_v2 | 40 | https://github.com/atishp04/linux/tree/b4/counter_delegation_v2 |
41 | 41 | ||
42 | [1] https://github.com/riscv/riscv-indirect-csr-access | 42 | [1] https://github.com/riscv/riscv-indirect-csr-access |
43 | [2] https://github.com/riscv/riscv-smcdeleg-ssccfg | 43 | [2] https://github.com/riscv/riscv-smcdeleg-ssccfg |
44 | 44 | ||
45 | Cc: kaiwenxue1@gmail.com | 45 | Cc: kaiwenxue1@gmail.com |
46 | 46 | ||
47 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 47 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
48 | --- | 48 | --- |
49 | Changes in v5: | ||
50 | - Rebased on top of the riscv-to-apply.next | ||
51 | - Added RB/AB tags. | ||
52 | - Link to v4: https://lore.kernel.org/r/20241203-counter_delegation-v4-0-c12a89baed86@rivosinc.com | ||
53 | |||
54 | Changes in v4: | ||
55 | - Fixed the comments recieved on v3. | ||
56 | - code style comments and removed 1 redundant if else block. | ||
57 | - Link to v3: https://lore.kernel.org/r/20241117-counter_delegation-v3-0-476d6f36e3c8@rivosinc.com | ||
58 | |||
49 | Changes in v3: | 59 | Changes in v3: |
50 | 1. Updated the priv version in extensions | 60 | 1. Updated the priv version in extensions |
51 | 2. Fixed minor issues pointed out in v2. | 61 | 2. Fixed minor issues pointed out in v2. |
52 | 3. Dropped preferred rule and added an implied rule for AIA and counter | 62 | 3. Dropped preferred rule and added an implied rule for AIA and counter |
53 | delegation. | 63 | delegation. |
... | ... | ||
82 | 92 | ||
83 | target/riscv/cpu.c | 20 +- | 93 | target/riscv/cpu.c | 20 +- |
84 | target/riscv/cpu.h | 1 + | 94 | target/riscv/cpu.h | 1 + |
85 | target/riscv/cpu_bits.h | 34 ++- | 95 | target/riscv/cpu_bits.h | 34 ++- |
86 | target/riscv/cpu_cfg.h | 4 + | 96 | target/riscv/cpu_cfg.h | 4 + |
87 | target/riscv/csr.c | 721 ++++++++++++++++++++++++++++++++++++++++++--- | 97 | target/riscv/csr.c | 718 ++++++++++++++++++++++++++++++++++++++++++--- |
88 | target/riscv/machine.c | 1 + | 98 | target/riscv/machine.c | 1 + |
89 | target/riscv/tcg/tcg-cpu.c | 28 +- | 99 | target/riscv/tcg/tcg-cpu.c | 28 +- |
90 | 7 files changed, 756 insertions(+), 53 deletions(-) | 100 | 7 files changed, 753 insertions(+), 53 deletions(-) |
91 | --- | 101 | --- |
92 | base-commit: 27652f9ca9d831c67dd447346c6ee953669255f0 | 102 | base-commit: b74e358af21fddb93228c4aed22520950cbe9dd7 |
93 | change-id: 20240715-counter_delegation-10ab44c7d2c0 | 103 | change-id: 20240715-counter_delegation-10ab44c7d2c0 |
94 | -- | 104 | -- |
95 | Regards, | 105 | Regards, |
96 | Atish patra | 106 | Atish patra | diff view generated by jsdifflib |
1 | From: Kaiwen Xue <kaiwenx@rivosinc.com> | 1 | From: Kaiwen Xue <kaiwenx@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | This adds the properties for sxcsrind. Definitions of new registers and | 3 | This adds the properties for sxcsrind. Definitions of new registers and |
4 | implementations will come with future patches. | 4 | implementations will come with future patches. |
5 | 5 | ||
6 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> | ||
7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 9 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
7 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> | ||
8 | --- | 10 | --- |
9 | target/riscv/cpu.c | 2 ++ | 11 | target/riscv/cpu.c | 2 ++ |
10 | target/riscv/cpu_cfg.h | 2 ++ | 12 | target/riscv/cpu_cfg.h | 2 ++ |
11 | 2 files changed, 4 insertions(+) | 13 | 2 files changed, 4 insertions(+) |
12 | 14 | ||
13 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/cpu.c | 17 | --- a/target/riscv/cpu.c |
16 | +++ b/target/riscv/cpu.c | 18 | +++ b/target/riscv/cpu.c |
17 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 19 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
18 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), | 20 | ISA_EXT_DATA_ENTRY(shvstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), |
19 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), | 21 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), |
20 | ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), | 22 | ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), |
21 | + ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind), | 23 | + ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind), |
22 | ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), | 24 | ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), |
23 | ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), | 25 | ISA_EXT_DATA_ENTRY(smrnmi, PRIV_VERSION_1_12_0, ext_smrnmi), |
24 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), | 26 | ISA_EXT_DATA_ENTRY(smmpm, PRIV_VERSION_1_13_0, ext_smmpm), |
27 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | ||
25 | ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), | 28 | ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), |
26 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), | 29 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), |
27 | ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), | 30 | ISA_EXT_DATA_ENTRY(sscounterenw, PRIV_VERSION_1_12_0, has_priv_1_12), |
28 | + ISA_EXT_DATA_ENTRY(sscsrind, PRIV_VERSION_1_12_0, ext_sscsrind), | 31 | + ISA_EXT_DATA_ENTRY(sscsrind, PRIV_VERSION_1_12_0, ext_sscsrind), |
32 | ISA_EXT_DATA_ENTRY(ssnpm, PRIV_VERSION_1_13_0, ext_ssnpm), | ||
33 | ISA_EXT_DATA_ENTRY(ssstateen, PRIV_VERSION_1_12_0, ext_ssstateen), | ||
29 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), | 34 | ISA_EXT_DATA_ENTRY(sstc, PRIV_VERSION_1_12_0, ext_sstc), |
30 | ISA_EXT_DATA_ENTRY(sstvala, PRIV_VERSION_1_12_0, has_priv_1_12), | ||
31 | ISA_EXT_DATA_ENTRY(sstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), | ||
32 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | 35 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
33 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/riscv/cpu_cfg.h | 37 | --- a/target/riscv/cpu_cfg.h |
35 | +++ b/target/riscv/cpu_cfg.h | 38 | +++ b/target/riscv/cpu_cfg.h |
36 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 39 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
13 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 13 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
14 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/csr.c | 15 | --- a/target/riscv/csr.c |
16 | +++ b/target/riscv/csr.c | 16 | +++ b/target/riscv/csr.c |
17 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ |
18 | #include "sysemu/cpu-timers.h" | 18 | #include "system/cpu-timers.h" |
19 | #include "qemu/guest-random.h" | 19 | #include "qemu/guest-random.h" |
20 | #include "qapi/error.h" | 20 | #include "qapi/error.h" |
21 | +#include <stdbool.h> | 21 | +#include <stdbool.h> |
22 | 22 | ||
23 | /* CSR function table public API */ | 23 | /* CSR function table public API */ |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
59 | + } | 59 | + } |
60 | + | 60 | + |
61 | return smode32(env, csrno); | 61 | return smode32(env, csrno); |
62 | } | 62 | } |
63 | 63 | ||
64 | @@ -XXX,XX +XXX,XX @@ static RISCVException pointer_masking(CPURISCVState *env, int csrno) | 64 | @@ -XXX,XX +XXX,XX @@ static RISCVException hgatp(CPURISCVState *env, int csrno) |
65 | 65 | ||
66 | static RISCVException aia_hmode(CPURISCVState *env, int csrno) | 66 | static RISCVException aia_hmode(CPURISCVState *env, int csrno) |
67 | { | 67 | { |
68 | + int ret; | 68 | + int ret; |
69 | + | 69 | + |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
4 | and the operations on them. Note that xiselect and xireg are used for | 4 | and the operations on them. Note that xiselect and xireg are used for |
5 | both AIA and sxcsrind, and the behavior of accessing them depends on | 5 | both AIA and sxcsrind, and the behavior of accessing them depends on |
6 | whether each extension is enabled and the value stored in xiselect. | 6 | whether each extension is enabled and the value stored in xiselect. |
7 | 7 | ||
8 | Co-developed-by: Atish Patra <atishp@rivosinc.com> | 8 | Co-developed-by: Atish Patra <atishp@rivosinc.com> |
9 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> | ||
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 12 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
10 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> | ||
11 | --- | 13 | --- |
12 | target/riscv/cpu_bits.h | 28 ++++++++- | 14 | target/riscv/cpu_bits.h | 28 +++++++++- |
13 | target/riscv/csr.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++-- | 15 | target/riscv/csr.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++-- |
14 | 2 files changed, 171 insertions(+), 6 deletions(-) | 16 | 2 files changed, 166 insertions(+), 6 deletions(-) |
15 | 17 | ||
16 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | 18 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
17 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/cpu_bits.h | 20 | --- a/target/riscv/cpu_bits.h |
19 | +++ b/target/riscv/cpu_bits.h | 21 | +++ b/target/riscv/cpu_bits.h |
... | ... | ||
83 | return any32(env, csrno); | 85 | return any32(env, csrno); |
84 | } | 86 | } |
85 | 87 | ||
86 | +static RISCVException csrind_any(CPURISCVState *env, int csrno) | 88 | +static RISCVException csrind_any(CPURISCVState *env, int csrno) |
87 | +{ | 89 | +{ |
88 | + RISCVCPU *cpu = env_archcpu(env); | 90 | + if (!riscv_cpu_cfg(env)->ext_smcsrind) { |
89 | + | ||
90 | + if (!cpu->cfg.ext_smcsrind) { | ||
91 | + return RISCV_EXCP_ILLEGAL_INST; | 91 | + return RISCV_EXCP_ILLEGAL_INST; |
92 | + } | 92 | + } |
93 | + | 93 | + |
94 | + return RISCV_EXCP_NONE; | 94 | + return RISCV_EXCP_NONE; |
95 | +} | 95 | +} |
... | ... | ||
205 | + } | 205 | + } |
206 | + | 206 | + |
207 | + return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); | 207 | + return rmw_xireg_csrind(env, csrno, isel, val, new_val, wr_mask); |
208 | + | 208 | + |
209 | +done: | 209 | +done: |
210 | + if (ret) { | 210 | + return (env->virt_enabled && virt) ? |
211 | + return (env->virt_enabled && virt) ? | 211 | + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; |
212 | + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | ||
213 | + } | ||
214 | + return RISCV_EXCP_NONE; | ||
215 | +} | 212 | +} |
216 | + | 213 | + |
217 | static RISCVException rmw_xireg(CPURISCVState *env, int csrno, | 214 | static RISCVException rmw_xireg(CPURISCVState *env, int csrno, |
218 | target_ulong *val, target_ulong new_val, | 215 | target_ulong *val, target_ulong new_val, |
219 | target_ulong wr_mask) | 216 | target_ulong wr_mask) |
... | ... | diff view generated by jsdifflib |
1 | This adds the properties for counter delegation ISA extensions | 1 | This adds the properties for counter delegation ISA extensions |
---|---|---|---|
2 | (Smcdeleg/Ssccfg). Definitions of new registers and and implementation | 2 | (Smcdeleg/Ssccfg). Definitions of new registers and and implementation |
3 | will come in the next set of patches. | 3 | will come in the next set of patches. |
4 | 4 | ||
5 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 7 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
6 | --- | 8 | --- |
7 | target/riscv/cpu.c | 2 ++ | 9 | target/riscv/cpu.c | 2 ++ |
8 | target/riscv/cpu_cfg.h | 2 ++ | 10 | target/riscv/cpu_cfg.h | 2 ++ |
9 | 2 files changed, 4 insertions(+) | 11 | 2 files changed, 4 insertions(+) |
10 | 12 | ||
11 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 13 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/cpu.c | 15 | --- a/target/riscv/cpu.c |
14 | +++ b/target/riscv/cpu.c | 16 | +++ b/target/riscv/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | 17 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
16 | ISA_EXT_DATA_ENTRY(zhinx, PRIV_VERSION_1_12_0, ext_zhinx), | 18 | ISA_EXT_DATA_ENTRY(shvstvala, PRIV_VERSION_1_12_0, has_priv_1_12), |
17 | ISA_EXT_DATA_ENTRY(zhinxmin, PRIV_VERSION_1_12_0, ext_zhinxmin), | 19 | ISA_EXT_DATA_ENTRY(shvstvecd, PRIV_VERSION_1_12_0, has_priv_1_12), |
18 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), | 20 | ISA_EXT_DATA_ENTRY(smaia, PRIV_VERSION_1_12_0, ext_smaia), |
19 | + ISA_EXT_DATA_ENTRY(smcdeleg, PRIV_VERSION_1_13_0, ext_smcdeleg), | 21 | + ISA_EXT_DATA_ENTRY(smcdeleg, PRIV_VERSION_1_13_0, ext_smcdeleg), |
20 | ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), | 22 | ISA_EXT_DATA_ENTRY(smcntrpmf, PRIV_VERSION_1_12_0, ext_smcntrpmf), |
21 | ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind), | 23 | ISA_EXT_DATA_ENTRY(smcsrind, PRIV_VERSION_1_13_0, ext_smcsrind), |
22 | ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), | 24 | ISA_EXT_DATA_ENTRY(smepmp, PRIV_VERSION_1_12_0, ext_smepmp), |
25 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | ||
26 | ISA_EXT_DATA_ENTRY(smnpm, PRIV_VERSION_1_13_0, ext_smnpm), | ||
23 | ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), | 27 | ISA_EXT_DATA_ENTRY(smstateen, PRIV_VERSION_1_12_0, ext_smstateen), |
24 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), | 28 | ISA_EXT_DATA_ENTRY(ssaia, PRIV_VERSION_1_12_0, ext_ssaia), |
25 | + ISA_EXT_DATA_ENTRY(ssccfg, PRIV_VERSION_1_13_0, ext_ssccfg), | 29 | + ISA_EXT_DATA_ENTRY(ssccfg, PRIV_VERSION_1_13_0, ext_ssccfg), |
26 | ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), | 30 | ISA_EXT_DATA_ENTRY(ssccptr, PRIV_VERSION_1_11_0, has_priv_1_11), |
27 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), | 31 | ISA_EXT_DATA_ENTRY(sscofpmf, PRIV_VERSION_1_12_0, ext_sscofpmf), |
... | ... | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
37 | + | 37 | + |
38 | /* Supervisor Trap Handling */ | 38 | /* Supervisor Trap Handling */ |
39 | #define CSR_SSCRATCH 0x140 | 39 | #define CSR_SSCRATCH 0x140 |
40 | #define CSR_SEPC 0x141 | 40 | #define CSR_SEPC 0x141 |
41 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | 41 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
42 | #define MENVCFG_CBIE (3UL << 4) | ||
43 | #define MENVCFG_CBCFE BIT(6) | 42 | #define MENVCFG_CBCFE BIT(6) |
44 | #define MENVCFG_CBZE BIT(7) | 43 | #define MENVCFG_CBZE BIT(7) |
44 | #define MENVCFG_PMM (3ULL << 32) | ||
45 | +#define MENVCFG_CDE (1ULL << 60) | 45 | +#define MENVCFG_CDE (1ULL << 60) |
46 | #define MENVCFG_ADUE (1ULL << 61) | 46 | #define MENVCFG_ADUE (1ULL << 61) |
47 | #define MENVCFG_PBMTE (1ULL << 62) | 47 | #define MENVCFG_PBMTE (1ULL << 62) |
48 | #define MENVCFG_STCE (1ULL << 63) | 48 | #define MENVCFG_STCE (1ULL << 63) |
49 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | 49 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
... | ... | diff view generated by jsdifflib |
1 | From: Kaiwen Xue <kaiwenx@rivosinc.com> | 1 | From: Kaiwen Xue <kaiwenx@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | This adds checks in ops performed on xireg and xireg2-xireg6 so that the | 3 | This adds checks in ops performed on xireg and xireg2-xireg6 so that the |
4 | counter delegation function will receive a valid xiselect value with the | 4 | counter delegation function will receive a valid xiselect value with the |
5 | proper extensions enabled. | 5 | proper extensions enabled. |
6 | 6 | ||
7 | Co-developed-by: Atish Patra <atishp@rivosinc.com> | 7 | Co-developed-by: Atish Patra <atishp@rivosinc.com> |
8 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> | 8 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 10 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
11 | --- | 11 | --- |
12 | target/riscv/csr.c | 36 +++++++++++++++++++++++++++++++++++- | 12 | target/riscv/csr.c | 36 +++++++++++++++++++++++++++++++++++- |
13 | 1 file changed, 35 insertions(+), 1 deletion(-) | 13 | 1 file changed, 35 insertions(+), 1 deletion(-) |
14 | 14 | ||
15 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 15 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/csr.c | 17 | --- a/target/riscv/csr.c |
18 | +++ b/target/riscv/csr.c | 18 | +++ b/target/riscv/csr.c |
19 | @@ -XXX,XX +XXX,XX @@ static bool xiselect_aia_range(target_ulong isel) | 19 | @@ -XXX,XX +XXX,XX @@ static bool xiselect_aia_range(target_ulong isel) |
20 | (ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST); | 20 | (ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST); |
21 | } | 21 | } |
22 | 22 | ||
23 | +static bool xiselect_cd_range(target_ulong isel) | 23 | +static bool xiselect_cd_range(target_ulong isel) |
24 | +{ | 24 | +{ |
25 | + return (ISELECT_CD_FIRST <= isel && isel <= ISELECT_CD_LAST); | 25 | + return (ISELECT_CD_FIRST <= isel && isel <= ISELECT_CD_LAST); |
26 | +} | 26 | +} |
27 | + | 27 | + |
28 | static int rmw_iprio(target_ulong xlen, | 28 | static int rmw_iprio(target_ulong xlen, |
29 | target_ulong iselect, uint8_t *iprio, | 29 | target_ulong iselect, uint8_t *iprio, |
30 | target_ulong *val, target_ulong new_val, | 30 | target_ulong *val, target_ulong new_val, |
31 | @@ -XXX,XX +XXX,XX @@ done: | 31 | @@ -XXX,XX +XXX,XX @@ done: |
32 | return RISCV_EXCP_NONE; | 32 | return RISCV_EXCP_NONE; |
33 | } | 33 | } |
34 | 34 | ||
35 | +static int rmw_xireg_cd(CPURISCVState *env, int csrno, | 35 | +static int rmw_xireg_cd(CPURISCVState *env, int csrno, |
36 | + target_ulong isel, target_ulong *val, | 36 | + target_ulong isel, target_ulong *val, |
37 | + target_ulong new_val, target_ulong wr_mask) | 37 | + target_ulong new_val, target_ulong wr_mask) |
38 | +{ | 38 | +{ |
39 | + if (!riscv_cpu_cfg(env)->ext_smcdeleg) { | 39 | + if (!riscv_cpu_cfg(env)->ext_smcdeleg) { |
40 | + return RISCV_EXCP_ILLEGAL_INST; | 40 | + return RISCV_EXCP_ILLEGAL_INST; |
41 | + } | 41 | + } |
42 | + /* TODO: Implement the functionality later */ | 42 | + /* TODO: Implement the functionality later */ |
43 | + return RISCV_EXCP_NONE; | 43 | + return RISCV_EXCP_NONE; |
44 | +} | 44 | +} |
45 | + | 45 | + |
46 | /* | 46 | /* |
47 | * rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6 | 47 | * rmw_xireg_csrind: Perform indirect access to xireg and xireg2-xireg6 |
48 | * | 48 | * |
49 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno, | 49 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg_csrind(CPURISCVState *env, int csrno, |
50 | target_ulong isel, target_ulong *val, | 50 | target_ulong isel, target_ulong *val, |
51 | target_ulong new_val, target_ulong wr_mask) | 51 | target_ulong new_val, target_ulong wr_mask) |
52 | { | 52 | { |
53 | - return -EINVAL; | 53 | - return -EINVAL; |
54 | + int ret = -EINVAL; | 54 | + int ret = -EINVAL; |
55 | + bool virt = csrno == CSR_VSIREG ? true : false; | 55 | + bool virt = csrno == CSR_VSIREG ? true : false; |
56 | + | 56 | + |
57 | + if (xiselect_cd_range(isel)) { | 57 | + if (xiselect_cd_range(isel)) { |
58 | + ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask); | 58 | + ret = rmw_xireg_cd(env, csrno, isel, val, new_val, wr_mask); |
59 | + } else { | 59 | + } else { |
60 | + /* | 60 | + /* |
61 | + * As per the specification, access to unimplented region is undefined | 61 | + * As per the specification, access to unimplented region is undefined |
62 | + * but recommendation is to raise illegal instruction exception. | 62 | + * but recommendation is to raise illegal instruction exception. |
63 | + */ | 63 | + */ |
64 | + return RISCV_EXCP_ILLEGAL_INST; | 64 | + return RISCV_EXCP_ILLEGAL_INST; |
65 | + } | 65 | + } |
66 | + | 66 | + |
67 | + if (ret) { | 67 | + if (ret) { |
68 | + return (env->virt_enabled && virt) ? | 68 | + return (env->virt_enabled && virt) ? |
69 | + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; | 69 | + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; |
70 | + } | 70 | + } |
71 | + | 71 | + |
72 | + return RISCV_EXCP_NONE; | 72 | + return RISCV_EXCP_NONE; |
73 | } | 73 | } |
74 | 74 | ||
75 | static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val, | 75 | static int rmw_xiregi(CPURISCVState *env, int csrno, target_ulong *val, |
76 | 76 | ||
77 | -- | 77 | -- |
78 | 2.34.1 | 78 | 2.34.1 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
6 | It also adds a new shadow CSR scountinhibit and menvcfg enable bit (CDE) | 6 | It also adds a new shadow CSR scountinhibit and menvcfg enable bit (CDE) |
7 | to enable this extension and scountovf virtualization. | 7 | to enable this extension and scountovf virtualization. |
8 | 8 | ||
9 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> | 9 | Signed-off-by: Kaiwen Xue <kaiwenx@rivosinc.com> |
10 | Co-developed-by: Atish Patra <atishp@rivosinc.com> | 10 | Co-developed-by: Atish Patra <atishp@rivosinc.com> |
11 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 13 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
12 | --- | 14 | --- |
13 | target/riscv/csr.c | 300 +++++++++++++++++++++++++++++++++++++++++++++++++++-- | 15 | target/riscv/csr.c | 304 ++++++++++++++++++++++++++++++++++++++++++++++++++--- |
14 | 1 file changed, 289 insertions(+), 11 deletions(-) | 16 | 1 file changed, 292 insertions(+), 12 deletions(-) |
15 | 17 | ||
16 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 18 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
17 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/csr.c | 20 | --- a/target/riscv/csr.c |
19 | +++ b/target/riscv/csr.c | 21 | +++ b/target/riscv/csr.c |
... | ... | ||
272 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg_cd(CPURISCVState *env, int csrno, | 274 | @@ -XXX,XX +XXX,XX @@ static int rmw_xireg_cd(CPURISCVState *env, int csrno, |
273 | target_ulong isel, target_ulong *val, | 275 | target_ulong isel, target_ulong *val, |
274 | target_ulong new_val, target_ulong wr_mask) | 276 | target_ulong new_val, target_ulong wr_mask) |
275 | { | 277 | { |
276 | - if (!riscv_cpu_cfg(env)->ext_smcdeleg) { | 278 | - if (!riscv_cpu_cfg(env)->ext_smcdeleg) { |
279 | - return RISCV_EXCP_ILLEGAL_INST; | ||
277 | + int ret = -EINVAL; | 280 | + int ret = -EINVAL; |
278 | + int ctr_index = isel - ISELECT_CD_FIRST; | 281 | + int ctr_index = isel - ISELECT_CD_FIRST; |
279 | + int isel_hpm_start = ISELECT_CD_FIRST + 3; | 282 | + int isel_hpm_start = ISELECT_CD_FIRST + 3; |
280 | + | 283 | + |
281 | + if (!riscv_cpu_cfg(env)->ext_smcdeleg || !riscv_cpu_cfg(env)->ext_ssccfg) { | 284 | + if (!riscv_cpu_cfg(env)->ext_smcdeleg || !riscv_cpu_cfg(env)->ext_ssccfg) { |
282 | return RISCV_EXCP_ILLEGAL_INST; | 285 | + ret = RISCV_EXCP_ILLEGAL_INST; |
286 | + goto done; | ||
283 | } | 287 | } |
284 | - /* TODO: Implement the functionality later */ | 288 | - /* TODO: Implement the functionality later */ |
285 | - return RISCV_EXCP_NONE; | 289 | - return RISCV_EXCP_NONE; |
286 | + | 290 | + |
287 | + /* Invalid siselect value for reserved */ | 291 | + /* Invalid siselect value for reserved */ |
... | ... | ||
290 | + } | 294 | + } |
291 | + | 295 | + |
292 | + /* sireg4 and sireg5 provides access RV32 only CSRs */ | 296 | + /* sireg4 and sireg5 provides access RV32 only CSRs */ |
293 | + if (((csrno == CSR_SIREG5) || (csrno == CSR_SIREG4)) && | 297 | + if (((csrno == CSR_SIREG5) || (csrno == CSR_SIREG4)) && |
294 | + (riscv_cpu_mxl(env) != MXL_RV32)) { | 298 | + (riscv_cpu_mxl(env) != MXL_RV32)) { |
295 | + return RISCV_EXCP_ILLEGAL_INST; | 299 | + ret = RISCV_EXCP_ILLEGAL_INST; |
300 | + goto done; | ||
296 | + } | 301 | + } |
297 | + | 302 | + |
298 | + /* Check Sscofpmf dependancy */ | 303 | + /* Check Sscofpmf dependancy */ |
299 | + if (!riscv_cpu_cfg(env)->ext_sscofpmf && csrno == CSR_SIREG5 && | 304 | + if (!riscv_cpu_cfg(env)->ext_sscofpmf && csrno == CSR_SIREG5 && |
300 | + (isel_hpm_start <= isel && isel <= ISELECT_CD_LAST)) { | 305 | + (isel_hpm_start <= isel && isel <= ISELECT_CD_LAST)) { |
... | ... | ||
389 | + (cfg->ext_smcdeleg ? MENVCFG_CDE : 0); | 394 | + (cfg->ext_smcdeleg ? MENVCFG_CDE : 0); |
390 | uint64_t valh = (uint64_t)val << 32; | 395 | uint64_t valh = (uint64_t)val << 32; |
391 | 396 | ||
392 | env->menvcfg = (env->menvcfg & ~mask) | (valh & mask); | 397 | env->menvcfg = (env->menvcfg & ~mask) | (valh & mask); |
393 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | 398 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { |
394 | write_sstateen_1_3, | 399 | [CSR_MNSTATUS] = { "mnstatus", rnmi, read_mnstatus, write_mnstatus, |
395 | .min_priv_ver = PRIV_VERSION_1_12_0 }, | 400 | .min_priv_ver = PRIV_VERSION_1_12_0 }, |
396 | 401 | ||
397 | + /* Supervisor Counter Delegation */ | 402 | + /* Supervisor Counter Delegation */ |
398 | + [CSR_SCOUNTINHIBIT] = {"scountinhibit", scountinhibit_pred, | 403 | + [CSR_SCOUNTINHIBIT] = {"scountinhibit", scountinhibit_pred, |
399 | + read_scountinhibit, write_scountinhibit, | 404 | + read_scountinhibit, write_scountinhibit, |
400 | + .min_priv_ver = PRIV_VERSION_1_12_0 }, | 405 | + .min_priv_ver = PRIV_VERSION_1_12_0 }, |
... | ... | diff view generated by jsdifflib |
1 | The dependant ISA features are enabled at the end of cpu_realize | 1 | The dependant ISA features are enabled at the end of cpu_realize |
---|---|---|---|
2 | in finalize_features. Thus, PMU init should be invoked after that | 2 | in finalize_features. Thus, PMU init should be invoked after that |
3 | only. Move the init invocation to riscv_tcg_cpu_finalize_features. | 3 | only. Move the init invocation to riscv_tcg_cpu_finalize_features. |
4 | 4 | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
6 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 6 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
7 | --- | 7 | --- |
8 | target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++-------------- | 8 | target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++-------------- |
9 | 1 file changed, 14 insertions(+), 14 deletions(-) | 9 | 1 file changed, 14 insertions(+), 14 deletions(-) |
10 | 10 | ||
11 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 11 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/tcg/tcg-cpu.c | 13 | --- a/target/riscv/tcg/tcg-cpu.c |
14 | +++ b/target/riscv/tcg/tcg-cpu.c | 14 | +++ b/target/riscv/tcg/tcg-cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | 15 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) |
16 | error_propagate(errp, local_err); | 16 | error_propagate(errp, local_err); |
17 | return; | 17 | return; |
18 | } | 18 | } |
19 | +#ifndef CONFIG_USER_ONLY | 19 | +#ifndef CONFIG_USER_ONLY |
20 | + if (cpu->cfg.pmu_mask) { | 20 | + if (cpu->cfg.pmu_mask) { |
21 | + riscv_pmu_init(cpu, &local_err); | 21 | + riscv_pmu_init(cpu, &local_err); |
22 | + if (local_err != NULL) { | 22 | + if (local_err != NULL) { |
23 | + error_propagate(errp, local_err); | 23 | + error_propagate(errp, local_err); |
24 | + return; | 24 | + return; |
25 | + } | 25 | + } |
26 | + | 26 | + |
27 | + if (cpu->cfg.ext_sscofpmf) { | 27 | + if (cpu->cfg.ext_sscofpmf) { |
28 | + cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | 28 | + cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, |
29 | + riscv_pmu_timer_cb, cpu); | 29 | + riscv_pmu_timer_cb, cpu); |
30 | + } | 30 | + } |
31 | + } | 31 | + } |
32 | +#endif | 32 | +#endif |
33 | } | 33 | } |
34 | 34 | ||
35 | void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) | 35 | void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) |
36 | @@ -XXX,XX +XXX,XX @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp) | 36 | @@ -XXX,XX +XXX,XX @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp) |
37 | 37 | ||
38 | #ifndef CONFIG_USER_ONLY | 38 | #ifndef CONFIG_USER_ONLY |
39 | CPURISCVState *env = &cpu->env; | 39 | CPURISCVState *env = &cpu->env; |
40 | - Error *local_err = NULL; | 40 | - Error *local_err = NULL; |
41 | 41 | ||
42 | tcg_cflags_set(CPU(cs), CF_PCREL); | 42 | tcg_cflags_set(CPU(cs), CF_PCREL); |
43 | 43 | ||
44 | @@ -XXX,XX +XXX,XX @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp) | 44 | @@ -XXX,XX +XXX,XX @@ static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp) |
45 | riscv_timer_init(cpu); | 45 | riscv_timer_init(cpu); |
46 | } | 46 | } |
47 | 47 | ||
48 | - if (cpu->cfg.pmu_mask) { | 48 | - if (cpu->cfg.pmu_mask) { |
49 | - riscv_pmu_init(cpu, &local_err); | 49 | - riscv_pmu_init(cpu, &local_err); |
50 | - if (local_err != NULL) { | 50 | - if (local_err != NULL) { |
51 | - error_propagate(errp, local_err); | 51 | - error_propagate(errp, local_err); |
52 | - return false; | 52 | - return false; |
53 | - } | 53 | - } |
54 | - | 54 | - |
55 | - if (cpu->cfg.ext_sscofpmf) { | 55 | - if (cpu->cfg.ext_sscofpmf) { |
56 | - cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | 56 | - cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, |
57 | - riscv_pmu_timer_cb, cpu); | 57 | - riscv_pmu_timer_cb, cpu); |
58 | - } | 58 | - } |
59 | - } | 59 | - } |
60 | - | 60 | - |
61 | /* With H-Ext, VSSIP, VSTIP, VSEIP and SGEIP are hardwired to one. */ | 61 | /* With H-Ext, VSSIP, VSTIP, VSEIP and SGEIP are hardwired to one. */ |
62 | if (riscv_has_ext(env, RVH)) { | 62 | if (riscv_has_ext(env, RVH)) { |
63 | env->mideleg = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP | MIP_SGEIP; | 63 | env->mideleg = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP | MIP_SGEIP; |
64 | 64 | ||
65 | -- | 65 | -- |
66 | 2.34.1 | 66 | 2.34.1 | diff view generated by jsdifflib |
... | ... | ||
---|---|---|---|
5 | 2. S[m|s]csrind - To enable indirect access CSRs | 5 | 2. S[m|s]csrind - To enable indirect access CSRs |
6 | 6 | ||
7 | Add an implied rule so that these extensions are enabled by default | 7 | Add an implied rule so that these extensions are enabled by default |
8 | if the sscfg extension is enabled. | 8 | if the sscfg extension is enabled. |
9 | 9 | ||
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 12 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
11 | --- | 13 | --- |
12 | target/riscv/cpu.c | 12 +++++++++++- | 14 | target/riscv/cpu.c | 12 +++++++++++- |
13 | 1 file changed, 11 insertions(+), 1 deletion(-) | 15 | 1 file changed, 11 insertions(+), 1 deletion(-) |
14 | 16 | ||
... | ... | diff view generated by jsdifflib |
1 | Add configuration options so that they can be enabled/disabld from | 1 | Add configuration options so that they can be enabled/disabld from |
---|---|---|---|
2 | qemu commandline. | 2 | qemu commandline. |
3 | 3 | ||
4 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 4 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
5 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 6 | Signed-off-by: Atish Patra <atishp@rivosinc.com> |
6 | --- | 7 | --- |
7 | target/riscv/cpu.c | 4 ++++ | 8 | target/riscv/cpu.c | 4 ++++ |
8 | 1 file changed, 4 insertions(+) | 9 | 1 file changed, 4 insertions(+) |
9 | 10 | ||
... | ... | diff view generated by jsdifflib |